Add support for specifying UDC that HID gadget will connect to
Currently, HID gadget always connects to the USB virtual hub port
under /sys/bus/platform/devices/1e6a0000.usb-vhub, which only works
on ASPEED platform.
This commit adds support for specifying UDC that HID gadget will
connect to, it could be useful for non-ASPEED platform. Although there
are still some other ASPEED-specific behaviors need to be addressed,
but this commit is the first step for non-ASPEED platform.
Tested:
Specify UDC by '-u' parameter and HID gadget will connect to it. Otherwise,
HID gadget will connect to the USB virtual hub port.
Signed-off-by: Marvin Lin <milkfafa@gmail.com>
Change-Id: Ie24ed9d32cb4f7483e8d4c8b51cc5e1bb5fa94de
diff --git a/ikvm_input.cpp b/ikvm_input.cpp
index e9bd151..107756b 100644
--- a/ikvm_input.cpp
+++ b/ikvm_input.cpp
@@ -23,9 +23,11 @@
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::File::Error;
-Input::Input(const std::string& kbdPath, const std::string& ptrPath) :
- keyboardFd(-1), pointerFd(-1), keyboardReport{0}, pointerReport{0},
- keyboardPath(kbdPath), pointerPath(ptrPath)
+Input::Input(const std::string& kbdPath, const std::string& ptrPath,
+ const std::string& udc) :
+ keyboardFd(-1),
+ pointerFd(-1), keyboardReport{0}, pointerReport{0}, keyboardPath(kbdPath),
+ pointerPath(ptrPath), udcName(udc)
{
hidUdcStream.exceptions(std::ofstream::failbit | std::ofstream::badbit);
hidUdcStream.open(hidUdcPath, std::ios::out | std::ios::app);
@@ -51,16 +53,23 @@
{
try
{
- for (const auto& port : fs::directory_iterator(usbVirtualHubPath))
+ if (udcName.empty())
{
- if (fs::is_directory(port) && !fs::is_symlink(port) &&
- !fs::exists(port.path() / "gadget/suspended"))
+ for (const auto& port : fs::directory_iterator(usbVirtualHubPath))
{
- const std::string portId = port.path().filename();
- hidUdcStream << portId << std::endl;
- break;
+ if (fs::is_directory(port) && !fs::is_symlink(port) &&
+ !fs::exists(port.path() / "gadget/suspended"))
+ {
+ const std::string portId = port.path().filename();
+ hidUdcStream << portId << std::endl;
+ break;
+ }
}
}
+ else // If UDC has been specified by '-u' parameter, connect to it.
+ {
+ hidUdcStream << udcName << std::endl;
+ }
}
catch (fs::filesystem_error& e)
{