From 30c7f1790b26b3b156d3143d30c37bd4c992a810 Mon Sep 17 00:00:00 2001 From: Stuart Langridge Date: Thu, 27 Jan 2022 16:56:58 +0000 Subject: [PATCH] nrf/drivers/bluetooth: Handle PHY_UPDATE messages, used in Bluetooth 5. Some devices, such as the LightBlue BTLE app on iOS, try to use Bluetooth 5 when connecting to a device. This means that they will send a BLE_GAP_EVT_PHY_UPDATE_REQUEST message to shift to a new physical layer. If this event isn't handled, LightBlue (and likely other Bluetooth 5.0 central devices) will try to connect and then fail, staying in "Connecting..." state forever. This message should be replied to with sd_ble_gap_phy_update, as documented in drivers/bluetooth/s140_nrf52_6.1.1/s140_nrf52_6.1.1_API/include/ble_gap.h. This commit handles the event. LightBlue can now successfully connect to a BTLE device on a P10059 nRF52840 dongle running MicroPython. Two other related events have logging added in case they are needed in the future. --- ports/nrf/drivers/bluetooth/ble_drv.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ports/nrf/drivers/bluetooth/ble_drv.c b/ports/nrf/drivers/bluetooth/ble_drv.c index 0040580933..173d3eda01 100644 --- a/ports/nrf/drivers/bluetooth/ble_drv.c +++ b/ports/nrf/drivers/bluetooth/ble_drv.c @@ -1136,6 +1136,24 @@ static void ble_evt_handler(ble_evt_t * p_ble_evt) { sd_ble_gap_data_length_update(p_ble_evt->evt.gap_evt.conn_handle, NULL, NULL); break; + case BLE_GAP_EVT_PHY_UPDATE_REQUEST: + BLE_DRIVER_LOG("BLE_GAP_EVT_PHY_UPDATE_REQUEST\n"); + ble_gap_phys_t const phys = + { + BLE_GAP_PHY_AUTO, + BLE_GAP_PHY_AUTO, + }; + sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys); + break; + + case BLE_GAP_EVT_PHY_UPDATE: + BLE_DRIVER_LOG("BLE_GAP_EVT_PHY_UPDATE -- unhandled!\n"); + break; + + case BLE_GAP_EVT_DATA_LENGTH_UPDATE: + BLE_DRIVER_LOG("BLE_GAP_EVT_DATA_LENGTH_UPDATE -- unhandled!\n"); + break; + #endif // (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140) default: