From: zhiweijian Date: Thu, 14 Mar 2019 06:03:36 +0000 (+0800) Subject: Component/bt: add new param for update_whitelist() X-Git-Tag: v4.0-beta1~462^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c0bdea6aaee41d6a08897d21852fe03f2b19f6ad;p=esp-idf Component/bt: add new param for update_whitelist() --- diff --git a/components/bt/bluedroid/api/esp_gap_ble_api.c b/components/bt/bluedroid/api/esp_gap_ble_api.c index c48fe757d8..cada44f8ba 100644 --- a/components/bt/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/bluedroid/api/esp_gap_ble_api.c @@ -287,7 +287,7 @@ esp_err_t esp_ble_gap_config_local_icon (uint16_t icon) 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; @@ -302,6 +302,7 @@ esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda 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) diff --git a/components/bt/bluedroid/api/include/api/esp_bt_defs.h b/components/bt/bluedroid/api/include/api/esp_bt_defs.h index da93b87bca..7e1063c71c 100644 --- a/components/bt/bluedroid/api/include/api/esp_bt_defs.h +++ b/components/bt/bluedroid/api/include/api/esp_bt_defs.h @@ -112,6 +112,12 @@ typedef enum { 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 diff --git a/components/bt/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/bluedroid/api/include/api/esp_gap_ble_api.h index b34c2ae11d..a2f03237c2 100644 --- a/components/bt/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/bluedroid/api/include/api/esp_gap_ble_api.h @@ -932,12 +932,13 @@ esp_err_t esp_ble_gap_config_local_icon (uint16_t icon); * * @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 diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index f1061a390f..390a7ad6f3 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -595,7 +595,7 @@ void bta_dm_set_dev_name (tBTA_DM_MSG *p_data) 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) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index c5d5440fc5..078903d31a 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -183,12 +183,13 @@ void BTA_DmSetDeviceName(const char *p_name) } -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)); diff --git a/components/bt/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/bluedroid/bta/dm/include/bta_dm_int.h index 6e962d5d5a..9ff577481c 100644 --- a/components/bt/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/include/bta_dm_int.h @@ -192,6 +192,7 @@ typedef struct { 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; diff --git a/components/bt/bluedroid/bta/include/bta/bta_api.h b/components/bt/bluedroid/bta/include/bta/bta_api.h index f384edeb45..c7bad21fed 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta/bta_api.h @@ -1450,7 +1450,7 @@ extern void BTA_DisableTestMode(void); *******************************************************************************/ 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); diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index ef13106dde..ffac0c35f6 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1117,7 +1117,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) 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); diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h index a6cfbba3e7..be818269b2 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -95,13 +95,14 @@ typedef union { 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; @@ -109,7 +110,7 @@ typedef union { 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) diff --git a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c index a39eb5afac..0766715480 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c @@ -154,8 +154,9 @@ void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) ** ** 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; @@ -184,7 +185,7 @@ BOOLEAN btm_add_dev_to_controller (BOOLEAN to_add, BD_ADDR bd_addr) } 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); @@ -196,6 +197,23 @@ BOOLEAN btm_add_dev_to_controller (BOOLEAN to_add, BD_ADDR bd_addr) } 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; + } /******************************************************************************* @@ -212,7 +230,7 @@ BOOLEAN btm_execute_wl_dev_operation(void) 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; @@ -226,13 +244,13 @@ BOOLEAN btm_execute_wl_dev_operation(void) ** ** 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) { @@ -242,6 +260,7 @@ void btm_enq_wl_dev_operation(BOOLEAN to_add, BD_ADDR bd_addr) 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"); @@ -257,8 +276,40 @@ void btm_enq_wl_dev_operation(BOOLEAN to_add, BD_ADDR bd_addr) ** 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) { @@ -296,7 +347,7 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBTM_ADD_W /* 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; diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index 14c96b15dc..fd231489ea 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -300,9 +300,9 @@ void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn ** 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); } /******************************************************************************* @@ -1083,7 +1083,7 @@ void BTM_BleClearBgConnDev(void) 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); } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/btm/include/btm_ble_int.h b/components/bt/bluedroid/stack/btm/include/btm_ble_int.h index 848bff3740..94a5069e5c 100644 --- a/components/bt/bluedroid/stack/btm/include/btm_ble_int.h +++ b/components/bt/bluedroid/stack/btm/include/btm_ble_int.h @@ -293,6 +293,7 @@ typedef struct { BOOLEAN in_use; BOOLEAN to_add; BD_ADDR bd_addr; + tBLE_ADDR_TYPE addr_type; UINT8 attr; } tBTM_BLE_WL_OP; @@ -427,7 +428,7 @@ void btm_ble_update_sec_key_size(BD_ADDR bd_addr, UINT8 enc_key_size); 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); diff --git a/components/bt/bluedroid/stack/gatt/gatt_utils.c b/components/bt/bluedroid/stack/gatt/gatt_utils.c index 6d724e6d43..2455f746f3 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_utils.c +++ b/components/bt/bluedroid/stack/gatt/gatt_utils.c @@ -2447,7 +2447,8 @@ BOOLEAN gatt_add_bg_dev_list(tGATT_REG *p_reg, BD_ADDR bd_addr, BOOLEAN is_init 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; } @@ -2587,7 +2588,8 @@ BOOLEAN gatt_remove_bg_dev_from_list(tGATT_REG *p_reg, BD_ADDR bd_addr, BOOLEAN } 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; } @@ -2648,7 +2650,8 @@ void gatt_deregister_bgdev_list(tGATT_IF gatt_if) } 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); } } } diff --git a/components/bt/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/bluedroid/stack/include/stack/btm_ble_api.h index 7e6feb39bd..cdbb2db617 100644 --- a/components/bt/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/bluedroid/stack/include/stack/btm_ble_api.h @@ -1802,7 +1802,7 @@ void BTM_BleTurnOnPrivacyOnRemote(BD_ADDR bd_addr, ** *******************************************************************************/ //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); /******************************************************************************* **