Skip to content

Commit c2d93de

Browse files
authored
Merge pull request #15232 from karalabe/macos-usbhw-fixes
accounts/usbwallet: handle bad interface number on macOS
2 parents f4c49bc + 8d126a4 commit c2d93de

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

accounts/usbwallet/hub.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type Hub struct {
4747
scheme string // Protocol scheme prefixing account and wallet URLs.
4848
vendorID uint16 // USB vendor identifier used for device discovery
4949
productIDs []uint16 // USB product identifiers used for device discovery
50+
usageID uint16 // USB usage page identifier used for macOS device discovery
51+
endpointID int // USB endpoint identifier used for non-macOS device discovery
5052
makeDriver func(log.Logger) driver // Factory method to construct a vendor specific driver
5153

5254
refreshed time.Time // Time instance when the list of wallets was last refreshed
@@ -66,23 +68,25 @@ type Hub struct {
6668

6769
// NewLedgerHub creates a new hardware wallet manager for Ledger devices.
6870
func NewLedgerHub() (*Hub, error) {
69-
return newHub(LedgerScheme, 0x2c97, []uint16{0x0000 /* Ledger Blue */, 0x0001 /* Ledger Nano S */}, newLedgerDriver)
71+
return newHub(LedgerScheme, 0x2c97, []uint16{0x0000 /* Ledger Blue */, 0x0001 /* Ledger Nano S */}, 0xffa0, 0, newLedgerDriver)
7072
}
7173

7274
// NewTrezorHub creates a new hardware wallet manager for Trezor devices.
7375
func NewTrezorHub() (*Hub, error) {
74-
return newHub(TrezorScheme, 0x534c, []uint16{0x0001 /* Trezor 1 */}, newTrezorDriver)
76+
return newHub(TrezorScheme, 0x534c, []uint16{0x0001 /* Trezor 1 */}, 0xff00, 0, newTrezorDriver)
7577
}
7678

7779
// newHub creates a new hardware wallet manager for generic USB devices.
78-
func newHub(scheme string, vendorID uint16, productIDs []uint16, makeDriver func(log.Logger) driver) (*Hub, error) {
80+
func newHub(scheme string, vendorID uint16, productIDs []uint16, usageID uint16, endpointID int, makeDriver func(log.Logger) driver) (*Hub, error) {
7981
if !hid.Supported() {
8082
return nil, errors.New("unsupported platform")
8183
}
8284
hub := &Hub{
8385
scheme: scheme,
8486
vendorID: vendorID,
8587
productIDs: productIDs,
88+
usageID: usageID,
89+
endpointID: endpointID,
8690
makeDriver: makeDriver,
8791
quit: make(chan chan error),
8892
}
@@ -133,7 +137,7 @@ func (hub *Hub) refreshWallets() {
133137
}
134138
for _, info := range hid.Enumerate(hub.vendorID, 0) {
135139
for _, id := range hub.productIDs {
136-
if info.ProductID == id && info.Interface == 0 {
140+
if info.ProductID == id && (info.UsagePage == hub.usageID || info.Interface == hub.endpointID) {
137141
devices = append(devices, info)
138142
break
139143
}

0 commit comments

Comments
 (0)