Linux bluetooth development
 help / color / mirror / Atom feed
* Re: [PATCH] android: Suppress compiler warnings not enabled by autotools build
From: Johan Hedberg @ 2013-11-05 11:04 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1383648613-21352-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Tue, Nov 05, 2013, Szymon Janc wrote:
> missing-field-initializers warning is not enabled on autotools build.
> Current code rely on implicit fields intializations resulting in flood
> of bogus compiler warnings while building for Android.
> 
> monitor/packet.c:348:2: warning: missing initializer
>     [-Wmissing-field-initializers]
> monitor/packet.c:348:2: warning: (near initialization for
>     'error2str_table[64].error') [-Wmissing-field-initializers]
> monitor/packet.c:542:2: warning: missing initializer
>     [-Wmissing-field-initializers]
> monitor/packet.c:542:2: warning: (near initialization for
>     'svc_class_table[8].bit') [-Wmissing-field-initializers]
> monitor/packet.c:557:2: warning: missing initializer
>     [-Wmissing-field-initializers]
> monitor/packet.c:557:2: warning: (near initialization for
>     'major_class_computer_table[8].val') [-Wmissing-field-initializers]
> ---
>  android/Android.mk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/6] android: Initial implementation of get_remote_services
From: Johan Hedberg @ 2013-11-05 10:57 UTC (permalink / raw)
  To: Marcin Kraglak; +Cc: linux-bluetooth
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>

Hi Marcin,

On Tue, Nov 05, 2013, Marcin Kraglak wrote:
> +static int bdaddr_cmp(gconstpointer a, gconstpointer b)
> +{
> +	const bdaddr_t *bda = a;
> +	const bdaddr_t *bdb = b;
> +
> +	return bacmp(bdb, bda);
> +}
> +
> +static bool fetch_remote_uuids(const bdaddr_t *addr)
> +{
> +	struct browse_req *req;
> +	uuid_t uuid;
> +
> +	if (g_slist_find_custom(sdp_req_list, addr, bdaddr_cmp))
> +		return false;
> +
> +	req = g_new0(struct browse_req, 1);
> +	bacpy(&req->bdaddr, addr);
> +	sdp_req_list = g_slist_append(sdp_req_list, &req->bdaddr);

This is quite wild coding, having a list with pointers into the middle
of a struct instead of the struct itself. To avoid having to twist ones
brain around to figure out correctness, could you just store the request
pointers in this list and then modify your bdaddr_cmp function to
compare a struct browse_req against a bdaddr_t pointer instead of
comparing two bdaddr pointers. You'll probably want to rename it to
req_cmp or something similar then though.

> +	sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
> +
> +	if (bt_search_service(&adapter->bdaddr,
> +			&req->bdaddr, &uuid, browse_cb, req, NULL) < 0) {
> +		sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
> +		browse_req_free(req);

Instead of having to do an extra g_slist_remove here why not just add
the entry to the sdp_req_list only after bt_search_service has been
successful?

Also, how about renaming sdp_req_list to browse_req_list to match the
name you've chosen for the context struct? Or maybe even simpler as
"browse_reqs"

>  static uint8_t get_remote_services(void *buf, uint16_t len)
>  {
> -	return HAL_STATUS_UNSUPPORTED;
> +	struct hal_cmd_get_remote_services *cmd = buf;
> +	bool ret;
> +	bdaddr_t addr;
> +
> +	android2bdaddr(&cmd->bdaddr, &addr);
> +
> +	ret = fetch_remote_uuids(&addr);
> +
> +	return ret ? HAL_STATUS_SUCCESS : HAL_STATUS_FAILED;
>  }

How about just making fetch_remote_uuids() return a proper HAL status
directly instead of this mapping of bool to HAL status? You could also
just consider merging the entire fetch_remote_uuids function (whose name
I don't really like btw) into this get_remote_services function,
especially if you don't foresee it having any other callers in the
future.

Johan

^ permalink raw reply

* [PATCH] android: Suppress compiler warnings not enabled by autotools build
From: Szymon Janc @ 2013-11-05 10:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

missing-field-initializers warning is not enabled on autotools build.
Current code rely on implicit fields intializations resulting in flood
of bogus compiler warnings while building for Android.

monitor/packet.c:348:2: warning: missing initializer
    [-Wmissing-field-initializers]
monitor/packet.c:348:2: warning: (near initialization for
    'error2str_table[64].error') [-Wmissing-field-initializers]
monitor/packet.c:542:2: warning: missing initializer
    [-Wmissing-field-initializers]
monitor/packet.c:542:2: warning: (near initialization for
    'svc_class_table[8].bit') [-Wmissing-field-initializers]
monitor/packet.c:557:2: warning: missing initializer
    [-Wmissing-field-initializers]
monitor/packet.c:557:2: warning: (near initialization for
    'major_class_computer_table[8].val') [-Wmissing-field-initializers]
---
 android/Android.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/android/Android.mk b/android/Android.mk
index 86af7b6..d76dfaf 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -11,7 +11,7 @@ BLUEZ_COMMON_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\" \
 	-DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
 
 # Disable warnings enabled by Android but not enabled in autotools build
-BLUEZ_COMMON_CFLAGS += -Wno-pointer-arith
+BLUEZ_COMMON_CFLAGS += -Wno-pointer-arith -Wno-missing-field-initializers
 
 #
 # Android BlueZ daemon (bluetoothd)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 6/6] android: Add support for getting adapter uuids
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>

Implement get adapter uuids command. It will pack supported
uuids to structure and send it via notification socket
---
 android/adapter.c | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 523209e..483bb1c 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1278,13 +1278,47 @@ static bool get_name(void)
 	return true;
 }
 
+static void swap_uuid(const uint8_t *src, uint8_t *dst)
+{
+	int i;
+
+	for (i = 0; i < 16; i++)
+		dst[15 - i] = src[i];
+}
+
 static bool get_uuids(void)
 {
-	DBG("Not implemented");
+	struct hal_ev_adapter_props_changed *ev;
+	unsigned int i;
+	int len;
+	uint8_t *p;
 
-	/* TODO: Add implementation */
+	len = sizeof(*ev) + sizeof(struct hal_property) +
+			NELEM(supported_services) * sizeof(uint128_t);
 
-	return false;
+	ev = g_malloc(len);
+
+	ev->num_props = 1;
+	ev->status = HAL_STATUS_SUCCESS;
+
+	ev->props[0].type = HAL_PROP_ADAPTER_UUIDS;
+	ev->props[0].len = sizeof(uint128_t) * NELEM(supported_services);
+	p = ev->props->val;
+
+	for (i = 0; i < NELEM(supported_services); i++) {
+		/* we have to swap supported uuids
+		 * because hal expects them in reversed order
+		 * than mgmt intrface */
+		swap_uuid(supported_services[i].uuid, p);
+		p += sizeof(uint128_t);
+	}
+
+	ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+				HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+	g_free(ev);
+
+	return true;
 }
 
 static bool get_class(void)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 5/6] android: Implement class of device property callback
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>

This will send adapter property with class of device
to notification socket.
---
 android/adapter.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index d791450..523209e 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -185,6 +185,30 @@ static void scan_mode_changed(void)
 	g_free(ev);
 }
 
