From 8bd948a7d9b2f2f3743816a9b51bac69445100d7 Mon Sep 17 00:00:00 2001 From: Lukasz Rymanowski Date: Sun, 13 Apr 2014 00:00:26 +0200 Subject: [PATCH] android/gatt: Add helper to create characteristic op data This patch adds helper to create data needed for read/write characteristic --- android/gatt.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/android/gatt.c b/android/gatt.c index 89ad3b5fb..1660075c1 100644 --- a/android/gatt.c +++ b/android/gatt.c @@ -1952,6 +1952,25 @@ struct char_op_data { uint8_t primary; }; +static struct char_op_data *create_char_op_data(int32_t conn_id, + const struct element_id *s_id, + const struct element_id *ch_id, + bool primary) +{ + struct char_op_data *d; + + d = new0(struct char_op_data, 1); + if (!d) + return NULL; + + d->conn_id = conn_id; + d->srvc_id = s_id; + d->char_id = ch_id; + d->primary = primary; + + return d; +} + static void send_client_read_char_notify(int32_t status, const uint8_t *pdu, uint16_t len, int32_t conn_id, const struct element_id *s_id, @@ -2029,18 +2048,14 @@ static void handle_client_read_characteristic(const void *buf, uint16_t len) goto failed; } - cb_data = new0(struct char_op_data, 1); + cb_data = create_char_op_data(cmd->conn_id, &srvc->id, &ch->id, + cmd->srvc_id.is_primary); if (!cb_data) { error("gatt: Cannot allocate cb data"); status = HAL_STATUS_NOMEM; goto failed; } - cb_data->conn_id = cmd->conn_id; - cb_data->primary = cmd->srvc_id.is_primary; - cb_data->srvc_id = &srvc->id; - cb_data->char_id = &ch->id; - if (!gatt_read_char(dev->attrib, ch->ch.value_handle, read_char_cb, cb_data)) { error("gatt: Cannot read characteristic with inst_id: %d", @@ -2132,18 +2147,14 @@ static void handle_client_write_characteristic(const void *buf, uint16_t len) goto failed; } - cb_data = new0(struct char_op_data, 1); + cb_data = create_char_op_data(cmd->conn_id, &srvc->id, &ch->id, + cmd->srvc_id.is_primary); if (!cb_data) { error("gatt: Cannot allocate call data"); status = HAL_STATUS_NOMEM; goto failed; } - cb_data->conn_id = cmd->conn_id; - cb_data->primary = cmd->srvc_id.is_primary; - cb_data->srvc_id = &srvc->id; - cb_data->char_id = &ch->id; - if (!gatt_write_char(dev->attrib, ch->ch.value_handle, cmd->value, cmd->len, write_char_cb, cb_data)) { error("gatt: Cannot read characteristic with inst_id: %d", -- 2.47.3