Linux bluetooth development
 help / color / mirror / Atom feed
* Re: [PATCH] Bluetooth: hidp: make sure input buffers are big enough
From: Jiri Kosina @ 2014-01-07 17:13 UTC (permalink / raw)
  To: David Herrmann
  Cc: Marcel Holtmann, open list:HID CORE LAYER,
	linux-bluetooth@vger.kernel.org development, Gustavo F. Padovan
In-Reply-To: <CANq1E4SxrDnbOCsohZXYoYL-HQjEc-xcOnXfAm=npHG2QfMS9A@mail.gmail.com>

On Tue, 7 Jan 2014, David Herrmann wrote:

> > So doing kzalloc(rsize, GFP_ATOMIC) in the HID-core for now, and copying
> > the buffer around, seems like only viable solution for now, with the
> > outlook of removing this ugliness once hid-core honors 'size' properly.
> 
> Should I resend the patches and move it to hid_input_report() for now?
> Or are you getting something in yourself?

Due to various reasons I will not have access to any testing HW for the 
upcoming 2-3 days, so if you can cook something up in that timeframe, it'd 
be appreciated.

Otherwise I'll be working on it by the end of this week.

> Given the amount of reports on the list and bugzilla, I think we should 
> get this fix in asap. We can always fix it properly in -next.

Agreed.

Thanks,

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply

* Re: [PATCH] Bluetooth: hidp: make sure input buffers are big enough
From: David Herrmann @ 2014-01-07 16:34 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Marcel Holtmann, open list:HID CORE LAYER,
	linux-bluetooth@vger.kernel.org development, Gustavo F. Padovan
In-Reply-To: <alpine.LNX.2.00.1401071308020.4962@pobox.suse.cz>

Hi Jiri

On Tue, Jan 7, 2014 at 1:11 PM, Jiri Kosina <jkosina@suse.cz> wrote:
> On Fri, 27 Dec 2013, David Herrmann wrote:
>
>> >> I also haven't figured out a nice way to make HID-core honor the
>> >> "size" parameter. hid-input depends on getting the whole
>> >> input-report.
>> >
>> > I think this needs clearly fixing.
>>
>> And we have a volunteer, yippie! ;)
>>
>> I think hid_input_report() in hid-core.c is the only place that relies
>> on this. Maybe it really is easier to fix it. But I am not even
>> slightly familiar with that code. So if no-one of the HID core
>> developers steps up to fix it, we should take the transport-driver
>> fixes instead. As nearly all transport-drivers are affected by this,
>> maybe we should even move this buffer into hid_device and provide
>> hid_input_truncated_report() which does this.
>>
>> Anyhow, waiting for Jiri's comments on this.
>
> Hmm, this is really unfortunate situation.
>
> I am now looking into making hid_input_report() honor 'size' properly, but
> no matter how it'll be done in the end, it'll absolutely not be a simple
> 'fix'. So definitely can be done for 3.15 or so, but not as a fix for
> current kernels.
>
> So doing kzalloc(rsize, GFP_ATOMIC) in the HID-core for now, and copying
> the buffer around, seems like only viable solution for now, with the
> outlook of removing this ugliness once hid-core honors 'size' properly.

Should I resend the patches and move it to hid_input_report() for now?
Or are you getting something in yourself?
Given the amount of reports on the list and bugzilla, I think we
should get this fix in asap. We can always fix it properly in -next.

Thanks
David

> I will keep looking into this and maybe some easy way how to hack this
> together will materialize, but I don't currently see it.
>
> Hmm ...
>
> --
> Jiri Kosina
> SUSE Labs

^ permalink raw reply

* [PATCH] android: Cleanup Android.mk
From: Szymon Janc @ 2014-01-07 15:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Remove not needed headers file in source list (Android build handles
this), explicitly mark packages as optional and fix bluetooth.default
dependencies (it should not depend on haltest as it is optional debug
package and should not be installed in user build).
---
 android/Android.mk | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/android/Android.mk b/android/Android.mk
index 27631cc..16339b1 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -25,8 +25,8 @@ LOCAL_SRC_FILES := \
 	bluetooth.c \
 	hidhost.c \
 	socket.c \
-	ipc.c ipc.h \
-	audio-ipc.c audio-ipc.h \
+	ipc.c \
+	audio-ipc.c \
 	avdtp.c \
 	a2dp.c \
 	pan.c \
@@ -75,6 +75,8 @@ $(shell mkdir -p $(LOCAL_PATH)/../lib/bluetooth)
 
 $(foreach file,$(lib_headers), $(shell ln -sf ../$(file) $(LOCAL_PATH)/../lib/bluetooth/$(file)))
 
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := bluetoothd
 
 include $(BUILD_EXECUTABLE)
@@ -107,7 +109,7 @@ LOCAL_MODULE := bluetooth.default
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
-LOCAL_REQUIRED_MODULES := haltest bluetoothd
+LOCAL_REQUIRED_MODULES := bluetoothd bluetoothd-snoop
 
 include $(BUILD_SHARED_LIBRARY)
 
@@ -146,7 +148,8 @@ LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
 
 LOCAL_SHARED_LIBRARIES := libhardware
 
-LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := debug
 LOCAL_MODULE := haltest
 
 include $(BUILD_EXECUTABLE)
@@ -159,42 +162,23 @@ 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 \
-	../monitor/hwdb.h \
 	../monitor/hwdb.c \
-	../monitor/ellisys.h \
 	../monitor/ellisys.c \
-	../monitor/analyze.h \
 	../monitor/analyze.c \
-	../src/shared/util.h \
 	../src/shared/util.c \
-	../src/shared/queue.h \
 	../src/shared/queue.c \
 	../lib/hci.c \
 	../lib/bluetooth.c \
-- 
1.8.3.2


^ permalink raw reply related

* pull request: bluetooth-next 2014-01-07
From: Gustavo Padovan @ 2014-01-07 15:22 UTC (permalink / raw)
  To: linville, linux-wireless, linux-bluetooth, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 4007 bytes --]

Hi John,

More patches to 3.14. The bulk of changes here is the 6LoWPAN support for
Bluetooth LE Devices. The commits that touches net/ieee802154/ are already
acked by David Miller. Other than that we have some RFCOMM fixes and
improvements plus fixes and clean ups all over the tree.

Please pull, or let me know of any concerns you have.

	Gustavo

---
The following changes since commit 71fb419724fadab4efdf98210aa3fe053bd81d29:

  Bluetooth: Fix handling of L2CAP Command Reject over LE (2013-12-10 01:15:44 -0800)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git for-upstream

for you to fetch changes up to e825eb1d7e06f616003c17e2e8e421c2e5e44142:

  Bluetooth: Fix 6loWPAN peer lookup (2014-01-07 11:32:15 -0200)

----------------------------------------------------------------
Alexander Aring (9):
      6lowpan: fix/move/cleanup debug functions
      6lowpan: introduce lowpan_push_hc_data function
      6lowpan: udp use lowpan_push_hc_data function
      6lowpan: fix udp compress ordering
      6lowpan: fix udp byte ordering
      6lowpan: add udp warning for elided checksum
      6lowpan: udp use lowpan_fetch_skb function
      6lowpan: udp use subtraction on both conditions
      6lowpan: cleanup udp compress function

Claudio Takahasi (2):
      Bluetooth: Fix setting Universal/Local bit
      Bluetooth: Fix 6loWPAN peer lookup

