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

Commit 42f114d8 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Add callbacks to GATT read/write operation

There is no need for read/write callback to be a global event. It should
execute local callback instead.

Change-Id: Id7e915af9d30092d2f754eddc7c3aed4970eeb2f
parent c8666db9
Loading
Loading
Loading
Loading
+12 −38
Original line number Diff line number Diff line
@@ -1233,29 +1233,16 @@ void bta_gattc_confirm(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
*******************************************************************************/
void bta_gattc_read_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
{
    uint8_t               event;
    tBTA_GATTC          cb_data;
    memset(&cb_data, 0, sizeof(tBTA_GATTC));

    cb_data.read.status     = p_data->status;

    if (p_data->p_cmpl != NULL && p_data->status == BTA_GATT_OK)
    {
        cb_data.read.handle = p_data->p_cmpl->att_value.handle;

        cb_data.read.len = p_data->p_cmpl->att_value.len;
        memcpy(cb_data.read.value, p_data->p_cmpl->att_value.value, cb_data.read.len);
    } else {
        cb_data.read.handle = p_clcb->p_q_cmd->api_read.handle;
    }

    event = p_clcb->p_q_cmd->api_read.cmpl_evt;
    cb_data.read.conn_id = p_clcb->bta_conn_id;
    GATT_READ_OP_CB cb = p_clcb->p_q_cmd->api_read.read_cb;
    void *my_cb_data = p_clcb->p_q_cmd->api_read.read_cb_data;

    uint16_t handle = p_clcb->p_q_cmd->api_read.handle;
    osi_free_and_reset((void **)&p_clcb->p_q_cmd);
    /* read complete, callback */
    ( *p_clcb->p_rcb->p_cback)(event, (tBTA_GATTC *)&cb_data);

    if (cb) {
        cb(p_clcb->bta_conn_id, p_data->status, handle,
            p_data->p_cmpl->att_value.len, p_data->p_cmpl->att_value.value, my_cb_data);
    }
}
/*******************************************************************************
**
@@ -1268,27 +1255,14 @@ void bta_gattc_read_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
*******************************************************************************/
void bta_gattc_write_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
{
    tBTA_GATTC      cb_data = {0};
    uint8_t          event;

    memset(&cb_data, 0, sizeof(tBTA_GATTC));

    cb_data.write.status     = p_data->status;
    cb_data.write.handle = p_data->p_cmpl->att_value.handle;

    if (p_clcb->p_q_cmd->api_write.hdr.event == BTA_GATTC_API_WRITE_EVT &&
        p_clcb->p_q_cmd->api_write.write_type == BTA_GATTC_WRITE_PREPARE)

        event = BTA_GATTC_PREP_WRITE_EVT;

    else
        event = p_clcb->p_q_cmd->api_write.cmpl_evt;
    GATT_WRITE_OP_CB cb = p_clcb->p_q_cmd->api_write.write_cb;
    void *my_cb_data = p_clcb->p_q_cmd->api_write.write_cb_data;

    osi_free_and_reset((void **)&p_clcb->p_q_cmd);
    cb_data.write.conn_id = p_clcb->bta_conn_id;
    /* write complete, callback */
    ( *p_clcb->p_rcb->p_cback)(event, (tBTA_GATTC *)&cb_data);

    if (cb) {
        cb(p_clcb->bta_conn_id, p_data->status, p_data->p_cmpl->att_value.handle, my_cb_data);
    }
}
/*******************************************************************************
**
+24 −11
Original line number Diff line number Diff line
@@ -334,7 +334,8 @@ void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle, uint16_t end_
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle, tBTA_GATT_AUTH_REQ auth_req)
void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle, tBTA_GATT_AUTH_REQ auth_req,
                                  GATT_READ_OP_CB callback, void* cb_data)
{
    tBTA_GATTC_API_READ *p_buf =
        (tBTA_GATTC_API_READ *)osi_calloc(sizeof(tBTA_GATTC_API_READ));
@@ -343,7 +344,8 @@ void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle, tBTA_GATT_A
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;
    p_buf->handle = handle;
    p_buf->cmpl_evt = BTA_GATTC_READ_CHAR_EVT;
    p_buf->read_cb = callback;
    p_buf->read_cb_data = cb_data;

    bta_sys_sendmsg(p_buf);
}
@@ -360,7 +362,8 @@ void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle, tBTA_GATT_A
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_ReadCharDescr (uint16_t conn_id, uint16_t handle, tBTA_GATT_AUTH_REQ auth_req)
void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle, tBTA_GATT_AUTH_REQ auth_req,
                             GATT_READ_OP_CB callback, void* cb_data)
{
    tBTA_GATTC_API_READ *p_buf =
        (tBTA_GATTC_API_READ *)osi_calloc(sizeof(tBTA_GATTC_API_READ));
@@ -369,7 +372,8 @@ void BTA_GATTC_ReadCharDescr (uint16_t conn_id, uint16_t handle, tBTA_GATT_AUTH_
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;
    p_buf->handle = handle;
    p_buf->cmpl_evt = BTA_GATTC_READ_DESCR_EVT;
    p_buf->read_cb = callback;
    p_buf->read_cb_data = cb_data;

    bta_sys_sendmsg(p_buf);
}
@@ -422,7 +426,9 @@ void BTA_GATTC_WriteCharValue ( uint16_t conn_id,
                                uint16_t handle,
                                tBTA_GATTC_WRITE_TYPE  write_type,
                                std::vector<uint8_t> value,
                                tBTA_GATT_AUTH_REQ auth_req)
                                tBTA_GATT_AUTH_REQ auth_req,
                                GATT_WRITE_OP_CB callback,
                                void* cb_data)
{
    tBTA_GATTC_API_WRITE  *p_buf = (tBTA_GATTC_API_WRITE *)
        osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size());
@@ -431,9 +437,10 @@ void BTA_GATTC_WriteCharValue ( uint16_t conn_id,
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;
    p_buf->handle = handle;
    p_buf->cmpl_evt = BTA_GATTC_WRITE_CHAR_EVT;
    p_buf->write_type = write_type;
    p_buf->len = value.size();
    p_buf->write_cb = callback;
    p_buf->write_cb_data = cb_data;

    if (value.size() > 0) {
        p_buf->p_value = (uint8_t *)(p_buf + 1);
@@ -461,7 +468,9 @@ void BTA_GATTC_WriteCharDescr (uint16_t conn_id,
                               uint16_t handle,
                               tBTA_GATTC_WRITE_TYPE  write_type,
                               std::vector<uint8_t> value,
                               tBTA_GATT_AUTH_REQ auth_req)
                               tBTA_GATT_AUTH_REQ auth_req,
                               GATT_WRITE_OP_CB callback,
                               void* cb_data)
{
    tBTA_GATTC_API_WRITE *p_buf = (tBTA_GATTC_API_WRITE *)
        osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size());
@@ -470,8 +479,9 @@ void BTA_GATTC_WriteCharDescr (uint16_t conn_id,
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;
    p_buf->handle = handle;
    p_buf->cmpl_evt = BTA_GATTC_WRITE_DESCR_EVT;
    p_buf->write_type = write_type;
    p_buf->write_cb = callback;
    p_buf->write_cb_data = cb_data;

    if (value.size() != 0) {
        p_buf->p_value  = (uint8_t *)(p_buf + 1);
@@ -496,9 +506,10 @@ void BTA_GATTC_WriteCharDescr (uint16_t conn_id,
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_PrepareWrite  (uint16_t conn_id, uint16_t handle,
                              uint16_t offset, std::vector<uint8_t> value,
                              tBTA_GATT_AUTH_REQ auth_req)
void BTA_GATTC_PrepareWrite  (uint16_t conn_id, uint16_t handle, uint16_t offset,
                              std::vector<uint8_t> value,
                              tBTA_GATT_AUTH_REQ auth_req,
                              GATT_WRITE_OP_CB callback, void* cb_data)
{
    tBTA_GATTC_API_WRITE *p_buf =
        (tBTA_GATTC_API_WRITE *)osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size());
@@ -507,6 +518,8 @@ void BTA_GATTC_PrepareWrite (uint16_t conn_id, uint16_t handle,
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;
    p_buf->handle = handle;
    p_buf->write_cb = callback;
    p_buf->write_cb_data = cb_data;

    p_buf->write_type = BTA_GATTC_WRITE_PREPARE;
    p_buf->offset   = offset;
+4 −9
Original line number Diff line number Diff line
@@ -32,10 +32,6 @@

#include "bt_common.h"

#ifdef __cplusplus
extern "C" {
#endif

/*****************************************************************************
**  Constants and data types
*****************************************************************************/
@@ -129,6 +125,8 @@ typedef struct
    tBTA_GATT_AUTH_REQ      auth_req;
    uint16_t                  handle;
    tBTA_GATTC_EVT          cmpl_evt;
    GATT_READ_OP_CB         read_cb;
    void*                   read_cb_data;
} tBTA_GATTC_API_READ;

