diff --git a/config/dyn-modes/adb_mode.ini b/config/dyn-modes/adb_mode.ini index 352b8fb..63b6103 100644 --- a/config/dyn-modes/adb_mode.ini +++ b/config/dyn-modes/adb_mode.ini @@ -12,4 +12,4 @@ sysfs_reset_value = none softconnect_path = /sys/class/android_usb/android0/enable softconnect = 1 softconnec_disconnect = 0 - +idProduct = 0003 diff --git a/config/dyn-modes/developer_mode-android.ini b/config/dyn-modes/developer_mode-android.ini index 84872ab..e9cc819 100644 --- a/config/dyn-modes/developer_mode-android.ini +++ b/config/dyn-modes/developer_mode-android.ini @@ -11,4 +11,4 @@ sysfs_reset_value = none softconnect_path = /sys/class/android_usb/android0/enable softconnect = 1 softconnec_disconnect = 0 - +idProduct = 0002 diff --git a/config/dyn-modes/diag_mode.ini b/config/dyn-modes/diag_mode.ini index 2a521c9..419c555 100644 --- a/config/dyn-modes/diag_mode.ini +++ b/config/dyn-modes/diag_mode.ini @@ -2,10 +2,12 @@ name = diag_mode module = none appsync = 1 +network = 1 +network_interface = rndis0 [options] sysfs_path = /sys/class/android_usb/android0/functions -sysfs_value = diag,serial +sysfs_value = rndis,adb,diag,serial sysfs_reset_value = none softconnect_path = /sys/class/android_usb/android0/enable softconnect = 1 @@ -14,3 +16,4 @@ android_extra_sysfs_path = /sys/class/android_usb/android0/f_diag/clients android_extra_sysfs_value = diag,diag_mdm android_extra_sysfs_path2 = /sys/class/android_usb/android0/f_serial/transports android_extra_sysfs_value2 = smd,tty +idProduct = 0004 diff --git a/config/dyn-modes/pc_suite-android.ini b/config/dyn-modes/pc_suite-android.ini index cdadd24..ceae478 100644 --- a/config/dyn-modes/pc_suite-android.ini +++ b/config/dyn-modes/pc_suite-android.ini @@ -9,4 +9,4 @@ sysfs_reset_value = none softconnect_path = /sys/class/android_usb/android0/enable softconnect = 1 softconnec_disconnect = 0 - +idProduct = 0001 diff --git a/src/usb_moded-android.c b/src/usb_moded-android.c index 30590e9..a93257b 100644 --- a/src/usb_moded-android.c +++ b/src/usb_moded-android.c @@ -91,6 +91,7 @@ int set_android_charging_mode(void) /* disable, set functions to "mass_storage", re-enable */ write_to_file("/sys/class/android_usb/android0/enable", "0"); + write_to_file("/sys/class/android_usb/android0/idProduct", "9999"); write_to_file("/sys/class/android_usb/android0/functions", "mass_storage"); ret = write_to_file("/sys/class/android_usb/android0/enable", "1"); if(ret < 0) @@ -98,3 +99,19 @@ int set_android_charging_mode(void) else return(ret); } + +/* Set a product id for the android gadget + * + * @return 0 if successful, 1 on failure + */ +int set_android_productid(char *id) +{ + int ret = 0; + + /* disable, set functions to "mass_storage", re-enable */ + write_to_file("/sys/class/android_usb/android0/idProduct", id); + if(ret < 0) + return(1); + else + return(ret); +} diff --git a/src/usb_moded-android.h b/src/usb_moded-android.h index c1a718e..346ba17 100644 --- a/src/usb_moded-android.h +++ b/src/usb_moded-android.h @@ -23,3 +23,4 @@ int android_settings(void); void android_init_values(void); int set_android_charging_mode(void); +int set_android_productid(char *id); diff --git a/src/usb_moded-dyn-config.c b/src/usb_moded-dyn-config.c index 7894ed4..5619c9e 100644 --- a/src/usb_moded-dyn-config.c +++ b/src/usb_moded-dyn-config.c @@ -96,6 +96,8 @@ static struct mode_list_elem *read_mode_file(const gchar *filename) list_item->android_extra_sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE, NULL); list_item->android_extra_sysfs_value2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE2, 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); + g_key_file_free(settingsfile); if(list_item->mode_name == NULL || list_item->mode_module == NULL) { diff --git a/src/usb_moded-dyn-config.h b/src/usb_moded-dyn-config.h index 390159a..2b1c678 100644 --- a/src/usb_moded-dyn-config.h +++ b/src/usb_moded-dyn-config.h @@ -45,6 +45,8 @@ android engineers prefered to have sysfs entries... go figure... */ /* in combined android gadgets we sometime need more than one extra sysfs path or value */ #define MODE_ANDROID_EXTRA_SYSFS_PATH2 "android_extra_sysfs_path2" #define MODE_ANDROID_EXTRA_SYSFS_VALUE2 "android_extra_sysfs_value2" +/* For windows different modes/usb profiles need their own idProduct */ +#define MODE_IDPRODUCT "idProduct" /** * Struct keeping all the data needed for the definition of a dynamic mode @@ -52,21 +54,22 @@ android engineers prefered to have sysfs entries... go figure... */ typedef struct mode_list_elem { /*@{ */ - char *mode_name; /* mode name */ - char *mode_module; /* needed module for given mode */ - int appsync; /* requires appsync or not */ - int network; /* bring up network or not */ - char *network_interface; /* Which network interface to bring up if network needs to be enabled */ - char *sysfs_path; /* path to set sysfs options */ - char *sysfs_value; /* option name/value to write to sysfs */ - char *sysfs_reset_value; /* value to reset the the sysfs to default */ - char *softconnect; /* value to be written to softconnect interface */ - char *softconnect_disconnect; /* value to set on the softconnect interface to disable after disconnect */ - char *softconnect_path; /* path for the softconnect */ - char *android_extra_sysfs_path; /* path for static value that never changes that needs to be set by sysfs :( */ - char *android_extra_sysfs_value; /* static value that never changes that needs to be set by sysfs :( */ - char *android_extra_sysfs_path2; /* path for static value that never changes that needs to be set by sysfs :( */ - char *android_extra_sysfs_value2; /* static value that never changes that needs to be set by sysfs :( */ + char *mode_name; /* mode name */ + char *mode_module; /* needed module for given mode */ + int appsync; /* requires appsync or not */ + int network; /* bring up network or not */ + char *network_interface; /* Which network interface to bring up if network needs to be enabled */ + char *sysfs_path; /* path to set sysfs options */ + char *sysfs_value; /* option name/value to write to sysfs */ + char *sysfs_reset_value; /* value to reset the the sysfs to default */ + char *softconnect; /* value to be written to softconnect interface */ + char *softconnect_disconnect; /* value to set on the softconnect interface to disable after disconnect */ + char *softconnect_path; /* path for the softconnect */ + char *android_extra_sysfs_path; /* path for static value that never changes that needs to be set by sysfs :( */ + char *android_extra_sysfs_value; /* static value that never changes that needs to be set by sysfs :( */ + char *android_extra_sysfs_path2; /* path for static value that never changes that needs to be set by sysfs :( */ + char *android_extra_sysfs_value2; /* static value that never changes that needs to be set by sysfs :( */ + char *idProduct; /* product id to assign to a specific profile */ /*@} */ }mode_list_elem; diff --git a/src/usb_moded-modesetting.c b/src/usb_moded-modesetting.c index ba8e817..b15ff4d 100644 --- a/src/usb_moded-modesetting.c +++ b/src/usb_moded-modesetting.c @@ -40,6 +40,7 @@ #include "usb_moded-modesetting.h" #include "usb_moded-network.h" #include "usb_moded-upstart.h" +#include "usb_moded-android.h" static void report_mass_storage_blocker(const char *mountpoint, int try); @@ -377,6 +378,12 @@ int set_dynamic_mode(void) write_to_file(data->sysfs_path, data->sysfs_value); log_debug("writing to file %s, value %s\n", data->sysfs_path, data->sysfs_value); } + if(data->idProduct) + { + /* only works for android since the idProduct is a module parameter */ + set_android_productid(data->idProduct); + } + /* enable the device */ if(data->softconnect) { write_to_file(data->softconnect_path, data->softconnect);