Skip to content

Commit

Permalink
Examples and utils are now updated to use the requiered nfc_context
Browse files Browse the repository at this point in the history
  • Loading branch information
neomilium committed Dec 4, 2012
1 parent dc949c2 commit 5b0e276
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 103 deletions.
13 changes: 7 additions & 6 deletions examples/nfc-anticol.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ main(int argc, char *argv[])
}
}

nfc_init(NULL);
nfc_context *context;
nfc_init(&context);

// Try to open the NFC reader
pnd = nfc_open(NULL, NULL);
pnd = nfc_open(context, NULL);

if (!pnd) {
printf("Error opening NFC reader\n");
Expand Down Expand Up @@ -187,8 +188,8 @@ main(int argc, char *argv[])
if (!transmit_bits(abtReqa, 7)) {
printf("Error: No tag available\n");
nfc_close(pnd);
nfc_exit(NULL);
return 1;
nfc_exit(context);
return EXIT_FAILURE;
}
memcpy(abtAtqa, abtRx, 2);

Expand Down Expand Up @@ -317,6 +318,6 @@ main(int argc, char *argv[])
}

nfc_close(pnd);
nfc_exit(NULL);
return 0;
nfc_exit(context);
return EXIT_SUCCESS;
}
7 changes: 4 additions & 3 deletions examples/nfc-dep-initiator.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ main(int argc, const char *argv[])
return EXIT_FAILURE;
}

nfc_init(NULL);
nfc_context *context;
nfc_init(&context);

pnd = nfc_open(NULL, NULL);
pnd = nfc_open(context, NULL);
if (!pnd) {
printf("Unable to open NFC device.\n");
return EXIT_FAILURE;
Expand Down Expand Up @@ -110,6 +111,6 @@ main(int argc, const char *argv[])

error:
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
return EXIT_SUCCESS;
}
12 changes: 7 additions & 5 deletions examples/nfc-dep-target.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,20 @@ main(int argc, const char *argv[])
uint8_t abtRx[MAX_FRAME_LEN];
int szRx;
uint8_t abtTx[] = "Hello Mars!";

nfc_context *context;
nfc_init(&context);
#define MAX_DEVICE_COUNT 2
nfc_connstring connstrings[MAX_DEVICE_COUNT];
size_t szDeviceFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
size_t szDeviceFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
// Little hack to allow using nfc-dep-initiator & nfc-dep-target from
// the same machine: if there is more than one readers opened
// nfc-dep-target will open the second reader
// (we hope they're always detected in the same order)
nfc_init(NULL);
if (szDeviceFound == 1) {
pnd = nfc_open(NULL, connstrings[0]);
pnd = nfc_open(context, connstrings[0]);
} else if (szDeviceFound > 1) {
pnd = nfc_open(NULL, connstrings[1]);
pnd = nfc_open(context, connstrings[1]);
} else {
printf("No device found.\n");
return EXIT_FAILURE;
Expand Down Expand Up @@ -141,6 +143,6 @@ main(int argc, const char *argv[])

error:
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
return EXIT_SUCCESS;
}
10 changes: 6 additions & 4 deletions examples/nfc-emulate-forum-tag2.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ main(int argc, char *argv[])
};

signal(SIGINT, stop_emulation);
nfc_init(NULL);
pnd = nfc_open(NULL, NULL);

nfc_context *context;
nfc_init(&context);
pnd = nfc_open(context, NULL);

if (pnd == NULL) {
ERR("Unable to open NFC device");
Expand All @@ -200,14 +202,14 @@ main(int argc, char *argv[])
}

nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);

exit(EXIT_SUCCESS);

error:
if (pnd) {
nfc_perror(pnd, argv[0]);
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
}
}
9 changes: 5 additions & 4 deletions examples/nfc-emulate-tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

static uint8_t abtRx[MAX_FRAME_LEN];
static int szRx;
static nfc_context *context;
static nfc_device *pnd;
static bool quiet_output = false;
static bool init_mfc_auth = false;
Expand All @@ -68,7 +69,7 @@ intr_hdlr(int sig)
if (pnd != NULL) {
nfc_close(pnd);
}
nfc_exit(NULL);
nfc_exit(context);
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -181,10 +182,10 @@ main(int argc, char *argv[])
signal(SIGINT, intr_hdlr);
#endif

nfc_init(NULL);
nfc_init(&context);

// Try to open the NFC reader
pnd = nfc_open(NULL, NULL);
pnd = nfc_open(context, NULL);

// Display libnfc version
acLibnfcVersion = nfc_version();
Expand Down Expand Up @@ -270,7 +271,7 @@ main(int argc, char *argv[])
}

nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
exit(EXIT_SUCCESS);
}

9 changes: 5 additions & 4 deletions examples/nfc-emulate-uid.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ main(int argc, char *argv[])
signal(SIGINT, intr_hdlr);
#endif

nfc_init(NULL);
nfc_context *context;
nfc_init(&context);

// Try to open the NFC device
pnd = nfc_open(NULL, NULL);
pnd = nfc_open(context, NULL);

if (pnd == NULL) {
printf("Unable to open NFC device\n");
Expand Down Expand Up @@ -220,11 +221,11 @@ main(int argc, char *argv[])
}
}
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
exit(EXIT_SUCCESS);

error:
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
exit(EXIT_FAILURE);
}
11 changes: 6 additions & 5 deletions examples/nfc-mfsetuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ main(int argc, char *argv[])
}
}

