]>
Commit | Line | Data |
---|---|---|
f13467ec | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
d7867b31 KS |
2 | /* |
3 | * USB device properties and persistent device path | |
4 | * | |
5 | * Copyright (c) 2005 SUSE Linux Products GmbH, Germany | |
6 | * Author: Hannes Reinecke <hare@suse.de> | |
d7867b31 KS |
7 | */ |
8 | ||
07630cea LP |
9 | #include <ctype.h> |
10 | #include <errno.h> | |
11 | #include <fcntl.h> | |
12 | #include <stdarg.h> | |
d7867b31 | 13 | #include <stdio.h> |
07630cea | 14 | #include <unistd.h> |
d7867b31 | 15 | |
b5efdb8a | 16 | #include "alloc-util.h" |
2b0f5113 | 17 | #include "device-nodes.h" |
9a6e5c24 | 18 | #include "device-util.h" |
3ffd4af2 | 19 | #include "fd-util.h" |
1001167c | 20 | #include "parse-util.h" |
07630cea | 21 | #include "string-util.h" |
5ea78a39 | 22 | #include "strxcpyx.h" |
07a26e42 | 23 | #include "udev-builtin.h" |
5953d8b9 | 24 | #include "udev-util.h" |
d7867b31 | 25 | |
9ec6e95b | 26 | static void set_usb_iftype(char *to, int if_class_num, size_t len) { |
04a9d3a0 | 27 | const char *type = "generic"; |
912541b0 KS |
28 | |
29 | switch (if_class_num) { | |
30 | case 1: | |
31 | type = "audio"; | |
32 | break; | |
33 | case 2: /* CDC-Control */ | |
34 | break; | |
35 | case 3: | |
36 | type = "hid"; | |
37 | break; | |
38 | case 5: /* Physical */ | |
39 | break; | |
40 | case 6: | |
41 | type = "media"; | |
42 | break; | |
43 | case 7: | |
44 | type = "printer"; | |
45 | break; | |
46 | case 8: | |
47 | type = "storage"; | |
48 | break; | |
49 | case 9: | |
50 | type = "hub"; | |
51 | break; | |
52 | case 0x0a: /* CDC-Data */ | |
53 | break; | |
54 | case 0x0b: /* Chip/Smart Card */ | |
55 | break; | |
56 | case 0x0d: /* Content Security */ | |
57 | break; | |
58 | case 0x0e: | |
59 | type = "video"; | |
60 | break; | |
61 | case 0xdc: /* Diagnostic Device */ | |
62 | break; | |
63 | case 0xe0: /* Wireless Controller */ | |
64 | break; | |
65 | case 0xfe: /* Application-specific */ | |
66 | break; | |
67 | case 0xff: /* Vendor-specific */ | |
68 | break; | |
69 | default: | |
70 | break; | |
71 | } | |
72 | strncpy(to, type, len); | |
73 | to[len-1] = '\0'; | |
d7867b31 KS |
74 | } |
75 | ||
9ec6e95b | 76 | static int set_usb_mass_storage_ifsubtype(char *to, const char *from, size_t len) { |
912541b0 | 77 | int type_num = 0; |
04a9d3a0 | 78 | const char *type = "generic"; |
912541b0 | 79 | |
1001167c | 80 | if (safe_atoi(from, &type_num) >= 0) { |
912541b0 | 81 | switch (type_num) { |
f6f2ad9b KS |
82 | case 1: /* RBC devices */ |
83 | type = "rbc"; | |
84 | break; | |
912541b0 KS |
85 | case 2: |
86 | type = "atapi"; | |
87 | break; | |
88 | case 3: | |
89 | type = "tape"; | |
90 | break; | |
91 | case 4: /* UFI */ | |
912541b0 KS |
92 | type = "floppy"; |
93 | break; | |
912541b0 KS |
94 | case 6: /* Transparent SPC-2 devices */ |
95 | type = "scsi"; | |
96 | break; | |
97 | default: | |
98 | break; | |
99 | } | |
100 | } | |
d5a89d7d | 101 | strscpy(to, len, type); |
912541b0 | 102 | return type_num; |
d7867b31 KS |
103 | } |
104 | ||
9ec6e95b | 105 | static void set_scsi_type(char *to, const char *from, size_t len) { |
1001167c | 106 | unsigned type_num; |
04a9d3a0 | 107 | const char *type = "generic"; |
912541b0 | 108 | |
1001167c | 109 | if (safe_atou(from, &type_num) >= 0) { |
912541b0 KS |
110 | switch (type_num) { |
111 | case 0: | |
112 | case 0xe: | |
113 | type = "disk"; | |
114 | break; | |
115 | case 1: | |
116 | type = "tape"; | |
117 | break; | |
118 | case 4: | |
119 | case 7: | |
120 | case 0xf: | |
121 | type = "optical"; | |
122 | break; | |
123 | case 5: | |
124 | type = "cd"; | |
125 | break; | |
126 | default: | |
127 | break; | |
128 | } | |
129 | } | |
d5a89d7d | 130 | strscpy(to, len, type); |
d7867b31 KS |
131 | } |
132 | ||
912541b0 KS |
133 | #define USB_DT_DEVICE 0x01 |
134 | #define USB_DT_INTERFACE 0x04 | |
d7867b31 | 135 | |
71bd61c5 | 136 | static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) { |
254d1313 | 137 | _cleanup_close_ int fd = -EBADF; |
912541b0 KS |
138 | ssize_t size; |
139 | unsigned char buf[18 + 65535]; | |
24bfda11 | 140 | size_t pos = 0; |
bad490b0 | 141 | unsigned strpos = 0; |
8bdca77c | 142 | const char *filename, *syspath; |
71bd61c5 | 143 | int r; |
912541b0 | 144 | struct usb_interface_descriptor { |
24bfda11 ZJS |
145 | uint8_t bLength; |
146 | uint8_t bDescriptorType; | |
147 | uint8_t bInterfaceNumber; | |
148 | uint8_t bAlternateSetting; | |
149 | uint8_t bNumEndpoints; | |
150 | uint8_t bInterfaceClass; | |
151 | uint8_t bInterfaceSubClass; | |
152 | uint8_t bInterfaceProtocol; | |
153 | uint8_t iInterface; | |
885fdebc | 154 | } _packed_; |
912541b0 | 155 | |
71bd61c5 YW |
156 | r = sd_device_get_syspath(dev, &syspath); |
157 | if (r < 0) | |
158 | return r; | |
bad490b0 | 159 | |
8bdca77c | 160 | filename = strjoina(syspath, "/descriptors"); |
32703bd1 | 161 | fd = open(filename, O_RDONLY|O_CLOEXEC|O_NOCTTY); |
8d8ce9e2 | 162 | if (fd < 0) |
8bdca77c | 163 | return log_device_debug_errno(dev, errno, "Failed to open \"%s\": %m", filename); |
bad490b0 | 164 | |
912541b0 | 165 | size = read(fd, buf, sizeof(buf)); |
760034be ZJS |
166 | if (size < 18) |
167 | return log_device_warning_errno(dev, SYNTHETIC_ERRNO(EIO), | |
168 | "Short read from \"%s\"", filename); | |
169 | assert((size_t) size <= sizeof buf); | |
912541b0 | 170 | |
912541b0 | 171 | ifs_str[0] = '\0'; |
24bfda11 ZJS |
172 | while (pos + sizeof(struct usb_interface_descriptor) < (size_t) size && |
173 | strpos + 7 < len - 2) { | |
174 | ||
912541b0 KS |
175 | struct usb_interface_descriptor *desc; |
176 | char if_str[8]; | |
177 | ||
760034be | 178 | desc = (struct usb_interface_descriptor *) (buf + pos); |
912541b0 KS |
179 | if (desc->bLength < 3) |
180 | break; | |
760034be ZJS |
181 | if (desc->bLength > size - sizeof(struct usb_interface_descriptor)) |
182 | return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EIO), | |
183 | "Corrupt data read from \"%s\"", filename); | |
912541b0 KS |
184 | pos += desc->bLength; |
185 | ||
186 | if (desc->bDescriptorType != USB_DT_INTERFACE) | |
187 | continue; | |
188 | ||
189 | if (snprintf(if_str, 8, ":%02x%02x%02x", | |
190 | desc->bInterfaceClass, | |
191 | desc->bInterfaceSubClass, | |
192 | desc->bInterfaceProtocol) != 7) | |
193 | continue; | |
194 | ||
4e361acc | 195 | if (strstr(ifs_str, if_str)) |
912541b0 KS |
196 | continue; |
197 | ||
198 | memcpy(&ifs_str[strpos], if_str, 8), | |
199 | strpos += 7; | |
200 | } | |
bad490b0 | 201 | |
912541b0 KS |
202 | if (strpos > 0) { |
203 | ifs_str[strpos++] = ':'; | |
204 | ifs_str[strpos++] = '\0'; | |
205 | } | |
bad490b0 ZJS |
206 | |
207 | return 0; | |
d7867b31 KS |
208 | } |
209 | ||
210 | /* | |
211 | * A unique USB identification is generated like this: | |
212 | * | |
213 | * 1.) Get the USB device type from InterfaceClass and InterfaceSubClass | |
73e231ab | 214 | * 2.) If the device type is 'Mass-Storage/SPC-2' or 'Mass-Storage/RBC', |
d7867b31 | 215 | * use the SCSI vendor and model as USB-Vendor and USB-model. |
73e231ab | 216 | * 3.) Otherwise, use the USB manufacturer and product as |
d7867b31 KS |
217 | * USB-Vendor and USB-model. Any non-printable characters |
218 | * in those strings will be skipped; a slash '/' will be converted | |
219 | * into a full stop '.'. | |
220 | * 4.) If that fails, too, we will use idVendor and idProduct | |
221 | * as USB-Vendor and USB-model. | |
222 | * 5.) The USB identification is the USB-vendor and USB-model | |
223 | * string concatenated with an underscore '_'. | |
224 | * 6.) If the device supplies a serial number, this number | |
225 | * is concatenated with the identification with an underscore '_'. | |
226 | */ | |
089bef66 | 227 | static int builtin_usb_id(UdevEvent *event, int argc, char *argv[]) { |
5668f3a7 | 228 | sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev); |
4beac74e | 229 | char vendor_str[64] = ""; |
912541b0 KS |
230 | char vendor_str_enc[256]; |
231 | const char *vendor_id; | |
4beac74e | 232 | char model_str[64] = ""; |
912541b0 KS |
233 | char model_str_enc[256]; |
234 | const char *product_id; | |
c8eaaf69 YW |
235 | char serial_str[UDEV_NAME_SIZE] = ""; |
236 | char packed_if_str[UDEV_NAME_SIZE] = ""; | |
4beac74e ZJS |
237 | char revision_str[64] = ""; |
238 | char type_str[64] = ""; | |
239 | char instance_str[64] = ""; | |
912541b0 KS |
240 | const char *ifnum = NULL; |
241 | const char *driver = NULL; | |
242 | char serial[256]; | |
243 | ||
71bd61c5 | 244 | sd_device *dev_interface, *dev_usb; |
912541b0 | 245 | const char *if_class, *if_subclass; |
1001167c | 246 | unsigned if_class_num; |
912541b0 KS |
247 | int protocol = 0; |
248 | size_t l; | |
249 | char *s; | |
250 | ||
fb53ee0a | 251 | const char *syspath, *sysname, *interface_syspath; |
71bd61c5 | 252 | int r; |
71bd61c5 | 253 | |
71bd61c5 YW |
254 | r = sd_device_get_syspath(dev, &syspath); |
255 | if (r < 0) | |
d354690e | 256 | return r; |
71bd61c5 YW |
257 | |
258 | r = sd_device_get_sysname(dev, &sysname); | |
259 | if (r < 0) | |
d354690e | 260 | return r; |
71bd61c5 | 261 | |
912541b0 | 262 | /* shortcut, if we are called directly for a "usb_device" type */ |
fb53ee0a | 263 | if (device_is_devtype(dev, "usb_device")) { |
912541b0 KS |
264 | dev_if_packed_info(dev, packed_if_str, sizeof(packed_if_str)); |
265 | dev_usb = dev; | |
266 | goto fallback; | |
267 | } | |
268 | ||
269 | /* usb interface directory */ | |
71bd61c5 | 270 | r = sd_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_interface", &dev_interface); |
d354690e | 271 | if (r < 0) |
9a6e5c24 | 272 | return log_device_debug_errno(dev, r, "Failed to access usb_interface: %m"); |
912541b0 | 273 | |
71bd61c5 YW |
274 | r = sd_device_get_syspath(dev_interface, &interface_syspath); |
275 | if (r < 0) | |
9a6e5c24 | 276 | return log_device_debug_errno(dev_interface, r, "Failed to get syspath: %m"); |
71bd61c5 YW |
277 | (void) sd_device_get_sysattr_value(dev_interface, "bInterfaceNumber", &ifnum); |
278 | (void) sd_device_get_sysattr_value(dev_interface, "driver", &driver); | |
912541b0 | 279 | |
71bd61c5 | 280 | r = sd_device_get_sysattr_value(dev_interface, "bInterfaceClass", &if_class); |
d354690e | 281 | if (r < 0) |
9a6e5c24 | 282 | return log_device_debug_errno(dev_interface, r, "Failed to get bInterfaceClass attribute: %m"); |
912541b0 | 283 | |
1001167c DT |
284 | r = safe_atou_full(if_class, 16, &if_class_num); |
285 | if (r < 0) | |
286 | return log_device_debug_errno(dev_interface, r, "Failed to parse if_class: %m"); | |
912541b0 KS |
287 | if (if_class_num == 8) { |
288 | /* mass storage */ | |
71bd61c5 | 289 | if (sd_device_get_sysattr_value(dev_interface, "bInterfaceSubClass", &if_subclass) >= 0) |
912541b0 | 290 | protocol = set_usb_mass_storage_ifsubtype(type_str, if_subclass, sizeof(type_str)-1); |
71bd61c5 | 291 | } else |
912541b0 | 292 | set_usb_iftype(type_str, if_class_num, sizeof(type_str)-1); |
912541b0 | 293 | |
c0f86d66 | 294 | log_device_debug(dev_interface, "if_class:%u protocol:%i", if_class_num, protocol); |
912541b0 KS |
295 | |
296 | /* usb device directory */ | |
71bd61c5 | 297 | r = sd_device_get_parent_with_subsystem_devtype(dev_interface, "usb", "usb_device", &dev_usb); |
d354690e | 298 | if (r < 0) |
9a6e5c24 | 299 | return log_device_debug_errno(dev_interface, r, "Failed to find parent 'usb' device"); |
912541b0 KS |
300 | |
301 | /* all interfaces of the device in a single string */ | |
302 | dev_if_packed_info(dev_usb, packed_if_str, sizeof(packed_if_str)); | |
303 | ||
304 | /* mass storage : SCSI or ATAPI */ | |
4c701096 | 305 | if (IN_SET(protocol, 6, 2)) { |
71bd61c5 YW |
306 | sd_device *dev_scsi; |
307 | const char *scsi_sysname, *scsi_model, *scsi_vendor, *scsi_type, *scsi_rev; | |
912541b0 KS |
308 | int host, bus, target, lun; |
309 | ||
310 | /* get scsi device */ | |
71bd61c5 YW |
311 | r = sd_device_get_parent_with_subsystem_devtype(dev, "scsi", "scsi_device", &dev_scsi); |
312 | if (r < 0) { | |
9a6e5c24 | 313 | log_device_debug_errno(dev, r, "Unable to find parent SCSI device"); |
912541b0 KS |
314 | goto fallback; |
315 | } | |
71bd61c5 YW |
316 | if (sd_device_get_sysname(dev_scsi, &scsi_sysname) < 0) |
317 | goto fallback; | |
318 | if (sscanf(scsi_sysname, "%d:%d:%d:%d", &host, &bus, &target, &lun) != 4) { | |
9a6e5c24 | 319 | log_device_debug(dev_scsi, "Invalid SCSI device"); |
912541b0 KS |
320 | goto fallback; |
321 | } | |
322 | ||
323 | /* Generic SPC-2 device */ | |
71bd61c5 YW |
324 | r = sd_device_get_sysattr_value(dev_scsi, "vendor", &scsi_vendor); |
325 | if (r < 0) { | |
9a6e5c24 | 326 | log_device_debug_errno(dev_scsi, r, "Failed to get SCSI vendor attribute: %m"); |
912541b0 KS |
327 | goto fallback; |
328 | } | |
2b0f5113 | 329 | encode_devnode_name(scsi_vendor, vendor_str_enc, sizeof(vendor_str_enc)); |
5953d8b9 | 330 | udev_replace_whitespace(scsi_vendor, vendor_str, sizeof(vendor_str)-1); |
393fcaf7 | 331 | udev_replace_chars(vendor_str, NULL); |
912541b0 | 332 | |
71bd61c5 YW |
333 | r = sd_device_get_sysattr_value(dev_scsi, "model", &scsi_model); |
334 | if (r < 0) { | |
9a6e5c24 | 335 | log_device_debug_errno(dev_scsi, r, "Failed to get SCSI model attribute: %m"); |
912541b0 KS |
336 | goto fallback; |
337 | } | |
2b0f5113 | 338 | encode_devnode_name(scsi_model, model_str_enc, sizeof(model_str_enc)); |
5953d8b9 | 339 | udev_replace_whitespace(scsi_model, model_str, sizeof(model_str)-1); |
393fcaf7 | 340 | udev_replace_chars(model_str, NULL); |
912541b0 | 341 | |
71bd61c5 YW |
342 | r = sd_device_get_sysattr_value(dev_scsi, "type", &scsi_type); |
343 | if (r < 0) { | |
9a6e5c24 | 344 | log_device_debug_errno(dev_scsi, r, "Failed to get SCSI type attribute: %m"); |
912541b0 KS |
345 | goto fallback; |
346 | } | |
347 | set_scsi_type(type_str, scsi_type, sizeof(type_str)-1); | |
348 | ||
71bd61c5 YW |
349 | r = sd_device_get_sysattr_value(dev_scsi, "rev", &scsi_rev); |
350 | if (r < 0) { | |
9a6e5c24 | 351 | log_device_debug_errno(dev_scsi, r, "Failed to get SCSI revision attribute: %m"); |
912541b0 KS |
352 | goto fallback; |
353 | } | |
5953d8b9 | 354 | udev_replace_whitespace(scsi_rev, revision_str, sizeof(revision_str)-1); |
393fcaf7 | 355 | udev_replace_chars(revision_str, NULL); |
912541b0 KS |
356 | |
357 | /* | |
358 | * some broken devices have the same identifiers | |
359 | * for all luns, export the target:lun number | |
360 | */ | |
361 | sprintf(instance_str, "%d:%d", target, lun); | |
362 | } | |
d7867b31 KS |
363 | |
364 | fallback: | |
71bd61c5 YW |
365 | r = sd_device_get_sysattr_value(dev_usb, "idVendor", &vendor_id); |
366 | if (r < 0) | |
9a6e5c24 | 367 | return log_device_debug_errno(dev_usb, r, "Failed to get idVendor attribute: %m"); |
71bd61c5 YW |
368 | |
369 | r = sd_device_get_sysattr_value(dev_usb, "idProduct", &product_id); | |
370 | if (r < 0) | |
9a6e5c24 | 371 | return log_device_debug_errno(dev_usb, r, "Failed to get idProduct attribute: %m"); |
912541b0 | 372 | |
2aed63f4 | 373 | /* fall back to USB vendor & device */ |
912541b0 | 374 | if (vendor_str[0] == '\0') { |
71bd61c5 | 375 | const char *usb_vendor; |
912541b0 | 376 | |
71bd61c5 | 377 | if (sd_device_get_sysattr_value(dev_usb, "manufacturer", &usb_vendor) < 0) |
912541b0 | 378 | usb_vendor = vendor_id; |
2b0f5113 | 379 | encode_devnode_name(usb_vendor, vendor_str_enc, sizeof(vendor_str_enc)); |
5953d8b9 | 380 | udev_replace_whitespace(usb_vendor, vendor_str, sizeof(vendor_str)-1); |
393fcaf7 | 381 | udev_replace_chars(vendor_str, NULL); |
912541b0 KS |
382 | } |
383 | ||
384 | if (model_str[0] == '\0') { | |
71bd61c5 | 385 | const char *usb_model; |
912541b0 | 386 | |
71bd61c5 | 387 | if (sd_device_get_sysattr_value(dev_usb, "product", &usb_model) < 0) |
912541b0 | 388 | usb_model = product_id; |
2b0f5113 | 389 | encode_devnode_name(usb_model, model_str_enc, sizeof(model_str_enc)); |
5953d8b9 | 390 | udev_replace_whitespace(usb_model, model_str, sizeof(model_str)-1); |
393fcaf7 | 391 | udev_replace_chars(model_str, NULL); |
912541b0 KS |
392 | } |
393 | ||
394 | if (revision_str[0] == '\0') { | |
395 | const char *usb_rev; | |
396 | ||
71bd61c5 | 397 | if (sd_device_get_sysattr_value(dev_usb, "bcdDevice", &usb_rev) >= 0) { |
5953d8b9 | 398 | udev_replace_whitespace(usb_rev, revision_str, sizeof(revision_str)-1); |
393fcaf7 | 399 | udev_replace_chars(revision_str, NULL); |
912541b0 KS |
400 | } |
401 | } | |
402 | ||
403 | if (serial_str[0] == '\0') { | |
404 | const char *usb_serial; | |
405 | ||
71bd61c5 | 406 | if (sd_device_get_sysattr_value(dev_usb, "serial", &usb_serial) >= 0) { |
a2cbfd59 | 407 | /* http://msdn.microsoft.com/en-us/library/windows/hardware/gg487321.aspx */ |
d3d2e3ab | 408 | for (const unsigned char *p = (unsigned char*) usb_serial; *p != '\0'; p++) |
a2cbfd59 KS |
409 | if (*p < 0x20 || *p > 0x7f || *p == ',') { |
410 | usb_serial = NULL; | |
411 | break; | |
412 | } | |
a2cbfd59 | 413 | |
71bd61c5 | 414 | if (usb_serial) { |
5953d8b9 | 415 | udev_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1); |
393fcaf7 | 416 | udev_replace_chars(serial_str, NULL); |
71bd61c5 | 417 | } |
912541b0 KS |
418 | } |
419 | } | |
420 | ||
421 | s = serial; | |
d5a89d7d | 422 | l = strpcpyl(&s, sizeof(serial), vendor_str, "_", model_str, NULL); |
38b9855b | 423 | if (!isempty(serial_str)) |
d5a89d7d | 424 | l = strpcpyl(&s, l, "_", serial_str, NULL); |
912541b0 | 425 | |
38b9855b | 426 | if (!isempty(instance_str)) |
d5a89d7d | 427 | strpcpyl(&s, l, "-", instance_str, NULL); |
912541b0 | 428 | |
479da110 YW |
429 | if (sd_device_get_property_value(dev, "ID_BUS", NULL) >= 0) |
430 | log_device_debug(dev, "ID_BUS property is already set, setting only properties prefixed with \"ID_USB_\"."); | |
431 | else { | |
089bef66 | 432 | udev_builtin_add_property(dev, event->event_mode, "ID_BUS", "usb"); |
479da110 | 433 | |
089bef66 YW |
434 | udev_builtin_add_property(dev, event->event_mode, "ID_MODEL", model_str); |
435 | udev_builtin_add_property(dev, event->event_mode, "ID_MODEL_ENC", model_str_enc); | |
436 | udev_builtin_add_property(dev, event->event_mode, "ID_MODEL_ID", product_id); | |
479da110 | 437 | |
089bef66 | 438 | udev_builtin_add_property(dev, event->event_mode, "ID_SERIAL", serial); |
479da110 | 439 | if (!isempty(serial_str)) |
089bef66 | 440 | udev_builtin_add_property(dev, event->event_mode, "ID_SERIAL_SHORT", serial_str); |
479da110 | 441 | |
089bef66 YW |
442 | udev_builtin_add_property(dev, event->event_mode, "ID_VENDOR", vendor_str); |
443 | udev_builtin_add_property(dev, event->event_mode, "ID_VENDOR_ENC", vendor_str_enc); | |
444 | udev_builtin_add_property(dev, event->event_mode, "ID_VENDOR_ID", vendor_id); | |
479da110 | 445 | |
089bef66 | 446 | udev_builtin_add_property(dev, event->event_mode, "ID_REVISION", revision_str); |
479da110 YW |
447 | |
448 | if (!isempty(type_str)) | |
089bef66 | 449 | udev_builtin_add_property(dev, event->event_mode, "ID_TYPE", type_str); |
479da110 YW |
450 | |
451 | if (!isempty(instance_str)) | |
089bef66 | 452 | udev_builtin_add_property(dev, event->event_mode, "ID_INSTANCE", instance_str); |
479da110 YW |
453 | } |
454 | ||
455 | /* Also export the same values in the above by prefixing ID_USB_. */ | |
089bef66 YW |
456 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_MODEL", model_str); |
457 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_MODEL_ENC", model_str_enc); | |
458 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_MODEL_ID", product_id); | |
459 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_SERIAL", serial); | |
38b9855b | 460 | if (!isempty(serial_str)) |
089bef66 | 461 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_SERIAL_SHORT", serial_str); |
479da110 | 462 | |
089bef66 YW |
463 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_VENDOR", vendor_str); |
464 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_VENDOR_ENC", vendor_str_enc); | |
465 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_VENDOR_ID", vendor_id); | |
479da110 | 466 | |
089bef66 | 467 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_REVISION", revision_str); |
479da110 | 468 | |
38b9855b | 469 | if (!isempty(type_str)) |
089bef66 | 470 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_TYPE", type_str); |
479da110 | 471 | |
38b9855b | 472 | if (!isempty(instance_str)) |
089bef66 | 473 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_INSTANCE", instance_str); |
479da110 | 474 | |
38b9855b | 475 | if (!isempty(packed_if_str)) |
089bef66 | 476 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_INTERFACES", packed_if_str); |
71bd61c5 | 477 | if (ifnum) |
089bef66 | 478 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_INTERFACE_NUM", ifnum); |
71bd61c5 | 479 | if (driver) |
089bef66 | 480 | udev_builtin_add_property(dev, event->event_mode, "ID_USB_DRIVER", driver); |
d354690e | 481 | return 0; |
d7867b31 KS |
482 | } |
483 | ||
25de7aa7 | 484 | const UdevBuiltin udev_builtin_usb_id = { |
912541b0 KS |
485 | .name = "usb_id", |
486 | .cmd = builtin_usb_id, | |
5ac0162c | 487 | .help = "USB device properties", |
912541b0 | 488 | .run_once = true, |
d7867b31 | 489 | }; |