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 struct connman_network {
34 struct connman_element element;
35 enum connman_network_type type;
36 enum connman_network_protocol protocol;
37 connman_bool_t secondary;
38 connman_bool_t available;
39 connman_bool_t connected;
40 connman_uint8_t strength;
41 connman_uint16_t frequency;
47 struct connman_ipconfig *ipconfig;
49 struct connman_network_driver *driver;
52 connman_bool_t registered;
53 connman_bool_t connecting;
54 connman_bool_t associating;
56 struct connman_device *device;
62 unsigned short channel;
68 static const char *type2string(enum connman_network_type type)
71 case CONNMAN_NETWORK_TYPE_UNKNOWN:
72 case CONNMAN_NETWORK_TYPE_VENDOR:
74 case CONNMAN_NETWORK_TYPE_WIFI:
76 case CONNMAN_NETWORK_TYPE_WIMAX:
78 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
79 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
81 case CONNMAN_NETWORK_TYPE_MBM:
82 case CONNMAN_NETWORK_TYPE_HSO:
89 static DBusMessage *get_properties(DBusConnection *conn,
90 DBusMessage *msg, void *data)
92 struct connman_network *network = data;
94 DBusMessageIter array, dict;
98 if (__connman_security_check_privilege(msg,
99 CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
100 return __connman_error_permission_denied(msg);
102 reply = dbus_message_new_method_return(msg);
106 dbus_message_iter_init_append(reply, &array);
108 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
109 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
110 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
111 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
113 if (network->device) {
114 const char *path = connman_device_get_path(network->device);
116 connman_dbus_dict_append_variant(&dict, "Device",
117 DBUS_TYPE_OBJECT_PATH, &path);
120 if (network->address != NULL)
121 connman_dbus_dict_append_variant(&dict, "Address",
122 DBUS_TYPE_STRING, &network->address);
124 if (network->name != NULL)
125 connman_dbus_dict_append_variant(&dict, "Name",
126 DBUS_TYPE_STRING, &network->name);
128 connman_dbus_dict_append_variant(&dict, "Connected",
129 DBUS_TYPE_BOOLEAN, &network->connected);
131 if (network->strength > 0)
132 connman_dbus_dict_append_variant(&dict, "Strength",
133 DBUS_TYPE_BYTE, &network->strength);
135 if (network->frequency > 0)
136 connman_dbus_dict_append_variant(&dict, "Frequency",
137 DBUS_TYPE_UINT16, &network->frequency);
139 if (network->wifi.ssid != NULL && network->wifi.ssid_len > 0)
140 connman_dbus_dict_append_array(&dict, "WiFi.SSID",
141 DBUS_TYPE_BYTE, &network->wifi.ssid,
142 network->wifi.ssid_len);
144 if (network->wifi.mode != NULL)
145 connman_dbus_dict_append_variant(&dict, "WiFi.Mode",
146 DBUS_TYPE_STRING, &network->wifi.mode);
148 if (network->wifi.channel > 0)
149 connman_dbus_dict_append_variant(&dict, "WiFi.Channel",
150 DBUS_TYPE_UINT16, &network->wifi.channel);
152 if (network->wifi.security != NULL)
153 connman_dbus_dict_append_variant(&dict, "WiFi.Security",
154 DBUS_TYPE_STRING, &network->wifi.security);
156 if (network->wifi.passphrase != NULL &&
157 __connman_security_check_privilege(msg,
158 CONNMAN_SECURITY_PRIVILEGE_SECRET) == 0)
159 connman_dbus_dict_append_variant(&dict, "WiFi.Passphrase",
160 DBUS_TYPE_STRING, &network->wifi.passphrase);
162 dbus_message_iter_close_container(&array, &dict);
167 static DBusMessage *set_property(DBusConnection *conn,
168 DBusMessage *msg, void *data)
170 struct connman_network *network = data;
171 DBusMessageIter iter, value;
175 DBG("conn %p", conn);
177 if (dbus_message_iter_init(msg, &iter) == FALSE)
178 return __connman_error_invalid_arguments(msg);
180 dbus_message_iter_get_basic(&iter, &name);
181 dbus_message_iter_next(&iter);
182 dbus_message_iter_recurse(&iter, &value);
184 if (__connman_security_check_privilege(msg,
185 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
186 return __connman_error_permission_denied(msg);
188 type = dbus_message_iter_get_arg_type(&value);
190 if (g_str_equal(name, "WiFi.Passphrase") == TRUE) {
191 const char *passphrase;
193 if (type != DBUS_TYPE_STRING)
194 return __connman_error_invalid_arguments(msg);
196 if (__connman_security_check_privilege(msg,
197 CONNMAN_SECURITY_PRIVILEGE_SECRET) < 0)
198 return __connman_error_permission_denied(msg);
200 dbus_message_iter_get_basic(&value, &passphrase);
202 g_free(network->wifi.passphrase);
203 network->wifi.passphrase = g_strdup(passphrase);
204 } else if (g_str_has_prefix(name, "IPv4.") == TRUE) {
207 err = __connman_ipconfig_set_ipv4(network->ipconfig,
210 return __connman_error_failed(msg, -err);
212 return __connman_error_invalid_property(msg);
214 __connman_storage_save_network(network);
216 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
219 static DBusMessage *do_connect(DBusConnection *conn,
220 DBusMessage *msg, void *data)
222 struct connman_network *network = data;
225 DBG("conn %p", conn);
227 if (__connman_security_check_privilege(msg,
228 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
229 return __connman_error_permission_denied(msg);
231 if (network->connected == TRUE)
232 return __connman_error_failed(msg, EALREADY);
234 if (network->driver && network->driver->connect) {
235 enum connman_device_mode mode;
237 mode = connman_device_get_mode(network->device);
238 if (mode == CONNMAN_DEVICE_MODE_NETWORK_SINGLE)
239 __connman_device_disconnect(network->device);
241 err = network->driver->connect(network);
242 if (err < 0 && err != -EINPROGRESS)
243 return __connman_error_failed(msg, -err);
245 network->connected = TRUE;
247 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
250 static DBusMessage *do_disconnect(DBusConnection *conn,
251 DBusMessage *msg, void *data)
253 struct connman_network *network = data;
256 DBG("conn %p", conn);
258 if (__connman_security_check_privilege(msg,
259 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
260 return __connman_error_permission_denied(msg);
262 if (network->connected == FALSE)
263 return __connman_error_failed(msg, EINVAL);
265 connman_element_unregister_children(&network->element);
267 connman_device_set_disconnected(network->device, TRUE);
269 if (network->driver && network->driver->disconnect) {
270 err = network->driver->disconnect(network);
271 if (err < 0 && err != -EINPROGRESS)
272 return __connman_error_failed(msg, -err);
274 network->connected = FALSE;
276 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
279 static GDBusMethodTable network_methods[] = {
280 { "GetProperties", "", "a{sv}", get_properties },
281 { "SetProperty", "sv", "", set_property },
282 { "Connect", "", "", do_connect },
283 { "Disconnect", "", "", do_disconnect },
287 static GDBusSignalTable network_signals[] = {
288 { "PropertyChanged", "sv" },
292 static DBusConnection *connection;
294 static void append_networks(struct connman_device *device,
295 DBusMessageIter *entry)
297 DBusMessageIter value, iter;
298 const char *key = "Networks";
300 dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
302 dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
303 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
306 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
307 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
308 __connman_element_list((struct connman_element *) device,
309 CONNMAN_ELEMENT_TYPE_NETWORK, &iter);
310 dbus_message_iter_close_container(&value, &iter);
312 dbus_message_iter_close_container(entry, &value);
315 static void emit_networks_signal(struct connman_device *device)
317 const char *path = connman_device_get_path(device);
319 DBusMessageIter entry;
321 signal = dbus_message_new_signal(path,
322 CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
326 dbus_message_iter_init_append(signal, &entry);
328 append_networks(device, &entry);
330 g_dbus_send_message(connection, signal);
333 static int register_interface(struct connman_element *element)
335 struct connman_network *network = element->network;
337 DBG("element %p name %s", element, element->name);
339 if (g_dbus_register_interface(connection, element->path,
340 CONNMAN_NETWORK_INTERFACE,
341 network_methods, network_signals,
342 NULL, network, NULL) == FALSE) {
343 connman_error("Failed to register %s network", element->path);
347 network->registered = TRUE;
349 emit_networks_signal(network->device);
354 static void unregister_interface(struct connman_element *element)
356 struct connman_network * network = element->network;
358 DBG("element %p name %s", element, element->name);
360 network->registered = FALSE;
362 emit_networks_signal(network->device);
364 g_dbus_unregister_interface(connection, element->path,
365 CONNMAN_NETWORK_INTERFACE);
368 connman_bool_t __connman_network_has_driver(struct connman_network *network)
370 if (network == NULL || network->driver == NULL)
373 return network->registered;
376 static GSList *driver_list = NULL;
378 static gint compare_priority(gconstpointer a, gconstpointer b)
380 const struct connman_network_driver *driver1 = a;
381 const struct connman_network_driver *driver2 = b;
383 return driver2->priority - driver1->priority;
387 * connman_network_driver_register:
388 * @driver: network driver definition
390 * Register a new network driver
392 * Returns: %0 on success
394 int connman_network_driver_register(struct connman_network_driver *driver)
396 DBG("driver %p name %s", driver, driver->name);
398 driver_list = g_slist_insert_sorted(driver_list, driver,
405 * connman_network_driver_unregister:
406 * @driver: network driver definition
408 * Remove a previously registered network driver
410 void connman_network_driver_unregister(struct connman_network_driver *driver)
412 DBG("driver %p name %s", driver, driver->name);
414 driver_list = g_slist_remove(driver_list, driver);
417 static void network_destruct(struct connman_element *element)
419 struct connman_network *network = element->network;
421 DBG("element %p name %s", element, element->name);
423 g_free(network->wifi.ssid);
424 g_free(network->wifi.mode);
425 g_free(network->wifi.security);
426 g_free(network->wifi.passphrase);
428 g_free(network->group);
429 g_free(network->node);
430 g_free(network->name);
431 g_free(network->address);
432 g_free(network->identifier);
434 connman_ipconfig_unref(network->ipconfig);
438 * connman_network_create:
439 * @identifier: network identifier (for example an unqiue name)
441 * Allocate a new network and assign the #identifier to it.
443 * Returns: a newly-allocated #connman_network structure
445 struct connman_network *connman_network_create(const char *identifier,
446 enum connman_network_type type)
448 struct connman_network *network;
449 connman_uint8_t strength = 0;
453 DBG("identifier %s type %d", identifier, type);
455 network = g_try_new0(struct connman_network, 1);
459 DBG("network %p", network);
461 __connman_element_initialize(&network->element);
463 //temp = connman_dbus_encode_string(identifier);
464 temp = g_strdup(identifier);
470 network->element.name = temp;
471 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
473 network->element.network = network;
474 network->element.destruct = network_destruct;
476 str = type2string(type);
478 connman_element_set_string(&network->element, "Type", str);
480 connman_element_set_uint8(&network->element, "Strength", strength);
482 network->type = type;
483 network->secondary = FALSE;
484 network->identifier = g_strdup(identifier);
486 network->ipconfig = connman_ipconfig_create();
487 if (network->ipconfig == NULL) {
488 connman_network_unref(network);
496 * connman_network_ref:
497 * @network: network structure
499 * Increase reference counter of network
501 struct connman_network *connman_network_ref(struct connman_network *network)
503 if (connman_element_ref(&network->element) == NULL)
510 * connman_network_unref:
511 * @network: network structure
513 * Decrease reference counter of network
515 void connman_network_unref(struct connman_network *network)
517 connman_element_unref(&network->element);
520 const char *__connman_network_get_type(struct connman_network *network)
522 return type2string(network->type);
526 * connman_network_get_type:
527 * @network: network structure
529 * Get type of network
531 enum connman_network_type connman_network_get_type(struct connman_network *network)
533 return network->type;
537 * connman_network_get_identifier:
538 * @network: network structure
540 * Get identifier of network
542 const char *connman_network_get_identifier(struct connman_network *network)
544 return network->identifier;
548 * connman_network_get_path:
549 * @network: network structure
551 * Get path name of network
553 const char *connman_network_get_path(struct connman_network *network)
555 return network->element.path;
559 * connman_network_set_index:
560 * @network: network structure
561 * @index: index number
563 * Set index number of network
565 void connman_network_set_index(struct connman_network *network, int index)
567 network->element.index = index;
571 * connman_network_get_index:
572 * @network: network structure
574 * Get index number of network
576 int connman_network_get_index(struct connman_network *network)
578 return network->element.index;
582 * connman_network_set_protocol:
583 * @network: network structure
584 * @protocol: network protocol
586 * Change protocol of network
588 void connman_network_set_protocol(struct connman_network *network,
589 enum connman_network_protocol protocol)
591 network->protocol = protocol;
595 * connman_network_set_group:
596 * @network: network structure
599 * Set group name for automatic clustering
601 void connman_network_set_group(struct connman_network *network,
604 if (network->secondary == TRUE)
607 if (g_strcmp0(network->group, group) == 0)
610 switch (network->type) {
611 case CONNMAN_NETWORK_TYPE_UNKNOWN:
612 case CONNMAN_NETWORK_TYPE_VENDOR:
613 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
614 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
616 case CONNMAN_NETWORK_TYPE_MBM:
617 case CONNMAN_NETWORK_TYPE_HSO:
618 case CONNMAN_NETWORK_TYPE_WIFI:
619 case CONNMAN_NETWORK_TYPE_WIMAX:
623 if (network->group != NULL) {
624 __connman_profile_remove_network(network);
626 g_free(network->group);
629 network->group = g_strdup(group);
631 if (network->group != NULL)
632 __connman_profile_add_network(network);
636 * connman_network_get_group:
637 * @network: network structure
639 * Get group name for automatic clustering
641 const char *connman_network_get_group(struct connman_network *network)
643 return network->group;
646 const char *__connman_network_get_ident(struct connman_network *network)
648 if (network->device == NULL)
651 return __connman_device_get_ident(network->device);
655 * connman_network_set_available:
656 * @network: network structure
657 * @available: availability state
659 * Change availability state of network (in range)
661 int connman_network_set_available(struct connman_network *network,
662 connman_bool_t available)
664 DBG("network %p available %d", network, available);
666 if (network->available == available)
669 network->available = available;
675 * connman_network_get_available:
676 * @network: network structure
678 * Get network available setting
680 connman_bool_t connman_network_get_available(struct connman_network *network)
682 return network->available;
686 * connman_network_set_associating:
687 * @network: network structure
688 * @associating: associating state
690 * Change associating state of network
692 int connman_network_set_associating(struct connman_network *network,
693 connman_bool_t associating)
695 DBG("network %p associating %d", network, associating);
697 if (network->associating == associating)
700 network->associating = associating;
702 if (associating == TRUE) {
703 struct connman_service *service;
705 service = __connman_service_lookup_from_network(network);
706 __connman_service_indicate_state(service,
707 CONNMAN_SERVICE_STATE_ASSOCIATION);
713 static gboolean set_connected(gpointer user_data)
715 struct connman_network *network = user_data;
716 struct connman_service *service;
718 service = __connman_service_lookup_from_network(network);
720 if (network->connected == TRUE) {
721 struct connman_element *element;
722 enum connman_element_type type = CONNMAN_ELEMENT_TYPE_UNKNOWN;
724 switch (network->protocol) {
725 case CONNMAN_NETWORK_PROTOCOL_UNKNOWN:
727 case CONNMAN_NETWORK_PROTOCOL_IP:
728 type = CONNMAN_ELEMENT_TYPE_DHCP;
730 case CONNMAN_NETWORK_PROTOCOL_PPP:
731 type = CONNMAN_ELEMENT_TYPE_PPP;
735 __connman_device_increase_connections(network->device);
737 __connman_device_set_network(network->device, network);
739 connman_device_set_disconnected(network->device, FALSE);
741 element = connman_element_create(NULL);
742 if (element != NULL) {
743 element->type = type;
744 element->index = network->element.index;
746 if (connman_element_register(element,
747 &network->element) < 0)
748 connman_element_unref(element);
750 __connman_service_indicate_state(service,
751 CONNMAN_SERVICE_STATE_CONFIGURATION);
754 connman_element_unregister_children(&network->element);
756 __connman_device_set_network(network->device, NULL);
758 __connman_device_decrease_connections(network->device);
760 __connman_service_indicate_state(service,
761 CONNMAN_SERVICE_STATE_IDLE);
764 network->connecting = FALSE;
770 * connman_network_set_connected:
771 * @network: network structure
772 * @connected: connected state
774 * Change connected state of network
776 int connman_network_set_connected(struct connman_network *network,
777 connman_bool_t connected)
780 DBusMessageIter entry, value;
781 const char *key = "Connected";
783 DBG("network %p connected %d", network, connected);
785 if ((network->connecting || network->associating == TRUE) &&
786 connected == FALSE) {
787 connman_element_set_error(&network->element,
788 CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
789 __connman_network_disconnect(network);
792 if (network->connected == connected)
795 network->connected = connected;
797 if (connected == TRUE)
798 network->associating = FALSE;
800 if (network->registered == FALSE) {
801 g_idle_add(set_connected, network);
805 signal = dbus_message_new_signal(network->element.path,
806 CONNMAN_NETWORK_INTERFACE, "PropertyChanged");
810 dbus_message_iter_init_append(signal, &entry);
812 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
814 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
815 DBUS_TYPE_BOOLEAN_AS_STRING, &value);
816 dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, &connected);
817 dbus_message_iter_close_container(&entry, &value);
819 g_dbus_send_message(connection, signal);
821 set_connected(network);
827 * connman_network_get_connected:
828 * @network: network structure
830 * Get network connection status
832 connman_bool_t connman_network_get_connected(struct connman_network *network)
834 return network->connected;
838 * connman_network_get_associating:
839 * @network: network structure
841 * Get network associating status
843 connman_bool_t connman_network_get_associating(struct connman_network *network)
845 return network->associating;
849 * __connman_network_connect:
850 * @network: network structure
854 int __connman_network_connect(struct connman_network *network)
858 DBG("network %p", network);
860 if (network->connected == TRUE || network->connecting == TRUE ||
861 network->associating == TRUE)
864 if (network->driver == NULL)
867 if (network->driver->connect == NULL)
870 __connman_device_disconnect(network->device);
872 network->connecting = TRUE;
874 err = network->driver->connect(network);
876 network->connected = TRUE;
877 set_connected(network);
884 * __connman_network_disconnect:
885 * @network: network structure
889 int __connman_network_disconnect(struct connman_network *network)
893 DBG("network %p", network);
895 if (network->connected == FALSE && network->connecting == FALSE &&
896 network->associating == FALSE)
899 if (network->driver == NULL)
902 if (network->driver->disconnect == NULL)
905 network->connecting = FALSE;
907 err = network->driver->disconnect(network);
909 network->connected = FALSE;
910 set_connected(network);
917 * connman_network_set_address:
918 * @network: network structure
919 * @address: binary address value
920 * @size: binary address length
922 * Set unique address value for network
924 int connman_network_set_address(struct connman_network *network,
925 const void *address, unsigned int size)
927 const unsigned char *addr_octet = address;
930 DBG("network %p size %d", network, size);
935 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
936 addr_octet[0], addr_octet[1], addr_octet[2],
937 addr_octet[3], addr_octet[4], addr_octet[5]);
941 g_free(network->address);
942 network->address = str;
944 return connman_element_set_string(&network->element,
945 "Address", network->address);
949 * connman_network_set_name:
950 * @network: network structure
953 * Set display name value for network
955 int connman_network_set_name(struct connman_network *network,
958 DBG("network %p name %s", network, name);
960 g_free(network->name);
961 network->name = g_strdup(name);
963 return connman_element_set_string(&network->element, "Name", name);
967 * connman_network_set_strength:
968 * @network: network structure
969 * @strength: strength value
971 * Set signal strength value for network
973 int connman_network_set_strength(struct connman_network *network,
974 connman_uint8_t strength)
976 DBG("network %p strengh %d", network, strength);
978 network->strength = strength;
980 return connman_element_set_uint8(&network->element,
981 "Strength", strength);
985 * connman_network_set_string:
986 * @network: network structure
987 * @key: unique identifier
988 * @value: string value
990 * Set string value for specific key
992 int connman_network_set_string(struct connman_network *network,
993 const char *key, const char *value)
995 DBG("network %p key %s value %s", network, key, value);
997 if (g_strcmp0(key, "Name") == 0)
998 return connman_network_set_name(network, value);
1000 if (g_str_equal(key, "Address") == TRUE) {
1001 g_free(network->address);
1002 network->address = g_strdup(value);
1003 } else if (g_str_equal(key, "Node") == TRUE) {
1004 g_free(network->node);
1005 network->node = g_strdup(value);
1006 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
1007 g_free(network->wifi.mode);
1008 network->wifi.mode = g_strdup(value);
1009 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
1010 g_free(network->wifi.security);
1011 network->wifi.security = g_strdup(value);
1012 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
1013 g_free(network->wifi.passphrase);
1014 network->wifi.passphrase = g_strdup(value);
1017 return connman_element_set_string(&network->element, key, value);
1021 * connman_network_get_string:
1022 * @network: network structure
1023 * @key: unique identifier
1025 * Get string value for specific key
1027 const char *connman_network_get_string(struct connman_network *network,
1030 DBG("network %p key %s", network, key);
1032 if (g_str_equal(key, "Address") == TRUE)
1033 return network->address;
1034 else if (g_str_equal(key, "Name") == TRUE)
1035 return network->name;
1036 else if (g_str_equal(key, "Node") == TRUE)
1037 return network->node;
1038 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
1039 return network->wifi.mode;
1040 else if (g_str_equal(key, "WiFi.Security") == TRUE)
1041 return network->wifi.security;
1042 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
1043 return network->wifi.passphrase;
1045 return connman_element_get_string(&network->element, key);
1049 * connman_network_set_uint8:
1050 * @network: network structure
1051 * @key: unique identifier
1052 * @value: integer value
1054 * Set integer value for specific key
1056 int connman_network_set_uint8(struct connman_network *network,
1057 const char *key, connman_uint8_t value)
1059 DBG("network %p key %s value %d", network, key, value);
1061 if (g_strcmp0(key, "Strength") == 0)
1062 return connman_network_set_strength(network, value);
1064 return connman_element_set_uint8(&network->element, key, value);
1068 * connman_network_get_uint8:
1069 * @network: network structure
1070 * @key: unique identifier
1072 * Get integer value for specific key
1074 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1077 DBG("network %p key %s", network, key);
1079 if (g_str_equal(key, "Strength") == TRUE)
1080 return network->strength;
1082 return connman_element_get_uint8(&network->element, key);
1086 * connman_network_set_uint16:
1087 * @network: network structure
1088 * @key: unique identifier
1089 * @value: integer value
1091 * Set integer value for specific key
1093 int connman_network_set_uint16(struct connman_network *network,
1094 const char *key, connman_uint16_t value)
1096 DBG("network %p key %s value %d", network, key, value);
1098 if (g_str_equal(key, "Frequency") == TRUE)
1099 network->frequency = value;
1100 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1101 network->wifi.channel = value;
1107 * connman_network_get_uint16:
1108 * @network: network structure
1109 * @key: unique identifier
1111 * Get integer value for specific key
1113 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1116 DBG("network %p key %s", network, key);
1118 if (g_str_equal(key, "Frequency") == TRUE)
1119 return network->frequency;
1120 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1121 return network->wifi.channel;
1127 * connman_network_set_blob:
1128 * @network: network structure
1129 * @key: unique identifier
1133 * Set binary blob value for specific key
1135 int connman_network_set_blob(struct connman_network *network,
1136 const char *key, const void *data, unsigned int size)
1138 DBG("network %p key %s size %d", network, key, size);
1140 if (g_strcmp0(key, "Address") == 0)
1141 return connman_network_set_address(network, data, size);
1143 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1144 g_free(network->wifi.ssid);
1145 network->wifi.ssid = g_try_malloc(size);
1146 if (network->wifi.ssid != NULL) {
1147 memcpy(network->wifi.ssid, data, size);
1148 network->wifi.ssid_len = size;
1150 network->wifi.ssid_len = 0;
1153 return connman_element_set_blob(&network->element, key, data, size);
1157 * connman_network_get_blob:
1158 * @network: network structure
1159 * @key: unique identifier
1160 * @size: pointer to blob size
1162 * Get binary blob value for specific key
1164 const void *connman_network_get_blob(struct connman_network *network,
1165 const char *key, unsigned int *size)
1167 DBG("network %p key %s", network, key);
1169 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1171 *size = network->wifi.ssid_len;
1172 return network->wifi.ssid;
1175 return connman_element_get_blob(&network->element, key, size);
1178 void __connman_network_set_device(struct connman_network *network,
1179 struct connman_device *device)
1181 network->device = device;
1185 * connman_network_get_device:
1186 * @network: network structure
1188 * Get parent device of network
1190 struct connman_device *connman_network_get_device(struct connman_network *network)
1192 return network->device;
1196 * connman_network_get_data:
1197 * @network: network structure
1199 * Get private network data pointer
1201 void *connman_network_get_data(struct connman_network *network)
1203 return network->driver_data;
1207 * connman_network_set_data:
1208 * @network: network structure
1209 * @data: data pointer
1211 * Set private network data pointer
1213 void connman_network_set_data(struct connman_network *network, void *data)
1215 network->driver_data = data;
1218 static gboolean match_driver(struct connman_network *network,
1219 struct connman_network_driver *driver)
1221 if (network->type == driver->type ||
1222 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1228 static int network_probe(struct connman_element *element)
1230 struct connman_network *network = element->network;
1234 DBG("element %p name %s", element, element->name);
1236 if (network == NULL)
1239 for (list = driver_list; list; list = list->next) {
1240 struct connman_network_driver *driver = list->data;
1242 if (match_driver(network, driver) == FALSE)
1245 DBG("driver %p name %s", driver, driver->name);
1247 if (driver->probe(network) == 0) {
1248 network->driver = driver;
1253 if (network->driver == NULL)
1256 err = register_interface(element);
1258 if (network->driver->remove)
1259 network->driver->remove(network);
1263 network->secondary = connman_device_get_secondary(network->device);
1265 switch (network->type) {
1266 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1267 case CONNMAN_NETWORK_TYPE_VENDOR:
1268 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1269 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1271 case CONNMAN_NETWORK_TYPE_MBM:
1272 case CONNMAN_NETWORK_TYPE_HSO:
1273 case CONNMAN_NETWORK_TYPE_WIFI:
1274 case CONNMAN_NETWORK_TYPE_WIMAX:
1275 if (network->group != NULL && network->secondary == FALSE)
1276 __connman_profile_add_network(network);
1283 static void network_remove(struct connman_element *element)
1285 struct connman_network *network = element->network;
1287 DBG("element %p name %s", element, element->name);
1289 if (network == NULL)
1292 if (network->driver == NULL)
1295 switch (network->type) {
1296 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1297 case CONNMAN_NETWORK_TYPE_VENDOR:
1298 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1299 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1301 case CONNMAN_NETWORK_TYPE_MBM:
1302 case CONNMAN_NETWORK_TYPE_HSO:
1303 case CONNMAN_NETWORK_TYPE_WIFI:
1304 case CONNMAN_NETWORK_TYPE_WIMAX:
1305 if (network->group != NULL && network->secondary == FALSE) {
1306 __connman_profile_remove_network(network);
1308 g_free(network->group);
1309 network->group = NULL;
1314 unregister_interface(element);
1316 if (network->driver->remove)
1317 network->driver->remove(network);
1320 static void network_change(struct connman_element *element)
1322 struct connman_network *network = element->network;
1324 DBG("element %p name %s", element, element->name);
1326 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1329 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1332 if (network->connected == FALSE)
1335 connman_element_unregister_children(element);
1337 connman_device_set_disconnected(network->device, TRUE);
1339 if (network->driver && network->driver->disconnect) {
1340 network->driver->disconnect(network);
1344 network->connected = FALSE;
1347 static struct connman_driver network_driver = {
1349 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1350 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1351 .probe = network_probe,
1352 .remove = network_remove,
1353 .change = network_change,
1356 int __connman_network_init(void)
1360 connection = connman_dbus_get_connection();
1362 return connman_driver_register(&network_driver);
1365 void __connman_network_cleanup(void)
1369 connman_driver_unregister(&network_driver);
1371 dbus_connection_unref(connection);