fix bad cast done in last revision.
Audrey Diacre
12 years ago
61 | 61 | main (int argc, const char *argv[]) |
62 | 62 | { |
63 | 63 | uint8_t abtRx[MAX_FRAME_LEN]; |
64 | int res = 0; | |
64 | 65 | size_t szRx = sizeof(abtRx); |
65 | 66 | size_t szDeviceFound; |
66 | 67 | uint8_t abtTx[] = "Hello Mars!"; |
124 | 125 | } |
125 | 126 | |
126 | 127 | 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) { | |
128 | 129 | nfc_perror(pnd, "nfc_target_receive_bytes"); |
129 | 130 | goto error; |
130 | 131 | } |
132 | szRx = (size_t) res; | |
131 | 133 | abtRx[szRx] = '\0'; |
132 | 134 | printf ("Received: %s\n", abtRx); |
133 | 135 |
136 | 136 | nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt) |
137 | 137 | { |
138 | 138 | size_t szTx; |
139 | int res = 0; | |
139 | 140 | uint8_t abtTx[MAX_FRAME_LEN]; |
140 | 141 | bool loop = true; |
141 | 142 | |
157 | 158 | nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false); |
158 | 159 | init_mfc_auth = false; |
159 | 160 | } |
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) { | |
161 | 162 | nfc_perror (pnd, "nfc_target_receive_bytes"); |
162 | 163 | return false; |
163 | 164 | } |
165 | szRx = (size_t) res; | |
164 | 166 | } |
165 | 167 | } |
166 | 168 | return true; |
46 | 46 | } |
47 | 47 | } |
48 | 48 | 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) { | |
50 | 50 | return -1; |
51 | 51 | } |
52 | 52 | } |
87 | 87 | cut_assert_operator_int (res, >, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device))); |
88 | 88 | if (res < 0) { thread_res = -1; return (void*) thread_res; } |
89 | 89 | |
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; | |
93 | 93 | const uint8_t abtAttRx[] = "Hello DEP target!"; |
94 | 94 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
95 | 95 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
86 | 86 | if (res < 0) { thread_res = -1; return (void*) thread_res; } |
87 | 87 | |
88 | 88 | // 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 | ||
92 | 93 | const uint8_t abtAttRx[] = "Hello DEP target!"; |
93 | 94 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
94 | 95 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
99 | 100 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
100 | 101 | |
101 | 102 | // 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; | |
104 | 106 | |
105 | 107 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
106 | 108 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
110 | 112 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
111 | 113 | |
112 | 114 | // 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; | |
115 | 118 | |
116 | 119 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
117 | 120 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
121 | 124 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
122 | 125 | |
123 | 126 | // 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; | |
126 | 130 | |
127 | 131 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
128 | 132 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
367 | 367 | |
368 | 368 | while (!quitting) { |
369 | 369 | bool ret; |
370 | int res = 0; | |
370 | 371 | if (!initiator_only_mode) { |
371 | 372 | // 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) { | |
373 | 374 | nfc_perror (pndTarget, "nfc_target_receive_bytes"); |
374 | 375 | if (!target_only_mode) { |
375 | 376 | nfc_disconnect (pndInitiator); |
377 | 378 | nfc_disconnect (pndTarget); |
378 | 379 | exit(EXIT_FAILURE); |
379 | 380 | } |
381 | szCapduLen = (size_t) res; | |
380 | 382 | if (target_only_mode) { |
381 | 383 | if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) { |
382 | 384 | fprintf (stderr, "Error while printing C-APDU to FD4\n"); |