OSDN Git Service

Remove #def code conditional BTM_MAX_SCO_LINKS
authorChris Manton <cmanton@google.com>
Fri, 18 Sep 2020 23:59:05 +0000 (16:59 -0700)
committerChris Manton <cmanton@google.com>
Wed, 23 Sep 2020 20:54:12 +0000 (13:54 -0700)
Ok for constants, poor for code conditionals

Towards readable code

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working
Test: acts -tc BleCocTest
Change-Id: Iae348262a3dc8449efaa7caaf45560918aaff8b7

stack/btm/btm_sco.cc

index 95c6876..a3d6989 100644 (file)
@@ -129,9 +129,10 @@ void btm_sco_init(void) {
 static void btm_esco_conn_rsp(uint16_t sco_inx, uint8_t hci_status,
                               const RawAddress& bda,
                               enh_esco_params_t* p_parms) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p_sco = NULL;
 
+  if (BTM_MAX_SCO_LINKS == 0) return;
+
   if (sco_inx < BTM_MAX_SCO_LINKS) p_sco = &btm_cb.sco_cb.sco_db[sco_inx];
 
   /* Reject the connect request if refused by caller or wrong state */
@@ -207,7 +208,6 @@ static void btm_esco_conn_rsp(uint16_t sco_inx, uint8_t hci_status,
           p_setup->retransmission_effort, p_setup->packet_types);
     }
   }
-#endif
 }
 
 /*******************************************************************************
@@ -249,7 +249,6 @@ tBTM_STATUS BTM_WriteScoData(UNUSED_ATTR uint16_t sco_inx,
   return (BTM_NO_RESOURCES);
 }
 
-#if (BTM_MAX_SCO_LINKS > 0)
 /*******************************************************************************
  *
  * Function         btm_send_connect_request
@@ -358,7 +357,6 @@ static tBTM_STATUS btm_send_connect_request(uint16_t acl_handle,
 
   return (BTM_CMD_STARTED);
 }
-#endif
 
 /*******************************************************************************
  *
@@ -386,9 +384,13 @@ void btm_set_sco_ind_cback(tBTM_SCO_IND_CBACK* sco_ind_cb) {
  ******************************************************************************/
 void btm_accept_sco_link(uint16_t sco_inx, enh_esco_params_t* p_setup,
                          tBTM_SCO_CB* p_conn_cb, tBTM_SCO_CB* p_disc_cb) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p_sco;
 
+  if (BTM_MAX_SCO_LINKS == 0) {
+    btm_reject_sco_link(sco_inx);
+    return;
+  }
+
   if (sco_inx >= BTM_MAX_SCO_LINKS) {
     BTM_TRACE_ERROR("btm_accept_sco_link: Invalid sco_inx(%d)", sco_inx);
     return;
@@ -404,9 +406,6 @@ void btm_accept_sco_link(uint16_t sco_inx, enh_esco_params_t* p_setup,
   BTM_TRACE_DEBUG("TCS accept SCO: Packet Types 0x%04x", p_setup->packet_types);
 
   btm_esco_conn_rsp(sco_inx, HCI_SUCCESS, p_sco->esco.data.bd_addr, p_setup);
-#else
-  btm_reject_sco_link(sco_inx);
-#endif
 }
 
 /*******************************************************************************
@@ -447,13 +446,16 @@ void btm_reject_sco_link(uint16_t sco_inx) {
 tBTM_STATUS BTM_CreateSco(const RawAddress* remote_bda, bool is_orig,
                           uint16_t pkt_types, uint16_t* p_sco_inx,
                           tBTM_SCO_CB* p_conn_cb, tBTM_SCO_CB* p_disc_cb) {
-#if (BTM_MAX_SCO_LINKS > 0)
   enh_esco_params_t* p_setup;
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
   uint16_t xx;
   uint16_t acl_handle = 0;
   *p_sco_inx = BTM_INVALID_SCO_INDEX;
 
+  if (BTM_MAX_SCO_LINKS == 0) {
+    return BTM_NO_RESOURCES;
+  }
+
   /* If originating, ensure that there is an ACL connection to the BD Address */
 
   if (is_orig) {
@@ -579,7 +581,6 @@ tBTM_STATUS BTM_CreateSco(const RawAddress* remote_bda, bool is_orig,
     }
   }
 
-#endif
   /* If here, all SCO blocks in use */
   LOG(ERROR) << __func__ << ": all SCO control blocks are in use";
   return BTM_NO_RESOURCES;
@@ -597,7 +598,6 @@ tBTM_STATUS BTM_CreateSco(const RawAddress* remote_bda, bool is_orig,
  *
  ******************************************************************************/
 void btm_sco_chk_pend_unpark(uint8_t hci_status, uint16_t hci_handle) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
   for (uint16_t xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) {
     uint16_t acl_handle =
@@ -616,7 +616,6 @@ void btm_sco_chk_pend_unpark(uint8_t hci_status, uint16_t hci_handle) {
       }
     }
   }
-#endif  // BTM_MAX_SCO_LINKS
 }
 
 /*******************************************************************************
@@ -631,7 +630,6 @@ void btm_sco_chk_pend_unpark(uint8_t hci_status, uint16_t hci_handle) {
  *
  ******************************************************************************/
 void btm_sco_chk_pend_rolechange(uint16_t hci_handle) {
-#if (BTM_MAX_SCO_LINKS > 0)
   uint16_t xx;
   uint16_t acl_handle;
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
@@ -651,7 +649,6 @@ void btm_sco_chk_pend_rolechange(uint16_t hci_handle) {
         p->state = SCO_ST_CONNECTING;
     }
   }
-#endif
 }
 
 /*******************************************************************************
@@ -666,7 +663,6 @@ void btm_sco_chk_pend_rolechange(uint16_t hci_handle) {
  *
  ******************************************************************************/
 void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
 
   BTM_TRACE_DEBUG("%s: hci_handle 0x%04x, p->state 0x%02x", __func__,
@@ -682,7 +678,6 @@ void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle) {
       BTM_RemoveSco(xx);
     }
   }
-#endif
 }
 
 /*******************************************************************************
@@ -697,7 +692,6 @@ void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle) {
  ******************************************************************************/
 void btm_sco_conn_req(const RawAddress& bda, DEV_CLASS dev_class,
                       uint8_t link_type) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CB* p_sco = &btm_cb.sco_cb;
   tSCO_CONN* p = &p_sco->sco_db[0];
   tBTM_ESCO_CONN_REQ_EVT_DATA evt_data = {};
@@ -773,7 +767,6 @@ void btm_sco_conn_req(const RawAddress& bda, DEV_CLASS dev_class,
     }
   }
 
-#endif
   /* If here, no one wants the SCO connection. Reject it */
   BTM_TRACE_WARNING("%s: rejecting SCO for %s", __func__,
                     bda.ToString().c_str());
@@ -793,16 +786,13 @@ void btm_sco_conn_req(const RawAddress& bda, DEV_CLASS dev_class,
  ******************************************************************************/
 void btm_sco_connected(uint8_t hci_status, const RawAddress* bda,
                        uint16_t hci_handle, tBTM_ESCO_DATA* p_esco_data) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
   uint16_t xx;
   bool spt = false;
   tBTM_CHG_ESCO_PARAMS parms = {};
-#endif
 
   btm_cb.sco_cb.sco_disc_reason = hci_status;
 
-#if (BTM_MAX_SCO_LINKS > 0)
   for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) {
     if (((p->state == SCO_ST_CONNECTING) || (p->state == SCO_ST_LISTENING) ||
          (p->state == SCO_ST_W4_CONN_RSP)) &&
@@ -858,7 +848,6 @@ void btm_sco_connected(uint8_t hci_status, const RawAddress* bda,
       return;
     }
   }
-#endif
 }
 
 /*******************************************************************************
@@ -871,13 +860,16 @@ void btm_sco_connected(uint8_t hci_status, const RawAddress* bda,
  *
  ******************************************************************************/
 tBTM_STATUS BTM_RemoveSco(uint16_t sco_inx) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[sco_inx];
   uint16_t tempstate;
   tBTM_PM_STATE state = BTM_PM_ST_INVALID;
 
   BTM_TRACE_DEBUG("%s", __func__);
 
