diff options
author | mfunkey <[email protected]> | 2022-01-20 07:44:46 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2022-01-20 09:44:46 +0300 |
commit | ba1f66db9ca0073730533bff79c6df80b9321a42 (patch) | |
tree | c8e3ef1487b8ab93458daf742097a3dc52582b05 | |
parent | 3ab43edeb962e95402ab0e18c553665ffd6117f0 (diff) |
RNDIS Version 5 for Windows XP, automatic driver load on Windows using ncm (#77)
* rndis version 5 implementation for windows xp
* make windows pick the ncm usb ethernet driver automatically
-rw-r--r-- | kvmd/apps/otg/__init__.py | 19 | ||||
-rw-r--r-- | kvmd/apps/otgnet/__init__.py | 5 | ||||
-rw-r--r-- | kvmd/validators/hw.py | 2 |
3 files changed, 20 insertions, 6 deletions
diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py index f404f54d..c8345d7f 100644 --- a/kvmd/apps/otg/__init__.py +++ b/kvmd/apps/otg/__init__.py @@ -113,7 +113,10 @@ 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") - func_path = join(gadget_path, f"functions/{driver}.usb0") + drv = driver + if driver == "rndis5": + drv = "rndis" + func_path = join(gadget_path, f"functions/{drv}.usb0") _mkdir(func_path) if host_mac: _write(join(func_path, "host_addr"), host_mac) @@ -130,7 +133,13 @@ def _create_ethernet(gadget_path: str, config_path: str, driver: str, host_mac: _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"{driver}.usb0")) + 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")) def _create_hid(gadget_path: str, config_path: str, instance: int, remote_wakeup: bool, hid: Hid) -> None: @@ -189,10 +198,12 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements _write(join(gadget_path, "idVendor"), f"0x{config.otg.vendor_id:04X}") _write(join(gadget_path, "idProduct"), f"0x{config.otg.product_id:04X}") - # bcdDevaev should be incremented any time there are breaking changes + # bcdDevice should be incremented any time there are breaking changes # to this script so that the host OS sees it as a new device # and re-enumerates everything rather than relying on cached values. - if config.otg.devices.ethernet.enabled and config.otg.devices.ethernet.driver == "rndis": + if config.otg.devices.ethernet.enabled and config.otg.devices.ethernet.driver == "ncm": + _write(join(gadget_path, "bcdDevice"), "0x0102") + elif config.otg.devices.ethernet.enabled and config.otg.devices.ethernet.driver == "rndis": _write(join(gadget_path, "bcdDevice"), "0x0101") else: _write(join(gadget_path, "bcdDevice"), "0x0100") diff --git a/kvmd/apps/otgnet/__init__.py b/kvmd/apps/otgnet/__init__.py index c87ad125..eeb9073a 100644 --- a/kvmd/apps/otgnet/__init__.py +++ b/kvmd/apps/otgnet/__init__.py @@ -173,10 +173,13 @@ class _Service: # pylint: disable=too-many-instance-attributes def __find_iface(self) -> str: logger = get_logger() + drv = self.__driver + if self.__driver == "rndis5": + drv = "rndis" path = env.SYSFS_PREFIX + os.path.join( "/sys/kernel/config/usb_gadget", self.__gadget, - f"functions/{self.__driver}.usb0/ifname", + f"functions/{drv}.usb0/ifname", ) logger.info("Using OTG gadget %r ...", self.__gadget) with open(path) as iface_file: diff --git a/kvmd/validators/hw.py b/kvmd/validators/hw.py index aae7a758..4fcab0af 100644 --- a/kvmd/validators/hw.py +++ b/kvmd/validators/hw.py @@ -55,4 +55,4 @@ def valid_otg_id(arg: Any) -> int: def valid_otg_ethernet(arg: Any) -> str: - return check_string_in_list(arg, "OTG Ethernet driver", ["ecm", "eem", "ncm", "rndis"]) + return check_string_in_list(arg, "OTG Ethernet driver", ["ecm", "eem", "ncm", "rndis", "rndis5"]) |