5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 static DBusConnection *connection;
35 static GSList *technology_list = NULL;
38 * List of devices with no technology associated with them either because of
39 * no compiled in support or the driver is not yet loaded.
41 static GSList *techless_device_list = NULL;
42 static GHashTable *rfkill_list;
44 static connman_bool_t global_offlinemode;
46 struct connman_rfkill {
48 enum connman_service_type type;
49 connman_bool_t softblock;
50 connman_bool_t hardblock;
53 struct connman_technology {
55 enum connman_service_type type;
60 connman_bool_t connected;
62 connman_bool_t tethering;
63 char *tethering_ident;
64 char *tethering_passphrase;
66 connman_bool_t enable_persistent; /* Save the tech state */
68 struct connman_technology_driver *driver;
71 DBusMessage *pending_reply;
72 guint pending_timeout;
77 static GSList *driver_list = NULL;
79 static gint compare_priority(gconstpointer a, gconstpointer b)
81 const struct connman_technology_driver *driver1 = a;
82 const struct connman_technology_driver *driver2 = b;
84 return driver2->priority - driver1->priority;
87 static void rfkill_check(gpointer key, gpointer value, gpointer user_data)
89 struct connman_rfkill *rfkill = value;
90 enum connman_service_type type = GPOINTER_TO_INT(user_data);
92 /* Calling _technology_rfkill_add will update the tech. */
93 if (rfkill->type == type)
94 __connman_technology_add_rfkill(rfkill->index, type,
95 rfkill->softblock, rfkill->hardblock);
99 * connman_technology_driver_register:
100 * @driver: Technology driver definition
102 * Register a new technology driver
104 * Returns: %0 on success
106 int connman_technology_driver_register(struct connman_technology_driver *driver)
109 struct connman_device *device;
110 enum connman_service_type type;
112 DBG("Registering %s driver", driver->name);
114 driver_list = g_slist_insert_sorted(driver_list, driver,
117 if (techless_device_list == NULL)
121 * Check for technology less devices if this driver
122 * can service any of them.
124 for (list = techless_device_list; list; list = list->next) {
127 type = __connman_device_get_service_type(device);
128 if (type != driver->type)
131 techless_device_list = g_slist_remove(techless_device_list,
134 __connman_technology_add_device(device);
138 /* Check for orphaned rfkill switches. */
139 g_hash_table_foreach(rfkill_list, rfkill_check,
140 GINT_TO_POINTER(driver->type));
146 * connman_technology_driver_unregister:
147 * @driver: Technology driver definition
149 * Remove a previously registered technology driver
151 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
154 struct connman_technology *technology;
156 DBG("Unregistering driver %p name %s", driver, driver->name);
158 for (list = technology_list; list; list = list->next) {
159 technology = list->data;
161 if (technology->driver == NULL)
164 if (technology->type == driver->type) {
165 technology->driver->remove(technology);
166 technology->driver = NULL;
170 driver_list = g_slist_remove(driver_list, driver);
173 static void tethering_changed(struct connman_technology *technology)
175 connman_bool_t tethering = technology->tethering;
177 connman_dbus_property_changed_basic(technology->path,
178 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
179 DBUS_TYPE_BOOLEAN, &tethering);
182 void connman_technology_tethering_notify(struct connman_technology *technology,
183 connman_bool_t enabled)
187 DBG("technology %p enabled %u", technology, enabled);
189 if (technology->tethering == enabled)
192 technology->tethering = enabled;
194 tethering_changed(technology);
197 __connman_tethering_set_enabled();
199 for (list = technology_list; list; list = list->next) {
200 struct connman_technology *other_tech = list->data;
201 if (other_tech->tethering == TRUE)
205 __connman_tethering_set_disabled();
209 static int set_tethering(struct connman_technology *technology,
210 connman_bool_t enabled)
212 const char *ident, *passphrase, *bridge;
214 ident = technology->tethering_ident;
215 passphrase = technology->tethering_passphrase;
217 if (technology->driver == NULL ||
218 technology->driver->set_tethering == NULL)
221 bridge = __connman_tethering_get_bridge();
225 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
226 (ident == NULL || passphrase == NULL))
229 return technology->driver->set_tethering(technology, ident, passphrase,
233 void connman_technology_regdom_notify(struct connman_technology *technology,
239 connman_error("Failed to set regulatory domain");
241 DBG("Regulatory domain set to %s", alpha2);
243 g_free(technology->regdom);
244 technology->regdom = g_strdup(alpha2);
247 int connman_technology_set_regdom(const char *alpha2)
251 for (list = technology_list; list; list = list->next) {
252 struct connman_technology *technology = list->data;
254 if (technology->driver == NULL)
257 if (technology->driver->set_regdom)
258 technology->driver->set_regdom(technology, alpha2);
264 static void free_rfkill(gpointer data)
266 struct connman_rfkill *rfkill = data;
271 static const char *get_name(enum connman_service_type type)
274 case CONNMAN_SERVICE_TYPE_UNKNOWN:
275 case CONNMAN_SERVICE_TYPE_SYSTEM:
276 case CONNMAN_SERVICE_TYPE_GPS:
277 case CONNMAN_SERVICE_TYPE_VPN:
278 case CONNMAN_SERVICE_TYPE_GADGET:
280 case CONNMAN_SERVICE_TYPE_ETHERNET:
282 case CONNMAN_SERVICE_TYPE_WIFI:
284 case CONNMAN_SERVICE_TYPE_WIMAX:
286 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
288 case CONNMAN_SERVICE_TYPE_CELLULAR:
295 static void load_state(struct connman_technology *technology)
299 GError *error = NULL;
300 connman_bool_t enable;
302 DBG("technology %p", technology);
304 keyfile = __connman_storage_load_global();
305 /* Fallback on disabling technology if file not found. */
306 if (keyfile == NULL) {
307 technology->enable_persistent = FALSE;
311 identifier = g_strdup_printf("%s", get_name(technology->type));
312 if (identifier == NULL)
315 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
317 technology->enable_persistent = enable;
319 technology->enable_persistent = FALSE;
320 g_clear_error(&error);
325 g_key_file_free(keyfile);
330 static void save_state(struct connman_technology *technology)
335 DBG("technology %p", technology);
337 keyfile = __connman_storage_load_global();
339 keyfile = g_key_file_new();
341 identifier = g_strdup_printf("%s", get_name(technology->type));
342 if (identifier == NULL)
345 g_key_file_set_boolean(keyfile, identifier, "Enable",
346 technology->enable_persistent);
351 __connman_storage_save_global(keyfile);
353 g_key_file_free(keyfile);
358 connman_bool_t __connman_technology_get_offlinemode(void)
360 return global_offlinemode;
363 static void connman_technology_save_offlinemode()
367 keyfile = __connman_storage_load_global();
369 keyfile = g_key_file_new();
371 g_key_file_set_boolean(keyfile, "global",
372 "OfflineMode", global_offlinemode);
374 __connman_storage_save_global(keyfile);
376 g_key_file_free(keyfile);
381 static connman_bool_t connman_technology_load_offlinemode()
384 GError *error = NULL;
385 connman_bool_t offlinemode;
387 /* If there is a error, we enable offlinemode */
388 keyfile = __connman_storage_load_global();
392 offlinemode = g_key_file_get_boolean(keyfile, "global",
393 "OfflineMode", &error);
396 g_clear_error(&error);
399 g_key_file_free(keyfile);
404 static void append_properties(DBusMessageIter *iter,
405 struct connman_technology *technology)
407 DBusMessageIter dict;
409 connman_bool_t powered;
411 connman_dbus_dict_open(iter, &dict);
413 str = get_name(technology->type);
415 connman_dbus_dict_append_basic(&dict, "Name",
416 DBUS_TYPE_STRING, &str);
418 str = __connman_service_type2string(technology->type);
420 connman_dbus_dict_append_basic(&dict, "Type",
421 DBUS_TYPE_STRING, &str);
423 __sync_synchronize();
424 if (technology->enabled > 0)
428 connman_dbus_dict_append_basic(&dict, "Powered",
429 DBUS_TYPE_BOOLEAN, &powered);
431 connman_dbus_dict_append_basic(&dict, "Connected",
433 &technology->connected);
435 connman_dbus_dict_append_basic(&dict, "Tethering",
437 &technology->tethering);
439 if (technology->tethering_ident != NULL)
440 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
442 &technology->tethering_ident);
444 if (technology->tethering_passphrase != NULL)
445 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
447 &technology->tethering_passphrase);
449 connman_dbus_dict_close(iter, &dict);
452 static void technology_added_signal(struct connman_technology *technology)
455 DBusMessageIter iter;
457 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
458 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
462 dbus_message_iter_init_append(signal, &iter);
463 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
465 append_properties(&iter, technology);
467 dbus_connection_send(connection, signal, NULL);
468 dbus_message_unref(signal);
471 static void technology_removed_signal(struct connman_technology *technology)
473 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
474 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
475 DBUS_TYPE_OBJECT_PATH, &technology->path,
479 static DBusMessage *get_properties(DBusConnection *conn,
480 DBusMessage *message, void *user_data)
482 struct connman_technology *technology = user_data;
484 DBusMessageIter iter;
486 reply = dbus_message_new_method_return(message);
490 dbus_message_iter_init_append(reply, &iter);
491 append_properties(&iter, technology);
496 void __connman_technology_list_struct(DBusMessageIter *array)
499 DBusMessageIter entry;
501 for (list = technology_list; list; list = list->next) {
502 struct connman_technology *technology = list->data;
504 if (technology->path == NULL)
507 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
509 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
511 append_properties(&entry, technology);
512 dbus_message_iter_close_container(array, &entry);
516 static gboolean technology_pending_reply(gpointer user_data)
518 struct connman_technology *technology = user_data;
521 /* Power request timedout, send ETIMEDOUT. */
522 if (technology->pending_reply != NULL) {
523 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
525 g_dbus_send_message(connection, reply);
527 dbus_message_unref(technology->pending_reply);
528 technology->pending_reply = NULL;
529 technology->pending_timeout = 0;
535 static int technology_enable(struct connman_technology *technology,
543 DBG("technology %p enable", technology);
545 __sync_synchronize();
546 if (technology->enabled > 0) {
551 if (technology->pending_reply != NULL) {
558 * This is a bit of a trick. When msg is not NULL it means
559 * thats technology_enable was invoked from the manager API.
560 * Hence we save the state here.
562 technology->enable_persistent = TRUE;
563 save_state(technology);
566 __connman_rfkill_block(technology->type, FALSE);
569 * An empty device list means that devices in the technology
570 * were rfkill blocked. The unblock above will enable the devs.
572 if (technology->device_list == NULL) {
577 for (list = technology->device_list; list; list = list->next) {
578 struct connman_device *device = list->data;
580 err = __connman_device_enable(device);
582 * err = 0 : Device was enabled right away.
583 * If atleast one device gets enabled, we consider
584 * the technology to be enabled.
593 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
598 if (err == -EINPROGRESS) {
599 technology->pending_reply = dbus_message_ref(msg);
600 technology->pending_timeout = g_timeout_add_seconds(10,
601 technology_pending_reply, technology);
603 reply = __connman_error_failed(msg, -err);
605 g_dbus_send_message(connection, reply);
612 static int technology_disable(struct connman_technology *technology,
620 DBG("technology %p disable", technology);
622 __sync_synchronize();
623 if (technology->enabled == 0) {
628 if (technology->pending_reply != NULL) {
633 if (technology->tethering == TRUE)
634 set_tethering(technology, FALSE);
637 technology->enable_persistent = FALSE;
638 save_state(technology);
641 __connman_rfkill_block(technology->type, TRUE);
643 for (list = technology->device_list; list; list = list->next) {
644 struct connman_device *device = list->data;
646 err = __connman_device_disable(device);
654 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
659 if (err == -EINPROGRESS) {
660 technology->pending_reply = dbus_message_ref(msg);
661 technology->pending_timeout = g_timeout_add_seconds(10,
662 technology_pending_reply, technology);
664 reply = __connman_error_failed(msg, -err);
666 g_dbus_send_message(connection, reply);
673 static DBusMessage *set_property(DBusConnection *conn,
674 DBusMessage *msg, void *data)
676 struct connman_technology *technology = data;
677 DBusMessageIter iter, value;
681 DBG("conn %p", conn);
683 if (dbus_message_iter_init(msg, &iter) == FALSE)
684 return __connman_error_invalid_arguments(msg);
686 dbus_message_iter_get_basic(&iter, &name);
687 dbus_message_iter_next(&iter);
688 dbus_message_iter_recurse(&iter, &value);
690 type = dbus_message_iter_get_arg_type(&value);
692 DBG("property %s", name);
694 if (g_str_equal(name, "Tethering") == TRUE) {
696 connman_bool_t tethering;
698 if (type != DBUS_TYPE_BOOLEAN)
699 return __connman_error_invalid_arguments(msg);
701 dbus_message_iter_get_basic(&value, &tethering);
703 if (technology->tethering == tethering)
704 return __connman_error_in_progress(msg);
706 err = set_tethering(technology, tethering);
708 return __connman_error_failed(msg, -err);
710 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
713 dbus_message_iter_get_basic(&value, &str);
715 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
716 return __connman_error_not_supported(msg);
718 technology->tethering_ident = g_strdup(str);
719 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
722 dbus_message_iter_get_basic(&value, &str);
724 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
725 return __connman_error_not_supported(msg);
728 return __connman_error_invalid_arguments(msg);
730 technology->tethering_passphrase = g_strdup(str);
731 } else if (g_str_equal(name, "Powered") == TRUE) {
732 connman_bool_t enable;
734 if (type != DBUS_TYPE_BOOLEAN)
735 return __connman_error_invalid_arguments(msg);
737 dbus_message_iter_get_basic(&value, &enable);
739 technology_enable(technology, msg);
741 technology_disable(technology, msg);
744 return __connman_error_invalid_property(msg);
746 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
749 static struct connman_technology *technology_find(enum connman_service_type type)
753 DBG("type %d", type);
755 for (list = technology_list; list; list = list->next) {
756 struct connman_technology *technology = list->data;
758 if (technology->type == type)
765 static void reply_scan_pending(struct connman_technology *technology, int err)
769 DBG("technology %p err %d", technology, err);
771 while (technology->scan_pending != NULL) {
772 DBusMessage *msg = technology->scan_pending->data;
774 DBG("reply to %s", dbus_message_get_sender(msg));
777 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
779 reply = __connman_error_failed(msg, -err);
780 g_dbus_send_message(connection, reply);
781 dbus_message_unref(msg);
783 technology->scan_pending =
784 g_slist_delete_link(technology->scan_pending,
785 technology->scan_pending);
789 void __connman_technology_scan_started(struct connman_device *device)
791 DBG("device %p", device);
794 void __connman_technology_scan_stopped(struct connman_device *device)
797 struct connman_technology *technology;
798 enum connman_service_type type;
801 type = __connman_device_get_service_type(device);
802 technology = technology_find(type);
804 DBG("technology %p device %p", technology, device);
806 if (technology == NULL)
809 for (list = technology->device_list; list != NULL; list = list->next) {
810 struct connman_device *other_device = list->data;
812 if (device == other_device)
815 if (__connman_device_get_service_type(other_device) != type)
818 if (__connman_device_scanning(other_device))
823 reply_scan_pending(technology, 0);
826 static DBusMessage *scan(DBusConnection *conn, DBusMessage *msg, void *data)
828 struct connman_technology *technology = data;
831 DBG ("technology %p request from %s", technology,
832 dbus_message_get_sender(msg));
834 dbus_message_ref(msg);
835 technology->scan_pending =
836 g_slist_prepend(technology->scan_pending, msg);
838 err = __connman_device_request_scan(technology->type);
840 reply_scan_pending(technology, err);
845 static GDBusMethodTable technology_methods[] = {
846 { "GetProperties", "", "a{sv}", get_properties },
847 { "SetProperty", "sv", "", set_property },
848 { "Scan", "", "", scan,
849 G_DBUS_METHOD_FLAG_ASYNC },
853 static GDBusSignalTable technology_signals[] = {
854 { "PropertyChanged", "sv" },
858 static struct connman_technology *technology_get(enum connman_service_type type)
860 struct connman_technology *technology;
861 struct connman_technology_driver *driver = NULL;
866 DBG("type %d", type);
868 str = __connman_service_type2string(type);
872 technology = technology_find(type);
873 if (technology != NULL) {
874 __sync_fetch_and_add(&technology->refcount, 1);
878 /* First check if we have a driver for this technology type */
879 for (list = driver_list; list; list = list->next) {
882 if (driver->type == type)
888 if (driver == NULL) {
889 DBG("No matching driver found for %s.",
890 __connman_service_type2string(type));
894 technology = g_try_new0(struct connman_technology, 1);
895 if (technology == NULL)
898 technology->refcount = 1;
900 technology->type = type;
901 technology->path = g_strdup_printf("%s/technology/%s",
904 technology->device_list = NULL;
906 technology->pending_reply = NULL;
908 load_state(technology);
910 if (g_dbus_register_interface(connection, technology->path,
911 CONNMAN_TECHNOLOGY_INTERFACE,
912 technology_methods, technology_signals,
913 NULL, technology, NULL) == FALSE) {
914 connman_error("Failed to register %s", technology->path);
919 technology_list = g_slist_append(technology_list, technology);
921 technology_added_signal(technology);
923 technology->driver = driver;
924 err = driver->probe(technology);
926 DBG("Driver probe failed for technology %p", technology);
928 DBG("technology %p", technology);
933 static void technology_put(struct connman_technology *technology)
935 DBG("technology %p", technology);
937 if (__sync_fetch_and_sub(&technology->refcount, 1) > 0)
940 reply_scan_pending(technology, -EINTR);
942 if (technology->driver) {
943 technology->driver->remove(technology);
944 technology->driver = NULL;
947 technology_list = g_slist_remove(technology_list, technology);
949 technology_removed_signal(technology);
951 g_dbus_unregister_interface(connection, technology->path,
952 CONNMAN_TECHNOLOGY_INTERFACE);
954 g_slist_free(technology->device_list);
956 g_free(technology->path);
957 g_free(technology->regdom);
961 void __connman_technology_add_interface(enum connman_service_type type,
962 int index, const char *name, const char *ident)
964 struct connman_technology *technology;
967 case CONNMAN_SERVICE_TYPE_UNKNOWN:
968 case CONNMAN_SERVICE_TYPE_SYSTEM:
970 case CONNMAN_SERVICE_TYPE_ETHERNET:
971 case CONNMAN_SERVICE_TYPE_WIFI:
972 case CONNMAN_SERVICE_TYPE_WIMAX:
973 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
974 case CONNMAN_SERVICE_TYPE_CELLULAR:
975 case CONNMAN_SERVICE_TYPE_GPS:
976 case CONNMAN_SERVICE_TYPE_VPN:
977 case CONNMAN_SERVICE_TYPE_GADGET:
981 connman_info("Adding interface %s [ %s ]", name,
982 __connman_service_type2string(type));
984 technology = technology_find(type);
986 if (technology == NULL || technology->driver == NULL
987 || technology->driver->add_interface == NULL)
990 technology->driver->add_interface(technology,
994 void __connman_technology_remove_interface(enum connman_service_type type,
995 int index, const char *name, const char *ident)
997 struct connman_technology *technology;
1000 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1001 case CONNMAN_SERVICE_TYPE_SYSTEM:
1003 case CONNMAN_SERVICE_TYPE_ETHERNET:
1004 case CONNMAN_SERVICE_TYPE_WIFI:
1005 case CONNMAN_SERVICE_TYPE_WIMAX:
1006 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1007 case CONNMAN_SERVICE_TYPE_CELLULAR:
1008 case CONNMAN_SERVICE_TYPE_GPS:
1009 case CONNMAN_SERVICE_TYPE_VPN:
1010 case CONNMAN_SERVICE_TYPE_GADGET:
1014 connman_info("Remove interface %s [ %s ]", name,
1015 __connman_service_type2string(type));
1017 technology = technology_find(type);
1019 if (technology == NULL || technology->driver == NULL)
1022 if (technology->driver->remove_interface)
1023 technology->driver->remove_interface(technology, index);
1026 int __connman_technology_add_device(struct connman_device *device)
1028 struct connman_technology *technology;
1029 enum connman_service_type type;
1031 DBG("device %p", device);
1033 type = __connman_device_get_service_type(device);
1035 technology = technology_get(type);
1036 if (technology == NULL) {
1038 * Since no driver can be found for this device at the moment we
1039 * add it to the techless device list.
1041 techless_device_list = g_slist_prepend(techless_device_list,
1047 if (technology->enable_persistent && !global_offlinemode)
1048 __connman_device_enable(device);
1049 /* if technology persistent state is offline */
1050 if (!technology->enable_persistent)
1051 __connman_device_disable(device);
1053 technology->device_list = g_slist_append(technology->device_list,
1059 int __connman_technology_remove_device(struct connman_device *device)
1061 struct connman_technology *technology;
1062 enum connman_service_type type;
1064 DBG("device %p", device);
1066 type = __connman_device_get_service_type(device);
1068 technology = technology_find(type);
1069 if (technology == NULL) {
1070 techless_device_list = g_slist_remove(techless_device_list,
1075 if (__connman_device_scanning(device))
1076 __connman_technology_scan_stopped(device);
1078 technology->device_list = g_slist_remove(technology->device_list,
1080 technology_put(technology);
1085 static void powered_changed(struct connman_technology *technology)
1087 connman_bool_t powered;
1089 __sync_synchronize();
1090 if (technology->enabled >0)
1095 connman_dbus_property_changed_basic(technology->path,
1096 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
1097 DBUS_TYPE_BOOLEAN, &powered);
1100 int __connman_technology_enabled(enum connman_service_type type)
1102 struct connman_technology *technology;
1104 technology = technology_find(type);
1105 if (technology == NULL)
1108 if (__sync_fetch_and_add(&technology->enabled, 1) == 0)
1109 powered_changed(technology);
1111 if (technology->pending_reply != NULL) {
1112 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1113 dbus_message_unref(technology->pending_reply);
1114 g_source_remove(technology->pending_timeout);
1115 technology->pending_reply = NULL;
1116 technology->pending_timeout = 0;
1122 int __connman_technology_disabled(enum connman_service_type type)
1124 struct connman_technology *technology;
1126 technology = technology_find(type);
1127 if (technology == NULL)
1130 if (technology->pending_reply != NULL) {
1131 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1132 dbus_message_unref(technology->pending_reply);
1133 g_source_remove(technology->pending_timeout);
1134 technology->pending_reply = NULL;
1135 technology->pending_timeout = 0;
1138 if (__sync_fetch_and_sub(&technology->enabled, 1) == 1)
1139 powered_changed(technology);
1144 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1149 if (global_offlinemode == offlinemode)
1152 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1155 * This is a bit tricky. When you set offlinemode, there is no
1156 * way to differentiate between attempting offline mode and
1157 * resuming offlinemode from last saved profile. We need that
1158 * information in rfkill_update, otherwise it falls back on the
1159 * technology's persistent state. Hence we set the offline mode here
1160 * but save it & call the notifier only if its successful.
1163 global_offlinemode = offlinemode;
1165 /* Traverse technology list, enable/disable each technology. */
1166 for (list = technology_list; list; list = list->next) {
1167 struct connman_technology *technology = list->data;
1170 err = technology_disable(technology, NULL);
1172 if (!offlinemode && technology->enable_persistent)
1173 err = technology_enable(technology, NULL);
1176 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1177 connman_technology_save_offlinemode();
1178 __connman_notifier_offlinemode(offlinemode);
1180 global_offlinemode = connman_technology_load_offlinemode();
1185 void __connman_technology_set_connected(enum connman_service_type type,
1186 connman_bool_t connected)
1188 struct connman_technology *technology;
1190 technology = technology_find(type);
1191 if (technology == NULL)
1194 DBG("technology %p connected %d", technology, connected);
1196 technology->connected = connected;
1198 connman_dbus_property_changed_basic(technology->path,
1199 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
1200 DBUS_TYPE_BOOLEAN, &connected);
1203 int __connman_technology_add_rfkill(unsigned int index,
1204 enum connman_service_type type,
1205 connman_bool_t softblock,
1206 connman_bool_t hardblock)
1208 struct connman_technology *technology;
1209 struct connman_rfkill *rfkill;
1211 DBG("index %u type %d soft %u hard %u", index, type,
1212 softblock, hardblock);
1214 rfkill = g_hash_table_lookup(rfkill_list, &index);
1218 rfkill = g_try_new0(struct connman_rfkill, 1);
1222 rfkill->index = index;
1223 rfkill->type = type;
1224 rfkill->softblock = softblock;
1225 rfkill->hardblock = hardblock;
1227 g_hash_table_insert(rfkill_list, &rfkill->index, rfkill);
1230 technology = technology_get(type);
1231 /* If there is no driver for this type, ignore it. */
1232 if (technology == NULL)
1236 DBG("%s is switched off.", get_name(type));
1241 * If Offline mode is on, we softblock the device if it isnt already.
1242 * If Offline mode is off, we rely on the persistent state of tech.
1244 if (global_offlinemode) {
1246 return __connman_rfkill_block(type, TRUE);
1248 if (technology->enable_persistent && softblock)
1249 return __connman_rfkill_block(type, FALSE);
1250 /* if technology persistent state is offline */
1251 if (!technology->enable_persistent && !softblock)
1252 return __connman_rfkill_block(type, TRUE);
1258 int __connman_technology_update_rfkill(unsigned int index,
1259 enum connman_service_type type,
1260 connman_bool_t softblock,
1261 connman_bool_t hardblock)
1263 struct connman_technology *technology;
1264 struct connman_rfkill *rfkill;
1266 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1268 rfkill = g_hash_table_lookup(rfkill_list, &index);
1272 if (rfkill->softblock == softblock &&
1273 rfkill->hardblock == hardblock)
1276 rfkill->softblock = softblock;
1277 rfkill->hardblock = hardblock;
1280 DBG("%s is switched off.", get_name(type));
1284 technology = technology_get(type);
1285 /* If there is no driver for this type, ignore it. */
1286 if (technology == NULL)
1289 if (!global_offlinemode) {
1290 if (technology->enable_persistent && softblock)
1291 return __connman_rfkill_block(type, FALSE);
1292 if (!technology->enable_persistent && !softblock)
1293 return __connman_rfkill_block(type, TRUE);
1299 int __connman_technology_remove_rfkill(unsigned int index,
1300 enum connman_service_type type)
1302 struct connman_technology *technology;
1303 struct connman_rfkill *rfkill;
1305 DBG("index %u", index);
1307 rfkill = g_hash_table_lookup(rfkill_list, &index);
1311 g_hash_table_remove(rfkill_list, &index);
1313 technology = technology_find(type);
1314 if (technology == NULL)
1317 technology_put(technology);
1322 int __connman_technology_init(void)
1326 connection = connman_dbus_get_connection();
1328 rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
1331 global_offlinemode = connman_technology_load_offlinemode();
1336 void __connman_technology_cleanup(void)
1340 g_hash_table_destroy(rfkill_list);
1342 dbus_connection_unref(connection);