5 * Copyright (C) 2007-2013 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
38 static DBusConnection *connection;
40 static GSList *technology_list = NULL;
43 * List of devices with no technology associated with them either because of
44 * no compiled in support or the driver is not yet loaded.
46 static GSList *techless_device_list = NULL;
47 static GHashTable *rfkill_list;
49 static bool global_offlinemode;
52 struct connman_scan_pending {
54 connman_scan_type_e scan_type;
58 struct connman_bssid_pending {
60 unsigned char bssid[6];
64 struct connman_rfkill {
66 enum connman_service_type type;
71 struct connman_technology {
73 enum connman_service_type type;
81 bool tethering_persistent; /* Tells the save status, needed
82 * as offline mode might set
85 char *tethering_ident;
86 char *tethering_passphrase;
88 bool enable_persistent; /* Save the tech state */
92 DBusMessage *pending_reply;
93 guint pending_timeout;
100 bool dbus_registered;
101 #if defined TIZEN_EXT
102 char **enabled_devices;
104 #if defined TIZEN_EXT_WIFI_MESH
105 DBusMessage *mesh_dbus_msg;
109 static GSList *driver_list = NULL;
111 static int technology_enabled(struct connman_technology *technology);
112 static int technology_disabled(struct connman_technology *technology);
114 static gint compare_priority(gconstpointer a, gconstpointer b)
116 const struct connman_technology_driver *driver1 = a;
117 const struct connman_technology_driver *driver2 = b;
119 return driver2->priority - driver1->priority;
122 static void rfkill_check(gpointer key, gpointer value, gpointer user_data)
124 struct connman_rfkill *rfkill = value;
125 enum connman_service_type type = GPOINTER_TO_INT(user_data);
127 /* Calling _technology_add_rfkill will update the tech. */
128 if (rfkill->type == type)
129 __connman_technology_add_rfkill(rfkill->index, type,
130 rfkill->softblock, rfkill->hardblock);
134 connman_technology_is_tethering_allowed(enum connman_service_type type)
136 static char *allowed_default[] = { "wifi", "bluetooth", "gadget",
138 const char *type_str = __connman_service_type2string(type);
145 allowed = connman_setting_get_string_list("TetheringTechnologies");
147 allowed = allowed_default;
149 for (i = 0; allowed[i]; i++) {
150 if (g_strcmp0(allowed[i], type_str) == 0)
157 static const char *get_name(enum connman_service_type type)
160 case CONNMAN_SERVICE_TYPE_UNKNOWN:
161 case CONNMAN_SERVICE_TYPE_SYSTEM:
162 case CONNMAN_SERVICE_TYPE_GPS:
163 case CONNMAN_SERVICE_TYPE_VPN:
165 case CONNMAN_SERVICE_TYPE_GADGET:
167 case CONNMAN_SERVICE_TYPE_ETHERNET:
169 case CONNMAN_SERVICE_TYPE_WIFI:
171 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
173 case CONNMAN_SERVICE_TYPE_CELLULAR:
175 case CONNMAN_SERVICE_TYPE_P2P:
177 #if defined TIZEN_EXT_WIFI_MESH
178 case CONNMAN_SERVICE_TYPE_MESH:
186 static void technology_save(struct connman_technology *technology)
190 const char *name = get_name(technology->type);
192 DBG("technology %p type %d name %s", technology, technology->type,
197 keyfile = __connman_storage_load_global();
199 keyfile = g_key_file_new();
201 identifier = g_strdup_printf("%s", name);
205 g_key_file_set_boolean(keyfile, identifier, "Enable",
206 technology->enable_persistent);
208 g_key_file_set_boolean(keyfile, identifier, "Tethering",
209 technology->tethering_persistent);
211 if (technology->tethering_ident)
212 g_key_file_set_string(keyfile, identifier,
213 "Tethering.Identifier",
214 technology->tethering_ident);
216 if (technology->tethering_passphrase)
217 g_key_file_set_string(keyfile, identifier,
218 "Tethering.Passphrase",
219 technology->tethering_passphrase);
224 __connman_storage_save_global(keyfile);
226 g_key_file_free(keyfile);
229 static void tethering_changed(struct connman_technology *technology)
231 dbus_bool_t tethering = technology->tethering;
233 connman_dbus_property_changed_basic(technology->path,
234 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
235 DBUS_TYPE_BOOLEAN, &tethering);
237 technology_save(technology);
240 int connman_technology_tethering_notify(struct connman_technology *technology,
245 DBG("technology %p enabled %u", technology, enabled);
247 if (technology->tethering == enabled)
251 err = __connman_tethering_set_enabled();
255 __connman_tethering_set_disabled();
257 technology->tethering = enabled;
258 tethering_changed(technology);
263 static int set_tethering(struct connman_technology *technology,
266 int result = -EOPNOTSUPP;
268 const char *ident, *passphrase, *bridge;
269 GSList *tech_drivers;
271 ident = technology->tethering_ident;
272 passphrase = technology->tethering_passphrase;
274 __sync_synchronize();
275 if (!technology->enabled)
278 bridge = __connman_tethering_get_bridge();
282 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
283 (!ident || !passphrase))
286 for (tech_drivers = technology->driver_list; tech_drivers;
287 tech_drivers = g_slist_next(tech_drivers)) {
288 struct connman_technology_driver *driver = tech_drivers->data;
290 if (!driver || !driver->set_tethering)
293 err = driver->set_tethering(technology, ident, passphrase,
296 if (result == -EINPROGRESS)
299 if (err == -EINPROGRESS || err == 0)
306 void connman_technology_regdom_notify(struct connman_technology *technology,
312 connman_error("Failed to set regulatory domain");
314 DBG("Regulatory domain set to %s", alpha2);
316 g_free(technology->regdom);
317 technology->regdom = g_strdup(alpha2);
320 static int set_regdom_by_device(struct connman_technology *technology,
325 for (list = technology->device_list; list; list = list->next) {
326 struct connman_device *device = list->data;
328 if (connman_device_set_regdom(device, alpha2) != 0)
335 int connman_technology_set_regdom(const char *alpha2)
337 GSList *list, *tech_drivers;
339 for (list = technology_list; list; list = list->next) {
340 struct connman_technology *technology = list->data;
342 if (set_regdom_by_device(technology, alpha2) != 0) {
344 for (tech_drivers = technology->driver_list;
346 tech_drivers = g_slist_next(tech_drivers)) {
348 struct connman_technology_driver *driver =
351 if (driver->set_regdom)
352 driver->set_regdom(technology, alpha2);
360 static struct connman_technology *technology_find(enum connman_service_type type)
364 DBG("type %d", type);
366 for (list = technology_list; list; list = list->next) {
367 struct connman_technology *technology = list->data;
369 if (technology->type == type)
376 enum connman_service_type connman_technology_get_type
377 (struct connman_technology *technology)
380 return CONNMAN_SERVICE_TYPE_UNKNOWN;
382 return technology->type;
385 bool connman_technology_get_wifi_tethering(const char **ssid,
388 struct connman_technology *technology;
395 technology = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
399 if (!technology->tethering)
402 *ssid = technology->tethering_ident;
403 *psk = technology->tethering_passphrase;
408 #if defined TIZEN_EXT
409 const char *connman_techonology_get_path(enum connman_service_type type)
411 struct connman_technology *technology = technology_find(type);
416 return technology->path;
420 static void free_rfkill(gpointer data)
422 struct connman_rfkill *rfkill = data;
427 static void technology_load(struct connman_technology *technology)
431 GError *error = NULL;
432 bool enable, need_saving = false;
434 DBG("technology %p", technology);
436 keyfile = __connman_storage_load_global();
437 /* Fallback on disabling technology if file not found. */
439 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
440 /* We enable ethernet by default */
441 technology->enable_persistent = true;
443 technology->enable_persistent = false;
447 identifier = g_strdup_printf("%s", get_name(technology->type));
453 technology->enabled_devices = g_key_file_get_string_list(keyfile,
454 identifier, "Enable.Devices", &length, NULL);
455 if (technology->enabled_devices && length == 0) {
456 g_strfreev(technology->enabled_devices);
457 technology->enabled_devices = NULL;
461 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
463 technology->enable_persistent = enable;
465 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
466 technology->enable_persistent = true;
468 technology->enable_persistent = false;
471 g_clear_error(&error);
474 enable = g_key_file_get_boolean(keyfile, identifier,
475 "Tethering", &error);
477 technology->tethering_persistent = enable;
480 g_clear_error(&error);
484 technology_save(technology);
486 technology->tethering_ident = g_key_file_get_string(keyfile,
487 identifier, "Tethering.Identifier", NULL);
489 technology->tethering_passphrase = g_key_file_get_string(keyfile,
490 identifier, "Tethering.Passphrase", NULL);
494 g_key_file_free(keyfile);
497 bool __connman_technology_get_offlinemode(void)
499 return global_offlinemode;
502 static void connman_technology_save_offlinemode(void)
505 GError *error = NULL;
508 keyfile = __connman_storage_load_global();
511 keyfile = g_key_file_new();
512 g_key_file_set_boolean(keyfile, "global",
513 "OfflineMode", global_offlinemode);
515 __connman_storage_save_global(keyfile);
518 offlinemode = g_key_file_get_boolean(keyfile, "global",
519 "OfflineMode", &error);
521 if (error || offlinemode != global_offlinemode) {
522 g_key_file_set_boolean(keyfile, "global",
523 "OfflineMode", global_offlinemode);
525 g_clear_error(&error);
527 __connman_storage_save_global(keyfile);
531 g_key_file_free(keyfile);
534 static bool connman_technology_load_offlinemode(void)
537 GError *error = NULL;
540 /* If there is a error, we enable offlinemode */
541 keyfile = __connman_storage_load_global();
545 offlinemode = g_key_file_get_boolean(keyfile, "global",
546 "OfflineMode", &error);
549 g_clear_error(&error);
552 g_key_file_free(keyfile);
557 #if defined TIZEN_EXT
558 static void append_devices(DBusMessageIter *iter, void *user_data)
562 struct connman_technology *technology = user_data;
564 for (list = technology->device_list; list; list = list->next) {
565 struct connman_device *device = list->data;
567 const char *str = connman_device_get_string(device, "Interface");
568 struct connman_network *network = connman_device_get_default_network(device);
569 struct connman_service *service = connman_service_lookup_from_network(network);
571 connman_dbus_dict_append_basic(iter, "Ifname",
572 DBUS_TYPE_STRING, &str);
574 val = connman_device_get_powered(device);
575 connman_dbus_dict_append_basic(iter, "Powered",
576 DBUS_TYPE_BOOLEAN, &val);
578 if (__connman_service_is_connected_state(service, CONNMAN_IPCONFIG_TYPE_IPV4) ||
579 __connman_service_is_connected_state(service, CONNMAN_IPCONFIG_TYPE_IPV6))
584 connman_dbus_dict_append_basic(iter, "Connected",
585 DBUS_TYPE_BOOLEAN, &val);
587 str = connman_device_get_string(device, "Address");
588 connman_dbus_dict_append_basic(iter, "MAC.Address",
589 DBUS_TYPE_STRING, &str);
593 void __connman_technology_append_interfaces(DBusMessageIter *array,
594 enum connman_service_type type, const char *ifname)
597 struct connman_technology *technology = NULL;
599 for (list = technology_list; list; list = list->next) {
600 struct connman_technology *local_tech = list->data;
602 if (local_tech->type != type)
605 technology = local_tech;
612 for (list = technology->device_list; list; list = list->next) {
613 struct connman_device *device = list->data;
614 const char *str = connman_device_get_string(device, "Interface");
616 if (g_strcmp0(ifname, str) == 0)
619 dbus_message_iter_append_basic(array,
620 DBUS_TYPE_STRING, &str);
625 static void append_properties(DBusMessageIter *iter,
626 struct connman_technology *technology)
628 DBusMessageIter dict;
632 connman_dbus_dict_open(iter, &dict);
634 str = get_name(technology->type);
636 connman_dbus_dict_append_basic(&dict, "Name",
637 DBUS_TYPE_STRING, &str);
639 str = __connman_service_type2string(technology->type);
641 connman_dbus_dict_append_basic(&dict, "Type",
642 DBUS_TYPE_STRING, &str);
644 __sync_synchronize();
645 val = technology->enabled;
646 connman_dbus_dict_append_basic(&dict, "Powered",
650 val = technology->connected;
651 connman_dbus_dict_append_basic(&dict, "Connected",
655 val = technology->tethering;
656 connman_dbus_dict_append_basic(&dict, "Tethering",
660 if (technology->tethering_ident)
661 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
663 &technology->tethering_ident);
665 if (technology->tethering_passphrase)
666 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
668 &technology->tethering_passphrase);
669 #if defined TIZEN_EXT
670 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI)
671 connman_dbus_dict_append_dict(&dict, "Device.List",
672 append_devices, technology);
674 connman_dbus_dict_close(iter, &dict);
677 static void technology_added_signal(struct connman_technology *technology)
680 DBusMessageIter iter;
682 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
683 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
687 dbus_message_iter_init_append(signal, &iter);
688 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
690 append_properties(&iter, technology);
692 dbus_connection_send(connection, signal, NULL);
693 dbus_message_unref(signal);
696 static void technology_removed_signal(struct connman_technology *technology)
698 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
699 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
700 DBUS_TYPE_OBJECT_PATH, &technology->path,
704 static DBusMessage *get_properties(DBusConnection *conn,
705 DBusMessage *message, void *user_data)
707 struct connman_technology *technology = user_data;
709 DBusMessageIter iter;
711 reply = dbus_message_new_method_return(message);
715 dbus_message_iter_init_append(reply, &iter);
716 append_properties(&iter, technology);
721 void __connman_technology_list_struct(DBusMessageIter *array)
724 DBusMessageIter entry;
726 for (list = technology_list; list; list = list->next) {
727 struct connman_technology *technology = list->data;
729 if (!technology->path ||
730 (technology->rfkill_driven &&
731 technology->hardblocked))
734 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
736 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
738 append_properties(&entry, technology);
739 dbus_message_iter_close_container(array, &entry);
743 static gboolean technology_pending_reply(gpointer user_data)
745 struct connman_technology *technology = user_data;
748 /* Power request timed out, send ETIMEDOUT. */
749 if (technology->pending_reply) {
750 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
752 g_dbus_send_message(connection, reply);
754 dbus_message_unref(technology->pending_reply);
755 technology->pending_reply = NULL;
756 technology->pending_timeout = 0;
762 static int technology_affect_devices(struct connman_technology *technology,
765 int err = 0, err_dev;
768 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
770 __connman_technology_enabled(technology->type);
772 __connman_technology_disabled(technology->type);
776 #if defined TIZEN_EXT_WIFI_MESH
777 if (technology->type == CONNMAN_SERVICE_TYPE_MESH)
781 for (list = technology->device_list; list; list = list->next) {
782 struct connman_device *device = list->data;
785 err_dev = __connman_device_enable(device);
787 err_dev = __connman_device_disable(device);
789 if (err_dev < 0 && err_dev != -EALREADY)
796 static void powered_changed(struct connman_technology *technology)
800 if (!technology->dbus_registered)
803 if (technology->pending_reply) {
804 g_dbus_send_reply(connection,
805 technology->pending_reply, DBUS_TYPE_INVALID);
806 dbus_message_unref(technology->pending_reply);
807 technology->pending_reply = NULL;
809 g_source_remove(technology->pending_timeout);
810 technology->pending_timeout = 0;
813 __sync_synchronize();
814 enabled = technology->enabled;
815 #if defined TIZEN_EXT
816 DBG("ConnMan, Powered : %s, %s",
817 enabled ? "TRUE" : "FALSE",technology->path);
819 connman_dbus_property_changed_basic(technology->path,
820 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
821 DBUS_TYPE_BOOLEAN, &enabled);
824 static void enable_tethering(struct connman_technology *technology)
828 if (!connman_setting_get_bool("PersistentTetheringMode"))
831 ret = set_tethering(technology, true);
832 if (ret < 0 && ret != -EALREADY)
833 DBG("Cannot enable tethering yet for %s (%d/%s)",
834 get_name(technology->type),
835 -ret, strerror(-ret));
838 static int technology_enabled(struct connman_technology *technology)
840 __sync_synchronize();
841 if (technology->enabled)
844 technology->enabled = true;
846 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
847 struct connman_technology *p2p;
849 p2p = technology_find(CONNMAN_SERVICE_TYPE_P2P);
850 if (p2p && !p2p->enabled && p2p->enable_persistent)
851 technology_enabled(p2p);
854 if (technology->tethering_persistent)
855 enable_tethering(technology);
857 powered_changed(technology);
862 static int technology_enable(struct connman_technology *technology)
867 DBG("technology %p enable", technology);
869 __sync_synchronize();
871 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
872 struct connman_technology *wifi;
874 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
875 if (wifi && wifi->enabled)
876 return technology_enabled(technology);
880 if (technology->enabled)
883 if (technology->pending_reply)
886 if (connman_setting_get_bool("PersistentTetheringMode") &&
887 technology->tethering)
888 set_tethering(technology, true);
890 if (technology->rfkill_driven)
891 err = __connman_rfkill_block(technology->type, false);
893 err_dev = technology_affect_devices(technology, true);
895 if (!technology->rfkill_driven)
901 static int technology_disabled(struct connman_technology *technology)
903 __sync_synchronize();
904 if (!technology->enabled)
907 technology->enabled = false;
909 powered_changed(technology);
914 static int technology_disable(struct connman_technology *technology)
918 DBG("technology %p disable", technology);
920 __sync_synchronize();
922 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
923 technology->enable_persistent = false;
924 __connman_device_stop_scan(CONNMAN_SERVICE_TYPE_P2P);
925 __connman_peer_disconnect_all();
926 return technology_disabled(technology);
927 } else if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
928 struct connman_technology *p2p;
930 p2p = technology_find(CONNMAN_SERVICE_TYPE_P2P);
931 if (p2p && p2p->enabled) {
932 p2p->enable_persistent = true;
933 technology_disabled(p2p);
937 if (!technology->enabled)
940 if (technology->pending_reply)
943 if (technology->tethering)
944 set_tethering(technology, false);
946 err = technology_affect_devices(technology, false);
948 if (technology->rfkill_driven)
949 err = __connman_rfkill_block(technology->type, true);
954 static DBusMessage *set_powered(struct connman_technology *technology,
955 DBusMessage *msg, bool powered)
957 DBusMessage *reply = NULL;
960 if (technology->rfkill_driven && technology->hardblocked) {
966 err = technology_enable(technology);
968 err = technology_disable(technology);
971 technology->enable_persistent = powered;
972 technology_save(technology);
976 if (err == -EINPROGRESS) {
977 technology->pending_reply = dbus_message_ref(msg);
978 technology->pending_timeout = g_timeout_add_seconds(10,
979 technology_pending_reply, technology);
980 } else if (err == -EALREADY) {
982 reply = __connman_error_already_enabled(msg);
984 reply = __connman_error_already_disabled(msg);
986 reply = __connman_error_failed(msg, -err);
988 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
993 #if defined TIZEN_EXT
994 int set_connman_bssid(enum bssid_type mode, char *bssid, const char *ifname)
996 static int bssid_len;
997 static const char *def_ifname = "default";
998 static GSList *bssid_list = NULL;
1000 const char *local_ifname = ifname;
1002 struct connman_bssid_pending *bssid_info;
1004 DBG("mode: %d, ifname: %s", mode, ifname);
1007 local_ifname = def_ifname;
1009 for (list = bssid_list; list; list = list->next) {
1010 bssid_info = list->data;
1012 if (g_strcmp0(bssid_info->ifname, local_ifname) == 0) {
1018 if (mode == CHECK_BSSID) {
1025 if (mode == GET_BSSID && bssid) {
1027 memcpy(bssid, bssid_info->bssid, 6);
1033 if (mode == RESET_BSSID) {
1035 bssid_list = g_slist_remove(bssid_list, bssid_info);
1036 g_free(bssid_info->ifname);
1042 if (mode != SET_BSSID || !bssid) {
1043 DBG("Invalid parameter");
1048 bssid_list = g_slist_remove(bssid_list, bssid_info);
1049 g_free(bssid_info->ifname);
1053 bssid_info = g_try_malloc0(sizeof(struct connman_bssid_pending));
1055 DBG("Failed to allocate memory");
1059 unsigned char *bssid_data = bssid_info->bssid;
1061 bssid_len = sscanf(bssid, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
1062 &bssid_data[0], &bssid_data[1], &bssid_data[2],
1063 &bssid_data[3], &bssid_data[4], &bssid_data[5]);
1064 if (bssid_len != 6) {
1065 DBG("Incorrect BSSID format. bssid_len = %d", bssid_len);
1070 DBG("SET BSSID len: %d, BSSID: %02x:%02x:%02x:%02x:%02x:%02x ifname: %s",
1072 bssid_data[0], bssid_data[1], bssid_data[2],
1073 bssid_data[3], bssid_data[4], bssid_data[5],
1076 bssid_info->ifname = g_strdup(ifname);
1077 bssid_list = g_slist_prepend(bssid_list, bssid_info);
1083 static DBusMessage *set_property(DBusConnection *conn,
1084 DBusMessage *msg, void *data)
1086 struct connman_technology *technology = data;
1087 DBusMessageIter iter, value;
1091 DBG("conn %p", conn);
1093 if (!dbus_message_iter_init(msg, &iter))
1094 return __connman_error_invalid_arguments(msg);
1096 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1097 return __connman_error_invalid_arguments(msg);
1099 dbus_message_iter_get_basic(&iter, &name);
1100 dbus_message_iter_next(&iter);
1102 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
1103 return __connman_error_invalid_arguments(msg);
1105 dbus_message_iter_recurse(&iter, &value);
1107 type = dbus_message_iter_get_arg_type(&value);
1109 DBG("property %s", name);
1111 if (g_str_equal(name, "Tethering")) {
1112 dbus_bool_t tethering;
1115 if (type != DBUS_TYPE_BOOLEAN)
1116 return __connman_error_invalid_arguments(msg);
1118 if (!connman_technology_is_tethering_allowed(technology->type)) {
1119 DBG("%s tethering not allowed by config file",
1120 __connman_service_type2string(technology->type));
1121 return __connman_error_not_supported(msg);
1124 dbus_message_iter_get_basic(&value, &tethering);
1126 if (technology->tethering == tethering) {
1128 return __connman_error_already_disabled(msg);
1130 return __connman_error_already_enabled(msg);
1133 err = set_tethering(technology, tethering);
1135 return __connman_error_failed(msg, -err);
1137 technology->tethering_persistent = tethering;
1139 technology_save(technology);
1141 } else if (g_str_equal(name, "TetheringIdentifier")) {
1144 dbus_message_iter_get_basic(&value, &str);
1146 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1147 return __connman_error_not_supported(msg);
1149 if (strlen(str) < 1 || strlen(str) > 32)
1150 return __connman_error_invalid_arguments(msg);
1152 if (g_strcmp0(technology->tethering_ident, str) != 0) {
1153 g_free(technology->tethering_ident);
1154 technology->tethering_ident = g_strdup(str);
1155 technology_save(technology);
1157 connman_dbus_property_changed_basic(technology->path,
1158 CONNMAN_TECHNOLOGY_INTERFACE,
1159 "TetheringIdentifier",
1161 &technology->tethering_ident);
1163 } else if (g_str_equal(name, "TetheringPassphrase")) {
1166 dbus_message_iter_get_basic(&value, &str);
1168 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1169 return __connman_error_not_supported(msg);
1171 err = __connman_service_check_passphrase(CONNMAN_SERVICE_SECURITY_PSK,
1174 return __connman_error_passphrase_required(msg);
1176 if (g_strcmp0(technology->tethering_passphrase, str) != 0) {
1177 g_free(technology->tethering_passphrase);
1178 technology->tethering_passphrase = g_strdup(str);
1179 technology_save(technology);
1181 connman_dbus_property_changed_basic(technology->path,
1182 CONNMAN_TECHNOLOGY_INTERFACE,
1183 "TetheringPassphrase",
1185 &technology->tethering_passphrase);
1187 } else if (g_str_equal(name, "Powered")) {
1190 if (type != DBUS_TYPE_BOOLEAN)
1191 return __connman_error_invalid_arguments(msg);
1193 dbus_message_iter_get_basic(&value, &enable);
1195 return set_powered(technology, msg, enable);
1196 #if defined TIZEN_EXT
1197 } else if (g_str_equal(name, "SetBSSID")) {
1200 if (type != DBUS_TYPE_STRING)
1201 return __connman_error_invalid_arguments(msg);
1203 dbus_message_iter_get_basic(&value, &key);
1204 DBG("BSSID %s", key);
1205 set_connman_bssid(SET_BSSID, key, NULL);
1208 return __connman_error_invalid_property(msg);
1210 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1213 static void reply_scan_pending(struct connman_technology *technology, int err)
1217 DBG("technology %p err %d", technology, err);
1219 while (technology->scan_pending) {
1220 #if defined TIZEN_EXT
1221 struct connman_scan_pending *pending_data = technology->scan_pending->data;
1222 DBusMessage *msg = pending_data->msg;
1224 DBusMessage *msg = technology->scan_pending->data;
1226 DBG("reply to %s", dbus_message_get_sender(msg));
1229 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1231 reply = __connman_error_failed(msg, -err);
1232 g_dbus_send_message(connection, reply);
1233 dbus_message_unref(msg);
1235 technology->scan_pending =
1236 g_slist_delete_link(technology->scan_pending,
1237 technology->scan_pending);
1238 #if defined TIZEN_EXT
1239 g_free(pending_data->ifname);
1240 g_free(pending_data);
1245 #if defined TIZEN_EXT
1246 dbus_bool_t __connman_technology_notify_scan_changed(const char *key, void *val)
1249 DBusMessage *signal;
1250 DBusMessageIter iter;
1251 dbus_bool_t result = FALSE;
1253 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
1254 CONNMAN_MANAGER_INTERFACE, "ScanChanged");
1258 dbus_message_iter_init_append(signal, &iter);
1260 connman_dbus_property_append_basic(&iter, key, DBUS_TYPE_BOOLEAN, val);
1262 connman_dbus_property_append_basic(&iter, "", DBUS_TYPE_BOOLEAN, val);
1264 result = dbus_connection_send(connection, signal, NULL);
1265 dbus_message_unref(signal);
1267 DBG("Successfuly sent signal");
1272 void __connman_technology_notify_scan_done(const char *ifname, int val)
1275 DBusMessage *signal;
1276 DBusMessageIter iter;
1278 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
1279 CONNMAN_MANAGER_INTERFACE, "ScanDone");
1283 dbus_message_iter_init_append(signal, &iter);
1285 connman_dbus_property_append_basic(&iter, ifname,
1286 DBUS_TYPE_INT32, &val);
1288 connman_dbus_property_append_basic(&iter, "",
1289 DBUS_TYPE_INT32, &val);
1291 dbus_connection_send(connection, signal, NULL);
1292 dbus_message_unref(signal);
1294 DBG("Successfuly sent ScanDone signal");
1297 static void reply_scan_pending_device(
1298 struct connman_technology *technology, const char *ifname, int count)
1302 dbus_bool_t status = 0;
1303 connman_scan_type_e scan_type = CONNMAN_SCAN_TYPE_UNKNOWN;
1305 DBG("technology %p ifname %s count %d", technology, ifname, count);
1307 list = technology->scan_pending;
1310 struct connman_scan_pending *pending_data = list->data;
1311 DBusMessage *msg = pending_data->msg;
1314 if (scan_type == CONNMAN_SCAN_TYPE_UNKNOWN)
1315 scan_type = pending_data->scan_type;
1317 if (count != 0 && g_strcmp0(pending_data->ifname, ifname) != 0)
1320 scan_type = pending_data->scan_type;
1322 DBG("reply to %s", dbus_message_get_sender(msg));
1323 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1325 g_dbus_send_message(connection, reply);
1326 dbus_message_unref(msg);
1328 technology->scan_pending =
1329 g_slist_remove(technology->scan_pending, pending_data);
1331 g_free(pending_data->ifname);
1332 g_free(pending_data);
1335 if (scan_type == CONNMAN_SCAN_TYPE_UNKNOWN)
1336 scan_type = CONNMAN_SCAN_TYPE_FULL_CHANNEL;
1338 __connman_technology_notify_scan_changed(ifname, &status);
1339 __connman_technology_notify_scan_done(ifname, scan_type);
1342 static void __connman_technology_notify_device_detected(
1343 struct connman_technology *technology, const char *ifname, bool val)
1346 DBusMessage *signal;
1347 DBusMessageIter iter;
1348 dbus_bool_t detected = val;
1353 signal = dbus_message_new_signal(technology->path,
1354 CONNMAN_TECHNOLOGY_INTERFACE, "DeviceDetected");
1358 dbus_message_iter_init_append(signal, &iter);
1359 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ifname);
1360 dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &detected);
1362 dbus_connection_send(connection, signal, NULL);
1363 dbus_message_unref(signal);
1365 DBG("Successfuly sent DeviceDetected signal");
1369 void __connman_technology_scan_started(struct connman_device *device)
1371 DBG("device %p", device);
1372 #if defined TIZEN_EXT
1373 dbus_bool_t status = 1;
1374 const char *ifname = connman_device_get_string(device, "Interface");
1376 __connman_technology_notify_scan_changed(ifname, &status);
1380 void __connman_technology_scan_stopped(struct connman_device *device,
1381 enum connman_service_type type)
1384 struct connman_technology *technology;
1387 technology = technology_find(type);
1389 DBG("technology %p device %p", technology, device);
1394 for (list = technology->device_list; list; list = list->next) {
1395 struct connman_device *other_device = list->data;
1397 if (device == other_device)
1400 if (connman_device_get_scanning(other_device, type))
1404 #if defined TIZEN_EXT
1405 const char *ifname = connman_device_get_string(device, "Interface");
1406 reply_scan_pending_device(technology, ifname, count);
1411 reply_scan_pending(technology, 0);
1414 void __connman_technology_notify_regdom_by_device(struct connman_device *device,
1415 int result, const char *alpha2)
1417 bool regdom_set = false;
1418 struct connman_technology *technology;
1419 enum connman_service_type type;
1420 GSList *tech_drivers;
1422 type = __connman_device_get_service_type(device);
1423 technology = technology_find(type);
1430 for (tech_drivers = technology->driver_list;
1432 tech_drivers = g_slist_next(tech_drivers)) {
1433 struct connman_technology_driver *driver =
1436 if (driver->set_regdom) {
1437 driver->set_regdom(technology, alpha2);
1447 connman_technology_regdom_notify(technology, alpha2);
1450 static DBusMessage *scan(DBusConnection *conn, DBusMessage *msg, void *data)
1452 struct connman_technology *technology = data;
1455 DBG("technology %p request from %s", technology,
1456 dbus_message_get_sender(msg));
1458 if (technology->type == CONNMAN_SERVICE_TYPE_P2P &&
1459 !technology->enabled)
1460 return __connman_error_permission_denied(msg);
1462 #if !defined TIZEN_EXT
1463 dbus_message_ref(msg);
1464 technology->scan_pending =
1465 g_slist_prepend(technology->scan_pending, msg);
1468 err = __connman_device_request_scan_full(technology->type);
1470 #if defined TIZEN_EXT
1471 return __connman_error_failed(msg, -err);
1473 reply_scan_pending(technology, err);
1476 #if defined TIZEN_EXT
1477 struct connman_scan_pending *pending_data =
1478 g_try_malloc0(sizeof(struct connman_scan_pending));
1480 return __connman_error_failed(msg, ENOMEM);
1482 pending_data->scan_type = CONNMAN_SCAN_TYPE_FULL_CHANNEL;
1483 DBG("scan_type %d", pending_data->scan_type);
1485 pending_data->msg = dbus_message_ref(msg);
1487 technology->scan_pending =
1488 g_slist_prepend(technology->scan_pending, pending_data);
1493 #if defined TIZEN_EXT
1494 static DBusMessage *scan_device(DBusConnection *conn, DBusMessage *msg, void *data)
1496 struct connman_technology *technology = data;
1497 DBusMessageIter iter;
1501 DBG("technology %p request from %s", technology,
1502 dbus_message_get_sender(msg));
1504 if (!dbus_message_iter_init(msg, &iter))
1505 return __connman_error_invalid_arguments(msg);
1507 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1508 return __connman_error_invalid_arguments(msg);
1510 dbus_message_iter_get_basic(&iter, &ifname);
1511 DBG("Interface name %s", ifname);
1513 if (!ifname || strlen(ifname) == 0)
1514 return __connman_error_invalid_arguments(msg);
1516 err = connman_device_request_device_scan(technology->type, ifname, true);
1518 return __connman_error_failed(msg, -err);
1520 struct connman_scan_pending *pending_data =
1521 g_try_malloc0(sizeof(struct connman_scan_pending));
1523 return __connman_error_failed(msg, ENOMEM);
1525 pending_data->ifname = g_strdup(ifname);
1526 if (pending_data->ifname == NULL) {
1527 g_free(pending_data);
1528 return __connman_error_failed(msg, ENOMEM);
1531 pending_data->scan_type = CONNMAN_SCAN_TYPE_FULL_CHANNEL;
1532 DBG("scan_type %d", pending_data->scan_type);
1534 pending_data->msg = dbus_message_ref(msg);
1536 technology->scan_pending =
1537 g_slist_prepend(technology->scan_pending, pending_data);
1542 static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void *data)
1544 struct connman_technology *technology = data;
1545 GSList *specific_scan_list = NULL;
1547 const char *name = NULL;
1548 const char *freq = NULL;
1549 const char *ifname = NULL;
1550 DBusMessageIter iter, dict;
1553 DBG("technology %p request from %s", technology,
1554 dbus_message_get_sender(msg));
1556 if (!dbus_message_iter_init(msg, &iter))
1557 return __connman_error_invalid_arguments(msg);
1559 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
1560 return __connman_error_invalid_arguments(msg);
1562 dbus_message_iter_recurse(&iter, &dict);
1563 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1564 DBusMessageIter entry, value2;
1568 dbus_message_iter_recurse(&dict, &entry);
1569 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) {
1570 g_slist_free_full(specific_scan_list, g_free);
1571 return __connman_error_invalid_arguments(msg);
1574 dbus_message_iter_get_basic(&entry, &key);
1575 dbus_message_iter_next(&entry);
1577 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) {
1578 g_slist_free_full(specific_scan_list, g_free);
1579 return __connman_error_invalid_arguments(msg);
1582 dbus_message_iter_recurse(&entry, &value2);
1583 type = dbus_message_iter_get_arg_type(&value2);
1584 if (g_str_equal(key, "Ifname") && type == DBUS_TYPE_STRING) {
1586 dbus_message_iter_get_basic(&value2, &ifname);
1587 DBG("ifname %s", ifname);
1588 } else if (g_str_equal(key, "SSID")) {
1589 if (type != DBUS_TYPE_STRING) {
1590 g_slist_free_full(specific_scan_list, g_free);
1591 return __connman_error_invalid_arguments(msg);
1594 scan_type = CONNMAN_MULTI_SCAN_SSID; /* SSID based scan */
1595 dbus_message_iter_get_basic(&value2, &name);
1596 DBG("name %s", name);
1597 specific_scan_list = g_slist_append(specific_scan_list, g_strdup(name));
1598 } else if (g_str_equal(key, "Frequency")) {
1599 if (type != DBUS_TYPE_STRING) {
1600 g_slist_free_full(specific_scan_list, g_free);
1601 return __connman_error_invalid_arguments(msg);
1604 scan_type = CONNMAN_MULTI_SCAN_FREQ; /* Frequency based scan */
1605 dbus_message_iter_get_basic(&value2, &freq);
1606 DBG("freq %s", freq);
1607 specific_scan_list = g_slist_append(specific_scan_list, GINT_TO_POINTER(atoi(freq)));
1608 } else if (g_str_equal(key, "SSID_Mixed")) {
1609 if (type != DBUS_TYPE_STRING) {
1610 g_slist_free_full(specific_scan_list, g_free);
1611 return __connman_error_invalid_arguments(msg);
1614 scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */
1615 dbus_message_iter_get_basic(&value2, &name);
1617 connman_multi_scan_ap_s *ap =
1618 (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s));
1620 g_strlcpy(ap->str, name, strlen(name) + 1);
1622 specific_scan_list = g_slist_append(specific_scan_list, ap);
1624 DBG("Failed to allocate memory");
1626 } else if (g_str_equal(key, "Frequency_Mixed")) {
1627 if (type != DBUS_TYPE_STRING) {
1628 g_slist_free_full(specific_scan_list, g_free);
1629 return __connman_error_invalid_arguments(msg);
1632 scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */
1633 dbus_message_iter_get_basic(&value2, &freq);
1635 connman_multi_scan_ap_s *ap =
1636 (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s));
1638 g_strlcpy(ap->str, freq, strlen(freq) + 1);
1640 specific_scan_list = g_slist_append(specific_scan_list, ap);
1642 DBG("Failed to allocate memory");
1644 dbus_message_iter_next(&dict);
1647 err = __connman_device_request_specific_scan(technology->type, ifname, scan_type, specific_scan_list);
1649 return __connman_error_failed(msg, -err);
1651 guint list_size = g_slist_length(specific_scan_list);
1653 if (scan_type == CONNMAN_MULTI_SCAN_SSID ||
1654 scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ)
1655 g_slist_free_full(specific_scan_list, g_free);
1657 struct connman_scan_pending *pending_data =
1658 g_try_malloc0(sizeof(struct connman_scan_pending));
1660 return __connman_error_failed(msg, ENOMEM);
1663 pending_data->ifname = g_strdup(ifname);
1664 if (pending_data->ifname == NULL) {
1665 g_free(pending_data);
1666 return __connman_error_failed(msg, ENOMEM);
1671 pending_data->scan_type = CONNMAN_SCAN_TYPE_SPECIFIC_AP;
1673 pending_data->scan_type = CONNMAN_SCAN_TYPE_MULTI_AP;
1674 DBG("list_size %u scan_type %d", list_size, pending_data->scan_type);
1676 pending_data->msg = dbus_message_ref(msg);
1678 technology->scan_pending =
1679 g_slist_prepend(technology->scan_pending, pending_data);
1684 static DBusMessage *get_5ghz_supported(DBusConnection *conn, DBusMessage *msg, void *data)
1687 DBusMessageIter iter, dict;
1689 struct connman_technology *technology = data;
1690 dbus_bool_t supported = false;
1691 const char *ifname = NULL;
1693 DBG("technology %p", technology);
1695 reply = dbus_message_new_method_return(msg);
1699 dbus_message_iter_init_append(reply, &iter);
1700 connman_dbus_dict_open(&iter, &dict);
1702 for (list = technology->device_list; list; list = list->next) {
1703 struct connman_device *device = list->data;
1705 supported = connman_device_get_wifi_5ghz_supported(device);
1706 ifname = connman_device_get_string(device, "Interface");
1708 DBG("ifname %s supported : %d", ifname, supported);
1709 connman_dbus_dict_append_basic(&dict, ifname,
1714 connman_dbus_dict_close(&iter, &dict);
1719 static DBusMessage *get_scan_state(DBusConnection *conn, DBusMessage *msg, void *data)
1722 DBusMessageIter iter, dict;
1724 struct connman_technology *technology = data;
1725 dbus_bool_t scanning = false;
1726 const char *ifname = NULL;
1728 DBG("technology %p", technology);
1730 reply = dbus_message_new_method_return(msg);
1734 dbus_message_iter_init_append(reply, &iter);
1735 connman_dbus_dict_open(&iter, &dict);
1737 for (list = technology->device_list; list; list = list->next) {
1738 struct connman_device *device = list->data;
1740 scanning = connman_device_get_scanning(device, technology->type);
1741 ifname = connman_device_get_string(device, "Interface");
1743 DBG("ifname %s scanning : %d", ifname, scanning);
1744 connman_dbus_dict_append_basic(&dict, ifname,
1749 connman_dbus_dict_close(&iter, &dict);
1754 static DBusMessage *get_max_scan_ssid(DBusConnection *conn, DBusMessage *msg, void *data)
1757 DBusMessageIter iter, dict;
1759 struct connman_technology *technology = data;
1760 dbus_int32_t max_scan_ssids = 0;
1761 const char *ifname = NULL;
1763 DBG("technology %p", technology);
1765 reply = dbus_message_new_method_return(msg);
1769 dbus_message_iter_init_append(reply, &iter);
1770 connman_dbus_dict_open(&iter, &dict);
1772 for (list = technology->device_list; list; list = list->next) {
1773 struct connman_device *device = list->data;
1775 max_scan_ssids = connman_device_get_max_scan_ssids(device);
1776 ifname = connman_device_get_string(device, "Interface");
1778 DBG("ifname %s max_scan_ssids : %d", ifname, max_scan_ssids);
1779 connman_dbus_dict_append_basic(&dict, ifname,
1784 connman_dbus_dict_close(&iter, &dict);
1789 static int technology_enable_device(struct connman_technology *technology,
1790 bool enable_device, const char *ifname, struct connman_device **device_out)
1795 for (list = technology->device_list; list; list = list->next) {
1796 struct connman_device *device = list->data;
1797 const char *str = connman_device_get_string(device, "Interface");
1799 if (g_strcmp0(str, ifname) != 0)
1803 err = __connman_device_enable(device);
1805 err = __connman_device_disable(device);
1807 *device_out = device;
1814 static DBusMessage *technology_set_device_powered(struct connman_technology *technology,
1815 DBusMessage *msg, bool powered, const char *ifname)
1817 DBusMessage *reply = NULL;
1818 struct connman_device *device = NULL;
1821 err = technology_enable_device(technology, powered, ifname, &device);
1823 if (err == -EINPROGRESS) {
1825 connman_device_set_pending_reply(device, msg);
1827 } else if (err == -EALREADY) {
1829 reply = __connman_error_already_enabled(msg);
1831 reply = __connman_error_already_disabled(msg);
1833 reply = __connman_error_failed(msg, -err);
1835 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1840 static DBusMessage *set_device_power(DBusConnection *conn,
1841 DBusMessage *msg, void *data)
1843 struct connman_technology *technology = data;
1844 DBusMessageIter iter;
1849 DBG("conn %p", conn);
1851 if (!dbus_message_iter_init(msg, &iter))
1852 return __connman_error_invalid_arguments(msg);
1854 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1855 return __connman_error_invalid_arguments(msg);
1857 dbus_message_iter_get_basic(&iter, &name);
1858 dbus_message_iter_next(&iter);
1860 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
1861 return __connman_error_invalid_arguments(msg);
1863 DBG("interface name %s", name);
1867 if (len + 1 > IFNAMSIZ)
1868 return __connman_error_invalid_arguments(msg);
1870 dbus_message_iter_get_basic(&iter, &enable);
1871 DBG("powered %s", enable ? "TRUE" : "FALSE");
1873 return technology_set_device_powered(technology, msg, enable, name);
1876 static DBusMessage *set_bssid(DBusConnection *conn,
1877 DBusMessage *msg, void *data)
1879 DBusMessageIter iter;
1883 DBG("conn %p", conn);
1885 if (!dbus_message_iter_init(msg, &iter))
1886 return __connman_error_invalid_arguments(msg);
1888 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1889 return __connman_error_invalid_arguments(msg);
1891 dbus_message_iter_get_basic(&iter, &name);
1892 dbus_message_iter_next(&iter);
1894 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1895 return __connman_error_invalid_arguments(msg);
1897 dbus_message_iter_get_basic(&iter, &bssid);
1899 DBG("interface name %s bssid %s", name, bssid);
1903 if (len + 1 > IFNAMSIZ)
1904 return __connman_error_invalid_arguments(msg);
1906 set_connman_bssid(SET_BSSID, bssid, name);
1908 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1910 static struct connman_technology *technology_get(enum connman_service_type type);
1912 void technology_save_device(struct connman_device *device)
1914 struct connman_technology *technology;
1915 enum connman_service_type type;
1917 type = __connman_device_get_service_type(device);
1918 technology = technology_get(type);
1924 const char *name = get_name(technology->type);
1926 DBG("technology %p type %d name %s", technology, technology->type,
1931 keyfile = __connman_storage_load_global();
1933 keyfile = g_key_file_new();
1935 identifier = g_strdup_printf("%s", name);
1939 GSList *list = NULL;
1940 gchar **ifname_list = NULL;
1941 guint dev_count = g_slist_length(technology->device_list);
1943 if (dev_count > 1) {
1944 GString *ifname_str = g_string_new(NULL);
1947 for (list = technology->device_list; list; list = list->next) {
1948 struct connman_device *device = list->data;
1950 if (connman_device_get_powered(device)) {
1951 const char *ifname = connman_device_get_string(device, "Interface");
1953 if (ifname_str->len > 0)
1954 g_string_append_printf(ifname_str, " %s", ifname);
1956 g_string_append(ifname_str, ifname);
1960 if (ifname_str->len > 0) {
1961 ifname_list = g_strsplit_set(ifname_str->str, " ", 0);
1962 dev_count = g_strv_length(ifname_list);
1963 g_key_file_set_string_list(keyfile, identifier, "Enable.Devices",
1964 (const gchar **) ifname_list, dev_count);
1966 technology->enable_persistent = true;
1968 g_key_file_remove_key(keyfile, identifier, "Enable.Devices", NULL);
1969 technology->enable_persistent = false;
1972 g_strfreev(ifname_list);
1973 g_string_free(ifname_str, TRUE);
1977 g_key_file_set_boolean(keyfile, identifier, "Enable",
1978 technology->enable_persistent);
1980 g_key_file_set_boolean(keyfile, identifier, "Tethering",
1981 technology->tethering_persistent);
1983 if (technology->tethering_ident)
1984 g_key_file_set_string(keyfile, identifier,
1985 "Tethering.Identifier",
1986 technology->tethering_ident);
1988 if (technology->tethering_passphrase)
1989 g_key_file_set_string(keyfile, identifier,
1990 "Tethering.Passphrase",
1991 technology->tethering_passphrase);
1996 __connman_storage_save_global(keyfile);
1998 g_key_file_free(keyfile);
2002 #if defined TIZEN_EXT_WIFI_MESH
2003 bool __connman_technology_get_connected(enum connman_service_type type)
2005 struct connman_technology *technology;
2007 technology = technology_find(type);
2012 return technology->connected;
2015 void __connman_technology_mesh_interface_create_finished(
2016 enum connman_service_type type, bool success,
2020 struct connman_technology *technology;
2022 technology = technology_find(type);
2024 DBG("technology %p success %d", technology, success);
2029 msg = technology->mesh_dbus_msg;
2031 DBG("No pending dbus message");
2036 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2037 __connman_device_request_scan(technology->type);
2039 reply = g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
2040 ".MeshInterfaceAddFailed", "%s", error);
2041 g_dbus_send_message(connection, reply);
2042 dbus_message_unref(msg);
2043 technology->mesh_dbus_msg = NULL;
2046 void __connman_technology_mesh_interface_remove_finished(
2047 enum connman_service_type type, bool success)
2050 struct connman_technology *technology;
2052 technology = technology_find(type);
2054 DBG("technology %p success %d", technology, success);
2056 if (!technology || !technology->mesh_dbus_msg)
2059 msg = technology->mesh_dbus_msg;
2061 DBG("No pending dbus message");
2066 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2068 reply = __connman_error_failed(msg, EINVAL);
2069 g_dbus_send_message(connection, reply);
2070 dbus_message_unref(msg);
2071 technology->mesh_dbus_msg = NULL;
2074 void __connman_technology_notify_abort_scan(enum connman_service_type type,
2078 struct connman_technology *technology;
2080 technology = technology_find(type);
2082 DBG("technology %p result %d", technology, result);
2084 if (!technology || !technology->mesh_dbus_msg)
2087 msg = technology->mesh_dbus_msg;
2089 DBG("No pending dbus message");
2094 reply = __connman_error_scan_abort_failed(msg);
2096 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2098 g_dbus_send_message(connection, reply);
2099 dbus_message_unref(msg);
2100 technology->mesh_dbus_msg = NULL;
2103 static DBusMessage *mesh_commands(DBusConnection *conn,
2104 DBusMessage *msg, void *data)
2106 struct connman_technology *technology = data;
2107 DBusMessageIter iter, value, dict;
2108 const char *cmd = NULL, *ifname = NULL, *parent_ifname = NULL;
2111 DBG("conn %p", conn);
2113 if (technology->type != CONNMAN_SERVICE_TYPE_MESH)
2114 return __connman_error_invalid_arguments(msg);
2116 if (!dbus_message_iter_init(msg, &iter))
2117 return __connman_error_invalid_arguments(msg);
2119 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
2120 return __connman_error_invalid_arguments(msg);
2122 dbus_message_iter_get_basic(&iter, &cmd);
2123 dbus_message_iter_next(&iter);
2125 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
2126 return __connman_error_invalid_arguments(msg);
2128 dbus_message_iter_recurse(&iter, &value);
2130 if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_ARRAY)
2131 return __connman_error_invalid_arguments(msg);
2133 DBG("Mesh Command %s", cmd);
2134 if (g_str_equal(cmd, "MeshInterfaceAdd")) {
2135 dbus_message_iter_recurse(&value, &dict);
2136 const char *bridge_ifname = NULL;
2137 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2138 DBusMessageIter entry, value2;
2142 dbus_message_iter_recurse(&dict, &entry);
2144 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2145 return __connman_error_invalid_arguments(msg);
2147 dbus_message_iter_get_basic(&entry, &key);
2148 dbus_message_iter_next(&entry);
2150 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2151 return __connman_error_invalid_arguments(msg);
2153 dbus_message_iter_recurse(&entry, &value2);
2155 type = dbus_message_iter_get_arg_type(&value2);
2157 if (g_str_equal(key, "Ifname")) {
2158 if (type != DBUS_TYPE_STRING)
2159 return __connman_error_invalid_arguments(msg);
2161 dbus_message_iter_get_basic(&value2, &ifname);
2162 } else if (g_str_equal(key, "ParentIfname")) {
2163 if (type != DBUS_TYPE_STRING)
2164 return __connman_error_invalid_arguments(msg);
2166 dbus_message_iter_get_basic(&value2, &parent_ifname);
2167 } else if (g_str_equal(key, "BridgeIfname")) {
2168 if (type != DBUS_TYPE_STRING)
2169 return __connman_error_invalid_arguments(msg);
2171 dbus_message_iter_get_basic(&value2, &bridge_ifname);
2173 dbus_message_iter_next(&dict);
2175 DBG("Mesh Ifname %s parent %s bridge %s", ifname, parent_ifname,
2176 bridge_ifname ? bridge_ifname : "NULL");
2177 err = __connman_mesh_add_virtual_interface(ifname, parent_ifname,
2181 DBG("Failed to add virtual mesh interface");
2182 return __connman_error_failed(msg, -err);
2185 DBG("Successfully added virtual mesh interface");
2187 dbus_message_ref(msg);
2188 technology->mesh_dbus_msg = msg;
2190 } else if (g_str_equal(cmd, "MeshInterfaceRemove")) {
2191 dbus_message_iter_recurse(&value, &dict);
2192 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2193 DBusMessageIter entry, value2;
2197 dbus_message_iter_recurse(&dict, &entry);
2199 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2200 return __connman_error_invalid_arguments(msg);
2202 dbus_message_iter_get_basic(&entry, &key);
2203 dbus_message_iter_next(&entry);
2205 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2206 return __connman_error_invalid_arguments(msg);
2208 dbus_message_iter_recurse(&entry, &value2);
2210 type = dbus_message_iter_get_arg_type(&value2);
2212 if (g_str_equal(key, "Ifname")) {
2213 if (type != DBUS_TYPE_STRING)
2214 return __connman_error_invalid_arguments(msg);
2216 dbus_message_iter_get_basic(&value2, &ifname);
2218 dbus_message_iter_next(&dict);
2220 DBG("Mesh Ifname %s", ifname);
2221 err = __connman_mesh_remove_virtual_interface(ifname);
2224 DBG("Failed to remove virtual mesh interface");
2225 return __connman_error_failed(msg, -err);
2228 DBG("Successfully removed virtual mesh interface");
2230 dbus_message_ref(msg);
2231 technology->mesh_dbus_msg = msg;
2233 } else if (g_str_equal(cmd, "MeshCreateNetwork")) {
2234 struct connman_mesh *connman_mesh;
2235 const char *name = NULL;
2236 const char *sec_type = NULL;
2237 const char *mesh_ifname = NULL;
2238 char *identifier, *group, *address;
2239 unsigned int freq = 0;
2240 unsigned int ieee80211w = 0;
2243 dbus_message_iter_recurse(&value, &dict);
2244 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2245 DBusMessageIter entry, value2;
2249 dbus_message_iter_recurse(&dict, &entry);
2251 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2252 return __connman_error_invalid_arguments(msg);
2254 dbus_message_iter_get_basic(&entry, &key);
2255 dbus_message_iter_next(&entry);
2257 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2258 return __connman_error_invalid_arguments(msg);
2260 dbus_message_iter_recurse(&entry, &value2);
2262 type = dbus_message_iter_get_arg_type(&value2);
2264 if (g_str_equal(key, "Name")) {
2265 if (type != DBUS_TYPE_STRING)
2266 return __connman_error_invalid_arguments(msg);
2268 dbus_message_iter_get_basic(&value2, &name);
2269 } else if (g_str_equal(key, "Frequency")) {
2270 if (type != DBUS_TYPE_UINT16)
2271 return __connman_error_invalid_arguments(msg);
2273 dbus_message_iter_get_basic(&value2, &freq);
2274 } else if (g_str_equal(key, "Security")) {
2275 if (type != DBUS_TYPE_STRING)
2276 return __connman_error_invalid_arguments(msg);
2278 dbus_message_iter_get_basic(&value2, &sec_type);
2279 } else if (g_str_equal(key, "Pmf")) {
2280 if (type != DBUS_TYPE_UINT16)
2281 return __connman_error_invalid_arguments(msg);
2283 dbus_message_iter_get_basic(&value2, &ieee80211w);
2285 dbus_message_iter_next(&dict);
2288 if (name == NULL || sec_type == NULL || freq == 0)
2289 return __connman_error_invalid_arguments(msg);
2291 DBG("Name %s Frequency %d Security type %s Pmf %u",
2292 name, freq, sec_type, ieee80211w);
2294 if (g_strcmp0(sec_type, "none") != 0 &&
2295 g_strcmp0(sec_type, "sae") != 0) {
2296 DBG("Unsupported security");
2297 return __connman_error_invalid_arguments(msg);
2300 mesh_ifname = connman_mesh_get_interface_name();
2302 if (!connman_mesh_is_interface_created()) {
2303 DBG("Mesh interface doesn't exists");
2304 return __connman_error_invalid_command(msg);
2307 str = g_string_sized_new((strlen(name) * 2) + 24);
2309 for (i = 0; name[i]; i++)
2310 g_string_append_printf(str, "%02x", name[i]);
2312 g_string_append_printf(str, "_mesh");
2314 if (g_strcmp0(sec_type, "none") == 0)
2315 g_string_append_printf(str, "_none");
2316 else if (g_strcmp0(sec_type, "sae") == 0)
2317 g_string_append_printf(str, "_sae");
2319 group = g_string_free(str, FALSE);
2321 identifier = connman_inet_ifaddr(mesh_ifname);
2322 address = connman_inet_ifname2addr(mesh_ifname);
2324 connman_mesh = connman_mesh_create(identifier, group);
2325 connman_mesh_set_name(connman_mesh, name);
2326 connman_mesh_set_address(connman_mesh, address);
2327 connman_mesh_set_security(connman_mesh, sec_type);
2328 connman_mesh_set_frequency(connman_mesh, freq);
2329 connman_mesh_set_index(connman_mesh, connman_inet_ifindex(mesh_ifname));
2330 connman_mesh_set_peer_type(connman_mesh,
2331 CONNMAN_MESH_PEER_TYPE_CREATED);
2332 connman_mesh_set_ieee80211w(connman_mesh, ieee80211w);
2334 connman_mesh_register(connman_mesh);
2338 DBG("Successfully Created Mesh Network");
2339 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2341 } else if (g_str_equal(cmd, "AbortScan")) {
2342 DBG("Abort Scan method");
2343 err = __connman_device_abort_scan(technology->type);
2345 DBG("Failed to abort scan");
2346 return __connman_error_failed(msg, -err);
2349 DBG("Successfully requested to abort scan");
2350 dbus_message_ref(msg);
2351 technology->mesh_dbus_msg = msg;
2353 } else if (g_str_equal(cmd, "MeshSpecificScan")) {
2354 const char *name = NULL;
2355 unsigned int freq = 0;
2356 dbus_message_iter_recurse(&value, &dict);
2357 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2358 DBusMessageIter entry, value2;
2362 dbus_message_iter_recurse(&dict, &entry);
2364 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2365 return __connman_error_invalid_arguments(msg);
2367 dbus_message_iter_get_basic(&entry, &key);
2368 dbus_message_iter_next(&entry);
2370 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2371 return __connman_error_invalid_arguments(msg);
2373 dbus_message_iter_recurse(&entry, &value2);
2375 type = dbus_message_iter_get_arg_type(&value2);
2377 if (g_str_equal(key, "Name")) {
2378 if (type != DBUS_TYPE_STRING)
2379 return __connman_error_invalid_arguments(msg);
2381 dbus_message_iter_get_basic(&value2, &name);
2382 } else if (g_str_equal(key, "Frequency")) {
2383 if (type != DBUS_TYPE_UINT16)
2384 return __connman_error_invalid_arguments(msg);
2386 dbus_message_iter_get_basic(&value2, &freq);
2388 dbus_message_iter_next(&dict);
2391 DBG("MeshID %s Frequency %d sender %s", name, freq,
2392 dbus_message_get_sender(msg));
2394 struct connman_scan_pending *pending_data =
2395 g_try_malloc0(sizeof(struct connman_scan_pending));
2397 return __connman_error_failed(msg, ENOMEM);
2399 pending_data->msg = dbus_message_ref(msg);
2401 technology->scan_pending =
2402 g_slist_prepend(technology->scan_pending, pending_data);
2404 err = __connman_device_request_mesh_specific_scan(technology->type,
2407 reply_scan_pending(technology, err);
2409 DBG("Successfully requested to scan specific Mesh Network");
2411 } else if (g_str_equal(cmd, "SetMeshGate")) {
2412 unsigned int hwmp_rootmode = 0;
2413 bool gate_announce = false;
2414 unsigned int stp = 0;
2416 dbus_message_iter_recurse(&value, &dict);
2417 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2418 DBusMessageIter entry, value2;
2422 dbus_message_iter_recurse(&dict, &entry);
2424 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2425 return __connman_error_invalid_arguments(msg);
2427 dbus_message_iter_get_basic(&entry, &key);
2428 dbus_message_iter_next(&entry);
2430 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2431 return __connman_error_invalid_arguments(msg);
2433 dbus_message_iter_recurse(&entry, &value2);
2435 type = dbus_message_iter_get_arg_type(&value2);
2437 if (g_str_equal(key, "GateAnnounce")) {
2438 if (type != DBUS_TYPE_BOOLEAN)
2439 return __connman_error_invalid_arguments(msg);
2441 dbus_message_iter_get_basic(&value2, &gate_announce);
2442 } else if (g_str_equal(key, "HWMPRootMode")) {
2443 if (type != DBUS_TYPE_UINT16)
2444 return __connman_error_invalid_arguments(msg);
2446 dbus_message_iter_get_basic(&value2, &hwmp_rootmode);
2447 } else if (g_str_equal(key, "STP")) {
2448 if (type != DBUS_TYPE_UINT16)
2449 return __connman_error_invalid_arguments(msg);
2451 dbus_message_iter_get_basic(&value2, &stp);
2453 dbus_message_iter_next(&dict);
2456 DBG("GateAnnounce %d HWMPRootMode %d STP %d sender %s",
2457 gate_announce, hwmp_rootmode, stp, dbus_message_get_sender(msg));
2459 err = __connman_mesh_set_stp_gate_announce(gate_announce,
2464 return __connman_error_failed(msg, -err);
2466 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2468 return __connman_error_invalid_command(msg);
2473 static const GDBusMethodTable technology_methods[] = {
2474 { GDBUS_DEPRECATED_METHOD("GetProperties",
2475 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
2477 { GDBUS_ASYNC_METHOD("SetProperty",
2478 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
2479 NULL, set_property) },
2480 { GDBUS_ASYNC_METHOD("Scan", NULL, NULL, scan) },
2481 #if defined TIZEN_EXT
2482 { GDBUS_ASYNC_METHOD("ScanDevice", GDBUS_ARGS({ "interface_name", "s" }),
2483 NULL, scan_device) },
2484 { GDBUS_ASYNC_METHOD("SpecificScan", GDBUS_ARGS({ "specificscan", "a{sv}" }),
2485 NULL, specific_scan) },
2486 { GDBUS_METHOD("GetScanState", NULL, GDBUS_ARGS({ "scan_state", "a{sv}" }),
2488 { GDBUS_METHOD("Get5GhzSupported", NULL, GDBUS_ARGS({ "supported", "a{sv}" }),
2489 get_5ghz_supported) },
2490 { GDBUS_METHOD("GetMaxScanSsid", NULL, GDBUS_ARGS({ "maxscanssid", "a{sv}" }),
2491 get_max_scan_ssid) },
2492 { GDBUS_ASYNC_METHOD("SetDevicePower",
2493 GDBUS_ARGS({ "ifname", "s" }, { "value", "b" }),
2494 NULL, set_device_power) },
2495 { GDBUS_ASYNC_METHOD("SetBSSID",
2496 GDBUS_ARGS({ "ifname", "s" }, { "bssid", "s" }),
2499 #if defined TIZEN_EXT_WIFI_MESH
2500 { GDBUS_ASYNC_METHOD("MeshCommands",
2501 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
2502 NULL, mesh_commands) },
2507 static const GDBusSignalTable technology_signals[] = {
2508 { GDBUS_SIGNAL("PropertyChanged",
2509 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
2510 #if defined TIZEN_EXT
2511 { GDBUS_SIGNAL("DeviceChanged",
2512 GDBUS_ARGS({ "device_property", "a{sv}" })) },
2513 { GDBUS_SIGNAL("DeviceDetected",
2514 GDBUS_ARGS({ "ifname", "s" }, { "detected", "b" })) },
2519 static bool technology_dbus_register(struct connman_technology *technology)
2521 if (technology->dbus_registered ||
2522 (technology->rfkill_driven &&
2523 technology->hardblocked))
2526 if (!g_dbus_register_interface(connection, technology->path,
2527 CONNMAN_TECHNOLOGY_INTERFACE,
2528 technology_methods, technology_signals,
2529 NULL, technology, NULL)) {
2530 connman_error("Failed to register %s", technology->path);
2534 technology_added_signal(technology);
2535 technology->dbus_registered = true;
2540 static void technology_dbus_unregister(struct connman_technology *technology)
2542 if (!technology->dbus_registered)
2545 technology_removed_signal(technology);
2546 g_dbus_unregister_interface(connection, technology->path,
2547 CONNMAN_TECHNOLOGY_INTERFACE);
2549 technology->dbus_registered = false;
2552 static void technology_put(struct connman_technology *technology)
2554 DBG("technology %p", technology);
2556 if (__sync_sub_and_fetch(&technology->refcount, 1) > 0)
2559 reply_scan_pending(technology, -EINTR);
2561 while (technology->driver_list) {
2562 struct connman_technology_driver *driver;
2564 driver = technology->driver_list->data;
2567 driver->remove(technology);
2569 technology->driver_list =
2570 g_slist_delete_link(technology->driver_list,
2571 technology->driver_list);
2574 technology_list = g_slist_remove(technology_list, technology);
2576 technology_dbus_unregister(technology);
2578 g_slist_free(technology->device_list);
2580 if (technology->pending_reply) {
2581 dbus_message_unref(technology->pending_reply);
2582 technology->pending_reply = NULL;
2583 g_source_remove(technology->pending_timeout);
2584 technology->pending_timeout = 0;
2587 g_strfreev(technology->enabled_devices);
2589 g_free(technology->path);
2590 g_free(technology->regdom);
2591 g_free(technology->tethering_ident);
2592 g_free(technology->tethering_passphrase);
2596 static struct connman_technology *technology_get(enum connman_service_type type)
2598 GSList *tech_drivers = NULL;
2599 struct connman_technology_driver *driver;
2600 struct connman_technology *technology;
2604 DBG("type %d", type);
2606 str = __connman_service_type2string(type);
2610 technology = technology_find(type);
2612 #if defined TIZEN_EXT_WIFI_MESH
2613 if (type != CONNMAN_SERVICE_TYPE_P2P &&
2614 type != CONNMAN_SERVICE_TYPE_MESH)
2616 if (type != CONNMAN_SERVICE_TYPE_P2P)
2618 __sync_fetch_and_add(&technology->refcount, 1);
2622 /* First check if we have a driver for this technology type */
2623 for (list = driver_list; list; list = list->next) {
2624 driver = list->data;
2626 if (driver->type == type) {
2627 DBG("technology %p driver %p", technology, driver);
2628 tech_drivers = g_slist_append(tech_drivers, driver);
2632 if (!tech_drivers) {
2633 DBG("No matching drivers found for %s.",
2634 __connman_service_type2string(type));
2638 technology = g_try_new0(struct connman_technology, 1);
2642 technology->refcount = 1;
2643 technology->type = type;
2644 technology->path = g_strdup_printf("%s/technology/%s",
2647 #if defined TIZEN_EXT_WIFI_MESH
2648 if (type == CONNMAN_SERVICE_TYPE_MESH) {
2649 struct connman_technology *wifi;
2651 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
2653 technology->enabled = wifi->enabled;
2657 technology_load(technology);
2658 technology_list = g_slist_prepend(technology_list, technology);
2659 technology->driver_list = tech_drivers;
2661 for (list = tech_drivers; list; list = list->next) {
2662 driver = list->data;
2664 if (driver->probe && driver->probe(technology) < 0)
2665 DBG("Driver probe failed for technology %p",
2669 if (!technology_dbus_register(technology)) {
2670 technology_put(technology);
2674 if (type == CONNMAN_SERVICE_TYPE_P2P) {
2675 struct connman_technology *wifi;
2678 enable = technology->enable_persistent;
2680 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
2682 enable = wifi->enabled;
2684 technology_affect_devices(technology, enable);
2687 DBG("technology %p %s", technology, get_name(technology->type));
2692 int connman_technology_driver_register(struct connman_technology_driver *driver)
2695 struct connman_device *device;
2696 enum connman_service_type type;
2698 for (list = driver_list; list; list = list->next) {
2699 if (list->data == driver)
2703 DBG("Registering %s driver", driver->name);
2705 driver_list = g_slist_insert_sorted(driver_list, driver,
2709 * Check for technology less devices if this driver
2710 * can service any of them.
2712 for (list = techless_device_list; list; list = list->next) {
2713 device = list->data;
2715 type = __connman_device_get_service_type(device);
2716 if (type != driver->type)
2719 techless_device_list = g_slist_remove(techless_device_list,
2722 __connman_technology_add_device(device);
2725 /* Check for orphaned rfkill switches. */
2726 g_hash_table_foreach(rfkill_list, rfkill_check,
2727 GINT_TO_POINTER(driver->type));
2730 if (driver->type == CONNMAN_SERVICE_TYPE_P2P) {
2731 if (!technology_get(CONNMAN_SERVICE_TYPE_P2P))
2735 #if defined TIZEN_EXT_WIFI_MESH
2736 if (driver->type == CONNMAN_SERVICE_TYPE_MESH) {
2737 if (!technology_get(CONNMAN_SERVICE_TYPE_MESH))
2745 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
2747 GSList *list, *tech_drivers;
2748 struct connman_technology *technology;
2749 struct connman_technology_driver *current;
2751 DBG("Unregistering driver %p name %s", driver, driver->name);
2753 for (list = technology_list; list; list = list->next) {
2754 technology = list->data;
2756 for (tech_drivers = technology->driver_list; tech_drivers;
2757 tech_drivers = g_slist_next(tech_drivers)) {
2758 current = tech_drivers->data;
2759 if (driver != current)
2763 driver->remove(technology);
2765 technology->driver_list =
2766 g_slist_remove(technology->driver_list,
2772 driver_list = g_slist_remove(driver_list, driver);
2774 if (driver->type == CONNMAN_SERVICE_TYPE_P2P) {
2775 technology = technology_find(CONNMAN_SERVICE_TYPE_P2P);
2777 technology_put(technology);
2779 #if defined TIZEN_EXT_WIFI_MESH
2780 if (driver->type == CONNMAN_SERVICE_TYPE_MESH) {
2781 technology = technology_find(CONNMAN_SERVICE_TYPE_MESH);
2783 technology_put(technology);
2788 void __connman_technology_add_interface(enum connman_service_type type,
2789 int index, const char *ident)
2791 struct connman_technology *technology;
2792 GSList *tech_drivers;
2793 struct connman_technology_driver *driver;
2797 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2798 case CONNMAN_SERVICE_TYPE_SYSTEM:
2800 case CONNMAN_SERVICE_TYPE_ETHERNET:
2801 case CONNMAN_SERVICE_TYPE_WIFI:
2802 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2803 case CONNMAN_SERVICE_TYPE_CELLULAR:
2804 case CONNMAN_SERVICE_TYPE_GPS:
2805 case CONNMAN_SERVICE_TYPE_VPN:
2806 case CONNMAN_SERVICE_TYPE_GADGET:
2807 case CONNMAN_SERVICE_TYPE_P2P:
2808 #if defined TIZEN_EXT_WIFI_MESH
2809 case CONNMAN_SERVICE_TYPE_MESH:
2814 name = connman_inet_ifname(index);
2815 connman_info("Adding interface %s [ %s ]", name,
2816 __connman_service_type2string(type));
2818 technology = technology_find(type);
2823 for (tech_drivers = technology->driver_list; tech_drivers;
2824 tech_drivers = g_slist_next(tech_drivers)) {
2825 driver = tech_drivers->data;
2827 if (driver->add_interface)
2828 driver->add_interface(technology, index, name, ident);
2832 * At this point we can try to enable tethering automatically as
2833 * now the interfaces are set properly.
2835 if (technology->tethering_persistent)
2836 enable_tethering(technology);
2842 void __connman_technology_remove_interface(enum connman_service_type type,
2843 int index, const char *ident)
2845 struct connman_technology *technology;
2846 GSList *tech_drivers;
2847 struct connman_technology_driver *driver;
2851 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2852 case CONNMAN_SERVICE_TYPE_SYSTEM:
2854 case CONNMAN_SERVICE_TYPE_ETHERNET:
2855 case CONNMAN_SERVICE_TYPE_WIFI:
2856 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2857 case CONNMAN_SERVICE_TYPE_CELLULAR:
2858 case CONNMAN_SERVICE_TYPE_GPS:
2859 case CONNMAN_SERVICE_TYPE_VPN:
2860 case CONNMAN_SERVICE_TYPE_GADGET:
2861 case CONNMAN_SERVICE_TYPE_P2P:
2862 #if defined TIZEN_EXT_WIFI_MESH
2863 case CONNMAN_SERVICE_TYPE_MESH:
2868 name = connman_inet_ifname(index);
2869 connman_info("Remove interface %s [ %s ]", name,
2870 __connman_service_type2string(type));
2873 technology = technology_find(type);
2878 for (tech_drivers = technology->driver_list; tech_drivers;
2879 tech_drivers = g_slist_next(tech_drivers)) {
2880 driver = tech_drivers->data;
2882 if (driver->remove_interface)
2883 driver->remove_interface(technology, index);
2887 int __connman_technology_add_device(struct connman_device *device)
2889 struct connman_technology *technology;
2890 enum connman_service_type type;
2892 type = __connman_device_get_service_type(device);
2894 DBG("device %p type %s", device, get_name(type));
2896 technology = technology_get(type);
2899 * Since no driver can be found for this device at the moment we
2900 * add it to the techless device list.
2902 techless_device_list = g_slist_prepend(techless_device_list,
2908 __sync_synchronize();
2909 if (technology->rfkill_driven) {
2910 if (technology->enabled)
2911 __connman_device_enable(device);
2913 __connman_device_disable(device);
2918 if (technology->enable_persistent &&
2919 !global_offlinemode) {
2920 #if defined TIZEN_EXT
2923 if (technology->enabled_devices) {
2926 const char *ifname = connman_device_get_string(device, "Interface");
2928 while (technology->enabled_devices[i]) {
2929 if (g_strcmp0(technology->enabled_devices[i], ifname) == 0) {
2938 err = __connman_device_enable(device);
2940 int err = __connman_device_enable(device);
2943 * connman_technology_add_device() calls __connman_device_enable()
2944 * but since the device is already enabled, the call does not
2945 * propagate through to connman_technology_enabled via
2946 * connman_device_set_powered.
2948 if (err == -EALREADY)
2949 __connman_technology_enabled(type);
2951 /* if technology persistent state is offline */
2952 if (!technology->enable_persistent)
2953 __connman_device_disable(device);
2956 technology->device_list = g_slist_prepend(technology->device_list,
2959 #if defined TIZEN_EXT
2960 const char *ifname = connman_device_get_string(device, "Interface");
2961 __connman_technology_notify_device_detected(technology, ifname, true);
2966 int __connman_technology_remove_device(struct connman_device *device)
2968 struct connman_technology *technology;
2969 enum connman_service_type type;
2971 DBG("device %p", device);
2973 type = __connman_device_get_service_type(device);
2975 technology = technology_find(type);
2977 techless_device_list = g_slist_remove(techless_device_list,
2982 technology->device_list = g_slist_remove(technology->device_list,
2985 #if defined TIZEN_EXT
2986 const char *ifname = connman_device_get_string(device, "Interface");
2987 __connman_technology_notify_device_detected(technology, ifname, false);
2990 if (technology->tethering)
2991 set_tethering(technology, false);
2993 technology_put(technology);
2998 int __connman_technology_enabled(enum connman_service_type type)
3000 struct connman_technology *technology;
3002 technology = technology_find(type);
3006 DBG("technology %p type %s rfkill %d enabled %d", technology,
3007 get_name(type), technology->rfkill_driven,
3008 technology->enabled);
3010 #if !defined TIZEN_EXT
3011 if (technology->rfkill_driven) {
3012 if (technology->tethering_persistent)
3013 enable_tethering(technology);
3018 return technology_enabled(technology);
3021 int __connman_technology_disabled(enum connman_service_type type)
3023 struct connman_technology *technology;
3026 technology = technology_find(type);
3030 #if !defined TIZEN_EXT
3031 if (technology->rfkill_driven)
3035 for (list = technology->device_list; list; list = list->next) {
3036 struct connman_device *device = list->data;
3038 if (connman_device_get_powered(device))
3042 return technology_disabled(technology);
3045 int __connman_technology_set_offlinemode(bool offlinemode)
3048 int err = -EINVAL, enabled_tech_count = 0;
3050 if (global_offlinemode == offlinemode)
3053 DBG("offlinemode %s", offlinemode ? "On" : "Off");
3056 * This is a bit tricky. When you set offlinemode, there is no
3057 * way to differentiate between attempting offline mode and
3058 * resuming offlinemode from last saved profile. We need that
3059 * information in rfkill_update, otherwise it falls back on the
3060 * technology's persistent state. Hence we set the offline mode here
3061 * but save it & call the notifier only if it is successful.
3064 global_offlinemode = offlinemode;
3066 /* Traverse technology list, enable/disable each technology. */
3067 for (list = technology_list; list; list = list->next) {
3068 struct connman_technology *technology = list->data;
3071 err = technology_disable(technology);
3073 if (technology->hardblocked)
3076 if (technology->enable_persistent) {
3077 err = technology_enable(technology);
3078 enabled_tech_count++;
3083 if (err == 0 || err == -EINPROGRESS || err == -EALREADY ||
3084 (err == -EINVAL && enabled_tech_count == 0)) {
3085 connman_technology_save_offlinemode();
3086 __connman_notifier_offlinemode(offlinemode);
3088 global_offlinemode = connman_technology_load_offlinemode();
3093 #if defined TIZEN_EXT_WIFI_MESH
3094 static gboolean __add_ethernet_to_bridge(gpointer data)
3097 __connman_mesh_add_ethernet_to_bridge();
3102 void __connman_technology_set_connected(enum connman_service_type type,
3105 struct connman_technology *technology;
3108 technology = technology_find(type);
3112 DBG("technology %p connected %d", technology, connected);
3114 technology->connected = connected;
3116 #if defined TIZEN_EXT_WIFI_MESH
3117 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET && connected)
3118 g_idle_add(__add_ethernet_to_bridge, NULL);
3122 connman_dbus_property_changed_basic(technology->path,
3123 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
3124 DBUS_TYPE_BOOLEAN, &val);
3127 static bool technology_apply_rfkill_change(struct connman_technology *technology,
3132 bool hardblock_changed = false;
3134 GList *start, *list;
3136 DBG("technology %p --> %d/%d vs %d/%d",
3137 technology, softblock, hardblock,
3138 technology->softblocked, technology->hardblocked);
3140 if (technology->hardblocked == hardblock)
3141 goto softblock_change;
3143 if (!(new_rfkill && !hardblock)) {
3144 start = g_hash_table_get_values(rfkill_list);
3146 for (list = start; list; list = list->next) {
3147 struct connman_rfkill *rfkill = list->data;
3149 if (rfkill->type != technology->type)
3152 if (rfkill->hardblock != hardblock)
3160 goto softblock_change;
3162 technology->hardblocked = hardblock;
3163 hardblock_changed = true;
3166 if (!apply && technology->softblocked != softblock)
3170 return technology->hardblocked;
3172 technology->softblocked = softblock;
3174 if (technology->hardblocked ||
3175 technology->softblocked) {
3176 if (technology_disabled(technology) != -EALREADY)
3177 technology_affect_devices(technology, false);
3178 } else if (!technology->hardblocked &&
3179 !technology->softblocked) {
3180 if (technology_enabled(technology) != -EALREADY)
3181 technology_affect_devices(technology, true);
3184 if (hardblock_changed) {
3185 if (technology->hardblocked) {
3186 DBG("%s is switched off.", get_name(technology->type));
3187 technology_dbus_unregister(technology);
3189 DBG("%s is switched on.", get_name(technology->type));
3190 technology_dbus_register(technology);
3192 if (global_offlinemode)
3193 __connman_rfkill_block(technology->type, true);
3197 return technology->hardblocked;
3200 int __connman_technology_add_rfkill(unsigned int index,
3201 enum connman_service_type type,
3205 struct connman_technology *technology;
3206 struct connman_rfkill *rfkill;
3208 DBG("index %u type %d soft %u hard %u", index, type,
3209 softblock, hardblock);
3211 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
3215 rfkill = g_try_new0(struct connman_rfkill, 1);
3219 rfkill->index = index;
3220 rfkill->type = type;
3221 rfkill->softblock = softblock;
3222 rfkill->hardblock = hardblock;
3224 g_hash_table_insert(rfkill_list, GINT_TO_POINTER(index), rfkill);
3227 #if defined TIZEN_EXT
3228 /* Fix Svace Issue [WGID: 1348]. */
3231 technology = technology_get(type);
3232 /* If there is no driver for this type, ignore it. */
3236 technology->rfkill_driven = true;
3238 #if !defined TIZEN_EXT
3239 /* If hardblocked, there is no need to handle softblocked state */
3240 if (technology_apply_rfkill_change(technology,
3241 softblock, hardblock, true))
3245 if (global_offlinemode)
3249 * Depending on softblocked state we unblock/block according to
3250 * offlinemode and persistente state.
3252 if (technology->softblocked &&
3253 technology->enable_persistent)
3254 return __connman_rfkill_block(type, false);
3255 else if (!technology->softblocked &&
3256 !technology->enable_persistent)
3257 return __connman_rfkill_block(type, true);
3262 int __connman_technology_update_rfkill(unsigned int index,
3263 enum connman_service_type type,
3267 struct connman_technology *technology;
3268 struct connman_rfkill *rfkill;
3270 DBG("index %u soft %u hard %u", index, softblock, hardblock);
3272 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
3276 if (rfkill->softblock == softblock &&
3277 rfkill->hardblock == hardblock)
3280 rfkill->softblock = softblock;
3281 rfkill->hardblock = hardblock;
3283 technology = technology_find(type);
3284 /* If there is no driver for this type, ignore it. */
3288 technology_apply_rfkill_change(technology, softblock, hardblock,
3291 if (technology->hardblocked)
3292 DBG("%s hardblocked", get_name(technology->type));
3294 DBG("%s is%s softblocked", get_name(technology->type),
3295 technology->softblocked ? "" : " not");
3300 int __connman_technology_remove_rfkill(unsigned int index,
3301 enum connman_service_type type)
3303 struct connman_technology *technology;
3304 struct connman_rfkill *rfkill;
3306 DBG("index %u", index);
3308 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
3312 g_hash_table_remove(rfkill_list, GINT_TO_POINTER(index));
3314 technology = technology_find(type);
3318 technology_apply_rfkill_change(technology,
3319 technology->softblocked, !technology->hardblocked, false);
3321 technology_put(technology);
3326 int __connman_technology_init(void)
3330 connection = connman_dbus_get_connection();
3332 rfkill_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
3335 global_offlinemode = connman_technology_load_offlinemode();
3337 /* This will create settings file if it is missing */
3338 connman_technology_save_offlinemode();
3343 void __connman_technology_cleanup(void)
3347 while (technology_list) {
3348 struct connman_technology *technology = technology_list->data;
3349 technology_list = g_slist_remove(technology_list, technology);
3350 technology_put(technology);
3353 g_hash_table_destroy(rfkill_list);
3355 dbus_connection_unref(connection);