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);
469 static DBusMessage *get_properties(DBusConnection *conn,
470 DBusMessage *message, void *user_data)
472 struct connman_technology *technology = user_data;
474 DBusMessageIter iter;
476 reply = dbus_message_new_method_return(message);
480 dbus_message_iter_init_append(reply, &iter);
481 append_properties(&iter, technology);
486 void __connman_technology_list_struct(DBusMessageIter *array)
489 DBusMessageIter entry;
491 for (list = technology_list; list; list = list->next) {
492 struct connman_technology *technology = list->data;
494 if (technology->path == NULL)
497 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
499 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
501 append_properties(&entry, technology);
502 dbus_message_iter_close_container(array, &entry);
506 static DBusMessage *set_property(DBusConnection *conn,
507 DBusMessage *msg, void *data)
509 struct connman_technology *technology = data;
510 DBusMessageIter iter, value;
514 DBG("conn %p", conn);
516 if (dbus_message_iter_init(msg, &iter) == FALSE)
517 return __connman_error_invalid_arguments(msg);
519 dbus_message_iter_get_basic(&iter, &name);
520 dbus_message_iter_next(&iter);
521 dbus_message_iter_recurse(&iter, &value);
523 type = dbus_message_iter_get_arg_type(&value);
525 DBG("property %s", name);
527 if (g_str_equal(name, "Tethering") == TRUE) {
529 connman_bool_t tethering;
531 if (type != DBUS_TYPE_BOOLEAN)
532 return __connman_error_invalid_arguments(msg);
534 dbus_message_iter_get_basic(&value, &tethering);
536 if (technology->tethering == tethering)
537 return __connman_error_in_progress(msg);
539 err = set_tethering(technology, tethering);
541 return __connman_error_failed(msg, -err);
543 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
546 dbus_message_iter_get_basic(&value, &str);
548 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
549 return __connman_error_not_supported(msg);
551 technology->tethering_ident = g_strdup(str);
552 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
555 dbus_message_iter_get_basic(&value, &str);
557 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
558 return __connman_error_not_supported(msg);
561 return __connman_error_invalid_arguments(msg);
563 technology->tethering_passphrase = g_strdup(str);
565 return __connman_error_invalid_property(msg);
567 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
570 static GDBusMethodTable technology_methods[] = {
571 { "GetProperties", "", "a{sv}", get_properties },
572 { "SetProperty", "sv", "", set_property },
576 static GDBusSignalTable technology_signals[] = {
577 { "PropertyChanged", "sv" },
581 static struct connman_technology *technology_find(enum connman_service_type type)
585 DBG("type %d", type);
587 for (list = technology_list; list; list = list->next) {
588 struct connman_technology *technology = list->data;
590 if (technology->type == type)
597 static struct connman_technology *technology_get(enum connman_service_type type)
599 struct connman_technology *technology;
603 DBG("type %d", type);
605 technology = technology_find(type);
606 if (technology != NULL) {
607 __sync_fetch_and_add(&technology->refcount, 1);
611 str = __connman_service_type2string(type);
615 technology = g_try_new0(struct connman_technology, 1);
616 if (technology == NULL)
619 technology->refcount = 1;
621 technology->type = type;
622 technology->path = g_strdup_printf("%s/technology/%s",
625 technology->rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
627 technology->device_list = NULL;
629 technology->pending_reply = NULL;
630 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
632 load_state(technology);
634 if (g_dbus_register_interface(connection, technology->path,
635 CONNMAN_TECHNOLOGY_INTERFACE,
636 technology_methods, technology_signals,
637 NULL, technology, NULL) == FALSE) {
638 connman_error("Failed to register %s", technology->path);
643 technology_list = g_slist_append(technology_list, technology);
645 technology_added_signal(technology);
647 if (technology->driver != NULL)
650 for (list = driver_list; list; list = list->next) {
651 struct connman_technology_driver *driver = list->data;
653 DBG("driver %p name %s", driver, driver->name);
655 if (driver->type != technology->type)
658 if (driver->probe(technology) == 0) {
659 technology->driver = driver;
665 DBG("technology %p", technology);
670 static void technology_put(struct connman_technology *technology)
672 DBG("technology %p", technology);
674 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
677 if (technology->driver) {
678 technology->driver->remove(technology);
679 technology->driver = NULL;
682 technology_list = g_slist_remove(technology_list, technology);
684 technology_removed_signal(technology);
686 g_dbus_unregister_interface(connection, technology->path,
687 CONNMAN_TECHNOLOGY_INTERFACE);
689 g_slist_free(technology->device_list);
690 g_hash_table_destroy(technology->rfkill_list);
692 g_free(technology->path);
693 g_free(technology->regdom);
697 void __connman_technology_add_interface(enum connman_service_type type,
698 int index, const char *name, const char *ident)
700 struct connman_technology *technology;
703 case CONNMAN_SERVICE_TYPE_UNKNOWN:
704 case CONNMAN_SERVICE_TYPE_SYSTEM:
706 case CONNMAN_SERVICE_TYPE_ETHERNET:
707 case CONNMAN_SERVICE_TYPE_WIFI:
708 case CONNMAN_SERVICE_TYPE_WIMAX:
709 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
710 case CONNMAN_SERVICE_TYPE_CELLULAR:
711 case CONNMAN_SERVICE_TYPE_GPS:
712 case CONNMAN_SERVICE_TYPE_VPN:
713 case CONNMAN_SERVICE_TYPE_GADGET:
717 connman_info("Create interface %s [ %s ]", name,
718 __connman_service_type2string(type));
720 technology = technology_get(type);
722 if (technology == NULL || technology->driver == NULL
723 || technology->driver->add_interface == NULL)
726 technology->driver->add_interface(technology,
730 void __connman_technology_remove_interface(enum connman_service_type type,
731 int index, const char *name, const char *ident)
733 struct connman_technology *technology;
736 case CONNMAN_SERVICE_TYPE_UNKNOWN:
737 case CONNMAN_SERVICE_TYPE_SYSTEM:
739 case CONNMAN_SERVICE_TYPE_ETHERNET:
740 case CONNMAN_SERVICE_TYPE_WIFI:
741 case CONNMAN_SERVICE_TYPE_WIMAX:
742 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
743 case CONNMAN_SERVICE_TYPE_CELLULAR:
744 case CONNMAN_SERVICE_TYPE_GPS:
745 case CONNMAN_SERVICE_TYPE_VPN:
746 case CONNMAN_SERVICE_TYPE_GADGET:
750 connman_info("Remove interface %s [ %s ]", name,
751 __connman_service_type2string(type));
753 technology = technology_find(type);
755 if (technology == NULL || technology->driver == NULL)
758 if (technology->driver->remove_interface)
759 technology->driver->remove_interface(technology, index);
761 technology_put(technology);
764 int __connman_technology_add_device(struct connman_device *device)
766 struct connman_technology *technology;
767 enum connman_service_type type;
769 DBG("device %p", device);
771 type = __connman_device_get_service_type(device);
772 __connman_notifier_register(type);
774 technology = technology_get(type);
775 if (technology == NULL)
778 if (technology->enable_persistent && !global_offlinemode)
779 __connman_device_enable(device);
780 /* if technology persistent state is offline */
781 if (!technology->enable_persistent)
782 __connman_device_disable(device);
784 technology->device_list = g_slist_append(technology->device_list,
790 int __connman_technology_remove_device(struct connman_device *device)
792 struct connman_technology *technology;
793 enum connman_service_type type;
795 DBG("device %p", device);
797 type = __connman_device_get_service_type(device);
798 __connman_notifier_unregister(type);
800 technology = technology_find(type);
801 if (technology == NULL)
804 technology->device_list = g_slist_remove(technology->device_list,
806 if (technology->device_list == NULL) {
807 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
808 state_changed(technology);
814 static gboolean technology_pending_reply(gpointer user_data)
816 struct connman_technology *technology = user_data;
819 /* Power request timedout, send ETIMEDOUT. */
820 if (technology->pending_reply != NULL) {
821 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
823 g_dbus_send_message(connection, reply);
825 dbus_message_unref(technology->pending_reply);
826 technology->pending_reply = NULL;
827 technology->pending_timeout = 0;
833 int __connman_technology_enabled(enum connman_service_type type)
835 struct connman_technology *technology;
837 technology = technology_find(type);
838 if (technology == NULL)
841 if (__sync_fetch_and_add(&technology->enabled, 1) == 0) {
842 __connman_notifier_enable(type);
843 technology->state = CONNMAN_TECHNOLOGY_STATE_ENABLED;
844 state_changed(technology);
847 if (technology->pending_reply != NULL) {
848 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
849 dbus_message_unref(technology->pending_reply);
850 g_source_remove(technology->pending_timeout);
851 technology->pending_reply = NULL;
852 technology->pending_timeout = 0;
858 int __connman_technology_enable(enum connman_service_type type, DBusMessage *msg)
860 struct connman_technology *technology;
866 DBG("type %d enable", type);
868 technology = technology_find(type);
869 if (technology == NULL) {
874 if (technology->pending_reply != NULL) {
881 * This is a bit of a trick. When msg is not NULL it means
882 * thats technology_enable was invoked from the manager API. Hence we save
885 technology->enable_persistent = TRUE;
886 save_state(technology);
889 __connman_rfkill_block(technology->type, FALSE);
892 * An empty device list means that devices in the technology
893 * were rfkill blocked. The unblock above will enable the devs.
895 if (technology->device_list == NULL)
898 for (list = technology->device_list; list; list = list->next) {
899 struct connman_device *device = list->data;
901 err = __connman_device_enable(device);
903 * err = 0 : Device was enabled right away.
904 * If atleast one device gets enabled, we consider
905 * the technology to be enabled.
914 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
919 if (err == -EINPROGRESS) {
920 technology->pending_reply = dbus_message_ref(msg);
921 technology->pending_timeout = g_timeout_add_seconds(10,
922 technology_pending_reply, technology);
924 reply = __connman_error_failed(msg, -err);
926 g_dbus_send_message(connection, reply);
933 int __connman_technology_disabled(enum connman_service_type type)
935 struct connman_technology *technology;
937 technology = technology_find(type);
938 if (technology == NULL)
941 if (technology->pending_reply != NULL) {
942 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
943 dbus_message_unref(technology->pending_reply);
944 g_source_remove(technology->pending_timeout);
945 technology->pending_reply = NULL;
946 technology->pending_timeout = 0;
949 if (__sync_fetch_and_sub(&technology->enabled, 1) != 1)
952 __connman_notifier_disable(type);
953 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
954 state_changed(technology);
959 int __connman_technology_disable(enum connman_service_type type, DBusMessage *msg)
961 struct connman_technology *technology;
967 DBG("type %d disable", type);
969 technology = technology_find(type);
970 if (technology == NULL) {
975 if (technology->pending_reply != NULL) {
980 if (technology->tethering == TRUE)
981 set_tethering(technology, FALSE);
984 technology->enable_persistent = FALSE;
985 save_state(technology);
988 __connman_rfkill_block(technology->type, TRUE);
990 for (list = technology->device_list; list; list = list->next) {
991 struct connman_device *device = list->data;
993 err = __connman_device_disable(device);
1001 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
1006 if (err == -EINPROGRESS) {
1007 technology->pending_reply = dbus_message_ref(msg);
1008 technology->pending_timeout = g_timeout_add_seconds(10,
1009 technology_pending_reply, technology);
1011 reply = __connman_error_failed(msg, -err);
1013 g_dbus_send_message(connection, reply);
1020 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1025 if (global_offlinemode == offlinemode)
1028 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1031 * This is a bit tricky. When you set offlinemode, there is no
1032 * way to differentiate between attempting offline mode and
1033 * resuming offlinemode from last saved profile. We need that
1034 * information in rfkill_update, otherwise it falls back on the
1035 * technology's persistent state. Hence we set the offline mode here
1036 * but save it & call the notifier only if its successful.
1039 global_offlinemode = offlinemode;
1041 /* Traverse technology list, enable/disable each technology. */
1042 for (list = technology_list; list; list = list->next) {
1043 struct connman_technology *technology = list->data;
1046 err = __connman_technology_disable(technology->type, NULL);
1048 if (!offlinemode && technology->enable_persistent)
1049 err = __connman_technology_enable(technology->type, NULL);
1052 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1053 connman_technology_save_offlinemode();
1054 __connman_notifier_offlinemode(offlinemode);
1056 global_offlinemode = connman_technology_load_offlinemode();
1061 int __connman_technology_add_rfkill(unsigned int index,
1062 enum connman_service_type type,
1063 connman_bool_t softblock,
1064 connman_bool_t hardblock)
1066 struct connman_technology *technology;
1067 struct connman_rfkill *rfkill;
1069 DBG("index %u type %d soft %u hard %u", index, type,
1070 softblock, hardblock);
1072 technology = technology_get(type);
1073 if (technology == NULL)
1076 rfkill = g_try_new0(struct connman_rfkill, 1);
1080 __connman_notifier_register(type);
1082 rfkill->index = index;
1083 rfkill->type = type;
1084 rfkill->softblock = softblock;
1085 rfkill->hardblock = hardblock;
1087 g_hash_table_replace(technology->rfkill_list, &rfkill->index, rfkill);
1090 DBG("%s is switched off.", get_name(type));
1095 * If Offline mode is on, we softblock the device if it isnt already.
1096 * If Offline mode is off, we rely on the persistent state of tech.
1098 if (global_offlinemode) {
1100 return __connman_rfkill_block(type, TRUE);
1102 if (technology->enable_persistent && softblock)
1103 return __connman_rfkill_block(type, FALSE);
1104 /* if technology persistent state is offline */
1105 if (!technology->enable_persistent && !softblock)
1106 return __connman_rfkill_block(type, TRUE);
1112 int __connman_technology_update_rfkill(unsigned int index,
1113 enum connman_service_type type,
1114 connman_bool_t softblock,
1115 connman_bool_t hardblock)
1117 struct connman_technology *technology;
1118 struct connman_rfkill *rfkill;
1120 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1122 technology = technology_find(type);
1123 if (technology == NULL)
1126 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1130 if (rfkill->softblock == softblock &&
1131 rfkill->hardblock == hardblock)
1134 rfkill->softblock = softblock;
1135 rfkill->hardblock = hardblock;
1138 DBG("%s is switched off.", get_name(type));
1142 if (!global_offlinemode) {
1143 if (technology->enable_persistent && softblock)
1144 return __connman_rfkill_block(type, FALSE);
1145 if (!technology->enable_persistent && !softblock)
1146 return __connman_rfkill_block(type, TRUE);
1152 int __connman_technology_remove_rfkill(unsigned int index,
1153 enum connman_service_type type)
1155 struct connman_technology *technology;
1156 struct connman_rfkill *rfkill;
1158 DBG("index %u", index);
1160 technology = technology_find(type);
1161 if (technology == NULL)
1164 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1168 g_hash_table_remove(technology->rfkill_list, &index);
1170 technology_put(technology);
1175 int __connman_technology_init(void)
1179 connection = connman_dbus_get_connection();
1181 global_offlinemode = connman_technology_load_offlinemode();
1186 void __connman_technology_cleanup(void)
1190 dbus_connection_unref(connection);