acassis commented on code in PR #16364:
URL: https://github.com/apache/nuttx/pull/16364#discussion_r2086397247


##########
wireless/bluetooth/bt_smp.c:
##########
@@ -71,6 +71,15 @@
 
 /* SMP channel specific context */
 
+enum pairing_method {
+    PAIRING_METHOD_JUST_WORKS,
+    PAIRING_METHOD_PASSKEY_DISPLAY, // Local displays, remote inputs
+    PAIRING_METHOD_PASSKEY_INPUT,   // Local inputs, remote displays

Review Comment:
   Please fix code style issues, there are many C++ "//" comments and even "{" 
starting at end of the line



##########
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:
     @robertc2000 "{" should be in a new line, without line of code. Seems like 
nxstyle failed to catch it. 



-- 
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

Reply via email to