xiaoxiang781216 commented on code in PR #16364: URL: https://github.com/apache/nuttx/pull/16364#discussion_r2086920818
########## wireless/bluetooth/bt_smp.c: ########## @@ -600,6 +710,45 @@ static uint8_t smp_pairing_req(FAR struct bt_conn_s *conn, return ret; } + // Perform pairing method selection before sending response + smp->selected_method = smp_get_pairing_method(local_io_cap, req->io_capability, + local_auth_req, req->auth_req); Review Comment: align ########## wireless/bluetooth/bt_smp.h: ########## @@ -172,5 +189,6 @@ bool bt_smp_irk_matches(FAR const uint8_t irk[16], int bt_smp_send_pairing_req(FAR struct bt_conn_s *conn); int bt_smp_send_security_req(FAR struct bt_conn_s *conn); int bt_smp_initialize(void); +void bt_smp_auth_cb_register(const struct bt_smp_auth_cb_s *cb); Review Comment: add FAR ########## wireless/bluetooth/bt_smp.c: ########## @@ -687,20 +828,53 @@ static uint8_t smp_pairing_rsp(FAR struct bt_conn_s *conn, { struct bt_smp_pairing_s *rsp = (FAR void *)buf->data; struct bt_smp_s *smp = conn->smp; + uint8_t local_io_cap = CONFIG_BLUETOOTH_SMP_IO_CAPABILITY; + uint8_t local_auth_req = smp->preq[3]; - wlinfo("\n"); + wlinfo("Pairing Response Received\n"); if ((rsp->max_key_size > BT_SMP_MAX_ENC_KEY_SIZE) || (rsp->max_key_size < BT_SMP_MIN_ENC_KEY_SIZE)) { return BT_SMP_ERR_ENC_KEY_SIZE; } - smp->local_dist &= rsp->init_key_dist; - smp->remote_dist &= rsp->resp_key_dist; + smp->selected_method = smp_get_pairing_method(local_io_cap, rsp->io_capability, + local_auth_req, rsp->auth_req); - /* Store rsp for later use */ + wlinfo("Selected pairing method: %d\n", smp->selected_method); + if (conn->sec_level >= BT_SECURITY_HIGH && !method_provides_mitm(smp->selected_method)) + { + wlerr("ERROR: Cannot achieve HIGH security (MITM) with selected method %d\n", smp->selected_method); + return BT_SMP_ERR_AUTH_REQUIREMENTS; + } + if (smp->selected_method == PAIRING_METHOD_NOT_SUPPORTED) + { + wlerr("ERROR: Pairing method for IO Caps %d/%d not supported\n", local_io_cap, rsp->io_capability); + return BT_SMP_ERR_PAIRING_NOTSUPP; + } + + if (smp->selected_method == PAIRING_METHOD_PASSKEY_DISPLAY) { + uint32_t passkey; + le_rand(&passkey, sizeof(passkey)); + passkey %= 1000000; // 6 digit passkey + smp->passkey = passkey; + wlinfo("Using Passkey Display method. Generated Passkey: %06u\n", (unsigned int) passkey); + smp_passkey_to_tk(passkey, smp->tk); + if (g_smp_auth_cb && g_smp_auth_cb->passkey_display) { + g_smp_auth_cb->passkey_display(conn, passkey); + } + } else if (smp->selected_method == PAIRING_METHOD_JUST_WORKS) { + wlwarn("Using Just Works method.\n"); + memset(smp->tk, 0, sizeof(smp->tk)); + } else { + wlerr("ERROR: Invalid selected method %d\n", smp->selected_method); + return BT_SMP_ERR_UNSPECIFIED; + } + + smp->local_dist &= rsp->init_key_dist; + smp->remote_dist &= rsp->resp_key_dist; Review Comment: please run `tools/checkpatch.sh -g HEAD~...HEAD` and fix all warning before updating the patch ########## wireless/bluetooth/bt_smp.c: ########## @@ -576,17 +631,72 @@ static int smp_init(struct bt_smp_s *smp) return 0; } +static enum pairing_method smp_get_pairing_method(uint8_t local_io, uint8_t remote_io, + uint8_t local_auth, uint8_t remote_auth) Review Comment: align -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org