5 * Copyright (C) 2007-2009 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:
94 case CONNMAN_NETWORK_TYPE_MBM:
95 case CONNMAN_NETWORK_TYPE_HSO:
102 static DBusMessage *get_properties(DBusConnection *conn,
103 DBusMessage *msg, void *data)
105 struct connman_network *network = data;
107 DBusMessageIter array, dict;
109 DBG("conn %p", conn);
111 if (__connman_security_check_privilege(msg,
112 CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
113 return __connman_error_permission_denied(msg);
115 reply = dbus_message_new_method_return(msg);
119 dbus_message_iter_init_append(reply, &array);
121 connman_dbus_dict_open(&array, &dict);
123 if (network->device) {
124 const char *path = connman_device_get_path(network->device);
126 connman_dbus_dict_append_basic(&dict, "Device",
127 DBUS_TYPE_OBJECT_PATH, &path);
130 if (network->address != NULL)
131 connman_dbus_dict_append_basic(&dict, "Address",
132 DBUS_TYPE_STRING, &network->address);
134 if (network->name != NULL)
135 connman_dbus_dict_append_basic(&dict, "Name",
136 DBUS_TYPE_STRING, &network->name);
138 connman_dbus_dict_append_basic(&dict, "Connected",
139 DBUS_TYPE_BOOLEAN, &network->connected);
141 if (network->strength > 0)
142 connman_dbus_dict_append_basic(&dict, "Strength",
143 DBUS_TYPE_BYTE, &network->strength);
145 if (network->frequency > 0)
146 connman_dbus_dict_append_basic(&dict, "Frequency",
147 DBUS_TYPE_UINT16, &network->frequency);
149 if (network->wifi.ssid != NULL && network->wifi.ssid_len > 0)
150 connman_dbus_dict_append_fixed_array(&dict, "WiFi.SSID",
151 DBUS_TYPE_BYTE, &network->wifi.ssid,
152 network->wifi.ssid_len);
154 if (network->wifi.mode != NULL)
155 connman_dbus_dict_append_basic(&dict, "WiFi.Mode",
156 DBUS_TYPE_STRING, &network->wifi.mode);
158 if (network->wifi.channel > 0)
159 connman_dbus_dict_append_basic(&dict, "WiFi.Channel",
160 DBUS_TYPE_UINT16, &network->wifi.channel);
162 if (network->wifi.security != NULL) {
163 connman_dbus_dict_append_basic(&dict, "WiFi.Security",
164 DBUS_TYPE_STRING, &network->wifi.security);
166 if (g_strcmp0(network->wifi.security, "ieee8021x") == 0 &&
167 network->wifi.eap != NULL)
168 connman_dbus_dict_append_basic(&dict, "WiFi.EAP",
169 DBUS_TYPE_STRING, &network->wifi.eap);
173 if (network->wifi.passphrase != NULL &&
174 __connman_security_check_privilege(msg,
175 CONNMAN_SECURITY_PRIVILEGE_SECRET) == 0)
176 connman_dbus_dict_append_basic(&dict, "WiFi.Passphrase",
177 DBUS_TYPE_STRING, &network->wifi.passphrase);
179 connman_dbus_dict_close(&array, &dict);
184 static GDBusMethodTable network_methods[] = {
185 { "GetProperties", "", "a{sv}", get_properties },
189 static GDBusSignalTable network_signals[] = {
190 { "PropertyChanged", "sv" },
194 static DBusConnection *connection;
196 static void append_networks(DBusMessageIter *iter, void *user_data)
198 struct connman_device *device = user_data;
200 __connman_element_list((struct connman_element *) device,
201 CONNMAN_ELEMENT_TYPE_NETWORK, iter);
204 static void emit_networks_signal(struct connman_device *device)
206 const char *path = connman_device_get_path(device);
208 connman_dbus_property_changed_array(path,
209 CONNMAN_DEVICE_INTERFACE, "Networks",
210 DBUS_TYPE_OBJECT_PATH, append_networks, device);
213 static int register_interface(struct connman_element *element)
215 struct connman_network *network = element->network;
217 DBG("element %p name %s", element, element->name);
219 if (g_dbus_register_interface(connection, element->path,
220 CONNMAN_NETWORK_INTERFACE,
221 network_methods, network_signals,
222 NULL, network, NULL) == FALSE) {
223 connman_error("Failed to register %s network", element->path);
227 network->registered = TRUE;
229 emit_networks_signal(network->device);
234 static void unregister_interface(struct connman_element *element)
236 struct connman_network * network = element->network;
238 DBG("element %p name %s", element, element->name);
240 network->registered = FALSE;
242 emit_networks_signal(network->device);
244 g_dbus_unregister_interface(connection, element->path,
245 CONNMAN_NETWORK_INTERFACE);
248 connman_bool_t __connman_network_has_driver(struct connman_network *network)
250 if (network == NULL || network->driver == NULL)
253 return network->registered;
256 static GSList *driver_list = NULL;
258 static gint compare_priority(gconstpointer a, gconstpointer b)
260 const struct connman_network_driver *driver1 = a;
261 const struct connman_network_driver *driver2 = b;
263 return driver2->priority - driver1->priority;
267 * connman_network_driver_register:
268 * @driver: network driver definition
270 * Register a new network driver
272 * Returns: %0 on success
274 int connman_network_driver_register(struct connman_network_driver *driver)
276 DBG("driver %p name %s", driver, driver->name);
278 driver_list = g_slist_insert_sorted(driver_list, driver,
285 * connman_network_driver_unregister:
286 * @driver: network driver definition
288 * Remove a previously registered network driver
290 void connman_network_driver_unregister(struct connman_network_driver *driver)
292 DBG("driver %p name %s", driver, driver->name);
294 driver_list = g_slist_remove(driver_list, driver);
297 static void network_destruct(struct connman_element *element)
299 struct connman_network *network = element->network;
301 DBG("element %p name %s", element, element->name);
303 g_free(network->wifi.ssid);
304 g_free(network->wifi.mode);
305 g_free(network->wifi.security);
306 g_free(network->wifi.passphrase);
308 g_free(network->group);
309 g_free(network->node);
310 g_free(network->name);
311 g_free(network->address);
312 g_free(network->identifier);
314 if (network->ipconfig) {
315 connman_ipconfig_unref(network->ipconfig);
316 network->ipconfig = NULL;
321 * connman_network_create:
322 * @identifier: network identifier (for example an unqiue name)
324 * Allocate a new network and assign the #identifier to it.
326 * Returns: a newly-allocated #connman_network structure
328 struct connman_network *connman_network_create(const char *identifier,
329 enum connman_network_type type)
331 struct connman_network *network;
332 connman_uint8_t strength = 0;
336 DBG("identifier %s type %d", identifier, type);
338 network = g_try_new0(struct connman_network, 1);
342 DBG("network %p", network);
344 __connman_element_initialize(&network->element);
346 //temp = connman_dbus_encode_string(identifier);
347 if (identifier == NULL) {
348 temp = g_strdup_printf("hidden_%d", hidden_counter++);
349 network->hidden = TRUE;
351 temp = g_strdup(identifier);
358 network->element.name = temp;
359 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
361 network->element.network = network;
362 network->element.destruct = network_destruct;
364 str = type2string(type);
366 connman_element_set_string(&network->element, "Type", str);
368 connman_element_set_uint8(&network->element, "Strength", strength);
370 network->type = type;
371 network->identifier = g_strdup(temp);
377 * connman_network_ref:
378 * @network: network structure
380 * Increase reference counter of network
382 struct connman_network *connman_network_ref(struct connman_network *network)
384 if (connman_element_ref(&network->element) == NULL)
391 * connman_network_unref:
392 * @network: network structure
394 * Decrease reference counter of network
396 void connman_network_unref(struct connman_network *network)
398 connman_element_unref(&network->element);
401 const char *__connman_network_get_type(struct connman_network *network)
403 return type2string(network->type);
407 * connman_network_get_type:
408 * @network: network structure
410 * Get type of network
412 enum connman_network_type connman_network_get_type(struct connman_network *network)
414 return network->type;
418 * connman_network_get_identifier:
419 * @network: network structure
421 * Get identifier of network
423 const char *connman_network_get_identifier(struct connman_network *network)
425 return network->identifier;
429 * connman_network_get_path:
430 * @network: network structure
432 * Get path name of network
434 const char *connman_network_get_path(struct connman_network *network)
436 return network->element.path;
440 * connman_network_set_index:
441 * @network: network structure
442 * @index: index number
444 * Set index number of network
446 void connman_network_set_index(struct connman_network *network, int index)
448 network->element.index = index;
452 * connman_network_get_index:
453 * @network: network structure
455 * Get index number of network
457 int connman_network_get_index(struct connman_network *network)
459 return network->element.index;
463 * connman_network_get_element:
464 * @network: network structure
466 * Get connman_element of network
468 struct connman_element *connman_network_get_element(
469 struct connman_network *network)
471 return &network->element;
475 * connman_network_set_protocol:
476 * @network: network structure
477 * @protocol: network protocol
479 * Change protocol of network
481 void connman_network_set_protocol(struct connman_network *network,
482 enum connman_network_protocol protocol)
484 network->protocol = protocol;
488 * connman_network_set_group:
489 * @network: network structure
492 * Set group name for automatic clustering
494 void connman_network_set_group(struct connman_network *network,
497 switch (network->type) {
498 case CONNMAN_NETWORK_TYPE_UNKNOWN:
499 case CONNMAN_NETWORK_TYPE_VENDOR:
501 case CONNMAN_NETWORK_TYPE_ETHERNET:
502 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
503 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
504 case CONNMAN_NETWORK_TYPE_CELLULAR:
505 case CONNMAN_NETWORK_TYPE_MBM:
506 case CONNMAN_NETWORK_TYPE_HSO:
507 case CONNMAN_NETWORK_TYPE_WIFI:
508 case CONNMAN_NETWORK_TYPE_WIMAX:
512 if (g_strcmp0(network->group, group) == 0) {
514 __connman_profile_update_network(network);
518 if (network->group != NULL) {
519 __connman_profile_remove_network(network);
521 g_free(network->group);
524 network->group = g_strdup(group);
526 if (network->group != NULL)
527 __connman_profile_add_network(network);
531 * connman_network_get_group:
532 * @network: network structure
534 * Get group name for automatic clustering
536 const char *connman_network_get_group(struct connman_network *network)
538 return network->group;
541 const char *__connman_network_get_ident(struct connman_network *network)
543 if (network->device == NULL)
546 return __connman_device_get_ident(network->device);
549 connman_bool_t __connman_network_get_weakness(struct connman_network *network)
551 switch (network->type) {
552 case CONNMAN_NETWORK_TYPE_UNKNOWN:
553 case CONNMAN_NETWORK_TYPE_VENDOR:
554 case CONNMAN_NETWORK_TYPE_ETHERNET:
555 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
556 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
557 case CONNMAN_NETWORK_TYPE_CELLULAR:
558 case CONNMAN_NETWORK_TYPE_MBM:
559 case CONNMAN_NETWORK_TYPE_HSO:
560 case CONNMAN_NETWORK_TYPE_WIMAX:
562 case CONNMAN_NETWORK_TYPE_WIFI:
563 if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
565 if (network->strength > 0 && network->strength < 20)
573 connman_bool_t __connman_network_get_connecting(struct connman_network *network)
575 return network->connecting;
579 * connman_network_set_available:
580 * @network: network structure
581 * @available: availability state
583 * Change availability state of network (in range)
585 int connman_network_set_available(struct connman_network *network,
586 connman_bool_t available)
588 DBG("network %p available %d", network, available);
590 if (network->available == available)
593 network->available = available;
599 * connman_network_get_available:
600 * @network: network structure
602 * Get network available setting
604 connman_bool_t connman_network_get_available(struct connman_network *network)
606 if (network->hidden == TRUE)
609 return network->available;
613 * connman_network_set_associating:
614 * @network: network structure
615 * @associating: associating state
617 * Change associating state of network
619 int connman_network_set_associating(struct connman_network *network,
620 connman_bool_t associating)
622 DBG("network %p associating %d", network, associating);
624 if (network->associating == associating)
627 network->associating = associating;
629 if (associating == TRUE) {
630 struct connman_service *service;
632 service = __connman_service_lookup_from_network(network);
633 __connman_service_indicate_state(service,
634 CONNMAN_SERVICE_STATE_ASSOCIATION);
640 static void set_associate_error(struct connman_network *network)
642 struct connman_service *service;
644 if (network->associating == FALSE)
647 network->associating = FALSE;
649 service = __connman_service_lookup_from_network(network);
651 __connman_service_indicate_state(service,
652 CONNMAN_SERVICE_STATE_FAILURE);
655 void connman_network_set_method(struct connman_network *network,
656 enum connman_ipconfig_method method)
658 network->element.ipv4.method = method;
661 void connman_network_set_error(struct connman_network *network,
662 enum connman_network_error error)
664 DBG("nework %p, error %d", network, error);
666 network->connecting = FALSE;
669 case CONNMAN_NETWORK_ERROR_UNKNOWN:
671 case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
672 set_associate_error(network);
677 static void set_connected_manual(struct connman_network *network)
679 struct connman_service *service;
683 __connman_device_increase_connections(network->device);
685 __connman_device_set_network(network->device, network);
687 connman_device_set_disconnected(network->device, FALSE);
689 service = __connman_service_lookup_from_network(network);
691 network->connecting = FALSE;
693 connman_network_set_associating(network, FALSE);
695 __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY);
698 static int set_connected_dhcp(struct connman_network *network)
700 struct connman_element *element;
701 struct connman_service *service;
704 DBG("network %p", network);
706 if (network->protocol != CONNMAN_NETWORK_PROTOCOL_IP)
709 service = __connman_service_lookup_from_network(network);
712 element = connman_element_create(NULL);
716 element->type = CONNMAN_ELEMENT_TYPE_DHCP;
717 element->index = network->element.index;
719 error = connman_element_register(element, &network->element);
721 connman_element_unref(element);
725 __connman_device_increase_connections(network->device);
727 __connman_device_set_network(network->device, network);
729 connman_device_set_disconnected(network->device, FALSE);
731 __connman_service_indicate_state(service,
732 CONNMAN_SERVICE_STATE_CONFIGURATION);
737 static gboolean set_connected(gpointer user_data)
739 struct connman_network *network = user_data;
741 DBG("network method %d", network->element.ipv4.method);
743 if (network->connected == TRUE) {
744 switch (network->element.ipv4.method) {
745 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
746 case CONNMAN_IPCONFIG_METHOD_OFF:
748 case CONNMAN_IPCONFIG_METHOD_MANUAL:
749 case CONNMAN_IPCONFIG_METHOD_FIXED:
750 set_connected_manual(network);
752 case CONNMAN_IPCONFIG_METHOD_DHCP:
753 if (set_connected_dhcp(network) < 0) {
754 connman_network_set_error(network,
755 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
761 struct connman_service *service;
763 connman_element_unregister_children(&network->element);
765 __connman_device_set_network(network->device, NULL);
766 network->hidden = FALSE;
768 __connman_device_decrease_connections(network->device);
770 service = __connman_service_lookup_from_network(network);
772 __connman_service_indicate_state(service,
773 CONNMAN_SERVICE_STATE_IDLE);
776 network->connecting = FALSE;
778 connman_network_set_associating(network, FALSE);
784 * connman_network_set_connected:
785 * @network: network structure
786 * @connected: connected state
788 * Change connected state of network
790 int connman_network_set_connected(struct connman_network *network,
791 connman_bool_t connected)
793 DBG("network %p connected %d", network, connected);
795 if ((network->connecting == TRUE || network->associating == TRUE) &&
796 connected == FALSE) {
797 connman_element_set_error(&network->element,
798 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
799 __connman_network_disconnect(network);
802 if (network->connected == connected)
805 network->connected = connected;
807 if (network->registered == FALSE) {
808 g_idle_add(set_connected, network);
812 connman_dbus_property_changed_basic(network->element.path,
813 CONNMAN_NETWORK_INTERFACE, "Connected",
814 DBUS_TYPE_BOOLEAN, &connected);
816 set_connected(network);
822 * connman_network_get_connected:
823 * @network: network structure
825 * Get network connection status
827 connman_bool_t connman_network_get_connected(struct connman_network *network)
829 return network->connected;
833 * connman_network_get_associating:
834 * @network: network structure
836 * Get network associating status
838 connman_bool_t connman_network_get_associating(struct connman_network *network)
840 return network->associating;
844 * __connman_network_connect:
845 * @network: network structure
849 int __connman_network_connect(struct connman_network *network)
853 DBG("network %p", network);
855 if (network->connected == TRUE)
858 if (network->connecting == TRUE || network->associating == TRUE)
861 if (network->driver == NULL)
864 if (network->driver->connect == NULL)
867 __connman_device_disconnect(network->device);
869 network->connecting = TRUE;
871 err = network->driver->connect(network);
873 if (err == -EINPROGRESS)
874 connman_network_set_associating(network, TRUE);
876 network->hidden = FALSE;
881 network->connected = TRUE;
882 set_connected(network);
888 * __connman_network_disconnect:
889 * @network: network structure
893 int __connman_network_disconnect(struct connman_network *network)
897 DBG("network %p", network);
899 if (network->connected == FALSE && network->connecting == FALSE &&
900 network->associating == FALSE)
903 if (network->driver == NULL)
906 if (network->driver->disconnect == NULL)
909 network->connecting = FALSE;
911 err = network->driver->disconnect(network);
913 network->connected = FALSE;
914 set_connected(network);
921 * connman_network_set_address:
922 * @network: network structure
923 * @address: binary address value
924 * @size: binary address length
926 * Set unique address value for network
928 int connman_network_set_address(struct connman_network *network,
929 const void *address, unsigned int size)
931 const unsigned char *addr_octet = address;
934 DBG("network %p size %d", network, size);
939 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
940 addr_octet[0], addr_octet[1], addr_octet[2],
941 addr_octet[3], addr_octet[4], addr_octet[5]);
945 g_free(network->address);
946 network->address = str;
948 return connman_element_set_string(&network->element,
949 "Address", network->address);
953 * connman_network_set_name:
954 * @network: network structure
957 * Set display name value for network
959 int connman_network_set_name(struct connman_network *network,
962 DBG("network %p name %s", network, name);
964 g_free(network->name);
965 network->name = g_strdup(name);
967 return connman_element_set_string(&network->element, "Name", name);
971 * connman_network_set_strength:
972 * @network: network structure
973 * @strength: strength value
975 * Set signal strength value for network
977 int connman_network_set_strength(struct connman_network *network,
978 connman_uint8_t strength)
980 DBG("network %p strengh %d", network, strength);
982 network->strength = strength;
984 return connman_element_set_uint8(&network->element,
985 "Strength", strength);
989 * connman_network_set_roaming:
990 * @network: network structure
991 * @roaming: roaming state
993 * Set roaming state for network
995 int connman_network_set_roaming(struct connman_network *network,
996 connman_bool_t roaming)
998 DBG("network %p roaming %d", network, roaming);
1000 network->roaming = roaming;
1002 return connman_element_set_bool(&network->element,
1003 "Roaming", roaming);
1007 * connman_network_set_string:
1008 * @network: network structure
1009 * @key: unique identifier
1010 * @value: string value
1012 * Set string value for specific key
1014 int connman_network_set_string(struct connman_network *network,
1015 const char *key, const char *value)
1017 DBG("network %p key %s value %s", network, key, value);
1019 if (g_strcmp0(key, "Name") == 0)
1020 return connman_network_set_name(network, value);
1022 if (g_str_equal(key, "Address") == TRUE) {
1023 g_free(network->address);
1024 network->address = g_strdup(value);
1025 } else if (g_str_equal(key, "Node") == TRUE) {
1026 g_free(network->node);
1027 network->node = g_strdup(value);
1028 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1029 g_free(network->wifi.mode);
1030 network->wifi.mode = g_strdup(value);
1031 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1032 g_free(network->wifi.security);
1033 network->wifi.security = g_strdup(value);
1034 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1035 g_free(network->wifi.passphrase);
1036 network->wifi.passphrase = g_strdup(value);
1037 } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
1038 g_free(network->wifi.eap);
1039 network->wifi.eap = g_strdup(value);
1040 } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
1041 g_free(network->wifi.identity);
1042 network->wifi.identity = g_strdup(value);
1043 } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
1044 g_free(network->wifi.ca_cert_path);
1045 network->wifi.ca_cert_path = g_strdup(value);
1046 } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
1047 g_free(network->wifi.client_cert_path);
1048 network->wifi.client_cert_path = g_strdup(value);
1049 } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
1050 g_free(network->wifi.private_key_path);
1051 network->wifi.private_key_path = g_strdup(value);
1052 } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
1053 g_free(network->wifi.private_key_passphrase);
1054 network->wifi.private_key_passphrase = g_strdup(value);
1055 } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
1056 g_free(network->wifi.phase2_auth);
1057 network->wifi.phase2_auth = g_strdup(value);
1060 return connman_element_set_string(&network->element, key, value);
1064 * connman_network_get_string:
1065 * @network: network structure
1066 * @key: unique identifier
1068 * Get string value for specific key
1070 const char *connman_network_get_string(struct connman_network *network,
1073 DBG("network %p key %s", network, key);
1075 if (g_str_equal(key, "Address") == TRUE)
1076 return network->address;
1077 else if (g_str_equal(key, "Name") == TRUE)
1078 return network->name;
1079 else if (g_str_equal(key, "Node") == TRUE)
1080 return network->node;
1081 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1082 return network->wifi.mode;
1083 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1084 return network->wifi.security;
1085 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1086 return network->wifi.passphrase;
1087 else if (g_str_equal(key, "WiFi.EAP") == TRUE)
1088 return network->wifi.eap;
1089 else if (g_str_equal(key, "WiFi.Identity") == TRUE)
1090 return network->wifi.identity;
1091 else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
1092 return network->wifi.ca_cert_path;
1093 else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
1094 return network->wifi.client_cert_path;
1095 else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
1096 return network->wifi.private_key_path;
1097 else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
1098 return network->wifi.private_key_passphrase;
1099 else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
1100 return network->wifi.phase2_auth;
1102 return connman_element_get_string(&network->element, key);
1106 * connman_network_set_bool:
1107 * @network: network structure
1108 * @key: unique identifier
1109 * @value: boolean value
1111 * Set boolean value for specific key
1113 int connman_network_set_bool(struct connman_network *network,
1114 const char *key, connman_bool_t value)
1116 DBG("network %p key %s value %d", network, key, value);
1118 if (g_strcmp0(key, "Roaming") == 0)
1119 return connman_network_set_roaming(network, value);
1121 return connman_element_set_bool(&network->element, key, value);
1125 * connman_network_get_bool:
1126 * @network: network structure
1127 * @key: unique identifier
1129 * Get boolean value for specific key
1131 connman_bool_t connman_network_get_bool(struct connman_network *network,
1134 DBG("network %p key %s", network, key);
1136 if (g_str_equal(key, "Roaming") == TRUE)
1137 return network->roaming;
1139 return connman_element_get_bool(&network->element, key);
1143 * connman_network_set_uint8:
1144 * @network: network structure
1145 * @key: unique identifier
1146 * @value: integer value
1148 * Set integer value for specific key
1150 int connman_network_set_uint8(struct connman_network *network,
1151 const char *key, connman_uint8_t value)
1153 DBG("network %p key %s value %d", network, key, value);
1155 if (g_strcmp0(key, "Strength") == 0)
1156 return connman_network_set_strength(network, value);
1158 return connman_element_set_uint8(&network->element, key, value);
1162 * connman_network_get_uint8:
1163 * @network: network structure
1164 * @key: unique identifier
1166 * Get integer value for specific key
1168 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1171 DBG("network %p key %s", network, key);
1173 if (g_str_equal(key, "Strength") == TRUE)
1174 return network->strength;
1176 return connman_element_get_uint8(&network->element, key);
1180 * connman_network_set_uint16:
1181 * @network: network structure
1182 * @key: unique identifier
1183 * @value: integer value
1185 * Set integer value for specific key
1187 int connman_network_set_uint16(struct connman_network *network,
1188 const char *key, connman_uint16_t value)
1190 DBG("network %p key %s value %d", network, key, value);
1192 if (g_str_equal(key, "Frequency") == TRUE)
1193 network->frequency = value;
1194 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1195 network->wifi.channel = value;
1201 * connman_network_get_uint16:
1202 * @network: network structure
1203 * @key: unique identifier
1205 * Get integer value for specific key
1207 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1210 DBG("network %p key %s", network, key);
1212 if (g_str_equal(key, "Frequency") == TRUE)
1213 return network->frequency;
1214 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1215 return network->wifi.channel;
1221 * connman_network_set_blob:
1222 * @network: network structure
1223 * @key: unique identifier
1227 * Set binary blob value for specific key
1229 int connman_network_set_blob(struct connman_network *network,
1230 const char *key, const void *data, unsigned int size)
1232 DBG("network %p key %s size %d", network, key, size);
1234 if (g_strcmp0(key, "Address") == 0)
1235 return connman_network_set_address(network, data, size);
1237 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1238 g_free(network->wifi.ssid);
1239 network->wifi.ssid = g_try_malloc(size);
1240 if (network->wifi.ssid != NULL) {
1241 memcpy(network->wifi.ssid, data, size);
1242 network->wifi.ssid_len = size;
1244 network->wifi.ssid_len = 0;
1247 return connman_element_set_blob(&network->element, key, data, size);
1251 * connman_network_get_blob:
1252 * @network: network structure
1253 * @key: unique identifier
1254 * @size: pointer to blob size
1256 * Get binary blob value for specific key
1258 const void *connman_network_get_blob(struct connman_network *network,
1259 const char *key, unsigned int *size)
1261 DBG("network %p key %s", network, key);
1263 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1265 *size = network->wifi.ssid_len;
1266 return network->wifi.ssid;
1269 return connman_element_get_blob(&network->element, key, size);
1272 void __connman_network_set_device(struct connman_network *network,
1273 struct connman_device *device)
1275 network->device = device;
1279 * connman_network_get_device:
1280 * @network: network structure
1282 * Get parent device of network
1284 struct connman_device *connman_network_get_device(struct connman_network *network)
1286 return network->device;
1290 * connman_network_get_data:
1291 * @network: network structure
1293 * Get private network data pointer
1295 void *connman_network_get_data(struct connman_network *network)
1297 return network->driver_data;
1301 * connman_network_set_data:
1302 * @network: network structure
1303 * @data: data pointer
1305 * Set private network data pointer
1307 void connman_network_set_data(struct connman_network *network, void *data)
1309 network->driver_data = data;
1312 static gboolean match_driver(struct connman_network *network,
1313 struct connman_network_driver *driver)
1315 if (network->type == driver->type ||
1316 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1322 static int network_probe(struct connman_element *element)
1324 struct connman_network *network = element->network;
1328 DBG("element %p name %s", element, element->name);
1330 if (network == NULL)
1333 for (list = driver_list; list; list = list->next) {
1334 struct connman_network_driver *driver = list->data;
1336 if (match_driver(network, driver) == FALSE)
1339 DBG("driver %p name %s", driver, driver->name);
1341 if (driver->probe(network) == 0) {
1342 network->driver = driver;
1347 if (network->driver == NULL)
1350 err = register_interface(element);
1352 if (network->driver->remove)
1353 network->driver->remove(network);
1357 switch (network->type) {
1358 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1359 case CONNMAN_NETWORK_TYPE_VENDOR:
1361 case CONNMAN_NETWORK_TYPE_ETHERNET:
1362 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1363 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1364 case CONNMAN_NETWORK_TYPE_CELLULAR:
1365 case CONNMAN_NETWORK_TYPE_MBM:
1366 case CONNMAN_NETWORK_TYPE_HSO:
1367 case CONNMAN_NETWORK_TYPE_WIFI:
1368 case CONNMAN_NETWORK_TYPE_WIMAX:
1369 if (network->group != NULL)
1370 __connman_profile_add_network(network);
1377 static void network_remove(struct connman_element *element)
1379 struct connman_network *network = element->network;
1381 DBG("element %p name %s", element, element->name);
1383 if (network == NULL)
1386 if (network->driver == NULL)
1389 switch (network->type) {
1390 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1391 case CONNMAN_NETWORK_TYPE_VENDOR:
1393 case CONNMAN_NETWORK_TYPE_ETHERNET:
1394 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1395 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1396 case CONNMAN_NETWORK_TYPE_CELLULAR:
1397 case CONNMAN_NETWORK_TYPE_MBM:
1398 case CONNMAN_NETWORK_TYPE_HSO:
1399 case CONNMAN_NETWORK_TYPE_WIFI:
1400 case CONNMAN_NETWORK_TYPE_WIMAX:
1401 if (network->group != NULL) {
1402 __connman_profile_remove_network(network);
1404 g_free(network->group);
1405 network->group = NULL;
1410 unregister_interface(element);
1412 if (network->driver->remove)
1413 network->driver->remove(network);
1416 static void network_change(struct connman_element *element)
1418 struct connman_network *network = element->network;
1420 DBG("element %p name %s", element, element->name);
1422 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1425 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1428 if (network->connected == FALSE)
1431 connman_element_unregister_children(element);
1433 connman_device_set_disconnected(network->device, TRUE);
1435 if (network->driver && network->driver->disconnect) {
1436 network->driver->disconnect(network);
1440 network->connected = FALSE;
1443 static struct connman_driver network_driver = {
1445 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1446 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1447 .probe = network_probe,
1448 .remove = network_remove,
1449 .change = network_change,
1452 int __connman_network_init(void)
1456 connection = connman_dbus_get_connection();
1458 return connman_driver_register(&network_driver);
1461 void __connman_network_cleanup(void)
1465 connman_driver_unregister(&network_driver);
1467 dbus_connection_unref(connection);