OSDN Git Service

Send a response to an smp security request depending on the callback event
authorRahul Sabnis <rahulsabnis@google.com>
Mon, 24 Aug 2020 23:36:36 +0000 (16:36 -0700)
committersyphyr <syphyr@gmail.com>
Fri, 6 Nov 2020 01:07:08 +0000 (02:07 +0100)
Tag: #feature
Bug: 157038281
Test: Manual
Merged-In: Iadeb25a43b46f615b55a0dfb6e7723e5d1204351
Change-Id: Iadeb25a43b46f615b55a0dfb6e7723e5d1204351
(cherry picked from commit 1570e8de12bd994abd8ac18e80734bcbd05430d1)

stack/smp/smp_api.c

index e50c572..efcf316 100644 (file)
@@ -262,44 +262,50 @@ void SMP_SecurityGrant(BD_ADDR bd_addr, UINT8 res)
 {
     SMP_TRACE_EVENT ("SMP_SecurityGrant ");
 
-    // If JUSTWORKS, this is used to display the consent dialog
-    if (smp_cb.selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS)
+    // If just showing consent dialog, send response
+    if (smp_cb.cb_evt == SMP_CONSENT_REQ_EVT)
     {
-        if (res == SMP_SUCCESS)
+        // If JUSTWORKS, this is used to display the consent dialog
+        if (smp_cb.selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS)
         {
-            smp_sm_event(&smp_cb, SMP_SC_NC_OK_EVT, NULL);
+            if (res == SMP_SUCCESS)
+            {
+                smp_sm_event(&smp_cb, SMP_SC_NC_OK_EVT, NULL);
+            }
+            else
+            {
+                SMP_TRACE_WARNING("%s() - Consent dialog fails for JUSTWORKS",
+                                  __func__);
+                /* send pairing failure */
+                uint8_t failure = SMP_NUMERIC_COMPAR_FAIL;
+                smp_sm_event(&smp_cb, SMP_AUTH_CMPL_EVT, &failure);
+            }
         }
-        else
+        else if (smp_cb.selected_association_model == SMP_MODEL_ENCRYPTION_ONLY)
         {
-            SMP_TRACE_WARNING("%s() - Consent dialog fails for JUSTWORKS", __func__);
-            /* send pairing failure */
-            uint8_t failure = SMP_NUMERIC_COMPAR_FAIL;
-            smp_sm_event(&smp_cb, SMP_AUTH_CMPL_EVT, &failure);
-        }
-    }
-    else if (smp_cb.selected_association_model == SMP_MODEL_ENCRYPTION_ONLY)
-    {
-        if (res == SMP_SUCCESS)
-        {
-            smp_cb.sec_level = SMP_SEC_UNAUTHENTICATE;
-
-            tSMP_KEY key;
-            tSMP_INT_DATA smp_int_data;
-            key.key_type = SMP_KEY_TYPE_TK;
-            key.p_data = smp_cb.tk;
-            smp_int_data.key = key;
-
-            memset(smp_cb.tk, 0, BT_OCTET16_LEN);
-            smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &smp_int_data);
-        }
-        else
-        {
-            SMP_TRACE_WARNING("%s() - Consent dialog fails for ENCRYPTION_ONLY",
-                              __func__);
-            /* send pairing failure */
-            uint8_t failure = SMP_NUMERIC_COMPAR_FAIL;
-            smp_sm_event(&smp_cb, SMP_AUTH_CMPL_EVT, &failure);
+            if (res == SMP_SUCCESS)
+            {
+                smp_cb.sec_level = SMP_SEC_UNAUTHENTICATE;
+
+                tSMP_KEY key;
+                tSMP_INT_DATA smp_int_data;
+                key.key_type = SMP_KEY_TYPE_TK;
+                key.p_data = smp_cb.tk;
+                smp_int_data.key = key;
+
+                memset(smp_cb.tk, 0, BT_OCTET16_LEN);
+                smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &smp_int_data);
+            }
+            else
+            {
+                SMP_TRACE_WARNING("%s() - Consent dialog fails for ENCRYPTION_ONLY",
+                                  __func__);
+                /* send pairing failure */
+                uint8_t failure = SMP_NUMERIC_COMPAR_FAIL;
+                smp_sm_event(&smp_cb, SMP_AUTH_CMPL_EVT, &failure);
+            }
         }
+        return;
     }
 
     if (smp_cb.smp_over_br)