Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 2 | * Copyright (C) 2017 Richard Hughes <richard@hughsie.com> |
| 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Richard Hughes | bfd946e | 2019-02-09 08:21:40 +0000 | [diff] [blame] | 7 | #pragma once |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 8 | |
Richard Hughes | adc9dad | 2017-09-04 13:19:27 +0100 | [diff] [blame] | 9 | #include <gio/gio.h> |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 10 | |
Mario Limonciello | 3960265 | 2019-04-29 21:08:58 -0500 | [diff] [blame] | 11 | /** |
| 12 | * FuAppFlags: |
| 13 | * @FU_APP_FLAGS_NONE: No flags set |
| 14 | * @FU_APP_FLAGS_NO_IDLE_SOURCES: Disallow idle sources |
Mario Limonciello | 3960265 | 2019-04-29 21:08:58 -0500 | [diff] [blame] | 15 | * |
| 16 | * The flags to use when loading an application. |
| 17 | **/ |
Richard Hughes | 5b5f655 | 2018-05-18 10:22:39 +0100 | [diff] [blame] | 18 | typedef enum { |
| 19 | FU_APP_FLAGS_NONE = 0, |
| 20 | FU_APP_FLAGS_NO_IDLE_SOURCES = 1 << 0, |
Mario Limonciello | 3960265 | 2019-04-29 21:08:58 -0500 | [diff] [blame] | 21 | /*< private >*/ |
Richard Hughes | 5b5f655 | 2018-05-18 10:22:39 +0100 | [diff] [blame] | 22 | FU_APP_FLAGS_LAST |
| 23 | } FuAppFlags; |
| 24 | |
Mario Limonciello | 3960265 | 2019-04-29 21:08:58 -0500 | [diff] [blame] | 25 | /** |
| 26 | * FuDumpFlags: |
| 27 | * @FU_DUMP_FLAGS_NONE: No flags set |
| 28 | * @FU_DUMP_FLAGS_SHOW_ASCII: Show ASCII in debugging dumps |
| 29 | * @FU_DUMP_FLAGS_SHOW_ADDRESSES: Show addresses in debugging dumps |
| 30 | * |
| 31 | * The flags to use when configuring debugging |
| 32 | **/ |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 33 | typedef enum { |
Richard Hughes | 3548186 | 2019-01-06 12:01:58 +0000 | [diff] [blame] | 34 | FU_DUMP_FLAGS_NONE = 0, |
| 35 | FU_DUMP_FLAGS_SHOW_ASCII = 1 << 0, |
| 36 | FU_DUMP_FLAGS_SHOW_ADDRESSES = 1 << 1, |
Mario Limonciello | 3960265 | 2019-04-29 21:08:58 -0500 | [diff] [blame] | 37 | /*< private >*/ |
Richard Hughes | 3548186 | 2019-01-06 12:01:58 +0000 | [diff] [blame] | 38 | FU_DUMP_FLAGS_LAST |
| 39 | } FuDumpFlags; |
| 40 | |
Richard Hughes | 37c6a7b | 2019-08-14 21:57:43 +0100 | [diff] [blame] | 41 | typedef guint FuEndianType; |
| 42 | |
Mario Limonciello | 3960265 | 2019-04-29 21:08:58 -0500 | [diff] [blame] | 43 | /** |
| 44 | * FuPathKind: |
| 45 | * @FU_PATH_KIND_CACHEDIR_PKG: The cache directory (IE /var/cache/fwupd) |
| 46 | * @FU_PATH_KIND_DATADIR_PKG: The non-volatile data store (IE /usr/share/fwupd) |
| 47 | * @FU_PATH_KIND_EFIAPPDIR: The location to store EFI apps before install (IE /usr/libexec/fwupd/efi) |
| 48 | * @FU_PATH_KIND_LOCALSTATEDIR: The local state directory (IE /var) |
| 49 | * @FU_PATH_KIND_LOCALSTATEDIR_PKG: The local state directory for the package (IE /var/lib/fwupd) |
| 50 | * @FU_PATH_KIND_PLUGINDIR_PKG: The location to look for plugins for package (IE /usr/lib/[triplet]/fwupd-plugins-3) |
| 51 | * @FU_PATH_KIND_SYSCONFDIR: The configuration location (IE /etc) |
| 52 | * @FU_PATH_KIND_SYSCONFDIR_PKG: The package configuration location (IE /etc/fwupd) |
| 53 | * @FU_PATH_KIND_SYSFSDIR_FW: The sysfs firmware location (IE /sys/firmware) |
| 54 | * @FU_PATH_KIND_SYSFSDIR_DRIVERS: The platform sysfs directory (IE /sys/bus/platform/drivers) |
| 55 | * @FU_PATH_KIND_SYSFSDIR_TPM: The TPM sysfs directory (IE /sys/class/tpm) |
Mario Limonciello | d8af5de | 2019-11-04 09:33:34 -0600 | [diff] [blame] | 56 | * @FU_PATH_KIND_POLKIT_ACTIONS: The directory for policy kit actions (IE /usr/share/polkit-1/actions/) |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame] | 57 | * @FU_PATH_KIND_OFFLINE_TRIGGER: The file for the offline trigger (IE /system-update) |
Mario Limonciello | 9dce1f7 | 2020-02-04 09:12:52 -0600 | [diff] [blame] | 58 | * @FU_PATH_KIND_SYSFSDIR_SECURITY: The sysfs security location (IE /sys/kernel/security) |
Mario Limonciello | 3960265 | 2019-04-29 21:08:58 -0500 | [diff] [blame] | 59 | * |
| 60 | * Path types to use when dynamically determining a path at runtime |
| 61 | **/ |
Richard Hughes | 3548186 | 2019-01-06 12:01:58 +0000 | [diff] [blame] | 62 | typedef enum { |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 63 | FU_PATH_KIND_CACHEDIR_PKG, |
| 64 | FU_PATH_KIND_DATADIR_PKG, |
Mario Limonciello | e6e2bf9 | 2018-07-10 12:11:25 -0500 | [diff] [blame] | 65 | FU_PATH_KIND_EFIAPPDIR, |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 66 | FU_PATH_KIND_LOCALSTATEDIR, |
| 67 | FU_PATH_KIND_LOCALSTATEDIR_PKG, |
| 68 | FU_PATH_KIND_PLUGINDIR_PKG, |
| 69 | FU_PATH_KIND_SYSCONFDIR, |
| 70 | FU_PATH_KIND_SYSCONFDIR_PKG, |
Richard Hughes | 282b10d | 2018-06-22 14:48:00 +0100 | [diff] [blame] | 71 | FU_PATH_KIND_SYSFSDIR_FW, |
Richard Hughes | 83390f6 | 2018-06-22 20:36:46 +0100 | [diff] [blame] | 72 | FU_PATH_KIND_SYSFSDIR_DRIVERS, |
Richard Hughes | b56015e | 2018-12-12 09:25:32 +0000 | [diff] [blame] | 73 | FU_PATH_KIND_SYSFSDIR_TPM, |
Mario Limonciello | 057c67a | 2019-05-23 10:44:19 -0500 | [diff] [blame] | 74 | FU_PATH_KIND_POLKIT_ACTIONS, |
Richard Hughes | afdba37 | 2019-11-23 12:57:35 +0000 | [diff] [blame] | 75 | FU_PATH_KIND_OFFLINE_TRIGGER, |
Mario Limonciello | 9dce1f7 | 2020-02-04 09:12:52 -0600 | [diff] [blame] | 76 | FU_PATH_KIND_SYSFSDIR_SECURITY, |
Mario Limonciello | 3960265 | 2019-04-29 21:08:58 -0500 | [diff] [blame] | 77 | /*< private >*/ |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 78 | FU_PATH_KIND_LAST |
| 79 | } FuPathKind; |
| 80 | |
Richard Hughes | 049ccc8 | 2017-08-09 15:26:56 +0100 | [diff] [blame] | 81 | typedef void (*FuOutputHandler) (const gchar *line, |
| 82 | gpointer user_data); |
| 83 | |
| 84 | gboolean fu_common_spawn_sync (const gchar * const *argv, |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 85 | FuOutputHandler handler_cb, |
Richard Hughes | 049ccc8 | 2017-08-09 15:26:56 +0100 | [diff] [blame] | 86 | gpointer handler_user_data, |
Richard Hughes | b768e4d | 2019-02-26 13:55:18 +0000 | [diff] [blame] | 87 | guint timeout_ms, |
Richard Hughes | 049ccc8 | 2017-08-09 15:26:56 +0100 | [diff] [blame] | 88 | GCancellable *cancellable, |
| 89 | GError **error); |
| 90 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 91 | gchar *fu_common_get_path (FuPathKind path_kind); |
Richard Hughes | 484ee29 | 2019-03-22 16:10:50 +0000 | [diff] [blame] | 92 | gchar *fu_common_realpath (const gchar *filename, |
| 93 | GError **error); |
Richard Hughes | 5c508de | 2019-11-22 09:57:34 +0000 | [diff] [blame] | 94 | gboolean fu_common_fnmatch (const gchar *pattern, |
| 95 | const gchar *str); |
Richard Hughes | 954dd9f | 2017-08-08 13:36:25 +0100 | [diff] [blame] | 96 | gboolean fu_common_rmtree (const gchar *directory, |
| 97 | GError **error); |
Richard Hughes | 89e968b | 2018-03-07 10:01:08 +0000 | [diff] [blame] | 98 | GPtrArray *fu_common_get_files_recursive (const gchar *path, |
| 99 | GError **error); |
Richard Hughes | 7ee42fe | 2017-08-15 14:06:21 +0100 | [diff] [blame] | 100 | gboolean fu_common_mkdir_parent (const gchar *filename, |
| 101 | GError **error); |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 102 | gboolean fu_common_set_contents_bytes (const gchar *filename, |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 103 | GBytes *bytes, |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 104 | GError **error); |
Richard Hughes | d0d2ae6 | 2017-08-08 12:22:30 +0100 | [diff] [blame] | 105 | GBytes *fu_common_get_contents_bytes (const gchar *filename, |
| 106 | GError **error); |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 107 | GBytes *fu_common_get_contents_fd (gint fd, |
| 108 | gsize count, |
| 109 | GError **error); |
Richard Hughes | 94f939a | 2017-08-08 12:21:39 +0100 | [diff] [blame] | 110 | gboolean fu_common_extract_archive (GBytes *blob, |
| 111 | const gchar *dir, |
| 112 | GError **error); |
Richard Hughes | 41cbe2a | 2017-08-08 14:13:35 +0100 | [diff] [blame] | 113 | GBytes *fu_common_firmware_builder (GBytes *bytes, |
| 114 | const gchar *script_fn, |
| 115 | const gchar *output_fn, |
| 116 | GError **error); |
Richard Hughes | e82eef3 | 2018-05-20 10:41:26 +0100 | [diff] [blame] | 117 | GError *fu_common_error_array_get_best (GPtrArray *errors); |
Richard Hughes | 73bf233 | 2018-08-28 09:38:09 +0100 | [diff] [blame] | 118 | guint64 fu_common_strtoull (const gchar *str); |
Richard Hughes | 22367e7 | 2018-08-30 10:24:04 +0100 | [diff] [blame] | 119 | gchar *fu_common_find_program_in_path (const gchar *basename, |
| 120 | GError **error); |
Richard Hughes | a574a75 | 2018-08-31 13:31:03 +0100 | [diff] [blame] | 121 | gchar *fu_common_strstrip (const gchar *str); |
Richard Hughes | e59cb9a | 2018-12-05 14:37:40 +0000 | [diff] [blame] | 122 | void fu_common_dump_raw (const gchar *log_domain, |
| 123 | const gchar *title, |
| 124 | const guint8 *data, |
| 125 | gsize len); |
Richard Hughes | 3548186 | 2019-01-06 12:01:58 +0000 | [diff] [blame] | 126 | void fu_common_dump_full (const gchar *log_domain, |
| 127 | const gchar *title, |
| 128 | const guint8 *data, |
| 129 | gsize len, |
| 130 | guint columns, |
| 131 | FuDumpFlags flags); |
Richard Hughes | e59cb9a | 2018-12-05 14:37:40 +0000 | [diff] [blame] | 132 | void fu_common_dump_bytes (const gchar *log_domain, |
| 133 | const gchar *title, |
| 134 | GBytes *bytes); |
Richard Hughes | fc90f39 | 2019-01-15 21:21:16 +0000 | [diff] [blame] | 135 | GBytes *fu_common_bytes_align (GBytes *bytes, |
| 136 | gsize blksz, |
| 137 | gchar padval); |
Richard Hughes | 3699946 | 2019-03-19 20:23:29 +0000 | [diff] [blame] | 138 | gboolean fu_common_bytes_is_empty (GBytes *bytes); |
Richard Hughes | 2aad104 | 2019-03-21 09:03:32 +0000 | [diff] [blame] | 139 | gboolean fu_common_bytes_compare (GBytes *bytes1, |
| 140 | GBytes *bytes2, |
| 141 | GError **error); |
Richard Hughes | 38245ff | 2019-09-18 14:46:09 +0100 | [diff] [blame] | 142 | gboolean fu_common_bytes_compare_raw (const guint8 *buf1, |
| 143 | gsize bufsz1, |
| 144 | const guint8 *buf2, |
| 145 | gsize bufsz2, |
| 146 | GError **error); |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 147 | GBytes *fu_common_bytes_pad (GBytes *bytes, |
| 148 | gsize sz); |
Richard Hughes | ae96a1f | 2019-09-23 11:16:36 +0100 | [diff] [blame] | 149 | gsize fu_common_strwidth (const gchar *text); |
Richard Hughes | 5308ea4 | 2019-08-09 12:25:13 +0100 | [diff] [blame] | 150 | gboolean fu_memcpy_safe (guint8 *dst, |
| 151 | gsize dst_sz, |
| 152 | gsize dst_offset, |
| 153 | const guint8 *src, |
| 154 | gsize src_sz, |
| 155 | gsize src_offset, |
| 156 | gsize n, |
| 157 | GError **error); |
Richard Hughes | c21a0b9 | 2019-10-24 12:24:37 +0100 | [diff] [blame] | 158 | gboolean fu_common_read_uint8_safe (const guint8 *buf, |
| 159 | gsize bufsz, |
| 160 | gsize offset, |
| 161 | guint8 *value, |
| 162 | GError **error); |
Richard Hughes | 80768f5 | 2019-10-22 07:19:14 +0100 | [diff] [blame] | 163 | gboolean fu_common_read_uint16_safe (const guint8 *buf, |
| 164 | gsize bufsz, |
| 165 | gsize offset, |
| 166 | guint16 *value, |
| 167 | FuEndianType endian, |
| 168 | GError **error); |
| 169 | gboolean fu_common_read_uint32_safe (const guint8 *buf, |
| 170 | gsize bufsz, |
| 171 | gsize offset, |
| 172 | guint32 *value, |
| 173 | FuEndianType endian, |
| 174 | GError **error); |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 175 | |
Richard Hughes | 37c6a7b | 2019-08-14 21:57:43 +0100 | [diff] [blame] | 176 | void fu_byte_array_append_uint8 (GByteArray *array, |
| 177 | guint8 data); |
| 178 | void fu_byte_array_append_uint16 (GByteArray *array, |
| 179 | guint16 data, |
| 180 | FuEndianType endian); |
| 181 | void fu_byte_array_append_uint32 (GByteArray *array, |
| 182 | guint32 data, |
| 183 | FuEndianType endian); |
Richard Hughes | ae252cd | 2017-12-08 10:48:15 +0000 | [diff] [blame] | 184 | |
| 185 | void fu_common_write_uint16 (guint8 *buf, |
| 186 | guint16 val_native, |
| 187 | FuEndianType endian); |
| 188 | void fu_common_write_uint32 (guint8 *buf, |
| 189 | guint32 val_native, |
| 190 | FuEndianType endian); |
| 191 | guint16 fu_common_read_uint16 (const guint8 *buf, |
| 192 | FuEndianType endian); |
| 193 | guint32 fu_common_read_uint32 (const guint8 *buf, |
| 194 | FuEndianType endian); |
| 195 | |
Richard Hughes | 83e56c1 | 2018-10-10 20:24:41 +0100 | [diff] [blame] | 196 | guint fu_common_string_replace (GString *string, |
| 197 | const gchar *search, |
| 198 | const gchar *replace); |
Richard Hughes | cea28de | 2019-08-09 11:16:40 +0100 | [diff] [blame] | 199 | void fu_common_string_append_kv (GString *str, |
Richard Hughes | 6e3e62b | 2019-08-14 10:43:08 +0100 | [diff] [blame] | 200 | guint idt, |
Richard Hughes | cea28de | 2019-08-09 11:16:40 +0100 | [diff] [blame] | 201 | const gchar *key, |
| 202 | const gchar *value); |
Richard Hughes | 6e3e62b | 2019-08-14 10:43:08 +0100 | [diff] [blame] | 203 | void fu_common_string_append_ku (GString *str, |
| 204 | guint idt, |
| 205 | const gchar *key, |
| 206 | guint64 value); |
| 207 | void fu_common_string_append_kx (GString *str, |
| 208 | guint idt, |
| 209 | const gchar *key, |
| 210 | guint64 value); |
| 211 | void fu_common_string_append_kb (GString *str, |
| 212 | guint idt, |
| 213 | const gchar *key, |
| 214 | gboolean value); |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 215 | gchar **fu_common_strnsplit (const gchar *str, |
| 216 | gsize sz, |
| 217 | const gchar *delimiter, |
| 218 | gint max_tokens); |
Mario Limonciello | 9dce1f7 | 2020-02-04 09:12:52 -0600 | [diff] [blame] | 219 | gboolean fu_common_kernel_locked_down (void); |