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
32 * How many times to send RS with the purpose of
33 * refreshing RDNSS entries before they actually expire.
34 * With a value of 1, one RS will be sent, with no retries.
36 #define RS_REFRESH_COUNT 1
39 * Value in seconds to wait for RA after RS was sent.
40 * After this time elapsed, we can send another RS.
42 #define RS_REFRESH_TIMEOUT 3
45 #define WIFI_ENCYPTION_MODE_LEN_MAX 6
46 #define WIFI_BSSID_LEN_MAX 6
49 static GSList *network_list = NULL;
50 static GSList *driver_list = NULL;
52 struct connman_network {
54 enum connman_network_type type;
66 int router_solicit_count;
67 int router_solicit_refresh_count;
69 struct connman_network_driver *driver;
75 struct connman_device *device;
81 unsigned short channel;
88 char *client_cert_path;
89 char *private_key_path;
90 char *private_key_passphrase;
96 char encryption_mode[WIFI_ENCYPTION_MODE_LEN_MAX];
97 unsigned char bssid[WIFI_BSSID_LEN_MAX];
99 unsigned int isHS20AP;
104 #if defined TIZEN_EXT
105 /* Multiple APN services and a default APN which a user selected */
106 bool default_internet;
111 static const char *type2string(enum connman_network_type type)
114 case CONNMAN_NETWORK_TYPE_UNKNOWN:
115 case CONNMAN_NETWORK_TYPE_VENDOR:
117 case CONNMAN_NETWORK_TYPE_ETHERNET:
119 case CONNMAN_NETWORK_TYPE_GADGET:
121 case CONNMAN_NETWORK_TYPE_WIFI:
123 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
124 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
126 case CONNMAN_NETWORK_TYPE_CELLULAR:
133 static bool match_driver(struct connman_network *network,
134 struct connman_network_driver *driver)
136 if (network->type == driver->type ||
137 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
143 static void set_configuration(struct connman_network *network,
144 enum connman_ipconfig_type type)
146 struct connman_service *service;
148 DBG("network %p", network);
150 if (!network->device)
153 __connman_device_set_network(network->device, network);
155 connman_device_set_disconnected(network->device, false);
157 service = connman_service_lookup_from_network(network);
158 __connman_service_ipconfig_indicate_state(service,
159 CONNMAN_SERVICE_STATE_CONFIGURATION,
163 static void dhcp_success(struct connman_network *network)
165 struct connman_service *service;
166 struct connman_ipconfig *ipconfig_ipv4;
169 service = connman_service_lookup_from_network(network);
173 ipconfig_ipv4 = __connman_service_get_ip4config(service);
175 DBG("lease acquired for ipconfig %p", ipconfig_ipv4);
180 err = __connman_ipconfig_address_add(ipconfig_ipv4);
184 #if defined TIZEN_EXT
185 err = __connman_ipconfig_gateway_add(ipconfig_ipv4, service);
187 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
195 connman_network_set_error(network,
196 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
199 static void dhcp_failure(struct connman_network *network)
201 struct connman_service *service;
202 struct connman_ipconfig *ipconfig_ipv4;
204 service = connman_service_lookup_from_network(network);
208 ipconfig_ipv4 = __connman_service_get_ip4config(service);
210 DBG("lease lost for ipconfig %p", ipconfig_ipv4);
215 __connman_ipconfig_address_remove(ipconfig_ipv4);
216 __connman_ipconfig_gateway_remove(ipconfig_ipv4);
219 static void dhcp_callback(struct connman_ipconfig *ipconfig,
220 struct connman_network *network,
221 bool success, gpointer data)
223 network->connecting = false;
226 dhcp_success(network);
228 dhcp_failure(network);
231 static int set_connected_manual(struct connman_network *network)
234 struct connman_service *service;
235 struct connman_ipconfig *ipconfig;
237 DBG("network %p", network);
239 network->connecting = false;
241 service = connman_service_lookup_from_network(network);
243 ipconfig = __connman_service_get_ip4config(service);
245 if (!__connman_ipconfig_get_local(ipconfig))
246 __connman_service_read_ip4config(service);
248 err = __connman_ipconfig_address_add(ipconfig);
252 #if defined TIZEN_EXT
253 err = __connman_ipconfig_gateway_add(ipconfig, service);
255 err = __connman_ipconfig_gateway_add(ipconfig);
264 static int set_connected_dhcp(struct connman_network *network)
266 struct connman_service *service;
267 struct connman_ipconfig *ipconfig_ipv4;
270 DBG("network %p", network);
272 service = connman_service_lookup_from_network(network);
273 ipconfig_ipv4 = __connman_service_get_ip4config(service);
275 err = __connman_dhcp_start(ipconfig_ipv4, network,
276 dhcp_callback, NULL);
278 connman_error("Can not request DHCP lease");
285 static int manual_ipv6_set(struct connman_network *network,
286 struct connman_ipconfig *ipconfig_ipv6)
288 struct connman_service *service;
291 DBG("network %p ipv6 %p", network, ipconfig_ipv6);
293 service = connman_service_lookup_from_network(network);
297 if (!__connman_ipconfig_get_local(ipconfig_ipv6))
298 __connman_service_read_ip6config(service);
300 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
302 err = __connman_ipconfig_address_add(ipconfig_ipv6);
304 connman_network_set_error(network,
305 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
309 #if defined TIZEN_EXT
310 err = __connman_ipconfig_gateway_add(ipconfig_ipv6, service);
312 err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
317 __connman_connection_gateway_activate(service,
318 CONNMAN_IPCONFIG_TYPE_IPV6);
320 __connman_device_set_network(network->device, network);
322 connman_device_set_disconnected(network->device, false);
324 connman_network_set_associating(network, false);
326 network->connecting = false;
331 static void stop_dhcpv6(struct connman_network *network)
333 network->connecting = false;
335 __connman_dhcpv6_stop(network);
338 static void dhcpv6_release_callback(struct connman_network *network,
339 enum __connman_dhcpv6_status status,
342 DBG("status %d", status);
344 stop_dhcpv6(network);
347 static void release_dhcpv6(struct connman_network *network)
349 __connman_dhcpv6_start_release(network, dhcpv6_release_callback);
350 stop_dhcpv6(network);
353 static void dhcpv6_info_callback(struct connman_network *network,
354 enum __connman_dhcpv6_status status,
357 DBG("status %d", status);
359 stop_dhcpv6(network);
362 static int dhcpv6_set_addresses(struct connman_network *network)
364 struct connman_service *service;
365 struct connman_ipconfig *ipconfig_ipv6;
368 service = connman_service_lookup_from_network(network);
372 network->connecting = false;
374 ipconfig_ipv6 = __connman_service_get_ip6config(service);
375 err = __connman_ipconfig_address_add(ipconfig_ipv6);
382 connman_network_set_error(network,
383 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
387 static void autoconf_ipv6_set(struct connman_network *network);
388 static void dhcpv6_callback(struct connman_network *network,
389 enum __connman_dhcpv6_status status, gpointer data);
392 * Have a separate callback for renew so that we do not do autoconf
393 * in wrong phase as the dhcpv6_callback() is also called when doing
394 * DHCPv6 solicitation.
396 static void dhcpv6_renew_callback(struct connman_network *network,
397 enum __connman_dhcpv6_status status,
401 case CONNMAN_DHCPV6_STATUS_SUCCEED:
402 dhcpv6_callback(network, status, data);
404 case CONNMAN_DHCPV6_STATUS_FAIL:
405 case CONNMAN_DHCPV6_STATUS_RESTART:
406 stop_dhcpv6(network);
408 /* restart and do solicit again. */
409 autoconf_ipv6_set(network);
414 static void dhcpv6_callback(struct connman_network *network,
415 enum __connman_dhcpv6_status status, gpointer data)
417 DBG("status %d", status);
419 /* Start the renew process if necessary */
420 if (status == CONNMAN_DHCPV6_STATUS_SUCCEED) {
422 if (dhcpv6_set_addresses(network) < 0) {
423 stop_dhcpv6(network);
427 if (__connman_dhcpv6_start_renew(network,
428 dhcpv6_renew_callback) == -ETIMEDOUT)
429 dhcpv6_renew_callback(network,
430 CONNMAN_DHCPV6_STATUS_FAIL,
433 } else if (status == CONNMAN_DHCPV6_STATUS_RESTART) {
434 stop_dhcpv6(network);
435 autoconf_ipv6_set(network);
437 stop_dhcpv6(network);
440 static void check_dhcpv6(struct nd_router_advert *reply,
441 unsigned int length, void *user_data)
443 struct connman_network *network = user_data;
444 struct connman_service *service;
447 DBG("reply %p", reply);
451 * Router solicitation message seem to get lost easily so
452 * try to send it again.
454 if (network->router_solicit_count > 0) {
455 DBG("re-send router solicitation %d",
456 network->router_solicit_count);
457 network->router_solicit_count--;
458 __connman_inet_ipv6_send_rs(network->index, 1,
459 check_dhcpv6, network);
462 connman_network_unref(network);
466 network->router_solicit_count = 0;
469 * If we were disconnected while waiting router advertisement,
470 * we just quit and do not start DHCPv6
472 if (!network->connected) {
473 connman_network_unref(network);
477 prefixes = __connman_inet_ipv6_get_prefixes(reply, length);
480 * If IPv6 config is missing from service, then create it.
481 * The ipconfig might be missing if we got a rtnl message
482 * that disabled IPv6 config and thus removed it. This
483 * can happen if we are switching from one service to
484 * another in the same interface. The only way to get IPv6
485 * config back is to re-create it here.
487 service = connman_service_lookup_from_network(network);
489 connman_service_create_ip6config(service, network->index);
491 connman_network_set_associating(network, false);
493 __connman_service_ipconfig_indicate_state(service,
494 CONNMAN_SERVICE_STATE_CONFIGURATION,
495 CONNMAN_IPCONFIG_TYPE_IPV6);
499 * We do stateful/stateless DHCPv6 if router advertisement says so.
501 if (reply->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) {
502 __connman_dhcpv6_start(network, prefixes, dhcpv6_callback);
504 if (reply->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
505 __connman_dhcpv6_start_info(network,
506 dhcpv6_info_callback);
508 g_slist_free_full(prefixes, g_free);
509 network->connecting = false;
512 connman_network_unref(network);
515 static void receive_refresh_rs_reply(struct nd_router_advert *reply,
516 unsigned int length, void *user_data)
518 struct connman_network *network = user_data;
520 DBG("reply %p", reply);
524 * Router solicitation message seem to get lost easily so
525 * try to send it again.
527 if (network->router_solicit_refresh_count > 1) {
528 network->router_solicit_refresh_count--;
529 DBG("re-send router solicitation %d",
530 network->router_solicit_refresh_count);
531 __connman_inet_ipv6_send_rs(network->index,
533 receive_refresh_rs_reply,
539 /* RS refresh not in progress anymore */
540 network->router_solicit_refresh_count = 0;
542 connman_network_unref(network);
546 int __connman_network_refresh_rs_ipv6(struct connman_network *network,
551 DBG("network %p index %d", network, index);
553 /* Send only one RS for all RDNSS entries which are about to expire */
554 if (network->router_solicit_refresh_count > 0) {
555 DBG("RS refresh already started");
559 network->router_solicit_refresh_count = RS_REFRESH_COUNT;
561 connman_network_ref(network);
563 ret = __connman_inet_ipv6_send_rs(index, RS_REFRESH_TIMEOUT,
564 receive_refresh_rs_reply, network);
568 static void autoconf_ipv6_set(struct connman_network *network)
570 struct connman_service *service;
571 struct connman_ipconfig *ipconfig;
574 DBG("network %p", network);
576 if (network->router_solicit_count > 0) {
578 * The autoconfiguration is already pending and we have sent
579 * router solicitation messages and are now waiting answers.
580 * There is no need to continue any further.
582 DBG("autoconfiguration already started");
586 __connman_device_set_network(network->device, network);
588 connman_device_set_disconnected(network->device, false);
590 #if defined TIZEN_EXT
591 if(network->type == CONNMAN_NETWORK_TYPE_CELLULAR)
595 service = connman_service_lookup_from_network(network);
599 ipconfig = __connman_service_get_ip6config(service);
603 __connman_ipconfig_enable_ipv6(ipconfig);
605 __connman_ipconfig_address_remove(ipconfig);
607 index = __connman_ipconfig_get_index(ipconfig);
609 connman_network_ref(network);
611 /* Try to get stateless DHCPv6 information, RFC 3736 */
612 network->router_solicit_count = 3;
613 __connman_inet_ipv6_send_rs(index, 1, check_dhcpv6, network);
616 static void set_connected(struct connman_network *network)
618 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
619 struct connman_service *service;
621 if (network->connected)
624 connman_network_set_associating(network, false);
626 network->connected = true;
628 service = connman_service_lookup_from_network(network);
630 ipconfig_ipv4 = __connman_service_get_ip4config(service);
631 ipconfig_ipv6 = __connman_service_get_ip6config(service);
633 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
636 __connman_network_enable_ipconfig(network, ipconfig_ipv4);
637 __connman_network_enable_ipconfig(network, ipconfig_ipv6);
640 static void set_disconnected(struct connman_network *network)
642 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
643 enum connman_ipconfig_method ipv4_method, ipv6_method;
644 enum connman_service_state state;
645 struct connman_service *service;
647 service = connman_service_lookup_from_network(network);
649 ipconfig_ipv4 = __connman_service_get_ip4config(service);
650 ipconfig_ipv6 = __connman_service_get_ip6config(service);
652 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
655 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
656 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
658 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
661 * Resetting solicit count here will prevent the RS resend loop
662 * from sending packets in check_dhcpv6()
664 network->router_solicit_count = 0;
666 __connman_device_set_network(network->device, NULL);
668 if (network->connected) {
669 switch (ipv6_method) {
670 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
671 case CONNMAN_IPCONFIG_METHOD_OFF:
672 case CONNMAN_IPCONFIG_METHOD_FIXED:
673 case CONNMAN_IPCONFIG_METHOD_MANUAL:
675 case CONNMAN_IPCONFIG_METHOD_DHCP:
676 case CONNMAN_IPCONFIG_METHOD_AUTO:
677 release_dhcpv6(network);
681 switch (ipv4_method) {
682 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
683 case CONNMAN_IPCONFIG_METHOD_OFF:
684 case CONNMAN_IPCONFIG_METHOD_AUTO:
685 case CONNMAN_IPCONFIG_METHOD_FIXED:
686 case CONNMAN_IPCONFIG_METHOD_MANUAL:
688 case CONNMAN_IPCONFIG_METHOD_DHCP:
689 __connman_dhcp_stop(ipconfig_ipv4);
695 * We only set the disconnect state if we were not in idle
696 * or in failure. It does not make sense to go to disconnect
697 * state if we were not connected.
699 state = __connman_service_ipconfig_get_state(service,
700 CONNMAN_IPCONFIG_TYPE_IPV4);
701 if (state != CONNMAN_SERVICE_STATE_IDLE &&
702 state != CONNMAN_SERVICE_STATE_FAILURE)
703 __connman_service_ipconfig_indicate_state(service,
704 CONNMAN_SERVICE_STATE_DISCONNECT,
705 CONNMAN_IPCONFIG_TYPE_IPV4);
707 state = __connman_service_ipconfig_get_state(service,
708 CONNMAN_IPCONFIG_TYPE_IPV6);
709 if (state != CONNMAN_SERVICE_STATE_IDLE &&
710 state != CONNMAN_SERVICE_STATE_FAILURE)
711 __connman_service_ipconfig_indicate_state(service,
712 CONNMAN_SERVICE_STATE_DISCONNECT,
713 CONNMAN_IPCONFIG_TYPE_IPV6);
715 if (network->connected) {
716 #if defined TIZEN_EXT
718 * Do not remove gateway and its address,
719 * if there are connected profiles that use same interface (multiple PDN)
721 if (connman_service_get_type(service) != CONNMAN_SERVICE_TYPE_CELLULAR ||
722 __connman_service_get_connected_count_of_iface(service) <= 0) {
724 __connman_connection_gateway_remove(service,
725 CONNMAN_IPCONFIG_TYPE_ALL);
727 __connman_ipconfig_address_unset(ipconfig_ipv4);
728 __connman_ipconfig_address_unset(ipconfig_ipv6);
729 #if defined TIZEN_EXT
733 * Special handling for IPv6 autoconfigured address.
734 * The simplest way to remove autoconfigured routes is to
735 * disable IPv6 temporarily so that kernel will do the cleanup
738 if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
739 __connman_ipconfig_disable_ipv6(ipconfig_ipv6);
740 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
744 __connman_service_ipconfig_indicate_state(service,
745 CONNMAN_SERVICE_STATE_IDLE,
746 CONNMAN_IPCONFIG_TYPE_IPV4);
748 __connman_service_ipconfig_indicate_state(service,
749 CONNMAN_SERVICE_STATE_IDLE,
750 CONNMAN_IPCONFIG_TYPE_IPV6);
752 network->connecting = false;
753 network->connected = false;
755 connman_network_set_associating(network, false);
760 static int network_probe(struct connman_network *network)
763 struct connman_network_driver *driver = NULL;
765 DBG("network %p name %s", network, network->name);
770 for (list = driver_list; list; list = list->next) {
773 if (!match_driver(network, driver)) {
778 DBG("driver %p name %s", driver, driver->name);
780 if (driver->probe(network) == 0)
792 switch (network->type) {
793 case CONNMAN_NETWORK_TYPE_UNKNOWN:
794 case CONNMAN_NETWORK_TYPE_VENDOR:
796 case CONNMAN_NETWORK_TYPE_ETHERNET:
797 case CONNMAN_NETWORK_TYPE_GADGET:
798 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
799 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
800 case CONNMAN_NETWORK_TYPE_CELLULAR:
801 case CONNMAN_NETWORK_TYPE_WIFI:
802 network->driver = driver;
803 if (!__connman_service_create_from_network(network)) {
804 network->driver = NULL;
812 static void network_remove(struct connman_network *network)
814 DBG("network %p name %s", network, network->name);
816 if (!network->driver)
819 if (network->connected)
820 set_disconnected(network);
822 switch (network->type) {
823 case CONNMAN_NETWORK_TYPE_UNKNOWN:
824 case CONNMAN_NETWORK_TYPE_VENDOR:
826 case CONNMAN_NETWORK_TYPE_ETHERNET:
827 case CONNMAN_NETWORK_TYPE_GADGET:
828 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
829 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
830 case CONNMAN_NETWORK_TYPE_CELLULAR:
831 case CONNMAN_NETWORK_TYPE_WIFI:
832 if (network->group) {
833 __connman_service_remove_from_network(network);
835 g_free(network->group);
836 network->group = NULL;
841 if (network->driver->remove)
842 network->driver->remove(network);
844 network->driver = NULL;
847 static void network_change(struct connman_network *network)
849 DBG("network %p name %s", network, network->name);
851 if (!network->connected)
854 connman_device_set_disconnected(network->device, true);
856 if (network->driver && network->driver->disconnect) {
857 network->driver->disconnect(network);
861 network->connected = false;
864 static void probe_driver(struct connman_network_driver *driver)
868 DBG("driver %p name %s", driver, driver->name);
870 for (list = network_list; list; list = list->next) {
871 struct connman_network *network = list->data;
876 if (driver->type != network->type)
879 if (driver->probe(network) < 0)
882 network->driver = driver;
886 static void remove_driver(struct connman_network_driver *driver)
890 DBG("driver %p name %s", driver, driver->name);
892 for (list = network_list; list; list = list->next) {
893 struct connman_network *network = list->data;
895 if (network->driver == driver)
896 network_remove(network);
900 static gint compare_priority(gconstpointer a, gconstpointer b)
902 const struct connman_network_driver *driver1 = a;
903 const struct connman_network_driver *driver2 = b;
905 return driver2->priority - driver1->priority;
909 * connman_network_driver_register:
910 * @driver: network driver definition
912 * Register a new network driver
914 * Returns: %0 on success
916 int connman_network_driver_register(struct connman_network_driver *driver)
918 DBG("driver %p name %s", driver, driver->name);
920 driver_list = g_slist_insert_sorted(driver_list, driver,
923 probe_driver(driver);
929 * connman_network_driver_unregister:
930 * @driver: network driver definition
932 * Remove a previously registered network driver
934 void connman_network_driver_unregister(struct connman_network_driver *driver)
936 DBG("driver %p name %s", driver, driver->name);
938 driver_list = g_slist_remove(driver_list, driver);
940 remove_driver(driver);
943 static void network_destruct(struct connman_network *network)
945 DBG("network %p name %s", network, network->name);
947 g_free(network->wifi.ssid);
948 g_free(network->wifi.mode);
949 g_free(network->wifi.security);
950 g_free(network->wifi.passphrase);
951 g_free(network->wifi.eap);
952 g_free(network->wifi.identity);
953 g_free(network->wifi.agent_identity);
954 g_free(network->wifi.ca_cert_path);
955 g_free(network->wifi.client_cert_path);
956 g_free(network->wifi.private_key_path);
957 g_free(network->wifi.private_key_passphrase);
958 g_free(network->wifi.phase2_auth);
959 g_free(network->wifi.pin_wps);
961 g_free(network->path);
962 g_free(network->group);
963 g_free(network->node);
964 g_free(network->name);
965 g_free(network->identifier);
967 network->device = NULL;
973 * connman_network_create:
974 * @identifier: network identifier (for example an unqiue name)
976 * Allocate a new network and assign the #identifier to it.
978 * Returns: a newly-allocated #connman_network structure
980 struct connman_network *connman_network_create(const char *identifier,
981 enum connman_network_type type)
983 struct connman_network *network;
986 DBG("identifier %s type %d", identifier, type);
988 network = g_try_new0(struct connman_network, 1);
992 DBG("network %p", network);
994 network->refcount = 1;
996 ident = g_strdup(identifier);
1003 network->type = type;
1004 network->identifier = ident;
1006 network_list = g_slist_prepend(network_list, network);
1012 * connman_network_ref:
1013 * @network: network structure
1015 * Increase reference counter of network
1017 struct connman_network *
1018 connman_network_ref_debug(struct connman_network *network,
1019 const char *file, int line, const char *caller)
1021 DBG("%p name %s ref %d by %s:%d:%s()", network, network->name,
1022 network->refcount + 1, file, line, caller);
1024 __sync_fetch_and_add(&network->refcount, 1);
1030 * connman_network_unref:
1031 * @network: network structure
1033 * Decrease reference counter of network
1035 void connman_network_unref_debug(struct connman_network *network,
1036 const char *file, int line, const char *caller)
1038 DBG("%p name %s ref %d by %s:%d:%s()", network, network->name,
1039 network->refcount - 1, file, line, caller);
1041 if (__sync_fetch_and_sub(&network->refcount, 1) != 1)
1044 network_list = g_slist_remove(network_list, network);
1046 network_destruct(network);
1049 const char *__connman_network_get_type(struct connman_network *network)
1051 return type2string(network->type);
1055 * connman_network_get_type:
1056 * @network: network structure
1058 * Get type of network
1060 enum connman_network_type connman_network_get_type(
1061 struct connman_network *network)
1063 return network->type;
1067 * connman_network_get_identifier:
1068 * @network: network structure
1070 * Get identifier of network
1072 const char *connman_network_get_identifier(struct connman_network *network)
1074 return network->identifier;
1078 * connman_network_set_index:
1079 * @network: network structure
1080 * @index: index number
1082 * Set index number of network
1084 void connman_network_set_index(struct connman_network *network, int index)
1086 struct connman_service *service;
1087 struct connman_ipconfig *ipconfig;
1089 service = connman_service_lookup_from_network(network);
1093 ipconfig = __connman_service_get_ip4config(service);
1095 __connman_ipconfig_set_index(ipconfig, index);
1097 DBG("index %d service %p ip4config %p", network->index,
1101 ipconfig = __connman_service_get_ip6config(service);
1103 __connman_ipconfig_set_index(ipconfig, index);
1105 DBG("index %d service %p ip6config %p", network->index,
1110 network->index = index;
1114 * connman_network_get_index:
1115 * @network: network structure
1117 * Get index number of network
1119 int connman_network_get_index(struct connman_network *network)
1121 return network->index;
1125 * connman_network_set_group:
1126 * @network: network structure
1127 * @group: group name
1129 * Set group name for automatic clustering
1131 void connman_network_set_group(struct connman_network *network,
1134 switch (network->type) {
1135 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1136 case CONNMAN_NETWORK_TYPE_VENDOR:
1138 case CONNMAN_NETWORK_TYPE_ETHERNET:
1139 case CONNMAN_NETWORK_TYPE_GADGET:
1140 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1141 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1142 case CONNMAN_NETWORK_TYPE_CELLULAR:
1143 case CONNMAN_NETWORK_TYPE_WIFI:
1147 if (g_strcmp0(network->group, group) == 0) {
1149 __connman_service_update_from_network(network);
1153 if (network->group) {
1154 __connman_service_remove_from_network(network);
1156 g_free(network->group);
1159 network->group = g_strdup(group);
1162 network_probe(network);
1166 * connman_network_get_group:
1167 * @network: network structure
1169 * Get group name for automatic clustering
1171 const char *connman_network_get_group(struct connman_network *network)
1173 return network->group;
1176 const char *__connman_network_get_ident(struct connman_network *network)
1178 if (!network->device)
1181 return connman_device_get_ident(network->device);
1184 bool __connman_network_get_weakness(struct connman_network *network)
1186 switch (network->type) {
1187 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1188 case CONNMAN_NETWORK_TYPE_VENDOR:
1189 case CONNMAN_NETWORK_TYPE_ETHERNET:
1190 case CONNMAN_NETWORK_TYPE_GADGET:
1191 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1192 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1193 case CONNMAN_NETWORK_TYPE_CELLULAR:
1195 case CONNMAN_NETWORK_TYPE_WIFI:
1196 if (network->strength > 0 && network->strength < 20)
1204 bool connman_network_get_connecting(struct connman_network *network)
1206 return network->connecting;
1210 * connman_network_set_available:
1211 * @network: network structure
1212 * @available: availability state
1214 * Change availability state of network (in range)
1216 int connman_network_set_available(struct connman_network *network,
1219 #if !defined TIZEN_EXT
1220 DBG("network %p available %d", network, available);
1223 if (network->available == available)
1226 network->available = available;
1232 * connman_network_get_available:
1233 * @network: network structure
1235 * Get network available setting
1237 bool connman_network_get_available(struct connman_network *network)
1239 return network->available;
1242 #if defined TIZEN_EXT
1243 void connman_network_clear_associating(struct connman_network *network)
1245 struct connman_service *service;
1246 enum connman_service_state state;
1248 DBG("network %p", network);
1250 network->connecting = FALSE;
1251 network->associating = FALSE;
1253 service = connman_service_lookup_from_network(network);
1257 state = __connman_service_ipconfig_get_state(service,
1258 CONNMAN_IPCONFIG_TYPE_IPV4);
1259 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1260 state != CONNMAN_SERVICE_STATE_FAILURE)
1261 __connman_service_ipconfig_indicate_state(service,
1262 CONNMAN_SERVICE_STATE_DISCONNECT,
1263 CONNMAN_IPCONFIG_TYPE_IPV4);
1265 state = __connman_service_ipconfig_get_state(service,
1266 CONNMAN_IPCONFIG_TYPE_IPV6);
1267 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1268 state != CONNMAN_SERVICE_STATE_FAILURE)
1269 __connman_service_ipconfig_indicate_state(service,
1270 CONNMAN_SERVICE_STATE_DISCONNECT,
1271 CONNMAN_IPCONFIG_TYPE_IPV6);
1273 __connman_service_ipconfig_indicate_state(service,
1274 CONNMAN_SERVICE_STATE_IDLE,
1275 CONNMAN_IPCONFIG_TYPE_IPV4);
1277 __connman_service_ipconfig_indicate_state(service,
1278 CONNMAN_SERVICE_STATE_IDLE,
1279 CONNMAN_IPCONFIG_TYPE_IPV6);
1282 static gboolean __connman_network_clear_associating_delayed(gpointer user_data)
1285 gboolean found = FALSE;
1286 enum connman_service_state state_ipv4;
1287 enum connman_service_state state_ipv6;
1288 struct connman_service *service;
1289 struct connman_network *network = (struct connman_network *)user_data;
1291 for (list = network_list; list != NULL; list = list->next) {
1292 struct connman_network *item = list->data;
1294 if (item == network) {
1303 DBG("network %p name %s", network, network->name);
1304 service = connman_service_lookup_from_network(network);
1306 state_ipv4 = __connman_service_ipconfig_get_state(service,
1307 CONNMAN_IPCONFIG_TYPE_IPV4);
1308 state_ipv6 = __connman_service_ipconfig_get_state(service,
1309 CONNMAN_IPCONFIG_TYPE_IPV6);
1311 DBG("service %p state %d/%d", service, state_ipv4, state_ipv6);
1313 if (network->associating == FALSE &&
1314 state_ipv4 == CONNMAN_SERVICE_STATE_ASSOCIATION &&
1315 state_ipv6 == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1316 __connman_service_ipconfig_indicate_state(service,
1317 CONNMAN_SERVICE_STATE_IDLE,
1318 CONNMAN_IPCONFIG_TYPE_IPV4);
1320 __connman_service_ipconfig_indicate_state(service,
1321 CONNMAN_SERVICE_STATE_IDLE,
1322 CONNMAN_IPCONFIG_TYPE_IPV6);
1330 * connman_network_set_associating:
1331 * @network: network structure
1332 * @associating: associating state
1334 * Change associating state of network
1336 int connman_network_set_associating(struct connman_network *network,
1339 DBG("network %p associating %d", network, associating);
1341 if (network->associating == associating)
1344 network->associating = associating;
1347 struct connman_service *service;
1349 service = connman_service_lookup_from_network(network);
1350 __connman_service_ipconfig_indicate_state(service,
1351 CONNMAN_SERVICE_STATE_ASSOCIATION,
1352 CONNMAN_IPCONFIG_TYPE_IPV4);
1353 __connman_service_ipconfig_indicate_state(service,
1354 CONNMAN_SERVICE_STATE_ASSOCIATION,
1355 CONNMAN_IPCONFIG_TYPE_IPV6);
1358 #if defined TIZEN_EXT
1359 if (associating == FALSE &&
1360 connman_network_get_bool(network, "WiFi.UseWPS") == FALSE)
1361 g_timeout_add_seconds(1,
1362 __connman_network_clear_associating_delayed,
1369 static void set_associate_error(struct connman_network *network)
1371 struct connman_service *service;
1373 service = connman_service_lookup_from_network(network);
1375 __connman_service_indicate_error(service,
1376 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
1379 static void set_configure_error(struct connman_network *network)
1381 struct connman_service *service;
1383 service = connman_service_lookup_from_network(network);
1385 __connman_service_indicate_error(service,
1386 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
1389 static void set_invalid_key_error(struct connman_network *network)
1391 struct connman_service *service;
1393 service = connman_service_lookup_from_network(network);
1395 __connman_service_indicate_error(service,
1396 CONNMAN_SERVICE_ERROR_INVALID_KEY);
1399 static void set_connect_error(struct connman_network *network)
1401 struct connman_service *service;
1403 service = connman_service_lookup_from_network(network);
1405 __connman_service_indicate_error(service,
1406 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
1409 void connman_network_set_ipv4_method(struct connman_network *network,
1410 enum connman_ipconfig_method method)
1412 struct connman_service *service;
1413 struct connman_ipconfig *ipconfig;
1415 service = connman_service_lookup_from_network(network);
1419 ipconfig = __connman_service_get_ip4config(service);
1423 __connman_ipconfig_set_method(ipconfig, method);
1426 void connman_network_set_ipv6_method(struct connman_network *network,
1427 enum connman_ipconfig_method method)
1429 struct connman_service *service;
1430 struct connman_ipconfig *ipconfig;
1432 service = connman_service_lookup_from_network(network);
1436 ipconfig = __connman_service_get_ip6config(service);
1440 __connman_ipconfig_set_method(ipconfig, method);
1443 void connman_network_set_error(struct connman_network *network,
1444 enum connman_network_error error)
1446 DBG("network %p error %d", network, error);
1448 network->connecting = false;
1449 network->associating = false;
1452 case CONNMAN_NETWORK_ERROR_UNKNOWN:
1454 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
1455 set_associate_error(network);
1457 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
1458 set_configure_error(network);
1460 case CONNMAN_NETWORK_ERROR_INVALID_KEY:
1461 set_invalid_key_error(network);
1463 case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
1464 set_connect_error(network);
1468 network_change(network);
1472 * connman_network_set_connected:
1473 * @network: network structure
1474 * @connected: connected state
1476 * Change connected state of network
1478 int connman_network_set_connected(struct connman_network *network,
1481 DBG("network %p connected %d/%d connecting %d associating %d",
1482 network, network->connected, connected, network->connecting,
1483 network->associating);
1485 if ((network->connecting || network->associating) &&
1487 connman_network_set_error(network,
1488 CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
1489 if (__connman_network_disconnect(network) == 0)
1493 if (network->connected == connected)
1497 set_disconnected(network);
1499 set_connected(network);
1505 * connman_network_get_connected:
1506 * @network: network structure
1508 * Get network connection status
1510 bool connman_network_get_connected(struct connman_network *network)
1512 return network->connected;
1516 * connman_network_get_associating:
1517 * @network: network structure
1519 * Get network associating status
1521 bool connman_network_get_associating(struct connman_network *network)
1523 return network->associating;
1526 void connman_network_clear_hidden(void *user_data)
1531 DBG("user_data %p", user_data);
1534 * Hidden service does not have a connect timeout so
1535 * we do not need to remove it. We can just return
1536 * error to the caller telling that we could not find
1537 * any network that we could connect to.
1539 connman_dbus_reply_pending(user_data, EIO, NULL);
1542 int connman_network_connect_hidden(struct connman_network *network,
1543 char *identity, char *passphrase, void *user_data)
1546 struct connman_service *service;
1548 service = connman_service_lookup_from_network(network);
1550 DBG("network %p service %p user_data %p", network, service, user_data);
1556 __connman_service_set_agent_identity(service, identity);
1559 err = __connman_service_set_passphrase(service, passphrase);
1561 if (err == -ENOKEY) {
1562 __connman_service_indicate_error(service,
1563 CONNMAN_SERVICE_ERROR_INVALID_KEY);
1566 __connman_service_set_hidden(service);
1567 __connman_service_set_hidden_data(service, user_data);
1568 return __connman_service_connect(service,
1569 CONNMAN_SERVICE_CONNECT_REASON_USER);
1573 __connman_service_return_error(service, -err, user_data);
1578 * __connman_network_connect:
1579 * @network: network structure
1583 int __connman_network_connect(struct connman_network *network)
1587 DBG("network %p", network);
1589 if (network->connected)
1592 if (network->connecting || network->associating)
1595 if (!network->driver)
1598 if (!network->driver->connect)
1601 if (!network->device)
1604 network->connecting = true;
1606 #if defined TIZEN_EXT
1607 if (network->type != CONNMAN_NETWORK_TYPE_CELLULAR)
1609 __connman_device_disconnect(network->device);
1611 err = network->driver->connect(network);
1613 if (err == -EINPROGRESS) {
1614 #if defined TIZEN_EXT
1615 if (network->type != CONNMAN_NETWORK_TYPE_CELLULAR)
1617 connman_network_set_associating(network, true);
1619 network->connecting = false;
1624 set_connected(network);
1630 * __connman_network_disconnect:
1631 * @network: network structure
1633 * Disconnect network
1635 int __connman_network_disconnect(struct connman_network *network)
1639 DBG("network %p", network);
1641 if (!network->connected && !network->connecting &&
1642 !network->associating)
1645 if (!network->driver)
1648 network->connecting = false;
1650 if (network->driver->disconnect)
1651 err = network->driver->disconnect(network);
1653 if (err != -EINPROGRESS)
1654 set_disconnected(network);
1659 int __connman_network_clear_ipconfig(struct connman_network *network,
1660 struct connman_ipconfig *ipconfig)
1662 struct connman_service *service;
1663 struct connman_ipconfig *ipconfig_ipv4;
1664 enum connman_ipconfig_method method;
1665 enum connman_ipconfig_type type;
1667 service = connman_service_lookup_from_network(network);
1671 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1672 method = __connman_ipconfig_get_method(ipconfig);
1673 type = __connman_ipconfig_get_config_type(ipconfig);
1676 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1677 case CONNMAN_IPCONFIG_METHOD_OFF:
1678 case CONNMAN_IPCONFIG_METHOD_FIXED:
1680 case CONNMAN_IPCONFIG_METHOD_AUTO:
1681 release_dhcpv6(network);
1683 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1684 __connman_ipconfig_address_remove(ipconfig);
1686 case CONNMAN_IPCONFIG_METHOD_DHCP:
1687 __connman_dhcp_stop(ipconfig_ipv4);
1691 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1692 __connman_service_ipconfig_indicate_state(service,
1693 CONNMAN_SERVICE_STATE_CONFIGURATION,
1694 CONNMAN_IPCONFIG_TYPE_IPV6);
1695 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1696 __connman_service_ipconfig_indicate_state(service,
1697 CONNMAN_SERVICE_STATE_CONFIGURATION,
1698 CONNMAN_IPCONFIG_TYPE_IPV4);
1703 int __connman_network_enable_ipconfig(struct connman_network *network,
1704 struct connman_ipconfig *ipconfig)
1707 enum connman_ipconfig_type type;
1708 enum connman_ipconfig_method method;
1709 #if defined TIZEN_EXT
1710 struct connman_service *service;
1713 if (!network || !ipconfig)
1716 type = __connman_ipconfig_get_config_type(ipconfig);
1719 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1720 case CONNMAN_IPCONFIG_TYPE_ALL:
1723 case CONNMAN_IPCONFIG_TYPE_IPV6:
1724 set_configuration(network, type);
1726 method = __connman_ipconfig_get_method(ipconfig);
1728 DBG("ipv6 ipconfig method %d", method);
1731 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1734 case CONNMAN_IPCONFIG_METHOD_OFF:
1735 __connman_ipconfig_disable_ipv6(ipconfig);
1738 case CONNMAN_IPCONFIG_METHOD_AUTO:
1739 #if defined TIZEN_EXT
1740 service = connman_service_lookup_from_network(network);
1742 if(network->type == CONNMAN_NETWORK_TYPE_CELLULAR)
1743 __connman_service_ipconfig_indicate_state(service,
1744 CONNMAN_SERVICE_STATE_CONFIGURATION,
1745 CONNMAN_IPCONFIG_TYPE_IPV6);
1747 autoconf_ipv6_set(network);
1750 case CONNMAN_IPCONFIG_METHOD_FIXED:
1751 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1752 r = manual_ipv6_set(network, ipconfig);
1755 case CONNMAN_IPCONFIG_METHOD_DHCP:
1762 case CONNMAN_IPCONFIG_TYPE_IPV4:
1763 set_configuration(network, type);
1765 method = __connman_ipconfig_get_method(ipconfig);
1767 DBG("ipv4 ipconfig method %d", method);
1770 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1771 case CONNMAN_IPCONFIG_METHOD_OFF:
1774 case CONNMAN_IPCONFIG_METHOD_AUTO:
1778 case CONNMAN_IPCONFIG_METHOD_FIXED:
1779 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1780 r = set_connected_manual(network);
1783 case CONNMAN_IPCONFIG_METHOD_DHCP:
1784 r = set_connected_dhcp(network);
1792 connman_network_set_error(network,
1793 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1798 int connman_network_set_ipaddress(struct connman_network *network,
1799 struct connman_ipaddress *ipaddress)
1801 struct connman_service *service;
1802 struct connman_ipconfig *ipconfig = NULL;
1804 DBG("network %p", network);
1806 service = connman_service_lookup_from_network(network);
1810 ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
1814 __connman_ipconfig_set_local(ipconfig, ipaddress->local);
1815 __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
1816 __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
1817 __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
1818 __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
1823 #if defined TIZEN_EXT
1825 * Description: Network client requires additional wifi specific info
1827 int connman_network_set_bssid(struct connman_network *network,
1828 const unsigned char *bssid)
1835 DBG("network %p bssid %02x:%02x:%02x:%02x:%02x:%02x", network,
1836 bssid[0], bssid[1], bssid[2],
1837 bssid[3], bssid[4], bssid[5]);
1839 for (;i < WIFI_BSSID_LEN_MAX;i++)
1840 network->wifi.bssid[i] = bssid[i];
1845 unsigned char *connman_network_get_bssid(struct connman_network *network)
1847 return (unsigned char *)network->wifi.bssid;
1850 int connman_network_set_maxrate(struct connman_network *network,
1851 unsigned int maxrate)
1853 #if !defined TIZEN_EXT
1854 DBG("network %p maxrate %d", network, maxrate);
1857 network->wifi.maxrate = maxrate;
1862 unsigned int connman_network_get_maxrate(struct connman_network *network)
1864 return network->wifi.maxrate;
1867 int connman_network_set_enc_mode(struct connman_network *network,
1868 const char *encryption_mode)
1870 if (encryption_mode == NULL)
1873 DBG("network %p encryption mode %s", network, encryption_mode);
1875 g_strlcpy(network->wifi.encryption_mode, encryption_mode,
1876 WIFI_ENCYPTION_MODE_LEN_MAX);
1881 const char *connman_network_get_enc_mode(struct connman_network *network)
1883 return (const char *)network->wifi.encryption_mode;
1886 int connman_network_set_rsn_selected(struct connman_network *network,
1889 network->wifi.rsn_selected = rsn_selected;
1894 int connman_network_set_proxy(struct connman_network *network,
1895 const char *proxies)
1897 struct connman_service *service;
1899 DBG("network %p proxies %s", network, proxies);
1901 service = connman_service_lookup_from_network(network);
1902 if (service == NULL)
1905 __connman_service_set_proxy(service, proxies);
1907 connman_service_set_proxy_method(service,
1908 CONNMAN_SERVICE_PROXY_METHOD_MANUAL);
1913 int connman_network_set_is_hs20AP(struct connman_network *network,
1914 unsigned int isHS20AP)
1919 network->wifi.isHS20AP = isHS20AP;
1924 unsigned int connman_network_get_is_hs20AP(struct connman_network *network)
1929 return network->wifi.isHS20AP;
1933 int connman_network_set_nameservers(struct connman_network *network,
1934 const char *nameservers)
1936 struct connman_service *service;
1937 char **nameservers_array;
1940 DBG("network %p nameservers %s", network, nameservers);
1942 service = connman_service_lookup_from_network(network);
1946 __connman_service_nameserver_clear(service);
1951 nameservers_array = g_strsplit(nameservers, " ", 0);
1953 for (i = 0; nameservers_array[i]; i++) {
1954 __connman_service_nameserver_append(service,
1955 nameservers_array[i], false);
1958 g_strfreev(nameservers_array);
1963 int connman_network_set_domain(struct connman_network *network,
1966 struct connman_service *service;
1968 DBG("network %p domain %s", network, domain);
1970 service = connman_service_lookup_from_network(network);
1974 __connman_service_set_domainname(service, domain);
1980 * connman_network_set_name:
1981 * @network: network structure
1984 * Set display name value for network
1986 int connman_network_set_name(struct connman_network *network,
1989 DBG("network %p name %s", network, name);
1991 g_free(network->name);
1992 network->name = g_strdup(name);
1998 * connman_network_set_strength:
1999 * @network: network structure
2000 * @strength: strength value
2002 * Set signal strength value for network
2005 int connman_network_set_strength(struct connman_network *network,
2008 #if !defined TIZEN_EXT
2009 DBG("network %p strengh %d", network, strength);
2012 network->strength = strength;
2017 uint8_t connman_network_get_strength(struct connman_network *network)
2019 return network->strength;
2022 int connman_network_set_frequency(struct connman_network *network,
2025 #if !defined TIZEN_EXT
2026 DBG("network %p frequency %d", network, frequency);
2029 network->frequency = frequency;
2034 uint16_t connman_network_get_frequency(struct connman_network *network)
2036 return network->frequency;
2039 int connman_network_set_wifi_channel(struct connman_network *network,
2042 DBG("network %p wifi channel %d", network, channel);
2044 network->wifi.channel = channel;
2049 uint16_t connman_network_get_wifi_channel(struct connman_network *network)
2051 return network->wifi.channel;
2055 * connman_network_set_string:
2056 * @network: network structure
2057 * @key: unique identifier
2058 * @value: string value
2060 * Set string value for specific key
2062 int connman_network_set_string(struct connman_network *network,
2063 const char *key, const char *value)
2065 #if !defined TIZEN_EXT
2066 DBG("network %p key %s value %s", network, key, value);
2069 if (g_strcmp0(key, "Name") == 0)
2070 return connman_network_set_name(network, value);
2072 if (g_str_equal(key, "Path")) {
2073 g_free(network->path);
2074 network->path = g_strdup(value);
2075 } else if (g_str_equal(key, "Node")) {
2076 g_free(network->node);
2077 network->node = g_strdup(value);
2078 } else if (g_str_equal(key, "WiFi.Mode")) {
2079 g_free(network->wifi.mode);
2080 network->wifi.mode = g_strdup(value);
2081 } else if (g_str_equal(key, "WiFi.Security")) {
2082 g_free(network->wifi.security);
2083 network->wifi.security = g_strdup(value);
2084 } else if (g_str_equal(key, "WiFi.Passphrase")) {
2085 g_free(network->wifi.passphrase);
2086 network->wifi.passphrase = g_strdup(value);
2087 } else if (g_str_equal(key, "WiFi.EAP")) {
2088 g_free(network->wifi.eap);
2089 network->wifi.eap = g_strdup(value);
2090 } else if (g_str_equal(key, "WiFi.Identity")) {
2091 g_free(network->wifi.identity);
2092 network->wifi.identity = g_strdup(value);
2093 } else if (g_str_equal(key, "WiFi.AgentIdentity")) {
2094 g_free(network->wifi.agent_identity);
2095 network->wifi.agent_identity = g_strdup(value);
2096 } else if (g_str_equal(key, "WiFi.CACertFile")) {
2097 g_free(network->wifi.ca_cert_path);
2098 network->wifi.ca_cert_path = g_strdup(value);
2099 } else if (g_str_equal(key, "WiFi.ClientCertFile")) {
2100 g_free(network->wifi.client_cert_path);
2101 network->wifi.client_cert_path = g_strdup(value);
2102 } else if (g_str_equal(key, "WiFi.PrivateKeyFile")) {
2103 g_free(network->wifi.private_key_path);
2104 network->wifi.private_key_path = g_strdup(value);
2105 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase")) {
2106 g_free(network->wifi.private_key_passphrase);
2107 network->wifi.private_key_passphrase = g_strdup(value);
2108 } else if (g_str_equal(key, "WiFi.Phase2")) {
2109 g_free(network->wifi.phase2_auth);
2110 network->wifi.phase2_auth = g_strdup(value);
2111 } else if (g_str_equal(key, "WiFi.PinWPS")) {
2112 g_free(network->wifi.pin_wps);
2113 network->wifi.pin_wps = g_strdup(value);
2122 * connman_network_get_string:
2123 * @network: network structure
2124 * @key: unique identifier
2126 * Get string value for specific key
2128 const char *connman_network_get_string(struct connman_network *network,
2131 #if !defined TIZEN_EXT
2132 DBG("network %p key %s", network, key);
2135 if (g_str_equal(key, "Path"))
2136 return network->path;
2137 else if (g_str_equal(key, "Name"))
2138 return network->name;
2139 else if (g_str_equal(key, "Node"))
2140 return network->node;
2141 else if (g_str_equal(key, "WiFi.Mode"))
2142 return network->wifi.mode;
2143 else if (g_str_equal(key, "WiFi.Security"))
2144 #if defined TIZEN_EXT
2145 if (network->wifi.rsn_selected != true ||
2146 g_str_equal(network->wifi.security, "ieee8021x"))
2147 return network->wifi.security;
2151 return network->wifi.security;
2153 else if (g_str_equal(key, "WiFi.Passphrase"))
2154 return network->wifi.passphrase;
2155 else if (g_str_equal(key, "WiFi.EAP"))
2156 return network->wifi.eap;
2157 else if (g_str_equal(key, "WiFi.Identity"))
2158 return network->wifi.identity;
2159 else if (g_str_equal(key, "WiFi.AgentIdentity"))
2160 return network->wifi.agent_identity;
2161 else if (g_str_equal(key, "WiFi.CACertFile"))
2162 return network->wifi.ca_cert_path;
2163 else if (g_str_equal(key, "WiFi.ClientCertFile"))
2164 return network->wifi.client_cert_path;
2165 else if (g_str_equal(key, "WiFi.PrivateKeyFile"))
2166 return network->wifi.private_key_path;
2167 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase"))
2168 return network->wifi.private_key_passphrase;
2169 else if (g_str_equal(key, "WiFi.Phase2"))
2170 return network->wifi.phase2_auth;
2171 else if (g_str_equal(key, "WiFi.PinWPS"))
2172 return network->wifi.pin_wps;
2178 * connman_network_set_bool:
2179 * @network: network structure
2180 * @key: unique identifier
2181 * @value: boolean value
2183 * Set boolean value for specific key
2185 int connman_network_set_bool(struct connman_network *network,
2186 const char *key, bool value)
2188 #if !defined TIZEN_EXT
2189 DBG("network %p key %s value %d", network, key, value);
2192 if (g_strcmp0(key, "Roaming") == 0)
2193 network->roaming = value;
2194 else if (g_strcmp0(key, "WiFi.WPS") == 0)
2195 network->wifi.wps = value;
2196 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
2197 network->wifi.use_wps = value;
2198 #if defined TIZEN_EXT
2199 else if (g_strcmp0(key, "DefaultInternet") == 0)
2200 network->default_internet = value;
2207 * connman_network_get_bool:
2208 * @network: network structure
2209 * @key: unique identifier
2211 * Get boolean value for specific key
2213 bool connman_network_get_bool(struct connman_network *network,
2216 #if !defined TIZEN_EXT
2217 DBG("network %p key %s", network, key);
2220 if (g_str_equal(key, "Roaming"))
2221 return network->roaming;
2222 else if (g_str_equal(key, "WiFi.WPS"))
2223 return network->wifi.wps;
2224 else if (g_str_equal(key, "WiFi.UseWPS"))
2225 return network->wifi.use_wps;
2226 #if defined TIZEN_EXT
2227 else if (g_str_equal(key, "DefaultInternet"))
2228 return network->default_internet;
2235 * connman_network_set_blob:
2236 * @network: network structure
2237 * @key: unique identifier
2241 * Set binary blob value for specific key
2243 int connman_network_set_blob(struct connman_network *network,
2244 const char *key, const void *data, unsigned int size)
2246 #if !defined TIZEN_EXT
2247 DBG("network %p key %s size %d", network, key, size);
2250 if (g_str_equal(key, "WiFi.SSID")) {
2251 g_free(network->wifi.ssid);
2252 network->wifi.ssid = g_try_malloc(size);
2253 if (network->wifi.ssid) {
2254 memcpy(network->wifi.ssid, data, size);
2255 network->wifi.ssid_len = size;
2257 network->wifi.ssid_len = 0;
2266 * connman_network_get_blob:
2267 * @network: network structure
2268 * @key: unique identifier
2269 * @size: pointer to blob size
2271 * Get binary blob value for specific key
2273 const void *connman_network_get_blob(struct connman_network *network,
2274 const char *key, unsigned int *size)
2276 DBG("network %p key %s", network, key);
2278 if (g_str_equal(key, "WiFi.SSID")) {
2280 *size = network->wifi.ssid_len;
2281 return network->wifi.ssid;
2287 void __connman_network_set_device(struct connman_network *network,
2288 struct connman_device *device)
2290 if (network->device == device)
2293 if (network->device)
2294 network_remove(network);
2296 network->device = device;
2298 if (network->device)
2299 network_probe(network);
2303 * connman_network_get_device:
2304 * @network: network structure
2306 * Get parent device of network
2308 struct connman_device *connman_network_get_device(struct connman_network *network)
2310 return network->device;
2314 * connman_network_get_data:
2315 * @network: network structure
2317 * Get private network data pointer
2319 void *connman_network_get_data(struct connman_network *network)
2321 return network->driver_data;
2325 * connman_network_set_data:
2326 * @network: network structure
2327 * @data: data pointer
2329 * Set private network data pointer
2331 void connman_network_set_data(struct connman_network *network, void *data)
2333 network->driver_data = data;
2336 void connman_network_update(struct connman_network *network)
2338 switch (network->type) {
2339 case CONNMAN_NETWORK_TYPE_UNKNOWN:
2340 case CONNMAN_NETWORK_TYPE_VENDOR:
2342 case CONNMAN_NETWORK_TYPE_ETHERNET:
2343 case CONNMAN_NETWORK_TYPE_GADGET:
2344 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
2345 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
2346 case CONNMAN_NETWORK_TYPE_CELLULAR:
2347 case CONNMAN_NETWORK_TYPE_WIFI:
2352 __connman_service_update_from_network(network);
2355 int __connman_network_init(void)
2362 void __connman_network_cleanup(void)