From 48b1b78d97d88f1d7a7a00252a489ed0eba598d4 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 16 Oct 2015 11:26:33 +0200 Subject: [PATCH] add include handle to include service query result event and show in pts test --- ble/gatt_client.c | 50 ++++++++++++++++++----------- src/hci_cmds.h | 3 +- test/gatt_client/gatt_client_test.c | 6 ++-- test/pts/ble_central_test.c | 18 ++++++----- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/ble/gatt_client.c b/ble/gatt_client.c index 7ccf3f72d..c854630ac 100644 --- a/ble/gatt_client.c +++ b/ble/gatt_client.c @@ -516,10 +516,10 @@ static void emit_gatt_complete_event(gatt_client_t * peripheral, uint8_t status) emit_event_new(peripheral->subclient_id, packet, sizeof(packet)); } -static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uint8_t type, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){ +static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){ // @format HX uint8_t packet[24]; - packet[0] = type; + packet[0] = GATT_SERVICE_QUERY_RESULT; packet[1] = sizeof(packet) - 2; bt_store_16(packet, 2, peripheral->handle); /// @@ -529,6 +529,21 @@ static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uin emit_event_new(peripheral->subclient_id, packet, sizeof(packet)); } +static void emit_gatt_included_service_query_result_event(gatt_client_t * peripheral, uint16_t include_handle, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){ + // @format HX + uint8_t packet[26]; + packet[0] = GATT_INCLUDED_SERVICE_QUERY_RESULT; + packet[1] = sizeof(packet) - 2; + bt_store_16(packet, 2, peripheral->handle); + /// + bt_store_16(packet, 4, include_handle); + // + bt_store_16(packet, 6, start_group_handle); + bt_store_16(packet, 8, end_group_handle); + swap128(uuid128, &packet[10]); + emit_event_new(peripheral->subclient_id, packet, sizeof(packet)); +} + static void emit_gatt_characteristic_query_result_event(gatt_client_t * peripheral, uint16_t start_handle, uint16_t value_handle, uint16_t end_handle, uint16_t properties, uint8_t * uuid128){ // @format HY @@ -576,7 +591,7 @@ static void report_gatt_services(gatt_client_t * peripheral, uint8_t * packet, } else { swap128(&packet[i+4], uuid128); } - emit_gatt_service_query_result_event(peripheral, GATT_SERVICE_QUERY_RESULT, start_group_handle, end_group_handle, uuid128); + emit_gatt_service_query_result_event(peripheral, start_group_handle, end_group_handle, uuid128); } // log_info("report_gatt_services for %02X done", peripheral->handle); } @@ -628,18 +643,16 @@ static void report_gatt_characteristics(gatt_client_t * peripheral, uint8_t * pa } } -// pre: uuid16 != 0 OR uuid128 != NULL -// maybe inline this into the two callers -static void report_gatt_included_service(gatt_client_t * peripheral, uint8_t *uuid128, uint16_t uuid16){ - if (uuid16){ - uint8_t normalized_uuid128[16]; - sdp_normalize_uuid(normalized_uuid128, uuid16); - emit_gatt_service_query_result_event(peripheral, GATT_INCLUDED_SERVICE_QUERY_RESULT, peripheral->query_start_handle, - peripheral->query_end_handle, normalized_uuid128); - } else if (uuid128){ - emit_gatt_service_query_result_event(peripheral, GATT_INCLUDED_SERVICE_QUERY_RESULT, peripheral->query_start_handle, - peripheral->query_end_handle, uuid128); - } +static void report_gatt_included_service_uuid16(gatt_client_t * peripheral, uint16_t include_handle, uint16_t uuid16){ + uint8_t normalized_uuid128[16]; + sdp_normalize_uuid(normalized_uuid128, uuid16); + emit_gatt_included_service_query_result_event(peripheral, include_handle, peripheral->query_start_handle, + peripheral->query_end_handle, normalized_uuid128); +} + +static void report_gatt_included_service_uuid128(gatt_client_t * peripheral, uint16_t include_handle, uint8_t *uuid128){ + emit_gatt_included_service_query_result_event(peripheral, include_handle, peripheral->query_start_handle, + peripheral->query_end_handle, uuid128); } // @returns packet pointer @@ -1105,10 +1118,11 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, uint16_t offset; for (offset = 2; offset < size; offset += pair_size){ + uint16_t include_handle = READ_BT_16(packet, offset); peripheral->query_start_handle = READ_BT_16(packet,offset+2); peripheral->query_end_handle = READ_BT_16(packet,offset+4); uuid16 = READ_BT_16(packet, offset+6); - report_gatt_included_service(peripheral, NULL, uuid16); + report_gatt_included_service_uuid16(peripheral, include_handle, uuid16); } trigger_next_included_service_query(peripheral, get_last_result_handle_from_included_services_list(packet, size)); @@ -1140,7 +1154,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, case P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT: { uint8_t uuid128[16]; swap128(&packet[1], uuid128); - report_gatt_included_service(peripheral, uuid128, 0); + report_gatt_included_service_uuid128(peripheral, peripheral->start_group_handle, uuid128); trigger_next_included_service_query(peripheral, peripheral->start_group_handle); // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done break; @@ -1171,7 +1185,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, for (i = 1; iuuid128); + emit_gatt_service_query_result_event(peripheral, start_group_handle, end_group_handle, peripheral->uuid128); } trigger_next_service_by_uuid_query(peripheral, end_group_handle); // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done diff --git a/src/hci_cmds.h b/src/hci_cmds.h index e52cc9095..cb2fda22c 100644 --- a/src/hci_cmds.h +++ b/src/hci_cmds.h @@ -490,8 +490,9 @@ extern "C" { #define GATT_CHARACTERISTIC_QUERY_RESULT 0xA2 /** - * @format HX + * @format H2X * @param handle + * @param include_handle * @param service */ #define GATT_INCLUDED_SERVICE_QUERY_RESULT 0xA3 diff --git a/test/gatt_client/gatt_client_test.c b/test/gatt_client/gatt_client_test.c index 701ffb502..d5420e65e 100644 --- a/test/gatt_client/gatt_client_test.c +++ b/test/gatt_client/gatt_client_test.c @@ -169,10 +169,10 @@ static void handle_ble_client_event(uint8_t packet_type, uint8_t *packet, uint16 result_counter++; break; case GATT_INCLUDED_SERVICE_QUERY_RESULT: - service.start_group_handle = READ_BT_16(packet, 4); - service.end_group_handle = READ_BT_16(packet, 6); + service.start_group_handle = READ_BT_16(packet, 6); + service.end_group_handle = READ_BT_16(packet, 8); service.uuid16 = 0; - swap128(&packet[8], service.uuid128); + swap128(&packet[10], service.uuid128); if (sdp_has_blueooth_base_uuid(service.uuid128)){ service.uuid16 = READ_NET_32(service.uuid128, 0); } diff --git a/test/pts/ble_central_test.c b/test/pts/ble_central_test.c index 4ad0b5bdf..b623bf08f 100644 --- a/test/pts/ble_central_test.c +++ b/test/pts/ble_central_test.c @@ -412,11 +412,11 @@ void use_public_pts_address(void){ current_pts_address_type = public_pts_address_type; } -void extract_service(le_service_t * service, uint8_t * packet){ - service->start_group_handle = READ_BT_16(packet, 4); - service->end_group_handle = READ_BT_16(packet, 6); +void extract_service(le_service_t * service, uint8_t * data){ + service->start_group_handle = READ_BT_16(data, 0); + service->end_group_handle = READ_BT_16(data, 2); service->uuid16 = 0; - swap128(&packet[8], service->uuid128); + swap128(&data[4], service->uuid128); if (sdp_has_blueooth_base_uuid(service->uuid128)){ service->uuid16 = READ_NET_32(service->uuid128, 0); } @@ -452,7 +452,7 @@ void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint16_t siz case GATT_SERVICE_QUERY_RESULT: switch (central_state){ case CENTRAL_W4_PRIMARY_SERVICES: - extract_service(&service, packet); + extract_service(&service, &packet[4]); printf("Primary Service with UUID "); printUUID(service.uuid128, service.uuid16); printf(", start group handle 0x%04x, end group handle 0x%04x\n", service.start_group_handle, service.end_group_handle); @@ -462,10 +462,12 @@ void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint16_t siz } break; case GATT_INCLUDED_SERVICE_QUERY_RESULT: - extract_service(&service, packet); - printf("Included Service with UUID "); + value_handle = READ_BT_16(packet, 4); + extract_service(&service, &packet[6]); + printf("Included Service at 0x%004x: ", value_handle); + printf("start group handle 0x%04x, end group handle 0x%04x with UUID ", service.start_group_handle, service.end_group_handle); printUUID(service.uuid128, service.uuid16); - printf(", start group handle 0x%04x, end group handle 0x%04x\n", service.start_group_handle, service.end_group_handle); + printf("\n"); break; case GATT_CHARACTERISTIC_QUERY_RESULT: extract_characteristic(&characteristic, packet);