diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-06-27 21:08:56 +0300 |
---|---|---|
committer | Szymon Janc <szymon.janc@tieto.com> | 2014-06-29 14:52:36 +0200 |
commit | 02f9e6e88b3adc3d42eb5aa3e952461b340012b8 (patch) | |
tree | 2ad1ab9ed14fea723365bbb24bca4f14bf730c7b /android | |
parent | 85eb28a8d33d72e32ff24ae9d73fc4d044324d2b (diff) | |
download | bluez-02f9e6e88b3adc3d42eb5aa3e952461b340012b8.tar.gz |
android/hog: Add support for Battery Service
If primary is not provided meaning primary should be auto discovered it
probably means other primary services such as Battery Service are not
being handled either so just handle BaS as well in such case.
Diffstat (limited to 'android')
-rw-r--r-- | android/hog.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/android/hog.c b/android/hog.c index aae1f8374..f93f24697 100644 --- a/android/hog.c +++ b/android/hog.c @@ -54,6 +54,7 @@ #include "android/scpp.h" #include "android/dis.h" +#include "android/bas.h" #include "android/hog.h" #define HOG_UUID "00001812-0000-1000-8000-00805f9b34fb" @@ -93,6 +94,7 @@ struct bt_hog { uint8_t flags; struct bt_scpp *scpp; struct bt_dis *dis; + struct bt_bas *bas; }; struct report { @@ -650,6 +652,7 @@ static void hog_free(struct bt_hog *hog) { bt_scpp_unref(hog->scpp); bt_dis_unref(hog->dis); + bt_bas_unref(hog->bas); bt_uhid_unref(hog->uhid); g_slist_free_full(hog->reports, report_free); g_attrib_unref(hog->attrib); @@ -789,6 +792,18 @@ static void hog_attach_dis(struct bt_hog *hog, struct gatt_primary *primary) } } +static void hog_attach_bas(struct bt_hog *hog, struct gatt_primary *primary) +{ + if (hog->bas) { + bt_bas_attach(hog->bas, hog->attrib); + return; + } + + hog->bas = bt_bas_new(primary); + if (hog->bas) + bt_bas_attach(hog->bas, hog->attrib); +} + static void primary_cb(uint8_t status, GSList *services, void *user_data) { struct bt_hog *hog = user_data; @@ -821,6 +836,11 @@ static void primary_cb(uint8_t status, GSList *services, void *user_data) continue; } + if (strcmp(primary->uuid, BATTERY_UUID) == 0) { + hog_attach_bas(hog, primary); + continue; + } + if (strcmp(primary->uuid, HOG_UUID) == 0) hog->primary = g_memdup(primary, sizeof(*primary)); } @@ -863,6 +883,9 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt) if (hog->dis) bt_dis_attach(hog->dis, gatt); + if (hog->bas) + bt_bas_attach(hog->bas, gatt); + if (hog->reports == NULL) { gatt_discover_char(hog->attrib, primary->range.start, primary->range.end, NULL, @@ -901,6 +924,9 @@ void bt_hog_detach(struct bt_hog *hog) if (hog->dis) bt_dis_detach(hog->dis); + if (hog->bas) + bt_bas_detach(hog->bas); + g_attrib_unref(hog->attrib); hog->attrib = NULL; } |