All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC BlueZ 00/35] More discovery tests
@ 2013-06-12 12:56 Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 01/35] emulator: Add support for multiple connections Bruna Moreira
                   ` (35 more replies)
  0 siblings, 36 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

This series implements more complex discovery tests and all necessary support
in the emulator. It is rather long because it required many modifications to
the emulation layer in order to support these tests.

Patches 1-11 implement basic LE support on emulator. The main features are:
- Set LE advertising data
- Set advertising enable command
- Set LE advertising parameters
- Send LE advertising report
- LE create connection command (Basic support for multiple connections).
NOTE: support for multiple connections is not necessary for discovery tests.

Patches 12-19 implement hook mechanism.
The hook mechanism is a way to run custom code from tests before/after
processing HCI commands and building events. It is also possible to "cancel"
events if the post event hook returns false. To simplify implementation,
default_cmd() was split in two parts: the command response (command
status/complete events) was kept in default_cmd() and "extra" events were moved
to default_cmd completion().

There are four hooks types:
- pre command: before default_cmd() function.
- post command: before sending packet in command status and command complete.
- pre event: before default_cmd_completion() function.
- post event: in send_event() function, before sending the packet.
They can used in external applications like tools/mgmt-tester.

Patches 20-25 and 28-35 implement discovery tests.
For start discovery, we have:
- Start BR/EDR Discovery and wait for Device Found event from BR/EDR device.
- Start LE-only Discovery and wait for Device Found event from LE device.
For stop discovery:
- Stop BR/EDR Discovery during Inquiry (no devices found).
- Wait for Device Found event from BR/EDR device and stop BR/EDR Discovery during:
  - Inquiry.
  - Name Resolving.
- Wait for Device Found event from LE device and stop interleaved discovery
  during LE scanning.
- Wait for Device Found event from BR/EDR device and stop interleaved discovery
  during:
  - Inquiry.
  - Name Resolving.
- Wait for Device Found event from LE device and stop LE-only Discovery during
  LE scanning.

NOTE: currently, bluetoothd should not be running during tests because it will
try to change EIR data for the second virtual controller (which represents the
remote device) and thus will not match the data statically declared on the
tests.

Patch 26 adds support for saving a packet cancelled by a post event hook, so it
can be sent later.

Patch 27 contains a fix already sent to the mailing list (with some
modifications to apply upstream):
 emulator: Fix Remote Name Request Cancel command complete

Comments and suggestions are welcome.

BR,
Bruna Moreira.

Anderson Lizardo (1):
  emulator: Fix Remote Name Request Cancel command complete

Bruna Moreira (16):
  emulator: Add remove operation in HCI hook callback
  emulator: Add new function for running all hooks
  tools/mgmt-tester: Add stop discovery for BR/EDR only
  tools/mgmt-tester: Add support for second controller
  tools/mgmt-tester: BR/EDR Start discovery (Device Found)
  tools/mgmt-tester: LE only Start discovery (Device Found)
  tools/mgmt-tester: Split test_command_generic()
  tools/mgmt-tester: BR/EDR Stop discovery (Device Found)
  btdev: Add function to send an aborted packet
  tools/mgmt-tester: Move command_generic_callback()
  tools/mgmt-tester: BR/EDR Stop discovery (Name Resolving)
  tools/mgmt-tester: Add support to set emulator type
  tools/mgmt-tester: Interleaved stop discovery (LE dev. found)
  tools/mgmt-tester: Increase timeout for dual mode controller
  tools/mgmt-tester: Interleaved stop discovery (BR/EDR dev. found)
  tools/mgmt-tester: Interleaved Stop discovery (Name Resolving)

Eder Ruiz Maria (7):
  emulator: Add support for pre/post command/event hooks
  emulator: Add hook only if there aren't other with same type and
    opcode
  emulator: Export command and event hooks for hciemu user
  emulator: Add support for delete a hook
  emulator: Split default_cmd() for better command and event handler
  emulator: cmd_status() using send_packet() for run hooks easily
  tools/mgmt-tester: LE Stop discovery (Device Found)

Jefferson Delfes (11):
  emulator: Add support for multiple connections
  emulator: Store LE advertising data length in btdev
  emulator: Implement basic LE set adv enable command
  emulator: Store LE scan state of virtual controller
  emulator: Search virtual devices in LE advertising mode
  emulator: Search virtual devices in LE scan mode
  emulator: Implement LE advertising report
  emulator: Implement basic LE create connection
  emulator: Dummy LE set advertising parameters
  emulator: Disallow LE set scan params command when scan is enabled
  emulator: Set LE supported states

 emulator/btdev.c    |  619 +++++++++++++++++++++++++++++++++++++++------
 emulator/btdev.h    |   20 ++
 monitor/bt.h        |   17 ++
 src/shared/hciemu.c |   87 ++++++-
 src/shared/hciemu.h |   22 +-
 tools/mgmt-tester.c |  690 ++++++++++++++++++++++++++++++++++++++++++++++++---
 6 files changed, 1338 insertions(+), 117 deletions(-)

-- 
1.7.9.5


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

* [RFC BlueZ 01/35] emulator: Add support for multiple connections
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 02/35] emulator: Store LE advertising data length in btdev Bruna Moreira
                   ` (34 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

In order to support multiple connections in emulator, we need to change
any access from btdev->conn to connection_list helpers.
Each time a connection is established, a handle is created to identify
this connection. That way a btdev can have more than one connection at
same time.
---
 emulator/btdev.c |  143 +++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 108 insertions(+), 35 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index d88c853..4baf019 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -45,8 +45,6 @@
 struct btdev {
 	enum btdev_type type;
 
-	struct btdev *conn;
-
 	btdev_command_func command_handler;
 	void *command_data;
 
@@ -100,6 +98,16 @@ struct btdev {
 
 static struct btdev *btdev_list[MAX_BTDEV_ENTRIES] = { };
 
+struct connection {
+	uint16_t handle;
+	struct btdev *dev1;
+	struct btdev *dev2;
+};
+
+#define MAX_CONNECTION_ENTRIES 32
+
+static struct connection *connection_list[MAX_CONNECTION_ENTRIES] = { };
+
 static inline int add_btdev(struct btdev *btdev)
 {
 	int i, index = -1;
@@ -142,6 +150,67 @@ static inline struct btdev *find_btdev_by_bdaddr(const uint8_t *bdaddr)
 	return NULL;
 }
 
+static struct connection *add_connection(struct btdev *dev1, struct btdev *dev2)
+{
+	static uint16_t actual_handle = 1;
+	struct connection *conn = NULL;
+	int i;
+
+	for (i = 0; i < MAX_CONNECTION_ENTRIES; i++) {
+		if (connection_list[i] == NULL) {
+			conn = malloc(sizeof(*conn));
+			memset(conn, 0, sizeof(*conn));
+			conn->handle = actual_handle++;
+			conn->dev1 = dev1;
+			conn->dev2 = dev2;
+			connection_list[i] = conn;
+			break;
+		}
+	}
+
+	return conn;
+}
+
+static void del_connection(struct connection *conn)
+{
+	int i;
+
+	for (i = 0; i < MAX_CONNECTION_ENTRIES; i++) {
+		if (connection_list[i] == conn) {
+			free(conn);
+			connection_list[i] = NULL;
+			break;
+		}
+	}
+}
+
+static struct connection *find_connection_by_handle(uint16_t handle)
+{
+	int i;
+
+	for (i = 0; i < MAX_CONNECTION_ENTRIES; i++)
+		if (connection_list[i] && connection_list[i]->handle == handle)
+			return connection_list[i];
+
+	return NULL;
+}
+
+static struct btdev *find_remote_of_connection(struct btdev *local,
+								uint16_t handle)
+{
+	struct btdev *remote = NULL;
+	struct connection *conn = find_connection_by_handle(handle);
+
+	if (conn) {
+		if (conn->dev1 == local)
+			remote = conn->dev2;
+		else
+			remote = conn->dev1;
+	}
+
+	return remote;
+}
+
 static void hexdump(const unsigned char *buf, uint16_t len)
 {
 	static const char hexdigits[] = "0123456789abcdef";
@@ -548,18 +617,15 @@ static void cmd_status(struct btdev *btdev, uint8_t status, uint16_t opcode)
 	send_event(btdev, BT_HCI_EVT_CMD_STATUS, &cs, sizeof(cs));
 }
 
-static void num_completed_packets(struct btdev *btdev)
+static void num_completed_packets(struct btdev *btdev, uint16_t handle)
 {
-	if (btdev->conn) {
-		struct bt_hci_evt_num_completed_packets ncp;
+	struct bt_hci_evt_num_completed_packets ncp;
 
-		ncp.num_handles = 1;
-		ncp.handle = cpu_to_le16(42);
-		ncp.count = cpu_to_le16(1);
+	ncp.num_handles = 1;
+	ncp.handle = cpu_to_le16(handle);
+	ncp.count = cpu_to_le16(1);
 
-		send_event(btdev, BT_HCI_EVT_NUM_COMPLETED_PACKETS,
-							&ncp, sizeof(ncp));
-	}
+	send_event(btdev, BT_HCI_EVT_NUM_COMPLETED_PACKETS, &ncp, sizeof(ncp));
 }
 
 static void inquiry_complete(struct btdev *btdev, uint8_t status)
@@ -630,20 +696,18 @@ static void conn_complete(struct btdev *btdev,
 
 	if (!status) {
 		struct btdev *remote = find_btdev_by_bdaddr(bdaddr);
-
-		btdev->conn = remote;
-		remote->conn = btdev;
+		struct connection *conn = add_connection(btdev, remote);
 
 		cc.status = status;
 		memcpy(cc.bdaddr, btdev->bdaddr, 6);
 		cc.encr_mode = 0x00;
 
-		cc.handle = cpu_to_le16(42);
+		cc.handle = cpu_to_le16(conn->handle);
 		cc.link_type = 0x01;
 
 		send_event(remote, BT_HCI_EVT_CONN_COMPLETE, &cc, sizeof(cc));
 
-		cc.handle = cpu_to_le16(42);
+		cc.handle = cpu_to_le16(conn->handle);
 		cc.link_type = 0x01;
 	} else {
 		cc.handle = cpu_to_le16(0x0000);
@@ -681,7 +745,7 @@ static void disconnect_complete(struct btdev *btdev, uint16_t handle,
 							uint8_t reason)
 {
 	struct bt_hci_evt_disconnect_complete dc;
-	struct btdev *remote;
+	struct connection *conn;
 
 	if (!btdev) {
 		dc.status = BT_HCI_ERR_UNKNOWN_CONN_ID;
@@ -697,13 +761,14 @@ static void disconnect_complete(struct btdev *btdev, uint16_t handle,
 	dc.handle = cpu_to_le16(handle);
 	dc.reason = reason;
 
-	remote = btdev->conn;
-
-	btdev->conn = NULL;
-	remote->conn = NULL;
-
-	send_event(btdev, BT_HCI_EVT_DISCONNECT_COMPLETE, &dc, sizeof(dc));
-	send_event(remote, BT_HCI_EVT_DISCONNECT_COMPLETE, &dc, sizeof(dc));
+	conn = find_connection_by_handle(handle);
+	if (conn) {
+		send_event(conn->dev1, BT_HCI_EVT_DISCONNECT_COMPLETE, &dc,
+								sizeof(dc));
+		send_event(conn->dev2, BT_HCI_EVT_DISCONNECT_COMPLETE, &dc,
+								sizeof(dc));
+		del_connection(conn);
+	}
 }
 
 static void name_request_complete(struct btdev *btdev,
@@ -731,11 +796,12 @@ static void name_request_complete(struct btdev *btdev,
 static void remote_features_complete(struct btdev *btdev, uint16_t handle)
 {
 	struct bt_hci_evt_remote_features_complete rfc;
+	struct btdev *remote = find_remote_of_connection(btdev, handle);
 
-	if (btdev->conn) {
+	if (remote) {
 		rfc.status = BT_HCI_ERR_SUCCESS;
 		rfc.handle = cpu_to_le16(handle);
-		memcpy(rfc.features, btdev->conn->features, 8);
+		memcpy(rfc.features, remote->features, 8);
 	} else {
 		rfc.status = BT_HCI_ERR_UNKNOWN_CONN_ID;
 		rfc.handle = cpu_to_le16(handle);
@@ -750,8 +816,9 @@ static void remote_ext_features_complete(struct btdev *btdev, uint16_t handle,
 								uint8_t page)
 {
 	struct bt_hci_evt_remote_ext_features_complete refc;
+	struct btdev *remote = find_remote_of_connection(btdev, handle);
 
-	if (btdev->conn && page < 0x02) {
+	if (remote && page < 0x02) {
 		refc.handle = cpu_to_le16(handle);
 		refc.page = page;
 		refc.max_page = 0x01;
@@ -759,7 +826,7 @@ static void remote_ext_features_complete(struct btdev *btdev, uint16_t handle,
 		switch (page) {
 		case 0x00:
 			refc.status = BT_HCI_ERR_SUCCESS;
-			memcpy(refc.features, btdev->conn->features, 8);
+			memcpy(refc.features, remote->features, 8);
 			break;
 		case 0x01:
 			refc.status = BT_HCI_ERR_SUCCESS;
@@ -785,13 +852,14 @@ static void remote_ext_features_complete(struct btdev *btdev, uint16_t handle,
 static void remote_version_complete(struct btdev *btdev, uint16_t handle)
 {
 	struct bt_hci_evt_remote_version_complete rvc;
+	struct btdev *remote = find_remote_of_connection(btdev, handle);
 
-	if (btdev->conn) {
+	if (remote) {
 		rvc.status = BT_HCI_ERR_SUCCESS;
 		rvc.handle = cpu_to_le16(handle);
-		rvc.lmp_ver = btdev->conn->version;
-		rvc.manufacturer = cpu_to_le16(btdev->conn->manufacturer);
-		rvc.lmp_subver = cpu_to_le16(btdev->conn->revision);
+		rvc.lmp_ver = remote->version;
+		rvc.manufacturer = cpu_to_le16(remote->manufacturer);
+		rvc.lmp_subver = cpu_to_le16(remote->revision);
 	} else {
 		rvc.status = BT_HCI_ERR_UNKNOWN_CONN_ID;
 		rvc.handle = cpu_to_le16(handle);
@@ -1563,6 +1631,8 @@ static void process_cmd(struct btdev *btdev, const void *data, uint16_t len)
 void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len)
 {
 	uint8_t pkt_type;
+	uint16_t handle;
+	struct btdev *remote;
 
 	if (!btdev)
 		return;
@@ -1577,9 +1647,12 @@ void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len)
 		process_cmd(btdev, data + 1, len - 1);
 		break;
 	case BT_H4_ACL_PKT:
-		if (btdev->conn)
-			send_packet(btdev->conn, data, len);
-		num_completed_packets(btdev);
+		handle = le16_to_cpu(((const uint16_t *) (data + 1))[0]);
+		remote = find_remote_of_connection(btdev, handle);
+		if (remote) {
+			send_packet(remote, data, len);
+			num_completed_packets(btdev, handle);
+		}
 		break;
 	default:
 		printf("Unsupported packet 0x%2.2x\n", pkt_type);
-- 
1.7.9.5


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

* [RFC BlueZ 02/35] emulator: Store LE advertising data length in btdev
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 01/35] emulator: Add support for multiple connections Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 03/35] emulator: Implement basic LE set adv enable command Bruna Moreira
                   ` (33 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

LE advertising data length will be used for emulating reports in other
virtual devices.
---
 emulator/btdev.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 4baf019..1555e2f 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -88,6 +88,7 @@ struct btdev {
 	uint8_t  le_simultaneous;
 	uint8_t  le_event_mask[8];
 	uint8_t  le_adv_data[31];
+	uint8_t  le_adv_data_len;
 
 	uint16_t sync_train_interval;
 	uint32_t sync_train_timeout;
@@ -1550,6 +1551,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 		if (btdev->type == BTDEV_TYPE_BREDR)
 			goto unsupported;
 		lsad = data;
+		btdev->le_adv_data_len = lsad->len;
 		memcpy(btdev->le_adv_data, lsad->data, 31);
 		status = BT_HCI_ERR_SUCCESS;
 		cmd_complete(btdev, opcode, &status, sizeof(status));
-- 
1.7.9.5


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

* [RFC BlueZ 03/35] emulator: Implement basic LE set adv enable command
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 01/35] emulator: Add support for multiple connections Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 02/35] emulator: Store LE advertising data length in btdev Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 04/35] emulator: Store LE scan state of virtual controller Bruna Moreira
                   ` (32 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

Store advertising state of virtual controller in btdev struct.
---
 emulator/btdev.c |   15 +++++++++++++++
 monitor/bt.h     |    1 +
 2 files changed, 16 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 1555e2f..316d816 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -89,6 +89,7 @@ struct btdev {
 	uint8_t  le_event_mask[8];
 	uint8_t  le_adv_data[31];
 	uint8_t  le_adv_data_len;
+	uint8_t  le_adv_enable;
 
 	uint16_t sync_train_interval;
 	uint32_t sync_train_timeout;
@@ -906,6 +907,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	const struct bt_hci_cmd_set_event_mask_page2 *semp2;
 	const struct bt_hci_cmd_le_set_event_mask *lsem;
 	const struct bt_hci_cmd_le_set_adv_data *lsad;
+	const struct bt_hci_cmd_le_set_adv_enable *lsae;
 	struct bt_hci_rsp_read_default_link_policy rdlp;
 	struct bt_hci_rsp_read_stored_link_key rslk;
 	struct bt_hci_rsp_write_stored_link_key wslk;
@@ -1517,6 +1519,19 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 		cmd_complete(btdev, opcode, &lratp, sizeof(lratp));
 		break;
 
+	case BT_HCI_CMD_LE_SET_ADV_ENABLE:
+		if (btdev->type == BTDEV_TYPE_BREDR)
+			goto unsupported;
+		lsae = data;
+		if (btdev->le_adv_enable == lsae->enable)
+			status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		else {
+			btdev->le_adv_enable = lsae->enable;
+			status = BT_HCI_ERR_SUCCESS;
+		}
+		cmd_complete(btdev, opcode, &status, sizeof(status));
+		break;
+
 	case BT_HCI_CMD_LE_SET_SCAN_PARAMETERS:
 		if (btdev->type == BTDEV_TYPE_BREDR)
 			goto unsupported;
diff --git a/monitor/bt.h b/monitor/bt.h
index 220cb0c..9f237ee 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -1475,6 +1475,7 @@ struct bt_hci_evt_le_long_term_key_request {
 #define BT_HCI_ERR_UNKNOWN_CONN_ID		0x02
 #define BT_HCI_ERR_HARDWARE_FAILURE		0x03
 #define BT_HCI_ERR_PAGE_TIMEOUT			0x04
+#define BT_HCI_ERR_COMMAND_DISALLOWED		0x0c
 #define BT_HCI_ERR_INVALID_PARAMETERS		0x12
 
 struct bt_l2cap_hdr {
-- 
1.7.9.5


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

* [RFC BlueZ 04/35] emulator: Store LE scan state of virtual controller
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (2 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 03/35] emulator: Implement basic LE set adv enable command Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 05/35] emulator: Search virtual devices in LE advertising mode Bruna Moreira
                   ` (31 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

The LE command set scan enable can change the scan state of virtual
controller.
---
 emulator/btdev.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 316d816..a7af6b3 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -89,6 +89,8 @@ struct btdev {
 	uint8_t  le_event_mask[8];
 	uint8_t  le_adv_data[31];
 	uint8_t  le_adv_data_len;
+	uint8_t  le_scan_enable;
+	uint8_t  le_filter_dup;
 	uint8_t  le_adv_enable;
 
 	uint16_t sync_train_interval;
@@ -908,6 +910,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	const struct bt_hci_cmd_le_set_event_mask *lsem;
 	const struct bt_hci_cmd_le_set_adv_data *lsad;
 	const struct bt_hci_cmd_le_set_adv_enable *lsae;
+	const struct bt_hci_cmd_le_set_scan_enable *lsse;
 	struct bt_hci_rsp_read_default_link_policy rdlp;
 	struct bt_hci_rsp_read_stored_link_key rslk;
 	struct bt_hci_rsp_write_stored_link_key wslk;
@@ -1542,7 +1545,14 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	case BT_HCI_CMD_LE_SET_SCAN_ENABLE:
 		if (btdev->type == BTDEV_TYPE_BREDR)
 			goto unsupported;
-		status = BT_HCI_ERR_SUCCESS;
+		lsse = data;
+		if (btdev->le_scan_enable == lsse->enable)
+			status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		else {
+			btdev->le_scan_enable = lsse->enable;
+			btdev->le_filter_dup = lsse->filter_dup;
+			status = BT_HCI_ERR_SUCCESS;
+		}
 		cmd_complete(btdev, opcode, &status, sizeof(status));
 		break;
 
-- 
1.7.9.5


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

* [RFC BlueZ 05/35] emulator: Search virtual devices in LE advertising mode
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (3 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 04/35] emulator: Store LE scan state of virtual controller Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-19  9:56   ` Johan Hedberg
  2013-06-12 12:56 ` [RFC BlueZ 06/35] emulator: Search virtual devices in LE scan mode Bruna Moreira
                   ` (30 subsequent siblings)
  35 siblings, 1 reply; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

After LE scan is enabled, the emulator search virtual devices that are
in advertising mode, in order to copy adv data.
---
 emulator/btdev.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index a7af6b3..160e5bf 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -876,6 +876,19 @@ static void remote_version_complete(struct btdev *btdev, uint16_t handle)
 							&rvc, sizeof(rvc));
 }
 
+static void le_set_scan_enable_complete(struct btdev *btdev)
+{
+	int i;
+
+	for (i = 0; i < MAX_BTDEV_ENTRIES; i++) {
+		if (!btdev_list[i] || btdev_list[i] == btdev)
+			continue;
+
+		if (!btdev_list[i]->le_adv_enable)
+			continue;
+	}
+}
+
 static void default_cmd(struct btdev *btdev, uint16_t opcode,
 						const void *data, uint8_t len)
 {
@@ -1554,6 +1567,8 @@ 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_READ_WHITE_LIST_SIZE:
-- 
1.7.9.5


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

* [RFC BlueZ 06/35] emulator: Search virtual devices in LE scan mode
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (4 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 05/35] emulator: Search virtual devices in LE advertising mode Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-19  9:57   ` Johan Hedberg
  2013-06-12 12:56 ` [RFC BlueZ 07/35] emulator: Implement LE advertising report Bruna Moreira
                   ` (29 subsequent siblings)
  35 siblings, 1 reply; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

When a virtual device starts an LE advertising, emulator search other
devices that are in scan mode, in order to send adv data to these
devices.
---
 emulator/btdev.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 160e5bf..2725c76 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -876,6 +876,19 @@ static void remote_version_complete(struct btdev *btdev, uint16_t handle)
 							&rvc, sizeof(rvc));
 }
 
+static void le_set_adv_enable_complete(struct btdev *btdev)
+{
+	int i;
+
+	for (i = 0; i < MAX_BTDEV_ENTRIES; i++) {
+		if (!btdev_list[i] || btdev_list[i] == btdev)
+			continue;
+
+		if (!btdev_list[i]->le_scan_enable)
+			continue;
+	}
+}
+
 static void le_set_scan_enable_complete(struct btdev *btdev)
 {
 	int i;
@@ -1546,6 +1559,8 @@ 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_adv_enable)
+			le_set_adv_enable_complete(btdev);
 		break;
 
 	case BT_HCI_CMD_LE_SET_SCAN_PARAMETERS:
-- 
1.7.9.5


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

* [RFC BlueZ 07/35] emulator: Implement LE advertising report
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (5 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 06/35] emulator: Search virtual devices in LE scan mode Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 08/35] emulator: Implement basic LE create connection Bruna Moreira
                   ` (28 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

This is a helper to report an advertising from a virtual device to other
device in scan mode.
---
 emulator/btdev.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 2725c76..171ca68 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -876,6 +876,30 @@ static void remote_version_complete(struct btdev *btdev, uint16_t handle)
 							&rvc, sizeof(rvc));
 }
 
+static void le_send_adv_report(struct btdev *btdev, const struct btdev *remote)
+{
+	struct __packed {
+		uint8_t subevent;
+		union {
+			struct bt_hci_evt_le_adv_report lar;
+			uint8_t raw[10 + 31 + 1];
+		};
+	} meta_event;
+
+	meta_event.subevent = BT_HCI_EVT_LE_ADV_REPORT;
+
+	memset(&meta_event.lar, 0, sizeof(meta_event.lar));
+	meta_event.lar.num_reports = 1;
+	memcpy(meta_event.lar.addr, remote->bdaddr, 6);
+	meta_event.lar.data_len = remote->le_adv_data_len;
+	memcpy(meta_event.lar.data, remote->le_adv_data,
+						meta_event.lar.data_len);
+	/* Not available */
+	meta_event.raw[10 + meta_event.lar.data_len] = 127;
+	send_event(btdev, BT_HCI_EVT_LE_META_EVENT, &meta_event,
+					1 + 10 + meta_event.lar.data_len + 1);
+}
+
 static void le_set_adv_enable_complete(struct btdev *btdev)
 {
 	int i;
@@ -886,6 +910,8 @@ static void le_set_adv_enable_complete(struct btdev *btdev)
 
 		if (!btdev_list[i]->le_scan_enable)
 			continue;
+
+		le_send_adv_report(btdev_list[i], btdev);
 	}
 }
 
@@ -899,6 +925,8 @@ static void le_set_scan_enable_complete(struct btdev *btdev)
 
 		if (!btdev_list[i]->le_adv_enable)
 			continue;
+
+		le_send_adv_report(btdev, btdev_list[i]);
 	}
 }
 
-- 
1.7.9.5


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

* [RFC BlueZ 08/35] emulator: Implement basic LE create connection
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (6 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 07/35] emulator: Implement LE advertising report Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 09/35] emulator: Dummy LE set advertising parameters Bruna Moreira
                   ` (27 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

Bind two LE virtual devices.
---
 emulator/btdev.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 171ca68..178971f 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -930,6 +930,43 @@ static void le_set_scan_enable_complete(struct btdev *btdev)
 	}
 }
 
+static void le_conn_complete(struct btdev *btdev, const uint8_t *bdaddr,
+						uint16_t handle, uint8_t role)
+{
+	struct __packed {
+		uint8_t subevent;
+		struct bt_hci_evt_le_conn_complete lcc;
+	} meta_event;
+
+	memset(&meta_event, 0, sizeof(meta_event));
+	meta_event.subevent = BT_HCI_EVT_LE_CONN_COMPLETE;
+	meta_event.lcc.handle = cpu_to_le16(handle);
+	meta_event.lcc.role = role;
+	memcpy(meta_event.lcc.peer_addr, bdaddr, 8);
+	/* 67.50 msec */
+	meta_event.lcc.interval = cpu_to_le16(54);
+
+	send_event(btdev, BT_HCI_EVT_LE_META_EVENT, &meta_event,
+							sizeof(meta_event));
+}
+
+static void le_conn_request(struct btdev *btdev, const uint8_t *bdaddr)
+{
+	struct btdev *remote = find_btdev_by_bdaddr(bdaddr);
+
+	/* TODO: check if is ADV connectable */
+	if (remote && remote->le_adv_enable) {
+		struct connection *conn = add_connection(btdev, remote);
+		/* disable advertising after connection succeeds */
+		remote->le_adv_enable = 0;
+
+		/* notify starter (Master) */
+		le_conn_complete(btdev, bdaddr, conn->handle, 0);
+		/* notify receiver (Slave) */
+		le_conn_complete(remote, btdev->bdaddr, conn->handle, 1);
+	}
+}
+
 static void default_cmd(struct btdev *btdev, uint16_t opcode,
 						const void *data, uint8_t len)
 {
@@ -965,6 +1002,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	const struct bt_hci_cmd_le_set_adv_data *lsad;
 	const struct bt_hci_cmd_le_set_adv_enable *lsae;
 	const struct bt_hci_cmd_le_set_scan_enable *lsse;
+	const struct bt_hci_cmd_le_create_conn *lcc;
 	struct bt_hci_rsp_read_default_link_policy rdlp;
 	struct bt_hci_rsp_read_stored_link_key rslk;
 	struct bt_hci_rsp_write_stored_link_key wslk;
@@ -1614,6 +1652,14 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 			le_set_scan_enable_complete(btdev);
 		break;
 
+	case BT_HCI_CMD_LE_CREATE_CONN:
+		if (btdev->type == BTDEV_TYPE_BREDR)
+			goto unsupported;
+		lcc = data;
+		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
+		le_conn_request(btdev, lcc->peer_addr);
+		break;
+
 	case BT_HCI_CMD_LE_READ_WHITE_LIST_SIZE:
 		if (btdev->type == BTDEV_TYPE_BREDR)
 			goto unsupported;
-- 
1.7.9.5


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

* [RFC BlueZ 09/35] emulator: Dummy LE set advertising parameters
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (7 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 08/35] emulator: Implement basic LE create connection Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 10/35] emulator: Disallow LE set scan params command when scan is enabled Bruna Moreira
                   ` (26 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

Implement basic LE set adv parameters command.
---
 emulator/btdev.c |   10 ++++++++++
 monitor/bt.h     |   12 ++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 178971f..cbcf140 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1606,6 +1606,16 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 		cmd_complete(btdev, opcode, &lrlf, sizeof(lrlf));
 		break;
 
+	case BT_HCI_CMD_LE_SET_ADV_PARAMETERS:
+		if (btdev->type == BTDEV_TYPE_BREDR)
+			goto unsupported;
+		if (btdev->le_adv_enable)
+			status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		else
+			status = BT_HCI_ERR_SUCCESS;
+		cmd_complete(btdev, opcode, &status, sizeof(status));
+		break;
+
 	case BT_HCI_CMD_LE_READ_ADV_TX_POWER:
 		if (btdev->type == BTDEV_TYPE_BREDR)
 			goto unsupported;
diff --git a/monitor/bt.h b/monitor/bt.h
index 9f237ee..e900525 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -838,6 +838,18 @@ struct bt_hci_cmd_le_set_random_address {
 	uint8_t  addr[6];
 } __attribute__ ((packed));
 
+#define BT_HCI_CMD_LE_SET_ADV_PARAMETERS	0x2006
+struct bt_hci_cmd_le_set_adv_parameters {
+	uint16_t adv_interval_min;
+	uint16_t adv_interval_max;
+	uint8_t adv_type;
+	uint8_t own_address_type;
+	uint8_t direct_address_type;
+	uint8_t direct_address[6];
+	uint8_t adv_channel_map;
+	uint8_t adv_filter_policy;
+} __attribute__ ((packed));
+
 #define BT_HCI_CMD_LE_READ_ADV_TX_POWER		0x2007
 struct bt_hci_rsp_le_read_adv_tx_power {
 	uint8_t  status;
-- 
1.7.9.5


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

* [RFC BlueZ 10/35] emulator: Disallow LE set scan params command when scan is enabled
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (8 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 09/35] emulator: Dummy LE set advertising parameters Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 11/35] emulator: Set LE supported states Bruna Moreira
                   ` (25 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

When LE scan is enabled, the command LE set scan parameters should
return a command disallowed in status of command complete event.
---
 emulator/btdev.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index cbcf140..e350a96 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1642,7 +1642,10 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	case BT_HCI_CMD_LE_SET_SCAN_PARAMETERS:
 		if (btdev->type == BTDEV_TYPE_BREDR)
 			goto unsupported;
-		status = BT_HCI_ERR_SUCCESS;
+		if (btdev->le_scan_enable)
+			status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		else
+			status = BT_HCI_ERR_SUCCESS;
 		cmd_complete(btdev, opcode, &status, sizeof(status));
 		break;
 
-- 
1.7.9.5


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

* [RFC BlueZ 11/35] emulator: Set LE supported states
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (9 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 10/35] emulator: Disallow LE set scan params command when scan is enabled Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 12/35] emulator: Add remove operation in HCI hook callback Bruna Moreira
                   ` (24 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

From: Jefferson Delfes <jefferson.delfes@openbossa.org>

---
 emulator/btdev.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index e350a96..6d95938 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -440,6 +440,37 @@ static void set_le_features(struct btdev *btdev)
 	btdev->max_page = 1;
 }
 
+static void set_le_states(struct btdev *btdev)
+{
+	btdev->le_states[0] |= 0x01; /* Non-connectable Advertsing */
+	btdev->le_states[0] |= 0x02; /* Scannable Advertising */
+	btdev->le_states[0] |= 0x04; /* Connectable Advertising */
+	btdev->le_states[0] |= 0x08; /* Directed Advertising */
+	btdev->le_states[0] |= 0x10; /* Passive Scanning */
+	btdev->le_states[0] |= 0x20; /* Active Scanning */
+	btdev->le_states[0] |= 0x40; /* Initiating / Connection (Master) */
+	btdev->le_states[0] |= 0x80; /* Connection (Slave) */
+	btdev->le_states[1] |= 0x01; /* Non-connectable Adv and Passive Scan */
+	btdev->le_states[1] |= 0x02; /* Scannable Adv and Passive Scan */
+	btdev->le_states[1] |= 0x04; /* Connectable Adv and Passive Scan */
+	btdev->le_states[1] |= 0x08; /* Directed Adv and Passive Scan */
+	btdev->le_states[1] |= 0x10; /* Non-connectable Adv and Active Scan */
+	btdev->le_states[1] |= 0x20; /* Scannable Adv and Active Scan */
+	btdev->le_states[1] |= 0x40; /* Connectable Adv and Active Scan */
+	btdev->le_states[1] |= 0x80; /* Directed Adv and Active Scan */
+	btdev->le_states[2] |= 0x01; /* Non-connectable Adv and Initiating */
+	btdev->le_states[2] |= 0x02; /* Scannable Adv and Initiating */
+	btdev->le_states[2] |= 0x04; /* Non-connectable Adv and Master Role */
+	btdev->le_states[2] |= 0x08; /* Scannable Adv and Master Role */
+	btdev->le_states[2] |= 0x10; /* Non-connectable Adv and Slave Role */
+	btdev->le_states[2] |= 0x20; /* Scannable Adv and Slave Role */
+	btdev->le_states[3] |= 0x01; /* Passive Scan and Master Role */
+	btdev->le_states[3] |= 0x02; /* Active Scan and Master Role */
+	btdev->le_states[3] |= 0x04; /* Passive Scan and Slave Role */
+	btdev->le_states[3] |= 0x08; /* Active Scan and Slave Role */
+	btdev->le_states[3] |= 0x10; /* Initiating and Master Role */
+}
+
 static void set_amp_features(struct btdev *btdev)
 {
 }
@@ -469,6 +500,7 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id)
 	case BTDEV_TYPE_BREDRLE:
 		set_bredrle_features(btdev);
 		set_bredrle_commands(btdev);
+		set_le_states(btdev);
 		break;
 	case BTDEV_TYPE_BREDR:
 		set_bredr_features(btdev);
@@ -477,6 +509,7 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id)
 	case BTDEV_TYPE_LE:
 		set_le_features(btdev);
 		set_le_commands(btdev);
+		set_le_states(btdev);
 		break;
 	case BTDEV_TYPE_AMP:
 		set_amp_features(btdev);
-- 
1.7.9.5


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

* [RFC BlueZ 12/35] emulator: Add remove operation in HCI hook callback
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (10 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 11/35] emulator: Set LE supported states Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:56 ` [RFC BlueZ 13/35] emulator: Add support for pre/post command/event hooks Bruna Moreira
                   ` (23 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

Now it is possible remove the HCI hook callback after running it at
least once. It working similar to glib watchers, and it is removed when
the function calback return false, otherwise it is kept.
---
 src/shared/hciemu.c |   24 ++++++++++++++++++++----
 src/shared/hciemu.h |    2 +-
 tools/mgmt-tester.c |   10 ++++++----
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
index a0b347c..7ff651e 100644
--- a/src/shared/hciemu.c
+++ b/src/shared/hciemu.c
@@ -66,21 +66,37 @@ static void destroy_command_hook(gpointer data, gpointer user_data)
 	g_free(hook);
 }
 
+static void remove_command_hook(GList **lhooks,
+					struct hciemu_command_hook *hook)
+{
+	*lhooks = g_list_remove(*lhooks, hook);
+	g_free(hook);
+}
+
 static void master_command_callback(uint16_t opcode,
 				const void *data, uint8_t len,
 				btdev_callback callback, void *user_data)
 {
 	struct hciemu *hciemu = user_data;
-	GList *list;
+	GList *list, *next;
 
 	btdev_command_default(callback);
 
 	for (list = g_list_first(hciemu->post_command_hooks); list;
-						list = g_list_next(list)) {
+								list = next) {
 		struct hciemu_command_hook *hook = list->data;
 
-		if (hook->function)
-			hook->function(opcode, data, len, hook->user_data);
+		next = g_list_next(list);
+
+		if (hook->function) {
+			int ret;
+
+			ret = hook->function(opcode, data, len,
+							hook->user_data);
+			if (!ret)
+				remove_command_hook(&hciemu->post_command_hooks,
+									hook);
+		}
 	}
 }
 
diff --git a/src/shared/hciemu.h b/src/shared/hciemu.h
index a473c0e..dc7cc1f 100644
--- a/src/shared/hciemu.h
+++ b/src/shared/hciemu.h
@@ -44,7 +44,7 @@ const char *hciemu_get_address(struct hciemu *hciemu);
 const uint8_t *hciemu_get_master_bdaddr(struct hciemu *hciemu);
 const uint8_t *hciemu_get_client_bdaddr(struct hciemu *hciemu);
 
-typedef void (*hciemu_command_func_t)(uint16_t opcode, const void *data,
+typedef bool (*hciemu_command_func_t)(uint16_t opcode, const void *data,
 						uint8_t len, void *user_data);
 
 bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 844f7db..08b5ac8 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -2300,7 +2300,7 @@ static void command_generic_callback(uint8_t status, uint16_t length,
 	test_condition_complete(data);
 }
 
-static void command_hci_callback(uint16_t opcode, const void *param,
+static bool command_hci_callback(uint16_t opcode, const void *param,
 					uint8_t length, void *user_data)
 {
 	struct test_data *data = user_data;
@@ -2309,21 +2309,23 @@ static void command_hci_callback(uint16_t opcode, const void *param,
 	tester_print("HCI Command 0x%04x length %u", opcode, length);
 
 	if (opcode != test->expect_hci_command)
-		return;
+		return true;
 
 	if (length != test->expect_hci_len) {
 		tester_warn("Invalid parameter size for HCI command");
 		tester_test_failed();
-		return;
+		return false;
 	}
 
 	if (memcmp(param, test->expect_hci_param, length) != 0) {
 		tester_warn("Unexpected HCI command parameter value");
 		tester_test_failed();
-		return;
+		return false;
 	}
 
 	test_condition_complete(data);
+
+	return true;
 }
 
 static void test_command_generic(const void *test_data)
-- 
1.7.9.5


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

* [RFC BlueZ 13/35] emulator: Add support for pre/post command/event hooks
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (11 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 12/35] emulator: Add remove operation in HCI hook callback Bruna Moreira
@ 2013-06-12 12:56 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 14/35] emulator: Add hook only if there aren't other with same type and opcode Bruna Moreira
                   ` (22 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Eder Ruiz Maria

From: Eder Ruiz Maria <eder.ruiz@openbossa.org>

Now who use emulator can add hooks to manipulate hci packets before
and after process commands and send events.
---
 emulator/btdev.c |   37 +++++++++++++++++++++++++++++++++++++
 emulator/btdev.h |   15 +++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 6d95938..1560936 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -42,6 +42,15 @@
 #define has_bredr(btdev)	(!((btdev)->features[4] & 0x20))
 #define has_le(btdev)		(!!((btdev)->features[4] & 0x40))
 
+struct hook {
+	btdev_hook_func handler;
+	void *user_data;
+	enum btdev_hook_type type;
+	uint16_t opcode;
+};
+
+#define MAX_HOOK_ENTRIES 16
+
 struct btdev {
 	enum btdev_type type;
 
@@ -51,6 +60,8 @@ struct btdev {
 	btdev_send_func send_handler;
 	void *send_data;
 
+	struct hook *hook_list[MAX_HOOK_ENTRIES];
+
         uint16_t manufacturer;
         uint8_t  version;
 	uint16_t revision;
@@ -1836,3 +1847,29 @@ void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len)
 		break;
 	}
 }
+
+int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
+				uint16_t opcode, btdev_hook_func handler,
+				void *user_data)
+{
+	int i;
+
+	if (!btdev)
+		return -1;
+
+	for (i = 0; i < MAX_HOOK_ENTRIES; i++) {
+		if (btdev->hook_list[i] == NULL) {
+			btdev->hook_list[i] = malloc(sizeof(struct hook));
+			if (btdev->hook_list[i] == NULL)
+				return -1;
+
+			btdev->hook_list[i]->handler = handler;
+			btdev->hook_list[i]->user_data = user_data;
+			btdev->hook_list[i]->opcode = opcode;
+			btdev->hook_list[i]->type = type;
+			return i;
+		}
+	}
+
+	return -1;
+}
diff --git a/emulator/btdev.h b/emulator/btdev.h
index 9fb023c..085093f 100644
--- a/emulator/btdev.h
+++ b/emulator/btdev.h
@@ -23,6 +23,7 @@
  */
 
 #include <stdint.h>
+#include <stdbool.h>
 
 #define BTDEV_RESPONSE_DEFAULT		0
 #define BTDEV_RESPONSE_COMMAND_STATUS	1
@@ -53,6 +54,9 @@ typedef void (*btdev_command_func) (uint16_t opcode,
 typedef void (*btdev_send_func) (const void *data, uint16_t len,
 							void *user_data);
 
+typedef bool (*btdev_hook_func) (const void *data, uint16_t len,
+							void *user_data);
+
 enum btdev_type {
 	BTDEV_TYPE_BREDRLE,
 	BTDEV_TYPE_BREDR,
@@ -60,6 +64,13 @@ enum btdev_type {
 	BTDEV_TYPE_AMP,
 };
 
+enum btdev_hook_type {
+	BTDEV_HOOK_PRE_CMD,
+	BTDEV_HOOK_POST_CMD,
+	BTDEV_HOOK_PRE_EVT,
+	BTDEV_HOOK_POST_EVT,
+};
+
 struct btdev;
 
 struct btdev *btdev_create(enum btdev_type type, uint16_t id);
@@ -74,3 +85,7 @@ void btdev_set_send_handler(struct btdev *btdev, btdev_send_func handler,
 							void *user_data);
 
 void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len);
+
+int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
+				uint16_t opcode, btdev_hook_func handler,
+				void *user_data);
-- 
1.7.9.5


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

* [RFC BlueZ 14/35] emulator: Add hook only if there aren't other with same type and opcode
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (12 preceding siblings ...)
  2013-06-12 12:56 ` [RFC BlueZ 13/35] emulator: Add support for pre/post command/event hooks Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 15/35] emulator: Export command and event hooks for hciemu user Bruna Moreira
                   ` (21 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Eder Ruiz Maria

From: Eder Ruiz Maria <eder.ruiz@openbossa.org>

---
 emulator/btdev.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 1560936..1006e03 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -123,6 +123,23 @@ struct connection {
 
 static struct connection *connection_list[MAX_CONNECTION_ENTRIES] = { };
 
+static int get_hook_index(struct btdev *btdev, enum btdev_hook_type type,
+								uint16_t opcode)
+{
+	int i;
+
+	for (i = 0; i < MAX_HOOK_ENTRIES; i++) {
+		if (btdev->hook_list[i] == NULL)
+			continue;
+
+		if (btdev->hook_list[i]->type == type &&
+					btdev->hook_list[i]->opcode == opcode)
+			return i;
+	}
+
+	return -1;
+}
+
 static inline int add_btdev(struct btdev *btdev)
 {
 	int i, index = -1;
@@ -1857,6 +1874,9 @@ int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
 	if (!btdev)
 		return -1;
 
+	if (get_hook_index(btdev, type, opcode) > 0)
+		return -1;
+
 	for (i = 0; i < MAX_HOOK_ENTRIES; i++) {
 		if (btdev->hook_list[i] == NULL) {
 			btdev->hook_list[i] = malloc(sizeof(struct hook));
-- 
1.7.9.5


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

* [RFC BlueZ 15/35] emulator: Export command and event hooks for hciemu user
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (13 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 14/35] emulator: Add hook only if there aren't other with same type and opcode Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 16/35] emulator: Add support for delete a hook Bruna Moreira
                   ` (20 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Eder Ruiz Maria

From: Eder Ruiz Maria <eder.ruiz@openbossa.org>

---
 src/shared/hciemu.c |   30 ++++++++++++++++++++++++++++++
 src/shared/hciemu.h |   15 ++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
index 7ff651e..4ebeff6 100644
--- a/src/shared/hciemu.c
+++ b/src/shared/hciemu.c
@@ -405,3 +405,33 @@ bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
 
 	return true;
 }
+
+int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
+				uint16_t opcode, hciemu_hook_func_t function,
+				void *user_data)
+{
+	enum btdev_hook_type hook_type;
+
+	if (!hciemu)
+		return -1;
+
+	switch (type) {
+	case HCIEMU_HOOK_PRE_CMD:
+		hook_type = BTDEV_HOOK_PRE_CMD;
+		break;
+	case HCIEMU_HOOK_POST_CMD:
+		hook_type = BTDEV_HOOK_POST_CMD;
+		break;
+	case HCIEMU_HOOK_PRE_EVT:
+		hook_type = BTDEV_HOOK_PRE_EVT;
+		break;
+	case HCIEMU_HOOK_POST_EVT:
+		hook_type = BTDEV_HOOK_POST_EVT;
+		break;
+	default:
+		return -1;
+	}
+
+	return btdev_add_hook(hciemu->master_dev, hook_type, opcode, function,
+								user_data);
+}
diff --git a/src/shared/hciemu.h b/src/shared/hciemu.h
index dc7cc1f..13575de 100644
--- a/src/shared/hciemu.h
+++ b/src/shared/hciemu.h
@@ -32,8 +32,14 @@ enum hciemu_type {
 	HCIEMU_TYPE_LE,
 };
 
-struct hciemu *hciemu_new(enum hciemu_type type);
+enum hciemu_hook_type {
+	HCIEMU_HOOK_PRE_CMD,
+	HCIEMU_HOOK_POST_CMD,
+	HCIEMU_HOOK_PRE_EVT,
+	HCIEMU_HOOK_POST_EVT,
+};
 
+struct hciemu *hciemu_new(enum hciemu_type type);
 struct hciemu *hciemu_ref(struct hciemu *hciemu);
 void hciemu_unref(struct hciemu *hciemu);
 
@@ -47,5 +53,12 @@ const uint8_t *hciemu_get_client_bdaddr(struct hciemu *hciemu);
 typedef bool (*hciemu_command_func_t)(uint16_t opcode, const void *data,
 						uint8_t len, void *user_data);
 
+typedef bool (*hciemu_hook_func_t)(const void *data, uint16_t len,
+							void *user_data);
+
 bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
 			hciemu_command_func_t function, void *user_data);
+
+int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
+				uint16_t opcode, hciemu_hook_func_t function,
+				void *user_data);
-- 
1.7.9.5


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

* [RFC BlueZ 16/35] emulator: Add support for delete a hook
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (14 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 15/35] emulator: Export command and event hooks for hciemu user Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 17/35] emulator: Split default_cmd() for better command and event handler Bruna Moreira
                   ` (19 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Eder Ruiz Maria

From: Eder Ruiz Maria <eder.ruiz@openbossa.org>

---
 emulator/btdev.c    |   25 +++++++++++++++++++++++++
 emulator/btdev.h    |    3 +++
 src/shared/hciemu.c |   28 ++++++++++++++++++++++++++++
 src/shared/hciemu.h |    3 +++
 4 files changed, 59 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 1006e03..13f99bc 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1893,3 +1893,28 @@ int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
 
 	return -1;
 }
+
+bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
+								uint16_t opcode)
+{
+	int i;
+
+	if (!btdev)
+		return false;
+
+	for (i = 0; i < MAX_HOOK_ENTRIES; i++) {
+		if (btdev->hook_list[i] == NULL)
+			continue;
+
+		if (btdev->hook_list[i]->type != type ||
+					btdev->hook_list[i]->opcode != opcode)
+			continue;
+
+		free(btdev->hook_list[i]);
+		btdev->hook_list[i] = NULL;
+
+		return true;
+	}
+
+	return false;
+}
diff --git a/emulator/btdev.h b/emulator/btdev.h
index 085093f..5118a4a 100644
--- a/emulator/btdev.h
+++ b/emulator/btdev.h
@@ -89,3 +89,6 @@ void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len);
 int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
 				uint16_t opcode, btdev_hook_func handler,
 				void *user_data);
+
+bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
+							uint16_t opcode);
diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
index 4ebeff6..0bbaa09 100644
--- a/src/shared/hciemu.c
+++ b/src/shared/hciemu.c
@@ -435,3 +435,31 @@ int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
 	return btdev_add_hook(hciemu->master_dev, hook_type, opcode, function,
 								user_data);
 }
+
+bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
+								uint16_t opcode)
+{
+	enum btdev_hook_type hook_type;
+
+	if (!hciemu)
+		return false;
+
+	switch (type) {
+	case HCIEMU_HOOK_PRE_CMD:
+		hook_type = BTDEV_HOOK_PRE_CMD;
+		break;
+	case HCIEMU_HOOK_POST_CMD:
+		hook_type = BTDEV_HOOK_POST_CMD;
+		break;
+	case HCIEMU_HOOK_PRE_EVT:
+		hook_type = BTDEV_HOOK_PRE_EVT;
+		break;
+	case HCIEMU_HOOK_POST_EVT:
+		hook_type = BTDEV_HOOK_POST_EVT;
+		break;
+	default:
+		return false;
+	}
+
+	return btdev_del_hook(hciemu->master_dev, hook_type, opcode);
+}
diff --git a/src/shared/hciemu.h b/src/shared/hciemu.h
index 13575de..2abf404 100644
--- a/src/shared/hciemu.h
+++ b/src/shared/hciemu.h
@@ -62,3 +62,6 @@ bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
 int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
 				uint16_t opcode, hciemu_hook_func_t function,
 				void *user_data);
+
+bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
+							uint16_t opcode);
-- 
1.7.9.5


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

* [RFC BlueZ 17/35] emulator: Split default_cmd() for better command and event handler
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (15 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 16/35] emulator: Add support for delete a hook Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 18/35] emulator: cmd_status() using send_packet() for run hooks easily Bruna Moreira
                   ` (18 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Eder Ruiz Maria

From: Eder Ruiz Maria <eder.ruiz@openbossa.org>

Now except for command complete event and command status event, all
other are handled by default_cmd_completion(). With this we can easily
add hooks in some points.
---
 emulator/btdev.c |  131 ++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 97 insertions(+), 34 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 13f99bc..c12103d 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1031,16 +1031,6 @@ static void le_conn_request(struct btdev *btdev, const uint8_t *bdaddr)
 static void default_cmd(struct btdev *btdev, uint16_t opcode,
 						const void *data, uint8_t len)
 {
-	const struct bt_hci_cmd_create_conn *cc;
-	const struct bt_hci_cmd_disconnect *dc;
-	const struct bt_hci_cmd_create_conn_cancel *ccc;
-	const struct bt_hci_cmd_accept_conn_request *acr;
-	const struct bt_hci_cmd_reject_conn_request *rcr;
-	const struct bt_hci_cmd_remote_name_request *rnr;
-	const struct bt_hci_cmd_remote_name_request_cancel *rnrc;
-	const struct bt_hci_cmd_read_remote_features *rrf;
-	const struct bt_hci_cmd_read_remote_ext_features *rref;
-	const struct bt_hci_cmd_read_remote_version *rrv;
 	const struct bt_hci_cmd_write_default_link_policy *wdlp;
 	const struct bt_hci_cmd_set_event_mask *sem;
 	const struct bt_hci_cmd_set_event_filter *sef;
@@ -1105,7 +1095,6 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		inquiry_complete(btdev, BT_HCI_ERR_SUCCESS);
 		break;
 
 	case BT_HCI_CMD_INQUIRY_CANCEL:
@@ -1118,80 +1107,58 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	case BT_HCI_CMD_CREATE_CONN:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		cc = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		conn_request(btdev, cc->bdaddr);
 		break;
 
 	case BT_HCI_CMD_DISCONNECT:
-		dc = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		disconnect_complete(btdev, le16_to_cpu(dc->handle), dc->reason);
 		break;
 
 	case BT_HCI_CMD_CREATE_CONN_CANCEL:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		ccc = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		conn_complete(btdev, ccc->bdaddr, BT_HCI_ERR_UNKNOWN_CONN_ID);
 		break;
 
 	case BT_HCI_CMD_ACCEPT_CONN_REQUEST:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		acr = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		conn_complete(btdev, acr->bdaddr, BT_HCI_ERR_SUCCESS);
 		break;
 
 	case BT_HCI_CMD_REJECT_CONN_REQUEST:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		rcr = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		conn_complete(btdev, rcr->bdaddr, BT_HCI_ERR_UNKNOWN_CONN_ID);
 		break;
 
 	case BT_HCI_CMD_REMOTE_NAME_REQUEST:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		rnr = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		name_request_complete(btdev, rnr->bdaddr, BT_HCI_ERR_SUCCESS);
 		break;
 
 	case BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		rnrc = data;
 		status = BT_HCI_ERR_SUCCESS;
 		cmd_complete(btdev, opcode, &status, sizeof(status));
-		name_request_complete(btdev, rnrc->bdaddr,
-						BT_HCI_ERR_UNKNOWN_CONN_ID);
 		break;
 
 	case BT_HCI_CMD_READ_REMOTE_FEATURES:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		rrf = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		remote_features_complete(btdev, le16_to_cpu(rrf->handle));
 		break;
 
 	case BT_HCI_CMD_READ_REMOTE_EXT_FEATURES:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		rref = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		remote_ext_features_complete(btdev, le16_to_cpu(rref->handle),
-								rref->page);
 		break;
 
 	case BT_HCI_CMD_READ_REMOTE_VERSION:
-		rrv = data;
 		cmd_status(btdev, BT_HCI_ERR_SUCCESS, opcode);
-		remote_version_complete(btdev, le16_to_cpu(rrv->handle));
 		break;
 
 	case BT_HCI_CMD_READ_DEFAULT_LINK_POLICY:
@@ -1772,6 +1739,97 @@ unsupported:
 	cmd_status(btdev, BT_HCI_ERR_UNKNOWN_COMMAND, opcode);
 }
 
+static void default_cmd_completion(struct btdev *btdev, uint16_t opcode,
+						const void *data, uint8_t len)
+{
+	const struct bt_hci_cmd_create_conn *cc;
+	const struct bt_hci_cmd_disconnect *dc;
+	const struct bt_hci_cmd_create_conn_cancel *ccc;
+	const struct bt_hci_cmd_accept_conn_request *acr;
+	const struct bt_hci_cmd_reject_conn_request *rcr;
+	const struct bt_hci_cmd_remote_name_request *rnr;
+	const struct bt_hci_cmd_remote_name_request_cancel *rnrc;
+	const struct bt_hci_cmd_read_remote_features *rrf;
+	const struct bt_hci_cmd_read_remote_ext_features *rref;
+	const struct bt_hci_cmd_read_remote_version *rrv;
+
+	switch (opcode) {
+	case BT_HCI_CMD_INQUIRY:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		inquiry_complete(btdev, BT_HCI_ERR_SUCCESS);
+		break;
+
+	case BT_HCI_CMD_CREATE_CONN:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		cc = data;
+		conn_request(btdev, cc->bdaddr);
+		break;
+
+	case BT_HCI_CMD_DISCONNECT:
+		dc = data;
+		disconnect_complete(btdev, le16_to_cpu(dc->handle), dc->reason);
+		break;
+
+	case BT_HCI_CMD_CREATE_CONN_CANCEL:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		ccc = data;
+		conn_complete(btdev, ccc->bdaddr, BT_HCI_ERR_UNKNOWN_CONN_ID);
+		break;
+
+	case BT_HCI_CMD_ACCEPT_CONN_REQUEST:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		acr = data;
+		conn_complete(btdev, acr->bdaddr, BT_HCI_ERR_SUCCESS);
+		break;
+
+	case BT_HCI_CMD_REJECT_CONN_REQUEST:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		rcr = data;
+		conn_complete(btdev, rcr->bdaddr, BT_HCI_ERR_UNKNOWN_CONN_ID);
+		break;
+
+	case BT_HCI_CMD_REMOTE_NAME_REQUEST:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		rnr = data;
+		name_request_complete(btdev, rnr->bdaddr, BT_HCI_ERR_SUCCESS);
+		break;
+
+	case BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		rnrc = data;
+		name_request_complete(btdev, rnrc->bdaddr,
+						BT_HCI_ERR_UNKNOWN_CONN_ID);
+		break;
+
+	case BT_HCI_CMD_READ_REMOTE_FEATURES:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		rrf = data;
+		remote_features_complete(btdev, le16_to_cpu(rrf->handle));
+		break;
+
+	case BT_HCI_CMD_READ_REMOTE_EXT_FEATURES:
+		if (btdev->type == BTDEV_TYPE_LE)
+			return;
+		rref = data;
+		remote_ext_features_complete(btdev, le16_to_cpu(rref->handle),
+								rref->page);
+		break;
+
+	case BT_HCI_CMD_READ_REMOTE_VERSION:
+		rrv = data;
+		remote_version_complete(btdev, le16_to_cpu(rrv->handle));
+		break;
+	}
+}
+
 struct btdev_callback {
 	void (*function)(btdev_callback callback, uint8_t response,
 				uint8_t status, const void *data, uint8_t len);
@@ -1796,6 +1854,8 @@ static void handler_callback(btdev_callback callback, uint8_t response,
 	case BTDEV_RESPONSE_DEFAULT:
 		default_cmd(btdev, callback->opcode,
 					callback->data, callback->len);
+		default_cmd_completion(btdev, callback->opcode,
+					callback->data, callback->len);
 		break;
 	case BTDEV_RESPONSE_COMMAND_STATUS:
 		cmd_status(btdev, status, callback->opcode);
@@ -1828,9 +1888,12 @@ static void process_cmd(struct btdev *btdev, const void *data, uint16_t len)
 		btdev->command_handler(callback.opcode,
 					callback.data, callback.len,
 					&callback, btdev->command_data);
-	else
+	else {
 		default_cmd(btdev, callback.opcode,
 					callback.data, callback.len);
+		default_cmd_completion(btdev, callback.opcode,
+					callback.data, callback.len);
+	}
 }
 
 void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len)
-- 
1.7.9.5


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

* [RFC BlueZ 18/35] emulator: cmd_status() using send_packet() for run hooks easily
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (16 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 17/35] emulator: Split default_cmd() for better command and event handler Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 19/35] emulator: Add new function for running all hooks Bruna Moreira
                   ` (17 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Eder Ruiz Maria

From: Eder Ruiz Maria <eder.ruiz@openbossa.org>

Now like cmd_command(), cmd_status() directly uses send_packet() instead
of send_event(), consequently cmd_status() must build the hci packet
without help of send_event(). With this change the events sent by
default_cmd() no more use send_event(), who is a good place to run hooks
for BTDEV_HOOK_POST_EVT. And the functions cmd_command() and
cmd_status() can run hooks for BTDEV_HOOK_POST_CMD.
---
 emulator/btdev.c |   28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index c12103d..69cfd12 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -673,13 +673,31 @@ static void cmd_complete(struct btdev *btdev, uint16_t opcode,
 
 static void cmd_status(struct btdev *btdev, uint8_t status, uint16_t opcode)
 {
-	struct bt_hci_evt_cmd_status cs;
+	struct bt_hci_evt_hdr *hdr;
+	struct bt_hci_evt_cmd_status *cs;
+	uint16_t pkt_len;
+	void *pkt_data;
+
+	pkt_len = 1 + sizeof(*hdr) + sizeof(*cs);
 
-	cs.status = status;
-	cs.ncmd = 0x01;
-	cs.opcode = cpu_to_le16(opcode);
+	pkt_data = malloc(pkt_len);
+	if (!pkt_data)
+		return;
 
-	send_event(btdev, BT_HCI_EVT_CMD_STATUS, &cs, sizeof(cs));
+	((uint8_t *) pkt_data)[0] = BT_H4_EVT_PKT;
+
+	hdr = pkt_data + 1;
+	hdr->evt = BT_HCI_EVT_CMD_STATUS;
+	hdr->plen = sizeof(*cs);
+
+	cs = pkt_data + 1 + sizeof(*hdr);
+	cs->status = status;
+	cs->ncmd = 0x01;
+	cs->opcode = cpu_to_le16(opcode);
+
+	send_packet(btdev, pkt_data, pkt_len);
+
+	free(pkt_data);
 }
 
 static void num_completed_packets(struct btdev *btdev, uint16_t handle)
-- 
1.7.9.5


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

* [RFC BlueZ 19/35] emulator: Add new function for running all hooks
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (17 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 18/35] emulator: cmd_status() using send_packet() for run hooks easily Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 20/35] tools/mgmt-tester: Add stop discovery for BR/EDR only Bruna Moreira
                   ` (16 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

It was defined four hook types and they are run before/after the first
part of default command processing and send event. Note that hook return
will define if the emulator will process/send next events (calling the
default_cmd_completion() function or not).
---
 emulator/btdev.c |   34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 69cfd12..e70ad19 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -140,6 +140,17 @@ static int get_hook_index(struct btdev *btdev, enum btdev_hook_type type,
 	return -1;
 }
 
+static bool run_hooks(struct btdev *btdev, enum btdev_hook_type type,
+				uint16_t opcode, const void *data, uint16_t len)
+{
+	int index = get_hook_index(btdev, type, opcode);
+	if (index < 0)
+		return true;
+
+	return btdev->hook_list[index]->handler(data, len,
+					btdev->hook_list[index]->user_data);
+}
+
 static inline int add_btdev(struct btdev *btdev)
 {
 	int i, index = -1;
@@ -634,7 +645,8 @@ static void send_event(struct btdev *btdev, uint8_t event,
 	if (len > 0)
 		memcpy(pkt_data + 1 + sizeof(*hdr), data, len);
 
-	send_packet(btdev, pkt_data, pkt_len);
+	if (run_hooks(btdev, BTDEV_HOOK_POST_EVT, event, pkt_data, pkt_len))
+		send_packet(btdev, pkt_data, pkt_len);
 
 	free(pkt_data);
 }
@@ -666,7 +678,8 @@ static void cmd_complete(struct btdev *btdev, uint16_t opcode,
 	if (len > 0)
 		memcpy(pkt_data + 1 + sizeof(*hdr) + sizeof(*cc), data, len);
 
-	send_packet(btdev, pkt_data, pkt_len);
+	if (run_hooks(btdev, BTDEV_HOOK_POST_CMD, opcode, pkt_data, pkt_len))
+		send_packet(btdev, pkt_data, pkt_len);
 
 	free(pkt_data);
 }
@@ -695,7 +708,8 @@ static void cmd_status(struct btdev *btdev, uint8_t status, uint16_t opcode)
 	cs->ncmd = 0x01;
 	cs->opcode = cpu_to_le16(opcode);
 
-	send_packet(btdev, pkt_data, pkt_len);
+	if (run_hooks(btdev, BTDEV_HOOK_POST_CMD, opcode, pkt_data, pkt_len))
+		send_packet(btdev, pkt_data, pkt_len);
 
 	free(pkt_data);
 }
@@ -1870,8 +1884,15 @@ static void handler_callback(btdev_callback callback, uint8_t response,
 
 	switch (response) {
 	case BTDEV_RESPONSE_DEFAULT:
+		if (!run_hooks(btdev, BTDEV_HOOK_PRE_CMD, callback->opcode,
+						callback->data, callback->len))
+			return;
 		default_cmd(btdev, callback->opcode,
 					callback->data, callback->len);
+
+		if (!run_hooks(btdev, BTDEV_HOOK_PRE_EVT, callback->opcode,
+						callback->data, callback->len))
+			return;
 		default_cmd_completion(btdev, callback->opcode,
 					callback->data, callback->len);
 		break;
@@ -1907,8 +1928,15 @@ static void process_cmd(struct btdev *btdev, const void *data, uint16_t len)
 					callback.data, callback.len,
 					&callback, btdev->command_data);
 	else {
+		if (!run_hooks(btdev, BTDEV_HOOK_PRE_CMD, callback.opcode,
+						callback.data, callback.len))
+			return;
 		default_cmd(btdev, callback.opcode,
 					callback.data, callback.len);
+
+		if (!run_hooks(btdev, BTDEV_HOOK_PRE_EVT, callback.opcode,
+						callback.data, callback.len))
+			return;
 		default_cmd_completion(btdev, callback.opcode,
 					callback.data, callback.len);
 	}
-- 
1.7.9.5


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

* [RFC BlueZ 20/35] tools/mgmt-tester: Add stop discovery for BR/EDR only
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (18 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 19/35] emulator: Add new function for running all hooks Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 21/35] tools/mgmt-tester: Add support for second controller Bruna Moreira
                   ` (15 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

Send stop command during inquiry. Check if inquiry cancel is sent and
discovering event is disabled.
---
 tools/mgmt-tester.c |   72 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 70 insertions(+), 2 deletions(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 08b5ac8..cbff775 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -352,6 +352,9 @@ static void controller_setup(const void *test_data)
 }
 
 struct generic_data {
+	uint16_t setup_expect_hci_command;
+	const void *setup_expect_hci_param;
+	uint8_t setup_expect_hci_len;
 	bool send_index_none;
 	uint16_t send_opcode;
 	const void *send_param;
@@ -1125,6 +1128,9 @@ static const char stop_discovery_bredrle_param[] = { 0x07 };
 static const char stop_discovery_bredrle_invalid_param[] = { 0x06 };
 static const char stop_discovery_valid_hci[] = { 0x00, 0x00 };
 static const char stop_discovery_evt[] = { 0x07, 0x00 };
+static const char stop_discovery_bredr_param[] = { 0x01 };
+static const char stop_discovery_bredr_discovering[] = { 0x01, 0x00 };
+static const char stop_discovery_inq_param[] = { 0x33, 0x8b, 0x9e, 0x08, 0x00 };
 
 static const struct generic_data stop_discovery_success_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
@@ -1141,6 +1147,22 @@ static const struct generic_data stop_discovery_success_test_1 = {
 	.expect_alt_ev_len = sizeof(stop_discovery_evt),
 };
 
+static const struct generic_data stop_discovery_bredr_success_test_1 = {
+	.setup_expect_hci_command = BT_HCI_CMD_INQUIRY,
+	.setup_expect_hci_param = stop_discovery_inq_param,
+	.setup_expect_hci_len = sizeof(stop_discovery_inq_param),
+	.send_opcode = MGMT_OP_STOP_DISCOVERY,
+	.send_param = stop_discovery_bredr_param,
+	.send_len = sizeof(stop_discovery_bredr_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = stop_discovery_bredr_param,
+	.expect_len = sizeof(stop_discovery_bredr_param),
+	.expect_hci_command = BT_HCI_CMD_INQUIRY_CANCEL,
+	.expect_alt_ev = MGMT_EV_DISCOVERING,
+	.expect_alt_ev_param = stop_discovery_bredr_discovering,
+	.expect_alt_ev_len = sizeof(stop_discovery_bredr_discovering),
+};
+
 static const struct generic_data stop_discovery_rejected_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
 	.send_param = stop_discovery_bredrle_param,
@@ -1833,11 +1855,41 @@ static void setup_discovery_callback(uint8_t status, uint16_t length,
 	tester_setup_complete();
 }
 
+static bool setup_command_hci_callback(const void *data, uint16_t len,
+								void *user_data)
+{
+	struct test_data *tdata = tester_get_data();
+	const struct generic_data *test = tdata->test_data;
+
+	tester_print("HCI Command 0x%04x length %u (setup)",
+					test->setup_expect_hci_command, len);
+
+	if (len != test->setup_expect_hci_len) {
+		tester_warn("Invalid parameter size for HCI command (setup)");
+		tester_setup_failed();
+		goto done;
+	}
+
+	if (memcmp(data, test->setup_expect_hci_param, len) != 0) {
+		tester_warn("Unexpected HCI command parameter value (setup)");
+		tester_setup_failed();
+		goto done;
+	}
+
+	tester_setup_complete();
+
+done:
+	hciemu_del_hook(tdata->hciemu, HCIEMU_HOOK_PRE_EVT,
+			test->setup_expect_hci_command);
+
+	return false;
+}
+
 static void setup_start_discovery_callback(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
 	struct test_data *data = tester_get_data();
-	unsigned char disc_param[] = { 0x07 };
+	const struct generic_data *test = data->test_data;
 
 	if (status != MGMT_STATUS_SUCCESS) {
 		tester_setup_failed();
@@ -1846,9 +1898,22 @@ static void setup_start_discovery_callback(uint8_t status, uint16_t length,
 
 	tester_print("Controller powered on");
 
-	mgmt_send(data->mgmt, MGMT_OP_START_DISCOVERY, data->mgmt_index,
+	if (test->setup_expect_hci_command) {
+		tester_print("Registering HCI command callback (setup)");
+		hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT,
+				test->setup_expect_hci_command,
+				setup_command_hci_callback,
+				NULL);
+		mgmt_send(data->mgmt, MGMT_OP_START_DISCOVERY, data->mgmt_index,
+				test->send_len, test->send_param,
+				NULL, NULL, NULL);
+	} else {
+		unsigned char disc_param[] = { 0x07 };
+
+		mgmt_send(data->mgmt, MGMT_OP_START_DISCOVERY, data->mgmt_index,
 					sizeof(disc_param), disc_param,
 					setup_discovery_callback, NULL, NULL);
+	}
 
 	if (option_wait_powered)
 		tester_wait(1, NULL, NULL);
@@ -2655,6 +2720,9 @@ int main(int argc, char *argv[])
 	test_bredrle("Stop Discovery - Success 1",
 				&stop_discovery_success_test_1,
 				setup_start_discovery, test_command_generic);
+	test_bredr("Stop Discovery - BR/EDR (Inquiry) Success 1",
+				&stop_discovery_bredr_success_test_1,
+				setup_start_discovery, test_command_generic);
 	test_bredrle("Stop Discovery - Rejected 1",
 				&stop_discovery_rejected_test_1,
 				setup_le_powered, test_command_generic);
-- 
1.7.9.5


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

* [RFC BlueZ 21/35] tools/mgmt-tester: Add support for second controller
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (19 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 20/35] tools/mgmt-tester: Add stop discovery for BR/EDR only Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-19 10:00   ` Johan Hedberg
  2013-06-12 12:57 ` [RFC BlueZ 22/35] tools/mgmt-tester: BR/EDR Start discovery (Device Found) Bruna Moreira
                   ` (14 subsequent siblings)
  35 siblings, 1 reply; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

Add second controller to tester and let a testcase start discovery and
receive Device Found events.
---
 tools/mgmt-tester.c |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 1 deletion(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index cbff775..a27b2e2 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -56,6 +56,8 @@ struct test_data {
 	uint16_t mgmt_index;
 	struct hciemu *hciemu;
 	enum hciemu_type hciemu_type;
+	struct hciemu *hciemu_second;
+	uint16_t mgmt_index_second;
 	int unmet_conditions;
 };
 
@@ -165,6 +167,30 @@ static void read_info_callback(uint8_t status, uint16_t length,
 	tester_pre_setup_complete();
 }
 
+static void setup_powered_callback(uint8_t status, uint16_t length,
+					const void *param, void *user_data);
+
+static void second_powered_discoverable()
+{
+	struct test_data *data = tester_get_data();
+	unsigned char con_param[] = { 0x01 };
+	unsigned char discov_param[] = { 0x01, 0x00, 0x00 };
+
+	tester_print("Enabling connectable, discoverable and powered (second)");
+
+	mgmt_send(data->mgmt, MGMT_OP_SET_CONNECTABLE, data->mgmt_index_second,
+					sizeof(con_param), con_param,
+					NULL, NULL, NULL);
+
+	mgmt_send(data->mgmt, MGMT_OP_SET_DISCOVERABLE, data->mgmt_index_second,
+					sizeof(discov_param), discov_param,
+					NULL, NULL, NULL);
+
+	mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index_second,
+					sizeof(con_param), con_param,
+					setup_powered_callback, NULL, NULL);
+}
+
 static void index_added_callback(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -173,6 +199,12 @@ static void index_added_callback(uint16_t index, uint16_t length,
 	tester_print("Index Added callback");
 	tester_print("  Index: 0x%04x", index);
 
+	if (data->hciemu_second) {
+		data->mgmt_index_second = index;
+		second_powered_discoverable();
+		return;
+	}
+
 	data->mgmt_index = index;
 
 	mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL,
@@ -268,6 +300,12 @@ static void test_post_teardown(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
 
+	if (data->hciemu_second) {
+		hciemu_unref(data->hciemu_second);
+		data->mgmt_index_second = 0xffff;
+		data->hciemu_second = NULL;
+	}
+
 	hciemu_unref(data->hciemu);
 	data->hciemu = NULL;
 }
@@ -299,6 +337,8 @@ static void test_condition_complete(struct test_data *data)
 		if (!user) \
 			break; \
 		user->hciemu_type = HCIEMU_TYPE_BREDRLE; \
+		user->hciemu_second = NULL; \
+		user->mgmt_index_second = 0xffff; \
 		user->test_data = data; \
 		user->expected_version = 0x06; \
 		user->expected_manufacturer = 0x003f; \
@@ -317,6 +357,8 @@ static void test_condition_complete(struct test_data *data)
 		if (!user) \
 			break; \
 		user->hciemu_type = HCIEMU_TYPE_BREDR; \
+		user->hciemu_second = NULL; \
+		user->mgmt_index_second = 0xffff; \
 		user->test_data = data; \
 		user->expected_version = 0x05; \
 		user->expected_manufacturer = 0x003f; \
@@ -335,6 +377,8 @@ static void test_condition_complete(struct test_data *data)
 		if (!user) \
 			break; \
 		user->hciemu_type = HCIEMU_TYPE_LE; \
+		user->hciemu_second = NULL; \
+		user->mgmt_index_second = 0xffff; \
 		user->test_data = data; \
 		user->expected_version = 0x06; \
 		user->expected_manufacturer = 0x003f; \
@@ -1828,6 +1872,27 @@ static void setup_ssp_powered(const void *test_data)
 					setup_powered_callback, NULL, NULL);
 }
 
+static void setup_le_powered_callback(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	struct test_data *data = tester_get_data();
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		tester_setup_failed();
+		return;
+	}
+
+	tester_print("First Controller powered on");
+
+	if (!data->hciemu_second) {
+		if (option_wait_powered)
+			tester_wait(1, powered_delay, NULL);
+		else
+			tester_setup_complete();
+		return;
+	}
+}
+
 static void setup_le_powered(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
@@ -1835,12 +1900,19 @@ static void setup_le_powered(const void *test_data)
 
 	tester_print("Powering on controller (with LE enabled)");
 
+	data->hciemu_second = hciemu_new(data->hciemu_type);
+	if (!data->hciemu_second) {
+		tester_warn("Failed to setup second HCI emulation");
+		tester_setup_failed();
+		return;
+	}
+
 	mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index,
 				sizeof(param), param, NULL, NULL, NULL);
 
 	mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
 					sizeof(param), param,
-					setup_powered_callback, NULL, NULL);
+					setup_le_powered_callback, NULL, NULL);
 }
 
 static void setup_discovery_callback(uint8_t status, uint16_t length,
-- 
1.7.9.5


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

* [RFC BlueZ 22/35] tools/mgmt-tester: BR/EDR Start discovery (Device Found)
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (20 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 21/35] tools/mgmt-tester: Add support for second controller Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 23/35] tools/mgmt-tester: LE only " Bruna Moreira
                   ` (13 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

This test will start an BR/EDR discovery (inquiry) and verifies the
following:
- Inquiry HCI command is received, and
- Device found event is received.
---
 tools/mgmt-tester.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index a27b2e2..d36b50c 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -1116,6 +1116,11 @@ static const char start_discovery_bredrle_param[] = { 0x07 };
 static const char start_discovery_valid_hci[] = { 0x01, 0x01 };
 static const char start_discovery_evt[] = { 0x07, 0x01 };
 static const char start_discovery_le_evt[] = { 0x06, 0x01 };
+static const char start_discovery_inq_param[] = { 0x33, 0x8b, 0x9e, 0x08,
+									0x00 };
+static const char start_device_found_evt[] = { 0x00, 0x00, 0x02, 0x01, 0xaa,
+			0x00, 0x00, 0xc4, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00,
+			0x04, 0x0d, 0x00, 0x00, 0x00, };
 
 static const struct generic_data start_discovery_not_powered_test_1 = {
 	.send_opcode = MGMT_OP_START_DISCOVERY,
@@ -1168,6 +1173,21 @@ static const struct generic_data start_discovery_valid_param_test_2 = {
 	.expect_alt_ev_len = sizeof(start_discovery_le_evt),
 };
 
+static const struct generic_data start_discovery_valid_param_test_3 = {
+	.send_opcode = MGMT_OP_START_DISCOVERY,
+	.send_param = start_discovery_bredr_param,
+	.send_len = sizeof(start_discovery_bredr_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = start_discovery_bredr_param,
+	.expect_len = sizeof(start_discovery_bredr_param),
+	.expect_hci_command = BT_HCI_CMD_INQUIRY,
+	.expect_hci_param = start_discovery_inq_param,
+	.expect_hci_len = sizeof(start_discovery_inq_param),
+	.expect_alt_ev = MGMT_EV_DEVICE_FOUND,
+	.expect_alt_ev_param = start_device_found_evt,
+	.expect_alt_ev_len = sizeof(start_device_found_evt),
+};
+
 static const char stop_discovery_bredrle_param[] = { 0x07 };
 static const char stop_discovery_bredrle_invalid_param[] = { 0x06 };
 static const char stop_discovery_valid_hci[] = { 0x00, 0x00 };
@@ -2788,6 +2808,9 @@ int main(int argc, char *argv[])
 	test_le("Start Discovery - Success 2",
 				&start_discovery_valid_param_test_2,
 				setup_powered, test_command_generic);
+	test_bredr("Start Discovery (Device Found) - Success 3",
+				&start_discovery_valid_param_test_3,
+				setup_le_powered, test_command_generic);
 
 	test_bredrle("Stop Discovery - Success 1",
 				&stop_discovery_success_test_1,
-- 
1.7.9.5


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

* [RFC BlueZ 23/35] tools/mgmt-tester: LE only Start discovery (Device Found)
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (21 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 22/35] tools/mgmt-tester: BR/EDR Start discovery (Device Found) Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 24/35] tools/mgmt-tester: Split test_command_generic() Bruna Moreira
                   ` (12 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

This test will start a LE only discovery and verifies the following:
- LE scan enable command is received, and
- Device found event is received.
---
 tools/mgmt-tester.c |  142 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 139 insertions(+), 3 deletions(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index d36b50c..4bf3235 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -29,6 +29,11 @@
 
 #include <glib.h>
 
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
+#include <bluetooth/l2cap.h>
+
 #include "lib/bluetooth.h"
 #include "lib/mgmt.h"
 
@@ -167,8 +172,118 @@ static void read_info_callback(uint8_t status, uint16_t length,
 	tester_pre_setup_complete();
 }
 
-static void setup_powered_callback(uint8_t status, uint16_t length,
-					const void *param, void *user_data);
+static gboolean received_adv_hci_event(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	char buf[1 + HCI_EVENT_HDR_SIZE + EVT_CMD_COMPLETE_SIZE + 1], *ptr;
+	evt_cmd_complete *cc;
+	hci_event_hdr *hdr;
+	uint8_t status;
+	gsize len;
+
+	if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
+		goto failed;
+
+	if (g_io_channel_read_chars(io, (gchar *) buf, sizeof(buf), &len,
+						NULL) != G_IO_STATUS_NORMAL)
+		goto failed;
+
+	if (len != sizeof(buf))
+		goto failed;
+
+	ptr = buf + 1;
+	hdr = (void *) ptr;
+	if (hdr->evt != EVT_CMD_COMPLETE ||
+					hdr->plen != EVT_CMD_COMPLETE_SIZE + 1)
+		goto failed;
+
+	ptr += HCI_EVENT_HDR_SIZE;
+	cc = (void *) ptr;
+	if (btohs(cc->opcode) != cmd_opcode_pack(OGF_LE_CTL,
+						OCF_LE_SET_ADVERTISE_ENABLE))
+		goto failed;
+
+	ptr += EVT_CMD_COMPLETE_SIZE;
+	status = *ptr;
+	if (status != 0)
+		goto failed;
+
+	tester_setup_complete();
+
+	return FALSE;
+
+failed:
+	tester_setup_failed();
+
+	return FALSE;
+}
+
+static int enable_le_advertising(int hdev)
+{
+	le_set_advertise_enable_cp adv_cp;
+	struct hci_filter nf;
+	GIOChannel *channel;
+	uint16_t opcode;
+	int dd;
+
+	dd = hci_open_dev(hdev);
+	if (dd < 0) {
+		tester_warn("Could not open device");
+		return -1;
+	}
+
+	hci_filter_clear(&nf);
+	hci_filter_set_ptype(HCI_EVENT_PKT, &nf);
+	hci_filter_set_event(EVT_CMD_COMPLETE, &nf);
+	opcode = htobs(cmd_opcode_pack(OGF_LE_CTL,
+						OCF_LE_SET_ADVERTISE_ENABLE));
+	hci_filter_set_opcode(opcode, &nf);
+	if (setsockopt(dd, SOL_HCI, HCI_FILTER, &nf, sizeof(nf)) < 0) {
+		tester_warn("Error setting the socket filter");
+		return -1;
+	}
+
+	channel = g_io_channel_unix_new(dd);
+	g_io_channel_set_close_on_unref(channel, TRUE);
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				received_adv_hci_event, NULL, NULL);
+
+	g_io_channel_unref(channel);
+
+	adv_cp.enable = 0x01;
+	if (hci_send_cmd(dd, OGF_LE_CTL, OCF_LE_SET_ADVERTISE_ENABLE,
+						sizeof(adv_cp), &adv_cp) < 0) {
+		tester_warn("Error sending LE ADV Enable command");
+		return -1;
+	}
+
+	return 0;
+}
+
+static void setup_adv_powered_callback(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	struct test_data *data = tester_get_data();
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		tester_setup_failed();
+		return;
+	}
+
+	tester_print("Controller powered on");
+
+	if (data->hciemu_type == HCIEMU_TYPE_BREDR) {
+		tester_setup_complete();
+		return;
+	}
+
+	if (enable_le_advertising(data->mgmt_index_second) < 0)
+		tester_setup_failed();
+}
 
 static void second_powered_discoverable()
 {
@@ -188,7 +303,7 @@ static void second_powered_discoverable()
 
 	mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index_second,
 					sizeof(con_param), con_param,
-					setup_powered_callback, NULL, NULL);
+					setup_adv_powered_callback, NULL, NULL);
 }
 
 static void index_added_callback(uint16_t index, uint16_t length,
@@ -1121,6 +1236,9 @@ static const char start_discovery_inq_param[] = { 0x33, 0x8b, 0x9e, 0x08,
 static const char start_device_found_evt[] = { 0x00, 0x00, 0x02, 0x01, 0xaa,
 			0x00, 0x00, 0xc4, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00,
 			0x04, 0x0d, 0x00, 0x00, 0x00, };
+static const char start_le_device_found_evt[] = { 0x00, 0x00, 0x02, 0x01, 0xaa,
+			0x00, 0x01, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
+			0x02, 0x01, 0x06, 0x02, 0x0a, 0x00, };
 
 static const struct generic_data start_discovery_not_powered_test_1 = {
 	.send_opcode = MGMT_OP_START_DISCOVERY,
@@ -1188,6 +1306,21 @@ static const struct generic_data start_discovery_valid_param_test_3 = {
 	.expect_alt_ev_len = sizeof(start_device_found_evt),
 };
 
+static const struct generic_data start_discovery_valid_param_test_4 = {
+	.send_opcode = MGMT_OP_START_DISCOVERY,
+	.send_param = start_discovery_le_param,
+	.send_len = sizeof(start_discovery_le_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = start_discovery_le_param,
+	.expect_len = sizeof(start_discovery_le_param),
+	.expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_ENABLE,
+	.expect_hci_param = start_discovery_valid_hci,
+	.expect_hci_len = sizeof(start_discovery_valid_hci),
+	.expect_alt_ev = MGMT_EV_DEVICE_FOUND,
+	.expect_alt_ev_param = start_le_device_found_evt,
+	.expect_alt_ev_len = sizeof(start_le_device_found_evt),
+};
+
 static const char stop_discovery_bredrle_param[] = { 0x07 };
 static const char stop_discovery_bredrle_invalid_param[] = { 0x06 };
 static const char stop_discovery_valid_hci[] = { 0x00, 0x00 };
@@ -2811,6 +2944,9 @@ int main(int argc, char *argv[])
 	test_bredr("Start Discovery (Device Found) - Success 3",
 				&start_discovery_valid_param_test_3,
 				setup_le_powered, test_command_generic);
+	test_le("Start Discovery (Device Found) - Success 4",
+				&start_discovery_valid_param_test_4,
+				setup_le_powered, test_command_generic);
 
 	test_bredrle("Stop Discovery - Success 1",
 				&stop_discovery_success_test_1,
-- 
1.7.9.5


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

* [RFC BlueZ 24/35] tools/mgmt-tester: Split test_command_generic()
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (22 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 23/35] tools/mgmt-tester: LE only " Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 25/35] tools/mgmt-tester: BR/EDR Stop discovery (Device Found) Bruna Moreira
                   ` (11 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

The test_command_generic() was split in two parts to use the new
setup_test_command_generic() function in next tests.
---
 tools/mgmt-tester.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 4bf3235..313feff 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -2618,7 +2618,7 @@ static bool command_hci_callback(uint16_t opcode, const void *param,
 	return true;
 }
 
-static void test_command_generic(const void *test_data)
+static void setup_test_command_generic(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
 	const struct generic_data *test = data->test_data;
@@ -2655,6 +2655,17 @@ static void test_command_generic(const void *test_data)
 						command_hci_callback, data);
 		test_add_condition(data);
 	}
+}
+
+static void test_command_generic(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+	uint16_t index;
+
+	index = test->send_index_none ? MGMT_INDEX_NONE : data->mgmt_index;
+
+	setup_test_command_generic(test_data);
 
 	tester_print("Sending command 0x%04x", test->send_opcode);
 
-- 
1.7.9.5


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

* [RFC BlueZ 25/35] tools/mgmt-tester: BR/EDR Stop discovery (Device Found)
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (23 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 24/35] tools/mgmt-tester: Split test_command_generic() Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 26/35] btdev: Add function to send an aborted packet Bruna Moreira
                   ` (10 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

This test will check the stop BR/EDR discovery (inquiry). For this, it
verifies the following:
- Inquiry HCI command is received,
- Device found event is received, and
- Stop discovery is succeed.
---
 tools/mgmt-tester.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 113 insertions(+), 2 deletions(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 313feff..d53f94e 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -514,6 +514,7 @@ struct generic_data {
 	uint16_t setup_expect_hci_command;
 	const void *setup_expect_hci_param;
 	uint8_t setup_expect_hci_len;
+	uint16_t block_hci_command;
 	bool send_index_none;
 	uint16_t send_opcode;
 	const void *send_param;
@@ -1328,6 +1329,9 @@ static const char stop_discovery_evt[] = { 0x07, 0x00 };
 static const char stop_discovery_bredr_param[] = { 0x01 };
 static const char stop_discovery_bredr_discovering[] = { 0x01, 0x00 };
 static const char stop_discovery_inq_param[] = { 0x33, 0x8b, 0x9e, 0x08, 0x00 };
+static const char stop_device_found_bredr_evt[] = { 0x00, 0x00, 0x02, 0x01,
+			0xaa, 0x00, 0x00, 0xc4, 0x03, 0x00, 0x00, 0x00, 0x05,
+			0x00, 0x04, 0x0d, 0x00, 0x00, 0x00, };
 
 static const struct generic_data stop_discovery_success_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
@@ -1360,6 +1364,23 @@ static const struct generic_data stop_discovery_bredr_success_test_1 = {
 	.expect_alt_ev_len = sizeof(stop_discovery_bredr_discovering),
 };
 
+static const struct generic_data stop_discovery_bredr_success_test_2 = {
+	.setup_expect_hci_command = BT_HCI_CMD_INQUIRY,
+	.setup_expect_hci_param = stop_discovery_inq_param,
+	.setup_expect_hci_len = sizeof(stop_discovery_inq_param),
+	.block_hci_command = BT_HCI_EVT_INQUIRY_COMPLETE,
+	.send_opcode = MGMT_OP_STOP_DISCOVERY,
+	.send_param = stop_discovery_bredr_param,
+	.send_len = sizeof(stop_discovery_bredr_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = stop_discovery_bredr_param,
+	.expect_len = sizeof(stop_discovery_bredr_param),
+	.expect_hci_command = BT_HCI_CMD_INQUIRY_CANCEL,
+	.expect_alt_ev = MGMT_EV_DEVICE_FOUND,
+	.expect_alt_ev_param = stop_device_found_bredr_evt,
+	.expect_alt_ev_len = sizeof(stop_device_found_bredr_evt),
+};
+
 static const struct generic_data stop_discovery_rejected_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
 	.send_param = stop_discovery_bredrle_param,
@@ -2085,6 +2106,7 @@ static bool setup_command_hci_callback(const void *data, uint16_t len,
 {
 	struct test_data *tdata = tester_get_data();
 	const struct generic_data *test = tdata->test_data;
+	bool *is_setup = user_data;
 
 	tester_print("HCI Command 0x%04x length %u (setup)",
 					test->setup_expect_hci_command, len);
@@ -2101,7 +2123,14 @@ static bool setup_command_hci_callback(const void *data, uint16_t len,
 		goto done;
 	}
 
-	tester_setup_complete();
+	if (is_setup && *is_setup)
+		tester_setup_complete();
+	else {
+		test_condition_complete(tdata);
+		hciemu_del_hook(tdata->hciemu, HCIEMU_HOOK_PRE_EVT,
+					test->setup_expect_hci_command);
+		return true;
+	}
 
 done:
 	hciemu_del_hook(tdata->hciemu, HCIEMU_HOOK_PRE_EVT,
@@ -2124,11 +2153,13 @@ static void setup_start_discovery_callback(uint8_t status, uint16_t length,
 	tester_print("Controller powered on");
 
 	if (test->setup_expect_hci_command) {
+		static bool is_setup = true;
+
 		tester_print("Registering HCI command callback (setup)");
 		hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT,
 				test->setup_expect_hci_command,
 				setup_command_hci_callback,
-				NULL);
+				&is_setup);
 		mgmt_send(data->mgmt, MGMT_OP_START_DISCOVERY, data->mgmt_index,
 				test->send_len, test->send_param,
 				NULL, NULL, NULL);
@@ -2675,6 +2706,83 @@ static void test_command_generic(const void *test_data)
 	test_add_condition(data);
 }
 
+static bool stop_command_hci_callback(const void *data, uint16_t len,
+								void *user_data)
+{
+	struct test_data *tdata = tester_get_data();
+	const struct generic_data *test = tdata->test_data;
+
+	tester_print("Interrupt HCI Command 0x%04x length %u",
+						test->block_hci_command, len);
+
+	test_condition_complete(tdata);
+
+	hciemu_del_hook(tdata->hciemu, HCIEMU_HOOK_POST_EVT,
+						test->block_hci_command);
+
+	return false;
+}
+
+static void start_discovery_callback(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		tester_warn("Error starting discovery");
+		tester_test_failed();
+		return;
+	}
+
+	tester_print("Discovery started");
+
+	tester_print("Sending command 0x%04x", test->send_opcode);
+	mgmt_send(data->mgmt, test->send_opcode, data->mgmt_index,
+					test->send_len, test->send_param,
+					command_generic_callback, NULL, NULL);
+	test_add_condition(data);
+}
+
+static void hook_stop_hci_command(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+
+	if (test->block_hci_command) {
+		tester_print("Registering hook to stop HCI command 0x%04x",
+						test->block_hci_command);
+		hciemu_add_hook(data->hciemu, HCIEMU_HOOK_POST_EVT,
+				test->block_hci_command,
+				stop_command_hci_callback,
+				NULL);
+		test_add_condition(data);
+	}
+}
+
+static void test_command_start_discovery(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+	uint16_t index;
+
+	index = test->send_index_none ? MGMT_INDEX_NONE : data->mgmt_index;
+
+	setup_test_command_generic(test_data);
+
+	tester_print("Registering HCI command callback (second)");
+	hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT,
+			test->setup_expect_hci_command,
+			setup_command_hci_callback,
+			NULL);
+	test_add_condition(data);
+
+	hook_stop_hci_command(test_data);
+
+	mgmt_send(data->mgmt, MGMT_OP_START_DISCOVERY, index, test->send_len,
+			test->send_param, start_discovery_callback, NULL, NULL);
+}
+
 static GOptionEntry options[] = {
 	{ "wait-powered", 'P', 0, G_OPTION_ARG_NONE, &option_wait_powered,
 					"Add a delay after powering on" },
@@ -2965,6 +3073,9 @@ int main(int argc, char *argv[])
 	test_bredr("Stop Discovery - BR/EDR (Inquiry) Success 1",
 				&stop_discovery_bredr_success_test_1,
 				setup_start_discovery, test_command_generic);
+	test_bredr("Stop Discovery (Device Found) - Success 2",
+				&stop_discovery_bredr_success_test_2,
+				setup_le_powered, test_command_start_discovery);
 	test_bredrle("Stop Discovery - Rejected 1",
 				&stop_discovery_rejected_test_1,
 				setup_le_powered, test_command_generic);
-- 
1.7.9.5


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

* [RFC BlueZ 26/35] btdev: Add function to send an aborted packet
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (24 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 25/35] tools/mgmt-tester: BR/EDR Stop discovery (Device Found) Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 27/35] emulator: Fix Remote Name Request Cancel command complete Bruna Moreira
                   ` (9 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

After running a hook, it is possible to ignore a packet in this moment
for sending the same packet later.
---
 emulator/btdev.c    |   14 ++++++++++++++
 emulator/btdev.h    |    2 ++
 src/shared/hciemu.c |    5 +++++
 src/shared/hciemu.h |    2 ++
 4 files changed, 23 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index e70ad19..6d71ce2 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -107,6 +107,9 @@ struct btdev {
 	uint16_t sync_train_interval;
 	uint32_t sync_train_timeout;
 	uint8_t  sync_train_service_data;
+
+	uint8_t dropped_pkt_data[255];
+	uint16_t dropped_pkt_len;
 };
 
 #define MAX_BTDEV_ENTRIES 16
@@ -647,6 +650,10 @@ static void send_event(struct btdev *btdev, uint8_t event,
 
 	if (run_hooks(btdev, BTDEV_HOOK_POST_EVT, event, pkt_data, pkt_len))
 		send_packet(btdev, pkt_data, pkt_len);
+	else {
+		memcpy(btdev->dropped_pkt_data, pkt_data, pkt_len);
+		btdev->dropped_pkt_len = pkt_len;
+	}
 
 	free(pkt_data);
 }
@@ -2027,3 +2034,10 @@ bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
 
 	return false;
 }
+
+void btdev_send_packet(struct btdev *btdev)
+{
+	if (btdev->dropped_pkt_len)
+		send_packet(btdev, btdev->dropped_pkt_data,
+							btdev->dropped_pkt_len);
+}
diff --git a/emulator/btdev.h b/emulator/btdev.h
index 5118a4a..c1cf882 100644
--- a/emulator/btdev.h
+++ b/emulator/btdev.h
@@ -92,3 +92,5 @@ int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
 
 bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
 							uint16_t opcode);
+
+void btdev_send_packet(struct btdev *btdev);
diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
index 0bbaa09..d36639f 100644
--- a/src/shared/hciemu.c
+++ b/src/shared/hciemu.c
@@ -463,3 +463,8 @@ bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
 
 	return btdev_del_hook(hciemu->master_dev, hook_type, opcode);
 }
+
+void hciemu_send_packet(struct hciemu *hciemu)
+{
+	btdev_send_packet(hciemu->master_dev);
+}
diff --git a/src/shared/hciemu.h b/src/shared/hciemu.h
index 2abf404..5b23a0b 100644
--- a/src/shared/hciemu.h
+++ b/src/shared/hciemu.h
@@ -65,3 +65,5 @@ int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
 
 bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
 							uint16_t opcode);
+
+void hciemu_send_packet(struct hciemu *hciemu);
-- 
1.7.9.5


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

* [RFC BlueZ 27/35] emulator: Fix Remote Name Request Cancel command complete
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (25 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 26/35] btdev: Add function to send an aborted packet Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 28/35] tools/mgmt-tester: Move command_generic_callback() Bruna Moreira
                   ` (8 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

From: Anderson Lizardo <anderson.lizardo@openbossa.org>

The Command Complete event for this HCI command contains two parameters,
status and bd_addr.
---
 emulator/btdev.c |    8 ++++++--
 monitor/bt.h     |    4 ++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 6d71ce2..2e099b9 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1093,6 +1093,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	const struct bt_hci_cmd_le_set_adv_enable *lsae;
 	const struct bt_hci_cmd_le_set_scan_enable *lsse;
 	const struct bt_hci_cmd_le_create_conn *lcc;
+	const struct bt_hci_cmd_remote_name_request_cancel *rnrc_cmd;
 	struct bt_hci_rsp_read_default_link_policy rdlp;
 	struct bt_hci_rsp_read_stored_link_key rslk;
 	struct bt_hci_rsp_write_stored_link_key wslk;
@@ -1127,6 +1128,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	struct bt_hci_rsp_le_read_adv_tx_power lratp;
 	struct bt_hci_rsp_le_read_supported_states lrss;
 	struct bt_hci_rsp_le_read_white_list_size lrwls;
+	struct bt_hci_rsp_remote_name_request_cancel rnrc;
 	uint8_t status, page;
 
 	switch (opcode) {
@@ -1180,8 +1182,10 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 	case BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL:
 		if (btdev->type == BTDEV_TYPE_LE)
 			goto unsupported;
-		status = BT_HCI_ERR_SUCCESS;
-		cmd_complete(btdev, opcode, &status, sizeof(status));
+		rnrc_cmd = data;
+		rnrc.status = BT_HCI_ERR_SUCCESS;
+		memcpy(rnrc.bdaddr, rnrc_cmd->bdaddr, 6);
+		cmd_complete(btdev, opcode, &rnrc, sizeof(rnrc));
 		break;
 
 	case BT_HCI_CMD_READ_REMOTE_FEATURES:
diff --git a/monitor/bt.h b/monitor/bt.h
index e900525..0f1c1d8 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -167,6 +167,10 @@ struct bt_hci_cmd_remote_name_request {
 struct bt_hci_cmd_remote_name_request_cancel {
 	uint8_t  bdaddr[6];
 } __attribute__ ((packed));
+struct bt_hci_rsp_remote_name_request_cancel {
+	uint8_t  status;
+	uint8_t  bdaddr[6];
+} __attribute__ ((packed));
 
 #define BT_HCI_CMD_READ_REMOTE_FEATURES		0x041b
 struct bt_hci_cmd_read_remote_features {
-- 
1.7.9.5


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

* [RFC BlueZ 28/35] tools/mgmt-tester: Move command_generic_callback()
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (26 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 27/35] emulator: Fix Remote Name Request Cancel command complete Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 29/35] tools/mgmt-tester: BR/EDR Stop discovery (Name Resolving) Bruna Moreira
                   ` (7 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

Rearrange command_generic_callback() position to avoid fast forward
declaration in next patch.
---
 tools/mgmt-tester.c |   56 +++++++++++++++++++++++++--------------------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index d53f94e..64f18c1 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -2565,34 +2565,6 @@ done:
 	test_condition_complete(data);
 }
 
-static void command_generic_event_alt(uint16_t index, uint16_t length,
-							const void *param,
-							void *user_data)
-{
-	struct test_data *data = tester_get_data();
-	const struct generic_data *test = data->test_data;
-
-	if (length != test->expect_alt_ev_len) {
-		tester_warn("Invalid length %s event",
-					mgmt_evstr(test->expect_alt_ev));
-		tester_test_failed();
-		return;
-	}
-
-	tester_print("New %s event received", mgmt_evstr(test->expect_alt_ev));
-
-	if (memcmp(param, test->expect_alt_ev_param,
-						test->expect_alt_ev_len) != 0)
-		return;
-
-	tester_print("Unregistering %s notification",
-					mgmt_evstr(test->expect_alt_ev));
-
-	mgmt_unregister(data->mgmt_alt, data->mgmt_alt_ev_id);
-
-	test_condition_complete(data);
-}
-
 static void command_generic_callback(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -2621,6 +2593,34 @@ static void command_generic_callback(uint8_t status, uint16_t length,
 	test_condition_complete(data);
 }
 
+static void command_generic_event_alt(uint16_t index, uint16_t length,
+							const void *param,
+							void *user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+
+	if (length != test->expect_alt_ev_len) {
+		tester_warn("Invalid length %s event",
+					mgmt_evstr(test->expect_alt_ev));
+		tester_test_failed();
+		return;
+	}
+
+	tester_print("New %s event received", mgmt_evstr(test->expect_alt_ev));
+
+	if (memcmp(param, test->expect_alt_ev_param,
+						test->expect_alt_ev_len) != 0)
+		return;
+
+	tester_print("Unregistering %s notification",
+					mgmt_evstr(test->expect_alt_ev));
+
+	mgmt_unregister(data->mgmt_alt, data->mgmt_alt_ev_id);
+
+	test_condition_complete(data);
+}
+
 static bool command_hci_callback(uint16_t opcode, const void *param,
 					uint8_t length, void *user_data)
 {
-- 
1.7.9.5


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

* [RFC BlueZ 29/35] tools/mgmt-tester: BR/EDR Stop discovery (Name Resolving)
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (27 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 28/35] tools/mgmt-tester: Move command_generic_callback() Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 30/35] tools/mgmt-tester: Add support to set emulator type Bruna Moreira
                   ` (6 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

This test will check the stop BR/EDR discovery during name resolving
operation. For this, it verifies the following:
- Inquiry HCI command is received,
- Device found event is received,
- Remote name request cancel is received, and
- Stop discovery is succeed.
---
 tools/mgmt-tester.c |   97 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 3 deletions(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 64f18c1..da05b4f 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -1332,6 +1332,8 @@ static const char stop_discovery_inq_param[] = { 0x33, 0x8b, 0x9e, 0x08, 0x00 };
 static const char stop_device_found_bredr_evt[] = { 0x00, 0x00, 0x02, 0x01,
 			0xaa, 0x00, 0x00, 0xc4, 0x03, 0x00, 0x00, 0x00, 0x05,
 			0x00, 0x04, 0x0d, 0x00, 0x00, 0x00, };
+static const char stop_remote_name_valid_hci[] = { 0x00, 0x00, 0x02, 0x01, 0xaa,
+			0x00 };
 
 static const struct generic_data stop_discovery_success_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
@@ -1381,6 +1383,25 @@ static const struct generic_data stop_discovery_bredr_success_test_2 = {
 	.expect_alt_ev_len = sizeof(stop_device_found_bredr_evt),
 };
 
+static const struct generic_data stop_discovery_bredr_success_test_3 = {
+	.setup_expect_hci_command = BT_HCI_CMD_INQUIRY,
+	.setup_expect_hci_param = stop_discovery_inq_param,
+	.setup_expect_hci_len = sizeof(stop_discovery_inq_param),
+	.block_hci_command = BT_HCI_EVT_INQUIRY_COMPLETE,
+	.send_opcode = MGMT_OP_STOP_DISCOVERY,
+	.send_param = stop_discovery_bredr_param,
+	.send_len = sizeof(stop_discovery_bredr_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = stop_discovery_bredr_param,
+	.expect_len = sizeof(stop_discovery_bredr_param),
+	.expect_hci_command = BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL,
+	.expect_hci_param = stop_remote_name_valid_hci,
+	.expect_hci_len = sizeof(stop_remote_name_valid_hci),
+	.expect_alt_ev = MGMT_EV_DEVICE_FOUND,
+	.expect_alt_ev_param = stop_device_found_bredr_evt,
+	.expect_alt_ev_len = sizeof(stop_device_found_bredr_evt),
+};
+
 static const struct generic_data stop_discovery_rejected_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
 	.send_param = stop_discovery_bredrle_param,
@@ -2593,6 +2614,65 @@ static void command_generic_callback(uint8_t status, uint16_t length,
 	test_condition_complete(data);
 }
 
+static bool block_name_complete_callback(const void *data, uint16_t len,
+								void *user_data)
+{
+	struct test_data *tdata = tester_get_data();
+
+	tester_print("Interrupt HCI Command 0x%04x length %u",
+				BT_HCI_EVT_REMOTE_NAME_REQUEST_COMPLETE, len);
+
+	hciemu_del_hook(tdata->hciemu, HCIEMU_HOOK_POST_EVT,
+				BT_HCI_EVT_REMOTE_NAME_REQUEST_COMPLETE);
+
+	return false;
+}
+
+static void confirm_name_callback(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		tester_warn("Error sending confirm name, status 0x%02x",
+									status);
+		tester_test_failed();
+		return;
+	}
+
+	tester_print("Confirm name sent status %u", status);
+
+	tester_print("Registering hook to stop HCI command 0x%04x",
+				BT_HCI_EVT_REMOTE_NAME_REQUEST_COMPLETE);
+	hciemu_add_hook(data->hciemu, HCIEMU_HOOK_POST_EVT,
+			BT_HCI_EVT_REMOTE_NAME_REQUEST_COMPLETE,
+			block_name_complete_callback,
+			NULL);
+
+	hciemu_send_packet(data->hciemu);
+
+	tester_print("Sending command 0x%04x", test->send_opcode);
+
+	mgmt_send(data->mgmt, test->send_opcode, data->mgmt_index,
+					test->send_len, test->send_param,
+					command_generic_callback, NULL, NULL);
+	test_add_condition(data);
+}
+
+static void send_confirm_name()
+{
+	struct test_data *tdata = tester_get_data();
+	const char param[] = { 0x00, 0x00, 0x02, 0x01, 0xaa, 0x00, 0x00, 0x00 };
+
+	tester_print("Send confirm name");
+	mgmt_reply(tdata->mgmt, MGMT_OP_CONFIRM_NAME, tdata->mgmt_index,
+					sizeof(param), param,
+					confirm_name_callback, NULL, NULL);
+
+	test_condition_complete(tdata);
+}
+
 static void command_generic_event_alt(uint16_t index, uint16_t length,
 							const void *param,
 							void *user_data)
@@ -2616,6 +2696,11 @@ static void command_generic_event_alt(uint16_t index, uint16_t length,
 	tester_print("Unregistering %s notification",
 					mgmt_evstr(test->expect_alt_ev));
 
+	if (test->expect_hci_command == BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL) {
+		test_add_condition(data);
+		send_confirm_name();
+	}
+
 	mgmt_unregister(data->mgmt_alt, data->mgmt_alt_ev_id);
 
 	test_condition_complete(data);
@@ -2737,11 +2822,14 @@ static void start_discovery_callback(uint8_t status, uint16_t length,
 
 	tester_print("Discovery started");
 
-	tester_print("Sending command 0x%04x", test->send_opcode);
-	mgmt_send(data->mgmt, test->send_opcode, data->mgmt_index,
+	if (test->expect_hci_command != BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL) {
+		tester_print("Sending command 0x%04x", test->send_opcode);
+
+		mgmt_send(data->mgmt, test->send_opcode, data->mgmt_index,
 					test->send_len, test->send_param,
 					command_generic_callback, NULL, NULL);
-	test_add_condition(data);
+		test_add_condition(data);
+	}
 }
 
 static void hook_stop_hci_command(const void *test_data)
@@ -3076,6 +3164,9 @@ int main(int argc, char *argv[])
 	test_bredr("Stop Discovery (Device Found) - Success 2",
 				&stop_discovery_bredr_success_test_2,
 				setup_le_powered, test_command_start_discovery);
+	test_bredr("Stop Discovery (Name Resolving) - Success 3",
+				&stop_discovery_bredr_success_test_3,
+				setup_le_powered, test_command_start_discovery);
 	test_bredrle("Stop Discovery - Rejected 1",
 				&stop_discovery_rejected_test_1,
 				setup_le_powered, test_command_generic);
-- 
1.7.9.5


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

* [RFC BlueZ 30/35] tools/mgmt-tester: Add support to set emulator type
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (28 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 29/35] tools/mgmt-tester: BR/EDR Stop discovery (Name Resolving) Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 31/35] tools/mgmt-tester: LE Stop discovery (Device Found) Bruna Moreira
                   ` (5 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

It was added a field in struct generic_data to let the tester chooses
the type of second emulator. The default value is a dual mode
controller.

Note: If the tester needs a specific controller type (value different of
dual mode) is mandatory to set hciemu_type_second value in test struct.
---
 tools/mgmt-tester.c |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index da05b4f..bfcf9b5 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -62,6 +62,7 @@ struct test_data {
 	struct hciemu *hciemu;
 	enum hciemu_type hciemu_type;
 	struct hciemu *hciemu_second;
+	enum hciemu_type hciemu_type_second;
 	uint16_t mgmt_index_second;
 	int unmet_conditions;
 };
@@ -276,7 +277,7 @@ static void setup_adv_powered_callback(uint8_t status, uint16_t length,
 
 	tester_print("Controller powered on");
 
-	if (data->hciemu_type == HCIEMU_TYPE_BREDR) {
+	if (data->hciemu_type_second == HCIEMU_TYPE_BREDR) {
 		tester_setup_complete();
 		return;
 	}
@@ -289,7 +290,6 @@ static void second_powered_discoverable()
 {
 	struct test_data *data = tester_get_data();
 	unsigned char con_param[] = { 0x01 };
-	unsigned char discov_param[] = { 0x01, 0x00, 0x00 };
 
 	tester_print("Enabling connectable, discoverable and powered (second)");
 
@@ -297,9 +297,13 @@ static void second_powered_discoverable()
 					sizeof(con_param), con_param,
 					NULL, NULL, NULL);
 
-	mgmt_send(data->mgmt, MGMT_OP_SET_DISCOVERABLE, data->mgmt_index_second,
-					sizeof(discov_param), discov_param,
-					NULL, NULL, NULL);
+	if (data->hciemu_type_second == HCIEMU_TYPE_BREDR) {
+		unsigned char discov_param[] = { 0x01, 0x00, 0x00 };
+
+		mgmt_send(data->mgmt, MGMT_OP_SET_DISCOVERABLE,
+				data->mgmt_index_second, sizeof(discov_param),
+				discov_param, NULL, NULL, NULL);
+	}
 
 	mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index_second,
 					sizeof(con_param), con_param,
@@ -515,6 +519,7 @@ struct generic_data {
 	const void *setup_expect_hci_param;
 	uint8_t setup_expect_hci_len;
 	uint16_t block_hci_command;
+	enum hciemu_type hciemu_type_second;
 	bool send_index_none;
 	uint16_t send_opcode;
 	const void *send_param;
@@ -1308,6 +1313,7 @@ static const struct generic_data start_discovery_valid_param_test_3 = {
 };
 
 static const struct generic_data start_discovery_valid_param_test_4 = {
+	.hciemu_type_second = HCIEMU_TYPE_LE,
 	.send_opcode = MGMT_OP_START_DISCOVERY,
 	.send_param = start_discovery_le_param,
 	.send_len = sizeof(start_discovery_le_param),
@@ -2091,11 +2097,13 @@ static void setup_le_powered_callback(uint8_t status, uint16_t length,
 static void setup_le_powered(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
 	unsigned char param[] = { 0x01 };
 
 	tester_print("Powering on controller (with LE enabled)");
 
-	data->hciemu_second = hciemu_new(data->hciemu_type);
+	data->hciemu_type_second = test->hciemu_type_second;
+	data->hciemu_second = hciemu_new(data->hciemu_type_second);
 	if (!data->hciemu_second) {
 		tester_warn("Failed to setup second HCI emulation");
 		tester_setup_failed();
-- 
1.7.9.5


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

* [RFC BlueZ 31/35] tools/mgmt-tester: LE Stop discovery (Device Found)
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (29 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 30/35] tools/mgmt-tester: Add support to set emulator type Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 32/35] tools/mgmt-tester: Interleaved stop discovery (LE dev. found) Bruna Moreira
                   ` (4 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Eder Ruiz Maria

From: Eder Ruiz Maria <eder.ruiz@openbossa.org>

This test will check the stop LE discovery (scan enable). For this, it
verifies the following:
- LE Set Scan Enable HCI command is received,
- Device found event is received, and
- Stop discovery is succeed.
---
 tools/mgmt-tester.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index bfcf9b5..46ab3b0 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -1333,6 +1333,7 @@ static const char stop_discovery_bredrle_invalid_param[] = { 0x06 };
 static const char stop_discovery_valid_hci[] = { 0x00, 0x00 };
 static const char stop_discovery_evt[] = { 0x07, 0x00 };
 static const char stop_discovery_bredr_param[] = { 0x01 };
+static const char stop_discovery_le_param[] = { 0x06 };
 static const char stop_discovery_bredr_discovering[] = { 0x01, 0x00 };
 static const char stop_discovery_inq_param[] = { 0x33, 0x8b, 0x9e, 0x08, 0x00 };
 static const char stop_device_found_bredr_evt[] = { 0x00, 0x00, 0x02, 0x01,
@@ -1408,6 +1409,22 @@ static const struct generic_data stop_discovery_bredr_success_test_3 = {
 	.expect_alt_ev_len = sizeof(stop_device_found_bredr_evt),
 };
 
+static const struct generic_data stop_discovery_le_sucess_test_4 = {
+	.hciemu_type_second = HCIEMU_TYPE_LE,
+	.setup_expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_ENABLE,
+	.setup_expect_hci_param = start_discovery_valid_hci,
+	.setup_expect_hci_len = sizeof(start_discovery_valid_hci),
+	.send_opcode = MGMT_OP_STOP_DISCOVERY,
+	.send_param = stop_discovery_le_param,
+	.send_len = sizeof(stop_discovery_le_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = stop_discovery_le_param,
+	.expect_len = sizeof(stop_discovery_le_param),
+	.expect_alt_ev = MGMT_EV_DEVICE_FOUND,
+	.expect_alt_ev_param = start_le_device_found_evt,
+	.expect_alt_ev_len = sizeof(start_le_device_found_evt),
+};
+
 static const struct generic_data stop_discovery_rejected_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
 	.send_param = stop_discovery_bredrle_param,
@@ -3175,6 +3192,9 @@ int main(int argc, char *argv[])
 	test_bredr("Stop Discovery (Name Resolving) - Success 3",
 				&stop_discovery_bredr_success_test_3,
 				setup_le_powered, test_command_start_discovery);
+	test_le("Stop Discovery (Device Found) - Success 4",
+				&stop_discovery_le_sucess_test_4,
+				setup_le_powered, test_command_start_discovery);
 	test_bredrle("Stop Discovery - Rejected 1",
 				&stop_discovery_rejected_test_1,
 				setup_le_powered, test_command_generic);
-- 
1.7.9.5


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

* [RFC BlueZ 32/35] tools/mgmt-tester: Interleaved stop discovery (LE dev. found)
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (30 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 31/35] tools/mgmt-tester: LE Stop discovery (Device Found) Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 33/35] tools/mgmt-tester: Increase timeout for dual mode controller Bruna Moreira
                   ` (3 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

This test will check the stop interleaved discovery during LE scanning.
For this, it it verifies the following:
- LE Set Scan Enable HCI command is received,
- Device found event (with LE device) is received, and
- Stop discovery is succeed.
---
 tools/mgmt-tester.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 46ab3b0..150c76f 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -1425,6 +1425,22 @@ static const struct generic_data stop_discovery_le_sucess_test_4 = {
 	.expect_alt_ev_len = sizeof(start_le_device_found_evt),
 };
 
+static const struct generic_data stop_discovery_bredrle_success_test_5 = {
+	.hciemu_type_second = HCIEMU_TYPE_LE,
+	.setup_expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_ENABLE,
+	.setup_expect_hci_param = start_discovery_valid_hci,
+	.setup_expect_hci_len = sizeof(start_discovery_valid_hci),
+	.send_opcode = MGMT_OP_STOP_DISCOVERY,
+	.send_param = stop_discovery_bredrle_param,
+	.send_len = sizeof(stop_discovery_bredrle_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = stop_discovery_bredrle_param,
+	.expect_len = sizeof(stop_discovery_bredrle_param),
+	.expect_alt_ev = MGMT_EV_DEVICE_FOUND,
+	.expect_alt_ev_param = start_le_device_found_evt,
+	.expect_alt_ev_len = sizeof(start_le_device_found_evt),
+};
+
 static const struct generic_data stop_discovery_rejected_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
 	.send_param = stop_discovery_bredrle_param,
@@ -3195,6 +3211,9 @@ int main(int argc, char *argv[])
 	test_le("Stop Discovery (Device Found) - Success 4",
 				&stop_discovery_le_sucess_test_4,
 				setup_le_powered, test_command_start_discovery);
+	test_bredrle("Stop discovery (Device Found) - Success 5",
+				&stop_discovery_bredrle_success_test_5,
+				setup_le_powered, test_command_start_discovery);
 	test_bredrle("Stop Discovery - Rejected 1",
 				&stop_discovery_rejected_test_1,
 				setup_le_powered, test_command_generic);
-- 
1.7.9.5


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

* [RFC BlueZ 33/35] tools/mgmt-tester: Increase timeout for dual mode controller
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (31 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 32/35] tools/mgmt-tester: Interleaved stop discovery (LE dev. found) Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 34/35] tools/mgmt-tester: Interleaved stop discovery (BR/EDR dev. found) Bruna Moreira
                   ` (2 subsequent siblings)
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

It is need increase the test timeout to let the interleaved discovery
running until the end because LE scanning is controlled by kernel
running about 5 seconds before calling inquiry.
---
 tools/mgmt-tester.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 150c76f..92ae2ea 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -466,7 +466,7 @@ static void test_condition_complete(struct test_data *data)
 		user->unmet_conditions = 0; \
 		tester_add_full(name, data, \
 				test_pre_setup, setup, func, NULL, \
-				test_post_teardown, 2, user, free); \
+				test_post_teardown, 6, user, free); \
 	} while (0)
 
 #define test_bredr(name, data, setup, func) \
-- 
1.7.9.5


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

* [RFC BlueZ 34/35] tools/mgmt-tester: Interleaved stop discovery (BR/EDR dev. found)
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (32 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 33/35] tools/mgmt-tester: Increase timeout for dual mode controller Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-12 12:57 ` [RFC BlueZ 35/35] tools/mgmt-tester: Interleaved Stop discovery (Name Resolving) Bruna Moreira
  2013-06-19 10:02 ` [RFC BlueZ 00/35] More discovery tests Johan Hedberg
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

This test will check the stop interleaved discovery during inquiry. For
this, it verifies the following:
- LE Set Scan Enable HCI command is received,
- Device found event (with BR/EDR device) is received,
- Inquiry cancel is received, and
- Stop discovery is succeed.
---
 tools/mgmt-tester.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 92ae2ea..b995076 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -1441,6 +1441,24 @@ static const struct generic_data stop_discovery_bredrle_success_test_5 = {
 	.expect_alt_ev_len = sizeof(start_le_device_found_evt),
 };
 
+static const struct generic_data stop_discovery_bredrle_success_test_6 = {
+	.hciemu_type_second = HCIEMU_TYPE_BREDR,
+	.setup_expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_ENABLE,
+	.setup_expect_hci_param = start_discovery_valid_hci,
+	.setup_expect_hci_len = sizeof(start_discovery_valid_hci),
+	.block_hci_command = BT_HCI_EVT_INQUIRY_COMPLETE,
+	.send_opcode = MGMT_OP_STOP_DISCOVERY,
+	.send_param = stop_discovery_bredrle_param,
+	.send_len = sizeof(stop_discovery_bredrle_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = stop_discovery_bredrle_param,
+	.expect_len = sizeof(stop_discovery_bredrle_param),
+	.expect_hci_command = BT_HCI_CMD_INQUIRY_CANCEL,
+	.expect_alt_ev = MGMT_EV_DEVICE_FOUND,
+	.expect_alt_ev_param = stop_device_found_bredr_evt,
+	.expect_alt_ev_len = sizeof(stop_device_found_bredr_evt),
+};
+
 static const struct generic_data stop_discovery_rejected_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
 	.send_param = stop_discovery_bredrle_param,
@@ -2740,6 +2758,21 @@ static void command_generic_event_alt(uint16_t index, uint16_t length,
 	if (test->expect_hci_command == BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL) {
 		test_add_condition(data);
 		send_confirm_name();
+	} else if (test->setup_expect_hci_param) {
+		const char bredrle_param[] = { 0x07 };
+
+		/* Interleaved discovery */
+		if (memcmp(test->send_param, bredrle_param,
+							test->send_len) == 0) {
+			tester_print("Sending command 0x%04x (interleaved)",
+							test->send_opcode);
+
+			mgmt_send(data->mgmt, test->send_opcode,
+					data->mgmt_index,
+					test->send_len, test->send_param,
+					command_generic_callback, NULL, NULL);
+			test_add_condition(data);
+		}
 	}
 
 	mgmt_unregister(data->mgmt_alt, data->mgmt_alt_ev_id);
@@ -2864,6 +2897,14 @@ static void start_discovery_callback(uint8_t status, uint16_t length,
 	tester_print("Discovery started");
 
 	if (test->expect_hci_command != BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL) {
+		const char bredrle_param[] = { 0x07 };
+
+		/* If interleaved discovery was started, only send opcode after
+		 * device found event */
+		if (test->setup_expect_hci_param && (memcmp(test->send_param,
+					bredrle_param, test->send_len) == 0))
+				return;
+
 		tester_print("Sending command 0x%04x", test->send_opcode);
 
 		mgmt_send(data->mgmt, test->send_opcode, data->mgmt_index,
@@ -3214,6 +3255,9 @@ int main(int argc, char *argv[])
 	test_bredrle("Stop discovery (Device Found) - Success 5",
 				&stop_discovery_bredrle_success_test_5,
 				setup_le_powered, test_command_start_discovery);
+	test_bredrle("Stop discovery (Device Found) - Success 6",
+				&stop_discovery_bredrle_success_test_6,
+				setup_le_powered, test_command_start_discovery);
 	test_bredrle("Stop Discovery - Rejected 1",
 				&stop_discovery_rejected_test_1,
 				setup_le_powered, test_command_generic);
-- 
1.7.9.5


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

* [RFC BlueZ 35/35] tools/mgmt-tester: Interleaved Stop discovery (Name Resolving)
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (33 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 34/35] tools/mgmt-tester: Interleaved stop discovery (BR/EDR dev. found) Bruna Moreira
@ 2013-06-12 12:57 ` Bruna Moreira
  2013-06-19 10:02 ` [RFC BlueZ 00/35] More discovery tests Johan Hedberg
  35 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-12 12:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

This test will check the stop interleaved discovery during name
resolving operation. For this, it verifies the following:
- LE Set Scan Enable HCI command is received,
- Device found event (with BR/EDR device) is received,
- Remote name request cancel is received, and
- Stop discovery is succeed.
---
 tools/mgmt-tester.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index b995076..f001240 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -1459,6 +1459,26 @@ static const struct generic_data stop_discovery_bredrle_success_test_6 = {
 	.expect_alt_ev_len = sizeof(stop_device_found_bredr_evt),
 };
 
+static const struct generic_data stop_discovery_bredr_success_test_7 = {
+	.hciemu_type_second = HCIEMU_TYPE_BREDR,
+	.setup_expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_ENABLE,
+	.setup_expect_hci_param = start_discovery_valid_hci,
+	.setup_expect_hci_len = sizeof(start_discovery_valid_hci),
+	.block_hci_command = BT_HCI_EVT_INQUIRY_COMPLETE,
+	.send_opcode = MGMT_OP_STOP_DISCOVERY,
+	.send_param = stop_discovery_bredrle_param,
+	.send_len = sizeof(stop_discovery_bredrle_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = stop_discovery_bredrle_param,
+	.expect_len = sizeof(stop_discovery_bredrle_param),
+	.expect_hci_command = BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL,
+	.expect_hci_param = stop_remote_name_valid_hci,
+	.expect_hci_len = sizeof(stop_remote_name_valid_hci),
+	.expect_alt_ev = MGMT_EV_DEVICE_FOUND,
+	.expect_alt_ev_param = stop_device_found_bredr_evt,
+	.expect_alt_ev_len = sizeof(stop_device_found_bredr_evt),
+};
+
 static const struct generic_data stop_discovery_rejected_test_1 = {
 	.send_opcode = MGMT_OP_STOP_DISCOVERY,
 	.send_param = stop_discovery_bredrle_param,
@@ -3258,6 +3278,9 @@ int main(int argc, char *argv[])
 	test_bredrle("Stop discovery (Device Found) - Success 6",
 				&stop_discovery_bredrle_success_test_6,
 				setup_le_powered, test_command_start_discovery);
+	test_bredrle("Stop Discovery (Name Resolving) - Success 7",
+				&stop_discovery_bredr_success_test_7,
+				setup_le_powered, test_command_start_discovery);
 	test_bredrle("Stop Discovery - Rejected 1",
 				&stop_discovery_rejected_test_1,
 				setup_le_powered, test_command_generic);
-- 
1.7.9.5


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

* Re: [RFC BlueZ 05/35] emulator: Search virtual devices in LE advertising mode
  2013-06-12 12:56 ` [RFC BlueZ 05/35] emulator: Search virtual devices in LE advertising mode Bruna Moreira
@ 2013-06-19  9:56   ` Johan Hedberg
  2013-06-20 11:49     ` Bruna Moreira
  0 siblings, 1 reply; 42+ messages in thread
From: Johan Hedberg @ 2013-06-19  9:56 UTC (permalink / raw)
  To: Bruna Moreira; +Cc: linux-bluetooth, Jefferson Delfes

Hi,

On Wed, Jun 12, 2013, Bruna Moreira wrote:
> From: Jefferson Delfes <jefferson.delfes@openbossa.org>
> 
> After LE scan is enabled, the emulator search virtual devices that are
> in advertising mode, in order to copy adv data.
> ---
>  emulator/btdev.c |   15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/emulator/btdev.c b/emulator/btdev.c
> index a7af6b3..160e5bf 100644
> --- a/emulator/btdev.c
> +++ b/emulator/btdev.c
> @@ -876,6 +876,19 @@ static void remote_version_complete(struct btdev *btdev, uint16_t handle)
>  							&rvc, sizeof(rvc));
>  }
>  
> +static void le_set_scan_enable_complete(struct btdev *btdev)
> +{
> +	int i;
> +
> +	for (i = 0; i < MAX_BTDEV_ENTRIES; i++) {
> +		if (!btdev_list[i] || btdev_list[i] == btdev)
> +			continue;
> +
> +		if (!btdev_list[i]->le_adv_enable)
> +			continue;
> +	}
> +}

What's the purpose of this function? It doesn't seem to do anything but
iterate through the btdev list. Should it be merged with some later
patch (which actually does something useful)?

Johan

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

* Re: [RFC BlueZ 06/35] emulator: Search virtual devices in LE scan mode
  2013-06-12 12:56 ` [RFC BlueZ 06/35] emulator: Search virtual devices in LE scan mode Bruna Moreira
@ 2013-06-19  9:57   ` Johan Hedberg
  2013-06-20 11:52     ` Bruna Moreira
  0 siblings, 1 reply; 42+ messages in thread
From: Johan Hedberg @ 2013-06-19  9:57 UTC (permalink / raw)
  To: Bruna Moreira; +Cc: linux-bluetooth, Jefferson Delfes

Hi,

On Wed, Jun 12, 2013, Bruna Moreira wrote:
> From: Jefferson Delfes <jefferson.delfes@openbossa.org>
> 
> When a virtual device starts an LE advertising, emulator search other
> devices that are in scan mode, in order to send adv data to these
> devices.
> ---
>  emulator/btdev.c |   15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/emulator/btdev.c b/emulator/btdev.c
> index 160e5bf..2725c76 100644
> --- a/emulator/btdev.c
> +++ b/emulator/btdev.c
> @@ -876,6 +876,19 @@ static void remote_version_complete(struct btdev *btdev, uint16_t handle)
>  							&rvc, sizeof(rvc));
>  }
>  
> +static void le_set_adv_enable_complete(struct btdev *btdev)
> +{
> +	int i;
> +
> +	for (i = 0; i < MAX_BTDEV_ENTRIES; i++) {
> +		if (!btdev_list[i] || btdev_list[i] == btdev)
> +			continue;
> +
> +		if (!btdev_list[i]->le_scan_enable)
> +			continue;
> +	}
> +}

Same thing as with my earlier comment. This function doesn't seem to do
anything useful and should probably be merged with some later patch that
actually does something (assuming such a patch exists).

Johan

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

* Re: [RFC BlueZ 21/35] tools/mgmt-tester: Add support for second controller
  2013-06-12 12:57 ` [RFC BlueZ 21/35] tools/mgmt-tester: Add support for second controller Bruna Moreira
@ 2013-06-19 10:00   ` Johan Hedberg
  0 siblings, 0 replies; 42+ messages in thread
From: Johan Hedberg @ 2013-06-19 10:00 UTC (permalink / raw)
  To: Bruna Moreira; +Cc: linux-bluetooth

Hi,

On Wed, Jun 12, 2013, Bruna Moreira wrote:
> Add second controller to tester and let a testcase start discovery and
> receive Device Found events.
> ---
>  tools/mgmt-tester.c |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 73 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
> index cbff775..a27b2e2 100644
> --- a/tools/mgmt-tester.c
> +++ b/tools/mgmt-tester.c
> @@ -56,6 +56,8 @@ struct test_data {
>  	uint16_t mgmt_index;
>  	struct hciemu *hciemu;
>  	enum hciemu_type hciemu_type;
> +	struct hciemu *hciemu_second;
> +	uint16_t mgmt_index_second;
>  	int unmet_conditions;
>  };

It seems to me that this is exactly why bthost exists, i.e. the hciemu
instance already contains a peer controller combined with an emulated
host stack.

Johan

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

* Re: [RFC BlueZ 00/35] More discovery tests
  2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
                   ` (34 preceding siblings ...)
  2013-06-12 12:57 ` [RFC BlueZ 35/35] tools/mgmt-tester: Interleaved Stop discovery (Name Resolving) Bruna Moreira
@ 2013-06-19 10:02 ` Johan Hedberg
  35 siblings, 0 replies; 42+ messages in thread
From: Johan Hedberg @ 2013-06-19 10:02 UTC (permalink / raw)
  To: Bruna Moreira; +Cc: linux-bluetooth

Hi Bruna,

On Wed, Jun 12, 2013, Bruna Moreira wrote:
> This series implements more complex discovery tests and all necessary support
> in the emulator. It is rather long because it required many modifications to
> the emulation layer in order to support these tests.
> 
> Patches 1-11 implement basic LE support on emulator. The main features are:
> - Set LE advertising data
> - Set advertising enable command
> - Set LE advertising parameters
> - Send LE advertising report
> - LE create connection command (Basic support for multiple connections).
> NOTE: support for multiple connections is not necessary for discovery tests.
> 
> Patches 12-19 implement hook mechanism.
> The hook mechanism is a way to run custom code from tests before/after
> processing HCI commands and building events. It is also possible to "cancel"
> events if the post event hook returns false. To simplify implementation,
> default_cmd() was split in two parts: the command response (command
> status/complete events) was kept in default_cmd() and "extra" events were moved
> to default_cmd completion().
> 
> There are four hooks types:
> - pre command: before default_cmd() function.
> - post command: before sending packet in command status and command complete.
> - pre event: before default_cmd_completion() function.
> - post event: in send_event() function, before sending the packet.
> They can used in external applications like tools/mgmt-tester.
> 
> Patches 20-25 and 28-35 implement discovery tests.
> For start discovery, we have:
> - Start BR/EDR Discovery and wait for Device Found event from BR/EDR device.
> - Start LE-only Discovery and wait for Device Found event from LE device.
> For stop discovery:
> - Stop BR/EDR Discovery during Inquiry (no devices found).
> - Wait for Device Found event from BR/EDR device and stop BR/EDR Discovery during:
>   - Inquiry.
>   - Name Resolving.
> - Wait for Device Found event from LE device and stop interleaved discovery
>   during LE scanning.
> - Wait for Device Found event from BR/EDR device and stop interleaved discovery
>   during:
>   - Inquiry.
>   - Name Resolving.
> - Wait for Device Found event from LE device and stop LE-only Discovery during
>   LE scanning.
> 
> NOTE: currently, bluetoothd should not be running during tests because it will
> try to change EIR data for the second virtual controller (which represents the
> remote device) and thus will not match the data statically declared on the
> tests.
> 
> Patch 26 adds support for saving a packet cancelled by a post event hook, so it
> can be sent later.
> 
> Patch 27 contains a fix already sent to the mailing list (with some
> modifications to apply upstream):
>  emulator: Fix Remote Name Request Cancel command complete
> 
> Comments and suggestions are welcome.
> 
> BR,
> Bruna Moreira.
> 
> Anderson Lizardo (1):
>   emulator: Fix Remote Name Request Cancel command complete
> 
> Bruna Moreira (16):
>   emulator: Add remove operation in HCI hook callback
>   emulator: Add new function for running all hooks
>   tools/mgmt-tester: Add stop discovery for BR/EDR only
>   tools/mgmt-tester: Add support for second controller
>   tools/mgmt-tester: BR/EDR Start discovery (Device Found)
>   tools/mgmt-tester: LE only Start discovery (Device Found)
>   tools/mgmt-tester: Split test_command_generic()
>   tools/mgmt-tester: BR/EDR Stop discovery (Device Found)
>   btdev: Add function to send an aborted packet
>   tools/mgmt-tester: Move command_generic_callback()
>   tools/mgmt-tester: BR/EDR Stop discovery (Name Resolving)
>   tools/mgmt-tester: Add support to set emulator type
>   tools/mgmt-tester: Interleaved stop discovery (LE dev. found)
>   tools/mgmt-tester: Increase timeout for dual mode controller
>   tools/mgmt-tester: Interleaved stop discovery (BR/EDR dev. found)
>   tools/mgmt-tester: Interleaved Stop discovery (Name Resolving)
> 
> Eder Ruiz Maria (7):
>   emulator: Add support for pre/post command/event hooks
>   emulator: Add hook only if there aren't other with same type and
>     opcode
>   emulator: Export command and event hooks for hciemu user
>   emulator: Add support for delete a hook
>   emulator: Split default_cmd() for better command and event handler
>   emulator: cmd_status() using send_packet() for run hooks easily
>   tools/mgmt-tester: LE Stop discovery (Device Found)
> 
> Jefferson Delfes (11):
>   emulator: Add support for multiple connections
>   emulator: Store LE advertising data length in btdev
>   emulator: Implement basic LE set adv enable command
>   emulator: Store LE scan state of virtual controller
>   emulator: Search virtual devices in LE advertising mode
>   emulator: Search virtual devices in LE scan mode
>   emulator: Implement LE advertising report
>   emulator: Implement basic LE create connection
>   emulator: Dummy LE set advertising parameters
>   emulator: Disallow LE set scan params command when scan is enabled
>   emulator: Set LE supported states
> 
>  emulator/btdev.c    |  619 +++++++++++++++++++++++++++++++++++++++------
>  emulator/btdev.h    |   20 ++
>  monitor/bt.h        |   17 ++
>  src/shared/hciemu.c |   87 ++++++-
>  src/shared/hciemu.h |   22 +-
>  tools/mgmt-tester.c |  690 ++++++++++++++++++++++++++++++++++++++++++++++++---
>  6 files changed, 1338 insertions(+), 117 deletions(-)

You should know by now that huge patch bombs like this are not really
appreciated (this is part of the reason why it has taken so long to get
any response to it). Could you please split this up in some sensible
way, e.g. put clear fixes and necessary refactoring into its own patch
set (which shouldn't need the RFC declaration).

Johan

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

* Re: [RFC BlueZ 05/35] emulator: Search virtual devices in LE advertising mode
  2013-06-19  9:56   ` Johan Hedberg
@ 2013-06-20 11:49     ` Bruna Moreira
  0 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-20 11:49 UTC (permalink / raw)
  To: Bruna Moreira, linux-bluetooth, Jefferson Delfes

Hi,

>> +static void le_set_scan_enable_complete(struct btdev *btdev)
>> +{
>> +     int i;
>> +
>> +     for (i = 0; i < MAX_BTDEV_ENTRIES; i++) {
>> +             if (!btdev_list[i] || btdev_list[i] == btdev)
>> +                     continue;
>> +
>> +             if (!btdev_list[i]->le_adv_enable)
>> +                     continue;
>> +     }
>> +}
>
> What's the purpose of this function? It doesn't seem to do anything but
> iterate through the btdev list. Should it be merged with some later
> patch (which actually does something useful)?
>
> Johan

Yes, this function is used in a later patch "emulator: Implement LE
advertising report". I will merge it.

BR,
-- 
Bruna Moreira
Instituto Nokia de Tecnologia (INdT)
Manaus - Brazil

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

* Re: [RFC BlueZ 06/35] emulator: Search virtual devices in LE scan mode
  2013-06-19  9:57   ` Johan Hedberg
@ 2013-06-20 11:52     ` Bruna Moreira
  0 siblings, 0 replies; 42+ messages in thread
From: Bruna Moreira @ 2013-06-20 11:52 UTC (permalink / raw)
  To: Bruna Moreira, linux-bluetooth, Jefferson Delfes

Hi Johan,

On Wed, Jun 19, 2013 at 5:57 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
>> +static void le_set_adv_enable_complete(struct btdev *btdev)
>> +{
>> +     int i;
>> +
>> +     for (i = 0; i < MAX_BTDEV_ENTRIES; i++) {
>> +             if (!btdev_list[i] || btdev_list[i] == btdev)
>> +                     continue;
>> +
>> +             if (!btdev_list[i]->le_scan_enable)
>> +                     continue;
>> +     }
>> +}
>
> Same thing as with my earlier comment. This function doesn't seem to do
> anything useful and should probably be merged with some later patch that
> actually does something (assuming such a patch exists).

Same here. This function is used in a later patch. I will merge it too.

BR,
-- 
Bruna Moreira
Instituto Nokia de Tecnologia (INdT)
Manaus - Brazil

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

end of thread, other threads:[~2013-06-20 11:52 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-12 12:56 [RFC BlueZ 00/35] More discovery tests Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 01/35] emulator: Add support for multiple connections Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 02/35] emulator: Store LE advertising data length in btdev Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 03/35] emulator: Implement basic LE set adv enable command Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 04/35] emulator: Store LE scan state of virtual controller Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 05/35] emulator: Search virtual devices in LE advertising mode Bruna Moreira
2013-06-19  9:56   ` Johan Hedberg
2013-06-20 11:49     ` Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 06/35] emulator: Search virtual devices in LE scan mode Bruna Moreira
2013-06-19  9:57   ` Johan Hedberg
2013-06-20 11:52     ` Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 07/35] emulator: Implement LE advertising report Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 08/35] emulator: Implement basic LE create connection Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 09/35] emulator: Dummy LE set advertising parameters Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 10/35] emulator: Disallow LE set scan params command when scan is enabled Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 11/35] emulator: Set LE supported states Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 12/35] emulator: Add remove operation in HCI hook callback Bruna Moreira
2013-06-12 12:56 ` [RFC BlueZ 13/35] emulator: Add support for pre/post command/event hooks Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 14/35] emulator: Add hook only if there aren't other with same type and opcode Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 15/35] emulator: Export command and event hooks for hciemu user Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 16/35] emulator: Add support for delete a hook Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 17/35] emulator: Split default_cmd() for better command and event handler Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 18/35] emulator: cmd_status() using send_packet() for run hooks easily Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 19/35] emulator: Add new function for running all hooks Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 20/35] tools/mgmt-tester: Add stop discovery for BR/EDR only Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 21/35] tools/mgmt-tester: Add support for second controller Bruna Moreira
2013-06-19 10:00   ` Johan Hedberg
2013-06-12 12:57 ` [RFC BlueZ 22/35] tools/mgmt-tester: BR/EDR Start discovery (Device Found) Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 23/35] tools/mgmt-tester: LE only " Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 24/35] tools/mgmt-tester: Split test_command_generic() Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 25/35] tools/mgmt-tester: BR/EDR Stop discovery (Device Found) Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 26/35] btdev: Add function to send an aborted packet Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 27/35] emulator: Fix Remote Name Request Cancel command complete Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 28/35] tools/mgmt-tester: Move command_generic_callback() Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 29/35] tools/mgmt-tester: BR/EDR Stop discovery (Name Resolving) Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 30/35] tools/mgmt-tester: Add support to set emulator type Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 31/35] tools/mgmt-tester: LE Stop discovery (Device Found) Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 32/35] tools/mgmt-tester: Interleaved stop discovery (LE dev. found) Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 33/35] tools/mgmt-tester: Increase timeout for dual mode controller Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 34/35] tools/mgmt-tester: Interleaved stop discovery (BR/EDR dev. found) Bruna Moreira
2013-06-12 12:57 ` [RFC BlueZ 35/35] tools/mgmt-tester: Interleaved Stop discovery (Name Resolving) Bruna Moreira
2013-06-19 10:02 ` [RFC BlueZ 00/35] More discovery tests Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.