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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifdef HAVE_CONFIG_H
00054 # include "config.h"
00055 #endif // HAVE_CONFIG_H
00056
00057 #include <stdio.h>
00058 #include <stdlib.h>
00059 #include <stddef.h>
00060 #include <stdint.h>
00061 #include <string.h>
00062
00063 #include <nfc/nfc.h>
00064
00065 #include <nfc/nfc-messages.h>
00066 #include "nfc-utils.h"
00067
00068 #define MAX_FRAME_LEN 264
00069
00070 static byte_t abtRx[MAX_FRAME_LEN];
00071 static size_t szRx;
00072 static nfc_device_t *pnd;
00073 static bool quiet_output = false;
00074
00075 #define SYMBOL_PARAM_fISO14443_4_PICC 0x20
00076
00077 bool send_bytes (const byte_t * pbtTx, const size_t szTx)
00078 {
00079
00080 if (!quiet_output) {
00081 printf ("Sent data: ");
00082 print_hex (pbtTx, szTx);
00083 }
00084
00085
00086 if (!nfc_target_send_bytes(pnd, pbtTx, szTx)) {
00087 nfc_perror (pnd, "nfc_target_send_bytes");
00088 exit(EXIT_FAILURE);
00089 }
00090
00091 return true;
00092 }
00093
00094 bool receive_bytes (void)
00095 {
00096 if (!nfc_target_receive_bytes(pnd,abtRx,&szRx)) {
00097 nfc_perror (pnd, "nfc_target_receive_bytes");
00098 exit(EXIT_FAILURE);
00099 }
00100
00101
00102 if (!quiet_output) {
00103 printf ("Received data: ");
00104 print_hex (abtRx, szRx);
00105 }
00106
00107 return true;
00108 }
00109
00110 int
00111 main (int argc, char *argv[])
00112 {
00113
00114 pnd = nfc_connect (NULL);
00115
00116 if (pnd == NULL) {
00117 ERR("Unable to connect to NFC device");
00118 return EXIT_FAILURE;
00119 }
00120
00121 printf ("Connected to NFC device: %s\n", pnd->acName);
00122 printf ("Emulating NDEF tag now, please touch it with a second NFC device\n");
00123
00124 nfc_target_t nt = {
00125 .nm.nmt = NMT_ISO14443A,
00126 .nm.nbr = NBR_UNDEFINED,
00127 .nti.nai.abtAtqa = { 0x00, 0x04 },
00128 .nti.nai.abtUid = { 0x08, 0x00, 0xb0, 0x0b },
00129 .nti.nai.btSak = 0x20,
00130 .nti.nai.szUidLen = 4,
00131 .nti.nai.szAtsLen = 0,
00132 };
00133
00134 if (!nfc_target_init (pnd, &nt, abtRx, &szRx)) {
00135 nfc_perror (pnd, "nfc_target_init");
00136 ERR("Could not come out of auto-emulation, no command was received");
00137 return EXIT_FAILURE;
00138 }
00139
00140 if (!quiet_output) {
00141 printf ("Received data: ");
00142 print_hex (abtRx, szRx);
00143 }
00144
00145
00146
00147
00148 receive_bytes();
00149
00150
00151 send_bytes((const byte_t*)"\x6a\x87",2);
00152 receive_bytes();
00153
00154
00155 send_bytes((const byte_t*)"\x6a\x87",2);
00156 receive_bytes();
00157
00158
00159 send_bytes((const byte_t*)"\x90\x00",2);
00160 receive_bytes();
00161
00162
00163 send_bytes((const byte_t*)"\x90\x00",2);
00164 receive_bytes();
00165
00166
00167
00168 send_bytes((const byte_t*)"\x00\x0f\x10\x00\x3b\x00\x34\x04\x06\xe1\x04\x0e\xe0\x00\x00\x90\x00",17);
00169 receive_bytes();
00170
00171
00172 send_bytes((const byte_t*)"\x90\x00",2);
00173 receive_bytes();
00174
00175
00176
00177 send_bytes((const byte_t*)"\x00\x21\x90\x00",4);
00178 receive_bytes();
00179
00180
00181 send_bytes((const byte_t*)"\xd1\x02\x1c\x53\x70\x91\x01\x09\x54\x02\x65\x6e\x4c\x69\x62\x6e\x66\x63\x51\x01\x0b\x55\x03\x6c\x69\x62\x6e\x66\x63\x2e\x6f\x72\x67\x90\x00",35);
00182
00183 nfc_disconnect(pnd);
00184 exit (EXIT_SUCCESS);
00185 }