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;
47 struct connman_network_driver *driver;
50 connman_bool_t connecting;
51 connman_bool_t associating;
53 struct connman_device *device;
59 unsigned short channel;
65 char *client_cert_path;
66 char *private_key_path;
67 char *private_key_passphrase;
70 connman_bool_t use_wps;
75 static const char *type2string(enum connman_network_type type)
78 case CONNMAN_NETWORK_TYPE_UNKNOWN:
79 case CONNMAN_NETWORK_TYPE_VENDOR:
81 case CONNMAN_NETWORK_TYPE_ETHERNET:
83 case CONNMAN_NETWORK_TYPE_WIFI:
85 case CONNMAN_NETWORK_TYPE_WIMAX:
87 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
88 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
90 case CONNMAN_NETWORK_TYPE_CELLULAR:
97 connman_bool_t __connman_network_has_driver(struct connman_network *network)
99 if (network == NULL || network->driver == NULL)
105 static GSList *driver_list = NULL;
107 static gint compare_priority(gconstpointer a, gconstpointer b)
109 const struct connman_network_driver *driver1 = a;
110 const struct connman_network_driver *driver2 = b;
112 return driver2->priority - driver1->priority;
116 * connman_network_driver_register:
117 * @driver: network driver definition
119 * Register a new network driver
121 * Returns: %0 on success
123 int connman_network_driver_register(struct connman_network_driver *driver)
127 DBG("driver %p name %s", driver, driver->name);
129 for (list = driver_list; list; list = list->next) {
130 struct connman_network_driver *tmp = list->data;
132 if (tmp->type == driver->type)
137 driver_list = g_slist_insert_sorted(driver_list, driver,
144 * connman_network_driver_unregister:
145 * @driver: network driver definition
147 * Remove a previously registered network driver
149 void connman_network_driver_unregister(struct connman_network_driver *driver)
151 DBG("driver %p name %s", driver, driver->name);
153 driver_list = g_slist_remove(driver_list, driver);
156 static void network_destruct(struct connman_element *element)
158 struct connman_network *network = element->network;
160 DBG("element %p name %s", element, element->name);
162 g_free(network->wifi.ssid);
163 g_free(network->wifi.mode);
164 g_free(network->wifi.security);
165 g_free(network->wifi.passphrase);
166 g_free(network->wifi.eap);
167 g_free(network->wifi.identity);
168 g_free(network->wifi.ca_cert_path);
169 g_free(network->wifi.client_cert_path);
170 g_free(network->wifi.private_key_path);
171 g_free(network->wifi.private_key_passphrase);
172 g_free(network->wifi.phase2_auth);
173 g_free(network->wifi.pin_wps);
175 g_free(network->group);
176 g_free(network->node);
177 g_free(network->name);
178 g_free(network->identifier);
180 network->device = NULL;
184 * connman_network_create:
185 * @identifier: network identifier (for example an unqiue name)
187 * Allocate a new network and assign the #identifier to it.
189 * Returns: a newly-allocated #connman_network structure
191 struct connman_network *connman_network_create(const char *identifier,
192 enum connman_network_type type)
194 struct connman_network *network;
195 connman_uint8_t strength = 0;
199 DBG("identifier %s type %d", identifier, type);
201 network = g_try_new0(struct connman_network, 1);
205 DBG("network %p", network);
207 __connman_element_initialize(&network->element);
209 if (identifier == NULL) {
210 temp = g_strdup_printf("hidden_%d", hidden_counter++);
211 network->hidden = TRUE;
213 temp = g_strdup(identifier);
220 network->element.name = temp;
221 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
223 network->element.network = network;
224 network->element.destruct = network_destruct;
226 str = type2string(type);
228 connman_element_set_string(&network->element, "Type", str);
230 connman_element_set_uint8(&network->element, "Strength", strength);
232 network->type = type;
233 network->identifier = g_strdup(temp);
239 * connman_network_ref:
240 * @network: network structure
242 * Increase reference counter of network
244 struct connman_network *connman_network_ref(struct connman_network *network)
246 if (connman_element_ref(&network->element) == NULL)
253 * connman_network_unref:
254 * @network: network structure
256 * Decrease reference counter of network
258 void connman_network_unref(struct connman_network *network)
260 connman_element_unref(&network->element);
263 const char *__connman_network_get_type(struct connman_network *network)
265 return type2string(network->type);
269 * connman_network_get_type:
270 * @network: network structure
272 * Get type of network
274 enum connman_network_type connman_network_get_type(struct connman_network *network)
276 return network->type;
280 * connman_network_get_identifier:
281 * @network: network structure
283 * Get identifier of network
285 const char *connman_network_get_identifier(struct connman_network *network)
287 return network->identifier;
291 * connman_network_set_index:
292 * @network: network structure
293 * @index: index number
295 * Set index number of network
297 void connman_network_set_index(struct connman_network *network, int index)
299 struct connman_service *service;
300 struct connman_ipconfig *ipconfig;
302 service = __connman_service_lookup_from_network(network);
306 ipconfig = __connman_service_get_ip4config(service);
308 DBG("index %d service %p ip4config %p", network->element.index,
311 if (network->element.index < 0 && ipconfig == NULL) {
313 ipconfig = __connman_service_get_ip4config(service);
314 if (ipconfig == NULL)
316 * This is needed for plugins that havent set their
317 * ipconfig layer yet, due to not being able to get
318 * a network index prior to creating a service.
320 __connman_service_create_ip4config(service, index);
322 __connman_ipconfig_set_index(ipconfig, index);
325 /* If index changed, the index of ipconfig must be reset. */
326 if (ipconfig == NULL)
329 __connman_ipconfig_set_index(ipconfig, index);
333 network->element.index = index;
337 * connman_network_get_index:
338 * @network: network structure
340 * Get index number of network
342 int connman_network_get_index(struct connman_network *network)
344 return network->element.index;
348 * connman_network_get_element:
349 * @network: network structure
351 * Get connman_element of network
353 struct connman_element *connman_network_get_element(
354 struct connman_network *network)
356 return &network->element;
360 * connman_network_set_group:
361 * @network: network structure
364 * Set group name for automatic clustering
366 void connman_network_set_group(struct connman_network *network,
369 switch (network->type) {
370 case CONNMAN_NETWORK_TYPE_UNKNOWN:
371 case CONNMAN_NETWORK_TYPE_VENDOR:
373 case CONNMAN_NETWORK_TYPE_ETHERNET:
374 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
375 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
376 case CONNMAN_NETWORK_TYPE_CELLULAR:
377 case CONNMAN_NETWORK_TYPE_WIFI:
378 case CONNMAN_NETWORK_TYPE_WIMAX:
382 if (g_strcmp0(network->group, group) == 0) {
384 __connman_profile_update_network(network);
388 if (network->group != NULL) {
389 __connman_profile_remove_network(network);
391 g_free(network->group);
394 network->group = g_strdup(group);
396 if (network->group != NULL)
397 __connman_profile_add_network(network);
401 * connman_network_get_group:
402 * @network: network structure
404 * Get group name for automatic clustering
406 const char *connman_network_get_group(struct connman_network *network)
408 return network->group;
411 const char *__connman_network_get_ident(struct connman_network *network)
413 if (network->device == NULL)
416 return connman_device_get_ident(network->device);
419 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
421 switch (network->type) {
422 case CONNMAN_NETWORK_TYPE_UNKNOWN:
423 case CONNMAN_NETWORK_TYPE_VENDOR:
424 case CONNMAN_NETWORK_TYPE_ETHERNET:
425 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
426 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
427 case CONNMAN_NETWORK_TYPE_CELLULAR:
428 case CONNMAN_NETWORK_TYPE_WIMAX:
430 case CONNMAN_NETWORK_TYPE_WIFI:
431 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
433 if (network->strength > 0 && network->strength < 20)
441 connman_bool_t __connman_network_get_connecting(struct connman_network *network)
443 return network->connecting;
447 * connman_network_set_available:
448 * @network: network structure
449 * @available: availability state
451 * Change availability state of network (in range)
453 int connman_network_set_available(struct connman_network *network,
454 connman_bool_t available)
456 DBG("network %p available %d", network, available);
458 if (network->available == available)
461 network->available = available;
467 * connman_network_get_available:
468 * @network: network structure
470 * Get network available setting
472 connman_bool_t connman_network_get_available(struct connman_network *network)
474 if (network->hidden == TRUE)
477 return network->available;
481 * connman_network_set_associating:
482 * @network: network structure
483 * @associating: associating state
485 * Change associating state of network
487 int connman_network_set_associating(struct connman_network *network,
488 connman_bool_t associating)
490 DBG("network %p associating %d", network, associating);
492 if (network->associating == associating)
495 network->associating = associating;
497 if (associating == TRUE) {
498 struct connman_service *service;
500 service = __connman_service_lookup_from_network(network);
501 __connman_service_indicate_state(service,
502 CONNMAN_SERVICE_STATE_ASSOCIATION,
503 CONNMAN_IPCONFIG_TYPE_IPV4);
509 static void set_associate_error(struct connman_network *network)
511 struct connman_service *service;
513 if (network->associating == FALSE)
516 network->associating = FALSE;
518 service = __connman_service_lookup_from_network(network);
520 __connman_service_indicate_state(service,
521 CONNMAN_SERVICE_STATE_FAILURE,
522 CONNMAN_IPCONFIG_TYPE_IPV4);
525 static void set_configure_error(struct connman_network *network)
527 struct connman_service *service;
529 network->connecting = FALSE;
531 service = __connman_service_lookup_from_network(network);
533 __connman_service_indicate_state(service,
534 CONNMAN_SERVICE_STATE_FAILURE,
535 CONNMAN_IPCONFIG_TYPE_IPV4);
538 static void set_invalid_key_error(struct connman_network *network)
540 struct connman_service *service;
542 service = __connman_service_lookup_from_network(network);
544 __connman_service_indicate_error(service,
545 CONNMAN_SERVICE_ERROR_INVALID_KEY);
548 void connman_network_set_ipv4_method(struct connman_network *network,
549 enum connman_ipconfig_method method)
551 struct connman_service *service;
552 struct connman_ipconfig *ipconfig;
554 network->element.ipv4.method = method;
556 service = __connman_service_lookup_from_network(network);
560 ipconfig = __connman_service_get_ip4config(service);
561 if (ipconfig == NULL)
564 connman_ipconfig_set_method(ipconfig, method);
567 void connman_network_set_ipv6_method(struct connman_network *network,
568 enum connman_ipconfig_method method)
570 struct connman_service *service;
571 struct connman_ipconfig *ipconfig;
573 network->element.ipv6.method = method;
575 service = __connman_service_lookup_from_network(network);
579 ipconfig = __connman_service_get_ip6config(service);
580 if (ipconfig == NULL)
583 connman_ipconfig_set_method(ipconfig, method);
586 void connman_network_set_error(struct connman_network *network,
587 enum connman_network_error error)
589 DBG("nework %p, error %d", network, error);
591 network->connecting = FALSE;
594 case CONNMAN_NETWORK_ERROR_UNKNOWN:
596 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
597 set_associate_error(network);
599 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
600 set_configure_error(network);
602 case CONNMAN_NETWORK_ERROR_INVALID_KEY:
603 set_invalid_key_error(network);
608 void connman_network_clear_error(struct connman_network *network)
610 struct connman_service *service;
612 DBG("network %p", network);
617 if (network->connecting == TRUE || network->associating == TRUE)
620 service = __connman_service_lookup_from_network(network);
621 __connman_service_clear_error(service);
624 static void set_configuration(struct connman_network *network)
626 struct connman_service *service;
628 DBG("network %p", network);
630 __connman_device_increase_connections(network->device);
632 __connman_device_set_network(network->device, network);
634 connman_device_set_disconnected(network->device, FALSE);
636 service = __connman_service_lookup_from_network(network);
637 __connman_service_indicate_state(service,
638 CONNMAN_SERVICE_STATE_CONFIGURATION,
639 CONNMAN_IPCONFIG_TYPE_IPV4);
642 static int set_connected_fixed(struct connman_network *network)
644 struct connman_service *service;
645 struct connman_element *parent, *element;
649 service = __connman_service_lookup_from_network(network);
651 parent = connman_network_get_element(network);
653 set_configuration(network);
655 if (parent->ipv4.address == NULL)
658 if (parent->ipv4.netmask == NULL)
661 element = connman_element_create(NULL);
662 if (element == NULL) {
663 connman_error("Can not create connman_element");
667 element->type = CONNMAN_ELEMENT_TYPE_IPV4;
668 element->index = parent->index;
670 if (connman_element_register(element, parent) < 0) {
671 connman_error("Can not register connman_element");
675 network->connecting = FALSE;
677 connman_network_set_associating(network, FALSE);
682 static void set_connected_manual(struct connman_network *network)
684 struct connman_service *service;
685 struct connman_ipconfig *ipconfig;
686 const char *nameserver = NULL;
690 DBG("network %p", network);
692 service = __connman_service_lookup_from_network(network);
694 ipconfig = __connman_service_get_ip4config(service);
696 set_configuration(network);
698 err = __connman_ipconfig_set_address(ipconfig);
700 connman_network_set_error(network,
701 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
705 connman_element_get_value(&network->element,
706 CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
707 if (nameserver != NULL)
708 __connman_service_nameserver_append(service, nameserver);
710 connman_element_get_value(&network->element,
711 CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
713 __connman_ipconfig_set_gateway(ipconfig, gateway);
715 network->connecting = FALSE;
717 connman_network_set_associating(network, FALSE);
719 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
720 CONNMAN_IPCONFIG_TYPE_IPV4);
723 static int set_connected_dhcp(struct connman_network *network)
725 struct connman_element *element;
728 DBG("network %p", network);
730 element = connman_element_create(NULL);
734 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
735 element->index = network->element.index;
737 error = connman_element_register(element, &network->element);
739 connman_element_unref(element);
743 set_configuration(network);
748 static int manual_ipv6_set(struct connman_network *network,
749 struct connman_ipconfig *ipconfig_ipv6)
751 struct connman_service *service;
754 service = __connman_service_lookup_from_network(network);
758 err = __connman_ipconfig_set_address(ipconfig_ipv6);
760 connman_network_set_error(network,
761 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
766 * READY state will be indicated by IPV4 setting
767 * gateway will be set by IPV4 setting
773 static void autoconf_ipv6_set(struct connman_network *network)
775 struct connman_service *service;
776 struct connman_ipconfig *ipconfig;
777 const char *nameserver = NULL;
779 DBG("network %p", network);
781 service = __connman_service_lookup_from_network(network);
783 ipconfig = __connman_service_get_ip6config(service);
785 __connman_device_increase_connections(network->device);
787 __connman_device_set_network(network->device, network);
789 connman_device_set_disconnected(network->device, FALSE);
791 connman_element_get_value(&network->element,
792 CONNMAN_PROPERTY_ID_IPV6_NAMESERVER, &nameserver);
793 if (nameserver != NULL)
794 __connman_service_nameserver_append(service, nameserver);
796 network->connecting = FALSE;
798 __connman_service_indicate_state(service,
799 CONNMAN_SERVICE_STATE_READY,
800 CONNMAN_IPCONFIG_TYPE_IPV6);
803 static gboolean set_connected(gpointer user_data)
805 struct connman_network *network = user_data;
806 struct connman_service *service;
807 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
808 enum connman_ipconfig_method ipv4_method, ipv6_method;
810 service = __connman_service_lookup_from_network(network);
812 ipconfig_ipv4 = __connman_service_get_ip4config(service);
813 ipconfig_ipv6 = __connman_service_get_ip6config(service);
815 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
818 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
819 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
821 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
822 DBG("network connected %d", network->connected);
824 if (network->connected == TRUE) {
827 switch (ipv6_method) {
828 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
829 case CONNMAN_IPCONFIG_METHOD_OFF:
831 case CONNMAN_IPCONFIG_METHOD_AUTO:
832 autoconf_ipv6_set(network);
834 case CONNMAN_IPCONFIG_METHOD_FIXED:
835 case CONNMAN_IPCONFIG_METHOD_MANUAL:
836 ret = manual_ipv6_set(network, ipconfig_ipv6);
838 connman_network_set_error(network,
839 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
843 case CONNMAN_IPCONFIG_METHOD_DHCP:
847 switch (ipv4_method) {
848 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
849 case CONNMAN_IPCONFIG_METHOD_OFF:
850 case CONNMAN_IPCONFIG_METHOD_AUTO:
852 case CONNMAN_IPCONFIG_METHOD_FIXED:
853 if (set_connected_fixed(network) < 0) {
854 connman_network_set_error(network,
855 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
859 case CONNMAN_IPCONFIG_METHOD_MANUAL:
860 set_connected_manual(network);
862 case CONNMAN_IPCONFIG_METHOD_DHCP:
863 if (set_connected_dhcp(network) < 0) {
864 connman_network_set_error(network,
865 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
871 struct connman_service *service;
873 connman_element_unregister_children(&network->element);
875 __connman_device_set_network(network->device, NULL);
876 network->hidden = FALSE;
878 service = __connman_service_lookup_from_network(network);
880 __connman_service_indicate_state(service,
881 CONNMAN_SERVICE_STATE_IDLE,
882 CONNMAN_IPCONFIG_TYPE_IPV4);
884 /* TODO: eventually the IPv6 disconnect state should be handled
887 __connman_service_indicate_state(service,
888 CONNMAN_SERVICE_STATE_DISCONNECT,
889 CONNMAN_IPCONFIG_TYPE_IPV6);
891 __connman_service_indicate_state(service,
892 CONNMAN_SERVICE_STATE_IDLE,
893 CONNMAN_IPCONFIG_TYPE_IPV6);
896 network->connecting = FALSE;
898 connman_network_set_associating(network, FALSE);
904 * connman_network_set_connected:
905 * @network: network structure
906 * @connected: connected state
908 * Change connected state of network
910 int connman_network_set_connected(struct connman_network *network,
911 connman_bool_t connected)
913 DBG("network %p connected %d", network, connected);
915 if ((network->connecting == TRUE || network->associating == TRUE) &&
916 connected == FALSE) {
917 connman_element_set_error(&network->element,
918 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
919 __connman_network_disconnect(network);
922 if (network->connected == connected)
925 if (connected == FALSE)
926 __connman_device_decrease_connections(network->device);
928 network->connected = connected;
930 set_connected(network);
936 * connman_network_get_connected:
937 * @network: network structure
939 * Get network connection status
941 connman_bool_t connman_network_get_connected(struct connman_network *network)
943 return network->connected;
947 * connman_network_get_associating:
948 * @network: network structure
950 * Get network associating status
952 connman_bool_t connman_network_get_associating(struct connman_network *network)
954 return network->associating;
958 * __connman_network_connect:
959 * @network: network structure
963 int __connman_network_connect(struct connman_network *network)
965 struct connman_service *service;
968 DBG("network %p", network);
970 if (network->connected == TRUE)
973 if (network->connecting == TRUE || network->associating == TRUE)
976 if (network->driver == NULL)
979 if (network->driver->connect == NULL)
982 if (network->device == NULL)
985 network->connecting = TRUE;
987 __connman_device_disconnect(network->device);
989 service = __connman_service_lookup_from_network(network);
991 err = network->driver->connect(network);
993 if (err == -EINPROGRESS)
994 connman_network_set_associating(network, TRUE);
996 network->connecting = FALSE;
997 network->hidden = FALSE;
1003 network->connected = TRUE;
1004 set_connected(network);
1010 * __connman_network_disconnect:
1011 * @network: network structure
1013 * Disconnect network
1015 int __connman_network_disconnect(struct connman_network *network)
1019 DBG("network %p", network);
1021 if (network->connected == FALSE && network->connecting == FALSE &&
1022 network->associating == FALSE)
1025 if (network->driver == NULL)
1028 if (network->driver->disconnect == NULL)
1031 network->connecting = FALSE;
1033 err = network->driver->disconnect(network);
1035 connman_network_set_connected(network, FALSE);
1036 set_connected(network);
1042 static int dhcp_start(struct connman_network *network)
1044 struct connman_element *element;
1047 element = connman_element_create(NULL);
1048 if (element == NULL)
1051 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
1052 element->index = network->element.index;
1054 error = connman_element_register(element, &network->element);
1056 connman_element_unref(element);
1063 static int dhcp_stop(struct connman_network *network)
1065 connman_element_unregister_children_type(&network->element,
1066 CONNMAN_ELEMENT_TYPE_IPV4);
1067 connman_element_unregister_children_type(&network->element,
1068 CONNMAN_ELEMENT_TYPE_DHCP);
1073 static int manual_ipv4_set(struct connman_network *network,
1074 struct connman_ipconfig *ipconfig)
1076 struct connman_service *service;
1077 const char *gateway;
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_element_get_value(&network->element,
1092 CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
1093 if (gateway != NULL)
1094 __connman_ipconfig_set_gateway(ipconfig, gateway);
1096 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
1097 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_clear_address(ipconfig);
1125 case CONNMAN_IPCONFIG_METHOD_DHCP:
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 dhcp_start(network);
1193 * connman_network_set_name:
1194 * @network: network structure
1197 * Set display name value for network
1199 int connman_network_set_name(struct connman_network *network,
1202 DBG("network %p name %s", network, name);
1204 g_free(network->name);
1205 network->name = g_strdup(name);
1207 return connman_element_set_string(&network->element, "Name", name);
1211 * connman_network_set_strength:
1212 * @network: network structure
1213 * @strength: strength value
1215 * Set signal strength value for network
1217 int connman_network_set_strength(struct connman_network *network,
1218 connman_uint8_t strength)
1220 DBG("network %p strengh %d", network, strength);
1222 network->strength = strength;
1224 return connman_element_set_uint8(&network->element,
1225 "Strength", strength);
1229 * connman_network_set_roaming:
1230 * @network: network structure
1231 * @roaming: roaming state
1233 * Set roaming state for network
1235 int connman_network_set_roaming(struct connman_network *network,
1236 connman_bool_t roaming)
1238 DBG("network %p roaming %d", network, roaming);
1240 network->roaming = roaming;
1242 return connman_element_set_bool(&network->element,
1243 "Roaming", roaming);
1247 * connman_network_set_string:
1248 * @network: network structure
1249 * @key: unique identifier
1250 * @value: string value
1252 * Set string value for specific key
1254 int connman_network_set_string(struct connman_network *network,
1255 const char *key, const char *value)
1259 DBG("network %p key %s value %s", network, key, value);
1261 if (g_strcmp0(key, "Name") == 0)
1262 return connman_network_set_name(network, value);
1264 if (g_str_equal(key, "Node") == TRUE) {
1265 g_free(network->node);
1266 network->node = g_strdup(value);
1267 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1268 g_free(network->wifi.mode);
1269 network->wifi.mode = g_strdup(value);
1270 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1271 g_free(network->wifi.security);
1272 network->wifi.security = g_strdup(value);
1273 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1274 g_free(network->wifi.passphrase);
1275 network->wifi.passphrase = g_strdup(value);
1276 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1277 g_free(network->wifi.eap);
1278 network->wifi.eap = g_strdup(value);
1279 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1280 g_free(network->wifi.identity);
1281 network->wifi.identity = g_strdup(value);
1282 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1283 g_free(network->wifi.ca_cert_path);
1284 network->wifi.ca_cert_path = g_strdup(value);
1285 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1286 g_free(network->wifi.client_cert_path);
1287 network->wifi.client_cert_path = g_strdup(value);
1288 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1289 g_free(network->wifi.private_key_path);
1290 network->wifi.private_key_path = g_strdup(value);
1291 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1292 g_free(network->wifi.private_key_passphrase);
1293 network->wifi.private_key_passphrase = g_strdup(value);
1294 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1295 g_free(network->wifi.phase2_auth);
1296 network->wifi.phase2_auth = g_strdup(value);
1297 } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
1298 g_free(network->wifi.pin_wps);
1299 network->wifi.pin_wps = g_strdup(value);
1302 err = connman_element_set_string(&network->element, key, value);
1306 if (network->driver == NULL)
1309 if (network->driver->setup)
1310 return network->driver->setup(network, key);
1316 * connman_network_get_string:
1317 * @network: network structure
1318 * @key: unique identifier
1320 * Get string value for specific key
1322 const char *connman_network_get_string(struct connman_network *network,
1325 DBG("network %p key %s", network, key);
1327 if (g_str_equal(key, "Name") == TRUE)
1328 return network->name;
1329 else if (g_str_equal(key, "Node") == TRUE)
1330 return network->node;
1331 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1332 return network->wifi.mode;
1333 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1334 return network->wifi.security;
1335 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1336 return network->wifi.passphrase;
1337 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1338 return network->wifi.eap;
1339 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1340 return network->wifi.identity;
1341 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1342 return network->wifi.ca_cert_path;
1343 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1344 return network->wifi.client_cert_path;
1345 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1346 return network->wifi.private_key_path;
1347 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1348 return network->wifi.private_key_passphrase;
1349 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1350 return network->wifi.phase2_auth;
1351 else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
1352 return network->wifi.pin_wps;
1354 return connman_element_get_string(&network->element, key);
1358 * connman_network_set_bool:
1359 * @network: network structure
1360 * @key: unique identifier
1361 * @value: boolean value
1363 * Set boolean value for specific key
1365 int connman_network_set_bool(struct connman_network *network,
1366 const char *key, connman_bool_t value)
1368 DBG("network %p key %s value %d", network, key, value);
1370 if (g_strcmp0(key, "Roaming") == 0)
1371 return connman_network_set_roaming(network, value);
1372 else if (g_strcmp0(key, "WiFi.WPS") == 0)
1373 network->wifi.wps = value;
1374 else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
1375 network->wifi.use_wps = value;
1377 return connman_element_set_bool(&network->element, key, value);
1381 * connman_network_get_bool:
1382 * @network: network structure
1383 * @key: unique identifier
1385 * Get boolean value for specific key
1387 connman_bool_t connman_network_get_bool(struct connman_network *network,
1390 DBG("network %p key %s", network, key);
1392 if (g_str_equal(key, "Roaming") == TRUE)
1393 return network->roaming;
1394 else if (g_str_equal(key, "WiFi.WPS") == TRUE)
1395 return network->wifi.wps;
1396 else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
1397 return network->wifi.use_wps;
1399 return connman_element_get_bool(&network->element, key);
1403 * connman_network_set_uint8:
1404 * @network: network structure
1405 * @key: unique identifier
1406 * @value: integer value
1408 * Set integer value for specific key
1410 int connman_network_set_uint8(struct connman_network *network,
1411 const char *key, connman_uint8_t value)
1413 DBG("network %p key %s value %d", network, key, value);
1415 if (g_strcmp0(key, "Strength") == 0)
1416 return connman_network_set_strength(network, value);
1418 return connman_element_set_uint8(&network->element, key, value);
1422 * connman_network_get_uint8:
1423 * @network: network structure
1424 * @key: unique identifier
1426 * Get integer value for specific key
1428 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1431 DBG("network %p key %s", network, key);
1433 if (g_str_equal(key, "Strength") == TRUE)
1434 return network->strength;
1436 return connman_element_get_uint8(&network->element, key);
1440 * connman_network_set_uint16:
1441 * @network: network structure
1442 * @key: unique identifier
1443 * @value: integer value
1445 * Set integer value for specific key
1447 int connman_network_set_uint16(struct connman_network *network,
1448 const char *key, connman_uint16_t value)
1450 DBG("network %p key %s value %d", network, key, value);
1452 if (g_str_equal(key, "Frequency") == TRUE)
1453 network->frequency = value;
1454 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1455 network->wifi.channel = value;
1461 * connman_network_get_uint16:
1462 * @network: network structure
1463 * @key: unique identifier
1465 * Get integer value for specific key
1467 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1470 DBG("network %p key %s", network, key);
1472 if (g_str_equal(key, "Frequency") == TRUE)
1473 return network->frequency;
1474 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1475 return network->wifi.channel;
1481 * connman_network_set_blob:
1482 * @network: network structure
1483 * @key: unique identifier
1487 * Set binary blob value for specific key
1489 int connman_network_set_blob(struct connman_network *network,
1490 const char *key, const void *data, unsigned int size)
1492 DBG("network %p key %s size %d", network, key, size);
1494 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1495 g_free(network->wifi.ssid);
1496 network->wifi.ssid = g_try_malloc(size);
1497 if (network->wifi.ssid != NULL) {
1498 memcpy(network->wifi.ssid, data, size);
1499 network->wifi.ssid_len = size;
1501 network->wifi.ssid_len = 0;
1504 return connman_element_set_blob(&network->element, key, data, size);
1508 * connman_network_get_blob:
1509 * @network: network structure
1510 * @key: unique identifier
1511 * @size: pointer to blob size
1513 * Get binary blob value for specific key
1515 const void *connman_network_get_blob(struct connman_network *network,
1516 const char *key, unsigned int *size)
1518 DBG("network %p key %s", network, key);
1520 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1522 *size = network->wifi.ssid_len;
1523 return network->wifi.ssid;
1526 return connman_element_get_blob(&network->element, key, size);
1529 void __connman_network_set_device(struct connman_network *network,
1530 struct connman_device *device)
1532 network->device = device;
1536 * connman_network_get_device:
1537 * @network: network structure
1539 * Get parent device of network
1541 struct connman_device *connman_network_get_device(struct connman_network *network)
1543 return network->device;
1547 * connman_network_get_data:
1548 * @network: network structure
1550 * Get private network data pointer
1552 void *connman_network_get_data(struct connman_network *network)
1554 return network->driver_data;
1558 * connman_network_set_data:
1559 * @network: network structure
1560 * @data: data pointer
1562 * Set private network data pointer
1564 void connman_network_set_data(struct connman_network *network, void *data)
1566 network->driver_data = data;
1569 void connman_network_update(struct connman_network *network)
1571 switch (network->type) {
1572 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1573 case CONNMAN_NETWORK_TYPE_VENDOR:
1575 case CONNMAN_NETWORK_TYPE_ETHERNET:
1576 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1577 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1578 case CONNMAN_NETWORK_TYPE_CELLULAR:
1579 case CONNMAN_NETWORK_TYPE_WIFI:
1580 case CONNMAN_NETWORK_TYPE_WIMAX:
1584 if (network->group != NULL)
1585 __connman_service_update_from_network(network);
1590 static gboolean match_driver(struct connman_network *network,
1591 struct connman_network_driver *driver)
1593 if (network->type == driver->type ||
1594 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1600 static int network_probe(struct connman_element *element)
1602 struct connman_network *network = element->network;
1605 DBG("element %p name %s", element, element->name);
1607 if (network == NULL)
1610 for (list = driver_list; list; list = list->next) {
1611 struct connman_network_driver *driver = list->data;
1613 if (match_driver(network, driver) == FALSE)
1616 DBG("driver %p name %s", driver, driver->name);
1618 if (driver->probe(network) == 0) {
1619 network->driver = driver;
1624 if (network->driver == NULL)
1627 switch (network->type) {
1628 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1629 case CONNMAN_NETWORK_TYPE_VENDOR:
1631 case CONNMAN_NETWORK_TYPE_ETHERNET:
1632 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1633 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1634 case CONNMAN_NETWORK_TYPE_CELLULAR:
1635 case CONNMAN_NETWORK_TYPE_WIFI:
1636 case CONNMAN_NETWORK_TYPE_WIMAX:
1637 if (network->group != NULL)
1638 __connman_profile_add_network(network);
1645 static void network_remove(struct connman_element *element)
1647 struct connman_network *network = element->network;
1649 DBG("element %p name %s", element, element->name);
1651 if (network == NULL)
1654 if (network->driver == NULL)
1657 switch (network->type) {
1658 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1659 case CONNMAN_NETWORK_TYPE_VENDOR:
1661 case CONNMAN_NETWORK_TYPE_ETHERNET:
1662 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1663 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1664 case CONNMAN_NETWORK_TYPE_CELLULAR:
1665 case CONNMAN_NETWORK_TYPE_WIFI:
1666 case CONNMAN_NETWORK_TYPE_WIMAX:
1667 if (network->group != NULL) {
1668 __connman_profile_remove_network(network);
1670 g_free(network->group);
1671 network->group = NULL;
1676 if (network->driver->remove)
1677 network->driver->remove(network);
1680 static void network_change(struct connman_element *element)
1682 struct connman_network *network = element->network;
1684 DBG("element %p name %s", element, element->name);
1686 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1689 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1692 if (network->connected == FALSE)
1695 connman_element_unregister_children(element);
1697 connman_device_set_disconnected(network->device, TRUE);
1699 if (network->driver && network->driver->disconnect) {
1700 network->driver->disconnect(network);
1704 network->connected = FALSE;
1707 static struct connman_driver network_driver = {
1709 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1710 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1711 .probe = network_probe,
1712 .remove = network_remove,
1713 .change = network_change,
1716 int __connman_network_init(void)
1720 return connman_driver_register(&network_driver);
1723 void __connman_network_cleanup(void)
1727 connman_driver_unregister(&network_driver);