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
34 #include <connman/storage.h>
35 #include <connman/setting.h>
36 #include <connman/agent.h>
38 #include "src/shared/util.h"
42 #define CONNECT_TIMEOUT 120
45 #define WIFI_BSSID_STR_LEN 18
46 #define MAX_WIFI_PROFILES 200
48 #define FREQ_RANGE_24GHZ_CHANNEL_1 2412
49 #define FREQ_RANGE_24GHZ_CHANNEL_14 2484
50 #define FREQ_RANGE_5GHZ_CHANNEL_32 5160
51 #define FREQ_RANGE_5GHZ_CHANNEL_165 5825
53 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
54 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
56 #define VPN_AUTOCONNECT_TIMEOUT_DEFAULT 1
57 #define VPN_AUTOCONNECT_TIMEOUT_STEP 30
58 #define VPN_AUTOCONNECT_TIMEOUT_ATTEMPTS_THRESHOLD 270
60 static DBusConnection *connection = NULL;
62 static GList *service_list = NULL;
63 static GHashTable *service_hash = NULL;
64 static GSList *counter_list = NULL;
65 static unsigned int autoconnect_id = 0;
66 static unsigned int vpn_autoconnect_id = 0;
67 static struct connman_service *current_default = NULL;
68 static bool services_dirty = false;
71 static bool auto_connect_mode = TRUE;
73 struct saved_profiles {
78 enum connman_ins_preferred_freq {
79 CONNMAN_INS_PREFERRED_FREQ_UNKNOWN,
80 CONNMAN_INS_PREFERRED_FREQ_24GHZ,
81 CONNMAN_INS_PREFERRED_FREQ_5GHZ,
84 struct connman_ins_settings {
85 bool last_user_selection;
86 unsigned int last_user_selection_time;
87 unsigned int last_user_selection_score;
89 unsigned int last_connected_score;
90 enum connman_ins_preferred_freq preferred_freq;
91 unsigned int preferred_freq_score;
92 unsigned int security_priority[CONNMAN_SERVICE_SECURITY_MAX];
93 unsigned int security_priority_count;
94 unsigned int security_priority_score;
97 unsigned int internet_score;
98 int signal_level3_5ghz;
99 int signal_level3_24ghz;
102 static struct connman_ins_settings ins_settings;
104 static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
109 struct connman_stats {
112 struct connman_stats_data data_last;
113 struct connman_stats_data data;
117 struct connman_stats_counter {
119 struct connman_stats stats;
120 struct connman_stats stats_roaming;
123 struct connman_service {
127 enum connman_service_type type;
128 enum connman_service_security security;
129 enum connman_service_state state;
130 enum connman_service_state state_ipv4;
131 enum connman_service_state state_ipv6;
132 enum connman_service_error error;
133 enum connman_service_connect_reason connect_reason;
140 struct timeval modified;
145 struct connman_ipconfig *ipconfig_ipv4;
146 struct connman_ipconfig *ipconfig_ipv6;
147 struct connman_network *network;
148 struct connman_provider *provider;
150 char **nameservers_config;
151 char **nameservers_auto;
152 int nameservers_timeout;
159 char **timeservers_config;
160 /* 802.1x settings from the config files */
163 char *anonymous_identity;
164 char *agent_identity;
167 char *altsubject_match;
168 char *domain_suffix_match;
170 char *client_cert_file;
171 char *private_key_file;
172 char *private_key_passphrase;
174 DBusMessage *pending;
175 DBusMessage *provider_pending;
177 struct connman_stats stats;
178 struct connman_stats stats_roaming;
179 GHashTable *counter_table;
180 enum connman_service_proxy_method proxy;
181 enum connman_service_proxy_method proxy_config;
186 bool wps_advertizing;
187 guint online_timeout;
188 int online_check_interval_ipv4;
189 int online_check_interval_ipv6;
190 bool do_split_routing;
195 #if defined TIZEN_EXT
197 * Description: TIZEN implements system global connection management.
198 * It's only for PDP (cellular) bearer. Wi-Fi is managed
199 * by ConnMan automatically. Reference count can help to
200 * manage open/close connection requests by each application.
202 int user_pdn_connection_refcount;
205 * Description: In case of EAP security type,
206 * user can select the keymgmt type for roaming(802.11r).
207 * - FT, CCKM, OKC, ...
210 int disconnect_reason;
211 int assoc_status_code;
213 * Only for EAP-FAST and EAP-PEAP in EAPoL.
216 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
223 * Description: To indicate that disconnection triggered by user.
225 bool disconnection_requested;
227 enum connman_dnsconfig_method dns_config_method_ipv4;
228 enum connman_dnsconfig_method dns_config_method_ipv6;
230 #if defined TIZEN_EXT
233 char *net_access_key;
234 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
235 bool is_internet_connection;
236 int assoc_reject_count;
237 #if defined TIZEN_EXT_INS
238 int score_last_user_selection;
239 int score_last_connected;
241 int score_security_priority;
242 int score_internet_connection;
247 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
249 * To indicate use of EAP over Ethernet.
252 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
255 static bool allow_property_changed(struct connman_service *service);
257 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
258 int index, enum connman_ipconfig_method method);
259 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
261 static void dns_changed(struct connman_service *service);
262 static void vpn_auto_connect(void);
266 struct connman_service *service;
269 #if defined TIZEN_EXT
270 struct assoc_reject_data {
272 GSList *reject_time_list;
276 * Public APIs to use user_pdn_connection_refcount
278 void connman_service_user_pdn_connection_ref(struct connman_service *service)
280 __sync_fetch_and_add(&service->user_pdn_connection_refcount, 1);
282 DBG("User made PDN connection referenced: %d",
283 service->user_pdn_connection_refcount);
286 gboolean connman_service_user_pdn_connection_unref_and_test(
287 struct connman_service *service)
289 __sync_synchronize();
291 DBG("User made PDN connection referenced: %d, which will be decreased",
292 service->user_pdn_connection_refcount);
294 if (service->user_pdn_connection_refcount < 1)
297 if (__sync_sub_and_fetch(&service->user_pdn_connection_refcount, 1) == 0)
303 gboolean connman_service_is_no_ref_user_pdn_connection(
304 struct connman_service *cellular)
306 if (cellular == NULL)
309 __sync_synchronize();
310 if (cellular->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
311 cellular->user_pdn_connection_refcount == 0)
318 static void compare_path(gpointer value, gpointer user_data)
320 struct connman_service *service = value;
321 struct find_data *data = user_data;
326 if (g_strcmp0(service->path, data->path) == 0)
327 data->service = service;
330 static struct connman_service *find_service(const char *path)
332 struct find_data data = { .path = path, .service = NULL };
334 DBG("path %s", path);
336 g_list_foreach(service_list, compare_path, &data);
341 static const char *reason2string(enum connman_service_connect_reason reason)
345 case CONNMAN_SERVICE_CONNECT_REASON_NONE:
347 case CONNMAN_SERVICE_CONNECT_REASON_USER:
349 case CONNMAN_SERVICE_CONNECT_REASON_AUTO:
351 case CONNMAN_SERVICE_CONNECT_REASON_SESSION:
358 const char *__connman_service_type2string(enum connman_service_type type)
361 case CONNMAN_SERVICE_TYPE_UNKNOWN:
363 case CONNMAN_SERVICE_TYPE_SYSTEM:
365 case CONNMAN_SERVICE_TYPE_ETHERNET:
367 case CONNMAN_SERVICE_TYPE_WIFI:
369 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
371 case CONNMAN_SERVICE_TYPE_CELLULAR:
373 case CONNMAN_SERVICE_TYPE_GPS:
375 case CONNMAN_SERVICE_TYPE_VPN:
377 case CONNMAN_SERVICE_TYPE_GADGET:
379 case CONNMAN_SERVICE_TYPE_P2P:
381 #if defined TIZEN_EXT_WIFI_MESH
382 case CONNMAN_SERVICE_TYPE_MESH:
390 enum connman_service_type __connman_service_string2type(const char *str)
393 return CONNMAN_SERVICE_TYPE_UNKNOWN;
395 if (strcmp(str, "ethernet") == 0)
396 return CONNMAN_SERVICE_TYPE_ETHERNET;
397 if (strcmp(str, "gadget") == 0)
398 return CONNMAN_SERVICE_TYPE_GADGET;
399 if (strcmp(str, "wifi") == 0)
400 return CONNMAN_SERVICE_TYPE_WIFI;
401 if (strcmp(str, "cellular") == 0)
402 return CONNMAN_SERVICE_TYPE_CELLULAR;
403 if (strcmp(str, "bluetooth") == 0)
404 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
405 if (strcmp(str, "vpn") == 0)
406 return CONNMAN_SERVICE_TYPE_VPN;
407 if (strcmp(str, "gps") == 0)
408 return CONNMAN_SERVICE_TYPE_GPS;
409 if (strcmp(str, "system") == 0)
410 return CONNMAN_SERVICE_TYPE_SYSTEM;
411 if (strcmp(str, "p2p") == 0)
412 return CONNMAN_SERVICE_TYPE_P2P;
414 return CONNMAN_SERVICE_TYPE_UNKNOWN;
417 enum connman_service_security __connman_service_string2security(const char *str)
420 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
422 if (!strcmp(str, "psk"))
423 return CONNMAN_SERVICE_SECURITY_PSK;
424 if (!strcmp(str, "ieee8021x") || !strcmp(str, "8021x"))
425 return CONNMAN_SERVICE_SECURITY_8021X;
426 if (!strcmp(str, "none") || !strcmp(str, "open"))
427 return CONNMAN_SERVICE_SECURITY_NONE;
428 if (!strcmp(str, "wep"))
429 return CONNMAN_SERVICE_SECURITY_WEP;
430 #if defined TIZEN_EXT
431 if (!strcmp(str, "rsn"))
432 return CONNMAN_SERVICE_SECURITY_RSN;
433 if (!strcmp(str, "sae"))
434 return CONNMAN_SERVICE_SECURITY_SAE;
435 if (!strcmp(str, "owe"))
436 return CONNMAN_SERVICE_SECURITY_OWE;
437 if (!strcmp(str, "dpp"))
438 return CONNMAN_SERVICE_SECURITY_DPP;
441 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
444 static const char *security2string(enum connman_service_security security)
447 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
449 case CONNMAN_SERVICE_SECURITY_NONE:
451 case CONNMAN_SERVICE_SECURITY_WEP:
453 case CONNMAN_SERVICE_SECURITY_PSK:
454 case CONNMAN_SERVICE_SECURITY_WPA:
455 #if defined TIZEN_EXT
457 case CONNMAN_SERVICE_SECURITY_RSN:
459 case CONNMAN_SERVICE_SECURITY_SAE:
461 case CONNMAN_SERVICE_SECURITY_OWE:
463 case CONNMAN_SERVICE_SECURITY_DPP:
466 case CONNMAN_SERVICE_SECURITY_RSN:
469 case CONNMAN_SERVICE_SECURITY_8021X:
476 static const char *state2string(enum connman_service_state state)
479 case CONNMAN_SERVICE_STATE_UNKNOWN:
481 case CONNMAN_SERVICE_STATE_IDLE:
483 case CONNMAN_SERVICE_STATE_ASSOCIATION:
484 return "association";
485 case CONNMAN_SERVICE_STATE_CONFIGURATION:
486 return "configuration";
487 case CONNMAN_SERVICE_STATE_READY:
489 case CONNMAN_SERVICE_STATE_ONLINE:
491 case CONNMAN_SERVICE_STATE_DISCONNECT:
493 case CONNMAN_SERVICE_STATE_FAILURE:
500 static const char *error2string(enum connman_service_error error)
503 case CONNMAN_SERVICE_ERROR_UNKNOWN:
505 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
506 return "out-of-range";
507 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
508 return "pin-missing";
509 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
510 return "dhcp-failed";
511 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
512 return "connect-failed";
513 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
514 return "login-failed";
515 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
516 return "auth-failed";
517 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
518 return "invalid-key";
519 case CONNMAN_SERVICE_ERROR_BLOCKED:
526 static const char *proxymethod2string(enum connman_service_proxy_method method)
529 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
531 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
533 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
535 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
542 static enum connman_service_proxy_method string2proxymethod(const char *method)
544 if (g_strcmp0(method, "direct") == 0)
545 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
546 else if (g_strcmp0(method, "auto") == 0)
547 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
548 else if (g_strcmp0(method, "manual") == 0)
549 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
551 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
555 static const char *__connman_dnsconfig_method2string(enum connman_dnsconfig_method method)
558 case CONNMAN_DNSCONFIG_METHOD_UNKNOWN:
560 case CONNMAN_DNSCONFIG_METHOD_MANUAL:
562 case CONNMAN_DNSCONFIG_METHOD_DHCP:
569 static enum connman_dnsconfig_method __connman_dnsconfig_string2method(
572 if (g_strcmp0(method, "manual") == 0)
573 return CONNMAN_DNSCONFIG_METHOD_MANUAL;
574 else if (g_strcmp0(method, "dhcp") == 0)
575 return CONNMAN_DNSCONFIG_METHOD_DHCP;
577 return CONNMAN_DNSCONFIG_METHOD_UNKNOWN;
581 static void set_split_routing(struct connman_service *service, bool value)
583 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
586 service->do_split_routing = value;
588 if (service->do_split_routing)
594 int __connman_service_load_modifiable(struct connman_service *service)
597 GError *error = NULL;
601 DBG("service %p", service);
603 keyfile = connman_storage_load_service(service->identifier);
607 switch (service->type) {
608 case CONNMAN_SERVICE_TYPE_UNKNOWN:
609 case CONNMAN_SERVICE_TYPE_SYSTEM:
610 case CONNMAN_SERVICE_TYPE_GPS:
611 case CONNMAN_SERVICE_TYPE_P2P:
612 #if defined TIZEN_EXT_WIFI_MESH
613 case CONNMAN_SERVICE_TYPE_MESH:
616 case CONNMAN_SERVICE_TYPE_VPN:
617 set_split_routing(service, g_key_file_get_boolean(keyfile,
619 "SplitRouting", NULL));
622 case CONNMAN_SERVICE_TYPE_WIFI:
623 case CONNMAN_SERVICE_TYPE_GADGET:
624 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
625 case CONNMAN_SERVICE_TYPE_CELLULAR:
626 case CONNMAN_SERVICE_TYPE_ETHERNET:
627 autoconnect = g_key_file_get_boolean(keyfile,
628 service->identifier, "AutoConnect", &error);
630 service->autoconnect = autoconnect;
631 g_clear_error(&error);
635 str = g_key_file_get_string(keyfile,
636 service->identifier, "Modified", NULL);
638 util_iso8601_to_timeval(str, &service->modified);
642 g_key_file_free(keyfile);
647 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
648 static void __connman_service_cleanup_8021x(struct connman_service *service)
653 DBG("service %p ", service);
655 __connman_service_set_string(service, "EAP", NULL);
656 __connman_service_set_string(service, "Identity", NULL);
657 __connman_service_set_string(service, "Passphrase", NULL);
658 __connman_service_set_string(service, "AnonymousIdentity", NULL);
659 __connman_service_set_string(service, "CACertFile", NULL);
660 __connman_service_set_string(service, "ClientCertFile", NULL);
661 __connman_service_set_string(service, "PrivateKeyFile", NULL);
662 __connman_service_set_string(service, "PrivateKeyPassphrase", NULL);
663 __connman_service_set_string(service, "Phase1", NULL);
664 __connman_service_set_string(service, "Phase2", NULL);
665 __connman_service_set_string(service, "PacFile", NULL);
668 static int connman_service_set_eapol_property(struct connman_service *service,
669 DBusMessageIter *array)
671 DBusMessageIter dict;
674 __connman_service_cleanup_8021x(service);
676 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
679 dbus_message_iter_recurse(array, &dict);
681 while(dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
682 DBusMessageIter entry, value;
686 dbus_message_iter_recurse(&dict, &entry);
688 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
691 dbus_message_iter_get_basic(&entry, &key);
692 dbus_message_iter_next(&entry);
694 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
697 dbus_message_iter_recurse(&entry, &value);
699 type = dbus_message_iter_get_arg_type(&value);
701 if (g_str_equal(key, "UseEapol")) {
702 dbus_bool_t use_eapol;
704 if (type != DBUS_TYPE_BOOLEAN)
707 dbus_message_iter_get_basic(&value, &use_eapol);
708 service->use_eapol = use_eapol;
710 } else if (g_str_equal(key, "EAP")) {
711 if (type != DBUS_TYPE_STRING)
714 dbus_message_iter_get_basic(&value, &str);
715 __connman_service_set_string(service, "EAP", str);
717 } else if (g_str_equal(key, "Identity")) {
718 if (type != DBUS_TYPE_STRING)
721 dbus_message_iter_get_basic(&value, &str);
722 __connman_service_set_string(service, "Identity", str);
724 } else if (g_str_equal(key, "AnonymousIdentity")) {
725 if (type != DBUS_TYPE_STRING)
728 dbus_message_iter_get_basic(&value, &str);
729 __connman_service_set_string(service, "AnonymousIdentity", str);
731 } else if (g_str_equal(key, "CACertFile")) {
732 if (type != DBUS_TYPE_STRING)
735 dbus_message_iter_get_basic(&value, &str);
736 __connman_service_set_string(service, "CACertFile", str);
737 } else if (g_str_equal(key, "ClientCertFile")) {
738 if (type != DBUS_TYPE_STRING)
741 dbus_message_iter_get_basic(&value, &str);
742 __connman_service_set_string(service, "ClientCertFile", str);
743 } else if (g_str_equal(key, "PrivateKeyFile")) {
744 if (type != DBUS_TYPE_STRING)
747 dbus_message_iter_get_basic(&value, &str);
748 __connman_service_set_string(service, "PrivateKeyFile", str);
749 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
750 if (type != DBUS_TYPE_STRING)
753 dbus_message_iter_get_basic(&value, &str);
754 __connman_service_set_string(service, "PrivateKeyPassphrase", str);
755 } else if (g_str_equal(key, "Phase2")) {
756 if (type != DBUS_TYPE_STRING)
759 dbus_message_iter_get_basic(&value, &str);
760 __connman_service_set_string(service, "Phase2", str);
761 } else if (g_str_equal(key, "Phase1")) {
763 char phase1[5] = {0,};
765 if (type != DBUS_TYPE_INT32)
768 dbus_message_iter_get_basic(&value, &val);
769 sprintf(phase1, "%d", val);
770 __connman_service_set_string(service, "Phase1", phase1);
771 } else if (g_str_equal(key, "PacFile")) {
772 if (type != DBUS_TYPE_STRING)
775 dbus_message_iter_get_basic(&value, &str);
776 __connman_service_set_string(service, "PacFile", str);
779 dbus_message_iter_next(&dict);
786 #if defined TIZEN_EXT
787 static void save_assoc_reject(gpointer key, gpointer value, gpointer user_data)
789 struct assoc_reject_data *assoc_rd = value;
790 GString *assoc_reject_str = user_data;
794 if (g_slist_length(assoc_rd->reject_time_list) < 1)
797 for (list = assoc_rd->reject_time_list; list; list = list->next) {
798 time_t assoc_reject_time = GPOINTER_TO_INT(list->data);
800 val_str = g_strdup_printf("%s_%ld", assoc_rd->bssid, assoc_reject_time);
802 if (assoc_reject_str->len > 0)
803 g_string_append_printf(assoc_reject_str, " %s", val_str);
805 g_string_append(assoc_reject_str, val_str);
811 static void count_assoc_reject(gpointer key, gpointer value, gpointer user_data)
813 struct assoc_reject_data *assoc_data = value;
814 int *assoc_reject_count = user_data;
816 *assoc_reject_count += g_slist_length(assoc_data->reject_time_list);
819 static bool update_assoc_reject(struct connman_service *service)
821 GHashTable *assoc_reject_table;
822 int assoc_reject_count;
824 if (!service->network)
827 assoc_reject_table = connman_network_get_assoc_reject_table(service->network);
828 if (assoc_reject_table) {
829 assoc_reject_count = 0;
830 g_hash_table_foreach(assoc_reject_table, count_assoc_reject, &assoc_reject_count);
831 #if defined TIZEN_EXT_INS
832 DBG("assoc reject count [%d -> %d]",
833 service->assoc_reject_count, assoc_reject_count);
835 if (service->assoc_reject_count != assoc_reject_count) {
836 service->assoc_reject_count = assoc_reject_count;
844 static int service_ext_load(struct connman_service *service)
847 GHashTable *reject_table;
850 struct assoc_reject_data *reject_data;
856 struct tm* ref_timeinfo;
860 #if defined TIZEN_EXT
863 DBG("service %p", service);
865 if (!service->network)
868 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
871 keyfile = connman_storage_load_service(service->identifier);
875 reject_table = connman_network_get_assoc_reject_table(service->network);
877 reject_list = g_key_file_get_string_list(keyfile,
878 service->identifier, "AssocReject", &reject_len, NULL);
880 if (!reject_list || reject_len == 0) {
881 g_strfreev(reject_list);
885 /* Only events that occur within one hour are appened. */
886 curr_time = time(NULL);
887 ref_timeinfo = localtime(&curr_time);
888 ref_timeinfo->tm_hour -= 1;
889 ref_time = mktime(ref_timeinfo);
891 for (i = 0; reject_list[i]; i++) {
892 bssid_time = g_strsplit(reject_list[i], "_", 0);
898 bssid = bssid_time[0];
899 reject_time = strtol(bssid_time[1], NULL, 10);
901 if (reject_time < ref_time) {
902 g_strfreev(bssid_time);
907 reject_data = g_hash_table_lookup(reject_table, bssid);
909 reject_data = g_try_new0(struct assoc_reject_data, 1);
911 g_strfreev(bssid_time);
916 reject_data->bssid = g_strdup(bssid);
917 g_hash_table_insert(reject_table, reject_data->bssid, reject_data);
920 reject_data->reject_time_list = g_slist_append(reject_data->reject_time_list,
921 GINT_TO_POINTER(reject_time));
923 #if defined TIZEN_EXT_INS
924 DBG("assoc reject [%s_%ld]", bssid, reject_time);
927 g_strfreev(bssid_time);
930 g_strfreev(reject_list);
933 g_key_file_free(keyfile);
937 static int service_ext_save(struct connman_service *service)
940 GHashTable *reject_table;
946 DBG("service %p", service);
948 if (!service->network)
951 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
954 keyfile = g_key_file_new();
958 /* Last connected BSSID */
959 if (memcmp(service->last_connected_bssid, invalid_bssid, WIFI_BSSID_LEN_MAX)) {
960 char *identifier = service->identifier;
964 bssid_str = g_string_sized_new(MAC_ADDRESS_LENGTH);
970 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
971 g_string_append_printf(bssid_str,
972 "%02x", service->last_connected_bssid[i]);
973 if (i < WIFI_BSSID_LEN_MAX - 1)
974 g_string_append(bssid_str, ":");
977 g_key_file_set_string(keyfile, identifier,
978 "LastConnectedBSSID", bssid_str->str);
980 #if defined TIZEN_EXT_INS
981 DBG("last connected bssid[%s]", bssid_str->str);
984 g_string_free(bssid_str, TRUE);
990 reject_table = connman_network_get_assoc_reject_table(service->network);
991 if (reject_table && g_hash_table_size(reject_table) > 0) {
992 reject_str = g_string_new(NULL);
998 g_hash_table_foreach(reject_table, save_assoc_reject, reject_str);
1000 reject_list = g_strsplit_set(reject_str->str, " ", 0);
1001 reject_len = g_strv_length(reject_list);
1003 g_key_file_set_string_list(keyfile, service->identifier,
1004 "AssocReject", (const gchar **)reject_list, reject_len);
1006 #if defined TIZEN_EXT_INS
1007 DBG("assoc reject table [%d]", reject_len);
1010 g_strfreev(reject_list);
1011 g_string_free(reject_str, TRUE);
1013 g_key_file_remove_key(keyfile, service->identifier, "AssocReject", NULL);
1017 __connman_storage_save_service(keyfile, service->identifier);
1019 g_key_file_free(keyfile);
1024 static int service_load(struct connman_service *service)
1027 GError *error = NULL;
1031 unsigned int ssid_len;
1033 #if defined TIZEN_EXT
1034 bool internet_connection;
1036 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
1039 #if defined TIZEN_EXT
1040 if (!simplified_log)
1042 DBG("service %p", service);
1044 keyfile = connman_storage_load_service(service->identifier);
1046 service->new_service = true;
1049 service->new_service = false;
1051 switch (service->type) {
1052 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1053 case CONNMAN_SERVICE_TYPE_SYSTEM:
1054 case CONNMAN_SERVICE_TYPE_GPS:
1055 case CONNMAN_SERVICE_TYPE_P2P:
1056 #if defined TIZEN_EXT_WIFI_MESH
1057 case CONNMAN_SERVICE_TYPE_MESH:
1060 case CONNMAN_SERVICE_TYPE_VPN:
1061 set_split_routing(service, g_key_file_get_boolean(keyfile,
1062 service->identifier,
1063 "SplitRouting", NULL));
1065 autoconnect = g_key_file_get_boolean(keyfile,
1066 service->identifier, "AutoConnect", &error);
1068 service->autoconnect = autoconnect;
1069 g_clear_error(&error);
1071 case CONNMAN_SERVICE_TYPE_WIFI:
1072 if (!service->name) {
1075 name = g_key_file_get_string(keyfile,
1076 service->identifier, "Name", NULL);
1078 g_free(service->name);
1079 service->name = name;
1082 if (service->network)
1083 connman_network_set_name(service->network,
1087 if (service->network &&
1088 !connman_network_get_blob(service->network,
1089 "WiFi.SSID", &ssid_len)) {
1092 hex_ssid = g_key_file_get_string(keyfile,
1093 service->identifier,
1098 unsigned int i, j = 0, hex;
1099 size_t hex_ssid_len = strlen(hex_ssid);
1101 ssid = g_try_malloc0(hex_ssid_len / 2);
1108 for (i = 0; i < hex_ssid_len; i += 2) {
1109 sscanf(hex_ssid + i, "%02x", &hex);
1113 connman_network_set_blob(service->network,
1114 "WiFi.SSID", ssid, hex_ssid_len / 2);
1122 #if defined TIZEN_EXT
1123 /* Last connected BSSID */
1124 if (service->network) {
1126 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
1130 bssid_str = g_key_file_get_string(keyfile,
1131 service->identifier, "LastConnectedBSSID", NULL);
1134 str_list = g_strsplit(bssid_str, ":", 0);
1137 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++)
1138 last_connected_bssid[i] = strtol(str_list[i], NULL, 16);
1140 memcpy(service->last_connected_bssid,
1141 last_connected_bssid, WIFI_BSSID_LEN_MAX);
1143 connman_network_set_last_connected_bssid(service->network,
1144 last_connected_bssid);
1146 g_strfreev(str_list);
1153 /* Internet connection */
1154 internet_connection = g_key_file_get_boolean(keyfile,
1155 service->identifier, "InternetConnection", &error);
1157 service->is_internet_connection = internet_connection;
1159 g_clear_error(&error);
1163 case CONNMAN_SERVICE_TYPE_GADGET:
1164 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1165 case CONNMAN_SERVICE_TYPE_CELLULAR:
1166 service->favorite = g_key_file_get_boolean(keyfile,
1167 service->identifier, "Favorite", NULL);
1171 case CONNMAN_SERVICE_TYPE_ETHERNET:
1172 autoconnect = g_key_file_get_boolean(keyfile,
1173 service->identifier, "AutoConnect", &error);
1175 service->autoconnect = autoconnect;
1176 g_clear_error(&error);
1178 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
1179 use_eapol = g_key_file_get_boolean(keyfile,
1180 service->identifier, "UseEapol", &error);
1182 service->use_eapol = use_eapol;
1183 g_clear_error(&error);
1188 str = g_key_file_get_string(keyfile,
1189 service->identifier, "Modified", NULL);
1191 util_iso8601_to_timeval(str, &service->modified);
1195 str = g_key_file_get_string(keyfile,
1196 service->identifier, "Passphrase", NULL);
1198 g_free(service->passphrase);
1199 service->passphrase = str;
1202 if (service->ipconfig_ipv4)
1203 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
1204 service->identifier, "IPv4.");
1206 if (service->ipconfig_ipv6)
1207 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
1208 service->identifier, "IPv6.");
1210 service->nameservers_config = g_key_file_get_string_list(keyfile,
1211 service->identifier, "Nameservers", &length, NULL);
1212 if (service->nameservers_config && length == 0) {
1213 g_strfreev(service->nameservers_config);
1214 service->nameservers_config = NULL;
1220 dns_method = g_key_file_get_string(keyfile, service->identifier,
1221 "Nameservers.IPv4method", NULL);
1223 service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
1227 dns_method = g_key_file_get_string(keyfile, service->identifier,
1228 "Nameservers.IPv6method", NULL);
1230 service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
1235 service->timeservers_config = g_key_file_get_string_list(keyfile,
1236 service->identifier, "Timeservers", &length, NULL);
1237 if (service->timeservers_config && length == 0) {
1238 g_strfreev(service->timeservers_config);
1239 service->timeservers_config = NULL;
1242 service->domains = g_key_file_get_string_list(keyfile,
1243 service->identifier, "Domains", &length, NULL);
1244 if (service->domains && length == 0) {
1245 g_strfreev(service->domains);
1246 service->domains = NULL;
1249 str = g_key_file_get_string(keyfile,
1250 service->identifier, "Proxy.Method", NULL);
1252 service->proxy_config = string2proxymethod(str);
1256 service->proxies = g_key_file_get_string_list(keyfile,
1257 service->identifier, "Proxy.Servers", &length, NULL);
1258 if (service->proxies && length == 0) {
1259 g_strfreev(service->proxies);
1260 service->proxies = NULL;
1263 service->excludes = g_key_file_get_string_list(keyfile,
1264 service->identifier, "Proxy.Excludes", &length, NULL);
1265 if (service->excludes && length == 0) {
1266 g_strfreev(service->excludes);
1267 service->excludes = NULL;
1270 str = g_key_file_get_string(keyfile,
1271 service->identifier, "Proxy.URL", NULL);
1273 g_free(service->pac);
1277 service->mdns_config = g_key_file_get_boolean(keyfile,
1278 service->identifier, "mDNS", NULL);
1280 service->hidden_service = g_key_file_get_boolean(keyfile,
1281 service->identifier, "Hidden", NULL);
1283 #if defined TIZEN_EXT
1284 if ((service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1285 service->security == CONNMAN_SERVICE_SECURITY_8021X)
1286 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1287 || (service->type == CONNMAN_SERVICE_TYPE_ETHERNET && service->use_eapol)
1290 str = g_key_file_get_string(keyfile,
1291 service->identifier, "EAP", NULL);
1293 g_free(service->eap);
1297 str = g_key_file_get_string(keyfile,
1298 service->identifier, "Phase2", NULL);
1300 g_free(service->phase2);
1301 service->phase2 = str;
1304 str = g_key_file_get_string(keyfile,
1305 service->identifier, "Identity", NULL);
1307 g_free(service->identity);
1308 service->identity = str;
1311 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1312 str = g_key_file_get_string(keyfile,
1313 service->identifier, "AnonymousIdentity", NULL);
1315 g_free(service->anonymous_identity);
1316 service->anonymous_identity = str;
1319 str = g_key_file_get_string(keyfile,
1320 service->identifier, "CACertFile", NULL);
1322 g_free(service->ca_cert_file);
1323 service->ca_cert_file = str;
1326 str = g_key_file_get_string(keyfile,
1327 service->identifier, "ClientCertFile", NULL);
1329 g_free(service->client_cert_file);
1330 service->client_cert_file = str;
1333 str = g_key_file_get_string(keyfile,
1334 service->identifier, "PrivateKeyFile", NULL);
1336 g_free(service->private_key_file);
1337 service->private_key_file = str;
1340 str = g_key_file_get_string(keyfile,
1341 service->identifier, "PrivateKeyPassphrase", NULL);
1343 g_free(service->private_key_passphrase);
1344 service->private_key_passphrase = str;
1347 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1348 str = g_key_file_get_string(keyfile,
1349 service->identifier, "Phase1", NULL);
1351 g_free(service->phase1);
1352 service->phase1 = str;
1355 str = g_key_file_get_string(keyfile,
1356 service->identifier, "PacFile", NULL);
1358 g_free(service->pac_file);
1359 service->pac_file = str;
1364 #if defined TIZEN_EXT
1365 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1366 service->security == CONNMAN_SERVICE_SECURITY_DPP) {
1367 str = g_key_file_get_string(keyfile,
1368 service->identifier, "Connector", NULL);
1370 g_free(service->connector);
1371 service->connector = str;
1373 str = g_key_file_get_string(keyfile,
1374 service->identifier, "CSignKey", NULL);
1376 g_free(service->c_sign_key);
1377 service->c_sign_key = str;
1379 str = g_key_file_get_string(keyfile,
1380 service->identifier, "NetAccessKey", NULL);
1382 g_free(service->net_access_key);
1383 service->net_access_key = str;
1389 g_key_file_free(keyfile);
1394 static int service_save(struct connman_service *service)
1399 const char *cst_str = NULL;
1402 DBG("service %p new %d", service, service->new_service);
1404 if (service->new_service)
1407 keyfile = g_key_file_new();
1412 g_key_file_set_string(keyfile, service->identifier,
1413 "Name", service->name);
1415 switch (service->type) {
1416 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1417 case CONNMAN_SERVICE_TYPE_SYSTEM:
1418 case CONNMAN_SERVICE_TYPE_GPS:
1419 case CONNMAN_SERVICE_TYPE_P2P:
1420 #if defined TIZEN_EXT_WIFI_MESH
1421 case CONNMAN_SERVICE_TYPE_MESH:
1424 case CONNMAN_SERVICE_TYPE_VPN:
1425 g_key_file_set_boolean(keyfile, service->identifier,
1426 "SplitRouting", service->do_split_routing);
1427 if (service->favorite)
1428 g_key_file_set_boolean(keyfile, service->identifier,
1429 "AutoConnect", service->autoconnect);
1431 case CONNMAN_SERVICE_TYPE_WIFI:
1432 if (service->network) {
1433 const unsigned char *ssid;
1434 unsigned int ssid_len = 0;
1435 #if defined TIZEN_EXT
1436 GHashTable *assoc_reject_table;
1439 ssid = connman_network_get_blob(service->network,
1440 "WiFi.SSID", &ssid_len);
1442 if (ssid && ssid_len > 0 && ssid[0] != '\0') {
1443 char *identifier = service->identifier;
1447 ssid_str = g_string_sized_new(ssid_len * 2);
1453 for (i = 0; i < ssid_len; i++)
1454 g_string_append_printf(ssid_str,
1457 g_key_file_set_string(keyfile, identifier,
1458 "SSID", ssid_str->str);
1460 g_string_free(ssid_str, TRUE);
1463 freq = connman_network_get_frequency(service->network);
1464 g_key_file_set_integer(keyfile, service->identifier,
1467 #if defined TIZEN_EXT
1468 /* Last connected BSSID */
1469 if (memcmp(service->last_connected_bssid, invalid_bssid, WIFI_BSSID_LEN_MAX)) {
1470 char *identifier = service->identifier;
1474 bssid_str = g_string_sized_new(18);
1480 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
1481 g_string_append_printf(bssid_str,
1482 "%02x", service->last_connected_bssid[i]);
1483 if (i < WIFI_BSSID_LEN_MAX - 1)
1484 g_string_append(bssid_str, ":");
1487 g_key_file_set_string(keyfile, identifier,
1488 "LastConnectedBSSID", bssid_str->str);
1490 #if defined TIZEN_EXT_INS
1491 DBG("last connected bssid[%s]", bssid_str->str);
1494 g_string_free(bssid_str, TRUE);
1498 assoc_reject_table = connman_network_get_assoc_reject_table(service->network);
1499 if (assoc_reject_table && g_hash_table_size(assoc_reject_table) > 0) {
1500 GString *assoc_reject_str;
1501 char **assoc_reject_list;
1502 guint assoc_reject_len;
1504 assoc_reject_str = g_string_new(NULL);
1505 if (!assoc_reject_str) {
1510 g_hash_table_foreach(assoc_reject_table, save_assoc_reject, assoc_reject_str);
1512 assoc_reject_list = g_strsplit_set(assoc_reject_str->str, " ", 0);
1513 assoc_reject_len = g_strv_length(assoc_reject_list);
1515 g_key_file_set_string_list(keyfile, service->identifier,
1516 "AssocReject", (const gchar **)assoc_reject_list, assoc_reject_len);
1518 #if defined TIZEN_EXT_INS
1519 DBG("assoc reject table [%d]", assoc_reject_len);
1522 g_strfreev(assoc_reject_list);
1523 g_string_free(assoc_reject_str, TRUE);
1525 g_key_file_remove_key(keyfile, service->identifier, "AssocReject", NULL);
1527 /* Internet connection */
1528 g_key_file_set_boolean(keyfile, service->identifier,
1529 "InternetConnection", service->is_internet_connection);
1530 #if defined TIZEN_EXT_INS
1531 DBG("internet connection [%s]", service->is_internet_connection ? "true" : "false");
1537 case CONNMAN_SERVICE_TYPE_GADGET:
1538 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1539 case CONNMAN_SERVICE_TYPE_CELLULAR:
1540 g_key_file_set_boolean(keyfile, service->identifier,
1541 "Favorite", service->favorite);
1545 case CONNMAN_SERVICE_TYPE_ETHERNET:
1546 if (service->favorite)
1547 g_key_file_set_boolean(keyfile, service->identifier,
1548 "AutoConnect", service->autoconnect);
1549 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
1550 g_key_file_set_boolean(keyfile, service->identifier,
1551 "UseEapol", service->use_eapol);
1556 str = util_timeval_to_iso8601(&service->modified);
1558 g_key_file_set_string(keyfile, service->identifier,
1563 if (service->passphrase && strlen(service->passphrase) > 0)
1564 g_key_file_set_string(keyfile, service->identifier,
1565 "Passphrase", service->passphrase);
1567 if (service->ipconfig_ipv4)
1568 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
1569 service->identifier, "IPv4.");
1571 if (service->ipconfig_ipv6)
1572 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
1573 service->identifier, "IPv6.");
1575 if (service->nameservers_config) {
1576 guint len = g_strv_length(service->nameservers_config);
1578 g_key_file_set_string_list(keyfile, service->identifier,
1580 (const gchar **) service->nameservers_config, len);
1583 #if defined TIZEN_EXT
1584 if(service->dns_config_method_ipv4 != 0) {
1586 method = __connman_dnsconfig_method2string(
1587 service->dns_config_method_ipv4);
1588 g_key_file_set_string(keyfile, service->identifier,
1589 "Nameservers.IPv4method", method);
1591 g_key_file_remove_key(keyfile, service->identifier,
1592 "Nameservers.IPv4method", NULL);
1594 if(service->dns_config_method_ipv6 != 0) {
1596 method = __connman_dnsconfig_method2string(
1597 service->dns_config_method_ipv6);
1598 g_key_file_set_string(keyfile, service->identifier,
1599 "Nameservers.IPv6method", method);
1601 g_key_file_remove_key(keyfile, service->identifier,
1602 "Nameservers.IPv6method", NULL);
1605 if (service->timeservers_config) {
1606 guint len = g_strv_length(service->timeservers_config);
1608 g_key_file_set_string_list(keyfile, service->identifier,
1610 (const gchar **) service->timeservers_config, len);
1613 if (service->domains) {
1614 guint len = g_strv_length(service->domains);
1616 g_key_file_set_string_list(keyfile, service->identifier,
1618 (const gchar **) service->domains, len);
1621 cst_str = proxymethod2string(service->proxy_config);
1623 g_key_file_set_string(keyfile, service->identifier,
1624 "Proxy.Method", cst_str);
1626 if (service->proxies) {
1627 guint len = g_strv_length(service->proxies);
1629 g_key_file_set_string_list(keyfile, service->identifier,
1631 (const gchar **) service->proxies, len);
1634 if (service->excludes) {
1635 guint len = g_strv_length(service->excludes);
1637 g_key_file_set_string_list(keyfile, service->identifier,
1639 (const gchar **) service->excludes, len);
1642 if (service->pac && strlen(service->pac) > 0)
1643 g_key_file_set_string(keyfile, service->identifier,
1644 "Proxy.URL", service->pac);
1646 if (service->mdns_config)
1647 g_key_file_set_boolean(keyfile, service->identifier,
1650 if (service->hidden_service)
1651 g_key_file_set_boolean(keyfile, service->identifier, "Hidden",
1654 if (service->config_file && strlen(service->config_file) > 0)
1655 g_key_file_set_string(keyfile, service->identifier,
1656 "Config.file", service->config_file);
1658 if (service->config_entry &&
1659 strlen(service->config_entry) > 0)
1660 g_key_file_set_string(keyfile, service->identifier,
1661 "Config.ident", service->config_entry);
1663 #if defined TIZEN_EXT
1664 if ((service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1665 service->security == CONNMAN_SERVICE_SECURITY_8021X)
1666 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1667 || (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
1670 if (service->eap != NULL && strlen(service->eap) > 0)
1671 g_key_file_set_string(keyfile, service->identifier,
1672 "EAP", service->eap);
1674 g_key_file_remove_key(keyfile, service->identifier,
1677 if (service->phase2 != NULL && strlen(service->phase2) > 0)
1678 g_key_file_set_string(keyfile, service->identifier,
1679 "Phase2", service->phase2);
1681 g_key_file_remove_key(keyfile, service->identifier,
1684 if (service->identity != NULL && strlen(service->identity) > 0)
1685 g_key_file_set_string(keyfile, service->identifier,
1686 "Identity", service->identity);
1688 g_key_file_remove_key(keyfile, service->identifier,
1690 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1691 if (service->anonymous_identity != NULL && strlen(service->anonymous_identity) > 0)
1692 g_key_file_set_string(keyfile, service->identifier,
1693 "AnonymousIdentity", service->anonymous_identity);
1695 g_key_file_remove_key(keyfile, service->identifier,
1696 "AnonymousIdentity", NULL);
1699 if (service->ca_cert_file != NULL && strlen(service->ca_cert_file) > 0)
1700 g_key_file_set_string(keyfile, service->identifier,
1701 "CACertFile", service->ca_cert_file);
1703 g_key_file_remove_key(keyfile, service->identifier,
1704 "CACertFile", NULL);
1706 if (service->client_cert_file != NULL && strlen(service->client_cert_file) > 0)
1707 g_key_file_set_string(keyfile, service->identifier,
1708 "ClientCertFile", service->client_cert_file);
1710 g_key_file_remove_key(keyfile, service->identifier,
1711 "ClientCertFile", NULL);
1713 if (service->private_key_file != NULL && strlen(service->private_key_file) > 0)
1714 g_key_file_set_string(keyfile, service->identifier,
1715 "PrivateKeyFile", service->private_key_file);
1717 g_key_file_remove_key(keyfile, service->identifier,
1718 "PrivateKeyFile", NULL);
1720 if (service->private_key_passphrase != NULL && strlen(service->private_key_passphrase) > 0)
1721 g_key_file_set_string(keyfile, service->identifier,
1722 "PrivateKeyPassphrase", service->private_key_passphrase);
1724 g_key_file_remove_key(keyfile, service->identifier,
1725 "PrivateKeyPassphrase", NULL);
1726 #if defined TIZEN_EXT_EAP_ON_ETHERNET
1727 if (service->phase1 != NULL && strlen(service->phase1) > 0)
1728 g_key_file_set_string(keyfile, service->identifier,
1729 "Phase1", service->phase1);
1731 g_key_file_remove_key(keyfile, service->identifier,
1733 if (service->pac_file != NULL && strlen(service->pac_file) > 0)
1734 g_key_file_set_string(keyfile, service->identifier,
1735 "PacFile", service->pac_file);
1737 g_key_file_remove_key(keyfile, service->identifier,
1742 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1743 service->security == CONNMAN_SERVICE_SECURITY_DPP) {
1744 if (service->connector != NULL && strlen(service->connector) > 0)
1745 g_key_file_set_string(keyfile, service->identifier,
1746 "Connector", service->connector);
1748 g_key_file_remove_key(keyfile, service->identifier,
1751 if (service->c_sign_key != NULL && strlen(service->c_sign_key) > 0)
1752 g_key_file_set_string(keyfile, service->identifier,
1753 "CSignKey", service->c_sign_key);
1755 g_key_file_remove_key(keyfile, service->identifier,
1758 if (service->net_access_key != NULL && strlen(service->net_access_key) > 0)
1759 g_key_file_set_string(keyfile, service->identifier,
1760 "NetAccessKey", service->net_access_key);
1762 g_key_file_remove_key(keyfile, service->identifier,
1763 "NetAccessKey", NULL);
1768 __connman_storage_save_service(keyfile, service->identifier);
1770 g_key_file_free(keyfile);
1775 #if defined TIZEN_EXT
1776 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
1778 GTimeVal *aval = (GTimeVal *)a;
1779 GTimeVal *bval = (GTimeVal *)b;
1781 /* Note that the sort order is ascending */
1782 if (aval->tv_sec > bval->tv_sec)
1785 if (aval->tv_sec < bval->tv_sec)
1791 static void free_entry(gpointer data)
1793 struct saved_profiles *entry = data;
1794 g_free(entry->profile_name);
1798 static void __connman_manage_saved_profiles()
1801 gchar **services = NULL;
1803 int i, num_profiles = 0;
1804 GSequenceIter *iter;
1805 GSequence *profile_list;
1806 struct saved_profiles *entry;
1808 profile_list = g_sequence_new(free_entry);
1812 services = connman_storage_get_services();
1814 /* Check the count of saved profiles */
1815 for (i = 0; services && services[i]; i++) {
1816 if (strncmp(services[i], "wifi_", 5) != 0)
1819 keyfile = connman_storage_load_service(services[i]);
1823 gchar *str = g_key_file_get_string(keyfile,
1824 services[i], "Modified", NULL);
1826 g_key_file_free(keyfile);
1830 g_time_val_from_iso8601(str, &modified);
1833 entry = g_try_new(struct saved_profiles, 1);
1835 g_sequence_free(profile_list);
1836 g_key_file_free(keyfile);
1840 entry->modified = modified;
1841 entry->profile_name = g_strdup(services[i]);
1843 g_sequence_insert_sorted(profile_list, entry,
1848 DBG("number of profiles: %d", num_profiles);
1850 if (num_profiles > MAX_WIFI_PROFILES) {
1851 iter = g_sequence_get_begin_iter(profile_list);
1853 entry = g_sequence_get(iter);
1855 if (__connman_storage_remove_service(entry->profile_name) == false)
1856 DBG("Failed to remove service profile: %s", entry->profile_name);
1859 g_sequence_free(profile_list);
1863 void __connman_service_save(struct connman_service *service)
1868 service_save(service);
1869 #if defined TIZEN_EXT
1871 * Description: Manage the wireless profiles saved in connman.
1872 * If the number of saved profiles is more than 200, remove the
1873 * profile that is not updated for longer duration.
1875 __connman_manage_saved_profiles();
1879 static enum connman_service_state combine_state(
1880 enum connman_service_state state_a,
1881 enum connman_service_state state_b)
1883 enum connman_service_state result;
1885 if (state_a == state_b) {
1890 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
1895 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
1900 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
1905 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
1910 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
1915 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
1920 if (state_a == CONNMAN_SERVICE_STATE_READY) {
1925 if (state_b == CONNMAN_SERVICE_STATE_READY) {
1930 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1935 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1940 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1945 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1950 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
1955 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
1960 result = CONNMAN_SERVICE_STATE_FAILURE;
1966 static bool is_connecting(enum connman_service_state state)
1969 case CONNMAN_SERVICE_STATE_UNKNOWN:
1970 case CONNMAN_SERVICE_STATE_IDLE:
1971 case CONNMAN_SERVICE_STATE_FAILURE:
1972 case CONNMAN_SERVICE_STATE_DISCONNECT:
1973 case CONNMAN_SERVICE_STATE_READY:
1974 case CONNMAN_SERVICE_STATE_ONLINE:
1976 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1977 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1984 static bool is_connected(enum connman_service_state state)
1987 case CONNMAN_SERVICE_STATE_UNKNOWN:
1988 case CONNMAN_SERVICE_STATE_IDLE:
1989 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1990 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1991 case CONNMAN_SERVICE_STATE_DISCONNECT:
1992 case CONNMAN_SERVICE_STATE_FAILURE:
1994 case CONNMAN_SERVICE_STATE_READY:
1995 case CONNMAN_SERVICE_STATE_ONLINE:
2002 static bool is_idle(enum connman_service_state state)
2005 case CONNMAN_SERVICE_STATE_IDLE:
2006 case CONNMAN_SERVICE_STATE_DISCONNECT:
2007 case CONNMAN_SERVICE_STATE_FAILURE:
2009 case CONNMAN_SERVICE_STATE_UNKNOWN:
2010 case CONNMAN_SERVICE_STATE_ASSOCIATION:
2011 case CONNMAN_SERVICE_STATE_CONFIGURATION:
2012 case CONNMAN_SERVICE_STATE_READY:
2013 case CONNMAN_SERVICE_STATE_ONLINE:
2020 static int nameservers_changed_cb(void *user_data)
2022 struct connman_service *service = user_data;
2024 DBG("service %p", service);
2026 service->nameservers_timeout = 0;
2027 if ((is_idle(service->state) && !service->nameservers) ||
2028 is_connected(service->state))
2029 dns_changed(service);
2034 static void nameservers_changed(struct connman_service *service)
2036 if (!service->nameservers_timeout)
2037 service->nameservers_timeout = g_idle_add(nameservers_changed_cb,
2041 static bool nameserver_available(struct connman_service *service,
2042 enum connman_ipconfig_type type,
2047 family = connman_inet_check_ipaddress(ns);
2049 if (family == AF_INET) {
2050 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2053 return is_connected(service->state_ipv4);
2056 if (family == AF_INET6) {
2057 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2060 return is_connected(service->state_ipv6);
2066 static int searchdomain_add_all(struct connman_service *service)
2070 if (!is_connected(service->state))
2073 index = __connman_service_get_index(service);
2077 if (service->domains) {
2078 while (service->domains[i]) {
2079 connman_resolver_append(index, service->domains[i],
2087 if (service->domainname)
2088 connman_resolver_append(index, service->domainname, NULL);
2094 static int searchdomain_remove_all(struct connman_service *service)
2098 if (!is_connected(service->state))
2101 index = __connman_service_get_index(service);
2105 while (service->domains && service->domains[i]) {
2106 connman_resolver_remove(index, service->domains[i], NULL);
2110 if (service->domainname)
2111 connman_resolver_remove(index, service->domainname, NULL);
2116 static int nameserver_add(struct connman_service *service,
2117 enum connman_ipconfig_type type,
2118 const char *nameserver)
2122 if (!nameserver_available(service, type, nameserver))
2125 index = __connman_service_get_index(service);
2129 #if defined TIZEN_EXT
2130 DBG("Resolver append nameserver: %s", nameserver);
2132 ret = connman_resolver_append(index, NULL, nameserver);
2134 nameservers_changed(service);
2139 static int nameserver_add_all(struct connman_service *service,
2140 enum connman_ipconfig_type type)
2144 if (service->nameservers_config) {
2145 while (service->nameservers_config[i]) {
2146 #if defined TIZEN_EXT
2147 DBG("type %d add service->nameservers_config[%d]:%s",type,
2148 i, service->nameservers_config[i]);
2149 if(strncmp(service->nameservers_config[i], "::", 2) == 0) {
2150 DBG("Invalid nameserver");
2156 case CONNMAN_IPCONFIG_TYPE_IPV4:
2157 if (connman_inet_check_ipaddress(
2158 service->nameservers_config[i]) == AF_INET &&
2159 service->dns_config_method_ipv4 ==
2160 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2161 nameserver_add(service, type,
2162 service->nameservers_config[i]);
2165 case CONNMAN_IPCONFIG_TYPE_IPV6:
2166 if (connman_inet_check_ipaddress(
2167 service->nameservers_config[i]) == AF_INET6 &&
2168 service->dns_config_method_ipv6 ==
2169 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2170 nameserver_add(service, type,
2171 service->nameservers_config[i]);
2174 case CONNMAN_IPCONFIG_TYPE_ALL:
2175 if (connman_inet_check_ipaddress(
2176 service->nameservers_config[i]) == AF_INET &&
2177 service->dns_config_method_ipv4 ==
2178 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2179 nameserver_add(service, type,
2180 service->nameservers_config[i]);
2182 if (connman_inet_check_ipaddress(
2183 service->nameservers_config[i]) == AF_INET6 &&
2184 service->dns_config_method_ipv6 ==
2185 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2186 nameserver_add(service, type,
2187 service->nameservers_config[i]);
2190 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2191 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
2194 DBG("default case do nothing");
2198 nameserver_add(service, type,
2199 service->nameservers_config[i]);
2203 } else if (service->nameservers) {
2204 while (service->nameservers[i]) {
2205 #if defined TIZEN_EXT
2206 DBG("type %d service->nameservers[%d]: %s",type,
2207 i, service->nameservers[i]);
2210 case CONNMAN_IPCONFIG_TYPE_IPV4:
2211 if (connman_inet_check_ipaddress(
2212 service->nameservers[i]) == AF_INET &&
2213 service->dns_config_method_ipv4 ==
2214 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2215 nameserver_add(service, type,
2216 service->nameservers[i]);
2219 case CONNMAN_IPCONFIG_TYPE_IPV6:
2220 if (connman_inet_check_ipaddress(
2221 service->nameservers[i]) == AF_INET6 &&
2222 service->dns_config_method_ipv6 ==
2223 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2224 nameserver_add(service, type,
2225 service->nameservers[i]);
2228 case CONNMAN_IPCONFIG_TYPE_ALL:
2229 if (connman_inet_check_ipaddress(
2230 service->nameservers[i]) == AF_INET &&
2231 service->dns_config_method_ipv4 ==
2232 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2233 nameserver_add(service, type,
2234 service->nameservers[i]);
2236 if (connman_inet_check_ipaddress(
2237 service->nameservers[i]) == AF_INET6 &&
2238 service->dns_config_method_ipv6 ==
2239 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2240 nameserver_add(service, type,
2241 service->nameservers[i]);
2244 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2245 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
2248 DBG("default case do nothing");
2252 nameserver_add(service, type,
2253 service->nameservers[i]);
2260 __connman_resolver_append_fallback_nameservers();
2262 #if defined TIZEN_EXT
2263 const char *global_dns = connman_option_get_string("GlobalNameserver");
2265 nameserver_add(service, type, global_dns);
2268 searchdomain_add_all(service);
2273 static int nameserver_remove(struct connman_service *service,
2274 enum connman_ipconfig_type type,
2275 const char *nameserver)
2279 if (!nameserver_available(service, type, nameserver))
2282 index = __connman_service_get_index(service);
2286 #if defined TIZEN_EXT
2287 DBG("Resolver remove nameserver: %s", nameserver);
2289 ret = connman_resolver_remove(index, NULL, nameserver);
2291 nameservers_changed(service);
2296 static int nameserver_remove_all(struct connman_service *service,
2297 enum connman_ipconfig_type type)
2299 #if defined TIZEN_EXT
2301 * Skip this function if there is any connected profiles
2302 * that use same interface
2304 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2305 __connman_service_get_connected_count_of_iface(service) > 0)
2310 index = __connman_service_get_index(service);
2314 while (service->nameservers_config && service->nameservers_config[i]) {
2316 #if defined TIZEN_EXT
2317 DBG("type %d Remove service->nameservers_config[%d]: %s",
2318 type, i, service->nameservers_config[i]);
2320 case CONNMAN_IPCONFIG_TYPE_IPV4:
2321 if (connman_inet_check_ipaddress(
2322 service->nameservers_config[i]) == AF_INET &&
2323 (service->dns_config_method_ipv4 ==
2324 CONNMAN_DNSCONFIG_METHOD_DHCP ||
2325 service->dns_config_method_ipv4 ==
2326 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
2327 nameserver_remove(service, type,
2328 service->nameservers_config[i]);
2331 case CONNMAN_IPCONFIG_TYPE_IPV6:
2332 if (connman_inet_check_ipaddress(
2333 service->nameservers_config[i]) == AF_INET6 &&
2334 (service->dns_config_method_ipv6 ==
2335 CONNMAN_DNSCONFIG_METHOD_DHCP ||
2336 service->dns_config_method_ipv6 ==
2337 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
2338 nameserver_remove(service, type,
2339 service->nameservers_config[i]);
2342 case CONNMAN_IPCONFIG_TYPE_ALL:
2343 if (connman_inet_check_ipaddress(
2344 service->nameservers_config[i]) == AF_INET &&
2345 (service->dns_config_method_ipv4 ==
2346 CONNMAN_DNSCONFIG_METHOD_DHCP ||
2347 service->dns_config_method_ipv4 ==
2348 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
2349 nameserver_remove(service, type,
2350 service->nameservers_config[i]);
2352 if (connman_inet_check_ipaddress(
2353 service->nameservers_config[i]) == AF_INET6 &&
2354 (service->dns_config_method_ipv6 ==
2355 CONNMAN_DNSCONFIG_METHOD_DHCP ||
2356 service->dns_config_method_ipv6 ==
2357 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
2358 nameserver_remove(service, type,
2359 service->nameservers_config[i]);
2362 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2363 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
2366 DBG("default case do nothing");
2370 nameserver_remove(service, type,
2371 service->nameservers_config[i]);
2377 while (service->nameservers && service->nameservers[i]) {
2378 #if defined TIZEN_EXT
2379 DBG("type %d Remove service->nameservers[%d]: %s",type, i,
2380 service->nameservers[i]);
2382 case CONNMAN_IPCONFIG_TYPE_IPV4:
2383 if (connman_inet_check_ipaddress(
2384 service->nameservers[i]) == AF_INET &&
2385 (service->dns_config_method_ipv4 ==
2386 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
2387 service->dns_config_method_ipv4 ==
2388 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
2389 nameserver_remove(service, type,
2390 service->nameservers[i]);
2393 case CONNMAN_IPCONFIG_TYPE_IPV6:
2394 if (connman_inet_check_ipaddress(
2395 service->nameservers[i]) == AF_INET6 &&
2396 (service->dns_config_method_ipv6 ==
2397 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
2398 service->dns_config_method_ipv6 ==
2399 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
2400 nameserver_remove(service, type,
2401 service->nameservers[i]);
2404 case CONNMAN_IPCONFIG_TYPE_ALL:
2405 if (connman_inet_check_ipaddress(
2406 service->nameservers[i]) == AF_INET &&
2407 (service->dns_config_method_ipv4 ==
2408 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
2409 service->dns_config_method_ipv4 ==
2410 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
2411 nameserver_remove(service, type,
2412 service->nameservers[i]);
2414 if (connman_inet_check_ipaddress(
2415 service->nameservers[i]) == AF_INET6 &&
2416 (service->dns_config_method_ipv6 ==
2417 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
2418 service->dns_config_method_ipv6 ==
2419 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
2420 nameserver_remove(service, type,
2421 service->nameservers[i]);
2424 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2425 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
2428 DBG("default case do nothing");
2432 nameserver_remove(service, type, service->nameservers[i]);
2437 #if defined TIZEN_EXT
2438 const char *global_dns = connman_option_get_string("GlobalNameserver");
2440 nameserver_remove(service, type, global_dns);
2442 searchdomain_remove_all(service);
2448 * The is_auto variable is set to true when IPv6 autoconf nameservers are
2449 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
2450 * for details) and not through service.c
2452 #if defined TIZEN_EXT
2453 int __connman_service_nameserver_append(struct connman_service *service,
2454 const char *nameserver, bool is_auto,
2455 enum connman_ipconfig_type type)
2457 int __connman_service_nameserver_append(struct connman_service *service,
2458 const char *nameserver, bool is_auto)
2464 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
2470 nameservers = service->nameservers_auto;
2472 nameservers = service->nameservers;
2475 for (i = 0; nameservers[i]; i++) {
2476 #if defined TIZEN_EXT
2477 DBG("nameservers[%d] %s, nameserver %s", i, nameservers[i], nameserver);
2479 if (g_strcmp0(nameservers[i], nameserver) == 0)
2483 len = g_strv_length(nameservers);
2484 nameservers = g_try_renew(char *, nameservers, len + 2);
2487 nameservers = g_try_new0(char *, len + 2);
2493 nameservers[len] = g_strdup(nameserver);
2494 nameservers[len + 1] = NULL;
2497 if(type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
2498 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
2499 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
2501 if(type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
2502 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
2503 service->dns_config_method_ipv6 = CONNMAN_DNSCONFIG_METHOD_DHCP;
2507 service->nameservers_auto = nameservers;
2509 service->nameservers = nameservers;
2510 nameserver_add(service, CONNMAN_IPCONFIG_TYPE_ALL, nameserver);
2513 nameservers_changed(service);
2515 searchdomain_add_all(service);
2520 #if defined TIZEN_EXT
2521 int __connman_service_nameserver_remove(struct connman_service *service,
2522 const char *nameserver, bool is_auto,
2523 enum connman_ipconfig_type type)
2525 int __connman_service_nameserver_remove(struct connman_service *service,
2526 const char *nameserver, bool is_auto)
2529 char **servers, **nameservers;
2533 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
2539 nameservers = service->nameservers_auto;
2541 nameservers = service->nameservers;
2546 for (i = 0; nameservers[i]; i++)
2547 if (g_strcmp0(nameservers[i], nameserver) == 0) {
2555 len = g_strv_length(nameservers);
2562 servers = g_try_new0(char *, len);
2566 for (i = 0, j = 0; i < len; i++) {
2567 if (g_strcmp0(nameservers[i], nameserver)) {
2568 servers[j] = nameservers[i];
2571 g_free(nameservers[i]);
2573 nameservers[i] = NULL;
2575 servers[len - 1] = NULL;
2578 g_strfreev(nameservers);
2579 nameservers = servers;
2582 service->nameservers_auto = nameservers;
2584 service->nameservers = nameservers;
2585 #if defined TIZEN_EXT
2586 DBG("nameserver remove ip_type: %d", type);
2587 nameserver_remove(service, type,
2590 nameserver_remove(service, CONNMAN_IPCONFIG_TYPE_ALL,
2598 void __connman_service_nameserver_clear(struct connman_service *service)
2600 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
2602 g_strfreev(service->nameservers);
2603 service->nameservers = NULL;
2605 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
2608 static void add_nameserver_route(int family, int index, char *nameserver,
2613 if (connman_inet_compare_subnet(index, nameserver))
2616 if (connman_inet_add_host_route(index, nameserver, gw) < 0)
2617 /* For P-t-P link the above route add will fail */
2618 connman_inet_add_host_route(index, nameserver, NULL);
2622 if (connman_inet_add_ipv6_host_route(index, nameserver,
2624 connman_inet_add_ipv6_host_route(index, nameserver,
2630 static void nameserver_add_routes(int index, char **nameservers,
2633 int i, ns_family, gw_family;
2635 gw_family = connman_inet_check_ipaddress(gw);
2639 for (i = 0; nameservers[i]; i++) {
2640 ns_family = connman_inet_check_ipaddress(nameservers[i]);
2641 if (ns_family < 0 || ns_family != gw_family)
2644 add_nameserver_route(ns_family, index, nameservers[i], gw);
2648 static void nameserver_del_routes(int index, char **nameservers,
2649 enum connman_ipconfig_type type)
2653 for (i = 0; nameservers[i]; i++) {
2654 family = connman_inet_check_ipaddress(nameservers[i]);
2660 if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
2661 connman_inet_del_host_route(index,
2665 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
2666 connman_inet_del_ipv6_host_route(index,
2673 void __connman_service_nameserver_add_routes(struct connman_service *service,
2681 index = __connman_service_get_index(service);
2683 if (service->nameservers_config) {
2685 * Configured nameserver takes preference over the
2686 * discoverd nameserver gathered from DHCP, VPN, etc.
2688 nameserver_add_routes(index, service->nameservers_config, gw);
2689 } else if (service->nameservers) {
2691 * We add nameservers host routes for nameservers that
2692 * are not on our subnet. For those who are, the subnet
2693 * route will be installed by the time the dns proxy code
2694 * tries to reach them. The subnet route is installed
2695 * when setting the interface IP address.
2697 nameserver_add_routes(index, service->nameservers, gw);
2701 void __connman_service_nameserver_del_routes(struct connman_service *service,
2702 enum connman_ipconfig_type type)
2709 index = __connman_service_get_index(service);
2711 if (service->nameservers_config)
2712 nameserver_del_routes(index, service->nameservers_config,
2714 else if (service->nameservers)
2715 nameserver_del_routes(index, service->nameservers, type);
2718 static bool check_proxy_setup(struct connman_service *service)
2721 * We start WPAD if we haven't got a PAC URL from DHCP and
2722 * if our proxy manual configuration is either empty or set
2723 * to AUTO with an empty URL.
2726 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
2729 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
2730 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
2734 if (__connman_wpad_start(service) < 0) {
2735 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
2736 __connman_notifier_proxy_changed(service);
2743 static void cancel_online_check(struct connman_service *service)
2745 if (service->online_timeout == 0)
2748 g_source_remove(service->online_timeout);
2749 service->online_timeout = 0;
2750 connman_service_unref(service);
2753 static void start_online_check(struct connman_service *service,
2754 enum connman_ipconfig_type type)
2756 if (!connman_setting_get_bool("EnableOnlineCheck")) {
2757 connman_info("Online check disabled. "
2758 "Default service remains in READY state.");
2762 if (type != CONNMAN_IPCONFIG_TYPE_IPV4 || check_proxy_setup(service)) {
2763 cancel_online_check(service);
2764 __connman_service_wispr_start(service, type);
2768 static void address_updated(struct connman_service *service,
2769 enum connman_ipconfig_type type)
2771 if (is_connected(service->state) &&
2772 service == connman_service_get_default()) {
2773 nameserver_remove_all(service, type);
2774 nameserver_add_all(service, type);
2775 start_online_check(service, type);
2777 __connman_timeserver_sync(service);
2781 static struct connman_stats *stats_get(struct connman_service *service)
2783 if (service->roaming)
2784 return &service->stats_roaming;
2786 return &service->stats;
2789 static bool stats_enabled(struct connman_service *service)
2791 struct connman_stats *stats = stats_get(service);
2793 return stats->enabled;
2796 static void stats_start(struct connman_service *service)
2798 struct connman_stats *stats = stats_get(service);
2800 DBG("service %p", service);
2805 stats->enabled = true;
2806 stats->data_last.time = stats->data.time;
2808 g_timer_start(stats->timer);
2811 static void stats_stop(struct connman_service *service)
2813 struct connman_stats *stats = stats_get(service);
2814 unsigned int seconds;
2816 DBG("service %p", service);
2821 if (!stats->enabled)
2824 g_timer_stop(stats->timer);
2826 seconds = g_timer_elapsed(stats->timer, NULL);
2827 stats->data.time = stats->data_last.time + seconds;
2829 stats->enabled = false;
2832 static void reset_stats(struct connman_service *service)
2834 DBG("service %p", service);
2837 service->stats.valid = false;
2839 service->stats.data.rx_packets = 0;
2840 service->stats.data.tx_packets = 0;
2841 service->stats.data.rx_bytes = 0;
2842 service->stats.data.tx_bytes = 0;
2843 service->stats.data.rx_errors = 0;
2844 service->stats.data.tx_errors = 0;
2845 service->stats.data.rx_dropped = 0;
2846 service->stats.data.tx_dropped = 0;
2847 service->stats.data.time = 0;
2848 service->stats.data_last.time = 0;
2850 g_timer_reset(service->stats.timer);
2853 service->stats_roaming.valid = false;
2855 service->stats_roaming.data.rx_packets = 0;
2856 service->stats_roaming.data.tx_packets = 0;
2857 service->stats_roaming.data.rx_bytes = 0;
2858 service->stats_roaming.data.tx_bytes = 0;
2859 service->stats_roaming.data.rx_errors = 0;
2860 service->stats_roaming.data.tx_errors = 0;
2861 service->stats_roaming.data.rx_dropped = 0;
2862 service->stats_roaming.data.tx_dropped = 0;
2863 service->stats_roaming.data.time = 0;
2864 service->stats_roaming.data_last.time = 0;
2866 g_timer_reset(service->stats_roaming.timer);
2869 #if defined TIZEN_EXT
2870 static gboolean __connman_service_is_internet_profile(
2871 struct connman_service *cellular)
2873 const char internet_suffix[] = "_1";
2875 DBG("Service path: %s", cellular->path);
2877 if (g_str_has_suffix(cellular->path, internet_suffix) == TRUE)
2883 struct connman_service *connman_service_get_default_connection(void)
2886 struct connman_service *service;
2887 struct connman_service *default_service = NULL;
2889 for (list = service_list; list; list = list->next) {
2890 service = list->data;
2892 DBG("service: %p %s %s %s", service, service->name,
2893 state2string(service->state),
2894 __connman_service_type2string(service->type));
2896 #if defined TIZEN_MAINTAIN_ONLINE
2897 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2898 service->state == CONNMAN_SERVICE_STATE_ONLINE) {
2900 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2901 is_connected(service->state) == TRUE) {
2904 } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2905 __connman_service_is_internet_profile(service) == TRUE) {
2906 if (default_service == NULL)
2907 default_service = service;
2908 else if (is_connected(service->state) == TRUE &&
2909 is_connected(default_service->state) == FALSE)
2910 default_service = service;
2911 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
2912 is_connected(service->state) == TRUE) {
2913 if (default_service == NULL)
2914 default_service = service;
2915 } else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH &&
2916 is_connected(service->state) == TRUE) {
2917 if (default_service == NULL)
2918 default_service = service;
2922 return default_service;
2926 struct connman_service *connman_service_get_default(void)
2928 #if defined TIZEN_MAINTAIN_ONLINE
2929 return connman_service_get_default_connection();
2931 struct connman_service *service;
2936 service = service_list->data;
2938 if (!is_connected(service->state))
2945 bool __connman_service_index_is_default(int index)
2947 struct connman_service *service;
2952 service = connman_service_get_default();
2954 return __connman_service_get_index(service) == index;
2957 static void default_changed(void)
2959 #if defined TIZEN_EXT
2960 struct connman_service *service = connman_service_get_default_connection();
2962 struct connman_service *service = connman_service_get_default();
2965 if (service == current_default)
2968 DBG("current default %p %s", current_default,
2969 current_default ? current_default->identifier : "");
2970 DBG("new default %p %s", service, service ? service->identifier : "");
2972 #if defined TIZEN_EXT
2973 current_default = service;
2975 __connman_service_timeserver_changed(service, NULL);
2977 __connman_service_timeserver_changed(current_default, NULL);
2979 current_default = service;
2983 if (service->hostname &&
2984 connman_setting_get_bool("AllowHostnameUpdates"))
2985 __connman_utsname_set_hostname(service->hostname);
2987 if (service->domainname &&
2988 connman_setting_get_bool("AllowDomainnameUpdates"))
2989 __connman_utsname_set_domainname(service->domainname);
2992 * Connect VPN automatically when new default service
2993 * is set and connected, unless new default is VPN
2995 if (is_connected(service->state) &&
2996 service->type != CONNMAN_SERVICE_TYPE_VPN) {
2997 DBG("running vpn_auto_connect");
3002 __connman_notifier_default_changed(service);
3005 #if defined TIZEN_EXT
3006 static void append_struct(gpointer value, gpointer user_data);
3008 static void emit_state_changed_with_properties(struct connman_service *service)
3010 DBusMessage *signal;
3011 DBusMessageIter iter;
3016 signal = dbus_message_new_signal(service->path, CONNMAN_SERVICE_INTERFACE,
3017 "StateChangedProperties");
3021 dbus_message_iter_init_append(signal, &iter);
3022 append_struct(service, &iter);
3024 g_dbus_send_message(connection, signal);
3030 static void state_changed(struct connman_service *service)
3034 __connman_notifier_service_state_changed(service, service->state);
3036 str = state2string(service->state);
3040 #if !defined TIZEN_EXT
3041 if (!allow_property_changed(service))
3044 DBG(" %s, %s", str, service->path);
3047 connman_dbus_property_changed_basic(service->path,
3048 CONNMAN_SERVICE_INTERFACE, "State",
3049 DBUS_TYPE_STRING, &str);
3051 #if defined TIZEN_EXT
3052 emit_state_changed_with_properties(service);
3056 #if defined TIZEN_EXT
3057 static void connect_reason_changed(struct connman_service *service)
3059 struct connman_device *device;
3064 if (!allow_property_changed(service))
3067 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
3068 device = connman_network_get_device(service->network);
3070 bool need_save = false;
3072 need_save |= connman_device_set_last_user_selection_ident(device, service->identifier);
3073 need_save |= connman_device_set_last_user_selection_time(device, time(NULL));
3075 DBG("last user selection ident[%s] time[%ld]",
3076 connman_device_get_last_user_selection_ident(device),
3077 connman_device_get_last_user_selection_time(device));
3080 connman_device_save_last_user_selection(device);
3084 connman_dbus_property_changed_basic(service->path,
3085 CONNMAN_SERVICE_INTERFACE,
3088 &service->connect_reason);
3091 static void disconnection_requested_changed(struct connman_service *service)
3093 dbus_bool_t disconnection_requested;
3098 if (!allow_property_changed(service))
3101 disconnection_requested = service->disconnection_requested;
3102 connman_dbus_property_changed_basic(service->path,
3103 CONNMAN_SERVICE_INTERFACE,
3104 "DisconnectionRequested",
3106 &disconnection_requested);
3109 void connman_service_set_disconnection_requested(struct connman_service *service,
3110 bool disconnection_requested)
3112 if (service == NULL)
3115 service->disconnection_requested = disconnection_requested;
3116 disconnection_requested_changed(service);
3120 static void strength_changed(struct connman_service *service)
3122 if (service->strength == 0)
3125 if (!allow_property_changed(service))
3128 connman_dbus_property_changed_basic(service->path,
3129 CONNMAN_SERVICE_INTERFACE, "Strength",
3130 DBUS_TYPE_BYTE, &service->strength);
3133 #if defined TIZEN_EXT
3134 static bool update_last_connected_bssid(struct connman_service *service)
3136 const unsigned char *last_connected_bssid;
3138 if (!service->network)
3141 last_connected_bssid = connman_network_get_last_connected_bssid(service->network);
3142 if (memcmp(last_connected_bssid, invalid_bssid, WIFI_BSSID_LEN_MAX) == 0)
3145 if (memcmp(last_connected_bssid, service->last_connected_bssid, WIFI_BSSID_LEN_MAX) != 0) {
3146 memcpy(service->last_connected_bssid, last_connected_bssid, WIFI_BSSID_LEN_MAX);
3154 static void favorite_changed(struct connman_service *service)
3156 dbus_bool_t favorite;
3161 if (!allow_property_changed(service))
3164 favorite = service->favorite;
3165 connman_dbus_property_changed_basic(service->path,
3166 CONNMAN_SERVICE_INTERFACE, "Favorite",
3167 DBUS_TYPE_BOOLEAN, &favorite);
3170 static void immutable_changed(struct connman_service *service)
3172 dbus_bool_t immutable;
3177 if (!allow_property_changed(service))
3180 immutable = service->immutable;
3181 connman_dbus_property_changed_basic(service->path,
3182 CONNMAN_SERVICE_INTERFACE, "Immutable",
3183 DBUS_TYPE_BOOLEAN, &immutable);
3186 static void roaming_changed(struct connman_service *service)
3188 dbus_bool_t roaming;
3193 if (!allow_property_changed(service))
3196 roaming = service->roaming;
3197 connman_dbus_property_changed_basic(service->path,
3198 CONNMAN_SERVICE_INTERFACE, "Roaming",
3199 DBUS_TYPE_BOOLEAN, &roaming);
3202 static void autoconnect_changed(struct connman_service *service)
3204 dbus_bool_t autoconnect;
3209 if (!allow_property_changed(service))
3212 autoconnect = service->autoconnect;
3213 connman_dbus_property_changed_basic(service->path,
3214 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
3215 DBUS_TYPE_BOOLEAN, &autoconnect);
3218 bool connman_service_set_autoconnect(struct connman_service *service,
3221 if (service->autoconnect == autoconnect)
3224 service->autoconnect = autoconnect;
3225 autoconnect_changed(service);
3230 static void append_security(DBusMessageIter *iter, void *user_data)
3232 struct connman_service *service = user_data;
3235 str = security2string(service->security);
3237 dbus_message_iter_append_basic(iter,
3238 DBUS_TYPE_STRING, &str);
3241 * Some access points incorrectly advertise WPS even when they
3242 * are configured as open or no security, so filter
3246 switch (service->security) {
3247 case CONNMAN_SERVICE_SECURITY_PSK:
3248 case CONNMAN_SERVICE_SECURITY_WPA:
3249 case CONNMAN_SERVICE_SECURITY_RSN:
3250 #if defined TIZEN_EXT
3251 case CONNMAN_SERVICE_SECURITY_SAE:
3254 dbus_message_iter_append_basic(iter,
3255 DBUS_TYPE_STRING, &str);
3257 #if defined TIZEN_EXT
3258 case CONNMAN_SERVICE_SECURITY_OWE:
3260 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3261 case CONNMAN_SERVICE_SECURITY_NONE:
3262 case CONNMAN_SERVICE_SECURITY_WEP:
3263 case CONNMAN_SERVICE_SECURITY_8021X:
3267 if (service->wps_advertizing) {
3268 str = "wps_advertising";
3269 dbus_message_iter_append_basic(iter,
3270 DBUS_TYPE_STRING, &str);
3275 static void security_changed(struct connman_service *service)
3280 if (!allow_property_changed(service))
3283 connman_dbus_property_changed_array(service->path,
3284 CONNMAN_SERVICE_INTERFACE, "Security",
3285 DBUS_TYPE_STRING, append_security, service);
3288 static void append_ethernet(DBusMessageIter *iter, void *user_data)
3290 struct connman_service *service = user_data;
3292 if (service->ipconfig_ipv4)
3293 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
3295 else if (service->ipconfig_ipv6)
3296 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
3300 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3301 static void append_eap_over_ethernet(DBusMessageIter *iter, void *user_data)
3303 struct connman_service *service = user_data;
3306 val = service->use_eapol;
3307 connman_dbus_dict_append_basic(iter, "UseEapol",
3308 DBUS_TYPE_BOOLEAN, &val);
3309 if (service->use_eapol) {
3311 connman_dbus_dict_append_basic(iter, "EAP",
3312 DBUS_TYPE_STRING, &service->eap);
3314 if (service->identity)
3315 connman_dbus_dict_append_basic(iter, "Identity",
3316 DBUS_TYPE_STRING, &service->identity);
3318 if (service->anonymous_identity)
3319 connman_dbus_dict_append_basic(iter, "AnonymousIdentity",
3320 DBUS_TYPE_STRING, &service->anonymous_identity);
3322 if (service->ca_cert_file)
3323 connman_dbus_dict_append_basic(iter, "CACertFile",
3324 DBUS_TYPE_STRING, &service->ca_cert_file);
3326 if (service->client_cert_file)
3327 connman_dbus_dict_append_basic(iter, "ClientCertFile",
3328 DBUS_TYPE_STRING, &service->client_cert_file);
3330 if (service->private_key_file)
3331 connman_dbus_dict_append_basic(iter, "PrivateKeyFile",
3332 DBUS_TYPE_STRING, &service->private_key_file);
3334 if (service->phase2)
3335 connman_dbus_dict_append_basic(iter, "Phase2",
3336 DBUS_TYPE_STRING, &service->phase2);
3338 if (service->phase1)
3339 connman_dbus_dict_append_basic(iter, "Phase1",
3340 DBUS_TYPE_STRING, &service->phase1);
3342 if (service->pac_file)
3343 connman_dbus_dict_append_basic(iter, "PacFile",
3344 DBUS_TYPE_STRING, &service->pac_file);
3346 /* Should we include passphrase? */
3349 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3351 static void append_ipv4(DBusMessageIter *iter, void *user_data)
3353 struct connman_service *service = user_data;
3355 if (!is_connected(service->state_ipv4))
3358 if (service->ipconfig_ipv4)
3359 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
3362 static void append_ipv6(DBusMessageIter *iter, void *user_data)
3364 struct connman_service *service = user_data;
3366 if (!is_connected(service->state_ipv6))
3369 if (service->ipconfig_ipv6)
3370 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
3371 service->ipconfig_ipv4);
3374 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
3376 struct connman_service *service = user_data;
3378 if (service->ipconfig_ipv4)
3379 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
3383 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
3385 struct connman_service *service = user_data;
3387 if (service->ipconfig_ipv6)
3388 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
3392 static void append_nameservers(DBusMessageIter *iter,
3393 struct connman_service *service, char **servers)
3396 bool available = true;
3398 for (i = 0; servers[i]; i++) {
3400 available = nameserver_available(service,
3401 CONNMAN_IPCONFIG_TYPE_ALL,
3405 dbus_message_iter_append_basic(iter,
3406 DBUS_TYPE_STRING, &servers[i]);
3410 #if defined TIZEN_EXT
3411 static void append_nameserver_manual(DBusMessageIter *iter,
3412 struct connman_service *service, const char *server)
3414 bool available = true;
3417 available = nameserver_available(service,
3418 CONNMAN_IPCONFIG_TYPE_ALL, server);
3421 dbus_message_iter_append_basic(iter,
3422 DBUS_TYPE_STRING, &server);
3425 static void append_nameserver_dhcp(DBusMessageIter *iter,
3426 struct connman_service *service, const char *server)
3428 bool available = true;
3431 available = nameserver_available(service,
3432 CONNMAN_IPCONFIG_TYPE_ALL, server);
3435 dbus_message_iter_append_basic(iter,
3436 DBUS_TYPE_STRING, &server);
3440 static void append_dns(DBusMessageIter *iter, void *user_data)
3442 struct connman_service *service = user_data;
3443 #if defined TIZEN_EXT
3447 if (!is_connected(service->state))
3453 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
3455 char *str1 = g_strdup_printf("ipv4.%s", str);
3456 dbus_message_iter_append_basic(iter,
3457 DBUS_TYPE_STRING, &str1);
3461 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
3463 char *str1 = g_strdup_printf("ipv6.%s", str);
3464 dbus_message_iter_append_basic(iter,
3465 DBUS_TYPE_STRING, &str1);
3470 if (service->nameservers_config) {
3471 #if defined TIZEN_EXT
3473 while (service->nameservers_config[i]) {
3474 if (connman_inet_check_ipaddress(
3475 service->nameservers_config[i]) == AF_INET &&
3476 service->dns_config_method_ipv4 ==
3477 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
3478 append_nameserver_manual(iter, service,
3479 service->nameservers_config[i]);
3482 if (connman_inet_check_ipaddress(
3483 service->nameservers_config[i]) == AF_INET6 &&
3484 service->dns_config_method_ipv6 ==
3485 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
3486 append_nameserver_manual(iter, service,
3487 service->nameservers_config[i]);
3491 /* In case of mixed DNS Config Type one of IPv4/IPv6 can be
3492 * dynamic while other is static so try to append the DNS
3493 * Address which is dynamic also */
3494 if (service->nameservers != NULL) {
3496 while (service->nameservers[i]) {
3497 if (connman_inet_check_ipaddress(
3498 service->nameservers[i]) == AF_INET &&
3499 service->dns_config_method_ipv4 ==
3500 CONNMAN_DNSCONFIG_METHOD_DHCP) {
3501 append_nameserver_dhcp(iter, service,
3502 service->nameservers[i]);
3505 if (connman_inet_check_ipaddress(
3506 service->nameservers[i]) == AF_INET6 &&
3507 service->dns_config_method_ipv6 ==
3508 CONNMAN_DNSCONFIG_METHOD_DHCP) {
3509 append_nameserver_dhcp(iter, service,
3510 service->nameservers[i]);
3516 append_nameservers(iter, service, service->nameservers_config);
3520 if (service->nameservers)
3521 #if defined TIZEN_EXT
3524 while (service->nameservers[i]) {
3525 if (connman_inet_check_ipaddress(
3526 service->nameservers[i]) == AF_INET &&
3527 service->dns_config_method_ipv4 ==
3528 CONNMAN_DNSCONFIG_METHOD_DHCP) {
3529 append_nameserver_dhcp(iter, service,
3530 service->nameservers[i]);
3533 if (connman_inet_check_ipaddress(
3534 service->nameservers[i]) == AF_INET6 &&
3535 service->dns_config_method_ipv6 ==
3536 CONNMAN_DNSCONFIG_METHOD_DHCP) {
3537 append_nameserver_dhcp(iter, service,
3538 service->nameservers[i]);
3544 append_nameservers(iter, service,
3545 service->nameservers);
3548 if (service->nameservers_auto)
3549 append_nameservers(iter, service,
3550 service->nameservers_auto);
3552 if (!service->nameservers && !service->nameservers_auto) {
3555 DBG("append fallback nameservers");
3557 ns = connman_setting_get_string_list("FallbackNameservers");
3559 append_nameservers(iter, service, ns);
3564 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
3566 struct connman_service *service = user_data;
3569 /* Append DNS Config Type */
3571 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
3573 char *str1 = g_strdup_printf("ipv4.%s", str);
3574 dbus_message_iter_append_basic(iter,
3575 DBUS_TYPE_STRING, &str1);
3579 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
3581 char *str1 = g_strdup_printf("ipv6.%s", str);
3582 dbus_message_iter_append_basic(iter,
3583 DBUS_TYPE_STRING, &str1);
3588 if (!service->nameservers_config)
3591 #if defined TIZEN_EXT
3593 while (service->nameservers_config[i]) {
3594 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET &&
3595 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
3596 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
3599 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET6 &&
3600 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
3601 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
3606 append_nameservers(iter, NULL, service->nameservers_config);
3610 static void append_ts(DBusMessageIter *iter, void *user_data)
3612 GSList *list = user_data;
3615 char *timeserver = list->data;
3618 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
3621 list = g_slist_next(list);
3625 static void append_tsconfig(DBusMessageIter *iter, void *user_data)
3627 struct connman_service *service = user_data;
3630 if (!service->timeservers_config)
3633 for (i = 0; service->timeservers_config[i]; i++) {
3634 dbus_message_iter_append_basic(iter,
3636 &service->timeservers_config[i]);
3640 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
3642 struct connman_service *service = user_data;
3645 if (!service->domains)
3648 for (i = 0; service->domains[i]; i++)
3649 dbus_message_iter_append_basic(iter,
3650 DBUS_TYPE_STRING, &service->domains[i]);
3653 static void append_domain(DBusMessageIter *iter, void *user_data)
3655 struct connman_service *service = user_data;
3657 if (!is_connected(service->state) &&
3658 !is_connecting(service->state))
3661 if (service->domains)
3662 append_domainconfig(iter, user_data);
3663 else if (service->domainname)
3664 dbus_message_iter_append_basic(iter,
3665 DBUS_TYPE_STRING, &service->domainname);
3668 static void append_proxies(DBusMessageIter *iter, void *user_data)
3670 struct connman_service *service = user_data;
3673 if (!service->proxies)
3676 for (i = 0; service->proxies[i]; i++)
3677 dbus_message_iter_append_basic(iter,
3678 DBUS_TYPE_STRING, &service->proxies[i]);
3681 static void append_excludes(DBusMessageIter *iter, void *user_data)
3683 struct connman_service *service = user_data;
3686 if (!service->excludes)
3689 for (i = 0; service->excludes[i]; i++)
3690 dbus_message_iter_append_basic(iter,
3691 DBUS_TYPE_STRING, &service->excludes[i]);
3694 static void append_proxy(DBusMessageIter *iter, void *user_data)
3696 struct connman_service *service = user_data;
3697 enum connman_service_proxy_method proxy;
3698 const char *pac = NULL;
3699 const char *method = proxymethod2string(
3700 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
3702 if (!is_connected(service->state))
3705 proxy = connman_service_get_proxy_method(service);
3708 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
3710 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
3712 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
3713 connman_dbus_dict_append_array(iter, "Servers",
3714 DBUS_TYPE_STRING, append_proxies,
3717 connman_dbus_dict_append_array(iter, "Excludes",
3718 DBUS_TYPE_STRING, append_excludes,
3721 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
3722 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
3723 if (service->ipconfig_ipv4)
3724 pac = __connman_ipconfig_get_proxy_autoconfig(
3725 service->ipconfig_ipv4);
3726 else if (service->ipconfig_ipv6)
3727 pac = __connman_ipconfig_get_proxy_autoconfig(
3728 service->ipconfig_ipv6);
3730 if (!service->pac && !pac)
3736 connman_dbus_dict_append_basic(iter, "URL",
3737 DBUS_TYPE_STRING, &pac);
3741 method = proxymethod2string(proxy);
3744 connman_dbus_dict_append_basic(iter, "Method",
3745 DBUS_TYPE_STRING, &method);
3748 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
3750 struct connman_service *service = user_data;
3753 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
3756 switch (service->proxy_config) {
3757 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
3759 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
3761 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
3762 if (service->proxies)
3763 connman_dbus_dict_append_array(iter, "Servers",
3765 append_proxies, service);
3767 if (service->excludes)
3768 connman_dbus_dict_append_array(iter, "Excludes",
3770 append_excludes, service);
3772 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
3774 connman_dbus_dict_append_basic(iter, "URL",
3775 DBUS_TYPE_STRING, &service->pac);
3779 method = proxymethod2string(service->proxy_config);
3781 connman_dbus_dict_append_basic(iter, "Method",
3782 DBUS_TYPE_STRING, &method);
3785 static void append_provider(DBusMessageIter *iter, void *user_data)
3787 struct connman_service *service = user_data;
3789 if (!is_connected(service->state))
3792 if (service->provider)
3793 __connman_provider_append_properties(service->provider, iter);
3797 static void settings_changed(struct connman_service *service,
3798 struct connman_ipconfig *ipconfig)
3800 enum connman_ipconfig_type type;
3802 type = __connman_ipconfig_get_config_type(ipconfig);
3804 __connman_notifier_ipconfig_changed(service, ipconfig);
3806 if (!allow_property_changed(service))
3809 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
3810 connman_dbus_property_changed_dict(service->path,
3811 CONNMAN_SERVICE_INTERFACE, "IPv4",
3812 append_ipv4, service);
3813 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
3814 connman_dbus_property_changed_dict(service->path,
3815 CONNMAN_SERVICE_INTERFACE, "IPv6",
3816 append_ipv6, service);
3819 static void ipv4_configuration_changed(struct connman_service *service)
3821 if (!allow_property_changed(service))
3824 connman_dbus_property_changed_dict(service->path,
3825 CONNMAN_SERVICE_INTERFACE,
3826 "IPv4.Configuration",
3831 void __connman_service_notify_ipv4_configuration(
3832 struct connman_service *service)
3837 ipv4_configuration_changed(service);
3840 static void ipv6_configuration_changed(struct connman_service *service)
3842 if (!allow_property_changed(service))
3845 connman_dbus_property_changed_dict(service->path,
3846 CONNMAN_SERVICE_INTERFACE,
3847 "IPv6.Configuration",
3852 static void dns_changed(struct connman_service *service)
3854 if (!allow_property_changed(service))
3857 connman_dbus_property_changed_array(service->path,
3858 CONNMAN_SERVICE_INTERFACE, "Nameservers",
3859 DBUS_TYPE_STRING, append_dns, service);
3862 static void dns_configuration_changed(struct connman_service *service)
3864 if (!allow_property_changed(service))
3867 connman_dbus_property_changed_array(service->path,
3868 CONNMAN_SERVICE_INTERFACE,
3869 "Nameservers.Configuration",
3870 DBUS_TYPE_STRING, append_dnsconfig, service);
3872 dns_changed(service);
3875 static void domain_changed(struct connman_service *service)
3877 if (!allow_property_changed(service))
3880 connman_dbus_property_changed_array(service->path,
3881 CONNMAN_SERVICE_INTERFACE, "Domains",
3882 DBUS_TYPE_STRING, append_domain, service);
3885 static void domain_configuration_changed(struct connman_service *service)
3887 if (!allow_property_changed(service))
3890 connman_dbus_property_changed_array(service->path,
3891 CONNMAN_SERVICE_INTERFACE,
3892 "Domains.Configuration",
3893 DBUS_TYPE_STRING, append_domainconfig, service);
3896 static void proxy_changed(struct connman_service *service)
3898 if (!allow_property_changed(service))
3901 connman_dbus_property_changed_dict(service->path,
3902 CONNMAN_SERVICE_INTERFACE, "Proxy",
3903 append_proxy, service);
3906 static void proxy_configuration_changed(struct connman_service *service)
3908 if (!allow_property_changed(service))
3911 connman_dbus_property_changed_dict(service->path,
3912 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
3913 append_proxyconfig, service);
3915 proxy_changed(service);
3918 static void mdns_changed(struct connman_service *service)
3920 dbus_bool_t mdns = service->mdns;
3922 if (!allow_property_changed(service))
3925 connman_dbus_property_changed_basic(service->path,
3926 CONNMAN_SERVICE_INTERFACE, "mDNS", DBUS_TYPE_BOOLEAN,
3930 static void mdns_configuration_changed(struct connman_service *service)
3932 dbus_bool_t mdns_config = service->mdns_config;
3934 if (!allow_property_changed(service))
3937 connman_dbus_property_changed_basic(service->path,
3938 CONNMAN_SERVICE_INTERFACE, "mDNS.Configuration",
3939 DBUS_TYPE_BOOLEAN, &mdns_config);
3942 static int set_mdns(struct connman_service *service,
3947 result = __connman_resolver_set_mdns(
3948 __connman_service_get_index(service), enabled);
3951 if (service->mdns != enabled) {
3952 service->mdns = enabled;
3953 mdns_changed(service);
3960 static void timeservers_configuration_changed(struct connman_service *service)
3962 if (!allow_property_changed(service))
3965 connman_dbus_property_changed_array(service->path,
3966 CONNMAN_SERVICE_INTERFACE,
3967 "Timeservers.Configuration",
3969 append_tsconfig, service);
3972 static void link_changed(struct connman_service *service)
3974 if (!allow_property_changed(service))
3977 connman_dbus_property_changed_dict(service->path,
3978 CONNMAN_SERVICE_INTERFACE, "Ethernet",
3979 append_ethernet, service);
3982 static void stats_append_counters(DBusMessageIter *dict,
3983 struct connman_stats_data *stats,
3984 struct connman_stats_data *counters,
3987 if (counters->rx_packets != stats->rx_packets || append_all) {
3988 counters->rx_packets = stats->rx_packets;
3989 connman_dbus_dict_append_basic(dict, "RX.Packets",
3990 DBUS_TYPE_UINT32, &stats->rx_packets);
3993 if (counters->tx_packets != stats->tx_packets || append_all) {
3994 counters->tx_packets = stats->tx_packets;
3995 connman_dbus_dict_append_basic(dict, "TX.Packets",
3996 DBUS_TYPE_UINT32, &stats->tx_packets);
3999 if (counters->rx_bytes != stats->rx_bytes || append_all) {
4000 counters->rx_bytes = stats->rx_bytes;
4001 connman_dbus_dict_append_basic(dict, "RX.Bytes",
4002 DBUS_TYPE_UINT32, &stats->rx_bytes);
4005 if (counters->tx_bytes != stats->tx_bytes || append_all) {
4006 counters->tx_bytes = stats->tx_bytes;
4007 connman_dbus_dict_append_basic(dict, "TX.Bytes",
4008 DBUS_TYPE_UINT32, &stats->tx_bytes);
4011 if (counters->rx_errors != stats->rx_errors || append_all) {
4012 counters->rx_errors = stats->rx_errors;
4013 connman_dbus_dict_append_basic(dict, "RX.Errors",
4014 DBUS_TYPE_UINT32, &stats->rx_errors);
4017 if (counters->tx_errors != stats->tx_errors || append_all) {
4018 counters->tx_errors = stats->tx_errors;
4019 connman_dbus_dict_append_basic(dict, "TX.Errors",
4020 DBUS_TYPE_UINT32, &stats->tx_errors);
4023 if (counters->rx_dropped != stats->rx_dropped || append_all) {
4024 counters->rx_dropped = stats->rx_dropped;
4025 connman_dbus_dict_append_basic(dict, "RX.Dropped",
4026 DBUS_TYPE_UINT32, &stats->rx_dropped);
4029 if (counters->tx_dropped != stats->tx_dropped || append_all) {
4030 counters->tx_dropped = stats->tx_dropped;
4031 connman_dbus_dict_append_basic(dict, "TX.Dropped",
4032 DBUS_TYPE_UINT32, &stats->tx_dropped);
4035 if (counters->time != stats->time || append_all) {
4036 counters->time = stats->time;
4037 connman_dbus_dict_append_basic(dict, "Time",
4038 DBUS_TYPE_UINT32, &stats->time);
4042 static void stats_append(struct connman_service *service,
4043 const char *counter,
4044 struct connman_stats_counter *counters,
4047 DBusMessageIter array, dict;
4050 DBG("service %p counter %s", service, counter);
4052 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
4056 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
4057 &service->path, DBUS_TYPE_INVALID);
4059 dbus_message_iter_init_append(msg, &array);
4062 connman_dbus_dict_open(&array, &dict);
4064 stats_append_counters(&dict, &service->stats.data,
4065 &counters->stats.data, append_all);
4067 connman_dbus_dict_close(&array, &dict);
4069 /* roaming counter */
4070 connman_dbus_dict_open(&array, &dict);
4072 stats_append_counters(&dict, &service->stats_roaming.data,
4073 &counters->stats_roaming.data, append_all);
4075 connman_dbus_dict_close(&array, &dict);
4077 __connman_counter_send_usage(counter, msg);
4080 static void stats_update(struct connman_service *service,
4081 unsigned int rx_packets, unsigned int tx_packets,
4082 unsigned int rx_bytes, unsigned int tx_bytes,
4083 unsigned int rx_errors, unsigned int tx_errors,
4084 unsigned int rx_dropped, unsigned int tx_dropped)
4086 struct connman_stats *stats = stats_get(service);
4087 struct connman_stats_data *data_last = &stats->data_last;
4088 struct connman_stats_data *data = &stats->data;
4089 unsigned int seconds;
4091 DBG("service %p", service);
4095 rx_packets - data_last->rx_packets;
4097 tx_packets - data_last->tx_packets;
4099 rx_bytes - data_last->rx_bytes;
4101 tx_bytes - data_last->tx_bytes;
4103 rx_errors - data_last->rx_errors;
4105 tx_errors - data_last->tx_errors;
4107 rx_dropped - data_last->rx_dropped;
4109 tx_dropped - data_last->tx_dropped;
4111 stats->valid = true;
4114 data_last->rx_packets = rx_packets;
4115 data_last->tx_packets = tx_packets;
4116 data_last->rx_bytes = rx_bytes;
4117 data_last->tx_bytes = tx_bytes;
4118 data_last->rx_errors = rx_errors;
4119 data_last->tx_errors = tx_errors;
4120 data_last->rx_dropped = rx_dropped;
4121 data_last->tx_dropped = tx_dropped;
4123 seconds = g_timer_elapsed(stats->timer, NULL);
4124 stats->data.time = stats->data_last.time + seconds;
4127 void __connman_service_notify(struct connman_service *service,
4128 unsigned int rx_packets, unsigned int tx_packets,
4129 unsigned int rx_bytes, unsigned int tx_bytes,
4130 unsigned int rx_errors, unsigned int tx_errors,
4131 unsigned int rx_dropped, unsigned int tx_dropped)
4133 GHashTableIter iter;
4134 gpointer key, value;
4135 const char *counter;
4136 struct connman_stats_counter *counters;
4137 struct connman_stats_data *data;
4143 if (!is_connected(service->state))
4146 stats_update(service,
4147 rx_packets, tx_packets,
4149 rx_errors, tx_errors,
4150 rx_dropped, tx_dropped);
4152 data = &stats_get(service)->data;
4153 err = __connman_stats_update(service, service->roaming, data);
4155 connman_error("Failed to store statistics for %s",
4156 service->identifier);
4158 g_hash_table_iter_init(&iter, service->counter_table);
4159 while (g_hash_table_iter_next(&iter, &key, &value)) {
4163 stats_append(service, counter, counters, counters->append_all);
4164 counters->append_all = false;
4168 int __connman_service_counter_register(const char *counter)
4170 struct connman_service *service;
4172 struct connman_stats_counter *counters;
4174 DBG("counter %s", counter);
4176 counter_list = g_slist_prepend(counter_list, (gpointer)counter);
4178 for (list = service_list; list; list = list->next) {
4179 service = list->data;
4181 counters = g_try_new0(struct connman_stats_counter, 1);
4185 counters->append_all = true;
4187 g_hash_table_replace(service->counter_table, (gpointer)counter,
4194 void __connman_service_counter_unregister(const char *counter)
4196 struct connman_service *service;
4199 DBG("counter %s", counter);
4201 for (list = service_list; list; list = list->next) {
4202 service = list->data;
4204 g_hash_table_remove(service->counter_table, counter);
4207 counter_list = g_slist_remove(counter_list, counter);
4210 int connman_service_iterate_services(connman_service_iterate_cb cb,
4216 for (list = service_list; list && ret == 0; list = list->next)
4217 ret = cb((struct connman_service *)list->data, user_data);
4222 #if defined TIZEN_EXT
4223 static void append_wifi_ext_info(DBusMessageIter *dict,
4224 struct connman_network *network)
4226 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
4227 char *bssid_str = bssid_buff;
4229 unsigned int ssid_len;
4230 unsigned char *bssid;
4231 unsigned int maxrate;
4233 unsigned int keymgmt;
4235 const char *enc_mode;
4238 char country_code_buff[WIFI_COUNTRY_CODE_LEN + 1] = {0,};
4239 char *country_code_str = country_code_buff;
4240 unsigned char *country_code;
4241 uint16_t connection_mode;
4243 ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
4244 bssid = connman_network_get_bssid(network);
4245 maxrate = connman_network_get_maxrate(network);
4246 maxspeed = connman_network_get_maxspeed(network);
4247 frequency = connman_network_get_frequency(network);
4248 enc_mode = connman_network_get_enc_mode(network);
4249 passpoint = connman_network_get_bool(network, "WiFi.HS20AP");
4250 keymgmt = connman_network_get_keymgmt(network);
4251 country_code = connman_network_get_countrycode(network);
4252 connection_mode = connman_network_get_connection_mode(network);
4254 snprintf(bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bssid));
4256 snprintf(country_code_str, (WIFI_COUNTRY_CODE_LEN + 1), "%c%c",
4257 country_code[0], country_code[1]);
4260 connman_dbus_dict_append_fixed_array(dict, "SSID",
4261 DBUS_TYPE_BYTE, &ssid, ssid_len);
4262 connman_dbus_dict_append_basic(dict, "BSSID",
4263 DBUS_TYPE_STRING, &bssid_str);
4264 connman_dbus_dict_append_basic(dict, "MaxRate",
4265 DBUS_TYPE_UINT32, &maxrate);
4266 connman_dbus_dict_append_basic(dict, "MaxSpeed",
4267 DBUS_TYPE_INT32, &maxspeed);
4268 connman_dbus_dict_append_basic(dict, "Frequency",
4269 DBUS_TYPE_UINT16, &frequency);
4270 connman_dbus_dict_append_basic(dict, "EncryptionMode",
4271 DBUS_TYPE_STRING, &enc_mode);
4272 connman_dbus_dict_append_basic(dict, "Passpoint",
4273 DBUS_TYPE_BOOLEAN, &passpoint);
4274 connman_dbus_dict_append_basic(dict, "Keymgmt",
4275 DBUS_TYPE_UINT32, &keymgmt);
4276 connman_dbus_dict_append_basic(dict, "Country", DBUS_TYPE_STRING,
4278 connman_dbus_dict_append_basic(dict, "ConnMode",
4279 DBUS_TYPE_UINT16, &connection_mode);
4281 str = connman_network_get_string(network, "WiFi.Security");
4282 if (str != NULL && g_str_equal(str, "ieee8021x") == TRUE) {
4283 str = connman_network_get_string(network, "WiFi.EAP");
4285 connman_dbus_dict_append_basic(dict, "EAP",
4286 DBUS_TYPE_STRING, &str);
4288 str = connman_network_get_string(network, "WiFi.Phase2");
4290 connman_dbus_dict_append_basic(dict, "Phase2",
4291 DBUS_TYPE_STRING, &str);
4293 str = connman_network_get_string(network, "WiFi.Identity");
4295 connman_dbus_dict_append_basic(dict, "Identity",
4296 DBUS_TYPE_STRING, &str);
4298 str = connman_network_get_string(network, "WiFi.CACertFile");
4300 connman_dbus_dict_append_basic(dict, "CACertFile",
4301 DBUS_TYPE_STRING, &str);
4303 str = connman_network_get_string(network,
4304 "WiFi.ClientCertFile");
4306 connman_dbus_dict_append_basic(dict, "ClientCertFile",
4307 DBUS_TYPE_STRING, &str);
4309 str = connman_network_get_string(network,
4310 "WiFi.PrivateKeyFile");
4312 connman_dbus_dict_append_basic(dict, "PrivateKeyFile",
4313 DBUS_TYPE_STRING, &str);
4317 static void append_bssid_info(DBusMessageIter *iter, void *user_data)
4319 GSList *bssid_list = NULL;
4320 struct connman_network *network = user_data;
4321 struct connman_bssids *bssids;
4322 char bssid_buf[MAC_ADDRESS_LENGTH] = {0,};
4323 char *bssid_str = bssid_buf;
4325 bssid_list = (GSList *)connman_network_get_bssid_list(network);
4328 for (list = bssid_list; list; list = list->next) {
4329 bssids = (struct connman_bssids *)list->data;
4330 g_snprintf(bssid_buf, MAC_ADDRESS_LENGTH, MACSTR, MAC2STR(bssids->bssid));
4332 connman_dbus_dict_append_basic(iter, "BSSID",
4333 DBUS_TYPE_STRING, &bssid_str);
4335 connman_dbus_dict_append_basic(iter, "Strength",
4336 DBUS_TYPE_UINT16, &bssids->strength);
4338 connman_dbus_dict_append_basic(iter, "Frequency",
4339 DBUS_TYPE_UINT16, &bssids->frequency);
4345 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
4346 struct connman_service *service)
4352 #if defined TIZEN_EXT
4353 unsigned int frequency = 0U;
4354 unsigned char *wifi_vsie;
4355 unsigned int wifi_vsie_len;
4356 GSList *vsie_list = NULL;
4358 if (service->network) {
4359 frequency = connman_network_get_frequency(service->network);
4360 connman_dbus_dict_append_basic(dict, "Frequency",
4361 DBUS_TYPE_UINT16, &frequency);
4362 vsie_list = (GSList *)connman_network_get_vsie_list(service->network);
4367 for (list = vsie_list; list; list = list->next) {
4368 wifi_vsie = (unsigned char *)list->data;
4369 wifi_vsie_len = wifi_vsie[1] + 2;
4371 connman_dbus_dict_append_fixed_array(dict, "Vsie", DBUS_TYPE_BYTE,
4372 &wifi_vsie, wifi_vsie_len);
4377 str = __connman_service_type2string(service->type);
4379 connman_dbus_dict_append_basic(dict, "Type",
4380 DBUS_TYPE_STRING, &str);
4382 connman_dbus_dict_append_array(dict, "Security",
4383 DBUS_TYPE_STRING, append_security, service);
4385 str = state2string(service->state);
4387 connman_dbus_dict_append_basic(dict, "State",
4388 DBUS_TYPE_STRING, &str);
4391 str = state2string(service->state_ipv6);
4393 connman_dbus_dict_append_basic(dict, "StateIPv6",
4394 DBUS_TYPE_STRING, &str);
4397 str = error2string(service->error);
4399 connman_dbus_dict_append_basic(dict, "Error",
4400 DBUS_TYPE_STRING, &str);
4402 if (service->strength > 0)
4403 connman_dbus_dict_append_basic(dict, "Strength",
4404 DBUS_TYPE_BYTE, &service->strength);
4406 val = service->favorite;
4407 connman_dbus_dict_append_basic(dict, "Favorite",
4408 DBUS_TYPE_BOOLEAN, &val);
4410 val = service->immutable;
4411 connman_dbus_dict_append_basic(dict, "Immutable",
4412 DBUS_TYPE_BOOLEAN, &val);
4414 if (service->favorite)
4415 val = service->autoconnect;
4417 val = service->favorite;
4419 connman_dbus_dict_append_basic(dict, "AutoConnect",
4420 DBUS_TYPE_BOOLEAN, &val);
4423 connman_dbus_dict_append_basic(dict, "Name",
4424 DBUS_TYPE_STRING, &service->name);
4426 switch (service->type) {
4427 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4428 case CONNMAN_SERVICE_TYPE_SYSTEM:
4429 case CONNMAN_SERVICE_TYPE_GPS:
4430 case CONNMAN_SERVICE_TYPE_VPN:
4431 case CONNMAN_SERVICE_TYPE_P2P:
4432 #if defined TIZEN_EXT_WIFI_MESH
4433 case CONNMAN_SERVICE_TYPE_MESH:
4436 case CONNMAN_SERVICE_TYPE_CELLULAR:
4437 val = service->roaming;
4438 connman_dbus_dict_append_basic(dict, "Roaming",
4439 DBUS_TYPE_BOOLEAN, &val);
4441 connman_dbus_dict_append_dict(dict, "Ethernet",
4442 append_ethernet, service);
4444 case CONNMAN_SERVICE_TYPE_WIFI:
4445 #if defined TIZEN_EXT
4446 if (service->network != NULL) {
4447 append_wifi_ext_info(dict, service->network);
4448 connman_dbus_dict_append_dict(dict, "BSSID.List",
4449 append_bssid_info, service->network);
4452 connman_dbus_dict_append_dict(dict, "Ethernet",
4453 append_ethernet, service);
4455 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
4456 connman_dbus_dict_append_basic(dict, "DisconnectReason",
4457 DBUS_TYPE_INT32, &service->disconnect_reason);
4459 connman_dbus_dict_append_basic(dict, "AssocStatusCode",
4460 DBUS_TYPE_INT32, &service->assoc_status_code);
4462 val = service->hidden_service;
4463 connman_dbus_dict_append_basic(dict, "Hidden",
4464 DBUS_TYPE_BOOLEAN, &val);
4468 case CONNMAN_SERVICE_TYPE_ETHERNET:
4469 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4470 connman_dbus_dict_append_dict(dict, "EapOverEthernet",
4471 append_eap_over_ethernet, service);
4473 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4474 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4475 case CONNMAN_SERVICE_TYPE_GADGET:
4476 connman_dbus_dict_append_dict(dict, "Ethernet",
4477 append_ethernet, service);
4481 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
4483 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
4484 append_ipv4config, service);
4486 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
4488 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
4489 append_ipv6config, service);
4491 connman_dbus_dict_append_array(dict, "Nameservers",
4492 DBUS_TYPE_STRING, append_dns, service);
4494 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
4495 DBUS_TYPE_STRING, append_dnsconfig, service);
4497 if (service->state == CONNMAN_SERVICE_STATE_READY ||
4498 service->state == CONNMAN_SERVICE_STATE_ONLINE)
4499 list = __connman_timeserver_get_all(service);
4503 connman_dbus_dict_append_array(dict, "Timeservers",
4504 DBUS_TYPE_STRING, append_ts, list);
4506 g_slist_free_full(list, g_free);
4508 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
4509 DBUS_TYPE_STRING, append_tsconfig, service);
4511 connman_dbus_dict_append_array(dict, "Domains",
4512 DBUS_TYPE_STRING, append_domain, service);
4514 connman_dbus_dict_append_array(dict, "Domains.Configuration",
4515 DBUS_TYPE_STRING, append_domainconfig, service);
4517 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
4519 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
4520 append_proxyconfig, service);
4522 val = service->mdns;
4523 connman_dbus_dict_append_basic(dict, "mDNS", DBUS_TYPE_BOOLEAN,
4526 val = service->mdns_config;
4527 connman_dbus_dict_append_basic(dict, "mDNS.Configuration",
4528 DBUS_TYPE_BOOLEAN, &val);
4530 connman_dbus_dict_append_dict(dict, "Provider",
4531 append_provider, service);
4533 if (service->network)
4534 connman_network_append_acddbus(dict, service->network);
4537 #if defined TIZEN_EXT_INS
4538 static void append_ins_bssid_info(DBusMessageIter *iter, void *user_data)
4540 GSList *bssid_list = NULL;
4541 struct connman_network *network = user_data;
4542 struct connman_bssids *bssids;
4543 char bssid_buf[MAC_ADDRESS_LENGTH] = {0,};
4544 char *bssid_str = bssid_buf;
4546 bssid_list = (GSList *)connman_network_get_bssid_list(network);
4549 for (list = bssid_list; list; list = list->next) {
4550 bssids = (struct connman_bssids *)list->data;
4551 g_snprintf(bssid_buf, MAC_ADDRESS_LENGTH, MACSTR, MAC2STR(bssids->bssid));
4553 connman_dbus_dict_append_basic(iter, "BSSID",
4554 DBUS_TYPE_STRING, &bssid_str);
4556 connman_dbus_dict_append_basic(iter, "ScoreINS",
4557 DBUS_TYPE_INT32, &bssids->ins_score);
4559 connman_dbus_dict_append_basic(iter, "ScoreLastConnected",
4560 DBUS_TYPE_INT32, &bssids->score_last_connected_bssid);
4562 connman_dbus_dict_append_basic(iter, "ScoreAssocReject",
4563 DBUS_TYPE_INT32, &bssids->score_assoc_reject);
4565 connman_dbus_dict_append_basic(iter, "Frequency",
4566 DBUS_TYPE_UINT16, &bssids->frequency);
4568 connman_dbus_dict_append_basic(iter, "ScoreFrequency",
4569 DBUS_TYPE_INT32, &bssids->score_frequency);
4571 connman_dbus_dict_append_basic(iter, "Strength",
4572 DBUS_TYPE_UINT16, &bssids->strength);
4574 connman_dbus_dict_append_basic(iter, "ScoreStrength",
4575 DBUS_TYPE_INT32, &bssids->score_strength);
4580 static void append_ins_properties(DBusMessageIter *dict,
4581 struct connman_service *service)
4584 unsigned int frequency = 0U;
4587 connman_dbus_dict_append_basic(dict, "Name",
4588 DBUS_TYPE_STRING, &service->name);
4590 connman_dbus_dict_append_basic(dict, "ScoreINS",
4591 DBUS_TYPE_INT32, &service->ins_score);
4593 connman_dbus_dict_append_basic(dict, "ScoreLastUserSelection",
4594 DBUS_TYPE_INT32, &service->score_last_user_selection);
4596 connman_dbus_dict_append_basic(dict, "ScoreLastConnected",
4597 DBUS_TYPE_INT32, &service->score_last_connected);
4599 str = security2string(service->security);
4601 connman_dbus_dict_append_basic(dict, "Security",
4602 DBUS_TYPE_STRING, &str);
4604 connman_dbus_dict_append_basic(dict, "ScoreSecurityPriority",
4605 DBUS_TYPE_INT32, &service->score_security_priority);
4607 connman_dbus_dict_append_basic(dict, "Strength",
4608 DBUS_TYPE_BYTE, &service->strength);
4610 connman_dbus_dict_append_basic(dict, "ScoreStrength",
4611 DBUS_TYPE_INT32, &service->score_strength);
4613 connman_dbus_dict_append_basic(dict, "ScoreInternetConnection",
4614 DBUS_TYPE_INT32, &service->score_internet_connection);
4616 if (service->network) {
4617 frequency = connman_network_get_frequency(service->network);
4618 connman_dbus_dict_append_basic(dict, "Frequency",
4619 DBUS_TYPE_UINT16, &frequency);
4621 connman_dbus_dict_append_basic(dict, "ScoreFrequency",
4622 DBUS_TYPE_INT32, &service->score_frequency);
4624 connman_dbus_dict_append_dict(dict, "BSSID.List",
4625 append_ins_bssid_info, service->network);
4630 static void append_struct_service(DBusMessageIter *iter,
4631 connman_dbus_append_cb_t function,
4632 struct connman_service *service)
4634 DBusMessageIter entry, dict;
4636 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
4638 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
4641 connman_dbus_dict_open(&entry, &dict);
4643 function(&dict, service);
4644 connman_dbus_dict_close(&entry, &dict);
4646 dbus_message_iter_close_container(iter, &entry);
4649 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
4651 struct connman_service *service = user_data;
4653 append_properties(dict, TRUE, service);
4656 static void append_struct(gpointer value, gpointer user_data)
4658 struct connman_service *service = value;
4659 DBusMessageIter *iter = user_data;
4664 append_struct_service(iter, append_dict_properties, service);
4667 void __connman_service_list_struct(DBusMessageIter *iter)
4669 g_list_foreach(service_list, append_struct, iter);
4672 #if defined TIZEN_EXT_INS
4673 static void append_dict_ins_properties(DBusMessageIter *dict, void *user_data)
4675 struct connman_service *service = user_data;
4677 append_ins_properties(dict, service);
4680 static void append_ins_struct(gpointer value, gpointer user_data)
4682 struct connman_service *service = value;
4683 DBusMessageIter *iter = user_data;
4688 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
4691 append_struct_service(iter, append_dict_ins_properties, service);
4694 void __connman_ins_list_struct(DBusMessageIter *iter)
4696 g_list_foreach(service_list, append_ins_struct, iter);
4700 bool __connman_service_is_hidden(struct connman_service *service)
4702 return service->hidden;
4706 __connman_service_is_split_routing(struct connman_service *service)
4708 return service->do_split_routing;
4711 bool __connman_service_index_is_split_routing(int index)
4713 struct connman_service *service;
4718 service = __connman_service_lookup_from_index(index);
4722 return __connman_service_is_split_routing(service);
4725 int __connman_service_get_index(struct connman_service *service)
4730 if (service->network)
4731 return connman_network_get_index(service->network);
4732 else if (service->provider)
4733 return connman_provider_get_index(service->provider);
4738 void __connman_service_set_hidden(struct connman_service *service)
4740 if (!service || service->hidden)
4743 service->hidden_service = true;
4746 void __connman_service_set_hostname(struct connman_service *service,
4747 const char *hostname)
4749 if (!service || service->hidden)
4752 g_free(service->hostname);
4753 service->hostname = NULL;
4755 if (hostname && g_str_is_ascii(hostname))
4756 service->hostname = g_strdup(hostname);
4759 const char *__connman_service_get_hostname(struct connman_service *service)
4764 return service->hostname;
4767 void __connman_service_set_domainname(struct connman_service *service,
4768 const char *domainname)
4770 if (!service || service->hidden)
4773 g_free(service->domainname);
4774 service->domainname = NULL;
4776 if (domainname && g_str_is_ascii(domainname))
4777 service->domainname = g_strdup(domainname);
4779 domain_changed(service);
4782 const char *connman_service_get_domainname(struct connman_service *service)
4787 if (service->domains)
4788 return service->domains[0];
4790 return service->domainname;
4793 const char *connman_service_get_dbuspath(struct connman_service *service)
4798 return service->path;
4801 char **connman_service_get_nameservers(struct connman_service *service)
4806 if (service->nameservers_config)
4807 return g_strdupv(service->nameservers_config);
4808 else if (service->nameservers ||
4809 service->nameservers_auto) {
4810 int len = 0, len_auto = 0, i;
4813 if (service->nameservers)
4814 len = g_strv_length(service->nameservers);
4815 if (service->nameservers_auto)
4816 len_auto = g_strv_length(service->nameservers_auto);
4818 nameservers = g_try_new0(char *, len + len_auto + 1);
4822 for (i = 0; i < len; i++)
4823 nameservers[i] = g_strdup(service->nameservers[i]);
4825 for (i = 0; i < len_auto; i++)
4826 nameservers[i + len] =
4827 g_strdup(service->nameservers_auto[i]);
4832 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
4835 char **connman_service_get_timeservers_config(struct connman_service *service)
4840 return service->timeservers_config;
4843 char **connman_service_get_timeservers(struct connman_service *service)
4848 return service->timeservers;
4851 #if defined TIZEN_EXT
4853 * Description: Telephony plug-in requires manual PROXY setting function
4855 int connman_service_set_proxy(struct connman_service *service,
4856 const char *proxy, gboolean active)
4858 char **proxies_array = NULL;
4860 if (service == NULL)
4863 switch (service->type) {
4864 case CONNMAN_SERVICE_TYPE_CELLULAR:
4865 case CONNMAN_SERVICE_TYPE_ETHERNET:
4866 case CONNMAN_SERVICE_TYPE_WIFI:
4873 g_strfreev(service->proxies);
4874 service->proxies = NULL;
4877 proxies_array = g_strsplit(proxy, " ", 0);
4879 service->proxies = proxies_array;
4881 if (proxy == NULL) {
4882 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4883 DBG("proxy changed (%d)", active);
4885 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
4886 DBG("proxy chagned %s (%d)", proxy, active);
4889 if (active == TRUE) {
4890 proxy_changed(service);
4892 __connman_notifier_proxy_changed(service);
4899 void connman_service_set_proxy_method(struct connman_service *service,
4900 enum connman_service_proxy_method method)
4902 if (!service || service->hidden)
4905 service->proxy = method;
4907 proxy_changed(service);
4909 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
4910 __connman_notifier_proxy_changed(service);
4913 enum connman_service_proxy_method connman_service_get_proxy_method(
4914 struct connman_service *service)
4917 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
4919 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
4920 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
4922 return service->proxy;
4924 return service->proxy_config;
4927 return service->proxy;
4930 char **connman_service_get_proxy_servers(struct connman_service *service)
4932 return g_strdupv(service->proxies);
4935 char **connman_service_get_proxy_excludes(struct connman_service *service)
4937 return g_strdupv(service->excludes);
4940 const char *connman_service_get_proxy_url(struct connman_service *service)
4945 return service->pac;
4948 #if defined TIZEN_EXT
4949 void connman_service_set_internet_connection(struct connman_service *service,
4950 bool internet_connection)
4955 if (service->is_internet_connection != internet_connection) {
4956 service->is_internet_connection = internet_connection;
4958 g_get_current_time(&service->modified);
4959 service_save(service);
4963 bool connman_service_get_internet_connection(struct connman_service *service)
4968 return service->is_internet_connection;
4971 DBusMessage *connman_service_get_defaut_info(DBusMessage *msg,
4972 struct connman_service *service)
4975 DBusMessageIter array, dict;
4977 reply = dbus_message_new_method_return(msg);
4981 dbus_message_iter_init_append(reply, &array);
4984 dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
4987 connman_dbus_dict_open(&array, &dict);
4989 append_properties(&dict, FALSE, service);
4990 connman_dbus_dict_close(&array, &dict);
4996 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
4999 if (!service || service->hidden)
5002 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
5004 if (service->ipconfig_ipv4) {
5005 if (__connman_ipconfig_set_proxy_autoconfig(
5006 service->ipconfig_ipv4, url) < 0)
5008 } else if (service->ipconfig_ipv6) {
5009 if (__connman_ipconfig_set_proxy_autoconfig(
5010 service->ipconfig_ipv6, url) < 0)
5015 proxy_changed(service);
5017 __connman_notifier_proxy_changed(service);
5020 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
5025 if (service->ipconfig_ipv4)
5026 return __connman_ipconfig_get_proxy_autoconfig(
5027 service->ipconfig_ipv4);
5028 else if (service->ipconfig_ipv6)
5029 return __connman_ipconfig_get_proxy_autoconfig(
5030 service->ipconfig_ipv6);
5034 #if defined TIZEN_EXT
5035 int connman_service_get_ipv6_dns_method(struct connman_service *service)
5038 DBG("Service is NULL");
5042 return service->dns_config_method_ipv6;
5046 void __connman_service_set_timeservers(struct connman_service *service,
5054 g_strfreev(service->timeservers);
5055 service->timeservers = NULL;
5057 for (i = 0; timeservers && timeservers[i]; i++)
5058 __connman_service_timeserver_append(service, timeservers[i]);
5061 int __connman_service_timeserver_append(struct connman_service *service,
5062 const char *timeserver)
5066 DBG("service %p timeserver %s", service, timeserver);
5071 if (service->timeservers) {
5074 for (i = 0; service->timeservers[i]; i++)
5075 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
5078 len = g_strv_length(service->timeservers);
5079 service->timeservers = g_try_renew(char *, service->timeservers,
5083 service->timeservers = g_try_new0(char *, len + 2);
5086 if (!service->timeservers)
5089 service->timeservers[len] = g_strdup(timeserver);
5090 service->timeservers[len + 1] = NULL;
5095 int __connman_service_timeserver_remove(struct connman_service *service,
5096 const char *timeserver)
5099 int len, i, j, found = 0;
5101 DBG("service %p timeserver %s", service, timeserver);
5106 if (!service->timeservers)
5109 for (i = 0; service->timeservers &&
5110 service->timeservers[i]; i++)
5111 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
5119 len = g_strv_length(service->timeservers);
5122 g_strfreev(service->timeservers);
5123 service->timeservers = NULL;
5128 servers = g_try_new0(char *, len);
5132 for (i = 0, j = 0; i < len; i++) {
5133 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
5134 servers[j] = g_strdup(service->timeservers[i]);
5140 servers[len - 1] = NULL;
5142 g_strfreev(service->timeservers);
5143 service->timeservers = servers;
5148 void __connman_service_timeserver_changed(struct connman_service *service,
5154 if (!allow_property_changed(service))
5157 connman_dbus_property_changed_array(service->path,
5158 CONNMAN_SERVICE_INTERFACE, "Timeservers",
5159 DBUS_TYPE_STRING, append_ts, ts_list);
5162 void __connman_service_set_pac(struct connman_service *service,
5165 if (service->hidden)
5167 g_free(service->pac);
5168 service->pac = g_strdup(pac);
5170 proxy_changed(service);
5173 #if defined TIZEN_EXT
5174 void __connman_service_set_proxy(struct connman_service *service,
5175 const char *proxies)
5177 char **proxies_array = NULL;
5179 g_strfreev(service->proxies);
5180 service->proxies = NULL;
5182 if (proxies != NULL)
5183 proxies_array = g_strsplit(proxies, " ", 0);
5185 service->proxies = proxies_array;
5189 void __connman_service_set_identity(struct connman_service *service,
5190 const char *identity)
5192 if (service->immutable || service->hidden)
5195 g_free(service->identity);
5196 service->identity = g_strdup(identity);
5198 if (service->network)
5199 connman_network_set_string(service->network,
5204 void __connman_service_set_anonymous_identity(struct connman_service *service,
5205 const char *anonymous_identity)
5207 if (service->immutable || service->hidden)
5210 g_free(service->anonymous_identity);
5211 service->anonymous_identity = g_strdup(anonymous_identity);
5213 if (service->network)
5214 connman_network_set_string(service->network,
5215 "WiFi.AnonymousIdentity",
5216 service->anonymous_identity);
5219 void __connman_service_set_subject_match(struct connman_service *service,
5220 const char *subject_match)
5222 if (service->immutable || service->hidden)
5225 g_free(service->subject_match);
5226 service->subject_match = g_strdup(subject_match);
5228 if (service->network)
5229 connman_network_set_string(service->network,
5230 "WiFi.SubjectMatch",
5231 service->subject_match);
5234 void __connman_service_set_altsubject_match(struct connman_service *service,
5235 const char *altsubject_match)
5237 if (service->immutable || service->hidden)
5240 g_free(service->altsubject_match);
5241 service->altsubject_match = g_strdup(altsubject_match);
5243 if (service->network)
5244 connman_network_set_string(service->network,
5245 "WiFi.AltSubjectMatch",
5246 service->altsubject_match);
5249 void __connman_service_set_domain_suffix_match(struct connman_service *service,
5250 const char *domain_suffix_match)
5252 if (service->immutable || service->hidden)
5255 g_free(service->domain_suffix_match);
5256 service->domain_suffix_match = g_strdup(domain_suffix_match);
5258 if (service->network)
5259 connman_network_set_string(service->network,
5260 "WiFi.DomainSuffixMatch",
5261 service->domain_suffix_match);
5264 void __connman_service_set_domain_match(struct connman_service *service,
5265 const char *domain_match)
5267 if (service->immutable || service->hidden)
5270 g_free(service->domain_match);
5271 service->domain_match = g_strdup(domain_match);
5273 if (service->network)
5274 connman_network_set_string(service->network,
5276 service->domain_match);
5279 void __connman_service_set_agent_identity(struct connman_service *service,
5280 const char *agent_identity)
5282 if (service->hidden)
5284 g_free(service->agent_identity);
5285 service->agent_identity = g_strdup(agent_identity);
5287 if (service->network)
5288 connman_network_set_string(service->network,
5289 "WiFi.AgentIdentity",
5290 service->agent_identity);
5293 int __connman_service_check_passphrase(enum connman_service_security security,
5294 const char *passphrase)
5302 length = strlen(passphrase);
5305 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
5306 case CONNMAN_SERVICE_SECURITY_NONE:
5307 case CONNMAN_SERVICE_SECURITY_WPA:
5308 #if !defined TIZEN_EXT
5309 case CONNMAN_SERVICE_SECURITY_RSN:
5312 DBG("service security '%s' (%d) not handled",
5313 security2string(security), security);
5317 case CONNMAN_SERVICE_SECURITY_PSK:
5318 #if defined TIZEN_EXT
5319 case CONNMAN_SERVICE_SECURITY_RSN:
5320 /* TO CHECK: We need to check the key length supported by SAE */
5321 case CONNMAN_SERVICE_SECURITY_SAE:
5323 /* A raw key is always 64 bytes length,
5324 * its content is in hex representation.
5325 * A PSK key must be between [8..63].
5328 for (i = 0; i < 64; i++)
5329 if (!isxdigit((unsigned char)
5332 } else if (length < 8 || length > 63)
5335 case CONNMAN_SERVICE_SECURITY_WEP:
5336 /* length of WEP key is 10 or 26
5337 * length of WEP passphrase is 5 or 13
5339 if (length == 10 || length == 26) {
5340 for (i = 0; i < length; i++)
5341 if (!isxdigit((unsigned char)
5344 } else if (length != 5 && length != 13)
5348 case CONNMAN_SERVICE_SECURITY_8021X:
5349 #if defined TIZEN_EXT
5350 case CONNMAN_SERVICE_SECURITY_OWE:
5351 case CONNMAN_SERVICE_SECURITY_DPP:
5359 int __connman_service_set_passphrase(struct connman_service *service,
5360 const char *passphrase)
5364 if (service->hidden)
5367 if (service->immutable &&
5368 service->security != CONNMAN_SERVICE_SECURITY_8021X)
5371 #if defined TIZEN_EXT
5372 if (service->immutable &&
5373 service->security != CONNMAN_SERVICE_SECURITY_DPP)
5375 /* The encrypted passphrase is used here
5376 * and validation is done by net-config before being encrypted.
5379 if (service->security != CONNMAN_SERVICE_SECURITY_PSK &&
5380 service->security != CONNMAN_SERVICE_SECURITY_RSN &&
5381 service->security != CONNMAN_SERVICE_SECURITY_SAE &&
5382 service->security != CONNMAN_SERVICE_SECURITY_WEP)
5384 err = __connman_service_check_passphrase(service->security, passphrase);
5389 g_free(service->passphrase);
5390 service->passphrase = g_strdup(passphrase);
5392 if (service->network)
5393 connman_network_set_string(service->network, "WiFi.Passphrase",
5394 service->passphrase);
5399 const char *__connman_service_get_passphrase(struct connman_service *service)
5404 return service->passphrase;
5407 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5408 int __connman_service_get_use_eapol(struct connman_service *service)
5411 DBG("Service is NULL");
5415 return service->use_eapol;
5418 int __connman_service_get_connect_reason(struct connman_service *service)
5421 DBG("Service is NULL");
5425 return service->connect_reason;
5427 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5429 static DBusMessage *get_properties(DBusConnection *conn,
5430 DBusMessage *msg, void *user_data)
5432 struct connman_service *service = user_data;
5434 DBusMessageIter array, dict;
5436 reply = dbus_message_new_method_return(msg);
5440 dbus_message_iter_init_append(reply, &array);
5442 connman_dbus_dict_open(&array, &dict);
5443 append_properties(&dict, FALSE, service);
5444 connman_dbus_dict_close(&array, &dict);
5449 static char **remove_empty_strings(char **strv)
5456 strv[index++] = *iter;
5466 static int update_proxy_configuration(struct connman_service *service,
5467 DBusMessageIter *array)
5469 DBusMessageIter dict;
5470 enum connman_service_proxy_method method;
5471 GString *servers_str = NULL;
5472 GString *excludes_str = NULL;
5473 const char *url = NULL;
5475 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
5477 dbus_message_iter_recurse(array, &dict);
5479 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
5480 DBusMessageIter entry, variant;
5484 dbus_message_iter_recurse(&dict, &entry);
5486 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
5489 dbus_message_iter_get_basic(&entry, &key);
5490 dbus_message_iter_next(&entry);
5492 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
5495 dbus_message_iter_recurse(&entry, &variant);
5497 type = dbus_message_iter_get_arg_type(&variant);
5499 if (g_str_equal(key, "Method")) {
5502 if (type != DBUS_TYPE_STRING)
5505 dbus_message_iter_get_basic(&variant, &val);
5506 method = string2proxymethod(val);
5507 } else if (g_str_equal(key, "URL")) {
5508 if (type != DBUS_TYPE_STRING)
5511 dbus_message_iter_get_basic(&variant, &url);
5512 } else if (g_str_equal(key, "Servers")) {
5513 DBusMessageIter str_array;
5515 if (type != DBUS_TYPE_ARRAY)
5518 servers_str = g_string_new(NULL);
5522 dbus_message_iter_recurse(&variant, &str_array);
5524 while (dbus_message_iter_get_arg_type(&str_array) ==
5528 dbus_message_iter_get_basic(&str_array, &val);
5530 if (servers_str->len > 0)
5531 g_string_append_printf(servers_str,
5534 g_string_append(servers_str, val);
5536 dbus_message_iter_next(&str_array);
5538 } else if (g_str_equal(key, "Excludes")) {
5539 DBusMessageIter str_array;
5541 if (type != DBUS_TYPE_ARRAY)
5544 excludes_str = g_string_new(NULL);
5548 dbus_message_iter_recurse(&variant, &str_array);
5550 while (dbus_message_iter_get_arg_type(&str_array) ==
5554 dbus_message_iter_get_basic(&str_array, &val);
5556 if (excludes_str->len > 0)
5557 g_string_append_printf(excludes_str,
5560 g_string_append(excludes_str, val);
5562 dbus_message_iter_next(&str_array);
5566 dbus_message_iter_next(&dict);
5570 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
5572 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
5573 if (!servers_str && !service->proxies)
5577 g_strfreev(service->proxies);
5579 if (servers_str->len > 0) {
5580 char **proxies = g_strsplit_set(
5581 servers_str->str, " ", 0);
5582 proxies = remove_empty_strings(proxies);
5583 service->proxies = proxies;
5585 service->proxies = NULL;
5589 g_strfreev(service->excludes);
5591 if (excludes_str->len > 0) {
5592 char **excludes = g_strsplit_set(
5593 excludes_str->str, " ", 0);
5594 excludes = remove_empty_strings(excludes);
5595 service->excludes = excludes;
5597 service->excludes = NULL;
5600 if (!service->proxies)
5601 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
5604 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
5605 g_free(service->pac);
5607 if (url && strlen(url) > 0)
5608 service->pac = g_strstrip(g_strdup(url));
5610 service->pac = NULL;
5612 /* if we are connected:
5613 - if service->pac == NULL
5614 - if __connman_ipconfig_get_proxy_autoconfig(
5615 service->ipconfig) == NULL
5616 --> We should start WPAD */
5619 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
5624 g_string_free(servers_str, TRUE);
5627 g_string_free(excludes_str, TRUE);
5629 service->proxy_config = method;
5635 g_string_free(servers_str, TRUE);
5638 g_string_free(excludes_str, TRUE);
5643 static void do_auto_connect(struct connman_service *service,
5644 enum connman_service_connect_reason reason)
5647 * CONNMAN_SERVICE_CONNECT_REASON_NONE must be ignored for VPNs. VPNs
5648 * always have reason CONNMAN_SERVICE_CONNECT_REASON_USER/AUTO.
5650 if (!service || (service->type == CONNMAN_SERVICE_TYPE_VPN &&
5651 reason == CONNMAN_SERVICE_CONNECT_REASON_NONE))
5655 * Run service auto connect for other than VPN services. Afterwards
5656 * start also VPN auto connect process.
5658 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
5659 __connman_service_auto_connect(reason);
5660 /* Only user interaction should get VPN connected in failure state. */
5661 else if (service->state == CONNMAN_SERVICE_STATE_FAILURE &&
5662 reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
5668 int __connman_service_reset_ipconfig(struct connman_service *service,
5669 enum connman_ipconfig_type type, DBusMessageIter *array,
5670 enum connman_service_state *new_state)
5672 struct connman_ipconfig *ipconfig, *new_ipconfig;
5673 enum connman_ipconfig_method old_method, new_method;
5674 enum connman_service_state state;
5677 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
5678 ipconfig = service->ipconfig_ipv4;
5679 state = service->state_ipv4;
5680 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
5681 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
5682 ipconfig = service->ipconfig_ipv6;
5683 state = service->state_ipv6;
5684 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
5691 old_method = __connman_ipconfig_get_method(ipconfig);
5692 index = __connman_ipconfig_get_index(ipconfig);
5694 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
5695 new_ipconfig = create_ip4config(service, index,
5696 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
5698 new_ipconfig = create_ip6config(service, index);
5701 err = __connman_ipconfig_set_config(new_ipconfig, array);
5703 __connman_ipconfig_unref(new_ipconfig);
5707 new_method = __connman_ipconfig_get_method(new_ipconfig);
5710 if (is_connecting(state) || is_connected(state))
5711 __connman_network_clear_ipconfig(service->network, ipconfig);
5713 __connman_ipconfig_unref(ipconfig);
5715 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
5716 service->ipconfig_ipv4 = new_ipconfig;
5717 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
5718 service->ipconfig_ipv6 = new_ipconfig;
5720 if (is_connecting(state) || is_connected(state))
5721 __connman_ipconfig_enable(new_ipconfig);
5723 if (new_state && new_method != old_method) {
5724 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
5725 *new_state = service->state_ipv4;
5727 *new_state = service->state_ipv6;
5729 settings_changed(service, new_ipconfig);
5730 address_updated(service, type);
5732 do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5735 DBG("err %d ipconfig %p type %d method %d state %s", err,
5736 new_ipconfig, type, new_method,
5737 !new_state ? "-" : state2string(*new_state));
5743 * We set the timeout to 1 sec so that we have a chance to get
5744 * necessary IPv6 router advertisement messages that might have
5747 #define ONLINE_CHECK_INITIAL_INTERVAL 1
5748 #define ONLINE_CHECK_MAX_INTERVAL 12
5750 void __connman_service_wispr_start(struct connman_service *service,
5751 enum connman_ipconfig_type type)
5753 DBG("service %p type %s", service, __connman_ipconfig_type2string(type));
5755 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
5756 service->online_check_interval_ipv4 =
5757 ONLINE_CHECK_INITIAL_INTERVAL;
5759 service->online_check_interval_ipv6 =
5760 ONLINE_CHECK_INITIAL_INTERVAL;
5762 __connman_wispr_start(service, type);
5765 static void set_error(struct connman_service *service,
5766 enum connman_service_error error);
5768 static DBusMessage *set_property(DBusConnection *conn,
5769 DBusMessage *msg, void *user_data)
5771 struct connman_service *service = user_data;
5772 DBusMessageIter iter, value;
5776 DBG("service %p", service);
5778 if (!dbus_message_iter_init(msg, &iter))
5779 return __connman_error_invalid_arguments(msg);
5781 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
5782 return __connman_error_invalid_arguments(msg);
5784 dbus_message_iter_get_basic(&iter, &name);
5785 dbus_message_iter_next(&iter);
5787 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
5788 return __connman_error_invalid_arguments(msg);
5790 dbus_message_iter_recurse(&iter, &value);
5792 type = dbus_message_iter_get_arg_type(&value);
5794 if (g_str_equal(name, "AutoConnect")) {
5795 dbus_bool_t autoconnect;
5797 if (type != DBUS_TYPE_BOOLEAN)
5798 return __connman_error_invalid_arguments(msg);
5800 if (!service->favorite)
5801 return __connman_error_invalid_service(msg);
5803 dbus_message_iter_get_basic(&value, &autoconnect);
5805 if (autoconnect && service->type == CONNMAN_SERVICE_TYPE_VPN) {
5807 * Changing the autoconnect flag on VPN to "on" should
5808 * have the same effect as user connecting the VPN =
5809 * clear previous error and change state to idle.
5811 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
5813 if (service->state == CONNMAN_SERVICE_STATE_FAILURE) {
5814 service->state = CONNMAN_SERVICE_STATE_IDLE;
5815 state_changed(service);
5819 if (connman_service_set_autoconnect(service, autoconnect)) {
5820 service_save(service);
5822 do_auto_connect(service,
5823 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5825 } else if (g_str_equal(name, "Nameservers.Configuration")) {
5826 DBusMessageIter entry;
5830 #if defined TIZEN_EXT
5831 enum connman_ipconfig_type ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
5835 if (__connman_provider_is_immutable(service->provider) ||
5837 return __connman_error_not_supported(msg);
5839 if (type != DBUS_TYPE_ARRAY)
5840 return __connman_error_invalid_arguments(msg);
5842 str = g_string_new(NULL);
5844 return __connman_error_invalid_arguments(msg);
5846 index = __connman_service_get_index(service);
5847 gw = __connman_ipconfig_get_gateway_from_index(index,
5848 CONNMAN_IPCONFIG_TYPE_ALL);
5850 #if !defined TIZEN_EXT
5851 if (gw && strlen(gw))
5852 __connman_service_nameserver_del_routes(service,
5853 CONNMAN_IPCONFIG_TYPE_ALL);
5856 dbus_message_iter_recurse(&value, &entry);
5858 #if defined TIZEN_EXT
5859 /* IPv4/IPv6 Last DNS config method */
5860 int last_dns_ipv4 = service->dns_config_method_ipv4;
5861 int last_dns_ipv6 = service->dns_config_method_ipv6;
5862 DBG("Last DNS Config Method IPv4: %d IPv6: %d", last_dns_ipv4, last_dns_ipv6);
5865 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
5867 dbus_message_iter_get_basic(&entry, &val);
5868 dbus_message_iter_next(&entry);
5870 /* First unpack the DNS Config Method */
5871 DBG("DNS Config Method: %s", val);
5872 if((g_strcmp0(val, "ipv4.manual") == 0)) {
5873 service->dns_config_method_ipv4 =
5874 CONNMAN_DNSCONFIG_METHOD_MANUAL;
5876 if(last_dns_ipv4 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
5877 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
5878 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
5880 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
5883 } else if(g_strcmp0(val, "ipv4.dhcp") == 0) {
5884 service->dns_config_method_ipv4 =
5885 CONNMAN_DNSCONFIG_METHOD_DHCP;
5886 if(last_dns_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
5887 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
5890 } else if(g_strcmp0(val, "ipv6.manual") == 0) {
5891 service->dns_config_method_ipv6 =
5892 CONNMAN_DNSCONFIG_METHOD_MANUAL;
5893 if(last_dns_ipv6 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
5894 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
5895 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
5897 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
5900 } else if(g_strcmp0(val, "ipv6.dhcp") == 0) {
5901 service->dns_config_method_ipv6 =
5902 CONNMAN_DNSCONFIG_METHOD_DHCP;
5903 if(last_dns_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
5904 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
5913 g_string_append_printf(str, " %s", val);
5915 g_string_append(str, val);
5918 #if defined TIZEN_EXT
5919 if (service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_DHCP &&
5920 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_DHCP) {
5921 DBG("Both IPv4 and IPv6 DNS Method DHCP");
5922 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
5924 if (gw && strlen(gw))
5925 __connman_service_nameserver_del_routes(service,
5928 DBG("%s ip_type: %d nameserver remove all", name, ip_type);
5929 nameserver_remove_all(service, ip_type);
5931 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
5933 g_strfreev(service->nameservers_config);
5936 char **nameservers, **iter;
5938 nameservers = g_strsplit_set(str->str, " ", 0);
5940 for (iter = nameservers; *iter; iter++)
5941 if (connman_inet_check_ipaddress(*iter) <= 0)
5944 nameservers = remove_empty_strings(nameservers);
5945 service->nameservers_config = nameservers;
5947 service->nameservers_config = NULL;
5950 g_string_free(str, TRUE);
5952 if (gw && strlen(gw))
5953 __connman_service_nameserver_add_routes(service, gw);
5955 #if defined TIZEN_EXT
5956 DBG("%s ip_type: %d nameserver add all", name, ip_type);
5957 nameserver_add_all(service, ip_type);
5959 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
5961 dns_configuration_changed(service);
5963 if (__connman_service_is_connected_state(service,
5964 CONNMAN_IPCONFIG_TYPE_IPV4))
5965 __connman_service_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
5967 if (__connman_service_is_connected_state(service,
5968 CONNMAN_IPCONFIG_TYPE_IPV6))
5969 __connman_service_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
5971 service_save(service);
5972 } else if (g_str_equal(name, "Timeservers.Configuration")) {
5973 DBusMessageIter entry;
5976 if (service->immutable)
5977 return __connman_error_not_supported(msg);
5979 if (type != DBUS_TYPE_ARRAY)
5980 return __connman_error_invalid_arguments(msg);
5982 str = g_string_new(NULL);
5984 return __connman_error_invalid_arguments(msg);
5986 dbus_message_iter_recurse(&value, &entry);
5988 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
5990 dbus_message_iter_get_basic(&entry, &val);
5991 dbus_message_iter_next(&entry);
5997 g_string_append_printf(str, " %s", val);
5999 g_string_append(str, val);
6002 g_strfreev(service->timeservers_config);
6003 service->timeservers_config = NULL;
6006 char **timeservers = g_strsplit_set(str->str, " ", 0);
6007 timeservers = remove_empty_strings(timeservers);
6008 service->timeservers_config = timeservers;
6011 g_string_free(str, TRUE);
6013 service_save(service);
6014 timeservers_configuration_changed(service);
6016 if (service == connman_service_get_default())
6017 __connman_timeserver_sync(service);
6019 } else if (g_str_equal(name, "Domains.Configuration")) {
6020 DBusMessageIter entry;
6023 if (service->immutable)
6024 return __connman_error_not_supported(msg);
6026 if (type != DBUS_TYPE_ARRAY)
6027 return __connman_error_invalid_arguments(msg);
6029 str = g_string_new(NULL);
6031 return __connman_error_invalid_arguments(msg);
6033 dbus_message_iter_recurse(&value, &entry);
6035 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
6037 dbus_message_iter_get_basic(&entry, &val);
6038 dbus_message_iter_next(&entry);
6044 g_string_append_printf(str, " %s", val);
6046 g_string_append(str, val);
6049 searchdomain_remove_all(service);
6050 g_strfreev(service->domains);
6053 char **domains = g_strsplit_set(str->str, " ", 0);
6054 domains = remove_empty_strings(domains);
6055 service->domains = domains;
6057 service->domains = NULL;
6059 g_string_free(str, TRUE);
6061 searchdomain_add_all(service);
6062 domain_configuration_changed(service);
6063 domain_changed(service);
6065 service_save(service);
6066 } else if (g_str_equal(name, "Proxy.Configuration")) {
6069 if (service->immutable)
6070 return __connman_error_not_supported(msg);
6072 if (type != DBUS_TYPE_ARRAY)
6073 return __connman_error_invalid_arguments(msg);
6075 err = update_proxy_configuration(service, &value);
6078 return __connman_error_failed(msg, -err);
6080 proxy_configuration_changed(service);
6082 __connman_notifier_proxy_changed(service);
6084 service_save(service);
6085 } else if (g_str_equal(name, "mDNS.Configuration")) {
6088 if (service->immutable)
6089 return __connman_error_not_supported(msg);
6091 if (type != DBUS_TYPE_BOOLEAN)
6092 return __connman_error_invalid_arguments(msg);
6094 dbus_message_iter_get_basic(&value, &val);
6095 service->mdns_config = val;
6097 mdns_configuration_changed(service);
6099 set_mdns(service, service->mdns_config);
6101 service_save(service);
6102 } else if (g_str_equal(name, "IPv4.Configuration") ||
6103 g_str_equal(name, "IPv6.Configuration")) {
6105 enum connman_service_state state =
6106 CONNMAN_SERVICE_STATE_UNKNOWN;
6107 enum connman_ipconfig_type type =
6108 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
6111 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
6113 return __connman_error_not_supported(msg);
6117 if (!service->ipconfig_ipv4 &&
6118 !service->ipconfig_ipv6)
6119 return __connman_error_invalid_property(msg);
6121 if (g_str_equal(name, "IPv4.Configuration"))
6122 type = CONNMAN_IPCONFIG_TYPE_IPV4;
6124 type = CONNMAN_IPCONFIG_TYPE_IPV6;
6126 err = __connman_service_reset_ipconfig(service, type, &value,
6130 if (is_connected(state) || is_connecting(state)) {
6131 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6132 __connman_network_enable_ipconfig(service->network,
6133 service->ipconfig_ipv4);
6135 __connman_network_enable_ipconfig(service->network,
6136 service->ipconfig_ipv6);
6139 return __connman_error_failed(msg, -err);
6142 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6143 ipv4_configuration_changed(service);
6145 ipv6_configuration_changed(service);
6147 if (is_connecting(service->state) ||
6148 is_connected(service->state)) {
6149 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6150 __connman_network_enable_ipconfig(service->network,
6151 service->ipconfig_ipv4);
6153 __connman_network_enable_ipconfig(service->network,
6154 service->ipconfig_ipv6);
6157 service_save(service);
6158 #if defined TIZEN_EXT
6159 /* When AP is connected using WPS without SSID then its password needs
6160 * to be saved for autoconnection */
6161 } else if (g_str_equal(name, "Passphrase")) {
6164 if (type != DBUS_TYPE_STRING)
6165 return __connman_error_invalid_arguments(msg);
6167 dbus_message_iter_get_basic(&value, &passphrase);
6169 __connman_service_set_passphrase(service, passphrase);
6171 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
6172 } else if (g_str_equal(name, "EapOverEthernet")) {
6173 int err = connman_service_set_eapol_property(service, &value);
6175 return __connman_error_failed(msg, -err);
6177 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
6178 service_save(service);
6179 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
6181 return __connman_error_invalid_property(msg);
6183 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
6186 static void set_error(struct connman_service *service,
6187 enum connman_service_error error)
6191 if (service->error == error)
6194 service->error = error;
6199 #if !defined TIZEN_EXT
6200 if (!allow_property_changed(service))
6204 str = error2string(service->error);
6209 connman_dbus_property_changed_basic(service->path,
6210 CONNMAN_SERVICE_INTERFACE, "Error",
6211 DBUS_TYPE_STRING, &str);
6214 static void remove_timeout(struct connman_service *service)
6216 if (service->timeout > 0) {
6217 g_source_remove(service->timeout);
6218 service->timeout = 0;
6222 static void reply_pending(struct connman_service *service, int error)
6224 remove_timeout(service);
6226 if (service->pending) {
6227 connman_dbus_reply_pending(service->pending, error, NULL);
6228 service->pending = NULL;
6231 if (service->provider_pending) {
6232 connman_dbus_reply_pending(service->provider_pending,
6233 error, service->path);
6234 service->provider_pending = NULL;
6238 static void service_complete(struct connman_service *service)
6240 reply_pending(service, EIO);
6242 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
6243 do_auto_connect(service, service->connect_reason);
6245 gettimeofday(&service->modified, NULL);
6246 service_save(service);
6249 static DBusMessage *clear_property(DBusConnection *conn,
6250 DBusMessage *msg, void *user_data)
6252 struct connman_service *service = user_data;
6255 DBG("service %p", service);
6257 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
6260 if (g_str_equal(name, "Error")) {
6261 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6263 __connman_service_clear_error(service);
6264 service_complete(service);
6266 return __connman_error_invalid_property(msg);
6268 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
6271 static bool is_ipconfig_usable(struct connman_service *service)
6273 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
6274 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
6280 static bool is_ignore(struct connman_service *service)
6282 if (!service->autoconnect)
6285 if (service->roaming &&
6286 !connman_setting_get_bool("AutoConnectRoamingServices"))
6289 if (service->ignore)
6292 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
6295 if (!is_ipconfig_usable(service))
6301 static void disconnect_on_last_session(enum connman_service_type type)
6305 for (list = service_list; list; list = list->next) {
6306 struct connman_service *service = list->data;
6308 if (service->type != type)
6311 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
6314 __connman_service_disconnect(service);
6319 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
6320 static int always_connect[MAX_CONNMAN_SERVICE_TYPES] = {};
6321 static int active_count = 0;
6323 void __connman_service_set_active_session(bool enable, GSList *list)
6334 enum connman_service_type type = GPOINTER_TO_INT(list->data);
6337 case CONNMAN_SERVICE_TYPE_ETHERNET:
6338 case CONNMAN_SERVICE_TYPE_WIFI:
6339 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
6340 case CONNMAN_SERVICE_TYPE_CELLULAR:
6341 case CONNMAN_SERVICE_TYPE_GADGET:
6343 active_sessions[type]++;
6345 active_sessions[type]--;
6348 case CONNMAN_SERVICE_TYPE_UNKNOWN:
6349 case CONNMAN_SERVICE_TYPE_SYSTEM:
6350 case CONNMAN_SERVICE_TYPE_GPS:
6351 case CONNMAN_SERVICE_TYPE_VPN:
6352 case CONNMAN_SERVICE_TYPE_P2P:
6353 #if defined TIZEN_EXT_WIFI_MESH
6354 case CONNMAN_SERVICE_TYPE_MESH:
6359 if (active_sessions[type] == 0)
6360 disconnect_on_last_session(type);
6362 list = g_slist_next(list);
6365 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
6366 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
6367 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
6368 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
6369 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
6370 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
6374 struct preferred_tech_data {
6375 GList *preferred_list;
6376 enum connman_service_type type;
6379 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
6381 struct connman_service *service = data;
6382 struct preferred_tech_data *tech_data = user_data;
6384 if (service->type == tech_data->type) {
6385 tech_data->preferred_list =
6386 g_list_append(tech_data->preferred_list, service);
6388 #if defined TIZEN_EXT
6389 if (!simplified_log)
6391 DBG("type %d service %p %s", tech_data->type, service,
6396 static GList *preferred_tech_list_get(void)
6398 unsigned int *tech_array;
6399 struct preferred_tech_data tech_data = { 0, };
6402 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
6406 if (connman_setting_get_bool("SingleConnectedTechnology")) {
6408 for (list = service_list; list; list = list->next) {
6409 struct connman_service *service = list->data;
6411 if (!is_connected(service->state))
6414 if (service->connect_reason ==
6415 CONNMAN_SERVICE_CONNECT_REASON_USER) {
6416 DBG("service %p name %s is user connected",
6417 service, service->name);
6418 #if defined TIZEN_EXT
6419 /* We can connect to a favorite service like
6420 * wifi even we have a userconnect for cellular
6421 * because we have refount for cellular service
6423 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6426 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6434 for (i = 0; tech_array[i] != 0; i += 1) {
6435 tech_data.type = tech_array[i];
6436 g_list_foreach(service_list, preferred_tech_add_by_type,
6440 return tech_data.preferred_list;
6443 static void set_always_connecting_technologies()
6445 unsigned int *always_connected_techs =
6446 connman_setting_get_uint_list("AlwaysConnectedTechnologies");
6448 for (i = 0; always_connected_techs && always_connected_techs[i]; i++)
6449 always_connect[always_connected_techs[i]] = 1;
6452 static bool autoconnect_no_session_active(struct connman_service *service)
6455 * Test active_count to see if there are no sessions set up and
6456 * stop autoconnecting, but continue connecting if the service
6457 * belongs to a technology which should always autoconnect.
6459 if (!active_count && !always_connect[service->type])
6465 static bool autoconnect_already_connecting(struct connman_service *service,
6466 bool autoconnecting)
6469 * If another service is already connecting and this service type has
6470 * not been marked as always connecting, stop the connecting procedure.
6472 if (autoconnecting &&
6473 !active_sessions[service->type] &&
6474 !always_connect[service->type])
6480 static int service_indicate_state(struct connman_service *service);
6482 static bool auto_connect_service(GList *services,
6483 enum connman_service_connect_reason reason,
6486 struct connman_service *service = NULL;
6487 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
6488 bool autoconnecting = false;
6490 #if defined TIZEN_EXT
6491 GSList *wifi_ignore = NULL;
6494 DBG("preferred %d sessions %d reason %s", preferred, active_count,
6495 reason2string(reason));
6497 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
6499 #if defined TIZEN_EXT_WIFI_MESH
6500 /* Don't auto connect wifi if mesh interface is created */
6501 if (connman_mesh_is_interface_created())
6502 ignore[CONNMAN_SERVICE_TYPE_WIFI] = true;
6505 for (list = services; list; list = list->next) {
6506 service = list->data;
6508 #if defined TIZEN_EXT
6509 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
6510 int index = connman_network_get_index(service->network);
6511 if (g_slist_find(wifi_ignore, GINT_TO_POINTER(index)) != NULL)
6515 if (ignore[service->type]) {
6516 DBG("service %p type %s ignore", service,
6517 __connman_service_type2string(service->type));
6521 #if defined TIZEN_EXT
6522 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
6523 service, service->name,
6524 state2string(service->state),
6525 __connman_service_type2string(service->type),
6526 service->favorite, is_ignore(service),
6527 service->hidden, service->hidden_service);
6529 /* Tizen takes Wi-Fi as the highest priority into consideration. */
6530 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
6531 if (is_connecting(service->state) == TRUE || is_connected(service->state) == TRUE)
6535 if (service->pending ||
6536 is_connecting(service->state) ||
6537 is_connected(service->state)) {
6538 #if defined TIZEN_EXT
6539 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
6540 int index = connman_network_get_index(service->network);
6541 wifi_ignore = g_slist_prepend(wifi_ignore, GINT_TO_POINTER(index));
6543 autoconnecting = true;
6547 if (autoconnect_no_session_active(service))
6550 ignore[service->type] = true;
6551 autoconnecting = true;
6553 DBG("service %p type %s busy", service,
6554 __connman_service_type2string(service->type));
6559 if (!service->favorite) {
6563 #if defined TIZEN_EXT
6564 DBG("Service is not favorite, autoconnecting %d",
6566 g_slist_free(wifi_ignore);
6568 return autoconnecting;
6571 #if defined TIZEN_EXT
6572 DBG("service %p identifier %s roaming %d ignore %d "
6573 "ipconfig_usable %d autoconnect %d state %d",
6575 service->identifier, service->roaming,
6576 service->ignore, is_ipconfig_usable(service),
6577 service->autoconnect, service->state);
6579 if (is_ignore(service) || service->state !=
6580 CONNMAN_SERVICE_STATE_IDLE)
6582 #if defined TIZEN_EXT
6583 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
6585 if (autoconnect_already_connecting(service, autoconnecting)) {
6586 DBG("service %p type %s has no users", service,
6587 __connman_service_type2string(service->type));
6591 DBG("service %p %s %s", service, service->name,
6592 (preferred) ? "preferred" : reason2string(reason));
6594 #if defined TIZEN_EXT
6595 __connman_service_connect(service, reason);
6597 if (__connman_service_connect(service, reason) == 0)
6598 service_indicate_state(service);
6600 if (autoconnect_no_session_active(service))
6603 #if defined TIZEN_EXT
6604 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
6605 int index = connman_network_get_index(service->network);
6606 wifi_ignore = g_slist_prepend(wifi_ignore, GINT_TO_POINTER(index));
6607 autoconnecting = true;
6610 ignore[service->type] = true;
6612 #if defined TIZEN_EXT
6613 g_slist_free(wifi_ignore);
6615 return autoconnecting;
6618 static gboolean run_auto_connect(gpointer data)
6620 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
6621 bool autoconnecting = false;
6622 GList *preferred_tech;
6628 preferred_tech = preferred_tech_list_get();
6629 if (preferred_tech) {
6630 autoconnecting = auto_connect_service(preferred_tech, reason,
6632 g_list_free(preferred_tech);
6635 if (!autoconnecting || active_count)
6636 auto_connect_service(service_list, reason, false);
6641 #if defined TIZEN_EXT
6642 bool __connman_service_get_auto_connect_mode(void)
6644 return auto_connect_mode;
6647 void __connman_service_set_auto_connect_mode(bool enable)
6649 DBG("set auto_connect_mode = %d", enable);
6651 if (auto_connect_mode != enable)
6652 auto_connect_mode = enable;
6656 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
6660 if (autoconnect_id != 0)
6663 #if defined TIZEN_EXT
6664 if (auto_connect_mode == FALSE) {
6665 DBG("Currently, not auto connection mode");
6670 if (!__connman_session_policy_autoconnect(reason))
6673 #if defined TIZEN_EXT
6674 /* Adding Timeout of 500ms before trying to auto connect.
6675 * This is done because of below scenario
6676 * 1. Device is connected to AP1
6677 * 2. WPS Connection request is initiated for AP2
6678 * 3. Immediately WPS Connection is Cancelled
6679 * When WPS Connection Connection is initiated for AP2 then
6680 * sometimes there is a scenario where connman gets in ASSOCIATED
6681 * state with AP1 due to autoconnect and subsequently the connection
6682 * initiated by AP1 fails and connman service for AP1 comes in
6683 * FAILURE state due to this when connection with AP2 is cancelled
6684 * then autoconnect with AP1 doesn't works because its autoconnection
6685 * is ignored as its last state was FAILURE rather than IDLE */
6686 autoconnect_id = g_timeout_add(500, run_auto_connect,
6688 autoconnect_id = g_idle_add(run_auto_connect,
6690 GUINT_TO_POINTER(reason));
6693 static gboolean run_vpn_auto_connect(gpointer data) {
6695 bool need_split = false;
6696 bool autoconnectable_vpns = false;
6698 int timeout = VPN_AUTOCONNECT_TIMEOUT_DEFAULT;
6699 struct connman_service *def_service;
6701 attempts = GPOINTER_TO_INT(data);
6702 def_service = connman_service_get_default();
6705 * Stop auto connecting VPN if there is no transport service or the
6706 * transport service is not connected or if the current default service
6707 * is a connected VPN (in ready state).
6709 if (!def_service || !is_connected(def_service->state) ||
6710 (def_service->type == CONNMAN_SERVICE_TYPE_VPN &&
6711 is_connected(def_service->state))) {
6713 DBG("stopped, default service %s connected %d",
6714 def_service ? def_service->identifier : "NULL",
6715 def_service ? is_connected(def_service->state) : -1);
6719 for (list = service_list; list; list = list->next) {
6720 struct connman_service *service = list->data;
6723 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
6726 if (is_connected(service->state) ||
6727 is_connecting(service->state)) {
6728 if (!service->do_split_routing)
6732 * If the service is connecting it must be accounted
6733 * for to keep the autoconnection in main loop.
6735 if (is_connecting(service->state))
6736 autoconnectable_vpns = true;
6741 if (is_ignore(service) || !service->favorite)
6744 if (need_split && !service->do_split_routing) {
6745 DBG("service %p no split routing", service);
6749 DBG("service %p %s %s", service, service->name,
6750 service->do_split_routing ?
6751 "split routing" : "");
6753 res = __connman_service_connect(service,
6754 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
6758 service_indicate_state(service);
6761 autoconnectable_vpns = true;
6767 if (!service->do_split_routing)
6771 /* Stop if there is no VPN to automatically connect.*/
6772 if (!autoconnectable_vpns) {
6773 DBG("stopping, no autoconnectable VPNs found");
6777 /* Increase the attempt count up to the threshold.*/
6778 if (attempts < VPN_AUTOCONNECT_TIMEOUT_ATTEMPTS_THRESHOLD)
6782 * Timeout increases with 1s after VPN_AUTOCONNECT_TIMEOUT_STEP amount
6783 * of attempts made. After VPN_AUTOCONNECT_TIMEOUT_ATTEMPTS_THRESHOLD is
6784 * reached the delay does not increase.
6786 timeout = timeout + (int)(attempts / VPN_AUTOCONNECT_TIMEOUT_STEP);
6788 /* Re add this to main loop */
6789 vpn_autoconnect_id =
6790 g_timeout_add_seconds(timeout, run_vpn_auto_connect,
6791 GINT_TO_POINTER(attempts));
6793 DBG("re-added to main loop, next VPN autoconnect in %d seconds (#%d)",
6796 return G_SOURCE_REMOVE;
6799 vpn_autoconnect_id = 0;
6800 return G_SOURCE_REMOVE;
6803 static void vpn_auto_connect(void)
6806 * Remove existing autoconnect from main loop to reset the attempt
6807 * counter in order to get VPN connected when there is a network change.
6809 if (vpn_autoconnect_id) {
6810 if (!g_source_remove(vpn_autoconnect_id))
6814 vpn_autoconnect_id =
6815 g_idle_add(run_vpn_auto_connect, NULL);
6819 __connman_service_is_provider_pending(struct connman_service *service)
6824 if (service->provider_pending)
6830 void __connman_service_set_provider_pending(struct connman_service *service,
6833 if (service->provider_pending) {
6834 DBG("service %p provider pending msg %p already exists",
6835 service, service->provider_pending);
6839 service->provider_pending = msg;
6842 static void check_pending_msg(struct connman_service *service)
6844 if (!service->pending)
6847 DBG("service %p pending msg %p already exists", service,
6849 dbus_message_unref(service->pending);
6852 void __connman_service_set_hidden_data(struct connman_service *service,
6855 DBusMessage *pending = user_data;
6857 DBG("service %p pending %p", service, pending);
6862 check_pending_msg(service);
6864 service->pending = pending;
6867 void __connman_service_return_error(struct connman_service *service,
6868 int error, gpointer user_data)
6870 DBG("service %p error %d user_data %p", service, error, user_data);
6872 __connman_service_set_hidden_data(service, user_data);
6874 reply_pending(service, error);
6877 static gboolean connect_timeout(gpointer user_data)
6879 struct connman_service *service = user_data;
6880 bool autoconnect = false;
6882 DBG("service %p", service);
6884 service->timeout = 0;
6886 if (service->network)
6887 __connman_network_disconnect(service->network);
6888 else if (service->provider)
6889 connman_provider_disconnect(service->provider);
6891 __connman_stats_service_unregister(service);
6893 if (service->pending) {
6896 reply = __connman_error_operation_timeout(service->pending);
6898 g_dbus_send_message(connection, reply);
6900 dbus_message_unref(service->pending);
6901 service->pending = NULL;
6905 __connman_service_ipconfig_indicate_state(service,
6906 CONNMAN_SERVICE_STATE_FAILURE,
6907 CONNMAN_IPCONFIG_TYPE_IPV4);
6908 __connman_service_ipconfig_indicate_state(service,
6909 CONNMAN_SERVICE_STATE_FAILURE,
6910 CONNMAN_IPCONFIG_TYPE_IPV6);
6913 service->connect_reason !=
6914 CONNMAN_SERVICE_CONNECT_REASON_USER)
6915 do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
6920 static DBusMessage *connect_service(DBusConnection *conn,
6921 DBusMessage *msg, void *user_data)
6923 struct connman_service *service = user_data;
6924 #if defined TIZEN_EXT
6931 DBG("service %p", service);
6933 #if defined TIZEN_EXT
6935 * Description: TIZEN implements system global connection management.
6937 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6938 connman_service_user_pdn_connection_ref(service);
6940 /*Reset the Disconnect Reason while issue connect request*/
6941 service->disconnect_reason = 0;
6943 /*Reset the association status code while issue connect request*/
6944 service->assoc_status_code = 0;
6946 /* Reset the disconnection_requested while issue connect request*/
6947 connman_service_set_disconnection_requested(service, false);
6950 if (service->pending)
6951 return __connman_error_in_progress(msg);
6953 #if !defined TIZEN_EXT
6954 index = __connman_service_get_index(service);
6956 for (list = service_list; list; list = list->next) {
6957 struct connman_service *temp = list->data;
6959 #if defined TIZEN_EXT
6960 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6963 if (!is_connecting(temp->state) && !is_connected(temp->state))
6966 if (service == temp)
6969 if (service->type != temp->type)
6972 if (__connman_service_get_index(temp) == index &&
6973 __connman_service_disconnect(temp) == -EINPROGRESS)
6977 if (err == -EINPROGRESS)
6978 return __connman_error_operation_timeout(msg);
6981 service->ignore = false;
6983 service->pending = dbus_message_ref(msg);
6985 err = __connman_service_connect(service,
6986 CONNMAN_SERVICE_CONNECT_REASON_USER);
6988 if (err != -EINPROGRESS)
6989 reply_pending(service, -err);
6994 static DBusMessage *disconnect_service(DBusConnection *conn,
6995 DBusMessage *msg, void *user_data)
6997 struct connman_service *service = user_data;
7000 DBG("service %p", service);
7002 #if defined TIZEN_EXT
7004 * Description: TIZEN implements system global connection management.
7006 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
7007 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
7008 return __connman_error_failed(msg, EISCONN);
7010 if (is_connected(service->state) == TRUE &&
7011 service == connman_service_get_default_connection())
7012 return __connman_error_failed(msg, EISCONN);
7016 service->ignore = true;
7018 err = __connman_service_disconnect(service);
7019 if (err < 0 && err != -EINPROGRESS)
7020 return __connman_error_failed(msg, -err);
7022 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7025 #if defined TIZEN_EXT
7026 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
7028 if (service == NULL)
7031 DBG("service %p ", service);
7033 connman_network_set_string(service->network, "WiFi.EAP", NULL);
7034 connman_network_set_string(service->network, "WiFi.Identity", NULL);
7035 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
7036 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
7037 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
7038 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
7039 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
7040 connman_network_set_string(service->network, "WiFi.AnonymousIdentity", NULL);
7042 static void __connman_service_cleanup_network_dpp(struct connman_service *service)
7044 if (service == NULL)
7047 DBG("service %p ", service);
7049 connman_network_set_string(service->network, "WiFi.Connector", NULL);
7050 connman_network_set_string(service->network, "WiFi.CSignKey", NULL);
7051 connman_network_set_string(service->network, "WiFi.NetAccessKey", NULL);
7055 bool __connman_service_remove(struct connman_service *service)
7057 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
7058 service->type == CONNMAN_SERVICE_TYPE_GADGET)
7061 if (service->immutable || service->hidden ||
7062 __connman_provider_is_immutable(service->provider))
7065 #if !defined TIZEN_EXT
7066 if (!service->favorite && !is_idle(service->state))
7070 __connman_service_disconnect(service);
7072 g_free(service->passphrase);
7073 service->passphrase = NULL;
7075 g_free(service->identity);
7076 service->identity = NULL;
7078 g_free(service->anonymous_identity);
7079 service->anonymous_identity = NULL;
7081 g_free(service->subject_match);
7082 service->subject_match = NULL;
7084 g_free(service->altsubject_match);
7085 service->altsubject_match = NULL;
7087 g_free(service->domain_suffix_match);
7088 service->domain_suffix_match = NULL;
7090 g_free(service->domain_match);
7091 service->domain_match = NULL;
7093 g_free(service->agent_identity);
7094 service->agent_identity = NULL;
7096 g_free(service->eap);
7097 service->eap = NULL;
7099 #if defined TIZEN_EXT
7100 g_free(service->ca_cert_file);
7101 service->ca_cert_file = NULL;
7103 g_free(service->client_cert_file);
7104 service->client_cert_file = NULL;
7106 g_free(service->private_key_file);
7107 service->private_key_file = NULL;
7109 g_free(service->private_key_passphrase);
7110 service->private_key_passphrase = NULL;
7112 g_free(service->phase2);
7113 service->phase2 = NULL;
7115 __connman_service_cleanup_network_8021x(service);
7117 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
7118 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
7119 connman_service_set_proxy(service, NULL, false);
7121 __connman_service_nameserver_clear(service);
7123 g_strfreev(service->nameservers_config);
7124 service->nameservers_config = NULL;
7126 g_free(service->connector);
7127 service->connector = NULL;
7129 g_free(service->c_sign_key);
7130 service->c_sign_key = NULL;
7132 g_free(service->net_access_key);
7133 service->net_access_key = NULL;
7135 __connman_service_cleanup_network_dpp(service);
7138 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
7140 __connman_service_set_favorite(service, false);
7142 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
7144 #if defined TIZEN_EXT
7145 /* Reset IP Method and DNS Method to DHCP */
7146 __connman_ipconfig_set_method(service->ipconfig_ipv4,
7147 CONNMAN_IPCONFIG_METHOD_DHCP);
7148 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
7149 g_strfreev(service->nameservers_config);
7150 service->nameservers_config = NULL;
7153 #if defined TIZEN_EXT
7154 __connman_storage_remove_service(service->identifier);
7156 service_save(service);
7162 static DBusMessage *remove_service(DBusConnection *conn,
7163 DBusMessage *msg, void *user_data)
7165 struct connman_service *service = user_data;
7167 DBG("service %p", service);
7169 if (!__connman_service_remove(service))
7170 return __connman_error_not_supported(msg);
7172 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7175 static bool check_suitable_state(enum connman_service_state a,
7176 enum connman_service_state b)
7179 * Special check so that "ready" service can be moved before
7182 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
7183 b == CONNMAN_SERVICE_STATE_READY) ||
7184 (b == CONNMAN_SERVICE_STATE_ONLINE &&
7185 a == CONNMAN_SERVICE_STATE_READY))
7191 static void downgrade_state(struct connman_service *service)
7196 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
7197 service->state_ipv6);
7199 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
7200 __connman_service_ipconfig_indicate_state(service,
7201 CONNMAN_SERVICE_STATE_READY,
7202 CONNMAN_IPCONFIG_TYPE_IPV4);
7204 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
7205 __connman_service_ipconfig_indicate_state(service,
7206 CONNMAN_SERVICE_STATE_READY,
7207 CONNMAN_IPCONFIG_TYPE_IPV6);
7210 static void apply_relevant_default_downgrade(struct connman_service *service)
7212 struct connman_service *def_service;
7214 def_service = connman_service_get_default();
7218 if (def_service == service &&
7219 def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
7220 def_service->state = CONNMAN_SERVICE_STATE_READY;
7221 __connman_notifier_leave_online(def_service->type);
7222 state_changed(def_service);
7226 static void switch_default_service(struct connman_service *default_service,
7227 struct connman_service *downgrade_service)
7229 struct connman_service *service;
7232 apply_relevant_default_downgrade(default_service);
7233 src = g_list_find(service_list, downgrade_service);
7234 dst = g_list_find(service_list, default_service);
7237 if (src == dst || src->next == dst)
7240 service = src->data;
7241 service_list = g_list_delete_link(service_list, src);
7242 service_list = g_list_insert_before(service_list, dst, service);
7244 downgrade_state(downgrade_service);
7247 static struct _services_notify {
7254 static void service_append_added_foreach(gpointer data, gpointer user_data)
7256 struct connman_service *service = data;
7257 DBusMessageIter *iter = user_data;
7259 if (!service || !service->path) {
7260 DBG("service %p or path is NULL", service);
7264 if (g_hash_table_lookup(services_notify->add, service->path)) {
7265 DBG("new %s", service->path);
7267 append_struct(service, iter);
7268 g_hash_table_remove(services_notify->add, service->path);
7270 #if defined TIZEN_EXT
7271 if (!simplified_log)
7273 DBG("changed %s", service->path);
7275 append_struct_service(iter, NULL, service);
7279 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
7281 g_list_foreach(service_list, service_append_added_foreach, iter);
7284 static void append_removed(gpointer key, gpointer value, gpointer user_data)
7286 char *objpath = key;
7287 DBusMessageIter *iter = user_data;
7289 DBG("removed %s", objpath);
7290 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
7293 static void service_append_removed(DBusMessageIter *iter, void *user_data)
7295 g_hash_table_foreach(services_notify->remove, append_removed, iter);
7298 static gboolean service_send_changed(gpointer data)
7300 DBusMessage *signal;
7304 services_notify->id = 0;
7306 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
7307 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
7311 __connman_dbus_append_objpath_dict_array(signal,
7312 service_append_ordered, NULL);
7313 __connman_dbus_append_objpath_array(signal,
7314 service_append_removed, NULL);
7316 dbus_connection_send(connection, signal, NULL);
7317 dbus_message_unref(signal);
7319 g_hash_table_remove_all(services_notify->remove);
7320 g_hash_table_remove_all(services_notify->add);
7325 static void service_schedule_changed(void)
7327 if (services_notify->id != 0)
7330 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
7333 static DBusMessage *move_service(DBusConnection *conn,
7334 DBusMessage *msg, void *user_data,
7337 struct connman_service *service = user_data;
7338 struct connman_service *target;
7340 enum connman_ipconfig_method target4, target6;
7341 enum connman_ipconfig_method service4, service6;
7343 DBG("service %p", service);
7345 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
7348 if (!service->favorite)
7349 return __connman_error_not_supported(msg);
7351 target = find_service(path);
7352 if (!target || !target->favorite || target == service)
7353 return __connman_error_invalid_service(msg);
7355 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
7357 * We only allow VPN route splitting if there are
7358 * routes defined for a given VPN.
7360 if (!__connman_provider_check_routes(target->provider)) {
7361 connman_info("Cannot move service. "
7362 "No routes defined for provider %s",
7363 __connman_provider_get_ident(target->provider));
7364 return __connman_error_invalid_service(msg);
7367 set_split_routing(target, true);
7369 set_split_routing(target, false);
7371 set_split_routing(service, false);
7373 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
7374 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
7375 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
7376 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
7378 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
7379 target4, target6, target->state_ipv4, target->state_ipv6,
7380 target->do_split_routing);
7382 DBG("service %s method %d/%d state %d/%d", service->identifier,
7384 service->state_ipv4, service->state_ipv6);
7387 * If method is OFF, then we do not need to check the corresponding
7390 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
7391 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
7392 if (!check_suitable_state(target->state_ipv6,
7393 service->state_ipv6))
7394 return __connman_error_invalid_service(msg);
7398 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
7399 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
7400 if (!check_suitable_state(target->state_ipv4,
7401 service->state_ipv4))
7402 return __connman_error_invalid_service(msg);
7406 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
7407 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
7408 if (!check_suitable_state(target->state_ipv6,
7409 service->state_ipv6))
7410 return __connman_error_invalid_service(msg);
7414 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
7415 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
7416 if (!check_suitable_state(target->state_ipv4,
7417 service->state_ipv4))
7418 return __connman_error_invalid_service(msg);
7422 gettimeofday(&service->modified, NULL);
7423 service_save(service);
7424 service_save(target);
7427 * If the service which goes down is the default service and is
7428 * online, we downgrade directly its state to ready so:
7429 * the service which goes up, needs to recompute its state which
7430 * is triggered via downgrading it - if relevant - to state ready.
7433 switch_default_service(target, service);
7435 switch_default_service(service, target);
7437 __connman_connection_update_gateway();
7439 service_schedule_changed();
7441 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7444 static DBusMessage *move_before(DBusConnection *conn,
7445 DBusMessage *msg, void *user_data)
7447 return move_service(conn, msg, user_data, true);
7450 static DBusMessage *move_after(DBusConnection *conn,
7451 DBusMessage *msg, void *user_data)
7453 return move_service(conn, msg, user_data, false);
7456 static DBusMessage *reset_counters(DBusConnection *conn,
7457 DBusMessage *msg, void *user_data)
7459 struct connman_service *service = user_data;
7461 reset_stats(service);
7463 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7466 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
7467 static DBusMessage *is_eapol_enabled(DBusConnection *conn,
7468 DBusMessage *msg, void *user_data)
7470 struct connman_service *service = user_data;
7471 DBG("service: %p path: %s UseEapol: %d", service, service->path, service->use_eapol);
7473 dbus_bool_t eapol_status = service->use_eapol;
7475 DBusMessage *reply = dbus_message_new_method_return(msg);
7477 DBG("Failed to initialize reply");
7481 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &eapol_status, DBUS_TYPE_INVALID);
7484 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
7486 #if defined TIZEN_MAINTAIN_ONLINE
7487 static DBusMessage *downgrade_service(DBusConnection *conn,
7488 DBusMessage *msg, void *user_data)
7490 struct connman_service *service = user_data;
7492 downgrade_state(service);
7493 __connman_connection_update_gateway();
7495 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
7499 static void service_schedule_added(struct connman_service *service)
7501 #if defined TIZEN_EXT
7502 if (!simplified_log)
7504 DBG("service %p", service);
7506 g_hash_table_remove(services_notify->remove, service->path);
7507 g_hash_table_replace(services_notify->add, service->path, service);
7509 service_schedule_changed();
7512 static void service_schedule_removed(struct connman_service *service)
7514 if (!service || !service->path) {
7515 DBG("service %p or path is NULL", service);
7519 DBG("service %p %s", service, service->path);
7521 g_hash_table_remove(services_notify->add, service->path);
7522 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
7525 service_schedule_changed();
7528 static bool allow_property_changed(struct connman_service *service)
7530 #if defined TIZEN_EXT
7531 if (service->path == NULL)
7534 if (g_hash_table_lookup_extended(services_notify->add, service->path,
7541 static const GDBusMethodTable service_methods[] = {
7542 { GDBUS_DEPRECATED_METHOD("GetProperties",
7543 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
7545 { GDBUS_METHOD("SetProperty",
7546 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
7547 NULL, set_property) },
7548 { GDBUS_METHOD("ClearProperty",
7549 GDBUS_ARGS({ "name", "s" }), NULL,
7551 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
7553 { GDBUS_METHOD("Disconnect", NULL, NULL,
7554 disconnect_service) },
7555 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
7556 { GDBUS_METHOD("MoveBefore",
7557 GDBUS_ARGS({ "service", "o" }), NULL,
7559 { GDBUS_METHOD("MoveAfter",
7560 GDBUS_ARGS({ "service", "o" }), NULL,
7562 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
7563 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
7564 { GDBUS_METHOD("IsEapolEnabled", NULL, GDBUS_ARGS({ "eapol", "b" }), is_eapol_enabled) },
7566 #if defined TIZEN_MAINTAIN_ONLINE
7567 { GDBUS_METHOD("Downgrade", NULL, NULL, downgrade_service) },
7572 static const GDBusSignalTable service_signals[] = {
7573 { GDBUS_SIGNAL("PropertyChanged",
7574 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
7575 #if defined TIZEN_EXT
7576 { GDBUS_SIGNAL("StateChangedProperties",
7577 GDBUS_ARGS({ "properties", "a{sv}" })) },
7582 static void service_free(gpointer user_data)
7584 struct connman_service *service = user_data;
7585 char *path = service->path;
7587 DBG("service %p", service);
7589 reply_pending(service, ENOENT);
7591 if (service->nameservers_timeout) {
7592 g_source_remove(service->nameservers_timeout);
7593 dns_changed(service);
7596 __connman_notifier_service_remove(service);
7597 service_schedule_removed(service);
7599 __connman_wispr_stop(service);
7600 stats_stop(service);
7602 service->path = NULL;
7605 __connman_connection_update_gateway();
7607 g_dbus_unregister_interface(connection, path,
7608 CONNMAN_SERVICE_INTERFACE);
7612 g_hash_table_destroy(service->counter_table);
7614 if (service->network) {
7615 __connman_network_disconnect(service->network);
7616 connman_network_unref(service->network);
7617 service->network = NULL;
7620 if (service->provider)
7621 connman_provider_unref(service->provider);
7623 if (service->ipconfig_ipv4) {
7624 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
7625 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
7626 __connman_ipconfig_unref(service->ipconfig_ipv4);
7627 service->ipconfig_ipv4 = NULL;
7630 if (service->ipconfig_ipv6) {
7631 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
7632 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
7633 __connman_ipconfig_unref(service->ipconfig_ipv6);
7634 service->ipconfig_ipv6 = NULL;
7637 g_strfreev(service->timeservers);
7638 g_strfreev(service->timeservers_config);
7639 g_strfreev(service->nameservers);
7640 g_strfreev(service->nameservers_config);
7641 g_strfreev(service->nameservers_auto);
7642 g_strfreev(service->domains);
7643 g_strfreev(service->proxies);
7644 g_strfreev(service->excludes);
7646 g_free(service->hostname);
7647 g_free(service->domainname);
7648 g_free(service->pac);
7649 g_free(service->name);
7650 g_free(service->passphrase);
7651 g_free(service->identifier);
7652 g_free(service->eap);
7653 g_free(service->identity);
7654 g_free(service->anonymous_identity);
7655 g_free(service->agent_identity);
7656 g_free(service->ca_cert_file);
7657 g_free(service->subject_match);
7658 g_free(service->altsubject_match);
7659 g_free(service->domain_suffix_match);
7660 g_free(service->domain_match);
7661 g_free(service->client_cert_file);
7662 g_free(service->private_key_file);
7663 g_free(service->private_key_passphrase);
7664 g_free(service->phase2);
7665 g_free(service->config_file);
7666 g_free(service->config_entry);
7667 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
7668 g_free(service->pac_file);
7669 g_free(service->phase1);
7672 #if defined TIZEN_EXT
7673 g_free(service->connector);
7674 g_free(service->c_sign_key);
7675 g_free(service->net_access_key);
7678 if (service->stats.timer)
7679 g_timer_destroy(service->stats.timer);
7680 if (service->stats_roaming.timer)
7681 g_timer_destroy(service->stats_roaming.timer);
7683 if (current_default == service)
7684 current_default = NULL;
7689 static void stats_init(struct connman_service *service)
7692 service->stats.valid = false;
7693 service->stats.enabled = false;
7694 service->stats.timer = g_timer_new();
7697 service->stats_roaming.valid = false;
7698 service->stats_roaming.enabled = false;
7699 service->stats_roaming.timer = g_timer_new();
7702 static void service_initialize(struct connman_service *service)
7704 #if defined TIZEN_EXT
7705 if (!simplified_log)
7707 DBG("service %p", service);
7709 service->refcount = 1;
7711 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
7713 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
7714 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
7716 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
7717 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
7718 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
7720 service->favorite = false;
7721 service->immutable = false;
7722 service->hidden = false;
7724 service->ignore = false;
7726 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
7730 stats_init(service);
7732 service->provider = NULL;
7734 service->wps = false;
7735 service->wps_advertizing = false;
7736 #if defined TIZEN_EXT
7737 memset(service->last_connected_bssid, 0, WIFI_BSSID_LEN_MAX);
7738 service->is_internet_connection = false;
7739 service->assoc_reject_count = 0;
7741 #if defined TIZEN_EXT
7742 service->disconnection_requested = false;
7743 service->storage_reload = false;
7745 * Description: TIZEN implements system global connection management.
7747 service->user_pdn_connection_refcount = 0;
7748 __sync_synchronize();
7750 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
7751 service->use_eapol = false;
7752 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
7756 * connman_service_create:
7758 * Allocate a new service.
7760 * Returns: a newly-allocated #connman_service structure
7762 struct connman_service *connman_service_create(void)
7765 struct connman_stats_counter *counters;
7766 const char *counter;
7768 struct connman_service *service;
7770 service = g_try_new0(struct connman_service, 1);
7774 DBG("service %p", service);
7776 service->counter_table = g_hash_table_new_full(g_str_hash,
7777 g_str_equal, NULL, g_free);
7779 for (list = counter_list; list; list = list->next) {
7780 counter = list->data;
7782 counters = g_try_new0(struct connman_stats_counter, 1);
7784 g_hash_table_destroy(service->counter_table);
7789 counters->append_all = true;
7791 g_hash_table_replace(service->counter_table, (gpointer)counter,
7795 service_initialize(service);
7801 * connman_service_ref:
7802 * @service: service structure
7804 * Increase reference counter of service
7806 struct connman_service *
7807 connman_service_ref_debug(struct connman_service *service,
7808 const char *file, int line, const char *caller)
7810 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
7811 file, line, caller);
7813 __sync_fetch_and_add(&service->refcount, 1);
7819 * connman_service_unref:
7820 * @service: service structure
7822 * Decrease reference counter of service and release service if no
7825 void connman_service_unref_debug(struct connman_service *service,
7826 const char *file, int line, const char *caller)
7828 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
7829 file, line, caller);
7831 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
7834 service_list = g_list_remove(service_list, service);
7836 __connman_service_disconnect(service);
7838 g_hash_table_remove(service_hash, service->identifier);
7841 #if defined TIZEN_EXT
7842 static int calculate_score_last_user_selection(struct connman_service *service)
7845 struct connman_device *device;
7846 const char *last_user_selection_ident;
7847 time_t last_user_selection_time;
7848 unsigned int frequency;
7851 struct tm* ref_timeinfo;
7853 device = connman_network_get_device(service->network);
7857 last_user_selection_time = connman_device_get_last_user_selection_time(device);
7858 last_user_selection_ident = connman_device_get_last_user_selection_ident(device);
7859 frequency = connman_network_get_frequency(service->network);
7861 if (ins_settings.last_user_selection) {
7862 if (g_strcmp0(last_user_selection_ident, service->identifier) == 0 &&
7863 (((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
7864 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
7865 service->strength >= ins_settings.signal_level3_24ghz) ||
7866 ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
7867 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
7868 service->strength >= ins_settings.signal_level3_5ghz))) {
7870 /* Only events that occur within 8 hours are counted. */
7871 curr_time = time(NULL);
7872 ref_timeinfo = localtime(&curr_time);
7873 ref_timeinfo->tm_hour -= 8;
7874 ref_time = mktime(ref_timeinfo);
7876 if (last_user_selection_time > ref_time) {
7877 int time_diff = (curr_time - last_user_selection_time) / 60;
7878 int denominator = ins_settings.last_user_selection_time - time_diff;
7879 int numerator = ins_settings.last_user_selection_time /
7880 ins_settings.last_user_selection_score;
7881 int last_user_score = denominator / numerator;
7883 score += (last_user_score > ins_settings.last_user_selection_score ?
7884 ins_settings.last_user_selection_score : last_user_score);
7892 static int calculate_score_last_connected(struct connman_service *service)
7895 struct connman_device *device;
7896 const char *last_connected_ident;
7897 unsigned int frequency;
7899 device = connman_network_get_device(service->network);
7903 last_connected_ident = connman_device_get_last_connected_ident(device);
7904 frequency = connman_network_get_frequency(service->network);
7906 if (g_strcmp0(last_connected_ident, service->identifier) == 0 &&
7907 (((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
7908 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
7909 service->strength >= ins_settings.signal_level3_24ghz) ||
7910 ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
7911 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
7912 service->strength >= ins_settings.signal_level3_5ghz))) {
7913 score += ins_settings.last_connected_score;
7919 static int calculate_score_frequency(struct connman_service *service)
7922 unsigned int frequency;
7924 frequency = connman_network_get_frequency(service->network);
7926 switch (ins_settings.preferred_freq) {
7927 case CONNMAN_INS_PREFERRED_FREQ_24GHZ:
7928 if ((frequency >= FREQ_RANGE_24GHZ_CHANNEL_14 &&
7929 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
7930 (service->strength >= ins_settings.signal_level3_24ghz))
7931 score += ins_settings.preferred_freq_score;
7934 case CONNMAN_INS_PREFERRED_FREQ_5GHZ:
7935 if ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
7936 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
7937 (service->strength >= ins_settings.signal_level3_5ghz))
7938 score += ins_settings.preferred_freq_score;
7948 static int calculate_score_security_priority(struct connman_service *service)
7952 if (ins_settings.security_priority_count)
7953 score += ins_settings.security_priority[service->security];
7958 static int calculate_score_internet_connection(struct connman_service *service)
7962 if (ins_settings.internet) {
7963 if (service->is_internet_connection)
7964 score += ins_settings.internet_score;
7970 static int calculate_score_strength(struct connman_service *service)
7974 if (ins_settings.signal)
7975 score += (((service->strength > 60) ? 60 : service->strength) - 35);
7980 static int calculate_score(struct connman_service *service)
7982 int score_last_user_selection;
7983 int score_last_connected;
7984 int score_frequency;
7985 int score_security_priority;
7986 int score_internet_connection;
7990 if (service->type != CONNMAN_SERVICE_TYPE_WIFI) {
7991 score += calculate_score_internet_connection(service);
7992 service->ins_score = score;
7996 score_last_user_selection = calculate_score_last_user_selection(service);
7997 score_last_connected = calculate_score_last_connected(service);
7998 score_frequency = calculate_score_frequency(service);
7999 score_security_priority = calculate_score_security_priority(service);
8000 score_internet_connection = calculate_score_internet_connection(service);
8001 score_strength = calculate_score_strength(service);
8003 score = score_last_user_selection + score_last_connected +
8004 score_frequency + score_security_priority +
8005 score_internet_connection + score_strength;
8007 #if defined TIZEN_EXT_INS
8008 service->score_last_user_selection = score_last_user_selection;
8009 service->score_last_connected = score_last_connected;
8010 service->score_frequency = score_frequency;
8011 service->score_security_priority = score_security_priority;
8012 service->score_internet_connection = score_internet_connection;
8013 service->score_strength = score_strength;
8016 service->ins_score = score;
8021 static gint service_compare(gconstpointer a, gconstpointer b)
8023 struct connman_service *service_a = (void *) a;
8024 struct connman_service *service_b = (void *) b;
8025 enum connman_service_state state_a, state_b;
8026 bool a_connected, b_connected;
8027 #if defined TIZEN_EXT
8034 state_a = service_a->state;
8035 state_b = service_b->state;
8036 a_connected = is_connected(state_a);
8037 b_connected = is_connected(state_b);
8039 #if defined TIZEN_EXT
8040 if ((a_connected && b_connected) &&
8041 state_a == state_b &&
8042 service_a->type == CONNMAN_SERVICE_TYPE_WIFI &&
8043 service_b->type == CONNMAN_SERVICE_TYPE_WIFI) {
8044 const char *default_interface =
8045 connman_option_get_string("DefaultWifiInterface");
8046 const char *ifname_a = connman_device_get_string(
8047 connman_network_get_device(service_a->network), "Interface");
8048 const char *ifname_b = connman_device_get_string(
8049 connman_network_get_device(service_b->network), "Interface");
8051 if (g_strcmp0(default_interface, ifname_a) == 0)
8053 else if (g_strcmp0(default_interface, ifname_b) == 0)
8058 if (a_connected && b_connected) {
8059 if (service_a->order > service_b->order)
8062 if (service_a->order < service_b->order)
8066 if (state_a != state_b) {
8067 if (a_connected && b_connected) {
8068 /* We prefer online over ready state */
8069 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
8072 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
8081 if (is_connecting(state_a))
8083 if (is_connecting(state_b))
8087 if (service_a->favorite && !service_b->favorite)
8090 if (!service_a->favorite && service_b->favorite)
8093 if (service_a->type != service_b->type) {
8094 unsigned int *tech_array;
8097 tech_array = connman_setting_get_uint_list(
8098 "PreferredTechnologies");
8100 for (i = 0; tech_array[i]; i++) {
8101 if (tech_array[i] == service_a->type)
8104 if (tech_array[i] == service_b->type)
8109 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8111 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8114 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
8116 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
8119 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8121 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8124 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8126 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8129 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
8131 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
8134 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
8136 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
8140 #if defined TIZEN_EXT
8141 score_a = calculate_score(service_a);
8142 score_b = calculate_score(service_b);
8143 if (score_b != score_a)
8144 return score_b - score_a;
8146 strength = (gint) service_b->strength - (gint) service_a->strength;
8151 return g_strcmp0(service_a->name, service_b->name);
8154 #if defined TIZEN_EXT_INS
8155 static void print_service_sort(gpointer data, gpointer user_data)
8157 struct connman_service *service = data;
8159 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
8162 DBG("name[%-20s] total[%2d] last_usr[%2d] last_conn[%2d] "
8163 "freq[%2d] sec[%2d] internet[%2d] strength[%2d]",
8164 service->name, service->ins_score, service->score_last_user_selection,
8165 service->score_last_connected, service->score_frequency,
8166 service->score_security_priority, service->score_internet_connection,
8167 service->score_strength);
8171 static void service_list_sort(void)
8173 if (service_list && service_list->next) {
8174 service_list = g_list_sort(service_list, service_compare);
8175 #if defined TIZEN_EXT_INS
8176 g_list_foreach(service_list, print_service_sort, NULL);
8178 service_schedule_changed();
8182 int __connman_service_compare(const struct connman_service *a,
8183 const struct connman_service *b)
8185 return service_compare(a, b);
8189 * connman_service_get_type:
8190 * @service: service structure
8192 * Get the type of service
8194 enum connman_service_type connman_service_get_type(struct connman_service *service)
8197 return CONNMAN_SERVICE_TYPE_UNKNOWN;
8199 return service->type;
8203 * connman_service_get_interface:
8204 * @service: service structure
8206 * Get network interface of service
8208 char *connman_service_get_interface(struct connman_service *service)
8215 index = __connman_service_get_index(service);
8217 return connman_inet_ifname(index);
8221 * connman_service_get_network:
8222 * @service: service structure
8224 * Get the service network
8226 struct connman_network *
8227 __connman_service_get_network(struct connman_service *service)
8232 return service->network;
8235 struct connman_ipconfig *
8236 __connman_service_get_ip4config(struct connman_service *service)
8241 return service->ipconfig_ipv4;
8244 struct connman_ipconfig *
8245 __connman_service_get_ip6config(struct connman_service *service)
8250 return service->ipconfig_ipv6;
8253 struct connman_ipconfig *
8254 __connman_service_get_ipconfig(struct connman_service *service, int family)
8256 if (family == AF_INET)
8257 return __connman_service_get_ip4config(service);
8258 else if (family == AF_INET6)
8259 return __connman_service_get_ip6config(service);
8265 bool __connman_service_is_connected_state(struct connman_service *service,
8266 enum connman_ipconfig_type type)
8272 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
8274 case CONNMAN_IPCONFIG_TYPE_IPV4:
8275 return is_connected(service->state_ipv4);
8276 case CONNMAN_IPCONFIG_TYPE_IPV6:
8277 return is_connected(service->state_ipv6);
8278 case CONNMAN_IPCONFIG_TYPE_ALL:
8279 return is_connected(service->state_ipv4) &&
8280 is_connected(service->state_ipv6);
8285 enum connman_service_security __connman_service_get_security(
8286 struct connman_service *service)
8289 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8291 return service->security;
8294 const char *__connman_service_get_phase2(struct connman_service *service)
8299 return service->phase2;
8302 bool __connman_service_wps_enabled(struct connman_service *service)
8307 return service->wps;
8310 void __connman_service_mark_dirty(void)
8312 services_dirty = true;
8315 #if defined TIZEN_EXT
8317 * Returns profile count if there is any connected profiles
8318 * that use same interface
8320 int __connman_service_get_connected_count_of_iface(
8321 struct connman_service *service)
8330 index1 = __connman_service_get_index(service);
8335 for (list = service_list; list; list = list->next) {
8336 struct connman_service *service2 = list->data;
8338 if (service == service2)
8341 index2 = __connman_service_get_index(service2);
8343 if (is_connected(service2->state) && index2 > 0 && index1 == index2)
8349 DBG("Interface index %d, count %d", index1, count);
8354 void __connman_service_set_storage_reload(struct connman_service *service,
8355 bool storage_reload)
8357 if (service != NULL)
8358 service->storage_reload = storage_reload;
8363 * __connman_service_set_favorite_delayed:
8364 * @service: service structure
8365 * @favorite: favorite value
8366 * @delay_ordering: do not order service sequence
8368 * Change the favorite setting of service
8370 int __connman_service_set_favorite_delayed(struct connman_service *service,
8372 bool delay_ordering)
8374 #if defined TIZEN_EXT
8375 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8378 if (service->hidden)
8381 if (service->favorite == favorite)
8384 service->favorite = favorite;
8386 favorite_changed(service);
8388 if (!delay_ordering) {
8390 service_list_sort();
8392 __connman_connection_update_gateway();
8399 * __connman_service_set_favorite:
8400 * @service: service structure
8401 * @favorite: favorite value
8403 * Change the favorite setting of service
8405 int __connman_service_set_favorite(struct connman_service *service,
8408 return __connman_service_set_favorite_delayed(service, favorite,
8412 bool connman_service_get_favorite(struct connman_service *service)
8414 return service->favorite;
8417 bool connman_service_get_autoconnect(struct connman_service *service)
8419 return service->autoconnect;
8422 int __connman_service_set_immutable(struct connman_service *service,
8425 if (service->hidden)
8428 if (service->immutable == immutable)
8431 service->immutable = immutable;
8433 immutable_changed(service);
8438 int __connman_service_set_ignore(struct connman_service *service,
8444 service->ignore = ignore;
8449 void __connman_service_set_string(struct connman_service *service,
8450 const char *key, const char *value)
8452 if (service->hidden)
8454 if (g_str_equal(key, "EAP")) {
8455 g_free(service->eap);
8456 service->eap = g_strdup(value);
8457 } else if (g_str_equal(key, "Identity")) {
8458 g_free(service->identity);
8459 service->identity = g_strdup(value);
8460 } else if (g_str_equal(key, "AnonymousIdentity")) {
8461 g_free(service->anonymous_identity);
8462 service->anonymous_identity = g_strdup(value);
8463 } else if (g_str_equal(key, "CACertFile")) {
8464 g_free(service->ca_cert_file);
8465 service->ca_cert_file = g_strdup(value);
8466 } else if (g_str_equal(key, "SubjectMatch")) {
8467 g_free(service->subject_match);
8468 service->subject_match = g_strdup(value);
8469 } else if (g_str_equal(key, "AltSubjectMatch")) {
8470 g_free(service->altsubject_match);
8471 service->altsubject_match = g_strdup(value);
8472 } else if (g_str_equal(key, "DomainSuffixMatch")) {
8473 g_free(service->domain_suffix_match);
8474 service->domain_suffix_match = g_strdup(value);
8475 } else if (g_str_equal(key, "DomainMatch")) {
8476 g_free(service->domain_match);
8477 service->domain_match = g_strdup(value);
8478 } else if (g_str_equal(key, "ClientCertFile")) {
8479 g_free(service->client_cert_file);
8480 service->client_cert_file = g_strdup(value);
8481 } else if (g_str_equal(key, "PrivateKeyFile")) {
8482 g_free(service->private_key_file);
8483 service->private_key_file = g_strdup(value);
8484 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
8485 g_free(service->private_key_passphrase);
8486 service->private_key_passphrase = g_strdup(value);
8487 } else if (g_str_equal(key, "Phase2")) {
8488 g_free(service->phase2);
8489 service->phase2 = g_strdup(value);
8490 } else if (g_str_equal(key, "Passphrase"))
8491 __connman_service_set_passphrase(service, value);
8492 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8493 else if (g_str_equal(key, "Phase1")) {
8494 g_free(service->phase1);
8495 service->phase1 = g_strdup(value);
8496 } else if (g_str_equal(key, "PacFile")) {
8497 g_free(service->pac_file);
8498 service->pac_file = g_strdup(value);
8501 #if defined TIZEN_EXT
8502 else if (g_str_equal(key, "Connector")) {
8503 g_free(service->connector);
8504 service->connector = g_strdup(value);
8505 } else if (g_str_equal(key, "CSignKey")) {
8506 g_free(service->c_sign_key);
8507 service->c_sign_key = g_strdup(value);
8508 } else if (g_str_equal(key, "NetAccessKey")) {
8509 g_free(service->net_access_key);
8510 service->net_access_key = g_strdup(value);
8512 DBG("Unknown key: %s", key);
8516 void __connman_service_set_search_domains(struct connman_service *service,
8519 searchdomain_remove_all(service);
8521 if (service->domains)
8522 g_strfreev(service->domains);
8524 service->domains = g_strdupv(domains);
8526 searchdomain_add_all(service);
8529 int __connman_service_set_mdns(struct connman_service *service,
8532 service->mdns_config = enabled;
8534 return set_mdns(service, enabled);
8537 static void report_error_cb(void *user_context, bool retry,
8540 struct connman_service *service = user_context;
8543 __connman_service_connect(service,
8544 CONNMAN_SERVICE_CONNECT_REASON_USER);
8546 /* It is not relevant to stay on Failure state
8547 * when failing is due to wrong user input */
8548 __connman_service_clear_error(service);
8549 #if defined TIZEN_EXT
8550 /* Reseting the state back in case of failure state */
8551 service->state_ipv4 = service->state_ipv6 =
8552 CONNMAN_SERVICE_STATE_IDLE;
8554 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED)
8555 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
8557 service_complete(service);
8558 __connman_connection_update_gateway();
8562 static int check_wpspin(struct connman_service *service, const char *wpspin)
8570 length = strlen(wpspin);
8572 /* If 0, it will mean user wants to use PBC method */
8574 connman_network_set_string(service->network,
8575 "WiFi.PinWPS", NULL);
8579 /* A WPS PIN is always 8 chars length,
8580 * its content is in digit representation.
8585 for (i = 0; i < 8; i++)
8586 if (!isdigit((unsigned char) wpspin[i]))
8589 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
8594 static void request_input_cb(struct connman_service *service,
8595 bool values_received,
8596 const char *name, int name_len,
8597 const char *identity, const char *passphrase,
8598 bool wps, const char *wpspin,
8599 const char *error, void *user_data)
8601 struct connman_device *device;
8602 const char *security;
8605 DBG("RequestInput return, %p", service);
8608 DBG("error: %s", error);
8610 if (g_strcmp0(error,
8611 "net.connman.Agent.Error.Canceled") == 0) {
8612 err = -ECONNABORTED;
8614 if (service->hidden)
8615 __connman_service_return_error(service,
8621 if (service->hidden)
8622 __connman_service_return_error(service,
8623 ETIMEDOUT, user_data);
8629 if (service->hidden && name_len > 0 && name_len <= 32) {
8630 device = connman_network_get_device(service->network);
8631 security = connman_network_get_string(service->network,
8633 err = __connman_device_request_hidden_scan(device,
8635 identity, passphrase,
8636 security, user_data);
8638 __connman_service_return_error(service, -err,
8642 if (!values_received || service->hidden) {
8647 if (wps && service->network) {
8648 err = check_wpspin(service, wpspin);
8652 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
8656 __connman_service_set_agent_identity(service, identity);
8659 err = __connman_service_set_passphrase(service, passphrase);
8663 /* We forget any previous error. */
8664 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
8666 __connman_service_connect(service,
8667 CONNMAN_SERVICE_CONNECT_REASON_USER);
8669 } else if (err == -ENOKEY) {
8670 __connman_service_indicate_error(service,
8671 CONNMAN_SERVICE_ERROR_INVALID_KEY);
8673 /* It is not relevant to stay on Failure state
8674 * when failing is due to wrong user input */
8675 service->state = CONNMAN_SERVICE_STATE_IDLE;
8677 if (!service->hidden) {
8679 * If there was a real error when requesting
8680 * hidden scan, then that error is returned already
8681 * to the user somewhere above so do not try to
8684 __connman_service_return_error(service, -err,
8688 service_complete(service);
8689 __connman_connection_update_gateway();
8693 static void downgrade_connected_services(void)
8695 struct connman_service *up_service;
8698 for (list = service_list; list; list = list->next) {
8699 up_service = list->data;
8701 if (!is_connected(up_service->state))
8704 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
8707 downgrade_state(up_service);
8711 static int service_update_preferred_order(struct connman_service *default_service,
8712 struct connman_service *new_service,
8713 enum connman_service_state new_state)
8715 unsigned int *tech_array;
8718 if (!default_service || default_service == new_service ||
8719 default_service->state != new_state)
8722 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
8725 for (i = 0; tech_array[i] != 0; i += 1) {
8726 if (default_service->type == tech_array[i])
8729 if (new_service->type == tech_array[i]) {
8730 switch_default_service(default_service,
8732 __connman_connection_update_gateway();
8741 #if defined TIZEN_EXT
8742 static gboolean __connman_service_can_drop(struct connman_service *service)
8744 if (is_connected(service->state) == TRUE || is_connecting(service->state) == TRUE) {
8745 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
8747 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
8753 static struct connman_device *default_connecting_device = NULL;
8755 static void __connman_service_disconnect_default(struct connman_service *service)
8757 struct connman_device *default_device = NULL;
8758 struct connman_network *network = __connman_service_get_network(service);
8763 if (default_connecting_device == NULL)
8766 default_device = connman_network_get_device(network);
8768 DBG("Disconnecting service %p %s", service, service->path);
8769 DBG("Disconnecting device %p %p %s",
8770 default_connecting_device,
8772 connman_device_get_string(default_device, "Name"));
8774 if (default_connecting_device == default_device)
8775 default_connecting_device = NULL;
8778 #if defined TIZEN_MAINTAIN_ONLINE
8779 static void __connman_service_connect_default(struct connman_service *current,
8780 enum connman_service_state old_state)
8782 static void __connman_service_connect_default(struct connman_service *current)
8787 bool default_internet;
8788 struct connman_service *service;
8789 struct connman_service *default_service = NULL;
8790 struct connman_device *default_device = NULL;
8792 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
8793 switch (current->state) {
8794 case CONNMAN_SERVICE_STATE_UNKNOWN:
8795 case CONNMAN_SERVICE_STATE_ASSOCIATION:
8796 case CONNMAN_SERVICE_STATE_CONFIGURATION:
8802 if (default_connecting_device &&
8803 __connman_service_is_internet_profile(current) == TRUE) {
8804 if (current->network == NULL)
8807 default_device = connman_network_get_device(current->network);
8808 if (default_connecting_device == default_device) {
8809 DBG("Cellular service[%s] %p %s",
8810 state2string(current->state), current, current->path);
8811 DBG("Cellular device %p %p %s",
8812 default_connecting_device, default_device,
8813 connman_device_get_string(default_device, "Name"));
8815 default_connecting_device = NULL;
8820 #if defined TIZEN_MAINTAIN_ONLINE
8821 } else if (current->state == CONNMAN_SERVICE_STATE_READY &&
8822 old_state == CONNMAN_SERVICE_STATE_ONLINE) {
8823 DBG("Device is downgraded: online --> ready");
8825 } else if (is_connected(current->state) == TRUE || is_connecting(current->state) == TRUE)
8828 /* Always-on: keep default cellular connection as possible */
8829 for (list = service_list; list; list = list->next) {
8830 service = list->data;
8832 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
8833 __connman_service_is_internet_profile(service) != TRUE ||
8834 service->network == NULL) {
8839 connman_network_get_bool(service->network, "DefaultInternet");
8841 DBG("service: %p %s %s %s (default: %d)", service, service->name,
8842 __connman_service_type2string(service->type),
8843 state2string(service->state), default_internet);
8845 if (default_internet) {
8846 default_service = service;
8847 if (is_connected(default_service->state) == TRUE ||
8848 is_connecting(default_service->state) == TRUE)
8851 default_device = connman_network_get_device(default_service->network);
8852 if (default_connecting_device == default_device) {
8853 DBG("Device is connecting (%p)", default_connecting_device);
8857 default_connecting_device = default_device;
8858 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
8860 err = __connman_network_connect(default_service->network);
8861 DBG("Connecting default service %p %s [%d]",
8862 default_service, default_service->path, err);
8863 DBG("Connecting device %p %s", default_connecting_device,
8864 connman_device_get_string(default_connecting_device, "Name"));
8865 if (err < 0 && err != -EINPROGRESS) {
8866 default_connecting_device = NULL;
8874 static void single_connected_tech(struct connman_service *allowed)
8876 struct connman_service *service;
8877 GSList *services = NULL, *list;
8880 DBG("keeping %p %s", allowed, allowed->path);
8882 #if defined TIZEN_EXT
8883 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8887 for (iter = service_list; iter; iter = iter->next) {
8888 service = iter->data;
8890 #if defined TIZEN_EXT
8891 if (service != allowed && service->type != allowed->type &&
8892 __connman_service_can_drop(service) == TRUE)
8894 if (!is_connected(service->state))
8897 if (service == allowed)
8901 services = g_slist_prepend(services, service);
8904 for (list = services; list; list = list->next) {
8905 service = list->data;
8907 DBG("disconnecting %p %s", service, service->path);
8908 #if defined TIZEN_EXT
8909 __connman_service_disconnect_default(service);
8911 __connman_service_disconnect(service);
8914 g_slist_free(services);
8917 #if defined TIZEN_EXT
8918 static void set_priority_connected_service(void)
8920 struct connman_service *service;
8923 for (list = service_list; list; list = list->next) {
8924 service = list->data;
8926 if (is_connected(service->state) == FALSE)
8929 #if defined TIZEN_MAINTAIN_ONLINE
8931 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
8932 service->state == CONNMAN_SERVICE_STATE_ONLINE)
8934 else if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
8946 static const char *get_dbus_sender(struct connman_service *service)
8948 if (!service->pending)
8951 return dbus_message_get_sender(service->pending);
8954 static int service_indicate_state(struct connman_service *service)
8956 enum connman_service_state old_state, new_state;
8957 struct connman_service *def_service;
8958 enum connman_ipconfig_method method;
8964 old_state = service->state;
8965 new_state = combine_state(service->state_ipv4, service->state_ipv6);
8967 DBG("service %p old %s - new %s/%s => %s",
8969 state2string(old_state),
8970 state2string(service->state_ipv4),
8971 state2string(service->state_ipv6),
8972 state2string(new_state));
8974 if (old_state == new_state)
8977 def_service = connman_service_get_default();
8979 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
8980 result = service_update_preferred_order(def_service,
8981 service, new_state);
8982 if (result == -EALREADY)
8986 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
8987 __connman_notifier_leave_online(service->type);
8989 if (is_connected(old_state) && !is_connected(new_state))
8990 searchdomain_remove_all(service);
8992 service->state = new_state;
8993 #if defined TIZEN_EXT
8994 if (!is_connected(old_state) && is_connected(new_state))
8995 connman_device_send_connected_signal(
8996 connman_network_get_device(service->network), true);
8997 else if (is_connected(old_state) && !is_connected(new_state))
8998 connman_device_send_connected_signal(
8999 connman_network_get_device(service->network), false);
9001 state_changed(service);
9003 if (!is_connected(old_state) && is_connected(new_state))
9004 searchdomain_add_all(service);
9007 case CONNMAN_SERVICE_STATE_UNKNOWN:
9011 case CONNMAN_SERVICE_STATE_IDLE:
9012 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
9013 __connman_service_disconnect(service);
9017 case CONNMAN_SERVICE_STATE_ASSOCIATION:
9021 case CONNMAN_SERVICE_STATE_CONFIGURATION:
9022 if (!service->new_service &&
9023 __connman_stats_service_register(service) == 0) {
9025 * For new services the statistics are updated after
9026 * we have successfully connected.
9028 __connman_stats_get(service, false,
9029 &service->stats.data);
9030 __connman_stats_get(service, true,
9031 &service->stats_roaming.data);
9036 case CONNMAN_SERVICE_STATE_READY:
9037 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
9039 if (service->new_service &&
9040 __connman_stats_service_register(service) == 0) {
9042 * This is normally done after configuring state
9043 * but for new service do this after we have connected
9046 __connman_stats_get(service, false,
9047 &service->stats.data);
9048 __connman_stats_get(service, true,
9049 &service->stats_roaming.data);
9052 service->new_service = false;
9056 def_service = connman_service_get_default();
9058 service_update_preferred_order(def_service, service, new_state);
9060 __connman_service_set_favorite(service, true);
9062 reply_pending(service, 0);
9064 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
9065 connman_network_get_bool(service->network,
9069 pass = connman_network_get_string(service->network,
9072 __connman_service_set_passphrase(service, pass);
9074 connman_network_set_bool(service->network,
9075 "WiFi.UseWPS", false);
9078 gettimeofday(&service->modified, NULL);
9079 service_save(service);
9081 domain_changed(service);
9082 proxy_changed(service);
9084 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
9085 __connman_notifier_connect(service->type);
9087 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
9088 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
9089 __connman_ipconfig_disable_ipv6(
9090 service->ipconfig_ipv6);
9092 #if !defined TIZEN_MAINTAIN_ONLINE
9093 if (connman_setting_get_bool("SingleConnectedTechnology"))
9094 single_connected_tech(service);
9095 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
9098 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
9102 #if defined TIZEN_EXT
9103 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9104 set_priority_connected_service();
9109 case CONNMAN_SERVICE_STATE_ONLINE:
9110 #if defined TIZEN_MAINTAIN_ONLINE
9111 #if defined TIZEN_EXT
9112 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9113 set_priority_connected_service();
9116 if (connman_setting_get_bool("SingleConnectedTechnology"))
9117 single_connected_tech(service);
9120 #if defined TIZEN_EXT
9121 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9122 connman_service_set_internet_connection(service, true);
9126 case CONNMAN_SERVICE_STATE_DISCONNECT:
9127 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
9129 reply_pending(service, ECONNABORTED);
9133 __connman_wispr_stop(service);
9135 __connman_wpad_stop(service);
9137 #if defined TIZEN_EXT
9139 * Skip the functions if there is any connected profiles
9140 * that use same interface
9142 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
9143 __connman_service_get_connected_count_of_iface(
9146 domain_changed(service);
9147 proxy_changed(service);
9148 #if defined TIZEN_EXT
9153 * Previous services which are connected and which states
9154 * are set to online should reset relevantly ipconfig_state
9155 * to ready so wispr/portal will be rerun on those
9157 downgrade_connected_services();
9159 do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
9162 case CONNMAN_SERVICE_STATE_FAILURE:
9163 #if defined TIZEN_EXT
9164 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9166 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
9168 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
9169 connman_agent_report_error(service, service->path,
9170 error2string(service->error),
9172 get_dbus_sender(service),
9175 service_complete(service);
9179 service_list_sort();
9181 #if defined TIZEN_EXT
9182 #if defined TIZEN_MAINTAIN_ONLINE
9183 __connman_service_connect_default(service, old_state);
9185 __connman_service_connect_default(service);
9189 __connman_connection_update_gateway();
9191 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
9192 new_state != CONNMAN_SERVICE_STATE_READY) ||
9193 (old_state == CONNMAN_SERVICE_STATE_READY &&
9194 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
9195 __connman_notifier_disconnect(service->type);
9198 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
9199 __connman_notifier_enter_online(service->type);
9206 int __connman_service_indicate_error(struct connman_service *service,
9207 enum connman_service_error error)
9209 DBG("service %p error %d", service, error);
9214 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
9217 set_error(service, error);
9219 /* default internet service: fix not cleared if pdp activation*/
9220 #if defined TIZEN_EXT
9222 * If connection failed for default service(DefaultInternet),
9223 * default_connecting_device should be cleared.
9225 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
9226 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
9227 __connman_service_disconnect_default(service);
9229 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
9230 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
9231 g_free(service->passphrase);
9232 service->passphrase = NULL;
9236 __connman_service_ipconfig_indicate_state(service,
9237 CONNMAN_SERVICE_STATE_FAILURE,
9238 CONNMAN_IPCONFIG_TYPE_IPV4);
9239 __connman_service_ipconfig_indicate_state(service,
9240 CONNMAN_SERVICE_STATE_FAILURE,
9241 CONNMAN_IPCONFIG_TYPE_IPV6);
9245 int __connman_service_clear_error(struct connman_service *service)
9247 DBusMessage *pending, *provider_pending;
9249 DBG("service %p", service);
9254 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
9257 pending = service->pending;
9258 service->pending = NULL;
9259 provider_pending = service->provider_pending;
9260 service->provider_pending = NULL;
9262 __connman_service_ipconfig_indicate_state(service,
9263 CONNMAN_SERVICE_STATE_IDLE,
9264 CONNMAN_IPCONFIG_TYPE_IPV6);
9266 __connman_service_ipconfig_indicate_state(service,
9267 CONNMAN_SERVICE_STATE_IDLE,
9268 CONNMAN_IPCONFIG_TYPE_IPV4);
9270 service->pending = pending;
9271 service->provider_pending = provider_pending;
9276 int __connman_service_indicate_default(struct connman_service *service)
9278 DBG("service %p state %s", service, state2string(service->state));
9280 if (!is_connected(service->state)) {
9282 * If service is not yet fully connected, then we must not
9283 * change the default yet. The default gw will be changed
9284 * after the service state is in ready.
9286 return -EINPROGRESS;
9294 enum connman_service_state __connman_service_ipconfig_get_state(
9295 struct connman_service *service,
9296 enum connman_ipconfig_type type)
9299 return CONNMAN_SERVICE_STATE_UNKNOWN;
9301 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9302 return service->state_ipv4;
9304 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
9305 return service->state_ipv6;
9307 return CONNMAN_SERVICE_STATE_UNKNOWN;
9310 #if defined TIZEN_EXT
9311 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
9313 DBG("check the proxy and start wispr");
9314 check_proxy_setup(service);
9320 * How many networks are connected at the same time. If more than 1,
9321 * then set the rp_filter setting properly (loose mode routing) so that network
9322 * connectivity works ok. This is only done for IPv4 networks as IPv6
9323 * does not have rp_filter knob.
9325 static int connected_networks_count;
9326 static int original_rp_filter;
9328 static void service_rp_filter(struct connman_service *service,
9331 enum connman_ipconfig_method method;
9333 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
9336 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
9337 case CONNMAN_IPCONFIG_METHOD_OFF:
9338 case CONNMAN_IPCONFIG_METHOD_AUTO:
9340 case CONNMAN_IPCONFIG_METHOD_FIXED:
9341 case CONNMAN_IPCONFIG_METHOD_MANUAL:
9342 case CONNMAN_IPCONFIG_METHOD_DHCP:
9347 if (connected_networks_count == 1) {
9349 filter_value = __connman_ipconfig_set_rp_filter();
9350 if (filter_value < 0)
9353 original_rp_filter = filter_value;
9355 connected_networks_count++;
9358 if (connected_networks_count == 2)
9359 __connman_ipconfig_unset_rp_filter(original_rp_filter);
9361 connected_networks_count--;
9362 if (connected_networks_count < 0)
9363 connected_networks_count = 0;
9366 DBG("%s %s ipconfig %p method %d count %d filter %d",
9367 connected ? "connected" : "disconnected", service->identifier,
9368 service->ipconfig_ipv4, method,
9369 connected_networks_count, original_rp_filter);
9372 static void redo_wispr(struct connman_service *service,
9373 enum connman_ipconfig_type type)
9375 service->online_timeout = 0;
9376 connman_service_unref(service);
9378 DBG("Retrying %s WISPr for %p %s",
9379 __connman_ipconfig_type2string(type),
9380 service, service->name);
9382 __connman_wispr_start(service, type);
9385 static gboolean redo_wispr_ipv4(gpointer user_data)
9387 struct connman_service *service = user_data;
9389 redo_wispr(service, CONNMAN_IPCONFIG_TYPE_IPV4);
9394 static gboolean redo_wispr_ipv6(gpointer user_data)
9396 struct connman_service *service = user_data;
9398 redo_wispr(service, CONNMAN_IPCONFIG_TYPE_IPV6);
9403 #if defined TIZEN_MAINTAIN_ONLINE
9404 static gboolean redo_wispr_ipv4(gpointer user_data)
9406 struct connman_service *service = user_data;
9410 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
9416 int __connman_service_online_check_failed(struct connman_service *service,
9417 enum connman_ipconfig_type type)
9419 GSourceFunc redo_func;
9422 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
9423 interval = &service->online_check_interval_ipv4;
9424 redo_func = redo_wispr_ipv4;
9426 interval = &service->online_check_interval_ipv6;
9427 redo_func = redo_wispr_ipv6;
9430 DBG("service %p type %s interval %d", service,
9431 __connman_ipconfig_type2string(type), *interval);
9433 service->online_timeout = g_timeout_add_seconds(*interval * *interval,
9434 redo_func, connman_service_ref(service));
9436 /* Increment the interval for the next time, set a maximum timeout of
9437 * ONLINE_CHECK_MAX_INTERVAL * ONLINE_CHECK_MAX_INTERVAL seconds.
9439 if (*interval < ONLINE_CHECK_MAX_INTERVAL)
9445 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
9446 enum connman_service_state new_state,
9447 enum connman_ipconfig_type type)
9449 struct connman_ipconfig *ipconfig = NULL;
9450 enum connman_service_state old_state;
9451 enum connman_ipconfig_method method;
9457 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
9458 case CONNMAN_IPCONFIG_TYPE_ALL:
9461 case CONNMAN_IPCONFIG_TYPE_IPV4:
9462 old_state = service->state_ipv4;
9463 ipconfig = service->ipconfig_ipv4;
9467 case CONNMAN_IPCONFIG_TYPE_IPV6:
9468 old_state = service->state_ipv6;
9469 ipconfig = service->ipconfig_ipv6;
9477 method = __connman_ipconfig_get_method(ipconfig);
9480 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
9481 case CONNMAN_IPCONFIG_METHOD_OFF:
9482 if (new_state != CONNMAN_SERVICE_STATE_IDLE)
9483 connman_warn("ipconfig state %d ipconfig method %d",
9486 #if defined TIZEN_EXT
9487 if (old_state != CONNMAN_SERVICE_STATE_READY &&
9488 old_state != CONNMAN_SERVICE_STATE_ONLINE)
9490 new_state = CONNMAN_SERVICE_STATE_IDLE;
9493 case CONNMAN_IPCONFIG_METHOD_FIXED:
9494 case CONNMAN_IPCONFIG_METHOD_MANUAL:
9495 case CONNMAN_IPCONFIG_METHOD_DHCP:
9496 case CONNMAN_IPCONFIG_METHOD_AUTO:
9502 if (old_state == new_state)
9505 #if defined TIZEN_EXT
9506 __sync_synchronize();
9507 if (service->user_pdn_connection_refcount > 0 &&
9508 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
9509 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
9510 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
9511 new_state == CONNMAN_SERVICE_STATE_IDLE) {
9512 service->user_pdn_connection_refcount = 0;
9513 __sync_synchronize();
9517 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
9518 service, service ? service->identifier : NULL,
9519 old_state, state2string(old_state),
9520 new_state, state2string(new_state),
9521 type, __connman_ipconfig_type2string(type));
9523 switch (new_state) {
9524 case CONNMAN_SERVICE_STATE_UNKNOWN:
9525 case CONNMAN_SERVICE_STATE_ASSOCIATION:
9527 case CONNMAN_SERVICE_STATE_CONFIGURATION:
9529 case CONNMAN_SERVICE_STATE_READY:
9530 #if defined TIZEN_EXT
9531 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
9532 __connman_service_is_internet_profile(service) != TRUE) {
9533 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9534 service_rp_filter(service, TRUE);
9539 if (connman_setting_get_bool("EnableOnlineCheck"))
9540 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
9541 #if !defined TIZEN_EXT
9542 check_proxy_setup(service);
9544 #if defined TIZEN_MAINTAIN_ONLINE
9545 /* if (old_state == CONNMAN_SERVICE_STATE_ONLINE) */
9546 check_proxy_setup(service);
9549 __connman_service_wispr_start(service, type);
9552 connman_info("Online check disabled. "
9553 "Default service remains in READY state.");
9554 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9555 service_rp_filter(service, true);
9556 set_mdns(service, service->mdns_config);
9558 case CONNMAN_SERVICE_STATE_ONLINE:
9560 case CONNMAN_SERVICE_STATE_DISCONNECT:
9561 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
9564 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9565 service_rp_filter(service, false);
9569 case CONNMAN_SERVICE_STATE_IDLE:
9570 case CONNMAN_SERVICE_STATE_FAILURE:
9571 __connman_ipconfig_disable(ipconfig);
9576 if (is_connected(old_state) && !is_connected(new_state)) {
9577 nameserver_remove_all(service, type);
9578 cancel_online_check(service);
9581 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
9582 service->state_ipv4 = new_state;
9584 service->state_ipv6 = new_state;
9586 if (!is_connected(old_state) && is_connected(new_state))
9587 nameserver_add_all(service, type);
9589 __connman_timeserver_sync(service);
9591 #if defined TIZEN_EXT
9592 int ret = service_indicate_state(service);
9593 /*Sent the Ready changed signal again in case IPv4 IP set
9596 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
9597 && new_state == CONNMAN_SERVICE_STATE_READY) {
9598 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
9599 state_changed(service);
9604 return service_indicate_state(service);
9607 static bool prepare_network(struct connman_service *service)
9609 enum connman_network_type type;
9610 unsigned int ssid_len;
9612 type = connman_network_get_type(service->network);
9615 case CONNMAN_NETWORK_TYPE_UNKNOWN:
9616 case CONNMAN_NETWORK_TYPE_VENDOR:
9618 case CONNMAN_NETWORK_TYPE_WIFI:
9619 if (!connman_network_get_blob(service->network, "WiFi.SSID",
9623 if (service->passphrase)
9624 connman_network_set_string(service->network,
9625 "WiFi.Passphrase", service->passphrase);
9627 case CONNMAN_NETWORK_TYPE_ETHERNET:
9628 case CONNMAN_NETWORK_TYPE_GADGET:
9629 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
9630 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
9631 case CONNMAN_NETWORK_TYPE_CELLULAR:
9638 static void prepare_8021x(struct connman_service *service)
9641 connman_network_set_string(service->network, "WiFi.EAP",
9644 if (service->identity)
9645 connman_network_set_string(service->network, "WiFi.Identity",
9648 if (service->anonymous_identity)
9649 connman_network_set_string(service->network,
9650 "WiFi.AnonymousIdentity",
9651 service->anonymous_identity);
9653 if (service->ca_cert_file)
9654 connman_network_set_string(service->network, "WiFi.CACertFile",
9655 service->ca_cert_file);
9657 if (service->subject_match)
9658 connman_network_set_string(service->network, "WiFi.SubjectMatch",
9659 service->subject_match);
9661 if (service->altsubject_match)
9662 connman_network_set_string(service->network, "WiFi.AltSubjectMatch",
9663 service->altsubject_match);
9665 if (service->domain_suffix_match)
9666 connman_network_set_string(service->network, "WiFi.DomainSuffixMatch",
9667 service->domain_suffix_match);
9669 if (service->domain_match)
9670 connman_network_set_string(service->network, "WiFi.DomainMatch",
9671 service->domain_match);
9673 if (service->client_cert_file)
9674 connman_network_set_string(service->network,
9675 "WiFi.ClientCertFile",
9676 service->client_cert_file);
9678 if (service->private_key_file)
9679 connman_network_set_string(service->network,
9680 "WiFi.PrivateKeyFile",
9681 service->private_key_file);
9683 if (service->private_key_passphrase)
9684 connman_network_set_string(service->network,
9685 "WiFi.PrivateKeyPassphrase",
9686 service->private_key_passphrase);
9688 if (service->phase2)
9689 connman_network_set_string(service->network, "WiFi.Phase2",
9692 #if defined TIZEN_EXT
9693 if (service->keymgmt_type)
9694 connman_network_set_string(service->network, "WiFi.KeymgmtType",
9695 service->keymgmt_type);
9697 DBG("service->phase1 : %s", service->phase1);
9698 if (service->phase1)
9699 connman_network_set_string(service->network, "WiFi.Phase1",
9703 #if defined TIZEN_EXT
9705 static bool has_valid_configuration_object(struct connman_service *service)
9707 return service->connector && service->c_sign_key && service->net_access_key;
9710 static void prepare_dpp(struct connman_service *service)
9713 if (service->connector)
9714 connman_network_set_string(service->network, "WiFi.Connector",
9715 service->connector);
9717 if (service->c_sign_key)
9718 connman_network_set_string(service->network, "WiFi.CSignKey",
9719 service->c_sign_key);
9721 if (service->net_access_key)
9722 connman_network_set_string(service->network, "WiFi.NetAccessKey",
9723 service->net_access_key);
9727 static int service_connect(struct connman_service *service)
9731 if (service->hidden)
9734 #if defined TIZEN_EXT
9738 index = __connman_service_get_index(service);
9740 for (list = service_list; list; list = list->next) {
9741 struct connman_service *temp = list->data;
9743 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
9746 if (!is_connecting(temp->state) && !is_connected(temp->state))
9749 if (service == temp)
9752 if (service->type != temp->type)
9755 if (__connman_service_get_index(temp) == index &&
9756 __connman_service_disconnect(temp) == -EINPROGRESS)
9757 return -EINPROGRESS;
9761 switch (service->type) {
9762 case CONNMAN_SERVICE_TYPE_UNKNOWN:
9763 case CONNMAN_SERVICE_TYPE_SYSTEM:
9764 case CONNMAN_SERVICE_TYPE_GPS:
9765 case CONNMAN_SERVICE_TYPE_P2P:
9766 #if defined TIZEN_EXT_WIFI_MESH
9767 case CONNMAN_SERVICE_TYPE_MESH:
9770 case CONNMAN_SERVICE_TYPE_ETHERNET:
9771 case CONNMAN_SERVICE_TYPE_GADGET:
9772 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
9773 case CONNMAN_SERVICE_TYPE_CELLULAR:
9774 case CONNMAN_SERVICE_TYPE_VPN:
9776 case CONNMAN_SERVICE_TYPE_WIFI:
9777 switch (service->security) {
9778 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
9779 case CONNMAN_SERVICE_SECURITY_NONE:
9780 #if defined TIZEN_EXT
9781 case CONNMAN_SERVICE_SECURITY_OWE:
9784 case CONNMAN_SERVICE_SECURITY_WEP:
9785 case CONNMAN_SERVICE_SECURITY_PSK:
9786 case CONNMAN_SERVICE_SECURITY_WPA:
9787 case CONNMAN_SERVICE_SECURITY_RSN:
9788 #if defined TIZEN_EXT
9789 case CONNMAN_SERVICE_SECURITY_SAE:
9791 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
9794 if (!service->passphrase) {
9795 if (!service->network)
9798 if (!service->wps ||
9799 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
9804 #if defined TIZEN_EXT
9805 case CONNMAN_SERVICE_SECURITY_DPP:
9806 if (has_valid_configuration_object(service) &&
9811 case CONNMAN_SERVICE_SECURITY_8021X:
9812 if (!service->eap) {
9813 connman_warn("EAP type has not been found. "
9814 "Most likely ConnMan is not able to "
9815 "find a configuration for given "
9817 "Check SSID or Name match with the "
9822 #if defined TIZEN_EXT
9824 * never request credentials if using EAP-TLS, EAP-SIM
9825 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
9826 * need to be fully provisioned)
9828 DBG("service eap: %s", service->eap);
9829 if (g_str_equal(service->eap, "tls") ||
9830 g_str_equal(service->eap, "sim") ||
9831 g_str_equal(service->eap, "aka") ||
9832 g_str_equal(service->eap, "aka'") ||
9833 g_str_equal(service->eap, "pwd") ||
9834 g_str_equal(service->eap, "fast"))
9838 * never request credentials if using EAP-TLS
9839 * (EAP-TLS networks need to be fully provisioned)
9841 if (g_str_equal(service->eap, "tls"))
9846 * Return -ENOKEY if either identity or passphrase is
9847 * missing. Agent provided credentials can be used as
9848 * fallback if needed.
9850 if (((!service->identity &&
9851 !service->agent_identity) ||
9852 !service->passphrase) ||
9853 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
9861 if (service->network) {
9862 if (!prepare_network(service))
9865 switch (service->security) {
9866 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
9867 case CONNMAN_SERVICE_SECURITY_NONE:
9868 case CONNMAN_SERVICE_SECURITY_WEP:
9869 case CONNMAN_SERVICE_SECURITY_PSK:
9870 case CONNMAN_SERVICE_SECURITY_WPA:
9871 case CONNMAN_SERVICE_SECURITY_RSN:
9872 #if defined TIZEN_EXT
9873 case CONNMAN_SERVICE_SECURITY_SAE:
9874 case CONNMAN_SERVICE_SECURITY_OWE:
9876 case CONNMAN_SERVICE_SECURITY_DPP:
9877 prepare_dpp(service);
9880 case CONNMAN_SERVICE_SECURITY_8021X:
9881 prepare_8021x(service);
9885 if (__connman_stats_service_register(service) == 0) {
9886 __connman_stats_get(service, false,
9887 &service->stats.data);
9888 __connman_stats_get(service, true,
9889 &service->stats_roaming.data);
9892 err = __connman_network_connect(service->network);
9893 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
9895 err = __connman_provider_connect(service->provider,
9896 get_dbus_sender(service));
9901 if (err != -EINPROGRESS) {
9902 __connman_service_ipconfig_indicate_state(service,
9903 CONNMAN_SERVICE_STATE_FAILURE,
9904 CONNMAN_IPCONFIG_TYPE_IPV4);
9905 __connman_service_ipconfig_indicate_state(service,
9906 CONNMAN_SERVICE_STATE_FAILURE,
9907 CONNMAN_IPCONFIG_TYPE_IPV6);
9908 __connman_stats_service_unregister(service);
9915 int __connman_service_connect(struct connman_service *service,
9916 enum connman_service_connect_reason reason)
9920 DBG("service %p state %s connect reason %s -> %s",
9921 service, state2string(service->state),
9922 reason2string(service->connect_reason),
9923 reason2string(reason));
9925 if (is_connected(service->state))
9928 if (is_connecting(service->state))
9931 switch (service->type) {
9932 case CONNMAN_SERVICE_TYPE_UNKNOWN:
9933 case CONNMAN_SERVICE_TYPE_SYSTEM:
9934 case CONNMAN_SERVICE_TYPE_GPS:
9935 case CONNMAN_SERVICE_TYPE_P2P:
9936 #if defined TIZEN_EXT_WIFI_MESH
9937 case CONNMAN_SERVICE_TYPE_MESH:
9941 case CONNMAN_SERVICE_TYPE_ETHERNET:
9942 case CONNMAN_SERVICE_TYPE_GADGET:
9943 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
9944 case CONNMAN_SERVICE_TYPE_CELLULAR:
9945 case CONNMAN_SERVICE_TYPE_VPN:
9946 case CONNMAN_SERVICE_TYPE_WIFI:
9950 if (!is_ipconfig_usable(service))
9953 __connman_service_clear_error(service);
9955 err = service_connect(service);
9957 DBG("service %p err %d", service, err);
9959 service->connect_reason = reason;
9960 #if defined TIZEN_EXT
9961 connect_reason_changed(service);
9967 if (err == -EINPROGRESS) {
9968 if (service->timeout == 0)
9969 service->timeout = g_timeout_add_seconds(
9970 CONNECT_TIMEOUT, connect_timeout, service);
9972 return -EINPROGRESS;
9975 if (service->network)
9976 __connman_network_disconnect(service->network);
9977 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
9979 connman_provider_disconnect(service->provider);
9981 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
9982 if (err == -ENOKEY || err == -EPERM) {
9983 DBusMessage *pending = NULL;
9984 const char *dbus_sender = get_dbus_sender(service);
9987 * We steal the reply here. The idea is that the
9988 * connecting client will see the connection status
9989 * after the real hidden network is connected or
9990 * connection failed.
9992 if (service->hidden) {
9993 pending = service->pending;
9994 service->pending = NULL;
9997 err = __connman_agent_request_passphrase_input(service,
10001 if (service->hidden && err != -EINPROGRESS)
10002 service->pending = pending;
10011 int __connman_service_disconnect(struct connman_service *service)
10015 DBG("service %p", service);
10017 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
10018 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
10020 connman_agent_cancel(service);
10022 __connman_stats_service_unregister(service);
10024 if (service->network) {
10025 err = __connman_network_disconnect(service->network);
10026 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
10028 err = connman_provider_disconnect(service->provider);
10030 return -EOPNOTSUPP;
10032 if (err < 0 && err != -EINPROGRESS)
10035 __connman_6to4_remove(service->ipconfig_ipv4);
10037 if (service->ipconfig_ipv4)
10038 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
10041 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
10044 #if defined TIZEN_EXT
10046 * Skip the functions If there is any connected profiles
10047 * that use same interface
10049 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
10050 __connman_service_get_connected_count_of_iface(service) <= 0) {
10052 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
10053 settings_changed(service, service->ipconfig_ipv4);
10055 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
10056 settings_changed(service, service->ipconfig_ipv6);
10058 __connman_ipconfig_disable(service->ipconfig_ipv4);
10059 __connman_ipconfig_disable(service->ipconfig_ipv6);
10060 #if defined TIZEN_EXT
10067 int __connman_service_disconnect_all(void)
10069 struct connman_service *service;
10070 GSList *services = NULL, *list;
10075 for (iter = service_list; iter; iter = iter->next) {
10076 service = iter->data;
10078 if (!is_connected(service->state))
10081 services = g_slist_prepend(services, service);
10084 for (list = services; list; list = list->next) {
10085 struct connman_service *service = list->data;
10087 service->ignore = true;
10089 __connman_service_disconnect(service);
10092 g_slist_free(services);
10098 * lookup_by_identifier:
10099 * @identifier: service identifier
10101 * Look up a service by identifier (reference count will not be increased)
10103 static struct connman_service *lookup_by_identifier(const char *identifier)
10105 return g_hash_table_lookup(service_hash, identifier);
10108 struct connman_service *connman_service_lookup_from_identifier(const char* identifier)
10110 return identifier ? lookup_by_identifier(identifier) : NULL;
10113 struct provision_user_data {
10118 static void provision_changed(gpointer value, gpointer user_data)
10120 struct connman_service *service = value;
10121 struct provision_user_data *data = user_data;
10122 const char *path = data->ident;
10125 ret = __connman_config_provision_service_ident(service, path,
10126 service->config_file, service->config_entry);
10131 int __connman_service_provision_changed(const char *ident)
10133 struct provision_user_data data = {
10138 g_list_foreach(service_list, provision_changed, (void *)&data);
10141 * Because the provision_changed() might have set some services
10142 * as favorite, we must sort the sequence now.
10144 if (services_dirty) {
10145 services_dirty = false;
10147 service_list_sort();
10149 __connman_connection_update_gateway();
10155 void __connman_service_set_config(struct connman_service *service,
10156 const char *file_id, const char *entry)
10161 g_free(service->config_file);
10162 service->config_file = g_strdup(file_id);
10164 g_free(service->config_entry);
10165 service->config_entry = g_strdup(entry);
10169 * __connman_service_get:
10170 * @identifier: service identifier
10172 * Look up a service by identifier or create a new one if not found
10174 static struct connman_service *service_get(const char *identifier)
10176 struct connman_service *service;
10178 service = g_hash_table_lookup(service_hash, identifier);
10180 connman_service_ref(service);
10184 service = connman_service_create();
10187 #if defined TIZEN_EXT
10188 if (!simplified_log)
10190 DBG("service %p", service);
10192 service->identifier = g_strdup(identifier);
10194 service_list = g_list_insert_sorted(service_list, service,
10197 g_hash_table_insert(service_hash, service->identifier, service);
10202 static int service_register(struct connman_service *service)
10204 #if defined TIZEN_EXT
10205 if (!simplified_log)
10207 DBG("service %p", service);
10212 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
10213 service->identifier);
10215 DBG("path %s", service->path);
10217 #if defined TIZEN_EXT
10219 service_load(service);
10220 ret = service_ext_load(service);
10221 if (ret == -ERANGE)
10222 service_ext_save(service);
10223 ret = __connman_config_provision_service(service);
10224 if (ret < 0 && !simplified_log)
10225 DBG("Failed to provision service");
10227 if (__connman_config_provision_service(service) < 0)
10228 service_load(service);
10231 g_dbus_register_interface(connection, service->path,
10232 CONNMAN_SERVICE_INTERFACE,
10233 service_methods, service_signals,
10234 NULL, service, NULL);
10236 service_list_sort();
10238 __connman_connection_update_gateway();
10243 static void service_up(struct connman_ipconfig *ipconfig,
10244 const char *ifname)
10246 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10248 DBG("%s up", ifname);
10250 link_changed(service);
10252 service->stats.valid = false;
10253 service->stats_roaming.valid = false;
10256 static void service_down(struct connman_ipconfig *ipconfig,
10257 const char *ifname)
10259 DBG("%s down", ifname);
10262 static void service_lower_up(struct connman_ipconfig *ipconfig,
10263 const char *ifname)
10265 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10267 DBG("%s lower up", ifname);
10269 stats_start(service);
10272 static void service_lower_down(struct connman_ipconfig *ipconfig,
10273 const char *ifname)
10275 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10277 DBG("%s lower down", ifname);
10279 stats_stop(service);
10280 service_save(service);
10283 static void service_ip_bound(struct connman_ipconfig *ipconfig,
10284 const char *ifname)
10286 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10287 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
10288 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
10289 #if defined TIZEN_EXT
10293 DBG("%s ip bound", ifname);
10295 type = __connman_ipconfig_get_config_type(ipconfig);
10296 method = __connman_ipconfig_get_method(ipconfig);
10298 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
10301 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
10302 method == CONNMAN_IPCONFIG_METHOD_AUTO)
10303 #if defined TIZEN_EXT
10305 err = __connman_ipconfig_gateway_add(ipconfig, service);
10308 DBG("Failed to add gateway");
10311 __connman_service_ipconfig_indicate_state(service,
10312 CONNMAN_SERVICE_STATE_READY,
10313 CONNMAN_IPCONFIG_TYPE_IPV6);
10316 settings_changed(service, ipconfig);
10317 address_updated(service, type);
10320 static void service_ip_release(struct connman_ipconfig *ipconfig,
10321 const char *ifname)
10323 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10324 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
10325 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
10327 DBG("%s ip release", ifname);
10329 type = __connman_ipconfig_get_config_type(ipconfig);
10330 method = __connman_ipconfig_get_method(ipconfig);
10332 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
10335 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
10336 method == CONNMAN_IPCONFIG_METHOD_OFF)
10337 __connman_service_ipconfig_indicate_state(service,
10338 CONNMAN_SERVICE_STATE_DISCONNECT,
10339 CONNMAN_IPCONFIG_TYPE_IPV6);
10341 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
10342 method == CONNMAN_IPCONFIG_METHOD_OFF)
10343 __connman_service_ipconfig_indicate_state(service,
10344 CONNMAN_SERVICE_STATE_DISCONNECT,
10345 CONNMAN_IPCONFIG_TYPE_IPV4);
10347 settings_changed(service, ipconfig);
10350 static void service_route_changed(struct connman_ipconfig *ipconfig,
10351 const char *ifname)
10353 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
10355 DBG("%s route changed", ifname);
10357 settings_changed(service, ipconfig);
10360 static const struct connman_ipconfig_ops service_ops = {
10362 .down = service_down,
10363 .lower_up = service_lower_up,
10364 .lower_down = service_lower_down,
10365 .ip_bound = service_ip_bound,
10366 .ip_release = service_ip_release,
10367 .route_set = service_route_changed,
10368 .route_unset = service_route_changed,
10371 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
10372 int index, enum connman_ipconfig_method method)
10374 struct connman_ipconfig *ipconfig_ipv4;
10376 ipconfig_ipv4 = __connman_ipconfig_create(index,
10377 CONNMAN_IPCONFIG_TYPE_IPV4);
10378 if (!ipconfig_ipv4)
10381 __connman_ipconfig_set_method(ipconfig_ipv4, method);
10383 __connman_ipconfig_set_data(ipconfig_ipv4, service);
10385 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
10387 return ipconfig_ipv4;
10390 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
10393 struct connman_ipconfig *ipconfig_ipv6;
10395 ipconfig_ipv6 = __connman_ipconfig_create(index,
10396 CONNMAN_IPCONFIG_TYPE_IPV6);
10397 if (!ipconfig_ipv6)
10400 __connman_ipconfig_set_data(ipconfig_ipv6, service);
10402 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
10404 return ipconfig_ipv6;
10407 void __connman_service_read_ip4config(struct connman_service *service)
10411 if (!service->ipconfig_ipv4)
10414 keyfile = connman_storage_load_service(service->identifier);
10418 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
10419 service->identifier, "IPv4.");
10421 g_key_file_free(keyfile);
10424 void connman_service_create_ip4config(struct connman_service *service,
10427 DBG("ipv4 %p", service->ipconfig_ipv4);
10429 if (service->ipconfig_ipv4)
10432 service->ipconfig_ipv4 = create_ip4config(service, index,
10433 CONNMAN_IPCONFIG_METHOD_DHCP);
10434 __connman_service_read_ip4config(service);
10437 void __connman_service_read_ip6config(struct connman_service *service)
10441 if (!service->ipconfig_ipv6)
10444 keyfile = connman_storage_load_service(service->identifier);
10448 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
10449 service->identifier, "IPv6.");
10451 g_key_file_free(keyfile);
10454 void connman_service_create_ip6config(struct connman_service *service,
10457 DBG("ipv6 %p", service->ipconfig_ipv6);
10459 if (service->ipconfig_ipv6)
10462 service->ipconfig_ipv6 = create_ip6config(service, index);
10464 __connman_service_read_ip6config(service);
10468 * connman_service_lookup_from_network:
10469 * @network: network structure
10471 * Look up a service by network (reference count will not be increased)
10473 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
10475 struct connman_service *service;
10476 const char *ident, *group;
10482 ident = __connman_network_get_ident(network);
10486 group = connman_network_get_group(network);
10490 name = g_strdup_printf("%s_%s_%s",
10491 __connman_network_get_type(network), ident, group);
10492 service = lookup_by_identifier(name);
10498 struct connman_service *__connman_service_lookup_from_index(int index)
10500 struct connman_service *service;
10503 for (list = service_list; list; list = list->next) {
10504 service = list->data;
10506 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
10510 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
10518 const char *connman_service_get_identifier(struct connman_service *service)
10520 return service ? service->identifier : NULL;
10523 const char *__connman_service_get_path(struct connman_service *service)
10525 return service->path;
10528 const char *__connman_service_get_name(struct connman_service *service)
10530 return service->name;
10533 enum connman_service_state connman_service_get_state(struct connman_service *service)
10535 return service ? service->state : CONNMAN_SERVICE_STATE_UNKNOWN;
10538 static enum connman_service_type convert_network_type(struct connman_network *network)
10540 enum connman_network_type type = connman_network_get_type(network);
10543 case CONNMAN_NETWORK_TYPE_UNKNOWN:
10544 case CONNMAN_NETWORK_TYPE_VENDOR:
10546 case CONNMAN_NETWORK_TYPE_ETHERNET:
10547 return CONNMAN_SERVICE_TYPE_ETHERNET;
10548 case CONNMAN_NETWORK_TYPE_WIFI:
10549 return CONNMAN_SERVICE_TYPE_WIFI;
10550 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
10551 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
10552 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
10553 case CONNMAN_NETWORK_TYPE_CELLULAR:
10554 return CONNMAN_SERVICE_TYPE_CELLULAR;
10555 case CONNMAN_NETWORK_TYPE_GADGET:
10556 return CONNMAN_SERVICE_TYPE_GADGET;
10559 return CONNMAN_SERVICE_TYPE_UNKNOWN;
10562 static enum connman_service_security convert_wifi_security(const char *security)
10565 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
10566 else if (g_str_equal(security, "none"))
10567 return CONNMAN_SERVICE_SECURITY_NONE;
10568 else if (g_str_equal(security, "wep"))
10569 return CONNMAN_SERVICE_SECURITY_WEP;
10570 else if (g_str_equal(security, "psk"))
10571 return CONNMAN_SERVICE_SECURITY_PSK;
10572 else if (g_str_equal(security, "ieee8021x"))
10573 return CONNMAN_SERVICE_SECURITY_8021X;
10574 else if (g_str_equal(security, "wpa"))
10575 return CONNMAN_SERVICE_SECURITY_WPA;
10576 else if (g_str_equal(security, "rsn"))
10577 return CONNMAN_SERVICE_SECURITY_RSN;
10578 #if defined TIZEN_EXT
10579 else if (g_str_equal(security, "sae"))
10580 return CONNMAN_SERVICE_SECURITY_SAE;
10581 else if (g_str_equal(security, "owe"))
10582 return CONNMAN_SERVICE_SECURITY_OWE;
10583 else if (g_str_equal(security, "dpp"))
10584 return CONNMAN_SERVICE_SECURITY_DPP;
10585 else if (g_str_equal(security, "ft_psk") == TRUE)
10586 return CONNMAN_SERVICE_SECURITY_PSK;
10587 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
10588 return CONNMAN_SERVICE_SECURITY_8021X;
10591 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
10594 #if defined TIZEN_EXT
10595 int check_passphrase_ext(struct connman_network *network,
10596 const char *passphrase)
10599 enum connman_service_security security;
10601 str = connman_network_get_string(network, "WiFi.Security");
10602 security = convert_wifi_security(str);
10604 return __connman_service_check_passphrase(security, passphrase);
10608 static void update_wps_values(struct connman_service *service,
10609 struct connman_network *network)
10611 bool wps = connman_network_get_bool(network, "WiFi.WPS");
10612 bool wps_advertising = connman_network_get_bool(network,
10613 "WiFi.WPSAdvertising");
10615 if (service->wps != wps ||
10616 service->wps_advertizing != wps_advertising) {
10617 service->wps = wps;
10618 service->wps_advertizing = wps_advertising;
10619 security_changed(service);
10623 static void update_from_network(struct connman_service *service,
10624 struct connman_network *network)
10626 uint8_t strength = service->strength;
10629 DBG("service %p network %p", service, network);
10631 if (is_connected(service->state))
10634 if (is_connecting(service->state))
10637 str = connman_network_get_string(network, "Name");
10639 g_free(service->name);
10640 service->name = g_strdup(str);
10641 service->hidden = false;
10643 g_free(service->name);
10644 service->name = NULL;
10645 service->hidden = true;
10648 service->strength = connman_network_get_strength(network);
10649 service->roaming = connman_network_get_bool(network, "Roaming");
10651 if (service->strength == 0) {
10653 * Filter out 0-values; it's unclear what they mean
10654 * and they cause anomalous sorting of the priority list.
10656 service->strength = strength;
10659 str = connman_network_get_string(network, "WiFi.Security");
10660 service->security = convert_wifi_security(str);
10662 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
10663 update_wps_values(service, network);
10665 if (service->strength > strength && service->network) {
10666 connman_network_unref(service->network);
10667 service->network = connman_network_ref(network);
10669 strength_changed(service);
10672 if (!service->network)
10673 service->network = connman_network_ref(network);
10675 service_list_sort();
10679 * __connman_service_create_from_network:
10680 * @network: network structure
10682 * Look up service by network and if not found, create one
10684 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
10686 struct connman_service *service;
10687 struct connman_device *device;
10688 const char *ident, *group;
10690 unsigned int *auto_connect_types, *favorite_types;
10693 DBG("network %p", network);
10698 ident = __connman_network_get_ident(network);
10702 group = connman_network_get_group(network);
10706 name = g_strdup_printf("%s_%s_%s",
10707 __connman_network_get_type(network), ident, group);
10708 service = service_get(name);
10714 if (__connman_network_get_weakness(network))
10717 if (service->path) {
10718 update_from_network(service, network);
10719 __connman_connection_update_gateway();
10723 service->type = convert_network_type(network);
10725 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
10726 service->autoconnect = false;
10727 for (i = 0; auto_connect_types &&
10728 auto_connect_types[i] != 0; i++) {
10729 if (service->type == auto_connect_types[i]) {
10730 service->autoconnect = true;
10735 favorite_types = connman_setting_get_uint_list("DefaultFavoriteTechnologies");
10736 service->favorite = false;
10737 for (i = 0; favorite_types && favorite_types[i] != 0; i++) {
10738 if (service->type == favorite_types[i]) {
10739 service->favorite = true;
10744 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
10745 service->state = combine_state(service->state_ipv4, service->state_ipv6);
10747 update_from_network(service, network);
10749 index = connman_network_get_index(network);
10751 if (!service->ipconfig_ipv4)
10752 service->ipconfig_ipv4 = create_ip4config(service, index,
10753 CONNMAN_IPCONFIG_METHOD_DHCP);
10755 if (!service->ipconfig_ipv6)
10756 service->ipconfig_ipv6 = create_ip6config(service, index);
10758 service_register(service);
10759 service_schedule_added(service);
10761 if (service->favorite) {
10762 device = connman_network_get_device(service->network);
10763 if (device && !connman_device_get_scanning(device,
10764 CONNMAN_SERVICE_TYPE_UNKNOWN)) {
10766 switch (service->type) {
10767 case CONNMAN_SERVICE_TYPE_UNKNOWN:
10768 case CONNMAN_SERVICE_TYPE_SYSTEM:
10769 case CONNMAN_SERVICE_TYPE_P2P:
10770 #if defined TIZEN_EXT_WIFI_MESH
10771 case CONNMAN_SERVICE_TYPE_MESH:
10775 case CONNMAN_SERVICE_TYPE_GADGET:
10776 case CONNMAN_SERVICE_TYPE_ETHERNET:
10777 if (service->autoconnect) {
10778 __connman_service_connect(service,
10779 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
10784 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
10785 case CONNMAN_SERVICE_TYPE_GPS:
10786 case CONNMAN_SERVICE_TYPE_VPN:
10787 case CONNMAN_SERVICE_TYPE_WIFI:
10788 case CONNMAN_SERVICE_TYPE_CELLULAR:
10789 do_auto_connect(service,
10790 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
10795 #if defined TIZEN_EXT
10796 /* TIZEN synchronizes below information when the service creates */
10797 if (service->eap != NULL)
10798 connman_network_set_string(service->network, "WiFi.EAP",
10800 if (service->identity != NULL)
10801 connman_network_set_string(service->network, "WiFi.Identity",
10802 service->identity);
10803 if (service->phase2 != NULL)
10804 connman_network_set_string(service->network, "WiFi.Phase2",
10806 if (service->eap != NULL)
10807 connman_network_set_string(service->network, "WiFi.Connector",
10808 service->connector);
10809 if (service->identity != NULL)
10810 connman_network_set_string(service->network, "WiFi.CSignKey",
10811 service->c_sign_key);
10812 if (service->phase2 != NULL)
10813 connman_network_set_string(service->network, "WiFi.NetAccessKey",
10814 service->net_access_key);
10818 __connman_notifier_service_add(service, service->name);
10823 #if defined TIZEN_EXT
10824 void __connman_service_notify_strength_changed(struct connman_network *network)
10826 struct connman_service *service;
10827 uint8_t strength = 0;
10829 service = connman_service_lookup_from_network(network);
10833 if (!service->network)
10836 strength = connman_network_get_strength(service->network);
10837 if (strength == service->strength)
10840 service->strength = strength;
10841 if (!simplified_log)
10842 DBG("Strength %d", strength);
10843 strength_changed(service);
10844 service_list_sort();
10848 void __connman_service_update_from_network(struct connman_network *network)
10850 bool need_sort = false;
10851 struct connman_service *service;
10856 #if defined TIZEN_EXT
10857 bool need_save = false;
10860 service = connman_service_lookup_from_network(network);
10864 if (!service->network)
10867 #if defined TIZEN_EXT
10868 if (service->storage_reload) {
10869 service_load(service);
10870 __connman_service_set_storage_reload(service, false);
10874 name = connman_network_get_string(service->network, "Name");
10875 if (g_strcmp0(service->name, name) != 0) {
10876 g_free(service->name);
10877 service->name = g_strdup(name);
10879 if (allow_property_changed(service))
10880 connman_dbus_property_changed_basic(service->path,
10881 CONNMAN_SERVICE_INTERFACE, "Name",
10882 DBUS_TYPE_STRING, &service->name);
10885 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
10886 update_wps_values(service, network);
10888 strength = connman_network_get_strength(service->network);
10889 if (strength == service->strength)
10892 service->strength = strength;
10895 strength_changed(service);
10898 roaming = connman_network_get_bool(service->network, "Roaming");
10899 if (roaming == service->roaming)
10902 stats_enable = stats_enabled(service);
10904 stats_stop(service);
10906 service->roaming = roaming;
10910 stats_start(service);
10912 roaming_changed(service);
10915 #if defined TIZEN_EXT
10916 need_save |= update_last_connected_bssid(service);
10917 need_save |= update_assoc_reject(service);
10919 g_get_current_time(&service->modified);
10920 service_ext_save(service);
10926 service_list_sort();
10930 void __connman_service_remove_from_network(struct connman_network *network)
10932 struct connman_service *service;
10934 service = connman_service_lookup_from_network(network);
10936 DBG("network %p service %p", network, service);
10941 service->ignore = true;
10943 __connman_connection_gateway_remove(service,
10944 CONNMAN_IPCONFIG_TYPE_ALL);
10946 connman_service_unref(service);
10950 * __connman_service_create_from_provider:
10951 * @provider: provider structure
10953 * Look up service by provider and if not found, create one
10955 struct connman_service *
10956 __connman_service_create_from_provider(struct connman_provider *provider)
10958 struct connman_service *service;
10959 const char *ident, *str;
10961 int index = connman_provider_get_index(provider);
10963 DBG("provider %p", provider);
10965 ident = __connman_provider_get_ident(provider);
10969 name = g_strdup_printf("vpn_%s", ident);
10970 service = service_get(name);
10976 service->type = CONNMAN_SERVICE_TYPE_VPN;
10977 service->order = service->do_split_routing ? 0 : 10;
10978 service->provider = connman_provider_ref(provider);
10979 service->autoconnect = false;
10980 service->favorite = true;
10982 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
10983 service->state = combine_state(service->state_ipv4, service->state_ipv6);
10985 str = connman_provider_get_string(provider, "Name");
10987 g_free(service->name);
10988 service->name = g_strdup(str);
10989 service->hidden = false;
10991 g_free(service->name);
10992 service->name = NULL;
10993 service->hidden = true;
10996 service->strength = 0;
10998 if (!service->ipconfig_ipv4)
10999 service->ipconfig_ipv4 = create_ip4config(service, index,
11000 CONNMAN_IPCONFIG_METHOD_MANUAL);
11002 if (!service->ipconfig_ipv6)
11003 service->ipconfig_ipv6 = create_ip6config(service, index);
11005 service_register(service);
11007 __connman_notifier_service_add(service, service->name);
11008 service_schedule_added(service);
11013 static void remove_unprovisioned_services(void)
11016 GKeyFile *keyfile, *configkeyfile;
11017 char *file, *section;
11020 services = connman_storage_get_services();
11024 for (; services[i]; i++) {
11025 file = section = NULL;
11026 keyfile = configkeyfile = NULL;
11028 keyfile = connman_storage_load_service(services[i]);
11032 file = g_key_file_get_string(keyfile, services[i],
11033 "Config.file", NULL);
11037 section = g_key_file_get_string(keyfile, services[i],
11038 "Config.ident", NULL);
11042 configkeyfile = __connman_storage_load_config(file);
11043 if (!configkeyfile) {
11045 * Config file is missing, remove the provisioned
11048 __connman_storage_remove_service(services[i]);
11052 if (!g_key_file_has_group(configkeyfile, section))
11054 * Config section is missing, remove the provisioned
11057 __connman_storage_remove_service(services[i]);
11061 g_key_file_free(keyfile);
11064 g_key_file_free(configkeyfile);
11070 g_strfreev(services);
11073 static int agent_probe(struct connman_agent *agent)
11075 DBG("agent %p", agent);
11079 static void agent_remove(struct connman_agent *agent)
11081 DBG("agent %p", agent);
11084 static void *agent_context_ref(void *context)
11086 struct connman_service *service = context;
11088 return (void *)connman_service_ref(service);
11091 static void agent_context_unref(void *context)
11093 struct connman_service *service = context;
11095 connman_service_unref(service);
11098 static struct connman_agent_driver agent_driver = {
11100 .interface = CONNMAN_AGENT_INTERFACE,
11101 .probe = agent_probe,
11102 .remove = agent_remove,
11103 .context_ref = agent_context_ref,
11104 .context_unref = agent_context_unref,
11107 #if defined TIZEN_EXT
11108 static void ins_setting_init(void)
11111 const char *string;
11112 char **string_list;
11113 unsigned int string_count;
11115 ins_settings.last_user_selection = connman_setting_get_bool("INSLastUserSelection");
11116 ins_settings.last_user_selection_time = connman_setting_get_uint("INSLastUserSelectionTime");
11117 ins_settings.last_connected = connman_setting_get_bool("INSLastConnected");
11119 string = connman_option_get_string("INSPreferredFreq");
11120 if (g_strcmp0(string, "5GHz") == 0)
11121 ins_settings.preferred_freq = CONNMAN_INS_PREFERRED_FREQ_5GHZ;
11122 else if (g_strcmp0(string, "2.4GHz") == 0)
11123 ins_settings.preferred_freq = CONNMAN_INS_PREFERRED_FREQ_24GHZ;
11125 ins_settings.preferred_freq = CONNMAN_INS_PREFERRED_FREQ_UNKNOWN;
11127 ins_settings.security_priority_count = connman_setting_get_uint("INSSecurityPriorityCount");
11128 ins_settings.security_priority_score = connman_setting_get_uint("INSSecurityPriorityScore");
11129 string_count = ins_settings.security_priority_count;
11131 memset(ins_settings.security_priority, 0, sizeof(ins_settings.security_priority));
11132 string_list = connman_setting_get_string_list("INSSecurityPriority");
11133 for (i = 0; string_list && string_list[i]; i++) {
11134 unsigned int security_score = string_count * ins_settings.security_priority_score;
11136 if (g_strcmp0(string_list[i], "WEP") == 0)
11137 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_WEP] = security_score;
11138 else if (g_strcmp0(string_list[i], "PSK") == 0)
11139 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_PSK] = security_score;
11140 else if (g_strcmp0(string_list[i], "8021X") == 0)
11141 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_8021X] = security_score;
11142 else if (g_strcmp0(string_list[i], "WPA") == 0)
11143 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_WPA] = security_score;
11144 else if (g_strcmp0(string_list[i], "RSN") == 0)
11145 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_RSN] = security_score;
11146 else if (g_strcmp0(string_list[i], "SAE") == 0)
11147 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_SAE] = security_score;
11148 else if (g_strcmp0(string_list[i], "OWE") == 0)
11149 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_OWE] = security_score;
11150 else if (g_strcmp0(string_list[i], "DPP") == 0)
11151 ins_settings.security_priority[CONNMAN_SERVICE_SECURITY_DPP] = security_score;
11156 ins_settings.signal = connman_setting_get_bool("INSSignal");
11157 ins_settings.internet = connman_setting_get_bool("INSInternet");
11159 ins_settings.last_user_selection_score = connman_setting_get_uint("INSLastUserSelectionScore");
11160 ins_settings.last_connected_score = connman_setting_get_uint("INSLastConnectedScore");
11161 ins_settings.preferred_freq_score = connman_setting_get_uint("INSPreferredFreqScore");
11162 ins_settings.internet_score = connman_setting_get_uint("INSInternetScore");
11164 ins_settings.signal_level3_5ghz = connman_setting_get_int("INSSignalLevel3_5GHz");
11165 ins_settings.signal_level3_24ghz = connman_setting_get_int("INSSignalLevel3_24GHz");
11167 DBG("last_user_selection [%s]", ins_settings.last_user_selection ? "true" : "false");
11168 DBG("last_user_selection_time [%d]", ins_settings.last_user_selection_time);
11169 DBG("last_user_selection_score [%d]", ins_settings.last_user_selection_score);
11171 DBG("last_connected [%s]", ins_settings.last_connected ? "true" : "false");
11172 DBG("last_connected_score [%d]", ins_settings.last_connected_score);
11174 DBG("preferred_freq [%s]", ins_settings.preferred_freq ? "true" : "false");
11175 DBG("preferred_freq_score [%d]", ins_settings.preferred_freq_score);
11177 DBG("security_priority_count [%d]", ins_settings.security_priority_count);
11178 for (i = 0; i < CONNMAN_SERVICE_SECURITY_MAX; i++) {
11179 if (ins_settings.security_priority[i])
11180 DBG("security_priority %s [%d]", security2string(i),
11181 ins_settings.security_priority[i]);
11183 DBG("security_priority_score [%d]", ins_settings.security_priority_score);
11185 DBG("signal [%s]", ins_settings.signal ? "true" : "false");
11187 DBG("internet [%s]", ins_settings.internet ? "true" : "false");
11188 DBG("internet_score [%d]", ins_settings.internet_score);
11190 DBG("signal_level3_5ghz [%d]", ins_settings.signal_level3_5ghz);
11191 DBG("signal_level3_24ghz [%d]", ins_settings.signal_level3_24ghz);
11195 int __connman_service_init(void)
11201 err = connman_agent_driver_register(&agent_driver);
11203 connman_error("Cannot register agent driver for %s",
11204 agent_driver.name);
11208 set_always_connecting_technologies();
11210 connection = connman_dbus_get_connection();
11212 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
11213 NULL, service_free);
11215 services_notify = g_new0(struct _services_notify, 1);
11216 services_notify->remove = g_hash_table_new_full(g_str_hash,
11217 g_str_equal, g_free, NULL);
11218 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
11220 remove_unprovisioned_services();
11222 #if defined TIZEN_EXT
11223 ins_setting_init();
11229 void __connman_service_cleanup(void)
11233 if (vpn_autoconnect_id) {
11234 g_source_remove(vpn_autoconnect_id);
11235 vpn_autoconnect_id = 0;
11238 if (autoconnect_id != 0) {
11239 g_source_remove(autoconnect_id);
11240 autoconnect_id = 0;
11243 connman_agent_driver_unregister(&agent_driver);
11245 g_list_free(service_list);
11246 service_list = NULL;
11248 g_hash_table_destroy(service_hash);
11249 service_hash = NULL;
11251 g_slist_free(counter_list);
11252 counter_list = NULL;
11254 if (services_notify->id != 0) {
11255 g_source_remove(services_notify->id);
11256 service_send_changed(NULL);
11259 g_hash_table_destroy(services_notify->remove);
11260 g_hash_table_destroy(services_notify->add);
11261 g_free(services_notify);
11263 dbus_connection_unref(connection);