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;
73 static const char *type2string(enum connman_network_type type)
76 case CONNMAN_NETWORK_TYPE_UNKNOWN:
77 case CONNMAN_NETWORK_TYPE_VENDOR:
79 case CONNMAN_NETWORK_TYPE_ETHERNET:
81 case CONNMAN_NETWORK_TYPE_WIFI:
83 case CONNMAN_NETWORK_TYPE_WIMAX:
85 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
86 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
88 case CONNMAN_NETWORK_TYPE_CELLULAR:
95 connman_bool_t __connman_network_has_driver(struct connman_network *network)
97 if (network == NULL || network->driver == NULL)
103 static GSList *driver_list = NULL;
105 static gint compare_priority(gconstpointer a, gconstpointer b)
107 const struct connman_network_driver *driver1 = a;
108 const struct connman_network_driver *driver2 = b;
110 return driver2->priority - driver1->priority;
114 * connman_network_driver_register:
115 * @driver: network driver definition
117 * Register a new network driver
119 * Returns: %0 on success
121 int connman_network_driver_register(struct connman_network_driver *driver)
125 DBG("driver %p name %s", driver, driver->name);
127 for (list = driver_list; list; list = list->next) {
128 struct connman_network_driver *tmp = list->data;
130 if (tmp->type == driver->type)
135 driver_list = g_slist_insert_sorted(driver_list, driver,
142 * connman_network_driver_unregister:
143 * @driver: network driver definition
145 * Remove a previously registered network driver
147 void connman_network_driver_unregister(struct connman_network_driver *driver)
149 DBG("driver %p name %s", driver, driver->name);
151 driver_list = g_slist_remove(driver_list, driver);
154 static void network_destruct(struct connman_element *element)
156 struct connman_network *network = element->network;
158 DBG("element %p name %s", element, element->name);
160 g_free(network->wifi.ssid);
161 g_free(network->wifi.mode);
162 g_free(network->wifi.security);
163 g_free(network->wifi.passphrase);
165 g_free(network->group);
166 g_free(network->node);
167 g_free(network->name);
168 g_free(network->address);
169 g_free(network->identifier);
171 network->device = NULL;
175 * connman_network_create:
176 * @identifier: network identifier (for example an unqiue name)
178 * Allocate a new network and assign the #identifier to it.
180 * Returns: a newly-allocated #connman_network structure
182 struct connman_network *connman_network_create(const char *identifier,
183 enum connman_network_type type)
185 struct connman_network *network;
186 connman_uint8_t strength = 0;
190 DBG("identifier %s type %d", identifier, type);
192 network = g_try_new0(struct connman_network, 1);
196 DBG("network %p", network);
198 __connman_element_initialize(&network->element);
200 if (identifier == NULL) {
201 temp = g_strdup_printf("hidden_%d", hidden_counter++);
202 network->hidden = TRUE;
204 temp = g_strdup(identifier);
211 network->element.name = temp;
212 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
214 network->element.network = network;
215 network->element.destruct = network_destruct;
217 str = type2string(type);
219 connman_element_set_string(&network->element, "Type", str);
221 connman_element_set_uint8(&network->element, "Strength", strength);
223 network->type = type;
224 network->identifier = g_strdup(temp);
230 * connman_network_ref:
231 * @network: network structure
233 * Increase reference counter of network
235 struct connman_network *connman_network_ref(struct connman_network *network)
237 if (connman_element_ref(&network->element) == NULL)
244 * connman_network_unref:
245 * @network: network structure
247 * Decrease reference counter of network
249 void connman_network_unref(struct connman_network *network)
251 connman_element_unref(&network->element);
254 const char *__connman_network_get_type(struct connman_network *network)
256 return type2string(network->type);
260 * connman_network_get_type:
261 * @network: network structure
263 * Get type of network
265 enum connman_network_type connman_network_get_type(struct connman_network *network)
267 return network->type;
271 * connman_network_get_identifier:
272 * @network: network structure
274 * Get identifier of network
276 const char *connman_network_get_identifier(struct connman_network *network)
278 return network->identifier;
282 * connman_network_set_index:
283 * @network: network structure
284 * @index: index number
286 * Set index number of network
288 void connman_network_set_index(struct connman_network *network, int index)
290 struct connman_service *service;
291 struct connman_ipconfig *ipconfig;
293 service = __connman_service_lookup_from_network(network);
297 ipconfig = __connman_service_get_ip4config(service);
299 DBG("index %d service %p ip4config %p", network->element.index,
302 if (network->element.index < 0 && ipconfig == NULL) {
304 ipconfig = __connman_service_get_ip4config(service);
305 if (ipconfig == NULL)
307 * This is needed for plugins that havent set their
308 * ipconfig layer yet, due to not being able to get
309 * a network index prior to creating a service.
311 __connman_service_create_ip4config(service, index);
313 __connman_ipconfig_set_index(ipconfig, index);
316 /* If index changed, the index of ipconfig must be reset. */
317 if (ipconfig == NULL)
320 __connman_ipconfig_set_index(ipconfig, index);
324 network->element.index = index;
328 * connman_network_get_index:
329 * @network: network structure
331 * Get index number of network
333 int connman_network_get_index(struct connman_network *network)
335 return network->element.index;
339 * connman_network_get_element:
340 * @network: network structure
342 * Get connman_element of network
344 struct connman_element *connman_network_get_element(
345 struct connman_network *network)
347 return &network->element;
351 * connman_network_set_group:
352 * @network: network structure
355 * Set group name for automatic clustering
357 void connman_network_set_group(struct connman_network *network,
360 switch (network->type) {
361 case CONNMAN_NETWORK_TYPE_UNKNOWN:
362 case CONNMAN_NETWORK_TYPE_VENDOR:
364 case CONNMAN_NETWORK_TYPE_ETHERNET:
365 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
366 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
367 case CONNMAN_NETWORK_TYPE_CELLULAR:
368 case CONNMAN_NETWORK_TYPE_WIFI:
369 case CONNMAN_NETWORK_TYPE_WIMAX:
373 if (g_strcmp0(network->group, group) == 0) {
375 __connman_profile_update_network(network);
379 if (network->group != NULL) {
380 __connman_profile_remove_network(network);
382 g_free(network->group);
385 network->group = g_strdup(group);
387 if (network->group != NULL)
388 __connman_profile_add_network(network);
392 * connman_network_get_group:
393 * @network: network structure
395 * Get group name for automatic clustering
397 const char *connman_network_get_group(struct connman_network *network)
399 return network->group;
402 const char *__connman_network_get_ident(struct connman_network *network)
404 if (network->device == NULL)
407 return connman_device_get_ident(network->device);
410 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
412 switch (network->type) {
413 case CONNMAN_NETWORK_TYPE_UNKNOWN:
414 case CONNMAN_NETWORK_TYPE_VENDOR:
415 case CONNMAN_NETWORK_TYPE_ETHERNET:
416 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
417 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
418 case CONNMAN_NETWORK_TYPE_CELLULAR:
419 case CONNMAN_NETWORK_TYPE_WIMAX:
421 case CONNMAN_NETWORK_TYPE_WIFI:
422 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
424 if (network->strength > 0 && network->strength < 20)
432 connman_bool_t __connman_network_get_connecting(struct connman_network *network)
434 return network->connecting;
438 * connman_network_set_available:
439 * @network: network structure
440 * @available: availability state
442 * Change availability state of network (in range)
444 int connman_network_set_available(struct connman_network *network,
445 connman_bool_t available)
447 DBG("network %p available %d", network, available);
449 if (network->available == available)
452 network->available = available;
458 * connman_network_get_available:
459 * @network: network structure
461 * Get network available setting
463 connman_bool_t connman_network_get_available(struct connman_network *network)
465 if (network->hidden == TRUE)
468 return network->available;
472 * connman_network_set_associating:
473 * @network: network structure
474 * @associating: associating state
476 * Change associating state of network
478 int connman_network_set_associating(struct connman_network *network,
479 connman_bool_t associating)
481 DBG("network %p associating %d", network, associating);
483 if (network->associating == associating)
486 network->associating = associating;
488 if (associating == TRUE) {
489 struct connman_service *service;
491 service = __connman_service_lookup_from_network(network);
492 __connman_service_indicate_state(service,
493 CONNMAN_SERVICE_STATE_ASSOCIATION);
499 static void set_associate_error(struct connman_network *network)
501 struct connman_service *service;
503 if (network->associating == FALSE)
506 network->associating = FALSE;
508 service = __connman_service_lookup_from_network(network);
510 __connman_service_indicate_state(service,
511 CONNMAN_SERVICE_STATE_FAILURE);
514 static void set_configure_error(struct connman_network *network)
516 struct connman_service *service;
518 network->connecting = FALSE;
520 service = __connman_service_lookup_from_network(network);
522 __connman_service_indicate_state(service,
523 CONNMAN_SERVICE_STATE_FAILURE);
526 void connman_network_set_ipv4_method(struct connman_network *network,
527 enum connman_ipconfig_method method)
529 struct connman_service *service;
530 struct connman_ipconfig *ipconfig;
532 network->element.ipv4.method = method;
534 service = __connman_service_lookup_from_network(network);
538 ipconfig = __connman_service_get_ip4config(service);
539 if (ipconfig == NULL)
542 connman_ipconfig_set_method(ipconfig, method);
545 void connman_network_set_ipv6_method(struct connman_network *network,
546 enum connman_ipconfig_method method)
548 struct connman_service *service;
549 struct connman_ipconfig *ipconfig;
551 network->element.ipv6.method = method;
553 service = __connman_service_lookup_from_network(network);
557 ipconfig = __connman_service_get_ip6config(service);
558 if (ipconfig == NULL)
561 connman_ipconfig_set_method(ipconfig, method);
564 void connman_network_set_error(struct connman_network *network,
565 enum connman_network_error error)
567 DBG("nework %p, error %d", network, error);
569 network->connecting = FALSE;
572 case CONNMAN_NETWORK_ERROR_UNKNOWN:
574 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
575 set_associate_error(network);
577 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
578 set_configure_error(network);
583 static void set_configuration(struct connman_network *network)
585 struct connman_service *service;
587 DBG("network %p", network);
589 __connman_device_increase_connections(network->device);
591 __connman_device_set_network(network->device, network);
593 connman_device_set_disconnected(network->device, FALSE);
595 service = __connman_service_lookup_from_network(network);
596 __connman_service_indicate_state(service,
597 CONNMAN_SERVICE_STATE_CONFIGURATION);
600 static int set_connected_fixed(struct connman_network *network)
602 struct connman_service *service;
603 struct connman_element *parent, *element;
607 service = __connman_service_lookup_from_network(network);
609 parent = connman_network_get_element(network);
611 set_configuration(network);
613 if (parent->ipv4.address == NULL)
616 if (parent->ipv4.netmask == NULL)
619 element = connman_element_create(NULL);
620 if (element == NULL) {
621 connman_error("Can not create connman_element");
625 element->type = CONNMAN_ELEMENT_TYPE_IPV4;
626 element->index = parent->index;
628 if (connman_element_register(element, parent) < 0) {
629 connman_error("Can not register connman_element");
633 network->connecting = FALSE;
635 connman_network_set_associating(network, FALSE);
640 static void set_connected_manual(struct connman_network *network)
642 struct connman_service *service;
643 struct connman_ipconfig *ipconfig;
644 const char *nameserver = NULL;
647 DBG("network %p", network);
649 service = __connman_service_lookup_from_network(network);
651 ipconfig = __connman_service_get_ip4config(service);
653 set_configuration(network);
655 err = __connman_ipconfig_set_address(ipconfig);
657 connman_network_set_error(network,
658 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
662 connman_element_get_value(&network->element,
663 CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
664 if (nameserver != NULL)
665 __connman_service_append_nameserver(service, nameserver);
667 __connman_ipconfig_set_gateway(ipconfig, &network->element);
669 network->connecting = FALSE;
671 connman_network_set_associating(network, FALSE);
673 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY);
676 static int set_connected_dhcp(struct connman_network *network)
678 struct connman_element *element;
681 DBG("network %p", network);
683 element = connman_element_create(NULL);
687 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
688 element->index = network->element.index;
690 error = connman_element_register(element, &network->element);
692 connman_element_unref(element);
696 set_configuration(network);
701 static int manual_ipv6_set(struct connman_network *network,
702 struct connman_ipconfig *ipconfig_ipv6)
704 struct connman_service *service;
707 service = __connman_service_lookup_from_network(network);
711 err = __connman_ipconfig_set_address(ipconfig_ipv6);
713 connman_network_set_error(network,
714 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
719 * READY state will be indicated by IPV4 setting
720 * gateway will be set by IPV4 setting
726 static gboolean set_connected(gpointer user_data)
728 struct connman_network *network = user_data;
729 struct connman_service *service;
730 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
731 enum connman_ipconfig_method ipv4_method, ipv6_method;
733 service = __connman_service_lookup_from_network(network);
735 ipconfig_ipv4 = __connman_service_get_ip4config(service);
736 ipconfig_ipv6 = __connman_service_get_ip6config(service);
738 DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
742 ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
744 ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
747 ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
749 ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
751 DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
752 DBG("network connected %d", network->connected);
754 if (network->connected == TRUE) {
757 switch (ipv6_method) {
758 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
759 case CONNMAN_IPCONFIG_METHOD_OFF:
760 case CONNMAN_IPCONFIG_METHOD_FIXED:
761 case CONNMAN_IPCONFIG_METHOD_MANUAL:
762 ret = manual_ipv6_set(network, ipconfig_ipv6);
764 connman_network_set_error(network,
765 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
769 case CONNMAN_IPCONFIG_METHOD_DHCP:
773 switch (ipv4_method) {
774 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
775 case CONNMAN_IPCONFIG_METHOD_OFF:
777 case CONNMAN_IPCONFIG_METHOD_FIXED:
778 if (set_connected_fixed(network) < 0) {
779 connman_network_set_error(network,
780 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
784 case CONNMAN_IPCONFIG_METHOD_MANUAL:
785 set_connected_manual(network);
787 case CONNMAN_IPCONFIG_METHOD_DHCP:
788 if (set_connected_dhcp(network) < 0) {
789 connman_network_set_error(network,
790 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
796 struct connman_service *service;
798 connman_element_unregister_children(&network->element);
800 __connman_device_set_network(network->device, NULL);
801 network->hidden = FALSE;
803 service = __connman_service_lookup_from_network(network);
805 __connman_service_indicate_state(service,
806 CONNMAN_SERVICE_STATE_IDLE);
809 network->connecting = FALSE;
811 connman_network_set_associating(network, FALSE);
817 * connman_network_set_connected:
818 * @network: network structure
819 * @connected: connected state
821 * Change connected state of network
823 int connman_network_set_connected(struct connman_network *network,
824 connman_bool_t connected)
826 DBG("network %p connected %d", network, connected);
828 if ((network->connecting == TRUE || network->associating == TRUE) &&
829 connected == FALSE) {
830 connman_element_set_error(&network->element,
831 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
832 __connman_network_disconnect(network);
835 if (network->connected == connected)
838 if (connected == FALSE)
839 __connman_device_decrease_connections(network->device);
841 network->connected = connected;
843 set_connected(network);
849 * connman_network_get_connected:
850 * @network: network structure
852 * Get network connection status
854 connman_bool_t connman_network_get_connected(struct connman_network *network)
856 return network->connected;
860 * connman_network_get_associating:
861 * @network: network structure
863 * Get network associating status
865 connman_bool_t connman_network_get_associating(struct connman_network *network)
867 return network->associating;
871 * __connman_network_connect:
872 * @network: network structure
876 int __connman_network_connect(struct connman_network *network)
878 struct connman_service *service;
881 DBG("network %p", network);
883 if (network->connected == TRUE)
886 if (network->connecting == TRUE || network->associating == TRUE)
889 if (network->driver == NULL)
892 if (network->driver->connect == NULL)
895 if (network->device == NULL)
898 __connman_device_disconnect(network->device);
900 network->connecting = TRUE;
902 service = __connman_service_lookup_from_network(network);
904 err = network->driver->connect(network);
906 if (err == -EINPROGRESS)
907 connman_network_set_associating(network, TRUE);
909 network->connecting = FALSE;
910 network->hidden = FALSE;
916 network->connected = TRUE;
917 set_connected(network);
923 * __connman_network_disconnect:
924 * @network: network structure
928 int __connman_network_disconnect(struct connman_network *network)
932 DBG("network %p", network);
934 if (network->connected == FALSE && network->connecting == FALSE &&
935 network->associating == FALSE)
938 if (network->driver == NULL)
941 if (network->driver->disconnect == NULL)
944 network->connecting = FALSE;
946 err = network->driver->disconnect(network);
948 connman_network_set_connected(network, FALSE);
949 set_connected(network);
955 static int dhcp_start(struct connman_network *network)
957 struct connman_element *element;
960 element = connman_element_create(NULL);
964 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
965 element->index = network->element.index;
967 error = connman_element_register(element, &network->element);
969 connman_element_unref(element);
976 static int dhcp_stop(struct connman_network *network)
978 connman_element_unregister_children_type(&network->element,
979 CONNMAN_ELEMENT_TYPE_CONNECTION);
980 connman_element_unregister_children_type(&network->element,
981 CONNMAN_ELEMENT_TYPE_IPV4);
982 connman_element_unregister_children_type(&network->element,
983 CONNMAN_ELEMENT_TYPE_DHCP);
988 static int manual_ipv4_set(struct connman_network *network,
989 struct connman_ipconfig *ipconfig)
991 struct connman_service *service;
994 service = __connman_service_lookup_from_network(network);
998 err = __connman_ipconfig_set_address(ipconfig);
1000 connman_network_set_error(network,
1001 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1005 __connman_ipconfig_set_gateway(ipconfig, &network->element);
1007 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY);
1012 int __connman_network_clear_ipconfig(struct connman_network *network,
1013 struct connman_ipconfig *ipconfig)
1015 struct connman_service *service;
1016 enum connman_ipconfig_method method;
1018 service = __connman_service_lookup_from_network(network);
1019 if (service == NULL)
1022 method = __connman_ipconfig_get_method(ipconfig);
1025 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1026 case CONNMAN_IPCONFIG_METHOD_OFF:
1027 case CONNMAN_IPCONFIG_METHOD_FIXED:
1029 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1030 connman_element_unregister_children_type(&network->element,
1031 CONNMAN_ELEMENT_TYPE_CONNECTION);
1032 __connman_ipconfig_clear_address(ipconfig);
1034 case CONNMAN_IPCONFIG_METHOD_DHCP:
1039 __connman_service_indicate_state(service,
1040 CONNMAN_SERVICE_STATE_CONFIGURATION);
1045 int __connman_network_set_ipconfig(struct connman_network *network,
1046 struct connman_ipconfig *ipconfig_ipv4,
1047 struct connman_ipconfig *ipconfig_ipv6)
1049 enum connman_ipconfig_method method;
1052 if (ipconfig_ipv6) {
1053 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1056 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1057 case CONNMAN_IPCONFIG_METHOD_OFF:
1059 case CONNMAN_IPCONFIG_METHOD_FIXED:
1060 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1061 ret = manual_ipv6_set(network, ipconfig_ipv6);
1063 connman_network_set_error(network,
1064 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1068 case CONNMAN_IPCONFIG_METHOD_DHCP:
1073 if (ipconfig_ipv4) {
1074 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1077 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1078 case CONNMAN_IPCONFIG_METHOD_OFF:
1079 case CONNMAN_IPCONFIG_METHOD_FIXED:
1081 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1082 return manual_ipv4_set(network, ipconfig_ipv4);
1083 case CONNMAN_IPCONFIG_METHOD_DHCP:
1084 return dhcp_start(network);
1092 * connman_network_set_address:
1093 * @network: network structure
1094 * @address: binary address value
1095 * @size: binary address length
1097 * Set unique address value for network
1099 int connman_network_set_address(struct connman_network *network,
1100 const void *address, unsigned int size)
1102 const unsigned char *addr_octet = address;
1105 DBG("network %p size %d", network, size);
1110 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
1111 addr_octet[0], addr_octet[1], addr_octet[2],
1112 addr_octet[3], addr_octet[4], addr_octet[5]);
1116 g_free(network->address);
1117 network->address = str;
1119 return connman_element_set_string(&network->element,
1120 "Address", network->address);
1124 * connman_network_set_name:
1125 * @network: network structure
1128 * Set display name value for network
1130 int connman_network_set_name(struct connman_network *network,
1133 DBG("network %p name %s", network, name);
1135 g_free(network->name);
1136 network->name = g_strdup(name);
1138 return connman_element_set_string(&network->element, "Name", name);
1142 * connman_network_set_strength:
1143 * @network: network structure
1144 * @strength: strength value
1146 * Set signal strength value for network
1148 int connman_network_set_strength(struct connman_network *network,
1149 connman_uint8_t strength)
1151 DBG("network %p strengh %d", network, strength);
1153 network->strength = strength;
1155 return connman_element_set_uint8(&network->element,
1156 "Strength", strength);
1160 * connman_network_set_roaming:
1161 * @network: network structure
1162 * @roaming: roaming state
1164 * Set roaming state for network
1166 int connman_network_set_roaming(struct connman_network *network,
1167 connman_bool_t roaming)
1169 DBG("network %p roaming %d", network, roaming);
1171 network->roaming = roaming;
1173 return connman_element_set_bool(&network->element,
1174 "Roaming", roaming);
1178 * connman_network_set_string:
1179 * @network: network structure
1180 * @key: unique identifier
1181 * @value: string value
1183 * Set string value for specific key
1185 int connman_network_set_string(struct connman_network *network,
1186 const char *key, const char *value)
1190 DBG("network %p key %s value %s", network, key, value);
1192 if (g_strcmp0(key, "Name") == 0)
1193 return connman_network_set_name(network, value);
1195 if (g_str_equal(key, "Address") == TRUE) {
1196 g_free(network->address);
1197 network->address = g_strdup(value);
1198 } else if (g_str_equal(key, "Node") == TRUE) {
1199 g_free(network->node);
1200 network->node = g_strdup(value);
1201 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1202 g_free(network->wifi.mode);
1203 network->wifi.mode = g_strdup(value);
1204 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1205 g_free(network->wifi.security);
1206 network->wifi.security = g_strdup(value);
1207 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1208 g_free(network->wifi.passphrase);
1209 network->wifi.passphrase = g_strdup(value);
1210 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1211 g_free(network->wifi.eap);
1212 network->wifi.eap = g_strdup(value);
1213 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1214 g_free(network->wifi.identity);
1215 network->wifi.identity = g_strdup(value);
1216 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1217 g_free(network->wifi.ca_cert_path);
1218 network->wifi.ca_cert_path = g_strdup(value);
1219 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1220 g_free(network->wifi.client_cert_path);
1221 network->wifi.client_cert_path = g_strdup(value);
1222 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1223 g_free(network->wifi.private_key_path);
1224 network->wifi.private_key_path = g_strdup(value);
1225 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1226 g_free(network->wifi.private_key_passphrase);
1227 network->wifi.private_key_passphrase = g_strdup(value);
1228 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1229 g_free(network->wifi.phase2_auth);
1230 network->wifi.phase2_auth = g_strdup(value);
1233 err = connman_element_set_string(&network->element, key, value);
1237 if (network->driver == NULL)
1240 if (network->driver->setup)
1241 return network->driver->setup(network, key);
1247 * connman_network_get_string:
1248 * @network: network structure
1249 * @key: unique identifier
1251 * Get string value for specific key
1253 const char *connman_network_get_string(struct connman_network *network,
1256 DBG("network %p key %s", network, key);
1258 if (g_str_equal(key, "Address") == TRUE)
1259 return network->address;
1260 else if (g_str_equal(key, "Name") == TRUE)
1261 return network->name;
1262 else if (g_str_equal(key, "Node") == TRUE)
1263 return network->node;
1264 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1265 return network->wifi.mode;
1266 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1267 return network->wifi.security;
1268 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1269 return network->wifi.passphrase;
1270 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1271 return network->wifi.eap;
1272 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1273 return network->wifi.identity;
1274 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1275 return network->wifi.ca_cert_path;
1276 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1277 return network->wifi.client_cert_path;
1278 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1279 return network->wifi.private_key_path;
1280 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1281 return network->wifi.private_key_passphrase;
1282 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1283 return network->wifi.phase2_auth;
1285 return connman_element_get_string(&network->element, key);
1289 * connman_network_set_passphrase:
1290 * @network: network structure
1291 * @passphrase: network passphrase
1293 * Set network passphrase.
1294 * If the network is linked to a service, the latter gets his passphrase
1297 int connman_network_set_passphrase(struct connman_network *network,
1298 const char* passphrase)
1300 struct connman_service *service;
1302 service = __connman_service_lookup_from_network(network);
1303 if (service == NULL) {
1304 connman_network_set_string(network, "WiFi.Passphrase",
1310 __connman_service_set_passphrase(service, passphrase);
1317 * connman_network_set_bool:
1318 * @network: network structure
1319 * @key: unique identifier
1320 * @value: boolean value
1322 * Set boolean value for specific key
1324 int connman_network_set_bool(struct connman_network *network,
1325 const char *key, connman_bool_t value)
1327 DBG("network %p key %s value %d", network, key, value);
1329 if (g_strcmp0(key, "Roaming") == 0)
1330 return connman_network_set_roaming(network, value);
1332 return connman_element_set_bool(&network->element, key, value);
1336 * connman_network_get_bool:
1337 * @network: network structure
1338 * @key: unique identifier
1340 * Get boolean value for specific key
1342 connman_bool_t connman_network_get_bool(struct connman_network *network,
1345 DBG("network %p key %s", network, key);
1347 if (g_str_equal(key, "Roaming") == TRUE)
1348 return network->roaming;
1350 return connman_element_get_bool(&network->element, key);
1354 * connman_network_set_uint8:
1355 * @network: network structure
1356 * @key: unique identifier
1357 * @value: integer value
1359 * Set integer value for specific key
1361 int connman_network_set_uint8(struct connman_network *network,
1362 const char *key, connman_uint8_t value)
1364 DBG("network %p key %s value %d", network, key, value);
1366 if (g_strcmp0(key, "Strength") == 0)
1367 return connman_network_set_strength(network, value);
1369 return connman_element_set_uint8(&network->element, key, value);
1373 * connman_network_get_uint8:
1374 * @network: network structure
1375 * @key: unique identifier
1377 * Get integer value for specific key
1379 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1382 DBG("network %p key %s", network, key);
1384 if (g_str_equal(key, "Strength") == TRUE)
1385 return network->strength;
1387 return connman_element_get_uint8(&network->element, key);
1391 * connman_network_set_uint16:
1392 * @network: network structure
1393 * @key: unique identifier
1394 * @value: integer value
1396 * Set integer value for specific key
1398 int connman_network_set_uint16(struct connman_network *network,
1399 const char *key, connman_uint16_t value)
1401 DBG("network %p key %s value %d", network, key, value);
1403 if (g_str_equal(key, "Frequency") == TRUE)
1404 network->frequency = value;
1405 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1406 network->wifi.channel = value;
1412 * connman_network_get_uint16:
1413 * @network: network structure
1414 * @key: unique identifier
1416 * Get integer value for specific key
1418 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1421 DBG("network %p key %s", network, key);
1423 if (g_str_equal(key, "Frequency") == TRUE)
1424 return network->frequency;
1425 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1426 return network->wifi.channel;
1432 * connman_network_set_blob:
1433 * @network: network structure
1434 * @key: unique identifier
1438 * Set binary blob value for specific key
1440 int connman_network_set_blob(struct connman_network *network,
1441 const char *key, const void *data, unsigned int size)
1443 DBG("network %p key %s size %d", network, key, size);
1445 if (g_strcmp0(key, "Address") == 0)
1446 return connman_network_set_address(network, data, size);
1448 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1449 g_free(network->wifi.ssid);
1450 network->wifi.ssid = g_try_malloc(size);
1451 if (network->wifi.ssid != NULL) {
1452 memcpy(network->wifi.ssid, data, size);
1453 network->wifi.ssid_len = size;
1455 network->wifi.ssid_len = 0;
1458 return connman_element_set_blob(&network->element, key, data, size);
1462 * connman_network_get_blob:
1463 * @network: network structure
1464 * @key: unique identifier
1465 * @size: pointer to blob size
1467 * Get binary blob value for specific key
1469 const void *connman_network_get_blob(struct connman_network *network,
1470 const char *key, unsigned int *size)
1472 DBG("network %p key %s", network, key);
1474 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1476 *size = network->wifi.ssid_len;
1477 return network->wifi.ssid;
1480 return connman_element_get_blob(&network->element, key, size);
1483 void __connman_network_set_device(struct connman_network *network,
1484 struct connman_device *device)
1486 network->device = device;
1490 * connman_network_get_device:
1491 * @network: network structure
1493 * Get parent device of network
1495 struct connman_device *connman_network_get_device(struct connman_network *network)
1497 return network->device;
1501 * connman_network_get_data:
1502 * @network: network structure
1504 * Get private network data pointer
1506 void *connman_network_get_data(struct connman_network *network)
1508 return network->driver_data;
1512 * connman_network_set_data:
1513 * @network: network structure
1514 * @data: data pointer
1516 * Set private network data pointer
1518 void connman_network_set_data(struct connman_network *network, void *data)
1520 network->driver_data = data;
1523 void connman_network_update(struct connman_network *network)
1525 switch (network->type) {
1526 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1527 case CONNMAN_NETWORK_TYPE_VENDOR:
1529 case CONNMAN_NETWORK_TYPE_ETHERNET:
1530 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1531 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1532 case CONNMAN_NETWORK_TYPE_CELLULAR:
1533 case CONNMAN_NETWORK_TYPE_WIFI:
1534 case CONNMAN_NETWORK_TYPE_WIMAX:
1538 if (network->group != NULL)
1539 __connman_service_update_from_network(network);
1544 static gboolean match_driver(struct connman_network *network,
1545 struct connman_network_driver *driver)
1547 if (network->type == driver->type ||
1548 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1554 static int network_probe(struct connman_element *element)
1556 struct connman_network *network = element->network;
1559 DBG("element %p name %s", element, element->name);
1561 if (network == NULL)
1564 for (list = driver_list; list; list = list->next) {
1565 struct connman_network_driver *driver = list->data;
1567 if (match_driver(network, driver) == FALSE)
1570 DBG("driver %p name %s", driver, driver->name);
1572 if (driver->probe(network) == 0) {
1573 network->driver = driver;
1578 if (network->driver == NULL)
1581 switch (network->type) {
1582 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1583 case CONNMAN_NETWORK_TYPE_VENDOR:
1585 case CONNMAN_NETWORK_TYPE_ETHERNET:
1586 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1587 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1588 case CONNMAN_NETWORK_TYPE_CELLULAR:
1589 case CONNMAN_NETWORK_TYPE_WIFI:
1590 case CONNMAN_NETWORK_TYPE_WIMAX:
1591 if (network->group != NULL)
1592 __connman_profile_add_network(network);
1599 static void network_remove(struct connman_element *element)
1601 struct connman_network *network = element->network;
1603 DBG("element %p name %s", element, element->name);
1605 if (network == NULL)
1608 if (network->driver == NULL)
1611 switch (network->type) {
1612 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1613 case CONNMAN_NETWORK_TYPE_VENDOR:
1615 case CONNMAN_NETWORK_TYPE_ETHERNET:
1616 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1617 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1618 case CONNMAN_NETWORK_TYPE_CELLULAR:
1619 case CONNMAN_NETWORK_TYPE_WIFI:
1620 case CONNMAN_NETWORK_TYPE_WIMAX:
1621 if (network->group != NULL) {
1622 __connman_profile_remove_network(network);
1624 g_free(network->group);
1625 network->group = NULL;
1630 if (network->driver->remove)
1631 network->driver->remove(network);
1634 static void network_change(struct connman_element *element)
1636 struct connman_network *network = element->network;
1638 DBG("element %p name %s", element, element->name);
1640 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1643 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1646 if (network->connected == FALSE)
1649 connman_element_unregister_children(element);
1651 connman_device_set_disconnected(network->device, TRUE);
1653 if (network->driver && network->driver->disconnect) {
1654 network->driver->disconnect(network);
1658 network->connected = FALSE;
1661 static struct connman_driver network_driver = {
1663 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1664 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1665 .probe = network_probe,
1666 .remove = network_remove,
1667 .change = network_change,
1670 int __connman_network_init(void)
1674 return connman_driver_register(&network_driver);
1677 void __connman_network_cleanup(void)
1681 connman_driver_unregister(&network_driver);