Libnfc如何阅读NFC卡内容?

Libnfc如何阅读NFC卡内容?,nfc,acr122,lib-nfc,Nfc,Acr122,Lib Nfc,我尝试使用ACR122读卡器简单地读取ISO 14443-2B ST SRx卡内容 我已经用Libnfc和合适的读卡器驱动程序设置了我的环境 现在我已经写了一个代码,只需读取卡的UID并打印出来。 根本没有文档,我完全不知道从哪里开始阅读卡片内容。有线索或代码片段吗 这就是我所做的: // To compile this simple example: // $ gcc -o quick_start_example1 quick_start_example1.c -lnfc // ./q

我尝试使用ACR122读卡器简单地读取ISO 14443-2B ST SRx卡内容

我已经用Libnfc和合适的读卡器驱动程序设置了我的环境

现在我已经写了一个代码,只需读取卡的UID并打印出来。 根本没有文档,我完全不知道从哪里开始阅读卡片内容。有线索或代码片段吗

这就是我所做的:

    // To compile this simple example:
// $ gcc -o quick_start_example1 quick_start_example1.c -lnfc
// ./quick_start_example1

#include <stdlib.h>
#include <nfc/nfc.h>

void print_nfc_target(const nfc_target *pnt, bool verbose)
{
  char *s;
  str_nfc_target(&s, pnt, verbose);
  printf("%s", s);
  nfc_free(s);
}

int main(int argc, const char *argv[])
{
    nfc_device *pnd;
    nfc_target nt;

    // Allocate only a pointer to nfc_context
    nfc_context *context;

    // Initialize libnfc and set the nfc_context
    nfc_init(&context);
    if (context == NULL) {
      printf("Unable to init libnfc (malloc)\n");
      exit(EXIT_FAILURE);
    }

    // Display libnfc version
    const char *acLibnfcVersion = nfc_version();
    (void)argc;
    printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);

    // Open, using the first available NFC device
    pnd = nfc_open(context, NULL);

    if (pnd == NULL) {
      printf("ERROR: %s\n", "Unable to open NFC device.");
      exit(EXIT_FAILURE);
    }
    // Set opened NFC device to initiator mode
    if (nfc_initiator_init(pnd) < 0) {
      nfc_perror(pnd, "nfc_initiator_init");
      exit(EXIT_FAILURE);
    }

    printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));

    nfc_target ant[1];
    nfc_modulation nm;
    nm.nmt = NMT_ISO14443B;
    nm.nbr = NBR_106;

    nfc_initiator_list_passive_targets(pnd,nm,ant,1);
    printf("%s\n",nfc_strerror(pnd)); // print Success

    nfc_target ant2[1];
    nfc_modulation nm2;
    nm2.nmt = NMT_ISO14443B2SR;
    nm2.nbr = NBR_106;

    int res = 0;
    int n = 0;
    res = nfc_initiator_list_passive_targets(pnd, nm2, ant2, 1);
    printf("%s\n",nfc_strerror(pnd)); // print Success

    // printf("Cart identifier: %s\n", nt.nti.nsi.abtUID);
    for (n = 0; n < res; n++) {
      print_nfc_target(&ant2[n], true);
      printf("\n");
    }

    // Close NFC device
    nfc_close(pnd);
    // Release the context
    nfc_exit(context);
    exit(EXIT_SUCCESS);
}

PS:由于一个已知的错误,我列出了2倍的目标。首先,这是我如何开始、获取和阅读卡交易的命令,包括命令apdu及其编写方式、响应apdu及其处理方式、响应代码、状态字节码e.t.c。然后,获得上述书籍附带的书籍1-5。另外,还可以获得这本书,它将指导您完成学习如何开发EMV卡应用程序所需的每个步骤。希望对您有所帮助。

首先,我是如何开始、获取和阅读卡交易的命令的,包括命令apdu及其编写方式、响应apdu及其处理方式、响应代码、状态字节码e.t.c。然后获取上述书籍附带的书籍1-5。另外,还可以获得这本书,它将指导您完成学习如何开发EMV卡应用程序所需的每个步骤。希望对您有所帮助。

我编写了一个小帮助程序,使用LibNFC读取ST SRx标记:


它仍然需要一些更改才能写入它们,但它确实成功地读取了它们。

我编写了一个小的帮助程序,使用LibNFC读取ST SRx标记:


它仍然需要一些更改才能写入它们,但它确实成功地读取了它们。

也许我遗漏了一些东西,但问题中特别提到的ST's SR非接触式内存ISO 14443-2B ST SRx与APDU和EMV支付卡完全无关。我不知道,我会检查它。但是上面使用的代码是我在应用程序中读取nfc卡的代码的一部分,也是我开始学习读取nfc卡的地方,这就是为什么我请@user1118094查看这些教程。也许我错过了一些东西,但ST的SR非接触式内存ISO 14443-2B ST SRx,正如在问题中特别提到的,它们与APDU和EMV支付卡完全无关。我不知道,我会检查一下。但是上面使用的代码是我在应用程序中阅读nfc卡时使用的代码的一部分,也是我开始学习阅读nfc卡的地方,这就是为什么我请@user1118094查看这些教程。你找到答案了吗?我在努力做同样的事情你找到答案了吗?我也在努力做到这一点