This commit is contained in:
Milanka Ringwald 2015-07-16 23:49:14 +02:00
commit 45615488a3
5 changed files with 39 additions and 22 deletions

View File

@ -329,6 +329,7 @@ typedef enum {
typedef enum {
// general states
// state = 0
SM_GENERAL_IDLE,
SM_GENERAL_SEND_PAIRING_FAILED,
SM_GENERAL_TIMEOUT, // no other security messages are exchanged
@ -349,6 +350,7 @@ typedef enum {
SM_PH2_C1_W4_RANDOM_B,
// calculate confirm value for local side
// state = 10
SM_PH2_C1_GET_ENC_A,
SM_PH2_C1_W4_ENC_A,
SM_PH2_C1_GET_ENC_B,
@ -364,6 +366,7 @@ typedef enum {
SM_PH2_SEND_PAIRING_RANDOM,
// calc STK
// state = 20
SM_PH2_CALC_STK,
SM_PH2_W4_STK,
@ -379,6 +382,7 @@ typedef enum {
SM_PH3_Y_GET_ENC,
SM_PH3_Y_W4_ENC,
SM_PH3_LTK_GET_ENC,
// state = 30
SM_PH3_LTK_W4_ENC,
SM_PH3_CSRK_GET_ENC,
SM_PH3_CSRK_W4_ENC,
@ -395,6 +399,7 @@ typedef enum {
SM_PH4_SEND_LTK,
// RESPONDER ROLE
// state = 40
SM_RESPONDER_SEND_SECURITY_REQUEST,
SM_RESPONDER_PH0_RECEIVED_LTK,
SM_RESPONDER_PH0_SEND_LTK_REQUESTED_NEGATIVE_REPLY,

View File

@ -9,6 +9,7 @@ SUBDIRS = \
linked_list \
remote_device_db \
sdp_client \
security_manager \
# security_manager \

View File

@ -35,7 +35,7 @@ security_manager: ${CORE_OBJ} ${COMMON_OBJ} security_manager.c
${CC} ${CORE_OBJ} ${COMMON_OBJ} security_manager.c ${CFLAGS} ${LDFLAGS} -o $@
aestest: aestest.c rijndael.c
${CC} ${CFLAGS} -m32 rijndael.c aestest.c -o $@
${CC} ${CFLAGS} rijndael.c aestest.c -o $@
test: all
./security_manager

View File

@ -19,8 +19,14 @@ static uint16_t packet_buffer_len = 0;
static uint8_t aes128_cyphertext[16];
static hci_connection_t the_connection;
static linked_list_t connections;
void mock_init(void){
the_connection.item.next = NULL;
connections = (linked_item*) &the_connection;
}
uint8_t * mock_packet_buffer(void){
return packet_buffer;
}
@ -119,17 +125,13 @@ int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){
return 1;
}
// todo:
hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t addr, bd_addr_type_t addr_type){
printf("hci_connection_for_bd_addr_and_type not implemented in mock backend\n");
return NULL;
return &the_connection;
}
hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle){
printf("hci_connection_for_handle not implemented in mock backend\n");
return NULL;
return &the_connection;
}
void hci_connections_get_iterator(linked_list_iterator_t *it){
// printf("hci_connections_get_iterator not implemented in mock backend\n");
linked_list_iterator_init(it, &connections);
}

View File

@ -33,6 +33,10 @@ uint8_t test_command_packet_02[] = {
0x17, 0x20, 0x20, 0x9f, 0x9e, 0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93,
0x92, 0x91, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, };
uint8_t test_command_packet_02a[] = {
0x17, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x68, 0xc9, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00 };
uint8_t test_acl_packet_03[] = {
0x40, 0x00, 0x0b, 0x00, 0x07, 0x00, 0x06, 0x00, 0x02, 0x03, 0x00, 0x01, 0x10, 0x07, 0x07, };
uint8_t test_command_packet_04[] = {
@ -101,13 +105,14 @@ uint8_t test_acl_packet_22[] = {
0x5b, 0x93, 0x93, 0xc1, 0x8b, 0x09, 0xd0, 0xb8, 0x80, };
bd_addr_t test_device_addr = {0x34, 0xb1, 0xf7, 0xd1, 0x77, 0x9b};
void mock_simulate_hci_state_working();
void mock_init(void);
void mock_simulate_hci_state_working(void);
void mock_simulate_hci_event(uint8_t * packet, uint16_t size);
void aes128_report_result();
void aes128_report_result(void);
void mock_simulate_sm_data_packet(uint8_t * packet, uint16_t size);
void mock_simulate_command_complete(const hci_cmd_t *cmd);
void mock_simulate_connected();
void mock_simulate_connected(void);
uint8_t * mock_packet_buffer(void);
uint16_t mock_packet_buffer_len(void);
void mock_clear_packet_buffer(void);
@ -141,10 +146,9 @@ TEST_GROUP(SecurityManager){
TEST(SecurityManager, MainTest){
mock_init();
mock_simulate_hci_state_working();
printf("0\n");
// expect le encrypt commmand
CHECK_HCI_COMMAND(test_command_packet_01);
@ -154,26 +158,31 @@ TEST(SecurityManager, MainTest){
CHECK_HCI_COMMAND(test_command_packet_02);
aes128_report_result();
printf("1\n");
mock_clear_packet_buffer();
mock_simulate_connected();
CHECK_HCI_COMMAND(test_command_packet_02a);
aes128_report_result();
CHECK_HCI_COMMAND(test_command_packet_02a);
aes128_report_result();
CHECK_HCI_COMMAND(test_command_packet_02a);
aes128_report_result();
CHECK_HCI_COMMAND(test_command_packet_02a);
aes128_report_result();
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);