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;
692 DBG("network %p", network);
694 service = __connman_service_lookup_from_network(network);
696 ipconfig = __connman_service_get_ip4config(service);
698 set_configuration(network);
700 err = __connman_ipconfig_set_address(ipconfig);
702 connman_network_set_error(network,
703 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
707 connman_element_get_value(&network->element,
708 CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
709 if (nameserver != NULL)
710 __connman_service_nameserver_append(service, nameserver);
712 connman_element_get_value(&network->element,
713 CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
715 __connman_ipconfig_set_gateway(ipconfig, gateway);
717 network->connecting = FALSE;
719 connman_network_set_associating(network, FALSE);
721 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
722 CONNMAN_IPCONFIG_TYPE_IPV4);
725 static int set_connected_dhcp(struct connman_network *network)
727 struct connman_element *element;
730 DBG("network %p", network);
732 element = connman_element_create(NULL);
736 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
737 element->index = network->element.index;
739 error = connman_element_register(element, &network->element);
741 connman_element_unref(element);
745 set_configuration(network);
750 static int manual_ipv6_set(struct connman_network *network,
751 struct connman_ipconfig *ipconfig_ipv6)
753 struct connman_service *service;
756 service = __connman_service_lookup_from_network(network);
760 err = __connman_ipconfig_set_address(ipconfig_ipv6);
762 connman_network_set_error(network,
763 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
768 * READY state will be indicated by IPV4 setting
769 * gateway will be set by IPV4 setting
775 static void autoconf_ipv6_set(struct connman_network *network)
777 struct connman_service *service;
778 struct connman_ipconfig *ipconfig;
779 const char *nameserver = NULL;
781 DBG("network %p", network);
783 service = __connman_service_lookup_from_network(network);
785 ipconfig = __connman_service_get_ip6config(service);
787 __connman_device_increase_connections(network->device);
789 __connman_device_set_network(network->device, network);
791 connman_device_set_disconnected(network->device, FALSE);
793 connman_element_get_value(&network->element,
794 CONNMAN_PROPERTY_ID_IPV6_NAMESERVER, &nameserver);
795 if (nameserver != NULL)
796 __connman_service_nameserver_append(service, nameserver);
798 network->connecting = FALSE;
800 __connman_service_indicate_state(service,
801 CONNMAN_SERVICE_STATE_READY,
802 CONNMAN_IPCONFIG_TYPE_IPV6);
805 static gboolean set_connected(gpointer user_data)
807 struct connman_network *network = user_data;
808 struct connman_service *service;
809 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
810 enum connman_ipconfig_method ipv4_method, ipv6_method;
812 service = __connman_service_lookup_from_network(network);
814 ipconfig_ipv4 = __connman_service_get_ip4config(service);
815 ipconfig_ipv6 = __connman_service_get_ip6config(service);
817 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
820 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
821 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
823 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
824 DBG("network connected %d", network->connected);
826 if (network->connected == TRUE) {
829 switch (ipv6_method) {
830 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
831 case CONNMAN_IPCONFIG_METHOD_OFF:
833 case CONNMAN_IPCONFIG_METHOD_AUTO:
834 autoconf_ipv6_set(network);
836 case CONNMAN_IPCONFIG_METHOD_FIXED:
837 case CONNMAN_IPCONFIG_METHOD_MANUAL:
838 ret = manual_ipv6_set(network, ipconfig_ipv6);
840 connman_network_set_error(network,
841 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
845 case CONNMAN_IPCONFIG_METHOD_DHCP:
849 switch (ipv4_method) {
850 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
851 case CONNMAN_IPCONFIG_METHOD_OFF:
852 case CONNMAN_IPCONFIG_METHOD_AUTO:
854 case CONNMAN_IPCONFIG_METHOD_FIXED:
855 if (set_connected_fixed(network) < 0) {
856 connman_network_set_error(network,
857 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
861 case CONNMAN_IPCONFIG_METHOD_MANUAL:
862 set_connected_manual(network);
864 case CONNMAN_IPCONFIG_METHOD_DHCP:
865 if (set_connected_dhcp(network) < 0) {
866 connman_network_set_error(network,
867 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
873 struct connman_service *service;
875 connman_element_unregister_children(&network->element);
877 __connman_device_set_network(network->device, NULL);
878 network->hidden = FALSE;
880 service = __connman_service_lookup_from_network(network);
882 __connman_service_indicate_state(service,
883 CONNMAN_SERVICE_STATE_IDLE,
884 CONNMAN_IPCONFIG_TYPE_IPV4);
886 /* TODO: eventually the IPv6 disconnect state should be handled
889 __connman_service_indicate_state(service,
890 CONNMAN_SERVICE_STATE_DISCONNECT,
891 CONNMAN_IPCONFIG_TYPE_IPV6);
893 __connman_service_indicate_state(service,
894 CONNMAN_SERVICE_STATE_IDLE,
895 CONNMAN_IPCONFIG_TYPE_IPV6);
898 network->connecting = FALSE;
900 connman_network_set_associating(network, FALSE);
906 * connman_network_set_connected:
907 * @network: network structure
908 * @connected: connected state
910 * Change connected state of network
912 int connman_network_set_connected(struct connman_network *network,
913 connman_bool_t connected)
915 DBG("network %p connected %d", network, connected);
917 if ((network->connecting == TRUE || network->associating == TRUE) &&
918 connected == FALSE) {
919 connman_element_set_error(&network->element,
920 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
921 __connman_network_disconnect(network);
924 if (network->connected == connected)
927 if (connected == FALSE)
928 __connman_device_decrease_connections(network->device);
930 network->connected = connected;
932 set_connected(network);
938 * connman_network_get_connected:
939 * @network: network structure
941 * Get network connection status
943 connman_bool_t connman_network_get_connected(struct connman_network *network)
945 return network->connected;
949 * connman_network_get_associating:
950 * @network: network structure
952 * Get network associating status
954 connman_bool_t connman_network_get_associating(struct connman_network *network)
956 return network->associating;
960 * __connman_network_connect:
961 * @network: network structure
965 int __connman_network_connect(struct connman_network *network)
967 struct connman_service *service;
970 DBG("network %p", network);
972 if (network->connected == TRUE)
975 if (network->connecting == TRUE || network->associating == TRUE)
978 if (network->driver == NULL)
981 if (network->driver->connect == NULL)
984 if (network->device == NULL)
987 network->connecting = TRUE;
989 __connman_device_disconnect(network->device);
991 service = __connman_service_lookup_from_network(network);
993 err = network->driver->connect(network);
995 if (err == -EINPROGRESS)
996 connman_network_set_associating(network, TRUE);
998 network->connecting = FALSE;
999 network->hidden = FALSE;
1005 network->connected = TRUE;
1006 set_connected(network);
1012 * __connman_network_disconnect:
1013 * @network: network structure
1015 * Disconnect network
1017 int __connman_network_disconnect(struct connman_network *network)
1021 DBG("network %p", network);
1023 if (network->connected == FALSE && network->connecting == FALSE &&
1024 network->associating == FALSE)
1027 if (network->driver == NULL)
1030 if (network->driver->disconnect == NULL)
1033 network->connecting = FALSE;
1035 err = network->driver->disconnect(network);
1037 connman_network_set_connected(network, FALSE);
1038 set_connected(network);
1044 static int dhcp_start(struct connman_network *network)
1046 struct connman_element *element;
1049 element = connman_element_create(NULL);
1050 if (element == NULL)
1053 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
1054 element->index = network->element.index;
1056 error = connman_element_register(element, &network->element);
1058 connman_element_unref(element);
1065 static int dhcp_stop(struct connman_network *network)
1067 connman_element_unregister_children_type(&network->element,
1068 CONNMAN_ELEMENT_TYPE_IPV4);
1069 connman_element_unregister_children_type(&network->element,
1070 CONNMAN_ELEMENT_TYPE_DHCP);
1075 static int manual_ipv4_set(struct connman_network *network,
1076 struct connman_ipconfig *ipconfig)
1078 struct connman_service *service;
1079 const char *gateway;
1082 service = __connman_service_lookup_from_network(network);
1083 if (service == NULL)
1086 err = __connman_ipconfig_set_address(ipconfig);
1088 connman_network_set_error(network,
1089 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1093 connman_element_get_value(&network->element,
1094 CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
1095 if (gateway != NULL)
1096 __connman_ipconfig_set_gateway(ipconfig, gateway);
1098 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
1099 CONNMAN_IPCONFIG_TYPE_IPV4);
1104 int __connman_network_clear_ipconfig(struct connman_network *network,
1105 struct connman_ipconfig *ipconfig)
1107 struct connman_service *service;
1108 enum connman_ipconfig_method method;
1109 enum connman_ipconfig_type type;
1111 service = __connman_service_lookup_from_network(network);
1112 if (service == NULL)
1115 method = __connman_ipconfig_get_method(ipconfig);
1116 type = __connman_ipconfig_get_config_type(ipconfig);
1119 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1120 case CONNMAN_IPCONFIG_METHOD_OFF:
1121 case CONNMAN_IPCONFIG_METHOD_FIXED:
1122 case CONNMAN_IPCONFIG_METHOD_AUTO:
1124 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1125 __connman_ipconfig_clear_address(ipconfig);
1127 case CONNMAN_IPCONFIG_METHOD_DHCP:
1132 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1133 __connman_service_indicate_state(service,
1134 CONNMAN_SERVICE_STATE_CONFIGURATION,
1135 CONNMAN_IPCONFIG_TYPE_IPV6);
1136 else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1137 __connman_service_indicate_state(service,
1138 CONNMAN_SERVICE_STATE_CONFIGURATION,
1139 CONNMAN_IPCONFIG_TYPE_IPV4);
1144 int __connman_network_set_ipconfig(struct connman_network *network,
1145 struct connman_ipconfig *ipconfig_ipv4,
1146 struct connman_ipconfig *ipconfig_ipv6)
1148 enum connman_ipconfig_method method;
1151 if (ipconfig_ipv6) {
1152 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1155 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1156 case CONNMAN_IPCONFIG_METHOD_OFF:
1158 case CONNMAN_IPCONFIG_METHOD_AUTO:
1159 autoconf_ipv6_set(network);
1161 case CONNMAN_IPCONFIG_METHOD_FIXED:
1162 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1163 ret = manual_ipv6_set(network, ipconfig_ipv6);
1165 connman_network_set_error(network,
1166 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1170 case CONNMAN_IPCONFIG_METHOD_DHCP:
1175 if (ipconfig_ipv4) {
1176 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1179 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1180 case CONNMAN_IPCONFIG_METHOD_OFF:
1181 case CONNMAN_IPCONFIG_METHOD_FIXED:
1182 case CONNMAN_IPCONFIG_METHOD_AUTO:
1184 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1185 return manual_ipv4_set(network, ipconfig_ipv4);
1186 case CONNMAN_IPCONFIG_METHOD_DHCP:
1187 return dhcp_start(network);
1195 * connman_network_set_address:
1196 * @network: network structure
1197 * @address: binary address value
1198 * @size: binary address length
1200 * Set unique address value for network
1202 int connman_network_set_address(struct connman_network *network,
1203 const void *address, unsigned int size)
1205 const unsigned char *addr_octet = address;
1208 DBG("network %p size %d", network, size);
1213 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
1214 addr_octet[0], addr_octet[1], addr_octet[2],
1215 addr_octet[3], addr_octet[4], addr_octet[5]);
1219 g_free(network->address);
1220 network->address = str;
1222 return connman_element_set_string(&network->element,
1223 "Address", network->address);
1227 * connman_network_set_name:
1228 * @network: network structure
1231 * Set display name value for network
1233 int connman_network_set_name(struct connman_network *network,
1236 DBG("network %p name %s", network, name);
1238 g_free(network->name);
1239 network->name = g_strdup(name);
1241 return connman_element_set_string(&network->element, "Name", name);
1245 * connman_network_set_strength:
1246 * @network: network structure
1247 * @strength: strength value
1249 * Set signal strength value for network
1251 int connman_network_set_strength(struct connman_network *network,
1252 connman_uint8_t strength)
1254 DBG("network %p strengh %d", network, strength);
1256 network->strength = strength;
1258 return connman_element_set_uint8(&network->element,
1259 "Strength", strength);
1263 * connman_network_set_roaming:
1264 * @network: network structure
1265 * @roaming: roaming state
1267 * Set roaming state for network
1269 int connman_network_set_roaming(struct connman_network *network,
1270 connman_bool_t roaming)
1272 DBG("network %p roaming %d", network, roaming);
1274 network->roaming = roaming;
1276 return connman_element_set_bool(&network->element,
1277 "Roaming", roaming);
1281 * connman_network_set_string:
1282 * @network: network structure
1283 * @key: unique identifier
1284 * @value: string value
1286 * Set string value for specific key
1288 int connman_network_set_string(struct connman_network *network,
1289 const char *key, const char *value)
1293 DBG("network %p key %s value %s", network, key, value);
1295 if (g_strcmp0(key, "Name") == 0)
1296 return connman_network_set_name(network, value);
1298 if (g_str_equal(key, "Address") == TRUE) {
1299 g_free(network->address);
1300 network->address = g_strdup(value);
1301 } else if (g_str_equal(key, "Node") == TRUE) {
1302 g_free(network->node);
1303 network->node = g_strdup(value);
1304 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1305 g_free(network->wifi.mode);
1306 network->wifi.mode = g_strdup(value);
1307 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1308 g_free(network->wifi.security);
1309 network->wifi.security = g_strdup(value);
1310 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1311 g_free(network->wifi.passphrase);
1312 network->wifi.passphrase = g_strdup(value);
1313 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1314 g_free(network->wifi.eap);
1315 network->wifi.eap = g_strdup(value);
1316 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1317 g_free(network->wifi.identity);
1318 network->wifi.identity = g_strdup(value);
1319 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1320 g_free(network->wifi.ca_cert_path);
1321 network->wifi.ca_cert_path = g_strdup(value);
1322 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1323 g_free(network->wifi.client_cert_path);
1324 network->wifi.client_cert_path = g_strdup(value);
1325 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1326 g_free(network->wifi.private_key_path);
1327 network->wifi.private_key_path = g_strdup(value);
1328 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1329 g_free(network->wifi.private_key_passphrase);
1330 network->wifi.private_key_passphrase = g_strdup(value);
1331 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1332 g_free(network->wifi.phase2_auth);
1333 network->wifi.phase2_auth = g_strdup(value);
1334 } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
1335 g_free(network->wifi.pin_wps);
1336 network->wifi.pin_wps = g_strdup(value);
1339 err = connman_element_set_string(&network->element, key, value);
1343 if (network->driver == NULL)
1346 if (network->driver->setup)
1347 return network->driver->setup(network, key);
1353 * connman_network_get_string:
1354 * @network: network structure
1355 * @key: unique identifier
1357 * Get string value for specific key
1359 const char *connman_network_get_string(struct connman_network *network,
1362 DBG("network %p key %s", network, key);
1364 if (g_str_equal(key, "Address") == TRUE)
1365 return network->address;
1366 else if (g_str_equal(key, "Name") == TRUE)
1367 return network->name;
1368 else if (g_str_equal(key, "Node") == TRUE)
1369 return network->node;
1370 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1371 return network->wifi.mode;
1372 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1373 return network->wifi.security;
1374 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1375 return network->wifi.passphrase;
1376 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1377 return network->wifi.eap;
1378 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1379 return network->wifi.identity;
1380 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1381 return network->wifi.ca_cert_path;
1382 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1383 return network->wifi.client_cert_path;
1384 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1385 return network->wifi.private_key_path;
1386 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1387 return network->wifi.private_key_passphrase;
1388 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1389 return network->wifi.phase2_auth;
1390 else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
1391 return network->wifi.pin_wps;
1393 return connman_element_get_string(&network->element, key);
1397 * connman_network_set_bool:
1398 * @network: network structure
1399 * @key: unique identifier
1400 * @value: boolean value
1402 * Set boolean value for specific key
1404 int connman_network_set_bool(struct connman_network *network,
1405 const char *key, connman_bool_t value)
1407 DBG("network %p key %s value %d", network, key, value);
1409 if (g_strcmp0(key, "Roaming") == 0)
1410 return connman_network_set_roaming(network, value);
1411 else if (g_strcmp0(key, "WiFi.WPS") == 0)
1412 network->wifi.wps = value;
1413 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
1414 network->wifi.use_wps = value;
1416 return connman_element_set_bool(&network->element, key, value);
1420 * connman_network_get_bool:
1421 * @network: network structure
1422 * @key: unique identifier
1424 * Get boolean value for specific key
1426 connman_bool_t connman_network_get_bool(struct connman_network *network,
1429 DBG("network %p key %s", network, key);
1431 if (g_str_equal(key, "Roaming") == TRUE)
1432 return network->roaming;
1433 else if (g_str_equal(key, "WiFi.WPS") == TRUE)
1434 return network->wifi.wps;
1435 else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
1436 return network->wifi.use_wps;
1438 return connman_element_get_bool(&network->element, key);
1442 * connman_network_set_uint8:
1443 * @network: network structure
1444 * @key: unique identifier
1445 * @value: integer value
1447 * Set integer value for specific key
1449 int connman_network_set_uint8(struct connman_network *network,
1450 const char *key, connman_uint8_t value)
1452 DBG("network %p key %s value %d", network, key, value);
1454 if (g_strcmp0(key, "Strength") == 0)
1455 return connman_network_set_strength(network, value);
1457 return connman_element_set_uint8(&network->element, key, value);
1461 * connman_network_get_uint8:
1462 * @network: network structure
1463 * @key: unique identifier
1465 * Get integer value for specific key
1467 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1470 DBG("network %p key %s", network, key);
1472 if (g_str_equal(key, "Strength") == TRUE)
1473 return network->strength;
1475 return connman_element_get_uint8(&network->element, key);
1479 * connman_network_set_uint16:
1480 * @network: network structure
1481 * @key: unique identifier
1482 * @value: integer value
1484 * Set integer value for specific key
1486 int connman_network_set_uint16(struct connman_network *network,
1487 const char *key, connman_uint16_t value)
1489 DBG("network %p key %s value %d", network, key, value);
1491 if (g_str_equal(key, "Frequency") == TRUE)
1492 network->frequency = value;
1493 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1494 network->wifi.channel = value;
1500 * connman_network_get_uint16:
1501 * @network: network structure
1502 * @key: unique identifier
1504 * Get integer value for specific key
1506 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1509 DBG("network %p key %s", network, key);
1511 if (g_str_equal(key, "Frequency") == TRUE)
1512 return network->frequency;
1513 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1514 return network->wifi.channel;
1520 * connman_network_set_blob:
1521 * @network: network structure
1522 * @key: unique identifier
1526 * Set binary blob value for specific key
1528 int connman_network_set_blob(struct connman_network *network,
1529 const char *key, const void *data, unsigned int size)
1531 DBG("network %p key %s size %d", network, key, size);
1533 if (g_strcmp0(key, "Address") == 0)
1534 return connman_network_set_address(network, data, size);
1536 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1537 g_free(network->wifi.ssid);
1538 network->wifi.ssid = g_try_malloc(size);
1539 if (network->wifi.ssid != NULL) {
1540 memcpy(network->wifi.ssid, data, size);
1541 network->wifi.ssid_len = size;
1543 network->wifi.ssid_len = 0;
1546 return connman_element_set_blob(&network->element, key, data, size);
1550 * connman_network_get_blob:
1551 * @network: network structure
1552 * @key: unique identifier
1553 * @size: pointer to blob size
1555 * Get binary blob value for specific key
1557 const void *connman_network_get_blob(struct connman_network *network,
1558 const char *key, unsigned int *size)
1560 DBG("network %p key %s", network, key);
1562 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1564 *size = network->wifi.ssid_len;
1565 return network->wifi.ssid;
1568 return connman_element_get_blob(&network->element, key, size);
1571 void __connman_network_set_device(struct connman_network *network,
1572 struct connman_device *device)
1574 network->device = device;
1578 * connman_network_get_device:
1579 * @network: network structure
1581 * Get parent device of network
1583 struct connman_device *connman_network_get_device(struct connman_network *network)
1585 return network->device;
1589 * connman_network_get_data:
1590 * @network: network structure
1592 * Get private network data pointer
1594 void *connman_network_get_data(struct connman_network *network)
1596 return network->driver_data;
1600 * connman_network_set_data:
1601 * @network: network structure
1602 * @data: data pointer
1604 * Set private network data pointer
1606 void connman_network_set_data(struct connman_network *network, void *data)
1608 network->driver_data = data;
1611 void connman_network_update(struct connman_network *network)
1613 switch (network->type) {
1614 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1615 case CONNMAN_NETWORK_TYPE_VENDOR:
1617 case CONNMAN_NETWORK_TYPE_ETHERNET:
1618 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1619 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1620 case CONNMAN_NETWORK_TYPE_CELLULAR:
1621 case CONNMAN_NETWORK_TYPE_WIFI:
1622 case CONNMAN_NETWORK_TYPE_WIMAX:
1626 if (network->group != NULL)
1627 __connman_service_update_from_network(network);
1632 static gboolean match_driver(struct connman_network *network,
1633 struct connman_network_driver *driver)
1635 if (network->type == driver->type ||
1636 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1642 static int network_probe(struct connman_element *element)
1644 struct connman_network *network = element->network;
1647 DBG("element %p name %s", element, element->name);
1649 if (network == NULL)
1652 for (list = driver_list; list; list = list->next) {
1653 struct connman_network_driver *driver = list->data;
1655 if (match_driver(network, driver) == FALSE)
1658 DBG("driver %p name %s", driver, driver->name);
1660 if (driver->probe(network) == 0) {
1661 network->driver = driver;
1666 if (network->driver == NULL)
1669 switch (network->type) {
1670 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1671 case CONNMAN_NETWORK_TYPE_VENDOR:
1673 case CONNMAN_NETWORK_TYPE_ETHERNET:
1674 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1675 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1676 case CONNMAN_NETWORK_TYPE_CELLULAR:
1677 case CONNMAN_NETWORK_TYPE_WIFI:
1678 case CONNMAN_NETWORK_TYPE_WIMAX:
1679 if (network->group != NULL)
1680 __connman_profile_add_network(network);
1687 static void network_remove(struct connman_element *element)
1689 struct connman_network *network = element->network;
1691 DBG("element %p name %s", element, element->name);
1693 if (network == NULL)
1696 if (network->driver == NULL)
1699 switch (network->type) {
1700 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1701 case CONNMAN_NETWORK_TYPE_VENDOR:
1703 case CONNMAN_NETWORK_TYPE_ETHERNET:
1704 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1705 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1706 case CONNMAN_NETWORK_TYPE_CELLULAR:
1707 case CONNMAN_NETWORK_TYPE_WIFI:
1708 case CONNMAN_NETWORK_TYPE_WIMAX:
1709 if (network->group != NULL) {
1710 __connman_profile_remove_network(network);
1712 g_free(network->group);
1713 network->group = NULL;
1718 if (network->driver->remove)
1719 network->driver->remove(network);
1722 static void network_change(struct connman_element *element)
1724 struct connman_network *network = element->network;
1726 DBG("element %p name %s", element, element->name);
1728 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1731 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1734 if (network->connected == FALSE)
1737 connman_element_unregister_children(element);
1739 connman_device_set_disconnected(network->device, TRUE);
1741 if (network->driver && network->driver->disconnect) {
1742 network->driver->disconnect(network);
1746 network->connected = FALSE;
1749 static struct connman_driver network_driver = {
1751 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1752 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1753 .probe = network_probe,
1754 .remove = network_remove,
1755 .change = network_change,
1758 int __connman_network_init(void)
1762 return connman_driver_register(&network_driver);
1765 void __connman_network_cleanup(void)
1769 connman_driver_unregister(&network_driver);