/src/fwupd/libfwupdplugin/fu-hwids-darwin.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2021 Richard Hughes <richard@hughsie.com> |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #define G_LOG_DOMAIN "FuContext" |
8 | | |
9 | | #include "config.h" |
10 | | |
11 | | #ifdef HOST_MACHINE_SYSTEM_DARWIN |
12 | | #include "fu-context-private.h" |
13 | | #endif |
14 | | #include "fu-hwids-private.h" |
15 | | |
16 | | gboolean |
17 | | fu_hwids_darwin_setup(FuContext *ctx, FuHwids *self, GError **error) |
18 | 0 | { |
19 | | #ifdef HOST_MACHINE_SYSTEM_DARWIN |
20 | | struct { |
21 | | const gchar *hwid; |
22 | | const gchar *key; |
23 | | } map[] = { |
24 | | {FU_HWIDS_KEY_BIOS_VERSION, "System Firmware Version"}, |
25 | | {FU_HWIDS_KEY_FAMILY, "Model Name"}, |
26 | | {FU_HWIDS_KEY_PRODUCT_NAME, "Model Identifier"}, |
27 | | }; |
28 | | const gchar *family = NULL; |
29 | | g_autofree gchar *standard_output = NULL; |
30 | | g_auto(GStrv) lines = NULL; |
31 | | |
32 | | /* parse the profiler output: nocheck:blocked */ |
33 | | if (!g_spawn_command_line_sync("system_profiler SPHardwareDataType", |
34 | | &standard_output, |
35 | | NULL, |
36 | | NULL, |
37 | | error)) |
38 | | return FALSE; |
39 | | lines = g_strsplit(standard_output, "\n", -1); |
40 | | for (guint j = 0; lines[j] != NULL; j++) { |
41 | | for (guint i = 0; i < G_N_ELEMENTS(map); i++) { |
42 | | g_auto(GStrv) chunks = g_strsplit(lines[j], ":", 2); |
43 | | if (g_strv_length(chunks) != 2) |
44 | | continue; |
45 | | if (g_strstr_len(chunks[0], -1, map[i].key) != NULL) |
46 | | fu_hwids_add_value(self, map[i].hwid, g_strstrip(chunks[1])); |
47 | | } |
48 | | } |
49 | | |
50 | | /* this has to be hardcoded */ |
51 | | fu_hwids_add_value(self, FU_HWIDS_KEY_BASEBOARD_MANUFACTURER, "Apple"); |
52 | | fu_hwids_add_value(self, FU_HWIDS_KEY_MANUFACTURER, "Apple"); |
53 | | fu_hwids_add_value(self, FU_HWIDS_KEY_BIOS_VENDOR, "Apple"); |
54 | | |
55 | | /* set the chassis kind using the family */ |
56 | | family = fu_hwids_get_value(self, FU_HWIDS_KEY_FAMILY); |
57 | | if (g_strcmp0(family, "MacBook Pro") == 0) { |
58 | | fu_hwids_add_value(self, FU_HWIDS_KEY_ENCLOSURE_KIND, "a"); |
59 | | fu_context_set_chassis_kind(ctx, FU_SMBIOS_CHASSIS_KIND_LAPTOP); |
60 | | } |
61 | | #endif |
62 | | |
63 | | /* success */ |
64 | 0 | return TRUE; |
65 | 0 | } |