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

Commit 6e5f0111 authored by Grzegorz Kolodziejczyk's avatar Grzegorz Kolodziejczyk Committed by Grzegorz Kołodziejczyk
Browse files

gattc: Extend gattc queue with mtu exchange

Patch allows to exchange mtu using queue. Without this patch there was
no possiblity to exchange mtu mixing this synchronous and queue api.

Tag: #feature
Test: CtsVerifier
Sponsor: jpawlowski@
Change-Id: I2dd699d78de1b9eee8c683969f0c6586ccd21780
parent 2777b9a7
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -911,6 +911,8 @@ void bta_gattc_exec_cmpl(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_OP_CMPL* p_data) {
/** configure MTU operation complete */
void bta_gattc_cfg_mtu_cmpl(tBTA_GATTC_CLCB* p_clcb,
                            tBTA_GATTC_OP_CMPL* p_data) {
  GATT_CONFIGURE_MTU_OP_CB cb = p_clcb->p_q_cmd->api_mtu.mtu_cb;
  void* my_cb_data = p_clcb->p_q_cmd->api_mtu.mtu_cb_data;
  tBTA_GATTC cb_data;

  osi_free_and_reset((void**)&p_clcb->p_q_cmd);
@@ -924,6 +926,10 @@ void bta_gattc_cfg_mtu_cmpl(tBTA_GATTC_CLCB* p_clcb,
  cb_data.cfg_mtu.status = p_data->status;
  cb_data.cfg_mtu.mtu = p_clcb->p_srcb->mtu;

  if (cb) {
    cb(p_clcb->bta_conn_id, p_data->status, my_cb_data);
  }

  (*p_clcb->p_rcb->p_cback)(BTA_GATTC_CFG_MTU_EVT, &cb_data);
}

+13 −0
Original line number Diff line number Diff line
@@ -213,6 +213,19 @@ void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) {

  bta_sys_sendmsg(p_buf);
}
void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu,
                            GATT_CONFIGURE_MTU_OP_CB callback, void* cb_data) {
  tBTA_GATTC_API_CFG_MTU* p_buf =
      (tBTA_GATTC_API_CFG_MTU*)osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU));

  p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT;
  p_buf->hdr.layer_specific = conn_id;
  p_buf->mtu = mtu;
  p_buf->mtu_cb = callback;
  p_buf->mtu_cb_data = cb_data;

  bta_sys_sendmsg(p_buf);
}

/*******************************************************************************
 *
+2 −0
Original line number Diff line number Diff line
@@ -161,6 +161,8 @@ typedef struct {
typedef struct {
  BT_HDR hdr;
  uint16_t mtu;
  GATT_CONFIGURE_MTU_OP_CB mtu_cb;
  void* mtu_cb_data;
} tBTA_GATTC_API_CFG_MTU;

typedef struct {
+41 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ constexpr uint8_t GATT_READ_CHAR = 1;
constexpr uint8_t GATT_READ_DESC = 2;
constexpr uint8_t GATT_WRITE_CHAR = 3;
constexpr uint8_t GATT_WRITE_DESC = 4;
constexpr uint8_t GATT_CONFIG_MTU = 5;

struct gatt_read_op_data {
  GATT_READ_OP_CB cb;
@@ -80,6 +81,29 @@ void BtaGattQueue::gatt_write_op_finished(uint16_t conn_id, tGATT_STATUS status,
  }
}

struct gatt_configure_mtu_op_data {
  GATT_CONFIGURE_MTU_OP_CB cb;
  void* cb_data;
};

void BtaGattQueue::gatt_configure_mtu_op_finished(uint16_t conn_id,
                                                  tGATT_STATUS status,
                                                  void* data) {
  gatt_configure_mtu_op_data* tmp = (gatt_configure_mtu_op_data*)data;
  GATT_CONFIGURE_MTU_OP_CB tmp_cb = tmp->cb;
  void* tmp_cb_data = tmp->cb_data;

  osi_free(data);

  mark_as_not_executing(conn_id);
  gatt_execute_next_op(conn_id);

  if (tmp_cb) {
    tmp_cb(conn_id, status, tmp_cb_data);
    return;
  }
}

void BtaGattQueue::gatt_execute_next_op(uint16_t conn_id) {
  APPL_TRACE_DEBUG("%s: conn_id=0x%x", __func__, conn_id);
  if (gatt_op_queue.empty()) {
@@ -137,6 +161,14 @@ void BtaGattQueue::gatt_execute_next_op(uint16_t conn_id) {
    data->cb_data = op.write_cb_data;
    BTA_GATTC_WriteCharDescr(conn_id, op.handle, std::move(op.value),
                             GATT_AUTH_REQ_NONE, gatt_write_op_finished, data);
  } else if (op.type == GATT_CONFIG_MTU) {
    gatt_configure_mtu_op_data* data =
      (gatt_configure_mtu_op_data*)osi_malloc(sizeof(gatt_configure_mtu_op_data));
    data->cb = op.mtu_cb;
    data->cb_data = op.mtu_cb_data;
    BTA_GATTC_ConfigureMTU(conn_id, static_cast<uint16_t>(op.value[0] |
                                                          (op.value[1] << 8)),
                           gatt_configure_mtu_op_finished, data);
  }

  gatt_ops.pop_front();
@@ -190,3 +222,12 @@ void BtaGattQueue::WriteDescriptor(uint16_t conn_id, uint16_t handle,
                                    .value = std::move(value)});
  gatt_execute_next_op(conn_id);
}

void BtaGattQueue::ConfigureMtu(uint16_t conn_id, uint16_t mtu) {
  LOG(INFO) << __func__ << ", mtu: " << static_cast<int>(mtu);
  std::vector<uint8_t> value = {static_cast<uint8_t>(mtu & 0xff),
                                static_cast<uint8_t>(mtu >> 8)};
  gatt_op_queue[conn_id].push_back({.type = GATT_CONFIG_MTU,
                                    .value = std::move(value)});
  gatt_execute_next_op(conn_id);
}
+5 −0
Original line number Diff line number Diff line
@@ -601,6 +601,8 @@ typedef void (*GATT_READ_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
                                void* data);
typedef void (*GATT_WRITE_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
                                 uint16_t handle, void* data);
typedef void (*GATT_CONFIGURE_MTU_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
                                         void* data);

/*******************************************************************************
 *
@@ -808,6 +810,9 @@ extern void BTA_GATTC_Refresh(const RawAddress& remote_bda);
 *
 ******************************************************************************/
extern void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu);
extern void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu,
                                   GATT_CONFIGURE_MTU_OP_CB callback,
                                   void* cb_data);

/*******************************************************************************
 *  BTA GATT Server API
Loading