Skip to content

Empty Data  #46

Description

@cfontana0

Hey folks!
I'm trying to use the HCE feature on Android to transmit data from the phone to an ACR122 reader.
I was able to read the sent information from the Android phone with another phone, so, that means that it's transmitting correctly.
However, when I try to read the information using the ACR122 reader, I receive this as data:

New reader detected ACS ACR122U
Status( ACS ACR122U ): { state: 18, atr: <Buffer > }
card removed
Disconnected
Status( ACS ACR122U ): { state: 34, atr: <Buffer 3b 80 80 01 01> }
card inserted
Protocol( ACS ACR122U ): 2
Status( ACS ACR122U ): { state: 290, atr: <Buffer 3b 80 80 01 01> }
Data received <Buffer 69 86>

Any idea?

I'm running the following code:

const pcsclite = require('@pokusew/pcsclite');

const pcsc = pcsclite();

pcsc.on('reader', (reader) => {

    console.log('New reader detected', reader.name);

    reader.on('error', err => {
        console.log('Error(', reader.name, '):', err.message);
    });

    reader.on('status', (status) => {

        console.log('Status(', reader.name, '):', status);

        // check what has changed
        const changes = reader.state ^ status.state;

        if (!changes) {
            return;
        }

        if ((changes & reader.SCARD_STATE_EMPTY) && (status.state & reader.SCARD_STATE_EMPTY)) {

            console.log("card removed");

            reader.disconnect(reader.SCARD_LEAVE_CARD, err => {

                if (err) {
                    console.log(err);
                    return;
                }

                console.log('Disconnected');

            });

        }
        else if ((changes & reader.SCARD_STATE_PRESENT) && (status.state & reader.SCARD_STATE_PRESENT)) {

            console.log("card inserted");

            reader.connect({ share_mode: reader.SCARD_SHARE_SHARED }, (err, protocol) => {

                if (err) {
                    console.log(err);
                    return;
                }

                console.log('Protocol(', reader.name, '):', protocol);

                reader.transmit(Buffer.from([0x00, 0xB0, 0x00, 0x00, 0x20]), 40, protocol, (err, data) => {

                    if (err) {
                        console.log(err);
                        return;
                    }

                    console.log('Data received', data);
                    reader.close();
                    pcsc.close();

                });

            });

        }

    });

    reader.on('end', () => {
        console.log('Reader', reader.name, 'removed');
    });

});

pcsc.on('error', err => {
    console.log('PCSC error', err.message);
});

I also tried this library: https://github.com/pokusew/nfc-pcsc, but it requires defining an AID, should I do the same here?

Thanks,
Charlie

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions