Setting Up Bluetooth OOB Pairing with NFC on Raspberry Pi

This post shows steps to setup Bluetooth Out-Of-Band (OOB) pairing using NFC [1] on Raspberry Pi using nfcpy [2]. The goal is to pair a phone and Raspberry Pi by just touching each other.

 

Prerequisites (parentheses indicate my environment)

 

Steps
1. Installation
1-1. Install nfcpy.

pip install -U nfcpy

1-2. Verify installation by running the module.

python -m nfc

The output should be like this:

$ python -m nfc
No handlers could be found for logger "nfc.llcp.sec"
This is the 0.13.5 version of nfcpy run in Python 2.7.13
on Linux-4.14.50-v7+-armv7l-with-debian-9.4
I'm now searching your system for contactless devices
** found usb:04e6:5591 at usb:001:004 but access is denied
-- the device is owned by 'root' but you are 'pi'
-- also members of the 'root' group would be permitted
-- you could use 'sudo' but this is not recommended
-- better assign the device to the 'plugdev' group
sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"04e6\", ATTRS{idProduct}==\"5591\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'
sudo udevadm control -R # then re-attach device
I'm not trying serial devices because you haven't told me
-- add the option '--search-tty' to have me looking
-- but beware that this may break other serial devs
Sorry, but I couldn't find any contactless device

1-3. As the output suggests, copy line 11 above and execute it.

sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"04e6\", ATTRS{idProduct}==\"5591\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'

1-4. Reboot the system.

sudo reboot

1-5. After reboot, run the module again.

python -m nfc

This time, the output should be like this:

$ python -m nfc
No handlers could be found for logger "nfc.llcp.sec"
This is the 0.13.5 version of nfcpy run in Python 2.7.13
on Linux-4.14.50-v7+-armv7l-with-debian-9.4
I'm now searching your system for contactless devices
** found SCM Micro SCL3711-NFC&RW PN533v2.7 at usb:001:004
I'm not trying serial devices because you haven't told me
-- add the option '--search-tty' to have me looking
-- but beware that this may break other serial devs

 

2. Setting up Bluetooth OOB Pairing
2-1. Download example code [3].

git clone https://github.com/nfcpy/nfcpy.git

2-2. Create NDEF data [4] for Bluetooth OOB pairing [5].

./nfcpy/examples/ndeftool.py make btcfg -o bt_oob_conf XX:XX:XX:XX:XX:XX

Note: Replace “XX:XX:XX:XX:XX:XX” with your Raspberry Pi’s Bluetooth device address.

2-3. Write NDEF data to NFC adapter [6].

./nfcpy/examples/tagtool.py emulate -l bt_oob_conf tt3

2-4. Open another terminal and launch Bluetooth command line interface.

bluetoothctl

2-5. Enable the pairing agent.

agent NoInputNoOutput

2-6. Set the agent as default agent.

default agent

2-7. Enable discoverable mode.

discoverable on

 

3. Test
3-1. Enable NFC on the phone.

3-2. Move the phone close to the NFC adapter.

3-3. Allow the pairing request on the phone.

3-4. Allow the service authorization on Raspberry Pi if requested.

Authorize service
[agent] Authorize service 0000111E-0000-1000-8000-00805F9B34FB (yes/no): yes
Authorize service
[agent] Authorize service 0000110d-0000-1000-8000-00805f9b34fb (yes/no): yes

 

 

References
[1] Bluetooth Secure Simple Pairing Using NFC – NFC Forum
[2] Python module for near field communication – nfcpy
[3] nfcpy – GitHub
[4] NFC Data Exchange Format – nfcpy
[5] make btcfg – nfcpy
[6] emulate – nfcpy