+  if (BTM_MAX_SCO_LINKS == 0) {
+    return BTM_NO_RESOURCES;
+  }
+
   /* Validity check */
   if ((sco_inx >= BTM_MAX_SCO_LINKS) || (p->state == SCO_ST_UNUSED))
     return (BTM_UNKNOWN_ADDR);
@@ -905,13 +897,9 @@ tBTM_STATUS BTM_RemoveSco(uint16_t sco_inx) {
   btsnd_hcic_disconnect(p->hci_handle, HCI_ERR_PEER_USER);
 
   return (BTM_CMD_STARTED);
-#else
-  return (BTM_NO_RESOURCES);
-#endif
 }
 
 void BTM_RemoveSco(const RawAddress& bda) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
   uint16_t xx;
 
@@ -920,7 +908,6 @@ void BTM_RemoveSco(const RawAddress& bda) {
       BTM_RemoveSco(xx);
     }
   }
-#endif
 }
 
 /*******************************************************************************
@@ -934,7 +921,6 @@ void BTM_RemoveSco(const RawAddress& bda) {
  *
  ******************************************************************************/
 bool btm_sco_removed(uint16_t hci_handle, uint8_t reason) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
   uint16_t xx;
 
@@ -954,7 +940,6 @@ bool btm_sco_removed(uint16_t hci_handle, uint8_t reason) {
       return true;
     }
   }
-#endif
   return false;
 }
 
@@ -972,7 +957,6 @@ bool btm_sco_removed(uint16_t hci_handle, uint8_t reason) {
  *
  ******************************************************************************/
 void btm_sco_acl_removed(const RawAddress* bda) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
   uint16_t xx;
 
@@ -987,7 +971,6 @@ void btm_sco_acl_removed(const RawAddress* bda) {
       }
     }
   }
-#endif
 }
 
 /*******************************************************************************
@@ -1001,7 +984,6 @@ void btm_sco_acl_removed(const RawAddress* bda) {
  *
  ******************************************************************************/
 const RawAddress* BTM_ReadScoBdAddr(uint16_t sco_inx) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[sco_inx];
 
   /* Validity check */
