xref: /btstack/test/security_manager/security_manager.cpp (revision c502a66c58e29425304b42ba201b14f7ccce863a)
1 
2 // *****************************************************************************
3 //
4 // test rfcomm query tests
5 //
6 // *****************************************************************************
7 
8 
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 
14 #include "CppUTest/TestHarness.h"
15 #include "CppUTest/CommandLineTestRunner.h"
16 
17 #include "btstack_run_loop_embedded.h"
18 
19 #include "hci_cmd.h"
20 #include "btstack_util.h"
21 #include "btstack_debug.h"
22 #include "btstack_memory.h"
23 #include "hci.h"
24 #include "hci_dump.h"
25 #include "hci_dump_posix_fs.h"
26 #include "l2cap.h"
27 #include "ble/sm.h"
28 
29 uint8_t test_command_packet_sc_read_public_key[] = { 0x25, 0x20, 0x00 };
30 
31 // test data
32 
33 uint8_t test_command_packet_01[] = {
34     0x17, 0x20, 0x20, 0x9f, 0x9e, 0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93,
35     0x92, 0x91, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36     0x00, 0x00, 0x00, };
37 uint8_t test_command_packet_02[] = {
38     0x17, 0x20, 0x20, 0x9f, 0x9e, 0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93,
39     0x92, 0x91, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40     0x00, 0x00, 0x00, };
41 uint8_t test_acl_packet_03[] = {
42     0x40, 0x00, 0x0b, 0x00, 0x07, 0x00, 0x06, 0x00, 0x02, 0x03, 0x00, 0x01, 0x10, 0x07, 0x07, };
43 uint8_t test_command_packet_04[] = {
44     0x18, 0x20, 0x00, };
45 uint8_t test_command_packet_05[] = {
46     0x18, 0x20, 0x00, };
47 uint8_t test_command_packet_06[] = {
48     0x17, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49     0x00, 0x00, 0x00, 0x7b, 0x05, 0xd4, 0xef, 0x0e, 0x26, 0x2f, 0x4f, 0x94, 0x9e, 0x45, 0x72, 0x85,
50     0x92, 0x03, 0x28, };
51 uint8_t test_command_packet_07[] = {
52     0x17, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53     0x00, 0x00, 0x00, 0x87, 0xd0, 0x7b, 0x7f, 0xad, 0x4d, 0x47, 0xa6, 0x84, 0x2c, 0x85, 0x79, 0x58,
54     0xd3, 0xfe, 0xcd, };
55 uint8_t test_acl_packet_08[] = {
56     0x40, 0x00, 0x15, 0x00, 0x11, 0x00, 0x06, 0x00, 0x03, 0xa9, 0xe9, 0x8d, 0x9a, 0xc3, 0x96, 0xe3,
57     0x52, 0xa1, 0x17, 0xc0, 0xb2, 0xbe, 0x76, 0x42, 0xda, };
58 uint8_t test_command_packet_09[] = {
59     0x17, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60     0x00, 0x00, 0x00, 0xfc, 0xd4, 0x07, 0x41, 0x0f, 0x1f, 0xcc, 0x83, 0xd2, 0x41, 0xaf, 0xf7, 0x5f,
61     0xd0, 0x31, 0x2e, };
62 uint8_t test_command_packet_10[] = {
63     0x17, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64     0x00, 0x00, 0x00, 0x71, 0xd8, 0xbe, 0xe4, 0xb5, 0x48, 0x4d, 0x35, 0x80, 0x5e, 0x95, 0xf9, 0xb9,
65     0xaf, 0xc2, 0x55, };
66 uint8_t test_acl_packet_11[] = {
67     0x40, 0x00, 0x15, 0x00, 0x11, 0x00, 0x06, 0x00, 0x04, 0x7a, 0x05, 0xd5, 0xeb, 0x0e, 0x27, 0x3f,
68     0x48, 0x93, 0x9c, 0x46, 0x72, 0x84, 0x82, 0x04, 0x2f, };
69 uint8_t test_command_packet_12[] = {
70     0x17, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71     0x00, 0x00, 0x00, 0xfd, 0xd4, 0x06, 0x45, 0x0f, 0x1e, 0xdc, 0x84, 0x7a, 0x05, 0xd5, 0xeb, 0x0e,
72     0x27, 0x3f, 0x48, };
73 uint8_t test_command_packet_13[] = {
74     0x1a, 0x20, 0x12, 0x40, 0x00, 0xd1, 0x36, 0xa2, 0x5f, 0x8d, 0x5f, 0xd4, 0xd1, 0x70, 0x56, 0x1c,
75     0x12, 0x99, 0x98, 0x95, 0x30, };
76 uint8_t test_command_packet_14[] = {
77     0x18, 0x20, 0x00, };
78 uint8_t test_command_packet_15[] = {
79     0x18, 0x20, 0x00, };
80 uint8_t test_command_packet_16[] = {
81     0x17, 0x20, 0x20, 0xc7, 0x29, 0x17, 0x92, 0x59, 0xb9, 0x8f, 0xaa, 0xa2, 0x0a, 0x32, 0x2a, 0x73,
82     0xc6, 0x4f, 0xb5, 0xcf, 0x10, 0x70, 0x5f, 0x3c, 0x2d, 0xe3, 0xb3, 0x00, 0x00, 0x00, 0x00, 0x00,
83     0x00, 0x00, 0x00, };
84 uint8_t test_command_packet_17[] = {
85     0x17, 0x20, 0x20, 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33,
86     0x32, 0x31, 0x30, 0xe2, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87     0x00, 0x00, 0x00, };
88 uint8_t test_command_packet_18[] = {
89     0x17, 0x20, 0x20, 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33,
90     0x32, 0x31, 0x30, 0xe2, 0xf1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91     0x00, 0x00, 0x00, };
92 
93 uint8_t test_acl_packet_18[] = {
94     0x40, 0x00, 0x15, 0x00, 0x11, 0x00, 0x06, 0x00, 0x06, 0xef, 0x2f, 0xd9, 0x0b, 0x04, 0x7a, 0xe9,
95     0xa1, 0xcf, 0xc3, 0xa3, 0x83, 0xb7, 0x38, 0x30, 0x73, };
96 uint8_t test_acl_packet_19[] = {
97     0x40, 0x00, 0x0f, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x07, 0x5b, 0xb4, 0xcf, 0x10, 0x70, 0x5f, 0x3c,
98     0x2d, 0xe3, 0xb3, };
99 uint8_t test_acl_packet_20[] = {
100     0x40, 0x00, 0x15, 0x00, 0x11, 0x00, 0x06, 0x00, 0x08, 0xe6, 0xea, 0xee, 0x60, 0x31, 0x7b, 0xfc,
101     0xa2, 0x3f, 0xa5, 0x79, 0x59, 0xe7, 0x41, 0xcf, 0xc7, };
102 uint8_t test_acl_packet_21[] = {
103     0x40, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x06, 0x00, 0x09, 0x00, 0xef, 0x32, 0x07, 0xdc, 0x1b, 0x00, };
104 uint8_t test_acl_packet_22[] = {
105     0x40, 0x00, 0x15, 0x00, 0x11, 0x00, 0x06, 0x00, 0x0a, 0x1d, 0x06, 0xba, 0xf4, 0x0c, 0x49, 0x55,
106     0x5b, 0x93, 0x93, 0xc1, 0x8b, 0x09, 0xd0, 0xb8, 0x80, };
107 
108 bd_addr_t test_device_addr = {0x34, 0xb1, 0xf7, 0xd1, 0x77, 0x9b};
109 
110 static btstack_packet_callback_registration_t sm_event_callback_registration;
111 
112 extern "C" {
113     void mock_init(void);
114     void mock_simulate_hci_state_working(void);
115     void mock_simulate_hci_event(uint8_t * packet, uint16_t size);
116     void aes128_report_result(void);
117     void mock_simulate_sm_data_packet(uint8_t * packet, uint16_t size);
118     void mock_simulate_command_complete(const hci_cmd_t *cmd);
119     void mock_simulate_connected(void);
120     uint8_t * mock_packet_buffer(void);
121     uint16_t mock_packet_buffer_len(void);
122     void mock_clear_packet_buffer(void);
123 }
124 
125 void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
126     uint16_t aHandle;
127     bd_addr_t event_address;
128     switch (packet_type) {
129         case HCI_EVENT_PACKET:
130             switch (packet[0]) {
131                 case SM_EVENT_PASSKEY_INPUT_NUMBER:
132                     // store peer address for input
133                     printf("\nGAP Bonding: Enter 6 digit passkey: '");
134                     fflush(stdout);
135                     break;
136 
137                 case SM_EVENT_PASSKEY_DISPLAY_NUMBER:
138                     printf("\nGAP Bonding: Display Passkey '%06u\n", little_endian_read_32(packet, 11));
139                     break;
140 
141                 case SM_EVENT_PASSKEY_DISPLAY_CANCEL:
142                     printf("\nGAP Bonding: Display cancel\n");
143                     break;
144 
145                 case SM_EVENT_JUST_WORKS_REQUEST:
146                     // auto-authorize connection if requested
147                     sm_just_works_confirm(little_endian_read_16(packet, 2));
148                     printf("Just Works request confirmed\n");
149                     break;
150 
151                 case SM_EVENT_AUTHORIZATION_REQUEST:
152                     // auto-authorize connection if requested
153                     sm_authorization_grant(little_endian_read_16(packet, 2));
154                     break;
155 
156                 default:
157                     break;
158             }
159     }
160 }
161 
162 void CHECK_EQUAL_ARRAY(uint8_t * expected, uint8_t * actual, int size){
163 	int i;
164 	for (i=0; i<size; i++){
165 		if (expected[i] != actual[i]) {
166 			printf("offset %u wrong\n", i);
167 			printf("expected: "); printf_hexdump(expected, size);
168 			printf("actual:   "); printf_hexdump(actual, size);
169 		}
170 		BYTES_EQUAL(expected[i], actual[i]);
171 	}
172 }
173 
174 #define CHECK_HCI_COMMAND(packet) { log_info("check " #packet) ; CHECK_EQUAL_ARRAY(packet, mock_packet_buffer(), sizeof(packet)); mock_clear_packet_buffer(); }
175 #define CHECK_ACL_PACKET(packet)  { log_info("check " #packet) ; CHECK_EQUAL_ARRAY(packet, mock_packet_buffer(), sizeof(packet)); mock_clear_packet_buffer(); }
176 
177 static int parse_hex(uint8_t * buffer, const char * hex_string){
178     int len = 0;
179     while (*hex_string){
180         if (*hex_string == ' '){
181             hex_string++;
182             continue;
183         }
184         int high_nibble = nibble_for_char(*hex_string++);
185         int low_nibble = nibble_for_char(*hex_string++);
186         *buffer++ = (high_nibble << 4) | low_nibble;
187         len++;
188     }
189     return len;
190 }
191 
192 static const char * key_string = "2b7e1516 28aed2a6 abf71588 09cf4f3c";
193 
194 static const char * m0_string        = "";
195 static const char * cmac_m0_string   = "bb1d6929 e9593728 7fa37d12 9b756746";
196 static const char * m16_string       = "6bc1bee2 2e409f96 e93d7e11 7393172a";
197 static const char * cmac_m16_string  = "070a16b4 6b4d4144 f79bdd9d d04a287c";
198 static const char * m40_string       = "6bc1bee2 2e409f96 e93d7e11 7393172a ae2d8a57 1e03ac9c 9eb76fac 45af8e51 30c81c46 a35ce411";
199 static const char * cmac_m40_string  = "dfa66747 de9ae630 30ca3261 1497c827";
200 static const char * m64_string       = "6bc1bee2 2e409f96 e93d7e11 7393172a ae2d8a57 1e03ac9c 9eb76fac 45af8e51 30c81c46 a35ce411 e5fbc119 1a0a52ef f69f2445 df4f9b17 ad2b417b e66c3710";
201 static const char * cmac_m64_string  = "51f0bebf 7e3b9d92 fc497417 79363cfe";
202 
203 static uint8_t cmac_hash[16];
204 static int cmac_hash_received;
205 static void cmac_done(uint8_t * hash){
206     memcpy(cmac_hash, hash, 16);
207     printf("cmac hash: ");
208     printf_hexdump(hash, 16);
209     cmac_hash_received = 1;
210 }
211 
212 static uint8_t m[128];
213 
214 #define VALIDATE_MESSAGE(NAME) validate_message(#NAME, NAME##_string, cmac_##NAME##_string)
215 
216 
217 bool get_ltk_callback(hci_con_handle_t con_handle, uint8_t address_type, bd_addr_t addr, uint8_t * ltk){
218     UNUSED(con_handle);
219     UNUSED(address_type);
220     UNUSED(addr);
221     UNUSED(ltk);
222 
223     return true;
224 }
225 
226 
227 TEST_GROUP(SecurityManager){
228 	void setup(void){
229         static int first = 1;
230         if (first){
231             first = 0;
232             btstack_memory_init();
233             btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
234         }
235 	    sm_init();
236 	    sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
237 	    sm_set_authentication_requirements( SM_AUTHREQ_BONDING );
238         sm_event_callback_registration.callback = &app_packet_handler;
239         sm_add_event_handler(&sm_event_callback_registration);
240 
241 
242         // log into file using HCI_DUMP_PACKETLOGGER format
243         const char * log_path = "hci_dump.pklg";
244         hci_dump_posix_fs_open(log_path, HCI_DUMP_PACKETLOGGER);
245         hci_dump_init(hci_dump_posix_fs_get_instance());
246         printf("Packet Log: %s\n", log_path);
247     }
248 };
249 
250 TEST(SecurityManager, CallFunctions){
251     sm_register_ltk_callback(&get_ltk_callback);
252     sm_remove_event_handler(NULL);
253     sm_set_accepted_stk_generation_methods(0);
254     sm_set_encryption_key_size_range(16, 128);
255 #ifdef ENABLE_LE_PERIPHERAL
256     sm_set_request_security(true);
257 #endif
258     sm_key_t key = {1,2,3,4,5,6,7,8,8,10,11,12,13,14,15,16};
259     sm_set_er(key);
260     sm_set_ir(key);
261     sm_test_set_irk(key);
262     sm_test_use_fixed_local_csrk();
263     sm_use_fixed_passkey_in_display_role(1000);
264     sm_allow_ltk_reconstruction_without_le_device_db_entry(1);
265     sm_numeric_comparison_confirm(HCI_CON_HANDLE_INVALID);
266 }
267 
268 TEST(SecurityManager, MainTest){
269 
270     mock_init();
271     mock_simulate_hci_state_working();
272 
273 #ifdef ENABLE_LE_SECURE_CONNECTIONS
274 	// on start, new ECC Key is generated
275 #ifdef ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS
276     // with uECC, this requires to get some random data
277     int i;
278     for (i=0;i<8;i++){
279 		CHECK_HCI_COMMAND(test_command_packet_04);
280 		uint8_t rand_sc_1_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0x2f, 0x04, 0x82, 0x84, 0x72, 0x46, 0x9c, 0x93 };
281 		mock_simulate_hci_event(&rand_sc_1_data_event[0], sizeof(rand_sc_1_data_event));
282     }
283 #else
284 	// with Controller support, the stack will read public key
285 	CHECK_HCI_COMMAND(test_command_packet_sc_read_public_key);
286 	uint8_t read_public_key_event[] = {
287 			0x3E, 0x42, 0x08, 0x00, 0xD1, 0xD2, 0x7C, 0xF7, 0x08, 0x34, 0xC8, 0x19, 0xEC, 0x92, 0x39, 0x8D,
288 			0x55, 0xE7, 0xAB, 0x25, 0xDE, 0x7B, 0x32, 0x05, 0x64, 0xA8, 0x90, 0xA7, 0xE6, 0x52, 0x7B, 0x41,
289 			0x29, 0x14, 0xA3, 0xAE, 0x73, 0xC9, 0x57, 0x20, 0xA8, 0x5F, 0xFE, 0xE7, 0xC1, 0x27, 0xDE, 0x7D,
290 			0xB7, 0x25, 0xB0, 0xC1, 0x9E, 0x1F, 0xFE, 0xD1, 0xF0, 0x21, 0x22, 0x7E, 0x1F, 0xF4, 0x5D, 0x07,
291 			0x6D, 0x6F, 0x12, 0x06
292 	};
293 	mock_simulate_hci_event(&read_public_key_event[0], sizeof(read_public_key_event));
294 #endif
295 #endif
296 
297 #ifndef ENABLE_SOFTWARE_AES128
298     // expect le encrypt commmand
299     CHECK_HCI_COMMAND(test_command_packet_01);
300     aes128_report_result();
301 
302     // expect le encrypt commmand
303     CHECK_HCI_COMMAND(test_command_packet_02);
304     aes128_report_result();
305 #endif
306 
307 	mock_clear_packet_buffer();
308 
309     mock_simulate_connected();
310 
311     uint8_t test_pairing_request_command[] = { 0x01, 0x04, 0x00, 0x01, 0x10, 0x07, 0x07 };
312     mock_simulate_sm_data_packet(&test_pairing_request_command[0], sizeof(test_pairing_request_command));
313 
314     // expect send pairing response command
315     CHECK_ACL_PACKET(test_acl_packet_03);
316 
317     uint8_t test_pairing_confirm_command[] = { 0x03, 0x84, 0x5a, 0x87, 0x9a, 0x0f, 0xa9, 0x42, 0xba, 0x48, 0xc5, 0x79, 0xa0, 0x70, 0x70, 0xa9, 0xc8 };
318     mock_simulate_sm_data_packet(&test_pairing_confirm_command[0], sizeof(test_pairing_confirm_command));
319 
320     // expect le random command
321     CHECK_HCI_COMMAND(test_command_packet_04);
322 
323     uint8_t rand1_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0x2f, 0x04, 0x82, 0x84, 0x72, 0x46, 0x9c, 0x93 };
324 	mock_simulate_hci_event(&rand1_data_event[0], sizeof(rand1_data_event));
325 
326     // expect le random command
327     CHECK_HCI_COMMAND(test_command_packet_05);
328 
329     uint8_t rand2_data_event[] = { 0x0e, 0x0c,0x01, 0x18,0x20, 0x00,0x48, 0x3f,0x27, 0x0e,0xeb, 0xd5,0x05, 0x7a };
330 	mock_simulate_hci_event(&rand2_data_event[0], sizeof(rand2_data_event));
331 
332 #ifdef ENABLE_SOFTWARE_AES128
333 	// process sm_run_trigger()
334     btstack_run_loop_embedded_execute_once();
335 #else
336     // expect le encrypt command
337     CHECK_HCI_COMMAND(test_command_packet_06);
338     aes128_report_result();
339 
340     // expect le encrypt command
341     CHECK_HCI_COMMAND(test_command_packet_07);
342     aes128_report_result();
343 #endif
344 
345 
346     // expect send pairing confirm command
347     CHECK_ACL_PACKET(test_acl_packet_08);
348 
349     uint8_t test_pairing_random_command[] ={0x04, 0xfd, 0xd4, 0x06, 0x45, 0x0f, 0x1e, 0xdc, 0x84, 0xd5, 0x43, 0xac, 0xf7, 0x5e, 0xc0, 0x36, 0x29};
350     mock_simulate_sm_data_packet(&test_pairing_random_command[0], sizeof(test_pairing_random_command));
351 
352 #ifdef ENABLE_SOFTWARE_AES128
353     // process sm_run_trigger()
354     btstack_run_loop_embedded_execute_once();
355 #else
356     // expect le encrypt command
357     CHECK_HCI_COMMAND(test_command_packet_09);
358     aes128_report_result();
359 
360     // expect le encrypt command
361     CHECK_HCI_COMMAND(test_command_packet_10);
362     aes128_report_result();
363 #endif
364 
365     // expect send pairing random command
366     CHECK_ACL_PACKET(test_acl_packet_11);
367 
368     // NOTE: SM also triggered for wrong handle
369 
370 	uint8_t test_le_ltk_request[] = { 0x3e, 0x0d, 0x05, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00 };
371 	mock_simulate_hci_event(&test_le_ltk_request[0], sizeof(test_le_ltk_request));
372 
373 #ifdef ENABLE_SOFTWARE_AES128
374     // process sm_run_trigger()
375     btstack_run_loop_embedded_execute_once();
376 #else
377 	// expect le encrypt command
378     CHECK_HCI_COMMAND(test_command_packet_12);
379     aes128_report_result();
380 #endif
381 
382 	// expect le ltk reply
383     CHECK_HCI_COMMAND(test_command_packet_13);
384 
385 	uint8_t test_ecnryption_change_event[] = { 0x08, 0x04, 0x00, 0x40, 0x00, 0x01 };
386 	mock_simulate_hci_event(&test_ecnryption_change_event[0], sizeof(test_ecnryption_change_event));
387 
388     // expect le random command
389     CHECK_HCI_COMMAND(test_command_packet_14);
390 
391     uint8_t rand3_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0xc0, 0x10, 0x70, 0x5f, 0x3c, 0x2d, 0xe3, 0xb3 };
392 	mock_simulate_hci_event(&rand3_data_event[0], sizeof(rand3_data_event));
393 
394     // expect le random command
395     CHECK_HCI_COMMAND(test_command_packet_15);
396 
397     uint8_t rand4_data_event[] = { 0x0e, 0x0c, 0x01, 0x18, 0x20, 0x00, 0xf1, 0xe2, 0xbf, 0x7d, 0x84, 0x19, 0x32, 0x8b };
398 	mock_simulate_hci_event(&rand4_data_event[0], sizeof(rand4_data_event));
399 
400 #ifdef ENABLE_SOFTWARE_AES128
401     // process sm_run_trigger()
402     btstack_run_loop_embedded_execute_once();
403 #else
404 	// expect le encrypt command
405     CHECK_HCI_COMMAND(test_command_packet_16);
406     aes128_report_result();
407 
408 	// expect le encrypt command
409     CHECK_HCI_COMMAND(test_command_packet_17);
410     aes128_report_result();
411 
412 	// expect le encrypt command
413     CHECK_HCI_COMMAND(test_command_packet_18);
414     aes128_report_result();
415 #endif
416 
417     //
418 	uint8_t num_completed_packets_event[] = { 0x13, 0x05, 0x01, 0x4a, 0x00, 0x01, 00 };
419 
420     // expect send LE SMP Encryption Information Command
421     CHECK_ACL_PACKET(test_acl_packet_18);
422 
423 	mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event));
424 
425     // expect send LE SMP Master Identification Command
426     CHECK_ACL_PACKET(test_acl_packet_19);
427 
428 	mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event));
429 
430 	// expect send LE SMP Identity Information Command
431     CHECK_ACL_PACKET(test_acl_packet_20);
432 
433 	mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event));
434 
435 	// expect send LE SMP Identity Address Information Command
436     CHECK_ACL_PACKET(test_acl_packet_21);
437 
438 	mock_simulate_hci_event(&num_completed_packets_event[0], sizeof(num_completed_packets_event));
439 
440 	// expect send LE SMP Code Signing Information Command
441     CHECK_ACL_PACKET(test_acl_packet_22);
442 }
443 
444 TEST(SecurityManager, AddressResolutionLookup){
445     int status;
446     bd_addr_t address = {0,0,0,0,0,0};
447 
448     status = sm_address_resolution_lookup((uint8_t) BD_ADDR_TYPE_LE_PUBLIC, address);
449     CHECK_EQUAL(status, 0);
450 }
451 
452 int main (int argc, const char * argv[]){
453     // log into file using HCI_DUMP_PACKETLOGGER format
454     const char * log_path = "hci_dump.pklg";
455     hci_dump_posix_fs_open(log_path, HCI_DUMP_PACKETLOGGER);
456     hci_dump_init(hci_dump_posix_fs_get_instance());
457     printf("Packet Log: %s\n", log_path);
458 
459     return CommandLineTestRunner::RunAllTests(argc, argv);
460 }
461