Lines Matching full:p_cb
76 static bool smp_parameter_unconditionally_valid(tSMP_CB* p_cb);
77 static bool smp_parameter_unconditionally_invalid(tSMP_CB* p_cb);
80 typedef bool (*tSMP_CMD_LEN_VALID)(tSMP_CB* p_cb);
82 static bool smp_command_has_valid_fixed_length(tSMP_CB* p_cb);
104 typedef bool (*tSMP_CMD_PARAM_RANGES_VALID)(tSMP_CB* p_cb);
106 static bool smp_pairing_request_response_parameters_are_valid(tSMP_CB* p_cb);
107 static bool smp_pairing_keypress_notification_is_valid(tSMP_CB* p_cb);
133 typedef BT_HDR* (*tSMP_CMD_ACT)(uint8_t cmd_code, tSMP_CB* p_cb);
135 static BT_HDR* smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB* p_cb);
137 tSMP_CB* p_cb);
138 static BT_HDR* smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb);
140 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 UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb);
293 static tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB* p_cb);
295 tSMP_CB* p_cb);
332 bool smp_send_cmd(uint8_t cmd_code, tSMP_CB* p_cb) {
339 p_buf = (*smp_cmd_build_act[cmd_code])(cmd_code, p_cb);
341 if (p_buf != NULL && smp_send_msg_to_L2CAP(p_cb->pairing_bda, p_buf)) {
343 alarm_set_on_mloop(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS,
349 if (p_cb->smp_over_br) {
350 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure);
352 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure);
368 tSMP_CB* p_cb = &smp_cb;
371 SMP_TRACE_EVENT("%s state:%d br_state:%d", __func__, p_cb->state,
372 p_cb->br_state);
374 if (p_cb->smp_over_br) {
375 smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure);
377 smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure);
410 BT_HDR* smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB* p_cb) {
419 UINT8_TO_STREAM(p, p_cb->local_io_capability);
420 UINT8_TO_STREAM(p, p_cb->loc_oob_flag);
421 UINT8_TO_STREAM(p, p_cb->loc_auth_req);
422 UINT8_TO_STREAM(p, p_cb->loc_enc_size);
423 UINT8_TO_STREAM(p, p_cb->local_i_key);
424 UINT8_TO_STREAM(p, p_cb->local_r_key);
441 tSMP_CB* p_cb) {
451 ARRAY_TO_STREAM(p, p_cb->confirm, BT_OCTET16_LEN);
466 static BT_HDR* smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb) {
475 ARRAY_TO_STREAM(p, p_cb->rand, BT_OCTET16_LEN);
491 tSMP_CB* p_cb) {
500 ARRAY_TO_STREAM(p, p_cb->ltk, BT_OCTET16_LEN);
516 tSMP_CB* p_cb) {
525 UINT16_TO_STREAM(p, p_cb->ediv);
526 ARRAY_TO_STREAM(p, p_cb->enc_rand, BT_OCTET8_LEN);
542 UNUSED_ATTR tSMP_CB* p_cb) {
571 UNUSED_ATTR tSMP_CB* p_cb) {
597 tSMP_CB* p_cb) {
606 ARRAY_TO_STREAM(p, p_cb->csrk, BT_OCTET16_LEN);
622 tSMP_CB* p_cb) {
631 UINT8_TO_STREAM(p, p_cb->failure);
647 tSMP_CB* p_cb) {
655 UINT8_TO_STREAM(p, p_cb->loc_auth_req);
661 p_cb->loc_auth_req);
674 tSMP_CB* p_cb) {
683 memcpy(p_publ_key, p_cb->loc_publ_key.x, BT_OCTET32_LEN);
684 memcpy(p_publ_key + BT_OCTET32_LEN, p_cb->loc_publ_key.y, BT_OCTET32_LEN);
704 tSMP_CB* p_cb) {
713 ARRAY_TO_STREAM(p, p_cb->commitment, BT_OCTET16_LEN);
729 tSMP_CB* p_cb) {
738 ARRAY_TO_STREAM(p, p_cb->dhkey_check, BT_OCTET16_LEN);
754 UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb) {
763 UINT8_TO_STREAM(p, p_cb->local_keypress_notification);
842 void smp_cb_cleanup(tSMP_CB* p_cb) {
843 tSMP_CALLBACK* p_callback = p_cb->p_callback;
844 uint8_t trace_level = p_cb->trace_level;
845 alarm_t* smp_rsp_timer_ent = p_cb->smp_rsp_timer_ent;
846 alarm_t* delayed_auth_timer_ent = p_cb->delayed_auth_timer_ent;
850 alarm_cancel(p_cb->smp_rsp_timer_ent);
851 alarm_cancel(p_cb->delayed_auth_timer_ent);
852 memset(p_cb, 0, sizeof(tSMP_CB));
853 p_cb->p_callback = p_callback;
854 p_cb->trace_level = trace_level;
855 p_cb->smp_rsp_timer_ent = smp_rsp_timer_ent;
856 p_cb->delayed_auth_timer_ent = delayed_auth_timer_ent;
868 void smp_remove_fixed_channel(tSMP_CB* p_cb) {
871 if (p_cb->smp_over_br)
872 L2CA_RemoveFixedChnl(L2CAP_SMP_BR_CID, p_cb->pairing_bda);
874 L2CA_RemoveFixedChnl(L2CAP_SMP_CID, p_cb
888 void smp_reset_control_value(tSMP_CB* p_cb) {
891 alarm_cancel(p_cb->smp_rsp_timer_ent);
892 p_cb->flags = 0;
897 L2CA_SetIdleTimeoutByBdAddr(p_cb->pairing_bda, SMP_LINK_TOUT_MIN,
901 smp_remove_fixed_channel(p_cb);
902 smp_cb_cleanup(p_cb);
915 void smp_proc_pairing_cmpl(tSMP_CB* p_cb) {
917 tSMP_CALLBACK* p_callback = p_cb->p_callback;
921 evt_data.cmplt.reason = p_cb->status;
922 evt_data.cmplt.smp_over_br = p_cb->smp_over_br;
924 if (p_cb->status == SMP_SUCCESS) evt_data.cmplt.sec_level = p_cb->sec_level;
928 if (p_cb->is_pair_cancel) evt_data.cmplt.is_pair_cancel = true;
933 RawAddress pairing_bda = p_cb->pairing_bda;
935 smp_reset_control_value(p_cb);
952 bool smp_command_has_invalid_parameters(tSMP_CB* p_cb) {
953 uint8_t cmd_code = p_cb->rcvd_cmd_code;
962 if (!(*smp_cmd_len_is_valid[cmd_code])(p_cb)) {
968 if (!(*smp_cmd_param_ranges_are_valid[cmd_code])(p_cb)) {
988 bool smp_command_has_valid_fixed_length(tSMP_CB* p_cb) {
989 uint8_t cmd_code = p_cb->rcvd_cmd_code;
993 if (p_cb->rcvd_cmd_len != smp_cmd_size_per_spec[cmd_code]) {
997 cmd_code, p_cb->rcvd_cmd_len, smp_cmd_size_per_spec[cmd_code]);
1019 bool smp_pairing_request_response_parameters_are_valid(tSMP_CB* p_cb) {
1020 uint8_t io_caps = p_cb->peer_io_caps;
1021 uint8_t oob_flag = p_cb->peer_oob_flag;
1023 p_cb->peer_auth_req & 0x03; // 0x03 is gen bond with appropriate mask
1024 uint8_t enc_size = p_cb->peer_enc_size;
1026 SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, p_cb->rcvd_cmd_code);
1032 p_cb->rcvd_cmd_code, io_caps);
1040 p_cb->rcvd_cmd_code, oob_flag);
1048 p_cb->rcvd_cmd_code, bond_flag);
1057 p_cb->rcvd_cmd_code, enc_size);
1073 bool smp_pairing_keypress_notification_is_valid(tSMP_CB* p_cb) {
1074 tBTM_SP_KEY_TYPE keypress_notification = p_cb->peer_keypress_notification;
1076 SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, p_cb->rcvd_cmd_code);
1082 p_cb->rcvd_cmd_code, keypress_notification);
1096 bool smp_parameter_unconditionally_valid(UNUSED_ATTR tSMP_CB* p_cb) {
1107 bool smp_parameter_unconditionally_invalid(UNUSED_ATTR tSMP_CB* p_cb) {
1148 * if p_cb->secure_connections_only_mode_required = true
1150 * (p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) ==
1151 * (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT) ==
1155 tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB* p_cb) {
1157 p_cb->le_secure_connections_mode_is_used = false;
1160 SMP_TRACE_DEBUG("%s p_cb->peer_io_caps = %d p_cb->local_io_capability = %d",
1161 __func__, p_cb->peer_io_caps, p_cb->local_io_capability);
1162 SMP_TRACE_DEBUG("%s p_cb->peer_oob_flag = %d p_cb->loc_oob_flag = %d",
1163 __func__, p_cb->peer_oob_flag, p_cb->loc_oob_flag);
1164 SMP_TRACE_DEBUG("%s p_cb->peer_auth_req = 0x%02x p_cb->loc_auth_req = 0x%02x",
1165 __func__, p_cb->peer_auth_req, p_cb->loc_auth_req);
1167 "%s p_cb->secure_connections_only_mode_required = %s", __func__,
1168 p_cb->secure_connections_only_mode_required ? "true" : "false");
1170 if ((p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) &&
1171 (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)) {
1172 p_cb->le_secure_connections_mode_is_used = true;
1175 if ((p_cb->peer_auth_req & SMP_H7_SUPPORT_BIT) &&
1176 (p_cb->loc_auth_req & SMP_H7_SUPPORT_BIT)) {
1177 p_cb->key_derivation_h7_used = TRUE;
1181 p_cb->le_secure_connections_mode_is_used,
1182 p_cb->key_derivation_h7_used);
1184 if (p_cb->le_secure_connections_mode_is_used) {
1185 model = smp_select_association_model_secure_connections(p_cb);
1187 model = smp_select_legacy_association_model(p_cb);
1199 tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB* p_cb) {
1204 if (p_cb->peer_oob_flag == SMP_OOB_PRESENT &&
1205 p_cb->loc_oob_flag == SMP_OOB_PRESENT)
1210 if (SMP_NO_MITM_REQUIRED(p_cb->peer_auth_req) &&
1211 SMP_NO_MITM_REQUIRED(p_cb->loc_auth_req))
1215 if (p_cb->peer_io_caps < SMP_IO_CAP_MAX &&
1216 p_cb->local_io_capability < SMP_IO_CAP_MAX) {
1217 if (p_cb->role == HCI_ROLE_MASTER) {
1218 model = smp_association_table[p_cb->role][p_cb->peer_io_caps]
1219 [p_cb->local_io_capability];
1221 model = smp_association_table[p_cb->role][p_cb->local_io_capability]
1222 [p_cb->peer_io_caps];
1236 tSMP_ASSO_MODEL smp_select_association_model_secure_connections(tSMP_CB* p_cb) {
1242 if (p_cb->peer_oob_flag == SMP_OOB_PRESENT ||
1243 p_cb->loc_oob_flag == SMP_OOB_PRESENT)
1248 if (SMP_NO_MITM_REQUIRED(p_cb->peer_auth_req) &&
1249 SMP_NO_MITM_REQUIRED(p_cb->loc_auth_req))
1253 if (p_cb->peer_io_caps < SMP_IO_CAP_MAX &&
1254 p_cb->local_io_capability < SMP_IO_CAP_MAX) {
1255 if (p_cb->role == HCI_ROLE_MASTER) {
1256 model = smp_association_table_sc[p_cb->role][p_cb->peer_io_caps]
1257 [p_cb->local_io_capability];
1259 model = smp_association_table_sc[p_cb->role][p_cb->local_io_capability]
1260 [p_cb->peer_io_caps];
1317 void smp_collect_local_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb) {
1320 iocap[0] = p_cb
1321 iocap[1] = p_cb->loc_oob_flag;
1322 iocap[2] = p_cb->loc_auth_req;
1334 void smp_collect_peer_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb) {
1337 iocap[0] = p_cb->peer_io_caps;
1338 iocap[1] = p_cb->peer_oob_flag;
1339 iocap[2] = p_cb->peer_auth_req;
1352 void smp_collect_local_ble_address(uint8_t* le_addr, tSMP_CB* p_cb) {
1359 BTM_ReadConnectionAddr(p_cb->pairing_bda, bda, &addr_type);
1374 void smp_collect_peer_ble_address(uint8_t* le_addr, tSMP_CB* p_cb) {
1381 if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, bda, &addr_type)) {
1402 bool smp_check_commitment(tSMP_CB* p_cb) {
1407 smp_calculate_peer_commitment(p_cb, expected);
1409 print128(p_cb->remote_commitment, (const uint8_t*)"received peer commitment");
1411 if (memcmp(p_cb->remote_commitment, expected, BT_OCTET16_LEN)) {
1430 void smp_save_secure_connections_long_term_key(tSMP_CB* p_cb) {
1435 memcpy(lle_key.ltk, p_cb->ltk, BT_OCTET16_LEN);
1437 lle_key.key_size = p_cb->loc_enc_size;
1438 lle_key.sec_level = p_cb->sec_level;
1439 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC,
1445 memcpy(ple_key.ltk, p_cb->ltk, BT_OCTET16_LEN);
1446 ple_key.sec_level = p_cb->sec_level;
1447 ple_key.key_size = p_cb->loc_enc_size;
1448 btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC,
1464 bool smp_calculate_f5_mackey_and_long_term_key(tSMP_CB* p_cb) {
1472 if (p_cb->role == HCI_ROLE_MASTER) {
1473 smp_collect_local_ble_address(a, p_cb);
1474 smp_collect_peer_ble_address(b, p_cb);
1475 p_na = p_cb->rand;
1476 p_nb = p_cb->rrand;
1478 smp_collect_local_ble_address(b, p_cb);
1479 smp_collect_peer_ble_address(a, p_cb);
1480 p_na = p_cb->rrand;
1481 p_nb = p_cb->rand;
1484 if (!smp_calculate_f5(p_cb->dhkey, p_na, p_nb, a, b, p_cb->mac_key,
1485 p_cb->ltk)) {
1504 bool smp_request_oob_data(tSMP_CB* p_cb) {
1509 if (p_cb->peer_oob_flag == SMP_OOB_PRESENT &&
1510 p_cb->loc_oob_flag == SMP_OOB_PRESENT) {
1513 } else if (p_cb->peer_oob_flag == SMP_OOB_PRESENT) {
1516 } else if (p_cb->loc_oob_flag == SMP_OOB_PRESENT) {
1524 p_cb->req_oob_type = req_oob_type;
1525 p_cb->cb_evt = SMP_SC_OOB_REQ_EVT;
1526 smp_sm_event(p_cb, SMP_TK_REQ_EVT, &req_oob_type);