Gianluca Anzolin (4):
      Bluetooth: Release RFCOMM port when the last user closes the TTY
      Bluetooth: Move rfcomm_get_device() before rfcomm_dev_activate()
      Bluetooth: Always wait for a connection on RFCOMM open()
      Bluetooth: Remove rfcomm_carrier_raised()

Johan Hedberg (4):
      Bluetooth: Add missing 6lowpan.h include
      Bluetooth: Fix test for lookup_dev return value
      Bluetooth: Fix NULL pointer dereference when disconnecting
      Bluetooth: Default to no security with L2CAP RAW sockets

Jukka Rissanen (5):
      6lowpan: Moving generic compression code into 6lowpan_iphc.c
      net: if_arp: add ARPHRD_6LOWPAN type
      ipv6: Add checks for 6LOWPAN ARP type
      Bluetooth: Enable 6LoWPAN support for BT LE devices
      Bluetooth: Manually enable or disable 6LoWPAN between devices

Marcel Holtmann (5):
      Bluetooth: Set HCI_QUIRK_RESET_ON_CLOSE for Socket SDIO cards
      Bluetooth: Add support for vectored writes to virtual HCI driver
      Bluetooth: Use MD SET register for changing SDIO Type-B to Type-A
      Bluetooth: Add quirk for disabling Delete Stored Link Key command
      Bluetooth: Deal with USB devices that are faking CSR vendor

Wei Yongjun (2):
      Bluetooth: remove unused including <linux/version.h>
      Bluetooth: fix return value check

 drivers/bluetooth/btsdio.c       |   6 +-
 drivers/bluetooth/btusb.c        |  46 +++-
 drivers/bluetooth/hci_vhci.c     |  29 ++-
 include/net/bluetooth/hci.h      |   4 +-
 include/net/bluetooth/hci_core.h |   1 +
 include/net/bluetooth/l2cap.h    |   1 +
 include/uapi/linux/if_arp.h      |   1 +
 net/bluetooth/6lowpan.c          | 860 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/bluetooth/6lowpan.h          |  26 +++
 net/bluetooth/Makefile           |   6 +-
 net/bluetooth/hci_core.c         |  52 ++++-
 net/bluetooth/hci_event.c        |   3 +
 net/bluetooth/l2cap_core.c       |  12 ++
 net/bluetooth/l2cap_sock.c       |   3 +
 net/bluetooth/rfcomm/tty.c       | 103 +++++----
 net/ieee802154/6lowpan.c         | 796 ++++---------------------------------------------------------------
 net/ieee802154/6lowpan.h         |  72 +++++++
 net/ieee802154/6lowpan_iphc.c    | 799 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/ieee802154/Makefile          |   2 +-
 net/ipv6/addrconf.c              |   4 +-
 20 files changed, 2015 insertions(+), 811 deletions(-)
 create mode 100644 net/bluetooth/6lowpan.c
 create mode 100644 net/bluetooth/6lowpan.h
 create mode 100644 net/ieee802154/6lowpan_iphc.c


[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* [PATCH -next] Bluetooth: Convert to use ATTRIBUTE_GROUPS macro
From: Wei Yongjun @ 2014-01-07 14:23 UTC (permalink / raw)
  To: marcel, gustavo, johan.hedberg; +Cc: yongjun_wei, linux-bluetooth

From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Use ATTRIBUTE_GROUPS macro to reduce the number of lines of code.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 net/bluetooth/hci_sysfs.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 0b61250..555982a 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -49,14 +49,7 @@ static struct attribute *bt_link_attrs[] = {
 	NULL
 };
 
-static struct attribute_group bt_link_group = {
-	.attrs = bt_link_attrs,
-};
-
-static const struct attribute_group *bt_link_groups[] = {
-	&bt_link_group,
-	NULL
-};
+ATTRIBUTE_GROUPS(bt_link);
 
 static void bt_link_release(struct device *dev)
 {
@@ -182,14 +175,7 @@ static struct attribute *bt_host_attrs[] = {
 	NULL
 };
 
-static struct attribute_group bt_host_group = {
-	.attrs = bt_host_attrs,
-};
-
-static const struct attribute_group *bt_host_groups[] = {
-	&bt_host_group,
-	NULL
-};
+ATTRIBUTE_GROUPS(bt_host);
 
 static void bt_host_release(struct device *dev)
 {

^ permalink raw reply related

* [PATCH] android-tester: Add HIDHost initial interface setup test
From: Ravi kumar Veeramally @ 2014-01-07 14:18 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally

---
 android/android-tester.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 9a161ad..e4837c6 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -39,6 +39,7 @@
 #include <hardware/hardware.h>
 #include <hardware/bluetooth.h>
 #include <hardware/bt_sock.h>
+#include <hardware/bt_hh.h>
 
 #include "utils.h"
 
@@ -79,6 +80,7 @@ struct test_data {
 	struct hw_device_t *device;
 	const bt_interface_t *if_bluetooth;
 	const btsock_interface_t *if_sock;
+	const bthh_interface_t *if_hid;
 
 	bool mgmt_settings_set;
 	bool cb_count_checked;
@@ -958,6 +960,16 @@ static bt_callbacks_t bt_callbacks = {
 	.le_test_mode_cb = NULL
 };
 
+static bthh_callbacks_t bthh_callbacks = {
+	.size = sizeof(bthh_callbacks),
+	.connection_state_cb = NULL,
+	.hid_info_cb = NULL,
+	.protocol_mode_cb = NULL,
+	.idle_time_cb = NULL,
+	.get_report_cb = NULL,
+	.virtual_unplug_cb = NULL
+};
+
 static void setup(struct test_data *data)
 {
 	const hw_module_t *module;
@@ -1069,6 +1081,11 @@ static void teardown(const void *test_data)
 		data->if_bluetooth = NULL;
 	}
 
+	if (data->if_hid) {
+		data->if_hid->cleanup();
+		data->if_hid = NULL;
+	}
+
 	data->device->close(data->device);
 
 	if (data->bluetoothd_pid)
@@ -1860,6 +1877,32 @@ clean:
 		close(sock_fd);
 }
 
+static void setup_hidhost_interface(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	bt_status_t status;
+	const void *hid;
+
+	setup(data);
+
+	status = data->if_hid->init(&bthh_callbacks);
+	if (status != BT_STATUS_SUCCESS) {
+		data->if_hid = NULL;
+		tester_setup_failed();
+		return;
+	}
+
+	hid = data->if_bluetooth->get_profile_interface(BT_PROFILE_HIDHOST_ID);
+	if (!hid) {
+		tester_setup_failed();
+		return;
+	}
+
+	data->if_hid = hid;
+
+	tester_setup_complete();
+}
+
 #define test_bredrle(name, data, test_setup, test, test_teardown) \
 	do { \
 		struct test_data *user; \
@@ -2071,5 +2114,8 @@ int main(int argc, char *argv[])
 			setup_socket_interface_enabled,
 			test_socket_real_connect, teardown);
 
+	test_bredrle("HIDHost Init", NULL, setup_hidhost_interface,
+						test_dummy, teardown);
+
 	return tester_run();
 }
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH v3 3/3] android: Send remote devices properties on enable
From: Lukasz Rymanowski @ 2014-01-07 14:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
In-Reply-To: <1389104030-21314-1-git-send-email-lukasz.rymanowski@tieto.com>

If there is any bonded device stored then on bluetooth enable we
should send notification with its properties.

---
 android/bluetooth.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index e0673bb..9da988b 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2636,6 +2636,18 @@ static void get_remote_device_props(struct device *dev)
 	get_device_timestamp(dev);
 }
 
