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

Commit f1a150a5 authored by Chris Manton's avatar Chris Manton
Browse files

shim: Add l2cap per-channel network transfer metrics

Bug: 183374320
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I25bb743c6f9052b93a1bb8c663033c22e2bd16a8
parent e628699b
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -1098,16 +1098,19 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
          p_ccb->local_cid <= L2CAP_LAST_FIXED_CHNL) {
        if (p_ccb->local_cid < L2CAP_BASE_APPL_CID) {
          if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL]
                  .pL2CA_FixedData_Cb)
                  .pL2CA_FixedData_Cb != nullptr) {
            p_ccb->metrics.rx(static_cast<BT_HDR*>(p_data)->len);
            (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL]
                  .pL2CA_FixedData_Cb)(p_ccb->local_cid,
                                       p_ccb->p_lcb->remote_bd_addr,
                                       (BT_HDR*)p_data);
          else
            osi_free(p_data);
          } else {
            if (p_data != nullptr) osi_free_and_reset(&p_data);
          }
          break;
        }
      }
      if (p_data) p_ccb->metrics.rx(static_cast<BT_HDR*>(p_data)->len);
      (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid, (BT_HDR*)p_data);
      break;

@@ -1244,9 +1247,11 @@ static void l2c_csm_open(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
      break;

    case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd    */
      if ((p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_DataInd_Cb))
      if ((p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_DataInd_Cb)) {
        p_ccb->metrics.rx(static_cast<BT_HDR*>(p_data)->len);
        (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid,
                                              (BT_HDR*)p_data);
      }
      break;

    case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */
@@ -1543,6 +1548,10 @@ static const char* l2c_csm_get_event_name(tL2CEVT event) {
 *
 ******************************************************************************/
void l2c_enqueue_peer_data(tL2C_CCB* p_ccb, BT_HDR* p_buf) {
  CHECK(p_ccb != nullptr);

  p_ccb->metrics.tx(p_buf->len);

  uint8_t* p;

  if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) {
+22 −0
Original line number Diff line number Diff line
@@ -352,6 +352,28 @@ typedef struct t_l2c_ccb {
  /* used to indicate that ECOC is used */
  bool ecoc{false};
  bool reconfig_started;

  struct {
    struct {
      unsigned bytes{0};
      unsigned packets{0};
      void operator()(unsigned bytes) {
        this->bytes += bytes;
        this->packets++;
      }
    } rx, tx;
    struct {
      struct {
        unsigned bytes{0};
        unsigned packets{0};
        void operator()(unsigned bytes) {
          this->bytes += bytes;
          this->packets++;
        }
      } rx, tx;
    } dropped;
  } metrics;

} tL2C_CCB;

/***********************************************************************
+1 −0
Original line number Diff line number Diff line
@@ -199,6 +199,7 @@ void l2c_rcv_acl_data(BT_HDR* p_msg) {

    /* If no CCB for this channel, allocate one */
    p_ccb = p_lcb->p_fixed_ccbs[rcv_cid - L2CAP_FIRST_FIXED_CHNL];
    p_ccb->metrics.rx(p_msg->len);

    if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE)
      l2c_fcr_proc_pdu(p_ccb, p_msg);