Skip to content

Commit

Permalink
Enable setting idProduct per mode
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Aug 23, 2013
1 parent 7289239 commit d6a30bf
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion config/dyn-modes/adb_mode.ini
Expand Up @@ -12,4 +12,4 @@ sysfs_reset_value = none
softconnect_path = /sys/class/android_usb/android0/enable
softconnect = 1
softconnec_disconnect = 0

idProduct = 0003
2 changes: 1 addition & 1 deletion config/dyn-modes/developer_mode-android.ini
Expand Up @@ -11,4 +11,4 @@ sysfs_reset_value = none
softconnect_path = /sys/class/android_usb/android0/enable
softconnect = 1
softconnec_disconnect = 0

idProduct = 0002
5 changes: 4 additions & 1 deletion config/dyn-modes/diag_mode.ini
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion config/dyn-modes/pc_suite-android.ini
Expand Up @@ -9,4 +9,4 @@ sysfs_reset_value = none
softconnect_path = /sys/class/android_usb/android0/enable
softconnect = 1
softconnec_disconnect = 0

idProduct = 0001
17 changes: 17 additions & 0 deletions src/usb_moded-android.c
Expand Up @@ -91,10 +91,27 @@ 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)
return(1);
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);
}
1 change: 1 addition & 0 deletions src/usb_moded-android.h
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions src/usb_moded-dyn-config.c
Expand Up @@ -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)
{
Expand Down
33 changes: 18 additions & 15 deletions src/usb_moded-dyn-config.h
Expand Up @@ -45,28 +45,31 @@ 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
*/
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;

Expand Down
7 changes: 7 additions & 0 deletions src/usb_moded-modesetting.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d6a30bf

Please sign in to comment.