5 * Copyright (C) 2007-2010 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
31 static GSList *network_list = NULL;
32 static GSList *driver_list = NULL;
33 static unsigned int hidden_counter = 0;
35 struct connman_network {
37 enum connman_network_type type;
38 connman_bool_t available;
39 connman_bool_t connected;
40 connman_bool_t roaming;
41 connman_bool_t hidden;
42 connman_uint8_t strength;
43 connman_uint16_t frequency;
51 struct connman_network_driver *driver;
54 connman_bool_t connecting;
55 connman_bool_t associating;
57 struct connman_device *device;
63 unsigned short channel;
69 char *client_cert_path;
70 char *private_key_path;
71 char *private_key_passphrase;
74 connman_bool_t use_wps;
84 static const char *type2string(enum connman_network_type type)
87 case CONNMAN_NETWORK_TYPE_UNKNOWN:
88 case CONNMAN_NETWORK_TYPE_VENDOR:
90 case CONNMAN_NETWORK_TYPE_ETHERNET:
92 case CONNMAN_NETWORK_TYPE_WIFI:
94 case CONNMAN_NETWORK_TYPE_WIMAX:
96 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
97 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
99 case CONNMAN_NETWORK_TYPE_CELLULAR:
106 connman_bool_t __connman_network_has_driver(struct connman_network *network)
108 if (network == NULL || network->driver == NULL)
114 static gboolean match_driver(struct connman_network *network,
115 struct connman_network_driver *driver)
117 if (network->type == driver->type ||
118 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
124 static int network_probe(struct connman_network *network)
127 struct connman_network_driver *driver = NULL;
129 DBG("network %p name %s", network, network->name);
131 if (network->driver != NULL)
134 for (list = driver_list; list; list = list->next) {
137 if (match_driver(network, driver) == FALSE)
140 DBG("driver %p name %s", driver, driver->name);
142 if (driver->probe(network) == 0)
151 if (network->group == NULL)
154 switch (network->type) {
155 case CONNMAN_NETWORK_TYPE_UNKNOWN:
156 case CONNMAN_NETWORK_TYPE_VENDOR:
158 case CONNMAN_NETWORK_TYPE_ETHERNET:
159 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
160 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
161 case CONNMAN_NETWORK_TYPE_CELLULAR:
162 case CONNMAN_NETWORK_TYPE_WIFI:
163 case CONNMAN_NETWORK_TYPE_WIMAX:
164 network->driver = driver;
165 if (__connman_service_create_from_network(network) == NULL)
172 static void network_remove(struct connman_network *network)
174 DBG("network %p name %s", network, network->name);
176 if (network->driver == NULL)
179 switch (network->type) {
180 case CONNMAN_NETWORK_TYPE_UNKNOWN:
181 case CONNMAN_NETWORK_TYPE_VENDOR:
183 case CONNMAN_NETWORK_TYPE_ETHERNET:
184 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
185 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
186 case CONNMAN_NETWORK_TYPE_CELLULAR:
187 case CONNMAN_NETWORK_TYPE_WIFI:
188 case CONNMAN_NETWORK_TYPE_WIMAX:
189 if (network->group != NULL) {
190 __connman_service_remove_from_network(network);
192 g_free(network->group);
193 network->group = NULL;
198 if (network->driver->remove)
199 network->driver->remove(network);
201 network->driver = NULL;
204 static void network_change(struct connman_network *network)
206 DBG("network %p name %s", network, network->name);
208 if (network->connected == FALSE)
211 connman_network_unref(network);
213 connman_device_set_disconnected(network->device, TRUE);
215 if (network->driver && network->driver->disconnect) {
216 network->driver->disconnect(network);
220 network->connected = FALSE;
223 static void probe_driver(struct connman_network_driver *driver)
227 DBG("driver %p name %s", driver, driver->name);
229 for (list = network_list; list != NULL; list = list->next) {
230 struct connman_network *network = list->data;
232 if (network->driver != NULL)
235 if (driver->type != network->type)
238 if (driver->probe(network) < 0)
241 network->driver = driver;
245 static void remove_driver(struct connman_network_driver *driver)
249 DBG("driver %p name %s", driver, driver->name);
251 for (list = network_list; list != NULL; list = list->next) {
252 struct connman_network *network = list->data;
254 if (network->driver == driver)
255 network_remove(network);
259 static gint compare_priority(gconstpointer a, gconstpointer b)
261 const struct connman_network_driver *driver1 = a;
262 const struct connman_network_driver *driver2 = b;
264 return driver2->priority - driver1->priority;
268 * connman_network_driver_register:
269 * @driver: network driver definition
271 * Register a new network driver
273 * Returns: %0 on success
275 int connman_network_driver_register(struct connman_network_driver *driver)
279 DBG("driver %p name %s", driver, driver->name);
281 for (list = driver_list; list; list = list->next) {
282 struct connman_network_driver *tmp = list->data;
284 if (tmp->type == driver->type)
289 driver_list = g_slist_insert_sorted(driver_list, driver,
292 probe_driver(driver);
298 * connman_network_driver_unregister:
299 * @driver: network driver definition
301 * Remove a previously registered network driver
303 void connman_network_driver_unregister(struct connman_network_driver *driver)
305 DBG("driver %p name %s", driver, driver->name);
307 driver_list = g_slist_remove(driver_list, driver);
309 remove_driver(driver);
312 static void network_destruct(struct connman_network *network)
314 DBG("network %p name %s", network, network->name);
316 g_free(network->wifi.ssid);
317 g_free(network->wifi.mode);
318 g_free(network->wifi.security);
319 g_free(network->wifi.passphrase);
320 g_free(network->wifi.eap);
321 g_free(network->wifi.identity);
322 g_free(network->wifi.ca_cert_path);
323 g_free(network->wifi.client_cert_path);
324 g_free(network->wifi.private_key_path);
325 g_free(network->wifi.private_key_passphrase);
326 g_free(network->wifi.phase2_auth);
327 g_free(network->wifi.pin_wps);
329 g_free(network->path);
330 g_free(network->group);
331 g_free(network->node);
332 g_free(network->name);
333 g_free(network->identifier);
334 g_free(network->path);
336 network->device = NULL;
342 * connman_network_create:
343 * @identifier: network identifier (for example an unqiue name)
345 * Allocate a new network and assign the #identifier to it.
347 * Returns: a newly-allocated #connman_network structure
349 struct connman_network *connman_network_create(const char *identifier,
350 enum connman_network_type type)
352 struct connman_network *network;
355 DBG("identifier %s type %d", identifier, type);
357 network = g_try_new0(struct connman_network, 1);
361 DBG("network %p", network);
363 network->refcount = 1;
365 if (identifier == NULL) {
366 ident = g_strdup_printf("hidden_%d", hidden_counter++);
367 network->hidden = TRUE;
369 ident = g_strdup(identifier);
376 network->type = type;
377 network->identifier = ident;
379 network_list = g_slist_append(network_list, network);
385 * connman_network_ref:
386 * @network: network structure
388 * Increase reference counter of network
390 struct connman_network *connman_network_ref(struct connman_network *network)
392 DBG("network %p name %s refcount %d", network, network->name,
393 g_atomic_int_get(&network->refcount) + 1);
395 g_atomic_int_inc(&network->refcount);
401 * connman_network_unref:
402 * @network: network structure
404 * Decrease reference counter of network
406 void connman_network_unref(struct connman_network *network)
408 DBG("network %p name %s refcount %d", network, network->name,
409 g_atomic_int_get(&network->refcount) - 1);
411 if (g_atomic_int_dec_and_test(&network->refcount) == FALSE)
414 network_list = g_slist_remove(network_list, network);
416 network_destruct(network);
419 const char *__connman_network_get_type(struct connman_network *network)
421 return type2string(network->type);
425 * connman_network_get_type:
426 * @network: network structure
428 * Get type of network
430 enum connman_network_type connman_network_get_type(struct connman_network *network)
432 return network->type;
436 * connman_network_get_identifier:
437 * @network: network structure
439 * Get identifier of network
441 const char *connman_network_get_identifier(struct connman_network *network)
443 return network->identifier;
447 * connman_network_set_index:
448 * @network: network structure
449 * @index: index number
451 * Set index number of network
453 void connman_network_set_index(struct connman_network *network, int index)
455 struct connman_service *service;
456 struct connman_ipconfig *ipconfig;
458 service = __connman_service_lookup_from_network(network);
462 ipconfig = __connman_service_get_ip4config(service);
464 DBG("index %d service %p ip4config %p", network->index,
467 if (network->index < 0 && ipconfig == NULL) {
469 ipconfig = __connman_service_get_ip4config(service);
470 if (ipconfig == NULL)
472 * This is needed for plugins that havent set their
473 * ipconfig layer yet, due to not being able to get
474 * a network index prior to creating a service.
476 __connman_service_create_ip4config(service, index);
478 __connman_ipconfig_set_index(ipconfig, index);
481 /* If index changed, the index of ipconfig must be reset. */
482 if (ipconfig == NULL)
485 __connman_ipconfig_set_index(ipconfig, index);
489 network->index = index;
493 * connman_network_get_index:
494 * @network: network structure
496 * Get index number of network
498 int connman_network_get_index(struct connman_network *network)
500 return network->index;
504 * connman_network_set_group:
505 * @network: network structure
508 * Set group name for automatic clustering
510 void connman_network_set_group(struct connman_network *network,
513 switch (network->type) {
514 case CONNMAN_NETWORK_TYPE_UNKNOWN:
515 case CONNMAN_NETWORK_TYPE_VENDOR:
517 case CONNMAN_NETWORK_TYPE_ETHERNET:
518 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
519 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
520 case CONNMAN_NETWORK_TYPE_CELLULAR:
521 case CONNMAN_NETWORK_TYPE_WIFI:
522 case CONNMAN_NETWORK_TYPE_WIMAX:
526 if (g_strcmp0(network->group, group) == 0) {
528 __connman_service_update_from_network(network);
532 if (network->group != NULL) {
533 __connman_service_remove_from_network(network);
535 g_free(network->group);
538 network->group = g_strdup(group);
540 if (network->group != NULL)
541 network_probe(network);
545 * connman_network_get_group:
546 * @network: network structure
548 * Get group name for automatic clustering
550 const char *connman_network_get_group(struct connman_network *network)
552 return network->group;
555 const char *__connman_network_get_ident(struct connman_network *network)
557 if (network->device == NULL)
560 return connman_device_get_ident(network->device);
563 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
565 switch (network->type) {
566 case CONNMAN_NETWORK_TYPE_UNKNOWN:
567 case CONNMAN_NETWORK_TYPE_VENDOR:
568 case CONNMAN_NETWORK_TYPE_ETHERNET:
569 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
570 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
571 case CONNMAN_NETWORK_TYPE_CELLULAR:
572 case CONNMAN_NETWORK_TYPE_WIMAX:
574 case CONNMAN_NETWORK_TYPE_WIFI:
575 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
577 if (network->strength > 0 && network->strength < 20)
585 connman_bool_t connman_network_get_connecting(struct connman_network *network)
587 return network->connecting;
591 * connman_network_set_available:
592 * @network: network structure
593 * @available: availability state
595 * Change availability state of network (in range)
597 int connman_network_set_available(struct connman_network *network,
598 connman_bool_t available)
600 DBG("network %p available %d", network, available);
602 if (network->available == available)
605 network->available = available;
611 * connman_network_get_available:
612 * @network: network structure
614 * Get network available setting
616 connman_bool_t connman_network_get_available(struct connman_network *network)
618 if (network->hidden == TRUE)
621 return network->available;
625 * connman_network_set_associating:
626 * @network: network structure
627 * @associating: associating state
629 * Change associating state of network
631 int connman_network_set_associating(struct connman_network *network,
632 connman_bool_t associating)
634 DBG("network %p associating %d", network, associating);
636 if (network->associating == associating)
639 network->associating = associating;
641 if (associating == TRUE) {
642 struct connman_service *service;
644 service = __connman_service_lookup_from_network(network);
645 __connman_service_ipconfig_indicate_state(service,
646 CONNMAN_SERVICE_STATE_ASSOCIATION,
647 CONNMAN_IPCONFIG_TYPE_IPV4);
648 __connman_service_ipconfig_indicate_state(service,
649 CONNMAN_SERVICE_STATE_ASSOCIATION,
650 CONNMAN_IPCONFIG_TYPE_IPV6);
656 static void set_associate_error(struct connman_network *network)
658 struct connman_service *service;
660 if (network->associating == FALSE)
663 network->associating = FALSE;
665 service = __connman_service_lookup_from_network(network);
667 __connman_service_ipconfig_indicate_state(service,
668 CONNMAN_SERVICE_STATE_FAILURE,
669 CONNMAN_IPCONFIG_TYPE_IPV4);
672 static void set_configure_error(struct connman_network *network)
674 struct connman_service *service;
676 network->connecting = FALSE;
678 service = __connman_service_lookup_from_network(network);
680 __connman_service_ipconfig_indicate_state(service,
681 CONNMAN_SERVICE_STATE_FAILURE,
682 CONNMAN_IPCONFIG_TYPE_IPV4);
685 static void set_invalid_key_error(struct connman_network *network)
687 struct connman_service *service;
689 service = __connman_service_lookup_from_network(network);
691 __connman_service_indicate_error(service,
692 CONNMAN_SERVICE_ERROR_INVALID_KEY);
695 static void set_connect_error(struct connman_network *network)
697 struct connman_service *service;
699 service = __connman_service_lookup_from_network(network);
701 __connman_service_indicate_error(service,
702 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
705 void connman_network_set_ipv4_method(struct connman_network *network,
706 enum connman_ipconfig_method method)
708 struct connman_service *service;
709 struct connman_ipconfig *ipconfig;
711 service = __connman_service_lookup_from_network(network);
715 ipconfig = __connman_service_get_ip4config(service);
716 if (ipconfig == NULL)
719 connman_ipconfig_set_method(ipconfig, method);
722 void connman_network_set_ipv6_method(struct connman_network *network,
723 enum connman_ipconfig_method method)
725 struct connman_service *service;
726 struct connman_ipconfig *ipconfig;
728 service = __connman_service_lookup_from_network(network);
732 ipconfig = __connman_service_get_ip6config(service);
733 if (ipconfig == NULL)
736 connman_ipconfig_set_method(ipconfig, method);
739 void connman_network_set_error(struct connman_network *network,
740 enum connman_network_error error)
742 DBG("nework %p, error %d", network, error);
744 network->connecting = FALSE;
747 case CONNMAN_NETWORK_ERROR_UNKNOWN:
749 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
750 set_associate_error(network);
752 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
753 set_configure_error(network);
755 case CONNMAN_NETWORK_ERROR_INVALID_KEY:
756 set_invalid_key_error(network);
758 case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
759 set_connect_error(network);
763 network_change(network);
766 void connman_network_clear_error(struct connman_network *network)
768 struct connman_service *service;
770 DBG("network %p", network);
775 if (network->connecting == TRUE || network->associating == TRUE)
778 service = __connman_service_lookup_from_network(network);
779 __connman_service_clear_error(service);
782 static void set_configuration(struct connman_network *network)
784 struct connman_service *service;
786 DBG("network %p", network);
788 __connman_device_increase_connections(network->device);
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,
797 CONNMAN_IPCONFIG_TYPE_IPV4);
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);
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 set_configuration(network);
903 err = __connman_ipconfig_address_add(ipconfig);
907 err = __connman_ipconfig_gateway_add(ipconfig);
911 network->connecting = FALSE;
913 connman_network_set_associating(network, FALSE);
918 connman_network_set_error(network,
919 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
923 static int set_connected_dhcp(struct connman_network *network)
927 DBG("network %p", network);
929 set_configuration(network);
931 err = __connman_dhcp_start(network, dhcp_callback);
933 connman_error("Can not request DHCP lease");
940 static int manual_ipv6_set(struct connman_network *network,
941 struct connman_ipconfig *ipconfig_ipv6)
943 struct connman_service *service;
946 DBG("network %p ipv6 %p", network, ipconfig_ipv6);
948 service = __connman_service_lookup_from_network(network);
952 err = __connman_ipconfig_address_add(ipconfig_ipv6);
954 connman_network_set_error(network,
955 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
959 err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
963 __connman_connection_gateway_activate(service,
964 CONNMAN_IPCONFIG_TYPE_IPV6);
966 __connman_device_increase_connections(network->device);
968 __connman_device_set_network(network->device, network);
970 connman_device_set_disconnected(network->device, FALSE);
972 network->connecting = FALSE;
977 static void autoconf_ipv6_set(struct connman_network *network)
979 DBG("network %p", network);
981 __connman_device_increase_connections(network->device);
983 __connman_device_set_network(network->device, network);
985 connman_device_set_disconnected(network->device, FALSE);
987 /* XXX: Append IPv6 nameservers here */
989 network->connecting = FALSE;
992 static gboolean set_connected(gpointer user_data)
994 struct connman_network *network = user_data;
995 struct connman_service *service;
996 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
997 enum connman_ipconfig_method ipv4_method, ipv6_method;
999 service = __connman_service_lookup_from_network(network);
1001 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1002 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1004 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
1007 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
1008 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
1010 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
1011 DBG("network connected %d", network->connected);
1013 if (network->connected == TRUE) {
1016 switch (ipv6_method) {
1017 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1018 case CONNMAN_IPCONFIG_METHOD_OFF:
1020 case CONNMAN_IPCONFIG_METHOD_AUTO:
1021 autoconf_ipv6_set(network);
1023 case CONNMAN_IPCONFIG_METHOD_FIXED:
1024 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1025 ret = manual_ipv6_set(network, ipconfig_ipv6);
1027 connman_network_set_error(network,
1028 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1032 case CONNMAN_IPCONFIG_METHOD_DHCP:
1036 switch (ipv4_method) {
1037 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1038 case CONNMAN_IPCONFIG_METHOD_OFF:
1039 case CONNMAN_IPCONFIG_METHOD_AUTO:
1041 case CONNMAN_IPCONFIG_METHOD_FIXED:
1042 if (set_connected_fixed(network) < 0) {
1043 connman_network_set_error(network,
1044 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1048 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1049 set_connected_manual(network);
1051 case CONNMAN_IPCONFIG_METHOD_DHCP:
1052 if (set_connected_dhcp(network) < 0) {
1053 connman_network_set_error(network,
1054 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1060 struct connman_service *service;
1062 __connman_device_set_network(network->device, NULL);
1063 network->hidden = FALSE;
1065 service = __connman_service_lookup_from_network(network);
1067 switch (ipv4_method) {
1068 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1069 case CONNMAN_IPCONFIG_METHOD_OFF:
1070 case CONNMAN_IPCONFIG_METHOD_AUTO:
1071 case CONNMAN_IPCONFIG_METHOD_FIXED:
1072 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1074 case CONNMAN_IPCONFIG_METHOD_DHCP:
1075 __connman_dhcp_stop(network);
1079 __connman_service_ipconfig_indicate_state(service,
1080 CONNMAN_SERVICE_STATE_DISCONNECT,
1081 CONNMAN_IPCONFIG_TYPE_IPV4);
1083 __connman_service_ipconfig_indicate_state(service,
1084 CONNMAN_SERVICE_STATE_DISCONNECT,
1085 CONNMAN_IPCONFIG_TYPE_IPV6);
1087 __connman_connection_gateway_remove(service,
1088 CONNMAN_IPCONFIG_TYPE_ALL);
1090 __connman_ipconfig_address_unset(ipconfig_ipv4);
1091 __connman_ipconfig_address_unset(ipconfig_ipv6);
1094 * Special handling for IPv6 autoconfigured address.
1095 * The simplest way to remove autoconfigured routes is to
1096 * disable IPv6 temporarily so that kernel will do the cleanup
1099 if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
1100 __connman_ipconfig_disable_ipv6(ipconfig_ipv6);
1101 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
1104 __connman_service_ipconfig_indicate_state(service,
1105 CONNMAN_SERVICE_STATE_IDLE,
1106 CONNMAN_IPCONFIG_TYPE_IPV4);
1108 __connman_service_ipconfig_indicate_state(service,
1109 CONNMAN_SERVICE_STATE_IDLE,
1110 CONNMAN_IPCONFIG_TYPE_IPV6);
1113 network->connecting = FALSE;
1115 connman_network_set_associating(network, FALSE);
1121 * connman_network_set_connected:
1122 * @network: network structure
1123 * @connected: connected state
1125 * Change connected state of network
1127 int connman_network_set_connected(struct connman_network *network,
1128 connman_bool_t connected)
1130 DBG("network %p connected %d", network, connected);
1132 if ((network->connecting == TRUE || network->associating == TRUE) &&
1133 connected == FALSE) {
1134 connman_network_set_error(network,
1135 CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
1136 __connman_network_disconnect(network);
1139 if (network->connected == connected)
1142 if (connected == FALSE)
1143 __connman_device_decrease_connections(network->device);
1145 network->connected = connected;
1147 set_connected(network);
1153 * connman_network_get_connected:
1154 * @network: network structure
1156 * Get network connection status
1158 connman_bool_t connman_network_get_connected(struct connman_network *network)
1160 return network->connected;
1164 * connman_network_get_associating:
1165 * @network: network structure
1167 * Get network associating status
1169 connman_bool_t connman_network_get_associating(struct connman_network *network)
1171 return network->associating;
1175 * __connman_network_connect:
1176 * @network: network structure
1180 int __connman_network_connect(struct connman_network *network)
1184 DBG("network %p", network);
1186 if (network->connected == TRUE)
1189 if (network->connecting == TRUE || network->associating == TRUE)
1192 if (network->driver == NULL)
1195 if (network->driver->connect == NULL)
1198 if (network->device == NULL)
1201 network->connecting = TRUE;
1203 __connman_device_disconnect(network->device);
1205 err = network->driver->connect(network);
1207 if (err == -EINPROGRESS)
1208 connman_network_set_associating(network, TRUE);
1210 network->connecting = FALSE;
1211 network->hidden = FALSE;
1217 network->connected = TRUE;
1218 set_connected(network);
1224 * __connman_network_disconnect:
1225 * @network: network structure
1227 * Disconnect network
1229 int __connman_network_disconnect(struct connman_network *network)
1233 DBG("network %p", network);
1235 if (network->connected == FALSE && network->connecting == FALSE &&
1236 network->associating == FALSE)
1239 if (network->driver == NULL)
1242 if (network->driver->disconnect == NULL)
1245 network->connecting = FALSE;
1247 err = network->driver->disconnect(network);
1249 connman_network_set_connected(network, FALSE);
1250 set_connected(network);
1256 static int manual_ipv4_set(struct connman_network *network,
1257 struct connman_ipconfig *ipconfig)
1259 struct connman_service *service;
1262 service = __connman_service_lookup_from_network(network);
1263 if (service == NULL)
1266 err = __connman_ipconfig_address_add(ipconfig);
1268 connman_network_set_error(network,
1269 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1273 return __connman_ipconfig_gateway_add(ipconfig);
1276 int __connman_network_clear_ipconfig(struct connman_network *network,
1277 struct connman_ipconfig *ipconfig)
1279 struct connman_service *service;
1280 enum connman_ipconfig_method method;
1281 enum connman_ipconfig_type type;
1283 service = __connman_service_lookup_from_network(network);
1284 if (service == NULL)
1287 method = __connman_ipconfig_get_method(ipconfig);
1288 type = __connman_ipconfig_get_config_type(ipconfig);
1291 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1292 case CONNMAN_IPCONFIG_METHOD_OFF:
1293 case CONNMAN_IPCONFIG_METHOD_FIXED:
1294 case CONNMAN_IPCONFIG_METHOD_AUTO:
1296 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1297 __connman_ipconfig_address_remove(ipconfig);
1299 case CONNMAN_IPCONFIG_METHOD_DHCP:
1300 __connman_dhcp_stop(network);
1304 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1305 __connman_service_ipconfig_indicate_state(service,
1306 CONNMAN_SERVICE_STATE_CONFIGURATION,
1307 CONNMAN_IPCONFIG_TYPE_IPV6);
1308 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1309 __connman_service_ipconfig_indicate_state(service,
1310 CONNMAN_SERVICE_STATE_CONFIGURATION,
1311 CONNMAN_IPCONFIG_TYPE_IPV4);
1316 int __connman_network_set_ipconfig(struct connman_network *network,
1317 struct connman_ipconfig *ipconfig_ipv4,
1318 struct connman_ipconfig *ipconfig_ipv6)
1320 enum connman_ipconfig_method method;
1323 if (ipconfig_ipv6) {
1324 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1327 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1328 case CONNMAN_IPCONFIG_METHOD_OFF:
1330 case CONNMAN_IPCONFIG_METHOD_AUTO:
1331 autoconf_ipv6_set(network);
1333 case CONNMAN_IPCONFIG_METHOD_FIXED:
1334 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1335 ret = manual_ipv6_set(network, ipconfig_ipv6);
1337 connman_network_set_error(network,
1338 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1342 case CONNMAN_IPCONFIG_METHOD_DHCP:
1347 if (ipconfig_ipv4) {
1348 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1351 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1352 case CONNMAN_IPCONFIG_METHOD_OFF:
1353 case CONNMAN_IPCONFIG_METHOD_FIXED:
1354 case CONNMAN_IPCONFIG_METHOD_AUTO:
1356 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1357 return manual_ipv4_set(network, ipconfig_ipv4);
1358 case CONNMAN_IPCONFIG_METHOD_DHCP:
1359 return __connman_dhcp_start(network, dhcp_callback);
1366 int connman_network_set_ipaddress(struct connman_network *network,
1367 struct connman_ipaddress *ipaddress)
1369 struct connman_service *service;
1370 struct connman_ipconfig *ipconfig = NULL;
1372 DBG("network %p", network);
1374 service = __connman_service_lookup_from_network(network);
1375 if (service == NULL)
1378 ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
1379 if (ipconfig == NULL)
1382 __connman_ipconfig_set_local(ipconfig, ipaddress->local);
1383 __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
1384 __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
1385 __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
1386 __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
1391 int connman_network_set_pac(struct connman_network *network,
1394 struct connman_service *service;
1396 DBG("network %p pac %s", network, pac);
1398 service = __connman_service_lookup_from_network(network);
1399 if (service == NULL)
1402 __connman_service_set_pac(service, pac);
1407 int connman_network_set_nameservers(struct connman_network *network,
1408 const char *nameservers)
1410 struct connman_service *service;
1411 char **nameservers_array = NULL;
1414 DBG("network %p nameservers %s", network, nameservers);
1416 service = __connman_service_lookup_from_network(network);
1417 if (service == NULL)
1420 __connman_service_nameserver_clear(service);
1422 if (nameservers != NULL)
1423 nameservers_array = g_strsplit(nameservers, " ", 0);
1425 for (i = 0; nameservers_array[i] != NULL; i++) {
1426 __connman_service_nameserver_append(service,
1427 nameservers_array[i]);
1430 g_strfreev(nameservers_array);
1435 int connman_network_set_domain(struct connman_network *network,
1438 struct connman_service *service;
1440 DBG("network %p domain %s", network, domain);
1442 service = __connman_service_lookup_from_network(network);
1443 if (service == NULL)
1446 __connman_service_set_domainname(service, domain);
1452 * connman_network_set_name:
1453 * @network: network structure
1456 * Set display name value for network
1458 int connman_network_set_name(struct connman_network *network,
1461 DBG("network %p name %s", network, name);
1463 g_free(network->name);
1464 network->name = g_strdup(name);
1470 * connman_network_set_strength:
1471 * @network: network structure
1472 * @strength: strength value
1474 * Set signal strength value for network
1477 int connman_network_set_strength(struct connman_network *network,
1478 connman_uint8_t strength)
1480 DBG("network %p strengh %d", network, strength);
1482 network->strength = strength;
1487 connman_uint8_t connman_network_get_strength(struct connman_network *network)
1489 return network->strength;
1492 int connman_network_set_frequency(struct connman_network *network,
1493 connman_uint16_t frequency)
1495 DBG("network %p frequency %d", network, frequency);
1497 network->frequency = frequency;
1502 connman_uint16_t connman_network_get_frequency(struct connman_network *network)
1504 return network->frequency;
1507 int connman_network_set_wifi_channel(struct connman_network *network,
1508 connman_uint16_t channel)
1510 DBG("network %p wifi channel %d", network, channel);
1512 network->wifi.channel = channel;
1517 connman_uint16_t connman_network_get_wifi_channel(struct connman_network *network)
1519 return network->wifi.channel;
1523 * connman_network_set_roaming:
1524 * @network: network structure
1525 * @roaming: roaming state
1527 * Set roaming state for network
1529 int connman_network_set_roaming(struct connman_network *network,
1530 connman_bool_t roaming)
1532 DBG("network %p roaming %d", network, roaming);
1534 network->roaming = roaming;
1540 * connman_network_set_string:
1541 * @network: network structure
1542 * @key: unique identifier
1543 * @value: string value
1545 * Set string value for specific key
1547 int connman_network_set_string(struct connman_network *network,
1548 const char *key, const char *value)
1550 DBG("network %p key %s value %s", network, key, value);
1552 if (g_strcmp0(key, "Name") == 0)
1553 return connman_network_set_name(network, value);
1555 if (g_str_equal(key, "Path") == TRUE) {
1556 g_free(network->path);
1557 network->path = g_strdup(value);
1558 } else if (g_str_equal(key, "Node") == TRUE) {
1559 g_free(network->node);
1560 network->node = g_strdup(value);
1561 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1562 g_free(network->wifi.mode);
1563 network->wifi.mode = g_strdup(value);
1564 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1565 g_free(network->wifi.security);
1566 network->wifi.security = g_strdup(value);
1567 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1568 g_free(network->wifi.passphrase);
1569 network->wifi.passphrase = g_strdup(value);
1570 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1571 g_free(network->wifi.eap);
1572 network->wifi.eap = g_strdup(value);
1573 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1574 g_free(network->wifi.identity);
1575 network->wifi.identity = g_strdup(value);
1576 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1577 g_free(network->wifi.ca_cert_path);
1578 network->wifi.ca_cert_path = g_strdup(value);
1579 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1580 g_free(network->wifi.client_cert_path);
1581 network->wifi.client_cert_path = g_strdup(value);
1582 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1583 g_free(network->wifi.private_key_path);
1584 network->wifi.private_key_path = g_strdup(value);
1585 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1586 g_free(network->wifi.private_key_passphrase);
1587 network->wifi.private_key_passphrase = g_strdup(value);
1588 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1589 g_free(network->wifi.phase2_auth);
1590 network->wifi.phase2_auth = g_strdup(value);
1591 } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
1592 g_free(network->wifi.pin_wps);
1593 network->wifi.pin_wps = g_strdup(value);
1602 * connman_network_get_string:
1603 * @network: network structure
1604 * @key: unique identifier
1606 * Get string value for specific key
1608 const char *connman_network_get_string(struct connman_network *network,
1611 DBG("network %p key %s", network, key);
1613 if (g_str_equal(key, "Path") == TRUE)
1614 return network->path;
1615 else if (g_str_equal(key, "Name") == TRUE)
1616 return network->name;
1617 else if (g_str_equal(key, "Node") == TRUE)
1618 return network->node;
1619 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1620 return network->wifi.mode;
1621 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1622 return network->wifi.security;
1623 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1624 return network->wifi.passphrase;
1625 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1626 return network->wifi.eap;
1627 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1628 return network->wifi.identity;
1629 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1630 return network->wifi.ca_cert_path;
1631 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1632 return network->wifi.client_cert_path;
1633 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1634 return network->wifi.private_key_path;
1635 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1636 return network->wifi.private_key_passphrase;
1637 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1638 return network->wifi.phase2_auth;
1639 else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
1640 return network->wifi.pin_wps;
1646 * connman_network_set_bool:
1647 * @network: network structure
1648 * @key: unique identifier
1649 * @value: boolean value
1651 * Set boolean value for specific key
1653 int connman_network_set_bool(struct connman_network *network,
1654 const char *key, connman_bool_t value)
1656 DBG("network %p key %s value %d", network, key, value);
1658 if (g_strcmp0(key, "Roaming") == 0)
1659 return connman_network_set_roaming(network, value);
1660 else if (g_strcmp0(key, "WiFi.WPS") == 0)
1661 network->wifi.wps = value;
1662 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
1663 network->wifi.use_wps = value;
1669 * connman_network_get_bool:
1670 * @network: network structure
1671 * @key: unique identifier
1673 * Get boolean value for specific key
1675 connman_bool_t connman_network_get_bool(struct connman_network *network,
1678 DBG("network %p key %s", network, key);
1680 if (g_str_equal(key, "Roaming") == TRUE)
1681 return network->roaming;
1682 else if (g_str_equal(key, "WiFi.WPS") == TRUE)
1683 return network->wifi.wps;
1684 else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
1685 return network->wifi.use_wps;
1691 * connman_network_set_blob:
1692 * @network: network structure
1693 * @key: unique identifier
1697 * Set binary blob value for specific key
1699 int connman_network_set_blob(struct connman_network *network,
1700 const char *key, const void *data, unsigned int size)
1702 DBG("network %p key %s size %d", network, key, size);
1704 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1705 g_free(network->wifi.ssid);
1706 network->wifi.ssid = g_try_malloc(size);
1707 if (network->wifi.ssid != NULL) {
1708 memcpy(network->wifi.ssid, data, size);
1709 network->wifi.ssid_len = size;
1711 network->wifi.ssid_len = 0;
1720 * connman_network_get_blob:
1721 * @network: network structure
1722 * @key: unique identifier
1723 * @size: pointer to blob size
1725 * Get binary blob value for specific key
1727 const void *connman_network_get_blob(struct connman_network *network,
1728 const char *key, unsigned int *size)
1730 DBG("network %p key %s", network, key);
1732 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1734 *size = network->wifi.ssid_len;
1735 return network->wifi.ssid;
1741 void __connman_network_set_device(struct connman_network *network,
1742 struct connman_device *device)
1744 if (network->device == device)
1747 if (network->device != NULL)
1748 network_remove(network);
1750 network->device = device;
1752 if (network->device != NULL)
1753 network_probe(network);
1757 * connman_network_get_device:
1758 * @network: network structure
1760 * Get parent device of network
1762 struct connman_device *connman_network_get_device(struct connman_network *network)
1764 return network->device;
1768 * connman_network_get_data:
1769 * @network: network structure
1771 * Get private network data pointer
1773 void *connman_network_get_data(struct connman_network *network)
1775 return network->driver_data;
1779 * connman_network_set_data:
1780 * @network: network structure
1781 * @data: data pointer
1783 * Set private network data pointer
1785 void connman_network_set_data(struct connman_network *network, void *data)
1787 network->driver_data = data;
1790 void connman_network_update(struct connman_network *network)
1792 switch (network->type) {
1793 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1794 case CONNMAN_NETWORK_TYPE_VENDOR:
1796 case CONNMAN_NETWORK_TYPE_ETHERNET:
1797 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1798 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1799 case CONNMAN_NETWORK_TYPE_CELLULAR:
1800 case CONNMAN_NETWORK_TYPE_WIFI:
1801 case CONNMAN_NETWORK_TYPE_WIMAX:
1805 if (network->group != NULL)
1806 __connman_service_update_from_network(network);
1809 int __connman_network_init(void)
1816 void __connman_network_cleanup(void)