From 922b83ac38ede289bc045cbf83110992389be030 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 4 Feb 2016 12:58:19 +0200 Subject: [PATCH] drivers/nble: Add initial implementation of on_ble_gatts_write_evt Change-Id: Ib28d35d6f5aac697dbbbac8e7d01e6bfcf6545c6 Signed-off-by: Luiz Augusto von Dentz --- drivers/nble/gatt.c | 21 +++++++++++++++++++-- drivers/nble/gatt_internal.h | 5 ++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/nble/gatt.c b/drivers/nble/gatt.c index 573f79b41c1..a95a516c2bd 100644 --- a/drivers/nble/gatt.c +++ b/drivers/nble/gatt.c @@ -427,10 +427,27 @@ void on_ble_gattc_value_evt(const struct ble_gattc_value_evt *ev, BT_DBG(""); } -void on_ble_gatts_write_evt(const struct ble_gatt_wr_evt *ev, +void on_ble_gatts_write_evt(const struct ble_gatt_wr_evt *evt, const uint8_t *buf, uint8_t buflen) { - BT_DBG(""); + const struct bt_gatt_attr *attr = evt->attr; + struct ble_gatts_rw_reply_params reply_data; + + if (attr->write) { + reply_data.status = attr->write(NULL, attr, buf, buflen, + evt->offset); + } + + BT_DBG("handle 0x%04x buf %p len %u", attr->handle, buf, buflen); + + if (evt->reply) { + reply_data.conn_handle = evt->conn_handle; + reply_data.offset = evt->offset; + reply_data.write_reply = 1; + + nble_gatts_rw_authorize_reply_req(&reply_data, NULL, + reply_data.status); + } } void on_ble_gatts_get_attribute_value_rsp(const struct ble_gatts_attribute_response *par, diff --git a/drivers/nble/gatt_internal.h b/drivers/nble/gatt_internal.h index 1a017fee399..285a90edba5 100644 --- a/drivers/nble/gatt_internal.h +++ b/drivers/nble/gatt_internal.h @@ -93,12 +93,11 @@ enum BLE_GATTS_WR_OPS { * Write event context data structure. */ struct ble_gatt_wr_evt { - /**< Attribute mapping indexes */ - struct ble_gatt_attr_handle_mapping attr; + struct bt_gatt_attr *attr; /**< GATT Attribute */ uint16_t conn_handle; /**< Connection handle */ uint16_t attr_handle; /**< handle of attribute to write */ uint16_t offset; /**< offset in attribute buffer */ - uint8_t op; /**< @ref BLE_GATTS_WR_OPS */ + uint8_t reply; /**< 1 if reply required, 0 otherwise */ }; /**