+static void send_bonded_devices_props(void)
+{
+	GSList *l;
+
+	for (l = devices; l; l = g_slist_next(l)) {
+		struct device *dev = l->data;
+
+		if (dev->bond_state == HAL_BOND_STATE_BONDED)
+			get_remote_device_props(dev);
+	}
+}
+
 static void handle_enable_cmd(const void *buf, uint16_t len)
 {
 	uint8_t status;
@@ -2644,6 +2656,9 @@ static void handle_enable_cmd(const void *buf, uint16_t len)
 	 * enabling adapter */
 	get_adapter_properties();
 
+	/* Sent also properties of bonded devices */
+	send_bonded_devices_props();
+
 	if (adapter.current_settings & MGMT_SETTING_POWERED) {
 		status = HAL_STATUS_DONE;
 		goto failed;
-- 
1.8.4


^ permalink raw reply related

* [PATCH v3 2/3] android: Move get_remote_device_props up in the file
From: Lukasz Rymanowski @ 2014-01-07 14:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
In-Reply-To: <1389104030-21314-1-git-send-email-lukasz.rymanowski@tieto.com>

This patch moves up function get_remote_device_props() and all
functions required by this function.

---
 android/bluetooth.c | 100 ++++++++++++++++++++++++++--------------------------
 1 file changed, 50 insertions(+), 50 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index f281fcf..e0673bb 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2550,56 +2550,6 @@ static void handle_get_remote_services_cmd(const void *buf, uint16_t len)
 									status);
 }
 
-static void handle_enable_cmd(const void *buf, uint16_t len)
-{
-	uint8_t status;
-
-	/* Framework expects all properties to be emitted while
-	 * enabling adapter */
-	get_adapter_properties();
-
-	if (adapter.current_settings & MGMT_SETTING_POWERED) {
-		status = HAL_STATUS_DONE;
-		goto failed;
-	}
-
-	if (!set_mode(MGMT_OP_SET_POWERED, 0x01)) {
-		status = HAL_STATUS_FAILED;
-		goto failed;
-	}
-
-	status = HAL_STATUS_SUCCESS;
-failed:
-	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_ENABLE, status);
-}
-
-static void handle_disable_cmd(const void *buf, uint16_t len)
-{
-	uint8_t status;
-
-	if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
-		status = HAL_STATUS_DONE;
-		goto failed;
-	}
-
-	if (!set_mode(MGMT_OP_SET_POWERED, 0x00)) {
-		status = HAL_STATUS_FAILED;
-		goto failed;
-	}
-
-	status = HAL_STATUS_SUCCESS;
-failed:
-	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DISABLE, status);
-}
-
-static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
-{
-	get_adapter_properties();
-
-	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
-							HAL_STATUS_SUCCESS);
-}
-
 static uint8_t get_device_uuids(struct device *dev)
 {
 	send_device_uuids_notif(dev);
@@ -2686,6 +2636,56 @@ static void get_remote_device_props(struct device *dev)
 	get_device_timestamp(dev);
 }
 
+static void handle_enable_cmd(const void *buf, uint16_t len)
+{
+	uint8_t status;
+
+	/* Framework expects all properties to be emitted while
+	 * enabling adapter */
+	get_adapter_properties();
+
+	if (adapter.current_settings & MGMT_SETTING_POWERED) {
+		status = HAL_STATUS_DONE;
+		goto failed;
+	}
+
+	if (!set_mode(MGMT_OP_SET_POWERED, 0x01)) {
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
+	status = HAL_STATUS_SUCCESS;
+failed:
+	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_ENABLE, status);
+}
+
+static void handle_disable_cmd(const void *buf, uint16_t len)
+{
+	uint8_t status;
+
+	if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
+		status = HAL_STATUS_DONE;
+		goto failed;
+	}
+
+	if (!set_mode(MGMT_OP_SET_POWERED, 0x00)) {
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
+	status = HAL_STATUS_SUCCESS;
+failed:
+	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DISABLE, status);
+}
+
+static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
+{
+	get_adapter_properties();
+
+	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
+							HAL_STATUS_SUCCESS);
+}
+
 static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_get_remote_device_props *cmd = buf;
-- 
1.8.4


^ permalink raw reply related

* [PATCH v3 1/3] android: Add wrapper function for get remote dev properties
From: Lukasz Rymanowski @ 2014-01-07 14:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski

---
 android/bluetooth.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 3cbf68d..f281fcf 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2673,6 +2673,19 @@ static uint8_t get_device_timestamp(struct device *dev)
 	return HAL_STATUS_SUCCESS;
 }
 
+static void get_remote_device_props(struct device *dev)
+{
+	get_device_name(dev);
+	get_device_uuids(dev);
+	get_device_class(dev);
+	get_device_type(dev);
+	get_device_service_rec(dev);
+	get_device_friendly_name(dev);
+	get_device_rssi(dev);
+	get_device_version_info(dev);
+	get_device_timestamp(dev);
+}
+
 static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_get_remote_device_props *cmd = buf;
@@ -2688,15 +2701,7 @@ static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	get_device_name(l->data);
-	get_device_uuids(l->data);
-	get_device_class(l->data);
-	get_device_type(l->data);
-	get_device_service_rec(l->data);
-	get_device_friendly_name(l->data);
-	get_device_rssi(l->data);
-	get_device_version_info(l->data);
-	get_device_timestamp(l->data);
+	get_remote_device_props(l->data);
 
 	status = HAL_STATUS_SUCCESS;
 
-- 
1.8.4


^ permalink raw reply related

* Re: [PATCH BlueZ 06/12] tools: Fix unaligned memory access on smp-tester
From: Anderson Lizardo @ 2014-01-07 13:40 UTC (permalink / raw)
  To: Anderson Lizardo, BlueZ development
In-Reply-To: <20140106192520.GA25270@x220.p-661hnu-f1>

