diff --git a/src/usb_moded-android.c b/src/usb_moded-android.c index faf1b46..565cadc 100644 --- a/src/usb_moded-android.c +++ b/src/usb_moded-android.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); +} diff --git a/src/usb_moded-android.h b/src/usb_moded-android.h index 346ba17..e7f7ac0 100644 --- a/src/usb_moded-android.h +++ b/src/usb_moded-android.h @@ -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); diff --git a/src/usb_moded-dyn-config.c b/src/usb_moded-dyn-config.c index f4152c8..dfff972 100644 --- a/src/usb_moded-dyn-config.c +++ b/src/usb_moded-dyn-config.c @@ -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 diff --git a/src/usb_moded-dyn-config.h b/src/usb_moded-dyn-config.h index 127c1a6..81e7d2d 100644 --- a/src/usb_moded-dyn-config.h +++ b/src/usb_moded-dyn-config.h @@ -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 diff --git a/src/usb_moded-modesetting.c b/src/usb_moded-modesetting.c index af10eb8..3bdca1b 100644 --- a/src/usb_moded-modesetting.c +++ b/src/usb_moded-modesetting.c @@ -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