Beispiel #1
0
void snepClientThread :: run()
{
    /** wait  */
    while(!flag);
    qDebug() << "snepClientThread running.";

    if(mac_link == NULL || llc_link == NULL || con == NULL){
        qDebug() << "Device is not initialed.";
        return;
    }

    if (mac_link_activate_as_initiator(mac_link) < 0) {
        qDebug() << "Cannot activate MAC link";
        return;
    }

    if (llc_connection_connect(con) < 0){
        qDebug() << "Cannot connect llc_connection";
    }
    llc_connection_wait(con, NULL);

    llc_link_deactivate(llc_link);
}
Beispiel #2
0
int
activate_link(struct llc_link *llc_link)
{
  int res;
  struct mac_link *mac_link = llc_link->mac_link;
  switch (options.mode) {
    case M_NONE:
      res = mac_link_activate(mac_link);
      break;
    case M_INITIATOR:
      res = mac_link_activate_as_initiator(mac_link);
      break;
    case M_TARGET:
      res = mac_link_activate_as_target(mac_link);
      break;
  }

  if (res <= 0) {
    errx(EXIT_FAILURE, "Cannot activate link");
  }

  return res;
}
Beispiel #3
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;
}
Beispiel #4
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[])
{
	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);

}