From 1a389cdc721d4d404ab7d0eb33182fc392a58507 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 3 Feb 2016 19:58:50 +0100 Subject: [PATCH] att_dispatch: don't forward HCI Events to ATT Server. ATT Server registers for HCI Events --- src/ble/att_dispatch.c | 17 ----------------- src/ble/att_server.c | 12 +++++++++++- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/ble/att_dispatch.c b/src/ble/att_dispatch.c index 15ce57554..b28cb5caa 100644 --- a/src/ble/att_dispatch.c +++ b/src/ble/att_dispatch.c @@ -50,24 +50,9 @@ static void dummy_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t * static btstack_packet_handler_t att_client_handler = &dummy_packet_handler; static btstack_packet_handler_t att_server_handler = &dummy_packet_handler; -static btstack_packet_callback_registration_t hci_event_callback_registration; - -static int registered_for_hci_events = 0; - static void dummy_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size){ } -static void att_hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - att_server_handler(packet_type, 0, packet, size); -} - -static void att_dispatch_register_for_hci_events(void){ - if (registered_for_hci_events) return; - registered_for_hci_events = 1; - hci_event_callback_registration.callback = &att_hci_event_handler; - hci_add_event_handler(&hci_event_callback_registration); -} - static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size){ if (packet_type != ATT_DATA_PACKET) return; @@ -87,7 +72,6 @@ static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pa * @param packet_hander for ATT client packets */ void att_dispatch_register_client(btstack_packet_handler_t packet_handler){ - att_dispatch_register_for_hci_events(); if (packet_handler == NULL){ packet_handler = dummy_packet_handler; } @@ -100,7 +84,6 @@ void att_dispatch_register_client(btstack_packet_handler_t packet_handler){ * @param packet_hander for ATT server packets */ void att_dispatch_register_server(btstack_packet_handler_t packet_handler){ - att_dispatch_register_for_hci_events(); if (packet_handler == NULL){ packet_handler = dummy_packet_handler; } diff --git a/src/ble/att_server.c b/src/ble/att_server.c index f535419ee..c534a6f43 100644 --- a/src/ble/att_server.c +++ b/src/ble/att_server.c @@ -91,7 +91,7 @@ static int att_ir_lookup_active = 0; static int att_handle_value_indication_handle = 0; static btstack_timer_source_t att_handle_value_indication_timer; - +static btstack_packet_callback_registration_t hci_event_callback_registration; static btstack_packet_handler_t att_client_packet_handler = NULL; static void att_handle_value_indication_notify_client(uint8_t status, uint16_t client_handle, uint16_t attribute_handle){ @@ -355,10 +355,20 @@ static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pa att_run(); } +static void att_event_packet_handler2(uint8_t packet_type, uint8_t * packet, uint16_t size){ + att_event_packet_handler(packet_type, 0, packet, size); +} + void att_server_init(uint8_t const * db, att_read_callback_t read_callback, att_write_callback_t write_callback){ + // register for HCI Events + hci_event_callback_registration.callback = &att_event_packet_handler2; + hci_add_event_handler(&hci_event_callback_registration); + + // SM events sm_register_packet_handler(att_event_packet_handler); + // and L2CAP ATT Server PDUs att_dispatch_register_server(att_packet_handler); att_server_state = ATT_SERVER_IDLE;