]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: add new param for update_whitelist()
authorzhiweijian <zhiweijian@espressif.com>
Thu, 14 Mar 2019 06:03:36 +0000 (14:03 +0800)
committerbot <bot@espressif.com>
Fri, 22 Mar 2019 12:22:51 +0000 (12:22 +0000)
14 files changed:
components/bt/bluedroid/api/esp_gap_ble_api.c
components/bt/bluedroid/api/include/api/esp_bt_defs.h
components/bt/bluedroid/api/include/api/esp_gap_ble_api.h
components/bt/bluedroid/bta/dm/bta_dm_act.c
components/bt/bluedroid/bta/dm/bta_dm_api.c
components/bt/bluedroid/bta/dm/include/bta_dm_int.h
components/bt/bluedroid/bta/include/bta/bta_api.h
components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h
components/bt/bluedroid/stack/btm/btm_ble_bgconn.c
components/bt/bluedroid/stack/btm/btm_ble_gap.c
components/bt/bluedroid/stack/btm/include/btm_ble_int.h
components/bt/bluedroid/stack/gatt/gatt_utils.c
components/bt/bluedroid/stack/include/stack/btm_ble_api.h

index c48fe757d8ee18eb68594cd33145e499d2e55945..cada44f8bab928a1426392a8aa9e474de41fe39a 100644 (file)
@@ -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)
index da93b87bcadacc0c0814f139a8a791b67e02787e..7e1063c71c51cfaed7ffc1810535bdff1e528c02 100644 (file)
@@ -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
index b34c2ae11d9b4a16f94c74f4151c83d8da634596..a2f03237c26eb553dd1653b24754d18bbdccd93a 100644 (file)
@@ -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
index f1061a390fe0b5c06ec54b94e4769ca68aaa54ac..390a7ad6f31898306e3a552765481296c9298f99 100644 (file)
@@ -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)
index c5d5440fc531275c74518f05881fb56706caabf9..078903d31ae1cc87e27e4c819d739fb47dc92a7a 100644 (file)
@@ -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));
 
index 6e962d5d5ab7b536723dda898daff2468eb45048..9ff577481c79e73200c7d4861b678854e7a6b763 100644 (file)
@@ -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;
 
index f384edeb456da9018c0fb2a2c5a5320ea75e6123..c7bad21fed3e7c9c99060d952b1823de8d88cc63 100644 (file)
@@ -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);
 
index ef13106dde6035144ae6ea663ca89641e63bfb62..ffac0c35f6486ac6ca1cc6b92862ed382be13aa7 100644 (file)
@@ -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);
index a6cfbba3e7ed647ce850ce871f45207ff814c38d..be818269b275050058d12930dd0bf0ab55a40b0b 100644 (file)
@@ -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)
index a39eb5afac9684d6ff32196f323b7d3a6b78c359..0766715480ac5277a240e328e90cf52ac9973c2d 100644 (file)
@@ -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;
index 14c96b15dcdb8aabbf2c3d7eb0c291cb55338c49..fd231489ea17f68e9b1ad28099b8f22bf122f2f3 100644 (file)
@@ -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);
 }
 
 /*******************************************************************************
index 848bff3740509460154c24e47c48dccd63c6ed10..94a5069e5c3796f7cb992bbc28364918bc5023dc 100644 (file)
@@ -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);
index 6d724e6d431f8700dfb865426907dd4c73a8a34d..2455f746f3283447d181225c9de4c82a9b757029 100644 (file)
@@ -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);
                     }
                 }
             }
index 7e6feb39bd77dc6d7f10407f2d870f481c77dc5b..cdbb2db617f091af833756c5cbbb69e6a34c1397 100644 (file)
@@ -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);
 
 /*******************************************************************************
 **