* [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 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 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 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
* 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
* 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] 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
* [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
* [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 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 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 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 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
* 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
* [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
* [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 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 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 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 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 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 v2 5/5] android: Set umask in system-emulator
From: Szymon Janc @ 2013-12-19 12:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1387456713-12794-1-git-send-email-szymon.janc@tieto.com>
This will make sure files are created with proper permissions so
Android daemon doesn't have to handle that. On Android umask is
set by init.
---
android/system-emulator.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/android/system-emulator.c b/android/system-emulator.c
index 24f2741..299de0f 100644
--- a/android/system-emulator.c
+++ b/android/system-emulator.c
@@ -37,6 +37,8 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "monitor/mainloop.h"
@@ -169,5 +171,7 @@ int main(int argc, char *argv[])
mainloop_add_fd(fd, EPOLLIN, system_socket_callback, NULL, NULL);
+ umask(0177);
+
return mainloop_run();
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH v2 4/5] android/bluetooth: Add support for restoring devices from storage
From: Szymon Janc @ 2013-12-19 12:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1387456713-12794-1-git-send-email-szymon.janc@tieto.com>
This adds support to restore bonded devices from storage (including
linkkeys).
---
android/bluetooth.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 112 insertions(+), 1 deletion(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 8f2a94c..c84bab6 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1573,6 +1573,117 @@ static void clear_uuids(void)
sizeof(cp), &cp, NULL, NULL, NULL);
}
+static void create_device_from_info(GKeyFile *key_file, const char *peer)
+{
+ struct device *dev;
+ uint8_t type;
+ bdaddr_t bdaddr;
+ char **uuids;
+ char *str;
+
+ DBG("%s", peer);
+
+ type = g_key_file_get_integer(key_file, peer, "Type", NULL);
+
+ str2ba(peer, &bdaddr);
+ dev = create_device(&bdaddr, type);
+
+ dev->bond_state = HAL_BOND_STATE_BONDED;
+
+ str = g_key_file_get_string(key_file, peer, "Name", NULL);
+ if (str) {
+ g_free(dev->name);
+ dev->name = str;
+ }
+
+ str = g_key_file_get_string(key_file, peer, "FriendlyName", NULL);
+ if (str) {
+ g_free(dev->friendly_name);
+ dev->friendly_name = str;
+ }
+
+ dev->class = g_key_file_get_integer(key_file, peer, "Class", NULL);
+
+ uuids = g_key_file_get_string_list(key_file, peer, "Services", NULL,
+ NULL);
+ if (uuids) {
+ char **uuid;
+
+ for (uuid = uuids; *uuid; uuid++) {
+ uint8_t *u = g_malloc0(16);
+ int i;
+
+ for (i = 0; i < 16; i++)
+ sscanf((*uuid) + (i * 2), "%02hhX", &u[i]);
+
+ dev->uuids = g_slist_append(dev->uuids, u);
+ }
+
+ g_strfreev(uuids);
+ }
+}
+
+static struct mgmt_link_key_info *get_key_info(GKeyFile *key_file, const char *peer)
+{
+ struct mgmt_link_key_info *info = NULL;
+ char *str;
+ unsigned int i;
+
+ str = g_key_file_get_string(key_file, peer, "LinkKey", NULL);
+ if (!str || strlen(str) != 32)
+ goto failed;
+
+ info = g_new0(struct mgmt_link_key_info, 1);
+
+ str2ba(peer, &info->addr.bdaddr);
+
+ info->addr.type = g_key_file_get_integer(key_file, peer, "Type", NULL);
+
+ for (i = 0; i < sizeof(info->val); i++)
+ sscanf(str + (i * 2), "%02hhX", &info->val[i]);
+
+ info->type = g_key_file_get_integer(key_file, peer, "LinkKeyType",
+ NULL);
+ info->pin_len = g_key_file_get_integer(key_file, peer,
+ "LinkKeyPINLength", NULL);
+
+failed:
+ g_free(str);
+
+ return info;
+}
+
+static void load_devices_info(bt_bluetooth_ready cb)
+{
+ GKeyFile *key_file;
+ gchar **devs;
+ gsize len = 0;
+ unsigned int i;
+ GSList *keys = NULL;
+
+ key_file = g_key_file_new();
+
+ g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/devices", 0,
+ NULL);
+
+ devs = g_key_file_get_groups(key_file, &len);
+
+ for (i = 0; i < len; i++) {
+ struct mgmt_link_key_info *key_info;
+
+ create_device_from_info(key_file, devs[i]);
+
+ key_info = get_key_info(key_file, devs[i]);
+ if (key_info)
+ keys = g_slist_prepend(keys, key_info);
+
+ /* TODO ltk */
+ }
+
+ load_link_keys(keys, cb);
+ g_slist_free_full(keys, g_free);
+}
+
static void read_info_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
@@ -1627,7 +1738,7 @@ static void read_info_complete(uint8_t status, uint16_t length,
clear_uuids();
- load_link_keys(NULL, cb);
+ load_devices_info(cb);
set_io_capability();
set_device_id();
--
1.8.3.2
^ permalink raw reply related
* [PATCH v2 3/5] android/bluetooth: Add support for storing link keys
From: Szymon Janc @ 2013-12-19 12:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1387456713-12794-1-git-send-email-szymon.janc@tieto.com>
When new linkkey event is received store linkkey in devices info file.
Stored info includes linkkey, linkkey type and pin length.
---
android/bluetooth.c | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index ede844e..8f2a94c 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -490,7 +490,35 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
static void store_link_key(const bdaddr_t *dst, const uint8_t *key,
uint8_t type, uint8_t pin_length)
{
- /* TODO store link key */
+ GKeyFile *key_file;
+ char key_str[33];
+ gsize length = 0;
+ char addr[18];
+ char *data;
+ int i;
+
+ key_file = g_key_file_new();
+
+ if (!g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/devices",
+ 0, NULL))
+ return;
+
+ ba2str(dst, addr);
+
+ DBG("%s type %u pin_len %u", addr, type, pin_length);
+
+ for (i = 0; i < 16; i++)
+ sprintf(key_str + (i * 2), "%2.2X", key[i]);
+
+ g_key_file_set_string(key_file, addr, "LinkKey", key_str);
+ g_key_file_set_integer(key_file, addr, "LinkKeyType", type);
+ g_key_file_set_integer(key_file, addr, "LinkKeyPINLength", pin_length);
+
+ data = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(ANDROID_STORAGEDIR"/devices", data, length, NULL);
+ g_free(data);
+
+ g_key_file_free(key_file);
}
static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
@@ -717,6 +745,9 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
return;
}
+ set_device_bond_state(&addr->bdaddr, HAL_STATUS_SUCCESS,
+ HAL_BOND_STATE_BONDED);
+
if (ev->store_hint) {
const struct mgmt_link_key_info *key = &ev->key;
@@ -724,9 +755,6 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
key->pin_len);
}
- set_device_bond_state(&addr->bdaddr, HAL_STATUS_SUCCESS,
- HAL_BOND_STATE_BONDED);
-
browse_remote_sdp(&addr->bdaddr);
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH v2 2/5] android/bluetooth: Add initial support for storing device info
From: Szymon Janc @ 2013-12-19 12:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1387456713-12794-1-git-send-email-szymon.janc@tieto.com>
This allows to store information about remote device. For now this is
stored only for bonded devices. Currently stored data includes devices
ddress, type, name, friendly name, class and uuids.
---
android/bluetooth.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 75 insertions(+), 1 deletion(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index ae136e4..ede844e 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -186,6 +186,76 @@ static void load_adapter_config(void)
g_key_file_free(key_file);
}
+static void store_device_info(struct device *dev)
+{
+ GKeyFile *key_file;
+ char addr[18];
+ gsize length = 0;
+ char **uuids = NULL;
+ char *str;
+
+ if (dev->bond_state != HAL_BOND_STATE_BONDED &&
+ dev->bond_state != HAL_BOND_STATE_NONE)
+ return;
+
+ ba2str(&dev->bdaddr, addr);
+
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/devices", 0,
+ NULL);
+
+ if (dev->bond_state == HAL_BOND_STATE_NONE) {
+ g_key_file_remove_group(key_file, addr, NULL);
+ goto done;
+ }
+
+ g_key_file_set_integer(key_file, addr, "Type", dev->bdaddr_type);
+
+ g_key_file_set_string(key_file, addr, "Name", dev->name);
+
+ if (dev->friendly_name)
+ g_key_file_set_string(key_file, addr, "FriendlyName",
+ dev->friendly_name);
+ else
+ g_key_file_remove_key(key_file, addr, "FriendlyName", NULL);
+
+ if (dev->class)
+ g_key_file_set_integer(key_file, addr, "Class", dev->class);
+ else
+ g_key_file_remove_key(key_file, addr, "Class", NULL);
+
+ if (dev->uuids) {
+ GSList *l;
+ int i;
+
+ uuids = g_new0(char *, g_slist_length(dev->uuids) + 1);
+
+ for (i = 0, l = dev->uuids; l; l = g_slist_next(l), i++) {
+ int j;
+ uint8_t *u = l->data;
+ char *uuid_str = g_malloc0(33);
+
+ for (j = 0; j < 16; j++)
+ sprintf(uuid_str + (j * 2), "%2.2X", u[j]);
+
+ uuids[i] = uuid_str;
+ }
+
+ g_key_file_set_string_list(key_file, addr, "Services",
+ (const char **)uuids, i);
+ } else {
+ g_key_file_remove_key(key_file, addr, "Services", NULL);
+ }
+
+done:
+ str = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(ANDROID_STORAGEDIR"/devices", str, length, NULL);
+ g_free(str);
+
+ g_key_file_free(key_file);
+ g_strfreev(uuids);
+}
+
static int bdaddr_cmp(gconstpointer a, gconstpointer b)
{
const bdaddr_t *bda = a;
@@ -448,6 +518,8 @@ static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
if (dev->bond_state != state) {
dev->bond_state = state;
send_bond_state_change(&dev->bdaddr, status, state);
+
+ store_device_info(dev);
}
}
@@ -488,6 +560,8 @@ static void set_device_uuids(struct device *dev, GSList *uuids)
g_slist_free_full(dev->uuids, g_free);
dev->uuids = uuids;
+ store_device_info(dev);
+
send_device_uuids_notif(dev);
}
@@ -2529,7 +2603,7 @@ static uint8_t set_device_friendly_name(struct device *dev, const uint8_t *val,
g_free(dev->friendly_name);
dev->friendly_name = g_strndup((const char *) val, len);
- /* TODO store friendly name */
+ store_device_info(dev);
send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_FRIENDLY_NAME,
strlen(dev->friendly_name), dev->friendly_name);
--
1.8.3.2
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox