Skip to content

Commit e0d792d

Browse files
author
e.khalilov
committed
add device interfaces
1 parent cc30f8b commit e0d792d

6 files changed

Lines changed: 134 additions & 55 deletions

File tree

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,33 @@ interface UsbDevice {
7878
manufacturer?: string
7979
product?: string
8080
serialNumber?: string
81-
deviceClass: number
81+
deviceClass: number // raw bDeviceClass; 0 for HID/composite devices (see note)
8282
deviceSubclass: number
8383
deviceProtocol: number
8484
busId: string
8585
deviceAddress: number
86+
interfaces: UsbInterface[] // per-interface class info (the real function class)
87+
}
88+
89+
interface UsbInterface {
90+
interfaceNumber: number
91+
class: number
92+
subclass: number
93+
protocol: number
94+
interfaceString?: string
8695
}
8796
```
8897

98+
> **Note on `deviceClass`**
99+
>
100+
> The device-level `deviceClass` (`bDeviceClass` in the USB spec) is
101+
> legitimately `0x00` for HID and composite devices -- keyboards, trackpads,
102+
> mice, iPhones, etc. A value of `0x00` means the class is declared
103+
> *per-interface*, not at the device level. To determine what such a device
104+
> actually is, read `interfaces[].class` (e.g. `0x03` = HID, `0x06` =
105+
> still-image/PTP, `0xFF` = vendor-specific). On Windows, `interfaces` may be
106+
> empty for non-composite devices bound to a single driver.
107+
89108
## Platform support
90109

91110
| Platform | Architecture | Status |

index.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ export interface UsbDevice {
1515
manufacturer?: string
1616
product?: string
1717
serialNumber?: string
18+
/**
19+
* Raw `bDeviceClass` from the device descriptor. This is legitimately
20+
* `0x00` for HID and composite devices, which declare their class
21+
* per-interface. Inspect `interfaces` for the actual function class.
22+
*/
1823
deviceClass: number
1924
deviceSubclass: number
2025
deviceProtocol: number
2126
busId: string
2227
deviceAddress: number
28+
/**
29+
* Interfaces in the device's active configuration. May be empty on
30+
* Windows for non-composite devices bound to a single driver.
31+
*/
32+
interfaces: Array<UsbInterface>
2333
}
2434

2535
export interface UsbEvent {
@@ -34,6 +44,22 @@ export declare const enum UsbEventType {
3444
Disconnected = 'Disconnected'
3545
}
3646

47+
/**
48+
* Summary information about a single USB interface, taken from the
49+
* interface descriptor of the device's active configuration.
50+
*
51+
* This is where the real device function class lives for HID and
52+
* composite devices (keyboards, trackpads, iPhones, etc.), whose
53+
* device-level `bDeviceClass` is `0x00` per the USB specification.
54+
*/
55+
export interface UsbInterface {
56+
interfaceNumber: number
57+
class: number
58+
subclass: number
59+
protocol: number
60+
interfaceString?: string
61+
}
62+
3763
/**
3864
* Start watching for USB device connect/disconnect events.
3965
* The callback receives `(err, event)` for each hotplug event.

0 commit comments

Comments
 (0)