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;
397 connman_bool_t powered;
399 connman_dbus_dict_open(iter, &dict);
401 str = state2string(technology->state);
403 connman_dbus_dict_append_basic(&dict, "State",
404 DBUS_TYPE_STRING, &str);
406 str = get_name(technology->type);
408 connman_dbus_dict_append_basic(&dict, "Name",
409 DBUS_TYPE_STRING, &str);
411 str = __connman_service_type2string(technology->type);
413 connman_dbus_dict_append_basic(&dict, "Type",
414 DBUS_TYPE_STRING, &str);
416 __sync_synchronize();
417 if (technology->enabled > 0)
421 connman_dbus_dict_append_basic(&dict, "Powered",
422 DBUS_TYPE_BOOLEAN, &powered);
424 connman_dbus_dict_append_basic(&dict, "Tethering",
426 &technology->tethering);
428 if (technology->tethering_ident != NULL)
429 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
431 &technology->tethering_ident);
433 if (technology->tethering_passphrase != NULL)
434 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
436 &technology->tethering_passphrase);
438 connman_dbus_dict_close(iter, &dict);
441 static void technology_added_signal(struct connman_technology *technology)
444 DBusMessageIter iter;
446 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
447 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
451 dbus_message_iter_init_append(signal, &iter);
452 append_properties(&iter, technology);
454 dbus_connection_send(connection, signal, NULL);
455 dbus_message_unref(signal);
458 static void technology_removed_signal(struct connman_technology *technology)
460 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
461 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
462 DBUS_TYPE_OBJECT_PATH, technology->path,
466 static DBusMessage *get_properties(DBusConnection *conn,
467 DBusMessage *message, void *user_data)
469 struct connman_technology *technology = user_data;
471 DBusMessageIter iter;
473 reply = dbus_message_new_method_return(message);
477 dbus_message_iter_init_append(reply, &iter);
478 append_properties(&iter, technology);
483 void __connman_technology_list_struct(DBusMessageIter *array)
486 DBusMessageIter entry;
488 for (list = technology_list; list; list = list->next) {
489 struct connman_technology *technology = list->data;
491 if (technology->path == NULL)
494 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
496 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
498 append_properties(&entry, technology);
499 dbus_message_iter_close_container(array, &entry);
503 static gboolean technology_pending_reply(gpointer user_data)
505 struct connman_technology *technology = user_data;
508 /* Power request timedout, send ETIMEDOUT. */
509 if (technology->pending_reply != NULL) {
510 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
512 g_dbus_send_message(connection, reply);
514 dbus_message_unref(technology->pending_reply);
515 technology->pending_reply = NULL;
516 technology->pending_timeout = 0;
522 static int technology_enable(struct connman_technology *technology,
530 DBG("technology %p enable", technology);
532 __sync_synchronize();
533 if (technology->enabled > 0) {
538 if (technology->pending_reply != NULL) {
545 * This is a bit of a trick. When msg is not NULL it means
546 * thats technology_enable was invoked from the manager API.
547 * Hence we save the state here.
549 technology->enable_persistent = TRUE;
550 save_state(technology);
553 __connman_rfkill_block(technology->type, FALSE);
556 * An empty device list means that devices in the technology
557 * were rfkill blocked. The unblock above will enable the devs.
559 if (technology->device_list == NULL) {
564 for (list = technology->device_list; list; list = list->next) {
565 struct connman_device *device = list->data;
567 err = __connman_device_enable(device);
569 * err = 0 : Device was enabled right away.
570 * If atleast one device gets enabled, we consider
571 * the technology to be enabled.
580 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
585 if (err == -EINPROGRESS) {
586 technology->pending_reply = dbus_message_ref(msg);
587 technology->pending_timeout = g_timeout_add_seconds(10,
588 technology_pending_reply, technology);
590 reply = __connman_error_failed(msg, -err);
592 g_dbus_send_message(connection, reply);
599 static int technology_disable(struct connman_technology *technology,
607 DBG("technology %p disable", technology);
609 __sync_synchronize();
610 if (technology->enabled == 0) {
615 if (technology->pending_reply != NULL) {
620 if (technology->tethering == TRUE)
621 set_tethering(technology, FALSE);
624 technology->enable_persistent = FALSE;
625 save_state(technology);
628 __connman_rfkill_block(technology->type, TRUE);
630 for (list = technology->device_list; list; list = list->next) {
631 struct connman_device *device = list->data;
633 err = __connman_device_disable(device);
641 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
646 if (err == -EINPROGRESS) {
647 technology->pending_reply = dbus_message_ref(msg);
648 technology->pending_timeout = g_timeout_add_seconds(10,
649 technology_pending_reply, technology);
651 reply = __connman_error_failed(msg, -err);
653 g_dbus_send_message(connection, reply);
660 static DBusMessage *set_property(DBusConnection *conn,
661 DBusMessage *msg, void *data)
663 struct connman_technology *technology = data;
664 DBusMessageIter iter, value;
668 DBG("conn %p", conn);
670 if (dbus_message_iter_init(msg, &iter) == FALSE)
671 return __connman_error_invalid_arguments(msg);
673 dbus_message_iter_get_basic(&iter, &name);
674 dbus_message_iter_next(&iter);
675 dbus_message_iter_recurse(&iter, &value);
677 type = dbus_message_iter_get_arg_type(&value);
679 DBG("property %s", name);
681 if (g_str_equal(name, "Tethering") == TRUE) {
683 connman_bool_t tethering;
685 if (type != DBUS_TYPE_BOOLEAN)
686 return __connman_error_invalid_arguments(msg);
688 dbus_message_iter_get_basic(&value, &tethering);
690 if (technology->tethering == tethering)
691 return __connman_error_in_progress(msg);
693 err = set_tethering(technology, tethering);
695 return __connman_error_failed(msg, -err);
697 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
700 dbus_message_iter_get_basic(&value, &str);
702 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
703 return __connman_error_not_supported(msg);
705 technology->tethering_ident = g_strdup(str);
706 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
709 dbus_message_iter_get_basic(&value, &str);
711 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
712 return __connman_error_not_supported(msg);
715 return __connman_error_invalid_arguments(msg);
717 technology->tethering_passphrase = g_strdup(str);
718 } else if (g_str_equal(name, "Powered") == TRUE) {
719 connman_bool_t enable;
721 if (type != DBUS_TYPE_BOOLEAN)
722 return __connman_error_invalid_arguments(msg);
724 dbus_message_iter_get_basic(&value, &enable);
726 technology_enable(technology, msg);
728 technology_disable(technology, msg);
731 return __connman_error_invalid_property(msg);
733 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
736 static GDBusMethodTable technology_methods[] = {
737 { "GetProperties", "", "a{sv}", get_properties },
738 { "SetProperty", "sv", "", set_property },
742 static GDBusSignalTable technology_signals[] = {
743 { "PropertyChanged", "sv" },
747 static struct connman_technology *technology_find(enum connman_service_type type)
751 DBG("type %d", type);
753 for (list = technology_list; list; list = list->next) {
754 struct connman_technology *technology = list->data;
756 if (technology->type == type)
763 static struct connman_technology *technology_get(enum connman_service_type type)
765 struct connman_technology *technology;
766 struct connman_technology_driver *driver = NULL;
771 DBG("type %d", type);
773 str = __connman_service_type2string(type);
777 technology = technology_find(type);
778 if (technology != NULL)
781 /* First check if we have a driver for this technology type */
782 for (list = driver_list; list; list = list->next) {
785 if (driver->type == type)
791 if (driver == NULL) {
792 DBG("No matching driver found for %s.",
793 __connman_service_type2string(type));
797 technology = g_try_new0(struct connman_technology, 1);
798 if (technology == NULL)
801 technology->refcount = 1;
803 technology->type = type;
804 technology->path = g_strdup_printf("%s/technology/%s",
807 technology->rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
809 technology->device_list = NULL;
811 technology->pending_reply = NULL;
812 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
814 load_state(technology);
816 if (g_dbus_register_interface(connection, technology->path,
817 CONNMAN_TECHNOLOGY_INTERFACE,
818 technology_methods, technology_signals,
819 NULL, technology, NULL) == FALSE) {
820 connman_error("Failed to register %s", technology->path);
825 technology_list = g_slist_append(technology_list, technology);
827 technology_added_signal(technology);
829 technology->driver = driver;
830 err = driver->probe(technology);
832 DBG("Driver probe failed for technology %p", technology);
834 DBG("technology %p", technology);
839 static void technology_put(struct connman_technology *technology)
841 DBG("technology %p", technology);
843 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
846 if (technology->driver) {
847 technology->driver->remove(technology);
848 technology->driver = NULL;
851 technology_list = g_slist_remove(technology_list, technology);
853 technology_removed_signal(technology);
855 g_dbus_unregister_interface(connection, technology->path,
856 CONNMAN_TECHNOLOGY_INTERFACE);
858 g_slist_free(technology->device_list);
859 g_hash_table_destroy(technology->rfkill_list);
861 g_free(technology->path);
862 g_free(technology->regdom);
866 void __connman_technology_add_interface(enum connman_service_type type,
867 int index, const char *name, const char *ident)
869 struct connman_technology *technology;
872 case CONNMAN_SERVICE_TYPE_UNKNOWN:
873 case CONNMAN_SERVICE_TYPE_SYSTEM:
875 case CONNMAN_SERVICE_TYPE_ETHERNET:
876 case CONNMAN_SERVICE_TYPE_WIFI:
877 case CONNMAN_SERVICE_TYPE_WIMAX:
878 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
879 case CONNMAN_SERVICE_TYPE_CELLULAR:
880 case CONNMAN_SERVICE_TYPE_GPS:
881 case CONNMAN_SERVICE_TYPE_VPN:
882 case CONNMAN_SERVICE_TYPE_GADGET:
886 connman_info("Adding interface %s [ %s ]", name,
887 __connman_service_type2string(type));
889 technology = technology_find(type);
891 if (technology == NULL || technology->driver == NULL
892 || technology->driver->add_interface == NULL)
895 technology->driver->add_interface(technology,
899 void __connman_technology_remove_interface(enum connman_service_type type,
900 int index, const char *name, const char *ident)
902 struct connman_technology *technology;
905 case CONNMAN_SERVICE_TYPE_UNKNOWN:
906 case CONNMAN_SERVICE_TYPE_SYSTEM:
908 case CONNMAN_SERVICE_TYPE_ETHERNET:
909 case CONNMAN_SERVICE_TYPE_WIFI:
910 case CONNMAN_SERVICE_TYPE_WIMAX:
911 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
912 case CONNMAN_SERVICE_TYPE_CELLULAR:
913 case CONNMAN_SERVICE_TYPE_GPS:
914 case CONNMAN_SERVICE_TYPE_VPN:
915 case CONNMAN_SERVICE_TYPE_GADGET:
919 connman_info("Remove interface %s [ %s ]", name,
920 __connman_service_type2string(type));
922 technology = technology_find(type);
924 if (technology == NULL || technology->driver == NULL)
927 if (technology->driver->remove_interface)
928 technology->driver->remove_interface(technology, index);
931 int __connman_technology_add_device(struct connman_device *device)
933 struct connman_technology *technology;
934 enum connman_service_type type;
936 DBG("device %p", device);
938 type = __connman_device_get_service_type(device);
939 __connman_notifier_register(type);
941 technology = technology_get(type);
942 if (technology == NULL)
945 if (technology->enable_persistent && !global_offlinemode)
946 __connman_device_enable(device);
947 /* if technology persistent state is offline */
948 if (!technology->enable_persistent)
949 __connman_device_disable(device);
951 technology->device_list = g_slist_append(technology->device_list,
957 int __connman_technology_remove_device(struct connman_device *device)
959 struct connman_technology *technology;
960 enum connman_service_type type;
962 DBG("device %p", device);
964 type = __connman_device_get_service_type(device);
965 __connman_notifier_unregister(type);
967 technology = technology_find(type);
968 if (technology == NULL)
971 technology->device_list = g_slist_remove(technology->device_list,
973 if (technology->device_list == NULL) {
974 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
975 state_changed(technology);
981 static void powered_changed(struct connman_technology *technology)
983 connman_bool_t powered;
985 __sync_synchronize();
986 if (technology->enabled >0)
991 connman_dbus_property_changed_basic(technology->path,
992 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
993 DBUS_TYPE_BOOLEAN, &powered);
996 int __connman_technology_enabled(enum connman_service_type type)
998 struct connman_technology *technology;
1000 technology = technology_find(type);
1001 if (technology == NULL)
1004 if (__sync_fetch_and_add(&technology->enabled, 1) == 0) {
1005 __connman_notifier_enable(type);
1006 technology->state = CONNMAN_TECHNOLOGY_STATE_ENABLED;
1007 state_changed(technology);
1008 powered_changed(technology);
1011 if (technology->pending_reply != NULL) {
1012 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1013 dbus_message_unref(technology->pending_reply);
1014 g_source_remove(technology->pending_timeout);
1015 technology->pending_reply = NULL;
1016 technology->pending_timeout = 0;
1022 int __connman_technology_disabled(enum connman_service_type type)
1024 struct connman_technology *technology;
1026 technology = technology_find(type);
1027 if (technology == NULL)
1030 if (technology->pending_reply != NULL) {
1031 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1032 dbus_message_unref(technology->pending_reply);
1033 g_source_remove(technology->pending_timeout);
1034 technology->pending_reply = NULL;
1035 technology->pending_timeout = 0;
1038 if (__sync_fetch_and_sub(&technology->enabled, 1) != 1)
1041 __connman_notifier_disable(type);
1042 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
1043 state_changed(technology);
1044 powered_changed(technology);
1049 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1054 if (global_offlinemode == offlinemode)
1057 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1060 * This is a bit tricky. When you set offlinemode, there is no
1061 * way to differentiate between attempting offline mode and
1062 * resuming offlinemode from last saved profile. We need that
1063 * information in rfkill_update, otherwise it falls back on the
1064 * technology's persistent state. Hence we set the offline mode here
1065 * but save it & call the notifier only if its successful.
1068 global_offlinemode = offlinemode;
1070 /* Traverse technology list, enable/disable each technology. */
1071 for (list = technology_list; list; list = list->next) {
1072 struct connman_technology *technology = list->data;
1075 err = technology_disable(technology, NULL);
1077 if (!offlinemode && technology->enable_persistent)
1078 err = technology_enable(technology, NULL);
1081 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1082 connman_technology_save_offlinemode();
1083 __connman_notifier_offlinemode(offlinemode);
1085 global_offlinemode = connman_technology_load_offlinemode();
1090 int __connman_technology_add_rfkill(unsigned int index,
1091 enum connman_service_type type,
1092 connman_bool_t softblock,
1093 connman_bool_t hardblock)
1095 struct connman_technology *technology;
1096 struct connman_rfkill *rfkill;
1098 DBG("index %u type %d soft %u hard %u", index, type,
1099 softblock, hardblock);
1101 technology = technology_get(type);
1102 if (technology == NULL)
1105 rfkill = g_try_new0(struct connman_rfkill, 1);
1109 __connman_notifier_register(type);
1111 rfkill->index = index;
1112 rfkill->type = type;
1113 rfkill->softblock = softblock;
1114 rfkill->hardblock = hardblock;
1116 g_hash_table_replace(technology->rfkill_list, &rfkill->index, rfkill);
1119 DBG("%s is switched off.", get_name(type));
1124 * If Offline mode is on, we softblock the device if it isnt already.
1125 * If Offline mode is off, we rely on the persistent state of tech.
1127 if (global_offlinemode) {
1129 return __connman_rfkill_block(type, TRUE);
1131 if (technology->enable_persistent && softblock)
1132 return __connman_rfkill_block(type, FALSE);
1133 /* if technology persistent state is offline */
1134 if (!technology->enable_persistent && !softblock)
1135 return __connman_rfkill_block(type, TRUE);
1141 int __connman_technology_update_rfkill(unsigned int index,
1142 enum connman_service_type type,
1143 connman_bool_t softblock,
1144 connman_bool_t hardblock)
1146 struct connman_technology *technology;
1147 struct connman_rfkill *rfkill;
1149 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1151 technology = technology_find(type);
1152 if (technology == NULL)
1155 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1159 if (rfkill->softblock == softblock &&
1160 rfkill->hardblock == hardblock)
1163 rfkill->softblock = softblock;
1164 rfkill->hardblock = hardblock;
1167 DBG("%s is switched off.", get_name(type));
1171 if (!global_offlinemode) {
1172 if (technology->enable_persistent && softblock)
1173 return __connman_rfkill_block(type, FALSE);
1174 if (!technology->enable_persistent && !softblock)
1175 return __connman_rfkill_block(type, TRUE);
1181 int __connman_technology_remove_rfkill(unsigned int index,
1182 enum connman_service_type type)
1184 struct connman_technology *technology;
1185 struct connman_rfkill *rfkill;
1187 DBG("index %u", index);
1189 technology = technology_find(type);
1190 if (technology == NULL)
1193 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1197 g_hash_table_remove(technology->rfkill_list, &index);
1199 technology_put(technology);
1204 int __connman_technology_init(void)
1208 connection = connman_dbus_get_connection();
1210 global_offlinemode = connman_technology_load_offlinemode();
1215 void __connman_technology_cleanup(void)
1219 dbus_connection_unref(connection);