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 struct connman_technology {
48 enum connman_service_type type;
50 GHashTable *rfkill_list;
54 connman_bool_t connected;
56 connman_bool_t tethering;
57 char *tethering_ident;
58 char *tethering_passphrase;
60 connman_bool_t enable_persistent; /* Save the tech state */
62 struct connman_technology_driver *driver;
65 DBusMessage *pending_reply;
66 guint pending_timeout;
69 static GSList *driver_list = NULL;
71 static gint compare_priority(gconstpointer a, gconstpointer b)
73 const struct connman_technology_driver *driver1 = a;
74 const struct connman_technology_driver *driver2 = b;
76 return driver2->priority - driver1->priority;
80 * connman_technology_driver_register:
81 * @driver: Technology driver definition
83 * Register a new technology driver
85 * Returns: %0 on success
87 int connman_technology_driver_register(struct connman_technology_driver *driver)
89 DBG("Registering %s driver", driver->name);
91 driver_list = g_slist_insert_sorted(driver_list, driver,
98 * connman_technology_driver_unregister:
99 * @driver: Technology driver definition
101 * Remove a previously registered technology driver
103 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
106 struct connman_technology *technology;
108 DBG("Unregistering driver %p name %s", driver, driver->name);
110 for (list = technology_list; list; list = list->next) {
111 technology = list->data;
113 if (technology->driver == NULL)
116 if (technology->type == driver->type) {
117 technology->driver->remove(technology);
118 technology->driver = NULL;
122 driver_list = g_slist_remove(driver_list, driver);
125 static void tethering_changed(struct connman_technology *technology)
127 connman_bool_t tethering = technology->tethering;
129 connman_dbus_property_changed_basic(technology->path,
130 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
131 DBUS_TYPE_BOOLEAN, &tethering);
134 void connman_technology_tethering_notify(struct connman_technology *technology,
135 connman_bool_t enabled)
139 DBG("technology %p enabled %u", technology, enabled);
141 if (technology->tethering == enabled)
144 technology->tethering = enabled;
146 tethering_changed(technology);
149 __connman_tethering_set_enabled();
151 for (list = technology_list; list; list = list->next) {
152 struct connman_technology *other_tech = list->data;
153 if (other_tech->tethering == TRUE)
157 __connman_tethering_set_disabled();
161 static int set_tethering(struct connman_technology *technology,
162 connman_bool_t enabled)
164 const char *ident, *passphrase, *bridge;
166 ident = technology->tethering_ident;
167 passphrase = technology->tethering_passphrase;
169 if (technology->driver == NULL ||
170 technology->driver->set_tethering == NULL)
173 bridge = __connman_tethering_get_bridge();
177 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
178 (ident == NULL || passphrase == NULL))
181 return technology->driver->set_tethering(technology, ident, passphrase,
185 void connman_technology_regdom_notify(struct connman_technology *technology,
191 connman_error("Failed to set regulatory domain");
193 DBG("Regulatory domain set to %s", alpha2);
195 g_free(technology->regdom);
196 technology->regdom = g_strdup(alpha2);
199 int connman_technology_set_regdom(const char *alpha2)
203 for (list = technology_list; list; list = list->next) {
204 struct connman_technology *technology = list->data;
206 if (technology->driver == NULL)
209 if (technology->driver->set_regdom)
210 technology->driver->set_regdom(technology, alpha2);
216 static void free_rfkill(gpointer data)
218 struct connman_rfkill *rfkill = data;
223 static const char *get_name(enum connman_service_type type)
226 case CONNMAN_SERVICE_TYPE_UNKNOWN:
227 case CONNMAN_SERVICE_TYPE_SYSTEM:
228 case CONNMAN_SERVICE_TYPE_GPS:
229 case CONNMAN_SERVICE_TYPE_VPN:
230 case CONNMAN_SERVICE_TYPE_GADGET:
232 case CONNMAN_SERVICE_TYPE_ETHERNET:
234 case CONNMAN_SERVICE_TYPE_WIFI:
236 case CONNMAN_SERVICE_TYPE_WIMAX:
238 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
240 case CONNMAN_SERVICE_TYPE_CELLULAR:
247 static void load_state(struct connman_technology *technology)
251 GError *error = NULL;
252 connman_bool_t enable;
254 DBG("technology %p", technology);
256 keyfile = __connman_storage_load_global();
257 /* Fallback on disabling technology if file not found. */
258 if (keyfile == NULL) {
259 technology->enable_persistent = FALSE;
263 identifier = g_strdup_printf("%s", get_name(technology->type));
264 if (identifier == NULL)
267 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
269 technology->enable_persistent = enable;
271 technology->enable_persistent = FALSE;
272 g_clear_error(&error);
277 g_key_file_free(keyfile);
282 static void save_state(struct connman_technology *technology)
287 DBG("technology %p", technology);
289 keyfile = __connman_storage_load_global();
291 keyfile = g_key_file_new();
293 identifier = g_strdup_printf("%s", get_name(technology->type));
294 if (identifier == NULL)
297 g_key_file_set_boolean(keyfile, identifier, "Enable",
298 technology->enable_persistent);
303 __connman_storage_save_global(keyfile);
305 g_key_file_free(keyfile);
310 connman_bool_t __connman_technology_get_offlinemode(void)
312 return global_offlinemode;
315 static void connman_technology_save_offlinemode()
319 keyfile = __connman_storage_load_global();
321 keyfile = g_key_file_new();
323 g_key_file_set_boolean(keyfile, "global",
324 "OfflineMode", global_offlinemode);
326 __connman_storage_save_global(keyfile);
328 g_key_file_free(keyfile);
333 static connman_bool_t connman_technology_load_offlinemode()
336 GError *error = NULL;
337 connman_bool_t offlinemode;
339 /* If there is a error, we enable offlinemode */
340 keyfile = __connman_storage_load_global();
344 offlinemode = g_key_file_get_boolean(keyfile, "global",
345 "OfflineMode", &error);
348 g_clear_error(&error);
351 g_key_file_free(keyfile);
356 static void append_properties(DBusMessageIter *iter,
357 struct connman_technology *technology)
359 DBusMessageIter dict;
361 connman_bool_t powered;
363 connman_dbus_dict_open(iter, &dict);
365 str = get_name(technology->type);
367 connman_dbus_dict_append_basic(&dict, "Name",
368 DBUS_TYPE_STRING, &str);
370 str = __connman_service_type2string(technology->type);
372 connman_dbus_dict_append_basic(&dict, "Type",
373 DBUS_TYPE_STRING, &str);
375 __sync_synchronize();
376 if (technology->enabled > 0)
380 connman_dbus_dict_append_basic(&dict, "Powered",
381 DBUS_TYPE_BOOLEAN, &powered);
383 connman_dbus_dict_append_basic(&dict, "Connected",
385 &technology->connected);
387 connman_dbus_dict_append_basic(&dict, "Tethering",
389 &technology->tethering);
391 if (technology->tethering_ident != NULL)
392 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
394 &technology->tethering_ident);
396 if (technology->tethering_passphrase != NULL)
397 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
399 &technology->tethering_passphrase);
401 connman_dbus_dict_close(iter, &dict);
404 static void technology_added_signal(struct connman_technology *technology)
407 DBusMessageIter iter;
409 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
410 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
414 dbus_message_iter_init_append(signal, &iter);
415 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
417 append_properties(&iter, technology);
419 dbus_connection_send(connection, signal, NULL);
420 dbus_message_unref(signal);
423 static void technology_removed_signal(struct connman_technology *technology)
425 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
426 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
427 DBUS_TYPE_OBJECT_PATH, &technology->path,
431 static DBusMessage *get_properties(DBusConnection *conn,
432 DBusMessage *message, void *user_data)
434 struct connman_technology *technology = user_data;
436 DBusMessageIter iter;
438 reply = dbus_message_new_method_return(message);
442 dbus_message_iter_init_append(reply, &iter);
443 append_properties(&iter, technology);
448 void __connman_technology_list_struct(DBusMessageIter *array)
451 DBusMessageIter entry;
453 for (list = technology_list; list; list = list->next) {
454 struct connman_technology *technology = list->data;
456 if (technology->path == NULL)
459 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
461 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
463 append_properties(&entry, technology);
464 dbus_message_iter_close_container(array, &entry);
468 static gboolean technology_pending_reply(gpointer user_data)
470 struct connman_technology *technology = user_data;
473 /* Power request timedout, send ETIMEDOUT. */
474 if (technology->pending_reply != NULL) {
475 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
477 g_dbus_send_message(connection, reply);
479 dbus_message_unref(technology->pending_reply);
480 technology->pending_reply = NULL;
481 technology->pending_timeout = 0;
487 static int technology_enable(struct connman_technology *technology,
495 DBG("technology %p enable", technology);
497 __sync_synchronize();
498 if (technology->enabled > 0) {
503 if (technology->pending_reply != NULL) {
510 * This is a bit of a trick. When msg is not NULL it means
511 * thats technology_enable was invoked from the manager API.
512 * Hence we save the state here.
514 technology->enable_persistent = TRUE;
515 save_state(technology);
518 __connman_rfkill_block(technology->type, FALSE);
521 * An empty device list means that devices in the technology
522 * were rfkill blocked. The unblock above will enable the devs.
524 if (technology->device_list == NULL) {
529 for (list = technology->device_list; list; list = list->next) {
530 struct connman_device *device = list->data;
532 err = __connman_device_enable(device);
534 * err = 0 : Device was enabled right away.
535 * If atleast one device gets enabled, we consider
536 * the technology to be enabled.
545 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
550 if (err == -EINPROGRESS) {
551 technology->pending_reply = dbus_message_ref(msg);
552 technology->pending_timeout = g_timeout_add_seconds(10,
553 technology_pending_reply, technology);
555 reply = __connman_error_failed(msg, -err);
557 g_dbus_send_message(connection, reply);
564 static int technology_disable(struct connman_technology *technology,
572 DBG("technology %p disable", technology);
574 __sync_synchronize();
575 if (technology->enabled == 0) {
580 if (technology->pending_reply != NULL) {
585 if (technology->tethering == TRUE)
586 set_tethering(technology, FALSE);
589 technology->enable_persistent = FALSE;
590 save_state(technology);
593 __connman_rfkill_block(technology->type, TRUE);
595 for (list = technology->device_list; list; list = list->next) {
596 struct connman_device *device = list->data;
598 err = __connman_device_disable(device);
606 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
611 if (err == -EINPROGRESS) {
612 technology->pending_reply = dbus_message_ref(msg);
613 technology->pending_timeout = g_timeout_add_seconds(10,
614 technology_pending_reply, technology);
616 reply = __connman_error_failed(msg, -err);
618 g_dbus_send_message(connection, reply);
625 static DBusMessage *set_property(DBusConnection *conn,
626 DBusMessage *msg, void *data)
628 struct connman_technology *technology = data;
629 DBusMessageIter iter, value;
633 DBG("conn %p", conn);
635 if (dbus_message_iter_init(msg, &iter) == FALSE)
636 return __connman_error_invalid_arguments(msg);
638 dbus_message_iter_get_basic(&iter, &name);
639 dbus_message_iter_next(&iter);
640 dbus_message_iter_recurse(&iter, &value);
642 type = dbus_message_iter_get_arg_type(&value);
644 DBG("property %s", name);
646 if (g_str_equal(name, "Tethering") == TRUE) {
648 connman_bool_t tethering;
650 if (type != DBUS_TYPE_BOOLEAN)
651 return __connman_error_invalid_arguments(msg);
653 dbus_message_iter_get_basic(&value, &tethering);
655 if (technology->tethering == tethering)
656 return __connman_error_in_progress(msg);
658 err = set_tethering(technology, tethering);
660 return __connman_error_failed(msg, -err);
662 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
665 dbus_message_iter_get_basic(&value, &str);
667 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
668 return __connman_error_not_supported(msg);
670 technology->tethering_ident = g_strdup(str);
671 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
674 dbus_message_iter_get_basic(&value, &str);
676 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
677 return __connman_error_not_supported(msg);
680 return __connman_error_invalid_arguments(msg);
682 technology->tethering_passphrase = g_strdup(str);
683 } else if (g_str_equal(name, "Powered") == TRUE) {
684 connman_bool_t enable;
686 if (type != DBUS_TYPE_BOOLEAN)
687 return __connman_error_invalid_arguments(msg);
689 dbus_message_iter_get_basic(&value, &enable);
691 technology_enable(technology, msg);
693 technology_disable(technology, msg);
696 return __connman_error_invalid_property(msg);
698 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
701 static GDBusMethodTable technology_methods[] = {
702 { "GetProperties", "", "a{sv}", get_properties },
703 { "SetProperty", "sv", "", set_property },
707 static GDBusSignalTable technology_signals[] = {
708 { "PropertyChanged", "sv" },
712 static struct connman_technology *technology_find(enum connman_service_type type)
716 DBG("type %d", type);
718 for (list = technology_list; list; list = list->next) {
719 struct connman_technology *technology = list->data;
721 if (technology->type == type)
728 static struct connman_technology *technology_get(enum connman_service_type type)
730 struct connman_technology *technology;
731 struct connman_technology_driver *driver = NULL;
736 DBG("type %d", type);
738 str = __connman_service_type2string(type);
742 technology = technology_find(type);
743 if (technology != NULL)
746 /* First check if we have a driver for this technology type */
747 for (list = driver_list; list; list = list->next) {
750 if (driver->type == type)
756 if (driver == NULL) {
757 DBG("No matching driver found for %s.",
758 __connman_service_type2string(type));
762 technology = g_try_new0(struct connman_technology, 1);
763 if (technology == NULL)
766 technology->refcount = 1;
768 technology->type = type;
769 technology->path = g_strdup_printf("%s/technology/%s",
772 technology->rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
774 technology->device_list = NULL;
776 technology->pending_reply = NULL;
778 load_state(technology);
780 if (g_dbus_register_interface(connection, technology->path,
781 CONNMAN_TECHNOLOGY_INTERFACE,
782 technology_methods, technology_signals,
783 NULL, technology, NULL) == FALSE) {
784 connman_error("Failed to register %s", technology->path);
789 technology_list = g_slist_append(technology_list, technology);
791 technology_added_signal(technology);
793 technology->driver = driver;
794 err = driver->probe(technology);
796 DBG("Driver probe failed for technology %p", technology);
798 DBG("technology %p", technology);
803 static void technology_put(struct connman_technology *technology)
805 DBG("technology %p", technology);
807 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
810 if (technology->driver) {
811 technology->driver->remove(technology);
812 technology->driver = NULL;
815 technology_list = g_slist_remove(technology_list, technology);
817 technology_removed_signal(technology);
819 g_dbus_unregister_interface(connection, technology->path,
820 CONNMAN_TECHNOLOGY_INTERFACE);
822 g_slist_free(technology->device_list);
823 g_hash_table_destroy(technology->rfkill_list);
825 g_free(technology->path);
826 g_free(technology->regdom);
830 void __connman_technology_add_interface(enum connman_service_type type,
831 int index, const char *name, const char *ident)
833 struct connman_technology *technology;
836 case CONNMAN_SERVICE_TYPE_UNKNOWN:
837 case CONNMAN_SERVICE_TYPE_SYSTEM:
839 case CONNMAN_SERVICE_TYPE_ETHERNET:
840 case CONNMAN_SERVICE_TYPE_WIFI:
841 case CONNMAN_SERVICE_TYPE_WIMAX:
842 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
843 case CONNMAN_SERVICE_TYPE_CELLULAR:
844 case CONNMAN_SERVICE_TYPE_GPS:
845 case CONNMAN_SERVICE_TYPE_VPN:
846 case CONNMAN_SERVICE_TYPE_GADGET:
850 connman_info("Adding interface %s [ %s ]", name,
851 __connman_service_type2string(type));
853 technology = technology_find(type);
855 if (technology == NULL || technology->driver == NULL
856 || technology->driver->add_interface == NULL)
859 technology->driver->add_interface(technology,
863 void __connman_technology_remove_interface(enum connman_service_type type,
864 int index, const char *name, const char *ident)
866 struct connman_technology *technology;
869 case CONNMAN_SERVICE_TYPE_UNKNOWN:
870 case CONNMAN_SERVICE_TYPE_SYSTEM:
872 case CONNMAN_SERVICE_TYPE_ETHERNET:
873 case CONNMAN_SERVICE_TYPE_WIFI:
874 case CONNMAN_SERVICE_TYPE_WIMAX:
875 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
876 case CONNMAN_SERVICE_TYPE_CELLULAR:
877 case CONNMAN_SERVICE_TYPE_GPS:
878 case CONNMAN_SERVICE_TYPE_VPN:
879 case CONNMAN_SERVICE_TYPE_GADGET:
883 connman_info("Remove interface %s [ %s ]", name,
884 __connman_service_type2string(type));
886 technology = technology_find(type);
888 if (technology == NULL || technology->driver == NULL)
891 if (technology->driver->remove_interface)
892 technology->driver->remove_interface(technology, index);
895 int __connman_technology_add_device(struct connman_device *device)
897 struct connman_technology *technology;
898 enum connman_service_type type;
900 DBG("device %p", device);
902 type = __connman_device_get_service_type(device);
904 technology = technology_get(type);
905 if (technology == NULL)
908 if (technology->enable_persistent && !global_offlinemode)
909 __connman_device_enable(device);
910 /* if technology persistent state is offline */
911 if (!technology->enable_persistent)
912 __connman_device_disable(device);
914 technology->device_list = g_slist_append(technology->device_list,
920 int __connman_technology_remove_device(struct connman_device *device)
922 struct connman_technology *technology;
923 enum connman_service_type type;
925 DBG("device %p", device);
927 type = __connman_device_get_service_type(device);
929 technology = technology_find(type);
930 if (technology == NULL)
933 technology->device_list = g_slist_remove(technology->device_list,
938 static void powered_changed(struct connman_technology *technology)
940 connman_bool_t powered;
942 __sync_synchronize();
943 if (technology->enabled >0)
948 connman_dbus_property_changed_basic(technology->path,
949 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
950 DBUS_TYPE_BOOLEAN, &powered);
953 int __connman_technology_enabled(enum connman_service_type type)
955 struct connman_technology *technology;
957 technology = technology_find(type);
958 if (technology == NULL)
961 if (__sync_fetch_and_add(&technology->enabled, 1) == 0)
962 powered_changed(technology);
964 if (technology->pending_reply != NULL) {
965 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
966 dbus_message_unref(technology->pending_reply);
967 g_source_remove(technology->pending_timeout);
968 technology->pending_reply = NULL;
969 technology->pending_timeout = 0;
975 int __connman_technology_disabled(enum connman_service_type type)
977 struct connman_technology *technology;
979 technology = technology_find(type);
980 if (technology == NULL)
983 if (technology->pending_reply != NULL) {
984 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
985 dbus_message_unref(technology->pending_reply);
986 g_source_remove(technology->pending_timeout);
987 technology->pending_reply = NULL;
988 technology->pending_timeout = 0;
991 if (__sync_fetch_and_sub(&technology->enabled, 1) == 1)
992 powered_changed(technology);
997 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1002 if (global_offlinemode == offlinemode)
1005 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1008 * This is a bit tricky. When you set offlinemode, there is no
1009 * way to differentiate between attempting offline mode and
1010 * resuming offlinemode from last saved profile. We need that
1011 * information in rfkill_update, otherwise it falls back on the
1012 * technology's persistent state. Hence we set the offline mode here
1013 * but save it & call the notifier only if its successful.
1016 global_offlinemode = offlinemode;
1018 /* Traverse technology list, enable/disable each technology. */
1019 for (list = technology_list; list; list = list->next) {
1020 struct connman_technology *technology = list->data;
1023 err = technology_disable(technology, NULL);
1025 if (!offlinemode && technology->enable_persistent)
1026 err = technology_enable(technology, NULL);
1029 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1030 connman_technology_save_offlinemode();
1031 __connman_notifier_offlinemode(offlinemode);
1033 global_offlinemode = connman_technology_load_offlinemode();
1038 void __connman_technology_set_connected(enum connman_service_type type,
1039 connman_bool_t connected)
1041 struct connman_technology *technology;
1043 technology = technology_find(type);
1044 if (technology == NULL)
1047 DBG("technology %p connected %d", technology, connected);
1049 technology->connected = connected;
1051 connman_dbus_property_changed_basic(technology->path,
1052 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
1053 DBUS_TYPE_BOOLEAN, &connected);
1056 int __connman_technology_add_rfkill(unsigned int index,
1057 enum connman_service_type type,
1058 connman_bool_t softblock,
1059 connman_bool_t hardblock)
1061 struct connman_technology *technology;
1062 struct connman_rfkill *rfkill;
1064 DBG("index %u type %d soft %u hard %u", index, type,
1065 softblock, hardblock);
1067 technology = technology_get(type);
1068 if (technology == NULL)
1071 rfkill = g_try_new0(struct connman_rfkill, 1);
1075 rfkill->index = index;
1076 rfkill->type = type;
1077 rfkill->softblock = softblock;
1078 rfkill->hardblock = hardblock;
1080 g_hash_table_replace(technology->rfkill_list, &rfkill->index, rfkill);
1083 DBG("%s is switched off.", get_name(type));
1088 * If Offline mode is on, we softblock the device if it isnt already.
1089 * If Offline mode is off, we rely on the persistent state of tech.
1091 if (global_offlinemode) {
1093 return __connman_rfkill_block(type, TRUE);
1095 if (technology->enable_persistent && softblock)
1096 return __connman_rfkill_block(type, FALSE);
1097 /* if technology persistent state is offline */
1098 if (!technology->enable_persistent && !softblock)
1099 return __connman_rfkill_block(type, TRUE);
1105 int __connman_technology_update_rfkill(unsigned int index,
1106 enum connman_service_type type,
1107 connman_bool_t softblock,
1108 connman_bool_t hardblock)
1110 struct connman_technology *technology;
1111 struct connman_rfkill *rfkill;
1113 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1115 technology = technology_find(type);
1116 if (technology == NULL)
1119 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1123 if (rfkill->softblock == softblock &&
1124 rfkill->hardblock == hardblock)
1127 rfkill->softblock = softblock;
1128 rfkill->hardblock = hardblock;
1131 DBG("%s is switched off.", get_name(type));
1135 if (!global_offlinemode) {
1136 if (technology->enable_persistent && softblock)
1137 return __connman_rfkill_block(type, FALSE);
1138 if (!technology->enable_persistent && !softblock)
1139 return __connman_rfkill_block(type, TRUE);
1145 int __connman_technology_remove_rfkill(unsigned int index,
1146 enum connman_service_type type)
1148 struct connman_technology *technology;
1149 struct connman_rfkill *rfkill;
1151 DBG("index %u", index);
1153 technology = technology_find(type);
1154 if (technology == NULL)
1157 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1161 g_hash_table_remove(technology->rfkill_list, &index);
1163 technology_put(technology);
1168 int __connman_technology_init(void)
1172 connection = connman_dbus_get_connection();
1174 global_offlinemode = connman_technology_load_offlinemode();
1179 void __connman_technology_cleanup(void)
1183 dbus_connection_unref(connection);