linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] emulator: Fix LE Connection Complete Event data
@ 2015-08-27 15:54 Mariusz Skamra
  2015-08-27 15:54 ` [PATCH 2/5] emulator: Update LE supported commands Mariusz Skamra
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Mariusz Skamra @ 2015-08-27 15:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mariusz Skamra

This sets LE Connection Complete Event paramaters based on parameters
from LE Create Connection command.
Event parameters like Conn_Interval and Supervision_Timeout
shouldn't be set to 0.
---
 emulator/btdev.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index e4c85f8..319d434 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1085,20 +1085,22 @@ static void sco_conn_complete(struct btdev *btdev, uint8_t status)
 	send_event(btdev, BT_HCI_EVT_CONN_COMPLETE, &cc, sizeof(cc));
 }
 
-static void le_conn_complete(struct btdev *btdev,
-					const uint8_t *bdaddr, uint8_t bdaddr_type,
-					uint8_t status)
+static void le_conn_complete(struct btdev *btdev, const void *cmd,
+								uint8_t status)
 {
 	char buf[1 + sizeof(struct bt_hci_evt_le_conn_complete)];
 	struct bt_hci_evt_le_conn_complete *cc = (void *) &buf[1];
+	const struct bt_hci_cmd_le_create_conn *lecc = cmd;
 
 	memset(buf, 0, sizeof(buf));
 
 	buf[0] = BT_HCI_EVT_LE_CONN_COMPLETE;
 
 	if (!status) {
-		struct btdev *remote = find_btdev_by_bdaddr_type(bdaddr,
-								bdaddr_type);
+		struct btdev *remote;
+
+		remote = find_btdev_by_bdaddr_type(lecc->peer_addr,
+							lecc->peer_addr_type);
 
 		btdev->conn = remote;
 		btdev->le_adv_enable = 0;
@@ -1114,6 +1116,9 @@ static void le_conn_complete(struct btdev *btdev,
 
 		cc->role = 0x01;
 		cc->handle = cpu_to_le16(42);
+		cc->interval = lecc->max_interval;
+		cc->latency = lecc->latency;
+		cc->supv_timeout = lecc->supv_timeout;
 
 		send_event(remote, BT_HCI_EVT_LE_META_EVENT, buf, sizeof(buf));
 
@@ -1121,8 +1126,8 @@ static void le_conn_complete(struct btdev *btdev,
 	}
 
 	cc->status = status;
-	cc->peer_addr_type = bdaddr_type;
-	memcpy(cc->peer_addr, bdaddr, 6);
+	cc->peer_addr_type = lecc->peer_addr_type;
+	memcpy(cc->peer_addr, lecc->peer_addr, 6);
 	cc->role = 0x00;
 
 	send_event(btdev, BT_HCI_EVT_LE_META_EVENT, buf, sizeof(buf));
@@ -1164,16 +1169,17 @@ static bool adv_connectable(struct btdev *btdev)
 	return btdev->le_adv_type != 0x03;
 }
 
-static void le_conn_request(struct btdev *btdev, const uint8_t *bdaddr,
-							uint8_t bdaddr_type)
+static void le_conn_request(struct btdev *btdev, const void *cmd)
 {
-	struct btdev *remote = find_btdev_by_bdaddr_type(bdaddr, bdaddr_type);
+	const struct bt_hci_cmd_le_create_conn *lecc = cmd;
+	struct btdev *remote = find_btdev_by_bdaddr_type(lecc->peer_addr,
+							lecc->peer_addr_type);
 
 	if (remote && adv_connectable(remote) && adv_match(btdev, remote) &&
-					remote->le_adv_own_addr == bdaddr_type)
-		le_conn_complete(btdev, bdaddr, bdaddr_type, 0);
+				remote->le_adv_own_addr == lecc->peer_addr_type)
+		le_conn_complete(btdev, lecc, 0);
 	else
-		le_conn_complete(btdev, bdaddr, bdaddr_type,
+		le_conn_complete(btdev, lecc,
 					BT_HCI_ERR_CONN_FAILED_TO_ESTABLISH);
 }
 
@@ -3314,7 +3320,7 @@ static void default_cmd_completion(struct btdev *btdev, uint16_t opcode,
 			return;
 		lecc = data;
 		btdev->le_scan_own_addr_type = lecc->own_addr_type;
-		le_conn_request(btdev, lecc->peer_addr, lecc->peer_addr_type);
+		le_conn_request(btdev, lecc);
 		break;
 
 	case BT_HCI_CMD_LE_CONN_UPDATE:
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 20+ messages in thread
* [PATCH] emulator: Improve le set scan enable command handler
@ 2015-08-31 10:09 Mariusz Skamra
  2015-08-31 10:13 ` Mariusz Skamra
  0 siblings, 1 reply; 20+ messages in thread
From: Mariusz Skamra @ 2015-08-31 10:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, Mariusz Skamra

le_set_scan_enable_complete should be called as post hook action.
Moreover, depending on Filter Duplicates parameter, scan results
can be duplicated while scanning is enabled.
---
 emulator/btdev.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index e4c85f8..bab695b 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -134,6 +134,7 @@ struct btdev {
 	uint8_t  le_scan_data[31];
 	uint8_t  le_scan_data_len;
 	uint8_t  le_scan_enable;
+	unsigned int le_adv_results_timeout;
 	uint8_t  le_scan_type;
 	uint8_t  le_scan_own_addr_type;
 	uint8_t  le_filter_dup;
@@ -1801,8 +1802,9 @@ static void le_set_adv_enable_complete(struct btdev *btdev)
 	}
 }
 
