Skip to content

Commit

Permalink
[transport-hid] Fix device identification not relying on the correct …
Browse files Browse the repository at this point in the history
…information
  • Loading branch information
pbondoer committed Jul 10, 2019
1 parent 8338281 commit 7c92d92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 14 additions & 0 deletions packages/devices/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const devices = {
}
};

const productMap = {
Blue: "blue",
"Nano S": "nanoS",
"Nano X": "nanoX"
};

// $FlowFixMe
const devicesList: DeviceModel[] = Object.values(devices);

Expand All @@ -82,11 +88,19 @@ export const getDeviceModel = (id: DeviceModelId): DeviceModel => {
export const identifyUSBProductId = (usbProductId: number): ?DeviceModel => {
const legacy = devicesList.find(d => d.legacyUsbProductId === usbProductId);
if (legacy) return legacy;

const mm = usbProductId >> 8;
const deviceModel = devicesList.find(d => d.productIdMM === mm);
return deviceModel;
};

export const identifyProductName = (productName: string): ?DeviceModel => {
const productId = productMap[productName];
const deviceModel = devicesList.find(d => d.id === productId);

return deviceModel;
};

const bluetoothServices: string[] = [];
const serviceUuidToInfos: {
[_: string]: BluetoothInfos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from "@ledgerhq/hw-transport";
import { ledgerUSBVendorId } from "@ledgerhq/devices";
import hidFraming from "@ledgerhq/devices/lib/hid-framing";
import { identifyUSBProductId } from "@ledgerhq/devices";
import { identifyUSBProductId, identifyProductName } from "@ledgerhq/devices";
import type { DeviceModel } from "@ledgerhq/devices";
import { TransportError, DisconnectedDevice } from "@ledgerhq/errors";

Expand Down Expand Up @@ -93,9 +93,7 @@ export default class TransportNodeHidNoEvents extends Transport<?string> {
// $FlowFixMe
const info = device.getDeviceInfo();
this.deviceModel =
info && info.serialNumber
? identifyUSBProductId(parseInt(info.serialNumber, 16))
: null;
info && info.product ? identifyProductName(info.product) : null;
}

setDisconnected = () => {
Expand Down

0 comments on commit 7c92d92

Please sign in to comment.