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_device_set_disconnected(network->device, TRUE);
213 if (network->driver && network->driver->disconnect) {
214 network->driver->disconnect(network);
218 network->connected = FALSE;
221 static void probe_driver(struct connman_network_driver *driver)
225 DBG("driver %p name %s", driver, driver->name);
227 for (list = network_list; list != NULL; list = list->next) {
228 struct connman_network *network = list->data;
230 if (network->driver != NULL)
233 if (driver->type != network->type)
236 if (driver->probe(network) < 0)
239 network->driver = driver;
243 static void remove_driver(struct connman_network_driver *driver)
247 DBG("driver %p name %s", driver, driver->name);
249 for (list = network_list; list != NULL; list = list->next) {
250 struct connman_network *network = list->data;
252 if (network->driver == driver)
253 network_remove(network);
257 static gint compare_priority(gconstpointer a, gconstpointer b)
259 const struct connman_network_driver *driver1 = a;
260 const struct connman_network_driver *driver2 = b;
262 return driver2->priority - driver1->priority;
266 * connman_network_driver_register:
267 * @driver: network driver definition
269 * Register a new network driver
271 * Returns: %0 on success
273 int connman_network_driver_register(struct connman_network_driver *driver)
277 DBG("driver %p name %s", driver, driver->name);
279 for (list = driver_list; list; list = list->next) {
280 struct connman_network_driver *tmp = list->data;
282 if (tmp->type == driver->type)
287 driver_list = g_slist_insert_sorted(driver_list, driver,
290 probe_driver(driver);
296 * connman_network_driver_unregister:
297 * @driver: network driver definition
299 * Remove a previously registered network driver
301 void connman_network_driver_unregister(struct connman_network_driver *driver)
303 DBG("driver %p name %s", driver, driver->name);
305 driver_list = g_slist_remove(driver_list, driver);
307 remove_driver(driver);
310 static void network_destruct(struct connman_network *network)
312 DBG("network %p name %s", network, network->name);
314 g_free(network->wifi.ssid);
315 g_free(network->wifi.mode);
316 g_free(network->wifi.security);
317 g_free(network->wifi.passphrase);
318 g_free(network->wifi.eap);
319 g_free(network->wifi.identity);
320 g_free(network->wifi.ca_cert_path);
321 g_free(network->wifi.client_cert_path);
322 g_free(network->wifi.private_key_path);
323 g_free(network->wifi.private_key_passphrase);
324 g_free(network->wifi.phase2_auth);
325 g_free(network->wifi.pin_wps);
327 g_free(network->path);
328 g_free(network->group);
329 g_free(network->node);
330 g_free(network->name);
331 g_free(network->identifier);
332 g_free(network->path);
334 network->device = NULL;
340 * connman_network_create:
341 * @identifier: network identifier (for example an unqiue name)
343 * Allocate a new network and assign the #identifier to it.
345 * Returns: a newly-allocated #connman_network structure
347 struct connman_network *connman_network_create(const char *identifier,
348 enum connman_network_type type)
350 struct connman_network *network;
353 DBG("identifier %s type %d", identifier, type);
355 network = g_try_new0(struct connman_network, 1);
359 DBG("network %p", network);
361 network->refcount = 1;
363 if (identifier == NULL) {
364 ident = g_strdup_printf("hidden_%d", hidden_counter++);
365 network->hidden = TRUE;
367 ident = g_strdup(identifier);
374 network->type = type;
375 network->identifier = ident;
377 network_list = g_slist_append(network_list, network);
383 * connman_network_ref:
384 * @network: network structure
386 * Increase reference counter of network
388 struct connman_network *connman_network_ref(struct connman_network *network)
390 DBG("network %p name %s refcount %d", network, network->name,
391 g_atomic_int_get(&network->refcount) + 1);
393 g_atomic_int_inc(&network->refcount);
399 * connman_network_unref:
400 * @network: network structure
402 * Decrease reference counter of network
404 void connman_network_unref(struct connman_network *network)
406 DBG("network %p name %s refcount %d", network, network->name,
407 g_atomic_int_get(&network->refcount) - 1);
409 if (g_atomic_int_dec_and_test(&network->refcount) == FALSE)
412 network_list = g_slist_remove(network_list, network);
414 network_destruct(network);
417 const char *__connman_network_get_type(struct connman_network *network)
419 return type2string(network->type);
423 * connman_network_get_type:
424 * @network: network structure
426 * Get type of network
428 enum connman_network_type connman_network_get_type(struct connman_network *network)
430 return network->type;
434 * connman_network_get_identifier:
435 * @network: network structure
437 * Get identifier of network
439 const char *connman_network_get_identifier(struct connman_network *network)
441 return network->identifier;
445 * connman_network_set_index:
446 * @network: network structure
447 * @index: index number
449 * Set index number of network
451 void connman_network_set_index(struct connman_network *network, int index)
453 struct connman_service *service;
454 struct connman_ipconfig *ipconfig;
456 service = __connman_service_lookup_from_network(network);
460 ipconfig = __connman_service_get_ip4config(service);
462 DBG("index %d service %p ip4config %p", network->index,
465 if (network->index < 0 && ipconfig == NULL) {
467 ipconfig = __connman_service_get_ip4config(service);
468 if (ipconfig == NULL)
470 * This is needed for plugins that havent set their
471 * ipconfig layer yet, due to not being able to get
472 * a network index prior to creating a service.
474 __connman_service_create_ip4config(service, index);
476 __connman_ipconfig_set_index(ipconfig, index);
479 /* If index changed, the index of ipconfig must be reset. */
480 if (ipconfig == NULL)
483 __connman_ipconfig_set_index(ipconfig, index);
487 network->index = index;
491 * connman_network_get_index:
492 * @network: network structure
494 * Get index number of network
496 int connman_network_get_index(struct connman_network *network)
498 return network->index;
502 * connman_network_set_group:
503 * @network: network structure
506 * Set group name for automatic clustering
508 void connman_network_set_group(struct connman_network *network,
511 switch (network->type) {
512 case CONNMAN_NETWORK_TYPE_UNKNOWN:
513 case CONNMAN_NETWORK_TYPE_VENDOR:
515 case CONNMAN_NETWORK_TYPE_ETHERNET:
516 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
517 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
518 case CONNMAN_NETWORK_TYPE_CELLULAR:
519 case CONNMAN_NETWORK_TYPE_WIFI:
520 case CONNMAN_NETWORK_TYPE_WIMAX:
524 if (g_strcmp0(network->group, group) == 0) {
526 __connman_service_update_from_network(network);
530 if (network->group != NULL) {
531 __connman_service_remove_from_network(network);
533 g_free(network->group);
536 network->group = g_strdup(group);
538 if (network->group != NULL)
539 network_probe(network);
543 * connman_network_get_group:
544 * @network: network structure
546 * Get group name for automatic clustering
548 const char *connman_network_get_group(struct connman_network *network)
550 return network->group;
553 const char *__connman_network_get_ident(struct connman_network *network)
555 if (network->device == NULL)
558 return connman_device_get_ident(network->device);
561 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
563 switch (network->type) {
564 case CONNMAN_NETWORK_TYPE_UNKNOWN:
565 case CONNMAN_NETWORK_TYPE_VENDOR:
566 case CONNMAN_NETWORK_TYPE_ETHERNET:
567 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
568 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
569 case CONNMAN_NETWORK_TYPE_CELLULAR:
570 case CONNMAN_NETWORK_TYPE_WIMAX:
572 case CONNMAN_NETWORK_TYPE_WIFI:
573 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
575 if (network->strength > 0 && network->strength < 20)
583 connman_bool_t connman_network_get_connecting(struct connman_network *network)
585 return network->connecting;
589 * connman_network_set_available:
590 * @network: network structure
591 * @available: availability state
593 * Change availability state of network (in range)
595 int connman_network_set_available(struct connman_network *network,
596 connman_bool_t available)
598 DBG("network %p available %d", network, available);
600 if (network->available == available)
603 network->available = available;
609 * connman_network_get_available:
610 * @network: network structure
612 * Get network available setting
614 connman_bool_t connman_network_get_available(struct connman_network *network)
616 if (network->hidden == TRUE)
619 return network->available;
623 * connman_network_set_associating:
624 * @network: network structure
625 * @associating: associating state
627 * Change associating state of network
629 int connman_network_set_associating(struct connman_network *network,
630 connman_bool_t associating)
632 DBG("network %p associating %d", network, associating);
634 if (network->associating == associating)
637 network->associating = associating;
639 if (associating == TRUE) {
640 struct connman_service *service;
642 service = __connman_service_lookup_from_network(network);
643 __connman_service_ipconfig_indicate_state(service,
644 CONNMAN_SERVICE_STATE_ASSOCIATION,
645 CONNMAN_IPCONFIG_TYPE_IPV4);
646 __connman_service_ipconfig_indicate_state(service,
647 CONNMAN_SERVICE_STATE_ASSOCIATION,
648 CONNMAN_IPCONFIG_TYPE_IPV6);
654 static void set_associate_error(struct connman_network *network)
656 struct connman_service *service;
658 if (network->associating == FALSE)
661 network->associating = FALSE;
663 service = __connman_service_lookup_from_network(network);
665 __connman_service_ipconfig_indicate_state(service,
666 CONNMAN_SERVICE_STATE_FAILURE,
667 CONNMAN_IPCONFIG_TYPE_IPV4);
670 static void set_configure_error(struct connman_network *network)
672 struct connman_service *service;
674 network->connecting = FALSE;
676 service = __connman_service_lookup_from_network(network);
678 __connman_service_ipconfig_indicate_state(service,
679 CONNMAN_SERVICE_STATE_FAILURE,
680 CONNMAN_IPCONFIG_TYPE_IPV4);
683 static void set_invalid_key_error(struct connman_network *network)
685 struct connman_service *service;
687 service = __connman_service_lookup_from_network(network);
689 __connman_service_indicate_error(service,
690 CONNMAN_SERVICE_ERROR_INVALID_KEY);
693 static void set_connect_error(struct connman_network *network)
695 struct connman_service *service;
697 service = __connman_service_lookup_from_network(network);
699 __connman_service_indicate_error(service,
700 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
703 void connman_network_set_ipv4_method(struct connman_network *network,
704 enum connman_ipconfig_method method)
706 struct connman_service *service;
707 struct connman_ipconfig *ipconfig;
709 service = __connman_service_lookup_from_network(network);
713 ipconfig = __connman_service_get_ip4config(service);
714 if (ipconfig == NULL)
717 connman_ipconfig_set_method(ipconfig, method);
720 void connman_network_set_ipv6_method(struct connman_network *network,
721 enum connman_ipconfig_method method)
723 struct connman_service *service;
724 struct connman_ipconfig *ipconfig;
726 service = __connman_service_lookup_from_network(network);
730 ipconfig = __connman_service_get_ip6config(service);
731 if (ipconfig == NULL)
734 connman_ipconfig_set_method(ipconfig, method);
737 void connman_network_set_error(struct connman_network *network,
738 enum connman_network_error error)
740 DBG("nework %p, error %d", network, error);
742 network->connecting = 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)
782 struct connman_service *service;
784 DBG("network %p", network);
786 __connman_device_increase_connections(network->device);
788 __connman_device_set_network(network->device, network);
790 connman_device_set_disconnected(network->device, FALSE);
792 service = __connman_service_lookup_from_network(network);
793 __connman_service_ipconfig_indicate_state(service,
794 CONNMAN_SERVICE_STATE_CONFIGURATION,
795 CONNMAN_IPCONFIG_TYPE_IPV4);
798 static void dhcp_success(struct connman_network *network)
800 struct connman_service *service;
801 struct connman_ipconfig *ipconfig_ipv4;
804 service = __connman_service_lookup_from_network(network);
808 connman_network_set_associating(network, FALSE);
810 network->connecting = FALSE;
812 ipconfig_ipv4 = __connman_service_get_ip4config(service);
813 err = __connman_ipconfig_address_add(ipconfig_ipv4);
817 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
824 connman_network_set_error(network,
825 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
828 static void dhcp_failure(struct connman_network *network)
830 struct connman_service *service;
832 service = __connman_service_lookup_from_network(network);
836 __connman_service_ipconfig_indicate_state(service,
837 CONNMAN_SERVICE_STATE_IDLE,
838 CONNMAN_IPCONFIG_TYPE_IPV4);
841 static void dhcp_callback(struct connman_network *network,
842 connman_bool_t success)
844 DBG("success %d", success);
847 dhcp_success(network);
849 dhcp_failure(network);
852 static int set_connected_fixed(struct connman_network *network)
854 struct connman_service *service;
855 struct connman_ipconfig *ipconfig_ipv4;
860 service = __connman_service_lookup_from_network(network);
862 ipconfig_ipv4 = __connman_service_get_ip4config(service);
864 set_configuration(network);
866 network->connecting = FALSE;
868 connman_network_set_associating(network, FALSE);
870 err = __connman_ipconfig_address_add(ipconfig_ipv4);
874 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
881 connman_network_set_error(network,
882 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
887 static void set_connected_manual(struct connman_network *network)
889 struct connman_service *service;
890 struct connman_ipconfig *ipconfig;
893 DBG("network %p", network);
895 service = __connman_service_lookup_from_network(network);
897 ipconfig = __connman_service_get_ip4config(service);
899 set_configuration(network);
901 err = __connman_ipconfig_address_add(ipconfig);
905 err = __connman_ipconfig_gateway_add(ipconfig);
909 network->connecting = FALSE;
911 connman_network_set_associating(network, FALSE);
916 connman_network_set_error(network,
917 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
921 static int set_connected_dhcp(struct connman_network *network)
925 DBG("network %p", network);
927 set_configuration(network);
929 err = __connman_dhcp_start(network, dhcp_callback);
931 connman_error("Can not request DHCP lease");
938 static int manual_ipv6_set(struct connman_network *network,
939 struct connman_ipconfig *ipconfig_ipv6)
941 struct connman_service *service;
944 DBG("network %p ipv6 %p", network, ipconfig_ipv6);
946 service = __connman_service_lookup_from_network(network);
950 err = __connman_ipconfig_address_add(ipconfig_ipv6);
952 connman_network_set_error(network,
953 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
957 err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
961 __connman_connection_gateway_activate(service,
962 CONNMAN_IPCONFIG_TYPE_IPV6);
964 __connman_device_increase_connections(network->device);
966 __connman_device_set_network(network->device, network);
968 connman_device_set_disconnected(network->device, FALSE);
970 network->connecting = FALSE;
975 static void autoconf_ipv6_set(struct connman_network *network)
977 DBG("network %p", network);
979 __connman_device_increase_connections(network->device);
981 __connman_device_set_network(network->device, network);
983 connman_device_set_disconnected(network->device, FALSE);
985 /* XXX: Append IPv6 nameservers here */
987 network->connecting = FALSE;
990 static gboolean set_connected(gpointer user_data)
992 struct connman_network *network = user_data;
993 struct connman_service *service;
994 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
995 enum connman_ipconfig_method ipv4_method, ipv6_method;
997 service = __connman_service_lookup_from_network(network);
999 ipconfig_ipv4 = __connman_service_get_ip4config(service);
1000 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1002 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
1005 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
1006 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
1008 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
1009 DBG("network connected %d", network->connected);
1011 if (network->connected == TRUE) {
1014 switch (ipv6_method) {
1015 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1016 case CONNMAN_IPCONFIG_METHOD_OFF:
1018 case CONNMAN_IPCONFIG_METHOD_AUTO:
1019 autoconf_ipv6_set(network);
1021 case CONNMAN_IPCONFIG_METHOD_FIXED:
1022 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1023 ret = manual_ipv6_set(network, ipconfig_ipv6);
1025 connman_network_set_error(network,
1026 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1030 case CONNMAN_IPCONFIG_METHOD_DHCP:
1034 switch (ipv4_method) {
1035 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1036 case CONNMAN_IPCONFIG_METHOD_OFF:
1037 case CONNMAN_IPCONFIG_METHOD_AUTO:
1039 case CONNMAN_IPCONFIG_METHOD_FIXED:
1040 if (set_connected_fixed(network) < 0) {
1041 connman_network_set_error(network,
1042 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1046 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1047 set_connected_manual(network);
1049 case CONNMAN_IPCONFIG_METHOD_DHCP:
1050 if (set_connected_dhcp(network) < 0) {
1051 connman_network_set_error(network,
1052 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1058 struct connman_service *service;
1060 __connman_device_set_network(network->device, NULL);
1061 network->hidden = FALSE;
1063 service = __connman_service_lookup_from_network(network);
1065 switch (ipv4_method) {
1066 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1067 case CONNMAN_IPCONFIG_METHOD_OFF:
1068 case CONNMAN_IPCONFIG_METHOD_AUTO:
1069 case CONNMAN_IPCONFIG_METHOD_FIXED:
1070 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1072 case CONNMAN_IPCONFIG_METHOD_DHCP:
1073 __connman_dhcp_stop(network);
1077 __connman_service_ipconfig_indicate_state(service,
1078 CONNMAN_SERVICE_STATE_DISCONNECT,
1079 CONNMAN_IPCONFIG_TYPE_IPV4);
1081 __connman_service_ipconfig_indicate_state(service,
1082 CONNMAN_SERVICE_STATE_DISCONNECT,
1083 CONNMAN_IPCONFIG_TYPE_IPV6);
1085 __connman_connection_gateway_remove(service,
1086 CONNMAN_IPCONFIG_TYPE_ALL);
1088 __connman_ipconfig_address_unset(ipconfig_ipv4);
1089 __connman_ipconfig_address_unset(ipconfig_ipv6);
1092 * Special handling for IPv6 autoconfigured address.
1093 * The simplest way to remove autoconfigured routes is to
1094 * disable IPv6 temporarily so that kernel will do the cleanup
1097 if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
1098 __connman_ipconfig_disable_ipv6(ipconfig_ipv6);
1099 __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
1102 __connman_service_ipconfig_indicate_state(service,
1103 CONNMAN_SERVICE_STATE_IDLE,
1104 CONNMAN_IPCONFIG_TYPE_IPV4);
1106 __connman_service_ipconfig_indicate_state(service,
1107 CONNMAN_SERVICE_STATE_IDLE,
1108 CONNMAN_IPCONFIG_TYPE_IPV6);
1111 network->connecting = FALSE;
1113 connman_network_set_associating(network, FALSE);
1119 * connman_network_set_connected:
1120 * @network: network structure
1121 * @connected: connected state
1123 * Change connected state of network
1125 int connman_network_set_connected(struct connman_network *network,
1126 connman_bool_t connected)
1128 DBG("network %p connected %d", network, connected);
1130 if ((network->connecting == TRUE || network->associating == TRUE) &&
1131 connected == FALSE) {
1132 connman_network_set_error(network,
1133 CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
1134 __connman_network_disconnect(network);
1137 if (network->connected == connected)
1140 if (connected == FALSE)
1141 __connman_device_decrease_connections(network->device);
1143 network->connected = connected;
1145 set_connected(network);
1151 * connman_network_get_connected:
1152 * @network: network structure
1154 * Get network connection status
1156 connman_bool_t connman_network_get_connected(struct connman_network *network)
1158 return network->connected;
1162 * connman_network_get_associating:
1163 * @network: network structure
1165 * Get network associating status
1167 connman_bool_t connman_network_get_associating(struct connman_network *network)
1169 return network->associating;
1173 * __connman_network_connect:
1174 * @network: network structure
1178 int __connman_network_connect(struct connman_network *network)
1182 DBG("network %p", network);
1184 if (network->connected == TRUE)
1187 if (network->connecting == TRUE || network->associating == TRUE)
1190 if (network->driver == NULL)
1193 if (network->driver->connect == NULL)
1196 if (network->device == NULL)
1199 network->connecting = TRUE;
1201 __connman_device_disconnect(network->device);
1203 err = network->driver->connect(network);
1205 if (err == -EINPROGRESS)
1206 connman_network_set_associating(network, TRUE);
1208 network->connecting = FALSE;
1209 network->hidden = FALSE;
1215 network->connected = TRUE;
1216 set_connected(network);
1222 * __connman_network_disconnect:
1223 * @network: network structure
1225 * Disconnect network
1227 int __connman_network_disconnect(struct connman_network *network)
1231 DBG("network %p", network);
1233 if (network->connected == FALSE && network->connecting == FALSE &&
1234 network->associating == FALSE)
1237 if (network->driver == NULL)
1240 if (network->driver->disconnect == NULL)
1243 network->connecting = FALSE;
1245 err = network->driver->disconnect(network);
1247 connman_network_set_connected(network, FALSE);
1248 set_connected(network);
1254 static int manual_ipv4_set(struct connman_network *network,
1255 struct connman_ipconfig *ipconfig)
1257 struct connman_service *service;
1260 service = __connman_service_lookup_from_network(network);
1261 if (service == NULL)
1264 err = __connman_ipconfig_address_add(ipconfig);
1266 connman_network_set_error(network,
1267 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1271 return __connman_ipconfig_gateway_add(ipconfig);
1274 int __connman_network_clear_ipconfig(struct connman_network *network,
1275 struct connman_ipconfig *ipconfig)
1277 struct connman_service *service;
1278 enum connman_ipconfig_method method;
1279 enum connman_ipconfig_type type;
1281 service = __connman_service_lookup_from_network(network);
1282 if (service == NULL)
1285 method = __connman_ipconfig_get_method(ipconfig);
1286 type = __connman_ipconfig_get_config_type(ipconfig);
1289 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1290 case CONNMAN_IPCONFIG_METHOD_OFF:
1291 case CONNMAN_IPCONFIG_METHOD_FIXED:
1292 case CONNMAN_IPCONFIG_METHOD_AUTO:
1294 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1295 __connman_ipconfig_address_remove(ipconfig);
1297 case CONNMAN_IPCONFIG_METHOD_DHCP:
1298 __connman_dhcp_stop(network);
1302 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1303 __connman_service_ipconfig_indicate_state(service,
1304 CONNMAN_SERVICE_STATE_CONFIGURATION,
1305 CONNMAN_IPCONFIG_TYPE_IPV6);
1306 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1307 __connman_service_ipconfig_indicate_state(service,
1308 CONNMAN_SERVICE_STATE_CONFIGURATION,
1309 CONNMAN_IPCONFIG_TYPE_IPV4);
1314 int __connman_network_set_ipconfig(struct connman_network *network,
1315 struct connman_ipconfig *ipconfig_ipv4,
1316 struct connman_ipconfig *ipconfig_ipv6)
1318 enum connman_ipconfig_method method;
1321 if (ipconfig_ipv6) {
1322 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1325 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1326 case CONNMAN_IPCONFIG_METHOD_OFF:
1328 case CONNMAN_IPCONFIG_METHOD_AUTO:
1329 autoconf_ipv6_set(network);
1331 case CONNMAN_IPCONFIG_METHOD_FIXED:
1332 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1333 ret = manual_ipv6_set(network, ipconfig_ipv6);
1335 connman_network_set_error(network,
1336 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1340 case CONNMAN_IPCONFIG_METHOD_DHCP:
1345 if (ipconfig_ipv4) {
1346 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1349 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1350 case CONNMAN_IPCONFIG_METHOD_OFF:
1351 case CONNMAN_IPCONFIG_METHOD_FIXED:
1352 case CONNMAN_IPCONFIG_METHOD_AUTO:
1354 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1355 return manual_ipv4_set(network, ipconfig_ipv4);
1356 case CONNMAN_IPCONFIG_METHOD_DHCP:
1357 return __connman_dhcp_start(network, dhcp_callback);
1364 int connman_network_set_ipaddress(struct connman_network *network,
1365 struct connman_ipaddress *ipaddress)
1367 struct connman_service *service;
1368 struct connman_ipconfig *ipconfig = NULL;
1370 DBG("network %p", network);
1372 service = __connman_service_lookup_from_network(network);
1373 if (service == NULL)
1376 ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
1377 if (ipconfig == NULL)
1380 __connman_ipconfig_set_local(ipconfig, ipaddress->local);
1381 __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
1382 __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
1383 __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
1384 __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
1389 int connman_network_set_pac(struct connman_network *network,
1392 struct connman_service *service;
1394 DBG("network %p pac %s", network, pac);
1396 service = __connman_service_lookup_from_network(network);
1397 if (service == NULL)
1400 __connman_service_set_pac(service, pac);
1405 int connman_network_set_nameservers(struct connman_network *network,
1406 const char *nameservers)
1408 struct connman_service *service;
1409 char **nameservers_array = NULL;
1412 DBG("network %p nameservers %s", network, nameservers);
1414 service = __connman_service_lookup_from_network(network);
1415 if (service == NULL)
1418 __connman_service_nameserver_clear(service);
1420 if (nameservers != NULL)
1421 nameservers_array = g_strsplit(nameservers, " ", 0);
1423 for (i = 0; nameservers_array[i] != NULL; i++) {
1424 __connman_service_nameserver_append(service,
1425 nameservers_array[i]);
1428 g_strfreev(nameservers_array);
1433 int connman_network_set_domain(struct connman_network *network,
1436 struct connman_service *service;
1438 DBG("network %p domain %s", network, domain);
1440 service = __connman_service_lookup_from_network(network);
1441 if (service == NULL)
1444 __connman_service_set_domainname(service, domain);
1450 * connman_network_set_name:
1451 * @network: network structure
1454 * Set display name value for network
1456 int connman_network_set_name(struct connman_network *network,
1459 DBG("network %p name %s", network, name);
1461 g_free(network->name);
1462 network->name = g_strdup(name);
1468 * connman_network_set_strength:
1469 * @network: network structure
1470 * @strength: strength value
1472 * Set signal strength value for network
1475 int connman_network_set_strength(struct connman_network *network,
1476 connman_uint8_t strength)
1478 DBG("network %p strengh %d", network, strength);
1480 network->strength = strength;
1485 connman_uint8_t connman_network_get_strength(struct connman_network *network)
1487 return network->strength;
1490 int connman_network_set_frequency(struct connman_network *network,
1491 connman_uint16_t frequency)
1493 DBG("network %p frequency %d", network, frequency);
1495 network->frequency = frequency;
1500 connman_uint16_t connman_network_get_frequency(struct connman_network *network)
1502 return network->frequency;
1505 int connman_network_set_wifi_channel(struct connman_network *network,
1506 connman_uint16_t channel)
1508 DBG("network %p wifi channel %d", network, channel);
1510 network->wifi.channel = channel;
1515 connman_uint16_t connman_network_get_wifi_channel(struct connman_network *network)
1517 return network->wifi.channel;
1521 * connman_network_set_roaming:
1522 * @network: network structure
1523 * @roaming: roaming state
1525 * Set roaming state for network
1527 int connman_network_set_roaming(struct connman_network *network,
1528 connman_bool_t roaming)
1530 DBG("network %p roaming %d", network, roaming);
1532 network->roaming = roaming;
1538 * connman_network_set_string:
1539 * @network: network structure
1540 * @key: unique identifier
1541 * @value: string value
1543 * Set string value for specific key
1545 int connman_network_set_string(struct connman_network *network,
1546 const char *key, const char *value)
1548 DBG("network %p key %s value %s", network, key, value);
1550 if (g_strcmp0(key, "Name") == 0)
1551 return connman_network_set_name(network, value);
1553 if (g_str_equal(key, "Path") == TRUE) {
1554 g_free(network->path);
1555 network->path = g_strdup(value);
1556 } else if (g_str_equal(key, "Node") == TRUE) {
1557 g_free(network->node);
1558 network->node = g_strdup(value);
1559 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1560 g_free(network->wifi.mode);
1561 network->wifi.mode = g_strdup(value);
1562 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1563 g_free(network->wifi.security);
1564 network->wifi.security = g_strdup(value);
1565 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1566 g_free(network->wifi.passphrase);
1567 network->wifi.passphrase = g_strdup(value);
1568 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1569 g_free(network->wifi.eap);
1570 network->wifi.eap = g_strdup(value);
1571 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1572 g_free(network->wifi.identity);
1573 network->wifi.identity = g_strdup(value);
1574 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1575 g_free(network->wifi.ca_cert_path);
1576 network->wifi.ca_cert_path = g_strdup(value);
1577 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1578 g_free(network->wifi.client_cert_path);
1579 network->wifi.client_cert_path = g_strdup(value);
1580 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1581 g_free(network->wifi.private_key_path);
1582 network->wifi.private_key_path = g_strdup(value);
1583 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1584 g_free(network->wifi.private_key_passphrase);
1585 network->wifi.private_key_passphrase = g_strdup(value);
1586 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1587 g_free(network->wifi.phase2_auth);
1588 network->wifi.phase2_auth = g_strdup(value);
1589 } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
1590 g_free(network->wifi.pin_wps);
1591 network->wifi.pin_wps = g_strdup(value);
1600 * connman_network_get_string:
1601 * @network: network structure
1602 * @key: unique identifier
1604 * Get string value for specific key
1606 const char *connman_network_get_string(struct connman_network *network,
1609 DBG("network %p key %s", network, key);
1611 if (g_str_equal(key, "Path") == TRUE)
1612 return network->path;
1613 else if (g_str_equal(key, "Name") == TRUE)
1614 return network->name;
1615 else if (g_str_equal(key, "Node") == TRUE)
1616 return network->node;
1617 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1618 return network->wifi.mode;
1619 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1620 return network->wifi.security;
1621 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1622 return network->wifi.passphrase;
1623 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1624 return network->wifi.eap;
1625 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1626 return network->wifi.identity;
1627 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1628 return network->wifi.ca_cert_path;
1629 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1630 return network->wifi.client_cert_path;
1631 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1632 return network->wifi.private_key_path;
1633 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1634 return network->wifi.private_key_passphrase;
1635 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1636 return network->wifi.phase2_auth;
1637 else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
1638 return network->wifi.pin_wps;
1644 * connman_network_set_bool:
1645 * @network: network structure
1646 * @key: unique identifier
1647 * @value: boolean value
1649 * Set boolean value for specific key
1651 int connman_network_set_bool(struct connman_network *network,
1652 const char *key, connman_bool_t value)
1654 DBG("network %p key %s value %d", network, key, value);
1656 if (g_strcmp0(key, "Roaming") == 0)
1657 return connman_network_set_roaming(network, value);
1658 else if (g_strcmp0(key, "WiFi.WPS") == 0)
1659 network->wifi.wps = value;
1660 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
1661 network->wifi.use_wps = value;
1667 * connman_network_get_bool:
1668 * @network: network structure
1669 * @key: unique identifier
1671 * Get boolean value for specific key
1673 connman_bool_t connman_network_get_bool(struct connman_network *network,
1676 DBG("network %p key %s", network, key);
1678 if (g_str_equal(key, "Roaming") == TRUE)
1679 return network->roaming;
1680 else if (g_str_equal(key, "WiFi.WPS") == TRUE)
1681 return network->wifi.wps;
1682 else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
1683 return network->wifi.use_wps;
1689 * connman_network_set_blob:
1690 * @network: network structure
1691 * @key: unique identifier
1695 * Set binary blob value for specific key
1697 int connman_network_set_blob(struct connman_network *network,
1698 const char *key, const void *data, unsigned int size)
1700 DBG("network %p key %s size %d", network, key, size);
1702 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1703 g_free(network->wifi.ssid);
1704 network->wifi.ssid = g_try_malloc(size);
1705 if (network->wifi.ssid != NULL) {
1706 memcpy(network->wifi.ssid, data, size);
1707 network->wifi.ssid_len = size;
1709 network->wifi.ssid_len = 0;
1718 * connman_network_get_blob:
1719 * @network: network structure
1720 * @key: unique identifier
1721 * @size: pointer to blob size
1723 * Get binary blob value for specific key
1725 const void *connman_network_get_blob(struct connman_network *network,
1726 const char *key, unsigned int *size)
1728 DBG("network %p key %s", network, key);
1730 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1732 *size = network->wifi.ssid_len;
1733 return network->wifi.ssid;
1739 void __connman_network_set_device(struct connman_network *network,
1740 struct connman_device *device)
1742 if (network->device == device)
1745 if (network->device != NULL)
1746 network_remove(network);
1748 network->device = device;
1750 if (network->device != NULL)
1751 network_probe(network);
1755 * connman_network_get_device:
1756 * @network: network structure
1758 * Get parent device of network
1760 struct connman_device *connman_network_get_device(struct connman_network *network)
1762 return network->device;
1766 * connman_network_get_data:
1767 * @network: network structure
1769 * Get private network data pointer
1771 void *connman_network_get_data(struct connman_network *network)
1773 return network->driver_data;
1777 * connman_network_set_data:
1778 * @network: network structure
1779 * @data: data pointer
1781 * Set private network data pointer
1783 void connman_network_set_data(struct connman_network *network, void *data)
1785 network->driver_data = data;
1788 void connman_network_update(struct connman_network *network)
1790 switch (network->type) {
1791 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1792 case CONNMAN_NETWORK_TYPE_VENDOR:
1794 case CONNMAN_NETWORK_TYPE_ETHERNET:
1795 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1796 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1797 case CONNMAN_NETWORK_TYPE_CELLULAR:
1798 case CONNMAN_NETWORK_TYPE_WIFI:
1799 case CONNMAN_NETWORK_TYPE_WIMAX:
1803 if (network->group != NULL)
1804 __connman_service_update_from_network(network);
1807 int __connman_network_init(void)
1814 void __connman_network_cleanup(void)