Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/6] android/tester: Fix for not checking for BT_STATUS_SUCCESS
From: Jakub Tyszkowski @ 2013-12-19 12:42 UTC (permalink / raw)
  To: linux-bluetooth

For BT_STATUS_SUCCESS no checks were done as it is 0 in bt_status_t
enum. Valid status for no status expected should be STATUS_NOT_EXPECTED.

---
 android/android-tester.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index c24f5a6..5549dcb 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -72,7 +72,7 @@ enum hal_bluetooth_callbacks_id {
 };
 
 struct generic_data {
-	uint8_t expected_adapter_status;
+	int expected_adapter_status;
 	uint32_t expect_settings_set;
 	bt_property_t expected_property;
 	uint8_t expected_hal_callbacks[];
@@ -92,6 +92,8 @@ struct socket_data {
 #define WAIT_FOR_SIGNAL_TIME 2 /* in seconds */
 #define EMULATOR_SIGNAL "emulator_started"
 
+#define BT_STATUS_NOT_EXPECTED	-1
+
 struct test_data {
 	struct mgmt *mgmt;
 	uint16_t mgmt_index;
@@ -199,7 +201,7 @@ static void expected_status_init(struct test_data *data)
 {
 	const struct generic_data *test_data = data->test_data;
 
-	if (!(test_data->expected_adapter_status))
+	if (test_data->expected_adapter_status == BT_STATUS_NOT_EXPECTED)
 		data->status_checked = true;
 }
 
-- 
1.8.5


^ permalink raw reply related

* [PATCH 2/6] android/tester: Fix bluetooth disable success test case
From: Jakub Tyszkowski @ 2013-12-19 12:42 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387456946-9743-1-git-send-email-jakub.tyszkowski@tieto.com>

This fixes not checking for proper status on bluetooth disable.

---
 android/android-tester.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index 5549dcb..68614a2 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -596,7 +596,8 @@ static const struct generic_data bluetooth_enable_done_test = {
 
 static const struct generic_data bluetooth_disable_success_test = {
 	.expected_hal_callbacks = { ADAPTER_STATE_CHANGED_OFF,
-							ADAPTER_TEST_END }
+							ADAPTER_TEST_END },
+	.expected_adapter_status = BT_STATUS_SUCCESS
 };
 
 static const struct generic_data bluetooth_setprop_bdname_success_test = {
@@ -858,10 +859,12 @@ static void test_enable_done(const void *test_data)
 static void test_disable(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
+	bt_status_t adapter_status;
 
 	init_test_conditions(data);
 
-	data->if_bluetooth->disable();
+	adapter_status = data->if_bluetooth->disable();
+	check_expected_status(adapter_status);
 }
 
 static void test_setprop_bdname_success(const void *test_data)
-- 
1.8.5


^ permalink raw reply related

* [PATCH 3/6] android/tester: Add start device discovery success test case
From: Jakub Tyszkowski @ 2013-12-19 12:42 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387456946-9743-1-git-send-email-jakub.tyszkowski@tieto.com>

Add test case for starting device discovery with success.

---
 android/android-tester.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index 68614a2..1880cf1 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -68,7 +68,9 @@ enum hal_bluetooth_callbacks_id {
 	ADAPTER_PROP_SCAN_MODE,
 	ADAPTER_PROP_DISC_TIMEOUT,
 	ADAPTER_PROP_SERVICE_RECORD,
-	ADAPTER_PROP_BONDED_DEVICES
+	ADAPTER_PROP_BONDED_DEVICES,
+	ADAPTER_DISCOVERY_STATE_ON,
+	ADAPTER_DISCOVERY_STATE_OFF
 };
 
 struct generic_data {
@@ -527,6 +529,20 @@ static void adapter_state_changed_cb(bt_state_t state)
 	}
 }
 
+static void discovery_state_changed_cb(bt_discovery_state_t state)
+{
+	switch (state) {
+	case BT_DISCOVERY_STARTED:
+		update_hal_cb_list(ADAPTER_DISCOVERY_STATE_ON);
+		break;
+	case BT_DISCOVERY_STOPPED:
+		update_hal_cb_list(ADAPTER_DISCOVERY_STATE_OFF);
+		break;
+	default:
+		break;
+	}
+}
+
 static void adapter_properties_cb(bt_status_t status, int num_properties,
 						bt_property_t *properties)
 {
@@ -702,13 +718,19 @@ static const struct generic_data
 	.expected_property.len = sizeof(setprop_remote_service)
 };
 
+static const struct generic_data bluetooth_discovery_start_success_test = {
+	.expected_hal_callbacks = { ADAPTER_DISCOVERY_STATE_ON,
+							ADAPTER_TEST_END },
+	.expected_adapter_status = BT_STATUS_SUCCESS
+};
+
 static bt_callbacks_t bt_callbacks = {
 	.size = sizeof(bt_callbacks),
 	.adapter_state_changed_cb = adapter_state_changed_cb,
 	.adapter_properties_cb = adapter_properties_cb,
 	.remote_device_properties_cb = NULL,
 	.device_found_cb = NULL,
-	.discovery_state_changed_cb = NULL,
+	.discovery_state_changed_cb = discovery_state_changed_cb,
 	.pin_request_cb = NULL,
 	.ssp_request_cb = NULL,
 	.bond_state_changed_cb = NULL,
@@ -1230,6 +1252,17 @@ clean:
 		close(sock_fd);
 }
 
+static void test_discovery_start_success(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	bt_status_t status;
+
+	init_test_conditions(data);
+
+	status = data->if_bluetooth->start_discovery();
+	check_expected_status(status);
+}
+
 static gboolean socket_chan_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -1401,6 +1434,11 @@ int main(int argc, char *argv[])
 				setup_enabled_adapter,
 				test_setprop_service_record_invalid, teardown);
 
+	test_bredrle("Bluetooth BREDR Discovery Start - Success",
+				&bluetooth_discovery_start_success_test,
+				setup_enabled_adapter,
+				test_discovery_start_success, teardown);
+
 	test_bredrle("Socket Init", NULL, setup_socket_interface,
 						test_dummy, teardown);
 
-- 
1.8.5


^ permalink raw reply related

* [PATCH 4/6] android/tester: Add stop device discovery done test case
From: Jakub Tyszkowski @ 2013-12-19 12:42 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387456946-9743-1-git-send-email-jakub.tyszkowski@tieto.com>

Add test case for stopping device discovery when it wasn't started.

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

diff --git a/android/android-tester.c b/android/android-tester.c
index 1880cf1..0dae111 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -724,6 +724,11 @@ static const struct generic_data bluetooth_discovery_start_success_test = {
 	.expected_adapter_status = BT_STATUS_SUCCESS
 };
 
+static const struct generic_data bluetooth_discovery_stop_done_test = {
+	.expected_hal_callbacks = { ADAPTER_TEST_END },
+	.expected_adapter_status = BT_STATUS_DONE
+};
+
 static bt_callbacks_t bt_callbacks = {
 	.size = sizeof(bt_callbacks),
 	.adapter_state_changed_cb = adapter_state_changed_cb,
@@ -1263,6 +1268,17 @@ static void test_discovery_start_success(const void *test_data)
 	check_expected_status(status);
 }
 
+static void test_discovery_stop_done(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	bt_status_t status;
+
+	init_test_conditions(data);
+
+	status = data->if_bluetooth->cancel_discovery();
+	check_expected_status(status);
+}
+
 static gboolean socket_chan_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -1439,6 +1455,11 @@ int main(int argc, char *argv[])
 				setup_enabled_adapter,
 				test_discovery_start_success, teardown);
 
+	test_bredrle("Bluetooth BREDR Discovery Stop - Done",
+				&bluetooth_discovery_stop_done_test,
+				setup_enabled_adapter,
+				test_discovery_stop_done, teardown);
+
 	test_bredrle("Socket Init", NULL, setup_socket_interface,
 						test_dummy, teardown);
 
-- 
1.8.5


^ permalink raw reply related

* [PATCH 5/6] android/tester: Add device discovery cancel success test case
From: Jakub Tyszkowski @ 2013-12-19 12:42 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387456946-9743-1-git-send-email-jakub.tyszkowski@tieto.com>

Test for successfull discovery canceling after it was started.

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

diff --git a/android/android-tester.c b/android/android-tester.c
index 0dae111..737aeb3 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -96,6 +96,9 @@ struct socket_data {
 
 #define BT_STATUS_NOT_EXPECTED	-1
 
+/* User flags for Device Discovery */
+#define DEVICE_DISCOVERY_CANCEL_ON_START	0x01
+
 struct test_data {
 	struct mgmt *mgmt;
 	uint16_t mgmt_index;
@@ -115,6 +118,8 @@ struct test_data {
 
 	bt_property_t test_property;
 	GSList *expected_callbacks;
+
+	uint32_t userflag;
 };
 
 static char exec_dir[PATH_MAX + 1];
@@ -529,11 +534,23 @@ static void adapter_state_changed_cb(bt_state_t state)
 	}
 }
 
+static void post_discovery_started_cb(bt_discovery_state_t state)
+{
+	struct test_data *data = tester_get_data();
+	bt_status_t status;
+
+	if (data->userflag & DEVICE_DISCOVERY_CANCEL_ON_START) {
+		status = data->if_bluetooth->cancel_discovery();
+		check_expected_status(status);
+	}
+}
+
 static void discovery_state_changed_cb(bt_discovery_state_t state)
 {
 	switch (state) {
 	case BT_DISCOVERY_STARTED:
 		update_hal_cb_list(ADAPTER_DISCOVERY_STATE_ON);
+		post_discovery_started_cb(state);
 		break;
 	case BT_DISCOVERY_STOPPED:
 		update_hal_cb_list(ADAPTER_DISCOVERY_STATE_OFF);
@@ -729,6 +746,12 @@ static const struct generic_data bluetooth_discovery_stop_done_test = {
 	.expected_adapter_status = BT_STATUS_DONE
 };
 
+static const struct generic_data bluetooth_discovery_stop_success_test = {
+	.expected_hal_callbacks = { ADAPTER_DISCOVERY_STATE_ON,
+				ADAPTER_DISCOVERY_STATE_OFF, ADAPTER_TEST_END },
+	.expected_adapter_status = BT_STATUS_SUCCESS
+};
+
 static bt_callbacks_t bt_callbacks = {
 	.size = sizeof(bt_callbacks),
 	.adapter_state_changed_cb = adapter_state_changed_cb,
@@ -1279,6 +1302,28 @@ static void test_discovery_stop_done(const void *test_data)
 	check_expected_status(status);
 }
 
+static bool pre_inq_compl_hook(const void *data, uint16_t len, void *user_data)
+{
+	/* Make sure Inquiry Command Complete is not called */
+	return false;
+}
+
+static void test_discovery_stop_success(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	bt_status_t status;
+
+	data->userflag = DEVICE_DISCOVERY_CANCEL_ON_START;
+
+	init_test_conditions(data);
+
+	hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT, BT_HCI_CMD_INQUIRY,
+					pre_inq_compl_hook, data);
+
+	status = data->if_bluetooth->start_discovery();
+	check_expected_status(status);
+}
+
 static gboolean socket_chan_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -1460,6 +1505,11 @@ int main(int argc, char *argv[])
 				setup_enabled_adapter,
 				test_discovery_stop_done, teardown);
 
+	test_bredrle("Bluetooth BREDR Discovery Stop - Success",
+				&bluetooth_discovery_stop_success_test,
+				setup_enabled_adapter,
+				test_discovery_stop_success, teardown);
+
 	test_bredrle("Socket Init", NULL, setup_socket_interface,
 						test_dummy, teardown);
 
-- 
1.8.5


^ permalink raw reply related

* [PATCH 6/6] android/tester: Add start device discovery done test case
From: Jakub Tyszkowski @ 2013-12-19 12:42 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387456946-9743-1-git-send-email-jakub.tyszkowski@tieto.com>

This tests device discovery start being reported as done because of
ongoing discovery.

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

diff --git a/android/android-tester.c b/android/android-tester.c
index 737aeb3..aa0c155 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -98,6 +98,7 @@ struct socket_data {
 
 /* User flags for Device Discovery */
 #define DEVICE_DISCOVERY_CANCEL_ON_START	0x01
+#define DEVICE_DISCOVERY_START_ON_START		0x02
 
 struct test_data {
 	struct mgmt *mgmt;
@@ -543,6 +544,11 @@ static void post_discovery_started_cb(bt_discovery_state_t state)
 		status = data->if_bluetooth->cancel_discovery();
 		check_expected_status(status);
 	}
+
+	if (data->userflag & DEVICE_DISCOVERY_START_ON_START) {
+		status = data->if_bluetooth->start_discovery();
+		check_expected_status(status);
+	}
 }
 
 static void discovery_state_changed_cb(bt_discovery_state_t state)
@@ -741,6 +747,12 @@ static const struct generic_data bluetooth_discovery_start_success_test = {
 	.expected_adapter_status = BT_STATUS_SUCCESS
 };
 
+static const struct generic_data bluetooth_discovery_start_done_test = {
+	.expected_hal_callbacks = { ADAPTER_DISCOVERY_STATE_ON,
+							ADAPTER_TEST_END },
+	.expected_adapter_status = BT_STATUS_DONE
+};
+
 static const struct generic_data bluetooth_discovery_stop_done_test = {
 	.expected_hal_callbacks = { ADAPTER_TEST_END },
 	.expected_adapter_status = BT_STATUS_DONE
@@ -1324,6 +1336,20 @@ static void test_discovery_stop_success(const void *test_data)
 	check_expected_status(status);
 }
 
+static void test_discovery_start_done(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+
+	data->userflag = DEVICE_DISCOVERY_START_ON_START;
+
+	init_test_conditions(data);
+
+	hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT, BT_HCI_CMD_INQUIRY,
+					pre_inq_compl_hook, data);
+
+	data->if_bluetooth->start_discovery();
+}
+
 static gboolean socket_chan_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -1495,6 +1521,11 @@ int main(int argc, char *argv[])
 				setup_enabled_adapter,
 				test_setprop_service_record_invalid, teardown);
 
