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;
75 static GSList *driver_list = NULL;
77 static gint compare_priority(gconstpointer a, gconstpointer b)
79 const struct connman_technology_driver *driver1 = a;
80 const struct connman_technology_driver *driver2 = b;
82 return driver2->priority - driver1->priority;
85 static void rfkill_check(gpointer key, gpointer value, gpointer user_data)
87 struct connman_rfkill *rfkill = value;
88 enum connman_service_type type = GPOINTER_TO_INT(user_data);
90 /* Calling _technology_rfkill_add will update the tech. */
91 if (rfkill->type == type)
92 __connman_technology_add_rfkill(rfkill->index, type,
93 rfkill->softblock, rfkill->hardblock);
97 * connman_technology_driver_register:
98 * @driver: Technology driver definition
100 * Register a new technology driver
102 * Returns: %0 on success
104 int connman_technology_driver_register(struct connman_technology_driver *driver)
107 struct connman_device *device;
108 enum connman_service_type type;
110 DBG("Registering %s driver", driver->name);
112 driver_list = g_slist_insert_sorted(driver_list, driver,
115 if (techless_device_list == NULL)
119 * Check for technology less devices if this driver
120 * can service any of them.
122 for (list = techless_device_list; list; list = list->next) {
125 type = __connman_device_get_service_type(device);
126 if (type != driver->type)
129 techless_device_list = g_slist_remove(techless_device_list,
132 __connman_technology_add_device(device);
136 /* Check for orphaned rfkill switches. */
137 g_hash_table_foreach(rfkill_list, rfkill_check,
138 GINT_TO_POINTER(driver->type));
144 * connman_technology_driver_unregister:
145 * @driver: Technology driver definition
147 * Remove a previously registered technology driver
149 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
152 struct connman_technology *technology;
154 DBG("Unregistering driver %p name %s", driver, driver->name);
156 for (list = technology_list; list; list = list->next) {
157 technology = list->data;
159 if (technology->driver == NULL)
162 if (technology->type == driver->type) {
163 technology->driver->remove(technology);
164 technology->driver = NULL;
168 driver_list = g_slist_remove(driver_list, driver);
171 static void tethering_changed(struct connman_technology *technology)
173 connman_bool_t tethering = technology->tethering;
175 connman_dbus_property_changed_basic(technology->path,
176 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
177 DBUS_TYPE_BOOLEAN, &tethering);
180 void connman_technology_tethering_notify(struct connman_technology *technology,
181 connman_bool_t enabled)
185 DBG("technology %p enabled %u", technology, enabled);
187 if (technology->tethering == enabled)
190 technology->tethering = enabled;
192 tethering_changed(technology);
195 __connman_tethering_set_enabled();
197 for (list = technology_list; list; list = list->next) {
198 struct connman_technology *other_tech = list->data;
199 if (other_tech->tethering == TRUE)
203 __connman_tethering_set_disabled();
207 static int set_tethering(struct connman_technology *technology,
208 connman_bool_t enabled)
210 const char *ident, *passphrase, *bridge;
212 ident = technology->tethering_ident;
213 passphrase = technology->tethering_passphrase;
215 if (technology->driver == NULL ||
216 technology->driver->set_tethering == NULL)
219 bridge = __connman_tethering_get_bridge();
223 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
224 (ident == NULL || passphrase == NULL))
227 return technology->driver->set_tethering(technology, ident, passphrase,
231 void connman_technology_regdom_notify(struct connman_technology *technology,
237 connman_error("Failed to set regulatory domain");
239 DBG("Regulatory domain set to %s", alpha2);
241 g_free(technology->regdom);
242 technology->regdom = g_strdup(alpha2);
245 int connman_technology_set_regdom(const char *alpha2)
249 for (list = technology_list; list; list = list->next) {
250 struct connman_technology *technology = list->data;
252 if (technology->driver == NULL)
255 if (technology->driver->set_regdom)
256 technology->driver->set_regdom(technology, alpha2);
262 static void free_rfkill(gpointer data)
264 struct connman_rfkill *rfkill = data;
269 static const char *get_name(enum connman_service_type type)
272 case CONNMAN_SERVICE_TYPE_UNKNOWN:
273 case CONNMAN_SERVICE_TYPE_SYSTEM:
274 case CONNMAN_SERVICE_TYPE_GPS:
275 case CONNMAN_SERVICE_TYPE_VPN:
276 case CONNMAN_SERVICE_TYPE_GADGET:
278 case CONNMAN_SERVICE_TYPE_ETHERNET:
280 case CONNMAN_SERVICE_TYPE_WIFI:
282 case CONNMAN_SERVICE_TYPE_WIMAX:
284 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
286 case CONNMAN_SERVICE_TYPE_CELLULAR:
293 static void load_state(struct connman_technology *technology)
297 GError *error = NULL;
298 connman_bool_t enable;
300 DBG("technology %p", technology);
302 keyfile = __connman_storage_load_global();
303 /* Fallback on disabling technology if file not found. */
304 if (keyfile == NULL) {
305 technology->enable_persistent = FALSE;
309 identifier = g_strdup_printf("%s", get_name(technology->type));
310 if (identifier == NULL)
313 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
315 technology->enable_persistent = enable;
317 technology->enable_persistent = FALSE;
318 g_clear_error(&error);
323 g_key_file_free(keyfile);
328 static void save_state(struct connman_technology *technology)
333 DBG("technology %p", technology);
335 keyfile = __connman_storage_load_global();
337 keyfile = g_key_file_new();
339 identifier = g_strdup_printf("%s", get_name(technology->type));
340 if (identifier == NULL)
343 g_key_file_set_boolean(keyfile, identifier, "Enable",
344 technology->enable_persistent);
349 __connman_storage_save_global(keyfile);
351 g_key_file_free(keyfile);
356 connman_bool_t __connman_technology_get_offlinemode(void)
358 return global_offlinemode;
361 static void connman_technology_save_offlinemode()
365 keyfile = __connman_storage_load_global();
367 keyfile = g_key_file_new();
369 g_key_file_set_boolean(keyfile, "global",
370 "OfflineMode", global_offlinemode);
372 __connman_storage_save_global(keyfile);
374 g_key_file_free(keyfile);
379 static connman_bool_t connman_technology_load_offlinemode()
382 GError *error = NULL;
383 connman_bool_t offlinemode;
385 /* If there is a error, we enable offlinemode */
386 keyfile = __connman_storage_load_global();
390 offlinemode = g_key_file_get_boolean(keyfile, "global",
391 "OfflineMode", &error);
394 g_clear_error(&error);
397 g_key_file_free(keyfile);
402 static void append_properties(DBusMessageIter *iter,
403 struct connman_technology *technology)
405 DBusMessageIter dict;
407 connman_bool_t powered;
409 connman_dbus_dict_open(iter, &dict);
411 str = get_name(technology->type);
413 connman_dbus_dict_append_basic(&dict, "Name",
414 DBUS_TYPE_STRING, &str);
416 str = __connman_service_type2string(technology->type);
418 connman_dbus_dict_append_basic(&dict, "Type",
419 DBUS_TYPE_STRING, &str);
421 __sync_synchronize();
422 if (technology->enabled > 0)
426 connman_dbus_dict_append_basic(&dict, "Powered",
427 DBUS_TYPE_BOOLEAN, &powered);
429 connman_dbus_dict_append_basic(&dict, "Connected",
431 &technology->connected);
433 connman_dbus_dict_append_basic(&dict, "Tethering",
435 &technology->tethering);
437 if (technology->tethering_ident != NULL)
438 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
440 &technology->tethering_ident);
442 if (technology->tethering_passphrase != NULL)
443 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
445 &technology->tethering_passphrase);
447 connman_dbus_dict_close(iter, &dict);
450 static void technology_added_signal(struct connman_technology *technology)
453 DBusMessageIter iter;
455 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
456 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
460 dbus_message_iter_init_append(signal, &iter);
461 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
463 append_properties(&iter, technology);
465 dbus_connection_send(connection, signal, NULL);
466 dbus_message_unref(signal);
469 static void technology_removed_signal(struct connman_technology *technology)
471 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
472 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
473 DBUS_TYPE_OBJECT_PATH, &technology->path,
477 static DBusMessage *get_properties(DBusConnection *conn,
478 DBusMessage *message, void *user_data)
480 struct connman_technology *technology = user_data;
482 DBusMessageIter iter;
484 reply = dbus_message_new_method_return(message);
488 dbus_message_iter_init_append(reply, &iter);
489 append_properties(&iter, technology);
494 void __connman_technology_list_struct(DBusMessageIter *array)
497 DBusMessageIter entry;
499 for (list = technology_list; list; list = list->next) {
500 struct connman_technology *technology = list->data;
502 if (technology->path == NULL)
505 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
507 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
509 append_properties(&entry, technology);
510 dbus_message_iter_close_container(array, &entry);
514 static gboolean technology_pending_reply(gpointer user_data)
516 struct connman_technology *technology = user_data;
519 /* Power request timedout, send ETIMEDOUT. */
520 if (technology->pending_reply != NULL) {
521 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
523 g_dbus_send_message(connection, reply);
525 dbus_message_unref(technology->pending_reply);
526 technology->pending_reply = NULL;
527 technology->pending_timeout = 0;
533 static int technology_enable(struct connman_technology *technology,
541 DBG("technology %p enable", technology);
543 __sync_synchronize();
544 if (technology->enabled > 0) {
549 if (technology->pending_reply != NULL) {
556 * This is a bit of a trick. When msg is not NULL it means
557 * thats technology_enable was invoked from the manager API.
558 * Hence we save the state here.
560 technology->enable_persistent = TRUE;
561 save_state(technology);
564 __connman_rfkill_block(technology->type, FALSE);
567 * An empty device list means that devices in the technology
568 * were rfkill blocked. The unblock above will enable the devs.
570 if (technology->device_list == NULL) {
575 for (list = technology->device_list; list; list = list->next) {
576 struct connman_device *device = list->data;
578 err = __connman_device_enable(device);
580 * err = 0 : Device was enabled right away.
581 * If atleast one device gets enabled, we consider
582 * the technology to be enabled.
591 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
596 if (err == -EINPROGRESS) {
597 technology->pending_reply = dbus_message_ref(msg);
598 technology->pending_timeout = g_timeout_add_seconds(10,
599 technology_pending_reply, technology);
601 reply = __connman_error_failed(msg, -err);
603 g_dbus_send_message(connection, reply);
610 static int technology_disable(struct connman_technology *technology,
618 DBG("technology %p disable", technology);
620 __sync_synchronize();
621 if (technology->enabled == 0) {
626 if (technology->pending_reply != NULL) {
631 if (technology->tethering == TRUE)
632 set_tethering(technology, FALSE);
635 technology->enable_persistent = FALSE;
636 save_state(technology);
639 __connman_rfkill_block(technology->type, TRUE);
641 for (list = technology->device_list; list; list = list->next) {
642 struct connman_device *device = list->data;
644 err = __connman_device_disable(device);
652 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
657 if (err == -EINPROGRESS) {
658 technology->pending_reply = dbus_message_ref(msg);
659 technology->pending_timeout = g_timeout_add_seconds(10,
660 technology_pending_reply, technology);
662 reply = __connman_error_failed(msg, -err);
664 g_dbus_send_message(connection, reply);
671 static DBusMessage *set_property(DBusConnection *conn,
672 DBusMessage *msg, void *data)
674 struct connman_technology *technology = data;
675 DBusMessageIter iter, value;
679 DBG("conn %p", conn);
681 if (dbus_message_iter_init(msg, &iter) == FALSE)
682 return __connman_error_invalid_arguments(msg);
684 dbus_message_iter_get_basic(&iter, &name);
685 dbus_message_iter_next(&iter);
686 dbus_message_iter_recurse(&iter, &value);
688 type = dbus_message_iter_get_arg_type(&value);
690 DBG("property %s", name);
692 if (g_str_equal(name, "Tethering") == TRUE) {
694 connman_bool_t tethering;
696 if (type != DBUS_TYPE_BOOLEAN)
697 return __connman_error_invalid_arguments(msg);
699 dbus_message_iter_get_basic(&value, &tethering);
701 if (technology->tethering == tethering)
702 return __connman_error_in_progress(msg);
704 err = set_tethering(technology, tethering);
706 return __connman_error_failed(msg, -err);
708 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
711 dbus_message_iter_get_basic(&value, &str);
713 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
714 return __connman_error_not_supported(msg);
716 technology->tethering_ident = g_strdup(str);
717 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
720 dbus_message_iter_get_basic(&value, &str);
722 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
723 return __connman_error_not_supported(msg);
726 return __connman_error_invalid_arguments(msg);
728 technology->tethering_passphrase = g_strdup(str);
729 } else if (g_str_equal(name, "Powered") == TRUE) {
730 connman_bool_t enable;
732 if (type != DBUS_TYPE_BOOLEAN)
733 return __connman_error_invalid_arguments(msg);
735 dbus_message_iter_get_basic(&value, &enable);
737 technology_enable(technology, msg);
739 technology_disable(technology, msg);
742 return __connman_error_invalid_property(msg);
744 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
747 static GDBusMethodTable technology_methods[] = {
748 { "GetProperties", "", "a{sv}", get_properties },
749 { "SetProperty", "sv", "", set_property },
753 static GDBusSignalTable technology_signals[] = {
754 { "PropertyChanged", "sv" },
758 static struct connman_technology *technology_find(enum connman_service_type type)
762 DBG("type %d", type);
764 for (list = technology_list; list; list = list->next) {
765 struct connman_technology *technology = list->data;
767 if (technology->type == type)
774 static struct connman_technology *technology_get(enum connman_service_type type)
776 struct connman_technology *technology;
777 struct connman_technology_driver *driver = NULL;
782 DBG("type %d", type);
784 str = __connman_service_type2string(type);
788 technology = technology_find(type);
789 if (technology != NULL)
792 /* First check if we have a driver for this technology type */
793 for (list = driver_list; list; list = list->next) {
796 if (driver->type == type)
802 if (driver == NULL) {
803 DBG("No matching driver found for %s.",
804 __connman_service_type2string(type));
808 technology = g_try_new0(struct connman_technology, 1);
809 if (technology == NULL)
812 technology->refcount = 1;
814 technology->type = type;
815 technology->path = g_strdup_printf("%s/technology/%s",
818 technology->device_list = NULL;
820 technology->pending_reply = NULL;
822 load_state(technology);
824 if (g_dbus_register_interface(connection, technology->path,
825 CONNMAN_TECHNOLOGY_INTERFACE,
826 technology_methods, technology_signals,
827 NULL, technology, NULL) == FALSE) {
828 connman_error("Failed to register %s", technology->path);
833 technology_list = g_slist_append(technology_list, technology);
835 technology_added_signal(technology);
837 technology->driver = driver;
838 err = driver->probe(technology);
840 DBG("Driver probe failed for technology %p", technology);
842 DBG("technology %p", technology);
847 static void technology_put(struct connman_technology *technology)
849 DBG("technology %p", technology);
851 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
854 if (technology->driver) {
855 technology->driver->remove(technology);
856 technology->driver = NULL;
859 technology_list = g_slist_remove(technology_list, technology);
861 technology_removed_signal(technology);
863 g_dbus_unregister_interface(connection, technology->path,
864 CONNMAN_TECHNOLOGY_INTERFACE);
866 g_slist_free(technology->device_list);
868 g_free(technology->path);
869 g_free(technology->regdom);
873 void __connman_technology_add_interface(enum connman_service_type type,
874 int index, const char *name, const char *ident)
876 struct connman_technology *technology;
879 case CONNMAN_SERVICE_TYPE_UNKNOWN:
880 case CONNMAN_SERVICE_TYPE_SYSTEM:
882 case CONNMAN_SERVICE_TYPE_ETHERNET:
883 case CONNMAN_SERVICE_TYPE_WIFI:
884 case CONNMAN_SERVICE_TYPE_WIMAX:
885 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
886 case CONNMAN_SERVICE_TYPE_CELLULAR:
887 case CONNMAN_SERVICE_TYPE_GPS:
888 case CONNMAN_SERVICE_TYPE_VPN:
889 case CONNMAN_SERVICE_TYPE_GADGET:
893 connman_info("Adding interface %s [ %s ]", name,
894 __connman_service_type2string(type));
896 technology = technology_find(type);
898 if (technology == NULL || technology->driver == NULL
899 || technology->driver->add_interface == NULL)
902 technology->driver->add_interface(technology,
906 void __connman_technology_remove_interface(enum connman_service_type type,
907 int index, const char *name, const char *ident)
909 struct connman_technology *technology;
912 case CONNMAN_SERVICE_TYPE_UNKNOWN:
913 case CONNMAN_SERVICE_TYPE_SYSTEM:
915 case CONNMAN_SERVICE_TYPE_ETHERNET:
916 case CONNMAN_SERVICE_TYPE_WIFI:
917 case CONNMAN_SERVICE_TYPE_WIMAX:
918 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
919 case CONNMAN_SERVICE_TYPE_CELLULAR:
920 case CONNMAN_SERVICE_TYPE_GPS:
921 case CONNMAN_SERVICE_TYPE_VPN:
922 case CONNMAN_SERVICE_TYPE_GADGET:
926 connman_info("Remove interface %s [ %s ]", name,
927 __connman_service_type2string(type));
929 technology = technology_find(type);
931 if (technology == NULL || technology->driver == NULL)
934 if (technology->driver->remove_interface)
935 technology->driver->remove_interface(technology, index);
938 int __connman_technology_add_device(struct connman_device *device)
940 struct connman_technology *technology;
941 enum connman_service_type type;
943 DBG("device %p", device);
945 type = __connman_device_get_service_type(device);
947 technology = technology_get(type);
948 if (technology == NULL) {
950 * Since no driver can be found for this device at the moment we
951 * add it to the techless device list.
953 techless_device_list = g_slist_prepend(techless_device_list,
959 if (technology->enable_persistent && !global_offlinemode)
960 __connman_device_enable(device);
961 /* if technology persistent state is offline */
962 if (!technology->enable_persistent)
963 __connman_device_disable(device);
965 technology->device_list = g_slist_append(technology->device_list,
971 int __connman_technology_remove_device(struct connman_device *device)
973 struct connman_technology *technology;
974 enum connman_service_type type;
976 DBG("device %p", device);
978 type = __connman_device_get_service_type(device);
980 technology = technology_find(type);
981 if (technology == NULL) {
982 techless_device_list = g_slist_remove(techless_device_list,
987 technology->device_list = g_slist_remove(technology->device_list,
992 static void powered_changed(struct connman_technology *technology)
994 connman_bool_t powered;
996 __sync_synchronize();
997 if (technology->enabled >0)
1002 connman_dbus_property_changed_basic(technology->path,
1003 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
1004 DBUS_TYPE_BOOLEAN, &powered);
1007 int __connman_technology_enabled(enum connman_service_type type)
1009 struct connman_technology *technology;
1011 technology = technology_find(type);
1012 if (technology == NULL)
1015 if (__sync_fetch_and_add(&technology->enabled, 1) == 0)
1016 powered_changed(technology);
1018 if (technology->pending_reply != NULL) {
1019 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1020 dbus_message_unref(technology->pending_reply);
1021 g_source_remove(technology->pending_timeout);
1022 technology->pending_reply = NULL;
1023 technology->pending_timeout = 0;
1029 int __connman_technology_disabled(enum connman_service_type type)
1031 struct connman_technology *technology;
1033 technology = technology_find(type);
1034 if (technology == NULL)
1037 if (technology->pending_reply != NULL) {
1038 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1039 dbus_message_unref(technology->pending_reply);
1040 g_source_remove(technology->pending_timeout);
1041 technology->pending_reply = NULL;
1042 technology->pending_timeout = 0;
1045 if (__sync_fetch_and_sub(&technology->enabled, 1) == 1)
1046 powered_changed(technology);
1051 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1056 if (global_offlinemode == offlinemode)
1059 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1062 * This is a bit tricky. When you set offlinemode, there is no
1063 * way to differentiate between attempting offline mode and
1064 * resuming offlinemode from last saved profile. We need that
1065 * information in rfkill_update, otherwise it falls back on the
1066 * technology's persistent state. Hence we set the offline mode here
1067 * but save it & call the notifier only if its successful.
1070 global_offlinemode = offlinemode;
1072 /* Traverse technology list, enable/disable each technology. */
1073 for (list = technology_list; list; list = list->next) {
1074 struct connman_technology *technology = list->data;
1077 err = technology_disable(technology, NULL);
1079 if (!offlinemode && technology->enable_persistent)
1080 err = technology_enable(technology, NULL);
1083 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1084 connman_technology_save_offlinemode();
1085 __connman_notifier_offlinemode(offlinemode);
1087 global_offlinemode = connman_technology_load_offlinemode();
1092 void __connman_technology_set_connected(enum connman_service_type type,
1093 connman_bool_t connected)
1095 struct connman_technology *technology;
1097 technology = technology_find(type);
1098 if (technology == NULL)
1101 DBG("technology %p connected %d", technology, connected);
1103 technology->connected = connected;
1105 connman_dbus_property_changed_basic(technology->path,
1106 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
1107 DBUS_TYPE_BOOLEAN, &connected);
1110 int __connman_technology_add_rfkill(unsigned int index,
1111 enum connman_service_type type,
1112 connman_bool_t softblock,
1113 connman_bool_t hardblock)
1115 struct connman_technology *technology;
1116 struct connman_rfkill *rfkill;
1118 DBG("index %u type %d soft %u hard %u", index, type,
1119 softblock, hardblock);
1121 rfkill = g_hash_table_lookup(rfkill_list, &index);
1125 rfkill = g_try_new0(struct connman_rfkill, 1);
1129 rfkill->index = index;
1130 rfkill->type = type;
1131 rfkill->softblock = softblock;
1132 rfkill->hardblock = hardblock;
1134 g_hash_table_insert(rfkill_list, &rfkill->index, rfkill);
1137 technology = technology_get(type);
1138 /* If there is no driver for this type, ignore it. */
1139 if (technology == NULL)
1143 DBG("%s is switched off.", get_name(type));
1148 * If Offline mode is on, we softblock the device if it isnt already.
1149 * If Offline mode is off, we rely on the persistent state of tech.
1151 if (global_offlinemode) {
1153 return __connman_rfkill_block(type, TRUE);
1155 if (technology->enable_persistent && softblock)
1156 return __connman_rfkill_block(type, FALSE);
1157 /* if technology persistent state is offline */
1158 if (!technology->enable_persistent && !softblock)
1159 return __connman_rfkill_block(type, TRUE);
1165 int __connman_technology_update_rfkill(unsigned int index,
1166 enum connman_service_type type,
1167 connman_bool_t softblock,
1168 connman_bool_t hardblock)
1170 struct connman_technology *technology;
1171 struct connman_rfkill *rfkill;
1173 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1175 rfkill = g_hash_table_lookup(rfkill_list, &index);
1179 if (rfkill->softblock == softblock &&
1180 rfkill->hardblock == hardblock)
1183 rfkill->softblock = softblock;
1184 rfkill->hardblock = hardblock;
1187 DBG("%s is switched off.", get_name(type));
1191 technology = technology_get(type);
1192 /* If there is no driver for this type, ignore it. */
1193 if (technology == NULL)
1196 if (!global_offlinemode) {
1197 if (technology->enable_persistent && softblock)
1198 return __connman_rfkill_block(type, FALSE);
1199 if (!technology->enable_persistent && !softblock)
1200 return __connman_rfkill_block(type, TRUE);
1206 int __connman_technology_remove_rfkill(unsigned int index,
1207 enum connman_service_type type)
1209 struct connman_technology *technology;
1210 struct connman_rfkill *rfkill;
1212 DBG("index %u", index);
1214 rfkill = g_hash_table_lookup(rfkill_list, &index);
1218 g_hash_table_remove(rfkill_list, &index);
1220 technology = technology_find(type);
1221 if (technology == NULL)
1224 technology_put(technology);
1229 int __connman_technology_init(void)
1233 connection = connman_dbus_get_connection();
1235 rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
1238 global_offlinemode = connman_technology_load_offlinemode();
1243 void __connman_technology_cleanup(void)
1247 g_hash_table_destroy(rfkill_list);
1249 dbus_connection_unref(connection);