bool res;
int ret;
- switch (func->function_group) {
- case USB_FUNCTION_GROUP_SIMPLE:
- case USB_FUNCTION_GROUP_WITH_POST_SERVICE:
+ if (!func->ffs_service) {
ret = usbg_lookup_function_type(func->name);
res = ret >= 0;
- break;
- case USB_FUNCTION_GROUP_WITH_SERVICE:
+ } else {
/* TODO: Check if socket is available */
res = true;
- break;
- default:
- res = false;
}
return res;
int type;
usbg_function *func;
- switch (usb_func->function_group) {
- case USB_FUNCTION_GROUP_SIMPLE:
- case USB_FUNCTION_GROUP_WITH_POST_SERVICE:
+ if (!usb_func->ffs_service) {
type = usbg_lookup_function_type(usb_func->name);
if (strlen(usb_func->instance) >= MAX_INSTANCE_LEN)
return -ENAMETOOLONG;
strncpy(instance, usb_func->instance, MAX_INSTANCE_LEN);
instance[MAX_INSTANCE_LEN - 1] = '\0';
- break;
- case USB_FUNCTION_GROUP_WITH_SERVICE:
+ } else {
type = USBG_F_FFS;
ret = snprintf(instance, sizeof(instance), "%s%c%s",
usb_func->name, NAME_INSTANCE_SEP,
usb_func->instance);
if (ret < 0 || ret >= sizeof(instance))
return -ENAMETOOLONG;
- break;
- default:
- return -EINVAL;
}
-
func = usbg_get_function(cfs_client->gadget, type, instance);
if (!func) {
ret = usbg_create_function(cfs_client->gadget,
if (ret)
return ret;
- if (usb_func->function_group ==
- USB_FUNCTION_GROUP_WITH_SERVICE) {
- if (usb_func->service) {
- ret = cfs_prep_ffs_service(usb_func->name,
- usb_func->instance,
- instance,
- usb_func->service);
- if (ret)
- return ret;
- }
+ if (usb_func->ffs_service) {
+ ret = cfs_prep_ffs_service(usb_func->name,
+ usb_func->instance,
+ instance,
+ usb_func->ffs_service);
+ if (ret)
+ return ret;
}
-
}
ret = usbg_add_config_function(config, NULL, func);
int i;
int ret;
struct usb_gadget *gadget;
+ struct usb_function *func;
struct cfs_client *cfs_client;
if (!usb)
}
for (i = 0; gadget->funcs[i]; ++i) {
- if (gadget->funcs[i]->function_group != USB_FUNCTION_GROUP_WITH_POST_SERVICE)
- continue;
+ func = gadget->funcs[i];
- if (gadget->funcs[i]->service)
- (void)systemd_start_unit_wait_started(gadget->funcs[i]->service, ".service", -1);
+ if (func->service)
+ (void)systemd_start_unit_wait_started(func->service, ".service", -1);
}
cfs_free_gadget(gadget);
int i;
int ret;
struct usb_gadget *gadget;
+ struct usb_function *func;
struct cfs_client *cfs_client;
if (!usb)
return ret;
for (i = 0; gadget->funcs[i]; ++i) {
- if (gadget->funcs[i]->function_group != USB_FUNCTION_GROUP_WITH_POST_SERVICE)
- continue;
+ func = gadget->funcs[i];
- if (gadget->funcs[i]->service)
- (void)systemd_stop_unit_wait_stopped(gadget->funcs[i]->service, ".service", -1);
+ if (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->function_group == USB_FUNCTION_GROUP_WITH_SERVICE) {
- if (usb_func->service) {
- systemd_stop_unit_wait_stopped(usb_func->service, ".socket", -1);
- systemd_stop_unit_wait_stopped(usb_func->service, ".service", -1);
- }
+ 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);
}
}
int ret;
int i;
struct usb_gadget *gadget;
+ struct usb_function *func;
ret = sys_set_str(LEGACY_ENABLE_PATH,
LEGACY_ENABLE);
goto disable_gadget;
for (i = 0; gadget->funcs[i]; ++i) {
- if (gadget->funcs[i]->service)
- (void)systemd_start_unit_wait_started(gadget->funcs[i]->service, ".service", -1);
+ 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->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);
}
legacy_free_gadget(gadget);
int ret;
int i;
struct usb_gadget *gadget;
+ struct usb_function *func;
ret = legacy_get_current_gadget(usb, &gadget);
if (ret < 0)
return ret;
for (i = 0; gadget->funcs[i]; ++i) {
- if (gadget->funcs[i]->service)
- (void)systemd_stop_unit_wait_stopped(gadget->funcs[i]->service, ".service", -1);
+ 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);
}
ret = sys_set_str(LEGACY_ENABLE_PATH, LEGACY_DISABLE);
/* Function IDX in array is number of trailing zeros */
#define FUNC_IDX_FROM_MASK(mask) _HELPER_CTZ(mask)
-/**
- * USB_FUNCTION_GROUP_WITH_POST_SERVICE is the same as USB_FUNCTION_GROUP_SIMPLE
- * except running the service as a post.
- */
-typedef enum {
- USB_FUNCTION_GROUP_SIMPLE,
- USB_FUNCTION_GROUP_WITH_SERVICE,
- USB_FUNCTION_GROUP_WITH_POST_SERVICE,
-} usb_function_group_e;
-
struct usb_function {
- int function_group;
int id;
const char *name;
const char *instance;
+ const char *ffs_service; /* only used in configfs */
const char *service;
int (*clone)(struct usb_function *func, struct usb_function **_clone);
return -ENOMEM;
}
-#define DEFINE_USB_FUNCTION(_group, _id, _name, _service) \
- static struct usb_function _##_name##_function = { \
- .function_group = _group, \
- .id = _id, \
- .name = #_name, \
- .instance = "default", \
- .service = _service, \
- .clone = clone_simple_func, \
- .free_func = free_simple_func, \
+#define DEFINE_USB_FUNCTION(_id, _name, _ffs_service, _service) \
+ static struct usb_function _##_name##_function = { \
+ .id = _id, \
+ .name = #_name, \
+ .instance = "default", \
+ .ffs_service = _ffs_service, \
+ .service = _service, \
+ .clone = clone_simple_func, \
+ .free_func = free_simple_func, \
}
-#define DEFINE_USB_FUNCTION_NO_SERVICE(_id, _name) \
- DEFINE_USB_FUNCTION(USB_FUNCTION_GROUP_SIMPLE, _id, _name, NULL)
-
-#define DEFINE_USB_FUNCTION_WITH_SERVICE(_id, _name, _service) \
- DEFINE_USB_FUNCTION(USB_FUNCTION_GROUP_WITH_SERVICE, _id, _name, _service)
-
-#define DEFINE_USB_FUNCTION_WITH_POST_SERVICE(_id, _name, _service) \
- DEFINE_USB_FUNCTION(USB_FUNCTION_GROUP_WITH_POST_SERVICE, _id, _name, _service)
-
-DEFINE_USB_FUNCTION_NO_SERVICE(USB_FUNCTION_DIAG, diag);
-DEFINE_USB_FUNCTION_NO_SERVICE(USB_FUNCTION_RMNET, rmnet);
-DEFINE_USB_FUNCTION_NO_SERVICE(USB_FUNCTION_DM, dm);
-DEFINE_USB_FUNCTION_NO_SERVICE(USB_FUNCTION_CONN_GADGET, conn_gadget);
-
-DEFINE_USB_FUNCTION_WITH_SERVICE(USB_FUNCTION_SDB, sdb, "sdbd");
-DEFINE_USB_FUNCTION_WITH_SERVICE(USB_FUNCTION_MTP, mtp, "mtp-responder");
-
-DEFINE_USB_FUNCTION_WITH_POST_SERVICE(USB_FUNCTION_ACM, acm, "data-router");
-DEFINE_USB_FUNCTION_WITH_POST_SERVICE(USB_FUNCTION_RNDIS, rndis, "rndis");
-
+DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG, diag, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET, rmnet, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_DM, dm, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_SDB, sdb, "sdbd", NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_MTP, mtp, "mtp-responder", NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_ACM, acm, NULL, "data-router");
+DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS, rndis, NULL, "rndis");
+#undef DEFINE_USB_FUNCTION
-#define MAKE_FUNC_AVAILABLE(_name, _vname) \
+#define MAKE_FUNC_AVAILABLE(_name, _vname) \
[FUNC_IDX_FROM_MASK(USB_FUNCTION_##_name)] = &_##_vname##_function
static struct usb_function *_available_funcs[] = {
MAKE_FUNC_AVAILABLE(DM, dm),
MAKE_FUNC_AVAILABLE(RMNET, rmnet),
};
-
-#undef DEFINE_USB_FUNCTION
-#undef DEFINE_USB_FUNCTION_NO_SERVICE
-#undef DEFINE_USB_FUNCTION_WITH_SERVICE
-#undef DEFIND_USB_FUNCTION_WITH_POST_SERVICE
#undef MAKE_FUNC_AVAILABLE
struct usb_gadget_id {