Skip to content

Commit

Permalink
Use libusb to differenciate NK3
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Nov 20, 2024
1 parent d640aa0 commit 02d0994
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/operations_ccid.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,24 @@ int status_ccid(libusb_device_handle *handle, struct ResponseStatus *response) {
uint8_t buf[1024] = {};
IccResult iccResult = {};
bool pin_counter_is_error = false;
int r;
libusb_device *usb_dev;
struct libusb_device_descriptor usb_desc;
usb_dev = libusb_get_device(handle);

r = libusb_get_device_descriptor(usb_dev, &usb_desc);

if (r < 0) {
return r;
}


if (usb_desc.idVendor == 0x20a0 && usb_desc.idProduct == 0x42b2) {
r = send_select_nk3_admin_ccid(handle, buf, sizeof buf, &iccResult);
if (r != RET_NO_ERROR) {
return r;
}

int r = send_select_nk3_admin_ccid(handle, buf, sizeof buf, &iccResult);
if (r != RET_NO_ERROR || iccResult.data_status_code != 0x9000) {
response->is_nk3 = false;
printf("Not an NK3\n");
} else {
response->is_nk3 = true;

uint8_t data_iso[MAX_CCID_BUFFER_SIZE] = {};
Expand All @@ -310,6 +322,9 @@ int status_ccid(libusb_device_handle *handle, struct ResponseStatus *response) {
rassert(iccResult.data_status_code == 0x9000);
rassert(iccResult.data_len == 6);
response->firmware_version_nk3.firmware_version = be32toh(*(uint32_t *) iccResult.data);
} else {
response->is_nk3 = false;
printf("Not an NK3\n");
}

r = send_select_ccid(handle, buf, sizeof buf, &iccResult);
Expand Down

0 comments on commit 02d0994

Please sign in to comment.