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
00043 #include <nfc/nfc.h>
00044
00045 #include "nfc-utils.h"
00046
00047 #define MAX_FRAME_LEN 264
00048
00049 int
00050 main (int argc, const char *argv[])
00051 {
00052 byte_t abtRx[MAX_FRAME_LEN];
00053 size_t szRx;
00054 size_t szDeviceFound;
00055 byte_t abtTx[] = "Hello Mars!";
00056 nfc_device_t *pnd;
00057 #define MAX_DEVICE_COUNT 2
00058 nfc_device_desc_t pnddDevices[MAX_DEVICE_COUNT];
00059 nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szDeviceFound);
00060
00061
00062
00063
00064 if (szDeviceFound == 1) {
00065 pnd = nfc_connect (&(pnddDevices[0]));
00066 } else if (szDeviceFound > 1) {
00067 pnd = nfc_connect (&(pnddDevices[1]));
00068 } else {
00069 printf("No device found.");
00070 return EXIT_FAILURE;
00071 }
00072
00073 if (argc > 1) {
00074 printf ("Usage: %s\n", argv[0]);
00075 return EXIT_FAILURE;
00076 }
00077
00078 nfc_target_t nt = {
00079 .nm.nmt = NMT_DEP,
00080 .nm.nbr = NBR_UNDEFINED,
00081 .nti.ndi.abtNFCID3 = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00 },
00082 .nti.ndi.szGB = 4,
00083 .nti.ndi.abtGB = { 0x12, 0x34, 0x56, 0x78 },
00084
00085 .nti.ndi.btDID = 0x00,
00086 .nti.ndi.btBS = 0x00,
00087 .nti.ndi.btBR = 0x00,
00088 .nti.ndi.btTO = 0x00,
00089 .nti.ndi.btPP = 0x01,
00090 };
00091
00092 if (!pnd) {
00093 printf("Unable to connect to NFC device.\n");
00094 return EXIT_FAILURE;
00095 }
00096 printf ("Connected to NFC device: %s\n", pnd->acName);
00097
00098 printf ("NFC device will now act as: ");
00099 print_nfc_target (nt, false);
00100
00101 printf ("Waiting for initiator request...\n");
00102 if(!nfc_target_init (pnd, &nt, abtRx, &szRx)) {
00103 nfc_perror(pnd, "nfc_target_init");
00104 return EXIT_FAILURE;
00105 }
00106
00107 printf("Initiator request received. Waiting for data...\n");
00108 if (!nfc_target_receive_bytes (pnd, abtRx, &szRx)) {
00109 nfc_perror(pnd, "nfc_target_receive_bytes");
00110 return EXIT_FAILURE;
00111 }
00112 abtRx[szRx] = '\0';
00113 printf ("Received: %s\n", abtRx);
00114
00115 printf ("Sending: %s\n", abtTx);
00116 if (!nfc_target_send_bytes (pnd, abtTx, sizeof(abtTx))) {
00117 nfc_perror(pnd, "nfc_target_send_bytes");
00118 return EXIT_FAILURE;
00119 }
00120 printf("Data sent.\n");
00121
00122 nfc_disconnect (pnd);
00123 return EXIT_SUCCESS;
00124 }