From 54b841dc30c04930040f5e51b09865c5649b76d5 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Fri, 28 Sep 2018 19:51:55 +0800 Subject: [PATCH] =?UTF-8?q?Component/bt:=20fix=20service=20change=20char?= =?UTF-8?q?=20can=E2=80=99t=20read=20and=20write=20and=20no=20descr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/bt/bluedroid/stack/gap/gap_ble.c | 10 +-- .../bt/bluedroid/stack/gap/include/gap_int.h | 2 +- .../bt/bluedroid/stack/gatt/gatt_attr.c | 64 +++++++++++++++++-- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/components/bt/bluedroid/stack/gap/gap_ble.c b/components/bt/bluedroid/stack/gap/gap_ble.c index d6115fe41..5044f08f1 100644 --- a/components/bt/bluedroid/stack/gap/gap_ble.c +++ b/components/bt/bluedroid/stack/gap/gap_ble.c @@ -207,7 +207,7 @@ BOOLEAN gap_ble_dequeue_request (tGAP_CLCB *p_clcb, UINT16 *p_uuid, tGAP_BLE_CMP *******************************************************************************/ tGATT_STATUS gap_read_attr_value (UINT16 handle, tGATT_VALUE *p_value, BOOLEAN is_long) { - tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; + tGAP_ATTR *p_db_attr = gap_cb.gap_attr; UINT8 *p = p_value->value, i; UINT16 offset = p_value->offset; UINT8 *p_dev_name = NULL; @@ -293,7 +293,7 @@ tGATT_STATUS gap_proc_read (tGATTS_REQ_TYPE type, tGATT_READ_REQ *p_data, tGATTS *******************************************************************************/ UINT8 gap_proc_write_req( tGATTS_REQ_TYPE type, tGATT_WRITE_REQ *p_data) { - tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; + tGAP_ATTR *p_db_attr = gap_cb.gap_attr; UINT8 i; UNUSED(type); @@ -373,12 +373,12 @@ void gap_attr_db_init(void) tBT_UUID app_uuid = {LEN_UUID_128, {0}}; tBT_UUID uuid = {LEN_UUID_16, {UUID_SERVCLASS_GAP_SERVER}}; UINT16 service_handle; - tGAP_ATTR *p_db_attr = &gap_cb.gatt_attr[0]; + tGAP_ATTR *p_db_attr = &gap_cb.gap_attr[0]; tGATT_STATUS status; /* Fill our internal UUID with a fixed pattern 0x82 */ memset (&app_uuid.uu.uuid128, 0x82, LEN_UUID_128); - memset(gap_cb.gatt_attr, 0, sizeof(tGAP_ATTR) *GAP_MAX_CHAR_NUM); + memset(gap_cb.gap_attr, 0, sizeof(tGAP_ATTR) *GAP_MAX_CHAR_NUM); gap_cb.gatt_if = GATT_Register(&app_uuid, &gap_cback); @@ -456,7 +456,7 @@ void gap_attr_db_init(void) *******************************************************************************/ void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value) { - tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; + tGAP_ATTR *p_db_attr = gap_cb.gap_attr; UINT8 i = 0; GAP_TRACE_EVENT("GAP_BleAttrDBUpdate attr_uuid=0x%04x\n", attr_uuid); diff --git a/components/bt/bluedroid/stack/gap/include/gap_int.h b/components/bt/bluedroid/stack/gap/include/gap_int.h index a328986f2..e27814118 100644 --- a/components/bt/bluedroid/stack/gap/include/gap_int.h +++ b/components/bt/bluedroid/stack/gap/include/gap_int.h @@ -136,7 +136,7 @@ typedef struct { /* LE GAP attribute database */ #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE - tGAP_ATTR gatt_attr[GAP_MAX_CHAR_NUM]; + tGAP_ATTR gap_attr[GAP_MAX_CHAR_NUM]; tGAP_CLCB clcb[GAP_MAX_CL]; /* connection link*/ tGATT_IF gatt_if; #endif diff --git a/components/bt/bluedroid/stack/gatt/gatt_attr.c b/components/bt/bluedroid/stack/gatt/gatt_attr.c index 51c331f9f..ff75ff11b 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_attr.c +++ b/components/bt/bluedroid/stack/gatt/gatt_attr.c @@ -171,6 +171,59 @@ void gatt_profile_clcb_dealloc (tGATT_PROFILE_CLCB *p_clcb) memset(p_clcb, 0, sizeof(tGATT_PROFILE_CLCB)); } +/******************************************************************************* +** +** Function gatt_proc_read +** +** Description GATT Attributes Database Read/Read Blob Request process +** +** Returns GATT_SUCCESS if successfully sent; otherwise error code. +** +*******************************************************************************/ +tGATT_STATUS gatt_proc_read (tGATTS_REQ_TYPE type, tGATT_READ_REQ *p_data, tGATTS_RSP *p_rsp) +{ + tGATT_STATUS status = GATT_NO_RESOURCES; + UNUSED(type); + + if (p_data->is_long) { + p_rsp->attr_value.offset = p_data->offset; + } + + p_rsp->attr_value.handle = p_data->handle; + UINT16 len = 0; + uint8_t *value; + status = GATTS_GetAttributeValue(p_data->handle, &len, &value); + if(status == GATT_SUCCESS && len > 0 && value) { + if(len > GATT_MAX_ATTR_LEN) { + len = GATT_MAX_ATTR_LEN; + } + p_rsp->attr_value.len = len; + memcpy(p_rsp->attr_value.value, value, len); + } + + return status; +} + +/****************************************************************************** +** +** Function gatt_proc_write_req +** +** Description GATT server process a write request. +** +** Returns GATT_SUCCESS if successfully sent; otherwise error code. +** +*******************************************************************************/ +tGATT_STATUS gatt_proc_write_req( tGATTS_REQ_TYPE type, tGATT_WRITE_REQ *p_data) +{ + if(p_data->len > GATT_MAX_ATTR_LEN) { + p_data->len = GATT_MAX_ATTR_LEN; + } + return GATTS_SetAttributeValue(p_data->handle, + p_data->len, + p_data->value); + +} + /******************************************************************************* ** ** Function gatt_request_cback @@ -191,11 +244,14 @@ static void gatt_request_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE switch (type) { case GATTS_REQ_TYPE_READ: - status = GATT_READ_NOT_PERMIT; + status = gatt_proc_read(type, &p_data->read_req, &rsp_msg); break; case GATTS_REQ_TYPE_WRITE: - status = GATT_WRITE_NOT_PERMIT; + if (!p_data->write_req.need_rsp) { + ignore = TRUE; + } + status = gatt_proc_write_req(type, &p_data->write_req); break; case GATTS_REQ_TYPE_WRITE_EXEC: @@ -306,7 +362,6 @@ void gatt_profile_db_init (void) tBT_UUID descr_uuid = {LEN_UUID_16, {GATT_UUID_CHAR_CLIENT_CONFIG}}; uint8_t ccc_value[2] ={ 0x00, 0x00}; - tGATTS_ATTR_CONTROL control ={1}; tGATT_ATTR_VAL attr_val = { .attr_max_len = sizeof(UINT16), @@ -314,8 +369,7 @@ void gatt_profile_db_init (void) .attr_val = ccc_value, }; - GATTS_AddCharDescriptor (service_handle, GATT_PERM_READ | GATT_PERM_WRITE , &descr_uuid, &attr_val, &control); - + GATTS_AddCharDescriptor (service_handle, GATT_PERM_READ | GATT_PERM_WRITE , &descr_uuid, &attr_val, NULL); /* start service */ status = GATTS_StartService (gatt_cb.gatt_if, service_handle, GATTP_TRANSPORT_SUPPORTED );