bool res;
int ret;
- if (!func->ffs_service) {
+ if (!func->is_functionfs) {
ret = usbg_lookup_function_type(func->name);
res = ret >= 0;
} else {
int type;
usbg_function *func;
- if (!usb_func->ffs_service) {
+ if (!usb_func->is_functionfs) {
type = usbg_lookup_function_type(usb_func->name);
if (strlen(usb_func->instance) >= MAX_INSTANCE_LEN)
return -ENAMETOOLONG;
if (usbg_get_function_type(func) == USBG_F_RNDIS)
(void)cfs_set_rndis_mac_addr(cfs_client->gadget, func); /* A random value is used if fails */
- if (usb_func->ffs_service) {
+ if (usb_func->is_functionfs) {
ret = cfs_prep_ffs_service(usb_func->name,
usb_func->instance,
instance,
- usb_func->ffs_service);
+ usb_func->service);
if (ret)
return ret;
}
if (func->handler)
func->handler(1);
- if (func->service)
+ /* functionfs service is automatically started by socket activation */
+ if (!func->is_functionfs && func->service)
(void)systemd_start_unit_wait_started(func->service, ".service", -1);
-
- /* func->ffs_service is automatically started by socket activation */
}
cfs_free_gadget(gadget);
for (i = 0; gadget->funcs[i]; ++i) {
func = gadget->funcs[i];
- if (func->service)
+ if (!func->is_functionfs && func->service)
(void)systemd_stop_unit_wait_stopped(func->service, ".service", -1);
if (func->handler)
ret = usbg_disable_gadget(cfs_client->gadget); /* ignore error checking */
/*
- * Since ffs_service works with socket activation, you must stop it after disabling gadget.
- * If usb data may come in after stopping ffs_service and before disabling gadget,
- * ffs_service wakes up again by socket activation.
+ * Since functionfs service works with socket activation, you must stop it after disabling gadget.
+ * If usb data may come in after stopping functionfs service and before disabling gadget,
+ * functionfs service wakes up again by socket activation.
*/
for (i = 0; gadget->funcs[i]; ++i) {
func = gadget->funcs[i];
- if (func->ffs_service)
- (void)systemd_stop_unit_wait_stopped(func->ffs_service, ".service", -1);
+ if (func->is_functionfs && func->service)
+ (void)systemd_stop_unit_wait_stopped(func->service, ".service", -1);
}
cfs_free_gadget(gadget);
continue;
usb_func = _available_funcs[ret];
- if (usb_func->ffs_service) {
- systemd_stop_unit_wait_stopped(usb_func->ffs_service, ".socket", -1);
- systemd_stop_unit_wait_stopped(usb_func->ffs_service, ".service", -1);
+
+ if (usb_func->is_functionfs && usb_func->service) {
+ (void)systemd_stop_unit_wait_stopped(usb_func->service, ".socket", -1);
+ (void)systemd_stop_unit_wait_stopped(usb_func->service, ".service", -1);
}
}
if (func->handler)
func->handler(1);
- /*
- * Reuse configfs data structure to simplify design.
- * Configfs has a special service for functionfs. (E.g. sdbd and mtp-responder)
- * The legacy usb gadget must handle both services.
- */
- if (func->ffs_service)
- (void)systemd_start_unit_wait_started(func->ffs_service, ".service", -1);
-
if (func->service)
(void)systemd_start_unit_wait_started(func->service, ".service", -1);
}
for (i = 0; gadget->funcs[i]; ++i) {
func = gadget->funcs[i];
- /*
- * Reuse configfs data structure to simplify design.
- * Configfs has a special service for functionfs. (E.g. sdbd and mtp-responder)
- * The legacy usb gadget must handle both services.
- */
if (func->service)
(void)systemd_stop_unit_wait_stopped(func->service, ".service", -1);
- if (func->ffs_service)
- (void)systemd_stop_unit_wait_stopped(func->ffs_service, ".service", -1);
-
if (func->handler)
func->handler(0);
}
/*
- * legacy enable(usb plug) : enable gadget -> handler(1) -> ffs_service start -> service start
- * legacy disable(usb unplug) : service stop -> ffs_service stop -> handler(0) -> disable gadget
+ * legacy enable(usb plug) : enable gadget -> handler(1) -> service start
+ * legacy disable(usb unplug) : service stop -> handler(0) -> disable gadget
*
- * configfs init(booting) : ffs_service.socket start
- * configfs enable(usb plug)* : enable gadget -> handler(1) -> service start
- * configfs disable(usb unplug) : service stop -> handler(0) -> disable gadget -> ffs_service.service stop
- * configfs deinit : ffs_service.socket stop
+ * configfs init(booting) : service.socket start
+ * configfs enable(usb plug)* : enable gadget -> handler(1)
+ * configfs disable(usb unplug) : handler(0) -> disable gadget -> service.service stop
+ * configfs deinit : service.socket stop
*
- * Since ffs_service works by socket activation, it will be started automatically when data is enqueued to the usb socket.
- * So when enabling configfs gadget, it doesn't start ffs_service.
+ * Since functionfs of configfs works by socket activation,
+ * it will be started automatically when data is enqueued to the usb socket.
+ * So when enabling configfs gadget, it doesn't start the service for functionfs.
*/
struct usb_function {
int id;
const char *name;
const char *instance;
- const char *ffs_service; /* only used in configfs */
+ int is_functionfs;
const char *service;
void (*handler)(int enable);
if (func) {
free((void *)func->name);
free((void *)func->instance);
- free((void *)func->ffs_service);
free((void *)func->service);
free(func);
}
if (!other->name || !other->instance)
goto out_nomem;
- if (func->ffs_service) {
- other->ffs_service = strdup(func->ffs_service);
- if (!other->ffs_service)
- goto out_nomem;
- }
-
if (func->service) {
other->service = strdup(func->service);
if (!other->service)
return -ENOMEM;
}
-#define DEFINE_USB_FUNCTION(_id, _name, _ffs_service, _service, _handler) \
- static struct usb_function _##_name##_function = { \
- .id = _id, \
- .name = #_name, \
- .instance = "default", \
- .ffs_service = _ffs_service, \
- .service = _service, \
- .handler = _handler, \
- .clone = clone_simple_func, \
- .free_func = free_simple_func, \
+#define DEFINE_USB_FUNCTION(_id, _name, _is_functionfs, _service, _handler) \
+ static struct usb_function _##_name##_function = { \
+ .id = _id, \
+ .name = #_name, \
+ .instance = "default", \
+ .is_functionfs = _is_functionfs, \
+ .service = _service, \
+ .handler = _handler, \
+ .clone = clone_simple_func, \
+ .free_func = free_simple_func, \
}
-DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG, diag, NULL, NULL, NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET, rmnet, NULL, NULL, NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_DM, dm, NULL, NULL, NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, NULL, 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, "sshd", rndis_handler);
+DEFINE_USB_FUNCTION(USB_FUNCTION_MTP, mtp, 1, "mtp-responder", NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_ACM, acm, 0, "data-router", NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_SDB, sdb, 1, "sdbd", NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS, rndis, 0, "sshd", rndis_handler);
+DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG, diag, 0, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, 0, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_DM, dm, 0, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET, rmnet, 0, NULL, NULL);
+
#undef DEFINE_USB_FUNCTION
/* Caution: index order of arrary is important, because simple_id_to_gadget() uses it. */
* So in environments that mtp doesn't support, use dummy mtp.
*/
if (access("/usr/lib/systemd/system/mtp-responder.socket", F_OK)) {
- _available_funcs[USB_FUNCTION_IDX_MTP]->ffs_service = "mtp-responder-dummy";
+ _available_funcs[USB_FUNCTION_IDX_MTP]->service = "mtp-responder-dummy";
}
*common = &simple_translator->common;