diff --git a/test/security_manager/Makefile b/test/security_manager/Makefile index 18ff74085..df679254f 100644 --- a/test/security_manager/Makefile +++ b/test/security_manager/Makefile @@ -17,6 +17,7 @@ VPATH += ${BTSTACK_ROOT}/platform/posix VPATH += ${BTSTACK_ROOT}/3rd-party/micro-ecc COMMON = \ + btstack_crypto.c \ btstack_linked_list.c \ btstack_memory.c \ btstack_memory_pool.c \ @@ -69,4 +70,4 @@ clean: rm -f security_manager aestest ecc_micro_ecc aes_cmac_test rm -f *.o rm -rf *.dSYM - \ No newline at end of file + diff --git a/test/security_manager/mock.c b/test/security_manager/mock.c index 6d6399692..a954cb7d0 100644 --- a/test/security_manager/mock.c +++ b/test/security_manager/mock.c @@ -8,10 +8,9 @@ #include "hci_dump.h" #include "l2cap.h" #include "rijndael.h" - +#include "btstack_linked_list.h" static btstack_packet_handler_t le_data_handler; -static btstack_packet_handler_t event_packet_handler; static uint8_t packet_buffer[256]; static uint16_t packet_buffer_len = 0; @@ -20,6 +19,7 @@ static uint8_t aes128_cyphertext[16]; static hci_connection_t the_connection; static btstack_linked_list_t connections; +static btstack_linked_list_t event_packet_handlers; void mock_init(void){ the_connection.item.next = NULL; @@ -58,9 +58,12 @@ 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, 0, packet, size); - } + btstack_linked_list_iterator_t it; + btstack_linked_list_iterator_init(&it ,&event_packet_handlers); + while (btstack_linked_list_iterator_has_next(&it)){ + btstack_packet_callback_registration_t * item = (btstack_packet_callback_registration_t *) btstack_linked_list_iterator_next(&it); + item->callback(HCI_EVENT_PACKET, 0, packet, size); + } if (le_data_handler){ le_data_handler(HCI_EVENT_PACKET, 0, packet, size); } @@ -207,7 +210,7 @@ void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint1 } void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler){ - event_packet_handler = callback_handler->callback; + btstack_linked_list_add(&event_packet_handlers, (btstack_linked_item_t *) callback_handler); } int l2cap_reserve_packet_buffer(void){ @@ -256,4 +259,4 @@ void l2cap_run(void){ HCI_STATE hci_get_state(void){ return HCI_STATE_WORKING; -} \ No newline at end of file +} diff --git a/test/security_manager/security_manager.c b/test/security_manager/security_manager.c index c0b89887b..d5a91546b 100644 --- a/test/security_manager/security_manager.c +++ b/test/security_manager/security_manager.c @@ -209,6 +209,9 @@ static void cmac_done(uint8_t * hash){ } static uint8_t m[128]; + +#if 0 +// CMAC calculation has been moved to btstack_crypto static uint8_t get_byte(uint16_t offset){ // printf ("get byte %02u -> %02x\n", offset, m[offset]); return m[offset]; @@ -235,6 +238,7 @@ static void validate_message(const char * name, const char * message_string, con } CHECK_EQUAL_ARRAY(cmac, cmac_hash, 16); } +#endif #define VALIDATE_MESSAGE(NAME) validate_message(#NAME, NAME##_string, cmac_##NAME##_string) @@ -244,15 +248,17 @@ TEST_GROUP(SecurityManager){ if (first){ first = 0; btstack_memory_init(); - btstack_run_loop_init(btstack_run_loop_posix_get_instance()); + btstack_run_loop_init(btstack_run_loop_posix_get_instance()); } sm_init(); sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT); sm_set_authentication_requirements( SM_AUTHREQ_BONDING ); sm_event_callback_registration.callback = &app_packet_handler; - sm_add_event_handler(&sm_event_callback_registration); } + sm_add_event_handler(&sm_event_callback_registration); + } }; +#if 0 TEST(SecurityManager, CMACTest){ mock_init(); @@ -288,6 +294,7 @@ TEST(SecurityManager, CMACTest){ VALIDATE_MESSAGE(m40); VALIDATE_MESSAGE(m64); } +#endif TEST(SecurityManager, MainTest){ @@ -296,7 +303,6 @@ TEST(SecurityManager, MainTest){ // expect le encrypt commmand CHECK_HCI_COMMAND(test_command_packet_01); - aes128_report_result(); // expect le encrypt commmand @@ -440,6 +446,6 @@ TEST(SecurityManager, MainTest){ } int main (int argc, const char * argv[]){ - // hci_dump_open("hci_dump.pklg", HCI_DUMP_PACKETLOGGER); + // hci_dump_open("hci_dump.pklg", HCI_DUMP_STDOUT); // HCI_DUMP_PACKETLOGGER return CommandLineTestRunner::RunAllTests(argc, argv); }