if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
-
+ if (!remote_bda){
+ return ESP_ERR_INVALID_SIZE;
+ }
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST;
ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT, /*!< When clear the bond device clear complete, the event comes */
ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT, /*!< When get the bond device list complete, the event comes */
ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT, /*!< When read the rssi complete, the event comes */
+ ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT, /*!< When add or remove whitelist complete, the event comes */
ESP_GAP_BLE_EVT_MAX,
} esp_gap_ble_cb_event_t;
ESP_BLE_EVT_SCAN_RSP = 0x04, /*!< Scan Response (SCAN_RSP) */
} esp_ble_evt_type_t;
+typedef enum{
+ ESP_BLE_WHITELIST_REMOVE = 0X00, /*!< remove mac from whitelist */
+ ESP_BLE_WHITELIST_ADD = 0X01, /*!< add address to whitelist */
+}esp_ble_wl_opration;
/**
* @brief Gap callback parameters union
*/
if the RSSI cannot be read, the RSSI metric shall be set to 127. */
esp_bd_addr_t remote_addr; /*!< The remote device address */
} read_rssi_cmpl; /*!< Event parameter of ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT */
+ /**
+ * @brief ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT
+ */
+ struct ble_add_whitelist_cmpl_evt_param {
+ esp_bt_status_t status; /*!< Indicate the add or remove whitelist operation success status */
+ esp_ble_wl_opration wl_opration; /*!< The value is ESP_BLE_WHITELIST_ADD if add address to whitelist operation success, ESP_BLE_WHITELIST_REMOVE if remove address from the whitelist operation success */
+ } add_whitelist_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT */
} esp_ble_gap_cb_param_t;
/**
void bta_dm_update_white_list(tBTA_DM_MSG *p_data)
{
- BTM_BleUpdateAdvWhitelist(p_data->white_list.add_remove, p_data->white_list.remote_addr);
+ BTM_BleUpdateAdvWhitelist(p_data->white_list.add_remove, p_data->white_list.remote_addr, p_data->white_list.add_wl_cb);
}
void bta_dm_ble_read_adv_tx_power(tBTA_DM_MSG *p_data)
}
-void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr)
+void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBTA_ADD_WHITELIST_CBACK *add_wl_cb)
{
tBTA_DM_API_UPDATE_WHITE_LIST *p_msg;
if ((p_msg = (tBTA_DM_API_UPDATE_WHITE_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_WHITE_LIST))) != NULL) {
p_msg->hdr.event = BTA_DM_API_UPDATE_WHITE_LIST_EVT;
p_msg->add_remove = add_remove;
+ p_msg->add_wl_cb = add_wl_cb;
memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR));
bta_sys_sendmsg(p_msg);
BT_HDR hdr;
BOOLEAN add_remove;
BD_ADDR remote_addr;
+ tBTA_ADD_WHITELIST_CBACK *add_wl_cb;
}tBTA_DM_API_UPDATE_WHITE_LIST;
typedef struct {
typedef void (tBTA_START_ADV_CMPL_CBACK) (tBTA_STATUS status);
+typedef tBTM_ADD_WHITELIST_CBACK tBTA_ADD_WHITELIST_CBACK;
+
typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK;
typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK;
*******************************************************************************/
extern void BTA_DmSetDeviceName(char *p_name);
-extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr);
+extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBTA_ADD_WHITELIST_CBACK *add_wl_cb);
extern void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb);
}
}
+static void btc_add_whitelist_complete_callback(UINT8 status, tBTM_WL_OPERATION wl_opration)
+{
+ esp_ble_gap_cb_param_t param;
+ bt_status_t ret;
+ btc_msg_t msg;
+ msg.sig = BTC_SIG_API_CB;
+ msg.pid = BTC_PID_GAP_BLE;
+ msg.act = ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT;
+ param.add_whitelist_cmpl.status = btc_hci_to_esp_status(status);
+ param.add_whitelist_cmpl.wl_opration = wl_opration;
+ ret = btc_transfer_context(&msg, ¶m,
+ sizeof(esp_ble_gap_cb_param_t), NULL);
+
+ if (ret != BT_STATUS_SUCCESS) {
+ LOG_ERROR("%s btc_transfer_context failed\n", __func__);
+ }
+}
+
static void btc_set_local_privacy_callback(UINT8 status)
{
esp_ble_gap_cb_param_t param;
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable, btc_set_local_privacy_callback);
break;
case BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST:
- BTA_DmUpdateWhiteList(arg->update_white_list.add_remove, arg->update_white_list.remote_bda);
+ BTA_DmUpdateWhiteList(arg->update_white_list.add_remove, arg->update_white_list.remote_bda, btc_add_whitelist_complete_callback);
break;
case BTC_GAP_BLE_ACT_READ_RSSI:
BTA_DmBleReadRSSI(arg->read_rssi.remote_addr, btc_read_ble_rssi_cmpl_callback);
#if (BLE_INCLUDED == TRUE)
static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state);
-static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state);
+static void btm_wl_update_to_controller(void);
// Unfortunately (for now?) we have to maintain a copy of the device whitelist
// on the host to determine if a device is pending to be connected or not. This
else {
BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type);
- started = btsnd_hcic_ble_remove_from_white_list (addr_type, bd_addr);
if (to_add) {
started = btsnd_hcic_ble_add_white_list (addr_type, bd_addr);
+ }else{
+ started = btsnd_hcic_ble_remove_from_white_list (addr_type, bd_addr);
}
}
** the white list.
**
*******************************************************************************/
-BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr)
+BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBTM_ADD_WHITELIST_CBACK *add_wl_cb)
{
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
BTM_TRACE_DEBUG("%s Whitelist full, unable to add device", __func__);
return FALSE;
}
+ if (add_wl_cb){
+ //save add whitelist complete callback
+ p_cb->add_wl_cb = add_wl_cb;
+ }
if (to_add) {
/* added the bd_addr to the connection hash map queue */
btm_suspend_wl_activity(p_cb->wl_state);
/* save the bd_addr to the btm_cb env */
btm_enq_wl_dev_operation(to_add, bd_addr);
- /* save the ba_addr to the controller white list & start the auto connet */
- btm_resume_wl_activity(p_cb->wl_state);
+ /* save the ba_addr to the controller white list */
+ btm_wl_update_to_controller();
return TRUE;
}
void btm_ble_add_2_white_list_complete(UINT8 status)
{
BTM_TRACE_EVENT("%s status=%d", __func__, status);
+ tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
if (status == HCI_SUCCESS) {
--btm_cb.ble_ctr_cb.white_list_avail_size;
}
+ // add whitelist complete callback
+ if (p_cb->add_wl_cb)
+ {
+ (*p_cb->add_wl_cb)(status, BTM_WHITELIST_ADD);
+ }
+
}
/*******************************************************************************
*******************************************************************************/
void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len)
{
+ tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
UNUSED(evt_len);
BTM_TRACE_EVENT ("%s status=%d", __func__, *p);
if (*p == HCI_SUCCESS) {
++btm_cb.ble_ctr_cb.white_list_avail_size;
}
+ if (p_cb->add_wl_cb)
+ {
+ (*p_cb->add_wl_cb)(*p, BTM_WHITELIST_REMOVE);
+ }
}
/*******************************************************************************
** Returns none.
**
*******************************************************************************/
-static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state)
+void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state)
{
btm_ble_resume_bg_conn();
-
if (wl_state & BTM_BLE_WL_ADV) {
btm_ble_start_adv();
}
+}
+
+/*******************************************************************************
+**
+** Function btm_wl_update_to_controller
+**
+** Description This function is to update white list to controller
+**
+** Returns none.
+**
+*******************************************************************************/
+static void btm_wl_update_to_controller(void)
+{
+ /* whitelist will be added in the btm_ble_resume_bg_conn(), we do not
+ support background connection now, so we nedd to use btm_execute_wl_dev_operation
+ to add whitelist directly ,if we support background connection in the future,
+ please delete btm_execute_wl_dev_operation(). */
+ btm_execute_wl_dev_operation();
+
}
/*******************************************************************************
**
** Returns void
**
*******************************************************************************/
-BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda)
+BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda, tBTM_ADD_WHITELIST_CBACK *add_wl_cb)
{
- return btm_update_dev_to_white_list(add_remove, remote_bda);
+ return btm_update_dev_to_white_list(add_remove, remote_bda, add_wl_cb);
}
/*******************************************************************************
BOOLEAN BTM_BleUpdateBgConnDev(BOOLEAN add_remove, BD_ADDR remote_bda)
{
BTM_TRACE_EVENT("%s() add=%d", __func__, add_remove);
- return btm_update_dev_to_white_list(add_remove, remote_bda);
+ return btm_update_dev_to_white_list(add_remove, remote_bda, NULL);
}
/*******************************************************************************
p_dev->listen_gif[i] = gatt_if;
if (i == 0) {
- ret = BTM_BleUpdateAdvWhitelist(TRUE, bd_addr);
+ ret = BTM_BleUpdateAdvWhitelist(TRUE, bd_addr, NULL);
} else {
ret = TRUE;
}
}
if (p_dev->listen_gif[0] == 0) {
- ret = BTM_BleUpdateAdvWhitelist(FALSE, p_dev->remote_bda);
+ ret = BTM_BleUpdateAdvWhitelist(FALSE, p_dev->remote_bda, NULL);
} else {
ret = TRUE;
}
}
if (p_dev_list->listen_gif[0] == 0) {
- BTM_BleUpdateAdvWhitelist(FALSE, p_dev_list->remote_bda);
+ BTM_BleUpdateAdvWhitelist(FALSE, p_dev_list->remote_bda, NULL);
}
}
}
UINT16 supervision_tout;
}tBTM_LE_UPDATE_CONN_PRAMS;
+typedef enum{
+ BTM_WHITELIST_REMOVE = 0X00,
+ BTM_WHITELIST_ADD = 0X01,
+}tBTM_WL_OPERATION;
+
typedef void (tBTM_DEV_STATUS_CB) (tBTM_DEV_STATUS status);
typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params);
+typedef void (tBTM_ADD_WHITELIST_CBACK) (UINT8 status, tBTM_WL_OPERATION wl_opration);
+
typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status);
**
*******************************************************************************/
//extern
-BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda);
+BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda, tBTM_ADD_WHITELIST_CBACK *add_wl_cb);
/*******************************************************************************
**
/* white list information */
UINT8 white_list_avail_size;
+ tBTM_ADD_WHITELIST_CBACK *add_wl_cb;
tBTM_BLE_WL_STATE wl_state;
fixed_queue_t *conn_pending_q;
UINT8 btm_ble_read_sec_key_size(BD_ADDR bd_addr);
/* white list function */
-BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr);
+BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBTM_ADD_WHITELIST_CBACK *add_wl_cb);
void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy);
void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy);
void btm_ble_clear_white_list (void);