+	test_bredrle("Bluetooth BREDR Discovery Start - Done",
+				&bluetooth_discovery_start_done_test,
+				setup_enabled_adapter,
+				test_discovery_start_done, teardown);
+
 	test_bredrle("Bluetooth BREDR Discovery Start - Success",
 				&bluetooth_discovery_start_success_test,
 				setup_enabled_adapter,
-- 
1.8.5


^ permalink raw reply related

* [PATCH] android/build: Adding l2test to Android.mk
From: Sebastian Chlad @ 2013-12-19 12:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Sebastian Chlad

Enabling l2test tool for the android target
---
 android/Android.mk | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/android/Android.mk b/android/Android.mk
index ebc3219..fee2f6c 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -226,3 +226,27 @@ LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := audio.a2dp.default
 
 include $(BUILD_SHARED_LIBRARY)
+
+#
+# l2cap-test
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+	../tools/l2test.c \
+	../lib/bluetooth.c \
+	../lib/hci.c \
+
+LOCAL_C_INCLUDES := \
+	$(LOCAL_PATH)/.. \
+	$(LOCAL_PATH)/../lib \
+	$(LOCAL_PATH)/../src/shared \
+
+LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE := l2test
+
+include $(BUILD_EXECUTABLE)
-- 
1.8.1.2


^ permalink raw reply related

* Re: [PATCH] android/pts: Add PICS, PIXITs and PTS for L2CAP
From: Szymon Janc @ 2013-12-19 13:01 UTC (permalink / raw)
  To: Sebastian Chlad; +Cc: linux-bluetooth, Sebastian Chlad
In-Reply-To: <1387456001-6792-1-git-send-email-sebastianx.chlad@intel.com>

Hi Sebastian,

> This allows better tracking of the current state of implementation
> ---
>  android/Makefile.am     |   4 +-
>  android/pics-l2cap.txt  | 157 ++++++++++++++++++++++++++++++++++++++++++++++++
>  android/pixit-l2cap.txt |  39 ++++++++++++
>  android/pts-l2cap.txt   | 148 +++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 347 insertions(+), 1 deletion(-)
>  create mode 100644 android/pics-l2cap.txt
>  create mode 100644 android/pixit-l2cap.txt
>  create mode 100644 android/pts-l2cap.txt

Patch applied, thanks.

-- 
BR
Szymon Janc

^ permalink raw reply

* [RFCv4 0/5] SSP MITM protection
From: Timo Mueller @ 2013-12-19 13:08 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Timo Mueller

From: Timo Mueller <timo.mueller@bmw-carit.de>

Hi,

this is a rebased version of the rfc v3. I've successfully tested
these changes in the last couple of months at the UPF #46 in Vienna,
with the CE4A golden device and the bluetooth PTS (where applicable).

At the UPF I've tested remotely initiated pairing with different io
capabilities, as well locally initiated pairing. Regardless of the
bonding mode, the protocol chosen in ssp has been consistent when
being responder and also when being initiator. Pairing tests have been
successful in all 22 test sessions.

The configuration I used for testing was as follows:
bluez: 5.9-154-gf7773c7
kernel: v3.12-rc3-65-gf927318
with the remaining patches from [RFC BlueZ v3 0/8] SSP MITM protection

I used the same configuration to test the patches with the CE4A golden
device. Pairing here has been working as expected with all
combinations of io capabilities, bonding mode and intiator role.

Lastly I've successfully ran the applicable GAP tests with the
bluetooth PTS on this rebased version and the current head of
bluez. Unfortunately the interesting bonding test cases are not yet
implemented with the test suite. So I could only make sure general
functionality is preserved.

from the original cover letter:
The way the kernel handles MITM Protection during pairing is
inconsistent: General Bonding and Dedicated Bonding are not treated
equally.
<snip>
Therefore, the safest choice is to always request MITM Protection,
also for General Bonding [1]. The proposal here is to do this for both
incoming (patch 6/8) and outgoing (patch 7/8) procedures, as it was
previously done for Dedicated Bonding. This "conservative" approach is
smart enough to fall back to not using MITM Protection if the IO
capabilities don't allow it (this policy already existed before for
Dedicated Bonding, see patch 5/8).
<snip>

