Codebase list libfreefare / 601105e
fix bad cast done in last revision. Audrey Diacre 12 years ago
6 changed file(s) with 26 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
6161 main (int argc, const char *argv[])
6262 {
6363 uint8_t abtRx[MAX_FRAME_LEN];
64 int res = 0;
6465 size_t szRx = sizeof(abtRx);
6566 size_t szDeviceFound;
6667 uint8_t abtTx[] = "Hello Mars!";
124125 }
125126
126127 printf("Initiator request received. Waiting for data...\n");
127 if (((int) (szRx = (size_t) nfc_target_receive_bytes (pnd, abtRx, 0))) < 0) {
128 if ((res = nfc_target_receive_bytes (pnd, abtRx, 0)) < 0) {
128129 nfc_perror(pnd, "nfc_target_receive_bytes");
129130 goto error;
130131 }
132 szRx = (size_t) res;
131133 abtRx[szRx] = '\0';
132134 printf ("Received: %s\n", abtRx);
133135
136136 nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt)
137137 {
138138 size_t szTx;
139 int res = 0;
139140 uint8_t abtTx[MAX_FRAME_LEN];
140141 bool loop = true;
141142
157158 nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false);
158159 init_mfc_auth = false;
159160 }
160 if ((int) ((szRx = (size_t) nfc_target_receive_bytes(pnd, abtRx, 0))) < 0) {
161 if ((res = nfc_target_receive_bytes(pnd, abtRx, 0)) < 0) {
161162 nfc_perror (pnd, "nfc_target_receive_bytes");
162163 return false;
163164 }
165 szRx = (size_t) res;
164166 }
165167 }
166168 return true;
4646 }
4747 }
4848 if (res >= 0) {
49 if ((int) ((szRx = (size_t) nfc_target_receive_bytes(pnd, abtRx, 0))) < 0) {
49 if ((res = nfc_target_receive_bytes(pnd, abtRx, 0)) < 0) {
5050 return -1;
5151 }
5252 }
8787 cut_assert_operator_int (res, >, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
8888 if (res < 0) { thread_res = -1; return (void*) thread_res; }
8989
90 szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
91 cut_assert_operator_int (szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
92
90 res = nfc_target_receive_bytes (device, abtRx, 500);
91 cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
92 szRx = (size_t) res;
9393 const uint8_t abtAttRx[] = "Hello DEP target!";
9494 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
9595 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
8686 if (res < 0) { thread_res = -1; return (void*) thread_res; }
8787
8888 // First pass
89 szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
90 cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
91
89 res = nfc_target_receive_bytes (device, abtRx, 500);
90 cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
91 szRx = (size_t) res;
92
9293 const uint8_t abtAttRx[] = "Hello DEP target!";
9394 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
9495 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
99100 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
100101
101102 // Second pass
102 szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
103 cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
103 res = nfc_target_receive_bytes (device, abtRx, 500);
104 cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
105 szRx = (size_t) res;
104106
105107 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
106108 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
110112 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
111113
112114 // Third pass
113 szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
114 cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
115 res = nfc_target_receive_bytes (device, abtRx, 500);
116 cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
117 szRx = (size_t) res;
115118
116119 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
117120 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
121124 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
122125
123126 // Fourth pass
124 szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
125 cut_assert_operator_int ((int)szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
127 res = nfc_target_receive_bytes (device, abtRx, 500);
128 cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
129 szRx = (size_t) res;
126130
127131 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
128132 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
367367
368368 while (!quitting) {
369369 bool ret;
370 int res = 0;
370371 if (!initiator_only_mode) {
371372 // Receive external reader command through target
372 if ((int) ((szCapduLen = (size_t) nfc_target_receive_bytes(pndTarget, abtCapdu, 0))) < 0) {
373 if ((res = nfc_target_receive_bytes(pndTarget, abtCapdu, 0)) < 0) {
373374 nfc_perror (pndTarget, "nfc_target_receive_bytes");
374375 if (!target_only_mode) {
375376 nfc_disconnect (pndInitiator);
377378 nfc_disconnect (pndTarget);
378379 exit(EXIT_FAILURE);
379380 }
381 szCapduLen = (size_t) res;
380382 if (target_only_mode) {
381383 if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) {
382384 fprintf (stderr, "Error while printing C-APDU to FD4\n");