linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Add support for registering local SDP records
@ 2013-11-12 15:36 Szymon Janc
  2013-11-12 15:36 ` [PATCH v3 1/5] android: Add and remove sdp records and uuids Szymon Janc
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 15:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

v3:
 - fixed Johan comments

V2:
 - don't use bt_uuid_t
 - few bugfixes

V1 cover:
This adds support for manipulating local SDP database with
bt_adapter_add_record and bt_adapter_remove_record functions. Those should
be called when HAL service is registered or unregistered.

This also adds DeviceID record as at least 1 local UUID is needed by Android to
properly handle remote device profiles.

Last but not least: With this serie it is possible to connect HID device from
Android UI (Settings application).   \O/

-- 
BR
Szymon Janc

Marcin Kraglak (3):
  android: Add and remove sdp records and uuids
  android: Clear adapter uuids during initialization
  android: Add support for getting UUIDs property

Szymon Janc (2):
  android: Remove not needed include
  android: Register DeviceID record when adapter is initialized

 android/adapter.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 android/adapter.h |   3 +
 2 files changed, 192 insertions(+), 13 deletions(-)

-- 
1.8.4.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/5] android: Add and remove sdp records and uuids
  2013-11-12 15:36 [PATCH v3 0/5] Add support for registering local SDP records Szymon Janc
@ 2013-11-12 15:36 ` Szymon Janc
  2013-11-12 15:36 ` [PATCH v3 2/5] android: Remove not needed include Szymon Janc
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 15:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak

From: Marcin Kraglak <marcin.kraglak@tieto.com>

This is api for adding and removing sdp records and uuids
via mgmt interface. Local profiles have to store handle to
own records to remove them in cleanup. Additionally list of
uuids is created in bt_adapter struct.
---
 android/adapter.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 android/adapter.h |   3 ++
 2 files changed, 116 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 65b3170..ac5878b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -40,6 +40,7 @@
 #include "lib/sdp_lib.h"
 #include "lib/uuid.h"
 #include "src/sdp-client.h"
+#include "src/sdpd.h"
 #include "log.h"
 #include "hal-msg.h"
 #include "ipc.h"
@@ -74,6 +75,7 @@ struct bt_adapter {
 
 	bool discovering;
 	uint32_t discoverable_timeout;
+	GSList *uuids;
 };
 
 struct browse_req {
@@ -986,6 +988,117 @@ static void load_link_keys(GSList *keys)
 	}
 }
 
+/* output uint128 is in host order */
+static void uuid16_to_uint128(uint16_t uuid, uint128_t *u128)
+{
+	uuid_t uuid16, uuid128;
+
+	sdp_uuid16_create(&uuid16, uuid);
+	sdp_uuid16_to_uuid128(&uuid128, &uuid16);
+
+	ntoh128(&uuid128.value.uuid128, u128);
+}
+
+static void remove_uuid_complete(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	if (status != MGMT_STATUS_SUCCESS) {
+		error("Failed to remove UUID: %s (0x%02x)",
+						mgmt_errstr(status), status);
+		return;
+	}
+
+	mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+}
+
+static void remove_uuid(uint16_t uuid)
+{
+	uint128_t uint128;
+	struct mgmt_cp_remove_uuid cp;
+
+	uuid16_to_uint128(uuid, &uint128);
+	htob128(&uint128, (uint128_t *) cp.uuid);
+
+	mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_UUID,
+				adapter->index, sizeof(cp), &cp,
+				remove_uuid_complete, NULL, NULL);
+}
+
+static void add_uuid_complete(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	if (status != MGMT_STATUS_SUCCESS) {
+		error("Failed to add UUID: %s (0x%02x)",
+						mgmt_errstr(status), status);
+		return;
+	}
+
+	mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+}
+
+static void add_uuid(uint8_t svc_hint, uint16_t uuid)
+{
+	uint128_t uint128;
+	struct mgmt_cp_add_uuid cp;
+
+	uuid16_to_uint128(uuid, &uint128);
+
+	htob128(&uint128, (uint128_t *) cp.uuid);
+	cp.svc_hint = svc_hint;
+
+	mgmt_send(adapter->mgmt, MGMT_OP_ADD_UUID,
+				adapter->index, sizeof(cp), &cp,
+				add_uuid_complete, NULL, NULL);
+}
+
+int bt_adapter_add_record(sdp_record_t *rec, uint8_t svc_hint)
+{
+	uint16_t uuid;
+
+	/* TODO support all types? */
+	if (rec->svclass.type != SDP_UUID16) {
+		warn("Ignoring unsupported UUID type");
+		return -EINVAL;
+	}
+
+	uuid = rec->svclass.value.uuid16;
+
+	if (g_slist_find(adapter->uuids, GUINT_TO_POINTER(uuid))) {
+		DBG("UUID 0x%x already added", uuid);
+		return -EALREADY;
+	}
+
+	adapter->uuids = g_slist_prepend(adapter->uuids,
+						GUINT_TO_POINTER(uuid));
+
+	add_uuid(svc_hint, uuid);
+
+	return add_record_to_server(&adapter->bdaddr, rec);
+}
+
+void bt_adapter_remove_record(uint32_t handle)
+{
+	sdp_record_t *rec;
+	GSList *uuid_found;
+	uint16_t uuid;
+
+	rec = sdp_record_find(handle);
+	if (!rec)
+		return;
+
+	uuid = rec->svclass.value.uuid16;
+
+	uuid_found = g_slist_find(adapter->uuids, GUINT_TO_POINTER(uuid));
+	if (uuid_found) {
+		remove_uuid(uuid);
+
+		adapter->uuids = g_slist_remove(adapter->uuids,
+							uuid_found->data);
+	}
+
+	remove_record_from_server(handle);
+}
+
 static void set_mode_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
diff --git a/android/adapter.h b/android/adapter.h
index c62b859..0e84cb0 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -32,3 +32,6 @@ const bdaddr_t *bt_adapter_get_address(void);
 
 bool bt_adapter_register(int sk);
 void bt_adapter_unregister(void);
+
+int bt_adapter_add_record(sdp_record_t *rec, uint8_t svc_hint);
+void bt_adapter_remove_record(uint32_t handle);
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 2/5] android: Remove not needed include
  2013-11-12 15:36 [PATCH v3 0/5] Add support for registering local SDP records Szymon Janc
  2013-11-12 15:36 ` [PATCH v3 1/5] android: Add and remove sdp records and uuids Szymon Janc
