-
Notifications
You must be signed in to change notification settings - Fork 1
/
0001-Mac-use-IORegistryEntryGetRegistryEntryID-to-resolve.patch
73 lines (66 loc) · 2.55 KB
/
0001-Mac-use-IORegistryEntryGetRegistryEntryID-to-resolve.patch
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
From 91b14af4ab0b74c5de17249edf4b547a8129b6e4 Mon Sep 17 00:00:00 2001
From: faust93 <[email protected]>
Date: Sun, 18 Apr 2021 10:09:05 +0300
Subject: [PATCH] Mac: use IORegistryEntryGetRegistryEntryID to resolve paths
---
mac/hid.c | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/mac/hid.c b/mac/hid.c
index d88a9ad..c62be8d 100644
--- a/mac/hid.c
+++ b/mac/hid.c
@@ -440,6 +440,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
io_object_t iokit_dev;
kern_return_t res;
io_string_t path;
+ uint64_t entry_id;
if (dev == NULL) {
return NULL;
@@ -467,6 +468,16 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
else
cur_dev->path = strdup("");
+ /* Fill in the kernel_entry_id */
+ res = IORegistryEntryGetRegistryEntryID(iokit_dev, &entry_id);
+ if (res == KERN_SUCCESS) {
+ if ((cur_dev->path = calloc(32 + 3 + 1, 1)) != NULL) {
+ sprintf(cur_dev->path, "id:%llu", entry_id);
+ }
+ } else {
+ cur_dev->path = strdup("");
+ }
+
/* Serial Number */
get_serial_number(dev, buf, BUF_LEN);
cur_dev->serial_number = dup_wcs(buf);
@@ -834,9 +845,28 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
dev = new_hid_device();
- /* Get the IORegistry entry for the given path */
- entry = IORegistryEntryFromPath(kIOMasterPortDefault, path);
- if (entry == MACH_PORT_NULL) {
+ /* Check if the path represents IORegistry path or an IORegistryEntry ID */
+ if (strlen(path) > 3) {
+ if (strncmp("id:", path, 3) == 0) {
+ /* Get the IORegistry entry for the given ID */
+ uint64_t entry_id;
+
+ entry_id = strtoull(path+3, NULL, 10);
+
+ entry = IOServiceGetMatchingService(kIOMasterPortDefault, IORegistryEntryIDMatching(entry_id));
+ if (entry == 0) {
+ /* No service found for ID */
+ goto return_error;
+ }
+ } else {
+ /* Get the IORegistry entry for the given path */
+ entry = IORegistryEntryFromPath(kIOMasterPortDefault, path);
+ if (entry == MACH_PORT_NULL) {
+ /* Path wasn't valid (maybe device was removed?) */
+ goto return_error;
+ }
+ }
+ } else {
/* Path wasn't valid (maybe device was removed?) */
goto return_error;
}
--
2.17.2 (Apple Git-113)