[-- Attachment #1: Type: text/plain, Size: 3666 bytes --]

Hi Johan,

On Mon, Jan 6, 2014 at 3:25 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> This code was essentially a direct copy of what the kernel side SMP
> implementation does. Does this mean we have a problem on the kernel side
> too? Could you send a patch for that (after confirming that we do have a
> problem there too).

Checking the kernel compilation parameters, I see -Wcast-align (which
enables these warnings both on gcc and clang) is only passed if you
compile the kernel with W=2 (i.e. "make W=2 ..."). But it then enables
a ton of other warnings. I can see why they don't enable these
warnings by default.

So I did a small experiment to confirm that the code snippet you
copied from the kernel will give the same warnings with -Wcast-align
when building the kernel. I first compiled bluetooth.ko using the GCC
on my x86-64 system:

rm -rf build_test
mkdir build_test
make O=build_test allmodconfig modules_prepare
make O=build_test W=2 warning-2=-Wcast-align net/bluetooth/bluetooth.ko

This gave no warnings (maybe because x86 has no such alignment
issues?). I then downloaded the latest codesourcery ARM crosscompiler
and built bluetooth.ko for ARM with -Wcast-align (adding "ARCH=arm
CROSS_COMPILE=/opt/arm-2013.11/bin/arm-none-linux-gnueabi-" to the two
make commands). It gives 1.2MB of warnings, amongst them the ones
related to the copied code:


/home/lizardo/trees/linux.git/net/bluetooth/smp.c: In function 'smp_c1':
/home/lizardo/trees/linux.git/net/bluetooth/smp.c:103:11: warning:
cast increases required alignment of target type [-Wcast-align]
  u128_xor((u128 *) res, (u128 *) r, (u128 *) p1);
           ^
/home/lizardo/trees/linux.git/net/bluetooth/smp.c:103:25: warning:
cast increases required alignment of target type [-Wcast-align]
  u128_xor((u128 *) res, (u128 *) r, (u128 *) p1);
                         ^
/home/lizardo/trees/linux.git/net/bluetooth/smp.c:103:37: warning:
cast increases required alignment of target type [-Wcast-align]
  u128_xor((u128 *) res, (u128 *) r, (u128 *) p1);
                                     ^
/home/lizardo/trees/linux.git/net/bluetooth/smp.c:113:11: warning:
cast increases required alignment of target type [-Wcast-align]
  u128_xor((u128 *) res, (u128 *) res, (u128 *) p2);
           ^
/home/lizardo/trees/linux.git/net/bluetooth/smp.c:113:25: warning:
cast increases required alignment of target type [-Wcast-align]
  u128_xor((u128 *) res, (u128 *) res, (u128 *) p2);
                         ^
/home/lizardo/trees/linux.git/net/bluetooth/smp.c:113:39: warning:
cast increases required alignment of target type [-Wcast-align]
  u128_xor((u128 *) res, (u128 *) res, (u128 *) p2);
                                       ^

But note that there are lots of similar warnings on other kernel code,
specially from common headers. So I can only conclude that, at least
for kernel code, having these alignment requirements increased due to
cast is not considered an issue. So my suggestion is to keep the
kernel code as is, unless there is some indication that this may cause
problems.

On the other hand, on BlueZ we have traditionally taken care of fixing
these warnings (specially when people try to build for ARM and get
errors due to -Werror), so It's a good thing that clang detects it
even when building for x86. Given that it was the only place I got
this warning on BlueZ, it seemed fine to fix it like we did in the
past.

PS: I attached the compressed build log (when building only
bluetooth.ko for ARM with -Wcast-align). Unfortunately, it is too
polluted to attempt to analyze manually.

Best Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

[-- Attachment #2: build.log.xz --]
[-- Type: application/x-xz, Size: 16704 bytes --]

^ permalink raw reply

* Re: [PATCH 2/2] Bluetooth: Fix 6loWPAN peer lookup
From: Gustavo Padovan @ 2014-01-07 13:33 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1389096468-2917-2-git-send-email-claudio.takahasi@openbossa.org>

Hi Claudio,

2014-01-07 Claudio Takahasi <claudio.takahasi@openbossa.org>:

> This patch fixes peer address lookup for 6loWPAN over Bluetooth Low
> Energy links.
> 
> ADDR_LE_DEV_PUBLIC, and ADDR_LE_DEV_RANDOM are the values allowed for
> "dst_type" field in the hci_conn struct for LE links.
> 
> Signed-off-by: Claudio Takahasi <claudio.takahasi@openbossa.org>
> ---
>  net/bluetooth/6lowpan.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Both patches have been applied to bluetooth-next. Thanks.

	Gustavo

^ permalink raw reply

* [PATCH v2 2/2] android: Send remote devices properties on enable
From: Lukasz Rymanowski @ 2014-01-07 12:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
In-Reply-To: <1389098592-14403-1-git-send-email-lukasz.rymanowski@tieto.com>

If there is any bonded device stored then on bluetooth enable we
should send notification with its properties.

---
 android/bluetooth.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index e0673bb..9da988b 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2636,6 +2636,18 @@ static void get_remote_device_props(struct device *dev)
 	get_device_timestamp(dev);
 }
 
+static void send_bonded_devices_props(void)
+{
+	GSList *l;
+
+	for (l = devices; l; l = g_slist_next(l)) {
+		struct device *dev = l->data;
+
+		if (dev->bond_state == HAL_BOND_STATE_BONDED)
+			get_remote_device_props(dev);
+	}
+}
+
 static void handle_enable_cmd(const void *buf, uint16_t len)
 {
 	uint8_t status;
@@ -2644,6 +2656,9 @@ static void handle_enable_cmd(const void *buf, uint16_t len)
 	 * enabling adapter */
 	get_adapter_properties();
 
+	/* Sent also properties of bonded devices */
+	send_bonded_devices_props();
+
 	if (adapter.current_settings & MGMT_SETTING_POWERED) {
 		status = HAL_STATUS_DONE;
 		goto failed;
-- 
1.8.4


^ permalink raw reply related

* [PATCH v2 1/2] android: Add wrapper function for get remote dev properties
From: Lukasz Rymanowski @ 2014-01-07 12:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski

---
 android/bluetooth.c | 123 +++++++++++++++++++++++++++-------------------------
 1 file changed, 64 insertions(+), 59 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 3cbf68d..e0673bb 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2550,56 +2550,6 @@ static void handle_get_remote_services_cmd(const void *buf, uint16_t len)
 									status);
 }
 
-static void handle_enable_cmd(const void *buf, uint16_t len)
-{
-	uint8_t status;
-
-	/* Framework expects all properties to be emitted while
-	 * enabling adapter */
-	get_adapter_properties();
-
-	if (adapter.current_settings & MGMT_SETTING_POWERED) {
-		status = HAL_STATUS_DONE;
-		goto failed;
-	}
-
-	if (!set_mode(MGMT_OP_SET_POWERED, 0x01)) {
-		status = HAL_STATUS_FAILED;
-		goto failed;
-	}
-
-	status = HAL_STATUS_SUCCESS;
-failed:
-	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_ENABLE, status);
-}
-
-static void handle_disable_cmd(const void *buf, uint16_t len)
-{
-	uint8_t status;
-
-	if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
-		status = HAL_STATUS_DONE;
-		goto failed;
-	}
-
-	if (!set_mode(MGMT_OP_SET_POWERED, 0x00)) {
-		status = HAL_STATUS_FAILED;
-		goto failed;
-	}
-
-	status = HAL_STATUS_SUCCESS;
-failed:
-	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DISABLE, status);
-}
-
-static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
-{
-	get_adapter_properties();
-
-	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
-							HAL_STATUS_SUCCESS);
-}
-
 static uint8_t get_device_uuids(struct device *dev)
 {
 	send_device_uuids_notif(dev);
@@ -2673,6 +2623,69 @@ static uint8_t get_device_timestamp(struct device *dev)
 	return HAL_STATUS_SUCCESS;
 }
 
+static void get_remote_device_props(struct device *dev)
+{
+	get_device_name(dev);
+	get_device_uuids(dev);
+	get_device_class(dev);
+	get_device_type(dev);
+	get_device_service_rec(dev);
+	get_device_friendly_name(dev);
+	get_device_rssi(dev);
+	get_device_version_info(dev);
+	get_device_timestamp(dev);
+}
+
+static void handle_enable_cmd(const void *buf, uint16_t len)
+{
+	uint8_t status;
+
+	/* Framework expects all properties to be emitted while
+	 * enabling adapter */
+	get_adapter_properties();
+
+	if (adapter.current_settings & MGMT_SETTING_POWERED) {
+		status = HAL_STATUS_DONE;
+		goto failed;
+	}
+
+	if (!set_mode(MGMT_OP_SET_POWERED, 0x01)) {
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
+	status = HAL_STATUS_SUCCESS;
+failed:
+	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_ENABLE, status);
+}
+
+static void handle_disable_cmd(const void *buf, uint16_t len)
+{
+	uint8_t status;
+
+	if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
+		status = HAL_STATUS_DONE;
+		goto failed;
+	}
+
+	if (!set_mode(MGMT_OP_SET_POWERED, 0x00)) {
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
+	status = HAL_STATUS_SUCCESS;
+failed:
+	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DISABLE, status);
+}
+
+static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
+{
+	get_adapter_properties();
+
+	ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
+							HAL_STATUS_SUCCESS);
+}
+
 static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_get_remote_device_props *cmd = buf;
@@ -2688,15 +2701,7 @@ static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	get_device_name(l->data);
-	get_device_uuids(l->data);
-	get_device_class(l->data);
-	get_device_type(l->data);
-	get_device_service_rec(l->data);
-	get_device_friendly_name(l->data);
-	get_device_rssi(l->data);
-	get_device_version_info(l->data);
-	get_device_timestamp(l->data);
+	get_remote_device_props(l->data);
 
 	status = HAL_STATUS_SUCCESS;
 
-- 
1.8.4


^ permalink raw reply related

* [PATCH_v3 4/4] android/pan: Remove connected PAN devices on profile unregister call
From: Ravi kumar Veeramally @ 2014-01-07 12:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1389097880-14783-1-git-send-email-ravikumar.veeramally@linux.intel.com>

---
 android/pan.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/android/pan.c b/android/pan.c
index 0e12245..b933196 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -760,10 +760,20 @@ bool bt_pan_register(const bdaddr_t *addr)
 	return true;
 }
 
+static void pan_device_disconnected(gpointer data, gpointer user_data)
+{
+	struct pan_device *dev = data;
+
+	bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
+}
+
 void bt_pan_unregister(void)
 {
 	DBG("");
 
+	g_slist_foreach(devices, pan_device_disconnected, NULL);
+	devices = NULL;
+
 	bnep_cleanup();
 
 	ipc_unregister(HAL_SERVICE_ID_PAN);
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v3 3/4] android/pan: Implement PAN enable HAL api at daemon side
From: Ravi kumar Veeramally @ 2014-01-07 12:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1389097880-14783-1-git-send-email-ravikumar.veeramally@linux.intel.com>

---
 android/pan.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/android/pan.c b/android/pan.c
index 0eef284..0e12245 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -585,18 +585,38 @@ static void bt_pan_enable(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_pan_enable *cmd = buf;
 	uint8_t status;
+	int err;
+
+	DBG("");
+
+	if (local_role == cmd->local_role) {
+		status = HAL_STATUS_SUCCESS;
+		goto reply;
+	}
+
+	/* destroy existing server */
+	destroy_nap_device();
 
 	switch (cmd->local_role) {
 	case HAL_PAN_ROLE_PANU:
-	case HAL_PAN_ROLE_NAP:
-		DBG("Not Implemented");
-		status  = HAL_STATUS_FAILED;
-		break;
-	default:
 		status = HAL_STATUS_UNSUPPORTED;
-		break;
+		goto reply;
+	case HAL_PAN_ROLE_NONE:
+		status = HAL_STATUS_SUCCESS;
+		goto reply;
+	}
+
+	local_role = cmd->local_role;
+	err = register_nap_server();
+	if (err < 0) {
+		status = HAL_STATUS_FAILED;
+		destroy_nap_device();
+		goto reply;
 	}
 
+	status = HAL_STATUS_SUCCESS;
+
+reply:
 	ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_ENABLE, status);
 }
 
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v3 2/4] android/pan: Listen for incoming connections and accept in NAP role
From: Ravi kumar Veeramally @ 2014-01-07 12:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1389097880-14783-1-git-send-email-ravikumar.veeramally@linux.intel.com>

Listen for incoming connections and accept it. Create bnep interface
add it to bridge and notify control and connection state information
through HAL. Remove the device on disconnect request. If android
settings UI does not have bluetooth tethering enabled it immediately
sends disconnect signal.
---
 android/pan.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 190 insertions(+), 2 deletions(-)

diff --git a/android/pan.c b/android/pan.c
index 93078ba..0eef284 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -63,12 +63,17 @@ struct pan_device {
 	uint8_t		role;
 	GIOChannel	*io;
 	struct bnep	*session;
+	guint		watch;
 };
 
 static struct {
 	uint32_t	record_id;
+	guint		watch;
+	GIOChannel	*io;
 } nap_dev = {
 	.record_id = 0,
+	.watch = 0,
+	.io = NULL,
 };
 
 static int device_cmp(gconstpointer s, gconstpointer user_data)
@@ -81,13 +86,21 @@ static int device_cmp(gconstpointer s, gconstpointer user_data)
 
 static void pan_device_free(struct pan_device *dev)
 {
+	if (dev->watch > 0) {
+		bnep_server_delete(BNEP_BRIDGE, dev->iface, &dev->dst);
+		g_source_remove(dev->watch);
+		dev->watch = 0;
+	}
+
 	if (dev->io) {
 		g_io_channel_shutdown(dev->io, FALSE, NULL);
 		g_io_channel_unref(dev->io);
 		dev->io = NULL;
 	}
 
-	bnep_free(dev->session);
+	if (dev->session)
+		bnep_free(dev->session);
+
 	devices = g_slist_remove(devices, dev);
 	g_free(dev);
 
@@ -298,7 +311,7 @@ static void bt_pan_disconnect(const void *buf, uint16_t len)
 
 	dev = l->data;
 
-	if (dev->conn_state == HAL_PAN_STATE_CONNECTED)
+	if (dev->conn_state == HAL_PAN_STATE_CONNECTED && dev->session)
 		bnep_disconnect(dev->session);
 
 	bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
@@ -308,6 +321,154 @@ failed:
 	ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_DISCONNECT, status);
 }
 
+static gboolean nap_watchdog_cb(GIOChannel *chan, GIOCondition cond,
+							gpointer user_data)
+{
+	struct pan_device *dev = user_data;
+
+	DBG("disconnected");
+
+	bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
+
+	return FALSE;
+}
+static gboolean nap_setup_cb(GIOChannel *chan, GIOCondition cond,
+							gpointer user_data)
+{
+	struct pan_device *dev = user_data;
+	uint8_t packet[BNEP_MTU];
+	struct bnep_setup_conn_req *req = (void *) packet;
+	uint16_t src_role, dst_role, rsp = BNEP_CONN_NOT_ALLOWED;
+	int sk, n;
+
+	if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+		error("Hangup or error or inval on BNEP socket");
+		return FALSE;
+	}
+
+	sk = g_io_channel_unix_get_fd(chan);
+
+	/* Reading BNEP_SETUP_CONNECTION_REQUEST_MSG */
+	n = read(sk, packet, sizeof(packet));
+	if (n  < 0) {
+		error("read(): %s(%d)", strerror(errno), errno);
+		goto failed;
+	}
+
+	/* Highest known control command id BNEP_FILTER_MULT_ADDR_RSP 0x06 */
+	if (req->type == BNEP_CONTROL &&
+			req->ctrl > BNEP_FILTER_MULT_ADDR_RSP) {
+		error("cmd not understood");
+		bnep_send_ctrl_rsp(sk, BNEP_CONTROL, BNEP_CMD_NOT_UNDERSTOOD,
+								req->ctrl);
+		goto failed;
+	}
+
+	if (req->type != BNEP_CONTROL || req->ctrl != BNEP_SETUP_CONN_REQ) {
+		error("cmd is not BNEP_SETUP_CONN_REQ %02X %02X", req->type,
+								req->ctrl);
+		goto failed;
+	}
+
+	rsp = bnep_setup_decode(req, &dst_role, &src_role);
+	if (rsp) {
+		error("bnep_setup_decode failed");
+		goto failed;
+	}
+
+	rsp = bnep_setup_chk(dst_role, src_role);
+	if (rsp) {
+		error("benp_setup_chk failed");
+		goto failed;
+	}
+
+	if (bnep_server_add(sk, dst_role, BNEP_BRIDGE, dev->iface,
+							&dev->dst) < 0) {
+		error("server_connadd failed");
+		rsp = BNEP_CONN_NOT_ALLOWED;
+		goto failed;
+	}
+
+	rsp = BNEP_SUCCESS;
+	bnep_send_ctrl_rsp(sk, BNEP_CONTROL, BNEP_SETUP_CONN_RSP, rsp);
+
+	dev->watch = g_io_add_watch(chan, G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+							nap_watchdog_cb, dev);
+	g_io_channel_unref(dev->io);
+	dev->io = NULL;
+
+	bt_pan_notify_ctrl_state(dev, HAL_PAN_CTRL_ENABLED);
+	bt_pan_notify_conn_state(dev, HAL_PAN_STATE_CONNECTED);
+
+	return FALSE;
+
+failed:
+	bnep_send_ctrl_rsp(sk, BNEP_CONTROL, BNEP_SETUP_CONN_RSP, rsp);
+	pan_device_free(dev);
+
+	return FALSE;
+}
+
+static void nap_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
+{
+	struct pan_device *dev = user_data;
+
+	DBG("");
+
+	if (err) {
+		error("%s", err->message);
+		bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
+		return;
+	}
+
+	g_io_channel_set_close_on_unref(chan, TRUE);
+	dev->watch = g_io_add_watch(chan,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				nap_setup_cb, dev);
+}
+
+static void nap_confirm_cb(GIOChannel *chan, gpointer data)
+{
+	struct pan_device *dev = NULL;
+	bdaddr_t dst;
+	char address[18];
+	GError *err = NULL;
+
+	DBG("");
+
+	bt_io_get(chan, &err, BT_IO_OPT_DEST_BDADDR, &dst,
+			BT_IO_OPT_DEST, address, BT_IO_OPT_INVALID);
+	if (err) {
+		error("%s", err->message);
+		g_error_free(err);
+		goto failed;
+	}
+
+	DBG("incoming connect request from %s", address);
+	dev = g_new0(struct pan_device, 1);
+	bacpy(&dev->dst, &dst);
+	local_role = HAL_PAN_ROLE_NAP;
+	dev->role = HAL_PAN_ROLE_PANU;
+
+	dev->io = g_io_channel_ref(chan);
+	g_io_channel_set_close_on_unref(dev->io, TRUE);
+
+	if (!bt_io_accept(dev->io, nap_connect_cb, dev, NULL, &err)) {
+		error("bt_io_accept: %s", err->message);
+		g_error_free(err);
+		goto failed;
+	}
+
+	devices = g_slist_append(devices, dev);
+	bt_pan_notify_conn_state(dev, HAL_PAN_STATE_CONNECTING);
+
+	return;
+
+failed:
+	g_free(dev);
+	bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
+}
+
 static int set_forward_delay(void)
 {
 	int fd, ret;
@@ -378,10 +539,22 @@ static void destroy_nap_device(void)
 	nap_remove_bridge();
 
 	nap_dev.record_id = 0;
+
+	if (nap_dev.watch > 0) {
+		g_source_remove(nap_dev.watch);
+		nap_dev.watch = 0;
+	}
+
+	if (nap_dev.io) {
+		g_io_channel_shutdown(nap_dev.io, FALSE, NULL);
+		g_io_channel_unref(nap_dev.io);
+		nap_dev.io = NULL;
+	}
 }
 
 static int register_nap_server(void)
 {
+	GError *gerr;
 	int err;
 
 	DBG("");
@@ -390,6 +563,21 @@ static int register_nap_server(void)
 	if (err < 0)
 		return err;
 
+	nap_dev.io = bt_io_listen(NULL, nap_confirm_cb, NULL, NULL, &gerr,
+					BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
+					BT_IO_OPT_PSM, BNEP_PSM,
+					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
+					BT_IO_OPT_OMTU, BNEP_MTU,
+					BT_IO_OPT_IMTU, BNEP_MTU,
+					BT_IO_OPT_INVALID);
+
+	if (!nap_dev.io) {
+		destroy_nap_device();
+		error("%s", gerr->message);
+		g_error_free(gerr);
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v3 1/4] android/pan: Register Network Access Point
From: Ravi kumar Veeramally @ 2014-01-07 12:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1389097880-14783-1-git-send-email-ravikumar.veeramally@linux.intel.com>

Register NAP server and adds bnep bridge. Removes bridge
on destroy call. Bridge mechanism is needed when device acting
as a server and listen for incoming connections.
---
 android/pan.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 108 insertions(+), 4 deletions(-)

diff --git a/android/pan.c b/android/pan.c
index 38e353d..93078ba 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -28,6 +28,11 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <glib.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <net/if.h>
+#include <linux/sockios.h>
 
 #include "btio/btio.h"
 #include "lib/bluetooth.h"
@@ -45,11 +50,11 @@
 #include "bluetooth.h"
 
 #define SVC_HINT_NETWORKING 0x02
+#define BNEP_BRIDGE	"bnep"
 
 static bdaddr_t adapter_addr;
 GSList *devices = NULL;
 uint8_t local_role = HAL_PAN_ROLE_NONE;
-static uint32_t record_id = 0;
 
 struct pan_device {
 	char		iface[16];
@@ -60,6 +65,12 @@ struct pan_device {
 	struct bnep	*session;
 };
 
+static struct {
+	uint32_t	record_id;
+} nap_dev = {
+	.record_id = 0,
+};
+
 static int device_cmp(gconstpointer s, gconstpointer user_data)
 {
 	const struct pan_device *dev = s;
@@ -297,6 +308,91 @@ failed:
 	ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_DISCONNECT, status);
 }
 
+static int set_forward_delay(void)
+{
+	int fd, ret;
+	char path[41];
+
+	sprintf(path, "/sys/class/net/%s/bridge/forward_delay", BNEP_BRIDGE);
+
+	fd = open(path, O_RDWR);
+	if (fd < 0)
+		return -errno;
+
+	ret = write(fd, "0", sizeof("0"));
+	close(fd);
+
+	return ret;
+}
+
+static int nap_create_bridge(void)
+{
+	int sk, err;
+
+	DBG("%s", BNEP_BRIDGE);
+
+	sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -EOPNOTSUPP;
+
+	if (ioctl(sk, SIOCBRADDBR, BNEP_BRIDGE) < 0) {
+		err = -errno;
+		if (err != -EEXIST) {
+			close(sk);
+			return -EOPNOTSUPP;
+		}
+	}
+
+	err = set_forward_delay();
+	if (err < 0)
+		ioctl(sk, SIOCBRDELBR, BNEP_BRIDGE);
+
+	close(sk);
+
+	return err;
+}
+
+static int nap_remove_bridge(void)
+{
+	int sk, err;
+
+	DBG("%s", BNEP_BRIDGE);
+
+	sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -EOPNOTSUPP;
+
+	err = ioctl(sk, SIOCBRDELBR, BNEP_BRIDGE);
+	close(sk);
+
+	if (err < 0)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
+static void destroy_nap_device(void)
+{
+	DBG("");
+
+	nap_remove_bridge();
+
+	nap_dev.record_id = 0;
+}
+
+static int register_nap_server(void)
+{
+	int err;
+
+	DBG("");
+
+	err = nap_create_bridge();
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
 static void bt_pan_enable(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_pan_enable *cmd = buf;
@@ -441,7 +537,15 @@ bool bt_pan_register(const bdaddr_t *addr)
 		return false;
 	}
 
-	record_id = rec->handle;
+	err = register_nap_server();
+	if (err < 0) {
+		bt_adapter_remove_record(rec->handle);
+		sdp_record_free(rec);
+		bnep_cleanup();
+		return false;
+	}
+
+	nap_dev.record_id = rec->handle;
 	ipc_register(HAL_SERVICE_ID_PAN, cmd_handlers,
 						G_N_ELEMENTS(cmd_handlers));
 
@@ -455,6 +559,6 @@ void bt_pan_unregister(void)
 	bnep_cleanup();
 
 	ipc_unregister(HAL_SERVICE_ID_PAN);
-	bt_adapter_remove_record(record_id);
-	record_id = 0;
+	bt_adapter_remove_record(nap_dev.record_id);
+	destroy_nap_device();
 }
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v3 0/4] Add support for NAP role
From: Ravi kumar Veeramally @ 2014-01-07 12:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally

v3: Fixed Johan's comments (removed fopen, fprintf and used open and write).

v2: Fixed Johan's comments.

v1: This patch set add support for NAP role. It register NAP server and create
  bnep bridge and listen for incoming connections from client devices.
  On incoming connection request it accepts connection, creates bnep interface
  and notifies control state and connection state infromation. Removes device
  on disconnect request. Android related changes are required to enable this
  role. Patches sent to respective ML.

Ravi kumar Veeramally (4):
  android/pan: Register Network Access Point
  android/pan: Listen for incoming connections and accept in NAP role
  android/pan: Implement PAN enable HAL api at daemon side
  android/pan: Remove connected PAN devices on profile unregister call

 android/pan.c | 346 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 334 insertions(+), 12 deletions(-)

-- 
1.8.3.2


^ permalink raw reply

* Re: [PATCH] Bluetooth: hidp: make sure input buffers are big enough
From: Jiri Kosina @ 2014-01-07 12:11 UTC (permalink / raw)
  To: David Herrmann
  Cc: Marcel Holtmann, open list:HID CORE LAYER,
	linux-bluetooth@vger.kernel.org development, Gustavo F. Padovan
In-Reply-To: <CANq1E4TOHvb3--H6SoRhB09sUwuYkrvSAXCNN2Y0PaVSOEte=w@mail.gmail.com>

On Fri, 27 Dec 2013, David Herrmann wrote:

> >> I also haven't figured out a nice way to make HID-core honor the 
> >> "size" parameter. hid-input depends on getting the whole 
> >> input-report.
> >
> > I think this needs clearly fixing.
> 
> And we have a volunteer, yippie! ;)
> 
> I think hid_input_report() in hid-core.c is the only place that relies
> on this. Maybe it really is easier to fix it. But I am not even
> slightly familiar with that code. So if no-one of the HID core
> developers steps up to fix it, we should take the transport-driver
> fixes instead. As nearly all transport-drivers are affected by this,
> maybe we should even move this buffer into hid_device and provide
> hid_input_truncated_report() which does this.
> 
> Anyhow, waiting for Jiri's comments on this.

Hmm, this is really unfortunate situation.

I am now looking into making hid_input_report() honor 'size' properly, but 
no matter how it'll be done in the end, it'll absolutely not be a simple 
'fix'. So definitely can be done for 3.15 or so, but not as a fix for 
current kernels.

So doing kzalloc(rsize, GFP_ATOMIC) in the HID-core for now, and copying 
the buffer around, seems like only viable solution for now, with the 
outlook of removing this ugliness once hid-core honors 'size' properly.

I will keep looking into this and maybe some easy way how to hack this 
together will materialize, but I don't currently see it.

Hmm ...

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply

* [PATCH 2/2] Bluetooth: Fix 6loWPAN peer lookup
From: Claudio Takahasi @ 2014-01-07 12:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1389096468-2917-1-git-send-email-claudio.takahasi@openbossa.org>

This patch fixes peer address lookup for 6loWPAN over Bluetooth Low
Energy links.

ADDR_LE_DEV_PUBLIC, and ADDR_LE_DEV_RANDOM are the values allowed for
"dst_type" field in the hci_conn struct for LE links.

Signed-off-by: Claudio Takahasi <claudio.takahasi@openbossa.org>
---
 net/bluetooth/6lowpan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index ab4e771..adb3ea0 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -439,9 +439,9 @@ static void get_dest_bdaddr(struct in6_addr *ip6_daddr,
 	/* Set universal/local bit to 0 */
 	if (addr->b[5] & 1) {
 		addr->b[5] &= ~1;
-		*addr_type = BDADDR_LE_PUBLIC;
+		*addr_type = ADDR_LE_DEV_PUBLIC;
 	} else {
-		*addr_type = BDADDR_LE_RANDOM;
+		*addr_type = ADDR_LE_DEV_RANDOM;
 	}
 }
 
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH 1/2] Bluetooth: Fix setting Universal/Local bit
From: Claudio Takahasi @ 2014-01-07 12:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

This patch fixes the Bluetooth Low Energy Address type checking when
setting Universal/Local bit for the 6loWPAN network device or for the
peer device connection.

ADDR_LE_DEV_PUBLIC or ADDR_LE_DEV_RANDOM are the values allowed for
"src_type" and "dst_type" in the hci_conn struct. The Bluetooth link
type can be obtainned reading the "type" field in the same struct.

Signed-off-by: Claudio Takahasi <claudio.takahasi@openbossa.org>
---
 net/bluetooth/6lowpan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 5f0b11d..ab4e771 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -623,7 +623,7 @@ static void set_addr(u8 *eui, u8 *addr, u8 addr_type)
 	eui[0] ^= 2;
 
 	/* Universal/local bit set, RFC 4291 */
-	if (addr_type == BDADDR_LE_PUBLIC)
+	if (addr_type == ADDR_LE_DEV_PUBLIC)
 		eui[0] |= 1;
 	else
 		eui[0] &= ~1;
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCH_v2 1/4] android/pan: Register Network Access Point
From: Ravi kumar Veeramally @ 2014-01-07 12:04 UTC (permalink / raw)
  To: linux-bluetooth, johan.hedberg
In-Reply-To: <20140107115539.GA2107@x220.p-661hnu-f1>

Hi Johan,

