Beispiel #1
0
 def get_controller_class(self, controller):
     interface = self.get_property_from_wmi(
         controller["identifiers"]["instance_id"],
         PnpDeviceProperties.INTERFACE)
     if interface:
         return shared.USBControllerTypes(interface)
     service = self.get_property_from_wmi(
         controller["identifiers"]["instance_id"],
         PnpDeviceProperties.SERVICE)
     if not isinstance(service, str):
         shared.debug(
             f"Unknown controller type for interface {interface} and service {service}!"
         )
         return shared.USBControllerTypes.Unknown
     if service.lower() == "usbxhci":
         return shared.USBControllerTypes.XHCI
     elif service.lower() == "usbehci":
         return shared.USBControllerTypes.EHCI
     elif service.lower() == "usbohci":
         return shared.USBControllerTypes.OHCI
     elif service.lower() == "usbuhci":
         return shared.USBControllerTypes.UHCI
     else:
         shared.debug(
             f"Unknown controller type for interface {interface} and service {service}!"
         )
         return shared.USBControllerTypes.Unknown
Beispiel #2
0
    def choose_matching_key(self, controller):
        if "bus_number" in controller["identifiers"]:
            # M1 Macs
            return {"IOPropertyMatch": {"bus-number": binascii.a2b_hex(hexswap(hex(controller["identifiers"]["bus_number"])[2:].zfill(8)))}}

        elif not self.settings["use_native"] and self.check_unique(lambda c: c["identifiers"]["acpi_path"].rpartition(".")[2], lambda c: "acpi_path" in c["identifiers"], controller):
            # Unique ACPI name
            # Disable if using native because we don't know if it'll conflict
            # TODO: Check this maybe?
            shared.debug(f"Using ACPI path: {controller['identifiers']['acpi_path']}")
            return {"IONameMatch": controller["identifiers"]["acpi_path"].rpartition(".")[2]}

        elif "bdf" in controller["identifiers"]:
            # Use bus-device-function
            return {"IOPropertyMatch": {"pcidebug": ":".join([str(i) for i in controller["identifiers"]["bdf"]])}}

        elif self.check_unique(lambda c: c["identifiers"]["path"], lambda c: "path" in c["identifiers"], controller):
            # Use IORegistry path
            return {"IOPathMatch": controller["identifiers"]["path"]}

        elif self.check_unique(lambda c: c["identifiers"]["pci_id"], lambda c: "pci_id" in c["identifiers"], controller):
            # Use PCI ID
            pci_id: list[str] = controller["identifiers"]["pci_id"]
            return {"IOPCIPrimaryMatch": f"0x{pci_id[1]}{pci_id[0]}"} | ({"IOPCISecondaryMatch": f"0x{pci_id[3]}{pci_id[2]}"} if len(pci_id) > 2 else {})

        else:
            raise RuntimeError("No matching key available")
Beispiel #3
0
 def port_class_to_type(speed):
     if "AppleUSB30XHCIPort" in speed:
         return shared.USBDeviceSpeeds.SuperSpeed
     elif set(["AppleUSB20XHCIPort", "AppleUSBEHCIPort"]) & set(speed):
         return shared.USBDeviceSpeeds.HighSpeed
     elif set(["AppleUSBOHCIPort", "AppleUSBUHCIPort"]) & set(speed):
         return shared.USBDeviceSpeeds.FullSpeed
     else:
         shared.debug(f"Unknown port type for {speed}!")
         return shared.USBDeviceSpeeds.Unknown
Beispiel #4
0
    def get_controllers(self):
        # self.update_usbdump()
        for i in range(10):
            try:
                # time_it(self.update_usbdump, "USBdump time")
                self.update_usbdump()
                break
            except Exception as e:
                if i == 10:
                    raise
                else:
                    shared.debug(e)
                    time.sleep(2)

        controllers = self.usbdump

        for controller in controllers:
            controller["name"] = self.get_property_from_wmi(
                controller["identifiers"]["instance_id"],
                PnpDeviceProperties.FRIENDLY_NAME) or controller["name"]
            controller["class"] = self.get_controller_class(controller)
            acpi_path = self.get_property_from_wmi(
                controller["identifiers"]["instance_id"],
                PnpDeviceProperties.ACPI_PATH)
            if acpi_path:
                controller["identifiers"]["acpi_path"] = acpi_path
            driver_key = self.get_property_from_wmi(
                controller["identifiers"]["instance_id"],
                PnpDeviceProperties.DRIVER_KEY)
            if driver_key:
                controller["identifiers"]["driver_key"] = driver_key
            location_paths = self.get_property_from_wmi(
                controller["identifiers"]["instance_id"],
                PnpDeviceProperties.LOCATION_PATHS)
            if location_paths:
                controller["identifiers"]["location_paths"] = location_paths
            # controller["identifiers"]["bdf"] = self.get_property_from_wmi(controller["identifiers"]["instance_id"], PnpDeviceProperties.BUS_DEVICE_FUNCTION)
            for port in controller["ports"]:
                for device in port["devices"]:
                    self.get_name_from_wmi(device)

        self.controllers = controllers
        if not self.controllers_historical:
            self.controllers_historical = copy.deepcopy(self.controllers)
        else:
            self.merge_controllers(self.controllers_historical,
                                   self.controllers)
Beispiel #5
0
 def controller_class_to_type(parent_props, controller_props, inheritance):
     # Check class code
     if "class-code" in parent_props:
         return shared.USBControllerTypes(parent_props["class-code"][0])
     # Check class type
     elif "AppleUSBXHCI" in inheritance:
         return shared.USBControllerTypes.XHCI
     elif "AppleUSBEHCI" in inheritance:
         return shared.USBControllerTypes.EHCI
     elif "AppleUSBOHCI" in inheritance:
         return shared.USBControllerTypes.OHCI
     elif "AppleUSBUHCI" in inheritance:
         return shared.USBControllerTypes.UHCI
     else:
         shared.debug(
             f"Unknown controller type for class code {read_property(parent_props['class-code'], 2) if 'class-code' in parent_props else 'none'}, inheritance {inheritance}!"
         )
         return shared.USBControllerTypes.Unknown