Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9f93cdf authored by Liang Li's avatar Liang Li
Browse files

Add helper functions to get RFCOMM channel and L2CAP local mtu information

Flag: com.android.bluetooth.flags.socket_settings_api
Bug: 342012881
Bug: 374358112
Test: m -j
Change-Id: Id94712de7fb1ebdd88dd850db16e176092c10185
parent cfae36f8
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -933,6 +933,23 @@ public:
   **
   ******************************************************************************/
  virtual bool L2CA_GetAclHandle(uint16_t lcid, uint16_t* acl_handle) = 0;

  /*******************************************************************************
   **
   ** Function         L2CA_GetLocalMtu
   **
   ** Description      Given a local channel identifier, |lcid|, this function
   **                  returns the L2CAP local mtu, |local_mtu|. If
   **                  |lcid| is not known or is invalid, this function returns false and does not
   **                  modify the value pointed at by |local_mtu|.
   **
   ** Parameters:      lcid: Local CID
   **                  local_mtu: Pointer to L2CAP local mtu must NOT be nullptr
   **
   ** Returns          true if local_mtu lookup was successful
   **
   ******************************************************************************/
  virtual bool L2CA_GetLocalMtu(uint16_t lcid, uint16_t* local_mtu) = 0;
};

Interface& get_interface();
+26 −0
Original line number Diff line number Diff line
@@ -483,4 +483,30 @@ void RFCOMM_Init(void);
 ******************************************************************************/
[[nodiscard]] int PORT_GetSecurityMask(uint16_t handle, uint16_t* sec_mask);

/*******************************************************************************
 *
 * Function         PORT_GetChannelInfo
 *
 * Description      This function is called to get RFCOMM channel information
 *                  by the handle of the port. All OUT parameters must NOT be nullptr.
 *
 * Parameters:      handle        - Handle of the port returned in the Open
 *                  local_mtu     - OUT local L2CAP MTU
 *                  remote_mtu    - OUT remote L2CAP MTU
 *                  local_credit  - OUT local RFCOMM credit
 *                  remote_credit - OUT remote RFCOMM credit
 *                  local_cid     - OUT local L2CAP CID
 *                  remote_cid    - OUT remote L2CAP CID
 *                  dlci          - OUT dlci
 *                  max_frame_size- OUT max frame size for RFCOMM
 *                  acl_handle    - OUT ACL handle
 *                  mux_initiator - OUT is initiator of the RFCOMM multiplexer control channel
 *
 ******************************************************************************/
[[nodiscard]] int PORT_GetChannelInfo(uint16_t handle, uint16_t* local_mtu, uint16_t* remote_mtu,
                                      uint16_t* local_credit, uint16_t* remote_credit,
                                      uint16_t* local_cid, uint16_t* remote_cid, uint16_t* dlci,
                                      uint16_t* max_frame_size, uint16_t* acl_handle,
                                      bool* mux_initiator);

#endif /* PORT_API_H */
+17 −0
Original line number Diff line number Diff line
@@ -794,3 +794,20 @@ void L2CA_SetMediaStreamChannel(uint16_t local_media_cid, bool status);
**
******************************************************************************/
[[nodiscard]] bool L2CA_GetAclHandle(uint16_t lcid, uint16_t* acl_handle);

/*******************************************************************************
 **
 ** Function         L2CA_GetLocalMtu
 **
 ** Description      Given a local channel identifier, |lcid|, this function
 **                  returns the L2CAP local mtu, |local_mtu|. If
 **                  |lcid| is not known or is invalid, this function returns false and does not
 **                  modify the value pointed at by |local_mtu|.
 **
 ** Parameters:      lcid: Local CID
 **                  local_mtu: Pointer to L2CAP local mtu must NOT be nullptr
 **
 ** Returns          true if local_mtu lookup was successful
 **
 ******************************************************************************/
[[nodiscard]] bool L2CA_GetLocalMtu(uint16_t lcid, uint16_t* local_mtu);
+27 −0
Original line number Diff line number Diff line
@@ -1763,6 +1763,33 @@ bool L2CA_GetAclHandle(uint16_t lcid, uint16_t* acl_handle) {
  return true;
}

/*******************************************************************************
 **
 ** Function         L2CA_GetLocalMtu
 **
 ** Description      Given a local channel identifier, |lcid|, this function
 **                  returns the L2CAP local mtu, |local_mtu|. If
 **                  |lcid| is not known or is invalid, this function returns false and does not
 **                  modify the value pointed at by |local_mtu|.
 **
 ** Parameters:      lcid: Local CID
 **                  local_mtu: Pointer to L2CAP local mtu must NOT be nullptr
 **
 ** Returns          true if local_mtu lookup was successful
 **
 ******************************************************************************/
bool L2CA_GetLocalMtu(uint16_t lcid, uint16_t* local_mtu) {
  log::assert_that(local_mtu != nullptr, "assert failed: local_mtu != nullptr");

  tL2C_CCB* p_ccb = l2cu_find_ccb_by_cid(nullptr, lcid);
  if (p_ccb == nullptr) {
    log::error("No CCB for CID:0x{:04x}", lcid);
    return false;
  }
  *local_mtu = p_ccb->p_rcb->my_mtu;
  return true;
}

using namespace bluetooth;

#define DUMPSYS_TAG "shim::legacy::l2cap"
+2 −0
Original line number Diff line number Diff line
@@ -135,6 +135,8 @@ public:
                                         bool is_local_cid) override;

  [[nodiscard]] bool L2CA_GetAclHandle(uint16_t lcid, uint16_t* acl_handle) override;

  [[nodiscard]] bool L2CA_GetLocalMtu(uint16_t lcid, uint16_t* local_mtu) override;
};

}  // namespace l2cap
Loading