summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-10-15 05:29:01 +0300
committerDevaev Maxim <[email protected]>2019-10-15 05:29:15 +0300
commite58ad66da98917d66f58731d041d4ddbe18befed (patch)
treecf9d0c9a92eac227427b352d607558733db13fa9 /kvmd
parenta88ad42501e3afd49bb02f186e787b6e14474640 (diff)
some validation
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py8
-rw-r--r--kvmd/validators/hw.py9
2 files changed, 14 insertions, 3 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index bfb4263e..9fd536a5 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -68,6 +68,8 @@ from ..validators.kvm import valid_stream_quality
from ..validators.kvm import valid_stream_fps
from ..validators.hw import valid_gpio_pin_optional
+from ..validators.hw import valid_otg_gadget
+from ..validators.hw import valid_otg_id
# =====
@@ -247,9 +249,9 @@ def _get_config_scheme() -> Dict:
},
"otg": {
- "gadget": Option("kvmd"),
- "vendor_id": Option(0x1D6B, type=valid_number), # Linux Foundation
- "product_id": Option(0x0104, type=valid_number), # Multifunction Composite Gadget
+ "gadget": Option("kvmd", type=valid_otg_gadget),
+ "vendor_id": Option(0x1D6B, type=valid_otg_id), # Linux Foundation
+ "product_id": Option(0x0104, type=valid_otg_id), # Multifunction Composite Gadget
"manufacturer": Option("Pi-KVM"),
"product": Option("Composite KVM Device"),
"serial_number": Option("CAFEBABE"),
diff --git a/kvmd/validators/hw.py b/kvmd/validators/hw.py
index a68743ad..82d1221a 100644
--- a/kvmd/validators/hw.py
+++ b/kvmd/validators/hw.py
@@ -23,6 +23,7 @@
from typing import Any
from . import check_in_list
+from . import check_re_match
from .basic import valid_number
@@ -40,3 +41,11 @@ def valid_gpio_pin(arg: Any) -> int:
def valid_gpio_pin_optional(arg: Any) -> int:
return int(valid_number(arg, min=-1, name="optional GPIO pin"))
+
+
+def valid_otg_gadget(arg: Any) -> str:
+ return check_re_match(arg, "OTG gadget name", r"^[a-z_][a-z0-9_-]*$")[:255]
+
+
+def valid_otg_id(arg: Any) -> int:
+ return int(valid_number(arg, min=0, max=65535, name="OTG ID"))