Commit graph

1864 commits

Author SHA1 Message Date
Philippe Teuwen
ade71ee8a6 nfc_initiator_target_is_present(): reuse iso14443_cascade_uid() 2014-01-30 00:24:06 +01:00
Philippe Teuwen
095f945224 nfc_initiator_target_is_present(): improve MFC support for 7-byte UID 2014-01-30 00:09:03 +01:00
Philippe Teuwen
9d63a93dd8 nfc_initiator_target_is_present(): improve MFC support
Increase timeout to support Tikitag & PN533
Fix support for MFC Mini on PN533
2014-01-29 23:30:50 +01:00
Philippe Teuwen
94f4e001f4 nfc_initiator_target_is_present(): support MFUL on PN532 too 2014-01-29 23:02:36 +01:00
Romuald Conty
7b5ab23452 Partial MFC support while checking target presence on PN532/PN531
Goal is to implement "ping" on MFC the same as PN533 does. This patch implements MFC re-selection, but do not take care about authentication; this means this will have side effect while you are authenticated on a MFC block.
2014-01-29 11:36:12 +01:00
Philippe Teuwen
1a3acdadc4 Prepare nfc_initiator_target_is_present() to support more cases
and return NFC_EDEVNOTSUPP for cases not yet supported, depending on the chipset.

Little helper to debug future additions to that function:

// LIBNFC_LOG_LEVEL=193 ./nfc-testing
int
main(void)
{
  nfc_device *pnd;
  nfc_modulation nm = {  .nmt = NMT_ISO14443A,  .nbr = NBR_106,  };
  nfc_context *context;
  nfc_init(&context);
  pnd = nfc_open(context, NULL);
  nfc_initiator_init(pnd);
  nfc_target nt;
  nfc_initiator_select_passive_target(pnd, nm, NULL, 0, &nt);
  while (nfc_initiator_target_is_present(pnd, NULL) == NFC_SUCCESS);
  nfc_close(pnd);
  nfc_exit(context);
}
2014-01-29 01:54:46 +01:00
Philippe Teuwen
744e052fbe update ChangeLog 2014-01-28 13:20:03 +01:00
Philippe Teuwen
65ad186109 make style 2014-01-28 13:09:33 +01:00
Romuald Conty
e5c732e181 Fix internal current target when using nfc_initiator_poll_target() (Thanks to Bjoern Kinscher)
Fixes Issue 265.
2014-01-28 10:45:05 +01:00
Romuald Conty
b7f590acc8 Set correctly last_error when running pn53x_initiator_target_is_present() 2014-01-28 10:40:18 +01:00
Romuald Conty
9a0a10826b Fix pn53x_initiator_target_is_present() when saved target is NULL
This patch prevents from running any command to check target presence when none have been saved
2014-01-28 10:27:10 +01:00
Philippe Teuwen
7a30e35496 nfc-mfclassic: update help & man page 2014-01-28 00:22:33 +01:00
Philippe Teuwen
d47623319d nfc_initiator_target_is_present() allows pnt==NULL 2014-01-27 16:07:24 +01:00
Philippe Teuwen
7b7f506142 make style 2013-12-08 19:51:01 +01:00
Jiapeng Li
8026d6c047 CMake: find and use pcre3.dll when looking for PCRE 2013-12-08 14:24:48 +01:00
Jiapeng Li
aa2c1c47cd Config: bring configuration feature to Windows 2013-12-08 14:17:39 +01:00
Jiapeng Li
d89affd819 UART (Windows): fix uart_flush_input format
This patch allow uart files to be compiled under Windows, it adds a 'wait' parameter but do not use it.

Please note that patch fixes compilation but do not add any feature to Windows support
2013-12-08 14:15:36 +01:00
Jiapeng Li
76a85ce84b CMake: remove tailing newline from date under Windows
This patch prevents from having a newline (\n) within date result in generated RC file
2013-12-08 14:12:06 +01:00
Jiapeng Li
0ee6dcad4b Cmake: add CONFFILES define like available in autotools build system 2013-12-08 14:09:50 +01:00
Romuald Conty
a7fc1bddaf Fix nfc_target_init() timeout return
This patch prevent from returning a successfull error code while timeout occurred.

Thanks to blck on forum:
http://www.libnfc.org/community/post/4913/#p4913
2013-12-06 16:03:00 +01:00
Philippe Teuwen
4817a6e5c9 make style 2013-12-02 22:55:10 +01:00
Philippe Teuwen
a1ef329962 Fix use after free
pn532_uart.c:293:5: warning: Use of memory after it is freed
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "pn53x_check_communication error on %s", ndd.port);
    ^                                                                                                 ~~~~~~~~
