5 * Copyright (C) 2007-2012 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
44 static GSList *network_list = NULL;
45 static GSList *driver_list = NULL;
47 struct connman_network {
49 enum connman_network_type type;
50 connman_bool_t available;
51 connman_bool_t connected;
52 connman_bool_t roaming;
53 connman_uint8_t strength;
54 connman_uint16_t frequency;
61 int router_solicit_count;
62 int router_solicit_refresh_count;
64 struct connman_network_driver *driver;
67 connman_bool_t connecting;
68 connman_bool_t associating;
70 struct connman_device *device;
76 unsigned short channel;
79 char *agent_passphrase;
84 char *client_cert_path;
85 char *private_key_path;
86 char *private_key_passphrase;
89 connman_bool_t use_wps;
99 static const char *type2string(enum connman_network_type type)
102 case CONNMAN_NETWORK_TYPE_UNKNOWN:
103 case CONNMAN_NETWORK_TYPE_VENDOR:
105 case CONNMAN_NETWORK_TYPE_ETHERNET:
107 case CONNMAN_NETWORK_TYPE_WIFI:
109 case CONNMAN_NETWORK_TYPE_WIMAX:
111 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
112 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
114 case CONNMAN_NETWORK_TYPE_CELLULAR:
121 static gboolean match_driver(struct connman_network *network,
122 struct connman_network_driver *driver)
124 if (network->type == driver->type ||
125 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
131 static int network_probe(struct connman_network *network)
134 struct connman_network_driver *driver = NULL;
136 DBG("network %p name %s", network, network->name);
138 if (network->driver != NULL)
141 for (list = driver_list; list; list = list->next) {
144 if (match_driver(network, driver) == FALSE)
147 DBG("driver %p name %s", driver, driver->name);
149 if (driver->probe(network) == 0)
158 if (network->group == NULL)
161 switch (network->type) {
162 case CONNMAN_NETWORK_TYPE_UNKNOWN:
163 case CONNMAN_NETWORK_TYPE_VENDOR:
165 case CONNMAN_NETWORK_TYPE_ETHERNET:
166 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
167 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
168 case CONNMAN_NETWORK_TYPE_CELLULAR:
169 case CONNMAN_NETWORK_TYPE_WIFI:
170 case CONNMAN_NETWORK_TYPE_WIMAX:
171 network->driver = driver;
172 if (__connman_service_create_from_network(network) == NULL) {
173 network->driver = NULL;
181 static void network_remove(struct connman_network *network)
183 DBG("network %p name %s", network, network->name);
185 if (network->driver == NULL)
188 connman_network_set_connected(network, FALSE);
190 switch (network->type) {
191 case CONNMAN_NETWORK_TYPE_UNKNOWN:
192 case CONNMAN_NETWORK_TYPE_VENDOR:
194 case CONNMAN_NETWORK_TYPE_ETHERNET:
195 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
196 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
197 case CONNMAN_NETWORK_TYPE_CELLULAR:
198 case CONNMAN_NETWORK_TYPE_WIFI:
199 case CONNMAN_NETWORK_TYPE_WIMAX:
200 if (network->group != NULL) {
201 __connman_service_remove_from_network(network);
203 g_free(network->group);
204 network->group = NULL;
209 if (network->driver->remove)
210 network->driver->remove(network);
212 network->driver = NULL;
215 static void network_change(struct connman_network *network)
217 DBG("network %p name %s", network, network->name);
219 if (network->connected == FALSE)
222 connman_device_set_disconnected(network->device, TRUE);
224 if (network->driver && network->driver->disconnect) {
225 network->driver->disconnect(network);
229 network->connected = FALSE;
232 static void probe_driver(struct connman_network_driver *driver)
236 DBG("driver %p name %s", driver, driver->name);
238 for (list = network_list; list != NULL; list = list->next) {
239 struct connman_network *network = list->data;
241 if (network->driver != NULL)
244 if (driver->type != network->type)
247 if (driver->probe(network) < 0)
250 network->driver = driver;
254 static void remove_driver(struct connman_network_driver *driver)
258 DBG("driver %p name %s", driver, driver->name);
260 for (list = network_list; list != NULL; list = list->next) {
261 struct connman_network *network = list->data;
263 if (network->driver == driver)
264 network_remove(network);
268 static gint compare_priority(gconstpointer a, gconstpointer b)
270 const struct connman_network_driver *driver1 = a;
271 const struct connman_network_driver *driver2 = b;
273 return driver2->priority - driver1->priority;
277 * connman_network_driver_register:
278 * @driver: network driver definition
280 * Register a new network driver
282 * Returns: %0 on success
284 int connman_network_driver_register(struct connman_network_driver *driver)
288 DBG("driver %p name %s", driver, driver->name);
290 for (list = driver_list; list; list = list->next) {
291 struct connman_network_driver *tmp = list->data;
293 if (tmp->type == driver->type)
298 driver_list = g_slist_insert_sorted(driver_list, driver,
301 probe_driver(driver);
307 * connman_network_driver_unregister:
308 * @driver: network driver definition
310 * Remove a previously registered network driver
312 void connman_network_driver_unregister(struct connman_network_driver *driver)
314 DBG("driver %p name %s", driver, driver->name);
316 driver_list = g_slist_remove(driver_list, driver);
318 remove_driver(driver);
321 static void network_destruct(struct connman_network *network)
323 DBG("network %p name %s", network, network->name);
325 g_free(network->wifi.ssid);
326 g_free(network->wifi.mode);
327 g_free(network->wifi.security);
328 g_free(network->wifi.passphrase);
329 g_free(network->wifi.agent_passphrase);
330 g_free(network->wifi.eap);
331 g_free(network->wifi.identity);
332 g_free(network->wifi.agent_identity);
333 g_free(network->wifi.ca_cert_path);
334 g_free(network->wifi.client_cert_path);
335 g_free(network->wifi.private_key_path);
336 g_free(network->wifi.private_key_passphrase);
337 g_free(network->wifi.phase2_auth);
338 g_free(network->wifi.pin_wps);
340 g_free(network->path);
341 g_free(network->group);
342 g_free(network->node);
343 g_free(network->name);
344 g_free(network->identifier);
346 network->device = NULL;
352 * connman_network_create:
353 * @identifier: network identifier (for example an unqiue name)
355 * Allocate a new network and assign the #identifier to it.
357 * Returns: a newly-allocated #connman_network structure
359 struct connman_network *connman_network_create(const char *identifier,
360 enum connman_network_type type)
362 struct connman_network *network;
365 DBG("identifier %s type %d", identifier, type);
367 network = g_try_new0(struct connman_network, 1);
371 DBG("network %p", network);
373 network->refcount = 1;
375 ident = g_strdup(identifier);
382 network->type = type;
383 network->identifier = ident;
385 network_list = g_slist_prepend(network_list, network);
391 * connman_network_ref:
392 * @network: network structure
394 * Increase reference counter of network
396 struct connman_network *
397 connman_network_ref_debug(struct connman_network *network,
398 const char *file, int line, const char *caller)
400 DBG("%p name %s ref %d by %s:%d:%s()", network, network->name,
401 network->refcount + 1, file, line, caller);
403 __sync_fetch_and_add(&network->refcount, 1);
409 * connman_network_unref:
410 * @network: network structure
412 * Decrease reference counter of network
414 void connman_network_unref_debug(struct connman_network *network,
415 const char *file, int line, const char *caller)
417 DBG("%p name %s ref %d by %s:%d:%s()", network, network->name,
418 network->refcount - 1, file, line, caller);
420 if (__sync_fetch_and_sub(&network->refcount, 1) != 1)
423 network_list = g_slist_remove(network_list, network);
425 network_destruct(network);
428 const char *__connman_network_get_type(struct connman_network *network)
430 return type2string(network->type);
434 * connman_network_get_type:
435 * @network: network structure
437 * Get type of network
439 enum connman_network_type connman_network_get_type(struct connman_network *network)
441 return network->type;
445 * connman_network_get_identifier:
446 * @network: network structure
448 * Get identifier of network
450 const char *connman_network_get_identifier(struct connman_network *network)
452 return network->identifier;
456 * connman_network_set_index:
457 * @network: network structure
458 * @index: index number
460 * Set index number of network
462 void connman_network_set_index(struct connman_network *network, int index)
464 struct connman_service *service;
465 struct connman_ipconfig *ipconfig;
467 service = connman_service_lookup_from_network(network);
471 ipconfig = __connman_service_get_ip4config(service);
472 if (ipconfig == NULL)
475 /* If index changed, the index of ipconfig must be reset. */
476 __connman_ipconfig_set_index(ipconfig, index);
478 DBG("index %d service %p ip4config %p", network->index,
481 network->index = index;
485 * connman_network_get_index:
486 * @network: network structure
488 * Get index number of network
490 int connman_network_get_index(struct connman_network *network)
492 return network->index;
496 * connman_network_set_group:
497 * @network: network structure
500 * Set group name for automatic clustering
502 void connman_network_set_group(struct connman_network *network,
505 switch (network->type) {
506 case CONNMAN_NETWORK_TYPE_UNKNOWN:
507 case CONNMAN_NETWORK_TYPE_VENDOR:
509 case CONNMAN_NETWORK_TYPE_ETHERNET:
510 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
511 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
512 case CONNMAN_NETWORK_TYPE_CELLULAR:
513 case CONNMAN_NETWORK_TYPE_WIFI:
514 case CONNMAN_NETWORK_TYPE_WIMAX:
518 if (g_strcmp0(network->group, group) == 0) {
520 __connman_service_update_from_network(network);
524 if (network->group != NULL) {
525 __connman_service_remove_from_network(network);
527 g_free(network->group);
530 network->group = g_strdup(group);
532 if (network->group != NULL)
533 network_probe(network);
537 * connman_network_get_group:
538 * @network: network structure
540 * Get group name for automatic clustering
542 const char *connman_network_get_group(struct connman_network *network)
544 return network->group;
547 const char *__connman_network_get_ident(struct connman_network *network)
549 if (network->device == NULL)
552 return connman_device_get_ident(network->device);
555 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
557 switch (network->type) {
558 case CONNMAN_NETWORK_TYPE_UNKNOWN:
559 case CONNMAN_NETWORK_TYPE_VENDOR:
560 case CONNMAN_NETWORK_TYPE_ETHERNET:
561 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
562 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
563 case CONNMAN_NETWORK_TYPE_CELLULAR:
564 case CONNMAN_NETWORK_TYPE_WIMAX:
566 case CONNMAN_NETWORK_TYPE_WIFI:
567 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
569 if (network->strength > 0 && network->strength < 20)
577 connman_bool_t connman_network_get_connecting(struct connman_network *network)
579 return network->connecting;
583 * connman_network_set_available:
584 * @network: network structure
585 * @available: availability state
587 * Change availability state of network (in range)
589 int connman_network_set_available(struct connman_network *network,
590 connman_bool_t available)
592 DBG("network %p available %d", network, available);
594 if (network->available == available)
597 network->available = available;
603 * connman_network_get_available:
604 * @network: network structure
606 * Get network available setting
608 connman_bool_t connman_network_get_available(struct connman_network *network)
610 return network->available;
614 * connman_network_set_associating:
615 * @network: network structure
616 * @associating: associating state
618 * Change associating state of network
620 int connman_network_set_associating(struct connman_network *network,
621 connman_bool_t associating)
623 DBG("network %p associating %d", network, associating);
625 if (network->associating == associating)
628 network->associating = associating;
630 if (associating == TRUE) {
631 struct connman_service *service;
633 service = connman_service_lookup_from_network(network);
634 __connman_service_ipconfig_indicate_state(service,
635 CONNMAN_SERVICE_STATE_ASSOCIATION,
636 CONNMAN_IPCONFIG_TYPE_IPV4);
637 __connman_service_ipconfig_indicate_state(service,
638 CONNMAN_SERVICE_STATE_ASSOCIATION,
639 CONNMAN_IPCONFIG_TYPE_IPV6);
645 static void set_associate_error(struct connman_network *network)
647 struct connman_service *service;
649 service = connman_service_lookup_from_network(network);
651 __connman_service_indicate_error(service,
652 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
655 static void set_configure_error(struct connman_network *network)
657 struct connman_service *service;
659 service = connman_service_lookup_from_network(network);
661 __connman_service_indicate_error(service,
662 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
665 static void set_invalid_key_error(struct connman_network *network)
667 struct connman_service *service;
669 service = connman_service_lookup_from_network(network);
671 __connman_service_indicate_error(service,
672 CONNMAN_SERVICE_ERROR_INVALID_KEY);
675 static void set_connect_error(struct connman_network *network)
677 struct connman_service *service;
679 service = connman_service_lookup_from_network(network);
681 __connman_service_indicate_error(service,
682 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
685 void connman_network_set_ipv4_method(struct connman_network *network,
686 enum connman_ipconfig_method method)
688 struct connman_service *service;
689 struct connman_ipconfig *ipconfig;
691 service = connman_service_lookup_from_network(network);
695 ipconfig = __connman_service_get_ip4config(service);
696 if (ipconfig == NULL)
699 __connman_ipconfig_set_method(ipconfig, method);
702 void connman_network_set_ipv6_method(struct connman_network *network,
703 enum connman_ipconfig_method method)
705 struct connman_service *service;
706 struct connman_ipconfig *ipconfig;
708 service = connman_service_lookup_from_network(network);
712 ipconfig = __connman_service_get_ip6config(service);
713 if (ipconfig == NULL)
716 __connman_ipconfig_set_method(ipconfig, method);
719 void connman_network_set_error(struct connman_network *network,
720 enum connman_network_error error)
722 DBG("network %p error %d", network, error);
724 network->connecting = FALSE;
725 network->associating = FALSE;
728 case CONNMAN_NETWORK_ERROR_UNKNOWN:
730 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
731 set_associate_error(network);
733 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
734 set_configure_error(network);
736 case CONNMAN_NETWORK_ERROR_INVALID_KEY:
737 set_invalid_key_error(network);
739 case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
740 set_connect_error(network);
744 network_change(network);
747 void connman_network_clear_error(struct connman_network *network)
749 struct connman_service *service;
751 DBG("network %p", network);
756 if (network->connecting == TRUE || network->associating == TRUE)
759 service = connman_service_lookup_from_network(network);
760 __connman_service_clear_error(service);
763 static void set_configuration(struct connman_network *network,
764 enum connman_ipconfig_type type)
766 struct connman_service *service;
768 DBG("network %p", network);
770 if (network->device == NULL)
773 __connman_device_set_network(network->device, network);
775 connman_device_set_disconnected(network->device, FALSE);
777 service = connman_service_lookup_from_network(network);
778 __connman_service_ipconfig_indicate_state(service,
779 CONNMAN_SERVICE_STATE_CONFIGURATION,
783 static void dhcp_success(struct connman_network *network)
785 struct connman_service *service;
786 struct connman_ipconfig *ipconfig_ipv4;
789 service = connman_service_lookup_from_network(network);
793 connman_network_set_associating(network, FALSE);
795 network->connecting = FALSE;
797 ipconfig_ipv4 = __connman_service_get_ip4config(service);
798 err = __connman_ipconfig_address_add(ipconfig_ipv4);
802 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
809 connman_network_set_error(network,
810 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
813 static void dhcp_failure(struct connman_network *network)
815 struct connman_service *service;
817 service = connman_service_lookup_from_network(network);
821 __connman_service_ipconfig_indicate_state(service,
822 CONNMAN_SERVICE_STATE_IDLE,
823 CONNMAN_IPCONFIG_TYPE_IPV4);
826 static void dhcp_callback(struct connman_network *network,
827 connman_bool_t success)
829 DBG("success %d", success);
832 dhcp_success(network);
834 dhcp_failure(network);
837 static int set_connected_fixed(struct connman_network *network)
839 struct connman_service *service;
840 struct connman_ipconfig *ipconfig_ipv4;
845 service = connman_service_lookup_from_network(network);
847 ipconfig_ipv4 = __connman_service_get_ip4config(service);
849 set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
851 network->connecting = FALSE;
853 connman_network_set_associating(network, FALSE);
855 err = __connman_ipconfig_address_add(ipconfig_ipv4);
859 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
866 connman_network_set_error(network,
867 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
872 static void set_connected_manual(struct connman_network *network)
874 struct connman_service *service;
875 struct connman_ipconfig *ipconfig;
878 DBG("network %p", network);
880 service = connman_service_lookup_from_network(network);
882 ipconfig = __connman_service_get_ip4config(service);
884 if (__connman_ipconfig_get_local(ipconfig) == NULL)
885 __connman_service_read_ip4config(service);
887 set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
889 err = __connman_ipconfig_address_add(ipconfig);
893 err = __connman_ipconfig_gateway_add(ipconfig);
897 network->connecting = FALSE;
899 connman_network_set_associating(network, FALSE);
904 connman_network_set_error(network,
905 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
909 static int set_connected_dhcp(struct connman_network *network)
913 DBG("network %p", network);
915 set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
917 err = __connman_dhcp_start(network, dhcp_callback);
919 connman_error("Can not request DHCP lease");
926 static int manual_ipv6_set(struct connman_network *network,
927 struct connman_ipconfig *ipconfig_ipv6)
929 struct connman_service *service;
932 DBG("network %p ipv6 %p", network, ipconfig_ipv6);
934 service = connman_service_lookup_from_network(network);
938 if (__connman_ipconfig_get_local(ipconfig_ipv6) == NULL)
939 __connman_service_read_ip6config(service);
941 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
943 err = __connman_ipconfig_address_add(ipconfig_ipv6);
945 connman_network_set_error(network,
946 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
950 err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
954 __connman_connection_gateway_activate(service,
955 CONNMAN_IPCONFIG_TYPE_IPV6);
957 __connman_device_set_network(network->device, network);
959 connman_device_set_disconnected(network->device, FALSE);
961 network->connecting = FALSE;
966 static void stop_dhcpv6(struct connman_network *network)
968 __connman_dhcpv6_stop(network);
971 static void dhcpv6_release_callback(struct connman_network *network,
972 connman_bool_t success)
974 DBG("success %d", success);
976 stop_dhcpv6(network);
979 static void release_dhcpv6(struct connman_network *network)
981 __connman_dhcpv6_start_release(network, dhcpv6_release_callback);
982 stop_dhcpv6(network);
985 static void dhcpv6_info_callback(struct connman_network *network,
986 connman_bool_t success)
988 DBG("success %d", success);
990 stop_dhcpv6(network);
993 static gboolean dhcpv6_set_addresses(struct connman_network *network)
995 struct connman_service *service;
996 struct connman_ipconfig *ipconfig_ipv6;
999 service = connman_service_lookup_from_network(network);
1000 if (service == NULL)
1003 connman_network_set_associating(network, FALSE);
1005 network->connecting = FALSE;
1007 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1008 err = __connman_ipconfig_address_add(ipconfig_ipv6);
1012 err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
1019 connman_network_set_error(network,
1020 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1024 static void autoconf_ipv6_set(struct connman_network *network);
1025 static void dhcpv6_callback(struct connman_network *network,
1026 connman_bool_t success);
1029 * Have a separate callback for renew so that we do not do autoconf
1030 * in wrong phase as the dhcpv6_callback() is also called when doing
1031 * DHCPv6 solicitation.
1033 static void dhcpv6_renew_callback(struct connman_network *network,
1034 connman_bool_t success)
1036 if (success == TRUE)
1037 dhcpv6_callback(network, success);
1039 stop_dhcpv6(network);
1041 /* restart and do solicit again. */
1042 autoconf_ipv6_set(network);
1046 static void dhcpv6_callback(struct connman_network *network,
1047 connman_bool_t success)
1049 DBG("success %d", success);
1051 /* Start the renew process if necessary */
1052 if (success == TRUE) {
1054 if (dhcpv6_set_addresses(network) < 0) {
1055 stop_dhcpv6(network);
1059 if (__connman_dhcpv6_start_renew(network,
1060 dhcpv6_renew_callback) == -ETIMEDOUT)
1061 dhcpv6_renew_callback(network, FALSE);
1063 stop_dhcpv6(network);
1066 static void check_dhcpv6(struct nd_router_advert *reply,
1067 unsigned int length, void *user_data)
1069 struct connman_network *network = user_data;
1072 DBG("reply %p", reply);
1074 if (reply == NULL) {
1076 * Router solicitation message seem to get lost easily so
1077 * try to send it again.
1079 if (network->router_solicit_count > 0) {
1080 DBG("re-send router solicitation %d",
1081 network->router_solicit_count);
1082 network->router_solicit_count--;
1083 __connman_inet_ipv6_send_rs(network->index, 1,
1084 check_dhcpv6, network);
1087 connman_network_unref(network);
1091 network->router_solicit_count = 0;
1094 * If we were disconnected while waiting router advertisement,
1095 * we just quit and do not start DHCPv6
1097 if (network->connected == FALSE) {
1098 connman_network_unref(network);
1102 prefixes = __connman_inet_ipv6_get_prefixes(reply, length);
1105 * We do stateful/stateless DHCPv6 if router advertisement says so.
1107 if (reply->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED)
1108 __connman_dhcpv6_start(network, prefixes, dhcpv6_callback);
1109 else if (reply->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
1110 __connman_dhcpv6_start_info(network, dhcpv6_info_callback);
1112 connman_network_unref(network);
1115 static void receive_refresh_rs_reply(struct nd_router_advert *reply,
1116 unsigned int length, void *user_data)
1118 struct connman_network *network = user_data;
1120 DBG("reply %p", reply);
1122 if (reply == NULL) {
1124 * Router solicitation message seem to get lost easily so
1125 * try to send it again.
1127 if (network->router_solicit_refresh_count > 1) {
1128 network->router_solicit_refresh_count--;
1129 DBG("re-send router solicitation %d",
1130 network->router_solicit_refresh_count);
1131 __connman_inet_ipv6_send_rs(network->index,
1133 receive_refresh_rs_reply,
1139 /* RS refresh not in progress anymore */
1140 network->router_solicit_refresh_count = 0;
1142 connman_network_unref(network);
1146 int __connman_refresh_rs_ipv6(struct connman_network *network, int index)
1150 DBG("network %p index %d", network, index);
1152 /* Send only one RS for all RDNSS entries which are about to expire */
1153 if (network->router_solicit_refresh_count > 0) {
1154 DBG("RS refresh already started");
1158 network->router_solicit_refresh_count = RS_REFRESH_COUNT;
1160 connman_network_ref(network);
1162 ret = __connman_inet_ipv6_send_rs(index, RS_REFRESH_TIMEOUT,
1163 receive_refresh_rs_reply, network);
1167 static void autoconf_ipv6_set(struct connman_network *network)
1169 struct connman_service *service;
1170 struct connman_ipconfig *ipconfig;
1173 DBG("network %p", network);
1175 if (network->router_solicit_count > 0) {
1177 * The autoconfiguration is already pending and we have sent
1178 * router solicitation messages and are now waiting answers.
1179 * There is no need to continue any further.
1181 DBG("autoconfiguration already started");
1185 __connman_device_set_network(network->device, network);
1187 connman_device_set_disconnected(network->device, FALSE);
1189 network->connecting = FALSE;
1191 service = connman_service_lookup_from_network(network);
1192 if (service == NULL)
1195 ipconfig = __connman_service_get_ip6config(service);
1196 if (ipconfig == NULL)
1199 index = __connman_ipconfig_get_index(ipconfig);
1201 connman_network_ref(network);
1203 /* Try to get stateless DHCPv6 information, RFC 3736 */
1204 network->router_solicit_count = 3;
1205 __connman_inet_ipv6_send_rs(index, 1, check_dhcpv6, network);
1208 static void set_connected(struct connman_network *network)
1210 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
1211 enum connman_ipconfig_method ipv4_method, ipv6_method;
1212 struct connman_service *service;
1215 if (network->connected == TRUE)
1218 network->connected = TRUE;
1220 service = connman_service_lookup_from_network(network);
1222 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1223 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1225 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
1228 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
1229 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
1231 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
1233 switch (ipv6_method) {
1234 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1235 case CONNMAN_IPCONFIG_METHOD_OFF:
1237 case CONNMAN_IPCONFIG_METHOD_DHCP:
1238 case CONNMAN_IPCONFIG_METHOD_AUTO:
1239 autoconf_ipv6_set(network);
1241 case CONNMAN_IPCONFIG_METHOD_FIXED:
1242 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1243 ret = manual_ipv6_set(network, ipconfig_ipv6);
1245 connman_network_set_error(network,
1246 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1252 switch (ipv4_method) {
1253 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1254 case CONNMAN_IPCONFIG_METHOD_OFF:
1255 case CONNMAN_IPCONFIG_METHOD_AUTO:
1257 case CONNMAN_IPCONFIG_METHOD_FIXED:
1258 if (set_connected_fixed(network) < 0) {
1259 connman_network_set_error(network,
1260 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1264 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1265 set_connected_manual(network);
1267 case CONNMAN_IPCONFIG_METHOD_DHCP:
1268 if (set_connected_dhcp(network) < 0) {
1269 connman_network_set_error(network,
1270 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1275 network->connecting = FALSE;
1277 connman_network_set_associating(network, FALSE);
1280 static void set_disconnected(struct connman_network *network)
1282 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
1283 enum connman_ipconfig_method ipv4_method, ipv6_method;
1284 enum connman_service_state state;
1285 struct connman_service *service;
1287 if (network->connected == FALSE)
1290 network->connected = FALSE;
1292 service = connman_service_lookup_from_network(network);
1294 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1295 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1297 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
1300 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
1301 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
1303 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
1306 * Resetting solicit count here will prevent the RS resend loop
1307 * from sending packets in check_dhcpv6()
1309 network->router_solicit_count = 0;
1311 __connman_device_set_network(network->device, NULL);
1313 switch (ipv6_method) {
1314 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1315 case CONNMAN_IPCONFIG_METHOD_OFF:
1316 case CONNMAN_IPCONFIG_METHOD_FIXED:
1317 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1319 case CONNMAN_IPCONFIG_METHOD_DHCP:
1320 case CONNMAN_IPCONFIG_METHOD_AUTO:
1321 release_dhcpv6(network);
1325 switch (ipv4_method) {
1326 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1327 case CONNMAN_IPCONFIG_METHOD_OFF:
1328 case CONNMAN_IPCONFIG_METHOD_AUTO:
1329 case CONNMAN_IPCONFIG_METHOD_FIXED:
1330 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1332 case CONNMAN_IPCONFIG_METHOD_DHCP:
1333 __connman_dhcp_stop(network);
1338 * We only set the disconnect state if we were not in idle
1339 * or in failure. It does not make sense to go to disconnect
1340 * state if we were not connected.
1342 state = __connman_service_ipconfig_get_state(service,
1343 CONNMAN_IPCONFIG_TYPE_IPV4);
1344 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1345 state != CONNMAN_SERVICE_STATE_FAILURE)
1346 __connman_service_ipconfig_indicate_state(service,
1347 CONNMAN_SERVICE_STATE_DISCONNECT,
1348 CONNMAN_IPCONFIG_TYPE_IPV4);
1350 state = __connman_service_ipconfig_get_state(service,
1351 CONNMAN_IPCONFIG_TYPE_IPV6);
1352 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1353 state != CONNMAN_SERVICE_STATE_FAILURE)
1354 __connman_service_ipconfig_indicate_state(service,
1355 CONNMAN_SERVICE_STATE_DISCONNECT,
1356 CONNMAN_IPCONFIG_TYPE_IPV6);
1358 __connman_connection_gateway_remove(service,
1359 CONNMAN_IPCONFIG_TYPE_ALL);
1361 __connman_ipconfig_address_unset(ipconfig_ipv4);
1362 __connman_ipconfig_address_unset(ipconfig_ipv6);
1365 * Special handling for IPv6 autoconfigured address.
1366 * The simplest way to remove autoconfigured routes is to
1367 * disable IPv6 temporarily so that kernel will do the cleanup
1370 if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
1371 __connman_ipconfig_disable_ipv6(ipconfig_ipv6);
1372 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
1375 __connman_service_ipconfig_indicate_state(service,
1376 CONNMAN_SERVICE_STATE_IDLE,
1377 CONNMAN_IPCONFIG_TYPE_IPV4);
1379 __connman_service_ipconfig_indicate_state(service,
1380 CONNMAN_SERVICE_STATE_IDLE,
1381 CONNMAN_IPCONFIG_TYPE_IPV6);
1383 network->connecting = FALSE;
1385 connman_network_set_associating(network, FALSE);
1389 * connman_network_set_connected:
1390 * @network: network structure
1391 * @connected: connected state
1393 * Change connected state of network
1395 int connman_network_set_connected(struct connman_network *network,
1396 connman_bool_t connected)
1398 DBG("network %p connected %d/%d connecting %d associating %d",
1399 network, network->connected, connected, network->connecting,
1400 network->associating);
1402 if ((network->connecting == TRUE || network->associating == TRUE) &&
1403 connected == FALSE) {
1404 connman_network_set_error(network,
1405 CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
1406 if (__connman_network_disconnect(network) == 0)
1410 if (network->connected == connected)
1413 if (connected == FALSE)
1414 set_disconnected(network);
1416 set_connected(network);
1422 * connman_network_get_connected:
1423 * @network: network structure
1425 * Get network connection status
1427 connman_bool_t connman_network_get_connected(struct connman_network *network)
1429 return network->connected;
1433 * connman_network_get_associating:
1434 * @network: network structure
1436 * Get network associating status
1438 connman_bool_t connman_network_get_associating(struct connman_network *network)
1440 return network->associating;
1443 void connman_network_clear_hidden(void *user_data)
1445 if (user_data == NULL)
1448 DBG("user_data %p", user_data);
1451 * Hidden service does not have a connect timeout so
1452 * we do not need to remove it. We can just return
1453 * error to the caller telling that we could not find
1454 * any network that we could connect to.
1456 __connman_service_reply_dbus_pending(user_data, EIO, NULL);
1459 int connman_network_connect_hidden(struct connman_network *network,
1460 char *identity, char* passphrase, void *user_data)
1463 struct connman_service *service;
1465 service = connman_service_lookup_from_network(network);
1467 DBG("network %p service %p user_data %p", network, service, user_data);
1469 if (service == NULL) {
1474 if (identity != NULL)
1475 __connman_service_set_agent_identity(service, identity);
1477 if (passphrase != NULL)
1478 err = __connman_service_add_passphrase(service, passphrase);
1480 if (err == -ENOKEY) {
1481 __connman_service_indicate_error(service,
1482 CONNMAN_SERVICE_ERROR_INVALID_KEY);
1485 __connman_service_set_hidden(service);
1486 __connman_service_set_userconnect(service, TRUE);
1487 __connman_service_set_hidden_data(service, user_data);
1488 return __connman_service_connect(service);
1492 __connman_service_return_error(service, -err, user_data);
1497 * __connman_network_connect:
1498 * @network: network structure
1502 int __connman_network_connect(struct connman_network *network)
1506 DBG("network %p", network);
1508 if (network->connected == TRUE)
1511 if (network->connecting == TRUE || network->associating == TRUE)
1514 if (network->driver == NULL)
1517 if (network->driver->connect == NULL)
1520 if (network->device == NULL)
1523 network->connecting = TRUE;
1525 __connman_device_disconnect(network->device);
1527 err = network->driver->connect(network);
1529 if (err == -EINPROGRESS)
1530 connman_network_set_associating(network, TRUE);
1532 network->connecting = FALSE;
1538 set_connected(network);
1544 * __connman_network_disconnect:
1545 * @network: network structure
1547 * Disconnect network
1549 int __connman_network_disconnect(struct connman_network *network)
1553 DBG("network %p", network);
1555 if (network->connected == FALSE && network->connecting == FALSE &&
1556 network->associating == FALSE)
1559 if (network->driver == NULL)
1562 if (network->driver->disconnect == NULL)
1565 network->connecting = FALSE;
1567 err = network->driver->disconnect(network);
1569 set_disconnected(network);
1574 static int manual_ipv4_set(struct connman_network *network,
1575 struct connman_ipconfig *ipconfig)
1577 struct connman_service *service;
1580 service = connman_service_lookup_from_network(network);
1581 if (service == NULL)
1584 err = __connman_ipconfig_address_add(ipconfig);
1586 connman_network_set_error(network,
1587 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1591 return __connman_ipconfig_gateway_add(ipconfig);
1594 int __connman_network_clear_ipconfig(struct connman_network *network,
1595 struct connman_ipconfig *ipconfig)
1597 struct connman_service *service;
1598 enum connman_ipconfig_method method;
1599 enum connman_ipconfig_type type;
1601 service = connman_service_lookup_from_network(network);
1602 if (service == NULL)
1605 method = __connman_ipconfig_get_method(ipconfig);
1606 type = __connman_ipconfig_get_config_type(ipconfig);
1609 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1610 case CONNMAN_IPCONFIG_METHOD_OFF:
1611 case CONNMAN_IPCONFIG_METHOD_FIXED:
1613 case CONNMAN_IPCONFIG_METHOD_AUTO:
1614 release_dhcpv6(network);
1616 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1617 __connman_ipconfig_address_remove(ipconfig);
1619 case CONNMAN_IPCONFIG_METHOD_DHCP:
1620 __connman_dhcp_stop(network);
1624 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1625 __connman_service_ipconfig_indicate_state(service,
1626 CONNMAN_SERVICE_STATE_CONFIGURATION,
1627 CONNMAN_IPCONFIG_TYPE_IPV6);
1628 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1629 __connman_service_ipconfig_indicate_state(service,
1630 CONNMAN_SERVICE_STATE_CONFIGURATION,
1631 CONNMAN_IPCONFIG_TYPE_IPV4);
1636 int __connman_network_set_ipconfig(struct connman_network *network,
1637 struct connman_ipconfig *ipconfig_ipv4,
1638 struct connman_ipconfig *ipconfig_ipv6)
1640 enum connman_ipconfig_method method;
1643 if (network == NULL)
1646 if (ipconfig_ipv6) {
1647 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1650 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1651 case CONNMAN_IPCONFIG_METHOD_OFF:
1653 case CONNMAN_IPCONFIG_METHOD_AUTO:
1654 autoconf_ipv6_set(network);
1656 case CONNMAN_IPCONFIG_METHOD_FIXED:
1657 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1658 ret = manual_ipv6_set(network, ipconfig_ipv6);
1660 connman_network_set_error(network,
1661 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1665 case CONNMAN_IPCONFIG_METHOD_DHCP:
1670 if (ipconfig_ipv4) {
1671 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1674 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1675 case CONNMAN_IPCONFIG_METHOD_OFF:
1676 case CONNMAN_IPCONFIG_METHOD_FIXED:
1677 case CONNMAN_IPCONFIG_METHOD_AUTO:
1679 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1680 return manual_ipv4_set(network, ipconfig_ipv4);
1681 case CONNMAN_IPCONFIG_METHOD_DHCP:
1682 return __connman_dhcp_start(network, dhcp_callback);
1689 int connman_network_set_ipaddress(struct connman_network *network,
1690 struct connman_ipaddress *ipaddress)
1692 struct connman_service *service;
1693 struct connman_ipconfig *ipconfig = NULL;
1695 DBG("network %p", network);
1697 service = connman_service_lookup_from_network(network);
1698 if (service == NULL)
1701 ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
1702 if (ipconfig == NULL)
1705 __connman_ipconfig_set_local(ipconfig, ipaddress->local);
1706 __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
1707 __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
1708 __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
1709 __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
1714 int connman_network_set_nameservers(struct connman_network *network,
1715 const char *nameservers)
1717 struct connman_service *service;
1718 char **nameservers_array;
1721 DBG("network %p nameservers %s", network, nameservers);
1723 service = connman_service_lookup_from_network(network);
1724 if (service == NULL)
1727 __connman_service_nameserver_clear(service);
1729 if (nameservers == NULL)
1732 nameservers_array = g_strsplit(nameservers, " ", 0);
1734 for (i = 0; nameservers_array[i] != NULL; i++) {
1735 __connman_service_nameserver_append(service,
1736 nameservers_array[i], FALSE);
1739 g_strfreev(nameservers_array);
1744 int connman_network_set_domain(struct connman_network *network,
1747 struct connman_service *service;
1749 DBG("network %p domain %s", network, domain);
1751 service = connman_service_lookup_from_network(network);
1752 if (service == NULL)
1755 __connman_service_set_domainname(service, domain);
1761 * connman_network_set_name:
1762 * @network: network structure
1765 * Set display name value for network
1767 int connman_network_set_name(struct connman_network *network,
1770 DBG("network %p name %s", network, name);
1772 g_free(network->name);
1773 network->name = g_strdup(name);
1779 * connman_network_set_strength:
1780 * @network: network structure
1781 * @strength: strength value
1783 * Set signal strength value for network
1786 int connman_network_set_strength(struct connman_network *network,
1787 connman_uint8_t strength)
1789 DBG("network %p strengh %d", network, strength);
1791 network->strength = strength;
1796 connman_uint8_t connman_network_get_strength(struct connman_network *network)
1798 return network->strength;
1801 int connman_network_set_frequency(struct connman_network *network,
1802 connman_uint16_t frequency)
1804 DBG("network %p frequency %d", network, frequency);
1806 network->frequency = frequency;
1811 connman_uint16_t connman_network_get_frequency(struct connman_network *network)
1813 return network->frequency;
1816 int connman_network_set_wifi_channel(struct connman_network *network,
1817 connman_uint16_t channel)
1819 DBG("network %p wifi channel %d", network, channel);
1821 network->wifi.channel = channel;
1826 connman_uint16_t connman_network_get_wifi_channel(struct connman_network *network)
1828 return network->wifi.channel;
1832 * connman_network_set_string:
1833 * @network: network structure
1834 * @key: unique identifier
1835 * @value: string value
1837 * Set string value for specific key
1839 int connman_network_set_string(struct connman_network *network,
1840 const char *key, const char *value)
1842 DBG("network %p key %s value %s", network, key, value);
1844 if (g_strcmp0(key, "Name") == 0)
1845 return connman_network_set_name(network, value);
1847 if (g_str_equal(key, "Path") == TRUE) {
1848 g_free(network->path);
1849 network->path = g_strdup(value);
1850 } else if (g_str_equal(key, "Node") == TRUE) {
1851 g_free(network->node);
1852 network->node = g_strdup(value);
1853 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1854 g_free(network->wifi.mode);
1855 network->wifi.mode = g_strdup(value);
1856 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1857 g_free(network->wifi.security);
1858 network->wifi.security = g_strdup(value);
1859 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1860 g_free(network->wifi.passphrase);
1861 network->wifi.passphrase = g_strdup(value);
1862 } else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE) {
1863 g_free(network->wifi.agent_passphrase);
1864 network->wifi.agent_passphrase = g_strdup(value);
1865 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1866 g_free(network->wifi.eap);
1867 network->wifi.eap = g_strdup(value);
1868 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1869 g_free(network->wifi.identity);
1870 network->wifi.identity = g_strdup(value);
1871 } else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE) {
1872 g_free(network->wifi.agent_identity);
1873 network->wifi.agent_identity = g_strdup(value);
1874 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1875 g_free(network->wifi.ca_cert_path);
1876 network->wifi.ca_cert_path = g_strdup(value);
1877 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1878 g_free(network->wifi.client_cert_path);
1879 network->wifi.client_cert_path = g_strdup(value);
1880 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1881 g_free(network->wifi.private_key_path);
1882 network->wifi.private_key_path = g_strdup(value);
1883 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1884 g_free(network->wifi.private_key_passphrase);
1885 network->wifi.private_key_passphrase = g_strdup(value);
1886 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1887 g_free(network->wifi.phase2_auth);
1888 network->wifi.phase2_auth = g_strdup(value);
1889 } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
1890 g_free(network->wifi.pin_wps);
1891 network->wifi.pin_wps = g_strdup(value);
1900 * connman_network_get_string:
1901 * @network: network structure
1902 * @key: unique identifier
1904 * Get string value for specific key
1906 const char *connman_network_get_string(struct connman_network *network,
1909 DBG("network %p key %s", network, key);
1911 if (g_str_equal(key, "Path") == TRUE)
1912 return network->path;
1913 else if (g_str_equal(key, "Name") == TRUE)
1914 return network->name;
1915 else if (g_str_equal(key, "Node") == TRUE)
1916 return network->node;
1917 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1918 return network->wifi.mode;
1919 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1920 return network->wifi.security;
1921 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1922 return network->wifi.passphrase;
1923 else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE)
1924 return network->wifi.agent_passphrase;
1925 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1926 return network->wifi.eap;
1927 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1928 return network->wifi.identity;
1929 else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE)
1930 return network->wifi.agent_identity;
1931 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1932 return network->wifi.ca_cert_path;
1933 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1934 return network->wifi.client_cert_path;
1935 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1936 return network->wifi.private_key_path;
1937 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1938 return network->wifi.private_key_passphrase;
1939 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1940 return network->wifi.phase2_auth;
1941 else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
1942 return network->wifi.pin_wps;
1948 * connman_network_set_bool:
1949 * @network: network structure
1950 * @key: unique identifier
1951 * @value: boolean value
1953 * Set boolean value for specific key
1955 int connman_network_set_bool(struct connman_network *network,
1956 const char *key, connman_bool_t value)
1958 DBG("network %p key %s value %d", network, key, value);
1960 if (g_strcmp0(key, "Roaming") == 0)
1961 network->roaming = value;
1962 else if (g_strcmp0(key, "WiFi.WPS") == 0)
1963 network->wifi.wps = value;
1964 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
1965 network->wifi.use_wps = value;
1971 * connman_network_get_bool:
1972 * @network: network structure
1973 * @key: unique identifier
1975 * Get boolean value for specific key
1977 connman_bool_t connman_network_get_bool(struct connman_network *network,
1980 DBG("network %p key %s", network, key);
1982 if (g_str_equal(key, "Roaming") == TRUE)
1983 return network->roaming;
1984 else if (g_str_equal(key, "WiFi.WPS") == TRUE)
1985 return network->wifi.wps;
1986 else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
1987 return network->wifi.use_wps;
1993 * connman_network_set_blob:
1994 * @network: network structure
1995 * @key: unique identifier
1999 * Set binary blob value for specific key
2001 int connman_network_set_blob(struct connman_network *network,
2002 const char *key, const void *data, unsigned int size)
2004 DBG("network %p key %s size %d", network, key, size);
2006 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
2007 g_free(network->wifi.ssid);
2008 network->wifi.ssid = g_try_malloc(size);
2009 if (network->wifi.ssid != NULL) {
2010 memcpy(network->wifi.ssid, data, size);
2011 network->wifi.ssid_len = size;
2013 network->wifi.ssid_len = 0;
2022 * connman_network_get_blob:
2023 * @network: network structure
2024 * @key: unique identifier
2025 * @size: pointer to blob size
2027 * Get binary blob value for specific key
2029 const void *connman_network_get_blob(struct connman_network *network,
2030 const char *key, unsigned int *size)
2032 DBG("network %p key %s", network, key);
2034 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
2036 *size = network->wifi.ssid_len;
2037 return network->wifi.ssid;
2043 void __connman_network_set_device(struct connman_network *network,
2044 struct connman_device *device)
2046 if (network->device == device)
2049 if (network->device != NULL)
2050 network_remove(network);
2052 network->device = device;
2054 if (network->device != NULL)
2055 network_probe(network);
2059 * connman_network_get_device:
2060 * @network: network structure
2062 * Get parent device of network
2064 struct connman_device *connman_network_get_device(struct connman_network *network)
2066 return network->device;
2070 * connman_network_get_data:
2071 * @network: network structure
2073 * Get private network data pointer
2075 void *connman_network_get_data(struct connman_network *network)
2077 return network->driver_data;
2081 * connman_network_set_data:
2082 * @network: network structure
2083 * @data: data pointer
2085 * Set private network data pointer
2087 void connman_network_set_data(struct connman_network *network, void *data)
2089 network->driver_data = data;
2092 void connman_network_update(struct connman_network *network)
2094 switch (network->type) {
2095 case CONNMAN_NETWORK_TYPE_UNKNOWN:
2096 case CONNMAN_NETWORK_TYPE_VENDOR:
2098 case CONNMAN_NETWORK_TYPE_ETHERNET:
2099 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
2100 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
2101 case CONNMAN_NETWORK_TYPE_CELLULAR:
2102 case CONNMAN_NETWORK_TYPE_WIFI:
2103 case CONNMAN_NETWORK_TYPE_WIMAX:
2107 if (network->group != NULL)
2108 __connman_service_update_from_network(network);
2111 int __connman_network_init(void)
2118 void __connman_network_cleanup(void)