Examples and utils are now updated to use the requiered nfc_context
This commit is contained in:
parent
dc949c257e
commit
5b0e276572
20 changed files with 136 additions and 103 deletions
|
|
@ -366,10 +366,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 == NULL) {
|
||||
ERR("Unable to open NFC device");
|
||||
|
|
@ -393,6 +394,6 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,6 +253,6 @@ main(int argc, const char *argv[])
|
|||
nfc_close(pnd);
|
||||
}
|
||||
|
||||
nfc_exit(NULL);
|
||||
return 0;
|
||||
nfc_exit(context);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
#include "mifare.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
static nfc_context *context;
|
||||
static nfc_device *pnd;
|
||||
static nfc_target nt;
|
||||
static mifare_param mp;
|
||||
|
|
@ -508,10 +509,10 @@ main(int argc, const char *argv[])
|
|||
}
|
||||
// printf("Successfully opened required files\n");
|
||||
|
||||
nfc_init(NULL);
|
||||
nfc_init(&context);
|
||||
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
pnd = nfc_open(context, NULL);
|
||||
if (pnd == NULL) {
|
||||
printf("Error opening NFC reader\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
@ -536,7 +537,7 @@ main(int argc, const char *argv[])
|
|||
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) {
|
||||
printf("Error: no tag was found\n");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Test if we are dealing with a MIFARE compatible tag
|
||||
|
|
@ -596,6 +597,6 @@ main(int argc, const char *argv[])
|
|||
break;
|
||||
};
|
||||
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,10 +204,11 @@ main(int argc, const char *argv[])
|
|||
}
|
||||
DBG("Successfully opened the dump file\n");
|
||||
|
||||
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) {
|
||||
ERR("Error opening NFC device\n");
|
||||
return 1;
|
||||
|
|
@ -230,15 +231,15 @@ main(int argc, const char *argv[])
|
|||
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) {
|
||||
ERR("no tag was found\n");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
return 1;
|
||||
nfc_exit(context);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Test if we are dealing with a MIFARE compatible tag
|
||||
|
||||
if (nt.nti.nai.abtAtqa[1] != 0x44) {
|
||||
ERR("tag is not a MIFARE Ultralight card\n");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Get the info from the current tag
|
||||
|
|
@ -270,6 +271,6 @@ main(int argc, const char *argv[])
|
|||
}
|
||||
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,9 +192,10 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
nfc_init(NULL);
|
||||
nfc_context *context;
|
||||
nfc_init(&context);
|
||||
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
pnd = nfc_open(context, NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR("Unable to open NFC device");
|
||||
|
|
@ -314,6 +315,6 @@ error:
|
|||
if (pnd) {
|
||||
nfc_close(pnd);
|
||||
}
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,11 +195,12 @@ main(int argc, char *argv[])
|
|||
signal(SIGINT, intr_hdlr);
|
||||
#endif
|
||||
|
||||
nfc_init(NULL);
|
||||
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 (initiator_only_mode || target_only_mode) {
|
||||
if (szFound < 1) {
|
||||
|
|
@ -222,9 +223,9 @@ main(int argc, char *argv[])
|
|||
// if there is more than one readers opened we open the second reader
|
||||
// (we hope they're always detected in the same order)
|
||||
if ((szFound == 1) || swap_devices) {
|
||||
pndInitiator = nfc_open(NULL, connstrings[0]);
|
||||
pndInitiator = nfc_open(context, connstrings[0]);
|
||||
} else {
|
||||
pndInitiator = nfc_open(NULL, connstrings[1]);
|
||||
pndInitiator = nfc_open(context, connstrings[1]);
|
||||
}
|
||||
|
||||
if (!pndInitiator) {
|
||||
|
|
@ -237,7 +238,7 @@ main(int argc, char *argv[])
|
|||
if (nfc_initiator_init(pndInitiator) < 0) {
|
||||
printf("Error: fail initializing initiator\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +250,7 @@ main(int argc, char *argv[])
|
|||
if (nfc_initiator_select_passive_target(pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) {
|
||||
printf("Error: no tag was found\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -259,25 +260,25 @@ main(int argc, char *argv[])
|
|||
if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while printing UID to FD4\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (print_hex_fd4(ntRealTarget.nti.nai.abtAtqa, 2, "ATQA") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while printing ATQA to FD4\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (print_hex_fd4(&(ntRealTarget.nti.nai.btSak), 1, "SAK") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while printing SAK to FD4\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (print_hex_fd4(ntRealTarget.nti.nai.abtAts, ntRealTarget.nti.nai.szAtsLen, "ATS") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while printing ATS to FD4\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
@ -301,7 +302,7 @@ main(int argc, char *argv[])
|
|||
if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtUid, &(ntEmulatedTarget.nti.nai.szUidLen), "UID") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while scanning UID from FD3\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAtqa, &foo, "ATQA") != EXIT_SUCCESS) {
|
||||
|
|
@ -312,13 +313,13 @@ main(int argc, char *argv[])
|
|||
if (scan_hex_fd3(&(ntEmulatedTarget.nti.nai.btSak), &foo, "SAK") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while scanning SAK from FD3\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAts, &(ntEmulatedTarget.nti.nai.szAtsLen), "ATS") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while scanning ATS from FD3\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -358,16 +359,16 @@ main(int argc, char *argv[])
|
|||
|
||||
// Try to open the NFC emulator device
|
||||
if (swap_devices) {
|
||||
pndTarget = nfc_open(NULL, connstrings[1]);
|
||||
pndTarget = nfc_open(context, connstrings[1]);
|
||||
} else {
|
||||
pndTarget = nfc_open(NULL, connstrings[0]);
|
||||
pndTarget = nfc_open(context, connstrings[0]);
|
||||
}
|
||||
if (pndTarget == NULL) {
|
||||
printf("Error opening NFC emulator device\n");
|
||||
if (!target_only_mode) {
|
||||
nfc_close(pndInitiator);
|
||||
}
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +380,7 @@ main(int argc, char *argv[])
|
|||
nfc_close(pndInitiator);
|
||||
}
|
||||
nfc_close(pndTarget);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("%s\n", "Done, relaying frames now!");
|
||||
|
|
@ -396,7 +397,7 @@ main(int argc, char *argv[])
|
|||
nfc_close(pndInitiator);
|
||||
}
|
||||
nfc_close(pndTarget);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
szCapduLen = (size_t) res;
|
||||
|
|
@ -404,7 +405,7 @@ main(int argc, char *argv[])
|
|||
if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while printing C-APDU to FD4\n");
|
||||
nfc_close(pndTarget);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
@ -412,7 +413,7 @@ main(int argc, char *argv[])
|
|||
if (scan_hex_fd3(abtCapdu, &szCapduLen, "C-APDU") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while scanning C-APDU from FD3\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
@ -434,7 +435,7 @@ main(int argc, char *argv[])
|
|||
if (scan_hex_fd3(abtRapdu, &szRapduLen, "R-APDU") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while scanning R-APDU from FD3\n");
|
||||
nfc_close(pndTarget);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
ret = true;
|
||||
|
|
@ -461,16 +462,16 @@ main(int argc, char *argv[])
|
|||
}
|
||||
if (!initiator_only_mode) {
|
||||
nfc_close(pndTarget);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
}
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "Error while printing R-APDU to FD4\n");
|
||||
nfc_close(pndInitiator);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
@ -483,7 +484,7 @@ main(int argc, char *argv[])
|
|||
if (!initiator_only_mode) {
|
||||
nfc_close(pndTarget);
|
||||
}
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,8 @@ main(int argc, const char *argv[])
|
|||
size_t i;
|
||||
bool verbose = false;
|
||||
|
||||
nfc_init(NULL);
|
||||
nfc_context *context;
|
||||
nfc_init(&context);
|
||||
|
||||
// Display libnfc version
|
||||
acLibnfcVersion = nfc_version();
|
||||
|
|
@ -105,7 +106,7 @@ main(int argc, const char *argv[])
|
|||
#endif
|
||||
|
||||
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);
|
||||
|
||||
int res = EXIT_FAILURE;
|
||||
if (szDeviceFound == 0) {
|
||||
|
|
@ -116,7 +117,7 @@ main(int argc, const char *argv[])
|
|||
printf("%d NFC device(s) found:\n", (int)szDeviceFound);
|
||||
char *strinfo = NULL;
|
||||
for (i = 0; i < szDeviceFound; i++) {
|
||||
pnd = nfc_open(NULL, connstrings[i]);
|
||||
pnd = nfc_open(context, connstrings[i]);
|
||||
if (pnd != NULL) {
|
||||
printf("- %s:\n %s\n", nfc_device_get_name(pnd), nfc_device_get_connstring(pnd));
|
||||
if (verbose) {
|
||||
|
|
@ -133,6 +134,6 @@ main(int argc, const char *argv[])
|
|||
res = EXIT_SUCCESS;
|
||||
|
||||
bye:
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue