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 unsigned int hidden_counter = 0;
33 struct connman_network {
34 struct connman_element element;
35 enum connman_network_type type;
36 connman_bool_t available;
37 connman_bool_t connected;
38 connman_bool_t roaming;
39 connman_bool_t hidden;
40 connman_uint8_t strength;
41 connman_uint16_t frequency;
48 struct connman_network_driver *driver;
51 connman_bool_t connecting;
52 connman_bool_t associating;
54 struct connman_device *device;
60 unsigned short channel;
66 char *client_cert_path;
67 char *private_key_path;
68 char *private_key_passphrase;
71 connman_bool_t use_wps;
76 static const char *type2string(enum connman_network_type type)
79 case CONNMAN_NETWORK_TYPE_UNKNOWN:
80 case CONNMAN_NETWORK_TYPE_VENDOR:
82 case CONNMAN_NETWORK_TYPE_ETHERNET:
84 case CONNMAN_NETWORK_TYPE_WIFI:
86 case CONNMAN_NETWORK_TYPE_WIMAX:
88 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
89 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
91 case CONNMAN_NETWORK_TYPE_CELLULAR:
98 connman_bool_t __connman_network_has_driver(struct connman_network *network)
100 if (network == NULL || network->driver == NULL)
106 static GSList *driver_list = NULL;
108 static gint compare_priority(gconstpointer a, gconstpointer b)
110 const struct connman_network_driver *driver1 = a;
111 const struct connman_network_driver *driver2 = b;
113 return driver2->priority - driver1->priority;
117 * connman_network_driver_register:
118 * @driver: network driver definition
120 * Register a new network driver
122 * Returns: %0 on success
124 int connman_network_driver_register(struct connman_network_driver *driver)
128 DBG("driver %p name %s", driver, driver->name);
130 for (list = driver_list; list; list = list->next) {
131 struct connman_network_driver *tmp = list->data;
133 if (tmp->type == driver->type)
138 driver_list = g_slist_insert_sorted(driver_list, driver,
145 * connman_network_driver_unregister:
146 * @driver: network driver definition
148 * Remove a previously registered network driver
150 void connman_network_driver_unregister(struct connman_network_driver *driver)
152 DBG("driver %p name %s", driver, driver->name);
154 driver_list = g_slist_remove(driver_list, driver);
157 static void network_destruct(struct connman_element *element)
159 struct connman_network *network = element->network;
161 DBG("element %p name %s", element, element->name);
163 g_free(network->wifi.ssid);
164 g_free(network->wifi.mode);
165 g_free(network->wifi.security);
166 g_free(network->wifi.passphrase);
167 g_free(network->wifi.eap);
168 g_free(network->wifi.identity);
169 g_free(network->wifi.ca_cert_path);
170 g_free(network->wifi.client_cert_path);
171 g_free(network->wifi.private_key_path);
172 g_free(network->wifi.private_key_passphrase);
173 g_free(network->wifi.phase2_auth);
174 g_free(network->wifi.pin_wps);
176 g_free(network->path);
177 g_free(network->group);
178 g_free(network->node);
179 g_free(network->name);
180 g_free(network->identifier);
182 network->device = NULL;
186 * connman_network_create:
187 * @identifier: network identifier (for example an unqiue name)
189 * Allocate a new network and assign the #identifier to it.
191 * Returns: a newly-allocated #connman_network structure
193 struct connman_network *connman_network_create(const char *identifier,
194 enum connman_network_type type)
196 struct connman_network *network;
197 connman_uint8_t strength = 0;
200 DBG("identifier %s type %d", identifier, type);
202 network = g_try_new0(struct connman_network, 1);
206 DBG("network %p", network);
208 __connman_element_initialize(&network->element);
210 if (identifier == NULL) {
211 temp = g_strdup_printf("hidden_%d", hidden_counter++);
212 network->hidden = TRUE;
214 temp = g_strdup(identifier);
221 network->element.name = temp;
222 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
224 network->element.network = network;
225 network->element.destruct = network_destruct;
227 connman_element_set_uint8(&network->element, "Strength", strength);
229 network->type = type;
230 network->identifier = g_strdup(temp);
236 * connman_network_ref:
237 * @network: network structure
239 * Increase reference counter of network
241 struct connman_network *connman_network_ref(struct connman_network *network)
243 if (connman_element_ref(&network->element) == NULL)
250 * connman_network_unref:
251 * @network: network structure
253 * Decrease reference counter of network
255 void connman_network_unref(struct connman_network *network)
257 connman_element_unref(&network->element);
260 const char *__connman_network_get_type(struct connman_network *network)
262 return type2string(network->type);
266 * connman_network_get_type:
267 * @network: network structure
269 * Get type of network
271 enum connman_network_type connman_network_get_type(struct connman_network *network)
273 return network->type;
277 * connman_network_get_identifier:
278 * @network: network structure
280 * Get identifier of network
282 const char *connman_network_get_identifier(struct connman_network *network)
284 return network->identifier;
288 * connman_network_set_index:
289 * @network: network structure
290 * @index: index number
292 * Set index number of network
294 void connman_network_set_index(struct connman_network *network, int index)
296 struct connman_service *service;
297 struct connman_ipconfig *ipconfig;
299 service = __connman_service_lookup_from_network(network);
303 ipconfig = __connman_service_get_ip4config(service);
305 DBG("index %d service %p ip4config %p", network->element.index,
308 if (network->element.index < 0 && ipconfig == NULL) {
310 ipconfig = __connman_service_get_ip4config(service);
311 if (ipconfig == NULL)
313 * This is needed for plugins that havent set their
314 * ipconfig layer yet, due to not being able to get
315 * a network index prior to creating a service.
317 __connman_service_create_ip4config(service, index);
319 __connman_ipconfig_set_index(ipconfig, index);
322 /* If index changed, the index of ipconfig must be reset. */
323 if (ipconfig == NULL)
326 __connman_ipconfig_set_index(ipconfig, index);
330 network->element.index = index;
334 * connman_network_get_index:
335 * @network: network structure
337 * Get index number of network
339 int connman_network_get_index(struct connman_network *network)
341 return network->element.index;
345 * connman_network_get_element:
346 * @network: network structure
348 * Get connman_element of network
350 struct connman_element *connman_network_get_element(
351 struct connman_network *network)
353 return &network->element;
357 * connman_network_set_group:
358 * @network: network structure
361 * Set group name for automatic clustering
363 void connman_network_set_group(struct connman_network *network,
366 switch (network->type) {
367 case CONNMAN_NETWORK_TYPE_UNKNOWN:
368 case CONNMAN_NETWORK_TYPE_VENDOR:
370 case CONNMAN_NETWORK_TYPE_ETHERNET:
371 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
372 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
373 case CONNMAN_NETWORK_TYPE_CELLULAR:
374 case CONNMAN_NETWORK_TYPE_WIFI:
375 case CONNMAN_NETWORK_TYPE_WIMAX:
379 if (g_strcmp0(network->group, group) == 0) {
381 __connman_service_update_from_network(network);
385 if (network->group != NULL) {
386 __connman_service_remove_from_network(network);
388 g_free(network->group);
391 network->group = g_strdup(group);
393 if (network->group != NULL)
394 __connman_service_create_from_network(network);
398 * connman_network_get_group:
399 * @network: network structure
401 * Get group name for automatic clustering
403 const char *connman_network_get_group(struct connman_network *network)
405 return network->group;
408 const char *__connman_network_get_ident(struct connman_network *network)
410 if (network->device == NULL)
413 return connman_device_get_ident(network->device);
416 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
418 switch (network->type) {
419 case CONNMAN_NETWORK_TYPE_UNKNOWN:
420 case CONNMAN_NETWORK_TYPE_VENDOR:
421 case CONNMAN_NETWORK_TYPE_ETHERNET:
422 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
423 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
424 case CONNMAN_NETWORK_TYPE_CELLULAR:
425 case CONNMAN_NETWORK_TYPE_WIMAX:
427 case CONNMAN_NETWORK_TYPE_WIFI:
428 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
430 if (network->strength > 0 && network->strength < 20)
438 connman_bool_t connman_network_get_connecting(struct connman_network *network)
440 return network->connecting;
444 * connman_network_set_available:
445 * @network: network structure
446 * @available: availability state
448 * Change availability state of network (in range)
450 int connman_network_set_available(struct connman_network *network,
451 connman_bool_t available)
453 DBG("network %p available %d", network, available);
455 if (network->available == available)
458 network->available = available;
464 * connman_network_get_available:
465 * @network: network structure
467 * Get network available setting
469 connman_bool_t connman_network_get_available(struct connman_network *network)
471 if (network->hidden == TRUE)
474 return network->available;
478 * connman_network_set_associating:
479 * @network: network structure
480 * @associating: associating state
482 * Change associating state of network
484 int connman_network_set_associating(struct connman_network *network,
485 connman_bool_t associating)
487 DBG("network %p associating %d", network, associating);
489 if (network->associating == associating)
492 network->associating = associating;
494 if (associating == TRUE) {
495 struct connman_service *service;
497 service = __connman_service_lookup_from_network(network);
498 __connman_service_indicate_state(service,
499 CONNMAN_SERVICE_STATE_ASSOCIATION,
500 CONNMAN_IPCONFIG_TYPE_IPV4);
506 static void set_associate_error(struct connman_network *network)
508 struct connman_service *service;
510 if (network->associating == FALSE)
513 network->associating = FALSE;
515 service = __connman_service_lookup_from_network(network);
517 __connman_service_indicate_state(service,
518 CONNMAN_SERVICE_STATE_FAILURE,
519 CONNMAN_IPCONFIG_TYPE_IPV4);
522 static void set_configure_error(struct connman_network *network)
524 struct connman_service *service;
526 network->connecting = FALSE;
528 service = __connman_service_lookup_from_network(network);
530 __connman_service_indicate_state(service,
531 CONNMAN_SERVICE_STATE_FAILURE,
532 CONNMAN_IPCONFIG_TYPE_IPV4);
535 static void set_invalid_key_error(struct connman_network *network)
537 struct connman_service *service;
539 service = __connman_service_lookup_from_network(network);
541 __connman_service_indicate_error(service,
542 CONNMAN_SERVICE_ERROR_INVALID_KEY);
545 static void set_connect_error(struct connman_network *network)
547 struct connman_service *service;
549 service = __connman_service_lookup_from_network(network);
551 __connman_service_indicate_error(service,
552 CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
555 void connman_network_set_ipv4_method(struct connman_network *network,
556 enum connman_ipconfig_method method)
558 struct connman_service *service;
559 struct connman_ipconfig *ipconfig;
561 service = __connman_service_lookup_from_network(network);
565 ipconfig = __connman_service_get_ip4config(service);
566 if (ipconfig == NULL)
569 connman_ipconfig_set_method(ipconfig, method);
572 void connman_network_set_ipv6_method(struct connman_network *network,
573 enum connman_ipconfig_method method)
575 struct connman_service *service;
576 struct connman_ipconfig *ipconfig;
578 service = __connman_service_lookup_from_network(network);
582 ipconfig = __connman_service_get_ip6config(service);
583 if (ipconfig == NULL)
586 connman_ipconfig_set_method(ipconfig, method);
589 void connman_network_set_error(struct connman_network *network,
590 enum connman_network_error error)
592 DBG("nework %p, error %d", network, error);
594 network->connecting = FALSE;
597 case CONNMAN_NETWORK_ERROR_UNKNOWN:
599 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
600 set_associate_error(network);
602 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
603 set_configure_error(network);
605 case CONNMAN_NETWORK_ERROR_INVALID_KEY:
606 set_invalid_key_error(network);
608 case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
609 set_connect_error(network);
614 void connman_network_clear_error(struct connman_network *network)
616 struct connman_service *service;
618 DBG("network %p", network);
623 if (network->connecting == TRUE || network->associating == TRUE)
626 service = __connman_service_lookup_from_network(network);
627 __connman_service_clear_error(service);
630 static void set_configuration(struct connman_network *network)
632 struct connman_service *service;
634 DBG("network %p", network);
636 __connman_device_increase_connections(network->device);
638 __connman_device_set_network(network->device, network);
640 connman_device_set_disconnected(network->device, FALSE);
642 service = __connman_service_lookup_from_network(network);
643 __connman_service_indicate_state(service,
644 CONNMAN_SERVICE_STATE_CONFIGURATION,
645 CONNMAN_IPCONFIG_TYPE_IPV4);
648 static void dhcp_success(struct connman_network *network)
650 struct connman_service *service;
651 struct connman_ipconfig *ipconfig_ipv4;
654 service = __connman_service_lookup_from_network(network);
658 connman_network_set_associating(network, FALSE);
660 network->connecting = FALSE;
662 ipconfig_ipv4 = __connman_service_get_ip4config(service);
663 err = __connman_ipconfig_address_add(ipconfig_ipv4);
667 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
671 __connman_service_set_ipconfig_ready(service, CONNMAN_IPCONFIG_TYPE_IPV4);
676 connman_network_set_error(network,
677 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
680 static void dhcp_failure(struct connman_network *network)
682 struct connman_service *service;
684 service = __connman_service_lookup_from_network(network);
688 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_IDLE,
689 CONNMAN_IPCONFIG_TYPE_IPV4);
692 static void dhcp_callback(struct connman_network *network,
693 connman_bool_t success)
695 DBG("success %d", success);
698 dhcp_success(network);
700 dhcp_failure(network);
703 static int set_connected_fixed(struct connman_network *network)
705 struct connman_service *service;
706 struct connman_ipconfig *ipconfig_ipv4;
711 service = __connman_service_lookup_from_network(network);
713 ipconfig_ipv4 = __connman_service_get_ip4config(service);
715 set_configuration(network);
717 network->connecting = FALSE;
719 connman_network_set_associating(network, FALSE);
721 err = __connman_ipconfig_address_add(ipconfig_ipv4);
725 err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
729 __connman_service_set_ipconfig_ready(service, CONNMAN_IPCONFIG_TYPE_IPV4);
734 connman_network_set_error(network,
735 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
740 static void set_connected_manual(struct connman_network *network)
742 struct connman_service *service;
743 struct connman_ipconfig *ipconfig;
746 DBG("network %p", network);
748 service = __connman_service_lookup_from_network(network);
750 ipconfig = __connman_service_get_ip4config(service);
752 set_configuration(network);
754 err = __connman_ipconfig_address_add(ipconfig);
758 err = __connman_ipconfig_gateway_add(ipconfig);
762 network->connecting = FALSE;
764 connman_network_set_associating(network, FALSE);
766 __connman_service_set_ipconfig_ready(service, CONNMAN_IPCONFIG_TYPE_IPV4);
771 connman_network_set_error(network,
772 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
776 static int set_connected_dhcp(struct connman_network *network)
780 DBG("network %p", network);
782 set_configuration(network);
784 err = __connman_dhcp_start(network, dhcp_callback);
786 connman_error("Can not request DHCP lease");
793 static int manual_ipv6_set(struct connman_network *network,
794 struct connman_ipconfig *ipconfig_ipv6)
796 struct connman_service *service;
799 service = __connman_service_lookup_from_network(network);
803 err = __connman_ipconfig_address_add(ipconfig_ipv6);
805 connman_network_set_error(network,
806 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
811 * READY state will be indicated by IPV4 setting
812 * gateway will be set by IPV4 setting
818 static void autoconf_ipv6_set(struct connman_network *network)
820 struct connman_service *service;
822 DBG("network %p", network);
824 service = __connman_service_lookup_from_network(network);
826 __connman_device_increase_connections(network->device);
828 __connman_device_set_network(network->device, network);
830 connman_device_set_disconnected(network->device, FALSE);
832 /* XXX: Append IPv6 nameservers here */
834 network->connecting = FALSE;
836 __connman_service_set_ipconfig_ready(service, CONNMAN_IPCONFIG_TYPE_IPV6);
839 static gboolean set_connected(gpointer user_data)
841 struct connman_network *network = user_data;
842 struct connman_service *service;
843 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
844 enum connman_ipconfig_method ipv4_method, ipv6_method;
846 service = __connman_service_lookup_from_network(network);
848 ipconfig_ipv4 = __connman_service_get_ip4config(service);
849 ipconfig_ipv6 = __connman_service_get_ip6config(service);
851 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
854 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
855 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
857 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
858 DBG("network connected %d", network->connected);
860 if (network->connected == TRUE) {
863 switch (ipv6_method) {
864 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
865 case CONNMAN_IPCONFIG_METHOD_OFF:
867 case CONNMAN_IPCONFIG_METHOD_AUTO:
868 autoconf_ipv6_set(network);
870 case CONNMAN_IPCONFIG_METHOD_FIXED:
871 case CONNMAN_IPCONFIG_METHOD_MANUAL:
872 ret = manual_ipv6_set(network, ipconfig_ipv6);
874 connman_network_set_error(network,
875 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
879 case CONNMAN_IPCONFIG_METHOD_DHCP:
883 switch (ipv4_method) {
884 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
885 case CONNMAN_IPCONFIG_METHOD_OFF:
886 case CONNMAN_IPCONFIG_METHOD_AUTO:
888 case CONNMAN_IPCONFIG_METHOD_FIXED:
889 if (set_connected_fixed(network) < 0) {
890 connman_network_set_error(network,
891 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
895 case CONNMAN_IPCONFIG_METHOD_MANUAL:
896 set_connected_manual(network);
898 case CONNMAN_IPCONFIG_METHOD_DHCP:
899 if (set_connected_dhcp(network) < 0) {
900 connman_network_set_error(network,
901 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
907 struct connman_service *service;
909 connman_element_unregister_children(&network->element);
911 __connman_device_set_network(network->device, NULL);
912 network->hidden = FALSE;
914 service = __connman_service_lookup_from_network(network);
916 __connman_service_indicate_state(service,
917 CONNMAN_SERVICE_STATE_DISCONNECT,
918 CONNMAN_IPCONFIG_TYPE_IPV4);
920 __connman_service_indicate_state(service,
921 CONNMAN_SERVICE_STATE_DISCONNECT,
922 CONNMAN_IPCONFIG_TYPE_IPV6);
924 __connman_connection_gateway_remove(service);
926 __connman_service_indicate_state(service,
927 CONNMAN_SERVICE_STATE_IDLE,
928 CONNMAN_IPCONFIG_TYPE_IPV4);
930 __connman_service_indicate_state(service,
931 CONNMAN_SERVICE_STATE_IDLE,
932 CONNMAN_IPCONFIG_TYPE_IPV6);
935 network->connecting = FALSE;
937 connman_network_set_associating(network, FALSE);
943 * connman_network_set_connected:
944 * @network: network structure
945 * @connected: connected state
947 * Change connected state of network
949 int connman_network_set_connected(struct connman_network *network,
950 connman_bool_t connected)
952 DBG("network %p connected %d", network, connected);
954 if ((network->connecting == TRUE || network->associating == TRUE) &&
955 connected == FALSE) {
956 connman_network_set_error(network,
957 CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
958 __connman_network_disconnect(network);
961 if (network->connected == connected)
964 if (connected == FALSE)
965 __connman_device_decrease_connections(network->device);
967 network->connected = connected;
969 set_connected(network);
975 * connman_network_get_connected:
976 * @network: network structure
978 * Get network connection status
980 connman_bool_t connman_network_get_connected(struct connman_network *network)
982 return network->connected;
986 * connman_network_get_associating:
987 * @network: network structure
989 * Get network associating status
991 connman_bool_t connman_network_get_associating(struct connman_network *network)
993 return network->associating;
997 * __connman_network_connect:
998 * @network: network structure
1002 int __connman_network_connect(struct connman_network *network)
1006 DBG("network %p", network);
1008 if (network->connected == TRUE)
1011 if (network->connecting == TRUE || network->associating == TRUE)
1014 if (network->driver == NULL)
1017 if (network->driver->connect == NULL)
1020 if (network->device == NULL)
1023 network->connecting = TRUE;
1025 __connman_device_disconnect(network->device);
1027 err = network->driver->connect(network);
1029 if (err == -EINPROGRESS)
1030 connman_network_set_associating(network, TRUE);
1032 network->connecting = FALSE;
1033 network->hidden = FALSE;
1039 network->connected = TRUE;
1040 set_connected(network);
1046 * __connman_network_disconnect:
1047 * @network: network structure
1049 * Disconnect network
1051 int __connman_network_disconnect(struct connman_network *network)
1055 DBG("network %p", network);
1057 if (network->connected == FALSE && network->connecting == FALSE &&
1058 network->associating == FALSE)
1061 if (network->driver == NULL)
1064 if (network->driver->disconnect == NULL)
1067 network->connecting = FALSE;
1069 err = network->driver->disconnect(network);
1071 connman_network_set_connected(network, FALSE);
1072 set_connected(network);
1078 static int manual_ipv4_set(struct connman_network *network,
1079 struct connman_ipconfig *ipconfig)
1081 struct connman_service *service;
1084 service = __connman_service_lookup_from_network(network);
1085 if (service == NULL)
1088 err = __connman_ipconfig_address_add(ipconfig);
1090 connman_network_set_error(network,
1091 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1095 __connman_ipconfig_gateway_add(ipconfig);
1097 __connman_service_set_ipconfig_ready(service, CONNMAN_IPCONFIG_TYPE_IPV4);
1102 int __connman_network_clear_ipconfig(struct connman_network *network,
1103 struct connman_ipconfig *ipconfig)
1105 struct connman_service *service;
1106 enum connman_ipconfig_method method;
1107 enum connman_ipconfig_type type;
1109 service = __connman_service_lookup_from_network(network);
1110 if (service == NULL)
1113 method = __connman_ipconfig_get_method(ipconfig);
1114 type = __connman_ipconfig_get_config_type(ipconfig);
1117 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1118 case CONNMAN_IPCONFIG_METHOD_OFF:
1119 case CONNMAN_IPCONFIG_METHOD_FIXED:
1120 case CONNMAN_IPCONFIG_METHOD_AUTO:
1122 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1123 __connman_ipconfig_address_remove(ipconfig);
1125 case CONNMAN_IPCONFIG_METHOD_DHCP:
1126 __connman_dhcp_stop(network);
1130 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1131 __connman_service_indicate_state(service,
1132 CONNMAN_SERVICE_STATE_CONFIGURATION,
1133 CONNMAN_IPCONFIG_TYPE_IPV6);
1134 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1135 __connman_service_indicate_state(service,
1136 CONNMAN_SERVICE_STATE_CONFIGURATION,
1137 CONNMAN_IPCONFIG_TYPE_IPV4);
1142 int __connman_network_set_ipconfig(struct connman_network *network,
1143 struct connman_ipconfig *ipconfig_ipv4,
1144 struct connman_ipconfig *ipconfig_ipv6)
1146 enum connman_ipconfig_method method;
1149 if (ipconfig_ipv6) {
1150 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1153 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1154 case CONNMAN_IPCONFIG_METHOD_OFF:
1156 case CONNMAN_IPCONFIG_METHOD_AUTO:
1157 autoconf_ipv6_set(network);
1159 case CONNMAN_IPCONFIG_METHOD_FIXED:
1160 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1161 ret = manual_ipv6_set(network, ipconfig_ipv6);
1163 connman_network_set_error(network,
1164 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1168 case CONNMAN_IPCONFIG_METHOD_DHCP:
1173 if (ipconfig_ipv4) {
1174 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1177 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1178 case CONNMAN_IPCONFIG_METHOD_OFF:
1179 case CONNMAN_IPCONFIG_METHOD_FIXED:
1180 case CONNMAN_IPCONFIG_METHOD_AUTO:
1182 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1183 return manual_ipv4_set(network, ipconfig_ipv4);
1184 case CONNMAN_IPCONFIG_METHOD_DHCP:
1185 return __connman_dhcp_start(network, dhcp_callback);
1192 int connman_network_set_ipaddress(struct connman_network *network,
1193 struct connman_ipaddress *ipaddress)
1195 struct connman_service *service;
1196 struct connman_ipconfig *ipconfig = NULL;
1198 DBG("network %p", network);
1200 service = __connman_service_lookup_from_network(network);
1201 if (service == NULL)
1204 ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
1205 if (ipconfig == NULL)
1208 __connman_ipconfig_set_local(ipconfig, ipaddress->local);
1209 __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
1210 __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
1211 __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
1212 __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
1217 int connman_network_set_pac(struct connman_network *network,
1220 struct connman_service *service;
1222 DBG("network %p pac %s", network, pac);
1224 service = __connman_service_lookup_from_network(network);
1225 if (service == NULL)
1228 __connman_service_set_pac(service, pac);
1233 int connman_network_set_nameservers(struct connman_network *network,
1234 const char *nameservers)
1236 struct connman_service *service;
1237 char **nameservers_array = NULL;
1240 DBG("network %p nameservers %s", network, nameservers);
1242 service = __connman_service_lookup_from_network(network);
1243 if (service == NULL)
1246 __connman_service_nameserver_clear(service);
1248 if (nameservers != NULL)
1249 nameservers_array = g_strsplit(nameservers, " ", 0);
1251 for (i = 0; nameservers_array[i] != NULL; i++) {
1252 __connman_service_nameserver_append(service,
1253 nameservers_array[i]);
1256 g_strfreev(nameservers_array);
1261 int connman_network_set_domain(struct connman_network *network,
1264 struct connman_service *service;
1266 DBG("network %p domain %s", network, domain);
1268 service = __connman_service_lookup_from_network(network);
1269 if (service == NULL)
1272 __connman_service_set_domainname(service, domain);
1278 * connman_network_set_name:
1279 * @network: network structure
1282 * Set display name value for network
1284 int connman_network_set_name(struct connman_network *network,
1287 DBG("network %p name %s", network, name);
1289 g_free(network->name);
1290 network->name = g_strdup(name);
1292 return connman_element_set_string(&network->element, "Name", name);
1296 * connman_network_set_strength:
1297 * @network: network structure
1298 * @strength: strength value
1300 * Set signal strength value for network
1303 int connman_network_set_strength(struct connman_network *network,
1304 connman_uint8_t strength)
1306 DBG("network %p strengh %d", network, strength);
1308 network->strength = strength;
1313 connman_uint8_t connman_network_get_strength(struct connman_network *network)
1315 return network->strength;
1318 int connman_network_set_frequency(struct connman_network *network,
1319 connman_uint16_t frequency)
1321 DBG("network %p frequency %d", network, frequency);
1323 network->frequency = frequency;
1328 connman_uint16_t connman_network_get_frequency(struct connman_network *network)
1330 return network->frequency;
1333 int connman_network_set_wifi_channel(struct connman_network *network,
1334 connman_uint16_t channel)
1336 DBG("network %p wifi channel %d", network, channel);
1338 network->wifi.channel = channel;
1343 connman_uint16_t connman_network_get_wifi_channel(struct connman_network *network)
1345 return network->wifi.channel;
1349 * connman_network_set_roaming:
1350 * @network: network structure
1351 * @roaming: roaming state
1353 * Set roaming state for network
1355 int connman_network_set_roaming(struct connman_network *network,
1356 connman_bool_t roaming)
1358 DBG("network %p roaming %d", network, roaming);
1360 network->roaming = roaming;
1366 * connman_network_set_string:
1367 * @network: network structure
1368 * @key: unique identifier
1369 * @value: string value
1371 * Set string value for specific key
1373 int connman_network_set_string(struct connman_network *network,
1374 const char *key, const char *value)
1376 DBG("network %p key %s value %s", network, key, value);
1378 if (g_strcmp0(key, "Name") == 0)
1379 return connman_network_set_name(network, value);
1381 if (g_str_equal(key, "Path") == TRUE) {
1382 g_free(network->path);
1383 network->path = g_strdup(value);
1384 } else if (g_str_equal(key, "Node") == TRUE) {
1385 g_free(network->node);
1386 network->node = g_strdup(value);
1387 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1388 g_free(network->wifi.mode);
1389 network->wifi.mode = g_strdup(value);
1390 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1391 g_free(network->wifi.security);
1392 network->wifi.security = g_strdup(value);
1393 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1394 g_free(network->wifi.passphrase);
1395 network->wifi.passphrase = g_strdup(value);
1396 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1397 g_free(network->wifi.eap);
1398 network->wifi.eap = g_strdup(value);
1399 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1400 g_free(network->wifi.identity);
1401 network->wifi.identity = g_strdup(value);
1402 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1403 g_free(network->wifi.ca_cert_path);
1404 network->wifi.ca_cert_path = g_strdup(value);
1405 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1406 g_free(network->wifi.client_cert_path);
1407 network->wifi.client_cert_path = g_strdup(value);
1408 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1409 g_free(network->wifi.private_key_path);
1410 network->wifi.private_key_path = g_strdup(value);
1411 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1412 g_free(network->wifi.private_key_passphrase);
1413 network->wifi.private_key_passphrase = g_strdup(value);
1414 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1415 g_free(network->wifi.phase2_auth);
1416 network->wifi.phase2_auth = g_strdup(value);
1417 } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
1418 g_free(network->wifi.pin_wps);
1419 network->wifi.pin_wps = g_strdup(value);
1428 * connman_network_get_string:
1429 * @network: network structure
1430 * @key: unique identifier
1432 * Get string value for specific key
1434 const char *connman_network_get_string(struct connman_network *network,
1437 DBG("network %p key %s", network, key);
1439 if (g_str_equal(key, "Path") == TRUE)
1440 return network->path;
1441 else if (g_str_equal(key, "Name") == TRUE)
1442 return network->name;
1443 else if (g_str_equal(key, "Node") == TRUE)
1444 return network->node;
1445 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1446 return network->wifi.mode;
1447 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1448 return network->wifi.security;
1449 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1450 return network->wifi.passphrase;
1451 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1452 return network->wifi.eap;
1453 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1454 return network->wifi.identity;
1455 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1456 return network->wifi.ca_cert_path;
1457 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1458 return network->wifi.client_cert_path;
1459 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1460 return network->wifi.private_key_path;
1461 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1462 return network->wifi.private_key_passphrase;
1463 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1464 return network->wifi.phase2_auth;
1465 else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
1466 return network->wifi.pin_wps;
1472 * connman_network_set_bool:
1473 * @network: network structure
1474 * @key: unique identifier
1475 * @value: boolean value
1477 * Set boolean value for specific key
1479 int connman_network_set_bool(struct connman_network *network,
1480 const char *key, connman_bool_t value)
1482 DBG("network %p key %s value %d", network, key, value);
1484 if (g_strcmp0(key, "Roaming") == 0)
1485 return connman_network_set_roaming(network, value);
1486 else if (g_strcmp0(key, "WiFi.WPS") == 0)
1487 network->wifi.wps = value;
1488 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
1489 network->wifi.use_wps = value;
1495 * connman_network_get_bool:
1496 * @network: network structure
1497 * @key: unique identifier
1499 * Get boolean value for specific key
1501 connman_bool_t connman_network_get_bool(struct connman_network *network,
1504 DBG("network %p key %s", network, key);
1506 if (g_str_equal(key, "Roaming") == TRUE)
1507 return network->roaming;
1508 else if (g_str_equal(key, "WiFi.WPS") == TRUE)
1509 return network->wifi.wps;
1510 else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
1511 return network->wifi.use_wps;
1517 * connman_network_set_blob:
1518 * @network: network structure
1519 * @key: unique identifier
1523 * Set binary blob value for specific key
1525 int connman_network_set_blob(struct connman_network *network,
1526 const char *key, const void *data, unsigned int size)
1528 DBG("network %p key %s size %d", network, key, size);
1530 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1531 g_free(network->wifi.ssid);
1532 network->wifi.ssid = g_try_malloc(size);
1533 if (network->wifi.ssid != NULL) {
1534 memcpy(network->wifi.ssid, data, size);
1535 network->wifi.ssid_len = size;
1537 network->wifi.ssid_len = 0;
1546 * connman_network_get_blob:
1547 * @network: network structure
1548 * @key: unique identifier
1549 * @size: pointer to blob size
1551 * Get binary blob value for specific key
1553 const void *connman_network_get_blob(struct connman_network *network,
1554 const char *key, unsigned int *size)
1556 DBG("network %p key %s", network, key);
1558 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1560 *size = network->wifi.ssid_len;
1561 return network->wifi.ssid;
1567 void __connman_network_set_device(struct connman_network *network,
1568 struct connman_device *device)
1570 network->device = device;
1574 * connman_network_get_device:
1575 * @network: network structure
1577 * Get parent device of network
1579 struct connman_device *connman_network_get_device(struct connman_network *network)
1581 return network->device;
1585 * connman_network_get_data:
1586 * @network: network structure
1588 * Get private network data pointer
1590 void *connman_network_get_data(struct connman_network *network)
1592 return network->driver_data;
1596 * connman_network_set_data:
1597 * @network: network structure
1598 * @data: data pointer
1600 * Set private network data pointer
1602 void connman_network_set_data(struct connman_network *network, void *data)
1604 network->driver_data = data;
1607 void connman_network_update(struct connman_network *network)
1609 switch (network->type) {
1610 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1611 case CONNMAN_NETWORK_TYPE_VENDOR:
1613 case CONNMAN_NETWORK_TYPE_ETHERNET:
1614 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1615 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1616 case CONNMAN_NETWORK_TYPE_CELLULAR:
1617 case CONNMAN_NETWORK_TYPE_WIFI:
1618 case CONNMAN_NETWORK_TYPE_WIMAX:
1622 if (network->group != NULL)
1623 __connman_service_update_from_network(network);
1628 static gboolean match_driver(struct connman_network *network,
1629 struct connman_network_driver *driver)
1631 if (network->type == driver->type ||
1632 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1638 static int network_probe(struct connman_element *element)
1640 struct connman_network *network = element->network;
1643 DBG("element %p name %s", element, element->name);
1645 if (network == NULL)
1648 for (list = driver_list; list; list = list->next) {
1649 struct connman_network_driver *driver = list->data;
1651 if (match_driver(network, driver) == FALSE)
1654 DBG("driver %p name %s", driver, driver->name);
1656 if (driver->probe(network) == 0) {
1657 network->driver = driver;
1662 if (network->driver == NULL)
1665 switch (network->type) {
1666 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1667 case CONNMAN_NETWORK_TYPE_VENDOR:
1669 case CONNMAN_NETWORK_TYPE_ETHERNET:
1670 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1671 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1672 case CONNMAN_NETWORK_TYPE_CELLULAR:
1673 case CONNMAN_NETWORK_TYPE_WIFI:
1674 case CONNMAN_NETWORK_TYPE_WIMAX:
1675 if (network->group != NULL &&
1676 __connman_service_create_from_network(network) == NULL)
1683 static void network_remove(struct connman_element *element)
1685 struct connman_network *network = element->network;
1687 DBG("element %p name %s", element, element->name);
1689 if (network == NULL)
1692 if (network->driver == NULL)
1695 switch (network->type) {
1696 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1697 case CONNMAN_NETWORK_TYPE_VENDOR:
1699 case CONNMAN_NETWORK_TYPE_ETHERNET:
1700 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1701 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1702 case CONNMAN_NETWORK_TYPE_CELLULAR:
1703 case CONNMAN_NETWORK_TYPE_WIFI:
1704 case CONNMAN_NETWORK_TYPE_WIMAX:
1705 if (network->group != NULL) {
1706 __connman_service_remove_from_network(network);
1708 g_free(network->group);
1709 network->group = NULL;
1714 if (network->driver->remove)
1715 network->driver->remove(network);
1718 static void network_change(struct connman_element *element)
1720 struct connman_network *network = element->network;
1722 DBG("element %p name %s", element, element->name);
1724 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1727 if (network->connected == FALSE)
1730 connman_element_unregister_children(element);
1732 connman_device_set_disconnected(network->device, TRUE);
1734 if (network->driver && network->driver->disconnect) {
1735 network->driver->disconnect(network);
1739 network->connected = FALSE;
1742 static struct connman_driver network_driver = {
1744 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1745 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1746 .probe = network_probe,
1747 .remove = network_remove,
1748 .change = network_change,
1751 int __connman_network_init(void)
1755 return connman_driver_register(&network_driver);
1758 void __connman_network_cleanup(void)
1762 connman_driver_unregister(&network_driver);