Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Data #46

Open
cfontana0 opened this issue Nov 16, 2022 · 0 comments
Open

Empty Data #46

cfontana0 opened this issue Nov 16, 2022 · 0 comments

Comments

@cfontana0
Copy link

cfontana0 commented Nov 16, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant