* [PATCH v2 0/5] Add support for registering local SDP records
@ 2013-11-12 12:06 Szymon Janc
2013-11-12 12:06 ` [PATCH v2 1/5] android: Add and remove sdp records and uuids Szymon Janc
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 12:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
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 | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++----
android/adapter.h | 3 +
2 files changed, 178 insertions(+), 13 deletions(-)
--
1.8.4.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/5] android: Add and remove sdp records and uuids
2013-11-12 12:06 [PATCH v2 0/5] Add support for registering local SDP records Szymon Janc
@ 2013-11-12 12:06 ` Szymon Janc
2013-11-12 13:24 ` Johan Hedberg
2013-11-12 12:06 ` [PATCH v2 2/5] android: Remove not needed include Szymon Janc
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 12:06 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 | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 3 ++
2 files changed, 101 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 65b3170..b053043 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,102 @@ 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(uint128_t *uuid)
+{
+ struct mgmt_cp_remove_uuid cp;
+
+ htob128(uuid, (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, uint128_t *uuid)
+{
+ struct mgmt_cp_add_uuid cp;
+
+ htob128(uuid, (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(uint16_t uuid, sdp_record_t *rec, uint8_t svc_hint)
+{
+ uint128_t uint128;
+
+ if (g_slist_find(adapter->uuids, GUINT_TO_POINTER(uuid))) {
+ DBG("UUID 0x%x already added", uuid);
+ return -1;
+ }
+
+ adapter->uuids = g_slist_prepend(adapter->uuids,
+ GUINT_TO_POINTER(uuid));
+
+ uuid16_to_uint128(uuid, &uint128);
+
+ add_uuid(svc_hint, &uint128);
+
+ return add_record_to_server(&adapter->bdaddr, rec);
+}
+
+void bt_adapter_remove_record(uint16_t uuid, int handle)
+{
+ GSList *uuid_found;
+
+ uuid_found = g_slist_find(adapter->uuids, GUINT_TO_POINTER(uuid));
+ if (uuid_found) {
+ uint128_t uint128;
+
+ uuid16_to_uint128(uuid, &uint128);
+
+ remove_uuid(&uint128);
+
+ 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..4c3100f 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(uint16_t uuid, sdp_record_t *rec, uint8_t svc_hint);
+void bt_adapter_remove_record(uint16_t uuid, int handle);
--
1.8.4.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/5] android: Remove not needed include
2013-11-12 12:06 [PATCH v2 0/5] Add support for registering local SDP records Szymon Janc
2013-11-12 12:06 ` [PATCH v2 1/5] android: Add and remove sdp records and uuids Szymon Janc
@ 2013-11-12 12:06 ` Szymon Janc
2013-11-12 12:06 ` [PATCH v2 3/5] android: Clear adapter uuids during initialization Szymon Janc
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 12:06 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 b053043..bda8e20 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 v2 3/5] android: Clear adapter uuids during initialization
2013-11-12 12:06 [PATCH v2 0/5] Add support for registering local SDP records Szymon Janc
2013-11-12 12:06 ` [PATCH v2 1/5] android: Add and remove sdp records and uuids Szymon Janc
2013-11-12 12:06 ` [PATCH v2 2/5] android: Remove not needed include Szymon Janc
@ 2013-11-12 12:06 ` Szymon Janc
2013-11-12 12:06 ` [PATCH v2 4/5] android: Add support for getting UUIDs property Szymon Janc
2013-11-12 12:06 ` [PATCH v2 5/5] android: Register DeviceID record when adapter is initialized Szymon Janc
4 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 12:06 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 bda8e20..d5b1806 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1193,6 +1193,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)
{
@@ -1233,6 +1244,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 v2 4/5] android: Add support for getting UUIDs property
2013-11-12 12:06 [PATCH v2 0/5] Add support for registering local SDP records Szymon Janc
` (2 preceding siblings ...)
2013-11-12 12:06 ` [PATCH v2 3/5] android: Clear adapter uuids during initialization Szymon Janc
@ 2013-11-12 12:06 ` Szymon Janc
2013-11-12 12:06 ` [PATCH v2 5/5] android: Register DeviceID record when adapter is initialized Szymon Janc
4 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 12:06 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 d5b1806..fd40bad 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(uint128_t *uuid)
@@ -1031,6 +1074,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, uint128_t *uuid)
@@ -1331,14 +1378,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 v2 5/5] android: Register DeviceID record when adapter is initialized
2013-11-12 12:06 [PATCH v2 0/5] Add support for registering local SDP records Szymon Janc
` (3 preceding siblings ...)
2013-11-12 12:06 ` [PATCH v2 4/5] android: Add support for getting UUIDs property Szymon Janc
@ 2013-11-12 12:06 ` Szymon Janc
4 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-11-12 12:06 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 | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index fd40bad..1ddd1f4 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 */
@@ -1182,20 +1186,29 @@ 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(PNP_INFO_PROFILE_ID, 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 v2 1/5] android: Add and remove sdp records and uuids
2013-11-12 12:06 ` [PATCH v2 1/5] android: Add and remove sdp records and uuids Szymon Janc
@ 2013-11-12 13:24 ` Johan Hedberg
0 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2013-11-12 13:24 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth, Marcin Kraglak
Hi,
On Tue, Nov 12, 2013, Szymon Janc wrote:
> +static void add_uuid(uint8_t svc_hint, uint128_t *uuid)
> +{
> + struct mgmt_cp_add_uuid cp;
> +
> + htob128(uuid, (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(uint16_t uuid, sdp_record_t *rec, uint8_t svc_hint)
Is it really so that we can't infer the UUID by looking inside
sdp_record_t? (e.g. just use rec->svclass).
> +{
> + uint128_t uint128;
> +
> + if (g_slist_find(adapter->uuids, GUINT_TO_POINTER(uuid))) {
> + DBG("UUID 0x%x already added", uuid);
> + return -1;
> + }
Shouldn't this be return -EALREADY?
> + adapter->uuids = g_slist_prepend(adapter->uuids,
> + GUINT_TO_POINTER(uuid));
> +
> + uuid16_to_uint128(uuid, &uint128);
> +
> + add_uuid(svc_hint, &uint128);
If we only support adding UUID-16, then how about just providing
uint16_t to add/remove_uuid and do the conversion inside these
functions?
> +void bt_adapter_remove_record(uint16_t uuid, int handle)
The type that sdp_record_t uses for the handle is uint32_t so the
parameter here should reflect that.
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-11-12 13:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-12 12:06 [PATCH v2 0/5] Add support for registering local SDP records Szymon Janc
2013-11-12 12:06 ` [PATCH v2 1/5] android: Add and remove sdp records and uuids Szymon Janc
2013-11-12 13:24 ` Johan Hedberg
2013-11-12 12:06 ` [PATCH v2 2/5] android: Remove not needed include Szymon Janc
2013-11-12 12:06 ` [PATCH v2 3/5] android: Clear adapter uuids during initialization Szymon Janc
2013-11-12 12:06 ` [PATCH v2 4/5] android: Add support for getting UUIDs property Szymon Janc
2013-11-12 12:06 ` [PATCH v2 5/5] android: Register DeviceID record when adapter is initialized Szymon Janc
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).