bluedroid: support gatts show local database

This commit is contained in:
chenjianhua 2023-04-23 17:13:04 +08:00
parent be7cf3dffb
commit 97dd2dc88e
13 changed files with 182 additions and 1 deletions

View File

@ -421,4 +421,17 @@ static esp_err_t esp_ble_gatts_add_char_desc_param_check(esp_attr_value_t *char_
return ESP_OK;
}
esp_err_t esp_ble_gatts_show_local_database(void)
{
btc_msg_t msg = {0};
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SHOW_LOCAL_DATABASE;
return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif ///GATTS_INCLUDED

View File

@ -572,6 +572,16 @@ esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id);
*/
esp_err_t esp_ble_gatts_send_service_change_indication(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda);
/**
* @brief Print local database (GATT service table)
*
* @return
* - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gatts_show_local_database(void);
#ifdef __cplusplus
}
#endif

View File

@ -904,6 +904,22 @@ void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
}
}
/*******************************************************************************
**
** Function bta_gatts_show_local_database
**
** Description print loacl service database
**
** Returns none.
**
*******************************************************************************/
void bta_gatts_show_local_database (void)
{
if (GATTS_ShowLocalDatabase()) {
APPL_TRACE_ERROR("%s failed", __func__);
}
}
/*******************************************************************************
**
** Function bta_gatts_request_cback

View File

@ -667,4 +667,14 @@ uint8_t BTA_GATTS_SendMultiNotification(uint8_t gatt_if, uint16_t conn_id, void
return 0;
}
void BTA_GATTS_ShowLocalDatabase(void)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTS_API_SHOW_LOCAL_DATABASE_EVT;
bta_sys_sendmsg(p_buf);
}
}
#endif /* BTA_GATT_INCLUDED */

View File

@ -133,6 +133,9 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
case BTA_GATTS_API_SEND_SERVICE_CHANGE_EVT:
bta_gatts_send_service_change_indication((tBTA_GATTS_DATA *) p_msg);
break;
case BTA_GATTS_API_SHOW_LOCAL_DATABASE_EVT:
bta_gatts_show_local_database();
break;
default:
break;
}

View File

@ -53,7 +53,8 @@ enum {
BTA_GATTS_API_CLOSE_EVT,
BTA_GATTS_API_LISTEN_EVT,
BTA_GATTS_API_DISABLE_EVT,
BTA_GATTS_API_SEND_SERVICE_CHANGE_EVT
BTA_GATTS_API_SEND_SERVICE_CHANGE_EVT,
BTA_GATTS_API_SHOW_LOCAL_DATABASE_EVT
};
typedef UINT16 tBTA_GATTS_INT_EVT;
@ -251,6 +252,7 @@ extern void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_send_service_change_indication (tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_show_local_database (void);
extern BOOLEAN bta_gatts_uuid_compare(tBT_UUID tar, tBT_UUID src);
extern tBTA_GATTS_RCB *bta_gatts_find_app_rcb_by_app_if(tBTA_GATTS_IF server_if);

View File

@ -1542,6 +1542,16 @@ void BTA_GATTS_SendServiceChangeIndication(tBTA_GATTS_IF server_if, BD_ADDR remo
extern void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start,
BD_ADDR_PTR target_bda);
/*******************************************************************************
**
** Function BTA_GATTS_ShowLocalDatabase
**
** Description print local service database.
**
** Returns void
**
*******************************************************************************/
extern void BTA_GATTS_ShowLocalDatabase(void);
extern void bta_gattc_clcb_dealloc_by_conn_id(UINT16 conn_id);

View File

@ -498,6 +498,11 @@ esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *lengt
return BTA_GetAttributeValue(attr_handle, length, value);
}
esp_gatt_status_t btc_gatts_show_local_database(void)
{
BTA_GATTS_ShowLocalDatabase();
return ESP_GATT_OK;
}
static void btc_gatts_cb_param_copy_req(btc_msg_t *msg, void *p_dest, void *p_src)
{
@ -741,6 +746,9 @@ void btc_gatts_call_handler(btc_msg_t *msg)
BTA_GATTS_SendServiceChangeIndication(arg->send_service_change.gatts_if, remote_bda);
break;
}
case BTC_GATTS_ACT_SHOW_LOCAL_DATABASE:
BTA_GATTS_ShowLocalDatabase();
break;
default:
break;
}

View File

@ -30,6 +30,7 @@ typedef enum {
BTC_GATTS_ACT_OPEN,
BTC_GATTS_ACT_CLOSE,
BTC_GATTS_ACT_SEND_SERVICE_CHANGE,
BTC_GATTS_ACT_SHOW_LOCAL_DATABASE,
} btc_gatts_act_t;
/* btc_ble_gatts_args_t */
@ -164,6 +165,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg);
void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_gatts_arg_deep_free(btc_msg_t *msg);
esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value);
esp_gatt_status_t btc_gatts_show_local_database(void);
#endif /* __BTC_GATTS_H__ */

View File

@ -1769,4 +1769,10 @@ tGATT_STATUS GATTS_HandleMultiValueNotification (UINT16 conn_id, tGATT_HLV *tupl
return cmd_sent;
}
tGATT_STATUS GATTS_ShowLocalDatabase(void)
{
gatts_show_local_database();
return GATT_SUCCESS;
}
#endif

View File

@ -8,6 +8,36 @@
#include "smp_int.h"
#if (BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE)
const char *const gatt_attr_name[] = {
"primary service",
"secondary service",
"included service",
"characteristic",
};
const char *const gatt_char_desc_name[] = {
"characteristic extended properties",
"characteristic user description",
"client characteristic configuration",
"server characteristic configuration",
"characteristic presentation format",
"characteristic aggregate format",
};
static const char *gatt_get_attr_name(UINT16 uuid)
{
if (uuid >= GATT_UUID_PRI_SERVICE && uuid <= GATT_UUID_CHAR_DECLARE) {
return gatt_attr_name[uuid - GATT_UUID_PRI_SERVICE];
}
if (uuid >= GATT_UUID_CHAR_EXT_PROP && uuid <= GATT_UUID_CHAR_AGG_FORMAT) {
return gatt_char_desc_name[uuid - GATT_UUID_CHAR_EXT_PROP];
}
return "Unknown Attribute";
}
static void attr_uuid_to_bt_uuid(void *p_attr, tBT_UUID *p_uuid)
{
tGATT_ATTR16 *p_attr16 = (tGATT_ATTR16 *)p_attr;
@ -165,4 +195,62 @@ tGATT_STATUS gatts_calculate_datebase_hash(BT_OCTET16 hash)
osi_free(data_buf);
return GATT_SUCCESS;
}
void gatts_show_local_database(void)
{
UINT8 i;
tGATT_SVC_DB *p_db;
tGATT_ATTR16 *p_attr;
printf("\n================= GATTS DATABASE DUMP START =================\n");
for (i = 0; i < GATT_MAX_SR_PROFILES; i++) {
p_db = gatt_cb.sr_reg[i].p_db;
if (p_db && p_db->p_attr_list) {
p_attr = (tGATT_ATTR16 *)p_db->p_attr_list;
while (p_attr) {
switch (p_attr->uuid) {
case GATT_UUID_PRI_SERVICE:
case GATT_UUID_SEC_SERVICE:
// Service declaration
printf("%s\n", gatt_get_attr_name(p_attr->uuid));
printf("\tuuid %s\n", gatt_uuid_to_str(&p_attr->p_value->uuid));
printf("\thandle %d\n", p_attr->handle);
printf("\tend_handle %d\n",p_db->end_handle-1);
break;
case GATT_UUID_INCLUDE_SERVICE:
// Included service declaration
printf("%s\n", gatt_get_attr_name(p_attr->uuid));
printf("\tuuid %s\t", gatt_uuid_to_str(&p_attr->p_value->incl_handle.service_type));
printf("\thandle %d\n", p_attr->p_value->incl_handle.s_handle);
printf("\tend_handle %d\n", p_attr->p_value->incl_handle.e_handle);
break;
case GATT_UUID_CHAR_DECLARE: {
tBT_UUID char_uuid;
tGATT_ATTR16 *p_char_val;
p_char_val = (tGATT_ATTR16 *)p_attr->p_next;
attr_uuid_to_bt_uuid((void *)p_char_val, &char_uuid);
printf("%s\n", gatt_get_attr_name(p_attr->uuid));
printf("\tuuid %s\n", gatt_uuid_to_str(&char_uuid));
printf("\tdef_handle %d\n", p_attr->handle);
printf("\tval_handle %d\n", p_attr->p_value->char_decl.char_val_handle);
printf("\tperm 0x%04x, prop 0x%02x\n", p_char_val->permission, p_attr->p_value->char_decl.property);
break;
}
case GATT_UUID_CHAR_EXT_PROP:
case GATT_UUID_CHAR_DESCRIPTION:
case GATT_UUID_CHAR_CLIENT_CONFIG:
case GATT_UUID_CHAR_SRVR_CONFIG:
case GATT_UUID_CHAR_PRESENT_FORMAT:
case GATT_UUID_CHAR_AGG_FORMAT:
printf("%s\n", gatt_get_attr_name(p_attr->uuid));
printf("\thandle %d\n", p_attr->handle);
break;
}
p_attr = (tGATT_ATTR16 *) p_attr->p_next;
}
}
}
printf("================= GATTS DATABASE DUMP END =================\n");
}
#endif /* BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE */

View File

@ -778,6 +778,8 @@ extern uint16_t gatt_get_local_mtu(void);
extern void gatt_set_local_mtu(uint16_t mtu);
extern tGATT_STATUS gatts_calculate_datebase_hash(BT_OCTET16 hash);
extern void gatts_show_local_database(void);
extern BOOLEAN gatt_sr_is_cl_change_aware(tGATT_TCB *p_tcb);
extern void gatt_sr_init_cl_status(tGATT_TCB *p_tcb);
extern void gatt_sr_update_cl_status(tGATT_TCB *tcb, BOOLEAN chg_aware);

View File

@ -1279,6 +1279,17 @@ extern tGATT_STATUS GATTS_SetServiceChangeMode(UINT8 mode);
*******************************************************************************/
extern tGATT_STATUS GATTS_HandleMultiValueNotification (UINT16 conn_id, tGATT_HLV *tuples, UINT16 num_tuples);
/*******************************************************************************
**
** Function GATTS_ShowLocalDatabase
**
** Description This function print local service database.
**
** Returns GATT_SUCCESS if successfully sent; otherwise error code.
**
*******************************************************************************/
extern tGATT_STATUS GATTS_ShowLocalDatabase(void);
#ifdef __cplusplus
}