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 emit_networks_signal(network->device);
242 g_dbus_unregister_interface(connection, element->path,
243 CONNMAN_NETWORK_INTERFACE);
246 connman_bool_t __connman_network_has_driver(struct connman_network *network)
248 if (network == NULL || network->driver == NULL)
251 return network->registered;
254 static GSList *driver_list = NULL;
256 static gint compare_priority(gconstpointer a, gconstpointer b)
258 const struct connman_network_driver *driver1 = a;
259 const struct connman_network_driver *driver2 = b;
261 return driver2->priority - driver1->priority;
265 * connman_network_driver_register:
266 * @driver: network driver definition
268 * Register a new network driver
270 * Returns: %0 on success
272 int connman_network_driver_register(struct connman_network_driver *driver)
274 DBG("driver %p name %s", driver, driver->name);
276 driver_list = g_slist_insert_sorted(driver_list, driver,
283 * connman_network_driver_unregister:
284 * @driver: network driver definition
286 * Remove a previously registered network driver
288 void connman_network_driver_unregister(struct connman_network_driver *driver)
290 DBG("driver %p name %s", driver, driver->name);
292 driver_list = g_slist_remove(driver_list, driver);
295 static void network_destruct(struct connman_element *element)
297 struct connman_network *network = element->network;
299 DBG("element %p name %s", element, element->name);
301 g_free(network->wifi.ssid);
302 g_free(network->wifi.mode);
303 g_free(network->wifi.security);
304 g_free(network->wifi.passphrase);
306 g_free(network->group);
307 g_free(network->node);
308 g_free(network->name);
309 g_free(network->address);
310 g_free(network->identifier);
312 if (network->ipconfig) {
313 connman_ipconfig_unref(network->ipconfig);
314 network->ipconfig = NULL;
319 * connman_network_create:
320 * @identifier: network identifier (for example an unqiue name)
322 * Allocate a new network and assign the #identifier to it.
324 * Returns: a newly-allocated #connman_network structure
326 struct connman_network *connman_network_create(const char *identifier,
327 enum connman_network_type type)
329 struct connman_network *network;
330 connman_uint8_t strength = 0;
334 DBG("identifier %s type %d", identifier, type);
336 network = g_try_new0(struct connman_network, 1);
340 DBG("network %p", network);
342 __connman_element_initialize(&network->element);
344 //temp = connman_dbus_encode_string(identifier);
345 if (identifier == NULL) {
346 temp = g_strdup_printf("hidden_%d", hidden_counter++);
347 network->hidden = TRUE;
349 temp = g_strdup(identifier);
356 network->element.name = temp;
357 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
359 network->element.network = network;
360 network->element.destruct = network_destruct;
362 str = type2string(type);
364 connman_element_set_string(&network->element, "Type", str);
366 connman_element_set_uint8(&network->element, "Strength", strength);
368 network->type = type;
369 network->identifier = g_strdup(temp);
375 * connman_network_ref:
376 * @network: network structure
378 * Increase reference counter of network
380 struct connman_network *connman_network_ref(struct connman_network *network)
382 if (connman_element_ref(&network->element) == NULL)
389 * connman_network_unref:
390 * @network: network structure
392 * Decrease reference counter of network
394 void connman_network_unref(struct connman_network *network)
396 connman_element_unref(&network->element);
399 const char *__connman_network_get_type(struct connman_network *network)
401 return type2string(network->type);
405 * connman_network_get_type:
406 * @network: network structure
408 * Get type of network
410 enum connman_network_type connman_network_get_type(struct connman_network *network)
412 return network->type;
416 * connman_network_get_identifier:
417 * @network: network structure
419 * Get identifier of network
421 const char *connman_network_get_identifier(struct connman_network *network)
423 return network->identifier;
427 * connman_network_get_path:
428 * @network: network structure
430 * Get path name of network
432 const char *connman_network_get_path(struct connman_network *network)
434 return network->element.path;
438 * connman_network_set_index:
439 * @network: network structure
440 * @index: index number
442 * Set index number of network
444 void connman_network_set_index(struct connman_network *network, int index)
446 if (network->element.index < 0) {
447 struct connman_service *service;
450 * This is needed for plugins that havent set their ipconfig
451 * layer yet, due to not being able to get a network index
452 * prior to creating a service.
454 service = __connman_service_lookup_from_network(network);
456 __connman_service_create_ipconfig(service, index);
459 network->element.index = index;
463 * connman_network_get_index:
464 * @network: network structure
466 * Get index number of network
468 int connman_network_get_index(struct connman_network *network)
470 return network->element.index;
474 * connman_network_get_element:
475 * @network: network structure
477 * Get connman_element of network
479 struct connman_element *connman_network_get_element(
480 struct connman_network *network)
482 return &network->element;
486 * connman_network_set_protocol:
487 * @network: network structure
488 * @protocol: network protocol
490 * Change protocol of network
492 void connman_network_set_protocol(struct connman_network *network,
493 enum connman_network_protocol protocol)
495 network->protocol = protocol;
499 * connman_network_set_group:
500 * @network: network structure
503 * Set group name for automatic clustering
505 void connman_network_set_group(struct connman_network *network,
508 switch (network->type) {
509 case CONNMAN_NETWORK_TYPE_UNKNOWN:
510 case CONNMAN_NETWORK_TYPE_VENDOR:
512 case CONNMAN_NETWORK_TYPE_ETHERNET:
513 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
514 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
515 case CONNMAN_NETWORK_TYPE_CELLULAR:
516 case CONNMAN_NETWORK_TYPE_WIFI:
517 case CONNMAN_NETWORK_TYPE_WIMAX:
521 if (g_strcmp0(network->group, group) == 0) {
523 __connman_profile_update_network(network);
527 if (network->group != NULL) {
528 __connman_profile_remove_network(network);
530 g_free(network->group);
533 network->group = g_strdup(group);
535 if (network->group != NULL)
536 __connman_profile_add_network(network);
540 * connman_network_get_group:
541 * @network: network structure
543 * Get group name for automatic clustering
545 const char *connman_network_get_group(struct connman_network *network)
547 return network->group;
550 const char *__connman_network_get_ident(struct connman_network *network)
552 if (network->device == NULL)
555 return __connman_device_get_ident(network->device);
558 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
560 switch (network->type) {
561 case CONNMAN_NETWORK_TYPE_UNKNOWN:
562 case CONNMAN_NETWORK_TYPE_VENDOR:
563 case CONNMAN_NETWORK_TYPE_ETHERNET:
564 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
565 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
566 case CONNMAN_NETWORK_TYPE_CELLULAR:
567 case CONNMAN_NETWORK_TYPE_WIMAX:
569 case CONNMAN_NETWORK_TYPE_WIFI:
570 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
572 if (network->strength > 0 && network->strength < 20)
580 connman_bool_t __connman_network_get_connecting(struct connman_network *network)
582 return network->connecting;
586 * connman_network_set_available:
587 * @network: network structure
588 * @available: availability state
590 * Change availability state of network (in range)
592 int connman_network_set_available(struct connman_network *network,
593 connman_bool_t available)
595 DBG("network %p available %d", network, available);
597 if (network->available == available)
600 network->available = available;
606 * connman_network_get_available:
607 * @network: network structure
609 * Get network available setting
611 connman_bool_t connman_network_get_available(struct connman_network *network)
613 if (network->hidden == TRUE)
616 return network->available;
620 * connman_network_set_associating:
621 * @network: network structure
622 * @associating: associating state
624 * Change associating state of network
626 int connman_network_set_associating(struct connman_network *network,
627 connman_bool_t associating)
629 DBG("network %p associating %d", network, associating);
631 if (network->associating == associating)
634 network->associating = associating;
636 if (associating == TRUE) {
637 struct connman_service *service;
639 service = __connman_service_lookup_from_network(network);
640 __connman_service_indicate_state(service,
641 CONNMAN_SERVICE_STATE_ASSOCIATION);
647 static void set_associate_error(struct connman_network *network)
649 struct connman_service *service;
651 if (network->associating == FALSE)
654 network->associating = FALSE;
656 service = __connman_service_lookup_from_network(network);
658 __connman_service_indicate_state(service,
659 CONNMAN_SERVICE_STATE_FAILURE);
662 static void set_configure_error(struct connman_network *network)
664 struct connman_service *service;
666 network->connecting = FALSE;
668 service = __connman_service_lookup_from_network(network);
670 __connman_service_indicate_state(service,
671 CONNMAN_SERVICE_STATE_FAILURE);
674 void connman_network_set_method(struct connman_network *network,
675 enum connman_ipconfig_method method)
677 struct connman_service *service;
678 struct connman_ipconfig *ipconfig;
680 network->element.ipv4.method = method;
682 service = __connman_service_lookup_from_network(network);
686 ipconfig = __connman_service_get_ipconfig(service);
687 if (ipconfig == NULL)
690 connman_ipconfig_set_method(ipconfig, method);
693 void connman_network_set_error(struct connman_network *network,
694 enum connman_network_error error)
696 DBG("nework %p, error %d", network, error);
698 network->connecting = FALSE;
701 case CONNMAN_NETWORK_ERROR_UNKNOWN:
703 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
704 set_associate_error(network);
706 case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
707 set_configure_error(network);
712 static void set_configuration(struct connman_network *network)
714 struct connman_service *service;
716 DBG("network %p", network);
718 __connman_device_increase_connections(network->device);
720 __connman_device_set_network(network->device, network);
722 connman_device_set_disconnected(network->device, FALSE);
724 service = __connman_service_lookup_from_network(network);
725 __connman_service_indicate_state(service,
726 CONNMAN_SERVICE_STATE_CONFIGURATION);
729 static void set_connected_manual(struct connman_network *network)
731 struct connman_service *service;
732 struct connman_ipconfig *ipconfig;
735 DBG("network %p", network);
737 service = __connman_service_lookup_from_network(network);
739 ipconfig = __connman_service_get_ipconfig(service);
741 set_configuration(network);
743 err = __connman_ipconfig_set_address(ipconfig);
745 connman_network_set_error(network,
746 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
750 network->connecting = FALSE;
752 connman_network_set_associating(network, FALSE);
754 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY);
757 static int set_connected_dhcp(struct connman_network *network)
759 struct connman_element *element;
762 DBG("network %p", network);
764 if (network->protocol != CONNMAN_NETWORK_PROTOCOL_IP)
767 element = connman_element_create(NULL);
771 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
772 element->index = network->element.index;
774 error = connman_element_register(element, &network->element);
776 connman_element_unref(element);
780 set_configuration(network);
785 static gboolean set_connected(gpointer user_data)
787 struct connman_network *network = user_data;
788 struct connman_service *service;
789 struct connman_ipconfig *ipconfig;
790 enum connman_ipconfig_method method;
792 service = __connman_service_lookup_from_network(network);
794 ipconfig = __connman_service_get_ipconfig(service);
796 method = __connman_ipconfig_get_method(ipconfig);
798 DBG("method %d", method);
800 if (network->connected == TRUE) {
802 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
803 case CONNMAN_IPCONFIG_METHOD_OFF:
805 case CONNMAN_IPCONFIG_METHOD_MANUAL:
806 case CONNMAN_IPCONFIG_METHOD_FIXED:
807 set_connected_manual(network);
809 case CONNMAN_IPCONFIG_METHOD_DHCP:
810 if (set_connected_dhcp(network) < 0) {
811 connman_network_set_error(network,
812 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
818 struct connman_service *service;
820 connman_element_unregister_children(&network->element);
822 __connman_device_set_network(network->device, NULL);
823 network->hidden = FALSE;
825 __connman_device_decrease_connections(network->device);
827 service = __connman_service_lookup_from_network(network);
829 __connman_service_indicate_state(service,
830 CONNMAN_SERVICE_STATE_IDLE);
833 network->connecting = FALSE;
835 connman_network_set_associating(network, FALSE);
841 * connman_network_set_connected:
842 * @network: network structure
843 * @connected: connected state
845 * Change connected state of network
847 int connman_network_set_connected(struct connman_network *network,
848 connman_bool_t connected)
850 DBG("network %p connected %d", network, connected);
852 if ((network->connecting == TRUE || network->associating == TRUE) &&
853 connected == FALSE) {
854 connman_element_set_error(&network->element,
855 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
856 __connman_network_disconnect(network);
859 if (network->connected == connected)
862 network->connected = connected;
864 if (network->registered == FALSE) {
865 g_idle_add(set_connected, network);
869 connman_dbus_property_changed_basic(network->element.path,
870 CONNMAN_NETWORK_INTERFACE, "Connected",
871 DBUS_TYPE_BOOLEAN, &connected);
873 set_connected(network);
879 * connman_network_get_connected:
880 * @network: network structure
882 * Get network connection status
884 connman_bool_t connman_network_get_connected(struct connman_network *network)
886 return network->connected;
890 * connman_network_get_associating:
891 * @network: network structure
893 * Get network associating status
895 connman_bool_t connman_network_get_associating(struct connman_network *network)
897 return network->associating;
901 * __connman_network_connect:
902 * @network: network structure
906 int __connman_network_connect(struct connman_network *network)
910 DBG("network %p", network);
912 if (network->connected == TRUE)
915 if (network->connecting == TRUE || network->associating == TRUE)
918 if (network->driver == NULL)
921 if (network->driver->connect == NULL)
924 __connman_device_disconnect(network->device);
926 network->connecting = TRUE;
928 err = network->driver->connect(network);
930 if (err == -EINPROGRESS)
931 connman_network_set_associating(network, TRUE);
933 network->connecting = FALSE;
934 network->hidden = FALSE;
940 network->connected = TRUE;
941 set_connected(network);
947 * __connman_network_disconnect:
948 * @network: network structure
952 int __connman_network_disconnect(struct connman_network *network)
956 DBG("network %p", network);
958 if (network->connected == FALSE && network->connecting == FALSE &&
959 network->associating == FALSE)
962 if (network->driver == NULL)
965 if (network->driver->disconnect == NULL)
968 network->connecting = FALSE;
970 err = network->driver->disconnect(network);
972 connman_network_set_connected(network, FALSE);
973 set_connected(network);
980 * connman_network_set_address:
981 * @network: network structure
982 * @address: binary address value
983 * @size: binary address length
985 * Set unique address value for network
987 int connman_network_set_address(struct connman_network *network,
988 const void *address, unsigned int size)
990 const unsigned char *addr_octet = address;
993 DBG("network %p size %d", network, size);
998 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
999 addr_octet[0], addr_octet[1], addr_octet[2],
1000 addr_octet[3], addr_octet[4], addr_octet[5]);
1004 g_free(network->address);
1005 network->address = str;
1007 return connman_element_set_string(&network->element,
1008 "Address", network->address);
1012 * connman_network_set_name:
1013 * @network: network structure
1016 * Set display name value for network
1018 int connman_network_set_name(struct connman_network *network,
1021 DBG("network %p name %s", network, name);
1023 g_free(network->name);
1024 network->name = g_strdup(name);
1026 return connman_element_set_string(&network->element, "Name", name);
1030 * connman_network_set_strength:
1031 * @network: network structure
1032 * @strength: strength value
1034 * Set signal strength value for network
1036 int connman_network_set_strength(struct connman_network *network,
1037 connman_uint8_t strength)
1039 DBG("network %p strengh %d", network, strength);
1041 network->strength = strength;
1043 return connman_element_set_uint8(&network->element,
1044 "Strength", strength);
1048 * connman_network_set_roaming:
1049 * @network: network structure
1050 * @roaming: roaming state
1052 * Set roaming state for network
1054 int connman_network_set_roaming(struct connman_network *network,
1055 connman_bool_t roaming)
1057 DBG("network %p roaming %d", network, roaming);
1059 network->roaming = roaming;
1061 return connman_element_set_bool(&network->element,
1062 "Roaming", roaming);
1066 * connman_network_set_string:
1067 * @network: network structure
1068 * @key: unique identifier
1069 * @value: string value
1071 * Set string value for specific key
1073 int connman_network_set_string(struct connman_network *network,
1074 const char *key, const char *value)
1078 DBG("network %p key %s value %s", network, key, value);
1080 if (g_strcmp0(key, "Name") == 0)
1081 return connman_network_set_name(network, value);
1083 if (g_str_equal(key, "Address") == TRUE) {
1084 g_free(network->address);
1085 network->address = g_strdup(value);
1086 } else if (g_str_equal(key, "Node") == TRUE) {
1087 g_free(network->node);
1088 network->node = g_strdup(value);
1089 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1090 g_free(network->wifi.mode);
1091 network->wifi.mode = g_strdup(value);
1092 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1093 g_free(network->wifi.security);
1094 network->wifi.security = g_strdup(value);
1095 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1096 g_free(network->wifi.passphrase);
1097 network->wifi.passphrase = g_strdup(value);
1098 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1099 g_free(network->wifi.eap);
1100 network->wifi.eap = g_strdup(value);
1101 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1102 g_free(network->wifi.identity);
1103 network->wifi.identity = g_strdup(value);
1104 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1105 g_free(network->wifi.ca_cert_path);
1106 network->wifi.ca_cert_path = g_strdup(value);
1107 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1108 g_free(network->wifi.client_cert_path);
1109 network->wifi.client_cert_path = g_strdup(value);
1110 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1111 g_free(network->wifi.private_key_path);
1112 network->wifi.private_key_path = g_strdup(value);
1113 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1114 g_free(network->wifi.private_key_passphrase);
1115 network->wifi.private_key_passphrase = g_strdup(value);
1116 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1117 g_free(network->wifi.phase2_auth);
1118 network->wifi.phase2_auth = g_strdup(value);
1121 err = connman_element_set_string(&network->element, key, value);
1125 if (network->driver == NULL)
1128 if (network->driver->setup)
1129 return network->driver->setup(network, key);
1135 * connman_network_get_string:
1136 * @network: network structure
1137 * @key: unique identifier
1139 * Get string value for specific key
1141 const char *connman_network_get_string(struct connman_network *network,
1144 DBG("network %p key %s", network, key);
1146 if (g_str_equal(key, "Address") == TRUE)
1147 return network->address;
1148 else if (g_str_equal(key, "Name") == TRUE)
1149 return network->name;
1150 else if (g_str_equal(key, "Node") == TRUE)
1151 return network->node;
1152 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1153 return network->wifi.mode;
1154 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1155 return network->wifi.security;
1156 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1157 return network->wifi.passphrase;
1158 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1159 return network->wifi.eap;
1160 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1161 return network->wifi.identity;
1162 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1163 return network->wifi.ca_cert_path;
1164 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1165 return network->wifi.client_cert_path;
1166 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1167 return network->wifi.private_key_path;
1168 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1169 return network->wifi.private_key_passphrase;
1170 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1171 return network->wifi.phase2_auth;
1173 return connman_element_get_string(&network->element, key);
1177 * connman_network_set_bool:
1178 * @network: network structure
1179 * @key: unique identifier
1180 * @value: boolean value
1182 * Set boolean value for specific key
1184 int connman_network_set_bool(struct connman_network *network,
1185 const char *key, connman_bool_t value)
1187 DBG("network %p key %s value %d", network, key, value);
1189 if (g_strcmp0(key, "Roaming") == 0)
1190 return connman_network_set_roaming(network, value);
1192 return connman_element_set_bool(&network->element, key, value);
1196 * connman_network_get_bool:
1197 * @network: network structure
1198 * @key: unique identifier
1200 * Get boolean value for specific key
1202 connman_bool_t connman_network_get_bool(struct connman_network *network,
1205 DBG("network %p key %s", network, key);
1207 if (g_str_equal(key, "Roaming") == TRUE)
1208 return network->roaming;
1210 return connman_element_get_bool(&network->element, key);
1214 * connman_network_set_uint8:
1215 * @network: network structure
1216 * @key: unique identifier
1217 * @value: integer value
1219 * Set integer value for specific key
1221 int connman_network_set_uint8(struct connman_network *network,
1222 const char *key, connman_uint8_t value)
1224 DBG("network %p key %s value %d", network, key, value);
1226 if (g_strcmp0(key, "Strength") == 0)
1227 return connman_network_set_strength(network, value);
1229 return connman_element_set_uint8(&network->element, key, value);
1233 * connman_network_get_uint8:
1234 * @network: network structure
1235 * @key: unique identifier
1237 * Get integer value for specific key
1239 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1242 DBG("network %p key %s", network, key);
1244 if (g_str_equal(key, "Strength") == TRUE)
1245 return network->strength;
1247 return connman_element_get_uint8(&network->element, key);
1251 * connman_network_set_uint16:
1252 * @network: network structure
1253 * @key: unique identifier
1254 * @value: integer value
1256 * Set integer value for specific key
1258 int connman_network_set_uint16(struct connman_network *network,
1259 const char *key, connman_uint16_t value)
1261 DBG("network %p key %s value %d", network, key, value);
1263 if (g_str_equal(key, "Frequency") == TRUE)
1264 network->frequency = value;
1265 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1266 network->wifi.channel = value;
1272 * connman_network_get_uint16:
1273 * @network: network structure
1274 * @key: unique identifier
1276 * Get integer value for specific key
1278 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1281 DBG("network %p key %s", network, key);
1283 if (g_str_equal(key, "Frequency") == TRUE)
1284 return network->frequency;
1285 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1286 return network->wifi.channel;
1292 * connman_network_set_blob:
1293 * @network: network structure
1294 * @key: unique identifier
1298 * Set binary blob value for specific key
1300 int connman_network_set_blob(struct connman_network *network,
1301 const char *key, const void *data, unsigned int size)
1303 DBG("network %p key %s size %d", network, key, size);
1305 if (g_strcmp0(key, "Address") == 0)
1306 return connman_network_set_address(network, data, size);
1308 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1309 g_free(network->wifi.ssid);
1310 network->wifi.ssid = g_try_malloc(size);
1311 if (network->wifi.ssid != NULL) {
1312 memcpy(network->wifi.ssid, data, size);
1313 network->wifi.ssid_len = size;
1315 network->wifi.ssid_len = 0;
1318 return connman_element_set_blob(&network->element, key, data, size);
1322 * connman_network_get_blob:
1323 * @network: network structure
1324 * @key: unique identifier
1325 * @size: pointer to blob size
1327 * Get binary blob value for specific key
1329 const void *connman_network_get_blob(struct connman_network *network,
1330 const char *key, unsigned int *size)
1332 DBG("network %p key %s", network, key);
1334 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1336 *size = network->wifi.ssid_len;
1337 return network->wifi.ssid;
1340 return connman_element_get_blob(&network->element, key, size);
1343 void __connman_network_set_device(struct connman_network *network,
1344 struct connman_device *device)
1346 network->device = device;
1350 * connman_network_get_device:
1351 * @network: network structure
1353 * Get parent device of network
1355 struct connman_device *connman_network_get_device(struct connman_network *network)
1357 return network->device;
1361 * connman_network_get_data:
1362 * @network: network structure
1364 * Get private network data pointer
1366 void *connman_network_get_data(struct connman_network *network)
1368 return network->driver_data;
1372 * connman_network_set_data:
1373 * @network: network structure
1374 * @data: data pointer
1376 * Set private network data pointer
1378 void connman_network_set_data(struct connman_network *network, void *data)
1380 network->driver_data = data;
1383 static gboolean match_driver(struct connman_network *network,
1384 struct connman_network_driver *driver)
1386 if (network->type == driver->type ||
1387 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1393 static int network_probe(struct connman_element *element)
1395 struct connman_network *network = element->network;
1399 DBG("element %p name %s", element, element->name);
1401 if (network == NULL)
1404 for (list = driver_list; list; list = list->next) {
1405 struct connman_network_driver *driver = list->data;
1407 if (match_driver(network, driver) == FALSE)
1410 DBG("driver %p name %s", driver, driver->name);
1412 if (driver->probe(network) == 0) {
1413 network->driver = driver;
1418 if (network->driver == NULL)
1421 err = register_interface(element);
1423 if (network->driver->remove)
1424 network->driver->remove(network);
1428 switch (network->type) {
1429 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1430 case CONNMAN_NETWORK_TYPE_VENDOR:
1432 case CONNMAN_NETWORK_TYPE_ETHERNET:
1433 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1434 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1435 case CONNMAN_NETWORK_TYPE_CELLULAR:
1436 case CONNMAN_NETWORK_TYPE_WIFI:
1437 case CONNMAN_NETWORK_TYPE_WIMAX:
1438 if (network->group != NULL)
1439 __connman_profile_add_network(network);
1446 static void network_remove(struct connman_element *element)
1448 struct connman_network *network = element->network;
1450 DBG("element %p name %s", element, element->name);
1452 if (network == NULL)
1455 if (network->driver == NULL)
1458 switch (network->type) {
1459 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1460 case CONNMAN_NETWORK_TYPE_VENDOR:
1462 case CONNMAN_NETWORK_TYPE_ETHERNET:
1463 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1464 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1465 case CONNMAN_NETWORK_TYPE_CELLULAR:
1466 case CONNMAN_NETWORK_TYPE_WIFI:
1467 case CONNMAN_NETWORK_TYPE_WIMAX:
1468 if (network->group != NULL) {
1469 __connman_profile_remove_network(network);
1471 g_free(network->group);
1472 network->group = NULL;
1477 unregister_interface(element);
1479 if (network->driver->remove)
1480 network->driver->remove(network);
1483 static void network_change(struct connman_element *element)
1485 struct connman_network *network = element->network;
1487 DBG("element %p name %s", element, element->name);
1489 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1492 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1495 if (network->connected == FALSE)
1498 connman_element_unregister_children(element);
1500 connman_device_set_disconnected(network->device, TRUE);
1502 if (network->driver && network->driver->disconnect) {
1503 network->driver->disconnect(network);
1507 network->connected = FALSE;
1510 static struct connman_driver network_driver = {
1512 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1513 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1514 .probe = network_probe,
1515 .remove = network_remove,
1516 .change = network_change,
1519 int __connman_network_init(void)
1523 connection = connman_dbus_get_connection();
1525 return connman_driver_register(&network_driver);
1528 void __connman_network_cleanup(void)
1532 connman_driver_unregister(&network_driver);
1534 dbus_connection_unref(connection);