OSDN Git Service

Enum-ify stack/l2cap/l2c_int::tL2CEVT
authorChris Manton <cmanton@google.com>
Tue, 16 Mar 2021 02:40:25 +0000 (19:40 -0700)
committerChris Manton <cmanton@google.com>
Wed, 21 Apr 2021 04:11:13 +0000 (04:11 +0000)
Bug: 163134718
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I5b890c27aa183b183800806e012383d66ee27fd0

stack/l2cap/l2c_csm.cc
stack/l2cap/l2c_int.h
stack/l2cap/l2c_link.cc

index e4ff6a2..bea4ce2 100644 (file)
 /******************************************************************************/
 /*            L O C A L    F U N C T I O N     P R O T O T Y P E S            */
 /******************************************************************************/
-static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data);
-static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data);
+static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, tL2CEVT event,
                                      void* p_data);
-static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, tL2CEVT event,
                                      void* p_data);
-static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                                          void* p_data);
-static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                                         void* p_data);
-static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data);
-static void l2c_csm_open(tL2C_CCB* p_ccb, uint16_t event, void* p_data);
-static void l2c_csm_w4_l2cap_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_config(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data);
+static void l2c_csm_open(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data);
+static void l2c_csm_w4_l2cap_disconnect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                                             void* p_data);
-static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                                            void* p_data);
 