+static void send_adapter_class(void)
+{
+	struct hal_ev_adapter_props_changed *ev;
+	int len;
+
+	len = sizeof(*ev) + sizeof(struct hal_property) + sizeof(uint32_t);
+
+	ev = g_malloc(len);
+
+	ev->num_props = 1;
+	ev->status = HAL_STATUS_SUCCESS;
+
+	ev->props[0].type = HAL_PROP_ADAPTER_CLASS;
+	ev->props[0].len = sizeof(uint32_t);
+	memcpy(ev->props->val, &adapter->dev_class, sizeof(uint32_t));
+
+	DBG("Adapter class %u", adapter->dev_class);
+
+	ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+				HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+	g_free(ev);
+}
+
 static void adapter_name_changed(const uint8_t *name)
 {
 	struct hal_ev_adapter_props_changed *ev;
@@ -275,7 +299,7 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
 
 	adapter->dev_class = dev_class;
 
-	/* TODO: Inform prop change: Class */
+	send_adapter_class();
 
 	/* TODO: Gatt attrib set*/
 }
@@ -1265,11 +1289,11 @@ static bool get_uuids(void)
 
 static bool get_class(void)
 {
-	DBG("Not implemented");
+	DBG("");
 
-	/* TODO: Add implementation */
+	send_adapter_class();
 
-	return false;
+	return true;
 }
 
 static bool get_type(void)
-- 
1.8.4.1


^ permalink raw reply related

* Re: [PATCH] android/daemon: Save adapter name on complete event
From: Johan Hedberg @ 2013-11-05 10:33 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1383646128-8077-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Tue, Nov 05, 2013, Andrei Emeltchenko wrote:
> Saving adapter name was missing from set name complete event.
> Refactor code to function and reuse it in both places where
> name is changed.
> ---
>  android/adapter.c |   21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* [PATCH 4/6] android: Add supported uuids when adapter is initialized
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>

It will set class of device with proper service hints.
We set it statically because we want to keep code simple.
---
 android/adapter.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 64f0192..d791450 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -52,6 +52,29 @@ static GIOChannel *notification_io = NULL;
 /* This list contains addresses which are asked for records */
 static GSList *sdp_req_list;
 
+/*
+ * This is an array of supported uuids and service hints. We add them via mgmt
+ * interface when adapter is initialized. Uuids are in reverse orded.
+ */
+static const struct mgmt_cp_add_uuid supported_services[] = {
+	/* OBEX_OPP_UUID */
+	{ .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
+			0x00, 0x10, 0x00, 0x00, 0x05, 0x11, 0x00, 0x00 },
+	.svc_hint = 0x10 },
+	/* HFP_AG_UUID */
+	{ .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
+			0x00, 0x10, 0x00, 0x00, 0x1f, 0x11, 0x00, 0x00 },
+	.svc_hint = 0x40 },
+	/* ADVANCED_AUDIO_UUID */
+	{ .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
+			0x00, 0x10, 0x00, 0x00, 0x0d, 0x11, 0x00, 0x00 },
+	.svc_hint = 0x08 },
+	/* PANU_UUID */
+	{ .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
+			0x00, 0x10, 0x00, 0x00, 0x15, 0x11, 0x00, 0x00 },
+	.svc_hint = 0x02 }
+};
+
 struct bt_adapter {
 	uint16_t index;
 	struct mgmt *mgmt;
@@ -967,6 +990,39 @@ static void load_link_keys(GSList *keys)
 	}
 }
 
+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_uuids(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < NELEM(supported_services); i++)
+		mgmt_send(adapter->mgmt, MGMT_OP_ADD_UUID, adapter->index,
+				sizeof(supported_services[i]),
+				&supported_services[i], add_uuid_complete,
+				NULL, NULL);
+}
+
+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 set_mode_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -982,6 +1038,9 @@ static void set_mode_complete(uint8_t status, uint16_t length,
 	 * event handling functions here.
 	 */
 	new_settings_callback(adapter->index, length, param, NULL);
+
+	clear_uuids();
+	add_uuids();
 }
 
 static bool set_mode(uint16_t opcode, uint8_t mode)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 3/6] android: Pass found uuids to remote_device_properties_cb
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>

Send remote device's uuids in remote_device_properties_cb.
This patch will pack found uuids to buffer containing property
with list of uuids and send it to notification socket.
---
 android/adapter.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 81 insertions(+), 1 deletion(-)

diff --git a/android/adapter.c b/android/adapter.c
index 692ffe4..64f0192 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -283,9 +283,87 @@ static void browse_req_free(struct browse_req *req)
 	g_free(req);
 }
 
+static void fill_uuids(GSList *list, void *buf)
+{
+	for (; list; list = g_slist_next(list)) {
+		memcpy(buf, list->data, sizeof(uint128_t));
+		buf += sizeof(uint128_t);
+	}
+}
+
+static void remote_uuids_callback(struct browse_req *req)
+{
+	struct hal_ev_remote_device_props *ev;
+	int len;
+
+	len = sizeof(*ev) + sizeof(struct hal_property) + (sizeof(uint128_t) *
+						g_slist_length(req->uuids));
+	ev = g_malloc(len);
+
+	ev->status = HAL_STATUS_SUCCESS;
+	bdaddr2android(&req->bdaddr, &ev->bdaddr);
+	ev->num_props = 1;
+	ev->props[0].type = HAL_PROP_DEVICE_UUIDS;
+	ev->props[0].len = sizeof(uint128_t) * g_slist_length(req->uuids);
+	fill_uuids(req->uuids, ev->props[0].val);
+
+	ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+				HAL_EV_REMOTE_DEVICE_PROPS, len, ev, -1);
+
+	g_free(ev);
+}
+
+static int uuid_128_cmp(gconstpointer a, gconstpointer b)
+{
+	return memcmp(a, b, sizeof(uint128_t));
+}
+
 static void update_records(struct browse_req *req, sdp_list_t *recs)
 {
-	/* TODO cache found uuids */
+	for (; recs; recs = recs->next) {
+		sdp_record_t *rec = (sdp_record_t *) recs->data;
+		sdp_list_t *svcclass = NULL;
+		uuid_t uuid128;
+		uuid_t *tmp;
+		uint8_t *new_uuid;
+
+		if (!rec)
+			break;
+
+		if (sdp_get_service_classes(rec, &svcclass) < 0)
+			continue;
+
+		if (!svcclass)
+			continue;
+
+		tmp = svcclass->data;
+
+		switch (tmp->type) {
+		case SDP_UUID16:
+			sdp_uuid16_to_uuid128(&uuid128, tmp);
+			break;
+		case SDP_UUID32:
+			sdp_uuid32_to_uuid128(&uuid128, tmp);
+			break;
+		case SDP_UUID128:
+			memcpy(&uuid128, tmp, sizeof(uuid_t));
+			break;
+		default:
+			continue;
+		}
+
+		new_uuid = g_malloc(16);/* size of 128 bit uuid */
+		memcpy(new_uuid, &uuid128.value.uuid128,
+				sizeof(uuid128.value.uuid128));
+
+		/* Check if uuid is already added */
+		if (g_slist_find_custom(req->uuids, new_uuid, uuid_128_cmp))
+			g_free(new_uuid);
+		else
+			req->uuids = g_slist_append(req->uuids, new_uuid);
+
+		sdp_list_free(svcclass, free);
+	}
 }
 
 static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
