5 * Copyright (C) 2007-2012 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;
42 static GHashTable *rfkill_list;
44 static connman_bool_t global_offlinemode;
46 struct connman_rfkill {
48 enum connman_service_type type;
49 connman_bool_t softblock;
50 connman_bool_t hardblock;
53 struct connman_technology {
55 enum connman_service_type type;
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;
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;
87 static void rfkill_check(gpointer key, gpointer value, gpointer user_data)
89 struct connman_rfkill *rfkill = value;
90 enum connman_service_type type = GPOINTER_TO_INT(user_data);
92 /* Calling _technology_rfkill_add will update the tech. */
93 if (rfkill->type == type)
94 __connman_technology_add_rfkill(rfkill->index, type,
95 rfkill->softblock, rfkill->hardblock);
99 * connman_technology_driver_register:
100 * @driver: Technology driver definition
102 * Register a new technology driver
104 * Returns: %0 on success
106 int connman_technology_driver_register(struct connman_technology_driver *driver)
109 struct connman_device *device;
110 enum connman_service_type type;
112 DBG("Registering %s driver", driver->name);
114 driver_list = g_slist_insert_sorted(driver_list, driver,
117 if (techless_device_list == NULL)
121 * Check for technology less devices if this driver
122 * can service any of them.
124 for (list = techless_device_list; list; list = list->next) {
127 type = __connman_device_get_service_type(device);
128 if (type != driver->type)
131 techless_device_list = g_slist_remove(techless_device_list,
134 __connman_technology_add_device(device);
138 /* Check for orphaned rfkill switches. */
139 g_hash_table_foreach(rfkill_list, rfkill_check,
140 GINT_TO_POINTER(driver->type));
146 * connman_technology_driver_unregister:
147 * @driver: Technology driver definition
149 * Remove a previously registered technology driver
151 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
154 struct connman_technology *technology;
156 DBG("Unregistering driver %p name %s", driver, driver->name);
158 for (list = technology_list; list; list = list->next) {
159 technology = list->data;
161 if (technology->driver == NULL)
164 if (technology->type == driver->type) {
165 technology->driver->remove(technology);
166 technology->driver = NULL;
170 driver_list = g_slist_remove(driver_list, driver);
173 static void tethering_changed(struct connman_technology *technology)
175 connman_bool_t tethering = technology->tethering;
177 connman_dbus_property_changed_basic(technology->path,
178 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
179 DBUS_TYPE_BOOLEAN, &tethering);
182 void connman_technology_tethering_notify(struct connman_technology *technology,
183 connman_bool_t enabled)
187 DBG("technology %p enabled %u", technology, enabled);
189 if (technology->tethering == enabled)
192 technology->tethering = enabled;
194 tethering_changed(technology);
197 __connman_tethering_set_enabled();
199 for (list = technology_list; list; list = list->next) {
200 struct connman_technology *other_tech = list->data;
201 if (other_tech->tethering == TRUE)
205 __connman_tethering_set_disabled();
209 static int set_tethering(struct connman_technology *technology,
210 connman_bool_t enabled)
212 const char *ident, *passphrase, *bridge;
214 ident = technology->tethering_ident;
215 passphrase = technology->tethering_passphrase;
217 if (technology->driver == NULL ||
218 technology->driver->set_tethering == NULL)
221 bridge = __connman_tethering_get_bridge();
225 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
226 (ident == NULL || passphrase == NULL))
229 return technology->driver->set_tethering(technology, ident, passphrase,
233 void connman_technology_regdom_notify(struct connman_technology *technology,
239 connman_error("Failed to set regulatory domain");
241 DBG("Regulatory domain set to %s", alpha2);
243 g_free(technology->regdom);
244 technology->regdom = g_strdup(alpha2);
247 static int set_regdom_by_device(struct connman_technology *technology,
252 for (list = technology->device_list; list; list = list->next) {
253 struct connman_device *device = list->data;
255 if (connman_device_set_regdom(device, alpha2) != 0)
262 int connman_technology_set_regdom(const char *alpha2)
266 for (list = technology_list; list; list = list->next) {
267 struct connman_technology *technology = list->data;
269 if (set_regdom_by_device(technology, alpha2) != 0) {
270 if (technology->driver == NULL)
273 if (technology->driver->set_regdom != NULL)
274 technology->driver->set_regdom(technology,
282 static void free_rfkill(gpointer data)
284 struct connman_rfkill *rfkill = data;
289 static const char *get_name(enum connman_service_type type)
292 case CONNMAN_SERVICE_TYPE_UNKNOWN:
293 case CONNMAN_SERVICE_TYPE_SYSTEM:
294 case CONNMAN_SERVICE_TYPE_GPS:
295 case CONNMAN_SERVICE_TYPE_VPN:
296 case CONNMAN_SERVICE_TYPE_GADGET:
298 case CONNMAN_SERVICE_TYPE_ETHERNET:
300 case CONNMAN_SERVICE_TYPE_WIFI:
302 case CONNMAN_SERVICE_TYPE_WIMAX:
304 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
306 case CONNMAN_SERVICE_TYPE_CELLULAR:
313 static void technology_save(struct connman_technology *technology)
318 DBG("technology %p", technology);
320 keyfile = __connman_storage_load_global();
322 keyfile = g_key_file_new();
324 identifier = g_strdup_printf("%s", get_name(technology->type));
325 if (identifier == NULL)
328 g_key_file_set_boolean(keyfile, identifier, "Enable",
329 technology->enable_persistent);
331 if (technology->tethering_ident != NULL)
332 g_key_file_set_string(keyfile, identifier,
333 "Tethering.Identifier",
334 technology->tethering_ident);
336 if (technology->tethering_passphrase != NULL)
337 g_key_file_set_string(keyfile, identifier,
338 "Tethering.Passphrase",
339 technology->tethering_passphrase);
344 __connman_storage_save_global(keyfile);
346 g_key_file_free(keyfile);
351 static void technology_load(struct connman_technology *technology)
355 GError *error = NULL;
356 connman_bool_t enable;
358 DBG("technology %p", technology);
360 keyfile = __connman_storage_load_global();
361 /* Fallback on disabling technology if file not found. */
362 if (keyfile == NULL) {
363 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
364 /* We enable ethernet by default */
365 technology->enable_persistent = TRUE;
367 technology->enable_persistent = FALSE;
371 identifier = g_strdup_printf("%s", get_name(technology->type));
372 if (identifier == NULL)
375 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
377 technology->enable_persistent = enable;
379 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
380 technology->enable_persistent = TRUE;
382 technology->enable_persistent = FALSE;
384 technology_save(technology);
385 g_clear_error(&error);
388 technology->tethering_ident = g_key_file_get_string(keyfile,
389 identifier, "Tethering.Identifier", NULL);
391 technology->tethering_passphrase = g_key_file_get_string(keyfile,
392 identifier, "Tethering.Passphrase", NULL);
396 g_key_file_free(keyfile);
401 connman_bool_t __connman_technology_get_offlinemode(void)
403 return global_offlinemode;
406 static void connman_technology_save_offlinemode()
410 keyfile = __connman_storage_load_global();
412 keyfile = g_key_file_new();
414 g_key_file_set_boolean(keyfile, "global",
415 "OfflineMode", global_offlinemode);
417 __connman_storage_save_global(keyfile);
419 g_key_file_free(keyfile);
424 static connman_bool_t connman_technology_load_offlinemode()
427 GError *error = NULL;
428 connman_bool_t offlinemode;
430 /* If there is a error, we enable offlinemode */
431 keyfile = __connman_storage_load_global();
435 offlinemode = g_key_file_get_boolean(keyfile, "global",
436 "OfflineMode", &error);
439 g_clear_error(&error);
442 g_key_file_free(keyfile);
447 static void append_properties(DBusMessageIter *iter,
448 struct connman_technology *technology)
450 DBusMessageIter dict;
452 connman_bool_t powered;
454 connman_dbus_dict_open(iter, &dict);
456 str = get_name(technology->type);
458 connman_dbus_dict_append_basic(&dict, "Name",
459 DBUS_TYPE_STRING, &str);
461 str = __connman_service_type2string(technology->type);
463 connman_dbus_dict_append_basic(&dict, "Type",
464 DBUS_TYPE_STRING, &str);
466 __sync_synchronize();
467 if (technology->enabled > 0)
471 connman_dbus_dict_append_basic(&dict, "Powered",
472 DBUS_TYPE_BOOLEAN, &powered);
474 connman_dbus_dict_append_basic(&dict, "Connected",
476 &technology->connected);
478 connman_dbus_dict_append_basic(&dict, "Tethering",
480 &technology->tethering);
482 if (technology->tethering_ident != NULL)
483 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
485 &technology->tethering_ident);
487 if (technology->tethering_passphrase != NULL)
488 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
490 &technology->tethering_passphrase);
492 connman_dbus_dict_close(iter, &dict);
495 static void technology_added_signal(struct connman_technology *technology)
498 DBusMessageIter iter;
500 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
501 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
505 dbus_message_iter_init_append(signal, &iter);
506 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
508 append_properties(&iter, technology);
510 dbus_connection_send(connection, signal, NULL);
511 dbus_message_unref(signal);
514 static void technology_removed_signal(struct connman_technology *technology)
516 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
517 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
518 DBUS_TYPE_OBJECT_PATH, &technology->path,
522 static DBusMessage *get_properties(DBusConnection *conn,
523 DBusMessage *message, void *user_data)
525 struct connman_technology *technology = user_data;
527 DBusMessageIter iter;
529 reply = dbus_message_new_method_return(message);
533 dbus_message_iter_init_append(reply, &iter);
534 append_properties(&iter, technology);
539 void __connman_technology_list_struct(DBusMessageIter *array)
542 DBusMessageIter entry;
544 for (list = technology_list; list; list = list->next) {
545 struct connman_technology *technology = list->data;
547 if (technology->path == NULL)
550 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
552 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
554 append_properties(&entry, technology);
555 dbus_message_iter_close_container(array, &entry);
559 static gboolean technology_pending_reply(gpointer user_data)
561 struct connman_technology *technology = user_data;
564 /* Power request timedout, send ETIMEDOUT. */
565 if (technology->pending_reply != NULL) {
566 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
568 g_dbus_send_message(connection, reply);
570 dbus_message_unref(technology->pending_reply);
571 technology->pending_reply = NULL;
572 technology->pending_timeout = 0;
578 static int technology_enable(struct connman_technology *technology,
586 DBG("technology %p enable", technology);
588 __sync_synchronize();
589 if (technology->enabled > 0) {
594 if (technology->pending_reply != NULL) {
601 * This is a bit of a trick. When msg is not NULL it means
602 * thats technology_enable was invoked from the manager API.
603 * Hence we save the state here.
605 technology->enable_persistent = TRUE;
606 technology_save(technology);
609 __connman_rfkill_block(technology->type, FALSE);
612 * An empty device list means that devices in the technology
613 * were rfkill blocked. The unblock above will enable the devs.
615 if (technology->device_list == NULL) {
620 for (list = technology->device_list; list; list = list->next) {
621 struct connman_device *device = list->data;
623 err = __connman_device_enable(device);
625 * err = 0 : Device was enabled right away.
626 * If atleast one device gets enabled, we consider
627 * the technology to be enabled.
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 if (err == -EALREADY)
647 reply = __connman_error_already_enabled(msg);
649 reply = __connman_error_failed(msg, -err);
651 g_dbus_send_message(connection, reply);
658 static int technology_disable(struct connman_technology *technology,
666 DBG("technology %p disable", technology);
668 __sync_synchronize();
669 if (technology->enabled == 0) {
674 if (technology->pending_reply != NULL) {
679 if (technology->tethering == TRUE)
680 set_tethering(technology, FALSE);
683 technology->enable_persistent = FALSE;
684 technology_save(technology);
687 __connman_rfkill_block(technology->type, TRUE);
689 for (list = technology->device_list; list; list = list->next) {
690 struct connman_device *device = list->data;
692 err = __connman_device_disable(device);
700 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
705 if (err == -EINPROGRESS) {
706 technology->pending_reply = dbus_message_ref(msg);
707 technology->pending_timeout = g_timeout_add_seconds(10,
708 technology_pending_reply, technology);
710 if (err == -EALREADY)
711 reply = __connman_error_already_disabled(msg);
713 reply = __connman_error_failed(msg, -err);
715 g_dbus_send_message(connection, reply);
722 static DBusMessage *set_property(DBusConnection *conn,
723 DBusMessage *msg, void *data)
725 struct connman_technology *technology = data;
726 DBusMessageIter iter, value;
730 DBG("conn %p", conn);
732 if (dbus_message_iter_init(msg, &iter) == FALSE)
733 return __connman_error_invalid_arguments(msg);
735 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
736 return __connman_error_invalid_arguments(msg);
738 dbus_message_iter_get_basic(&iter, &name);
739 dbus_message_iter_next(&iter);
741 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
742 return __connman_error_invalid_arguments(msg);
744 dbus_message_iter_recurse(&iter, &value);
746 type = dbus_message_iter_get_arg_type(&value);
748 DBG("property %s", name);
750 if (g_str_equal(name, "Tethering") == TRUE) {
752 connman_bool_t tethering;
754 if (type != DBUS_TYPE_BOOLEAN)
755 return __connman_error_invalid_arguments(msg);
757 dbus_message_iter_get_basic(&value, &tethering);
759 if (technology->tethering == tethering)
760 return __connman_error_already_enabled(msg);
762 err = set_tethering(technology, tethering);
764 return __connman_error_failed(msg, -err);
766 } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
769 dbus_message_iter_get_basic(&value, &str);
771 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
772 return __connman_error_not_supported(msg);
774 if (strlen(str) < 1 || strlen(str) > 32)
775 return __connman_error_invalid_arguments(msg);
777 technology->tethering_ident = g_strdup(str);
778 technology_save(technology);
779 } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
782 dbus_message_iter_get_basic(&value, &str);
784 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
785 return __connman_error_not_supported(msg);
787 if (strlen(str) < 8 || strlen(str) > 63)
788 return __connman_error_passphrase_required(msg);
790 technology->tethering_passphrase = g_strdup(str);
791 technology_save(technology);
792 } else if (g_str_equal(name, "Powered") == TRUE) {
793 connman_bool_t enable;
795 if (type != DBUS_TYPE_BOOLEAN)
796 return __connman_error_invalid_arguments(msg);
798 dbus_message_iter_get_basic(&value, &enable);
800 technology_enable(technology, msg);
802 technology_disable(technology, msg);
805 return __connman_error_invalid_property(msg);
807 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
810 static struct connman_technology *technology_find(enum connman_service_type type)
814 DBG("type %d", type);
816 for (list = technology_list; list; list = list->next) {
817 struct connman_technology *technology = list->data;
819 if (technology->type == type)
826 static void reply_scan_pending(struct connman_technology *technology, int err)
830 DBG("technology %p err %d", technology, err);
832 while (technology->scan_pending != NULL) {
833 DBusMessage *msg = technology->scan_pending->data;
835 DBG("reply to %s", dbus_message_get_sender(msg));
838 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
840 reply = __connman_error_failed(msg, -err);
841 g_dbus_send_message(connection, reply);
842 dbus_message_unref(msg);
844 technology->scan_pending =
845 g_slist_delete_link(technology->scan_pending,
846 technology->scan_pending);
850 void __connman_technology_scan_started(struct connman_device *device)
852 DBG("device %p", device);
855 void __connman_technology_scan_stopped(struct connman_device *device)
858 struct connman_technology *technology;
859 enum connman_service_type type;
862 type = __connman_device_get_service_type(device);
863 technology = technology_find(type);
865 DBG("technology %p device %p", technology, device);
867 if (technology == NULL)
870 for (list = technology->device_list; list != NULL; list = list->next) {
871 struct connman_device *other_device = list->data;
873 if (device == other_device)
876 if (__connman_device_get_service_type(other_device) != type)
879 if (connman_device_get_scanning(other_device) == TRUE)
884 reply_scan_pending(technology, 0);
887 void __connman_technology_notify_regdom_by_device(struct connman_device *device,
888 int result, const char *alpha2)
890 struct connman_technology *technology;
891 enum connman_service_type type;
893 type = __connman_device_get_service_type(device);
894 technology = technology_find(type);
896 if (technology == NULL)
900 if (technology->driver != NULL &&
901 technology->driver->set_regdom != NULL) {
902 technology->driver->set_regdom(technology, alpha2);
909 connman_technology_regdom_notify(technology, alpha2);
912 static DBusMessage *scan(DBusConnection *conn, DBusMessage *msg, void *data)
914 struct connman_technology *technology = data;
917 DBG ("technology %p request from %s", technology,
918 dbus_message_get_sender(msg));
920 dbus_message_ref(msg);
921 technology->scan_pending =
922 g_slist_prepend(technology->scan_pending, msg);
924 err = __connman_device_request_scan(technology->type);
926 reply_scan_pending(technology, err);
931 static const GDBusMethodTable technology_methods[] = {
932 { GDBUS_DEPRECATED_METHOD("GetProperties",
933 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
935 { GDBUS_METHOD("SetProperty",
936 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
937 NULL, set_property) },
938 { GDBUS_ASYNC_METHOD("Scan", NULL, NULL, scan) },
942 static const GDBusSignalTable technology_signals[] = {
943 { GDBUS_SIGNAL("PropertyChanged",
944 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
948 static struct connman_technology *technology_get(enum connman_service_type type)
950 struct connman_technology *technology;
951 struct connman_technology_driver *driver = NULL;
956 DBG("type %d", type);
958 str = __connman_service_type2string(type);
962 technology = technology_find(type);
963 if (technology != NULL) {
964 __sync_fetch_and_add(&technology->refcount, 1);
968 /* First check if we have a driver for this technology type */
969 for (list = driver_list; list; list = list->next) {
972 if (driver->type == type)
978 if (driver == NULL) {
979 DBG("No matching driver found for %s.",
980 __connman_service_type2string(type));
984 technology = g_try_new0(struct connman_technology, 1);
985 if (technology == NULL)
988 technology->refcount = 1;
990 technology->type = type;
991 technology->path = g_strdup_printf("%s/technology/%s",
994 technology->device_list = NULL;
996 technology->pending_reply = NULL;
998 technology_load(technology);
1000 if (g_dbus_register_interface(connection, technology->path,
1001 CONNMAN_TECHNOLOGY_INTERFACE,
1002 technology_methods, technology_signals,
1003 NULL, technology, NULL) == FALSE) {
1004 connman_error("Failed to register %s", technology->path);
1009 technology_list = g_slist_append(technology_list, technology);
1011 technology_added_signal(technology);
1013 technology->driver = driver;
1014 err = driver->probe(technology);
1016 DBG("Driver probe failed for technology %p", technology);
1018 DBG("technology %p", technology);
1023 static void technology_put(struct connman_technology *technology)
1025 DBG("technology %p", technology);
1027 if (__sync_sub_and_fetch(&technology->refcount, 1) > 0)
1030 reply_scan_pending(technology, -EINTR);
1032 if (technology->driver) {
1033 technology->driver->remove(technology);
1034 technology->driver = NULL;
1037 technology_list = g_slist_remove(technology_list, technology);
1039 technology_removed_signal(technology);
1041 g_dbus_unregister_interface(connection, technology->path,
1042 CONNMAN_TECHNOLOGY_INTERFACE);
1044 g_slist_free(technology->device_list);
1046 g_free(technology->path);
1047 g_free(technology->regdom);
1051 void __connman_technology_add_interface(enum connman_service_type type,
1052 int index, const char *name, const char *ident)
1054 struct connman_technology *technology;
1057 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1058 case CONNMAN_SERVICE_TYPE_SYSTEM:
1060 case CONNMAN_SERVICE_TYPE_ETHERNET:
1061 case CONNMAN_SERVICE_TYPE_WIFI:
1062 case CONNMAN_SERVICE_TYPE_WIMAX:
1063 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1064 case CONNMAN_SERVICE_TYPE_CELLULAR:
1065 case CONNMAN_SERVICE_TYPE_GPS:
1066 case CONNMAN_SERVICE_TYPE_VPN:
1067 case CONNMAN_SERVICE_TYPE_GADGET:
1071 connman_info("Adding interface %s [ %s ]", name,
1072 __connman_service_type2string(type));
1074 technology = technology_find(type);
1076 if (technology == NULL || technology->driver == NULL
1077 || technology->driver->add_interface == NULL)
1080 technology->driver->add_interface(technology,
1081 index, name, ident);
1084 void __connman_technology_remove_interface(enum connman_service_type type,
1085 int index, const char *name, const char *ident)
1087 struct connman_technology *technology;
1090 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1091 case CONNMAN_SERVICE_TYPE_SYSTEM:
1093 case CONNMAN_SERVICE_TYPE_ETHERNET:
1094 case CONNMAN_SERVICE_TYPE_WIFI:
1095 case CONNMAN_SERVICE_TYPE_WIMAX:
1096 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1097 case CONNMAN_SERVICE_TYPE_CELLULAR:
1098 case CONNMAN_SERVICE_TYPE_GPS:
1099 case CONNMAN_SERVICE_TYPE_VPN:
1100 case CONNMAN_SERVICE_TYPE_GADGET:
1104 connman_info("Remove interface %s [ %s ]", name,
1105 __connman_service_type2string(type));
1107 technology = technology_find(type);
1109 if (technology == NULL || technology->driver == NULL)
1112 if (technology->driver->remove_interface)
1113 technology->driver->remove_interface(technology, index);
1116 int __connman_technology_add_device(struct connman_device *device)
1118 struct connman_technology *technology;
1119 enum connman_service_type type;
1121 DBG("device %p", device);
1123 type = __connman_device_get_service_type(device);
1125 technology = technology_get(type);
1126 if (technology == NULL) {
1128 * Since no driver can be found for this device at the moment we
1129 * add it to the techless device list.
1131 techless_device_list = g_slist_prepend(techless_device_list,
1137 if (technology->enable_persistent && !global_offlinemode) {
1138 int err = __connman_device_enable(device);
1140 * connman_technology_add_device() calls __connman_device_enable()
1141 * but since the device is already enabled, the calls does not
1142 * propagate through to connman_technology_enabled via
1143 * connman_device_set_powered.
1145 if (err == -EALREADY)
1146 __connman_technology_enabled(type);
1148 /* if technology persistent state is offline */
1149 if (!technology->enable_persistent)
1150 __connman_device_disable(device);
1152 technology->device_list = g_slist_append(technology->device_list,
1158 int __connman_technology_remove_device(struct connman_device *device)
1160 struct connman_technology *technology;
1161 enum connman_service_type type;
1163 DBG("device %p", device);
1165 type = __connman_device_get_service_type(device);
1167 technology = technology_find(type);
1168 if (technology == NULL) {
1169 techless_device_list = g_slist_remove(techless_device_list,
1174 technology->device_list = g_slist_remove(technology->device_list,
1176 technology_put(technology);
1181 static void powered_changed(struct connman_technology *technology)
1183 connman_bool_t powered;
1185 __sync_synchronize();
1186 if (technology->enabled >0)
1191 connman_dbus_property_changed_basic(technology->path,
1192 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
1193 DBUS_TYPE_BOOLEAN, &powered);
1196 int __connman_technology_enabled(enum connman_service_type type)
1198 struct connman_technology *technology;
1200 technology = technology_find(type);
1201 if (technology == NULL)
1204 if (__sync_fetch_and_add(&technology->enabled, 1) != 0)
1207 powered_changed(technology);
1209 if (technology->pending_reply != NULL) {
1210 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1211 dbus_message_unref(technology->pending_reply);
1212 g_source_remove(technology->pending_timeout);
1213 technology->pending_reply = NULL;
1214 technology->pending_timeout = 0;
1220 int __connman_technology_disabled(enum connman_service_type type)
1222 struct connman_technology *technology;
1224 technology = technology_find(type);
1225 if (technology == NULL)
1228 if (__sync_fetch_and_sub(&technology->enabled, 1) != 1)
1229 return -EINPROGRESS;
1231 if (technology->pending_reply != NULL) {
1232 g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID);
1233 dbus_message_unref(technology->pending_reply);
1234 g_source_remove(technology->pending_timeout);
1235 technology->pending_reply = NULL;
1236 technology->pending_timeout = 0;
1239 powered_changed(technology);
1244 int __connman_technology_set_offlinemode(connman_bool_t offlinemode)
1249 if (global_offlinemode == offlinemode)
1252 DBG("offlinemode %s", offlinemode ? "On" : "Off");
1255 * This is a bit tricky. When you set offlinemode, there is no
1256 * way to differentiate between attempting offline mode and
1257 * resuming offlinemode from last saved profile. We need that
1258 * information in rfkill_update, otherwise it falls back on the
1259 * technology's persistent state. Hence we set the offline mode here
1260 * but save it & call the notifier only if its successful.
1263 global_offlinemode = offlinemode;
1265 /* Traverse technology list, enable/disable each technology. */
1266 for (list = technology_list; list; list = list->next) {
1267 struct connman_technology *technology = list->data;
1270 err = technology_disable(technology, NULL);
1272 if (!offlinemode && technology->enable_persistent)
1273 err = technology_enable(technology, NULL);
1276 if (err == 0 || err == -EINPROGRESS || err == -EALREADY) {
1277 connman_technology_save_offlinemode();
1278 __connman_notifier_offlinemode(offlinemode);
1280 global_offlinemode = connman_technology_load_offlinemode();
1285 void __connman_technology_set_connected(enum connman_service_type type,
1286 connman_bool_t connected)
1288 struct connman_technology *technology;
1290 technology = technology_find(type);
1291 if (technology == NULL)
1294 DBG("technology %p connected %d", technology, connected);
1296 technology->connected = connected;
1298 connman_dbus_property_changed_basic(technology->path,
1299 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
1300 DBUS_TYPE_BOOLEAN, &connected);
1303 int __connman_technology_add_rfkill(unsigned int index,
1304 enum connman_service_type type,
1305 connman_bool_t softblock,
1306 connman_bool_t hardblock)
1308 struct connman_technology *technology;
1309 struct connman_rfkill *rfkill;
1311 DBG("index %u type %d soft %u hard %u", index, type,
1312 softblock, hardblock);
1314 rfkill = g_hash_table_lookup(rfkill_list, &index);
1318 rfkill = g_try_new0(struct connman_rfkill, 1);
1322 rfkill->index = index;
1323 rfkill->type = type;
1324 rfkill->softblock = softblock;
1325 rfkill->hardblock = hardblock;
1327 g_hash_table_insert(rfkill_list, &rfkill->index, rfkill);
1330 technology = technology_get(type);
1331 /* If there is no driver for this type, ignore it. */
1332 if (technology == NULL)
1336 DBG("%s is switched off.", get_name(type));
1341 * If Offline mode is on, we softblock the device if it isnt already.
1342 * If Offline mode is off, we rely on the persistent state of tech.
1344 if (global_offlinemode) {
1346 return __connman_rfkill_block(type, TRUE);
1348 if (technology->enable_persistent && softblock)
1349 return __connman_rfkill_block(type, FALSE);
1350 /* if technology persistent state is offline */
1351 if (!technology->enable_persistent && !softblock)
1352 return __connman_rfkill_block(type, TRUE);
1358 int __connman_technology_update_rfkill(unsigned int index,
1359 enum connman_service_type type,
1360 connman_bool_t softblock,
1361 connman_bool_t hardblock)
1363 struct connman_technology *technology;
1364 struct connman_rfkill *rfkill;
1366 DBG("index %u soft %u hard %u", index, softblock, hardblock);
1368 rfkill = g_hash_table_lookup(rfkill_list, &index);
1372 if (rfkill->softblock == softblock &&
1373 rfkill->hardblock == hardblock)
1376 rfkill->softblock = softblock;
1377 rfkill->hardblock = hardblock;
1380 DBG("%s is switched off.", get_name(type));
1384 technology = technology_find(type);
1385 /* If there is no driver for this type, ignore it. */
1386 if (technology == NULL)
1389 if (!global_offlinemode) {
1390 if (technology->enable_persistent && softblock)
1391 return __connman_rfkill_block(type, FALSE);
1392 if (!technology->enable_persistent && !softblock)
1393 return __connman_rfkill_block(type, TRUE);
1399 int __connman_technology_remove_rfkill(unsigned int index,
1400 enum connman_service_type type)
1402 struct connman_technology *technology;
1403 struct connman_rfkill *rfkill;
1405 DBG("index %u", index);
1407 rfkill = g_hash_table_lookup(rfkill_list, &index);
1411 g_hash_table_remove(rfkill_list, &index);
1413 technology = technology_find(type);
1414 if (technology == NULL)
1417 technology_put(technology);
1422 int __connman_technology_init(void)
1426 connection = connman_dbus_get_connection();
1428 rfkill_list = g_hash_table_new_full(g_int_hash, g_int_equal,
1431 global_offlinemode = connman_technology_load_offlinemode();
1433 /* This will create settings file if it is missing */
1434 connman_technology_save_offlinemode();
1439 void __connman_technology_cleanup(void)
1443 g_hash_table_destroy(rfkill_list);
1445 dbus_connection_unref(connection);