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 associating;
38 connman_bool_t secondary;
39 connman_bool_t available;
40 connman_bool_t connected;
41 connman_uint8_t strength;
42 connman_uint16_t frequency;
49 struct connman_network_driver *driver;
52 connman_bool_t registered;
54 struct connman_device *device;
60 unsigned short channel;
66 static const char *type2string(enum connman_network_type type)
69 case CONNMAN_NETWORK_TYPE_UNKNOWN:
70 case CONNMAN_NETWORK_TYPE_VENDOR:
72 case CONNMAN_NETWORK_TYPE_WIFI:
74 case CONNMAN_NETWORK_TYPE_WIMAX:
76 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
77 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
79 case CONNMAN_NETWORK_TYPE_HSO:
86 static DBusMessage *get_properties(DBusConnection *conn,
87 DBusMessage *msg, void *data)
89 struct connman_network *network = data;
91 DBusMessageIter array, dict;
95 if (__connman_security_check_privilege(msg,
96 CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
97 return __connman_error_permission_denied(msg);
99 reply = dbus_message_new_method_return(msg);
103 dbus_message_iter_init_append(reply, &array);
105 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
106 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
107 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
108 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
110 if (network->device) {
111 const char *path = connman_device_get_path(network->device);
113 connman_dbus_dict_append_variant(&dict, "Device",
114 DBUS_TYPE_OBJECT_PATH, &path);
117 if (network->address != NULL)
118 connman_dbus_dict_append_variant(&dict, "Address",
119 DBUS_TYPE_STRING, &network->address);
121 if (network->name != NULL)
122 connman_dbus_dict_append_variant(&dict, "Name",
123 DBUS_TYPE_STRING, &network->name);
125 connman_dbus_dict_append_variant(&dict, "Connected",
126 DBUS_TYPE_BOOLEAN, &network->connected);
128 if (network->strength > 0)
129 connman_dbus_dict_append_variant(&dict, "Strength",
130 DBUS_TYPE_BYTE, &network->strength);
132 if (network->frequency > 0)
133 connman_dbus_dict_append_variant(&dict, "Frequency",
134 DBUS_TYPE_UINT16, &network->frequency);
136 if (network->wifi.ssid != NULL && network->wifi.ssid_len > 0)
137 connman_dbus_dict_append_array(&dict, "WiFi.SSID",
138 DBUS_TYPE_BYTE, &network->wifi.ssid,
139 network->wifi.ssid_len);
141 if (network->wifi.mode != NULL)
142 connman_dbus_dict_append_variant(&dict, "WiFi.Mode",
143 DBUS_TYPE_STRING, &network->wifi.mode);
145 if (network->wifi.channel > 0)
146 connman_dbus_dict_append_variant(&dict, "WiFi.Channel",
147 DBUS_TYPE_UINT16, &network->wifi.channel);
149 if (network->wifi.security != NULL)
150 connman_dbus_dict_append_variant(&dict, "WiFi.Security",
151 DBUS_TYPE_STRING, &network->wifi.security);
153 if (network->wifi.passphrase != NULL &&
154 __connman_security_check_privilege(msg,
155 CONNMAN_SECURITY_PRIVILEGE_SECRET) == 0)
156 connman_dbus_dict_append_variant(&dict, "WiFi.Passphrase",
157 DBUS_TYPE_STRING, &network->wifi.passphrase);
159 dbus_message_iter_close_container(&array, &dict);
164 static DBusMessage *set_property(DBusConnection *conn,
165 DBusMessage *msg, void *data)
167 struct connman_network *network = data;
168 DBusMessageIter iter, value;
172 DBG("conn %p", conn);
174 if (dbus_message_iter_init(msg, &iter) == FALSE)
175 return __connman_error_invalid_arguments(msg);
177 dbus_message_iter_get_basic(&iter, &name);
178 dbus_message_iter_next(&iter);
179 dbus_message_iter_recurse(&iter, &value);
181 if (__connman_security_check_privilege(msg,
182 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
183 return __connman_error_permission_denied(msg);
185 type = dbus_message_iter_get_arg_type(&value);
187 if (g_str_equal(name, "WiFi.Passphrase") == TRUE) {
188 const char *passphrase;
190 if (type != DBUS_TYPE_STRING)
191 return __connman_error_invalid_arguments(msg);
193 if (__connman_security_check_privilege(msg,
194 CONNMAN_SECURITY_PRIVILEGE_SECRET) < 0)
195 return __connman_error_permission_denied(msg);
197 dbus_message_iter_get_basic(&value, &passphrase);
199 g_free(network->wifi.passphrase);
200 network->wifi.passphrase = g_strdup(passphrase);
203 __connman_storage_save_network(network);
205 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
208 static DBusMessage *do_connect(DBusConnection *conn,
209 DBusMessage *msg, void *data)
211 struct connman_network *network = data;
214 DBG("conn %p", conn);
216 if (__connman_security_check_privilege(msg,
217 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
218 return __connman_error_permission_denied(msg);
220 if (network->connected == TRUE)
221 return __connman_error_failed(msg, EALREADY);
223 if (network->driver && network->driver->connect) {
224 enum connman_device_mode mode;
226 mode = connman_device_get_mode(network->device);
227 if (mode == CONNMAN_DEVICE_MODE_NETWORK_SINGLE)
228 __connman_device_disconnect(network->device);
230 err = network->driver->connect(network);
231 if (err < 0 && err != -EINPROGRESS)
232 return __connman_error_failed(msg, -err);
234 network->connected = TRUE;
236 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
239 static DBusMessage *do_disconnect(DBusConnection *conn,
240 DBusMessage *msg, void *data)
242 struct connman_network *network = data;
245 DBG("conn %p", conn);
247 if (__connman_security_check_privilege(msg,
248 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
249 return __connman_error_permission_denied(msg);
251 if (network->connected == FALSE)
252 return __connman_error_failed(msg, EINVAL);
254 connman_element_unregister_children(&network->element);
256 connman_device_set_disconnected(network->device, TRUE);
258 if (network->driver && network->driver->disconnect) {
259 err = network->driver->disconnect(network);
260 if (err < 0 && err != -EINPROGRESS)
261 return __connman_error_failed(msg, -err);
263 network->connected = FALSE;
265 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
268 static GDBusMethodTable network_methods[] = {
269 { "GetProperties", "", "a{sv}", get_properties },
270 { "SetProperty", "sv", "", set_property },
271 { "Connect", "", "", do_connect },
272 { "Disconnect", "", "", do_disconnect },
276 static GDBusSignalTable network_signals[] = {
277 { "PropertyChanged", "sv" },
281 static DBusConnection *connection;
283 static void append_networks(struct connman_device *device,
284 DBusMessageIter *entry)
286 DBusMessageIter value, iter;
287 const char *key = "Networks";
289 dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
291 dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
292 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
295 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
296 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
297 __connman_element_list((struct connman_element *) device,
298 CONNMAN_ELEMENT_TYPE_NETWORK, &iter);
299 dbus_message_iter_close_container(&value, &iter);
301 dbus_message_iter_close_container(entry, &value);
304 static void emit_networks_signal(struct connman_device *device)
306 const char *path = connman_device_get_path(device);
308 DBusMessageIter entry;
310 signal = dbus_message_new_signal(path,
311 CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
315 dbus_message_iter_init_append(signal, &entry);
317 append_networks(device, &entry);
319 g_dbus_send_message(connection, signal);
322 static int register_interface(struct connman_element *element)
324 struct connman_network *network = element->network;
326 DBG("element %p name %s", element, element->name);
328 if (g_dbus_register_interface(connection, element->path,
329 CONNMAN_NETWORK_INTERFACE,
330 network_methods, network_signals,
331 NULL, network, NULL) == FALSE) {
332 connman_error("Failed to register %s network", element->path);
336 network->registered = TRUE;
338 emit_networks_signal(network->device);
343 static void unregister_interface(struct connman_element *element)
345 struct connman_network * network = element->network;
347 DBG("element %p name %s", element, element->name);
349 network->registered = FALSE;
351 emit_networks_signal(network->device);
353 g_dbus_unregister_interface(connection, element->path,
354 CONNMAN_NETWORK_INTERFACE);
357 connman_bool_t __connman_network_has_driver(struct connman_network *network)
359 if (network == NULL || network->driver == NULL)
362 return network->registered;
365 static GSList *driver_list = NULL;
367 static gint compare_priority(gconstpointer a, gconstpointer b)
369 const struct connman_network_driver *driver1 = a;
370 const struct connman_network_driver *driver2 = b;
372 return driver2->priority - driver1->priority;
376 * connman_network_driver_register:
377 * @driver: network driver definition
379 * Register a new network driver
381 * Returns: %0 on success
383 int connman_network_driver_register(struct connman_network_driver *driver)
385 DBG("driver %p name %s", driver, driver->name);
387 driver_list = g_slist_insert_sorted(driver_list, driver,
394 * connman_network_driver_unregister:
395 * @driver: network driver definition
397 * Remove a previously registered network driver
399 void connman_network_driver_unregister(struct connman_network_driver *driver)
401 DBG("driver %p name %s", driver, driver->name);
403 driver_list = g_slist_remove(driver_list, driver);
406 static void network_destruct(struct connman_element *element)
408 struct connman_network *network = element->network;
410 DBG("element %p name %s", element, element->name);
412 g_free(network->wifi.ssid);
413 g_free(network->wifi.mode);
414 g_free(network->wifi.security);
415 g_free(network->wifi.passphrase);
417 g_free(network->group);
418 g_free(network->node);
419 g_free(network->name);
420 g_free(network->address);
421 g_free(network->identifier);
425 * connman_network_create:
426 * @identifier: network identifier (for example an unqiue name)
428 * Allocate a new network and assign the #identifier to it.
430 * Returns: a newly-allocated #connman_network structure
432 struct connman_network *connman_network_create(const char *identifier,
433 enum connman_network_type type)
435 struct connman_network *network;
436 connman_uint8_t strength = 0;
440 DBG("identifier %s type %d", identifier, type);
442 network = g_try_new0(struct connman_network, 1);
446 DBG("network %p", network);
448 __connman_element_initialize(&network->element);
450 //temp = connman_dbus_encode_string(identifier);
451 temp = g_strdup(identifier);
457 network->element.name = temp;
458 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
460 network->element.network = network;
461 network->element.destruct = network_destruct;
463 str = type2string(type);
465 connman_element_set_string(&network->element, "Type", str);
467 connman_element_set_uint8(&network->element, "Strength", strength);
469 network->type = type;
470 network->secondary = FALSE;
471 network->identifier = g_strdup(identifier);
477 * connman_network_ref:
478 * @network: network structure
480 * Increase reference counter of network
482 struct connman_network *connman_network_ref(struct connman_network *network)
484 if (connman_element_ref(&network->element) == NULL)
491 * connman_network_unref:
492 * @network: network structure
494 * Decrease reference counter of network
496 void connman_network_unref(struct connman_network *network)
498 connman_element_unref(&network->element);
501 const char *__connman_network_get_type(struct connman_network *network)
503 return type2string(network->type);
507 * connman_network_get_type:
508 * @network: network structure
510 * Get type of network
512 enum connman_network_type connman_network_get_type(struct connman_network *network)
514 return network->type;
518 * connman_network_get_identifier:
519 * @network: network structure
521 * Get identifier of network
523 const char *connman_network_get_identifier(struct connman_network *network)
525 return network->identifier;
529 * connman_network_get_path:
530 * @network: network structure
532 * Get path name of network
534 const char *connman_network_get_path(struct connman_network *network)
536 return network->element.path;
540 * connman_network_set_index:
541 * @network: network structure
542 * @index: index number
544 * Set index number of network
546 void connman_network_set_index(struct connman_network *network, int index)
548 network->element.index = index;
552 * connman_network_get_index:
553 * @network: network structure
555 * Get index number of network
557 int connman_network_get_index(struct connman_network *network)
559 return network->element.index;
563 * connman_network_set_protocol:
564 * @network: network structure
565 * @protocol: network protocol
567 * Change protocol of network
569 void connman_network_set_protocol(struct connman_network *network,
570 enum connman_network_protocol protocol)
572 network->protocol = protocol;
576 * connman_network_set_group:
577 * @network: network structure
580 * Set group name for automatic clustering
582 void connman_network_set_group(struct connman_network *network,
585 if (network->secondary == TRUE)
588 if (g_strcmp0(network->group, group) == 0)
591 switch (network->type) {
592 case CONNMAN_NETWORK_TYPE_UNKNOWN:
593 case CONNMAN_NETWORK_TYPE_VENDOR:
594 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
595 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
596 case CONNMAN_NETWORK_TYPE_HSO:
598 case CONNMAN_NETWORK_TYPE_WIFI:
599 case CONNMAN_NETWORK_TYPE_WIMAX:
603 if (network->group != NULL) {
604 __connman_profile_remove_network(network);
606 g_free(network->group);
609 network->group = g_strdup(group);
611 if (network->group != NULL)
612 __connman_profile_add_network(network);
615 const char *__connman_network_get_group(struct connman_network *network)
617 return network->group;
620 const char *__connman_network_get_ident(struct connman_network *network)
622 if (network->device == NULL)
625 return __connman_device_get_ident(network->device);
629 * connman_network_set_available:
630 * @network: network structure
631 * @available: availability state
633 * Change availability state of network (in range)
635 int connman_network_set_available(struct connman_network *network,
636 connman_bool_t available)
638 DBG("network %p available %d", network, available);
640 if (network->available == available)
643 network->available = available;
649 * connman_network_get_available:
650 * @network: network structure
652 * Get network available setting
654 connman_bool_t connman_network_get_available(struct connman_network *network)
656 return network->available;
660 * connman_network_set_associating:
661 * @network: network structure
662 * @associating: associating state
664 * Change associating state of network
666 int connman_network_set_associating(struct connman_network *network,
667 connman_bool_t associating)
669 DBG("network %p associating %d", network, associating);
671 if (network->associating == associating)
674 network->associating = associating;
676 if (associating == TRUE) {
677 struct connman_service *service;
679 service = __connman_service_lookup_from_network(network);
680 __connman_service_indicate_state(service,
681 CONNMAN_SERVICE_STATE_ASSOCIATION);
687 static gboolean set_connected(gpointer user_data)
689 struct connman_network *network = user_data;
690 struct connman_service *service;
692 service = __connman_service_lookup_from_network(network);
694 if (network->connected == TRUE) {
695 struct connman_element *element;
696 enum connman_element_type type = CONNMAN_ELEMENT_TYPE_UNKNOWN;
698 switch (network->protocol) {
699 case CONNMAN_NETWORK_PROTOCOL_UNKNOWN:
701 case CONNMAN_NETWORK_PROTOCOL_IP:
702 type = CONNMAN_ELEMENT_TYPE_DHCP;
704 case CONNMAN_NETWORK_PROTOCOL_PPP:
705 type = CONNMAN_ELEMENT_TYPE_PPP;
709 __connman_device_increase_connections(network->device);
711 __connman_device_set_network(network->device, network);
713 connman_device_set_disconnected(network->device, FALSE);
715 element = connman_element_create(NULL);
716 if (element != NULL) {
717 element->type = type;
718 element->index = network->element.index;
720 if (connman_element_register(element,
721 &network->element) < 0)
722 connman_element_unref(element);
724 __connman_service_indicate_state(service,
725 CONNMAN_SERVICE_STATE_CONFIGURATION);
728 __connman_service_indicate_state(service,
729 CONNMAN_SERVICE_STATE_IDLE);
731 connman_element_unregister_children(&network->element);
733 __connman_device_set_network(network->device, NULL);
735 __connman_device_decrease_connections(network->device);
742 * connman_network_set_connected:
743 * @network: network structure
744 * @connected: connected state
746 * Change connected state of network
748 int connman_network_set_connected(struct connman_network *network,
749 connman_bool_t connected)
752 DBusMessageIter entry, value;
753 const char *key = "Connected";
755 DBG("network %p connected %d", network, connected);
757 if (network->connected == connected)
760 network->connected = connected;
762 if (connected == TRUE)
763 network->associating = FALSE;
765 if (network->registered == FALSE) {
766 g_idle_add(set_connected, network);
770 signal = dbus_message_new_signal(network->element.path,
771 CONNMAN_NETWORK_INTERFACE, "PropertyChanged");
775 dbus_message_iter_init_append(signal, &entry);
777 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
779 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
780 DBUS_TYPE_BOOLEAN_AS_STRING, &value);
781 dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, &connected);
782 dbus_message_iter_close_container(&entry, &value);
784 g_dbus_send_message(connection, signal);
786 set_connected(network);
792 * connman_network_get_connected:
793 * @network: network structure
795 * Get network connection status
797 connman_bool_t connman_network_get_connected(struct connman_network *network)
799 return network->connected;
803 * __connman_network_connect:
804 * @network: network structure
808 int __connman_network_connect(struct connman_network *network)
812 DBG("network %p", network);
814 if (network->connected == TRUE)
817 if (network->driver == NULL)
820 if (network->driver->connect == NULL)
823 __connman_device_disconnect(network->device);
825 err = network->driver->connect(network);
827 network->connected = TRUE;
828 set_connected(network);
835 * __connman_network_disconnect:
836 * @network: network structure
840 int __connman_network_disconnect(struct connman_network *network)
844 DBG("network %p", network);
846 if (network->connected == FALSE)
849 if (network->driver == NULL)
852 if (network->driver->disconnect == NULL)
855 err = network->driver->disconnect(network);
857 network->connected = FALSE;
858 set_connected(network);
865 * connman_network_set_address:
866 * @network: network structure
867 * @address: binary address value
868 * @size: binary address length
870 * Set unique address value for network
872 int connman_network_set_address(struct connman_network *network,
873 const void *address, unsigned int size)
875 const unsigned char *addr_octet = address;
878 DBG("network %p size %d", network, size);
883 str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
884 addr_octet[0], addr_octet[1], addr_octet[2],
885 addr_octet[3], addr_octet[4], addr_octet[5]);
889 g_free(network->address);
890 network->address = str;
892 return connman_element_set_string(&network->element,
893 "Address", network->address);
897 * connman_network_set_name:
898 * @network: network structure
901 * Set display name value for network
903 int connman_network_set_name(struct connman_network *network,
906 DBG("network %p name %s", network, name);
908 g_free(network->name);
909 network->name = g_strdup(name);
911 return connman_element_set_string(&network->element, "Name", name);
915 * connman_network_set_strength:
916 * @network: network structure
917 * @strength: strength value
919 * Set signal strength value for network
921 int connman_network_set_strength(struct connman_network *network,
922 connman_uint8_t strength)
924 DBG("network %p strengh %d", network, strength);
926 network->strength = strength;
928 return connman_element_set_uint8(&network->element,
929 "Strength", strength);
933 * connman_network_set_string:
934 * @network: network structure
935 * @key: unique identifier
936 * @value: string value
938 * Set string value for specific key
940 int connman_network_set_string(struct connman_network *network,
941 const char *key, const char *value)
943 DBG("network %p key %s value %s", network, key, value);
945 if (g_strcmp0(key, "Name") == 0)
946 return connman_network_set_name(network, value);
948 if (g_str_equal(key, "Address") == TRUE) {
949 g_free(network->address);
950 network->address = g_strdup(value);
951 } else if (g_str_equal(key, "Node") == TRUE) {
952 g_free(network->node);
953 network->node = g_strdup(value);
954 } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
955 g_free(network->wifi.mode);
956 network->wifi.mode = g_strdup(value);
957 } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
958 g_free(network->wifi.security);
959 network->wifi.security = g_strdup(value);
960 } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
961 g_free(network->wifi.passphrase);
962 network->wifi.passphrase = g_strdup(value);
965 return connman_element_set_string(&network->element, key, value);
969 * connman_network_get_string:
970 * @network: network structure
971 * @key: unique identifier
973 * Get string value for specific key
975 const char *connman_network_get_string(struct connman_network *network,
978 DBG("network %p key %s", network, key);
980 if (g_str_equal(key, "Address") == TRUE)
981 return network->address;
982 else if (g_str_equal(key, "Name") == TRUE)
983 return network->name;
984 else if (g_str_equal(key, "Node") == TRUE)
985 return network->node;
986 else if (g_str_equal(key, "WiFi.Mode") == TRUE)
987 return network->wifi.mode;
988 else if (g_str_equal(key, "WiFi.Security") == TRUE)
989 return network->wifi.security;
990 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
991 return network->wifi.passphrase;
993 return connman_element_get_string(&network->element, key);
997 * connman_network_set_uint8:
998 * @network: network structure
999 * @key: unique identifier
1000 * @value: integer value
1002 * Set integer value for specific key
1004 int connman_network_set_uint8(struct connman_network *network,
1005 const char *key, connman_uint8_t value)
1007 DBG("network %p key %s value %d", network, key, value);
1009 if (g_strcmp0(key, "Strength") == 0)
1010 return connman_network_set_strength(network, value);
1012 return connman_element_set_uint8(&network->element, key, value);
1016 * connman_network_get_uint8:
1017 * @network: network structure
1018 * @key: unique identifier
1020 * Get integer value for specific key
1022 connman_uint8_t connman_network_get_uint8(struct connman_network *network,
1025 DBG("network %p key %s", network, key);
1027 if (g_str_equal(key, "Strength") == TRUE)
1028 return network->strength;
1030 return connman_element_get_uint8(&network->element, key);
1034 * connman_network_set_uint16:
1035 * @network: network structure
1036 * @key: unique identifier
1037 * @value: integer value
1039 * Set integer value for specific key
1041 int connman_network_set_uint16(struct connman_network *network,
1042 const char *key, connman_uint16_t value)
1044 DBG("network %p key %s value %d", network, key, value);
1046 if (g_str_equal(key, "Frequency") == TRUE)
1047 network->frequency = value;
1048 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1049 network->wifi.channel = value;
1055 * connman_network_get_uint16:
1056 * @network: network structure
1057 * @key: unique identifier
1059 * Get integer value for specific key
1061 connman_uint16_t connman_network_get_uint16(struct connman_network *network,
1064 DBG("network %p key %s", network, key);
1066 if (g_str_equal(key, "Frequency") == TRUE)
1067 return network->frequency;
1068 else if (g_str_equal(key, "WiFi.Channel") == TRUE)
1069 return network->wifi.channel;
1075 * connman_network_set_blob:
1076 * @network: network structure
1077 * @key: unique identifier
1081 * Set binary blob value for specific key
1083 int connman_network_set_blob(struct connman_network *network,
1084 const char *key, const void *data, unsigned int size)
1086 DBG("network %p key %s size %d", network, key, size);
1088 if (g_strcmp0(key, "Address") == 0)
1089 return connman_network_set_address(network, data, size);
1091 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1092 g_free(network->wifi.ssid);
1093 network->wifi.ssid = g_try_malloc(size);
1094 if (network->wifi.ssid != NULL) {
1095 memcpy(network->wifi.ssid, data, size);
1096 network->wifi.ssid_len = size;
1098 network->wifi.ssid_len = 0;
1101 return connman_element_set_blob(&network->element, key, data, size);
1105 * connman_network_get_blob:
1106 * @network: network structure
1107 * @key: unique identifier
1108 * @size: pointer to blob size
1110 * Get binary blob value for specific key
1112 const void *connman_network_get_blob(struct connman_network *network,
1113 const char *key, unsigned int *size)
1115 DBG("network %p key %s", network, key);
1117 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
1119 *size = network->wifi.ssid_len;
1120 return network->wifi.ssid;
1123 return connman_element_get_blob(&network->element, key, size);
1126 void __connman_network_set_device(struct connman_network *network,
1127 struct connman_device *device)
1129 network->device = device;
1133 * connman_network_get_device:
1134 * @network: network structure
1136 * Get parent device of network
1138 struct connman_device *connman_network_get_device(struct connman_network *network)
1140 return network->device;
1144 * connman_network_get_data:
1145 * @network: network structure
1147 * Get private network data pointer
1149 void *connman_network_get_data(struct connman_network *network)
1151 return network->driver_data;
1155 * connman_network_set_data:
1156 * @network: network structure
1157 * @data: data pointer
1159 * Set private network data pointer
1161 void connman_network_set_data(struct connman_network *network, void *data)
1163 network->driver_data = data;
1166 static gboolean match_driver(struct connman_network *network,
1167 struct connman_network_driver *driver)
1169 if (network->type == driver->type ||
1170 driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
1176 static int network_probe(struct connman_element *element)
1178 struct connman_network *network = element->network;
1182 DBG("element %p name %s", element, element->name);
1184 if (network == NULL)
1187 for (list = driver_list; list; list = list->next) {
1188 struct connman_network_driver *driver = list->data;
1190 if (match_driver(network, driver) == FALSE)
1193 DBG("driver %p name %s", driver, driver->name);
1195 if (driver->probe(network) == 0) {
1196 network->driver = driver;
1201 if (network->driver == NULL)
1204 err = register_interface(element);
1206 if (network->driver->remove)
1207 network->driver->remove(network);
1211 network->secondary = connman_device_get_secondary(network->device);
1213 switch (network->type) {
1214 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1215 case CONNMAN_NETWORK_TYPE_VENDOR:
1216 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1217 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1218 case CONNMAN_NETWORK_TYPE_HSO:
1220 case CONNMAN_NETWORK_TYPE_WIFI:
1221 case CONNMAN_NETWORK_TYPE_WIMAX:
1222 if (network->group != NULL && network->secondary == FALSE)
1223 __connman_profile_add_network(network);
1230 static void network_remove(struct connman_element *element)
1232 struct connman_network *network = element->network;
1234 DBG("element %p name %s", element, element->name);
1236 if (network == NULL)
1239 if (network->driver == NULL)
1242 switch (network->type) {
1243 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1244 case CONNMAN_NETWORK_TYPE_VENDOR:
1245 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1246 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1247 case CONNMAN_NETWORK_TYPE_HSO:
1249 case CONNMAN_NETWORK_TYPE_WIFI:
1250 case CONNMAN_NETWORK_TYPE_WIMAX:
1251 if (network->group != NULL && network->secondary == FALSE) {
1252 __connman_profile_remove_network(network);
1254 g_free(network->group);
1255 network->group = NULL;
1260 unregister_interface(element);
1262 if (network->driver->remove)
1263 network->driver->remove(network);
1266 static void network_change(struct connman_element *element)
1268 struct connman_network *network = element->network;
1270 DBG("element %p name %s", element, element->name);
1272 if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
1275 if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
1278 if (network->connected == FALSE)
1281 connman_element_unregister_children(element);
1283 connman_device_set_disconnected(network->device, TRUE);
1285 if (network->driver && network->driver->disconnect) {
1286 network->driver->disconnect(network);
1290 network->connected = FALSE;
1293 static struct connman_driver network_driver = {
1295 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
1296 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1297 .probe = network_probe,
1298 .remove = network_remove,
1299 .change = network_change,
1302 int __connman_network_init(void)
1306 connection = connman_dbus_get_connection();
1308 return connman_driver_register(&network_driver);
1311 void __connman_network_cleanup(void)
1315 connman_driver_unregister(&network_driver);
1317 dbus_connection_unref(connection);