diff --git a/components/bt/bluedroid/api/include/esp_bt_defs.h b/components/bt/bluedroid/api/include/esp_bt_defs.h index ca3ef9d2a..9d90cbf9e 100644 --- a/components/bt/bluedroid/api/include/esp_bt_defs.h +++ b/components/bt/bluedroid/api/include/esp_bt_defs.h @@ -14,6 +14,8 @@ typedef enum { ESP_BT_STATUS_WRONG_MODE = 5, } esp_bt_status_t; +#define ESP_DEFAULT_GATT_IF 0xff + #define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ #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 3a7a5d9ee..6fd356c0d 100644 --- a/components/bt/bluedroid/api/include/esp_gap_ble_api.h +++ b/components/bt/bluedroid/api/include/esp_gap_ble_api.h @@ -62,15 +62,16 @@ typedef struct { bool set_scan_rsp; bool include_name; bool include_txpower; - int min_interval; - int max_interval; - int appearance; + int min_interval; + int max_interval; + int appearance; uint16_t manufacturer_len; - uint8_t *p_manufacturer_data; + uint8_t *p_manufacturer_data; uint16_t service_data_len; - uint8_t *p_service_data; + uint8_t *p_service_data; uint16_t service_uuid_len; - uint8_t *p_service_uuid; + uint8_t *p_service_uuid; + uint8_t flag; } esp_ble_adv_data_t; typedef enum { 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 79c53b378..c6e2aa98c 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 @@ -110,10 +110,10 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT memset(bta_adv_data, 0, sizeof(tBTA_BLE_ADV_DATA)); mask = 0; - if (!p_adv_data->set_scan_rsp) + if (p_adv_data->flag != 0) { mask = BTM_BLE_AD_BIT_FLAGS; - } + } if (p_adv_data->include_name) mask |= BTM_BLE_AD_BIT_DEV_NAME; @@ -202,7 +202,7 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT tBT_UUID bt_uuid; memcpy(&bt_uuid.uu, p_adv_data->p_service_uuid + position, LEN_UUID_128); - bt_uuid.len = p_adv_data->service_uuid_len; + bt_uuid.len = p_adv_data->service_uuid_len; switch(bt_uuid.len) { @@ -305,16 +305,6 @@ static void btc_adv_data_callback(tBTA_STATUS status) } } -static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data, - tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback) -{ - tBTA_BLE_ADV_DATA bta_adv_data; //TODO:must be global, not stack - tBTA_BLE_AD_MASK data_mask = 0; - - btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask); - BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback); -} - static void btc_scan_rsp_data_callback(tBTA_STATUS status) { esp_ble_gap_cb_param_t param; @@ -324,7 +314,7 @@ static void btc_scan_rsp_data_callback(tBTA_STATUS status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT; - param.scan_rsp_data_cmpl.status = status; + param.adv_data_cmpl.status = status; ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL); @@ -334,13 +324,53 @@ static void btc_scan_rsp_data_callback(tBTA_STATUS status) } } -static void btc_ble_set_scan_rsp_data(esp_ble_adv_data_t *scan_rsp_data, - tBTA_SET_ADV_DATA_CMPL_CBACK p_scan_rsp_data_cback) +static void btc_set_scan_param_callback(tGATT_IF client_if, tBTA_STATUS status ) { + 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_SCAN_PARAM_SET_COMPLETE_EVT; + param.adv_data_cmpl.status = status; + + 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_ble_set_adv_data(esp_ble_adv_data_t *adv_data, + tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback) +{ + tBTA_BLE_ADV_DATA bta_adv_data; //TODO:must be global, not stack tBTA_BLE_AD_MASK data_mask = 0; - btc_to_bta_adv_data(scan_rsp_data, &gl_bta_scan_rsp_data, &data_mask); - BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data, p_scan_rsp_data_cback); + btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask); + if (!adv_data->set_scan_rsp){ + BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback); + }else{ + BTA_DmBleSetScanRsp(data_mask, &gl_bta_adv_data, p_adv_data_cback); + } +} + + +static void btc_ble_set_scan_param(esp_ble_scan_params_t *ble_scan_params, + tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) +{ + //tBTA_BLE_AD_MASK data_mask = 0; + BTA_DmSetBleScanParams (ESP_DEFAULT_GATT_IF, + ble_scan_params->scan_interval, + ble_scan_params->scan_window, + ble_scan_params->scan_type, + scan_param_setup_cback); + //btc_to_bta_adv_data(scan_rsp_data, &gl_bta_scan_rsp_data, &data_mask); + //BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data, p_scan_rsp_data_cback); } static void btc_ble_start_advertising(esp_ble_adv_params_t *ble_adv_params) @@ -375,12 +405,12 @@ static void btc_ble_start_advertising(esp_ble_adv_params_t *ble_adv_params) memcpy(&bd_addr.bda, ble_adv_params->peer_addr, sizeof(BD_ADDR)); /// BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min, - ble_adv_params->adv_int_max, - ble_adv_params->adv_type, - ble_adv_params->own_addr_type, - ble_adv_params->channel_map, - ble_adv_params->adv_filter_policy, - &bd_addr); + ble_adv_params->adv_int_max, + ble_adv_params->adv_type, + ble_adv_params->own_addr_type, + ble_adv_params->channel_map, + ble_adv_params->adv_filter_policy, + &bd_addr); } @@ -544,10 +574,16 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_GAP_BLE_ACT_CFG_ADV_DATA: - btc_ble_set_adv_data(&arg->adv_data, btc_adv_data_callback); + { + if(arg->adv_data.set_scan_rsp == false){ + btc_ble_set_adv_data(&arg->adv_data, btc_adv_data_callback); + }else{ + btc_ble_set_adv_data(&arg->adv_data, btc_scan_rsp_data_callback); + } break; + } case BTC_GAP_BLE_ACT_SET_SCAN_PARAM: - btc_ble_set_scan_rsp_data(&arg->adv_data, btc_adv_data_callback); + btc_ble_set_scan_param(&arg->scan_params, btc_set_scan_param_callback); break; case BTC_GAP_BLE_ACT_START_SCAN: btc_ble_start_scanning(arg->duration, btc_search_callback); diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c index 539a524d9..75f5cb622 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c @@ -217,7 +217,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg) { esp_ble_gatts_cb_param_t param; - tBTA_GATTS *p_data = (tBTA_GATTS *)msg->arg; + tBTA_GATTS *p_data = (tBTA_GATTS *)msg->arg; switch (msg->act) { case BTA_GATTS_REG_EVT: { diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c index ee57954c3..931e146a0 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c @@ -373,7 +373,7 @@ void bt_app_stop_timer(TIMER_LIST_ENT *p_tle) // Get the alarm for the timer list entry. osi_alarm_t *alarm = hash_map_get(bt_app_general_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_WARN("%s Unable to find expected alarm in hashmap", __func__); + LOG_WARN("%s Unable to find expected alarm in hashmap\n", __func__); return; } osi_alarm_cancel(alarm); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c index 7e2808c39..6f3be9a0f 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. + + /**************************************************************************** * * This file is for gatt client. It can scan ble device, connect one device,