sm.c (d88e71affe485e1ec11ee98ed0afb736f145b61d) | sm.c (eddc894f0fdcbd5f74364a73ac5888339d91ee1d) |
---|---|
1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 939 unchanged lines hidden (view full) --- 948 int recv_flags; 949 if (IS_RESPONDER(sm_conn->sm_role)){ 950 // slave / responder 951 recv_flags = sm_key_distribution_flags_for_set(sm_pairing_packet_get_initiator_key_distribution(setup->sm_s_pres)); 952 } else { 953 // master / initiator 954 recv_flags = sm_key_distribution_flags_for_set(sm_pairing_packet_get_responder_key_distribution(setup->sm_s_pres)); 955 } | 1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 939 unchanged lines hidden (view full) --- 948 int recv_flags; 949 if (IS_RESPONDER(sm_conn->sm_role)){ 950 // slave / responder 951 recv_flags = sm_key_distribution_flags_for_set(sm_pairing_packet_get_initiator_key_distribution(setup->sm_s_pres)); 952 } else { 953 // master / initiator 954 recv_flags = sm_key_distribution_flags_for_set(sm_pairing_packet_get_responder_key_distribution(setup->sm_s_pres)); 955 } |
956 957#ifdef ENABLE_LE_SECURE_CONNECTIONS 958 // LTK (= encyrption information & master identification) only used exchanged for LE Legacy Connection 959 if (setup->sm_use_secure_connections){ 960 recv_flags &= ~(SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION | SM_KEYDIST_FLAG_MASTER_IDENTIFICATION); 961 } 962#endif 963 |
|
956 log_debug("sm_key_distribution_all_received: received 0x%02x, expecting 0x%02x", setup->sm_key_distribution_received_set, recv_flags); 957 return recv_flags == setup->sm_key_distribution_received_set; 958} 959 960static void sm_done_for_handle(hci_con_handle_t con_handle){ 961 if (sm_active_connection_handle == con_handle){ 962 sm_timeout_stop(); 963 sm_active_connection_handle = HCI_CON_HANDLE_INVALID; --- 97 unchanged lines hidden (view full) --- 1061 remote_packet = &setup->sm_s_pres; 1062 remote_key_request = sm_pairing_packet_get_initiator_key_distribution(setup->sm_s_pres); 1063 } 1064 1065 // check key size 1066 sm_conn->sm_actual_encryption_key_size = sm_calc_actual_encryption_key_size(sm_pairing_packet_get_max_encryption_key_size(*remote_packet)); 1067 if (sm_conn->sm_actual_encryption_key_size == 0) return SM_REASON_ENCRYPTION_KEY_SIZE; 1068 | 964 log_debug("sm_key_distribution_all_received: received 0x%02x, expecting 0x%02x", setup->sm_key_distribution_received_set, recv_flags); 965 return recv_flags == setup->sm_key_distribution_received_set; 966} 967 968static void sm_done_for_handle(hci_con_handle_t con_handle){ 969 if (sm_active_connection_handle == con_handle){ 970 sm_timeout_stop(); 971 sm_active_connection_handle = HCI_CON_HANDLE_INVALID; --- 97 unchanged lines hidden (view full) --- 1069 remote_packet = &setup->sm_s_pres; 1070 remote_key_request = sm_pairing_packet_get_initiator_key_distribution(setup->sm_s_pres); 1071 } 1072 1073 // check key size 1074 sm_conn->sm_actual_encryption_key_size = sm_calc_actual_encryption_key_size(sm_pairing_packet_get_max_encryption_key_size(*remote_packet)); 1075 if (sm_conn->sm_actual_encryption_key_size == 0) return SM_REASON_ENCRYPTION_KEY_SIZE; 1076 |
1069 // decide on STK generation method | 1077 // decide on STK generation method / SC |
1070 sm_setup_tk(); 1071 log_info("SMP: generation method %u", setup->sm_stk_generation_method); 1072 1073 // check if STK generation method is acceptable by client 1074 if (!sm_validate_stk_generation_method()) return SM_REASON_AUTHENTHICATION_REQUIREMENTS; 1075 | 1078 sm_setup_tk(); 1079 log_info("SMP: generation method %u", setup->sm_stk_generation_method); 1080 1081 // check if STK generation method is acceptable by client 1082 if (!sm_validate_stk_generation_method()) return SM_REASON_AUTHENTHICATION_REQUIREMENTS; 1083 |
1084#ifdef ENABLE_LE_SECURE_CONNECTIONS 1085 // LTK (= encyrption information & master identification) only used exchanged for LE Legacy Connection 1086 if (setup->sm_use_secure_connections){ 1087 remote_key_request &= ~SM_KEYDIST_ENC_KEY; 1088 } 1089#endif 1090 |
|
1076 // identical to responder 1077 sm_setup_key_distribution(remote_key_request); 1078 1079 // JUST WORKS doens't provide authentication 1080 sm_conn->sm_connection_authenticated = setup->sm_stk_generation_method == JUST_WORKS ? 0 : 1; 1081 1082 return 0; 1083} --- 1208 unchanged lines hidden (view full) --- 2292#ifdef ENABLE_LE_PERIPHERAL 2293 case SM_RESPONDER_PH1_SEND_PAIRING_RESPONSE: 2294 // echo initiator for now 2295 sm_pairing_packet_set_code(setup->sm_s_pres,SM_CODE_PAIRING_RESPONSE); 2296 key_distribution_flags = sm_key_distribution_flags_for_auth_req(); 2297 2298 if (setup->sm_use_secure_connections){ 2299 connection->sm_engine_state = SM_SC_W4_PUBLIC_KEY_COMMAND; | 1091 // identical to responder 1092 sm_setup_key_distribution(remote_key_request); 1093 1094 // JUST WORKS doens't provide authentication 1095 sm_conn->sm_connection_authenticated = setup->sm_stk_generation_method == JUST_WORKS ? 0 : 1; 1096 1097 return 0; 1098} --- 1208 unchanged lines hidden (view full) --- 2307#ifdef ENABLE_LE_PERIPHERAL 2308 case SM_RESPONDER_PH1_SEND_PAIRING_RESPONSE: 2309 // echo initiator for now 2310 sm_pairing_packet_set_code(setup->sm_s_pres,SM_CODE_PAIRING_RESPONSE); 2311 key_distribution_flags = sm_key_distribution_flags_for_auth_req(); 2312 2313 if (setup->sm_use_secure_connections){ 2314 connection->sm_engine_state = SM_SC_W4_PUBLIC_KEY_COMMAND; |
2300 // skip LTK/EDIV for SC 2301 log_info("sm: dropping encryption information flag"); 2302 key_distribution_flags &= ~SM_KEYDIST_ENC_KEY; | |
2303 } else { 2304 connection->sm_engine_state = SM_RESPONDER_PH1_W4_PAIRING_CONFIRM; 2305 } 2306 2307 sm_pairing_packet_set_initiator_key_distribution(setup->sm_s_pres, sm_pairing_packet_get_initiator_key_distribution(setup->sm_m_preq) & key_distribution_flags); 2308 sm_pairing_packet_set_responder_key_distribution(setup->sm_s_pres, sm_pairing_packet_get_responder_key_distribution(setup->sm_m_preq) & key_distribution_flags); 2309 // update key distribution after ENC was dropped 2310 sm_setup_key_distribution(sm_pairing_packet_get_responder_key_distribution(setup->sm_s_pres)); --- 1711 unchanged lines hidden --- | 2315 } else { 2316 connection->sm_engine_state = SM_RESPONDER_PH1_W4_PAIRING_CONFIRM; 2317 } 2318 2319 sm_pairing_packet_set_initiator_key_distribution(setup->sm_s_pres, sm_pairing_packet_get_initiator_key_distribution(setup->sm_m_preq) & key_distribution_flags); 2320 sm_pairing_packet_set_responder_key_distribution(setup->sm_s_pres, sm_pairing_packet_get_responder_key_distribution(setup->sm_m_preq) & key_distribution_flags); 2321 // update key distribution after ENC was dropped 2322 sm_setup_key_distribution(sm_pairing_packet_get_responder_key_distribution(setup->sm_s_pres)); --- 1711 unchanged lines hidden --- |