5 * Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include <sys/types.h>
39 #include "dbus_helpers.h"
42 #if defined TIZEN_EXT_INS
45 #include "tethering.h"
49 #include "vpnconnections.h"
50 #if defined TIZEN_EXT_WIFI_MESH
54 static DBusConnection *connection;
55 static GHashTable *service_hash;
56 static GHashTable *vpnconnection_hash;
57 static GHashTable *peer_hash;
58 static GHashTable *technology_hash;
59 static char *session_notify_path;
60 static char *session_path;
61 static bool session_connected;
63 struct connman_option {
69 static char *ipv4[] = {
77 static char *ipv6[] = {
85 static int cmd_help(char *args[], int num, struct connman_option *options);
87 static bool check_dbus_name(const char *name)
90 * Valid dbus chars should be [A-Z][a-z][0-9]_
91 * and should not start with number.
95 if (!name || name[0] == '\0')
98 for (i = 0; name[i] != '\0'; i++)
99 if (!((name[i] >= 'A' && name[i] <= 'Z') ||
100 (name[i] >= 'a' && name[i] <= 'z') ||
101 (name[i] >= '0' && name[i] <= '9') ||
108 static int parse_boolean(char *arg)
113 if (strcasecmp(arg, "no") == 0 ||
114 strcasecmp(arg, "false") == 0 ||
115 strcasecmp(arg, "off" ) == 0 ||
116 strcasecmp(arg, "disable" ) == 0 ||
117 strcasecmp(arg, "n") == 0 ||
118 strcasecmp(arg, "f") == 0 ||
119 strcasecmp(arg, "0") == 0)
122 if (strcasecmp(arg, "yes") == 0 ||
123 strcasecmp(arg, "true") == 0 ||
124 strcasecmp(arg, "on") == 0 ||
125 strcasecmp(arg, "enable" ) == 0 ||
126 strcasecmp(arg, "y") == 0 ||
127 strcasecmp(arg, "t") == 0 ||
128 strcasecmp(arg, "1") == 0)
134 static int parse_args(char *arg, struct connman_option *options)
141 for (i = 0; options[i].name; i++) {
142 if (strcmp(options[i].name, arg) == 0 ||
143 (strncmp(arg, "--", 2) == 0 &&
144 strcmp(&arg[2], options[i].name) == 0))
145 return options[i].val;
151 static int enable_return(DBusMessageIter *iter, int errnum, const char *error,
154 char *tech = user_data;
157 str = strrchr(tech, '/');
165 fprintf(stdout, "Enabled %s\n", str);
168 fprintf(stderr, "%s is not available\n", str);
171 fprintf(stderr, "%s is already enabled\n", str);
174 fprintf(stderr, "Error %s: %s\n", str, error);
182 static int cmd_enable(char *args[], int num, struct connman_option *options)
185 dbus_bool_t b = TRUE;
193 if (check_dbus_name(args[1]) == false)
196 if (strcmp(args[1], "offline") == 0) {
197 tech = g_strdup(args[1]);
198 return __connmanctl_dbus_set_property(connection, "/",
199 "net.connman.Manager", enable_return, tech,
200 "OfflineMode", DBUS_TYPE_BOOLEAN, &b);
203 tech = g_strdup_printf("/net/connman/technology/%s", args[1]);
204 return __connmanctl_dbus_set_property(connection, tech,
205 "net.connman.Technology", enable_return, tech,
206 "Powered", DBUS_TYPE_BOOLEAN, &b);
209 static int disable_return(DBusMessageIter *iter, int errnum, const char *error,
212 char *tech = user_data;
215 str = strrchr(tech, '/');
223 fprintf(stdout, "Disable %s\n", str);
226 fprintf(stderr, "%s is not available\n", str);
229 fprintf(stderr, "%s is already disabled\n", str);
232 fprintf(stderr, "Error %s: %s\n", str, error);
240 static int cmd_disable(char *args[], int num, struct connman_option *options)
243 dbus_bool_t b = FALSE;
251 if (check_dbus_name(args[1]) == false)
254 if (strcmp(args[1], "offline") == 0) {
255 tech = g_strdup(args[1]);
256 return __connmanctl_dbus_set_property(connection, "/",
257 "net.connman.Manager", disable_return, tech,
258 "OfflineMode", DBUS_TYPE_BOOLEAN, &b);
261 tech = g_strdup_printf("/net/connman/technology/%s", args[1]);
262 return __connmanctl_dbus_set_property(connection, tech,
263 "net.connman.Technology", disable_return, tech,
264 "Powered", DBUS_TYPE_BOOLEAN, &b);
267 static int state_print(DBusMessageIter *iter, int errnum, const char *error,
270 DBusMessageIter entry;
273 fprintf(stderr, "Error: %s\n", error);
277 dbus_message_iter_recurse(iter, &entry);
278 __connmanctl_dbus_print(&entry, " ", " = ", "\n");
279 fprintf(stdout, "\n");
284 static int cmd_state(char *args[], int num, struct connman_option *options)
289 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
290 CONNMAN_PATH, "net.connman.Manager", "GetProperties",
291 state_print, NULL, NULL, NULL);
294 static int clock_print(DBusMessageIter *iter, int errnum, const char *error,
297 DBusMessageIter entry;
300 fprintf(stderr, "Error: %s\n", error);
304 dbus_message_iter_recurse(iter, &entry);
305 __connmanctl_dbus_print(&entry, " ", " = ", "\n");
306 fprintf(stdout, "\n");
311 static int cmd_clock(char *args[], int num, struct connman_option *options)
316 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
317 CONNMAN_PATH, "net.connman.Clock", "GetProperties",
318 clock_print, NULL, NULL, NULL);
321 static int services_list(DBusMessageIter *iter, int errnum, const char *error,
325 __connmanctl_services_list(iter);
326 fprintf(stdout, "\n");
328 fprintf(stderr, "Error: %s\n", error);
334 #if defined TIZEN_EXT_INS
335 static int ins_list(DBusMessageIter *iter, const char *error,
338 char *filter = user_data;
341 __connmanctl_ins_list(iter, filter);
342 fprintf(stdout, "\n");
344 fprintf(stderr, "Error: %s\n", error);
353 static int peers_list(DBusMessageIter *iter, int errnum,
354 const char *error, void *user_data)
357 __connmanctl_peers_list(iter);
358 fprintf(stdout, "\n");
360 fprintf(stderr, "Error: %s\n", error);
365 static int tethering_clients_list(DBusMessageIter *iter, int errnum,
366 const char *error, void *user_data)
369 __connmanctl_tethering_clients_list(iter);
370 fprintf(stdout, "\n");
372 fprintf(stderr, "Error: %s\n", error);
377 static int object_properties(DBusMessageIter *iter, int errnum,
378 const char *error, void *user_data)
380 char *path = user_data;
382 DBusMessageIter dict;
385 fprintf(stdout, "%s\n", path);
387 dbus_message_iter_recurse(iter, &dict);
388 __connmanctl_dbus_print(&dict, " ", " = ", "\n");
390 fprintf(stdout, "\n");
393 str = strrchr(path, '/');
399 fprintf(stderr, "Error %s: %s\n", str, error);
407 static int cmd_services(char *args[], int num, struct connman_option *options)
409 char *service_name = NULL;
416 c = parse_args(args[1], options);
423 service_name = args[2];
428 service_name = args[1];
433 return __connmanctl_dbus_method_call(connection,
434 CONNMAN_SERVICE, CONNMAN_PATH,
435 "net.connman.Manager", "GetServices",
436 services_list, NULL, NULL, NULL);
439 if (check_dbus_name(service_name) == false)
442 path = g_strdup_printf("/net/connman/service/%s", service_name);
443 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, path,
444 "net.connman.Service", "GetProperties",
445 object_properties, path, NULL, NULL);
448 #if defined TIZEN_EXT_INS
449 static int cmd_ins(char *args[], int num, struct connman_option *options)
457 filter = g_strdup(args[1]);
459 return __connmanctl_dbus_method_call(connection,
460 CONNMAN_SERVICE, CONNMAN_PATH,
461 "net.connman.Manager", "GetINS",
462 ins_list, filter, NULL, NULL);
466 static int cmd_peers(char *args[], int num, struct connman_option *options)
468 char *peer_name = NULL;
478 return __connmanctl_dbus_method_call(connection,
479 CONNMAN_SERVICE, CONNMAN_PATH,
480 "net.connman.Manager", "GetPeers",
481 peers_list, NULL, NULL, NULL);
484 if (check_dbus_name(peer_name) == false)
487 path = g_strdup_printf("/net/connman/peer/%s", peer_name);
488 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
489 path, "net.connman.Peer", "GetProperties",
490 object_properties, path, NULL, NULL);
493 static int technology_print(DBusMessageIter *iter, int errnum, const char *error,
496 DBusMessageIter array;
499 fprintf(stderr, "Error: %s\n", error);
503 dbus_message_iter_recurse(iter, &array);
504 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
505 DBusMessageIter entry, dict;
508 dbus_message_iter_recurse(&array, &entry);
509 dbus_message_iter_get_basic(&entry, &path);
510 fprintf(stdout, "%s\n", path);
512 dbus_message_iter_next(&entry);
514 dbus_message_iter_recurse(&entry, &dict);
515 __connmanctl_dbus_print(&dict, " ", " = ", "\n");
516 fprintf(stdout, "\n");
518 dbus_message_iter_next(&array);
524 static int cmd_technologies(char *args[], int num,
525 struct connman_option *options)
530 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
531 CONNMAN_PATH, "net.connman.Manager", "GetTechnologies",
532 technology_print, NULL, NULL, NULL);
535 struct tether_enable {
540 static int tether_set_return(DBusMessageIter *iter, int errnum,
541 const char *error, void *user_data)
543 struct tether_enable *tether = user_data;
546 str = strrchr(tether->path, '/');
553 fprintf(stdout, "%s tethering for %s\n",
554 tether->enable ? "Enabled" : "Disabled",
557 fprintf(stderr, "Error %s %s tethering: %s\n",
559 "enabling" : "disabling", str, error);
561 g_free(tether->path);
567 static int tether_set(char *technology, int set_tethering)
569 struct tether_enable *tether = g_new(struct tether_enable, 1);
571 switch(set_tethering) {
573 tether->enable = TRUE;
576 tether->enable = FALSE;
583 tether->path = g_strdup_printf("/net/connman/technology/%s",
586 return __connmanctl_dbus_set_property(connection, tether->path,
587 "net.connman.Technology", tether_set_return,
588 tether, "Tethering", DBUS_TYPE_BOOLEAN,
592 struct tether_properties {
594 int passphrase_result;
598 static int tether_update(struct tether_properties *tether)
602 if (tether->ssid_result == 0 && tether->passphrase_result == 0) {
603 ret = tether_set("wifi", tether->set_tethering);
608 if (tether->ssid_result != -EINPROGRESS &&
609 tether->passphrase_result != -EINPROGRESS) {
617 static int tether_set_ssid_return(DBusMessageIter *iter, int errnum,
618 const char *error, void *user_data)
620 struct tether_properties *tether = user_data;
623 fprintf(stdout, "Wifi SSID set\n");
624 tether->ssid_result = 0;
626 fprintf(stderr, "Error setting wifi SSID: %s\n", error);
627 tether->ssid_result = -EINVAL;
630 return tether_update(tether);
633 static int tether_set_passphrase_return(DBusMessageIter *iter, int errnum,
634 const char *error, void *user_data)
636 struct tether_properties *tether = user_data;
639 fprintf(stdout, "Wifi passphrase set\n");
640 tether->passphrase_result = 0;
642 fprintf(stderr, "Error setting wifi passphrase: %s\n", error);
643 tether->passphrase_result = -EINVAL;
646 return tether_update(tether);
649 static int tether_set_ssid(char *ssid, char *passphrase, int set_tethering)
651 struct tether_properties *tether = g_new(struct tether_properties, 1);
653 tether->set_tethering = set_tethering;
655 tether->ssid_result = __connmanctl_dbus_set_property(connection,
656 "/net/connman/technology/wifi",
657 "net.connman.Technology",
658 tether_set_ssid_return, tether,
659 "TetheringIdentifier", DBUS_TYPE_STRING, &ssid);
661 tether->passphrase_result =__connmanctl_dbus_set_property(connection,
662 "/net/connman/technology/wifi",
663 "net.connman.Technology",
664 tether_set_passphrase_return, tether,
665 "TetheringPassphrase", DBUS_TYPE_STRING, &passphrase);
667 if (tether->ssid_result != -EINPROGRESS &&
668 tether->passphrase_result != -EINPROGRESS) {
676 #if defined TIZEN_EXT_WIFI_MESH
677 struct mesh_if_prop {
683 struct mesh_create_network {
689 struct mesh_specific_scan_params {
694 struct mesh_gate_params {
700 static int mesh_return(DBusMessageIter *iter, const char *error,
703 char *method = user_data;
706 fprintf(stderr, "Error %s: %s\n", method, error);
708 fprintf(stderr, "Success %s\n", method);
715 static void mesh_interface_add_append(DBusMessageIter *iter, void *user_data)
717 struct mesh_if_prop *append = user_data;
719 /* Append Virtual Interface Name */
720 __connmanctl_dbus_append_dict_entry(iter, "Ifname",
721 DBUS_TYPE_STRING, &append->ifname);
723 /* Append Parent WiFi Interface Name */
724 __connmanctl_dbus_append_dict_entry(iter, "ParentIfname",
725 DBUS_TYPE_STRING, &append->parent_ifname);
727 /* Append Bridge Interface Name */
728 if (append->bridge_ifname)
729 __connmanctl_dbus_append_dict_entry(iter, "BridgeIfname",
730 DBUS_TYPE_STRING, &append->bridge_ifname);
733 static void mesh_interface_remove_append(DBusMessageIter *iter, void *user_data)
735 struct mesh_if_prop *append = user_data;
737 /* Append Virtual Interface Name */
738 __connmanctl_dbus_append_dict_entry(iter, "Ifname",
739 DBUS_TYPE_STRING, &append->ifname);
742 static void mesh_create_network_append(DBusMessageIter *iter, void *user_data)
744 struct mesh_create_network *append = user_data;
746 /* Append Mesh Network Name */
747 __connmanctl_dbus_append_dict_entry(iter, "Name",
748 DBUS_TYPE_STRING, &append->name);
750 /* Append Mesh Network Frequency */
751 __connmanctl_dbus_append_dict_entry(iter, "Frequency",
752 DBUS_TYPE_UINT16, &append->freq);
754 /* Append Mesh Network Security Type */
755 __connmanctl_dbus_append_dict_entry(iter, "Security",
756 DBUS_TYPE_STRING, &append->sec_type);
759 static void mesh_specific_scan_append(DBusMessageIter *iter, void *user_data)
761 struct mesh_specific_scan_params *append = user_data;
763 /* Append Mesh Network Name */
764 __connmanctl_dbus_append_dict_entry(iter, "Name",
765 DBUS_TYPE_STRING, &append->name);
767 /* Append Mesh Network Frequency */
768 __connmanctl_dbus_append_dict_entry(iter, "Frequency",
769 DBUS_TYPE_UINT16, &append->freq);
772 static void mesh_set_gate_append(DBusMessageIter *iter, void *user_data)
774 struct mesh_gate_params *append = user_data;
776 /* Append Gate Announce Protocol */
777 __connmanctl_dbus_append_dict_entry(iter, "GateAnnounce",
778 DBUS_TYPE_BOOLEAN, &append->gate_announce);
780 /* Append HWMP Root Mode */
781 __connmanctl_dbus_append_dict_entry(iter, "HWMPRootMode",
782 DBUS_TYPE_UINT16, &append->hwmp_rootmode);
785 __connmanctl_dbus_append_dict_entry(iter, "STP", DBUS_TYPE_UINT16,
789 static void mesh_peer_append(DBusMessageIter *iter, void *user_data)
791 char *peer_addr = user_data;
793 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &peer_addr);
798 static int mesh_peers_list(DBusMessageIter *iter,
799 const char *error, void *user_data)
802 __connmanctl_mesh_peers_list(iter);
803 fprintf(stdout, "\n");
805 fprintf(stderr, "Error: %s\n", error);
810 static int connected_mesh_peers_list(DBusMessageIter *iter,
811 const char *error, void *user_data)
814 __connmanctl_mesh_connected_peers_list(iter);
815 fprintf(stdout, "\n");
817 fprintf(stderr, "Error: %s\n", error);
822 static int disconnected_mesh_peers_list(DBusMessageIter *iter,
823 const char *error, void *user_data)
826 __connmanctl_mesh_disconnected_peers_list(iter);
827 fprintf(stdout, "\n");
829 fprintf(stderr, "Error: %s\n", error);
834 static int mesh_connect_return(DBusMessageIter *iter, const char *error,
837 char *path = user_data;
840 char *str = strrchr(path, '/');
842 fprintf(stdout, "Connected %s\n", str);
844 fprintf(stderr, "Error %s: %s\n", path, error);
851 static int mesh_disconnect_return(DBusMessageIter *iter, const char *error,
854 char *path = user_data;
857 char *str = strrchr(path, '/');
859 fprintf(stdout, "Disconnected %s\n", str);
861 fprintf(stderr, "Error %s: %s\n", path, error);
868 static int mesh_remove_return(DBusMessageIter *iter, const char *error,
871 char *path = user_data;
874 char *str = strrchr(path, '/');
876 fprintf(stdout, "Removed %s\n", str);
878 fprintf(stderr, "Error %s: %s\n", path, error);
885 static int mesh_config_return(DBusMessageIter *iter, const char *error,
888 char *path = user_data;
889 char *str = strrchr(path, '/');
893 fprintf(stderr, "Error %s: %s\n", path, error);
895 fprintf(stdout, "Success SetProperty %s\n", str);
902 static int cmd_mesh(char *args[], int num, struct connman_option *options)
908 char *mesh_peer_name = NULL;
909 char *mesh_peer_path = NULL;
910 char *property = NULL;
912 struct mesh_if_prop *append;
913 struct mesh_create_network *network;
914 struct mesh_specific_scan_params *scan_params;
915 struct mesh_gate_params *gate_params;
916 char *mesh_peer_addr = NULL;
918 c = parse_args(args[1], options);
922 if (num < 4 || num > 5) {
926 path = g_strdup_printf("/net/connman/technology/mesh");
928 append = dbus_malloc0(sizeof(struct mesh_if_prop));
929 append->ifname = g_strdup(args[2]);
930 append->parent_ifname = g_strdup(args[3]);
932 append->bridge_ifname = g_strdup(args[4]);
933 method = g_strdup("MeshInterfaceAdd");
934 result = __connmanctl_dbus_mesh_dict(connection, path,
935 "net.connman.Technology", mesh_return, method,
936 "MeshInterfaceAdd", DBUS_TYPE_STRING,
937 mesh_interface_add_append, append);
938 g_free(append->ifname);
939 g_free(append->parent_ifname);
940 g_free(append->bridge_ifname);
949 path = g_strdup_printf("/net/connman/technology/mesh");
951 append = dbus_malloc0(sizeof(struct mesh_if_prop));
952 append->ifname = g_strdup(args[2]);
953 method = g_strdup("MeshInterfaceRemove");
954 result = __connmanctl_dbus_mesh_dict(connection, path,
955 "net.connman.Technology", mesh_return, method,
956 "MeshInterfaceRemove", DBUS_TYPE_STRING,
957 mesh_interface_remove_append, append);
958 g_free(append->ifname);
969 mesh_peer_name = args[2];
971 if (!mesh_peer_name) {
972 result = __connmanctl_dbus_method_call(connection,
973 CONNMAN_SERVICE, CONNMAN_PATH,
974 "net.connman.Manager", "GetMeshPeers",
975 mesh_peers_list, NULL, NULL, NULL);
979 if (check_dbus_name(mesh_peer_name) == false) {
984 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
986 result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
987 mesh_peer_path, "net.connman.Mesh", "GetProperties",
988 object_properties, mesh_peer_path, NULL, NULL);
1002 mesh_peer_name = args[2];
1004 if (check_dbus_name(mesh_peer_name) == false) {
1009 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1011 result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1012 mesh_peer_path, "net.connman.Mesh", "Connect",
1013 mesh_connect_return, mesh_peer_path, NULL, NULL);
1027 mesh_peer_name = args[2];
1029 if (check_dbus_name(mesh_peer_name) == false) {
1034 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1036 result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1037 mesh_peer_path, "net.connman.Mesh", "Disconnect",
1038 mesh_disconnect_return, mesh_peer_path, NULL, NULL);
1052 mesh_peer_name = args[2];
1054 if (check_dbus_name(mesh_peer_name) == false) {
1059 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1061 result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1062 mesh_peer_path, "net.connman.Mesh", "Remove",
1063 mesh_remove_return, mesh_peer_path, NULL, NULL);
1072 result = __connmanctl_dbus_method_call(connection,
1073 CONNMAN_SERVICE, CONNMAN_PATH,
1074 "net.connman.Manager", "GetConnectedMeshPeers",
1075 connected_mesh_peers_list, NULL, NULL, NULL);
1084 result = __connmanctl_dbus_method_call(connection,
1085 CONNMAN_SERVICE, CONNMAN_PATH,
1086 "net.connman.Manager",
1087 "GetDisconnectedMeshPeers",
1088 disconnected_mesh_peers_list, NULL, NULL, NULL);
1096 path = g_strdup_printf("/net/connman/technology/mesh");
1098 network = dbus_malloc0(sizeof(struct mesh_create_network));
1099 network->name = g_strdup(args[2]);
1100 network->freq = atoi(args[3]);
1101 network->sec_type = g_strdup(args[4]);
1102 method = g_strdup("MeshCreateNetwork");
1103 result = __connmanctl_dbus_mesh_dict(connection, path,
1104 "net.connman.Technology", mesh_return, method,
1105 "MeshCreateNetwork", DBUS_TYPE_STRING,
1106 mesh_create_network_append, network);
1107 g_free(network->name);
1108 g_free(network->sec_type);
1117 path = g_strdup_printf("/net/connman/technology/mesh");
1119 method = g_strdup("AbortScan");
1120 result = __connmanctl_dbus_mesh_dict(connection, path,
1121 "net.connman.Technology", mesh_return, method,
1122 "AbortScan", DBUS_TYPE_STRING,
1131 path = g_strdup_printf("/net/connman/technology/mesh");
1133 scan_params = dbus_malloc0(sizeof(struct mesh_specific_scan_params));
1134 scan_params->name = g_strdup(args[2]);
1135 scan_params->freq = atoi(args[3]);
1136 method = g_strdup("MeshSpecificScan");
1137 result = __connmanctl_dbus_mesh_dict(connection, path,
1138 "net.connman.Technology", mesh_return, method,
1139 "MeshSpecificScan", DBUS_TYPE_STRING,
1140 mesh_specific_scan_append, scan_params);
1141 g_free(scan_params->name);
1142 g_free(scan_params);
1151 mesh_peer_name = args[2];
1155 if (check_dbus_name(mesh_peer_name) == false) {
1160 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1163 if (g_strcmp0(property, "Passphrase") == 0) {
1164 result = __connmanctl_dbus_set_property(connection,
1165 mesh_peer_path, "net.connman.Mesh",
1166 mesh_config_return, mesh_peer_path, property,
1167 DBUS_TYPE_STRING, &value);
1169 printf("Invalid property %s\n", property);
1181 path = g_strdup_printf("/net/connman/technology/mesh");
1183 gate_params = dbus_malloc0(sizeof(struct mesh_gate_params));
1184 gate_params->gate_announce = atoi(args[2]);
1185 gate_params->hwmp_rootmode = atoi(args[3]);
1186 gate_params->stp = atoi(args[4]);
1188 method = g_strdup("SetMeshGate");
1190 result = __connmanctl_dbus_mesh_dict(connection, path,
1191 "net.connman.Technology", mesh_return, method,
1192 "SetMeshGate", DBUS_TYPE_STRING,
1193 mesh_set_gate_append, gate_params);
1203 mesh_peer_addr = g_strdup(args[2]);
1204 method = g_strdup("MeshAddPeer");
1206 result = __connmanctl_dbus_method_call(connection,
1207 CONNMAN_SERVICE, CONNMAN_PATH,
1208 "net.connman.Manager", "MeshAddPeer",
1209 mesh_return, method, mesh_peer_append,
1220 mesh_peer_addr = g_strdup(args[2]);
1221 method = g_strdup("MeshRemovePeer");
1223 result = __connmanctl_dbus_method_call(connection,
1224 CONNMAN_SERVICE, CONNMAN_PATH,
1225 "net.connman.Manager", "MeshRemovePeer",
1226 mesh_return, method, mesh_peer_append,
1239 if (result != -EINPROGRESS)
1240 printf("Error '%s': %s\n", args[1], strerror(-result));
1248 static int cmd_tether(char *args[], int num, struct connman_option *options)
1250 char *ssid, *passphrase;
1256 passphrase = args[num - 1];
1257 ssid = args[num - 2];
1259 set_tethering = parse_boolean(args[2]);
1261 if (strcmp(args[1], "wifi") == 0) {
1266 if (num == 5 && set_tethering == -1)
1273 return tether_set_ssid(ssid, passphrase, set_tethering);
1279 if (set_tethering == -1)
1282 if (check_dbus_name(args[1]) == false)
1285 return tether_set(args[1], set_tethering);
1288 static int cmd_tethering_clients(char *args[], int num, struct connman_option *options)
1293 return __connmanctl_dbus_method_call(connection,
1294 CONNMAN_SERVICE, CONNMAN_PATH,
1295 "net.connman.Manager", "GetTetheringClients",
1296 tethering_clients_list, NULL, NULL, NULL);
1299 static int scan_return(DBusMessageIter *iter, int ernnum, const char *error,
1302 char *path = user_data;
1305 char *str = strrchr(path, '/');
1307 fprintf(stdout, "Scan completed for %s\n", str);
1309 fprintf(stderr, "Error %s: %s\n", path, error);
1316 static int cmd_scan(char *args[], int num, struct connman_option *options)
1326 if (check_dbus_name(args[1]) == false)
1329 path = g_strdup_printf("/net/connman/technology/%s", args[1]);
1330 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, path,
1331 "net.connman.Technology", "Scan",
1332 scan_return, path, NULL, NULL);
1335 static int connect_return(DBusMessageIter *iter, int errnum,
1336 const char *error, void *user_data)
1338 char *path = user_data;
1341 char *str = strrchr(path, '/');
1343 fprintf(stdout, "Connected %s\n", str);
1345 fprintf(stderr, "Error %s: %s\n", path, error);
1352 static int cmd_connect(char *args[], int num, struct connman_option *options)
1354 const char *iface = "net.connman.Service";
1363 if (check_dbus_name(args[1]) == false)
1366 if (g_strstr_len(args[1], 5, "peer_") == args[1]) {
1367 iface = "net.connman.Peer";
1368 path = g_strdup_printf("/net/connman/peer/%s", args[1]);
1370 path = g_strdup_printf("/net/connman/service/%s", args[1]);
1372 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, path,
1373 iface, "Connect", connect_return, path, NULL, NULL);
1376 static int disconnect_return(DBusMessageIter *iter, int errnum,
1377 const char *error, void *user_data)
1379 char *path = user_data;
1382 char *str = strrchr(path, '/');
1384 fprintf(stdout, "Disconnected %s\n", str);
1386 fprintf(stderr, "Error %s: %s\n", path, error);
1393 static int cmd_disconnect(char *args[], int num, struct connman_option *options)
1395 const char *iface = "net.connman.Service";
1404 if (check_dbus_name(args[1]) == false)
1407 if (g_strstr_len(args[1], 5, "peer_") == args[1]) {
1408 iface = "net.connman.Peer";
1409 path = g_strdup_printf("/net/connman/peer/%s", args[1]);
1411 path = g_strdup_printf("/net/connman/service/%s", args[1]);
1413 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1414 path, iface, "Disconnect",
1415 disconnect_return, path, NULL, NULL);
1418 struct move_service {
1423 static int move_before_return(DBusMessageIter *iter, int errnum,
1424 const char *error, void *user_data)
1426 struct move_service *services = user_data;
1431 service = strrchr(services->service, '/');
1433 target = strrchr(services->target, '/');
1435 fprintf(stdout, "Moved %s before %s\n", service, target);
1437 fprintf(stderr, "Error %s: %s\n", services->service, error);
1439 g_free(services->service);
1440 g_free(services->target);
1446 static void move_before_append_args(DBusMessageIter *iter, void *user_data)
1448 char *path = user_data;
1450 dbus_message_iter_append_basic(iter,
1451 DBUS_TYPE_OBJECT_PATH, &path);
1454 static int cmd_service_move_before(char *args[], int num,
1455 struct connman_option *options)
1457 const char *iface = "net.connman.Service";
1458 struct move_service *services;
1466 if (check_dbus_name(args[1]) == false)
1469 services = g_new(struct move_service, 1);
1471 services->service = g_strdup_printf("/net/connman/service/%s", args[1]);
1472 services->target = g_strdup_printf("/net/connman/service/%s", args[2]);
1474 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1475 services->service, iface, "MoveBefore",
1476 move_before_return, services,
1477 move_before_append_args,
1481 static int move_after_return(DBusMessageIter *iter, int errnum,
1482 const char *error, void *user_data)
1484 struct move_service *services = user_data;
1489 service = strrchr(services->service, '/');
1491 target = strrchr(services->target, '/');
1493 fprintf(stdout, "Moved %s after %s\n", service, target);
1495 fprintf(stderr, "Error %s: %s\n", services->service, error);
1497 g_free(services->service);
1498 g_free(services->target);
1504 static void move_after_append_args(DBusMessageIter *iter, void *user_data)
1506 char *path = user_data;
1508 dbus_message_iter_append_basic(iter,
1509 DBUS_TYPE_OBJECT_PATH, &path);
1512 static int cmd_service_move_after(char *args[], int num,
1513 struct connman_option *options)
1515 const char *iface = "net.connman.Service";
1516 struct move_service *services;
1524 if (check_dbus_name(args[1]) == false)
1527 services = g_new(struct move_service, 1);
1529 services->service = g_strdup_printf("/net/connman/service/%s", args[1]);
1530 services->target = g_strdup_printf("/net/connman/service/%s", args[2]);
1532 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1533 services->service, iface, "MoveAfter",
1534 move_after_return, services,
1535 move_after_append_args,
1539 static int config_return(DBusMessageIter *iter, int errnum,
1540 const char *error, void *user_data)
1542 char *service_name = user_data;
1545 fprintf(stderr, "Error %s: %s\n", service_name, error);
1552 struct config_append {
1557 struct session_options {
1561 struct connman_option *options;
1564 static void config_append_ipv4(DBusMessageIter *iter,
1567 struct config_append *append = user_data;
1568 char **opts = append->opts;
1574 while (opts[i] && ipv4[i]) {
1575 __connmanctl_dbus_append_dict_entry(iter, ipv4[i],
1576 DBUS_TYPE_STRING, &opts[i]);
1583 static void config_append_ipv6(DBusMessageIter *iter, void *user_data)
1585 struct config_append *append = user_data;
1586 char **opts = append->opts;
1593 if (g_strcmp0(opts[0], "auto") == 0) {
1596 switch (parse_boolean(opts[1])) {
1601 __connmanctl_dbus_append_dict_entry(iter, "Privacy",
1602 DBUS_TYPE_STRING, &str);
1609 __connmanctl_dbus_append_dict_entry(iter, "Privacy",
1610 DBUS_TYPE_STRING, &str);
1617 if (g_strcmp0(opts[1], "prefered") != 0 &&
1619 "preferred") != 0) {
1620 fprintf(stderr, "Error %s: %s\n",
1627 __connmanctl_dbus_append_dict_entry(iter,
1628 "Privacy", DBUS_TYPE_STRING,
1633 } else if (g_strcmp0(opts[0], "manual") == 0) {
1636 while (opts[i] && ipv6[i]) {
1638 int value = atoi(opts[i]);
1639 __connmanctl_dbus_append_dict_entry(iter,
1640 ipv6[i], DBUS_TYPE_BYTE,
1643 __connmanctl_dbus_append_dict_entry(iter,
1644 ipv6[i], DBUS_TYPE_STRING,
1652 } else if (g_strcmp0(opts[0], "off") != 0) {
1653 fprintf(stderr, "Error %s: %s\n", opts[0], strerror(EINVAL));
1658 __connmanctl_dbus_append_dict_entry(iter, "Method", DBUS_TYPE_STRING,
1662 static void config_append_str(DBusMessageIter *iter, void *user_data)
1664 struct config_append *append = user_data;
1665 char **opts = append->opts;
1672 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
1680 static void append_servers(DBusMessageIter *iter, void *user_data)
1682 struct config_append *append = user_data;
1683 char **opts = append->opts;
1689 while (opts[i] && g_strcmp0(opts[i], "--excludes") != 0) {
1690 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
1698 static void append_excludes(DBusMessageIter *iter, void *user_data)
1700 struct config_append *append = user_data;
1701 char **opts = append->opts;
1702 int i = append->values;
1704 if (!opts || !opts[i] ||
1705 g_strcmp0(opts[i], "--excludes") != 0)
1710 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
1718 static void config_append_proxy(DBusMessageIter *iter, void *user_data)
1720 struct config_append *append = user_data;
1721 char **opts = append->opts;
1726 if (g_strcmp0(opts[0], "manual") == 0) {
1727 __connmanctl_dbus_append_dict_string_array(iter, "Servers",
1728 append_servers, append);
1730 __connmanctl_dbus_append_dict_string_array(iter, "Excludes",
1731 append_excludes, append);
1733 } else if (g_strcmp0(opts[0], "auto") == 0) {
1735 __connmanctl_dbus_append_dict_entry(iter, "URL",
1736 DBUS_TYPE_STRING, &opts[1]);
1740 } else if (g_strcmp0(opts[0], "direct") != 0)
1743 __connmanctl_dbus_append_dict_entry(iter, "Method",DBUS_TYPE_STRING,
1749 static int cmd_config(char *args[], int num, struct connman_option *options)
1751 int result = 0, res = 0, index = 2, oldindex = 0;
1753 char *service_name, *path;
1756 struct config_append append;
1758 service_name = args[1];
1762 if (check_dbus_name(service_name) == false)
1765 while (index < num && args[index]) {
1766 c = parse_args(args[index], options);
1767 opt_start = &args[index + 1];
1768 append.opts = opt_start;
1774 path = g_strdup_printf("/net/connman/service/%s", service_name);
1778 switch (parse_boolean(*opt_start)) {
1793 res = __connmanctl_dbus_set_property(connection,
1794 path, "net.connman.Service",
1796 g_strdup(service_name),
1798 DBUS_TYPE_BOOLEAN, &val);
1802 res = __connmanctl_dbus_set_property_dict(connection,
1803 path, "net.connman.Service",
1804 config_return, g_strdup(service_name),
1805 "IPv4.Configuration", DBUS_TYPE_STRING,
1806 config_append_ipv4, &append);
1807 index += append.values;
1811 res = __connmanctl_dbus_set_property_dict(connection,
1812 path, "net.connman.Service",
1813 config_return, g_strdup(service_name),
1814 "IPv6.Configuration", DBUS_TYPE_STRING,
1815 config_append_ipv6, &append);
1816 index += append.values;
1820 res = __connmanctl_dbus_set_property_array(connection,
1821 path, "net.connman.Service",
1822 config_return, g_strdup(service_name),
1823 "Nameservers.Configuration",
1824 DBUS_TYPE_STRING, config_append_str,
1826 index += append.values;
1830 res = __connmanctl_dbus_set_property_array(connection,
1831 path, "net.connman.Service",
1832 config_return, g_strdup(service_name),
1833 "Timeservers.Configuration",
1834 DBUS_TYPE_STRING, config_append_str,
1836 index += append.values;
1840 res = __connmanctl_dbus_set_property_array(connection,
1841 path, "net.connman.Service",
1842 config_return, g_strdup(service_name),
1843 "Domains.Configuration",
1844 DBUS_TYPE_STRING, config_append_str,
1846 index += append.values;
1850 res = __connmanctl_dbus_set_property_dict(connection,
1851 path, "net.connman.Service",
1852 config_return, g_strdup(service_name),
1853 "Proxy.Configuration",
1854 DBUS_TYPE_STRING, config_append_proxy,
1856 index += append.values;
1859 res = __connmanctl_dbus_method_call(connection,
1860 CONNMAN_SERVICE, path,
1861 "net.connman.Service", "Remove",
1862 config_return, g_strdup(service_name),
1867 switch (parse_boolean(*opt_start)) {
1879 res = __connmanctl_dbus_set_property(connection,
1880 path, "net.connman.Service",
1882 g_strdup(service_name),
1883 "mDNS.Configuration",
1884 DBUS_TYPE_BOOLEAN, &val);
1897 if (res == -EINPROGRESS)
1898 result = -EINPROGRESS;
1900 printf("Error '%s': %s\n", args[oldindex],
1911 static DBusHandlerResult monitor_changed(DBusConnection *connection,
1912 DBusMessage *message, void *user_data)
1914 DBusMessageIter iter;
1915 const char *interface, *path;
1917 interface = dbus_message_get_interface(message);
1919 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1921 if (strncmp(interface, "net.connman.", 12) != 0)
1922 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1924 if (!strcmp(interface, "net.connman.Agent") ||
1925 !strcmp(interface, "net.connman.vpn.Agent") ||
1926 !strcmp(interface, "net.connman.Session") ||
1927 !strcmp(interface, "net.connman.Notification"))
1928 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1930 interface = strrchr(interface, '.');
1931 if (interface && *interface != '\0')
1934 path = strrchr(dbus_message_get_path(message), '/');
1935 if (path && *path != '\0')
1938 __connmanctl_save_rl();
1940 if (dbus_message_is_signal(message, "net.connman.Manager",
1941 "ServicesChanged")) {
1943 fprintf(stdout, "%-12s %-20s = {\n", interface,
1945 dbus_message_iter_init(message, &iter);
1946 __connmanctl_services_list(&iter);
1947 fprintf(stdout, "\n}\n");
1949 __connmanctl_redraw_rl();
1951 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1952 } else if (dbus_message_is_signal(message, "net.connman.Manager",
1954 fprintf(stdout, "%-12s %-20s = {\n", interface,
1956 dbus_message_iter_init(message, &iter);
1957 __connmanctl_peers_list(&iter);
1958 fprintf(stdout, "\n}\n");
1960 __connmanctl_redraw_rl();
1962 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1963 } else if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
1964 "ConnectionAdded") ||
1965 dbus_message_is_signal(message,
1966 "net.connman.vpn.Manager",
1967 "ConnectionRemoved")) {
1968 interface = "vpn.Manager";
1969 path = dbus_message_get_member(message);
1971 } else if (dbus_message_is_signal(message, "net.connman.Manager",
1972 "TechnologyAdded") ||
1973 dbus_message_is_signal(message, "net.connman.Manager",
1974 "TechnologyRemoved"))
1975 path = dbus_message_get_member(message);
1977 fprintf(stdout, "%-12s %-20s ", interface, path);
1978 dbus_message_iter_init(message, &iter);
1980 __connmanctl_dbus_print(&iter, "", " = ", " = ");
1981 fprintf(stdout, "\n");
1983 __connmanctl_redraw_rl();
1985 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1992 { "Service", false },
1993 { "Technology", false },
1994 { "Manager", false },
1995 { "vpn.Manager", false },
1996 { "vpn.Connection", false },
2000 static void monitor_add(char *interface)
2002 bool add_filter = true, found = false;
2007 for (i = 0; monitor[i].interface; i++) {
2008 if (monitor[i].enabled == true)
2011 if (g_strcmp0(interface, monitor[i].interface) == 0) {
2012 if (monitor[i].enabled == true)
2015 monitor[i].enabled = true;
2023 if (add_filter == true)
2024 dbus_connection_add_filter(connection, monitor_changed,
2027 dbus_error_init(&err);
2028 rule = g_strdup_printf("type='signal',interface='net.connman.%s'",
2030 dbus_bus_add_match(connection, rule, &err);
2033 if (dbus_error_is_set(&err))
2034 fprintf(stderr, "Error: %s\n", err.message);
2037 static void monitor_del(char *interface)
2039 bool del_filter = true, found = false;
2044 for (i = 0; monitor[i].interface; i++) {
2045 if (g_strcmp0(interface, monitor[i].interface) == 0) {
2046 if (monitor[i].enabled == false)
2049 monitor[i].enabled = false;
2053 if (monitor[i].enabled == true)
2060 rule = g_strdup_printf("type='signal',interface='net.connman.%s'",
2062 dbus_bus_remove_match(connection, rule, NULL);
2065 if (del_filter == true)
2066 dbus_connection_remove_filter(connection, monitor_changed,
2070 static int cmd_monitor(char *args[], int num, struct connman_option *options)
2079 switch (parse_boolean(args[2])) {
2089 c = parse_args(args[1], options);
2092 monitor_add("Service");
2093 monitor_add("Technology");
2094 monitor_add("Manager");
2095 monitor_add("vpn.Manager");
2096 monitor_add("vpn.Connection");
2101 monitor_add("Service");
2103 monitor_del("Service");
2108 monitor_add("Technology");
2110 monitor_del("Technology");
2115 monitor_add("Manager");
2117 monitor_del("Manager");
2122 monitor_add("vpn.Manager");
2124 monitor_del("vpn.Manager");
2129 monitor_add("vpn.Connection");
2131 monitor_del("vpn.Connection");
2135 switch(parse_boolean(args[1])) {
2137 monitor_del("Service");
2138 monitor_del("Technology");
2139 monitor_del("Manager");
2140 monitor_del("vpn.Manager");
2141 monitor_del("vpn.Connection");
2145 monitor_add("Service");
2146 monitor_add("Technology");
2147 monitor_add("Manager");
2148 monitor_add("vpn.Manager");
2149 monitor_add("vpn.Connection");
2158 return -EINPROGRESS;
2163 static int cmd_agent(char *args[], int num, struct connman_option *options)
2165 if (!__connmanctl_is_interactive()) {
2166 fprintf(stderr, "Error: Not supported in non-interactive "
2177 switch(parse_boolean(args[1])) {
2179 __connmanctl_agent_unregister(connection);
2183 if (__connmanctl_agent_register(connection) == -EINPROGRESS)
2184 return -EINPROGRESS;
2196 static int vpnconnections_properties(DBusMessageIter *iter, int errnum,
2197 const char *error, void *user_data)
2199 char *path = user_data;
2201 DBusMessageIter dict;
2204 fprintf(stdout, "%s\n", path);
2206 dbus_message_iter_recurse(iter, &dict);
2207 __connmanctl_dbus_print(&dict, " ", " = ", "\n");
2209 fprintf(stdout, "\n");
2212 str = strrchr(path, '/');
2218 fprintf(stderr, "Error %s: %s\n", str, error);
2226 static int vpnconnections_list(DBusMessageIter *iter, int errnum,
2227 const char *error, void *user_data)
2230 __connmanctl_vpnconnections_list(iter);
2232 fprintf(stderr, "Error: %s\n", error);
2237 static int cmd_vpnconnections(char *args[], int num,
2238 struct connman_option *options)
2240 char *vpnconnection_name, *path;
2245 vpnconnection_name = args[1];
2247 if (!vpnconnection_name)
2248 return __connmanctl_dbus_method_call(connection,
2249 VPN_SERVICE, VPN_PATH,
2250 "net.connman.vpn.Manager", "GetConnections",
2251 vpnconnections_list, NULL,
2254 if (check_dbus_name(vpnconnection_name) == false)
2257 path = g_strdup_printf("/net/connman/vpn/connection/%s",
2258 vpnconnection_name);
2259 return __connmanctl_dbus_method_call(connection, VPN_SERVICE, path,
2260 "net.connman.vpn.Connection", "GetProperties",
2261 vpnconnections_properties, path, NULL, NULL);
2265 static int cmd_vpnagent(char *args[], int num, struct connman_option *options)
2267 if (!__connmanctl_is_interactive()) {
2268 fprintf(stderr, "Error: Not supported in non-interactive "
2279 switch(parse_boolean(args[1])) {
2281 __connmanctl_vpn_agent_unregister(connection);
2285 if (__connmanctl_vpn_agent_register(connection) ==
2287 return -EINPROGRESS;
2299 static DBusMessage *session_release(DBusConnection *connection,
2300 DBusMessage *message, void *user_data)
2302 __connmanctl_save_rl();
2304 fprintf(stdout, "Session %s released\n", session_path);
2306 __connmanctl_redraw_rl();
2308 g_free(session_path);
2309 session_path = NULL;
2310 session_connected = false;
2312 return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
2315 static DBusMessage *session_update(DBusConnection *connection,
2316 DBusMessage *message, void *user_data)
2318 DBusMessageIter iter, dict;
2320 __connmanctl_save_rl();
2322 fprintf(stdout, "Session Update = {\n");
2324 dbus_message_iter_init(message, &iter);
2325 dbus_message_iter_recurse(&iter, &dict);
2327 __connmanctl_dbus_print(&dict, "", " = ", "\n");
2328 fprintf(stdout, "\n}\n");
2330 dbus_message_iter_recurse(&iter, &dict);
2332 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2333 DBusMessageIter entry, variant;
2334 char *field, *state;
2336 dbus_message_iter_recurse(&dict, &entry);
2338 dbus_message_iter_get_basic(&entry, &field);
2340 if (dbus_message_iter_get_arg_type(&entry)
2342 && !strcmp(field, "State")) {
2344 dbus_message_iter_next(&entry);
2345 dbus_message_iter_recurse(&entry, &variant);
2346 if (dbus_message_iter_get_arg_type(&variant)
2347 != DBUS_TYPE_STRING)
2350 dbus_message_iter_get_basic(&variant, &state);
2352 if (!session_connected && (!strcmp(state, "connected")
2353 || !strcmp(state, "online"))) {
2355 fprintf(stdout, "Session %s connected\n",
2357 session_connected = true;
2362 if (!strcmp(state, "disconnected") &&
2363 session_connected) {
2365 fprintf(stdout, "Session %s disconnected\n",
2367 session_connected = false;
2372 dbus_message_iter_next(&dict);
2375 __connmanctl_redraw_rl();
2377 return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
2380 static const GDBusMethodTable notification_methods[] = {
2381 { GDBUS_METHOD("Release", NULL, NULL, session_release) },
2382 { GDBUS_METHOD("Update", GDBUS_ARGS({"settings", "a{sv}"}),
2383 NULL, session_update) },
2387 static int session_notify_add(const char *path)
2389 if (session_notify_path)
2392 if (!g_dbus_register_interface(connection, path,
2393 "net.connman.Notification",
2394 notification_methods, NULL, NULL,
2396 fprintf(stderr, "Error: Failed to register VPN Agent "
2401 session_notify_path = g_strdup(path);
2406 static void session_notify_remove(void)
2408 if (!session_notify_path)
2411 g_dbus_unregister_interface(connection, session_notify_path,
2412 "net.connman.Notification");
2414 g_free(session_notify_path);
2415 session_notify_path = NULL;
2418 static int session_connect_cb(DBusMessageIter *iter, int errnum,
2419 const char *error, void *user_data)
2422 fprintf(stderr, "Error: %s\n", error);
2426 return -EINPROGRESS;
2430 static int session_connect(void)
2432 return __connmanctl_dbus_method_call(connection, "net.connman",
2433 session_path, "net.connman.Session", "Connect",
2434 session_connect_cb, NULL, NULL, NULL);
2437 static int session_disconnect_cb(DBusMessageIter *iter, int errnum,
2438 const char *error, void *user_data)
2441 fprintf(stderr, "Error: %s\n", error);
2446 static int session_disconnect(void)
2448 return __connmanctl_dbus_method_call(connection, "net.connman",
2449 session_path, "net.connman.Session", "Disconnect",
2450 session_disconnect_cb, NULL, NULL, NULL);
2453 static int session_create_cb(DBusMessageIter *iter, int errnum,
2454 const char *error, void *user_data)
2456 gboolean connect = GPOINTER_TO_INT(user_data);
2460 fprintf(stderr, "Error creating session: %s", error);
2461 session_notify_remove();
2465 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH) {
2466 fprintf(stderr, "Error creating session: No session path\n");
2470 g_free(session_path);
2472 dbus_message_iter_get_basic(iter, &str);
2473 session_path = g_strdup(str);
2475 fprintf(stdout, "Session %s created\n", session_path);
2478 return session_connect();
2480 return -EINPROGRESS;
2483 static void session_config_append_array(DBusMessageIter *iter,
2486 struct config_append *append = user_data;
2487 char **opts = append->opts;
2493 while (opts[i] && strncmp(opts[i], "--", 2) != 0) {
2494 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2502 static void session_create_append_dict(DBusMessageIter *iter, void *user_data)
2504 struct session_options *args_struct = user_data;
2505 int index = 0, res = 0;
2506 struct config_append append;
2509 dbus_bool_t source_ip_rule;
2511 while (index < args_struct->num && args_struct->args[index]) {
2512 append.opts = &args_struct->args[index];
2515 c = parse_args(args_struct->args[index], args_struct->options);
2519 __connmanctl_dbus_append_dict_string_array(iter, "AllowedBearers",
2520 session_config_append_array,
2524 if (! args_struct->args[index + 1]) {
2528 __connmanctl_dbus_append_dict_entry(iter, "ConnectionType",
2530 &args_struct->args[index + 1]);
2534 if (index + 1 < args_struct->num)
2535 ifname = args_struct->args[index + 1];
2538 __connmanctl_dbus_append_dict_entry(iter, "AllowedInterface",
2544 if (! args_struct->args[index + 1]) {
2548 switch (parse_boolean( args_struct->args[index + 1])) {
2550 source_ip_rule = TRUE;
2553 source_ip_rule = FALSE;
2559 __connmanctl_dbus_append_dict_entry(iter, "SourceIPRule",
2565 if (!args_struct->args[index + 1]) {
2569 __connmanctl_dbus_append_dict_entry(iter, "ContextIdentifier",
2571 &args_struct->args[index + 1]);
2578 if (res < 0 && res != -EINPROGRESS) {
2579 printf("Error '%s': %s\n", args_struct->args[index],
2584 index += append.values;
2588 static void session_create_append(DBusMessageIter *iter, void *user_data)
2590 struct session_options *args_struct = user_data;
2592 __connmanctl_dbus_append_dict(iter, session_create_append_dict,
2595 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
2596 &args_struct->notify_path);
2599 static int session_create(gboolean connect, char *args[], int num,
2600 struct connman_option *options)
2604 struct session_options args_struct;
2605 args_struct.args = args;
2606 args_struct.num = num;
2607 args_struct.options = options;
2609 notify_path = g_strdup_printf("/net/connman/connmanctl%d", getpid());
2610 session_notify_add(notify_path);
2611 args_struct.notify_path = notify_path;
2613 res = __connmanctl_dbus_method_call(connection, "net.connman", "/",
2614 "net.connman.Manager", "CreateSession",
2615 session_create_cb, GINT_TO_POINTER(connect),
2616 session_create_append, &args_struct);
2618 g_free(notify_path);
2620 if (res < 0 && res != -EINPROGRESS)
2621 session_notify_remove();
2626 static int session_destroy_cb(DBusMessageIter *iter, int errnum,
2627 const char *error, void *user_data)
2630 fprintf(stderr, "Error destroying session: %s", error);
2634 fprintf(stdout, "Session %s ended\n", session_path);
2636 g_free(session_path);
2637 session_path = NULL;
2638 session_connected = false;
2643 static void session_destroy_append(DBusMessageIter *iter, void *user_data)
2645 const char *path = user_data;
2647 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
2650 static int session_destroy(void)
2652 return __connmanctl_dbus_method_call(connection, "net.connman", "/",
2653 "net.connman.Manager", "DestroySession",
2654 session_destroy_cb, NULL,
2655 session_destroy_append, session_path);
2658 static int session_config_return(DBusMessageIter *iter, int errnum,
2659 const char *error, void *user_data)
2661 char *property_name = user_data;
2664 fprintf(stderr, "Error setting session %s: %s\n",
2665 property_name, error);
2670 static int session_config(char *args[], int num,
2671 struct connman_option *options)
2673 int index = 0, res = 0;
2674 struct config_append append;
2677 dbus_bool_t source_ip_rule;
2679 while (index < num && args[index]) {
2680 append.opts = &args[index];
2683 c = parse_args(args[index], options);
2687 res = __connmanctl_dbus_session_change_array(connection,
2688 session_path, session_config_return,
2689 "AllowedBearers", "AllowedBearers",
2690 session_config_append_array, &append);
2693 if (!args[index + 1]) {
2698 res = __connmanctl_dbus_session_change(connection,
2699 session_path, session_config_return,
2700 "ConnectionType", "ConnectionType",
2701 DBUS_TYPE_STRING, &args[index + 1]);
2705 if (index + 1 < num)
2706 ifname = args[index + 1];
2710 res = __connmanctl_dbus_session_change(connection,
2711 session_path, session_config_return,
2712 "AllowedInterface", "AllowedInterface",
2713 DBUS_TYPE_STRING, &ifname);
2717 if (!args[index + 1]) {
2721 switch (parse_boolean(args[index + 1])) {
2723 source_ip_rule = TRUE;
2726 source_ip_rule = FALSE;
2733 res = __connmanctl_dbus_session_change(connection,
2734 session_path, session_config_return,
2735 "SourceIPRule", "SourceIPRule",
2736 DBUS_TYPE_BOOLEAN, &source_ip_rule);
2740 if (!args[index + 1]) {
2745 res = __connmanctl_dbus_session_change(connection,
2746 session_path, session_config_return,
2747 "ctxid", "ctxid", DBUS_TYPE_STRING,
2756 if (res < 0 && res != -EINPROGRESS) {
2757 printf("Error '%s': %s\n", args[index],
2762 index += append.values;
2768 static int cmd_session(char *args[], int num, struct connman_option *options)
2777 switch(parse_boolean(command)) {
2781 return session_destroy();
2786 return session_create(FALSE, &args[2], num - 2, options);
2789 if (!strcmp(command, "connect")) {
2791 return session_create(TRUE, &args[2], num - 2,
2794 return session_connect();
2796 } else if (!strcmp(command, "disconnect")) {
2798 if (!session_path) {
2799 fprintf(stdout, "Session does not exist\n");
2803 return session_disconnect();
2804 } else if (!strcmp(command, "config")) {
2805 if (!session_path) {
2806 fprintf(stdout, "Session does not exist\n");
2813 return session_config(&args[2], num - 2, options);
2821 static int cmd_exit(char *args[], int num, struct connman_option *options)
2826 static char *lookup_key_from_table(GHashTable *hash, const char *text,
2830 static GHashTableIter iter;
2831 gpointer key, value;
2834 g_hash_table_iter_init(&iter, hash);
2838 while (g_hash_table_iter_next(&iter, &key, &value))
2839 if (strncmp(text, key, len) == 0)
2845 static char *lookup_service_arg(const char *text, int state)
2847 if (__connmanctl_input_calc_level() > 1) {
2848 __connmanctl_input_lookup_end();
2852 return lookup_key_from_table(service_hash, text, state);
2855 static char *lookup_peer(const char *text, int state)
2857 static GHashTableIter iter;
2858 gpointer key, value;
2862 g_hash_table_iter_init(&iter, peer_hash);
2866 while (g_hash_table_iter_next(&iter, &key, &value)) {
2867 const char *peer = key;
2868 if (strncmp(text, peer, len) == 0)
2869 return strdup(peer);
2875 static char *lookup_peer_arg(const char *text, int state)
2877 if (__connmanctl_input_calc_level() > 1) {
2878 __connmanctl_input_lookup_end();
2882 return lookup_peer(text, state);
2885 static char *lookup_technology(const char *text, int state)
2888 static GHashTableIter iter;
2889 gpointer key, value;
2892 g_hash_table_iter_init(&iter, technology_hash);
2896 while (g_hash_table_iter_next(&iter, &key, &value)) {
2897 const char *technology = key;
2898 if (strncmp(text, technology, len) == 0)
2899 return strdup(technology);
2905 static char *lookup_technology_arg(const char *text, int state)
2907 if (__connmanctl_input_calc_level() > 1) {
2908 __connmanctl_input_lookup_end();
2912 return lookup_technology(text, state);
2915 static char *lookup_technology_offline(const char *text, int state)
2918 static bool end = false;
2921 if (__connmanctl_input_calc_level() > 1) {
2922 __connmanctl_input_lookup_end();
2934 str = lookup_technology(text, state);
2940 if (strncmp(text, "offline", len) == 0)
2941 return strdup("offline");
2946 static char *lookup_on_off(const char *text, int state)
2948 char *onoff[] = { "on", "off", NULL };
2959 while (onoff[idx]) {
2963 if (!strncmp(text, str, len))
2970 static char *lookup_tether(const char *text, int state)
2974 level = __connmanctl_input_calc_level();
2976 return lookup_technology(text, state);
2979 return lookup_on_off(text, state);
2981 __connmanctl_input_lookup_end();
2986 static char *lookup_agent(const char *text, int state)
2988 if (__connmanctl_input_calc_level() > 1) {
2989 __connmanctl_input_lookup_end();
2993 return lookup_on_off(text, state);
2996 static char *lookup_vpnconnection_arg(const char *text, int state)
2998 if (__connmanctl_input_calc_level() > 1) {
2999 __connmanctl_input_lookup_end();
3003 return lookup_key_from_table(vpnconnection_hash, text, state);
3006 static struct connman_option service_options[] = {
3007 {"properties", 'p', "[<service>] (obsolete)"},
3011 #if defined TIZEN_EXT_INS
3012 static struct connman_option ins_options[] = {
3014 {"filter-ssid", 's', "ssid"},
3015 {"filter-name", 'n', "[<service_name>]"},
3020 static struct connman_option config_options[] = {
3021 {"nameservers", 'n', "<dns1> [<dns2>] [<dns3>]"},
3022 {"timeservers", 't', "<ntp1> [<ntp2>] [...]"},
3023 {"domains", 'd', "<domain1> [<domain2>] [...]"},
3024 {"mdns", 'm', "yes|no"},
3025 {"ipv6", 'v', "off|auto [enable|disable|preferred]|\n"
3026 "\t\t\tmanual <address> <prefixlength> <gateway>"},
3027 {"proxy", 'x', "direct|auto <URL>|manual <URL1> [<URL2>] [...]\n"
3028 "\t\t\t[exclude <exclude1> [<exclude2>] [...]]"},
3029 {"autoconnect", 'a', "yes|no"},
3030 {"ipv4", 'i', "off|dhcp|manual <address> <netmask> <gateway>"},
3031 {"remove", 'r', " Remove service"},
3035 static struct connman_option monitor_options[] = {
3036 {"services", 's', "[off] Monitor only services"},
3037 {"tech", 'c', "[off] Monitor only technologies"},
3038 {"manager", 'm', "[off] Monitor only manager interface"},
3039 {"vpnmanager", 'M', "[off] Monitor only VPN manager "
3041 {"vpnconnection", 'C', "[off] Monitor only VPN "
3046 static struct connman_option session_options[] = {
3047 {"bearers", 'b', "<technology1> [<technology2> [...]]"},
3048 {"type", 't', "local|internet|any"},
3049 {"ifname", 'i', "[<interface_name>]"},
3050 {"srciprule", 's', "yes|no"},
3051 {"ctxid", 'c', "<context_identifier>"},
3055 #if defined TIZEN_EXT_WIFI_MESH
3056 static struct connman_option mesh_options[] = {
3057 {"ifadd", 'a', "<ifname> <wifi_ifname>\n"
3058 " [bridge_ifname] Add Virtual Mesh "
3060 {"ifrmv", 'r', "<ifname> Remove Virtual Mesh "
3062 {"peers", 'p', "[peer] Display Mesh peer "
3064 {"connect", 'c', "<peer> Connect Mesh Peer"},
3065 {"disconnect", 'd', "<peer> Disconnect Mesh Peer"},
3066 {"remove", 'f', "<peer> Forget Mesh Peer"},
3067 {"connected_peers", 'C', "[] Displays connected"
3068 " Peer informations"},
3069 {"disconnected_peers", 'D', "[] Displays "
3070 "Disconnected Peer informations"},
3071 {"create_network", 'n', "<name> <frequency> <sec_type> Create New Mesh "
3073 {"abort_scan", 'A', " Abort ongoing mesh "
3075 {"specific_scan", 'S', "<name> <frequency> Create New Mesh "
3077 {"config", 'P', "<peer> Set Mesh Network "
3078 "Configurations\n Passphrase <passphrase>"},
3079 {"set_gate", 'G', "<gate_ann> <rootmode> <stp> Set Mesh Gate "
3081 {"add_peer", 'z', "<addr> Add Mesh Peer"},
3082 {"remove_peer", 'y', "<addr> Remove Mesh Peer"},
3087 static char *lookup_options(struct connman_option *options, const char *text,
3099 while (options[idx].name) {
3100 str = options[idx].name;
3103 if (str && strncmp(text, str, len) == 0)
3110 static char *lookup_monitor(const char *text, int state)
3114 level = __connmanctl_input_calc_level();
3117 return lookup_options(monitor_options, text, state);
3120 return lookup_on_off(text, state);
3122 __connmanctl_input_lookup_end();
3126 static char *lookup_config(const char *text, int state)
3128 if (__connmanctl_input_calc_level() < 2)
3129 return lookup_key_from_table(service_hash, text, state);
3131 return lookup_options(config_options, text, state);
3134 static char *lookup_session(const char *text, int state)
3136 return lookup_options(session_options, text, state);
3139 #if defined TIZEN_EXT_WIFI_MESH
3140 static char *lookup_mesh(const char *text, int state)
3142 return lookup_options(mesh_options, text, state);
3146 static int peer_service_cb(DBusMessageIter *iter, int errnum,
3147 const char *error, void *user_data)
3149 bool registration = GPOINTER_TO_INT(user_data);
3152 fprintf(stderr, "Error %s peer service: %s\n",
3153 registration ? "registering" : "unregistering", error);
3155 fprintf(stdout, "Peer service %s\n",
3156 registration ? "registered" : "unregistered");
3161 struct _peer_service {
3162 unsigned char *bjr_query;
3164 unsigned char *bjr_response;
3165 int bjr_response_len;
3166 unsigned char *wfd_ies;
3173 static void append_dict_entry_fixed_array(DBusMessageIter *iter,
3174 const char *property, void *value, int length)
3176 DBusMessageIter dict_entry, variant, array;
3178 dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY,
3180 dbus_message_iter_append_basic(&dict_entry, DBUS_TYPE_STRING,
3182 dbus_message_iter_open_container(&dict_entry, DBUS_TYPE_VARIANT,
3183 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING,
3185 dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
3186 DBUS_TYPE_BYTE_AS_STRING, &array);
3187 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
3189 dbus_message_iter_close_container(&variant, &array);
3190 dbus_message_iter_close_container(&dict_entry, &variant);
3191 dbus_message_iter_close_container(iter, &dict_entry);
3194 static void append_peer_service_dict(DBusMessageIter *iter, void *user_data)
3196 struct _peer_service *service = user_data;
3198 if (service->bjr_query && service->bjr_response) {
3199 append_dict_entry_fixed_array(iter, "BonjourQuery",
3200 &service->bjr_query, service->bjr_query_len);
3201 append_dict_entry_fixed_array(iter, "BonjourResponse",
3202 &service->bjr_response, service->bjr_response_len);
3203 } else if (service->upnp_service && service->version) {
3204 __connmanctl_dbus_append_dict_entry(iter, "UpnpVersion",
3205 DBUS_TYPE_INT32, &service->version);
3206 __connmanctl_dbus_append_dict_entry(iter, "UpnpService",
3207 DBUS_TYPE_STRING, &service->upnp_service);
3208 } else if (service->wfd_ies) {
3209 append_dict_entry_fixed_array(iter, "WiFiDisplayIEs",
3210 &service->wfd_ies, service->wfd_ies_len);
3214 static void peer_service_append(DBusMessageIter *iter, void *user_data)
3216 struct _peer_service *service = user_data;
3219 __connmanctl_dbus_append_dict(iter, append_peer_service_dict, service);
3221 if (service->master < 0)
3224 master = service->master == 1 ? TRUE : FALSE;
3225 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &master);
3228 static struct _peer_service *fill_in_peer_service(unsigned char *bjr_query,
3229 int bjr_query_len, unsigned char *bjr_response,
3230 int bjr_response_len, char *upnp_service,
3231 int version, unsigned char *wfd_ies,
3234 struct _peer_service *service;
3236 service = dbus_malloc0(sizeof(*service));
3238 #if defined TIZEN_EXT
3243 if (bjr_query_len && bjr_response_len) {
3244 service->bjr_query = dbus_malloc0(bjr_query_len);
3245 #if defined TIZEN_EXT
3246 if(!service->bjr_query) {
3251 memcpy(service->bjr_query, bjr_query, bjr_query_len);
3252 service->bjr_query_len = bjr_query_len;
3254 service->bjr_response = dbus_malloc0(bjr_response_len);
3255 #if defined TIZEN_EXT
3256 if(!service->bjr_response) {
3257 dbus_free(service->bjr_query);
3262 memcpy(service->bjr_response, bjr_response, bjr_response_len);
3263 service->bjr_response_len = bjr_response_len;
3264 } else if (upnp_service && version) {
3265 service->upnp_service = strdup(upnp_service);
3266 service->version = version;
3267 } else if (wfd_ies && wfd_ies_len) {
3268 service->wfd_ies = dbus_malloc0(wfd_ies_len);
3269 #if defined TIZEN_EXT
3270 if (!service->wfd_ies) {
3275 memcpy(service->wfd_ies, wfd_ies, wfd_ies_len);
3276 service->wfd_ies_len = wfd_ies_len;
3285 static void free_peer_service(struct _peer_service *service)
3287 dbus_free(service->bjr_query);
3288 dbus_free(service->bjr_response);
3289 dbus_free(service->wfd_ies);
3290 free(service->upnp_service);
3294 static int peer_service_register(unsigned char *bjr_query, int bjr_query_len,
3295 unsigned char *bjr_response, int bjr_response_len,
3296 char *upnp_service, int version,
3297 unsigned char *wfd_ies, int wfd_ies_len, int master)
3299 struct _peer_service *service;
3300 bool registration = true;
3303 service = fill_in_peer_service(bjr_query, bjr_query_len, bjr_response,
3304 bjr_response_len, upnp_service, version,
3305 wfd_ies, wfd_ies_len);
3309 service->master = master;
3311 ret = __connmanctl_dbus_method_call(connection, "net.connman", "/",
3312 "net.connman.Manager", "RegisterPeerService",
3313 peer_service_cb, GINT_TO_POINTER(registration),
3314 peer_service_append, service);
3316 free_peer_service(service);
3321 static int peer_service_unregister(unsigned char *bjr_query, int bjr_query_len,
3322 unsigned char *bjr_response, int bjr_response_len,
3323 char *upnp_service, int version,
3324 unsigned char *wfd_ies, int wfd_ies_len)
3326 struct _peer_service *service;
3327 bool registration = false;
3330 service = fill_in_peer_service(bjr_query, bjr_query_len, bjr_response,
3331 bjr_response_len, upnp_service, version,
3332 wfd_ies, wfd_ies_len);
3336 service->master = -1;
3338 ret = __connmanctl_dbus_method_call(connection, "net.connman", "/",
3339 "net.connman.Manager", "UnregisterPeerService",
3340 peer_service_cb, GINT_TO_POINTER(registration),
3341 peer_service_append, service);
3343 free_peer_service(service);
3348 static int parse_spec_array(char *command, unsigned char spec[1024])
3350 int length, pos, end;
3354 end = strlen(command);
3355 for (e = NULL, length = pos = 0; command[pos] != '\0'; length++) {
3359 b[0] = command[pos];
3360 b[1] = command[pos+1];
3362 spec[length] = strtol(b, &e, 16);
3363 if (e && *e != '\0')
3372 static int cmd_peer_service(char *args[], int num,
3373 struct connman_option *options)
3375 unsigned char bjr_query[1024] = {};
3376 unsigned char bjr_response[1024] = {};
3377 unsigned char wfd_ies[1024] = {};
3378 char *upnp_service = NULL;
3379 int bjr_query_len = 0, bjr_response_len = 0;
3380 int version = 0, master = 0, wfd_ies_len = 0;
3386 if (!strcmp(args[2], "wfd_ies")) {
3387 wfd_ies_len = parse_spec_array(args[3], wfd_ies);
3388 if (wfd_ies_len == -EINVAL)
3398 if (!strcmp(args[2], "bjr_query")) {
3399 if (strcmp(args[4], "bjr_response"))
3401 bjr_query_len = parse_spec_array(args[3], bjr_query);
3402 bjr_response_len = parse_spec_array(args[5], bjr_response);
3404 if (bjr_query_len == -EINVAL || bjr_response_len == -EINVAL)
3406 } else if (!strcmp(args[2], "upnp_service")) {
3409 if (strcmp(args[4], "upnp_version"))
3411 upnp_service = args[3];
3412 version = strtol(args[5], &e, 10);
3419 master = parse_boolean(args[6]);
3424 if (!strcmp(args[1], "register")) {
3425 return peer_service_register(bjr_query, bjr_query_len,
3426 bjr_response, bjr_response_len, upnp_service,
3427 version, wfd_ies, wfd_ies_len, master);
3428 } else if (!strcmp(args[1], "unregister")) {
3429 return peer_service_unregister(bjr_query, bjr_query_len,
3430 bjr_response, bjr_response_len, upnp_service,
3431 version, wfd_ies, wfd_ies_len);
3437 static const struct {
3439 const char *argument;
3440 struct connman_option *options;
3441 int (*func) (char *args[], int num, struct connman_option *options);
3443 __connmanctl_lookup_cb cb;
3445 { "state", NULL, NULL, cmd_state,
3446 "Shows if the system is online or offline", NULL },
3447 { "technologies", NULL, NULL, cmd_technologies,
3448 "Display technologies", NULL },
3449 { "clock", NULL, NULL, cmd_clock,
3450 "Get System Clock Properties", NULL },
3451 { "enable", "<technology>|offline", NULL, cmd_enable,
3452 "Enables given technology or offline mode",
3453 lookup_technology_offline },
3454 { "disable", "<technology>|offline", NULL, cmd_disable,
3455 "Disables given technology or offline mode",
3456 lookup_technology_offline },
3457 #if defined TIZEN_EXT_WIFI_MESH
3458 { "mesh", "", mesh_options, cmd_mesh, "Mesh specific commands",
3461 { "tether", "<technology> on|off\n"
3462 " wifi [on|off] <ssid> <passphrase> ",
3464 "Enable, disable tethering, set SSID and passphrase for wifi",
3466 { "tethering_clients", NULL, NULL, cmd_tethering_clients,
3467 "Display tethering clients", NULL },
3468 { "services", "[<service>]", service_options, cmd_services,
3469 "Display services", lookup_service_arg },
3470 #if defined TIZEN_EXT_INS
3471 { "ins", NULL, ins_options, cmd_ins,
3472 "Display intelligent network selection", NULL },
3474 { "peers", "[peer]", NULL, cmd_peers,
3475 "Display peers", lookup_peer_arg },
3476 { "scan", "<technology>", NULL, cmd_scan,
3477 "Scans for new services for given technology",
3478 lookup_technology_arg },
3479 { "connect", "<service/peer>", NULL, cmd_connect,
3480 "Connect a given service or peer", lookup_service_arg },
3481 { "disconnect", "<service/peer>", NULL, cmd_disconnect,
3482 "Disconnect a given service or peer", lookup_service_arg },
3483 { "move-before", "<service> <target service> ", NULL,
3484 cmd_service_move_before, "Move <service> before <target service>",
3485 lookup_service_arg },
3486 { "move-after", "<service> <target service> ", NULL,
3487 cmd_service_move_after, "Move <service> after <target service>",
3488 lookup_service_arg },
3489 { "config", "<service>", config_options, cmd_config,
3490 "Set service configuration options", lookup_config },
3491 { "monitor", "[off]", monitor_options, cmd_monitor,
3492 "Monitor signals from interfaces", lookup_monitor },
3493 { "agent", "on|off", NULL, cmd_agent,
3494 "Agent mode", lookup_agent },
3495 { "vpnconnections", "[<connection>]", NULL, cmd_vpnconnections,
3496 "Display VPN connections", lookup_vpnconnection_arg },
3497 { "vpnagent", "on|off", NULL, cmd_vpnagent,
3498 "VPN Agent mode", lookup_agent },
3499 { "session", "on|off|connect|disconnect|config", session_options,
3500 cmd_session, "Enable or disable a session", lookup_session },
3501 { "peer_service", "register|unregister <specs> <master>\n"
3502 "Where specs are:\n"
3503 "\tbjr_query <query> bjr_response <response>\n"
3504 "\tupnp_service <service> upnp_version <version>\n"
3505 "\twfd_ies <ies>\n", NULL,
3506 cmd_peer_service, "(Un)Register a Peer Service", NULL },
3507 { "help", NULL, NULL, cmd_help,
3508 "Show help", NULL },
3509 { "exit", NULL, NULL, cmd_exit,
3511 { "quit", NULL, NULL, cmd_exit,
3516 static int cmd_help(char *args[], int num, struct connman_option *options)
3518 bool interactive = __connmanctl_is_interactive();
3521 if (interactive == false)
3522 fprintf(stdout, "Usage: connmanctl [[command] [args]]\n");
3524 for (i = 0; cmd_table[i].cmd; i++) {
3525 const char *cmd = cmd_table[i].cmd;
3526 const char *argument = cmd_table[i].argument;
3527 const char *desc = cmd_table[i].desc;
3529 printf("%-16s%-22s%s\n", cmd? cmd: "",
3530 argument? argument: "",
3533 if (cmd_table[i].options) {
3534 for (j = 0; cmd_table[i].options[j].name;
3536 const char *options_desc =
3537 cmd_table[i].options[j].desc ?
3538 cmd_table[i].options[j].desc: "";
3540 printf(" --%-16s%s\n",
3541 cmd_table[i].options[j].name,
3547 if (interactive == false)
3548 fprintf(stdout, "\nNote: arguments and output are considered "
3549 "EXPERIMENTAL for now.\n");
3554 __connmanctl_lookup_cb __connmanctl_get_lookup_func(const char *text)
3556 int i, cmdlen, textlen;
3561 textlen = strlen(text);
3563 for (i = 0; cmd_table[i].cmd; i++) {
3564 cmdlen = strlen(cmd_table[i].cmd);
3566 if (textlen > cmdlen && text[cmdlen] != ' ')
3569 if (strncmp(cmd_table[i].cmd, text, cmdlen) == 0)
3570 return cmd_table[i].cb;
3576 int __connmanctl_commands(DBusConnection *dbus_conn, char *argv[], int argc)
3580 connection = dbus_conn;
3582 for (i = 0; cmd_table[i].cmd; i++) {
3583 if (g_strcmp0(cmd_table[i].cmd, argv[0]) == 0 &&
3584 cmd_table[i].func) {
3585 result = cmd_table[i].func(argv, argc,
3586 cmd_table[i].options);
3587 if (result < 0 && result != -EINPROGRESS)
3588 fprintf(stderr, "Error '%s': %s\n", argv[0],
3594 fprintf(stderr, "Error '%s': Unknown command\n", argv[0]);
3598 char *__connmanctl_lookup_command(const char *text, int state)
3608 while (cmd_table[i].cmd) {
3609 const char *command = cmd_table[i].cmd;
3613 if (strncmp(text, command, len) == 0)
3614 return strdup(command);
3620 static char *get_path(char *full_path)
3624 path = strrchr(full_path, '/');
3625 if (path && *path != '\0')
3633 static void add_service_id(const char *path)
3635 g_hash_table_replace(service_hash, g_strdup(path),
3636 GINT_TO_POINTER(TRUE));
3639 static void remove_service_id(const char *path)
3641 g_hash_table_remove(service_hash, path);
3644 static void services_added(DBusMessageIter *iter)
3646 DBusMessageIter array;
3649 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
3651 dbus_message_iter_recurse(iter, &array);
3652 if (dbus_message_iter_get_arg_type(&array) !=
3653 DBUS_TYPE_OBJECT_PATH)
3656 dbus_message_iter_get_basic(&array, &path);
3657 add_service_id(get_path(path));
3659 dbus_message_iter_next(iter);
3663 static void update_services(DBusMessageIter *iter)
3665 DBusMessageIter array;
3668 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3671 dbus_message_iter_recurse(iter, &array);
3672 services_added(&array);
3674 dbus_message_iter_next(iter);
3675 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3678 dbus_message_iter_recurse(iter, &array);
3679 while (dbus_message_iter_get_arg_type(&array) ==
3680 DBUS_TYPE_OBJECT_PATH) {
3681 dbus_message_iter_get_basic(&array, &path);
3682 remove_service_id(get_path(path));
3684 dbus_message_iter_next(&array);
3688 static int populate_service_hash(DBusMessageIter *iter, int errnum,
3689 const char *error, void *user_data)
3692 fprintf(stderr, "Error getting services: %s", error);
3696 update_services(iter);
3700 static void add_vpnconnection_id(const char *path)
3702 g_hash_table_replace(vpnconnection_hash, g_strdup(path),
3703 GINT_TO_POINTER(TRUE));
3706 static void remove_vpnconnection_id(const char *path)
3708 g_hash_table_remove(vpnconnection_hash, path);
3711 static void vpnconnection_added(DBusMessageIter *iter)
3715 dbus_message_iter_get_basic(iter, &path);
3716 add_vpnconnection_id(get_path(path));
3719 static void vpnconnection_removed(DBusMessageIter *iter)
3723 dbus_message_iter_get_basic(iter, &path);
3724 remove_vpnconnection_id(get_path(path));
3727 static void add_vpnconnections(DBusMessageIter *iter)
3729 DBusMessageIter array;
3732 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
3734 dbus_message_iter_recurse(iter, &array);
3735 if (dbus_message_iter_get_arg_type(&array) !=
3736 DBUS_TYPE_OBJECT_PATH)
3739 dbus_message_iter_get_basic(&array, &path);
3740 add_vpnconnection_id(get_path(path));
3742 dbus_message_iter_next(iter);
3746 static int populate_vpnconnection_hash(DBusMessageIter *iter, int errnum,
3747 const char *error, void *user_data)
3749 DBusMessageIter array;
3752 fprintf(stderr, "Error getting VPN connections: %s", error);
3756 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3759 dbus_message_iter_recurse(iter, &array);
3761 add_vpnconnections(&array);
3766 static void add_peer_id(const char *path)
3768 g_hash_table_replace(peer_hash, g_strdup(path), GINT_TO_POINTER(TRUE));
3771 static void remove_peer_id(const char *path)
3773 g_hash_table_remove(peer_hash, path);
3776 static void peers_added(DBusMessageIter *iter)
3778 DBusMessageIter array;
3781 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
3783 dbus_message_iter_recurse(iter, &array);
3784 if (dbus_message_iter_get_arg_type(&array) !=
3785 DBUS_TYPE_OBJECT_PATH)
3788 dbus_message_iter_get_basic(&array, &path);
3789 add_peer_id(get_path(path));
3791 dbus_message_iter_next(iter);
3795 static void update_peers(DBusMessageIter *iter)
3797 DBusMessageIter array;
3800 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3803 dbus_message_iter_recurse(iter, &array);
3804 peers_added(&array);
3806 dbus_message_iter_next(iter);
3807 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3810 dbus_message_iter_recurse(iter, &array);
3811 while (dbus_message_iter_get_arg_type(&array) ==
3812 DBUS_TYPE_OBJECT_PATH) {
3813 dbus_message_iter_get_basic(&array, &path);
3814 remove_peer_id(get_path(path));
3816 dbus_message_iter_next(&array);
3820 static int populate_peer_hash(DBusMessageIter *iter, int errnum,
3821 const char *error, void *user_data)
3824 fprintf(stderr, "Error getting peers: %s", error);
3832 static void add_technology_id(const char *path)
3834 g_hash_table_replace(technology_hash, g_strdup(path),
3835 GINT_TO_POINTER(TRUE));
3838 static void remove_technology_id(const char *path)
3840 g_hash_table_remove(technology_hash, path);
3843 static void remove_technology(DBusMessageIter *iter)
3847 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH)
3850 dbus_message_iter_get_basic(iter, &path);
3851 remove_technology_id(get_path(path));
3854 static void add_technology(DBusMessageIter *iter)
3858 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH)
3861 dbus_message_iter_get_basic(iter, &path);
3862 add_technology_id(get_path(path));
3865 static void update_technologies(DBusMessageIter *iter)
3867 DBusMessageIter array;
3869 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3872 dbus_message_iter_recurse(iter, &array);
3874 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
3875 DBusMessageIter object_path;
3877 dbus_message_iter_recurse(&array, &object_path);
3879 add_technology(&object_path);
3881 dbus_message_iter_next(&array);
3885 static int populate_technology_hash(DBusMessageIter *iter, int errnum,
3886 const char *error, void *user_data)
3889 fprintf(stderr, "Error getting technologies: %s\n", error);
3893 update_technologies(iter);
3898 static DBusHandlerResult monitor_completions_changed(
3899 DBusConnection *connection,
3900 DBusMessage *message, void *user_data)
3902 bool *enabled = user_data;
3903 DBusMessageIter iter;
3904 DBusHandlerResult handled;
3907 handled = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3909 handled = DBUS_HANDLER_RESULT_HANDLED;
3911 if (dbus_message_is_signal(message, "net.connman.Manager",
3912 "ServicesChanged")) {
3913 dbus_message_iter_init(message, &iter);
3914 update_services(&iter);
3918 if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
3919 "ConnectionAdded")) {
3920 dbus_message_iter_init(message, &iter);
3921 vpnconnection_added(&iter);
3925 if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
3926 "ConnectionRemoved")) {
3927 dbus_message_iter_init(message, &iter);
3928 vpnconnection_removed(&iter);
3932 if (dbus_message_is_signal(message, "net.connman.Manager",
3934 dbus_message_iter_init(message, &iter);
3935 update_peers(&iter);
3939 if (dbus_message_is_signal(message, "net.connman.Manager",
3940 "TechnologyAdded")) {
3941 dbus_message_iter_init(message, &iter);
3942 add_technology(&iter);
3946 if (dbus_message_is_signal(message, "net.connman.Manager",
3947 "TechnologyRemoved")) {
3948 dbus_message_iter_init(message, &iter);
3949 remove_technology(&iter);
3953 if (!g_strcmp0(dbus_message_get_interface(message),
3954 "net.connman.Manager"))
3957 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3960 void __connmanctl_monitor_completions(DBusConnection *dbus_conn)
3962 bool *manager_enabled = NULL;
3966 for (i = 0; monitor[i].interface; i++) {
3967 if (!strcmp(monitor[i].interface, "Manager")) {
3968 manager_enabled = &monitor[i].enabled;
3974 g_hash_table_destroy(service_hash);
3975 g_hash_table_destroy(vpnconnection_hash);
3976 g_hash_table_destroy(technology_hash);
3978 dbus_bus_remove_match(connection,
3979 "type='signal',interface='net.connman.Manager'", NULL);
3980 dbus_bus_remove_match(connection,
3981 "type='signal',interface='net.connman.vpn.Manager'",
3983 dbus_connection_remove_filter(connection,
3984 monitor_completions_changed,
3989 connection = dbus_conn;
3991 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
3994 vpnconnection_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
3997 peer_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
4000 technology_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
4003 __connmanctl_dbus_method_call(connection,
4004 CONNMAN_SERVICE, CONNMAN_PATH,
4005 "net.connman.Manager", "GetServices",
4006 populate_service_hash, NULL, NULL, NULL);
4008 __connmanctl_dbus_method_call(connection,
4009 VPN_SERVICE, CONNMAN_PATH,
4010 "net.connman.vpn.Manager", "GetConnections",
4011 populate_vpnconnection_hash, NULL, NULL, NULL);
4013 __connmanctl_dbus_method_call(connection,
4014 CONNMAN_SERVICE, CONNMAN_PATH,
4015 "net.connman.Manager", "GetPeers",
4016 populate_peer_hash, NULL, NULL, NULL);
4018 __connmanctl_dbus_method_call(connection,
4019 CONNMAN_SERVICE, CONNMAN_PATH,
4020 "net.connman.Manager", "GetTechnologies",
4021 populate_technology_hash, NULL, NULL, NULL);
4023 dbus_connection_add_filter(connection,
4024 monitor_completions_changed, manager_enabled,
4027 dbus_error_init(&err);
4028 dbus_bus_add_match(connection,
4029 "type='signal',interface='net.connman.Manager'", &err);
4031 if (dbus_error_is_set(&err)) {
4032 fprintf(stderr, "Error: %s\n", err.message);
4036 dbus_bus_add_match(connection,
4037 "type='signal',interface='net.connman.vpn.Manager'",
4040 if (dbus_error_is_set(&err))
4041 fprintf(stderr, "Error: %s\n", err.message);