Best regards
Timo

Mikel Astiz (3):
  Bluetooth: Refactor hci_get_auth_req()
  Bluetooth: Refactor code for outgoing dedicated bonding
  Bluetooth: Request MITM Protection when initiator

Timo Mueller (2):
  Bluetooth: Use MITM Protection when IO caps allow it
  Bluetooth: Add management command to relax MITM Protection

 include/net/bluetooth/hci.h  |  3 ++-
 include/net/bluetooth/mgmt.h |  3 +++
 net/bluetooth/hci_event.c    | 57 ++++++++++++++++++++++++++++----------------
 net/bluetooth/mgmt.c         | 50 ++++++++++++++++++++++++++++++++++----
 4 files changed, 87 insertions(+), 26 deletions(-)

-- 
1.8.3.1


^ permalink raw reply

* [RFCv4 1/5] Bluetooth: Refactor hci_get_auth_req()
From: Timo Mueller @ 2013-12-19 13:08 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz, Timo Mueller
In-Reply-To: <cover.1387450435.git.timo.mueller@bmw-carit.de>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Refactor the code without changing its behavior by handling the
no-bonding cases first followed by General Bonding.

Signed-off-by: Mikel Astiz <mikel.astiz@bmw-carit.de>
Signed-off-by: Timo Mueller <timo.mueller@bmw-carit.de>
---
 net/bluetooth/hci_event.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 5f81245..6f9c425 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3037,24 +3037,25 @@ unlock:
 
 static u8 hci_get_auth_req(struct hci_conn *conn)
 {
-	/* If remote requests dedicated bonding follow that lead */
-	if (conn->remote_auth == HCI_AT_DEDICATED_BONDING ||
-	    conn->remote_auth == HCI_AT_DEDICATED_BONDING_MITM) {
-		/* If both remote and local IO capabilities allow MITM
-		 * protection then require it, otherwise don't */
-		if (conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT ||
-		    conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)
-			return HCI_AT_DEDICATED_BONDING;
-		else
-			return HCI_AT_DEDICATED_BONDING_MITM;
-	}
-
 	/* If remote requests no-bonding follow that lead */
 	if (conn->remote_auth == HCI_AT_NO_BONDING ||
 	    conn->remote_auth == HCI_AT_NO_BONDING_MITM)
 		return conn->remote_auth | (conn->auth_type & 0x01);
 
-	return conn->auth_type;
+	/* For general bonding, use the given auth_type */
+	if (conn->remote_auth == HCI_AT_GENERAL_BONDING ||
+	    conn->remote_auth == HCI_AT_GENERAL_BONDING_MITM)
+		return conn->auth_type;
+
+	/* If both remote and local have enough IO capabilities, require
+	 * MITM protection
+	 */
+	if (conn->remote_cap != HCI_IO_NO_INPUT_OUTPUT &&
+	    conn->io_capability != HCI_IO_NO_INPUT_OUTPUT)
+		return conn->remote_auth | 0x01;
+
+	/* No MITM protection possible so remove requirement */
+	return conn->remote_auth & ~0x01;
 }
 
 static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
@@ -3084,8 +3085,14 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		 * to DisplayYesNo as it is not supported by BT spec. */
 		cp.capability = (conn->io_capability == 0x04) ?
 				HCI_IO_DISPLAY_YESNO : conn->io_capability;
-		conn->auth_type = hci_get_auth_req(conn);
-		cp.authentication = conn->auth_type;
+
+		/* If we are initiators, there is no remote information yet */
+		if (conn->remote_auth == 0xff) {
+			cp.authentication = conn->auth_type;
+		} else {
+			conn->auth_type = hci_get_auth_req(conn);
+			cp.authentication = conn->auth_type;
+		}
 
 		if (hci_find_remote_oob_data(hdev, &conn->dst) &&
 		    (conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags)))
-- 
1.8.3.1


^ permalink raw reply related

* [RFCv4 2/5] Bluetooth: Refactor code for outgoing dedicated bonding
From: Timo Mueller @ 2013-12-19 13:08 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <cover.1387450435.git.timo.mueller@bmw-carit.de>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Do not always set the MITM protection requirement by default in the
field conn->auth_type, since this will be added later in
hci_io_capa_request_evt(), as part of the requirements specified in
HCI_OP_IO_CAPABILITY_REPLY.

This avoids a hackish exception for the auto-reject case, but doesn't
change the behavior of the code at all.

Signed-off-by: Mikel Astiz <mikel.astiz@bmw-carit.de>
---
 net/bluetooth/hci_event.c | 14 ++++++++------
 net/bluetooth/mgmt.c      |  5 +----
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 6f9c425..1cbec8f 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3089,6 +3089,11 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		/* If we are initiators, there is no remote information yet */
 		if (conn->remote_auth == 0xff) {
 			cp.authentication = conn->auth_type;
+
+			/* Use MITM protection for outgoing dedicated bonding */
+			if (conn->io_capability != HCI_IO_NO_INPUT_OUTPUT &&
+			    cp.authentication == HCI_AT_DEDICATED_BONDING)
+				cp.authentication |= 0x01;
 		} else {
 			conn->auth_type = hci_get_auth_req(conn);
 			cp.authentication = conn->auth_type;
@@ -3160,12 +3165,9 @@ static void hci_user_confirm_request_evt(struct hci_dev *hdev,
 	rem_mitm = (conn->remote_auth & 0x01);
 
 	/* If we require MITM but the remote device can't provide that
-	 * (it has NoInputNoOutput) then reject the confirmation
-	 * request. The only exception is when we're dedicated bonding
-	 * initiators (connect_cfm_cb set) since then we always have the MITM
-	 * bit set. */
-	if (!conn->connect_cfm_cb && loc_mitm &&
-	    conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) {
+	 * (it has NoInputNoOutput) then reject the confirmation request
+	 */
+	if (loc_mitm && conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) {
 		BT_DBG("Rejecting request: remote device can't provide MITM");
 		hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY,
 			     sizeof(ev->bdaddr), &ev->bdaddr);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index a03ca3c..8e302f4 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2692,10 +2692,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
 	}
 
 	sec_level = BT_SECURITY_MEDIUM;
-	if (cp->io_cap == 0x03)
-		auth_type = HCI_AT_DEDICATED_BONDING;
-	else
-		auth_type = HCI_AT_DEDICATED_BONDING_MITM;
+	auth_type = HCI_AT_DEDICATED_BONDING;
 
 	if (cp->addr.type == BDADDR_BREDR)
 		conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr,
-- 
1.8.3.1


^ permalink raw reply related

* [RFCv4 3/5] Bluetooth: Use MITM Protection when IO caps allow it
From: Timo Mueller @ 2013-12-19 13:08 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Timo Mueller, Mikel Astiz
In-Reply-To: <cover.1387450435.git.timo.mueller@bmw-carit.de>

From: Timo Mueller <timo.mueller@bmw-carit.de>

When responding to a remotely-initiated pairing procedure, a MITM
protected SSP associaton model can be used for pairing if both local
and remote IO capabilities are set to something other than
NoInputNoOutput, regardless of the bonding type (Dedicated or
General).

This was already done for Dedicated Bonding but this patch proposes to
use the same policy for General Bonding as well.

The GAP Specification gives the flexibility to decide whether MITM
Protection is used ot not (Bluetooth Core Specification v4.0 Volume 3,
part C, section 6.5.3).

Note however that the recommendation is *not* to set this flag "unless
the security policy of an available local service requires MITM
Protection" (for both Dedicated and General Bonding). However, the
kernel doesn't necessarily have this information and therefore the
safest choice is to always use MITM Protection, also for General
Bonding.

Signed-off-by: Timo Mueller <timo.mueller@bmw-carit.de>
Signed-off-by: Mikel Astiz <mikel.astiz@bmw-carit.de>
---
 net/bluetooth/hci_event.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 1cbec8f..882e569 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3042,11 +3042,6 @@ static u8 hci_get_auth_req(struct hci_conn *conn)
 	    conn->remote_auth == HCI_AT_NO_BONDING_MITM)
 		return conn->remote_auth | (conn->auth_type & 0x01);
 
-	/* For general bonding, use the given auth_type */
-	if (conn->remote_auth == HCI_AT_GENERAL_BONDING ||
-	    conn->remote_auth == HCI_AT_GENERAL_BONDING_MITM)
-		return conn->auth_type;
-
 	/* If both remote and local have enough IO capabilities, require
 	 * MITM protection
 	 */
@@ -3054,8 +3049,8 @@ static u8 hci_get_auth_req(struct hci_conn *conn)
 	    conn->io_capability != HCI_IO_NO_INPUT_OUTPUT)
 		return conn->remote_auth | 0x01;
 
-	/* No MITM protection possible so remove requirement */
-	return conn->remote_auth & ~0x01;
+	/* No MITM protection possible so ignore remote requirement */
+	return (conn->remote_auth & ~0x01) | (conn->auth_type & 0x01);
 }
 
 static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
