diff --git a/components/bt/bluedroid/api/esp_gap_ble_api.c b/components/bt/bluedroid/api/esp_gap_ble_api.c index 5367ea0f9e..713ec47400 100644 --- a/components/bt/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/bluedroid/api/esp_gap_ble_api.c @@ -195,6 +195,69 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable) return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } +esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda) +{ + btc_msg_t msg; + btc_ble_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST; + arg.update_white_list.add_remove = add_remove; + 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) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_gap_get_whitelist_size(uint16_t *length) +{ + if (length == NULL) { + return ESP_FAIL; + } + btc_get_whitelist_size(length); + + return ESP_OK; +} + +esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr, + uint16_t min_conn_int, uint16_t max_conn_int, + uint16_t slave_latency, uint16_t supervision_tout) +{ + btc_msg_t msg; + btc_ble_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (ESP_BLE_IS_VALID_PARAM(min_conn_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && + ESP_BLE_IS_VALID_PARAM(max_conn_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) && + ESP_BLE_IS_VALID_PARAM(supervision_tout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) && + (slave_latency <= ESP_BLE_CONN_LATENCY_MAX || slave_latency == ESP_BLE_CONN_PARAM_UNDEF)) { + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ACT_SET_CONN_PARAMS; + arg.set_conn_params.min_conn_int = min_conn_int; + arg.set_conn_params.max_conn_int = max_conn_int; + arg.set_conn_params.slave_latency = slave_latency; + arg.set_conn_params.supervision_tout = supervision_tout; + memcpy(arg.set_conn_params.bd_addr, bd_addr, sizeof(esp_bd_addr_t)); + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); + } else { + LOG_ERROR("%s,invalid connection params:min_int = %d, max_int = %d, latency = %d, timeout = %d",\ + __func__, min_conn_int, max_conn_int, slave_latency, supervision_tout); + return ESP_FAIL; + } +} + esp_err_t esp_ble_gap_set_device_name(const char *name) { ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -240,6 +303,23 @@ esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_l } +esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr) +{ + btc_msg_t msg; + btc_ble_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ACT_READ_RSSI; + memcpy(arg.read_rssi.remote_addr, remote_addr, sizeof(esp_bd_addr_t)); + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len) { btc_msg_t msg; diff --git a/components/bt/bluedroid/api/include/esp_bt_defs.h b/components/bt/bluedroid/api/include/esp_bt_defs.h index 513d37ec42..25a2e217b4 100644 --- a/components/bt/bluedroid/api/include/esp_bt_defs.h +++ b/components/bt/bluedroid/api/include/esp_bt_defs.h @@ -66,8 +66,13 @@ typedef uint8_t esp_link_key[ESP_BT_OCTET16_LEN]; /* Link Key */ /// Default GATT interface id #define ESP_DEFAULT_GATT_IF 0xff -/// Default BLE connection param, if the value doesn't be overwritten -#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ +#define ESP_BLE_CONN_INT_MIN 0x0006 /*!< relate to BTM_BLE_CONN_INT_MIN in btm_ble_api.h */ +#define ESP_BLE_CONN_INT_MAX 0x0C80 /*!< relate to BTM_BLE_CONN_INT_MAX in btm_ble_api.h */ +#define ESP_BLE_CONN_LATENCY_MAX 500 /*!< relate to ESP_BLE_CONN_LATENCY_MAX in btm_ble_api.h */ +#define ESP_BLE_CONN_SUP_TOUT_MIN 0x000A /*!< relate to BTM_BLE_CONN_SUP_TOUT_MIN in btm_ble_api.h */ +#define ESP_BLE_CONN_SUP_TOUT_MAX 0x0C80 /*!< relate to ESP_BLE_CONN_SUP_TOUT_MAX in btm_ble_api.h */ +#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ /* relate to ESP_BLE_CONN_PARAM_UNDEF in btm_ble_api.h */ +#define ESP_BLE_SCAN_PARAM_UNDEF 0xffffffff /* relate to ESP_BLE_SCAN_PARAM_UNDEF in btm_ble_api.h */ /// Check the param is valid or not #define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) diff --git a/components/bt/bluedroid/api/include/esp_gap_ble_api.h b/components/bt/bluedroid/api/include/esp_gap_ble_api.h index 3d835d04b4..7d98fe11c1 100644 --- a/components/bt/bluedroid/api/include/esp_gap_ble_api.h +++ b/components/bt/bluedroid/api/include/esp_gap_ble_api.h @@ -68,7 +68,6 @@ typedef uint8_t esp_ble_auth_req_t; /*!< combination of the above bit #define ESP_IO_CAP_KBDISP 4 /*!< Keyboard display */ /* relate to BTM_IO_CAP_KBDISP in btm_api.h */ typedef uint8_t esp_ble_io_cap_t; /*!< combination of the io capability */ - /// GAP BLE callback event type typedef enum { ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT = 0, /*!< When advertising data set complete, the event comes */ @@ -95,6 +94,9 @@ typedef enum { ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, /*!< When set pkt lenght complete, the event comes */ ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT, /*!< When Enable/disable privacy on the local device complete, the event comes */ ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT, /*!< When remove the bond device complete, the event comes */ + 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_EVT_MAX, } esp_gap_ble_cb_event_t; @@ -567,7 +569,7 @@ typedef union { */ struct ble_local_privacy_cmpl_evt_param { esp_bt_status_t status; /*!< Indicate the set local privacy operation success status */ - } local_privacy_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */ + } local_privacy_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */ /** * @brief ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT */ @@ -575,6 +577,29 @@ typedef union { esp_bt_status_t status; /*!< Indicate the remove bond device operation success status */ esp_bd_addr_t bd_addr; /*!< The device address which has been remove from the bond list */ }remove_bond_dev_cmpl; /*!< Event parameter of ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT + */ + struct ble_clear_bond_dev_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the clear bond device operation success status */ + }clear_bond_dev_cmpl; /*!< Event parameter of ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT + */ + struct ble_get_bond_dev_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the get bond device operation success status */ + uint8_t dev_num; /*!< Indicate the get number device in the bond list */ + esp_ble_bond_dev_t *bond_dev; /*!< the pointer to the bond device Structure */ + }get_bond_dev_cmpl; /*!< Event parameter of ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT + */ + struct ble_read_rssi_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the read adv tx power operation success status */ + int8_t rssi; /*!< The ble remote device rssi value, the range is from -127 to 20, the unit is dbm, + 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 */ } esp_ble_gap_cb_param_t; /** @@ -726,6 +751,48 @@ esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr); */ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable); +/** +* @brief Add or remove device from white list +* +* @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. +* @return +* - ESP_OK : success +* - other : failed +* +*/ +esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda); + +/** +* @brief Get the whitelist size in the controller +* +* @param[out] length: the white list length. +* @return +* - ESP_OK : success +* - other : failed +* +*/ +esp_err_t esp_ble_gap_get_whitelist_size(uint16_t *length); + +/** +* @brief This function is called to set the preferred connection +* parameters when default connection parameter is not desired before connecting. +* This API can only be used in the master role. +* +* @param[in] bd_addr: BD address of the peripheral +* @param[in] min_conn_int: minimum preferred connection interval +* @param[in] max_conn_int: maximum preferred connection interval +* @param[in] slave_latency: preferred slave latency +* @param[in] supervision_tout: preferred supervision timeout +* +* @return +* - ESP_OK : success +* - other : failed +* +*/ +esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr, + uint16_t min_conn_int, uint16_t max_conn_int, + uint16_t slave_latency, uint16_t supervision_tout); /** * @brief Set device name to the local device @@ -780,6 +847,26 @@ esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_l */ esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len); +/** + * @brief This function is called to read the RSSI of remote device. + * The address of link policy results are returned in the gap callback function with + * ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT event. + * + * @param[in] remote_addr : The remote connection device address. + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr); +<<<<<<< HEAD + +======= + + + + +>>>>>>> e14a214... squash the commit. #if (SMP_INCLUDED == TRUE) /** * @brief Set a GAP security parameter value. Overrides the default value. diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index eed5241a5a..916547fd05 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -523,6 +523,29 @@ void bta_dm_set_dev_name (tBTA_DM_MSG *p_data) bta_dm_set_eir ((char *)p_data->set_name.name); } +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); +} + +void bta_dm_ble_read_adv_tx_power(tBTA_DM_MSG *p_data) +{ + if (p_data->read_tx_power.read_tx_power_cb != NULL) { + BTM_BleReadAdvTxPower(p_data->read_tx_power.read_tx_power_cb); + } else { + APPL_TRACE_ERROR("%s(), the callback function cann't be NULL.", __func__); + } +} + +void bta_dm_ble_read_rssi(tBTA_DM_MSG *p_data) +{ + if (p_data->rssi.read_rssi_cb != NULL) { + BTM_ReadRSSI(p_data->rssi.remote_addr, p_data->rssi.read_rssi_cb); + } else { + APPL_TRACE_ERROR("%s(), the callback function cann't be NULL.", __func__); + } +} + /******************************************************************************* ** ** Function bta_dm_set_visibility diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 58414c2370..2f3c7a912f 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -183,6 +183,39 @@ void BTA_DmSetDeviceName(char *p_name) } +void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr) +{ + 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; + memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR)); + + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb) +{ + tBTA_DM_API_READ_ADV_TX_POWER *p_msg; + if ((p_msg = (tBTA_DM_API_READ_ADV_TX_POWER *)osi_malloc(sizeof(tBTA_DM_API_READ_ADV_TX_POWER))) != NULL) { + p_msg->hdr.event = BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT; + p_msg->read_tx_power_cb = cmpl_cb; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleReadRSSI(BD_ADDR remote_addr, tBTA_CMPL_CB *cmpl_cb) +{ + tBTA_DM_API_READ_RSSI *p_msg; + if ((p_msg = (tBTA_DM_API_READ_RSSI *)osi_malloc(sizeof(tBTA_DM_API_READ_RSSI))) != NULL) { + p_msg->hdr.event = BTA_DM_API_BLE_READ_RSSI_EVT; + memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR)); + p_msg->read_rssi_cb = cmpl_cb; + bta_sys_sendmsg(p_msg); + } +} + /******************************************************************************* ** ** Function BTA_DmSetVisibility diff --git a/components/bt/bluedroid/bta/dm/bta_dm_int.h b/components/bt/bluedroid/bta/dm/bta_dm_int.h index 204b8e58c2..5676758aa9 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/bta_dm_int.h @@ -145,6 +145,9 @@ enum { BTA_DM_API_EXECUTE_CBACK_EVT, BTA_DM_API_REMOVE_ALL_ACL_EVT, BTA_DM_API_REMOVE_DEVICE_EVT, + BTA_DM_API_UPDATE_WHITE_LIST_EVT, + BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT, + BTA_DM_API_BLE_READ_RSSI_EVT, BTA_DM_MAX_EVT }; @@ -161,8 +164,7 @@ enum { BTA_DM_SEARCH_CMPL_EVT, BTA_DM_DISCOVERY_RESULT_EVT, BTA_DM_API_DI_DISCOVER_EVT, - BTA_DM_DISC_CLOSE_TOUT_EVT - + BTA_DM_DISC_CLOSE_TOUT_EVT, }; /* data type for BTA_DM_API_ENABLE_EVT */ @@ -177,6 +179,23 @@ typedef struct { BD_NAME name; /* max 248 bytes name, plus must be Null terminated */ } tBTA_DM_API_SET_NAME; +typedef struct { + BT_HDR hdr; + BOOLEAN add_remove; + BD_ADDR remote_addr; +}tBTA_DM_API_UPDATE_WHITE_LIST; + +typedef struct { + BT_HDR hdr; + tBTA_CMPL_CB *read_tx_power_cb; +}tBTA_DM_API_READ_ADV_TX_POWER; + +typedef struct { + BT_HDR hdr; + BD_ADDR remote_addr; + tBTA_CMPL_CB *read_rssi_cb; +}tBTA_DM_API_READ_RSSI; + /* data type for BTA_DM_API_SET_VISIBILITY_EVT */ typedef struct { BT_HDR hdr; @@ -684,6 +703,9 @@ typedef union { tBTA_DM_API_SET_NAME set_name; + tBTA_DM_API_UPDATE_WHITE_LIST white_list; + tBTA_DM_API_READ_ADV_TX_POWER read_tx_power; + tBTA_DM_API_READ_RSSI rssi; tBTA_DM_API_SET_VISIBILITY set_visibility; tBTA_DM_API_ADD_DEVICE add_dev; @@ -1101,6 +1123,9 @@ extern void bta_dm_search_sm_disable( void ); extern void bta_dm_enable (tBTA_DM_MSG *p_data); extern void bta_dm_disable (tBTA_DM_MSG *p_data); extern void bta_dm_set_dev_name (tBTA_DM_MSG *p_data); +extern void bta_dm_update_white_list(tBTA_DM_MSG *p_data); +extern void bta_dm_ble_read_adv_tx_power(tBTA_DM_MSG *p_data); +extern void bta_dm_ble_read_rssi(tBTA_DM_MSG *p_data); extern void bta_dm_set_visibility (tBTA_DM_MSG *p_data); extern void bta_dm_set_scan_config(tBTA_DM_MSG *p_data); diff --git a/components/bt/bluedroid/bta/dm/bta_dm_main.c b/components/bt/bluedroid/bta/dm/bta_dm_main.c index 2f01c248f5..1fecf879d7 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -140,6 +140,9 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { bta_dm_remove_all_acl, /* BTA_DM_API_REMOVE_ALL_ACL_EVT */ bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */ + bta_dm_update_white_list, /* BTA_DM_API_UPDATE_WHITE_LIST_EVT */ + bta_dm_ble_read_adv_tx_power, /* BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT */ + bta_dm_ble_read_rssi, /* BTA_DM_API_BLE_READ_RSSI_EVT */ }; diff --git a/components/bt/bluedroid/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index fb02175f68..12fd911cc8 100644 --- a/components/bt/bluedroid/bta/include/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta_api.h @@ -406,6 +406,12 @@ typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK; typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK; +typedef tBTM_CMPL_CB tBTA_CMPL_CB; + +typedef tBTM_TX_POWER_RESULTS tBTA_TX_POWER_RESULTS; + +typedef tBTM_RSSI_RESULTS tBTA_RSSI_RESULTS; + /* advertising channel map */ #define BTA_BLE_ADV_CHNL_37 BTM_BLE_ADV_CHNL_37 #define BTA_BLE_ADV_CHNL_38 BTM_BLE_ADV_CHNL_38 @@ -1404,6 +1410,12 @@ extern void BTA_DisableTestMode(void); *******************************************************************************/ extern void BTA_DmSetDeviceName(char *p_name); +extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr); + +extern void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb); + +extern void BTA_DmBleReadRSSI(BD_ADDR remote_addr, tBTA_CMPL_CB *cmpl_cb); + /******************************************************************************* ** ** Function BTA_DmSetVisibility 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 5869f393d1..6a7bb0befd 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 @@ -145,6 +145,15 @@ static esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status) case BTM_SUCCESS: esp_status = ESP_BT_STATUS_SUCCESS; break; + case BTM_BUSY: + esp_status = ESP_BT_STATUS_BUSY; + break; + case BTM_NO_RESOURCES: + esp_status = ESP_BT_STATUS_NOMEM; + break; + case BTM_ERR_PROCESSING: + esp_status = ESP_BT_STATUS_PENDING; + break; case BTM_PEER_LE_DATA_LEN_UNSUPPORTED: esp_status = ESP_BT_STATUS_PEER_LE_DATA_LEN_UNSUPPORTED; break; @@ -700,6 +709,33 @@ static void btc_set_encryption_callback(BD_ADDR bd_addr, tBTA_TRANSPORT transpor } #endif ///SMP_INCLUDED == TRUE +static void btc_read_ble_rssi_cmpl_callback(void *p_data) +{ + tBTA_RSSI_RESULTS *result = (tBTA_RSSI_RESULTS *)p_data; + 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_READ_RSSI_COMPLETE_EVT; + param.read_rssi_cmpl.rssi = result->rssi; + param.read_rssi_cmpl.status = btc_btm_status_to_esp_status(result->status); + memcpy(param.read_rssi_cmpl.remote_addr, result->rem_bda, sizeof(BD_ADDR)); + + 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__); + } +} + +void btc_get_whitelist_size(uint16_t *length) +{ + BTM_BleGetWhiteListSize(length); + return; +} + static void btc_ble_start_scanning(uint32_t duration, tBTA_DM_SEARCH_CBACK *results_cb, tBTA_START_STOP_SCAN_CMPL_CBACK *start_scan_cb) @@ -994,6 +1030,20 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY: 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); + break; + case BTC_GAP_BLE_ACT_READ_RSSI: + BTA_DmBleReadRSSI(arg->read_rssi.remote_addr, btc_read_ble_rssi_cmpl_callback); + break; + case BTC_GAP_BLE_ACT_SET_CONN_PARAMS: + BTA_DmSetBlePrefConnParams(arg->set_conn_params.bd_addr, arg->set_conn_params.min_conn_int, + arg->set_conn_params.max_conn_int, arg->set_conn_params.slave_latency, + arg->set_conn_params.supervision_tout); + break; + case BTC_GAP_BLE_ACT_SET_DEV_NAME: + BTA_DmSetDeviceName(arg->set_dev_name.device_name); + break; case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv, arg->cfg_adv_data_raw.raw_adv_len, 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 601167a5a3..8074c1b9b4 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 @@ -31,9 +31,12 @@ typedef enum { BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN, BTC_GAP_BLE_ACT_SET_RAND_ADDRESS, BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, + BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST, + BTC_GAP_BLE_ACT_SET_CONN_PARAMS, BTC_GAP_BLE_ACT_SET_DEV_NAME, BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW, BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW, + BTC_GAP_BLE_ACT_READ_RSSI, BTC_GAP_BLE_SET_ENCRYPTION_EVT, BTC_GAP_BLE_SET_SECURITY_PARAM_EVT, BTC_GAP_BLE_SECURITY_RSP_EVT, @@ -79,7 +82,25 @@ typedef union { //BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, struct cfg_local_privacy_args { bool privacy_enable; - } cfg_local_privacy; + } cfg_local_privacy; + //BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST + struct update_white_list_args { + bool add_remove; + esp_bd_addr_t remote_bda; + }update_white_list; + //BTC_GAP_BLE_ACT_SET_CONN_PARAMS + struct set_conn_params_args { + esp_bd_addr_t bd_addr; + uint16_t min_conn_int; + uint16_t max_conn_int; + uint16_t slave_latency; + uint16_t supervision_tout; + }set_conn_params; + //BTC_GAP_BLE_ACT_SET_DEV_NAME, + struct set_dev_name_args { +#define ESP_GAP_DEVICE_NAME_MAX (32) + char device_name[ESP_GAP_DEVICE_NAME_MAX + 1]; + } set_dev_name; //BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW, struct config_adv_data_raw_args { uint8_t *raw_adv; @@ -125,11 +146,15 @@ typedef union { struct remove_bond_device_args { esp_bd_addr_t bd_addr; } remove_bond_device; + //BTC_GAP_BLE_ACT_READ_RSSI + struct read_rssi_args { + esp_bd_addr_t remote_addr; + } read_rssi; } btc_ble_gap_args_t; void btc_gap_ble_call_handler(btc_msg_t *msg); void btc_gap_ble_cb_handler(btc_msg_t *msg); - +void btc_get_whitelist_size(uint16_t *length); void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); void btc_gap_ble_arg_deep_free(btc_msg_t *msg); void btc_gap_ble_cb_deep_free(btc_msg_t *msg); diff --git a/components/bt/bluedroid/stack/btm/btm_acl.c b/components/bt/bluedroid/stack/btm/btm_acl.c index 2603a9a8d1..028f6f867d 100644 --- a/components/bt/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/bluedroid/stack/btm/btm_acl.c @@ -1906,9 +1906,11 @@ tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x\n", remote_bda[0], remote_bda[1], remote_bda[2], remote_bda[3], remote_bda[4], remote_bda[5]); - + tBTM_RSSI_RESULTS result; /* If someone already waiting on the version, do not allow another */ if (btm_cb.devcb.p_rssi_cmpl_cb) { + result.status = BTM_BUSY; + (*p_cb)(&result); return (BTM_BUSY); } @@ -1929,6 +1931,8 @@ tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) if (!btsnd_hcic_read_rssi (p->hci_handle)) { btm_cb.devcb.p_rssi_cmpl_cb = NULL; btu_stop_timer (&btm_cb.devcb.rssi_timer); + result.status = BTM_NO_RESOURCES; + (*p_cb)(&result); return (BTM_NO_RESOURCES); } else { return (BTM_CMD_STARTED); @@ -2038,6 +2042,43 @@ tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_C /* If here, no BD Addr found */ return (BTM_UNKNOWN_ADDR); } +tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb) +{ + BOOLEAN ret; + tBTM_TX_POWER_RESULTS result; + /* If someone already waiting on the version, do not allow another */ + if (btm_cb.devcb.p_tx_power_cmpl_cb) { + result.status = BTM_BUSY; + (*p_cb)(&result); + return (BTM_BUSY); + } + + btm_cb.devcb.p_tx_power_cmpl_cb = p_cb; + btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL, + BTM_DEV_REPLY_TIMEOUT); + ret = btsnd_hcic_ble_read_adv_chnl_tx_power(); + + if(!ret) { + btm_cb.devcb.p_tx_power_cmpl_cb = NULL; + btu_stop_timer (&btm_cb.devcb.tx_power_timer); + result.status = BTM_NO_RESOURCES; + (*p_cb)(&result); + return (BTM_NO_RESOURCES); + } else { + return BTM_CMD_STARTED; + } +} + +void BTM_BleGetWhiteListSize(uint16_t *length) +{ + tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; + if (p_cb->white_list_avail_size == 0) { + BTM_TRACE_ERROR("%s Whitelist full.", __func__); + } + *length = p_cb->white_list_avail_size; + return; +} + /******************************************************************************* ** ** Function btm_read_tx_power_complete diff --git a/components/bt/bluedroid/stack/btm/btm_ble.c b/components/bt/bluedroid/stack/btm/btm_ble.c index d1bb913d54..fd4cb81ada 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/bluedroid/stack/btm/btm_ble.c @@ -542,7 +542,7 @@ void BTM_BleSetPrefConnParams (BD_ADDR bd_addr, UINT16 min_conn_int, UINT16 max_conn_int, UINT16 slave_latency, UINT16 supervision_tout) { - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); + tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (bd_addr); BTM_TRACE_API ("BTM_BleSetPrefConnParams min: %u max: %u latency: %u \ tout: %u", diff --git a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c index faf5713eff..4d57f3edcb 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c @@ -258,18 +258,22 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr) tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; if (to_add && p_cb->white_list_avail_size == 0) { - BTM_TRACE_ERROR("%s Whitelist full, unable to add device", __func__); + BTM_TRACE_DEBUG("%s Whitelist full, unable to add device", __func__); return FALSE; } if (to_add) { + /* added the bd_addr to the connection hash map queue */ background_connection_add((bt_bdaddr_t *)bd_addr); } else { + /* remove the bd_addr to the connection hash map queue */ background_connection_remove((bt_bdaddr_t *)bd_addr); } - + /* 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); + /* save the ba_addr to the controller white list & start the auto connet */ btm_resume_wl_activity(p_cb->wl_state); 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 616f3aa960..4e62504a05 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -246,10 +246,7 @@ void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn *******************************************************************************/ BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda) { - UNUSED(add_remove); - UNUSED(remote_bda); - - return FALSE; + return btm_update_dev_to_white_list(add_remove, remote_bda); } /******************************************************************************* @@ -3164,7 +3161,8 @@ tBTM_STATUS btm_ble_start_adv(void) } #endif if (p_cb->afp != AP_SCAN_CONN_ALL) { - btm_execute_wl_dev_operation(); + //find the device in the btm dev buffer and write it to the controller white list + btm_execute_wl_dev_operation(); btm_cb.ble_ctr_cb.wl_state |= BTM_BLE_WL_ADV; } diff --git a/components/bt/bluedroid/stack/include/btm_api.h b/components/bt/bluedroid/stack/include/btm_api.h index d4ee7b4734..e477eae110 100644 --- a/components/bt/bluedroid/stack/include/btm_api.h +++ b/components/bt/bluedroid/stack/include/btm_api.h @@ -2833,6 +2833,11 @@ tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb); +tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb); + +void BTM_BleGetWhiteListSize(uint16_t *length); + + /******************************************************************************* ** ** Function BTM_ReadLinkQuality