mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/fix_ble_robost_cashing_v5.2' into 'release/v5.2'
fix(bt/bluedroid): Fix BLE robost cashing config(backport v5.2) See merge request espressif/esp-idf!28201
This commit is contained in:
commit
2710c37d51
@ -221,7 +221,10 @@ config BT_GATTS_ROBUST_CACHING_ENABLED
|
||||
depends on BT_GATTS_ENABLE
|
||||
default n
|
||||
help
|
||||
This option enable gatt robust caching feature on server
|
||||
This option enables the GATT robust caching feature on the server.
|
||||
if turned on, the Client Supported Features characteristic, Database Hash characteristic,
|
||||
and Server Supported Features characteristic will be included in the GAP SERVICE.
|
||||
|
||||
|
||||
config BT_GATTS_DEVICE_NAME_WRITABLE
|
||||
bool "Allow to write device name by GATT clients"
|
||||
|
@ -122,6 +122,7 @@ BOOLEAN GATTS_NVRegister (const tGATT_APPL_INFO *p_cb_info)
|
||||
return status;
|
||||
}
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
static void gatt_update_for_database_change(void)
|
||||
{
|
||||
UINT8 i;
|
||||
@ -135,7 +136,7 @@ static void gatt_update_for_database_change(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function GATTS_CreateService
|
||||
@ -414,7 +415,9 @@ BOOLEAN GATTS_DeleteService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid, UINT16 svc_
|
||||
GATT_TRACE_DEBUG ("Delete a new service changed item - the service has not yet started");
|
||||
osi_free(fixed_queue_try_remove_from_queue(gatt_cb.pending_new_srv_start_q, p_buf));
|
||||
} else {
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
gatt_update_for_database_change();
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
if (gatt_cb.srv_chg_mode == GATTS_SEND_SERVICE_CHANGE_AUTO) {
|
||||
gatt_proc_srv_chg();
|
||||
}
|
||||
@ -527,7 +530,11 @@ tGATT_STATUS GATTS_StartService (tGATT_IF gatt_if, UINT16 service_handle,
|
||||
if ( (p_buf = gatt_sr_is_new_srv_chg(&p_list->asgn_range.app_uuid128,
|
||||
&p_list->asgn_range.svc_uuid,
|
||||
p_list->asgn_range.svc_inst)) != NULL) {
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
gatt_update_for_database_change();
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
|
||||
if (gatt_cb.srv_chg_mode == GATTS_SEND_SERVICE_CHANGE_AUTO) {
|
||||
gatt_proc_srv_chg();
|
||||
}
|
||||
|
@ -40,7 +40,13 @@
|
||||
#define BLE_GATT_CL_SUPP_FEAT_BITMASK 0x07
|
||||
|
||||
#define GATTP_MAX_NUM_INC_SVR 0
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
#define GATTP_MAX_CHAR_NUM 5
|
||||
#else
|
||||
#define GATTP_MAX_CHAR_NUM 2
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
|
||||
#define GATTP_MAX_ATTR_NUM (GATTP_MAX_CHAR_NUM * 2 + GATTP_MAX_NUM_INC_SVR + 1)
|
||||
#define GATTP_MAX_CHAR_VALUE_SIZE 50
|
||||
|
||||
@ -196,14 +202,15 @@ tGATT_STATUS gatt_proc_read (UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_READ_RE
|
||||
|
||||
GATT_TRACE_DEBUG("%s handle %x", __func__, p_data->handle);
|
||||
|
||||
UINT8 tcb_idx = GATT_GET_TCB_IDX(conn_id);
|
||||
tGATT_TCB *tcb = gatt_get_tcb_by_idx(tcb_idx);
|
||||
|
||||
if (p_data->is_long) {
|
||||
p_rsp->attr_value.offset = p_data->offset;
|
||||
}
|
||||
|
||||
p_rsp->attr_value.handle = p_data->handle;
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
|
||||
UINT8 tcb_idx = GATT_GET_TCB_IDX(conn_id);
|
||||
tGATT_TCB *tcb = gatt_get_tcb_by_idx(tcb_idx);
|
||||
|
||||
/* handle request for reading client supported features */
|
||||
if (p_data->handle == gatt_cb.handle_of_cl_supported_feat) {
|
||||
@ -229,7 +236,7 @@ tGATT_STATUS gatt_proc_read (UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_READ_RE
|
||||
memcpy(p_rsp->attr_value.value, &gatt_cb.gatt_sr_supported_feat_mask, 1);
|
||||
return GATT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
/* handle request for reading service changed des and the others */
|
||||
status = GATTS_GetAttributeValue(p_data->handle, &len, &value);
|
||||
if(status == GATT_SUCCESS && len > 0 && value) {
|
||||
@ -241,7 +248,7 @@ tGATT_STATUS gatt_proc_read (UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_READ_RE
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
static tGATT_STATUS gatt_sr_write_cl_supp_feat(UINT16 conn_id, tGATT_WRITE_REQ *p_data)
|
||||
{
|
||||
UINT8 val_new;
|
||||
@ -286,7 +293,7 @@ static tGATT_STATUS gatt_sr_write_cl_supp_feat(UINT16 conn_id, tGATT_WRITE_REQ *
|
||||
#endif
|
||||
return GATT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
/******************************************************************************
|
||||
**
|
||||
** Function gatt_proc_write_req
|
||||
@ -301,7 +308,7 @@ tGATT_STATUS gatt_proc_write_req(UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_WRI
|
||||
if(p_data->len > GATT_MAX_ATTR_LEN) {
|
||||
p_data->len = GATT_MAX_ATTR_LEN;
|
||||
}
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
if (p_data->handle == gatt_cb.handle_of_h_r) {
|
||||
return GATT_WRITE_NOT_PERMIT;
|
||||
}
|
||||
@ -317,7 +324,7 @@ tGATT_STATUS gatt_proc_write_req(UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_WRI
|
||||
if (p_data->handle == gatt_cb.handle_of_sr_supported_feat) {
|
||||
return GATT_WRITE_NOT_PERMIT;
|
||||
}
|
||||
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
return GATTS_SetAttributeValue(p_data->handle,
|
||||
p_data->len,
|
||||
p_data->value);
|
||||
@ -470,7 +477,7 @@ void gatt_profile_db_init (void)
|
||||
};
|
||||
|
||||
GATTS_AddCharDescriptor (service_handle, GATT_PERM_READ | GATT_PERM_WRITE , &descr_uuid, &attr_val, NULL);
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
/* add Client Supported Features characteristic */
|
||||
uuid.uu.uuid16 = GATT_UUID_CLIENT_SUP_FEAT;
|
||||
gatt_cb.handle_of_cl_supported_feat = GATTS_AddCharacteristic(service_handle, &uuid, GATT_PERM_READ | GATT_PERM_WRITE,
|
||||
@ -483,7 +490,7 @@ void gatt_profile_db_init (void)
|
||||
/* add Server Supported Features characteristic */
|
||||
uuid.uu.uuid16 = GATT_UUID_SERVER_SUP_FEAT;
|
||||
gatt_cb.handle_of_sr_supported_feat = GATTS_AddCharacteristic(service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ, NULL, NULL);
|
||||
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
/* start service */
|
||||
status = GATTS_StartService (gatt_cb.gatt_if, service_handle, GATTP_TRANSPORT_SUPPORTED );
|
||||
|
||||
@ -689,6 +696,7 @@ void GATT_ConfigServiceChangeCCC (BD_ADDR remote_bda, BOOLEAN enable, tBT_TRANSP
|
||||
gatt_cl_start_config_ccc(p_clcb);
|
||||
}
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function gatt_sr_is_cl_robust_caching_supported
|
||||
@ -700,14 +708,8 @@ void GATT_ConfigServiceChangeCCC (BD_ADDR remote_bda, BOOLEAN enable, tBT_TRANSP
|
||||
*******************************************************************************/
|
||||
static BOOLEAN gatt_sr_is_cl_robust_caching_supported(tGATT_TCB *p_tcb)
|
||||
{
|
||||
// Server robust caching not enabled
|
||||
if (!GATTS_ROBUST_CACHING_ENABLED) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (p_tcb->cl_supp_feat & BLE_GATT_CL_SUPP_FEAT_ROBUST_CACHING_BITMASK);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function gatt_sr_is_cl_change_aware
|
||||
@ -791,4 +793,5 @@ void gatt_sr_update_cl_status(tGATT_TCB *p_tcb, BOOLEAN chg_aware)
|
||||
|
||||
GATT_TRACE_DEBUG("%s status %d", __func__, chg_aware);
|
||||
}
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
#endif /* BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE */
|
||||
|
@ -1681,9 +1681,10 @@ static BOOLEAN gatts_proc_ind_ack(tGATT_TCB *p_tcb, UINT16 ack_handle)
|
||||
gatts_proc_srv_chg_ind_ack(p_tcb);
|
||||
/* there is no need to inform the application since srv chg is handled internally by GATT */
|
||||
continue_processing = FALSE;
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
/* after receiving ack of svc_chg_ind, reset client status */
|
||||
gatt_sr_update_cl_status(p_tcb, true);
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
}
|
||||
|
||||
gatts_chk_pending_ind(p_tcb);
|
||||
@ -1730,6 +1731,7 @@ void gatts_process_value_conf(tGATT_TCB *p_tcb, UINT8 op_code)
|
||||
}
|
||||
}
|
||||
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
static BOOLEAN gatts_handle_db_out_of_sync(tGATT_TCB *p_tcb, UINT8 op_code,
|
||||
UINT16 len, UINT8 *p_data)
|
||||
{
|
||||
@ -1809,6 +1811,7 @@ static BOOLEAN gatts_handle_db_out_of_sync(tGATT_TCB *p_tcb, UINT8 op_code,
|
||||
return should_ignore;
|
||||
}
|
||||
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function gatt_server_handle_client_req
|
||||
@ -1840,11 +1843,12 @@ void gatt_server_handle_client_req (tGATT_TCB *p_tcb, UINT8 op_code,
|
||||
}
|
||||
/* otherwise, ignore the pkt */
|
||||
} else {
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
// handle database out of sync
|
||||
if (gatts_handle_db_out_of_sync(p_tcb, op_code, len, p_data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
switch (op_code) {
|
||||
case GATT_REQ_READ_BY_GRP_TYPE: /* discover primary services */
|
||||
case GATT_REQ_FIND_TYPE_VALUE: /* discover service by UUID */
|
||||
|
@ -1090,9 +1090,9 @@ tGATT_TCB *gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport)
|
||||
p_tcb->transport = transport;
|
||||
}
|
||||
memcpy(p_tcb->peer_bda, bda, BD_ADDR_LEN);
|
||||
#if (GATTS_INCLUDED == TRUE)
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
gatt_sr_init_cl_status(p_tcb);
|
||||
#endif ///GATTS_INCLUDED == TRUE
|
||||
#endif /* GATTS_ROBUST_CACHING_ENABLED */
|
||||
}
|
||||
return p_tcb;
|
||||
}
|
||||
|
@ -539,6 +539,7 @@ typedef struct {
|
||||
tGATT_PROFILE_CLCB profile_clcb[GATT_MAX_APPS];
|
||||
#endif ///GATTS_INCLUDED == TRUE
|
||||
UINT16 handle_of_h_r; /* Handle of the handles reused characteristic value */
|
||||
#if GATTS_ROBUST_CACHING_ENABLED
|
||||
UINT16 handle_of_database_hash;
|
||||
UINT16 handle_of_cl_supported_feat;
|
||||
UINT16 handle_of_sr_supported_feat;
|
||||
@ -546,6 +547,7 @@ typedef struct {
|
||||
UINT8 gatt_sr_supported_feat_mask;
|
||||
UINT8 gatt_cl_supported_feat_mask;
|
||||
|
||||
#endif
|
||||
tGATT_APPL_INFO cb_info;
|
||||
|
||||
|
||||
|
@ -246,6 +246,10 @@ static const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB] =
|
||||
static void show_bonded_devices(void)
|
||||
{
|
||||
int dev_num = esp_ble_get_bond_device_num();
|
||||
if (dev_num == 0) {
|
||||
ESP_LOGI(EXAMPLE_TAG, "Bonded devices number zero\n");
|
||||
return;
|
||||
}
|
||||
|
||||
esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
|
||||
if (!dev_list) {
|
||||
@ -268,6 +272,10 @@ static void show_bonded_devices(void)
|
||||
static void __attribute__((unused)) remove_all_bonded_devices(void)
|
||||
{
|
||||
int dev_num = esp_ble_get_bond_device_num();
|
||||
if (dev_num == 0) {
|
||||
ESP_LOGI(EXAMPLE_TAG, "Bonded devices number zero\n");
|
||||
return;
|
||||
}
|
||||
|
||||
esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
|
||||
if (!dev_list) {
|
||||
|
@ -23,9 +23,6 @@
|
||||
#include "esp_gap_ble_api.h"
|
||||
#include "esp_gattc_api.h"
|
||||
|
||||
|
||||
/* Because current ESP IDF version doesn't support scan and adv simultaneously,
|
||||
* so iBeacon sender and receiver should not run simultaneously */
|
||||
#define IBEACON_SENDER 0
|
||||
#define IBEACON_RECEIVER 1
|
||||
#define IBEACON_MODE CONFIG_IBEACON_MODE
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -256,6 +256,10 @@ static char *esp_auth_req_to_str(esp_ble_auth_req_t auth_req)
|
||||
static void show_bonded_devices(void)
|
||||
{
|
||||
int dev_num = esp_ble_get_bond_device_num();
|
||||
if (dev_num == 0) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number zero\n");
|
||||
return;
|
||||
}
|
||||
|
||||
esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
|
||||
if (!dev_list) {
|
||||
@ -276,6 +280,10 @@ static void show_bonded_devices(void)
|
||||
static void __attribute__((unused)) remove_all_bonded_devices(void)
|
||||
{
|
||||
int dev_num = esp_ble_get_bond_device_num();
|
||||
if (dev_num == 0) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number zero\n");
|
||||
return;
|
||||
}
|
||||
|
||||
esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
|
||||
if (!dev_list) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -228,6 +228,10 @@ static char *esp_auth_req_to_str(esp_ble_auth_req_t auth_req)
|
||||
static void show_bonded_devices(void)
|
||||
{
|
||||
int dev_num = esp_ble_get_bond_device_num();
|
||||
if (dev_num == 0) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number zero\n");
|
||||
return;
|
||||
}
|
||||
|
||||
esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
|
||||
if (!dev_list) {
|
||||
@ -246,6 +250,10 @@ static void show_bonded_devices(void)
|
||||
static void __attribute__((unused)) remove_all_bonded_devices(void)
|
||||
{
|
||||
int dev_num = esp_ble_get_bond_device_num();
|
||||
if (dev_num == 0) {
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number zero\n");
|
||||
return;
|
||||
}
|
||||
|
||||
esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
|
||||
if (!dev_list) {
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "esp_system.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
|
||||
#define GATTS_SERVICE_UUID_TEST_A 0x00FF
|
||||
#define GATTS_CHAR_UUID_TEST_A 0xFF01
|
||||
#define GATTS_NUM_HANDLE_TEST_A 4
|
||||
@ -57,6 +56,9 @@
|
||||
|
||||
static const char remote_device_name[] = "ESP_GATTS_DEMO";
|
||||
|
||||
// record peer gatt server address
|
||||
esp_bd_addr_t peer_gatts_addr = {0};
|
||||
|
||||
typedef struct {
|
||||
uint8_t *prepare_buf;
|
||||
int prepare_len;
|
||||
@ -284,7 +286,17 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
connect = true;
|
||||
ESP_LOGI(COEX_TAG, "connect to the remote device %s", remote_device_name);
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gattc_open(gattc_profile_tab[GATTC_PROFILE_C_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
|
||||
|
||||
// Initiate GATT connection with the remote device,
|
||||
// If ble physical connection is set up, ESP_GATTS_CONNECT_EVT and ESP_GATTC_CONNECT_EVT event will come
|
||||
esp_ble_gattc_open(gattc_profile_tab[GATTC_PROFILE_C_APP_ID].gattc_if,
|
||||
scan_result->scan_rst.bda,
|
||||
scan_result->scan_rst.ble_addr_type,
|
||||
true);
|
||||
|
||||
// Update peer gatt server address
|
||||
memcpy(peer_gatts_addr, scan_result->scan_rst.bda, sizeof(esp_bd_addr_t));
|
||||
esp_log_buffer_hex("the remote device addr", peer_gatts_addr, sizeof(esp_bd_addr_t));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,6 +328,8 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
break;
|
||||
case ESP_GATTC_CONNECT_EVT: {
|
||||
ESP_LOGI(COEX_TAG, "ESP_GATTC_CONNECT_EVT conn_id %d, if %d", p_data->connect.conn_id, gattc_if);
|
||||
if (!memcmp(peer_gatts_addr, param->connect.remote_bda, sizeof(esp_bd_addr_t))) {
|
||||
// Update gattc_profile_tab if peer device is a gatt server
|
||||
gattc_profile_tab[GATTC_PROFILE_C_APP_ID].conn_id = p_data->connect.conn_id;
|
||||
memcpy(gattc_profile_tab[GATTC_PROFILE_C_APP_ID].remote_bda, p_data->connect.remote_bda, sizeof(esp_bd_addr_t));
|
||||
ESP_LOGI(COEX_TAG, "REMOTE BDA:");
|
||||
@ -324,6 +338,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
if (mtu_ret) {
|
||||
ESP_LOGE(COEX_TAG, "config MTU error, error code = %x", mtu_ret);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_OPEN_EVT:
|
||||
@ -521,8 +536,11 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
ESP_LOGI(COEX_TAG, "write char success ");
|
||||
break;
|
||||
case ESP_GATTC_DISCONNECT_EVT: {
|
||||
if (!memcmp(peer_gatts_addr, p_data->disconnect.remote_bda, sizeof(esp_bd_addr_t))) {
|
||||
// Update connect flag and get_server flag if peer device is a gatt server
|
||||
connect = false;
|
||||
get_server = false;
|
||||
}
|
||||
ESP_LOGI(COEX_TAG, "ESP_GATTC_DISCONNECT_EVT, reason = %d", p_data->disconnect.reason);
|
||||
break;
|
||||
}
|
||||
@ -531,7 +549,8 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
}
|
||||
}
|
||||
|
||||
static void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param) {
|
||||
static void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param)
|
||||
{
|
||||
esp_gatt_status_t status = ESP_GATT_OK;
|
||||
if (param->write.need_rsp) {
|
||||
if (param->write.is_prep) {
|
||||
@ -579,7 +598,8 @@ static void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *
|
||||
}
|
||||
}
|
||||
|
||||
static void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param) {
|
||||
static 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_log_buffer_hex(COEX_TAG, prepare_write_env->prepare_buf, prepare_write_env->prepare_len);
|
||||
} else {
|
||||
@ -592,7 +612,8 @@ static void example_exec_write_event_env(prepare_type_env_t *prepare_write_env,
|
||||
prepare_write_env->prepare_len = 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
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(COEX_TAG, "REGISTER_APP_EVT, status %d, app_id %d", param->reg.status, param->reg.app_id);
|
||||
@ -736,17 +757,23 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
param->start.status, param->start.service_handle);
|
||||
break;
|
||||
case ESP_GATTS_CONNECT_EVT: {
|
||||
|
||||
if (memcmp(peer_gatts_addr, param->connect.remote_bda, sizeof(esp_bd_addr_t))) {
|
||||
// If a BLE physical connection is established, both ESP_GATTS_CONNECT_EVT and ESP_GATTC_CONNECT_EVT events will occur.
|
||||
// Update the connection ID in the gatts_profile_tab only if the peer device is a GATT client.
|
||||
gatts_profile_tab[GATTS_PROFILE_A_APP_ID].conn_id = param->connect.conn_id;
|
||||
}
|
||||
ESP_LOGI(COEX_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]);
|
||||
gatts_profile_tab[GATTS_PROFILE_A_APP_ID].conn_id = param->connect.conn_id;
|
||||
break;
|
||||
}
|
||||
case ESP_GATTS_DISCONNECT_EVT:
|
||||
ESP_LOGI(COEX_TAG, "ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x%x", param->disconnect.reason);
|
||||
if (memcmp(peer_gatts_addr, param->disconnect.remote_bda, sizeof(esp_bd_addr_t))) {
|
||||
// If the peer device is a GATT client, restart advertising
|
||||
esp_ble_gap_start_advertising(&adv_params);
|
||||
}
|
||||
break;
|
||||
case ESP_GATTS_CONF_EVT:
|
||||
ESP_LOGI(COEX_TAG, "ESP_GATTS_CONF_EVT, status %d attr_handle %d", param->conf.status, param->conf.handle);
|
||||
@ -760,7 +787,8 @@ 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) {
|
||||
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(COEX_TAG, "REGISTER_APP_EVT, status %d, app_id %d", param->reg.status, param->reg.app_id);
|
||||
@ -882,7 +910,11 @@ static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
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]);
|
||||
if (memcmp(peer_gatts_addr, param->connect.remote_bda, sizeof(esp_bd_addr_t))) {
|
||||
// If a BLE physical connection is established, both ESP_GATTS_CONNECT_EVT and ESP_GATTC_CONNECT_EVT events will occur.
|
||||
// Update the connection ID in the gatts_profile_tab only if the peer device is a GATT client.
|
||||
gatts_profile_tab[GATTS_PROFILE_B_APP_ID].conn_id = param->connect.conn_id;
|
||||
}
|
||||
break;
|
||||
case ESP_GATTS_CONF_EVT:
|
||||
ESP_LOGI(COEX_TAG, "ESP_GATTS_CONF_EVT status %d attr_handle %d", param->conf.status, param->conf.handle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user