Merge branch 'bugfix/btdm_master_write_service_change_ccc' into 'master'
component/bt: Fix slave initiate service change ccc discovery procedure bug See merge request !847
This commit is contained in:
commit
6b3a559ee7
10 changed files with 298 additions and 29 deletions
|
@ -62,6 +62,10 @@ static void bta_gattc_cmpl_sendmsg(UINT16 conn_id, tGATTC_OPTYPE op,
|
||||||
static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg);
|
static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg);
|
||||||
static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda);
|
static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda);
|
||||||
static void bta_gattc_cong_cback (UINT16 conn_id, BOOLEAN congested);
|
static void bta_gattc_cong_cback (UINT16 conn_id, BOOLEAN congested);
|
||||||
|
static tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda, BOOLEAN *need_timer);
|
||||||
|
static void bta_gattc_wait4_service_change_ccc_cback (TIMER_LIST_ENT *p_tle);
|
||||||
|
static void bta_gattc_start_service_change_ccc_timer(UINT16 conn_id, BD_ADDR bda,UINT32 timeout_ms,
|
||||||
|
UINT8 timer_cnt, UINT8 last_status, TIMER_LIST_ENT *ccc_timer);
|
||||||
|
|
||||||
static tGATT_CBACK bta_gattc_cl_cback = {
|
static tGATT_CBACK bta_gattc_cl_cback = {
|
||||||
bta_gattc_conn_cback,
|
bta_gattc_conn_cback,
|
||||||
|
@ -1696,6 +1700,7 @@ static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg)
|
||||||
p_cb->state = BTA_GATTC_STATE_DISABLED;
|
p_cb->state = BTA_GATTC_STATE_DISABLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
** Function bta_gattc_conn_cback
|
** Function bta_gattc_conn_cback
|
||||||
|
@ -1710,20 +1715,54 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id,
|
||||||
tBT_TRANSPORT transport)
|
tBT_TRANSPORT transport)
|
||||||
{
|
{
|
||||||
tBTA_GATTC_DATA *p_buf;
|
tBTA_GATTC_DATA *p_buf;
|
||||||
|
BOOLEAN start_ccc_timer = FALSE;
|
||||||
|
tBTA_GATTC_CONN *p_conn = NULL;
|
||||||
|
tBTA_GATTC_FIND_SERVICE_CB result;
|
||||||
|
|
||||||
if (reason != 0) {
|
if (reason != 0) {
|
||||||
APPL_TRACE_WARNING("%s() - cif=%d connected=%d conn_id=%d reason=0x%04x",
|
APPL_TRACE_WARNING("%s() - cif=%d connected=%d conn_id=%d reason=0x%04x",
|
||||||
__FUNCTION__, gattc_if, connected, conn_id, reason);
|
__FUNCTION__, gattc_if, connected, conn_id, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (connected == TRUE){
|
||||||
|
p_conn = bta_gattc_conn_find_alloc(bda);
|
||||||
|
}
|
||||||
|
else if (connected == FALSE){
|
||||||
|
p_conn = bta_gattc_conn_find(bda);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_conn == NULL){
|
||||||
|
APPL_TRACE_ERROR("p_conn is NULL in %s\n", __func__);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((transport == BT_TRANSPORT_LE) && (connected == TRUE) && (p_conn != NULL) \
|
||||||
|
&& (p_conn->service_change_ccc_written == FALSE) && (p_conn->ccc_timer_used == FALSE)){
|
||||||
|
result = bta_gattc_register_service_change_notify(conn_id, bda, &start_ccc_timer);
|
||||||
|
if (start_ccc_timer == TRUE){
|
||||||
|
TIMER_LIST_ENT *ccc_timer = &(p_conn->service_change_ccc_timer);
|
||||||
|
/* start a 1000ms timer to wait for service discovery finished */
|
||||||
|
bta_gattc_start_service_change_ccc_timer(conn_id, bda, 1000, 0, result, ccc_timer);
|
||||||
|
p_conn->ccc_timer_used = TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Has written service change ccc; or service change ccc doesn't exist in remote device's gatt database */
|
||||||
|
p_conn->service_change_ccc_written = TRUE;
|
||||||
|
p_conn->ccc_timer_used = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if ((transport == BT_TRANSPORT_LE) && (connected == FALSE) && (p_conn != NULL)){
|
||||||
|
p_conn->service_change_ccc_written = FALSE;
|
||||||
|
if (p_conn->ccc_timer_used == TRUE){
|
||||||
|
GKI_freebuf((void *)p_conn->service_change_ccc_timer.param);
|
||||||
|
bta_sys_stop_timer(&(p_conn->service_change_ccc_timer));
|
||||||
|
p_conn->ccc_timer_used = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bt_bdaddr_t bdaddr;
|
bt_bdaddr_t bdaddr;
|
||||||
bdcpy(bdaddr.address, bda);
|
bdcpy(bdaddr.address, bda);
|
||||||
/*
|
|
||||||
if (connected)
|
|
||||||
btif_debug_conn_state(bdaddr, BTIF_DEBUG_CONNECTED, GATT_CONN_UNKNOWN);
|
|
||||||
else
|
|
||||||
btif_debug_conn_state(bdaddr, BTIF_DEBUG_DISCONNECTED, reason);
|
|
||||||
*/
|
|
||||||
if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL) {
|
if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL) {
|
||||||
memset(p_buf, 0, sizeof(tBTA_GATTC_DATA));
|
memset(p_buf, 0, sizeof(tBTA_GATTC_DATA));
|
||||||
|
|
||||||
|
@ -2241,5 +2280,219 @@ void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
|
||||||
(*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
|
(*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
** Function bta_gattc_start_service_change_ccc_timer
|
||||||
|
**
|
||||||
|
** Description start a timer to wait for service change ccc discovered
|
||||||
|
**
|
||||||
|
** Returns void
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
void bta_gattc_start_service_change_ccc_timer(UINT16 conn_id, BD_ADDR bda,UINT32 timeout_ms,
|
||||||
|
UINT8 timer_cnt, UINT8 last_status, TIMER_LIST_ENT *ccc_timer)
|
||||||
|
{
|
||||||
|
tBTA_GATTC_WAIT_CCC_TIMER *p_timer_param = (tBTA_GATTC_WAIT_CCC_TIMER*) GKI_getbuf(sizeof(tBTA_GATTC_WAIT_CCC_TIMER));
|
||||||
|
if (p_timer_param != NULL){
|
||||||
|
p_timer_param->conn_id = conn_id;
|
||||||
|
memcpy(p_timer_param->remote_bda, bda, sizeof(BD_ADDR));
|
||||||
|
p_timer_param->count = timer_cnt;
|
||||||
|
p_timer_param->last_status = last_status;
|
||||||
|
ccc_timer->param = (UINT32)p_timer_param;
|
||||||
|
ccc_timer->p_cback = (TIMER_CBACK *)&bta_gattc_wait4_service_change_ccc_cback;
|
||||||
|
bta_sys_start_timer(ccc_timer, 0, timeout_ms);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
APPL_TRACE_ERROR("%s, allocate p_timer_param failed\n", __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
** Function bta_gattc_register_service_change_notify
|
||||||
|
**
|
||||||
|
** Description Find remote device's gatt service change characteristic ccc's handle and write 2 to this
|
||||||
|
** this ccc. If not found, start a timer to wait for service discovery finished.
|
||||||
|
**
|
||||||
|
** Returns Return result of service change ccc service discovery result result and written operate result
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda, BOOLEAN *need_timer){
|
||||||
|
tBTA_GATTC_SERV *p_srcb = NULL;
|
||||||
|
tBTA_GATTC_CACHE *p_cache = NULL;
|
||||||
|
tBTA_GATT_ID result_id;
|
||||||
|
tBTA_GATT_ID *p_result = &result_id;
|
||||||
|
tBTA_GATTC_CACHE_ATTR *p_attr = NULL;
|
||||||
|
tGATT_STATUS write_status;
|
||||||
|
tGATT_VALUE ccc_value;
|
||||||
|
tBTA_GATTC_FIND_SERVICE_CB result;
|
||||||
|
BOOLEAN gatt_cache_found = FALSE;
|
||||||
|
BOOLEAN gatt_service_found = FALSE;
|
||||||
|
BOOLEAN gatt_service_change_found = FALSE;
|
||||||
|
BOOLEAN gatt_ccc_found = FALSE;
|
||||||
|
BOOLEAN start_find_ccc_timer = FALSE;
|
||||||
|
|
||||||
|
tBT_UUID gatt_service_uuid = {LEN_UUID_16, {UUID_SERVCLASS_GATT_SERVER}};
|
||||||
|
tBT_UUID gatt_service_change_uuid = {LEN_UUID_16, {GATT_UUID_GATT_SRV_CHGD}};
|
||||||
|
tBT_UUID gatt_ccc_uuid = {LEN_UUID_16, {GATT_UUID_CHAR_CLIENT_CONFIG}};
|
||||||
|
|
||||||
|
p_srcb = bta_gattc_find_srcb(remote_bda);
|
||||||
|
if ((p_srcb != NULL) && (p_srcb->p_srvc_cache != NULL)){
|
||||||
|
p_cache = p_srcb->p_srvc_cache;
|
||||||
|
gatt_cache_found = TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
start_find_ccc_timer = TRUE;
|
||||||
|
result = SERVICE_CHANGE_CACHE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* start to find gatt service */
|
||||||
|
if (gatt_cache_found == TRUE){
|
||||||
|
while (p_cache) {
|
||||||
|
if (bta_gattc_uuid_compare(&gatt_service_uuid, &p_cache->service_uuid.id.uuid, TRUE)) {
|
||||||
|
gatt_service_found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p_cache = p_cache->p_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
start_find_ccc_timer = TRUE;
|
||||||
|
result = SERVICE_CHANGE_CACHE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* start to find gatt service change characteristic */
|
||||||
|
if (gatt_service_found == TRUE){
|
||||||
|
p_attr = p_cache->p_attr;
|
||||||
|
|
||||||
|
while(p_attr){
|
||||||
|
bta_gattc_pack_attr_uuid(p_attr, &p_result->uuid);
|
||||||
|
if (bta_gattc_uuid_compare(&gatt_service_change_uuid, &p_result->uuid, TRUE)){
|
||||||
|
gatt_service_change_found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p_attr = p_attr->p_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (gatt_cache_found == TRUE){
|
||||||
|
/* Gatt service not found, start a timer to wait for service discovery */
|
||||||
|
start_find_ccc_timer = TRUE;
|
||||||
|
result = SERVICE_CHANGE_SERVICE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* start to find gatt service change characteristic ccc */
|
||||||
|
if (gatt_service_change_found == TRUE){
|
||||||
|
p_attr = p_attr->p_next;
|
||||||
|
|
||||||
|
while(p_attr && p_attr->attr_type != BTA_GATTC_ATTR_TYPE_CHAR){
|
||||||
|
bta_gattc_pack_attr_uuid(p_attr, &p_result->uuid);
|
||||||
|
if (bta_gattc_uuid_compare(&gatt_ccc_uuid, &p_result->uuid, TRUE)){
|
||||||
|
gatt_ccc_found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p_attr = p_attr->p_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (gatt_service_found ==TRUE){
|
||||||
|
/* Gatt service found, but service change char not found,
|
||||||
|
* Case1: remote device doesn't have service change char, we don't need to start a timer here to
|
||||||
|
* wait for service discovery
|
||||||
|
* Case2: remote device exist service change char, we have found gatt service, but have not found
|
||||||
|
* service change char, we need to start a timer here*/
|
||||||
|
start_find_ccc_timer = TRUE;
|
||||||
|
result = SERVICE_CHANGE_CHAR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gatt_ccc_found == TRUE){
|
||||||
|
ccc_value.handle = p_attr->attr_handle;
|
||||||
|
ccc_value.len = 2;
|
||||||
|
ccc_value.value[0] = GATT_CLT_CONFIG_INDICATION;
|
||||||
|
ccc_value.auth_req = GATT_AUTH_REQ_NONE;
|
||||||
|
write_status = GATTC_Write (conn_id, GATT_WRITE, &ccc_value);
|
||||||
|
if (write_status != GATT_SUCCESS) {
|
||||||
|
start_find_ccc_timer = TRUE;
|
||||||
|
result = SERVICE_CHANGE_WRITE_CCC_FAILED;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
start_find_ccc_timer = FALSE;
|
||||||
|
result = SERVICE_CHANGE_CCC_WRITTEN_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (gatt_service_change_found == TRUE){
|
||||||
|
/* Gatt service char found, but service change char ccc not found,
|
||||||
|
* Case1: remote device doesn't have service change char ccc, we don't need to start a timer here to
|
||||||
|
* wait for service discovery
|
||||||
|
* Case2: remote device exist service change char ccc, we have found gatt service change char, but have not found
|
||||||
|
* service change char ccc, we need to start a timer here*/
|
||||||
|
start_find_ccc_timer = TRUE;
|
||||||
|
result = SERVICE_CHANGE_CCC_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (need_timer != NULL){
|
||||||
|
*need_timer = start_find_ccc_timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
** Function bta_gattc_wait4_service_change_ccc_cback
|
||||||
|
**
|
||||||
|
** Description callback function of service_change_ccc_timer
|
||||||
|
**
|
||||||
|
** Returns None
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
static void bta_gattc_wait4_service_change_ccc_cback (TIMER_LIST_ENT *p_tle)
|
||||||
|
{
|
||||||
|
tBTA_GATTC_FIND_SERVICE_CB result;
|
||||||
|
BOOLEAN start_ccc_timer = FALSE;
|
||||||
|
UINT32 new_timeout;
|
||||||
|
|
||||||
|
tBTA_GATTC_WAIT_CCC_TIMER *p_timer_param = (tBTA_GATTC_WAIT_CCC_TIMER*) p_tle->param;
|
||||||
|
if (p_timer_param == NULL){
|
||||||
|
APPL_TRACE_ERROR("p_timer_param is NULL in %s\n", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tBTA_GATTC_CONN *p_conn = bta_gattc_conn_find(p_timer_param->remote_bda);
|
||||||
|
if (p_conn == NULL){
|
||||||
|
APPL_TRACE_ERROR("p_conn is NULL in %s\n", __func__);
|
||||||
|
GKI_freebuf(p_timer_param);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = bta_gattc_register_service_change_notify(p_timer_param->conn_id, p_timer_param->remote_bda, &start_ccc_timer);
|
||||||
|
/* If return SERVICE_CHANGE_CHAR_NOT_FOUND or SERVICE_CHANGE_CCC_NOT_FOUND twice, means remote device doesn't have
|
||||||
|
* service change char or ccc, stop timer */
|
||||||
|
if ((result == p_timer_param->last_status) \
|
||||||
|
&& ((result == SERVICE_CHANGE_CHAR_NOT_FOUND) || (result == SERVICE_CHANGE_CCC_NOT_FOUND))){
|
||||||
|
start_ccc_timer = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((start_ccc_timer == TRUE) && (p_timer_param->count < 10)){
|
||||||
|
TIMER_LIST_ENT *ccc_timer = &(p_conn->service_change_ccc_timer);
|
||||||
|
if (result == SERVICE_CHANGE_WRITE_CCC_FAILED){
|
||||||
|
/* retry to write service change ccc, needn't to add counter */
|
||||||
|
new_timeout = 200;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* retry to find service change ccc */
|
||||||
|
new_timeout = 1000;
|
||||||
|
p_timer_param->count ++;
|
||||||
|
}
|
||||||
|
bta_gattc_start_service_change_ccc_timer(p_timer_param->conn_id, p_timer_param->remote_bda, \
|
||||||
|
new_timeout, p_timer_param->count, result, ccc_timer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p_conn->ccc_timer_used = FALSE;
|
||||||
|
p_conn->service_change_ccc_written = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GKI_freebuf(p_timer_param);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif ///GATTC_INCLUDED == TRUE && BLE_INCLUDED == TRUE
|
#endif ///GATTC_INCLUDED == TRUE && BLE_INCLUDED == TRUE
|
|
@ -635,6 +635,14 @@ typedef union {
|
||||||
|
|
||||||
} tBTA_GATTS;
|
} tBTA_GATTS;
|
||||||
|
|
||||||
|
/* GATTC wait for service change ccc timer callback data */
|
||||||
|
typedef struct {
|
||||||
|
UINT16 conn_id;
|
||||||
|
BD_ADDR remote_bda;
|
||||||
|
UINT8 count;
|
||||||
|
UINT8 last_status;
|
||||||
|
}tBTA_GATTC_WAIT_CCC_TIMER;
|
||||||
|
|
||||||
/* GATTS enable callback function */
|
/* GATTS enable callback function */
|
||||||
typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
|
typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "bta_gatt_api.h"
|
#include "bta_gatt_api.h"
|
||||||
#include "bta_gattc_ci.h"
|
#include "bta_gattc_ci.h"
|
||||||
#include "bta_gattc_co.h"
|
#include "bta_gattc_co.h"
|
||||||
|
|
||||||
#include "gki.h"
|
#include "gki.h"
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -380,6 +379,9 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BOOLEAN in_use;
|
BOOLEAN in_use;
|
||||||
BD_ADDR remote_bda;
|
BD_ADDR remote_bda;
|
||||||
|
TIMER_LIST_ENT service_change_ccc_timer; /* wait for discovering remote device's service change ccc handle */
|
||||||
|
BOOLEAN ccc_timer_used; /* service_change_ccc_timer started */
|
||||||
|
BOOLEAN service_change_ccc_written; /* has written remote device's service change ccc */
|
||||||
} tBTA_GATTC_CONN;
|
} tBTA_GATTC_CONN;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -404,6 +406,16 @@ typedef struct {
|
||||||
UINT16 sdp_conn_id;
|
UINT16 sdp_conn_id;
|
||||||
} tBTA_GATTC_CB;
|
} tBTA_GATTC_CB;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SERVICE_CHANGE_CCC_WRITTEN_SUCCESS = 0,
|
||||||
|
SERVICE_CHANGE_CACHE_NOT_FOUND,
|
||||||
|
SERVICE_CHANGE_SERVICE_NOT_FOUND,
|
||||||
|
SERVICE_CHANGE_CHAR_NOT_FOUND,
|
||||||
|
SERVICE_CHANGE_CCC_NOT_FOUND,
|
||||||
|
SERVICE_CHANGE_WRITE_CCC_FAILED
|
||||||
|
}tBTA_GATTC_FIND_SERVICE_CB;
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
** Global data
|
** Global data
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
|
@ -4549,7 +4549,6 @@ void btm_sec_disconnected (UINT16 handle, UINT8 reason)
|
||||||
p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
|
p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
|
||||||
|
|
||||||
#if BTM_DISC_DURING_RS == TRUE
|
#if BTM_DISC_DURING_RS == TRUE
|
||||||
LOG_INFO("%s clearing pending flag handle:%d reason:%d\n", __func__, handle, reason);
|
|
||||||
p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
|
p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -253,7 +253,6 @@ static void gatt_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
|
||||||
p_clcb->conn_id = conn_id;
|
p_clcb->conn_id = conn_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_clcb->ccc_stage = GATT_SVC_CHANGED_CONNECTING;
|
|
||||||
|
|
||||||
if (!p_clcb->connected) {
|
if (!p_clcb->connected) {
|
||||||
/* wait for connection */
|
/* wait for connection */
|
||||||
|
@ -264,10 +263,6 @@ static void gatt_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
|
||||||
p_clcb->conn_id = conn_id;
|
p_clcb->conn_id = conn_id;
|
||||||
p_clcb->connected = TRUE;
|
p_clcb->connected = TRUE;
|
||||||
|
|
||||||
if (p_clcb->ccc_stage == GATT_SVC_CHANGED_CONNECTING) {
|
|
||||||
p_clcb->ccc_stage ++;
|
|
||||||
gatt_cl_start_config_ccc(p_clcb);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
gatt_profile_clcb_dealloc(p_clcb);
|
gatt_profile_clcb_dealloc(p_clcb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ typedef UINT8 tBTM_BLE_SFP;
|
||||||
|
|
||||||
/* default supervision timeout */
|
/* default supervision timeout */
|
||||||
#ifndef BTM_BLE_CONN_TIMEOUT_DEF
|
#ifndef BTM_BLE_CONN_TIMEOUT_DEF
|
||||||
#define BTM_BLE_CONN_TIMEOUT_DEF 2000
|
#define BTM_BLE_CONN_TIMEOUT_DEF 600
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* minimum acceptable connection interval */
|
/* minimum acceptable connection interval */
|
||||||
|
|
|
@ -105,7 +105,7 @@ void esp_log_write(esp_log_level_t level, const char* tag, const char* format, .
|
||||||
* @param buff_len length of buffer
|
* @param buff_len length of buffer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void esp_log_buffer_hex(const char *tag, const char *buffer, uint16_t buff_len);
|
void esp_log_buffer_hex(const char *tag, const void *buffer, uint16_t buff_len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Log a buffer of characters at Info level. Buffer should contain only printable characters.
|
* @brief Log a buffer of characters at Info level. Buffer should contain only printable characters.
|
||||||
|
@ -117,7 +117,7 @@ void esp_log_buffer_hex(const char *tag, const char *buffer, uint16_t buff_len);
|
||||||
* @param buff_len length of buffer
|
* @param buff_len length of buffer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void esp_log_buffer_char(const char *tag, const char *buffer, uint16_t buff_len);
|
void esp_log_buffer_char(const char *tag, const void *buffer, uint16_t buff_len);
|
||||||
|
|
||||||
#if CONFIG_LOG_COLORS
|
#if CONFIG_LOG_COLORS
|
||||||
#define LOG_COLOR_BLACK "30"
|
#define LOG_COLOR_BLACK "30"
|
||||||
|
|
|
@ -319,12 +319,13 @@ uint32_t esp_log_timestamp() __attribute__((alias("esp_log_early_timestamp")));
|
||||||
|
|
||||||
#endif //BOOTLOADER_BUILD
|
#endif //BOOTLOADER_BUILD
|
||||||
|
|
||||||
void esp_log_buffer_hex(const char *tag, const char *buffer, uint16_t buff_len)
|
void esp_log_buffer_hex(const char *tag, const void *buffer, uint16_t buff_len)
|
||||||
{
|
{
|
||||||
|
const char *as_bytes = (const char *)buffer;
|
||||||
char temp_buffer[3*BYTES_PER_LINE + 1]= {0};
|
char temp_buffer[3*BYTES_PER_LINE + 1]= {0};
|
||||||
int line_len = 0;
|
int line_len = 0;
|
||||||
for (int i = 0; i < buff_len; i++) {
|
for (int i = 0; i < buff_len; i++) {
|
||||||
line_len += sprintf(temp_buffer+line_len, "%02x ", buffer[i]);
|
line_len += sprintf(temp_buffer+line_len, "%02x ", as_bytes[i]);
|
||||||
if (((i + 1) % BYTES_PER_LINE == 0) || (i == buff_len - 1)) {
|
if (((i + 1) % BYTES_PER_LINE == 0) || (i == buff_len - 1)) {
|
||||||
ESP_LOGI(tag, "%s", temp_buffer);
|
ESP_LOGI(tag, "%s", temp_buffer);
|
||||||
line_len = 0;
|
line_len = 0;
|
||||||
|
@ -333,12 +334,13 @@ void esp_log_buffer_hex(const char *tag, const char *buffer, uint16_t buff_len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_log_buffer_char(const char *tag, const char *buffer, uint16_t buff_len)
|
void esp_log_buffer_char(const char *tag, const void *buffer, uint16_t buff_len)
|
||||||
{
|
{
|
||||||
|
const char *as_bytes = (const char *)buffer;
|
||||||
char temp_buffer[BYTES_PER_LINE + 1] = {0};
|
char temp_buffer[BYTES_PER_LINE + 1] = {0};
|
||||||
int line_len = 0;
|
int line_len = 0;
|
||||||
for (int i = 0; i < buff_len; i++) {
|
for (int i = 0; i < buff_len; i++) {
|
||||||
line_len += sprintf(temp_buffer+line_len, "%c", buffer[i]);
|
line_len += sprintf(temp_buffer+line_len, "%c", as_bytes[i]);
|
||||||
if (((i + 1) % BYTES_PER_LINE == 0) || (i == buff_len - 1)) {
|
if (((i + 1) % BYTES_PER_LINE == 0) || (i == buff_len - 1)) {
|
||||||
ESP_LOGI(tag, "%s", temp_buffer);
|
ESP_LOGI(tag, "%s", temp_buffer);
|
||||||
line_len = 0;
|
line_len = 0;
|
||||||
|
|
|
@ -120,7 +120,7 @@ static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
||||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
||||||
|
|
||||||
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
||||||
esp_log_buffer_hex(GATTC_TAG, (char *)gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
||||||
|
|
||||||
esp_ble_gattc_search_service(gattc_if, conn_id, NULL);
|
esp_ble_gattc_search_service(gattc_if, conn_id, NULL);
|
||||||
break;
|
break;
|
||||||
|
@ -134,7 +134,7 @@ static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
||||||
ESP_LOGI(GATTC_TAG, "UUID32: %x", srvc_id->id.uuid.uuid.uuid32);
|
ESP_LOGI(GATTC_TAG, "UUID32: %x", srvc_id->id.uuid.uuid.uuid32);
|
||||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
||||||
ESP_LOGI(GATTC_TAG, "UUID128:");
|
ESP_LOGI(GATTC_TAG, "UUID128:");
|
||||||
esp_log_buffer_hex(GATTC_TAG, (char *)srvc_id->id.uuid.uuid.uuid128, ESP_UUID_LEN_128);
|
esp_log_buffer_hex(GATTC_TAG, srvc_id->id.uuid.uuid.uuid128, ESP_UUID_LEN_128);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(GATTC_TAG, "UNKNOWN LEN %d", srvc_id->id.uuid.len);
|
ESP_LOGE(GATTC_TAG, "UNKNOWN LEN %d", srvc_id->id.uuid.len);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
||||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
||||||
|
|
||||||
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
||||||
esp_log_buffer_hex(GATTC_TAG, (char *)gl_profile_tab[PROFILE_B_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_B_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
||||||
esp_ble_gattc_search_service(gattc_if, conn_id, NULL);
|
esp_ble_gattc_search_service(gattc_if, conn_id, NULL);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||||
|
@ -223,7 +223,7 @@ static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
||||||
ESP_LOGI(GATTC_TAG, "UUID32: %x", srvc_id->id.uuid.uuid.uuid32);
|
ESP_LOGI(GATTC_TAG, "UUID32: %x", srvc_id->id.uuid.uuid.uuid32);
|
||||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
||||||
ESP_LOGI(GATTC_TAG, "UUID128:");
|
ESP_LOGI(GATTC_TAG, "UUID128:");
|
||||||
esp_log_buffer_hex(GATTC_TAG, (char *)srvc_id->id.uuid.uuid.uuid128, ESP_UUID_LEN_128);
|
esp_log_buffer_hex(GATTC_TAG, srvc_id->id.uuid.uuid.uuid128, ESP_UUID_LEN_128);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(GATTC_TAG, "UNKNOWN LEN %d", srvc_id->id.uuid.len);
|
ESP_LOGE(GATTC_TAG, "UNKNOWN LEN %d", srvc_id->id.uuid.len);
|
||||||
}
|
}
|
||||||
|
@ -297,12 +297,12 @@ 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;
|
esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
|
||||||
switch (scan_result->scan_rst.search_evt) {
|
switch (scan_result->scan_rst.search_evt) {
|
||||||
case ESP_GAP_SEARCH_INQ_RES_EVT:
|
case ESP_GAP_SEARCH_INQ_RES_EVT:
|
||||||
esp_log_buffer_hex(GATTC_TAG, (char *)scan_result->scan_rst.bda, 6);
|
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);
|
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(scan_result->scan_rst.ble_adv,
|
adv_name = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv,
|
||||||
ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_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, "Searched Device Name Len %d", adv_name_len);
|
||||||
esp_log_buffer_char(GATTC_TAG, (char *)adv_name, adv_name_len);
|
esp_log_buffer_char(GATTC_TAG, adv_name, adv_name_len);
|
||||||
ESP_LOGI(GATTC_TAG, "\n");
|
ESP_LOGI(GATTC_TAG, "\n");
|
||||||
if (adv_name != NULL) {
|
if (adv_name != NULL) {
|
||||||
if (strlen(device_name) == adv_name_len && strncmp((char *)adv_name, device_name, adv_name_len) == 0) {
|
if (strlen(device_name) == adv_name_len && strncmp((char *)adv_name, device_name, adv_name_len) == 0) {
|
||||||
|
|
|
@ -238,7 +238,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){
|
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){
|
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC){
|
||||||
esp_log_buffer_hex(GATTS_TAG, (char *)prepare_write_env->prepare_buf, prepare_write_env->prepare_len);
|
esp_log_buffer_hex(GATTS_TAG, prepare_write_env->prepare_buf, prepare_write_env->prepare_len);
|
||||||
}else{
|
}else{
|
||||||
ESP_LOGI(GATTS_TAG,"ESP_GATT_PREP_WRITE_CANCEL");
|
ESP_LOGI(GATTS_TAG,"ESP_GATT_PREP_WRITE_CANCEL");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue