Skip to contentSkip to conversation

monitor/msft: Fix uuid.u128 format

PATCH In review Luiz Augusto von Dentz 2 participants 7 messages Oct 20, 2021 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/6 monitor/msft: Fix uuid.u128 format

From: Luiz Augusto von Dentz <[email protected]>

128 bits are actually 16 octecs not 8.

---
 monitor/msft.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor/msft.h +1 -1
index 79692537f..d2921f4c8 100644
@@ -87,7 +87,7 @@ struct msft_le_monitor_adv_uuid {
 	union {
 		uint16_t u16;
 		uint32_t u32;
-		uint8_t  u128[8];
+		uint8_t  u128[16];
 	} value;
 } __attribute__((packed));
 
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 2/6 monitor/msft: Add feature bits definition

From: Luiz Augusto von Dentz <[email protected]>

This adds the feature bits definition used in
HCI_VS_MSFT_Read_Supported_Features.

---
 monitor/msft.h | 7 +++++++
 1 file changed, 7 insertions(+)
monitor/msft.h +7 -0
index d2921f4c8..e6e3019be 100644
@@ -30,6 +30,13 @@ struct msft_cmd_read_supported_features {
 	uint8_t subcmd;
 } __attribute__((packed));
 
+#define MSFT_MONITOR_BREDR_RSSI			BIT(0)
+#define MSFT_MONITOR_LE_RSSI			BIT(1)
+#define MSFT_MONITOR_LE_LEGACY_RSSI		BIT(2)
+#define MSFT_MONITOR_LE_ADV			BIT(3)
+#define MSFT_MONITOR_SSP_VALIDATION		BIT(4)
+#define MSFT_MONITOR_LE_ADV_CONTINUOS		BIT(5)
+
 struct msft_rsp_read_supported_features {
 	uint8_t  status;
 	uint8_t  subcmd;
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH 3/6 emulator/vhci: Fix writing msft_opcode using binary format

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

debugfs expects values in string format not binary format.

---
 emulator/vhci.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
emulator/vhci.c +10 -1
index f8560e0c5..59ad1ecb8 100644
@@ -230,7 +230,16 @@ int vhci_set_force_wakeup(struct vhci *vhci, bool enable)
 
 int vhci_set_msft_opcode(struct vhci *vhci, uint16_t opcode)
 {
-	return vhci_debugfs_write(vhci, "msft_opcode", &opcode, sizeof(opcode));
+	int err;
+	char val[7];
+
+	snprintf(val, sizeof(val), "0x%4x", opcode);
+
+	err = vhci_debugfs_write(vhci, "msft_opcode", &val, sizeof(val));
+	if (err)
+		return err;
+
+	return btdev_set_msft_opcode(vhci->btdev, opcode);
 }
 
 int vhci_set_aosp_capable(struct vhci *vhci, bool enable)
Signature · 1 line
2.31.1
author maintainer
#3 lore raw

PATCH 4/6 btdev: Use Linux Foundation as manufacturer

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This makes the emulator use Linux Foundation manufacturer id which shall be simpler to distinguish emulator instances since it is unlikely there will be other vendors using it.

---
 emulator/btdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
emulator/btdev.c +1 -1
index d9c55d99d..18aefed11 100644
@@ -6263,7 +6263,7 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id)
 
 	btdev->type = type;
 	btdev->id = id;
-	btdev->manufacturer = 63;
+	btdev->manufacturer = 1521;
 	btdev->revision = 0x0000;
 
 	switch (btdev->type) {
Signature · 1 line
2.31.1
author maintainer
#4 lore raw

PATCH 5/6 monitor: Enable decoding of MSFT extension with emulator

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This enables decoding MSFT extension with emulator instances since it shall be the only one using Linux Foundation as manufacturer.

---
 monitor/packet.c | 9 +++++++++
 1 file changed, 9 insertions(+)
monitor/packet.c +9 -0
index 9b81cfc89..9030f2493 100644
@@ -4021,6 +4021,15 @@ void packet_monitor(struct timeval *tv, struct ucred *cred,
 				 */
 				index_list[index].msft_opcode = 0xFCF0;
 				break;
+			case 1521:
+				/*
+				 * Emulator controllers use Linux Foundation as
+				 * manufacturer and support the
+				 * Microsoft vendor extenions using
+				 * 0xFC1E for VsMsftOpCode.
+				 */
+				index_list[index].msft_opcode = 0xFC1E;
+				break;
 			}
 		}
 
Signature · 1 line
2.31.1
author maintainer
#5 lore raw

PATCH 6/6 emulator: Add initial support for MSFT vendor commands

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds the initial support for MSFT vendor commands and enable them when in btvirt:

< HCI Command: Microsoft Ex.. (0x3f|0x001e) plen 1

      Read Supported Features (0x00)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 14

Microsoft Extension (0x3f|0x001e) ncmd 1 Read Supported Features (0x00)
Status: Success (0x00)
Features: 0x3f 0x00 0x00 0x00 0x00 0x00 0x00 0x00
RSSI Monitoring feature for BR/EDR RSSI Monitoring feature for LE connections RSSI Monitoring of LE advertisements Advertising Monitoring of LE advertisements Verifying the validity of P-192 and P-256 keys Continuous Advertising Monitoring
Event prefix length: 0
Event prefix:
< HCI Command: Microsoft Ex.. (0x3f|0x001e) plen 2

      LE Set Advertisement Filter Enable (0x05)
        Enable: All filter conditions (0x01)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 5

      Microsoft Extension (0x3f|0x001e) ncmd 1
      LE Set Advertisement Filter Enable (0x05)
        Status: Success (0x00)
---
 emulator/btdev.c | 245 ++++++++++++++++++++++++++++++++++++++++++-----
 emulator/main.c  |   2 +
 2 files changed, 223 insertions(+), 24 deletions(-)
emulator/btdev.c +221 -24
index 18aefed11..096ba2da4 100644
@@ -33,6 +33,7 @@
 #include "src/shared/ecc.h"
 #include "src/shared/queue.h"
 #include "monitor/bt.h"
+#include "monitor/msft.h"
 #include "btdev.h"
 
 #define AL_SIZE			16
@@ -139,6 +140,7 @@ struct btdev {
 	uint8_t  le_states[8];
 	const struct btdev_cmd *cmds;
 	uint16_t msft_opcode;
+	const struct btdev_cmd *msft_cmds;
 	bool aosp_capable;
 
 	uint16_t default_link_policy;
@@ -6440,41 +6442,76 @@ static void num_completed_packets(struct btdev *btdev, uint16_t handle)
 	}
 }
 
+static const struct btdev_cmd *run_cmd(struct btdev *btdev,
+					const struct btdev_cmd *cmd,
+					const void *data, uint8_t len)
+{
+	uint8_t status = BT_HCI_ERR_UNKNOWN_COMMAND;
+	int err;
+
+	err = cmd->func(btdev, data, len);
+	switch (err) {
+	case 0:
+		return cmd;
+	case -ENOTSUP:
+		status = BT_HCI_ERR_UNKNOWN_COMMAND;
+		break;
+	case -EINVAL:
+		status = BT_HCI_ERR_INVALID_PARAMETERS;
+		break;
+	case -EPERM:
+		status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		break;
+	default:
+		status = BT_HCI_ERR_UNSPECIFIED_ERROR;
+		break;
+	}
+
+	cmd_status(btdev, status, cmd->opcode);
+
+	return NULL;
+}
+
+static const struct btdev_cmd *msft_cmd(struct btdev *btdev, const void *data,
+								uint8_t len)
+{
+	const struct btdev_cmd *cmd;
+
+	for (cmd = btdev->msft_cmds; cmd->func; cmd++) {
+		if (cmd->opcode != ((uint8_t *)data)[0])
+			continue;
+
+		return run_cmd(btdev, cmd, data, len);
+	}
+
+	util_debug(btdev->debug_callback, btdev->debug_data,
+			"Unsupported MSFT subcommand 0x%2.2x\n",
+			((uint8_t *)data)[0]);
+
+	cmd_status(btdev, BT_HCI_ERR_UNKNOWN_COMMAND, btdev->msft_opcode);
+
+	return NULL;
+}
+
 static const struct btdev_cmd *default_cmd(struct btdev *btdev, uint16_t opcode,
 						const void *data, uint8_t len)
 {
 	const struct btdev_cmd *cmd;
-	uint8_t status = BT_HCI_ERR_UNKNOWN_COMMAND;
-	int err;
+
+	if (btdev->msft_opcode == opcode)
+		return msft_cmd(btdev, data, len);
 
 	for (cmd = btdev->cmds; cmd->func; cmd++) {
 		if (cmd->opcode != opcode)
 			continue;
 
-		err = cmd->func(btdev, data, len);
-		switch (err) {
-		case 0:
-			return cmd;
-		case -ENOTSUP:
-			status = BT_HCI_ERR_UNKNOWN_COMMAND;
-			goto failed;
-		case -EINVAL:
-			status = BT_HCI_ERR_INVALID_PARAMETERS;
-			goto failed;
-		case -EPERM:
-			status = BT_HCI_ERR_COMMAND_DISALLOWED;
-			goto failed;
-		default:
-			status = BT_HCI_ERR_UNSPECIFIED_ERROR;
-			goto failed;
-		}
+		return run_cmd(btdev, cmd, data, len);
 	}
 
 	util_debug(btdev->debug_callback, btdev->debug_data,
 			"Unsupported command 0x%4.4x\n", opcode);
 
-failed:
-	cmd_status(btdev, status, opcode);
+	cmd_status(btdev, BT_HCI_ERR_UNKNOWN_COMMAND, opcode);
 
 	return NULL;
 }
