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