linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 1/6] emulator: Fix LE Connection Complete Event data
@ 2015-09-23 11:36 Mariusz Skamra
  2015-09-23 11:36 ` [PATCHv2 2/6] emulator: Remove duplicated assignment Mariusz Skamra
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Mariusz Skamra @ 2015-09-23 11:36 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 | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index ceefd56..f3ef1ca 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1095,8 +1095,8 @@ static void sco_conn_complete(struct btdev *btdev, uint8_t status)
 }
 
 static void le_conn_complete(struct btdev *btdev,
-					const uint8_t *bdaddr, uint8_t bdaddr_type,
-					uint8_t status)
+				const struct bt_hci_cmd_le_create_conn *lecc,
+				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];
@@ -1106,8 +1106,10 @@ static void le_conn_complete(struct btdev *btdev,
 	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;
@@ -1123,6 +1125,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));
 
@@ -1130,8 +1135,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));
@@ -1173,16 +1178,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 struct bt_hci_cmd_le_create_conn *lecc)
 {
-	struct btdev *remote = find_btdev_by_bdaddr_type(bdaddr, bdaddr_type);
+	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);
 }
 
@@ -3323,7 +3329,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] 8+ messages in thread
* Re: [PATCH 1/5] emulator: Fix LE Connection Complete Event data
@ 2015-08-29  3:20 Johan Hedberg
  2015-08-31 10:18 ` [PATCHv2 1/6] " Mariusz Skamra
  0 siblings, 1 reply; 8+ messages in thread
From: Johan Hedberg @ 2015-08-29  3:20 UTC (permalink / raw)
  To: Mariusz Skamra; +Cc: linux-bluetooth

Hi Mariusz,

On Thu, Aug 27, 2015, Mariusz Skamra wrote:
> +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;

Why the void pointer in the function parameters and then casting it to
the actual one? It'd be simpler and safer if you just passed this as the
right type from the start.

Johan

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

end of thread, other threads:[~2015-10-05  8:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-23 11:36 [PATCHv2 1/6] emulator: Fix LE Connection Complete Event data Mariusz Skamra
2015-09-23 11:36 ` [PATCHv2 2/6] emulator: Remove duplicated assignment Mariusz Skamra
2015-09-23 11:36 ` [PATCHv2 3/6] emulator: Add support for LE Remote Connection Parameter Request Reply Mariusz Skamra
2015-09-23 11:36 ` [PATCHv2 4/6] emulator: Add support for LE Remote Connection Parameter Request Negative Reply Mariusz Skamra
2015-09-23 11:36 ` [PATCHv2 5/6] emulator: Enable Slave-initiated Features Exchange feature Mariusz Skamra
2015-09-23 11:36 ` [PATCHv2 6/6] emulator: Refactor le set scan enable command handler Mariusz Skamra
2015-10-05  8:03 ` [PATCHv2 1/6] emulator: Fix LE Connection Complete Event data Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2015-08-29  3:20 [PATCH 1/5] " Johan Hedberg
2015-08-31 10:18 ` [PATCHv2 1/6] " 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).