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
30 #include <connman/acd.h>
31 #include "src/shared/arp.h"
36 static DBusConnection *connection;
40 * How many times to send RS with the purpose of
41 * refreshing RDNSS entries before they actually expire.
42 * With a value of 1, one RS will be sent, with no retries.
44 #define RS_REFRESH_COUNT 1
47 * Value in seconds to wait for RA after RS was sent.
48 * After this time elapsed, we can send another RS.
50 #define RS_REFRESH_TIMEOUT 3
53 * As per RFC 4861, a host should transmit up to MAX_RTR_SOLICITATIONS(3)
54 * Router Solicitation messages, each separated by at least
55 * RTR_SOLICITATION_INTERVAL(4) seconds to obtain RA for IPv6 auto-configuration.
57 #define RTR_SOLICITATION_INTERVAL 4
59 #define DHCP_RETRY_TIMEOUT 10
62 static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
66 static GHashTable *dhcp_status_list = NULL;
69 static GSList *network_list = NULL;
70 static GSList *driver_list = NULL;
72 struct connman_network {
74 enum connman_network_type type;
86 int router_solicit_count;
87 int router_solicit_refresh_count;
88 struct acd_host *acd_host;
92 struct connman_network_driver *driver;
98 struct connman_device *device;
104 unsigned short channel;
109 char *anonymous_identity;
110 char *agent_identity;
113 char *altsubject_match;
114 char *domain_suffix_match;
116 char *client_cert_path;
117 char *private_key_path;
118 char *private_key_passphrase;
121 bool wps_advertizing;
124 #if defined TIZEN_EXT
125 char encryption_mode[WIFI_ENCYPTION_MODE_LEN_MAX];
126 unsigned char bssid[WIFI_BSSID_LEN_MAX];
127 unsigned int maxrate;
130 unsigned int keymgmt;
134 int disconnect_reason;
135 int assoc_status_code;
141 unsigned char country_code[WIFI_COUNTRY_CODE_LEN];
144 ieee80211_modes_e phy_mode;
145 connection_mode_e connection_mode;
148 char *net_access_key;
150 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
151 GHashTable *assoc_reject_table;
152 bool owe_transition_mode;
153 void *transition_mode_ssid;
154 int transition_mode_ssid_len;
155 unsigned char transition_mode_bssid[WIFI_BSSID_LEN_MAX];
156 bool roaming_progress;
158 char *roaming_cur_bssid;
159 char *roaming_dst_bssid;
160 __time_t roam_scan_time;
161 unsigned int max_bssid_count;
163 unsigned int est_throughput;
167 #if defined TIZEN_EXT
168 /* Multiple APN services and a default APN which a user selected */
169 bool default_internet;
175 static const char *type2string(enum connman_network_type type)
178 case CONNMAN_NETWORK_TYPE_UNKNOWN:
179 case CONNMAN_NETWORK_TYPE_VENDOR:
181 case CONNMAN_NETWORK_TYPE_ETHERNET:
183 case CONNMAN_NETWORK_TYPE_GADGET:
185 case CONNMAN_NETWORK_TYPE_WIFI:
187 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
188 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
190 case CONNMAN_NETWORK_TYPE_CELLULAR:
197 static bool match_driver(struct connman_network *network,
198 struct connman_network_driver *driver)
200 if (network->type == driver->type ||
201 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
207 static void set_configuration(struct connman_network *network,
208 enum connman_ipconfig_type type)
210 struct connman_service *service;
212 DBG("network %p", network);
214 if (!network->device)
217 __connman_device_set_network(network->device, network);
219 service = connman_service_lookup_from_network(network);
220 __connman_service_ipconfig_indicate_state(service,
221 CONNMAN_SERVICE_STATE_CONFIGURATION,
225 void connman_network_append_acddbus(DBusMessageIter *dict,
226 struct connman_network *network)
228 if (!network->acd_host)
231 acd_host_append_dbus_property(network->acd_host, dict);
234 static int start_acd(struct connman_network *network);
236 static void remove_ipv4ll_timeout(struct connman_network *network)
238 if (network->ipv4ll_timeout > 0) {
239 g_source_remove(network->ipv4ll_timeout);
240 network->ipv4ll_timeout = 0;
244 static void acd_host_ipv4_available(struct acd_host *acd, gpointer user_data)
246 struct connman_network *network = user_data;
247 struct connman_service *service;
248 struct connman_ipconfig *ipconfig_ipv4;
254 service = connman_service_lookup_from_network(network);
258 ipconfig_ipv4 = __connman_service_get_ip4config(service);
259 if (!ipconfig_ipv4) {
260 connman_error("Service has no IPv4 configuration");
264 err = __connman_ipconfig_address_add(ipconfig_ipv4);
268 #if defined TIZEN_EXT
269 err = __connman_ipconfig_gateway_add(ipconfig_ipv4, service);
271 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
276 __connman_service_save(service);
281 connman_network_set_error(__connman_service_get_network(service),
282 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
285 static int start_ipv4ll(struct connman_network *network)
287 struct connman_service *service;
288 struct connman_ipconfig *ipconfig_ipv4;
292 service = connman_service_lookup_from_network(network);
296 ipconfig_ipv4 = __connman_service_get_ip4config(service);
297 if (!ipconfig_ipv4) {
298 connman_error("Service has no IPv4 configuration");
302 /* Apply random IPv4 address. */
303 addr.s_addr = htonl(arp_random_ip());
304 address = inet_ntoa(addr);
306 connman_error("Could not convert IPv4LL random address %u",
310 __connman_ipconfig_set_local(ipconfig_ipv4, address);
312 connman_info("Probing IPv4LL address %s", address);
313 return start_acd(network);
316 static gboolean start_ipv4ll_ontimeout(gpointer data)
318 struct connman_network *network = data;
323 /* Start IPv4LL ACD. */
324 start_ipv4ll(network);
329 static void acd_host_ipv4_lost(struct acd_host *acd, gpointer user_data)
331 struct connman_network *network = user_data;
332 struct connman_service *service;
333 struct connman_ipconfig *ipconfig_ipv4;
334 enum connman_ipconfig_type type;
335 enum connman_ipconfig_method method;
340 service = connman_service_lookup_from_network(network);
344 ipconfig_ipv4 = __connman_service_get_ip4config(service);
345 if (!ipconfig_ipv4) {
346 connman_error("Service has no IPv4 configuration");
350 type = __connman_ipconfig_get_config_type(ipconfig_ipv4);
351 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
354 __connman_ipconfig_address_remove(ipconfig_ipv4);
356 method = __connman_ipconfig_get_method(ipconfig_ipv4);
357 if (method == CONNMAN_IPCONFIG_METHOD_DHCP) {
359 * We have one more chance for DHCP. If this fails
360 * acd_host_ipv4_conflict will be called.
362 network = __connman_service_get_network(service);
364 __connman_network_enable_ipconfig(network, ipconfig_ipv4);
366 /* Start IPv4LL ACD. */
367 start_ipv4ll(network);
371 static void acd_host_ipv4_conflict(struct acd_host *acd, gpointer user_data)
373 struct connman_network *network = user_data;
374 struct connman_service *service;
375 struct connman_ipconfig *ipconfig_ipv4;
376 enum connman_ipconfig_method method;
378 service = connman_service_lookup_from_network(network);
382 ipconfig_ipv4 = __connman_service_get_ip4config(service);
383 if (!ipconfig_ipv4) {
384 connman_error("Service has no IPv4 configuration");
388 method = __connman_ipconfig_get_method(ipconfig_ipv4);
389 connman_info("%s conflict counts=%u", __FUNCTION__,
390 acd_host_get_conflicts_count(acd));
392 if (method == CONNMAN_IPCONFIG_METHOD_DHCP &&
393 acd_host_get_conflicts_count(acd) < 2) {
394 connman_info("%s Sending DHCP decline", __FUNCTION__);
395 __connman_dhcp_decline(ipconfig_ipv4);
397 connman_network_set_connected_dhcp_later(network, DHCP_RETRY_TIMEOUT);
398 __connman_ipconfig_set_local(ipconfig_ipv4, NULL);
400 if (method == CONNMAN_IPCONFIG_METHOD_DHCP) {
401 __connman_ipconfig_set_method(ipconfig_ipv4,
402 CONNMAN_IPCONFIG_METHOD_AUTO);
403 __connman_dhcp_decline(ipconfig_ipv4);
405 /* Start IPv4LL ACD. */
406 start_ipv4ll(network);
410 static void acd_host_ipv4_maxconflict(struct acd_host *acd, gpointer user_data)
412 struct connman_network *network = user_data;
414 remove_ipv4ll_timeout(network);
415 connman_info("Had maximum number of conflicts. Next IPv4LL address will be "
416 "tried in %d seconds", RATE_LIMIT_INTERVAL);
417 /* Wait, then start IPv4LL ACD. */
418 network->ipv4ll_timeout =
419 g_timeout_add_seconds_full(G_PRIORITY_HIGH,
421 start_ipv4ll_ontimeout,
426 static int start_acd(struct connman_network *network)
428 struct connman_service *service;
429 struct connman_ipconfig *ipconfig_ipv4;
433 remove_ipv4ll_timeout(network);
435 service = connman_service_lookup_from_network(network);
439 ipconfig_ipv4 = __connman_service_get_ip4config(service);
440 if (!ipconfig_ipv4) {
441 connman_error("Service has no IPv4 configuration");
445 if (!network->acd_host) {
448 index = __connman_ipconfig_get_index(ipconfig_ipv4);
449 network->acd_host = acd_host_new(index,
450 connman_service_get_dbuspath(service));
451 if (!network->acd_host) {
452 connman_error("Could not create ACD data structure");
456 acd_host_register_event(network->acd_host,
457 ACD_HOST_EVENT_IPV4_AVAILABLE,
458 acd_host_ipv4_available, network);
459 acd_host_register_event(network->acd_host,
460 ACD_HOST_EVENT_IPV4_LOST,
461 acd_host_ipv4_lost, network);
462 acd_host_register_event(network->acd_host,
463 ACD_HOST_EVENT_IPV4_CONFLICT,
464 acd_host_ipv4_conflict, network);
465 acd_host_register_event(network->acd_host,
466 ACD_HOST_EVENT_IPV4_MAXCONFLICT,
467 acd_host_ipv4_maxconflict, network);
470 address = __connman_ipconfig_get_local(ipconfig_ipv4);
474 connman_info("Starting ACD for address %s", address);
475 if (inet_pton(AF_INET, address, &addr) != 1)
476 connman_error("Could not convert address %s", address);
478 acd_host_start(network->acd_host, htonl(addr.s_addr));
483 static void dhcp_success(struct connman_network *network)
485 struct connman_service *service;
486 struct connman_ipconfig *ipconfig_ipv4;
489 service = connman_service_lookup_from_network(network);
493 ipconfig_ipv4 = __connman_service_get_ip4config(service);
495 DBG("lease acquired for ipconfig %p", ipconfig_ipv4);
500 if (connman_setting_get_bool("AddressConflictDetection")) {
501 err = start_acd(network);
505 /* On error proceed without ACD. */
508 err = __connman_ipconfig_address_add(ipconfig_ipv4);
512 #if defined TIZEN_EXT
513 err = __connman_ipconfig_gateway_add(ipconfig_ipv4, service);
515 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
520 __connman_service_save(service);
525 connman_network_set_error(network,
526 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
529 static void dhcp_failure(struct connman_network *network)
531 struct connman_service *service;
532 struct connman_ipconfig *ipconfig_ipv4;
534 service = connman_service_lookup_from_network(network);
538 ipconfig_ipv4 = __connman_service_get_ip4config(service);
540 DBG("lease lost for ipconfig %p", ipconfig_ipv4);
545 __connman_ipconfig_address_remove(ipconfig_ipv4);
546 __connman_ipconfig_gateway_remove(ipconfig_ipv4);
549 static void dhcp_callback(struct connman_ipconfig *ipconfig,
550 struct connman_network *network,
551 bool success, gpointer data)
553 network->connecting = false;
556 dhcp_success(network);
558 dhcp_failure(network);
561 static int set_connected_manual(struct connman_network *network)
564 struct connman_service *service;
565 struct connman_ipconfig *ipconfig;
567 DBG("network %p", network);
569 network->connecting = false;
571 service = connman_service_lookup_from_network(network);
572 ipconfig = __connman_service_get_ip4config(service);
573 __connman_ipconfig_enable(ipconfig);
575 #if defined TIZEN_EXT
576 if (!service || !ipconfig)
579 if (!__connman_ipconfig_get_local(ipconfig))
580 __connman_service_read_ip4config(service);
582 if (connman_setting_get_bool("AddressConflictDetection")) {
583 err = start_acd(network);
587 /* On error proceed without ACD. */
590 err = __connman_ipconfig_address_add(ipconfig);
594 #if defined TIZEN_EXT
595 err = __connman_ipconfig_gateway_add(ipconfig, service);
597 err = __connman_ipconfig_gateway_add(ipconfig);
606 static void remove_dhcp_timeout(struct connman_network *network)
608 if (network->dhcp_timeout > 0) {
609 g_source_remove(network->dhcp_timeout);
610 network->dhcp_timeout = 0;
614 #if defined TIZEN_EXT
615 int set_connected_dhcp(struct connman_network *network)
617 static int set_connected_dhcp(struct connman_network *network)
620 struct connman_service *service;
621 struct connman_ipconfig *ipconfig_ipv4;
624 DBG("network %p", network);
625 remove_dhcp_timeout(network);
627 service = connman_service_lookup_from_network(network);
628 ipconfig_ipv4 = __connman_service_get_ip4config(service);
629 __connman_ipconfig_enable(ipconfig_ipv4);
631 err = __connman_dhcp_start(ipconfig_ipv4, network,
632 dhcp_callback, NULL);
634 connman_error("Can not request DHCP lease");
641 static gboolean set_connected_dhcp_timout(gpointer data)
643 struct connman_network *network = data;
644 struct connman_service *service;
645 struct connman_ipconfig *ipconfig;
646 enum connman_ipconfig_method method;
648 network->dhcp_timeout = 0;
650 service = connman_service_lookup_from_network(network);
654 ipconfig = __connman_service_get_ip4config(service);
658 /* Method is still DHCP? */
659 method = __connman_ipconfig_get_method(ipconfig);
660 if (method == CONNMAN_IPCONFIG_METHOD_DHCP)
661 set_connected_dhcp(network);
666 void connman_network_set_connected_dhcp_later(struct connman_network *network,
669 remove_dhcp_timeout(network);
671 network->dhcp_timeout =
672 g_timeout_add_seconds_full(G_PRIORITY_HIGH,
674 set_connected_dhcp_timout,
679 static int manual_ipv6_set(struct connman_network *network,
680 struct connman_ipconfig *ipconfig_ipv6)
682 struct connman_service *service;
685 DBG("network %p ipv6 %p", network, ipconfig_ipv6);
687 service = connman_service_lookup_from_network(network);
691 if (!__connman_ipconfig_get_local(ipconfig_ipv6))
692 __connman_service_read_ip6config(service);
694 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
696 err = __connman_ipconfig_address_add(ipconfig_ipv6);
698 connman_network_set_error(network,
699 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
703 #if defined TIZEN_EXT
704 err = __connman_ipconfig_gateway_add(ipconfig_ipv6, service);
706 err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
711 __connman_device_set_network(network->device, network);
713 connman_network_set_associating(network, false);
715 network->connecting = false;
720 static void stop_dhcpv6(struct connman_network *network)
722 network->connecting = false;
724 __connman_dhcpv6_stop(network);
727 static void dhcpv6_release_callback(struct connman_network *network,
728 enum __connman_dhcpv6_status status,
731 DBG("status %d", status);
733 stop_dhcpv6(network);
736 static void release_dhcpv6(struct connman_network *network)
738 __connman_dhcpv6_start_release(network, dhcpv6_release_callback);
739 stop_dhcpv6(network);
742 static void dhcpv6_info_callback(struct connman_network *network,
743 enum __connman_dhcpv6_status status,
746 DBG("status %d", status);
748 stop_dhcpv6(network);
751 static int dhcpv6_set_addresses(struct connman_network *network)
753 struct connman_service *service;
754 struct connman_ipconfig *ipconfig_ipv6;
757 service = connman_service_lookup_from_network(network);
761 network->connecting = false;
763 ipconfig_ipv6 = __connman_service_get_ip6config(service);
764 #if defined TIZEN_EXT
768 err = __connman_ipconfig_address_add(ipconfig_ipv6);
775 connman_network_set_error(network,
776 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
780 static void autoconf_ipv6_set(struct connman_network *network);
781 static void dhcpv6_callback(struct connman_network *network,
782 enum __connman_dhcpv6_status status, gpointer data);
785 * Have a separate callback for renew so that we do not do autoconf
786 * in wrong phase as the dhcpv6_callback() is also called when doing
787 * DHCPv6 solicitation.
789 static void dhcpv6_renew_callback(struct connman_network *network,
790 enum __connman_dhcpv6_status status,
794 case CONNMAN_DHCPV6_STATUS_SUCCEED:
795 dhcpv6_callback(network, status, data);
797 case CONNMAN_DHCPV6_STATUS_FAIL:
798 case CONNMAN_DHCPV6_STATUS_RESTART:
799 stop_dhcpv6(network);
801 /* restart and do solicit again. */
802 autoconf_ipv6_set(network);
807 static void dhcpv6_callback(struct connman_network *network,
808 enum __connman_dhcpv6_status status, gpointer data)
810 DBG("status %d", status);
812 /* Start the renew process if necessary */
813 if (status == CONNMAN_DHCPV6_STATUS_SUCCEED) {
815 if (dhcpv6_set_addresses(network) < 0) {
816 stop_dhcpv6(network);
820 if (__connman_dhcpv6_start_renew(network,
821 dhcpv6_renew_callback) == -ETIMEDOUT)
822 dhcpv6_renew_callback(network,
823 CONNMAN_DHCPV6_STATUS_FAIL,
826 } else if (status == CONNMAN_DHCPV6_STATUS_RESTART) {
827 stop_dhcpv6(network);
828 autoconf_ipv6_set(network);
830 stop_dhcpv6(network);
833 static void check_dhcpv6(struct nd_router_advert *reply,
834 unsigned int length, void *user_data)
836 struct connman_network *network = user_data;
837 struct connman_service *service;
840 DBG("reply %p", reply);
844 * Router solicitation message seem to get lost easily so
845 * try to send it again.
847 if (network->router_solicit_count > 0) {
848 DBG("re-send router solicitation %d",
849 network->router_solicit_count);
850 network->router_solicit_count--;
851 __connman_inet_ipv6_send_rs(network->index, RTR_SOLICITATION_INTERVAL,
852 check_dhcpv6, network);
855 #if defined TIZEN_EXT
856 DBG("RA message is not received from server in reply of RS.");
858 connman_network_unref(network);
862 network->router_solicit_count = 0;
865 * If we were disconnected while waiting router advertisement,
866 * we just quit and do not start DHCPv6
868 if (!network->connected) {
869 connman_network_unref(network);
870 #if defined TIZEN_EXT
871 DBG("Network is not connected");
876 prefixes = __connman_inet_ipv6_get_prefixes(reply, length);
879 * If IPv6 config is missing from service, then create it.
880 * The ipconfig might be missing if we got a rtnl message
881 * that disabled IPv6 config and thus removed it. This
882 * can happen if we are switching from one service to
883 * another in the same interface. The only way to get IPv6
884 * config back is to re-create it here.
886 service = connman_service_lookup_from_network(network);
888 connman_service_create_ip6config(service, network->index);
890 connman_network_set_associating(network, false);
892 __connman_service_ipconfig_indicate_state(service,
893 CONNMAN_SERVICE_STATE_CONFIGURATION,
894 CONNMAN_IPCONFIG_TYPE_IPV6);
898 * We do stateful/stateless DHCPv6 if router advertisement says so.
900 if (reply->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) {
901 #if defined TIZEN_EXT
902 DBG("IPv6 ND_RA_FLAG_MANAGED");
904 __connman_dhcpv6_start(network, prefixes, dhcpv6_callback);
906 if (reply->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
907 #if defined TIZEN_EXT
909 DBG("IPv6 ND_RA_FLAG_OTHER");
911 __connman_dhcpv6_start_info(network,
912 dhcpv6_info_callback);
913 #if defined TIZEN_EXT
917 g_slist_free_full(prefixes, g_free);
918 network->connecting = false;
921 connman_network_unref(network);
924 static void receive_refresh_rs_reply(struct nd_router_advert *reply,
925 unsigned int length, void *user_data)
927 struct connman_network *network = user_data;
929 DBG("reply %p", reply);
933 * Router solicitation message seem to get lost easily so
934 * try to send it again.
936 if (network->router_solicit_refresh_count > 1) {
937 network->router_solicit_refresh_count--;
938 DBG("re-send router solicitation %d",
939 network->router_solicit_refresh_count);
940 __connman_inet_ipv6_send_rs(network->index,
942 receive_refresh_rs_reply,
948 /* RS refresh not in progress anymore */
949 network->router_solicit_refresh_count = 0;
951 connman_network_unref(network);
954 int __connman_network_refresh_rs_ipv6(struct connman_network *network,
959 DBG("network %p index %d", network, index);
961 /* Send only one RS for all RDNSS entries which are about to expire */
962 if (network->router_solicit_refresh_count > 0) {
963 DBG("RS refresh already started");
967 network->router_solicit_refresh_count = RS_REFRESH_COUNT;
969 connman_network_ref(network);
971 ret = __connman_inet_ipv6_send_rs(index, RS_REFRESH_TIMEOUT,
972 receive_refresh_rs_reply, network);
976 static void autoconf_ipv6_set(struct connman_network *network)
978 struct connman_service *service;
979 struct connman_ipconfig *ipconfig;
982 DBG("network %p", network);
984 if (network->router_solicit_count > 0) {
986 * The autoconfiguration is already pending and we have sent
987 * router solicitation messages and are now waiting answers.
988 * There is no need to continue any further.
990 DBG("autoconfiguration already started");
994 __connman_device_set_network(network->device, network);
996 #if defined TIZEN_EXT
997 if(network->type == CONNMAN_NETWORK_TYPE_CELLULAR)
1001 service = connman_service_lookup_from_network(network);
1005 ipconfig = __connman_service_get_ip6config(service);
1009 __connman_ipconfig_enable(ipconfig);
1011 __connman_ipconfig_enable_ipv6(ipconfig);
1013 __connman_ipconfig_address_remove(ipconfig);
1015 index = __connman_ipconfig_get_index(ipconfig);
1017 connman_network_ref(network);
1019 /* Try to get stateless DHCPv6 information, RFC 3736 */
1020 network->router_solicit_count = 3;
1021 __connman_inet_ipv6_send_rs(index, RTR_SOLICITATION_INTERVAL,
1022 check_dhcpv6, network);
1025 static void set_connected(struct connman_network *network)
1027 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
1028 struct connman_service *service;
1030 if (network->connected)
1033 connman_network_set_associating(network, false);
1035 network->connected = true;
1037 service = connman_service_lookup_from_network(network);
1039 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1040 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1042 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
1045 __connman_network_enable_ipconfig(network, ipconfig_ipv4);
1046 __connman_network_enable_ipconfig(network, ipconfig_ipv6);
1049 static void set_disconnected(struct connman_network *network)
1051 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
1052 enum connman_ipconfig_method ipv4_method, ipv6_method;
1053 enum connman_service_state state;
1054 struct connman_service *service;
1056 service = connman_service_lookup_from_network(network);
1058 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1059 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1061 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
1064 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
1065 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
1067 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
1070 * Resetting solicit count here will prevent the RS resend loop
1071 * from sending packets in check_dhcpv6()
1073 network->router_solicit_count = 0;
1075 __connman_device_set_network(network->device, NULL);
1077 if (network->connected) {
1078 switch (ipv6_method) {
1079 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1080 case CONNMAN_IPCONFIG_METHOD_OFF:
1081 case CONNMAN_IPCONFIG_METHOD_FIXED:
1082 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1084 case CONNMAN_IPCONFIG_METHOD_DHCP:
1085 case CONNMAN_IPCONFIG_METHOD_AUTO:
1086 release_dhcpv6(network);
1090 switch (ipv4_method) {
1091 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1092 case CONNMAN_IPCONFIG_METHOD_OFF:
1093 case CONNMAN_IPCONFIG_METHOD_FIXED:
1094 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1096 case CONNMAN_IPCONFIG_METHOD_AUTO:
1098 * If the current method is AUTO then next time we
1099 * try first DHCP. DHCP also needs to be stopped
1100 * in this case because if we fell in AUTO means
1101 * that DHCP was launched for IPv4 but it failed.
1103 __connman_ipconfig_set_method(ipconfig_ipv4,
1104 CONNMAN_IPCONFIG_METHOD_DHCP);
1105 __connman_service_notify_ipv4_configuration(service);
1107 case CONNMAN_IPCONFIG_METHOD_DHCP:
1108 remove_dhcp_timeout(network);
1109 __connman_dhcp_stop(ipconfig_ipv4);
1115 * We only set the disconnect state if we were not in idle
1116 * or in failure. It does not make sense to go to disconnect
1117 * state if we were not connected.
1119 state = __connman_service_ipconfig_get_state(service,
1120 CONNMAN_IPCONFIG_TYPE_IPV4);
1121 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1122 state != CONNMAN_SERVICE_STATE_FAILURE)
1123 __connman_service_ipconfig_indicate_state(service,
1124 CONNMAN_SERVICE_STATE_DISCONNECT,
1125 CONNMAN_IPCONFIG_TYPE_IPV4);
1127 state = __connman_service_ipconfig_get_state(service,
1128 CONNMAN_IPCONFIG_TYPE_IPV6);
1129 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1130 state != CONNMAN_SERVICE_STATE_FAILURE)
1131 __connman_service_ipconfig_indicate_state(service,
1132 CONNMAN_SERVICE_STATE_DISCONNECT,
1133 CONNMAN_IPCONFIG_TYPE_IPV6);
1135 if (network->connected) {
1136 #if defined TIZEN_EXT
1138 * Do not remove gateway and its address,
1139 * if there are connected profiles that use same interface (multiple PDN)
1141 if (connman_service_get_type(service) != CONNMAN_SERVICE_TYPE_CELLULAR ||
1142 __connman_service_get_connected_count_of_iface(service) <= 0) {
1144 __connman_connection_gateway_remove(service,
1145 CONNMAN_IPCONFIG_TYPE_ALL);
1147 __connman_ipconfig_address_unset(ipconfig_ipv4);
1148 __connman_ipconfig_address_unset(ipconfig_ipv6);
1150 #if defined TIZEN_EXT
1154 * Special handling for IPv6 autoconfigured address.
1155 * The simplest way to remove autoconfigured routes is to
1156 * disable IPv6 temporarily so that kernel will do the cleanup
1159 if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
1160 __connman_ipconfig_disable_ipv6(ipconfig_ipv6);
1161 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
1165 __connman_service_ipconfig_indicate_state(service,
1166 CONNMAN_SERVICE_STATE_IDLE,
1167 CONNMAN_IPCONFIG_TYPE_IPV4);
1169 __connman_service_ipconfig_indicate_state(service,
1170 CONNMAN_SERVICE_STATE_IDLE,
1171 CONNMAN_IPCONFIG_TYPE_IPV6);
1173 network->connecting = false;
1174 network->connected = false;
1176 connman_network_set_associating(network, false);
1181 static int network_probe(struct connman_network *network)
1184 struct connman_network_driver *driver = NULL;
1186 DBG("network %p name %s", network, network->name);
1188 if (network->driver)
1191 for (list = driver_list; list; list = list->next) {
1192 driver = list->data;
1194 if (!match_driver(network, driver)) {
1198 #if defined TIZEN_EXT
1199 if (!simplified_log)
1201 DBG("driver %p name %s", driver, driver->name);
1203 if (driver->probe(network) == 0)
1212 if (!network->group)
1215 switch (network->type) {
1216 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1217 case CONNMAN_NETWORK_TYPE_VENDOR:
1219 case CONNMAN_NETWORK_TYPE_ETHERNET:
1220 case CONNMAN_NETWORK_TYPE_GADGET:
1221 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1222 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1223 case CONNMAN_NETWORK_TYPE_CELLULAR:
1224 case CONNMAN_NETWORK_TYPE_WIFI:
1225 network->driver = driver;
1226 if (!__connman_service_create_from_network(network)) {
1227 network->driver = NULL;
1235 static void network_remove(struct connman_network *network)
1237 DBG("network %p name %s", network, network->name);
1239 if (!network->driver)
1242 if (network->connected)
1243 set_disconnected(network);
1245 switch (network->type) {
1246 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1247 case CONNMAN_NETWORK_TYPE_VENDOR:
1249 case CONNMAN_NETWORK_TYPE_ETHERNET:
1250 case CONNMAN_NETWORK_TYPE_GADGET:
1251 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1252 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1253 case CONNMAN_NETWORK_TYPE_CELLULAR:
1254 case CONNMAN_NETWORK_TYPE_WIFI:
1255 if (network->group) {
1256 __connman_service_remove_from_network(network);
1258 g_free(network->group);
1259 network->group = NULL;
1264 if (network->driver->remove)
1265 network->driver->remove(network);
1267 network->driver = NULL;
1270 static void probe_driver(struct connman_network_driver *driver)
1274 DBG("driver %p name %s", driver, driver->name);
1276 for (list = network_list; list; list = list->next) {
1277 struct connman_network *network = list->data;
1279 if (network->driver)
1282 if (driver->type != network->type)
1285 if (driver->probe(network) < 0)
1288 network->driver = driver;
1292 static gint compare_priority(gconstpointer a, gconstpointer b)
1294 const struct connman_network_driver *driver1 = a;
1295 const struct connman_network_driver *driver2 = b;
1297 return driver2->priority - driver1->priority;
1301 * connman_network_driver_register:
1302 * @driver: network driver definition
1304 * Register a new network driver
1306 * Returns: %0 on success
1308 int connman_network_driver_register(struct connman_network_driver *driver)
1310 DBG("driver %p name %s", driver, driver->name);
1312 driver_list = g_slist_insert_sorted(driver_list, driver,
1315 probe_driver(driver);
1321 * connman_network_driver_unregister:
1322 * @driver: network driver definition
1324 * Remove a previously registered network driver
1326 void connman_network_driver_unregister(struct connman_network_driver *driver)
1330 DBG("driver %p name %s", driver, driver->name);
1332 driver_list = g_slist_remove(driver_list, driver);
1334 for (list = network_list; list; list = list->next) {
1335 struct connman_network *network = list->data;
1337 if (network->driver == driver)
1338 network_remove(network);
1342 static void network_destruct(struct connman_network *network)
1344 DBG("network %p name %s", network, network->name);
1346 g_free(network->wifi.ssid);
1347 g_free(network->wifi.mode);
1348 g_free(network->wifi.security);
1349 g_free(network->wifi.passphrase);
1350 g_free(network->wifi.eap);
1351 g_free(network->wifi.identity);
1352 g_free(network->wifi.anonymous_identity);
1353 g_free(network->wifi.agent_identity);
1354 g_free(network->wifi.ca_cert_path);
1355 g_free(network->wifi.subject_match);
1356 g_free(network->wifi.altsubject_match);
1357 g_free(network->wifi.domain_suffix_match);
1358 g_free(network->wifi.domain_match);
1359 g_free(network->wifi.client_cert_path);
1360 g_free(network->wifi.private_key_path);
1361 g_free(network->wifi.private_key_passphrase);
1362 g_free(network->wifi.phase2_auth);
1363 g_free(network->wifi.pin_wps);
1365 #if defined TIZEN_EXT
1366 g_slist_free_full(network->wifi.vsie_list, g_free);
1367 g_slist_free_full(network->wifi.bssid_list, g_free);
1369 if (TIZEN_INS_ENABLED)
1370 g_hash_table_destroy(network->wifi.assoc_reject_table);
1372 g_free(network->path);
1373 g_free(network->group);
1374 g_free(network->node);
1375 g_free(network->name);
1376 g_free(network->identifier);
1377 acd_host_free(network->acd_host);
1379 network->device = NULL;
1385 * connman_network_create:
1386 * @identifier: network identifier (for example an unique name)
1388 * Allocate a new network and assign the #identifier to it.
1390 * Returns: a newly-allocated #connman_network structure
1392 struct connman_network *connman_network_create(const char *identifier,
1393 enum connman_network_type type)
1395 struct connman_network *network;
1398 network = g_try_new0(struct connman_network, 1);
1402 network->refcount = 1;
1404 ident = g_strdup(identifier);
1411 network->type = type;
1412 network->identifier = ident;
1413 network->acd_host = NULL;
1414 network->ipv4ll_timeout = 0;
1416 network_list = g_slist_prepend(network_list, network);
1418 network->dhcp_timeout = 0;
1420 DBG("network %p identifier %s type %s", network, identifier,
1426 * connman_network_ref:
1427 * @network: network structure
1429 * Increase reference counter of network
1431 struct connman_network *
1432 connman_network_ref_debug(struct connman_network *network,
1433 const char *file, int line, const char *caller)
1435 #if defined TIZEN_EXT
1436 if (!simplified_log)
1438 DBG("%p name %s ref %d by %s:%d:%s()", network, network->name,
1439 network->refcount + 1, file, line, caller);
1441 __sync_fetch_and_add(&network->refcount, 1);
1447 * connman_network_unref:
1448 * @network: network structure
1450 * Decrease reference counter of network
1452 void connman_network_unref_debug(struct connman_network *network,
1453 const char *file, int line, const char *caller)
1455 #if defined TIZEN_EXT
1456 if (!simplified_log)
1458 DBG("%p name %s ref %d by %s:%d:%s()", network, network->name,
1459 network->refcount - 1, file, line, caller);
1461 if (__sync_fetch_and_sub(&network->refcount, 1) != 1)
1464 network_list = g_slist_remove(network_list, network);
1466 network_destruct(network);
1469 const char *__connman_network_get_type(struct connman_network *network)
1471 return type2string(network->type);
1475 * connman_network_get_type:
1476 * @network: network structure
1478 * Get type of network
1480 enum connman_network_type connman_network_get_type(
1481 struct connman_network *network)
1483 return network->type;
1487 * connman_network_get_identifier:
1488 * @network: network structure
1490 * Get identifier of network
1492 const char *connman_network_get_identifier(struct connman_network *network)
1494 return network->identifier;
1498 * connman_network_set_index:
1499 * @network: network structure
1500 * @index: index number
1502 * Set index number of network
1504 void connman_network_set_index(struct connman_network *network, int index)
1506 struct connman_service *service;
1507 struct connman_ipconfig *ipconfig;
1509 service = connman_service_lookup_from_network(network);
1513 ipconfig = __connman_service_get_ip4config(service);
1515 __connman_ipconfig_set_index(ipconfig, index);
1517 DBG("index %d service %p ip4config %p", network->index,
1521 ipconfig = __connman_service_get_ip6config(service);
1523 __connman_ipconfig_set_index(ipconfig, index);
1525 DBG("index %d service %p ip6config %p", network->index,
1530 network->index = index;
1534 * connman_network_get_index:
1535 * @network: network structure
1537 * Get index number of network
1539 int connman_network_get_index(struct connman_network *network)
1541 return network->index;
1545 * connman_network_set_group:
1546 * @network: network structure
1547 * @group: group name
1549 * Set group name for automatic clustering
1551 void connman_network_set_group(struct connman_network *network,
1554 switch (network->type) {
1555 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1556 case CONNMAN_NETWORK_TYPE_VENDOR:
1558 case CONNMAN_NETWORK_TYPE_ETHERNET:
1559 case CONNMAN_NETWORK_TYPE_GADGET:
1560 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1561 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1562 case CONNMAN_NETWORK_TYPE_CELLULAR:
1563 case CONNMAN_NETWORK_TYPE_WIFI:
1567 if (g_strcmp0(network->group, group) == 0) {
1569 __connman_service_update_from_network(network);
1573 if (network->group) {
1574 __connman_service_remove_from_network(network);
1576 g_free(network->group);
1579 network->group = g_strdup(group);
1582 network_probe(network);
1586 * connman_network_get_group:
1587 * @network: network structure
1589 * Get group name for automatic clustering
1591 const char *connman_network_get_group(struct connman_network *network)
1593 return network->group;
1596 const char *__connman_network_get_ident(struct connman_network *network)
1598 if (!network->device)
1601 return connman_device_get_ident(network->device);
1604 bool __connman_network_get_weakness(struct connman_network *network)
1606 switch (network->type) {
1607 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1608 case CONNMAN_NETWORK_TYPE_VENDOR:
1609 case CONNMAN_NETWORK_TYPE_ETHERNET:
1610 case CONNMAN_NETWORK_TYPE_GADGET:
1611 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1612 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1613 case CONNMAN_NETWORK_TYPE_CELLULAR:
1615 case CONNMAN_NETWORK_TYPE_WIFI:
1616 if (network->strength > 0 && network->strength < 20)
1624 #if defined TIZEN_EXT
1625 void connman_network_set_connecting(struct connman_network *network)
1627 DBG("set network connecting true");
1628 network->connecting = TRUE;
1633 bool connman_network_get_connecting(struct connman_network *network)
1635 return network->connecting;
1639 * connman_network_set_available:
1640 * @network: network structure
1641 * @available: availability state
1643 * Change availability state of network (in range)
1645 int connman_network_set_available(struct connman_network *network,
1648 #if !defined TIZEN_EXT
1649 DBG("network %p available %d", network, available);
1652 if (network->available == available)
1655 network->available = available;
1661 * connman_network_get_available:
1662 * @network: network structure
1664 * Get network available setting
1666 bool connman_network_get_available(struct connman_network *network)
1668 return network->available;
1671 #if defined TIZEN_EXT
1672 void connman_network_clear_associating(struct connman_network *network)
1674 struct connman_service *service;
1675 enum connman_service_state state;
1677 DBG("network %p", network);
1679 network->connecting = FALSE;
1680 network->associating = FALSE;
1682 service = connman_service_lookup_from_network(network);
1686 state = __connman_service_ipconfig_get_state(service,
1687 CONNMAN_IPCONFIG_TYPE_IPV4);
1688 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1689 state != CONNMAN_SERVICE_STATE_FAILURE)
1690 __connman_service_ipconfig_indicate_state(service,
1691 CONNMAN_SERVICE_STATE_DISCONNECT,
1692 CONNMAN_IPCONFIG_TYPE_IPV4);
1694 state = __connman_service_ipconfig_get_state(service,
1695 CONNMAN_IPCONFIG_TYPE_IPV6);
1696 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1697 state != CONNMAN_SERVICE_STATE_FAILURE)
1698 __connman_service_ipconfig_indicate_state(service,
1699 CONNMAN_SERVICE_STATE_DISCONNECT,
1700 CONNMAN_IPCONFIG_TYPE_IPV6);
1702 __connman_service_ipconfig_indicate_state(service,
1703 CONNMAN_SERVICE_STATE_IDLE,
1704 CONNMAN_IPCONFIG_TYPE_IPV4);
1706 __connman_service_ipconfig_indicate_state(service,
1707 CONNMAN_SERVICE_STATE_IDLE,
1708 CONNMAN_IPCONFIG_TYPE_IPV6);
1711 static gboolean __connman_network_clear_associating_delayed(gpointer user_data)
1714 gboolean found = FALSE;
1715 enum connman_service_state state_ipv4;
1716 enum connman_service_state state_ipv6;
1717 struct connman_service *service;
1718 struct connman_network *network = (struct connman_network *)user_data;
1720 for (list = network_list; list != NULL; list = list->next) {
1721 struct connman_network *item = list->data;
1723 if (item == network) {
1732 DBG("network %p name %s", network, network->name);
1733 service = connman_service_lookup_from_network(network);
1735 state_ipv4 = __connman_service_ipconfig_get_state(service,
1736 CONNMAN_IPCONFIG_TYPE_IPV4);
1737 state_ipv6 = __connman_service_ipconfig_get_state(service,
1738 CONNMAN_IPCONFIG_TYPE_IPV6);
1740 DBG("service %p state %d/%d", service, state_ipv4, state_ipv6);
1742 if (network->associating == FALSE &&
1743 state_ipv4 == CONNMAN_SERVICE_STATE_ASSOCIATION &&
1744 state_ipv6 == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1745 __connman_service_ipconfig_indicate_state(service,
1746 CONNMAN_SERVICE_STATE_IDLE,
1747 CONNMAN_IPCONFIG_TYPE_IPV4);
1748 __connman_service_ipconfig_indicate_state(service,
1749 CONNMAN_SERVICE_STATE_IDLE,
1750 CONNMAN_IPCONFIG_TYPE_IPV6);
1752 if (network->associating == FALSE) {
1753 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
1754 enum connman_ipconfig_method ipv4_method, ipv6_method;
1756 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1757 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
1758 ipconfig_ipv6 = __connman_service_get_ip4config(service);
1759 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
1761 if((ipv4_method == CONNMAN_IPCONFIG_METHOD_UNKNOWN || ipv4_method == CONNMAN_IPCONFIG_METHOD_OFF) &&
1762 (state_ipv6 == CONNMAN_SERVICE_STATE_ASSOCIATION))
1763 __connman_service_ipconfig_indicate_state(service,
1764 CONNMAN_SERVICE_STATE_IDLE,
1765 CONNMAN_IPCONFIG_TYPE_IPV6);
1766 if((ipv6_method == CONNMAN_IPCONFIG_METHOD_UNKNOWN || ipv6_method == CONNMAN_IPCONFIG_METHOD_OFF) &&
1767 (state_ipv4 == CONNMAN_SERVICE_STATE_ASSOCIATION))
1768 __connman_service_ipconfig_indicate_state(service,
1769 CONNMAN_SERVICE_STATE_IDLE,
1770 CONNMAN_IPCONFIG_TYPE_IPV4);
1778 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
1779 bool connman_network_check_validity(struct connman_network *network)
1781 return (NULL == g_slist_find(network_list, network)) ? false : true;
1783 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
1786 * connman_network_set_associating:
1787 * @network: network structure
1788 * @associating: associating state
1790 * Change associating state of network
1792 int connman_network_set_associating(struct connman_network *network,
1795 DBG("network %p associating %d", network, associating);
1797 if (network->associating == associating)
1800 network->associating = associating;
1803 struct connman_service *service;
1805 service = connman_service_lookup_from_network(network);
1806 __connman_service_ipconfig_indicate_state(service,
1807 CONNMAN_SERVICE_STATE_ASSOCIATION,
1808 CONNMAN_IPCONFIG_TYPE_IPV4);
1809 __connman_service_ipconfig_indicate_state(service,
1810 CONNMAN_SERVICE_STATE_ASSOCIATION,
1811 CONNMAN_IPCONFIG_TYPE_IPV6);
1814 #if defined TIZEN_EXT
1815 if (associating == FALSE &&
1816 connman_network_get_bool(network, "WiFi.UseWPS") == FALSE)
1817 g_timeout_add_seconds(1,
1818 __connman_network_clear_associating_delayed,
1825 #if defined TIZEN_EXT
1826 static void set_authenticate_error(struct connman_network *network)
1828 struct connman_service *service;
1830 service = connman_service_lookup_from_network(network);
1835 if (connman_service_get_favorite(service)) {
1836 __connman_service_set_ignore(service, true);
1839 __connman_service_indicate_error(service,
1840 CONNMAN_SERVICE_ERROR_AUTH_FAILED);
1845 static void set_associate_error(struct connman_network *network)
1847 struct connman_service *service;
1849 service = connman_service_lookup_from_network(network);
1851 #if defined TIZEN_EXT
1855 if (connman_service_get_favorite(service))
1856 __connman_service_set_ignore(service, true);
1858 __connman_service_indicate_error(service,
1859 CONNMAN_SERVICE_ERROR_ASSOC_FAILED);
1861 __connman_service_indicate_error(service,
1862 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
1866 static void set_configure_error(struct connman_network *network)
1868 struct connman_service *service;
1870 service = connman_service_lookup_from_network(network);
1872 __connman_service_indicate_error(service,
1873 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
1876 static void set_invalid_key_error(struct connman_network *network)
1878 struct connman_service *service;
1880 service = connman_service_lookup_from_network(network);
1882 #if defined TIZEN_EXT
1884 __connman_service_set_favorite(service, false);
1886 __connman_service_indicate_error(service,
1887 CONNMAN_SERVICE_ERROR_INVALID_KEY);
1890 static void set_connect_error(struct connman_network *network)
1892 struct connman_service *service;
1894 service = connman_service_lookup_from_network(network);
1896 __connman_service_indicate_error(service,
1897 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
1900 static void set_blocked_error(struct connman_network *network)
1902 struct connman_service *service;
1904 service = connman_service_lookup_from_network(network);
1906 __connman_service_indicate_error(service,
1907 CONNMAN_SERVICE_ERROR_BLOCKED);
1911 #if defined TIZEN_EXT
1912 static void set_dhcp_error(struct connman_network *network)
1914 struct connman_service *service;
1916 if (network->associating != FALSE)
1917 network->associating = FALSE;
1919 service = connman_service_lookup_from_network(network);
1921 __connman_service_indicate_error(service,
1922 CONNMAN_SERVICE_ERROR_DHCP_FAILED);
1926 void connman_network_set_ipv4_method(struct connman_network *network,
1927 enum connman_ipconfig_method method)
1929 struct connman_service *service;
1930 struct connman_ipconfig *ipconfig;
1932 service = connman_service_lookup_from_network(network);
1936 ipconfig = __connman_service_get_ip4config(service);
1940 __connman_ipconfig_set_method(ipconfig, method);
1943 void connman_network_set_ipv6_method(struct connman_network *network,
1944 enum connman_ipconfig_method method)
1946 struct connman_service *service;
1947 struct connman_ipconfig *ipconfig;
1949 service = connman_service_lookup_from_network(network);
1953 ipconfig = __connman_service_get_ip6config(service);
1957 __connman_ipconfig_set_method(ipconfig, method);
1960 void connman_network_set_error(struct connman_network *network,
1961 enum connman_network_error error)
1963 DBG("network %p error %d", network, error);
1966 case CONNMAN_NETWORK_ERROR_UNKNOWN:
1968 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
1969 set_associate_error(network);
1971 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
1972 set_configure_error(network);
1974 case CONNMAN_NETWORK_ERROR_INVALID_KEY:
1975 set_invalid_key_error(network);
1977 case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
1978 set_connect_error(network);
1980 #if defined TIZEN_EXT
1981 case CONNMAN_NETWORK_ERROR_AUTHENTICATE_FAIL:
1982 set_authenticate_error(network);
1984 case CONNMAN_NETWORK_ERROR_DHCP_FAIL:
1985 set_dhcp_error(network);
1989 case CONNMAN_NETWORK_ERROR_BLOCKED:
1990 set_blocked_error(network);
1994 __connman_network_disconnect(network);
1998 * connman_network_set_connected:
1999 * @network: network structure
2000 * @connected: connected state
2002 * Change connected state of network
2004 int connman_network_set_connected(struct connman_network *network,
2007 DBG("network %p connected %d/%d connecting %d associating %d",
2008 network, network->connected, connected, network->connecting,
2009 network->associating);
2011 if ((network->connecting || network->associating) &&
2013 connman_network_set_error(network,
2014 CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
2018 if (network->connected == connected)
2022 set_disconnected(network);
2024 set_connected(network);
2030 * connman_network_get_connected:
2031 * @network: network structure
2033 * Get network connection status
2035 bool connman_network_get_connected(struct connman_network *network)
2037 return network->connected;
2040 #if defined TIZEN_EXT
2041 bool connman_network_get_psk_sha256(struct connman_network *network)
2043 return network->is_psk_sha256;
2046 void connman_network_set_psk_sha256(struct connman_network *network, bool is_psk_sha256)
2048 network->is_psk_sha256 = is_psk_sha256;
2053 * connman_network_get_associating:
2054 * @network: network structure
2056 * Get network associating status
2058 bool connman_network_get_associating(struct connman_network *network)
2060 return network->associating;
2063 void connman_network_clear_hidden(void *user_data)
2068 DBG("user_data %p", user_data);
2071 * Hidden service does not have a connect timeout so
2072 * we do not need to remove it. We can just return
2073 * error to the caller telling that we could not find
2074 * any network that we could connect to.
2076 connman_dbus_reply_pending(user_data, EIO, NULL);
2079 int connman_network_connect_hidden(struct connman_network *network,
2080 char *identity, char *passphrase, void *user_data)
2083 struct connman_service *service;
2085 service = connman_service_lookup_from_network(network);
2087 DBG("network %p service %p user_data %p", network, service, user_data);
2093 __connman_service_set_agent_identity(service, identity);
2096 err = __connman_service_set_passphrase(service, passphrase);
2098 if (err == -ENOKEY) {
2099 __connman_service_indicate_error(service,
2100 CONNMAN_SERVICE_ERROR_INVALID_KEY);
2103 __connman_service_set_hidden(service);
2104 __connman_service_set_hidden_data(service, user_data);
2105 return __connman_service_connect(service,
2106 CONNMAN_SERVICE_CONNECT_REASON_USER);
2110 __connman_service_return_error(service, -err, user_data);
2114 #if defined TIZEN_EXT
2115 char *__connman_network_get_dhcp_status(const char *ifname)
2117 char *status = NULL;
2122 status = g_hash_table_lookup(dhcp_status_list, ifname);
2123 DBG("ifname: %s, DHCP status: %s", ifname, status);
2128 static void __connman_network_update_dhcp_status(
2129 const char *ifname, const char *status)
2131 if (!ifname || !status)
2134 g_hash_table_replace(dhcp_status_list, g_strdup(ifname), g_strdup(status));
2137 dbus_bool_t __connman_network_notify_dhcp_changed(const char *key, const char *val)
2139 DBusMessage *signal;
2140 DBusMessageIter iter;
2141 dbus_bool_t result = FALSE;
2144 if (!g_utf8_validate(val, -1, NULL)) {
2145 DBG("key %s, invalid val", key);
2148 DBG("key %s, val %s", key, val);
2151 DBG("key %s, val NULL", key);
2155 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
2156 CONNMAN_MANAGER_INTERFACE, "DhcpChanged");
2161 dbus_message_iter_init_append(signal, &iter);
2162 connman_dbus_property_append_basic(&iter, key, DBUS_TYPE_STRING, &val);
2164 result = dbus_connection_send(connection, signal, NULL);
2166 DBG("Successfuly sent signal");
2168 DBG("Fail to send signal");
2170 dbus_message_unref(signal);
2172 __connman_network_update_dhcp_status(val, key);
2179 * __connman_network_connect:
2180 * @network: network structure
2184 int __connman_network_connect(struct connman_network *network)
2188 DBG("network %p", network);
2190 if (network->connected)
2193 if (network->connecting || network->associating)
2196 if (!network->driver)
2199 if (!network->driver->connect)
2202 if (!network->device)
2205 #if defined TIZEN_EXT
2206 if (network->type != CONNMAN_NETWORK_TYPE_CELLULAR)
2208 __connman_device_disconnect(network->device);
2210 network->connecting = true;
2212 #if defined TIZEN_EXT
2213 DBG("ConnMan, Connect Request [%s]", network->name);
2216 err = network->driver->connect(network);
2218 if (err == -EINPROGRESS) {
2219 #if defined TIZEN_EXT
2220 if (network->type != CONNMAN_NETWORK_TYPE_CELLULAR)
2222 connman_network_set_associating(network, true);
2224 network->connecting = false;
2229 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
2231 * Note: If EAP on Ethernet is ON, then network will be connected
2232 * after EAP Success event is recieved, from plugin/ethernet.c
2234 struct connman_service *service = connman_service_lookup_from_network(network);
2235 if (service && __connman_service_get_use_eapol(service)) {
2236 connman_network_set_associating(network, true);
2239 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
2241 set_connected(network);
2247 * __connman_network_disconnect:
2248 * @network: network structure
2250 * Disconnect network
2252 int __connman_network_disconnect(struct connman_network *network)
2255 #if defined TIZEN_EXT
2256 if (!simplified_log)
2258 DBG("network %p", network);
2260 remove_ipv4ll_timeout(network);
2261 if (network->acd_host)
2262 acd_host_stop(network->acd_host);
2264 if (!network->connected && !network->connecting &&
2265 !network->associating)
2268 if (!network->driver)
2271 network->connecting = false;
2273 #if defined TIZEN_EXT
2274 DBG("ConnMan, Disconnect request");
2275 struct connman_service *service = connman_service_lookup_from_network(network);
2276 connman_service_set_disconnection_requested(service, true);
2278 if (network->driver->disconnect)
2279 err = network->driver->disconnect(network);
2281 if (err != -EINPROGRESS)
2282 set_disconnected(network);
2287 int __connman_network_clear_ipconfig(struct connman_network *network,
2288 struct connman_ipconfig *ipconfig)
2290 struct connman_service *service;
2291 struct connman_ipconfig *ipconfig_ipv4;
2292 enum connman_ipconfig_method method;
2293 enum connman_ipconfig_type type;
2295 service = connman_service_lookup_from_network(network);
2299 ipconfig_ipv4 = __connman_service_get_ip4config(service);
2300 method = __connman_ipconfig_get_method(ipconfig);
2301 type = __connman_ipconfig_get_config_type(ipconfig);
2304 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
2305 case CONNMAN_IPCONFIG_METHOD_OFF:
2306 case CONNMAN_IPCONFIG_METHOD_FIXED:
2308 case CONNMAN_IPCONFIG_METHOD_MANUAL:
2309 __connman_ipconfig_address_remove(ipconfig);
2311 case CONNMAN_IPCONFIG_METHOD_AUTO:
2312 release_dhcpv6(network);
2313 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2316 case CONNMAN_IPCONFIG_METHOD_DHCP:
2317 remove_dhcp_timeout(network);
2318 __connman_dhcp_stop(ipconfig_ipv4);
2322 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2323 __connman_service_ipconfig_indicate_state(service,
2324 CONNMAN_SERVICE_STATE_CONFIGURATION,
2325 CONNMAN_IPCONFIG_TYPE_IPV6);
2326 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2327 __connman_service_ipconfig_indicate_state(service,
2328 CONNMAN_SERVICE_STATE_CONFIGURATION,
2329 CONNMAN_IPCONFIG_TYPE_IPV4);
2334 #if defined TIZEN_EXT
2335 void __connman_network_set_auto_ipv6_gateway(char *gateway, void *user_data)
2339 struct connman_network *network = user_data;
2340 struct connman_service *service;
2341 struct connman_ipconfig *ipconfig = NULL;
2343 service = connman_service_lookup_from_network(network);
2344 if (service == NULL)
2347 ipconfig = __connman_service_get_ipconfig(service, AF_INET6);
2348 if (ipconfig == NULL)
2351 __connman_ipconfig_set_gateway(ipconfig, gateway);
2357 int __connman_network_enable_ipconfig(struct connman_network *network,
2358 struct connman_ipconfig *ipconfig)
2361 enum connman_ipconfig_type type;
2362 enum connman_ipconfig_method method;
2363 #if defined TIZEN_EXT
2364 struct connman_service *service;
2367 if (!network || !ipconfig)
2370 type = __connman_ipconfig_get_config_type(ipconfig);
2373 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
2374 case CONNMAN_IPCONFIG_TYPE_ALL:
2377 case CONNMAN_IPCONFIG_TYPE_IPV6:
2378 set_configuration(network, type);
2380 method = __connman_ipconfig_get_method(ipconfig);
2382 DBG("ipv6 ipconfig method %d", method);
2385 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
2388 case CONNMAN_IPCONFIG_METHOD_OFF:
2389 __connman_ipconfig_disable_ipv6(ipconfig);
2392 case CONNMAN_IPCONFIG_METHOD_AUTO:
2393 #if defined TIZEN_EXT
2394 service = connman_service_lookup_from_network(network);
2396 if(network->type == CONNMAN_NETWORK_TYPE_CELLULAR)
2397 __connman_service_ipconfig_indicate_state(service,
2398 CONNMAN_SERVICE_STATE_CONFIGURATION,
2399 CONNMAN_IPCONFIG_TYPE_IPV6);
2401 autoconf_ipv6_set(network);
2404 case CONNMAN_IPCONFIG_METHOD_FIXED:
2405 case CONNMAN_IPCONFIG_METHOD_MANUAL:
2406 r = manual_ipv6_set(network, ipconfig);
2409 case CONNMAN_IPCONFIG_METHOD_DHCP:
2416 case CONNMAN_IPCONFIG_TYPE_IPV4:
2417 set_configuration(network, type);
2419 method = __connman_ipconfig_get_method(ipconfig);
2421 DBG("ipv4 ipconfig method %d", method);
2424 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
2425 case CONNMAN_IPCONFIG_METHOD_OFF:
2428 case CONNMAN_IPCONFIG_METHOD_AUTO:
2432 case CONNMAN_IPCONFIG_METHOD_FIXED:
2433 case CONNMAN_IPCONFIG_METHOD_MANUAL:
2434 r = set_connected_manual(network);
2437 case CONNMAN_IPCONFIG_METHOD_DHCP:
2438 r = set_connected_dhcp(network);
2446 connman_network_set_error(network,
2447 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
2452 int connman_network_set_ipaddress(struct connman_network *network,
2453 struct connman_ipaddress *ipaddress)
2455 struct connman_service *service;
2456 struct connman_ipconfig *ipconfig = NULL;
2458 DBG("network %p", network);
2460 service = connman_service_lookup_from_network(network);
2464 ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
2468 __connman_ipconfig_set_local(ipconfig, ipaddress->local);
2469 __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
2470 __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
2471 __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
2472 __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
2477 #if defined TIZEN_EXT
2479 * Description: Network client requires additional wifi specific info
2481 int connman_network_set_bssid(struct connman_network *network,
2482 const unsigned char *bssid)
2489 if (!simplified_log)
2490 DBG("network %p bssid %02x:%02x:%02x:%02x:%02x:%02x", network,
2491 bssid[0], bssid[1], bssid[2],
2492 bssid[3], bssid[4], bssid[5]);
2494 for (;i < WIFI_BSSID_LEN_MAX;i++)
2495 network->wifi.bssid[i] = bssid[i];
2500 unsigned char *connman_network_get_bssid(struct connman_network *network)
2502 return (unsigned char *)network->wifi.bssid;
2505 int connman_network_set_transition_mode_bssid(struct connman_network *network,
2506 const unsigned char *transition_mode_bssid)
2510 if (transition_mode_bssid == NULL)
2513 for (;i < WIFI_BSSID_LEN_MAX;i++)
2514 network->wifi.transition_mode_bssid[i] = transition_mode_bssid[i];
2519 unsigned char *connman_network_get_transition_mode_bssid(struct connman_network *network)
2521 return (unsigned char *)network->wifi.transition_mode_bssid;
2524 bool connman_network_check_transition_mode(struct connman_network *network1, struct connman_network *network2)
2527 if (network1 == NULL || network2 == NULL)
2530 if (network1->wifi.owe_transition_mode == FALSE || network2->wifi.owe_transition_mode == FALSE)
2533 if ((memcmp(network1->wifi.bssid, network2->wifi.transition_mode_bssid, WIFI_BSSID_LEN_MAX) == 0)
2534 && (memcmp(network1->wifi.transition_mode_bssid, network2->wifi.bssid, WIFI_BSSID_LEN_MAX) == 0))
2540 int connman_network_set_maxspeed(struct connman_network *network,
2543 network->wifi.maxspeed = maxspeed;
2547 int connman_network_get_maxspeed(struct connman_network *network)
2549 if (!network->driver)
2552 if (network->connected)
2553 return network->wifi.maxspeed;
2558 int connman_network_set_sec_list(struct connman_network *network,
2561 g_slist_free(network->wifi.sec_list);
2562 network->wifi.sec_list = sec_list;
2567 void *connman_network_get_sec_list(struct connman_network *network)
2569 return network->wifi.sec_list;
2572 int connman_network_set_maxrate(struct connman_network *network,
2573 unsigned int maxrate)
2575 #if !defined TIZEN_EXT
2576 DBG("network %p maxrate %d", network, maxrate);
2579 network->wifi.maxrate = maxrate;
2584 unsigned int connman_network_get_maxrate(struct connman_network *network)
2586 return network->wifi.maxrate;
2589 int connman_network_set_enc_mode(struct connman_network *network,
2590 const char *encryption_mode)
2592 if (encryption_mode == NULL)
2595 if (!simplified_log)
2596 DBG("network %p encryption mode %s", network, encryption_mode);
2598 g_strlcpy(network->wifi.encryption_mode, encryption_mode,
2599 WIFI_ENCYPTION_MODE_LEN_MAX);
2604 const char *connman_network_get_enc_mode(struct connman_network *network)
2606 return (const char *)network->wifi.encryption_mode;
2609 int connman_network_set_rsn_mode(struct connman_network *network,
2612 network->wifi.rsn_mode = rsn_mode;
2617 int connman_network_set_proxy(struct connman_network *network,
2618 const char *proxies)
2620 struct connman_service *service;
2622 DBG("network %p proxies %s", network, proxies);
2624 service = connman_service_lookup_from_network(network);
2625 if (service == NULL)
2628 __connman_service_set_proxy(service, proxies);
2630 connman_service_set_proxy_method(service,
2631 CONNMAN_SERVICE_PROXY_METHOD_MANUAL);
2636 int connman_network_set_keymgmt(struct connman_network *network,
2637 unsigned int keymgmt)
2639 if (network == NULL)
2642 network->wifi.keymgmt = keymgmt;
2647 unsigned int connman_network_get_keymgmt(struct connman_network *network)
2649 if (network == NULL)
2652 return network->wifi.keymgmt;
2655 int connman_network_set_disconnect_reason(struct connman_network *network,
2658 if (network == NULL)
2661 network->wifi.disconnect_reason = reason_code;
2666 int connman_network_get_disconnect_reason(struct connman_network *network)
2668 if (network == NULL)
2671 return network->wifi.disconnect_reason;
2673 int connman_network_get_assoc_status_code(struct connman_network *network)
2675 if (network == NULL)
2678 return network->wifi.assoc_status_code;
2681 int connman_network_set_countrycode(struct connman_network *network,
2682 const unsigned char *country_code)
2686 if (country_code == NULL)
2689 if (!simplified_log)
2690 DBG("network %p Country Code %02x:%02x",network,
2691 country_code[0],country_code[1]);
2693 for (; i < WIFI_COUNTRY_CODE_LEN; i++)
2694 network->wifi.country_code[i] = country_code[i];
2699 unsigned char *connman_network_get_countrycode(struct connman_network *network)
2701 return (unsigned char *)network->wifi.country_code;
2704 int connman_network_set_bssid_list(struct connman_network *network,
2707 unsigned int max_bssid_count;
2709 g_slist_free_full(network->wifi.bssid_list, g_free);
2710 network->wifi.bssid_list = bssids;
2712 max_bssid_count = g_slist_length(bssids);
2713 if (network->wifi.max_bssid_count < max_bssid_count)
2714 network->wifi.max_bssid_count = max_bssid_count;
2719 int connman_network_set_phy_mode(struct connman_network *network,
2720 ieee80211_modes_e mode)
2722 if (!simplified_log)
2723 DBG("network %p phy mode %d", network, mode);
2724 network->wifi.phy_mode = mode;
2729 ieee80211_modes_e connman_network_get_phy_mode(struct connman_network *network)
2731 return network->wifi.phy_mode;
2734 int connman_network_set_connection_mode(struct connman_network *network,
2735 connection_mode_e mode)
2737 DBG("network %p connection mode %d", network, mode);
2738 network->wifi.connection_mode = mode;
2743 connection_mode_e connman_network_get_connection_mode(struct connman_network *network)
2745 return network->wifi.connection_mode;
2748 void *connman_network_get_bssid_list(struct connman_network *network)
2750 return network->wifi.bssid_list;
2753 unsigned int connman_network_get_max_bssid_count(struct connman_network *network)
2755 return network->wifi.max_bssid_count;
2758 int connman_network_set_last_connected_bssid(struct connman_network *network,
2759 const unsigned char *bssid)
2764 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2767 memcpy(network->wifi.last_connected_bssid, bssid, WIFI_BSSID_LEN_MAX);
2772 unsigned char *connman_network_get_last_connected_bssid(struct connman_network *network)
2774 return (unsigned char *)network->wifi.last_connected_bssid;
2777 void connman_network_set_assoc_reject_table(struct connman_network *network,
2778 GHashTable *assoc_reject_table)
2783 if (!assoc_reject_table)
2786 g_hash_table_destroy(network->wifi.assoc_reject_table);
2788 network->wifi.assoc_reject_table = assoc_reject_table;
2791 GHashTable *connman_network_get_assoc_reject_table(struct connman_network *network)
2796 return network->wifi.assoc_reject_table;
2799 __time_t connman_network_get_roam_scan_time(struct connman_network *network)
2801 return network->wifi.roam_scan_time;
2804 void connman_network_set_roam_scan_time(struct connman_network *network,
2805 __time_t roam_scan_time)
2807 network->wifi.roam_scan_time = roam_scan_time;
2810 int connman_network_get_snr(struct connman_network *network)
2812 return network->wifi.snr;
2815 void connman_network_set_snr(struct connman_network *network, int snr)
2817 network->wifi.snr = snr;
2820 unsigned int connman_network_get_est_throughput(struct connman_network *network)
2822 return network->wifi.est_throughput;
2825 void connman_network_set_est_throughput(struct connman_network *network,
2826 unsigned int est_throughput)
2828 network->wifi.est_throughput = est_throughput;
2832 int connman_network_set_nameservers(struct connman_network *network,
2833 const char *nameservers)
2835 struct connman_service *service;
2836 char **nameservers_array;
2839 DBG("network %p nameservers %s", network, nameservers);
2841 service = connman_service_lookup_from_network(network);
2845 __connman_service_nameserver_clear(service);
2850 nameservers_array = g_strsplit(nameservers, " ", 0);
2852 for (i = 0; nameservers_array[i]; i++) {
2853 #if defined TIZEN_EXT
2854 __connman_service_nameserver_append(service,
2855 nameservers_array[i], false,
2856 CONNMAN_IPCONFIG_TYPE_ALL);
2858 __connman_service_nameserver_append(service,
2859 nameservers_array[i], false);
2863 g_strfreev(nameservers_array);
2868 int connman_network_set_domain(struct connman_network *network,
2871 struct connman_service *service;
2873 DBG("network %p domain %s", network, domain);
2875 service = connman_service_lookup_from_network(network);
2879 __connman_service_set_domainname(service, domain);
2885 * connman_network_set_name:
2886 * @network: network structure
2889 * Set display name value for network
2891 int connman_network_set_name(struct connman_network *network,
2894 #if defined TIZEN_EXT
2895 if (!simplified_log)
2897 DBG("network %p name %s", network, name);
2899 g_free(network->name);
2900 network->name = g_strdup(name);
2906 * connman_network_set_strength:
2907 * @network: network structure
2908 * @strength: strength value
2910 * Set signal strength value for network
2913 int connman_network_set_strength(struct connman_network *network,
2916 network->strength = strength;
2917 #if defined TIZEN_EXT
2918 __connman_service_notify_strength_changed(network);
2924 uint8_t connman_network_get_strength(struct connman_network *network)
2926 return network->strength;
2929 int connman_network_set_frequency(struct connman_network *network,
2932 network->frequency = frequency;
2937 uint16_t connman_network_get_frequency(struct connman_network *network)
2939 return network->frequency;
2942 int connman_network_set_wifi_channel(struct connman_network *network,
2945 network->wifi.channel = channel;
2950 int connman_network_set_autoconnect(struct connman_network *network,
2953 if (!network->driver || !network->driver->set_autoconnect)
2955 return network->driver->set_autoconnect(network, autoconnect);
2958 bool __connman_network_native_autoconnect(struct connman_network *network)
2960 if (!network->driver || !network->driver->set_autoconnect)
2965 uint16_t connman_network_get_wifi_channel(struct connman_network *network)
2967 return network->wifi.channel;
2971 * connman_network_set_string:
2972 * @network: network structure
2973 * @key: unique identifier
2974 * @value: string value
2976 * Set string value for specific key
2978 int connman_network_set_string(struct connman_network *network,
2979 const char *key, const char *value)
2981 if (g_strcmp0(key, "Name") == 0)
2982 return connman_network_set_name(network, value);
2984 if (g_str_equal(key, "Path")) {
2985 g_free(network->path);
2986 network->path = g_strdup(value);
2987 } else if (g_str_equal(key, "Node")) {
2988 g_free(network->node);
2989 network->node = g_strdup(value);
2990 } else if (g_str_equal(key, "WiFi.Mode")) {
2991 g_free(network->wifi.mode);
2992 network->wifi.mode = g_strdup(value);
2993 } else if (g_str_equal(key, "WiFi.Security")) {
2994 g_free(network->wifi.security);
2995 network->wifi.security = g_strdup(value);
2996 } else if (g_str_equal(key, "WiFi.Passphrase")) {
2997 #if defined TIZEN_EXT
2998 DBG("ConnMan, %p key %s", network, key);
3000 g_free(network->wifi.passphrase);
3001 network->wifi.passphrase = g_strdup(value);
3002 } else if (g_str_equal(key, "WiFi.EAP")) {
3003 g_free(network->wifi.eap);
3004 network->wifi.eap = g_strdup(value);
3005 } else if (g_str_equal(key, "WiFi.Identity")) {
3006 g_free(network->wifi.identity);
3007 network->wifi.identity = g_strdup(value);
3008 } else if (g_str_equal(key, "WiFi.AnonymousIdentity")) {
3009 g_free(network->wifi.anonymous_identity);
3010 network->wifi.anonymous_identity = g_strdup(value);
3011 } else if (g_str_equal(key, "WiFi.AgentIdentity")) {
3012 g_free(network->wifi.agent_identity);
3013 network->wifi.agent_identity = g_strdup(value);
3014 } else if (g_str_equal(key, "WiFi.CACertFile")) {
3015 g_free(network->wifi.ca_cert_path);
3016 network->wifi.ca_cert_path = g_strdup(value);
3017 } else if (g_str_equal(key, "WiFi.SubjectMatch")) {
3018 g_free(network->wifi.subject_match);
3019 network->wifi.subject_match = g_strdup(value);
3020 } else if (g_str_equal(key, "WiFi.AltSubjectMatch")) {
3021 g_free(network->wifi.altsubject_match);
3022 network->wifi.altsubject_match = g_strdup(value);
3023 } else if (g_str_equal(key, "WiFi.DomainSuffixMatch")) {
3024 g_free(network->wifi.domain_suffix_match);
3025 network->wifi.domain_suffix_match = g_strdup(value);
3026 } else if (g_str_equal(key, "WiFi.DomainMatch")) {
3027 g_free(network->wifi.domain_match);
3028 network->wifi.domain_match = g_strdup(value);
3029 } else if (g_str_equal(key, "WiFi.ClientCertFile")) {
3030 g_free(network->wifi.client_cert_path);
3031 network->wifi.client_cert_path = g_strdup(value);
3032 } else if (g_str_equal(key, "WiFi.PrivateKeyFile")) {
3033 g_free(network->wifi.private_key_path);
3034 network->wifi.private_key_path = g_strdup(value);
3035 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase")) {
3036 g_free(network->wifi.private_key_passphrase);
3037 network->wifi.private_key_passphrase = g_strdup(value);
3038 } else if (g_str_equal(key, "WiFi.Phase2")) {
3039 g_free(network->wifi.phase2_auth);
3040 network->wifi.phase2_auth = g_strdup(value);
3041 } else if (g_str_equal(key, "WiFi.PinWPS")) {
3042 g_free(network->wifi.pin_wps);
3043 network->wifi.pin_wps = g_strdup(value);
3044 #if defined TIZEN_EXT
3045 } else if (g_str_equal(key, "WiFi.Connector")) {
3046 g_free(network->wifi.connector);
3047 network->wifi.connector = g_strdup(value);
3048 } else if (g_str_equal(key, "WiFi.CSignKey")) {
3049 g_free(network->wifi.c_sign_key);
3050 network->wifi.c_sign_key = g_strdup(value);
3051 } else if (g_str_equal(key, "WiFi.NetAccessKey")) {
3052 g_free(network->wifi.net_access_key);
3053 network->wifi.net_access_key = g_strdup(value);
3054 } else if (g_str_equal(key, "WiFi.RoamingCurBSSID")) {
3055 g_free(network->wifi.roaming_cur_bssid);
3056 network->wifi.roaming_cur_bssid = g_strdup(value);
3057 } else if (g_str_equal(key, "WiFi.RoamingDstBSSID")) {
3058 g_free(network->wifi.roaming_dst_bssid);
3059 network->wifi.roaming_dst_bssid = g_strdup(value);
3069 * connman_network_get_string:
3070 * @network: network structure
3071 * @key: unique identifier
3073 * Get string value for specific key
3075 const char *connman_network_get_string(struct connman_network *network,
3078 if (g_str_equal(key, "Path"))
3079 return network->path;
3080 else if (g_str_equal(key, "Name"))
3081 return network->name;
3082 else if (g_str_equal(key, "Node"))
3083 return network->node;
3084 else if (g_str_equal(key, "WiFi.Mode"))
3085 return network->wifi.mode;
3086 else if (g_str_equal(key, "WiFi.Security"))
3087 return network->wifi.security;
3088 else if (g_str_equal(key, "WiFi.Passphrase"))
3089 return network->wifi.passphrase;
3090 else if (g_str_equal(key, "WiFi.EAP"))
3091 return network->wifi.eap;
3092 else if (g_str_equal(key, "WiFi.Identity"))
3093 return network->wifi.identity;
3094 else if (g_str_equal(key, "WiFi.AnonymousIdentity"))
3095 return network->wifi.anonymous_identity;
3096 else if (g_str_equal(key, "WiFi.AgentIdentity"))
3097 return network->wifi.agent_identity;
3098 else if (g_str_equal(key, "WiFi.CACertFile"))
3099 return network->wifi.ca_cert_path;
3100 else if (g_str_equal(key, "WiFi.SubjectMatch"))
3101 return network->wifi.subject_match;
3102 else if (g_str_equal(key, "WiFi.AltSubjectMatch"))
3103 return network->wifi.altsubject_match;
3104 else if (g_str_equal(key, "WiFi.DomainSuffixMatch"))
3105 return network->wifi.domain_suffix_match;
3106 else if (g_str_equal(key, "WiFi.DomainMatch"))
3107 return network->wifi.domain_match;
3108 else if (g_str_equal(key, "WiFi.ClientCertFile"))
3109 return network->wifi.client_cert_path;
3110 else if (g_str_equal(key, "WiFi.PrivateKeyFile"))
3111 return network->wifi.private_key_path;
3112 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase"))
3113 return network->wifi.private_key_passphrase;
3114 else if (g_str_equal(key, "WiFi.Phase2"))
3115 return network->wifi.phase2_auth;
3116 else if (g_str_equal(key, "WiFi.PinWPS"))
3117 return network->wifi.pin_wps;
3118 #if defined TIZEN_EXT
3119 else if (g_str_equal(key, "WiFi.Connector"))
3120 return network->wifi.connector;
3121 else if (g_str_equal(key, "WiFi.CSignKey"))
3122 return network->wifi.c_sign_key;
3123 else if (g_str_equal(key, "WiFi.NetAccessKey"))
3124 return network->wifi.net_access_key;
3125 else if (g_str_equal(key, "WiFi.RoamingCurBSSID"))
3126 return network->wifi.roaming_cur_bssid;
3127 else if (g_str_equal(key, "WiFi.RoamingDstBSSID"))
3128 return network->wifi.roaming_dst_bssid;
3135 * connman_network_set_bool:
3136 * @network: network structure
3137 * @key: unique identifier
3138 * @value: boolean value
3140 * Set boolean value for specific key
3142 int connman_network_set_bool(struct connman_network *network,
3143 const char *key, bool value)
3145 if (g_strcmp0(key, "Roaming") == 0)
3146 network->roaming = value;
3147 else if (g_strcmp0(key, "WiFi.WPS") == 0)
3148 network->wifi.wps = value;
3149 else if (g_strcmp0(key, "WiFi.WPSAdvertising") == 0)
3150 network->wifi.wps_advertizing = value;
3151 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
3152 network->wifi.use_wps = value;
3153 #if defined TIZEN_EXT
3154 else if (g_strcmp0(key, "DefaultInternet") == 0)
3155 network->default_internet = value;
3156 else if (g_strcmp0(key, "WiFi.HS20AP") == 0)
3157 network->wifi.isHS20AP = value;
3158 else if (g_strcmp0(key, "WiFi.TRANSITION_MODE") == 0)
3159 network->wifi.owe_transition_mode = value;
3160 else if (g_strcmp0(key, "WiFi.Roaming") == 0)
3161 network->wifi.roaming_progress = value;
3162 else if (g_strcmp0(key, "WiFi.RoamingDHCP") == 0)
3163 network->wifi.roaming_dhcp = value;
3164 else if (g_strcmp0(key, "WiFi.PMFRequired") == 0)
3165 network->wifi.pmf_required = value;
3172 * connman_network_get_bool:
3173 * @network: network structure
3174 * @key: unique identifier
3176 * Get boolean value for specific key
3178 bool connman_network_get_bool(struct connman_network *network,
3181 if (g_str_equal(key, "Roaming"))
3182 return network->roaming;
3183 else if (g_str_equal(key, "WiFi.WPS"))
3184 return network->wifi.wps;
3185 else if (g_str_equal(key, "WiFi.WPSAdvertising"))
3186 return network->wifi.wps_advertizing;
3187 else if (g_str_equal(key, "WiFi.UseWPS"))
3188 return network->wifi.use_wps;
3189 #if defined TIZEN_EXT
3190 else if (g_str_equal(key, "DefaultInternet"))
3191 return network->default_internet;
3192 else if (g_str_equal(key, "WiFi.HS20AP"))
3193 return network->wifi.isHS20AP;
3194 else if (g_str_equal(key, "WiFi.TRANSITION_MODE"))
3195 return network->wifi.owe_transition_mode;
3196 else if (g_str_equal(key, "WiFi.Roaming"))
3197 return network->wifi.roaming_progress;
3198 else if (g_str_equal(key, "WiFi.RoamingDHCP"))
3199 return network->wifi.roaming_dhcp;
3200 else if (g_str_equal(key, "WiFi.PMFRequired"))
3201 return network->wifi.pmf_required;
3207 #if defined TIZEN_EXT
3209 * connman_network_set_vsie_list:
3210 * @network: network structure
3211 * @vsie_list: GSList pointer
3213 * Set vendor specific list pointer
3215 void connman_network_set_vsie_list(struct connman_network *network, GSList *vsie_list)
3217 g_slist_free_full(network->wifi.vsie_list, g_free);
3218 network->wifi.vsie_list = vsie_list;
3222 * connman_network_get_vsie_list:
3223 * @network: network structure
3225 * Get vendor specific list pointer
3227 void *connman_network_get_vsie_list(struct connman_network *network)
3229 return network->wifi.vsie_list;
3234 * connman_network_set_blob:
3235 * @network: network structure
3236 * @key: unique identifier
3240 * Set binary blob value for specific key
3242 int connman_network_set_blob(struct connman_network *network,
3243 const char *key, const void *data, unsigned int size)
3245 if (g_str_equal(key, "WiFi.SSID")) {
3246 g_free(network->wifi.ssid);
3247 network->wifi.ssid = g_try_malloc(size);
3248 if (network->wifi.ssid) {
3249 memcpy(network->wifi.ssid, data, size);
3250 network->wifi.ssid_len = size;
3252 network->wifi.ssid_len = 0;
3254 } else if (g_str_equal(key, "WiFi.TRANSITION_MODE_SSID")) {
3255 g_free(network->wifi.transition_mode_ssid);
3256 network->wifi.transition_mode_ssid = g_try_malloc(size);
3257 if (network->wifi.transition_mode_ssid) {
3258 memcpy(network->wifi.transition_mode_ssid, data, size);
3259 network->wifi.transition_mode_ssid_len = size;
3261 network->wifi.transition_mode_ssid_len = 0;
3271 * connman_network_get_blob:
3272 * @network: network structure
3273 * @key: unique identifier
3274 * @size: pointer to blob size
3276 * Get binary blob value for specific key
3278 const void *connman_network_get_blob(struct connman_network *network,
3279 const char *key, unsigned int *size)
3281 if (g_str_equal(key, "WiFi.SSID")) {
3283 *size = network->wifi.ssid_len;
3284 return network->wifi.ssid;
3286 } else if (g_str_equal(key, "WiFi.TRANSITION_MODE_SSID")) {
3288 *size = network->wifi.transition_mode_ssid_len;
3289 return network->wifi.transition_mode_ssid;
3296 void __connman_network_set_device(struct connman_network *network,
3297 struct connman_device *device)
3299 if (network->device == device)
3302 if (network->device)
3303 network_remove(network);
3305 network->device = device;
3307 if (network->device)
3308 network_probe(network);
3312 * connman_network_get_device:
3313 * @network: network structure
3315 * Get parent device of network
3317 struct connman_device *connman_network_get_device(struct connman_network *network)
3319 return network->device;
3323 * connman_network_get_data:
3324 * @network: network structure
3326 * Get private network data pointer
3328 void *connman_network_get_data(struct connman_network *network)
3330 return network->driver_data;
3334 * connman_network_set_data:
3335 * @network: network structure
3336 * @data: data pointer
3338 * Set private network data pointer
3340 void connman_network_set_data(struct connman_network *network, void *data)
3342 network->driver_data = data;
3345 void connman_network_update(struct connman_network *network)
3347 switch (network->type) {
3348 case CONNMAN_NETWORK_TYPE_UNKNOWN:
3349 case CONNMAN_NETWORK_TYPE_VENDOR:
3351 case CONNMAN_NETWORK_TYPE_ETHERNET:
3352 case CONNMAN_NETWORK_TYPE_GADGET:
3353 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
3354 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
3355 case CONNMAN_NETWORK_TYPE_CELLULAR:
3356 case CONNMAN_NETWORK_TYPE_WIFI:
3361 __connman_service_update_from_network(network);
3364 int __connman_network_init(void)
3367 #if defined TIZEN_EXT
3368 connection = connman_dbus_get_connection();
3369 dhcp_status_list = g_hash_table_new_full(g_str_hash,
3370 g_str_equal, g_free, g_free);
3376 void __connman_network_cleanup(void)
3379 #if defined TIZEN_EXT
3380 dbus_connection_unref(connection);
3381 if (dhcp_status_list)
3382 g_hash_table_destroy(dhcp_status_list);