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 9504f675e6..4ecc64a3f7 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 @@ -155,6 +155,16 @@ typedef enum { #define ESP_BT_IO_CAP_NONE 3 /*!< NoInputNoOutput */ /* relate to BTM_IO_CAP_NONE in stack/btm_api.h */ typedef uint8_t esp_bt_io_cap_t; /*!< combination of the io capability */ + +/* BTM Power manager modes */ +#define ESP_BT_PM_MD_ACTIVE 0x00 /*!< Active mode */ +#define ESP_BT_PM_MD_HOLD 0x01 /*!< Hold mode */ +#define ESP_BT_PM_MD_SNIFF 0x02 /*!< Sniff mode */ +#define ESP_BT_PM_MD_PARK 0x03 /*!< Park state */ +typedef uint8_t esp_bt_pm_mode_t; + + + /// Bits of major service class field #define ESP_BT_COD_SRVC_BIT_MASK (0xffe000) /*!< Major service bit mask */ #define ESP_BT_COD_SRVC_BIT_OFFSET (13) /*!< Major service bit offset */ @@ -210,6 +220,7 @@ typedef enum { ESP_BT_GAP_CONFIG_EIR_DATA_EVT, /*!< config EIR data event */ ESP_BT_GAP_SET_AFH_CHANNELS_EVT, /*!< set AFH channels event */ ESP_BT_GAP_READ_REMOTE_NAME_EVT, /*!< read Remote Name event */ + ESP_BT_GAP_MODE_CHG_EVT, ESP_BT_GAP_EVT_MAX, } esp_bt_gap_cb_event_t; @@ -336,6 +347,14 @@ typedef union { uint8_t rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; /*!< Remote device name */ } read_rmt_name; /*!< read Remote Name parameter struct */ + /** + * @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*/ + } mode_chg; /*!< mode change event parameter struct */ + } esp_bt_gap_cb_param_t; /** 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 ff42a65a17..5b4775704e 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_pm.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_pm.c @@ -973,6 +973,17 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data) default: break; } + + if ( bta_dm_cb.p_sec_cback ) { + if (p_data->pm_status.status <= BTM_PM_STS_PARK + /*&& p_data->pm_status.status >= BTM_PM_STS_ACTIVE*/ // comparison is always true due to limited range of data type + ) { + tBTA_DM_SEC conn; + conn.mode_chg.mode = p_data->pm_status.status; + 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 dc9b3c4a02..c5daf6cc8b 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -655,6 +655,7 @@ typedef UINT8 tBTA_SIG_STRENGTH_MASK; #define BTA_DM_ENER_INFO_READ 28 /* Energy info read */ #define BTA_DM_BLE_DEV_UNPAIRED_EVT 29 /* BLE unpair event */ #define BTA_DM_SP_KEY_REQ_EVT 30 /* Simple Pairing Passkey request */ +#define BTA_DM_PM_MODE_CHG_EVT 31 /* Mode changed event */ typedef UINT8 tBTA_DM_SEC_EVT; @@ -877,6 +878,12 @@ typedef tBTM_LE_AUTH_REQ tBTA_LE_AUTH_REQ; /* combination of the abo #endif typedef tBTM_OOB_DATA tBTA_OOB_DATA; +#define BTA_PM_MD_ACTIVE BTM_PM_MD_ACTIVE /* 0 Active mode */ +#define BTA_PM_MD_HOLD BTM_PM_MD_HOLD /* 1 Hold mode */ +#define BTA_PM_MD_SNIFF BTM_PM_MD_SNIFF /* 2 Sniff mode */ +#define BTA_PM_MD_PARK BTM_PM_MD_PARK /* 3 Park state */ +typedef tBTM_PM_MODE tBTA_PM_MODE; + /* Structure associated with BTA_DM_SP_CFM_REQ_EVT */ typedef struct { /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */ @@ -935,6 +942,13 @@ typedef struct { tBTA_STATUS result; /* TRUE of bond cancel succeeded, FALSE if failed. */ } tBTA_DM_BOND_CANCEL_CMPL; +/* Structure associated with BTA_DM_PM_MODE_CHG_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + tBTA_PM_MODE mode; /* the new connection role */ +} tBTA_DM_MODE_CHG; + + /* Union of all security callback structures */ typedef union { tBTA_DM_ENABLE enable; /* BTA enabled */ @@ -955,6 +969,9 @@ typedef union { tBTA_DM_BLE_KEY ble_key; /* BLE SMP keys used when pairing */ tBTA_BLE_LOCAL_ID_KEYS ble_id_keys; /* IR event */ BT_OCTET16 ble_er; /* ER event data */ +#if BTA_DM_PM_INCLUDED + tBTA_DM_MODE_CHG mode_chg; /* mode change event */ +#endif ///BTA_DM_PM_INCLUDED } tBTA_DM_SEC; /* Security callback */ diff --git a/components/bt/host/bluedroid/btc/core/btc_dm.c b/components/bt/host/bluedroid/btc/core/btc_dm.c index b4e70d53a9..266869fa20 100644 --- a/components/bt/host/bluedroid/btc/core/btc_dm.c +++ b/components/bt/host/bluedroid/btc/core/btc_dm.c @@ -510,6 +510,27 @@ static void btc_dm_sp_key_req_evt(tBTA_DM_SP_KEY_REQ *p_key_req) } #endif /// BT_SSP_INCLUDED == TRUE +#if (BTC_DM_PM_INCLUDED == TRUE) +static void btc_dm_pm_mode_chg_evt(tBTA_DM_MODE_CHG *p_mode_chg) +{ + esp_bt_gap_cb_param_t param; + bt_status_t ret; + btc_msg_t msg; + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_GAP_BT; + 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; + + ret = btc_transfer_context(&msg, ¶m, + sizeof(esp_bt_gap_cb_param_t), NULL); + + if (ret != BT_STATUS_SUCCESS) { + BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); + } +} +#endif /// BTC_DM_PM_INCLUDED == TRUE + tBTA_SERVICE_MASK btc_get_enabled_services_mask(void) { return btc_dm_cb.btc_enabled_services; @@ -857,6 +878,13 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) } #endif +#if (BTC_DM_PM_INCLUDED == TRUE) + case BTA_DM_PM_MODE_CHG_EVT: + BTC_TRACE_DEBUG("BTA_DM_PM_MODE_CHG_EVT mode:%d", p_data->mode_chg.mode); + btc_dm_pm_mode_chg_evt(&p_data->mode_chg); + break; +#endif /// BTA_DM_PM_INCLUDED == TRUE + case BTA_DM_AUTHORIZE_EVT: case BTA_DM_SIG_STRENGTH_EVT: case BTA_DM_ROLE_CHG_EVT: diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c index 9ece2ada6e..7b711102f9 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c @@ -980,6 +980,9 @@ void btc_gap_bt_cb_deep_free(btc_msg_t *msg) case BTC_GAP_BT_KEY_NOTIF_EVT: case BTC_GAP_BT_KEY_REQ_EVT: #endif ///BT_SSP_INCLUDED == TRUE +#if (BTC_DM_PM_INCLUDED == TRUE) + case BTC_GAP_BT_MODE_CHG_EVT: +#endif /// BTC_DM_PM_INCLUDED == TRUE break; default: BTC_TRACE_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act); @@ -1042,6 +1045,12 @@ void btc_gap_bt_cb_handler(btc_msg_t *msg) break; } #endif + +#if (BTC_DM_PM_INCLUDED == TRUE) + case BTC_GAP_BT_MODE_CHG_EVT: + btc_gap_bt_cb_to_app(ESP_BT_GAP_MODE_CHG_EVT,(esp_bt_gap_cb_param_t *)msg->arg); + break; +#endif /// BTC_DM_PM_INCLUDED == TRUE default: BTC_TRACE_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act); break; diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h index 3c6cceeed3..ec36a1cd8c 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h @@ -36,6 +36,7 @@ typedef enum { BTC_GAP_BT_CONFIG_EIR_DATA_EVT, BTC_GAP_BT_SET_AFH_CHANNELS_EVT, BTC_GAP_BT_READ_REMOTE_NAME_EVT, + BTC_GAP_BT_MODE_CHG_EVT, }btc_gap_bt_evt_t; typedef enum { diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index abf2c73db0..d01aa27ee5 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -57,6 +57,7 @@ #define BTC_GAP_BT_INCLUDED TRUE #define BTA_SDP_INCLUDED TRUE #define BTA_DM_PM_INCLUDED TRUE +#define BTC_DM_PM_INCLUDED TRUE #define SDP_INCLUDED TRUE #if (UC_BT_A2DP_ENABLED == TRUE) 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 ae09f4674b..c6b37034d9 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c @@ -161,6 +161,10 @@ void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) break; #endif + case ESP_BT_GAP_MODE_CHG_EVT: + ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode:%d", param->mode_chg.mode); + break; + default: { ESP_LOGI(BT_AV_TAG, "event: %d", event); break; diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c index 25f66c90fc..d4e2aaa840 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c @@ -313,6 +313,10 @@ void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) break; #endif + case ESP_BT_GAP_MODE_CHG_EVT: + ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode:%d", param->mode_chg.mode); + break; + default: { ESP_LOGI(BT_AV_TAG, "event: %d", event); break; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/example_spp_acceptor_demo.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/example_spp_acceptor_demo.c index f8710342be..4abe7d5154 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/example_spp_acceptor_demo.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/example_spp_acceptor_demo.c @@ -152,6 +152,10 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) break; #endif + case ESP_BT_GAP_MODE_CHG_EVT: + ESP_LOGI(SPP_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode:%d", param->mode_chg.mode); + break; + default: { ESP_LOGI(SPP_TAG, "event: %d", event); break; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/example_spp_initiator_demo.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/example_spp_initiator_demo.c index e3dbf36bb0..44c06541dd 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/example_spp_initiator_demo.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/example_spp_initiator_demo.c @@ -233,6 +233,10 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; #endif + case ESP_BT_GAP_MODE_CHG_EVT: + ESP_LOGI(SPP_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode:%d", param->mode_chg.mode); + break; + default: break; } diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c index 8b9e947b41..265d304f29 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c @@ -154,6 +154,10 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) break; #endif + case ESP_BT_GAP_MODE_CHG_EVT: + ESP_LOGI(SPP_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode:%d", param->mode_chg.mode); + break; + default: { ESP_LOGI(SPP_TAG, "event: %d", event); break; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c index f7ecf1a472..562ffdd237 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c @@ -216,6 +216,10 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; #endif + case ESP_BT_GAP_MODE_CHG_EVT: + ESP_LOGI(SPP_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode:%d", param->mode_chg.mode); + break; + default: break; } diff --git a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c index e1cb81b987..82b3390f95 100644 --- a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c +++ b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c @@ -624,6 +624,10 @@ void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) ESP_LOGI(BT_BLE_COEX_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); break; #endif + case ESP_BT_GAP_MODE_CHG_EVT: + ESP_LOGI(BT_BLE_COEX_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode:%d", param->mode_chg.mode); + break; + default: { ESP_LOGI(BT_BLE_COEX_TAG, "event: %d", event); break;