BLE Just Works on nrf52832 and NRF Connect

Hi, I am working on something that requires me to use Just Works on nrf52832 custom board. Here is the work sccenario. under normal conditions, my module has a bonding PIN and the user is supposed to enter the PIN on his application to get data. My NRF module is a peripheral and i have enabled following in the prj.conf.


CONFIG_BT_NUS_SECURITY_ENABLED

CONFIG_BT_FIXED_PASSKEY

I have registered the necessary callbacks too.

What I now need to implement is a functionality which allows user to bond without a PIN temporarily after a button press. I assume BLE Just Works is what I need for this purpose. But I am open to any other suggestions or new perspectives to get this done.Thanks in advance.

  • Hi Midhunjac, 

    To be able to change the capability of the device to not have passkey (no display and keyboard) what you need to do is to 

    bt_conn_auth_cb_register() with NULL input to remove the callback. Then you recall the bt_conn_auth_cb_register() without the display or confirm or entry callback. 

    However we need to look at how you define your characteristics as well. Because in the characteristic definitions you also define the minimum level of security to access the characteristics. If you set it to requires MITM, having Just work bonding would not be enough to allow accessing the characteristics. 
    If it's the case you may want to reinitalize the characteristic with new parameter. 
  • Hi, here is the code snippet defining my characteristics. Is there any change that I should do in this definition for Just Works to work ? Meanwhile, I will try out your suggestion and let you know.

    BT_GATT_SERVICE_DEFINE(nus_custom,BT_GATT_PRIMARY_SERVICE(BT_UUID_DIS),
    						//BT_GATT_CHARACTERISTIC(BT_UUID_NUS_RX,BT_GATT_CHRC_NOTIFY| BT_GATT_CHRC_WRITE,BT_GATT_PERM_WRITE,write_rcv,on_receive,NULL),
    						BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MANUFACTURER_NAME,BT_GATT_CHRC_READ,BT_GATT_PERM_READ,get_manufacturer_name,NULL,NULL),
    						BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER,BT_GATT_CHRC_READ,BT_GATT_PERM_READ,get_model_name,NULL,NULL),
    						BT_GATT_CHARACTERISTIC(BT_UUID_DIS_SERIAL_NUMBER,BT_GATT_CHRC_READ,BT_GATT_PERM_READ,get_serial_number,NULL,NULL),
    						BT_GATT_CHARACTERISTIC(BT_UUID_DIS_HARDWARE_REVISION,BT_GATT_CHRC_READ,BT_GATT_PERM_READ,get_hardware_rev,NULL,NULL),
    						BT_GATT_CHARACTERISTIC(BT_UUID_DIS_FIRMWARE_REVISION,BT_GATT_CHRC_READ,BT_GATT_PERM_READ,get_firmware_rev,NULL,NULL),
    						BT_GATT_CHARACTERISTIC(BT_UUID_DIS_SOFTWARE_REVISION,BT_GATT_CHRC_READ,BT_GATT_PERM_READ,get_software_rev,NULL,NULL),
    						);

  • I tried your suggestion but it didnt work. When I tried out what you suggested, the bonding failed. These are the logs.

    <inf>: Connected 68:4A:E9:DC:F3:BC (public)
    <wrn>: Security failed: 68:4A:E9:DC:F3:BC (public) level 1 err 4
    <inf> migration1: Pairing failed conn: 68:4A:E9:DC:F3:BC (public), reason 4
    <inf>: Disconnected: 68:4A:E9:DC:F3:BC (public) (reason 19)
    <inf>:Disconnected 68:4A:E9:DC:F3:BC (public) :
    I am sure it must be a mistake on my side. Can you please take a look at this ? Isn't this how you suggested that I do ? Just to make sure that we are not misunderstanding each other, I am using NCSv2.1.0 and for testing purposes, I have switched to the basic peripheral UART example. So the characteristics of that particular service applies now. What I am testing is if I can bond with the peripheral without a passkey. I am not trying to access any particular characteristic. I just want to bond with the peripheral straight away.

    /*some code*/
    err = bt_conn_auth_cb_register(NULL);
    err = bt_conn_auth_cb_register(&conn_auth_callbacks);
    /* some code */
    
    static struct bt_conn_auth_cb conn_auth_callbacks = {
    		.cancel = auth_cancel,
    
    };

    Tried adding the bt_conn_auth_cb_register() with the passkey display and passkey entry and passkey confirm callbacks set to NULL. That didnt work out too.

  • Hi Midhunjac, 

    It doesn't seem you characteristic require any encryption at all. Have you tried to access the characteristic without bonding ?
    For example you can use nRF Connect and try to read the characteristic. 

    There are multiple level of permision you can configure: 

    	/** Attribute read permission. */
    	BT_GATT_PERM_READ = BIT(0),
    
    	/** Attribute write permission. */
    	BT_GATT_PERM_WRITE = BIT(1),
    
    	/** @brief Attribute read permission with encryption.
    	 *
    	 *  If set, requires encryption for read access.
    	 */
    	BT_GATT_PERM_READ_ENCRYPT = BIT(2),
    
    	/** @brief Attribute write permission with encryption.
    	 *
    	 *  If set, requires encryption for write access.
    	 */
    	BT_GATT_PERM_WRITE_ENCRYPT = BIT(3),
    
    	/** @brief Attribute read permission with authentication.
    	 *
    	 *  If set, requires encryption using authenticated link-key for read
    	 *  access.
    	 */
    	BT_GATT_PERM_READ_AUTHEN = BIT(4),
    
    	/** @brief Attribute write permission with authentication.
    	 *
    	 *  If set, requires encryption using authenticated link-key for write
    	 *  access.
    	 */
    	BT_GATT_PERM_WRITE_AUTHEN = BIT(5),

    BT_GATT_PERM_READ: Read possible even without bonding/encryption.
    BT_GATT_PERM_READ_ENCRYPT would require encryption and MITM is not needed.

    BT_GATT_PERM_READ_AUTHEN would require encryption and MITM. 

  • I can access the characteristics without bonding. But that is not really my goal. I want to get bond with the peripheral even though it is not necessary. As part of testing I did try out BT_GATT_PERM_READ_ENCRYPT and BT_GATT_PERM_READ_AUTHEN and they worked as expected, prompting for passkey and all. But I want to bond without a passkey independent of whether the characteristics requires it or not.

Related