I use nRFConnect iOS APP to pair nRF52832 device. But it failed to show passkey dialog.
I use nRFConnect iOS APP to pair nRF52832 device. But it failed to show passkey dialog.
I am not sure "it failed to show passkey dialog" means?
There does not seem to be any encryption requested by either side of the device. How do you want to initiate pairing?
Please go through this case where my colleague Vidar tried to explain what is expected on the peripheral side for the pairing to work with Apple devices.
I have added the following configuration in prj.conf.
CONFIG_BT_FIXED_PASSKEY=y
CONFIG_BT_GATT_AUTO_SEC_REQ=y
CONFIG_BT_SMP=y
And I also add the following code in bt.c for static pairing
bt_passkey_set(123456); // in btInit()
bt_conn_set_security(conn, BT_SECURITY_L2); // in connected() callback function
Now nRFConnect iOS APP shows pairing request information. But it doesn't shows dialog for me to enter passkey 123456.
I have another question. nRFConnect iOS APP shows connected even if I enter wrong passkey (e.g. 111111).
00> *** Booting Zephyr OS build v3.2.99-ncs2 ***
00> Starting button Test example
00> btInit() e
00> bt_passkey_set(123456)
00> _btReady(0) e
00> Bluetooth initialized
00> calling bt_le_adv_start() begin
00> calling bt_le_adv_start() end
00> _btReady(0) x
00> btInit() x
00> Starting button Test example
00> device_is_ready() ok
00> gpio_pin_configure_dt() ok
00> gpio_pin_interrupt_configure_dt() ok
00> Set up button at gpio@50000000 pin 27
00> button state=1
00> start a timer
00> Button pressed or released
00> Button pressed at 4064315
00> Connected 44:78:DB:9A:A4:3A (random)[00:02:22.595,245] <wrn> bt_l2cap: Ignoring data for unknown channel ID 0x003a
00> Passkey for 44:78:DB:9A:A4:3A (random): 123456Security failed: 44:78:DB:9A:A4:3A (random) level 1 err 1Pairing failed conn: 44:78:DB:9A:A4:3A (random), reason 1
How to add code in pairing_failed() for triggering nRFConnect iOS APP to disconnect.
static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Pairing failed conn: %s, reason %d", addr, reason);
}
How to add code in pairing_failed() for triggering nRFConnect iOS APP to disconnect.
static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Pairing failed conn: %s, reason %d", addr, reason);
}
I have added bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN) to pairing_failed() callback function. Now nRFConnect iOS APP can disconnect successfully.
static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
printk("Pairing failed conn: %s, reason %d", addr, reason);
}
Thanks for letting us know about the fix snowuyl.