2013-11-12 00:43:43 +01:00
Philippe Teuwen
b8e0eec91d nfc-mfclassic: initialize always bFormatCard 2013-11-12 00:43:25 +01:00
Adam Laurie
250068462b add format/wipe command to nfc-mfclassic 2013-11-11 22:03:09 +00:00
Philippe Teuwen
7e5257dd44 Update Changelog 2013-10-01 14:29:51 +02:00
Philippe Teuwen
186cccfe6a pn532_uart: make use of log level for pn53x_check_communication() 2013-10-01 14:14:00 +02:00
Philippe Teuwen
1d0d3c3b45 uart_flush_input() can now wait a bit
Calling ioctl flush too fast before actual garbage bytes arrive was useless.
It solves an issue e.g. when config asks for scanning for multiple incompatible serial devices:
One scan can mess up the reader and we've to wait & flush properly for the next driver to be able to scan correctly
2013-10-01 14:09:15 +02:00
Philippe Teuwen
de1ca46066 Add envvars LIBNFC_DEVICE (to force only one device, no matter the conf files) and LIBNFC_AUTO_SCAN 2013-10-01 14:08:57 +02:00
Philippe Teuwen
1596255506 driver Arygon: don't try to send commands if reset failed 2013-10-01 12:27:19 +02:00
Philippe Teuwen
252f590d5c Revert "Check data from getenv("LIBNFC_LOG_LEVEL") and config file"
This reverts commit 846189b62c.
It didn't solve Coverity somplain and it broke bitfield support of log_level
2013-09-22 19:55:31 +02:00
Philippe Teuwen
846189b62c Check data from getenv("LIBNFC_LOG_LEVEL") and config file
Problem reported by Coverity:
CID 1090344 (#1 of 1): Use of untrusted string value (TAINTED_STRING)
. tainted_string: Passing tainted string "res->log_level" to "log_init(nfc_context const *)", which cannot accept tainted data.[show details]
2013-09-22 19:32:37 +02:00
Philippe Teuwen
9bb568b799 driver acr122_usb: fix dead code issue
Redundant result check leading to dead code was probably indicative
of a missing return value check of acr122_usb_send_apdu()

Problem reported by Coverity:
  at_least: At condition "res < 0", the value of "res" must be at least 12.
  cannot_single: At condition "res < 0", the value of "res" cannot be equal to -6.
  dead_error_condition: The condition "res < 0" cannot be true.
CID 1090327 (#1 of 1): Logically dead code (DEADCODE)
  dead_error_begin: Execution cannot reach this statement "acr122_usb_ack(pnd);".
2013-09-22 19:08:26 +02:00
Philippe Teuwen
117b58f501 nfc-read-forum-tag3: avoid passing large struct as parameter
Problem reported by Coverity:
CID 1090334 (#1 of 1): Big parameter passed by value (PASS_BY_VALUE)
  pass_by_value: Passing parameter nt of type nfc_target const (size 291 bytes) by value.
2013-09-22 18:32:47 +02:00
Philippe Teuwen
4a91859150 Fix unharmful warning
Commit 54729fb458 removed some dead code spotted by Coverity
but it had as effect to trigger a gcc warning, which prefers to see all enum in a switch rather than dead code:

pn53x.c: In function 'pn53x_InJumpForDEP':
pn53x.c:2552:5: warning: enumeration value 'NBR_UNDEFINED' not handled in switch [-Wswitch]
pn53x.c:2552:5: warning: enumeration value 'NBR_847' not handled in switch [-Wswitch]

So both switches were merged, which slightly optimizes the code for speed.
2013-09-22 12:02:31 +02:00
Philippe Teuwen
7cb8fd3833 verify return of pn53x_set_property_bool()
Problem reported by Coverity:
CID 1090321 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "pn53x_set_property_bool(pnd, NP_INFINITE_SELECT, true)".
2013-09-22 03:36:45 +02:00
Philippe Teuwen
2e51318bcb pn53x_usb driver: verify return of pn53x_build_frame()
Problem reported by Coverity:
CID 1090322 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "pn53x_build_frame(abtFrame, &szFrame, pbtData, szData)".
2013-09-22 03:31:50 +02:00
Philippe Teuwen
90160d6507 Fix possible overflow
Note that this could happen e.g. if a fake PN533 sends malicious frames over USB

CID 1090329 (#1 of 1): Overflowed return value (INTEGER_OVERFLOW)
  overflow_sink: Overflowed or truncated value (or a value computed from an overflowed or truncated value) "res" used as return value.
2013-09-22 03:26:33 +02:00
Philippe Teuwen
618ca1e92b Remove dead code
Problem reported by Coverity:
at_most: At condition "io_res < 0", the value of "io_res" must be at most -1.
dead_error_condition: The condition "io_res < 0" must be true.
CID 1090328 (#1 of 1): Logically dead code (DEADCODE)
  dead_error_line: Execution cannot reach this expression "0" inside statement "return (io_res < 0) ? io_re...".
2013-09-22 03:13:09 +02:00
Philippe Teuwen
54729fb458 Remove dead code
Problem reported by Coverity:
  dead_error_condition: The switch value "nbr" cannot be "NBR_UNDEFINED".
  CID 1090326 (#1 of 2): Logically dead code (DEADCODE)
  dead_error_begin: Execution cannot reach this statement "case NBR_UNDEFINED:".
2013-09-22 03:09:08 +02:00
Philippe Teuwen
cedbefb880 nfc-relay-picc: sleep() expects unsigned int
This avoids Coverity being unhappy that only lower bound was defined, well I hope

lower_bounds: Checking lower bounds of signed scalar "waiting_time" by "waiting_time > 0".
CID 1090343 (#1 of 1): Untrusted value as argument (TAINTED_SCALAR)
  tainted_data: Passing tainted variable "waiting_time" to a tainted sink.
  sleep(waiting_time);
2013-09-22 03:00:58 +02:00
Philippe Teuwen
61884967ea nfc-mfclassic: verify return of nfc_initiator_select_passive_target()
Problem reported by Coverity:
CID 1090323 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_initiator_select_passive_target(pnd, nmMifare, nt.nti.nai.abtUid, nt.nti.nai.szUidLen, NULL)".
2013-09-22 02:45:23 +02:00
Philippe Teuwen
a4f466df06 Verify return of nfc_device_set_property_bool()
Problem reported by Coverity:
CID 1090325 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false)".
2013-09-22 02:41:11 +02:00
Philippe Teuwen
e2135dbaa5 pn53x-sam: fix truncated stdio return value
Problem reported by Coverity:
CID 1090318 (#1 of 1): Truncated stdio return value (CHAR_IO)
char_io: Assigning the return value of "getchar(void)" to char "input" truncates its value
2013-09-22 02:38:17 +02:00
Philippe Teuwen
679897d0a1 nfc-emulate-forum-tag4: fix TOCTOU
Hopefully fix TOCTOU by calling fopen() before stat()

At least this should prevent Coverity to complain about it:
CID 1090346 (#1 of 1): Time of check time of use (TOCTOU)
  fs_check_call: Calling function "stat(char const *, struct stat *)" to perform check on "filename".
  toctou: Calling function "fopen(char const * restrict, char const * restrict)" that uses "filename" after a check function. This can cause a time-of-check, time-of-use race condition.

Note that it seems pretty hard to avoid completely:
https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use#Preventing_TOCTTOU
2013-09-22 02:29:07 +02:00
Philippe Teuwen
feb5f37aa3 nfc-read-forum-tag3: remove redundant error
switch case was redundant as getopt was already telling the issue:

  nfc-read-forum-tag3: option requires an argument -- 'o'
  Option -o requires an argument.

This fixes also a problem reported by Coverity about missing break:

CID 1090330 (#1 of 1): Missing break in switch (MISSING_BREAK)
  unterminated_case: This case (value 63) is not terminated by a 'break' statement.
2013-09-22 02:14:08 +02:00
Philippe Teuwen
70048a0b2c uart.c: check return of read()
Fix warning
uart.c:146:3: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]

Also reported by Coverity:
CID undefined (#1 of 1): Ignoring number of bytes read (CHECKED_RETURN)
  check_return: "read(int, void *, size_t)" returns the number of bytes read, but it is ignored.
2013-09-22 02:06:58 +02:00
Philippe Teuwen
b5d76a327d Fix strcpy into fixed size buffer in conf.c
Problem reported by Coverity:

CID 1090340 (#1 of 2): Copy into fixed size buffer (STRING_OVERFLOW)
  fixed_size_dest: You might overrun the 256 byte fixed-size string "context->user_defined_devices[context->user_defined_device_count - 1U].name" by copying "value" without checking the length.
  parameter_as_source: Note: This defect has an elevated risk because the source argument is a parameter of the current function.
CID 1090340 (#2 of 2): Copy into fixed size buffer (STRING_OVERFLOW)[select issue]
2013-09-22 01:57:58 +02:00
Philippe Teuwen
d9854cfdd9 Fix out-of-bounds access in driver acr122_pcsc
Problem reported by Coverity:
CID 1091328 (#1 of 1): Out-of-bounds access (OVERRUN)
  overrun-buffer-arg: Overrunning buffer pointed to by "&abtTxBuf[6]" of 271 bytes by passing it to a function which accesses it at byte offset 271 using argument "szData" (which evaluates to 266).
2013-09-22 01:47:15 +02:00
Philippe Teuwen
d9b531f50f Verify return of nfc_device_set_property_bool()
Problem reported by Coverity
CID 1090319 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, nt.nti.nai.btSak & 0x20)".
CID 1090320 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(dev, NP_HANDLE_CRC, false)".
CID 1090324 (#1 of 2): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, true)".
CID 1090325 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false)".
2013-09-22 01:31:45 +02:00
Philippe Teuwen
ddf58f2d69 Changing conditions to avoid Coverity to complain in artificial situations
CID 1090331 (#1 of 1): Out-of-bounds access (OVERRUN)
11. overrun-buffer-arg: Overrunning array "pnti->nai.abtUid" of 10 bytes by passing it to a function which accesses it at byte offset 11 using argument "pnti->nai.szUidLen" (which evaluates to 12).
2013-09-20 00:13:21 +02:00