return ret;
}
-esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda)
+esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda, esp_ble_wl_addr_type_t wl_addr_type)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST;
arg.update_white_list.add_remove = add_remove;
+ arg.update_white_list.wl_addr_type = wl_addr_type;
memcpy(arg.update_white_list.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
BLE_ADDR_TYPE_RPA_RANDOM = 0x03,
} esp_ble_addr_type_t;
+/// white list address type
+typedef enum {
+ BLE_WL_ADDR_TYPE_PUBLIC = 0x00,
+ BLE_WL_ADDR_TYPE_RANDOM = 0x01,
+} esp_ble_wl_addr_type_t;
+
/// Used to exchange the encryption key in the init key & response key
#define ESP_BLE_ENC_KEY_MASK (1 << 0) /* relate to BTM_BLE_ENC_KEY_MASK in stack/btm_api.h */
/// Used to exchange the IRK key in the init key & response key
*
* @param[in] add_remove: the value is true if added the ble device to the white list, and false remove to the white list.
* @param[in] remote_bda: the remote device address add/remove from the white list.
+* @param[in] wl_addr_type: whitelist address type
* @return
* - ESP_OK : success
* - other : failed
*
*/
-esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda);
+esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda, esp_ble_wl_addr_type_t wl_addr_type);
/**
* @brief Get the whitelist size in the controller
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, p_data->white_list.add_wl_cb);
+ BTM_BleUpdateAdvWhitelist(p_data->white_list.add_remove, p_data->white_list.remote_addr, p_data->white_list.addr_type, 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, tBTA_ADD_WHITELIST_CBACK *add_wl_cb)
+void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, 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->addr_type = addr_type;
p_msg->add_wl_cb = add_wl_cb;
memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR));
BT_HDR hdr;
BOOLEAN add_remove;
BD_ADDR remote_addr;
+ tBLE_ADDR_TYPE addr_type;
tBTA_ADD_WHITELIST_CBACK *add_wl_cb;
}tBTA_DM_API_UPDATE_WHITE_LIST;
*******************************************************************************/
extern void BTA_DmSetDeviceName(const char *p_name);
-extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBTA_ADD_WHITELIST_CBACK *add_wl_cb);
+extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_ADD_WHITELIST_CBACK *add_wl_cb);
extern void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb);
btc_ble_config_local_icon(arg->cfg_local_icon.icon);
break;
case BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST:
- BTA_DmUpdateWhiteList(arg->update_white_list.add_remove, arg->update_white_list.remote_bda, btc_add_whitelist_complete_callback);
+ BTA_DmUpdateWhiteList(arg->update_white_list.add_remove, arg->update_white_list.remote_bda, arg->update_white_list.wl_addr_type, btc_add_whitelist_complete_callback);
break;
case BTC_GAP_BLE_ACT_READ_RSSI:
BTA_DmBleReadRSSI(arg->read_rssi.remote_addr, BTA_TRANSPORT_LE, btc_read_ble_rssi_cmpl_callback);
struct update_white_list_args {
bool add_remove;
esp_bd_addr_t remote_bda;
- }update_white_list;
+ esp_ble_wl_addr_type_t wl_addr_type;
+ } update_white_list;
//BTC_GAP_BLE_UPDATE_DUPLICATE_SCAN_EXCEPTIONAL_LIST
struct update_duplicate_exceptional_list_args {
uint8_t subcode;
uint32_t info_type;
esp_duplicate_info_t device_info;
- }update_duplicate_exceptional_list;
+ } update_duplicate_exceptional_list;
//BTC_GAP_BLE_ACT_SET_CONN_PARAMS
struct set_conn_params_args {
esp_bd_addr_t bd_addr;
uint16_t max_conn_int;
uint16_t slave_latency;
uint16_t supervision_tout;
- }set_conn_params;
+ } set_conn_params;
//BTC_GAP_BLE_ACT_SET_DEV_NAME,
struct set_dev_name_args {
#define ESP_GAP_DEVICE_NAME_MAX (32)
**
** Description This function load the device into controller white list
*******************************************************************************/
-BOOLEAN btm_add_dev_to_controller (BOOLEAN to_add, BD_ADDR bd_addr)
+BOOLEAN btm_add_dev_to_controller (BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE wl_addr_type)
{
+ /*
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
BOOLEAN started = FALSE;
}
p_dev_rec->ble.in_controller_list &= ~BTM_WHITE_LIST_BIT;
}
- } /* if not a known device, shall we add it? */
+ } // if not a known device, shall we add it?
else {
BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type);
}
return started;
+ */
+
+ /* Controller do not support resolvable address now, only support public address and static random address */
+ BOOLEAN started = FALSE;
+ if(wl_addr_type > BLE_ADDR_RANDOM) {
+ BTM_TRACE_ERROR("wl_addr_type is error\n");
+ return started;
+ }
+
+ if (to_add) {
+ started = btsnd_hcic_ble_add_white_list (wl_addr_type, bd_addr);
+ }else{
+ started = btsnd_hcic_ble_remove_from_white_list (wl_addr_type, bd_addr);
+ }
+
+ return started;
+
}
/*******************************************************************************
for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && rt; i ++, p_dev_op ++) {
if (p_dev_op->in_use) {
- rt = btm_add_dev_to_controller(p_dev_op->to_add, p_dev_op->bd_addr);
+ rt = btm_add_dev_to_controller(p_dev_op->to_add, p_dev_op->bd_addr, p_dev_op->addr_type);
memset(p_dev_op, 0, sizeof(tBTM_BLE_WL_OP));
} else {
break;
**
** Description enqueue the pending whitelist device operation(loading or removing).
*******************************************************************************/
-void btm_enq_wl_dev_operation(BOOLEAN to_add, BD_ADDR bd_addr)
+void btm_enq_wl_dev_operation(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type)
{
tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q;
UINT8 i = 0;
for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++, p_dev_op ++) {
- if (p_dev_op->in_use && !memcmp(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN)) {
+ if (p_dev_op->in_use && p_dev_op->addr_type == addr_type && !memcmp(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN)) {
p_dev_op->to_add = to_add;
return;
} else if (!p_dev_op->in_use) {
if (i != BTM_BLE_MAX_BG_CONN_DEV_NUM) {
p_dev_op->in_use = TRUE;
p_dev_op->to_add = to_add;
+ p_dev_op->addr_type = addr_type;
memcpy(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN);
} else {
BTM_TRACE_ERROR("max pending WL operation reached, discard");
** the white list.
**
*******************************************************************************/
-BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBTM_ADD_WHITELIST_CBACK *add_wl_cb)
+BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBTM_ADD_WHITELIST_CBACK *add_wl_cb)
{
+ if(addr_type > BLE_ADDR_RANDOM) {
+ BTM_TRACE_ERROR("%s address type is error, unable to add device", __func__);
+ if (add_wl_cb){
+ add_wl_cb(HCI_ERR_ILLEGAL_PARAMETER_FMT,to_add);
+ }
+ return FALSE;
+ }
+ if(addr_type == BLE_ADDR_RANDOM) {
+ /*
+ A static address is a 48-bit randomly generated address and shall meet the following requirements:
+ • The two most significant bits of the address shall be equal to 1
+ • All bits of the random part of the address shall not be equal to 1
+ • All bits of the random part of the address shall not be equal to 0
+ */
+ BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
+ memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
+ memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
+ invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK;
+ if((bd_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
+ && memcmp(invalid_rand_addr_a, bd_addr, BD_ADDR_LEN) != 0
+ && memcmp(invalid_rand_addr_b, bd_addr, BD_ADDR_LEN) != 0){
+ // do nothing
+ } else {
+ BTC_TRACE_ERROR(" controller not support resolvable address");
+ if (add_wl_cb){
+ add_wl_cb(HCI_ERR_ILLEGAL_PARAMETER_FMT,to_add);
+ }
+ return FALSE;
+ }
+
+ }
+
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
if (to_add && p_cb->white_list_avail_size == 0) {
/* stop the auto connect */
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);
+ btm_enq_wl_dev_operation(to_add, bd_addr, addr_type);
/* save the ba_addr to the controller white list */
btm_wl_update_to_controller();
return TRUE;
** Returns void
**
*******************************************************************************/
-BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda, tBTM_ADD_WHITELIST_CBACK *add_wl_cb)
+BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda, tBLE_ADDR_TYPE addr_type, tBTM_ADD_WHITELIST_CBACK *add_wl_cb)
{
- return btm_update_dev_to_white_list(add_remove, remote_bda, add_wl_cb);
+ return btm_update_dev_to_white_list(add_remove, remote_bda, addr_type, 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, NULL);
+ return btm_update_dev_to_white_list(add_remove, remote_bda, 0, NULL);
}
/*******************************************************************************
BOOLEAN in_use;
BOOLEAN to_add;
BD_ADDR bd_addr;
+ tBLE_ADDR_TYPE addr_type;
UINT8 attr;
} tBTM_BLE_WL_OP;
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, tBTM_ADD_WHITELIST_CBACK *add_wl_cb);
+BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, 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);
p_dev->listen_gif[i] = gatt_if;
if (i == 0) {
- ret = BTM_BleUpdateAdvWhitelist(TRUE, bd_addr, NULL);
+ // To check, we do not support background connection, code will not be called here
+ ret = BTM_BleUpdateAdvWhitelist(TRUE, bd_addr, 0, NULL);
} else {
ret = TRUE;
}
}
if (p_dev->listen_gif[0] == 0) {
- ret = BTM_BleUpdateAdvWhitelist(FALSE, p_dev->remote_bda, NULL);
+ // To check, we do not support background connection, code will not be called here
+ ret = BTM_BleUpdateAdvWhitelist(FALSE, p_dev->remote_bda, 0, NULL);
} else {
ret = TRUE;
}
}
if (p_dev_list->listen_gif[0] == 0) {
- BTM_BleUpdateAdvWhitelist(FALSE, p_dev_list->remote_bda, NULL);
+ // To check, we do not support background connection, code will not be called here
+ BTM_BleUpdateAdvWhitelist(FALSE, p_dev_list->remote_bda, 0, NULL);
}
}
}
**
*******************************************************************************/
//extern
-BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda, tBTM_ADD_WHITELIST_CBACK *add_wl_cb);
+BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda, tBLE_ADDR_TYPE addr_type, tBTM_ADD_WHITELIST_CBACK *add_wl_cb);
/*******************************************************************************
**