This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NFC type 4 and Linux (neard) interoperability

Hi, I'm trying to use NFC type 4 tag on nRF52 side (PCA10040) and poll and read it on Embedded Linux using neard [1]. I'm not an expert in NFC area, so I could be wrong in some my assumptions, I beg a pardon in advance if something wrong with my setup.

I use 4.10.5 version of Linux kernel and the latest version (0.16) of neard. I use st95hf driver from mainline, without any additional patches (HW: cr95hf - slightly modified version of the chip with UART as an option)[2]. For getting started quickly I grabbed experimental_writable_ndef_msg example project.

I power up the adapter and start polling. It detects the tag successfully, but when it tries to read NDEF Tag Application Name ({0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01}) nRF always replied with error code 0x6a82 (NDEF Tag Application not found; no data is returned -- according to specification[3]).

There is debug output from neard:

neard[213]: src/adapter.c:append_protocols() protocols 0xd0
neard[213]: src/adapter.c:start_poll_loop() conn 0x56898
neard[213]: src/adapter.c:start_poll_loop() Mode Initiator
neard[213]: src/adapter.c:adapter_start_poll() Poll mode 0x1
neard[213]: src/netlink.c:__near_netlink_start_poll() IM protos 0xd0 TM protos 0x0
neard[213]: src/netlink.c:__nl_send_msg() 
neard[213]: src/netlink.c:ack_handler() 
neard[213]: src/netlink.c:no_seq_check() 
neard[213]: src/netlink.c:nfc_netlink_event() event 0x9
neard[213]: src/netlink.c:nfc_netlink_event() Targets found
neard[213]: src/netlink.c:nfc_netlink_event_targets_found() 
neard[213]: src/netlink.c:nfc_netlink_event_targets_found() adapter 0
neard[213]: src/netlink.c:__nl_send_msg() 
neard[213]: src/netlink.c:get_targets_handler() 
neard[213]: src/netlink.c:get_targets_handler() target idx 0 proto 0x10 sens_res 0x44 sel_res 0x20 NFCID len 7
neard[213]: src/netlink.c:get_targets_handler()         iso15693_uid_len 0
neard[213]: src/adapter.c:__near_adapter_add_target() idx 0
neard[213]: src/tag.c:tag_initialize() 
neard[213]: src/tag.c:set_tag_type() protocol 0x10 sens_res 0x44 sel_res 0x20
neard[213]: src/tag.c:set_tag_type() proto 0x1
neard[213]: src/tag.c:set_tag_type() tag type 0x4
neard[213]: src/tag.c:__near_tag_add() connection 0x56898
neard[213]: src/adapter.c:near_adapter_connect() idx 0
neard[213]: src/tag.c:__near_tag_read() type 0x4
neard[213]: src/adapter.c:__near_adapter_stop_check_presence() 
neard[213]: src/tag.c:__near_tag_read() driver type 0x1
neard[213]: src/tag.c:__near_tag_read() driver type 0x2
neard[213]: src/tag.c:__near_tag_read() driver type 0x3
neard[213]: src/tag.c:__near_tag_read() driver type 0x4
neard[213]: plugins/nfctype4.c:nfctype4_read() 
neard[213]: plugins/nfctype4.c:ISO_Select() 
neard[213]: plugins/nfctype4.c:ISO_send_cmd() CLA-00 INS-a4 P1-04 P2-00
neard[213]: src/adapter.c:near_adapter_send() idx 0
neard[213]: src/adapter.c:near_adapter_send() req 0x598b8 cb 0x22c1c data 0x56f38
neard[213]: src/netlink.c:__finish_handler() 
neard[213]: src/netlink.c:get_targets_finish_handler() 
neard[213]: src/adapter.c:__near_adapter_get_targets_done() idx 0
neard[213]: src/tag.c:type_string() type 0x4
neard[213]: src/tag.c:protocol_string() protocol 0x10
neard[213]: src/adapter.c:adapter_recv_event() condition 0x1
neard[213]: src/adapter.c:execute_recv_cb() data 0x56f38
neard[213]: plugins/nfctype4.c:t4_select_file_by_name_v2() 3
neard[213]: plugins/nfctype4.c:t4_select_file_by_name_v2() Fallback to V1
neard[213]: plugins/nfctype4.c:ISO_Select() 
neard[213]: plugins/nfctype4.c:ISO_send_cmd() CLA-00 INS-a4 P1-04 P2-00
neard[213]: src/adapter.c:near_adapter_send() idx 0
neard[213]: src/adapter.c:near_adapter_send() req 0x5b940 cb 0x235a4 data 0x56f38
neard[213]: src/adapter.c:adapter_recv_event() condition 0x1
neard[213]: src/adapter.c:execute_recv_cb() data 0x56f38
neard[213]: plugins/nfctype4.c:t4_select_file_by_name_v1() 3
neard[213]: plugins/nfctype4.c:t4_select_file_by_name_v1() V1 Fail SW:x6a82
neard[213]: plugins/nfctype4.c:t4_cookie_release() 0x56f38
neard[213]: src/adapter.c:tag_read_cb() status -5
neard[213]: src/adapter.c:near_adapter_disconnect() idx 0
neard[213]: src/adapter.c:near_adapter_disconnect() link 0x5a678
neard[213]: src/adapter.c:near_adapter_disconnect() tag type 4
neard[213]: src/adapter.c:__near_adapter_remove_target() idx 0
neard[213]: src/tag.c:__near_tag_remove() path /org/neard/nfc0/tag0
neard[213]: src/tag.c:free_tag() tag 0x5a678

