@@ -29,9 +29,8 @@ import (
29
29
const (
30
30
VendorLedger = 0x2c97
31
31
UsagePageLedgerNanoS = 0xffa0
32
- //ProductNano = 1
33
- Channel = 0x0101
34
- PacketSize = 64
32
+ Channel = 0x0101
33
+ PacketSize = 64
35
34
)
36
35
37
36
type LedgerAdminHID struct {}
@@ -42,6 +41,12 @@ type LedgerDeviceHID struct {
42
41
readChannel chan []byte
43
42
}
44
43
44
+ // list of supported product ids as well as their corresponding interfaces
45
+ var supportedLedgerProductID = map [uint16 ]int {
46
+ 0x4011 : 0 , // Ledger Nano X
47
+ 0x1011 : 0 , // Ledger Nano S
48
+ }
49
+
45
50
func NewLedgerAdmin () * LedgerAdminHID {
46
51
return & LedgerAdminHID {}
47
52
}
@@ -72,9 +77,11 @@ func (admin *LedgerAdminHID) ListDevices() ([]string, error) {
72
77
func isLedgerDevice (d hid.DeviceInfo ) bool {
73
78
deviceFound := d .UsagePage == UsagePageLedgerNanoS
74
79
// Workarounds for possible empty usage pages
75
- return deviceFound ||
76
- (d .Product == "Nano S" && d .Interface == 0 ) ||
77
- (d .Product == "Nano X" && d .Interface == 0 )
80
+ if interfaceID , supported := supportedLedgerProductID [d .ProductID ]; deviceFound || (supported && (interfaceID == d .Interface )) {
81
+ return true
82
+ }
83
+
84
+ return false
78
85
}
79
86
80
87
func (admin * LedgerAdminHID ) CountDevices () int {
@@ -92,8 +99,8 @@ func (admin *LedgerAdminHID) CountDevices() int {
92
99
93
100
func newDevice (dev * hid.Device ) * LedgerDeviceHID {
94
101
return & LedgerDeviceHID {
95
- device : dev ,
96
- readCo : new (sync.Once ),
102
+ device : dev ,
103
+ readCo : new (sync.Once ),
97
104
readChannel : make (chan []byte ),
98
105
}
99
106
}
0 commit comments