Commit 6848228a authored by spiiroin's avatar spiiroin

[dyn-config] Drop unused syfs_path and sysfs_reset_value attributes

All "normal" modes ignore syfs_path and sysfs_reset_value configuration
values.

Remove redundant lines from sample configuration files and adjust
configuration file sanity checking rules.

Also fix a GKeyFile leak on error path in dynconfig_read_mode_file().
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 9dd55147
......@@ -5,9 +5,8 @@ appsync = 1
network = 0
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = adb,diag
sysfs_reset_value = none
android_extra_sysfs_path = /sys/class/android_usb/android0/f_diag/clients
android_extra_sysfs_value = diag
idProduct = 0A05
......@@ -6,10 +6,9 @@ network = 1
network_interface = rndis0
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = rndis,adb
android_extra_sysfs_path = /sys/class/android_usb/android0/f_ffs/aliases
android_extra_sysfs_value = adb
sysfs_reset_value = none
idProduct = 0A03
dhcp_server = 1
......@@ -3,8 +3,7 @@ name = acm_mode
module = none
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = acm
sysfs_reset_value = none
android_extra_sysfs_path = /sys/class/android_usb/android/f_acm/acm_transports
android_extra_sysfs_value = tty
......@@ -3,8 +3,7 @@ name = at_mode
module = none
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = serial
sysfs_reset_value = none
android_extra_sysfs_path = /sys/class/android_usb/android0/f_serial/transports
android_extra_sysfs_value = smd,tty
......@@ -3,8 +3,7 @@ name = connection_sharing
module = none
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = rndis
sysfs_reset_value = none
idProduct = 0A02
connman_tethering = /net/connman/technology/gadget
......@@ -6,8 +6,7 @@ network_interface = rndis0
appsync = 1
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = rndis
sysfs_reset_value = none
idProduct = 0A02
nat = 1
......@@ -6,8 +6,7 @@ network_interface = rndis0
appsync = 1
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = rndis
sysfs_reset_value = none
idProduct = 0A02
dhcp_server = 1
......@@ -6,9 +6,8 @@ network = 1
network_interface = rndis0
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = diag,serial,rmnet,qdss,adb,rndis
sysfs_reset_value = none
android_extra_sysfs_path = /sys/class/android_usb/android0/f_diag/clients
android_extra_sysfs_value = diag
android_extra_sysfs_path2 = /sys/class/android_usb/android0/f_serial/transports
......
......@@ -6,9 +6,8 @@ network = 1
network_interface = rndis0
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = rndis,adb,diag,serial
sysfs_reset_value = none
android_extra_sysfs_path = /sys/class/android_usb/android0/f_diag/clients
android_extra_sysfs_value = diag
android_extra_sysfs_path2 = /sys/class/android_usb/android0/f_serial/transports
......
......@@ -3,7 +3,6 @@ name = mtp_mode
module = none
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = ffs
sysfs_reset_value = none
idProduct = 0A07
......@@ -3,6 +3,5 @@ name = mtp_mode
module = none
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = mtp
sysfs_reset_value = none
......@@ -3,7 +3,6 @@ name = pc_suite
module = none
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = ffs
sysfs_reset_value = none
idProduct = 0A07
......@@ -4,7 +4,6 @@ module = none
appsync = 1
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = mass_storage
sysfs_reset_value = none
idProduct = 55AA
......@@ -323,9 +323,8 @@ network = 1
network_interface = rndis0
[options]
sysfs_path = /sys/class/android_usb/android0/functions
# sysfs_value = comma separated list of functions to enable in this mode
sysfs_value = rndis
sysfs_reset_value = none
idProduct = 0002
......
......@@ -55,26 +55,28 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename);
void dynconfig_free_list_item(mode_list_elem *list_item)
{
free(list_item->mode_name);
free(list_item->mode_module);
free(list_item->network_interface);
free(list_item->sysfs_path);
free(list_item->sysfs_value);
free(list_item->sysfs_reset_value);
free(list_item->android_extra_sysfs_path);
free(list_item->android_extra_sysfs_value);
free(list_item->android_extra_sysfs_path2);
free(list_item->android_extra_sysfs_value2);
free(list_item->android_extra_sysfs_path3);
free(list_item->android_extra_sysfs_value3);
free(list_item->android_extra_sysfs_path4);
free(list_item->android_extra_sysfs_value4);
free(list_item->idProduct);
free(list_item->idVendorOverride);
if( list_item ) {
free(list_item->mode_name);
free(list_item->mode_module);
free(list_item->network_interface);
free(list_item->sysfs_path);
free(list_item->sysfs_value);
free(list_item->sysfs_reset_value);
free(list_item->android_extra_sysfs_path);
free(list_item->android_extra_sysfs_value);
free(list_item->android_extra_sysfs_path2);
free(list_item->android_extra_sysfs_value2);
free(list_item->android_extra_sysfs_path3);
free(list_item->android_extra_sysfs_value3);
free(list_item->android_extra_sysfs_path4);
free(list_item->android_extra_sysfs_value4);
free(list_item->idProduct);
free(list_item->idVendorOverride);
#ifdef CONNMAN
free(list_item->connman_tethering);
free(list_item->connman_tethering);
#endif
free(list_item);
free(list_item);
}
}
void dynconfig_free_mode_list(GList *modelist)
......@@ -133,17 +135,16 @@ GList *dynconfig_read_mode_list(int diag)
static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
bool success = false;
GKeyFile *settingsfile = g_key_file_new();
struct mode_list_elem *list_item = NULL;
settingsfile = g_key_file_new();
test = g_key_file_load_from_file(settingsfile, filename, G_KEY_FILE_NONE, NULL);
if(!test)
{
return(NULL);
if( !g_key_file_load_from_file(settingsfile, filename, G_KEY_FILE_NONE, NULL) ) {
log_err("%s: can't read mode configuration file", filename);
goto EXIT;
}
list_item = malloc(sizeof(struct mode_list_elem));
list_item = calloc(1, sizeof *list_item);
// [MODE_ENTRY = "mode"]
list_item->mode_name = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_NAME_KEY, NULL);
......@@ -161,6 +162,7 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename)
list_item->sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_PATH, NULL);
list_item->sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_VALUE, NULL);
list_item->sysfs_reset_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_RESET_VALUE, NULL);
list_item->android_extra_sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH, NULL);
list_item->android_extra_sysfs_path2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH2, NULL);
list_item->android_extra_sysfs_path3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH3, NULL);
......@@ -169,6 +171,7 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename)
list_item->android_extra_sysfs_value2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE2, NULL);
list_item->android_extra_sysfs_value3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE3, NULL);
list_item->android_extra_sysfs_value4 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE4, NULL);
list_item->idProduct = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDPRODUCT, NULL);
list_item->idVendorOverride = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDVENDOROVERRIDE, NULL);
list_item->nat = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_NAT, NULL);
......@@ -182,24 +185,40 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename)
//log_debug("Android extra mode sysfs path2 = %s\n", list_item->android_extra_sysfs_path2);
//log_debug("Android extra value2 = %s\n", list_item->android_extra_sysfs_value2);
g_key_file_free(settingsfile);
if(list_item->mode_name == NULL || list_item->mode_module == NULL)
{
/* free list_item as it will not be used */
dynconfig_free_list_item(list_item);
return NULL;
if( list_item->mode_name == NULL || list_item->mode_module == NULL ) {
log_err("%s: mode_name or mode_module not defined", filename);
goto EXIT;
}
if(list_item->network && list_item->network_interface == NULL)
{
/* free list_item as it will not be used */
dynconfig_free_list_item(list_item);
return NULL;
if( list_item->network && list_item->network_interface == NULL) {
log_err("%s: network not fully defined", filename);
goto EXIT;
}
if(list_item->sysfs_path && list_item->sysfs_value == NULL)
{
/* free list_item as it will not be used */
dynconfig_free_list_item(list_item);
return NULL;
if( (list_item->sysfs_path && !list_item->sysfs_value) ||
(list_item->sysfs_reset_value && !list_item->sysfs_path) ) {
/* In theory all of this is optional.
*
* In most cases 'sysfs_value' holds a list of functions to enable,
* and 'sysfs_path' or 'sysfs_reset_value' values are simply ignored.
*
* However, for the benefit of existing special configuration files
* like the one for host mode:
* - having sysfs_path implies that sysfs_value should be set too
* - having sysfs_reset_value implies that sysfs_path should be set
*/
log_err("%s: sysfs_value not fully defined", filename);
goto EXIT;
}
return(list_item);
log_debug("%s: successfully loaded", filename);
success = true;
EXIT:
g_key_file_free(settingsfile);
if( !success )
dynconfig_free_list_item(list_item), list_item = 0;
return list_item;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment