From 595bd2e3c4fa322e44f9022dede46c759be94823 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Tue, 22 Nov 2016 17:26:30 +0800 Subject: [PATCH] component/bt : gatt client fix search service bug 1. fix search service bug 2. delete some print --- components/bt/bluedroid/api/esp_gattc_api.c | 7 ++++- .../btc/profile/std/gatt/btc_gattc.c | 12 ++++++-- .../btc/profile/std/include/btc_gattc.h | 1 + components/bt/bluedroid/hci/hci_hal_h4.c | 2 +- .../bt/bluedroid/hci/packet_fragmenter.c | 3 +- .../bt/bluedroid/stack/l2cap/l2c_main.c | 2 +- .../app_project/Arch_SimpleClientProject.c | 29 +++++++++++++++++-- 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/components/bt/bluedroid/api/esp_gattc_api.c b/components/bt/bluedroid/api/esp_gattc_api.c index eed981f0c..b57ad9e7f 100644 --- a/components/bt/bluedroid/api/esp_gattc_api.c +++ b/components/bt/bluedroid/api/esp_gattc_api.c @@ -198,7 +198,12 @@ esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_u msg.pid = BTC_PID_GATTC; msg.act = BTC_GATTC_ACT_SEARCH_SERVICE; arg.conn_id = conn_id; - memcpy(&arg.uuid, filter_uuid, sizeof(esp_bt_uuid_t)); + if (filter_uuid) { + arg.have_uuid = true; + memcpy(&arg.uuid, filter_uuid, sizeof(esp_bt_uuid_t)); + } else { + arg.have_uuid = false; + } return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c index 674416f84..c8ee401c0 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c @@ -93,8 +93,14 @@ static void btc_gattc_cfg_mtu(btc_ble_gattc_args_t *arg) static void btc_gattc_search_service(btc_ble_gattc_args_t *arg) { - tBT_UUID *srvc_uuid = (tBT_UUID *)(&arg->uuid); - BTA_GATTC_ServiceSearchRequest(arg->conn_id, srvc_uuid); + tBT_UUID srvc_uuid; + + if (arg->have_uuid) { + btc_to_bta_uuid(&srvc_uuid, &arg->uuid); + BTA_GATTC_ServiceSearchRequest(arg->conn_id, &srvc_uuid); + } else { + BTA_GATTC_ServiceSearchRequest(arg->conn_id, NULL); + } } static void btc_gattc_get_first_char(btc_ble_gattc_args_t *arg) @@ -488,7 +494,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg) case BTA_GATTC_SEARCH_RES_EVT: { tBTA_GATTC_SRVC_RES *srvc_res = &arg->srvc_res; param.search_res.conn_id = srvc_res->conn_id; - memcpy(¶m.search_res.service_id, &srvc_res->service_uuid, sizeof(esp_gatt_srvc_id_t)); + bta_to_btc_srvc_id(¶m.search_res.service_id, &srvc_res->service_uuid); BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_RES_EVT, ¶m); break; } diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h b/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h index 2500b4449..e9a12c0e9 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h @@ -39,6 +39,7 @@ typedef struct { esp_gatt_auth_req_t auth_req; esp_bd_addr_t remote_bda; esp_bt_uuid_t uuid; + bool have_uuid; uint16_t app_id; uint16_t conn_id; uint16_t mtu; diff --git a/components/bt/bluedroid/hci/hci_hal_h4.c b/components/bt/bluedroid/hci/hci_hal_h4.c index 743ccdcdc..f2038d985 100755 --- a/components/bt/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/bluedroid/hci/hci_hal_h4.c @@ -197,7 +197,7 @@ static void hci_hal_h4_hdl_rx_packet(BT_HDR *packet) { return; } if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) { - LOG_ERROR("%d Unknown HCI message type. Dropping this byte 0x%x," + LOG_ERROR("%s Unknown HCI message type. Dropping this byte 0x%x," " min %x, max %x\n", __func__, type, DATA_TYPE_ACL, DATA_TYPE_EVENT); hci_hal_env.allocator->free(packet); diff --git a/components/bt/bluedroid/hci/packet_fragmenter.c b/components/bt/bluedroid/hci/packet_fragmenter.c index 540df2d7b..1f2ad4a86 100755 --- a/components/bt/bluedroid/hci/packet_fragmenter.c +++ b/components/bt/bluedroid/hci/packet_fragmenter.c @@ -120,7 +120,8 @@ static void fragment_and_dispatch(BT_HDR *packet) { } static void reassemble_and_dispatch(BT_HDR *packet) { - LOG_ERROR("reassemble_and_dispatch\n"); + LOG_DEBUG("reassemble_and_dispatch\n"); + if ((packet->event & MSG_EVT_MASK) == MSG_HC_TO_STACK_HCI_ACL) { uint8_t *stream = packet->data; uint16_t handle; diff --git a/components/bt/bluedroid/stack/l2cap/l2c_main.c b/components/bt/bluedroid/stack/l2cap/l2c_main.c index 4e5d8a21f..74740c2fb 100755 --- a/components/bt/bluedroid/stack/l2cap/l2c_main.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_main.c @@ -192,7 +192,7 @@ void l2c_rcv_acl_data (BT_HDR *p_msg) /* only process fixed channel data as channel open indication when link is not in disconnecting mode */ l2cble_notify_le_connection(p_lcb->remote_bd_addr); #endif - L2CAP_TRACE_WARNING ("L2CAP - rcv_cid CID: 0x%04x\n", rcv_cid); + L2CAP_TRACE_DEBUG ("L2CAP - rcv_cid CID: 0x%04x\n", rcv_cid); /* Find the CCB for this CID */ if (rcv_cid >= L2CAP_BASE_APPL_CID) { diff --git a/examples/10_gatt_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c b/examples/10_gatt_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c index 1d1eec6a0..fb109778d 100644 --- a/examples/10_gatt_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c +++ b/examples/10_gatt_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c @@ -33,6 +33,7 @@ #include "bta_gatt_api.h" #include "esp_gap_ble_api.h" #include "esp_gattc_api.h" +#include "esp_gatt_defs.h" #include "esp_bt_main.h" @@ -207,10 +208,34 @@ static void esp_gattc_result_cb(uint32_t event, void *gattc_param) conidx = gattc_data->open.conn_id; LOG_ERROR("conidx = %x, if = %x\n",conidx, gattc_data->open.gatt_if); esp_ble_gattc_search_service(conidx, NULL); - LOG_ERROR("ESP_GATTC_OPEN_EVT\n"); + LOG_ERROR("ESP_GATTC_OPEN_EVT status %d\n", gattc_data->open.status); + break; + case ESP_GATTC_SEARCH_RES_EVT: { + esp_gatt_srvc_id_t *srvc_id = &gattc_data->search_res.service_id; + conidx = gattc_data->open.conn_id; + LOG_ERROR("SEARCH RES: conidx = %x\n", conidx); + if (srvc_id->id.uuid.len == ESP_UUID_LEN_16) { + LOG_ERROR("UUID16: %x\n", srvc_id->id.uuid.uuid.uuid16); + } else if (srvc_id->id.uuid.len == ESP_UUID_LEN_32) { + LOG_ERROR("UUID32: %x\n", srvc_id->id.uuid.uuid.uuid32); + } else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) { + LOG_ERROR("UUID128: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", srvc_id->id.uuid.uuid.uuid128[0], + srvc_id->id.uuid.uuid.uuid128[1],srvc_id->id.uuid.uuid.uuid128[2], srvc_id->id.uuid.uuid.uuid128[3], + srvc_id->id.uuid.uuid.uuid128[4],srvc_id->id.uuid.uuid.uuid128[5],srvc_id->id.uuid.uuid.uuid128[6], + srvc_id->id.uuid.uuid.uuid128[7],srvc_id->id.uuid.uuid.uuid128[8],srvc_id->id.uuid.uuid.uuid128[9], + srvc_id->id.uuid.uuid.uuid128[10],srvc_id->id.uuid.uuid.uuid128[11],srvc_id->id.uuid.uuid.uuid128[12], + srvc_id->id.uuid.uuid.uuid128[13],srvc_id->id.uuid.uuid.uuid128[14],srvc_id->id.uuid.uuid.uuid128[15]); + } else { + LOG_ERROR("UNKNOWN LEN %d\n", srvc_id->id.uuid.len); + } + break; + } + case ESP_GATTC_SEARCH_CMPL_EVT: + conidx = gattc_data->search_cmpl.conn_id; + LOG_ERROR("SEARCH_CMPL: conidx = %x, status %d\n",conidx, gattc_data->search_cmpl.status); break; default: - break; + break; } }