From 406722e45a194a24427949e4812cd93ac915bfc6 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 4 Feb 2016 16:20:00 +0100 Subject: [PATCH] sm: replace sm_register_packet_handler with sm_add_event_handler --- src/ble/att_server.c | 6 ++++-- src/ble/sm.c | 4 ---- src/ble/sm.h | 6 ------ test/pts/ble_central_test.c | 18 ++++++++++++++++-- test/pts/sco_loopback.c | 7 +++++-- test/security_manager/security_manager.c | 9 +++++++-- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/ble/att_server.c b/src/ble/att_server.c index c534a6f43..f86da4eca 100644 --- a/src/ble/att_server.c +++ b/src/ble/att_server.c @@ -92,6 +92,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_callback_registration_t sm_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){ @@ -365,8 +366,9 @@ void att_server_init(uint8_t const * db, att_read_callback_t read_callback, att_ 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); + // register for SM events + sm_event_callback_registration.callback = &att_event_packet_handler2; + sm_add_event_handler(&sm_event_callback_registration); // and L2CAP ATT Server PDUs att_dispatch_register_server(att_packet_handler); diff --git a/src/ble/sm.c b/src/ble/sm.c index 02fb211ea..194ef7167 100644 --- a/src/ble/sm.c +++ b/src/ble/sm.c @@ -2265,10 +2265,6 @@ void sm_register_oob_data_callback( int (*get_oob_data_callback)(uint8_t addres_ sm_get_oob_data = get_oob_data_callback; } -void sm_register_packet_handler(btstack_packet_handler_t handler){ - sm_client_packet_handler = handler; -} - void sm_add_event_handler(btstack_packet_callback_registration_t * callback_handler){ btstack_linked_list_add_tail(&sm_event_handlers, (btstack_linked_item_t*) callback_handler); } diff --git a/src/ble/sm.h b/src/ble/sm.h index 1dc786f39..c605c5c1e 100644 --- a/src/ble/sm.h +++ b/src/ble/sm.h @@ -80,12 +80,6 @@ void sm_set_ir(sm_key_t ir); */ void sm_register_oob_data_callback( int (*get_oob_data_callback)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_data)); -/** - * - * @brief Registers packet handler. Called by att_server.c - */ -void sm_register_packet_handler(btstack_packet_handler_t handler); - /** * @brief Add event packet handler. */ diff --git a/test/pts/ble_central_test.c b/test/pts/ble_central_test.c index ec8abafa4..9b4c2489c 100644 --- a/test/pts/ble_central_test.c +++ b/test/pts/ble_central_test.c @@ -198,6 +198,9 @@ static le_characteristic_t gap_peripheral_privacy_flag_characteristic; static le_characteristic_t signed_write_characteristic; static le_service_t service; +static btstack_packet_callback_registration_t hci_event_callback_registration; +static btstack_packet_callback_registration_t sm_event_callback_registration; + static void show_usage(); /// @@ -330,7 +333,7 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t * case BTSTACK_EVENT_STATE: // bt stack activated, get started if (packet[2] == HCI_STATE_WORKING) { - printf("SM Init completed\n"); + printf("Central test ready\n"); show_usage(); gap_run(); } @@ -1664,6 +1667,10 @@ static uint16_t att_read_callback(uint16_t con_handle, uint16_t attribute_handle return 0; } +static void att_event_packet_handler2(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[]){ @@ -1674,12 +1681,19 @@ int btstack_main(int argc, const char * argv[]){ strcpy(gap_device_name, "BTstack"); + // register for HCI Events + hci_event_callback_registration.callback = &att_event_packet_handler2; + hci_add_event_handler(&hci_event_callback_registration); + + // register for SM events + sm_event_callback_registration.callback = &att_event_packet_handler2; + sm_add_event_handler(&sm_event_callback_registration); + // set up l2cap_le l2cap_init(); // Setup SM: Display only sm_init(); - sm_register_packet_handler(app_packet_handler); sm_register_oob_data_callback(get_oob_data_callback); sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT); sm_io_capabilities = "IO_CAPABILITY_NO_INPUT_NO_OUTPUT"; diff --git a/test/pts/sco_loopback.c b/test/pts/sco_loopback.c index 4966271b3..2b76825c6 100644 --- a/test/pts/sco_loopback.c +++ b/test/pts/sco_loopback.c @@ -50,7 +50,9 @@ #include "hci.h" #include "btstack_debug.h" -uint16_t sco_handle = 0; +static uint16_t sco_handle = 0; + +static btstack_packet_callback_registration_t hci_event_callback_registration; static void try_send_sco(void){ if (!sco_handle) return; @@ -94,7 +96,8 @@ static void packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t event int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ - hci_register_packet_handler(&packet_handler); + hci_event_callback_registration.callback = &packet_handler; + hci_add_event_handler(&hci_event_callback_registration); // turn on! hci_power_control(HCI_POWER_ON); diff --git a/test/security_manager/security_manager.c b/test/security_manager/security_manager.c index cf57802de..dddda2d88 100644 --- a/test/security_manager/security_manager.c +++ b/test/security_manager/security_manager.c @@ -108,6 +108,8 @@ uint8_t test_acl_packet_22[] = { bd_addr_t test_device_addr = {0x34, 0xb1, 0xf7, 0xd1, 0x77, 0x9b}; +static btstack_packet_callback_registration_t sm_event_callback_registration; + void mock_init(void); void mock_simulate_hci_state_working(void); void mock_simulate_hci_event(uint8_t * packet, uint16_t size); @@ -157,6 +159,9 @@ 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; @@ -181,8 +186,8 @@ TEST_GROUP(SecurityManager){ sm_init(); sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT); sm_set_authentication_requirements( SM_AUTHREQ_BONDING ); - sm_register_packet_handler(app_packet_handler); - } + sm_event_callback_registration.callback = &att_event_packet_handler2; + sm_add_event_handler(&sm_event_callback_registration); } }; TEST(SecurityManager, MainTest){