-- 
1.8.3.1


^ permalink raw reply related

* [RFCv4 4/5] Bluetooth: Request MITM Protection when initiator
From: Timo Mueller @ 2013-12-19 13:08 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz, Timo Mueller
In-Reply-To: <cover.1387450435.git.timo.mueller@bmw-carit.de>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

The GAP Specification gives the flexibility to decide whether MITM
Protection is requested or not (Bluetooth Core Specification v4.0
Volume 3, part C, section 6.5.3) when replying to an
HCI_EV_IO_CAPA_REQUEST event.

The recommendation is *not* to set this flag "unless the security
policy of an available local service requires MITM Protection"
(regardless of the bonding type). However, the kernel doesn't
necessarily have this information and therefore the safest choice is
to always use MITM Protection, also for General Bonding.

This patch changes the behavior for the General Bonding initiator
role, always requesting MITM Protection even if no high security level
is used. Depending on the remote capabilities, the protection might
not be actually used, and we will accept this locally unless of course
a high security level was originally required.

Note that this was already done for Dedicated Bonding. No-Bonding is
left unmodified because MITM Protection is normally not desired in
these cases.

Signed-off-by: Mikel Astiz <mikel.astiz@bmw-carit.de>
Signed-off-by: Timo Mueller <timo.mueller@bmw-carit.de>
---
 net/bluetooth/hci_event.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 882e569..4516215 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3085,9 +3085,11 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		if (conn->remote_auth == 0xff) {
 			cp.authentication = conn->auth_type;
 
-			/* Use MITM protection for outgoing dedicated bonding */
+			/* Request MITM protection if our IO caps allow it
+			 * except for the no-bonding case
+			 */
 			if (conn->io_capability != HCI_IO_NO_INPUT_OUTPUT &&
-			    cp.authentication == HCI_AT_DEDICATED_BONDING)
+			    cp.authentication != HCI_AT_NO_BONDING)
 				cp.authentication |= 0x01;
 		} else {
 			conn->auth_type = hci_get_auth_req(conn);
-- 
1.8.3.1


^ permalink raw reply related

* [RFCv4 5/5] Bluetooth: Add management command to relax MITM Protection
From: Timo Mueller @ 2013-12-19 13:08 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Timo Mueller
In-Reply-To: <cover.1387450435.git.timo.mueller@bmw-carit.de>

From: Timo Mueller <timo.mueller@bmw-carit.de>

As a general rule, the Bluetooth Specification (v4.0 Volume 3, part C,
section 6.5.3) recommends *NOT* to require MITM Protection, unless the
available local services require it. The Kernel doesn't however adhere
to this recommendation because the locally available services are not
known reliably.

This lack of information is exactly what this patch addresses: a
dedicated flag is proposed in the management interface. If set to 1, the
recommentation described in the specification will be followed: it will
be assumed that none of the locally available services require MITM
Protection, unless the Kernel has any evidence of the contrary (i.e. a
socket exists with a high security level, which requires MITM
Protection).

If set to 0, MITM Protection will always be required, provided that it
is possible according to the I/O capabilities. This was the behavior
prior to this patch and therefore the flag is set to 0 by default.

Note that this affects General Bonding and Dedicated Bonding equally as
well as locally or remotely initiated pairing procedures.

Signed-off-by: Timo Mueller <timo.mueller@bmw-carit.de>
---
 include/net/bluetooth/hci.h  |  3 ++-
 include/net/bluetooth/mgmt.h |  3 +++
 net/bluetooth/hci_event.c    | 15 ++++++++++++---
 net/bluetooth/mgmt.c         | 45 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 5dc3d90..147fac6 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -121,6 +121,7 @@ enum {
 
 	HCI_LE_SCAN,
 	HCI_SSP_ENABLED,
+	HCI_RELAX_MITM,
 	HCI_HS_ENABLED,
 	HCI_LE_ENABLED,
 	HCI_ADVERTISING,
@@ -138,7 +139,7 @@ enum {
  * or the HCI device is closed.
  */
 #define HCI_PERSISTENT_MASK (BIT(HCI_LE_SCAN) | BIT(HCI_PERIODIC_INQ) | \
-			      BIT(HCI_FAST_CONNECTABLE))
+			      BIT(HCI_FAST_CONNECTABLE) | BIT(HCI_RELAX_MITM))
 
 /* HCI ioctl defines */
 #define HCIDEVUP	_IOW('H', 201, int)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 518c5c8..2da018b 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -94,6 +94,7 @@ struct mgmt_rp_read_index_list {
 #define MGMT_SETTING_HS			0x00000100
 #define MGMT_SETTING_LE			0x00000200
 #define MGMT_SETTING_ADVERTISING	0x00000400
+#define MGMT_SETTING_RELAX_MITM	0x00000800
 
 #define MGMT_OP_READ_INFO		0x0004
 #define MGMT_READ_INFO_SIZE		0
@@ -369,6 +370,8 @@ struct mgmt_cp_set_scan_params {
 } __packed;
 #define MGMT_SET_SCAN_PARAMS_SIZE	4
 
+#define MGMT_OP_SET_RELAX_MITM		0x002D
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16	opcode;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 4516215..d23370b 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3042,6 +3042,12 @@ static u8 hci_get_auth_req(struct hci_conn *conn)
 	    conn->remote_auth == HCI_AT_NO_BONDING_MITM)
 		return conn->remote_auth | (conn->auth_type & 0x01);
 
+	/* MITM Protection should be used only if strictly required, so follow
+	 * the recommendation in the Spec and do not require it otherwise
+	 */
+	if (test_bit(HCI_RELAX_MITM, &conn->hdev->dev_flags))
+		return conn->remote_auth | (conn->auth_type & 0x01);
+
 	/* If both remote and local have enough IO capabilities, require
 	 * MITM protection
 	 */
@@ -3085,11 +3091,14 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		if (conn->remote_auth == 0xff) {
 			cp.authentication = conn->auth_type;
 
-			/* Request MITM protection if our IO caps allow it
-			 * except for the no-bonding case
+			/* MITM Protection should be used only if strictly
+			 * required, so follow the recommendation in the Spec
+			 * and do not require it otherwise (no-bonding is left
+			 * unmodified in any case)
 			 */
 			if (conn->io_capability != HCI_IO_NO_INPUT_OUTPUT &&
-			    cp.authentication != HCI_AT_NO_BONDING)
+			    cp.authentication != HCI_AT_NO_BONDING &&
+			    !test_bit(HCI_RELAX_MITM, &conn->hdev->dev_flags))
 				cp.authentication |= 0x01;
 		} else {
 			conn->auth_type = hci_get_auth_req(conn);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 8e302f4..2aca565 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -79,6 +79,7 @@ static const u16 mgmt_commands[] = {
 	MGMT_OP_SET_BREDR,
 	MGMT_OP_SET_STATIC_ADDRESS,
 	MGMT_OP_SET_SCAN_PARAMS,
+	MGMT_OP_SET_RELAX_MITM,
 };
 
 static const u16 mgmt_events[] = {
@@ -375,6 +376,7 @@ static u32 get_supported_settings(struct hci_dev *hdev)
 		if (lmp_ssp_capable(hdev)) {
 			settings |= MGMT_SETTING_SSP;
 			settings |= MGMT_SETTING_HS;
+			settings |= MGMT_SETTING_RELAX_MITM;
 		}
 	}
 
@@ -423,6 +425,9 @@ static u32 get_current_settings(struct hci_dev *hdev)
 	if (test_bit(HCI_ADVERTISING, &hdev->dev_flags))
 		settings |= MGMT_SETTING_ADVERTISING;
 
+	if (test_bit(HCI_RELAX_MITM, &hdev->dev_flags))
+		settings |= MGMT_SETTING_RELAX_MITM;
+
 	return settings;
 }
 
@@ -1719,6 +1724,45 @@ failed:
 	return err;
 }
 
