From 1b19449dc08614bb671cf2e69d384c90374f750e Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Thu, 19 Sep 2024 14:36:31 +0800 Subject: [PATCH] feat(bt/bluedroid): Report sniff interval to application layer --- .../bt/host/bluedroid/api/include/api/esp_gap_bt_api.h | 5 +++-- components/bt/host/bluedroid/bta/dm/bta_dm_pm.c | 9 +++++---- components/bt/host/bluedroid/bta/include/bta/bta_api.h | 1 + components/bt/host/bluedroid/btc/core/btc_dm.c | 1 + .../bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c | 3 ++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h index 98454a88ea..2ca2bca5af 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h @@ -406,8 +406,9 @@ typedef union { * @brief ESP_BT_GAP_MODE_CHG_EVT */ struct mode_chg_param { - esp_bd_addr_t bda; /*!< remote bluetooth device address*/ - esp_bt_pm_mode_t mode; /*!< PM mode*/ + esp_bd_addr_t bda; /*!< remote bluetooth device address */ + esp_bt_pm_mode_t mode; /*!< PM mode */ + uint16_t interval; /*!< Number of baseband slots. unit is 0.625ms */ } mode_chg; /*!< mode change event parameter struct */ /** diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_pm.c b/components/bt/host/bluedroid/bta/dm/bta_dm_pm.c index 149b4fac65..8167ddf9a6 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_pm.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_pm.c @@ -75,7 +75,7 @@ void bta_dm_init_pm(void) { memset(&bta_dm_conn_srvcs, 0x00, sizeof(bta_dm_conn_srvcs)); - /* if there are no power manger entries, so not register */ + /* if there are no power manager entries, so not register */ if (p_bta_dm_pm_cfg[0].app_id != 0) { bta_sys_pm_register((tBTA_SYS_CONN_CBACK *)bta_dm_pm_cback); @@ -694,9 +694,9 @@ static BOOLEAN bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE *p_peer_dev, UINT8 index) #endif { #if (BTM_SSR_INCLUDED == TRUE) - /* Dont initiate Sniff if controller has alreay accepted + /* Dont initiate Sniff if controller has already accepted * remote sniff params. This avoid sniff loop issue with - * some agrresive headsets who use sniff latencies more than + * some aggressive headsets who use sniff latencies more than * DUT supported range of Sniff intervals.*/ if ((mode == BTM_PM_MD_SNIFF) && (p_peer_dev->info & BTA_DM_DI_ACP_SNIFF)) { APPL_TRACE_DEBUG("%s: already in remote initiate sniff", __func__); @@ -917,7 +917,7 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data) } else { #if (BTM_SSR_INCLUDED == TRUE) if (p_dev->prev_low) { - /* need to send the SSR paramaters to controller again */ + /* need to send the SSR parameters to controller again */ bta_dm_pm_ssr(p_dev->peer_bdaddr); } p_dev->prev_low = BTM_PM_STS_ACTIVE; @@ -980,6 +980,7 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data) ) { tBTA_DM_SEC conn; conn.mode_chg.mode = p_data->pm_status.status; + conn.mode_chg.interval = p_data->pm_status.value; bdcpy(conn.mode_chg.bd_addr, p_data->pm_status.bd_addr); bta_dm_cb.p_sec_cback(BTA_DM_PM_MODE_CHG_EVT, (tBTA_DM_SEC *)&conn); } diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index 9b3c88fec1..cfa231a3e2 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -993,6 +993,7 @@ typedef struct { typedef struct { BD_ADDR bd_addr; /* BD address peer device. */ tBTA_PM_MODE mode; /* the new connection role */ + UINT16 interval; /* Number of baseband slots */ } tBTA_DM_MODE_CHG; typedef struct { diff --git a/components/bt/host/bluedroid/btc/core/btc_dm.c b/components/bt/host/bluedroid/btc/core/btc_dm.c index 8c55d7bbe3..074a568fa0 100644 --- a/components/bt/host/bluedroid/btc/core/btc_dm.c +++ b/components/bt/host/bluedroid/btc/core/btc_dm.c @@ -602,6 +602,7 @@ static void btc_dm_pm_mode_chg_evt(tBTA_DM_MODE_CHG *p_mode_chg) msg->act = BTC_GAP_BT_MODE_CHG_EVT; memcpy(param.mode_chg.bda, p_mode_chg->bd_addr, ESP_BD_ADDR_LEN); param.mode_chg.mode = p_mode_chg->mode; + param.mode_chg.interval= p_mode_chg->interval; memcpy(msg->arg, ¶m, sizeof(esp_bt_gap_cb_param_t)); ret = btc_inter_profile_call(msg); diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c index d535507918..49669aaba4 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c @@ -91,7 +91,8 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa /* when GAP mode changed, this event comes */ case ESP_BT_GAP_MODE_CHG_EVT: - ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode: %d", param->mode_chg.mode); + ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode: %d, interval: %.2f ms", + param->mode_chg.mode, param->mode_chg.interval * 0.625); break; /* when ACL connection completed, this event comes */ case ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT: