From cce7df86ec53327ae238470bf46b637c5a105778 Mon Sep 17 00:00:00 2001 From: "mila@ringwald.ch" Date: Fri, 4 Apr 2014 09:26:52 +0000 Subject: [PATCH] ble client: support for characteristic descriptor with UUID128 --- example/libusb/ble_client.c | 66 ++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/example/libusb/ble_client.c b/example/libusb/ble_client.c index a3aee4b5a..2c82440d7 100644 --- a/example/libusb/ble_client.c +++ b/example/libusb/ble_client.c @@ -87,13 +87,6 @@ void (*le_central_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); -static void dump_characteristic(le_characteristic_t * characteristic){ - printf(" *** characteristic *** properties %x, start handle 0x%02x, value handle 0x%02x, end handle 0x%02x, uuid16 0x%02x, uuid128 ", - characteristic->properties, characteristic->start_handle, characteristic->value_handle, - characteristic->end_handle, characteristic->uuid16); - printUUID128(characteristic->uuid128); - printf("\n"); -} void le_central_init(){ state = W4_ON; @@ -122,6 +115,7 @@ static void gatt_client_run(); static uint16_t l2cap_max_mtu_for_handle(uint16_t handle){ return l2cap_max_mtu(); } + // END Helper Functions static le_command_status_t att_confirmation(uint16_t peripheral_handle){ @@ -859,10 +853,12 @@ le_command_status_t le_central_write_client_characteristic_configuration(le_peri le_command_status_t le_central_read_characteristic_descriptor(le_peripheral_t *peripheral, le_characteristic_descriptor_t * descriptor){ if (peripheral->state != P_CONNECTED) return BLE_PERIPHERAL_IN_WRONG_STATE; peripheral->query_start_handle = descriptor->handle; + peripheral->uuid16 = descriptor->uuid16; if (!descriptor->uuid16){ memcpy(peripheral->uuid128, descriptor->uuid128, 16); } + peripheral->state = P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY; gatt_client_run(); return BLE_PERIPHERAL_OK; @@ -1174,13 +1170,39 @@ static void report_gatt_characteristic_descriptor(le_peripheral_t * peripheral, descriptor.uuid16 = uuid16; if (uuid128){ memcpy(descriptor.uuid128, uuid128, 16); + } else { + sdp_normalize_uuid((uint8_t*) &descriptor.uuid128, descriptor.uuid16); } + descriptor.value = value; descriptor.value_length = value_length; event.characteristic_descriptor = descriptor; (*le_central_callback)((le_central_event_t*)&event); } +static void report_gatt_all_characteristic_descriptors(le_peripheral_t * peripheral, uint8_t * packet, uint16_t size, uint16_t pair_size){ + le_characteristic_descriptor_t descriptor; + le_characteristic_descriptor_event_t event; + event.type = GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT; + + int i; + for (i = 0; iend_group_handle){ peripheral->start_group_handle = last_result_handle + 1; @@ -1363,20 +1385,14 @@ static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pa case ATT_FIND_INFORMATION_REPLY: { uint8_t pair_size = 4; - le_characteristic_descriptor_t descriptor; - le_characteristic_descriptor_event_t event; - event.type = GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT; - - int i; - for (i = 2; iproperties, characteristic->start_handle, characteristic->value_handle, characteristic->end_handle); + printUUID(characteristic->uuid128, characteristic->uuid16); +} + static void dump_ad_event(ad_event_t * e){ printf(" *** adv. event *** evt-type %u, addr-type %u, addr %s, rssi %u, length adv %u, data: ", e->event_type, e->address_type, bd_addr_to_str(e->address), e->rssi, e->length);