mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
refactor(bt/bluedroid): Refactor the print for BLE examples
This commit is contained in:
parent
35a6671072
commit
53a8345e60
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -82,13 +82,17 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
|
||||
//scan start complete event to indicate scan start successfully or failed
|
||||
if ((err = param->scan_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(DEMO_TAG, "Scan start failed: %s", esp_err_to_name(err));
|
||||
ESP_LOGE(DEMO_TAG, "Scanning start failed, error %s", esp_err_to_name(err));
|
||||
} else {
|
||||
ESP_LOGI(DEMO_TAG, "Scanning start successfully");
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
||||
//adv start complete event to indicate adv start successfully or failed
|
||||
if ((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(DEMO_TAG, "Adv start failed: %s", esp_err_to_name(err));
|
||||
ESP_LOGE(DEMO_TAG, "Advertising start failed, error %s", esp_err_to_name(err));
|
||||
} else {
|
||||
ESP_LOGI(DEMO_TAG, "Advertising start successfully");
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_SCAN_RESULT_EVT: {
|
||||
@ -99,15 +103,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
if (esp_ble_is_ibeacon_packet(scan_result->scan_rst.ble_adv, scan_result->scan_rst.adv_data_len)){
|
||||
esp_ble_ibeacon_t *ibeacon_data = (esp_ble_ibeacon_t*)(scan_result->scan_rst.ble_adv);
|
||||
ESP_LOGI(DEMO_TAG, "----------iBeacon Found----------");
|
||||
ESP_LOG_BUFFER_HEX("IBEACON_DEMO: Device address:", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN );
|
||||
ESP_LOG_BUFFER_HEX("IBEACON_DEMO: Proximity UUID:", ibeacon_data->ibeacon_vendor.proximity_uuid, ESP_UUID_LEN_128);
|
||||
ESP_LOGI(DEMO_TAG, "Device address: "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(scan_result->scan_rst.bda));
|
||||
ESP_LOG_BUFFER_HEX("IBEACON_DEMO: Proximity UUID", ibeacon_data->ibeacon_vendor.proximity_uuid, ESP_UUID_LEN_128);
|
||||
|
||||
uint16_t major = ENDIAN_CHANGE_U16(ibeacon_data->ibeacon_vendor.major);
|
||||
uint16_t minor = ENDIAN_CHANGE_U16(ibeacon_data->ibeacon_vendor.minor);
|
||||
ESP_LOGI(DEMO_TAG, "Major: 0x%04x (%d)", major, major);
|
||||
ESP_LOGI(DEMO_TAG, "Minor: 0x%04x (%d)", minor, minor);
|
||||
ESP_LOGI(DEMO_TAG, "Measured power (RSSI at a 1m distance):%d dbm", ibeacon_data->ibeacon_vendor.measured_power);
|
||||
ESP_LOGI(DEMO_TAG, "RSSI of packet:%d dbm", scan_result->scan_rst.rssi);
|
||||
ESP_LOGI(DEMO_TAG, "Measured power (RSSI at a 1m distance): %d dBm", ibeacon_data->ibeacon_vendor.measured_power);
|
||||
ESP_LOGI(DEMO_TAG, "RSSI of packet: %d dbm", scan_result->scan_rst.rssi);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -118,19 +122,19 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
|
||||
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
|
||||
if ((err = param->scan_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(DEMO_TAG, "Scan stop failed: %s", esp_err_to_name(err));
|
||||
ESP_LOGE(DEMO_TAG, "Scanning stop failed, error %s", esp_err_to_name(err));
|
||||
}
|
||||
else {
|
||||
ESP_LOGI(DEMO_TAG, "Stop scan successfully");
|
||||
ESP_LOGI(DEMO_TAG, "Scanning stop successfully");
|
||||
}
|
||||
break;
|
||||
|
||||
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||
if ((err = param->adv_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(DEMO_TAG, "Adv stop failed: %s", esp_err_to_name(err));
|
||||
ESP_LOGE(DEMO_TAG, "Advertising stop failed, error %s", esp_err_to_name(err));
|
||||
}
|
||||
else {
|
||||
ESP_LOGI(DEMO_TAG, "Stop adv successfully");
|
||||
ESP_LOGI(DEMO_TAG, "Advertising stop successfully");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1,14 +1,27 @@
|
||||
menu "Example 'GATT CLIENT THROUGHPUT' Config"
|
||||
|
||||
config GATTS_NOTIFY_THROUGHPUT
|
||||
config EXAMPLE_GATTS_NOTIFY_THROUGHPUT
|
||||
bool "test the gatts notify throughput"
|
||||
help
|
||||
If this config item is set, then the 'GATTC_WRITE_THROUGHPUT' config should be close, it can't test both
|
||||
write or notify at the same time at this demo
|
||||
If this config item is set, then the 'EXAMPLE_GATTC_WRITE_THROUGHPUT' config should be close,
|
||||
it can't test both write or notify at the same time at this demo
|
||||
|
||||
config GATTC_WRITE_THROUGHPUT
|
||||
config EXAMPLE_GATTC_WRITE_THROUGHPUT
|
||||
bool "test the gattc write throughput"
|
||||
help
|
||||
If this config item is set, then the 'GATTS_NOTIFY_THROUGHPUT' config should be close, it can't test both
|
||||
write or notify at the same time at this demo
|
||||
If this config item is set, then the 'EXAMPLE_GATTS_NOTIFY_THROUGHPUT' config should be close,
|
||||
it can't test both write or notify at the same time at this demo
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int
|
||||
default 60
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
||||
|
@ -48,25 +48,25 @@
|
||||
#define INVALID_HANDLE 0
|
||||
#define SECOND_TO_USECOND 1000000
|
||||
|
||||
static const char remote_device_name[] = "THROUGHPUT_DEMO";
|
||||
static char remote_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "THROUGHPUT_DEMO";
|
||||
static bool connect = false;
|
||||
static bool get_server = false;
|
||||
static esp_gattc_char_elem_t *char_elem_result = NULL;
|
||||
static esp_gattc_descr_elem_t *descr_elem_result = NULL;
|
||||
#if (CONFIG_GATTS_NOTIFY_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
|
||||
static bool start = false;
|
||||
static uint64_t notify_len = 0;
|
||||
static uint64_t start_time = 0;
|
||||
static uint64_t current_time = 0;
|
||||
#endif /* #if (CONFIG_GATTS_NOTIFY_THROUGHPUT) */
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT) */
|
||||
|
||||
#if (CONFIG_GATTC_WRITE_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT)
|
||||
#define GATTC_WRITE_LEN 495
|
||||
|
||||
static bool can_send_write = false;
|
||||
static SemaphoreHandle_t gattc_semaphore;
|
||||
uint8_t write_data[GATTC_WRITE_LEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0e, 0x0f};
|
||||
#endif /* #if (CONFIG_GATTC_WRITE_THROUGHPUT) */
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT) */
|
||||
|
||||
static bool is_connect = false;
|
||||
|
||||
@ -144,18 +144,17 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
|
||||
switch (event) {
|
||||
case ESP_GATTC_REG_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "REG_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "GATT client register, status %d, app_id %d, gattc_if %d", param->reg.status, param->reg.app_id, gattc_if);
|
||||
esp_err_t scan_ret = esp_ble_gap_set_scan_params(&ble_scan_params);
|
||||
if (scan_ret){
|
||||
ESP_LOGE(GATTC_TAG, "set scan params error, error code = %x", scan_ret);
|
||||
}
|
||||
break;
|
||||
case ESP_GATTC_CONNECT_EVT: {
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT conn_id %d, if %d", p_data->connect.conn_id, gattc_if);
|
||||
ESP_LOGI(GATTC_TAG, "Connected, conn_id %d, remote "ESP_BD_ADDR_STR"", p_data->connect.conn_id,
|
||||
ESP_BD_ADDR_HEX(p_data->connect.remote_bda));
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id = p_data->connect.conn_id;
|
||||
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->connect.remote_bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
||||
esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, p_data->connect.conn_id);
|
||||
if (mtu_ret){
|
||||
ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
|
||||
@ -164,24 +163,21 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
}
|
||||
case ESP_GATTC_OPEN_EVT:
|
||||
if (param->open.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "open failed, status %d", p_data->open.status);
|
||||
ESP_LOGE(GATTC_TAG, "Open failed, status %d", p_data->open.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "open success");
|
||||
ESP_LOGI(GATTC_TAG, "Open successfully, MTU %u", param->open.mtu);
|
||||
break;
|
||||
case ESP_GATTC_CFG_MTU_EVT:
|
||||
if (param->cfg_mtu.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG,"config mtu failed, error status = %x", param->cfg_mtu.status);
|
||||
}
|
||||
is_connect = true;
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_CFG_MTU_EVT, Status %d, MTU %d, conn_id %d", param->cfg_mtu.status, param->cfg_mtu.mtu, param->cfg_mtu.conn_id);
|
||||
ESP_LOGI(GATTC_TAG, "MTU exchange, status %d, MTU %d", param->cfg_mtu.status, param->cfg_mtu.mtu);
|
||||
esp_ble_gattc_search_service(gattc_if, param->cfg_mtu.conn_id, &remote_filter_service_uuid);
|
||||
break;
|
||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_SEARCH_RES_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Service search result");
|
||||
esp_gatt_srvc_id_t *srvc_id =(esp_gatt_srvc_id_t *)&p_data->search_res.srvc_id;
|
||||
if (srvc_id->id.uuid.len == ESP_UUID_LEN_16 && srvc_id->id.uuid.uuid.uuid16 == REMOTE_SERVICE_UUID) {
|
||||
ESP_LOGI(GATTC_TAG, "service found");
|
||||
ESP_LOGI(GATTC_TAG, "Service found");
|
||||
get_server = true;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_start_handle = p_data->search_res.start_handle;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_end_handle = p_data->search_res.end_handle;
|
||||
@ -191,10 +187,10 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
}
|
||||
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||
if (p_data->search_cmpl.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "search service failed, error status = %x", p_data->search_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Service search failed, status %x", p_data->search_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_SEARCH_CMPL_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Service search complete");
|
||||
if (get_server){
|
||||
uint16_t count = 0;
|
||||
esp_gatt_status_t status = esp_ble_gattc_get_attr_count( gattc_if,
|
||||
@ -244,10 +240,10 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
}
|
||||
break;
|
||||
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_REG_FOR_NOTIFY_EVT");
|
||||
if (p_data->reg_for_notify.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "REG FOR NOTIFY failed: error status = %d", p_data->reg_for_notify.status);
|
||||
ESP_LOGE(GATTC_TAG, "Notification register failed, status %d", p_data->reg_for_notify.status);
|
||||
}else{
|
||||
ESP_LOGI(GATTC_TAG, "Notification register successfully");
|
||||
uint16_t count = 0;
|
||||
uint16_t notify_en = 1;
|
||||
esp_gatt_status_t ret_status = esp_ble_gattc_get_attr_count( gattc_if,
|
||||
@ -302,13 +298,13 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_NOTIFY_EVT: {
|
||||
#if (CONFIG_GATTS_NOTIFY_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
|
||||
if (p_data->notify.is_notify &&
|
||||
(p_data->notify.value[p_data->notify.value_len - 1] ==
|
||||
check_sum(p_data->notify.value, p_data->notify.value_len - 1))){
|
||||
notify_len += p_data->notify.value_len;
|
||||
} else {
|
||||
ESP_LOGE(GATTC_TAG, "ESP_GATTC_NOTIFY_EVT, receive indicate value:");
|
||||
ESP_LOGE(GATTC_TAG, "Indication received, value:");
|
||||
}
|
||||
if (start == false) {
|
||||
start_time = esp_timer_get_time();
|
||||
@ -316,53 +312,53 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
break;
|
||||
}
|
||||
|
||||
#endif /* #if (CONFIG_GATTS_NOTIFY_THROUGHPUT) */
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT) */
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
||||
if (p_data->write.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "write descr failed, error status = %x", p_data->write.status);
|
||||
ESP_LOGE(GATTC_TAG, "Descriptor write failed, status %x", p_data->write.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "write descr success ");
|
||||
#if (CONFIG_GATTC_WRITE_THROUGHPUT)
|
||||
ESP_LOGI(GATTC_TAG, "Descriptor write successfully");
|
||||
#if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT)
|
||||
can_send_write = true;
|
||||
xSemaphoreGive(gattc_semaphore);
|
||||
#endif /* #if (CONFIG_GATTC_WRITE_THROUGHPUT) */
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT) */
|
||||
break;
|
||||
case ESP_GATTC_SRVC_CHG_EVT: {
|
||||
esp_bd_addr_t bda;
|
||||
memcpy(bda, p_data->srvc_chg.remote_bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_SRVC_CHG_EVT, bd_addr:");
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "Service change from "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(bda));
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_WRITE_CHAR_EVT:
|
||||
if (p_data->write.status != ESP_GATT_OK) {
|
||||
ESP_LOGE(GATTC_TAG, "write char failed, error status = %x", p_data->write.status);
|
||||
ESP_LOGE(GATTC_TAG, "Characteristic write failed, status %x", p_data->write.status);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESP_GATTC_DISCONNECT_EVT:
|
||||
is_connect = false;
|
||||
get_server = false;
|
||||
#if (CONFIG_GATTS_NOTIFY_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
|
||||
start = false;
|
||||
start_time = 0;
|
||||
current_time = 0;
|
||||
notify_len = 0;
|
||||
#endif /* #if (CONFIG_GATTS_NOTIFY_THROUGHPUT) */
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_DISCONNECT_EVT, reason = %d", p_data->disconnect.reason);
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT) */
|
||||
ESP_LOGI(GATTC_TAG, "Disconnected, remote "ESP_BD_ADDR_STR", reason 0x%02x",
|
||||
ESP_BD_ADDR_HEX(p_data->disconnect.remote_bda), p_data->disconnect.reason);
|
||||
break;
|
||||
case ESP_GATTC_CONGEST_EVT:
|
||||
#if (CONFIG_GATTC_WRITE_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT)
|
||||
if (param->congest.congested) {
|
||||
can_send_write = false;
|
||||
} else {
|
||||
can_send_write = true;
|
||||
xSemaphoreGive(gattc_semaphore);
|
||||
}
|
||||
#endif /* #if (CONFIG_GATTC_WRITE_THROUGHPUT) */
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT) */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -383,32 +379,29 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
|
||||
//scan start complete event to indicate scan start successfully or failed
|
||||
if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(GATTC_TAG, "scan start failed, error status = %x", param->scan_start_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Scanning start failed, status %x", param->scan_start_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "scan start success");
|
||||
ESP_LOGI(GATTC_TAG, "Scanning start successfully");
|
||||
|
||||
break;
|
||||
case ESP_GAP_BLE_SCAN_RESULT_EVT: {
|
||||
esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
|
||||
switch (scan_result->scan_rst.search_evt) {
|
||||
case ESP_GAP_SEARCH_INQ_RES_EVT:
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, scan_result->scan_rst.bda, 6);
|
||||
ESP_LOGI(GATTC_TAG, "searched Adv Data Len %d, Scan Response Len %d", scan_result->scan_rst.adv_data_len, scan_result->scan_rst.scan_rsp_len);
|
||||
adv_name = esp_ble_resolve_adv_data_by_type(scan_result->scan_rst.ble_adv,
|
||||
scan_result->scan_rst.adv_data_len + scan_result->scan_rst.scan_rsp_len,
|
||||
ESP_BLE_AD_TYPE_NAME_CMPL,
|
||||
&adv_name_len);
|
||||
ESP_LOGI(GATTC_TAG, "searched Device Name Len %d", adv_name_len);
|
||||
ESP_LOGI(GATTC_TAG, "Scan result, device "ESP_BD_ADDR_STR", name len %u", ESP_BD_ADDR_HEX(scan_result->scan_rst.bda), adv_name_len);
|
||||
ESP_LOG_BUFFER_CHAR(GATTC_TAG, adv_name, adv_name_len);
|
||||
ESP_LOGI(GATTC_TAG, " ");
|
||||
if (adv_name != NULL) {
|
||||
if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
|
||||
ESP_LOGI(GATTC_TAG, "searched device %s", remote_device_name);
|
||||
ESP_LOGI(GATTC_TAG, "Device found %s", remote_device_name);
|
||||
if (connect == false) {
|
||||
connect = true;
|
||||
ESP_LOGI(GATTC_TAG, "connect to the remote device.");
|
||||
#if(CONFIG_GATTC_WRITE_THROUGHPUT && CONFIG_GATTS_NOTIFY_THROUGHPUT)
|
||||
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
|
||||
#if(CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT && CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
|
||||
esp_ble_gap_set_prefer_conn_params(scan_result->scan_rst.bda, 34, 34, 0, 600);
|
||||
#else
|
||||
esp_ble_gap_set_prefer_conn_params(scan_result->scan_rst.bda, 32, 32, 0, 600);
|
||||
@ -430,21 +423,21 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
|
||||
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
|
||||
if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(GATTC_TAG, "scan stop failed, error status = %x", param->scan_stop_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Scanning stop failed, status %x", param->scan_stop_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "stop scan successfully");
|
||||
ESP_LOGI(GATTC_TAG, "Scanning stop successfully");
|
||||
break;
|
||||
|
||||
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(GATTC_TAG, "adv stop failed, error status = %x", param->adv_stop_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Advertising stop failed, status %x", param->adv_stop_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "stop adv successfully");
|
||||
ESP_LOGI(GATTC_TAG, "Advertising stop successfully");
|
||||
break;
|
||||
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
|
||||
ESP_LOGI(GATTC_TAG, "Connection params update, status %d, conn_int %d, latency %d, timeout %d",
|
||||
param->update_conn_params.status,
|
||||
param->update_conn_params.conn_int,
|
||||
param->update_conn_params.latency,
|
||||
@ -484,7 +477,7 @@ static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp
|
||||
} while (0);
|
||||
}
|
||||
|
||||
#if (CONFIG_GATTC_WRITE_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT)
|
||||
static void throughput_client_task(void *param)
|
||||
{
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
@ -520,9 +513,9 @@ static void throughput_client_task(void *param)
|
||||
|
||||
}
|
||||
}
|
||||
#endif /* #if (CONFIG_GATTC_WRITE_THROUGHPUT) */
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT) */
|
||||
|
||||
#if (CONFIG_GATTS_NOTIFY_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
|
||||
static void throughput_cal_task(void *param)
|
||||
{
|
||||
while (1)
|
||||
@ -542,7 +535,7 @@ static void throughput_cal_task(void *param)
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* #if (CONFIG_GATTS_NOTIFY_THROUGHPUT) */
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT) */
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
@ -554,6 +547,10 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
memcpy(remote_device_name, esp_bluedroid_get_example_name(), sizeof(remote_device_name));
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
@ -604,21 +601,21 @@ void app_main(void)
|
||||
if (local_mtu_ret){
|
||||
ESP_LOGE(GATTC_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
|
||||
}
|
||||
#if (CONFIG_GATTC_WRITE_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT)
|
||||
// The task is only created on the CPU core that Bluetooth is working on,
|
||||
// preventing the sending task from using the un-updated Bluetooth state on another CPU.
|
||||
xTaskCreatePinnedToCore(&throughput_client_task, "throughput_client_task", 4096, NULL, 10, NULL, BLUETOOTH_TASK_PINNED_TO_CORE);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_GATTS_NOTIFY_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
|
||||
xTaskCreatePinnedToCore(&throughput_cal_task, "throughput_cal_task", 4096, NULL, 9, NULL, BLUETOOTH_TASK_PINNED_TO_CORE);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_GATTC_WRITE_THROUGHPUT)
|
||||
#if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT)
|
||||
gattc_semaphore = xSemaphoreCreateBinary();
|
||||
if (!gattc_semaphore) {
|
||||
ESP_LOGE(GATTC_TAG, "%s, init fail, the gattc semaphore create fail.", __func__);
|
||||
return;
|
||||
}
|
||||
#endif /* #if (CONFIG_GATTC_WRITE_THROUGHPUT) */
|
||||
#endif /* #if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT) */
|
||||
}
|
||||
|
@ -6,5 +6,5 @@ CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
|
||||
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||
# CONFIG_BT_LE_50_FEATURE_SUPPORT is not used on ESP32, ESP32-C3 and ESP32-S3.
|
||||
CONFIG_BT_LE_50_FEATURE_SUPPORT=n
|
||||
CONFIG_GATTS_NOTIFY_THROUGHPUT=y
|
||||
CONFIG_GATTC_WRITE_THROUGHPUT=n
|
||||
CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT=y
|
||||
CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT=n
|
||||
|
@ -14,12 +14,25 @@ menu "Example 'GATT SERVER THROUGHPUT' Config"
|
||||
config EXAMPLE_GATTS_NOTIFY_THROUGHPUT
|
||||
bool "test the gatts notify throughput"
|
||||
help
|
||||
If this config item is set, then the 'EXAMPLE_GATTC_WRITE_THROUGHPUT' config should be close, it can't test
|
||||
both write or notify at the same time at this demo
|
||||
If this config item is set, then the 'EXAMPLE_GATTC_WRITE_THROUGHPUT' config should be close,
|
||||
it can't test both write or notify at the same time at this demo
|
||||
|
||||
config EXAMPLE_GATTC_WRITE_THROUGHPUT
|
||||
bool "test the gattc write throughput"
|
||||
help
|
||||
If this config item is set, then the 'EXAMPLE_GATTS_NOTIFY_THROUGHPUT' config should be close, it can't
|
||||
test both write or notify at the same time at this demo
|
||||
If this config item is set, then the 'EXAMPLE_GATTS_NOTIFY_THROUGHPUT' config should be close,
|
||||
it can't test both write or notify at the same time at this demo
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int
|
||||
default 60
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
||||
|
@ -75,13 +75,13 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
#define GATTS_DESCR_UUID_TEST_B 0x2222
|
||||
#define GATTS_NUM_HANDLE_TEST_B 4
|
||||
|
||||
#define TEST_DEVICE_NAME "THROUGHPUT_DEMO"
|
||||
#define TEST_MANUFACTURER_DATA_LEN 17
|
||||
|
||||
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 0x40
|
||||
|
||||
#define PREPARE_BUF_MAX_SIZE 1024
|
||||
|
||||
static char test_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "THROUGHPUT_DEMO";
|
||||
static uint8_t char1_str[] = {0x11,0x22,0x33};
|
||||
static esp_gatt_char_prop_t a_property = 0;
|
||||
|
||||
@ -257,19 +257,21 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
||||
//advertising start complete event to indicate advertising start successfully or failed
|
||||
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(GATTS_TAG, "Advertising start failed");
|
||||
ESP_LOGE(GATTS_TAG, "Advertising start failed, status %d", param->adv_start_cmpl.status);
|
||||
} else {
|
||||
ESP_LOGI(GATTS_TAG, "Advertising start successfully");
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(GATTS_TAG, "Advertising stop failed");
|
||||
ESP_LOGE(GATTS_TAG, "Advertising stop failed, status %d", param->adv_stop_cmpl.status);
|
||||
}
|
||||
else {
|
||||
ESP_LOGI(GATTS_TAG, "Stop adv successfully");
|
||||
ESP_LOGI(GATTS_TAG, "Advertising stop successfully");
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
|
||||
ESP_LOGI(GATTS_TAG, "Connection params update, status %d, conn_int %d, latency %d, timeout %d",
|
||||
param->update_conn_params.status,
|
||||
param->update_conn_params.conn_int,
|
||||
param->update_conn_params.latency,
|
||||
@ -333,7 +335,7 @@ void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare
|
||||
|
||||
void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param){
|
||||
if (param->exec_write.exec_write_flag != ESP_GATT_PREP_WRITE_EXEC){
|
||||
ESP_LOGI(GATTS_TAG,"ESP_GATT_PREP_WRITE_CANCEL");
|
||||
ESP_LOGI(GATTS_TAG,"Prepare write cancel");
|
||||
}
|
||||
if (prepare_write_env->prepare_buf) {
|
||||
free(prepare_write_env->prepare_buf);
|
||||
@ -345,13 +347,13 @@ void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble
|
||||
static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "REGISTER_APP_EVT, status %d, app_id %d", param->reg.status, param->reg.app_id);
|
||||
ESP_LOGI(GATTS_TAG, "GATT server register, status %d, app_id %d, gatts_if %d", param->reg.status, param->reg.app_id, gatts_if);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.is_primary = true;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.inst_id = 0x00;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].gatts_if = gatts_if;
|
||||
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
|
||||
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(test_device_name);
|
||||
if (set_dev_name_ret){
|
||||
ESP_LOGE(GATTS_TAG, "set device name failed, error code = %x", set_dev_name_ret);
|
||||
}
|
||||
@ -384,7 +386,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_A_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_A);
|
||||
break;
|
||||
case ESP_GATTS_READ_EVT: {
|
||||
ESP_LOGI(GATTS_TAG, "GATT_READ_EVT, conn_id %d, trans_id %" PRIu32 ", handle %d", param->read.conn_id, param->read.trans_id, param->read.handle);
|
||||
ESP_LOGI(GATTS_TAG, "Characteristic read, conn_id %d, trans_id %" PRIu32 ", handle %d", param->read.conn_id, param->read.trans_id, param->read.handle);
|
||||
esp_gatt_rsp_t rsp;
|
||||
memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
|
||||
rsp.attr_value.handle = param->read.handle;
|
||||
@ -405,13 +407,13 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
if (descr_value == 0x0001){
|
||||
if (a_property & ESP_GATT_CHAR_PROP_BIT_NOTIFY){
|
||||
|
||||
ESP_LOGI(GATTS_TAG, "notify enable");
|
||||
ESP_LOGI(GATTS_TAG, "Notification enable");
|
||||
can_send_notify = true;
|
||||
xSemaphoreGive(gatts_semaphore);
|
||||
}
|
||||
}else if (descr_value == 0x0002){
|
||||
if (a_property & ESP_GATT_CHAR_PROP_BIT_INDICATE){
|
||||
ESP_LOGI(GATTS_TAG, "indicate enable");
|
||||
ESP_LOGI(GATTS_TAG, "Indication enable");
|
||||
uint8_t indicate_data[600];
|
||||
for (int i = 0; i < sizeof(indicate_data); ++i)
|
||||
{
|
||||
@ -428,7 +430,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
else if (descr_value == 0x0000){
|
||||
can_send_notify = false;
|
||||
a_property = 0;
|
||||
ESP_LOGI(GATTS_TAG, "notify/indicate disable ");
|
||||
ESP_LOGI(GATTS_TAG, "Notification/Indication disable");
|
||||
}else{
|
||||
ESP_LOGE(GATTS_TAG, "unknown descr value");
|
||||
ESP_LOG_BUFFER_HEX(GATTS_TAG, param->write.value, param->write.len);
|
||||
@ -457,7 +459,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
break;
|
||||
}
|
||||
case ESP_GATTS_EXEC_WRITE_EVT:
|
||||
ESP_LOGI(GATTS_TAG,"ESP_GATTS_EXEC_WRITE_EVT");
|
||||
ESP_LOGI(GATTS_TAG,"Execute write");
|
||||
#if (CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT)
|
||||
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_CANCEL) {
|
||||
if (write_len > a_prepare_write_env.prepare_len) {
|
||||
@ -471,13 +473,13 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
example_exec_write_event_env(&a_prepare_write_env, param);
|
||||
break;
|
||||
case ESP_GATTS_MTU_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "ESP_GATTS_MTU_EVT, MTU %d", param->mtu.mtu);
|
||||
ESP_LOGI(GATTS_TAG, "MTU exchange, MTU %d", param->mtu.mtu);
|
||||
is_connect = true;
|
||||
break;
|
||||
case ESP_GATTS_UNREG_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CREATE_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "CREATE_SERVICE_EVT, status %d, service_handle %d", param->create.status, param->create.service_handle);
|
||||
ESP_LOGI(GATTS_TAG, "Service create, status %d, service_handle %d", param->create.status, param->create.service_handle);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_handle = param->create.service_handle;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_A;
|
||||
@ -498,7 +500,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
uint16_t length = 0;
|
||||
const uint8_t *prf_char;
|
||||
|
||||
ESP_LOGI(GATTS_TAG, "ADD_CHAR_EVT, status %d, attr_handle %d, service_handle %d",
|
||||
ESP_LOGI(GATTS_TAG, "Characteristic add, status %d, attr_handle %d, service_handle %d",
|
||||
param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_handle = param->add_char.attr_handle;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.len = ESP_UUID_LEN_16;
|
||||
@ -520,30 +522,28 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
break;
|
||||
}
|
||||
case ESP_GATTS_ADD_CHAR_DESCR_EVT:
|
||||
|
||||
gl_profile_tab[PROFILE_A_APP_ID].descr_handle = param->add_char_descr.attr_handle;
|
||||
ESP_LOGI(GATTS_TAG, "ADD_DESCR_EVT, status %d, attr_handle %d, service_handle %d",
|
||||
ESP_LOGI(GATTS_TAG, "Descriptor add, status %d, attr_handle %d, service_handle %d",
|
||||
param->add_char_descr.status, param->add_char_descr.attr_handle, param->add_char_descr.service_handle);
|
||||
break;
|
||||
case ESP_GATTS_DELETE_EVT:
|
||||
break;
|
||||
case ESP_GATTS_START_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "SERVICE_START_EVT, status %d, service_handle %d",
|
||||
ESP_LOGI(GATTS_TAG, "Service start, status %d, service_handle %d",
|
||||
param->start.status, param->start.service_handle);
|
||||
break;
|
||||
case ESP_GATTS_STOP_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CONNECT_EVT: {
|
||||
ESP_LOGI(GATTS_TAG, "ESP_GATTS_CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:",
|
||||
param->connect.conn_id,
|
||||
param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2],
|
||||
param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5]);
|
||||
ESP_LOGI(GATTS_TAG, "Connected, conn_id %d, remote "ESP_BD_ADDR_STR"",
|
||||
param->connect.conn_id, ESP_BD_ADDR_HEX(param->connect.remote_bda));
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id = param->connect.conn_id;
|
||||
break;
|
||||
}
|
||||
case ESP_GATTS_DISCONNECT_EVT:
|
||||
is_connect = false;
|
||||
ESP_LOGI(GATTS_TAG, "ESP_GATTS_DISCONNECT_EVT");
|
||||
ESP_LOGI(GATTS_TAG, "Disconnected, remote "ESP_BD_ADDR_STR", reason 0x%02x",
|
||||
ESP_BD_ADDR_HEX(param->disconnect.remote_bda), param->disconnect.reason);
|
||||
esp_ble_gap_start_advertising(&adv_params);
|
||||
break;
|
||||
case ESP_GATTS_CONF_EVT:
|
||||
@ -661,6 +661,10 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK( ret );
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
memcpy(test_device_name, esp_bluedroid_get_example_name(), ESP_BLE_ADV_NAME_LEN_MAX);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
|
@ -99,7 +99,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
|
||||
switch (event) {
|
||||
case ESP_GATTC_REG_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "GATTC application register, status %d, app_id %d", param->reg.status, param->reg.app_id);
|
||||
ESP_LOGI(GATTC_TAG, "GATT client register, status %d, app_id %d, gattc_if %d", param->reg.status, param->reg.app_id, gattc_if);
|
||||
esp_err_t scan_ret = esp_ble_gap_set_scan_params(&ble_scan_params);
|
||||
if (scan_ret){
|
||||
ESP_LOGE(GATTC_TAG, "set scan params error, error code = %x", scan_ret);
|
||||
@ -121,7 +121,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
ESP_LOGE(GATTC_TAG, "Open failed, status %d", p_data->open.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Open successfully, mtu %u", p_data->open.mtu);
|
||||
ESP_LOGI(GATTC_TAG, "Open successfully, MTU %u", p_data->open.mtu);
|
||||
break;
|
||||
case ESP_GATTC_DIS_SRVC_CMPL_EVT:
|
||||
if (param->dis_srvc_cmpl.status != ESP_GATT_OK){
|
||||
@ -132,10 +132,10 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
esp_ble_gattc_search_service(gattc_if, param->dis_srvc_cmpl.conn_id, &remote_filter_service_uuid);
|
||||
break;
|
||||
case ESP_GATTC_CFG_MTU_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "MTU exchange, status %d, MTU %d, conn_id %d", param->cfg_mtu.status, param->cfg_mtu.mtu, param->cfg_mtu.conn_id);
|
||||
ESP_LOGI(GATTC_TAG, "MTU exchange, status %d, MTU %d", param->cfg_mtu.status, param->cfg_mtu.mtu);
|
||||
break;
|
||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||
ESP_LOGI(GATTC_TAG, "Search result, conn_id = %x, is primary service %d", p_data->search_res.conn_id, p_data->search_res.is_primary);
|
||||
ESP_LOGI(GATTC_TAG, "Service search result, conn_id = %x, is primary service %d", p_data->search_res.conn_id, p_data->search_res.is_primary);
|
||||
ESP_LOGI(GATTC_TAG, "start handle %d, end handle %d, current handle value %d", p_data->search_res.start_handle, p_data->search_res.end_handle, p_data->search_res.srvc_id.inst_id);
|
||||
if (p_data->search_res.srvc_id.uuid.len == ESP_UUID_LEN_16 && p_data->search_res.srvc_id.uuid.uuid.uuid16 == REMOTE_SERVICE_UUID) {
|
||||
ESP_LOGI(GATTC_TAG, "Service found");
|
||||
@ -366,7 +366,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
ESP_LOGI(GATTC_TAG, "Device found %s", remote_device_name);
|
||||
if (connect == false) {
|
||||
connect = true;
|
||||
ESP_LOGI(GATTC_TAG, "Connect to "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(scan_result->scan_rst.bda));
|
||||
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
menu "Example 'GATT SECURITY CLIENT' Config"
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int
|
||||
default 80
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
@ -51,7 +51,7 @@ static esp_bt_uuid_t remote_filter_service_uuid = {
|
||||
|
||||
static bool connect = false;
|
||||
static bool get_service = false;
|
||||
static const char remote_device_name[] = "ESP_BLE_SECURITY";
|
||||
static char remote_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "ESP_BLE_SECURITY";
|
||||
|
||||
static esp_ble_scan_params_t ble_scan_params = {
|
||||
.scan_type = BLE_SCAN_TYPE_ACTIVE,
|
||||
@ -167,33 +167,32 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
|
||||
switch (event) {
|
||||
case ESP_GATTC_REG_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "REG_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "GATT client register, status %u, app_id %u, gattc_if %d", p_data->reg.status, p_data->reg.app_id, gattc_if);
|
||||
esp_ble_gap_config_local_privacy(true);
|
||||
break;
|
||||
case ESP_GATTC_CONNECT_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "Connected, conn_id %d, remote "ESP_BD_ADDR_STR"", p_data->connect.conn_id,
|
||||
ESP_BD_ADDR_HEX(p_data->connect.remote_bda));
|
||||
break;
|
||||
case ESP_GATTC_OPEN_EVT:
|
||||
if (param->open.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "open failed, error status = %x", p_data->open.status);
|
||||
ESP_LOGE(GATTC_TAG, "Open failed, status %x", p_data->open.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "open success");
|
||||
ESP_LOGI(GATTC_TAG, "Open successfully, MTU %d", p_data->open.mtu);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id = p_data->open.conn_id;
|
||||
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
||||
esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, p_data->open.conn_id);
|
||||
if (mtu_ret){
|
||||
ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
|
||||
}
|
||||
break;
|
||||
case ESP_GATTC_CFG_MTU_EVT:
|
||||
if (param->cfg_mtu.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG,"config mtu failed, error status = %x", param->cfg_mtu.status);
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_CFG_MTU_EVT, Status %d, MTU %d, conn_id %d", param->cfg_mtu.status, param->cfg_mtu.mtu, param->cfg_mtu.conn_id);
|
||||
ESP_LOGI(GATTC_TAG, "MTU exchange, status %d, MTU %d", param->cfg_mtu.status, param->cfg_mtu.mtu);
|
||||
esp_ble_gattc_search_service(gattc_if, param->cfg_mtu.conn_id, &remote_filter_service_uuid);
|
||||
break;
|
||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||
ESP_LOGI(GATTC_TAG, "SEARCH RES: conn_id = %x is primary service %d", p_data->search_res.conn_id, p_data->search_res.is_primary);
|
||||
ESP_LOGI(GATTC_TAG, "Service search result, conn_id %x, is primary service %d", p_data->search_res.conn_id, p_data->search_res.is_primary);
|
||||
ESP_LOGI(GATTC_TAG, "start handle %d end handle %d current handle value %d", p_data->search_res.start_handle, p_data->search_res.end_handle, p_data->search_res.srvc_id.inst_id);
|
||||
if (p_data->search_res.srvc_id.uuid.len == ESP_UUID_LEN_16 && p_data->search_res.srvc_id.uuid.uuid.uuid16 == REMOTE_SERVICE_UUID) {
|
||||
ESP_LOGI(GATTC_TAG, "UUID16: %x", p_data->search_res.srvc_id.uuid.uuid.uuid16);
|
||||
@ -205,7 +204,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
}
|
||||
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||
if (p_data->search_cmpl.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "search service failed, error status = %x", p_data->search_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Service search failed, status %x", p_data->search_cmpl.status);
|
||||
break;
|
||||
}
|
||||
if(p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_REMOTE_DEVICE) {
|
||||
@ -215,6 +214,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
} else {
|
||||
ESP_LOGI(GATTC_TAG, "unknown service source");
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Service search complete");
|
||||
if (get_service){
|
||||
uint16_t count = 0;
|
||||
uint16_t offset = 0;
|
||||
@ -271,92 +271,95 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
break;
|
||||
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
||||
if (p_data->reg_for_notify.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "reg for notify failed, error status = %x", p_data->reg_for_notify.status);
|
||||
ESP_LOGE(GATTC_TAG, "Notification register failed, status %x", p_data->reg_for_notify.status);
|
||||
break;
|
||||
} else {
|
||||
ESP_LOGI(GATTC_TAG, "Notification register successfully");
|
||||
}
|
||||
|
||||
uint16_t count = 0;
|
||||
uint16_t offset = 0;
|
||||
uint16_t notify_en = 1;
|
||||
esp_gatt_status_t ret_status = esp_ble_gattc_get_attr_count(gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
ESP_GATT_DB_DESCRIPTOR,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_start_handle,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_end_handle,
|
||||
p_data->reg_for_notify.handle,
|
||||
&count);
|
||||
if (ret_status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_attr_count error, %d", __LINE__);
|
||||
break;
|
||||
}
|
||||
|
||||
uint16_t count = 0;
|
||||
uint16_t offset = 0;
|
||||
uint16_t notify_en = 1;
|
||||
esp_gatt_status_t ret_status = esp_ble_gattc_get_attr_count(gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
ESP_GATT_DB_DESCRIPTOR,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_start_handle,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_end_handle,
|
||||
p_data->reg_for_notify.handle,
|
||||
&count);
|
||||
if (ret_status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_attr_count error, %d", __LINE__);
|
||||
if (count > 0) {
|
||||
descr_elem_result = malloc(sizeof(esp_gattc_descr_elem_t) * count);
|
||||
if (!descr_elem_result){
|
||||
ESP_LOGE(GATTC_TAG, "malloc error, gattc no mem");
|
||||
break;
|
||||
}
|
||||
if (count > 0){
|
||||
descr_elem_result = malloc(sizeof(esp_gattc_descr_elem_t) * count);
|
||||
if (!descr_elem_result){
|
||||
ESP_LOGE(GATTC_TAG, "malloc error, gattc no mem");
|
||||
break;
|
||||
}else{
|
||||
ret_status = esp_ble_gattc_get_all_descr(gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
p_data->reg_for_notify.handle,
|
||||
descr_elem_result,
|
||||
&count,
|
||||
offset);
|
||||
if (ret_status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_all_descr error, %d", __LINE__);
|
||||
free(descr_elem_result);
|
||||
descr_elem_result = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (descr_elem_result[i].uuid.len == ESP_UUID_LEN_16 && descr_elem_result[i].uuid.uuid.uuid16 == ESP_GATT_UUID_CHAR_CLIENT_CONFIG)
|
||||
{
|
||||
esp_ble_gattc_write_char_descr (gattc_if,
|
||||
}else{
|
||||
ret_status = esp_ble_gattc_get_all_descr(gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
descr_elem_result[i].handle,
|
||||
sizeof(notify_en),
|
||||
(uint8_t *)¬ify_en,
|
||||
ESP_GATT_WRITE_TYPE_RSP,
|
||||
ESP_GATT_AUTH_REQ_NONE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
p_data->reg_for_notify.handle,
|
||||
descr_elem_result,
|
||||
&count,
|
||||
offset);
|
||||
if (ret_status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_all_descr error, %d", __LINE__);
|
||||
free(descr_elem_result);
|
||||
descr_elem_result = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (descr_elem_result[i].uuid.len == ESP_UUID_LEN_16 && descr_elem_result[i].uuid.uuid.uuid16 == ESP_GATT_UUID_CHAR_CLIENT_CONFIG)
|
||||
{
|
||||
esp_ble_gattc_write_char_descr (gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
descr_elem_result[i].handle,
|
||||
sizeof(notify_en),
|
||||
(uint8_t *)¬ify_en,
|
||||
ESP_GATT_WRITE_TYPE_RSP,
|
||||
ESP_GATT_AUTH_REQ_NONE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(descr_elem_result);
|
||||
descr_elem_result = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_NOTIFY_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_NOTIFY_EVT, receive notify value:");
|
||||
ESP_LOGI(GATTC_TAG, "Notification received, value ");
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, p_data->notify.value, p_data->notify.value_len);
|
||||
break;
|
||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
||||
if (p_data->write.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "write descr failed, error status = %x", p_data->write.status);
|
||||
ESP_LOGE(GATTC_TAG, "Descriptor write failed, status %x", p_data->write.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "write descr success");
|
||||
ESP_LOGI(GATTC_TAG, "Descriptor write successfully");
|
||||
break;
|
||||
case ESP_GATTC_SRVC_CHG_EVT: {
|
||||
esp_bd_addr_t bda;
|
||||
memcpy(bda, p_data->srvc_chg.remote_bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_SRVC_CHG_EVT, bd_addr:");
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "Service change from "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(bda));
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_WRITE_CHAR_EVT:
|
||||
if (p_data->write.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "write char failed, error status = %x", p_data->write.status);
|
||||
ESP_LOGE(GATTC_TAG, "Characteristic write failed, status %x", p_data->write.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Write char success ");
|
||||
ESP_LOGI(GATTC_TAG, "Characteristic write successfully");
|
||||
break;
|
||||
case ESP_GATTC_DISCONNECT_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_DISCONNECT_EVT, reason = 0x%x", p_data->disconnect.reason);
|
||||
ESP_LOGI(GATTC_TAG, "Disconnected, remote "ESP_BD_ADDR_STR", reason 0x%02x",
|
||||
ESP_BD_ADDR_HEX(p_data->disconnect.remote_bda), p_data->disconnect.reason);
|
||||
connect = false;
|
||||
get_service = false;
|
||||
break;
|
||||
@ -372,9 +375,10 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
switch (event) {
|
||||
case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT:
|
||||
if (param->local_privacy_cmpl.status != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(GATTC_TAG, "config local privacy failed, error code =%x", param->local_privacy_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Local privacy config failed, status %x", param->local_privacy_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Local privacy config successfully");
|
||||
esp_err_t scan_ret = esp_ble_gap_set_scan_params(&ble_scan_params);
|
||||
if (scan_ret){
|
||||
ESP_LOGE(GATTC_TAG, "set scan params error, error code = %x", scan_ret);
|
||||
@ -389,27 +393,27 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
|
||||
//scan start complete event to indicate scan start successfully or failed
|
||||
if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(GATTC_TAG, "scan start failed, error status = %x", param->scan_start_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Scanning start failed, status %x", param->scan_start_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Scan start success");
|
||||
ESP_LOGI(GATTC_TAG, "Scanning start successfully");
|
||||
break;
|
||||
case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */
|
||||
/* Call the following function to input the passkey which is displayed on the remote device */
|
||||
//esp_ble_passkey_reply(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, true, 0x00);
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Passkey request");
|
||||
break;
|
||||
case ESP_GAP_BLE_OOB_REQ_EVT: {
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_OOB_REQ_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "OOB request");
|
||||
uint8_t tk[16] = {1}; //If you paired with OOB, both devices need to use the same tk
|
||||
esp_ble_oob_req_reply(param->ble_security.ble_req.bd_addr, tk, sizeof(tk));
|
||||
break;
|
||||
}
|
||||
case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Local identity root");
|
||||
break;
|
||||
case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_LOCAL_ER_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Local encryption root");
|
||||
break;
|
||||
case ESP_GAP_BLE_SEC_REQ_EVT:
|
||||
/* send the positive(true) security response to the peer device to accept the security request.
|
||||
@ -420,28 +424,25 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
/* The app will receive this evt when the IO has DisplayYesNO capability and the peer device IO also has DisplayYesNo capability.
|
||||
show the passkey number to the user to confirm it with the number displayed by peer device. */
|
||||
esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, true);
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_NC_REQ_EVT, the passkey Notify number:%" PRIu32, param->ble_security.key_notif.passkey);
|
||||
ESP_LOGI(GATTC_TAG, "Numeric Comparison request, passkey %" PRIu32, param->ble_security.key_notif.passkey);
|
||||
break;
|
||||
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: ///the app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
|
||||
///show the passkey number to the user to input it in the peer device.
|
||||
ESP_LOGI(GATTC_TAG, "The passkey Notify number:%06" PRIu32, param->ble_security.key_notif.passkey);
|
||||
ESP_LOGI(GATTC_TAG, "Passkey notify, passkey %06" PRIu32, param->ble_security.key_notif.passkey);
|
||||
break;
|
||||
case ESP_GAP_BLE_KEY_EVT:
|
||||
//shows the ble key info share with peer device to the user.
|
||||
ESP_LOGI(GATTC_TAG, "key type = %s", esp_key_type_to_str(param->ble_security.ble_key.key_type));
|
||||
ESP_LOGI(GATTC_TAG, "Key exchanged, key_type %s", esp_key_type_to_str(param->ble_security.ble_key.key_type));
|
||||
break;
|
||||
case ESP_GAP_BLE_AUTH_CMPL_EVT: {
|
||||
esp_bd_addr_t bd_addr;
|
||||
memcpy(bd_addr, param->ble_security.auth_cmpl.bd_addr, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "remote BD_ADDR: %08x%04x",\
|
||||
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
|
||||
(bd_addr[4] << 8) + bd_addr[5]);
|
||||
ESP_LOGI(GATTC_TAG, "address type = %d", param->ble_security.auth_cmpl.addr_type);
|
||||
ESP_LOGI(GATTC_TAG, "pair status = %s",param->ble_security.auth_cmpl.success ? "success" : "fail");
|
||||
ESP_LOGI(GATTC_TAG, "Authentication complete, addr_type %d, addr "ESP_BD_ADDR_STR"",
|
||||
param->ble_security.auth_cmpl.addr_type, ESP_BD_ADDR_HEX(bd_addr));
|
||||
if (!param->ble_security.auth_cmpl.success) {
|
||||
ESP_LOGI(GATTC_TAG, "fail reason = 0x%x",param->ble_security.auth_cmpl.fail_reason);
|
||||
ESP_LOGI(GATTC_TAG, "Pairing failed, reason 0x%x",param->ble_security.auth_cmpl.fail_reason);
|
||||
} else {
|
||||
ESP_LOGI(GATTC_TAG, "auth mode = %s",esp_auth_req_to_str(param->ble_security.auth_cmpl.auth_mode));
|
||||
ESP_LOGI(GATTC_TAG, "Pairing successfully, auth mode %s", esp_auth_req_to_str(param->ble_security.auth_cmpl.auth_mode));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -449,21 +450,18 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
|
||||
switch (scan_result->scan_rst.search_evt) {
|
||||
case ESP_GAP_SEARCH_INQ_RES_EVT:
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, scan_result->scan_rst.bda, 6);
|
||||
ESP_LOGI(GATTC_TAG, "Searched Adv Data Len %d, Scan Response Len %d", scan_result->scan_rst.adv_data_len, scan_result->scan_rst.scan_rsp_len);
|
||||
adv_name = esp_ble_resolve_adv_data_by_type(scan_result->scan_rst.ble_adv,
|
||||
scan_result->scan_rst.adv_data_len + scan_result->scan_rst.scan_rsp_len,
|
||||
ESP_BLE_AD_TYPE_NAME_CMPL,
|
||||
&adv_name_len);
|
||||
ESP_LOGI(GATTC_TAG, "Searched Device Name Len %d", adv_name_len);
|
||||
ESP_LOGI(GATTC_TAG, "Scan result, device "ESP_BD_ADDR_STR", name len %u", ESP_BD_ADDR_HEX(scan_result->scan_rst.bda), adv_name_len);
|
||||
ESP_LOG_BUFFER_CHAR(GATTC_TAG, adv_name, adv_name_len);
|
||||
ESP_LOGI(GATTC_TAG, " ");
|
||||
if (adv_name != NULL) {
|
||||
if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
|
||||
ESP_LOGI(GATTC_TAG, "searched device %s", remote_device_name);
|
||||
ESP_LOGI(GATTC_TAG, "Device found %s", remote_device_name);
|
||||
if (connect == false) {
|
||||
connect = true;
|
||||
ESP_LOGI(GATTC_TAG, "connect to the remote device.");
|
||||
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
|
||||
}
|
||||
@ -480,10 +478,10 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
|
||||
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
|
||||
if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(GATTC_TAG, "Scan stop failed, error status = %x", param->scan_stop_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Scanning stop failed, status %x", param->scan_stop_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Stop scan successfully");
|
||||
ESP_LOGI(GATTC_TAG, "Scanning stop successfully");
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -532,6 +530,10 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK( ret );
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
memcpy(remote_device_name, esp_bluedroid_get_example_name(), sizeof(remote_device_name));
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
|
@ -0,0 +1,15 @@
|
||||
menu "Example 'GATT SECURITY SERVER' Config"
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int
|
||||
default 80
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
@ -25,7 +25,6 @@
|
||||
#define HEART_PROFILE_NUM 1
|
||||
#define HEART_PROFILE_APP_IDX 0
|
||||
#define ESP_HEART_RATE_APP_ID 0x55
|
||||
#define EXAMPLE_DEVICE_NAME "ESP_BLE_SECURITY"
|
||||
#define HEART_RATE_SVC_INST_ID 0
|
||||
|
||||
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 0x40
|
||||
@ -33,6 +32,7 @@
|
||||
#define ADV_CONFIG_FLAG (1 << 0)
|
||||
#define SCAN_RSP_CONFIG_FLAG (1 << 1)
|
||||
|
||||
static char example_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "ESP_BLE_SECURITY";
|
||||
static uint8_t adv_config_done = 0;
|
||||
|
||||
static uint16_t heart_rate_handle_table[HRS_IDX_NB];
|
||||
@ -268,11 +268,10 @@ static void show_bonded_devices(void)
|
||||
return;
|
||||
}
|
||||
esp_ble_get_bond_device_list(&dev_num, dev_list);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number : %d", dev_num);
|
||||
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices list : %d", dev_num);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number %d", dev_num);
|
||||
for (int i = 0; i < dev_num; i++) {
|
||||
ESP_LOG_BUFFER_HEX(GATTS_TABLE_TAG, (void *)dev_list[i].bd_addr, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "[%u] addr_type %u, addr "ESP_BD_ADDR_STR"",
|
||||
i, dev_list[i].bd_addr_type, ESP_BD_ADDR_HEX(dev_list[i].bd_addr));
|
||||
}
|
||||
|
||||
free(dev_list);
|
||||
@ -319,33 +318,33 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
||||
//advertising start complete event to indicate advertising start successfully or failed
|
||||
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "advertising start failed, error status = %x", param->adv_start_cmpl.status);
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "Advertising start failed, status %x", param->adv_start_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "advertising start success");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Advertising start successfully");
|
||||
break;
|
||||
case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Passkey request");
|
||||
/* Call the following function to input the passkey which is displayed on the remote device */
|
||||
//esp_ble_passkey_reply(heart_rate_profile_tab[HEART_PROFILE_APP_IDX].remote_bda, true, 0x00);
|
||||
break;
|
||||
case ESP_GAP_BLE_OOB_REQ_EVT: {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_OOB_REQ_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "OOB request");
|
||||
uint8_t tk[16] = {1}; //If you paired with OOB, both devices need to use the same tk
|
||||
esp_ble_oob_req_reply(param->ble_security.ble_req.bd_addr, tk, sizeof(tk));
|
||||
break;
|
||||
}
|
||||
case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Local identity root");
|
||||
break;
|
||||
case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_LOCAL_ER_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Local encryption root");
|
||||
break;
|
||||
case ESP_GAP_BLE_NC_REQ_EVT:
|
||||
/* The app will receive this evt when the IO has DisplayYesNO capability and the peer device IO also has DisplayYesNo capability.
|
||||
show the passkey number to the user to confirm it with the number displayed by peer device. */
|
||||
esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, true);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_NC_REQ_EVT, the passkey Notify number:%" PRIu32, param->ble_security.key_notif.passkey);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Numeric Comparison request, passkey %" PRIu32, param->ble_security.key_notif.passkey);
|
||||
break;
|
||||
case ESP_GAP_BLE_SEC_REQ_EVT:
|
||||
/* send the positive(true) security response to the peer device to accept the security request.
|
||||
@ -354,41 +353,36 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
break;
|
||||
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: ///the app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
|
||||
///show the passkey number to the user to input it in the peer device.
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "The passkey Notify number:%06" PRIu32, param->ble_security.key_notif.passkey);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Passkey notify, passkey %06" PRIu32, param->ble_security.key_notif.passkey);
|
||||
break;
|
||||
case ESP_GAP_BLE_KEY_EVT:
|
||||
//shows the ble key info share with peer device to the user.
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "key type = %s", esp_key_type_to_str(param->ble_security.ble_key.key_type));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Key exchanged, key_type %s", esp_key_type_to_str(param->ble_security.ble_key.key_type));
|
||||
break;
|
||||
case ESP_GAP_BLE_AUTH_CMPL_EVT: {
|
||||
esp_bd_addr_t bd_addr;
|
||||
memcpy(bd_addr, param->ble_security.auth_cmpl.bd_addr, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "remote BD_ADDR: %08x%04x",\
|
||||
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
|
||||
(bd_addr[4] << 8) + bd_addr[5]);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "address type = %d", param->ble_security.auth_cmpl.addr_type);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "pair status = %s",param->ble_security.auth_cmpl.success ? "success" : "fail");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Authentication complete, addr_type %u, addr "ESP_BD_ADDR_STR"",
|
||||
param->ble_security.auth_cmpl.addr_type, ESP_BD_ADDR_HEX(bd_addr));
|
||||
if(!param->ble_security.auth_cmpl.success) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "fail reason = 0x%x",param->ble_security.auth_cmpl.fail_reason);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Pairing failed, reason 0x%x",param->ble_security.auth_cmpl.fail_reason);
|
||||
} else {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "auth mode = %s",esp_auth_req_to_str(param->ble_security.auth_cmpl.auth_mode));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Pairing successfully, auth_mode %s",esp_auth_req_to_str(param->ble_security.auth_cmpl.auth_mode));
|
||||
}
|
||||
show_bonded_devices();
|
||||
break;
|
||||
}
|
||||
case ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT: {
|
||||
ESP_LOGD(GATTS_TABLE_TAG, "ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT status = %d", param->remove_bond_dev_cmpl.status);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_REMOVE_BOND_DEV");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "-----ESP_GAP_BLE_REMOVE_BOND_DEV----");
|
||||
ESP_LOG_BUFFER_HEX(GATTS_TABLE_TAG, (void *)param->remove_bond_dev_cmpl.bd_addr, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "------------------------------------");
|
||||
ESP_LOGD(GATTS_TABLE_TAG, "Bond device remove, status %d, device "ESP_BD_ADDR_STR"",
|
||||
param->remove_bond_dev_cmpl.status, ESP_BD_ADDR_HEX(param->remove_bond_dev_cmpl.bd_addr));
|
||||
break;
|
||||
}
|
||||
case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT:
|
||||
if (param->local_privacy_cmpl.status != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "config local privacy failed, error status = %x", param->local_privacy_cmpl.status);
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "Local privacy config failed, status %x", param->local_privacy_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Local privacy config successfully");
|
||||
|
||||
esp_err_t ret = esp_ble_gap_config_adv_data(&heart_rate_adv_config);
|
||||
if (ret){
|
||||
@ -416,7 +410,9 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
ESP_LOGV(GATTS_TABLE_TAG, "event = %x",event);
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
esp_ble_gap_set_device_name(EXAMPLE_DEVICE_NAME);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "GATT server register, status %d, app_id %d, gatts_if %d",
|
||||
param->reg.status, param->reg.app_id, gatts_if);
|
||||
esp_ble_gap_set_device_name(example_device_name);
|
||||
//generate a resolvable random address
|
||||
esp_ble_gap_config_local_privacy(true);
|
||||
esp_ble_gatts_create_attr_tab(heart_rate_gatt_db, gatts_if,
|
||||
@ -425,7 +421,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
case ESP_GATTS_READ_EVT:
|
||||
break;
|
||||
case ESP_GATTS_WRITE_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_WRITE_EVT, write value:");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Characteristic write, value ");
|
||||
ESP_LOG_BUFFER_HEX(GATTS_TABLE_TAG, param->write.value, param->write.len);
|
||||
break;
|
||||
case ESP_GATTS_EXEC_WRITE_EVT:
|
||||
@ -443,12 +439,14 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
case ESP_GATTS_STOP_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CONNECT_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONNECT_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Connected, conn_id %u, remote "ESP_BD_ADDR_STR"",
|
||||
param->connect.conn_id, ESP_BD_ADDR_HEX(param->connect.remote_bda));
|
||||
/* start security connect with peer device when receive the connect event sent by the master */
|
||||
esp_ble_set_encryption(param->connect.remote_bda, ESP_BLE_SEC_ENCRYPT_MITM);
|
||||
break;
|
||||
case ESP_GATTS_DISCONNECT_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x%x", param->disconnect.reason);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Disconnected, remote "ESP_BD_ADDR_STR", reason 0x%x",
|
||||
ESP_BD_ADDR_HEX(param->disconnect.remote_bda), param->disconnect.reason);
|
||||
/* start advertising again when missing the connect */
|
||||
esp_ble_gap_start_advertising(&heart_rate_adv_params);
|
||||
break;
|
||||
@ -463,18 +461,18 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
case ESP_GATTS_CONGEST_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CREAT_ATTR_TAB_EVT: {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "The number handle = %x",param->add_attr_tab.num_handle);
|
||||
if (param->create.status == ESP_GATT_OK){
|
||||
if(param->add_attr_tab.num_handle == HRS_IDX_NB) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Attribute table create successfully, num_handle %x", param->add_attr_tab.num_handle);
|
||||
memcpy(heart_rate_handle_table, param->add_attr_tab.handles,
|
||||
sizeof(heart_rate_handle_table));
|
||||
esp_ble_gatts_start_service(heart_rate_handle_table[HRS_IDX_SVC]);
|
||||
}else{
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "Create attribute table abnormally, num_handle (%d) doesn't equal to HRS_IDX_NB(%d)",
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "Attribute table create abnormally, num_handle (%d) doesn't equal to HRS_IDX_NB(%d)",
|
||||
param->add_attr_tab.num_handle, HRS_IDX_NB);
|
||||
}
|
||||
}else{
|
||||
ESP_LOGE(GATTS_TABLE_TAG, " Create attribute table failed, error code = %x", param->create.status);
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "Attribute table create failed, error code = %x", param->create.status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -525,6 +523,10 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK( ret );
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
memcpy(example_device_name, esp_bluedroid_get_example_name(), ESP_BLE_ADV_NAME_LEN_MAX);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
|
@ -315,7 +315,7 @@ void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble
|
||||
static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "GATTS application register, status %d, app_id %d", param->reg.status, param->reg.app_id);
|
||||
ESP_LOGI(GATTS_TAG, "GATT server register, status %d, app_id %d, gatts_if %d", param->reg.status, param->reg.app_id, gatts_if);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.is_primary = true;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.inst_id = 0x00;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
@ -417,7 +417,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
example_exec_write_event_env(&a_prepare_write_env, param);
|
||||
break;
|
||||
case ESP_GATTS_MTU_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "MTU exchange, conn_id %d, MTU %d", param->mtu.conn_id, param->mtu.mtu);
|
||||
ESP_LOGI(GATTS_TAG, "MTU exchange, MTU %d", param->mtu.mtu);
|
||||
break;
|
||||
case ESP_GATTS_UNREG_EVT:
|
||||
break;
|
||||
@ -516,7 +516,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "GATTS application register, status %d, app_id %d", param->reg.status, param->reg.app_id);
|
||||
ESP_LOGI(GATTS_TAG, "GATT server register, status %d, app_id %d, gatts_if %d", param->reg.status, param->reg.app_id, gatts_if);
|
||||
gl_profile_tab[PROFILE_B_APP_ID].service_id.is_primary = true;
|
||||
gl_profile_tab[PROFILE_B_APP_ID].service_id.id.inst_id = 0x00;
|
||||
gl_profile_tab[PROFILE_B_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
@ -587,7 +587,7 @@ static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
example_exec_write_event_env(&b_prepare_write_env, param);
|
||||
break;
|
||||
case ESP_GATTS_MTU_EVT:
|
||||
ESP_LOGI(GATTS_TAG, "MTU exchange, conn_id %d, MTU %d", param->mtu.conn_id, param->mtu.mtu);
|
||||
ESP_LOGI(GATTS_TAG, "MTU exchange, MTU %d", param->mtu.mtu);
|
||||
break;
|
||||
case ESP_GATTS_UNREG_EVT:
|
||||
break;
|
||||
|
@ -0,0 +1,15 @@
|
||||
menu "Example 'BLE50 SECURITY GATT CLIENT' Config"
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int
|
||||
default 100
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
@ -54,7 +54,7 @@ static esp_bt_uuid_t remote_filter_service_uuid = {
|
||||
|
||||
static bool connect = false;
|
||||
static bool get_service = false;
|
||||
static const char remote_device_name[] = "ESP_BLE50_SERVER";
|
||||
static char remote_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "ESP_BLE50_SERVER";
|
||||
|
||||
static esp_ble_ext_scan_params_t ext_scan_params = {
|
||||
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
|
||||
@ -200,43 +200,39 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
|
||||
switch (event) {
|
||||
case ESP_GATTC_REG_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "REG_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "GATT client register, status %u", p_data->reg.status);
|
||||
esp_ble_gap_config_local_privacy(true);
|
||||
break;
|
||||
case ESP_GATTC_CONNECT_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Connected, conn_id %d, remote "ESP_BD_ADDR_STR"", p_data->connect.conn_id,
|
||||
ESP_BD_ADDR_HEX(p_data->connect.remote_bda));
|
||||
break;
|
||||
case ESP_GATTC_OPEN_EVT:
|
||||
if (param->open.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "open failed, error status = %x", p_data->open.status);
|
||||
ESP_LOGE(GATTC_TAG, "Open failed, status %x", p_data->open.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "open success");
|
||||
ESP_LOGI(GATTC_TAG, "Open successfully, MTU %d", p_data->open.mtu);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id = p_data->open.conn_id;
|
||||
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
||||
esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, p_data->open.conn_id);
|
||||
if (mtu_ret){
|
||||
ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
|
||||
}
|
||||
break;
|
||||
case ESP_GATTC_CFG_MTU_EVT:
|
||||
if (param->cfg_mtu.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG,"config mtu failed, error status = %x", param->cfg_mtu.status);
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_CFG_MTU_EVT, Status %d, MTU %d, conn_id %d", param->cfg_mtu.status, param->cfg_mtu.mtu, param->cfg_mtu.conn_id);
|
||||
ESP_LOGI(GATTC_TAG, "MTU exchange, status %d, MTU %d, conn_id %d", param->cfg_mtu.status, param->cfg_mtu.mtu, param->cfg_mtu.conn_id);
|
||||
break;
|
||||
case ESP_GATTC_DIS_SRVC_CMPL_EVT:
|
||||
if (param->dis_srvc_cmpl.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "discover service failed, status %d", param->dis_srvc_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Service discover failed, status %d", param->dis_srvc_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "discover service complete conn_id %d", param->dis_srvc_cmpl.conn_id);
|
||||
ESP_LOGI(GATTC_TAG, "Service discover complete, conn_id %d", param->dis_srvc_cmpl.conn_id);
|
||||
esp_ble_gattc_search_service(gattc_if, param->cfg_mtu.conn_id, &remote_filter_service_uuid);
|
||||
break;
|
||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||
ESP_LOGI(GATTC_TAG, "SEARCH RES: conn_id = %x is primary service %d", p_data->search_res.conn_id, p_data->search_res.is_primary);
|
||||
ESP_LOGI(GATTC_TAG, "Service search result, conn_id %x, is primary service %d", p_data->search_res.conn_id, p_data->search_res.is_primary);
|
||||
ESP_LOGI(GATTC_TAG, "start handle %d end handle %d current handle value %d", p_data->search_res.start_handle, p_data->search_res.end_handle, p_data->search_res.srvc_id.inst_id);
|
||||
if (p_data->search_res.srvc_id.uuid.len == ESP_UUID_LEN_16 && p_data->search_res.srvc_id.uuid.uuid.uuid16 == REMOTE_SERVICE_UUID) {
|
||||
ESP_LOGI(GATTC_TAG, "UUID16: %x", p_data->search_res.srvc_id.uuid.uuid.uuid16);
|
||||
@ -248,9 +244,10 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
}
|
||||
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||
if (p_data->search_cmpl.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "search service failed, error status = %x", p_data->search_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Service search failed, status %x", p_data->search_cmpl.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Service search complete");
|
||||
if(p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_REMOTE_DEVICE) {
|
||||
ESP_LOGI(GATTC_TAG, "Get service information from remote device");
|
||||
} else if (p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_NVS_FLASH) {
|
||||
@ -313,91 +310,90 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
break;
|
||||
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
||||
if (p_data->reg_for_notify.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "reg for notify failed, error status = %x", p_data->reg_for_notify.status);
|
||||
ESP_LOGE(GATTC_TAG, "Notification register failed, status %x", p_data->reg_for_notify.status);
|
||||
break;
|
||||
}
|
||||
|
||||
uint16_t count = 0;
|
||||
uint16_t offset = 0;
|
||||
uint16_t notify_en = 1;
|
||||
esp_gatt_status_t ret_status = esp_ble_gattc_get_attr_count(gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
ESP_GATT_DB_DESCRIPTOR,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_start_handle,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_end_handle,
|
||||
p_data->reg_for_notify.handle,
|
||||
&count);
|
||||
if (ret_status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_attr_count error, %d", __LINE__);
|
||||
}
|
||||
if (count > 0){
|
||||
descr_elem_result = malloc(sizeof(esp_gattc_descr_elem_t) * count);
|
||||
if (!descr_elem_result){
|
||||
ESP_LOGE(GATTC_TAG, "malloc error, gattc no mem");
|
||||
break;
|
||||
}else{
|
||||
ret_status = esp_ble_gattc_get_all_descr(gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
p_data->reg_for_notify.handle,
|
||||
descr_elem_result,
|
||||
&count,
|
||||
offset);
|
||||
if (ret_status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_all_descr error, %d", __LINE__);
|
||||
free(descr_elem_result);
|
||||
descr_elem_result = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (descr_elem_result[i].uuid.len == ESP_UUID_LEN_16 && descr_elem_result[i].uuid.uuid.uuid16 == ESP_GATT_UUID_CHAR_CLIENT_CONFIG)
|
||||
{
|
||||
esp_ble_gattc_write_char_descr (gattc_if,
|
||||
ESP_LOGI(GATTC_TAG, "Notification register successfully");
|
||||
uint16_t count = 0;
|
||||
uint16_t offset = 0;
|
||||
uint16_t notify_en = 1;
|
||||
esp_gatt_status_t ret_status = esp_ble_gattc_get_attr_count(gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
ESP_GATT_DB_DESCRIPTOR,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_start_handle,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_end_handle,
|
||||
p_data->reg_for_notify.handle,
|
||||
&count);
|
||||
if (ret_status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_attr_count error, %d", __LINE__);
|
||||
}
|
||||
if (count > 0){
|
||||
descr_elem_result = malloc(sizeof(esp_gattc_descr_elem_t) * count);
|
||||
if (!descr_elem_result){
|
||||
ESP_LOGE(GATTC_TAG, "malloc error, gattc no mem");
|
||||
break;
|
||||
}else{
|
||||
ret_status = esp_ble_gattc_get_all_descr(gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
descr_elem_result[i].handle,
|
||||
sizeof(notify_en),
|
||||
(uint8_t *)¬ify_en,
|
||||
ESP_GATT_WRITE_TYPE_RSP,
|
||||
ESP_GATT_AUTH_REQ_NONE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
p_data->reg_for_notify.handle,
|
||||
descr_elem_result,
|
||||
&count,
|
||||
offset);
|
||||
if (ret_status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_all_descr error, %d", __LINE__);
|
||||
free(descr_elem_result);
|
||||
descr_elem_result = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (descr_elem_result[i].uuid.len == ESP_UUID_LEN_16 && descr_elem_result[i].uuid.uuid.uuid16 == ESP_GATT_UUID_CHAR_CLIENT_CONFIG)
|
||||
{
|
||||
esp_ble_gattc_write_char_descr (gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
descr_elem_result[i].handle,
|
||||
sizeof(notify_en),
|
||||
(uint8_t *)¬ify_en,
|
||||
ESP_GATT_WRITE_TYPE_RSP,
|
||||
ESP_GATT_AUTH_REQ_NONE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(descr_elem_result);
|
||||
descr_elem_result = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_NOTIFY_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_NOTIFY_EVT, receive notify value:");
|
||||
ESP_LOGI(GATTC_TAG, "Notification received, value ");
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, p_data->notify.value, p_data->notify.value_len);
|
||||
break;
|
||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
||||
if (p_data->write.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "write descr failed, error status = %x", p_data->write.status);
|
||||
ESP_LOGE(GATTC_TAG, "Descriptor write failed, status %x", p_data->write.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "write descr success");
|
||||
ESP_LOGI(GATTC_TAG, "Descriptor write successfully");
|
||||
break;
|
||||
case ESP_GATTC_SRVC_CHG_EVT: {
|
||||
esp_bd_addr_t bda;
|
||||
memcpy(bda, p_data->srvc_chg.remote_bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_SRVC_CHG_EVT, bd_addr:");
|
||||
ESP_LOG_BUFFER_HEX(GATTC_TAG, bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "Service change from "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(bda));
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_WRITE_CHAR_EVT:
|
||||
if (p_data->write.status != ESP_GATT_OK){
|
||||
ESP_LOGE(GATTC_TAG, "write char failed, error status = %x", p_data->write.status);
|
||||
ESP_LOGE(GATTC_TAG, "Characteristic write failed, status %x", p_data->write.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Write char success ");
|
||||
ESP_LOGI(GATTC_TAG, "Characteristic Write successfully");
|
||||
break;
|
||||
case ESP_GATTC_DISCONNECT_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_DISCONNECT_EVT, reason = 0x%x", p_data->disconnect.reason);
|
||||
ESP_LOGI(GATTC_TAG, "Disconnected, remote "ESP_BD_ADDR_STR", reason 0x%02x",
|
||||
ESP_BD_ADDR_HEX(p_data->disconnect.remote_bda), p_data->disconnect.reason);
|
||||
connect = false;
|
||||
get_service = false;
|
||||
break;
|
||||
@ -411,17 +407,17 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
switch (event) {
|
||||
case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT:
|
||||
if (param->local_privacy_cmpl.status != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(GATTC_TAG, "config local privacy failed, error code =%x", param->local_privacy_cmpl.status);
|
||||
ESP_LOGE(GATTC_TAG, "Local privacy config failed, status %x", param->local_privacy_cmpl.status);
|
||||
break;
|
||||
}
|
||||
esp_err_t scan_ret = esp_ble_gap_set_ext_scan_params(&ext_scan_params);
|
||||
if (scan_ret){
|
||||
ESP_LOGE(GATTC_TAG, "set extend scan params error, error code = %x", scan_ret);
|
||||
ESP_LOGE(GATTC_TAG, "Set extend scan params error, error code = %x", scan_ret);
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT: {
|
||||
if (param->set_ext_scan_params.status != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(GATTC_TAG, "extend scan parameters set failed, error status = %x", param->set_ext_scan_params.status);
|
||||
ESP_LOGE(GATTC_TAG, "Extend scan parameters set failed, error status = %x", param->set_ext_scan_params.status);
|
||||
break;
|
||||
}
|
||||
//the unit of the duration is second
|
||||
@ -430,27 +426,27 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
}
|
||||
case ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT:
|
||||
if (param->ext_scan_start.status != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(GATTC_TAG, "scan start failed, error status = %x", param->ext_scan_start.status);
|
||||
ESP_LOGE(GATTC_TAG, "Extended scanning start failed, status %x", param->ext_scan_start.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Scan start success");
|
||||
ESP_LOGI(GATTC_TAG, "Extended scanning start successfully");
|
||||
break;
|
||||
case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */
|
||||
/* Call the following function to input the passkey which is displayed on the remote device */
|
||||
//esp_ble_passkey_reply(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, true, 0x00);
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Passkey request");
|
||||
break;
|
||||
case ESP_GAP_BLE_OOB_REQ_EVT: {
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_OOB_REQ_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "OOB request");
|
||||
uint8_t tk[16] = {1}; //If you paired with OOB, both devices need to use the same tk
|
||||
esp_ble_oob_req_reply(param->ble_security.ble_req.bd_addr, tk, sizeof(tk));
|
||||
break;
|
||||
}
|
||||
case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Local identity root");
|
||||
break;
|
||||
case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_LOCAL_ER_EVT");
|
||||
ESP_LOGI(GATTC_TAG, "Local encryption root");
|
||||
break;
|
||||
case ESP_GAP_BLE_SEC_REQ_EVT:
|
||||
/* send the positive(true) security response to the peer device to accept the security request.
|
||||
@ -461,28 +457,25 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
/* The app will receive this evt when the IO has DisplayYesNO capability and the peer device IO also has DisplayYesNo capability.
|
||||
show the passkey number to the user to confirm it with the number displayed by peer device. */
|
||||
esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, true);
|
||||
ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_NC_REQ_EVT, the passkey Notify number:%" PRIu32, param->ble_security.key_notif.passkey);
|
||||
ESP_LOGI(GATTC_TAG, "Numeric Comparison request, passkey %" PRIu32, param->ble_security.key_notif.passkey);
|
||||
break;
|
||||
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: ///the app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
|
||||
///show the passkey number to the user to input it in the peer device.
|
||||
ESP_LOGI(GATTC_TAG, "The passkey Notify number:%06" PRIu32, param->ble_security.key_notif.passkey);
|
||||
ESP_LOGI(GATTC_TAG, "Passkey notify, passkey %06" PRIu32, param->ble_security.key_notif.passkey);
|
||||
break;
|
||||
case ESP_GAP_BLE_KEY_EVT:
|
||||
//shows the ble key info share with peer device to the user.
|
||||
ESP_LOGI(GATTC_TAG, "key type = %s", esp_key_type_to_str(param->ble_security.ble_key.key_type));
|
||||
ESP_LOGI(GATTC_TAG, "Key exchanged, key_type %s", esp_key_type_to_str(param->ble_security.ble_key.key_type));
|
||||
break;
|
||||
case ESP_GAP_BLE_AUTH_CMPL_EVT: {
|
||||
esp_bd_addr_t bd_addr;
|
||||
memcpy(bd_addr, param->ble_security.auth_cmpl.bd_addr, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTC_TAG, "remote BD_ADDR: %08x%04x",\
|
||||
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
|
||||
(bd_addr[4] << 8) + bd_addr[5]);
|
||||
ESP_LOGI(GATTC_TAG, "address type = %d", param->ble_security.auth_cmpl.addr_type);
|
||||
ESP_LOGI(GATTC_TAG, "pair status = %s",param->ble_security.auth_cmpl.success ? "success" : "fail");
|
||||
ESP_LOGI(GATTC_TAG, "Authentication complete, addr_type %d, addr "ESP_BD_ADDR_STR"",
|
||||
param->ble_security.auth_cmpl.addr_type, ESP_BD_ADDR_HEX(bd_addr));
|
||||
if (!param->ble_security.auth_cmpl.success) {
|
||||
ESP_LOGI(GATTC_TAG, "fail reason = 0x%x",param->ble_security.auth_cmpl.fail_reason);
|
||||
ESP_LOGI(GATTC_TAG, "Pairing failed, reason 0x%x",param->ble_security.auth_cmpl.fail_reason);
|
||||
} else {
|
||||
ESP_LOGI(GATTC_TAG, "auth mode = %s",esp_auth_req_to_str(param->ble_security.auth_cmpl.auth_mode));
|
||||
ESP_LOGI(GATTC_TAG, "Pairing successfully, auth mode %s",esp_auth_req_to_str(param->ble_security.auth_cmpl.auth_mode));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -490,9 +483,9 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
uint8_t *adv_name = NULL;
|
||||
uint8_t adv_name_len = 0;
|
||||
if(param->ext_adv_report.params.event_type & ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY) {
|
||||
ESP_LOGI(GATTC_TAG, "legacy adv, adv type 0x%x data len %d", param->ext_adv_report.params.event_type, param->ext_adv_report.params.adv_data_len);
|
||||
ESP_LOGI(GATTC_TAG, "Legacy adv, adv type 0x%x data len %d", param->ext_adv_report.params.event_type, param->ext_adv_report.params.adv_data_len);
|
||||
} else {
|
||||
ESP_LOGI(GATTC_TAG, "extend adv, adv type 0x%x data len %d", param->ext_adv_report.params.event_type, param->ext_adv_report.params.adv_data_len);
|
||||
ESP_LOGI(GATTC_TAG, "Extend adv, adv type 0x%x data len %d", param->ext_adv_report.params.event_type, param->ext_adv_report.params.adv_data_len);
|
||||
}
|
||||
adv_name = esp_ble_resolve_adv_data_by_type(param->ext_adv_report.params.adv_data,
|
||||
param->ext_adv_report.params.adv_data_len,
|
||||
@ -501,8 +494,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
if (!connect && strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
|
||||
connect = true;
|
||||
esp_ble_gap_stop_ext_scan();
|
||||
ESP_LOG_BUFFER_HEX("adv addr", param->ext_adv_report.params.addr, 6);
|
||||
ESP_LOG_BUFFER_CHAR("adv name", adv_name, adv_name_len);
|
||||
ESP_LOGI(GATTC_TAG, "Device found "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(param->ext_adv_report.params.addr));
|
||||
ESP_LOG_BUFFER_CHAR("Adv name", adv_name, adv_name_len);
|
||||
ESP_LOGI(GATTC_TAG, "Stop extend scan and create aux open, primary_phy %d secondary phy %d", param->ext_adv_report.params.primary_phy, param->ext_adv_report.params.secondly_phy);
|
||||
|
||||
esp_ble_gap_prefer_ext_connect_params_set(param->ext_adv_report.params.addr,
|
||||
@ -517,10 +510,10 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
}
|
||||
case ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT:
|
||||
if (param->ext_scan_stop.status != ESP_BT_STATUS_SUCCESS){
|
||||
ESP_LOGE(GATTC_TAG, "extend Scan stop failed, error status = %x", param->ext_scan_stop.status);
|
||||
ESP_LOGE(GATTC_TAG, "Scanning stop failed, status %x", param->ext_scan_stop.status);
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(GATTC_TAG, "Stop extend scan successfully");
|
||||
ESP_LOGI(GATTC_TAG, "Scanning stop successfully");
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -530,7 +523,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
|
||||
static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
|
||||
{
|
||||
ESP_LOGI(GATTC_TAG, "EVT %d, gattc if %d", event, gattc_if);
|
||||
ESP_LOGD(GATTC_TAG, "EVT %d, gattc if %d", event, gattc_if);
|
||||
|
||||
/* If event is register event, store the gattc_if for each profile */
|
||||
if (event == ESP_GATTC_REG_EVT) {
|
||||
@ -569,6 +562,10 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK( ret );
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
memcpy(remote_device_name, esp_bluedroid_get_example_name(), sizeof(remote_device_name));
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
|
@ -0,0 +1,15 @@
|
||||
menu "Example 'BLE50 SECURITY GATT SERVER' Config"
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int
|
||||
default 100
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
@ -29,9 +29,15 @@
|
||||
#define NUM_EXT_ADV_SET 1
|
||||
#define EXT_ADV_DURATION 0
|
||||
#define EXT_ADV_MAX_EVENTS 0
|
||||
#define EXT_ADV_NAME_LEN_OFFSET 10
|
||||
#define EXT_ADV_NAME_OFFSET 12
|
||||
|
||||
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 0x40
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
static uint16_t profile_handle_table[HRS_IDX_NB];
|
||||
|
||||
static uint8_t ext_adv_raw_data[] = {
|
||||
@ -239,9 +245,10 @@ static void show_bonded_devices(void)
|
||||
return;
|
||||
}
|
||||
esp_ble_get_bond_device_list(&dev_num, dev_list);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number : %d", dev_num);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number %d", dev_num);
|
||||
for (int i = 0; i < dev_num; i++) {
|
||||
ESP_LOG_BUFFER_HEX(GATTS_TABLE_TAG, (void *)dev_list[i].bd_addr, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "[%u] addr_type %u, addr "ESP_BD_ADDR_STR"",
|
||||
i, dev_list[i].bd_addr_type, ESP_BD_ADDR_HEX(dev_list[i].bd_addr));
|
||||
}
|
||||
|
||||
free(dev_list);
|
||||
@ -272,43 +279,44 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
{
|
||||
switch (event) {
|
||||
case ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG,"ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT status %d", param->ext_adv_set_params.status);
|
||||
ESP_LOGI(GATTS_TABLE_TAG,"Extended advertising params set, status %d", param->ext_adv_set_params.status);
|
||||
esp_ble_gap_config_ext_adv_data_raw(EXT_ADV_HANDLE, sizeof(ext_adv_raw_data), &ext_adv_raw_data[0]);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG,"ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT status %d", param->ext_adv_data_set.status);
|
||||
esp_ble_gap_ext_adv_start(NUM_EXT_ADV_SET, &ext_adv[0]);
|
||||
break;
|
||||
ESP_LOGI(GATTS_TABLE_TAG,"Extended advertising data set, status %d", param->ext_adv_data_set.status);
|
||||
esp_ble_gap_ext_adv_start(NUM_EXT_ADV_SET, &ext_adv[0]);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT, status = %d", param->ext_adv_data_set.status);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Extended advertising start, status %d", param->ext_adv_data_set.status);
|
||||
break;
|
||||
case ESP_GAP_BLE_ADV_TERMINATED_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_ADV_TERMINATED_EVT, status = %d", param->adv_terminate.status);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Extended advertising terminated, status %d", param->adv_terminate.status);
|
||||
if(param->adv_terminate.status == 0x00) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ADV successfully ended with a connection being created");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Advertising successfully ended with a connection being created");
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */
|
||||
/* Call the following function to input the passkey which is displayed on the remote device */
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Passkey request");
|
||||
//esp_ble_passkey_reply(heart_rate_profile_tab[HEART_PROFILE_APP_IDX].remote_bda, true, 0x00);
|
||||
break;
|
||||
case ESP_GAP_BLE_OOB_REQ_EVT: {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_OOB_REQ_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "OOB request");
|
||||
uint8_t tk[16] = {1}; //If you paired with OOB, both devices need to use the same tk
|
||||
esp_ble_oob_req_reply(param->ble_security.ble_req.bd_addr, tk, sizeof(tk));
|
||||
break;
|
||||
}
|
||||
case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Local identity root");
|
||||
break;
|
||||
case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_LOCAL_ER_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Local encryption root");
|
||||
break;
|
||||
case ESP_GAP_BLE_NC_REQ_EVT:
|
||||
/* The app will receive this evt when the IO has DisplayYesNO capability and the peer device IO also has DisplayYesNo capability.
|
||||
show the passkey number to the user to confirm it with the number displayed by peer device. */
|
||||
esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, true);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_NC_REQ_EVT, the passkey Notify number:%" PRIu32, param->ble_security.key_notif.passkey);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Numeric Comparison request, passkey %" PRIu32, param->ble_security.key_notif.passkey);
|
||||
break;
|
||||
case ESP_GAP_BLE_SEC_REQ_EVT:
|
||||
/* send the positive(true) security response to the peer device to accept the security request.
|
||||
@ -317,42 +325,39 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
break;
|
||||
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: ///the app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
|
||||
///show the passkey number to the user to input it in the peer device.
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "The passkey Notify number:%06" PRIu32, param->ble_security.key_notif.passkey);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Passkey notify, passkey %06" PRIu32, param->ble_security.key_notif.passkey);
|
||||
break;
|
||||
case ESP_GAP_BLE_KEY_EVT:
|
||||
//shows the ble key info share with peer device to the user.
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "key type = %s", esp_key_type_to_str(param->ble_security.ble_key.key_type));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Key exchanged, key_type %s", esp_key_type_to_str(param->ble_security.ble_key.key_type));
|
||||
if (param->ble_security.ble_key.key_type == ESP_LE_KEY_PID) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "peer addr "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(param->ble_security.ble_key.bd_addr));
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_AUTH_CMPL_EVT: {
|
||||
esp_bd_addr_t bd_addr;
|
||||
memcpy(bd_addr, param->ble_security.auth_cmpl.bd_addr, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "remote BD_ADDR: %08x%04x",\
|
||||
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
|
||||
(bd_addr[4] << 8) + bd_addr[5]);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "address type = %d", param->ble_security.auth_cmpl.addr_type);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "pair status = %s",param->ble_security.auth_cmpl.success ? "success" : "fail");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Authentication complete, addr_type %u, addr "ESP_BD_ADDR_STR"",
|
||||
param->ble_security.auth_cmpl.addr_type, ESP_BD_ADDR_HEX(bd_addr));
|
||||
if(!param->ble_security.auth_cmpl.success) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "fail reason = 0x%x",param->ble_security.auth_cmpl.fail_reason);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Pairing failed, reason 0x%x",param->ble_security.auth_cmpl.fail_reason);
|
||||
} else {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "auth mode = %s",esp_auth_req_to_str(param->ble_security.auth_cmpl.auth_mode));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Pairing successfully, auth_mode %s",esp_auth_req_to_str(param->ble_security.auth_cmpl.auth_mode));
|
||||
}
|
||||
show_bonded_devices();
|
||||
break;
|
||||
}
|
||||
case ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT: {
|
||||
ESP_LOGD(GATTS_TABLE_TAG, "ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT status = %d", param->remove_bond_dev_cmpl.status);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_REMOVE_BOND_DEV");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "-----ESP_GAP_BLE_REMOVE_BOND_DEV----");
|
||||
ESP_LOG_BUFFER_HEX(GATTS_TABLE_TAG, (void *)param->remove_bond_dev_cmpl.bd_addr, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "------------------------------------");
|
||||
ESP_LOGD(GATTS_TABLE_TAG, "Bond device remove, status %d, device "ESP_BD_ADDR_STR"",
|
||||
param->remove_bond_dev_cmpl.status, ESP_BD_ADDR_HEX(param->remove_bond_dev_cmpl.bd_addr));
|
||||
break;
|
||||
}
|
||||
case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT, tatus = %x", param->local_privacy_cmpl.status);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Local privacy config, status %x", param->local_privacy_cmpl.status);
|
||||
esp_ble_gap_ext_adv_set_params(EXT_ADV_HANDLE, &ext_adv_params_2M);
|
||||
break;
|
||||
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "update connection params status = %d, conn_int = %d, latency = %d, timeout = %d",
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Connection params update, status %d, conn_int %d, latency %d, timeout %d",
|
||||
param->update_conn_params.status,
|
||||
param->update_conn_params.conn_int,
|
||||
param->update_conn_params.latency,
|
||||
@ -368,16 +373,16 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
{
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_REG_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "GATT server register, status %d", param->reg.status);
|
||||
//generate a resolvable random address
|
||||
esp_ble_gap_config_local_privacy(true);
|
||||
esp_ble_gatts_create_attr_tab(gatt_db, gatts_if, HRS_IDX_NB, SVC_INST_ID);
|
||||
break;
|
||||
case ESP_GATTS_READ_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_READ_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Characteristic read");
|
||||
break;
|
||||
case ESP_GATTS_WRITE_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_WRITE_EVT, write value:");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Characteristic write, value ");
|
||||
ESP_LOG_BUFFER_HEX(GATTS_TABLE_TAG, param->write.value, param->write.len);
|
||||
break;
|
||||
case ESP_GATTS_EXEC_WRITE_EVT:
|
||||
@ -395,12 +400,14 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
case ESP_GATTS_STOP_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CONNECT_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONNECT_EVT");
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Connected, conn_id %u, remote "ESP_BD_ADDR_STR"",
|
||||
param->connect.conn_id, ESP_BD_ADDR_HEX(param->connect.remote_bda));
|
||||
/* start security connect with peer device when receive the connect event sent by the master */
|
||||
esp_ble_set_encryption(param->connect.remote_bda, ESP_BLE_SEC_ENCRYPT_MITM);
|
||||
break;
|
||||
case ESP_GATTS_DISCONNECT_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x%x", param->disconnect.reason);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Disconnected, remote "ESP_BD_ADDR_STR", reason 0x%x",
|
||||
ESP_BD_ADDR_HEX(param->disconnect.remote_bda), param->disconnect.reason);
|
||||
/* start advertising again when missing the connect */
|
||||
esp_ble_gap_ext_adv_start(NUM_EXT_ADV_SET, &ext_adv[0]);
|
||||
break;
|
||||
@ -415,22 +422,21 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
case ESP_GATTS_CONGEST_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CREAT_ATTR_TAB_EVT: {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "The number handle = %x",param->add_attr_tab.num_handle);
|
||||
if (param->create.status == ESP_GATT_OK){
|
||||
if(param->add_attr_tab.num_handle == HRS_IDX_NB) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Attribute table create successfully, num_handle %x", param->add_attr_tab.num_handle);
|
||||
memcpy(profile_handle_table, param->add_attr_tab.handles,
|
||||
sizeof(profile_handle_table));
|
||||
esp_ble_gatts_start_service(profile_handle_table[IDX_SVC]);
|
||||
esp_ble_gatts_start_service(profile_handle_table[IDX_SVC]);
|
||||
}else{
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "Create attribute table abnormally, num_handle (%d) doesn't equal to HRS_IDX_NB(%d)",
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "Attribute table create abnormally, num_handle (%d) doesn't equal to HRS_IDX_NB(%d)",
|
||||
param->add_attr_tab.num_handle, HRS_IDX_NB);
|
||||
}
|
||||
}else{
|
||||
ESP_LOGE(GATTS_TABLE_TAG, " Create attribute table failed, error code = %x", param->create.status);
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "Attribute table create failed, status %x", param->create.status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -477,6 +483,14 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK( ret );
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
uint8_t adv_name_len = ext_adv_raw_data[EXT_ADV_NAME_LEN_OFFSET] - 1;
|
||||
char *adv_name = esp_bluedroid_get_example_name();
|
||||
adv_name_len = MIN(adv_name_len, strlen(adv_name));
|
||||
memcpy(&ext_adv_raw_data[EXT_ADV_NAME_OFFSET], adv_name, adv_name_len);
|
||||
ext_adv_raw_data[EXT_ADV_NAME_LEN_OFFSET] = (adv_name_len + 1);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
|
@ -160,27 +160,33 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
switch (event) {
|
||||
case ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT, status %d", param->ext_adv_set_rand_addr.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising random address set, status %d, instance %u",
|
||||
param->ext_adv_set_rand_addr.status, param->ext_adv_set_rand_addr.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT, status %d", param->ext_adv_set_params.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising params set, status %d, instance %u",
|
||||
param->ext_adv_set_params.status, param->ext_adv_set_params.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT, status %d", param->ext_adv_data_set.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising data set, status %d, instance %u",
|
||||
param->ext_adv_data_set.status, param->ext_adv_data_set.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT, status %d", param->scan_rsp_set.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising scan response data set, status %d, instance %u",
|
||||
param->scan_rsp_set.status, param->scan_rsp_set.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT, status %d", param->ext_adv_start.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising start, status %d, instance_num %u",
|
||||
param->ext_adv_start.status, param->ext_adv_start.instance_num);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT, status %d", param->ext_adv_stop.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising stop, status %d, instance_num %u",
|
||||
param->ext_adv_stop.status, param->ext_adv_stop.instance_num);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -0,0 +1,15 @@
|
||||
menu "Example 'PERIODIC ADVERTISING' Config"
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int
|
||||
default 110
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
@ -47,6 +47,12 @@
|
||||
|
||||
#define EXT_ADV_HANDLE 0
|
||||
#define NUM_EXT_ADV 1
|
||||
#define EXT_ADV_NAME_LEN_OFFSET 6
|
||||
#define EXT_ADV_NAME_OFFSET 8
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
static SemaphoreHandle_t test_sem = NULL;
|
||||
|
||||
@ -99,39 +105,39 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
switch (event) {
|
||||
case ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT, status %d, instance %d", param->ext_adv_set_rand_addr.status, param->ext_adv_set_rand_addr.instance);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising random address set, status %d, instance %d", param->ext_adv_set_rand_addr.status, param->ext_adv_set_rand_addr.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT, status %d, instance %d", param->ext_adv_set_params.status, param->ext_adv_set_params.instance);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising params set, status %d, instance %d", param->ext_adv_set_params.status, param->ext_adv_set_params.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT, status %d, instance %d", param->ext_adv_data_set.status, param->ext_adv_data_set.instance);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising data set, status %d, instance %d", param->ext_adv_data_set.status, param->ext_adv_data_set.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT, status %d, instance %d", param->scan_rsp_set.status, param->scan_rsp_set.instance);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising scan response data set, status %d, instance %d", param->scan_rsp_set.status, param->scan_rsp_set.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT, status %d, instance numble %d", param->ext_adv_start.status, param->ext_adv_start.instance_num);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising start, status %d, instance numble %d", param->ext_adv_start.status, param->ext_adv_start.instance_num);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT, status %d, instance numble %d", param->ext_adv_stop.status, param->ext_adv_stop.instance_num);
|
||||
ESP_LOGI(LOG_TAG, "Extended advertising start, status %d, instance numble %d", param->ext_adv_stop.status, param->ext_adv_stop.instance_num);
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT, status %d, instance %d", param->peroid_adv_set_params.status, param->peroid_adv_set_params.instance);
|
||||
ESP_LOGI(LOG_TAG, "Periodic advertising params set, status %d, instance %d", param->peroid_adv_set_params.status, param->peroid_adv_set_params.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT, status %d, instance %d", param->period_adv_data_set.status, param->period_adv_data_set.instance);
|
||||
ESP_LOGI(LOG_TAG, "Periodic advertising data set, status %d, instance %d", param->period_adv_data_set.status, param->period_adv_data_set.instance);
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT, status %d, instance %d", param->period_adv_start.status, param->period_adv_start.instance);
|
||||
ESP_LOGI(LOG_TAG, "Periodic advertising start, status %d, instance %d", param->period_adv_start.status, param->period_adv_start.instance);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -150,6 +156,14 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK( ret );
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
uint8_t adv_name_len = raw_ext_adv_data_2m[EXT_ADV_NAME_LEN_OFFSET] - 1;
|
||||
char *adv_name = esp_bluedroid_get_example_name();
|
||||
adv_name_len = MIN(adv_name_len, strlen(adv_name));
|
||||
memcpy(&raw_ext_adv_data_2m[EXT_ADV_NAME_OFFSET], adv_name, adv_name_len);
|
||||
raw_ext_adv_data_2m[EXT_ADV_NAME_LEN_OFFSET] = (adv_name_len + 1);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
@ -0,0 +1,15 @@
|
||||
menu "Example 'PERIODIC SYNCHRONIZATION' Config"
|
||||
|
||||
config EXAMPLE_CI_ID
|
||||
int
|
||||
default 110
|
||||
help
|
||||
This config the example id for CI test. Only for internal used.
|
||||
|
||||
config EXAMPLE_CI_PIPELINE_ID
|
||||
int "The pipeline id for CI test"
|
||||
default 0
|
||||
help
|
||||
This config the pipeline id for CI test. Only for internal used.
|
||||
|
||||
endmenu
|
@ -48,6 +48,7 @@
|
||||
#define EXT_SCAN_DURATION 0
|
||||
#define EXT_SCAN_PERIOD 0
|
||||
|
||||
static char remote_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "ESP_MULTI_ADV_80MS";
|
||||
static SemaphoreHandle_t test_sem = NULL;
|
||||
|
||||
static esp_ble_ext_scan_params_t ext_scan_params = {
|
||||
@ -75,31 +76,31 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
switch (event) {
|
||||
case ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT, status %d", param->set_ext_scan_params.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended scanning params set, status %d", param->set_ext_scan_params.status);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT, status %d", param->ext_scan_start.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended scanning start, status %d", param->ext_scan_start.status);
|
||||
break;
|
||||
case ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT:
|
||||
xSemaphoreGive(test_sem);
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT, status %d", param->period_adv_stop.status);
|
||||
ESP_LOGI(LOG_TAG, "Extended scanning stop, status %d", param->period_adv_stop.status);
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT:
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT, status %d", param->period_adv_create_sync.status);
|
||||
ESP_LOGI(LOG_TAG, "Periodic advertising create sync, status %d", param->period_adv_create_sync.status);
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT:
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT, status %d", param->period_adv_sync_cancel.status);
|
||||
ESP_LOGI(LOG_TAG, "Periodic advertising sync cancel, status %d", param->period_adv_sync_cancel.status);
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT:
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT, status %d", param->period_adv_sync_term.status);
|
||||
ESP_LOGI(LOG_TAG, "Periodic advertising sync terminate, status %d", param->period_adv_sync_term.status);
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT:
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT, sync handle %d", param->periodic_adv_sync_lost.sync_handle);
|
||||
ESP_LOGI(LOG_TAG, "Periodic advertising sync lost, sync handle %d", param->periodic_adv_sync_lost.sync_handle);
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT:
|
||||
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT, status %d", param->periodic_adv_sync_estab.status);
|
||||
ESP_LOG_BUFFER_HEX("sync addr", param->periodic_adv_sync_estab.adv_addr, 6);
|
||||
ESP_LOGI(LOG_TAG, "Periodic advertising sync establish, status %d", param->periodic_adv_sync_estab.status);
|
||||
ESP_LOGI(LOG_TAG, "address "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(param->periodic_adv_sync_estab.adv_addr));
|
||||
ESP_LOGI(LOG_TAG, "sync handle %d sid %d perioic adv interval %d adv phy %d", param->periodic_adv_sync_estab.sync_handle,
|
||||
param->periodic_adv_sync_estab.sid,
|
||||
param->periodic_adv_sync_estab.period_adv_interval,
|
||||
@ -112,11 +113,11 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
param->ext_adv_report.params.adv_data_len,
|
||||
ESP_BLE_AD_TYPE_NAME_CMPL,
|
||||
&adv_name_len);
|
||||
if ((adv_name != NULL) && (memcmp(adv_name, "ESP_MULTI_ADV_80MS", adv_name_len) == 0) && !periodic_sync) {
|
||||
if ((adv_name != NULL) && (memcmp(adv_name, remote_device_name, adv_name_len) == 0) && !periodic_sync) {
|
||||
periodic_sync = true;
|
||||
char adv_temp_name[30] = {'0'};
|
||||
memcpy(adv_temp_name, adv_name, adv_name_len);
|
||||
ESP_LOGI(LOG_TAG, "Start create sync with the peer device %s", adv_temp_name);
|
||||
ESP_LOGI(LOG_TAG, "Create sync with the peer device %s", adv_temp_name);
|
||||
periodic_adv_sync_params.sid = param->ext_adv_report.params.sid;
|
||||
periodic_adv_sync_params.addr_type = param->ext_adv_report.params.addr_type;
|
||||
memcpy(periodic_adv_sync_params.addr, param->ext_adv_report.params.addr, sizeof(esp_bd_addr_t));
|
||||
@ -125,7 +126,7 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT:
|
||||
ESP_LOGI(LOG_TAG, "periodic adv report, sync handle %d data status %d data len %d rssi %d", param->period_adv_report.params.sync_handle,
|
||||
ESP_LOGI(LOG_TAG, "Periodic adv report, sync handle %d, data status %d, data len %d, rssi %d", param->period_adv_report.params.sync_handle,
|
||||
param->period_adv_report.params.data_status,
|
||||
param->period_adv_report.params.data_length,
|
||||
param->period_adv_report.params.rssi);
|
||||
@ -148,6 +149,10 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK( ret );
|
||||
|
||||
#if CONFIG_EXAMPLE_CI_PIPELINE_ID
|
||||
memcpy(remote_device_name, esp_bluedroid_get_example_name(), sizeof(remote_device_name));
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
Loading…
Reference in New Issue
Block a user