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) {
790 __sync_fetch_and_add(&technology->refcount, 1);
794 /* First check if we have a driver for this technology type */
795 for (list = driver_list; list; list = list->next) {
798 if (driver->type == type)
804 if (driver == NULL) {
805 DBG("No matching driver found for %s.",
806 __connman_service_type2string(type));
810 technology = g_try_new0(struct connman_technology, 1);
811 if (technology == NULL)
814 technology->refcount = 1;
816 technology->type = type;
817 technology->path = g_strdup_printf("%s/technology/%s",
820 technology->device_list = NULL;
822 technology->pending_reply = NULL;
824 load_state(technology);
826 if (g_dbus_register_interface(connection, technology->path,
827 CONNMAN_TECHNOLOGY_INTERFACE,
828 technology_methods, technology_signals,
829 NULL, technology, NULL) == FALSE) {
830 connman_error("Failed to register %s", technology->path);
835 technology_list = g_slist_append(technology_list, technology);
837 technology_added_signal(technology);
839 technology->driver = driver;
840 err = driver->probe(technology);
842 DBG("Driver probe failed for technology %p", technology);
844 DBG("technology %p", technology);
849 static void technology_put(struct connman_technology *technology)
851 DBG("technology %p", technology);
853 if (__sync_fetch_and_sub(&technology->refcount, 1) > 0)
856 if (technology->driver) {
857 technology->driver->remove(technology);
858 technology->driver = NULL;
861 technology_list = g_slist_remove(technology_list, technology);
863 technology_removed_signal(technology);
865 g_dbus_unregister_interface(connection, technology->path,
866 CONNMAN_TECHNOLOGY_INTERFACE);
868 g_slist_free(technology->device_list);
870 g_free(technology->path);
871 g_free(technology->regdom);
875 void __connman_technology_add_interface(enum connman_service_type type,
876 int index, const char *name, const char *ident)
878 struct connman_technology *technology;
881 case CONNMAN_SERVICE_TYPE_UNKNOWN:
882 case CONNMAN_SERVICE_TYPE_SYSTEM:
884 case CONNMAN_SERVICE_TYPE_ETHERNET:
885 case CONNMAN_SERVICE_TYPE_WIFI:
886 case CONNMAN_SERVICE_TYPE_WIMAX:
887 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
888 case CONNMAN_SERVICE_TYPE_CELLULAR:
889 case CONNMAN_SERVICE_TYPE_GPS:
890 case CONNMAN_SERVICE_TYPE_VPN:
891 case CONNMAN_SERVICE_TYPE_GADGET:
895 connman_info("Adding interface %s [ %s ]", name,
896 __connman_service_type2string(type));
898 technology = technology_find(type);
900 if (technology == NULL || technology->driver == NULL
901 || technology->driver->add_interface == NULL)
904 technology->driver->add_interface(technology,
908 void __connman_technology_remove_interface(enum connman_service_type type,
909 int index, const char *name, const char *ident)
911 struct connman_technology *technology;
914 case CONNMAN_SERVICE_TYPE_UNKNOWN:
915 case CONNMAN_SERVICE_TYPE_SYSTEM:
917 case CONNMAN_SERVICE_TYPE_ETHERNET:
918 case CONNMAN_SERVICE_TYPE_WIFI:
919 case CONNMAN_SERVICE_TYPE_WIMAX:
920 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
921 case CONNMAN_SERVICE_TYPE_CELLULAR:
922 case CONNMAN_SERVICE_TYPE_GPS:
923 case CONNMAN_SERVICE_TYPE_VPN:
924 case CONNMAN_SERVICE_TYPE_GADGET:
928 connman_info("Remove interface %s [ %s ]", name,
929 __connman_service_type2string(type));
931 technology = technology_find(type);
933 if (technology == NULL || technology->driver == NULL)
936 if (technology->driver->remove_interface)
937 technology->driver->remove_interface(technology, index);
940 int __connman_technology_add_device(struct connman_device *device)
942 struct connman_technology *technology;
943 enum connman_service_type type;
945 DBG("device %p", device);
947 type = __connman_device_get_service_type(device);
949 technology = technology_get(type);
950 if (technology == NULL) {
952 * Since no driver can be found for this device at the moment we
953 * add it to the techless device list.
955 techless_device_list = g_slist_prepend(techless_device_list,
961 if (technology->enable_persistent && !global_offlinemode)
962 __connman_device_enable(device);
963 /* if technology persistent state is offline */
964 if (!technology->enable_persistent)
965 __connman_device_disable(device);
967 technology->device_list = g_slist_append(technology->device_list,
973 int __connman_technology_remove_device(struct connman_device *device)
975 struct connman_technology *technology;
976 enum connman_service_type type;
978 DBG("device %p", device);
980 type = __connman_device_get_service_type(device);
982 technology = technology_find(type);
983 if (technology == NULL) {
984 techless_device_list = g_slist_remove(techless_device_list,
989 technology->device_list = g_slist_remove(technology->device_list,
991 technology_put(technology);
996 static void powered_changed(struct connman_technology *technology)
998 connman_bool_t powered;
1000 __sync_synchronize();
1001 if (technology->enabled >0)
1006 connman_dbus_property_changed_basic(technology->path,
1007 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
1008 DBUS_TYPE_BOOLEAN, &powered);
1011 int __connman_technology_enabled(enum connman_service_type type)
1013 struct connman_technology *technology;
1015 technology = technology_find(type);
1016 if (technology == NULL)
1019 if (__sync_fetch_and_add(&technology->enabled, 1) == 0)
1020 powered_changed(technology);
1022 if (technology->pending_reply != NULL) {
1023 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1024 dbus_message_unref(technology->pending_reply);
1025 g_source_remove(technology->pending_timeout);
1026 technology->pending_reply = NULL;
1027 technology->pending_timeout = 0;
1033 int __connman_technology_disabled(enum connman_service_type type)
1035 struct connman_technology *technology;
1037 technology = technology_find(type);
1038 if (technology == NULL)
1041 if (technology->pending_reply != NULL) {
1042 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1043 dbus_message_unref(technology->pending_reply);
1044 g_source_remove(technology->pending_timeout);
1045 technology->pending_reply = NULL;
1046 technology->pending_timeout = 0;
1049 if (__sync_fetch_and_sub(&technology->enabled, 1) == 1)
1050 powered_changed(technology);
1055 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1060 if (global_offlinemode == offlinemode)
1063 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1066 * This is a bit tricky. When you set offlinemode, there is no
1067 * way to differentiate between attempting offline mode and
1068 * resuming offlinemode from last saved profile. We need that
1069 * information in rfkill_update, otherwise it falls back on the
1070 * technology's persistent state. Hence we set the offline mode here
1071 * but save it & call the notifier only if its successful.
1074 global_offlinemode = offlinemode;
1076 /* Traverse technology list, enable/disable each technology. */
1077 for (list = technology_list; list; list = list->next) {
1078 struct connman_technology *technology = list->data;
1081 err = technology_disable(technology, NULL);
1083 if (!offlinemode && technology->enable_persistent)
1084 err = technology_enable(technology, NULL);
1087 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1088 connman_technology_save_offlinemode();
1089 __connman_notifier_offlinemode(offlinemode);
1091 global_offlinemode = connman_technology_load_offlinemode();
1096 void __connman_technology_set_connected(enum connman_service_type type,
1097 connman_bool_t connected)
1099 struct connman_technology *technology;
1101 technology = technology_find(type);
1102 if (technology == NULL)
1105 DBG("technology %p connected %d", technology, connected);
1107 technology->connected = connected;
1109 connman_dbus_property_changed_basic(technology->path,
1110 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
1111 DBUS_TYPE_BOOLEAN, &connected);
1114 int __connman_technology_add_rfkill(unsigned int index,
1115 enum connman_service_type type,
1116 connman_bool_t softblock,
1117 connman_bool_t hardblock)
1119 struct connman_technology *technology;
1120 struct connman_rfkill *rfkill;
1122 DBG("index %u type %d soft %u hard %u", index, type,
1123 softblock, hardblock);
1125 rfkill = g_hash_table_lookup(rfkill_list, &index);
1129 rfkill = g_try_new0(struct connman_rfkill, 1);
1133 rfkill->index = index;
1134 rfkill->type = type;
1135 rfkill->softblock = softblock;
1136 rfkill->hardblock = hardblock;
1138 g_hash_table_insert(rfkill_list, &rfkill->index, rfkill);
1141 technology = technology_get(type);
1142 /* If there is no driver for this type, ignore it. */
1143 if (technology == NULL)
1147 DBG("%s is switched off.", get_name(type));
1152 * If Offline mode is on, we softblock the device if it isnt already.
1153 * If Offline mode is off, we rely on the persistent state of tech.
1155 if (global_offlinemode) {
1157 return __connman_rfkill_block(type, TRUE);
1159 if (technology->enable_persistent && softblock)
1160 return __connman_rfkill_block(type, FALSE);
1161 /* if technology persistent state is offline */
1162 if (!technology->enable_persistent && !softblock)
1163 return __connman_rfkill_block(type, TRUE);
1169 int __connman_technology_update_rfkill(unsigned int index,
1170 enum connman_service_type type,
1171 connman_bool_t softblock,
1172 connman_bool_t hardblock)
1174 struct connman_technology *technology;
1175 struct connman_rfkill *rfkill;
1177 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1179 rfkill = g_hash_table_lookup(rfkill_list, &index);
1183 if (rfkill->softblock == softblock &&
1184 rfkill->hardblock == hardblock)
1187 rfkill->softblock = softblock;
1188 rfkill->hardblock = hardblock;
1191 DBG("%s is switched off.", get_name(type));
1195 technology = technology_get(type);
1196 /* If there is no driver for this type, ignore it. */
1197 if (technology == NULL)
1200 if (!global_offlinemode) {
1201 if (technology->enable_persistent && softblock)
1202 return __connman_rfkill_block(type, FALSE);
1203 if (!technology->enable_persistent && !softblock)
1204 return __connman_rfkill_block(type, TRUE);
1210 int __connman_technology_remove_rfkill(unsigned int index,
1211 enum connman_service_type type)
1213 struct connman_technology *technology;
1214 struct connman_rfkill *rfkill;
1216 DBG("index %u", index);
1218 rfkill = g_hash_table_lookup(rfkill_list, &index);
1222 g_hash_table_remove(rfkill_list, &index);
1224 technology = technology_find(type);
1225 if (technology == NULL)
1228 technology_put(technology);
1233 int __connman_technology_init(void)
1237 connection = connman_dbus_get_connection();
1239 rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
1242 global_offlinemode = connman_technology_load_offlinemode();
1247 void __connman_technology_cleanup(void)
1251 g_hash_table_destroy(rfkill_list);
1253 dbus_connection_unref(connection);