summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Paulo Rechi Vita <jprvita@gmail.com>2013-12-18 11:41:10 -0300
committerJoão Paulo Rechi Vita <jprvita@gmail.com>2014-01-15 15:03:54 -0300
commit5c35b1f5e0f5839b1bf995e9d81157ff9ad627f1 (patch)
tree3d21adcff18cb715b8ffde4768bf4354780c9acb
parentdd8e8418a3f9c74d9275d7ca075d8d92d197165e (diff)
lib: Create API to read a GATT descriptor
-rw-r--r--lib/ble.c35
-rw-r--r--lib/ble.h16
2 files changed, 50 insertions, 1 deletions
diff --git a/lib/ble.c b/lib/ble.c
index 0a4530d..4a96e66 100644
--- a/lib/ble.c
+++ b/lib/ble.c
@@ -543,6 +543,22 @@ void read_characteristic_cb(int conn_id, int status,
p_data->value.len, p_data->value_type, status);
}
+/* Called when a GATT read descriptor operation returns */
+static void read_descriptor_cb(int conn_id, int status,
+ btgatt_read_params_t *p_data) {
+ ble_device_t *dev;
+ int id = -1;
+
+ dev = find_device_by_conn_id(conn_id);
+ if (dev)
+ id = find_descriptor(dev, &p_data->srvc_id, &p_data->char_id,
+ &p_data->descr_id);
+
+ if (data.cbs.desc_read_cb)
+ data.cbs.desc_read_cb(conn_id, id, p_data->value.value,
+ p_data->value.len, p_data->value_type, status);
+}
+
static int ble_gatt_op(int operation, int conn_id, int id, int auth) {
ble_device_t *dev;
bt_status_t s = BT_STATUS_UNSUPPORTED;
@@ -572,6 +588,19 @@ static int ble_gatt_op(int operation, int conn_id, int id, int auth) {
&dev->chars[id].c,
auth);
break;
+
+ case 1: /* Read descriptor */
+ if (dev->desc_count <= 0)
+ return -1;
+ if (id >= dev->desc_count)
+ return -1;
+
+ s = data.gattiface->client->read_descriptor(conn_id,
+ &dev->descs[id].c.s,
+ &dev->descs[id].c.c,
+ &dev->descs[id].d,
+ auth);
+ break;
}
if (s != BT_STATUS_SUCCESS)
@@ -584,6 +613,10 @@ int ble_gatt_read_char(int conn_id, int char_id, int auth) {
return ble_gatt_op(0, conn_id, char_id, auth);
}
+int ble_gatt_read_desc(int conn_id, int desc_id, int auth) {
+ return ble_gatt_op(1, conn_id, desc_id, auth);
+}
+
/* Called when the client registration is finished */
static void register_client_cb(int status, int client_if, bt_uuid_t *app_uuid) {
if (status == BT_STATUS_SUCCESS) {
@@ -609,7 +642,7 @@ static const btgatt_client_callbacks_t gattccbs = {
NULL, /* notify_cb */
read_characteristic_cb,
NULL, /* write_characteristic_cb */
- NULL, /* read_descriptor_cb */
+ read_descriptor_cb,
NULL, /* write_descriptor_cb */
NULL, /* execute_write_cb */
NULL, /* read_remote_rssi_cb */
diff --git a/lib/ble.h b/lib/ble.h
index d963630..10945bb 100644
--- a/lib/ble.h
+++ b/lib/ble.h
@@ -163,6 +163,7 @@ typedef struct ble_cbs {
ble_gatt_found_cb_t desc_found_cb;
ble_gatt_finished_cb_t desc_finished_cb;
ble_gatt_response_cb_t char_read_cb;
+ ble_gatt_response_cb_t desc_read_cb;
} ble_cbs_t;
/**
@@ -324,4 +325,19 @@ int ble_gatt_discover_descriptors(int conn_id, int char_id);
* @return -1 if failed to request characteristic read.
*/
int ble_gatt_read_char(int conn_id, int char_id, int auth);
+
+/**
+ * Read the value of a characteristic descriptor.
+ *
+ * There should be an active connection with the device.
+ *
+ * @param conn_id The identifier of the connected remote device.
+ * @param desc_id The identifier of the descriptor to be read.
+ * @param auth Whether or not link authentication should be requested before
+ * trying to read the characteristic: 1 request, 0 do not request.
+ *
+ * @return 0 if characteristic read has been successfully requested.
+ * @return -1 if failed to request characteristic read.
+ */
+int ble_gatt_read_desc(int conn_id, int desc_id, int auth);
#endif