2014-08-26 20:41:48

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 1/5] android/bluetooth: Fix incoming just works bonding

With this patch Android framework will be notified about bonded device
which initiated bonding and used just works association model.
---
android/bluetooth.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 984ecba..96f6101 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -889,8 +889,20 @@ static void update_device_state(struct device *dev, uint8_t addr_type,

new_bond = device_bond_state(dev);

- if (old_bond != new_bond)
+ if (old_bond != new_bond) {
+ /*
+ * For incoming just works bonding we will switch here from
+ * non bonded to bonded directly. This is something Android
+ * will not handle in their bond state machine. To make Android
+ * handle it corretly we need to send BONDING state before BOND
+ */
+ if (old_bond == HAL_BOND_STATE_NONE &&
+ new_bond == HAL_BOND_STATE_BONDED)
+ send_bond_state_change(dev, status,
+ HAL_BOND_STATE_BONDING);
+
send_bond_state_change(dev, status, new_bond);
+ }
}

static void send_device_property(struct device *dev, uint8_t type,
--
1.8.4



2014-08-28 19:01:41

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH 1/5] android/bluetooth: Fix incoming just works bonding

Hi Ɓukasz,

On Tuesday 26 August 2014 22:41:48 Lukasz Rymanowski wrote:
> With this patch Android framework will be notified about bonded device
> which initiated bonding and used just works association model.
> ---
> android/bluetooth.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index 984ecba..96f6101 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -889,8 +889,20 @@ static void update_device_state(struct device *dev,
> uint8_t addr_type,
>
> new_bond = device_bond_state(dev);
>
> - if (old_bond != new_bond)
> + if (old_bond != new_bond) {
> + /*
> + * For incoming just works bonding we will switch here from
> + * non bonded to bonded directly. This is something Android
> + * will not handle in their bond state machine. To make Android
> + * handle it corretly we need to send BONDING state before BOND
> + */
> + if (old_bond == HAL_BOND_STATE_NONE &&
> + new_bond == HAL_BOND_STATE_BONDED)
> + send_bond_state_change(dev, status,
> + HAL_BOND_STATE_BONDING);
> +
> send_bond_state_change(dev, status, new_bond);
> + }
> }
>
> static void send_device_property(struct device *dev, uint8_t type,

All patches applied. Thanks.

--
Szymon K. Janc
[email protected]

2014-08-26 20:41:52

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 5/5] android/tester: Add test for incoming bonding

This patch add test for incoming just works bonding
---
android/tester-bluetooth.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)

diff --git a/android/tester-bluetooth.c b/android/tester-bluetooth.c
index 018d712..7ea0684 100644
--- a/android/tester-bluetooth.c
+++ b/android/tester-bluetooth.c
@@ -444,6 +444,20 @@ static struct bt_action_data ssp_confirm_reject_reply = {
.accept = FALSE,
};

