diff --git a/platforms/ios/CocoaTouch/src/BTDevice.m b/platforms/ios/CocoaTouch/src/BTDevice.m index 905f7c352..2f2efa548 100644 --- a/platforms/ios/CocoaTouch/src/BTDevice.m +++ b/platforms/ios/CocoaTouch/src/BTDevice.m @@ -90,7 +90,7 @@ // store if (result == 6){ for (i = 0; i < BD_ADDR_LEN; i++) { - (*address)[i] = (uint8_t) bd_addr_buffer[i]; + address[i] = (uint8_t) bd_addr_buffer[i]; } return YES; } @@ -103,7 +103,7 @@ } - (NSString *) addressString{ - return [BTDevice stringForAddress:&_address]; + return [BTDevice stringForAddress:_address]; } - (BluetoothDeviceType) deviceType{ @@ -117,7 +117,7 @@ } } - (NSString *) toString{ - return [NSString stringWithFormat:@"Device addr %@ name %@ COD %x", [BTDevice stringForAddress:&_address], name, classOfDevice]; + return [NSString stringWithFormat:@"Device addr %@ name %@ COD %x", [BTDevice stringForAddress:_address], name, classOfDevice]; } - (void)dealloc { diff --git a/platforms/ios/README.md b/platforms/ios/README.md index cb37d2a5d..771d038bf 100644 --- a/platforms/ios/README.md +++ b/platforms/ios/README.md @@ -1,16 +1,16 @@ === BTstack for iOS === -BTstack for iOS provides an alternative Bluetooth stack for iOS devices with a public and complete API. +BTstack for iOS provides an alternative Bluetooth stack for iOS devices with a public API. -It supports the following protocols: +It supports the following Bluetooth Classic protocols: - L2CAP - RFCOMM - SDP Based on these protocols, applications or daemons can implement various Bluetooth profiles. -You need to install other packages like BTstack GPS, Blutrol, or WeBe++ to make use of -BTstack. +Packages that already use BTstack are: BTstack GPS, Blutrol, WeBe++, and various game emulators. -Note: As BTstack directly uses the Bluetooth hardware, the iOS Bluetooth is automatically disabled for BTstack applications & services. +Note: As BTstack directly uses the Bluetooth hardware, the iOS Bluetooth is automatically disabled for BTstack applications & services. You can always turn BTstack off in Settings->BTstack. + +Please visit the [project page at GitHub](https://github.com/bluekitchen/btstack/) for technical information and check the platform/ios subfolder. -Please visit the [project page at GitHub](https://github.com/bluekitchen/btstack/) for technical information. diff --git a/src/hci.c b/src/hci.c index 71c4e8565..48e0131f5 100644 --- a/src/hci.c +++ b/src/hci.c @@ -847,10 +847,13 @@ static void hci_initializing_run(void){ switch (hci_stack->substate){ case HCI_INIT_SEND_RESET: hci_state_reset(); + +#ifndef USE_BLUETOOL // prepare reset if command complete not received in 100ms run_loop_set_timer(&hci_stack->timeout, 100); run_loop_set_timer_handler(&hci_stack->timeout, hci_initialization_timeout_handler); run_loop_add_timer(&hci_stack->timeout); +#endif // send command hci_stack->substate = HCI_INIT_W4_SEND_RESET; hci_send_cmd(&hci_reset); diff --git a/test/Makefile b/test/Makefile index 5150379c7..ad8032464 100644 --- a/test/Makefile +++ b/test/Makefile @@ -9,7 +9,8 @@ SUBDIRS = \ linked_list \ remote_device_db \ sdp_client \ - security_manager \ + +# security_manager \ EXCLUDED = ios diff --git a/test/att_db/Makefile b/test/att_db/Makefile index 9a61f5f26..b3516652f 100644 --- a/test/att_db/Makefile +++ b/test/att_db/Makefile @@ -1,12 +1,10 @@ CC = g++ -# Requirements: http://www.cpputest.org/ should be placed in btstack/test +# Requirements: cpputest.github.io BTSTACK_ROOT = ../.. -CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I.. -I${BTSTACK_ROOT}/example/libusb -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include -# -L$(CPPUTEST_HOME)/lib +CFLAGS = -g -Wall -I.. -I${BTSTACK_ROOT}/example/libusb -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include LDFLAGS += -lCppUTest -lCppUTestExt VPATH += ${BTSTACK_ROOT}/ble @@ -24,7 +22,7 @@ all: att_db_util_test att_db_util_test: ${COMMON_OBJ} att_db_util_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ -test: +test: all ./att_db_util_test clean: diff --git a/test/ble_client/Makefile b/test/ble_client/Makefile index c8172e056..a0b0e99b5 100644 --- a/test/ble_client/Makefile +++ b/test/ble_client/Makefile @@ -1,11 +1,10 @@ CC = g++ -# Requirements: http://www.cpputest.org/ should be placed in btstack/test +# Requirements: cpputest.github.io BTSTACK_ROOT = ../.. -CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I.. -I${BTSTACK_ROOT}/example/libusb -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +CFLAGS = -g -Wall -I.. -I${BTSTACK_ROOT}/example/libusb -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include LDFLAGS += -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt VPATH += ${BTSTACK_ROOT}/ble @@ -33,7 +32,7 @@ all: ad_parser ad_parser: ${CORE_OBJ} ${COMMON_OBJ} advertising_data_parser.c ${CC} ${CORE_OBJ} ${COMMON_OBJ} advertising_data_parser.c ${CFLAGS} ${LDFLAGS} -o $@ -test: +test: all ./ad_parser clean: diff --git a/test/des_iterator/Makefile b/test/des_iterator/Makefile index 34ff05635..ec910e912 100644 --- a/test/des_iterator/Makefile +++ b/test/des_iterator/Makefile @@ -1,13 +1,11 @@ CC = g++ -# Requirements: http://www.cpputest.org/ should be placed in btstack/test +# Requirements: cpputest.github.io BTSTACK_ROOT = ../.. -CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include LDFLAGS += -lCppUTest -lCppUTestExt -# -L$(CPPUTEST_HOME) VPATH += ${BTSTACK_ROOT}/ble VPATH += ${BTSTACK_ROOT}/src @@ -24,7 +22,7 @@ all: des_iterator_test des_iterator_test: ${COMMON_OBJ} des_iterator_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ -test: +test: all ./des_iterator_test clean: diff --git a/test/gatt_client/Makefile b/test/gatt_client/Makefile index 069f90783..d639a6e99 100644 --- a/test/gatt_client/Makefile +++ b/test/gatt_client/Makefile @@ -1,13 +1,11 @@ CC = g++ -# Requirements: http://www.cpputest.org/ should be placed in btstack/test +# Requirements: cpputest.github.io BTSTACK_ROOT = ../.. -CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -DUNIT_TEST -x c++ -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include LDFLAGS += -lCppUTest -lCppUTestExt -# -L$(CPPUTEST_HOME) VPATH += ${BTSTACK_ROOT}/ble VPATH += ${BTSTACK_ROOT}/src @@ -44,7 +42,7 @@ gatt_client_test: profile.h ${CORE_OBJ} ${COMMON_OBJ} gatt_client_test.o expecte le_central: ${CORE_OBJ} ${COMMON_OBJ} le_central.o ${CC} ${CORE_OBJ} ${COMMON_OBJ} le_central.o ${CFLAGS} ${LDFLAGS} -o $@ -test: +test: all ./gatt_client_test ./le_central diff --git a/test/linked_list/Makefile b/test/linked_list/Makefile index 0e08d07d4..0902c8c62 100644 --- a/test/linked_list/Makefile +++ b/test/linked_list/Makefile @@ -1,13 +1,12 @@ CC=g++ -# Requirements: http://www.cpputest.org/ should be placed in btstack/test +# Requirements: cpputest.github.io BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include LDFLAGS += -lCppUTest -lCppUTestExt -# -L$(CPPUTEST_HOME)/lib VPATH += ${BTSTACK_ROOT}/ble VPATH += ${BTSTACK_ROOT}/src @@ -23,7 +22,7 @@ all: linked_list_test linked_list_test: ${COMMON_OBJ} linked_list_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ -test: +test: all ./linked_list_test clean: diff --git a/test/remote_device_db/Makefile b/test/remote_device_db/Makefile index 347113c77..5e7f30eeb 100644 --- a/test/remote_device_db/Makefile +++ b/test/remote_device_db/Makefile @@ -1,13 +1,12 @@ CC=g++ -# Requirements: http://www.cpputest.org/ should be placed in btstack/test +# Requirements: cpputest.github.io BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I${BTSTACK_ROOT}/ble -I$(CPPUTEST_HOME)/include +CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I${BTSTACK_ROOT}/ble LDFLAGS += -lCppUTest -lCppUTestExt -# -L$(CPPUTEST_HOME) VPATH += ${BTSTACK_ROOT}/ble VPATH += ${BTSTACK_ROOT}/src @@ -36,7 +35,7 @@ remote_device_db_memory_test: ${MEMORY_OBJ} remote_device_db_memory_test.c remote_device_db_fs_test: ${FS_OBJ} remote_device_db_fs_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ -test: +test: all ./remote_device_db_memory_test ./remote_device_db_fs_test diff --git a/test/sdp_client/Makefile b/test/sdp_client/Makefile index 2d14ce98d..1353b5525 100644 --- a/test/sdp_client/Makefile +++ b/test/sdp_client/Makefile @@ -1,11 +1,11 @@ CC = g++ -# Requirements: http://www.cpputest.org/ should be placed in btstack/test +# Requirements: cpputest.github.io BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include LDFLAGS += -lCppUTest -lCppUTestExt # -L$(CPPUTEST_HOME) @@ -34,7 +34,7 @@ service_attribute_search_query: ${COMMON_OBJ} service_attribute_search_query.c service_search_query: ${COMMON_OBJ} service_search_query.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ -test: +test: all ./sdp_rfcomm_query ./general_sdp_query ./service_attribute_search_query diff --git a/test/security_manager/Makefile b/test/security_manager/Makefile index e1b49b680..b8b4e7c8f 100644 --- a/test/security_manager/Makefile +++ b/test/security_manager/Makefile @@ -1,13 +1,11 @@ CC = g++ -# Requirements: http://www.cpputest.org/ should be placed in btstack/test +# Requirements: cpputest.github.io BTSTACK_ROOT = ../.. -CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wno-unused -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wno-unused -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include LDFLAGS += -lCppUTest -lCppUTestExt -# -L$(CPPUTEST_HOME)/lib VPATH += ${BTSTACK_ROOT}/ble VPATH += ${BTSTACK_ROOT}/src @@ -39,7 +37,7 @@ security_manager: ${CORE_OBJ} ${COMMON_OBJ} security_manager.c aestest: aestest.c rijndael.c ${CC} ${CFLAGS} -m32 rijndael.c aestest.c -o $@ -test: +test: all ./security_manager ./aestest diff --git a/test/security_manager/security_manager.c b/test/security_manager/security_manager.c index d1b7d0a15..64c1872de 100644 --- a/test/security_manager/security_manager.c +++ b/test/security_manager/security_manager.c @@ -129,150 +129,160 @@ void CHECK_EQUAL_ARRAY(uint8_t * expected, uint8_t * actual, int size){ #define CHECK_ACL_PACKET(packet) { printf("check " #packet "\n") ; CHECK_EQUAL_ARRAY(packet, mock_packet_buffer(), sizeof(packet)); mock_clear_packet_buffer(); } -TEST_GROUP(GATTClient){ +TEST_GROUP(SecurityManager){ void setup(void){ btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); sm_init(); sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT); sm_set_authentication_requirements( SM_AUTHREQ_BONDING ); - - mock_simulate_hci_state_working(); - - // expect le encrypt commmand - CHECK_HCI_COMMAND(test_command_packet_01); - - aes128_report_result(); - - // expect le encrypt commmand - CHECK_HCI_COMMAND(test_command_packet_02); - - aes128_report_result(); - - mock_simulate_connected(); - - uint8_t test_pairing_request_command[] = { 0x01, 0x04, 0x00, 0x01, 0x10, 0x07, 0x07 }; - mock_simulate_sm_data_packet(&test_pairing_request_command[0], sizeof(test_pairing_request_command)); - - // expect send pairing response command - CHECK_ACL_PACKET(test_acl_packet_03); - - uint8_t test_pairing_confirm_command[] = { 0x03, 0x84, 0x5a, 0x87, 0x9a, 0x0f, 0xa9, 0x42, 0xba, 0x48, 0xc5, 0x79, 0xa0, 0x70, 0x70, 0xa9, 0xc8 }; - mock_simulate_sm_data_packet(&test_pairing_confirm_command[0], sizeof(test_pairing_confirm_command)); - - // expect le random command - CHECK_HCI_COMMAND(test_command_packet_04); - - uint8_t rand1_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0x2f, 0x04, 0x82, 0x84, 0x72, 0x46, 0x9c, 0x93 }; - mock_simulate_hci_event(&rand1_data_event[0], sizeof(rand1_data_event)); - - // expect le random command - CHECK_HCI_COMMAND(test_command_packet_05); - - uint8_t rand2_data_event[] = { 0x0e, 0x0c,0x01, 0x18,0x20, 0x00,0x48, 0x3f,0x27, 0x0e,0xeb, 0xd5,0x05, 0x7a }; - mock_simulate_hci_event(&rand2_data_event[0], sizeof(rand2_data_event)); - - // expect le encrypt command - CHECK_HCI_COMMAND(test_command_packet_06); - - aes128_report_result(); - - // expect le encrypt command - CHECK_HCI_COMMAND(test_command_packet_07); - - aes128_report_result(); - - // expect send paring confirm command - CHECK_ACL_PACKET(test_acl_packet_08); - - uint8_t test_pairing_random_command[] ={0x04, 0xfd, 0xd4, 0x06, 0x45, 0x0f, 0x1e, 0xdc, 0x84, 0xd5, 0x43, 0xac, 0xf7, 0x5e, 0xc0, 0x36, 0x29}; - mock_simulate_sm_data_packet(&test_pairing_random_command[0], sizeof(test_pairing_random_command)); - - // expect le encrypt command - CHECK_HCI_COMMAND(test_command_packet_09); - - aes128_report_result(); - - // expect le encrypt command - CHECK_HCI_COMMAND(test_command_packet_10); - - aes128_report_result(); - - // expect send pairing random command - CHECK_ACL_PACKET(test_acl_packet_11); - - // NOTE: SM also triggered for wrong handle - - uint8_t test_le_ltk_request[] = { 0x3e, 0x0d, 0x05, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00 }; - mock_simulate_hci_event(&test_le_ltk_request[0], sizeof(test_le_ltk_request)); - - // expect le encrypt command - CHECK_HCI_COMMAND(test_command_packet_12); - - aes128_report_result(); - - // expect le ltk reply - CHECK_HCI_COMMAND(test_command_packet_13); - - uint8_t test_ecnryption_change_event[] = { 0x08, 0x04, 0x00, 0x40, 0x00, 0x01 }; - mock_simulate_hci_event(&test_ecnryption_change_event[0], sizeof(test_ecnryption_change_event)); - - // expect le random command - CHECK_HCI_COMMAND(test_command_packet_14); - - uint8_t rand3_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0xc0, 0x10, 0x70, 0x5f, 0x3c, 0x2d, 0xe3, 0xb3 }; - mock_simulate_hci_event(&rand3_data_event[0], sizeof(rand3_data_event)); - - // expect le random command - CHECK_HCI_COMMAND(test_command_packet_15); - - uint8_t rand4_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0xf1, 0xe2, 0xbf, 0x7d, 0x84, 0x19, 0x32, 0x8b }; - mock_simulate_hci_event(&rand4_data_event[0], sizeof(rand4_data_event)); - - // expect le encrypt command - CHECK_HCI_COMMAND(test_command_packet_16); - - aes128_report_result(); - - // expect le encrypt command - CHECK_HCI_COMMAND(test_command_packet_17); - - aes128_report_result(); - - // expect le encrypt command - CHECK_HCI_COMMAND(test_command_packet_18); - - aes128_report_result(); - - // - uint8_t num_completed_packets_event[] = { 0x13, 0x05, 0x01, 0x4a, 0x00, 0x01, 00 }; - - // expect send LE SMP Encryption Information Command - CHECK_ACL_PACKET(test_acl_packet_18); - - mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event)); - - // expect send LE SMP Master Identification Command - CHECK_ACL_PACKET(test_acl_packet_19); - - mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event)); - - // expect send LE SMP Identity Information Command - CHECK_ACL_PACKET(test_acl_packet_20); - - mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event)); - - // expect send LE SMP Identity Address Information Command - CHECK_ACL_PACKET(test_acl_packet_21); - - mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event)); - - // expect send LE SMP Code Signing Information Command - CHECK_ACL_PACKET(test_acl_packet_22); } }; -TEST(GATTClient, TestScanning){ +TEST(SecurityManager, MainTest){ + + mock_simulate_hci_state_working(); + + printf("0\n"); + + // expect le encrypt commmand + CHECK_HCI_COMMAND(test_command_packet_01); + + aes128_report_result(); + + // expect le encrypt commmand + CHECK_HCI_COMMAND(test_command_packet_02); + + aes128_report_result(); + + printf("1\n"); + + mock_simulate_connected(); + + uint8_t test_pairing_request_command[] = { 0x01, 0x04, 0x00, 0x01, 0x10, 0x07, 0x07 }; + mock_simulate_sm_data_packet(&test_pairing_request_command[0], sizeof(test_pairing_request_command)); + + printf("2\n"); + + // expect send pairing response command + CHECK_ACL_PACKET(test_acl_packet_03); + + printf("3\n"); + + uint8_t test_pairing_confirm_command[] = { 0x03, 0x84, 0x5a, 0x87, 0x9a, 0x0f, 0xa9, 0x42, 0xba, 0x48, 0xc5, 0x79, 0xa0, 0x70, 0x70, 0xa9, 0xc8 }; + mock_simulate_sm_data_packet(&test_pairing_confirm_command[0], sizeof(test_pairing_confirm_command)); + + printf("4\n"); + + // expect le random command + CHECK_HCI_COMMAND(test_command_packet_04); + + uint8_t rand1_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0x2f, 0x04, 0x82, 0x84, 0x72, 0x46, 0x9c, 0x93 }; + mock_simulate_hci_event(&rand1_data_event[0], sizeof(rand1_data_event)); + + // expect le random command + CHECK_HCI_COMMAND(test_command_packet_05); + + uint8_t rand2_data_event[] = { 0x0e, 0x0c,0x01, 0x18,0x20, 0x00,0x48, 0x3f,0x27, 0x0e,0xeb, 0xd5,0x05, 0x7a }; + mock_simulate_hci_event(&rand2_data_event[0], sizeof(rand2_data_event)); + + // expect le encrypt command + CHECK_HCI_COMMAND(test_command_packet_06); + + aes128_report_result(); + + // expect le encrypt command + CHECK_HCI_COMMAND(test_command_packet_07); + + aes128_report_result(); + + // expect send paring confirm command + CHECK_ACL_PACKET(test_acl_packet_08); + + uint8_t test_pairing_random_command[] ={0x04, 0xfd, 0xd4, 0x06, 0x45, 0x0f, 0x1e, 0xdc, 0x84, 0xd5, 0x43, 0xac, 0xf7, 0x5e, 0xc0, 0x36, 0x29}; + mock_simulate_sm_data_packet(&test_pairing_random_command[0], sizeof(test_pairing_random_command)); + + // expect le encrypt command + CHECK_HCI_COMMAND(test_command_packet_09); + + aes128_report_result(); + + // expect le encrypt command + CHECK_HCI_COMMAND(test_command_packet_10); + + aes128_report_result(); + + // expect send pairing random command + CHECK_ACL_PACKET(test_acl_packet_11); + + // NOTE: SM also triggered for wrong handle + + uint8_t test_le_ltk_request[] = { 0x3e, 0x0d, 0x05, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00 }; + mock_simulate_hci_event(&test_le_ltk_request[0], sizeof(test_le_ltk_request)); + + // expect le encrypt command + CHECK_HCI_COMMAND(test_command_packet_12); + + aes128_report_result(); + + // expect le ltk reply + CHECK_HCI_COMMAND(test_command_packet_13); + + uint8_t test_ecnryption_change_event[] = { 0x08, 0x04, 0x00, 0x40, 0x00, 0x01 }; + mock_simulate_hci_event(&test_ecnryption_change_event[0], sizeof(test_ecnryption_change_event)); + + // expect le random command + CHECK_HCI_COMMAND(test_command_packet_14); + + uint8_t rand3_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0xc0, 0x10, 0x70, 0x5f, 0x3c, 0x2d, 0xe3, 0xb3 }; + mock_simulate_hci_event(&rand3_data_event[0], sizeof(rand3_data_event)); + + // expect le random command + CHECK_HCI_COMMAND(test_command_packet_15); + + uint8_t rand4_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0xf1, 0xe2, 0xbf, 0x7d, 0x84, 0x19, 0x32, 0x8b }; + mock_simulate_hci_event(&rand4_data_event[0], sizeof(rand4_data_event)); + + // expect le encrypt command + CHECK_HCI_COMMAND(test_command_packet_16); + + aes128_report_result(); + + // expect le encrypt command + CHECK_HCI_COMMAND(test_command_packet_17); + + aes128_report_result(); + + // expect le encrypt command + CHECK_HCI_COMMAND(test_command_packet_18); + + aes128_report_result(); + + // + uint8_t num_completed_packets_event[] = { 0x13, 0x05, 0x01, 0x4a, 0x00, 0x01, 00 }; + + // expect send LE SMP Encryption Information Command + CHECK_ACL_PACKET(test_acl_packet_18); + + mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event)); + + // expect send LE SMP Master Identification Command + CHECK_ACL_PACKET(test_acl_packet_19); + + mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event)); + + // expect send LE SMP Identity Information Command + CHECK_ACL_PACKET(test_acl_packet_20); + + mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event)); + + // expect send LE SMP Identity Address Information Command + CHECK_ACL_PACKET(test_acl_packet_21); + + mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event)); + + // expect send LE SMP Code Signing Information Command + CHECK_ACL_PACKET(test_acl_packet_22); } int main (int argc, const char * argv[]){