* [PATCH 1/2] tools: Add mgmt test case for pair device while powered off
@ 2013-01-18 11:51 Szymon Janc
2013-01-18 11:51 ` [PATCH 2/2] Adapter: Add workaround for device pairing kernel bug Szymon Janc
2013-01-18 13:26 ` [PATCH 1/2] tools: Add mgmt test case for pair device while powered off Johan Hedberg
0 siblings, 2 replies; 3+ messages in thread
From: Szymon Janc @ 2013-01-18 11:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This tests if kernel is responding with proper command complete event.
---
tools/mgmt-tester.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index cb02480..5c72d00 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -916,6 +916,20 @@ static const struct generic_data add_uuid32_test_1 = {
.expect_hci_len = sizeof(write_eir_uuid32_hci),
};
+static const char pair_device_param[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00 };
+static const char pair_device_rsp[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00 };
+
+static const struct generic_data pair_device_not_powered_test_1 = {
+ .send_opcode = MGMT_OP_PAIR_DEVICE,
+ .send_param = pair_device_param,
+ .send_len = sizeof(pair_device_param),
+ .expect_status = MGMT_STATUS_NOT_POWERED,
+ .expect_param = pair_device_rsp,
+ .expect_len = sizeof(pair_device_rsp),
+};
+
static void setup_powered_callback(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
@@ -1414,5 +1428,8 @@ int main(int argc, char *argv[])
test_bredr("Add UUID - UUID-32 1", &add_uuid32_test_1, setup_ssp,
test_command_generic);
+ test_bredr("Pair Device - Not Powered 1",
+ &pair_device_not_powered_test_1, NULL,
+ test_command_generic);
return tester_run();
}
--
1.8.0.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] Adapter: Add workaround for device pairing kernel bug
2013-01-18 11:51 [PATCH 1/2] tools: Add mgmt test case for pair device while powered off Szymon Janc
@ 2013-01-18 11:51 ` Szymon Janc
2013-01-18 13:26 ` [PATCH 1/2] tools: Add mgmt test case for pair device while powered off Johan Hedberg
1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2013-01-18 11:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Some kernels reply to device pairing command with bogus command status
instead of command complete event if adapter was not powered.
Command status event doesn't provide remote device address and type
needed to properly complete bonding request.
Pass possibly missing data as user_data to mgmt_send and use it in
pair_device_complete function if needed.
---
src/adapter.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 1a5b1ad..c413242 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -4643,17 +4643,40 @@ static void adapter_bonding_complete(struct btd_adapter *adapter,
check_oob_bonding_complete(adapter, bdaddr, status);
}
+struct pair_device_data {
+ struct btd_adapter *adapter;
+ bdaddr_t bdaddr;
+ uint8_t addr_type;
+};
+
+static void free_pair_device_data(void *user_data)
+{
+ struct pair_device_data *data = user_data;
+
+ g_free(data);
+}
+
static void pair_device_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
const struct mgmt_rp_pair_device *rp = param;
- struct btd_adapter *adapter = user_data;
+ struct pair_device_data *data = user_data;
DBG("%s (0x%02x)", mgmt_errstr(status), status);
+ /*
+ * Workaround for a kernel bug
+ *
+ * Broken kernels may reply to device pairing command with command
+ * status instead of command complete event e.g. if adapter was not
+ * powered.
+ */
if (status != MGMT_STATUS_SUCCESS && length < sizeof(*rp)) {
error("Pair device failed: %s (0x%02x)",
mgmt_errstr(status), status);
+
+ adapter_bonding_complete(data->adapter, &data->bdaddr,
+ data->addr_type, status);
return;
}
@@ -4662,7 +4685,7 @@ static void pair_device_complete(uint8_t status, uint16_t length,
return;
}
- adapter_bonding_complete(adapter, &rp->addr.bdaddr, rp->addr.type,
+ adapter_bonding_complete(data->adapter, &rp->addr.bdaddr, rp->addr.type,
status);
}
@@ -4671,6 +4694,7 @@ int adapter_create_bonding(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
{
struct mgmt_cp_pair_device cp;
char addr[18];
+ struct pair_device_data *data;
suspend_discovery(adapter);
@@ -4683,13 +4707,21 @@ int adapter_create_bonding(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
cp.addr.type = addr_type;
cp.io_cap = io_cap;
+ data = g_new0(struct pair_device_data, 1);
+ data->adapter = adapter;
+ bacpy(&data->bdaddr, bdaddr);
+ data->addr_type = addr_type;
+
if (mgmt_send(adapter->mgmt, MGMT_OP_PAIR_DEVICE,
adapter->dev_id, sizeof(cp), &cp,
- pair_device_complete, adapter, NULL) > 0)
+ pair_device_complete, data,
+ free_pair_device_data) > 0)
return 0;
error("Failed to pair %s for hci%u", addr, adapter->dev_id);
+ free_pair_device_data(data);
+
return -EIO;
}
--
1.8.0.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] tools: Add mgmt test case for pair device while powered off
2013-01-18 11:51 [PATCH 1/2] tools: Add mgmt test case for pair device while powered off Szymon Janc
2013-01-18 11:51 ` [PATCH 2/2] Adapter: Add workaround for device pairing kernel bug Szymon Janc
@ 2013-01-18 13:26 ` Johan Hedberg
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2013-01-18 13:26 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Fri, Jan 18, 2013, Szymon Janc wrote:
> This tests if kernel is responding with proper command complete event.
> ---
> tools/mgmt-tester.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
Applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-01-18 13:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-18 11:51 [PATCH 1/2] tools: Add mgmt test case for pair device while powered off Szymon Janc
2013-01-18 11:51 ` [PATCH 2/2] Adapter: Add workaround for device pairing kernel bug Szymon Janc
2013-01-18 13:26 ` [PATCH 1/2] tools: Add mgmt test case for pair device while powered off Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).