* Re: [PATCH 1/2] android/bluetooth: Set default adapter name on first start
From: Szymon Janc @ 2014-01-09 9:32 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1389256760-10832-1-git-send-email-szymon.janc@tieto.com>
On Thursday 09 of January 2014 09:39:19 Szymon Janc wrote:
> On first start always set name to default name. Adapter name is
> updated on start only if current name is different.
> ---
> android/bluetooth.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index 9da988b..6aad9b5 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -50,6 +50,8 @@
> #include "utils.h"
> #include "bluetooth.h"
>
> +#define DEFAULT_ADAPTER_NAME "BlueZ for Android"
> +
> #define DUT_MODE_FILE "/sys/kernel/debug/bluetooth/hci%u/dut_mode"
>
> #define DEVICE_ID_SOURCE 0x0002 /* USB */
> @@ -1734,15 +1736,17 @@ static void read_info_complete(uint8_t status, uint16_t length,
>
> if (!bacmp(&adapter.bdaddr, BDADDR_ANY)) {
> bacpy(&adapter.bdaddr, &rp->bdaddr);
> - adapter.name = g_strdup((const char *) rp->name);
> + adapter.name = g_strdup(DEFAULT_ADAPTER_NAME);
> store_adapter_config();
> - set_adapter_name(rp->name, strlen((char *)rp->name));
> } else if (bacmp(&adapter.bdaddr, &rp->bdaddr)) {
> error("Bluetooth address mismatch");
> err = -ENODEV;
> goto failed;
> }
>
> + if (g_strcmp0(adapter.name, (const char *) rp->name))
> + set_adapter_name((uint8_t *)adapter.name, strlen(adapter.name));
> +
> /* Store adapter information */
> adapter.dev_class = rp->dev_class[0] | (rp->dev_class[1] << 8) |
> (rp->dev_class[2] << 16);
>
Both patches are now pushed upstream.
--
Best regards,
Szymon Janc
^ permalink raw reply
* [PATCH] shared: Fix clearing of IO handlers
From: Szymon Janc @ 2014-01-09 10:31 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
If NULL callback is passed to io_set_read/write_handler don't add watch
for it and just clear struct io memebers. This was resulting in
write/read_callback being call in loop due to fd being never written
or read.
---
src/shared/io-glib.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c
index 010dc71..443132e 100644
--- a/src/shared/io-glib.c
+++ b/src/shared/io-glib.c
@@ -142,8 +142,13 @@ bool io_set_read_handler(struct io *io, io_callback_func_t callback,
if (!io)
return false;
- if (io->read_watch > 0)
+ if (io->read_watch > 0) {
g_source_remove(io->read_watch);
+ io->read_watch = 0;
+ }
+
+ if (!callback)
+ goto done;
io->read_watch = g_io_add_watch_full(io->channel, G_PRIORITY_DEFAULT,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
@@ -151,6 +156,7 @@ bool io_set_read_handler(struct io *io, io_callback_func_t callback,
if (io->read_watch == 0)
return false;
+done:
io->read_callback = callback;
io->read_destroy = destroy;
io->read_data = user_data;
@@ -191,8 +197,13 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback,
if (!io)
return false;
- if (io->write_watch > 0)
+ if (io->write_watch > 0) {
g_source_remove(io->write_watch);
+ io->write_watch = 0;
+ }
+
+ if (!callback)
+ goto done;
io->write_watch = g_io_add_watch_full(io->channel, G_PRIORITY_DEFAULT,
G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
@@ -200,6 +211,7 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback,
if (io->write_watch == 0)
return false;
+done:
io->write_callback = callback;
io->write_destroy = destroy;
io->write_data = user_data;
--
1.8.3.2
^ permalink raw reply related
* [PATCH] android/haltest: Silence static analyzers
From: Andrei Emeltchenko @ 2014-01-09 10:45 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1389259565-995-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This makes code more readable and silence static analyzers which think
that pipe and fd are close two times.
---
android/android-tester.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/android-tester.c b/android/android-tester.c
index a448ab5..c14cc19 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -445,7 +445,7 @@ static void emulator(int pipe, int hci_index)
close(pipe);
close(fd);
- bluetoothd_start(hci_index);
+ return bluetoothd_start(hci_index);
failed:
close(pipe);
--
1.8.3.2
^ permalink raw reply related
* [PATCH 1/4] android/tester: Remove redundant whitespace
From: Grzegorz Kolodziejczyk @ 2014-01-09 11:01 UTC (permalink / raw)
To: linux-bluetooth
---
android/android-tester.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/android/android-tester.c b/android/android-tester.c
index a448ab5..4f733e1 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -189,7 +189,6 @@ static void expected_cb_count_init(struct test_data *data)
data->cb_count = test_data->expected_cb_count;
check_cb_count();
-
}
static void mgmt_cb_init(struct test_data *data)
--
1.8.5.2
^ permalink raw reply related
* [PATCH 2/4] android/tester: Use common property check function for all test props
From: Grzegorz Kolodziejczyk @ 2014-01-09 11:01 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1389265295-3344-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>
This patch makes discovery device found test case to use generic
property check method.
---
android/android-tester.c | 73 ++++++++++++++++--------------------------------
1 file changed, 24 insertions(+), 49 deletions(-)
diff --git a/android/android-tester.c b/android/android-tester.c
index 4f733e1..a63d836 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -110,35 +110,6 @@ static void test_update_state(void)
tester_test_passed();
}
-static void test_device_property(bt_property_t *property,
- bt_property_type_t type, const void *value, int len)
-{
- if (value == NULL) {
- tester_warn("NULL property passed");
- tester_test_failed();
- return;
- }
-
- if (property->type != type) {
- tester_warn("Wrong remote property type %d, expected %d",
- type, property->type);
- tester_test_failed();
- return;
- }
-
- if (property->len != len) {
- tester_warn("Wrong remote property len %d, expected %d",
- len, property->len);
- tester_test_failed();
- return;
- }
-
- if (memcmp(property->val, value, len)) {
- tester_warn("Wrong remote property value");
- tester_test_failed();
- }
-}
-
static void test_mgmt_settings_set(struct test_data *data)
{
data->mgmt_settings_set = true;
@@ -583,12 +554,14 @@ static void discovery_device_found_cb(int num_properties,
bt_property_t *properties)
{
struct test_data *data = tester_get_data();
- const uint8_t *remote_bdaddr =
- hciemu_get_client_bdaddr(data->hciemu);
- const uint32_t emu_remote_type = BT_DEVICE_DEVTYPE_BREDR;
- const int32_t emu_remote_rssi = -60;
+ uint8_t *remote_bdaddr =
+ (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
+ uint32_t emu_remote_type = BT_DEVICE_DEVTYPE_BREDR;
+ int32_t emu_remote_rssi = -60;
bt_bdaddr_t emu_remote_bdaddr;
int i;
+ bt_property_t expected_prop;
+ bt_property_t received_prop;
data->cb_count--;
@@ -598,34 +571,36 @@ static void discovery_device_found_cb(int num_properties,
bdaddr2android((const bdaddr_t *) remote_bdaddr, &emu_remote_bdaddr);
for (i = 0; i < num_properties; i++) {
- int prop_len;
- const void *prop_data;
+ received_prop = properties[i];
switch (properties[i].type) {
case BT_PROPERTY_BDADDR:
- prop_len = sizeof(emu_remote_bdaddr);
- prop_data = &emu_remote_bdaddr;
-
+ expected_prop.type = BT_PROPERTY_BDADDR;
+ expected_prop.len = sizeof(emu_remote_bdaddr);
+ expected_prop.val = &emu_remote_bdaddr;
break;
- case BT_PROPERTY_TYPE_OF_DEVICE:
- prop_len = sizeof(emu_remote_type);
- prop_data = &emu_remote_type;
+ case BT_PROPERTY_TYPE_OF_DEVICE:
+ expected_prop.type = BT_PROPERTY_TYPE_OF_DEVICE;
+ expected_prop.len = sizeof(emu_remote_type);
+ expected_prop.val = &emu_remote_type;
break;
- case BT_PROPERTY_REMOTE_RSSI:
- prop_len = sizeof(emu_remote_rssi);
- prop_data = &emu_remote_rssi;
+ case BT_PROPERTY_REMOTE_RSSI:
+ expected_prop.type = BT_PROPERTY_REMOTE_RSSI;
+ expected_prop.len = sizeof(emu_remote_rssi);
+ expected_prop.val = &emu_remote_rssi;
break;
- default:
- prop_len = 0;
- prop_data = NULL;
+ default:
+ expected_prop.type = 0;
+ expected_prop.len = 0;
+ expected_prop.val = NULL;
break;
}
- test_device_property(&properties[i], properties[i].type,
- prop_data, prop_len);
+ if (!check_test_property(received_prop, expected_prop))
+ tester_test_failed();
}
}
--
1.8.5.2
^ permalink raw reply related
* [PATCH 3/4] android/tester: Add test case state handling
From: Grzegorz Kolodziejczyk @ 2014-01-09 11:01 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1389265295-3344-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>
This patch make test state handling more stable by avoiding errors like
i.e. double free of memory in teardown phase. Double state set is
undesirable for test case and may cause errors. Now after every
condition change, test state is checked if it can set test state to pass.
In some places of test fail, returns are added to avoid furhter code
execution.
---
android/android-tester.c | 43 ++++++++++++++++++++++++++++---------------
1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/android/android-tester.c b/android/android-tester.c
index a63d836..a29c982 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -147,10 +147,10 @@ static void check_cb_count(void)
if (!data->test_init_done)
return;
- if (data->cb_count == 0)
+ if (data->cb_count == 0) {
data->cb_count_checked = true;
-
- test_update_state();
+ test_update_state();
+ }
}
static void expected_cb_count_init(struct test_data *data)
@@ -205,12 +205,11 @@ static void check_expected_status(uint8_t status)
struct test_data *data = tester_get_data();
const struct generic_data *test_data = data->test_data;
- if (test_data->expected_adapter_status == status)
+ if (test_data->expected_adapter_status == status) {
data->status_checked = true;
- else
+ test_update_state();
+ } else
tester_test_failed();
-
- test_update_state();
}
static bool check_test_property(bt_property_t received_prop,
@@ -467,6 +466,7 @@ static void enable_success_cb(bt_state_t state)
if (state == BT_STATE_ON) {
setup_powered_emulated_remote();
data->cb_count--;
+ check_cb_count();
}
}
@@ -474,8 +474,10 @@ static void disable_success_cb(bt_state_t state)
{
struct test_data *data = tester_get_data();
- if (state == BT_STATE_OFF)
+ if (state == BT_STATE_OFF) {
data->cb_count--;
+ check_cb_count();
+ }
}
static void adapter_state_changed_cb(bt_state_t state)
@@ -486,7 +488,6 @@ static void adapter_state_changed_cb(bt_state_t state)
if (data->test_init_done &&
test->expected_hal_cb.adapter_state_changed_cb) {
test->expected_hal_cb.adapter_state_changed_cb(state);
- check_cb_count();
return;
}
@@ -498,8 +499,10 @@ static void discovery_start_success_cb(bt_discovery_state_t state)
{
struct test_data *data = tester_get_data();
- if (state == BT_DISCOVERY_STARTED)
+ if (state == BT_DISCOVERY_STARTED) {
data->cb_count--;
+ check_cb_count();
+ }
}
static void discovery_start_done_cb(bt_discovery_state_t state)
@@ -509,6 +512,8 @@ static void discovery_start_done_cb(bt_discovery_state_t state)
status = data->if_bluetooth->start_discovery();
data->cb_count--;
+
+ check_cb_count();
check_expected_status(status);
}
@@ -523,8 +528,10 @@ static void discovery_stop_success_cb(bt_discovery_state_t state)
data->cb_count--;
return;
}
- if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1)
+ if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1) {
data->cb_count--;
+ check_cb_count();
+ }
}
static void discovery_device_found_state_changed_cb(bt_discovery_state_t state)
@@ -535,8 +542,10 @@ static void discovery_device_found_state_changed_cb(bt_discovery_state_t state)
data->cb_count--;
return;
}
- if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1)
+ if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1) {
data->cb_count--;
+ check_cb_count();
+ }
}
static void discovery_state_changed_cb(bt_discovery_state_t state)
@@ -546,7 +555,6 @@ static void discovery_state_changed_cb(bt_discovery_state_t state)
if (test && test->expected_hal_cb.discovery_state_changed_cb) {
test->expected_hal_cb.discovery_state_changed_cb(state);
- check_cb_count();
}
}
@@ -564,9 +572,12 @@ static void discovery_device_found_cb(int num_properties,
bt_property_t received_prop;
data->cb_count--;
+ check_cb_count();
- if (num_properties < 1)
+ if (num_properties < 1) {
tester_test_failed();
+ return;
+ }
bdaddr2android((const bdaddr_t *) remote_bdaddr, &emu_remote_bdaddr);
@@ -599,8 +610,10 @@ static void discovery_device_found_cb(int num_properties,
break;
}
- if (!check_test_property(received_prop, expected_prop))
+ if (!check_test_property(received_prop, expected_prop)) {
tester_test_failed();
+ return;
+ }
}
}
--
1.8.5.2
^ permalink raw reply related
* [PATCH 4/4] android/tester: Multi property check for test case
From: Grzegorz Kolodziejczyk @ 2014-01-09 11:01 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1389265295-3344-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>
This patch allows to check multiple properties for test case. Properties
can be prioritized to allow check if they'll come in right order. Now
properties aren't treated as a "single" callback. In future in one
callback multiple properties can come.
---
android/android-tester.c | 525 ++++++++++++++++++++++++++++++++++-------------
1 file changed, 381 insertions(+), 144 deletions(-)
diff --git a/android/android-tester.c b/android/android-tester.c
index a29c982..1c538e2 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -43,13 +43,19 @@
#include "utils.h"
+struct priority_property {
+ bt_property_t prop;
+ int prio;
+};
+
struct generic_data {
int expected_adapter_status;
uint32_t expect_settings_set;
int expected_cb_count;
bt_property_t set_property;
- bt_property_t expected_property;
bt_callbacks_t expected_hal_cb;
+ struct priority_property *expected_properties;
+ uint8_t expected_properties_num;
};
struct socket_data {
@@ -91,6 +97,7 @@ struct test_data {
bool test_init_done;
int cb_count;
+ GSList *expected_properties_list;
};
static char exec_dir[PATH_MAX + 1];
@@ -185,9 +192,18 @@ static void expected_status_init(struct test_data *data)
static void test_property_init(struct test_data *data)
{
const struct generic_data *test_data = data->test_data;
+ GSList *l = data->expected_properties_list;
+ int i;
- if (!test_data->expected_property.type)
+ if (!test_data->expected_hal_cb.adapter_properties_cb) {
data->property_checked = true;
+ return;
+ }
+
+ for (i = 0; i < test_data->expected_properties_num; i++)
+ l = g_slist_prepend(l, &(test_data->expected_properties[i]));
+
+ data->expected_properties_list = l;
}
static void init_test_conditions(struct test_data *data)
@@ -212,6 +228,73 @@ static void check_expected_status(uint8_t status)
tester_test_failed();
}
+static int locate_property(gconstpointer expected_data,
+ gconstpointer received_prop)
+{
+ bt_property_t rec_prop = *((bt_property_t *)received_prop);
+ bt_property_t exp_prop =
+ ((struct priority_property *)expected_data)->prop;
+
+ if (exp_prop.type && (exp_prop.type != rec_prop.type))
+ return 1;
+ if (exp_prop.len && (exp_prop.len != rec_prop.len))
+ return 1;
+ if (exp_prop.val && memcmp(exp_prop.val, rec_prop.val, exp_prop.len))
+ return 1;
+
+ return 0;
+}
+
+static int compare_priorities(gconstpointer prop_list, gconstpointer priority)
+{
+ int prio = GPOINTER_TO_INT(priority);
+ int comp_prio = ((struct priority_property *)prop_list)->prio;
+
+ if (prio > comp_prio)
+ return 0;
+
+ return 1;
+}
+
+static bool check_prop_priority(int rec_prop_prio)
+{
+ struct test_data *data = tester_get_data();
+ GSList *l = data->expected_properties_list;
+
+ if (!rec_prop_prio || !g_slist_length(l))
+ return true;
+
+ if (g_slist_find_custom(l, GINT_TO_POINTER(rec_prop_prio),
+ &compare_priorities))
+ return false;
+
+ return true;
+}
+
+static void check_expected_property(bt_property_t received_prop)
+{
+ struct test_data *data = tester_get_data();
+ int rec_prio;
+ GSList *l = data->expected_properties_list;
+ GSList *found_exp_prop;
+
+ found_exp_prop = g_slist_find_custom(l, &received_prop,
+ &locate_property);
+
+ if (found_exp_prop) {
+ rec_prio = ((struct priority_property *)
+ (found_exp_prop->data))->prio;
+ if (check_prop_priority(rec_prio))
+ l = g_slist_remove(l, found_exp_prop->data);
+ }
+
+ if (g_slist_length(l))
+ return;
+
+ data->property_checked = true;
+ test_update_state();
+}
+
static bool check_test_property(bt_property_t received_prop,
bt_property_t expected_prop)
{
@@ -625,27 +708,18 @@ static void device_found_cb(int num_properties, bt_property_t *properties)
if (data->test_init_done && test->expected_hal_cb.device_found_cb) {
test->expected_hal_cb.device_found_cb(num_properties,
properties);
- check_cb_count();
}
}
static void check_count_properties_cb(bt_status_t status, int num_properties,
bt_property_t *properties)
{
- struct test_data *data = tester_get_data();
+ int i;
- data->cb_count--;
+ for (i = 0; i < num_properties; i++)
+ check_expected_property(properties[i]);
}
-static void getprop_success_cb(bt_status_t status, int num_properties,
- bt_property_t *properties)
-{
- struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
-
- if (check_test_property(properties[0], test->expected_property))
- data->cb_count--;
-}
static void adapter_properties_cb(bt_status_t status, int num_properties,
bt_property_t *properties)
@@ -658,21 +732,87 @@ static void adapter_properties_cb(bt_status_t status, int num_properties,
test->expected_hal_cb.adapter_properties_cb(
status, num_properties,
properties);
- check_cb_count();
}
}
+static bt_bdaddr_t enable_done_bdaddr_val = {
+ .address = { 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00 },
+};
+static const char enable_done_bdname_val[] = "";
+static bt_uuid_t enable_done_uuids_val = {
+ .uu = { 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00,
+ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb},
+};
+static uint32_t enable_done_cod_val = 0;
+static bt_device_type_t enable_done_tod_val = BT_DEVICE_DEVTYPE_BREDR;
+static bt_scan_mode_t enable_done_scanmode_val = BT_SCAN_MODE_NONE;
+static uint32_t enable_done_disctimeout_val = 120;
+
+static struct priority_property enable_done_props[] = {
+ {
+ .prop.type = BT_PROPERTY_BDADDR,
+ .prop.len = sizeof(enable_done_bdaddr_val),
+ .prop.val = &enable_done_bdaddr_val,
+ .prio = 1,
+ },
+ {
+ .prop.type = BT_PROPERTY_BDNAME,
+ .prop.len = sizeof(enable_done_bdname_val) - 1,
+ .prop.val = &enable_done_bdname_val,
+ .prio = 2,
+ },
+ {
+ .prop.type = BT_PROPERTY_UUIDS,
+ .prop.len = sizeof(enable_done_uuids_val),
+ .prop.val = &enable_done_uuids_val,
+ .prio = 3,
+ },
+ {
+ .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
+ .prop.len = sizeof(enable_done_cod_val),
+ .prop.val = &enable_done_cod_val,
+ .prio = 4,
+ },
+ {
+ .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
+ .prop.len = sizeof(enable_done_tod_val),
+ .prop.val = &enable_done_tod_val,
+ .prio = 5,
+ },
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
+ .prop.len = sizeof(enable_done_scanmode_val),
+ .prop.val = &enable_done_scanmode_val,
+ .prio = 6,
+ },
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
+ .prop.len = 0,
+ .prop.val = NULL,
+ .prio = 7,
+ },
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
+ .prop.len = sizeof(enable_done_disctimeout_val),
+ .prop.val = &enable_done_disctimeout_val,
+ .prio = 8,
+ },
+};
+
static const struct generic_data bluetooth_enable_success_test = {
.expected_hal_cb.adapter_state_changed_cb = enable_success_cb,
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
- .expected_cb_count = 9,
+ .expected_cb_count = 1,
+ .expected_properties_num = 8,
+ .expected_properties = enable_done_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bluetooth_enable_done_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
- .expected_cb_count = 8,
.expected_adapter_status = BT_STATUS_DONE,
+ .expected_properties_num = 8,
+ .expected_properties = enable_done_props,
};
static const struct generic_data bluetooth_disable_success_test = {
@@ -683,94 +823,148 @@ static const struct generic_data bluetooth_disable_success_test = {
static char test_set_bdname[] = "test_bdname_set";
+static struct priority_property setprop_bdname_props[] = {
+ {
+ .prop.type = BT_PROPERTY_BDNAME,
+ .prop.val = test_set_bdname,
+ .prop.len = sizeof(test_set_bdname) - 1,
+ .prio = 0,
+ },
+};
+
static const struct generic_data bluetooth_setprop_bdname_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
- .expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_BDNAME,
- .expected_property.val = test_set_bdname,
- .expected_property.len = sizeof(test_set_bdname) - 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = setprop_bdname_props,
};
static bt_scan_mode_t test_setprop_scanmode_val =
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE;
+static struct priority_property setprop_scanmode_props[] = {
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
+ .prop.val = &test_setprop_scanmode_val,
+ .prop.len = sizeof(bt_scan_mode_t),
+ },
+};
+
static const struct generic_data bluetooth_setprop_scanmode_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = setprop_scanmode_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
- .expected_property.val = &test_setprop_scanmode_val,
- .expected_property.len = sizeof(bt_scan_mode_t),
};
static uint32_t test_setprop_disctimeout_val = 120;
+static struct priority_property setprop_disctimeout_props[] = {
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
+ .prop.val = &test_setprop_disctimeout_val,
+ .prop.len = sizeof(test_setprop_disctimeout_val),
+ },
+};
+
static const struct generic_data bluetooth_setprop_disctimeout_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = setprop_disctimeout_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
- .expected_property.val = &test_setprop_disctimeout_val,
- .expected_property.len = sizeof(test_setprop_disctimeout_val),
+};
+
+static bt_bdaddr_t test_getprop_bdaddr_val = {
+ .address = { 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00 }
+};
+
+static struct priority_property getprop_bdaddr_props[] = {
+ {
+ .prop.type = BT_PROPERTY_BDADDR,
+ .prop.val = &test_getprop_bdaddr_val,
+ .prop.len = sizeof(test_getprop_bdaddr_val),
+ },
};
static const struct generic_data bluetooth_getprop_bdaddr_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = getprop_bdaddr_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_BDADDR,
- .expected_property.val = NULL,
- .expected_property.len = sizeof(bt_bdaddr_t),
};
static char test_bdname[] = "test_bdname_setget";
+static struct priority_property getprop_bdname_props[] = {
+ {
+ .prop.type = BT_PROPERTY_BDNAME,
+ .prop.val = &test_bdname,
+ .prop.len = sizeof(test_bdname) - 1,
+ },
+};
+
static const struct generic_data bluetooth_getprop_bdname_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = getprop_bdname_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_BDNAME,
- .expected_property.val = test_bdname,
- .expected_property.len = sizeof(test_bdname) - 1,
};
static unsigned char setprop_uuids[] = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00,
0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
+static struct priority_property setprop_uuid_prop[] = {
+ {
+ .prop.type = BT_PROPERTY_UUIDS,
+ .prop.val = &setprop_uuids,
+ .prop.len = sizeof(setprop_uuids),
+ },
+};
+
static const struct generic_data bluetooth_setprop_uuid_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
- .set_property.type = BT_PROPERTY_UUIDS,
- .set_property.val = &setprop_uuids,
- .set_property.len = sizeof(setprop_uuids),
};
static uint32_t setprop_class_of_device = 0;
+static struct priority_property setprop_cod_props[] = {
+ {
+ .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
+ .prop.val = &setprop_class_of_device,
+ .prop.len = sizeof(setprop_class_of_device),
+ },
+};
+
static const struct generic_data bluetooth_setprop_cod_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
- .set_property.type = BT_PROPERTY_CLASS_OF_DEVICE,
- .set_property.val = &setprop_class_of_device,
- .set_property.len = sizeof(setprop_class_of_device),
};
static bt_device_type_t setprop_type_of_device = BT_DEVICE_DEVTYPE_BREDR;
+static struct priority_property setprop_tod_props[] = {
+ {
+ .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
+ .prop.val = &setprop_type_of_device,
+ .prop.len = sizeof(setprop_type_of_device),
+ },
+};
+
static const struct generic_data bluetooth_setprop_tod_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
- .set_property.type = BT_PROPERTY_TYPE_OF_DEVICE,
- .set_property.val = &setprop_type_of_device,
- .set_property.len = sizeof(setprop_type_of_device),
};
static int32_t setprop_remote_rssi = 0;
+static struct priority_property setprop_remote_rssi_props[] = {
+ {
+ .prop.type = BT_PROPERTY_REMOTE_RSSI,
+ .prop.val = &setprop_remote_rssi,
+ .prop.len = sizeof(setprop_remote_rssi),
+ },
+};
+
static const struct generic_data bluetooth_setprop_remote_rssi_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
- .set_property.type = BT_PROPERTY_REMOTE_RSSI,
- .set_property.val = &setprop_remote_rssi,
- .set_property.len = sizeof(setprop_remote_rssi),
};
static bt_service_record_t setprop_remote_service = {
@@ -779,91 +973,136 @@ static bt_service_record_t setprop_remote_service = {
.name = "bt_name",
};
+static struct priority_property setprop_service_record_props[] = {
+ {
+ .prop.type = BT_PROPERTY_SERVICE_RECORD,
+ .prop.val = &setprop_remote_service,
+ .prop.len = sizeof(setprop_remote_service),
+ },
+};
+
static const struct generic_data
bluetooth_setprop_service_record_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
- .set_property.type = BT_PROPERTY_SERVICE_RECORD,
- .set_property.val = &setprop_remote_service,
- .set_property.len = sizeof(setprop_remote_service),
};
static bt_bdaddr_t setprop_bdaddr = {
.address = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
+static struct priority_property setprop_bdaddr_props[] = {
+ {
+ .prop.type = BT_PROPERTY_BDADDR,
+ .prop.val = &setprop_bdaddr,
+ .prop.len = sizeof(setprop_bdaddr),
+ },
+};
+
static const struct generic_data bluetooth_setprop_bdaddr_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
- .set_property.type = BT_PROPERTY_BDADDR,
- .set_property.val = &setprop_bdaddr,
- .set_property.len = sizeof(setprop_bdaddr),
};
static bt_scan_mode_t setprop_scanmode_connectable = BT_SCAN_MODE_CONNECTABLE;
+static struct priority_property setprop_scanmode_connectable_props[] = {
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
+ .prop.val = &setprop_scanmode_connectable,
+ .prop.len = sizeof(setprop_scanmode_connectable),
+ },
+};
+
static const struct generic_data
bluetooth_setprop_scanmode_connectable_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = setprop_scanmode_connectable_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
- .expected_property.val = &setprop_scanmode_connectable,
- .expected_property.len = sizeof(setprop_scanmode_connectable),
};
static bt_bdaddr_t setprop_bonded_devices = {
.address = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
};
+static struct priority_property setprop_bonded_devices_props[] = {
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
+ .prop.val = &setprop_bonded_devices,
+ .prop.len = sizeof(setprop_bonded_devices),
+ },
+};
+
static const struct generic_data
bluetooth_setprop_bonded_devices_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
- .set_property.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
- .set_property.val = &setprop_bonded_devices,
- .set_property.len = sizeof(setprop_bonded_devices),
};
static uint32_t getprop_cod = 0;
+static struct priority_property getprop_cod_props[] = {
+ {
+ .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
+ .prop.val = &getprop_cod,
+ .prop.len = sizeof(getprop_cod),
+ },
+};
+
static const struct generic_data bluetooth_getprop_cod_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = getprop_cod_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_CLASS_OF_DEVICE,
- .expected_property.val = &getprop_cod,
- .expected_property.len = sizeof(getprop_cod),
};
static bt_device_type_t getprop_tod = BT_DEVICE_DEVTYPE_BREDR;
+static struct priority_property getprop_tod_props[] = {
+ {
+ .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
+ .prop.val = &getprop_tod,
+ .prop.len = sizeof(getprop_tod),
+ },
+};
+
static const struct generic_data bluetooth_getprop_tod_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = getprop_tod_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_TYPE_OF_DEVICE,
- .expected_property.val = &getprop_tod,
- .expected_property.len = sizeof(getprop_tod),
};
static bt_scan_mode_t getprop_scanmode = BT_SCAN_MODE_NONE;
+static struct priority_property getprop_scanmode_props[] = {
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
+ .prop.val = &getprop_scanmode,
+ .prop.len = sizeof(getprop_scanmode),
+ },
+};
+
static const struct generic_data bluetooth_getprop_scanmode_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = getprop_scanmode_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
- .expected_property.val = &getprop_scanmode,
- .expected_property.len = sizeof(getprop_scanmode),
};
static uint32_t getprop_disctimeout_val = 120;
+static struct priority_property getprop_disctimeout_props[] = {
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
+ .prop.val = &getprop_disctimeout_val,
+ .prop.len = sizeof(getprop_disctimeout_val),
+ },
+};
+
static const struct generic_data bluetooth_getprop_disctimeout_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = getprop_disctimeout_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
- .expected_property.val = &getprop_disctimeout_val,
- .expected_property.len = sizeof(getprop_disctimeout_val),
};
static bt_uuid_t getprop_uuids = {
@@ -871,33 +1110,51 @@ static bt_uuid_t getprop_uuids = {
0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB },
};
+static struct priority_property getprop_uuids_props[] = {
+ {
+ .prop.type = BT_PROPERTY_UUIDS,
+ .prop.val = &getprop_uuids,
+ .prop.len = sizeof(getprop_uuids),
+ },
+};
+
static const struct generic_data bluetooth_getprop_uuids_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = getprop_uuids_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_UUIDS,
- .expected_property.val = &getprop_uuids,
- .expected_property.len = sizeof(getprop_uuids),
+};
+
+static struct priority_property getprop_bondeddev_props[] = {
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
+ .prop.val = NULL,
+ .prop.len = 0,
+ },
};
static const struct generic_data bluetooth_getprop_bondeddev_success_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = getprop_bondeddev_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
- .expected_property.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
- .expected_property.val = NULL,
- .expected_property.len = 0,
};
static bt_scan_mode_t setprop_scanmode_none = BT_SCAN_MODE_NONE;
+static struct priority_property setprop_scanmode_none_props[] = {
+ {
+ .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
+ .prop.val = &setprop_scanmode_none,
+ .prop.len = sizeof(setprop_scanmode_none),
+ },
+};
+
static const struct generic_data bluetooth_setprop_scanmode_none_done_test = {
- .expected_hal_cb.adapter_properties_cb = getprop_success_cb,
- .expected_cb_count = 1,
+ .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
+ .expected_properties_num = 1,
+ .expected_properties = setprop_scanmode_none_props,
.expected_adapter_status = BT_STATUS_DONE,
- .expected_property.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
- .expected_property.val = &setprop_scanmode_none,
- .expected_property.len = sizeof(setprop_scanmode_none),
};
static const struct generic_data bluetooth_discovery_start_success_test = {
@@ -1122,22 +1379,19 @@ static void test_disable(const void *test_data)
static void test_setprop_bdname_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_bdname_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
-
check_expected_status(adapter_status);
}
static void test_setprop_scanmode_succes(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_scanmode_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1149,8 +1403,7 @@ static void test_setprop_scanmode_succes(const void *test_data)
static void test_setprop_disctimeout_succes(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_disctimeout_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1162,8 +1415,7 @@ static void test_setprop_disctimeout_succes(const void *test_data)
static void test_getprop_bdaddr_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t prop = test->expected_property;
+ const bt_property_t prop = setprop_bdaddr_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1175,8 +1427,7 @@ static void test_getprop_bdaddr_success(const void *test_data)
static void test_getprop_bdname_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(getprop_bdname_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1187,12 +1438,10 @@ static void test_getprop_bdname_success(const void *test_data)
adapter_status = data->if_bluetooth->get_adapter_property((*prop).type);
check_expected_status(adapter_status);
}
-
static void test_setprop_uuid_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_uuid_prop[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1204,8 +1453,7 @@ static void test_setprop_uuid_invalid(const void *test_data)
static void test_setprop_cod_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_cod_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1230,8 +1478,7 @@ static void test_setprop_tod_invalid(const void *test_data)
static void test_setprop_rssi_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_remote_rssi_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1243,8 +1490,7 @@ static void test_setprop_rssi_invalid(const void *test_data)
static void test_setprop_service_record_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_service_record_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1256,8 +1502,7 @@ static void test_setprop_service_record_invalid(const void *test_data)
static void test_setprop_bdaddr_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_bdaddr_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1269,8 +1514,8 @@ static void test_setprop_bdaddr_invalid(const void *test_data)
static void test_setprop_scanmode_connectable_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop =
+ &(setprop_scanmode_connectable_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1282,8 +1527,7 @@ static void test_setprop_scanmode_connectable_success(const void *test_data)
static void test_setprop_bonded_devices_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_bonded_devices_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1295,8 +1539,7 @@ static void test_setprop_bonded_devices_invalid(const void *test_data)
static void test_getprop_cod_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t prop = test->expected_property;
+ const bt_property_t prop = setprop_cod_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1308,8 +1551,7 @@ static void test_getprop_cod_success(const void *test_data)
static void test_getprop_tod_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t prop = test->expected_property;
+ const bt_property_t prop = setprop_tod_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1321,8 +1563,7 @@ static void test_getprop_tod_success(const void *test_data)
static void test_getprop_scanmode_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t prop = test->expected_property;
+ const bt_property_t prop = setprop_scanmode_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1334,8 +1575,7 @@ static void test_getprop_scanmode_success(const void *test_data)
static void test_getprop_disctimeout_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t prop = test->expected_property;
+ const bt_property_t prop = setprop_disctimeout_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1347,8 +1587,7 @@ static void test_getprop_disctimeout_success(const void *test_data)
static void test_getprop_uuids_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t prop = test->expected_property;
+ const bt_property_t prop = getprop_uuids_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1360,8 +1599,7 @@ static void test_getprop_uuids_success(const void *test_data)
static void test_getprop_bondeddev_success(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t prop = test->expected_property;
+ const bt_property_t prop = getprop_bondeddev_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
@@ -1373,8 +1611,7 @@ static void test_getprop_bondeddev_success(const void *test_data)
static void test_setprop_scanmode_none_done(const void *test_data)
{
struct test_data *data = tester_get_data();
- const struct generic_data *test = data->test_data;
- const bt_property_t *prop = &test->expected_property;
+ const bt_property_t *prop = &(setprop_scanmode_none_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
--
1.8.5.2
^ permalink raw reply related
* [PATCH 0/4] Next skeleton patches for audio plugin
From: Lukasz Rymanowski @ 2014-01-09 11:45 UTC (permalink / raw)
To: linux-bluetooth; +Cc: luiz.dentz, szymon.janc, johan.hedberg, Lukasz Rymanowski
Those patches adds function to handle send/receive msg on audio IPC.
Also do some small changes.
Not that since we do not yet support AUDIO_OP_OPEN, audio socket will be
reseted just after connect.
Lukasz Rymanowski (4):
android/audio: Prefix error log with "a2dp"
android/audio: Change mainloop handle in ipc_handler
android/audio: Add skeleton for open_endpoint_cmd function
android/audio: Add audio_ipc_cmd
android/Makefile.am | 1 +
android/hal-audio.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 186 insertions(+), 11 deletions(-)
--
1.8.4
^ permalink raw reply
* [PATCH 1/4] android/audio: Prefix error log with "a2dp"
From: Lukasz Rymanowski @ 2014-01-09 11:45 UTC (permalink / raw)
To: linux-bluetooth; +Cc: luiz.dentz, szymon.janc, johan.hedberg, Lukasz Rymanowski
In-Reply-To: <1389267956-2297-1-git-send-email-lukasz.rymanowski@tieto.com>
---
android/hal-audio.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/android/hal-audio.c b/android/hal-audio.c
index 59a8269..7a7c111 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -423,7 +423,8 @@ static bool create_audio_ipc(void)
sk = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
if (sk < 0) {
err = errno;
- error("Failed to create socket: %d (%s)", err, strerror(err));
+ error("a2dp: Failed to create socket: %d (%s)", err,
+ strerror(err));
return false;
}
@@ -435,13 +436,14 @@ static bool create_audio_ipc(void)
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
err = errno;
- error("Failed to bind socket: %d (%s)", err, strerror(err));
+ error("a2dp: Failed to bind socket: %d (%s)", err,
+ strerror(err));
goto failed;
}
if (listen(sk, 1) < 0) {
err = errno;
- error("Failed to listen on the socket: %d (%s)", err,
+ error("a2dp: Failed to listen on the socket: %d (%s)", err,
strerror(err));
goto failed;
}
@@ -449,7 +451,7 @@ static bool create_audio_ipc(void)
audio_sk = accept(sk, NULL, NULL);
if (audio_sk < 0) {
err = errno;
- error("Failed to accept socket: %d (%s)", err, strerror(err));
+ error("a2dp: Failed to accept socket: %d (%s)", err, strerror(err));
goto failed;
}
@@ -470,7 +472,7 @@ static void *ipc_handler(void *data)
while (!done) {
if(!create_audio_ipc()) {
- error("Failed to create listening socket");
+ error("a2dp: Failed to create listening socket");
sleep(1);
continue;
}
@@ -511,7 +513,7 @@ static int audio_open(const hw_module_t *module, const char *name,
DBG("");
if (strcmp(name, AUDIO_HARDWARE_INTERFACE)) {
- error("interface %s not matching [%s]", name,
+ error("ad2p: interface %s not matching [%s]", name,
AUDIO_HARDWARE_INTERFACE);
return -EINVAL;
}
@@ -547,7 +549,7 @@ static int audio_open(const hw_module_t *module, const char *name,
err = pthread_create(&ipc_th, NULL, ipc_handler, NULL);
if (err < 0) {
ipc_th = 0;
- error("Failed to start Audio IPC thread: %d (%s)",
+ error("a2dp: Failed to start Audio IPC thread: %d (%s)",
-err, strerror(-err));
return (-err);
}
--
1.8.4
^ permalink raw reply related
* [PATCH 2/4] android/audio: Change mainloop handle in ipc_handler
From: Lukasz Rymanowski @ 2014-01-09 11:45 UTC (permalink / raw)
To: linux-bluetooth; +Cc: luiz.dentz, szymon.janc, johan.hedberg, Lukasz Rymanowski
In-Reply-To: <1389267956-2297-1-git-send-email-lukasz.rymanowski@tieto.com>
Make sure we wait 1 sec after each loop iteration.
It is important in case of failure that we do not overload cpu.
---
android/hal-audio.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/android/hal-audio.c b/android/hal-audio.c
index 7a7c111..4a12bcb 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -465,15 +465,14 @@ failed:
static void *ipc_handler(void *data)
{
- bool done = false;
struct pollfd pfd;
+ bool done;
DBG("");
- while (!done) {
+ for (done = false; !done; sleep(1)) {
if(!create_audio_ipc()) {
error("a2dp: Failed to create listening socket");
- sleep(1);
continue;
}
--
1.8.4
^ permalink raw reply related
* [PATCH 3/4] android/audio: Add skeleton for open_endpoint_cmd function
From: Lukasz Rymanowski @ 2014-01-09 11:45 UTC (permalink / raw)
To: linux-bluetooth; +Cc: luiz.dentz, szymon.janc, johan.hedberg, Lukasz Rymanowski
In-Reply-To: <1389267956-2297-1-git-send-email-lukasz.rymanowski@tieto.com>
---
android/hal-audio.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/android/hal-audio.c b/android/hal-audio.c
index 4a12bcb..95efa89 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -412,6 +412,13 @@ static int audio_close(hw_device_t *device)
return 0;
}
+static int open_endpoint_cmd(void)
+{
+ DBG("Not Implemented");
+
+ return AUDIO_STATUS_FAILED;
+}
+
static bool create_audio_ipc(void)
{
struct sockaddr_un addr;
@@ -478,7 +485,10 @@ static void *ipc_handler(void *data)
DBG("Audio IPC: Connected");
- /* TODO: Register ENDPOINT here */
+ if (open_endpoint_cmd() == AUDIO_STATUS_FAILED) {
+ error("a2dp: failed to open endpoint");
+ continue;
+ }
memset(&pfd, 0, sizeof(pfd));
pfd.fd = audio_sk;
--
1.8.4
^ permalink raw reply related
* [PATCH 4/4] android/audio: Add audio_ipc_cmd
From: Lukasz Rymanowski @ 2014-01-09 11:45 UTC (permalink / raw)
To: linux-bluetooth; +Cc: luiz.dentz, szymon.janc, johan.hedberg, Lukasz Rymanowski
In-Reply-To: <1389267956-2297-1-git-send-email-lukasz.rymanowski@tieto.com>
Adds function to handle send/receive on audio_sk
---
android/Makefile.am | 1 +
android/hal-audio.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 166 insertions(+), 2 deletions(-)
diff --git a/android/Makefile.am b/android/Makefile.am
index 0a32a95..94e5329 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -117,6 +117,7 @@ android_android_tester_LDFLAGS = -pthread
noinst_LTLIBRARIES += android/libaudio-internal.la
android_libaudio_internal_la_SOURCES = android/audio-msg.h \
+ android/hal-msg.h \
android/hal-audio.c \
android/hardware/audio.h \
android/hardware/audio_effect.h \
diff --git a/android/hal-audio.c b/android/hal-audio.c
index 95efa89..e515f53 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -31,12 +31,14 @@
#include "audio-msg.h"
#include "hal-log.h"
+#include "hal-msg.h"
static int audio_sk = -1;
static bool close_thread = false;
static pthread_t ipc_th = 0;
static pthread_mutex_t close_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t sk_mutex = PTHREAD_MUTEX_INITIALIZER;
struct a2dp_audio_dev {
struct audio_hw_device dev;
@@ -412,13 +414,174 @@ static int audio_close(hw_device_t *device)
return 0;
}
-static int open_endpoint_cmd(void)
+static int audio_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len,
+ void *param, size_t *rsp_len, void *rsp, int *fd)
{
- DBG("Not Implemented");
+ ssize_t ret;
+ struct msghdr msg;
+ struct iovec iv[2];
+ struct hal_hdr cmd;
+ char cmsgbuf[CMSG_SPACE(sizeof(int))];
+ struct hal_status s;
+ size_t s_len = sizeof(s);
+
+ if (audio_sk < 0) {
+ error("a2dp: Invalid cmd socket passed to audio_sk");
+ goto failed;
+ }
+
+ if (!rsp || !rsp_len) {
+ memset(&s, 0, s_len);
+ rsp_len = &s_len;
+ rsp = &s;
+ }
+
+ memset(&msg, 0, sizeof(msg));
+ memset(&cmd, 0, sizeof(cmd));
+
+ cmd.service_id = service_id;
+ cmd.opcode = opcode;
+ cmd.len = len;
+
+ iv[0].iov_base = &cmd;
+ iv[0].iov_len = sizeof(cmd);
+
+ iv[1].iov_base = param;
+ iv[1].iov_len = len;
+
+ msg.msg_iov = iv;
+ msg.msg_iovlen = 2;
+
+ pthread_mutex_lock(&sk_mutex);
+
+ ret = sendmsg(audio_sk, &msg, 0);
+ if (ret < 0) {
+ error("a2dp: Sending command failed:%s", strerror(errno));
+ pthread_mutex_unlock(&sk_mutex);
+ goto failed;
+ }
+
+ /* socket was shutdown */
+ if (ret == 0) {
+ error("a2dp: Command socket closed");
+ goto failed;
+ }
+
+ memset(&msg, 0, sizeof(msg));
+ memset(&cmd, 0, sizeof(cmd));
+
+ iv[0].iov_base = &cmd;
+ iv[0].iov_len = sizeof(cmd);
+
+ iv[1].iov_base = rsp;
+ iv[1].iov_len = *rsp_len;
+
+ msg.msg_iov = iv;
+ msg.msg_iovlen = 2;
+
+ if (fd) {
+ memset(cmsgbuf, 0, sizeof(cmsgbuf));
+ msg.msg_control = cmsgbuf;
+ msg.msg_controllen = sizeof(cmsgbuf);
+ }
+
+ ret = recvmsg(audio_sk, &msg, 0);
+ if (ret < 0) {
+ error("a2dp: Receiving command response failed:%s",
+ strerror(errno));
+ pthread_mutex_unlock(&sk_mutex);
+ goto failed;
+ }
+
+ pthread_mutex_unlock(&sk_mutex);
+
+ if (ret < (ssize_t) sizeof(cmd)) {
+ error("a2dp: Too small response received(%zd bytes)", ret);
+ goto failed;
+ }
+
+ if (cmd.service_id != service_id) {
+ error("a2dp: Invalid service id (%u vs %u)", cmd.service_id,
+ service_id);
+ goto failed;
+ }
+
+ if (ret != (ssize_t) (sizeof(cmd) + cmd.len)) {
+ error("a2dp: Malformed response received(%zd bytes)", ret);
+ goto failed;
+ }
+
+ if (cmd.opcode != opcode && cmd.opcode != AUDIO_OP_STATUS) {
+ error("a2dp: Invalid opcode received (%u vs %u)",
+ cmd.opcode, opcode);
+ goto failed;
+ }
+
+ if (cmd.opcode == AUDIO_OP_STATUS) {
+ struct hal_status *s = rsp;
+
+ if (sizeof(*s) != cmd.len) {
+ error("a2dp: Invalid status length");
+ goto failed;
+ }
+
+ if (s->code == AUDIO_STATUS_SUCCESS) {
+ error("a2dp: Invalid success status response");
+ goto failed;
+ }
+
+ return s->code;
+ }
+
+ /* Receive auxiliary data in msg */
+ if (fd) {
+ struct cmsghdr *cmsg;
+
+ *fd = -1;
+
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg;
+ cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ if (cmsg->cmsg_level == SOL_SOCKET
+ && cmsg->cmsg_type == SCM_RIGHTS) {
+ memcpy(fd, CMSG_DATA(cmsg), sizeof(int));
+ break;
+ }
+ }
+ }
+
+ if (rsp_len)
+ *rsp_len = cmd.len;
+ return AUDIO_STATUS_SUCCESS;
+
+failed:
+ /* Some serious issue happen on IPC - recover */
+ shutdown(audio_sk, SHUT_RDWR);
return AUDIO_STATUS_FAILED;
}
+static int open_endpoint_cmd(void)
+{
+ struct audio_rsp_open rsp;
+ uint8_t buf[sizeof(struct audio_cmd_open) +
+ sizeof(struct audio_preset)];
+ size_t rsp_len = sizeof(rsp);
+ int result;
+
+ DBG("");
+
+ memset(&buf, 0, sizeof(buf));
+
+ /* TODO: Fill in buf here with smth */
+
+ result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_OPEN, sizeof(buf), buf,
+ &rsp_len, &rsp, NULL);
+
+ /*TODO: Read response and store endoint id */
+
+ return result;
+}
+
static bool create_audio_ipc(void)
{
struct sockaddr_un addr;
--
1.8.4
^ permalink raw reply related
* Re: [PATCH 1/4] android/audio: Prefix error log with "a2dp"
From: Luiz Augusto von Dentz @ 2014-01-09 12:06 UTC (permalink / raw)
To: Lukasz Rymanowski
Cc: linux-bluetooth@vger.kernel.org, Szymon Janc, Johan Hedberg
In-Reply-To: <1389267956-2297-2-git-send-email-lukasz.rymanowski@tieto.com>
Hi Lukasz,
On Thu, Jan 9, 2014 at 1:45 PM, Lukasz Rymanowski
<lukasz.rymanowski@tieto.com> wrote:
> ---
> android/hal-audio.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/android/hal-audio.c b/android/hal-audio.c
> index 59a8269..7a7c111 100644
> --- a/android/hal-audio.c
> +++ b/android/hal-audio.c
> @@ -423,7 +423,8 @@ static bool create_audio_ipc(void)
> sk = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
> if (sk < 0) {
> err = errno;
> - error("Failed to create socket: %d (%s)", err, strerror(err));
> + error("a2dp: Failed to create socket: %d (%s)", err,
> + strerror(err));
> return false;
> }
>
> @@ -435,13 +436,14 @@ static bool create_audio_ipc(void)
>
> if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
> err = errno;
> - error("Failed to bind socket: %d (%s)", err, strerror(err));
> + error("a2dp: Failed to bind socket: %d (%s)", err,
> + strerror(err));
> goto failed;
> }
>
> if (listen(sk, 1) < 0) {
> err = errno;
> - error("Failed to listen on the socket: %d (%s)", err,
> + error("a2dp: Failed to listen on the socket: %d (%s)", err,
> strerror(err));
> goto failed;
> }
> @@ -449,7 +451,7 @@ static bool create_audio_ipc(void)
> audio_sk = accept(sk, NULL, NULL);
> if (audio_sk < 0) {
> err = errno;
> - error("Failed to accept socket: %d (%s)", err, strerror(err));
> + error("a2dp: Failed to accept socket: %d (%s)", err, strerror(err));
> goto failed;
> }
>
> @@ -470,7 +472,7 @@ static void *ipc_handler(void *data)
>
> while (!done) {
> if(!create_audio_ipc()) {
> - error("Failed to create listening socket");
> + error("a2dp: Failed to create listening socket");
> sleep(1);
> continue;
> }
> @@ -511,7 +513,7 @@ static int audio_open(const hw_module_t *module, const char *name,
> DBG("");
>
> if (strcmp(name, AUDIO_HARDWARE_INTERFACE)) {
> - error("interface %s not matching [%s]", name,
> + error("ad2p: interface %s not matching [%s]", name,
> AUDIO_HARDWARE_INTERFACE);
> return -EINVAL;
> }
> @@ -547,7 +549,7 @@ static int audio_open(const hw_module_t *module, const char *name,
> err = pthread_create(&ipc_th, NULL, ipc_handler, NULL);
> if (err < 0) {
> ipc_th = 0;
> - error("Failed to start Audio IPC thread: %d (%s)",
> + error("a2dp: Failed to start Audio IPC thread: %d (%s)",
> -err, strerror(-err));
> return (-err);
> }
> --
> 1.8.4
I prefer you use the term Audio as prefix e.g. Audo: Failed to start
IPC thread as this may be used for more than just A2DP.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [PATCH 2/4] android/audio: Change mainloop handle in ipc_handler
From: Luiz Augusto von Dentz @ 2014-01-09 12:14 UTC (permalink / raw)
To: Lukasz Rymanowski
Cc: linux-bluetooth@vger.kernel.org, Szymon Janc, Johan Hedberg
In-Reply-To: <1389267956-2297-3-git-send-email-lukasz.rymanowski@tieto.com>
Hi Lukasz,
On Thu, Jan 9, 2014 at 1:45 PM, Lukasz Rymanowski
<lukasz.rymanowski@tieto.com> wrote:
> Make sure we wait 1 sec after each loop iteration.
> It is important in case of failure that we do not overload cpu.
>
> ---
> android/hal-audio.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/android/hal-audio.c b/android/hal-audio.c
> index 7a7c111..4a12bcb 100644
> --- a/android/hal-audio.c
> +++ b/android/hal-audio.c
> @@ -465,15 +465,14 @@ failed:
>
> static void *ipc_handler(void *data)
> {
> - bool done = false;
> struct pollfd pfd;
> + bool done;
>
> DBG("");
>
> - while (!done) {
> + for (done = false; !done; sleep(1)) {
This is getting bad really quickly, I did not realize there was a
sleep in it but usually the use of it means we are doing something
wrong which I suspect it has to do with either bind or listen failing
since you are executing them in a loop, in that case I would suggest
to start the listen socket on audio_open and only do the accept in the
thread.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [PATCH] shared: Fix clearing of IO handlers
From: Johan Hedberg @ 2014-01-09 12:15 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1389263508-7073-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Thu, Jan 09, 2014, Szymon Janc wrote:
> If NULL callback is passed to io_set_read/write_handler don't add watch
> for it and just clear struct io memebers. This was resulting in
> write/read_callback being call in loop due to fd being never written
> or read.
> ---
> src/shared/io-glib.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* [PATCH] shared: Add ref counting to struct io
From: Szymon Janc @ 2014-01-09 12:44 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This fix use after free in watch_destroy callbacks after mgmt_unref.
Fix number of following valgrind reports:
Invalid read of size 8
at 0x4088A1: read_watch_destroy (io-glib.c:116)
by 0x4E794A7: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7C4C1: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x40B53C: tester_run (tester.c:784)
by 0x4034F4: main (android-tester.c:2127)
Address 0x595f828 is 24 bytes inside a block of size 72 free'd
at 0x4C2B60C: free (in /usr/lib/valgrind/
vgpreload_memcheck-amd64-linux.so)
by 0x40A079: mgmt_unref (mgmt.c:504)
by 0x40D754: index_removed_callback (android-tester.c:329)
by 0x408E67: queue_foreach (queue.c:180)
by 0x40994E: can_read_data (mgmt.c:282)
by 0x40893C: read_callback (io-glib.c:135)
by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x40B53C: tester_run (tester.c:784)
by 0x4034F4: main (android-tester.c:2127)
Invalid write of size 4
at 0x4088B3: read_watch_destroy (io-glib.c:119)
by 0x4E794A7: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7C4C1: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x40B53C: tester_run (tester.c:784)
by 0x4034F4: main (android-tester.c:2127)
Address 0x595f818 is 8 bytes inside a block of size 72 free'd
at 0x4C2B60C: free (in /usr/lib/valgrind/
vgpreload_memcheck-amd64-linux.so)
by 0x40A079: mgmt_unref (mgmt.c:504)
by 0x40D754: index_removed_callback (android-tester.c:329)
by 0x408E67: queue_foreach (queue.c:180)
by 0x40994E: can_read_data (mgmt.c:282)
by 0x40893C: read_callback (io-glib.c:135)
by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x40B53C: tester_run (tester.c:784)
by 0x4034F4: main (android-tester.c:2127)
---
src/shared/io-glib.c | 45 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 6 deletions(-)
diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c
index ea84a69..488b1a2 100644
--- a/src/shared/io-glib.c
+++ b/src/shared/io-glib.c
@@ -30,6 +30,7 @@
#include "src/shared/io.h"
struct io {
+ int ref_count;
GIOChannel *channel;
guint read_watch;
io_callback_func_t read_callback;
@@ -41,6 +42,27 @@ struct io {
void *write_data;
};
+static struct io *io_ref(struct io *io)
+{
+ if (!io)
+ return NULL;
+
+ __sync_fetch_and_add(&io->ref_count, 1);
+
+ return io;
+}
+
+static void io_unref(struct io *io)
+{
+ if (!io)
+ return;
+
+ if (__sync_sub_and_fetch(&io->ref_count, 1))
+ return;
+
+ g_free(io);
+}
+
struct io *io_new(int fd)
{
struct io *io;
@@ -69,7 +91,7 @@ struct io *io_new(int fd)
io->write_destroy = NULL;
io->write_data = NULL;
- return io;
+ return io_ref(io);
}
void io_destroy(struct io *io)
@@ -77,15 +99,20 @@ void io_destroy(struct io *io)
if (!io)
return;
- if (io->read_watch > 0)
+ if (io->read_watch > 0) {
g_source_remove(io->read_watch);
+ io->read_watch = 0;
+ }
- if (io->write_watch > 0)
+ if (io->write_watch > 0) {
g_source_remove(io->write_watch);
+ io->write_watch = 0;
+ }
g_io_channel_unref(io->channel);
+ io->channel = NULL;
- g_free(io);
+ io_unref(io);
}
int io_get_fd(struct io *io)
@@ -120,6 +147,8 @@ static void read_watch_destroy(gpointer user_data)
io->read_callback = NULL;
io->read_destroy = NULL;
io->read_data = NULL;
+
+ io_unref(io);
}
static gboolean read_callback(GIOChannel *channel, GIOCondition cond,
@@ -155,7 +184,8 @@ bool io_set_read_handler(struct io *io, io_callback_func_t callback,
io->read_watch = g_io_add_watch_full(io->channel, G_PRIORITY_DEFAULT,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- read_callback, io, read_watch_destroy);
+ read_callback, io_ref(io),
+ read_watch_destroy);
if (io->read_watch == 0)
return false;
@@ -178,6 +208,8 @@ static void write_watch_destroy(gpointer user_data)
io->write_callback = NULL;
io->write_destroy = NULL;
io->write_data = NULL;
+
+ io_unref(io);
}
static gboolean write_callback(GIOChannel *channel, GIOCondition cond,
@@ -213,7 +245,8 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback,
io->write_watch = g_io_add_watch_full(io->channel, G_PRIORITY_DEFAULT,
G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- write_callback, io, write_watch_destroy);
+ write_callback, io_ref(io),
+ write_watch_destroy);
if (io->write_watch == 0)
return false;
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH] shared: Add ref counting to struct io
From: Johan Hedberg @ 2014-01-09 13:22 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1389271491-20388-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Thu, Jan 09, 2014, Szymon Janc wrote:
> This fix use after free in watch_destroy callbacks after mgmt_unref.
> Fix number of following valgrind reports:
>
> Invalid read of size 8
> at 0x4088A1: read_watch_destroy (io-glib.c:116)
> by 0x4E794A7: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7C4C1: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x40B53C: tester_run (tester.c:784)
> by 0x4034F4: main (android-tester.c:2127)
> Address 0x595f828 is 24 bytes inside a block of size 72 free'd
> at 0x4C2B60C: free (in /usr/lib/valgrind/
> vgpreload_memcheck-amd64-linux.so)
> by 0x40A079: mgmt_unref (mgmt.c:504)
> by 0x40D754: index_removed_callback (android-tester.c:329)
> by 0x408E67: queue_foreach (queue.c:180)
> by 0x40994E: can_read_data (mgmt.c:282)
> by 0x40893C: read_callback (io-glib.c:135)
> by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x40B53C: tester_run (tester.c:784)
> by 0x4034F4: main (android-tester.c:2127)
>
> Invalid write of size 4
> at 0x4088B3: read_watch_destroy (io-glib.c:119)
> by 0x4E794A7: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7C4C1: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x40B53C: tester_run (tester.c:784)
> by 0x4034F4: main (android-tester.c:2127)
> Address 0x595f818 is 8 bytes inside a block of size 72 free'd
> at 0x4C2B60C: free (in /usr/lib/valgrind/
> vgpreload_memcheck-amd64-linux.so)
> by 0x40A079: mgmt_unref (mgmt.c:504)
> by 0x40D754: index_removed_callback (android-tester.c:329)
> by 0x408E67: queue_foreach (queue.c:180)
> by 0x40994E: can_read_data (mgmt.c:282)
> by 0x40893C: read_callback (io-glib.c:135)
> by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x40B53C: tester_run (tester.c:784)
> by 0x4034F4: main (android-tester.c:2127)
> ---
> src/shared/io-glib.c | 45 +++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 39 insertions(+), 6 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* [PATCH] shared: Fix use after free in queue_foreach
From: Szymon Janc @ 2014-01-09 13:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Function passed to queue_foreach may free queue entry. Make loop safe
with that. Fix number of following valgrin reports.
Invalid read of size 8
at 0x408EEC: queue_foreach (queue.c:181)
by 0x409A0E: can_read_data (mgmt.c:286)
by 0x40896C: read_callback (io-glib.c:164)
by 0x4E7C3B5: g_main_context_dispatch (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x40B5FC: tester_run (tester.c:784)
by 0x4034F4: main (android-tester.c:2127)
Address 0x59603a8 is 8 bytes inside a block of size 16 free'd
at 0x4C2B60C: free (in /usr/lib/valgrind/
vgpreload_memcheck-amd64-linux.so)
by 0x40910D: queue_remove_all (queue.c:289)
by 0x40A0BD: mgmt_unregister_all (mgmt.c:792)
by 0x40A0F4: mgmt_unref (mgmt.c:499)
by 0x40D814: index_removed_callback (android-tester.c:329)
by 0x408EEB: queue_foreach (queue.c:184)
by 0x409A0E: can_read_data (mgmt.c:286)
by 0x40896C: read_callback (io-glib.c:164)
by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x40B5FC: tester_run (tester.c:784)
---
src/shared/queue.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/shared/queue.c b/src/shared/queue.c
index 0019e53..a7cc8d5 100644
--- a/src/shared/queue.c
+++ b/src/shared/queue.c
@@ -176,8 +176,15 @@ void queue_foreach(struct queue *queue, queue_foreach_func_t function,
if (!queue || !function)
return;
- for (entry = queue->head; entry; entry = entry->next)
- function(entry->data, user_data);
+ entry = queue->head;
+
+ while (entry) {
+ struct queue_entry *tmp = entry;
+
+ entry = tmp->next;
+
+ function(tmp->data, user_data);
+ }
}
void *queue_find(struct queue *queue, queue_match_func_t function,
--
1.8.3.2
^ permalink raw reply related
* [PATCH] shared: Fix memory leaks in mgmt_unref
From: Szymon Janc @ 2014-01-09 14:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Destroy notify and pending lists on freeing mgmt. Those two lists
cannot be destroyed in same place as reply and request queues due
to being used in can_read_data().
Fix following valgrind reports:
24 bytes in 1 blocks are definitely lost in loss record 70 of 212
at 0x4C2C494: calloc (in /usr/lib/valgrind/
vgpreload_memcheck-amd64-linux.so)
by 0x46B5E2: queue_new (queue.c:46)
by 0x46C3CA: mgmt_new (mgmt.c:407)
by 0x46C4B5: mgmt_new_default (mgmt.c:466)
by 0x45FB45: adapter_init (adapter.c:6237)
by 0x40A4F1: main (main.c:534)
24 bytes in 1 blocks are definitely lost in loss record 71 of 212
at 0x4C2C494: calloc (in /usr/lib/
valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x46B5E2: queue_new (queue.c:46)
by 0x46C3D8: mgmt_new (mgmt.c:417)
by 0x46C4B5: mgmt_new_default (mgmt.c:466)
by 0x45FB45: adapter_init (adapter.c:6237)
by 0x40A4F1: main (main.c:534)
---
src/shared/mgmt.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 2a2c2a3..b663d3a 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -291,8 +291,11 @@ static void read_watch_destroy(void *user_data)
{
struct mgmt *mgmt = user_data;
- if (mgmt->destroyed)
+ if (mgmt->destroyed) {
+ queue_destroy(mgmt->notify_list, NULL);
+ queue_destroy(mgmt->pending_list, NULL);
free(mgmt);
+ }
}
static bool can_read_data(struct io *io, void *user_data)
@@ -514,6 +517,8 @@ void mgmt_unref(struct mgmt *mgmt)
mgmt->buf = NULL;
if (!mgmt->in_notify) {
+ queue_destroy(mgmt->notify_list, NULL);
+ queue_destroy(mgmt->pending_list, NULL);
free(mgmt);
return;
}
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH] shared: Fix use after free in queue_foreach
From: Johan Hedberg @ 2014-01-09 14:32 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1389274357-25902-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Thu, Jan 09, 2014, Szymon Janc wrote:
> Function passed to queue_foreach may free queue entry. Make loop safe
> with that. Fix number of following valgrin reports.
>
> Invalid read of size 8
> at 0x408EEC: queue_foreach (queue.c:181)
> by 0x409A0E: can_read_data (mgmt.c:286)
> by 0x40896C: read_callback (io-glib.c:164)
> by 0x4E7C3B5: g_main_context_dispatch (in
> /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x40B5FC: tester_run (tester.c:784)
> by 0x4034F4: main (android-tester.c:2127)
> Address 0x59603a8 is 8 bytes inside a block of size 16 free'd
> at 0x4C2B60C: free (in /usr/lib/valgrind/
> vgpreload_memcheck-amd64-linux.so)
> by 0x40910D: queue_remove_all (queue.c:289)
> by 0x40A0BD: mgmt_unregister_all (mgmt.c:792)
> by 0x40A0F4: mgmt_unref (mgmt.c:499)
> by 0x40D814: index_removed_callback (android-tester.c:329)
> by 0x408EEB: queue_foreach (queue.c:184)
> by 0x409A0E: can_read_data (mgmt.c:286)
> by 0x40896C: read_callback (io-glib.c:164)
> by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
> by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
> libglib-2.0.so.0.3800.1)
> by 0x40B5FC: tester_run (tester.c:784)
> ---
> src/shared/queue.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] shared: Fix memory leaks in mgmt_unref
From: Johan Hedberg @ 2014-01-09 14:32 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1389277030-2131-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Thu, Jan 09, 2014, Szymon Janc wrote:
> Destroy notify and pending lists on freeing mgmt. Those two lists
> cannot be destroyed in same place as reply and request queues due
> to being used in can_read_data().
>
> Fix following valgrind reports:
>
> 24 bytes in 1 blocks are definitely lost in loss record 70 of 212
> at 0x4C2C494: calloc (in /usr/lib/valgrind/
> vgpreload_memcheck-amd64-linux.so)
> by 0x46B5E2: queue_new (queue.c:46)
> by 0x46C3CA: mgmt_new (mgmt.c:407)
> by 0x46C4B5: mgmt_new_default (mgmt.c:466)
> by 0x45FB45: adapter_init (adapter.c:6237)
> by 0x40A4F1: main (main.c:534)
>
> 24 bytes in 1 blocks are definitely lost in loss record 71 of 212
> at 0x4C2C494: calloc (in /usr/lib/
> valgrind/vgpreload_memcheck-amd64-linux.so)
> by 0x46B5E2: queue_new (queue.c:46)
> by 0x46C3D8: mgmt_new (mgmt.c:417)
> by 0x46C4B5: mgmt_new_default (mgmt.c:466)
> by 0x45FB45: adapter_init (adapter.c:6237)
> by 0x40A4F1: main (main.c:534)
> ---
> src/shared/mgmt.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
Applied. Thanks.
Johan
^ permalink raw reply
* [PATCH] shared: Fix not calling destroy callback while clearing up handlers
From: Szymon Janc @ 2014-01-09 15:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
read/write_watch_destroy is be called after io_set_read/write_handler
exits. This was resulting in io destroy callback being NULLem before
destroy was called resulting in io destroy not being called at all.
Fix this by assigning destroy callback only if setting non-NULL
callback. destroy_watch will clean it when called.
Fix following valgrind report:
168 (120 direct, 48 indirect) bytes in 1 blocks are definitely lost in
loss record 34 of 36
at 0x4C2C494: calloc (in /usr/lib/valgrind/
vgpreload_memcheck-amd64-linux.so)
by 0x409BAE: mgmt_new (mgmt.c:372)
by 0x409D05: mgmt_new_default (mgmt.c:469)
by 0x40E100: test_pre_setup (android-tester.c:371)
by 0x40AD84: start_tester (tester.c:586)
by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
by 0x40B76C: tester_run (tester.c:784)
by 0x4034F4: main (android-tester.c:2127)
---
src/shared/io-glib.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c
index 488b1a2..b7b3ff2 100644
--- a/src/shared/io-glib.c
+++ b/src/shared/io-glib.c
@@ -191,8 +191,10 @@ bool io_set_read_handler(struct io *io, io_callback_func_t callback,
done:
io->read_callback = callback;
- io->read_destroy = destroy;
- io->read_data = user_data;
+ if (callback) {
+ io->read_destroy = destroy;
+ io->read_data = user_data;
+ }
return true;
}
@@ -252,8 +254,10 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback,
done:
io->write_callback = callback;
- io->write_destroy = destroy;
- io->write_data = user_data;
+ if (callback) {
+ io->write_destroy = destroy;
+ io->write_data = user_data;
+ }
return true;
}
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH 0/7] sixaxis: Don't mark USB plugged device as trusted
From: Johan Hedberg @ 2014-01-09 15:57 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth, Bastien Nocera
In-Reply-To: <1389139348-3552-1-git-send-email-szymon.janc@gmail.com>
Hi Szymon,
On Wed, Jan 08, 2014, Szymon Janc wrote:
> This serie removes marking USB plugged sixaxis DS3 devices as trusted.
> Now agent is asked for service authorization before device is connected
> over BT. This is to address conserns about possibly crafted USB devices.
>
> This is implemented in PATCH 1. Rest are fixes for bugs that were uncovered
> due this change and client functionality that I've found missing while
> testing this.
>
> Comments and testing are welcome.
>
> --
> BR
> Szymon Janc
>
>
> Szymon Janc (7):
> sixaxis: Don't mark USB plugged device as trusted
> input: Fix crash on authorization reply with first sixaxis connection
> input: Fix check if device is sixaxis in auth_callback
> input: Fix connecting new trusted sixaxis device
> client: Add untrust command
> client: Add block command
> client: Add unblock command
>
> client/main.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++
> plugins/sixaxis.c | 1 -
> profiles/input/server.c | 37 ++++----------------
> 3 files changed, 99 insertions(+), 32 deletions(-)
All patches have been applied. Thanks.
Johan
^ permalink raw reply
* [PATCH 1/3] hcidump: Fix missing break
From: Andrei Emeltchenko @ 2014-01-09 16:11 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
tools/parser/avrcp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/parser/avrcp.c b/tools/parser/avrcp.c
index b523533..7c320ea 100644
--- a/tools/parser/avrcp.c
+++ b/tools/parser/avrcp.c
@@ -1180,12 +1180,16 @@ response:
switch (status) {
case 0x00:
printf("(POWER_ON)\n");
+ break;
case 0x01:
printf("(POWER_OFF)\n");
+ break;
case 0x02:
printf("(UNPLUGGED)\n");
+ break;
default:
printf("(UNKOWN)\n");
+ break;
}
break;
case AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED:
--
1.8.3.2
^ permalink raw reply related
* [PATCH 2/3] l2test: Fix using incorrect size of option
From: Andrei Emeltchenko @ 2014-01-09 16:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1389283864-15135-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Use size of option instead of size of pointer
---
tools/l2test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/l2test.c b/tools/l2test.c
index 9a7c809..aaa1608 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -287,7 +287,7 @@ static int setopts(int sk, struct l2cap_options *opts)
{
if (bdaddr_type == BDADDR_BREDR || cid)
return setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, opts,
- sizeof(opts));
+ sizeof(*opts));
return setsockopt(sk, SOL_BLUETOOTH, BT_RCVMTU, &opts->imtu,
sizeof(opts->imtu));
--
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