@@ -315,6 +393,8 @@ static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
 	}
 
 done:
+	remote_uuids_callback(req);
+
 	sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
 	browse_req_free(req);
 }
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 2/6] android: Fetch remote device uuids after pairing
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>

Android framework expects list of bonded device's uuids.
Start sdp query after setting bond state to BOND_STATE_BONBED.
---
 android/adapter.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 027af25..692ffe4 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -382,6 +382,8 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
 
 	send_bond_state_change(&addr->bdaddr, HAL_STATUS_SUCCESS,
 							HAL_BOND_STATE_BONDED);
+
+	fetch_remote_uuids(&addr->bdaddr);
 }
 
 static void pin_code_request_callback(uint16_t index, uint16_t length,
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 1/6] android: Initial implementation of get_remote_services
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcin Kraglak

This patch implements method to retrieve remote device sdp records.
Caching struct is implemented for adding fetched uuids to list.
sdp_req_list will contain list of devices which are asked for records.
Function get_remote_services will check if device is on list, and will
start sdp procedure.
---
 android/adapter.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 102 insertions(+), 9 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 929e8cb..027af25 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -35,6 +35,10 @@
 #include "src/shared/mgmt.h"
 #include "src/glib-helper.h"
 #include "src/eir.h"
+#include "lib/sdp.h"
+#include "lib/sdp_lib.h"
+#include "lib/uuid.h"
+#include "src/sdp-client.h"
 #include "log.h"
 #include "hal-msg.h"
 #include "ipc.h"
@@ -45,6 +49,8 @@
 #define DEFAULT_IO_CAPABILITY 0x01
 
 static GIOChannel *notification_io = NULL;
+/* This list contains addresses which are asked for records */
+static GSList *sdp_req_list;
 
 struct bt_adapter {
 	uint16_t index;
@@ -63,6 +69,20 @@ struct bt_adapter {
 	bool discovering;
 };
 
+struct browse_req {
+	bdaddr_t bdaddr;
+	GSList *uuids;
+	int search_uuid;
+	int reconnect_attempt;
+};
+
+static const uint16_t uuid_list[] = {
+	L2CAP_UUID,
+	PNP_INFO_SVCLASS_ID,
+	PUBLIC_BROWSE_GROUP,
+	0
+};
+
 static struct bt_adapter *adapter;
 static GSList *found_devices = NULL;
 
@@ -257,6 +277,79 @@ static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
 			HAL_EV_BOND_STATE_CHANGED, sizeof(ev), &ev, -1);
 }
 
+static void browse_req_free(struct browse_req *req)
+{
+	g_slist_free_full(req->uuids, g_free);
+	g_free(req);
+}
+
+static void update_records(struct browse_req *req, sdp_list_t *recs)
+{
+	/* TODO cache found uuids */
+}
+
+static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
+{
+	struct browse_req *req = user_data;
+	uuid_t uuid;
+
+	/* If we have a valid response and req->search_uuid == 2, then L2CAP
+	 * UUID & PNP searching was successful -- we are done */
+	if (err < 0 || req->search_uuid == 2) {
+		if (err == -ECONNRESET && req->reconnect_attempt < 1) {
+			req->search_uuid--;
+			req->reconnect_attempt++;
+		} else {
+			goto done;
+		}
+	}
+
+	update_records(req, recs);
+
+	/* Search for mandatory uuids */
+	if (uuid_list[req->search_uuid]) {
+		sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
+		bt_search_service(&adapter->bdaddr, &req->bdaddr, &uuid,
+						browse_cb, user_data, NULL);
+		return;
+	}
+
+done:
+	sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
+	browse_req_free(req);
+}
+
+static int bdaddr_cmp(gconstpointer a, gconstpointer b)
+{
+	const bdaddr_t *bda = a;
+	const bdaddr_t *bdb = b;
+
+	return bacmp(bdb, bda);
+}
+
+static bool fetch_remote_uuids(const bdaddr_t *addr)
+{
+	struct browse_req *req;
+	uuid_t uuid;
+
+	if (g_slist_find_custom(sdp_req_list, addr, bdaddr_cmp))
+		return false;
+
+	req = g_new0(struct browse_req, 1);
+	bacpy(&req->bdaddr, addr);
+	sdp_req_list = g_slist_append(sdp_req_list, &req->bdaddr);
+	sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
+
+	if (bt_search_service(&adapter->bdaddr,
+			&req->bdaddr, &uuid, browse_cb, req, NULL) < 0) {
+		sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
+		browse_req_free(req);
+		return false;
+	}
+
+	return true;
+}
+
 static void new_link_key_callback(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -445,14 +538,6 @@ static void confirm_device_name(const bdaddr_t *addr, uint8_t addr_type)
 		error("Failed to send confirm name request");
 }
 
-static int bdaddr_cmp(gconstpointer a, gconstpointer b)
-{
-	const bdaddr_t *bda = a;
-	const bdaddr_t *bdb = b;
-
-	return bacmp(bdb, bda);
-}
-
 static int fill_device_props(struct hal_property *prop, bdaddr_t *addr,
 					uint32_t cod, int8_t rssi, char *name)
 {
@@ -1477,7 +1562,15 @@ static uint8_t ssp_reply(void *buf, uint16_t len)
 
 static uint8_t get_remote_services(void *buf, uint16_t len)
 {
-	return HAL_STATUS_UNSUPPORTED;
+	struct hal_cmd_get_remote_services *cmd = buf;
+	bool ret;
+	bdaddr_t addr;
+
+	android2bdaddr(&cmd->bdaddr, &addr);
+
+	ret = fetch_remote_uuids(&addr);
+
+	return ret ? HAL_STATUS_SUCCESS : HAL_STATUS_FAILED;
 }
 
 void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
-- 
1.8.4.1


^ permalink raw reply related

* Re: [PATCH 0/2] Style, typo and naming fixes
From: Johan Hedberg @ 2013-11-05 10:32 UTC (permalink / raw)
  To: Jerzy Kasenberg; +Cc: linux-bluetooth
In-Reply-To: <1383645382-3372-1-git-send-email-jerzy.kasenberg@tieto.com>

Hi Jerzy,

On Tue, Nov 05, 2013, Jerzy Kasenberg wrote:
> This patchset fixes obvious spelling errors.
> It also changes adapter to bluetooth in help and comments.
> Few white space errors also were fixed.
> 
> Jerzy Kasenberg (2):
>   android/client: Fix style and typos
>   android/client: Change adapter to bluetooth
> 
>  android/client/haltest.c       |    6 +++---
>  android/client/history.c       |    3 +++
>  android/client/if-main.h       |    2 +-
>  android/client/tabcompletion.c |   21 +++++++++++++--------
>  android/client/terminal.c      |   26 ++++++++++++++------------
>  5 files changed, 34 insertions(+), 24 deletions(-)

Both patches have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] android: Add Android Makefile for btmon
From: Johan Hedberg @ 2013-11-05 10:31 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1383644812-24537-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Tue, Nov 05, 2013, Andrei Emeltchenko wrote:
> Build btmon for Android image. btmon requires fresh bionic to build.
> ---
>  android/Android.mk |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)

