From: chen.ganir@ti.com
To: linux-bluetooth@vger.kernel.org
Cc: Chen Ganir <chen.ganir@ti.com>
Subject: [PATCH v3 3/5] DeviceInfo: Discover Characteristics
Date: Wed, 28 Mar 2012 17:26:43 +0200 [thread overview]
Message-ID: <1332948405-1104-4-git-send-email-chen.ganir@ti.com> (raw)
In-Reply-To: <1332948405-1104-1-git-send-email-chen.ganir@ti.com>
From: Chen Ganir <chen.ganir@ti.com>
Add logic to discover all characteristics and build a
characteristic list.
---
deviceinfo/deviceinfo.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++-
deviceinfo/deviceinfo.h | 2 +-
deviceinfo/manager.c | 5 +++-
3 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/deviceinfo/deviceinfo.c b/deviceinfo/deviceinfo.c
index 8624a31..cc2b061 100644
--- a/deviceinfo/deviceinfo.c
+++ b/deviceinfo/deviceinfo.c
@@ -34,17 +34,33 @@
#include "att.h"
#include "gattrib.h"
#include "gatt.h"
+#include "log.h"
#include "deviceinfo.h"
+#define PNPID_UUID "00002a50-0000-1000-8000-00805f9b34fb"
struct deviceinfo {
struct btd_device *dev; /* Device reference */
GAttrib *attrib; /* GATT connection */
+ struct att_range *svc_range; /* DeviceInfo range */
guint attioid; /* Att watcher id */
+ GSList *chars; /* Characteristics */
};
static GSList *deviceinfoservers = NULL;
+struct characteristic {
+ struct gatt_char attr; /* Characteristic */
+ struct deviceinfo *d; /* deviceinfo where the char belongs */
+};
+
+static void char_free(gpointer user_data)
+{
+ struct characteristic *c = user_data;
+
+ g_free(c);
+}
+
static void deviceinfo_free(gpointer user_data)
{
struct deviceinfo *d = user_data;
@@ -55,7 +71,11 @@ static void deviceinfo_free(gpointer user_data)
if (d->attrib != NULL)
g_attrib_unref(d->attrib);
+ if (d->chars != NULL)
+ g_slist_free_full(d->chars, char_free);
+
btd_device_unref(d->dev);
+ g_free(d->svc_range);
g_free(d);
}
@@ -70,11 +90,40 @@ static gint cmp_device(gconstpointer a, gconstpointer b)
return -1;
}
+static void configure_deviceinfo_cb(GSList *characteristics, guint8 status,
+ gpointer user_data)
+{
+ struct deviceinfo *d = user_data;
+ GSList *l;
+
+ if (status != 0) {
+ error("Discover deviceinfo characteristics: %s",
+ att_ecode2str(status));
+ return;
+ }
+
+ for (l = characteristics; l; l = l->next) {
+ struct gatt_char *c = l->data;
+ struct characteristic *ch;
+
+ ch = g_new0(struct characteristic, 1);
+ ch->attr.handle = c->handle;
+ ch->attr.properties = c->properties;
+ ch->attr.value_handle = c->value_handle;
+ memcpy(ch->attr.uuid, c->uuid, MAX_LEN_UUID_STR + 1);
+ ch->d = d;
+
+ d->chars = g_slist_append(d->chars, ch);
+ }
+}
static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
{
struct deviceinfo *d = user_data;
d->attrib = g_attrib_ref(attrib);
+
+ gatt_discover_char(d->attrib, d->svc_range->start, d->svc_range->end,
+ NULL, configure_deviceinfo_cb, d);
}
static void attio_disconnected_cb(gpointer user_data)
@@ -85,12 +134,15 @@ static void attio_disconnected_cb(gpointer user_data)
d->attrib = NULL;
}
-int deviceinfo_register(struct btd_device *device)
+int deviceinfo_register(struct btd_device *device, struct gatt_primary *prim)
{
struct deviceinfo *d;
d = g_new0(struct deviceinfo, 1);
d->dev = btd_device_ref(device);
+ d->svc_range = g_new0(struct att_range, 1);
+ d->svc_range->start = prim->range.start;
+ d->svc_range->end = prim->range.end;
deviceinfoservers = g_slist_prepend(deviceinfoservers, d);
diff --git a/deviceinfo/deviceinfo.h b/deviceinfo/deviceinfo.h
index 0ea6ff5..7a804a5 100644
--- a/deviceinfo/deviceinfo.h
+++ b/deviceinfo/deviceinfo.h
@@ -20,5 +20,5 @@
*
*/
-int deviceinfo_register(struct btd_device *device);
+int deviceinfo_register(struct btd_device *device, struct gatt_primary *prim);
void deviceinfo_unregister(struct btd_device *device);
diff --git a/deviceinfo/manager.c b/deviceinfo/manager.c
index 025a076..c2378c2 100644
--- a/deviceinfo/manager.c
+++ b/deviceinfo/manager.c
@@ -44,6 +44,7 @@ static gint primary_uuid_cmp(gconstpointer a, gconstpointer b)
static int deviceinfo_driver_probe(struct btd_device *device, GSList *uuids)
{
+ struct gatt_primary *prim;
GSList *primaries, *l;
primaries = btd_device_get_primaries(device);
@@ -53,7 +54,9 @@ static int deviceinfo_driver_probe(struct btd_device *device, GSList *uuids)
if (l == NULL)
return -EINVAL;
- return deviceinfo_register(device);
+ prim = l->data;
+
+ return deviceinfo_register(device, prim);
}
static void deviceinfo_driver_remove(struct btd_device *device)
--
1.7.4.1
next prev parent reply other threads:[~2012-03-28 15:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-28 15:26 [PATCH v3 0/5] Add DeviceInformationService plugin chen.ganir
2012-03-28 15:26 ` [PATCH v3 1/5] Add DeviceInformation GATT Client chen.ganir
2012-03-29 10:15 ` Johan Hedberg
2012-03-28 15:26 ` [PATCH v3 2/5] DeviceInfo: Add connection logic chen.ganir
2012-03-28 15:26 ` chen.ganir [this message]
2012-03-29 10:18 ` [PATCH v3 3/5] DeviceInfo: Discover Characteristics Johan Hedberg
2012-03-28 15:26 ` [PATCH v3 4/5] Fix device version in GetProperties chen.ganir
2012-03-29 10:19 ` Johan Hedberg
2012-03-28 15:26 ` [PATCH v3 5/5] DeviceInfo: Read PNP ID chen.ganir
2012-03-29 10:22 ` Johan Hedberg
2012-03-29 10:45 ` Anderson Lizardo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1332948405-1104-4-git-send-email-chen.ganir@ti.com \
--to=chen.ganir@ti.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).