@ 2013-11-12 15:36 ` Szymon Janc
  2013-11-12 15:36 ` [PATCH v3 3/5] android: Clear adapter uuids during initialization Szymon Janc
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 15:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

bt_uuid_t is not used so lib/uuid.h doesn't need to be included.
---
 android/adapter.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/android/adapter.c b/android/adapter.c
index ac5878b..92949f9 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -38,7 +38,6 @@
 #include "src/eir.h"
 #include "lib/sdp.h"
 #include "lib/sdp_lib.h"
-#include "lib/uuid.h"
 #include "src/sdp-client.h"
 #include "src/sdpd.h"
 #include "log.h"
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 3/5] android: Clear adapter uuids during initialization
  2013-11-12 15:36 [PATCH v3 0/5] Add support for registering local SDP records Szymon Janc
  2013-11-12 15:36 ` [PATCH v3 1/5] android: Add and remove sdp records and uuids Szymon Janc
  2013-11-12 15:36 ` [PATCH v3 2/5] android: Remove not needed include Szymon Janc
@ 2013-11-12 15:36 ` Szymon Janc
  2013-11-12 15:36 ` [PATCH v3 4/5] android: Add support for getting UUIDs property Szymon Janc
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 15:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak

From: Marcin Kraglak <marcin.kraglak@tieto.com>

Clear adapter uuids during init. We have to do it before
other profiles will be able to register sdp records and add
their uuids.
---
 android/adapter.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 92949f9..a42cdcb 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1208,6 +1208,17 @@ static uint8_t set_discoverable_timeout(uint8_t *timeout)
 
 	return HAL_STATUS_SUCCESS;
 }
+
+static void clear_uuids(void)
+{
+	struct mgmt_cp_remove_uuid cp;
+
+	memset(&cp, 0, sizeof(cp));
+
+	mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_UUID, adapter->index,
+					sizeof(cp), &cp, NULL, NULL, NULL);
+}
+
 static void read_info_complete(uint8_t status, uint16_t length, const void *param,
 							void *user_data)
 {
@@ -1248,6 +1259,8 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
 	/* TODO: Register all event notification handlers */
 	register_mgmt_handlers();
 
+	clear_uuids();
+
 	load_link_keys(NULL);
 
 	set_io_capability();
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 4/5] android: Add support for getting UUIDs property
  2013-11-12 15:36 [PATCH v3 0/5] Add support for registering local SDP records Szymon Janc
                   ` (2 preceding siblings ...)
  2013-11-12 15:36 ` [PATCH v3 3/5] android: Clear adapter uuids during initialization Szymon Janc
@ 2013-11-12 15:36 ` Szymon Janc
  2013-11-12 15:36 ` [PATCH v3 5/5] android: Register DeviceID record when adapter is initialized Szymon Janc
  2013-11-12 17:00 ` [PATCH v3 0/5] Add support for registering local SDP records Johan Hedberg
  5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 15:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak

From: Marcin Kraglak <marcin.kraglak@tieto.com>

This method will call adapter_properties_cb with uuids of
adapter. Method is called also when uuid is added or removed.
---
 android/adapter.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 47 insertions(+), 8 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index a42cdcb..2c95e54 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -998,6 +998,45 @@ static void uuid16_to_uint128(uint16_t uuid, uint128_t *u128)
 	ntoh128(&uuid128.value.uuid128, u128);
 }
 
+static bool get_uuids(void)
+{
+	struct hal_ev_adapter_props_changed *ev;
+	GSList *list = adapter->uuids;
+	unsigned int uuid_count = g_slist_length(list);
+	int len = uuid_count * sizeof(uint128_t);
+	uint8_t buf[BASELEN_PROP_CHANGED + len];
+	uint8_t *p;
+	int i;
+
+	memset(buf, 0, sizeof(buf));
+	ev = (void *) buf;
+
+	ev->num_props = 1;
+	ev->status = HAL_STATUS_SUCCESS;
+
+	ev->props[0].type = HAL_PROP_ADAPTER_UUIDS;
+	ev->props[0].len = len;
+	p = ev->props->val;
+
+	for (; list; list = g_slist_next(list)) {
+		uint16_t uuid = GPOINTER_TO_UINT(list->data);
+		uint128_t uint128;
+
+		uuid16_to_uint128(uuid, &uint128);
+
+		/* Android expects swapped bytes in uuid */
+		for (i = 0; i < 16; i++)
+			p[15 - i] = uint128.data[i];
+
+		p += sizeof(uint128_t);
+	}
+
+	ipc_send(notification_sk, HAL_SERVICE_ID_BLUETOOTH,
+			HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev, -1);
+
+	return true;
+}
+
 static void remove_uuid_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -1008,6 +1047,10 @@ static void remove_uuid_complete(uint8_t status, uint16_t length,
 	}
 
 	mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+
+	/* send notification only if bluetooth service is registered */
+	if (notification_sk >= 0)
+		get_uuids();
 }
 
 static void remove_uuid(uint16_t uuid)
@@ -1033,6 +1076,10 @@ static void add_uuid_complete(uint8_t status, uint16_t length,
 	}
 
 	mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+
+	/* send notification only if bluetooth service is registered */
+	if (notification_sk >= 0)
+		get_uuids();
 }
 
 static void add_uuid(uint8_t svc_hint, uint16_t uuid)
@@ -1346,14 +1393,6 @@ static bool get_name(void)
 	return true;
 }
 
-static bool get_uuids(void)
-{
-	DBG("Not implemented");
-
-	/* TODO: Add implementation */
-
-	return false;
-}
 
 static bool get_class(void)
 {
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 5/5] android: Register DeviceID record when adapter is initialized
  2013-11-12 15:36 [PATCH v3 0/5] Add support for registering local SDP records Szymon Janc
                   ` (3 preceding siblings ...)
  2013-11-12 15:36 ` [PATCH v3 4/5] android: Add support for getting UUIDs property Szymon Janc
@ 2013-11-12 15:36 ` Szymon Janc
  2013-11-12 17:00 ` [PATCH v3 0/5] Add support for registering local SDP records Johan Hedberg
  5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 15:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Register DeviceID SDP record and update local UUIDs after DeviceID
information is passed to kernel.
---
 android/adapter.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 2c95e54..2fd6aeb 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -46,6 +46,10 @@
 #include "utils.h"
 #include "adapter.h"
 
+#define DEVICE_ID_SOURCE	0x0002	/* USB */
+#define DEVICE_ID_VENDOR	0x1d6b	/* Linux Foundation */
+#define DEVICE_ID_PRODUCT	0x0247	/* BlueZ for Android */
+
 /* Default to DisplayYesNo */
 #define DEFAULT_IO_CAPABILITY 0x01
 /* Default discoverable timeout 120sec as in Android */
@@ -1197,20 +1201,28 @@ static void set_device_id(void)
 {
 	struct mgmt_cp_set_device_id cp;
 	uint8_t major, minor;
+	uint16_t version;
 
 	if (sscanf(VERSION, "%hhu.%hhu", &major, &minor) != 2)
 		return;
 
+	version = major << 8 | minor;
+
 	memset(&cp, 0, sizeof(cp));
-	cp.source = htobs(0x0002);		/* USB */
-	cp.vendor = htobs(0x1d6b);		/* Linux Foundation */
-	cp.product = htobs(0x0247);		/* BlueZ for Android */
-	cp.version = htobs(major << 8 | minor);
+	cp.source = htobs(DEVICE_ID_SOURCE);
+	cp.vendor = htobs(DEVICE_ID_VENDOR);
+	cp.product = htobs(DEVICE_ID_PRODUCT);
+	cp.version = htobs(version);
 
 	if (mgmt_send(adapter->mgmt, MGMT_OP_SET_DEVICE_ID,
 				adapter->index, sizeof(cp), &cp,
 				NULL, NULL, NULL) == 0)
 		error("Failed to set device id");
+
+	register_device_id(DEVICE_ID_SOURCE, DEVICE_ID_VENDOR,
+						DEVICE_ID_PRODUCT, version);
+
+	bt_adapter_add_record(sdp_record_find(0x10000), 0x00);
 }
 
 static void set_adapter_name_complete(uint8_t status, uint16_t length,
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/5] Add support for registering local SDP records
  2013-11-12 15:36 [PATCH v3 0/5] Add support for registering local SDP records Szymon Janc
                   ` (4 preceding siblings ...)
  2013-11-12 15:36 ` [PATCH v3 5/5] android: Register DeviceID record when adapter is initialized Szymon Janc
@ 2013-11-12 17:00 ` Johan Hedberg
  5 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2013-11-12 17:00 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth

Hi Szymon,

On Tue, Nov 12, 2013, Szymon Janc wrote:
> v3:
>  - fixed Johan comments
> 
> V2:
>  - don't use bt_uuid_t
>  - few bugfixes
> 
> V1 cover:
> This adds support for manipulating local SDP database with
> bt_adapter_add_record and bt_adapter_remove_record functions. Those should
> be called when HAL service is registered or unregistered.
> 
> This also adds DeviceID record as at least 1 local UUID is needed by Android to
> properly handle remote device profiles.
> 
> Last but not least: With this serie it is possible to connect HID device from
> Android UI (Settings application).   \O/
> 
> -- 
> BR
> Szymon Janc
> 
> Marcin Kraglak (3):
>   android: Add and remove sdp records and uuids
>   android: Clear adapter uuids during initialization
>   android: Add support for getting UUIDs property
> 
> Szymon Janc (2):
>   android: Remove not needed include
>   android: Register DeviceID record when adapter is initialized
> 
>  android/adapter.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++----
>  android/adapter.h |   3 +
>  2 files changed, 192 insertions(+), 13 deletions(-)

All five patches have been applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-11-12 17:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-12 15:36 [PATCH v3 0/5] Add support for registering local SDP records Szymon Janc
2013-11-12 15:36 ` [PATCH v3 1/5] android: Add and remove sdp records and uuids Szymon Janc
2013-11-12 15:36 ` [PATCH v3 2/5] android: Remove not needed include Szymon Janc
2013-11-12 15:36 ` [PATCH v3 3/5] android: Clear adapter uuids during initialization Szymon Janc
2013-11-12 15:36 ` [PATCH v3 4/5] android: Add support for getting UUIDs property Szymon Janc
2013-11-12 15:36 ` [PATCH v3 5/5] android: Register DeviceID record when adapter is initialized Szymon Janc
2013-11-12 17:00 ` [PATCH v3 0/5] Add support for registering local SDP records Johan Hedberg

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).