diff --git a/configure.ac b/configure.ac index e302ea8..89c40c5 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([usb_moded], [0.85.2]) +AC_INIT([usb_moded], [0.85.3]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_CONFIG_HEADER([config.h]) diff --git a/debian/changelog b/debian/changelog index 2fa92a9..692dbbb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +usb-moded (0.85.2) unstable; urgency=low + + * [hidden modes] Add support for hidden modes. Fixes: MER#1540 + + -- Philippe De Swert Tue 22 Mar 23:24:01 EET 2016 + usb-moded (0.85.2) unstable; urgency=low * [devel] Fix DIAG_MODE definition. Fixes: JB#32805 diff --git a/docs/usb_moded-doc.txt b/docs/usb_moded-doc.txt index 4a33945..f942397 100644 --- a/docs/usb_moded-doc.txt +++ b/docs/usb_moded-doc.txt @@ -14,9 +14,11 @@ Thus if you need this functionality, usb_moded needs to be started with the session. (functionality not verified yet on multi-user setups. See TODO) -Usb cable detection is supported by several different methods. -Old deprecated hal, through Nokia's own battery monitoring bme, -or the preferred udev option. (This has to be chosen at compile time) +Usb cable detection is handled with udev, it even tries to guess +which is the correct power_supply entry to use. + +A Qt lib to interact with usb-moded is available here: +https://git.merproject.org/mer-core/libusb-moded-qt Starting usb_moded ------------------- @@ -398,3 +400,19 @@ For this are the Network options. nat_interface documents which interfaces the internet facing modem. noroaming when set to 1 will prohibit enabling the modem interface in case you are roaming (this requires ofono). + + +hidden modes +------------ + +Sometimes it is useful to hide modes from the ui (the mode can be queried through dbus). +To hide modes this can be done by adding a hide= key to the +[usbmode] section. If you want to hide more modes this needs +to be a comma separated list. + +For example +[usbmode] +hide=developer_mode,bastard_mode + +Modes can also be set and removed through dbus (one mode at a time) +See usb_moded_util (-i and -u) diff --git a/src/usb_moded-config-private.h b/src/usb_moded-config-private.h index 4cb1f80..b4d3896 100644 --- a/src/usb_moded-config-private.h +++ b/src/usb_moded-config-private.h @@ -26,4 +26,6 @@ char * get_mode_setting(void); set_config_result_t set_mode_setting(const char *mode); +set_config_result_t set_hide_mode_setting(const char *mode); +set_config_result_t set_unhide_mode_setting(const char *mode); set_config_result_t set_network_setting(const char *config, const char *setting); diff --git a/src/usb_moded-config.c b/src/usb_moded-config.c index f351ddf..5ce2991 100644 --- a/src/usb_moded-config.c +++ b/src/usb_moded-config.c @@ -409,6 +409,73 @@ set_config_result_t set_mode_setting(const char *mode) return (set_config_setting(MODE_SETTING_ENTRY, MODE_SETTING_KEY, mode)); } +/* Builds the string used for hidden modes, when hide set to one builds the + new string of hidden modes when adding one, otherwise it will remove one */ +static const char * make_hidden_modes_string(const char *hidden, int hide) +{ + GString *modelist_str; + char *hidden_modes_list; + gchar **hidden_mode_split; + int i; + + + hidden_modes_list = get_hidden_modes(); + if(hidden_modes_list) + { + hidden_mode_split = g_strsplit(hidden_modes_list, ",", 0); + } + else + { + /* no hidden modes yet. So just return the original string */ + return hidden; + } + + modelist_str = g_string_new(NULL); + + for(i = 0; hidden_mode_split[i] != NULL; i++) + { + if(!strcmp(hidden_mode_split[i], hidden)) + { + /* if hiding a mode that is already hidden do nothing */ + if(hide) + return(NULL); + if(!hide) + continue; + } + modelist_str = g_string_append(modelist_str, hidden_mode_split[i]); + if(hidden_mode_split[i+1] != NULL) + modelist_str = g_string_append(modelist_str, ","); + } + if(hide) + { + modelist_str = g_string_append(modelist_str, ","); + modelist_str = g_string_append(modelist_str, hidden); + } + + g_strfreev(hidden_mode_split); + return(g_string_free(modelist_str, FALSE)); +} + +set_config_result_t set_hide_mode_setting(const char *mode) +{ + set_config_result_t ret; + + ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, make_hidden_modes_string(mode, 1)); + if(ret == SET_CONFIG_UPDATED) + send_supported_modes_signal(); + return(ret); +} + +set_config_result_t set_unhide_mode_setting(const char *mode) +{ + set_config_result_t ret; + + ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, make_hidden_modes_string(mode, 0)); + if(ret == SET_CONFIG_UPDATED) + send_supported_modes_signal(); + return(ret); +} + /* * @param config : the key to be set * @param setting : The value to be set @@ -515,7 +582,7 @@ int conf_file_merge(void) { GDir *confdir; struct stat fileinfo, dir; - char *mode = 0, *ip = 0, *gateway = 0, *udev = 0; + char *mode = 0, *ip = 0, *gateway = 0, *udev = 0, *hide = 0; gchar *filename_full; const gchar *filename; GString *keyfile_string = NULL; @@ -575,8 +642,11 @@ int conf_file_merge(void) mode = get_mode_setting(); /* store udev path (especially important for the upgrade path */ udev = find_udev_path(); + /* store network info */ ip = get_conf_string(NETWORK_ENTRY, NETWORK_IP_KEY); gateway = get_conf_string(NETWORK_ENTRY, NETWORK_GATEWAY_KEY); + /* store hidden modes */ + hide = get_hidden_modes(); continue; } /* load contents of file, if it fails skip to next one */ @@ -617,6 +687,9 @@ int conf_file_merge(void) set_network_setting(NETWORK_IP_KEY, ip); if(gateway) set_network_setting(NETWORK_GATEWAY_KEY, gateway); + /* re-add hidden modes info */ + if(hide) + set_hide_mode_setting(hide); } else ret = 1; @@ -655,6 +728,11 @@ char * get_android_product_id(void) return(get_conf_string(ANDROID_ENTRY, ANDROID_PRODUCT_ID_KEY)); } +char * get_hidden_modes(void) +{ + return(get_conf_string(MODE_SETTING_ENTRY, MODE_HIDE_KEY)); +} + int check_android_section(void) { GKeyFile *settingsfile; diff --git a/src/usb_moded-config.h b/src/usb_moded-config.h index 8a8e8a3..2afb1ff 100644 --- a/src/usb_moded-config.h +++ b/src/usb_moded-config.h @@ -57,6 +57,7 @@ #define ANDROID_VENDOR_ID_KEY "idVendor" #define ANDROID_PRODUCT_KEY "iProduct" #define ANDROID_PRODUCT_ID_KEY "idProduct" +#define MODE_HIDE_KEY "hide" const char * find_mounts(void); int find_sync(void); @@ -78,6 +79,8 @@ char * get_android_vendor_id(void); char * get_android_product(void); char * get_android_product_id(void); +char * get_hidden_modes(void); + int check_android_section(void); int is_roaming_not_allowed(void); diff --git a/src/usb_moded-dbus.c b/src/usb_moded-dbus.c index 16a159e..f2b0830 100644 --- a/src/usb_moded-dbus.c +++ b/src/usb_moded-dbus.c @@ -8,14 +8,14 @@ @author: Philippe De Swert This program is free software; you can redistribute it and/or - modify it under the terms of the Lesser GNU General Public License - version 2 as published by the Free Software Foundation. + modify it under the terms of the Lesser GNU General Public License + version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the Lesser GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA @@ -70,7 +70,7 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa const char *member = dbus_message_get_member(msg); const char *object = dbus_message_get_path(msg); int type = dbus_message_get_type(msg); - const char *xml = "\n" "\n" " \n" @@ -131,25 +131,25 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa if( type == DBUS_MESSAGE_TYPE_METHOD_CALL && !strcmp(interface, USB_MODE_INTERFACE) && !strcmp(object, USB_MODE_OBJECT)) { - status = DBUS_HANDLER_RESULT_HANDLED; - - if(!strcmp(member, USB_MODE_STATE_REQUEST)) - { + status = DBUS_HANDLER_RESULT_HANDLED; + + if(!strcmp(member, USB_MODE_STATE_REQUEST)) + { const char *mode = get_usb_mode(); /* To the outside we want to keep CHARGING and CHARGING_FALLBACK the same */ if(!strcmp(MODE_CHARGING_FALLBACK, mode)) mode = MODE_CHARGING; - if((reply = dbus_message_new_method_return(msg))) - dbus_message_append_args (reply, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID); - } - else if(!strcmp(member, USB_MODE_STATE_SET)) - { - char *use = 0; - DBusError err = DBUS_ERROR_INIT; - - if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID)) - reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); + if((reply = dbus_message_new_method_return(msg))) + dbus_message_append_args (reply, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID); + } + else if(!strcmp(member, USB_MODE_STATE_SET)) + { + char *use = 0; + DBusError err = DBUS_ERROR_INIT; + + if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID)) + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); else { /* check if usb is connected, since it makes no sense to change mode if it isn't */ @@ -167,21 +167,21 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa usb_moded_mode_cleanup(get_usb_module()); set_usb_mode(use); } - if((reply = dbus_message_new_method_return(msg))) - dbus_message_append_args (reply, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID); + if((reply = dbus_message_new_method_return(msg))) + dbus_message_append_args (reply, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID); else error_reply: - reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); } dbus_error_free(&err); } else if(!strcmp(member, USB_MODE_CONFIG_SET)) { - char *config = 0; - DBusError err = DBUS_ERROR_INIT; + char *config = 0; + DBusError err = DBUS_ERROR_INIT; - if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID)) - reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); + if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID)) + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); else { /* error checking is done when setting configuration */ @@ -190,21 +190,67 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa usb_moded_send_config_signal(MODE_SETTING_ENTRY, MODE_SETTING_KEY, config); if (SET_CONFIG_OK(ret)) { - if((reply = dbus_message_new_method_return(msg))) - dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID); + if((reply = dbus_message_new_method_return(msg))) + dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID); } else - reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config); + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config); } - dbus_error_free(&err); + dbus_error_free(&err); + } + else if(!strcmp(member, USB_MODE_HIDE)) + { + char *config = 0; + DBusError err = DBUS_ERROR_INIT; + + if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID)) + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); + else + { + /* error checking is done when setting configuration */ + int ret = set_hide_mode_setting(config); + if (ret == SET_CONFIG_UPDATED) + usb_moded_send_config_signal(MODE_SETTING_ENTRY, MODE_HIDE_KEY, config); + if (SET_CONFIG_OK(ret)) + { + if((reply = dbus_message_new_method_return(msg))) + dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID); + } + else + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config); + } + dbus_error_free(&err); + } + else if(!strcmp(member, USB_MODE_UNHIDE)) + { + char *config = 0; + DBusError err = DBUS_ERROR_INIT; + + if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID)) + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); + else + { + /* error checking is done when setting configuration */ + int ret = set_unhide_mode_setting(config); + if (ret == SET_CONFIG_UPDATED) + usb_moded_send_config_signal(MODE_SETTING_ENTRY, MODE_HIDE_KEY, config); + if (SET_CONFIG_OK(ret)) + { + if((reply = dbus_message_new_method_return(msg))) + dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID); + } + else + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config); + } + dbus_error_free(&err); } else if(!strcmp(member, USB_MODE_NETWORK_SET)) { - char *config = 0, *setting = 0; - DBusError err = DBUS_ERROR_INIT; + char *config = 0, *setting = 0; + DBusError err = DBUS_ERROR_INIT; - if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID)) - reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); + if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID)) + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member); else { /* error checking is done when setting configuration */ @@ -213,14 +259,14 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa usb_moded_send_config_signal(NETWORK_ENTRY, config, setting); if (SET_CONFIG_OK(ret)) { - if((reply = dbus_message_new_method_return(msg))) - dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID); + if((reply = dbus_message_new_method_return(msg))) + dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID); usb_network_update(); } else - reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config); + reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config); } - dbus_error_free(&err); + dbus_error_free(&err); } else if(!strcmp(member, USB_MODE_NETWORK_GET)) { @@ -248,9 +294,9 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa else if(!strcmp(member, USB_MODE_CONFIG_GET)) { char *config = get_mode_setting(); - - if((reply = dbus_message_new_method_return(msg))) - dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID); + + if((reply = dbus_message_new_method_return(msg))) + dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID); free(config); } else if(!strcmp(member, USB_MODE_LIST)) @@ -267,23 +313,23 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa log_debug("Rescue mode off\n "); reply = dbus_message_new_method_return(msg); } - else - { - /*unknown methods are handled here */ - reply = dbus_message_new_error(msg, DBUS_ERROR_UNKNOWN_METHOD, member); - } - - if( !reply ) - { - reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, member); - } + else + { + /*unknown methods are handled here */ + reply = dbus_message_new_error(msg, DBUS_ERROR_UNKNOWN_METHOD, member); + } + + if( !reply ) + { + reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, member); + } } else if( type == DBUS_MESSAGE_TYPE_METHOD_CALL && !strcmp(interface, "org.freedesktop.DBus.Introspectable") && !strcmp(object, USB_MODE_OBJECT) && !strcmp(member, "Introspect")) { - status = DBUS_HANDLER_RESULT_HANDLED; + status = DBUS_HANDLER_RESULT_HANDLED; - if((reply = dbus_message_new_method_return(msg))) + if((reply = dbus_message_new_method_return(msg))) dbus_message_append_args (reply, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID); } @@ -292,12 +338,12 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa if(reply) { - if( !dbus_message_get_no_reply(msg) ) - { - if( !dbus_connection_send(connection, reply, 0) ) - log_debug("Failed sending reply. Out Of Memory!\n"); - } - dbus_message_unref(reply); + if( !dbus_message_get_no_reply(msg) ) + { + if( !dbus_connection_send(connection, reply, 0) ) + log_debug("Failed sending reply. Out Of Memory!\n"); + } + dbus_message_unref(reply); } return status; @@ -317,19 +363,19 @@ gboolean usb_moded_dbus_init(void) dbus_error_init(&error); /* connect to system bus */ - if ((dbus_connection_sys = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) == NULL) + if ((dbus_connection_sys = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) == NULL) { - log_debug("Failed to open connection to system message bus; %s\n", error.message); + log_debug("Failed to open connection to system message bus; %s\n", error.message); goto EXIT; } /* Initialise message handlers */ - if (!dbus_connection_add_filter(dbus_connection_sys, msg_handler, NULL, NULL)) - goto EXIT; + if (!dbus_connection_add_filter(dbus_connection_sys, msg_handler, NULL, NULL)) + goto EXIT; /* Acquire D-Bus service */ ret = dbus_bus_request_name(dbus_connection_sys, USB_MODE_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error); - if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { log_debug("failed claiming dbus name\n"); if( dbus_error_is_set(&error) ) @@ -349,7 +395,7 @@ gboolean usb_moded_dbus_init(void) /* everything went fine */ status = TRUE; -EXIT: +EXIT: dbus_error_free(&error); return status; } @@ -361,7 +407,7 @@ gboolean usb_moded_dbus_init(void) void usb_moded_dbus_cleanup(void) { /* clean up system bus connection */ - if (dbus_connection_sys != NULL) + if (dbus_connection_sys != NULL) { dbus_bus_release_name(dbus_connection_sys, USB_MODE_SERVICE, NULL); dbus_connection_remove_filter(dbus_connection_sys, msg_handler, NULL); @@ -387,31 +433,31 @@ static int usb_moded_dbus_signal(const char *signal_type, const char *content) log_err("Dbus system connection broken!\n"); goto EXIT; } - // create a signal and check for errors + // create a signal and check for errors msg = dbus_message_new_signal(USB_MODE_OBJECT, USB_MODE_INTERFACE, signal_type ); - if (NULL == msg) - { - log_debug("Message Null\n"); + if (NULL == msg) + { + log_debug("Message Null\n"); goto EXIT; } // append arguments onto signal - if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &content, DBUS_TYPE_INVALID)) - { - log_debug("Appending arguments failed. Out Of Memory!\n"); + if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &content, DBUS_TYPE_INVALID)) + { + log_debug("Appending arguments failed. Out Of Memory!\n"); goto EXIT; } // send the message on the correct bus and flush the connection - if (!dbus_connection_send(dbus_connection_sys, msg, 0)) + if (!dbus_connection_send(dbus_connection_sys, msg, 0)) { - log_debug("Failed sending message. Out Of Memory!\n"); + log_debug("Failed sending message. Out Of Memory!\n"); goto EXIT; } result = 0; -EXIT: - // free the message +EXIT: + // free the message if(msg != 0) dbus_message_unref(msg); diff --git a/src/usb_moded-dbus.h b/src/usb_moded-dbus.h index 4f35158..eaf4279 100644 --- a/src/usb_moded-dbus.h +++ b/src/usb_moded-dbus.h @@ -43,10 +43,8 @@ #define USB_MODE_RESCUE_OFF "rescue_off" /* turns rescue mode off so normal mode selection is restored */ #define USB_MODE_CONFIG_GET "get_config" /* returns the mode set in the config */ #define USB_MODE_LIST "get_modes" /* returns a comma-separated list of supported modes for ui's */ - -/** - * @credential usb-moded::USBControl Credential needed to be able to call the set_mode or set_config methods -**/ +#define USB_MODE_HIDE "hide_mode" /* hide a mode */ +#define USB_MODE_UNHIDE "unhide_mode" /* unhide a mode */ #define USB_MODE_STATE_SET "set_mode" /* set a mode (only works when connected) */ #define USB_MODE_CONFIG_SET "set_config" /* set the mode that needs to be activated in the config file */ #define USB_MODE_NETWORK_SET "net_config" /* set the network config in the config file */ diff --git a/src/usb_moded-modes.h b/src/usb_moded-modes.h index d72b7e6..0c01d4f 100644 --- a/src/usb_moded-modes.h +++ b/src/usb_moded-modes.h @@ -44,3 +44,5 @@ **/ #define MODE_CHARGING_FALLBACK "charging_only_fallback" #define MODE_CHARGER "dedicated_charger" + +void send_supported_modes_signal(void); diff --git a/src/usb_moded-network.c b/src/usb_moded-network.c index 4c6e8c7..218f262 100644 --- a/src/usb_moded-network.c +++ b/src/usb_moded-network.c @@ -615,8 +615,10 @@ static int connman_fill_connection_data(DBusMessage *reply, struct ipforward_dat /* if cellular not online, connect it */ if(strcmp(string, "online")) { - log_debug("Not online. Turning on cellular data connection.\n"); - return(1); + /* if in ready state connection might be up anyway */ + if(strcmp(string, "ready")) + log_debug("Not online. Turning on cellular data connection.\n"); + return(1); } } diff --git a/src/usb_moded-util.c b/src/usb_moded-util.c index 03ee6c6..cb5f29a 100644 --- a/src/usb_moded-util.c +++ b/src/usb_moded-util.c @@ -181,7 +181,61 @@ static int set_mode_config (char *mode) printf("mode set in the configuration file = %s\n", ret); return 0; } - + + /* not everything went as planned, return error */ + return 1; +} + +static int set_hide_mode_config (char *mode) +{ + DBusMessage *req = NULL, *reply = NULL; + char *ret = 0; + + printf("Trying to hide the following mode %s in the config file\n", mode); + if ((req = dbus_message_new_method_call(USB_MODE_SERVICE, USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_HIDE)) != NULL) + { + dbus_message_append_args (req, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID); + if ((reply = dbus_connection_send_with_reply_and_block(conn, req, -1, NULL)) != NULL) + { + dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &ret, DBUS_TYPE_INVALID); + dbus_message_unref(reply); + } + dbus_message_unref(req); + } + + if(ret) + { + printf("mode hidden = %s\n", ret); + return 0; + } + + /* not everything went as planned, return error */ + return 1; +} + +static int set_unhide_mode_config (char *mode) +{ + DBusMessage *req = NULL, *reply = NULL; + char *ret = 0; + + printf("Trying to unhide the following mode %s in the config file\n", mode); + if ((req = dbus_message_new_method_call(USB_MODE_SERVICE, USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_UNHIDE)) != NULL) + { + dbus_message_append_args (req, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID); + if ((reply = dbus_connection_send_with_reply_and_block(conn, req, -1, NULL)) != NULL) + { + dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &ret, DBUS_TYPE_INVALID); + dbus_message_unref(reply); + } + dbus_message_unref(req); + } + + if(ret) + { + printf("mode unhidden = %s\n", ret); + return 0; + } + /* not everything went as planned, return error */ return 1; } @@ -260,7 +314,7 @@ static int handle_network(char *network) int main (int argc, char *argv[]) { int query = 0, network = 0, setmode = 0, config = 0; - int modelist = 0, mode_configured = 0; + int modelist = 0, mode_configured = 0, hide = 0, unhide = 0; int res = 1, opt, rescue = 0; char *option = 0; @@ -270,7 +324,7 @@ int main (int argc, char *argv[]) exit(1); } - while ((opt = getopt(argc, argv, "c:dhmn:qrs:")) != -1) + while ((opt = getopt(argc, argv, "c:dhi:mn:qrs:u:")) != -1) { switch (opt) { case 'c': @@ -280,6 +334,10 @@ int main (int argc, char *argv[]) case 'd': mode_configured = 1; break; + case 'i': + hide = 1; + option = optarg; + break; case 'm': modelist = 1; break; @@ -297,6 +355,10 @@ int main (int argc, char *argv[]) setmode = 1; option = optarg; break; + case 'u': + unhide = 1; + option = optarg; + break; case 'h': default: fprintf(stderr, "\nUsage: %s -