-static void le_set_scan_enable_complete(struct btdev *btdev)
+static bool le_set_scan_enable_complete(void *user_data)
 {
+	struct btdev *btdev = user_data;
 	int i;
 
 	for (i = 0; i < MAX_BTDEV_ENTRIES; i++) {
@@ -1828,6 +1830,11 @@ static void le_set_scan_enable_complete(struct btdev *btdev)
 					btdev_list[i]->le_adv_type == 0x02)
 			le_send_adv_report(btdev, btdev_list[i], 0x04);
 	}
+
+	if (!btdev->le_filter_dup)
+		return true;
+
+	return false;
 }
 
 static void le_read_remote_features_complete(struct btdev *btdev)
@@ -2939,8 +2946,6 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 			status = BT_HCI_ERR_SUCCESS;
 		}
 		cmd_complete(btdev, opcode, &status, sizeof(status));
-		if (status == BT_HCI_ERR_SUCCESS && btdev->le_scan_enable)
-			le_set_scan_enable_complete(btdev);
 		break;
 
 	case BT_HCI_CMD_LE_CREATE_CONN:
@@ -3170,6 +3175,7 @@ static void default_cmd_completion(struct btdev *btdev, uint16_t opcode,
 	const struct bt_hci_cmd_read_clock_offset *rco;
 	const struct bt_hci_cmd_le_create_conn *lecc;
 	const struct bt_hci_cmd_le_conn_update *lecu;
+	const struct bt_hci_cmd_le_set_scan_enable *lsse;
 
 	switch (opcode) {
 	case BT_HCI_CMD_INQUIRY:
@@ -3329,6 +3335,20 @@ static void default_cmd_completion(struct btdev *btdev, uint16_t opcode,
 				le16_to_cpu(lecu->min_length),
 				le16_to_cpu(lecu->max_length));
 		break;
+		break;
+	case BT_HCI_CMD_LE_SET_SCAN_ENABLE:
+		if (btdev->type == BTDEV_TYPE_BREDR)
+			return;
+		lsse = data;
+		if (btdev->le_scan_enable && lsse->enable)
+			btdev->le_adv_results_timeout = timeout_add(1000,
+				le_set_scan_enable_complete, btdev, NULL);
+
+		if (!btdev->le_scan_enable && !lsse->enable &&
+						btdev->le_adv_results_timeout) {
+			timeout_remove(btdev->le_adv_results_timeout);
+		}
+
 	}
 }
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-08-31 10:18 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-27 15:54 [PATCH 1/5] emulator: Fix LE Connection Complete Event data Mariusz Skamra
2015-08-27 15:54 ` [PATCH 2/5] emulator: Update LE supported commands Mariusz Skamra
2015-08-29  3:25   ` Johan Hedberg
2015-08-27 15:54 ` [PATCH 3/5] emulator: Remove duplicated assignment Mariusz Skamra
2015-08-27 15:54 ` [PATCH 4/5] emulator: Add support for LE Remote Connection Parameter Request Reply Mariusz Skamra
2015-08-27 15:54 ` [PATCH 5/5] emulator: Enable Slave-initiated Features Exchange feature Mariusz Skamra
2015-08-29  3:20 ` [PATCH 1/5] emulator: Fix LE Connection Complete Event data Johan Hedberg
2015-08-31 10:09   ` [PATCHv2 1/5] emulator: Remove duplicated assignment Mariusz Skamra
2015-08-31 10:09   ` [PATCHv2 2/5] emulator: Add support for LE Remote Connection Parameter Request Reply Mariusz Skamra
2015-08-31 10:09   ` [PATCHv2 3/5] emulator: Add support for LE Remote Connection Parameter Request Negative Reply Mariusz Skamra
2015-08-31 10:09   ` [PATCHv2 4/5] emulator: Enable Slave-initiated Features Exchange feature Mariusz Skamra
2015-08-31 10:09   ` [PATCHv2 5/5] emulator: Refactor le set scan enable command handler Mariusz Skamra
2015-08-31 10:18   ` [PATCHv2 1/6] emulator: Fix LE Connection Complete Event data Mariusz Skamra
2015-08-31 10:18   ` [PATCHv2 2/6] emulator: Remove duplicated assignment Mariusz Skamra
2015-08-31 10:18   ` [PATCHv2 3/6] emulator: Add support for LE Remote Connection Parameter Request Reply Mariusz Skamra
2015-08-31 10:18   ` [PATCHv2 4/6] emulator: Add support for LE Remote Connection Parameter Request Negative Reply Mariusz Skamra
2015-08-31 10:18   ` [PATCHv2 5/6] emulator: Enable Slave-initiated Features Exchange feature Mariusz Skamra
2015-08-31 10:18   ` [PATCHv2 6/6] emulator: Refactor le set scan enable command handler Mariusz Skamra
  -- strict thread matches above, loose matches on Subject: below --
2015-08-31 10:09 [PATCH] emulator: Improve " Mariusz Skamra
2015-08-31 10:13 ` Mariusz Skamra

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).