From 2107460209742b5e99d2bb126678e58ac4823758 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 22 Mar 2024 10:54:14 +0530 Subject: [PATCH] Add support to handle Data Length change event --- nimble/host/include/host/ble_gap.h | 25 ++++++++++++++++++++++++- nimble/host/src/ble_gap.c | 19 +++++++++++++++++++ nimble/host/src/ble_gap_priv.h | 2 ++ nimble/host/src/ble_hs_hci_evt.c | 18 ++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index d9b0c96ff..ebab72b80 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -160,7 +160,7 @@ struct hci_conn_update; #define BLE_GAP_EVENT_REATTEMPT_COUNT 31 #define BLE_GAP_EVENT_AUTHORIZE 32 #define BLE_GAP_EVENT_TEST_UPDATE 33 - +#define BLE_GAP_EVENT_DATA_LEN_CHG 34 /* DTM events */ #define BLE_GAP_DTM_TX_START_EVT 0 @@ -1246,6 +1246,29 @@ struct ble_gap_event { */ uint16_t num_pkt; } dtm_state; + + /** + * Represent an event for LE Data length change + * + * Valid for the following event types: + * o BLE_GAP_EVENT_DATA_LEN_CHG + */ + struct { + /* Connection handle */ + uint16_t conn_handle; + + /* Max Tx Payload octotes */ + uint16_t max_tx_octets; + + /* Max Tx Time */ + uint16_t max_tx_time; + + /* Max Rx payload octet */ + uint16_t max_rx_octets; + + /* Max Rx Time */ + uint16_t max_rx_time; + } data_len_chg; }; }; diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index a7e7b5f18..06006c16c 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -2289,6 +2289,25 @@ ble_gap_rx_phy_update_complete(const struct ble_hci_ev_le_subev_phy_update_compl #endif } +void +ble_gap_rx_data_len_change(const struct ble_hci_ev_le_subev_data_len_chg *ev) +{ +#if NIMBLE_BLE_CONNECT + struct ble_gap_event event; + uint16_t conn_handle = le16toh(ev->conn_handle); + + memset(&event, 0, sizeof event); + event.type = BLE_GAP_EVENT_DATA_LEN_CHG; + event.data_len_chg.max_tx_octets = le16toh(ev->max_tx_octets); + event.data_len_chg.max_rx_octets = le16toh(ev->max_rx_octets); + event.data_len_chg.max_tx_time = le16toh(ev->max_tx_time); + event.data_len_chg.max_rx_time = le16toh(ev->max_rx_time); + + ble_gap_event_listener_call(&event); + ble_gap_call_conn_event_cb(&event, conn_handle); +#endif +} + static int32_t ble_gap_master_timer(void) { diff --git a/nimble/host/src/ble_gap_priv.h b/nimble/host/src/ble_gap_priv.h index d15f633ef..5e05b8c67 100644 --- a/nimble/host/src/ble_gap_priv.h +++ b/nimble/host/src/ble_gap_priv.h @@ -164,6 +164,8 @@ int ble_gap_dbg_update_active(uint16_t conn_handle); void ble_gap_reattempt_count(uint16_t conn_handle, uint8_t count); #endif +void ble_gap_rx_data_len_change(const struct ble_hci_ev_le_subev_data_len_chg *ev); + #ifdef __cplusplus } #endif diff --git a/nimble/host/src/ble_hs_hci_evt.c b/nimble/host/src/ble_hs_hci_evt.c index dccfd003e..2e8115847 100644 --- a/nimble/host/src/ble_hs_hci_evt.c +++ b/nimble/host/src/ble_hs_hci_evt.c @@ -78,6 +78,7 @@ static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_complete; static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_upd_complete; static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_lt_key_req; static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_parm_req; +static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_data_len_change; static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_phy_update_complete; static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_enh_conn_complete; #endif @@ -149,6 +150,7 @@ static ble_hs_hci_evt_le_fn * const ble_hs_hci_evt_le_dispatch[] = { [BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE] = ble_hs_hci_evt_le_conn_upd_complete, [BLE_HCI_LE_SUBEV_LT_KEY_REQ] = ble_hs_hci_evt_le_lt_key_req, [BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ] = ble_hs_hci_evt_le_conn_parm_req, + [BLE_HCI_LE_SUBEV_DATA_LEN_CHG] = ble_hs_hci_evt_le_data_len_change, [BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE] = ble_hs_hci_evt_le_enh_conn_complete, #endif [BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT] = ble_hs_hci_evt_le_dir_adv_rpt, @@ -1040,6 +1042,22 @@ ble_hs_hci_evt_le_phy_update_complete(uint8_t subevent, const void *data, return 0; } + +static int +ble_hs_hci_evt_le_data_len_change(uint8_t subevent, const void *data, + unsigned int len) +{ + const struct ble_hci_ev_le_subev_data_len_chg *ev = data; + + if (len != sizeof(*ev)) { + return BLE_HS_ECONTROLLER; + } + + ble_gap_rx_data_len_change(ev); + + return 0; + +} #endif int