From 957744d8ad444dbea31cd6b1107dc3af90c5b836 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Mon, 11 Nov 2019 13:51:46 +0200 Subject: [PATCH] [configfs] Handle comma separated list of functions. JB#48079 In android-usb backend a comma separated list of functions to enabled can be written as-is to sysfs control file. This assumption got inherited by configfs backend, and things fall apart if a mode needs to activate more than one function. Split comma separated list of functions into an array and enable each function separately. Signed-off-by: Simo Piiroinen --- src/usb_moded-configfs.c | 34 ++++++++++++++++++++++------------ src/usb_moded-configfs.h | 2 +- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/usb_moded-configfs.c b/src/usb_moded-configfs.c index 8abb66d..8daa899 100644 --- a/src/usb_moded-configfs.c +++ b/src/usb_moded-configfs.c @@ -102,7 +102,7 @@ bool configfs_set_charging_mode (void); bool configfs_set_productid (const char *id); bool configfs_set_vendorid (const char *id); static const char *configfs_map_function (const char *func); -bool configfs_set_function (const char *func); +bool configfs_set_function (const char *functions); bool configfs_add_mass_storage_lun (int lun); bool configfs_remove_mass_storage_lun(int lun); bool configfs_set_mass_storage_attr (int lun, const char *attr, const char *value); @@ -956,35 +956,44 @@ configfs_map_function(const char *func) return func; } -/* Set a function +/* Set active functions * - * @param func Mame of function to enable, or NULL to disable all + * @param function Comma separated list of function names to + * enable, or NULL to disable all * * @return true if successful, false on failure */ bool -configfs_set_function(const char *func) +configfs_set_function(const char *functions) { LOG_REGISTER_CONTEXT; bool ack = false; + gchar **vec = 0; + if( !configfs_in_use() ) goto EXIT; - /* Normalize names used by usb-moded itself and already - * existing configuration files etc. - */ - func = configfs_map_function(func); - if( !configfs_set_udc(false) ) goto EXIT; if( !configfs_disable_all_functions() ) goto EXIT; - if( func && !configfs_enable_function(func) ) - goto EXIT; + if( functions ) { + vec = g_strsplit(functions, ",", 0); + for( size_t i = 0; vec[i]; ++i ) { + /* Normalize names used by usb-moded itself and already + * existing configuration files etc. + */ + const char *use = configfs_map_function(vec[i]); + if( !use || !*use ) + continue; + if( !configfs_enable_function(use) ) + goto EXIT; + } + } /* Leave disabled, so that caller can adjust attributes * etc before enabling */ @@ -992,7 +1001,8 @@ configfs_set_function(const char *func) ack = true; EXIT: - log_debug("CONFIGFS %s(%s) -> %d", __func__, func, ack); + log_debug("CONFIGFS %s(%s) -> %d", __func__, functions, ack); + g_strfreev(vec); return ack; } diff --git a/src/usb_moded-configfs.h b/src/usb_moded-configfs.h index 96d9dd2..896b905 100644 --- a/src/usb_moded-configfs.h +++ b/src/usb_moded-configfs.h @@ -40,7 +40,7 @@ void configfs_quit (void); bool configfs_set_charging_mode (void); bool configfs_set_productid (const char *id); bool configfs_set_vendorid (const char *id); -bool configfs_set_function (const char *func); +bool configfs_set_function (const char *functions); bool configfs_add_mass_storage_lun (int lun); bool configfs_remove_mass_storage_lun(int lun); bool configfs_set_mass_storage_attr (int lun, const char *attr, const char *value);