components/bt: Add mode change event

This commit is contained in:
baohongde 2020-07-21 18:11:11 +08:00 committed by bot
parent 0584b3d1d3
commit 060a36352c
14 changed files with 114 additions and 0 deletions

View File

@ -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;
/**

View File

@ -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);
}
}
}

View File

@ -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 */

View File

@ -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, &param,
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:

View File

@ -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;

View File

@ -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 {

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;