typedef struct
@@ -136,11 +134,12 @@ typedef struct
    BT_HDR                  hdr;
    tBTA_GATT_AUTH_REQ      auth_req;
    uint16_t                  handle;
    tBTA_GATTC_EVT          cmpl_evt;
    tBTA_GATTC_WRITE_TYPE   write_type;
    uint16_t                  offset;
    uint16_t                  len;
    uint8_t                   *p_value;
    GATT_WRITE_OP_CB        write_cb;
    void*                   write_cb_data;
}tBTA_GATTC_API_WRITE;

typedef struct
@@ -497,8 +496,4 @@ extern bool bta_gattc_conn_dealloc(BD_ADDR remote_bda);
extern bool bta_gattc_cache_load(tBTA_GATTC_CLCB *p_clcb);
extern void bta_gattc_cache_reset(BD_ADDR server_bda);

#ifdef __cplusplus
}
#endif

#endif /* BTA_GATTC_INT_H */
+0 −20
Original line number Diff line number Diff line
@@ -33,10 +33,6 @@
#include "bta_gatt_api.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

/* can be moved to bta_api.h */
#define BTA_HH_MAX_RPT_CHARS    8

@@ -65,10 +61,6 @@ enum
    BTA_HH_GATT_OPEN_EVT,
    BTA_HH_START_ENC_EVT,
    BTA_HH_ENC_CMPL_EVT,
    BTA_HH_GATT_READ_CHAR_CMPL_EVT,
    BTA_HH_GATT_WRITE_CHAR_CMPL_EVT,
    BTA_HH_GATT_READ_DESCR_CMPL_EVT,
    BTA_HH_GATT_WRITE_DESCR_CMPL_EVT,
    BTA_HH_GATT_ENC_CMPL_EVT,
#endif

@@ -216,7 +208,6 @@ typedef struct
    uint16_t                  proto_mode_handle;
    uint8_t                   control_point_handle;

    bool                 expl_incl_srvc;
    uint8_t                   incl_srvc_inst; /* assuming only one included service : battery service */
    uint8_t                   cur_expl_char_idx; /* currently discovering service index */
    uint8_t                   *rpt_map;
@@ -385,13 +376,6 @@ extern void bta_hh_gatt_open(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_gatt_close(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_start_security(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_start_srvc_discovery(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_w4_le_read_char_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_le_read_char_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_w4_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_w4_le_write_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_le_write_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_le_write_char_descr_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_start_security(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_security_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_le_notify_enc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
@@ -401,9 +385,5 @@ extern void bta_hh_ci_load_rpt (tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
extern void bta_hh_trace_dev_db(void);
#endif

#ifdef __cplusplus
}
#endif

#endif
Loading