Here is logging information from kernel:

[ 4911.620000] DIGITAL TX: 26 01 00
[ 4911.660000] DIGITAL TX: 26 01 00
[ 4911.760000] DIGITAL TX: 05 00 00
[ 4912.400000] DIGITAL TX: 26
[ 4912.580000] DIGITAL TX: 05 00 00
[ 4913.220000] DIGITAL TX: 26 01 00
[ 4913.260000] DIGITAL TX: 26
[ 4913.260000] DIGITAL RX: 44 00
[ 4913.260000] DIGITAL TX: 93 20
[ 4913.260000] DIGITAL RX: 88 5f 87 a6 f6
[ 4913.260000] DIGITAL TX: 93 70 88 5f 87 a6 f6
[ 4913.260000] DIGITAL RX: 24
[ 4913.260000] DIGITAL TX: 95 20
[ 4913.260000] DIGITAL RX: 26 24 cc a8 66
[ 4913.260000] DIGITAL TX: 95 70 26 24 cc a8 66
[ 4913.270000] DIGITAL RX: 20
[ 4913.270000] DIGITAL TX: e0 80
[ 4913.270000] DIGITAL RX: 05 78 80 42 02
[ 4913.270000] digital_target_found:379: digital: digital_target_found: rf_tech=0, protocol=4
[ 4913.270000] nfc_targets_found:780: nfc: nfc_targets_found: dev_name=nfc0 n_targets=1
[ 4913.290000] rawsock_create:342: nfc: rawsock_create: sock=cf5c9680
[ 4913.290000] rawsock_connect:95: nfc: rawsock_connect: sock=cf5c9680 sk=cf36b000 flags=2
[ 4913.290000] rawsock_connect:102: nfc: rawsock_connect: addr dev_idx=0 target_idx=0 protocol=4
[ 4913.290000] nfc_activate_target:411: nfc: nfc_activate_target: dev_name=nfc0 target_idx=0 protocol=4
[ 4913.290000] rawsock_sendmsg:221: nfc: rawsock_sendmsg: sock=cf5c9680 sk=cf36b000 len=12
[ 4913.290000] rawsock_tx_work:196: nfc: rawsock_tx_work: sk=cf36b000 target_idx=0
[ 4913.290000] nfc_data_exchange:504: nfc: nfc_data_exchange: dev_name=nfc0 target_idx=0 skb->len=12
[ 4913.290000] DIGITAL TX: 02 00 a4 04 00 07 d2 76 00 00 85 01 01
[ 4913.300000] DIGITAL RX: 02 6a 82
[ 4913.300000] rawsock_data_exchange_complete:157: nfc: rawsock_data_exchange_complete: sk=cf36b000 err=0
[ 4913.300000] rawsock_recvmsg:259: nfc: rawsock_recvmsg: sock=cf5c9680 sk=cf36b000 len=1024 flags=64
[ 4913.310000] rawsock_sendmsg:221: nfc: rawsock_sendmsg: sock=cf5c9680 sk=cf36b000 len=12
[ 4913.310000] rawsock_tx_work:196: nfc: rawsock_tx_work: sk=cf36b000 target_idx=0
[ 4913.310000] nfc_data_exchange:504: nfc: nfc_data_exchange: dev_name=nfc0 target_idx=0 skb->len=12
[ 4913.310000] DIGITAL TX: 03 00 a4 04 00 07 d2 76 00 00 85 01 00
[ 4913.310000] DIGITAL RX: 03 6a 82
[ 4913.310000] rawsock_data_exchange_complete:157: nfc: rawsock_data_exchange_complete: sk=cf36b000 err=0
[ 4913.310000] rawsock_recvmsg:259: nfc: rawsock_recvmsg: sock=cf5c9680 sk=cf36b000 len=1024 flags=64
[ 4913.320000] rawsock_release:73: nfc: rawsock_release: sock=cf5c9680 sk=cf36b000
[ 4913.320000] rawsock_destruct:320: nfc: rawsock_destruct: sk=cf36b000
[ 4913.320000] nfc_deactivate_target:457: nfc: nfc_deactivate_target: dev_name=nfc0 target_idx=0

