Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initiate BLE pairing on BlueZ

I want to initiate pairing on Bluez with a Bluetooth Low Energy device. While there are some posts on how to trigger the SMP procedures using GATT, there is not much available if you do not want to use GATT.

My use case is that I want to use an encrypted link for bluetooth-6lowpan which exchanges data over L2CAP credit based mode and not ATT/GATT.

Further, I would like to use the OOB mode for SMP pairing.

Pointers on how I could trigger SMP pairing either using command line or writing a C program is appreciated.

Thank you!

like image 638
Krishna Shingala Avatar asked Sep 05 '25 03:09

Krishna Shingala


1 Answers

I don't think it's possible to perform BLE pairing without the use of GATT commands (from the command line only). The reason for this is that security in LE is GATT-action-based. In other words, the characteristic/service permissions dictate whether you need to pair with the device or not (i.e. to read the heart rate characteristic, the device might dictate that you need to be paired first). For this, the operation would be something like:

gatttool --sec-level=high --device=00:11:22:33:44:55:66 --char-read --uuid=0x2A37

This command will establish pairing first before reading the characteristic.

As for how to perform this using a C program, You can download the BlueZ source code and have a look at what passing this "sec-level" option does. I've quickly browsed through the code and found this in utils.c:-

            chan = bt_io_connect(connect_cb, NULL, NULL, &tmp_err,
            BT_IO_OPT_SOURCE_BDADDR, &sba,
            BT_IO_OPT_SOURCE_TYPE, BDADDR_LE_PUBLIC,
            BT_IO_OPT_DEST_BDADDR, &dba,
            BT_IO_OPT_DEST_TYPE, dest_type,
            BT_IO_OPT_CID, ATT_CID,
            BT_IO_OPT_SEC_LEVEL, sec,
            BT_IO_OPT_INVALID);

where sec is set with sec = BT_IO_SEC_HIGH;

I hope this helps.

like image 143
Youssif Saeed Avatar answered Sep 07 '25 23:09

Youssif Saeed