Skip to contentSkip to conversation

Bluetooth: btmtk: add event filter to filter specific event

PATCH Superseded Chris Lu 3 participants 4 messages Apr 7

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Chris Lu

author
#0 lore raw

PATCH 1/1 Bluetooth: btmtk: add event filter to filter specific event

Due to some Bluetooth hosts have mechanism to detect invalid events, causing abnormal behavior. Add a event filter to prevent debugging events from being sent to host.

---
 drivers/bluetooth/btmtk.c | 22 ++++++++++++++++++++++
 drivers/bluetooth/btmtk.h |  7 +++++++
 drivers/bluetooth/btusb.c |  2 ++
 3 files changed, 31 insertions(+)
drivers/bluetooth/btmtk.c +22 -0
index 55516b4602db..302d6ddf9062 100644
@@ -1503,6 +1503,28 @@ int btmtk_usb_shutdown(struct hci_dev *hdev)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(btmtk_usb_shutdown);
+
+int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_event_hdr *hdr = (void *)skb->data;
+
+	if (hdr->evt == HCI_EV_CMD_COMPLETE) {
+		struct hci_ev_cmd_complete *ec;
+		u16 opcode;
+
+		ec = (void *)(skb->data + HCI_EVENT_HDR_SIZE);
+		opcode = __le16_to_cpu(ec->opcode);
+
+		/* Filter vendor opcode */
+		if (opcode == 0xfc5d) {
+			kfree_skb(skb);
+			return 0;
+		}
+	}
+
+	return hci_recv_frame(hdev, skb);
+}
+EXPORT_SYMBOL_GPL(btmtk_recv_event);
 #endif
 
 MODULE_AUTHOR("Sean Wang <[email protected]>");
drivers/bluetooth/btmtk.h +7 -0
index adaf385626ee..08b73927c8f3 100644
@@ -218,6 +218,8 @@ int btmtk_usb_suspend(struct hci_dev *hdev);
 int btmtk_usb_setup(struct hci_dev *hdev);
 
 int btmtk_usb_shutdown(struct hci_dev *hdev);
+
+int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb);
 #else
 
 static inline int btmtk_set_bdaddr(struct hci_dev *hdev,
@@ -296,4 +298,9 @@ static inline int btmtk_usb_shutdown(struct hci_dev *hdev)
 {
 	return -EOPNOTSUPP;
 }
+
+static inline int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	return -EOPNOTSUPP;
+}
 #endif
drivers/bluetooth/btusb.c +2 -0
index f9d515ee9124..daf8a387e660 100644
@@ -4150,6 +4150,8 @@ static int btusb_probe(struct usb_interface *intf,
 	} else if (id->driver_info & BTUSB_MEDIATEK) {
 		/* Allocate extra space for Mediatek device */
 		priv_size += sizeof(struct btmtk_data);
+
+		data->recv_event = btmtk_recv_event;
 	}
 
 	data->recv_acl = hci_recv_frame;
Signature · 1 line
2.45.2
#1 lore raw

Dear Chris,

Thank you for the patch.

Am 07.04.26 um 08:47 schrieb Chris Lu:

Quoted 2 lines

Due to some Bluetooth hosts have mechanism to detect invalid events, causing abnormal behavior.

Sorry, this description is much too short and general. Please elaborate, and document details.

Quoted 1 line

Add a event filter to prevent debugging events from being sent to host.

a*n*

What are debugging events, and how can they be detected?

Quoted 1 line

Should there be a Fixes: tag, so it gets backported?

Quoted 67 lines
---
  drivers/bluetooth/btmtk.c | 22 ++++++++++++++++++++++
  drivers/bluetooth/btmtk.h |  7 +++++++
  drivers/bluetooth/btusb.c |  2 ++
  3 files changed, 31 insertions(+)
drivers/bluetooth/btmtk.c +22 -0
index 55516b4602db..302d6ddf9062 100644
@@ -1503,6 +1503,28 @@ int btmtk_usb_shutdown(struct hci_dev *hdev)
  	return 0;
  }
  EXPORT_SYMBOL_GPL(btmtk_usb_shutdown);
+
+int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_event_hdr *hdr = (void *)skb->data;
+
+	if (hdr->evt == HCI_EV_CMD_COMPLETE) {
+		struct hci_ev_cmd_complete *ec;
+		u16 opcode;
+
+		ec = (void *)(skb->data + HCI_EVENT_HDR_SIZE);
+		opcode = __le16_to_cpu(ec->opcode);
+
+		/* Filter vendor opcode */
+		if (opcode == 0xfc5d) {
+			kfree_skb(skb);
+			return 0;
+		}
+	}
+
+	return hci_recv_frame(hdev, skb);
+}
+EXPORT_SYMBOL_GPL(btmtk_recv_event);
  #endif
 
  MODULE_AUTHOR("Sean Wang <[email protected]>");
drivers/bluetooth/btmtk.h +7 -0
index adaf385626ee..08b73927c8f3 100644
@@ -218,6 +218,8 @@ int btmtk_usb_suspend(struct hci_dev *hdev);
  int btmtk_usb_setup(struct hci_dev *hdev);
 
  int btmtk_usb_shutdown(struct hci_dev *hdev);
+
+int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb);
  #else
 
  static inline int btmtk_set_bdaddr(struct hci_dev *hdev,
@@ -296,4 +298,9 @@ static inline int btmtk_usb_shutdown(struct hci_dev *hdev)
  {
  	return -EOPNOTSUPP;
  }
+
+static inline int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	return -EOPNOTSUPP;
+}
  #endif
drivers/bluetooth/btusb.c +0 -0
index f9d515ee9124..daf8a387e660 100644

