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

Working with NFC pairing in nRF Connect SDK .

Hi Nordic Team,

I am new to embedded programming. I am trying to explore pairing using NFC(Near Field Communication).

I am working with nRF5340 and nRF Connect SDK v1.5.0

I am using this Bluetooth: NFC pairing example to study pairing between nRF5340 and Android mobile( oneplus 8t) with nRF Connect for Mobile app.

From the documentation of the example , it says "the sample supports pairing in 

  • LE Secure Connections Just Works pairing

  • LE Secure Connections OOB pairing

  • Legacy OOB pairing

  • Legacy Just Works pairing

  • Negotiated Handover(TNEP protocol) - two-way OOB pairing"

I have some doubts with the implementation.

1.How to choose a desired method of paring from the above 5 modes?

For example, nRF5 SDK Nordic Semiconductor Infocenter guides to use buttons to switch between the modes. But Bluetooth: NFC pairing — nRF Connect SDK 1.5.0 documentation (nordicsemi.com) did not explain about switching different modes.

2.I have tested the sample with android mobile : Oneplus 8t. While I touched the NFC antenna from DK, the mobile received a popup "Do you want to pair...", after clicking YES, i could see the device gets bonded and i could connect to it with nRF connect app. Here what method of pairing is used (LE Legacy / LESC)? .

Also i found that on the mobile side, the data from NFC record is read by the Android generic nfc service. 

If i am right, the nRF Connect for Mobile app takes the bonding related data from the android's nfc service?

And can you point me what data are being transmitted through NFC records from DK to Mobile. Is it one way communication from DK to Mobile or two way?

Sorry for so many questions.

