From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 5/6] android/hog: Add support to auto discover primary if not set
Date: Mon, 2 Jun 2014 20:50:06 +0300 [thread overview]
Message-ID: <1401731407-10352-5-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1401731407-10352-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds support to auto discover primary service stopping once HoG
UUID is found.
---
android/hog.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 99 insertions(+), 1 deletion(-)
diff --git a/android/hog.c b/android/hog.c
index bfb9c17..e929d7d 100644
--- a/android/hog.c
+++ b/android/hog.c
@@ -674,7 +674,9 @@ struct bt_hog *bt_hog_new(const char *name, uint16_t vendor, uint16_t product,
hog->vendor = vendor;
hog->product = product;
hog->version = version;
- hog->primary = g_memdup(primary, sizeof(*primary));
+
+ if (primary)
+ hog->primary = g_memdup(primary, sizeof(*hog->primary));
return bt_hog_ref(hog);
}
@@ -700,6 +702,97 @@ void bt_hog_unref(struct bt_hog *hog)
hog_free(hog);
}
+static void find_included_cb(uint8_t status, GSList *services, void *user_data)
+{
+ struct bt_hog *hog = user_data;
+ struct gatt_included *include;
+ GSList *l;
+
+ DBG("");
+
+ if (hog->primary)
+ return;
+
+ if (status) {
+ const char *str = att_ecode2str(status);
+ DBG("Find included failed: %s", str);
+ return;
+ }
+
+ if (!services) {
+ DBG("No included service found");
+ return;
+ }
+
+ for (l = services; l; l = l->next) {
+ include = l->data;
+
+ if (strcmp(include->uuid, HOG_UUID) == 0)
+ break;
+
+ gatt_find_included(hog->attrib, include->range.start,
+ include->range.end, find_included_cb, hog);
+ }
+
+ if (!l)
+ return;
+
+ hog->primary = g_new0(struct gatt_primary, 1);
+ memcpy(hog->primary->uuid, include->uuid, sizeof(include->uuid));
+ memcpy(&hog->primary->range, &include->range, sizeof(include->range));
+
+ gatt_discover_char(hog->attrib, hog->primary->range.start,
+ hog->primary->range.end, NULL,
+ char_discovered_cb, hog);
+}
+
+static void primary_cb(uint8_t status, GSList *services, void *user_data)
+{
+ struct bt_hog *hog = user_data;
+ struct gatt_primary *primary;
+ GSList *l;
+
+ DBG("");
+
+ if (status) {
+ const char *str = att_ecode2str(status);
+ DBG("Discover primary failed: %s", str);
+ return;
+ }
+
+ if (!services) {
+ DBG("No primary service found");
+ return;
+ }
+
+ for (l = services; l; l = l->next) {
+ primary = l->data;
+
+ if (strcmp(primary->uuid, HOG_UUID) == 0)
+ break;
+
+ gatt_find_included(hog->attrib, primary->range.start,
+ primary->range.end, find_included_cb, hog);
+ }
+
+ if (!l) {
+ for (l = services; l; l = l->next) {
+ primary = l->data;
+
+ gatt_find_included(hog->attrib, primary->range.start,
+ primary->range.end, find_included_cb,
+ hog);
+ }
+ return;
+ }
+
+ hog->primary = g_memdup(primary, sizeof(*primary));
+
+ gatt_discover_char(hog->attrib, hog->primary->range.start,
+ hog->primary->range.end, NULL,
+ char_discovered_cb, hog);
+}
+
bool bt_hog_attach(struct bt_hog *hog, void *gatt)
{
struct gatt_primary *primary = hog->primary;
@@ -710,6 +803,11 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)
hog->attrib = g_attrib_ref(gatt);
+ if (!primary) {
+ gatt_discover_primary(hog->attrib, NULL, primary_cb, hog);
+ return true;
+ }
+
if (hog->reports == NULL) {
gatt_discover_char(hog->attrib, primary->range.start,
primary->range.end, NULL,
--
1.9.0
next prev parent reply other threads:[~2014-06-02 17:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-02 17:50 [PATCH BlueZ 1/6] android/hog: Add copy to HoG implementation from input plugin Luiz Augusto von Dentz
2014-06-02 17:50 ` [PATCH BlueZ 2/6] android/hog: Strip dependencies " Luiz Augusto von Dentz
2014-06-02 17:50 ` [PATCH BlueZ 3/6] android/gatt: Make application API public Luiz Augusto von Dentz
2014-06-02 17:50 ` [PATCH BlueZ 4/6] android/bluetooth: Add bt_is_device_le function Luiz Augusto von Dentz
2014-06-02 17:50 ` Luiz Augusto von Dentz [this message]
2014-06-02 17:50 ` [PATCH BlueZ 6/6] android/hidhost: Add support for HoG Luiz Augusto von Dentz
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=1401731407-10352-5-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.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).