diff options
-rw-r--r-- | kvmd/apps/otg/__init__.py | 31 | ||||
-rw-r--r-- | kvmd/apps/otgnet/__init__.py | 6 | ||||
-rw-r--r-- | testenv/tests/validators/test_hw.py | 2 |
3 files changed, 18 insertions, 21 deletions
diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py index c8345d7f..fb2254ad 100644 --- a/kvmd/apps/otg/__init__.py +++ b/kvmd/apps/otg/__init__.py @@ -113,33 +113,30 @@ def _create_serial(gadget_path: str, config_path: str) -> None: def _create_ethernet(gadget_path: str, config_path: str, driver: str, host_mac: str, kvm_mac: str) -> None: if host_mac and kvm_mac and host_mac == kvm_mac: raise RuntimeError("Ethernet host_mac should not be equal to kvm_mac") - drv = driver + real_driver = driver if driver == "rndis5": - drv = "rndis" - func_path = join(gadget_path, f"functions/{drv}.usb0") + real_driver = "rndis" + func_path = join(gadget_path, f"functions/{real_driver}.usb0") _mkdir(func_path) if host_mac: _write(join(func_path, "host_addr"), host_mac) if kvm_mac: _write(join(func_path, "dev_addr"), kvm_mac) - if driver == "rndis": - # On Windows 7 and later, the RNDIS 5.1 driver would be used by default, - # but it does not work very well. The RNDIS 6.0 driver works better. - # In order to get this driver to load automatically, we have to use - # a Microsoft-specific extension of USB. - _write(join(func_path, "os_desc/interface.rndis/compatible_id"), "RNDIS") - _write(join(func_path, "os_desc/interface.rndis/sub_compatible_id"), "5162001") + if driver in ["ncm", "rndis"]: _write(join(gadget_path, "os_desc/use"), "1") _write(join(gadget_path, "os_desc/b_vendor_code"), "0xCD") _write(join(gadget_path, "os_desc/qw_sign"), "MSFT100") + if driver == "ncm": + _write(join(func_path, "os_desc/interface.ncm/compatible_id"), "WINNCM") + elif driver == "rndis": + # On Windows 7 and later, the RNDIS 5.1 driver would be used by default, + # but it does not work very well. The RNDIS 6.0 driver works better. + # In order to get this driver to load automatically, we have to use + # a Microsoft-specific extension of USB. + _write(join(func_path, "os_desc/interface.rndis/compatible_id"), "RNDIS") + _write(join(func_path, "os_desc/interface.rndis/sub_compatible_id"), "5162001") _symlink(config_path, join(gadget_path, "os_desc/c.1")) - if driver == "ncm": - _write(join(func_path, "os_desc/interface.ncm/compatible_id"), "WINNCM") - _write(join(gadget_path, "os_desc/use"), "1") - _write(join(gadget_path, "os_desc/b_vendor_code"), "0xCD") - _write(join(gadget_path, "os_desc/qw_sign"), "MSFT100") - _symlink(config_path, join(gadget_path, "os_desc/c.1")) - _symlink(func_path, join(config_path, f"{drv}.usb0")) + _symlink(func_path, join(config_path, f"{real_driver}.usb0")) def _create_hid(gadget_path: str, config_path: str, instance: int, remote_wakeup: bool, hid: Hid) -> None: diff --git a/kvmd/apps/otgnet/__init__.py b/kvmd/apps/otgnet/__init__.py index eeb9073a..ad1f6a28 100644 --- a/kvmd/apps/otgnet/__init__.py +++ b/kvmd/apps/otgnet/__init__.py @@ -173,13 +173,13 @@ class _Service: # pylint: disable=too-many-instance-attributes def __find_iface(self) -> str: logger = get_logger() - drv = self.__driver + real_driver = self.__driver if self.__driver == "rndis5": - drv = "rndis" + real_driver = "rndis" path = env.SYSFS_PREFIX + os.path.join( "/sys/kernel/config/usb_gadget", self.__gadget, - f"functions/{drv}.usb0/ifname", + f"functions/{real_driver}.usb0/ifname", ) logger.info("Using OTG gadget %r ...", self.__gadget) with open(path) as iface_file: diff --git a/testenv/tests/validators/test_hw.py b/testenv/tests/validators/test_hw.py index 47876fc2..d30bd3d8 100644 --- a/testenv/tests/validators/test_hw.py +++ b/testenv/tests/validators/test_hw.py @@ -121,7 +121,7 @@ def test_fail__valid_otg_id(arg: Any) -> None: # ===== [email protected]("arg", ["ECM ", "EeM ", "ncm ", " Rndis"]) [email protected]("arg", ["ECM ", "EeM ", "ncm ", " Rndis", "RNDIS5"]) def test_ok__valid_otg_ethernet(arg: Any) -> None: assert valid_otg_ethernet(arg) == arg.strip().lower() |