Applied. Thanks.

Johan

^ permalink raw reply

* [PATCH] android/daemon: Save adapter name on complete event
From: Andrei Emeltchenko @ 2013-11-05 10:08 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <CABBYNZKJV-h82WQ5_J3z+ArC3=Gy00qTpKHhWSF7v+fFC7KTrA@mail.gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Saving adapter name was missing from set name complete event.
Refactor code to function and reuse it in both places where
name is changed.
---
 android/adapter.c |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index b6f6096..6b0dc8b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -88,6 +88,17 @@ static void adapter_name_changed(const uint8_t *name)
 			HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev, -1);
 }
 
+static void adapter_set_name(const uint8_t *name)
+{
+	if (!g_strcmp0(adapter->name, (const char *) name))
+		return;
+
+	DBG("Cnage name: %s -> %s", adapter->name, name);
+
+	g_free(adapter->name);
+	adapter->name = g_strdup((const char *) name);
+}
+
 static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -98,13 +109,7 @@ static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
 		return;
 	}
 
-	if (!g_strcmp0(adapter->name, (const char *) rp->name))
-		return;
-
-	DBG("name: %s", rp->name);
-
-	g_free(adapter->name);
-	adapter->name = g_strdup((const char *) rp->name);
+	adapter_set_name(rp->name);
 
 	adapter_name_changed(rp->name);
 }
@@ -879,6 +884,8 @@ static void set_adapter_name_complete(uint8_t status, uint16_t length,
 		return;
 	}
 
+	adapter_set_name(rp->name);
+
 	adapter_name_changed(rp->name);
 }
 
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH 2/2] android/client: Change adapter to bluetooth
From: Jerzy Kasenberg @ 2013-11-05  9:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1383645382-3372-1-git-send-email-jerzy.kasenberg@tieto.com>

This fixes all places where adapter should be changed to
bluetooth.
---
 android/client/haltest.c |    6 +++---
 android/client/if-main.h |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index bbe8693..f511025 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -141,9 +141,9 @@ static void help_p(int argc, const char **argv)
 
 		terminal_print("\nTo get help on methods for each interface type:\n");
 		terminal_print("\n\thelp <inerface>\n");
-		terminal_print("\nBasic scenario:\n\tadapter init\n");
-		terminal_print("\tadapter enable\n\tadapter start_discovery\n");
-		terminal_print("\tadapter get_profile_interface handsfree\n");
+		terminal_print("\nBasic scenario:\n\tbluetooth init\n");
+		terminal_print("\tbluetooth enable\n\tbluetooth start_discovery\n");
+		terminal_print("\tbluetooth get_profile_interface handsfree\n");
 		terminal_print("\thandsfree init\n\n");
 		return;
 	}
diff --git a/android/client/if-main.h b/android/client/if-main.h
index 0c59054..f638b91 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -61,7 +61,7 @@ extern const btgatt_client_interface_t *if_gatt_client;
 
 /*
  * Structure defines top level interfaces that can be used in test tool
- * this will contain values as: adapter, av, gatt, sock, pan...
+ * this will contain values as: bluetooth, av, gatt, socket, pan...
  */
 struct interface {
 	const char *name; /* interface name */
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 1/2] android/client: Fix style and typos
From: Jerzy Kasenberg @ 2013-11-05  9:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1383645382-3372-1-git-send-email-jerzy.kasenberg@tieto.com>

Fixes spelling errors and white space style errors.
---
 android/client/history.c       |    3 +++
 android/client/tabcompletion.c |   21 +++++++++++++--------
 android/client/terminal.c      |   26 ++++++++++++++------------
 3 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/android/client/history.c b/android/client/history.c
index 6481174..ee285da 100644
--- a/android/client/history.c
+++ b/android/client/history.c
@@ -49,13 +49,16 @@ void history_restore(const char *filename)
 	for (;;) {
 		if (fgets(line, 1000, f) != NULL) {
 			int l = strlen(line);
+
 			while (l > 0 && isspace(line[--l]))
 				line[l] = 0;
+
 			if (l > 0)
 				history_add_line(line);
 		} else
 			break;
 	}
+
 	fclose(f);
 }
 
diff --git a/android/client/tabcompletion.c b/android/client/tabcompletion.c
index cc1a5d3..4a6329f 100644
--- a/android/client/tabcompletion.c
+++ b/android/client/tabcompletion.c
@@ -58,9 +58,9 @@ static void print_matches(enum_func f, void *user, const char *prefix, int len)
 
 /*
  * This function splits command line into linked list of arguments.
- * line_buffer - pointer to input comman line
+ * line_buffer - pointer to input command line
  * size - size of command line to parse
- * buf - output buffer to keep splited arguments list
+ * buf - output buffer to keep split arguments list
  * buf_size_in_bytes - size of buf
  */
 static int split_command(const char *line_buffer, int size, split_arg_t *buf,
@@ -134,12 +134,14 @@ static void tab_completion(struct command_completion_args *args)
 		/* prefix does not match */
 		if (strncmp(enum_name, name, len) != 0)
 			continue;
+
 		/* prefix matches first time */
 		if (count++ == 0) {
 			strcpy(prefix, enum_name);
 			prefix_len = strlen(prefix);
 			continue;
 		}
+
 		/*
 		 * Prefix matches next time
 		 * reduce prefix to common part
@@ -158,12 +160,13 @@ static void tab_completion(struct command_completion_args *args)
 		tab_hit_count = 0;
 		return;
 	}
+
 	/* len == prefix_len => nothing new was added */
 	if (len == prefix_len) {
 		if (count != 1) {
-			if (tab_hit_count == 1)
+			if (tab_hit_count == 1) {
 				putchar('\a');
-			else if (tab_hit_count == 2 ||
+			} else if (tab_hit_count == 2 ||
 					args->help == NULL) {
 				print_matches(args->func,
 						args->user, name, len);
@@ -182,6 +185,7 @@ static void tab_completion(struct command_completion_args *args)
 			prefix[prefix_len++] = ' ';
 			prefix[prefix_len] = '\0';
 		}
+
 		terminal_insert_into_command_line(prefix + len);
 		tab_hit_count = 0;
 	}
@@ -304,7 +308,7 @@ static const char *return_null(void *user, int i)
  * parameter completion function
  * argc - number of elements in arg list
  * arg - list of arguments
- * megthod - method to get completion from (can be NULL)
+ * method - method to get completion from (can be NULL)
  */
 static void param_completion(int argc, const split_arg_t *arg,
 					const struct method *method, int hlpix)
@@ -339,9 +343,9 @@ static void param_completion(int argc, const split_arg_t *arg,
 }
 
 /*
- * This methd gets called when user tapped tab key.
- * line - points to comman line
- * len - size of line that should be used for comletions. This should be
+ * This method gets called when user tapped tab key.
+ * line - points to command line
+ * len - size of line that should be used for completions. This should be
  *   cursor position during tab hit.
  */
 void process_tab(const char *line, int len)
@@ -360,6 +364,7 @@ void process_tab(const char *line, int len)
 		command_completion(buf);
 		return;
 	}
+
 	method = get_command(buf[0].ntcopy);
 	if (method != NULL) {
 		param_completion(argc, buf, method, 1);
diff --git a/android/client/terminal.c b/android/client/terminal.c
index 22a1d8a..b152bf3 100644
--- a/android/client/terminal.c
+++ b/android/client/terminal.c
@@ -99,8 +99,8 @@ static const struct ansii_sequence ansii_sequnces[] = {
 #define isseqence(c) ((c) == 0x1B)
 
 /*
- * Number of characters that consist of ANSII sequence
- * Should not be less then longest string in ansii_sequnces
+ * Number of characters that consist of ANSI sequence
+ * Should not be less then longest string in ansi_sequences
  */
 #define MAX_ASCII_SEQUENCE 10
 
@@ -139,7 +139,7 @@ static void terminal_move_cursor(int n)
 void terminal_draw_command_line(void)
 {
 	/*
-	 * this needs to be checked here since line_buf is not cleard
+	 * this needs to be checked here since line_buf is not cleared
 	 * before parsing event though line_len and line_buf_ix are
 	 */
 	if (line_len > 0)
@@ -240,7 +240,7 @@ static void terminal_clear_line(void)
 	terminal_line_replaced();
 }
 
-static void terminal_clear_sceen(void)
+static void terminal_clear_screen(void)
 {
 	line_buf[0] = '\0';
 	line_buf_ix = 0;
@@ -312,7 +312,7 @@ static void terminal_match_hitory(bool back)
 	if (matching_line >= 0) {
 		int pos = line_buf_ix;
 		terminal_get_line_from_history(matching_line);
-		/* move back to cursor position to origianl place */
+		/* move back to cursor position to original place */
 		line_buf_ix = pos;
 		terminal_move_cursor(pos - line_len);
 	}
@@ -328,12 +328,13 @@ static int terminal_convert_sequence(int c)
 
 	/* Not in sequence yet? */
 	if (current_sequence_len == -1) {
-		/* Is ansii sequence detected by 0x1B ? */
+		/* Is ansi sequence detected by 0x1B ? */
 		if (isseqence(c)) {
 			current_sequence_len++;
 			return KEY_SEQUNCE_NOT_FINISHED;
-	       }
-	       return c;
+		}
+
+		return c;
 	}
 
 	/* Inside sequence */
@@ -350,11 +351,12 @@ static int terminal_convert_sequence(int c)
 			current_sequence_len = -1;
 			return ansii_sequnces[i].code;
 		}
+
 		/* partial match (not whole sequence yet) */
 		return KEY_SEQUNCE_NOT_FINISHED;
 	}
 
-	terminal_print("ansii char 0x%X %c\n", c);
+	terminal_print("ansi char 0x%X %c\n", c);
 	/*
 	 * Sequence does not match
 	 * mark that no in sequence any more, return char
@@ -421,7 +423,7 @@ void terminal_process_char(int c, void (*process_line)(char *line))
 			line_buf_ix--;
 		/* skip all non spaces to the left */
 		while (line_buf_ix > 0 &&
-		       !isspace(line_buf[line_buf_ix - 1]))
+			!isspace(line_buf[line_buf_ix - 1]))
 			line_buf_ix--;
 		/* move cursor to new position */
 		terminal_move_cursor(line_buf_ix - old_pos);
@@ -538,7 +540,7 @@ void terminal_process_char(int c, void (*process_line)(char *line))
 		}
 		break;
 	case KEY_C_L:
-		terminal_clear_sceen();
+		terminal_clear_screen();
 		break;
 	default:
 		if (!isprint(c)) {
@@ -592,7 +594,7 @@ void terminal_setup(void)
 
 	/*
 	 * Turn off echo since all editing is done by hand,
-	 * Ctrl-c handled internaly
+	 * Ctrl-c handled internally
 	 */
 	tios.c_lflag &= ~(ICANON | ECHO | BRKINT | IGNBRK);
 	tcsetattr(0, TCSANOW, &tios);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 0/2] Style, typo and naming fixes
From: Jerzy Kasenberg @ 2013-11-05  9:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg

This patchset fixes obvious spelling errors.
It also changes adapter to bluetooth in help and comments.
Few white space errors also were fixed.

Jerzy Kasenberg (2):
  android/client: Fix style and typos
  android/client: Change adapter to bluetooth

 android/client/haltest.c       |    6 +++---
 android/client/history.c       |    3 +++
 android/client/if-main.h       |    2 +-
 android/client/tabcompletion.c |   21 +++++++++++++--------
 android/client/terminal.c      |   26 ++++++++++++++------------
 5 files changed, 34 insertions(+), 24 deletions(-)

-- 
1.7.9.5


^ permalink raw reply

* [PATCH] android: Add Android Makefile for btmon
From: Andrei Emeltchenko @ 2013-11-05  9:46 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Build btmon for Android image. btmon requires fresh bionic to build.
---
 android/Android.mk |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/android/Android.mk b/android/Android.mk
index 77fd5a0..86af7b6 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -145,3 +145,58 @@ LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := haltest
 
 include $(BUILD_EXECUTABLE)
+
+#
+# btmon
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+	../monitor/main.c \
+	../monitor/bt.h \
+	../monitor/mainloop.h \
+	../monitor/mainloop.c \
+	../monitor/display.h \
+	../monitor/display.c \
+	../monitor/hcidump.h \
+	../monitor/hcidump.c \
+	../monitor/btsnoop.h \
+	../monitor/btsnoop.c \
+	../monitor/control.h \
+	../monitor/control.c \
+	../monitor/packet.h \
+	../monitor/packet.c \
+	../monitor/l2cap.h \
+	../monitor/l2cap.c \
+	../monitor/uuid.h \
+	../monitor/uuid.c \
+	../monitor/sdp.h \
+	../monitor/sdp.c \
+	../monitor/vendor.h \
+	../monitor/vendor.c \
+	../monitor/lmp.h \
+	../monitor/lmp.c \
+	../monitor/crc.h \
+	../monitor/crc.c \
+	../monitor/ll.h \
+	../monitor/ll.c \
+	../lib/hci.c \
+	../lib/bluetooth.c \
+
+LOCAL_C_INCLUDES := \
+	$(LOCAL_PATH)/.. \
+	$(LOCAL_PATH)/../lib \
+	$(LOCAL_PATH)/../src/shared \
+
+LOCAL_C_INCLUDES += \
+	$(call include-path-for, glib) \
+	$(call include-path-for, glib)/glib \
+
+LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE := btmon
+
+include $(BUILD_EXECUTABLE)
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH] net: bluetooth: fix crash in l2cap_chan_send after l2cap_chan_del
From: Seung-Woo Kim @ 2013-11-05  9:46 UTC (permalink / raw)
  To: linux-bluetooth, johan.hedberg; +Cc: marcel, gustavo, sw0312.kim, s.syam
In-Reply-To: <20131101075718.GA13221@x220.p-661hnu-f1>

Removing a bond and disconnecting from a specific remote device
can cause l2cap_chan_send() is called after l2cap_chan_del() is
called. This causes following crash.

[ 1384.972086] Unable to handle kernel NULL pointer dereference at virtual address 00000008
[ 1384.972090] pgd = c0004000
[ 1384.972125] [00000008] *pgd=00000000
[ 1384.972137] Internal error: Oops: 17 [#1] PREEMPT SMP ARM
[ 1384.972144] Modules linked in:
[ 1384.972156] CPU: 0 PID: 841 Comm: krfcommd Not tainted 3.10.14-gdf22a71-dirty #435
[ 1384.972162] task: df29a100 ti: df178000 task.ti: df178000
[ 1384.972182] PC is at l2cap_create_basic_pdu+0x30/0x1ac
[ 1384.972191] LR is at l2cap_chan_send+0x100/0x1d4
[ 1384.972198] pc : [<c051d250>]    lr : [<c0521c78>]    psr: 40000113
[ 1384.972198] sp : df179d40  ip : c083a010  fp : 00000008
[ 1384.972202] r10: 00000004  r9 : 0000065a  r8 : 000003f5
[ 1384.972206] r7 : 00000000  r6 : 00000000  r5 : df179e84  r4 : da557000
[ 1384.972210] r3 : 00000000  r2 : 00000004  r1 : df179e84  r0 : 00000000
[ 1384.972215] Flags: nZcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
[ 1384.972220] Control: 10c53c7d  Table: 5c8b004a  DAC: 00000015
[ 1384.972224] Process krfcommd (pid: 841, stack limit = 0xdf178238)
[ 1384.972229] Stack: (0xdf179d40 to 0xdf17a000)
[ 1384.972238] 9d40: 00000000 da557000 00000004 df179e84 00000004 000003f5 0000065a 00000000
[ 1384.972245] 9d60: 00000008 c0521c78 df179e84 da557000 00000004 da557204 de0c6800 df179e84
[ 1384.972253] 9d80: da557000 00000004 da557204 c0526b7c 00000004 df724000 df179e84 00000004
[ 1384.972260] 9da0: df179db0 df29a100 c083bc48 c045481c 00000001 00000000 00000000 00000000
[ 1384.972267] 9dc0: 00000000 df29a100 00000000 00000000 00000000 00000000 df179e10 00000000
[ 1384.972274] 9de0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 1384.972281] 9e00: 00000000 00000000 00000000 00000000 df179e4c c000ec80 c0b538c0 00000004
[ 1384.972288] 9e20: df724000 df178000 00000000 df179e84 c0b538c0 00000000 df178000 c07f4570
[ 1384.972295] 9e40: dcad9c00 df179e74 c07f4394 df179e60 df178000 00000000 df179e84 de247010
[ 1384.972303] 9e60: 00000043 c0454dec 00000001 00000004 df315c00 c0530598 00000004 df315c0c
[ 1384.972310] 9e80: ffffc32c 00000000 00000000 df179ea0 00000001 00000000 00000000 00000000
[ 1384.972317] 9ea0: df179ebc 00000004 df315c00 c05df838 00000000 c0530810 c07d08c0 d7017303
[ 1384.972325] 9ec0: 6ec245b9 00000000 df315c00 c0531b04 c07f3fe0 c07f4018 da67a300 df315c00
[ 1384.972332] 9ee0: 00000000 c05334e0 df315c00 df315b80 df315c00 de0c6800 da67a300 00000000
[ 1384.972339] 9f00: de0c684c c0533674 df204100 df315c00 df315c00 df204100 df315c00 c082b138
[ 1384.972347] 9f20: c053385c c0533754 a0000113 df178000 00000001 c083bc48 00000000 c053385c
[ 1384.972354] 9f40: 00000000 00000000 00000000 c05338c4 00000000 df9f0000 df9f5ee4 df179f6c
[ 1384.972360] 9f60: df178000 c0049db4 00000000 00000000 c07f3ff8 00000000 00000000 00000000
[ 1384.972368] 9f80: df179f80 df179f80 00000000 00000000 df179f90 df179f90 df9f5ee4 c0049cfc
[ 1384.972374] 9fa0: 00000000 00000000 00000000 c000f168 00000000 00000000 00000000 00000000
[ 1384.972381] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 1384.972388] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 00010000 00000600
[ 1384.972411] [<c051d250>] (l2cap_create_basic_pdu+0x30/0x1ac) from [<c0521c78>] (l2cap_chan_send+0x100/0x1d4)
[ 1384.972425] [<c0521c78>] (l2cap_chan_send+0x100/0x1d4) from [<c0526b7c>] (l2cap_sock_sendmsg+0xa8/0x104)
[ 1384.972440] [<c0526b7c>] (l2cap_sock_sendmsg+0xa8/0x104) from [<c045481c>] (sock_sendmsg+0xac/0xcc)
[ 1384.972453] [<c045481c>] (sock_sendmsg+0xac/0xcc) from [<c0454dec>] (kernel_sendmsg+0x2c/0x34)
[ 1384.972469] [<c0454dec>] (kernel_sendmsg+0x2c/0x34) from [<c0530598>] (rfcomm_send_frame+0x58/0x7c)
[ 1384.972481] [<c0530598>] (rfcomm_send_frame+0x58/0x7c) from [<c0530810>] (rfcomm_send_ua+0x98/0xbc)
[ 1384.972494] [<c0530810>] (rfcomm_send_ua+0x98/0xbc) from [<c0531b04>] (rfcomm_recv_disc+0xac/0x100)
[ 1384.972506] [<c0531b04>] (rfcomm_recv_disc+0xac/0x100) from [<c05334e0>] (rfcomm_recv_frame+0x144/0x264)
[ 1384.972519] [<c05334e0>] (rfcomm_recv_frame+0x144/0x264) from [<c0533674>] (rfcomm_process_rx+0x74/0xfc)
[ 1384.972531] [<c0533674>] (rfcomm_process_rx+0x74/0xfc) from [<c0533754>] (rfcomm_process_sessions+0x58/0x160)
[ 1384.972543] [<c0533754>] (rfcomm_process_sessions+0x58/0x160) from [<c05338c4>] (rfcomm_run+0x68/0x110)
[ 1384.972558] [<c05338c4>] (rfcomm_run+0x68/0x110) from [<c0049db4>] (kthread+0xb8/0xbc)
[ 1384.972576] [<c0049db4>] (kthread+0xb8/0xbc) from [<c000f168>] (ret_from_fork+0x14/0x2c)
[ 1384.972586] Code: e3100004 e1a07003 e5946000 1a000057 (e5969008)
[ 1384.972614] ---[ end trace 6170b7ce00144e8c ]---

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
---
I can reproduce this crash with bluetooth-next kernel merged onto my v3.10
system. It is usually happens when the device is at sleep state and remote
device disconnects and removes bonding.

This patch is based on bluetooth-next tree.
---
 net/bluetooth/l2cap_core.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 0cef677..4af3821 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2439,6 +2439,9 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
 	int err;
 	struct sk_buff_head seg_queue;
 
