OSDN Git Service

L2cap channel cb: Store who initiated dynamic channel
authorHansong Zhang <hsz@google.com>
Sun, 27 Sep 2020 23:12:43 +0000 (16:12 -0700)
committerHansong Zhang <hsz@google.com>
Mon, 28 Sep 2020 18:55:20 +0000 (11:55 -0700)
Use pL2CA_ConfigCfm_Cb to let user know the direction.

Later the user can run check in ConnectInd or ConnectCfm callback.

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Iae663e6bea0fc9426c5dfbbfc52bd1ae848f2965

16 files changed:
stack/avct/avct_l2c.cc
stack/avct/avct_l2c_br.cc
stack/avdt/avdt_l2c.cc
stack/bnep/bnep_main.cc
stack/gap/gap_conn.cc
stack/gatt/gatt_main.cc
stack/hid/hidd_conn.cc
stack/hid/hidh_conn.cc
stack/include/l2c_api.h
stack/l2cap/l2c_api.cc
stack/l2cap/l2c_ble.cc
stack/l2cap/l2c_csm.cc
stack/l2cap/l2c_int.h
stack/l2cap/l2c_main.cc
stack/rfcomm/rfc_l2cap_if.cc
stack/sdp/sdp_main.cc

index 33b0028..adac961 100644 (file)
@@ -216,7 +216,7 @@ void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) {
  * Returns          void
  *
  ******************************************************************************/
-void avct_l2c_config_cfm_cback(uint16_t lcid, uint16_t result) {
+void avct_l2c_config_cfm_cback(uint16_t lcid, uint16_t initiator) {
   tAVCT_LCB* p_lcb;
 
   /* look up lcb for this channel */
index 1db9ec8..a11ece8 100644 (file)
@@ -148,7 +148,7 @@ void avct_l2c_br_connect_cfm_cback(uint16_t lcid, uint16_t result) {
  * Returns          void
  *
  ******************************************************************************/
-void avct_l2c_br_config_cfm_cback(uint16_t lcid, uint16_t result) {
+void avct_l2c_br_config_cfm_cback(uint16_t lcid, uint16_t initiator) {
   tAVCT_BCB* p_lcb;
 
   /* look up lcb for this channel */
index fa2dfb1..f1d3515 100644 (file)
@@ -289,7 +289,7 @@ void avdt_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) {
  * Returns          void
  *
  ******************************************************************************/
-void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t result) {
+void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t initiator) {
   AvdtpTransportChannel* p_tbl;
 
   AVDT_TRACE_DEBUG("%s: lcid: %d", __func__, lcid);
index 7469dba..ba3ee0f 100644 (file)
@@ -211,7 +211,7 @@ static void bnep_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) {
  * Returns          void
  *
  ******************************************************************************/
-static void bnep_config_cfm(uint16_t l2cap_cid, uint16_t result) {
+static void bnep_config_cfm(uint16_t l2cap_cid, uint16_t initiator) {
   tBNEP_CONN* p_bcb;
 
   BNEP_TRACE_EVENT("BNEP - Rcvd cfg cfm, CID: 0x%x", l2cap_cid);
index bfda3d0..13b12e7 100644 (file)
@@ -783,7 +783,7 @@ static void gap_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) {
  * Returns          void
  *
  ******************************************************************************/
-static void gap_config_cfm(uint16_t l2cap_cid, uint16_t result) {
+static void gap_config_cfm(uint16_t l2cap_cid, uint16_t initiator) {
   tGAP_CCB* p_ccb;
 
   /* Find CCB based on CID */
index 5c0ad3b..07d6190 100644 (file)
@@ -614,7 +614,7 @@ static void gatt_l2cif_connect_cfm_cback(uint16_t lcid, uint16_t result) {
 }
 
 /** This is the L2CAP config confirm callback function */
-void gatt_l2cif_config_cfm_cback(uint16_t lcid, uint16_t result) {
+void gatt_l2cif_config_cfm_cback(uint16_t lcid, uint16_t initiator) {
   /* look up clcb for this channel */
   tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid);
   if (!p_tcb) return;
index 4518d3e..ed4f4cf 100644 (file)
@@ -267,7 +267,7 @@ static void hidd_l2cif_config_ind(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) {
  * Returns          void
  *
  ******************************************************************************/
-static void hidd_l2cif_config_cfm(uint16_t cid, uint16_t result) {
+static void hidd_l2cif_config_cfm(uint16_t cid, uint16_t initiator) {
   tHID_CONN* p_hcon;
 
   HIDD_TRACE_EVENT("%s: cid=%04x", __func__, cid);
index e7d90b0..794d04c 100644 (file)
@@ -376,7 +376,7 @@ static void hidh_l2cif_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) {
  * Returns          void
  *
  ******************************************************************************/
-static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, uint16_t result) {
+static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, uint16_t initiator) {
   uint8_t dhandle;
   tHID_CONN* p_hcon = NULL;
   uint32_t reason;
index ab29e15..84cd013 100644 (file)
@@ -194,10 +194,12 @@ typedef void(tL2CA_CONNECT_CFM_CB)(uint16_t, uint16_t);
  */
 typedef void(tL2CA_CONFIG_IND_CB)(uint16_t, tL2CAP_CFG_INFO*);
 
+constexpr uint16_t L2CAP_INITIATOR_LOCAL = 1;
+constexpr uint16_t L2CAP_INITIATOR_REMOTE = 0;
 /* Configuration confirm callback prototype. Parameters are
  *              Local CID assigned to the connection
- *              Config result (L2CA_CONN_OK)
- *              If there is an error, tL2CA_ERROR_CB is invoked
+ *              Initiator (1 for local, 0 for remote)
+ * If there is an error, tL2CA_ERROR_CB is invoked
  */
 typedef void(tL2CA_CONFIG_CFM_CB)(uint16_t, uint16_t);
 
index 7fa972a..762d49b 100644 (file)
@@ -364,6 +364,8 @@ uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& p_bd_addr) {
   /* Save registration info */
   p_ccb->p_rcb = p_rcb;
 
+  p_ccb->connection_initiator = L2CAP_INITIATOR_LOCAL;
+
   /* If link is up, start the L2CAP connection */
   if (p_lcb->link_state == LST_CONNECTED) {
     l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_REQ, nullptr);
@@ -568,6 +570,8 @@ uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr,
   /* Save registration info */
   p_ccb->p_rcb = p_rcb;
 
+  p_ccb->connection_initiator = L2CAP_INITIATOR_LOCAL;
+
   /* Save the configuration */
   if (p_cfg) {
     p_ccb->local_conn_cfg = *p_cfg;
index 5e7909d..e760d65 100644 (file)
@@ -643,6 +643,8 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
       p_ccb->is_first_seg = true;
       p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE;
 
+      p_ccb->connection_initiator = L2CAP_INITIATOR_REMOTE;
+
       l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info);
       break;
 
index bb2e69e..7c22243 100644 (file)
@@ -757,7 +757,7 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
         if (p_ccb->config_done & OB_CFG_DONE) {
           if (p_ccb->remote_config_rsp_result == L2CAP_CFG_OK) {
             (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)(
-                p_ccb->local_cid, p_ccb->remote_config_rsp_result);
+                p_ccb->local_cid, p_ccb->connection_initiator);
           } else {
             (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid,
                                                 L2CAP_CFG_FAILED_NO_REASON);
@@ -830,7 +830,7 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
       p_ccb->remote_config_rsp_result = p_cfg->result;
       if (p_ccb->config_done & IB_CFG_DONE) {
         (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)(p_ccb->local_cid,
-                                                p_cfg->result);
+                                                p_ccb->connection_initiator);
       }
       break;
 
index e6e73dc..61c781f 100644 (file)
@@ -253,6 +253,8 @@ typedef struct t_l2c_ccb {
 #define CCB_FLAG_SENT_PENDING 0x02 /* already sent pending response */
   uint8_t flags;
 
+  bool connection_initiator; /* true if we sent ConnectReq */
+
   tL2CAP_CFG_INFO our_cfg;          /* Our saved configuration options */
   tL2CAP_CFG_INFO peer_cfg;         /* Peer's saved configuration options */
 
index 77a0cc5..cea264a 100644 (file)
@@ -392,6 +392,7 @@ static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
         p_ccb->remote_id = id;
         p_ccb->p_rcb = p_rcb;
         p_ccb->remote_cid = rcid;
+        p_ccb->connection_initiator = L2CAP_INITIATOR_REMOTE;
 
         if (p_rcb->psm == BT_PSM_RFCOMM) {
           btsnoop_get_interface()->add_rfc_l2c_channel(
index 7333019..a3f0b69 100644 (file)
@@ -197,14 +197,14 @@ void RFCOMM_ConfigInd(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) {
  *                  event to the FSM.
  *
  ******************************************************************************/
-void RFCOMM_ConfigCnf(uint16_t lcid, uint16_t result) {
+void RFCOMM_ConfigCnf(uint16_t lcid, uint16_t initiator) {
   tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid);
 
   if (!p_mcb) {
     RFCOMM_TRACE_ERROR("RFCOMM_ConfigCnf no MCB LCID:0x%x", lcid);
     return;
   }
-  uintptr_t result_as_ptr = result;
+  uintptr_t result_as_ptr = L2CAP_CFG_OK;
   rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONF_CNF, (void*)result_as_ptr);
 }
 
index 71e2757..5bd4807 100644 (file)
@@ -209,7 +209,7 @@ static void sdp_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) {
  * Returns          void
  *
  ******************************************************************************/
-static void sdp_config_cfm(uint16_t l2cap_cid, uint16_t result) {
+static void sdp_config_cfm(uint16_t l2cap_cid, uint16_t initiator) {
   tCONN_CB* p_ccb;
 
   SDP_TRACE_EVENT("SDP - Rcvd cfg cfm, CID: 0x%x", l2cap_cid);