/
DeckTest.c
59 lines (44 loc) · 1.24 KB
/
DeckTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Program to test the deck make sure cards are read correctly
*/
#include <stdlib.h>
#include <nfc/nfc.h>
static void
print_card(const uint8_t *pbtData, const size_t szBytes)
{
}
int main(int argc, const char *argv[])
{
nfc_device *pnd;
nfc_target nt;
nfc_context *context;
nfc_init(&context);
if(context == NULL) {
printf("unable to init (malloc)\n");
exit(EXIT_FAILURE);
}
pnd = nfc_open(context, NULL);
if (pnd == NULL) {
printf("ERROR: %s\n", "Unable to open NFC Device.");
exit(EXIT_FAILURE);
}
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));
const nfc_modulation nmMifare = {
.nmt = NMT_ISO14443A,
.nbr = NBR_106,
};
for(int i = 0; i < 24; i++) {
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) {
printf("The following (NFC) card was found:\n");
print_card(nt.nti.nai.abtUid, nt.nti.nai.szUidLen);
}
while (0 == nfc_initiator_target_is_present(pnd, NULL)){}
}
nfc_close(pnd);
nfc_exit(context);
exit(EXIT_SUCCESS);
}