All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tedd Ho-Jeong An <hj.tedd.an@gmail.com>
To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org
Subject: [RFC BlueZ v2] monitor: Fix the incorrect vendor name
Date: Wed, 14 Apr 2021 18:48:28 -0700	[thread overview]
Message-ID: <20210415014828.422303-1-hj.tedd.an@gmail.com> (raw)
In-Reply-To: <Tedd Ho-Jeong An <tedd.an@intel.com>

From: Tedd Ho-Jeong An <tedd.an@intel.com>

This patch fixes the vendor name is alwasy shown as "Microsoft".

< HCI Command: Microsoft Secure Send (0x3f|0x0009) plen 249
        Type: Data fragment (0x01)
> HCI Event: Command Complete (0x0e) plen 4
      Microsoft Secure Send (0x3f|0x0009) ncmd 31
        Status: Success (0x00)
---
 monitor/packet.c | 56 +++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 12 deletions(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index d729a01cc..30ed9944c 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -266,6 +266,7 @@ struct index_data {
 	uint8_t  bdaddr[6];
 	uint16_t manufacturer;
 	uint16_t msft_opcode;
+	uint8_t  msft_evt_code;
 	size_t   frame;
 };
 
@@ -3940,6 +3941,7 @@ void packet_monitor(struct timeval *tv, struct ucred *cred,
 			memcpy(index_list[index].bdaddr, ni->bdaddr, 6);
 			index_list[index].manufacturer = fallback_manufacturer;
 			index_list[index].msft_opcode = BT_HCI_CMD_NOP;
+			index_list[index].msft_evt_code = 0x00;
 		}
 
 		addr2str(ni->bdaddr, str);
@@ -4006,9 +4008,11 @@ void packet_monitor(struct timeval *tv, struct ucred *cred,
 				/*
 				 * Intel controllers that support the
 				 * Microsoft vendor extension are using
-				 * 0xFC1E for VsMsftOpCode.
+				 * 0xFC1E for VsMsftOpCode and 0x50 for event
+				 * code.
 				 */
 				index_list[index].msft_opcode = 0xFC1E;
+				index_list[index].msft_evt_code = 0x50;
 				break;
 			case 93:
 				/*
@@ -9323,7 +9327,7 @@ static const char *get_supported_command(int bit)
 	return NULL;
 }
 
-static const char *current_vendor_str(void)
+static const char *current_vendor_str(uint16_t ocf)
 {
 	uint16_t manufacturer, msft_opcode;
 
@@ -9335,7 +9339,35 @@ static const char *current_vendor_str(void)
 		msft_opcode = BT_HCI_CMD_NOP;
 	}
 
-	if (msft_opcode != BT_HCI_CMD_NOP)
+	if (msft_opcode != BT_HCI_CMD_NOP &&
+				cmd_opcode_ocf(msft_opcode) == ocf)
+		return "Microsoft";
+
+	switch (manufacturer) {
+	case 2:
+		return "Intel";
+	case 15:
+		return "Broadcom";
+	case 93:
+		return "Realtek";
+	}
+
+	return NULL;
+}
+
+static const char *current_vendor_evt_str(uint8_t evt)
+{
+	uint16_t manufacturer, msft_evt_code;
+
+	if (index_current < MAX_INDEX) {
+		manufacturer = index_list[index_current].manufacturer;
+		msft_evt_code = index_list[index_current].msft_evt_code;
+	} else {
+		manufacturer = fallback_manufacturer;
+		msft_evt_code = 0x00;
+	}
+
+	if (msft_evt_code == evt)
 		return "Microsoft";
 
 	switch (manufacturer) {
@@ -9378,18 +9410,18 @@ static const struct vendor_ocf *current_vendor_ocf(uint16_t ocf)
 
 static const struct vendor_evt *current_vendor_evt(uint8_t evt)
 {
-	uint16_t manufacturer, msft_opcode;
+	uint16_t manufacturer, msft_evt_code;
 
 	if (index_current < MAX_INDEX) {
 		manufacturer = index_list[index_current].manufacturer;
-		msft_opcode = index_list[index_current].msft_opcode;
+		msft_evt_code = index_list[index_current].msft_evt_code;
 	} else {
 		manufacturer = fallback_manufacturer;
-		msft_opcode = BT_HCI_CMD_NOP;
+		msft_evt_code = 0x00;
 	}
 
-	if (msft_opcode != BT_HCI_CMD_NOP)
-		return NULL;
+	if (msft_evt_code == evt)
+		return msft_vendor_evt();
 
 	switch (manufacturer) {
 	case 2:
@@ -9573,7 +9605,7 @@ static void cmd_complete_evt(const void *data, uint8_t size)
 			const struct vendor_ocf *vnd = current_vendor_ocf(ocf);
 
 			if (vnd) {
-				const char *str = current_vendor_str();
+				const char *str = current_vendor_str(ocf);
 
 				if (str) {
 					snprintf(vendor_str, sizeof(vendor_str),
@@ -9665,7 +9697,7 @@ static void cmd_status_evt(const void *data, uint8_t size)
 			const struct vendor_ocf *vnd = current_vendor_ocf(ocf);
 
 			if (vnd) {
-				const char *str = current_vendor_str();
+				const char *str = current_vendor_str(ocf);
 
 				if (str) {
 					snprintf(vendor_str, sizeof(vendor_str),
@@ -11018,7 +11050,7 @@ static void vendor_evt(const void *data, uint8_t size)
 	const struct vendor_evt *vnd = current_vendor_evt(subevent);
 
 	if (vnd) {
-		const char *str = current_vendor_str();
+		const char *str = current_vendor_evt_str(subevent);
 
 		if (str) {
 			snprintf(vendor_str, sizeof(vendor_str),
@@ -11419,7 +11451,7 @@ void packet_hci_command(struct timeval *tv, struct ucred *cred, uint16_t index,
 			const struct vendor_ocf *vnd = current_vendor_ocf(ocf);
 
 			if (vnd) {
-				const char *str = current_vendor_str();
+				const char *str = current_vendor_str(ocf);
 
 				if (str) {
 					snprintf(vendor_str, sizeof(vendor_str),
-- 
2.25.1


  parent reply	other threads:[~2021-04-15  1:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Tedd Ho-Jeong An <tedd.an@intel.com>
2021-04-14  4:38 ` [BlueZ] monitor: Fix the incorrect vendor name Tedd Ho-Jeong An
2021-04-14  5:07   ` bluez.test.bot
2021-04-14 10:08   ` Marcel Holtmann
2021-04-15  2:25     ` An, Tedd
2021-04-15  3:47       ` Archie Pusaka
2021-04-15  4:34         ` Tedd Ho-Jeong An
2021-04-16  5:23         ` Marcel Holtmann
2021-04-15  1:48 ` Tedd Ho-Jeong An [this message]
2021-04-15  2:35   ` [RFC,BlueZ,v2] " bluez.test.bot
2021-04-16  5:56 ` [BlueZ PATCH] monitor: Update manpage Tedd Ho-Jeong An
2021-04-16  6:43   ` [BlueZ] " bluez.test.bot
2021-04-16 20:06 ` [BlueZ PATCH] monitor: Add Intel read supported VS features command Tedd Ho-Jeong An
2021-04-16 20:39   ` [BlueZ] " bluez.test.bot
2021-04-17  0:34 ` [BlueZ v2] " Tedd Ho-Jeong An
2021-04-17  1:30   ` [BlueZ,v2] " bluez.test.bot
2021-04-19 13:01   ` [BlueZ v2] " Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210415014828.422303-1-hj.tedd.an@gmail.com \
    --to=hj.tedd.an@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.