Thanks and Regards,
S Mohan 

  • Hi,

    1.How to choose a desired method of paring from the above 5 modes?

    The example is configured to support all five options simultaneously, and which is used is determined dynamically based on the capabilities of the device you test with.

    Here what method of pairing is used (LE Legacy / LESC)? .

    You sould see that from the UART log. Have you looked at it? Can you paste it here?

    If i am right, the nRF Connect for Mobile app takes the bonding related data from the android's nfc service?

    I am not sure I understand the question. Can you clarify?

    And can you point me what data are being transmitted through NFC records from DK to Mobile. Is it one way communication from DK to Mobile or two way?

     This depends on whether TNEP is used or not (TNEP is bidirectional, but quite new and not widely supported). When not using TNEP, data over NFC flows from the tag (nRF) to the reader. You can see this illustrated under Static Handover.

  • HI Mr. Einar ,

    Thank you so much for replying.

    You sould see that from the UART log. Have you looked at it? Can you paste it here?

    I am attaching the logs from DK board and the Mobile nRF Logger

    Clock driver initialization*** Booting Zephyr OS build v2.4.99-ncs1  ***
    Starting Bluetooth NFC Pairing Reference example
    Bt_enable entered...
    I: 2 Sectors of 4096 bytes
    I: alloc wra: 0, fd8
    I: data wra: 0, 1c
    I: No ID address. App must call settings_load()
    Bluetooth initialized
    Generating new pairing keys
    NFC configuration done
    Regular advertising started
    Connected 42:F9:9D:B2:50:2C (random)
    Pairing confirmed: 42:F9:9D:B2:50:2C (random)
    Security changed: 42:F9:9D:B2:50:2C (random) level 2
    Pairing completed: 5C:17:CF:A4:7B:57 (public), bonded: 1
    Generating new pairing keys
    
    

    nRF Connect, 2021-04-22
    Nordic_NFC_pairing (EB:CB:39:B8:FA:F9)
    V	16:29:38.694	Connecting to EB:CB:39:B8:FA:F9...
    D	16:29:38.694	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
    D	16:29:38.703	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I	16:29:38.703	Connected to EB:CB:39:B8:FA:F9
    D	16:29:38.703	wait(1600ms)
    V	16:29:40.304	Discovering services...
    D	16:29:40.304	gatt.discoverServices()
    D	16:29:40.317	[Callback] Services discovered with status: 0
    I	16:29:40.317	Services discovered
    V	16:29:40.324	Generic Attribute (0x1801)
    - Service Changed [I] (0x2A05)
       Client Characteristic Configuration (0x2902)
    - Client Supported Features [R W] (0x2B29)
    - Database Hash [R] (0x2B2A)
    Generic Access (0x1800)
    - Device Name [R] (0x2A00)
    - Appearance [R] (0x2A01)
    - Peripheral Preferred Connection Parameters [R] (0x2A04)
    Device Information (0x180A)
    - Model Number String [R] (0x2A24)
    - Manufacturer Name String [R] (0x2A29)
    - PnP ID [R] (0x2A50)
    D	16:29:40.324	gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
    

    I could able to bond and connect with Bluetooth. But I am unsure which type of pairing took place dynamically(from the 5 types), and which protocol format is used in NFC data exchange(TNEP supported or not), whether the NFC data exchange is bidirectional or unidirectional?. 

    I am attaching the unedited prj.conf file.

    #
    # Copyright (c) 2020 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    CONFIG_DK_LIBRARY=y
    
    CONFIG_NFC_T4T_NRFXLIB=y
    
    CONFIG_NFC_NDEF=y
    CONFIG_NFC_NDEF_MSG=y
    CONFIG_NFC_NDEF_RECORD=y
    CONFIG_NFC_NDEF_LE_OOB_REC=y
    CONFIG_NFC_NDEF_CH_MSG=y
    
    CONFIG_NFC_NDEF_TNEP_RECORD=y
    CONFIG_NFC_TNEP_TAG=y
    CONFIG_NFC_NDEF_PARSER=y
    CONFIG_NFC_NDEF_CH_PARSER=y
    CONFIG_NFC_NDEF_LE_OOB_REC_PARSER=y
    CONFIG_NFC_TNEP_CH=y
    
    CONFIG_BT=y
    CONFIG_BT_SMP=y
    CONFIG_BT_SMP_APP_PAIRING_ACCEPT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_NFC_pairing"
    CONFIG_BT_TINYCRYPT_ECC=y
    
    CONFIG_BT_DIS=y
    CONFIG_BT_DIS_PNP=y
    CONFIG_BT_DIS_MANUF="NordicSemiconductor"
    CONFIG_BT_DIS_PNP_VID_SRC=2
    CONFIG_BT_DIS_PNP_VID=0x1915
    CONFIG_BT_DIS_PNP_PID=0xEEEF
    CONFIG_BT_DIS_PNP_VER=0x0100
    
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_MAIN_STACK_SIZE=3072
    
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    
    CONFIG_DK_LIBRARY=y
    

    Please take a look and let me know if any additional configs need to be added to see the logs that show which method of pairing takes place.

    I am not sure I understand the question. Can you clarify?

    Sure. I was thinking how internally the nRF Connect for mobile app reads the records. I found out that, android os of my mobile has a android service named "nfc service",

    I have attached the screenshots of this service. here, the popup that says yes or no, is also given by this nfc service only. So i was thinking that nRF Connect mobile app would copy the records with the help of this android service internally. I am planning to implement NFC feature in nRF mesh app, so i though this understanding would help me.

    It would be great if you could help me in finding the method of pairing used and NFC data exchange type through logs. Thank you so much.

    Regards,

    S Mohan.

  • Hi Mohan,

    You can seer "Security changed: 42:F9:9D:B2:50:2C (random) level 2". So it is using legacy pairing without authentication/MITM (No LESC). TNEP is not yet supported by Android (nor iOS).

    Regarding the pairing implementation I just talked to our mobile App team, and they do not do any handling of pairing/bonding specifically. All the details there are handled by the BLE stack on Android, the app can only trigger Pairing/bonding (on iOS even that is not possible, and it is all handled automatically by the stack).

    Einar

Related