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->group);
177 g_free(network->node);
178 g_free(network->name);
179 g_free(network->address);
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;
201 DBG("identifier %s type %d", identifier, type);
203 network = g_try_new0(struct connman_network, 1);
207 DBG("network %p", network);
209 __connman_element_initialize(&network->element);
211 if (identifier == NULL) {
212 temp = g_strdup_printf("hidden_%d", hidden_counter++);
213 network->hidden = TRUE;
215 temp = g_strdup(identifier);
222 network->element.name = temp;
223 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
225 network->element.network = network;
226 network->element.destruct = network_destruct;
228 str = type2string(type);
230 connman_element_set_string(&network->element, "Type", str);
232 connman_element_set_uint8(&network->element, "Strength", strength);
234 network->type = type;
235 network->identifier = g_strdup(temp);
241 * connman_network_ref:
242 * @network: network structure
244 * Increase reference counter of network
246 struct connman_network *connman_network_ref(struct connman_network *network)
248 if (connman_element_ref(&network->element) == NULL)
255 * connman_network_unref:
256 * @network: network structure
258 * Decrease reference counter of network
260 void connman_network_unref(struct connman_network *network)
262 connman_element_unref(&network->element);
265 const char *__connman_network_get_type(struct connman_network *network)
267 return type2string(network->type);
271 * connman_network_get_type:
272 * @network: network structure
274 * Get type of network
276 enum connman_network_type connman_network_get_type(struct connman_network *network)
278 return network->type;
282 * connman_network_get_identifier:
283 * @network: network structure
285 * Get identifier of network
287 const char *connman_network_get_identifier(struct connman_network *network)
289 return network->identifier;
293 * connman_network_set_index:
294 * @network: network structure
295 * @index: index number
297 * Set index number of network
299 void connman_network_set_index(struct connman_network *network, int index)
301 struct connman_service *service;
302 struct connman_ipconfig *ipconfig;
304 service = __connman_service_lookup_from_network(network);
308 ipconfig = __connman_service_get_ip4config(service);
310 DBG("index %d service %p ip4config %p", network->element.index,
313 if (network->element.index < 0 && ipconfig == NULL) {
315 ipconfig = __connman_service_get_ip4config(service);
316 if (ipconfig == NULL)
318 * This is needed for plugins that havent set their
319 * ipconfig layer yet, due to not being able to get
320 * a network index prior to creating a service.
322 __connman_service_create_ip4config(service, index);
324 __connman_ipconfig_set_index(ipconfig, index);
327 /* If index changed, the index of ipconfig must be reset. */
328 if (ipconfig == NULL)
331 __connman_ipconfig_set_index(ipconfig, index);
335 network->element.index = index;
339 * connman_network_get_index:
340 * @network: network structure
342 * Get index number of network
344 int connman_network_get_index(struct connman_network *network)
346 return network->element.index;
350 * connman_network_get_element:
351 * @network: network structure
353 * Get connman_element of network
355 struct connman_element *connman_network_get_element(
356 struct connman_network *network)
358 return &network->element;
362 * connman_network_set_group:
363 * @network: network structure
366 * Set group name for automatic clustering
368 void connman_network_set_group(struct connman_network *network,
371 switch (network->type) {
372 case CONNMAN_NETWORK_TYPE_UNKNOWN:
373 case CONNMAN_NETWORK_TYPE_VENDOR:
375 case CONNMAN_NETWORK_TYPE_ETHERNET:
376 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
377 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
378 case CONNMAN_NETWORK_TYPE_CELLULAR:
379 case CONNMAN_NETWORK_TYPE_WIFI:
380 case CONNMAN_NETWORK_TYPE_WIMAX:
384 if (g_strcmp0(network->group, group) == 0) {
386 __connman_profile_update_network(network);
390 if (network->group != NULL) {
391 __connman_profile_remove_network(network);
393 g_free(network->group);
396 network->group = g_strdup(group);
398 if (network->group != NULL)
399 __connman_profile_add_network(network);
403 * connman_network_get_group:
404 * @network: network structure
406 * Get group name for automatic clustering
408 const char *connman_network_get_group(struct connman_network *network)
410 return network->group;
413 const char *__connman_network_get_ident(struct connman_network *network)
415 if (network->device == NULL)
418 return connman_device_get_ident(network->device);
421 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
423 switch (network->type) {
424 case CONNMAN_NETWORK_TYPE_UNKNOWN:
425 case CONNMAN_NETWORK_TYPE_VENDOR:
426 case CONNMAN_NETWORK_TYPE_ETHERNET:
427 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
428 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
429 case CONNMAN_NETWORK_TYPE_CELLULAR:
430 case CONNMAN_NETWORK_TYPE_WIMAX:
432 case CONNMAN_NETWORK_TYPE_WIFI:
433 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
435 if (network->strength > 0 && network->strength < 20)
443 connman_bool_t __connman_network_get_connecting(struct connman_network *network)
445 return network->connecting;
449 * connman_network_set_available:
450 * @network: network structure
451 * @available: availability state
453 * Change availability state of network (in range)
455 int connman_network_set_available(struct connman_network *network,
456 connman_bool_t available)
458 DBG("network %p available %d", network, available);
460 if (network->available == available)
463 network->available = available;
469 * connman_network_get_available:
470 * @network: network structure
472 * Get network available setting
474 connman_bool_t connman_network_get_available(struct connman_network *network)
476 if (network->hidden == TRUE)
479 return network->available;
483 * connman_network_set_associating:
484 * @network: network structure
485 * @associating: associating state
487 * Change associating state of network
489 int connman_network_set_associating(struct connman_network *network,
490 connman_bool_t associating)
492 DBG("network %p associating %d", network, associating);
494 if (network->associating == associating)
497 network->associating = associating;
499 if (associating == TRUE) {
500 struct connman_service *service;
502 service = __connman_service_lookup_from_network(network);
503 __connman_service_indicate_state(service,
504 CONNMAN_SERVICE_STATE_ASSOCIATION,
505 CONNMAN_IPCONFIG_TYPE_IPV4);
511 static void set_associate_error(struct connman_network *network)
513 struct connman_service *service;
515 if (network->associating == FALSE)
518 network->associating = FALSE;
520 service = __connman_service_lookup_from_network(network);
522 __connman_service_indicate_state(service,
523 CONNMAN_SERVICE_STATE_FAILURE,
524 CONNMAN_IPCONFIG_TYPE_IPV4);
527 static void set_configure_error(struct connman_network *network)
529 struct connman_service *service;
531 network->connecting = FALSE;
533 service = __connman_service_lookup_from_network(network);
535 __connman_service_indicate_state(service,
536 CONNMAN_SERVICE_STATE_FAILURE,
537 CONNMAN_IPCONFIG_TYPE_IPV4);
540 static void set_invalid_key_error(struct connman_network *network)
542 struct connman_service *service;
544 service = __connman_service_lookup_from_network(network);
546 __connman_service_indicate_error(service,
547 CONNMAN_SERVICE_ERROR_INVALID_KEY);
550 void connman_network_set_ipv4_method(struct connman_network *network,
551 enum connman_ipconfig_method method)
553 struct connman_service *service;
554 struct connman_ipconfig *ipconfig;
556 network->element.ipv4.method = method;
558 service = __connman_service_lookup_from_network(network);
562 ipconfig = __connman_service_get_ip4config(service);
563 if (ipconfig == NULL)
566 connman_ipconfig_set_method(ipconfig, method);
569 void connman_network_set_ipv6_method(struct connman_network *network,
570 enum connman_ipconfig_method method)
572 struct connman_service *service;
573 struct connman_ipconfig *ipconfig;
575 network->element.ipv6.method = method;
577 service = __connman_service_lookup_from_network(network);
581 ipconfig = __connman_service_get_ip6config(service);
582 if (ipconfig == NULL)
585 connman_ipconfig_set_method(ipconfig, method);
588 void connman_network_set_error(struct connman_network *network,
589 enum connman_network_error error)
591 DBG("nework %p, error %d", network, error);
593 network->connecting = FALSE;
596 case CONNMAN_NETWORK_ERROR_UNKNOWN:
598 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
599 set_associate_error(network);
601 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
602 set_configure_error(network);
604 case CONNMAN_NETWORK_ERROR_INVALID_KEY:
605 set_invalid_key_error(network);
610 void connman_network_clear_error(struct connman_network *network)
612 struct connman_service *service;
614 DBG("network %p", network);
619 if (network->connecting == TRUE || network->associating == TRUE)
622 service = __connman_service_lookup_from_network(network);
623 __connman_service_clear_error(service);
626 static void set_configuration(struct connman_network *network)
628 struct connman_service *service;
630 DBG("network %p", network);
632 __connman_device_increase_connections(network->device);
634 __connman_device_set_network(network->device, network);
636 connman_device_set_disconnected(network->device, FALSE);
638 service = __connman_service_lookup_from_network(network);
639 __connman_service_indicate_state(service,
640 CONNMAN_SERVICE_STATE_CONFIGURATION,
641 CONNMAN_IPCONFIG_TYPE_IPV4);
644 static int set_connected_fixed(struct connman_network *network)
646 struct connman_service *service;
647 struct connman_element *parent, *element;
651 service = __connman_service_lookup_from_network(network);
653 parent = connman_network_get_element(network);
655 set_configuration(network);
657 if (parent->ipv4.address == NULL)
660 if (parent->ipv4.netmask == NULL)
663 element = connman_element_create(NULL);
664 if (element == NULL) {
665 connman_error("Can not create connman_element");
669 element->type = CONNMAN_ELEMENT_TYPE_IPV4;
670 element->index = parent->index;
672 if (connman_element_register(element, parent) < 0) {
673 connman_error("Can not register connman_element");
677 network->connecting = FALSE;
679 connman_network_set_associating(network, FALSE);
684 static void set_connected_manual(struct connman_network *network)
686 struct connman_service *service;
687 struct connman_ipconfig *ipconfig;
688 const char *nameserver = NULL;
691 DBG("network %p", network);
693 service = __connman_service_lookup_from_network(network);
695 ipconfig = __connman_service_get_ip4config(service);
697 set_configuration(network);
699 err = __connman_ipconfig_set_address(ipconfig);
701 connman_network_set_error(network,
702 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
706 connman_element_get_value(&network->element,
707 CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
708 if (nameserver != NULL)
709 __connman_service_nameserver_append(service, nameserver);
711 __connman_ipconfig_set_gateway_to_element(ipconfig, &network->element);
713 network->connecting = FALSE;
715 connman_network_set_associating(network, FALSE);
717 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
718 CONNMAN_IPCONFIG_TYPE_IPV4);
721 static int set_connected_dhcp(struct connman_network *network)
723 struct connman_element *element;
726 DBG("network %p", network);
728 element = connman_element_create(NULL);
732 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
733 element->index = network->element.index;
735 error = connman_element_register(element, &network->element);
737 connman_element_unref(element);
741 set_configuration(network);
746 static int manual_ipv6_set(struct connman_network *network,
747 struct connman_ipconfig *ipconfig_ipv6)
749 struct connman_service *service;
752 service = __connman_service_lookup_from_network(network);
756 err = __connman_ipconfig_set_address(ipconfig_ipv6);
758 connman_network_set_error(network,
759 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
764 * READY state will be indicated by IPV4 setting
765 * gateway will be set by IPV4 setting
771 static void autoconf_ipv6_set(struct connman_network *network,
772 struct connman_ipconfig *ipconfig_ipv6)
774 struct connman_service *service;
775 struct connman_ipconfig *ipconfig;
776 const char *nameserver = NULL;
778 DBG("network %p", network);
780 service = __connman_service_lookup_from_network(network);
782 ipconfig = __connman_service_get_ip6config(service);
784 __connman_device_increase_connections(network->device);
786 __connman_device_set_network(network->device, network);
788 connman_device_set_disconnected(network->device, FALSE);
790 connman_element_get_value(&network->element,
791 CONNMAN_PROPERTY_ID_IPV6_NAMESERVER, &nameserver);
792 if (nameserver != NULL)
793 __connman_service_nameserver_append(service, nameserver);
795 network->connecting = FALSE;
797 __connman_service_indicate_state(service,
798 CONNMAN_SERVICE_STATE_READY,
799 CONNMAN_IPCONFIG_TYPE_IPV6);
802 static gboolean set_connected(gpointer user_data)
804 struct connman_network *network = user_data;
805 struct connman_service *service;
806 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
807 enum connman_ipconfig_method ipv4_method, ipv6_method;
809 service = __connman_service_lookup_from_network(network);
811 ipconfig_ipv4 = __connman_service_get_ip4config(service);
812 ipconfig_ipv6 = __connman_service_get_ip6config(service);
814 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
817 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
818 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
820 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
821 DBG("network connected %d", network->connected);
823 if (network->connected == TRUE) {
826 switch (ipv6_method) {
827 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
828 case CONNMAN_IPCONFIG_METHOD_OFF:
830 case CONNMAN_IPCONFIG_METHOD_AUTO:
831 autoconf_ipv6_set(network, ipconfig_ipv6);
833 case CONNMAN_IPCONFIG_METHOD_FIXED:
834 case CONNMAN_IPCONFIG_METHOD_MANUAL:
835 ret = manual_ipv6_set(network, ipconfig_ipv6);
837 connman_network_set_error(network,
838 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
842 case CONNMAN_IPCONFIG_METHOD_DHCP:
846 switch (ipv4_method) {
847 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
848 case CONNMAN_IPCONFIG_METHOD_OFF:
849 case CONNMAN_IPCONFIG_METHOD_AUTO:
851 case CONNMAN_IPCONFIG_METHOD_FIXED:
852 if (set_connected_fixed(network) < 0) {
853 connman_network_set_error(network,
854 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
858 case CONNMAN_IPCONFIG_METHOD_MANUAL:
859 set_connected_manual(network);
861 case CONNMAN_IPCONFIG_METHOD_DHCP:
862 if (set_connected_dhcp(network) < 0) {
863 connman_network_set_error(network,
864 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
870 struct connman_service *service;
872 connman_element_unregister_children(&network->element);
874 __connman_device_set_network(network->device, NULL);
875 network->hidden = FALSE;
877 service = __connman_service_lookup_from_network(network);
879 __connman_service_indicate_state(service,
880 CONNMAN_SERVICE_STATE_IDLE,
881 CONNMAN_IPCONFIG_TYPE_IPV4);
883 /* TODO: eventually the IPv6 disconnect state should be handled
886 __connman_service_indicate_state(service,
887 CONNMAN_SERVICE_STATE_DISCONNECT,
888 CONNMAN_IPCONFIG_TYPE_IPV6);
890 __connman_service_indicate_state(service,
891 CONNMAN_SERVICE_STATE_IDLE,
892 CONNMAN_IPCONFIG_TYPE_IPV6);
895 network->connecting = FALSE;
897 connman_network_set_associating(network, FALSE);
903 * connman_network_set_connected:
904 * @network: network structure
905 * @connected: connected state
907 * Change connected state of network
909 int connman_network_set_connected(struct connman_network *network,
910 connman_bool_t connected)
912 DBG("network %p connected %d", network, connected);
914 if ((network->connecting == TRUE || network->associating == TRUE) &&
915 connected == FALSE) {
916 connman_element_set_error(&network->element,
917 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
918 __connman_network_disconnect(network);
921 if (network->connected == connected)
924 if (connected == FALSE)
925 __connman_device_decrease_connections(network->device);
927 network->connected = connected;
929 set_connected(network);
935 * connman_network_get_connected:
936 * @network: network structure
938 * Get network connection status
940 connman_bool_t connman_network_get_connected(struct connman_network *network)
942 return network->connected;
946 * connman_network_get_associating:
947 * @network: network structure
949 * Get network associating status
951 connman_bool_t connman_network_get_associating(struct connman_network *network)
953 return network->associating;
957 * __connman_network_connect:
958 * @network: network structure
962 int __connman_network_connect(struct connman_network *network)
964 struct connman_service *service;
967 DBG("network %p", network);
969 if (network->connected == TRUE)
972 if (network->connecting == TRUE || network->associating == TRUE)
975 if (network->driver == NULL)
978 if (network->driver->connect == NULL)
981 if (network->device == NULL)
984 network->connecting = TRUE;
986 __connman_device_disconnect(network->device);
988 service = __connman_service_lookup_from_network(network);
990 err = network->driver->connect(network);
992 if (err == -EINPROGRESS)
993 connman_network_set_associating(network, TRUE);
995 network->connecting = FALSE;
996 network->hidden = FALSE;
1002 network->connected = TRUE;
1003 set_connected(network);
1009 * __connman_network_disconnect:
1010 * @network: network structure
1012 * Disconnect network
1014 int __connman_network_disconnect(struct connman_network *network)
1018 DBG("network %p", network);
1020 if (network->connected == FALSE && network->connecting == FALSE &&
1021 network->associating == FALSE)
1024 if (network->driver == NULL)
1027 if (network->driver->disconnect == NULL)
1030 network->connecting = FALSE;
1032 err = network->driver->disconnect(network);
1034 connman_network_set_connected(network, FALSE);
1035 set_connected(network);
1041 static int dhcp_start(struct connman_network *network)
1043 struct connman_element *element;
1046 element = connman_element_create(NULL);
1047 if (element == NULL)
1050 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
1051 element->index = network->element.index;
1053 error = connman_element_register(element, &network->element);
1055 connman_element_unref(element);
1062 static int dhcp_stop(struct connman_network *network)
1064 connman_element_unregister_children_type(&network->element,
1065 CONNMAN_ELEMENT_TYPE_CONNECTION);
1066 connman_element_unregister_children_type(&network->element,
1067 CONNMAN_ELEMENT_TYPE_IPV4);
1068 connman_element_unregister_children_type(&network->element,
1069 CONNMAN_ELEMENT_TYPE_DHCP);
1074 static int manual_ipv4_set(struct connman_network *network,
1075 struct connman_ipconfig *ipconfig)
1077 struct connman_service *service;
1080 service = __connman_service_lookup_from_network(network);
1081 if (service == NULL)
1084 err = __connman_ipconfig_set_address(ipconfig);
1086 connman_network_set_error(network,
1087 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1091 __connman_ipconfig_set_gateway_to_element(ipconfig, &network->element);
1093 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
1094 CONNMAN_IPCONFIG_TYPE_IPV4);
1099 int __connman_network_clear_ipconfig(struct connman_network *network,
1100 struct connman_ipconfig *ipconfig)
1102 struct connman_service *service;
1103 enum connman_ipconfig_method method;
1104 enum connman_ipconfig_type type;
1106 service = __connman_service_lookup_from_network(network);
1107 if (service == NULL)
1110 method = __connman_ipconfig_get_method(ipconfig);
1111 type = __connman_ipconfig_get_config_type(ipconfig);
1114 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1115 case CONNMAN_IPCONFIG_METHOD_OFF:
1116 case CONNMAN_IPCONFIG_METHOD_FIXED:
1117 case CONNMAN_IPCONFIG_METHOD_AUTO:
1119 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1120 connman_element_unregister_children_type(&network->element,
1121 CONNMAN_ELEMENT_TYPE_CONNECTION);
1122 __connman_ipconfig_clear_address(ipconfig);
1124 case CONNMAN_IPCONFIG_METHOD_DHCP:
1129 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1130 __connman_service_indicate_state(service,
1131 CONNMAN_SERVICE_STATE_CONFIGURATION,
1132 CONNMAN_IPCONFIG_TYPE_IPV6);
1133 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1134 __connman_service_indicate_state(service,
1135 CONNMAN_SERVICE_STATE_CONFIGURATION,
1136 CONNMAN_IPCONFIG_TYPE_IPV4);
1141 int __connman_network_set_ipconfig(struct connman_network *network,
1142 struct connman_ipconfig *ipconfig_ipv4,
1143 struct connman_ipconfig *ipconfig_ipv6)
1145 enum connman_ipconfig_method method;
1148 if (ipconfig_ipv6) {
1149 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1152 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1153 case CONNMAN_IPCONFIG_METHOD_OFF:
1155 case CONNMAN_IPCONFIG_METHOD_AUTO:
1156 autoconf_ipv6_set(network, ipconfig_ipv6);
1158 case CONNMAN_IPCONFIG_METHOD_FIXED:
1159 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1160 ret = manual_ipv6_set(network, ipconfig_ipv6);
1162 connman_network_set_error(network,
1163 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1167 case CONNMAN_IPCONFIG_METHOD_DHCP:
1172 if (ipconfig_ipv4) {
1173 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1176 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1177 case CONNMAN_IPCONFIG_METHOD_OFF:
1178 case CONNMAN_IPCONFIG_METHOD_FIXED:
1179 case CONNMAN_IPCONFIG_METHOD_AUTO:
1181 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1182 return manual_ipv4_set(network, ipconfig_ipv4);
1183 case CONNMAN_IPCONFIG_METHOD_DHCP:
1184 return dhcp_start(network);
1192 * connman_network_set_address:
1193 * @network: network structure
1194 * @address: binary address value
1195 * @size: binary address length
1197 * Set unique address value for network
1199 int connman_network_set_address(struct connman_network *network,
1200 const void *address, unsigned int size)
1202 const unsigned char *addr_octet = address;
1205 DBG("network %p size %d", network, size);
1210 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
1211 addr_octet[0], addr_octet[1], addr_octet[2],
1212 addr_octet[3], addr_octet[4], addr_octet[5]);
1216 g_free(network->address);
1217 network->address = str;
1219 return connman_element_set_string(&network->element,
1220 "Address", network->address);
1224 * connman_network_set_name:
1225 * @network: network structure
1228 * Set display name value for network
1230 int connman_network_set_name(struct connman_network *network,
1233 DBG("network %p name %s", network, name);
1235 g_free(network->name);
1236 network->name = g_strdup(name);
1238 return connman_element_set_string(&network->element, "Name", name);
1242 * connman_network_set_strength:
1243 * @network: network structure
1244 * @strength: strength value
1246 * Set signal strength value for network
1248 int connman_network_set_strength(struct connman_network *network,
1249 connman_uint8_t strength)
1251 DBG("network %p strengh %d", network, strength);
1253 network->strength = strength;
1255 return connman_element_set_uint8(&network->element,
1256 "Strength", strength);
1260 * connman_network_set_roaming:
1261 * @network: network structure
1262 * @roaming: roaming state
1264 * Set roaming state for network
1266 int connman_network_set_roaming(struct connman_network *network,
1267 connman_bool_t roaming)
1269 DBG("network %p roaming %d", network, roaming);
1271 network->roaming = roaming;
1273 return connman_element_set_bool(&network->element,
1274 "Roaming", roaming);
1278 * connman_network_set_string:
1279 * @network: network structure
1280 * @key: unique identifier
1281 * @value: string value
1283 * Set string value for specific key
1285 int connman_network_set_string(struct connman_network *network,
1286 const char *key, const char *value)
1290 DBG("network %p key %s value %s", network, key, value);
1292 if (g_strcmp0(key, "Name") == 0)
1293 return connman_network_set_name(network, value);
1295 if (g_str_equal(key, "Address") == TRUE) {
1296 g_free(network->address);
1297 network->address = g_strdup(value);
1298 } else if (g_str_equal(key, "Node") == TRUE) {
1299 g_free(network->node);
1300 network->node = g_strdup(value);
1301 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1302 g_free(network->wifi.mode);
1303 network->wifi.mode = g_strdup(value);
1304 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1305 g_free(network->wifi.security);
1306 network->wifi.security = g_strdup(value);
1307 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1308 g_free(network->wifi.passphrase);
1309 network->wifi.passphrase = g_strdup(value);
1310 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1311 g_free(network->wifi.eap);
1312 network->wifi.eap = g_strdup(value);
1313 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1314 g_free(network->wifi.identity);
1315 network->wifi.identity = g_strdup(value);
1316 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1317 g_free(network->wifi.ca_cert_path);
1318 network->wifi.ca_cert_path = g_strdup(value);
1319 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1320 g_free(network->wifi.client_cert_path);
1321 network->wifi.client_cert_path = g_strdup(value);
1322 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1323 g_free(network->wifi.private_key_path);
1324 network->wifi.private_key_path = g_strdup(value);
1325 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1326 g_free(network->wifi.private_key_passphrase);
1327 network->wifi.private_key_passphrase = g_strdup(value);
1328 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1329 g_free(network->wifi.phase2_auth);
1330 network->wifi.phase2_auth = g_strdup(value);
1331 } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
1332 g_free(network->wifi.pin_wps);
1333 network->wifi.pin_wps = g_strdup(value);
1336 err = connman_element_set_string(&network->element, key, value);
1340 if (network->driver == NULL)
1343 if (network->driver->setup)
1344 return network->driver->setup(network, key);
1350 * connman_network_get_string:
1351 * @network: network structure
1352 * @key: unique identifier
1354 * Get string value for specific key
1356 const char *connman_network_get_string(struct connman_network *network,
1359 DBG("network %p key %s", network, key);
1361 if (g_str_equal(key, "Address") == TRUE)
1362 return network->address;
1363 else if (g_str_equal(key, "Name") == TRUE)
1364 return network->name;
1365 else if (g_str_equal(key, "Node") == TRUE)
1366 return network->node;
1367 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1368 return network->wifi.mode;
1369 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1370 return network->wifi.security;
1371 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1372 return network->wifi.passphrase;
1373 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1374 return network->wifi.eap;
1375 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1376 return network->wifi.identity;
1377 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1378 return network->wifi.ca_cert_path;
1379 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1380 return network->wifi.client_cert_path;
1381 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1382 return network->wifi.private_key_path;
1383 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1384 return network->wifi.private_key_passphrase;
1385 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1386 return network->wifi.phase2_auth;
1387 else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
1388 return network->wifi.pin_wps;
1390 return connman_element_get_string(&network->element, key);
1394 * connman_network_set_bool:
1395 * @network: network structure
1396 * @key: unique identifier
1397 * @value: boolean value
1399 * Set boolean value for specific key
1401 int connman_network_set_bool(struct connman_network *network,
1402 const char *key, connman_bool_t value)
1404 DBG("network %p key %s value %d", network, key, value);
1406 if (g_strcmp0(key, "Roaming") == 0)
1407 return connman_network_set_roaming(network, value);
1408 else if (g_strcmp0(key, "WiFi.WPS") == 0)
1409 network->wifi.wps = value;
1410 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
1411 network->wifi.use_wps = value;
1413 return connman_element_set_bool(&network->element, key, value);
1417 * connman_network_get_bool:
1418 * @network: network structure
1419 * @key: unique identifier
1421 * Get boolean value for specific key
1423 connman_bool_t connman_network_get_bool(struct connman_network *network,
1426 DBG("network %p key %s", network, key);
1428 if (g_str_equal(key, "Roaming") == TRUE)
1429 return network->roaming;
1430 else if (g_str_equal(key, "WiFi.WPS") == TRUE)
1431 return network->wifi.wps;
1432 else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
1433 return network->wifi.use_wps;
1435 return connman_element_get_bool(&network->element, key);
1439 * connman_network_set_uint8:
1440 * @network: network structure
1441 * @key: unique identifier
1442 * @value: integer value
1444 * Set integer value for specific key
1446 int connman_network_set_uint8(struct connman_network *network,
1447 const char *key, connman_uint8_t value)
1449 DBG("network %p key %s value %d", network, key, value);
1451 if (g_strcmp0(key, "Strength") == 0)
1452 return connman_network_set_strength(network, value);
1454 return connman_element_set_uint8(&network->element, key, value);
1458 * connman_network_get_uint8:
1459 * @network: network structure
1460 * @key: unique identifier
1462 * Get integer value for specific key
1464 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1467 DBG("network %p key %s", network, key);
1469 if (g_str_equal(key, "Strength") == TRUE)
1470 return network->strength;
1472 return connman_element_get_uint8(&network->element, key);
1476 * connman_network_set_uint16:
1477 * @network: network structure
1478 * @key: unique identifier
1479 * @value: integer value
1481 * Set integer value for specific key
1483 int connman_network_set_uint16(struct connman_network *network,
1484 const char *key, connman_uint16_t value)
1486 DBG("network %p key %s value %d", network, key, value);
1488 if (g_str_equal(key, "Frequency") == TRUE)
1489 network->frequency = value;
1490 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1491 network->wifi.channel = value;
1497 * connman_network_get_uint16:
1498 * @network: network structure
1499 * @key: unique identifier
1501 * Get integer value for specific key
1503 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1506 DBG("network %p key %s", network, key);
1508 if (g_str_equal(key, "Frequency") == TRUE)
1509 return network->frequency;
1510 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1511 return network->wifi.channel;
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_strcmp0(key, "Address") == 0)
1531 return connman_network_set_address(network, data, size);
1533 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1534 g_free(network->wifi.ssid);
1535 network->wifi.ssid = g_try_malloc(size);
1536 if (network->wifi.ssid != NULL) {
1537 memcpy(network->wifi.ssid, data, size);
1538 network->wifi.ssid_len = size;
1540 network->wifi.ssid_len = 0;
1543 return connman_element_set_blob(&network->element, key, data, size);
1547 * connman_network_get_blob:
1548 * @network: network structure
1549 * @key: unique identifier
1550 * @size: pointer to blob size
1552 * Get binary blob value for specific key
1554 const void *connman_network_get_blob(struct connman_network *network,
1555 const char *key, unsigned int *size)
1557 DBG("network %p key %s", network, key);
1559 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1561 *size = network->wifi.ssid_len;
1562 return network->wifi.ssid;
1565 return connman_element_get_blob(&network->element, key, size);
1568 void __connman_network_set_device(struct connman_network *network,
1569 struct connman_device *device)
1571 network->device = device;
1575 * connman_network_get_device:
1576 * @network: network structure
1578 * Get parent device of network
1580 struct connman_device *connman_network_get_device(struct connman_network *network)
1582 return network->device;
1586 * connman_network_get_data:
1587 * @network: network structure
1589 * Get private network data pointer
1591 void *connman_network_get_data(struct connman_network *network)
1593 return network->driver_data;
1597 * connman_network_set_data:
1598 * @network: network structure
1599 * @data: data pointer
1601 * Set private network data pointer
1603 void connman_network_set_data(struct connman_network *network, void *data)
1605 network->driver_data = data;
1608 void connman_network_update(struct connman_network *network)
1610 switch (network->type) {
1611 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1612 case CONNMAN_NETWORK_TYPE_VENDOR:
1614 case CONNMAN_NETWORK_TYPE_ETHERNET:
1615 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1616 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1617 case CONNMAN_NETWORK_TYPE_CELLULAR:
1618 case CONNMAN_NETWORK_TYPE_WIFI:
1619 case CONNMAN_NETWORK_TYPE_WIMAX:
1623 if (network->group != NULL)
1624 __connman_service_update_from_network(network);
1629 static gboolean match_driver(struct connman_network *network,
1630 struct connman_network_driver *driver)
1632 if (network->type == driver->type ||
1633 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1639 static int network_probe(struct connman_element *element)
1641 struct connman_network *network = element->network;
1644 DBG("element %p name %s", element, element->name);
1646 if (network == NULL)
1649 for (list = driver_list; list; list = list->next) {
1650 struct connman_network_driver *driver = list->data;
1652 if (match_driver(network, driver) == FALSE)
1655 DBG("driver %p name %s", driver, driver->name);
1657 if (driver->probe(network) == 0) {
1658 network->driver = driver;
1663 if (network->driver == NULL)
1666 switch (network->type) {
1667 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1668 case CONNMAN_NETWORK_TYPE_VENDOR:
1670 case CONNMAN_NETWORK_TYPE_ETHERNET:
1671 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1672 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1673 case CONNMAN_NETWORK_TYPE_CELLULAR:
1674 case CONNMAN_NETWORK_TYPE_WIFI:
1675 case CONNMAN_NETWORK_TYPE_WIMAX:
1676 if (network->group != NULL)
1677 __connman_profile_add_network(network);
1684 static void network_remove(struct connman_element *element)
1686 struct connman_network *network = element->network;
1688 DBG("element %p name %s", element, element->name);
1690 if (network == NULL)
1693 if (network->driver == NULL)
1696 switch (network->type) {
1697 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1698 case CONNMAN_NETWORK_TYPE_VENDOR:
1700 case CONNMAN_NETWORK_TYPE_ETHERNET:
1701 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1702 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1703 case CONNMAN_NETWORK_TYPE_CELLULAR:
1704 case CONNMAN_NETWORK_TYPE_WIFI:
1705 case CONNMAN_NETWORK_TYPE_WIMAX:
1706 if (network->group != NULL) {
1707 __connman_profile_remove_network(network);
1709 g_free(network->group);
1710 network->group = NULL;
1715 if (network->driver->remove)
1716 network->driver->remove(network);
1719 static void network_change(struct connman_element *element)
1721 struct connman_network *network = element->network;
1723 DBG("element %p name %s", element, element->name);
1725 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1728 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1731 if (network->connected == FALSE)
1734 connman_element_unregister_children(element);
1736 connman_device_set_disconnected(network->device, TRUE);
1738 if (network->driver && network->driver->disconnect) {
1739 network->driver->disconnect(network);
1743 network->connected = FALSE;
1746 static struct connman_driver network_driver = {
1748 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1749 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1750 .probe = network_probe,
1751 .remove = network_remove,
1752 .change = network_change,
1755 int __connman_network_init(void)
1759 return connman_driver_register(&network_driver);
1762 void __connman_network_cleanup(void)
1766 connman_driver_unregister(&network_driver);