Skip to content
Permalink
Browse files
[idVendor] Allow modes to override the vendor id
For the special android gadget modes it is sometimes useful
to be able to override the vendor id temporarly.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Nov 5, 2015
1 parent eadebc6 commit e4045598423eb3ad2624e75007086f5b6744ff8c
Showing with 35 additions and 0 deletions.
  1. +16 −0 src/usb_moded-android.c
  2. +1 −0 src/usb_moded-android.h
  3. +2 −0 src/usb_moded-dyn-config.c
  4. +2 −0 src/usb_moded-dyn-config.h
  5. +14 −0 src/usb_moded-modesetting.c
@@ -117,3 +117,19 @@ int set_android_productid(char *id)
else
return(ret);
}

/* Set a vendor id for the android gadget
*
* @return 0 if successful, 1 on failure
*/
int set_android_vendorid(char *id)
{
int ret = 0;

/* disable, set functions to "mass_storage", re-enable */
ret = write_to_file("/sys/class/android_usb/android0/idVendor", id);
if(ret < 0)
return(1);
else
return(ret);
}
@@ -24,3 +24,4 @@ int android_settings(void);
void android_init_values(void);
int set_android_charging_mode(void);
int set_android_productid(char *id);
int set_android_vendorid(char *id);
@@ -55,6 +55,7 @@ void list_item_free(mode_list_elem *list_item)
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);
#endif
@@ -155,6 +156,7 @@ static struct mode_list_elem *read_mode_file(const gchar *filename)
list_item->android_extra_sysfs_value4 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE4, NULL);
//log_debug("Android extra value2 = %s\n", list_item->android_extra_sysfs_value2);
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);
list_item->dhcp_server = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_DHCP_SERVER, NULL);
#ifdef CONNMAN
@@ -53,6 +53,7 @@ android engineers prefered to have sysfs entries... go figure... */
#define MODE_ANDROID_EXTRA_SYSFS_VALUE4 "android_extra_sysfs_value4"
/* For windows different modes/usb profiles need their own idProduct */
#define MODE_IDPRODUCT "idProduct"
#define MODE_IDVENDOROVERRIDE "idVendorOverride"
#define MODE_HAS_NAT "nat"
#define MODE_HAS_DHCP_SERVER "dhcp_server"
#ifdef CONNMAN
@@ -86,6 +87,7 @@ typedef struct mode_list_elem
char *android_extra_sysfs_path4; /* path for static value that never changes that needs to be set by sysfs :( */
char *android_extra_sysfs_value4; /* static value that never changes that needs to be set by sysfs :( */
char *idProduct; /* product id to assign to a specific profile */
char *idVendorOverride; /* Temporary vendor override for special modes used by odms in testing/manufacturing */
int nat; /* If NAT should be set up in this mode or not */
int dhcp_server; /* if a DHCP server needs to be configured and started or not */
#ifdef CONNMAN
@@ -369,6 +369,12 @@ int set_dynamic_mode(void)
/* only works for android since the idProduct is a module parameter */
set_android_productid(data->idProduct);
}
if(data->idVendorOverride)
{
/* only works for android since the idProduct is a module parameter */
set_android_vendorid(data->idVendorOverride);
}

/* enable the device */
if(data->softconnect)
{
@@ -463,6 +469,14 @@ void unset_dynamic_mode(void)
write_to_file(data->sysfs_path, data->sysfs_reset_value);
log_debug("writing to file %s, value %s\n", data->sysfs_path, data->sysfs_reset_value);
}
/* restore vendorid if the mode had an override */
if(data->idVendorOverride)
{
char *id;
id = get_android_vendor_id();
set_android_vendorid(id);
g_free(id);
}
}

/** clean up mode changes or extra actions to perform after a mode change

0 comments on commit e404559

Please sign in to comment.