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)
96 DBG("Registering %s driver", driver->name);
98 driver_list = g_slist_insert_sorted(driver_list, driver,
105 * connman_technology_driver_unregister:
106 * @driver: Technology driver definition
108 * Remove a previously registered technology driver
110 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
113 struct connman_technology *technology;
115 DBG("Unregistering driver %p name %s", driver, driver->name);
117 for (list = technology_list; list; list = list->next) {
118 technology = list->data;
120 if (technology->driver == NULL)
123 if (technology->type == driver->type) {
124 technology->driver->remove(technology);
125 technology->driver = NULL;
129 driver_list = g_slist_remove(driver_list, driver);
132 static void tethering_changed(struct connman_technology *technology)
134 connman_bool_t tethering = technology->tethering;
136 connman_dbus_property_changed_basic(technology->path,
137 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
138 DBUS_TYPE_BOOLEAN, &tethering);
141 void connman_technology_tethering_notify(struct connman_technology *technology,
142 connman_bool_t enabled)
146 DBG("technology %p enabled %u", technology, enabled);
148 if (technology->tethering == enabled)
151 technology->tethering = enabled;
153 tethering_changed(technology);
156 __connman_tethering_set_enabled();
158 for (list = technology_list; list; list = list->next) {
159 struct connman_technology *other_tech = list->data;
160 if (other_tech->tethering == TRUE)
164 __connman_tethering_set_disabled();
168 static int set_tethering(struct connman_technology *technology,
169 connman_bool_t enabled)
171 const char *ident, *passphrase, *bridge;
173 ident = technology->tethering_ident;
174 passphrase = technology->tethering_passphrase;
176 if (technology->driver == NULL ||
177 technology->driver->set_tethering == NULL)
180 bridge = __connman_tethering_get_bridge();
184 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
185 (ident == NULL || passphrase == NULL))
188 return technology->driver->set_tethering(technology, ident, passphrase,
192 void connman_technology_regdom_notify(struct connman_technology *technology,
198 connman_error("Failed to set regulatory domain");
200 DBG("Regulatory domain set to %s", alpha2);
202 g_free(technology->regdom);
203 technology->regdom = g_strdup(alpha2);
206 int connman_technology_set_regdom(const char *alpha2)
210 for (list = technology_list; list; list = list->next) {
211 struct connman_technology *technology = list->data;
213 if (technology->driver == NULL)
216 if (technology->driver->set_regdom)
217 technology->driver->set_regdom(technology, alpha2);
223 static void free_rfkill(gpointer data)
225 struct connman_rfkill *rfkill = data;
230 static const char *state2string(enum connman_technology_state state)
233 case CONNMAN_TECHNOLOGY_STATE_UNKNOWN:
235 case CONNMAN_TECHNOLOGY_STATE_OFFLINE:
237 case CONNMAN_TECHNOLOGY_STATE_ENABLED:
239 case CONNMAN_TECHNOLOGY_STATE_CONNECTED:
246 static void state_changed(struct connman_technology *technology)
250 str = state2string(technology->state);
254 connman_dbus_property_changed_basic(technology->path,
255 CONNMAN_TECHNOLOGY_INTERFACE, "State",
256 DBUS_TYPE_STRING, &str);
259 static const char *get_name(enum connman_service_type type)
262 case CONNMAN_SERVICE_TYPE_UNKNOWN:
263 case CONNMAN_SERVICE_TYPE_SYSTEM:
264 case CONNMAN_SERVICE_TYPE_GPS:
265 case CONNMAN_SERVICE_TYPE_VPN:
266 case CONNMAN_SERVICE_TYPE_GADGET:
268 case CONNMAN_SERVICE_TYPE_ETHERNET:
270 case CONNMAN_SERVICE_TYPE_WIFI:
272 case CONNMAN_SERVICE_TYPE_WIMAX:
274 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
276 case CONNMAN_SERVICE_TYPE_CELLULAR:
283 static void load_state(struct connman_technology *technology)
287 GError *error = NULL;
288 connman_bool_t enable;
290 DBG("technology %p", technology);
292 keyfile = __connman_storage_load_global();
293 /* Fallback on disabling technology if file not found. */
294 if (keyfile == NULL) {
295 technology->enable_persistent = FALSE;
299 identifier = g_strdup_printf("%s", get_name(technology->type));
300 if (identifier == NULL)
303 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
305 technology->enable_persistent = enable;
307 technology->enable_persistent = FALSE;
308 g_clear_error(&error);
313 g_key_file_free(keyfile);
318 static void save_state(struct connman_technology *technology)
323 DBG("technology %p", technology);
325 keyfile = __connman_storage_load_global();
327 keyfile = g_key_file_new();
329 identifier = g_strdup_printf("%s", get_name(technology->type));
330 if (identifier == NULL)
333 g_key_file_set_boolean(keyfile, identifier, "Enable",
334 technology->enable_persistent);
339 __connman_storage_save_global(keyfile);
341 g_key_file_free(keyfile);
346 connman_bool_t __connman_technology_get_offlinemode(void)
348 return global_offlinemode;
351 static void connman_technology_save_offlinemode()
355 keyfile = __connman_storage_load_global();
357 keyfile = g_key_file_new();
359 g_key_file_set_boolean(keyfile, "global",
360 "OfflineMode", global_offlinemode);
362 __connman_storage_save_global(keyfile);
364 g_key_file_free(keyfile);
369 static connman_bool_t connman_technology_load_offlinemode()
372 GError *error = NULL;
373 connman_bool_t offlinemode;
375 /* If there is a error, we enable offlinemode */
376 keyfile = __connman_storage_load_global();
380 offlinemode = g_key_file_get_boolean(keyfile, "global",
381 "OfflineMode", &error);
384 g_clear_error(&error);
387 g_key_file_free(keyfile);
392 static void append_properties(DBusMessageIter *iter,
393 struct connman_technology *technology)
395 DBusMessageIter dict;
398 connman_dbus_dict_open(iter, &dict);
400 str = state2string(technology->state);
402 connman_dbus_dict_append_basic(&dict, "State",
403 DBUS_TYPE_STRING, &str);
405 str = get_name(technology->type);
407 connman_dbus_dict_append_basic(&dict, "Name",
408 DBUS_TYPE_STRING, &str);
410 str = __connman_service_type2string(technology->type);
412 connman_dbus_dict_append_basic(&dict, "Type",
413 DBUS_TYPE_STRING, &str);
415 connman_dbus_dict_append_basic(&dict, "Tethering",
417 &technology->tethering);
419 if (technology->tethering_ident != NULL)
420 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
422 &technology->tethering_ident);
424 if (technology->tethering_passphrase != NULL)
425 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
427 &technology->tethering_passphrase);
429 connman_dbus_dict_close(iter, &dict);
432 static void technology_added_signal(struct connman_technology *technology)
435 DBusMessageIter iter;
437 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
438 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
442 dbus_message_iter_init_append(signal, &iter);
443 append_properties(&iter, technology);
445 dbus_connection_send(connection, signal, NULL);
446 dbus_message_unref(signal);
449 static void technology_removed_signal(struct connman_technology *technology)
451 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
452 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
453 DBUS_TYPE_OBJECT_PATH, technology->path,
457 static DBusMessage *get_properties(DBusConnection *conn,
458 DBusMessage *message, void *user_data)
460 struct connman_technology *technology = user_data;
462 DBusMessageIter iter;
464 reply = dbus_message_new_method_return(message);
468 dbus_message_iter_init_append(reply, &iter);
469 append_properties(&iter, technology);
474 void __connman_technology_list_struct(DBusMessageIter *array)
477 DBusMessageIter entry;
479 for (list = technology_list; list; list = list->next) {
480 struct connman_technology *technology = list->data;
482 if (technology->path == NULL)
485 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
487 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
489 append_properties(&entry, technology);
490 dbus_message_iter_close_container(array, &entry);
494 static DBusMessage *set_property(DBusConnection *conn,
495 DBusMessage *msg, void *data)
497 struct connman_technology *technology = data;
498 DBusMessageIter iter, value;
502 DBG("conn %p", conn);
504 if (dbus_message_iter_init(msg, &iter) == FALSE)
505 return __connman_error_invalid_arguments(msg);
507 dbus_message_iter_get_basic(&iter, &name);
508 dbus_message_iter_next(&iter);
509 dbus_message_iter_recurse(&iter, &value);
511 type = dbus_message_iter_get_arg_type(&value);
513 DBG("property %s", name);
515 if (g_str_equal(name, "Tethering") == TRUE) {
517 connman_bool_t tethering;
519 if (type != DBUS_TYPE_BOOLEAN)
520 return __connman_error_invalid_arguments(msg);
522 dbus_message_iter_get_basic(&value, &tethering);
524 if (technology->tethering == tethering)
525 return __connman_error_in_progress(msg);
527 err = set_tethering(technology, tethering);
529 return __connman_error_failed(msg, -err);
531 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
534 dbus_message_iter_get_basic(&value, &str);
536 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
537 return __connman_error_not_supported(msg);
539 technology->tethering_ident = g_strdup(str);
540 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
543 dbus_message_iter_get_basic(&value, &str);
545 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
546 return __connman_error_not_supported(msg);
549 return __connman_error_invalid_arguments(msg);
551 technology->tethering_passphrase = g_strdup(str);
553 return __connman_error_invalid_property(msg);
555 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
558 static GDBusMethodTable technology_methods[] = {
559 { "GetProperties", "", "a{sv}", get_properties },
560 { "SetProperty", "sv", "", set_property },
564 static GDBusSignalTable technology_signals[] = {
565 { "PropertyChanged", "sv" },
569 static struct connman_technology *technology_find(enum connman_service_type type)
573 DBG("type %d", type);
575 for (list = technology_list; list; list = list->next) {
576 struct connman_technology *technology = list->data;
578 if (technology->type == type)
585 static struct connman_technology *technology_get(enum connman_service_type type)
587 struct connman_technology *technology;
588 struct connman_technology_driver *driver = NULL;
593 DBG("type %d", type);
595 str = __connman_service_type2string(type);
599 technology = technology_find(type);
600 if (technology != NULL)
603 /* First check if we have a driver for this technology type */
604 for (list = driver_list; list; list = list->next) {
607 if (driver->type == type)
613 if (driver == NULL) {
614 DBG("No matching driver found for %s.",
615 __connman_service_type2string(type));
619 technology = g_try_new0(struct connman_technology, 1);
620 if (technology == NULL)
623 technology->refcount = 1;
625 technology->type = type;
626 technology->path = g_strdup_printf("%s/technology/%s",
629 technology->rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
631 technology->device_list = NULL;
633 technology->pending_reply = NULL;
634 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
636 load_state(technology);
638 if (g_dbus_register_interface(connection, technology->path,
639 CONNMAN_TECHNOLOGY_INTERFACE,
640 technology_methods, technology_signals,
641 NULL, technology, NULL) == FALSE) {
642 connman_error("Failed to register %s", technology->path);
647 technology_list = g_slist_append(technology_list, technology);
649 technology_added_signal(technology);
651 technology->driver = driver;
652 err = driver->probe(technology);
654 DBG("Driver probe failed for technology %p", technology);
656 DBG("technology %p", technology);
661 static void technology_put(struct connman_technology *technology)
663 DBG("technology %p", technology);
665 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
668 if (technology->driver) {
669 technology->driver->remove(technology);
670 technology->driver = NULL;
673 technology_list = g_slist_remove(technology_list, technology);
675 technology_removed_signal(technology);
677 g_dbus_unregister_interface(connection, technology->path,
678 CONNMAN_TECHNOLOGY_INTERFACE);
680 g_slist_free(technology->device_list);
681 g_hash_table_destroy(technology->rfkill_list);
683 g_free(technology->path);
684 g_free(technology->regdom);
688 void __connman_technology_add_interface(enum connman_service_type type,
689 int index, const char *name, const char *ident)
691 struct connman_technology *technology;
694 case CONNMAN_SERVICE_TYPE_UNKNOWN:
695 case CONNMAN_SERVICE_TYPE_SYSTEM:
697 case CONNMAN_SERVICE_TYPE_ETHERNET:
698 case CONNMAN_SERVICE_TYPE_WIFI:
699 case CONNMAN_SERVICE_TYPE_WIMAX:
700 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
701 case CONNMAN_SERVICE_TYPE_CELLULAR:
702 case CONNMAN_SERVICE_TYPE_GPS:
703 case CONNMAN_SERVICE_TYPE_VPN:
704 case CONNMAN_SERVICE_TYPE_GADGET:
708 connman_info("Adding interface %s [ %s ]", name,
709 __connman_service_type2string(type));
711 technology = technology_find(type);
713 if (technology == NULL || technology->driver == NULL
714 || technology->driver->add_interface == NULL)
717 technology->driver->add_interface(technology,
721 void __connman_technology_remove_interface(enum connman_service_type type,
722 int index, const char *name, const char *ident)
724 struct connman_technology *technology;
727 case CONNMAN_SERVICE_TYPE_UNKNOWN:
728 case CONNMAN_SERVICE_TYPE_SYSTEM:
730 case CONNMAN_SERVICE_TYPE_ETHERNET:
731 case CONNMAN_SERVICE_TYPE_WIFI:
732 case CONNMAN_SERVICE_TYPE_WIMAX:
733 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
734 case CONNMAN_SERVICE_TYPE_CELLULAR:
735 case CONNMAN_SERVICE_TYPE_GPS:
736 case CONNMAN_SERVICE_TYPE_VPN:
737 case CONNMAN_SERVICE_TYPE_GADGET:
741 connman_info("Remove interface %s [ %s ]", name,
742 __connman_service_type2string(type));
744 technology = technology_find(type);
746 if (technology == NULL || technology->driver == NULL)
749 if (technology->driver->remove_interface)
750 technology->driver->remove_interface(technology, index);
753 int __connman_technology_add_device(struct connman_device *device)
755 struct connman_technology *technology;
756 enum connman_service_type type;
758 DBG("device %p", device);
760 type = __connman_device_get_service_type(device);
761 __connman_notifier_register(type);
763 technology = technology_get(type);
764 if (technology == NULL)
767 if (technology->enable_persistent && !global_offlinemode)
768 __connman_device_enable(device);
769 /* if technology persistent state is offline */
770 if (!technology->enable_persistent)
771 __connman_device_disable(device);
773 technology->device_list = g_slist_append(technology->device_list,
779 int __connman_technology_remove_device(struct connman_device *device)
781 struct connman_technology *technology;
782 enum connman_service_type type;
784 DBG("device %p", device);
786 type = __connman_device_get_service_type(device);
787 __connman_notifier_unregister(type);
789 technology = technology_find(type);
790 if (technology == NULL)
793 technology->device_list = g_slist_remove(technology->device_list,
795 if (technology->device_list == NULL) {
796 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
797 state_changed(technology);
803 static gboolean technology_pending_reply(gpointer user_data)
805 struct connman_technology *technology = user_data;
808 /* Power request timedout, send ETIMEDOUT. */
809 if (technology->pending_reply != NULL) {
810 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
812 g_dbus_send_message(connection, reply);
814 dbus_message_unref(technology->pending_reply);
815 technology->pending_reply = NULL;
816 technology->pending_timeout = 0;
822 int __connman_technology_enabled(enum connman_service_type type)
824 struct connman_technology *technology;
826 technology = technology_find(type);
827 if (technology == NULL)
830 if (__sync_fetch_and_add(&technology->enabled, 1) == 0) {
831 __connman_notifier_enable(type);
832 technology->state = CONNMAN_TECHNOLOGY_STATE_ENABLED;
833 state_changed(technology);
836 if (technology->pending_reply != NULL) {
837 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
838 dbus_message_unref(technology->pending_reply);
839 g_source_remove(technology->pending_timeout);
840 technology->pending_reply = NULL;
841 technology->pending_timeout = 0;
847 int __connman_technology_enable(enum connman_service_type type, DBusMessage *msg)
849 struct connman_technology *technology;
855 DBG("type %d enable", type);
857 technology = technology_find(type);
858 if (technology == NULL) {
863 if (technology->pending_reply != NULL) {
870 * This is a bit of a trick. When msg is not NULL it means
871 * thats technology_enable was invoked from the manager API. Hence we save
874 technology->enable_persistent = TRUE;
875 save_state(technology);
878 __connman_rfkill_block(technology->type, FALSE);
881 * An empty device list means that devices in the technology
882 * were rfkill blocked. The unblock above will enable the devs.
884 if (technology->device_list == NULL) {
889 for (list = technology->device_list; list; list = list->next) {
890 struct connman_device *device = list->data;
892 err = __connman_device_enable(device);
894 * err = 0 : Device was enabled right away.
895 * If atleast one device gets enabled, we consider
896 * the technology to be enabled.
905 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
910 if (err == -EINPROGRESS) {
911 technology->pending_reply = dbus_message_ref(msg);
912 technology->pending_timeout = g_timeout_add_seconds(10,
913 technology_pending_reply, technology);
915 reply = __connman_error_failed(msg, -err);
917 g_dbus_send_message(connection, reply);
924 int __connman_technology_disabled(enum connman_service_type type)
926 struct connman_technology *technology;
928 technology = technology_find(type);
929 if (technology == NULL)
932 if (technology->pending_reply != NULL) {
933 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
934 dbus_message_unref(technology->pending_reply);
935 g_source_remove(technology->pending_timeout);
936 technology->pending_reply = NULL;
937 technology->pending_timeout = 0;
940 if (__sync_fetch_and_sub(&technology->enabled, 1) != 1)
943 __connman_notifier_disable(type);
944 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
945 state_changed(technology);
950 int __connman_technology_disable(enum connman_service_type type, DBusMessage *msg)
952 struct connman_technology *technology;
958 DBG("type %d disable", type);
960 technology = technology_find(type);
961 if (technology == NULL) {
966 if (technology->pending_reply != NULL) {
971 if (technology->tethering == TRUE)
972 set_tethering(technology, FALSE);
975 technology->enable_persistent = FALSE;
976 save_state(technology);
979 __connman_rfkill_block(technology->type, TRUE);
981 for (list = technology->device_list; list; list = list->next) {
982 struct connman_device *device = list->data;
984 err = __connman_device_disable(device);
992 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
997 if (err == -EINPROGRESS) {
998 technology->pending_reply = dbus_message_ref(msg);
999 technology->pending_timeout = g_timeout_add_seconds(10,
1000 technology_pending_reply, technology);
1002 reply = __connman_error_failed(msg, -err);
1004 g_dbus_send_message(connection, reply);
1011 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1016 if (global_offlinemode == offlinemode)
1019 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1022 * This is a bit tricky. When you set offlinemode, there is no
1023 * way to differentiate between attempting offline mode and
1024 * resuming offlinemode from last saved profile. We need that
1025 * information in rfkill_update, otherwise it falls back on the
1026 * technology's persistent state. Hence we set the offline mode here
1027 * but save it & call the notifier only if its successful.
1030 global_offlinemode = offlinemode;
1032 /* Traverse technology list, enable/disable each technology. */
1033 for (list = technology_list; list; list = list->next) {
1034 struct connman_technology *technology = list->data;
1037 err = __connman_technology_disable(technology->type, NULL);
1039 if (!offlinemode && technology->enable_persistent)
1040 err = __connman_technology_enable(technology->type, NULL);
1043 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1044 connman_technology_save_offlinemode();
1045 __connman_notifier_offlinemode(offlinemode);
1047 global_offlinemode = connman_technology_load_offlinemode();
1052 int __connman_technology_add_rfkill(unsigned int index,
1053 enum connman_service_type type,
1054 connman_bool_t softblock,
1055 connman_bool_t hardblock)
1057 struct connman_technology *technology;
1058 struct connman_rfkill *rfkill;
1060 DBG("index %u type %d soft %u hard %u", index, type,
1061 softblock, hardblock);
1063 technology = technology_get(type);
1064 if (technology == NULL)
1067 rfkill = g_try_new0(struct connman_rfkill, 1);
1071 __connman_notifier_register(type);
1073 rfkill->index = index;
1074 rfkill->type = type;
1075 rfkill->softblock = softblock;
1076 rfkill->hardblock = hardblock;
1078 g_hash_table_replace(technology->rfkill_list, &rfkill->index, rfkill);
1081 DBG("%s is switched off.", get_name(type));
1086 * If Offline mode is on, we softblock the device if it isnt already.
1087 * If Offline mode is off, we rely on the persistent state of tech.
1089 if (global_offlinemode) {
1091 return __connman_rfkill_block(type, TRUE);
1093 if (technology->enable_persistent && softblock)
1094 return __connman_rfkill_block(type, FALSE);
1095 /* if technology persistent state is offline */
1096 if (!technology->enable_persistent && !softblock)
1097 return __connman_rfkill_block(type, TRUE);
1103 int __connman_technology_update_rfkill(unsigned int index,
1104 enum connman_service_type type,
1105 connman_bool_t softblock,
1106 connman_bool_t hardblock)
1108 struct connman_technology *technology;
1109 struct connman_rfkill *rfkill;
1111 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1113 technology = technology_find(type);
1114 if (technology == NULL)
1117 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1121 if (rfkill->softblock == softblock &&
1122 rfkill->hardblock == hardblock)
1125 rfkill->softblock = softblock;
1126 rfkill->hardblock = hardblock;
1129 DBG("%s is switched off.", get_name(type));
1133 if (!global_offlinemode) {
1134 if (technology->enable_persistent && softblock)
1135 return __connman_rfkill_block(type, FALSE);
1136 if (!technology->enable_persistent && !softblock)
1137 return __connman_rfkill_block(type, TRUE);
1143 int __connman_technology_remove_rfkill(unsigned int index,
1144 enum connman_service_type type)
1146 struct connman_technology *technology;
1147 struct connman_rfkill *rfkill;
1149 DBG("index %u", index);
1151 technology = technology_find(type);
1152 if (technology == NULL)
1155 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1159 g_hash_table_remove(technology->rfkill_list, &index);
1161 technology_put(technology);
1166 int __connman_technology_init(void)
1170 connection = connman_dbus_get_connection();
1172 global_offlinemode = connman_technology_load_offlinemode();
1177 void __connman_technology_cleanup(void)
1181 dbus_connection_unref(connection);