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;
38 * List of devices with no technology associated with them either because of
39 * no compiled in support or the driver is not yet loaded.
41 static GSList *techless_device_list = NULL;
43 static connman_bool_t global_offlinemode;
45 struct connman_rfkill {
47 enum connman_service_type type;
48 connman_bool_t softblock;
49 connman_bool_t hardblock;
52 struct connman_technology {
54 enum connman_service_type type;
56 GHashTable *rfkill_list;
60 connman_bool_t connected;
62 connman_bool_t tethering;
63 char *tethering_ident;
64 char *tethering_passphrase;
66 connman_bool_t enable_persistent; /* Save the tech state */
68 struct connman_technology_driver *driver;
71 DBusMessage *pending_reply;
72 guint pending_timeout;
75 static GSList *driver_list = NULL;
77 static gint compare_priority(gconstpointer a, gconstpointer b)
79 const struct connman_technology_driver *driver1 = a;
80 const struct connman_technology_driver *driver2 = b;
82 return driver2->priority - driver1->priority;
86 * connman_technology_driver_register:
87 * @driver: Technology driver definition
89 * Register a new technology driver
91 * Returns: %0 on success
93 int connman_technology_driver_register(struct connman_technology_driver *driver)
96 struct connman_device *device;
97 enum connman_service_type type;
99 DBG("Registering %s driver", driver->name);
101 driver_list = g_slist_insert_sorted(driver_list, driver,
104 if (techless_device_list == NULL)
108 * Check for technology less devices if this driver
109 * can service any of them.
111 for (list = techless_device_list; list; list = list->next) {
114 type = __connman_device_get_service_type(device);
115 if (type != driver->type)
118 techless_device_list = g_slist_remove(techless_device_list,
121 __connman_technology_add_device(device);
128 * connman_technology_driver_unregister:
129 * @driver: Technology driver definition
131 * Remove a previously registered technology driver
133 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
136 struct connman_technology *technology;
138 DBG("Unregistering driver %p name %s", driver, driver->name);
140 for (list = technology_list; list; list = list->next) {
141 technology = list->data;
143 if (technology->driver == NULL)
146 if (technology->type == driver->type) {
147 technology->driver->remove(technology);
148 technology->driver = NULL;
152 driver_list = g_slist_remove(driver_list, driver);
155 static void tethering_changed(struct connman_technology *technology)
157 connman_bool_t tethering = technology->tethering;
159 connman_dbus_property_changed_basic(technology->path,
160 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
161 DBUS_TYPE_BOOLEAN, &tethering);
164 void connman_technology_tethering_notify(struct connman_technology *technology,
165 connman_bool_t enabled)
169 DBG("technology %p enabled %u", technology, enabled);
171 if (technology->tethering == enabled)
174 technology->tethering = enabled;
176 tethering_changed(technology);
179 __connman_tethering_set_enabled();
181 for (list = technology_list; list; list = list->next) {
182 struct connman_technology *other_tech = list->data;
183 if (other_tech->tethering == TRUE)
187 __connman_tethering_set_disabled();
191 static int set_tethering(struct connman_technology *technology,
192 connman_bool_t enabled)
194 const char *ident, *passphrase, *bridge;
196 ident = technology->tethering_ident;
197 passphrase = technology->tethering_passphrase;
199 if (technology->driver == NULL ||
200 technology->driver->set_tethering == NULL)
203 bridge = __connman_tethering_get_bridge();
207 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
208 (ident == NULL || passphrase == NULL))
211 return technology->driver->set_tethering(technology, ident, passphrase,
215 void connman_technology_regdom_notify(struct connman_technology *technology,
221 connman_error("Failed to set regulatory domain");
223 DBG("Regulatory domain set to %s", alpha2);
225 g_free(technology->regdom);
226 technology->regdom = g_strdup(alpha2);
229 int connman_technology_set_regdom(const char *alpha2)
233 for (list = technology_list; list; list = list->next) {
234 struct connman_technology *technology = list->data;
236 if (technology->driver == NULL)
239 if (technology->driver->set_regdom)
240 technology->driver->set_regdom(technology, alpha2);
246 static void free_rfkill(gpointer data)
248 struct connman_rfkill *rfkill = data;
253 static const char *get_name(enum connman_service_type type)
256 case CONNMAN_SERVICE_TYPE_UNKNOWN:
257 case CONNMAN_SERVICE_TYPE_SYSTEM:
258 case CONNMAN_SERVICE_TYPE_GPS:
259 case CONNMAN_SERVICE_TYPE_VPN:
260 case CONNMAN_SERVICE_TYPE_GADGET:
262 case CONNMAN_SERVICE_TYPE_ETHERNET:
264 case CONNMAN_SERVICE_TYPE_WIFI:
266 case CONNMAN_SERVICE_TYPE_WIMAX:
268 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
270 case CONNMAN_SERVICE_TYPE_CELLULAR:
277 static void load_state(struct connman_technology *technology)
281 GError *error = NULL;
282 connman_bool_t enable;
284 DBG("technology %p", technology);
286 keyfile = __connman_storage_load_global();
287 /* Fallback on disabling technology if file not found. */
288 if (keyfile == NULL) {
289 technology->enable_persistent = FALSE;
293 identifier = g_strdup_printf("%s", get_name(technology->type));
294 if (identifier == NULL)
297 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
299 technology->enable_persistent = enable;
301 technology->enable_persistent = FALSE;
302 g_clear_error(&error);
307 g_key_file_free(keyfile);
312 static void save_state(struct connman_technology *technology)
317 DBG("technology %p", technology);
319 keyfile = __connman_storage_load_global();
321 keyfile = g_key_file_new();
323 identifier = g_strdup_printf("%s", get_name(technology->type));
324 if (identifier == NULL)
327 g_key_file_set_boolean(keyfile, identifier, "Enable",
328 technology->enable_persistent);
333 __connman_storage_save_global(keyfile);
335 g_key_file_free(keyfile);
340 connman_bool_t __connman_technology_get_offlinemode(void)
342 return global_offlinemode;
345 static void connman_technology_save_offlinemode()
349 keyfile = __connman_storage_load_global();
351 keyfile = g_key_file_new();
353 g_key_file_set_boolean(keyfile, "global",
354 "OfflineMode", global_offlinemode);
356 __connman_storage_save_global(keyfile);
358 g_key_file_free(keyfile);
363 static connman_bool_t connman_technology_load_offlinemode()
366 GError *error = NULL;
367 connman_bool_t offlinemode;
369 /* If there is a error, we enable offlinemode */
370 keyfile = __connman_storage_load_global();
374 offlinemode = g_key_file_get_boolean(keyfile, "global",
375 "OfflineMode", &error);
378 g_clear_error(&error);
381 g_key_file_free(keyfile);
386 static void append_properties(DBusMessageIter *iter,
387 struct connman_technology *technology)
389 DBusMessageIter dict;
391 connman_bool_t powered;
393 connman_dbus_dict_open(iter, &dict);
395 str = get_name(technology->type);
397 connman_dbus_dict_append_basic(&dict, "Name",
398 DBUS_TYPE_STRING, &str);
400 str = __connman_service_type2string(technology->type);
402 connman_dbus_dict_append_basic(&dict, "Type",
403 DBUS_TYPE_STRING, &str);
405 __sync_synchronize();
406 if (technology->enabled > 0)
410 connman_dbus_dict_append_basic(&dict, "Powered",
411 DBUS_TYPE_BOOLEAN, &powered);
413 connman_dbus_dict_append_basic(&dict, "Connected",
415 &technology->connected);
417 connman_dbus_dict_append_basic(&dict, "Tethering",
419 &technology->tethering);
421 if (technology->tethering_ident != NULL)
422 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
424 &technology->tethering_ident);
426 if (technology->tethering_passphrase != NULL)
427 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
429 &technology->tethering_passphrase);
431 connman_dbus_dict_close(iter, &dict);
434 static void technology_added_signal(struct connman_technology *technology)
437 DBusMessageIter iter;
439 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
440 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
444 dbus_message_iter_init_append(signal, &iter);
445 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
447 append_properties(&iter, technology);
449 dbus_connection_send(connection, signal, NULL);
450 dbus_message_unref(signal);
453 static void technology_removed_signal(struct connman_technology *technology)
455 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
456 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
457 DBUS_TYPE_OBJECT_PATH, &technology->path,
461 static DBusMessage *get_properties(DBusConnection *conn,
462 DBusMessage *message, void *user_data)
464 struct connman_technology *technology = user_data;
466 DBusMessageIter iter;
468 reply = dbus_message_new_method_return(message);
472 dbus_message_iter_init_append(reply, &iter);
473 append_properties(&iter, technology);
478 void __connman_technology_list_struct(DBusMessageIter *array)
481 DBusMessageIter entry;
483 for (list = technology_list; list; list = list->next) {
484 struct connman_technology *technology = list->data;
486 if (technology->path == NULL)
489 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
491 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
493 append_properties(&entry, technology);
494 dbus_message_iter_close_container(array, &entry);
498 static gboolean technology_pending_reply(gpointer user_data)
500 struct connman_technology *technology = user_data;
503 /* Power request timedout, send ETIMEDOUT. */
504 if (technology->pending_reply != NULL) {
505 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
507 g_dbus_send_message(connection, reply);
509 dbus_message_unref(technology->pending_reply);
510 technology->pending_reply = NULL;
511 technology->pending_timeout = 0;
517 static int technology_enable(struct connman_technology *technology,
525 DBG("technology %p enable", technology);
527 __sync_synchronize();
528 if (technology->enabled > 0) {
533 if (technology->pending_reply != NULL) {
540 * This is a bit of a trick. When msg is not NULL it means
541 * thats technology_enable was invoked from the manager API.
542 * Hence we save the state here.
544 technology->enable_persistent = TRUE;
545 save_state(technology);
548 __connman_rfkill_block(technology->type, FALSE);
551 * An empty device list means that devices in the technology
552 * were rfkill blocked. The unblock above will enable the devs.
554 if (technology->device_list == NULL) {
559 for (list = technology->device_list; list; list = list->next) {
560 struct connman_device *device = list->data;
562 err = __connman_device_enable(device);
564 * err = 0 : Device was enabled right away.
565 * If atleast one device gets enabled, we consider
566 * the technology to be enabled.
575 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
580 if (err == -EINPROGRESS) {
581 technology->pending_reply = dbus_message_ref(msg);
582 technology->pending_timeout = g_timeout_add_seconds(10,
583 technology_pending_reply, technology);
585 reply = __connman_error_failed(msg, -err);
587 g_dbus_send_message(connection, reply);
594 static int technology_disable(struct connman_technology *technology,
602 DBG("technology %p disable", technology);
604 __sync_synchronize();
605 if (technology->enabled == 0) {
610 if (technology->pending_reply != NULL) {
615 if (technology->tethering == TRUE)
616 set_tethering(technology, FALSE);
619 technology->enable_persistent = FALSE;
620 save_state(technology);
623 __connman_rfkill_block(technology->type, TRUE);
625 for (list = technology->device_list; list; list = list->next) {
626 struct connman_device *device = list->data;
628 err = __connman_device_disable(device);
636 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
641 if (err == -EINPROGRESS) {
642 technology->pending_reply = dbus_message_ref(msg);
643 technology->pending_timeout = g_timeout_add_seconds(10,
644 technology_pending_reply, technology);
646 reply = __connman_error_failed(msg, -err);
648 g_dbus_send_message(connection, reply);
655 static DBusMessage *set_property(DBusConnection *conn,
656 DBusMessage *msg, void *data)
658 struct connman_technology *technology = data;
659 DBusMessageIter iter, value;
663 DBG("conn %p", conn);
665 if (dbus_message_iter_init(msg, &iter) == FALSE)
666 return __connman_error_invalid_arguments(msg);
668 dbus_message_iter_get_basic(&iter, &name);
669 dbus_message_iter_next(&iter);
670 dbus_message_iter_recurse(&iter, &value);
672 type = dbus_message_iter_get_arg_type(&value);
674 DBG("property %s", name);
676 if (g_str_equal(name, "Tethering") == TRUE) {
678 connman_bool_t tethering;
680 if (type != DBUS_TYPE_BOOLEAN)
681 return __connman_error_invalid_arguments(msg);
683 dbus_message_iter_get_basic(&value, &tethering);
685 if (technology->tethering == tethering)
686 return __connman_error_in_progress(msg);
688 err = set_tethering(technology, tethering);
690 return __connman_error_failed(msg, -err);
692 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
695 dbus_message_iter_get_basic(&value, &str);
697 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
698 return __connman_error_not_supported(msg);
700 technology->tethering_ident = g_strdup(str);
701 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
704 dbus_message_iter_get_basic(&value, &str);
706 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
707 return __connman_error_not_supported(msg);
710 return __connman_error_invalid_arguments(msg);
712 technology->tethering_passphrase = g_strdup(str);
713 } else if (g_str_equal(name, "Powered") == TRUE) {
714 connman_bool_t enable;
716 if (type != DBUS_TYPE_BOOLEAN)
717 return __connman_error_invalid_arguments(msg);
719 dbus_message_iter_get_basic(&value, &enable);
721 technology_enable(technology, msg);
723 technology_disable(technology, msg);
726 return __connman_error_invalid_property(msg);
728 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
731 static GDBusMethodTable technology_methods[] = {
732 { "GetProperties", "", "a{sv}", get_properties },
733 { "SetProperty", "sv", "", set_property },
737 static GDBusSignalTable technology_signals[] = {
738 { "PropertyChanged", "sv" },
742 static struct connman_technology *technology_find(enum connman_service_type type)
746 DBG("type %d", type);
748 for (list = technology_list; list; list = list->next) {
749 struct connman_technology *technology = list->data;
751 if (technology->type == type)
758 static struct connman_technology *technology_get(enum connman_service_type type)
760 struct connman_technology *technology;
761 struct connman_technology_driver *driver = NULL;
766 DBG("type %d", type);
768 str = __connman_service_type2string(type);
772 technology = technology_find(type);
773 if (technology != NULL)
776 /* First check if we have a driver for this technology type */
777 for (list = driver_list; list; list = list->next) {
780 if (driver->type == type)
786 if (driver == NULL) {
787 DBG("No matching driver found for %s.",
788 __connman_service_type2string(type));
792 technology = g_try_new0(struct connman_technology, 1);
793 if (technology == NULL)
796 technology->refcount = 1;
798 technology->type = type;
799 technology->path = g_strdup_printf("%s/technology/%s",
802 technology->rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
804 technology->device_list = NULL;
806 technology->pending_reply = NULL;
808 load_state(technology);
810 if (g_dbus_register_interface(connection, technology->path,
811 CONNMAN_TECHNOLOGY_INTERFACE,
812 technology_methods, technology_signals,
813 NULL, technology, NULL) == FALSE) {
814 connman_error("Failed to register %s", technology->path);
819 technology_list = g_slist_append(technology_list, technology);
821 technology_added_signal(technology);
823 technology->driver = driver;
824 err = driver->probe(technology);
826 DBG("Driver probe failed for technology %p", technology);
828 DBG("technology %p", technology);
833 static void technology_put(struct connman_technology *technology)
835 DBG("technology %p", technology);
837 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
840 if (technology->driver) {
841 technology->driver->remove(technology);
842 technology->driver = NULL;
845 technology_list = g_slist_remove(technology_list, technology);
847 technology_removed_signal(technology);
849 g_dbus_unregister_interface(connection, technology->path,
850 CONNMAN_TECHNOLOGY_INTERFACE);
852 g_slist_free(technology->device_list);
853 g_hash_table_destroy(technology->rfkill_list);
855 g_free(technology->path);
856 g_free(technology->regdom);
860 void __connman_technology_add_interface(enum connman_service_type type,
861 int index, const char *name, const char *ident)
863 struct connman_technology *technology;
866 case CONNMAN_SERVICE_TYPE_UNKNOWN:
867 case CONNMAN_SERVICE_TYPE_SYSTEM:
869 case CONNMAN_SERVICE_TYPE_ETHERNET:
870 case CONNMAN_SERVICE_TYPE_WIFI:
871 case CONNMAN_SERVICE_TYPE_WIMAX:
872 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
873 case CONNMAN_SERVICE_TYPE_CELLULAR:
874 case CONNMAN_SERVICE_TYPE_GPS:
875 case CONNMAN_SERVICE_TYPE_VPN:
876 case CONNMAN_SERVICE_TYPE_GADGET:
880 connman_info("Adding interface %s [ %s ]", name,
881 __connman_service_type2string(type));
883 technology = technology_find(type);
885 if (technology == NULL || technology->driver == NULL
886 || technology->driver->add_interface == NULL)
889 technology->driver->add_interface(technology,
893 void __connman_technology_remove_interface(enum connman_service_type type,
894 int index, const char *name, const char *ident)
896 struct connman_technology *technology;
899 case CONNMAN_SERVICE_TYPE_UNKNOWN:
900 case CONNMAN_SERVICE_TYPE_SYSTEM:
902 case CONNMAN_SERVICE_TYPE_ETHERNET:
903 case CONNMAN_SERVICE_TYPE_WIFI:
904 case CONNMAN_SERVICE_TYPE_WIMAX:
905 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
906 case CONNMAN_SERVICE_TYPE_CELLULAR:
907 case CONNMAN_SERVICE_TYPE_GPS:
908 case CONNMAN_SERVICE_TYPE_VPN:
909 case CONNMAN_SERVICE_TYPE_GADGET:
913 connman_info("Remove interface %s [ %s ]", name,
914 __connman_service_type2string(type));
916 technology = technology_find(type);
918 if (technology == NULL || technology->driver == NULL)
921 if (technology->driver->remove_interface)
922 technology->driver->remove_interface(technology, index);
925 int __connman_technology_add_device(struct connman_device *device)
927 struct connman_technology *technology;
928 enum connman_service_type type;
930 DBG("device %p", device);
932 type = __connman_device_get_service_type(device);
934 technology = technology_get(type);
935 if (technology == NULL) {
937 * Since no driver can be found for this device at the moment we
938 * add it to the techless device list.
940 techless_device_list = g_slist_prepend(techless_device_list,
946 if (technology->enable_persistent && !global_offlinemode)
947 __connman_device_enable(device);
948 /* if technology persistent state is offline */
949 if (!technology->enable_persistent)
950 __connman_device_disable(device);
952 technology->device_list = g_slist_append(technology->device_list,
958 int __connman_technology_remove_device(struct connman_device *device)
960 struct connman_technology *technology;
961 enum connman_service_type type;
963 DBG("device %p", device);
965 type = __connman_device_get_service_type(device);
967 technology = technology_find(type);
968 if (technology == NULL) {
969 techless_device_list = g_slist_remove(techless_device_list,
974 technology->device_list = g_slist_remove(technology->device_list,
979 static void powered_changed(struct connman_technology *technology)
981 connman_bool_t powered;
983 __sync_synchronize();
984 if (technology->enabled >0)
989 connman_dbus_property_changed_basic(technology->path,
990 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
991 DBUS_TYPE_BOOLEAN, &powered);
994 int __connman_technology_enabled(enum connman_service_type type)
996 struct connman_technology *technology;
998 technology = technology_find(type);
999 if (technology == NULL)
1002 if (__sync_fetch_and_add(&technology->enabled, 1) == 0)
1003 powered_changed(technology);
1005 if (technology->pending_reply != NULL) {
1006 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1007 dbus_message_unref(technology->pending_reply);
1008 g_source_remove(technology->pending_timeout);
1009 technology->pending_reply = NULL;
1010 technology->pending_timeout = 0;
1016 int __connman_technology_disabled(enum connman_service_type type)
1018 struct connman_technology *technology;
1020 technology = technology_find(type);
1021 if (technology == NULL)
1024 if (technology->pending_reply != NULL) {
1025 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1026 dbus_message_unref(technology->pending_reply);
1027 g_source_remove(technology->pending_timeout);
1028 technology->pending_reply = NULL;
1029 technology->pending_timeout = 0;
1032 if (__sync_fetch_and_sub(&technology->enabled, 1) == 1)
1033 powered_changed(technology);
1038 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1043 if (global_offlinemode == offlinemode)
1046 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1049 * This is a bit tricky. When you set offlinemode, there is no
1050 * way to differentiate between attempting offline mode and
1051 * resuming offlinemode from last saved profile. We need that
1052 * information in rfkill_update, otherwise it falls back on the
1053 * technology's persistent state. Hence we set the offline mode here
1054 * but save it & call the notifier only if its successful.
1057 global_offlinemode = offlinemode;
1059 /* Traverse technology list, enable/disable each technology. */
1060 for (list = technology_list; list; list = list->next) {
1061 struct connman_technology *technology = list->data;
1064 err = technology_disable(technology, NULL);
1066 if (!offlinemode && technology->enable_persistent)
1067 err = technology_enable(technology, NULL);
1070 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1071 connman_technology_save_offlinemode();
1072 __connman_notifier_offlinemode(offlinemode);
1074 global_offlinemode = connman_technology_load_offlinemode();
1079 void __connman_technology_set_connected(enum connman_service_type type,
1080 connman_bool_t connected)
1082 struct connman_technology *technology;
1084 technology = technology_find(type);
1085 if (technology == NULL)
1088 DBG("technology %p connected %d", technology, connected);
1090 technology->connected = connected;
1092 connman_dbus_property_changed_basic(technology->path,
1093 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
1094 DBUS_TYPE_BOOLEAN, &connected);
1097 int __connman_technology_add_rfkill(unsigned int index,
1098 enum connman_service_type type,
1099 connman_bool_t softblock,
1100 connman_bool_t hardblock)
1102 struct connman_technology *technology;
1103 struct connman_rfkill *rfkill;
1105 DBG("index %u type %d soft %u hard %u", index, type,
1106 softblock, hardblock);
1108 technology = technology_get(type);
1109 if (technology == NULL)
1112 rfkill = g_try_new0(struct connman_rfkill, 1);
1116 rfkill->index = index;
1117 rfkill->type = type;
1118 rfkill->softblock = softblock;
1119 rfkill->hardblock = hardblock;
1121 g_hash_table_replace(technology->rfkill_list, &rfkill->index, rfkill);
1124 DBG("%s is switched off.", get_name(type));
1129 * If Offline mode is on, we softblock the device if it isnt already.
1130 * If Offline mode is off, we rely on the persistent state of tech.
1132 if (global_offlinemode) {
1134 return __connman_rfkill_block(type, TRUE);
1136 if (technology->enable_persistent && softblock)
1137 return __connman_rfkill_block(type, FALSE);
1138 /* if technology persistent state is offline */
1139 if (!technology->enable_persistent && !softblock)
1140 return __connman_rfkill_block(type, TRUE);
1146 int __connman_technology_update_rfkill(unsigned int index,
1147 enum connman_service_type type,
1148 connman_bool_t softblock,
1149 connman_bool_t hardblock)
1151 struct connman_technology *technology;
1152 struct connman_rfkill *rfkill;
1154 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1156 technology = technology_find(type);
1157 if (technology == NULL)
1160 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1164 if (rfkill->softblock == softblock &&
1165 rfkill->hardblock == hardblock)
1168 rfkill->softblock = softblock;
1169 rfkill->hardblock = hardblock;
1172 DBG("%s is switched off.", get_name(type));
1176 if (!global_offlinemode) {
1177 if (technology->enable_persistent && softblock)
1178 return __connman_rfkill_block(type, FALSE);
1179 if (!technology->enable_persistent && !softblock)
1180 return __connman_rfkill_block(type, TRUE);
1186 int __connman_technology_remove_rfkill(unsigned int index,
1187 enum connman_service_type type)
1189 struct connman_technology *technology;
1190 struct connman_rfkill *rfkill;
1192 DBG("index %u", index);
1194 technology = technology_find(type);
1195 if (technology == NULL)
1198 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1202 g_hash_table_remove(technology->rfkill_list, &index);
1204 technology_put(technology);
1209 int __connman_technology_init(void)
1213 connection = connman_dbus_get_connection();
1215 global_offlinemode = connman_technology_load_offlinemode();
1220 void __connman_technology_cleanup(void)
1224 dbus_connection_unref(connection);