@@ -1009,9 +991,6 @@ const RawAddress* BTM_ReadScoBdAddr(uint16_t sco_inx) {
     return &(p->esco.data.bd_addr);
   else
     return (NULL);
-#else
-  return (NULL);
-#endif
 }
 
 /*******************************************************************************
@@ -1071,7 +1050,10 @@ tBTM_STATUS BTM_SetEScoMode(enh_esco_params_t* p_parms) {
  ******************************************************************************/
 tBTM_STATUS BTM_RegForEScoEvts(uint16_t sco_inx,
                                tBTM_ESCO_CBACK* p_esco_cback) {
-#if (BTM_MAX_SCO_LINKS > 0)
+  if (BTM_MAX_SCO_LINKS == 0) {
+    return BTM_MODE_UNSUPPORTED;
+  }
+
   if (!btm_cb.sco_cb.esco_supported) {
     btm_cb.sco_cb.sco_db[sco_inx].esco.p_esco_cback = NULL;
     return (BTM_MODE_UNSUPPORTED);
@@ -1083,9 +1065,6 @@ tBTM_STATUS BTM_RegForEScoEvts(uint16_t sco_inx,
     return (BTM_SUCCESS);
   }
   return (BTM_ILLEGAL_VALUE);
-#else
-  return (BTM_MODE_UNSUPPORTED);
-#endif
 }
 
 /*******************************************************************************
@@ -1110,7 +1089,9 @@ tBTM_STATUS BTM_RegForEScoEvts(uint16_t sco_inx,
  ******************************************************************************/
 tBTM_STATUS BTM_ChangeEScoLinkParms(uint16_t sco_inx,
                                     tBTM_CHG_ESCO_PARAMS* p_parms) {
-#if (BTM_MAX_SCO_LINKS > 0)
+  if (BTM_MAX_SCO_LINKS == 0) {
+    return BTM_WRONG_MODE;
+  }
 
   /* Make sure sco handle is valid and on an active link */
   if (sco_inx >= BTM_MAX_SCO_LINKS ||
@@ -1187,9 +1168,6 @@ tBTM_STATUS BTM_ChangeEScoLinkParms(uint16_t sco_inx,
   }
 
   return (BTM_CMD_STARTED);
-#else
-  return (BTM_WRONG_MODE);
-#endif
 }
 
 /*******************************************************************************
@@ -1212,13 +1190,11 @@ tBTM_STATUS BTM_ChangeEScoLinkParms(uint16_t sco_inx,
  ******************************************************************************/
 void BTM_EScoConnRsp(uint16_t sco_inx, uint8_t hci_status,
                      enh_esco_params_t* p_parms) {
-#if (BTM_MAX_SCO_LINKS > 0)
   if (sco_inx < BTM_MAX_SCO_LINKS &&
       btm_cb.sco_cb.sco_db[sco_inx].state == SCO_ST_W4_CONN_RSP) {
     btm_esco_conn_rsp(sco_inx, hci_status,
                       btm_cb.sco_cb.sco_db[sco_inx].esco.data.bd_addr, p_parms);
   }
-#endif
 }
 
 /*******************************************************************************
@@ -1234,7 +1210,6 @@ void BTM_EScoConnRsp(uint16_t sco_inx, uint8_t hci_status,
 void btm_esco_proc_conn_chg(uint8_t status, uint16_t handle,
                             uint8_t tx_interval, uint8_t retrans_window,
                             uint16_t rx_pkt_len, uint16_t tx_pkt_len) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
   tBTM_CHG_ESCO_EVT_DATA data;
   uint16_t xx;
@@ -1261,7 +1236,6 @@ void btm_esco_proc_conn_chg(uint8_t status, uint16_t handle,
       return;
     }
   }
-#endif
 }
 
 /*******************************************************************************
@@ -1275,14 +1249,12 @@ void btm_esco_proc_conn_chg(uint8_t status, uint16_t handle,
  *
  ******************************************************************************/
 bool btm_is_sco_active(uint16_t handle) {
-#if (BTM_MAX_SCO_LINKS > 0)
   uint16_t xx;
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
 
   for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) {
     if (handle == p->hci_handle && p->state == SCO_ST_CONNECTED) return (true);
   }
-#endif
   return (false);
 }
 
@@ -1296,7 +1268,6 @@ bool btm_is_sco_active(uint16_t handle) {
  *
  ******************************************************************************/
 uint8_t BTM_GetNumScoLinks(void) {
-#if (BTM_MAX_SCO_LINKS > 0)
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
   uint16_t xx;
   uint8_t num_scos = 0;
@@ -1312,9 +1283,6 @@ uint8_t BTM_GetNumScoLinks(void) {
     }
   }
   return (num_scos);
-#else
-  return (0);
-#endif
 }
 
 /*******************************************************************************
@@ -1328,7 +1296,6 @@ uint8_t BTM_GetNumScoLinks(void) {
  *
  ******************************************************************************/
 bool BTM_IsScoActiveByBdaddr(const RawAddress& remote_bda) {
-#if (BTM_MAX_SCO_LINKS > 0)
   uint8_t xx;
   tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0];
 
@@ -1338,7 +1305,6 @@ bool BTM_IsScoActiveByBdaddr(const RawAddress& remote_bda) {
       return (true);
     }
   }
-#endif
   return (false);
 }