On 01/07/2014 01:55 PM, Johan Hedberg wrote:
> Hi Ravi,
>
> On Tue, Jan 07, 2014, Ravi kumar Veeramally wrote:
>> +static int set_forward_delay(void)
>> +{
>> +	FILE *f;
>> +	char *path;
>> +
>> +	path = g_strdup_printf("/sys/class/net/%s/bridge/forward_delay",
>> +								BNEP_BRIDGE);
>> +	if (!path)
>> +		return -ENOMEM;
>> +
>> +	f = fopen(path, "r+");
>> +	g_free(path);
>> +	if (!f)
>> +		return -errno;
> The above is not safe since g_free() might modify the value of errno.
>
> In general, we're not really in the habit of using the f* variants of
> file access functions. Could you convert the above to use a stack
> variable for path (there's a PATH_MAX variable you can use for its
> size) together with sprintf and use open + write instead of fopen +
> fprintf?
   Ok, I will change it.
>> +static int nap_create_bridge(void)
>> +{
>> +	int sk, err;
>> +
>> +	DBG(" %s", BNEP_BRIDGE);
> Why the extra space before %s?
  I will remove it.
>
>> +	if (ioctl(sk, SIOCBRADDBR, BNEP_BRIDGE) == -1) {
> We usually check for this kind of errors with < 0 instead of == -1.
   Ok.
>
>> +	DBG(" %s", BNEP_BRIDGE);
> Same thing here with the seemingly unnecessary space.
   Ok, I will remove it.

  Regards,
  Ravi.

^ permalink raw reply

* Re: [PATCH_v2 1/4] android/pan: Register Network Access Point
From: Johan Hedberg @ 2014-01-07 11:55 UTC (permalink / raw)
  To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1389093533-13210-2-git-send-email-ravikumar.veeramally@linux.intel.com>

Hi Ravi,

On Tue, Jan 07, 2014, Ravi kumar Veeramally wrote:
> +static int set_forward_delay(void)
> +{
> +	FILE *f;
> +	char *path;
> +
> +	path = g_strdup_printf("/sys/class/net/%s/bridge/forward_delay",
> +								BNEP_BRIDGE);
> +	if (!path)
> +		return -ENOMEM;
> +
> +	f = fopen(path, "r+");
> +	g_free(path);
> +	if (!f)
> +		return -errno;

The above is not safe since g_free() might modify the value of errno.

In general, we're not really in the habit of using the f* variants of
file access functions. Could you convert the above to use a stack
variable for path (there's a PATH_MAX variable you can use for its
size) together with sprintf and use open + write instead of fopen +
fprintf?

> +static int nap_create_bridge(void)
> +{
> +	int sk, err;
> +
> +	DBG(" %s", BNEP_BRIDGE);

Why the extra space before %s?


> +	if (ioctl(sk, SIOCBRADDBR, BNEP_BRIDGE) == -1) {

We usually check for this kind of errors with < 0 instead of == -1.

> +	DBG(" %s", BNEP_BRIDGE);

Same thing here with the seemingly unnecessary space.

Johan

^ permalink raw reply

* [PATCH BlueZ v3 10/10] android/A2DP: Add stream suspend command/response struct
From: Luiz Augusto von Dentz @ 2014-01-07 11:53 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1389095603-30504-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds the definitions to stream suspend command and response.
---
 android/a2dp.c      | 9 +++++++++
 android/audio-msg.h | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/android/a2dp.c b/android/a2dp.c
index 5d540f3..b59c53d 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -389,6 +389,13 @@ static void bt_stream_resume(const void *buf, uint16_t len)
 	audio_ipc_send_rsp(AUDIO_OP_RESUME_STREAM, AUDIO_STATUS_FAILED);
 }
 
+static void bt_stream_suspend(const void *buf, uint16_t len)
+{
+	DBG("Not Implemented");
+
+	audio_ipc_send_rsp(AUDIO_OP_SUSPEND_STREAM, AUDIO_STATUS_FAILED);
+}
+
 static const struct ipc_handler audio_handlers[] = {
 	/* AUDIO_OP_OPEN */
 	{ bt_audio_open, true, sizeof(struct audio_cmd_open) },
@@ -400,6 +407,8 @@ static const struct ipc_handler audio_handlers[] = {
 	{ bt_stream_close, false, sizeof(struct audio_cmd_close_stream) },
 	/* AUDIO_OP_RESUME_STREAM */
 	{ bt_stream_resume, false, sizeof(struct audio_cmd_resume_stream) },
+	/* AUDIO_OP_SUSPEND_STREAM */
+	{ bt_stream_suspend, false, sizeof(struct audio_cmd_suspend_stream) },
 };
 
 bool bt_a2dp_register(const bdaddr_t *addr)
diff --git a/android/audio-msg.h b/android/audio-msg.h
index 8f92413..438bc18 100644
--- a/android/audio-msg.h
+++ b/android/audio-msg.h
@@ -77,3 +77,8 @@ struct audio_cmd_close_stream {
 struct audio_cmd_resume_stream {
 	uint8_t id;
 } __attribute__((packed));
+
+#define AUDIO_OP_SUSPEND_STREAM		0x06
+struct audio_cmd_suspend_stream {
+	uint8_t id;
+} __attribute__((packed));
-- 
1.8.4.2


^ permalink raw reply related

* [PATCH BlueZ v3 09/10] android/A2DP: Add stream resume command/response struct
From: Luiz Augusto von Dentz @ 2014-01-07 11:53 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1389095603-30504-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds the definitions to stream resume command and response.
---
 android/a2dp.c      | 9 +++++++++
 android/audio-msg.h | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/android/a2dp.c b/android/a2dp.c
index 7c49bc9..5d540f3 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -382,6 +382,13 @@ static void bt_stream_close(const void *buf, uint16_t len)
 	audio_ipc_send_rsp(AUDIO_OP_CLOSE_STREAM, AUDIO_STATUS_FAILED);
 }
 
+static void bt_stream_resume(const void *buf, uint16_t len)
+{
+	DBG("Not Implemented");
+
+	audio_ipc_send_rsp(AUDIO_OP_RESUME_STREAM, AUDIO_STATUS_FAILED);
+}
+
 static const struct ipc_handler audio_handlers[] = {
 	/* AUDIO_OP_OPEN */
 	{ bt_audio_open, true, sizeof(struct audio_cmd_open) },
@@ -391,6 +398,8 @@ static const struct ipc_handler audio_handlers[] = {
 	{ bt_stream_open, false, sizeof(struct audio_cmd_open_stream) },
 	/* AUDIO_OP_CLOSE_STREAM */
 	{ bt_stream_close, false, sizeof(struct audio_cmd_close_stream) },
+	/* AUDIO_OP_RESUME_STREAM */
+	{ bt_stream_resume, false, sizeof(struct audio_cmd_resume_stream) },
 };
 
 bool bt_a2dp_register(const bdaddr_t *addr)
diff --git a/android/audio-msg.h b/android/audio-msg.h
index 4dfa8cf..8f92413 100644
--- a/android/audio-msg.h
+++ b/android/audio-msg.h
@@ -72,3 +72,8 @@ struct audio_rsp_open_stream {
 struct audio_cmd_close_stream {
 	uint8_t id;
 } __attribute__((packed));
+
+#define AUDIO_OP_RESUME_STREAM		0x05
+struct audio_cmd_resume_stream {
+	uint8_t id;
+} __attribute__((packed));
-- 
1.8.4.2


^ permalink raw reply related


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