Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb48079_configfs_diag_mode' into 'master'
Handle comma separated list of configfs functions

See merge request mer-core/usb-moded!54
  • Loading branch information
spiiroin committed Nov 12, 2019
2 parents b567e11 + 957744d commit 62e5a87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions src/usb_moded-configfs.c
Expand Up @@ -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);
Expand Down Expand Up @@ -956,43 +956,53 @@ 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 */

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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-configfs.h
Expand Up @@ -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);
Expand Down

0 comments on commit 62e5a87

Please sign in to comment.