87 stop_emulation(
int sig)
98 static uint8_t __nfcforum_tag2_memory_area[] = {
99 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00,
101 0x00, 0x00, 0xFF, 0xFF,
102 0xE1, 0x10, 0x06, 0x0F,
104 0x03, 33, 0xd1, 0x02,
105 0x1c, 0x53, 0x70, 0x91,
106 0x01, 0x09, 0x54, 0x02,
107 0x65, 0x6e, 0x4c, 0x69,
109 0x62, 0x6e, 0x66, 0x63,
110 0x51, 0x01, 0x0b, 0x55,
111 0x03, 0x6c, 0x69, 0x62,
112 0x6e, 0x66, 0x63, 0x2e,
114 0x6f, 0x72, 0x67, 0x00,
115 0x00, 0x00, 0x00, 0x00,
116 0x00, 0x00, 0x00, 0x00,
117 0x00, 0x00, 0x00, 0x00,
122 #define SECTOR_SELECT 0xC2
126 nfcforum_tag2_io(
struct nfc_emulator *emulator,
const uint8_t *data_in,
const size_t data_in_len, uint8_t *data_out,
const size_t data_out_len)
130 uint8_t *nfcforum_tag2_memory_area = (uint8_t *)(emulator->user_data);
133 print_hex(data_in, data_in_len);
135 switch (data_in[0]) {
137 if (data_out_len >= 16) {
138 memcpy(data_out, nfcforum_tag2_memory_area + (data_in[1] * 4), 16);
145 printf(
"HALT sent\n");
149 printf(
"Unknown command: 0x%02x\n", data_in[0]);
154 ERR(
"%s (%d)", strerror(-res), -res);
157 print_hex(data_out, res);
164 main(
int argc,
char *argv[])
171 .nmt = NMT_ISO14443A,
172 .nbr = NBR_UNDEFINED,
176 .abtAtqa = { 0x00, 0x04 },
177 .abtUid = { 0x08, 0x00, 0xb0, 0x0b },
186 .io = nfcforum_tag2_io
191 .state_machine = &state_machine,
192 .user_data = __nfcforum_tag2_memory_area,
195 signal(SIGINT, stop_emulation);
198 if (context == NULL) {
199 ERR(
"Unable to init libnfc (malloc)");
205 ERR(
"Unable to open NFC device");
211 printf(
"Emulating NDEF tag now, please touch it with a second NFC device\n");
const char * nfc_device_get_name(nfc_device *pnd)
Returns the device name.
void nfc_close(nfc_device *pnd)
Close from a NFC device.
nfc_device * nfc_open(nfc_context *context, const nfc_connstring connstring)
Open a NFC device.
int nfc_abort_command(nfc_device *pnd)
Abort current running command.
void nfc_perror(const nfc_device *pnd, const char *pcString)
Display the last error occured on a nfc_device.
void nfc_exit(nfc_context *context)
Deinitialize libnfc. Should be called after closing all open devices and before your application term...
void nfc_init(nfc_context **context)
Initialize libnfc. This function must be called before calling any other libnfc function.
int nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator, const int timeout)
Emulate a target.
Provide a small API to ease emulation in libnfc.
Provide some examples shared functions like print, parity calculation, options parsing.
#define ERR(...)
Print a error message.
NFC library context Struct which contains internal options, references, pointers, etc....
NFC emulation state machine structure.