Skip to content

Commit

Permalink
Merge branch 'jb41302_whitelist_hiccup' into 'master'
Browse files Browse the repository at this point in the history
Do not switch from undefined mode to charging fallback

See merge request mer-core/usb-moded!33
  • Loading branch information
spiiroin committed Mar 29, 2018
2 parents cbe38f5 + 00e6688 commit b3c14f5
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 87 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -22,7 +22,7 @@ test_gcc_flag() {

# We use gnu99 instead of c99 because many have interpreted the standard
# in a way that int64_t isn't defined on non-64 bit platforms.
CFLAGS="-Os -std=gnu99 -Wall -Wextra -pipe -Wold-style-definition -Wfloat-equal -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wno-unused-parameter -finline-small-functions -Wno-unused-result -fstack-protector -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -fPIE -fpie -pie"
CFLAGS="-Os -std=gnu99 -Wall -Wextra -pipe -Wold-style-definition -Wfloat-equal -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -finline-small-functions -fstack-protector -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -fPIE -fpie -pie"
LDFLAGS="-z relro -z now"

AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug],[Enable debug @<:@default=false@:>@]),
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-appsync.c
Expand Up @@ -52,7 +52,7 @@ static void cancel_enumerate_usb_timer(void);
static GList *sync_list = NULL;

static guint enumerate_usb_id = 0;
static struct timeval sync_tv;
static struct timeval sync_tv = {0, 0};
#ifdef APP_SYNC_DBUS
static int no_dbus = 0;
#else
Expand Down
18 changes: 9 additions & 9 deletions src/usb_moded-appsync.h
Expand Up @@ -32,6 +32,8 @@
#define APP_INFO_SYSTEMD_KEY "systemd"
#define APP_INFO_POST "post"

/** Application activation state
*/
typedef enum {
/** Application is not relevant for the current mode */
APP_STATE_DONTCARE = 0,
Expand All @@ -46,15 +48,13 @@ typedef enum {
*/
typedef struct list_elem
{
/*@{*/
char *name; /* name of the app to launch */
char *mode; /* mode in which to launch the app */
char *launch; /* dbus launch command/address */
app_state_t state; /* marker to check if the app has started sucessfully */
int systemd; /* marker to know if we start it with systemd or not */
int post; /* marker to indicate when to start the app */
/*@}*/
}list_elem;
char *name; /**< name of the app to launch */
char *mode; /**< mode in which to launch the app */
char *launch; /**< dbus launch command/address */
app_state_t state; /**< marker to check if the app has started sucessfully */
int systemd; /**< marker to know if we start it with systemd or not */
int post; /**< marker to indicate when to start the app */
} list_elem;

void readlist(int diag);
int activate_sync(const char *mode);
Expand Down
7 changes: 6 additions & 1 deletion src/usb_moded-config.c
Expand Up @@ -528,7 +528,12 @@ set_config_result_t set_mode_whitelist(const char *whitelist)
g_free(mode_setting);

current_mode = get_usb_mode();
if (strcmp(current_mode, MODE_CHARGING_FALLBACK) && strcmp(current_mode, MODE_ASK) && valid_mode(current_mode)) {
if (!strcmp(current_mode, MODE_UNDEFINED)) {
/* Disconnected -> do nothing */
}
else if (strcmp(current_mode, MODE_CHARGING_FALLBACK) && strcmp(current_mode, MODE_ASK) && valid_mode(current_mode)) {
/* Invalid mode that is not MODE_ASK or MODE_CHARGING_FALLBACK
* -> switch to MODE_CHARGING_FALLBACK */
usb_moded_mode_cleanup(get_usb_module());
set_usb_mode(MODE_CHARGING_FALLBACK);
}
Expand Down
8 changes: 5 additions & 3 deletions src/usb_moded-config.h
Expand Up @@ -85,10 +85,12 @@ char * get_mode_whitelist(void);

int is_roaming_not_allowed(void);

/** Configuration change result
*/
typedef enum set_config_result_t {
SET_CONFIG_ERROR = -1,
SET_CONFIG_UPDATED,
SET_CONFIG_UNCHANGED
SET_CONFIG_ERROR = -1, /**< Value change failed */
SET_CONFIG_UPDATED, /**< Value change succeeded */
SET_CONFIG_UNCHANGED, /**< Value did not change */
} set_config_result_t;

int conf_file_merge(void);
Expand Down
7 changes: 5 additions & 2 deletions src/usb_moded-dbus.c
Expand Up @@ -47,8 +47,6 @@
static DBusConnection *dbus_connection_sys = NULL;
static gboolean have_service_name = FALSE;

extern gboolean rescue_mode;

/**
* Issues "sig_usb_config_ind" signal.
*/
Expand Down Expand Up @@ -188,6 +186,11 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa

if(!interface || !member || !object) goto EXIT;

log_debug("DBUS %s %s.%s from %s",
dbus_message_type_to_string(type),
interface, member,
dbus_message_get_sender(msg) ?: "N/A");

if( type == DBUS_MESSAGE_TYPE_SIGNAL )
{
if( !strcmp(interface, INIT_DONE_INTERFACE) && !strcmp(member, INIT_DONE_SIGNAL) ) {
Expand Down
54 changes: 26 additions & 28 deletions src/usb_moded-dyn-config.h
Expand Up @@ -65,36 +65,34 @@ 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 */
int mass_storage; /* Use mass-storage functions */
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 *android_extra_sysfs_path3; /* path for static value that never changes that needs to be set by sysfs :( */
char *android_extra_sysfs_value3; /* static value that never changes that needs to be set by sysfs :( */
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 */
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 */
int mass_storage; /**< Use mass-storage functions */
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 *android_extra_sysfs_path3; /**< Path for static value that never changes that needs to be set by sysfs :( */
char *android_extra_sysfs_value3; /**< Static value that never changes that needs to be set by sysfs :( */
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
char* connman_tethering; /* connman's tethering technology path */
char* connman_tethering; /**< Connman's tethering technology path */
#endif
/*@} */
}mode_list_elem;
} mode_list_elem;

/* diag is used to select a secondary configuration location for diagnostic purposes */
GList *read_mode_list(int diag);
Expand Down
21 changes: 16 additions & 5 deletions src/usb_moded-log.c
Expand Up @@ -65,12 +65,14 @@ static void log_gettime(struct timeval *tv)
timersub(tv, &log_begtime, tv);
}

/**
* Print the logged messages to the selected output
/** Print the logged messages to the selected output
*
* @param lev The wanted log level
* @param fmt The message to be logged
* @param va The stdarg variable list
* @param file Source file name
* @param func Function name
* @param line Line in source file
* @param lev The wanted log level
* @param fmt The message format string
* @param va Arguments for the format string
*/
void log_emit_va(const char *file, const char *func, int line, int lev, const char *fmt, va_list va)
{
Expand Down Expand Up @@ -138,6 +140,15 @@ void log_emit_va(const char *file, const char *func, int line, int lev, const ch
errno = saved;
}

/** Print the logged messages to the selected output
*
* @param file Source file name
* @param func Function name
* @param line Line in source file
* @param lev The wanted log level
* @param fmt The message format string
* @param ... Arguments for the format string
*/
void log_emit_real(const char *file, const char *func, int line, int lev, const char *fmt, ...)
{
va_list va;
Expand Down
3 changes: 0 additions & 3 deletions src/usb_moded-modules-android.c
Expand Up @@ -38,9 +38,6 @@
#include "usb_moded-config.h"
#include "usb_moded-modesetting.h"

/* kmod context - initialized at start in usb_moded_init */
struct kmod_ctx *ctx;

/** load module
*
* @param module Name of the module to load
Expand Down
4 changes: 3 additions & 1 deletion src/usb_moded-network.c
Expand Up @@ -52,7 +52,7 @@
#define UDHCP_CONFIG_DIR "/run/usb-moded"
#define UDHCP_CONFIG_LINK "/etc/udhcpd.conf"

const char default_interface[] = "usb0";
static const char default_interface[] = "usb0";

/** IP forwarding configuration block */
typedef struct ipforward_data
Expand Down Expand Up @@ -100,6 +100,8 @@ static int check_interface(char *interface)

static char* get_interface(struct mode_list_elem *data)
{
(void)data; // FIXME: why is this passed in the 1st place?

char *interface = 0;
char *setting = get_network_setting(NETWORK_INTERFACE_KEY);

Expand Down
4 changes: 3 additions & 1 deletion src/usb_moded-trigger.c
Expand Up @@ -47,7 +47,7 @@ static struct udev *udev = 0;
static struct udev_monitor *mon = 0;
static GIOChannel *iochannel = 0;
static guint watch_id = 0;
static const char *dev_name;
static const char *dev_name = 0;

/* static function definitions */
static gboolean monitor_udev(GIOChannel *iochannel G_GNUC_UNUSED, GIOCondition cond,
Expand All @@ -56,6 +56,8 @@ static void udev_parse(struct udev_device *dev);

static void notify_issue (gpointer data)
{
(void)data;

log_debug("trigger watch destroyed\n!");
/* clean up & restart trigger */
trigger_stop();
Expand Down
12 changes: 8 additions & 4 deletions src/usb_moded-udev.c
Expand Up @@ -40,10 +40,10 @@
#include "usb_moded-modes.h"

/* global variables */
static struct udev *udev;
static struct udev_monitor *mon;
static GIOChannel *iochannel;
static guint watch_id;
static struct udev *udev = 0;
static struct udev_monitor *mon = 0;
static GIOChannel *iochannel = 0;
static guint watch_id = 0;
static char *dev_name = 0;
static int cleanup = 0;
/* track cable and charger connects disconnects */
Expand All @@ -70,6 +70,8 @@ static gboolean cable_connection_timeout_cb(gpointer data);

static void notify_issue (gpointer data)
{
(void)data;

/* we do not want to restart when we try to clean up */
if(cleanup)
return;
Expand Down Expand Up @@ -335,6 +337,8 @@ static void setup_charger_connection(void)

static gboolean cable_connection_timeout_cb(gpointer data)
{
(void)data;

log_debug("connect delay: timeout");
cable_connection_timeout_id = 0;

Expand Down
5 changes: 2 additions & 3 deletions src/usb_moded-util.c
Expand Up @@ -29,8 +29,7 @@

#include "usb_moded-dbus.h"

DBusError error;
DBusConnection *conn = 0;
static DBusConnection *conn = 0;

static int query_mode (void)
{
Expand Down Expand Up @@ -408,7 +407,7 @@ int main (int argc, char *argv[])
}

/* init dbus */
dbus_error_init(&error);
DBusError error = DBUS_ERROR_INIT;

conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
if (!conn)
Expand Down

0 comments on commit b3c14f5

Please sign in to comment.