From: Tian Hao Date: Tue, 22 Nov 2016 09:26:30 +0000 (+0800) Subject: component/bt : gatt client fix search service bug X-Git-Tag: v1.0~2^2~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=595bd2e3c4fa322e44f9022dede46c759be94823;p=esp-idf component/bt : gatt client fix search service bug 1. fix search service bug 2. delete some print --- diff --git a/components/bt/bluedroid/api/esp_gattc_api.c b/components/bt/bluedroid/api/esp_gattc_api.c index eed981f0c8..b57ad9e7f8 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 674416f849..c8ee401c04 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 2500b44491..e9a12c0e96 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 743ccdcdcc..f2038d9857 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 540df2d7ba..1f2ad4a86c 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 4e5d8a21fa..74740c2fb9 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 1d1eec6a03..fb109778d3 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; } }