nfc_context *edgehog_nfc_get_context() { nfc_context *context; nfc_init(&context); return context; }
/** * @brief Function for application main entry. */ int main(void) { uint32_t err_code; clock_init(); // Start APP_TIMER to generate timeouts. APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL); leds_init(); err_code = bsp_init(BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), bsp_evt_handler); APP_ERROR_CHECK(err_code); nfc_init(); m_active_led_mask = BSP_LED_0_MASK; err_code = led_softblink_start(m_active_led_mask); APP_ERROR_CHECK(err_code); while (true) { __WFE(); softblink_led_update(); } }
static PyObject * my_nfc_open() //PyObject *self, PyObject *args) { // Initialize libnfc and set the nfc_context nfc_init(&context); if (context == NULL) { printf("Unable to init libnfc (malloc)\n"); exit(EXIT_FAILURE); } // Open, using the first available NFC device which can be in order of selection: // - default device specified using environment variable or // - first specified device in libnfc.conf (/etc/nfc) or // - first specified device in device-configuration directory (/etc/nfc/devices.d) or // - first auto-detected (if feature is not disabled in libnfc.conf) 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)); return Py_BuildValue(""); }
/** * @brief set gpios as nand Ce pin, and get the chip id and chip count detected * @author Yang Yiming * @date 2012-12-25 * @param [out]pChipID the ID of nandflash detected * @param [out]pChipCnt the amount of nandflash detected * @param [in]pCePos the GPIOs connected to nandflash Ce, 0xFF for default pin * @param [in]nCeCnt the GPIOs amount to be set, not more than 4 * @return T_VOID */ T_VOID nand_setCe_getID(T_U32 pChipID[2], T_U32 *pChipCnt, T_U8 *pCePos, T_U32 nCeCnt) { T_U32 i; T_U32 aID[NAND_ID_LEN / 4]; nfc_init(pCePos, nCeCnt); for (i = 0; i < nCeCnt; i++) { nfc_select(i, AK_TRUE); nfc_cycle(CMD_CYCLE(NFLASH_RESET), DELAY_CYCLE(240), END_CYCLE); nfc_cycle(CMD_CYCLE(NFLASH_ID), ADDR_CYCLE(0), DELAY_CYCLE(8), END_CYCLE); nfc_read((T_U8*)aID, AK_NULL, NAND_ID_LEN, AK_NULL); nfc_select(i, AK_FALSE); if (0xFFFFFFFF == aID[0]) { break; } pChipID[0] = aID[0]; pChipID[1] = aID[1]&0xffff; } *pChipCnt = i; }
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); // Display libnfc version const char *acLibnfcVersion = nfc_version(); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); // Open, using the first available NFC device which can be in order of selection: // - default device specified using environment variable or // - first specified device in libnfc.conf (/etc/nfc) or // - first specified device in device-configuration directory (/etc/nfc/devices.d) or // - first auto-detected (if feature is not disabled in libnfc.conf) device pnd = nfc_open(context, NULL); if (pnd == NULL) { warnx("ERROR: %s", "Unable to open NFC device."); return 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)); // Poll for a ISO14443A (MIFARE) tag const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) { printf("The following (NFC) ISO14443A tag was found:\n"); printf(" ATQA (SENS_RES): "); print_hex(nt.nti.nai.abtAtqa, 2); printf(" UID (NFCID%c): ", (nt.nti.nai.abtUid[0] == 0x08 ? '3' : '1')); print_hex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen); printf(" SAK (SEL_RES): "); print_hex(&nt.nti.nai.btSak, 1); if (nt.nti.nai.szAtsLen) { printf(" ATS (ATR): "); print_hex(nt.nti.nai.abtAts, nt.nti.nai.szAtsLen); } } // Close NFC device nfc_close(pnd); // Release the context nfc_exit(context); return EXIT_SUCCESS; }
ResultBool LibNfc::init() { nfc_init(&_context); if (!_context) { return ResultBool::error("LibNfc could not be initialized"); } return ResultBool::ok(true); }
void TagInit(ReaderTag *rt){ nfc_init(&rt->context); if (rt->context == NULL) { ERR("Unable to init libnfc (malloc)"); exit(EXIT_FAILURE); } // Try to open the NFC device rt->device = nfc_open(rt->context, NULL); if (rt->device == NULL) { ERR("Error opening NFC device"); nfc_exit(rt->context); exit(EXIT_FAILURE); } if (nfc_initiator_init(rt->device) < 0) { nfc_perror(rt->device, "nfc_initiator_init"); nfc_close(rt->device); nfc_exit(rt->context); exit(EXIT_FAILURE); } // Scan until the cows come home, or the tag, which ever comes first. if (nfc_device_set_property_bool(rt->device, NP_INFINITE_SELECT, true) < 0) { nfc_perror(rt->device, "nfc_device_set_property_bool"); nfc_close(rt->device); nfc_exit(rt->context); exit(EXIT_FAILURE); } printf("NFC device: %s opened\n", nfc_device_get_name(rt->device)); printf("\nWaiting for tag\n"); // Try to find a MIFARE Ultralight tag if (nfc_initiator_select_passive_target(rt->device, nmMifare, NULL, 0, &rt->nt) <= 0) { ERR("no tag was found\n"); nfc_close(rt->device); nfc_exit(rt->context); exit(EXIT_FAILURE); } // Test if we are dealing with a MIFARE compatible tag if (rt->nt.nti.nai.abtAtqa[1] != 0x44) { ERR("tag is not a MIFARE Ultralight card\n"); nfc_close(rt->device); nfc_exit(rt->context); exit(EXIT_FAILURE); } // Get the info from the current tag printf("Found MIFARE Ultralight card with UID: "); size_t szPos; for (szPos = 0; szPos < rt->nt.nti.nai.szUidLen; szPos++) { printf("%02x", rt->nt.nti.nai.abtUid[szPos]); } printf("\n"); }
bool verification_libnfc(QLabel* label_conf_libnfc, QLabel* Message_utilisateur){ Message_utilisateur->setText("Detecting libNFC"); nfc_context* context; nfc_init(&context); bool res= verification_libnfc_context(&context,label_conf_libnfc, Message_utilisateur); nfc_exit(context); return res; }
silvia_nfc_card_monitor::silvia_nfc_card_monitor() { nfc_init(&context); device = nfc_open(context, NULL); if (device != NULL) { nfc_initiator_init(device); } }
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 libnfc (malloc)\n"); exit(EXIT_FAILURE); } const char *acLibnfcVersion = nfc_version(); (void)argc; printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); 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)); for( ; ; ){ const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) { printf("The following (NFC) ISO14443A tag was found:\n"); printf(" ATQA (SENS_RES): "); print_hex(nt.nti.nai.abtAtqa, 2); printf(" UID (NFCID%c): ", (nt.nti.nai.abtUid[0] == 0x08 ? '3' : '1')); print_hex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen); printf(" SAK (SEL_RES): "); print_hex(&nt.nti.nai.btSak, 1); if (nt.nti.nai.szAtsLen) { printf(" ATS (ATR): "); print_hex(nt.nti.nai.abtAts, nt.nti.nai.szAtsLen); } sleep(3); } } nfc_close(pnd); nfc_exit(context); exit(EXIT_SUCCESS); }
nfc_device *rfid_init(void) { nfc_init(&nfc_ctx); if(!nfc_ctx) { log("initializing libnfc failed"); return NULL; } door_aid = mifare_desfire_aid_new(0x2305CA); nfc_connstring devices[NFC_MAX_DEVICES]; int device_count = nfc_list_devices(nfc_ctx, devices, NFC_MAX_DEVICES); if(device_count <= 0) { log("no NFC devices found"); return NULL; } log("found %u NFC devices:", device_count); for(int i = 0; i < device_count; i++) log(" - %s", devices[i]); int selected_device = -1; const char *conf_connstring = getenv("RFID_CONNSTRING"); if(conf_connstring) { for(int i = 0; i < device_count; i++) if(strstr(devices[i], conf_connstring)) { selected_device = i; break; } } else { log("no connection string supplied, using first device"); selected_device = 0; } if(selected_device == -1) { log("could not find requested device"); return NULL; } log("using device %s", devices[selected_device]); nfc_device *dev = nfc_open(nfc_ctx, devices[selected_device]); if(!dev) { log("opening NFC device failed"); return NULL; } if(nfc_initiator_init(dev) < 0) { nfc_perror(dev, "configuring NFC device as initiator failed"); return NULL; } return dev; }
bool nfosc_check() { nfc_context *test_context; nfc_connstring test_strings[MAX_DEVICE_COUNT]; nfc_init(&test_context); if (test_context == NULL) return false; size_t szFound = nfc_list_devices (test_context, test_strings, MAX_DEVICE_COUNT); nfc_exit(context); if (szFound) return true; else return false; }
void cut_setup (void) { int res; nfc_connstring devices[8]; size_t device_count; nfc_init (&context); cut_assert_not_null (context, cut_message ("Unable to init libnfc (malloc)")); device_count = nfc_list_devices (context, devices, 8); if (device_count <= 0) cut_omit ("No device found"); for (size_t i = 0; i < device_count; i++) { device = nfc_open (context, devices[i]); if (!device) cut_omit ("nfc_open() failed."); tags = freefare_get_tags (device); cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed")); tag = NULL; for (int i=0; tags[i]; i++) { if (freefare_get_tag_type(tags[i]) == MIFARE_DESFIRE) { tag = tags[i]; res = mifare_desfire_connect (tag); cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed")); struct mifare_desfire_version_info version_info; res = mifare_desfire_get_version (tag, &version_info); cut_assert_equal_int (0, res, cut_message ("mifare_desfire_get_version")); if (version_info.hardware.storage_size < 0x18) { cut_omit ("DESFire EV1 tests require at least a 4K card"); } if ((version_info.hardware.version_major >= 1) && (version_info.software.version_major >= 1)) { return; } mifare_desfire_disconnect (tag); } } nfc_close (device); device = NULL; freefare_free_tags (tags); tags = NULL; } cut_omit ("No MIFARE DESFire EV1 tag on NFC device"); }
int main(int argc, const char *argv[]) { system("clear"); 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); // Display libnfc version const char *acLibnfcVersion = nfc_version(); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); // Open, using the first available NFC device. pnd = nfc_open(context, NULL); if (pnd == NULL) { warnx("ERROR: %s", "Unable to open NFC device."); return 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)); printf("...\n", nfc_device_get_name(pnd)); while (true){ // Poll for a ISO14443A (MIFARE) tag const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) { print_hex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen); } sleep(1); } // Close NFC device nfc_close(pnd); // Release the context nfc_exit(context); return EXIT_SUCCESS; }
uint_32 nfc_wl_init ( /* [IN] the NAND flash information */ IO_NANDFLASH_STRUCT_PTR nandflash_ptr ) { /* Body */ uint_32 num_metadata_bytes; uint_32 num_ecc_bytes; uint_32 result = NANDFLASHERR_NO_ERROR; result = nfc_init(nandflash_ptr); switch(nandflash_ptr->ECC_SIZE) { case 0: curr_ecc_mode = 0; break; case 4: curr_ecc_mode = 1; break; case 6: curr_ecc_mode = 2; break; case 8: curr_ecc_mode = 3; break; case 12: curr_ecc_mode = 4; break; case 16: curr_ecc_mode = 5; break; case 24: curr_ecc_mode = 6; break; case 32: curr_ecc_mode = 7; break; default: curr_ecc_mode = 0; break; } num_ecc_bytes = NANDFLASH_ECC_SIZE_TO_NUM_BYTES_CONV(nandflash_ptr->ECC_SIZE); num_metadata_bytes = nandflash_ptr->NANDFLASH_INFO_PTR->SPARE_AREA_SIZE/nandflash_ptr->PHY_PAGE_SIZE_TO_VIRTUAL_PAGE_SIZE_RATIO - num_ecc_bytes; /* In case we arrange the page layout as Data-Metadata-ECC, we need to use another swap_addr1 */ nfc_swap_addr1_with_metadata = ((nandflash_ptr->NANDFLASH_INFO_PTR->PHY_PAGE_SIZE)- ((nandflash_ptr->PHY_PAGE_SIZE_TO_VIRTUAL_PAGE_SIZE_RATIO - 1) * (nandflash_ptr->VIRTUAL_PAGE_SIZE + num_ecc_bytes + num_metadata_bytes)))/8; NFC_LOG("NFC_INIT nfc_swap_addr1_with_metadata*8=%d\n", nfc_swap_addr1_with_metadata); return result; } /* Endbody */
void cut_setup(void) { size_t n = nfc_list_devices(NULL, connstrings, 2); if (n < 2) { cut_omit("At least two NFC devices must be plugged-in to run this test"); } nfc_init(NULL); devices[TARGET] = nfc_open(NULL, connstrings[TARGET]); devices[INITIATOR] = nfc_open(NULL, connstrings[INITIATOR]); signal(SIGINT, abort_test_by_keypress); }
int main (int argc, const char *argv[]) { nfc_device *pnd; nfc_target nt; nfc_init (NULL); // Display libnfc version const char *acLibnfcVersion = nfc_version (); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); // Open, using the first available NFC device pnd = nfc_open (NULL, NULL); if (pnd == NULL) { ERR ("%s", "Unable to open NFC device."); return 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)); // Poll for a ISO14443A (MIFARE) tag const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) > 0) { printf ("The following (NFC) ISO14443A tag was found:\n"); printf (" ATQA (SENS_RES): "); print_hex (nt.nti.nai.abtAtqa, 2); printf (" UID (NFCID%c): ", (nt.nti.nai.abtUid[0] == 0x08 ? '3' : '1')); print_hex (nt.nti.nai.abtUid, nt.nti.nai.szUidLen); printf (" SAK (SEL_RES): "); print_hex (&nt.nti.nai.btSak, 1); if (nt.nti.nai.szAtsLen) { printf (" ATS (ATR): "); print_hex (nt.nti.nai.abtAts, nt.nti.nai.szAtsLen); } } // Close NFC device nfc_close (pnd); nfc_exit (NULL); return EXIT_SUCCESS; }
void cut_setup(void) { nfc_init(&context); size_t n = nfc_list_devices(context, connstrings, 2); if (n < 2) { cut_omit("At least two NFC devices must be plugged-in to run this test"); } second_device = nfc_open(context, connstrings[0]); first_device = nfc_open(context, connstrings[1]); signal(SIGINT, abort_test_by_keypress); }
int 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(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) if (szDeviceFound == 1) { pnd = nfc_open(context, connstrings[0]); } else if (szDeviceFound > 1) { pnd = nfc_open(context, connstrings[1]); } else { printf("No device found.\n"); return EXIT_FAILURE; } if (argc > 1) { printf("Usage: %s\n", argv[0]); return EXIT_FAILURE; } nfc_target nt = { .nm = { .nmt = NMT_DEP, .nbr = NBR_UNDEFINED }, .nti = { .ndi = { .abtNFCID3 = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00 }, .szGB = 4, .abtGB = { 0x12, 0x34, 0x56, 0x78 }, .ndm = NDM_UNDEFINED, /* These bytes are not used by nfc_target_init: the chip will provide them automatically to the initiator */ .btDID = 0x00, .btBS = 0x00, .btBR = 0x00, .btTO = 0x00, .btPP = 0x01, }, },
int main(int argc, char** argv) { memset(&mtDump, 0x00, sizeof(mtDump)); Credentials crd; char cmd[200]; signal(SIGINT, stop_polling); nfc_init(&RT.context); if (RT.context == NULL) { ERR("Unable to init libnfc (malloc)"); exit(EXIT_FAILURE); } TagInit(&RT); while(run){ if(ScanForTag(&RT)){ if(N_read_card(RT,&mtDump)){ if(NDDEF_DEGenerate(&crd, &mtDump)){ if(Credentials_Check(&crd)){ printf("\nGood\n"); memset(cmd, 0x00, sizeof(cmd)); //snprintf(cmd,200,"startx /usr/bin/nice -n 18 /usr/bin/rdesktop -a 24 -x 6 -P -r sound:local -u %s -p %s -f %s",crd.user,crd.password, crd.VM); //printf("%s",cmd); //system(cmd); printf("Waiting for card removing..."); sleep(1); while (0 == nfc_initiator_target_is_present(RT.device, NULL)) {} nfc_perror(RT.device, "nfc_initiator_target_is_present"); printf("done.\n"); } } } } //nfc_idle(RT.device); //nfc_exit(RT.context); sleep(1); } if (RT.device != NULL) nfc_abort_command(RT.device); else { nfc_exit(RT.context); exit(EXIT_SUCCESS); } }
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) { exit(EXIT_FAILURE); } // Display libnfc version const char *acLibnfcVersion = nfc_version(); (void)argc; // Open, using the first available NFC device which can be in order of selection: // - default device specified using environment variable or // - first specified device in libnfc.conf (/etc/nfc) or // - first specified device in device-configuration directory (/etc/nfc/devices.d) or // - first auto-detected (if feature is not disabled in libnfc.conf) device pnd = nfc_open(context, NULL); if (pnd == NULL) { 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); } // Poll for a ISO14443A (MIFARE) tag nfc_modulation nmMifare; nmMifare.nmt = NMT_ISO14443A; nmMifare.nbr = NBR_106; if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) print_hex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen); // Close NFC device nfc_close(pnd); // Release the context nfc_exit(context); exit(EXIT_SUCCESS); }
int main(int argc, const char *argv[]) { pinMode(LED_R, OUTPUT); // Set PWM LED as PWM output pinMode(LED_G, OUTPUT); // Set regular LED as output pinMode(LED_B, OUTPUT); pinMode(DOOR, OUTPUT); //tür öffner // nfc initiiere nfc_init(&context); if (context == NULL) { printf("ERROR: fehler beim dev init\n"); exit(EXIT_FAILURE); } while (true) { doorCode = 0; // öffnet verbindung zum token pnd = nfc_open(context, NULL); led(1,1,0); //Gelb an if (pnd == NULL) { printf("ERROR: fehler beim öffnen.\n"); exit(EXIT_FAILURE); } if (nfc_initiator_init(pnd) < 0) { nfc_perror(pnd, "nfc_initiator_init"); exit(EXIT_FAILURE); } const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) { toTokenKey(nt.nti.nai.abtUid); printf("%s\n",tokenKey); checkToken(); } // TODO checken ob offen ist oder nicht um dann blau oder black zu zeigen nfc_close(pnd); } nfc_exit(context); exit(EXIT_SUCCESS); }
/* * call-seq: * connect * * Connect to the NFC device */ static VALUE connect(VALUE klass) { nfc_init(NULL); nfc_device * dev = nfc_open(NULL, NULL); if(!dev) rb_raise(rb_eRuntimeError, "could not find NFC device"); if(nfc_initiator_init(dev) < 0) { nfc_perror (dev, "nfc_initiator_init"); rb_raise(rb_eRuntimeError, "oh snap, could not init"); } return Data_Wrap_Struct(klass, 0, 0, dev); }
int mf_connect() { // Initialize libnfc and set the nfc_context nfc_init(&context); // Connect to (any) NFC reader device = nfc_open(context, NULL); if (device == NULL) { printf ("Could not connect to any NFC device\n"); return -1; // Don't jump here, since we don't need to disconnect } // Initialize the device as a reader if (!mf_configure_device()) { printf("Error initializing NFC device\n"); return mf_disconnect(-1); } // Try to find a tag if (!mf_select_target() || target.nti.nai.btSak == 0) { printf("Connected to device, but no tag found.\n"); return mf_disconnect(-1); } // Test if we are dealing with a Mifare Classic compatible tag if ((target.nti.nai.btSak & 0x08) == 0) { printf("Incompatible tag type: 0x%02x (i.e. not Mifare Classic).\n", target.nti.nai.btSak); return mf_disconnect(-1); } // Guessing tag size if ((target.nti.nai.abtAtqa[1] & 0x02)) { // 4K size = MF_4K; } else if ((target.nti.nai.abtAtqa[1] & 0x04)) { // 1K size = MF_1K; } else { printf("Unsupported tag size. ATQA 0x%02x 0x%02x (i.e. not [1|4]K.)\n", target.nti.nai.abtAtqa[0], target.nti.nai.abtAtqa[1]); return mf_disconnect(-1); } return 0; // Indicate success - we are now connected }
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); }
nfc_device* getRfidDevice() { size_t device_count = 0; nfc_connstring devices[8]; nfc_context *context; nfc_init(&context); device_count = nfc_list_devices(context,devices,8); if (device_count > 0) return nfc_open (context,devices[0]); else { fprintf(stderr,"Connecting to nfc device failed\n"); return NULL; } }
void cut_setup(void) { size_t n; nfc_init(NULL); llcp_init(); //cut_pend ("MAC link over DEP does not work"); n = nfc_list_devices(NULL, device_descriptions, 2); if (n < 2) { cut_omit("At least two NFC devices must be plugged-in to run this test"); } devices[TARGET] = nfc_open(NULL, device_descriptions[TARGET]); devices[INITIATOR] = nfc_open(NULL, device_descriptions[INITIATOR]); }
void vNFCTask(void *vParameter){ vDebugString("vNFCTask started"); vTaskDelay(100); nfc_init(&context); pnd = nfc_open(context); nfc_close(pnd); nfc_exit(context); for(;;){ vTaskDelay(1000); } }
void RFIDHandler::init() { nfc_connstring devices[1]; nfc_context *context; nfc_init (&context); if(nfc_list_devices (context, devices, 1) == 0) { cout << "Error no NFC devices found..." << endl; } m_nfc_device = nfc_open (context, devices[0]); if(m_nfc_device == NULL) { cout << "Error unable to open NFC device" << endl; } }
void nfc_task(void * data) { int len; nfc_init(&context); if (context == NULL ) { //we should never get here! for (;;) ; } pnd = nfc_open(context, NULL); for (;;) { { g_bReceivedFromPhone = 0; g_bDeliveredToPhone = 0; if (pnd != NULL) { //EnableKeyPoll(1); nfc_emulate_target(pnd, &emulator, 0); //EnableKeyPoll(0); if (g_bReceivedFromPhone || g_bDeliveredToPhone) { taginfo.msgLen = (g_bReceivedFromPhone)? (((uint16_t)taginfo.msg[0])<<8) | taginfo.msg[1] : 0; xQueueSend(xUIQueue, &taginfo, portMAX_DELAY); } } else { pnd = nfc_open(context, NULL); } } if (pnd != NULL) { //nfc_idle(pnd); } //EnableKeyPoll(1); } }