0

I am building a node application, which should read information from an NFC reader connected through USB. I´m able to power up the device, I can read ATR, but unable to read UID of a card, when the card is connected.

I´m starting with node-usb and it gives me an instance of webUSB

    import { usb, getDeviceList, findByIds } from 'usb';
    import usbLib from 'usb';
    import { findBySerialNumber, WebUSBDevice } from 'usb';

const device= findByIds( 0x072F, 0x2200);  // Find usb device by ID

      const webDevice = await WebUSBDevice.createInstance(device);
  webDevice.open(); 
  webDevice.selectConfiguration(1);                           // open device
  webDevice.claimInterface(0);                                // claim interface

let powerUpDevice  = new Uint8Array([0x62,0x00,0x00,00x00,0x00,0x00,0x01,0x00,0x00]).buffer;

await webDevice.transferOut(2, powerUpDevice);  // powerUp => o.k.

//reading endpoint after poweringup
let result = await webDevice.transferIn(2, 64);
  console.log(result.data.buffer);

result in console :

ArrayBuffer { [Uint8Contents]: <80 14 00 00 00 00 00 00 81 00 3b 8f 80 01 80 4f 0c a0 00 00 03 06 03 00 01 00 00 00 00 6a>, byteLength: 30 }

it is the right ATR if the reader detects a PICC. But now I want to read the UID tag of the inserted card. After reading and researching I´m lost. Maybe there should be some control transfer and then I should be able to read the UID tag.

something like this:

 let setup =    {
    requestType: 'class',
    recipient: 'interface',
    request: 0x00,
    value: 0x00,
    index: 0x00
        }    ;

        let abc = await webDevice.controlTransferOut(setup);

        const getCardUID = new Uint8Array([0xff,0xca, 0x00, 0x00, 0x04]).buffer;
        let getUID = await webDevice.transferOut(2, getCardUID);

        result = await webDevice.transferIn(2, 64);
        console.log(result.data.buffer);

running it returns nothing. Can anyone help me?

Thank You!

  • What does "unable to read UID of a card" mean? Do you have any code for it but it crashes, or returns incorrect data, or is stuck? Or don't you have any code at all? – Codo Aug 31 '22 at 14:01
  • BTW: open(), setConfiguration() and claimInterface() are async method. So you need to use "await" as well. As the code is now, it's surprising it works as they will run in parallel. – Codo Aug 31 '22 at 14:02
  • I added "await", the result stays the same. After "let getUID = await webDevice.transferOut(2, getCardUID);" the "result = await webDevice.transferIn(2, 64);" should deliver UID, but it keeps hanging there.... – Jarda Hrbacek Aug 31 '22 at 14:22
  • What is the control request supposed to do? In the USB CCID spec, I can't see a valid request with a request value of 0x00. – Codo Aug 31 '22 at 14:32
  • Maybe that´s my problem. Where can I find the right values for the command? – Jarda Hrbacek Aug 31 '22 at 14:37
  • What do you want to achieve with the control request anyway? Have you tried without it? The USB class for smart readers is described here: https://usb.org/sites/default/files/DWG_Smart-Card_CCID_Rev110.pdf – Codo Aug 31 '22 at 18:18
  • The only thing I want is to get the serial number of the inserted card. According to the vendor documentation : Example: 1. To get the serial number of the connected PICC. UINT8 GET_UID[5]={FFh, CAh, 00h, 00h, 04h}; – Jarda Hrbacek Sep 01 '22 at 04:44

0 Answers0