-static const char* l2c_csm_get_event_name(uint16_t event);
+static const char* l2c_csm_get_event_name(tL2CEVT event);
 
 // Send a connect response with result OK and adjust the state machine
 static void l2c_csm_send_connect_rsp(tL2C_CCB* p_ccb) {
@@ -132,7 +132,7 @@ static std::string channel_state_text(const tL2C_CHNL_STATE& state) {
  * Returns          void
  *
  ******************************************************************************/
-void l2c_csm_execute(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
+void l2c_csm_execute(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
   if (!l2cu_is_ccb_active(p_ccb)) {
     LOG_WARN("CCB not in use, event (%d) cannot be processed", event);
     return;
@@ -196,7 +196,7 @@ void l2c_csm_execute(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
+static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
   tL2C_CONN_INFO* p_ci = (tL2C_CONN_INFO*)p_data;
   uint16_t local_cid = p_ccb->local_cid;
   tL2CA_DISCONNECT_IND_CB* disconnect_ind;
@@ -347,6 +347,9 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
     case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */
       l2cu_release_ccb(p_ccb);
       break;
+
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -363,7 +366,7 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, tL2CEVT event,
                                      void* p_data) {
   tL2CA_DISCONNECT_IND_CB* disconnect_ind =
       p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb;
@@ -443,6 +446,9 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
 
       l2cu_release_ccb(p_ccb);
       break;
+
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -459,7 +465,7 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, tL2CEVT event,
                                      void* p_data) {
   LOG_DEBUG("LCID: 0x%04x  st: TERM_W4_SEC_COMP  evt: %s", p_ccb->local_cid,
             l2c_csm_get_event_name(event));
@@ -572,6 +578,9 @@ static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
       btm_sec_l2cap_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm,
                                false, &l2c_link_sec_comp, p_ccb);
       break;
+
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -588,7 +597,7 @@ static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                                          void* p_data) {
   tL2C_CONN_INFO* p_ci = (tL2C_CONN_INFO*)p_data;
   tL2CA_DISCONNECT_IND_CB* disconnect_ind =
@@ -729,6 +738,9 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
         l2cu_send_peer_connect_req(p_ccb); /* Start Connection     */
       }
       break;
+
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -745,7 +757,7 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                                         void* p_data) {
   tL2C_CONN_INFO* p_ci;
   tL2CA_DISCONNECT_IND_CB* disconnect_ind =
@@ -878,6 +890,8 @@ static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
       l2c_csm_send_connect_rsp(p_ccb);
       l2c_csm_send_config_req(p_ccb);
       break;
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -894,7 +908,7 @@ static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
+static void l2c_csm_config(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
   tL2CAP_CFG_INFO* p_cfg = (tL2CAP_CFG_INFO*)p_data;
   tL2CA_DISCONNECT_IND_CB* disconnect_ind =
       p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb;
@@ -1149,6 +1163,8 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
       l2cu_release_ccb(p_ccb);
       (*disconnect_ind)(local_cid, false);
       break;
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -1165,7 +1181,7 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_open(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
+static void l2c_csm_open(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
   uint16_t local_cid = p_ccb->local_cid;
   tL2CAP_CFG_INFO* p_cfg;
   tL2C_CHNL_STATE tempstate;
@@ -1325,6 +1341,8 @@ static void l2c_csm_open(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
         l2c_link_check_send_pkts(p_ccb->p_lcb, 0, NULL);
       }
       break;
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -1341,7 +1359,7 @@ static void l2c_csm_open(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_w4_l2cap_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_w4_l2cap_disconnect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                                             void* p_data) {
   LOG_DEBUG("LCID: 0x%04x  st: W4_L2CAP_DISC_RSP  evt: %s", p_ccb->local_cid,
             l2c_csm_get_event_name(event));
@@ -1366,6 +1384,8 @@ static void l2c_csm_w4_l2cap_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event,
     case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */
       osi_free(p_data);
       break;
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -1382,7 +1402,7 @@ static void l2c_csm_w4_l2cap_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event,
  * Returns          void
  *
  ******************************************************************************/
-static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event,
+static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                                            void* p_data) {
   tL2CA_DISCONNECT_IND_CB* disconnect_ind =
       p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb;
@@ -1419,6 +1439,8 @@ static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event,
     case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */
       osi_free(p_data);
       break;
+    default:
+      LOG_ERROR("Handling unexpected event:%s", l2c_csm_get_event_name(event));
   }
   LOG_DEBUG("Exit chnl_state=%s [%d], event=%s [%d]",
             channel_state_text(p_ccb->chnl_state).c_str(), p_ccb->chnl_state,
@@ -1436,7 +1458,7 @@ static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event,
  * Returns          pointer to the name
  *
  ******************************************************************************/
-static const char* l2c_csm_get_event_name(uint16_t event) {
+static const char* l2c_csm_get_event_name(tL2CEVT event) {
   switch (event) {
     case L2CEVT_LP_CONNECT_CFM: /* Lower layer connect confirm          */
       return ("LOWER_LAYER_CONNECT_CFM");
index 8d083e6..eba9925 100644 (file)
@@ -115,7 +115,7 @@ inline std::string link_state_text(const tL2C_LINK_STATE& state) {
  * of the events may seem a bit strange, but they are taken from
  * the Bluetooth specification.
 */
-enum : uint16_t {
+typedef enum : uint16_t {
   /* Lower layer */
   L2CEVT_LP_CONNECT_CFM = 0,     /* connect confirm */
   L2CEVT_LP_CONNECT_CFM_NEG = 1, /* connect confirm (failed) */
@@ -178,7 +178,7 @@ enum : uint16_t {
   L2CEVT_L2CA_CREDIT_BASED_CONNECT_RSP = 43,     /* connect response */
   L2CEVT_L2CA_CREDIT_BASED_CONNECT_RSP_NEG = 44, /* connect response (failed)*/
   L2CEVT_L2CA_CREDIT_BASED_RECONFIG_REQ = 45,    /* reconfig request */
-};
+} tL2CEVT;
 
 /* Constants for LE Dynamic PSM values */
 #define LE_DYNAMIC_PSM_START 0x0080
@@ -751,7 +751,7 @@ extern void l2cu_set_info_rsp_mask(uint32_t mask);
 /* Functions provided by l2c_csm.cc
  ***********************************
 */
-extern void l2c_csm_execute(tL2C_CCB* p_ccb, uint16_t event, void* p_data);
+extern void l2c_csm_execute(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data);
 
 extern void l2c_enqueue_peer_data(tL2C_CCB* p_ccb, BT_HDR* p_buf);
 
index 8f92aea..e38dd1b 100644 (file)
@@ -276,7 +276,6 @@ void l2c_link_sec_comp2(const RawAddress& p_bda,
   tL2C_LCB* p_lcb;
   tL2C_CCB* p_ccb;
   tL2C_CCB* p_next_ccb;
-  uint8_t event;
 
   LOG_DEBUG("btm_status=%s, BD_ADDR=%s, transport=%s",
             btm_status_text(status).c_str(), PRIVATE_ADDRESS(p_bda),
@@ -305,7 +304,7 @@ void l2c_link_sec_comp2(const RawAddress& p_bda,
     if (p_ccb == p_ref_data) {
       switch (status) {
         case BTM_SUCCESS:
-          event = L2CEVT_SEC_COMP;
+          l2c_csm_execute(p_ccb, L2CEVT_SEC_COMP, &ci);
           break;
 
         case BTM_DELAY_CHECK:
@@ -317,9 +316,9 @@ void l2c_link_sec_comp2(const RawAddress& p_bda,
           return;
 
         default:
-          event = L2CEVT_SEC_COMP_NEG;
+          l2c_csm_execute(p_ccb, L2CEVT_SEC_COMP_NEG, &ci);
+          break;
       }
-      l2c_csm_execute(p_ccb, event, &ci);
       break;
     }
   }