From 313340f1c6abfa0062813cf3ff7b4c31f798240a Mon Sep 17 00:00:00 2001 From: Charlie Boutier Date: Fri, 15 Mar 2024 17:29:17 +0000 Subject: [PATCH] intel driver: check the vendorId and productId --- bumble/drivers/intel.py | 44 +++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/bumble/drivers/intel.py b/bumble/drivers/intel.py index c65d5281..e613c1e5 100644 --- a/bumble/drivers/intel.py +++ b/bumble/drivers/intel.py @@ -29,6 +29,17 @@ from bumble.hci import ( # ----------------------------------------------------------------------------- logger = logging.getLogger(__name__) +# ----------------------------------------------------------------------------- +# Constant +# ----------------------------------------------------------------------------- + +INTEL_USB_PRODUCTS = { + # Intel AX210 + (0x8087, 0x0032), + # Intel BE200 + (0x8087, 0x0036), +} + # ----------------------------------------------------------------------------- # HCI Commands # ----------------------------------------------------------------------------- @@ -52,13 +63,34 @@ class Driver(common.Driver): def __init__(self, host): self.host = host - @classmethod - async def for_host(cls, host): # type: ignore - # Only instantiate this driver if explicitly selected - if host.hci_metadata.get("driver") == "intel": - return cls(host) + @staticmethod + def check(host): + driver = host.hci_metadata.get("driver") + if driver == "intel": + return True - return None + vendor_id = host.hci_metadata.get("vendor_id") + product_id = host.hci_metadata.get("product_id") + + if vendor_id is None or product_id is None: + logger.debug("USB metadata not sufficient") + return False + + if (vendor_id, product_id) not in INTEL_USB_PRODUCTS: + logger.debug( + f"USB device ({vendor_id:04X}, {product_id:04X}) " "not in known list" + ) + return False + + return True + + @classmethod + async def for_host(cls, host, force=False): # type: ignore + # Only instantiate this driver if explicitly selected + if not force and not cls.check(host): + return None + + return cls(host) async def init_controller(self): self.host.ready = True