Windows: Clean up all compiler warnings and link warnings
- Fixed the suppression of the auto-fixup for linking against MS built libs
- Fixed all the formatting warnings by shifting to inttypes.h specifiers
- shifted to %lu for DWORD printf
Alex Lian authored 11 years ago
Philippe Teuwen committed 11 years ago
78 | 78 | IF(MINGW) |
79 | 79 | # force MinGW-w64 in 32bit mode |
80 | 80 | SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}") |
81 | SET(CMAKE_MODULE_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") | |
82 | SET(CMAKE_SHARED_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") | |
83 | SET(CMAKE_EXE_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}") | |
81 | SET(CMAKE_MODULE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") | |
82 | SET(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") | |
83 | SET(CMAKE_EXE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}") | |
84 | 84 | SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}") |
85 | 85 | ENDIF(MINGW) |
86 | 86 |
37 | 37 | #endif // HAVE_CONFIG_H |
38 | 38 | |
39 | 39 | #include <err.h> |
40 | #include <inttypes.h> | |
40 | 41 | #include <signal.h> |
41 | 42 | #include <stdio.h> |
42 | 43 | #include <stddef.h> |
127 | 128 | } |
128 | 129 | |
129 | 130 | printf("NFC reader: %s opened\n", nfc_device_get_name(pnd)); |
130 | printf("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations); | |
131 | printf("NFC device will poll during %ld ms (%u pollings of %lu ms for %" PRIdPTR " modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations); | |
131 | 132 | if ((res = nfc_initiator_poll_target(pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) { |
132 | 133 | nfc_perror(pnd, "nfc_initiator_poll_target"); |
133 | 134 | nfc_close(pnd); |
36 | 36 | # include "config.h" |
37 | 37 | #endif /* HAVE_CONFIG_H */ |
38 | 38 | |
39 | #include <inttypes.h> | |
39 | 40 | #include <stdio.h> |
40 | 41 | #include <stdlib.h> |
41 | 42 | #include <stdint.h> |
118 | 119 | size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT); |
119 | 120 | |
120 | 121 | if (szFound < 2) { |
121 | ERR("%zd device found but two opened devices are needed to relay NFC.", szFound); | |
122 | ERR("%" PRIdPTR " device found but two opened devices are needed to relay NFC.", szFound); | |
122 | 123 | nfc_exit(context); |
123 | 124 | exit(EXIT_FAILURE); |
124 | 125 | } |
23 | 23 | * @brief Windows UART driver |
24 | 24 | */ |
25 | 25 | |
26 | #include <inttypes.h> | |
26 | 27 | #include "log.h" |
27 | 28 | |
28 | 29 | #define LOG_GROUP NFC_LOG_GROUP_COM |
163 | 164 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new timeout settings."); |
164 | 165 | return NFC_EIO; |
165 | 166 | } |
166 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeouts are set to %u ms", timeout_ms); | |
167 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeouts are set to %lu ms", timeout_ms); | |
167 | 168 | |
168 | 169 | // TODO Enhance the reception method |
169 | 170 | // - According to MSDN, it could be better to implement nfc_abort_command() mecanism using Cancello() |
178 | 179 | |
179 | 180 | if (!res) { |
180 | 181 | DWORD err = GetLastError(); |
181 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "ReadFile error: %u", err); | |
182 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "ReadFile error: %lu", err); | |
182 | 183 | return NFC_EIO; |
183 | 184 | } else if (dwBytesReceived == 0) { |
184 | 185 | return NFC_ETIMEOUT; |
27 | 27 | # include "config.h" |
28 | 28 | #endif // HAVE_CONFIG_H |
29 | 29 | |
30 | #include <inttypes.h> | |
30 | 31 | #include <stdio.h> |
31 | 32 | #include <stdlib.h> |
32 | 33 | #include <string.h> |
1353 | 1354 | const size_t szRxLen = (size_t)res - 1; |
1354 | 1355 | if (pbtRx != NULL) { |
1355 | 1356 | if (szRxLen > szRx) { |
1356 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Buffer size is too short: %zuo available(s), %zuo needed", szRx, szRxLen); | |
1357 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Buffer size is too short: %" PRIuPTR " available(s), %" PRIuPTR " needed", szRx, szRxLen); | |
1357 | 1358 | return NFC_EOVFLOW; |
1358 | 1359 | } |
1359 | 1360 | // Copy the received bytes |
1628 | 1629 | } |
1629 | 1630 | if (pbtRx != NULL) { |
1630 | 1631 | if ((szRxLen + sz) > szRx) { |
1631 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Buffer size is too short: %zuo available(s), %zuo needed", szRx, szRxLen + sz); | |
1632 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Buffer size is too short: %" PRIuPTR " available(s), %" PRIuPTR " needed", szRx, szRxLen + sz); | |
1632 | 1633 | return NFC_EOVFLOW; |
1633 | 1634 | } |
1634 | 1635 | // Copy the received bytes |
2710 | 2711 | |
2711 | 2712 | (*pszFrame) = szData + PN53x_EXTENDED_FRAME__OVERHEAD; |
2712 | 2713 | } else { |
2713 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "We can't send more than %d bytes in a raw (requested: %zd)", PN53x_EXTENDED_FRAME__DATA_MAX_LEN, szData); | |
2714 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "We can't send more than %d bytes in a raw (requested: %" PRIdPTR ")", PN53x_EXTENDED_FRAME__DATA_MAX_LEN, szData); | |
2714 | 2715 | return NFC_ECHIP; |
2715 | 2716 | } |
2716 | 2717 | return NFC_SUCCESS; |
254 | 254 | if (strlen(ndd.pcsc_device_name) < 5) { // We can assume it's a reader ID as pcsc_name always ends with "NN NN" |
255 | 255 | // Device was not specified, only ID, retrieve it |
256 | 256 | size_t index; |
257 | if (sscanf(ndd.pcsc_device_name, "%4lu", &index) != 1) | |
257 | if (sscanf(ndd.pcsc_device_name, "%4" SCNuPTR, &index) != 1) | |
258 | 258 | return NULL; |
259 | 259 | nfc_connstring *ncs = malloc(sizeof(nfc_connstring) * (index + 1)); |
260 | 260 | if (!ncs) { |
717 | 717 | len -= 4; // We skip 2 bytes for PN532 direction byte (D5) and command byte (CMD+1), then 2 bytes for APDU status (90 00). |
718 | 718 | |
719 | 719 | if (len > szDataLen) { |
720 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len); | |
720 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len); | |
721 | 721 | pnd->last_error = NFC_EOVFLOW; |
722 | 722 | return pnd->last_error; |
723 | 723 | } |
683 | 683 | |
684 | 684 | size_t data_len = FRAME_SIZE(tmp) - 17; |
685 | 685 | if (data_len > buf_len) { |
686 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Receive buffer too small. (buf_len: %zu, data_len: %zu)", buf_len, data_len); | |
686 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Receive buffer too small. (buf_len: %" PRIuPTR ", data_len: %" PRIuPTR ")", buf_len, data_len); | |
687 | 687 | pnd->last_error = NFC_EIO; |
688 | 688 | return pnd->last_error; |
689 | 689 | } |
329 | 329 | size_t szFrame = 0; |
330 | 330 | if (szData > PN53x_NORMAL_FRAME__DATA_MAX_LEN) { |
331 | 331 | // ARYGON Reader with PN532 equipped does not support extended frame (bug in ARYGON firmware?) |
332 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ARYGON device does not support more than %d bytes as payload (requested: %zd)", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData); | |
332 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ARYGON device does not support more than %d bytes as payload (requested: %" PRIdPTR ")", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData); | |
333 | 333 | pnd->last_error = NFC_EDEVNOTSUPP; |
334 | 334 | return pnd->last_error; |
335 | 335 | } |
437 | 437 | } |
438 | 438 | |
439 | 439 | if (len > szDataLen) { |
440 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len); | |
440 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len); | |
441 | 441 | pnd->last_error = NFC_EIO; |
442 | 442 | return pnd->last_error; |
443 | 443 | } |
423 | 423 | } |
424 | 424 | |
425 | 425 | if (len > szDataLen) { |
426 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len); | |
426 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len); | |
427 | 427 | pnd->last_error = NFC_EIO; |
428 | 428 | goto error; |
429 | 429 | } |
587 | 587 | } |
588 | 588 | |
589 | 589 | if (len > szDataLen) { |
590 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len); | |
590 | log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len); | |
591 | 591 | pnd->last_error = NFC_EIO; |
592 | 592 | return pnd->last_error; |
593 | 593 | } |
22 | 22 | * @file target-subr.c |
23 | 23 | * @brief Target-related subroutines. (ie. determine target type, print target, etc.) |
24 | 24 | */ |
25 | #include <inttypes.h> | |
25 | 26 | #include <nfc/nfc.h> |
26 | 27 | |
27 | 28 | #include "target-subr.h" |
247 | 248 | uint8_t TC = pnai->abtAts[offset]; |
248 | 249 | offset++; |
249 | 250 | if (TC & 0x1) { |
250 | off += snprintf(dst + off, size - off, "* Node ADdress supported\n"); | |
251 | off += snprintf(dst + off, size - off, "* Node Address supported\n"); | |
251 | 252 | } else { |
252 | off += snprintf(dst + off, size - off, "* Node ADdress not supported\n"); | |
253 | off += snprintf(dst + off, size - off, "* Node Address not supported\n"); | |
253 | 254 | } |
254 | 255 | if (TC & 0x2) { |
255 | 256 | off += snprintf(dst + off, size - off, "* Card IDentifier supported\n"); |
270 | 271 | offset++; |
271 | 272 | if (L != (pnai->szAtsLen - offset)) { |
272 | 273 | off += snprintf(dst + off, size - off, " * Warning: Type Identification Coding length (%i)", L); |
273 | off += snprintf(dst + off, size - off, " not matching Tk length (%zi)\n", (pnai->szAtsLen - offset)); | |
274 | off += snprintf(dst + off, size - off, " not matching Tk length (%" PRIdPTR ")\n", (pnai->szAtsLen - offset)); | |
274 | 275 | } |
275 | 276 | if ((pnai->szAtsLen - offset - 2) > 0) { // Omit 2 CRC bytes |
276 | 277 | uint8_t CTC = pnai->abtAts[offset]; |
41 | 41 | # include "config.h" |
42 | 42 | #endif /* HAVE_CONFIG_H */ |
43 | 43 | |
44 | #include <inttypes.h> | |
44 | 45 | #include <stdio.h> |
45 | 46 | #include <stdlib.h> |
46 | 47 | #include <stdint.h> |
99 | 100 | if (szBytes > MAX_FRAME_LEN) { |
100 | 101 | return -1; |
101 | 102 | } |
102 | if (fprintf(fd4, "#%s %04zx: ", pchPrefix, szBytes) < 0) { | |
103 | if (fprintf(fd4, "#%s %04" PRIxPTR ": ", pchPrefix, szBytes) < 0) { | |
103 | 104 | return -1; |
104 | 105 | } |
105 | 106 | |
224 | 225 | } |
225 | 226 | } else { |
226 | 227 | if (szFound < 2) { |
227 | ERR("%zd device found but two opened devices are needed to relay NFC.", szFound); | |
228 | ERR("%" PRIdPTR " device found but two opened devices are needed to relay NFC.", szFound); | |
228 | 229 | nfc_exit(context); |
229 | 230 | exit(EXIT_FAILURE); |
230 | 231 | } |