Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #ifdef HAVE_CONFIG_H
00037 # include "config.h"
00038 #endif // HAVE_CONFIG_H
00039
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <string.h>
00043
00044 #include <nfc/nfc.h>
00045
00046 #include "nfc-utils.h"
00047
00048 #define MAX_FRAME_LEN 264
00049
00050 int
00051 main (int argc, const char *argv[])
00052 {
00053 nfc_device_t *pnd;
00054 nfc_target_t nt;
00055 byte_t abtRx[MAX_FRAME_LEN];
00056 size_t szRx;
00057 byte_t abtTx[] = "Hello World!";
00058
00059 if (argc > 1) {
00060 printf ("Usage: %s\n", argv[0]);
00061 return EXIT_FAILURE;
00062 }
00063
00064 pnd = nfc_connect (NULL);
00065 if (!pnd) {
00066 printf("Unable to connect to NFC device.\n");
00067 return EXIT_FAILURE;
00068 }
00069 printf ("Connected to NFC device: %s\n", pnd->acName);
00070
00071 if (!nfc_initiator_init (pnd)) {
00072 nfc_perror(pnd, "nfc_initiator_init");
00073 return EXIT_FAILURE;
00074 }
00075
00076 if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NBR_212, NULL, &nt)) {
00077 nfc_perror(pnd, "nfc_initiator_select_dep_target");
00078 return EXIT_FAILURE;
00079 }
00080 print_nfc_target (nt, false);
00081
00082 printf ("Sending: %s\n", abtTx);
00083 if (!nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, &szRx)) {
00084 nfc_perror(pnd, "nfc_initiator_transceive_bytes");
00085 return EXIT_FAILURE;
00086 }
00087
00088 abtRx[szRx] = 0;
00089 printf ("Received: %s\n", abtRx);
00090
00091 nfc_initiator_deselect_target (pnd);
00092 nfc_disconnect (pnd);
00093 return EXIT_SUCCESS;
00094 }