+static int set_relax_mitm(struct sock *sk, struct hci_dev *hdev, void *data,
+			    u16 len)
+{
+	struct mgmt_mode *cp = data;
+	u8 val;
+	int err;
+
+	BT_DBG("request for %s", hdev->name);
+
+	if (!lmp_ssp_capable(hdev))
+		return cmd_status(sk, hdev->id, MGMT_OP_SET_RELAX_MITM,
+				  MGMT_STATUS_NOT_SUPPORTED);
+
+	if (cp->val != 0x00 && cp->val != 0x01)
+		return cmd_status(sk, hdev->id, MGMT_OP_SET_RELAX_MITM,
+				  MGMT_STATUS_INVALID_PARAMS);
+
+	hci_dev_lock(hdev);
+
+	val = !!cp->val;
+
+	if (val == test_bit(HCI_RELAX_MITM, &hdev->dev_flags)) {
+		err = send_settings_rsp(sk, MGMT_OP_SET_RELAX_MITM, hdev);
+		goto failed;
+	}
+
+	change_bit(HCI_RELAX_MITM, &hdev->dev_flags);
+
+	err = send_settings_rsp(sk, MGMT_OP_SET_RELAX_MITM, hdev);
+	if (err < 0)
+		goto failed;
+
+	err = new_settings(hdev, sk);
+
+failed:
+	hci_dev_unlock(hdev);
+	return err;
+}
+
 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
 {
 	struct mgmt_mode *cp = data;
@@ -4124,6 +4168,7 @@ static const struct mgmt_handler {
 	{ set_bredr,              false, MGMT_SETTING_SIZE },
 	{ set_static_address,     false, MGMT_SET_STATIC_ADDRESS_SIZE },
 	{ set_scan_params,        false, MGMT_SET_SCAN_PARAMS_SIZE },
+	{ set_relax_mitm,        false, MGMT_SETTING_SIZE },
 };
 
 
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCH] avrcp: Remove unneeded code
From: Luiz Augusto von Dentz @ 2013-12-19 13:18 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1387444404-6834-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Thu, Dec 19, 2013 at 11:13 AM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Checking (val & 0x7f) > 127 does not make any sense.
> ---
>  profiles/audio/avrcp.c | 5 -----
>  1 file changed, 5 deletions(-)
>
> diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
> index cd027c6..7731e88 100644
> --- a/profiles/audio/avrcp.c
> +++ b/profiles/audio/avrcp.c
> @@ -1577,15 +1577,10 @@ static uint8_t avrcp_handle_set_absolute_volume(struct avrcp *session,
>  {
>         struct avrcp_player *player = session->controller->player;
>         uint16_t len = ntohs(pdu->params_len);
> -       uint8_t volume;
>
>         if (len != 1)
>                 goto err;
>
> -       volume = pdu->params[0] & 0x7F;
> -       if (volume > 127)
> -               goto err;
> -
>         if (!player)
>                 goto err;
>
> --
> 1.8.3.2

Ive applied a proper fix, there was a real problem since we were not
passing the value stored in volume which does ignore the reserved bits
properly, Ive also removed the the check for > 127 since it will never
be the case after & 0x7F operation which was initially your idea but
we cannot just remove volume for the reasons stated above.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH] android/build: Adding l2test to Android.mk
From: Szymon Janc @ 2013-12-19 13:33 UTC (permalink / raw)
  To: Sebastian Chlad; +Cc: linux-bluetooth, Sebastian Chlad
In-Reply-To: <1387457595-8020-1-git-send-email-sebastianx.chlad@intel.com>

Hi Sebastian,

> Enabling l2test tool for the android target
> ---
>  android/Android.mk | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/android/Android.mk b/android/Android.mk
> index ebc3219..fee2f6c 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -226,3 +226,27 @@ LOCAL_MODULE_TAGS := optional
>  LOCAL_MODULE := audio.a2dp.default
>  
>  include $(BUILD_SHARED_LIBRARY)
> +
> +#
> +# l2cap-test
> +#
> +
> +include $(CLEAR_VARS)
> +
> +LOCAL_SRC_FILES := \
> +	../tools/l2test.c \
> +	../lib/bluetooth.c \
> +	../lib/hci.c \
> +
> +LOCAL_C_INCLUDES := \
> +	$(LOCAL_PATH)/.. \
> +	$(LOCAL_PATH)/../lib \
> +	$(LOCAL_PATH)/../src/shared \
> +
> +LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
> +
> +LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
> +LOCAL_MODULE_TAGS := eng
> +LOCAL_MODULE := l2test
> +
> +include $(BUILD_EXECUTABLE)
> 

Applied (after fixing commit message), thanks.

-- 
BR
Szymon Janc



^ permalink raw reply

* Re: [PATCH 1/6] android/tester: Fix for not checking for BT_STATUS_SUCCESS
From: Johan Hedberg @ 2013-12-19 13:42 UTC (permalink / raw)
  To: Jakub Tyszkowski; +Cc: linux-bluetooth
In-Reply-To: <1387456946-9743-1-git-send-email-jakub.tyszkowski@tieto.com>

Hi Jakub,

On Thu, Dec 19, 2013, Jakub Tyszkowski wrote:
> For BT_STATUS_SUCCESS no checks were done as it is 0 in bt_status_t
> enum. Valid status for no status expected should be STATUS_NOT_EXPECTED.
> 
> ---
>  android/android-tester.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/android/android-tester.c b/android/android-tester.c
> index c24f5a6..5549dcb 100644
> --- a/android/android-tester.c
> +++ b/android/android-tester.c
> @@ -72,7 +72,7 @@ enum hal_bluetooth_callbacks_id {
>  };
>  
>  struct generic_data {
> -	uint8_t expected_adapter_status;
> +	int expected_adapter_status;
>  	uint32_t expect_settings_set;
>  	bt_property_t expected_property;
>  	uint8_t expected_hal_callbacks[];
> @@ -92,6 +92,8 @@ struct socket_data {
>  #define WAIT_FOR_SIGNAL_TIME 2 /* in seconds */
>  #define EMULATOR_SIGNAL "emulator_started"
>  
> +#define BT_STATUS_NOT_EXPECTED	-1
> +
>  struct test_data {
>  	struct mgmt *mgmt;
>  	uint16_t mgmt_index;
> @@ -199,7 +201,7 @@ static void expected_status_init(struct test_data *data)
>  {
>  	const struct generic_data *test_data = data->test_data;
>  
> -	if (!(test_data->expected_adapter_status))
> +	if (test_data->expected_adapter_status == BT_STATUS_NOT_EXPECTED)
>  		data->status_checked = true;
>  }

I suppose it does make sense to have such a special value, but I can't
see you use it anywhere in your patch set. So I'd postpone this patch
until you've got some actual code that needs it.

Johan

^ permalink raw reply

* [PATCHv2 1/6] emulator: Add new method for adding l2cap server
From: Marcin Kraglak @ 2013-12-19 14:29 UTC (permalink / raw)
  To: linux-bluetooth

This method allow user to add l2cap server and register
connect callback. If no callback is specified, it will behave
like bthost_set_server_psm() method.
---
 emulator/bthost.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 emulator/bthost.h |  5 +++++
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/emulator/bthost.c b/emulator/bthost.c
index 654338d..7ccef9c 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -90,6 +90,13 @@ struct l2cap_pending_req {
 	struct l2cap_pending_req *next;
 };
 
+struct l2cap_conn_cb_data {
+	uint16_t psm;
+	bthost_l2cap_connect_cb func;
+	void *user_data;
+	struct l2cap_conn_cb_data *next;
+};
+
 struct bthost {
 	uint8_t bdaddr[6];
 	bthost_send_func send_handler;
@@ -101,7 +108,7 @@ struct bthost {
 	void *cmd_complete_data;
 	bthost_new_conn_cb new_conn_cb;
 	void *new_conn_data;
-	uint16_t server_psm;
+	struct l2cap_conn_cb_data *new_l2cap_conn_data;
 	struct l2cap_pending_req *l2reqs;
 };
 
@@ -187,6 +194,19 @@ static struct l2conn *btconn_find_l2cap_conn_by_scid(struct btconn *conn,
 	return NULL;
 }
 
+static struct l2cap_conn_cb_data *bthost_find_l2cap_cb_by_psm(
+					struct bthost *bthost, uint16_t psm)
+{
+	struct l2cap_conn_cb_data *cb;
+
+	for (cb = bthost->new_l2cap_conn_data; cb != NULL; cb = cb->next) {
+		if (cb->psm == psm)
+			return cb;
+	}
+
+	return NULL;
+}
+
 void bthost_destroy(struct bthost *bthost)
 {
 	if (!bthost)
@@ -214,6 +234,13 @@ void bthost_destroy(struct bthost *bthost)
 		free(req);
 	}
 
+	while (bthost->new_l2cap_conn_data) {
+		struct l2cap_conn_cb_data *cb = bthost->new_l2cap_conn_data;
+
+		bthost->new_l2cap_conn_data = cb->next;
+		free(cb);
+	}
+
 	free(bthost);
 }
 
@@ -737,7 +764,7 @@ static bool l2cap_conn_req(struct bthost *bthost, struct btconn *conn,
 	memset(&rsp, 0, sizeof(rsp));
 	rsp.scid = req->scid;
 
-	if (bthost->server_psm && bthost->server_psm == psm)
+	if (bthost_find_l2cap_cb_by_psm(bthost, psm))
 		rsp.dcid = cpu_to_le16(conn->next_cid++);
 	else
 		rsp.result = cpu_to_le16(0x0002); /* PSM Not Supported */
@@ -747,6 +774,8 @@ static bool l2cap_conn_req(struct bthost *bthost, struct btconn *conn,
 
 	if (!rsp.result) {
 		struct bt_l2cap_pdu_config_req conf_req;
+		struct l2cap_conn_cb_data *cb_data;
+		struct l2conn *l2conn;
 
 		bthost_add_l2cap_conn(bthost, conn, le16_to_cpu(rsp.dcid),
 							le16_to_cpu(rsp.scid),
@@ -757,6 +786,14 @@ static bool l2cap_conn_req(struct bthost *bthost, struct btconn *conn,
 
 		l2cap_sig_send(bthost, conn, BT_L2CAP_PDU_CONFIG_REQ, 0,
 						&conf_req, sizeof(conf_req));
+
+		cb_data = bthost_find_l2cap_cb_by_psm(bthost, psm);
+		l2conn  = btconn_find_l2cap_conn_by_scid(conn,
+							le16_to_cpu(rsp.scid));
+
+		if (cb_data && l2conn->psm == cb_data->psm && cb_data->func)
+			cb_data->func(conn->handle, l2conn->dcid,
+							cb_data->user_data);
 	}
 
 	return true;
@@ -1012,7 +1049,7 @@ static bool l2cap_le_conn_req(struct bthost *bthost, struct btconn *conn,
 	rsp.mps = 23;
 	rsp.credits = 1;
 
-	if (bthost->server_psm && bthost->server_psm == psm)
+	if (bthost_find_l2cap_cb_by_psm(bthost, psm))
 		rsp.dcid = cpu_to_le16(conn->next_cid++);
 	else
 		rsp.result = cpu_to_le16(0x0002); /* PSM Not Supported */
@@ -1249,9 +1286,26 @@ void bthost_le_start_encrypt(struct bthost *bthost, uint16_t handle,
 	send_command(bthost, BT_HCI_CMD_LE_START_ENCRYPT, &cmd, sizeof(cmd));
 }
 
+void bthost_add_l2cap_server(struct bthost *bthost, uint16_t psm,
+				bthost_l2cap_connect_cb func, void *user_data)
+{
+	struct l2cap_conn_cb_data *data;
+
+	data = malloc(sizeof(struct l2cap_conn_cb_data));
+	if (!data)
+		return;
+
+	data->psm = psm;
+	data->user_data = user_data;
+	data->func = func;
+	data->next = bthost->new_l2cap_conn_data;
+
+	bthost->new_l2cap_conn_data = data;
+}
+
 void bthost_set_server_psm(struct bthost *bthost, uint16_t psm)
 {
-	bthost->server_psm = psm;
+	bthost_add_l2cap_server(bthost, psm, NULL, NULL);
 }
 
 void bthost_start(struct bthost *bthost)
diff --git a/emulator/bthost.h b/emulator/bthost.h
index 474ada9..2b8f212 100644
--- a/emulator/bthost.h
+++ b/emulator/bthost.h
@@ -74,8 +74,13 @@ void bthost_set_adv_enable(struct bthost *bthost, uint8_t enable);
 
 void bthost_le_start_encrypt(struct bthost *bthost, uint16_t handle,
 							const uint8_t ltk[16]);
+typedef void (*bthost_l2cap_connect_cb) (uint16_t handle, uint16_t cid,
+							void *user_data);
 
 void bthost_set_server_psm(struct bthost *bthost, uint16_t psm);
 
+void bthost_add_l2cap_server(struct bthost *bthost, uint16_t psm,
+				bthost_l2cap_connect_cb func, void *user_data);
+
 void bthost_start(struct bthost *bthost);
 void bthost_stop(struct bthost *bthost);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCHv2 2/6] tools/l2cap_tester: Add read client test case
From: Marcin Kraglak @ 2013-12-19 14:29 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387463345-26406-1-git-send-email-marcin.kraglak@tieto.com>

This test case send data from remote device to client.
It verifies if data is passed corerctly through L2CAP socket.
---
 tools/l2cap-tester.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index e4dade2..a8718d4 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -50,12 +50,18 @@ struct test_data {
 	struct hciemu *hciemu;
 	enum hciemu_type hciemu_type;
 	unsigned int io_id;
+	uint16_t handle;
+	uint16_t scid;
+	uint16_t dcid;
 };
 
 struct l2cap_client_data {
 	uint16_t client_psm;
 	uint16_t server_psm;
 	int expect_err;
+	uint16_t data_len;
+	const void *read_data;
+	const void *write_data;
 };
 
 struct l2cap_server_data {
@@ -247,6 +253,15 @@ static const struct l2cap_client_data client_connect_success_test = {
 	.server_psm = 0x1001,
 };
 
+static uint8_t l2_data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
+
+static const struct  l2cap_client_data client_connect_read_success_test = {
+	.client_psm = 0x1001,
+	.server_psm = 0x1001,
+	.read_data = l2_data,
+	.data_len = sizeof(l2_data),
+};
+
 static const struct l2cap_client_data client_connect_nval_psm_test = {
 	.client_psm = 0x1001,
 	.expect_err = ECONNREFUSED,
@@ -455,6 +470,25 @@ static void test_basic(const void *test_data)
 	tester_test_passed();
 }
 
+static gboolean client_received_data(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct l2cap_client_data *l2data = data->test_data;
+	char buf[1024];
+	int sk;
+
+	sk = g_io_channel_unix_get_fd(io);
+	read(sk, buf, l2data->data_len);
+
+	if (memcmp(buf, l2data->read_data, l2data->data_len))
+		tester_test_failed();
+	else
+		tester_test_passed();
+
+	return FALSE;
+}
+
 static gboolean l2cap_connect_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -477,6 +511,18 @@ static gboolean l2cap_connect_cb(GIOChannel *io, GIOCondition cond,
 	else
 		tester_print("Successfully connected");
 
+	if (l2data->read_data) {
+		struct bthost *bthost;
+
+		bthost = hciemu_client_get_host(data->hciemu);
+		g_io_add_watch(io, G_IO_IN, client_received_data, NULL);
+
+		bthost_send_cid(bthost, data->handle, data->dcid,
+					l2data->read_data, l2data->data_len);
+
+		return FALSE;
+	}
+
 	if (-err != l2data->expect_err)
 		tester_test_failed();
 	else
@@ -559,6 +605,15 @@ static int connect_l2cap_sock(struct test_data *data, int sk, uint16_t psm)
 	return 0;
 }
 
+static void client_l2cap_connect_cb(uint16_t handle, uint16_t cid,
+							void *user_data)
+{
+	struct test_data *data = user_data;
+
+	data->dcid = cid;
+	data->handle = handle;
+}
+
 static void test_connect(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
@@ -568,7 +623,12 @@ static void test_connect(const void *test_data)
 
 	if (l2data->server_psm) {
 		struct bthost *bthost = hciemu_client_get_host(data->hciemu);
-		bthost_set_server_psm(bthost, l2data->server_psm);
+
+		if (!l2data->data_len)
+			bthost_set_server_psm(bthost, l2data->server_psm);
+		else
+			bthost_add_l2cap_server(bthost, l2data->server_psm,
+						client_l2cap_connect_cb, data);
 	}
 
 	sk = create_l2cap_sock(data, 0);
@@ -744,6 +804,11 @@ int main(int argc, char *argv[])
 	test_l2cap_bredr("L2CAP BR/EDR Client - Success",
 					&client_connect_success_test,
 					setup_powered_client, test_connect);
+
+	test_l2cap_bredr("L2CAP BR/EDR Client - Read Success",
+					&client_connect_read_success_test,
+					setup_powered_client, test_connect);
+
 	test_l2cap_bredr("L2CAP BR/EDR Client - Invalid PSM",
 					&client_connect_nval_psm_test,
 					setup_powered_client, test_connect);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCHv2 3/6] tools/l2cap_tester: Add write client test case
From: Marcin Kraglak @ 2013-12-19 14:29 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387463345-26406-1-git-send-email-marcin.kraglak@tieto.com>

This test case write data from client to remote server.
---
 tools/l2cap-tester.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index a8718d4..15b441b 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -262,6 +262,13 @@ static const struct  l2cap_client_data client_connect_read_success_test = {
 	.data_len = sizeof(l2_data),
 };
 
+static const struct  l2cap_client_data client_connect_write_success_test = {
+	.client_psm = 0x1001,
+	.server_psm = 0x1001,
+	.write_data = l2_data,
+	.data_len = sizeof(l2_data),
+};
+
 static const struct l2cap_client_data client_connect_nval_psm_test = {
 	.client_psm = 0x1001,
 	.expect_err = ECONNREFUSED,
@@ -489,6 +496,23 @@ static gboolean client_received_data(GIOChannel *io, GIOCondition cond,
 	return FALSE;
 }
 
+static void bthost_received_data(const void *buf, uint16_t len,
+							void *user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct l2cap_client_data *l2data = data->test_data;
+
+	if (len != l2data->data_len) {
+		tester_test_failed();
+		return;
+	}
+
+	if (memcmp(buf, l2data->write_data, l2data->data_len))
+		tester_test_failed();
+	else
+		tester_test_passed();
+}
+
 static gboolean l2cap_connect_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -521,6 +545,16 @@ static gboolean l2cap_connect_cb(GIOChannel *io, GIOCondition cond,
 					l2data->read_data, l2data->data_len);
 
 		return FALSE;
+	} else if (l2data->write_data) {
+		struct bthost *bthost;
+
+		bthost = hciemu_client_get_host(data->hciemu);
+		bthost_add_cid_hook(bthost, data->handle, data->dcid,
+					bthost_received_data, NULL);
+
+		write(sk, l2data->write_data, l2data->data_len);
+
+		return FALSE;
 	}
 
 	if (-err != l2data->expect_err)
@@ -809,6 +843,10 @@ int main(int argc, char *argv[])
 					&client_connect_read_success_test,
 					setup_powered_client, test_connect);
 
+	test_l2cap_bredr("L2CAP BR/EDR Client - Write Success",
+					&client_connect_write_success_test,
+					setup_powered_client, test_connect);
+
 	test_l2cap_bredr("L2CAP BR/EDR Client - Invalid PSM",
 					&client_connect_nval_psm_test,
 					setup_powered_client, test_connect);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCHv2 4/6] tools/l2cap_tester: Add read server test case
From: Marcin Kraglak @ 2013-12-19 14:29 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387463345-26406-1-git-send-email-marcin.kraglak@tieto.com>

This test checks data transfer from remote client to server.
---
 tools/l2cap-tester.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index 15b441b..a756a81 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -72,6 +72,9 @@ struct l2cap_server_data {
 	uint8_t expect_rsp_code;
 	const void *expect_rsp;
 	uint16_t expect_rsp_len;
+	uint16_t data_len;
+	const void *read_data;
+	const void *write_data;
 };
 
 static void mgmt_debug(const char *str, void *user_data)
@@ -284,6 +287,16 @@ static const struct l2cap_server_data l2cap_server_success_test = {
 	.expect_rsp_code = BT_L2CAP_PDU_CONN_RSP,
 };
 
+static const struct l2cap_server_data l2cap_server_read_success_test = {
+	.server_psm = 0x1001,
+	.send_req_code = BT_L2CAP_PDU_CONN_REQ,
+	.send_req = l2cap_connect_req,
+	.send_req_len = sizeof(l2cap_connect_req),
+	.expect_rsp_code = BT_L2CAP_PDU_CONN_RSP,
+	.read_data = l2_data,
+	.data_len = sizeof(l2_data),
+};
+
 static const uint8_t l2cap_nval_psm_rsp[] = {	0x00, 0x00,	/* dcid */
 						0x41, 0x00,	/* scid */
 						0x02, 0x00,	/* nval PSM */
@@ -496,6 +509,27 @@ static gboolean client_received_data(GIOChannel *io, GIOCondition cond,
 	return FALSE;
 }
 
+static gboolean server_received_data(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct l2cap_server_data *l2data = data->test_data;
+	char buf[1024];
+	int sk;
+
+	sk = g_io_channel_unix_get_fd(io);
+	read(sk, buf, l2data->data_len);
+
+	if (memcmp(buf, l2data->read_data, l2data->data_len))
+		tester_test_failed();
+	else
+		tester_test_passed();
+
+	close(sk);
+
+	return FALSE;
+}
+
 static void bthost_received_data(const void *buf, uint16_t len,
 							void *user_data)
 {
@@ -691,6 +725,7 @@ static gboolean l2cap_listen_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
 	struct test_data *data = tester_get_data();
+	const struct l2cap_server_data *l2data = data->test_data;
 	int sk, new_sk;
 
 	data->io_id = 0;
@@ -704,6 +739,20 @@ static gboolean l2cap_listen_cb(GIOChannel *io, GIOCondition cond,
 		return FALSE;
 	}
 
+	if (l2data->read_data) {
+		struct bthost *bthost;
+		GIOChannel *new_io;
+
+		new_io = g_io_channel_unix_new(new_sk);
+
+		bthost = hciemu_client_get_host(data->hciemu);
+		g_io_add_watch(new_io, G_IO_IN, server_received_data, NULL);
+		bthost_send_cid(bthost, data->handle, data->dcid,
+					l2data->read_data, l2data->data_len);
+
+		return FALSE;
+	}
+
 	tester_print("Successfully connected");
 
 	close(new_sk);
@@ -727,6 +776,19 @@ static void client_l2cap_rsp(uint8_t code, const void *data, uint16_t len,
 		goto failed;
 	}
 
+	if (code == BT_L2CAP_PDU_CONN_RSP) {
+
+		const struct bt_l2cap_pdu_conn_rsp *rsp = data;
+		if (len == sizeof(rsp) && !rsp->result && !rsp->status)
+			return;
+
+		test_data->dcid = rsp->dcid;
+		test_data->scid = rsp->scid;
+
+		if (l2data->data_len)
+			return;
+	}
+
 	if (!l2data->expect_rsp) {
 		tester_test_passed();
 		return;
@@ -758,6 +820,8 @@ static void client_new_conn(uint16_t handle, void *user_data)
 
 	tester_print("New client connection with handle 0x%04x", handle);
 
+	data->handle = handle;
+
 	if (l2data->send_req) {
 		bthost_l2cap_rsp_cb cb;
 
@@ -854,6 +918,11 @@ int main(int argc, char *argv[])
 	test_l2cap_bredr("L2CAP BR/EDR Server - Success",
 					&l2cap_server_success_test,
 					setup_powered_server, test_server);
+
+	test_l2cap_bredr("L2CAP BR/EDR Server - Read Success",
+					&l2cap_server_read_success_test,
+					setup_powered_server, test_server);
+
 	test_l2cap_bredr("L2CAP BR/EDR Server - Invalid PSM",
 					&l2cap_server_nval_psm_test,
 					setup_powered_server, test_server);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCHv2 5/6] tools/l2cap_tester: Add write server test case
From: Marcin Kraglak @ 2013-12-19 14:29 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387463345-26406-1-git-send-email-marcin.kraglak@tieto.com>

These test case send data from local server to remote client.
---
 tools/l2cap-tester.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index a756a81..55e8ac9 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -297,6 +297,16 @@ static const struct l2cap_server_data l2cap_server_read_success_test = {
 	.data_len = sizeof(l2_data),
 };
 
+static const struct l2cap_server_data l2cap_server_write_success_test = {
+	.server_psm = 0x1001,
+	.send_req_code = BT_L2CAP_PDU_CONN_REQ,
+	.send_req = l2cap_connect_req,
+	.send_req_len = sizeof(l2cap_connect_req),
+	.expect_rsp_code = BT_L2CAP_PDU_CONN_RSP,
+	.write_data = l2_data,
+	.data_len = sizeof(l2_data),
+};
+
 static const uint8_t l2cap_nval_psm_rsp[] = {	0x00, 0x00,	/* dcid */
 						0x41, 0x00,	/* scid */
 						0x02, 0x00,	/* nval PSM */
@@ -547,6 +557,23 @@ static void bthost_received_data(const void *buf, uint16_t len,
 		tester_test_passed();
 }
 
+static void server_bthost_received_data(const void *buf, uint16_t len,
+							void *user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct l2cap_server_data *l2data = data->test_data;
+
+	if (len != l2data->data_len) {
+		tester_test_failed();
+		return;
+	}
+
+	if (memcmp(buf, l2data->write_data, l2data->data_len))
+		tester_test_failed();
+	else
+		tester_test_passed();
+}
+
 static gboolean l2cap_connect_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -751,6 +778,17 @@ static gboolean l2cap_listen_cb(GIOChannel *io, GIOCondition cond,
 					l2data->read_data, l2data->data_len);
 
 		return FALSE;
+	} else if (l2data->write_data) {
+		struct bthost *bthost;
+
+		bthost = hciemu_client_get_host(data->hciemu);
+		bthost_add_cid_hook(bthost, data->handle, data->scid,
+					server_bthost_received_data, NULL);
+
+		write(new_sk, l2data->write_data, l2data->data_len);
+		close(new_sk);
+
+		return FALSE;
 	}
 
 	tester_print("Successfully connected");
@@ -923,6 +961,10 @@ int main(int argc, char *argv[])
 					&l2cap_server_read_success_test,
 					setup_powered_server, test_server);
 
+	test_l2cap_bredr("L2CAP BR/EDR Server - Write Success",
+					&l2cap_server_write_success_test,
+					setup_powered_server, test_server);
+
 	test_l2cap_bredr("L2CAP BR/EDR Server - Invalid PSM",
 					&l2cap_server_nval_psm_test,
 					setup_powered_server, test_server);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCHv2 6/6] emulator: Remove not necessary bthost_set_server_psm
From: Marcin Kraglak @ 2013-12-19 14:29 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1387463345-26406-1-git-send-email-marcin.kraglak@tieto.com>

Remove not necessary function and replace all uses with new one,
bthost_add_l2cap_server().
---
 android/android-tester.c | 2 +-
 emulator/bthost.c        | 5 -----
 emulator/bthost.h        | 2 --
 tools/l2cap-tester.c     | 3 ++-
 4 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index c24f5a6..2d78646 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -1279,7 +1279,7 @@ static void test_socket_real_connect(const void *test_data)
 
 	bdaddr2android((bdaddr_t *) client_bdaddr, &emu_bdaddr);
 
-	bthost_set_server_psm(bthost, 0x0003);
+	bthost_add_l2cap_server(bthost, 0x0003, NULL, NULL);
 
 	status = data->if_sock->connect(&emu_bdaddr, test->sock_type,
 					test->service_uuid, test->channel,
diff --git a/emulator/bthost.c b/emulator/bthost.c
index 7ccef9c..28d0591 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -1303,11 +1303,6 @@ void bthost_add_l2cap_server(struct bthost *bthost, uint16_t psm,
 	bthost->new_l2cap_conn_data = data;
 }
 
-void bthost_set_server_psm(struct bthost *bthost, uint16_t psm)
-{
-	bthost_add_l2cap_server(bthost, psm, NULL, NULL);
-}
-
 void bthost_start(struct bthost *bthost)
 {
 	if (!bthost)
diff --git a/emulator/bthost.h b/emulator/bthost.h
index 2b8f212..97f011b 100644
--- a/emulator/bthost.h
+++ b/emulator/bthost.h
@@ -77,8 +77,6 @@ void bthost_le_start_encrypt(struct bthost *bthost, uint16_t handle,
 typedef void (*bthost_l2cap_connect_cb) (uint16_t handle, uint16_t cid,
 							void *user_data);
 
-void bthost_set_server_psm(struct bthost *bthost, uint16_t psm);
-
 void bthost_add_l2cap_server(struct bthost *bthost, uint16_t psm,
 				bthost_l2cap_connect_cb func, void *user_data);
 
diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index 55e8ac9..2a7a394 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -720,7 +720,8 @@ static void test_connect(const void *test_data)
 		struct bthost *bthost = hciemu_client_get_host(data->hciemu);
 
 		if (!l2data->data_len)
-			bthost_set_server_psm(bthost, l2data->server_psm);
+			bthost_add_l2cap_server(bthost, l2data->server_psm,
+								NULL, NULL);
 		else
 			bthost_add_l2cap_server(bthost, l2data->server_psm,
 						client_l2cap_connect_cb, data);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH_v6 1/5] android/pan: shutdown io channel on disconnect call
From: Ravi kumar Veeramally @ 2013-12-19 14:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally

Shutdown io channel and send DISCONNECTING notification and send
DISCONNECTED notification and free the device on callback.
---
 android/pan.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/android/pan.c b/android/pan.c
index b83f534..187953b 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -284,14 +284,16 @@ static void bt_pan_disconnect(const void *buf, uint16_t len)
 	}
 
 	dev = l->data;
-	if (dev->watch) {
-		g_source_remove(dev->watch);
-		dev->watch = 0;
+
+	if (dev->io)
+		g_io_channel_shutdown(dev->io, TRUE, NULL);
+
+	if (dev->conn_state == HAL_PAN_STATE_CONNECTED) {
+		bnep_if_down(dev->iface);
+		bnep_conndel(&dst);
 	}
 
-	bnep_if_down(dev->iface);
-	bnep_conndel(&dst);
-	bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
+	bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTING);
 	status = HAL_STATUS_SUCCESS;
 
 failed:
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v6 2/5] bnep: Rename struct bnep_conn to struct bnep for better readability
From: Ravi kumar Veeramally @ 2013-12-19 14:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1387463983-6373-1-git-send-email-ravikumar.veeramally@linux.intel.com>

---
 profiles/network/bnep.c | 80 ++++++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 08037e6..02e2647 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -67,7 +67,7 @@ struct __service_16 {
 	uint16_t src;
 } __attribute__ ((packed));
 
-struct bnep_conn {
+struct bnep {
 	GIOChannel	*io;
 	uint16_t	src;
 	uint16_t	dst;
@@ -77,17 +77,17 @@ struct bnep_conn {
 	bnep_connect_cb	conn_cb;
 };
 
-static void free_bnep_connect(struct bnep_conn *bc)
+static void free_bnep_connect(struct bnep *b)
 {
-	if (!bc)
+	if (!b)
 		return;
 
-	if (bc->io) {
-		g_io_channel_unref(bc->io);
-		bc->io = NULL;
+	if (b->io) {
+		g_io_channel_unref(b->io);
+		b->io = NULL;
 	}
 
-	g_free(bc);
+	g_free(b);
 }
 
 uint16_t bnep_service_id(const char *svc)
@@ -249,7 +249,7 @@ int bnep_if_down(const char *devname)
 static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 								gpointer data)
 {
-	struct bnep_conn *bc = data;
+	struct bnep *b = data;
 	struct bnep_control_rsp *rsp;
 	struct timeval timeo;
 	char pkt[BNEP_MTU];
@@ -260,9 +260,9 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 	if (cond & G_IO_NVAL)
 		goto failed;
 
-	if (bc->setup_to > 0) {
-		g_source_remove(bc->setup_to);
-		bc->setup_to = 0;
+	if (b->setup_to > 0) {
+		g_source_remove(b->setup_to);
+		b->setup_to = 0;
 	}
 
 	if (cond & (G_IO_HUP | G_IO_ERR)) {
@@ -309,8 +309,8 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 	timeo.tv_sec = 0;
 	setsockopt(sk, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
 
-	sk = g_io_channel_unix_get_fd(bc->io);
-	if (bnep_connadd(sk, bc->src, iface)) {
+	sk = g_io_channel_unix_get_fd(b->io);
+	if (bnep_connadd(sk, b->src, iface)) {
 		error("bnep conn could not be added");
 		goto failed;
 	}
@@ -320,19 +320,19 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 		goto failed;
 	}
 
-	bc->conn_cb(chan, iface, 0, bc->data);
-	free_bnep_connect(bc);
+	b->conn_cb(chan, iface, 0, b->data);
+	free_bnep_connect(b);
 
 	return FALSE;
 
 failed:
-	bc->conn_cb(NULL, NULL, -EIO, bc->data);
-	free_bnep_connect(bc);
+	b->conn_cb(NULL, NULL, -EIO, b->data);
+	free_bnep_connect(b);
 
 	return FALSE;
 }
 
-static int bnep_setup_conn_req(struct bnep_conn *bc)
+static int bnep_setup_conn_req(struct bnep *b)
 {
 	struct bnep_setup_conn_req *req;
 	struct __service_16 *s;
@@ -345,34 +345,34 @@ static int bnep_setup_conn_req(struct bnep_conn *bc)
 	req->ctrl = BNEP_SETUP_CONN_REQ;
 	req->uuid_size = 2;     /* 16bit UUID */
 	s = (void *) req->service;
-	s->src = htons(bc->src);
-	s->dst = htons(bc->dst);
+	s->src = htons(b->src);
+	s->dst = htons(b->dst);
 
-	fd = g_io_channel_unix_get_fd(bc->io);
+	fd = g_io_channel_unix_get_fd(b->io);
 	if (write(fd, pkt, sizeof(*req) + sizeof(*s)) < 0) {
 		error("bnep connection req send failed: %s", strerror(errno));
 		return -errno;
 	}
 
-	bc->attempts++;
+	b->attempts++;
 
 	return 0;
 }
 
 static gboolean bnep_conn_req_to(gpointer user_data)
 {
-	struct bnep_conn *bc = user_data;
+	struct bnep *b = user_data;
 
-	if (bc->attempts == CON_SETUP_RETRIES) {
+	if (b->attempts == CON_SETUP_RETRIES) {
 		error("Too many bnep connection attempts");
 	} else {
 		error("bnep connection setup TO, retrying...");
-		if (bnep_setup_conn_req(bc) == 0)
+		if (bnep_setup_conn_req(b) == 0)
 			return TRUE;
 	}
 
-	bc->conn_cb(NULL, NULL, -ETIMEDOUT, bc->data);
-	free_bnep_connect(bc);
+	b->conn_cb(NULL, NULL, -ETIMEDOUT, b->data);
+	free_bnep_connect(b);
 
 	return FALSE;
 }
@@ -380,28 +380,28 @@ static gboolean bnep_conn_req_to(gpointer user_data)
 int bnep_connect(int sk, uint16_t src, uint16_t dst, bnep_connect_cb conn_cb,
 								void *data)
 {
-	struct bnep_conn *bc;
+	struct bnep *b;
 	int err;
 
 	if (!conn_cb)
 		return -EINVAL;
 
-	bc = g_new0(struct bnep_conn, 1);
-	bc->io = g_io_channel_unix_new(sk);
-	bc->attempts = 0;
-	bc->src = src;
-	bc->dst = dst;
-	bc->conn_cb = conn_cb;
-	bc->data = data;
+	b = g_new0(struct bnep, 1);
+	b->io = g_io_channel_unix_new(sk);
+	b->attempts = 0;
+	b->src = src;
+	b->dst = dst;
+	b->conn_cb = conn_cb;
+	b->data = data;
 
-	err = bnep_setup_conn_req(bc);
+	err = bnep_setup_conn_req(b);
 	if (err < 0)
 		return err;
 
-	bc->setup_to = g_timeout_add_seconds(CON_SETUP_TO,
-							bnep_conn_req_to, bc);
-	g_io_add_watch(bc->io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
-							bnep_setup_cb, bc);
+	b->setup_to = g_timeout_add_seconds(CON_SETUP_TO,
+							bnep_conn_req_to, b);
+	g_io_add_watch(b->io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+							bnep_setup_cb, b);
 	return 0;
 }
 
-- 
1.8.3.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