From bac1ffdb4f06305c7b28e70655444f5c4038c009 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 3 Apr 2015 22:42:05 +0200 Subject: [PATCH] add gatt_get_mtu daemon command and GATT_MTU response event --- include/btstack/hci_cmds.h | 7 +++++++ platforms/posix/src/daemon.c | 18 ++++++++++++++++++ src/hci.h | 1 + src/hci_cmds.c | 7 +++++++ 4 files changed, 33 insertions(+) diff --git a/include/btstack/hci_cmds.h b/include/btstack/hci_cmds.h index 9ad4fb1b8..c36f7f105 100644 --- a/include/btstack/hci_cmds.h +++ b/include/btstack/hci_cmds.h @@ -535,6 +535,13 @@ extern "C" { #define GATT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT 0xA9 #define GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT 0xAA +/** + * @format H2 + * @param handle + * @param MTU + */ +#define GATT_MTU 0xAB + /** * @format H2 * @param handle diff --git a/platforms/posix/src/daemon.c b/platforms/posix/src/daemon.c index d323a4a98..32297cc9a 100644 --- a/platforms/posix/src/daemon.c +++ b/platforms/posix/src/daemon.c @@ -564,6 +564,19 @@ static void send_gatt_query_complete(connection_t * connection, uint16_t handle, socket_connection_send_packet(connection, HCI_EVENT_PACKET, 0, event, sizeof(event)); } +static void send_gatt_mtu_event(connection_t * connection, uint16_t handle, uint16_t mtu){ + uint8_t event[6]; + int pos = 0; + event[pos++] = GATT_MTU; + event[pos++] = sizeof(event) - 2; + bt_store_16(event, pos, handle); + pos += 2; + bt_store_16(event, pos, mtu); + pos += 2; + hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); + socket_connection_send_packet(connection, HCI_EVENT_PACKET, 0, event, sizeof(event)); +} + linked_list_gatt_client_helper_t * daemon_setup_gatt_client_request(connection_t *connection, uint8_t *packet) { hci_con_handle_t handle = READ_BT_16(packet, 3); log_info("daemon_setup_gatt_client_request for handle 0x%02x", handle); @@ -1063,6 +1076,11 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui daemon_gatt_deserialize_characteristic(packet, 5, &characteristic); gatt_client_write_client_characteristic_configuration(gatt_client_id, gatt_helper->con_handle, &characteristic, configuration); break; + case GATT_GET_MTU: + handle = READ_BT_16(packet, 3); + gatt_client_get_mtu(handle, &mtu); + send_gatt_mtu_event(connection, handle, mtu); + break; } #endif default: diff --git a/src/hci.h b/src/hci.h index 36e4de2b4..c66792b66 100644 --- a/src/hci.h +++ b/src/hci.h @@ -230,6 +230,7 @@ extern "C" { #define GATT_WRITE_CHARACTERISTIC_DESCRIPTOR 0X7F #define GATT_WRITE_LONG_CHARACTERISTIC_DESCRIPTOR 0X80 #define GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION 0X81 +#define GATT_GET_MTU 0x82 // #define IS_COMMAND(packet, command) (READ_BT_16(packet,0) == command.opcode) diff --git a/src/hci_cmds.c b/src/hci_cmds.c index e89696a20..05b607220 100644 --- a/src/hci_cmds.c +++ b/src/hci_cmds.c @@ -1400,3 +1400,10 @@ const hci_cmd_t gatt_write_long_characteristic_descriptor_cmd = { const hci_cmd_t gatt_write_client_characteristic_configuration_cmd = { OPCODE(OGF_BTSTACK, GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION), "HY2" }; + +/** + * @param handle + */ +const hci_cmd_t gatt_get_mtu = { + OPCODE(OGF_BTSTACK, GATT_GET_MTU), "H" +};