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_append(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);
473 DBG("index %d service %p ip4config %p", network->index,
476 if (network->index < 0 && ipconfig == NULL) {
478 ipconfig = __connman_service_get_ip4config(service);
479 if (ipconfig == NULL)
481 * This is needed for plugins that havent set their
482 * ipconfig layer yet, due to not being able to get
483 * a network index prior to creating a service.
485 connman_service_create_ip4config(service, index);
487 __connman_ipconfig_set_index(ipconfig, index);
490 /* If index changed, the index of ipconfig must be reset. */
491 if (ipconfig == NULL)
494 __connman_ipconfig_set_index(ipconfig, index);
498 network->index = index;
502 * connman_network_get_index:
503 * @network: network structure
505 * Get index number of network
507 int connman_network_get_index(struct connman_network *network)
509 return network->index;
513 * connman_network_set_group:
514 * @network: network structure
517 * Set group name for automatic clustering
519 void connman_network_set_group(struct connman_network *network,
522 switch (network->type) {
523 case CONNMAN_NETWORK_TYPE_UNKNOWN:
524 case CONNMAN_NETWORK_TYPE_VENDOR:
526 case CONNMAN_NETWORK_TYPE_ETHERNET:
527 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
528 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
529 case CONNMAN_NETWORK_TYPE_CELLULAR:
530 case CONNMAN_NETWORK_TYPE_WIFI:
531 case CONNMAN_NETWORK_TYPE_WIMAX:
535 if (g_strcmp0(network->group, group) == 0) {
537 __connman_service_update_from_network(network);
541 if (network->group != NULL) {
542 __connman_service_remove_from_network(network);
544 g_free(network->group);
547 network->group = g_strdup(group);
549 if (network->group != NULL)
550 network_probe(network);
554 * connman_network_get_group:
555 * @network: network structure
557 * Get group name for automatic clustering
559 const char *connman_network_get_group(struct connman_network *network)
561 return network->group;
564 const char *__connman_network_get_ident(struct connman_network *network)
566 if (network->device == NULL)
569 return connman_device_get_ident(network->device);
572 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
574 switch (network->type) {
575 case CONNMAN_NETWORK_TYPE_UNKNOWN:
576 case CONNMAN_NETWORK_TYPE_VENDOR:
577 case CONNMAN_NETWORK_TYPE_ETHERNET:
578 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
579 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
580 case CONNMAN_NETWORK_TYPE_CELLULAR:
581 case CONNMAN_NETWORK_TYPE_WIMAX:
583 case CONNMAN_NETWORK_TYPE_WIFI:
584 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
586 if (network->strength > 0 && network->strength < 20)
594 connman_bool_t connman_network_get_connecting(struct connman_network *network)
596 return network->connecting;
600 * connman_network_set_available:
601 * @network: network structure
602 * @available: availability state
604 * Change availability state of network (in range)
606 int connman_network_set_available(struct connman_network *network,
607 connman_bool_t available)
609 DBG("network %p available %d", network, available);
611 if (network->available == available)
614 network->available = available;
620 * connman_network_get_available:
621 * @network: network structure
623 * Get network available setting
625 connman_bool_t connman_network_get_available(struct connman_network *network)
627 return network->available;
631 * connman_network_set_associating:
632 * @network: network structure
633 * @associating: associating state
635 * Change associating state of network
637 int connman_network_set_associating(struct connman_network *network,
638 connman_bool_t associating)
640 DBG("network %p associating %d", network, associating);
642 if (network->associating == associating)
645 network->associating = associating;
647 if (associating == TRUE) {
648 struct connman_service *service;
650 service = __connman_service_lookup_from_network(network);
651 __connman_service_ipconfig_indicate_state(service,
652 CONNMAN_SERVICE_STATE_ASSOCIATION,
653 CONNMAN_IPCONFIG_TYPE_IPV4);
654 __connman_service_ipconfig_indicate_state(service,
655 CONNMAN_SERVICE_STATE_ASSOCIATION,
656 CONNMAN_IPCONFIG_TYPE_IPV6);
662 static void set_associate_error(struct connman_network *network)
664 struct connman_service *service;
666 service = __connman_service_lookup_from_network(network);
668 __connman_service_indicate_error(service,
669 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
672 static void set_configure_error(struct connman_network *network)
674 struct connman_service *service;
676 service = __connman_service_lookup_from_network(network);
678 __connman_service_indicate_error(service,
679 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
682 static void set_invalid_key_error(struct connman_network *network)
684 struct connman_service *service;
686 service = __connman_service_lookup_from_network(network);
688 __connman_service_indicate_error(service,
689 CONNMAN_SERVICE_ERROR_INVALID_KEY);
692 static void set_connect_error(struct connman_network *network)
694 struct connman_service *service;
696 service = __connman_service_lookup_from_network(network);
698 __connman_service_indicate_error(service,
699 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
702 void connman_network_set_ipv4_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_ip4config(service);
713 if (ipconfig == NULL)
716 __connman_ipconfig_set_method(ipconfig, method);
719 void connman_network_set_ipv6_method(struct connman_network *network,
720 enum connman_ipconfig_method method)
722 struct connman_service *service;
723 struct connman_ipconfig *ipconfig;
725 service = __connman_service_lookup_from_network(network);
729 ipconfig = __connman_service_get_ip6config(service);
730 if (ipconfig == NULL)
733 __connman_ipconfig_set_method(ipconfig, method);
736 void connman_network_set_error(struct connman_network *network,
737 enum connman_network_error error)
739 DBG("nework %p, error %d", network, error);
741 network->connecting = FALSE;
742 network->associating = FALSE;
745 case CONNMAN_NETWORK_ERROR_UNKNOWN:
747 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
748 set_associate_error(network);
750 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
751 set_configure_error(network);
753 case CONNMAN_NETWORK_ERROR_INVALID_KEY:
754 set_invalid_key_error(network);
756 case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
757 set_connect_error(network);
761 network_change(network);
764 void connman_network_clear_error(struct connman_network *network)
766 struct connman_service *service;
768 DBG("network %p", network);
773 if (network->connecting == TRUE || network->associating == TRUE)
776 service = __connman_service_lookup_from_network(network);
777 __connman_service_clear_error(service);
780 static void set_configuration(struct connman_network *network,
781 enum connman_ipconfig_type type)
783 struct connman_service *service;
785 DBG("network %p", network);
787 if (network->device == NULL)
790 __connman_device_set_network(network->device, network);
792 connman_device_set_disconnected(network->device, FALSE);
794 service = __connman_service_lookup_from_network(network);
795 __connman_service_ipconfig_indicate_state(service,
796 CONNMAN_SERVICE_STATE_CONFIGURATION,
800 static void dhcp_success(struct connman_network *network)
802 struct connman_service *service;
803 struct connman_ipconfig *ipconfig_ipv4;
806 service = __connman_service_lookup_from_network(network);
810 connman_network_set_associating(network, FALSE);
812 network->connecting = FALSE;
814 ipconfig_ipv4 = __connman_service_get_ip4config(service);
815 err = __connman_ipconfig_address_add(ipconfig_ipv4);
819 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
826 connman_network_set_error(network,
827 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
830 static void dhcp_failure(struct connman_network *network)
832 struct connman_service *service;
834 service = __connman_service_lookup_from_network(network);
838 __connman_service_ipconfig_indicate_state(service,
839 CONNMAN_SERVICE_STATE_IDLE,
840 CONNMAN_IPCONFIG_TYPE_IPV4);
843 static void dhcp_callback(struct connman_network *network,
844 connman_bool_t success)
846 DBG("success %d", success);
849 dhcp_success(network);
851 dhcp_failure(network);
854 static int set_connected_fixed(struct connman_network *network)
856 struct connman_service *service;
857 struct connman_ipconfig *ipconfig_ipv4;
862 service = __connman_service_lookup_from_network(network);
864 ipconfig_ipv4 = __connman_service_get_ip4config(service);
866 set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
868 network->connecting = FALSE;
870 connman_network_set_associating(network, FALSE);
872 err = __connman_ipconfig_address_add(ipconfig_ipv4);
876 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
883 connman_network_set_error(network,
884 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
889 static void set_connected_manual(struct connman_network *network)
891 struct connman_service *service;
892 struct connman_ipconfig *ipconfig;
895 DBG("network %p", network);
897 service = __connman_service_lookup_from_network(network);
899 ipconfig = __connman_service_get_ip4config(service);
901 if (__connman_ipconfig_get_local(ipconfig) == NULL)
902 __connman_service_read_ip4config(service);
904 set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
906 err = __connman_ipconfig_address_add(ipconfig);
910 err = __connman_ipconfig_gateway_add(ipconfig);
914 network->connecting = FALSE;
916 connman_network_set_associating(network, FALSE);
921 connman_network_set_error(network,
922 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
926 static int set_connected_dhcp(struct connman_network *network)
930 DBG("network %p", network);
932 set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
934 err = __connman_dhcp_start(network, dhcp_callback);
936 connman_error("Can not request DHCP lease");
943 static int manual_ipv6_set(struct connman_network *network,
944 struct connman_ipconfig *ipconfig_ipv6)
946 struct connman_service *service;
949 DBG("network %p ipv6 %p", network, ipconfig_ipv6);
951 service = __connman_service_lookup_from_network(network);
955 if (__connman_ipconfig_get_local(ipconfig_ipv6) == NULL)
956 __connman_service_read_ip6config(service);
958 err = __connman_ipconfig_address_add(ipconfig_ipv6);
960 connman_network_set_error(network,
961 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
965 err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
969 __connman_connection_gateway_activate(service,
970 CONNMAN_IPCONFIG_TYPE_IPV6);
972 __connman_device_set_network(network->device, network);
974 connman_device_set_disconnected(network->device, FALSE);
976 network->connecting = FALSE;
981 static void stop_dhcpv6(struct connman_network *network)
983 __connman_dhcpv6_stop(network);
986 static void dhcpv6_release_callback(struct connman_network *network,
987 connman_bool_t success)
989 DBG("success %d", success);
991 stop_dhcpv6(network);
994 static void release_dhcpv6(struct connman_network *network)
996 __connman_dhcpv6_start_release(network, dhcpv6_release_callback);
997 stop_dhcpv6(network);
1000 static void dhcpv6_info_callback(struct connman_network *network,
1001 connman_bool_t success)
1003 DBG("success %d", success);
1005 stop_dhcpv6(network);
1008 static gboolean dhcpv6_set_addresses(struct connman_network *network)
1010 struct connman_service *service;
1011 struct connman_ipconfig *ipconfig_ipv6;
1014 service = __connman_service_lookup_from_network(network);
1015 if (service == NULL)
1018 connman_network_set_associating(network, FALSE);
1020 network->connecting = FALSE;
1022 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1023 err = __connman_ipconfig_address_add(ipconfig_ipv6);
1027 err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
1034 connman_network_set_error(network,
1035 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1039 static void autoconf_ipv6_set(struct connman_network *network);
1040 static void dhcpv6_callback(struct connman_network *network,
1041 connman_bool_t success);
1044 * Have a separate callback for renew so that we do not do autoconf
1045 * in wrong phase as the dhcpv6_callback() is also called when doing
1046 * DHCPv6 solicitation.
1048 static void dhcpv6_renew_callback(struct connman_network *network,
1049 connman_bool_t success)
1051 if (success == TRUE)
1052 dhcpv6_callback(network, success);
1054 stop_dhcpv6(network);
1056 /* restart and do solicit again. */
1057 autoconf_ipv6_set(network);
1061 static void dhcpv6_callback(struct connman_network *network,
1062 connman_bool_t success)
1064 DBG("success %d", success);
1066 /* Start the renew process if necessary */
1067 if (success == TRUE) {
1069 if (dhcpv6_set_addresses(network) < 0) {
1070 stop_dhcpv6(network);
1074 if (__connman_dhcpv6_start_renew(network,
1075 dhcpv6_renew_callback) == -ETIMEDOUT)
1076 dhcpv6_renew_callback(network, FALSE);
1078 stop_dhcpv6(network);
1081 static void check_dhcpv6(struct nd_router_advert *reply,
1082 unsigned int length, void *user_data)
1084 struct connman_network *network = user_data;
1087 DBG("reply %p", reply);
1089 if (reply == NULL) {
1091 * Router solicitation message seem to get lost easily so
1092 * try to send it again.
1094 if (network->router_solicit_count > 0) {
1095 DBG("re-send router solicitation %d",
1096 network->router_solicit_count);
1097 network->router_solicit_count--;
1098 __connman_inet_ipv6_send_rs(network->index, 1,
1099 check_dhcpv6, network);
1102 connman_network_unref(network);
1106 network->router_solicit_count = 0;
1109 * If we were disconnected while waiting router advertisement,
1110 * we just quit and do not start DHCPv6
1112 if (network->connected == FALSE) {
1113 connman_network_unref(network);
1117 prefixes = __connman_inet_ipv6_get_prefixes(reply, length);
1120 * We do stateful/stateless DHCPv6 if router advertisement says so.
1122 if (reply->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED)
1123 __connman_dhcpv6_start(network, prefixes, dhcpv6_callback);
1124 else if (reply->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
1125 __connman_dhcpv6_start_info(network, dhcpv6_info_callback);
1127 connman_network_unref(network);
1130 static void receive_refresh_rs_reply(struct nd_router_advert *reply,
1131 unsigned int length, void *user_data)
1133 struct connman_network *network = user_data;
1135 DBG("reply %p", reply);
1137 if (reply == NULL) {
1139 * Router solicitation message seem to get lost easily so
1140 * try to send it again.
1142 if (network->router_solicit_refresh_count > 1) {
1143 network->router_solicit_refresh_count--;
1144 DBG("re-send router solicitation %d",
1145 network->router_solicit_refresh_count);
1146 __connman_inet_ipv6_send_rs(network->index,
1148 receive_refresh_rs_reply,
1154 /* RS refresh not in progress anymore */
1155 network->router_solicit_refresh_count = 0;
1157 connman_network_unref(network);
1161 int __connman_refresh_rs_ipv6(struct connman_network *network, int index)
1165 DBG("network %p index %d", network, index);
1167 /* Send only one RS for all RDNSS entries which are about to expire */
1168 if (network->router_solicit_refresh_count > 0) {
1169 DBG("RS refresh already started");
1173 network->router_solicit_refresh_count = RS_REFRESH_COUNT;
1175 connman_network_ref(network);
1177 ret = __connman_inet_ipv6_send_rs(index, RS_REFRESH_TIMEOUT,
1178 receive_refresh_rs_reply, network);
1182 static void autoconf_ipv6_set(struct connman_network *network)
1184 struct connman_service *service;
1185 struct connman_ipconfig *ipconfig;
1188 DBG("network %p", network);
1190 if (network->router_solicit_count > 0) {
1192 * The autoconfiguration is already pending and we have sent
1193 * router solicitation messages and are now waiting answers.
1194 * There is no need to continue any further.
1196 DBG("autoconfiguration already started");
1200 __connman_device_set_network(network->device, network);
1202 connman_device_set_disconnected(network->device, FALSE);
1204 network->connecting = FALSE;
1206 service = __connman_service_lookup_from_network(network);
1207 if (service == NULL)
1210 ipconfig = __connman_service_get_ip6config(service);
1211 if (ipconfig == NULL)
1214 index = __connman_ipconfig_get_index(ipconfig);
1216 connman_network_ref(network);
1218 /* Try to get stateless DHCPv6 information, RFC 3736 */
1219 network->router_solicit_count = 3;
1220 __connman_inet_ipv6_send_rs(index, 1, check_dhcpv6, network);
1223 static void set_connected(struct connman_network *network)
1225 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
1226 enum connman_ipconfig_method ipv4_method, ipv6_method;
1227 struct connman_service *service;
1230 if (network->connected == TRUE)
1233 network->connected = TRUE;
1235 service = __connman_service_lookup_from_network(network);
1237 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1238 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1240 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
1243 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
1244 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
1246 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
1248 switch (ipv6_method) {
1249 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1250 case CONNMAN_IPCONFIG_METHOD_OFF:
1252 case CONNMAN_IPCONFIG_METHOD_DHCP:
1253 case CONNMAN_IPCONFIG_METHOD_AUTO:
1254 autoconf_ipv6_set(network);
1256 case CONNMAN_IPCONFIG_METHOD_FIXED:
1257 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1258 ret = manual_ipv6_set(network, ipconfig_ipv6);
1260 connman_network_set_error(network,
1261 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1267 switch (ipv4_method) {
1268 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1269 case CONNMAN_IPCONFIG_METHOD_OFF:
1270 case CONNMAN_IPCONFIG_METHOD_AUTO:
1272 case CONNMAN_IPCONFIG_METHOD_FIXED:
1273 if (set_connected_fixed(network) < 0) {
1274 connman_network_set_error(network,
1275 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1279 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1280 set_connected_manual(network);
1282 case CONNMAN_IPCONFIG_METHOD_DHCP:
1283 if (set_connected_dhcp(network) < 0) {
1284 connman_network_set_error(network,
1285 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1290 network->connecting = FALSE;
1292 connman_network_set_associating(network, FALSE);
1295 static void set_disconnected(struct connman_network *network)
1297 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
1298 enum connman_ipconfig_method ipv4_method, ipv6_method;
1299 enum connman_service_state state;
1300 struct connman_service *service;
1302 if (network->connected == FALSE)
1305 network->connected = FALSE;
1307 service = __connman_service_lookup_from_network(network);
1309 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1310 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1312 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
1315 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
1316 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
1318 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
1321 * Resetting solicit count here will prevent the RS resend loop
1322 * from sending packets in check_dhcpv6()
1324 network->router_solicit_count = 0;
1326 __connman_device_set_network(network->device, NULL);
1328 switch (ipv6_method) {
1329 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1330 case CONNMAN_IPCONFIG_METHOD_OFF:
1331 case CONNMAN_IPCONFIG_METHOD_FIXED:
1332 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1334 case CONNMAN_IPCONFIG_METHOD_DHCP:
1335 case CONNMAN_IPCONFIG_METHOD_AUTO:
1336 release_dhcpv6(network);
1340 switch (ipv4_method) {
1341 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1342 case CONNMAN_IPCONFIG_METHOD_OFF:
1343 case CONNMAN_IPCONFIG_METHOD_AUTO:
1344 case CONNMAN_IPCONFIG_METHOD_FIXED:
1345 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1347 case CONNMAN_IPCONFIG_METHOD_DHCP:
1348 __connman_dhcp_stop(network);
1353 * We only set the disconnect state if we were not in idle
1354 * or in failure. It does not make sense to go to disconnect
1355 * state if we were not connected.
1357 state = __connman_service_ipconfig_get_state(service,
1358 CONNMAN_IPCONFIG_TYPE_IPV4);
1359 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1360 state != CONNMAN_SERVICE_STATE_FAILURE)
1361 __connman_service_ipconfig_indicate_state(service,
1362 CONNMAN_SERVICE_STATE_DISCONNECT,
1363 CONNMAN_IPCONFIG_TYPE_IPV4);
1365 state = __connman_service_ipconfig_get_state(service,
1366 CONNMAN_IPCONFIG_TYPE_IPV6);
1367 if (state != CONNMAN_SERVICE_STATE_IDLE &&
1368 state != CONNMAN_SERVICE_STATE_FAILURE)
1369 __connman_service_ipconfig_indicate_state(service,
1370 CONNMAN_SERVICE_STATE_DISCONNECT,
1371 CONNMAN_IPCONFIG_TYPE_IPV6);
1373 __connman_connection_gateway_remove(service,
1374 CONNMAN_IPCONFIG_TYPE_ALL);
1376 __connman_ipconfig_address_unset(ipconfig_ipv4);
1377 __connman_ipconfig_address_unset(ipconfig_ipv6);
1380 * Special handling for IPv6 autoconfigured address.
1381 * The simplest way to remove autoconfigured routes is to
1382 * disable IPv6 temporarily so that kernel will do the cleanup
1385 if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
1386 __connman_ipconfig_disable_ipv6(ipconfig_ipv6);
1387 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
1390 __connman_service_ipconfig_indicate_state(service,
1391 CONNMAN_SERVICE_STATE_IDLE,
1392 CONNMAN_IPCONFIG_TYPE_IPV4);
1394 __connman_service_ipconfig_indicate_state(service,
1395 CONNMAN_SERVICE_STATE_IDLE,
1396 CONNMAN_IPCONFIG_TYPE_IPV6);
1398 network->connecting = FALSE;
1400 connman_network_set_associating(network, FALSE);
1404 * connman_network_set_connected:
1405 * @network: network structure
1406 * @connected: connected state
1408 * Change connected state of network
1410 int connman_network_set_connected(struct connman_network *network,
1411 connman_bool_t connected)
1413 DBG("network %p connected %d/%d connecting %d associating %d",
1414 network, network->connected, connected, network->connecting,
1415 network->associating);
1417 if ((network->connecting == TRUE || network->associating == TRUE) &&
1418 connected == FALSE) {
1419 connman_network_set_error(network,
1420 CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
1421 if (__connman_network_disconnect(network) == 0)
1425 if (network->connected == connected)
1428 if (connected == FALSE)
1429 set_disconnected(network);
1431 set_connected(network);
1437 * connman_network_get_connected:
1438 * @network: network structure
1440 * Get network connection status
1442 connman_bool_t connman_network_get_connected(struct connman_network *network)
1444 return network->connected;
1448 * connman_network_get_associating:
1449 * @network: network structure
1451 * Get network associating status
1453 connman_bool_t connman_network_get_associating(struct connman_network *network)
1455 return network->associating;
1458 void connman_network_clear_hidden(void *user_data)
1460 if (user_data == NULL)
1463 DBG("user_data %p", user_data);
1466 * Hidden service does not have a connect timeout so
1467 * we do not need to remove it. We can just return
1468 * error to the caller telling that we could not find
1469 * any network that we could connect to.
1471 __connman_service_reply_dbus_pending(user_data, EIO);
1474 int connman_network_connect_hidden(struct connman_network *network,
1475 char *identity, char* passphrase, void *user_data)
1478 struct connman_service *service;
1480 service = __connman_service_lookup_from_network(network);
1482 DBG("network %p service %p user_data %p", network, service, user_data);
1484 if (service == NULL) {
1489 if (identity != NULL)
1490 __connman_service_set_agent_identity(service, identity);
1492 if (passphrase != NULL)
1493 err = __connman_service_add_passphrase(service, passphrase);
1495 if (err == -ENOKEY) {
1496 __connman_service_indicate_error(service,
1497 CONNMAN_SERVICE_ERROR_INVALID_KEY);
1500 __connman_service_set_hidden(service);
1501 __connman_service_set_userconnect(service, TRUE);
1502 __connman_service_set_hidden_data(service, user_data);
1503 return __connman_service_connect(service);
1507 __connman_service_return_error(service, -err, user_data);
1512 * __connman_network_connect:
1513 * @network: network structure
1517 int __connman_network_connect(struct connman_network *network)
1521 DBG("network %p", network);
1523 if (network->connected == TRUE)
1526 if (network->connecting == TRUE || network->associating == TRUE)
1529 if (network->driver == NULL)
1532 if (network->driver->connect == NULL)
1535 if (network->device == NULL)
1538 network->connecting = TRUE;
1540 __connman_device_disconnect(network->device);
1542 err = network->driver->connect(network);
1544 if (err == -EINPROGRESS)
1545 connman_network_set_associating(network, TRUE);
1547 network->connecting = FALSE;
1553 set_connected(network);
1559 * __connman_network_disconnect:
1560 * @network: network structure
1562 * Disconnect network
1564 int __connman_network_disconnect(struct connman_network *network)
1568 DBG("network %p", network);
1570 if (network->connected == FALSE && network->connecting == FALSE &&
1571 network->associating == FALSE)
1574 if (network->driver == NULL)
1577 if (network->driver->disconnect == NULL)
1580 network->connecting = FALSE;
1582 err = network->driver->disconnect(network);
1584 set_disconnected(network);
1589 static int manual_ipv4_set(struct connman_network *network,
1590 struct connman_ipconfig *ipconfig)
1592 struct connman_service *service;
1595 service = __connman_service_lookup_from_network(network);
1596 if (service == NULL)
1599 err = __connman_ipconfig_address_add(ipconfig);
1601 connman_network_set_error(network,
1602 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1606 return __connman_ipconfig_gateway_add(ipconfig);
1609 int __connman_network_clear_ipconfig(struct connman_network *network,
1610 struct connman_ipconfig *ipconfig)
1612 struct connman_service *service;
1613 enum connman_ipconfig_method method;
1614 enum connman_ipconfig_type type;
1616 service = __connman_service_lookup_from_network(network);
1617 if (service == NULL)
1620 method = __connman_ipconfig_get_method(ipconfig);
1621 type = __connman_ipconfig_get_config_type(ipconfig);
1624 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1625 case CONNMAN_IPCONFIG_METHOD_OFF:
1626 case CONNMAN_IPCONFIG_METHOD_FIXED:
1628 case CONNMAN_IPCONFIG_METHOD_AUTO:
1629 release_dhcpv6(network);
1631 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1632 __connman_ipconfig_address_remove(ipconfig);
1634 case CONNMAN_IPCONFIG_METHOD_DHCP:
1635 __connman_dhcp_stop(network);
1639 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1640 __connman_service_ipconfig_indicate_state(service,
1641 CONNMAN_SERVICE_STATE_CONFIGURATION,
1642 CONNMAN_IPCONFIG_TYPE_IPV6);
1643 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1644 __connman_service_ipconfig_indicate_state(service,
1645 CONNMAN_SERVICE_STATE_CONFIGURATION,
1646 CONNMAN_IPCONFIG_TYPE_IPV4);
1651 int __connman_network_set_ipconfig(struct connman_network *network,
1652 struct connman_ipconfig *ipconfig_ipv4,
1653 struct connman_ipconfig *ipconfig_ipv6)
1655 enum connman_ipconfig_method method;
1658 if (network == NULL)
1661 if (ipconfig_ipv6) {
1662 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1665 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1666 case CONNMAN_IPCONFIG_METHOD_OFF:
1668 case CONNMAN_IPCONFIG_METHOD_AUTO:
1669 autoconf_ipv6_set(network);
1671 case CONNMAN_IPCONFIG_METHOD_FIXED:
1672 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1673 ret = manual_ipv6_set(network, ipconfig_ipv6);
1675 connman_network_set_error(network,
1676 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1680 case CONNMAN_IPCONFIG_METHOD_DHCP:
1685 if (ipconfig_ipv4) {
1686 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1689 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1690 case CONNMAN_IPCONFIG_METHOD_OFF:
1691 case CONNMAN_IPCONFIG_METHOD_FIXED:
1692 case CONNMAN_IPCONFIG_METHOD_AUTO:
1694 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1695 return manual_ipv4_set(network, ipconfig_ipv4);
1696 case CONNMAN_IPCONFIG_METHOD_DHCP:
1697 return __connman_dhcp_start(network, dhcp_callback);
1704 int connman_network_set_ipaddress(struct connman_network *network,
1705 struct connman_ipaddress *ipaddress)
1707 struct connman_service *service;
1708 struct connman_ipconfig *ipconfig = NULL;
1710 DBG("network %p", network);
1712 service = __connman_service_lookup_from_network(network);
1713 if (service == NULL)
1716 ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
1717 if (ipconfig == NULL)
1720 __connman_ipconfig_set_local(ipconfig, ipaddress->local);
1721 __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
1722 __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
1723 __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
1724 __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
1729 int connman_network_set_nameservers(struct connman_network *network,
1730 const char *nameservers)
1732 struct connman_service *service;
1733 char **nameservers_array;
1736 DBG("network %p nameservers %s", network, nameservers);
1738 service = __connman_service_lookup_from_network(network);
1739 if (service == NULL)
1742 __connman_service_nameserver_clear(service);
1744 if (nameservers == NULL)
1747 nameservers_array = g_strsplit(nameservers, " ", 0);
1749 for (i = 0; nameservers_array[i] != NULL; i++) {
1750 __connman_service_nameserver_append(service,
1751 nameservers_array[i], FALSE);
1754 g_strfreev(nameservers_array);
1759 int connman_network_set_domain(struct connman_network *network,
1762 struct connman_service *service;
1764 DBG("network %p domain %s", network, domain);
1766 service = __connman_service_lookup_from_network(network);
1767 if (service == NULL)
1770 __connman_service_set_domainname(service, domain);
1776 * connman_network_set_name:
1777 * @network: network structure
1780 * Set display name value for network
1782 int connman_network_set_name(struct connman_network *network,
1785 DBG("network %p name %s", network, name);
1787 g_free(network->name);
1788 network->name = g_strdup(name);
1794 * connman_network_set_strength:
1795 * @network: network structure
1796 * @strength: strength value
1798 * Set signal strength value for network
1801 int connman_network_set_strength(struct connman_network *network,
1802 connman_uint8_t strength)
1804 DBG("network %p strengh %d", network, strength);
1806 network->strength = strength;
1811 connman_uint8_t connman_network_get_strength(struct connman_network *network)
1813 return network->strength;
1816 int connman_network_set_frequency(struct connman_network *network,
1817 connman_uint16_t frequency)
1819 DBG("network %p frequency %d", network, frequency);
1821 network->frequency = frequency;
1826 connman_uint16_t connman_network_get_frequency(struct connman_network *network)
1828 return network->frequency;
1831 int connman_network_set_wifi_channel(struct connman_network *network,
1832 connman_uint16_t channel)
1834 DBG("network %p wifi channel %d", network, channel);
1836 network->wifi.channel = channel;
1841 connman_uint16_t connman_network_get_wifi_channel(struct connman_network *network)
1843 return network->wifi.channel;
1847 * connman_network_set_string:
1848 * @network: network structure
1849 * @key: unique identifier
1850 * @value: string value
1852 * Set string value for specific key
1854 int connman_network_set_string(struct connman_network *network,
1855 const char *key, const char *value)
1857 DBG("network %p key %s value %s", network, key, value);
1859 if (g_strcmp0(key, "Name") == 0)
1860 return connman_network_set_name(network, value);
1862 if (g_str_equal(key, "Path") == TRUE) {
1863 g_free(network->path);
1864 network->path = g_strdup(value);
1865 } else if (g_str_equal(key, "Node") == TRUE) {
1866 g_free(network->node);
1867 network->node = g_strdup(value);
1868 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1869 g_free(network->wifi.mode);
1870 network->wifi.mode = g_strdup(value);
1871 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1872 g_free(network->wifi.security);
1873 network->wifi.security = g_strdup(value);
1874 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1875 g_free(network->wifi.passphrase);
1876 network->wifi.passphrase = g_strdup(value);
1877 } else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE) {
1878 g_free(network->wifi.agent_passphrase);
1879 network->wifi.agent_passphrase = g_strdup(value);
1880 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1881 g_free(network->wifi.eap);
1882 network->wifi.eap = g_strdup(value);
1883 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1884 g_free(network->wifi.identity);
1885 network->wifi.identity = g_strdup(value);
1886 } else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE) {
1887 g_free(network->wifi.agent_identity);
1888 network->wifi.agent_identity = g_strdup(value);
1889 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1890 g_free(network->wifi.ca_cert_path);
1891 network->wifi.ca_cert_path = g_strdup(value);
1892 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1893 g_free(network->wifi.client_cert_path);
1894 network->wifi.client_cert_path = g_strdup(value);
1895 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1896 g_free(network->wifi.private_key_path);
1897 network->wifi.private_key_path = g_strdup(value);
1898 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1899 g_free(network->wifi.private_key_passphrase);
1900 network->wifi.private_key_passphrase = g_strdup(value);
1901 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1902 g_free(network->wifi.phase2_auth);
1903 network->wifi.phase2_auth = g_strdup(value);
1904 } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
1905 g_free(network->wifi.pin_wps);
1906 network->wifi.pin_wps = g_strdup(value);
1915 * connman_network_get_string:
1916 * @network: network structure
1917 * @key: unique identifier
1919 * Get string value for specific key
1921 const char *connman_network_get_string(struct connman_network *network,
1924 DBG("network %p key %s", network, key);
1926 if (g_str_equal(key, "Path") == TRUE)
1927 return network->path;
1928 else if (g_str_equal(key, "Name") == TRUE)
1929 return network->name;
1930 else if (g_str_equal(key, "Node") == TRUE)
1931 return network->node;
1932 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1933 return network->wifi.mode;
1934 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1935 return network->wifi.security;
1936 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1937 return network->wifi.passphrase;
1938 else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE)
1939 return network->wifi.agent_passphrase;
1940 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1941 return network->wifi.eap;
1942 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1943 return network->wifi.identity;
1944 else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE)
1945 return network->wifi.agent_identity;
1946 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1947 return network->wifi.ca_cert_path;
1948 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1949 return network->wifi.client_cert_path;
1950 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1951 return network->wifi.private_key_path;
1952 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1953 return network->wifi.private_key_passphrase;
1954 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1955 return network->wifi.phase2_auth;
1956 else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
1957 return network->wifi.pin_wps;
1963 * connman_network_set_bool:
1964 * @network: network structure
1965 * @key: unique identifier
1966 * @value: boolean value
1968 * Set boolean value for specific key
1970 int connman_network_set_bool(struct connman_network *network,
1971 const char *key, connman_bool_t value)
1973 DBG("network %p key %s value %d", network, key, value);
1975 if (g_strcmp0(key, "Roaming") == 0)
1976 network->roaming = value;
1977 else if (g_strcmp0(key, "WiFi.WPS") == 0)
1978 network->wifi.wps = value;
1979 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
1980 network->wifi.use_wps = value;
1986 * connman_network_get_bool:
1987 * @network: network structure
1988 * @key: unique identifier
1990 * Get boolean value for specific key
1992 connman_bool_t connman_network_get_bool(struct connman_network *network,
1995 DBG("network %p key %s", network, key);
1997 if (g_str_equal(key, "Roaming") == TRUE)
1998 return network->roaming;
1999 else if (g_str_equal(key, "WiFi.WPS") == TRUE)
2000 return network->wifi.wps;
2001 else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
2002 return network->wifi.use_wps;
2008 * connman_network_set_blob:
2009 * @network: network structure
2010 * @key: unique identifier
2014 * Set binary blob value for specific key
2016 int connman_network_set_blob(struct connman_network *network,
2017 const char *key, const void *data, unsigned int size)
2019 DBG("network %p key %s size %d", network, key, size);
2021 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
2022 g_free(network->wifi.ssid);
2023 network->wifi.ssid = g_try_malloc(size);
2024 if (network->wifi.ssid != NULL) {
2025 memcpy(network->wifi.ssid, data, size);
2026 network->wifi.ssid_len = size;
2028 network->wifi.ssid_len = 0;
2037 * connman_network_get_blob:
2038 * @network: network structure
2039 * @key: unique identifier
2040 * @size: pointer to blob size
2042 * Get binary blob value for specific key
2044 const void *connman_network_get_blob(struct connman_network *network,
2045 const char *key, unsigned int *size)
2047 DBG("network %p key %s", network, key);
2049 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
2051 *size = network->wifi.ssid_len;
2052 return network->wifi.ssid;
2058 void __connman_network_set_device(struct connman_network *network,
2059 struct connman_device *device)
2061 if (network->device == device)
2064 if (network->device != NULL)
2065 network_remove(network);
2067 network->device = device;
2069 if (network->device != NULL)
2070 network_probe(network);
2074 * connman_network_get_device:
2075 * @network: network structure
2077 * Get parent device of network
2079 struct connman_device *connman_network_get_device(struct connman_network *network)
2081 return network->device;
2085 * connman_network_get_data:
2086 * @network: network structure
2088 * Get private network data pointer
2090 void *connman_network_get_data(struct connman_network *network)
2092 return network->driver_data;
2096 * connman_network_set_data:
2097 * @network: network structure
2098 * @data: data pointer
2100 * Set private network data pointer
2102 void connman_network_set_data(struct connman_network *network, void *data)
2104 network->driver_data = data;
2107 void connman_network_update(struct connman_network *network)
2109 switch (network->type) {
2110 case CONNMAN_NETWORK_TYPE_UNKNOWN:
2111 case CONNMAN_NETWORK_TYPE_VENDOR:
2113 case CONNMAN_NETWORK_TYPE_ETHERNET:
2114 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
2115 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
2116 case CONNMAN_NETWORK_TYPE_CELLULAR:
2117 case CONNMAN_NETWORK_TYPE_WIFI:
2118 case CONNMAN_NETWORK_TYPE_WIMAX:
2122 if (network->group != NULL)
2123 __connman_service_update_from_network(network);
2126 int __connman_network_init(void)
2133 void __connman_network_cleanup(void)