void cut_setup() { if (llcp_init()) cut_fail("llcp_init() failed"); if (!(sample_a_pdu = malloc(sizeof(*sample_a_pdu)))) { cut_fail("Cannot allocate sample_a_pdu"); } sample_a_pdu->dsap = 0; sample_a_pdu->ptype = PDU_AGF; sample_a_pdu->ssap = 0; sample_a_pdu->information_size = sizeof(sample_a_pdu_information); sample_a_pdu->information = malloc(sizeof(sample_a_pdu_information)); memcpy(sample_a_pdu->information, sample_a_pdu_information, sizeof(sample_a_pdu_information)); if (!(sample_i_pdu = malloc(sizeof(*sample_i_pdu)))) { cut_fail("Cannot allocate sample_i_pdu"); } sample_i_pdu->dsap = 8; sample_i_pdu->ptype = PDU_I; sample_i_pdu->ssap = 2; sample_i_pdu->ns = 5; sample_i_pdu->nr = 3; sample_i_pdu->information_size = 11; sample_i_pdu->information = (uint8_t *)strdup("Hello World"); }
void cut_setup(void) { if (llcp_init()) cut_fail("llcp_init() failed"); /* Void service is never called */ void_service(NULL); }
void cut_setup(void) { if (llcp_init()) cut_fail("llcp_init() failed"); sem_cutter = sem_open(sem_cutter_name, O_CREAT | O_EXCL, 0666, 0); if (sem_cutter == SEM_FAILED) cut_fail("sem_open() failed"); }
int snepClientThread :: init(nfc_device **device) { pnd = *device; if (llcp_init() < 0){ qDebug() << "llcp_init() failed."; return -1; } llc_link = llc_link_new(); if (!llc_link) { qDebug() << "Cannot allocate LLC link data structures"; } mac_link = mac_link_new(pnd, llc_link); if (!mac_link){ qDebug() << "Cannot create MAC link"; return -1; } struct llc_service *com_android_npp; if (!(com_android_npp = llc_service_new(NULL, snepService, NULL))){ qDebug() << "Cannot create com.android.npp service"; return -1; } llc_service_set_miu(com_android_npp, 512); llc_service_set_rw(com_android_npp, 2); int sap; if ((sap = llc_link_service_bind(llc_link, com_android_npp, 0x20)) < 0){ qDebug() << "Cannot create com.android.npp service"; return -1; } con = llc_outgoing_data_link_connection_new(llc_link, sap, LLCP_SNEP_SAP); if (!con){ qDebug() << "Connection created failed."; return -1; } qDebug() << "snep: flag set true"; flag = true; return 0; }
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]); }
int snepServerThread :: init(nfc_device **device) { pnd = *device; if (llcp_init() < 0) { qDebug() << "llcp_init() failed."; return -1; } llc_link = llc_link_new(); if (!llc_link) { qDebug() << "Cannot allocate LLC link data structures"; return -1; } /** initial LLCP service struct */ struct llc_service *com_android_snep; if (!(com_android_snep = llc_service_new_with_uri(NULL, snepService, (char *)"urn:nfc:sn:snep", NULL))) { qDebug() << "Cannot create com.android.snep service"; } llc_service_set_miu(com_android_snep, 512); llc_service_set_rw(com_android_snep, 2); if (llc_link_service_bind(llc_link, com_android_snep, LLCP_SNEP_SAP) < 0) { qDebug() << "Cannot bind service"; } mac_link = mac_link_new(pnd, llc_link); if (!mac_link) { qDebug() << "Cannot create MAC link"; return -1; } qDebug() << "snep: flag set true"; flag = true; return 0; }
int main(int argc, char *argv[]) { (void)argc; (void)argv; nfc_context *context; nfc_init(&context); if (llcp_init() < 0) errx(EXIT_FAILURE, "llcp_init()"); signal(SIGINT, stop_mac_link); atexit(bye); if (!(device = nfc_open(context, NULL))) { errx(EXIT_FAILURE, "Cannot connect to NFC device"); } struct llc_link *llc_link = llc_link_new(); if (!llc_link) { errx(EXIT_FAILURE, "Cannot allocate LLC link data structures"); } mac_link = mac_link_new(device, llc_link); if (!mac_link){ errx(EXIT_FAILURE, "Cannot create MAC link"); } struct llc_service *com_android_npp; if (!(com_android_npp = llc_service_new(NULL, com_android_snep_service, NULL))){ errx(EXIT_FAILURE, "Cannot create com.android.npp service"); } llc_service_set_miu(com_android_npp, 512); llc_service_set_rw(com_android_npp, 2); int sap; if ((sap = llc_link_service_bind(llc_link, com_android_npp, 0x20)) < 0) errx(EXIT_FAILURE, "Cannot bind service"); // struct llc_connection *con = llc_outgoing_data_link_connection_new_by_uri(llc_link, sap, "urn:nfc:sn:snep"); struct llc_connection *con = llc_outgoing_data_link_connection_new(llc_link, sap, LLCP_SNEP_SAP); if (!con){ errx(EXIT_FAILURE, "Cannot create llc_connection"); } if (mac_link_activate_as_initiator(mac_link) < 0) { errx(EXIT_FAILURE, "Cannot activate MAC link"); } if (llc_connection_connect(con) < 0) errx(EXIT_FAILURE, "Cannot connect llc_connection"); llc_connection_wait(con, NULL); llc_link_deactivate(llc_link); mac_link_free(mac_link); llc_link_free(llc_link); nfc_close(device); device = NULL; llcp_fini(); nfc_exit(context); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int ret = 0; int ch; int testno; const int testcount = sizeof(tests) / sizeof(*tests); char junk; nfc_init(NULL); if (llcp_init() < 0) errx(EXIT_FAILURE, "llcp_init()"); signal(SIGINT, stop_mac_link); while ((ch = getopt_long(argc, argv, "qd:f:l:D:m:Q:ht:T", longopts, NULL)) != -1) { switch (ch) { case 'q': case 'd': case 'f': warnx("ignored option -- %c (hint: edit log4crc)", ch); break; case 'l': if (1 != sscanf(optarg, "%d%c", &options.link_miu, &junk)) { errx(EXIT_FAILURE, "“%s” is not a valid link MIU value", optarg); } break; case 'D': options.device = optarg; break; case 'm': if (0 == strcasecmp("initiator", optarg)) options.mode = M_INITIATOR; else if (0 == strcasecmp("target", optarg)) options.mode = M_TARGET; else errx(EXIT_FAILURE, "“%s” is not a supported mode", optarg); break; case 'Q': if (0 == strcasecmp("android", optarg)) options.quirks = Q_ANDROID; else errx(EXIT_FAILURE, "“%s” is not a support quirks mode", optarg); break; case 't': if (1 != sscanf(optarg, "%d%c", &testno, &junk)) { errx(EXIT_FAILURE, "“%s” is not a valid test number", optarg); } if ((testno < 1) || (testno > testcount)) { errx(EXIT_FAILURE, "Test number %d is not in the [1..%d] range", testno, (int) testcount); } tests[testno - 1].enabled = 1; break; case 'T': fprintf(stderr, "Available tests:\n"); for (size_t i = 0; i < sizeof(tests) / sizeof(*tests); i++) { fprintf(stderr, "%3d - %s\n", (int) i + 1, tests[i].description); } exit(EXIT_SUCCESS); break; case 'h': default: usage(basename(argv[0])); exit(EXIT_FAILURE); break; } } argc -= optind; argv += optind; nfc_connstring device_connstring[1]; int res; res = nfc_list_devices(NULL, device_connstring, 1); if (res < 1) errx(EXIT_FAILURE, "No NFC device found"); nfc_device *device; if (!(device = nfc_open(NULL, device_connstring[0]))) { errx(EXIT_FAILURE, "Cannot open NFC device"); } struct llc_link *llc_link = llc_link_new(); if (!llc_link) { errx(EXIT_FAILURE, "Cannot allocate LLC link data structures"); } mac_link = mac_link_new(device, llc_link); if (!mac_link) errx(EXIT_FAILURE, "Cannot create MAC link"); for (int i = 0; i < testcount; i++) { if (tests[i].enabled) { ret += tests[i].fn(llc_link); } } void *err; mac_link_wait(mac_link, &err); switch (llc_link->role & 0x01) { case LLC_INITIATOR: printf("I was the Initiator\n"); break; case LLC_TARGET: printf("I was the Target\n"); break; } mac_link_free(mac_link); llc_link_free(llc_link); nfc_close(device); llcp_fini(); nfc_exit(NULL); exit(ret); }
int main (int argc, char *argv[]) { nfc_init(&context); if (context == NULL) { printf("Unable to init libnfc (malloc)"); exit(EXIT_FAILURE); } if (llcp_init () < 0) errx (EXIT_FAILURE, "llcp_init()"); llcp_log_log("[nfc-p2p-demo.c]", LLC_PRIORITY_WARN, "This is a test warning message"); llcp_log_log("[nfc-p2p-demo.c]", LLC_PRIORITY_FATAL, "This is a test fatal message"); llcp_log_log("[nfc-p2p-demo.c]", LLC_PRIORITY_TRACE, "This is a test trace message"); llcp_log_log("[nfc-p2p-demo.c]", LLC_PRIORITY_DEBUG, "This is a test debug message"); llcp_log_log("[nfc-p2p-demo.c]", LLC_PRIORITY_ERROR, "This is a test error message"); int res; //Auto probe for nfc device /* nfc_connstring device_connstring[1]; res = nfc_list_devices (NULL, device_connstring, 1); if (res < 1) errx (EXIT_FAILURE, "Sorry, no NFC device found"); //Create nfc_device nfc_device *device; if (!(device = nfc_open (NULL, device_connstring[0]))) { errx (EXIT_FAILURE, "Cannot connect to NFC device"); } */ //Create nfc_device nfc_device *device; //if (!(device = nfc_open (NULL, device_connstring[0]))) { //if (!(device = nfc_open (NULL, "pn532_uart:/dev/ttyUSB0:115200"))) { if (!(device = nfc_open (context, NULL))) { errx (EXIT_FAILURE, "Cannot connect to NFC device"); } //Create llc_link struct llc_link *my_llc_link = llc_link_new (); struct llc_service *snep_service; //Create receiving service! if (!(snep_service = llc_service_new_with_uri (NULL, snep_service_thread, LLCP_SNEP_URI, NULL))) errx (EXIT_FAILURE, "Cannot create snep service"); //Bind llc_service to llc_link if (llc_link_service_bind (my_llc_link, snep_service, LLCP_SNEP_SAP) < 0) { errx (EXIT_FAILURE, "llc_service_new_with_uri()"); } //Create mac_link struct mac_link *my_mac_link = mac_link_new (device, my_llc_link); if (!my_mac_link) errx (EXIT_FAILURE, "Cannot establish MAC link"); //Active mac_link as initiator res = mac_link_activate_as_initiator(my_mac_link); if (res <= 0) errx (EXIT_FAILURE, "Cannot activate link"); //Wait for mac_link to finish void *status; mac_link_wait (my_mac_link, &status); printf ("STATUS = %p\n", status); mac_link_free (my_mac_link); llc_link_free (my_llc_link); nfc_close (device); llcp_fini (); nfc_exit(context); exit(EXIT_SUCCESS); }