android/dis: Add copy to Device Info implementation
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH v3 1/15 android/dis: Add copy to Device Info implementation
From: Luiz Augusto von Dentz <[email protected]>
---
v3: Fix passing wrong handle to g_attrib_register in ScPP
profiles/deviceinfo/deviceinfo.c => android/dis.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) copy profiles/deviceinfo/deviceinfo.c => android/dis.c (100%)
android/dis.c renamed from profiles/deviceinfo/deviceinfo.c +0 -0
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 2/15 android/dis: Strip dependencies from deviceinfo plugin
From: Luiz Augusto von Dentz <[email protected]>
This strip any dependecy from deviceinfo plugin so the code can be reused by HoG implementation.
--- android/Android.mk | 1 + android/Makefile.am | 1 + android/dis.c | 154 ++++++++++++++++++++++++---------------------------- android/dis.h | 32 +++++++++++ 4 files changed, 106 insertions(+), 82 deletions(-) create mode 100644 android/dis.h
android/Android.mk +1 -0
@@ -35,6 +35,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ bluez/android/main.c \ bluez/android/bluetooth.c \ + bluez/android/dis.c \ bluez/android/hog.c \ bluez/android/hidhost.c \ bluez/android/socket.c \
android/Makefile.am +1 -0
@@ -38,6 +38,7 @@ android_bluetoothd_SOURCES = android/main.c \ src/shared/uhid.h src/shared/uhid.c \ android/bluetooth.h android/bluetooth.c \ android/hidhost.h android/hidhost.c \ + android/dis.h android/dis.c \ android/hog.h android/hog.c \ android/ipc-common.h \ android/ipc.h android/ipc.c \
android/dis.c +72 -82
213 lines not on this page · raw message
android/dis.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2014 Intel Corporation. All rights reserved. +* +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +struct bt_dis ; + +struct bt_dis *bt_dis_new (void *primary); + +struct bt_dis *bt_dis_ref (struct bt_dis *dis); +void bt_dis_unref (struct bt_dis *dis); + +bool bt_dis_attach (struct bt_dis *dis,void *gatt); +void bt_dis_detach (struct bt_dis *dis);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 3/15 android/dis: Add bt_dis_set_notification
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Function bt_dis_set_notification can be used to set notify callback.
--- android/dis.c | 21 +++++++++++++++++++++ android/dis.h | 7 +++++++ 2 files changed, 28 insertions(+)
android/dis.c +21 -0
@@ -51,6 +51,8 @@ struct bt_dis {GAttrib *attrib;/* GATT connection */ struct gatt_primary *primary;/* Primary details */ GSList *chars;/* Characteristics */ +bt_dis_notify notify; +void *notify_data; };struct characteristic {
@@ -132,6 +134,13 @@ static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len, dis->vendor =get_le16 (&value[1 ]); dis->product =get_le16 (&value[3 ]); dis->version =get_le16 (&value[5 ]); + +DBG ("source: 0x%02X vendor: 0x%04X product: 0x%04X version: 0x%04X" , + dis->source, dis->vendor, dis->product, dis->version); + +if (dis->notify) + dis->notify (dis->source, dis->vendor, dis->product, + dis->version, dis->notify_data); }static void process_deviceinfo_char (struct characteristic *ch)
@@ -194,3 +203,15 @@ void bt_dis_detach(struct bt_dis *dis)g_attrib_unref (dis->attrib); dis->attrib =NULL ; } + +bool bt_dis_set_notification (struct bt_dis *dis,bt_dis_notify func, +void *user_data) +{ +if (!dis) +return false; + + dis->notify = func; + dis->notify_data = user_data; + +return true; +}
android/dis.h +7 -0
@@ -30,3 +30,10 @@ void bt_dis_unref(struct bt_dis *dis);bool bt_dis_attach (struct bt_dis *dis,void *gatt);void bt_dis_detach (struct bt_dis *dis); + +typedef void (*bt_dis_notify ) (uint8_t source,uint16_t vendor, +uint16_t product,uint16_t version, +void *user_data); + +bool bt_dis_set_notification (struct bt_dis *dis,bt_dis_notify func, +void *user_data);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 4/15 android/dis: Only cache the handle not all the characteristics
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/dis.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-)
android/dis.c +9 -24
@@ -44,13 +44,13 @@struct bt_dis {int ref_count; +uint16_t handle;uint8_t source;uint16_t vendor;uint16_t product;uint16_t version;GAttrib *attrib;/* GATT connection */ struct gatt_primary *primary;/* Primary details */ -GSList *chars;/* Characteristics */ bt_dis_notify notify;void *notify_data; };
@@ -65,8 +65,6 @@ static void dis_free(struct bt_dis *dis)if (dis->attrib)g_attrib_unref (dis->attrib); -g_slist_free_full (dis->chars, g_free); -g_free (dis->primary);g_free (dis); }
@@ -109,8 +107,7 @@ void bt_dis_unref(struct bt_dis *dis)static void read_pnpid_cb (guint8 status,const guint8 *pdu,guint16 len,gpointer user_data) { -struct characteristic *ch = user_data; -struct bt_dis *dis = ch->d; +struct bt_dis *dis = user_data;uint8_t value[PNP_ID_SIZE ];ssize_t vlen;
@@ -143,13 +140,6 @@ static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len, dis->version, dis->notify_data); } -static void process_deviceinfo_char (struct characteristic *ch) -{ -if (g_strcmp0 (ch->attr.uuid,PNPID_UUID ) ==0 ) -gatt_read_char (ch->d->attrib, ch->attr.value_handle, - read_pnpid_cb, ch); -} -static void configure_deviceinfo_cb (uint8_t status,GSList *characteristics,void *user_data) {
@@ -164,18 +154,12 @@ static void configure_deviceinfo_cb(uint8_t status, GSList *characteristics,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); -process_deviceinfo_char (ch); +if (strcmp (c->uuid,PNPID_UUID ) ==0 ) { + d->handle = c->value_handle; +gatt_read_char (d->attrib, d->handle, read_pnpid_cb, d); +break ; + } } }
@@ -188,7 +172,8 @@ bool bt_dis_attach(struct bt_dis *dis, void *attrib) dis->attrib =g_attrib_ref (attrib); -gatt_discover_char (dis->attrib, primary->range.start, +if (!dis->handle) +gatt_discover_char (dis->attrib, primary->range.start, primary->range.end,NULL , configure_deviceinfo_cb, dis);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 5/15 android/hog: Add support for reading device details via DIS
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
If primary is not provided meaning primary should be auto discovered it probably means other primary services such as Device Information Service are not being handled either so just handle DIS as well in such case.
--- android/hog.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 12 deletions(-)
android/hog.c +49 -12
@@ -52,6 +52,7 @@#include "btio/btio.h" +#include "android/dis.h" #include "android/hog.h" #define HOG_UUID "00001812-0000-1000-8000-00805f9b34fb"
@@ -89,6 +90,7 @@ struct bt_hog {uint16_t proto_mode_handle;uint16_t ctrlpt_handle;uint8_t flags; +struct bt_dis *dis; };struct report {
@@ -644,6 +646,7 @@ static void report_free(void *data)static void hog_free (struct bt_hog *hog) { +bt_dis_unref (hog->dis);bt_uhid_unref (hog->uhid);g_slist_free_full (hog->reports, report_free);g_attrib_unref (hog->attrib);
@@ -747,6 +750,30 @@ static void find_included_cb(uint8_t status, GSList *services, void *user_data) char_discovered_cb, hog); } +static void dis_notify (uint8_t source,uint16_t vendor,uint16_t product, +uint16_t version,void *user_data) +{ +struct bt_hog *hog = user_data; + + hog->vendor = vendor; + hog->product = product; + hog->version = version; +} + +static void hog_attach_dis (struct bt_hog *hog,struct gatt_primary *primary) +{ +if (hog->dis) { +bt_dis_attach (hog->dis, hog->attrib); +return ; + } + + hog->dis =bt_dis_new (primary); +if (hog->dis) { +bt_dis_set_notification (hog->dis, dis_notify, hog); +bt_dis_attach (hog->dis, hog->attrib); + } +} +static void primary_cb (uint8_t status,GSList *services,void *user_data) {struct bt_hog *hog = user_data;
@@ -769,26 +796,30 @@ static void primary_cb(uint8_t status, GSList *services, void *user_data)for (l = services; l; l = l->next) { primary = l->data; +if (strcmp (primary->uuid,DEVICE_INFORMATION_UUID ) ==0 ) { +hog_attach_dis (hog, primary); +continue ; + } +if (strcmp (primary->uuid,HOG_UUID ) ==0 ) -break ; + hog->primary =g_memdup (primary,sizeof (*primary)); } -if (!l) { -for (l = services; l; l = l->next) { - primary = l->data; +if (hog->primary) { +gatt_discover_char (hog->attrib, hog->primary->range.start, + hog->primary->range.end,NULL , + char_discovered_cb, hog); -gatt_find_included (hog->attrib, primary->range.start, - primary->range.end, find_included_cb, - hog); - }return ; } - hog->primary =g_memdup (primary,sizeof (*primary)); +for (l = services; l; l = l->next) { + primary = l->data; -gatt_discover_char (hog->attrib, hog->primary->range.start, - hog->primary->range.end,NULL , - char_discovered_cb, hog); +gatt_find_included (hog->attrib, primary->range.start, + primary->range.end, find_included_cb, + hog); + } }bool bt_hog_attach (struct bt_hog *hog,void *gatt)
@@ -806,6 +837,9 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)return true; } +if (hog->dis) +bt_dis_attach (hog->dis, gatt); +if (hog->reports ==NULL ) { gatt_discover_char(hog->attrib, primary->range.start, primary->range.end, NULL,
@@ -838,6 +872,9 @@ void bt_hog_detach(struct bt_hog *hog)g_attrib_unregister (hog->attrib, r->notifyid); } +if (hog->dis) +bt_dis_detach (hog->dis); +g_attrib_unref (hog->attrib); hog->attrib =NULL ; }
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 6/15 lib/uuid: Add define for Scan Parameter UUID
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- lib/uuid.h | 1 + profiles/scanparam/scan.c | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-)
lib/uuid.h +1 -0
@@ -60,6 +60,7 @@ extern "C" {#define IMMEDIATE_ALERT_UUID "00001802-0000-1000-8000-00805f9b34fb"#define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb"#define TX_POWER_UUID "00001804-0000-1000-8000-00805f9b34fb" +#define SCAN_PARAMETERS_UUID "00001813-0000-1000-8000-00805f9b34fb"#define SAP_UUID "0000112D-0000-1000-8000-00805f9b34fb"
profiles/scanparam/scan.c +0 -2
@@ -42,8 +42,6 @@#include "attrib/gatt.h" #include "src/attio.h" -#define SCAN_PARAMETERS_UUID "00001813-0000-1000-8000-00805f9b34fb" -#define SCAN_INTERVAL_WIN_UUID 0x2A4F#define SCAN_REFRESH_UUID 0x2A31
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 7/15 android/scpp: Add copy to Scan Parameter Profile implementation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- profiles/scanparam/scan.c => android/scpp.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) copy profiles/scanparam/scan.c => android/scpp.c (100%)
android/scpp.c renamed from profiles/scanparam/scan.c +0 -0
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 8/15 android/scpp: Strip dependencies from scan plugin
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This strip any dependecy from scan plugin so the code can be reused by HoG implementation.
--- android/Android.mk | 1 + android/Makefile.am | 1 + android/scpp.c | 168 ++++++++++++++++++++++++---------------------------- android/scpp.h | 32 ++++++++++ 4 files changed, 110 insertions(+), 92 deletions(-) create mode 100644 android/scpp.h
android/Android.mk +1 -0
@@ -36,6 +36,7 @@ LOCAL_SRC_FILES := \ bluez/android/main.c \ bluez/android/bluetooth.c \ bluez/android/dis.c \ + bluez/android/scpp.c \ bluez/android/hog.c \ bluez/android/hidhost.c \ bluez/android/socket.c \
android/Makefile.am +1 -0
@@ -39,6 +39,7 @@ android_bluetoothd_SOURCES = android/main.c \ android/bluetooth.h android/bluetooth.c \ android/hidhost.h android/hidhost.c \ android/dis.h android/dis.c \ + android/scpp.h android/scpp.c \ android/hog.h android/hog.c \ android/ipc-common.h \ android/ipc.h android/ipc.c \
android/scpp.c +76 -92
251 lines not on this page · raw message
android/scpp.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2014 Intel Corporation. All rights reserved. +* +* +* This library is free software; you can rescpptribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is scpptributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +struct bt_scpp ; + +struct bt_scpp *bt_scpp_new (void *primary); + +struct bt_scpp *bt_scpp_ref (struct bt_scpp *scan); +void bt_scpp_unref (struct bt_scpp *scan); + +bool bt_scpp_attach (struct bt_scpp *scan,void *gatt); +void bt_scpp_detach (struct bt_scpp *scan);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 9/15 android/scpp: Add bt_scpp_set_interval and bt_scpp_set_window
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
These functions can be used to change the current values.
--- android/scpp.c | 43 +++++++++++++++++++++++++++++++++++++------ android/scpp.h | 3 +++ 2 files changed, 40 insertions(+), 6 deletions(-)
android/scpp.c +37 -6
@@ -77,6 +77,9 @@ struct bt_scpp *bt_scpp_new(void *primary)if (!scan)return NULL ; + scan->interval =SCAN_INTERVAL ; + scan->window =SCAN_WINDOW ; +if (primary) scan->primary =g_memdup (primary,sizeof (*scan->primary));
@@ -104,12 +107,13 @@ void bt_scpp_unref(struct bt_scpp *scan)scpp_free (scan); } -static void write_scan_params (GAttrib *attrib,uint16_t handle) +static void write_scan_params (GAttrib *attrib,uint16_t handle, +uint16_t interval,uint16_t window) {uint8_t value[4 ]; -put_le16 (SCAN_INTERVAL , &value[0 ]); -put_le16 (SCAN_WINDOW , &value[2 ]); +put_le16 (interval, &value[0 ]); +put_le16 (window, &value[2 ]);gatt_write_cmd (attrib, handle, value,sizeof (value),NULL ,NULL ); }
@@ -122,7 +126,8 @@ static void refresh_value_cb(const uint8_t *pdu, uint16_t len,DBG ("Server requires refresh: %d" , pdu[3 ]);if (pdu[3 ] ==SERVER_REQUIRES_REFRESH ) -write_scan_params (scan->attrib, scan->iwhandle); +write_scan_params (scan->attrib, scan->iwhandle, scan->interval, + scan->window); } static void ccc_written_cb(guint8 status, const guint8 *pdu,
@@ -215,7 +220,8 @@ static void iwin_discovered_cb(uint8_t status, GSList *chars, void *user_data)DBG ("Scan Interval Window handle: 0x%04x" , scan->iwhandle); -write_scan_params (scan->attrib, scan->iwhandle); +write_scan_params (scan->attrib, scan->iwhandle, scan->interval, + scan->window); }bool bt_scpp_attach (struct bt_scpp *scan,void *attrib)
@@ -228,7 +234,8 @@ bool bt_scpp_attach(struct bt_scpp *scan, void *attrib) scan->attrib =g_attrib_ref (attrib);if (scan->iwhandle) { -write_scan_params (scan->attrib, scan->iwhandle); +write_scan_params (scan->attrib, scan->iwhandle, scan->interval, + scan->window);return true; }
@@ -254,3 +261,27 @@ void bt_scpp_detach(struct bt_scpp *scan)g_attrib_unref (scan->attrib); scan->attrib =NULL ; } + +bool bt_scpp_set_interval (struct bt_scpp *scan,uint16_t value) +{ +if (!scan) +return false; + +/* TODO: Check valid range */ + + scan->interval = value; + +return true; +} + +bool bt_scpp_set_window (struct bt_scpp *scan,uint16_t value) +{ +if (!scan) +return false; + +/* TODO: Check valid range */ + + scan->window = value; + +return true; +}
android/scpp.h +3 -0
@@ -30,3 +30,6 @@ void bt_scpp_unref(struct bt_scpp *scan);bool bt_scpp_attach (struct bt_scpp *scan,void *gatt);void bt_scpp_detach (struct bt_scpp *scan); + +bool bt_scpp_set_interval (struct bt_scpp *scan,uint16_t value); +bool bt_scpp_set_window (struct bt_scpp *scan,uint16_t value);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 10/15 android/scpp: Check for cached handles on attach
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/scpp.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-)
android/scpp.c +28 -16
@@ -148,12 +148,22 @@ static void ccc_written_cb(guint8 status, const guint8 *pdu, refresh_value_cb, scan, NULL); } +static void write_ccc (GAttrib *attrib,uint16_t handle,void *user_data) +{ +uint8_t value[2 ]; + +put_le16 (GATT_CLIENT_CHARAC_CFG_NOTIF_BIT , value); + +gatt_write_char (attrib, handle, value,sizeof (value), ccc_written_cb, + user_data); +} +static void discover_descriptor_cb (uint8_t status,GSList *descs,void *user_data) {struct bt_scpp *scan = user_data;struct gatt_desc *desc; -uint8_t value[2 ]; +if (status !=0 ) {error ("Discover descriptors failed: %s" ,att_ecode2str (status));
@@ -163,9 +173,7 @@ static void discover_descriptor_cb(uint8_t status, GSList *descs,/* There will be only one descriptor on list and it will be CCC */ desc = descs->data; -put_le16 (GATT_CLIENT_CHARAC_CFG_NOTIF_BIT , value); -gatt_write_char (scan->attrib, desc->handle, value,sizeof (value), - ccc_written_cb, user_data); +write_ccc (scan->attrib, desc->handle, scan); } static void refresh_discovered_cb(uint8_t status, GSList *chars,
@@ -233,22 +241,26 @@ bool bt_scpp_attach(struct bt_scpp *scan, void *attrib) scan->attrib =g_attrib_ref (attrib); -if (scan->iwhandle) { +if (scan->iwhandle)write_scan_params (scan->attrib, scan->iwhandle, scan->interval, scan->window); -return true; +else { +bt_uuid16_create (&iwin_uuid,SCAN_INTERVAL_WIN_UUID ); +gatt_discover_char (scan->attrib, scan->primary->range.start, + scan->primary->range.end, &iwin_uuid, + iwin_discovered_cb, scan); } -bt_uuid16_create (&iwin_uuid,SCAN_INTERVAL_WIN_UUID ); -bt_uuid16_create (&refresh_uuid,SCAN_REFRESH_UUID ); - -gatt_discover_char (scan->attrib, scan->primary->range.start, - scan->primary->range.end, &iwin_uuid, - iwin_discovered_cb, scan); - -gatt_discover_char (scan->attrib, scan->primary->range.start, - scan->primary->range.end, &refresh_uuid, - refresh_discovered_cb, scan); +if (scan->refresh_handle) + scan->refresh_cb_id =g_attrib_register (scan->attrib, +ATT_OP_HANDLE_NOTIFY , scan->refresh_handle, + refresh_value_cb, scan,NULL ); +else { +bt_uuid16_create (&refresh_uuid,SCAN_REFRESH_UUID ); +gatt_discover_char (scan->attrib, scan->primary->range.start, + scan->primary->range.end, &refresh_uuid, + refresh_discovered_cb, scan); + }return true; }
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 11/15 android/hog: Add support for Scan Parameter Service
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
If primary is not provided meaning primary should be auto discovered it probably means other primary services such as Scan Parameter Profile are not being handled either so just handle ScPP as well in such case.
--- android/hog.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
android/hog.c +26 -0
@@ -53,6 +53,7 @@#include "btio/btio.h" #include "android/dis.h" +#include "android/scpp.h" #include "android/hog.h" #define HOG_UUID "00001812-0000-1000-8000-00805f9b34fb"
@@ -91,6 +92,7 @@ struct bt_hog {uint16_t ctrlpt_handle;uint8_t flags;struct bt_dis *dis; +struct bt_scpp *scpp; };struct report {
@@ -647,6 +649,7 @@ static void report_free(void *data)static void hog_free (struct bt_hog *hog) {bt_dis_unref (hog->dis); +bt_scpp_unref (hog->scpp);bt_uhid_unref (hog->uhid);g_slist_free_full (hog->reports, report_free);g_attrib_unref (hog->attrib);
@@ -774,6 +777,18 @@ static void hog_attach_dis(struct bt_hog *hog, struct gatt_primary *primary) } } +static void hog_attach_scpp (struct bt_hog *hog,struct gatt_primary *primary) +{ +if (hog->scpp) { +bt_scpp_attach (hog->scpp, hog->attrib); +return ; + } + + hog->scpp =bt_scpp_new (primary); +if (hog->scpp) +bt_scpp_attach (hog->scpp, hog->attrib); +} +static void primary_cb (uint8_t status,GSList *services,void *user_data) {struct bt_hog *hog = user_data;
@@ -801,6 +816,11 @@ static void primary_cb(uint8_t status, GSList *services, void *user_data)continue ; } +if (strcmp (primary->uuid,SCAN_PARAMETERS_UUID ) ==0 ) { +hog_attach_scpp (hog, primary); +continue ; + } +if (strcmp (primary->uuid,HOG_UUID ) ==0 ) hog->primary =g_memdup (primary,sizeof (*primary)); }
@@ -840,6 +860,9 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)if (hog->dis)bt_dis_attach (hog->dis, gatt); +if (hog->scpp) +bt_scpp_attach (hog->scpp, gatt); +if (hog->reports ==NULL ) { gatt_discover_char(hog->attrib, primary->range.start, primary->range.end, NULL,
@@ -875,6 +898,9 @@ void bt_hog_detach(struct bt_hog *hog)if (hog->dis)bt_dis_detach (hog->dis); +if (hog->scpp) +bt_scpp_detach (hog->scpp); +g_attrib_unref (hog->attrib); hog->attrib =NULL ; }
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 12/15 android: Add initial implementation of Battery Service client
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/Android.mk | 1 + android/Makefile.am | 1 + android/bas.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++ android/bas.h | 32 ++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 android/bas.c create mode 100644 android/bas.h
android/Android.mk +1 -0
@@ -37,6 +37,7 @@ LOCAL_SRC_FILES := \ bluez/android/bluetooth.c \ bluez/android/dis.c \ bluez/android/scpp.c \ + bluez/android/bas.c \ bluez/android/hog.c \ bluez/android/hidhost.c \ bluez/android/socket.c \
android/Makefile.am +1 -0
@@ -40,6 +40,7 @@ android_bluetoothd_SOURCES = android/main.c \ android/hidhost.h android/hidhost.c \ android/dis.h android/dis.c \ android/scpp.h android/scpp.c \ + android/bas.h android/bas.c \ android/hog.h android/hog.c \ android/ipc-common.h \ android/ipc.h android/ipc.c \
android/bas.c new file +137 -0
137 lines not on this page · raw message
android/bas.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2014 Intel Corporation. All rights reserved. +* +* +* This library is free software; you can rebastribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is bastributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +struct bt_bas ; + +struct bt_bas *bt_bas_new (void *primary); + +struct bt_bas *bt_bas_ref (struct bt_bas *bas); +void bt_bas_unref (struct bt_bas *bas); + +bool bt_bas_attach (struct bt_bas *bas,void *gatt); +void bt_bas_detach (struct bt_bas *bas);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 13/15 lib/uuid: Add define for Battery UUID
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- lib/uuid.h | 1 + 1 file changed, 1 insertion(+)
lib/uuid.h +1 -0
@@ -60,6 +60,7 @@ extern "C" {#define IMMEDIATE_ALERT_UUID "00001802-0000-1000-8000-00805f9b34fb"#define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb"#define TX_POWER_UUID "00001804-0000-1000-8000-00805f9b34fb" +#define BATTERY_UUID "0000180f-0000-1000-8000-00805f9b34fb"#define SCAN_PARAMETERS_UUID "00001813-0000-1000-8000-00805f9b34fb"#define SAP_UUID "0000112D-0000-1000-8000-00805f9b34fb"
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 14/15 android/hog: Add support for Battery Service
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
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.
--- android/hog.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
android/hog.c +26 -0
@@ -54,6 +54,7 @@#include "android/dis.h" #include "android/scpp.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_dis *dis;struct bt_scpp *scpp; +struct bt_bas *bas; };struct report {
@@ -650,6 +652,7 @@ static void hog_free(struct bt_hog *hog) {bt_dis_unref (hog->dis);bt_scpp_unref (hog->scpp); +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_scpp(struct bt_hog *hog, struct gatt_primary *primary)bt_scpp_attach (hog->scpp, hog->attrib); } +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->scpp)bt_scpp_attach (hog->scpp, 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->scpp)bt_scpp_detach (hog->scpp); +if (hog->bas) +bt_bas_detach (hog->bas); +g_attrib_unref (hog->attrib); hog->attrib =NULL ; }
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH v3 15/15 android/hog: Add support for multiple instaces
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This is necessary to pass PTS tests which does include 2 instances.
--- android/hog.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-)
android/hog.c +40 -8
@@ -95,6 +95,7 @@ struct bt_hog {struct bt_dis *dis;struct bt_scpp *scpp;struct bt_bas *bas; +GSList *instances; };struct report {
@@ -648,8 +649,11 @@ static void report_free(void *data)g_free (report); } -static void hog_free (struct bt_hog *hog) +static void hog_free (void *data) { +struct bt_hog *hog = data; + +g_slist_free_full (hog->instances, hog_free);bt_dis_unref (hog->dis);bt_scpp_unref (hog->scpp);bt_bas_unref (hog->bas);
@@ -804,6 +808,27 @@ static void hog_attach_bas(struct bt_hog *hog, struct gatt_primary *primary)bt_bas_attach (hog->bas, hog->attrib); } +static void hog_attach_hog (struct bt_hog *hog,struct gatt_primary *primary) +{ +struct bt_hog *instance; + +if (!hog->primary) { + hog->primary =g_memdup (primary,sizeof (*primary)); +gatt_discover_char (hog->attrib, primary->range.start, + primary->range.end,NULL , + char_discovered_cb, hog); +return ; + } + + instance =bt_hog_new (hog->name, hog->vendor, hog->product, + hog->version, primary); +if (!instance) +return ; + +bt_hog_attach (instance, hog->attrib); + hog->instances =g_slist_append (hog->instances, instance); +} +static void primary_cb (uint8_t status,GSList *services,void *user_data) {struct bt_hog *hog = user_data;
@@ -842,16 +867,11 @@ static void primary_cb(uint8_t status, GSList *services, void *user_data) }if (strcmp (primary->uuid,HOG_UUID ) ==0 ) - hog->primary =g_memdup (primary,sizeof (*primary)); +hog_attach_hog (hog, primary); } -if (hog->primary) { -gatt_discover_char (hog->attrib, hog->primary->range.start, - hog->primary->range.end,NULL , - char_discovered_cb, hog); - +if (hog->primary)return ; - }for (l = services; l; l = l->next) { primary = l->data;
@@ -886,6 +906,12 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)if (hog->bas)bt_bas_attach (hog->bas, gatt); +for (l = hog->instances; l; l = l->next) { +struct bt_hog *instance = l->data; + +bt_hog_attach (instance, gatt); + } +if (hog->reports ==NULL ) { gatt_discover_char(hog->attrib, primary->range.start, primary->range.end, NULL,
@@ -912,6 +938,12 @@ void bt_hog_detach(struct bt_hog *hog)if (!hog->attrib)return ; +for (l = hog->instances; l; l = l->next) { +struct bt_hog *instance = l->data; + +bt_hog_detach (instance); + } +for (l = hog->reports; l; l = l->next) {struct report *r = l->data;
Signature · 1 line
1.9.3
Hi Luiz,
android/dis.c
Quoted 13 lines · On Friday 27 of June 2014 11:27:45 Luiz Augusto von Dentz wrote:
From: Luiz Augusto von Dentz <[email protected]>
---
v3: Fix passing wrong handle tog_attrib_registerin ScPPprofiles/deviceinfo/deviceinfo.c => android/dis.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) copy profiles/deviceinfo/deviceinfo.c => android/dis.c (100%)android/dis.c renamed from profiles/deviceinfo/deviceinfo.c +0
-0
ScPP related patches (6-11) are now applied. Thanks.
Signature · 2 lines
Best regards, Szymon Janc