Skip to content

Commit

Permalink
[idVendor] Allow modes to override the vendor id
Browse files Browse the repository at this point in the history
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 e404559
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/usb_moded-android.c
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/usb_moded-android.h
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions src/usb_moded-dyn-config.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/usb_moded-dyn-config.h
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/usb_moded-modesetting.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e404559

Please sign in to comment.