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
37 static DBusConnection *connection;
39 static GSList *technology_list = NULL;
42 * List of devices with no technology associated with them either because of
43 * no compiled in support or the driver is not yet loaded.
45 static GSList *techless_device_list = NULL;
46 static GHashTable *rfkill_list;
48 static bool global_offlinemode;
51 static connman_scan_type_e g_scan_type = -1;
54 struct connman_rfkill {
56 enum connman_service_type type;
61 struct connman_technology {
63 enum connman_service_type type;
71 bool tethering_persistent; /* Tells the save status, needed
72 * as offline mode might set
75 char *tethering_ident;
76 char *tethering_passphrase;
78 bool enable_persistent; /* Save the tech state */
82 DBusMessage *pending_reply;
83 guint pending_timeout;
91 #if defined TIZEN_EXT_WIFI_MESH
92 DBusMessage *mesh_dbus_msg;
95 bool is_5_0_ghz_supported;
100 static GSList *driver_list = NULL;
102 static int technology_enabled(struct connman_technology *technology);
103 static int technology_disabled(struct connman_technology *technology);
105 static gint compare_priority(gconstpointer a, gconstpointer b)
107 const struct connman_technology_driver *driver1 = a;
108 const struct connman_technology_driver *driver2 = b;
110 return driver2->priority - driver1->priority;
113 static void rfkill_check(gpointer key, gpointer value, gpointer user_data)
115 struct connman_rfkill *rfkill = value;
116 enum connman_service_type type = GPOINTER_TO_INT(user_data);
118 /* Calling _technology_add_rfkill will update the tech. */
119 if (rfkill->type == type)
120 __connman_technology_add_rfkill(rfkill->index, type,
121 rfkill->softblock, rfkill->hardblock);
125 connman_technology_is_tethering_allowed(enum connman_service_type type)
127 static char *allowed_default[] = { "wifi", "bluetooth", "gadget",
129 const char *type_str = __connman_service_type2string(type);
136 allowed = connman_setting_get_string_list("TetheringTechnologies");
138 allowed = allowed_default;
140 for (i = 0; allowed[i]; i++) {
141 if (g_strcmp0(allowed[i], type_str) == 0)
148 static const char *get_name(enum connman_service_type type)
151 case CONNMAN_SERVICE_TYPE_UNKNOWN:
152 case CONNMAN_SERVICE_TYPE_SYSTEM:
153 case CONNMAN_SERVICE_TYPE_GPS:
154 case CONNMAN_SERVICE_TYPE_VPN:
156 case CONNMAN_SERVICE_TYPE_GADGET:
158 case CONNMAN_SERVICE_TYPE_ETHERNET:
160 case CONNMAN_SERVICE_TYPE_WIFI:
162 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
164 case CONNMAN_SERVICE_TYPE_CELLULAR:
166 case CONNMAN_SERVICE_TYPE_P2P:
168 #if defined TIZEN_EXT_WIFI_MESH
169 case CONNMAN_SERVICE_TYPE_MESH:
177 static void technology_save(struct connman_technology *technology)
181 const char *name = get_name(technology->type);
183 DBG("technology %p type %d name %s", technology, technology->type,
188 keyfile = __connman_storage_load_global();
190 keyfile = g_key_file_new();
192 identifier = g_strdup_printf("%s", name);
196 g_key_file_set_boolean(keyfile, identifier, "Enable",
197 technology->enable_persistent);
199 g_key_file_set_boolean(keyfile, identifier, "Tethering",
200 technology->tethering_persistent);
202 if (technology->tethering_ident)
203 g_key_file_set_string(keyfile, identifier,
204 "Tethering.Identifier",
205 technology->tethering_ident);
207 if (technology->tethering_passphrase)
208 g_key_file_set_string(keyfile, identifier,
209 "Tethering.Passphrase",
210 technology->tethering_passphrase);
215 __connman_storage_save_global(keyfile);
217 g_key_file_free(keyfile);
220 static void tethering_changed(struct connman_technology *technology)
222 dbus_bool_t tethering = technology->tethering;
224 connman_dbus_property_changed_basic(technology->path,
225 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
226 DBUS_TYPE_BOOLEAN, &tethering);
228 technology_save(technology);
231 int connman_technology_tethering_notify(struct connman_technology *technology,
236 DBG("technology %p enabled %u", technology, enabled);
238 if (technology->tethering == enabled)
242 err = __connman_tethering_set_enabled();
246 __connman_tethering_set_disabled();
248 technology->tethering = enabled;
249 tethering_changed(technology);
254 static int set_tethering(struct connman_technology *technology,
257 int result = -EOPNOTSUPP;
259 const char *ident, *passphrase, *bridge;
260 GSList *tech_drivers;
262 ident = technology->tethering_ident;
263 passphrase = technology->tethering_passphrase;
265 __sync_synchronize();
266 if (!technology->enabled)
269 bridge = __connman_tethering_get_bridge();
273 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
274 (!ident || !passphrase))
277 for (tech_drivers = technology->driver_list; tech_drivers;
278 tech_drivers = g_slist_next(tech_drivers)) {
279 struct connman_technology_driver *driver = tech_drivers->data;
281 if (!driver || !driver->set_tethering)
284 err = driver->set_tethering(technology, ident, passphrase,
287 if (result == -EINPROGRESS)
290 if (err == -EINPROGRESS || err == 0)
297 void connman_technology_regdom_notify(struct connman_technology *technology,
303 connman_error("Failed to set regulatory domain");
305 DBG("Regulatory domain set to %s", alpha2);
307 g_free(technology->regdom);
308 technology->regdom = g_strdup(alpha2);
311 static int set_regdom_by_device(struct connman_technology *technology,
316 for (list = technology->device_list; list; list = list->next) {
317 struct connman_device *device = list->data;
319 if (connman_device_set_regdom(device, alpha2) != 0)
326 int connman_technology_set_regdom(const char *alpha2)
328 GSList *list, *tech_drivers;
330 for (list = technology_list; list; list = list->next) {
331 struct connman_technology *technology = list->data;
333 if (set_regdom_by_device(technology, alpha2) != 0) {
335 for (tech_drivers = technology->driver_list;
337 tech_drivers = g_slist_next(tech_drivers)) {
339 struct connman_technology_driver *driver =
342 if (driver->set_regdom)
343 driver->set_regdom(technology, alpha2);
351 static struct connman_technology *technology_find(enum connman_service_type type)
355 DBG("type %d", type);
357 for (list = technology_list; list; list = list->next) {
358 struct connman_technology *technology = list->data;
360 if (technology->type == type)
367 enum connman_service_type connman_technology_get_type
368 (struct connman_technology *technology)
371 return CONNMAN_SERVICE_TYPE_UNKNOWN;
373 return technology->type;
376 bool connman_technology_get_wifi_tethering(const char **ssid,
379 struct connman_technology *technology;
386 technology = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
390 if (!technology->tethering)
393 *ssid = technology->tethering_ident;
394 *psk = technology->tethering_passphrase;
399 #if defined TIZEN_EXT
400 void connman_techonology_wifi_set_5ghz_supported(struct connman_technology *wifi_technology,
401 bool is_5_0_ghz_supported)
405 wifi_technology->is_5_0_ghz_supported = is_5_0_ghz_supported;
409 static void free_rfkill(gpointer data)
411 struct connman_rfkill *rfkill = data;
416 static void technology_load(struct connman_technology *technology)
420 GError *error = NULL;
421 bool enable, need_saving = false;
423 DBG("technology %p", technology);
425 keyfile = __connman_storage_load_global();
426 /* Fallback on disabling technology if file not found. */
428 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
429 /* We enable ethernet by default */
430 technology->enable_persistent = true;
432 technology->enable_persistent = false;
436 identifier = g_strdup_printf("%s", get_name(technology->type));
440 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
442 technology->enable_persistent = enable;
444 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
445 technology->enable_persistent = true;
447 technology->enable_persistent = false;
450 g_clear_error(&error);
453 enable = g_key_file_get_boolean(keyfile, identifier,
454 "Tethering", &error);
456 technology->tethering_persistent = enable;
459 g_clear_error(&error);
463 technology_save(technology);
465 technology->tethering_ident = g_key_file_get_string(keyfile,
466 identifier, "Tethering.Identifier", NULL);
468 technology->tethering_passphrase = g_key_file_get_string(keyfile,
469 identifier, "Tethering.Passphrase", NULL);
473 g_key_file_free(keyfile);
476 bool __connman_technology_get_offlinemode(void)
478 return global_offlinemode;
481 static void connman_technology_save_offlinemode(void)
484 GError *error = NULL;
487 keyfile = __connman_storage_load_global();
490 keyfile = g_key_file_new();
491 g_key_file_set_boolean(keyfile, "global",
492 "OfflineMode", global_offlinemode);
494 __connman_storage_save_global(keyfile);
497 offlinemode = g_key_file_get_boolean(keyfile, "global",
498 "OfflineMode", &error);
500 if (error || offlinemode != global_offlinemode) {
501 g_key_file_set_boolean(keyfile, "global",
502 "OfflineMode", global_offlinemode);
504 g_clear_error(&error);
506 __connman_storage_save_global(keyfile);
510 g_key_file_free(keyfile);
513 static bool connman_technology_load_offlinemode(void)
516 GError *error = NULL;
519 /* If there is a error, we enable offlinemode */
520 keyfile = __connman_storage_load_global();
524 offlinemode = g_key_file_get_boolean(keyfile, "global",
525 "OfflineMode", &error);
528 g_clear_error(&error);
531 g_key_file_free(keyfile);
536 static void append_properties(DBusMessageIter *iter,
537 struct connman_technology *technology)
539 DBusMessageIter dict;
543 connman_dbus_dict_open(iter, &dict);
545 str = get_name(technology->type);
547 connman_dbus_dict_append_basic(&dict, "Name",
548 DBUS_TYPE_STRING, &str);
550 str = __connman_service_type2string(technology->type);
552 connman_dbus_dict_append_basic(&dict, "Type",
553 DBUS_TYPE_STRING, &str);
555 __sync_synchronize();
556 val = technology->enabled;
557 connman_dbus_dict_append_basic(&dict, "Powered",
561 val = technology->connected;
562 connman_dbus_dict_append_basic(&dict, "Connected",
566 val = technology->tethering;
567 connman_dbus_dict_append_basic(&dict, "Tethering",
571 if (technology->tethering_ident)
572 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
574 &technology->tethering_ident);
576 if (technology->tethering_passphrase)
577 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
579 &technology->tethering_passphrase);
581 connman_dbus_dict_close(iter, &dict);
584 static void technology_added_signal(struct connman_technology *technology)
587 DBusMessageIter iter;
589 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
590 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
594 dbus_message_iter_init_append(signal, &iter);
595 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
597 append_properties(&iter, technology);
599 dbus_connection_send(connection, signal, NULL);
600 dbus_message_unref(signal);
603 static void technology_removed_signal(struct connman_technology *technology)
605 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
606 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
607 DBUS_TYPE_OBJECT_PATH, &technology->path,
611 static DBusMessage *get_properties(DBusConnection *conn,
612 DBusMessage *message, void *user_data)
614 struct connman_technology *technology = user_data;
616 DBusMessageIter iter;
618 reply = dbus_message_new_method_return(message);
622 dbus_message_iter_init_append(reply, &iter);
623 append_properties(&iter, technology);
628 void __connman_technology_list_struct(DBusMessageIter *array)
631 DBusMessageIter entry;
633 for (list = technology_list; list; list = list->next) {
634 struct connman_technology *technology = list->data;
636 if (!technology->path ||
637 (technology->rfkill_driven &&
638 technology->hardblocked))
641 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
643 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
645 append_properties(&entry, technology);
646 dbus_message_iter_close_container(array, &entry);
650 static gboolean technology_pending_reply(gpointer user_data)
652 struct connman_technology *technology = user_data;
655 /* Power request timed out, send ETIMEDOUT. */
656 if (technology->pending_reply) {
657 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
659 g_dbus_send_message(connection, reply);
661 dbus_message_unref(technology->pending_reply);
662 technology->pending_reply = NULL;
663 technology->pending_timeout = 0;
669 static int technology_affect_devices(struct connman_technology *technology,
672 int err = 0, err_dev;
675 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
677 __connman_technology_enabled(technology->type);
679 __connman_technology_disabled(technology->type);
683 #if defined TIZEN_EXT_WIFI_MESH
684 if (technology->type == CONNMAN_SERVICE_TYPE_MESH)
688 for (list = technology->device_list; list; list = list->next) {
689 struct connman_device *device = list->data;
692 err_dev = __connman_device_enable(device);
694 err_dev = __connman_device_disable(device);
696 if (err_dev < 0 && err_dev != -EALREADY)
703 static void powered_changed(struct connman_technology *technology)
707 if (!technology->dbus_registered)
710 if (technology->pending_reply) {
711 g_dbus_send_reply(connection,
712 technology->pending_reply, DBUS_TYPE_INVALID);
713 dbus_message_unref(technology->pending_reply);
714 technology->pending_reply = NULL;
716 g_source_remove(technology->pending_timeout);
717 technology->pending_timeout = 0;
720 __sync_synchronize();
721 enabled = technology->enabled;
722 #if defined TIZEN_EXT
723 DBG("ConnMan, Powered : %s, %s",
724 enabled ? "TRUE" : "FALSE",technology->path);
726 connman_dbus_property_changed_basic(technology->path,
727 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
728 DBUS_TYPE_BOOLEAN, &enabled);
731 static void enable_tethering(struct connman_technology *technology)
735 if (!connman_setting_get_bool("PersistentTetheringMode"))
738 ret = set_tethering(technology, true);
739 if (ret < 0 && ret != -EALREADY)
740 DBG("Cannot enable tethering yet for %s (%d/%s)",
741 get_name(technology->type),
742 -ret, strerror(-ret));
745 static int technology_enabled(struct connman_technology *technology)
747 __sync_synchronize();
748 if (technology->enabled)
751 technology->enabled = true;
753 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
754 struct connman_technology *p2p;
756 p2p = technology_find(CONNMAN_SERVICE_TYPE_P2P);
757 if (p2p && !p2p->enabled && p2p->enable_persistent)
758 technology_enabled(p2p);
761 if (technology->tethering_persistent)
762 enable_tethering(technology);
764 powered_changed(technology);
769 static int technology_enable(struct connman_technology *technology)
774 DBG("technology %p enable", technology);
776 __sync_synchronize();
778 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
779 struct connman_technology *wifi;
781 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
782 if (wifi && wifi->enabled)
783 return technology_enabled(technology);
787 if (technology->enabled)
790 if (technology->pending_reply)
793 if (connman_setting_get_bool("PersistentTetheringMode") &&
794 technology->tethering)
795 set_tethering(technology, true);
797 if (technology->rfkill_driven)
798 err = __connman_rfkill_block(technology->type, false);
800 err_dev = technology_affect_devices(technology, true);
802 if (!technology->rfkill_driven)
808 static int technology_disabled(struct connman_technology *technology)
810 __sync_synchronize();
811 if (!technology->enabled)
814 technology->enabled = false;
816 powered_changed(technology);
821 static int technology_disable(struct connman_technology *technology)
825 DBG("technology %p disable", technology);
827 __sync_synchronize();
829 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
830 technology->enable_persistent = false;
831 __connman_device_stop_scan(CONNMAN_SERVICE_TYPE_P2P);
832 __connman_peer_disconnect_all();
833 return technology_disabled(technology);
834 } else if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
835 struct connman_technology *p2p;
837 p2p = technology_find(CONNMAN_SERVICE_TYPE_P2P);
838 if (p2p && p2p->enabled) {
839 p2p->enable_persistent = true;
840 technology_disabled(p2p);
844 if (!technology->enabled)
847 if (technology->pending_reply)
850 if (technology->tethering)
851 set_tethering(technology, false);
853 err = technology_affect_devices(technology, false);
855 if (technology->rfkill_driven)
856 err = __connman_rfkill_block(technology->type, true);
861 static DBusMessage *set_powered(struct connman_technology *technology,
862 DBusMessage *msg, bool powered)
864 DBusMessage *reply = NULL;
867 if (technology->rfkill_driven && technology->hardblocked) {
873 err = technology_enable(technology);
875 err = technology_disable(technology);
878 technology->enable_persistent = powered;
879 technology_save(technology);
883 if (err == -EINPROGRESS) {
884 technology->pending_reply = dbus_message_ref(msg);
885 technology->pending_timeout = g_timeout_add_seconds(10,
886 technology_pending_reply, technology);
887 } else if (err == -EALREADY) {
889 reply = __connman_error_already_enabled(msg);
891 reply = __connman_error_already_disabled(msg);
893 reply = __connman_error_failed(msg, -err);
895 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
900 #if defined TIZEN_EXT
901 int set_connman_bssid(enum bssid_type mode, char *bssid)
903 static unsigned char bssid_for_connect[6];
904 static int bssid_len;
906 DBG("mode : %d", mode);
908 if (mode == CHECK_BSSID) {
912 if (mode == GET_BSSID && bssid) {
913 memcpy(bssid, bssid_for_connect, 6);
917 if (mode == RESET_BSSID) {
922 if (mode != SET_BSSID || !bssid) {
923 DBG("Invalid parameter");
927 bssid_len = sscanf(bssid, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
928 &bssid_for_connect[0], &bssid_for_connect[1], &bssid_for_connect[2],
929 &bssid_for_connect[3], &bssid_for_connect[4], &bssid_for_connect[5]);
930 if (bssid_len != 6) {
931 DBG("Incorrect BSSID format. bssid_len = %d", bssid_len);
935 DBG("SET BSSID len : %d, BSSID : %02x:%02x:%02x:%02x:%02x:%02x", bssid_len,
936 bssid_for_connect[0], bssid_for_connect[1], bssid_for_connect[2],
937 bssid_for_connect[3], bssid_for_connect[4], bssid_for_connect[5]);
943 static DBusMessage *set_property(DBusConnection *conn,
944 DBusMessage *msg, void *data)
946 struct connman_technology *technology = data;
947 DBusMessageIter iter, value;
951 DBG("conn %p", conn);
953 if (!dbus_message_iter_init(msg, &iter))
954 return __connman_error_invalid_arguments(msg);
956 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
957 return __connman_error_invalid_arguments(msg);
959 dbus_message_iter_get_basic(&iter, &name);
960 dbus_message_iter_next(&iter);
962 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
963 return __connman_error_invalid_arguments(msg);
965 dbus_message_iter_recurse(&iter, &value);
967 type = dbus_message_iter_get_arg_type(&value);
969 DBG("property %s", name);
971 if (g_str_equal(name, "Tethering")) {
972 dbus_bool_t tethering;
975 if (type != DBUS_TYPE_BOOLEAN)
976 return __connman_error_invalid_arguments(msg);
978 if (!connman_technology_is_tethering_allowed(technology->type)) {
979 DBG("%s tethering not allowed by config file",
980 __connman_service_type2string(technology->type));
981 return __connman_error_not_supported(msg);
984 dbus_message_iter_get_basic(&value, &tethering);
986 if (technology->tethering == tethering) {
988 return __connman_error_already_disabled(msg);
990 return __connman_error_already_enabled(msg);
993 err = set_tethering(technology, tethering);
995 return __connman_error_failed(msg, -err);
997 technology->tethering_persistent = tethering;
999 technology_save(technology);
1001 } else if (g_str_equal(name, "TetheringIdentifier")) {
1004 dbus_message_iter_get_basic(&value, &str);
1006 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1007 return __connman_error_not_supported(msg);
1009 if (strlen(str) < 1 || strlen(str) > 32)
1010 return __connman_error_invalid_arguments(msg);
1012 if (g_strcmp0(technology->tethering_ident, str) != 0) {
1013 g_free(technology->tethering_ident);
1014 technology->tethering_ident = g_strdup(str);
1015 technology_save(technology);
1017 connman_dbus_property_changed_basic(technology->path,
1018 CONNMAN_TECHNOLOGY_INTERFACE,
1019 "TetheringIdentifier",
1021 &technology->tethering_ident);
1023 } else if (g_str_equal(name, "TetheringPassphrase")) {
1026 dbus_message_iter_get_basic(&value, &str);
1028 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1029 return __connman_error_not_supported(msg);
1031 err = __connman_service_check_passphrase(CONNMAN_SERVICE_SECURITY_PSK,
1034 return __connman_error_passphrase_required(msg);
1036 if (g_strcmp0(technology->tethering_passphrase, str) != 0) {
1037 g_free(technology->tethering_passphrase);
1038 technology->tethering_passphrase = g_strdup(str);
1039 technology_save(technology);
1041 connman_dbus_property_changed_basic(technology->path,
1042 CONNMAN_TECHNOLOGY_INTERFACE,
1043 "TetheringPassphrase",
1045 &technology->tethering_passphrase);
1047 } else if (g_str_equal(name, "Powered")) {
1050 if (type != DBUS_TYPE_BOOLEAN)
1051 return __connman_error_invalid_arguments(msg);
1053 dbus_message_iter_get_basic(&value, &enable);
1055 return set_powered(technology, msg, enable);
1056 #if defined TIZEN_EXT
1057 } else if (g_str_equal(name, "SetBSSID")) {
1060 if (type != DBUS_TYPE_STRING)
1061 return __connman_error_invalid_arguments(msg);
1063 dbus_message_iter_get_basic(&value, &key);
1064 DBG("BSSID %s", key);
1065 set_connman_bssid(SET_BSSID, key);
1068 return __connman_error_invalid_property(msg);
1070 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1073 static void reply_scan_pending(struct connman_technology *technology, int err)
1077 DBG("technology %p err %d", technology, err);
1079 while (technology->scan_pending) {
1080 DBusMessage *msg = technology->scan_pending->data;
1082 DBG("reply to %s", dbus_message_get_sender(msg));
1085 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1087 reply = __connman_error_failed(msg, -err);
1088 g_dbus_send_message(connection, reply);
1089 dbus_message_unref(msg);
1091 technology->scan_pending =
1092 g_slist_delete_link(technology->scan_pending,
1093 technology->scan_pending);
1097 #if defined TIZEN_EXT
1098 dbus_bool_t __connman_technology_notify_scan_changed(const char *key, void *val)
1101 DBusMessage *signal;
1102 DBusMessageIter iter;
1103 dbus_bool_t result = FALSE;
1105 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
1106 CONNMAN_MANAGER_INTERFACE, "ScanChanged");
1110 dbus_message_iter_init_append(signal, &iter);
1111 connman_dbus_property_append_basic(&iter, key, DBUS_TYPE_BOOLEAN, val);
1113 result = dbus_connection_send(connection, signal, NULL);
1114 dbus_message_unref(signal);
1116 DBG("Successfuly sent signal");
1121 void __connman_technology_notify_scan_done(int val)
1124 DBusMessage *signal;
1125 DBusMessageIter iter;
1127 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
1128 CONNMAN_MANAGER_INTERFACE, "ScanDone");
1132 dbus_message_iter_init_append(signal, &iter);
1133 connman_dbus_property_append_basic(&iter, "Scantype",
1134 DBUS_TYPE_INT32, &val);
1136 dbus_connection_send(connection, signal, NULL);
1137 dbus_message_unref(signal);
1139 DBG("Successfuly sent signal");
1143 void __connman_technology_scan_started(struct connman_device *device)
1145 DBG("device %p", device);
1146 #if defined TIZEN_EXT
1147 dbus_bool_t status = 1;
1148 __connman_technology_notify_scan_changed("scan_started", &status);
1152 void __connman_technology_scan_stopped(struct connman_device *device,
1153 enum connman_service_type type)
1156 struct connman_technology *technology;
1159 technology = technology_find(type);
1161 DBG("technology %p device %p", technology, device);
1166 for (list = technology->device_list; list; list = list->next) {
1167 struct connman_device *other_device = list->data;
1169 if (device == other_device)
1172 if (connman_device_get_scanning(other_device, type))
1176 #if defined TIZEN_EXT
1178 dbus_bool_t status = 0;
1180 __connman_technology_notify_scan_changed("scan_done", &status);
1181 __connman_technology_notify_scan_done((int)g_scan_type);
1182 reply_scan_pending(technology, 0);
1184 DBG("Successfuly sent ScanDone signal");
1188 reply_scan_pending(technology, 0);
1192 void __connman_technology_notify_regdom_by_device(struct connman_device *device,
1193 int result, const char *alpha2)
1195 bool regdom_set = false;
1196 struct connman_technology *technology;
1197 enum connman_service_type type;
1198 GSList *tech_drivers;
1200 type = __connman_device_get_service_type(device);
1201 technology = technology_find(type);
1208 for (tech_drivers = technology->driver_list;
1210 tech_drivers = g_slist_next(tech_drivers)) {
1211 struct connman_technology_driver *driver =
1214 if (driver->set_regdom) {
1215 driver->set_regdom(technology, alpha2);
1225 connman_technology_regdom_notify(technology, alpha2);
1228 static DBusMessage *scan(DBusConnection *conn, DBusMessage *msg, void *data)
1230 struct connman_technology *technology = data;
1233 DBG("technology %p request from %s", technology,
1234 dbus_message_get_sender(msg));
1236 if (technology->type == CONNMAN_SERVICE_TYPE_P2P &&
1237 !technology->enabled)
1238 return __connman_error_permission_denied(msg);
1240 dbus_message_ref(msg);
1241 #if !defined TIZEN_EXT
1242 technology->scan_pending =
1243 g_slist_prepend(technology->scan_pending, msg);
1246 err = __connman_device_request_scan_full(technology->type);
1248 #if defined TIZEN_EXT
1249 return __connman_error_failed(msg, -err);
1251 reply_scan_pending(technology, err);
1254 #if defined TIZEN_EXT
1256 g_scan_type = CONNMAN_SCAN_TYPE_FULL_CHANNEL;
1257 DBG("g_scan_type %d", g_scan_type);
1259 technology->scan_pending =
1260 g_slist_prepend(technology->scan_pending, msg);
1265 #if defined TIZEN_EXT
1266 static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void *data)
1268 struct connman_technology *technology = data;
1269 GSList *specific_scan_list = NULL;
1271 const char *name = NULL;
1272 const char *freq = NULL;
1273 DBusMessageIter iter, dict;
1276 DBG("technology %p request from %s", technology,
1277 dbus_message_get_sender(msg));
1279 if (!dbus_message_iter_init(msg, &iter))
1280 return __connman_error_invalid_arguments(msg);
1282 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
1283 return __connman_error_invalid_arguments(msg);
1285 dbus_message_iter_recurse(&iter, &dict);
1286 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1287 DBusMessageIter entry, value2;
1291 dbus_message_iter_recurse(&dict, &entry);
1292 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) {
1293 g_slist_free_full(specific_scan_list, g_free);
1294 return __connman_error_invalid_arguments(msg);
1297 dbus_message_iter_get_basic(&entry, &key);
1298 dbus_message_iter_next(&entry);
1300 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) {
1301 g_slist_free_full(specific_scan_list, g_free);
1302 return __connman_error_invalid_arguments(msg);
1305 dbus_message_iter_recurse(&entry, &value2);
1306 type = dbus_message_iter_get_arg_type(&value2);
1307 if (g_str_equal(key, "SSID")) {
1308 if (type != DBUS_TYPE_STRING) {
1309 g_slist_free_full(specific_scan_list, g_free);
1310 return __connman_error_invalid_arguments(msg);
1313 scan_type = CONNMAN_MULTI_SCAN_SSID; /* SSID based scan */
1314 dbus_message_iter_get_basic(&value2, &name);
1315 DBG("name %s", name);
1316 specific_scan_list = g_slist_append(specific_scan_list, g_strdup(name));
1317 } else if (g_str_equal(key, "Frequency")) {
1318 if (type != DBUS_TYPE_STRING) {
1319 g_slist_free_full(specific_scan_list, g_free);
1320 return __connman_error_invalid_arguments(msg);
1323 scan_type = CONNMAN_MULTI_SCAN_FREQ; /* Frequency based scan */
1324 dbus_message_iter_get_basic(&value2, &freq);
1325 DBG("freq %s", freq);
1326 specific_scan_list = g_slist_append(specific_scan_list, GINT_TO_POINTER(atoi(freq)));
1327 } else if (g_str_equal(key, "SSID_Mixed")) {
1328 if (type != DBUS_TYPE_STRING) {
1329 g_slist_free_full(specific_scan_list, g_free);
1330 return __connman_error_invalid_arguments(msg);
1333 scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */
1334 dbus_message_iter_get_basic(&value2, &name);
1336 connman_multi_scan_ap_s *ap = (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s));
1338 g_strlcpy(ap->str, name, strlen(name) + 1);
1340 specific_scan_list = g_slist_append(specific_scan_list, ap);
1342 DBG("Failed to allocate memory");
1344 } else if (g_str_equal(key, "Frequency_Mixed")) {
1345 if (type != DBUS_TYPE_STRING) {
1346 g_slist_free_full(specific_scan_list, g_free);
1347 return __connman_error_invalid_arguments(msg);
1350 scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */
1351 dbus_message_iter_get_basic(&value2, &freq);
1353 connman_multi_scan_ap_s *ap = (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s));
1355 g_strlcpy(ap->str, freq, strlen(freq) + 1);
1357 specific_scan_list = g_slist_append(specific_scan_list, ap);
1359 DBG("Failed to allocate memory");
1361 dbus_message_iter_next(&dict);
1364 dbus_message_ref(msg);
1366 err = __connman_device_request_specific_scan(technology->type, scan_type, specific_scan_list);
1368 return __connman_error_failed(msg, -err);
1371 guint list_size = g_slist_length(specific_scan_list);
1373 g_scan_type = CONNMAN_SCAN_TYPE_SPECIFIC_AP;
1375 g_scan_type = CONNMAN_SCAN_TYPE_MULTI_AP;
1376 DBG("list_size %u g_scan_type %d", list_size, g_scan_type);
1378 technology->scan_pending =
1379 g_slist_prepend(technology->scan_pending, msg);
1381 if (scan_type == CONNMAN_MULTI_SCAN_SSID ||
1382 scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) {
1383 g_slist_free_full(specific_scan_list, g_free);
1389 #if defined TIZEN_EXT
1390 static DBusMessage *get_5ghz_supported(DBusConnection *conn, DBusMessage *msg, void *data)
1393 DBusMessageIter iter, dict;
1394 struct connman_technology *technology = data;
1395 dbus_bool_t supported = technology->is_5_0_ghz_supported;
1397 DBG("technology %p", technology);
1399 reply = dbus_message_new_method_return(msg);
1403 dbus_message_iter_init_append(reply, &iter);
1405 connman_dbus_dict_open(&iter, &dict);
1406 connman_dbus_dict_append_basic(&dict, "Is5GhzSupported",
1410 connman_dbus_dict_close(&iter, &dict);
1416 static DBusMessage *get_scan_state(DBusConnection *conn, DBusMessage *msg, void *data)
1419 DBusMessageIter iter, dict;
1421 struct connman_technology *technology = data;
1422 dbus_bool_t scanning = false;
1424 DBG("technology %p", technology);
1426 for (list = technology->device_list; list; list = list->next) {
1427 struct connman_device *device = list->data;
1428 scanning = connman_device_get_scanning(device,
1429 connman_device_get_type(device));
1434 DBG("scanning : %d", scanning);
1435 reply = dbus_message_new_method_return(msg);
1439 dbus_message_iter_init_append(reply, &iter);
1441 connman_dbus_dict_open(&iter, &dict);
1442 connman_dbus_dict_append_basic(&dict, "Scanstate",
1446 connman_dbus_dict_close(&iter, &dict);
1451 void connman_techonology_set_max_scan_ssids(struct connman_technology *technology,
1455 technology->max_scan_ssids = max_scan_ssids;
1458 static DBusMessage *get_max_scan_ssid(DBusConnection *conn, DBusMessage *msg, void *data)
1461 DBusMessageIter iter, dict;
1462 struct connman_technology *technology = data;
1463 dbus_int32_t max_scan_ssids = technology->max_scan_ssids;
1465 DBG("technology %p", technology);
1467 reply = dbus_message_new_method_return(msg);
1471 dbus_message_iter_init_append(reply, &iter);
1473 connman_dbus_dict_open(&iter, &dict);
1474 connman_dbus_dict_append_basic(&dict, "MaxScanSSID",
1478 connman_dbus_dict_close(&iter, &dict);
1484 #if defined TIZEN_EXT_WIFI_MESH
1485 bool __connman_technology_get_connected(enum connman_service_type type)
1487 struct connman_technology *technology;
1489 technology = technology_find(type);
1494 return technology->connected;
1497 void __connman_technology_mesh_interface_create_finished(
1498 enum connman_service_type type, bool success,
1502 struct connman_technology *technology;
1504 technology = technology_find(type);
1506 DBG("technology %p success %d", technology, success);
1511 msg = technology->mesh_dbus_msg;
1513 DBG("No pending dbus message");
1518 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1519 __connman_device_request_scan(technology->type);
1521 reply = g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
1522 ".MeshInterfaceAddFailed", "%s", error);
1523 g_dbus_send_message(connection, reply);
1524 dbus_message_unref(msg);
1525 technology->mesh_dbus_msg = NULL;
1528 void __connman_technology_mesh_interface_remove_finished(
1529 enum connman_service_type type, bool success)
1532 struct connman_technology *technology;
1534 technology = technology_find(type);
1536 DBG("technology %p success %d", technology, success);
1538 if (!technology || !technology->mesh_dbus_msg)
1541 msg = technology->mesh_dbus_msg;
1543 DBG("No pending dbus message");
1548 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1550 reply = __connman_error_failed(msg, EINVAL);
1551 g_dbus_send_message(connection, reply);
1552 dbus_message_unref(msg);
1553 technology->mesh_dbus_msg = NULL;
1556 void __connman_technology_notify_abort_scan(enum connman_service_type type,
1560 struct connman_technology *technology;
1562 technology = technology_find(type);
1564 DBG("technology %p result %d", technology, result);
1566 if (!technology || !technology->mesh_dbus_msg)
1569 msg = technology->mesh_dbus_msg;
1571 DBG("No pending dbus message");
1576 reply = __connman_error_scan_abort_failed(msg);
1578 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1580 g_dbus_send_message(connection, reply);
1581 dbus_message_unref(msg);
1582 technology->mesh_dbus_msg = NULL;
1585 static DBusMessage *mesh_commands(DBusConnection *conn,
1586 DBusMessage *msg, void *data)
1588 struct connman_technology *technology = data;
1589 DBusMessageIter iter, value, dict;
1590 const char *cmd = NULL, *ifname = NULL, *parent_ifname = NULL;
1593 DBG("conn %p", conn);
1595 if (technology->type != CONNMAN_SERVICE_TYPE_MESH)
1596 return __connman_error_invalid_arguments(msg);
1598 if (!dbus_message_iter_init(msg, &iter))
1599 return __connman_error_invalid_arguments(msg);
1601 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1602 return __connman_error_invalid_arguments(msg);
1604 dbus_message_iter_get_basic(&iter, &cmd);
1605 dbus_message_iter_next(&iter);
1607 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
1608 return __connman_error_invalid_arguments(msg);
1610 dbus_message_iter_recurse(&iter, &value);
1612 if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_ARRAY)
1613 return __connman_error_invalid_arguments(msg);
1615 DBG("Mesh Command %s", cmd);
1616 if (g_str_equal(cmd, "MeshInterfaceAdd")) {
1617 dbus_message_iter_recurse(&value, &dict);
1618 const char *bridge_ifname = NULL;
1619 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1620 DBusMessageIter entry, value2;
1624 dbus_message_iter_recurse(&dict, &entry);
1626 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1627 return __connman_error_invalid_arguments(msg);
1629 dbus_message_iter_get_basic(&entry, &key);
1630 dbus_message_iter_next(&entry);
1632 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
1633 return __connman_error_invalid_arguments(msg);
1635 dbus_message_iter_recurse(&entry, &value2);
1637 type = dbus_message_iter_get_arg_type(&value2);
1639 if (g_str_equal(key, "Ifname")) {
1640 if (type != DBUS_TYPE_STRING)
1641 return __connman_error_invalid_arguments(msg);
1643 dbus_message_iter_get_basic(&value2, &ifname);
1644 } else if (g_str_equal(key, "ParentIfname")) {
1645 if (type != DBUS_TYPE_STRING)
1646 return __connman_error_invalid_arguments(msg);
1648 dbus_message_iter_get_basic(&value2, &parent_ifname);
1649 } else if (g_str_equal(key, "BridgeIfname")) {
1650 if (type != DBUS_TYPE_STRING)
1651 return __connman_error_invalid_arguments(msg);
1653 dbus_message_iter_get_basic(&value2, &bridge_ifname);
1655 dbus_message_iter_next(&dict);
1657 DBG("Mesh Ifname %s parent %s bridge %s", ifname, parent_ifname,
1658 bridge_ifname ? bridge_ifname : "NULL");
1659 err = __connman_mesh_add_virtual_interface(ifname, parent_ifname,
1663 DBG("Failed to add virtual mesh interface");
1664 return __connman_error_failed(msg, -err);
1667 DBG("Successfully added virtual mesh interface");
1669 dbus_message_ref(msg);
1670 technology->mesh_dbus_msg = msg;
1672 } else if (g_str_equal(cmd, "MeshInterfaceRemove")) {
1673 dbus_message_iter_recurse(&value, &dict);
1674 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1675 DBusMessageIter entry, value2;
1679 dbus_message_iter_recurse(&dict, &entry);
1681 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1682 return __connman_error_invalid_arguments(msg);
1684 dbus_message_iter_get_basic(&entry, &key);
1685 dbus_message_iter_next(&entry);
1687 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
1688 return __connman_error_invalid_arguments(msg);
1690 dbus_message_iter_recurse(&entry, &value2);
1692 type = dbus_message_iter_get_arg_type(&value2);
1694 if (g_str_equal(key, "Ifname")) {
1695 if (type != DBUS_TYPE_STRING)
1696 return __connman_error_invalid_arguments(msg);
1698 dbus_message_iter_get_basic(&value2, &ifname);
1700 dbus_message_iter_next(&dict);
1702 DBG("Mesh Ifname %s", ifname);
1703 err = __connman_mesh_remove_virtual_interface(ifname);
1706 DBG("Failed to remove virtual mesh interface");
1707 return __connman_error_failed(msg, -err);
1710 DBG("Successfully removed virtual mesh interface");
1712 dbus_message_ref(msg);
1713 technology->mesh_dbus_msg = msg;
1715 } else if (g_str_equal(cmd, "MeshCreateNetwork")) {
1716 struct connman_mesh *connman_mesh;
1717 const char *name = NULL;
1718 const char *sec_type = NULL;
1719 const char *mesh_ifname = NULL;
1720 char *identifier, *group, *address;
1721 unsigned int freq = 0;
1722 unsigned int ieee80211w = 0;
1725 dbus_message_iter_recurse(&value, &dict);
1726 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1727 DBusMessageIter entry, value2;
1731 dbus_message_iter_recurse(&dict, &entry);
1733 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1734 return __connman_error_invalid_arguments(msg);
1736 dbus_message_iter_get_basic(&entry, &key);
1737 dbus_message_iter_next(&entry);
1739 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
1740 return __connman_error_invalid_arguments(msg);
1742 dbus_message_iter_recurse(&entry, &value2);
1744 type = dbus_message_iter_get_arg_type(&value2);
1746 if (g_str_equal(key, "Name")) {
1747 if (type != DBUS_TYPE_STRING)
1748 return __connman_error_invalid_arguments(msg);
1750 dbus_message_iter_get_basic(&value2, &name);
1751 } else if (g_str_equal(key, "Frequency")) {
1752 if (type != DBUS_TYPE_UINT16)
1753 return __connman_error_invalid_arguments(msg);
1755 dbus_message_iter_get_basic(&value2, &freq);
1756 } else if (g_str_equal(key, "Security")) {
1757 if (type != DBUS_TYPE_STRING)
1758 return __connman_error_invalid_arguments(msg);
1760 dbus_message_iter_get_basic(&value2, &sec_type);
1761 } else if (g_str_equal(key, "Pmf")) {
1762 if (type != DBUS_TYPE_UINT16)
1763 return __connman_error_invalid_arguments(msg);
1765 dbus_message_iter_get_basic(&value2, &ieee80211w);
1767 dbus_message_iter_next(&dict);
1770 if (name == NULL || sec_type == NULL || freq == 0)
1771 return __connman_error_invalid_arguments(msg);
1773 DBG("Name %s Frequency %d Security type %s Pmf %u",
1774 name, freq, sec_type, ieee80211w);
1776 if (g_strcmp0(sec_type, "none") != 0 &&
1777 g_strcmp0(sec_type, "sae") != 0) {
1778 DBG("Unsupported security");
1779 return __connman_error_invalid_arguments(msg);
1782 mesh_ifname = connman_mesh_get_interface_name();
1784 if (!connman_mesh_is_interface_created()) {
1785 DBG("Mesh interface doesn't exists");
1786 return __connman_error_invalid_command(msg);
1789 str = g_string_sized_new((strlen(name) * 2) + 24);
1791 for (i = 0; name[i]; i++)
1792 g_string_append_printf(str, "%02x", name[i]);
1794 g_string_append_printf(str, "_mesh");
1796 if (g_strcmp0(sec_type, "none") == 0)
1797 g_string_append_printf(str, "_none");
1798 else if (g_strcmp0(sec_type, "sae") == 0)
1799 g_string_append_printf(str, "_sae");
1801 group = g_string_free(str, FALSE);
1803 identifier = connman_inet_ifaddr(mesh_ifname);
1804 address = connman_inet_ifname2addr(mesh_ifname);
1806 connman_mesh = connman_mesh_create(identifier, group);
1807 connman_mesh_set_name(connman_mesh, name);
1808 connman_mesh_set_address(connman_mesh, address);
1809 connman_mesh_set_security(connman_mesh, sec_type);
1810 connman_mesh_set_frequency(connman_mesh, freq);
1811 connman_mesh_set_index(connman_mesh, connman_inet_ifindex(mesh_ifname));
1812 connman_mesh_set_peer_type(connman_mesh,
1813 CONNMAN_MESH_PEER_TYPE_CREATED);
1814 connman_mesh_set_ieee80211w(connman_mesh, ieee80211w);
1816 connman_mesh_register(connman_mesh);
1820 DBG("Successfully Created Mesh Network");
1821 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1823 } else if (g_str_equal(cmd, "AbortScan")) {
1824 DBG("Abort Scan method");
1825 err = __connman_device_abort_scan(technology->type);
1827 DBG("Failed to abort scan");
1828 return __connman_error_failed(msg, -err);
1831 DBG("Successfully requested to abort scan");
1832 dbus_message_ref(msg);
1833 technology->mesh_dbus_msg = msg;
1835 } else if (g_str_equal(cmd, "MeshSpecificScan")) {
1836 const char *name = NULL;
1837 unsigned int freq = 0;
1838 dbus_message_iter_recurse(&value, &dict);
1839 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1840 DBusMessageIter entry, value2;
1844 dbus_message_iter_recurse(&dict, &entry);
1846 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1847 return __connman_error_invalid_arguments(msg);
1849 dbus_message_iter_get_basic(&entry, &key);
1850 dbus_message_iter_next(&entry);
1852 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
1853 return __connman_error_invalid_arguments(msg);
1855 dbus_message_iter_recurse(&entry, &value2);
1857 type = dbus_message_iter_get_arg_type(&value2);
1859 if (g_str_equal(key, "Name")) {
1860 if (type != DBUS_TYPE_STRING)
1861 return __connman_error_invalid_arguments(msg);
1863 dbus_message_iter_get_basic(&value2, &name);
1864 } else if (g_str_equal(key, "Frequency")) {
1865 if (type != DBUS_TYPE_UINT16)
1866 return __connman_error_invalid_arguments(msg);
1868 dbus_message_iter_get_basic(&value2, &freq);
1870 dbus_message_iter_next(&dict);
1873 DBG("MeshID %s Frequency %d sender %s", name, freq,
1874 dbus_message_get_sender(msg));
1876 dbus_message_ref(msg);
1877 technology->scan_pending =
1878 g_slist_prepend(technology->scan_pending, msg);
1880 err = __connman_device_request_mesh_specific_scan(technology->type,
1883 reply_scan_pending(technology, err);
1885 DBG("Successfully requested to scan specific Mesh Network");
1887 } else if (g_str_equal(cmd, "SetMeshGate")) {
1888 unsigned int hwmp_rootmode = 0;
1889 bool gate_announce = false;
1890 unsigned int stp = 0;
1892 dbus_message_iter_recurse(&value, &dict);
1893 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1894 DBusMessageIter entry, value2;
1898 dbus_message_iter_recurse(&dict, &entry);
1900 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1901 return __connman_error_invalid_arguments(msg);
1903 dbus_message_iter_get_basic(&entry, &key);
1904 dbus_message_iter_next(&entry);
1906 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
1907 return __connman_error_invalid_arguments(msg);
1909 dbus_message_iter_recurse(&entry, &value2);
1911 type = dbus_message_iter_get_arg_type(&value2);
1913 if (g_str_equal(key, "GateAnnounce")) {
1914 if (type != DBUS_TYPE_BOOLEAN)
1915 return __connman_error_invalid_arguments(msg);
1917 dbus_message_iter_get_basic(&value2, &gate_announce);
1918 } else if (g_str_equal(key, "HWMPRootMode")) {
1919 if (type != DBUS_TYPE_UINT16)
1920 return __connman_error_invalid_arguments(msg);
1922 dbus_message_iter_get_basic(&value2, &hwmp_rootmode);
1923 } else if (g_str_equal(key, "STP")) {
1924 if (type != DBUS_TYPE_UINT16)
1925 return __connman_error_invalid_arguments(msg);
1927 dbus_message_iter_get_basic(&value2, &stp);
1929 dbus_message_iter_next(&dict);
1932 DBG("GateAnnounce %d HWMPRootMode %d STP %d sender %s",
1933 gate_announce, hwmp_rootmode, stp, dbus_message_get_sender(msg));
1935 err = __connman_mesh_set_stp_gate_announce(gate_announce,
1940 return __connman_error_failed(msg, -err);
1942 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1944 return __connman_error_invalid_command(msg);
1949 static const GDBusMethodTable technology_methods[] = {
1950 { GDBUS_DEPRECATED_METHOD("GetProperties",
1951 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
1953 { GDBUS_ASYNC_METHOD("SetProperty",
1954 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
1955 NULL, set_property) },
1956 { GDBUS_ASYNC_METHOD("Scan", NULL, NULL, scan) },
1957 #if defined TIZEN_EXT
1958 { GDBUS_ASYNC_METHOD("SpecificScan", GDBUS_ARGS({ "specificscan", "a{sv}" }),
1959 NULL, specific_scan) },
1960 { GDBUS_METHOD("GetScanState", NULL, GDBUS_ARGS({ "scan_state", "a{sv}" }),
1962 { GDBUS_METHOD("Get5GhzSupported", NULL, GDBUS_ARGS({ "supported", "a{sv}" }),
1963 get_5ghz_supported) },
1964 { GDBUS_METHOD("GetMaxScanSsid", NULL, GDBUS_ARGS({ "maxscanssid", "a{sv}" }),
1965 get_max_scan_ssid) },
1967 #if defined TIZEN_EXT_WIFI_MESH
1968 { GDBUS_ASYNC_METHOD("MeshCommands",
1969 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
1970 NULL, mesh_commands) },
1975 static const GDBusSignalTable technology_signals[] = {
1976 { GDBUS_SIGNAL("PropertyChanged",
1977 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
1981 static bool technology_dbus_register(struct connman_technology *technology)
1983 if (technology->dbus_registered ||
1984 (technology->rfkill_driven &&
1985 technology->hardblocked))
1988 if (!g_dbus_register_interface(connection, technology->path,
1989 CONNMAN_TECHNOLOGY_INTERFACE,
1990 technology_methods, technology_signals,
1991 NULL, technology, NULL)) {
1992 connman_error("Failed to register %s", technology->path);
1996 technology_added_signal(technology);
1997 technology->dbus_registered = true;
2002 static void technology_dbus_unregister(struct connman_technology *technology)
2004 if (!technology->dbus_registered)
2007 technology_removed_signal(technology);
2008 g_dbus_unregister_interface(connection, technology->path,
2009 CONNMAN_TECHNOLOGY_INTERFACE);
2011 technology->dbus_registered = false;
2014 static void technology_put(struct connman_technology *technology)
2016 DBG("technology %p", technology);
2018 if (__sync_sub_and_fetch(&technology->refcount, 1) > 0)
2021 reply_scan_pending(technology, -EINTR);
2023 while (technology->driver_list) {
2024 struct connman_technology_driver *driver;
2026 driver = technology->driver_list->data;
2029 driver->remove(technology);
2031 technology->driver_list =
2032 g_slist_delete_link(technology->driver_list,
2033 technology->driver_list);
2036 technology_list = g_slist_remove(technology_list, technology);
2038 technology_dbus_unregister(technology);
2040 g_slist_free(technology->device_list);
2042 if (technology->pending_reply) {
2043 dbus_message_unref(technology->pending_reply);
2044 technology->pending_reply = NULL;
2045 g_source_remove(technology->pending_timeout);
2046 technology->pending_timeout = 0;
2049 g_free(technology->path);
2050 g_free(technology->regdom);
2051 g_free(technology->tethering_ident);
2052 g_free(technology->tethering_passphrase);
2056 static struct connman_technology *technology_get(enum connman_service_type type)
2058 GSList *tech_drivers = NULL;
2059 struct connman_technology_driver *driver;
2060 struct connman_technology *technology;
2064 DBG("type %d", type);
2066 str = __connman_service_type2string(type);
2070 technology = technology_find(type);
2072 #if defined TIZEN_EXT_WIFI_MESH
2073 if (type != CONNMAN_SERVICE_TYPE_P2P &&
2074 type != CONNMAN_SERVICE_TYPE_MESH)
2076 if (type != CONNMAN_SERVICE_TYPE_P2P)
2078 __sync_fetch_and_add(&technology->refcount, 1);
2082 /* First check if we have a driver for this technology type */
2083 for (list = driver_list; list; list = list->next) {
2084 driver = list->data;
2086 if (driver->type == type) {
2087 DBG("technology %p driver %p", technology, driver);
2088 tech_drivers = g_slist_append(tech_drivers, driver);
2092 if (!tech_drivers) {
2093 DBG("No matching drivers found for %s.",
2094 __connman_service_type2string(type));
2098 technology = g_try_new0(struct connman_technology, 1);
2102 technology->refcount = 1;
2103 technology->type = type;
2104 technology->path = g_strdup_printf("%s/technology/%s",
2107 #if defined TIZEN_EXT_WIFI_MESH
2108 if (type == CONNMAN_SERVICE_TYPE_MESH) {
2109 struct connman_technology *wifi;
2111 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
2113 technology->enabled = wifi->enabled;
2117 technology_load(technology);
2118 technology_list = g_slist_prepend(technology_list, technology);
2119 technology->driver_list = tech_drivers;
2121 for (list = tech_drivers; list; list = list->next) {
2122 driver = list->data;
2124 if (driver->probe && driver->probe(technology) < 0)
2125 DBG("Driver probe failed for technology %p",
2129 if (!technology_dbus_register(technology)) {
2130 technology_put(technology);
2134 if (type == CONNMAN_SERVICE_TYPE_P2P) {
2135 struct connman_technology *wifi;
2138 enable = technology->enable_persistent;
2140 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
2142 enable = wifi->enabled;
2144 technology_affect_devices(technology, enable);
2147 DBG("technology %p %s", technology, get_name(technology->type));
2152 int connman_technology_driver_register(struct connman_technology_driver *driver)
2155 struct connman_device *device;
2156 enum connman_service_type type;
2158 for (list = driver_list; list; list = list->next) {
2159 if (list->data == driver)
2163 DBG("Registering %s driver", driver->name);
2165 driver_list = g_slist_insert_sorted(driver_list, driver,
2169 * Check for technology less devices if this driver
2170 * can service any of them.
2172 for (list = techless_device_list; list; list = list->next) {
2173 device = list->data;
2175 type = __connman_device_get_service_type(device);
2176 if (type != driver->type)
2179 techless_device_list = g_slist_remove(techless_device_list,
2182 __connman_technology_add_device(device);
2185 /* Check for orphaned rfkill switches. */
2186 g_hash_table_foreach(rfkill_list, rfkill_check,
2187 GINT_TO_POINTER(driver->type));
2190 if (driver->type == CONNMAN_SERVICE_TYPE_P2P) {
2191 if (!technology_get(CONNMAN_SERVICE_TYPE_P2P))
2195 #if defined TIZEN_EXT_WIFI_MESH
2196 if (driver->type == CONNMAN_SERVICE_TYPE_MESH) {
2197 if (!technology_get(CONNMAN_SERVICE_TYPE_MESH))
2205 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
2207 GSList *list, *tech_drivers;
2208 struct connman_technology *technology;
2209 struct connman_technology_driver *current;
2211 DBG("Unregistering driver %p name %s", driver, driver->name);
2213 for (list = technology_list; list; list = list->next) {
2214 technology = list->data;
2216 for (tech_drivers = technology->driver_list; tech_drivers;
2217 tech_drivers = g_slist_next(tech_drivers)) {
2218 current = tech_drivers->data;
2219 if (driver != current)
2223 driver->remove(technology);
2225 technology->driver_list =
2226 g_slist_remove(technology->driver_list,
2232 driver_list = g_slist_remove(driver_list, driver);
2234 if (driver->type == CONNMAN_SERVICE_TYPE_P2P) {
2235 technology = technology_find(CONNMAN_SERVICE_TYPE_P2P);
2237 technology_put(technology);
2239 #if defined TIZEN_EXT_WIFI_MESH
2240 if (driver->type == CONNMAN_SERVICE_TYPE_MESH) {
2241 technology = technology_find(CONNMAN_SERVICE_TYPE_MESH);
2243 technology_put(technology);
2248 void __connman_technology_add_interface(enum connman_service_type type,
2249 int index, const char *ident)
2251 struct connman_technology *technology;
2252 GSList *tech_drivers;
2253 struct connman_technology_driver *driver;
2257 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2258 case CONNMAN_SERVICE_TYPE_SYSTEM:
2260 case CONNMAN_SERVICE_TYPE_ETHERNET:
2261 case CONNMAN_SERVICE_TYPE_WIFI:
2262 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2263 case CONNMAN_SERVICE_TYPE_CELLULAR:
2264 case CONNMAN_SERVICE_TYPE_GPS:
2265 case CONNMAN_SERVICE_TYPE_VPN:
2266 case CONNMAN_SERVICE_TYPE_GADGET:
2267 case CONNMAN_SERVICE_TYPE_P2P:
2268 #if defined TIZEN_EXT_WIFI_MESH
2269 case CONNMAN_SERVICE_TYPE_MESH:
2274 name = connman_inet_ifname(index);
2275 connman_info("Adding interface %s [ %s ]", name,
2276 __connman_service_type2string(type));
2278 technology = technology_find(type);
2283 for (tech_drivers = technology->driver_list; tech_drivers;
2284 tech_drivers = g_slist_next(tech_drivers)) {
2285 driver = tech_drivers->data;
2287 if (driver->add_interface)
2288 driver->add_interface(technology, index, name, ident);
2292 * At this point we can try to enable tethering automatically as
2293 * now the interfaces are set properly.
2295 if (technology->tethering_persistent)
2296 enable_tethering(technology);
2302 void __connman_technology_remove_interface(enum connman_service_type type,
2303 int index, const char *ident)
2305 struct connman_technology *technology;
2306 GSList *tech_drivers;
2307 struct connman_technology_driver *driver;
2311 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2312 case CONNMAN_SERVICE_TYPE_SYSTEM:
2314 case CONNMAN_SERVICE_TYPE_ETHERNET:
2315 case CONNMAN_SERVICE_TYPE_WIFI:
2316 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2317 case CONNMAN_SERVICE_TYPE_CELLULAR:
2318 case CONNMAN_SERVICE_TYPE_GPS:
2319 case CONNMAN_SERVICE_TYPE_VPN:
2320 case CONNMAN_SERVICE_TYPE_GADGET:
2321 case CONNMAN_SERVICE_TYPE_P2P:
2322 #if defined TIZEN_EXT_WIFI_MESH
2323 case CONNMAN_SERVICE_TYPE_MESH:
2328 name = connman_inet_ifname(index);
2329 connman_info("Remove interface %s [ %s ]", name,
2330 __connman_service_type2string(type));
2333 technology = technology_find(type);
2338 for (tech_drivers = technology->driver_list; tech_drivers;
2339 tech_drivers = g_slist_next(tech_drivers)) {
2340 driver = tech_drivers->data;
2342 if (driver->remove_interface)
2343 driver->remove_interface(technology, index);
2347 int __connman_technology_add_device(struct connman_device *device)
2349 struct connman_technology *technology;
2350 enum connman_service_type type;
2352 type = __connman_device_get_service_type(device);
2354 DBG("device %p type %s", device, get_name(type));
2356 technology = technology_get(type);
2359 * Since no driver can be found for this device at the moment we
2360 * add it to the techless device list.
2362 techless_device_list = g_slist_prepend(techless_device_list,
2368 __sync_synchronize();
2369 if (technology->rfkill_driven) {
2370 if (technology->enabled)
2371 __connman_device_enable(device);
2373 __connman_device_disable(device);
2378 if (technology->enable_persistent &&
2379 !global_offlinemode) {
2380 int err = __connman_device_enable(device);
2382 * connman_technology_add_device() calls __connman_device_enable()
2383 * but since the device is already enabled, the call does not
2384 * propagate through to connman_technology_enabled via
2385 * connman_device_set_powered.
2387 if (err == -EALREADY)
2388 __connman_technology_enabled(type);
2390 /* if technology persistent state is offline */
2391 if (!technology->enable_persistent)
2392 __connman_device_disable(device);
2395 technology->device_list = g_slist_prepend(technology->device_list,
2401 int __connman_technology_remove_device(struct connman_device *device)
2403 struct connman_technology *technology;
2404 enum connman_service_type type;
2406 DBG("device %p", device);
2408 type = __connman_device_get_service_type(device);
2410 technology = technology_find(type);
2412 techless_device_list = g_slist_remove(techless_device_list,
2417 technology->device_list = g_slist_remove(technology->device_list,
2420 if (technology->tethering)
2421 set_tethering(technology, false);
2423 technology_put(technology);
2428 int __connman_technology_enabled(enum connman_service_type type)
2430 struct connman_technology *technology;
2432 technology = technology_find(type);
2436 DBG("technology %p type %s rfkill %d enabled %d", technology,
2437 get_name(type), technology->rfkill_driven,
2438 technology->enabled);
2440 #if !defined TIZEN_EXT
2441 if (technology->rfkill_driven) {
2442 if (technology->tethering_persistent)
2443 enable_tethering(technology);
2448 return technology_enabled(technology);
2451 int __connman_technology_disabled(enum connman_service_type type)
2453 struct connman_technology *technology;
2456 technology = technology_find(type);
2460 #if !defined TIZEN_EXT
2461 if (technology->rfkill_driven)
2465 for (list = technology->device_list; list; list = list->next) {
2466 struct connman_device *device = list->data;
2468 if (connman_device_get_powered(device))
2472 return technology_disabled(technology);
2475 int __connman_technology_set_offlinemode(bool offlinemode)
2478 int err = -EINVAL, enabled_tech_count = 0;
2480 if (global_offlinemode == offlinemode)
2483 DBG("offlinemode %s", offlinemode ? "On" : "Off");
2486 * This is a bit tricky. When you set offlinemode, there is no
2487 * way to differentiate between attempting offline mode and
2488 * resuming offlinemode from last saved profile. We need that
2489 * information in rfkill_update, otherwise it falls back on the
2490 * technology's persistent state. Hence we set the offline mode here
2491 * but save it & call the notifier only if it is successful.
2494 global_offlinemode = offlinemode;
2496 /* Traverse technology list, enable/disable each technology. */
2497 for (list = technology_list; list; list = list->next) {
2498 struct connman_technology *technology = list->data;
2501 err = technology_disable(technology);
2503 if (technology->hardblocked)
2506 if (technology->enable_persistent) {
2507 err = technology_enable(technology);
2508 enabled_tech_count++;
2513 if (err == 0 || err == -EINPROGRESS || err == -EALREADY ||
2514 (err == -EINVAL && enabled_tech_count == 0)) {
2515 connman_technology_save_offlinemode();
2516 __connman_notifier_offlinemode(offlinemode);
2518 global_offlinemode = connman_technology_load_offlinemode();
2523 #if defined TIZEN_EXT_WIFI_MESH
2524 static gboolean __add_ethernet_to_bridge(gpointer data)
2527 __connman_mesh_add_ethernet_to_bridge();
2532 void __connman_technology_set_connected(enum connman_service_type type,
2535 struct connman_technology *technology;
2538 technology = technology_find(type);
2542 DBG("technology %p connected %d", technology, connected);
2544 technology->connected = connected;
2546 #if defined TIZEN_EXT_WIFI_MESH
2547 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET && connected)
2548 g_idle_add(__add_ethernet_to_bridge, NULL);
2552 connman_dbus_property_changed_basic(technology->path,
2553 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
2554 DBUS_TYPE_BOOLEAN, &val);
2557 static bool technology_apply_rfkill_change(struct connman_technology *technology,
2562 bool hardblock_changed = false;
2564 GList *start, *list;
2566 DBG("technology %p --> %d/%d vs %d/%d",
2567 technology, softblock, hardblock,
2568 technology->softblocked, technology->hardblocked);
2570 if (technology->hardblocked == hardblock)
2571 goto softblock_change;
2573 if (!(new_rfkill && !hardblock)) {
2574 start = g_hash_table_get_values(rfkill_list);
2576 for (list = start; list; list = list->next) {
2577 struct connman_rfkill *rfkill = list->data;
2579 if (rfkill->type != technology->type)
2582 if (rfkill->hardblock != hardblock)
2590 goto softblock_change;
2592 technology->hardblocked = hardblock;
2593 hardblock_changed = true;
2596 if (!apply && technology->softblocked != softblock)
2600 return technology->hardblocked;
2602 technology->softblocked = softblock;
2604 if (technology->hardblocked ||
2605 technology->softblocked) {
2606 if (technology_disabled(technology) != -EALREADY)
2607 technology_affect_devices(technology, false);
2608 } else if (!technology->hardblocked &&
2609 !technology->softblocked) {
2610 if (technology_enabled(technology) != -EALREADY)
2611 technology_affect_devices(technology, true);
2614 if (hardblock_changed) {
2615 if (technology->hardblocked) {
2616 DBG("%s is switched off.", get_name(technology->type));
2617 technology_dbus_unregister(technology);
2619 DBG("%s is switched on.", get_name(technology->type));
2620 technology_dbus_register(technology);
2622 if (global_offlinemode)
2623 __connman_rfkill_block(technology->type, true);
2627 return technology->hardblocked;
2630 int __connman_technology_add_rfkill(unsigned int index,
2631 enum connman_service_type type,
2635 struct connman_technology *technology;
2636 struct connman_rfkill *rfkill;
2638 DBG("index %u type %d soft %u hard %u", index, type,
2639 softblock, hardblock);
2641 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
2645 rfkill = g_try_new0(struct connman_rfkill, 1);
2649 rfkill->index = index;
2650 rfkill->type = type;
2651 rfkill->softblock = softblock;
2652 rfkill->hardblock = hardblock;
2654 g_hash_table_insert(rfkill_list, GINT_TO_POINTER(index), rfkill);
2657 #if defined TIZEN_EXT
2658 /* Fix Svace Issue [WGID: 1348]. */
2661 technology = technology_get(type);
2662 /* If there is no driver for this type, ignore it. */
2666 technology->rfkill_driven = true;
2668 #if !defined TIZEN_EXT
2669 /* If hardblocked, there is no need to handle softblocked state */
2670 if (technology_apply_rfkill_change(technology,
2671 softblock, hardblock, true))
2675 if (global_offlinemode)
2679 * Depending on softblocked state we unblock/block according to
2680 * offlinemode and persistente state.
2682 if (technology->softblocked &&
2683 technology->enable_persistent)
2684 return __connman_rfkill_block(type, false);
2685 else if (!technology->softblocked &&
2686 !technology->enable_persistent)
2687 return __connman_rfkill_block(type, true);
2692 int __connman_technology_update_rfkill(unsigned int index,
2693 enum connman_service_type type,
2697 struct connman_technology *technology;
2698 struct connman_rfkill *rfkill;
2700 DBG("index %u soft %u hard %u", index, softblock, hardblock);
2702 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
2706 if (rfkill->softblock == softblock &&
2707 rfkill->hardblock == hardblock)
2710 rfkill->softblock = softblock;
2711 rfkill->hardblock = hardblock;
2713 technology = technology_find(type);
2714 /* If there is no driver for this type, ignore it. */
2718 technology_apply_rfkill_change(technology, softblock, hardblock,
2721 if (technology->hardblocked)
2722 DBG("%s hardblocked", get_name(technology->type));
2724 DBG("%s is%s softblocked", get_name(technology->type),
2725 technology->softblocked ? "" : " not");
2730 int __connman_technology_remove_rfkill(unsigned int index,
2731 enum connman_service_type type)
2733 struct connman_technology *technology;
2734 struct connman_rfkill *rfkill;
2736 DBG("index %u", index);
2738 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
2742 g_hash_table_remove(rfkill_list, GINT_TO_POINTER(index));
2744 technology = technology_find(type);
2748 technology_apply_rfkill_change(technology,
2749 technology->softblocked, !technology->hardblocked, false);
2751 technology_put(technology);
2756 int __connman_technology_init(void)
2760 connection = connman_dbus_get_connection();
2762 rfkill_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2765 global_offlinemode = connman_technology_load_offlinemode();
2767 /* This will create settings file if it is missing */
2768 connman_technology_save_offlinemode();
2773 void __connman_technology_cleanup(void)
2777 while (technology_list) {
2778 struct connman_technology *technology = technology_list->data;
2779 technology_list = g_slist_remove(technology_list, technology);
2780 technology_put(technology);
2783 g_hash_table_destroy(rfkill_list);
2785 dbus_connection_unref(connection);