From b41bf592045a999ba9b8c58036f8228ab3640855 Mon Sep 17 00:00:00 2001 From: Geng Yuchao Date: Thu, 25 Jul 2024 14:37:49 +0800 Subject: [PATCH] (feat) nimble : Add hci event and startup for Bluetooth LE 5.1 Direction Finding feature. --- nimble/host/src/ble_hs_hci_evt.c | 57 ++++++++++++++++++++++++++++++++ nimble/host/src/ble_hs_startup.c | 12 +++++++ 2 files changed, 69 insertions(+) diff --git a/nimble/host/src/ble_hs_hci_evt.c b/nimble/host/src/ble_hs_hci_evt.c index 64b37f018..16d76e649 100644 --- a/nimble/host/src/ble_hs_hci_evt.c +++ b/nimble/host/src/ble_hs_hci_evt.c @@ -103,6 +103,12 @@ static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_transmit_power_report; #if MYNEWT_VAL(BLE_CONN_SUBRATING) static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_subrate_change; #endif +#if MYNEWT_VAL(BLE_AOA_AOD) +static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_connless_iq_report; +static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_iq_report; +static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_cte_req_failed; +#endif + /* Statistics */ struct host_hci_stats { @@ -177,6 +183,11 @@ static ble_hs_hci_evt_le_fn * const ble_hs_hci_evt_le_dispatch[] = { #if MYNEWT_VAL(BLE_CONN_SUBRATING) [BLE_HCI_LE_SUBEV_SUBRATE_CHANGE] = ble_hs_hci_evt_le_subrate_change, #endif +#if MYNEWT_VAL(BLE_AOA_AOD) + [BLE_HCI_LE_SUBEV_CONNLESS_IQ_RPT] = ble_hs_hci_evt_le_connless_iq_report, + [BLE_HCI_LE_SUBEV_CONN_IQ_RPT] = ble_hs_hci_evt_le_conn_iq_report, + [BLE_HCI_LE_SUBEV_CTE_REQ_FAILED] = ble_hs_hci_evt_le_cte_req_failed, +#endif }; #define BLE_HS_HCI_EVT_LE_DISPATCH_SZ \ @@ -990,6 +1001,52 @@ ble_hs_hci_evt_le_subrate_change(uint8_t subevent, const void *data, } #endif +#if MYNEWT_VAL(BLE_AOA_AOD) +static int +ble_hs_hci_evt_le_connless_iq_report(uint8_t subevent, const void *data, + unsigned int len) +{ + const struct ble_hci_ev_le_subev_connless_iq_rpt *ev = data; + + if (len < sizeof(*ev)) { + return BLE_HS_ECONTROLLER; + } + + ble_gap_rx_connless_iq_report(ev); + + return 0; +} + +static int +ble_hs_hci_evt_le_conn_iq_report(uint8_t subevent, const void *data, + unsigned int len) +{ + const struct ble_hci_ev_le_subev_conn_iq_rpt *ev = data; + if (len < sizeof(*ev)) { + return BLE_HS_ECONTROLLER; + } + + ble_gap_rx_conn_iq_report(ev); + + return 0; +} + +static int +ble_hs_hci_evt_le_cte_req_failed(uint8_t subevent, const void *data, + unsigned int len) +{ + const struct ble_hci_ev_le_subev_cte_req_failed *ev = data; + + if (len != sizeof(*ev)) { + return BLE_HS_ECONTROLLER; + } + + ble_gap_rx_cte_req_failed(ev); + + return 0; +} +#endif + #if NIMBLE_BLE_CONNECT static int ble_hs_hci_evt_le_conn_upd_complete(uint8_t subevent, const void *data, diff --git a/nimble/host/src/ble_hs_startup.c b/nimble/host/src/ble_hs_startup.c index b84a90d2d..5d4b8fc48 100644 --- a/nimble/host/src/ble_hs_startup.c +++ b/nimble/host/src/ble_hs_startup.c @@ -281,6 +281,18 @@ ble_hs_startup_le_set_evmask_tx(void) } #endif +#if MYNEWT_VAL(BLE_AOA_AOD) + if (version >= BLE_HCI_VER_BCS_5_1) { + /** + * Enable the following LE events: + * 0x0000000000100000 LE Connectionless IQ Report event + * 0x0000000000200000 LE Connection IQ Report event + * 0x0000000000400000 LE CTE Request Failed event + */ + mask |= 0x0000000000700000; + } +#endif + cmd.event_mask = htole64(mask); rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,