nfc_init(NULL);
nfc_context *context;
nfc_init(&context);

// Try to open the NFC reader
pnd = nfc_open(NULL, NULL);
pnd = nfc_open(context, NULL);

if (!pnd) {
printf("Error opening NFC reader\n");
Expand Down Expand Up @@ -215,7 +216,7 @@ main(int argc, char *argv[])
if (!transmit_bits(abtReqa, 7)) {
printf("Error: No tag available\n");
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
return 1;
}
memcpy(abtAtqa, abtRx, 2);
Expand Down Expand Up @@ -354,6 +355,6 @@ main(int argc, char *argv[])


nfc_close(pnd);
nfc_exit(NULL);
return 0;
nfc_exit(context);
return EXIT_SUCCESS;
}
9 changes: 5 additions & 4 deletions examples/nfc-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ main(int argc, const char *argv[])
nfc_target nt;
int res = 0;

nfc_init(NULL);
nfc_context *context;
nfc_init(&context);

pnd = nfc_open(NULL, NULL);
pnd = nfc_open(context, NULL);

if (pnd == NULL) {
ERR("%s", "Unable to open NFC device.");
Expand All @@ -122,7 +123,7 @@ main(int argc, const char *argv[])
if ((res = nfc_initiator_poll_target(pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) {
nfc_perror(pnd, "nfc_initiator_poll_target");
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
exit(EXIT_FAILURE);
}

Expand All @@ -132,6 +133,6 @@ main(int argc, const char *argv[])
printf("No target found.\n");
}
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);
exit(EXIT_SUCCESS);
}
14 changes: 7 additions & 7 deletions examples/nfc-relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ main(int argc, char *argv[])
signal(SIGINT, intr_hdlr);
#endif

nfc_context *context;
nfc_init(&context);
nfc_connstring connstrings[MAX_DEVICE_COUNT];
// List available devices
size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);

if (szFound < 2) {
ERR("%zd device found but two opened devices are needed to relay NFC.", szFound);
return EXIT_FAILURE;
}

nfc_init(NULL);

// Try to open the NFC emulator device
pndTag = nfc_open(NULL, connstrings[0]);
pndTag = nfc_open(context, connstrings[0]);
if (pndTag == NULL) {
printf("Error opening NFC emulator device\n");
return EXIT_FAILURE;
Expand Down Expand Up @@ -152,7 +152,7 @@ main(int argc, char *argv[])
if ((szReaderRxBits = nfc_target_init(pndTag, &nt, abtReaderRx, sizeof(abtReaderRx), 0)) < 0) {
ERR("%s", "Initialization of NFC emulator failed");
nfc_close(pndTag);
nfc_exit(NULL);
nfc_exit(context);
return EXIT_FAILURE;
}
printf("%s", "Configuring emulator settings...");
Expand All @@ -164,7 +164,7 @@ main(int argc, char *argv[])
printf("%s", "Done, emulated tag is initialized");

// Try to open the NFC reader
pndReader = nfc_open(NULL, connstrings[1]);
pndReader = nfc_open(context, connstrings[1]);

printf("NFC reader device: %s opened", nfc_device_get_name(pndReader));
printf("%s", "Configuring NFC reader settings...");
Expand Down Expand Up @@ -222,6 +222,6 @@ main(int argc, char *argv[])

nfc_close(pndTag);
nfc_close(pndReader);
nfc_exit(NULL);
nfc_exit(context);
exit(EXIT_SUCCESS);
}
7 changes: 4 additions & 3 deletions examples/pn53x-diagnose.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,22 @@ main(int argc, const char *argv[])
errx(1, "usage: %s", argv[0]);
}

nfc_init(NULL);
nfc_context *context;
nfc_init(&context);

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

nfc_connstring connstrings[MAX_DEVICE_COUNT];
size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);

if (szFound == 0) {
printf("No NFC device found.\n");
}

for (i = 0; i < szFound; i++) {
pnd = nfc_open(NULL, connstrings[i]);
pnd = nfc_open(context, connstrings[i]);

if (pnd == NULL) {
ERR("%s", "Unable to open NFC device.");
Expand Down
7 changes: 4 additions & 3 deletions examples/pn53x-sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ main(int argc, const char *argv[])

int ret = EXIT_FAILURE;

nfc_init(NULL);
nfc_context *context;
nfc_init(&context);

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

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

if (pnd == NULL) {
ERR("%s", "Unable to open NFC device.");
Expand Down Expand Up @@ -211,7 +212,7 @@ main(int argc, const char *argv[])

// Close NFC device
nfc_close(pnd);
nfc_exit(NULL);
nfc_exit(context);

exit(ret);
}
9 changes: 5 additions & 4 deletions examples/pn53x-tamashell.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ int main(int argc, const char *argv[])
}
}

nfc_init(NULL);
nfc_context *context;
nfc_init(&context);

// Try to open the NFC reader
pnd = nfc_open(NULL, NULL);
pnd = nfc_open(context, NULL);

if (pnd == NULL) {
ERR("%s", "Unable to open NFC device.");
Expand Down Expand Up @@ -197,6 +198,6 @@ int main(int argc, const char *argv[])
fclose(input);
}
nfc_close(pnd);
nfc_exit(NULL);
return 1;
nfc_exit(context);
return EXIT_SUCCESS;
}
Loading

0 comments on commit 5b0e276

Please sign in to comment.