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"
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
335 static int ins_list(DBusMessageIter *iter, int errnum,
336 const char *error, void *user_data)
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
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;
599 static int tether_update(struct tether_properties *tether)
603 if (tether->ssid_result == 0 && tether->passphrase_result == 0 &&
604 tether->freq_result == 0) {
605 ret = tether_set("wifi", tether->set_tethering);
610 if (tether->ssid_result != -EINPROGRESS &&
611 tether->passphrase_result != -EINPROGRESS &&
612 tether->freq_result != -EINPROGRESS) {
620 static int tether_set_ssid_return(DBusMessageIter *iter, int errnum,
621 const char *error, void *user_data)
623 struct tether_properties *tether = user_data;
626 fprintf(stdout, "Wifi SSID set\n");
627 tether->ssid_result = 0;
629 fprintf(stderr, "Error setting wifi SSID: %s\n", error);
630 tether->ssid_result = -EINVAL;
633 return tether_update(tether);
636 static int tether_set_passphrase_return(DBusMessageIter *iter, int errnum,
637 const char *error, void *user_data)
639 struct tether_properties *tether = user_data;
642 fprintf(stdout, "Wifi passphrase set\n");
643 tether->passphrase_result = 0;
645 fprintf(stderr, "Error setting wifi passphrase: %s\n", error);
646 tether->passphrase_result = -EINVAL;
649 return tether_update(tether);
652 static int tether_set_freq_return(DBusMessageIter *iter, int errnum,
653 const char *error, void *user_data)
655 struct tether_properties *tether = user_data;
658 fprintf(stdout, "Wifi access point frequency set\n");
659 tether->freq_result = 0;
661 fprintf(stderr, "Error setting wifi frequency: %s\n", error);
662 tether->freq_result = -EINVAL;
665 return tether_update(tether);
668 static int tether_set_ssid(char *ssid, char *passphrase, int set_tethering, int freq)
670 struct tether_properties *tether = g_new0(struct tether_properties, 1);
672 tether->set_tethering = set_tethering;
674 tether->ssid_result = __connmanctl_dbus_set_property(connection,
675 "/net/connman/technology/wifi",
676 "net.connman.Technology",
677 tether_set_ssid_return, tether,
678 "TetheringIdentifier", DBUS_TYPE_STRING, &ssid);
680 tether->passphrase_result =__connmanctl_dbus_set_property(connection,
681 "/net/connman/technology/wifi",
682 "net.connman.Technology",
683 tether_set_passphrase_return, tether,
684 "TetheringPassphrase", DBUS_TYPE_STRING, &passphrase);
687 tether->freq_result =__connmanctl_dbus_set_property(connection,
688 "/net/connman/technology/wifi",
689 "net.connman.Technology",
690 tether_set_freq_return, tether,
691 "TetheringFreq", DBUS_TYPE_INT32, &freq);
694 if (tether->ssid_result != -EINPROGRESS &&
695 tether->passphrase_result != -EINPROGRESS &&
696 tether->freq_result != -EINPROGRESS) {
701 #if defined TIZEN_EXT
707 #if defined TIZEN_EXT_WIFI_MESH
708 struct mesh_if_prop {
714 struct mesh_create_network {
720 struct mesh_specific_scan_params {
725 struct mesh_gate_params {
731 static int mesh_return(DBusMessageIter *iter, const char *error,
734 char *method = user_data;
737 fprintf(stderr, "Error %s: %s\n", method, error);
739 fprintf(stderr, "Success %s\n", method);
746 static void mesh_interface_add_append(DBusMessageIter *iter, void *user_data)
748 struct mesh_if_prop *append = user_data;
750 /* Append Virtual Interface Name */
751 __connmanctl_dbus_append_dict_entry(iter, "Ifname",
752 DBUS_TYPE_STRING, &append->ifname);
754 /* Append Parent WiFi Interface Name */
755 __connmanctl_dbus_append_dict_entry(iter, "ParentIfname",
756 DBUS_TYPE_STRING, &append->parent_ifname);
758 /* Append Bridge Interface Name */
759 if (append->bridge_ifname)
760 __connmanctl_dbus_append_dict_entry(iter, "BridgeIfname",
761 DBUS_TYPE_STRING, &append->bridge_ifname);
764 static void mesh_interface_remove_append(DBusMessageIter *iter, void *user_data)
766 struct mesh_if_prop *append = user_data;
768 /* Append Virtual Interface Name */
769 __connmanctl_dbus_append_dict_entry(iter, "Ifname",
770 DBUS_TYPE_STRING, &append->ifname);
773 static void mesh_create_network_append(DBusMessageIter *iter, void *user_data)
775 struct mesh_create_network *append = user_data;
777 /* Append Mesh Network Name */
778 __connmanctl_dbus_append_dict_entry(iter, "Name",
779 DBUS_TYPE_STRING, &append->name);
781 /* Append Mesh Network Frequency */
782 __connmanctl_dbus_append_dict_entry(iter, "Frequency",
783 DBUS_TYPE_UINT16, &append->freq);
785 /* Append Mesh Network Security Type */
786 __connmanctl_dbus_append_dict_entry(iter, "Security",
787 DBUS_TYPE_STRING, &append->sec_type);
790 static void mesh_specific_scan_append(DBusMessageIter *iter, void *user_data)
792 struct mesh_specific_scan_params *append = user_data;
794 /* Append Mesh Network Name */
795 __connmanctl_dbus_append_dict_entry(iter, "Name",
796 DBUS_TYPE_STRING, &append->name);
798 /* Append Mesh Network Frequency */
799 __connmanctl_dbus_append_dict_entry(iter, "Frequency",
800 DBUS_TYPE_UINT16, &append->freq);
803 static void mesh_set_gate_append(DBusMessageIter *iter, void *user_data)
805 struct mesh_gate_params *append = user_data;
807 /* Append Gate Announce Protocol */
808 __connmanctl_dbus_append_dict_entry(iter, "GateAnnounce",
809 DBUS_TYPE_BOOLEAN, &append->gate_announce);
811 /* Append HWMP Root Mode */
812 __connmanctl_dbus_append_dict_entry(iter, "HWMPRootMode",
813 DBUS_TYPE_UINT16, &append->hwmp_rootmode);
816 __connmanctl_dbus_append_dict_entry(iter, "STP", DBUS_TYPE_UINT16,
820 static void mesh_peer_append(DBusMessageIter *iter, void *user_data)
822 char *peer_addr = user_data;
824 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &peer_addr);
829 static int mesh_peers_list(DBusMessageIter *iter,
830 const char *error, void *user_data)
833 __connmanctl_mesh_peers_list(iter);
834 fprintf(stdout, "\n");
836 fprintf(stderr, "Error: %s\n", error);
841 static int connected_mesh_peers_list(DBusMessageIter *iter,
842 const char *error, void *user_data)
845 __connmanctl_mesh_connected_peers_list(iter);
846 fprintf(stdout, "\n");
848 fprintf(stderr, "Error: %s\n", error);
853 static int disconnected_mesh_peers_list(DBusMessageIter *iter,
854 const char *error, void *user_data)
857 __connmanctl_mesh_disconnected_peers_list(iter);
858 fprintf(stdout, "\n");
860 fprintf(stderr, "Error: %s\n", error);
865 static int mesh_connect_return(DBusMessageIter *iter, const char *error,
868 char *path = user_data;
871 char *str = strrchr(path, '/');
873 fprintf(stdout, "Connected %s\n", str);
875 fprintf(stderr, "Error %s: %s\n", path, error);
882 static int mesh_disconnect_return(DBusMessageIter *iter, const char *error,
885 char *path = user_data;
888 char *str = strrchr(path, '/');
890 fprintf(stdout, "Disconnected %s\n", str);
892 fprintf(stderr, "Error %s: %s\n", path, error);
899 static int mesh_remove_return(DBusMessageIter *iter, const char *error,
902 char *path = user_data;
905 char *str = strrchr(path, '/');
907 fprintf(stdout, "Removed %s\n", str);
909 fprintf(stderr, "Error %s: %s\n", path, error);
916 static int mesh_config_return(DBusMessageIter *iter, const char *error,
919 char *path = user_data;
920 char *str = strrchr(path, '/');
924 fprintf(stderr, "Error %s: %s\n", path, error);
926 fprintf(stdout, "Success SetProperty %s\n", str);
933 static int cmd_mesh(char *args[], int num, struct connman_option *options)
939 char *mesh_peer_name = NULL;
940 char *mesh_peer_path = NULL;
941 char *property = NULL;
943 struct mesh_if_prop *append;
944 struct mesh_create_network *network;
945 struct mesh_specific_scan_params *scan_params;
946 struct mesh_gate_params *gate_params;
947 char *mesh_peer_addr = NULL;
949 c = parse_args(args[1], options);
953 if (num < 4 || num > 5) {
957 path = g_strdup_printf("/net/connman/technology/mesh");
959 append = dbus_malloc0(sizeof(struct mesh_if_prop));
960 append->ifname = g_strdup(args[2]);
961 append->parent_ifname = g_strdup(args[3]);
963 append->bridge_ifname = g_strdup(args[4]);
964 method = g_strdup("MeshInterfaceAdd");
965 result = __connmanctl_dbus_mesh_dict(connection, path,
966 "net.connman.Technology", mesh_return, method,
967 "MeshInterfaceAdd", DBUS_TYPE_STRING,
968 mesh_interface_add_append, append);
969 g_free(append->ifname);
970 g_free(append->parent_ifname);
971 g_free(append->bridge_ifname);
980 path = g_strdup_printf("/net/connman/technology/mesh");
982 append = dbus_malloc0(sizeof(struct mesh_if_prop));
983 append->ifname = g_strdup(args[2]);
984 method = g_strdup("MeshInterfaceRemove");
985 result = __connmanctl_dbus_mesh_dict(connection, path,
986 "net.connman.Technology", mesh_return, method,
987 "MeshInterfaceRemove", DBUS_TYPE_STRING,
988 mesh_interface_remove_append, append);
989 g_free(append->ifname);
1000 mesh_peer_name = args[2];
1002 if (!mesh_peer_name) {
1003 result = __connmanctl_dbus_method_call(connection,
1004 CONNMAN_SERVICE, CONNMAN_PATH,
1005 "net.connman.Manager", "GetMeshPeers",
1006 mesh_peers_list, NULL, NULL, NULL);
1010 if (check_dbus_name(mesh_peer_name) == false) {
1015 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1017 result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1018 mesh_peer_path, "net.connman.Mesh", "GetProperties",
1019 object_properties, mesh_peer_path, NULL, NULL);
1033 mesh_peer_name = args[2];
1035 if (check_dbus_name(mesh_peer_name) == false) {
1040 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1042 result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1043 mesh_peer_path, "net.connman.Mesh", "Connect",
1044 mesh_connect_return, mesh_peer_path, NULL, NULL);
1058 mesh_peer_name = args[2];
1060 if (check_dbus_name(mesh_peer_name) == false) {
1065 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1067 result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1068 mesh_peer_path, "net.connman.Mesh", "Disconnect",
1069 mesh_disconnect_return, mesh_peer_path, NULL, NULL);
1083 mesh_peer_name = args[2];
1085 if (check_dbus_name(mesh_peer_name) == false) {
1090 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1092 result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1093 mesh_peer_path, "net.connman.Mesh", "Remove",
1094 mesh_remove_return, mesh_peer_path, NULL, NULL);
1103 result = __connmanctl_dbus_method_call(connection,
1104 CONNMAN_SERVICE, CONNMAN_PATH,
1105 "net.connman.Manager", "GetConnectedMeshPeers",
1106 connected_mesh_peers_list, NULL, NULL, NULL);
1115 result = __connmanctl_dbus_method_call(connection,
1116 CONNMAN_SERVICE, CONNMAN_PATH,
1117 "net.connman.Manager",
1118 "GetDisconnectedMeshPeers",
1119 disconnected_mesh_peers_list, NULL, NULL, NULL);
1127 path = g_strdup_printf("/net/connman/technology/mesh");
1129 network = dbus_malloc0(sizeof(struct mesh_create_network));
1130 network->name = g_strdup(args[2]);
1131 network->freq = atoi(args[3]);
1132 network->sec_type = g_strdup(args[4]);
1133 method = g_strdup("MeshCreateNetwork");
1134 result = __connmanctl_dbus_mesh_dict(connection, path,
1135 "net.connman.Technology", mesh_return, method,
1136 "MeshCreateNetwork", DBUS_TYPE_STRING,
1137 mesh_create_network_append, network);
1138 g_free(network->name);
1139 g_free(network->sec_type);
1148 path = g_strdup_printf("/net/connman/technology/mesh");
1150 method = g_strdup("AbortScan");
1151 result = __connmanctl_dbus_mesh_dict(connection, path,
1152 "net.connman.Technology", mesh_return, method,
1153 "AbortScan", DBUS_TYPE_STRING,
1162 path = g_strdup_printf("/net/connman/technology/mesh");
1164 scan_params = dbus_malloc0(sizeof(struct mesh_specific_scan_params));
1165 scan_params->name = g_strdup(args[2]);
1166 scan_params->freq = atoi(args[3]);
1167 method = g_strdup("MeshSpecificScan");
1168 result = __connmanctl_dbus_mesh_dict(connection, path,
1169 "net.connman.Technology", mesh_return, method,
1170 "MeshSpecificScan", DBUS_TYPE_STRING,
1171 mesh_specific_scan_append, scan_params);
1172 g_free(scan_params->name);
1173 g_free(scan_params);
1182 mesh_peer_name = args[2];
1186 if (check_dbus_name(mesh_peer_name) == false) {
1191 mesh_peer_path = g_strdup_printf("/net/connman/mesh/%s",
1194 if (g_strcmp0(property, "Passphrase") == 0) {
1195 result = __connmanctl_dbus_set_property(connection,
1196 mesh_peer_path, "net.connman.Mesh",
1197 mesh_config_return, mesh_peer_path, property,
1198 DBUS_TYPE_STRING, &value);
1200 printf("Invalid property %s\n", property);
1212 path = g_strdup_printf("/net/connman/technology/mesh");
1214 gate_params = dbus_malloc0(sizeof(struct mesh_gate_params));
1215 gate_params->gate_announce = atoi(args[2]);
1216 gate_params->hwmp_rootmode = atoi(args[3]);
1217 gate_params->stp = atoi(args[4]);
1219 method = g_strdup("SetMeshGate");
1221 result = __connmanctl_dbus_mesh_dict(connection, path,
1222 "net.connman.Technology", mesh_return, method,
1223 "SetMeshGate", DBUS_TYPE_STRING,
1224 mesh_set_gate_append, gate_params);
1234 mesh_peer_addr = g_strdup(args[2]);
1235 method = g_strdup("MeshAddPeer");
1237 result = __connmanctl_dbus_method_call(connection,
1238 CONNMAN_SERVICE, CONNMAN_PATH,
1239 "net.connman.Manager", "MeshAddPeer",
1240 mesh_return, method, mesh_peer_append,
1251 mesh_peer_addr = g_strdup(args[2]);
1252 method = g_strdup("MeshRemovePeer");
1254 result = __connmanctl_dbus_method_call(connection,
1255 CONNMAN_SERVICE, CONNMAN_PATH,
1256 "net.connman.Manager", "MeshRemovePeer",
1257 mesh_return, method, mesh_peer_append,
1270 if (result != -EINPROGRESS)
1271 printf("Error '%s': %s\n", args[1], strerror(-result));
1279 static int cmd_tether(char *args[], int num, struct connman_option *options)
1281 char *ssid, *passphrase;
1287 set_tethering = parse_boolean(args[2]);
1289 if (strcmp(args[1], "wifi") == 0) {
1295 if (num >= 5 && set_tethering == -1)
1302 freq = atoi(args[num - 1]);
1306 passphrase = args[num - 1];
1307 ssid = args[num - 2];
1310 return tether_set_ssid(ssid, passphrase, set_tethering, freq);
1316 if (set_tethering == -1)
1319 if (check_dbus_name(args[1]) == false)
1322 return tether_set(args[1], set_tethering);
1325 static int cmd_tethering_clients(char *args[], int num, struct connman_option *options)
1330 return __connmanctl_dbus_method_call(connection,
1331 CONNMAN_SERVICE, CONNMAN_PATH,
1332 "net.connman.Manager", "GetTetheringClients",
1333 tethering_clients_list, NULL, NULL, NULL);
1336 static int scan_return(DBusMessageIter *iter, int ernnum, const char *error,
1339 char *path = user_data;
1342 char *str = strrchr(path, '/');
1344 fprintf(stdout, "Scan completed for %s\n", str);
1346 fprintf(stderr, "Error %s: %s\n", path, error);
1353 static int cmd_scan(char *args[], int num, struct connman_option *options)
1363 if (check_dbus_name(args[1]) == false)
1366 path = g_strdup_printf("/net/connman/technology/%s", args[1]);
1367 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, path,
1368 "net.connman.Technology", "Scan",
1369 scan_return, path, NULL, NULL);
1372 static int connect_return(DBusMessageIter *iter, int errnum,
1373 const char *error, void *user_data)
1375 char *path = user_data;
1378 char *str = strrchr(path, '/');
1380 fprintf(stdout, "Connected %s\n", str);
1382 fprintf(stderr, "Error %s: %s\n", path, error);
1389 static int cmd_connect(char *args[], int num, struct connman_option *options)
1391 const char *iface = "net.connman.Service";
1400 if (check_dbus_name(args[1]) == false)
1403 if (g_strstr_len(args[1], 5, "peer_") == args[1]) {
1404 iface = "net.connman.Peer";
1405 path = g_strdup_printf("/net/connman/peer/%s", args[1]);
1407 path = g_strdup_printf("/net/connman/service/%s", args[1]);
1409 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, path,
1410 iface, "Connect", connect_return, path, NULL, NULL);
1413 static int disconnect_return(DBusMessageIter *iter, int errnum,
1414 const char *error, void *user_data)
1416 char *path = user_data;
1419 char *str = strrchr(path, '/');
1421 fprintf(stdout, "Disconnected %s\n", str);
1423 fprintf(stderr, "Error %s: %s\n", path, error);
1430 static int cmd_disconnect(char *args[], int num, struct connman_option *options)
1432 const char *iface = "net.connman.Service";
1441 if (check_dbus_name(args[1]) == false)
1444 if (g_strstr_len(args[1], 5, "peer_") == args[1]) {
1445 iface = "net.connman.Peer";
1446 path = g_strdup_printf("/net/connman/peer/%s", args[1]);
1448 path = g_strdup_printf("/net/connman/service/%s", args[1]);
1450 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1451 path, iface, "Disconnect",
1452 disconnect_return, path, NULL, NULL);
1455 struct move_service {
1460 static int move_before_return(DBusMessageIter *iter, int errnum,
1461 const char *error, void *user_data)
1463 struct move_service *services = user_data;
1468 service = strrchr(services->service, '/');
1470 target = strrchr(services->target, '/');
1472 fprintf(stdout, "Moved %s before %s\n", service, target);
1474 fprintf(stderr, "Error %s: %s\n", services->service, error);
1476 g_free(services->service);
1477 g_free(services->target);
1483 static void move_before_append_args(DBusMessageIter *iter, void *user_data)
1485 char *path = user_data;
1487 dbus_message_iter_append_basic(iter,
1488 DBUS_TYPE_OBJECT_PATH, &path);
1491 static int cmd_service_move_before(char *args[], int num,
1492 struct connman_option *options)
1494 const char *iface = "net.connman.Service";
1495 struct move_service *services;
1503 if (check_dbus_name(args[1]) == false)
1506 services = g_new(struct move_service, 1);
1508 services->service = g_strdup_printf("/net/connman/service/%s", args[1]);
1509 services->target = g_strdup_printf("/net/connman/service/%s", args[2]);
1511 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1512 services->service, iface, "MoveBefore",
1513 move_before_return, services,
1514 move_before_append_args,
1518 static int move_after_return(DBusMessageIter *iter, int errnum,
1519 const char *error, void *user_data)
1521 struct move_service *services = user_data;
1526 service = strrchr(services->service, '/');
1528 target = strrchr(services->target, '/');
1530 fprintf(stdout, "Moved %s after %s\n", service, target);
1532 fprintf(stderr, "Error %s: %s\n", services->service, error);
1534 g_free(services->service);
1535 g_free(services->target);
1541 static void move_after_append_args(DBusMessageIter *iter, void *user_data)
1543 char *path = user_data;
1545 dbus_message_iter_append_basic(iter,
1546 DBUS_TYPE_OBJECT_PATH, &path);
1549 static int cmd_service_move_after(char *args[], int num,
1550 struct connman_option *options)
1552 const char *iface = "net.connman.Service";
1553 struct move_service *services;
1561 if (check_dbus_name(args[1]) == false)
1564 services = g_new(struct move_service, 1);
1566 services->service = g_strdup_printf("/net/connman/service/%s", args[1]);
1567 services->target = g_strdup_printf("/net/connman/service/%s", args[2]);
1569 return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
1570 services->service, iface, "MoveAfter",
1571 move_after_return, services,
1572 move_after_append_args,
1576 static int config_return(DBusMessageIter *iter, int errnum,
1577 const char *error, void *user_data)
1579 char *service_name = user_data;
1582 fprintf(stderr, "Error %s: %s\n", service_name, error);
1589 struct config_append {
1594 struct session_options {
1598 struct connman_option *options;
1601 static void config_append_ipv4(DBusMessageIter *iter,
1604 struct config_append *append = user_data;
1605 char **opts = append->opts;
1611 while (opts[i] && ipv4[i]) {
1612 __connmanctl_dbus_append_dict_entry(iter, ipv4[i],
1613 DBUS_TYPE_STRING, &opts[i]);
1620 static void config_append_ipv6(DBusMessageIter *iter, void *user_data)
1622 struct config_append *append = user_data;
1623 char **opts = append->opts;
1630 if (g_strcmp0(opts[0], "auto") == 0) {
1633 switch (parse_boolean(opts[1])) {
1638 __connmanctl_dbus_append_dict_entry(iter, "Privacy",
1639 DBUS_TYPE_STRING, &str);
1646 __connmanctl_dbus_append_dict_entry(iter, "Privacy",
1647 DBUS_TYPE_STRING, &str);
1654 if (g_strcmp0(opts[1], "prefered") != 0 &&
1656 "preferred") != 0) {
1657 fprintf(stderr, "Error %s: %s\n",
1664 __connmanctl_dbus_append_dict_entry(iter,
1665 "Privacy", DBUS_TYPE_STRING,
1670 } else if (g_strcmp0(opts[0], "manual") == 0) {
1673 while (opts[i] && ipv6[i]) {
1675 int value = atoi(opts[i]);
1676 __connmanctl_dbus_append_dict_entry(iter,
1677 ipv6[i], DBUS_TYPE_BYTE,
1680 __connmanctl_dbus_append_dict_entry(iter,
1681 ipv6[i], DBUS_TYPE_STRING,
1689 } else if (g_strcmp0(opts[0], "off") != 0) {
1690 fprintf(stderr, "Error %s: %s\n", opts[0], strerror(EINVAL));
1695 __connmanctl_dbus_append_dict_entry(iter, "Method", DBUS_TYPE_STRING,
1699 static void config_append_str(DBusMessageIter *iter, void *user_data)
1701 struct config_append *append = user_data;
1702 char **opts = append->opts;
1709 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
1717 static void append_servers(DBusMessageIter *iter, void *user_data)
1719 struct config_append *append = user_data;
1720 char **opts = append->opts;
1726 while (opts[i] && g_strcmp0(opts[i], "--excludes") != 0) {
1727 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
1735 static void append_excludes(DBusMessageIter *iter, void *user_data)
1737 struct config_append *append = user_data;
1738 char **opts = append->opts;
1739 int i = append->values;
1741 if (!opts || !opts[i] ||
1742 g_strcmp0(opts[i], "--excludes") != 0)
1747 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
1755 static void config_append_proxy(DBusMessageIter *iter, void *user_data)
1757 struct config_append *append = user_data;
1758 char **opts = append->opts;
1763 if (g_strcmp0(opts[0], "manual") == 0) {
1764 __connmanctl_dbus_append_dict_string_array(iter, "Servers",
1765 append_servers, append);
1767 __connmanctl_dbus_append_dict_string_array(iter, "Excludes",
1768 append_excludes, append);
1770 } else if (g_strcmp0(opts[0], "auto") == 0) {
1772 __connmanctl_dbus_append_dict_entry(iter, "URL",
1773 DBUS_TYPE_STRING, &opts[1]);
1777 } else if (g_strcmp0(opts[0], "direct") != 0)
1780 __connmanctl_dbus_append_dict_entry(iter, "Method",DBUS_TYPE_STRING,
1786 static int cmd_config(char *args[], int num, struct connman_option *options)
1788 int result = 0, res = 0, index = 2, oldindex = 0;
1790 char *service_name, *path;
1793 struct config_append append;
1795 service_name = args[1];
1799 if (check_dbus_name(service_name) == false)
1802 while (index < num && args[index]) {
1803 c = parse_args(args[index], options);
1804 opt_start = &args[index + 1];
1805 append.opts = opt_start;
1811 path = g_strdup_printf("/net/connman/service/%s", service_name);
1815 switch (parse_boolean(*opt_start)) {
1830 res = __connmanctl_dbus_set_property(connection,
1831 path, "net.connman.Service",
1833 g_strdup(service_name),
1835 DBUS_TYPE_BOOLEAN, &val);
1839 res = __connmanctl_dbus_set_property_dict(connection,
1840 path, "net.connman.Service",
1841 config_return, g_strdup(service_name),
1842 "IPv4.Configuration", DBUS_TYPE_STRING,
1843 config_append_ipv4, &append);
1844 index += append.values;
1848 res = __connmanctl_dbus_set_property_dict(connection,
1849 path, "net.connman.Service",
1850 config_return, g_strdup(service_name),
1851 "IPv6.Configuration", DBUS_TYPE_STRING,
1852 config_append_ipv6, &append);
1853 index += append.values;
1857 res = __connmanctl_dbus_set_property_array(connection,
1858 path, "net.connman.Service",
1859 config_return, g_strdup(service_name),
1860 "Nameservers.Configuration",
1861 DBUS_TYPE_STRING, config_append_str,
1863 index += append.values;
1867 res = __connmanctl_dbus_set_property_array(connection,
1868 path, "net.connman.Service",
1869 config_return, g_strdup(service_name),
1870 "Timeservers.Configuration",
1871 DBUS_TYPE_STRING, config_append_str,
1873 index += append.values;
1877 res = __connmanctl_dbus_set_property_array(connection,
1878 path, "net.connman.Service",
1879 config_return, g_strdup(service_name),
1880 "Domains.Configuration",
1881 DBUS_TYPE_STRING, config_append_str,
1883 index += append.values;
1887 res = __connmanctl_dbus_set_property_dict(connection,
1888 path, "net.connman.Service",
1889 config_return, g_strdup(service_name),
1890 "Proxy.Configuration",
1891 DBUS_TYPE_STRING, config_append_proxy,
1893 index += append.values;
1896 res = __connmanctl_dbus_method_call(connection,
1897 CONNMAN_SERVICE, path,
1898 "net.connman.Service", "Remove",
1899 config_return, g_strdup(service_name),
1904 switch (parse_boolean(*opt_start)) {
1916 res = __connmanctl_dbus_set_property(connection,
1917 path, "net.connman.Service",
1919 g_strdup(service_name),
1920 "mDNS.Configuration",
1921 DBUS_TYPE_BOOLEAN, &val);
1934 if (res == -EINPROGRESS)
1935 result = -EINPROGRESS;
1937 printf("Error '%s': %s\n", args[oldindex],
1948 static DBusHandlerResult monitor_changed(DBusConnection *connection,
1949 DBusMessage *message, void *user_data)
1951 DBusMessageIter iter;
1952 const char *interface, *path;
1954 interface = dbus_message_get_interface(message);
1956 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1958 if (strncmp(interface, "net.connman.", 12) != 0)
1959 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1961 if (!strcmp(interface, "net.connman.Agent") ||
1962 !strcmp(interface, "net.connman.vpn.Agent") ||
1963 !strcmp(interface, "net.connman.Session") ||
1964 !strcmp(interface, "net.connman.Notification"))
1965 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1967 interface = strrchr(interface, '.');
1968 if (interface && *interface != '\0')
1971 path = strrchr(dbus_message_get_path(message), '/');
1972 if (path && *path != '\0')
1975 __connmanctl_save_rl();
1977 if (dbus_message_is_signal(message, "net.connman.Manager",
1978 "ServicesChanged")) {
1980 fprintf(stdout, "%-12s %-20s = {\n", interface,
1982 dbus_message_iter_init(message, &iter);
1983 __connmanctl_services_list(&iter);
1984 fprintf(stdout, "\n}\n");
1986 __connmanctl_redraw_rl();
1988 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1989 } else if (dbus_message_is_signal(message, "net.connman.Manager",
1991 fprintf(stdout, "%-12s %-20s = {\n", interface,
1993 dbus_message_iter_init(message, &iter);
1994 __connmanctl_peers_list(&iter);
1995 fprintf(stdout, "\n}\n");
1997 __connmanctl_redraw_rl();
1999 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2000 } else if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
2001 "ConnectionAdded") ||
2002 dbus_message_is_signal(message,
2003 "net.connman.vpn.Manager",
2004 "ConnectionRemoved")) {
2005 interface = "vpn.Manager";
2006 path = dbus_message_get_member(message);
2008 } else if (dbus_message_is_signal(message, "net.connman.Manager",
2009 "TechnologyAdded") ||
2010 dbus_message_is_signal(message, "net.connman.Manager",
2011 "TechnologyRemoved"))
2012 path = dbus_message_get_member(message);
2014 fprintf(stdout, "%-12s %-20s ", interface, path);
2015 dbus_message_iter_init(message, &iter);
2017 __connmanctl_dbus_print(&iter, "", " = ", " = ");
2018 fprintf(stdout, "\n");
2020 __connmanctl_redraw_rl();
2022 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2029 { "Service", false },
2030 { "Technology", false },
2031 { "Manager", false },
2032 { "vpn.Manager", false },
2033 { "vpn.Connection", false },
2037 static void monitor_add(char *interface)
2039 bool add_filter = true, found = false;
2044 for (i = 0; monitor[i].interface; i++) {
2045 if (monitor[i].enabled == true)
2048 if (g_strcmp0(interface, monitor[i].interface) == 0) {
2049 if (monitor[i].enabled == true)
2052 monitor[i].enabled = true;
2060 if (add_filter == true)
2061 dbus_connection_add_filter(connection, monitor_changed,
2064 dbus_error_init(&err);
2065 rule = g_strdup_printf("type='signal',interface='net.connman.%s'",
2067 dbus_bus_add_match(connection, rule, &err);
2070 if (dbus_error_is_set(&err))
2071 fprintf(stderr, "Error: %s\n", err.message);
2074 static void monitor_del(char *interface)
2076 bool del_filter = true, found = false;
2080 for (i = 0; monitor[i].interface; i++) {
2081 if (g_strcmp0(interface, monitor[i].interface) == 0) {
2082 if (monitor[i].enabled == false)
2085 monitor[i].enabled = false;
2089 if (monitor[i].enabled == true)
2096 rule = g_strdup_printf("type='signal',interface='net.connman.%s'",
2098 dbus_bus_remove_match(connection, rule, NULL);
2101 if (del_filter == true)
2102 dbus_connection_remove_filter(connection, monitor_changed,
2106 static int cmd_monitor(char *args[], int num, struct connman_option *options)
2115 switch (parse_boolean(args[2])) {
2125 c = parse_args(args[1], options);
2128 monitor_add("Service");
2129 monitor_add("Technology");
2130 monitor_add("Manager");
2131 monitor_add("vpn.Manager");
2132 monitor_add("vpn.Connection");
2137 monitor_add("Service");
2139 monitor_del("Service");
2144 monitor_add("Technology");
2146 monitor_del("Technology");
2151 monitor_add("Manager");
2153 monitor_del("Manager");
2158 monitor_add("vpn.Manager");
2160 monitor_del("vpn.Manager");
2165 monitor_add("vpn.Connection");
2167 monitor_del("vpn.Connection");
2171 switch(parse_boolean(args[1])) {
2173 monitor_del("Service");
2174 monitor_del("Technology");
2175 monitor_del("Manager");
2176 monitor_del("vpn.Manager");
2177 monitor_del("vpn.Connection");
2181 monitor_add("Service");
2182 monitor_add("Technology");
2183 monitor_add("Manager");
2184 monitor_add("vpn.Manager");
2185 monitor_add("vpn.Connection");
2194 return -EINPROGRESS;
2199 static int cmd_agent(char *args[], int num, struct connman_option *options)
2201 if (!__connmanctl_is_interactive()) {
2202 fprintf(stderr, "Error: Not supported in non-interactive "
2213 switch(parse_boolean(args[1])) {
2215 __connmanctl_agent_unregister(connection);
2219 if (__connmanctl_agent_register(connection) == -EINPROGRESS)
2220 return -EINPROGRESS;
2232 static int vpnconnections_properties(DBusMessageIter *iter, int errnum,
2233 const char *error, void *user_data)
2235 char *path = user_data;
2237 DBusMessageIter dict;
2240 fprintf(stdout, "%s\n", path);
2242 dbus_message_iter_recurse(iter, &dict);
2243 __connmanctl_dbus_print(&dict, " ", " = ", "\n");
2245 fprintf(stdout, "\n");
2248 str = strrchr(path, '/');
2254 fprintf(stderr, "Error %s: %s\n", str, error);
2262 static int vpnconnections_list(DBusMessageIter *iter, int errnum,
2263 const char *error, void *user_data)
2266 __connmanctl_vpnconnections_list(iter);
2268 fprintf(stderr, "Error: %s\n", error);
2273 static int cmd_vpnconnections(char *args[], int num,
2274 struct connman_option *options)
2276 char *vpnconnection_name, *path;
2281 vpnconnection_name = args[1];
2283 if (!vpnconnection_name)
2284 return __connmanctl_dbus_method_call(connection,
2285 VPN_SERVICE, VPN_PATH,
2286 "net.connman.vpn.Manager", "GetConnections",
2287 vpnconnections_list, NULL,
2290 if (check_dbus_name(vpnconnection_name) == false)
2293 path = g_strdup_printf("/net/connman/vpn/connection/%s",
2294 vpnconnection_name);
2295 return __connmanctl_dbus_method_call(connection, VPN_SERVICE, path,
2296 "net.connman.vpn.Connection", "GetProperties",
2297 vpnconnections_properties, path, NULL, NULL);
2301 static int cmd_vpnagent(char *args[], int num, struct connman_option *options)
2303 if (!__connmanctl_is_interactive()) {
2304 fprintf(stderr, "Error: Not supported in non-interactive "
2315 switch(parse_boolean(args[1])) {
2317 __connmanctl_vpn_agent_unregister(connection);
2321 if (__connmanctl_vpn_agent_register(connection) ==
2323 return -EINPROGRESS;
2335 static DBusMessage *session_release(DBusConnection *connection,
2336 DBusMessage *message, void *user_data)
2338 __connmanctl_save_rl();
2340 fprintf(stdout, "Session %s released\n", session_path);
2342 __connmanctl_redraw_rl();
2344 g_free(session_path);
2345 session_path = NULL;
2346 session_connected = false;
2348 return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
2351 static DBusMessage *session_update(DBusConnection *connection,
2352 DBusMessage *message, void *user_data)
2354 DBusMessageIter iter, dict;
2356 __connmanctl_save_rl();
2358 fprintf(stdout, "Session Update = {\n");
2360 dbus_message_iter_init(message, &iter);
2361 dbus_message_iter_recurse(&iter, &dict);
2363 __connmanctl_dbus_print(&dict, "", " = ", "\n");
2364 fprintf(stdout, "\n}\n");
2366 dbus_message_iter_recurse(&iter, &dict);
2368 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2369 DBusMessageIter entry, variant;
2370 char *field, *state;
2372 dbus_message_iter_recurse(&dict, &entry);
2374 dbus_message_iter_get_basic(&entry, &field);
2376 if (dbus_message_iter_get_arg_type(&entry)
2378 && !strcmp(field, "State")) {
2380 dbus_message_iter_next(&entry);
2381 dbus_message_iter_recurse(&entry, &variant);
2382 if (dbus_message_iter_get_arg_type(&variant)
2383 != DBUS_TYPE_STRING)
2386 dbus_message_iter_get_basic(&variant, &state);
2388 if (!session_connected && (!strcmp(state, "connected")
2389 || !strcmp(state, "online"))) {
2391 fprintf(stdout, "Session %s connected\n",
2393 session_connected = true;
2398 if (!strcmp(state, "disconnected") &&
2399 session_connected) {
2401 fprintf(stdout, "Session %s disconnected\n",
2403 session_connected = false;
2408 dbus_message_iter_next(&dict);
2411 __connmanctl_redraw_rl();
2413 return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
2416 static const GDBusMethodTable notification_methods[] = {
2417 { GDBUS_METHOD("Release", NULL, NULL, session_release) },
2418 { GDBUS_METHOD("Update", GDBUS_ARGS({"settings", "a{sv}"}),
2419 NULL, session_update) },
2423 static int session_notify_add(const char *path)
2425 if (session_notify_path)
2428 if (!g_dbus_register_interface(connection, path,
2429 "net.connman.Notification",
2430 notification_methods, NULL, NULL,
2432 fprintf(stderr, "Error: Failed to register VPN Agent "
2437 session_notify_path = g_strdup(path);
2442 static void session_notify_remove(void)
2444 if (!session_notify_path)
2447 g_dbus_unregister_interface(connection, session_notify_path,
2448 "net.connman.Notification");
2450 g_free(session_notify_path);
2451 session_notify_path = NULL;
2454 static int session_connect_cb(DBusMessageIter *iter, int errnum,
2455 const char *error, void *user_data)
2458 fprintf(stderr, "Error: %s\n", error);
2462 return -EINPROGRESS;
2465 static int session_connect(void)
2467 return __connmanctl_dbus_method_call(connection, "net.connman",
2468 session_path, "net.connman.Session", "Connect",
2469 session_connect_cb, NULL, NULL, NULL);
2472 static int session_disconnect_cb(DBusMessageIter *iter, int errnum,
2473 const char *error, void *user_data)
2476 fprintf(stderr, "Error: %s\n", error);
2481 static int session_disconnect(void)
2483 return __connmanctl_dbus_method_call(connection, "net.connman",
2484 session_path, "net.connman.Session", "Disconnect",
2485 session_disconnect_cb, NULL, NULL, NULL);
2488 static int session_create_cb(DBusMessageIter *iter, int errnum,
2489 const char *error, void *user_data)
2491 gboolean connect = GPOINTER_TO_INT(user_data);
2495 fprintf(stderr, "Error creating session: %s", error);
2496 session_notify_remove();
2500 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH) {
2501 fprintf(stderr, "Error creating session: No session path\n");
2505 g_free(session_path);
2507 dbus_message_iter_get_basic(iter, &str);
2508 session_path = g_strdup(str);
2510 fprintf(stdout, "Session %s created\n", session_path);
2513 return session_connect();
2515 return -EINPROGRESS;
2518 static void session_config_append_array(DBusMessageIter *iter,
2521 struct config_append *append = user_data;
2522 char **opts = append->opts;
2528 while (opts[i] && strncmp(opts[i], "--", 2) != 0) {
2529 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2537 static void session_create_append_dict(DBusMessageIter *iter, void *user_data)
2539 struct session_options *args_struct = user_data;
2540 int index = 0, res = 0;
2541 struct config_append append;
2544 dbus_bool_t source_ip_rule;
2546 while (index < args_struct->num && args_struct->args[index]) {
2547 append.opts = &args_struct->args[index];
2550 c = parse_args(args_struct->args[index], args_struct->options);
2554 __connmanctl_dbus_append_dict_string_array(iter, "AllowedBearers",
2555 session_config_append_array,
2559 if (! args_struct->args[index + 1]) {
2563 __connmanctl_dbus_append_dict_entry(iter, "ConnectionType",
2565 &args_struct->args[index + 1]);
2569 if (index + 1 < args_struct->num)
2570 ifname = args_struct->args[index + 1];
2573 __connmanctl_dbus_append_dict_entry(iter, "AllowedInterface",
2579 if (! args_struct->args[index + 1]) {
2583 switch (parse_boolean( args_struct->args[index + 1])) {
2585 source_ip_rule = TRUE;
2588 source_ip_rule = FALSE;
2594 __connmanctl_dbus_append_dict_entry(iter, "SourceIPRule",
2600 if (!args_struct->args[index + 1]) {
2604 __connmanctl_dbus_append_dict_entry(iter, "ContextIdentifier",
2606 &args_struct->args[index + 1]);
2613 if (res < 0 && res != -EINPROGRESS) {
2614 printf("Error '%s': %s\n", args_struct->args[index],
2619 index += append.values;
2623 static void session_create_append(DBusMessageIter *iter, void *user_data)
2625 struct session_options *args_struct = user_data;
2627 __connmanctl_dbus_append_dict(iter, session_create_append_dict,
2630 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
2631 &args_struct->notify_path);
2634 static int session_create(gboolean connect, char *args[], int num,
2635 struct connman_option *options)
2639 struct session_options args_struct;
2640 args_struct.args = args;
2641 args_struct.num = num;
2642 args_struct.options = options;
2644 notify_path = g_strdup_printf("/net/connman/connmanctl%d", getpid());
2645 session_notify_add(notify_path);
2646 args_struct.notify_path = notify_path;
2648 res = __connmanctl_dbus_method_call(connection, "net.connman", "/",
2649 "net.connman.Manager", "CreateSession",
2650 session_create_cb, GINT_TO_POINTER(connect),
2651 session_create_append, &args_struct);
2653 g_free(notify_path);
2655 if (res < 0 && res != -EINPROGRESS)
2656 session_notify_remove();
2661 static int session_destroy_cb(DBusMessageIter *iter, int errnum,
2662 const char *error, void *user_data)
2665 fprintf(stderr, "Error destroying session: %s", error);
2669 fprintf(stdout, "Session %s ended\n", session_path);
2671 g_free(session_path);
2672 session_path = NULL;
2673 session_connected = false;
2678 static void session_destroy_append(DBusMessageIter *iter, void *user_data)
2680 const char *path = user_data;
2682 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
2685 static int session_destroy(void)
2687 return __connmanctl_dbus_method_call(connection, "net.connman", "/",
2688 "net.connman.Manager", "DestroySession",
2689 session_destroy_cb, NULL,
2690 session_destroy_append, session_path);
2693 static int session_config_return(DBusMessageIter *iter, int errnum,
2694 const char *error, void *user_data)
2696 char *property_name = user_data;
2699 fprintf(stderr, "Error setting session %s: %s\n",
2700 property_name, error);
2705 static int session_config(char *args[], int num,
2706 struct connman_option *options)
2708 int index = 0, res = 0;
2709 struct config_append append;
2712 dbus_bool_t source_ip_rule;
2714 while (index < num && args[index]) {
2715 append.opts = &args[index];
2718 c = parse_args(args[index], options);
2722 res = __connmanctl_dbus_session_change_array(connection,
2723 session_path, session_config_return,
2724 "AllowedBearers", "AllowedBearers",
2725 session_config_append_array, &append);
2728 if (!args[index + 1]) {
2733 res = __connmanctl_dbus_session_change(connection,
2734 session_path, session_config_return,
2735 "ConnectionType", "ConnectionType",
2736 DBUS_TYPE_STRING, &args[index + 1]);
2740 if (index + 1 < num)
2741 ifname = args[index + 1];
2745 res = __connmanctl_dbus_session_change(connection,
2746 session_path, session_config_return,
2747 "AllowedInterface", "AllowedInterface",
2748 DBUS_TYPE_STRING, &ifname);
2752 if (!args[index + 1]) {
2756 switch (parse_boolean(args[index + 1])) {
2758 source_ip_rule = TRUE;
2761 source_ip_rule = FALSE;
2768 res = __connmanctl_dbus_session_change(connection,
2769 session_path, session_config_return,
2770 "SourceIPRule", "SourceIPRule",
2771 DBUS_TYPE_BOOLEAN, &source_ip_rule);
2775 if (!args[index + 1]) {
2780 res = __connmanctl_dbus_session_change(connection,
2781 session_path, session_config_return,
2782 "ctxid", "ctxid", DBUS_TYPE_STRING,
2791 if (res < 0 && res != -EINPROGRESS) {
2792 printf("Error '%s': %s\n", args[index],
2797 index += append.values;
2803 static int cmd_session(char *args[], int num, struct connman_option *options)
2812 switch(parse_boolean(command)) {
2816 return session_destroy();
2821 return session_create(FALSE, &args[2], num - 2, options);
2824 if (!strcmp(command, "connect")) {
2826 return session_create(TRUE, &args[2], num - 2,
2829 return session_connect();
2831 } else if (!strcmp(command, "disconnect")) {
2833 if (!session_path) {
2834 fprintf(stdout, "Session does not exist\n");
2838 return session_disconnect();
2839 } else if (!strcmp(command, "config")) {
2840 if (!session_path) {
2841 fprintf(stdout, "Session does not exist\n");
2848 return session_config(&args[2], num - 2, options);
2856 static int cmd_exit(char *args[], int num, struct connman_option *options)
2861 static char *lookup_key_from_table(GHashTable *hash, const char *text,
2865 static GHashTableIter iter;
2866 gpointer key, value;
2869 g_hash_table_iter_init(&iter, hash);
2873 while (g_hash_table_iter_next(&iter, &key, &value))
2874 if (strncmp(text, key, len) == 0)
2880 static char *lookup_service_arg(const char *text, int state)
2882 if (__connmanctl_input_calc_level() > 1) {
2883 __connmanctl_input_lookup_end();
2887 return lookup_key_from_table(service_hash, text, state);
2890 static char *lookup_peer(const char *text, int state)
2892 static GHashTableIter iter;
2893 gpointer key, value;
2897 g_hash_table_iter_init(&iter, peer_hash);
2901 while (g_hash_table_iter_next(&iter, &key, &value)) {
2902 const char *peer = key;
2903 if (strncmp(text, peer, len) == 0)
2904 return strdup(peer);
2910 static char *lookup_peer_arg(const char *text, int state)
2912 if (__connmanctl_input_calc_level() > 1) {
2913 __connmanctl_input_lookup_end();
2917 return lookup_peer(text, state);
2920 static char *lookup_technology(const char *text, int state)
2923 static GHashTableIter iter;
2924 gpointer key, value;
2927 g_hash_table_iter_init(&iter, technology_hash);
2931 while (g_hash_table_iter_next(&iter, &key, &value)) {
2932 const char *technology = key;
2933 if (strncmp(text, technology, len) == 0)
2934 return strdup(technology);
2940 static char *lookup_technology_arg(const char *text, int state)
2942 if (__connmanctl_input_calc_level() > 1) {
2943 __connmanctl_input_lookup_end();
2947 return lookup_technology(text, state);
2950 static char *lookup_technology_offline(const char *text, int state)
2953 static bool end = false;
2956 if (__connmanctl_input_calc_level() > 1) {
2957 __connmanctl_input_lookup_end();
2969 str = lookup_technology(text, state);
2975 if (strncmp(text, "offline", len) == 0)
2976 return strdup("offline");
2981 static char *lookup_on_off(const char *text, int state)
2983 char *onoff[] = { "on", "off", NULL };
2994 while (onoff[idx]) {
2998 if (!strncmp(text, str, len))
3005 static char *lookup_tether(const char *text, int state)
3009 level = __connmanctl_input_calc_level();
3011 return lookup_technology(text, state);
3014 return lookup_on_off(text, state);
3016 __connmanctl_input_lookup_end();
3021 static char *lookup_agent(const char *text, int state)
3023 if (__connmanctl_input_calc_level() > 1) {
3024 __connmanctl_input_lookup_end();
3028 return lookup_on_off(text, state);
3031 static char *lookup_vpnconnection_arg(const char *text, int state)
3033 if (__connmanctl_input_calc_level() > 1) {
3034 __connmanctl_input_lookup_end();
3038 return lookup_key_from_table(vpnconnection_hash, text, state);
3041 static struct connman_option service_options[] = {
3042 {"properties", 'p', "[<service>] (obsolete)"},
3046 #if defined TIZEN_EXT
3047 static struct connman_option ins_options[] = {
3049 {"filter-ssid", 's', "ssid"},
3050 {"filter-name", 'n', "[<service_name>]"},
3055 static struct connman_option config_options[] = {
3056 #if defined TIZEN_EXT
3057 {"nameservers", 'n', "ipv4.manual|ipv4.dhcp|ipv6.manual|ipv6.dhcp\n"
3058 "\t\t\t<dns1> [<dns2>] [<dns3>]"},
3060 {"nameservers", 'n', "<dns1> [<dns2>] [<dns3>]"},
3062 {"timeservers", 't', "<ntp1> [<ntp2>] [...]"},
3063 {"domains", 'd', "<domain1> [<domain2>] [...]"},
3064 {"mdns", 'm', "yes|no"},
3065 {"ipv6", 'v', "off|auto [enable|disable|preferred]|\n"
3066 "\t\t\tmanual <address> <prefixlength> <gateway>"},
3067 {"proxy", 'x', "direct|auto <URL>|manual <URL1> [<URL2>] [...]\n"
3068 "\t\t\t[exclude <exclude1> [<exclude2>] [...]]"},
3069 {"autoconnect", 'a', "yes|no"},
3070 {"ipv4", 'i', "off|dhcp|manual <address> <netmask> <gateway>"},
3071 {"remove", 'r', " Remove service"},
3075 static struct connman_option monitor_options[] = {
3076 {"services", 's', "[off] Monitor only services"},
3077 {"tech", 'c', "[off] Monitor only technologies"},
3078 {"manager", 'm', "[off] Monitor only manager interface"},
3079 {"vpnmanager", 'M', "[off] Monitor only VPN manager "
3081 {"vpnconnection", 'C', "[off] Monitor only VPN "
3086 static struct connman_option session_options[] = {
3087 {"bearers", 'b', "<technology1> [<technology2> [...]]"},
3088 {"type", 't', "local|internet|any"},
3089 {"ifname", 'i', "[<interface_name>]"},
3090 {"srciprule", 's', "yes|no"},
3091 {"ctxid", 'c', "<context_identifier>"},
3095 #if defined TIZEN_EXT_WIFI_MESH
3096 static struct connman_option mesh_options[] = {
3097 {"ifadd", 'a', "<ifname> <wifi_ifname>\n"
3098 " [bridge_ifname] Add Virtual Mesh "
3100 {"ifrmv", 'r', "<ifname> Remove Virtual Mesh "
3102 {"peers", 'p', "[peer] Display Mesh peer "
3104 {"connect", 'c', "<peer> Connect Mesh Peer"},
3105 {"disconnect", 'd', "<peer> Disconnect Mesh Peer"},
3106 {"remove", 'f', "<peer> Forget Mesh Peer"},
3107 {"connected_peers", 'C', "[] Displays connected"
3108 " Peer informations"},
3109 {"disconnected_peers", 'D', "[] Displays "
3110 "Disconnected Peer informations"},
3111 {"create_network", 'n', "<name> <frequency> <sec_type> Create New Mesh "
3113 {"abort_scan", 'A', " Abort ongoing mesh "
3115 {"specific_scan", 'S', "<name> <frequency> Create New Mesh "
3117 {"config", 'P', "<peer> Set Mesh Network "
3118 "Configurations\n Passphrase <passphrase>"},
3119 {"set_gate", 'G', "<gate_ann> <rootmode> <stp> Set Mesh Gate "
3121 {"add_peer", 'z', "<addr> Add Mesh Peer"},
3122 {"remove_peer", 'y', "<addr> Remove Mesh Peer"},
3127 static char *lookup_options(struct connman_option *options, const char *text,
3139 while (options[idx].name) {
3140 str = options[idx].name;
3143 if (str && strncmp(text, str, len) == 0)
3150 static char *lookup_monitor(const char *text, int state)
3154 level = __connmanctl_input_calc_level();
3157 return lookup_options(monitor_options, text, state);
3160 return lookup_on_off(text, state);
3162 __connmanctl_input_lookup_end();
3166 static char *lookup_config(const char *text, int state)
3168 if (__connmanctl_input_calc_level() < 2)
3169 return lookup_key_from_table(service_hash, text, state);
3171 return lookup_options(config_options, text, state);
3174 static char *lookup_session(const char *text, int state)
3176 return lookup_options(session_options, text, state);
3179 #if defined TIZEN_EXT_WIFI_MESH
3180 static char *lookup_mesh(const char *text, int state)
3182 return lookup_options(mesh_options, text, state);
3186 static int peer_service_cb(DBusMessageIter *iter, int errnum,
3187 const char *error, void *user_data)
3189 bool registration = GPOINTER_TO_INT(user_data);
3192 fprintf(stderr, "Error %s peer service: %s\n",
3193 registration ? "registering" : "unregistering", error);
3195 fprintf(stdout, "Peer service %s\n",
3196 registration ? "registered" : "unregistered");
3201 struct _peer_service {
3202 unsigned char *bjr_query;
3204 unsigned char *bjr_response;
3205 int bjr_response_len;
3206 unsigned char *wfd_ies;
3213 static void append_dict_entry_fixed_array(DBusMessageIter *iter,
3214 const char *property, void *value, int length)
3216 DBusMessageIter dict_entry, variant, array;
3218 dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY,
3220 dbus_message_iter_append_basic(&dict_entry, DBUS_TYPE_STRING,
3222 dbus_message_iter_open_container(&dict_entry, DBUS_TYPE_VARIANT,
3223 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING,
3225 dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
3226 DBUS_TYPE_BYTE_AS_STRING, &array);
3227 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
3229 dbus_message_iter_close_container(&variant, &array);
3230 dbus_message_iter_close_container(&dict_entry, &variant);
3231 dbus_message_iter_close_container(iter, &dict_entry);
3234 static void append_peer_service_dict(DBusMessageIter *iter, void *user_data)
3236 struct _peer_service *service = user_data;
3238 if (service->bjr_query && service->bjr_response) {
3239 append_dict_entry_fixed_array(iter, "BonjourQuery",
3240 &service->bjr_query, service->bjr_query_len);
3241 append_dict_entry_fixed_array(iter, "BonjourResponse",
3242 &service->bjr_response, service->bjr_response_len);
3243 } else if (service->upnp_service && service->version) {
3244 __connmanctl_dbus_append_dict_entry(iter, "UpnpVersion",
3245 DBUS_TYPE_INT32, &service->version);
3246 __connmanctl_dbus_append_dict_entry(iter, "UpnpService",
3247 DBUS_TYPE_STRING, &service->upnp_service);
3248 } else if (service->wfd_ies) {
3249 append_dict_entry_fixed_array(iter, "WiFiDisplayIEs",
3250 &service->wfd_ies, service->wfd_ies_len);
3254 static void peer_service_append(DBusMessageIter *iter, void *user_data)
3256 struct _peer_service *service = user_data;
3259 __connmanctl_dbus_append_dict(iter, append_peer_service_dict, service);
3261 if (service->master < 0)
3264 master = service->master == 1 ? TRUE : FALSE;
3265 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &master);
3268 static struct _peer_service *fill_in_peer_service(unsigned char *bjr_query,
3269 int bjr_query_len, unsigned char *bjr_response,
3270 int bjr_response_len, char *upnp_service,
3271 int version, unsigned char *wfd_ies,
3274 struct _peer_service *service;
3276 service = dbus_malloc0(sizeof(*service));
3278 #if defined TIZEN_EXT
3283 if (bjr_query_len && bjr_response_len) {
3284 service->bjr_query = dbus_malloc0(bjr_query_len);
3285 #if defined TIZEN_EXT
3286 if(!service->bjr_query) {
3291 memcpy(service->bjr_query, bjr_query, bjr_query_len);
3292 service->bjr_query_len = bjr_query_len;
3294 service->bjr_response = dbus_malloc0(bjr_response_len);
3295 #if defined TIZEN_EXT
3296 if(!service->bjr_response) {
3297 dbus_free(service->bjr_query);
3302 memcpy(service->bjr_response, bjr_response, bjr_response_len);
3303 service->bjr_response_len = bjr_response_len;
3304 } else if (upnp_service && version) {
3305 service->upnp_service = strdup(upnp_service);
3306 service->version = version;
3307 } else if (wfd_ies && wfd_ies_len) {
3308 service->wfd_ies = dbus_malloc0(wfd_ies_len);
3309 #if defined TIZEN_EXT
3310 if (!service->wfd_ies) {
3315 memcpy(service->wfd_ies, wfd_ies, wfd_ies_len);
3316 service->wfd_ies_len = wfd_ies_len;
3325 static void free_peer_service(struct _peer_service *service)
3327 dbus_free(service->bjr_query);
3328 dbus_free(service->bjr_response);
3329 dbus_free(service->wfd_ies);
3330 free(service->upnp_service);
3334 static int peer_service_register(unsigned char *bjr_query, int bjr_query_len,
3335 unsigned char *bjr_response, int bjr_response_len,
3336 char *upnp_service, int version,
3337 unsigned char *wfd_ies, int wfd_ies_len, int master)
3339 struct _peer_service *service;
3340 bool registration = true;
3343 service = fill_in_peer_service(bjr_query, bjr_query_len, bjr_response,
3344 bjr_response_len, upnp_service, version,
3345 wfd_ies, wfd_ies_len);
3349 service->master = master;
3351 ret = __connmanctl_dbus_method_call(connection, "net.connman", "/",
3352 "net.connman.Manager", "RegisterPeerService",
3353 peer_service_cb, GINT_TO_POINTER(registration),
3354 peer_service_append, service);
3356 free_peer_service(service);
3361 static int peer_service_unregister(unsigned char *bjr_query, int bjr_query_len,
3362 unsigned char *bjr_response, int bjr_response_len,
3363 char *upnp_service, int version,
3364 unsigned char *wfd_ies, int wfd_ies_len)
3366 struct _peer_service *service;
3367 bool registration = false;
3370 service = fill_in_peer_service(bjr_query, bjr_query_len, bjr_response,
3371 bjr_response_len, upnp_service, version,
3372 wfd_ies, wfd_ies_len);
3376 service->master = -1;
3378 ret = __connmanctl_dbus_method_call(connection, "net.connman", "/",
3379 "net.connman.Manager", "UnregisterPeerService",
3380 peer_service_cb, GINT_TO_POINTER(registration),
3381 peer_service_append, service);
3383 free_peer_service(service);
3388 static int parse_spec_array(char *command, unsigned char spec[1024])
3390 int length, pos, end;
3394 end = strlen(command);
3395 for (e = NULL, length = pos = 0; command[pos] != '\0'; length++) {
3399 b[0] = command[pos];
3400 b[1] = command[pos+1];
3402 spec[length] = strtol(b, &e, 16);
3403 if (e && *e != '\0')
3412 static int cmd_peer_service(char *args[], int num,
3413 struct connman_option *options)
3415 unsigned char bjr_query[1024] = {};
3416 unsigned char bjr_response[1024] = {};
3417 unsigned char wfd_ies[1024] = {};
3418 char *upnp_service = NULL;
3419 int bjr_query_len = 0, bjr_response_len = 0;
3420 int version = 0, master = 0, wfd_ies_len = 0;
3426 if (!strcmp(args[2], "wfd_ies")) {
3427 wfd_ies_len = parse_spec_array(args[3], wfd_ies);
3428 if (wfd_ies_len == -EINVAL)
3438 if (!strcmp(args[2], "bjr_query")) {
3439 if (strcmp(args[4], "bjr_response"))
3441 bjr_query_len = parse_spec_array(args[3], bjr_query);
3442 bjr_response_len = parse_spec_array(args[5], bjr_response);
3444 if (bjr_query_len == -EINVAL || bjr_response_len == -EINVAL)
3446 } else if (!strcmp(args[2], "upnp_service")) {
3449 if (strcmp(args[4], "upnp_version"))
3451 upnp_service = args[3];
3452 version = strtol(args[5], &e, 10);
3459 master = parse_boolean(args[6]);
3464 if (!strcmp(args[1], "register")) {
3465 return peer_service_register(bjr_query, bjr_query_len,
3466 bjr_response, bjr_response_len, upnp_service,
3467 version, wfd_ies, wfd_ies_len, master);
3468 } else if (!strcmp(args[1], "unregister")) {
3469 return peer_service_unregister(bjr_query, bjr_query_len,
3470 bjr_response, bjr_response_len, upnp_service,
3471 version, wfd_ies, wfd_ies_len);
3477 static const struct {
3479 const char *argument;
3480 struct connman_option *options;
3481 int (*func) (char *args[], int num, struct connman_option *options);
3483 __connmanctl_lookup_cb cb;
3485 { "state", NULL, NULL, cmd_state,
3486 "Shows if the system is online or offline", NULL },
3487 { "technologies", NULL, NULL, cmd_technologies,
3488 "Display technologies", NULL },
3489 { "clock", NULL, NULL, cmd_clock,
3490 "Get System Clock Properties", NULL },
3491 { "enable", "<technology>|offline", NULL, cmd_enable,
3492 "Enables given technology or offline mode",
3493 lookup_technology_offline },
3494 { "disable", "<technology>|offline", NULL, cmd_disable,
3495 "Disables given technology or offline mode",
3496 lookup_technology_offline },
3497 #if defined TIZEN_EXT_WIFI_MESH
3498 { "mesh", "", mesh_options, cmd_mesh, "Mesh specific commands",
3501 { "tether", "<technology> on|off\n"
3502 " wifi [on|off] <ssid> <passphrase> [<freq>] ",
3504 "Enable, disable tethering, set SSID and passphrase for wifi",
3506 { "tethering_clients", NULL, NULL, cmd_tethering_clients,
3507 "Display tethering clients", NULL },
3508 { "services", "[<service>]", service_options, cmd_services,
3509 "Display services", lookup_service_arg },
3510 #if defined TIZEN_EXT
3511 { "ins", NULL, ins_options, cmd_ins,
3512 "Display intelligent network selection", NULL },
3514 { "peers", "[peer]", NULL, cmd_peers,
3515 "Display peers", lookup_peer_arg },
3516 { "scan", "<technology>", NULL, cmd_scan,
3517 "Scans for new services for given technology",
3518 lookup_technology_arg },
3519 { "connect", "<service/peer>", NULL, cmd_connect,
3520 "Connect a given service or peer", lookup_service_arg },
3521 { "disconnect", "<service/peer>", NULL, cmd_disconnect,
3522 "Disconnect a given service or peer", lookup_service_arg },
3523 { "move-before", "<service> <target service> ", NULL,
3524 cmd_service_move_before, "Move <service> before <target service>",
3525 lookup_service_arg },
3526 { "move-after", "<service> <target service> ", NULL,
3527 cmd_service_move_after, "Move <service> after <target service>",
3528 lookup_service_arg },
3529 { "config", "<service>", config_options, cmd_config,
3530 "Set service configuration options", lookup_config },
3531 { "monitor", "[off]", monitor_options, cmd_monitor,
3532 "Monitor signals from interfaces", lookup_monitor },
3533 { "agent", "on|off", NULL, cmd_agent,
3534 "Agent mode", lookup_agent },
3535 { "vpnconnections", "[<connection>]", NULL, cmd_vpnconnections,
3536 "Display VPN connections", lookup_vpnconnection_arg },
3537 { "vpnagent", "on|off", NULL, cmd_vpnagent,
3538 "VPN Agent mode", lookup_agent },
3539 { "session", "on|off|connect|disconnect|config", session_options,
3540 cmd_session, "Enable or disable a session", lookup_session },
3541 { "peer_service", "register|unregister <specs> <master>\n"
3542 "Where specs are:\n"
3543 "\tbjr_query <query> bjr_response <response>\n"
3544 "\tupnp_service <service> upnp_version <version>\n"
3545 "\twfd_ies <ies>\n", NULL,
3546 cmd_peer_service, "(Un)Register a Peer Service", NULL },
3547 { "help", NULL, NULL, cmd_help,
3548 "Show help", NULL },
3549 { "exit", NULL, NULL, cmd_exit,
3551 { "quit", NULL, NULL, cmd_exit,
3556 static int cmd_help(char *args[], int num, struct connman_option *options)
3558 bool interactive = __connmanctl_is_interactive();
3561 if (interactive == false)
3562 fprintf(stdout, "Usage: connmanctl [[command] [args]]\n");
3564 for (i = 0; cmd_table[i].cmd; i++) {
3565 const char *cmd = cmd_table[i].cmd;
3566 const char *argument = cmd_table[i].argument;
3567 const char *desc = cmd_table[i].desc;
3569 printf("%-16s%-22s%s\n", cmd? cmd: "",
3570 argument? argument: "",
3573 if (cmd_table[i].options) {
3574 for (j = 0; cmd_table[i].options[j].name;
3576 const char *options_desc =
3577 cmd_table[i].options[j].desc ?
3578 cmd_table[i].options[j].desc: "";
3580 printf(" --%-16s%s\n",
3581 cmd_table[i].options[j].name,
3587 if (interactive == false)
3588 fprintf(stdout, "\nNote: arguments and output are considered "
3589 "EXPERIMENTAL for now.\n");
3594 __connmanctl_lookup_cb __connmanctl_get_lookup_func(const char *text)
3596 int i, cmdlen, textlen;
3601 textlen = strlen(text);
3603 for (i = 0; cmd_table[i].cmd; i++) {
3604 cmdlen = strlen(cmd_table[i].cmd);
3606 if (textlen > cmdlen && text[cmdlen] != ' ')
3609 if (strncmp(cmd_table[i].cmd, text, cmdlen) == 0)
3610 return cmd_table[i].cb;
3616 int __connmanctl_commands(DBusConnection *dbus_conn, char *argv[], int argc)
3620 connection = dbus_conn;
3622 for (i = 0; cmd_table[i].cmd; i++) {
3623 if (g_strcmp0(cmd_table[i].cmd, argv[0]) == 0 &&
3624 cmd_table[i].func) {
3625 result = cmd_table[i].func(argv, argc,
3626 cmd_table[i].options);
3627 if (result < 0 && result != -EINPROGRESS)
3628 fprintf(stderr, "Error '%s': %s\n", argv[0],
3634 fprintf(stderr, "Error '%s': Unknown command\n", argv[0]);
3638 char *__connmanctl_lookup_command(const char *text, int state)
3648 while (cmd_table[i].cmd) {
3649 const char *command = cmd_table[i].cmd;
3653 if (strncmp(text, command, len) == 0)
3654 return strdup(command);
3660 static char *get_path(char *full_path)
3664 path = strrchr(full_path, '/');
3665 if (path && *path != '\0')
3673 static void add_service_id(const char *path)
3675 g_hash_table_replace(service_hash, g_strdup(path),
3676 GINT_TO_POINTER(TRUE));
3679 static void remove_service_id(const char *path)
3681 g_hash_table_remove(service_hash, path);
3684 static void services_added(DBusMessageIter *iter)
3686 DBusMessageIter array;
3689 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
3691 dbus_message_iter_recurse(iter, &array);
3692 if (dbus_message_iter_get_arg_type(&array) !=
3693 DBUS_TYPE_OBJECT_PATH)
3696 dbus_message_iter_get_basic(&array, &path);
3697 add_service_id(get_path(path));
3699 dbus_message_iter_next(iter);
3703 static void update_services(DBusMessageIter *iter)
3705 DBusMessageIter array;
3708 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3711 dbus_message_iter_recurse(iter, &array);
3712 services_added(&array);
3714 dbus_message_iter_next(iter);
3715 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3718 dbus_message_iter_recurse(iter, &array);
3719 while (dbus_message_iter_get_arg_type(&array) ==
3720 DBUS_TYPE_OBJECT_PATH) {
3721 dbus_message_iter_get_basic(&array, &path);
3722 remove_service_id(get_path(path));
3724 dbus_message_iter_next(&array);
3728 static int populate_service_hash(DBusMessageIter *iter, int errnum,
3729 const char *error, void *user_data)
3732 fprintf(stderr, "Error getting services: %s", error);
3736 update_services(iter);
3740 static void add_vpnconnection_id(const char *path)
3742 g_hash_table_replace(vpnconnection_hash, g_strdup(path),
3743 GINT_TO_POINTER(TRUE));
3746 static void remove_vpnconnection_id(const char *path)
3748 g_hash_table_remove(vpnconnection_hash, path);
3751 static void vpnconnection_added(DBusMessageIter *iter)
3755 dbus_message_iter_get_basic(iter, &path);
3756 add_vpnconnection_id(get_path(path));
3759 static void vpnconnection_removed(DBusMessageIter *iter)
3763 dbus_message_iter_get_basic(iter, &path);
3764 remove_vpnconnection_id(get_path(path));
3767 static void add_vpnconnections(DBusMessageIter *iter)
3769 DBusMessageIter array;
3772 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
3774 dbus_message_iter_recurse(iter, &array);
3775 if (dbus_message_iter_get_arg_type(&array) !=
3776 DBUS_TYPE_OBJECT_PATH)
3779 dbus_message_iter_get_basic(&array, &path);
3780 add_vpnconnection_id(get_path(path));
3782 dbus_message_iter_next(iter);
3786 static int populate_vpnconnection_hash(DBusMessageIter *iter, int errnum,
3787 const char *error, void *user_data)
3789 DBusMessageIter array;
3792 fprintf(stderr, "Error getting VPN connections: %s", error);
3796 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3799 dbus_message_iter_recurse(iter, &array);
3801 add_vpnconnections(&array);
3806 static void add_peer_id(const char *path)
3808 g_hash_table_replace(peer_hash, g_strdup(path), GINT_TO_POINTER(TRUE));
3811 static void remove_peer_id(const char *path)
3813 g_hash_table_remove(peer_hash, path);
3816 static void peers_added(DBusMessageIter *iter)
3818 DBusMessageIter array;
3821 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
3823 dbus_message_iter_recurse(iter, &array);
3824 if (dbus_message_iter_get_arg_type(&array) !=
3825 DBUS_TYPE_OBJECT_PATH)
3828 dbus_message_iter_get_basic(&array, &path);
3829 add_peer_id(get_path(path));
3831 dbus_message_iter_next(iter);
3835 static void update_peers(DBusMessageIter *iter)
3837 DBusMessageIter array;
3840 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3843 dbus_message_iter_recurse(iter, &array);
3844 peers_added(&array);
3846 dbus_message_iter_next(iter);
3847 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3850 dbus_message_iter_recurse(iter, &array);
3851 while (dbus_message_iter_get_arg_type(&array) ==
3852 DBUS_TYPE_OBJECT_PATH) {
3853 dbus_message_iter_get_basic(&array, &path);
3854 remove_peer_id(get_path(path));
3856 dbus_message_iter_next(&array);
3860 static int populate_peer_hash(DBusMessageIter *iter, int errnum,
3861 const char *error, void *user_data)
3864 fprintf(stderr, "Error getting peers: %s", error);
3872 static void add_technology_id(const char *path)
3874 g_hash_table_replace(technology_hash, g_strdup(path),
3875 GINT_TO_POINTER(TRUE));
3878 static void remove_technology_id(const char *path)
3880 g_hash_table_remove(technology_hash, path);
3883 static void remove_technology(DBusMessageIter *iter)
3887 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH)
3890 dbus_message_iter_get_basic(iter, &path);
3891 remove_technology_id(get_path(path));
3894 static void add_technology(DBusMessageIter *iter)
3898 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH)
3901 dbus_message_iter_get_basic(iter, &path);
3902 add_technology_id(get_path(path));
3905 static void update_technologies(DBusMessageIter *iter)
3907 DBusMessageIter array;
3909 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
3912 dbus_message_iter_recurse(iter, &array);
3914 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
3915 DBusMessageIter object_path;
3917 dbus_message_iter_recurse(&array, &object_path);
3919 add_technology(&object_path);
3921 dbus_message_iter_next(&array);
3925 static int populate_technology_hash(DBusMessageIter *iter, int errnum,
3926 const char *error, void *user_data)
3929 fprintf(stderr, "Error getting technologies: %s\n", error);
3933 update_technologies(iter);
3938 static DBusHandlerResult monitor_completions_changed(
3939 DBusConnection *connection,
3940 DBusMessage *message, void *user_data)
3942 bool *enabled = user_data;
3943 DBusMessageIter iter;
3944 DBusHandlerResult handled;
3947 handled = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3949 handled = DBUS_HANDLER_RESULT_HANDLED;
3951 if (dbus_message_is_signal(message, "net.connman.Manager",
3952 "ServicesChanged")) {
3953 dbus_message_iter_init(message, &iter);
3954 update_services(&iter);
3958 if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
3959 "ConnectionAdded")) {
3960 dbus_message_iter_init(message, &iter);
3961 vpnconnection_added(&iter);
3965 if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
3966 "ConnectionRemoved")) {
3967 dbus_message_iter_init(message, &iter);
3968 vpnconnection_removed(&iter);
3972 if (dbus_message_is_signal(message, "net.connman.Manager",
3974 dbus_message_iter_init(message, &iter);
3975 update_peers(&iter);
3979 if (dbus_message_is_signal(message, "net.connman.Manager",
3980 "TechnologyAdded")) {
3981 dbus_message_iter_init(message, &iter);
3982 add_technology(&iter);
3986 if (dbus_message_is_signal(message, "net.connman.Manager",
3987 "TechnologyRemoved")) {
3988 dbus_message_iter_init(message, &iter);
3989 remove_technology(&iter);
3993 if (!g_strcmp0(dbus_message_get_interface(message),
3994 "net.connman.Manager"))
3997 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4000 void __connmanctl_monitor_completions(DBusConnection *dbus_conn)
4002 bool *manager_enabled = NULL;
4006 for (i = 0; monitor[i].interface; i++) {
4007 if (!strcmp(monitor[i].interface, "Manager")) {
4008 manager_enabled = &monitor[i].enabled;
4014 g_hash_table_destroy(service_hash);
4015 g_hash_table_destroy(vpnconnection_hash);
4016 g_hash_table_destroy(technology_hash);
4018 dbus_bus_remove_match(connection,
4019 "type='signal',interface='net.connman.Manager'", NULL);
4020 dbus_bus_remove_match(connection,
4021 "type='signal',interface='net.connman.vpn.Manager'",
4023 dbus_connection_remove_filter(connection,
4024 monitor_completions_changed,
4029 connection = dbus_conn;
4031 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
4034 vpnconnection_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
4037 peer_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
4040 technology_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
4043 __connmanctl_dbus_method_call(connection,
4044 CONNMAN_SERVICE, CONNMAN_PATH,
4045 "net.connman.Manager", "GetServices",
4046 populate_service_hash, NULL, NULL, NULL);
4048 __connmanctl_dbus_method_call(connection,
4049 VPN_SERVICE, CONNMAN_PATH,
4050 "net.connman.vpn.Manager", "GetConnections",
4051 populate_vpnconnection_hash, NULL, NULL, NULL);
4053 __connmanctl_dbus_method_call(connection,
4054 CONNMAN_SERVICE, CONNMAN_PATH,
4055 "net.connman.Manager", "GetPeers",
4056 populate_peer_hash, NULL, NULL, NULL);
4058 __connmanctl_dbus_method_call(connection,
4059 CONNMAN_SERVICE, CONNMAN_PATH,
4060 "net.connman.Manager", "GetTechnologies",
4061 populate_technology_hash, NULL, NULL, NULL);
4063 dbus_connection_add_filter(connection,
4064 monitor_completions_changed, manager_enabled,
4067 dbus_error_init(&err);
4068 dbus_bus_add_match(connection,
4069 "type='signal',interface='net.connman.Manager'", &err);
4071 if (dbus_error_is_set(&err)) {
4072 fprintf(stderr, "Error: %s\n", err.message);
4076 dbus_bus_add_match(connection,
4077 "type='signal',interface='net.connman.vpn.Manager'",
4080 if (dbus_error_is_set(&err))
4081 fprintf(stderr, "Error: %s\n", err.message);