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

Commit 86bc3759 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Make GAP_ConnWriteData accept BT_HDR

This is next step towards making LE sockets work with zero copies.

Test: transfer file using OPP
Bug: 68359837
Change-Id: Iedcdd59acb223e2982f6cb96b8656f517008dee5
parent 9a69b08f
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -1171,7 +1171,17 @@ void bta_jv_l2cap_write(uint32_t handle, uint32_t req_id, uint8_t* p_data,
  evt_data.cong = p_cb->cong;
  evt_data.len = len;
  bta_jv_pm_conn_busy(p_cb->p_pm_cb);
  if (!evt_data.cong && BT_PASS == GAP_ConnWriteData(handle, p_data, len)) {

  if (!evt_data.cong) {
    BT_HDR* msg = (BT_HDR*)osi_malloc(BT_HDR_SIZE + L2CAP_MIN_OFFSET + len +
                                      L2CAP_FCS_LENGTH);
    msg->offset = L2CAP_MIN_OFFSET;
    msg->len = len;
    memcpy((uint8_t*)(msg) + BT_HDR_SIZE + msg->offset, p_data, msg->len);
    // TODO: this was set only for non-fixed channel packets. Get rid of it.
    msg->event = BT_EVT_TO_BTU_SP_DATA;

    if (GAP_ConnWriteData(handle, msg) == BT_PASS)
      evt_data.status = BTA_JV_SUCCESS;
  }

@@ -1194,9 +1204,9 @@ void bta_jv_l2cap_write_fixed(uint16_t channel, const RawAddress& addr,
  evt_data.len = 0;

  BT_HDR* msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + len + L2CAP_MIN_OFFSET);
  memcpy(((uint8_t*)(msg + 1)) + L2CAP_MIN_OFFSET, p_data, len);
  msg->len = len;
  msg->offset = L2CAP_MIN_OFFSET;
  msg->len = len;
  memcpy((uint8_t*)(msg) + BT_HDR_SIZE + msg->offset, p_data, msg->len);

  osi_free(p_data);

+17 −20
Original line number Diff line number Diff line
@@ -499,8 +499,8 @@ static bool gap_try_write_queued_data(tGAP_CCB* p_ccb) {
 *                  to send data to the connection.
 *
 * Parameters:      handle      - Handle of the connection returned in the Open
 *                  p_data      - Data area
 *                  data_len    - Data length, must be smaller thand remote MTU
 *                  msg         - pointer to single SDU to send. This function
 *                                will take ownership of it.
 *
 * Returns          BT_PASS                 - data read
 *                  GAP_ERR_BAD_HANDLE      - invalid handle
@@ -508,30 +508,27 @@ static bool gap_try_write_queued_data(tGAP_CCB* p_ccb) {
 *                  GAP_CONGESTION          - system is congested
 *
 ******************************************************************************/
uint16_t GAP_ConnWriteData(uint16_t gap_handle, uint8_t* p_data,
                           uint16_t data_len) {
uint16_t GAP_ConnWriteData(uint16_t gap_handle, BT_HDR* msg) {
  tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle);

  if (!p_ccb) return (GAP_ERR_BAD_HANDLE);

  if (p_ccb->con_state != GAP_CCB_STATE_CONNECTED) return (GAP_ERR_BAD_STATE);

  if (data_len > p_ccb->rem_mtu_size) return GAP_ERR_ILL_PARM;

  size_t bufsize = BT_HDR_SIZE + L2CAP_MIN_OFFSET + data_len;
  if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)
    bufsize += 2; /* 2 byte FCS at end on PDU */
  if (!p_ccb) {
    osi_free(msg);
    return GAP_ERR_BAD_HANDLE;
  }

  BT_HDR* p_buf = (BT_HDR*)osi_malloc(bufsize);
  p_buf->offset = L2CAP_MIN_OFFSET;
  p_buf->len = data_len;
  p_buf->event = BT_EVT_TO_BTU_SP_DATA;
  if (p_ccb->con_state != GAP_CCB_STATE_CONNECTED) {
    osi_free(msg);
    return GAP_ERR_BAD_STATE;
  }

  memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, p_data, p_buf->len);
  if (msg->len > p_ccb->rem_mtu_size) {
    osi_free(msg);
    return GAP_ERR_ILL_PARM;
  }

  DVLOG(1) << StringPrintf("GAP_WriteData %d bytes", p_buf->len);
  DVLOG(1) << StringPrintf("GAP_WriteData %d bytes", msg->len);

  fixed_queue_enqueue(p_ccb->tx_queue, p_buf);
  fixed_queue_enqueue(p_ccb->tx_queue, msg);

  if (!gap_try_write_queued_data(p_ccb)) return GAP_ERR_BAD_STATE;

+1 −2
Original line number Diff line number Diff line
@@ -239,8 +239,7 @@ extern uint16_t GAP_ConnBTRead(uint16_t gap_handle, BT_HDR** pp_buf);
 *                  GAP_CONGESTION          - system is congested
 *
 ******************************************************************************/
extern uint16_t GAP_ConnWriteData(uint16_t gap_handle, uint8_t* p_data,
                                  uint16_t max_len);
extern uint16_t GAP_ConnWriteData(uint16_t gap_handle, BT_HDR* msg);

/*******************************************************************************
 *
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@
#define L2CAP_LCC_OFFSET \
  (L2CAP_MIN_OFFSET + L2CAP_LCC_SDU_LENGTH) /* plus SDU length(2) */

#define L2CAP_FCS_LENGTH 2

/* ping result codes */
#define L2CAP_PING_RESULT_OK 0      /* Ping reply received OK     */
#define L2CAP_PING_RESULT_NO_LINK 1 /* Link could not be setup    */