@@ -6719,14 +6756,174 @@ bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
 	return false;
 }
 
+static int cmd_msft_read_features(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	struct msft_rsp_read_supported_features rsp;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.status = BT_HCI_ERR_SUCCESS;
+	rsp.subcmd = MSFT_SUBCMD_READ_SUPPORTED_FEATURES;
+	rsp.features[0] = MSFT_MONITOR_BREDR_RSSI | MSFT_MONITOR_LE_RSSI |
+				MSFT_MONITOR_LE_LEGACY_RSSI |
+				MSFT_MONITOR_LE_ADV |
+				MSFT_MONITOR_SSP_VALIDATION |
+				MSFT_MONITOR_LE_ADV_CONTINUOS;
+
+	cmd_complete(dev, dev->msft_opcode, &rsp, sizeof(rsp));
+
+	return 0;
+}
+
+static int cmd_msft_monitor_rssi(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	const struct msft_cmd_monitor_rssi *cmd = data;
+	struct msft_rsp_monitor_rssi rsp;
+	struct btdev_conn *conn;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.status = BT_HCI_ERR_SUCCESS;
+	rsp.subcmd = MSFT_SUBCMD_MONITOR_RSSI;
+
+	conn = queue_find(dev->conns, match_handle,
+				UINT_TO_PTR(le16_to_cpu(cmd->handle)));
+	if (!conn)
+		rsp.status = BT_HCI_ERR_UNKNOWN_CONN_ID;
+
+	cmd_complete(dev, dev->msft_opcode, &rsp, sizeof(rsp));
+
+	return 0;
+}
+
+static int cmd_msft_cancel_monitor_rssi(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	const struct msft_cmd_cancel_monitor_rssi *cmd = data;
+	struct msft_rsp_cancel_monitor_rssi rsp;
+	struct btdev_conn *conn;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.status = BT_HCI_ERR_SUCCESS;
+	rsp.subcmd = MSFT_SUBCMD_CANCEL_MONITOR_RSSI;
+
+	conn = queue_find(dev->conns, match_handle,
+				UINT_TO_PTR(le16_to_cpu(cmd->handle)));
+	if (!conn)
+		rsp.status = BT_HCI_ERR_UNKNOWN_CONN_ID;
+
+	cmd_complete(dev, dev->msft_opcode, &rsp, sizeof(rsp));
+
+	return 0;
+}
+
+static int cmd_msft_le_monitor_adv(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	const struct msft_cmd_le_monitor_adv *cmd = data;
+	struct msft_rsp_le_monitor_adv rsp;
+	static uint8_t handle;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.status = BT_HCI_ERR_SUCCESS;
+	rsp.subcmd = MSFT_SUBCMD_LE_MONITOR_ADV;
+
+	switch (cmd->type) {
+	case MSFT_LE_MONITOR_ADV_PATTERN:
+	case MSFT_LE_MONITOR_ADV_UUID:
+	case MSFT_LE_MONITOR_ADV_IRK:
+	case MSFT_LE_MONITOR_ADV_ADDR:
+		rsp.handle = handle++;
+		break;
+	default:
+		rsp.status = BT_HCI_ERR_INVALID_PARAMETERS;
+		break;
+	}
+
+	cmd_complete(dev, dev->msft_opcode, &rsp, sizeof(rsp));
+
+	return 0;
+}
+
+static int cmd_msft_le_cancel_monitor_adv(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	struct msft_rsp_le_cancel_monitor_adv rsp;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.status = BT_HCI_ERR_SUCCESS;
+	rsp.subcmd = MSFT_SUBCMD_LE_CANCEL_MONITOR_ADV;
+
+	cmd_complete(dev, dev->msft_opcode, &rsp, sizeof(rsp));
+
+	return 0;
+}
+
+static int cmd_msft_le_monitor_adv_enable(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	struct msft_rsp_le_cancel_monitor_adv rsp;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.status = BT_HCI_ERR_SUCCESS;
+	rsp.subcmd = MSFT_SUBCMD_LE_MONITOR_ADV_ENABLE;
+
+	cmd_complete(dev, dev->msft_opcode, &rsp, sizeof(rsp));
+
+	return 0;
+}
+
+static int cmd_msft_read_abs_rssi(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	struct msft_rsp_read_abs_rssi rsp;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.status = BT_HCI_ERR_SUCCESS;
+	rsp.subcmd = MSFT_SUBCMD_READ_ABS_RSSI;
+
+	cmd_complete(dev, dev->msft_opcode, &rsp, sizeof(rsp));
+
+	return 0;
+}
+
+#define CMD_MSFT \
+	CMD(MSFT_SUBCMD_READ_SUPPORTED_FEATURES, cmd_msft_read_features, \
+						NULL), \
+	CMD(MSFT_SUBCMD_MONITOR_RSSI, cmd_msft_monitor_rssi, NULL), \
+	CMD(MSFT_SUBCMD_CANCEL_MONITOR_RSSI, cmd_msft_cancel_monitor_rssi, \
+						NULL), \
+	CMD(MSFT_SUBCMD_LE_MONITOR_ADV, cmd_msft_le_monitor_adv, NULL),	\
+	CMD(MSFT_SUBCMD_LE_CANCEL_MONITOR_ADV, cmd_msft_le_cancel_monitor_adv, \
+						NULL), \
+	CMD(MSFT_SUBCMD_LE_MONITOR_ADV_ENABLE, cmd_msft_le_monitor_adv_enable, \
+						NULL), \
+	CMD(MSFT_SUBCMD_READ_ABS_RSSI, cmd_msft_read_abs_rssi, NULL)
+
+static const struct btdev_cmd cmd_msft[] = {
+	CMD_MSFT,
+	{}
+};
+
 int btdev_set_msft_opcode(struct btdev *btdev, uint16_t opcode)
 {
 	if (!btdev)
 		return -EINVAL;
 
-	btdev->msft_opcode = opcode;
-
-	return 0;
+	switch (btdev->type) {
+	case BTDEV_TYPE_BREDRLE:
+	case BTDEV_TYPE_BREDRLE50:
+	case BTDEV_TYPE_BREDRLE52:
+		btdev->msft_opcode = opcode;
+		btdev->msft_cmds = cmd_msft;
+		return 0;
+	case BTDEV_TYPE_BREDR:
+	case BTDEV_TYPE_LE:
+	case BTDEV_TYPE_AMP:
+	case BTDEV_TYPE_BREDR20:
+	default:
+		return -ENOTSUP;
+	}
 }
 
 int btdev_set_aosp_capable(struct btdev *btdev, bool enable)
emulator/main.c +2 -0
index f64d46a5e..3c215efbc 100644
@@ -192,6 +192,8 @@ int main(int argc, char *argv[])
 
 		if (debug_enabled)
 			vhci_set_debug(vhci, vhci_debug, UINT_TO_PTR(i), NULL);
+
+		vhci_set_msft_opcode(vhci, 0xfc1e);
 	}
 
 	if (serial_enabled) {
Signature · 1 line
2.31.1
#6 lore raw
In reply to Luiz Augusto von Dentz

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=567367

---Test result---

Test Summary:

CheckPatch                    PASS      8.45 seconds
GitLint                       PASS      5.65 seconds
Prep - Setup ELL              PASS      39.54 seconds
Build - Prep                  PASS      0.44 seconds
Build - Configure             PASS      7.45 seconds
Build - Make                  PASS      169.13 seconds
Make Check                    PASS      9.24 seconds
Make Distcheck                PASS      202.33 seconds
Build w/ext ELL - Configure   PASS      7.73 seconds
Build w/ext ELL - Make        PASS      156.56 seconds

---
Regards,
Linux Bluetooth