Lines Matching refs:p_cb
78 static bool smp_parameter_unconditionally_valid(tSMP_CB* p_cb);
79 static bool smp_parameter_unconditionally_invalid(tSMP_CB* p_cb);
82 typedef bool (*tSMP_CMD_LEN_VALID)(tSMP_CB* p_cb);
84 static bool smp_command_has_valid_fixed_length(tSMP_CB* p_cb);
106 typedef bool (*tSMP_CMD_PARAM_RANGES_VALID)(tSMP_CB* p_cb);
108 static bool smp_pairing_request_response_parameters_are_valid(tSMP_CB* p_cb);
109 static bool smp_pairing_keypress_notification_is_valid(tSMP_CB* p_cb);
135 typedef BT_HDR* (*tSMP_CMD_ACT)(uint8_t cmd_code, tSMP_CB* p_cb);
137 static BT_HDR* smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB* p_cb);
139 tSMP_CB* p_cb);
140 static BT_HDR* smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb);
142 tSMP_CB* p_cb);
144 tSMP_CB* p_cb);
146 tSMP_CB* p_cb);
148 tSMP_CB* p_cb);
150 tSMP_CB* p_cb);
152 tSMP_CB* p_cb);
154 tSMP_CB* p_cb);
156 tSMP_CB* p_cb);
158 tSMP_CB* p_cb);
160 tSMP_CB* p_cb);
162 UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb);
295 static tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB* p_cb);
297 tSMP_CB* p_cb);
364 bool smp_send_cmd(uint8_t cmd_code, tSMP_CB* p_cb) { in smp_send_cmd() argument
369 cmd_code, p_cb->pairing_bda.ToString().c_str()); in smp_send_cmd()
373 p_buf = (*smp_cmd_build_act[cmd_code])(cmd_code, p_cb); in smp_send_cmd()
375 if (p_buf != NULL && smp_send_msg_to_L2CAP(p_cb->pairing_bda, p_buf)) { in smp_send_cmd()
377 alarm_set_on_mloop(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS, in smp_send_cmd()
385 if (p_cb->smp_over_br) { in smp_send_cmd()
386 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data); in smp_send_cmd()
388 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_send_cmd()
404 tSMP_CB* p_cb = &smp_cb; in smp_rsp_timeout() local
406 SMP_TRACE_EVENT("%s state:%d br_state:%d", __func__, p_cb->state, in smp_rsp_timeout()
407 p_cb->br_state); in smp_rsp_timeout()
411 if (p_cb->smp_over_br) { in smp_rsp_timeout()
412 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data); in smp_rsp_timeout()
414 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_rsp_timeout()
448 BT_HDR* smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB* p_cb) { in smp_build_pairing_cmd() argument
457 UINT8_TO_STREAM(p, p_cb->local_io_capability); in smp_build_pairing_cmd()
458 UINT8_TO_STREAM(p, p_cb->loc_oob_flag); in smp_build_pairing_cmd()
459 UINT8_TO_STREAM(p, p_cb->loc_auth_req); in smp_build_pairing_cmd()
460 UINT8_TO_STREAM(p, p_cb->loc_enc_size); in smp_build_pairing_cmd()
461 UINT8_TO_STREAM(p, p_cb->local_i_key); in smp_build_pairing_cmd()
462 UINT8_TO_STREAM(p, p_cb->local_r_key); in smp_build_pairing_cmd()
479 tSMP_CB* p_cb) { in smp_build_confirm_cmd() argument
489 ARRAY_TO_STREAM(p, p_cb->confirm, OCTET16_LEN); in smp_build_confirm_cmd()
504 static BT_HDR* smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb) { in smp_build_rand_cmd() argument
513 ARRAY_TO_STREAM(p, p_cb->rand, OCTET16_LEN); in smp_build_rand_cmd()
529 tSMP_CB* p_cb) { in smp_build_encrypt_info_cmd() argument
538 ARRAY_TO_STREAM(p, p_cb->ltk, OCTET16_LEN); in smp_build_encrypt_info_cmd()
554 tSMP_CB* p_cb) { in smp_build_master_id_cmd() argument
563 UINT16_TO_STREAM(p, p_cb->ediv); in smp_build_master_id_cmd()
564 ARRAY_TO_STREAM(p, p_cb->enc_rand, BT_OCTET8_LEN); in smp_build_master_id_cmd()
580 UNUSED_ATTR tSMP_CB* p_cb) { in smp_build_identity_info_cmd() argument
608 UNUSED_ATTR tSMP_CB* p_cb) { in smp_build_id_addr_cmd() argument
634 tSMP_CB* p_cb) { in smp_build_signing_info_cmd() argument
643 ARRAY_TO_STREAM(p, p_cb->csrk, OCTET16_LEN); in smp_build_signing_info_cmd()
659 tSMP_CB* p_cb) { in smp_build_pairing_fail() argument
668 UINT8_TO_STREAM(p, p_cb->failure); in smp_build_pairing_fail()
684 tSMP_CB* p_cb) { in smp_build_security_request() argument
692 UINT8_TO_STREAM(p, p_cb->loc_auth_req); in smp_build_security_request()
698 p_cb->loc_auth_req); in smp_build_security_request()
711 tSMP_CB* p_cb) { in smp_build_pair_public_key_cmd() argument
720 memcpy(p_publ_key, p_cb->loc_publ_key.x, BT_OCTET32_LEN); in smp_build_pair_public_key_cmd()
721 memcpy(p_publ_key + BT_OCTET32_LEN, p_cb->loc_publ_key.y, BT_OCTET32_LEN); in smp_build_pair_public_key_cmd()
741 tSMP_CB* p_cb) { in smp_build_pairing_commitment_cmd() argument
750 ARRAY_TO_STREAM(p, p_cb->commitment, OCTET16_LEN); in smp_build_pairing_commitment_cmd()
766 tSMP_CB* p_cb) { in smp_build_pair_dhkey_check_cmd() argument
775 ARRAY_TO_STREAM(p, p_cb->dhkey_check, OCTET16_LEN); in smp_build_pair_dhkey_check_cmd()
791 UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb) { in smp_build_pairing_keypress_notification_cmd() argument
800 UINT8_TO_STREAM(p, p_cb->local_keypress_notification); in smp_build_pairing_keypress_notification_cmd()
857 void smp_cb_cleanup(tSMP_CB* p_cb) { in smp_cb_cleanup() argument
858 tSMP_CALLBACK* p_callback = p_cb->p_callback; in smp_cb_cleanup()
859 uint8_t trace_level = p_cb->trace_level; in smp_cb_cleanup()
860 alarm_t* smp_rsp_timer_ent = p_cb->smp_rsp_timer_ent; in smp_cb_cleanup()
861 alarm_t* delayed_auth_timer_ent = p_cb->delayed_auth_timer_ent; in smp_cb_cleanup()
865 alarm_cancel(p_cb->smp_rsp_timer_ent); in smp_cb_cleanup()
866 alarm_cancel(p_cb->delayed_auth_timer_ent); in smp_cb_cleanup()
867 memset(p_cb, 0, sizeof(tSMP_CB)); in smp_cb_cleanup()
868 p_cb->p_callback = p_callback; in smp_cb_cleanup()
869 p_cb->trace_level = trace_level; in smp_cb_cleanup()
870 p_cb->smp_rsp_timer_ent = smp_rsp_timer_ent; in smp_cb_cleanup()
871 p_cb->delayed_auth_timer_ent = delayed_auth_timer_ent; in smp_cb_cleanup()
883 void smp_remove_fixed_channel(tSMP_CB* p_cb) { in smp_remove_fixed_channel() argument
886 if (p_cb->smp_over_br) in smp_remove_fixed_channel()
887 L2CA_RemoveFixedChnl(L2CAP_SMP_BR_CID, p_cb->pairing_bda); in smp_remove_fixed_channel()
889 L2CA_RemoveFixedChnl(L2CAP_SMP_CID, p_cb->pairing_bda); in smp_remove_fixed_channel()
903 void smp_reset_control_value(tSMP_CB* p_cb) { in smp_reset_control_value() argument
906 alarm_cancel(p_cb->smp_rsp_timer_ent); in smp_reset_control_value()
907 p_cb->flags = 0; in smp_reset_control_value()
912 L2CA_SetIdleTimeoutByBdAddr(p_cb->pairing_bda, SMP_LINK_TOUT_MIN, in smp_reset_control_value()
916 smp_remove_fixed_channel(p_cb); in smp_reset_control_value()
917 smp_cb_cleanup(p_cb); in smp_reset_control_value()
930 void smp_proc_pairing_cmpl(tSMP_CB* p_cb) { in smp_proc_pairing_cmpl() argument
932 tSMP_CALLBACK* p_callback = p_cb->p_callback; in smp_proc_pairing_cmpl()
935 p_cb->pairing_bda.ToString().c_str()); in smp_proc_pairing_cmpl()
937 evt_data.cmplt.reason = p_cb->status; in smp_proc_pairing_cmpl()
938 evt_data.cmplt.smp_over_br = p_cb->smp_over_br; in smp_proc_pairing_cmpl()
940 if (p_cb->status == SMP_SUCCESS) evt_data.cmplt.sec_level = p_cb->sec_level; in smp_proc_pairing_cmpl()
944 if (p_cb->is_pair_cancel) evt_data.cmplt.is_pair_cancel = true; in smp_proc_pairing_cmpl()
949 RawAddress pairing_bda = p_cb->pairing_bda; in smp_proc_pairing_cmpl()
951 smp_reset_control_value(p_cb); in smp_proc_pairing_cmpl()
966 bool smp_command_has_invalid_length(tSMP_CB* p_cb) { in smp_command_has_invalid_length() argument
967 uint8_t cmd_code = p_cb->rcvd_cmd_code; in smp_command_has_invalid_length()
976 if (!smp_command_has_valid_fixed_length(p_cb)) { in smp_command_has_invalid_length()
995 bool smp_command_has_invalid_parameters(tSMP_CB* p_cb) { in smp_command_has_invalid_parameters() argument
996 uint8_t cmd_code = p_cb->rcvd_cmd_code; in smp_command_has_invalid_parameters()
1005 if (!(*smp_cmd_len_is_valid[cmd_code])(p_cb)) { in smp_command_has_invalid_parameters()
1011 if (!(*smp_cmd_param_ranges_are_valid[cmd_code])(p_cb)) { in smp_command_has_invalid_parameters()
1031 bool smp_command_has_valid_fixed_length(tSMP_CB* p_cb) { in smp_command_has_valid_fixed_length() argument
1032 uint8_t cmd_code = p_cb->rcvd_cmd_code; in smp_command_has_valid_fixed_length()
1036 if (p_cb->rcvd_cmd_len != smp_cmd_size_per_spec[cmd_code]) { in smp_command_has_valid_fixed_length()
1040 cmd_code, p_cb->rcvd_cmd_len, smp_cmd_size_per_spec[cmd_code]); in smp_command_has_valid_fixed_length()
1062 bool smp_pairing_request_response_parameters_are_valid(tSMP_CB* p_cb) { in smp_pairing_request_response_parameters_are_valid() argument
1063 uint8_t io_caps = p_cb->peer_io_caps; in smp_pairing_request_response_parameters_are_valid()
1064 uint8_t oob_flag = p_cb->peer_oob_flag; in smp_pairing_request_response_parameters_are_valid()
1066 p_cb->peer_auth_req & 0x03; // 0x03 is gen bond with appropriate mask in smp_pairing_request_response_parameters_are_valid()
1067 uint8_t enc_size = p_cb->peer_enc_size; in smp_pairing_request_response_parameters_are_valid()
1069 SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, p_cb->rcvd_cmd_code); in smp_pairing_request_response_parameters_are_valid()
1075 p_cb->rcvd_cmd_code, io_caps); in smp_pairing_request_response_parameters_are_valid()
1083 p_cb->rcvd_cmd_code, oob_flag); in smp_pairing_request_response_parameters_are_valid()
1091 p_cb->rcvd_cmd_code, bond_flag); in smp_pairing_request_response_parameters_are_valid()
1100 p_cb->rcvd_cmd_code, enc_size); in smp_pairing_request_response_parameters_are_valid()
1116 bool smp_pairing_keypress_notification_is_valid(tSMP_CB* p_cb) { in smp_pairing_keypress_notification_is_valid() argument
1117 tBTM_SP_KEY_TYPE keypress_notification = p_cb->peer_keypress_notification; in smp_pairing_keypress_notification_is_valid()
1119 SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, p_cb->rcvd_cmd_code); in smp_pairing_keypress_notification_is_valid()
1125 p_cb->rcvd_cmd_code, keypress_notification); in smp_pairing_keypress_notification_is_valid()
1139 bool smp_parameter_unconditionally_valid(UNUSED_ATTR tSMP_CB* p_cb) { in smp_parameter_unconditionally_valid() argument
1150 bool smp_parameter_unconditionally_invalid(UNUSED_ATTR tSMP_CB* p_cb) { in smp_parameter_unconditionally_invalid() argument
1198 tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB* p_cb) { in smp_select_association_model() argument
1200 p_cb->le_secure_connections_mode_is_used = false; in smp_select_association_model()
1204 __func__, p_cb->peer_io_caps, p_cb->local_io_capability); in smp_select_association_model()
1206 __func__, p_cb->peer_oob_flag, p_cb->loc_oob_flag); in smp_select_association_model()
1208 __func__, p_cb->peer_auth_req, p_cb->loc_auth_req); in smp_select_association_model()
1211 p_cb->secure_connections_only_mode_required ? "true" : "false"); in smp_select_association_model()
1213 if ((p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) && in smp_select_association_model()
1214 (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)) { in smp_select_association_model()
1215 p_cb->le_secure_connections_mode_is_used = true; in smp_select_association_model()
1218 if ((p_cb->peer_auth_req & SMP_H7_SUPPORT_BIT) && in smp_select_association_model()
1219 (p_cb->loc_auth_req & SMP_H7_SUPPORT_BIT)) { in smp_select_association_model()
1220 p_cb->key_derivation_h7_used = TRUE; in smp_select_association_model()
1224 p_cb->le_secure_connections_mode_is_used, in smp_select_association_model()
1225 p_cb->key_derivation_h7_used); in smp_select_association_model()
1227 if (p_cb->le_secure_connections_mode_is_used) { in smp_select_association_model()
1228 model = smp_select_association_model_secure_connections(p_cb); in smp_select_association_model()
1230 model = smp_select_legacy_association_model(p_cb); in smp_select_association_model()
1242 tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB* p_cb) { in smp_select_legacy_association_model() argument
1247 if (p_cb->peer_oob_flag == SMP_OOB_PRESENT && in smp_select_legacy_association_model()
1248 p_cb->loc_oob_flag == SMP_OOB_PRESENT) in smp_select_legacy_association_model()
1253 if (SMP_NO_MITM_REQUIRED(p_cb->peer_auth_req) && in smp_select_legacy_association_model()
1254 SMP_NO_MITM_REQUIRED(p_cb->loc_auth_req)) in smp_select_legacy_association_model()
1258 if (p_cb->peer_io_caps < SMP_IO_CAP_MAX && in smp_select_legacy_association_model()
1259 p_cb->local_io_capability < SMP_IO_CAP_MAX) { in smp_select_legacy_association_model()
1260 if (p_cb->role == HCI_ROLE_MASTER) { in smp_select_legacy_association_model()
1261 model = smp_association_table[p_cb->role][p_cb->peer_io_caps] in smp_select_legacy_association_model()
1262 [p_cb->local_io_capability]; in smp_select_legacy_association_model()
1264 model = smp_association_table[p_cb->role][p_cb->local_io_capability] in smp_select_legacy_association_model()
1265 [p_cb->peer_io_caps]; in smp_select_legacy_association_model()
1279 tSMP_ASSO_MODEL smp_select_association_model_secure_connections(tSMP_CB* p_cb) { in smp_select_association_model_secure_connections() argument
1285 if (p_cb->peer_oob_flag == SMP_OOB_PRESENT || in smp_select_association_model_secure_connections()
1286 p_cb->loc_oob_flag == SMP_OOB_PRESENT) in smp_select_association_model_secure_connections()
1291 if (SMP_NO_MITM_REQUIRED(p_cb->peer_auth_req) && in smp_select_association_model_secure_connections()
1292 SMP_NO_MITM_REQUIRED(p_cb->loc_auth_req)) in smp_select_association_model_secure_connections()
1296 if (p_cb->peer_io_caps < SMP_IO_CAP_MAX && in smp_select_association_model_secure_connections()
1297 p_cb->local_io_capability < SMP_IO_CAP_MAX) { in smp_select_association_model_secure_connections()
1298 if (p_cb->role == HCI_ROLE_MASTER) { in smp_select_association_model_secure_connections()
1299 model = smp_association_table_sc[p_cb->role][p_cb->peer_io_caps] in smp_select_association_model_secure_connections()
1300 [p_cb->local_io_capability]; in smp_select_association_model_secure_connections()
1302 model = smp_association_table_sc[p_cb->role][p_cb->local_io_capability] in smp_select_association_model_secure_connections()
1303 [p_cb->peer_io_caps]; in smp_select_association_model_secure_connections()
1360 void smp_collect_local_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb) { in smp_collect_local_io_capabilities() argument
1363 iocap[0] = p_cb->local_io_capability; in smp_collect_local_io_capabilities()
1364 iocap[1] = p_cb->loc_oob_flag; in smp_collect_local_io_capabilities()
1365 iocap[2] = p_cb->loc_auth_req; in smp_collect_local_io_capabilities()
1377 void smp_collect_peer_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb) { in smp_collect_peer_io_capabilities() argument
1380 iocap[0] = p_cb->peer_io_caps; in smp_collect_peer_io_capabilities()
1381 iocap[1] = p_cb->peer_oob_flag; in smp_collect_peer_io_capabilities()
1382 iocap[2] = p_cb->peer_auth_req; in smp_collect_peer_io_capabilities()
1395 void smp_collect_local_ble_address(uint8_t* le_addr, tSMP_CB* p_cb) { in smp_collect_local_ble_address() argument
1402 BTM_ReadConnectionAddr(p_cb->pairing_bda, bda, &addr_type); in smp_collect_local_ble_address()
1417 void smp_collect_peer_ble_address(uint8_t* le_addr, tSMP_CB* p_cb) { in smp_collect_peer_ble_address() argument
1424 if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, bda, &addr_type)) { in smp_collect_peer_ble_address()
1445 bool smp_check_commitment(tSMP_CB* p_cb) { in smp_check_commitment() argument
1449 Octet16 expected = smp_calculate_peer_commitment(p_cb); in smp_check_commitment()
1451 print128(p_cb->remote_commitment, (const uint8_t*)"received peer commitment"); in smp_check_commitment()
1453 if (memcmp(p_cb->remote_commitment.data(), expected.data(), OCTET16_LEN)) { in smp_check_commitment()
1472 void smp_save_secure_connections_long_term_key(tSMP_CB* p_cb) { in smp_save_secure_connections_long_term_key() argument
1477 lle_key.lenc_key.ltk = p_cb->ltk; in smp_save_secure_connections_long_term_key()
1479 lle_key.lenc_key.key_size = p_cb->loc_enc_size; in smp_save_secure_connections_long_term_key()
1480 lle_key.lenc_key.sec_level = p_cb->sec_level; in smp_save_secure_connections_long_term_key()
1481 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, &lle_key, true); in smp_save_secure_connections_long_term_key()
1486 ple_key.penc_key.ltk = p_cb->ltk; in smp_save_secure_connections_long_term_key()
1487 ple_key.penc_key.sec_level = p_cb->sec_level; in smp_save_secure_connections_long_term_key()
1488 ple_key.penc_key.key_size = p_cb->loc_enc_size; in smp_save_secure_connections_long_term_key()
1489 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, &ple_key, true); in smp_save_secure_connections_long_term_key()
1495 void smp_calculate_f5_mackey_and_long_term_key(tSMP_CB* p_cb) { in smp_calculate_f5_mackey_and_long_term_key() argument
1503 if (p_cb->role == HCI_ROLE_MASTER) { in smp_calculate_f5_mackey_and_long_term_key()
1504 smp_collect_local_ble_address(a, p_cb); in smp_calculate_f5_mackey_and_long_term_key()
1505 smp_collect_peer_ble_address(b, p_cb); in smp_calculate_f5_mackey_and_long_term_key()
1506 na = p_cb->rand; in smp_calculate_f5_mackey_and_long_term_key()
1507 nb = p_cb->rrand; in smp_calculate_f5_mackey_and_long_term_key()
1509 smp_collect_local_ble_address(b, p_cb); in smp_calculate_f5_mackey_and_long_term_key()
1510 smp_collect_peer_ble_address(a, p_cb); in smp_calculate_f5_mackey_and_long_term_key()
1511 na = p_cb->rrand; in smp_calculate_f5_mackey_and_long_term_key()
1512 nb = p_cb->rand; in smp_calculate_f5_mackey_and_long_term_key()
1515 crypto_toolbox::f5(p_cb->dhkey, na, nb, a, b, &p_cb->mac_key, &p_cb->ltk); in smp_calculate_f5_mackey_and_long_term_key()
1530 bool smp_request_oob_data(tSMP_CB* p_cb) { in smp_request_oob_data() argument
1535 if (p_cb->peer_oob_flag == SMP_OOB_PRESENT && in smp_request_oob_data()
1536 p_cb->loc_oob_flag == SMP_OOB_PRESENT) { in smp_request_oob_data()
1539 } else if (p_cb->peer_oob_flag == SMP_OOB_PRESENT) { in smp_request_oob_data()
1542 } else if (p_cb->loc_oob_flag == SMP_OOB_PRESENT) { in smp_request_oob_data()
1550 p_cb->req_oob_type = req_oob_type; in smp_request_oob_data()
1551 p_cb->cb_evt = SMP_SC_OOB_REQ_EVT; in smp_request_oob_data()
1554 smp_sm_event(p_cb, SMP_TK_REQ_EVT, &smp_int_data); in smp_request_oob_data()