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 void __connman_technology_list(DBusMessageIter *iter, void *user_data)
247 for (list = technology_list; list; list = list->next) {
248 struct connman_technology *technology = list->data;
250 if (technology->path == NULL)
253 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
258 static void technologies_changed(void)
260 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
261 CONNMAN_MANAGER_INTERFACE, "Technologies",
262 DBUS_TYPE_OBJECT_PATH, __connman_technology_list, NULL);
265 static const char *state2string(enum connman_technology_state state)
268 case CONNMAN_TECHNOLOGY_STATE_UNKNOWN:
270 case CONNMAN_TECHNOLOGY_STATE_OFFLINE:
272 case CONNMAN_TECHNOLOGY_STATE_ENABLED:
274 case CONNMAN_TECHNOLOGY_STATE_CONNECTED:
281 static void state_changed(struct connman_technology *technology)
285 str = state2string(technology->state);
289 connman_dbus_property_changed_basic(technology->path,
290 CONNMAN_TECHNOLOGY_INTERFACE, "State",
291 DBUS_TYPE_STRING, &str);
294 static const char *get_name(enum connman_service_type type)
297 case CONNMAN_SERVICE_TYPE_UNKNOWN:
298 case CONNMAN_SERVICE_TYPE_SYSTEM:
299 case CONNMAN_SERVICE_TYPE_GPS:
300 case CONNMAN_SERVICE_TYPE_VPN:
301 case CONNMAN_SERVICE_TYPE_GADGET:
303 case CONNMAN_SERVICE_TYPE_ETHERNET:
305 case CONNMAN_SERVICE_TYPE_WIFI:
307 case CONNMAN_SERVICE_TYPE_WIMAX:
309 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
311 case CONNMAN_SERVICE_TYPE_CELLULAR:
318 static void load_state(struct connman_technology *technology)
322 GError *error = NULL;
323 connman_bool_t enable;
325 DBG("technology %p", technology);
327 keyfile = __connman_storage_load_global();
328 /* Fallback on disabling technology if file not found. */
329 if (keyfile == NULL) {
330 technology->enable_persistent = FALSE;
334 identifier = g_strdup_printf("%s", get_name(technology->type));
335 if (identifier == NULL)
338 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
340 technology->enable_persistent = enable;
342 technology->enable_persistent = FALSE;
343 g_clear_error(&error);
348 g_key_file_free(keyfile);
353 static void save_state(struct connman_technology *technology)
358 DBG("technology %p", technology);
360 keyfile = __connman_storage_load_global();
362 keyfile = g_key_file_new();
364 identifier = g_strdup_printf("%s", get_name(technology->type));
365 if (identifier == NULL)
368 g_key_file_set_boolean(keyfile, identifier, "Enable",
369 technology->enable_persistent);
374 __connman_storage_save_global(keyfile);
376 g_key_file_free(keyfile);
381 connman_bool_t __connman_technology_get_offlinemode(void)
383 return global_offlinemode;
386 static void connman_technology_save_offlinemode()
390 keyfile = __connman_storage_load_global();
392 keyfile = g_key_file_new();
394 g_key_file_set_boolean(keyfile, "global",
395 "OfflineMode", global_offlinemode);
397 __connman_storage_save_global(keyfile);
399 g_key_file_free(keyfile);
404 static connman_bool_t connman_technology_load_offlinemode()
407 GError *error = NULL;
408 connman_bool_t offlinemode;
410 /* If there is a error, we enable offlinemode */
411 keyfile = __connman_storage_load_global();
415 offlinemode = g_key_file_get_boolean(keyfile, "global",
416 "OfflineMode", &error);
419 g_clear_error(&error);
422 g_key_file_free(keyfile);
427 static void append_properties(DBusMessageIter *iter,
428 struct connman_technology *technology)
430 DBusMessageIter dict;
433 connman_dbus_dict_open(iter, &dict);
435 str = state2string(technology->state);
437 connman_dbus_dict_append_basic(&dict, "State",
438 DBUS_TYPE_STRING, &str);
440 str = get_name(technology->type);
442 connman_dbus_dict_append_basic(&dict, "Name",
443 DBUS_TYPE_STRING, &str);
445 str = __connman_service_type2string(technology->type);
447 connman_dbus_dict_append_basic(&dict, "Type",
448 DBUS_TYPE_STRING, &str);
450 connman_dbus_dict_append_basic(&dict, "Tethering",
452 &technology->tethering);
454 if (technology->tethering_ident != NULL)
455 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
457 &technology->tethering_ident);
459 if (technology->tethering_passphrase != NULL)
460 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
462 &technology->tethering_passphrase);
464 connman_dbus_dict_close(iter, &dict);
467 static void technology_added_signal(struct connman_technology *technology)
470 DBusMessageIter iter;
472 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
473 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
477 dbus_message_iter_init_append(signal, &iter);
478 append_properties(&iter, technology);
480 dbus_connection_send(connection, signal, NULL);
481 dbus_message_unref(signal);
484 static void technology_removed_signal(struct connman_technology *technology)
486 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
487 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
488 DBUS_TYPE_OBJECT_PATH, technology->path);
491 static DBusMessage *get_properties(DBusConnection *conn,
492 DBusMessage *message, void *user_data)
494 struct connman_technology *technology = user_data;
496 DBusMessageIter iter;
498 reply = dbus_message_new_method_return(message);
502 dbus_message_iter_init_append(reply, &iter);
503 append_properties(&iter, technology);
508 static DBusMessage *set_property(DBusConnection *conn,
509 DBusMessage *msg, void *data)
511 struct connman_technology *technology = data;
512 DBusMessageIter iter, value;
516 DBG("conn %p", conn);
518 if (dbus_message_iter_init(msg, &iter) == FALSE)
519 return __connman_error_invalid_arguments(msg);
521 dbus_message_iter_get_basic(&iter, &name);
522 dbus_message_iter_next(&iter);
523 dbus_message_iter_recurse(&iter, &value);
525 type = dbus_message_iter_get_arg_type(&value);
527 DBG("property %s", name);
529 if (g_str_equal(name, "Tethering") == TRUE) {
531 connman_bool_t tethering;
533 if (type != DBUS_TYPE_BOOLEAN)
534 return __connman_error_invalid_arguments(msg);
536 dbus_message_iter_get_basic(&value, &tethering);
538 if (technology->tethering == tethering)
539 return __connman_error_in_progress(msg);
541 err = set_tethering(technology, tethering);
543 return __connman_error_failed(msg, -err);
545 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
548 dbus_message_iter_get_basic(&value, &str);
550 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
551 return __connman_error_not_supported(msg);
553 technology->tethering_ident = g_strdup(str);
554 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
557 dbus_message_iter_get_basic(&value, &str);
559 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
560 return __connman_error_not_supported(msg);
563 return __connman_error_invalid_arguments(msg);
565 technology->tethering_passphrase = g_strdup(str);
567 return __connman_error_invalid_property(msg);
569 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
572 static GDBusMethodTable technology_methods[] = {
573 { "GetProperties", "", "a{sv}", get_properties },
574 { "SetProperty", "sv", "", set_property },
578 static GDBusSignalTable technology_signals[] = {
579 { "PropertyChanged", "sv" },
583 static struct connman_technology *technology_find(enum connman_service_type type)
587 DBG("type %d", type);
589 for (list = technology_list; list; list = list->next) {
590 struct connman_technology *technology = list->data;
592 if (technology->type == type)
599 static struct connman_technology *technology_get(enum connman_service_type type)
601 struct connman_technology *technology;
605 DBG("type %d", type);
607 technology = technology_find(type);
608 if (technology != NULL) {
609 __sync_fetch_and_add(&technology->refcount, 1);
613 str = __connman_service_type2string(type);
617 technology = g_try_new0(struct connman_technology, 1);
618 if (technology == NULL)
621 technology->refcount = 1;
623 technology->type = type;
624 technology->path = g_strdup_printf("%s/technology/%s",
627 technology->rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
629 technology->device_list = NULL;
631 technology->pending_reply = NULL;
632 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
634 load_state(technology);
636 if (g_dbus_register_interface(connection, technology->path,
637 CONNMAN_TECHNOLOGY_INTERFACE,
638 technology_methods, technology_signals,
639 NULL, technology, NULL) == FALSE) {
640 connman_error("Failed to register %s", technology->path);
645 technology_list = g_slist_append(technology_list, technology);
647 technologies_changed();
648 technology_added_signal(technology);
650 if (technology->driver != NULL)
653 for (list = driver_list; list; list = list->next) {
654 struct connman_technology_driver *driver = list->data;
656 DBG("driver %p name %s", driver, driver->name);
658 if (driver->type != technology->type)
661 if (driver->probe(technology) == 0) {
662 technology->driver = driver;
668 DBG("technology %p", technology);
673 static void technology_put(struct connman_technology *technology)
675 DBG("technology %p", technology);
677 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
680 if (technology->driver) {
681 technology->driver->remove(technology);
682 technology->driver = NULL;
685 technology_list = g_slist_remove(technology_list, technology);
687 technologies_changed();
688 technology_removed_signal(technology);
690 g_dbus_unregister_interface(connection, technology->path,
691 CONNMAN_TECHNOLOGY_INTERFACE);
693 g_slist_free(technology->device_list);
694 g_hash_table_destroy(technology->rfkill_list);
696 g_free(technology->path);
697 g_free(technology->regdom);
701 void __connman_technology_add_interface(enum connman_service_type type,
702 int index, const char *name, const char *ident)
704 struct connman_technology *technology;
707 case CONNMAN_SERVICE_TYPE_UNKNOWN:
708 case CONNMAN_SERVICE_TYPE_SYSTEM:
710 case CONNMAN_SERVICE_TYPE_ETHERNET:
711 case CONNMAN_SERVICE_TYPE_WIFI:
712 case CONNMAN_SERVICE_TYPE_WIMAX:
713 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
714 case CONNMAN_SERVICE_TYPE_CELLULAR:
715 case CONNMAN_SERVICE_TYPE_GPS:
716 case CONNMAN_SERVICE_TYPE_VPN:
717 case CONNMAN_SERVICE_TYPE_GADGET:
721 connman_info("Create interface %s [ %s ]", name,
722 __connman_service_type2string(type));
724 technology = technology_get(type);
726 if (technology == NULL || technology->driver == NULL
727 || technology->driver->add_interface == NULL)
730 technology->driver->add_interface(technology,
734 void __connman_technology_remove_interface(enum connman_service_type type,
735 int index, const char *name, const char *ident)
737 struct connman_technology *technology;
740 case CONNMAN_SERVICE_TYPE_UNKNOWN:
741 case CONNMAN_SERVICE_TYPE_SYSTEM:
743 case CONNMAN_SERVICE_TYPE_ETHERNET:
744 case CONNMAN_SERVICE_TYPE_WIFI:
745 case CONNMAN_SERVICE_TYPE_WIMAX:
746 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
747 case CONNMAN_SERVICE_TYPE_CELLULAR:
748 case CONNMAN_SERVICE_TYPE_GPS:
749 case CONNMAN_SERVICE_TYPE_VPN:
750 case CONNMAN_SERVICE_TYPE_GADGET:
754 connman_info("Remove interface %s [ %s ]", name,
755 __connman_service_type2string(type));
757 technology = technology_find(type);
759 if (technology == NULL || technology->driver == NULL)
762 if (technology->driver->remove_interface)
763 technology->driver->remove_interface(technology, index);
765 technology_put(technology);
768 int __connman_technology_add_device(struct connman_device *device)
770 struct connman_technology *technology;
771 enum connman_service_type type;
773 DBG("device %p", device);
775 type = __connman_device_get_service_type(device);
776 __connman_notifier_register(type);
778 technology = technology_get(type);
779 if (technology == NULL)
782 if (technology->enable_persistent && !global_offlinemode)
783 __connman_device_enable(device);
784 /* if technology persistent state is offline */
785 if (!technology->enable_persistent)
786 __connman_device_disable(device);
788 technology->device_list = g_slist_append(technology->device_list,
794 int __connman_technology_remove_device(struct connman_device *device)
796 struct connman_technology *technology;
797 enum connman_service_type type;
799 DBG("device %p", device);
801 type = __connman_device_get_service_type(device);
802 __connman_notifier_unregister(type);
804 technology = technology_find(type);
805 if (technology == NULL)
808 technology->device_list = g_slist_remove(technology->device_list,
810 if (technology->device_list == NULL) {
811 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
812 state_changed(technology);
818 static gboolean technology_pending_reply(gpointer user_data)
820 struct connman_technology *technology = user_data;
823 /* Power request timedout, send ETIMEDOUT. */
824 if (technology->pending_reply != NULL) {
825 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
827 g_dbus_send_message(connection, reply);
829 dbus_message_unref(technology->pending_reply);
830 technology->pending_reply = NULL;
831 technology->pending_timeout = 0;
837 int __connman_technology_enabled(enum connman_service_type type)
839 struct connman_technology *technology;
841 technology = technology_find(type);
842 if (technology == NULL)
845 if (__sync_fetch_and_add(&technology->enabled, 1) == 0) {
846 __connman_notifier_enable(type);
847 technology->state = CONNMAN_TECHNOLOGY_STATE_ENABLED;
848 state_changed(technology);
851 if (technology->pending_reply != NULL) {
852 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
853 dbus_message_unref(technology->pending_reply);
854 g_source_remove(technology->pending_timeout);
855 technology->pending_reply = NULL;
856 technology->pending_timeout = 0;
862 int __connman_technology_enable(enum connman_service_type type, DBusMessage *msg)
864 struct connman_technology *technology;
870 DBG("type %d enable", type);
872 technology = technology_find(type);
873 if (technology == NULL) {
878 if (technology->pending_reply != NULL) {
885 * This is a bit of a trick. When msg is not NULL it means
886 * thats technology_enable was invoked from the manager API. Hence we save
889 technology->enable_persistent = TRUE;
890 save_state(technology);
893 __connman_rfkill_block(technology->type, FALSE);
896 * An empty device list means that devices in the technology
897 * were rfkill blocked. The unblock above will enable the devs.
899 if (technology->device_list == NULL)
902 for (list = technology->device_list; list; list = list->next) {
903 struct connman_device *device = list->data;
905 err = __connman_device_enable(device);
907 * err = 0 : Device was enabled right away.
908 * If atleast one device gets enabled, we consider
909 * the technology to be enabled.
918 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
923 if (err == -EINPROGRESS) {
924 technology->pending_reply = dbus_message_ref(msg);
925 technology->pending_timeout = g_timeout_add_seconds(10,
926 technology_pending_reply, technology);
928 reply = __connman_error_failed(msg, -err);
930 g_dbus_send_message(connection, reply);
937 int __connman_technology_disabled(enum connman_service_type type)
939 struct connman_technology *technology;
941 technology = technology_find(type);
942 if (technology == NULL)
945 if (technology->pending_reply != NULL) {
946 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
947 dbus_message_unref(technology->pending_reply);
948 g_source_remove(technology->pending_timeout);
949 technology->pending_reply = NULL;
950 technology->pending_timeout = 0;
953 if (__sync_fetch_and_sub(&technology->enabled, 1) != 1)
956 __connman_notifier_disable(type);
957 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
958 state_changed(technology);
963 int __connman_technology_disable(enum connman_service_type type, DBusMessage *msg)
965 struct connman_technology *technology;
971 DBG("type %d disable", type);
973 technology = technology_find(type);
974 if (technology == NULL) {
979 if (technology->pending_reply != NULL) {
984 if (technology->tethering == TRUE)
985 set_tethering(technology, FALSE);
988 technology->enable_persistent = FALSE;
989 save_state(technology);
992 __connman_rfkill_block(technology->type, TRUE);
994 for (list = technology->device_list; list; list = list->next) {
995 struct connman_device *device = list->data;
997 err = __connman_device_disable(device);
1005 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
1010 if (err == -EINPROGRESS) {
1011 technology->pending_reply = dbus_message_ref(msg);
1012 technology->pending_timeout = g_timeout_add_seconds(10,
1013 technology_pending_reply, technology);
1015 reply = __connman_error_failed(msg, -err);
1017 g_dbus_send_message(connection, reply);
1024 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1029 if (global_offlinemode == offlinemode)
1032 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1035 * This is a bit tricky. When you set offlinemode, there is no
1036 * way to differentiate between attempting offline mode and
1037 * resuming offlinemode from last saved profile. We need that
1038 * information in rfkill_update, otherwise it falls back on the
1039 * technology's persistent state. Hence we set the offline mode here
1040 * but save it & call the notifier only if its successful.
1043 global_offlinemode = offlinemode;
1045 /* Traverse technology list, enable/disable each technology. */
1046 for (list = technology_list; list; list = list->next) {
1047 struct connman_technology *technology = list->data;
1050 err = __connman_technology_disable(technology->type, NULL);
1052 if (!offlinemode && technology->enable_persistent)
1053 err = __connman_technology_enable(technology->type, NULL);
1056 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1057 connman_technology_save_offlinemode();
1058 __connman_notifier_offlinemode(offlinemode);
1060 global_offlinemode = connman_technology_load_offlinemode();
1065 int __connman_technology_add_rfkill(unsigned int index,
1066 enum connman_service_type type,
1067 connman_bool_t softblock,
1068 connman_bool_t hardblock)
1070 struct connman_technology *technology;
1071 struct connman_rfkill *rfkill;
1073 DBG("index %u type %d soft %u hard %u", index, type,
1074 softblock, hardblock);
1076 technology = technology_get(type);
1077 if (technology == NULL)
1080 rfkill = g_try_new0(struct connman_rfkill, 1);
1084 __connman_notifier_register(type);
1086 rfkill->index = index;
1087 rfkill->type = type;
1088 rfkill->softblock = softblock;
1089 rfkill->hardblock = hardblock;
1091 g_hash_table_replace(technology->rfkill_list, &rfkill->index, rfkill);
1094 DBG("%s is switched off.", get_name(type));
1099 * If Offline mode is on, we softblock the device if it isnt already.
1100 * If Offline mode is off, we rely on the persistent state of tech.
1102 if (global_offlinemode) {
1104 return __connman_rfkill_block(type, TRUE);
1106 if (technology->enable_persistent && softblock)
1107 return __connman_rfkill_block(type, FALSE);
1108 /* if technology persistent state is offline */
1109 if (!technology->enable_persistent && !softblock)
1110 return __connman_rfkill_block(type, TRUE);
1116 int __connman_technology_update_rfkill(unsigned int index,
1117 enum connman_service_type type,
1118 connman_bool_t softblock,
1119 connman_bool_t hardblock)
1121 struct connman_technology *technology;
1122 struct connman_rfkill *rfkill;
1124 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1126 technology = technology_find(type);
1127 if (technology == NULL)
1130 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1134 if (rfkill->softblock == softblock &&
1135 rfkill->hardblock == hardblock)
1138 rfkill->softblock = softblock;
1139 rfkill->hardblock = hardblock;
1142 DBG("%s is switched off.", get_name(type));
1146 if (!global_offlinemode) {
1147 if (technology->enable_persistent && softblock)
1148 return __connman_rfkill_block(type, FALSE);
1149 if (!technology->enable_persistent && !softblock)
1150 return __connman_rfkill_block(type, TRUE);
1156 int __connman_technology_remove_rfkill(unsigned int index,
1157 enum connman_service_type type)
1159 struct connman_technology *technology;
1160 struct connman_rfkill *rfkill;
1162 DBG("index %u", index);
1164 technology = technology_find(type);
1165 if (technology == NULL)
1168 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1172 g_hash_table_remove(technology->rfkill_list, &index);
1174 technology_put(technology);
1179 int __connman_technology_init(void)
1183 connection = connman_dbus_get_connection();
1185 global_offlinemode = connman_technology_load_offlinemode();
1190 void __connman_technology_cleanup(void)
1194 dbus_connection_unref(connection);