From dc10d02f8a1fee855bce0d99ef2af77b3fe4043e Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 28 Jan 2020 17:40:43 +0900 Subject: [PATCH] Add USB rndis_handler for rndis mode Rndis mode needs rndis.service and sshd.service. Also, rndis.service should run first, and sshd.service should run later. The rndis_handler starts rndis.service and service trigger starts sshd.service. Change-Id: I1a2f3960b257ce56a7d49e47848ab11021ad418e (cherry picked from commit 90247ab0794ce0dde0d1bd5f8378fa0a055b5129) --- hw/usb_gadget.h | 4 +++- hw/usb_gadget_common.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/usb_gadget.h b/hw/usb_gadget.h index 8533228..f61f966 100644 --- a/hw/usb_gadget.h +++ b/hw/usb_gadget.h @@ -165,6 +165,8 @@ out_nomem: return -ENOMEM; } +void rndis_handler(int enable); + #define DEFINE_USB_FUNCTION(_id, _name, _ffs_service, _service, _handler) \ static struct usb_function _##_name##_function = { \ .id = _id, \ @@ -184,7 +186,7 @@ DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, NULL, NULL, DEFINE_USB_FUNCTION(USB_FUNCTION_SDB, sdb, "sdbd", NULL, NULL); DEFINE_USB_FUNCTION(USB_FUNCTION_MTP, mtp, "mtp-responder", NULL, NULL); DEFINE_USB_FUNCTION(USB_FUNCTION_ACM, acm, NULL, "data-router", NULL); -DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS, rndis, NULL, "rndis", NULL); +DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS, rndis, NULL, "sshd", rndis_handler); #undef DEFINE_USB_FUNCTION #define MAKE_FUNC_AVAILABLE(_name, _vname) \ diff --git a/hw/usb_gadget_common.c b/hw/usb_gadget_common.c index e629b47..e9db26a 100644 --- a/hw/usb_gadget_common.c +++ b/hw/usb_gadget_common.c @@ -24,6 +24,8 @@ #include #include +#include + #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) #define zalloc(amount) calloc(1, amount) @@ -397,6 +399,14 @@ out: return ret; } +void rndis_handler(int enable) +{ + if (enable) + (void)systemd_start_unit_wait_started("rndis.service", NULL, -1); + else + (void)systemd_stop_unit_wait_stopped("rndis.service", NULL, -1); +} + EXPORT int simple_translator_open(struct hw_info *info, const char *id, struct hw_common **common) -- 2.34.1