+	if (!chan->conn)
+		return -ENOTCONN;
+
 	/* Connectionless channel */
 	if (chan->chan_type == L2CAP_CHAN_CONN_LESS) {
 		skb = l2cap_create_connless_pdu(chan, msg, len, priority);
-- 
1.7.4.1

^ permalink raw reply related

* [PATCH] Bluetooth: Fix rejecting SMP security request in slave role
From: johan.hedberg @ 2013-11-05  9:30 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The SMP security request is for a slave role device to request the
master role device to initiate a pairing request. If we receive this
command while we're in the slave role we should reject it appropriately.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 85a2796cac61..4b07acb8293c 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -742,6 +742,9 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
 
 	BT_DBG("conn %p", conn);
 
+	if (!(conn->hcon->link_mode & HCI_LM_MASTER))
+		return SMP_CMD_NOTSUPP;
+
 	hcon->pending_sec_level = authreq_to_seclevel(rp->auth_req);
 
 	if (smp_ltk_encrypt(conn, hcon->pending_sec_level))
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCH] android/daemon: Send update name notification on mgmt evt
From: Luiz Augusto von Dentz @ 2013-11-05  9:05 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1383641621-25933-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Tue, Nov 5, 2013 at 10:53 AM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Wehen receiving mgmt event local_name_changed we shall send notification
> to the HAL that local name is changed.
> ---
>  android/adapter.c |   46 +++++++++++++++++++++++-----------------------
>  1 file changed, 23 insertions(+), 23 deletions(-)
>
> diff --git a/android/adapter.c b/android/adapter.c
> index 383cf07..b6f6096 100644
> --- a/android/adapter.c
> +++ b/android/adapter.c
> @@ -66,6 +66,28 @@ struct bt_adapter {
>  static struct bt_adapter *adapter;
>  static GSList *found_devices = NULL;
>
> +static void adapter_name_changed(const uint8_t *name)
> +{
> +       struct hal_ev_adapter_props_changed *ev;
> +       size_t len = strlen((const char *) name);
> +       uint8_t buf[sizeof(*ev) + sizeof(struct hal_property) + len];
> +
> +       memset(buf, 0, sizeof(buf));
> +       ev = (void *) buf;
> +
> +       ev->num_props = 1;
> +       ev->status = HAL_STATUS_SUCCESS;
> +       ev->props[0].type = HAL_PROP_ADAPTER_NAME;
> +       /* Android expects value without NULL terminator */
> +       ev->props[0].len = len;
> +       memcpy(ev->props->val, name, len);
> +
> +       DBG("Adapter name changed to: %s", name);
> +
> +       ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
> +                       HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev, -1);
> +}
> +
>  static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
>                                         const void *param, void *user_data)
>  {
> @@ -84,7 +106,7 @@ static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
>         g_free(adapter->name);
>         adapter->name = g_strdup((const char *) rp->name);
>
> -       /* TODO Update services if needed */
> +       adapter_name_changed(rp->name);
>  }

This is okay, but you should call this function from
set_adapter_name_complete to make sure we are synchronized with the
upper stack.

^ permalink raw reply

* [PATCH] android/daemon: Send update name notification on mgmt evt
From: Andrei Emeltchenko @ 2013-11-05  8:53 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Wehen receiving mgmt event local_name_changed we shall send notification
to the HAL that local name is changed.
---
 android/adapter.c |   46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 383cf07..b6f6096 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -66,6 +66,28 @@ struct bt_adapter {
 static struct bt_adapter *adapter;
 static GSList *found_devices = NULL;
 
+static void adapter_name_changed(const uint8_t *name)
+{
+	struct hal_ev_adapter_props_changed *ev;
+	size_t len = strlen((const char *) name);
+	uint8_t buf[sizeof(*ev) + sizeof(struct hal_property) + len];
+
+	memset(buf, 0, sizeof(buf));
+	ev = (void *) buf;
+
+	ev->num_props = 1;
+	ev->status = HAL_STATUS_SUCCESS;
+	ev->props[0].type = HAL_PROP_ADAPTER_NAME;
+	/* Android expects value without NULL terminator */
+	ev->props[0].len = len;
+	memcpy(ev->props->val, name, len);
+
+	DBG("Adapter name changed to: %s", name);
+
+	ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+			HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev, -1);
+}
+
 static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -84,7 +106,7 @@ static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
 	g_free(adapter->name);
 	adapter->name = g_strdup((const char *) rp->name);
 
-	/* TODO Update services if needed */
+	adapter_name_changed(rp->name);
 }
 
 static void powered_changed(void)
@@ -142,28 +164,6 @@ static void scan_mode_changed(void)
 	g_free(ev);
 }
 