And the following fragment is a bit modified logging from nRF52 side:

HAL_NFC:INFO:Reinitialize
HAL_NFC:DEBUG:Field detected
HAL_NFC:DEBUG:Field detected
HAL_NFC:DEBUG:Field detected
:DEBUG:nfc_callback: 1
HAL_NFC:DEBUG:Selected
HAL_NFC:DEBUG:RX: T4T Activate
HAL_NFC:INFO:Send
HAL_NFC:DEBUG:Rx fend
HAL_NFC:DEBUG:
E0 80                                            ..              
HAL_NFC:DEBUG:Tx fend
HAL_NFC:INFO:Send
HAL_NFC:DEBUG:Rx fend
HAL_NFC:DEBUG:
02 00 A4 04 00 07 D2 76 00 00 85 01 01           .......v.....   
HAL_NFC:DEBUG:Tx fend
HAL_NFC:INFO:Send
HAL_NFC:DEBUG:Rx fend
HAL_NFC:DEBUG:
03 00 A4 04 00 07 D2 76 00 00 85 01 00           .......v.....   
HAL_NFC:DEBUG:Tx fend

I really have no clue where the problem could be: whether it on adapter or tag side. I'd really appreciate if you could take a look and give me a direction where to dig for a solution.

[1] https://01.org/linux-nfc [2] www.st.com/.../en.DM00102056.pdf [3] apps4android.org/.../NFCForum-TS-Type-4-Tag_2.0.pdf

  • Hi,

    looking at your log, the adapter side sends a too short Command APDU: 02 00 a4 04 00 07 d2 76 00 00 85 01 01 The first byte: 02 is an ISO-DEP I-block header, then "Select NDEF Application" APDU is sent: 00 a4 04 00 07 d2 76 00 00 85 01 01 00, but it is missing the highlighted 00 byte at the end. This byte is called Le and it tells how many data bytes shall be sent in a Response APDU, and in case of this command it should be 0 (see Table 10. in NFC Forum Type 4 Tag Operation Specification v2.0).

    So please check with the adapter, why it sends a truncated first Command: "Select NDEF Application".

  • Hi Michał, it was clearly the problem in the code of neard (plugins/nfctype4.c). The ISO_Select function doesn't work correctly for all cases. I'm preparing a patch for sending to upstream. Thank you very much, I really appreciate your help.

Related