diff options
author | Nishant Chaprana <n.chaprana@samsung.com> | 2019-09-17 19:00:55 +0530 |
---|---|---|
committer | Nishant Chaprana <n.chaprana@samsung.com> | 2019-09-18 19:23:41 +0530 |
commit | 26cc90dfaf2ad149b702626f9552c81abbb26862 (patch) | |
tree | 2524c8994cf58358350fde67dfba5c3b8cb58f7d /client | |
parent | 9e3beb21876b6e63bd8acf53e751480d7a1cc16f (diff) | |
parent | 6b2381a2adabea7d8309ff158ef675ff88184305 (diff) | |
download | connman-26cc90dfaf2ad149b702626f9552c81abbb26862.tar.gz connman-26cc90dfaf2ad149b702626f9552c81abbb26862.tar.bz2 connman-26cc90dfaf2ad149b702626f9552c81abbb26862.zip |
Imported Upstream version 1.37submit/tizen/20190920.082459
Change-Id: Idb47c1ddbedc9f97181b8e9a5eeac04ddd832a2c
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
Diffstat (limited to 'client')
-rw-r--r-- | client/commands.c | 231 | ||||
-rw-r--r-- | client/tethering.c | 63 | ||||
-rw-r--r-- | client/tethering.h | 39 |
3 files changed, 298 insertions, 35 deletions
diff --git a/client/commands.c b/client/commands.c index ce827919..6abe7db5 100644 --- a/client/commands.c +++ b/client/commands.c @@ -39,6 +39,7 @@ #include "dbus_helpers.h" #include "input.h" #include "services.h" +#include "tethering.h" #include "peers.h" #include "commands.h" #include "agent.h" @@ -248,7 +249,7 @@ static int state_print(DBusMessageIter *iter, const char *error, DBusMessageIter entry; if (error) { - fprintf(stderr, "Error: %s", error); + fprintf(stderr, "Error: %s\n", error); return 0; } @@ -275,7 +276,7 @@ static int clock_print(DBusMessageIter *iter, const char *error, DBusMessageIter entry; if (error) { - fprintf(stderr, "Error: %s", error); + fprintf(stderr, "Error: %s\n", error); return 0; } @@ -321,6 +322,18 @@ static int peers_list(DBusMessageIter *iter, return 0; } +static int tethering_clients_list(DBusMessageIter *iter, + const char *error, void *user_data) +{ + if (!error) { + __connmanctl_tethering_clients_list(iter); + fprintf(stdout, "\n"); + } else + fprintf(stderr, "Error: %s\n", error); + + return 0; +} + static int object_properties(DBusMessageIter *iter, const char *error, void *user_data) { @@ -1214,6 +1227,17 @@ static int cmd_tether(char *args[], int num, struct connman_option *options) return tether_set(args[1], set_tethering); } +static int cmd_tethering_clients(char *args[], int num, struct connman_option *options) +{ + if (num > 1) + return -E2BIG; + + return __connmanctl_dbus_method_call(connection, + CONNMAN_SERVICE, CONNMAN_PATH, + "net.connman.Manager", "GetTetheringClients", + tethering_clients_list, NULL, NULL, NULL); +} + static int scan_return(DBusMessageIter *iter, const char *error, void *user_data) { @@ -1367,8 +1391,6 @@ static void move_before_append_args(DBusMessageIter *iter, void *user_data) dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); - - return; } static int cmd_service_move_before(char *args[], int num, @@ -1427,8 +1449,6 @@ static void move_after_append_args(DBusMessageIter *iter, void *user_data) dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); - - return; } static int cmd_service_move_after(char *args[], int num, @@ -1476,6 +1496,13 @@ struct config_append { int values; }; +struct session_options { + char **args; + int num; + char *notify_path; + struct connman_option *options; +}; + static void config_append_ipv4(DBusMessageIter *iter, void *user_data) { @@ -1777,6 +1804,30 @@ static int cmd_config(char *args[], int num, struct connman_option *options) config_return, g_strdup(service_name), NULL, NULL); break; + + case 'm': + switch (parse_boolean(*opt_start)) { + case 1: + val = TRUE; + break; + case 0: + val = FALSE; + break; + default: + res = -EINVAL; + break; + } + if (res == 0) { + res = __connmanctl_dbus_set_property(connection, + path, "net.connman.Service", + config_return, + g_strdup(service_name), + "mDNS.Configuration", + DBUS_TYPE_BOOLEAN, &val); + } + index++; + break; + default: res = -EINVAL; break; @@ -2310,7 +2361,7 @@ static int session_connect_cb(DBusMessageIter *iter, const char *error, void *user_data) { if (error) { - fprintf(stderr, "Error: %s", error); + fprintf(stderr, "Error: %s\n", error); return 0; } @@ -2329,7 +2380,7 @@ static int session_disconnect_cb(DBusMessageIter *iter, const char *error, void *user_data) { if (error) - fprintf(stderr, "Error: %s", error); + fprintf(stderr, "Error: %s\n", error); return 0; } @@ -2371,28 +2422,140 @@ static int session_create_cb(DBusMessageIter *iter, const char *error, return -EINPROGRESS; } +static void session_config_append_array(DBusMessageIter *iter, + void *user_data) +{ + struct config_append *append = user_data; + char **opts = append->opts; + int i = 1; + + if (!opts) + return; + + while (opts[i] && strncmp(opts[i], "--", 2) != 0) { + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, + &opts[i]); + i++; + } + + append->values = i; +} + +static void session_create_append_dict(DBusMessageIter *iter, void *user_data) +{ + struct session_options *args_struct = user_data; + int index = 0, res = 0; + struct config_append append; + char c; + char *ifname; + dbus_bool_t source_ip_rule; + + while (index < args_struct->num && args_struct->args[index]) { + append.opts = &args_struct->args[index]; + append.values = 0; + + c = parse_args(args_struct->args[index], args_struct->options); + + switch (c) { + case 'b': + __connmanctl_dbus_append_dict_string_array(iter, "AllowedBearers", + session_config_append_array, + &append); + break; + case 't': + if (! args_struct->args[index + 1]) { + res = -EINVAL; + break; + } + __connmanctl_dbus_append_dict_entry(iter, "ConnectionType", + DBUS_TYPE_STRING, + &args_struct->args[index + 1]); + append.values = 2; + break; + case 'i': + if (index + 1 < args_struct->num) + ifname = args_struct->args[index + 1]; + else + ifname = ""; + __connmanctl_dbus_append_dict_entry(iter, "AllowedInterface", + DBUS_TYPE_STRING, + &ifname); + append.values = 2; + break; + case 's': + if (! args_struct->args[index + 1]) { + res = -EINVAL; + break; + } + switch (parse_boolean( args_struct->args[index + 1])) { + case 1: + source_ip_rule = TRUE; + break; + case 0: + source_ip_rule = FALSE; + break; + default: + res = -EINVAL; + break; + } + __connmanctl_dbus_append_dict_entry(iter, "SourceIPRule", + DBUS_TYPE_BOOLEAN, + &source_ip_rule); + append.values = 2; + break; + case 'c': + if (!args_struct->args[index + 1]) { + res = -EINVAL; + break; + } + __connmanctl_dbus_append_dict_entry(iter, "ContextIdentifier", + DBUS_TYPE_STRING, + &args_struct->args[index + 1]); + append.values = 2; + break; + default: + res = -EINVAL; + } + + if (res < 0 && res != -EINPROGRESS) { + printf("Error '%s': %s\n", args_struct->args[index], + strerror(-res)); + return; + } + + index += append.values; + } +} + static void session_create_append(DBusMessageIter *iter, void *user_data) { - const char *notify_path = user_data; + struct session_options *args_struct = user_data; - __connmanctl_dbus_append_dict(iter, NULL, NULL); + __connmanctl_dbus_append_dict(iter, session_create_append_dict, + args_struct); dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, - ¬ify_path); + &args_struct->notify_path); } -static int session_create(gboolean connect) +static int session_create(gboolean connect, char *args[], int num, + struct connman_option *options) { int res; char *notify_path; + struct session_options args_struct; + args_struct.args = args; + args_struct.num = num; + args_struct.options = options; notify_path = g_strdup_printf("/net/connman/connmanctl%d", getpid()); session_notify_add(notify_path); + args_struct.notify_path = notify_path; res = __connmanctl_dbus_method_call(connection, "net.connman", "/", "net.connman.Manager", "CreateSession", session_create_cb, GINT_TO_POINTER(connect), - session_create_append, notify_path); + session_create_append, &args_struct); g_free(notify_path); @@ -2446,25 +2609,6 @@ static int session_config_return(DBusMessageIter *iter, const char *error, return 0; } -static void session_config_append_array(DBusMessageIter *iter, - void *user_data) -{ - struct config_append *append = user_data; - char **opts = append->opts; - int i = 1; - - if (!opts) - return; - - while (opts[i] && strncmp(opts[i], "--", 2) != 0) { - dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, - &opts[i]); - i++; - } - - append->values = i; -} - static int session_config(char *args[], int num, struct connman_option *options) { @@ -2534,6 +2678,18 @@ static int session_config(char *args[], int num, DBUS_TYPE_BOOLEAN, &source_ip_rule); append.values = 2; break; + case 'c': + if (!args[index + 1]) { + res = -EINVAL; + break; + } + + res = __connmanctl_dbus_session_change(connection, + session_path, session_config_return, + "ctxid", "ctxid", DBUS_TYPE_STRING, + &args[index + 1]); + append.values = 2; + break; default: res = -EINVAL; @@ -2569,12 +2725,13 @@ static int cmd_session(char *args[], int num, struct connman_option *options) case 1: if (session_path) return -EALREADY; - return session_create(FALSE); + return session_create(FALSE, &args[2], num - 2, options); default: if (!strcmp(command, "connect")) { if (!session_path) - return session_create(TRUE); + return session_create(TRUE, &args[2], num - 2, + options); return session_connect(); @@ -2797,6 +2954,7 @@ static struct connman_option config_options[] = { {"nameservers", 'n', "<dns1> [<dns2>] [<dns3>]"}, {"timeservers", 't', "<ntp1> [<ntp2>] [...]"}, {"domains", 'd', "<domain1> [<domain2>] [...]"}, + {"mdns", 'm', "yes|no"}, {"ipv6", 'v', "off|auto [enable|disable|preferred]|\n" "\t\t\tmanual <address> <prefixlength> <gateway>"}, {"proxy", 'x', "direct|auto <URL>|manual <URL1> [<URL2>] [...]\n" @@ -2823,6 +2981,7 @@ static struct connman_option session_options[] = { {"type", 't', "local|internet|any"}, {"ifname", 'i', "[<interface_name>]"}, {"srciprule", 's', "yes|no"}, + {"ctxid", 'c', "<context_identifier>"}, { NULL, } }; @@ -3237,6 +3396,8 @@ static const struct { NULL, cmd_tether, "Enable, disable tethering, set SSID and passphrase for wifi", lookup_tether }, + { "tethering_clients", NULL, NULL, cmd_tethering_clients, + "Display tethering clients", NULL }, { "services", "[<service>]", service_options, cmd_services, "Display services", lookup_service_arg }, { "peers", "[peer]", NULL, cmd_peers, @@ -3654,7 +3815,7 @@ static int populate_technology_hash(DBusMessageIter *iter, const char *error, void *user_data) { if (error) { - fprintf(stderr, "Error getting technologies: %s", error); + fprintf(stderr, "Error getting technologies: %s\n", error); return 0; } diff --git a/client/tethering.c b/client/tethering.c new file mode 100644 index 00000000..361189be --- /dev/null +++ b/client/tethering.c @@ -0,0 +1,63 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2014 Intel Corporation. All rights reserved. + * Copyright (C) 2018 GlobalLogic. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <stdio.h> + +#include "tethering.h" + +void __connmanctl_tethering_clients_list(DBusMessageIter *iter) +{ + DBusMessageIter array; + char *addr = NULL; + + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(iter, &array); + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&array, &addr); + + fprintf(stdout, "%s", addr); + + if (dbus_message_iter_has_next(&array)) + fprintf(stdout, "\n"); + + dbus_message_iter_next(&array); + } + + dbus_message_iter_next(iter); + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(iter, &array); + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&array, &addr); + + fprintf(stdout, "\n%s %s", "removed", addr); + + if (dbus_message_iter_has_next(&array)) + fprintf(stdout, "\n"); + + dbus_message_iter_next(&array); + } +} diff --git a/client/tethering.h b/client/tethering.h new file mode 100644 index 00000000..6135e3c5 --- /dev/null +++ b/client/tethering.h @@ -0,0 +1,39 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2014 Intel Corporation. All rights reserved. + * Copyright (C) 2018 GlobalLogic. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CONNMANCTL_TETHERING_H +#define __CONNMANCTL_TETHERING_H + +#include <dbus/dbus.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void __connmanctl_tethering_clients_list(DBusMessageIter *iter); + +#ifdef __cplusplus +} +#endif + +#endif /* __CONNMANCTL_TETHERING_H */ |