-static void adapter_name_changed(const uint8_t *name)
-{
-	struct hal_ev_adapter_props_changed *ev;
-	size_t len = strlen((const char *) name);
-	uint8_t buf[sizeof(*ev) + sizeof(struct hal_property) + len];
-
-	memset(buf, 0, sizeof(buf));
-	ev = (void *) buf;
-
-	ev->num_props = 1;
-	ev->status = HAL_STATUS_SUCCESS;
-	ev->props[0].type = HAL_PROP_ADAPTER_NAME;
-	/* Android expects value without NULL terminator */
-	ev->props[0].len = len;
-	memcpy(ev->props->val, name, len);
-
-	DBG("Adapter name changed to: %s", name);
-
-	ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
-			HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev, -1);
-}
-
 static void settings_changed(uint32_t settings)
 {
 	uint32_t changed_mask;
-- 
1.7.10.4


^ permalink raw reply related

* Re: [PATCH 07/11] android/hid: Implement hid set report in daemon
From: Johan Hedberg @ 2013-11-05  8:31 UTC (permalink / raw)
  To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383603615-9953-8-git-send-email-ravikumar.veeramally@linux.intel.com>

Hi Ravi,

On Tue, Nov 05, 2013, Ravi kumar Veeramally wrote:
> This patch requests hid device to set report.
> ---
>  android/hal-hidhost.c |  1 +
>  android/hal-msg.h     |  1 +
>  android/hid.c         | 40 ++++++++++++++++++++++++++++++++++++++--
>  3 files changed, 40 insertions(+), 2 deletions(-)

Again, split this into separate patches.

> diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
> index 027e3b8..040d517 100644
> --- a/android/hal-hidhost.c
> +++ b/android/hal-hidhost.c
> @@ -284,6 +284,7 @@ static bt_status_t hh_set_report(bt_bdaddr_t *bd_addr,
>  		return BT_STATUS_PARM_INVALID;
>  
>  	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
> +	cmd.report = report;
>  
>  	switch (reportType) {
>  	case BTHH_INPUT_REPORT:
> diff --git a/android/hal-msg.h b/android/hal-msg.h
> index eaa5c9c..e1fd027 100644
> --- a/android/hal-msg.h
> +++ b/android/hal-msg.h
> @@ -292,6 +292,7 @@ struct hal_cmd_hid_get_report {
>  struct hal_cmd_hid_set_report {
>  	uint8_t bdaddr[6];
>  	uint8_t type;
> +	char *report;
>  } __attribute__((packed));

Seriously? Trying to send pointers over IPC :)

Also verify that whatever you add matches what we have in
hal-ipc-api.txt (and if the API documentation is wrong or missing
something fix it).

Johan

^ permalink raw reply

* Re: [PATCH 11/11] android/hid: Handle uhid events
From: Andrei Emeltchenko @ 2013-11-05  8:29 UTC (permalink / raw)
  To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383603615-9953-12-git-send-email-ravikumar.veeramally@linux.intel.com>

Hi Ravi,

On Tue, Nov 05, 2013 at 12:20:15AM +0200, Ravi kumar Veeramally wrote:
> Handling few uhid events and described scenarios. OUTPUT and
> FEATURE events are not yet handled.
> ---
>  android/hid.c | 40 +++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 39 insertions(+), 1 deletion(-)
> 
> diff --git a/android/hid.c b/android/hid.c
> index 74de02f..fccaa87 100644
> --- a/android/hid.c
> +++ b/android/hid.c
> @@ -149,6 +149,11 @@ static void hid_device_free(struct hid_device *dev)
>  	g_free(dev);
>  }
>  
> +static void handle_uhid_event(struct hid_device *dev, struct uhid_event *ev)
> +{
> +	DBG("unsupported event");
> +}
> +
>  static gboolean uhid_event_cb(GIOChannel *io, GIOCondition cond,
>  							gpointer user_data)
>  {
> @@ -172,7 +177,40 @@ static gboolean uhid_event_cb(GIOChannel *io, GIOCondition cond,
>  	}
>  
>  	DBG("uHID event type %d received", ev.type);
> -	/* TODO Handle events */
> +
> +	switch (ev.type) {
> +	case UHID_START:
> +	case UHID_STOP:
> +		/* These are called to start and stop the underlying hardware.
> +		 * We open the channels before creating the device so the
> +		 * hardware is always ready. No need to handle these.
> +		 * The kernel never destroys a device itself! Only an explicit
> +		 * UHID_DESTROY request can remove a device. */
> +
> +		break;
> +	case UHID_OPEN:
> +	case UHID_CLOSE:
> +		/* OPEN/CLOSE are sent whenever user-space opens any interface
> +		 * provided by the kernel HID device. Whenever the open-count
> +		 * is non-zero we must be ready for I/O. As long as it is zero,
> +		 * we can decide to drop all I/O and put the device
> +		 * asleep This is optional, though. */
> +		break;
> +	case UHID_OUTPUT:
> +	case UHID_FEATURE:
> +		handle_uhid_event(dev, &ev);
> +		break;
> +	case UHID_OUTPUT_EV:
> +		/* This is only sent by kernels prior to linux-3.11. It
> +		 * requires us to parse HID-descriptors in user-space to
> +		 * properly handle it. This is redundant as the kernel
> +		 * does it already. That's why newer kernels assemble
> +		 * the output-reports and send it to us via UHID_OUTPUT. */
> +		DBG("Unsupported uHID event: type %d", ev.u.output_ev.type);

Use handle_uhid_event helper? You could add printing event type there.

Best regards 
Andrei Emeltchenko 

> +		break;
> +	default:
> +		warn("unexpected uHID event");
> +	}
>  
>  	return TRUE;
>  
> -- 
> 1.8.1.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* Re: [PATCH 06/11] android/hid: Implement hid get report in daemon
From: Johan Hedberg @ 2013-11-05  8:29 UTC (permalink / raw)
  To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383603615-9953-7-git-send-email-ravikumar.veeramally@linux.intel.com>

Hi Ravi,

On Tue, Nov 05, 2013, Ravi kumar Veeramally wrote:
> This patch requests hid device report and reads reply
> message and sends notification to hal.
> ---
>  android/hal-hidhost.c |   1 +
>  android/hal-msg.h     |   8 ++++
>  android/hid.c         | 104 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 111 insertions(+), 2 deletions(-)

Again, I'd split this into separate patches. One to update the
hal-msg.h, one for the daemon and another for the HAL.

> +#define HAL_EV_HID_GET_REPORT		0x84
> +struct hal_ev_hid_get_report {
> +	uint8_t bdaddr[6];
> +	uint8_t status;
> +	uint16_t len;
> +	uint8_t data[0];
> +} __attribute__((packed));

In our hal-ipc.api.txt this event is defined as 0x85. Not 0x84. Is the
code or documentation wrong?

Also, please follow the same alignment for the variables in the struct
as elsewhere in hal-msg.h.

Johan

^ permalink raw reply

* Re: [PATCH 03/11] android/hid: Implement hid get protocol in daemon
From: Johan Hedberg @ 2013-11-05  8:24 UTC (permalink / raw)
  To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383603615-9953-4-git-send-email-ravikumar.veeramally@linux.intel.com>

Hi Ravi,

On Tue, Nov 05, 2013, Ravi kumar Veeramally wrote:
> This patch requests hid device protocol mode and reads reply
> message and sends notification to hal.
> ---
>  android/hal-msg.h |   9 +++++
>  android/hid.c     | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  2 files changed, 113 insertions(+), 4 deletions(-)

I've applied patches 1 and 2, but from this one onwards there were
sevaral issues.

> diff --git a/android/hal-msg.h b/android/hal-msg.h
> index f381862..214daa9 100644
> --- a/android/hal-msg.h
> +++ b/android/hal-msg.h
> @@ -442,6 +442,8 @@ struct hal_ev_hid_conn_state {
>  	uint8_t state;
>  } __attribute__((packed));
>  
> +#define HAL_HID_STATUS_OK		0x00
> +
>  #define HAL_EV_HID_INFO			0x82
>  struct hal_ev_hid_info {
>  	uint8_t bdaddr[6];
> @@ -456,6 +458,13 @@ struct hal_ev_hid_info {
>  	uint8_t descr[884];
>  } __attribute__((packed));
>  
> +#define HAL_EV_HID_PROTO_MODE		0x83
> +struct hal_ev_hid_protocol {
> +	uint8_t bdaddr[6];
> +	uint8_t status;
> +	uint8_t mode;
> +} __attribute__((packed));

To be consistent, shouldn't the struct be called hal_ev_hid_proto_mode?

Also, I'd split this hal-msg.h update into a separate patch. Am I right
to assume hal-ipc-api.txt doesn't need updating for this one?

> @@ -76,6 +84,7 @@ struct hid_device {
>  	guint		intr_watch;
>  	int		uhid_fd;
>  	guint		uhid_watch_id;
> +	int		hid_msg;
>  };
>  
>  static int device_cmp(gconstpointer s, gconstpointer user_data)
> @@ -243,12 +252,74 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond,
>  	return FALSE;
>  }
>  
> +static void bt_hid_notify_protocol_mode(struct hid_device *dev, uint8_t *buf,
> +									int len)

To be consistent with the struct names you might use "proto" instead of
"protocol" here.

> +static gboolean ctrl_io_watch_cb(GIOChannel *chan, gpointer data)
> +{
> +	struct hid_device *dev = data;
> +	int fd, bread;
> +	uint8_t buf[UHID_DATA_MAX];
> +
> +	DBG("");
> +
> +	fd = g_io_channel_unix_get_fd(chan);
> +	bread = read(fd, buf, sizeof(buf));
> +	if (bread < 0) {
> +		error("read: %s(%d)", strerror(errno), -errno);
> +		return TRUE;
> +	}
> +
> +	switch (dev->hid_msg) {
> +	case HID_MSG_GET_PROTOCOL:
> +		bt_hid_notify_protocol_mode(dev, buf, bread);
> +		break;
> +	default:
> +		DBG("unhandled hid msg type 0x%02x", dev->hid_msg);
> +	}
> +
> +	/* reset msg type request */
> +	dev->hid_msg = -1;

Do we really need to do this tracking of what we wrote to the socket.
Isn't it possible to infer the type of procedure from the content of the
data that we read from the socket?

Johan

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox