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:
761 case CONNMAN_IPCONFIG_METHOD_FIXED:
762 case CONNMAN_IPCONFIG_METHOD_MANUAL:
763 ret = manual_ipv6_set(network, ipconfig_ipv6);
765 connman_network_set_error(network,
766 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
770 case CONNMAN_IPCONFIG_METHOD_DHCP:
774 switch (ipv4_method) {
775 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
776 case CONNMAN_IPCONFIG_METHOD_OFF:
778 case CONNMAN_IPCONFIG_METHOD_FIXED:
779 if (set_connected_fixed(network) < 0) {
780 connman_network_set_error(network,
781 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
785 case CONNMAN_IPCONFIG_METHOD_MANUAL:
786 set_connected_manual(network);
788 case CONNMAN_IPCONFIG_METHOD_DHCP:
789 if (set_connected_dhcp(network) < 0) {
790 connman_network_set_error(network,
791 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
797 struct connman_service *service;
799 connman_element_unregister_children(&network->element);
801 __connman_device_set_network(network->device, NULL);
802 network->hidden = FALSE;
804 service = __connman_service_lookup_from_network(network);
806 __connman_service_indicate_state(service,
807 CONNMAN_SERVICE_STATE_IDLE);
810 network->connecting = FALSE;
812 connman_network_set_associating(network, FALSE);
818 * connman_network_set_connected:
819 * @network: network structure
820 * @connected: connected state
822 * Change connected state of network
824 int connman_network_set_connected(struct connman_network *network,
825 connman_bool_t connected)
827 DBG("network %p connected %d", network, connected);
829 if ((network->connecting == TRUE || network->associating == TRUE) &&
830 connected == FALSE) {
831 connman_element_set_error(&network->element,
832 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
833 __connman_network_disconnect(network);
836 if (network->connected == connected)
839 if (connected == FALSE)
840 __connman_device_decrease_connections(network->device);
842 network->connected = connected;
844 set_connected(network);
850 * connman_network_get_connected:
851 * @network: network structure
853 * Get network connection status
855 connman_bool_t connman_network_get_connected(struct connman_network *network)
857 return network->connected;
861 * connman_network_get_associating:
862 * @network: network structure
864 * Get network associating status
866 connman_bool_t connman_network_get_associating(struct connman_network *network)
868 return network->associating;
872 * __connman_network_connect:
873 * @network: network structure
877 int __connman_network_connect(struct connman_network *network)
879 struct connman_service *service;
882 DBG("network %p", network);
884 if (network->connected == TRUE)
887 if (network->connecting == TRUE || network->associating == TRUE)
890 if (network->driver == NULL)
893 if (network->driver->connect == NULL)
896 if (network->device == NULL)
899 network->connecting = TRUE;
901 __connman_device_disconnect(network->device);
903 service = __connman_service_lookup_from_network(network);
905 err = network->driver->connect(network);
907 if (err == -EINPROGRESS)
908 connman_network_set_associating(network, TRUE);
910 network->connecting = FALSE;
911 network->hidden = FALSE;
917 network->connected = TRUE;
918 set_connected(network);
924 * __connman_network_disconnect:
925 * @network: network structure
929 int __connman_network_disconnect(struct connman_network *network)
933 DBG("network %p", network);
935 if (network->connected == FALSE && network->connecting == FALSE &&
936 network->associating == FALSE)
939 if (network->driver == NULL)
942 if (network->driver->disconnect == NULL)
945 network->connecting = FALSE;
947 err = network->driver->disconnect(network);
949 connman_network_set_connected(network, FALSE);
950 set_connected(network);
956 static int dhcp_start(struct connman_network *network)
958 struct connman_element *element;
961 element = connman_element_create(NULL);
965 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
966 element->index = network->element.index;
968 error = connman_element_register(element, &network->element);
970 connman_element_unref(element);
977 static int dhcp_stop(struct connman_network *network)
979 connman_element_unregister_children_type(&network->element,
980 CONNMAN_ELEMENT_TYPE_CONNECTION);
981 connman_element_unregister_children_type(&network->element,
982 CONNMAN_ELEMENT_TYPE_IPV4);
983 connman_element_unregister_children_type(&network->element,
984 CONNMAN_ELEMENT_TYPE_DHCP);
989 static int manual_ipv4_set(struct connman_network *network,
990 struct connman_ipconfig *ipconfig)
992 struct connman_service *service;
995 service = __connman_service_lookup_from_network(network);
999 err = __connman_ipconfig_set_address(ipconfig);
1001 connman_network_set_error(network,
1002 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1006 __connman_ipconfig_set_gateway(ipconfig, &network->element);
1008 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY);
1013 int __connman_network_clear_ipconfig(struct connman_network *network,
1014 struct connman_ipconfig *ipconfig)
1016 struct connman_service *service;
1017 enum connman_ipconfig_method method;
1019 service = __connman_service_lookup_from_network(network);
1020 if (service == NULL)
1023 method = __connman_ipconfig_get_method(ipconfig);
1026 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1027 case CONNMAN_IPCONFIG_METHOD_OFF:
1028 case CONNMAN_IPCONFIG_METHOD_FIXED:
1030 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1031 connman_element_unregister_children_type(&network->element,
1032 CONNMAN_ELEMENT_TYPE_CONNECTION);
1033 __connman_ipconfig_clear_address(ipconfig);
1035 case CONNMAN_IPCONFIG_METHOD_DHCP:
1040 __connman_service_indicate_state(service,
1041 CONNMAN_SERVICE_STATE_CONFIGURATION);
1046 int __connman_network_set_ipconfig(struct connman_network *network,
1047 struct connman_ipconfig *ipconfig_ipv4,
1048 struct connman_ipconfig *ipconfig_ipv6)
1050 enum connman_ipconfig_method method;
1053 if (ipconfig_ipv6) {
1054 method = __connman_ipconfig_get_method(ipconfig_ipv6);
1057 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1058 case CONNMAN_IPCONFIG_METHOD_OFF:
1060 case CONNMAN_IPCONFIG_METHOD_FIXED:
1061 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1062 ret = manual_ipv6_set(network, ipconfig_ipv6);
1064 connman_network_set_error(network,
1065 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
1069 case CONNMAN_IPCONFIG_METHOD_DHCP:
1074 if (ipconfig_ipv4) {
1075 method = __connman_ipconfig_get_method(ipconfig_ipv4);
1078 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1079 case CONNMAN_IPCONFIG_METHOD_OFF:
1080 case CONNMAN_IPCONFIG_METHOD_FIXED:
1082 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1083 return manual_ipv4_set(network, ipconfig_ipv4);
1084 case CONNMAN_IPCONFIG_METHOD_DHCP:
1085 return dhcp_start(network);
1093 * connman_network_set_address:
1094 * @network: network structure
1095 * @address: binary address value
1096 * @size: binary address length
1098 * Set unique address value for network
1100 int connman_network_set_address(struct connman_network *network,
1101 const void *address, unsigned int size)
1103 const unsigned char *addr_octet = address;
1106 DBG("network %p size %d", network, size);
1111 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
1112 addr_octet[0], addr_octet[1], addr_octet[2],
1113 addr_octet[3], addr_octet[4], addr_octet[5]);
1117 g_free(network->address);
1118 network->address = str;
1120 return connman_element_set_string(&network->element,
1121 "Address", network->address);
1125 * connman_network_set_name:
1126 * @network: network structure
1129 * Set display name value for network
1131 int connman_network_set_name(struct connman_network *network,
1134 DBG("network %p name %s", network, name);
1136 g_free(network->name);
1137 network->name = g_strdup(name);
1139 return connman_element_set_string(&network->element, "Name", name);
1143 * connman_network_set_strength:
1144 * @network: network structure
1145 * @strength: strength value
1147 * Set signal strength value for network
1149 int connman_network_set_strength(struct connman_network *network,
1150 connman_uint8_t strength)
1152 DBG("network %p strengh %d", network, strength);
1154 network->strength = strength;
1156 return connman_element_set_uint8(&network->element,
1157 "Strength", strength);
1161 * connman_network_set_roaming:
1162 * @network: network structure
1163 * @roaming: roaming state
1165 * Set roaming state for network
1167 int connman_network_set_roaming(struct connman_network *network,
1168 connman_bool_t roaming)
1170 DBG("network %p roaming %d", network, roaming);
1172 network->roaming = roaming;
1174 return connman_element_set_bool(&network->element,
1175 "Roaming", roaming);
1179 * connman_network_set_string:
1180 * @network: network structure
1181 * @key: unique identifier
1182 * @value: string value
1184 * Set string value for specific key
1186 int connman_network_set_string(struct connman_network *network,
1187 const char *key, const char *value)
1191 DBG("network %p key %s value %s", network, key, value);
1193 if (g_strcmp0(key, "Name") == 0)
1194 return connman_network_set_name(network, value);
1196 if (g_str_equal(key, "Address") == TRUE) {
1197 g_free(network->address);
1198 network->address = g_strdup(value);
1199 } else if (g_str_equal(key, "Node") == TRUE) {
1200 g_free(network->node);
1201 network->node = g_strdup(value);
1202 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1203 g_free(network->wifi.mode);
1204 network->wifi.mode = g_strdup(value);
1205 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1206 g_free(network->wifi.security);
1207 network->wifi.security = g_strdup(value);
1208 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1209 g_free(network->wifi.passphrase);
1210 network->wifi.passphrase = g_strdup(value);
1211 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1212 g_free(network->wifi.eap);
1213 network->wifi.eap = g_strdup(value);
1214 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1215 g_free(network->wifi.identity);
1216 network->wifi.identity = g_strdup(value);
1217 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1218 g_free(network->wifi.ca_cert_path);
1219 network->wifi.ca_cert_path = g_strdup(value);
1220 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1221 g_free(network->wifi.client_cert_path);
1222 network->wifi.client_cert_path = g_strdup(value);
1223 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1224 g_free(network->wifi.private_key_path);
1225 network->wifi.private_key_path = g_strdup(value);
1226 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1227 g_free(network->wifi.private_key_passphrase);
1228 network->wifi.private_key_passphrase = g_strdup(value);
1229 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1230 g_free(network->wifi.phase2_auth);
1231 network->wifi.phase2_auth = g_strdup(value);
1234 err = connman_element_set_string(&network->element, key, value);
1238 if (network->driver == NULL)
1241 if (network->driver->setup)
1242 return network->driver->setup(network, key);
1248 * connman_network_get_string:
1249 * @network: network structure
1250 * @key: unique identifier
1252 * Get string value for specific key
1254 const char *connman_network_get_string(struct connman_network *network,
1257 DBG("network %p key %s", network, key);
1259 if (g_str_equal(key, "Address") == TRUE)
1260 return network->address;
1261 else if (g_str_equal(key, "Name") == TRUE)
1262 return network->name;
1263 else if (g_str_equal(key, "Node") == TRUE)
1264 return network->node;
1265 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1266 return network->wifi.mode;
1267 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1268 return network->wifi.security;
1269 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1270 return network->wifi.passphrase;
1271 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1272 return network->wifi.eap;
1273 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1274 return network->wifi.identity;
1275 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1276 return network->wifi.ca_cert_path;
1277 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1278 return network->wifi.client_cert_path;
1279 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1280 return network->wifi.private_key_path;
1281 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1282 return network->wifi.private_key_passphrase;
1283 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1284 return network->wifi.phase2_auth;
1286 return connman_element_get_string(&network->element, key);
1290 * connman_network_set_passphrase:
1291 * @network: network structure
1292 * @passphrase: network passphrase
1294 * Set network passphrase.
1295 * If the network is linked to a service, the latter gets his passphrase
1298 int connman_network_set_passphrase(struct connman_network *network,
1299 const char* passphrase)
1301 struct connman_service *service;
1303 service = __connman_service_lookup_from_network(network);
1304 if (service == NULL) {
1305 connman_network_set_string(network, "WiFi.Passphrase",
1311 __connman_service_set_passphrase(service, passphrase);
1318 * connman_network_set_bool:
1319 * @network: network structure
1320 * @key: unique identifier
1321 * @value: boolean value
1323 * Set boolean value for specific key
1325 int connman_network_set_bool(struct connman_network *network,
1326 const char *key, connman_bool_t value)
1328 DBG("network %p key %s value %d", network, key, value);
1330 if (g_strcmp0(key, "Roaming") == 0)
1331 return connman_network_set_roaming(network, value);
1333 return connman_element_set_bool(&network->element, key, value);
1337 * connman_network_get_bool:
1338 * @network: network structure
1339 * @key: unique identifier
1341 * Get boolean value for specific key
1343 connman_bool_t connman_network_get_bool(struct connman_network *network,
1346 DBG("network %p key %s", network, key);
1348 if (g_str_equal(key, "Roaming") == TRUE)
1349 return network->roaming;
1351 return connman_element_get_bool(&network->element, key);
1355 * connman_network_set_uint8:
1356 * @network: network structure
1357 * @key: unique identifier
1358 * @value: integer value
1360 * Set integer value for specific key
1362 int connman_network_set_uint8(struct connman_network *network,
1363 const char *key, connman_uint8_t value)
1365 DBG("network %p key %s value %d", network, key, value);
1367 if (g_strcmp0(key, "Strength") == 0)
1368 return connman_network_set_strength(network, value);
1370 return connman_element_set_uint8(&network->element, key, value);
1374 * connman_network_get_uint8:
1375 * @network: network structure
1376 * @key: unique identifier
1378 * Get integer value for specific key
1380 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1383 DBG("network %p key %s", network, key);
1385 if (g_str_equal(key, "Strength") == TRUE)
1386 return network->strength;
1388 return connman_element_get_uint8(&network->element, key);
1392 * connman_network_set_uint16:
1393 * @network: network structure
1394 * @key: unique identifier
1395 * @value: integer value
1397 * Set integer value for specific key
1399 int connman_network_set_uint16(struct connman_network *network,
1400 const char *key, connman_uint16_t value)
1402 DBG("network %p key %s value %d", network, key, value);
1404 if (g_str_equal(key, "Frequency") == TRUE)
1405 network->frequency = value;
1406 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1407 network->wifi.channel = value;
1413 * connman_network_get_uint16:
1414 * @network: network structure
1415 * @key: unique identifier
1417 * Get integer value for specific key
1419 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1422 DBG("network %p key %s", network, key);
1424 if (g_str_equal(key, "Frequency") == TRUE)
1425 return network->frequency;
1426 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1427 return network->wifi.channel;
1433 * connman_network_set_blob:
1434 * @network: network structure
1435 * @key: unique identifier
1439 * Set binary blob value for specific key
1441 int connman_network_set_blob(struct connman_network *network,
1442 const char *key, const void *data, unsigned int size)
1444 DBG("network %p key %s size %d", network, key, size);
1446 if (g_strcmp0(key, "Address") == 0)
1447 return connman_network_set_address(network, data, size);
1449 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1450 g_free(network->wifi.ssid);
1451 network->wifi.ssid = g_try_malloc(size);
1452 if (network->wifi.ssid != NULL) {
1453 memcpy(network->wifi.ssid, data, size);
1454 network->wifi.ssid_len = size;
1456 network->wifi.ssid_len = 0;
1459 return connman_element_set_blob(&network->element, key, data, size);
1463 * connman_network_get_blob:
1464 * @network: network structure
1465 * @key: unique identifier
1466 * @size: pointer to blob size
1468 * Get binary blob value for specific key
1470 const void *connman_network_get_blob(struct connman_network *network,
1471 const char *key, unsigned int *size)
1473 DBG("network %p key %s", network, key);
1475 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1477 *size = network->wifi.ssid_len;
1478 return network->wifi.ssid;
1481 return connman_element_get_blob(&network->element, key, size);
1484 void __connman_network_set_device(struct connman_network *network,
1485 struct connman_device *device)
1487 network->device = device;
1491 * connman_network_get_device:
1492 * @network: network structure
1494 * Get parent device of network
1496 struct connman_device *connman_network_get_device(struct connman_network *network)
1498 return network->device;
1502 * connman_network_get_data:
1503 * @network: network structure
1505 * Get private network data pointer
1507 void *connman_network_get_data(struct connman_network *network)
1509 return network->driver_data;
1513 * connman_network_set_data:
1514 * @network: network structure
1515 * @data: data pointer
1517 * Set private network data pointer
1519 void connman_network_set_data(struct connman_network *network, void *data)
1521 network->driver_data = data;
1524 void connman_network_update(struct connman_network *network)
1526 switch (network->type) {
1527 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1528 case CONNMAN_NETWORK_TYPE_VENDOR:
1530 case CONNMAN_NETWORK_TYPE_ETHERNET:
1531 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1532 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1533 case CONNMAN_NETWORK_TYPE_CELLULAR:
1534 case CONNMAN_NETWORK_TYPE_WIFI:
1535 case CONNMAN_NETWORK_TYPE_WIMAX:
1539 if (network->group != NULL)
1540 __connman_service_update_from_network(network);
1545 static gboolean match_driver(struct connman_network *network,
1546 struct connman_network_driver *driver)
1548 if (network->type == driver->type ||
1549 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1555 static int network_probe(struct connman_element *element)
1557 struct connman_network *network = element->network;
1560 DBG("element %p name %s", element, element->name);
1562 if (network == NULL)
1565 for (list = driver_list; list; list = list->next) {
1566 struct connman_network_driver *driver = list->data;
1568 if (match_driver(network, driver) == FALSE)
1571 DBG("driver %p name %s", driver, driver->name);
1573 if (driver->probe(network) == 0) {
1574 network->driver = driver;
1579 if (network->driver == NULL)
1582 switch (network->type) {
1583 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1584 case CONNMAN_NETWORK_TYPE_VENDOR:
1586 case CONNMAN_NETWORK_TYPE_ETHERNET:
1587 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1588 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1589 case CONNMAN_NETWORK_TYPE_CELLULAR:
1590 case CONNMAN_NETWORK_TYPE_WIFI:
1591 case CONNMAN_NETWORK_TYPE_WIMAX:
1592 if (network->group != NULL)
1593 __connman_profile_add_network(network);
1600 static void network_remove(struct connman_element *element)
1602 struct connman_network *network = element->network;
1604 DBG("element %p name %s", element, element->name);
1606 if (network == NULL)
1609 if (network->driver == NULL)
1612 switch (network->type) {
1613 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1614 case CONNMAN_NETWORK_TYPE_VENDOR:
1616 case CONNMAN_NETWORK_TYPE_ETHERNET:
1617 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1618 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1619 case CONNMAN_NETWORK_TYPE_CELLULAR:
1620 case CONNMAN_NETWORK_TYPE_WIFI:
1621 case CONNMAN_NETWORK_TYPE_WIMAX:
1622 if (network->group != NULL) {
1623 __connman_profile_remove_network(network);
1625 g_free(network->group);
1626 network->group = NULL;
1631 if (network->driver->remove)
1632 network->driver->remove(network);
1635 static void network_change(struct connman_element *element)
1637 struct connman_network *network = element->network;
1639 DBG("element %p name %s", element, element->name);
1641 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1644 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1647 if (network->connected == FALSE)
1650 connman_element_unregister_children(element);
1652 connman_device_set_disconnected(network->device, TRUE);
1654 if (network->driver && network->driver->disconnect) {
1655 network->driver->disconnect(network);
1659 network->connected = FALSE;
1662 static struct connman_driver network_driver = {
1664 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1665 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1666 .probe = network_probe,
1667 .remove = network_remove,
1668 .change = network_change,
1671 int __connman_network_init(void)
1675 return connman_driver_register(&network_driver);
1678 void __connman_network_cleanup(void)
1682 connman_driver_unregister(&network_driver);