OSDN Git Service

Simplify bnep_sec_check_complete
authorHansong Zhang <hsz@google.com>
Sun, 27 Sep 2020 00:42:02 +0000 (17:42 -0700)
committerHansong Zhang <hsz@google.com>
Mon, 28 Sep 2020 06:38:08 +0000 (23:38 -0700)
Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ifc0edea758f4d1e0847f5b00fc49b51b4ad00344

stack/bnep/bnep_api.cc
stack/bnep/bnep_int.h
stack/bnep/bnep_main.cc
stack/bnep/bnep_utils.cc

index 5cb756e..455dc16 100644 (file)
@@ -162,8 +162,7 @@ tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda, const Uuid& src_uuid,
     BNEP_TRACE_API("BNEP initiating security procedures for src uuid %s",
                    p_bcb->src_uuid.ToString().c_str());
 
-    bnep_sec_check_complete(&p_bcb->rem_bda, BT_TRANSPORT_BR_EDR, p_bcb,
-                            BTM_SUCCESS);
+    bnep_sec_check_complete(&p_bcb->rem_bda, BT_TRANSPORT_BR_EDR, p_bcb);
   } else {
     /* Transition to the next appropriate state, waiting for connection confirm.
      */
index bd18f8c..1675e2f 100644 (file)
@@ -204,8 +204,7 @@ extern void bnep_process_setup_conn_responce(tBNEP_CONN* p_bcb,
 extern uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,
                                             uint16_t* len, bool is_ext);
 extern void bnep_sec_check_complete(const RawAddress* bd_addr,
-                                    tBT_TRANSPORT trasnport, void* p_ref_data,
-                                    uint8_t result);
+                                    tBT_TRANSPORT trasnport, void* p_ref_data);
 extern tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb,
                                            const RawAddress& p_dest_addr,
                                            uint16_t protocol,
index 61cdd6d..f8e76f5 100644 (file)
@@ -234,8 +234,7 @@ static void bnep_config_cfm(uint16_t l2cap_cid, uint16_t result) {
                        bnep_conn_timer_timeout, p_bcb);
 
     if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) {
-      bnep_sec_check_complete(&p_bcb->rem_bda, BT_TRANSPORT_BR_EDR, p_bcb,
-                              BTM_SUCCESS);
+      bnep_sec_check_complete(&p_bcb->rem_bda, BT_TRANSPORT_BR_EDR, p_bcb);
     }
   } else {
     LOG(ERROR) << __func__ << ": invoked with non OK status";
index 5481af1..4813ce3 100644 (file)
@@ -607,8 +607,7 @@ void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup,
   BNEP_TRACE_EVENT(
       "BNEP initiating security check for incoming call for uuid %s",
       p_bcb->src_uuid.ToString().c_str());
-  bnep_sec_check_complete(&p_bcb->rem_bda, BT_TRANSPORT_BR_EDR, p_bcb,
-                          BTM_SUCCESS);
+  bnep_sec_check_complete(&p_bcb->rem_bda, BT_TRANSPORT_BR_EDR, p_bcb);
 }
 
 /*******************************************************************************
@@ -1148,14 +1147,12 @@ void bnepu_send_peer_multicast_filter_rsp(tBNEP_CONN* p_bcb,
  * Returns          void
  *
  ******************************************************************************/
-void bnep_sec_check_complete(UNUSED_ATTR const RawAddress* bd_addr,
-                             UNUSED_ATTR tBT_TRANSPORT trasnport,
-                             void* p_ref_data, uint8_t result) {
+void bnep_sec_check_complete(const RawAddress* bd_addr, tBT_TRANSPORT trasnport,
+                             void* p_ref_data) {
   tBNEP_CONN* p_bcb = (tBNEP_CONN*)p_ref_data;
   uint16_t resp_code = BNEP_SETUP_CONN_OK;
   bool is_role_change;
 
-  BNEP_TRACE_EVENT("BNEP security callback returned result %d", result);
   if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)
     is_role_change = true;
   else
@@ -1171,30 +1168,6 @@ void bnep_sec_check_complete(UNUSED_ATTR const RawAddress* bd_addr,
 
   /* if it is outgoing call and result is FAILURE return security fail error */
   if (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD)) {
-    if (result != BTM_SUCCESS) {
-      if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) {
-        /* Tell the user that role change is failed because of security */
-        if (bnep_cb.p_conn_state_cb)
-          (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda,
-                                     BNEP_SECURITY_FAIL, is_role_change);
-
-        p_bcb->con_state = BNEP_STATE_CONNECTED;
-        p_bcb->src_uuid = p_bcb->prv_src_uuid;
-        p_bcb->dst_uuid = p_bcb->prv_dst_uuid;
-        return;
-      }
-
-      L2CA_DisconnectReq(p_bcb->l2cap_cid);
-
-      /* Tell the user if there is a callback */
-      if (bnep_cb.p_conn_state_cb)
-        (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda,
-                                   BNEP_SECURITY_FAIL, is_role_change);
-
-      bnepu_release_bcb(p_bcb);
-      return;
-    }
-
     /* Transition to the next appropriate state, waiting for connection confirm.
      */
     p_bcb->con_state = BNEP_STATE_CONN_SETUP;
@@ -1205,25 +1178,6 @@ void bnep_sec_check_complete(UNUSED_ATTR const RawAddress* bd_addr,
     return;
   }
 
-  /* it is an incoming call respond appropriately */
-  if (result != BTM_SUCCESS) {
-    bnep_send_conn_responce(p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED);
-    if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) {
-      /* Role change is failed because of security. Revert back to connected
-       * state */
-      p_bcb->con_state = BNEP_STATE_CONNECTED;
-      p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD);
-      p_bcb->src_uuid = p_bcb->prv_src_uuid;
-      p_bcb->dst_uuid = p_bcb->prv_dst_uuid;
-      return;
-    }
-
-    L2CA_DisconnectReq(p_bcb->l2cap_cid);
-
-    bnepu_release_bcb(p_bcb);
-    return;
-  }
-
   if (bnep_cb.p_conn_ind_cb) {
     p_bcb->con_state = BNEP_STATE_CONN_SETUP;
     (*bnep_cb.p_conn_ind_cb)(p_bcb->handle, p_bcb->rem_bda, p_bcb->dst_uuid,
@@ -1233,8 +1187,6 @@ void bnep_sec_check_complete(UNUSED_ATTR const RawAddress* bd_addr,
     bnep_send_conn_responce(p_bcb, resp_code);
     bnep_connected(p_bcb);
   }
-
-  return;
 }
 
 /*******************************************************************************