drivers/bluetooth/btusb.c static int btusb_probe(struct usb_interface *intf, · line 4157

Quoted 8 lines
drivers/bluetooth/btusb.c +2 -0
@@ -4150,6 +4150,8 @@ static int btusb_probe(struct usb_interface *intf,
  	} else if (id->driver_info & BTUSB_MEDIATEK) {
  		/* Allocate extra space for Mediatek device */
  		priv_size += sizeof(struct btmtk_data);
+
+		data->recv_event = btmtk_recv_event;
  	}
 
  	data->recv_acl = hci_recv_frame;

Kind regards,

Paul

#2 lore raw

Dear Paul,

Quoted 19 lines · Paul Menzel

External email : Please do not click links or open attachments until you have verified the sender or the content.

Dear Chris,

Thank you for the patch.

Am 07.04.26 um 08:47 schrieb Chris Lu:

Quoted 3 lines

Due to some Bluetooth hosts have mechanism to detect invalid events,
causing abnormal behavior.

Sorry, this description is much too short and general. Please elaborate,
and document details.

Quoted 6 lines
Quoted 2 lines

Add a event filter to prevent debugging events from being sent to host.

a*n*

What are debugging events, and how can they be detected?

Thanks for your suggestion.
I'll submit v2 to revise the commit message to avoid using vague descriptions.

Quoted 4 lines
Quoted 2 lines

Should there be a Fixes: tag, so it gets backported?

No, it's not an issue derived from previous driver changes.

Quoted 78 lines
Quoted 78 lines

---

  drivers/bluetooth/btmtk.c | 22 ++++++++++++++++++++++
  drivers/bluetooth/btmtk.h |  7 +++++++
  drivers/bluetooth/btusb.c |  2 ++
  3 files changed, 31 insertions(+)
drivers/bluetooth/btmtk.c +22 -0
index 55516b4602db..302d6ddf9062 100644
@@ -1503,6 +1503,28 @@ int btmtk_usb_shutdown(struct hci_dev *hdev)
       return 0;
   }
   EXPORT_SYMBOL_GPL(btmtk_usb_shutdown);
+
+int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
+{
+     struct hci_event_hdr *hdr = (void *)skb->data;
+
+     if (hdr->evt == HCI_EV_CMD_COMPLETE) {
+             struct hci_ev_cmd_complete *ec;
+             u16 opcode;
+
+             ec = (void *)(skb->data + HCI_EVENT_HDR_SIZE);
+             opcode = __le16_to_cpu(ec->opcode);
+
+             /* Filter vendor opcode */
+             if (opcode == 0xfc5d) {
+                     kfree_skb(skb);
+                     return 0;
+             }
+     }
+
+     return hci_recv_frame(hdev, skb);
+}
+EXPORT_SYMBOL_GPL(btmtk_recv_event);
   #endif
 
   MODULE_AUTHOR("Sean Wang <[email protected]>");
drivers/bluetooth/btmtk.h +4 -0
index adaf385626ee..08b73927c8f3 100644
@@ -218,6 +218,8 @@ int btmtk_usb_suspend(struct hci_dev *hdev);
   int btmtk_usb_setup(struct hci_dev *hdev);
 
   int btmtk_usb_shutdown(struct hci_dev *hdev);
+
+int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb);
   #else
 
   static inline int btmtk_set_bdaddr(struct hci_dev *hdev,
@@ -296,4 +298,9 @@ static inline int btmtk_usb_shutdown(struct
 hci_dev *hdev)
   {
       return -EOPNOTSUPP;
   }
+
+static inline int btmtk_recv_event(struct hci_dev *hdev, struct

sk_buff *skb)

drivers/bluetooth/btmtk.h +3 -0
+{
+     return -EOPNOTSUPP;
+}

  #endif

drivers/bluetooth/btusb.c +2 -0
index f9d515ee9124..daf8a387e660 100644
@@ -4150,6 +4150,8 @@ static int btusb_probe(struct usb_interface
 *intf,
       } else if (id->driver_info & BTUSB_MEDIATEK) {
               /* Allocate extra space for Mediatek device */
               priv_size += sizeof(struct btmtk_data);
+
+             data->recv_event = btmtk_recv_event;
       }
 
Quoted 6 lines
Quoted 1 line

      data->recv_acl = hci_recv_frame;

Kind regards,

Paul

Thanks,
Chris Lu

#3 lore raw
In reply to Chris Lu

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

---Test result---

Test Summary:

CheckPatch                    PENDING   0.47 seconds
GitLint                       PENDING   0.33 seconds
SubjectPrefix                 PASS      0.11 seconds
BuildKernel                   PASS      26.07 seconds
CheckAllWarning               PASS      30.19 seconds
CheckSparse                   PASS      27.56 seconds
BuildKernel32                 PASS      25.19 seconds
TestRunnerSetup               PASS      564.03 seconds
TestRunner_l2cap-tester       PASS      27.56 seconds
TestRunner_iso-tester         PASS      41.09 seconds
TestRunner_bnep-tester        PASS      6.25 seconds
TestRunner_mgmt-tester        FAIL      114.17 seconds
TestRunner_rfcomm-tester      PASS      9.37 seconds
TestRunner_sco-tester         FAIL      14.11 seconds
TestRunner_ioctl-tester       PASS      10.18 seconds
TestRunner_mesh-tester        FAIL      13.13 seconds
TestRunner_smp-tester         PASS      8.49 seconds
TestRunner_userchan-tester    PASS      6.57 seconds
IncrementalBuild              PENDING   0.83 seconds

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

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

##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success Failed 0.104 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected

BUG: sleeping function called from invalid context at net/core/sock.c:3782

Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases

Mesh - Send cancel - 1                               Timed out    2.714 seconds
Mesh - Send cancel - 2                               Timed out    1.994 seconds

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth