linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command
@ 2024-11-14 19:25 Luiz Augusto von Dentz
  2024-11-14 19:25 ` [PATCH BlueZ v2 2/5] monitor: Fix opcode for MGMT_OP_MESH_SEND_CANCEL Luiz Augusto von Dentz
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2024-11-14 19:25 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds Send HCI command and wait for event Command initial
documentation.
---
 doc/mgmt-api.txt | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 01a23526a4ef..b4a5776574f7 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -3992,6 +3992,36 @@ Cancel Transmit Mesh Packet Command
 	Possible errors:	Failed
 				Invalid Parameters
 
+Send HCI command and wait for event Command
+===========================================
+
+	Command Code:		0x005B
+	Controller Index:	<controller id>
+	Command Parameters:	Opcode (2 Octets)
+				Event (1 Octet)
+				Timeout (1 Octet)
+				Parameter Length (2 Octets)
+				Parameter (variable)
+	Return Parameters:	Response (1-variable Octets)
+
+	This command may be used to send a HCI command and wait for an
+	(optional) event.
+
+	The HCI command is specified by the Opcode, any arbitrary is supported
+	including vendor commands, but contrary to the like of
+	Raw/User channel it is run as an HCI command send by the kernel
+	since it uses its command synchronization thus it is possible to wait
+	for a specific event as a response.
+
+	Setting event to 0x00 will cause the command to wait for either
+	HCI Command Status or HCI Command Complete.
+
+	Timeout is specified in seconds, setting it to 0 will cause the
+	default timeout to be used.
+
+	Possible errors:	Failed
+				Invalid Parameters
+
 Command Complete Event
 ======================
 
-- 
2.47.0


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

* [PATCH BlueZ v2 2/5] monitor: Fix opcode for MGMT_OP_MESH_SEND_CANCEL
  2024-11-14 19:25 [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command Luiz Augusto von Dentz
@ 2024-11-14 19:25 ` Luiz Augusto von Dentz
  2024-11-14 19:25 ` [PATCH BlueZ v2 3/5] monitor: Add decoding of MGMT_OP_HCI_CMD_SYNC Luiz Augusto von Dentz
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2024-11-14 19:25 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

MGMT_OP_MESH_SEND_CANCEL opcode is 0x005A not 0x0056.
---
 monitor/packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index 32a440bbea68..6d869ffeadb8 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -14982,7 +14982,7 @@ static const struct mgmt_data mgmt_command_table[] = {
 	{ 0x0059, "Mesh Send",
 				mgmt_mesh_send_cmd, 19, false,
 				mgmt_mesh_send_rsp, 1, true},
-	{ 0x0056, "Mesh Send Cancel",
+	{ 0x005A, "Mesh Send Cancel",
 				mgmt_mesh_send_cancel_cmd, 1, true,
 				mgmt_null_rsp, 0, true},
 	{ }
-- 
2.47.0


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

* [PATCH BlueZ v2 3/5] monitor: Add decoding of MGMT_OP_HCI_CMD_SYNC
  2024-11-14 19:25 [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command Luiz Augusto von Dentz
  2024-11-14 19:25 ` [PATCH BlueZ v2 2/5] monitor: Fix opcode for MGMT_OP_MESH_SEND_CANCEL Luiz Augusto von Dentz
@ 2024-11-14 19:25 ` Luiz Augusto von Dentz
  2024-11-14 19:25 ` [PATCH BlueZ v2 4/5] lib/mgmt: Add definitions " Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2024-11-14 19:25 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

@ MGMT Com..nd (0x005b) plen 6  {0x0002}
        Opcode: 0xffff
        Event: 0x00
        Timeout: 0 seconds
        Parameters Length: 0
        Parameters[0]:
@ MGMT Event: Command Status (0x0002) plen 3    {0x0002}
        Send HCI command and wait for event (0x005b)
          Status: Failed (0x03)
---
 monitor/packet.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/monitor/packet.c b/monitor/packet.c
index 6d869ffeadb8..f1a42925a8fc 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -14712,6 +14712,55 @@ static void mgmt_mesh_send_cancel_cmd(const void *data, uint16_t size)
 	print_field("Handle: %d", handle);
 }
 
+static void mgmt_hci_cmd_sync_cmd(const void *data, uint16_t size)
+{
+	struct iovec iov = { (void *)data, size };
+	uint16_t opcode, len;
+	uint8_t event;
+	uint8_t timeout;
+
+	if (!util_iov_pull_le16(&iov, &opcode)) {
+		print_text(COLOR_ERROR, "  invalid opcode");
+		return;
+	}
+
+	print_field("Opcode: 0x%4.4x", opcode);
+
+	if (!util_iov_pull_u8(&iov, &event)) {
+		print_text(COLOR_ERROR, "  invalid event");
+		return;
+	}
+
+	print_field("Event: 0x%2.2x", event);
+
+	if (!util_iov_pull_u8(&iov, &timeout)) {
+		print_text(COLOR_ERROR, "  invalid timeout");
+		return;
+	}
+
+	print_field("Timeout: %d seconds", timeout);
+
+	if (!util_iov_pull_le16(&iov, &len)) {
+		print_text(COLOR_ERROR, "  invalid parameters length");
+		return;
+	}
+
+	print_field("Parameters Length: %d", len);
+
+	if (iov.iov_len != len) {
+		print_text(COLOR_ERROR, "  length mismatch (%zu != %d)",
+				iov.iov_len, len);
+		return;
+	}
+
+	print_hex_field("Parameters", iov.iov_base, iov.iov_len);
+}
+
+static void mgmt_hci_cmd_sync_rsp(const void *data, uint16_t size)
+{
+	print_hex_field("Response", data, size);
+}
+
 struct mgmt_data {
 	uint16_t opcode;
 	const char *str;
@@ -14985,6 +15034,9 @@ static const struct mgmt_data mgmt_command_table[] = {
 	{ 0x005A, "Mesh Send Cancel",
 				mgmt_mesh_send_cancel_cmd, 1, true,
 				mgmt_null_rsp, 0, true},
+	{ 0x005B, "Send HCI command and wait for event",
+				mgmt_hci_cmd_sync_cmd, 6, false,
+				mgmt_hci_cmd_sync_rsp, 0, false},
 	{ }
 };
 
-- 
2.47.0


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

* [PATCH BlueZ v2 4/5] lib/mgmt: Add definitions of MGMT_OP_HCI_CMD_SYNC
  2024-11-14 19:25 [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command Luiz Augusto von Dentz
  2024-11-14 19:25 ` [PATCH BlueZ v2 2/5] monitor: Fix opcode for MGMT_OP_MESH_SEND_CANCEL Luiz Augusto von Dentz
  2024-11-14 19:25 ` [PATCH BlueZ v2 3/5] monitor: Add decoding of MGMT_OP_HCI_CMD_SYNC Luiz Augusto von Dentz
@ 2024-11-14 19:25 ` Luiz Augusto von Dentz
  2024-11-14 19:25 ` [PATCH BlueZ v2 5/5] client/mgmt: Add hci-cmd command Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2024-11-14 19:25 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds the definition of MGMT_OP_HCI_CMD_SYNC and its packet
structure.
---
 lib/mgmt.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 8f92b77315e3..f784dcada191 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -797,7 +797,16 @@ struct mgmt_cp_mesh_send {
 
 #define MGMT_OP_MESH_SEND_CANCEL	0x005A
 struct mgmt_cp_mesh_send_cancel {
-	uint8_t handle;
+		uint8_t handle;
+} __packed;
+
+#define MGMT_OP_HCI_CMD_SYNC		0x005B
+struct mgmt_cp_hci_cmd_sync {
+	uint16_t opcode;
+	uint8_t  event;
+	uint8_t  timeout;
+	uint16_t params_len;
+	uint8_t  params[];
 } __packed;
 
 #define MGMT_EV_CMD_COMPLETE		0x0001
-- 
2.47.0


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

* [PATCH BlueZ v2 5/5] client/mgmt: Add hci-cmd command
  2024-11-14 19:25 [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2024-11-14 19:25 ` [PATCH BlueZ v2 4/5] lib/mgmt: Add definitions " Luiz Augusto von Dentz
@ 2024-11-14 19:25 ` Luiz Augusto von Dentz
  2024-11-14 20:33 ` [BlueZ,v2,1/5] mgmt-api: Add Send HCI command and wait for event Command bluez.test.bot
  2024-11-14 20:40 ` [PATCH BlueZ v2 1/5] " patchwork-bot+bluetooth
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2024-11-14 19:25 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds hci-cmd command which uses the MGMT_OP_HCI_CMD_SYNC:

bluetoothctl> mgmt.hci-send 0xffff
bluetoothctl[44]: @ MGMT Com..nd (0x005b) plen 6  {0x0002}
        Opcode: 0xffff
        Event: 0x00
        Timeout: 0 seconds
        Parameters Length: 0
        Parameters[0]:
< HCI Command: Vendor (0x3f|0x03ff) plen 0
> HCI Event: Command Status (0x0f) plen 4
      Vendor (0x3f|0x03ff) ncmd 1
        Status: Unknown HCI Command (0x01)
@ MGMT Event: Command Status (0x0002) plen 3    {0x0002}
      Send HCI command and wait for event (0x005b)
        Status: Failed (0x03)
---
 client/mgmt.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)

diff --git a/client/mgmt.c b/client/mgmt.c
index 602b92228ab8..59dcb3135344 100644
--- a/client/mgmt.c
+++ b/client/mgmt.c
@@ -2338,6 +2338,115 @@ static void cmd_set_flags(int argc, char **argv)
 
 }
 
+static uint8_t *str2bytearray(char *arg, uint8_t *val, long *val_len)
+{
+	char *entry;
+	unsigned int i;
+
+	for (i = 0; (entry = strsep(&arg, " \t")) != NULL; i++) {
+		long v;
+		char *endptr = NULL;
+
+		if (*entry == '\0')
+			continue;
+
+		if (i >= *val_len) {
+			bt_shell_printf("Too much data\n");
+			return NULL;
+		}
+
+		v = strtol(entry, &endptr, 0);
+		if (!endptr || *endptr != '\0' || v > UINT8_MAX) {
+			bt_shell_printf("Invalid value at index %d\n", i);
+			return NULL;
+		}
+
+		val[i] = v;
+	}
+
+	*val_len = i;
+
+	return val;
+}
+
+static void hci_cmd_rsp(uint8_t status, uint16_t len, const void *param,
+							void *user_data)
+{
+	if (status != 0) {
+		error("HCI command failed with status 0x%02x (%s)",
+						status, mgmt_errstr(status));
+		bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	if (len > 0) {
+		bt_shell_printf("Response: ");
+		bt_shell_hexdump(param, len);
+	}
+
+	bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static void cmd_hci_cmd(int argc, char **argv)
+{
+	struct {
+		struct mgmt_cp_hci_cmd_sync cp;
+		uint8_t data[UINT8_MAX];
+	} pkt;
+	char *endptr = NULL;
+	long value;
+	uint16_t index;
+
+	value = strtoul(argv[1], &endptr, 0);
+	if (!endptr || *endptr != '\0' || value > UINT16_MAX) {
+		bt_shell_printf("Invalid opcode: %s", argv[1]);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	memset(&pkt, 0, sizeof(pkt));
+	pkt.cp.opcode = cpu_to_le16(value);
+
+	if (argc > 2) {
+		endptr = NULL;
+		value = strtoul(argv[2], &endptr, 0);
+		if (!endptr || *endptr != '\0' || value > UINT8_MAX) {
+			bt_shell_printf("Invalid event: %s", argv[2]);
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
+
+		pkt.cp.event = value;
+	}
+
+	if (argc > 3) {
+		endptr = NULL;
+		value = strtoul(argv[3], &endptr, 0);
+		if (!endptr || *endptr != '\0' || value > UINT8_MAX) {
+			bt_shell_printf("Invalid timeout: %s", argv[2]);
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
+
+		pkt.cp.timeout = value;
+	}
+
+	if (argc > 4) {
+		value = sizeof(pkt.data);
+		if (!str2bytearray(argv[4], pkt.data, &value))
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+		pkt.cp.params_len = value;
+	}
+
+	index = mgmt_index;
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	if (mgmt_send(mgmt, MGMT_OP_HCI_CMD_SYNC, index,
+			sizeof(pkt.cp) + pkt.cp.params_len, &pkt,
+			hci_cmd_rsp, NULL, NULL) == 0) {
+		error("Unable to send HCI command");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+}
+
 /* Wrapper to get the index and opcode to the response callback */
 struct command_data {
 	uint16_t id;
@@ -6016,6 +6125,8 @@ static const struct bt_shell_menu mgmt_menu = {
 		cmd_get_flags,		"Get device flags"		},
 	{ "set-flags",		"[-f flags] [-t type] <address>",
 		cmd_set_flags,		"Set device flags"		},
+	{ "hci-cmd",		"<opcode> [event] [timeout] [param...]",
+		cmd_hci_cmd,	"Send HCI Command and wait for Event"	},
 	{} },
 };
 
-- 
2.47.0


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

* RE: [BlueZ,v2,1/5] mgmt-api: Add Send HCI command and wait for event Command
  2024-11-14 19:25 [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2024-11-14 19:25 ` [PATCH BlueZ v2 5/5] client/mgmt: Add hci-cmd command Luiz Augusto von Dentz
@ 2024-11-14 20:33 ` bluez.test.bot
  2024-11-14 20:40 ` [PATCH BlueZ v2 1/5] " patchwork-bot+bluetooth
  5 siblings, 0 replies; 7+ messages in thread
From: bluez.test.bot @ 2024-11-14 20:33 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 2020 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=909740

---Test result---

Test Summary:
CheckPatch                    PENDING   0.26 seconds
GitLint                       PENDING   0.29 seconds
BuildEll                      PASS      20.85 seconds
BluezMake                     PASS      1669.08 seconds
MakeCheck                     PASS      13.01 seconds
MakeDistcheck                 PASS      158.31 seconds
CheckValgrind                 PASS      216.43 seconds
CheckSmatch                   WARNING   275.04 seconds
bluezmakeextell               PASS      99.28 seconds
IncrementalBuild              PENDING   0.29 seconds
ScanBuild                     PASS      857.74 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
monitor/packet.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c:1868:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3606:52: warning: array of flexible structuresmonitor/bt.h:3594:40: warning: array of flexible structuresmonitor/packet.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c:1868:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3606:52: warning: array of flexible structuresmonitor/bt.h:3594:40: warning: array of flexible structures
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


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

* Re: [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command
  2024-11-14 19:25 [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command Luiz Augusto von Dentz
                   ` (4 preceding siblings ...)
  2024-11-14 20:33 ` [BlueZ,v2,1/5] mgmt-api: Add Send HCI command and wait for event Command bluez.test.bot
@ 2024-11-14 20:40 ` patchwork-bot+bluetooth
  5 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+bluetooth @ 2024-11-14 20:40 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Thu, 14 Nov 2024 14:25:20 -0500 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> This adds Send HCI command and wait for event Command initial
> documentation.
> ---
>  doc/mgmt-api.txt | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)

Here is the summary with links:
  - [BlueZ,v2,1/5] mgmt-api: Add Send HCI command and wait for event Command
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=fe1296cb1156
  - [BlueZ,v2,2/5] monitor: Fix opcode for MGMT_OP_MESH_SEND_CANCEL
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2e981e1a9498
  - [BlueZ,v2,3/5] monitor: Add decoding of MGMT_OP_HCI_CMD_SYNC
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d395c6b1c7d4
  - [BlueZ,v2,4/5] lib/mgmt: Add definitions of MGMT_OP_HCI_CMD_SYNC
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=0580dc4bb64f
  - [BlueZ,v2,5/5] client/mgmt: Add hci-cmd command
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=95e89cd2e4f8

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-11-14 20:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-14 19:25 [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command Luiz Augusto von Dentz
2024-11-14 19:25 ` [PATCH BlueZ v2 2/5] monitor: Fix opcode for MGMT_OP_MESH_SEND_CANCEL Luiz Augusto von Dentz
2024-11-14 19:25 ` [PATCH BlueZ v2 3/5] monitor: Add decoding of MGMT_OP_HCI_CMD_SYNC Luiz Augusto von Dentz
2024-11-14 19:25 ` [PATCH BlueZ v2 4/5] lib/mgmt: Add definitions " Luiz Augusto von Dentz
2024-11-14 19:25 ` [PATCH BlueZ v2 5/5] client/mgmt: Add hci-cmd command Luiz Augusto von Dentz
2024-11-14 20:33 ` [BlueZ,v2,1/5] mgmt-api: Add Send HCI command and wait for event Command bluez.test.bot
2024-11-14 20:40 ` [PATCH BlueZ v2 1/5] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).