mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
refactoring
This commit is contained in:
parent
ba1f66db9c
commit
bdc2a317e5
@ -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:
|
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:
|
if host_mac and kvm_mac and host_mac == kvm_mac:
|
||||||
raise RuntimeError("Ethernet host_mac should not be equal to kvm_mac")
|
raise RuntimeError("Ethernet host_mac should not be equal to kvm_mac")
|
||||||
drv = driver
|
real_driver = driver
|
||||||
if driver == "rndis5":
|
if driver == "rndis5":
|
||||||
drv = "rndis"
|
real_driver = "rndis"
|
||||||
func_path = join(gadget_path, f"functions/{drv}.usb0")
|
func_path = join(gadget_path, f"functions/{real_driver}.usb0")
|
||||||
_mkdir(func_path)
|
_mkdir(func_path)
|
||||||
if host_mac:
|
if host_mac:
|
||||||
_write(join(func_path, "host_addr"), host_mac)
|
_write(join(func_path, "host_addr"), host_mac)
|
||||||
if kvm_mac:
|
if kvm_mac:
|
||||||
_write(join(func_path, "dev_addr"), kvm_mac)
|
_write(join(func_path, "dev_addr"), kvm_mac)
|
||||||
if driver == "rndis":
|
if driver in ["ncm", "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")
|
|
||||||
_write(join(gadget_path, "os_desc/use"), "1")
|
_write(join(gadget_path, "os_desc/use"), "1")
|
||||||
_write(join(gadget_path, "os_desc/b_vendor_code"), "0xCD")
|
_write(join(gadget_path, "os_desc/b_vendor_code"), "0xCD")
|
||||||
_write(join(gadget_path, "os_desc/qw_sign"), "MSFT100")
|
_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"))
|
_symlink(config_path, join(gadget_path, "os_desc/c.1"))
|
||||||
if driver == "ncm":
|
_symlink(func_path, join(config_path, f"{real_driver}.usb0"))
|
||||||
_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:
|
def _create_hid(gadget_path: str, config_path: str, instance: int, remote_wakeup: bool, hid: Hid) -> None:
|
||||||
|
|||||||
@ -173,13 +173,13 @@ class _Service: # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
def __find_iface(self) -> str:
|
def __find_iface(self) -> str:
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
drv = self.__driver
|
real_driver = self.__driver
|
||||||
if self.__driver == "rndis5":
|
if self.__driver == "rndis5":
|
||||||
drv = "rndis"
|
real_driver = "rndis"
|
||||||
path = env.SYSFS_PREFIX + os.path.join(
|
path = env.SYSFS_PREFIX + os.path.join(
|
||||||
"/sys/kernel/config/usb_gadget",
|
"/sys/kernel/config/usb_gadget",
|
||||||
self.__gadget,
|
self.__gadget,
|
||||||
f"functions/{drv}.usb0/ifname",
|
f"functions/{real_driver}.usb0/ifname",
|
||||||
)
|
)
|
||||||
logger.info("Using OTG gadget %r ...", self.__gadget)
|
logger.info("Using OTG gadget %r ...", self.__gadget)
|
||||||
with open(path) as iface_file:
|
with open(path) as iface_file:
|
||||||
|
|||||||
@ -121,7 +121,7 @@ def test_fail__valid_otg_id(arg: Any) -> None:
|
|||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
@pytest.mark.parametrize("arg", ["ECM ", "EeM ", "ncm ", " Rndis"])
|
@pytest.mark.parametrize("arg", ["ECM ", "EeM ", "ncm ", " Rndis", "RNDIS5"])
|
||||||
def test_ok__valid_otg_ethernet(arg: Any) -> None:
|
def test_ok__valid_otg_ethernet(arg: Any) -> None:
|
||||||
assert valid_otg_ethernet(arg) == arg.strip().lower()
|
assert valid_otg_ethernet(arg) == arg.strip().lower()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user