5 * Copyright (C) 2007-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 version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
38 #include <connman/storage.h>
39 #include <connman/setting.h>
40 #include <connman/agent.h>
42 #include "src/shared/util.h"
46 #define CONNECT_TIMEOUT 120
49 #define WIFI_BSSID_STR_LEN 18
50 #define MAX_WIFI_PROFILES 200
52 #define FREQ_RANGE_24GHZ_CHANNEL_1 2412
53 #define FREQ_RANGE_24GHZ_CHANNEL_14 2484
54 #define FREQ_RANGE_5GHZ_CHANNEL_32 5160
55 #define FREQ_RANGE_5GHZ_CHANNEL_165 5825
57 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
58 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
60 #define VPN_AUTOCONNECT_TIMEOUT_DEFAULT 1
61 #define VPN_AUTOCONNECT_TIMEOUT_STEP 30
62 #define VPN_AUTOCONNECT_TIMEOUT_ATTEMPTS_THRESHOLD 270
64 static DBusConnection *connection = NULL;
66 static GList *service_list = NULL;
67 static GHashTable *service_hash = NULL;
68 static GHashTable *passphrase_requested = NULL;
69 static GSList *counter_list = NULL;
70 static unsigned int autoconnect_id = 0;
71 static unsigned int vpn_autoconnect_id = 0;
72 static struct connman_service *current_default = NULL;
73 static bool services_dirty = false;
74 static bool enable_online_to_ready_transition = false;
75 static unsigned int online_check_initial_interval = 0;
76 static unsigned int online_check_max_interval = 0;
79 static bool auto_connect_mode = TRUE;
81 struct saved_profiles {
86 static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
90 enum connman_ins_preferred_freq {
91 CONNMAN_INS_PREFERRED_FREQ_UNKNOWN,
92 CONNMAN_INS_PREFERRED_FREQ_24GHZ,
93 CONNMAN_INS_PREFERRED_FREQ_5GHZ,
96 struct connman_ins_settings {
97 bool last_user_selection;
98 unsigned int last_user_selection_time;
99 unsigned int last_user_selection_score;
101 unsigned int last_connected_score;
102 enum connman_ins_preferred_freq preferred_freq;
103 unsigned int preferred_freq_score;
104 unsigned int security_priority[CONNMAN_SERVICE_SECURITY_MAX];
105 unsigned int security_priority_count;
106 unsigned int security_priority_score;
109 unsigned int internet_score;
110 int signal_level3_5ghz;
111 int signal_level3_24ghz;
114 static struct connman_ins_settings ins_settings;
115 #endif /* defined TIZEN_EXT */
117 struct connman_stats {
120 struct connman_stats_data data_last;
121 struct connman_stats_data data;
125 struct connman_stats_counter {
127 struct connman_stats stats;
128 struct connman_stats stats_roaming;
131 struct connman_service {
135 enum connman_service_type type;
136 enum connman_service_security security;
137 enum connman_service_state state;
138 enum connman_service_state state_ipv4;
139 enum connman_service_state state_ipv6;
140 enum connman_service_error error;
141 enum connman_service_connect_reason connect_reason;
148 struct timeval modified;
153 struct connman_ipconfig *ipconfig_ipv4;
154 struct connman_ipconfig *ipconfig_ipv6;
155 struct connman_network *network;
156 struct connman_provider *provider;
158 char **nameservers_config;
159 char **nameservers_auto;
160 int nameservers_timeout;
167 char **timeservers_config;
168 /* 802.1x settings from the config files */
171 char *anonymous_identity;
172 char *agent_identity;
175 char *altsubject_match;
176 char *domain_suffix_match;
178 char *client_cert_file;
179 char *private_key_file;
180 char *private_key_passphrase;
182 DBusMessage *pending;
183 DBusMessage *provider_pending;
185 struct connman_stats stats;
186 struct connman_stats stats_roaming;
187 GHashTable *counter_table;
188 enum connman_service_proxy_method proxy;
189 enum connman_service_proxy_method proxy_config;
194 bool wps_advertizing;
195 guint online_timeout;
196 unsigned int online_check_interval_ipv4;
197 unsigned int online_check_interval_ipv6;
198 bool do_split_routing;
203 #if defined TIZEN_EXT
205 * Description: TIZEN implements system global connection management.
206 * It's only for PDP (cellular) bearer. Wi-Fi is managed
207 * by ConnMan automatically. Reference count can help to
208 * manage open/close connection requests by each application.
210 int user_pdn_connection_refcount;
213 * Description: In case of EAP security type,
214 * user can select the keymgmt type for roaming(802.11r).
215 * - FT, CCKM, OKC, ...
218 int disconnect_reason;
219 int assoc_status_code;
221 * Only for EAP-FAST and EAP-PEAP in EAPoL.
224 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
231 * Description: To indicate that disconnection triggered by user.
233 bool disconnection_requested;
235 enum connman_dnsconfig_method dns_config_method_ipv4;
236 enum connman_dnsconfig_method dns_config_method_ipv6;
240 char *net_access_key;
241 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
242 bool is_internet_connection;
243 int assoc_reject_count;
244 int score_last_user_selection;
245 int score_last_connected;
247 int score_security_priority;
248 int score_internet_connection;
252 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
254 * To indicate use of EAP over Ethernet.
257 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
260 static bool allow_property_changed(struct connman_service *service);
262 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
263 int index, enum connman_ipconfig_method method);
264 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
266 static void dns_changed(struct connman_service *service);
267 static void vpn_auto_connect(void);
271 struct connman_service *service;
274 #if defined TIZEN_EXT
275 struct assoc_reject_data {
277 GSList *reject_time_list;
281 * Public APIs to use user_pdn_connection_refcount
283 void connman_service_user_pdn_connection_ref(struct connman_service *service)
285 __sync_fetch_and_add(&service->user_pdn_connection_refcount, 1);
287 DBG("User made PDN connection referenced: %d",
288 service->user_pdn_connection_refcount);
291 gboolean connman_service_user_pdn_connection_unref_and_test(
292 struct connman_service *service)
294 __sync_synchronize();
296 DBG("User made PDN connection referenced: %d, which will be decreased",
297 service->user_pdn_connection_refcount);
299 if (service->user_pdn_connection_refcount < 1)
302 if (__sync_sub_and_fetch(&service->user_pdn_connection_refcount, 1) == 0)
308 gboolean connman_service_is_no_ref_user_pdn_connection(
309 struct connman_service *cellular)
311 if (cellular == NULL)
314 __sync_synchronize();
315 if (cellular->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
316 cellular->user_pdn_connection_refcount == 0)
323 static void compare_path(gpointer value, gpointer user_data)
325 struct connman_service *service = value;
326 struct find_data *data = user_data;
331 if (g_strcmp0(service->path, data->path) == 0)
332 data->service = service;
335 static struct connman_service *find_service(const char *path)
337 struct find_data data = { .path = path, .service = NULL };
339 DBG("path %s", path);
341 g_list_foreach(service_list, compare_path, &data);
346 static const char *reason2string(enum connman_service_connect_reason reason)
350 case CONNMAN_SERVICE_CONNECT_REASON_NONE:
352 case CONNMAN_SERVICE_CONNECT_REASON_USER:
354 case CONNMAN_SERVICE_CONNECT_REASON_AUTO:
356 case CONNMAN_SERVICE_CONNECT_REASON_SESSION:
358 case CONNMAN_SERVICE_CONNECT_REASON_NATIVE:
365 const char *__connman_service_type2string(enum connman_service_type type)
368 case CONNMAN_SERVICE_TYPE_UNKNOWN:
370 case CONNMAN_SERVICE_TYPE_SYSTEM:
372 case CONNMAN_SERVICE_TYPE_ETHERNET:
374 case CONNMAN_SERVICE_TYPE_WIFI:
376 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
378 case CONNMAN_SERVICE_TYPE_CELLULAR:
380 case CONNMAN_SERVICE_TYPE_GPS:
382 case CONNMAN_SERVICE_TYPE_VPN:
384 case CONNMAN_SERVICE_TYPE_GADGET:
386 case CONNMAN_SERVICE_TYPE_P2P:
388 #if defined TIZEN_EXT_WIFI_MESH
389 case CONNMAN_SERVICE_TYPE_MESH:
397 enum connman_service_type __connman_service_string2type(const char *str)
400 return CONNMAN_SERVICE_TYPE_UNKNOWN;
402 if (strcmp(str, "ethernet") == 0)
403 return CONNMAN_SERVICE_TYPE_ETHERNET;
404 if (strcmp(str, "gadget") == 0)
405 return CONNMAN_SERVICE_TYPE_GADGET;
406 if (strcmp(str, "wifi") == 0)
407 return CONNMAN_SERVICE_TYPE_WIFI;
408 if (strcmp(str, "cellular") == 0)
409 return CONNMAN_SERVICE_TYPE_CELLULAR;
410 if (strcmp(str, "bluetooth") == 0)
411 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
412 if (strcmp(str, "vpn") == 0)
413 return CONNMAN_SERVICE_TYPE_VPN;
414 if (strcmp(str, "gps") == 0)
415 return CONNMAN_SERVICE_TYPE_GPS;
416 if (strcmp(str, "system") == 0)
417 return CONNMAN_SERVICE_TYPE_SYSTEM;
418 if (strcmp(str, "p2p") == 0)
419 return CONNMAN_SERVICE_TYPE_P2P;
421 return CONNMAN_SERVICE_TYPE_UNKNOWN;
424 enum connman_service_security __connman_service_string2security(const char *str)
427 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
429 if (!strcmp(str, "psk"))
430 return CONNMAN_SERVICE_SECURITY_PSK;
431 if (!strcmp(str, "ieee8021x") || !strcmp(str, "8021x"))
432 return CONNMAN_SERVICE_SECURITY_8021X;
433 if (!strcmp(str, "none") || !strcmp(str, "open"))
434 return CONNMAN_SERVICE_SECURITY_NONE;
435 if (!strcmp(str, "wep"))
436 return CONNMAN_SERVICE_SECURITY_WEP;
437 #if defined TIZEN_EXT
438 if (!strcmp(str, "rsn"))
439 return CONNMAN_SERVICE_SECURITY_RSN;
440 if (!strcmp(str, "sae"))
441 return CONNMAN_SERVICE_SECURITY_SAE;
442 if (!strcmp(str, "owe"))
443 return CONNMAN_SERVICE_SECURITY_OWE;
444 if (!strcmp(str, "dpp"))
445 return CONNMAN_SERVICE_SECURITY_DPP;
448 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
451 static const char *security2string(enum connman_service_security security)
454 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
456 case CONNMAN_SERVICE_SECURITY_NONE:
458 case CONNMAN_SERVICE_SECURITY_WEP:
460 case CONNMAN_SERVICE_SECURITY_PSK:
461 case CONNMAN_SERVICE_SECURITY_WPA:
462 #if defined TIZEN_EXT
464 case CONNMAN_SERVICE_SECURITY_RSN:
466 case CONNMAN_SERVICE_SECURITY_SAE:
468 case CONNMAN_SERVICE_SECURITY_OWE:
470 case CONNMAN_SERVICE_SECURITY_DPP:
473 case CONNMAN_SERVICE_SECURITY_RSN:
476 case CONNMAN_SERVICE_SECURITY_8021X:
478 #if defined TIZEN_EXT
487 static const char *state2string(enum connman_service_state state)
490 case CONNMAN_SERVICE_STATE_UNKNOWN:
492 case CONNMAN_SERVICE_STATE_IDLE:
494 case CONNMAN_SERVICE_STATE_ASSOCIATION:
495 return "association";
496 case CONNMAN_SERVICE_STATE_CONFIGURATION:
497 return "configuration";
498 case CONNMAN_SERVICE_STATE_READY:
500 case CONNMAN_SERVICE_STATE_ONLINE:
502 case CONNMAN_SERVICE_STATE_DISCONNECT:
504 case CONNMAN_SERVICE_STATE_FAILURE:
511 static const char *error2string(enum connman_service_error error)
514 case CONNMAN_SERVICE_ERROR_UNKNOWN:
516 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
517 return "out-of-range";
518 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
519 return "pin-missing";
520 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
521 return "dhcp-failed";
522 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
523 return "connect-failed";
524 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
525 return "login-failed";
526 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
527 return "auth-failed";
529 case CONNMAN_SERVICE_ERROR_ASSOC_FAILED:
530 return "assoc-failed";
532 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
533 return "invalid-key";
534 case CONNMAN_SERVICE_ERROR_BLOCKED:
541 static const char *proxymethod2string(enum connman_service_proxy_method method)
544 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
546 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
548 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
550 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
557 static enum connman_service_proxy_method string2proxymethod(const char *method)
559 if (g_strcmp0(method, "direct") == 0)
560 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
561 else if (g_strcmp0(method, "auto") == 0)
562 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
563 else if (g_strcmp0(method, "manual") == 0)
564 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
566 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
570 static const char *__connman_dnsconfig_method2string(enum connman_dnsconfig_method method)
573 case CONNMAN_DNSCONFIG_METHOD_UNKNOWN:
575 case CONNMAN_DNSCONFIG_METHOD_MANUAL:
577 case CONNMAN_DNSCONFIG_METHOD_DHCP:
584 static enum connman_dnsconfig_method __connman_dnsconfig_string2method(
587 if (g_strcmp0(method, "manual") == 0)
588 return CONNMAN_DNSCONFIG_METHOD_MANUAL;
589 else if (g_strcmp0(method, "dhcp") == 0)
590 return CONNMAN_DNSCONFIG_METHOD_DHCP;
592 return CONNMAN_DNSCONFIG_METHOD_UNKNOWN;
596 void __connman_service_split_routing_changed(struct connman_service *service)
598 dbus_bool_t split_routing;
603 if (!allow_property_changed(service))
606 split_routing = service->do_split_routing;
607 if (!connman_dbus_property_changed_basic(service->path,
608 CONNMAN_SERVICE_INTERFACE, "SplitRouting",
609 DBUS_TYPE_BOOLEAN, &split_routing))
610 connman_warn("cannot send SplitRouting property change on %s",
611 service->identifier);
614 void __connman_service_set_split_routing(struct connman_service *service,
617 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
620 service->do_split_routing = value;
622 if (service->do_split_routing)
628 * In order to make sure the value is propagated also when loading the
629 * VPN service signal the value regardless of the value change.
631 __connman_service_split_routing_changed(service);
634 int __connman_service_load_modifiable(struct connman_service *service)
637 GError *error = NULL;
641 DBG("service %p", service);
643 keyfile = connman_storage_load_service(service->identifier);
647 switch (service->type) {
648 case CONNMAN_SERVICE_TYPE_UNKNOWN:
649 case CONNMAN_SERVICE_TYPE_SYSTEM:
650 case CONNMAN_SERVICE_TYPE_GPS:
651 case CONNMAN_SERVICE_TYPE_P2P:
652 #if defined TIZEN_EXT_WIFI_MESH
653 case CONNMAN_SERVICE_TYPE_MESH:
656 case CONNMAN_SERVICE_TYPE_VPN:
657 __connman_service_set_split_routing(service,
658 g_key_file_get_boolean(keyfile,
660 "SplitRouting", NULL));
663 case CONNMAN_SERVICE_TYPE_WIFI:
664 case CONNMAN_SERVICE_TYPE_GADGET:
665 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
666 case CONNMAN_SERVICE_TYPE_CELLULAR:
667 case CONNMAN_SERVICE_TYPE_ETHERNET:
668 autoconnect = g_key_file_get_boolean(keyfile,
669 service->identifier, "AutoConnect", &error);
671 service->autoconnect = autoconnect;
672 g_clear_error(&error);
676 str = g_key_file_get_string(keyfile,
677 service->identifier, "Modified", NULL);
679 util_iso8601_to_timeval(str, &service->modified);
683 g_key_file_free(keyfile);
688 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
689 static void __connman_service_cleanup_8021x(struct connman_service *service)
694 DBG("service %p ", service);
696 __connman_service_set_string(service, "EAP", NULL);
697 __connman_service_set_string(service, "Identity", NULL);
698 __connman_service_set_string(service, "Passphrase", NULL);
699 __connman_service_set_string(service, "AnonymousIdentity", NULL);
700 __connman_service_set_string(service, "CACertFile", NULL);
701 __connman_service_set_string(service, "ClientCertFile", NULL);
702 __connman_service_set_string(service, "PrivateKeyFile", NULL);
703 __connman_service_set_string(service, "PrivateKeyPassphrase", NULL);
704 __connman_service_set_string(service, "Phase1", NULL);
705 __connman_service_set_string(service, "Phase2", NULL);
706 __connman_service_set_string(service, "PacFile", NULL);
709 static int connman_service_set_eapol_property(struct connman_service *service,
710 DBusMessageIter *array)
712 DBusMessageIter dict;
715 __connman_service_cleanup_8021x(service);
717 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
720 dbus_message_iter_recurse(array, &dict);
722 while(dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
723 DBusMessageIter entry, value;
727 dbus_message_iter_recurse(&dict, &entry);
729 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
732 dbus_message_iter_get_basic(&entry, &key);
733 dbus_message_iter_next(&entry);
735 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
738 dbus_message_iter_recurse(&entry, &value);
740 type = dbus_message_iter_get_arg_type(&value);
742 if (g_str_equal(key, "UseEapol")) {
743 dbus_bool_t use_eapol;
745 if (type != DBUS_TYPE_BOOLEAN)
748 dbus_message_iter_get_basic(&value, &use_eapol);
749 service->use_eapol = use_eapol;
751 } else if (g_str_equal(key, "EAP")) {
752 if (type != DBUS_TYPE_STRING)
755 dbus_message_iter_get_basic(&value, &str);
756 __connman_service_set_string(service, "EAP", str);
758 } else if (g_str_equal(key, "Identity")) {
759 if (type != DBUS_TYPE_STRING)
762 dbus_message_iter_get_basic(&value, &str);
763 __connman_service_set_string(service, "Identity", str);
765 } else if (g_str_equal(key, "AnonymousIdentity")) {
766 if (type != DBUS_TYPE_STRING)
769 dbus_message_iter_get_basic(&value, &str);
770 __connman_service_set_string(service, "AnonymousIdentity", str);
772 } else if (g_str_equal(key, "CACertFile")) {
773 if (type != DBUS_TYPE_STRING)
776 dbus_message_iter_get_basic(&value, &str);
777 __connman_service_set_string(service, "CACertFile", str);
778 } else if (g_str_equal(key, "ClientCertFile")) {
779 if (type != DBUS_TYPE_STRING)
782 dbus_message_iter_get_basic(&value, &str);
783 __connman_service_set_string(service, "ClientCertFile", str);
784 } else if (g_str_equal(key, "PrivateKeyFile")) {
785 if (type != DBUS_TYPE_STRING)
788 dbus_message_iter_get_basic(&value, &str);
789 __connman_service_set_string(service, "PrivateKeyFile", str);
790 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
791 if (type != DBUS_TYPE_STRING)
794 dbus_message_iter_get_basic(&value, &str);
795 __connman_service_set_string(service, "PrivateKeyPassphrase", str);
796 } else if (g_str_equal(key, "Phase2")) {
797 if (type != DBUS_TYPE_STRING)
800 dbus_message_iter_get_basic(&value, &str);
801 __connman_service_set_string(service, "Phase2", str);
802 } else if (g_str_equal(key, "Phase1")) {
804 char phase1[5] = {0,};
806 if (type != DBUS_TYPE_INT32)
809 dbus_message_iter_get_basic(&value, &val);
810 sprintf(phase1, "%d", val);
811 __connman_service_set_string(service, "Phase1", phase1);
812 } else if (g_str_equal(key, "PacFile")) {
813 if (type != DBUS_TYPE_STRING)
816 dbus_message_iter_get_basic(&value, &str);
817 __connman_service_set_string(service, "PacFile", str);
820 dbus_message_iter_next(&dict);
827 #if defined TIZEN_EXT
828 static void save_assoc_reject(gpointer key, gpointer value, gpointer user_data)
830 struct assoc_reject_data *assoc_rd = value;
831 GString *assoc_reject_str = user_data;
838 if (g_slist_length(assoc_rd->reject_time_list) < 1)
841 for (list = assoc_rd->reject_time_list; list; list = list->next) {
842 time_t assoc_reject_time = GPOINTER_TO_INT(list->data);
844 val_str = g_strdup_printf("%s_%ld", assoc_rd->bssid, assoc_reject_time);
846 if (assoc_reject_str->len > 0)
847 g_string_append_printf(assoc_reject_str, " %s", val_str);
849 g_string_append(assoc_reject_str, val_str);
855 static void count_assoc_reject(gpointer key, gpointer value, gpointer user_data)
857 struct assoc_reject_data *assoc_data = value;
858 int *assoc_reject_count = user_data;
861 *assoc_reject_count += g_slist_length(assoc_data->reject_time_list);
864 static bool update_assoc_reject(struct connman_service *service)
866 GHashTable *assoc_reject_table;
867 int assoc_reject_count;
869 if (!service->network)
872 assoc_reject_table = connman_network_get_assoc_reject_table(service->network);
873 if (assoc_reject_table) {
874 assoc_reject_count = 0;
875 g_hash_table_foreach(assoc_reject_table, count_assoc_reject, &assoc_reject_count);
877 DBG("assoc reject count [%d -> %d]",
878 service->assoc_reject_count, assoc_reject_count);
880 if (service->assoc_reject_count != assoc_reject_count) {
881 service->assoc_reject_count = assoc_reject_count;
889 static int service_ext_load(struct connman_service *service)
892 GHashTable *reject_table;
895 struct assoc_reject_data *reject_data;
901 struct tm* ref_timeinfo;
906 DBG("service %p", service);
908 if (!service->network)
911 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
914 keyfile = connman_storage_load_service(service->identifier);
918 reject_table = connman_network_get_assoc_reject_table(service->network);
920 reject_list = g_key_file_get_string_list(keyfile,
921 service->identifier, "AssocReject", &reject_len, NULL);
923 if (!reject_list || reject_len == 0) {
924 g_strfreev(reject_list);
928 /* Only events that occur within one hour are appened. */
929 curr_time = time(NULL);
930 ref_timeinfo = localtime(&curr_time);
931 ref_timeinfo->tm_hour -= 1;
932 ref_time = mktime(ref_timeinfo);
934 for (i = 0; reject_list[i]; i++) {
935 bssid_time = g_strsplit(reject_list[i], "_", 0);
941 bssid = bssid_time[0];
942 reject_time = strtol(bssid_time[1], NULL, 10);
944 if (reject_time < ref_time) {
945 g_strfreev(bssid_time);
950 reject_data = g_hash_table_lookup(reject_table, bssid);
952 reject_data = g_try_new0(struct assoc_reject_data, 1);
954 g_strfreev(bssid_time);
959 reject_data->bssid = g_strdup(bssid);
960 g_hash_table_insert(reject_table, reject_data->bssid, reject_data);
963 reject_data->reject_time_list = g_slist_append(reject_data->reject_time_list,
964 GINT_TO_POINTER(reject_time));
966 DBG("assoc reject [%s_%ld]", bssid, reject_time);
968 g_strfreev(bssid_time);
971 g_strfreev(reject_list);
974 g_key_file_free(keyfile);
978 static int service_ext_save(struct connman_service *service)
981 GHashTable *reject_table;
987 DBG("service %p", service);
989 if (!service->network)
992 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
995 keyfile = connman_storage_load_service(service->identifier);
1000 /* Last connected BSSID */
1001 if (memcmp(service->last_connected_bssid, invalid_bssid, WIFI_BSSID_LEN_MAX)) {
1002 char *identifier = service->identifier;
1006 bssid_str = g_string_sized_new(MAC_ADDRESS_LENGTH);
1012 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
1013 g_string_append_printf(bssid_str,
1014 "%02x", service->last_connected_bssid[i]);
1015 if (i < WIFI_BSSID_LEN_MAX - 1)
1016 g_string_append(bssid_str, ":");
1019 g_key_file_set_string(keyfile, identifier,
1020 "LastConnectedBSSID", bssid_str->str);
1022 DBG("last connected bssid[%s]", bssid_str->str);
1024 g_string_free(bssid_str, TRUE);
1030 reject_table = connman_network_get_assoc_reject_table(service->network);
1031 if (reject_table && g_hash_table_size(reject_table) > 0) {
1032 reject_str = g_string_new(NULL);
1038 g_hash_table_foreach(reject_table, save_assoc_reject, reject_str);
1040 reject_list = g_strsplit_set(reject_str->str, " ", 0);
1041 reject_len = g_strv_length(reject_list);
1043 g_key_file_set_string_list(keyfile, service->identifier,
1044 "AssocReject", (const gchar **)reject_list, reject_len);
1046 DBG("assoc reject table [%d]", reject_len);
1048 g_strfreev(reject_list);
1049 g_string_free(reject_str, TRUE);
1051 g_key_file_remove_key(keyfile, service->identifier, "AssocReject", NULL);
1055 __connman_storage_save_service(keyfile, service->identifier);
1057 g_key_file_free(keyfile);
1060 #endif /* defined TIZEN_EXT */
1062 static int service_load(struct connman_service *service)
1065 GError *error = NULL;
1069 unsigned int ssid_len;
1071 #if defined TIZEN_EXT
1072 bool internet_connection;
1074 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
1077 #if defined TIZEN_EXT
1078 if (!simplified_log)
1080 DBG("service %p", service);
1082 keyfile = connman_storage_load_service(service->identifier);
1084 service->new_service = true;
1087 service->new_service = false;
1089 switch (service->type) {
1090 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1091 case CONNMAN_SERVICE_TYPE_SYSTEM:
1092 case CONNMAN_SERVICE_TYPE_GPS:
1093 case CONNMAN_SERVICE_TYPE_P2P:
1094 #if defined TIZEN_EXT_WIFI_MESH
1095 case CONNMAN_SERVICE_TYPE_MESH:
1098 case CONNMAN_SERVICE_TYPE_VPN:
1099 __connman_service_set_split_routing(service,
1100 g_key_file_get_boolean(keyfile,
1101 service->identifier,
1102 "SplitRouting", NULL));
1104 autoconnect = g_key_file_get_boolean(keyfile,
1105 service->identifier, "AutoConnect", &error);
1107 service->autoconnect = autoconnect;
1108 g_clear_error(&error);
1110 case CONNMAN_SERVICE_TYPE_WIFI:
1111 if (!service->name) {
1114 name = g_key_file_get_string(keyfile,
1115 service->identifier, "Name", NULL);
1117 g_free(service->name);
1118 service->name = name;
1121 if (service->network)
1122 connman_network_set_name(service->network,
1126 if (service->network &&
1127 !connman_network_get_blob(service->network,
1128 "WiFi.SSID", &ssid_len)) {
1131 hex_ssid = g_key_file_get_string(keyfile,
1132 service->identifier,
1137 unsigned int i, j = 0, hex;
1138 size_t hex_ssid_len = strlen(hex_ssid);
1140 ssid = g_try_malloc0(hex_ssid_len / 2);
1147 for (i = 0; i < hex_ssid_len; i += 2) {
1148 sscanf(hex_ssid + i, "%02x", &hex);
1152 connman_network_set_blob(service->network,
1153 "WiFi.SSID", ssid, hex_ssid_len / 2);
1161 #if defined TIZEN_EXT
1162 if (TIZEN_INS_ENABLED) {
1163 /* Last connected BSSID */
1164 if (service->network) {
1166 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
1170 bssid_str = g_key_file_get_string(keyfile,
1171 service->identifier, "LastConnectedBSSID", NULL);
1174 str_list = g_strsplit(bssid_str, ":", 0);
1177 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++)
1178 last_connected_bssid[i] = strtol(str_list[i], NULL, 16);
1180 memcpy(service->last_connected_bssid,
1181 last_connected_bssid, WIFI_BSSID_LEN_MAX);
1183 connman_network_set_last_connected_bssid(service->network,
1184 last_connected_bssid);
1186 g_strfreev(str_list);
1193 /* Internet connection */
1194 internet_connection = g_key_file_get_boolean(keyfile,
1195 service->identifier, "InternetConnection", &error);
1197 service->is_internet_connection = internet_connection;
1199 g_clear_error(&error);
1201 #endif /* defined TIZEN_EXT */
1204 case CONNMAN_SERVICE_TYPE_GADGET:
1205 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1206 case CONNMAN_SERVICE_TYPE_CELLULAR:
1207 service->favorite = g_key_file_get_boolean(keyfile,
1208 service->identifier, "Favorite", NULL);
1212 case CONNMAN_SERVICE_TYPE_ETHERNET:
1213 autoconnect = g_key_file_get_boolean(keyfile,
1214 service->identifier, "AutoConnect", &error);
1216 service->autoconnect = autoconnect;
1217 g_clear_error(&error);
1219 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
1220 use_eapol = g_key_file_get_boolean(keyfile,
1221 service->identifier, "UseEapol", &error);
1223 service->use_eapol = use_eapol;
1224 g_clear_error(&error);
1229 str = g_key_file_get_string(keyfile,
1230 service->identifier, "Modified", NULL);
1232 util_iso8601_to_timeval(str, &service->modified);
1236 str = g_key_file_get_string(keyfile,
1237 service->identifier, "Passphrase", NULL);
1239 char *dec = g_strcompress(str);
1241 g_free(service->passphrase);
1242 service->passphrase = dec;
1245 if (service->ipconfig_ipv4)
1246 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
1247 service->identifier, "IPv4.");
1249 if (service->ipconfig_ipv6)
1250 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
1251 service->identifier, "IPv6.");
1253 service->nameservers_config = g_key_file_get_string_list(keyfile,
1254 service->identifier, "Nameservers", &length, NULL);
1255 if (service->nameservers_config && length == 0) {
1256 g_strfreev(service->nameservers_config);
1257 service->nameservers_config = NULL;
1263 dns_method = g_key_file_get_string(keyfile, service->identifier,
1264 "Nameservers.IPv4method", NULL);
1266 service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
1270 dns_method = g_key_file_get_string(keyfile, service->identifier,
1271 "Nameservers.IPv6method", NULL);
1273 service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
1278 service->timeservers_config = g_key_file_get_string_list(keyfile,
1279 service->identifier, "Timeservers", &length, NULL);
1280 if (service->timeservers_config && length == 0) {
1281 g_strfreev(service->timeservers_config);
1282 service->timeservers_config = NULL;
1285 service->domains = g_key_file_get_string_list(keyfile,
1286 service->identifier, "Domains", &length, NULL);
1287 if (service->domains && length == 0) {
1288 g_strfreev(service->domains);
1289 service->domains = NULL;
1292 str = g_key_file_get_string(keyfile,
1293 service->identifier, "Proxy.Method", NULL);
1295 service->proxy_config = string2proxymethod(str);
1299 service->proxies = g_key_file_get_string_list(keyfile,
1300 service->identifier, "Proxy.Servers", &length, NULL);
1301 if (service->proxies && length == 0) {
1302 g_strfreev(service->proxies);
1303 service->proxies = NULL;
1306 service->excludes = g_key_file_get_string_list(keyfile,
1307 service->identifier, "Proxy.Excludes", &length, NULL);
1308 if (service->excludes && length == 0) {
1309 g_strfreev(service->excludes);
1310 service->excludes = NULL;
1313 str = g_key_file_get_string(keyfile,
1314 service->identifier, "Proxy.URL", NULL);
1316 g_free(service->pac);
1320 service->mdns_config = g_key_file_get_boolean(keyfile,
1321 service->identifier, "mDNS", NULL);
1323 service->hidden_service = g_key_file_get_boolean(keyfile,
1324 service->identifier, "Hidden", NULL);
1326 #if defined TIZEN_EXT
1327 if ((service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1328 service->security == CONNMAN_SERVICE_SECURITY_8021X)
1329 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1330 || (service->type == CONNMAN_SERVICE_TYPE_ETHERNET && service->use_eapol)
1333 str = g_key_file_get_string(keyfile,
1334 service->identifier, "EAP", NULL);
1336 g_free(service->eap);
1340 str = g_key_file_get_string(keyfile,
1341 service->identifier, "Phase2", NULL);
1343 g_free(service->phase2);
1344 service->phase2 = str;
1347 str = g_key_file_get_string(keyfile,
1348 service->identifier, "Identity", NULL);
1350 g_free(service->identity);
1351 service->identity = str;
1354 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1355 str = g_key_file_get_string(keyfile,
1356 service->identifier, "AnonymousIdentity", NULL);
1358 g_free(service->anonymous_identity);
1359 service->anonymous_identity = str;
1362 str = g_key_file_get_string(keyfile,
1363 service->identifier, "CACertFile", NULL);
1365 g_free(service->ca_cert_file);
1366 service->ca_cert_file = str;
1369 str = g_key_file_get_string(keyfile,
1370 service->identifier, "ClientCertFile", NULL);
1372 g_free(service->client_cert_file);
1373 service->client_cert_file = str;
1376 str = g_key_file_get_string(keyfile,
1377 service->identifier, "PrivateKeyFile", NULL);
1379 g_free(service->private_key_file);
1380 service->private_key_file = str;
1383 str = g_key_file_get_string(keyfile,
1384 service->identifier, "PrivateKeyPassphrase", NULL);
1386 g_free(service->private_key_passphrase);
1387 service->private_key_passphrase = str;
1390 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1391 str = g_key_file_get_string(keyfile,
1392 service->identifier, "Phase1", NULL);
1394 g_free(service->phase1);
1395 service->phase1 = str;
1398 str = g_key_file_get_string(keyfile,
1399 service->identifier, "PacFile", NULL);
1401 g_free(service->pac_file);
1402 service->pac_file = str;
1407 #if defined TIZEN_EXT
1408 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1409 service->security == CONNMAN_SERVICE_SECURITY_DPP) {
1410 str = g_key_file_get_string(keyfile,
1411 service->identifier, "Connector", NULL);
1413 g_free(service->connector);
1414 service->connector = str;
1416 str = g_key_file_get_string(keyfile,
1417 service->identifier, "CSignKey", NULL);
1419 g_free(service->c_sign_key);
1420 service->c_sign_key = str;
1422 str = g_key_file_get_string(keyfile,
1423 service->identifier, "NetAccessKey", NULL);
1425 g_free(service->net_access_key);
1426 service->net_access_key = str;
1432 g_key_file_free(keyfile);
1437 static int service_save(struct connman_service *service)
1442 const char *cst_str = NULL;
1445 DBG("service %p new %d", service, service->new_service);
1447 if (service->new_service)
1450 keyfile = g_key_file_new();
1455 g_key_file_set_string(keyfile, service->identifier,
1456 "Name", service->name);
1458 switch (service->type) {
1459 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1460 case CONNMAN_SERVICE_TYPE_SYSTEM:
1461 case CONNMAN_SERVICE_TYPE_GPS:
1462 case CONNMAN_SERVICE_TYPE_P2P:
1463 #if defined TIZEN_EXT_WIFI_MESH
1464 case CONNMAN_SERVICE_TYPE_MESH:
1467 case CONNMAN_SERVICE_TYPE_VPN:
1468 g_key_file_set_boolean(keyfile, service->identifier,
1469 "SplitRouting", service->do_split_routing);
1470 if (service->favorite)
1471 g_key_file_set_boolean(keyfile, service->identifier,
1472 "AutoConnect", service->autoconnect);
1474 case CONNMAN_SERVICE_TYPE_WIFI:
1475 if (service->network) {
1476 const unsigned char *ssid;
1477 unsigned int ssid_len = 0;
1478 #if defined TIZEN_EXT
1479 GHashTable *assoc_reject_table;
1482 ssid = connman_network_get_blob(service->network,
1483 "WiFi.SSID", &ssid_len);
1485 if (ssid && ssid_len > 0 && ssid[0] != '\0') {
1486 char *identifier = service->identifier;
1490 ssid_str = g_string_sized_new(ssid_len * 2);
1496 for (i = 0; i < ssid_len; i++)
1497 g_string_append_printf(ssid_str,
1500 g_key_file_set_string(keyfile, identifier,
1501 "SSID", ssid_str->str);
1503 g_string_free(ssid_str, TRUE);
1506 freq = connman_network_get_frequency(service->network);
1507 g_key_file_set_integer(keyfile, service->identifier,
1510 #if defined TIZEN_EXT
1511 if (TIZEN_INS_ENABLED) {
1512 /* Last connected BSSID */
1513 if (memcmp(service->last_connected_bssid, invalid_bssid, WIFI_BSSID_LEN_MAX)) {
1514 char *identifier = service->identifier;
1518 bssid_str = g_string_sized_new(18);
1524 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
1525 g_string_append_printf(bssid_str,
1526 "%02x", service->last_connected_bssid[i]);
1527 if (i < WIFI_BSSID_LEN_MAX - 1)
1528 g_string_append(bssid_str, ":");
1531 g_key_file_set_string(keyfile, identifier,
1532 "LastConnectedBSSID", bssid_str->str);
1534 DBG("last connected bssid[%s]", bssid_str->str);
1536 g_string_free(bssid_str, TRUE);
1540 assoc_reject_table = connman_network_get_assoc_reject_table(service->network);
1541 if (assoc_reject_table && g_hash_table_size(assoc_reject_table) > 0) {
1542 GString *assoc_reject_str;
1543 char **assoc_reject_list;
1544 guint assoc_reject_len;
1546 assoc_reject_str = g_string_new(NULL);
1547 if (!assoc_reject_str) {
1552 g_hash_table_foreach(assoc_reject_table, save_assoc_reject, assoc_reject_str);
1554 assoc_reject_list = g_strsplit_set(assoc_reject_str->str, " ", 0);
1555 assoc_reject_len = g_strv_length(assoc_reject_list);
1557 g_key_file_set_string_list(keyfile, service->identifier,
1558 "AssocReject", (const gchar **)assoc_reject_list, assoc_reject_len);
1560 DBG("assoc reject table [%d]", assoc_reject_len);
1562 g_strfreev(assoc_reject_list);
1563 g_string_free(assoc_reject_str, TRUE);
1565 g_key_file_remove_key(keyfile, service->identifier, "AssocReject", NULL);
1567 /* Internet connection */
1568 g_key_file_set_boolean(keyfile, service->identifier,
1569 "InternetConnection", service->is_internet_connection);
1571 DBG("internet connection [%s]", service->is_internet_connection ? "true" : "false");
1573 #endif /* defined TIZEN_EXT */
1577 case CONNMAN_SERVICE_TYPE_GADGET:
1578 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1579 case CONNMAN_SERVICE_TYPE_CELLULAR:
1580 g_key_file_set_boolean(keyfile, service->identifier,
1581 "Favorite", service->favorite);
1585 case CONNMAN_SERVICE_TYPE_ETHERNET:
1586 if (service->favorite)
1587 g_key_file_set_boolean(keyfile, service->identifier,
1588 "AutoConnect", service->autoconnect);
1589 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
1590 g_key_file_set_boolean(keyfile, service->identifier,
1591 "UseEapol", service->use_eapol);
1596 str = util_timeval_to_iso8601(&service->modified);
1598 g_key_file_set_string(keyfile, service->identifier,
1603 if (service->passphrase && strlen(service->passphrase) > 0) {
1604 char *enc = g_strescape(service->passphrase, NULL);
1605 g_key_file_set_string(keyfile, service->identifier,
1610 if (service->ipconfig_ipv4)
1611 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
1612 service->identifier, "IPv4.");
1614 if (service->ipconfig_ipv6)
1615 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
1616 service->identifier, "IPv6.");
1618 if (service->nameservers_config) {
1619 guint len = g_strv_length(service->nameservers_config);
1621 g_key_file_set_string_list(keyfile, service->identifier,
1623 (const gchar **) service->nameservers_config, len);
1626 #if defined TIZEN_EXT
1627 if(service->dns_config_method_ipv4 != 0) {
1629 method = __connman_dnsconfig_method2string(
1630 service->dns_config_method_ipv4);
1631 g_key_file_set_string(keyfile, service->identifier,
1632 "Nameservers.IPv4method", method);
1634 g_key_file_remove_key(keyfile, service->identifier,
1635 "Nameservers.IPv4method", NULL);
1637 if(service->dns_config_method_ipv6 != 0) {
1639 method = __connman_dnsconfig_method2string(
1640 service->dns_config_method_ipv6);
1641 g_key_file_set_string(keyfile, service->identifier,
1642 "Nameservers.IPv6method", method);
1644 g_key_file_remove_key(keyfile, service->identifier,
1645 "Nameservers.IPv6method", NULL);
1648 if (service->timeservers_config) {
1649 guint len = g_strv_length(service->timeservers_config);
1651 g_key_file_set_string_list(keyfile, service->identifier,
1653 (const gchar **) service->timeservers_config, len);
1656 if (service->domains) {
1657 guint len = g_strv_length(service->domains);
1659 g_key_file_set_string_list(keyfile, service->identifier,
1661 (const gchar **) service->domains, len);
1664 cst_str = proxymethod2string(service->proxy_config);
1666 g_key_file_set_string(keyfile, service->identifier,
1667 "Proxy.Method", cst_str);
1669 if (service->proxies) {
1670 guint len = g_strv_length(service->proxies);
1672 g_key_file_set_string_list(keyfile, service->identifier,
1674 (const gchar **) service->proxies, len);
1677 if (service->excludes) {
1678 guint len = g_strv_length(service->excludes);
1680 g_key_file_set_string_list(keyfile, service->identifier,
1682 (const gchar **) service->excludes, len);
1685 if (service->pac && strlen(service->pac) > 0)
1686 g_key_file_set_string(keyfile, service->identifier,
1687 "Proxy.URL", service->pac);
1689 if (service->mdns_config)
1690 g_key_file_set_boolean(keyfile, service->identifier,
1693 if (service->hidden_service)
1694 g_key_file_set_boolean(keyfile, service->identifier,
1697 if (service->config_file && strlen(service->config_file) > 0)
1698 g_key_file_set_string(keyfile, service->identifier,
1699 "Config.file", service->config_file);
1701 if (service->config_entry && strlen(service->config_entry) > 0)
1702 g_key_file_set_string(keyfile, service->identifier,
1703 "Config.ident", service->config_entry);
1705 #if defined TIZEN_EXT
1706 if ((service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1707 service->security == CONNMAN_SERVICE_SECURITY_8021X)
1708 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1709 || (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
1712 if (service->eap != NULL && strlen(service->eap) > 0)
1713 g_key_file_set_string(keyfile, service->identifier,
1714 "EAP", service->eap);
1716 g_key_file_remove_key(keyfile, service->identifier,
1719 if (service->phase2 != NULL && strlen(service->phase2) > 0)
1720 g_key_file_set_string(keyfile, service->identifier,
1721 "Phase2", service->phase2);
1723 g_key_file_remove_key(keyfile, service->identifier,
1726 if (service->identity != NULL && strlen(service->identity) > 0)
1727 g_key_file_set_string(keyfile, service->identifier,
1728 "Identity", service->identity);
1730 g_key_file_remove_key(keyfile, service->identifier,
1732 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1733 if (service->anonymous_identity != NULL && strlen(service->anonymous_identity) > 0)
1734 g_key_file_set_string(keyfile, service->identifier,
1735 "AnonymousIdentity", service->anonymous_identity);
1737 g_key_file_remove_key(keyfile, service->identifier,
1738 "AnonymousIdentity", NULL);
1741 if (service->ca_cert_file != NULL && strlen(service->ca_cert_file) > 0)
1742 g_key_file_set_string(keyfile, service->identifier,
1743 "CACertFile", service->ca_cert_file);
1745 g_key_file_remove_key(keyfile, service->identifier,
1746 "CACertFile", NULL);
1748 if (service->client_cert_file != NULL && strlen(service->client_cert_file) > 0)
1749 g_key_file_set_string(keyfile, service->identifier,
1750 "ClientCertFile", service->client_cert_file);
1752 g_key_file_remove_key(keyfile, service->identifier,
1753 "ClientCertFile", NULL);
1755 if (service->private_key_file != NULL && strlen(service->private_key_file) > 0)
1756 g_key_file_set_string(keyfile, service->identifier,
1757 "PrivateKeyFile", service->private_key_file);
1759 g_key_file_remove_key(keyfile, service->identifier,
1760 "PrivateKeyFile", NULL);
1762 if (service->private_key_passphrase != NULL && strlen(service->private_key_passphrase) > 0)
1763 g_key_file_set_string(keyfile, service->identifier,
1764 "PrivateKeyPassphrase", service->private_key_passphrase);
1766 g_key_file_remove_key(keyfile, service->identifier,
1767 "PrivateKeyPassphrase", NULL);
1768 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1769 if (service->phase1 != NULL && strlen(service->phase1) > 0)
1770 g_key_file_set_string(keyfile, service->identifier,
1771 "Phase1", service->phase1);
1773 g_key_file_remove_key(keyfile, service->identifier,
1775 if (service->pac_file != NULL && strlen(service->pac_file) > 0)
1776 g_key_file_set_string(keyfile, service->identifier,
1777 "PacFile", service->pac_file);
1779 g_key_file_remove_key(keyfile, service->identifier,
1784 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1785 service->security == CONNMAN_SERVICE_SECURITY_DPP) {
1786 if (service->connector != NULL && strlen(service->connector) > 0)
1787 g_key_file_set_string(keyfile, service->identifier,
1788 "Connector", service->connector);
1790 g_key_file_remove_key(keyfile, service->identifier,
1793 if (service->c_sign_key != NULL && strlen(service->c_sign_key) > 0)
1794 g_key_file_set_string(keyfile, service->identifier,
1795 "CSignKey", service->c_sign_key);
1797 g_key_file_remove_key(keyfile, service->identifier,
1800 if (service->net_access_key != NULL && strlen(service->net_access_key) > 0)
1801 g_key_file_set_string(keyfile, service->identifier,
1802 "NetAccessKey", service->net_access_key);
1804 g_key_file_remove_key(keyfile, service->identifier,
1805 "NetAccessKey", NULL);
1810 __connman_storage_save_service(keyfile, service->identifier);
1812 g_key_file_free(keyfile);
1817 #if defined TIZEN_EXT
1818 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
1820 GTimeVal *aval = (GTimeVal *)a;
1821 GTimeVal *bval = (GTimeVal *)b;
1823 /* Note that the sort order is ascending */
1824 if (aval->tv_sec > bval->tv_sec)
1827 if (aval->tv_sec < bval->tv_sec)
1833 static void free_entry(gpointer data)
1835 struct saved_profiles *entry = data;
1836 g_free(entry->profile_name);
1840 static void __connman_manage_saved_profiles()
1843 gchar **services = NULL;
1845 int i, num_profiles = 0;
1846 GSequenceIter *iter;
1847 GSequence *profile_list;
1848 struct saved_profiles *entry;
1850 profile_list = g_sequence_new(free_entry);
1854 services = connman_storage_get_services();
1856 /* Check the count of saved profiles */
1857 for (i = 0; services && services[i]; i++) {
1858 if (strncmp(services[i], "wifi_", 5) != 0)
1861 keyfile = connman_storage_load_service(services[i]);
1865 gchar *str = g_key_file_get_string(keyfile,
1866 services[i], "Modified", NULL);
1868 g_key_file_free(keyfile);
1872 g_time_val_from_iso8601(str, &modified);
1875 entry = g_try_new(struct saved_profiles, 1);
1877 g_sequence_free(profile_list);
1878 g_key_file_free(keyfile);
1879 g_strfreev(services);
1883 entry->modified = modified;
1884 entry->profile_name = g_strdup(services[i]);
1886 g_sequence_insert_sorted(profile_list, entry,
1891 DBG("number of profiles: %d", num_profiles);
1893 if (num_profiles > MAX_WIFI_PROFILES) {
1894 iter = g_sequence_get_begin_iter(profile_list);
1896 entry = g_sequence_get(iter);
1898 if (__connman_storage_remove_service(entry->profile_name) == false)
1899 DBG("Failed to remove service profile: %s", entry->profile_name);
1902 g_sequence_free(profile_list);
1903 g_strfreev(services);
1907 void __connman_service_save(struct connman_service *service)
1912 service_save(service);
1913 #if defined TIZEN_EXT
1915 * Description: Manage the wireless profiles saved in connman.
1916 * If the number of saved profiles is more than 200, remove the
1917 * profile that is not updated for longer duration.
1919 __connman_manage_saved_profiles();
1923 static enum connman_service_state combine_state(
1924 enum connman_service_state state_a,
1925 enum connman_service_state state_b)
1927 enum connman_service_state result;
1929 if (state_a == state_b) {
1934 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
1939 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
1944 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
1949 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
1954 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
1959 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
1964 if (state_a == CONNMAN_SERVICE_STATE_READY) {
1969 if (state_b == CONNMAN_SERVICE_STATE_READY) {
1974 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1979 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1984 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1989 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1994 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
1999 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
2004 result = CONNMAN_SERVICE_STATE_FAILURE;
2010 static bool is_connecting(enum connman_service_state state)
2013 case CONNMAN_SERVICE_STATE_UNKNOWN:
2014 case CONNMAN_SERVICE_STATE_IDLE:
2015 case CONNMAN_SERVICE_STATE_FAILURE:
2016 case CONNMAN_SERVICE_STATE_DISCONNECT:
2017 case CONNMAN_SERVICE_STATE_READY:
2018 case CONNMAN_SERVICE_STATE_ONLINE:
2020 case CONNMAN_SERVICE_STATE_ASSOCIATION:
2021 case CONNMAN_SERVICE_STATE_CONFIGURATION:
2028 static bool is_connected(enum connman_service_state state)
2031 case CONNMAN_SERVICE_STATE_UNKNOWN:
2032 case CONNMAN_SERVICE_STATE_IDLE:
2033 case CONNMAN_SERVICE_STATE_ASSOCIATION:
2034 case CONNMAN_SERVICE_STATE_CONFIGURATION:
2035 case CONNMAN_SERVICE_STATE_DISCONNECT:
2036 case CONNMAN_SERVICE_STATE_FAILURE:
2038 case CONNMAN_SERVICE_STATE_READY:
2039 case CONNMAN_SERVICE_STATE_ONLINE:
2046 static bool is_idle(enum connman_service_state state)
2049 case CONNMAN_SERVICE_STATE_IDLE:
2050 case CONNMAN_SERVICE_STATE_DISCONNECT:
2051 case CONNMAN_SERVICE_STATE_FAILURE:
2053 case CONNMAN_SERVICE_STATE_UNKNOWN:
2054 case CONNMAN_SERVICE_STATE_ASSOCIATION:
2055 case CONNMAN_SERVICE_STATE_CONFIGURATION:
2056 case CONNMAN_SERVICE_STATE_READY:
2057 case CONNMAN_SERVICE_STATE_ONLINE:
2064 static int nameservers_changed_cb(void *user_data)
2066 struct connman_service *service = user_data;
2068 DBG("service %p", service);
2070 service->nameservers_timeout = 0;
2071 if ((is_idle(service->state) && !service->nameservers) ||
2072 is_connected(service->state))
2073 dns_changed(service);
2078 static void nameservers_changed(struct connman_service *service)
2080 if (!service->nameservers_timeout)
2081 service->nameservers_timeout = g_idle_add(nameservers_changed_cb,
2085 static bool nameserver_available(struct connman_service *service,
2086 enum connman_ipconfig_type type,
2091 family = connman_inet_check_ipaddress(ns);
2093 if (family == AF_INET) {
2094 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2097 return is_connected(service->state_ipv4);
2100 if (family == AF_INET6) {
2101 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2104 return is_connected(service->state_ipv6);
2110 static int searchdomain_add_all(struct connman_service *service)
2114 if (!is_connected(service->state))
2117 index = __connman_service_get_index(service);
2121 if (service->domains) {
2122 while (service->domains[i]) {
2123 connman_resolver_append(index, service->domains[i],
2131 if (service->domainname)
2132 connman_resolver_append(index, service->domainname, NULL);
2138 static int searchdomain_remove_all(struct connman_service *service)
2142 if (!is_connected(service->state))
2145 index = __connman_service_get_index(service);
2149 while (service->domains && service->domains[i]) {
2150 connman_resolver_remove(index, service->domains[i], NULL);
2154 if (service->domainname)
2155 connman_resolver_remove(index, service->domainname, NULL);
2160 static int nameserver_add(struct connman_service *service,
2161 enum connman_ipconfig_type type,
2162 const char *nameserver)
2166 if (!nameserver_available(service, type, nameserver))
2169 index = __connman_service_get_index(service);
2173 #if defined TIZEN_EXT
2174 DBG("Resolver append nameserver: %s", nameserver);
2176 ret = connman_resolver_append(index, NULL, nameserver);
2178 nameservers_changed(service);
2183 static int nameserver_add_all(struct connman_service *service,
2184 enum connman_ipconfig_type type)
2188 if (service->nameservers_config) {
2189 while (service->nameservers_config[i]) {
2190 #if defined TIZEN_EXT
2191 DBG("type %d add service->nameservers_config[%d]:%s",type,
2192 i, service->nameservers_config[i]);
2193 if(strncmp(service->nameservers_config[i], "::", 2) == 0) {
2194 DBG("Invalid nameserver");
2200 case CONNMAN_IPCONFIG_TYPE_IPV4:
2201 if (connman_inet_check_ipaddress(
2202 service->nameservers_config[i]) == AF_INET &&
2203 service->dns_config_method_ipv4 ==
2204 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2205 nameserver_add(service, type,
2206 service->nameservers_config[i]);
2209 case CONNMAN_IPCONFIG_TYPE_IPV6:
2210 if (connman_inet_check_ipaddress(
2211 service->nameservers_config[i]) == AF_INET6 &&
2212 service->dns_config_method_ipv6 ==
2213 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2214 nameserver_add(service, type,
2215 service->nameservers_config[i]);
2218 case CONNMAN_IPCONFIG_TYPE_ALL:
2219 if (connman_inet_check_ipaddress(
2220 service->nameservers_config[i]) == AF_INET &&
2221 service->dns_config_method_ipv4 ==
2222 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2223 nameserver_add(service, type,
2224 service->nameservers_config[i]);
2226 if (connman_inet_check_ipaddress(
2227 service->nameservers_config[i]) == AF_INET6 &&
2228 service->dns_config_method_ipv6 ==
2229 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2230 nameserver_add(service, type,
2231 service->nameservers_config[i]);
2234 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2235 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
2238 DBG("default case do nothing");
2242 nameserver_add(service, type,
2243 service->nameservers_config[i]);
2247 } else if (service->nameservers) {
2248 while (service->nameservers[i]) {
2249 #if defined TIZEN_EXT
2250 DBG("type %d service->nameservers[%d]: %s",type,
2251 i, service->nameservers[i]);
2254 case CONNMAN_IPCONFIG_TYPE_IPV4:
2255 if (connman_inet_check_ipaddress(
2256 service->nameservers[i]) == AF_INET &&
2257 service->dns_config_method_ipv4 ==
2258 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2259 nameserver_add(service, type,
2260 service->nameservers[i]);
2263 case CONNMAN_IPCONFIG_TYPE_IPV6:
2264 if (connman_inet_check_ipaddress(
2265 service->nameservers[i]) == AF_INET6 &&
2266 service->dns_config_method_ipv6 ==
2267 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2268 nameserver_add(service, type,
2269 service->nameservers[i]);
2272 case CONNMAN_IPCONFIG_TYPE_ALL:
2273 if (connman_inet_check_ipaddress(
2274 service->nameservers[i]) == AF_INET &&
2275 service->dns_config_method_ipv4 ==
2276 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2277 nameserver_add(service, type,
2278 service->nameservers[i]);
2280 if (connman_inet_check_ipaddress(
2281 service->nameservers[i]) == AF_INET6 &&
2282 service->dns_config_method_ipv6 ==
2283 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2284 nameserver_add(service, type,
2285 service->nameservers[i]);
2288 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2289 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
2292 DBG("default case do nothing");
2296 nameserver_add(service, type,
2297 service->nameservers[i]);
2304 __connman_resolver_append_fallback_nameservers();
2306 #if defined TIZEN_EXT
2307 const char *global_dns = connman_setting_get_string("GlobalNameserver");
2309 nameserver_add(service, type, global_dns);
2312 searchdomain_add_all(service);
2317 static int nameserver_remove(struct connman_service *service,
2318 enum connman_ipconfig_type type,
2319 const char *nameserver)
2323 if (!nameserver_available(service, type, nameserver))
2326 index = __connman_service_get_index(service);
2330 #if defined TIZEN_EXT
2331 DBG("Resolver remove nameserver: %s", nameserver);
2333 ret = connman_resolver_remove(index, NULL, nameserver);
2335 nameservers_changed(service);
2340 static int nameserver_remove_all(struct connman_service *service,
2341 enum connman_ipconfig_type type)
2343 #if defined TIZEN_EXT
2345 * Skip this function if there is any connected profiles
2346 * that use same interface
2348 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2349 __connman_service_get_connected_count_of_iface(service) > 0)
2354 index = __connman_service_get_index(service);
2358 while (service->nameservers_config && service->nameservers_config[i]) {
2360 #if defined TIZEN_EXT
2361 DBG("type %d Remove service->nameservers_config[%d]: %s",
2362 type, i, service->nameservers_config[i]);
2364 case CONNMAN_IPCONFIG_TYPE_IPV4:
2365 if (connman_inet_check_ipaddress(
2366 service->nameservers_config[i]) == AF_INET &&
2367 (service->dns_config_method_ipv4 ==
2368 CONNMAN_DNSCONFIG_METHOD_DHCP ||
2369 service->dns_config_method_ipv4 ==
2370 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
2371 nameserver_remove(service, type,
2372 service->nameservers_config[i]);
2375 case CONNMAN_IPCONFIG_TYPE_IPV6:
2376 if (connman_inet_check_ipaddress(
2377 service->nameservers_config[i]) == AF_INET6 &&
2378 (service->dns_config_method_ipv6 ==
2379 CONNMAN_DNSCONFIG_METHOD_DHCP ||
2380 service->dns_config_method_ipv6 ==
2381 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
2382 nameserver_remove(service, type,
2383 service->nameservers_config[i]);
2386 case CONNMAN_IPCONFIG_TYPE_ALL:
2387 if (connman_inet_check_ipaddress(
2388 service->nameservers_config[i]) == AF_INET &&
2389 (service->dns_config_method_ipv4 ==
2390 CONNMAN_DNSCONFIG_METHOD_DHCP ||
2391 service->dns_config_method_ipv4 ==
2392 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
2393 nameserver_remove(service, type,
2394 service->nameservers_config[i]);
2396 if (connman_inet_check_ipaddress(
2397 service->nameservers_config[i]) == AF_INET6 &&
2398 (service->dns_config_method_ipv6 ==
2399 CONNMAN_DNSCONFIG_METHOD_DHCP ||
2400 service->dns_config_method_ipv6 ==
2401 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
2402 nameserver_remove(service, type,
2403 service->nameservers_config[i]);
2406 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2407 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
2410 DBG("default case do nothing");
2414 nameserver_remove(service, type,
2415 service->nameservers_config[i]);
2421 while (service->nameservers && service->nameservers[i]) {
2422 #if defined TIZEN_EXT
2423 DBG("type %d Remove service->nameservers[%d]: %s",type, i,
2424 service->nameservers[i]);
2426 case CONNMAN_IPCONFIG_TYPE_IPV4:
2427 if (connman_inet_check_ipaddress(
2428 service->nameservers[i]) == AF_INET &&
2429 (service->dns_config_method_ipv4 ==
2430 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
2431 service->dns_config_method_ipv4 ==
2432 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
2433 nameserver_remove(service, type,
2434 service->nameservers[i]);
2437 case CONNMAN_IPCONFIG_TYPE_IPV6:
2438 if (connman_inet_check_ipaddress(
2439 service->nameservers[i]) == AF_INET6 &&
2440 (service->dns_config_method_ipv6 ==
2441 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
2442 service->dns_config_method_ipv6 ==
2443 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
2444 nameserver_remove(service, type,
2445 service->nameservers[i]);
2448 case CONNMAN_IPCONFIG_TYPE_ALL:
2449 if (connman_inet_check_ipaddress(
2450 service->nameservers[i]) == AF_INET &&
2451 (service->dns_config_method_ipv4 ==
2452 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
2453 service->dns_config_method_ipv4 ==
2454 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
2455 nameserver_remove(service, type,
2456 service->nameservers[i]);
2458 if (connman_inet_check_ipaddress(
2459 service->nameservers[i]) == AF_INET6 &&
2460 (service->dns_config_method_ipv6 ==
2461 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
2462 service->dns_config_method_ipv6 ==
2463 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
2464 nameserver_remove(service, type,
2465 service->nameservers[i]);
2468 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2469 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
2472 DBG("default case do nothing");
2476 nameserver_remove(service, type, service->nameservers[i]);
2481 #if defined TIZEN_EXT
2482 const char *global_dns = connman_setting_get_string("GlobalNameserver");
2484 nameserver_remove(service, type, global_dns);
2486 searchdomain_remove_all(service);
2492 * The is_auto variable is set to true when IPv6 autoconf nameservers are
2493 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
2494 * for details) and not through service.c
2496 #if defined TIZEN_EXT
2497 int __connman_service_nameserver_append(struct connman_service *service,
2498 const char *nameserver, bool is_auto,
2499 enum connman_ipconfig_type type)
2501 int __connman_service_nameserver_append(struct connman_service *service,
2502 const char *nameserver, bool is_auto)
2508 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
2514 nameservers = service->nameservers_auto;
2516 nameservers = service->nameservers;
2519 for (i = 0; nameservers[i]; i++) {
2520 #if defined TIZEN_EXT
2521 DBG("nameservers[%d] %s, nameserver %s", i, nameservers[i], nameserver);
2523 if (g_strcmp0(nameservers[i], nameserver) == 0)
2527 len = g_strv_length(nameservers);
2528 nameservers = g_try_renew(char *, nameservers, len + 2);
2531 nameservers = g_try_new0(char *, len + 2);
2537 nameservers[len] = g_strdup(nameserver);
2538 nameservers[len + 1] = NULL;
2541 if(type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
2542 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
2543 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
2545 if(type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
2546 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
2547 service->dns_config_method_ipv6 = CONNMAN_DNSCONFIG_METHOD_DHCP;
2551 service->nameservers_auto = nameservers;
2553 service->nameservers = nameservers;
2554 nameserver_add(service, CONNMAN_IPCONFIG_TYPE_ALL, nameserver);
2557 nameservers_changed(service);
2559 searchdomain_add_all(service);
2564 #if defined TIZEN_EXT
2565 int __connman_service_nameserver_remove(struct connman_service *service,
2566 const char *nameserver, bool is_auto,
2567 enum connman_ipconfig_type type)
2569 int __connman_service_nameserver_remove(struct connman_service *service,
2570 const char *nameserver, bool is_auto)
2573 char **servers, **nameservers;
2577 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
2583 nameservers = service->nameservers_auto;
2585 nameservers = service->nameservers;
2590 for (i = 0; nameservers[i]; i++)
2591 if (g_strcmp0(nameservers[i], nameserver) == 0) {
2599 len = g_strv_length(nameservers);
2606 servers = g_try_new0(char *, len);
2610 for (i = 0, j = 0; i < len; i++) {
2611 if (g_strcmp0(nameservers[i], nameserver)) {
2612 servers[j] = nameservers[i];
2615 g_free(nameservers[i]);
2617 nameservers[i] = NULL;
2619 servers[len - 1] = NULL;
2622 g_strfreev(nameservers);
2623 nameservers = servers;
2626 service->nameservers_auto = nameservers;
2628 service->nameservers = nameservers;
2629 #if defined TIZEN_EXT
2630 DBG("nameserver remove ip_type: %d", type);
2631 nameserver_remove(service, type,
2634 nameserver_remove(service, CONNMAN_IPCONFIG_TYPE_ALL,
2642 void __connman_service_nameserver_clear(struct connman_service *service)
2644 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
2646 g_strfreev(service->nameservers);
2647 service->nameservers = NULL;
2649 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
2652 static void add_nameserver_route(int family, int index, char *nameserver,
2657 if (connman_inet_compare_subnet(index, nameserver))
2660 if (connman_inet_add_host_route(index, nameserver, gw) < 0)
2661 /* For P-t-P link the above route add will fail */
2662 connman_inet_add_host_route(index, nameserver, NULL);
2666 if (connman_inet_add_ipv6_host_route(index, nameserver,
2668 connman_inet_add_ipv6_host_route(index, nameserver,
2674 static void nameserver_add_routes(int index, char **nameservers,
2677 int i, ns_family, gw_family;
2679 gw_family = connman_inet_check_ipaddress(gw);
2683 for (i = 0; nameservers[i]; i++) {
2684 ns_family = connman_inet_check_ipaddress(nameservers[i]);
2685 if (ns_family < 0 || ns_family != gw_family)
2688 add_nameserver_route(ns_family, index, nameservers[i], gw);
2692 static void nameserver_del_routes(int index, char **nameservers,
2693 enum connman_ipconfig_type type)
2697 for (i = 0; nameservers[i]; i++) {
2698 family = connman_inet_check_ipaddress(nameservers[i]);
2704 if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
2705 connman_inet_del_host_route(index,
2709 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
2710 connman_inet_del_ipv6_host_route(index,
2717 void __connman_service_nameserver_add_routes(struct connman_service *service,
2725 index = __connman_service_get_index(service);
2727 if (service->nameservers_config) {
2729 * Configured nameserver takes preference over the
2730 * discoverd nameserver gathered from DHCP, VPN, etc.
2732 nameserver_add_routes(index, service->nameservers_config, gw);
2733 } else if (service->nameservers) {
2735 * We add nameservers host routes for nameservers that
2736 * are not on our subnet. For those who are, the subnet
2737 * route will be installed by the time the dns proxy code
2738 * tries to reach them. The subnet route is installed
2739 * when setting the interface IP address.
2741 nameserver_add_routes(index, service->nameservers, gw);
2745 void __connman_service_nameserver_del_routes(struct connman_service *service,
2746 enum connman_ipconfig_type type)
2753 index = __connman_service_get_index(service);
2755 if (service->nameservers_config)
2756 nameserver_del_routes(index, service->nameservers_config,
2758 else if (service->nameservers)
2759 nameserver_del_routes(index, service->nameservers, type);
2762 static bool check_proxy_setup(struct connman_service *service)
2765 * We start WPAD if we haven't got a PAC URL from DHCP and
2766 * if our proxy manual configuration is either empty or set
2767 * to AUTO with an empty URL.
2770 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
2773 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
2774 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
2778 if (__connman_wpad_start(service) < 0) {
2779 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
2780 __connman_notifier_proxy_changed(service);
2787 static void cancel_online_check(struct connman_service *service)
2789 if (service->online_timeout == 0)
2792 g_source_remove(service->online_timeout);
2793 service->online_timeout = 0;
2794 connman_service_unref(service);
2797 static void start_online_check(struct connman_service *service,
2798 enum connman_ipconfig_type type)
2800 if (!connman_setting_get_bool("EnableOnlineCheck")) {
2801 connman_info("Online check disabled. "
2802 "Default service remains in READY state.");
2805 enable_online_to_ready_transition =
2806 connman_setting_get_bool("EnableOnlineToReadyTransition");
2807 online_check_initial_interval =
2808 connman_setting_get_uint("OnlineCheckInitialInterval");
2809 online_check_max_interval =
2810 connman_setting_get_uint("OnlineCheckMaxInterval");
2812 if (type != CONNMAN_IPCONFIG_TYPE_IPV4 || check_proxy_setup(service)) {
2813 cancel_online_check(service);
2814 __connman_service_wispr_start(service, type);
2818 static void address_updated(struct connman_service *service,
2819 enum connman_ipconfig_type type)
2821 if (is_connected(service->state) &&
2822 service == connman_service_get_default()) {
2823 nameserver_remove_all(service, type);
2824 nameserver_add_all(service, type);
2825 start_online_check(service, type);
2827 __connman_timeserver_sync(service);
2831 static struct connman_stats *stats_get(struct connman_service *service)
2833 if (service->roaming)
2834 return &service->stats_roaming;
2836 return &service->stats;
2839 static bool stats_enabled(struct connman_service *service)
2841 struct connman_stats *stats = stats_get(service);
2843 return stats->enabled;
2846 static void stats_start(struct connman_service *service)
2848 struct connman_stats *stats = stats_get(service);
2850 DBG("service %p", service);
2855 stats->enabled = true;
2856 stats->data_last.time = stats->data.time;
2858 g_timer_start(stats->timer);
2861 static void stats_stop(struct connman_service *service)
2863 struct connman_stats *stats = stats_get(service);
2864 unsigned int seconds;
2866 DBG("service %p", service);
2871 if (!stats->enabled)
2874 g_timer_stop(stats->timer);
2876 seconds = g_timer_elapsed(stats->timer, NULL);
2877 stats->data.time = stats->data_last.time + seconds;
2879 stats->enabled = false;
2882 static void reset_stats(struct connman_service *service)
2884 DBG("service %p", service);
2887 service->stats.valid = false;
2889 service->stats.data.rx_packets = 0;
2890 service->stats.data.tx_packets = 0;
2891 service->stats.data.rx_bytes = 0;
2892 service->stats.data.tx_bytes = 0;
2893 service->stats.data.rx_errors = 0;
2894 service->stats.data.tx_errors = 0;
2895 service->stats.data.rx_dropped = 0;
2896 service->stats.data.tx_dropped = 0;
2897 service->stats.data.time = 0;
2898 service->stats.data_last.time = 0;
2900 g_timer_reset(service->stats.timer);
2903 service->stats_roaming.valid = false;
2905 service->stats_roaming.data.rx_packets = 0;
2906 service->stats_roaming.data.tx_packets = 0;
2907 service->stats_roaming.data.rx_bytes = 0;
2908 service->stats_roaming.data.tx_bytes = 0;
2909 service->stats_roaming.data.rx_errors = 0;
2910 service->stats_roaming.data.tx_errors = 0;
2911 service->stats_roaming.data.rx_dropped = 0;
2912 service->stats_roaming.data.tx_dropped = 0;
2913 service->stats_roaming.data.time = 0;
2914 service->stats_roaming.data_last.time = 0;
2916 g_timer_reset(service->stats_roaming.timer);
2919 #if defined TIZEN_EXT
2920 static gboolean __connman_service_is_internet_profile(
2921 struct connman_service *cellular)
2923 const char internet_suffix[] = "_1";
2925 DBG("Service path: %s", cellular->path);
2927 if (g_str_has_suffix(cellular->path, internet_suffix) == TRUE)
2933 struct connman_service *connman_service_get_default_connection(void)
2936 struct connman_service *service;
2937 struct connman_service *default_service = NULL;
2939 for (list = service_list; list; list = list->next) {
2940 service = list->data;
2942 DBG("service: %p %s %s %s", service, service->name,
2943 state2string(service->state),
2944 __connman_service_type2string(service->type));
2946 #if defined TIZEN_MAINTAIN_ONLINE
2947 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2948 service->state == CONNMAN_SERVICE_STATE_ONLINE) {
2950 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2951 is_connected(service->state) == TRUE) {
2954 } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2955 __connman_service_is_internet_profile(service) == TRUE) {
2956 if (default_service == NULL)
2957 default_service = service;
2958 else if (is_connected(service->state) == TRUE &&
2959 is_connected(default_service->state) == FALSE)
2960 default_service = service;
2961 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
2962 is_connected(service->state) == TRUE) {
2963 if (default_service == NULL)
2964 default_service = service;
2965 } else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH &&
2966 is_connected(service->state) == TRUE) {
2967 if (default_service == NULL)
2968 default_service = service;
2972 return default_service;
2975 struct connman_service *connman_service_get_connected_service(const char *ifname)
2978 const char *svc_ifname;
2979 struct connman_service *service;
2984 for (list = service_list; list; list = list->next) {
2985 service = list->data;
2987 if (!is_connected(service->state))
2990 svc_ifname = connman_device_get_string(
2991 connman_network_get_device(service->network), "Interface");
2993 if (svc_ifname && g_strcmp0(svc_ifname, ifname) == 0)
3001 struct connman_service *connman_service_get_default(void)
3003 #if defined TIZEN_MAINTAIN_ONLINE
3004 return connman_service_get_default_connection();
3006 struct connman_service *service;
3011 service = service_list->data;
3013 if (!is_connected(service->state))
3020 bool __connman_service_index_is_default(int index)
3022 struct connman_service *service;
3027 service = connman_service_get_default();
3029 return __connman_service_get_index(service) == index;
3032 static void start_wispr_when_connected(struct connman_service *service)
3034 if (!connman_setting_get_bool("EnableOnlineCheck")) {
3035 connman_info("Online check disabled. "
3036 "Default service remains in READY state.");
3040 if (__connman_service_is_connected_state(service,
3041 CONNMAN_IPCONFIG_TYPE_IPV4))
3042 __connman_service_wispr_start(service,
3043 CONNMAN_IPCONFIG_TYPE_IPV4);
3045 if (__connman_service_is_connected_state(service,
3046 CONNMAN_IPCONFIG_TYPE_IPV6))
3047 __connman_service_wispr_start(service,
3048 CONNMAN_IPCONFIG_TYPE_IPV6);
3051 static void default_changed(void)
3053 #if defined TIZEN_EXT
3054 struct connman_service *service = connman_service_get_default_connection();
3056 struct connman_service *service = connman_service_get_default();
3059 if (service == current_default)
3062 DBG("current default %p %s", current_default,
3063 current_default ? current_default->identifier : "");
3064 DBG("new default %p %s", service, service ? service->identifier : "");
3066 #if defined TIZEN_EXT
3067 current_default = service;
3069 __connman_service_timeserver_changed(service, NULL);
3071 __connman_service_timeserver_changed(current_default, NULL);
3073 current_default = service;
3077 if (service->hostname &&
3078 connman_setting_get_bool("AllowHostnameUpdates"))
3079 __connman_utsname_set_hostname(service->hostname);
3081 if (service->domainname &&
3082 connman_setting_get_bool("AllowDomainnameUpdates"))
3083 __connman_utsname_set_domainname(service->domainname);
3085 start_wispr_when_connected(service);
3088 * Connect VPN automatically when new default service
3089 * is set and connected, unless new default is VPN
3091 if (is_connected(service->state) &&
3092 service->type != CONNMAN_SERVICE_TYPE_VPN) {
3093 DBG("running vpn_auto_connect");
3098 __connman_notifier_default_changed(service);
3101 #if defined TIZEN_EXT
3102 static void append_struct(gpointer value, gpointer user_data);
3104 static void emit_state_changed_with_properties(struct connman_service *service)
3106 DBusMessage *signal;
3107 DBusMessageIter iter;
3112 signal = dbus_message_new_signal(service->path, CONNMAN_SERVICE_INTERFACE,
3113 "StateChangedProperties");
3117 dbus_message_iter_init_append(signal, &iter);
3118 append_struct(service, &iter);
3120 g_dbus_send_message(connection, signal);
3126 static void state_changed(struct connman_service *service)
3130 __connman_notifier_service_state_changed(service, service->state);
3132 str = state2string(service->state);
3136 #if !defined TIZEN_EXT
3137 if (!allow_property_changed(service))
3140 DBG(" %s, %s", str, service->path);
3143 connman_dbus_property_changed_basic(service->path,
3144 CONNMAN_SERVICE_INTERFACE, "State",
3145 DBUS_TYPE_STRING, &str);
3147 #if defined TIZEN_EXT
3148 emit_state_changed_with_properties(service);
3152 #if defined TIZEN_EXT
3153 static void connect_reason_changed(struct connman_service *service)
3155 struct connman_device *device;
3160 if (!allow_property_changed(service))
3163 if (TIZEN_INS_ENABLED) {
3164 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
3165 device = connman_network_get_device(service->network);
3167 bool need_save = false;
3169 need_save |= connman_device_set_last_user_selection_ident(device, service->identifier);
3170 need_save |= connman_device_set_last_user_selection_time(device, time(NULL));
3172 DBG("last user selection ident[%s] time[%ld]",
3173 connman_device_get_last_user_selection_ident(device),
3174 connman_device_get_last_user_selection_time(device));
3177 connman_device_save_last_user_selection(device);
3182 connman_dbus_property_changed_basic(service->path,
3183 CONNMAN_SERVICE_INTERFACE,
3186 &service->connect_reason);
3189 static void disconnection_requested_changed(struct connman_service *service)
3191 dbus_bool_t disconnection_requested;
3196 if (!allow_property_changed(service))
3199 disconnection_requested = service->disconnection_requested;
3200 connman_dbus_property_changed_basic(service->path,
3201 CONNMAN_SERVICE_INTERFACE,
3202 "DisconnectionRequested",
3204 &disconnection_requested);
3207 void connman_service_set_disconnection_requested(struct connman_service *service,
3208 bool disconnection_requested)
3210 if (service == NULL)
3213 service->disconnection_requested = disconnection_requested;
3214 disconnection_requested_changed(service);
3217 static void connman_service_emit_state(struct connman_service *service,
3218 enum connman_service_state state)
3221 enum connman_service_state cur_state = service->state;
3223 if (service->state != state)
3224 service->state = state;
3226 str = state2string(service->state);
3228 service->state = cur_state;
3232 DBG(" %s, %s", str, service->path);
3234 connman_dbus_property_changed_basic(service->path,
3235 CONNMAN_SERVICE_INTERFACE, "State",
3236 DBUS_TYPE_STRING, &str);
3238 emit_state_changed_with_properties(service);
3239 service->state = cur_state;
3242 void connman_service_notify_reconnection_roaming(struct connman_service *service)
3247 if (service->state != CONNMAN_SERVICE_STATE_READY &&
3248 service->state != CONNMAN_SERVICE_STATE_ONLINE)
3251 connman_service_emit_state(service, CONNMAN_SERVICE_STATE_CONFIGURATION);
3252 connman_service_emit_state(service, CONNMAN_SERVICE_STATE_READY);
3254 if (service->state == CONNMAN_SERVICE_STATE_ONLINE)
3255 connman_service_emit_state(service, CONNMAN_SERVICE_STATE_ONLINE);
3259 static void strength_changed(struct connman_service *service)
3261 if (service->strength == 0)
3264 if (!allow_property_changed(service))
3267 connman_dbus_property_changed_basic(service->path,
3268 CONNMAN_SERVICE_INTERFACE, "Strength",
3269 DBUS_TYPE_BYTE, &service->strength);
3272 #if defined TIZEN_EXT
3273 static bool update_last_connected_bssid(struct connman_service *service)
3275 const unsigned char *last_connected_bssid;
3277 if (!service->network)
3280 last_connected_bssid = connman_network_get_last_connected_bssid(service->network);
3281 if (memcmp(last_connected_bssid, invalid_bssid, WIFI_BSSID_LEN_MAX) == 0)
3284 if (memcmp(last_connected_bssid, service->last_connected_bssid, WIFI_BSSID_LEN_MAX) != 0) {
3285 memcpy(service->last_connected_bssid, last_connected_bssid, WIFI_BSSID_LEN_MAX);
3293 static void favorite_changed(struct connman_service *service)
3295 dbus_bool_t favorite;
3300 if (!allow_property_changed(service))
3303 favorite = service->favorite;
3304 connman_dbus_property_changed_basic(service->path,
3305 CONNMAN_SERVICE_INTERFACE, "Favorite",
3306 DBUS_TYPE_BOOLEAN, &favorite);
3309 static void immutable_changed(struct connman_service *service)
3311 dbus_bool_t immutable;
3316 if (!allow_property_changed(service))
3319 immutable = service->immutable;
3320 connman_dbus_property_changed_basic(service->path,
3321 CONNMAN_SERVICE_INTERFACE, "Immutable",
3322 DBUS_TYPE_BOOLEAN, &immutable);
3325 static void roaming_changed(struct connman_service *service)
3327 dbus_bool_t roaming;
3332 if (!allow_property_changed(service))
3335 roaming = service->roaming;
3336 connman_dbus_property_changed_basic(service->path,
3337 CONNMAN_SERVICE_INTERFACE, "Roaming",
3338 DBUS_TYPE_BOOLEAN, &roaming);
3341 static void autoconnect_changed(struct connman_service *service)
3343 dbus_bool_t autoconnect;
3348 if (!allow_property_changed(service))
3351 autoconnect = service->autoconnect;
3352 connman_dbus_property_changed_basic(service->path,
3353 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
3354 DBUS_TYPE_BOOLEAN, &autoconnect);
3357 bool connman_service_set_autoconnect(struct connman_service *service,
3360 if (service->autoconnect == autoconnect)
3363 service->autoconnect = autoconnect;
3364 autoconnect_changed(service);
3366 connman_network_set_autoconnect(service->network, autoconnect);
3371 static void append_security(DBusMessageIter *iter, void *user_data)
3373 struct connman_service *service = user_data;
3376 str = security2string(service->security);
3378 dbus_message_iter_append_basic(iter,
3379 DBUS_TYPE_STRING, &str);
3382 * Some access points incorrectly advertise WPS even when they
3383 * are configured as open or no security, so filter
3387 switch (service->security) {
3388 case CONNMAN_SERVICE_SECURITY_PSK:
3389 case CONNMAN_SERVICE_SECURITY_WPA:
3390 case CONNMAN_SERVICE_SECURITY_RSN:
3391 #if defined TIZEN_EXT
3392 case CONNMAN_SERVICE_SECURITY_SAE:
3395 dbus_message_iter_append_basic(iter,
3396 DBUS_TYPE_STRING, &str);
3398 #if defined TIZEN_EXT
3399 case CONNMAN_SERVICE_SECURITY_OWE:
3400 case CONNMAN_SERVICE_SECURITY_DPP:
3402 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3403 case CONNMAN_SERVICE_SECURITY_NONE:
3404 case CONNMAN_SERVICE_SECURITY_WEP:
3405 case CONNMAN_SERVICE_SECURITY_8021X:
3407 #if defined TIZEN_EXT
3413 if (service->wps_advertizing) {
3414 str = "wps_advertising";
3415 dbus_message_iter_append_basic(iter,
3416 DBUS_TYPE_STRING, &str);
3421 static void security_changed(struct connman_service *service)
3426 if (!allow_property_changed(service))
3429 connman_dbus_property_changed_array(service->path,
3430 CONNMAN_SERVICE_INTERFACE, "Security",
3431 DBUS_TYPE_STRING, append_security, service);
3434 static void append_ethernet(DBusMessageIter *iter, void *user_data)
3436 struct connman_service *service = user_data;
3438 if (service->ipconfig_ipv4)
3439 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
3441 else if (service->ipconfig_ipv6)
3442 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
3446 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3447 static void append_eap_over_ethernet(DBusMessageIter *iter, void *user_data)
3449 struct connman_service *service = user_data;
3452 val = service->use_eapol;
3453 connman_dbus_dict_append_basic(iter, "UseEapol",
3454 DBUS_TYPE_BOOLEAN, &val);
3455 if (service->use_eapol) {
3457 connman_dbus_dict_append_basic(iter, "EAP",
3458 DBUS_TYPE_STRING, &service->eap);
3460 if (service->identity)
3461 connman_dbus_dict_append_basic(iter, "Identity",
3462 DBUS_TYPE_STRING, &service->identity);
3464 if (service->anonymous_identity)
3465 connman_dbus_dict_append_basic(iter, "AnonymousIdentity",
3466 DBUS_TYPE_STRING, &service->anonymous_identity);
3468 if (service->ca_cert_file)
3469 connman_dbus_dict_append_basic(iter, "CACertFile",
3470 DBUS_TYPE_STRING, &service->ca_cert_file);
3472 if (service->client_cert_file)
3473 connman_dbus_dict_append_basic(iter, "ClientCertFile",
3474 DBUS_TYPE_STRING, &service->client_cert_file);
3476 if (service->private_key_file)
3477 connman_dbus_dict_append_basic(iter, "PrivateKeyFile",
3478 DBUS_TYPE_STRING, &service->private_key_file);
3480 if (service->phase2)
3481 connman_dbus_dict_append_basic(iter, "Phase2",
3482 DBUS_TYPE_STRING, &service->phase2);
3484 if (service->phase1)
3485 connman_dbus_dict_append_basic(iter, "Phase1",
3486 DBUS_TYPE_STRING, &service->phase1);
3488 if (service->pac_file)
3489 connman_dbus_dict_append_basic(iter, "PacFile",
3490 DBUS_TYPE_STRING, &service->pac_file);
3492 /* Should we include passphrase? */
3495 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3497 static void append_ipv4(DBusMessageIter *iter, void *user_data)
3499 struct connman_service *service = user_data;
3501 if (!is_connected(service->state_ipv4))
3504 if (service->ipconfig_ipv4)
3505 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
3508 static void append_ipv6(DBusMessageIter *iter, void *user_data)
3510 struct connman_service *service = user_data;
3512 if (!is_connected(service->state_ipv6))
3515 if (service->ipconfig_ipv6)
3516 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
3517 service->ipconfig_ipv4);
3520 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
3522 struct connman_service *service = user_data;
3524 if (service->ipconfig_ipv4)
3525 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
3529 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
3531 struct connman_service *service = user_data;
3533 if (service->ipconfig_ipv6)
3534 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
3538 static void append_nameservers(DBusMessageIter *iter,
3539 struct connman_service *service, char **servers)
3542 bool available = true;
3544 for (i = 0; servers[i]; i++) {
3546 available = nameserver_available(service,
3547 CONNMAN_IPCONFIG_TYPE_ALL,
3551 dbus_message_iter_append_basic(iter,
3552 DBUS_TYPE_STRING, &servers[i]);
3556 #if defined TIZEN_EXT
3557 static void append_nameserver_manual(DBusMessageIter *iter,
3558 struct connman_service *service, const char *server)
3560 bool available = true;
3563 available = nameserver_available(service,
3564 CONNMAN_IPCONFIG_TYPE_ALL, server);
3567 dbus_message_iter_append_basic(iter,
3568 DBUS_TYPE_STRING, &server);
3571 static void append_nameserver_dhcp(DBusMessageIter *iter,
3572 struct connman_service *service, const char *server)
3574 bool available = true;
3577 available = nameserver_available(service,
3578 CONNMAN_IPCONFIG_TYPE_ALL, server);
3581 dbus_message_iter_append_basic(iter,
3582 DBUS_TYPE_STRING, &server);
3586 static void append_dns(DBusMessageIter *iter, void *user_data)
3588 struct connman_service *service = user_data;
3589 #if defined TIZEN_EXT
3593 if (!is_connected(service->state))
3599 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
3601 char *str1 = g_strdup_printf("ipv4.%s", str);
3602 dbus_message_iter_append_basic(iter,
3603 DBUS_TYPE_STRING, &str1);
3607 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
3609 char *str1 = g_strdup_printf("ipv6.%s", str);
3610 dbus_message_iter_append_basic(iter,
3611 DBUS_TYPE_STRING, &str1);
3616 if (service->nameservers_config) {
3617 #if defined TIZEN_EXT
3619 while (service->nameservers_config[i]) {
3620 if (connman_inet_check_ipaddress(
3621 service->nameservers_config[i]) == AF_INET &&
3622 service->dns_config_method_ipv4 ==
3623 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
3624 append_nameserver_manual(iter, service,
3625 service->nameservers_config[i]);
3628 if (connman_inet_check_ipaddress(
3629 service->nameservers_config[i]) == AF_INET6 &&
3630 service->dns_config_method_ipv6 ==
3631 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
3632 append_nameserver_manual(iter, service,
3633 service->nameservers_config[i]);
3637 /* In case of mixed DNS Config Type one of IPv4/IPv6 can be
3638 * dynamic while other is static so try to append the DNS
3639 * Address which is dynamic also */
3640 if (service->nameservers != NULL) {
3642 while (service->nameservers[i]) {
3643 if (connman_inet_check_ipaddress(
3644 service->nameservers[i]) == AF_INET &&
3645 service->dns_config_method_ipv4 ==
3646 CONNMAN_DNSCONFIG_METHOD_DHCP) {
3647 append_nameserver_dhcp(iter, service,
3648 service->nameservers[i]);
3651 if (connman_inet_check_ipaddress(
3652 service->nameservers[i]) == AF_INET6 &&
3653 service->dns_config_method_ipv6 ==
3654 CONNMAN_DNSCONFIG_METHOD_DHCP) {
3655 append_nameserver_dhcp(iter, service,
3656 service->nameservers[i]);
3662 append_nameservers(iter, service, service->nameservers_config);
3666 if (service->nameservers)
3667 #if defined TIZEN_EXT
3670 while (service->nameservers[i]) {
3671 if (connman_inet_check_ipaddress(
3672 service->nameservers[i]) == AF_INET &&
3673 service->dns_config_method_ipv4 ==
3674 CONNMAN_DNSCONFIG_METHOD_DHCP) {
3675 append_nameserver_dhcp(iter, service,
3676 service->nameservers[i]);
3679 if (connman_inet_check_ipaddress(
3680 service->nameservers[i]) == AF_INET6 &&
3681 service->dns_config_method_ipv6 ==
3682 CONNMAN_DNSCONFIG_METHOD_DHCP) {
3683 append_nameserver_dhcp(iter, service,
3684 service->nameservers[i]);
3690 append_nameservers(iter, service,
3691 service->nameservers);
3694 if (service->nameservers_auto)
3695 append_nameservers(iter, service,
3696 service->nameservers_auto);
3698 if (!service->nameservers && !service->nameservers_auto) {
3701 DBG("append fallback nameservers");
3703 ns = connman_setting_get_string_list("FallbackNameservers");
3705 append_nameservers(iter, service, ns);
3710 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
3712 struct connman_service *service = user_data;
3715 /* Append DNS Config Type */
3717 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
3719 char *str1 = g_strdup_printf("ipv4.%s", str);
3720 dbus_message_iter_append_basic(iter,
3721 DBUS_TYPE_STRING, &str1);
3725 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
3727 char *str1 = g_strdup_printf("ipv6.%s", str);
3728 dbus_message_iter_append_basic(iter,
3729 DBUS_TYPE_STRING, &str1);
3734 if (!service->nameservers_config)
3737 #if defined TIZEN_EXT
3739 while (service->nameservers_config[i]) {
3740 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET &&
3741 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
3742 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
3745 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET6 &&
3746 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
3747 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
3752 append_nameservers(iter, NULL, service->nameservers_config);
3756 static void append_ts(DBusMessageIter *iter, void *user_data)
3758 GSList *list = user_data;
3761 char *timeserver = list->data;
3764 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
3767 list = g_slist_next(list);
3771 static void append_tsconfig(DBusMessageIter *iter, void *user_data)
3773 struct connman_service *service = user_data;
3776 if (!service->timeservers_config)
3779 for (i = 0; service->timeservers_config[i]; i++) {
3780 dbus_message_iter_append_basic(iter,
3782 &service->timeservers_config[i]);
3786 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
3788 struct connman_service *service = user_data;
3791 if (!service->domains)
3794 for (i = 0; service->domains[i]; i++)
3795 dbus_message_iter_append_basic(iter,
3796 DBUS_TYPE_STRING, &service->domains[i]);
3799 static void append_domain(DBusMessageIter *iter, void *user_data)
3801 struct connman_service *service = user_data;
3803 if (!is_connected(service->state) &&
3804 !is_connecting(service->state))
3807 if (service->domains)
3808 append_domainconfig(iter, user_data);
3809 else if (service->domainname)
3810 dbus_message_iter_append_basic(iter,
3811 DBUS_TYPE_STRING, &service->domainname);
3814 static void append_proxies(DBusMessageIter *iter, void *user_data)
3816 struct connman_service *service = user_data;
3819 if (!service->proxies)
3822 for (i = 0; service->proxies[i]; i++)
3823 dbus_message_iter_append_basic(iter,
3824 DBUS_TYPE_STRING, &service->proxies[i]);
3827 static void append_excludes(DBusMessageIter *iter, void *user_data)
3829 struct connman_service *service = user_data;
3832 if (!service->excludes)
3835 for (i = 0; service->excludes[i]; i++)
3836 dbus_message_iter_append_basic(iter,
3837 DBUS_TYPE_STRING, &service->excludes[i]);
3840 static void append_proxy(DBusMessageIter *iter, void *user_data)
3842 struct connman_service *service = user_data;
3843 enum connman_service_proxy_method proxy;
3844 const char *pac = NULL;
3845 const char *method = proxymethod2string(
3846 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
3848 if (!is_connected(service->state))
3851 proxy = connman_service_get_proxy_method(service);
3854 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
3856 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
3858 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
3859 connman_dbus_dict_append_array(iter, "Servers",
3860 DBUS_TYPE_STRING, append_proxies,
3863 connman_dbus_dict_append_array(iter, "Excludes",
3864 DBUS_TYPE_STRING, append_excludes,
3867 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
3868 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
3869 if (service->ipconfig_ipv4)
3870 pac = __connman_ipconfig_get_proxy_autoconfig(
3871 service->ipconfig_ipv4);
3872 else if (service->ipconfig_ipv6)
3873 pac = __connman_ipconfig_get_proxy_autoconfig(
3874 service->ipconfig_ipv6);
3876 if (!service->pac && !pac)
3882 connman_dbus_dict_append_basic(iter, "URL",
3883 DBUS_TYPE_STRING, &pac);
3887 method = proxymethod2string(proxy);
3890 connman_dbus_dict_append_basic(iter, "Method",
3891 DBUS_TYPE_STRING, &method);
3894 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
3896 struct connman_service *service = user_data;
3899 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
3902 switch (service->proxy_config) {
3903 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
3905 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
3907 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
3908 if (service->proxies)
3909 connman_dbus_dict_append_array(iter, "Servers",
3911 append_proxies, service);
3913 if (service->excludes)
3914 connman_dbus_dict_append_array(iter, "Excludes",
3916 append_excludes, service);
3918 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
3920 connman_dbus_dict_append_basic(iter, "URL",
3921 DBUS_TYPE_STRING, &service->pac);
3925 method = proxymethod2string(service->proxy_config);
3927 connman_dbus_dict_append_basic(iter, "Method",
3928 DBUS_TYPE_STRING, &method);
3931 static void append_provider(DBusMessageIter *iter, void *user_data)
3933 struct connman_service *service = user_data;
3935 if (!is_connected(service->state))
3938 if (service->provider)
3939 __connman_provider_append_properties(service->provider, iter);
3943 static void settings_changed(struct connman_service *service,
3944 struct connman_ipconfig *ipconfig)
3946 enum connman_ipconfig_type type;
3948 type = __connman_ipconfig_get_config_type(ipconfig);
3950 __connman_notifier_ipconfig_changed(service, ipconfig);
3952 if (!allow_property_changed(service))
3955 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
3956 connman_dbus_property_changed_dict(service->path,
3957 CONNMAN_SERVICE_INTERFACE, "IPv4",
3958 append_ipv4, service);
3959 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
3960 connman_dbus_property_changed_dict(service->path,
3961 CONNMAN_SERVICE_INTERFACE, "IPv6",
3962 append_ipv6, service);
3965 static void ipv4_configuration_changed(struct connman_service *service)
3967 if (!allow_property_changed(service))
3970 connman_dbus_property_changed_dict(service->path,
3971 CONNMAN_SERVICE_INTERFACE,
3972 "IPv4.Configuration",
3977 void __connman_service_notify_ipv4_configuration(
3978 struct connman_service *service)
3983 ipv4_configuration_changed(service);
3986 static void ipv6_configuration_changed(struct connman_service *service)
3988 if (!allow_property_changed(service))
3991 connman_dbus_property_changed_dict(service->path,
3992 CONNMAN_SERVICE_INTERFACE,
3993 "IPv6.Configuration",
3998 static void dns_changed(struct connman_service *service)
4000 if (!allow_property_changed(service))
4003 connman_dbus_property_changed_array(service->path,
4004 CONNMAN_SERVICE_INTERFACE, "Nameservers",
4005 DBUS_TYPE_STRING, append_dns, service);
4008 static void dns_configuration_changed(struct connman_service *service)
4010 if (!allow_property_changed(service))
4013 connman_dbus_property_changed_array(service->path,
4014 CONNMAN_SERVICE_INTERFACE,
4015 "Nameservers.Configuration",
4016 DBUS_TYPE_STRING, append_dnsconfig, service);
4018 dns_changed(service);
4021 static void domain_changed(struct connman_service *service)
4023 if (!allow_property_changed(service))
4026 connman_dbus_property_changed_array(service->path,
4027 CONNMAN_SERVICE_INTERFACE, "Domains",
4028 DBUS_TYPE_STRING, append_domain, service);
4031 static void domain_configuration_changed(struct connman_service *service)
4033 if (!allow_property_changed(service))
4036 connman_dbus_property_changed_array(service->path,
4037 CONNMAN_SERVICE_INTERFACE,
4038 "Domains.Configuration",
4039 DBUS_TYPE_STRING, append_domainconfig, service);
4042 static void proxy_changed(struct connman_service *service)
4044 if (!allow_property_changed(service))
4047 connman_dbus_property_changed_dict(service->path,
4048 CONNMAN_SERVICE_INTERFACE, "Proxy",
4049 append_proxy, service);
4052 static void proxy_configuration_changed(struct connman_service *service)
4054 if (!allow_property_changed(service))
4057 connman_dbus_property_changed_dict(service->path,
4058 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
4059 append_proxyconfig, service);
4061 proxy_changed(service);
4064 static void mdns_changed(struct connman_service *service)
4066 dbus_bool_t mdns = service->mdns;
4068 if (!allow_property_changed(service))
4071 connman_dbus_property_changed_basic(service->path,
4072 CONNMAN_SERVICE_INTERFACE, "mDNS", DBUS_TYPE_BOOLEAN,
4076 static void mdns_configuration_changed(struct connman_service *service)
4078 dbus_bool_t mdns_config = service->mdns_config;
4080 if (!allow_property_changed(service))
4083 connman_dbus_property_changed_basic(service->path,
4084 CONNMAN_SERVICE_INTERFACE, "mDNS.Configuration",
4085 DBUS_TYPE_BOOLEAN, &mdns_config);
4088 static int set_mdns(struct connman_service *service,
4093 result = __connman_resolver_set_mdns(
4094 __connman_service_get_index(service), enabled);
4097 if (service->mdns != enabled) {
4098 service->mdns = enabled;
4099 mdns_changed(service);
4106 static void timeservers_configuration_changed(struct connman_service *service)
4108 if (!allow_property_changed(service))
4111 connman_dbus_property_changed_array(service->path,
4112 CONNMAN_SERVICE_INTERFACE,
4113 "Timeservers.Configuration",
4115 append_tsconfig, service);
4118 static void link_changed(struct connman_service *service)
4120 if (!allow_property_changed(service))
4123 connman_dbus_property_changed_dict(service->path,
4124 CONNMAN_SERVICE_INTERFACE, "Ethernet",
4125 append_ethernet, service);
4128 static void stats_append_counters(DBusMessageIter *dict,
4129 struct connman_stats_data *stats,
4130 struct connman_stats_data *counters,
4133 if (counters->rx_packets != stats->rx_packets || append_all) {
4134 counters->rx_packets = stats->rx_packets;
4135 connman_dbus_dict_append_basic(dict, "RX.Packets",
4136 DBUS_TYPE_UINT32, &stats->rx_packets);
4139 if (counters->tx_packets != stats->tx_packets || append_all) {
4140 counters->tx_packets = stats->tx_packets;
4141 connman_dbus_dict_append_basic(dict, "TX.Packets",
4142 DBUS_TYPE_UINT32, &stats->tx_packets);
4145 if (counters->rx_bytes != stats->rx_bytes || append_all) {
4146 counters->rx_bytes = stats->rx_bytes;
4147 connman_dbus_dict_append_basic(dict, "RX.Bytes",
4148 DBUS_TYPE_UINT32, &stats->rx_bytes);
4151 if (counters->tx_bytes != stats->tx_bytes || append_all) {
4152 counters->tx_bytes = stats->tx_bytes;
4153 connman_dbus_dict_append_basic(dict, "TX.Bytes",
4154 DBUS_TYPE_UINT32, &stats->tx_bytes);
4157 if (counters->rx_errors != stats->rx_errors || append_all) {
4158 counters->rx_errors = stats->rx_errors;
4159 connman_dbus_dict_append_basic(dict, "RX.Errors",
4160 DBUS_TYPE_UINT32, &stats->rx_errors);
4163 if (counters->tx_errors != stats->tx_errors || append_all) {
4164 counters->tx_errors = stats->tx_errors;
4165 connman_dbus_dict_append_basic(dict, "TX.Errors",
4166 DBUS_TYPE_UINT32, &stats->tx_errors);
4169 if (counters->rx_dropped != stats->rx_dropped || append_all) {
4170 counters->rx_dropped = stats->rx_dropped;
4171 connman_dbus_dict_append_basic(dict, "RX.Dropped",
4172 DBUS_TYPE_UINT32, &stats->rx_dropped);
4175 if (counters->tx_dropped != stats->tx_dropped || append_all) {
4176 counters->tx_dropped = stats->tx_dropped;
4177 connman_dbus_dict_append_basic(dict, "TX.Dropped",
4178 DBUS_TYPE_UINT32, &stats->tx_dropped);
4181 if (counters->time != stats->time || append_all) {
4182 counters->time = stats->time;
4183 connman_dbus_dict_append_basic(dict, "Time",
4184 DBUS_TYPE_UINT32, &stats->time);
4188 static void stats_append(struct connman_service *service,
4189 const char *counter,
4190 struct connman_stats_counter *counters,
4193 DBusMessageIter array, dict;
4196 DBG("service %p counter %s", service, counter);
4198 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
4202 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
4203 &service->path, DBUS_TYPE_INVALID);
4205 dbus_message_iter_init_append(msg, &array);
4208 connman_dbus_dict_open(&array, &dict);
4210 stats_append_counters(&dict, &service->stats.data,
4211 &counters->stats.data, append_all);
4213 connman_dbus_dict_close(&array, &dict);
4215 /* roaming counter */
4216 connman_dbus_dict_open(&array, &dict);
4218 stats_append_counters(&dict, &service->stats_roaming.data,
4219 &counters->stats_roaming.data, append_all);
4221 connman_dbus_dict_close(&array, &dict);
4223 __connman_counter_send_usage(counter, msg);
4226 static void stats_update(struct connman_service *service,
4227 unsigned int rx_packets, unsigned int tx_packets,
4228 unsigned int rx_bytes, unsigned int tx_bytes,
4229 unsigned int rx_errors, unsigned int tx_errors,
4230 unsigned int rx_dropped, unsigned int tx_dropped)
4232 struct connman_stats *stats = stats_get(service);
4233 struct connman_stats_data *data_last = &stats->data_last;
4234 struct connman_stats_data *data = &stats->data;
4235 unsigned int seconds;
4237 DBG("service %p", service);
4241 rx_packets - data_last->rx_packets;
4243 tx_packets - data_last->tx_packets;
4245 rx_bytes - data_last->rx_bytes;
4247 tx_bytes - data_last->tx_bytes;
4249 rx_errors - data_last->rx_errors;
4251 tx_errors - data_last->tx_errors;
4253 rx_dropped - data_last->rx_dropped;
4255 tx_dropped - data_last->tx_dropped;
4257 stats->valid = true;
4260 data_last->rx_packets = rx_packets;
4261 data_last->tx_packets = tx_packets;
4262 data_last->rx_bytes = rx_bytes;
4263 data_last->tx_bytes = tx_bytes;
4264 data_last->rx_errors = rx_errors;
4265 data_last->tx_errors = tx_errors;
4266 data_last->rx_dropped = rx_dropped;
4267 data_last->tx_dropped = tx_dropped;
4269 seconds = g_timer_elapsed(stats->timer, NULL);
4270 stats->data.time = stats->data_last.time + seconds;
4273 void __connman_service_notify(struct connman_service *service,
4274 unsigned int rx_packets, unsigned int tx_packets,
4275 unsigned int rx_bytes, unsigned int tx_bytes,
4276 unsigned int rx_errors, unsigned int tx_errors,
4277 unsigned int rx_dropped, unsigned int tx_dropped)
4279 GHashTableIter iter;
4280 gpointer key, value;
4281 const char *counter;
4282 struct connman_stats_counter *counters;
4283 struct connman_stats_data *data;
4289 if (!is_connected(service->state))
4292 stats_update(service,
4293 rx_packets, tx_packets,
4295 rx_errors, tx_errors,
4296 rx_dropped, tx_dropped);
4298 data = &stats_get(service)->data;
4299 err = __connman_stats_update(service, service->roaming, data);
4301 connman_error("Failed to store statistics for %s",
4302 service->identifier);
4304 g_hash_table_iter_init(&iter, service->counter_table);
4305 while (g_hash_table_iter_next(&iter, &key, &value)) {
4309 stats_append(service, counter, counters, counters->append_all);
4310 counters->append_all = false;
4314 int __connman_service_counter_register(const char *counter)
4316 struct connman_service *service;
4318 struct connman_stats_counter *counters;
4320 DBG("counter %s", counter);
4322 counter_list = g_slist_prepend(counter_list, (gpointer)counter);
4324 for (list = service_list; list; list = list->next) {
4325 service = list->data;
4327 counters = g_try_new0(struct connman_stats_counter, 1);
4331 counters->append_all = true;
4333 g_hash_table_replace(service->counter_table, (gpointer)counter,
4340 void __connman_service_counter_unregister(const char *counter)
4342 struct connman_service *service;
4345 DBG("counter %s", counter);
4347 for (list = service_list; list; list = list->next) {
4348 service = list->data;
4350 g_hash_table_remove(service->counter_table, counter);
4353 counter_list = g_slist_remove(counter_list, counter);
4356 int connman_service_iterate_services(connman_service_iterate_cb cb,
4362 for (list = service_list; list && ret == 0; list = list->next)
4363 ret = cb((struct connman_service *)list->data, user_data);
4368 #if defined TIZEN_EXT
4369 static void append_security_list(DBusMessageIter *iter, void *user_data)
4371 GSList *sec_list = (GSList *)user_data;
4372 const char *sec_str;
4376 for (list = sec_list; list; list = list->next) {
4377 sec_str = (const char *)list->data;
4379 dbus_message_iter_append_basic(iter,
4380 DBUS_TYPE_STRING, &sec_str);
4385 static void append_wifi_ext_info(DBusMessageIter *dict,
4386 struct connman_network *network)
4388 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
4389 char *bssid_str = bssid_buff;
4391 unsigned int ssid_len;
4392 unsigned char *bssid;
4393 unsigned int maxrate;
4395 unsigned int keymgmt;
4397 const char *enc_mode;
4400 gboolean pmf_required;
4401 char country_code_buff[WIFI_COUNTRY_CODE_LEN + 1] = {0,};
4402 char *country_code_str = country_code_buff;
4403 unsigned char *country_code;
4404 uint16_t connection_mode;
4405 GSList *sec_list = NULL;
4407 ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
4408 bssid = connman_network_get_bssid(network);
4409 maxrate = connman_network_get_maxrate(network);
4410 maxspeed = connman_network_get_maxspeed(network);
4411 frequency = connman_network_get_frequency(network);
4412 enc_mode = connman_network_get_enc_mode(network);
4413 passpoint = connman_network_get_bool(network, "WiFi.HS20AP");
4414 keymgmt = connman_network_get_keymgmt(network);
4415 pmf_required = connman_network_get_bool(network, "WiFi.PMFRequired");
4416 country_code = connman_network_get_countrycode(network);
4417 connection_mode = connman_network_get_connection_mode(network);
4418 sec_list = (GSList *)connman_network_get_sec_list(network);
4420 snprintf(bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bssid));
4422 snprintf(country_code_str, (WIFI_COUNTRY_CODE_LEN + 1), "%c%c",
4423 country_code[0], country_code[1]);
4425 connman_dbus_dict_append_array(dict, "SecurityList",
4427 append_security_list, sec_list);
4429 connman_dbus_dict_append_fixed_array(dict, "SSID",
4430 DBUS_TYPE_BYTE, &ssid, ssid_len);
4431 connman_dbus_dict_append_basic(dict, "BSSID",
4432 DBUS_TYPE_STRING, &bssid_str);
4433 connman_dbus_dict_append_basic(dict, "MaxRate",
4434 DBUS_TYPE_UINT32, &maxrate);
4435 connman_dbus_dict_append_basic(dict, "MaxSpeed",
4436 DBUS_TYPE_INT32, &maxspeed);
4437 connman_dbus_dict_append_basic(dict, "Frequency",
4438 DBUS_TYPE_UINT16, &frequency);
4439 connman_dbus_dict_append_basic(dict, "EncryptionMode",
4440 DBUS_TYPE_STRING, &enc_mode);
4441 connman_dbus_dict_append_basic(dict, "Passpoint",
4442 DBUS_TYPE_BOOLEAN, &passpoint);
4443 connman_dbus_dict_append_basic(dict, "Keymgmt",
4444 DBUS_TYPE_UINT32, &keymgmt);
4445 connman_dbus_dict_append_basic(dict, "PmfReq",
4446 DBUS_TYPE_BOOLEAN, &pmf_required);
4447 connman_dbus_dict_append_basic(dict, "Country", DBUS_TYPE_STRING,
4449 connman_dbus_dict_append_basic(dict, "ConnMode",
4450 DBUS_TYPE_UINT16, &connection_mode);
4452 str = connman_network_get_string(network, "WiFi.Security");
4453 if (str != NULL && g_str_equal(str, "ieee8021x") == TRUE) {
4454 str = connman_network_get_string(network, "WiFi.EAP");
4456 connman_dbus_dict_append_basic(dict, "EAP",
4457 DBUS_TYPE_STRING, &str);
4459 str = connman_network_get_string(network, "WiFi.Phase2");
4461 connman_dbus_dict_append_basic(dict, "Phase2",
4462 DBUS_TYPE_STRING, &str);
4464 str = connman_network_get_string(network, "WiFi.Identity");
4466 connman_dbus_dict_append_basic(dict, "Identity",
4467 DBUS_TYPE_STRING, &str);
4469 str = connman_network_get_string(network, "WiFi.CACertFile");
4471 connman_dbus_dict_append_basic(dict, "CACertFile",
4472 DBUS_TYPE_STRING, &str);
4474 str = connman_network_get_string(network,
4475 "WiFi.ClientCertFile");
4477 connman_dbus_dict_append_basic(dict, "ClientCertFile",
4478 DBUS_TYPE_STRING, &str);
4480 str = connman_network_get_string(network,
4481 "WiFi.PrivateKeyFile");
4483 connman_dbus_dict_append_basic(dict, "PrivateKeyFile",
4484 DBUS_TYPE_STRING, &str);
4488 static void append_bssid_info(DBusMessageIter *iter, void *user_data)
4490 GSList *bssid_list = NULL;
4491 struct connman_network *network = user_data;
4492 struct connman_bssids *bssids;
4493 char bssid_buf[MAC_ADDRESS_LENGTH] = {0,};
4494 char *bssid_str = bssid_buf;
4496 bssid_list = (GSList *)connman_network_get_bssid_list(network);
4499 for (list = bssid_list; list; list = list->next) {
4500 bssids = (struct connman_bssids *)list->data;
4501 g_snprintf(bssid_buf, MAC_ADDRESS_LENGTH, MACSTR, MAC2STR(bssids->bssid));
4503 connman_dbus_dict_append_basic(iter, "BSSID",
4504 DBUS_TYPE_STRING, &bssid_str);
4506 connman_dbus_dict_append_basic(iter, "Strength",
4507 DBUS_TYPE_UINT16, &bssids->strength);
4509 connman_dbus_dict_append_basic(iter, "Frequency",
4510 DBUS_TYPE_UINT16, &bssids->frequency);
4516 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
4517 struct connman_service *service)
4523 #if defined TIZEN_EXT
4524 unsigned int frequency = 0U;
4525 unsigned char *wifi_vsie;
4526 unsigned int wifi_vsie_len;
4527 GSList *vsie_list = NULL;
4529 if (service->network) {
4530 frequency = connman_network_get_frequency(service->network);
4531 connman_dbus_dict_append_basic(dict, "Frequency",
4532 DBUS_TYPE_UINT16, &frequency);
4533 vsie_list = (GSList *)connman_network_get_vsie_list(service->network);
4538 for (list = vsie_list; list; list = list->next) {
4539 wifi_vsie = (unsigned char *)list->data;
4540 wifi_vsie_len = wifi_vsie[1] + 2;
4542 connman_dbus_dict_append_fixed_array(dict, "Vsie", DBUS_TYPE_BYTE,
4543 &wifi_vsie, wifi_vsie_len);
4548 str = __connman_service_type2string(service->type);
4550 connman_dbus_dict_append_basic(dict, "Type",
4551 DBUS_TYPE_STRING, &str);
4553 connman_dbus_dict_append_array(dict, "Security",
4554 DBUS_TYPE_STRING, append_security, service);
4556 str = state2string(service->state);
4558 connman_dbus_dict_append_basic(dict, "State",
4559 DBUS_TYPE_STRING, &str);
4562 str = state2string(service->state_ipv6);
4564 connman_dbus_dict_append_basic(dict, "StateIPv6",
4565 DBUS_TYPE_STRING, &str);
4568 str = error2string(service->error);
4570 connman_dbus_dict_append_basic(dict, "Error",
4571 DBUS_TYPE_STRING, &str);
4573 if (service->strength > 0)
4574 connman_dbus_dict_append_basic(dict, "Strength",
4575 DBUS_TYPE_BYTE, &service->strength);
4577 val = service->favorite;
4578 connman_dbus_dict_append_basic(dict, "Favorite",
4579 DBUS_TYPE_BOOLEAN, &val);
4581 val = service->immutable;
4582 connman_dbus_dict_append_basic(dict, "Immutable",
4583 DBUS_TYPE_BOOLEAN, &val);
4585 if (service->favorite)
4586 val = service->autoconnect;
4588 val = service->favorite;
4590 connman_dbus_dict_append_basic(dict, "AutoConnect",
4591 DBUS_TYPE_BOOLEAN, &val);
4594 connman_dbus_dict_append_basic(dict, "Name",
4595 DBUS_TYPE_STRING, &service->name);
4597 switch (service->type) {
4598 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4599 case CONNMAN_SERVICE_TYPE_SYSTEM:
4600 case CONNMAN_SERVICE_TYPE_GPS:
4601 case CONNMAN_SERVICE_TYPE_VPN:
4602 case CONNMAN_SERVICE_TYPE_P2P:
4603 #if defined TIZEN_EXT_WIFI_MESH
4604 case CONNMAN_SERVICE_TYPE_MESH:
4607 case CONNMAN_SERVICE_TYPE_CELLULAR:
4608 val = service->roaming;
4609 connman_dbus_dict_append_basic(dict, "Roaming",
4610 DBUS_TYPE_BOOLEAN, &val);
4612 connman_dbus_dict_append_dict(dict, "Ethernet",
4613 append_ethernet, service);
4615 case CONNMAN_SERVICE_TYPE_WIFI:
4616 #if defined TIZEN_EXT
4617 if (service->network != NULL) {
4618 append_wifi_ext_info(dict, service->network);
4619 connman_dbus_dict_append_dict(dict, "BSSID.List",
4620 append_bssid_info, service->network);
4623 connman_dbus_dict_append_dict(dict, "Ethernet",
4624 append_ethernet, service);
4626 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
4627 connman_dbus_dict_append_basic(dict, "DisconnectReason",
4628 DBUS_TYPE_INT32, &service->disconnect_reason);
4630 connman_dbus_dict_append_basic(dict, "AssocStatusCode",
4631 DBUS_TYPE_INT32, &service->assoc_status_code);
4633 val = service->hidden_service;
4634 connman_dbus_dict_append_basic(dict, "Hidden",
4635 DBUS_TYPE_BOOLEAN, &val);
4639 case CONNMAN_SERVICE_TYPE_ETHERNET:
4640 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4641 connman_dbus_dict_append_dict(dict, "EapOverEthernet",
4642 append_eap_over_ethernet, service);
4644 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4645 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4646 case CONNMAN_SERVICE_TYPE_GADGET:
4647 connman_dbus_dict_append_dict(dict, "Ethernet",
4648 append_ethernet, service);
4652 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
4654 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
4655 append_ipv4config, service);
4657 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
4659 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
4660 append_ipv6config, service);
4662 connman_dbus_dict_append_array(dict, "Nameservers",
4663 DBUS_TYPE_STRING, append_dns, service);
4665 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
4666 DBUS_TYPE_STRING, append_dnsconfig, service);
4668 if (service->state == CONNMAN_SERVICE_STATE_READY ||
4669 service->state == CONNMAN_SERVICE_STATE_ONLINE)
4670 list = __connman_timeserver_get_all(service);
4674 connman_dbus_dict_append_array(dict, "Timeservers",
4675 DBUS_TYPE_STRING, append_ts, list);
4677 g_slist_free_full(list, g_free);
4679 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
4680 DBUS_TYPE_STRING, append_tsconfig, service);
4682 connman_dbus_dict_append_array(dict, "Domains",
4683 DBUS_TYPE_STRING, append_domain, service);
4685 connman_dbus_dict_append_array(dict, "Domains.Configuration",
4686 DBUS_TYPE_STRING, append_domainconfig, service);
4688 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
4690 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
4691 append_proxyconfig, service);
4693 val = service->mdns;
4694 connman_dbus_dict_append_basic(dict, "mDNS", DBUS_TYPE_BOOLEAN,
4697 val = service->mdns_config;
4698 connman_dbus_dict_append_basic(dict, "mDNS.Configuration",
4699 DBUS_TYPE_BOOLEAN, &val);
4701 connman_dbus_dict_append_dict(dict, "Provider",
4702 append_provider, service);
4704 if (service->network)
4705 connman_network_append_acddbus(dict, service->network);
4708 #if defined TIZEN_EXT
4709 static void append_ins_bssid_info(DBusMessageIter *iter, void *user_data)
4711 GSList *bssid_list = NULL;
4712 struct connman_network *network = user_data;
4713 struct connman_bssids *bssids;
4714 char bssid_buf[MAC_ADDRESS_LENGTH] = {0,};
4715 char *bssid_str = bssid_buf;
4717 bssid_list = (GSList *)connman_network_get_bssid_list(network);
4720 for (list = bssid_list; list; list = list->next) {
4721 bssids = (struct connman_bssids *)list->data;
4722 g_snprintf(bssid_buf, MAC_ADDRESS_LENGTH, MACSTR, MAC2STR(bssids->bssid));
4724 connman_dbus_dict_append_basic(iter, "BSSID",
4725 DBUS_TYPE_STRING, &bssid_str);
4727 connman_dbus_dict_append_basic(iter, "ScoreINS",
4728 DBUS_TYPE_INT32, &bssids->ins_score);
4730 connman_dbus_dict_append_basic(iter, "ScoreLastConnected",
4731 DBUS_TYPE_INT32, &bssids->score_last_connected_bssid);
4733 connman_dbus_dict_append_basic(iter, "ScoreAssocReject",
4734 DBUS_TYPE_INT32, &bssids->score_assoc_reject);
4736 connman_dbus_dict_append_basic(iter, "Frequency",
4737 DBUS_TYPE_UINT16, &bssids->frequency);
4739 connman_dbus_dict_append_basic(iter, "ScoreFrequency",
4740 DBUS_TYPE_INT32, &bssids->score_frequency);
4742 connman_dbus_dict_append_basic(iter, "Strength",
4743 DBUS_TYPE_UINT16, &bssids->strength);
4745 connman_dbus_dict_append_basic(iter, "ScoreStrength",
4746 DBUS_TYPE_INT32, &bssids->score_strength);
4751 static void append_ins_properties(DBusMessageIter *dict,
4752 struct connman_service *service)
4755 unsigned int frequency = 0U;
4758 connman_dbus_dict_append_basic(dict, "Name",
4759 DBUS_TYPE_STRING, &service->name);
4761 connman_dbus_dict_append_basic(dict, "ScoreINS",
4762 DBUS_TYPE_INT32, &service->ins_score);
4764 connman_dbus_dict_append_basic(dict, "ScoreLastUserSelection",
4765 DBUS_TYPE_INT32, &service->score_last_user_selection);
4767 connman_dbus_dict_append_basic(dict, "ScoreLastConnected",
4768 DBUS_TYPE_INT32, &service->score_last_connected);
4770 str = security2string(service->security);
4772 connman_dbus_dict_append_basic(dict, "Security",
4773 DBUS_TYPE_STRING, &str);
4775 connman_dbus_dict_append_basic(dict, "ScoreSecurityPriority",
4776 DBUS_TYPE_INT32, &service->score_security_priority);
4778 connman_dbus_dict_append_basic(dict, "Strength",
4779 DBUS_TYPE_BYTE, &service->strength);
4781 connman_dbus_dict_append_basic(dict, "ScoreStrength",
4782 DBUS_TYPE_INT32, &service->score_strength);
4784 connman_dbus_dict_append_basic(dict, "ScoreInternetConnection",
4785 DBUS_TYPE_INT32, &service->score_internet_connection);
4787 if (service->network) {
4788 frequency = connman_network_get_frequency(service->network);
4789 connman_dbus_dict_append_basic(dict, "Frequency",
4790 DBUS_TYPE_UINT16, &frequency);
4792 connman_dbus_dict_append_basic(dict, "ScoreFrequency",
4793 DBUS_TYPE_INT32, &service->score_frequency);
4795 connman_dbus_dict_append_dict(dict, "BSSID.List",
4796 append_ins_bssid_info, service->network);
4799 #endif /* defined TIZEN_EXT */
4801 static void append_struct_service(DBusMessageIter *iter,
4802 connman_dbus_append_cb_t function,
4803 struct connman_service *service)
4805 DBusMessageIter entry, dict;
4807 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
4809 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
4812 connman_dbus_dict_open(&entry, &dict);
4814 function(&dict, service);
4815 connman_dbus_dict_close(&entry, &dict);
4817 dbus_message_iter_close_container(iter, &entry);
4820 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
4822 struct connman_service *service = user_data;
4824 append_properties(dict, TRUE, service);
4827 static void append_struct(gpointer value, gpointer user_data)
4829 struct connman_service *service = value;
4830 DBusMessageIter *iter = user_data;
4835 append_struct_service(iter, append_dict_properties, service);
4838 #if defined TIZEN_EXT
4839 static void append_dict_ins_properties(DBusMessageIter *dict, void *user_data)
4841 struct connman_service *service = user_data;
4843 append_ins_properties(dict, service);
4846 static void append_ins_struct(gpointer value, gpointer user_data)
4848 struct connman_service *service = value;
4849 DBusMessageIter *iter = user_data;
4854 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
4857 append_struct_service(iter, append_dict_ins_properties, service);
4860 void __connman_ins_list_struct(DBusMessageIter *iter)
4862 g_list_foreach(service_list, append_ins_struct, iter);
4864 #endif /* defined TIZEN_EXT */
4866 void __connman_service_list_struct(DBusMessageIter *iter)
4868 g_list_foreach(service_list, append_struct, iter);
4871 bool __connman_service_is_hidden(struct connman_service *service)
4873 return service->hidden;
4877 __connman_service_is_split_routing(struct connman_service *service)
4879 return service->do_split_routing;
4882 bool __connman_service_index_is_split_routing(int index)
4884 struct connman_service *service;
4889 service = __connman_service_lookup_from_index(index);
4893 return __connman_service_is_split_routing(service);
4896 int __connman_service_get_index(struct connman_service *service)
4901 if (service->network)
4902 return connman_network_get_index(service->network);
4903 else if (service->provider)
4904 return connman_provider_get_index(service->provider);
4909 void __connman_service_set_hidden(struct connman_service *service)
4911 if (!service || service->hidden)
4914 service->hidden_service = true;
4917 void __connman_service_set_hostname(struct connman_service *service,
4918 const char *hostname)
4920 if (!service || service->hidden)
4923 g_free(service->hostname);
4924 service->hostname = NULL;
4926 if (hostname && g_str_is_ascii(hostname))
4927 service->hostname = g_strdup(hostname);
4930 const char *__connman_service_get_hostname(struct connman_service *service)
4935 return service->hostname;
4938 void __connman_service_set_domainname(struct connman_service *service,
4939 const char *domainname)
4941 if (!service || service->hidden)
4944 g_free(service->domainname);
4945 service->domainname = NULL;
4947 if (domainname && g_str_is_ascii(domainname))
4948 service->domainname = g_strdup(domainname);
4950 domain_changed(service);
4953 const char *connman_service_get_domainname(struct connman_service *service)
4958 if (service->domains)
4959 return service->domains[0];
4961 return service->domainname;
4964 const char *connman_service_get_dbuspath(struct connman_service *service)
4969 return service->path;
4972 char **connman_service_get_nameservers(struct connman_service *service)
4977 if (service->nameservers_config)
4978 return g_strdupv(service->nameservers_config);
4979 else if (service->nameservers ||
4980 service->nameservers_auto) {
4981 int len = 0, len_auto = 0, i;
4984 if (service->nameservers)
4985 len = g_strv_length(service->nameservers);
4986 if (service->nameservers_auto)
4987 len_auto = g_strv_length(service->nameservers_auto);
4989 nameservers = g_try_new0(char *, len + len_auto + 1);
4993 for (i = 0; i < len; i++)
4994 nameservers[i] = g_strdup(service->nameservers[i]);
4996 for (i = 0; i < len_auto; i++)
4997 nameservers[i + len] =
4998 g_strdup(service->nameservers_auto[i]);
5003 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
5006 char **connman_service_get_timeservers_config(struct connman_service *service)
5011 return service->timeservers_config;
5014 char **connman_service_get_timeservers(struct connman_service *service)
5019 return service->timeservers;
5022 #if defined TIZEN_EXT
5024 * Description: Telephony plug-in requires manual PROXY setting function
5026 int connman_service_set_proxy(struct connman_service *service,
5027 const char *proxy, gboolean active)
5029 char **proxies_array = NULL;
5031 if (service == NULL)
5034 switch (service->type) {
5035 case CONNMAN_SERVICE_TYPE_CELLULAR:
5036 case CONNMAN_SERVICE_TYPE_ETHERNET:
5037 case CONNMAN_SERVICE_TYPE_WIFI:
5044 g_strfreev(service->proxies);
5045 service->proxies = NULL;
5048 proxies_array = g_strsplit(proxy, " ", 0);
5050 service->proxies = proxies_array;
5052 if (proxy == NULL) {
5053 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
5054 DBG("proxy changed (%d)", active);
5056 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
5057 DBG("proxy chagned %s (%d)", proxy, active);
5060 if (active == TRUE) {
5061 proxy_changed(service);
5063 __connman_notifier_proxy_changed(service);
5070 void connman_service_set_proxy_method(struct connman_service *service,
5071 enum connman_service_proxy_method method)
5073 if (!service || service->hidden)
5076 service->proxy = method;
5078 proxy_changed(service);
5080 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
5081 __connman_notifier_proxy_changed(service);
5084 enum connman_service_proxy_method connman_service_get_proxy_method(
5085 struct connman_service *service)
5088 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
5090 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
5091 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
5093 return service->proxy;
5095 return service->proxy_config;
5098 return service->proxy;
5101 char **connman_service_get_proxy_servers(struct connman_service *service)
5103 return g_strdupv(service->proxies);
5106 char **connman_service_get_proxy_excludes(struct connman_service *service)
5108 return g_strdupv(service->excludes);
5111 const char *connman_service_get_proxy_url(struct connman_service *service)
5116 return service->pac;
5119 #if defined TIZEN_EXT
5120 void connman_service_set_internet_connection(struct connman_service *service,
5121 bool internet_connection)
5126 if (service->is_internet_connection != internet_connection) {
5127 service->is_internet_connection = internet_connection;
5129 g_get_current_time((GTimeVal *)&service->modified);
5130 service_save(service);
5134 bool connman_service_get_internet_connection(struct connman_service *service)
5139 return service->is_internet_connection;
5142 DBusMessage *connman_service_create_dbus_service_reply(DBusMessage *msg,
5143 struct connman_service *service)
5146 DBusMessageIter array, dict;
5148 reply = dbus_message_new_method_return(msg);
5152 dbus_message_iter_init_append(reply, &array);
5155 dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
5158 connman_dbus_dict_open(&array, &dict);
5160 append_properties(&dict, FALSE, service);
5161 connman_dbus_dict_close(&array, &dict);
5167 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
5170 if (!service || service->hidden)
5173 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
5175 if (service->ipconfig_ipv4) {
5176 if (__connman_ipconfig_set_proxy_autoconfig(
5177 service->ipconfig_ipv4, url) < 0)
5179 } else if (service->ipconfig_ipv6) {
5180 if (__connman_ipconfig_set_proxy_autoconfig(
5181 service->ipconfig_ipv6, url) < 0)
5186 proxy_changed(service);
5188 __connman_notifier_proxy_changed(service);
5191 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
5196 if (service->ipconfig_ipv4)
5197 return __connman_ipconfig_get_proxy_autoconfig(
5198 service->ipconfig_ipv4);
5199 else if (service->ipconfig_ipv6)
5200 return __connman_ipconfig_get_proxy_autoconfig(
5201 service->ipconfig_ipv6);
5205 #if defined TIZEN_EXT
5206 int connman_service_get_ipv6_dns_method(struct connman_service *service)
5209 DBG("Service is NULL");
5213 return service->dns_config_method_ipv6;
5217 void __connman_service_set_timeservers(struct connman_service *service,
5225 g_strfreev(service->timeservers);
5226 service->timeservers = NULL;
5228 for (i = 0; timeservers && timeservers[i]; i++)
5229 __connman_service_timeserver_append(service, timeservers[i]);
5232 int __connman_service_timeserver_append(struct connman_service *service,
5233 const char *timeserver)
5237 DBG("service %p timeserver %s", service, timeserver);
5242 if (service->timeservers) {
5245 for (i = 0; service->timeservers[i]; i++)
5246 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
5249 len = g_strv_length(service->timeservers);
5250 service->timeservers = g_try_renew(char *, service->timeservers,
5254 service->timeservers = g_try_new0(char *, len + 2);
5257 if (!service->timeservers)
5260 service->timeservers[len] = g_strdup(timeserver);
5261 service->timeservers[len + 1] = NULL;
5266 int __connman_service_timeserver_remove(struct connman_service *service,
5267 const char *timeserver)
5270 int len, i, j, found = 0;
5272 DBG("service %p timeserver %s", service, timeserver);
5277 if (!service->timeservers)
5280 for (i = 0; service->timeservers &&
5281 service->timeservers[i]; i++)
5282 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
5290 len = g_strv_length(service->timeservers);
5293 g_strfreev(service->timeservers);
5294 service->timeservers = NULL;
5299 servers = g_try_new0(char *, len);
5303 for (i = 0, j = 0; i < len; i++) {
5304 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
5305 servers[j] = g_strdup(service->timeservers[i]);
5311 servers[len - 1] = NULL;
5313 g_strfreev(service->timeservers);
5314 service->timeservers = servers;
5319 void __connman_service_timeserver_changed(struct connman_service *service,
5325 if (!allow_property_changed(service))
5328 connman_dbus_property_changed_array(service->path,
5329 CONNMAN_SERVICE_INTERFACE, "Timeservers",
5330 DBUS_TYPE_STRING, append_ts, ts_list);
5333 void __connman_service_set_pac(struct connman_service *service,
5336 if (service->hidden)
5338 g_free(service->pac);
5339 service->pac = g_strdup(pac);
5341 proxy_changed(service);
5344 #if defined TIZEN_EXT
5345 void __connman_service_set_proxy(struct connman_service *service,
5346 const char *proxies)
5348 char **proxies_array = NULL;
5350 g_strfreev(service->proxies);
5351 service->proxies = NULL;
5353 if (proxies != NULL)
5354 proxies_array = g_strsplit(proxies, " ", 0);
5356 service->proxies = proxies_array;
5360 void __connman_service_set_identity(struct connman_service *service,
5361 const char *identity)
5363 if (service->immutable || service->hidden)
5366 g_free(service->identity);
5367 service->identity = g_strdup(identity);
5369 if (service->network)
5370 connman_network_set_string(service->network,
5375 void __connman_service_set_anonymous_identity(struct connman_service *service,
5376 const char *anonymous_identity)
5378 if (service->immutable || service->hidden)
5381 g_free(service->anonymous_identity);
5382 service->anonymous_identity = g_strdup(anonymous_identity);
5384 if (service->network)
5385 connman_network_set_string(service->network,
5386 "WiFi.AnonymousIdentity",
5387 service->anonymous_identity);
5390 void __connman_service_set_subject_match(struct connman_service *service,
5391 const char *subject_match)
5393 if (service->immutable || service->hidden)
5396 g_free(service->subject_match);
5397 service->subject_match = g_strdup(subject_match);
5399 if (service->network)
5400 connman_network_set_string(service->network,
5401 "WiFi.SubjectMatch",
5402 service->subject_match);
5405 void __connman_service_set_altsubject_match(struct connman_service *service,
5406 const char *altsubject_match)
5408 if (service->immutable || service->hidden)
5411 g_free(service->altsubject_match);
5412 service->altsubject_match = g_strdup(altsubject_match);
5414 if (service->network)
5415 connman_network_set_string(service->network,
5416 "WiFi.AltSubjectMatch",
5417 service->altsubject_match);
5420 void __connman_service_set_domain_suffix_match(struct connman_service *service,
5421 const char *domain_suffix_match)
5423 if (service->immutable || service->hidden)
5426 g_free(service->domain_suffix_match);
5427 service->domain_suffix_match = g_strdup(domain_suffix_match);
5429 if (service->network)
5430 connman_network_set_string(service->network,
5431 "WiFi.DomainSuffixMatch",
5432 service->domain_suffix_match);
5435 void __connman_service_set_domain_match(struct connman_service *service,
5436 const char *domain_match)
5438 if (service->immutable || service->hidden)
5441 g_free(service->domain_match);
5442 service->domain_match = g_strdup(domain_match);
5444 if (service->network)
5445 connman_network_set_string(service->network,
5447 service->domain_match);
5450 void __connman_service_set_agent_identity(struct connman_service *service,
5451 const char *agent_identity)
5453 if (service->hidden)
5455 g_free(service->agent_identity);
5456 service->agent_identity = g_strdup(agent_identity);
5458 if (service->network)
5459 connman_network_set_string(service->network,
5460 "WiFi.AgentIdentity",
5461 service->agent_identity);
5464 int __connman_service_check_passphrase(enum connman_service_security security,
5465 const char *passphrase)
5473 length = strlen(passphrase);
5476 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
5477 case CONNMAN_SERVICE_SECURITY_NONE:
5478 case CONNMAN_SERVICE_SECURITY_WPA:
5479 #if !defined TIZEN_EXT
5480 case CONNMAN_SERVICE_SECURITY_RSN:
5483 DBG("service security '%s' (%d) not handled",
5484 security2string(security), security);
5488 case CONNMAN_SERVICE_SECURITY_PSK:
5489 #if defined TIZEN_EXT
5490 case CONNMAN_SERVICE_SECURITY_RSN:
5491 /* TO CHECK: We need to check the key length supported by SAE */
5492 case CONNMAN_SERVICE_SECURITY_SAE:
5494 /* A raw key is always 64 bytes length,
5495 * its content is in hex representation.
5496 * A PSK key must be between [8..63].
5499 for (i = 0; i < 64; i++)
5500 if (!isxdigit((unsigned char)
5503 } else if (length < 8 || length > 63)
5506 case CONNMAN_SERVICE_SECURITY_WEP:
5507 /* length of WEP key is 10 or 26
5508 * length of WEP passphrase is 5 or 13
5510 if (length == 10 || length == 26) {
5511 for (i = 0; i < length; i++)
5512 if (!isxdigit((unsigned char)
5515 } else if (length != 5 && length != 13)
5519 case CONNMAN_SERVICE_SECURITY_8021X:
5520 #if defined TIZEN_EXT
5521 case CONNMAN_SERVICE_SECURITY_OWE:
5522 case CONNMAN_SERVICE_SECURITY_DPP:
5531 int __connman_service_set_passphrase(struct connman_service *service,
5532 const char *passphrase)
5536 if (service->hidden)
5539 if (service->immutable &&
5540 service->security != CONNMAN_SERVICE_SECURITY_8021X)
5543 #if defined TIZEN_EXT
5544 if (service->immutable &&
5545 service->security != CONNMAN_SERVICE_SECURITY_DPP)
5547 /* The encrypted passphrase is used here
5548 * and validation is done by net-config before being encrypted.
5551 if (service->security != CONNMAN_SERVICE_SECURITY_PSK &&
5552 service->security != CONNMAN_SERVICE_SECURITY_RSN &&
5553 service->security != CONNMAN_SERVICE_SECURITY_SAE &&
5554 service->security != CONNMAN_SERVICE_SECURITY_WEP)
5556 err = __connman_service_check_passphrase(service->security, passphrase);
5561 g_free(service->passphrase);
5562 service->passphrase = g_strdup(passphrase);
5564 if (service->network)
5565 connman_network_set_string(service->network, "WiFi.Passphrase",
5566 service->passphrase);
5571 const char *__connman_service_get_passphrase(struct connman_service *service)
5576 return service->passphrase;
5579 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5580 int __connman_service_get_use_eapol(struct connman_service *service)
5583 DBG("Service is NULL");
5587 return service->use_eapol;
5590 int __connman_service_get_connect_reason(struct connman_service *service)
5593 DBG("Service is NULL");
5597 return service->connect_reason;
5599 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5601 static DBusMessage *get_properties(DBusConnection *conn,
5602 DBusMessage *msg, void *user_data)
5604 struct connman_service *service = user_data;
5606 DBusMessageIter array, dict;
5608 reply = dbus_message_new_method_return(msg);
5612 dbus_message_iter_init_append(reply, &array);
5614 connman_dbus_dict_open(&array, &dict);
5615 append_properties(&dict, FALSE, service);
5616 connman_dbus_dict_close(&array, &dict);
5621 static char **remove_empty_strings(char **strv)
5628 strv[index++] = *iter;
5638 static int update_proxy_configuration(struct connman_service *service,
5639 DBusMessageIter *array)
5641 DBusMessageIter dict;
5642 enum connman_service_proxy_method method;
5643 GString *servers_str = NULL;
5644 GString *excludes_str = NULL;
5645 const char *url = NULL;
5647 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
5649 dbus_message_iter_recurse(array, &dict);
5651 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
5652 DBusMessageIter entry, variant;
5656 dbus_message_iter_recurse(&dict, &entry);
5658 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
5661 dbus_message_iter_get_basic(&entry, &key);
5662 dbus_message_iter_next(&entry);
5664 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
5667 dbus_message_iter_recurse(&entry, &variant);
5669 type = dbus_message_iter_get_arg_type(&variant);
5671 if (g_str_equal(key, "Method")) {
5674 if (type != DBUS_TYPE_STRING)
5677 dbus_message_iter_get_basic(&variant, &val);
5678 method = string2proxymethod(val);
5679 } else if (g_str_equal(key, "URL")) {
5680 if (type != DBUS_TYPE_STRING)
5683 dbus_message_iter_get_basic(&variant, &url);
5684 } else if (g_str_equal(key, "Servers")) {
5685 DBusMessageIter str_array;
5687 if (type != DBUS_TYPE_ARRAY)
5690 servers_str = g_string_new(NULL);
5694 dbus_message_iter_recurse(&variant, &str_array);
5696 while (dbus_message_iter_get_arg_type(&str_array) ==
5700 dbus_message_iter_get_basic(&str_array, &val);
5702 if (servers_str->len > 0)
5703 g_string_append_printf(servers_str,
5706 g_string_append(servers_str, val);
5708 dbus_message_iter_next(&str_array);
5710 } else if (g_str_equal(key, "Excludes")) {
5711 DBusMessageIter str_array;
5713 if (type != DBUS_TYPE_ARRAY)
5716 excludes_str = g_string_new(NULL);
5720 dbus_message_iter_recurse(&variant, &str_array);
5722 while (dbus_message_iter_get_arg_type(&str_array) ==
5726 dbus_message_iter_get_basic(&str_array, &val);
5728 if (excludes_str->len > 0)
5729 g_string_append_printf(excludes_str,
5732 g_string_append(excludes_str, val);
5734 dbus_message_iter_next(&str_array);
5738 dbus_message_iter_next(&dict);
5742 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
5744 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
5745 if (!servers_str && !service->proxies)
5749 g_strfreev(service->proxies);
5751 if (servers_str->len > 0) {
5752 char **proxies = g_strsplit_set(
5753 servers_str->str, " ", 0);
5754 proxies = remove_empty_strings(proxies);
5755 service->proxies = proxies;
5757 service->proxies = NULL;
5761 g_strfreev(service->excludes);
5763 if (excludes_str->len > 0) {
5764 char **excludes = g_strsplit_set(
5765 excludes_str->str, " ", 0);
5766 excludes = remove_empty_strings(excludes);
5767 service->excludes = excludes;
5769 service->excludes = NULL;
5772 if (!service->proxies)
5773 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
5776 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
5777 g_free(service->pac);
5779 if (url && strlen(url) > 0)
5780 service->pac = g_strstrip(g_strdup(url));
5782 service->pac = NULL;
5784 /* if we are connected:
5785 - if service->pac == NULL
5786 - if __connman_ipconfig_get_proxy_autoconfig(
5787 service->ipconfig) == NULL
5788 --> We should start WPAD */
5791 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
5796 g_string_free(servers_str, TRUE);
5799 g_string_free(excludes_str, TRUE);
5801 service->proxy_config = method;
5807 g_string_free(servers_str, TRUE);
5810 g_string_free(excludes_str, TRUE);
5815 static void do_auto_connect(struct connman_service *service,
5816 enum connman_service_connect_reason reason)
5819 * CONNMAN_SERVICE_CONNECT_REASON_NONE must be ignored for VPNs. VPNs
5820 * always have reason CONNMAN_SERVICE_CONNECT_REASON_USER/AUTO.
5822 if (!service || (service->type == CONNMAN_SERVICE_TYPE_VPN &&
5823 reason == CONNMAN_SERVICE_CONNECT_REASON_NONE))
5827 * Only user interaction should get VPN or WIFI connected in failure
5830 if (service->state == CONNMAN_SERVICE_STATE_FAILURE &&
5831 reason != CONNMAN_SERVICE_CONNECT_REASON_USER &&
5832 (service->type == CONNMAN_SERVICE_TYPE_VPN ||
5833 service->type == CONNMAN_SERVICE_TYPE_WIFI))
5837 * Do not use the builtin auto connect, instead rely on the
5838 * native auto connect feature of the service.
5840 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_NATIVE)
5844 * Run service auto connect for other than VPN services. Afterwards
5845 * start also VPN auto connect process.
5847 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
5848 __connman_service_auto_connect(reason);
5853 int __connman_service_reset_ipconfig(struct connman_service *service,
5854 enum connman_ipconfig_type type, DBusMessageIter *array,
5855 enum connman_service_state *new_state)
5857 struct connman_ipconfig *ipconfig, *new_ipconfig;
5858 enum connman_ipconfig_method old_method, new_method;
5859 enum connman_service_state state;
5862 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
5863 ipconfig = service->ipconfig_ipv4;
5864 state = service->state_ipv4;
5865 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
5866 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
5867 ipconfig = service->ipconfig_ipv6;
5868 state = service->state_ipv6;
5869 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
5876 old_method = __connman_ipconfig_get_method(ipconfig);
5877 index = __connman_ipconfig_get_index(ipconfig);
5879 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
5880 new_ipconfig = create_ip4config(service, index,
5881 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
5883 new_ipconfig = create_ip6config(service, index);
5886 err = __connman_ipconfig_set_config(new_ipconfig, array);
5888 __connman_ipconfig_unref(new_ipconfig);
5892 new_method = __connman_ipconfig_get_method(new_ipconfig);
5895 if (is_connecting(state) || is_connected(state))
5896 __connman_network_clear_ipconfig(service->network, ipconfig);
5898 __connman_ipconfig_unref(ipconfig);
5900 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
5901 service->ipconfig_ipv4 = new_ipconfig;
5902 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
5903 service->ipconfig_ipv6 = new_ipconfig;
5905 if (is_connecting(state) || is_connected(state))
5906 __connman_ipconfig_enable(new_ipconfig);
5908 if (new_state && new_method != old_method) {
5909 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
5910 *new_state = service->state_ipv4;
5912 *new_state = service->state_ipv6;
5914 settings_changed(service, new_ipconfig);
5915 address_updated(service, type);
5917 do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5920 DBG("err %d ipconfig %p type %d method %d state %s", err,
5921 new_ipconfig, type, new_method,
5922 !new_state ? "-" : state2string(*new_state));
5927 void __connman_service_wispr_start(struct connman_service *service,
5928 enum connman_ipconfig_type type)
5930 DBG("service %p type %s", service, __connman_ipconfig_type2string(type));
5932 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
5933 service->online_check_interval_ipv4 =
5934 online_check_initial_interval;
5936 service->online_check_interval_ipv6 =
5937 online_check_initial_interval;
5939 __connman_wispr_start(service, type);
5942 static void set_error(struct connman_service *service,
5943 enum connman_service_error error);
5945 static DBusMessage *set_property(DBusConnection *conn,
5946 DBusMessage *msg, void *user_data)
5948 struct connman_service *service = user_data;
5949 DBusMessageIter iter, value;
5953 DBG("service %p", service);
5955 if (!dbus_message_iter_init(msg, &iter))
5956 return __connman_error_invalid_arguments(msg);
5958 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
5959 return __connman_error_invalid_arguments(msg);
5961 dbus_message_iter_get_basic(&iter, &name);
5962 dbus_message_iter_next(&iter);
5964 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
5965 return __connman_error_invalid_arguments(msg);
5967 dbus_message_iter_recurse(&iter, &value);
5969 type = dbus_message_iter_get_arg_type(&value);
5971 if (g_str_equal(name, "AutoConnect")) {
5972 dbus_bool_t autoconnect;
5974 if (type != DBUS_TYPE_BOOLEAN)
5975 return __connman_error_invalid_arguments(msg);
5977 if (!service->favorite)
5978 return __connman_error_invalid_service(msg);
5980 dbus_message_iter_get_basic(&value, &autoconnect);
5982 if (autoconnect && service->type == CONNMAN_SERVICE_TYPE_VPN) {
5984 * Changing the autoconnect flag on VPN to "on" should
5985 * have the same effect as user connecting the VPN =
5986 * clear previous error and change state to idle.
5988 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
5990 if (service->state == CONNMAN_SERVICE_STATE_FAILURE) {
5991 service->state = CONNMAN_SERVICE_STATE_IDLE;
5992 state_changed(service);
5996 if (connman_service_set_autoconnect(service, autoconnect)) {
5997 service_save(service);
5999 do_auto_connect(service,
6000 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
6002 } else if (g_str_equal(name, "Nameservers.Configuration")) {
6003 DBusMessageIter entry;
6007 #if defined TIZEN_EXT
6008 enum connman_ipconfig_type ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
6012 if (__connman_provider_is_immutable(service->provider) ||
6014 return __connman_error_not_supported(msg);
6016 if (type != DBUS_TYPE_ARRAY)
6017 return __connman_error_invalid_arguments(msg);
6019 str = g_string_new(NULL);
6021 return __connman_error_invalid_arguments(msg);
6023 index = __connman_service_get_index(service);
6024 gw = __connman_ipconfig_get_gateway_from_index(index,
6025 CONNMAN_IPCONFIG_TYPE_ALL);
6027 #if !defined TIZEN_EXT
6028 if (gw && strlen(gw))
6029 __connman_service_nameserver_del_routes(service,
6030 CONNMAN_IPCONFIG_TYPE_ALL);
6033 dbus_message_iter_recurse(&value, &entry);
6035 #if defined TIZEN_EXT
6036 /* IPv4/IPv6 Last DNS config method */
6037 int last_dns_ipv4 = service->dns_config_method_ipv4;
6038 int last_dns_ipv6 = service->dns_config_method_ipv6;
6039 DBG("Last DNS Config Method IPv4: %d IPv6: %d", last_dns_ipv4, last_dns_ipv6);
6042 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
6044 dbus_message_iter_get_basic(&entry, &val);
6045 dbus_message_iter_next(&entry);
6047 /* First unpack the DNS Config Method */
6048 DBG("DNS Config Method: %s", val);
6049 if((g_strcmp0(val, "ipv4.manual") == 0)) {
6050 service->dns_config_method_ipv4 =
6051 CONNMAN_DNSCONFIG_METHOD_MANUAL;
6053 if(last_dns_ipv4 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
6054 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
6055 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
6057 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
6060 } else if(g_strcmp0(val, "ipv4.dhcp") == 0) {
6061 service->dns_config_method_ipv4 =
6062 CONNMAN_DNSCONFIG_METHOD_DHCP;
6063 if(last_dns_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
6064 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
6067 } else if(g_strcmp0(val, "ipv6.manual") == 0) {
6068 service->dns_config_method_ipv6 =
6069 CONNMAN_DNSCONFIG_METHOD_MANUAL;
6070 if(last_dns_ipv6 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
6071 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
6072 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
6074 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
6077 } else if(g_strcmp0(val, "ipv6.dhcp") == 0) {
6078 service->dns_config_method_ipv6 =
6079 CONNMAN_DNSCONFIG_METHOD_DHCP;
6080 if(last_dns_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
6081 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
6090 g_string_append_printf(str, " %s", val);
6092 g_string_append(str, val);
6095 #if defined TIZEN_EXT
6096 if (service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_DHCP &&
6097 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_DHCP) {
6098 DBG("Both IPv4 and IPv6 DNS Method DHCP");
6099 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
6101 if (gw && strlen(gw))
6102 __connman_service_nameserver_del_routes(service,
6105 DBG("%s ip_type: %d nameserver remove all", name, ip_type);
6106 nameserver_remove_all(service, ip_type);
6108 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
6110 g_strfreev(service->nameservers_config);
6113 char **nameservers, **iter;
6115 nameservers = g_strsplit_set(str->str, " ", 0);
6117 for (iter = nameservers; *iter; iter++)
6118 if (connman_inet_check_ipaddress(*iter) <= 0)
6121 nameservers = remove_empty_strings(nameservers);
6122 service->nameservers_config = nameservers;
6124 service->nameservers_config = NULL;
6127 g_string_free(str, TRUE);
6129 if (gw && strlen(gw))
6130 __connman_service_nameserver_add_routes(service, gw);
6132 #if defined TIZEN_EXT
6133 DBG("%s ip_type: %d nameserver add all", name, ip_type);
6134 nameserver_add_all(service, ip_type);
6136 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
6138 dns_configuration_changed(service);
6140 start_wispr_when_connected(service);
6142 service_save(service);
6143 } else if (g_str_equal(name, "Timeservers.Configuration")) {
6144 DBusMessageIter entry;
6147 if (service->immutable)
6148 return __connman_error_not_supported(msg);
6150 if (type != DBUS_TYPE_ARRAY)
6151 return __connman_error_invalid_arguments(msg);
6153 str = g_string_new(NULL);
6155 return __connman_error_invalid_arguments(msg);
6157 dbus_message_iter_recurse(&value, &entry);
6159 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
6161 dbus_message_iter_get_basic(&entry, &val);
6162 dbus_message_iter_next(&entry);
6168 g_string_append_printf(str, " %s", val);
6170 g_string_append(str, val);
6173 g_strfreev(service->timeservers_config);
6174 service->timeservers_config = NULL;
6177 char **timeservers = g_strsplit_set(str->str, " ", 0);
6178 timeservers = remove_empty_strings(timeservers);
6179 service->timeservers_config = timeservers;
6182 g_string_free(str, TRUE);
6184 service_save(service);
6185 timeservers_configuration_changed(service);
6186 __connman_timeserver_conf_update(service);
6188 } else if (g_str_equal(name, "Domains.Configuration")) {
6189 DBusMessageIter entry;
6192 if (service->immutable)
6193 return __connman_error_not_supported(msg);
6195 if (type != DBUS_TYPE_ARRAY)
6196 return __connman_error_invalid_arguments(msg);
6198 str = g_string_new(NULL);
6200 return __connman_error_invalid_arguments(msg);
6202 dbus_message_iter_recurse(&value, &entry);
6204 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
6206 dbus_message_iter_get_basic(&entry, &val);
6207 dbus_message_iter_next(&entry);
6213 g_string_append_printf(str, " %s", val);
6215 g_string_append(str, val);
6218 searchdomain_remove_all(service);
6219 g_strfreev(service->domains);
6222 char **domains = g_strsplit_set(str->str, " ", 0);
6223 domains = remove_empty_strings(domains);
6224 service->domains = domains;
6226 service->domains = NULL;
6228 g_string_free(str, TRUE);
6230 searchdomain_add_all(service);
6231 domain_configuration_changed(service);
6232 domain_changed(service);
6234 service_save(service);
6235 } else if (g_str_equal(name, "Proxy.Configuration")) {
6238 if (service->immutable)
6239 return __connman_error_not_supported(msg);
6241 if (type != DBUS_TYPE_ARRAY)
6242 return __connman_error_invalid_arguments(msg);
6244 err = update_proxy_configuration(service, &value);
6247 return __connman_error_failed(msg, -err);
6249 proxy_configuration_changed(service);
6251 __connman_notifier_proxy_changed(service);
6253 service_save(service);
6254 } else if (g_str_equal(name, "mDNS.Configuration")) {
6257 if (service->immutable)
6258 return __connman_error_not_supported(msg);
6260 if (type != DBUS_TYPE_BOOLEAN)
6261 return __connman_error_invalid_arguments(msg);
6263 dbus_message_iter_get_basic(&value, &val);
6264 service->mdns_config = val;
6266 mdns_configuration_changed(service);
6268 set_mdns(service, service->mdns_config);
6270 service_save(service);
6271 } else if (g_str_equal(name, "IPv4.Configuration") ||
6272 g_str_equal(name, "IPv6.Configuration")) {
6274 enum connman_service_state state =
6275 CONNMAN_SERVICE_STATE_UNKNOWN;
6276 enum connman_ipconfig_type type =
6277 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
6280 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
6282 return __connman_error_not_supported(msg);
6286 if (!service->ipconfig_ipv4 &&
6287 !service->ipconfig_ipv6)
6288 return __connman_error_invalid_property(msg);
6290 if (g_str_equal(name, "IPv4.Configuration"))
6291 type = CONNMAN_IPCONFIG_TYPE_IPV4;
6293 type = CONNMAN_IPCONFIG_TYPE_IPV6;
6295 err = __connman_service_reset_ipconfig(service, type, &value,
6299 if (is_connected(state) || is_connecting(state)) {
6300 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6301 __connman_network_enable_ipconfig(service->network,
6302 service->ipconfig_ipv4);
6304 __connman_network_enable_ipconfig(service->network,
6305 service->ipconfig_ipv6);
6308 return __connman_error_failed(msg, -err);
6311 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6312 ipv4_configuration_changed(service);
6314 ipv6_configuration_changed(service);
6316 if (is_connecting(service->state) ||
6317 is_connected(service->state)) {
6318 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6319 __connman_network_enable_ipconfig(service->network,
6320 service->ipconfig_ipv4);
6322 __connman_network_enable_ipconfig(service->network,
6323 service->ipconfig_ipv6);
6326 service_save(service);
6327 #if defined TIZEN_EXT
6328 /* When AP is connected using WPS without SSID then its password needs
6329 * to be saved for autoconnection */
6330 } else if (g_str_equal(name, "Passphrase")) {
6333 if (type != DBUS_TYPE_STRING)
6334 return __connman_error_invalid_arguments(msg);
6336 dbus_message_iter_get_basic(&value, &passphrase);
6338 __connman_service_set_passphrase(service, passphrase);
6340 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
6341 } else if (g_str_equal(name, "EapOverEthernet")) {
6342 int err = connman_service_set_eapol_property(service, &value);
6344 return __connman_error_failed(msg, -err);
6346 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
6347 service_save(service);
6348 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
6350 return __connman_error_invalid_property(msg);
6352 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
6355 static void set_error(struct connman_service *service,
6356 enum connman_service_error error)
6360 #if !defined TIZEN_EXT
6361 if (service->error == error)
6365 service->error = error;
6370 #if !defined TIZEN_EXT
6371 if (!allow_property_changed(service))
6375 str = error2string(service->error);
6380 connman_dbus_property_changed_basic(service->path,
6381 CONNMAN_SERVICE_INTERFACE, "Error",
6382 DBUS_TYPE_STRING, &str);
6385 static void remove_timeout(struct connman_service *service)
6387 if (service->timeout > 0) {
6388 g_source_remove(service->timeout);
6389 service->timeout = 0;
6393 static void reply_pending(struct connman_service *service, int error)
6395 remove_timeout(service);
6397 if (service->pending) {
6398 connman_dbus_reply_pending(service->pending, error, NULL);
6399 service->pending = NULL;
6402 if (service->provider_pending) {
6403 connman_dbus_reply_pending(service->provider_pending,
6404 error, service->path);
6405 service->provider_pending = NULL;
6409 static void service_complete(struct connman_service *service)
6411 reply_pending(service, EIO);
6413 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
6414 do_auto_connect(service, service->connect_reason);
6416 gettimeofday(&service->modified, NULL);
6417 service_save(service);
6420 static DBusMessage *clear_property(DBusConnection *conn,
6421 DBusMessage *msg, void *user_data)
6423 struct connman_service *service = user_data;
6426 DBG("service %p", service);
6428 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
6431 if (g_str_equal(name, "Error")) {
6432 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6434 __connman_service_clear_error(service);
6435 service_complete(service);
6437 return __connman_error_invalid_property(msg);
6439 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
6442 static bool is_ipconfig_usable(struct connman_service *service)
6444 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
6445 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
6451 static bool is_ignore(struct connman_service *service)
6453 if (!service->autoconnect)
6456 if (service->roaming &&
6457 !connman_setting_get_bool("AutoConnectRoamingServices"))
6460 if (service->ignore)
6463 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
6466 if (!is_ipconfig_usable(service))
6472 static void disconnect_on_last_session(enum connman_service_type type)
6476 for (list = service_list; list; list = list->next) {
6477 struct connman_service *service = list->data;
6479 if (service->type != type)
6482 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
6485 __connman_service_disconnect(service);
6490 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
6491 static int always_connect[MAX_CONNMAN_SERVICE_TYPES] = {};
6492 static int active_count = 0;
6494 void __connman_service_set_active_session(bool enable, GSList *list)
6505 enum connman_service_type type = GPOINTER_TO_INT(list->data);
6508 case CONNMAN_SERVICE_TYPE_ETHERNET:
6509 case CONNMAN_SERVICE_TYPE_WIFI:
6510 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
6511 case CONNMAN_SERVICE_TYPE_CELLULAR:
6512 case CONNMAN_SERVICE_TYPE_GADGET:
6514 active_sessions[type]++;
6516 active_sessions[type]--;
6519 case CONNMAN_SERVICE_TYPE_UNKNOWN:
6520 case CONNMAN_SERVICE_TYPE_SYSTEM:
6521 case CONNMAN_SERVICE_TYPE_GPS:
6522 case CONNMAN_SERVICE_TYPE_VPN:
6523 case CONNMAN_SERVICE_TYPE_P2P:
6524 #if defined TIZEN_EXT_WIFI_MESH
6525 case CONNMAN_SERVICE_TYPE_MESH:
6530 if (active_sessions[type] == 0)
6531 disconnect_on_last_session(type);
6533 list = g_slist_next(list);
6536 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
6537 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
6538 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
6539 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
6540 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
6541 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
6545 struct preferred_tech_data {
6546 GList *preferred_list;
6547 enum connman_service_type type;
6550 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
6552 struct connman_service *service = data;
6553 struct preferred_tech_data *tech_data = user_data;
6555 if (service->type == tech_data->type) {
6556 tech_data->preferred_list =
6557 g_list_append(tech_data->preferred_list, service);
6559 #if defined TIZEN_EXT
6560 if (!simplified_log)
6562 DBG("type %d service %p %s", tech_data->type, service,
6567 static GList *preferred_tech_list_get(void)
6569 unsigned int *tech_array;
6570 struct preferred_tech_data tech_data = { 0, };
6573 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
6577 if (connman_setting_get_bool("SingleConnectedTechnology")) {
6579 for (list = service_list; list; list = list->next) {
6580 struct connman_service *service = list->data;
6582 if (!is_connected(service->state))
6585 if (service->connect_reason ==
6586 CONNMAN_SERVICE_CONNECT_REASON_USER) {
6587 DBG("service %p name %s is user connected",
6588 service, service->name);
6589 #if defined TIZEN_EXT
6590 /* We can connect to a favorite service like
6591 * wifi even we have a userconnect for cellular
6592 * because we have refount for cellular service
6594 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6597 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6605 for (i = 0; tech_array[i] != 0; i += 1) {
6606 tech_data.type = tech_array[i];
6607 g_list_foreach(service_list, preferred_tech_add_by_type,
6611 return tech_data.preferred_list;
6614 static void set_always_connecting_technologies()
6616 unsigned int *always_connected_techs =
6617 connman_setting_get_uint_list("AlwaysConnectedTechnologies");
6619 for (i = 0; always_connected_techs && always_connected_techs[i]; i++)
6620 always_connect[always_connected_techs[i]] = 1;
6623 #if !defined TIZEN_EXT
6624 static bool autoconnect_no_session_active(struct connman_service *service)
6627 * Test active_count to see if there are no sessions set up and
6628 * stop autoconnecting, but continue connecting if the service
6629 * belongs to a technology which should always autoconnect.
6631 if (!active_count && !always_connect[service->type])
6638 static bool autoconnect_already_connecting(struct connman_service *service,
6639 bool autoconnecting)
6642 * If another service is already connecting and this service type has
6643 * not been marked as always connecting, stop the connecting procedure.
6645 if (autoconnecting &&
6646 !active_sessions[service->type] &&
6647 !always_connect[service->type])
6653 static int service_indicate_state(struct connman_service *service);
6655 static bool auto_connect_service(GList *services,
6656 enum connman_service_connect_reason reason,
6659 struct connman_service *service = NULL;
6660 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
6661 bool autoconnecting = false;
6663 #if defined TIZEN_EXT
6664 GSList *wifi_ignore = NULL;
6668 DBG("preferred %d sessions %d reason %s", preferred, active_count,
6669 reason2string(reason));
6671 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
6673 #if defined TIZEN_EXT_WIFI_MESH
6674 /* Don't auto connect wifi if mesh interface is created */
6675 if (connman_mesh_is_interface_created())
6676 ignore[CONNMAN_SERVICE_TYPE_WIFI] = true;
6679 for (list = services; list; list = list->next) {
6680 service = list->data;
6682 #if defined TIZEN_EXT
6683 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
6684 int index = connman_network_get_index(service->network);
6685 if (g_slist_find(wifi_ignore, GINT_TO_POINTER(index)) != NULL)
6689 if (ignore[service->type]) {
6690 DBG("service %p type %s ignore", service,
6691 __connman_service_type2string(service->type));
6695 #if defined TIZEN_EXT
6696 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
6697 service, service->name,
6698 state2string(service->state),
6699 __connman_service_type2string(service->type),
6700 service->favorite, is_ignore(service),
6701 service->hidden, service->hidden_service);
6703 /* Tizen takes Wi-Fi as the highest priority into consideration. */
6704 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
6705 if (is_connecting(service->state) == TRUE || is_connected(service->state) == TRUE)
6709 if (service->connect_reason ==
6710 CONNMAN_SERVICE_CONNECT_REASON_NATIVE) {
6711 DBG("service %p uses native autonnect, skip", service);
6715 index = __connman_service_get_index(service);
6716 if (g_hash_table_lookup(passphrase_requested,
6717 GINT_TO_POINTER(index)))
6720 if (service->pending ||
6721 is_connecting(service->state) ||
6722 is_connected(service->state)) {
6723 #if defined TIZEN_EXT
6724 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
6725 int index = connman_network_get_index(service->network);
6726 wifi_ignore = g_slist_prepend(wifi_ignore, GINT_TO_POINTER(index));
6728 autoconnecting = true;
6732 if (autoconnect_no_session_active(service))
6735 ignore[service->type] = true;
6736 autoconnecting = true;
6738 DBG("service %p type %s busy", service,
6739 __connman_service_type2string(service->type));
6744 if (!service->favorite) {
6748 #if defined TIZEN_EXT
6749 DBG("Service is not favorite, autoconnecting %d",
6751 g_slist_free(wifi_ignore);
6753 return autoconnecting;
6756 #if defined TIZEN_EXT
6757 DBG("service %p identifier %s roaming %d ignore %d "
6758 "ipconfig_usable %d autoconnect %d state %d",
6760 service->identifier, service->roaming,
6761 service->ignore, is_ipconfig_usable(service),
6762 service->autoconnect, service->state);
6764 if (is_ignore(service) || service->state !=
6765 CONNMAN_SERVICE_STATE_IDLE)
6767 #if defined TIZEN_EXT
6768 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
6770 if (autoconnect_already_connecting(service, autoconnecting)) {
6771 DBG("service %p type %s has no users", service,
6772 __connman_service_type2string(service->type));
6776 DBG("service %p %s %s", service, service->name,
6777 (preferred) ? "preferred" : reason2string(reason));
6779 #if defined TIZEN_EXT
6780 __connman_service_connect(service, reason);
6782 if (__connman_service_connect(service, reason) == 0)
6783 service_indicate_state(service);
6785 if (autoconnect_no_session_active(service))
6788 #if defined TIZEN_EXT
6789 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
6790 int index = connman_network_get_index(service->network);
6791 wifi_ignore = g_slist_prepend(wifi_ignore, GINT_TO_POINTER(index));
6792 autoconnecting = true;
6795 ignore[service->type] = true;
6797 #if defined TIZEN_EXT
6798 g_slist_free(wifi_ignore);
6800 return autoconnecting;
6803 static gboolean run_auto_connect(gpointer data)
6805 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
6806 bool autoconnecting = false;
6807 GList *preferred_tech;
6813 preferred_tech = preferred_tech_list_get();
6814 if (preferred_tech) {
6815 autoconnecting = auto_connect_service(preferred_tech, reason,
6817 g_list_free(preferred_tech);
6820 if (!autoconnecting || active_count)
6821 auto_connect_service(service_list, reason, false);
6826 #if defined TIZEN_EXT
6827 bool __connman_service_get_auto_connect_mode(void)
6829 return auto_connect_mode;
6832 void __connman_service_set_auto_connect_mode(bool enable)
6834 DBG("set auto_connect_mode = %d", enable);
6836 if (auto_connect_mode != enable)
6837 auto_connect_mode = enable;
6841 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
6845 if (autoconnect_id != 0)
6848 #if defined TIZEN_EXT
6849 if (auto_connect_mode == FALSE) {
6850 DBG("Currently, not auto connection mode");
6855 if (!__connman_session_policy_autoconnect(reason))
6858 #if defined TIZEN_EXT
6859 /* Adding Timeout of 500ms before trying to auto connect.
6860 * This is done because of below scenario
6861 * 1. Device is connected to AP1
6862 * 2. WPS Connection request is initiated for AP2
6863 * 3. Immediately WPS Connection is Cancelled
6864 * When WPS Connection Connection is initiated for AP2 then
6865 * sometimes there is a scenario where connman gets in ASSOCIATED
6866 * state with AP1 due to autoconnect and subsequently the connection
6867 * initiated by AP1 fails and connman service for AP1 comes in
6868 * FAILURE state due to this when connection with AP2 is cancelled
6869 * then autoconnect with AP1 doesn't works because its autoconnection
6870 * is ignored as its last state was FAILURE rather than IDLE */
6871 autoconnect_id = g_timeout_add(500, run_auto_connect,
6873 autoconnect_id = g_idle_add(run_auto_connect,
6875 GUINT_TO_POINTER(reason));
6878 static gboolean run_vpn_auto_connect(gpointer data) {
6880 bool need_split = false;
6881 bool autoconnectable_vpns = false;
6883 int timeout = VPN_AUTOCONNECT_TIMEOUT_DEFAULT;
6884 struct connman_service *def_service;
6886 attempts = GPOINTER_TO_INT(data);
6887 def_service = connman_service_get_default();
6890 * Stop auto connecting VPN if there is no transport service or the
6891 * transport service is not connected or if the current default service
6892 * is a connected VPN (in ready state).
6894 if (!def_service || !is_connected(def_service->state) ||
6895 (def_service->type == CONNMAN_SERVICE_TYPE_VPN &&
6896 is_connected(def_service->state))) {
6898 DBG("stopped, default service %s connected %d",
6899 def_service ? def_service->identifier : "NULL",
6900 def_service ? is_connected(def_service->state) : -1);
6904 for (list = service_list; list; list = list->next) {
6905 struct connman_service *service = list->data;
6908 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
6911 if (is_connected(service->state) ||
6912 is_connecting(service->state)) {
6913 if (!service->do_split_routing)
6917 * If the service is connecting it must be accounted
6918 * for to keep the autoconnection in main loop.
6920 if (is_connecting(service->state))
6921 autoconnectable_vpns = true;
6926 if (is_ignore(service) || !service->favorite)
6929 if (need_split && !service->do_split_routing) {
6930 DBG("service %p no split routing", service);
6934 DBG("service %p %s %s", service, service->name,
6935 service->do_split_routing ?
6936 "split routing" : "");
6938 res = __connman_service_connect(service,
6939 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
6943 service_indicate_state(service);
6946 autoconnectable_vpns = true;
6952 if (!service->do_split_routing)
6956 /* Stop if there is no VPN to automatically connect.*/
6957 if (!autoconnectable_vpns) {
6958 DBG("stopping, no autoconnectable VPNs found");
6962 /* Increase the attempt count up to the threshold.*/
6963 if (attempts < VPN_AUTOCONNECT_TIMEOUT_ATTEMPTS_THRESHOLD)
6967 * Timeout increases with 1s after VPN_AUTOCONNECT_TIMEOUT_STEP amount
6968 * of attempts made. After VPN_AUTOCONNECT_TIMEOUT_ATTEMPTS_THRESHOLD is
6969 * reached the delay does not increase.
6971 timeout = timeout + (int)(attempts / VPN_AUTOCONNECT_TIMEOUT_STEP);
6973 /* Re add this to main loop */
6974 vpn_autoconnect_id =
6975 g_timeout_add_seconds(timeout, run_vpn_auto_connect,
6976 GINT_TO_POINTER(attempts));
6978 DBG("re-added to main loop, next VPN autoconnect in %d seconds (#%d)",
6981 return G_SOURCE_REMOVE;
6984 vpn_autoconnect_id = 0;
6985 return G_SOURCE_REMOVE;
6988 static void vpn_auto_connect(void)
6991 * Remove existing autoconnect from main loop to reset the attempt
6992 * counter in order to get VPN connected when there is a network change.
6994 if (vpn_autoconnect_id) {
6995 if (!g_source_remove(vpn_autoconnect_id))
6999 vpn_autoconnect_id =
7000 g_idle_add(run_vpn_auto_connect, NULL);
7004 __connman_service_is_provider_pending(struct connman_service *service)
7009 if (service->provider_pending)
7015 void __connman_service_set_provider_pending(struct connman_service *service,
7018 if (service->provider_pending) {
7019 DBG("service %p provider pending msg %p already exists",
7020 service, service->provider_pending);
7024 service->provider_pending = msg;
7027 static void check_pending_msg(struct connman_service *service)
7029 if (!service->pending)
7032 DBG("service %p pending msg %p already exists", service,
7034 dbus_message_unref(service->pending);
7037 void __connman_service_set_hidden_data(struct connman_service *service,
7040 DBusMessage *pending = user_data;
7042 DBG("service %p pending %p", service, pending);
7047 check_pending_msg(service);
7049 service->pending = pending;
7052 void __connman_service_return_error(struct connman_service *service,
7053 int error, gpointer user_data)
7055 DBG("service %p error %d user_data %p", service, error, user_data);
7057 __connman_service_set_hidden_data(service, user_data);
7059 reply_pending(service, error);
7062 static gboolean connect_timeout(gpointer user_data)
7064 struct connman_service *service = user_data;
7065 bool autoconnect = false;
7067 DBG("service %p", service);
7069 service->timeout = 0;
7071 if (service->network)
7072 __connman_network_disconnect(service->network);
7073 else if (service->provider)
7074 connman_provider_disconnect(service->provider);
7076 __connman_stats_service_unregister(service);
7078 if (service->pending) {
7081 reply = __connman_error_operation_timeout(service->pending);
7083 g_dbus_send_message(connection, reply);
7085 dbus_message_unref(service->pending);
7086 service->pending = NULL;
7090 __connman_service_ipconfig_indicate_state(service,
7091 CONNMAN_SERVICE_STATE_FAILURE,
7092 CONNMAN_IPCONFIG_TYPE_IPV4);
7093 __connman_service_ipconfig_indicate_state(service,
7094 CONNMAN_SERVICE_STATE_FAILURE,
7095 CONNMAN_IPCONFIG_TYPE_IPV6);
7098 service->connect_reason !=
7099 CONNMAN_SERVICE_CONNECT_REASON_USER)
7100 do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7105 static DBusMessage *connect_service(DBusConnection *conn,
7106 DBusMessage *msg, void *user_data)
7108 struct connman_service *service = user_data;
7109 #if defined TIZEN_EXT
7116 DBG("service %p", service);
7118 #if defined TIZEN_EXT
7120 * Description: TIZEN implements system global connection management.
7122 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7123 connman_service_user_pdn_connection_ref(service);
7125 /*Reset the Disconnect Reason while issue connect request*/
7126 service->disconnect_reason = 0;
7128 /*Reset the association status code while issue connect request*/
7129 service->assoc_status_code = 0;
7131 /* Reset the disconnection_requested while issue connect request*/
7132 connman_service_set_disconnection_requested(service, false);
7135 if (service->pending)
7136 return __connman_error_in_progress(msg);
7138 #if !defined TIZEN_EXT
7139 index = __connman_service_get_index(service);
7141 for (list = service_list; list; list = list->next) {
7142 struct connman_service *temp = list->data;
7144 #if defined TIZEN_EXT
7145 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7148 if (!is_connecting(temp->state) && !is_connected(temp->state))
7151 if (service == temp)
7154 if (service->type != temp->type)
7157 if (__connman_service_get_index(temp) == index &&
7158 __connman_service_disconnect(temp) == -EINPROGRESS)
7162 if (err == -EINPROGRESS)
7163 return __connman_error_operation_timeout(msg);
7166 service->ignore = false;
7168 service->pending = dbus_message_ref(msg);
7170 err = __connman_service_connect(service,
7171 CONNMAN_SERVICE_CONNECT_REASON_USER);
7173 if (err != -EINPROGRESS)
7174 reply_pending(service, -err);
7179 static DBusMessage *disconnect_service(DBusConnection *conn,
7180 DBusMessage *msg, void *user_data)
7182 struct connman_service *service = user_data;
7185 DBG("service %p", service);
7187 #if defined TIZEN_EXT
7189 * Description: TIZEN implements system global connection management.
7191 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
7192 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
7193 return __connman_error_failed(msg, EISCONN);
7195 if (is_connected(service->state) == TRUE &&
7196 service == connman_service_get_default_connection())
7197 return __connman_error_failed(msg, EISCONN);
7201 service->ignore = true;
7203 err = __connman_service_disconnect(service);
7204 if (err < 0 && err != -EINPROGRESS)
7205 return __connman_error_failed(msg, -err);
7207 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7210 #if defined TIZEN_EXT
7211 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
7213 if (service == NULL)
7216 DBG("service %p ", service);
7218 connman_network_set_string(service->network, "WiFi.EAP", NULL);
7219 connman_network_set_string(service->network, "WiFi.Identity", NULL);
7220 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
7221 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
7222 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
7223 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
7224 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
7225 connman_network_set_string(service->network, "WiFi.AnonymousIdentity", NULL);
7227 static void __connman_service_cleanup_network_dpp(struct connman_service *service)
7229 if (service == NULL)
7232 DBG("service %p ", service);
7234 connman_network_set_string(service->network, "WiFi.Connector", NULL);
7235 connman_network_set_string(service->network, "WiFi.CSignKey", NULL);
7236 connman_network_set_string(service->network, "WiFi.NetAccessKey", NULL);
7240 bool __connman_service_remove(struct connman_service *service)
7242 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
7243 service->type == CONNMAN_SERVICE_TYPE_GADGET)
7246 if (service->immutable || service->hidden ||
7247 __connman_provider_is_immutable(service->provider))
7250 #if !defined TIZEN_EXT
7251 if (!service->favorite && !is_idle(service->state))
7255 __connman_service_disconnect(service);
7257 g_free(service->passphrase);
7258 service->passphrase = NULL;
7260 g_free(service->identity);
7261 service->identity = NULL;
7263 g_free(service->anonymous_identity);
7264 service->anonymous_identity = NULL;
7266 g_free(service->subject_match);
7267 service->subject_match = NULL;
7269 g_free(service->altsubject_match);
7270 service->altsubject_match = NULL;
7272 g_free(service->domain_suffix_match);
7273 service->domain_suffix_match = NULL;
7275 g_free(service->domain_match);
7276 service->domain_match = NULL;
7278 g_free(service->agent_identity);
7279 service->agent_identity = NULL;
7281 g_free(service->eap);
7282 service->eap = NULL;
7284 #if defined TIZEN_EXT
7285 g_free(service->ca_cert_file);
7286 service->ca_cert_file = NULL;
7288 g_free(service->client_cert_file);
7289 service->client_cert_file = NULL;
7291 g_free(service->private_key_file);
7292 service->private_key_file = NULL;
7294 g_free(service->private_key_passphrase);
7295 service->private_key_passphrase = NULL;
7297 g_free(service->phase2);
7298 service->phase2 = NULL;
7300 __connman_service_cleanup_network_8021x(service);
7302 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
7303 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
7304 connman_service_set_proxy(service, NULL, false);
7306 __connman_service_nameserver_clear(service);
7308 g_strfreev(service->nameservers_config);
7309 service->nameservers_config = NULL;
7311 g_free(service->connector);
7312 service->connector = NULL;
7314 g_free(service->c_sign_key);
7315 service->c_sign_key = NULL;
7317 g_free(service->net_access_key);
7318 service->net_access_key = NULL;
7320 __connman_service_cleanup_network_dpp(service);
7323 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
7325 __connman_service_set_favorite(service, false);
7327 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
7329 #if defined TIZEN_EXT
7330 /* Reset IP Method and DNS Method to DHCP */
7331 __connman_ipconfig_set_method(service->ipconfig_ipv4,
7332 CONNMAN_IPCONFIG_METHOD_DHCP);
7333 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
7334 g_strfreev(service->nameservers_config);
7335 service->nameservers_config = NULL;
7338 #if defined TIZEN_EXT
7339 __connman_storage_remove_service(service->identifier);
7341 service_save(service);
7347 #if defined TIZEN_EXT
7348 static char *__connman_service_get_wpa_id_to_remove(struct connman_service *service)
7353 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
7356 if (service->security != CONNMAN_SERVICE_SECURITY_SAE &&
7357 service->security != CONNMAN_SERVICE_SECURITY_PSK)
7360 identifier = g_strdup(service->identifier);
7364 if (service->security == CONNMAN_SERVICE_SECURITY_SAE) {
7365 ptr = strstr(identifier, "_sae");
7371 memcpy(ptr, "_psk", strlen("_psk"));
7372 } else if (service->security == CONNMAN_SERVICE_SECURITY_PSK) {
7373 ptr = strstr(identifier, "_psk");
7379 memcpy(ptr, "_sae", strlen("_sae"));
7386 static void __connman_service_remove_wpa_service(struct connman_service *service)
7390 char *identifier = __connman_service_get_wpa_id_to_remove(service);
7395 dir = g_strdup_printf("%s/%s", STORAGEDIR, identifier);
7399 if (g_file_test(dir, G_FILE_TEST_EXISTS) != TRUE)
7402 for (list = service_list; list; list = list->next) {
7403 struct connman_service *dst_service = list->data;
7405 if (dst_service->type != CONNMAN_SERVICE_TYPE_WIFI)
7408 if (g_strcmp0(dst_service->identifier, identifier) == 0) {
7409 __connman_service_remove(dst_service);
7414 __connman_storage_remove_service(identifier);
7422 static DBusMessage *remove_service(DBusConnection *conn,
7423 DBusMessage *msg, void *user_data)
7425 struct connman_service *service = user_data;
7427 DBG("service %p", service);
7428 #if defined TIZEN_EXT
7429 __connman_service_remove_wpa_service(service);
7431 if (!__connman_service_remove(service))
7432 return __connman_error_not_supported(msg);
7434 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7437 static bool check_suitable_state(enum connman_service_state a,
7438 enum connman_service_state b)
7441 * Special check so that "ready" service can be moved before
7444 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
7445 b == CONNMAN_SERVICE_STATE_READY) ||
7446 (b == CONNMAN_SERVICE_STATE_ONLINE &&
7447 a == CONNMAN_SERVICE_STATE_READY))
7453 static void downgrade_state(struct connman_service *service)
7458 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
7459 service->state_ipv6);
7461 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
7462 __connman_service_ipconfig_indicate_state(service,
7463 CONNMAN_SERVICE_STATE_READY,
7464 CONNMAN_IPCONFIG_TYPE_IPV4);
7466 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
7467 __connman_service_ipconfig_indicate_state(service,
7468 CONNMAN_SERVICE_STATE_READY,
7469 CONNMAN_IPCONFIG_TYPE_IPV6);
7472 static void apply_relevant_default_downgrade(struct connman_service *service)
7474 struct connman_service *def_service;
7476 def_service = connman_service_get_default();
7477 if (!def_service || def_service != service ||
7478 def_service->state != CONNMAN_SERVICE_STATE_ONLINE)
7481 downgrade_state(def_service);
7484 static void switch_default_service(struct connman_service *default_service,
7485 struct connman_service *downgrade_service)
7487 struct connman_service *service;
7490 apply_relevant_default_downgrade(default_service);
7491 src = g_list_find(service_list, downgrade_service);
7492 dst = g_list_find(service_list, default_service);
7495 if (src == dst || src->next == dst)
7498 service = src->data;
7499 service_list = g_list_delete_link(service_list, src);
7500 service_list = g_list_insert_before(service_list, dst, service);
7502 downgrade_state(downgrade_service);
7505 static struct _services_notify {
7512 static void service_append_added_foreach(gpointer data, gpointer user_data)
7514 struct connman_service *service = data;
7515 DBusMessageIter *iter = user_data;
7517 if (!service || !service->path) {
7518 DBG("service %p or path is NULL", service);
7522 if (g_hash_table_lookup(services_notify->add, service->path)) {
7523 DBG("new %s", service->path);
7525 append_struct(service, iter);
7526 g_hash_table_remove(services_notify->add, service->path);
7528 #if defined TIZEN_EXT
7529 if (!simplified_log)
7531 DBG("changed %s", service->path);
7533 append_struct_service(iter, NULL, service);
7537 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
7539 g_list_foreach(service_list, service_append_added_foreach, iter);
7542 static void append_removed(gpointer key, gpointer value, gpointer user_data)
7544 char *objpath = key;
7545 DBusMessageIter *iter = user_data;
7547 DBG("removed %s", objpath);
7548 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
7551 static void service_append_removed(DBusMessageIter *iter, void *user_data)
7553 g_hash_table_foreach(services_notify->remove, append_removed, iter);
7556 static gboolean service_send_changed(gpointer data)
7558 DBusMessage *signal;
7562 services_notify->id = 0;
7564 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
7565 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
7569 __connman_dbus_append_objpath_dict_array(signal,
7570 service_append_ordered, NULL);
7571 __connman_dbus_append_objpath_array(signal,
7572 service_append_removed, NULL);
7574 dbus_connection_send(connection, signal, NULL);
7575 dbus_message_unref(signal);
7577 g_hash_table_remove_all(services_notify->remove);
7578 g_hash_table_remove_all(services_notify->add);
7583 static void service_schedule_changed(void)
7585 if (services_notify->id != 0)
7588 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
7591 int __connman_service_move(struct connman_service *service,
7592 struct connman_service *target, bool before)
7594 enum connman_ipconfig_method target4, target6;
7595 enum connman_ipconfig_method service4, service6;
7597 DBG("service %p", service);
7602 if (!service->favorite)
7605 if (!target || !target->favorite || target == service)
7608 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
7610 * We only allow VPN route splitting if there are
7611 * routes defined for a given VPN.
7613 if (!__connman_provider_check_routes(target->provider)) {
7614 connman_info("Cannot move service. "
7615 "No routes defined for provider %s",
7616 __connman_provider_get_ident(target->provider));
7620 __connman_service_set_split_routing(target, true);
7622 __connman_service_set_split_routing(target, false);
7624 __connman_service_set_split_routing(service, false);
7626 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
7627 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
7628 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
7629 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
7631 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
7632 target4, target6, target->state_ipv4, target->state_ipv6,
7633 target->do_split_routing);
7635 DBG("service %s method %d/%d state %d/%d", service->identifier,
7637 service->state_ipv4, service->state_ipv6);
7640 * If method is OFF, then we do not need to check the corresponding
7643 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
7644 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
7645 if (!check_suitable_state(target->state_ipv6,
7646 service->state_ipv6))
7651 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
7652 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
7653 if (!check_suitable_state(target->state_ipv4,
7654 service->state_ipv4))
7659 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
7660 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
7661 if (!check_suitable_state(target->state_ipv6,
7662 service->state_ipv6))
7667 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
7668 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
7669 if (!check_suitable_state(target->state_ipv4,
7670 service->state_ipv4))
7675 gettimeofday(&service->modified, NULL);
7676 service_save(service);
7677 service_save(target);
7680 * If the service which goes down is the default service and is
7681 * online, we downgrade directly its state to ready so:
7682 * the service which goes up, needs to recompute its state which
7683 * is triggered via downgrading it - if relevant - to state ready.
7686 switch_default_service(target, service);
7688 switch_default_service(service, target);
7690 __connman_connection_update_gateway();
7692 service_schedule_changed();
7697 static DBusMessage *move_service(DBusConnection *conn,
7698 DBusMessage *msg, void *user_data,
7701 struct connman_service *service = user_data;
7702 struct connman_service *target;
7706 DBG("service %p", service);
7708 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
7711 target = find_service(path);
7713 err = __connman_service_move(service, target, before);
7718 return __connman_error_invalid_service(msg);
7720 return __connman_error_not_supported(msg);
7722 connman_warn("unsupported error code %d in move_service()",
7727 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7730 static DBusMessage *move_before(DBusConnection *conn,
7731 DBusMessage *msg, void *user_data)
7733 return move_service(conn, msg, user_data, true);
7736 static DBusMessage *move_after(DBusConnection *conn,
7737 DBusMessage *msg, void *user_data)
7739 return move_service(conn, msg, user_data, false);
7742 static DBusMessage *reset_counters(DBusConnection *conn,
7743 DBusMessage *msg, void *user_data)
7745 struct connman_service *service = user_data;
7747 reset_stats(service);
7749 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7752 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
7753 static DBusMessage *is_eapol_enabled(DBusConnection *conn,
7754 DBusMessage *msg, void *user_data)
7756 struct connman_service *service = user_data;
7757 DBG("service: %p path: %s UseEapol: %d", service, service->path, service->use_eapol);
7759 dbus_bool_t eapol_status = service->use_eapol;
7761 DBusMessage *reply = dbus_message_new_method_return(msg);
7763 DBG("Failed to initialize reply");
7767 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &eapol_status, DBUS_TYPE_INVALID);
7770 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
7772 #if defined TIZEN_EXT
7773 static DBusMessage *downgrade_service(DBusConnection *conn,
7774 DBusMessage *msg, void *user_data)
7776 struct connman_service *service = user_data;
7778 downgrade_state(service);
7779 __connman_connection_update_gateway();
7780 start_online_check(service, CONNMAN_IPCONFIG_TYPE_IPV4);
7782 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7786 static void service_schedule_added(struct connman_service *service)
7788 #if defined TIZEN_EXT
7789 if (!simplified_log)
7791 DBG("service %p", service);
7793 g_hash_table_remove(services_notify->remove, service->path);
7794 g_hash_table_replace(services_notify->add, service->path, service);
7796 service_schedule_changed();
7799 static void service_schedule_removed(struct connman_service *service)
7801 if (!service || !service->path) {
7802 DBG("service %p or path is NULL", service);
7806 DBG("service %p %s", service, service->path);
7808 g_hash_table_remove(services_notify->add, service->path);
7809 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
7812 service_schedule_changed();
7815 static bool allow_property_changed(struct connman_service *service)
7817 #if defined TIZEN_EXT
7818 if (service->path == NULL)
7821 if (g_hash_table_lookup_extended(services_notify->add, service->path,
7828 static const GDBusMethodTable service_methods[] = {
7829 { GDBUS_DEPRECATED_METHOD("GetProperties",
7830 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
7832 { GDBUS_METHOD("SetProperty",
7833 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
7834 NULL, set_property) },
7835 { GDBUS_METHOD("ClearProperty",
7836 GDBUS_ARGS({ "name", "s" }), NULL,
7838 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
7840 { GDBUS_METHOD("Disconnect", NULL, NULL,
7841 disconnect_service) },
7842 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
7843 { GDBUS_METHOD("MoveBefore",
7844 GDBUS_ARGS({ "service", "o" }), NULL,
7846 { GDBUS_METHOD("MoveAfter",
7847 GDBUS_ARGS({ "service", "o" }), NULL,
7849 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
7850 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
7851 { GDBUS_METHOD("IsEapolEnabled", NULL, GDBUS_ARGS({ "eapol", "b" }), is_eapol_enabled) },
7853 #if defined TIZEN_EXT
7854 { GDBUS_METHOD("Downgrade", NULL, NULL, downgrade_service) },
7859 static const GDBusSignalTable service_signals[] = {
7860 { GDBUS_SIGNAL("PropertyChanged",
7861 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
7862 #if defined TIZEN_EXT
7863 { GDBUS_SIGNAL("StateChangedProperties",
7864 GDBUS_ARGS({ "properties", "a{sv}" })) },
7869 static void service_free(gpointer user_data)
7871 struct connman_service *service = user_data;
7872 char *path = service->path;
7874 DBG("service %p", service);
7876 reply_pending(service, ENOENT);
7878 if (service->nameservers_timeout) {
7879 g_source_remove(service->nameservers_timeout);
7880 dns_changed(service);
7883 __connman_notifier_service_remove(service);
7884 service_schedule_removed(service);
7886 __connman_wispr_stop(service);
7887 stats_stop(service);
7889 service->path = NULL;
7892 __connman_connection_update_gateway();
7894 g_dbus_unregister_interface(connection, path,
7895 CONNMAN_SERVICE_INTERFACE);
7899 g_hash_table_destroy(service->counter_table);
7901 if (service->network) {
7902 __connman_network_disconnect(service->network);
7903 connman_network_unref(service->network);
7904 service->network = NULL;
7907 if (service->provider)
7908 connman_provider_unref(service->provider);
7910 if (service->ipconfig_ipv4) {
7911 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
7912 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
7913 __connman_ipconfig_unref(service->ipconfig_ipv4);
7914 service->ipconfig_ipv4 = NULL;
7917 if (service->ipconfig_ipv6) {
7918 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
7919 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
7920 __connman_ipconfig_unref(service->ipconfig_ipv6);
7921 service->ipconfig_ipv6 = NULL;
7924 g_strfreev(service->timeservers);
7925 g_strfreev(service->timeservers_config);
7926 g_strfreev(service->nameservers);
7927 g_strfreev(service->nameservers_config);
7928 g_strfreev(service->nameservers_auto);
7929 g_strfreev(service->domains);
7930 g_strfreev(service->proxies);
7931 g_strfreev(service->excludes);
7933 g_free(service->hostname);
7934 g_free(service->domainname);
7935 g_free(service->pac);
7936 g_free(service->name);
7937 g_free(service->passphrase);
7938 g_free(service->identifier);
7939 g_free(service->eap);
7940 g_free(service->identity);
7941 g_free(service->anonymous_identity);
7942 g_free(service->agent_identity);
7943 g_free(service->ca_cert_file);
7944 g_free(service->subject_match);
7945 g_free(service->altsubject_match);
7946 g_free(service->domain_suffix_match);
7947 g_free(service->domain_match);
7948 g_free(service->client_cert_file);
7949 g_free(service->private_key_file);
7950 g_free(service->private_key_passphrase);
7951 g_free(service->phase2);
7952 g_free(service->config_file);
7953 g_free(service->config_entry);
7954 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
7955 g_free(service->pac_file);
7956 g_free(service->phase1);
7959 #if defined TIZEN_EXT
7960 g_free(service->connector);
7961 g_free(service->c_sign_key);
7962 g_free(service->net_access_key);
7965 if (service->stats.timer)
7966 g_timer_destroy(service->stats.timer);
7967 if (service->stats_roaming.timer)
7968 g_timer_destroy(service->stats_roaming.timer);
7970 if (current_default == service)
7971 current_default = NULL;
7976 static void stats_init(struct connman_service *service)
7979 service->stats.valid = false;
7980 service->stats.enabled = false;
7981 service->stats.timer = g_timer_new();
7984 service->stats_roaming.valid = false;
7985 service->stats_roaming.enabled = false;
7986 service->stats_roaming.timer = g_timer_new();
7989 static void service_initialize(struct connman_service *service)
7991 #if defined TIZEN_EXT
7992 if (!simplified_log)
7994 DBG("service %p", service);
7996 service->refcount = 1;
7998 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
8000 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
8001 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
8003 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
8004 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
8005 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
8007 service->favorite = false;
8008 service->immutable = false;
8009 service->hidden = false;
8011 service->ignore = false;
8013 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
8017 stats_init(service);
8019 service->provider = NULL;
8021 service->wps = false;
8022 service->wps_advertizing = false;
8023 #if defined TIZEN_EXT
8024 memset(service->last_connected_bssid, 0, WIFI_BSSID_LEN_MAX);
8025 service->is_internet_connection = false;
8026 service->assoc_reject_count = 0;
8027 service->disconnection_requested = false;
8028 service->storage_reload = false;
8030 * Description: TIZEN implements system global connection management.
8032 service->user_pdn_connection_refcount = 0;
8033 __sync_synchronize();
8035 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8036 service->use_eapol = false;
8037 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8041 * connman_service_create:
8043 * Allocate a new service.
8045 * Returns: a newly-allocated #connman_service structure
8047 struct connman_service *connman_service_create(void)
8050 struct connman_stats_counter *counters;
8051 const char *counter;
8053 struct connman_service *service;
8055 service = g_try_new0(struct connman_service, 1);
8059 DBG("service %p", service);
8061 service->counter_table = g_hash_table_new_full(g_str_hash,
8062 g_str_equal, NULL, g_free);
8064 for (list = counter_list; list; list = list->next) {
8065 counter = list->data;
8067 counters = g_try_new0(struct connman_stats_counter, 1);
8069 g_hash_table_destroy(service->counter_table);
8074 counters->append_all = true;
8076 g_hash_table_replace(service->counter_table, (gpointer)counter,
8080 service_initialize(service);
8086 * connman_service_ref:
8087 * @service: service structure
8089 * Increase reference counter of service
8091 struct connman_service *
8092 connman_service_ref_debug(struct connman_service *service,
8093 const char *file, int line, const char *caller)
8095 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
8096 file, line, caller);
8098 __sync_fetch_and_add(&service->refcount, 1);
8104 * connman_service_unref:
8105 * @service: service structure
8107 * Decrease reference counter of service and release service if no
8110 void connman_service_unref_debug(struct connman_service *service,
8111 const char *file, int line, const char *caller)
8113 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
8114 file, line, caller);
8116 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
8119 service_list = g_list_remove(service_list, service);
8121 __connman_service_disconnect(service);
8123 g_hash_table_remove(service_hash, service->identifier);
8126 #if defined TIZEN_EXT
8127 static int calculate_score_last_user_selection(struct connman_service *service)
8130 struct connman_device *device;
8131 const char *last_user_selection_ident;
8132 time_t last_user_selection_time;
8133 unsigned int frequency;
8136 struct tm* ref_timeinfo;
8138 device = connman_network_get_device(service->network);
8142 last_user_selection_time = connman_device_get_last_user_selection_time(device);
8143 last_user_selection_ident = connman_device_get_last_user_selection_ident(device);
8144 frequency = connman_network_get_frequency(service->network);
8146 if (ins_settings.last_user_selection) {
8147 if (g_strcmp0(last_user_selection_ident, service->identifier) == 0 &&
8148 (((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
8149 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
8150 service->strength >= ins_settings.signal_level3_24ghz) ||
8151 ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
8152 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
8153 service->strength >= ins_settings.signal_level3_5ghz))) {
8155 /* Only events that occur within 8 hours are counted. */
8156 curr_time = time(NULL);
8157 ref_timeinfo = localtime(&curr_time);
8158 ref_timeinfo->tm_hour -= 8;
8159 ref_time = mktime(ref_timeinfo);
8161 if (last_user_selection_time > ref_time) {
8162 int time_diff = (curr_time - last_user_selection_time) / 60;
8163 int denominator = ins_settings.last_user_selection_time - time_diff;
8164 int numerator = ins_settings.last_user_selection_time /
8165 ins_settings.last_user_selection_score;
8166 int last_user_score = denominator / numerator;
8168 score += (last_user_score > ins_settings.last_user_selection_score ?
8169 ins_settings.last_user_selection_score : last_user_score);
8177 static int calculate_score_last_connected(struct connman_service *service)
8180 struct connman_device *device;
8181 const char *last_connected_ident;
8182 unsigned int frequency;
8184 device = connman_network_get_device(service->network);
8188 last_connected_ident = connman_device_get_last_connected_ident(device);
8189 frequency = connman_network_get_frequency(service->network);
8191 if (ins_settings.last_connected) {
8192 if (g_strcmp0(last_connected_ident, service->identifier) == 0 &&
8193 (((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
8194 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
8195 service->strength >= ins_settings.signal_level3_24ghz) ||
8196 ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
8197 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
8198 service->strength >= ins_settings.signal_level3_5ghz))) {
8199 score += ins_settings.last_connected_score;
8206 static int calculate_score_frequency(struct connman_service *service)
8209 unsigned int frequency;
8211 frequency = connman_network_get_frequency(service->network);
8213 switch (ins_settings.preferred_freq) {
8214 case CONNMAN_INS_PREFERRED_FREQ_24GHZ:
8215 if ((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
8216 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
8217 (service->strength >= ins_settings.signal_level3_24ghz))
8218 score += ins_settings.preferred_freq_score;
8221 case CONNMAN_INS_PREFERRED_FREQ_5GHZ:
8222 if ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
8223 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
8224 (service->strength >= ins_settings.signal_level3_5ghz))
8225 score += ins_settings.preferred_freq_score;
8235 static int calculate_score_security_priority(struct connman_service *service)
8239 if (ins_settings.security_priority_count)
8240 score += ins_settings.security_priority[service->security];
8245 static int calculate_score_internet_connection(struct connman_service *service)
8249 if (ins_settings.internet) {
8250 if (service->is_internet_connection)
8251 score += ins_settings.internet_score;
8257 static int calculate_score_strength(struct connman_service *service)
8261 if (ins_settings.signal)
8262 score += (((service->strength > 60) ? 60 : service->strength) - 35);
8267 static int calculate_score(struct connman_service *service)
8269 int score_last_user_selection;
8270 int score_last_connected;
8271 int score_frequency;
8272 int score_security_priority;
8273 int score_internet_connection;
8277 if (service->type != CONNMAN_SERVICE_TYPE_WIFI) {
8278 score += calculate_score_internet_connection(service);
8279 service->ins_score = score;
8283 score_last_user_selection = calculate_score_last_user_selection(service);
8284 score_last_connected = calculate_score_last_connected(service);
8285 score_frequency = calculate_score_frequency(service);
8286 score_security_priority = calculate_score_security_priority(service);
8287 score_internet_connection = calculate_score_internet_connection(service);
8288 score_strength = calculate_score_strength(service);
8290 score = score_last_user_selection + score_last_connected +
8291 score_frequency + score_security_priority +
8292 score_internet_connection + score_strength;
8294 service->score_last_user_selection = score_last_user_selection;
8295 service->score_last_connected = score_last_connected;
8296 service->score_frequency = score_frequency;
8297 service->score_security_priority = score_security_priority;
8298 service->score_internet_connection = score_internet_connection;
8299 service->score_strength = score_strength;
8301 service->ins_score = score;
8304 #endif /* defined TIZEN_EXT */
8306 static gint service_compare(gconstpointer a, gconstpointer b);
8308 static gint service_compare_vpn(struct connman_service *a,
8309 struct connman_service *b)
8311 struct connman_provider *provider;
8312 struct connman_service *service;
8313 struct connman_service *transport;
8318 provider = a->provider;
8321 } else if (b->provider) {
8322 provider = b->provider;
8329 ident = __connman_provider_get_transport_ident(provider);
8330 transport = connman_service_lookup_from_identifier(ident);
8335 return service_compare(service, transport);
8337 return service_compare(transport, service);
8340 static gint service_compare_preferred(struct connman_service *service_a,
8341 struct connman_service *service_b)
8343 unsigned int *tech_array;
8346 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
8348 for (i = 0; tech_array[i]; i++) {
8349 if (tech_array[i] == service_a->type)
8352 if (tech_array[i] == service_b->type)
8359 static gint service_compare(gconstpointer a, gconstpointer b)
8361 struct connman_service *service_a = (void *) a;
8362 struct connman_service *service_b = (void *) b;
8363 enum connman_service_state state_a, state_b;
8364 bool a_connected, b_connected;
8365 #if defined TIZEN_EXT
8369 #else /* defined TIZEN_EXT */
8371 #endif /* defined TIZEN_EXT */
8373 state_a = service_a->state;
8374 state_b = service_b->state;
8375 a_connected = is_connected(state_a);
8376 b_connected = is_connected(state_b);
8378 #if defined TIZEN_EXT
8379 if ((a_connected && b_connected) &&
8380 state_a == state_b &&
8381 service_a->type == CONNMAN_SERVICE_TYPE_WIFI &&
8382 service_b->type == CONNMAN_SERVICE_TYPE_WIFI) {
8383 const char *default_interface =
8384 connman_setting_get_string("DefaultWifiInterface");
8385 const char *ifname_a = connman_device_get_string(
8386 connman_network_get_device(service_a->network), "Interface");
8387 const char *ifname_b = connman_device_get_string(
8388 connman_network_get_device(service_b->network), "Interface");
8390 if (g_strcmp0(default_interface, ifname_a) == 0)
8392 else if (g_strcmp0(default_interface, ifname_b) == 0)
8397 if (a_connected && b_connected) {
8400 /* Compare the VPN transport and the service */
8401 if ((service_a->type == CONNMAN_SERVICE_TYPE_VPN ||
8402 service_b->type == CONNMAN_SERVICE_TYPE_VPN) &&
8403 service_b->type != service_a->type) {
8404 rval = service_compare_vpn(service_a, service_b);
8409 if (service_a->order > service_b->order)
8412 if (service_a->order < service_b->order)
8415 rval = service_compare_preferred(service_a, service_b);
8420 if (state_a != state_b) {
8421 if (a_connected && b_connected) {
8422 /* We prefer online over ready state */
8423 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
8426 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
8435 if (is_connecting(state_a))
8437 if (is_connecting(state_b))
8441 if (service_a->favorite && !service_b->favorite)
8444 if (!service_a->favorite && service_b->favorite)
8447 if (service_a->type != service_b->type) {
8450 rval = service_compare_preferred(service_a, service_b);
8454 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8456 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8459 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
8461 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
8464 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8466 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8469 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8471 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8474 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
8476 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
8479 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
8481 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
8485 #if defined TIZEN_EXT
8486 if (TIZEN_INS_ENABLED) {
8487 score_a = calculate_score(service_a);
8488 score_b = calculate_score(service_b);
8490 if (score_b != score_a)
8491 return score_b - score_a;
8492 else if (score_b == score_a) {
8493 strength = (gint) service_b->strength - (gint) service_a->strength;
8498 #else /* defined TIZEN_EXT */
8499 strength = (gint) service_b->strength - (gint) service_a->strength;
8502 #endif /* defined TIZEN_EXT */
8504 return g_strcmp0(service_a->name, service_b->name);
8507 static void service_list_sort(void)
8509 if (service_list && service_list->next) {
8510 service_list = g_list_sort(service_list, service_compare);
8511 service_schedule_changed();
8515 int __connman_service_compare(const struct connman_service *a,
8516 const struct connman_service *b)
8518 return service_compare(a, b);
8522 * connman_service_get_type:
8523 * @service: service structure
8525 * Get the type of service
8527 enum connman_service_type connman_service_get_type(struct connman_service *service)
8530 return CONNMAN_SERVICE_TYPE_UNKNOWN;
8532 return service->type;
8536 * connman_service_get_interface:
8537 * @service: service structure
8539 * Get network interface of service
8541 char *connman_service_get_interface(struct connman_service *service)
8548 index = __connman_service_get_index(service);
8550 return connman_inet_ifname(index);
8554 * connman_service_get_network:
8555 * @service: service structure
8557 * Get the service network
8559 struct connman_network *
8560 __connman_service_get_network(struct connman_service *service)
8565 return service->network;
8568 struct connman_ipconfig *
8569 __connman_service_get_ip4config(struct connman_service *service)
8574 return service->ipconfig_ipv4;
8577 struct connman_ipconfig *
8578 __connman_service_get_ip6config(struct connman_service *service)
8583 return service->ipconfig_ipv6;
8586 struct connman_ipconfig *
8587 __connman_service_get_ipconfig(struct connman_service *service, int family)
8589 if (family == AF_INET)
8590 return __connman_service_get_ip4config(service);
8591 else if (family == AF_INET6)
8592 return __connman_service_get_ip6config(service);
8598 bool __connman_service_is_connected_state(struct connman_service *service,
8599 enum connman_ipconfig_type type)
8605 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
8607 case CONNMAN_IPCONFIG_TYPE_IPV4:
8608 return is_connected(service->state_ipv4);
8609 case CONNMAN_IPCONFIG_TYPE_IPV6:
8610 return is_connected(service->state_ipv6);
8611 case CONNMAN_IPCONFIG_TYPE_ALL:
8612 return is_connected(service->state_ipv4) &&
8613 is_connected(service->state_ipv6);
8618 enum connman_service_security __connman_service_get_security(
8619 struct connman_service *service)
8622 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8624 return service->security;
8627 const char *__connman_service_get_phase2(struct connman_service *service)
8632 return service->phase2;
8635 bool __connman_service_wps_enabled(struct connman_service *service)
8640 return service->wps;
8643 void __connman_service_mark_dirty(void)
8645 services_dirty = true;
8648 #if defined TIZEN_EXT
8650 * Returns profile count if there is any connected profiles
8651 * that use same interface
8653 int __connman_service_get_connected_count_of_iface(
8654 struct connman_service *service)
8663 index1 = __connman_service_get_index(service);
8668 for (list = service_list; list; list = list->next) {
8669 struct connman_service *service2 = list->data;
8671 if (service == service2)
8674 index2 = __connman_service_get_index(service2);
8676 if (is_connected(service2->state) && index2 > 0 && index1 == index2)
8682 DBG("Interface index %d, count %d", index1, count);
8687 void __connman_service_set_storage_reload(struct connman_service *service,
8688 bool storage_reload)
8690 if (service != NULL)
8691 service->storage_reload = storage_reload;
8696 * __connman_service_set_favorite_delayed:
8697 * @service: service structure
8698 * @favorite: favorite value
8699 * @delay_ordering: do not order service sequence
8701 * Change the favorite setting of service
8703 int __connman_service_set_favorite_delayed(struct connman_service *service,
8705 bool delay_ordering)
8707 #if defined TIZEN_EXT
8708 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8711 if (service->hidden)
8714 if (service->favorite == favorite)
8717 service->favorite = favorite;
8719 favorite_changed(service);
8721 if (!delay_ordering) {
8723 service_list_sort();
8725 __connman_connection_update_gateway();
8732 * __connman_service_set_favorite:
8733 * @service: service structure
8734 * @favorite: favorite value
8736 * Change the favorite setting of service
8738 int __connman_service_set_favorite(struct connman_service *service,
8741 return __connman_service_set_favorite_delayed(service, favorite,
8745 bool connman_service_get_favorite(struct connman_service *service)
8747 return service->favorite;
8750 bool connman_service_get_autoconnect(struct connman_service *service)
8752 return service->autoconnect;
8755 int __connman_service_set_immutable(struct connman_service *service,
8758 if (service->hidden)
8761 if (service->immutable == immutable)
8764 service->immutable = immutable;
8766 immutable_changed(service);
8771 int __connman_service_set_ignore(struct connman_service *service,
8777 service->ignore = ignore;
8782 void __connman_service_set_string(struct connman_service *service,
8783 const char *key, const char *value)
8785 if (service->hidden)
8787 if (g_str_equal(key, "EAP")) {
8788 g_free(service->eap);
8789 service->eap = g_strdup(value);
8790 } else if (g_str_equal(key, "Identity")) {
8791 g_free(service->identity);
8792 service->identity = g_strdup(value);
8793 } else if (g_str_equal(key, "AnonymousIdentity")) {
8794 g_free(service->anonymous_identity);
8795 service->anonymous_identity = g_strdup(value);
8796 } else if (g_str_equal(key, "CACertFile")) {
8797 g_free(service->ca_cert_file);
8798 service->ca_cert_file = g_strdup(value);
8799 } else if (g_str_equal(key, "SubjectMatch")) {
8800 g_free(service->subject_match);
8801 service->subject_match = g_strdup(value);
8802 } else if (g_str_equal(key, "AltSubjectMatch")) {
8803 g_free(service->altsubject_match);
8804 service->altsubject_match = g_strdup(value);
8805 } else if (g_str_equal(key, "DomainSuffixMatch")) {
8806 g_free(service->domain_suffix_match);
8807 service->domain_suffix_match = g_strdup(value);
8808 } else if (g_str_equal(key, "DomainMatch")) {
8809 g_free(service->domain_match);
8810 service->domain_match = g_strdup(value);
8811 } else if (g_str_equal(key, "ClientCertFile")) {
8812 g_free(service->client_cert_file);
8813 service->client_cert_file = g_strdup(value);
8814 } else if (g_str_equal(key, "PrivateKeyFile")) {
8815 g_free(service->private_key_file);
8816 service->private_key_file = g_strdup(value);
8817 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
8818 g_free(service->private_key_passphrase);
8819 service->private_key_passphrase = g_strdup(value);
8820 } else if (g_str_equal(key, "Phase2")) {
8821 g_free(service->phase2);
8822 service->phase2 = g_strdup(value);
8823 } else if (g_str_equal(key, "Passphrase"))
8824 __connman_service_set_passphrase(service, value);
8825 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8826 else if (g_str_equal(key, "Phase1")) {
8827 g_free(service->phase1);
8828 service->phase1 = g_strdup(value);
8829 } else if (g_str_equal(key, "PacFile")) {
8830 g_free(service->pac_file);
8831 service->pac_file = g_strdup(value);
8834 #if defined TIZEN_EXT
8835 else if (g_str_equal(key, "Connector")) {
8836 g_free(service->connector);
8837 service->connector = g_strdup(value);
8838 } else if (g_str_equal(key, "CSignKey")) {
8839 g_free(service->c_sign_key);
8840 service->c_sign_key = g_strdup(value);
8841 } else if (g_str_equal(key, "NetAccessKey")) {
8842 g_free(service->net_access_key);
8843 service->net_access_key = g_strdup(value);
8845 DBG("Unknown key: %s", key);
8849 void __connman_service_set_search_domains(struct connman_service *service,
8852 searchdomain_remove_all(service);
8854 if (service->domains)
8855 g_strfreev(service->domains);
8857 service->domains = g_strdupv(domains);
8859 searchdomain_add_all(service);
8862 int __connman_service_set_mdns(struct connman_service *service,
8865 service->mdns_config = enabled;
8867 return set_mdns(service, enabled);
8870 static void report_error_cb(void *user_context, bool retry,
8873 struct connman_service *service = user_context;
8876 __connman_service_connect(service,
8877 CONNMAN_SERVICE_CONNECT_REASON_USER);
8879 /* It is not relevant to stay on Failure state
8880 * when failing is due to wrong user input */
8881 __connman_service_clear_error(service);
8882 #if defined TIZEN_EXT
8883 /* Reseting the state back in case of failure state */
8884 service->state_ipv4 = service->state_ipv6 =
8885 CONNMAN_SERVICE_STATE_IDLE;
8887 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED &&
8888 service->error != CONNMAN_SERVICE_ERROR_ASSOC_FAILED)
8889 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
8891 service_complete(service);
8892 service_list_sort();
8893 __connman_connection_update_gateway();
8897 static int check_wpspin(struct connman_service *service, const char *wpspin)
8905 length = strlen(wpspin);
8907 /* If 0, it will mean user wants to use PBC method */
8909 connman_network_set_string(service->network,
8910 "WiFi.PinWPS", NULL);
8914 /* A WPS PIN is always 8 chars length,
8915 * its content is in digit representation.
8920 for (i = 0; i < 8; i++)
8921 if (!isdigit((unsigned char) wpspin[i]))
8924 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
8929 static void request_input_cb(struct connman_service *service,
8930 bool values_received,
8931 const char *name, int name_len,
8932 const char *identity, const char *passphrase,
8933 bool wps, const char *wpspin,
8934 const char *error, void *user_data)
8936 struct connman_device *device;
8937 const char *security;
8941 DBG("RequestInput return, %p", service);
8944 DBG("error: %s", error);
8946 if (g_strcmp0(error,
8947 "net.connman.Agent.Error.Canceled") == 0) {
8948 err = -ECONNABORTED;
8950 if (service->hidden)
8951 __connman_service_return_error(service,
8957 if (service->hidden)
8958 __connman_service_return_error(service,
8959 ETIMEDOUT, user_data);
8965 if (service->hidden) {
8966 if (name_len > 0 && name_len <= 32) {
8967 device = connman_network_get_device(service->network);
8968 security = connman_network_get_string(service->network,
8970 err = __connman_device_request_hidden_scan(device,
8972 identity, passphrase,
8973 security, user_data);
8978 __connman_service_return_error(service, -err,
8982 if (!values_received || service->hidden) {
8987 if (wps && service->network) {
8988 err = check_wpspin(service, wpspin);
8992 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
8996 __connman_service_set_agent_identity(service, identity);
8999 err = __connman_service_set_passphrase(service, passphrase);
9002 index = __connman_service_get_index(service);
9003 g_hash_table_remove(passphrase_requested,
9004 GINT_TO_POINTER(index));
9007 /* We forget any previous error. */
9008 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
9010 __connman_service_connect(service,
9011 CONNMAN_SERVICE_CONNECT_REASON_USER);
9013 } else if (err == -ENOKEY) {
9014 __connman_service_indicate_error(service,
9015 CONNMAN_SERVICE_ERROR_INVALID_KEY);
9017 /* It is not relevant to stay on Failure state
9018 * when failing is due to wrong user input */
9019 service->state = CONNMAN_SERVICE_STATE_IDLE;
9021 if (!service->hidden) {
9023 * If there was a real error when requesting
9024 * hidden scan, then that error is returned already
9025 * to the user somewhere above so do not try to
9028 __connman_service_return_error(service, -err,
9032 service_complete(service);
9033 __connman_connection_update_gateway();
9037 static void downgrade_connected_services(void)
9039 struct connman_service *up_service;
9042 for (list = service_list; list; list = list->next) {
9043 up_service = list->data;
9045 if (!is_connected(up_service->state))
9048 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
9051 downgrade_state(up_service);
9055 static int service_update_preferred_order(struct connman_service *default_service,
9056 struct connman_service *new_service,
9057 enum connman_service_state new_state)
9059 if (!default_service || default_service == new_service)
9062 if (service_compare_preferred(default_service, new_service) > 0) {
9063 switch_default_service(default_service,
9065 __connman_connection_update_gateway();
9072 #if defined TIZEN_EXT
9073 static gboolean __connman_service_can_drop(struct connman_service *service)
9075 if (is_connected(service->state) == TRUE || is_connecting(service->state) == TRUE) {
9076 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
9078 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
9084 static struct connman_device *default_connecting_device = NULL;
9086 static void __connman_service_disconnect_default(struct connman_service *service)
9088 struct connman_device *default_device = NULL;
9089 struct connman_network *network = __connman_service_get_network(service);
9094 if (default_connecting_device == NULL)
9097 default_device = connman_network_get_device(network);
9099 DBG("Disconnecting service %p %s", service, service->path);
9100 DBG("Disconnecting device %p %p %s",
9101 default_connecting_device,
9103 connman_device_get_string(default_device, "Name"));
9105 if (default_connecting_device == default_device)
9106 default_connecting_device = NULL;
9109 #if defined TIZEN_MAINTAIN_ONLINE
9110 static void __connman_service_connect_default(struct connman_service *current,
9111 enum connman_service_state old_state)
9113 static void __connman_service_connect_default(struct connman_service *current)
9118 bool default_internet;
9119 struct connman_service *service;
9120 struct connman_service *default_service = NULL;
9121 struct connman_device *default_device = NULL;
9123 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
9124 switch (current->state) {
9125 case CONNMAN_SERVICE_STATE_UNKNOWN:
9126 case CONNMAN_SERVICE_STATE_ASSOCIATION:
9127 case CONNMAN_SERVICE_STATE_CONFIGURATION:
9133 if (default_connecting_device &&
9134 __connman_service_is_internet_profile(current) == TRUE) {
9135 if (current->network == NULL)
9138 default_device = connman_network_get_device(current->network);
9139 if (default_connecting_device == default_device) {
9140 DBG("Cellular service[%s] %p %s",
9141 state2string(current->state), current, current->path);
9142 DBG("Cellular device %p %p %s",
9143 default_connecting_device, default_device,
9144 connman_device_get_string(default_device, "Name"));
9146 default_connecting_device = NULL;
9151 #if defined TIZEN_MAINTAIN_ONLINE
9152 } else if (current->state == CONNMAN_SERVICE_STATE_READY &&
9153 old_state == CONNMAN_SERVICE_STATE_ONLINE) {
9154 DBG("Device is downgraded: online --> ready");
9156 } else if (is_connected(current->state) == TRUE || is_connecting(current->state) == TRUE)
9159 /* Always-on: keep default cellular connection as possible */
9160 for (list = service_list; list; list = list->next) {
9161 service = list->data;
9163 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
9164 __connman_service_is_internet_profile(service) != TRUE ||
9165 service->network == NULL) {
9170 connman_network_get_bool(service->network, "DefaultInternet");
9172 DBG("service: %p %s %s %s (default: %d)", service, service->name,
9173 __connman_service_type2string(service->type),
9174 state2string(service->state), default_internet);
9176 if (default_internet) {
9177 default_service = service;
9178 if (is_connected(default_service->state) == TRUE ||
9179 is_connecting(default_service->state) == TRUE)
9182 default_device = connman_network_get_device(default_service->network);
9183 if (default_connecting_device == default_device) {
9184 DBG("Device is connecting (%p)", default_connecting_device);
9188 default_connecting_device = default_device;
9189 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
9191 err = __connman_network_connect(default_service->network);
9192 DBG("Connecting default service %p %s [%d]",
9193 default_service, default_service->path, err);
9194 DBG("Connecting device %p %s", default_connecting_device,
9195 connman_device_get_string(default_connecting_device, "Name"));
9196 if (err < 0 && err != -EINPROGRESS) {
9197 default_connecting_device = NULL;
9205 static void single_connected_tech(struct connman_service *allowed)
9207 struct connman_service *service;
9208 GSList *services = NULL, *list;
9211 DBG("keeping %p %s", allowed, allowed->path);
9213 #if defined TIZEN_EXT
9214 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
9218 for (iter = service_list; iter; iter = iter->next) {
9219 service = iter->data;
9221 #if defined TIZEN_EXT
9222 if (service != allowed && service->type != allowed->type &&
9223 __connman_service_can_drop(service) == TRUE)
9225 if (!is_connected(service->state))
9228 if (service == allowed)
9232 services = g_slist_prepend(services, service);
9235 for (list = services; list; list = list->next) {
9236 service = list->data;
9238 DBG("disconnecting %p %s", service, service->path);
9239 #if defined TIZEN_EXT
9240 __connman_service_disconnect_default(service);
9242 __connman_service_disconnect(service);
9245 g_slist_free(services);
9248 #if defined TIZEN_EXT
9249 static void set_priority_connected_service(void)
9251 struct connman_service *service;
9254 for (list = service_list; list; list = list->next) {
9255 service = list->data;
9257 if (is_connected(service->state) == FALSE)
9260 #if defined TIZEN_MAINTAIN_ONLINE
9262 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
9263 service->state == CONNMAN_SERVICE_STATE_ONLINE)
9265 else if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
9276 static void emit_wifi_roaming_failure(struct connman_service *service,
9277 enum connman_service_state new_state)
9279 if (connman_setting_get_bool("WifiRoaming") &&
9280 connman_network_get_bool(service->network, "WiFi.Roaming")) {
9281 const char *cur_bssid;
9282 const char *dst_bssid;
9284 struct connman_device *device;
9286 device = connman_network_get_device(service->network);
9288 ifname = connman_device_get_string(device, "Interface");
9289 cur_bssid = connman_network_get_string(service->network,
9290 "WiFi.RoamingCurBSSID");
9291 dst_bssid = connman_network_get_string(service->network,
9292 "WiFi.RoamingDstBSSID");
9295 if (device && ifname && cur_bssid && dst_bssid) {
9297 case CONNMAN_SERVICE_STATE_UNKNOWN:
9298 case CONNMAN_SERVICE_STATE_ASSOCIATION:
9299 case CONNMAN_SERVICE_STATE_CONFIGURATION:
9300 case CONNMAN_SERVICE_STATE_READY:
9301 case CONNMAN_SERVICE_STATE_ONLINE:
9303 case CONNMAN_SERVICE_STATE_DISCONNECT:
9304 case CONNMAN_SERVICE_STATE_FAILURE:
9305 case CONNMAN_SERVICE_STATE_IDLE:
9306 __connman_technology_notify_roaming_state(ifname,
9307 "failure", cur_bssid, dst_bssid);
9308 connman_network_set_bool(service->network,
9309 "WiFi.Roaming", false);
9310 connman_network_set_string(service->network,
9311 "WiFi.RoamingCurBSSID", NULL);
9312 connman_network_set_string(service->network,
9313 "WiFi.RoamingDstBSSID", NULL);
9321 static const char *get_dbus_sender(struct connman_service *service)
9323 if (!service->pending)
9326 return dbus_message_get_sender(service->pending);
9329 static int service_indicate_state(struct connman_service *service)
9331 enum connman_service_state old_state, new_state;
9332 struct connman_service *def_service;
9333 enum connman_ipconfig_method method;
9339 old_state = service->state;
9340 new_state = combine_state(service->state_ipv4, service->state_ipv6);
9342 DBG("service %p old %s - new %s/%s => %s",
9344 state2string(old_state),
9345 state2string(service->state_ipv4),
9346 state2string(service->state_ipv6),
9347 state2string(new_state));
9349 if (old_state == new_state)
9352 def_service = connman_service_get_default();
9354 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
9355 result = service_update_preferred_order(def_service,
9356 service, new_state);
9357 if (result == -EALREADY)
9361 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
9362 __connman_notifier_leave_online(service->type);
9364 if (is_connected(old_state) && !is_connected(new_state))
9365 searchdomain_remove_all(service);
9367 service->state = new_state;
9368 #if defined TIZEN_EXT
9369 if (!is_connected(old_state) && is_connected(new_state))
9370 connman_device_send_connected_signal(
9371 connman_network_get_device(service->network), true);
9372 else if (is_connected(old_state) && !is_connected(new_state))
9373 connman_device_send_connected_signal(
9374 connman_network_get_device(service->network), false);
9376 state_changed(service);
9378 if (!is_connected(old_state) && is_connected(new_state))
9379 searchdomain_add_all(service);
9382 case CONNMAN_SERVICE_STATE_UNKNOWN:
9386 case CONNMAN_SERVICE_STATE_IDLE:
9387 if (old_state == CONNMAN_SERVICE_STATE_FAILURE &&
9388 service->connect_reason ==
9389 CONNMAN_SERVICE_CONNECT_REASON_NATIVE &&
9391 CONNMAN_SERVICE_ERROR_INVALID_KEY) {
9392 __connman_service_clear_error(service);
9393 service_complete(service);
9396 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
9397 __connman_service_disconnect(service);
9401 case CONNMAN_SERVICE_STATE_ASSOCIATION:
9405 case CONNMAN_SERVICE_STATE_CONFIGURATION:
9406 if (!service->new_service &&
9407 __connman_stats_service_register(service) == 0) {
9409 * For new services the statistics are updated after
9410 * we have successfully connected.
9412 __connman_stats_get(service, false,
9413 &service->stats.data);
9414 __connman_stats_get(service, true,
9415 &service->stats_roaming.data);
9420 case CONNMAN_SERVICE_STATE_READY:
9421 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
9423 if (service->new_service &&
9424 __connman_stats_service_register(service) == 0) {
9426 * This is normally done after configuring state
9427 * but for new service do this after we have connected
9430 __connman_stats_get(service, false,
9431 &service->stats.data);
9432 __connman_stats_get(service, true,
9433 &service->stats_roaming.data);
9436 service->new_service = false;
9438 def_service = connman_service_get_default();
9440 service_update_preferred_order(def_service, service, new_state);
9444 __connman_service_set_favorite(service, true);
9446 reply_pending(service, 0);
9448 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
9449 connman_network_get_bool(service->network,
9453 pass = connman_network_get_string(service->network,
9456 __connman_service_set_passphrase(service, pass);
9458 connman_network_set_bool(service->network,
9459 "WiFi.UseWPS", false);
9462 gettimeofday(&service->modified, NULL);
9463 service_save(service);
9465 domain_changed(service);
9466 proxy_changed(service);
9468 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
9469 __connman_notifier_connect(service->type);
9471 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
9472 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
9473 __connman_ipconfig_disable_ipv6(
9474 service->ipconfig_ipv6);
9476 #if !defined TIZEN_MAINTAIN_ONLINE
9477 if (connman_setting_get_bool("SingleConnectedTechnology"))
9478 single_connected_tech(service);
9479 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
9482 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
9486 #if defined TIZEN_EXT
9487 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9488 set_priority_connected_service();
9493 case CONNMAN_SERVICE_STATE_ONLINE:
9494 #if defined TIZEN_MAINTAIN_ONLINE
9495 #if defined TIZEN_EXT
9496 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9497 set_priority_connected_service();
9500 if (connman_setting_get_bool("SingleConnectedTechnology"))
9501 single_connected_tech(service);
9504 #if defined TIZEN_EXT
9505 if (TIZEN_INS_ENABLED && service->type == CONNMAN_SERVICE_TYPE_WIFI)
9506 connman_service_set_internet_connection(service, true);
9510 case CONNMAN_SERVICE_STATE_DISCONNECT:
9511 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
9513 reply_pending(service, ECONNABORTED);
9517 __connman_wispr_stop(service);
9519 __connman_wpad_stop(service);
9521 #if defined TIZEN_EXT
9523 * Skip the functions if there is any connected profiles
9524 * that use same interface
9526 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
9527 __connman_service_get_connected_count_of_iface(
9530 domain_changed(service);
9531 proxy_changed(service);
9532 #if defined TIZEN_EXT
9535 emit_wifi_roaming_failure(service, new_state);
9539 * Previous services which are connected and which states
9540 * are set to online should reset relevantly ipconfig_state
9541 * to ready so wispr/portal will be rerun on those
9543 downgrade_connected_services();
9545 do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
9548 case CONNMAN_SERVICE_STATE_FAILURE:
9549 #if defined TIZEN_EXT
9550 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9552 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
9554 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER ||
9555 service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_NATIVE) {
9556 connman_agent_report_error(service, service->path,
9557 error2string(service->error),
9559 get_dbus_sender(service),
9561 #if !defined TIZEN_EXT
9565 service_complete(service);
9569 service_list_sort();
9571 #if defined TIZEN_EXT
9572 #if defined TIZEN_MAINTAIN_ONLINE
9573 __connman_service_connect_default(service, old_state);
9575 __connman_service_connect_default(service);
9577 emit_wifi_roaming_failure(service, new_state);
9580 __connman_connection_update_gateway();
9582 #if !defined TIZEN_EXT
9585 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
9586 new_state != CONNMAN_SERVICE_STATE_READY) ||
9587 (old_state == CONNMAN_SERVICE_STATE_READY &&
9588 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
9589 __connman_notifier_disconnect(service->type);
9592 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
9593 __connman_notifier_enter_online(service->type);
9600 int __connman_service_indicate_error(struct connman_service *service,
9601 enum connman_service_error error)
9603 DBG("service %p error %d", service, error);
9608 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
9611 #if defined TIZEN_EXT
9613 * change connman_service_error type
9614 * from CONNMAN_SERVICE_ERROR_AUTH_FAILED to CONNMAN_SERVICE_ERROR_INVALID_KEY
9615 * in case of SAE security type.
9617 if (error == CONNMAN_SERVICE_ERROR_AUTH_FAILED &&
9618 service->security == CONNMAN_SERVICE_SECURITY_SAE) {
9619 DBG("SAE security auth failed, set error to invalid-key and ignore the service");
9620 error = CONNMAN_SERVICE_ERROR_INVALID_KEY;
9621 __connman_service_set_ignore(service, true);
9625 set_error(service, error);
9627 /* default internet service: fix not cleared if pdp activation*/
9628 #if defined TIZEN_EXT
9630 * If connection failed for default service(DefaultInternet),
9631 * default_connecting_device should be cleared.
9633 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
9634 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
9635 __connman_service_disconnect_default(service);
9637 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
9638 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
9639 g_free(service->passphrase);
9640 service->passphrase = NULL;
9644 __connman_service_ipconfig_indicate_state(service,
9645 CONNMAN_SERVICE_STATE_FAILURE,
9646 CONNMAN_IPCONFIG_TYPE_IPV4);
9647 __connman_service_ipconfig_indicate_state(service,
9648 CONNMAN_SERVICE_STATE_FAILURE,
9649 CONNMAN_IPCONFIG_TYPE_IPV6);
9653 int __connman_service_clear_error(struct connman_service *service)
9655 DBusMessage *pending, *provider_pending;
9657 DBG("service %p", service);
9662 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
9665 pending = service->pending;
9666 service->pending = NULL;
9667 provider_pending = service->provider_pending;
9668 service->provider_pending = NULL;
9670 __connman_service_ipconfig_indicate_state(service,
9671 CONNMAN_SERVICE_STATE_IDLE,
9672 CONNMAN_IPCONFIG_TYPE_IPV6);
9674 __connman_service_ipconfig_indicate_state(service,
9675 CONNMAN_SERVICE_STATE_IDLE,
9676 CONNMAN_IPCONFIG_TYPE_IPV4);
9678 service->pending = pending;
9679 service->provider_pending = provider_pending;
9684 int __connman_service_indicate_default(struct connman_service *service)
9686 DBG("service %p state %s", service, state2string(service->state));
9688 if (!is_connected(service->state)) {
9690 * If service is not yet fully connected, then we must not
9691 * change the default yet. The default gw will be changed
9692 * after the service state is in ready.
9694 return -EINPROGRESS;
9702 enum connman_service_state __connman_service_ipconfig_get_state(
9703 struct connman_service *service,
9704 enum connman_ipconfig_type type)
9707 return CONNMAN_SERVICE_STATE_UNKNOWN;
9709 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9710 return service->state_ipv4;
9712 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
9713 return service->state_ipv6;
9715 return CONNMAN_SERVICE_STATE_UNKNOWN;
9718 #if defined TIZEN_EXT
9719 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
9721 DBG("check the proxy and start wispr");
9722 check_proxy_setup(service);
9728 * How many networks are connected at the same time. If more than 1,
9729 * then set the rp_filter setting properly (loose mode routing) so that network
9730 * connectivity works ok. This is only done for IPv4 networks as IPv6
9731 * does not have rp_filter knob.
9733 static int connected_networks_count;
9734 static int original_rp_filter;
9736 static void service_rp_filter(struct connman_service *service,
9739 enum connman_ipconfig_method method;
9741 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
9744 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
9745 case CONNMAN_IPCONFIG_METHOD_OFF:
9746 case CONNMAN_IPCONFIG_METHOD_AUTO:
9748 case CONNMAN_IPCONFIG_METHOD_FIXED:
9749 case CONNMAN_IPCONFIG_METHOD_MANUAL:
9750 case CONNMAN_IPCONFIG_METHOD_DHCP:
9755 if (connected_networks_count == 1) {
9757 filter_value = __connman_ipconfig_set_rp_filter();
9758 if (filter_value < 0)
9761 original_rp_filter = filter_value;
9763 connected_networks_count++;
9766 if (connected_networks_count == 2)
9767 __connman_ipconfig_unset_rp_filter(original_rp_filter);
9769 connected_networks_count--;
9770 if (connected_networks_count < 0)
9771 connected_networks_count = 0;
9774 DBG("%s %s ipconfig %p method %d count %d filter %d",
9775 connected ? "connected" : "disconnected", service->identifier,
9776 service->ipconfig_ipv4, method,
9777 connected_networks_count, original_rp_filter);
9780 static void redo_wispr(struct connman_service *service,
9781 enum connman_ipconfig_type type)
9783 service->online_timeout = 0;
9784 connman_service_unref(service);
9786 DBG("Retrying %s WISPr for %p %s",
9787 __connman_ipconfig_type2string(type),
9788 service, service->name);
9790 __connman_wispr_start(service, type);
9793 static gboolean redo_wispr_ipv4(gpointer user_data)
9795 struct connman_service *service = user_data;
9797 #if defined TIZEN_MAINTAIN_ONLINE
9800 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
9802 redo_wispr(service, CONNMAN_IPCONFIG_TYPE_IPV4);
9808 static gboolean redo_wispr_ipv6(gpointer user_data)
9810 struct connman_service *service = user_data;
9812 redo_wispr(service, CONNMAN_IPCONFIG_TYPE_IPV6);
9817 void __connman_service_online_check(struct connman_service *service,
9818 enum connman_ipconfig_type type,
9821 GSourceFunc redo_func;
9822 unsigned int *interval;
9823 enum connman_service_state current_state;
9825 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
9826 interval = &service->online_check_interval_ipv4;
9827 redo_func = redo_wispr_ipv4;
9829 interval = &service->online_check_interval_ipv6;
9830 redo_func = redo_wispr_ipv6;
9833 if(!enable_online_to_ready_transition)
9837 *interval = online_check_max_interval;
9839 current_state = service->state;
9840 downgrade_state(service);
9841 if (current_state != service->state)
9842 *interval = online_check_initial_interval;
9843 if (service != connman_service_get_default()) {
9849 DBG("service %p type %s interval %d", service,
9850 __connman_ipconfig_type2string(type), *interval);
9852 service->online_timeout = g_timeout_add_seconds(*interval * *interval,
9853 redo_func, connman_service_ref(service));
9855 /* Increment the interval for the next time, set a maximum timeout of
9856 * online_check_max_interval seconds * online_check_max_interval seconds.
9858 if (*interval < online_check_max_interval)
9862 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
9863 enum connman_service_state new_state,
9864 enum connman_ipconfig_type type)
9866 struct connman_ipconfig *ipconfig = NULL;
9867 enum connman_service_state old_state;
9868 enum connman_ipconfig_method method;
9874 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
9875 case CONNMAN_IPCONFIG_TYPE_ALL:
9878 case CONNMAN_IPCONFIG_TYPE_IPV4:
9879 old_state = service->state_ipv4;
9880 ipconfig = service->ipconfig_ipv4;
9884 case CONNMAN_IPCONFIG_TYPE_IPV6:
9885 old_state = service->state_ipv6;
9886 ipconfig = service->ipconfig_ipv6;
9894 method = __connman_ipconfig_get_method(ipconfig);
9897 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
9898 case CONNMAN_IPCONFIG_METHOD_OFF:
9899 if (new_state != CONNMAN_SERVICE_STATE_IDLE)
9900 connman_warn("ipconfig state %d ipconfig method %d",
9903 #if defined TIZEN_EXT
9904 if (old_state != CONNMAN_SERVICE_STATE_READY &&
9905 old_state != CONNMAN_SERVICE_STATE_ONLINE)
9907 new_state = CONNMAN_SERVICE_STATE_IDLE;
9910 case CONNMAN_IPCONFIG_METHOD_FIXED:
9911 case CONNMAN_IPCONFIG_METHOD_MANUAL:
9912 case CONNMAN_IPCONFIG_METHOD_DHCP:
9913 case CONNMAN_IPCONFIG_METHOD_AUTO:
9919 if (old_state == new_state)
9922 #if defined TIZEN_EXT
9923 __sync_synchronize();
9924 if (service->user_pdn_connection_refcount > 0 &&
9925 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
9926 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
9927 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
9928 new_state == CONNMAN_SERVICE_STATE_IDLE) {
9929 service->user_pdn_connection_refcount = 0;
9930 __sync_synchronize();
9934 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
9935 service, service ? service->identifier : NULL,
9936 old_state, state2string(old_state),
9937 new_state, state2string(new_state),
9938 type, __connman_ipconfig_type2string(type));
9940 switch (new_state) {
9941 case CONNMAN_SERVICE_STATE_UNKNOWN:
9942 case CONNMAN_SERVICE_STATE_ASSOCIATION:
9944 case CONNMAN_SERVICE_STATE_CONFIGURATION:
9946 case CONNMAN_SERVICE_STATE_READY:
9947 #if defined TIZEN_EXT
9948 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
9949 __connman_service_is_internet_profile(service) != TRUE) {
9950 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9951 service_rp_filter(service, TRUE);
9956 if (connman_setting_get_bool("EnableOnlineCheck"))
9957 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
9958 #if !defined TIZEN_EXT
9959 check_proxy_setup(service);
9961 #if defined TIZEN_MAINTAIN_ONLINE
9962 /* if (old_state == CONNMAN_SERVICE_STATE_ONLINE) */
9963 check_proxy_setup(service);
9966 __connman_service_wispr_start(service, type);
9969 connman_info("Online check disabled. "
9970 "Default service remains in READY state.");
9971 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9972 service_rp_filter(service, true);
9973 set_mdns(service, service->mdns_config);
9975 case CONNMAN_SERVICE_STATE_ONLINE:
9977 case CONNMAN_SERVICE_STATE_DISCONNECT:
9978 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
9981 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9982 service_rp_filter(service, false);
9986 case CONNMAN_SERVICE_STATE_IDLE:
9987 case CONNMAN_SERVICE_STATE_FAILURE:
9988 __connman_ipconfig_disable(ipconfig);
9993 if (is_connected(old_state) && !is_connected(new_state)) {
9994 nameserver_remove_all(service, type);
9995 cancel_online_check(service);
9998 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9999 service->state_ipv4 = new_state;
10001 service->state_ipv6 = new_state;
10003 if (!is_connected(old_state) && is_connected(new_state))
10004 nameserver_add_all(service, type);
10006 __connman_timeserver_sync(service);
10008 #if defined TIZEN_EXT
10009 int ret = service_indicate_state(service);
10010 /*Sent the Ready changed signal again in case IPv4 IP set
10011 after IPv6 IP set*/
10013 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
10014 && new_state == CONNMAN_SERVICE_STATE_READY) {
10015 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
10016 state_changed(service);
10021 return service_indicate_state(service);
10024 static bool prepare_network(struct connman_service *service)
10026 enum connman_network_type type;
10027 unsigned int ssid_len;
10029 type = connman_network_get_type(service->network);
10032 case CONNMAN_NETWORK_TYPE_UNKNOWN:
10033 case CONNMAN_NETWORK_TYPE_VENDOR:
10035 case CONNMAN_NETWORK_TYPE_WIFI:
10036 if (!connman_network_get_blob(service->network, "WiFi.SSID",
10040 if (service->passphrase)
10041 connman_network_set_string(service->network,
10042 "WiFi.Passphrase", service->passphrase);
10044 case CONNMAN_NETWORK_TYPE_ETHERNET:
10045 case CONNMAN_NETWORK_TYPE_GADGET:
10046 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
10047 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
10048 case CONNMAN_NETWORK_TYPE_CELLULAR:
10055 static void prepare_8021x(struct connman_service *service)
10058 connman_network_set_string(service->network, "WiFi.EAP",
10061 if (service->identity)
10062 connman_network_set_string(service->network, "WiFi.Identity",
10063 service->identity);
10065 if (service->anonymous_identity)
10066 connman_network_set_string(service->network,
10067 "WiFi.AnonymousIdentity",
10068 service->anonymous_identity);
10070 if (service->ca_cert_file)
10071 connman_network_set_string(service->network, "WiFi.CACertFile",
10072 service->ca_cert_file);
10074 if (service->subject_match)
10075 connman_network_set_string(service->network, "WiFi.SubjectMatch",
10076 service->subject_match);
10078 if (service->altsubject_match)
10079 connman_network_set_string(service->network, "WiFi.AltSubjectMatch",
10080 service->altsubject_match);
10082 if (service->domain_suffix_match)
10083 connman_network_set_string(service->network, "WiFi.DomainSuffixMatch",
10084 service->domain_suffix_match);
10086 if (service->domain_match)
10087 connman_network_set_string(service->network, "WiFi.DomainMatch",
10088 service->domain_match);
10090 if (service->client_cert_file)
10091 connman_network_set_string(service->network,
10092 "WiFi.ClientCertFile",
10093 service->client_cert_file);
10095 if (service->private_key_file)
10096 connman_network_set_string(service->network,
10097 "WiFi.PrivateKeyFile",
10098 service->private_key_file);
10100 if (service->private_key_passphrase)
10101 connman_network_set_string(service->network,
10102 "WiFi.PrivateKeyPassphrase",
10103 service->private_key_passphrase);
10105 if (service->phase2)
10106 connman_network_set_string(service->network, "WiFi.Phase2",
10109 #if defined TIZEN_EXT
10110 if (service->keymgmt_type)
10111 connman_network_set_string(service->network, "WiFi.KeymgmtType",
10112 service->keymgmt_type);
10114 DBG("service->phase1 : %s", service->phase1);
10115 if (service->phase1)
10116 connman_network_set_string(service->network, "WiFi.Phase1",
10121 #if defined TIZEN_EXT
10122 static bool has_valid_configuration_object(struct connman_service *service)
10124 return service->connector && service->c_sign_key && service->net_access_key;
10127 static void prepare_dpp(struct connman_service *service)
10129 DBG("prepare dpp");
10130 if (service->connector)
10131 connman_network_set_string(service->network, "WiFi.Connector",
10132 service->connector);
10134 if (service->c_sign_key)
10135 connman_network_set_string(service->network, "WiFi.CSignKey",
10136 service->c_sign_key);
10138 if (service->net_access_key)
10139 connman_network_set_string(service->network, "WiFi.NetAccessKey",
10140 service->net_access_key);
10144 static int service_connect(struct connman_service *service)
10148 if (service->hidden)
10151 #if defined TIZEN_EXT
10155 index = __connman_service_get_index(service);
10157 for (list = service_list; list; list = list->next) {
10158 struct connman_service *temp = list->data;
10160 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
10163 if (!is_connecting(temp->state) && !is_connected(temp->state))
10166 if (service == temp)
10169 if (service->type != temp->type)
10172 if (__connman_service_get_index(temp) == index &&
10173 __connman_service_disconnect(temp) == -EINPROGRESS)
10174 return -EINPROGRESS;
10178 switch (service->type) {
10179 case CONNMAN_SERVICE_TYPE_UNKNOWN:
10180 case CONNMAN_SERVICE_TYPE_SYSTEM:
10181 case CONNMAN_SERVICE_TYPE_GPS:
10182 case CONNMAN_SERVICE_TYPE_P2P:
10183 #if defined TIZEN_EXT_WIFI_MESH
10184 case CONNMAN_SERVICE_TYPE_MESH:
10187 case CONNMAN_SERVICE_TYPE_ETHERNET:
10188 case CONNMAN_SERVICE_TYPE_GADGET:
10189 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
10190 case CONNMAN_SERVICE_TYPE_CELLULAR:
10191 case CONNMAN_SERVICE_TYPE_VPN:
10193 case CONNMAN_SERVICE_TYPE_WIFI:
10194 switch (service->security) {
10195 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
10196 case CONNMAN_SERVICE_SECURITY_NONE:
10197 #if defined TIZEN_EXT
10198 case CONNMAN_SERVICE_SECURITY_OWE:
10201 case CONNMAN_SERVICE_SECURITY_WEP:
10202 case CONNMAN_SERVICE_SECURITY_PSK:
10203 case CONNMAN_SERVICE_SECURITY_WPA:
10204 case CONNMAN_SERVICE_SECURITY_RSN:
10205 #if defined TIZEN_EXT
10206 case CONNMAN_SERVICE_SECURITY_SAE:
10208 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
10211 if (!service->passphrase) {
10212 if (!service->network)
10213 return -EOPNOTSUPP;
10215 if (!service->wps ||
10216 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
10221 #if defined TIZEN_EXT
10222 case CONNMAN_SERVICE_SECURITY_DPP:
10223 if (has_valid_configuration_object(service) &&
10228 case CONNMAN_SERVICE_SECURITY_8021X:
10229 if (!service->eap) {
10230 connman_warn("EAP type has not been found. "
10231 "Most likely ConnMan is not able to "
10232 "find a configuration for given "
10234 "Check SSID or Name match with the "
10239 #if defined TIZEN_EXT
10241 * never request credentials if using EAP-TLS, EAP-SIM
10242 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
10243 * need to be fully provisioned)
10245 DBG("service eap: %s", service->eap);
10246 if (g_str_equal(service->eap, "tls") ||
10247 g_str_equal(service->eap, "sim") ||
10248 g_str_equal(service->eap, "aka") ||
10249 g_str_equal(service->eap, "aka'") ||
10250 g_str_equal(service->eap, "pwd") ||
10251 g_str_equal(service->eap, "fast"))
10255 * never request credentials if using EAP-TLS
10256 * (EAP-TLS networks need to be fully provisioned)
10258 if (g_str_equal(service->eap, "tls"))
10263 * Return -ENOKEY if either identity or passphrase is
10264 * missing. Agent provided credentials can be used as
10265 * fallback if needed.
10267 if (((!service->identity &&
10268 !service->agent_identity) ||
10269 !service->passphrase) ||
10270 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
10274 #if defined TIZEN_EXT
10282 if (service->network) {
10283 if (!prepare_network(service))
10286 switch (service->security) {
10287 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
10288 case CONNMAN_SERVICE_SECURITY_NONE:
10289 case CONNMAN_SERVICE_SECURITY_WEP:
10290 case CONNMAN_SERVICE_SECURITY_PSK:
10291 case CONNMAN_SERVICE_SECURITY_WPA:
10292 case CONNMAN_SERVICE_SECURITY_RSN:
10293 #if defined TIZEN_EXT
10294 case CONNMAN_SERVICE_SECURITY_SAE:
10295 case CONNMAN_SERVICE_SECURITY_OWE:
10297 case CONNMAN_SERVICE_SECURITY_DPP:
10298 prepare_dpp(service);
10301 case CONNMAN_SERVICE_SECURITY_8021X:
10302 prepare_8021x(service);
10304 #if defined TIZEN_EXT
10310 if (__connman_stats_service_register(service) == 0) {
10311 __connman_stats_get(service, false,
10312 &service->stats.data);
10313 __connman_stats_get(service, true,
10314 &service->stats_roaming.data);
10317 err = __connman_network_connect(service->network);
10318 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
10320 err = __connman_provider_connect(service->provider,
10321 get_dbus_sender(service));
10323 return -EOPNOTSUPP;
10326 if (err != -EINPROGRESS) {
10327 __connman_service_ipconfig_indicate_state(service,
10328 CONNMAN_SERVICE_STATE_FAILURE,
10329 CONNMAN_IPCONFIG_TYPE_IPV4);
10330 __connman_service_ipconfig_indicate_state(service,
10331 CONNMAN_SERVICE_STATE_FAILURE,
10332 CONNMAN_IPCONFIG_TYPE_IPV6);
10333 __connman_stats_service_unregister(service);
10340 int __connman_service_connect(struct connman_service *service,
10341 enum connman_service_connect_reason reason)
10346 DBG("service %p state %s connect reason %s -> %s",
10347 service, state2string(service->state),
10348 reason2string(service->connect_reason),
10349 reason2string(reason));
10351 if (is_connected(service->state))
10354 if (is_connecting(service->state))
10357 switch (service->type) {
10358 case CONNMAN_SERVICE_TYPE_UNKNOWN:
10359 case CONNMAN_SERVICE_TYPE_SYSTEM:
10360 case CONNMAN_SERVICE_TYPE_GPS:
10361 case CONNMAN_SERVICE_TYPE_P2P:
10362 #if defined TIZEN_EXT_WIFI_MESH
10363 case CONNMAN_SERVICE_TYPE_MESH:
10367 case CONNMAN_SERVICE_TYPE_ETHERNET:
10368 case CONNMAN_SERVICE_TYPE_GADGET:
10369 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
10370 case CONNMAN_SERVICE_TYPE_CELLULAR:
10371 case CONNMAN_SERVICE_TYPE_VPN:
10372 case CONNMAN_SERVICE_TYPE_WIFI:
10376 if (!is_ipconfig_usable(service))
10379 __connman_service_clear_error(service);
10381 if (service->network && service->autoconnect &&
10382 __connman_network_native_autoconnect(service->network)) {
10383 DBG("service %p switch connecting reason to native", service);
10384 reason = CONNMAN_SERVICE_CONNECT_REASON_NATIVE;
10387 err = service_connect(service);
10389 DBG("service %p err %d", service, err);
10391 service->connect_reason = reason;
10392 #if defined TIZEN_EXT
10393 connect_reason_changed(service);
10399 if (err == -EINPROGRESS) {
10400 if (service->timeout == 0)
10401 service->timeout = g_timeout_add_seconds(
10402 CONNECT_TIMEOUT, connect_timeout, service);
10404 return -EINPROGRESS;
10407 if (service->network)
10408 __connman_network_disconnect(service->network);
10409 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
10411 connman_provider_disconnect(service->provider);
10413 if (reason == CONNMAN_SERVICE_CONNECT_REASON_USER ||
10414 reason == CONNMAN_SERVICE_CONNECT_REASON_NATIVE) {
10415 if (err == -ENOKEY || err == -EPERM) {
10416 DBusMessage *pending = NULL;
10417 const char *dbus_sender = get_dbus_sender(service);
10420 * We steal the reply here. The idea is that the
10421 * connecting client will see the connection status
10422 * after the real hidden network is connected or
10423 * connection failed.
10425 if (service->hidden) {
10426 pending = service->pending;
10427 service->pending = NULL;
10430 err = __connman_agent_request_passphrase_input(service,
10434 if (service->hidden && err != -EINPROGRESS)
10435 service->pending = pending;
10437 if (err == -EINPROGRESS) {
10438 index = __connman_service_get_index(service);
10439 g_hash_table_replace(passphrase_requested,
10440 GINT_TO_POINTER(index),
10441 GINT_TO_POINTER(true));
10451 int __connman_service_disconnect(struct connman_service *service)
10455 DBG("service %p", service);
10457 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
10458 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
10460 connman_agent_cancel(service);
10462 __connman_stats_service_unregister(service);
10464 if (service->network) {
10465 err = __connman_network_disconnect(service->network);
10466 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
10468 err = connman_provider_disconnect(service->provider);
10470 return -EOPNOTSUPP;
10472 if (err < 0 && err != -EINPROGRESS)
10475 __connman_6to4_remove(service->ipconfig_ipv4);
10477 if (service->ipconfig_ipv4)
10478 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
10481 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
10484 #if defined TIZEN_EXT
10486 * Skip the functions If there is any connected profiles
10487 * that use same interface
10489 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
10490 __connman_service_get_connected_count_of_iface(service) <= 0) {
10492 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
10493 settings_changed(service, service->ipconfig_ipv4);
10495 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
10496 settings_changed(service, service->ipconfig_ipv6);
10498 __connman_ipconfig_disable(service->ipconfig_ipv4);
10499 __connman_ipconfig_disable(service->ipconfig_ipv6);
10500 #if defined TIZEN_EXT
10507 int __connman_service_disconnect_all(void)
10509 struct connman_service *service;
10510 GSList *services = NULL, *list;
10515 for (iter = service_list; iter; iter = iter->next) {
10516 service = iter->data;
10518 if (!is_connected(service->state))
10521 services = g_slist_prepend(services, service);
10524 for (list = services; list; list = list->next) {
10525 struct connman_service *service = list->data;
10527 service->ignore = true;
10529 __connman_service_disconnect(service);
10532 g_slist_free(services);
10538 * lookup_by_identifier:
10539 * @identifier: service identifier
10541 * Look up a service by identifier (reference count will not be increased)
10543 static struct connman_service *lookup_by_identifier(const char *identifier)
10545 return g_hash_table_lookup(service_hash, identifier);
10548 struct connman_service *connman_service_lookup_from_identifier(const char* identifier)
10550 return identifier ? lookup_by_identifier(identifier) : NULL;
10553 struct provision_user_data {
10558 static void provision_changed(gpointer value, gpointer user_data)
10560 struct connman_service *service = value;
10561 struct provision_user_data *data = user_data;
10562 const char *path = data->ident;
10565 ret = __connman_config_provision_service_ident(service, path,
10566 service->config_file, service->config_entry);
10571 int __connman_service_provision_changed(const char *ident)
10573 struct provision_user_data data = {
10578 g_list_foreach(service_list, provision_changed, (void *)&data);
10581 * Because the provision_changed() might have set some services
10582 * as favorite, we must sort the sequence now.
10584 if (services_dirty) {
10585 services_dirty = false;
10587 service_list_sort();
10589 __connman_connection_update_gateway();
10595 void __connman_service_set_config(struct connman_service *service,
10596 const char *file_id, const char *entry)
10601 g_free(service->config_file);
10602 service->config_file = g_strdup(file_id);
10604 g_free(service->config_entry);
10605 service->config_entry = g_strdup(entry);
10609 * __connman_service_get:
10610 * @identifier: service identifier
10612 * Look up a service by identifier or create a new one if not found
10614 static struct connman_service *service_get(const char *identifier)
10616 struct connman_service *service;
10618 service = g_hash_table_lookup(service_hash, identifier);
10620 connman_service_ref(service);
10624 service = connman_service_create();
10627 #if defined TIZEN_EXT
10628 if (!simplified_log)
10630 DBG("service %p", service);
10632 service->identifier = g_strdup(identifier);
10634 service_list = g_list_insert_sorted(service_list, service,
10637 g_hash_table_insert(service_hash, service->identifier, service);
10642 #if defined TIZEN_EXT
10643 static void service_load_wpa_passphrase(struct connman_service *service)
10652 if (service->security != CONNMAN_SERVICE_SECURITY_SAE)
10655 if (service->passphrase)
10658 if (!service->identifier)
10661 identifier = g_strdup(service->identifier);
10665 ptr = strstr(identifier, "_sae");
10667 g_free(identifier);
10671 memcpy(ptr, "_psk", strlen("_psk"));
10673 keyfile = connman_storage_load_service(identifier);
10675 g_free(identifier);
10679 favorite = g_key_file_get_boolean(keyfile, identifier, "Favorite", NULL);
10680 autoconnect = g_key_file_get_boolean(keyfile, identifier, "AutoConnect", NULL);
10682 if (!favorite || !autoconnect) {
10683 g_free(identifier);
10684 g_key_file_free(keyfile);
10688 passphrase = g_key_file_get_string(keyfile, identifier, "Passphrase", NULL);
10690 service->passphrase = g_strdup(passphrase);
10691 service->favorite = favorite;
10692 service->autoconnect = autoconnect;
10695 g_free(identifier);
10696 g_free(passphrase);
10697 g_key_file_free(keyfile);
10701 static int service_register(struct connman_service *service)
10703 #if defined TIZEN_EXT
10704 if (!simplified_log)
10706 DBG("service %p", service);
10711 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
10712 service->identifier);
10714 DBG("path %s", service->path);
10716 #if defined TIZEN_EXT
10718 service_load(service);
10719 service_load_wpa_passphrase(service);
10721 if (TIZEN_INS_ENABLED) {
10722 ret = service_ext_load(service);
10723 if (ret == -ERANGE)
10724 service_ext_save(service);
10727 ret = __connman_config_provision_service(service);
10728 if (ret < 0 && !simplified_log)
10729 DBG("Failed to provision service");
10731 if (__connman_config_provision_service(service) < 0)
10732 service_load(service);
10733 #endif /* defined TIZEN_EXT */
10735 g_dbus_register_interface(connection, service->path,
10736 CONNMAN_SERVICE_INTERFACE,
10737 service_methods, service_signals,
10738 NULL, service, NULL);
10740 if (__connman_config_provision_service(service) < 0)
10741 service_load(service);
10743 service_list_sort();
10745 __connman_connection_update_gateway();
10750 static void service_up(struct connman_ipconfig *ipconfig,
10751 const char *ifname)
10753 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10755 DBG("%s up", ifname);
10757 link_changed(service);
10759 service->stats.valid = false;
10760 service->stats_roaming.valid = false;
10763 static void service_down(struct connman_ipconfig *ipconfig,
10764 const char *ifname)
10766 DBG("%s down", ifname);
10769 static void service_lower_up(struct connman_ipconfig *ipconfig,
10770 const char *ifname)
10772 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10774 DBG("%s lower up", ifname);
10776 stats_start(service);
10779 static void service_lower_down(struct connman_ipconfig *ipconfig,
10780 const char *ifname)
10782 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10784 DBG("%s lower down", ifname);
10786 stats_stop(service);
10787 service_save(service);
10790 static void service_ip_bound(struct connman_ipconfig *ipconfig,
10791 const char *ifname)
10793 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10794 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
10795 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
10796 #if defined TIZEN_EXT
10800 DBG("%s ip bound", ifname);
10802 type = __connman_ipconfig_get_config_type(ipconfig);
10803 method = __connman_ipconfig_get_method(ipconfig);
10805 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
10808 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
10809 method == CONNMAN_IPCONFIG_METHOD_AUTO)
10810 #if defined TIZEN_EXT
10812 err = __connman_ipconfig_gateway_add(ipconfig, service);
10815 DBG("Failed to add gateway");
10818 __connman_service_ipconfig_indicate_state(service,
10819 CONNMAN_SERVICE_STATE_READY,
10820 CONNMAN_IPCONFIG_TYPE_IPV6);
10823 settings_changed(service, ipconfig);
10824 address_updated(service, type);
10827 static void service_ip_release(struct connman_ipconfig *ipconfig,
10828 const char *ifname)
10830 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10831 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
10832 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
10834 DBG("%s ip release", ifname);
10836 type = __connman_ipconfig_get_config_type(ipconfig);
10837 method = __connman_ipconfig_get_method(ipconfig);
10839 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
10842 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
10843 method == CONNMAN_IPCONFIG_METHOD_OFF)
10844 __connman_service_ipconfig_indicate_state(service,
10845 CONNMAN_SERVICE_STATE_DISCONNECT,
10846 CONNMAN_IPCONFIG_TYPE_IPV6);
10848 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
10849 method == CONNMAN_IPCONFIG_METHOD_OFF)
10850 __connman_service_ipconfig_indicate_state(service,
10851 CONNMAN_SERVICE_STATE_DISCONNECT,
10852 CONNMAN_IPCONFIG_TYPE_IPV4);
10854 settings_changed(service, ipconfig);
10857 static void service_route_changed(struct connman_ipconfig *ipconfig,
10858 const char *ifname)
10860 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10862 DBG("%s route changed", ifname);
10864 settings_changed(service, ipconfig);
10867 static const struct connman_ipconfig_ops service_ops = {
10869 .down = service_down,
10870 .lower_up = service_lower_up,
10871 .lower_down = service_lower_down,
10872 .ip_bound = service_ip_bound,
10873 .ip_release = service_ip_release,
10874 .route_set = service_route_changed,
10875 .route_unset = service_route_changed,
10878 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
10879 int index, enum connman_ipconfig_method method)
10881 struct connman_ipconfig *ipconfig_ipv4;
10883 ipconfig_ipv4 = __connman_ipconfig_create(index,
10884 CONNMAN_IPCONFIG_TYPE_IPV4);
10885 if (!ipconfig_ipv4)
10888 __connman_ipconfig_set_method(ipconfig_ipv4, method);
10890 __connman_ipconfig_set_data(ipconfig_ipv4, service);
10892 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
10894 return ipconfig_ipv4;
10897 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
10900 struct connman_ipconfig *ipconfig_ipv6;
10902 ipconfig_ipv6 = __connman_ipconfig_create(index,
10903 CONNMAN_IPCONFIG_TYPE_IPV6);
10904 if (!ipconfig_ipv6)
10907 __connman_ipconfig_set_data(ipconfig_ipv6, service);
10909 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
10911 return ipconfig_ipv6;
10914 void __connman_service_read_ip4config(struct connman_service *service)
10918 if (!service->ipconfig_ipv4)
10921 keyfile = connman_storage_load_service(service->identifier);
10925 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
10926 service->identifier, "IPv4.");
10928 g_key_file_free(keyfile);
10931 void connman_service_create_ip4config(struct connman_service *service,
10934 DBG("ipv4 %p", service->ipconfig_ipv4);
10936 if (service->ipconfig_ipv4)
10939 service->ipconfig_ipv4 = create_ip4config(service, index,
10940 CONNMAN_IPCONFIG_METHOD_DHCP);
10941 __connman_service_read_ip4config(service);
10944 void __connman_service_read_ip6config(struct connman_service *service)
10948 if (!service->ipconfig_ipv6)
10951 keyfile = connman_storage_load_service(service->identifier);
10955 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
10956 service->identifier, "IPv6.");
10958 g_key_file_free(keyfile);
10961 void connman_service_create_ip6config(struct connman_service *service,
10964 DBG("ipv6 %p", service->ipconfig_ipv6);
10966 if (service->ipconfig_ipv6)
10969 service->ipconfig_ipv6 = create_ip6config(service, index);
10971 __connman_service_read_ip6config(service);
10975 * connman_service_lookup_from_network:
10976 * @network: network structure
10978 * Look up a service by network (reference count will not be increased)
10980 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
10982 struct connman_service *service;
10983 const char *ident, *group;
10989 ident = __connman_network_get_ident(network);
10993 group = connman_network_get_group(network);
10997 name = g_strdup_printf("%s_%s_%s",
10998 __connman_network_get_type(network), ident, group);
10999 service = lookup_by_identifier(name);
11005 struct connman_service *__connman_service_lookup_from_index(int index)
11007 struct connman_service *service;
11010 for (list = service_list; list; list = list->next) {
11011 service = list->data;
11013 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
11017 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
11025 const char *connman_service_get_identifier(struct connman_service *service)
11027 return service ? service->identifier : NULL;
11030 const char *__connman_service_get_path(struct connman_service *service)
11032 return service->path;
11035 const char *__connman_service_get_name(struct connman_service *service)
11037 return service->name;
11040 enum connman_service_state connman_service_get_state(struct connman_service *service)
11042 return service ? service->state : CONNMAN_SERVICE_STATE_UNKNOWN;
11045 static enum connman_service_type convert_network_type(struct connman_network *network)
11047 enum connman_network_type type = connman_network_get_type(network);
11050 case CONNMAN_NETWORK_TYPE_UNKNOWN:
11051 case CONNMAN_NETWORK_TYPE_VENDOR:
11053 case CONNMAN_NETWORK_TYPE_ETHERNET:
11054 return CONNMAN_SERVICE_TYPE_ETHERNET;
11055 case CONNMAN_NETWORK_TYPE_WIFI:
11056 return CONNMAN_SERVICE_TYPE_WIFI;
11057 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
11058 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
11059 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
11060 case CONNMAN_NETWORK_TYPE_CELLULAR:
11061 return CONNMAN_SERVICE_TYPE_CELLULAR;
11062 case CONNMAN_NETWORK_TYPE_GADGET:
11063 return CONNMAN_SERVICE_TYPE_GADGET;
11066 return CONNMAN_SERVICE_TYPE_UNKNOWN;
11069 static enum connman_service_security convert_wifi_security(const char *security)
11072 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
11073 else if (g_str_equal(security, "none"))
11074 return CONNMAN_SERVICE_SECURITY_NONE;
11075 else if (g_str_equal(security, "wep"))
11076 return CONNMAN_SERVICE_SECURITY_WEP;
11077 else if (g_str_equal(security, "psk"))
11078 return CONNMAN_SERVICE_SECURITY_PSK;
11079 else if (g_str_equal(security, "ieee8021x"))
11080 return CONNMAN_SERVICE_SECURITY_8021X;
11081 else if (g_str_equal(security, "wpa"))
11082 return CONNMAN_SERVICE_SECURITY_WPA;
11083 else if (g_str_equal(security, "rsn"))
11084 return CONNMAN_SERVICE_SECURITY_RSN;
11085 #if defined TIZEN_EXT
11086 else if (g_str_equal(security, "sae"))
11087 return CONNMAN_SERVICE_SECURITY_SAE;
11088 else if (g_str_equal(security, "owe"))
11089 return CONNMAN_SERVICE_SECURITY_OWE;
11090 else if (g_str_equal(security, "dpp"))
11091 return CONNMAN_SERVICE_SECURITY_DPP;
11092 else if (g_str_equal(security, "ft_psk") == TRUE)
11093 return CONNMAN_SERVICE_SECURITY_PSK;
11094 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
11095 return CONNMAN_SERVICE_SECURITY_8021X;
11098 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
11101 #if defined TIZEN_EXT
11102 int check_passphrase_ext(struct connman_network *network,
11103 const char *passphrase)
11106 enum connman_service_security security;
11108 str = connman_network_get_string(network, "WiFi.Security");
11109 security = convert_wifi_security(str);
11111 return __connman_service_check_passphrase(security, passphrase);
11115 static void update_wps_values(struct connman_service *service,
11116 struct connman_network *network)
11118 bool wps = connman_network_get_bool(network, "WiFi.WPS");
11119 bool wps_advertising = connman_network_get_bool(network,
11120 "WiFi.WPSAdvertising");
11122 if (service->wps != wps ||
11123 service->wps_advertizing != wps_advertising) {
11124 service->wps = wps;
11125 service->wps_advertizing = wps_advertising;
11126 security_changed(service);
11130 static void update_from_network(struct connman_service *service,
11131 struct connman_network *network)
11133 uint8_t strength = service->strength;
11136 DBG("service %p network %p", service, network);
11138 if (is_connected(service->state))
11141 if (is_connecting(service->state))
11144 str = connman_network_get_string(network, "Name");
11146 g_free(service->name);
11147 service->name = g_strdup(str);
11148 service->hidden = false;
11150 g_free(service->name);
11151 service->name = NULL;
11152 service->hidden = true;
11155 service->strength = connman_network_get_strength(network);
11156 service->roaming = connman_network_get_bool(network, "Roaming");
11158 if (service->strength == 0) {
11160 * Filter out 0-values; it's unclear what they mean
11161 * and they cause anomalous sorting of the priority list.
11163 service->strength = strength;
11166 str = connman_network_get_string(network, "WiFi.Security");
11167 service->security = convert_wifi_security(str);
11169 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
11170 update_wps_values(service, network);
11172 if (service->strength > strength && service->network) {
11173 connman_network_unref(service->network);
11174 service->network = connman_network_ref(network);
11176 strength_changed(service);
11179 if (!service->network)
11180 service->network = connman_network_ref(network);
11182 service_list_sort();
11185 static void trigger_autoconnect(struct connman_service *service)
11187 struct connman_device *device;
11190 if (!service->favorite)
11193 native = __connman_network_native_autoconnect(service->network);
11194 if (native && service->autoconnect) {
11195 DBG("trigger native autoconnect");
11196 connman_network_set_autoconnect(service->network, true);
11200 device = connman_network_get_device(service->network);
11201 if (device && connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_UNKNOWN))
11204 switch (service->type) {
11205 case CONNMAN_SERVICE_TYPE_UNKNOWN:
11206 case CONNMAN_SERVICE_TYPE_SYSTEM:
11207 case CONNMAN_SERVICE_TYPE_P2P:
11208 #if defined TIZEN_EXT_WIFI_MESH
11209 case CONNMAN_SERVICE_TYPE_MESH:
11213 case CONNMAN_SERVICE_TYPE_GADGET:
11214 case CONNMAN_SERVICE_TYPE_ETHERNET:
11215 if (service->autoconnect) {
11216 __connman_service_connect(service,
11217 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
11222 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
11223 case CONNMAN_SERVICE_TYPE_GPS:
11224 case CONNMAN_SERVICE_TYPE_VPN:
11225 case CONNMAN_SERVICE_TYPE_WIFI:
11226 case CONNMAN_SERVICE_TYPE_CELLULAR:
11227 do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
11231 #if defined TIZEN_EXT
11232 /* TIZEN synchronizes below information when the service creates */
11233 if (service->eap != NULL)
11234 connman_network_set_string(service->network, "WiFi.EAP",
11236 if (service->identity != NULL)
11237 connman_network_set_string(service->network, "WiFi.Identity",
11238 service->identity);
11239 if (service->phase2 != NULL)
11240 connman_network_set_string(service->network, "WiFi.Phase2",
11242 if (service->eap != NULL)
11243 connman_network_set_string(service->network, "WiFi.Connector",
11244 service->connector);
11245 if (service->identity != NULL)
11246 connman_network_set_string(service->network, "WiFi.CSignKey",
11247 service->c_sign_key);
11248 if (service->phase2 != NULL)
11249 connman_network_set_string(service->network, "WiFi.NetAccessKey",
11250 service->net_access_key);
11255 * __connman_service_create_from_network:
11256 * @network: network structure
11258 * Look up service by network and if not found, create one
11260 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
11262 struct connman_service *service;
11263 const char *ident, *group;
11265 unsigned int *auto_connect_types, *favorite_types;
11268 DBG("network %p", network);
11273 ident = __connman_network_get_ident(network);
11277 group = connman_network_get_group(network);
11281 name = g_strdup_printf("%s_%s_%s",
11282 __connman_network_get_type(network), ident, group);
11283 service = service_get(name);
11289 if (__connman_network_get_weakness(network))
11292 index = connman_network_get_index(network);
11294 if (service->path) {
11295 update_from_network(service, network);
11297 if (service->ipconfig_ipv4)
11298 __connman_ipconfig_set_index(service->ipconfig_ipv4,
11301 if (service->ipconfig_ipv6)
11302 __connman_ipconfig_set_index(service->ipconfig_ipv6,
11305 __connman_connection_update_gateway();
11309 service->type = convert_network_type(network);
11311 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
11312 service->autoconnect = false;
11313 for (i = 0; auto_connect_types &&
11314 auto_connect_types[i] != 0; i++) {
11315 if (service->type == auto_connect_types[i]) {
11316 service->autoconnect = true;
11321 favorite_types = connman_setting_get_uint_list("DefaultFavoriteTechnologies");
11322 service->favorite = false;
11323 for (i = 0; favorite_types && favorite_types[i] != 0; i++) {
11324 if (service->type == favorite_types[i]) {
11325 service->favorite = true;
11330 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
11331 service->state = combine_state(service->state_ipv4, service->state_ipv6);
11333 update_from_network(service, network);
11335 if (!service->ipconfig_ipv4)
11336 service->ipconfig_ipv4 = create_ip4config(service, index,
11337 CONNMAN_IPCONFIG_METHOD_DHCP);
11339 __connman_ipconfig_set_index(service->ipconfig_ipv4, index);
11341 if (!service->ipconfig_ipv6)
11342 service->ipconfig_ipv6 = create_ip6config(service, index);
11344 __connman_ipconfig_set_index(service->ipconfig_ipv6, index);
11346 service_register(service);
11347 service_schedule_added(service);
11349 trigger_autoconnect(service);
11351 __connman_notifier_service_add(service, service->name);
11356 #if defined TIZEN_EXT
11357 void __connman_service_notify_strength_changed(struct connman_network *network)
11359 struct connman_service *service;
11360 uint8_t strength = 0;
11362 service = connman_service_lookup_from_network(network);
11366 if (!service->network)
11369 strength = connman_network_get_strength(service->network);
11370 if (strength == service->strength)
11373 service->strength = strength;
11374 if (!simplified_log)
11375 DBG("Strength %d", strength);
11376 strength_changed(service);
11377 service_list_sort();
11381 void __connman_service_update_from_network(struct connman_network *network)
11383 bool need_sort = false;
11384 struct connman_service *service;
11390 service = connman_service_lookup_from_network(network);
11394 if (!service->network)
11397 #if defined TIZEN_EXT
11398 if (service->storage_reload) {
11399 service_load(service);
11400 __connman_service_set_storage_reload(service, false);
11404 name = connman_network_get_string(service->network, "Name");
11405 if (g_strcmp0(service->name, name) != 0) {
11406 g_free(service->name);
11407 service->name = g_strdup(name);
11409 if (allow_property_changed(service))
11410 connman_dbus_property_changed_basic(service->path,
11411 CONNMAN_SERVICE_INTERFACE, "Name",
11412 DBUS_TYPE_STRING, &service->name);
11415 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
11416 update_wps_values(service, network);
11418 strength = connman_network_get_strength(service->network);
11419 if (strength == service->strength)
11422 service->strength = strength;
11425 strength_changed(service);
11428 roaming = connman_network_get_bool(service->network, "Roaming");
11429 if (roaming == service->roaming)
11432 stats_enable = stats_enabled(service);
11434 stats_stop(service);
11436 service->roaming = roaming;
11440 stats_start(service);
11442 roaming_changed(service);
11445 #if defined TIZEN_EXT
11446 if (TIZEN_INS_ENABLED) {
11447 bool need_save = false;
11449 need_save |= update_last_connected_bssid(service);
11450 need_save |= update_assoc_reject(service);
11453 g_get_current_time((GTimeVal *)&service->modified);
11454 service_ext_save(service);
11461 service_list_sort();
11465 void __connman_service_remove_from_network(struct connman_network *network)
11467 struct connman_service *service;
11469 service = connman_service_lookup_from_network(network);
11471 DBG("network %p service %p", network, service);
11476 service->ignore = true;
11478 __connman_connection_gateway_remove(service,
11479 CONNMAN_IPCONFIG_TYPE_ALL);
11481 connman_service_unref(service);
11485 * __connman_service_create_from_provider:
11486 * @provider: provider structure
11488 * Look up service by provider and if not found, create one
11490 struct connman_service *
11491 __connman_service_create_from_provider(struct connman_provider *provider)
11493 struct connman_service *service;
11494 const char *ident, *str;
11496 int index = connman_provider_get_index(provider);
11498 DBG("provider %p", provider);
11500 ident = __connman_provider_get_ident(provider);
11504 name = g_strdup_printf("vpn_%s", ident);
11505 service = service_get(name);
11511 service->type = CONNMAN_SERVICE_TYPE_VPN;
11512 service->order = service->do_split_routing ? 0 : 10;
11513 service->provider = connman_provider_ref(provider);
11514 service->autoconnect = false;
11515 service->favorite = true;
11517 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
11518 service->state = combine_state(service->state_ipv4, service->state_ipv6);
11520 str = connman_provider_get_string(provider, "Name");
11522 g_free(service->name);
11523 service->name = g_strdup(str);
11524 service->hidden = false;
11526 g_free(service->name);
11527 service->name = NULL;
11528 service->hidden = true;
11531 service->strength = 0;
11533 if (!service->ipconfig_ipv4)
11534 service->ipconfig_ipv4 = create_ip4config(service, index,
11535 CONNMAN_IPCONFIG_METHOD_MANUAL);
11537 if (!service->ipconfig_ipv6)
11538 service->ipconfig_ipv6 = create_ip6config(service, index);
11540 service_register(service);
11542 __connman_notifier_service_add(service, service->name);
11543 service_schedule_added(service);
11548 static void remove_unprovisioned_services(void)
11551 GKeyFile *keyfile, *configkeyfile;
11552 char *file, *section;
11555 services = connman_storage_get_services();
11559 for (; services[i]; i++) {
11560 file = section = NULL;
11561 keyfile = configkeyfile = NULL;
11563 keyfile = connman_storage_load_service(services[i]);
11567 file = g_key_file_get_string(keyfile, services[i],
11568 "Config.file", NULL);
11572 section = g_key_file_get_string(keyfile, services[i],
11573 "Config.ident", NULL);
11577 configkeyfile = __connman_storage_load_config(file);
11578 if (!configkeyfile) {
11580 * Config file is missing, remove the provisioned
11583 __connman_storage_remove_service(services[i]);
11587 if (!g_key_file_has_group(configkeyfile, section))
11589 * Config section is missing, remove the provisioned
11592 __connman_storage_remove_service(services[i]);
11596 g_key_file_free(keyfile);
11599 g_key_file_free(configkeyfile);
11605 g_strfreev(services);
11608 static int agent_probe(struct connman_agent *agent)
11610 DBG("agent %p", agent);
11614 static void agent_remove(struct connman_agent *agent)
11616 DBG("agent %p", agent);
11619 static void *agent_context_ref(void *context)
11621 struct connman_service *service = context;
11623 return (void *)connman_service_ref(service);
11626 static void agent_context_unref(void *context)
11628 struct connman_service *service = context;
11630 connman_service_unref(service);
11633 static struct connman_agent_driver agent_driver = {
11635 .interface = CONNMAN_AGENT_INTERFACE,
11636 .probe = agent_probe,
11637 .remove = agent_remove,
11638 .context_ref = agent_context_ref,
11639 .context_unref = agent_context_unref,
11642 #if defined TIZEN_EXT
11643 static void ins_setting_init(void)
11646 const char *string;
11647 char **string_list;
11648 unsigned int string_count;
11650 ins_settings.last_user_selection = connman_setting_get_bool("INSLastUserSelection");
11651 ins_settings.last_user_selection_time = connman_setting_get_uint("INSLastUserSelectionTime");
11652 ins_settings.last_connected = connman_setting_get_bool("INSLastConnected");
11654 string = connman_setting_get_string("INSPreferredFreq");
11655 if (g_strcmp0(string, "5GHz") == 0)
11656 ins_settings.preferred_freq = CONNMAN_INS_PREFERRED_FREQ_5GHZ;
11657 else if (g_strcmp0(string, "2.4GHz") == 0)
11658 ins_settings.preferred_freq = CONNMAN_INS_PREFERRED_FREQ_24GHZ;
11660 ins_settings.preferred_freq = CONNMAN_INS_PREFERRED_FREQ_UNKNOWN;
11662 ins_settings.security_priority_count = connman_setting_get_uint("INSSecurityPriorityCount");
11663 ins_settings.security_priority_score = connman_setting_get_uint("INSSecurityPriorityScore");
11664 string_count = ins_settings.security_priority_count;
11666 memset(ins_settings.security_priority, 0, sizeof(ins_settings.security_priority));
11667 string_list = connman_setting_get_string_list("INSSecurityPriority");
11668 for (i = 0; string_list && string_list[i]; i++) {
11669 unsigned int security_score = string_count * ins_settings.security_priority_score;
11671 if (g_strcmp0(string_list[i], "WEP") == 0)
11672 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_WEP] = security_score;
11673 else if (g_strcmp0(string_list[i], "PSK") == 0)
11674 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_PSK] = security_score;
11675 else if (g_strcmp0(string_list[i], "8021X") == 0)
11676 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_8021X] = security_score;
11677 else if (g_strcmp0(string_list[i], "WPA") == 0)
11678 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_WPA] = security_score;
11679 else if (g_strcmp0(string_list[i], "RSN") == 0)
11680 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_RSN] = security_score;
11681 else if (g_strcmp0(string_list[i], "SAE") == 0)
11682 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_SAE] = security_score;
11683 else if (g_strcmp0(string_list[i], "OWE") == 0)
11684 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_OWE] = security_score;
11685 else if (g_strcmp0(string_list[i], "DPP") == 0)
11686 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_DPP] = security_score;
11691 ins_settings.signal = connman_setting_get_bool("INSSignal");
11692 ins_settings.internet = connman_setting_get_bool("INSInternet");
11694 ins_settings.last_user_selection_score = connman_setting_get_uint("INSLastUserSelectionScore");
11695 ins_settings.last_connected_score = connman_setting_get_uint("INSLastConnectedScore");
11696 ins_settings.preferred_freq_score = connman_setting_get_uint("INSPreferredFreqScore");
11697 ins_settings.internet_score = connman_setting_get_uint("INSInternetScore");
11700 * In ConnMan, signal strength is used after being converted
11701 * to positive value(signal strength + 120).
11702 * So the value for comparison should also be converted to the same.
11704 ins_settings.signal_level3_5ghz = connman_setting_get_int("INSSignalLevel3_5GHz") + 120;
11705 ins_settings.signal_level3_24ghz = connman_setting_get_int("INSSignalLevel3_2_4GHz") + 120;
11707 DBG("last_user_selection [%s]", ins_settings.last_user_selection ? "true" : "false");
11708 DBG("last_user_selection_time [%d]", ins_settings.last_user_selection_time);
11709 DBG("last_user_selection_score [%d]", ins_settings.last_user_selection_score);
11711 DBG("last_connected [%s]", ins_settings.last_connected ? "true" : "false");
11712 DBG("last_connected_score [%d]", ins_settings.last_connected_score);
11714 DBG("preferred_freq [%s]", ins_settings.preferred_freq ? "true" : "false");
11715 DBG("preferred_freq_score [%d]", ins_settings.preferred_freq_score);
11717 DBG("security_priority_count [%d]", ins_settings.security_priority_count);
11718 for (i = 0; i < CONNMAN_SERVICE_SECURITY_MAX; i++) {
11719 if (ins_settings.security_priority[i])
11720 DBG("security_priority %s [%d]", security2string(i),
11721 ins_settings.security_priority[i]);
11723 DBG("security_priority_score [%d]", ins_settings.security_priority_score);
11725 DBG("signal [%s]", ins_settings.signal ? "true" : "false");
11727 DBG("internet [%s]", ins_settings.internet ? "true" : "false");
11728 DBG("internet_score [%d]", ins_settings.internet_score);
11730 DBG("signal_level3_5ghz [%d]", ins_settings.signal_level3_5ghz);
11731 DBG("signal_level3_24ghz [%d]", ins_settings.signal_level3_24ghz);
11733 #endif /* defined TIZEN_EXT */
11735 int __connman_service_init(void)
11741 err = connman_agent_driver_register(&agent_driver);
11743 connman_error("Cannot register agent driver for %s",
11744 agent_driver.name);
11748 set_always_connecting_technologies();
11750 connection = connman_dbus_get_connection();
11752 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
11753 NULL, service_free);
11755 passphrase_requested = g_hash_table_new(g_direct_hash, g_direct_equal);
11757 services_notify = g_new0(struct _services_notify, 1);
11758 services_notify->remove = g_hash_table_new_full(g_str_hash,
11759 g_str_equal, g_free, NULL);
11760 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
11762 remove_unprovisioned_services();
11764 #if defined TIZEN_EXT
11765 if (TIZEN_INS_ENABLED)
11766 ins_setting_init();
11767 #endif /* defined TIZEN_EXT */
11772 void __connman_service_cleanup(void)
11776 if (vpn_autoconnect_id) {
11777 g_source_remove(vpn_autoconnect_id);
11778 vpn_autoconnect_id = 0;
11781 if (autoconnect_id != 0) {
11782 g_source_remove(autoconnect_id);
11783 autoconnect_id = 0;
11786 connman_agent_driver_unregister(&agent_driver);
11788 g_list_free(service_list);
11789 service_list = NULL;
11791 g_hash_table_destroy(service_hash);
11792 service_hash = NULL;
11794 g_hash_table_destroy(passphrase_requested);
11795 passphrase_requested = NULL;
11797 g_slist_free(counter_list);
11798 counter_list = NULL;
11800 if (services_notify->id != 0) {
11801 g_source_remove(services_notify->id);
11802 service_send_changed(NULL);
11805 g_hash_table_destroy(services_notify->remove);
11806 g_hash_table_destroy(services_notify->add);
11807 g_free(services_notify);
11809 dbus_connection_unref(connection);