summaryrefslogtreecommitdiffstats
path: root/source/a/upower/patches/0011-linux-Add-support-for-iPhone-XR-XS-models.patch
blob: 2426e044bbcf280e1b4d92856f0cb9a1c2665c99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
From 97185bae75b16bea48d532aa5511417e485b1c06 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 17 Jun 2020 10:51:09 +0200
Subject: [PATCH 1/4] linux: Add support for iPhone XR, XS models

Modifying the udev serial to be acceptable as an hyphened UDID, as the
usbmux stack expects.

Closes: #114
---
 src/linux/up-device-idevice.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/linux/up-device-idevice.c b/src/linux/up-device-idevice.c
index a808269..d2fa0a1 100644
--- a/src/linux/up-device-idevice.c
+++ b/src/linux/up-device-idevice.c
@@ -203,6 +203,28 @@ out:
 	return G_SOURCE_CONTINUE;
 }
 
+static char *
+get_device_uuid (GUdevDevice *native)
+{
+	const char *uuid;
+	char *retval;
+
+	uuid = g_udev_device_get_property (native, "ID_SERIAL_SHORT");
+	if (uuid == NULL)
+		return NULL;
+
+	if (strlen (uuid) != 24)
+		return g_strdup (uuid);
+
+	/* new style UDID: add hyphen between first 8 and following 16 digits */
+	retval = g_malloc0 (24 + 1 + 1);
+	memcpy (&retval[0], &uuid[0], 8);
+	retval[8] = '-';
+	memcpy (&retval[9], &uuid[8], 16);
+
+	return retval;
+}
+
 /**
  * up_device_idevice_coldplug:
  *
@@ -213,7 +235,7 @@ up_device_idevice_coldplug (UpDevice *device)
 {
 	UpDeviceIdevice *idevice = UP_DEVICE_IDEVICE (device);
 	GUdevDevice *native;
-	const gchar *uuid;
+	char *uuid;
 	const gchar *model;
 	UpDeviceKind kind;
 
@@ -223,7 +245,7 @@ up_device_idevice_coldplug (UpDevice *device)
 		return FALSE;
 
 	/* Get the UUID */
-	uuid = g_udev_device_get_property (native, "ID_SERIAL_SHORT");
+	uuid = get_device_uuid (native);
 	if (uuid == NULL)
 		return FALSE;
 
@@ -253,6 +275,8 @@ up_device_idevice_coldplug (UpDevice *device)
 	g_source_set_name_by_id (idevice->priv->start_id,
 				 "[upower] up_device_idevice_start_poll_cb (linux)");
 
+	g_free (uuid);
+
 	return TRUE;
 }
 
-- 
2.27.0