+static struct bt_action_data no_input_no_output_io_cap = {
+ .io_cap = 0x03,
+};
+
+static void conn_cb(uint16_t handle, void *user_data)
+{
+ struct test_data *data = tester_get_data();
+ struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+
+ tester_print("New connection with handle 0x%04x", handle);
+
+ bthost_request_auth(bthost, handle);
+}
+
static struct test_case test_cases[] = {
TEST_CASE_BREDRLE("Bluetooth Init",
ACTION_SUCCESS(dummy_action, NULL),
@@ -1143,6 +1157,27 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(bluetooth_disable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDR("Bluetooth Accept Bond - Just Works - Success",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION_SUCCESS(bt_set_property_action,
+ &prop_test_scanmode_conn_discov),
+ CALLBACK_ADAPTER_PROPS(&prop_test_scanmode_conn_discov, 1),
+ ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+ ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
+ ACTION_SUCCESS(emu_set_io_cap, &no_input_no_output_io_cap),
+ ACTION_SUCCESS(emu_set_connect_cb_action, conn_cb),
+ ACTION_SUCCESS(emu_remote_connect_hci_action, NULL),
+ CALLBACK_BOND_STATE(BT_BOND_STATE_BONDING,
+ &prop_emu_remote_bdadr, 1),
+ CALLBACK_BOND_STATE(BT_BOND_STATE_BONDED,
+ &prop_emu_remote_bdadr, 1),
+ ACTION_SUCCESS(bt_remove_bond_action, &emu_remote_bdaddr_val),
+ CALLBACK_BOND_STATE(BT_BOND_STATE_NONE,
+ &prop_emu_remote_bdadr, 1),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};

struct queue *get_bluetooth_tests(void)
--
1.8.4


2014-08-26 20:41:51

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 4/5] android/tester: Add function to set io cap to bthost

Some tests might need to change default io capabilities of bthost.
This patch adds means to do it.
---
android/tester-main.c | 20 ++++++++++++++++++++
android/tester-main.h | 2 ++
2 files changed, 22 insertions(+)

diff --git a/android/tester-main.c b/android/tester-main.c
index 310efb0..a001059 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -1665,6 +1665,26 @@ void emu_remote_disconnect_hci_action(void)
schedule_action_verification(step);
}

+void emu_set_io_cap(void)
+{
+ struct test_data *data = tester_get_data();
+ struct bthost *bthost;
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *action_data = current_data_step->set_data;
+ struct step *step = g_new0(struct step, 1);
+
+ bthost = hciemu_client_get_host(data->hciemu);
+
+ if (action_data)
+ bthost_set_io_capability(bthost, action_data->io_cap);
+ else
+ bthost_set_io_capability(bthost, 0x01);
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+ schedule_action_verification(step);
+}
+
void emu_add_l2cap_server_action(void)
{
struct test_data *data = tester_get_data();
diff --git a/android/tester-main.h b/android/tester-main.h
index e83933a..77f7660 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -332,6 +332,7 @@ struct bt_action_data {
const uint8_t pin_len;
const uint8_t ssp_variant;
const bool accept;
+ const uint16_t io_cap;

/* Socket HAL specific params */
const btsock_type_t sock_type;
@@ -436,6 +437,7 @@ void emu_set_ssp_mode_action(void);
void emu_set_connect_cb_action(void);
void emu_remote_connect_hci_action(void);
void emu_remote_disconnect_hci_action(void);
+void emu_set_io_cap(void);
void emu_add_l2cap_server_action(void);
void emu_add_rfcomm_server_action(void);

--
1.8.4


2014-08-26 20:41:50

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 3/5] android/tester: Add parameter to remote connect function

This patch extends emu_remote_connect_hci_action function with address
type of device to be connected
---
android/tester-gatt.c | 10 +++++++---
android/tester-main.c | 8 +++++++-
android/tester-main.h | 3 +++
3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index 979a1de..b680322 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -95,6 +95,10 @@ static struct gatt_connect_data client2_conn_req = {
static const uint8_t exchange_mtu_req_pdu[] = { 0x02, 0xa0, 0x02 };
static const uint8_t exchange_mtu_resp_pdu[] = { 0x03, 0xa0, 0x02 };

+static struct bt_action_data bearer_type = {
+ .bearer_type = BDADDR_LE_PUBLIC,
+};
+
static void gatt_client_register_action(void)
{
struct test_data *data = tester_get_data();
@@ -380,7 +384,7 @@ static struct test_case test_cases[] = {
CALLBACK_STATUS(CB_GATTC_REGISTER_CLIENT, BT_STATUS_SUCCESS),
ACTION_SUCCESS(gatt_client_do_listen_action, &client1_conn_req),
CALLBACK_STATUS(CB_GATTC_LISTEN, GATT_STATUS_SUCCESS),
- ACTION_SUCCESS(emu_remote_connect_hci_action, NULL),
+ ACTION_SUCCESS(emu_remote_connect_hci_action, &bearer_type),
CALLBACK_GATTC_CONNECT(GATT_STATUS_SUCCESS,
prop_emu_remotes_default_set,
CONN1_ID, CLIENT1_ID),
@@ -408,7 +412,7 @@ static struct test_case test_cases[] = {
CALLBACK_STATUS(CB_GATTC_REGISTER_CLIENT, BT_STATUS_SUCCESS),
ACTION_SUCCESS(gatt_client_do_listen_action, &client1_conn_req),
CALLBACK_STATUS(CB_GATTC_LISTEN, GATT_STATUS_SUCCESS),
- ACTION_SUCCESS(emu_remote_connect_hci_action, NULL),
+ ACTION_SUCCESS(emu_remote_connect_hci_action, &bearer_type),
CALLBACK_GATTC_CONNECT(GATT_STATUS_SUCCESS,
prop_emu_remotes_default_set,
CONN1_ID, CLIENT1_ID),
@@ -427,7 +431,7 @@ static struct test_case test_cases[] = {
BT_ACL_STATE_DISCONNECTED),
ACTION_SUCCESS(gatt_client_do_listen_action, &client1_conn_req),
CALLBACK_STATUS(CB_GATTC_LISTEN, GATT_STATUS_SUCCESS),
- ACTION_SUCCESS(emu_remote_connect_hci_action, NULL),
+ ACTION_SUCCESS(emu_remote_connect_hci_action, &bearer_type),
CALLBACK_GATTC_CONNECT(GATT_STATUS_SUCCESS,
prop_emu_remotes_default_set,
CONN2_ID, CLIENT1_ID),
diff --git a/android/tester-main.c b/android/tester-main.c
index c41ce1c..310efb0 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -1627,6 +1627,8 @@ void emu_remote_connect_hci_action(void)
{
struct test_data *data = tester_get_data();
struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *action_data = current_data_step->set_data;
struct step *step = g_new0(struct step, 1);
const uint8_t *master_addr;

@@ -1634,7 +1636,11 @@ void emu_remote_connect_hci_action(void)

tester_print("Trying to connect hci");

- bthost_hci_connect(bthost, master_addr, BDADDR_LE_PUBLIC);
+ if (action_data)
+ bthost_hci_connect(bthost, master_addr,
+ action_data->bearer_type);
+ else
+ bthost_hci_connect(bthost, master_addr, BDADDR_BREDR);

step->action_status = BT_STATUS_SUCCESS;

diff --git a/android/tester-main.h b/android/tester-main.h
index 3331e91..e83933a 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -343,6 +343,9 @@ struct bt_action_data {

/* HidHost params */
const int report_size;
+
+ /*Connection params*/
+ const uint8_t bearer_type;
};

/* bthost's l2cap server setup parameters */
--
1.8.4


2014-08-26 20:41:49

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 2/5] android/tester: Move emu related functions to tester main

Those function can be used by other tester modules

In addition function emu_remote_disconnect_hci_action has been changed a
bit so it take handle from step data now. It was needed as cid_data was
static in tester_gatt.c
---
android/tester-gatt.c | 49 ++-----------------------------------------------
android/tester-main.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
android/tester-main.h | 3 +++
3 files changed, 56 insertions(+), 47 deletions(-)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index 1d66309..979a1de 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -253,52 +253,6 @@ static void gatt_conn_cb(uint16_t handle, void *user_data)
&cid_data);
}

-static void emu_set_connect_cb_action(void)
-{
- struct test_data *data = tester_get_data();
- struct bthost *bthost = hciemu_client_get_host(data->hciemu);
- struct step *current_data_step = queue_peek_head(data->steps);
- void *cb = current_data_step->set_data;
- struct step *step = g_new0(struct step, 1);
-
- bthost_set_connect_cb(bthost, cb, data);
-
- step->action_status = BT_STATUS_SUCCESS;
-
- schedule_action_verification(step);
-}
-
-static void emu_remote_connect_hci_action(void)
-{
- struct test_data *data = tester_get_data();
- struct bthost *bthost = hciemu_client_get_host(data->hciemu);
- struct step *step = g_new0(struct step, 1);
- const uint8_t *master_addr;
-
- master_addr = hciemu_get_master_bdaddr(data->hciemu);
-
- tester_print("Trying to connect hci");
-
- bthost_hci_connect(bthost, master_addr, BDADDR_LE_PUBLIC);
-
- step->action_status = BT_STATUS_SUCCESS;
-
- schedule_action_verification(step);
-}
-
-static void emu_remote_disconnect_hci_action(void)
-{
- struct test_data *data = tester_get_data();
- struct bthost *bthost = hciemu_client_get_host(data->hciemu);
- struct step *step = g_new0(struct step, 1);
-
- bthost_hci_disconnect(bthost, cid_data.handle, 0x13);
-
- step->action_status = BT_STATUS_SUCCESS;
-
- schedule_action_verification(step);
-}
-
static struct test_case test_cases[] = {
TEST_CASE_BREDRLE("Gatt Init",
ACTION_SUCCESS(dummy_action, NULL),
@@ -467,7 +421,8 @@ static struct test_case test_cases[] = {
prop_emu_remotes_default_set,
CONN1_ID, CLIENT1_ID),
/* Close ACL on emulated remotes side so it can reconnect */
- ACTION_SUCCESS(emu_remote_disconnect_hci_action, NULL),
+ ACTION_SUCCESS(emu_remote_disconnect_hci_action,
+ &cid_data.handle),
CALLBACK_STATE(CB_BT_ACL_STATE_CHANGED,
BT_ACL_STATE_DISCONNECTED),
ACTION_SUCCESS(gatt_client_do_listen_action, &client1_conn_req),
diff --git a/android/tester-main.c b/android/tester-main.c
index 369a943..c41ce1c 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -1608,6 +1608,57 @@ void emu_set_ssp_mode_action(void)
schedule_action_verification(step);
}

+void emu_set_connect_cb_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+ struct step *current_data_step = queue_peek_head(data->steps);
+ void *cb = current_data_step->set_data;
+ struct step *step = g_new0(struct step, 1);
+
+ bthost_set_connect_cb(bthost, cb, data);
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+ schedule_action_verification(step);
+}
+
+void emu_remote_connect_hci_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+ struct step *step = g_new0(struct step, 1);
+ const uint8_t *master_addr;
+
+ master_addr = hciemu_get_master_bdaddr(data->hciemu);
+
+ tester_print("Trying to connect hci");
+
+ bthost_hci_connect(bthost, master_addr, BDADDR_LE_PUBLIC);
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+ schedule_action_verification(step);
+}
+
+void emu_remote_disconnect_hci_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+ struct step *current_data_step = queue_peek_head(data->steps);
+ uint16_t *handle = current_data_step->set_data;
+ struct step *step = g_new0(struct step, 1);
+
+ if (handle) {
+ bthost_hci_disconnect(bthost, *handle, 0x13);
+ step->action_status = BT_STATUS_SUCCESS;
+ } else {
+ step->action_status = BT_STATUS_FAIL;
+ }
+
+ schedule_action_verification(step);
+}
+
void emu_add_l2cap_server_action(void)
{
struct test_data *data = tester_get_data();
diff --git a/android/tester-main.h b/android/tester-main.h
index ad87878..3331e91 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -430,6 +430,9 @@ void schedule_action_verification(struct step *step);
void emu_setup_powered_remote_action(void);
void emu_set_pin_code_action(void);
void emu_set_ssp_mode_action(void);
+void emu_set_connect_cb_action(void);
+void emu_remote_connect_hci_action(void);
+void emu_remote_disconnect_hci_action(void);
void emu_add_l2cap_server_action(void);
void emu_add_rfcomm_server_action(void);

--
1.8.4