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;
37 static connman_bool_t global_offlinemode;
39 struct connman_rfkill {
41 enum connman_service_type type;
42 connman_bool_t softblock;
43 connman_bool_t hardblock;
46 enum connman_technology_state {
47 CONNMAN_TECHNOLOGY_STATE_UNKNOWN = 0,
48 CONNMAN_TECHNOLOGY_STATE_OFFLINE = 1,
49 CONNMAN_TECHNOLOGY_STATE_ENABLED = 2,
50 CONNMAN_TECHNOLOGY_STATE_CONNECTED = 3,
53 struct connman_technology {
55 enum connman_service_type type;
56 enum connman_technology_state state;
58 GHashTable *rfkill_list;
63 connman_bool_t tethering;
64 char *tethering_ident;
65 char *tethering_passphrase;
67 connman_bool_t enable_persistent; /* Save the tech state */
69 struct connman_technology_driver *driver;
72 DBusMessage *pending_reply;
73 guint pending_timeout;
76 static GSList *driver_list = NULL;
78 static gint compare_priority(gconstpointer a, gconstpointer b)
80 const struct connman_technology_driver *driver1 = a;
81 const struct connman_technology_driver *driver2 = b;
83 return driver2->priority - driver1->priority;
87 * connman_technology_driver_register:
88 * @driver: Technology driver definition
90 * Register a new technology driver
92 * Returns: %0 on success
94 int connman_technology_driver_register(struct connman_technology_driver *driver)
97 struct connman_technology *technology;
99 DBG("driver %p name %s", driver, driver->name);
101 driver_list = g_slist_insert_sorted(driver_list, driver,
104 for (list = technology_list; list; list = list->next) {
105 technology = list->data;
107 if (technology->driver != NULL)
110 if (technology->type == driver->type)
111 technology->driver = driver;
118 * connman_technology_driver_unregister:
119 * @driver: Technology driver definition
121 * Remove a previously registered technology driver
123 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
126 struct connman_technology *technology;
128 DBG("driver %p name %s", driver, driver->name);
130 for (list = technology_list; list; list = list->next) {
131 technology = list->data;
133 if (technology->driver == NULL)
136 if (technology->type == driver->type) {
137 technology->driver->remove(technology);
138 technology->driver = NULL;
142 driver_list = g_slist_remove(driver_list, driver);
145 static void tethering_changed(struct connman_technology *technology)
147 connman_bool_t tethering = technology->tethering;
149 connman_dbus_property_changed_basic(technology->path,
150 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
151 DBUS_TYPE_BOOLEAN, &tethering);
154 void connman_technology_tethering_notify(struct connman_technology *technology,
155 connman_bool_t enabled)
159 DBG("technology %p enabled %u", technology, enabled);
161 if (technology->tethering == enabled)
164 technology->tethering = enabled;
166 tethering_changed(technology);
169 __connman_tethering_set_enabled();
171 for (list = technology_list; list; list = list->next) {
172 struct connman_technology *other_tech = list->data;
173 if (other_tech->tethering == TRUE)
177 __connman_tethering_set_disabled();
181 static int set_tethering(struct connman_technology *technology,
182 connman_bool_t enabled)
184 const char *ident, *passphrase, *bridge;
186 ident = technology->tethering_ident;
187 passphrase = technology->tethering_passphrase;
189 if (technology->driver == NULL ||
190 technology->driver->set_tethering == NULL)
193 bridge = __connman_tethering_get_bridge();
197 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
198 (ident == NULL || passphrase == NULL))
201 return technology->driver->set_tethering(technology, ident, passphrase,
205 void connman_technology_regdom_notify(struct connman_technology *technology,
211 connman_error("Failed to set regulatory domain");
213 DBG("Regulatory domain set to %s", alpha2);
215 g_free(technology->regdom);
216 technology->regdom = g_strdup(alpha2);
219 int connman_technology_set_regdom(const char *alpha2)
223 for (list = technology_list; list; list = list->next) {
224 struct connman_technology *technology = list->data;
226 if (technology->driver == NULL)
229 if (technology->driver->set_regdom)
230 technology->driver->set_regdom(technology, alpha2);
236 static void free_rfkill(gpointer data)
238 struct connman_rfkill *rfkill = data;
243 static const char *state2string(enum connman_technology_state state)
246 case CONNMAN_TECHNOLOGY_STATE_UNKNOWN:
248 case CONNMAN_TECHNOLOGY_STATE_OFFLINE:
250 case CONNMAN_TECHNOLOGY_STATE_ENABLED:
252 case CONNMAN_TECHNOLOGY_STATE_CONNECTED:
259 static void state_changed(struct connman_technology *technology)
263 str = state2string(technology->state);
267 connman_dbus_property_changed_basic(technology->path,
268 CONNMAN_TECHNOLOGY_INTERFACE, "State",
269 DBUS_TYPE_STRING, &str);
272 static const char *get_name(enum connman_service_type type)
275 case CONNMAN_SERVICE_TYPE_UNKNOWN:
276 case CONNMAN_SERVICE_TYPE_SYSTEM:
277 case CONNMAN_SERVICE_TYPE_GPS:
278 case CONNMAN_SERVICE_TYPE_VPN:
279 case CONNMAN_SERVICE_TYPE_GADGET:
281 case CONNMAN_SERVICE_TYPE_ETHERNET:
283 case CONNMAN_SERVICE_TYPE_WIFI:
285 case CONNMAN_SERVICE_TYPE_WIMAX:
287 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
289 case CONNMAN_SERVICE_TYPE_CELLULAR:
296 static void load_state(struct connman_technology *technology)
300 GError *error = NULL;
301 connman_bool_t enable;
303 DBG("technology %p", technology);
305 keyfile = __connman_storage_load_global();
306 /* Fallback on disabling technology if file not found. */
307 if (keyfile == NULL) {
308 technology->enable_persistent = FALSE;
312 identifier = g_strdup_printf("%s", get_name(technology->type));
313 if (identifier == NULL)
316 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
318 technology->enable_persistent = enable;
320 technology->enable_persistent = FALSE;
321 g_clear_error(&error);
326 g_key_file_free(keyfile);
331 static void save_state(struct connman_technology *technology)
336 DBG("technology %p", technology);
338 keyfile = __connman_storage_load_global();
340 keyfile = g_key_file_new();
342 identifier = g_strdup_printf("%s", get_name(technology->type));
343 if (identifier == NULL)
346 g_key_file_set_boolean(keyfile, identifier, "Enable",
347 technology->enable_persistent);
352 __connman_storage_save_global(keyfile);
354 g_key_file_free(keyfile);
359 connman_bool_t __connman_technology_get_offlinemode(void)
361 return global_offlinemode;
364 static void connman_technology_save_offlinemode()
368 keyfile = __connman_storage_load_global();
370 keyfile = g_key_file_new();
372 g_key_file_set_boolean(keyfile, "global",
373 "OfflineMode", global_offlinemode);
375 __connman_storage_save_global(keyfile);
377 g_key_file_free(keyfile);
382 static connman_bool_t connman_technology_load_offlinemode()
385 GError *error = NULL;
386 connman_bool_t offlinemode;
388 /* If there is a error, we enable offlinemode */
389 keyfile = __connman_storage_load_global();
393 offlinemode = g_key_file_get_boolean(keyfile, "global",
394 "OfflineMode", &error);
397 g_clear_error(&error);
400 g_key_file_free(keyfile);
405 static void append_properties(DBusMessageIter *iter,
406 struct connman_technology *technology)
408 DBusMessageIter dict;
411 connman_dbus_dict_open(iter, &dict);
413 str = state2string(technology->state);
415 connman_dbus_dict_append_basic(&dict, "State",
416 DBUS_TYPE_STRING, &str);
418 str = get_name(technology->type);
420 connman_dbus_dict_append_basic(&dict, "Name",
421 DBUS_TYPE_STRING, &str);
423 str = __connman_service_type2string(technology->type);
425 connman_dbus_dict_append_basic(&dict, "Type",
426 DBUS_TYPE_STRING, &str);
428 connman_dbus_dict_append_basic(&dict, "Tethering",
430 &technology->tethering);
432 if (technology->tethering_ident != NULL)
433 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
435 &technology->tethering_ident);
437 if (technology->tethering_passphrase != NULL)
438 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
440 &technology->tethering_passphrase);
442 connman_dbus_dict_close(iter, &dict);
445 static void technology_added_signal(struct connman_technology *technology)
448 DBusMessageIter iter;
450 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
451 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
455 dbus_message_iter_init_append(signal, &iter);
456 append_properties(&iter, technology);
458 dbus_connection_send(connection, signal, NULL);
459 dbus_message_unref(signal);
462 static void technology_removed_signal(struct connman_technology *technology)
464 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
465 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
466 DBUS_TYPE_OBJECT_PATH, technology->path,
470 static DBusMessage *get_properties(DBusConnection *conn,
471 DBusMessage *message, void *user_data)
473 struct connman_technology *technology = user_data;
475 DBusMessageIter iter;
477 reply = dbus_message_new_method_return(message);
481 dbus_message_iter_init_append(reply, &iter);
482 append_properties(&iter, technology);
487 void __connman_technology_list_struct(DBusMessageIter *array)
490 DBusMessageIter entry;
492 for (list = technology_list; list; list = list->next) {
493 struct connman_technology *technology = list->data;
495 if (technology->path == NULL)
498 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
500 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
502 append_properties(&entry, technology);
503 dbus_message_iter_close_container(array, &entry);
507 static DBusMessage *set_property(DBusConnection *conn,
508 DBusMessage *msg, void *data)
510 struct connman_technology *technology = data;
511 DBusMessageIter iter, value;
515 DBG("conn %p", conn);
517 if (dbus_message_iter_init(msg, &iter) == FALSE)
518 return __connman_error_invalid_arguments(msg);
520 dbus_message_iter_get_basic(&iter, &name);
521 dbus_message_iter_next(&iter);
522 dbus_message_iter_recurse(&iter, &value);
524 type = dbus_message_iter_get_arg_type(&value);
526 DBG("property %s", name);
528 if (g_str_equal(name, "Tethering") == TRUE) {
530 connman_bool_t tethering;
532 if (type != DBUS_TYPE_BOOLEAN)
533 return __connman_error_invalid_arguments(msg);
535 dbus_message_iter_get_basic(&value, &tethering);
537 if (technology->tethering == tethering)
538 return __connman_error_in_progress(msg);
540 err = set_tethering(technology, tethering);
542 return __connman_error_failed(msg, -err);
544 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
547 dbus_message_iter_get_basic(&value, &str);
549 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
550 return __connman_error_not_supported(msg);
552 technology->tethering_ident = g_strdup(str);
553 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
556 dbus_message_iter_get_basic(&value, &str);
558 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
559 return __connman_error_not_supported(msg);
562 return __connman_error_invalid_arguments(msg);
564 technology->tethering_passphrase = g_strdup(str);
566 return __connman_error_invalid_property(msg);
568 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
571 static GDBusMethodTable technology_methods[] = {
572 { "GetProperties", "", "a{sv}", get_properties },
573 { "SetProperty", "sv", "", set_property },
577 static GDBusSignalTable technology_signals[] = {
578 { "PropertyChanged", "sv" },
582 static struct connman_technology *technology_find(enum connman_service_type type)
586 DBG("type %d", type);
588 for (list = technology_list; list; list = list->next) {
589 struct connman_technology *technology = list->data;
591 if (technology->type == type)
598 static struct connman_technology *technology_get(enum connman_service_type type)
600 struct connman_technology *technology;
604 DBG("type %d", type);
606 technology = technology_find(type);
607 if (technology != NULL) {
608 __sync_fetch_and_add(&technology->refcount, 1);
612 str = __connman_service_type2string(type);
616 technology = g_try_new0(struct connman_technology, 1);
617 if (technology == NULL)
620 technology->refcount = 1;
622 technology->type = type;
623 technology->path = g_strdup_printf("%s/technology/%s",
626 technology->rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
628 technology->device_list = NULL;
630 technology->pending_reply = NULL;
631 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
633 load_state(technology);
635 if (g_dbus_register_interface(connection, technology->path,
636 CONNMAN_TECHNOLOGY_INTERFACE,
637 technology_methods, technology_signals,
638 NULL, technology, NULL) == FALSE) {
639 connman_error("Failed to register %s", technology->path);
644 technology_list = g_slist_append(technology_list, technology);
646 technology_added_signal(technology);
648 if (technology->driver != NULL)
651 for (list = driver_list; list; list = list->next) {
652 struct connman_technology_driver *driver = list->data;
654 DBG("driver %p name %s", driver, driver->name);
656 if (driver->type != technology->type)
659 if (driver->probe(technology) == 0) {
660 technology->driver = driver;
666 DBG("technology %p", technology);
671 static void technology_put(struct connman_technology *technology)
673 DBG("technology %p", technology);
675 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
678 if (technology->driver) {
679 technology->driver->remove(technology);
680 technology->driver = NULL;
683 technology_list = g_slist_remove(technology_list, technology);
685 technology_removed_signal(technology);
687 g_dbus_unregister_interface(connection, technology->path,
688 CONNMAN_TECHNOLOGY_INTERFACE);
690 g_slist_free(technology->device_list);
691 g_hash_table_destroy(technology->rfkill_list);
693 g_free(technology->path);
694 g_free(technology->regdom);
698 void __connman_technology_add_interface(enum connman_service_type type,
699 int index, const char *name, const char *ident)
701 struct connman_technology *technology;
704 case CONNMAN_SERVICE_TYPE_UNKNOWN:
705 case CONNMAN_SERVICE_TYPE_SYSTEM:
707 case CONNMAN_SERVICE_TYPE_ETHERNET:
708 case CONNMAN_SERVICE_TYPE_WIFI:
709 case CONNMAN_SERVICE_TYPE_WIMAX:
710 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
711 case CONNMAN_SERVICE_TYPE_CELLULAR:
712 case CONNMAN_SERVICE_TYPE_GPS:
713 case CONNMAN_SERVICE_TYPE_VPN:
714 case CONNMAN_SERVICE_TYPE_GADGET:
718 connman_info("Adding interface %s [ %s ]", name,
719 __connman_service_type2string(type));
721 technology = technology_find(type);
723 if (technology == NULL || technology->driver == NULL
724 || technology->driver->add_interface == NULL)
727 technology->driver->add_interface(technology,
731 void __connman_technology_remove_interface(enum connman_service_type type,
732 int index, const char *name, const char *ident)
734 struct connman_technology *technology;
737 case CONNMAN_SERVICE_TYPE_UNKNOWN:
738 case CONNMAN_SERVICE_TYPE_SYSTEM:
740 case CONNMAN_SERVICE_TYPE_ETHERNET:
741 case CONNMAN_SERVICE_TYPE_WIFI:
742 case CONNMAN_SERVICE_TYPE_WIMAX:
743 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
744 case CONNMAN_SERVICE_TYPE_CELLULAR:
745 case CONNMAN_SERVICE_TYPE_GPS:
746 case CONNMAN_SERVICE_TYPE_VPN:
747 case CONNMAN_SERVICE_TYPE_GADGET:
751 connman_info("Remove interface %s [ %s ]", name,
752 __connman_service_type2string(type));
754 technology = technology_find(type);
756 if (technology == NULL || technology->driver == NULL)
759 if (technology->driver->remove_interface)
760 technology->driver->remove_interface(technology, index);
763 int __connman_technology_add_device(struct connman_device *device)
765 struct connman_technology *technology;
766 enum connman_service_type type;
768 DBG("device %p", device);
770 type = __connman_device_get_service_type(device);
771 __connman_notifier_register(type);
773 technology = technology_get(type);
774 if (technology == NULL)
777 if (technology->enable_persistent && !global_offlinemode)
778 __connman_device_enable(device);
779 /* if technology persistent state is offline */
780 if (!technology->enable_persistent)
781 __connman_device_disable(device);
783 technology->device_list = g_slist_append(technology->device_list,
789 int __connman_technology_remove_device(struct connman_device *device)
791 struct connman_technology *technology;
792 enum connman_service_type type;
794 DBG("device %p", device);
796 type = __connman_device_get_service_type(device);
797 __connman_notifier_unregister(type);
799 technology = technology_find(type);
800 if (technology == NULL)
803 technology->device_list = g_slist_remove(technology->device_list,
805 if (technology->device_list == NULL) {
806 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
807 state_changed(technology);
813 static gboolean technology_pending_reply(gpointer user_data)
815 struct connman_technology *technology = user_data;
818 /* Power request timedout, send ETIMEDOUT. */
819 if (technology->pending_reply != NULL) {
820 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
822 g_dbus_send_message(connection, reply);
824 dbus_message_unref(technology->pending_reply);
825 technology->pending_reply = NULL;
826 technology->pending_timeout = 0;
832 int __connman_technology_enabled(enum connman_service_type type)
834 struct connman_technology *technology;
836 technology = technology_find(type);
837 if (technology == NULL)
840 if (__sync_fetch_and_add(&technology->enabled, 1) == 0) {
841 __connman_notifier_enable(type);
842 technology->state = CONNMAN_TECHNOLOGY_STATE_ENABLED;
843 state_changed(technology);
846 if (technology->pending_reply != NULL) {
847 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
848 dbus_message_unref(technology->pending_reply);
849 g_source_remove(technology->pending_timeout);
850 technology->pending_reply = NULL;
851 technology->pending_timeout = 0;
857 int __connman_technology_enable(enum connman_service_type type, DBusMessage *msg)
859 struct connman_technology *technology;
865 DBG("type %d enable", type);
867 technology = technology_find(type);
868 if (technology == NULL) {
873 if (technology->pending_reply != NULL) {
880 * This is a bit of a trick. When msg is not NULL it means
881 * thats technology_enable was invoked from the manager API. Hence we save
884 technology->enable_persistent = TRUE;
885 save_state(technology);
888 __connman_rfkill_block(technology->type, FALSE);
891 * An empty device list means that devices in the technology
892 * were rfkill blocked. The unblock above will enable the devs.
894 if (technology->device_list == NULL) {
899 for (list = technology->device_list; list; list = list->next) {
900 struct connman_device *device = list->data;
902 err = __connman_device_enable(device);
904 * err = 0 : Device was enabled right away.
905 * If atleast one device gets enabled, we consider
906 * the technology to be enabled.
915 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
920 if (err == -EINPROGRESS) {
921 technology->pending_reply = dbus_message_ref(msg);
922 technology->pending_timeout = g_timeout_add_seconds(10,
923 technology_pending_reply, technology);
925 reply = __connman_error_failed(msg, -err);
927 g_dbus_send_message(connection, reply);
934 int __connman_technology_disabled(enum connman_service_type type)
936 struct connman_technology *technology;
938 technology = technology_find(type);
939 if (technology == NULL)
942 if (technology->pending_reply != NULL) {
943 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
944 dbus_message_unref(technology->pending_reply);
945 g_source_remove(technology->pending_timeout);
946 technology->pending_reply = NULL;
947 technology->pending_timeout = 0;
950 if (__sync_fetch_and_sub(&technology->enabled, 1) != 1)
953 __connman_notifier_disable(type);
954 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
955 state_changed(technology);
960 int __connman_technology_disable(enum connman_service_type type, DBusMessage *msg)
962 struct connman_technology *technology;
968 DBG("type %d disable", type);
970 technology = technology_find(type);
971 if (technology == NULL) {
976 if (technology->pending_reply != NULL) {
981 if (technology->tethering == TRUE)
982 set_tethering(technology, FALSE);
985 technology->enable_persistent = FALSE;
986 save_state(technology);
989 __connman_rfkill_block(technology->type, TRUE);
991 for (list = technology->device_list; list; list = list->next) {
992 struct connman_device *device = list->data;
994 err = __connman_device_disable(device);
1002 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
1007 if (err == -EINPROGRESS) {
1008 technology->pending_reply = dbus_message_ref(msg);
1009 technology->pending_timeout = g_timeout_add_seconds(10,
1010 technology_pending_reply, technology);
1012 reply = __connman_error_failed(msg, -err);
1014 g_dbus_send_message(connection, reply);
1021 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1026 if (global_offlinemode == offlinemode)
1029 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1032 * This is a bit tricky. When you set offlinemode, there is no
1033 * way to differentiate between attempting offline mode and
1034 * resuming offlinemode from last saved profile. We need that
1035 * information in rfkill_update, otherwise it falls back on the
1036 * technology's persistent state. Hence we set the offline mode here
1037 * but save it & call the notifier only if its successful.
1040 global_offlinemode = offlinemode;
1042 /* Traverse technology list, enable/disable each technology. */
1043 for (list = technology_list; list; list = list->next) {
1044 struct connman_technology *technology = list->data;
1047 err = __connman_technology_disable(technology->type, NULL);
1049 if (!offlinemode && technology->enable_persistent)
1050 err = __connman_technology_enable(technology->type, NULL);
1053 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1054 connman_technology_save_offlinemode();
1055 __connman_notifier_offlinemode(offlinemode);
1057 global_offlinemode = connman_technology_load_offlinemode();
1062 int __connman_technology_add_rfkill(unsigned int index,
1063 enum connman_service_type type,
1064 connman_bool_t softblock,
1065 connman_bool_t hardblock)
1067 struct connman_technology *technology;
1068 struct connman_rfkill *rfkill;
1070 DBG("index %u type %d soft %u hard %u", index, type,
1071 softblock, hardblock);
1073 technology = technology_get(type);
1074 if (technology == NULL)
1077 rfkill = g_try_new0(struct connman_rfkill, 1);
1081 __connman_notifier_register(type);
1083 rfkill->index = index;
1084 rfkill->type = type;
1085 rfkill->softblock = softblock;
1086 rfkill->hardblock = hardblock;
1088 g_hash_table_replace(technology->rfkill_list, &rfkill->index, rfkill);
1091 DBG("%s is switched off.", get_name(type));
1096 * If Offline mode is on, we softblock the device if it isnt already.
1097 * If Offline mode is off, we rely on the persistent state of tech.
1099 if (global_offlinemode) {
1101 return __connman_rfkill_block(type, TRUE);
1103 if (technology->enable_persistent && softblock)
1104 return __connman_rfkill_block(type, FALSE);
1105 /* if technology persistent state is offline */
1106 if (!technology->enable_persistent && !softblock)
1107 return __connman_rfkill_block(type, TRUE);
1113 int __connman_technology_update_rfkill(unsigned int index,
1114 enum connman_service_type type,
1115 connman_bool_t softblock,
1116 connman_bool_t hardblock)
1118 struct connman_technology *technology;
1119 struct connman_rfkill *rfkill;
1121 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1123 technology = technology_find(type);
1124 if (technology == NULL)
1127 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1131 if (rfkill->softblock == softblock &&
1132 rfkill->hardblock == hardblock)
1135 rfkill->softblock = softblock;
1136 rfkill->hardblock = hardblock;
1139 DBG("%s is switched off.", get_name(type));
1143 if (!global_offlinemode) {
1144 if (technology->enable_persistent && softblock)
1145 return __connman_rfkill_block(type, FALSE);
1146 if (!technology->enable_persistent && !softblock)
1147 return __connman_rfkill_block(type, TRUE);
1153 int __connman_technology_remove_rfkill(unsigned int index,
1154 enum connman_service_type type)
1156 struct connman_technology *technology;
1157 struct connman_rfkill *rfkill;
1159 DBG("index %u", index);
1161 technology = technology_find(type);
1162 if (technology == NULL)
1165 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1169 g_hash_table_remove(technology->rfkill_list, &index);
1171 technology_put(technology);
1176 int __connman_technology_init(void)
1180 connection = connman_dbus_get_connection();
1182 global_offlinemode = connman_technology_load_offlinemode();
1187 void __connman_technology_cleanup(void)
1191 dbus_connection_unref(connection);