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
33 static unsigned int hidden_counter = 0;
35 struct connman_network {
36 struct connman_element element;
37 enum connman_network_type type;
38 enum connman_network_protocol protocol;
39 connman_bool_t available;
40 connman_bool_t connected;
41 connman_bool_t roaming;
42 connman_bool_t hidden;
43 connman_uint8_t strength;
44 connman_uint16_t frequency;
50 struct connman_ipconfig *ipconfig;
52 struct connman_network_driver *driver;
55 connman_bool_t registered;
56 connman_bool_t connecting;
57 connman_bool_t associating;
59 struct connman_device *device;
65 unsigned short channel;
71 char *client_cert_path;
72 char *private_key_path;
73 char *private_key_passphrase;
78 static const char *type2string(enum connman_network_type type)
81 case CONNMAN_NETWORK_TYPE_UNKNOWN:
82 case CONNMAN_NETWORK_TYPE_VENDOR:
84 case CONNMAN_NETWORK_TYPE_ETHERNET:
86 case CONNMAN_NETWORK_TYPE_WIFI:
88 case CONNMAN_NETWORK_TYPE_WIMAX:
90 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
91 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
93 case CONNMAN_NETWORK_TYPE_CELLULAR:
100 static DBusMessage *get_properties(DBusConnection *conn,
101 DBusMessage *msg, void *data)
103 struct connman_network *network = data;
105 DBusMessageIter array, dict;
107 DBG("conn %p", conn);
109 if (__connman_security_check_privilege(msg,
110 CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
111 return __connman_error_permission_denied(msg);
113 reply = dbus_message_new_method_return(msg);
117 dbus_message_iter_init_append(reply, &array);
119 connman_dbus_dict_open(&array, &dict);
121 if (network->device) {
122 const char *path = connman_device_get_path(network->device);
124 connman_dbus_dict_append_basic(&dict, "Device",
125 DBUS_TYPE_OBJECT_PATH, &path);
128 if (network->address != NULL)
129 connman_dbus_dict_append_basic(&dict, "Address",
130 DBUS_TYPE_STRING, &network->address);
132 if (network->name != NULL)
133 connman_dbus_dict_append_basic(&dict, "Name",
134 DBUS_TYPE_STRING, &network->name);
136 connman_dbus_dict_append_basic(&dict, "Connected",
137 DBUS_TYPE_BOOLEAN, &network->connected);
139 if (network->strength > 0)
140 connman_dbus_dict_append_basic(&dict, "Strength",
141 DBUS_TYPE_BYTE, &network->strength);
143 if (network->frequency > 0)
144 connman_dbus_dict_append_basic(&dict, "Frequency",
145 DBUS_TYPE_UINT16, &network->frequency);
147 if (network->wifi.ssid != NULL && network->wifi.ssid_len > 0)
148 connman_dbus_dict_append_fixed_array(&dict, "WiFi.SSID",
149 DBUS_TYPE_BYTE, &network->wifi.ssid,
150 network->wifi.ssid_len);
152 if (network->wifi.mode != NULL)
153 connman_dbus_dict_append_basic(&dict, "WiFi.Mode",
154 DBUS_TYPE_STRING, &network->wifi.mode);
156 if (network->wifi.channel > 0)
157 connman_dbus_dict_append_basic(&dict, "WiFi.Channel",
158 DBUS_TYPE_UINT16, &network->wifi.channel);
160 if (network->wifi.security != NULL) {
161 connman_dbus_dict_append_basic(&dict, "WiFi.Security",
162 DBUS_TYPE_STRING, &network->wifi.security);
164 if (g_strcmp0(network->wifi.security, "ieee8021x") == 0 &&
165 network->wifi.eap != NULL)
166 connman_dbus_dict_append_basic(&dict, "WiFi.EAP",
167 DBUS_TYPE_STRING, &network->wifi.eap);
171 if (network->wifi.passphrase != NULL &&
172 __connman_security_check_privilege(msg,
173 CONNMAN_SECURITY_PRIVILEGE_SECRET) == 0)
174 connman_dbus_dict_append_basic(&dict, "WiFi.Passphrase",
175 DBUS_TYPE_STRING, &network->wifi.passphrase);
177 connman_dbus_dict_close(&array, &dict);
182 static GDBusMethodTable network_methods[] = {
183 { "GetProperties", "", "a{sv}", get_properties },
187 static GDBusSignalTable network_signals[] = {
188 { "PropertyChanged", "sv" },
192 static DBusConnection *connection;
194 static void append_networks(DBusMessageIter *iter, void *user_data)
196 struct connman_device *device = user_data;
198 __connman_element_list((struct connman_element *) device,
199 CONNMAN_ELEMENT_TYPE_NETWORK, iter);
202 static void emit_networks_signal(struct connman_device *device)
204 const char *path = connman_device_get_path(device);
206 connman_dbus_property_changed_array(path,
207 CONNMAN_DEVICE_INTERFACE, "Networks",
208 DBUS_TYPE_OBJECT_PATH, append_networks, device);
211 static int register_interface(struct connman_element *element)
213 struct connman_network *network = element->network;
215 DBG("element %p name %s", element, element->name);
217 if (g_dbus_register_interface(connection, element->path,
218 CONNMAN_NETWORK_INTERFACE,
219 network_methods, network_signals,
220 NULL, network, NULL) == FALSE) {
221 connman_error("Failed to register %s network", element->path);
225 network->registered = TRUE;
227 emit_networks_signal(network->device);
232 static void unregister_interface(struct connman_element *element)
234 struct connman_network * network = element->network;
236 DBG("element %p name %s", element, element->name);
238 network->registered = FALSE;
240 if (network->device != NULL)
241 emit_networks_signal(network->device);
243 g_dbus_unregister_interface(connection, element->path,
244 CONNMAN_NETWORK_INTERFACE);
247 connman_bool_t __connman_network_has_driver(struct connman_network *network)
249 if (network == NULL || network->driver == NULL)
252 return network->registered;
255 static GSList *driver_list = NULL;
257 static gint compare_priority(gconstpointer a, gconstpointer b)
259 const struct connman_network_driver *driver1 = a;
260 const struct connman_network_driver *driver2 = b;
262 return driver2->priority - driver1->priority;
266 * connman_network_driver_register:
267 * @driver: network driver definition
269 * Register a new network driver
271 * Returns: %0 on success
273 int connman_network_driver_register(struct connman_network_driver *driver)
275 DBG("driver %p name %s", driver, driver->name);
277 driver_list = g_slist_insert_sorted(driver_list, driver,
284 * connman_network_driver_unregister:
285 * @driver: network driver definition
287 * Remove a previously registered network driver
289 void connman_network_driver_unregister(struct connman_network_driver *driver)
291 DBG("driver %p name %s", driver, driver->name);
293 driver_list = g_slist_remove(driver_list, driver);
296 static void network_destruct(struct connman_element *element)
298 struct connman_network *network = element->network;
300 DBG("element %p name %s", element, element->name);
302 g_free(network->wifi.ssid);
303 g_free(network->wifi.mode);
304 g_free(network->wifi.security);
305 g_free(network->wifi.passphrase);
307 g_free(network->group);
308 g_free(network->node);
309 g_free(network->name);
310 g_free(network->address);
311 g_free(network->identifier);
313 if (network->ipconfig) {
314 connman_ipconfig_unref(network->ipconfig);
315 network->ipconfig = NULL;
318 network->device = NULL;
322 * connman_network_create:
323 * @identifier: network identifier (for example an unqiue name)
325 * Allocate a new network and assign the #identifier to it.
327 * Returns: a newly-allocated #connman_network structure
329 struct connman_network *connman_network_create(const char *identifier,
330 enum connman_network_type type)
332 struct connman_network *network;
333 connman_uint8_t strength = 0;
337 DBG("identifier %s type %d", identifier, type);
339 network = g_try_new0(struct connman_network, 1);
343 DBG("network %p", network);
345 __connman_element_initialize(&network->element);
347 //temp = connman_dbus_encode_string(identifier);
348 if (identifier == NULL) {
349 temp = g_strdup_printf("hidden_%d", hidden_counter++);
350 network->hidden = TRUE;
352 temp = g_strdup(identifier);
359 network->element.name = temp;
360 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
362 network->element.network = network;
363 network->element.destruct = network_destruct;
365 str = type2string(type);
367 connman_element_set_string(&network->element, "Type", str);
369 connman_element_set_uint8(&network->element, "Strength", strength);
371 network->type = type;
372 network->identifier = g_strdup(temp);
378 * connman_network_ref:
379 * @network: network structure
381 * Increase reference counter of network
383 struct connman_network *connman_network_ref(struct connman_network *network)
385 if (connman_element_ref(&network->element) == NULL)
392 * connman_network_unref:
393 * @network: network structure
395 * Decrease reference counter of network
397 void connman_network_unref(struct connman_network *network)
399 connman_element_unref(&network->element);
402 const char *__connman_network_get_type(struct connman_network *network)
404 return type2string(network->type);
408 * connman_network_get_type:
409 * @network: network structure
411 * Get type of network
413 enum connman_network_type connman_network_get_type(struct connman_network *network)
415 return network->type;
419 * connman_network_get_identifier:
420 * @network: network structure
422 * Get identifier of network
424 const char *connman_network_get_identifier(struct connman_network *network)
426 return network->identifier;
430 * connman_network_get_path:
431 * @network: network structure
433 * Get path name of network
435 const char *connman_network_get_path(struct connman_network *network)
437 return network->element.path;
441 * connman_network_set_index:
442 * @network: network structure
443 * @index: index number
445 * Set index number of network
447 void connman_network_set_index(struct connman_network *network, int index)
449 struct connman_service *service;
451 service = __connman_service_lookup_from_network(network);
455 if (network->element.index < 0)
457 * This is needed for plugins that havent set their ipconfig
458 * layer yet, due to not being able to get a network index
459 * prior to creating a service.
461 __connman_service_create_ipconfig(service, index);
463 struct connman_ipconfig *ipconfig;
465 /* If index changed, the index of ipconfig must be reset. */
466 ipconfig = __connman_service_get_ipconfig(service);
467 if (ipconfig == NULL)
470 __connman_ipconfig_set_index(ipconfig, index);
474 network->element.index = index;
478 * connman_network_get_index:
479 * @network: network structure
481 * Get index number of network
483 int connman_network_get_index(struct connman_network *network)
485 return network->element.index;
489 * connman_network_get_element:
490 * @network: network structure
492 * Get connman_element of network
494 struct connman_element *connman_network_get_element(
495 struct connman_network *network)
497 return &network->element;
501 * connman_network_set_protocol:
502 * @network: network structure
503 * @protocol: network protocol
505 * Change protocol of network
507 void connman_network_set_protocol(struct connman_network *network,
508 enum connman_network_protocol protocol)
510 network->protocol = protocol;
514 * connman_network_set_group:
515 * @network: network structure
518 * Set group name for automatic clustering
520 void connman_network_set_group(struct connman_network *network,
523 switch (network->type) {
524 case CONNMAN_NETWORK_TYPE_UNKNOWN:
525 case CONNMAN_NETWORK_TYPE_VENDOR:
527 case CONNMAN_NETWORK_TYPE_ETHERNET:
528 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
529 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
530 case CONNMAN_NETWORK_TYPE_CELLULAR:
531 case CONNMAN_NETWORK_TYPE_WIFI:
532 case CONNMAN_NETWORK_TYPE_WIMAX:
536 if (g_strcmp0(network->group, group) == 0) {
538 __connman_profile_update_network(network);
542 if (network->group != NULL) {
543 __connman_profile_remove_network(network);
545 g_free(network->group);
548 network->group = g_strdup(group);
550 if (network->group != NULL)
551 __connman_profile_add_network(network);
555 * connman_network_get_group:
556 * @network: network structure
558 * Get group name for automatic clustering
560 const char *connman_network_get_group(struct connman_network *network)
562 return network->group;
565 const char *__connman_network_get_ident(struct connman_network *network)
567 if (network->device == NULL)
570 return __connman_device_get_ident(network->device);
573 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
575 switch (network->type) {
576 case CONNMAN_NETWORK_TYPE_UNKNOWN:
577 case CONNMAN_NETWORK_TYPE_VENDOR:
578 case CONNMAN_NETWORK_TYPE_ETHERNET:
579 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
580 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
581 case CONNMAN_NETWORK_TYPE_CELLULAR:
582 case CONNMAN_NETWORK_TYPE_WIMAX:
584 case CONNMAN_NETWORK_TYPE_WIFI:
585 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
587 if (network->strength > 0 && network->strength < 20)
595 connman_bool_t __connman_network_get_connecting(struct connman_network *network)
597 return network->connecting;
601 * connman_network_set_available:
602 * @network: network structure
603 * @available: availability state
605 * Change availability state of network (in range)
607 int connman_network_set_available(struct connman_network *network,
608 connman_bool_t available)
610 DBG("network %p available %d", network, available);
612 if (network->available == available)
615 network->available = available;
621 * connman_network_get_available:
622 * @network: network structure
624 * Get network available setting
626 connman_bool_t connman_network_get_available(struct connman_network *network)
628 if (network->hidden == TRUE)
631 return network->available;
635 * connman_network_set_associating:
636 * @network: network structure
637 * @associating: associating state
639 * Change associating state of network
641 int connman_network_set_associating(struct connman_network *network,
642 connman_bool_t associating)
644 DBG("network %p associating %d", network, associating);
646 if (network->associating == associating)
649 network->associating = associating;
651 if (associating == TRUE) {
652 struct connman_service *service;
654 service = __connman_service_lookup_from_network(network);
655 __connman_service_indicate_state(service,
656 CONNMAN_SERVICE_STATE_ASSOCIATION);
662 static void set_associate_error(struct connman_network *network)
664 struct connman_service *service;
666 if (network->associating == FALSE)
669 network->associating = FALSE;
671 service = __connman_service_lookup_from_network(network);
673 __connman_service_indicate_state(service,
674 CONNMAN_SERVICE_STATE_FAILURE);
677 static void set_configure_error(struct connman_network *network)
679 struct connman_service *service;
681 network->connecting = FALSE;
683 service = __connman_service_lookup_from_network(network);
685 __connman_service_indicate_state(service,
686 CONNMAN_SERVICE_STATE_FAILURE);
689 void connman_network_set_method(struct connman_network *network,
690 enum connman_ipconfig_method method)
692 struct connman_service *service;
693 struct connman_ipconfig *ipconfig;
695 network->element.ipv4.method = method;
697 service = __connman_service_lookup_from_network(network);
701 ipconfig = __connman_service_get_ipconfig(service);
702 if (ipconfig == NULL)
705 connman_ipconfig_set_method(ipconfig, method);
708 void connman_network_set_error(struct connman_network *network,
709 enum connman_network_error error)
711 DBG("nework %p, error %d", network, error);
713 network->connecting = FALSE;
716 case CONNMAN_NETWORK_ERROR_UNKNOWN:
718 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
719 set_associate_error(network);
721 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
722 set_configure_error(network);
727 static void set_configuration(struct connman_network *network)
729 struct connman_service *service;
731 DBG("network %p", network);
733 __connman_device_increase_connections(network->device);
735 __connman_device_set_network(network->device, network);
737 connman_device_set_disconnected(network->device, FALSE);
739 service = __connman_service_lookup_from_network(network);
740 __connman_service_indicate_state(service,
741 CONNMAN_SERVICE_STATE_CONFIGURATION);
744 static int set_connected_fixed(struct connman_network *network)
746 struct connman_service *service;
747 struct connman_element *parent, *element;
751 service = __connman_service_lookup_from_network(network);
753 parent = connman_network_get_element(network);
755 set_configuration(network);
757 if (parent->ipv4.address == NULL)
760 if (parent->ipv4.netmask == NULL)
763 element = connman_element_create(NULL);
764 if (element == NULL) {
765 connman_error("Can not create connman_element");
769 element->type = CONNMAN_ELEMENT_TYPE_IPV4;
770 element->index = parent->index;
772 if (connman_element_register(element, parent) < 0) {
773 connman_error("Can not register connman_element");
777 network->connecting = FALSE;
779 connman_network_set_associating(network, FALSE);
784 static void set_connected_manual(struct connman_network *network)
786 struct connman_service *service;
787 struct connman_ipconfig *ipconfig;
788 const char *nameserver = NULL;
791 DBG("network %p", network);
793 service = __connman_service_lookup_from_network(network);
795 ipconfig = __connman_service_get_ipconfig(service);
797 set_configuration(network);
799 err = __connman_ipconfig_set_address(ipconfig);
801 connman_network_set_error(network,
802 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
806 connman_element_get_value(&network->element,
807 CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
808 if (nameserver != NULL)
809 __connman_service_append_nameserver(service, nameserver);
811 __connman_ipconfig_set_gateway(ipconfig, &network->element);
813 network->connecting = FALSE;
815 connman_network_set_associating(network, FALSE);
817 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY);
820 static int set_connected_dhcp(struct connman_network *network)
822 struct connman_element *element;
825 DBG("network %p", network);
827 if (network->protocol != CONNMAN_NETWORK_PROTOCOL_IP)
830 element = connman_element_create(NULL);
834 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
835 element->index = network->element.index;
837 error = connman_element_register(element, &network->element);
839 connman_element_unref(element);
843 set_configuration(network);
848 static gboolean set_connected(gpointer user_data)
850 struct connman_network *network = user_data;
851 struct connman_service *service;
852 struct connman_ipconfig *ipconfig;
853 enum connman_ipconfig_method method;
855 service = __connman_service_lookup_from_network(network);
857 ipconfig = __connman_service_get_ipconfig(service);
859 method = __connman_ipconfig_get_method(ipconfig);
861 DBG("method %d", method);
863 if (network->connected == TRUE) {
865 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
866 case CONNMAN_IPCONFIG_METHOD_OFF:
868 case CONNMAN_IPCONFIG_METHOD_FIXED:
869 if (set_connected_fixed(network) < 0) {
870 connman_network_set_error(network,
871 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
875 case CONNMAN_IPCONFIG_METHOD_MANUAL:
876 set_connected_manual(network);
878 case CONNMAN_IPCONFIG_METHOD_DHCP:
879 if (set_connected_dhcp(network) < 0) {
880 connman_network_set_error(network,
881 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
887 struct connman_service *service;
889 connman_element_unregister_children(&network->element);
891 __connman_device_set_network(network->device, NULL);
892 network->hidden = FALSE;
894 __connman_device_decrease_connections(network->device);
896 service = __connman_service_lookup_from_network(network);
898 __connman_service_indicate_state(service,
899 CONNMAN_SERVICE_STATE_IDLE);
902 network->connecting = FALSE;
904 connman_network_set_associating(network, FALSE);
910 * connman_network_set_connected:
911 * @network: network structure
912 * @connected: connected state
914 * Change connected state of network
916 int connman_network_set_connected(struct connman_network *network,
917 connman_bool_t connected)
919 DBG("network %p connected %d", network, connected);
921 if ((network->connecting == TRUE || network->associating == TRUE) &&
922 connected == FALSE) {
923 connman_element_set_error(&network->element,
924 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
925 __connman_network_disconnect(network);
928 if (network->connected == connected)
931 network->connected = connected;
933 if (network->registered == FALSE) {
934 g_idle_add(set_connected, network);
938 connman_dbus_property_changed_basic(network->element.path,
939 CONNMAN_NETWORK_INTERFACE, "Connected",
940 DBUS_TYPE_BOOLEAN, &connected);
942 set_connected(network);
948 * connman_network_get_connected:
949 * @network: network structure
951 * Get network connection status
953 connman_bool_t connman_network_get_connected(struct connman_network *network)
955 return network->connected;
959 * connman_network_get_associating:
960 * @network: network structure
962 * Get network associating status
964 connman_bool_t connman_network_get_associating(struct connman_network *network)
966 return network->associating;
970 * __connman_network_connect:
971 * @network: network structure
975 int __connman_network_connect(struct connman_network *network)
979 DBG("network %p", network);
981 if (network->connected == TRUE)
984 if (network->connecting == TRUE || network->associating == TRUE)
987 if (network->driver == NULL)
990 if (network->driver->connect == NULL)
993 __connman_device_disconnect(network->device);
995 network->connecting = TRUE;
997 err = network->driver->connect(network);
999 if (err == -EINPROGRESS)
1000 connman_network_set_associating(network, TRUE);
1002 network->connecting = FALSE;
1003 network->hidden = FALSE;
1009 network->connected = TRUE;
1010 set_connected(network);
1016 * __connman_network_disconnect:
1017 * @network: network structure
1019 * Disconnect network
1021 int __connman_network_disconnect(struct connman_network *network)
1025 DBG("network %p", network);
1027 if (network->connected == FALSE && network->connecting == FALSE &&
1028 network->associating == FALSE)
1031 if (network->driver == NULL)
1034 if (network->driver->disconnect == NULL)
1037 network->connecting = FALSE;
1039 err = network->driver->disconnect(network);
1041 connman_network_set_connected(network, FALSE);
1042 set_connected(network);
1048 static int dhcp_start(struct connman_network *network)
1050 struct connman_element *element;
1053 if (network->protocol != CONNMAN_NETWORK_PROTOCOL_IP)
1056 element = connman_element_create(NULL);
1057 if (element == NULL)
1060 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
1061 element->index = network->element.index;
1063 error = connman_element_register(element, &network->element);
1065 connman_element_unref(element);
1072 static int dhcp_stop(struct connman_network *network)
1074 if (network->protocol != CONNMAN_NETWORK_PROTOCOL_IP)
1077 connman_element_unregister_children_type(&network->element,
1078 CONNMAN_ELEMENT_TYPE_CONNECTION);
1079 connman_element_unregister_children_type(&network->element,
1080 CONNMAN_ELEMENT_TYPE_IPV4);
1081 connman_element_unregister_children_type(&network->element,
1082 CONNMAN_ELEMENT_TYPE_DHCP);
1087 static int manual_ipv4_set(struct connman_network *network,
1088 struct connman_ipconfig *ipconfig)
1090 struct connman_service *service;
1093 service = __connman_service_lookup_from_network(network);
1094 if (service == NULL)
1097 err = __connman_ipconfig_set_address(ipconfig);
1099 connman_network_set_error(network,
1100 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1104 __connman_ipconfig_set_gateway(ipconfig, &network->element);
1106 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY);
1111 int __connman_network_clear_ipconfig(struct connman_network *network,
1112 struct connman_ipconfig *ipconfig)
1114 struct connman_service *service;
1115 enum connman_ipconfig_method method;
1117 service = __connman_service_lookup_from_network(network);
1118 if (service == NULL)
1121 method = __connman_ipconfig_get_method(ipconfig);
1124 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1125 case CONNMAN_IPCONFIG_METHOD_OFF:
1126 case CONNMAN_IPCONFIG_METHOD_FIXED:
1128 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1129 connman_element_unregister_children_type(&network->element,
1130 CONNMAN_ELEMENT_TYPE_CONNECTION);
1131 __connman_ipconfig_clear_address(ipconfig);
1133 case CONNMAN_IPCONFIG_METHOD_DHCP:
1138 __connman_service_indicate_state(service,
1139 CONNMAN_SERVICE_STATE_CONFIGURATION);
1144 int __connman_network_set_ipconfig(struct connman_network *network, struct connman_ipconfig *ipconfig)
1146 enum connman_ipconfig_method method;
1148 method = __connman_ipconfig_get_method(ipconfig);
1151 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1152 case CONNMAN_IPCONFIG_METHOD_OFF:
1153 case CONNMAN_IPCONFIG_METHOD_FIXED:
1155 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1156 return manual_ipv4_set(network, ipconfig);
1157 case CONNMAN_IPCONFIG_METHOD_DHCP:
1158 return dhcp_start(network);
1165 * connman_network_set_address:
1166 * @network: network structure
1167 * @address: binary address value
1168 * @size: binary address length
1170 * Set unique address value for network
1172 int connman_network_set_address(struct connman_network *network,
1173 const void *address, unsigned int size)
1175 const unsigned char *addr_octet = address;
1178 DBG("network %p size %d", network, size);
1183 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
1184 addr_octet[0], addr_octet[1], addr_octet[2],
1185 addr_octet[3], addr_octet[4], addr_octet[5]);
1189 g_free(network->address);
1190 network->address = str;
1192 return connman_element_set_string(&network->element,
1193 "Address", network->address);
1197 * connman_network_set_name:
1198 * @network: network structure
1201 * Set display name value for network
1203 int connman_network_set_name(struct connman_network *network,
1206 DBG("network %p name %s", network, name);
1208 g_free(network->name);
1209 network->name = g_strdup(name);
1211 return connman_element_set_string(&network->element, "Name", name);
1215 * connman_network_set_strength:
1216 * @network: network structure
1217 * @strength: strength value
1219 * Set signal strength value for network
1221 int connman_network_set_strength(struct connman_network *network,
1222 connman_uint8_t strength)
1224 DBG("network %p strengh %d", network, strength);
1226 network->strength = strength;
1228 return connman_element_set_uint8(&network->element,
1229 "Strength", strength);
1233 * connman_network_set_roaming:
1234 * @network: network structure
1235 * @roaming: roaming state
1237 * Set roaming state for network
1239 int connman_network_set_roaming(struct connman_network *network,
1240 connman_bool_t roaming)
1242 DBG("network %p roaming %d", network, roaming);
1244 network->roaming = roaming;
1246 return connman_element_set_bool(&network->element,
1247 "Roaming", roaming);
1251 * connman_network_set_string:
1252 * @network: network structure
1253 * @key: unique identifier
1254 * @value: string value
1256 * Set string value for specific key
1258 int connman_network_set_string(struct connman_network *network,
1259 const char *key, const char *value)
1263 DBG("network %p key %s value %s", network, key, value);
1265 if (g_strcmp0(key, "Name") == 0)
1266 return connman_network_set_name(network, value);
1268 if (g_str_equal(key, "Address") == TRUE) {
1269 g_free(network->address);
1270 network->address = g_strdup(value);
1271 } else if (g_str_equal(key, "Node") == TRUE) {
1272 g_free(network->node);
1273 network->node = g_strdup(value);
1274 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1275 g_free(network->wifi.mode);
1276 network->wifi.mode = g_strdup(value);
1277 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1278 g_free(network->wifi.security);
1279 network->wifi.security = g_strdup(value);
1280 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1281 g_free(network->wifi.passphrase);
1282 network->wifi.passphrase = g_strdup(value);
1283 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1284 g_free(network->wifi.eap);
1285 network->wifi.eap = g_strdup(value);
1286 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1287 g_free(network->wifi.identity);
1288 network->wifi.identity = g_strdup(value);
1289 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1290 g_free(network->wifi.ca_cert_path);
1291 network->wifi.ca_cert_path = g_strdup(value);
1292 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1293 g_free(network->wifi.client_cert_path);
1294 network->wifi.client_cert_path = g_strdup(value);
1295 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1296 g_free(network->wifi.private_key_path);
1297 network->wifi.private_key_path = g_strdup(value);
1298 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1299 g_free(network->wifi.private_key_passphrase);
1300 network->wifi.private_key_passphrase = g_strdup(value);
1301 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1302 g_free(network->wifi.phase2_auth);
1303 network->wifi.phase2_auth = g_strdup(value);
1306 err = connman_element_set_string(&network->element, key, value);
1310 if (network->driver == NULL)
1313 if (network->driver->setup)
1314 return network->driver->setup(network, key);
1320 * connman_network_get_string:
1321 * @network: network structure
1322 * @key: unique identifier
1324 * Get string value for specific key
1326 const char *connman_network_get_string(struct connman_network *network,
1329 DBG("network %p key %s", network, key);
1331 if (g_str_equal(key, "Address") == TRUE)
1332 return network->address;
1333 else if (g_str_equal(key, "Name") == TRUE)
1334 return network->name;
1335 else if (g_str_equal(key, "Node") == TRUE)
1336 return network->node;
1337 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1338 return network->wifi.mode;
1339 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1340 return network->wifi.security;
1341 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1342 return network->wifi.passphrase;
1343 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1344 return network->wifi.eap;
1345 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1346 return network->wifi.identity;
1347 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1348 return network->wifi.ca_cert_path;
1349 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1350 return network->wifi.client_cert_path;
1351 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1352 return network->wifi.private_key_path;
1353 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1354 return network->wifi.private_key_passphrase;
1355 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1356 return network->wifi.phase2_auth;
1358 return connman_element_get_string(&network->element, key);
1362 * connman_network_set_bool:
1363 * @network: network structure
1364 * @key: unique identifier
1365 * @value: boolean value
1367 * Set boolean value for specific key
1369 int connman_network_set_bool(struct connman_network *network,
1370 const char *key, connman_bool_t value)
1372 DBG("network %p key %s value %d", network, key, value);
1374 if (g_strcmp0(key, "Roaming") == 0)
1375 return connman_network_set_roaming(network, 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;
1395 return connman_element_get_bool(&network->element, key);
1399 * connman_network_set_uint8:
1400 * @network: network structure
1401 * @key: unique identifier
1402 * @value: integer value
1404 * Set integer value for specific key
1406 int connman_network_set_uint8(struct connman_network *network,
1407 const char *key, connman_uint8_t value)
1409 DBG("network %p key %s value %d", network, key, value);
1411 if (g_strcmp0(key, "Strength") == 0)
1412 return connman_network_set_strength(network, value);
1414 return connman_element_set_uint8(&network->element, key, value);
1418 * connman_network_get_uint8:
1419 * @network: network structure
1420 * @key: unique identifier
1422 * Get integer value for specific key
1424 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1427 DBG("network %p key %s", network, key);
1429 if (g_str_equal(key, "Strength") == TRUE)
1430 return network->strength;
1432 return connman_element_get_uint8(&network->element, key);
1436 * connman_network_set_uint16:
1437 * @network: network structure
1438 * @key: unique identifier
1439 * @value: integer value
1441 * Set integer value for specific key
1443 int connman_network_set_uint16(struct connman_network *network,
1444 const char *key, connman_uint16_t value)
1446 DBG("network %p key %s value %d", network, key, value);
1448 if (g_str_equal(key, "Frequency") == TRUE)
1449 network->frequency = value;
1450 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1451 network->wifi.channel = value;
1457 * connman_network_get_uint16:
1458 * @network: network structure
1459 * @key: unique identifier
1461 * Get integer value for specific key
1463 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1466 DBG("network %p key %s", network, key);
1468 if (g_str_equal(key, "Frequency") == TRUE)
1469 return network->frequency;
1470 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1471 return network->wifi.channel;
1477 * connman_network_set_blob:
1478 * @network: network structure
1479 * @key: unique identifier
1483 * Set binary blob value for specific key
1485 int connman_network_set_blob(struct connman_network *network,
1486 const char *key, const void *data, unsigned int size)
1488 DBG("network %p key %s size %d", network, key, size);
1490 if (g_strcmp0(key, "Address") == 0)
1491 return connman_network_set_address(network, data, size);
1493 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1494 g_free(network->wifi.ssid);
1495 network->wifi.ssid = g_try_malloc(size);
1496 if (network->wifi.ssid != NULL) {
1497 memcpy(network->wifi.ssid, data, size);
1498 network->wifi.ssid_len = size;
1500 network->wifi.ssid_len = 0;
1503 return connman_element_set_blob(&network->element, key, data, size);
1507 * connman_network_get_blob:
1508 * @network: network structure
1509 * @key: unique identifier
1510 * @size: pointer to blob size
1512 * Get binary blob value for specific key
1514 const void *connman_network_get_blob(struct connman_network *network,
1515 const char *key, unsigned int *size)
1517 DBG("network %p key %s", network, key);
1519 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1521 *size = network->wifi.ssid_len;
1522 return network->wifi.ssid;
1525 return connman_element_get_blob(&network->element, key, size);
1528 void __connman_network_set_device(struct connman_network *network,
1529 struct connman_device *device)
1531 network->device = device;
1535 * connman_network_get_device:
1536 * @network: network structure
1538 * Get parent device of network
1540 struct connman_device *connman_network_get_device(struct connman_network *network)
1542 return network->device;
1546 * connman_network_get_data:
1547 * @network: network structure
1549 * Get private network data pointer
1551 void *connman_network_get_data(struct connman_network *network)
1553 return network->driver_data;
1557 * connman_network_set_data:
1558 * @network: network structure
1559 * @data: data pointer
1561 * Set private network data pointer
1563 void connman_network_set_data(struct connman_network *network, void *data)
1565 network->driver_data = data;
1568 static gboolean match_driver(struct connman_network *network,
1569 struct connman_network_driver *driver)
1571 if (network->type == driver->type ||
1572 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1578 static int network_probe(struct connman_element *element)
1580 struct connman_network *network = element->network;
1584 DBG("element %p name %s", element, element->name);
1586 if (network == NULL)
1589 for (list = driver_list; list; list = list->next) {
1590 struct connman_network_driver *driver = list->data;
1592 if (match_driver(network, driver) == FALSE)
1595 DBG("driver %p name %s", driver, driver->name);
1597 if (driver->probe(network) == 0) {
1598 network->driver = driver;
1603 if (network->driver == NULL)
1606 err = register_interface(element);
1608 if (network->driver->remove)
1609 network->driver->remove(network);
1613 switch (network->type) {
1614 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1615 case CONNMAN_NETWORK_TYPE_VENDOR:
1617 case CONNMAN_NETWORK_TYPE_ETHERNET:
1618 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1619 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1620 case CONNMAN_NETWORK_TYPE_CELLULAR:
1621 case CONNMAN_NETWORK_TYPE_WIFI:
1622 case CONNMAN_NETWORK_TYPE_WIMAX:
1623 if (network->group != NULL)
1624 __connman_profile_add_network(network);
1631 static void network_remove(struct connman_element *element)
1633 struct connman_network *network = element->network;
1635 DBG("element %p name %s", element, element->name);
1637 if (network == NULL)
1640 if (network->driver == NULL)
1643 switch (network->type) {
1644 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1645 case CONNMAN_NETWORK_TYPE_VENDOR:
1647 case CONNMAN_NETWORK_TYPE_ETHERNET:
1648 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1649 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1650 case CONNMAN_NETWORK_TYPE_CELLULAR:
1651 case CONNMAN_NETWORK_TYPE_WIFI:
1652 case CONNMAN_NETWORK_TYPE_WIMAX:
1653 if (network->group != NULL) {
1654 __connman_profile_remove_network(network);
1656 g_free(network->group);
1657 network->group = NULL;
1662 unregister_interface(element);
1664 if (network->driver->remove)
1665 network->driver->remove(network);
1668 static void network_change(struct connman_element *element)
1670 struct connman_network *network = element->network;
1672 DBG("element %p name %s", element, element->name);
1674 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1677 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1680 if (network->connected == FALSE)
1683 connman_element_unregister_children(element);
1685 connman_device_set_disconnected(network->device, TRUE);
1687 if (network->driver && network->driver->disconnect) {
1688 network->driver->disconnect(network);
1692 network->connected = FALSE;
1695 static struct connman_driver network_driver = {
1697 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1698 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1699 .probe = network_probe,
1700 .remove = network_remove,
1701 .change = network_change,
1704 int __connman_network_init(void)
1708 connection = connman_dbus_get_connection();
1710 return connman_driver_register(&network_driver);
1713 void __connman_network_cleanup(void)
1717 connman_driver_unregister(&network_driver);
1719 dbus_connection_unref(connection);