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;
62 connman_bool_t connected;
64 connman_bool_t tethering;
65 char *tethering_ident;
66 char *tethering_passphrase;
68 connman_bool_t enable_persistent; /* Save the tech state */
70 struct connman_technology_driver *driver;
73 DBusMessage *pending_reply;
74 guint pending_timeout;
77 static GSList *driver_list = NULL;
79 static gint compare_priority(gconstpointer a, gconstpointer b)
81 const struct connman_technology_driver *driver1 = a;
82 const struct connman_technology_driver *driver2 = b;
84 return driver2->priority - driver1->priority;
88 * connman_technology_driver_register:
89 * @driver: Technology driver definition
91 * Register a new technology driver
93 * Returns: %0 on success
95 int connman_technology_driver_register(struct connman_technology_driver *driver)
97 DBG("Registering %s driver", driver->name);
99 driver_list = g_slist_insert_sorted(driver_list, driver,
106 * connman_technology_driver_unregister:
107 * @driver: Technology driver definition
109 * Remove a previously registered technology driver
111 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
114 struct connman_technology *technology;
116 DBG("Unregistering driver %p name %s", driver, driver->name);
118 for (list = technology_list; list; list = list->next) {
119 technology = list->data;
121 if (technology->driver == NULL)
124 if (technology->type == driver->type) {
125 technology->driver->remove(technology);
126 technology->driver = NULL;
130 driver_list = g_slist_remove(driver_list, driver);
133 static void tethering_changed(struct connman_technology *technology)
135 connman_bool_t tethering = technology->tethering;
137 connman_dbus_property_changed_basic(technology->path,
138 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
139 DBUS_TYPE_BOOLEAN, &tethering);
142 void connman_technology_tethering_notify(struct connman_technology *technology,
143 connman_bool_t enabled)
147 DBG("technology %p enabled %u", technology, enabled);
149 if (technology->tethering == enabled)
152 technology->tethering = enabled;
154 tethering_changed(technology);
157 __connman_tethering_set_enabled();
159 for (list = technology_list; list; list = list->next) {
160 struct connman_technology *other_tech = list->data;
161 if (other_tech->tethering == TRUE)
165 __connman_tethering_set_disabled();
169 static int set_tethering(struct connman_technology *technology,
170 connman_bool_t enabled)
172 const char *ident, *passphrase, *bridge;
174 ident = technology->tethering_ident;
175 passphrase = technology->tethering_passphrase;
177 if (technology->driver == NULL ||
178 technology->driver->set_tethering == NULL)
181 bridge = __connman_tethering_get_bridge();
185 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
186 (ident == NULL || passphrase == NULL))
189 return technology->driver->set_tethering(technology, ident, passphrase,
193 void connman_technology_regdom_notify(struct connman_technology *technology,
199 connman_error("Failed to set regulatory domain");
201 DBG("Regulatory domain set to %s", alpha2);
203 g_free(technology->regdom);
204 technology->regdom = g_strdup(alpha2);
207 int connman_technology_set_regdom(const char *alpha2)
211 for (list = technology_list; list; list = list->next) {
212 struct connman_technology *technology = list->data;
214 if (technology->driver == NULL)
217 if (technology->driver->set_regdom)
218 technology->driver->set_regdom(technology, alpha2);
224 static void free_rfkill(gpointer data)
226 struct connman_rfkill *rfkill = data;
231 static const char *state2string(enum connman_technology_state state)
234 case CONNMAN_TECHNOLOGY_STATE_UNKNOWN:
236 case CONNMAN_TECHNOLOGY_STATE_OFFLINE:
238 case CONNMAN_TECHNOLOGY_STATE_ENABLED:
240 case CONNMAN_TECHNOLOGY_STATE_CONNECTED:
247 static void state_changed(struct connman_technology *technology)
251 str = state2string(technology->state);
255 connman_dbus_property_changed_basic(technology->path,
256 CONNMAN_TECHNOLOGY_INTERFACE, "State",
257 DBUS_TYPE_STRING, &str);
260 static const char *get_name(enum connman_service_type type)
263 case CONNMAN_SERVICE_TYPE_UNKNOWN:
264 case CONNMAN_SERVICE_TYPE_SYSTEM:
265 case CONNMAN_SERVICE_TYPE_GPS:
266 case CONNMAN_SERVICE_TYPE_VPN:
267 case CONNMAN_SERVICE_TYPE_GADGET:
269 case CONNMAN_SERVICE_TYPE_ETHERNET:
271 case CONNMAN_SERVICE_TYPE_WIFI:
273 case CONNMAN_SERVICE_TYPE_WIMAX:
275 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
277 case CONNMAN_SERVICE_TYPE_CELLULAR:
284 static void load_state(struct connman_technology *technology)
288 GError *error = NULL;
289 connman_bool_t enable;
291 DBG("technology %p", technology);
293 keyfile = __connman_storage_load_global();
294 /* Fallback on disabling technology if file not found. */
295 if (keyfile == NULL) {
296 technology->enable_persistent = FALSE;
300 identifier = g_strdup_printf("%s", get_name(technology->type));
301 if (identifier == NULL)
304 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
306 technology->enable_persistent = enable;
308 technology->enable_persistent = FALSE;
309 g_clear_error(&error);
314 g_key_file_free(keyfile);
319 static void save_state(struct connman_technology *technology)
324 DBG("technology %p", technology);
326 keyfile = __connman_storage_load_global();
328 keyfile = g_key_file_new();
330 identifier = g_strdup_printf("%s", get_name(technology->type));
331 if (identifier == NULL)
334 g_key_file_set_boolean(keyfile, identifier, "Enable",
335 technology->enable_persistent);
340 __connman_storage_save_global(keyfile);
342 g_key_file_free(keyfile);
347 connman_bool_t __connman_technology_get_offlinemode(void)
349 return global_offlinemode;
352 static void connman_technology_save_offlinemode()
356 keyfile = __connman_storage_load_global();
358 keyfile = g_key_file_new();
360 g_key_file_set_boolean(keyfile, "global",
361 "OfflineMode", global_offlinemode);
363 __connman_storage_save_global(keyfile);
365 g_key_file_free(keyfile);
370 static connman_bool_t connman_technology_load_offlinemode()
373 GError *error = NULL;
374 connman_bool_t offlinemode;
376 /* If there is a error, we enable offlinemode */
377 keyfile = __connman_storage_load_global();
381 offlinemode = g_key_file_get_boolean(keyfile, "global",
382 "OfflineMode", &error);
385 g_clear_error(&error);
388 g_key_file_free(keyfile);
393 static void append_properties(DBusMessageIter *iter,
394 struct connman_technology *technology)
396 DBusMessageIter dict;
398 connman_bool_t powered;
400 connman_dbus_dict_open(iter, &dict);
402 str = state2string(technology->state);
404 connman_dbus_dict_append_basic(&dict, "State",
405 DBUS_TYPE_STRING, &str);
407 str = get_name(technology->type);
409 connman_dbus_dict_append_basic(&dict, "Name",
410 DBUS_TYPE_STRING, &str);
412 str = __connman_service_type2string(technology->type);
414 connman_dbus_dict_append_basic(&dict, "Type",
415 DBUS_TYPE_STRING, &str);
417 __sync_synchronize();
418 if (technology->enabled > 0)
422 connman_dbus_dict_append_basic(&dict, "Powered",
423 DBUS_TYPE_BOOLEAN, &powered);
425 connman_dbus_dict_append_basic(&dict, "Connected",
427 &technology->connected);
429 connman_dbus_dict_append_basic(&dict, "Tethering",
431 &technology->tethering);
433 if (technology->tethering_ident != NULL)
434 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
436 &technology->tethering_ident);
438 if (technology->tethering_passphrase != NULL)
439 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
441 &technology->tethering_passphrase);
443 connman_dbus_dict_close(iter, &dict);
446 static void technology_added_signal(struct connman_technology *technology)
449 DBusMessageIter iter;
451 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
452 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
456 dbus_message_iter_init_append(signal, &iter);
457 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
459 append_properties(&iter, technology);
461 dbus_connection_send(connection, signal, NULL);
462 dbus_message_unref(signal);
465 static void technology_removed_signal(struct connman_technology *technology)
467 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
468 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
469 DBUS_TYPE_OBJECT_PATH, &technology->path,
473 static DBusMessage *get_properties(DBusConnection *conn,
474 DBusMessage *message, void *user_data)
476 struct connman_technology *technology = user_data;
478 DBusMessageIter iter;
480 reply = dbus_message_new_method_return(message);
484 dbus_message_iter_init_append(reply, &iter);
485 append_properties(&iter, technology);
490 void __connman_technology_list_struct(DBusMessageIter *array)
493 DBusMessageIter entry;
495 for (list = technology_list; list; list = list->next) {
496 struct connman_technology *technology = list->data;
498 if (technology->path == NULL)
501 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
503 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
505 append_properties(&entry, technology);
506 dbus_message_iter_close_container(array, &entry);
510 static gboolean technology_pending_reply(gpointer user_data)
512 struct connman_technology *technology = user_data;
515 /* Power request timedout, send ETIMEDOUT. */
516 if (technology->pending_reply != NULL) {
517 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
519 g_dbus_send_message(connection, reply);
521 dbus_message_unref(technology->pending_reply);
522 technology->pending_reply = NULL;
523 technology->pending_timeout = 0;
529 static int technology_enable(struct connman_technology *technology,
537 DBG("technology %p enable", technology);
539 __sync_synchronize();
540 if (technology->enabled > 0) {
545 if (technology->pending_reply != NULL) {
552 * This is a bit of a trick. When msg is not NULL it means
553 * thats technology_enable was invoked from the manager API.
554 * Hence we save the state here.
556 technology->enable_persistent = TRUE;
557 save_state(technology);
560 __connman_rfkill_block(technology->type, FALSE);
563 * An empty device list means that devices in the technology
564 * were rfkill blocked. The unblock above will enable the devs.
566 if (technology->device_list == NULL) {
571 for (list = technology->device_list; list; list = list->next) {
572 struct connman_device *device = list->data;
574 err = __connman_device_enable(device);
576 * err = 0 : Device was enabled right away.
577 * If atleast one device gets enabled, we consider
578 * the technology to be enabled.
587 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
592 if (err == -EINPROGRESS) {
593 technology->pending_reply = dbus_message_ref(msg);
594 technology->pending_timeout = g_timeout_add_seconds(10,
595 technology_pending_reply, technology);
597 reply = __connman_error_failed(msg, -err);
599 g_dbus_send_message(connection, reply);
606 static int technology_disable(struct connman_technology *technology,
614 DBG("technology %p disable", technology);
616 __sync_synchronize();
617 if (technology->enabled == 0) {
622 if (technology->pending_reply != NULL) {
627 if (technology->tethering == TRUE)
628 set_tethering(technology, FALSE);
631 technology->enable_persistent = FALSE;
632 save_state(technology);
635 __connman_rfkill_block(technology->type, TRUE);
637 for (list = technology->device_list; list; list = list->next) {
638 struct connman_device *device = list->data;
640 err = __connman_device_disable(device);
648 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
653 if (err == -EINPROGRESS) {
654 technology->pending_reply = dbus_message_ref(msg);
655 technology->pending_timeout = g_timeout_add_seconds(10,
656 technology_pending_reply, technology);
658 reply = __connman_error_failed(msg, -err);
660 g_dbus_send_message(connection, reply);
667 static DBusMessage *set_property(DBusConnection *conn,
668 DBusMessage *msg, void *data)
670 struct connman_technology *technology = data;
671 DBusMessageIter iter, value;
675 DBG("conn %p", conn);
677 if (dbus_message_iter_init(msg, &iter) == FALSE)
678 return __connman_error_invalid_arguments(msg);
680 dbus_message_iter_get_basic(&iter, &name);
681 dbus_message_iter_next(&iter);
682 dbus_message_iter_recurse(&iter, &value);
684 type = dbus_message_iter_get_arg_type(&value);
686 DBG("property %s", name);
688 if (g_str_equal(name, "Tethering") == TRUE) {
690 connman_bool_t tethering;
692 if (type != DBUS_TYPE_BOOLEAN)
693 return __connman_error_invalid_arguments(msg);
695 dbus_message_iter_get_basic(&value, &tethering);
697 if (technology->tethering == tethering)
698 return __connman_error_in_progress(msg);
700 err = set_tethering(technology, tethering);
702 return __connman_error_failed(msg, -err);
704 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
707 dbus_message_iter_get_basic(&value, &str);
709 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
710 return __connman_error_not_supported(msg);
712 technology->tethering_ident = g_strdup(str);
713 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
716 dbus_message_iter_get_basic(&value, &str);
718 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
719 return __connman_error_not_supported(msg);
722 return __connman_error_invalid_arguments(msg);
724 technology->tethering_passphrase = g_strdup(str);
725 } else if (g_str_equal(name, "Powered") == TRUE) {
726 connman_bool_t enable;
728 if (type != DBUS_TYPE_BOOLEAN)
729 return __connman_error_invalid_arguments(msg);
731 dbus_message_iter_get_basic(&value, &enable);
733 technology_enable(technology, msg);
735 technology_disable(technology, msg);
738 return __connman_error_invalid_property(msg);
740 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
743 static GDBusMethodTable technology_methods[] = {
744 { "GetProperties", "", "a{sv}", get_properties },
745 { "SetProperty", "sv", "", set_property },
749 static GDBusSignalTable technology_signals[] = {
750 { "PropertyChanged", "sv" },
754 static struct connman_technology *technology_find(enum connman_service_type type)
758 DBG("type %d", type);
760 for (list = technology_list; list; list = list->next) {
761 struct connman_technology *technology = list->data;
763 if (technology->type == type)
770 static struct connman_technology *technology_get(enum connman_service_type type)
772 struct connman_technology *technology;
773 struct connman_technology_driver *driver = NULL;
778 DBG("type %d", type);
780 str = __connman_service_type2string(type);
784 technology = technology_find(type);
785 if (technology != NULL)
788 /* First check if we have a driver for this technology type */
789 for (list = driver_list; list; list = list->next) {
792 if (driver->type == type)
798 if (driver == NULL) {
799 DBG("No matching driver found for %s.",
800 __connman_service_type2string(type));
804 technology = g_try_new0(struct connman_technology, 1);
805 if (technology == NULL)
808 technology->refcount = 1;
810 technology->type = type;
811 technology->path = g_strdup_printf("%s/technology/%s",
814 technology->rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
816 technology->device_list = NULL;
818 technology->pending_reply = NULL;
819 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
821 load_state(technology);
823 if (g_dbus_register_interface(connection, technology->path,
824 CONNMAN_TECHNOLOGY_INTERFACE,
825 technology_methods, technology_signals,
826 NULL, technology, NULL) == FALSE) {
827 connman_error("Failed to register %s", technology->path);
832 technology_list = g_slist_append(technology_list, technology);
834 technology_added_signal(technology);
836 technology->driver = driver;
837 err = driver->probe(technology);
839 DBG("Driver probe failed for technology %p", technology);
841 DBG("technology %p", technology);
846 static void technology_put(struct connman_technology *technology)
848 DBG("technology %p", technology);
850 if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
853 if (technology->driver) {
854 technology->driver->remove(technology);
855 technology->driver = NULL;
858 technology_list = g_slist_remove(technology_list, technology);
860 technology_removed_signal(technology);
862 g_dbus_unregister_interface(connection, technology->path,
863 CONNMAN_TECHNOLOGY_INTERFACE);
865 g_slist_free(technology->device_list);
866 g_hash_table_destroy(technology->rfkill_list);
868 g_free(technology->path);
869 g_free(technology->regdom);
873 void __connman_technology_add_interface(enum connman_service_type type,
874 int index, const char *name, const char *ident)
876 struct connman_technology *technology;
879 case CONNMAN_SERVICE_TYPE_UNKNOWN:
880 case CONNMAN_SERVICE_TYPE_SYSTEM:
882 case CONNMAN_SERVICE_TYPE_ETHERNET:
883 case CONNMAN_SERVICE_TYPE_WIFI:
884 case CONNMAN_SERVICE_TYPE_WIMAX:
885 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
886 case CONNMAN_SERVICE_TYPE_CELLULAR:
887 case CONNMAN_SERVICE_TYPE_GPS:
888 case CONNMAN_SERVICE_TYPE_VPN:
889 case CONNMAN_SERVICE_TYPE_GADGET:
893 connman_info("Adding interface %s [ %s ]", name,
894 __connman_service_type2string(type));
896 technology = technology_find(type);
898 if (technology == NULL || technology->driver == NULL
899 || technology->driver->add_interface == NULL)
902 technology->driver->add_interface(technology,
906 void __connman_technology_remove_interface(enum connman_service_type type,
907 int index, const char *name, const char *ident)
909 struct connman_technology *technology;
912 case CONNMAN_SERVICE_TYPE_UNKNOWN:
913 case CONNMAN_SERVICE_TYPE_SYSTEM:
915 case CONNMAN_SERVICE_TYPE_ETHERNET:
916 case CONNMAN_SERVICE_TYPE_WIFI:
917 case CONNMAN_SERVICE_TYPE_WIMAX:
918 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
919 case CONNMAN_SERVICE_TYPE_CELLULAR:
920 case CONNMAN_SERVICE_TYPE_GPS:
921 case CONNMAN_SERVICE_TYPE_VPN:
922 case CONNMAN_SERVICE_TYPE_GADGET:
926 connman_info("Remove interface %s [ %s ]", name,
927 __connman_service_type2string(type));
929 technology = technology_find(type);
931 if (technology == NULL || technology->driver == NULL)
934 if (technology->driver->remove_interface)
935 technology->driver->remove_interface(technology, index);
938 int __connman_technology_add_device(struct connman_device *device)
940 struct connman_technology *technology;
941 enum connman_service_type type;
943 DBG("device %p", device);
945 type = __connman_device_get_service_type(device);
947 technology = technology_get(type);
948 if (technology == NULL)
951 if (technology->enable_persistent && !global_offlinemode)
952 __connman_device_enable(device);
953 /* if technology persistent state is offline */
954 if (!technology->enable_persistent)
955 __connman_device_disable(device);
957 technology->device_list = g_slist_append(technology->device_list,
963 int __connman_technology_remove_device(struct connman_device *device)
965 struct connman_technology *technology;
966 enum connman_service_type type;
968 DBG("device %p", device);
970 type = __connman_device_get_service_type(device);
972 technology = technology_find(type);
973 if (technology == NULL)
976 technology->device_list = g_slist_remove(technology->device_list,
978 if (technology->device_list == NULL) {
979 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
980 state_changed(technology);
986 static void powered_changed(struct connman_technology *technology)
988 connman_bool_t powered;
990 __sync_synchronize();
991 if (technology->enabled >0)
996 connman_dbus_property_changed_basic(technology->path,
997 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
998 DBUS_TYPE_BOOLEAN, &powered);
1001 int __connman_technology_enabled(enum connman_service_type type)
1003 struct connman_technology *technology;
1005 technology = technology_find(type);
1006 if (technology == NULL)
1009 if (__sync_fetch_and_add(&technology->enabled, 1) == 0) {
1010 technology->state = CONNMAN_TECHNOLOGY_STATE_ENABLED;
1011 state_changed(technology);
1012 powered_changed(technology);
1015 if (technology->pending_reply != NULL) {
1016 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1017 dbus_message_unref(technology->pending_reply);
1018 g_source_remove(technology->pending_timeout);
1019 technology->pending_reply = NULL;
1020 technology->pending_timeout = 0;
1026 int __connman_technology_disabled(enum connman_service_type type)
1028 struct connman_technology *technology;
1030 technology = technology_find(type);
1031 if (technology == NULL)
1034 if (technology->pending_reply != NULL) {
1035 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1036 dbus_message_unref(technology->pending_reply);
1037 g_source_remove(technology->pending_timeout);
1038 technology->pending_reply = NULL;
1039 technology->pending_timeout = 0;
1042 if (__sync_fetch_and_sub(&technology->enabled, 1) != 1)
1045 technology->state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
1046 state_changed(technology);
1047 powered_changed(technology);
1052 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1057 if (global_offlinemode == offlinemode)
1060 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1063 * This is a bit tricky. When you set offlinemode, there is no
1064 * way to differentiate between attempting offline mode and
1065 * resuming offlinemode from last saved profile. We need that
1066 * information in rfkill_update, otherwise it falls back on the
1067 * technology's persistent state. Hence we set the offline mode here
1068 * but save it & call the notifier only if its successful.
1071 global_offlinemode = offlinemode;
1073 /* Traverse technology list, enable/disable each technology. */
1074 for (list = technology_list; list; list = list->next) {
1075 struct connman_technology *technology = list->data;
1078 err = technology_disable(technology, NULL);
1080 if (!offlinemode && technology->enable_persistent)
1081 err = technology_enable(technology, NULL);
1084 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1085 connman_technology_save_offlinemode();
1086 __connman_notifier_offlinemode(offlinemode);
1088 global_offlinemode = connman_technology_load_offlinemode();
1093 void __connman_technology_set_connected(enum connman_service_type type,
1094 connman_bool_t connected)
1096 struct connman_technology *technology;
1098 technology = technology_find(type);
1099 if (technology == NULL)
1102 DBG("technology %p connected %d", technology, connected);
1104 technology->connected = connected;
1106 connman_dbus_property_changed_basic(technology->path,
1107 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
1108 DBUS_TYPE_BOOLEAN, &connected);
1111 int __connman_technology_add_rfkill(unsigned int index,
1112 enum connman_service_type type,
1113 connman_bool_t softblock,
1114 connman_bool_t hardblock)
1116 struct connman_technology *technology;
1117 struct connman_rfkill *rfkill;
1119 DBG("index %u type %d soft %u hard %u", index, type,
1120 softblock, hardblock);
1122 technology = technology_get(type);
1123 if (technology == NULL)
1126 rfkill = g_try_new0(struct connman_rfkill, 1);
1130 rfkill->index = index;
1131 rfkill->type = type;
1132 rfkill->softblock = softblock;
1133 rfkill->hardblock = hardblock;
1135 g_hash_table_replace(technology->rfkill_list, &rfkill->index, rfkill);
1138 DBG("%s is switched off.", get_name(type));
1143 * If Offline mode is on, we softblock the device if it isnt already.
1144 * If Offline mode is off, we rely on the persistent state of tech.
1146 if (global_offlinemode) {
1148 return __connman_rfkill_block(type, TRUE);
1150 if (technology->enable_persistent && softblock)
1151 return __connman_rfkill_block(type, FALSE);
1152 /* if technology persistent state is offline */
1153 if (!technology->enable_persistent && !softblock)
1154 return __connman_rfkill_block(type, TRUE);
1160 int __connman_technology_update_rfkill(unsigned int index,
1161 enum connman_service_type type,
1162 connman_bool_t softblock,
1163 connman_bool_t hardblock)
1165 struct connman_technology *technology;
1166 struct connman_rfkill *rfkill;
1168 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1170 technology = technology_find(type);
1171 if (technology == NULL)
1174 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1178 if (rfkill->softblock == softblock &&
1179 rfkill->hardblock == hardblock)
1182 rfkill->softblock = softblock;
1183 rfkill->hardblock = hardblock;
1186 DBG("%s is switched off.", get_name(type));
1190 if (!global_offlinemode) {
1191 if (technology->enable_persistent && softblock)
1192 return __connman_rfkill_block(type, FALSE);
1193 if (!technology->enable_persistent && !softblock)
1194 return __connman_rfkill_block(type, TRUE);
1200 int __connman_technology_remove_rfkill(unsigned int index,
1201 enum connman_service_type type)
1203 struct connman_technology *technology;
1204 struct connman_rfkill *rfkill;
1206 DBG("index %u", index);
1208 technology = technology_find(type);
1209 if (technology == NULL)
1212 rfkill = g_hash_table_lookup(technology->rfkill_list, &index);
1216 g_hash_table_remove(technology->rfkill_list, &index);
1218 technology_put(technology);
1223 int __connman_technology_init(void)
1227 connection = connman_dbus_get_connection();
1229 global_offlinemode = connman_technology_load_offlinemode();
1234 void __connman_technology_cleanup(void)
1238 dbus_connection_unref(connection);