From d9a7306a10f9a1b4dcae1f7fca484233f49c6707 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 4 Feb 2016 17:45:02 +0100 Subject: [PATCH] hci/sm: use btstack_packet_handler instead of (*fn)(type,packet,size) for events --- example/embedded/ancs_client_demo.c | 8 ++----- example/embedded/gap_dedicated_bonding.c | 2 +- example/embedded/gap_inquiry.c | 2 +- example/embedded/gap_inquiry_and_bond.c | 2 +- example/embedded/gap_le_advertisements.c | 4 ++-- example/embedded/gatt_battery_query.c | 2 +- example/embedded/gatt_browser.c | 4 ++-- example/embedded/hsp_hs_test.c | 5 ++-- example/embedded/le_counter.c | 4 ++-- example/embedded/le_streamer.c | 7 +----- example/embedded/panu_demo.c | 7 +----- example/embedded/sdp_bnep_query.c | 4 ++-- example/embedded/sdp_general_query.c | 4 ++-- example/embedded/sdp_rfcomm_query.c | 2 +- example/embedded/spp_and_le_counter.c | 6 +---- example/embedded/spp_counter.c | 6 +---- example/embedded/spp_streamer.c | 5 +--- platform/daemon/daemon.c | 5 +--- port/ez430-rf2560/example/ant_test.c | 6 +---- port/ez430-rf2560/example/spp_accel.c | 6 +---- .../example/ant_test.c | 5 +--- .../example/hid_demo.c | 5 +--- .../example/spp_accel.c | 5 +--- src/ble/ancs_client.c | 7 ++++-- src/ble/att_server.c | 8 ++----- src/ble/gatt_client.c | 4 ++-- src/ble/sm.c | 4 ++-- src/btstack_util.h | 6 ++--- src/classic/hfp_ag.c | 6 +---- src/classic/hfp_hf.c | 6 +---- src/classic/hsp_ag.c | 6 +---- src/classic/hsp_hs.c | 6 +---- src/hci.c | 2 +- src/l2cap.c | 23 +++++-------------- test/ble_client/advertising_data_parser.c | 2 +- test/security_manager/mock.c | 6 ++--- test/security_manager/security_manager.c | 6 +---- 37 files changed, 61 insertions(+), 137 deletions(-) diff --git a/example/embedded/ancs_client_demo.c b/example/embedded/ancs_client_demo.c index 7e01865e6..cb9c58c21 100644 --- a/example/embedded/ancs_client_demo.c +++ b/example/embedded/ancs_client_demo.c @@ -124,17 +124,13 @@ static void ancs_callback(uint8_t packet_type, uint8_t *packet, uint16_t size){ } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - app_packet_handler(packet_type, 0, packet, size); -} - int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ printf("BTstack ANCS Client starting up...\n"); // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &app_packet_handler; hci_add_event_handler(&hci_event_callback_registration); // set up l2cap_le @@ -149,7 +145,7 @@ int btstack_main(int argc, const char * argv[]){ sm_set_authentication_requirements( SM_AUTHREQ_BONDING ); // register for SM events - sm_event_callback_registration.callback = &hci_event_handler; + sm_event_callback_registration.callback = &app_packet_handler; hci_add_event_handler(&sm_event_callback_registration); // setup ATT server diff --git a/example/embedded/gap_dedicated_bonding.c b/example/embedded/gap_dedicated_bonding.c index 61c59f359..4cfcd67d8 100644 --- a/example/embedded/gap_dedicated_bonding.c +++ b/example/embedded/gap_dedicated_bonding.c @@ -56,7 +56,7 @@ static bd_addr_t remote = {0x84, 0x38, 0x35, 0x65, 0xD1, 0x15}; static btstack_packet_callback_registration_t hci_event_callback_registration; -static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ if (packet_type != HCI_EVENT_PACKET) return; switch (packet[0]) { diff --git a/example/embedded/gap_inquiry.c b/example/embedded/gap_inquiry.c index 0d7b1832a..86355e4cb 100644 --- a/example/embedded/gap_inquiry.c +++ b/example/embedded/gap_inquiry.c @@ -137,7 +137,7 @@ static void continue_remote_names(void){ * INIT, and ACTIVE. */ -static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ bd_addr_t addr; int i; int numResponses; diff --git a/example/embedded/gap_inquiry_and_bond.c b/example/embedded/gap_inquiry_and_bond.c index 469cd35ae..6e765bf3b 100644 --- a/example/embedded/gap_inquiry_and_bond.c +++ b/example/embedded/gap_inquiry_and_bond.c @@ -126,7 +126,7 @@ static void continue_bonding(void){ start_scan(); } -static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ bd_addr_t addr; int i; int numResponses; diff --git a/example/embedded/gap_le_advertisements.c b/example/embedded/gap_le_advertisements.c index 92f98de09..855e78641 100644 --- a/example/embedded/gap_le_advertisements.c +++ b/example/embedded/gap_le_advertisements.c @@ -66,7 +66,7 @@ static btstack_packet_callback_registration_t hci_event_callback_registration; */ /* LISTING_START(GAPLEAdvSetup): Setting up GAP LE client for receiving advertisements */ -static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size); +static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); static void gap_le_advertisements_setup(void){ hci_event_callback_registration.callback = &packet_handler; @@ -228,7 +228,7 @@ static void dump_advertisement_data(uint8_t * adv_data, uint8_t adv_size){ /* LISTING_START(GAPLEAdvPacketHandler): Scanning and receiving advertisements */ -static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ if (packet_type != HCI_EVENT_PACKET) return; switch (packet[0]) { diff --git a/example/embedded/gatt_battery_query.c b/example/embedded/gatt_battery_query.c index 89cb9045b..794872070 100644 --- a/example/embedded/gatt_battery_query.c +++ b/example/embedded/gatt_battery_query.c @@ -235,7 +235,7 @@ static void fill_advertising_report_from_packet(advertising_report_t * report, u dump_advertising_report(report); } -static void hci_event_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ if (packet_type != HCI_EVENT_PACKET) return; advertising_report_t report; uint8_t event = packet[0]; diff --git a/example/embedded/gatt_browser.c b/example/embedded/gatt_browser.c index b84a1e700..ec3c15463 100644 --- a/example/embedded/gatt_browser.c +++ b/example/embedded/gatt_browser.c @@ -106,7 +106,7 @@ static uint16_t gc_id; // Handles connect, disconnect, and advertising report events, // starts the GATT client, and sends the first query. -static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size); +static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); // Handles GATT client query results, sends queries and the // GAP disconnect command when the querying is done. @@ -185,7 +185,7 @@ static void fill_advertising_report_from_packet(advertising_report_t * report, u */ /* LISTING_START(GATTBrowserHCIPacketHandler): Connecting and disconnecting from the GATT client */ -static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ if (packet_type != HCI_EVENT_PACKET) return; advertising_report_t report; diff --git a/example/embedded/hsp_hs_test.c b/example/embedded/hsp_hs_test.c index d21f9f756..76ce26f5e 100644 --- a/example/embedded/hsp_hs_test.c +++ b/example/embedded/hsp_hs_test.c @@ -217,7 +217,8 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ break; } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ + +static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){ packet_handler(packet, size); } @@ -233,7 +234,7 @@ int btstack_main(int argc, const char * argv[]){ gap_set_local_name("BTstack HSP HS"); // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &handle_hci_event; hci_add_event_handler(&hci_event_callback_registration); // register for SCO packets diff --git a/example/embedded/le_counter.c b/example/embedded/le_counter.c index 98920bbfb..ab328cc9f 100644 --- a/example/embedded/le_counter.c +++ b/example/embedded/le_counter.c @@ -87,7 +87,7 @@ static int le_notification_enabled; static btstack_timer_source_t heartbeat; static btstack_packet_callback_registration_t hci_event_callback_registration; -static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size); +static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); static uint16_t att_read_callback(uint16_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size); static int att_write_callback(uint16_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size); static void heartbeat_handler(struct btstack_timer_source *ts); @@ -142,7 +142,7 @@ static void le_counter_setup(void){ */ /* LISTING_START(packetHandler): Packet Handler */ -static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ switch (packet_type) { case HCI_EVENT_PACKET: switch (packet[0]) { diff --git a/example/embedded/le_streamer.c b/example/embedded/le_streamer.c index 14ef2cb70..26b0c3be1 100644 --- a/example/embedded/le_streamer.c +++ b/example/embedded/le_streamer.c @@ -74,7 +74,6 @@ static int le_notification_enabled; static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size); static int att_write_callback(uint16_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size); static void streamer(void); static btstack_packet_callback_registration_t hci_event_callback_registration; @@ -106,7 +105,7 @@ static uint16_t conn_handle; static void le_streamer_setup(void){ // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); l2cap_init(); @@ -205,10 +204,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack streamer(); } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} - /* LISTING_END */ /* * @section Streamer diff --git a/example/embedded/panu_demo.c b/example/embedded/panu_demo.c index 17118f756..cff98e59d 100644 --- a/example/embedded/panu_demo.c +++ b/example/embedded/panu_demo.c @@ -135,13 +135,12 @@ static btstack_packet_callback_registration_t hci_event_callback_registration; /* LISTING_START(PanuSetup): Panu setup */ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size); static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, uint16_t size); static void panu_setup(void){ // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // Initialize L2CAP @@ -421,10 +420,6 @@ static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} - /* * @section Packet Handler * diff --git a/example/embedded/sdp_bnep_query.c b/example/embedded/sdp_bnep_query.c index 7c6731a4d..ebd64697f 100644 --- a/example/embedded/sdp_bnep_query.c +++ b/example/embedded/sdp_bnep_query.c @@ -89,7 +89,7 @@ static void assertBuffer(int size){ */ /* LISTING_START(SDPClientInit): SDP client setup */ -static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size); +static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, uint16_t size); static void sdp_client_init(void){ @@ -116,7 +116,7 @@ static void sdp_client_init(void){ */ /* LISTING_START(SDPQueryUUID): Querying the a list of service records on a remote device. */ -static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ if (packet_type != HCI_EVENT_PACKET) return; uint8_t event = packet[0]; diff --git a/example/embedded/sdp_general_query.c b/example/embedded/sdp_general_query.c index 73bdd8b1f..44330ff92 100644 --- a/example/embedded/sdp_general_query.c +++ b/example/embedded/sdp_general_query.c @@ -79,7 +79,7 @@ static btstack_packet_callback_registration_t hci_event_callback_registration; */ /* LISTING_START(SDPClientInit): SDP client setup */ -static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size); +static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); static void handle_sdp_client_query_result(uint8_t packet_type, uint8_t *packet, uint16_t size); static void sdp_client_init(void){ @@ -111,7 +111,7 @@ static bd_addr_t remote = {0x04,0x0C,0xCE,0xE4,0x85,0xD3}; /* LISTING_END */ /* LISTING_START(SDPQueryUUID): Querying a list of service records on a remote device. */ -static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ // printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]); if (packet_type != HCI_EVENT_PACKET) return; diff --git a/example/embedded/sdp_rfcomm_query.c b/example/embedded/sdp_rfcomm_query.c index d22e691ab..62cccbd68 100644 --- a/example/embedded/sdp_rfcomm_query.c +++ b/example/embedded/sdp_rfcomm_query.c @@ -68,7 +68,7 @@ static char* service_name[10]; static btstack_packet_callback_registration_t hci_event_callback_registration; -static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ // printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]); if (packet_type != HCI_EVENT_PACKET) return; diff --git a/example/embedded/spp_and_le_counter.c b/example/embedded/spp_and_le_counter.c index e9fba2cf8..ff3eda1f2 100644 --- a/example/embedded/spp_and_le_counter.c +++ b/example/embedded/spp_and_le_counter.c @@ -181,10 +181,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} - // ATT Client Read Callback for Dynamic Data // - if buffer == NULL, don't copy data, just return size of value // - if buffer != NULL, copy data and return number bytes copied @@ -257,7 +253,7 @@ int btstack_main(void) hci_discoverable_control(1); // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); l2cap_init(); diff --git a/example/embedded/spp_counter.c b/example/embedded/spp_counter.c index 692628d1e..b77bcd8e8 100644 --- a/example/embedded/spp_counter.c +++ b/example/embedded/spp_counter.c @@ -70,7 +70,6 @@ #define HEARTBEAT_PERIOD_MS 1000 static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size); static uint16_t rfcomm_channel_id; static uint8_t spp_service_buffer[150]; @@ -95,7 +94,7 @@ static btstack_packet_callback_registration_t hci_event_callback_registration; static void spp_service_setup(void){ // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); l2cap_init(); @@ -258,9 +257,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack } /* LISTING_RESUME */ } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} /* LISTING_END */ int btstack_main(int argc, const char * argv[]); diff --git a/example/embedded/spp_streamer.c b/example/embedded/spp_streamer.c index ad84614f6..e39c3ce1e 100644 --- a/example/embedded/spp_streamer.c +++ b/example/embedded/spp_streamer.c @@ -151,9 +151,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack break; } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} static void handle_found_service(const char * name, uint8_t port){ printf("APP: Service name: '%s', RFCOMM port %u\n", name, port); @@ -194,7 +191,7 @@ int btstack_main(int argc, const char * argv[]){ printf("Client HCI init done\r\n"); // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/platform/daemon/daemon.c b/platform/daemon/daemon.c index 136635ae8..4abff240b 100644 --- a/platform/daemon/daemon.c +++ b/platform/daemon/daemon.c @@ -1639,9 +1639,6 @@ static void daemon_packet_handler(void * connection, uint8_t packet_type, uint16 daemon_emit_packet(connection, packet_type, channel, packet, size); } -static void hci_packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - daemon_packet_handler(NULL, packet_type, 0, packet, size); -} static void l2cap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){ daemon_packet_handler(NULL, packet_type, channel, packet, size); } @@ -2073,7 +2070,7 @@ int main (int argc, char * const * argv){ #endif // register for HCI events - hci_event_callback_registration.callback = &hci_packet_handler; + hci_event_callback_registration.callback = &l2cap_packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/port/ez430-rf2560/example/ant_test.c b/port/ez430-rf2560/example/ant_test.c index 8650ea93c..ce87321f4 100644 --- a/port/ez430-rf2560/example/ant_test.c +++ b/port/ez430-rf2560/example/ant_test.c @@ -194,10 +194,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet, size); -} - static void heartbeat_handler(struct btstack_timer_source *ts){ if (rfcomm_channel_id){ @@ -221,7 +217,7 @@ int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/port/ez430-rf2560/example/spp_accel.c b/port/ez430-rf2560/example/spp_accel.c index 761bc0c14..b666410a0 100644 --- a/port/ez430-rf2560/example/spp_accel.c +++ b/port/ez430-rf2560/example/spp_accel.c @@ -198,10 +198,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack break; } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet, size); -} - int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ @@ -211,7 +207,7 @@ int btstack_main(int argc, const char * argv[]){ prepare_accel_packet(); // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/port/msp-exp430f5438-cc2564b/example/ant_test.c b/port/msp-exp430f5438-cc2564b/example/ant_test.c index 16b36c20d..33e42cf92 100644 --- a/port/msp-exp430f5438-cc2564b/example/ant_test.c +++ b/port/msp-exp430f5438-cc2564b/example/ant_test.c @@ -193,9 +193,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack break; } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet, size); -} static void heartbeat_handler(struct btstack_timer_source *ts){ @@ -220,7 +217,7 @@ int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/port/msp-exp430f5438-cc2564b/example/hid_demo.c b/port/msp-exp430f5438-cc2564b/example/hid_demo.c index 7b0b18f6d..2f49a2bb3 100644 --- a/port/msp-exp430f5438-cc2564b/example/hid_demo.c +++ b/port/msp-exp430f5438-cc2564b/example/hid_demo.c @@ -343,9 +343,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack } } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet, size); -} static hci_transport_config_uart_t config = { HCI_TRANSPORT_CONFIG_UART, @@ -389,7 +386,7 @@ int main(void){ btstack_chipset_cc256x_enable_ehcill(1); // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/port/msp-exp430f5438-cc2564b/example/spp_accel.c b/port/msp-exp430f5438-cc2564b/example/spp_accel.c index 17607f1c4..0ec9f8b7f 100644 --- a/port/msp-exp430f5438-cc2564b/example/spp_accel.c +++ b/port/msp-exp430f5438-cc2564b/example/spp_accel.c @@ -199,9 +199,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack break; } } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet, size); -} int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ @@ -211,7 +208,7 @@ int btstack_main(int argc, const char * argv[]){ prepare_accel_packet(); // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/src/ble/ancs_client.c b/src/ble/ancs_client.c index a02659ac5..60fb0282e 100644 --- a/src/ble/ancs_client.c +++ b/src/ble/ancs_client.c @@ -196,7 +196,7 @@ static void extract_characteristic(le_characteristic_t * characteristic, uint8_t } } -static void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ int connection_encrypted; @@ -353,9 +353,12 @@ static void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint1 } // app_run(); } +static void handle_gatt_client_event(uint8_t packet_type, uint8_t * packet, uint16_t size){ + handle_hci_event(packet_type, 0, packet, size); +} void ancs_client_init(void){ - hci_event_callback_registration.callback = &handle_gatt_client_event; + hci_event_callback_registration.callback = &handle_hci_event; hci_add_event_handler(&hci_event_callback_registration); gc_id = gatt_client_register_packet_handler(&handle_gatt_client_event); diff --git a/src/ble/att_server.c b/src/ble/att_server.c index 880ac4db0..cca240f45 100644 --- a/src/ble/att_server.c +++ b/src/ble/att_server.c @@ -354,18 +354,14 @@ 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_event_callback_registration.callback = &att_event_packet_handler; hci_add_event_handler(&hci_event_callback_registration); // register for SM events - sm_event_callback_registration.callback = &att_event_packet_handler2; + sm_event_callback_registration.callback = &att_event_packet_handler; sm_add_event_handler(&sm_event_callback_registration); // and L2CAP ATT Server PDUs diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index 2532d5070..70826cc4a 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -66,7 +66,7 @@ static uint8_t pts_suppress_mtu_exchange; static btstack_packet_callback_registration_t hci_event_callback_registration; static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); -static void gatt_client_hci_event_packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size); +static void gatt_client_hci_event_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); static void gatt_client_report_error_if_pending(gatt_client_t *peripheral, uint8_t error_code); static void att_signed_write_handle_cmac_result(uint8_t hash[8]); @@ -1034,7 +1034,7 @@ static void gatt_client_report_error_if_pending(gatt_client_t *peripheral, uint8 emit_gatt_complete_event(peripheral, error_code); } -static void gatt_client_hci_event_packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void gatt_client_hci_event_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ if (packet_type != HCI_EVENT_PACKET) return; switch (packet[0]) { diff --git a/src/ble/sm.c b/src/ble/sm.c index 0e5302f32..7e8340594 100644 --- a/src/ble/sm.c +++ b/src/ble/sm.c @@ -486,7 +486,7 @@ static void sm_dispatch_event(uint8_t packet_type, uint16_t channel, uint8_t * p btstack_linked_list_iterator_init(&it, &sm_event_handlers); while (btstack_linked_list_iterator_has_next(&it)){ btstack_packet_callback_registration_t * entry = (btstack_packet_callback_registration_t*) btstack_linked_list_iterator_next(&it); - entry->callback(packet_type, packet, size); + entry->callback(packet_type, 0, packet, size); } } @@ -1826,7 +1826,7 @@ static void sm_handle_random_result(uint8_t * data){ } } -static void sm_event_packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){ +static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ sm_connection_t * sm_conn; uint16_t handle; diff --git a/src/btstack_util.h b/src/btstack_util.h index 20c44dcc6..763632776 100644 --- a/src/btstack_util.h +++ b/src/btstack_util.h @@ -98,10 +98,10 @@ typedef uint8_t device_name_t[DEVICE_NAME_LEN+1]; // packet handler typedef void (*btstack_packet_handler_t) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); -// new packet callback supporting multiple registration +// packet callback supporting multiple registrations typedef struct { - btstack_linked_item_t item; - void (*callback)(uint8_t packet_type, uint8_t * packet, uint16_t size); + btstack_linked_item_t item; + btstack_packet_handler_t callback; } btstack_packet_callback_registration_t; diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c index bbeacdf75..dd7bab27f 100644 --- a/src/classic/hfp_ag.c +++ b/src/classic/hfp_ag.c @@ -1975,10 +1975,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe hfp_run(); } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} - static void hfp_ag_set_ag_indicators(hfp_ag_indicator_t * ag_indicators, int ag_indicators_nr){ hfp_ag_indicators_nr = ag_indicators_nr; memcpy(hfp_ag_indicators, ag_indicators, ag_indicators_nr * sizeof(hfp_ag_indicator_t)); @@ -1995,7 +1991,7 @@ void hfp_ag_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, } // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); l2cap_init(); diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c index 47aa72220..23d30d5a8 100644 --- a/src/classic/hfp_hf.c +++ b/src/classic/hfp_hf.c @@ -1024,10 +1024,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe hfp_run(); } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} - void hfp_hf_set_codecs(uint8_t * codecs, int codecs_nr){ if (codecs_nr > HFP_MAX_NUM_CODECS){ log_error("hfp_hf_set_codecs: codecs_nr (%d) > HFP_MAX_NUM_CODECS (%d)", codecs_nr, HFP_MAX_NUM_CODECS); @@ -1056,7 +1052,7 @@ void hfp_hf_set_codecs(uint8_t * codecs, int codecs_nr){ void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint16_t * indicators, int indicators_nr, uint32_t indicators_status){ // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); l2cap_init(); diff --git a/src/classic/hsp_ag.c b/src/classic/hsp_ag.c index 0071260c6..8c37c34e0 100644 --- a/src/classic/hsp_ag.c +++ b/src/classic/hsp_ag.c @@ -257,13 +257,9 @@ static void hsp_ag_reset_state(void){ ag_speaker_gain = -1; } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} - void hsp_ag_init(uint8_t rfcomm_channel_nr){ // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/src/classic/hsp_hs.c b/src/classic/hsp_hs.c index 7097f048c..f639c9d4c 100644 --- a/src/classic/hsp_hs.c +++ b/src/classic/hsp_hs.c @@ -255,13 +255,9 @@ static void hsp_hs_reset_state(void){ hs_support_custom_indications = 0; } -static void hci_event_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ - packet_handler(packet_type, 0, packet, size); -} - void hsp_hs_init(uint8_t rfcomm_channel_nr){ // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; + hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // init L2CAP diff --git a/src/hci.c b/src/hci.c index e35fb25bd..152bd9707 100644 --- a/src/hci.c +++ b/src/hci.c @@ -2880,7 +2880,7 @@ static void hci_emit_event(uint8_t * event, uint16_t size, int dump){ btstack_linked_list_iterator_init(&it, &hci_stack->event_handlers); while (btstack_linked_list_iterator_has_next(&it)){ btstack_packet_callback_registration_t * entry = (btstack_packet_callback_registration_t*) btstack_linked_list_iterator_next(&it); - entry->callback(HCI_EVENT_PACKET, event, size); + entry->callback(HCI_EVENT_PACKET, 0, event, size); } } diff --git a/src/l2cap.c b/src/l2cap.c index 2af4cf76e..f09433462 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -67,7 +67,6 @@ #define L2CAP_SIGNALING_COMMAND_DATA_OFFSET 4 static void null_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); -static void l2cap_packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size); // used to cache l2cap rejects, echo, and informational requests static l2cap_signaling_response_t signaling_responses[NR_PENDING_SIGNALING_RESPONSES]; @@ -93,6 +92,8 @@ static void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status); static void l2cap_emit_channel_closed(l2cap_channel_t *channel); static void l2cap_emit_connection_request(l2cap_channel_t *channel); static int l2cap_channel_ready_for_open(l2cap_channel_t *channel); +static void l2cap_hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); +static void l2cap_acl_handler(uint8_t packet_type, uint8_t *packet, uint16_t size ); void l2cap_init(void){ @@ -113,10 +114,10 @@ void l2cap_init(void){ // // register callback with HCI // - hci_event_callback_registration.callback = &l2cap_packet_handler; + hci_event_callback_registration.callback = &l2cap_hci_event_handler; hci_add_event_handler(&hci_event_callback_registration); - hci_register_acl_packet_handler(&l2cap_packet_handler); + hci_register_acl_packet_handler(&l2cap_acl_handler); hci_connectable_control(0); // no services yet } @@ -818,7 +819,7 @@ static void l2cap_handle_connection_success_for_addr(bd_addr_t address, hci_con_ l2cap_run(); } -static void l2cap_event_handler(uint8_t *packet, uint16_t size){ +static void l2cap_hci_event_handler(uint8_t packet_type, uint16_t cid, uint8_t *packet, uint16_t size){ bd_addr_t address; hci_con_handle_t handle; @@ -1296,7 +1297,7 @@ static void l2cap_signaling_handler_dispatch( hci_con_handle_t handle, uint8_t * } } -static void l2cap_acl_handler( uint8_t *packet, uint16_t size ){ +static void l2cap_acl_handler(uint8_t packet_type, uint8_t *packet, uint16_t size ){ // Get Channel ID uint16_t channel_id = READ_L2CAP_CHANNEL_ID(packet); @@ -1409,19 +1410,7 @@ static void l2cap_acl_handler( uint8_t *packet, uint16_t size ){ break; } } -} -static void l2cap_packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ - switch (packet_type) { - case HCI_EVENT_PACKET: - l2cap_event_handler(packet, size); - break; - case HCI_ACL_DATA_PACKET: - l2cap_acl_handler(packet, size); - break; - default: - break; - } l2cap_run(); } diff --git a/test/ble_client/advertising_data_parser.c b/test/ble_client/advertising_data_parser.c index 96e66684f..543ad0767 100644 --- a/test/ble_client/advertising_data_parser.c +++ b/test/ble_client/advertising_data_parser.c @@ -113,7 +113,7 @@ static hci_transport_t dummy_transport = { }; -void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ +void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ CHECK_EQUAL(0xE2, packet[2]); // event type CHECK_EQUAL(0x01, packet[3]); // address type CHECK_EQUAL_ARRAY(expected_bt_addr, &packet[4], 6); diff --git a/test/security_manager/mock.c b/test/security_manager/mock.c index faadfa69c..6d93ba058 100644 --- a/test/security_manager/mock.c +++ b/test/security_manager/mock.c @@ -11,7 +11,7 @@ static btstack_packet_handler_t le_data_handler; -static void (*event_packet_handler) (uint8_t packet_type, uint8_t *packet, uint16_t size) = NULL; +static btstack_packet_handler_t event_packet_handler; static uint8_t packet_buffer[256]; static uint16_t packet_buffer_len = 0; @@ -59,10 +59,10 @@ void aes128_calc_cyphertext(uint8_t key[16], uint8_t plaintext[16], uint8_t cyph void mock_simulate_hci_event(uint8_t * packet, uint16_t size){ hci_dump_packet(HCI_EVENT_PACKET, 1, packet, size); if (event_packet_handler){ - event_packet_handler(HCI_EVENT_PACKET, packet, size); + event_packet_handler(HCI_EVENT_PACKET, 0, packet, size); } if (le_data_handler){ - le_data_handler(HCI_EVENT_PACKET, NULL, packet, size); + le_data_handler(HCI_EVENT_PACKET, 0, packet, size); } } diff --git a/test/security_manager/security_manager.c b/test/security_manager/security_manager.c index dddda2d88..2d4861e84 100644 --- a/test/security_manager/security_manager.c +++ b/test/security_manager/security_manager.c @@ -159,10 +159,6 @@ void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, } } -static void att_event_packet_handler2(uint8_t packet_type, uint8_t * packet, uint16_t size){ - app_packet_handler(packet_type, 0, packet, size); -} - void CHECK_EQUAL_ARRAY(uint8_t * expected, uint8_t * actual, int size){ int i; for (i=0; i