summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-30 03:53:39 +0300
committerDevaev Maxim <[email protected]>2020-09-30 04:53:21 +0300
commit771640a79c437ecc39296faee1c4dedb016d71a2 (patch)
treef71c1818c5bd1da6209e238829e3a43c231c683a
parenta86ec65024774bab1b6b62ec30a8cf46c0e1613d (diff)
options to configure otg ethernet
-rw-r--r--kvmd/apps/__init__.py6
-rw-r--r--kvmd/apps/otg/__init__.py15
2 files changed, 21 insertions, 0 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 5a2b5244..a760d188 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -387,6 +387,12 @@ def _get_config_scheme() -> Dict:
"enabled": Option(False, type=valid_bool),
},
+ "ethernet": {
+ "enabled": Option(False, type=valid_bool),
+ "host_mac": Option("", type=valid_mac, only_if="enabled"),
+ "kvm_mac": Option("", type=valid_mac, only_if="enabled"),
+ },
+
"drives": {
"enabled": Option(False, type=valid_bool),
"count": Option(1, type=valid_int_f1),
diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py
index 8f5444bc..2085134b 100644
--- a/kvmd/apps/otg/__init__.py
+++ b/kvmd/apps/otg/__init__.py
@@ -97,6 +97,7 @@ def _find_udc(udc: str) -> str:
def _check_config(config: Section) -> None:
if (
not config.otg.acm.enabled
+ and not config.otg.ethernet.enabled
and config.kvmd.hid.type != "otg"
and config.kvmd.msd.type != "otg"
):
@@ -110,6 +111,16 @@ def _create_acm(gadget_path: str, config_path: str) -> None:
_symlink(func_path, join(config_path, "acm.usb0"))
+def _create_ethernet(gadget_path: str, config_path: str, host_mac: str, kvm_mac: str) -> None:
+ if host_mac == kvm_mac:
+ raise RuntimeError("Ethernet host_mac should not be equal to kvm_mac")
+ func_path = join(gadget_path, "functions/ecm.usb0")
+ _mkdir(func_path)
+ _write(join(func_path, "host_addr"), host_mac)
+ _write(join(func_path, "dev_addr"), kvm_mac)
+ _symlink(func_path, join(config_path, "ecm.usb0"))
+
+
def _create_hid(gadget_path: str, config_path: str, instance: int, hid: Hid) -> None:
func_path = join(gadget_path, f"functions/hid.usb{instance}")
_mkdir(func_path)
@@ -181,6 +192,10 @@ def _cmd_start(config: Section) -> None:
logger.info("Required ACM")
_create_acm(gadget_path, config_path)
+ if config.otg.ethernet.enabled:
+ logger.info("Required Ethernet")
+ _create_ethernet(gadget_path, config_path, config.otg.ethernet.host_mac, config.otg.ethernet.kvm_mac)
+
if config.kvmd.hid.type == "otg":
logger.info("Required HID")
_create_hid(gadget_path, config_path, 0, KEYBOARD_HID)