36 lines
800 B
C
36 lines
800 B
C
#include <err.h>
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include "poll_desfire.h"
|
|
|
|
int init(nfc_context **context, nfc_device **device) {
|
|
nfc_connstring devices[8];
|
|
size_t device_count;
|
|
|
|
nfc_init(context);
|
|
if (context == NULL) {
|
|
errx(EXIT_FAILURE, "Unable to init libnfc (malloc)");
|
|
}
|
|
|
|
device_count = nfc_list_devices(*context, devices, sizeof(devices) / sizeof(devices[0]));
|
|
if (device_count <= 0) {
|
|
errx(EXIT_FAILURE, "No NFC device found.");
|
|
}
|
|
|
|
if (device_count > 1) {
|
|
printf("More than 1 device available. Using %s\n", devices[0]);
|
|
}
|
|
|
|
*device = nfc_open(*context, devices[0]);
|
|
if (!device) {
|
|
errx(EXIT_FAILURE, "nfc_open() failed.");
|
|
}
|
|
|
|
if (nfc_initiator_init(*device) < 0) {
|
|
errx(EXIT_FAILURE, "Initiator failed.");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
void poll_target(nfc_device *device);
|