Lines Matching refs:p_cb
52 static bool pts_test_send_authentication_complete_failure(tSMP_CB* p_cb) { in pts_test_send_authentication_complete_failure() argument
53 uint8_t reason = p_cb->cert_failure; in pts_test_send_authentication_complete_failure()
59 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in pts_test_send_authentication_complete_failure()
69 static void smp_update_key_mask(tSMP_CB* p_cb, uint8_t key_type, bool recv) { in smp_update_key_mask() argument
72 __func__, p_cb->role, recv, p_cb->local_i_key, p_cb->local_r_key); in smp_update_key_mask()
74 if (((p_cb->le_secure_connections_mode_is_used) || (p_cb->smp_over_br)) && in smp_update_key_mask()
79 p_cb->local_i_key &= ~key_type; in smp_update_key_mask()
80 p_cb->local_r_key &= ~key_type; in smp_update_key_mask()
81 } else if (p_cb->role == HCI_ROLE_SLAVE) { in smp_update_key_mask()
83 p_cb->local_i_key &= ~key_type; in smp_update_key_mask()
85 p_cb->local_r_key &= ~key_type; in smp_update_key_mask()
88 p_cb->local_r_key &= ~key_type; in smp_update_key_mask()
90 p_cb->local_i_key &= ~key_type; in smp_update_key_mask()
94 p_cb->local_i_key, p_cb->local_r_key); in smp_update_key_mask()
102 void smp_send_app_cback(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_app_cback() argument
105 SMP_TRACE_DEBUG("%s p_cb->cb_evt=%d", __func__, p_cb->cb_evt); in smp_send_app_cback()
106 if (p_cb->p_callback && p_cb->cb_evt != 0) { in smp_send_app_cback()
107 switch (p_cb->cb_evt) { in smp_send_app_cback()
109 cb_data.io_req.auth_req = p_cb->peer_auth_req; in smp_send_app_cback()
113 cb_data.io_req.init_keys = p_cb->local_i_key; in smp_send_app_cback()
114 cb_data.io_req.resp_keys = p_cb->local_r_key; in smp_send_app_cback()
125 cb_data.loc_oob_data = p_cb->sc_oob_data.loc_oob_data; in smp_send_app_cback()
142 (*p_cb->p_callback)(p_cb->cb_evt, p_cb->pairing_bda, &cb_data); in smp_send_app_cback()
145 callback_rc, p_cb->cb_evt); in smp_send_app_cback()
148 switch (p_cb->cb_evt) { in smp_send_app_cback()
150 p_cb->loc_auth_req = cb_data.io_req.auth_req; in smp_send_app_cback()
151 p_cb->local_io_capability = cb_data.io_req.io_cap; in smp_send_app_cback()
152 p_cb->loc_oob_flag = cb_data.io_req.oob_data; in smp_send_app_cback()
153 p_cb->loc_enc_size = cb_data.io_req.max_key_size; in smp_send_app_cback()
154 p_cb->local_i_key = cb_data.io_req.init_keys; in smp_send_app_cback()
155 p_cb->local_r_key = cb_data.io_req.resp_keys; in smp_send_app_cback()
157 if (!(p_cb->loc_auth_req & SMP_AUTH_BOND)) { in smp_send_app_cback()
159 p_cb->local_i_key = 0; in smp_send_app_cback()
160 p_cb->local_r_key = 0; in smp_send_app_cback()
167 p_cb->loc_auth_req, p_cb->local_io_capability, p_cb->loc_oob_flag, in smp_send_app_cback()
168 p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key); in smp_send_app_cback()
170 p_cb->secure_connections_only_mode_required = in smp_send_app_cback()
173 if (p_cb->secure_connections_only_mode_required) { in smp_send_app_cback()
174 p_cb->loc_auth_req |= SMP_SC_SUPPORT_BIT; in smp_send_app_cback()
177 if (!p_cb->secure_connections_only_mode_required && in smp_send_app_cback()
178 (!(p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT) || in smp_send_app_cback()
179 lmp_version_below(p_cb->pairing_bda, HCI_PROTO_VERSION_4_2) || in smp_send_app_cback()
181 (const RawAddress*)&p_cb->pairing_bda))) { in smp_send_app_cback()
182 p_cb->loc_auth_req &= ~SMP_SC_SUPPORT_BIT; in smp_send_app_cback()
183 p_cb->loc_auth_req &= ~SMP_KP_SUPPORT_BIT; in smp_send_app_cback()
184 p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_send_app_cback()
185 p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_send_app_cback()
188 if (lmp_version_below(p_cb->pairing_bda, HCI_PROTO_VERSION_5_0)) { in smp_send_app_cback()
189 p_cb->loc_auth_req &= ~SMP_H7_SUPPORT_BIT; in smp_send_app_cback()
194 p_cb->loc_auth_req, p_cb->local_i_key, p_cb->local_r_key); in smp_send_app_cback()
196 smp_sm_event(p_cb, SMP_IO_RSP_EVT, NULL); in smp_send_app_cback()
200 p_cb->loc_enc_size = cb_data.io_req.max_key_size; in smp_send_app_cback()
201 p_cb->local_i_key = cb_data.io_req.init_keys; in smp_send_app_cback()
202 p_cb->local_r_key = cb_data.io_req.resp_keys; in smp_send_app_cback()
203 p_cb->loc_auth_req |= SMP_H7_SUPPORT_BIT; in smp_send_app_cback()
205 p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_send_app_cback()
206 p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_send_app_cback()
211 p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key, in smp_send_app_cback()
212 p_cb->loc_auth_req); in smp_send_app_cback()
214 smp_br_state_machine_event(p_cb, SMP_BR_KEYS_RSP_EVT, NULL); in smp_send_app_cback()
220 if (!p_cb->cb_evt && p_cb->discard_sec_req) { in smp_send_app_cback()
221 p_cb->discard_sec_req = false; in smp_send_app_cback()
222 smp_sm_event(p_cb, SMP_DISCARD_SEC_REQ_EVT, NULL); in smp_send_app_cback()
232 void smp_send_pair_fail(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_pair_fail() argument
233 p_cb->status = p_data->status; in smp_send_pair_fail()
234 p_cb->failure = p_data->status; in smp_send_pair_fail()
236 SMP_TRACE_DEBUG("%s: status=%d failure=%d ", __func__, p_cb->status, in smp_send_pair_fail()
237 p_cb->failure); in smp_send_pair_fail()
239 if (p_cb->status <= SMP_MAX_FAIL_RSN_PER_SPEC && in smp_send_pair_fail()
240 p_cb->status != SMP_SUCCESS) { in smp_send_pair_fail()
241 smp_send_cmd(SMP_OPCODE_PAIRING_FAILED, p_cb); in smp_send_pair_fail()
242 p_cb->wait_for_authorization_complete = true; in smp_send_pair_fail()
250 void smp_send_pair_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_pair_req() argument
251 tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(p_cb->pairing_bda); in smp_send_pair_req()
258 smp_send_cmd(SMP_OPCODE_PAIRING_REQ, p_cb); in smp_send_pair_req()
265 void smp_send_pair_rsp(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_pair_rsp() argument
268 p_cb->local_i_key &= p_cb->peer_i_key; in smp_send_pair_rsp()
269 p_cb->local_r_key &= p_cb->peer_r_key; in smp_send_pair_rsp()
271 if (smp_send_cmd(SMP_OPCODE_PAIRING_RSP, p_cb)) { in smp_send_pair_rsp()
272 if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) in smp_send_pair_rsp()
273 smp_use_oob_private_key(p_cb, NULL); in smp_send_pair_rsp()
275 smp_decide_association_model(p_cb, NULL); in smp_send_pair_rsp()
283 void smp_send_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_confirm() argument
285 smp_send_cmd(SMP_OPCODE_CONFIRM, p_cb); in smp_send_confirm()
292 void smp_send_init(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_init() argument
294 smp_send_cmd(SMP_OPCODE_INIT, p_cb); in smp_send_init()
301 void smp_send_rand(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_rand() argument
303 smp_send_cmd(SMP_OPCODE_RAND, p_cb); in smp_send_rand()
310 void smp_send_pair_public_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_pair_public_key() argument
312 smp_send_cmd(SMP_OPCODE_PAIR_PUBLIC_KEY, p_cb); in smp_send_pair_public_key()
319 void smp_send_commitment(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_commitment() argument
321 smp_send_cmd(SMP_OPCODE_PAIR_COMMITM, p_cb); in smp_send_commitment()
328 void smp_send_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_dhkey_check() argument
330 smp_send_cmd(SMP_OPCODE_PAIR_DHKEY_CHECK, p_cb); in smp_send_dhkey_check()
337 void smp_send_keypress_notification(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_keypress_notification() argument
338 p_cb->local_keypress_notification = p_data->status; in smp_send_keypress_notification()
339 smp_send_cmd(SMP_OPCODE_PAIR_KEYPR_NOTIF, p_cb); in smp_send_keypress_notification()
346 void smp_send_enc_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_enc_info() argument
349 SMP_TRACE_DEBUG("%s: p_cb->loc_enc_size = %d", __func__, p_cb->loc_enc_size); in smp_send_enc_info()
350 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ENC, false); in smp_send_enc_info()
352 smp_send_cmd(SMP_OPCODE_ENCRYPT_INFO, p_cb); in smp_send_enc_info()
353 smp_send_cmd(SMP_OPCODE_MASTER_ID, p_cb); in smp_send_enc_info()
356 le_key.lenc_key.ltk = p_cb->ltk; in smp_send_enc_info()
357 le_key.lenc_key.div = p_cb->div; in smp_send_enc_info()
358 le_key.lenc_key.key_size = p_cb->loc_enc_size; in smp_send_enc_info()
359 le_key.lenc_key.sec_level = p_cb->sec_level; in smp_send_enc_info()
361 if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && in smp_send_enc_info()
362 (p_cb->loc_auth_req & SMP_AUTH_BOND)) in smp_send_enc_info()
363 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, &le_key, true); in smp_send_enc_info()
367 smp_key_distribution(p_cb, NULL); in smp_send_enc_info()
374 void smp_send_id_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_id_info() argument
377 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ID, false); in smp_send_id_info()
379 smp_send_cmd(SMP_OPCODE_IDENTITY_INFO, p_cb); in smp_send_id_info()
380 smp_send_cmd(SMP_OPCODE_ID_ADDR, p_cb); in smp_send_id_info()
382 if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && in smp_send_id_info()
383 (p_cb->loc_auth_req & SMP_AUTH_BOND)) in smp_send_id_info()
384 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LID, &le_key, true); in smp_send_id_info()
387 smp_key_distribution_by_transport(p_cb, NULL); in smp_send_id_info()
391 void smp_send_csrk_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_csrk_info() argument
394 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_CSRK, false); in smp_send_csrk_info()
396 if (smp_send_cmd(SMP_OPCODE_SIGN_INFO, p_cb)) { in smp_send_csrk_info()
397 key.lcsrk_key.div = p_cb->div; in smp_send_csrk_info()
398 key.lcsrk_key.sec_level = p_cb->sec_level; in smp_send_csrk_info()
400 key.lcsrk_key.csrk = p_cb->csrk; in smp_send_csrk_info()
401 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LCSRK, &key, true); in smp_send_csrk_info()
404 smp_key_distribution_by_transport(p_cb, NULL); in smp_send_csrk_info()
411 void smp_send_ltk_reply(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_send_ltk_reply() argument
417 btm_ble_ltk_request_reply(p_cb->pairing_bda, true, stk); in smp_send_ltk_reply()
424 void smp_proc_sec_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_sec_req() argument
430 p_cb->cb_evt = 0; in smp_proc_sec_req()
432 btm_ble_link_sec_check(p_cb->pairing_bda, auth_req, &sec_req_act); in smp_proc_sec_req()
439 smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); in smp_proc_sec_req()
443 p_cb->secure_connections_only_mode_required = in smp_proc_sec_req()
447 if (p_cb->secure_connections_only_mode_required && in smp_proc_sec_req()
451 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_sec_req()
454 p_cb->peer_auth_req = auth_req; in smp_proc_sec_req()
455 p_cb->local_r_key = p_cb->local_i_key = SMP_SEC_DEFAULT_KEY; in smp_proc_sec_req()
456 p_cb->cb_evt = SMP_SEC_REQUEST_EVT; in smp_proc_sec_req()
461 p_cb->discard_sec_req = true; in smp_proc_sec_req()
474 void smp_proc_sec_grant(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_sec_grant() argument
478 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, p_data); in smp_proc_sec_grant()
482 p_cb->cb_evt = SMP_IO_CAP_REQ_EVT; in smp_proc_sec_grant()
490 void smp_proc_pair_fail(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_pair_fail() argument
493 if (p_cb->rcvd_cmd_len < 2) { in smp_proc_pair_fail()
496 __func__, p_cb->rcvd_cmd_len); in smp_proc_pair_fail()
497 p_cb->status = SMP_INVALID_PARAMETERS; in smp_proc_pair_fail()
499 p_cb->status = p_data->status; in smp_proc_pair_fail()
503 alarm_cancel(p_cb->delayed_auth_timer_ent); in smp_proc_pair_fail()
510 void smp_proc_pair_cmd(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_pair_cmd() argument
512 tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(p_cb->pairing_bda); in smp_proc_pair_cmd()
515 p_cb->pairing_bda.ToString().c_str()); in smp_proc_pair_cmd()
518 if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) in smp_proc_pair_cmd()
521 p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR; in smp_proc_pair_cmd()
523 if (smp_command_has_invalid_length(p_cb)) { in smp_proc_pair_cmd()
527 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_pair_cmd()
531 STREAM_TO_UINT8(p_cb->peer_io_caps, p); in smp_proc_pair_cmd()
532 STREAM_TO_UINT8(p_cb->peer_oob_flag, p); in smp_proc_pair_cmd()
533 STREAM_TO_UINT8(p_cb->peer_auth_req, p); in smp_proc_pair_cmd()
534 STREAM_TO_UINT8(p_cb->peer_enc_size, p); in smp_proc_pair_cmd()
535 STREAM_TO_UINT8(p_cb->peer_i_key, p); in smp_proc_pair_cmd()
536 STREAM_TO_UINT8(p_cb->peer_r_key, p); in smp_proc_pair_cmd()
538 if (smp_command_has_invalid_parameters(p_cb)) { in smp_proc_pair_cmd()
541 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_pair_cmd()
546 if (pts_test_send_authentication_complete_failure(p_cb)) return; in smp_proc_pair_cmd()
548 if (p_cb->role == HCI_ROLE_SLAVE) { in smp_proc_pair_cmd()
549 if (!(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) { in smp_proc_pair_cmd()
551 p_cb->local_i_key = p_cb->peer_i_key; in smp_proc_pair_cmd()
552 p_cb->local_r_key = p_cb->peer_r_key; in smp_proc_pair_cmd()
554 p_cb->cb_evt = SMP_SEC_REQUEST_EVT; in smp_proc_pair_cmd()
558 p_cb->local_i_key &= p_cb->peer_i_key; in smp_proc_pair_cmd()
559 p_cb->local_r_key &= p_cb->peer_r_key; in smp_proc_pair_cmd()
560 p_cb->selected_association_model = smp_select_association_model(p_cb); in smp_proc_pair_cmd()
562 if (p_cb->secure_connections_only_mode_required && in smp_proc_pair_cmd()
563 (!(p_cb->le_secure_connections_mode_is_used) || in smp_proc_pair_cmd()
564 (p_cb->selected_association_model == in smp_proc_pair_cmd()
571 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_pair_cmd()
575 if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) { in smp_proc_pair_cmd()
576 if (smp_request_oob_data(p_cb)) return; in smp_proc_pair_cmd()
578 smp_send_pair_rsp(p_cb, NULL); in smp_proc_pair_cmd()
583 p_cb->selected_association_model = smp_select_association_model(p_cb); in smp_proc_pair_cmd()
585 if (p_cb->secure_connections_only_mode_required && in smp_proc_pair_cmd()
586 (!(p_cb->le_secure_connections_mode_is_used) || in smp_proc_pair_cmd()
587 (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) { in smp_proc_pair_cmd()
593 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_pair_cmd()
597 if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) { in smp_proc_pair_cmd()
598 if (smp_request_oob_data(p_cb)) return; in smp_proc_pair_cmd()
600 smp_decide_association_model(p_cb, NULL); in smp_proc_pair_cmd()
606 void smp_proc_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_confirm() argument
609 if (smp_command_has_invalid_parameters(p_cb)) { in smp_proc_confirm()
612 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_confirm()
620 STREAM_TO_ARRAY(p_cb->rconfirm.data(), p, OCTET16_LEN); in smp_proc_confirm()
624 p_cb->flags |= SMP_PAIR_FLAGS_CMD_CONFIRM; in smp_proc_confirm()
628 void smp_proc_init(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_init() argument
633 if (smp_command_has_invalid_parameters(p_cb)) { in smp_proc_init()
636 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_init()
641 STREAM_TO_ARRAY(p_cb->rrand.data(), p, OCTET16_LEN); in smp_proc_init()
648 void smp_proc_rand(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_rand() argument
653 if (smp_command_has_invalid_parameters(p_cb)) { in smp_proc_rand()
656 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_rand()
661 STREAM_TO_ARRAY(p_cb->rrand.data(), p, OCTET16_LEN); in smp_proc_rand()
672 void smp_process_pairing_public_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_process_pairing_public_key() argument
677 if (smp_command_has_invalid_parameters(p_cb)) { in smp_process_pairing_public_key()
680 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_pairing_public_key()
684 STREAM_TO_ARRAY(p_cb->peer_publ_key.x, p, BT_OCTET32_LEN); in smp_process_pairing_public_key()
685 STREAM_TO_ARRAY(p_cb->peer_publ_key.y, p, BT_OCTET32_LEN); in smp_process_pairing_public_key()
688 memcpy(pt.x, p_cb->peer_publ_key.x, BT_OCTET32_LEN); in smp_process_pairing_public_key()
689 memcpy(pt.y, p_cb->peer_publ_key.y, BT_OCTET32_LEN); in smp_process_pairing_public_key()
695 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp); in smp_process_pairing_public_key()
699 p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY; in smp_process_pairing_public_key()
701 smp_wait_for_both_public_keys(p_cb, NULL); in smp_process_pairing_public_key()
708 void smp_process_pairing_commitment(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_process_pairing_commitment() argument
713 if (smp_command_has_invalid_parameters(p_cb)) { in smp_process_pairing_commitment()
716 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_pairing_commitment()
720 p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_COMM; in smp_process_pairing_commitment()
723 STREAM_TO_ARRAY(p_cb->remote_commitment.data(), p, OCTET16_LEN); in smp_process_pairing_commitment()
731 void smp_process_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_process_dhkey_check() argument
736 if (smp_command_has_invalid_parameters(p_cb)) { in smp_process_dhkey_check()
739 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_dhkey_check()
744 STREAM_TO_ARRAY(p_cb->remote_dhkey_check.data(), p, OCTET16_LEN); in smp_process_dhkey_check()
747 p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK; in smp_process_dhkey_check()
754 void smp_process_keypress_notification(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_process_keypress_notification() argument
758 p_cb->status = p_data->status; in smp_process_keypress_notification()
760 if (smp_command_has_invalid_parameters(p_cb)) { in smp_process_keypress_notification()
763 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_keypress_notification()
768 STREAM_TO_UINT8(p_cb->peer_keypress_notification, p); in smp_process_keypress_notification()
770 p_cb->peer_keypress_notification = BTM_SP_KEY_OUT_OF_RANGE; in smp_process_keypress_notification()
772 p_cb->cb_evt = SMP_PEER_KEYPR_NOT_EVT; in smp_process_keypress_notification()
780 void smp_br_process_pairing_command(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_br_process_pairing_command() argument
782 tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(p_cb->pairing_bda); in smp_br_process_pairing_command()
786 if (!p_dev_rec->new_encryption_key_is_p256 && p_cb->role == HCI_ROLE_SLAVE) { in smp_br_process_pairing_command()
789 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data); in smp_br_process_pairing_command()
794 if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) in smp_br_process_pairing_command()
797 p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR; in smp_br_process_pairing_command()
799 if (smp_command_has_invalid_length(p_cb)) { in smp_br_process_pairing_command()
803 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data); in smp_br_process_pairing_command()
807 STREAM_TO_UINT8(p_cb->peer_io_caps, p); in smp_br_process_pairing_command()
808 STREAM_TO_UINT8(p_cb->peer_oob_flag, p); in smp_br_process_pairing_command()
809 STREAM_TO_UINT8(p_cb->peer_auth_req, p); in smp_br_process_pairing_command()
810 STREAM_TO_UINT8(p_cb->peer_enc_size, p); in smp_br_process_pairing_command()
811 STREAM_TO_UINT8(p_cb->peer_i_key, p); in smp_br_process_pairing_command()
812 STREAM_TO_UINT8(p_cb->peer_r_key, p); in smp_br_process_pairing_command()
814 if (smp_command_has_invalid_parameters(p_cb)) { in smp_br_process_pairing_command()
817 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data); in smp_br_process_pairing_command()
823 p_cb->local_i_key = p_cb->peer_i_key; in smp_br_process_pairing_command()
824 p_cb->local_r_key = p_cb->peer_r_key; in smp_br_process_pairing_command()
826 if (p_cb->role == HCI_ROLE_SLAVE) { in smp_br_process_pairing_command()
829 p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT; in smp_br_process_pairing_command()
840 p_cb->peer_auth_req |= SMP_AUTH_BOND; in smp_br_process_pairing_command()
841 p_cb->loc_auth_req |= SMP_AUTH_BOND; in smp_br_process_pairing_command()
848 void smp_br_process_security_grant(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_br_process_security_grant() argument
851 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, p_data); in smp_br_process_security_grant()
854 p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT; in smp_br_process_security_grant()
863 void smp_br_check_authorization_request(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_br_check_authorization_request() argument
865 __func__, p_cb->local_i_key, p_cb->local_r_key); in smp_br_check_authorization_request()
868 p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_br_check_authorization_request()
869 p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_br_check_authorization_request()
873 if (p_cb->role == HCI_ROLE_MASTER) { in smp_br_check_authorization_request()
874 p_cb->local_r_key &= (SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK); in smp_br_check_authorization_request()
878 if ((p_cb->loc_auth_req & SMP_H7_SUPPORT_BIT) && in smp_br_check_authorization_request()
879 (p_cb->peer_auth_req & SMP_H7_SUPPORT_BIT)) { in smp_br_check_authorization_request()
880 p_cb->key_derivation_h7_used = TRUE; in smp_br_check_authorization_request()
882 SMP_TRACE_DEBUG("%s: use h7 = %d", __func__, p_cb->key_derivation_h7_used); in smp_br_check_authorization_request()
886 __func__, p_cb->local_i_key, p_cb->local_r_key); in smp_br_check_authorization_request()
890 (p_cb->local_i_key || p_cb->local_r_key)) { in smp_br_check_authorization_request()
891 smp_br_state_machine_event(p_cb, SMP_BR_BOND_REQ_EVT, NULL); in smp_br_check_authorization_request()
894 if (p_cb->role == HCI_ROLE_MASTER && p_cb->local_r_key == 0) in smp_br_check_authorization_request()
895 smp_key_distribution_by_transport(p_cb, NULL); in smp_br_check_authorization_request()
899 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data); in smp_br_check_authorization_request()
908 void smp_br_select_next_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_br_select_next_key() argument
910 p_cb->role, p_cb->local_r_key, p_cb->local_i_key); in smp_br_select_next_key()
912 if (p_cb->role == HCI_ROLE_SLAVE || in smp_br_select_next_key()
913 (!p_cb->local_r_key && p_cb->role == HCI_ROLE_MASTER)) { in smp_br_select_next_key()
914 smp_key_pick_key(p_cb, p_data); in smp_br_select_next_key()
917 if (!p_cb->local_i_key && !p_cb->local_r_key) { in smp_br_select_next_key()
920 if (p_cb->total_tx_unacked == 0) { in smp_br_select_next_key()
923 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data); in smp_br_select_next_key()
925 p_cb->wait_for_authorization_complete = true; in smp_br_select_next_key()
932 void smp_proc_enc_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_enc_info() argument
937 if (smp_command_has_invalid_parameters(p_cb)) { in smp_proc_enc_info()
941 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_enc_info()
945 STREAM_TO_ARRAY(p_cb->ltk.data(), p, OCTET16_LEN); in smp_proc_enc_info()
947 smp_key_distribution(p_cb, NULL); in smp_proc_enc_info()
951 void smp_proc_master_id(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_master_id() argument
957 if (p_cb->rcvd_cmd_len < 11) { // 1(Code) + 2(EDIV) + 8(Rand) in smp_proc_master_id()
960 __func__, p_cb->rcvd_cmd_len); in smp_proc_master_id()
964 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ENC, true); in smp_proc_master_id()
970 le_key.penc_key.ltk = p_cb->ltk; in smp_proc_master_id()
971 le_key.penc_key.sec_level = p_cb->sec_level; in smp_proc_master_id()
972 le_key.penc_key.key_size = p_cb->loc_enc_size; in smp_proc_master_id()
974 if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && in smp_proc_master_id()
975 (p_cb->loc_auth_req & SMP_AUTH_BOND)) in smp_proc_master_id()
976 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, &le_key, true); in smp_proc_master_id()
978 smp_key_distribution(p_cb, NULL); in smp_proc_master_id()
982 void smp_proc_id_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_id_info() argument
987 if (smp_command_has_invalid_parameters(p_cb)) { in smp_proc_id_info()
991 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_id_info()
995 STREAM_TO_ARRAY(p_cb->tk.data(), p, OCTET16_LEN); /* reuse TK for IRK */ in smp_proc_id_info()
996 smp_key_distribution_by_transport(p_cb, NULL); in smp_proc_id_info()
1000 void smp_proc_id_addr(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_id_addr() argument
1006 if (smp_command_has_invalid_parameters(p_cb)) { in smp_proc_id_addr()
1010 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_id_addr()
1014 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ID, true); in smp_proc_id_addr()
1018 pid_key.pid_key.irk = p_cb->tk; in smp_proc_id_addr()
1021 p_cb->id_addr_rcvd = true; in smp_proc_id_addr()
1022 p_cb->id_addr_type = pid_key.pid_key.identity_addr_type; in smp_proc_id_addr()
1023 p_cb->id_addr = pid_key.pid_key.identity_addr; in smp_proc_id_addr()
1026 if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && in smp_proc_id_addr()
1027 (p_cb->loc_auth_req & SMP_AUTH_BOND)) in smp_proc_id_addr()
1028 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PID, &pid_key, true); in smp_proc_id_addr()
1029 smp_key_distribution_by_transport(p_cb, NULL); in smp_proc_id_addr()
1033 void smp_proc_srk_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_srk_info() argument
1038 if (smp_command_has_invalid_parameters(p_cb)) { in smp_proc_srk_info()
1042 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_srk_info()
1046 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_CSRK, true); in smp_proc_srk_info()
1049 le_key.pcsrk_key.sec_level = p_cb->sec_level; in smp_proc_srk_info()
1058 if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && in smp_proc_srk_info()
1059 (p_cb->loc_auth_req & SMP_AUTH_BOND)) in smp_proc_srk_info()
1060 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PCSRK, &le_key, true); in smp_proc_srk_info()
1061 smp_key_distribution_by_transport(p_cb, NULL); in smp_proc_srk_info()
1068 void smp_proc_compare(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_compare() argument
1070 if (!memcmp(p_cb->rconfirm.data(), p_data->key.p_data, OCTET16_LEN)) { in smp_proc_compare()
1073 if (p_cb->peer_enc_size < p_cb->loc_enc_size) in smp_proc_compare()
1074 p_cb->loc_enc_size = p_cb->peer_enc_size; in smp_proc_compare()
1076 if (p_cb->role == HCI_ROLE_SLAVE) in smp_proc_compare()
1077 smp_sm_event(p_cb, SMP_RAND_EVT, NULL); in smp_proc_compare()
1080 p_cb->local_i_key = p_cb->peer_i_key; in smp_proc_compare()
1081 p_cb->local_r_key = p_cb->peer_r_key; in smp_proc_compare()
1083 smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); in smp_proc_compare()
1089 p_cb->failure = SMP_CONFIRM_VALUE_ERR; in smp_proc_compare()
1090 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_proc_compare()
1098 void smp_proc_sl_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_sl_key() argument
1103 smp_generate_srand_mrand_confirm(p_cb, NULL); in smp_proc_sl_key()
1107 if (p_cb->flags & SMP_PAIR_FLAGS_CMD_CONFIRM) in smp_proc_sl_key()
1108 smp_sm_event(p_cb, SMP_CONFIRM_EVT, NULL); in smp_proc_sl_key()
1116 void smp_start_enc(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_start_enc() argument
1121 cmd = btm_ble_start_encrypt(p_cb->pairing_bda, true, in smp_start_enc()
1124 cmd = btm_ble_start_encrypt(p_cb->pairing_bda, false, NULL); in smp_start_enc()
1130 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_start_enc()
1138 void smp_proc_discard(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_proc_discard() argument
1140 if (!(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) in smp_proc_discard()
1141 smp_reset_control_value(p_cb); in smp_proc_discard()
1148 void smp_enc_cmpl(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_enc_cmpl() argument
1154 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_enc_cmpl()
1161 void smp_check_auth_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_check_auth_req() argument
1166 __func__, enc_enable, p_cb->local_i_key, p_cb->local_r_key); in smp_check_auth_req()
1168 if (p_cb->le_secure_connections_mode_is_used) { in smp_check_auth_req()
1170 p_cb->local_i_key |= SMP_SEC_KEY_TYPE_ENC; in smp_check_auth_req()
1171 p_cb->local_r_key |= SMP_SEC_KEY_TYPE_ENC; in smp_check_auth_req()
1174 if (!(p_cb->local_i_key & SMP_SEC_KEY_TYPE_LK) || in smp_check_auth_req()
1175 !(p_cb->local_r_key & SMP_SEC_KEY_TYPE_LK)) { in smp_check_auth_req()
1176 p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_check_auth_req()
1177 p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_check_auth_req()
1183 if (p_cb->role == HCI_ROLE_MASTER) { in smp_check_auth_req()
1184 p_cb->local_r_key &= (SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK); in smp_check_auth_req()
1188 p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_check_auth_req()
1189 p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; in smp_check_auth_req()
1193 __func__, p_cb->local_i_key, p_cb->local_r_key); in smp_check_auth_req()
1197 (p_cb->local_i_key || p_cb->local_r_key)) { in smp_check_auth_req()
1198 smp_sm_event(p_cb, SMP_BOND_REQ_EVT, NULL); in smp_check_auth_req()
1202 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_check_auth_req()
1208 if (p_cb->flags & SMP_PAIR_FLAG_ENC_AFTER_PAIR) in smp_check_auth_req()
1209 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_check_auth_req()
1212 else if (p_cb->role == HCI_ROLE_MASTER) { in smp_check_auth_req()
1213 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_check_auth_req()
1222 void smp_key_pick_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_key_pick_key() argument
1224 (p_cb->role == HCI_ROLE_SLAVE) ? p_cb->local_r_key : p_cb->local_i_key; in smp_key_pick_key()
1233 (*smp_distribute_act[i])(p_cb, p_data); in smp_key_pick_key()
1243 void smp_key_distribution(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_key_distribution() argument
1245 p_cb->role, p_cb->local_r_key, p_cb->local_i_key); in smp_key_distribution()
1247 if (p_cb->role == HCI_ROLE_SLAVE || in smp_key_distribution()
1248 (!p_cb->local_r_key && p_cb->role == HCI_ROLE_MASTER)) { in smp_key_distribution()
1249 smp_key_pick_key(p_cb, p_data); in smp_key_distribution()
1252 if (!p_cb->local_i_key && !p_cb->local_r_key) { in smp_key_distribution()
1255 if (p_cb->derive_lk) { in smp_key_distribution()
1256 smp_derive_link_key_from_long_term_key(p_cb, NULL); in smp_key_distribution()
1257 p_cb->derive_lk = false; in smp_key_distribution()
1260 if (p_cb->total_tx_unacked == 0) { in smp_key_distribution()
1268 if (!alarm_is_scheduled(p_cb->delayed_auth_timer_ent)) { in smp_key_distribution()
1270 alarm_set_on_mloop(p_cb->delayed_auth_timer_ent, in smp_key_distribution()
1275 p_cb->wait_for_authorization_complete = true; in smp_key_distribution()
1287 void smp_decide_association_model(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_decide_association_model() argument
1292 p_cb->selected_association_model); in smp_decide_association_model()
1294 switch (p_cb->selected_association_model) { in smp_decide_association_model()
1296 if (p_cb->role == HCI_ROLE_MASTER && in smp_decide_association_model()
1297 ((p_cb->peer_auth_req & SMP_AUTH_YN_BIT) != 0) && in smp_decide_association_model()
1298 ((p_cb->loc_auth_req & SMP_AUTH_YN_BIT) == 0)) { in smp_decide_association_model()
1304 p_cb->sec_level = SMP_SEC_UNAUTHENTICATE; in smp_decide_association_model()
1306 p_cb->sec_level); in smp_decide_association_model()
1310 key.p_data = p_cb->tk.data(); in smp_decide_association_model()
1313 p_cb->tk = {0}; in smp_decide_association_model()
1320 p_cb->sec_level = SMP_SEC_AUTHENTICATED; in smp_decide_association_model()
1322 p_cb->sec_level); in smp_decide_association_model()
1324 p_cb->cb_evt = SMP_PASSKEY_REQ_EVT; in smp_decide_association_model()
1330 p_cb->sec_level = SMP_SEC_AUTHENTICATED; in smp_decide_association_model()
1332 p_cb->sec_level); in smp_decide_association_model()
1334 p_cb->cb_evt = SMP_OOB_REQ_EVT; in smp_decide_association_model()
1339 p_cb->sec_level = SMP_SEC_AUTHENTICATED; in smp_decide_association_model()
1343 smp_generate_passkey(p_cb, NULL); in smp_decide_association_model()
1363 p_cb->selected_association_model); in smp_decide_association_model()
1368 SMP_TRACE_EVENT("sec_level=%d ", p_cb->sec_level); in smp_decide_association_model()
1369 if (int_evt) smp_sm_event(p_cb, int_evt, &smp_int_data); in smp_decide_association_model()
1376 void smp_process_io_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_process_io_response() argument
1379 if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) { in smp_process_io_response()
1382 smp_send_cmd(SMP_OPCODE_SEC_REQ, p_cb); in smp_process_io_response()
1386 p_cb->selected_association_model = smp_select_association_model(p_cb); in smp_process_io_response()
1388 if (p_cb->secure_connections_only_mode_required && in smp_process_io_response()
1389 (!(p_cb->le_secure_connections_mode_is_used) || in smp_process_io_response()
1390 (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) { in smp_process_io_response()
1396 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_io_response()
1400 if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) { in smp_process_io_response()
1401 if (smp_request_oob_data(p_cb)) return; in smp_process_io_response()
1405 if (pts_test_send_authentication_complete_failure(p_cb)) return; in smp_process_io_response()
1407 smp_send_pair_rsp(p_cb, NULL); in smp_process_io_response()
1416 void smp_br_process_slave_keys_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_br_process_slave_keys_response() argument
1417 smp_br_send_pair_response(p_cb, NULL); in smp_br_process_slave_keys_response()
1425 void smp_br_send_pair_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_br_send_pair_response() argument
1428 p_cb->local_i_key &= p_cb->peer_i_key; in smp_br_send_pair_response()
1429 p_cb->local_r_key &= p_cb->peer_r_key; in smp_br_send_pair_response()
1431 smp_send_cmd(SMP_OPCODE_PAIRING_RSP, p_cb); in smp_br_send_pair_response()
1439 void smp_pairing_cmpl(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_pairing_cmpl() argument
1440 if (p_cb->total_tx_unacked == 0) { in smp_pairing_cmpl()
1442 smp_proc_pairing_cmpl(p_cb); in smp_pairing_cmpl()
1451 void smp_pair_terminate(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_pair_terminate() argument
1453 p_cb->status = SMP_CONN_TOUT; in smp_pair_terminate()
1454 smp_proc_pairing_cmpl(p_cb); in smp_pair_terminate()
1462 void smp_idle_terminate(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_idle_terminate() argument
1463 if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) { in smp_idle_terminate()
1465 p_cb->status = SMP_FAIL; in smp_idle_terminate()
1466 smp_proc_pairing_cmpl(p_cb); in smp_idle_terminate()
1479 void smp_both_have_public_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_both_have_public_keys() argument
1483 smp_compute_dhkey(p_cb); in smp_both_have_public_keys()
1486 if (p_cb->role == HCI_ROLE_SLAVE) smp_send_pair_public_key(p_cb, NULL); in smp_both_have_public_keys()
1488 smp_sm_event(p_cb, SMP_SC_DHKEY_CMPLT_EVT, NULL); in smp_both_have_public_keys()
1498 void smp_start_secure_connection_phase1(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_start_secure_connection_phase1() argument
1501 if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) { in smp_start_secure_connection_phase1()
1502 p_cb->sec_level = SMP_SEC_UNAUTHENTICATE; in smp_start_secure_connection_phase1()
1504 p_cb->sec_level); in smp_start_secure_connection_phase1()
1506 p_cb->sec_level = SMP_SEC_AUTHENTICATED; in smp_start_secure_connection_phase1()
1508 p_cb->sec_level); in smp_start_secure_connection_phase1()
1511 switch (p_cb->selected_association_model) { in smp_start_secure_connection_phase1()
1514 p_cb->local_random = {0}; in smp_start_secure_connection_phase1()
1515 smp_start_nonce_generation(p_cb); in smp_start_secure_connection_phase1()
1519 p_cb->cb_evt = SMP_PASSKEY_REQ_EVT; in smp_start_secure_connection_phase1()
1520 smp_sm_event(p_cb, SMP_TK_REQ_EVT, NULL); in smp_start_secure_connection_phase1()
1525 smp_generate_passkey(p_cb, NULL); in smp_start_secure_connection_phase1()
1529 smp_process_secure_connection_oob_data(p_cb, NULL); in smp_start_secure_connection_phase1()
1533 p_cb->selected_association_model); in smp_start_secure_connection_phase1()
1544 void smp_process_local_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_process_local_nonce() argument
1547 switch (p_cb->selected_association_model) { in smp_process_local_nonce()
1550 if (p_cb->role == HCI_ROLE_SLAVE) { in smp_process_local_nonce()
1552 smp_calculate_local_commitment(p_cb); in smp_process_local_nonce()
1553 smp_send_commitment(p_cb, NULL); in smp_process_local_nonce()
1558 if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_COMM) { in smp_process_local_nonce()
1564 p_cb->selected_association_model); in smp_process_local_nonce()
1565 p_cb->flags &= ~SMP_PAIR_FLAG_HAVE_PEER_COMM; in smp_process_local_nonce()
1566 smp_send_rand(p_cb, NULL); in smp_process_local_nonce()
1573 smp_calculate_local_commitment(p_cb); in smp_process_local_nonce()
1575 if (p_cb->role == HCI_ROLE_MASTER) { in smp_process_local_nonce()
1576 smp_send_commitment(p_cb, NULL); in smp_process_local_nonce()
1579 if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_COMM) { in smp_process_local_nonce()
1581 smp_send_commitment(p_cb, NULL); in smp_process_local_nonce()
1587 if (p_cb->role == HCI_ROLE_MASTER) { in smp_process_local_nonce()
1588 smp_send_rand(p_cb, NULL); in smp_process_local_nonce()
1595 p_cb->selected_association_model); in smp_process_local_nonce()
1608 void smp_process_peer_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_process_peer_nonce() argument
1612 if (p_cb->cert_failure == SMP_CONFIRM_VALUE_ERR) { in smp_process_peer_nonce()
1613 SMP_TRACE_ERROR("%s failure case = %d", __func__, p_cb->cert_failure); in smp_process_peer_nonce()
1616 p_cb->failure = SMP_CONFIRM_VALUE_ERR; in smp_process_peer_nonce()
1617 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_peer_nonce()
1621 if ((p_cb->cert_failure == SMP_NUMERIC_COMPAR_FAIL) && in smp_process_peer_nonce()
1622 (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) && in smp_process_peer_nonce()
1623 (p_cb->role == HCI_ROLE_SLAVE)) { in smp_process_peer_nonce()
1624 SMP_TRACE_ERROR("%s failure case = %d", __func__, p_cb->cert_failure); in smp_process_peer_nonce()
1627 p_cb->failure = SMP_NUMERIC_COMPAR_FAIL; in smp_process_peer_nonce()
1628 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_peer_nonce()
1632 switch (p_cb->selected_association_model) { in smp_process_peer_nonce()
1636 if (p_cb->role == HCI_ROLE_MASTER) { in smp_process_peer_nonce()
1637 if (!smp_check_commitment(p_cb)) { in smp_process_peer_nonce()
1640 p_cb->failure = SMP_CONFIRM_VALUE_ERR; in smp_process_peer_nonce()
1641 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_peer_nonce()
1646 smp_send_rand(p_cb, NULL); in smp_process_peer_nonce()
1649 if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) { in smp_process_peer_nonce()
1651 smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); in smp_process_peer_nonce()
1655 smp_sm_event(p_cb, SMP_SC_CALC_NC_EVT, NULL); in smp_process_peer_nonce()
1660 if (!smp_check_commitment(p_cb) && in smp_process_peer_nonce()
1661 p_cb->cert_failure != SMP_NUMERIC_COMPAR_FAIL) { in smp_process_peer_nonce()
1664 p_cb->failure = SMP_CONFIRM_VALUE_ERR; in smp_process_peer_nonce()
1665 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_peer_nonce()
1669 if (p_cb->role == HCI_ROLE_SLAVE) { in smp_process_peer_nonce()
1670 smp_send_rand(p_cb, NULL); in smp_process_peer_nonce()
1673 if (++p_cb->round < 20) { in smp_process_peer_nonce()
1675 p_cb->flags &= ~SMP_PAIR_FLAG_HAVE_PEER_COMM; in smp_process_peer_nonce()
1676 smp_start_nonce_generation(p_cb); in smp_process_peer_nonce()
1680 smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); in smp_process_peer_nonce()
1683 if (p_cb->role == HCI_ROLE_SLAVE) { in smp_process_peer_nonce()
1684 smp_send_rand(p_cb, NULL); in smp_process_peer_nonce()
1687 smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); in smp_process_peer_nonce()
1691 p_cb->selected_association_model); in smp_process_peer_nonce()
1703 void smp_match_dhkey_checks(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_match_dhkey_checks() argument
1706 if (memcmp(p_data->key.p_data, p_cb->remote_dhkey_check.data(), in smp_match_dhkey_checks()
1711 p_cb->failure = SMP_DHKEY_CHK_FAIL; in smp_match_dhkey_checks()
1712 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_match_dhkey_checks()
1720 if (p_cb->peer_enc_size < p_cb->loc_enc_size) in smp_match_dhkey_checks()
1721 p_cb->loc_enc_size = p_cb->peer_enc_size; in smp_match_dhkey_checks()
1723 if (p_cb->role == HCI_ROLE_SLAVE) { in smp_match_dhkey_checks()
1724 smp_sm_event(p_cb, SMP_PAIR_DHKEY_CHCK_EVT, NULL); in smp_match_dhkey_checks()
1727 p_cb->local_i_key = p_cb->peer_i_key; in smp_match_dhkey_checks()
1728 p_cb->local_r_key = p_cb->peer_r_key; in smp_match_dhkey_checks()
1729 smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); in smp_match_dhkey_checks()
1740 void smp_move_to_secure_connections_phase2(tSMP_CB* p_cb, in smp_move_to_secure_connections_phase2() argument
1743 smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); in smp_move_to_secure_connections_phase2()
1755 void smp_phase_2_dhkey_checks_are_present(tSMP_CB* p_cb, in smp_phase_2_dhkey_checks_are_present() argument
1759 if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK) in smp_phase_2_dhkey_checks_are_present()
1760 smp_sm_event(p_cb, SMP_SC_2_DHCK_CHKS_PRES_EVT, NULL); in smp_phase_2_dhkey_checks_are_present()
1771 void smp_wait_for_both_public_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_wait_for_both_public_keys() argument
1774 if ((p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY) && in smp_wait_for_both_public_keys()
1775 (p_cb->flags & SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY)) { in smp_wait_for_both_public_keys()
1776 if ((p_cb->role == HCI_ROLE_SLAVE) && in smp_wait_for_both_public_keys()
1777 ((p_cb->req_oob_type == SMP_OOB_LOCAL) || in smp_wait_for_both_public_keys()
1778 (p_cb->req_oob_type == SMP_OOB_BOTH))) { in smp_wait_for_both_public_keys()
1781 smp_sm_event(p_cb, SMP_BOTH_PUBL_KEYS_RCVD_EVT, NULL); in smp_wait_for_both_public_keys()
1789 void smp_start_passkey_verification(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_start_passkey_verification() argument
1793 p = p_cb->local_random.data(); in smp_start_passkey_verification()
1796 p = p_cb->peer_random.data(); in smp_start_passkey_verification()
1799 p_cb->round = 0; in smp_start_passkey_verification()
1800 smp_start_nonce_generation(p_cb); in smp_start_passkey_verification()
1807 void smp_process_secure_connection_oob_data(tSMP_CB* p_cb, in smp_process_secure_connection_oob_data() argument
1811 tSMP_SC_OOB_DATA* p_sc_oob_data = &p_cb->sc_oob_data; in smp_process_secure_connection_oob_data()
1813 p_cb->local_random = p_sc_oob_data->loc_oob_data.randomizer; in smp_process_secure_connection_oob_data()
1816 p_cb->local_random = {0}; in smp_process_secure_connection_oob_data()
1821 p_cb->peer_random = {0}; in smp_process_secure_connection_oob_data()
1823 p_cb->peer_random = p_sc_oob_data->peer_oob_data.randomizer; in smp_process_secure_connection_oob_data()
1824 p_cb->remote_commitment = p_sc_oob_data->peer_oob_data.commitment; in smp_process_secure_connection_oob_data()
1827 if (!smp_check_commitment(p_cb)) { in smp_process_secure_connection_oob_data()
1830 p_cb->failure = SMP_CONFIRM_VALUE_ERR; in smp_process_secure_connection_oob_data()
1831 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_process_secure_connection_oob_data()
1835 if (p_cb->peer_oob_flag != SMP_OOB_PRESENT) { in smp_process_secure_connection_oob_data()
1840 p_cb->local_random = {0}; in smp_process_secure_connection_oob_data()
1844 print128(p_cb->local_random, (const uint8_t*)"local OOB randomizer"); in smp_process_secure_connection_oob_data()
1845 print128(p_cb->peer_random, (const uint8_t*)"peer OOB randomizer"); in smp_process_secure_connection_oob_data()
1846 smp_start_nonce_generation(p_cb); in smp_process_secure_connection_oob_data()
1855 void smp_set_local_oob_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_set_local_oob_keys() argument
1858 memcpy(p_cb->sc_oob_data.loc_oob_data.private_key_used, p_cb->private_key, in smp_set_local_oob_keys()
1860 p_cb->sc_oob_data.loc_oob_data.publ_key_used = p_cb->loc_publ_key; in smp_set_local_oob_keys()
1861 smp_start_nonce_generation(p_cb); in smp_set_local_oob_keys()
1870 void smp_set_local_oob_random_commitment(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_set_local_oob_random_commitment() argument
1872 p_cb->sc_oob_data.loc_oob_data.randomizer = p_cb->rand; in smp_set_local_oob_random_commitment()
1874 p_cb->sc_oob_data.loc_oob_data.commitment = in smp_set_local_oob_random_commitment()
1875 crypto_toolbox::f4(p_cb->sc_oob_data.loc_oob_data.publ_key_used.x, in smp_set_local_oob_random_commitment()
1876 p_cb->sc_oob_data.loc_oob_data.publ_key_used.x, in smp_set_local_oob_random_commitment()
1877 p_cb->sc_oob_data.loc_oob_data.randomizer, 0); in smp_set_local_oob_random_commitment()
1882 p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.addr_sent_to; in smp_set_local_oob_random_commitment()
1885 p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.private_key_used; in smp_set_local_oob_random_commitment()
1888 p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.publ_key_used.x; in smp_set_local_oob_random_commitment()
1891 p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.publ_key_used.y; in smp_set_local_oob_random_commitment()
1894 p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.randomizer; in smp_set_local_oob_random_commitment()
1896 p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.commitment; in smp_set_local_oob_random_commitment()
1902 p_cb->cb_evt = SMP_SC_LOC_OOB_DATA_UP_EVT; in smp_set_local_oob_random_commitment()
1903 smp_send_app_cback(p_cb, NULL); in smp_set_local_oob_random_commitment()
1905 smp_cb_cleanup(p_cb); in smp_set_local_oob_random_commitment()
1921 tSMP_CB* p_cb = &smp_cb; in smp_link_encrypted() local
1928 if (p_cb->loc_enc_size != 0 && encr_enable) { in smp_link_encrypted()
1930 btm_ble_update_sec_key_size(bda, p_cb->loc_enc_size); in smp_link_encrypted()
1988 tSMP_CB* p_cb = &smp_cb; in smp_process_secure_connection_long_term_key() local
1991 smp_save_secure_connections_long_term_key(p_cb); in smp_process_secure_connection_long_term_key()
1993 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ENC, false); in smp_process_secure_connection_long_term_key()
1994 smp_key_distribution(p_cb, NULL); in smp_process_secure_connection_long_term_key()
2008 void smp_set_derive_link_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_set_derive_link_key() argument
2010 p_cb->derive_lk = true; in smp_set_derive_link_key()
2011 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_LK, false); in smp_set_derive_link_key()
2012 smp_key_distribution(p_cb, NULL); in smp_set_derive_link_key()
2024 void smp_derive_link_key_from_long_term_key(tSMP_CB* p_cb, in smp_derive_link_key_from_long_term_key() argument
2029 if (!smp_calculate_link_key_from_long_term_key(p_cb)) { in smp_derive_link_key_from_long_term_key()
2033 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data); in smp_derive_link_key_from_long_term_key()
2049 void smp_br_process_link_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_br_process_link_key() argument
2053 if (!smp_calculate_long_term_key_from_link_key(p_cb)) { in smp_br_process_link_key()
2057 smp_sm_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data); in smp_br_process_link_key()
2061 tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(p_cb->pairing_bda); in smp_br_process_link_key()
2071 smp_save_secure_connections_long_term_key(p_cb); in smp_br_process_link_key()
2072 smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ENC, false); in smp_br_process_link_key()
2073 smp_br_select_next_key(p_cb, NULL); in smp_br_process_link_key()
2081 void smp_key_distribution_by_transport(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_key_distribution_by_transport() argument
2083 if (p_cb->smp_over_br) { in smp_key_distribution_by_transport()
2084 smp_br_select_next_key(p_cb, NULL); in smp_key_distribution_by_transport()
2086 smp_key_distribution(p_cb, NULL); in smp_key_distribution_by_transport()
2095 void smp_br_pairing_complete(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { in smp_br_pairing_complete() argument
2098 if (p_cb->total_tx_unacked == 0) { in smp_br_pairing_complete()
2100 smp_proc_pairing_cmpl(p_cb); in smp_br_pairing_complete()