diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2010-11-17 16:09:45 -0200 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2010-11-18 21:58:22 +0200 |
commit | 8022b94b0523b2bdb8a02d7d148eb58d4b189dd2 (patch) | |
tree | 8308147566fd35691f3e89efbaf8f8ee930cd4ad /attrib | |
parent | 0f8be9dbaa8b625c00cb58c9656e954bd545c5ba (diff) | |
download | bluez-8022b94b0523b2bdb8a02d7d148eb58d4b189dd2.tar.gz bluez-8022b94b0523b2bdb8a02d7d148eb58d4b189dd2.tar.xz bluez-8022b94b0523b2bdb8a02d7d148eb58d4b189dd2.zip |
Add an extra parameter in the discovery primary to specify the UUID
Extends discover primary function to perform discover by UUID. UUID
parameter defines which procedure will be executed: Discover All
Primary Services or Discover Primary Service by Service UUID.
Diffstat (limited to 'attrib')
-rw-r--r-- | attrib/client.c | 8 | ||||
-rw-r--r-- | attrib/gatt.c | 37 | ||||
-rw-r--r-- | attrib/gatt.h | 4 | ||||
-rw-r--r-- | attrib/gatttool.c | 6 |
4 files changed, 40 insertions, 15 deletions
diff --git a/attrib/client.c b/attrib/client.c index 955e6230..a851a741 100644 --- a/attrib/client.c +++ b/attrib/client.c @@ -363,8 +363,8 @@ static void connect_cb(GIOChannel *chan, GError *gerr, gpointer user_data) return; } - atid = gatt_discover_primary(gatt->attrib, 0x0001, 0xffff, primary_cb, - gatt); + atid = gatt_discover_primary(gatt->attrib, 0x0001, 0xffff, NULL, + primary_cb, gatt); if (atid == 0) goto fail; @@ -1311,8 +1311,8 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen, * the Error Code is set to Attribute Not Found. */ gatt->attrib = g_attrib_ref(gatt->attrib); - gatt->atid = gatt_discover_primary(gatt->attrib, - end + 1, 0xffff, primary_cb, gatt); + gatt->atid = gatt_discover_primary(gatt->attrib, end + 1, 0xffff, NULL, + primary_cb, gatt); done: g_attrib_unref(gatt->attrib); } diff --git a/attrib/gatt.c b/attrib/gatt.c index 24ec9904..2c87dafd 100644 --- a/attrib/gatt.c +++ b/attrib/gatt.c @@ -31,21 +31,44 @@ #include "gattrib.h" #include "gatt.h" -guint gatt_discover_primary(GAttrib *attrib, uint16_t start, - uint16_t end, GAttribResultFunc func, gpointer user_data) +guint gatt_discover_primary(GAttrib *attrib, uint16_t start, uint16_t end, + uuid_t *uuid, GAttribResultFunc func, gpointer user_data) { uint8_t pdu[ATT_DEFAULT_MTU]; - uuid_t uuid; + uuid_t prim; guint16 plen; + uint8_t op; + + sdp_uuid16_create(&prim, GATT_PRIM_SVC_UUID); + + if (uuid == NULL) { + + /* Discover all primary services */ + op = ATT_OP_READ_BY_GROUP_REQ; + plen = enc_read_by_grp_req(start, end, &prim, pdu, sizeof(pdu)); + } else { + const void *value; + int vlen; - sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID); + /* Discover primary service by service UUID */ + op = ATT_OP_FIND_BY_TYPE_REQ; + + if (uuid->type == SDP_UUID16) { + value = &uuid->value.uuid16; + vlen = sizeof(uuid->value.uuid16); + } else { + value = &uuid->value.uuid128; + vlen = sizeof(uuid->value.uuid128); + } + + plen = enc_find_by_type_req(start, end, &prim, value, vlen, + pdu, sizeof(pdu)); + } - plen = enc_read_by_grp_req(start, end, &uuid, pdu, sizeof(pdu)); if (plen == 0) return 0; - return g_attrib_send(attrib, ATT_OP_READ_BY_GROUP_REQ, - pdu, plen, func, user_data, NULL); + return g_attrib_send(attrib, op, pdu, plen, func, user_data, NULL); } guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end, diff --git a/attrib/gatt.h b/attrib/gatt.h index f1599c29..4e7d88b0 100644 --- a/attrib/gatt.h +++ b/attrib/gatt.h @@ -24,8 +24,8 @@ #define GATT_CID 4 -guint gatt_discover_primary(GAttrib *attrib, uint16_t start, - uint16_t end, GAttribResultFunc func, gpointer user_data); +guint gatt_discover_primary(GAttrib *attrib, uint16_t start, uint16_t end, + uuid_t *uuid, GAttribResultFunc func, gpointer user_data); guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end, GAttribResultFunc func, gpointer user_data); diff --git a/attrib/gatttool.c b/attrib/gatttool.c index 636e0c39..1a74edd6 100644 --- a/attrib/gatttool.c +++ b/attrib/gatttool.c @@ -200,7 +200,8 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen, * Read by Group Type Request until Error Response is received and * the Error Code is set to Attribute Not Found. */ - gatt_discover_primary(attrib, end + 1, opt_end, primary_cb, attrib); + gatt_discover_primary(attrib, end + 1, opt_end, NULL, primary_cb, + attrib); return; @@ -259,7 +260,8 @@ static gboolean primary(gpointer user_data) { GAttrib *attrib = user_data; - gatt_discover_primary(attrib, opt_start, opt_end, primary_cb, attrib); + gatt_discover_primary(attrib, opt_start, opt_end, NULL, primary_cb, + attrib); return FALSE; } |