Пример #1
0
void *
target_thread(void *arg)
{
    intptr_t res = 0;
    struct test_thread_data *thread_data = (struct test_thread_data *) arg;
    /*
    uint8_t id[] = {
    0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00
    };*/

    cut_set_current_test_context(thread_data->context);

    printf("Activating target...\n");
    struct llc_link *llc_link = llc_link_new();
    cut_assert_not_null(llc_link, cut_message("llc_link_new() failed"));

    struct mac_link *link = mac_link_new(thread_data->device, llc_link);
    cut_assert_not_null(link, cut_message("mac_link_new() failed"));

    res = mac_link_activate_as_target(link);
    cut_assert_equal_int(1, res, cut_message("mac_link_activate_as_target() failed"));

    sleep(3);

    printf("===== DEACTIVATE =====\n");
    mac_link_deactivate(link, MAC_DEACTIVATE_ON_REQUEST);
    mac_link_free(link);
    llc_link_free(llc_link);
    return (void *) res;
}
Пример #2
0
snepClientThread :: ~snepClientThread()
{
    if(mac_link != NULL){
        mac_link_free(mac_link);
        mac_link = NULL;
    }
    if(llc_link != NULL){
        llc_link_free(llc_link);
        llc_link= NULL;
    }
    llcp_fini();
}
Пример #3
0
void snepClientThread :: free()
{
    qDebug() << "snepClientThread is stopped.";
    flag = false;
    if(mac_link != NULL){
        mac_link_free(mac_link);
        mac_link = NULL;
    }
    if(llc_link != NULL){
        llc_link_free(llc_link);
        llc_link= NULL;
    }
}
Пример #4
0
void *
initiator_thread(void *arg)
{
    intptr_t res = 0;
    struct test_thread_data *thread_data = (struct test_thread_data *) arg;

    cut_set_current_test_context(thread_data->context);

    struct llc_link *llc_link = llc_link_new();
    cut_assert_not_null(llc_link, cut_message("llc_link_new() failed"));

    struct mac_link *link = mac_link_new(thread_data->device, llc_link);
    cut_assert_not_null(link, cut_message("mac_link_new() failed"));

    printf("Activating initiator...\n");
    res = mac_link_activate_as_initiator(link);
    cut_assert_equal_int(1, res, cut_message("mac_link_activate_as_initiator() failed"));

    printf("===== DEACTIVATE =====\n");
    mac_link_deactivate(link, MAC_DEACTIVATE_ON_REQUEST);
    mac_link_free(link);
    llc_link_free(llc_link);
    return (void *) res;
}
Пример #5
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);
}
Пример #6
0
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);
}
Пример #7
0
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);

}