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

EIO when send HLTA command #707

Open
tinytaro opened this issue Jan 12, 2024 · 0 comments
Open

EIO when send HLTA command #707

tinytaro opened this issue Jan 12, 2024 · 0 comments

Comments

@tinytaro
Copy link

Using the nfc_initiator_transceive_bytes function to send HLTA command to the mifare classic tag will fail and report an 'Input / Output Error'.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <nfc/nfc.h>
#include <mifare.h>

int main()
{
    nfc_context* context;
    nfc_device* reader;
    nfc_target card;

    nfc_init(&context);
    reader = nfc_open(context, "pn532_uart:com5");
    nfc_initiator_init(reader);

    nfc_modulation nm = {
        .nmt = NMT_ISO14443A,
        .nbr = NBR_106
    };

    int selected = nfc_initiator_select_passive_target(reader, nm, NULL, 0, &card);
    if (selected > 0)
    {
        mifare_param mp;
        uint8_t cmd[] = {0x50, 0x00};

        memcpy(mp.mpa.abtAuthUid, card.nti.nai.abtUid, 4);
        memset(mp.mpa.abtKey, 0xff, sizeof(mp.mpa.abtKey));

        if (nfc_initiator_mifare_cmd(reader, MC_AUTH_A, 0, &mp) == false)
        {
            printf("auth: %s\n", nfc_strerror(reader));
            return EXIT_FAILURE;
        }

        if (nfc_initiator_transceive_bytes(reader, cmd, sizeof(cmd), NULL, 0, -1) < 0)
        {
            printf("halt: %s\n", nfc_strerror(reader));
            return EXIT_FAILURE;
        }
    }

    nfc_close(reader);
    nfc_exit(context);
    return EXIT_SUCCESS;
}

output:

error	libnfc.driver.pn532_uart	Application level error detected
halt: Input / Output Error
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