diff options
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/__init__.py | 24 | ||||
-rw-r--r-- | kvmd/apps/otg/__init__.py | 32 | ||||
-rw-r--r-- | kvmd/apps/otgmsd/__init__.py | 4 | ||||
-rw-r--r-- | kvmd/usb.py | 8 |
4 files changed, 63 insertions, 5 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index 5ad38d90..7c587c3f 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -595,6 +595,18 @@ def _get_config_scheme() -> dict: "rw": Option(False, type=valid_bool), "removable": Option(True, type=valid_bool), "fua": Option(True, type=valid_bool), + "inquiry_string": { + "cdrom": { + "vendor": Option("PiKVM", type=valid_stripped_string), + "product": Option("Optical Drive", type=valid_stripped_string), + "revision": Option("1.00", type=valid_stripped_string), + }, + "flash": { + "vendor": Option("PiKVM", type=valid_stripped_string), + "product": Option("Flash Drive", type=valid_stripped_string), + "revision": Option("1.00", type=valid_stripped_string), + }, + }, }, }, @@ -626,6 +638,18 @@ def _get_config_scheme() -> dict: "rw": Option(True, type=valid_bool), "removable": Option(True, type=valid_bool), "fua": Option(True, type=valid_bool), + "inquiry_string": { + "cdrom": { + "vendor": Option("PiKVM", type=valid_stripped_string), + "product": Option("Optical Drive", type=valid_stripped_string), + "revision": Option("1.00", type=valid_stripped_string), + }, + "flash": { + "vendor": Option("PiKVM", type=valid_stripped_string), + "product": Option("Flash Drive", type=valid_stripped_string), + "revision": Option("1.00", type=valid_stripped_string), + }, + }, }, }, }, diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py index e1e886cb..076fe6b8 100644 --- a/kvmd/apps/otg/__init__.py +++ b/kvmd/apps/otg/__init__.py @@ -186,7 +186,19 @@ class _GadgetConfig: self.__create_meta(func, desc, eps) self.__hid_instance += 1 - def add_msd(self, start: bool, user: str, stall: bool, cdrom: bool, rw: bool, removable: bool, fua: bool) -> None: + def add_msd( + self, + start: bool, + user: str, + stall: bool, + cdrom: bool, + rw: bool, + removable: bool, + fua: bool, + inquiry_string_cdrom: str, + inquiry_string_flash: str, + ) -> None: + # Endpoints number depends on transport_type but we can consider that this is 2 # because transport_type is always USB_PR_BULK by default if CONFIG_USB_FILE_STORAGE_TEST # is not defined. See drivers/usb/gadget/function/storage_common.c @@ -198,6 +210,8 @@ class _GadgetConfig: _write(join(func_path, "lun.0/ro"), int(not rw)) _write(join(func_path, "lun.0/removable"), int(removable)) _write(join(func_path, "lun.0/nofua"), int(not fua)) + _write(join(func_path, "lun.0/inquiry_string_cdrom"), inquiry_string_cdrom) + _write(join(func_path, "lun.0/inquiry_string"), inquiry_string_flash) if user != "root": _chown(join(func_path, "lun.0/cdrom"), user) _chown(join(func_path, "lun.0/ro"), user) @@ -293,11 +307,23 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements, if config.kvmd.msd.type == "otg": logger.info("===== MSD =====") - gc.add_msd(cod.msd.start, config.otg.user, **cod.msd.default._unpack()) + gc.add_msd( + start=cod.msd.start, + user=config.otg.user, + inquiry_string_cdrom=usb.make_inquiry_string(**cod.msd.default.inquiry_string.cdrom._unpack()), + inquiry_string_flash=usb.make_inquiry_string(**cod.msd.default.inquiry_string.flash._unpack()), + **cod.msd.default._unpack(ignore="inquiry_string"), + ) if cod.drives.enabled: for count in range(cod.drives.count): logger.info("===== MSD Extra: %d =====", count + 1) - gc.add_msd(cod.drives.start, "root", **cod.drives.default._unpack()) + gc.add_msd( + start=cod.drives.start, + user="root", + inquiry_string_cdrom=usb.make_inquiry_string(**cod.drives.default.inquiry_string.cdrom._unpack()), + inquiry_string_flash=usb.make_inquiry_string(**cod.drives.default.inquiry_string.flash._unpack()), + **cod.drives.default._unpack(ignore="inquiry_string"), + ) if cod.ethernet.enabled: logger.info("===== Ethernet =====") diff --git a/kvmd/apps/otgmsd/__init__.py b/kvmd/apps/otgmsd/__init__.py index a289307f..3aab3127 100644 --- a/kvmd/apps/otgmsd/__init__.py +++ b/kvmd/apps/otgmsd/__init__.py @@ -68,7 +68,7 @@ def main(argv: (list[str] | None)=None) -> None: parser.add_argument("-i", "--instance", default=0, type=valid_int_f0, metavar="<N>", help="Drive instance (0 for KVMD drive)") parser.add_argument("--set-cdrom", default=None, type=valid_bool, - metavar="<1|0|yes|no>", help="Set CD-ROM flag") + metavar="<1|0|yes|no>", help="Set CD/DVD flag") parser.add_argument("--set-rw", default=None, type=valid_bool, metavar="<1|0|yes|no>", help="Set RW flag") parser.add_argument("--set-image", default=None, type=valid_abs_path, @@ -101,5 +101,5 @@ def main(argv: (list[str] | None)=None) -> None: set_param("file", options.set_image) print("Image file: ", (get_param("file") or "<none>")) - print("CD-ROM flag:", ("yes" if int(get_param("cdrom")) else "no")) + print("CD/DVD flag:", ("yes" if int(get_param("cdrom")) else "no")) print("RW flag: ", ("no" if int(get_param("ro")) else "yes")) diff --git a/kvmd/usb.py b/kvmd/usb.py index 54309c2c..34646c3f 100644 --- a/kvmd/usb.py +++ b/kvmd/usb.py @@ -55,3 +55,11 @@ G_PROFILE = f"configs/{G_PROFILE_NAME}" def get_gadget_path(gadget: str, *parts: str) -> str: return os.path.join(f"{env.SYSFS_PREFIX}/sys/kernel/config/usb_gadget", gadget, *parts) + + +# ===== +def make_inquiry_string(vendor: str, product: str, revision: str) -> str: + # Vendor: 8 ASCII chars + # Product: 16 + # Revision: 4 + return "%-8.8s%-16.16s%-4.4s" % (vendor, product, revision) |