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;
89 bool enable_persistent; /* Save the tech state */
93 DBusMessage *pending_reply;
94 guint pending_timeout;
101 bool dbus_registered;
102 #if defined TIZEN_EXT
103 char **enabled_devices;
104 unsigned int mac_policy;
105 unsigned int preassoc_mac_policy;
106 unsigned int random_mac_lifetime;
108 #if defined TIZEN_EXT_WIFI_MESH
109 DBusMessage *mesh_dbus_msg;
113 static GSList *driver_list = NULL;
115 static int technology_enabled(struct connman_technology *technology);
116 static int technology_disabled(struct connman_technology *technology);
118 static gint compare_priority(gconstpointer a, gconstpointer b)
120 const struct connman_technology_driver *driver1 = a;
121 const struct connman_technology_driver *driver2 = b;
123 return driver2->priority - driver1->priority;
126 static void rfkill_check(gpointer key, gpointer value, gpointer user_data)
128 struct connman_rfkill *rfkill = value;
129 enum connman_service_type type = GPOINTER_TO_INT(user_data);
131 /* Calling _technology_add_rfkill will update the tech. */
132 if (rfkill->type == type)
133 __connman_technology_add_rfkill(rfkill->index, type,
134 rfkill->softblock, rfkill->hardblock);
138 connman_technology_is_tethering_allowed(enum connman_service_type type)
140 static char *allowed_default[] = { "wifi", "bluetooth", "gadget",
142 const char *type_str = __connman_service_type2string(type);
149 allowed = connman_setting_get_string_list("TetheringTechnologies");
151 allowed = allowed_default;
153 for (i = 0; allowed[i]; i++) {
154 if (g_strcmp0(allowed[i], type_str) == 0)
161 static const char *get_name(enum connman_service_type type)
164 case CONNMAN_SERVICE_TYPE_UNKNOWN:
165 case CONNMAN_SERVICE_TYPE_SYSTEM:
166 case CONNMAN_SERVICE_TYPE_GPS:
167 case CONNMAN_SERVICE_TYPE_VPN:
169 case CONNMAN_SERVICE_TYPE_GADGET:
171 case CONNMAN_SERVICE_TYPE_ETHERNET:
173 case CONNMAN_SERVICE_TYPE_WIFI:
175 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
177 case CONNMAN_SERVICE_TYPE_CELLULAR:
179 case CONNMAN_SERVICE_TYPE_P2P:
181 #if defined TIZEN_EXT_WIFI_MESH
182 case CONNMAN_SERVICE_TYPE_MESH:
190 static void technology_save(struct connman_technology *technology)
194 const char *name = get_name(technology->type);
196 DBG("technology %p type %d name %s", technology, technology->type,
201 keyfile = __connman_storage_load_global();
203 keyfile = g_key_file_new();
205 identifier = g_strdup_printf("%s", name);
209 g_key_file_set_boolean(keyfile, identifier, "Enable",
210 technology->enable_persistent);
212 g_key_file_set_boolean(keyfile, identifier, "Tethering",
213 technology->tethering_persistent);
215 if (technology->tethering_ident)
216 g_key_file_set_string(keyfile, identifier,
217 "Tethering.Identifier",
218 technology->tethering_ident);
220 if (technology->tethering_passphrase) {
221 char *enc = g_strescape(technology->tethering_passphrase, NULL);
222 g_key_file_set_string(keyfile, identifier,
223 "Tethering.Passphrase", enc);
228 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
229 g_key_file_set_uint64(keyfile, identifier, "MacPolicy",
230 technology->mac_policy);
232 g_key_file_set_uint64(keyfile, identifier, "PreassocMacPolicy",
233 technology->preassoc_mac_policy);
235 g_key_file_set_uint64(keyfile, identifier, "RandomMacLifetime",
236 technology->random_mac_lifetime);
238 #endif /* TIZEN_EXT */
239 if (technology->tethering_freq == 0)
240 technology->tethering_freq = 2412;
242 g_key_file_set_integer(keyfile, identifier,
244 technology->tethering_freq);
249 __connman_storage_save_global(keyfile);
251 g_key_file_free(keyfile);
254 static void tethering_changed(struct connman_technology *technology)
256 dbus_bool_t tethering = technology->tethering;
258 connman_dbus_property_changed_basic(technology->path,
259 CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
260 DBUS_TYPE_BOOLEAN, &tethering);
262 technology_save(technology);
265 int connman_technology_tethering_notify(struct connman_technology *technology,
270 DBG("technology %p enabled %u", technology, enabled);
272 if (technology->tethering == enabled)
276 err = __connman_tethering_set_enabled();
280 __connman_tethering_set_disabled();
282 technology->tethering = enabled;
283 tethering_changed(technology);
288 static int set_tethering(struct connman_technology *technology,
291 int result = -EOPNOTSUPP;
293 const char *ident, *passphrase, *bridge;
294 GSList *tech_drivers;
296 ident = technology->tethering_ident;
297 passphrase = technology->tethering_passphrase;
299 __sync_synchronize();
300 if (!technology->enabled)
303 bridge = __connman_tethering_get_bridge();
307 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
308 (!ident || !passphrase))
311 for (tech_drivers = technology->driver_list; tech_drivers;
312 tech_drivers = g_slist_next(tech_drivers)) {
313 struct connman_technology_driver *driver = tech_drivers->data;
315 if (!driver || !driver->set_tethering)
318 err = driver->set_tethering(technology, bridge, enabled);
320 if (result == -EINPROGRESS)
323 if (err == -EINPROGRESS || err == 0)
330 void connman_technology_regdom_notify(struct connman_technology *technology,
336 connman_error("Failed to set regulatory domain");
338 DBG("Regulatory domain set to %s", alpha2);
340 g_free(technology->regdom);
341 technology->regdom = g_strdup(alpha2);
344 static int set_regdom_by_device(struct connman_technology *technology,
349 for (list = technology->device_list; list; list = list->next) {
350 struct connman_device *device = list->data;
352 if (connman_device_set_regdom(device, alpha2) != 0)
359 int connman_technology_set_regdom(const char *alpha2)
361 GSList *list, *tech_drivers;
363 for (list = technology_list; list; list = list->next) {
364 struct connman_technology *technology = list->data;
366 if (set_regdom_by_device(technology, alpha2) != 0) {
368 for (tech_drivers = technology->driver_list;
370 tech_drivers = g_slist_next(tech_drivers)) {
372 struct connman_technology_driver *driver =
375 if (driver->set_regdom)
376 driver->set_regdom(technology, alpha2);
384 static struct connman_technology *technology_find(enum connman_service_type type)
388 DBG("type %d", type);
390 for (list = technology_list; list; list = list->next) {
391 struct connman_technology *technology = list->data;
393 if (technology->type == type)
400 enum connman_service_type connman_technology_get_type
401 (struct connman_technology *technology)
404 return CONNMAN_SERVICE_TYPE_UNKNOWN;
406 return technology->type;
409 bool connman_technology_get_wifi_tethering(const struct connman_technology *technology,
410 const char **ssid, const char **psk,
420 /* Workaround for the neard plugin */
422 technology = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
429 if (!force && !technology->tethering)
432 *ssid = technology->tethering_ident;
433 *psk = technology->tethering_passphrase;
434 *freq = technology->tethering_freq;
439 #if defined TIZEN_EXT
440 const char *connman_techonology_get_path(enum connman_service_type type)
442 struct connman_technology *technology = technology_find(type);
447 return technology->path;
451 static void free_rfkill(gpointer data)
453 struct connman_rfkill *rfkill = data;
458 static void technology_load(struct connman_technology *technology)
462 GError *error = NULL;
463 bool enable, need_saving = false;
470 DBG("technology %p", technology);
472 keyfile = __connman_storage_load_global();
473 /* Fallback on disabling technology if file not found. */
475 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
476 /* We enable ethernet by default */
477 technology->enable_persistent = true;
479 technology->enable_persistent = false;
483 identifier = g_strdup_printf("%s", get_name(technology->type));
489 technology->enabled_devices = g_key_file_get_string_list(keyfile,
490 identifier, "Enable.Devices", &length, NULL);
491 if (technology->enabled_devices && length == 0) {
492 g_strfreev(technology->enabled_devices);
493 technology->enabled_devices = NULL;
497 enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
499 technology->enable_persistent = enable;
501 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
502 technology->enable_persistent = true;
504 technology->enable_persistent = false;
507 g_clear_error(&error);
510 enable = g_key_file_get_boolean(keyfile, identifier,
511 "Tethering", &error);
513 technology->tethering_persistent = enable;
516 g_clear_error(&error);
520 technology_save(technology);
522 technology->tethering_ident = g_key_file_get_string(keyfile,
523 identifier, "Tethering.Identifier", NULL);
525 enc = g_key_file_get_string(keyfile,
526 identifier, "Tethering.Passphrase", NULL);
528 technology->tethering_passphrase = g_strcompress(enc);
530 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
531 unsigned int val = 0;
533 val = g_key_file_get_uint64(keyfile,
534 identifier, "MacPolicy", NULL);
536 technology->mac_policy = val;
538 technology->mac_policy = 0;
540 val = g_key_file_get_uint64(keyfile,
541 identifier, "PreassocMacPolicy", NULL);
543 technology->preassoc_mac_policy = val;
545 technology->preassoc_mac_policy = 0;
547 val = g_key_file_get_uint64(keyfile,
548 identifier, "RandomMacLifetime", NULL);
550 technology->random_mac_lifetime = val;
552 technology->random_mac_lifetime = 60;
554 #endif /* TIZEN_EXT */
556 technology->tethering_freq = g_key_file_get_integer(keyfile,
557 identifier, "Tethering.Freq", NULL);
565 g_key_file_free(keyfile);
568 bool __connman_technology_get_offlinemode(void)
570 return global_offlinemode;
573 static void connman_technology_save_offlinemode(void)
576 GError *error = NULL;
579 keyfile = __connman_storage_load_global();
582 keyfile = g_key_file_new();
583 g_key_file_set_boolean(keyfile, "global",
584 "OfflineMode", global_offlinemode);
586 __connman_storage_save_global(keyfile);
589 offlinemode = g_key_file_get_boolean(keyfile, "global",
590 "OfflineMode", &error);
592 if (error || offlinemode != global_offlinemode) {
593 g_key_file_set_boolean(keyfile, "global",
594 "OfflineMode", global_offlinemode);
596 g_clear_error(&error);
598 __connman_storage_save_global(keyfile);
602 g_key_file_free(keyfile);
605 static bool connman_technology_load_offlinemode(void)
608 GError *error = NULL;
611 /* If there is a error, we enable offlinemode */
612 keyfile = __connman_storage_load_global();
616 offlinemode = g_key_file_get_boolean(keyfile, "global",
617 "OfflineMode", &error);
620 g_clear_error(&error);
623 g_key_file_free(keyfile);
628 #if defined TIZEN_EXT
629 static void append_devices(DBusMessageIter *iter, void *user_data)
633 struct connman_technology *technology = user_data;
635 for (list = technology->device_list; list; list = list->next) {
636 struct connman_device *device = list->data;
638 const char *str = connman_device_get_string(device, "Interface");
639 struct connman_network *network = connman_device_get_default_network(device);
640 struct connman_service *service = connman_service_lookup_from_network(network);
642 connman_dbus_dict_append_basic(iter, "Ifname",
643 DBUS_TYPE_STRING, &str);
645 val = connman_device_get_powered(device);
646 connman_dbus_dict_append_basic(iter, "Powered",
647 DBUS_TYPE_BOOLEAN, &val);
649 if (__connman_service_is_connected_state(service, CONNMAN_IPCONFIG_TYPE_IPV4) ||
650 __connman_service_is_connected_state(service, CONNMAN_IPCONFIG_TYPE_IPV6))
655 connman_dbus_dict_append_basic(iter, "Connected",
656 DBUS_TYPE_BOOLEAN, &val);
658 str = connman_device_get_string(device, "Address");
659 connman_dbus_dict_append_basic(iter, "MAC.Address",
660 DBUS_TYPE_STRING, &str);
664 void __connman_technology_append_interfaces(DBusMessageIter *array,
665 enum connman_service_type type, const char *ifname)
668 struct connman_technology *technology = NULL;
670 for (list = technology_list; list; list = list->next) {
671 struct connman_technology *local_tech = list->data;
673 if (local_tech->type != type)
676 technology = local_tech;
683 for (list = technology->device_list; list; list = list->next) {
684 struct connman_device *device = list->data;
685 const char *str = connman_device_get_string(device, "Interface");
687 if (g_strcmp0(ifname, str) == 0)
690 dbus_message_iter_append_basic(array,
691 DBUS_TYPE_STRING, &str);
696 static void append_properties(DBusMessageIter *iter,
697 struct connman_technology *technology)
699 DBusMessageIter dict;
703 connman_dbus_dict_open(iter, &dict);
705 str = get_name(technology->type);
707 connman_dbus_dict_append_basic(&dict, "Name",
708 DBUS_TYPE_STRING, &str);
710 str = __connman_service_type2string(technology->type);
712 connman_dbus_dict_append_basic(&dict, "Type",
713 DBUS_TYPE_STRING, &str);
715 __sync_synchronize();
716 val = technology->enabled;
717 connman_dbus_dict_append_basic(&dict, "Powered",
721 val = technology->connected;
722 connman_dbus_dict_append_basic(&dict, "Connected",
726 val = technology->tethering;
727 connman_dbus_dict_append_basic(&dict, "Tethering",
731 if (technology->tethering_ident)
732 connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
734 &technology->tethering_ident);
736 if (technology->tethering_passphrase)
737 connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
739 &technology->tethering_passphrase);
741 #if defined TIZEN_EXT
742 connman_dbus_dict_append_basic(&dict, "MacPolicy",
744 &(technology->mac_policy));
746 connman_dbus_dict_append_basic(&dict, "PreassocMacPolicy",
748 &(technology->preassoc_mac_policy));
750 connman_dbus_dict_append_basic(&dict, "RandomMacLifetime",
752 &(technology->random_mac_lifetime));
754 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI)
755 connman_dbus_dict_append_dict(&dict, "Device.List",
756 append_devices, technology);
757 if (technology->regdom)
758 connman_dbus_dict_append_basic(&dict, "CountryCode",
760 &technology->regdom);
762 connman_dbus_dict_append_basic(&dict, "TetheringFreq",
764 &technology->tethering_freq);
765 connman_dbus_dict_close(iter, &dict);
768 static void technology_added_signal(struct connman_technology *technology)
771 DBusMessageIter iter;
773 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
774 CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
778 dbus_message_iter_init_append(signal, &iter);
779 dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
781 append_properties(&iter, technology);
783 dbus_connection_send(connection, signal, NULL);
784 dbus_message_unref(signal);
787 static void technology_removed_signal(struct connman_technology *technology)
789 g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
790 CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
791 DBUS_TYPE_OBJECT_PATH, &technology->path,
795 static DBusMessage *get_properties(DBusConnection *conn,
796 DBusMessage *message, void *user_data)
798 struct connman_technology *technology = user_data;
800 DBusMessageIter iter;
802 reply = dbus_message_new_method_return(message);
806 dbus_message_iter_init_append(reply, &iter);
807 append_properties(&iter, technology);
812 void __connman_technology_list_struct(DBusMessageIter *array)
815 DBusMessageIter entry;
817 for (list = technology_list; list; list = list->next) {
818 struct connman_technology *technology = list->data;
820 if (!technology->path ||
821 (technology->rfkill_driven &&
822 technology->hardblocked))
825 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
827 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
829 append_properties(&entry, technology);
830 dbus_message_iter_close_container(array, &entry);
834 static gboolean technology_pending_reply(gpointer user_data)
836 struct connman_technology *technology = user_data;
839 /* Power request timed out, send ETIMEDOUT. */
840 if (technology->pending_reply) {
841 reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
843 g_dbus_send_message(connection, reply);
845 dbus_message_unref(technology->pending_reply);
846 technology->pending_reply = NULL;
847 technology->pending_timeout = 0;
853 static int technology_affect_devices(struct connman_technology *technology,
856 int err = 0, err_dev;
859 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
861 __connman_technology_enabled(technology->type);
863 __connman_technology_disabled(technology->type);
867 #if defined TIZEN_EXT_WIFI_MESH
868 if (technology->type == CONNMAN_SERVICE_TYPE_MESH)
872 for (list = technology->device_list; list; list = list->next) {
873 struct connman_device *device = list->data;
876 err_dev = __connman_device_enable(device);
878 err_dev = __connman_device_disable(device);
880 if (err_dev < 0 && err_dev != -EALREADY)
887 static void powered_changed(struct connman_technology *technology)
891 if (!technology->dbus_registered)
894 if (technology->pending_reply) {
895 g_dbus_send_reply(connection,
896 technology->pending_reply, DBUS_TYPE_INVALID);
897 dbus_message_unref(technology->pending_reply);
898 technology->pending_reply = NULL;
900 g_source_remove(technology->pending_timeout);
901 technology->pending_timeout = 0;
904 __sync_synchronize();
905 enabled = technology->enabled;
906 #if defined TIZEN_EXT
907 DBG("ConnMan, Powered : %s, %s",
908 enabled ? "TRUE" : "FALSE",technology->path);
910 connman_dbus_property_changed_basic(technology->path,
911 CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
912 DBUS_TYPE_BOOLEAN, &enabled);
915 static void enable_tethering(struct connman_technology *technology)
919 if (!connman_setting_get_bool("PersistentTetheringMode"))
922 ret = set_tethering(technology, true);
923 if (ret < 0 && ret != -EALREADY)
924 DBG("Cannot enable tethering yet for %s (%d/%s)",
925 get_name(technology->type),
926 -ret, strerror(-ret));
929 static int technology_enabled(struct connman_technology *technology)
931 __sync_synchronize();
932 if (technology->enabled)
935 technology->enabled = true;
937 if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
938 struct connman_technology *p2p;
940 p2p = technology_find(CONNMAN_SERVICE_TYPE_P2P);
941 if (p2p && !p2p->enabled && p2p->enable_persistent)
942 technology_enabled(p2p);
945 if (technology->tethering_persistent)
946 enable_tethering(technology);
948 powered_changed(technology);
953 static int technology_enable(struct connman_technology *technology)
958 DBG("technology %p enable", technology);
960 __sync_synchronize();
962 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
963 struct connman_technology *wifi;
965 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
966 if (wifi && wifi->enabled)
967 return technology_enabled(technology);
971 if (technology->enabled)
974 if (technology->pending_reply)
977 if (connman_setting_get_bool("PersistentTetheringMode") &&
978 technology->tethering)
979 set_tethering(technology, true);
981 if (technology->rfkill_driven)
982 err = __connman_rfkill_block(technology->type, false);
984 err_dev = technology_affect_devices(technology, true);
986 if (!technology->rfkill_driven)
992 static int technology_disabled(struct connman_technology *technology)
994 __sync_synchronize();
995 if (!technology->enabled)
998 technology->enabled = false;
1000 powered_changed(technology);
1005 static int technology_disable(struct connman_technology *technology)
1009 DBG("technology %p disable", technology);
1011 __sync_synchronize();
1013 if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
1014 technology->enable_persistent = false;
1015 __connman_device_stop_scan(CONNMAN_SERVICE_TYPE_P2P);
1016 __connman_peer_disconnect_all();
1017 return technology_disabled(technology);
1018 } else if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
1019 struct connman_technology *p2p;
1021 p2p = technology_find(CONNMAN_SERVICE_TYPE_P2P);
1022 if (p2p && p2p->enabled) {
1023 p2p->enable_persistent = true;
1024 technology_disabled(p2p);
1028 if (!technology->enabled)
1031 if (technology->pending_reply)
1034 if (technology->tethering)
1035 set_tethering(technology, false);
1037 err = technology_affect_devices(technology, false);
1039 if (technology->rfkill_driven)
1040 err = __connman_rfkill_block(technology->type, true);
1045 static DBusMessage *set_powered(struct connman_technology *technology,
1046 DBusMessage *msg, bool powered)
1048 DBusMessage *reply = NULL;
1051 if (technology->rfkill_driven && technology->hardblocked) {
1057 err = technology_enable(technology);
1059 err = technology_disable(technology);
1061 if (err != -EBUSY) {
1062 technology->enable_persistent = powered;
1063 technology_save(technology);
1067 if (err == -EINPROGRESS) {
1068 technology->pending_reply = dbus_message_ref(msg);
1069 technology->pending_timeout = g_timeout_add_seconds(10,
1070 technology_pending_reply, technology);
1071 } else if (err == -EALREADY) {
1073 reply = __connman_error_already_enabled(msg);
1075 reply = __connman_error_already_disabled(msg);
1077 reply = __connman_error_failed(msg, -err);
1079 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1084 #if defined TIZEN_EXT
1085 int set_connman_bssid(enum bssid_type mode, char *bssid, const char *ifname)
1087 static int bssid_len;
1088 static const char *def_ifname = "default";
1089 static GSList *bssid_list = NULL;
1091 const char *local_ifname = ifname;
1093 struct connman_bssid_pending *bssid_info;
1095 DBG("mode: %d, ifname: %s", mode, ifname);
1098 local_ifname = def_ifname;
1100 for (list = bssid_list; list; list = list->next) {
1101 bssid_info = list->data;
1103 if (g_strcmp0(bssid_info->ifname, local_ifname) == 0) {
1109 if (mode == CHECK_BSSID) {
1116 if (mode == GET_BSSID && bssid) {
1118 memcpy(bssid, bssid_info->bssid, 6);
1124 if (mode == RESET_BSSID) {
1126 bssid_list = g_slist_remove(bssid_list, bssid_info);
1127 g_free(bssid_info->ifname);
1133 if (mode != SET_BSSID || !bssid) {
1134 DBG("Invalid parameter");
1139 bssid_list = g_slist_remove(bssid_list, bssid_info);
1140 g_free(bssid_info->ifname);
1144 bssid_info = g_try_malloc0(sizeof(struct connman_bssid_pending));
1146 DBG("Failed to allocate memory");
1150 unsigned char *bssid_data = bssid_info->bssid;
1152 bssid_len = sscanf(bssid, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
1153 &bssid_data[0], &bssid_data[1], &bssid_data[2],
1154 &bssid_data[3], &bssid_data[4], &bssid_data[5]);
1155 if (bssid_len != 6) {
1156 DBG("Incorrect BSSID format. bssid_len = %d", bssid_len);
1161 DBG("SET BSSID len: %d, BSSID: %02x:%02x:%02x:%02x:%02x:%02x ifname: %s",
1163 bssid_data[0], bssid_data[1], bssid_data[2],
1164 bssid_data[3], bssid_data[4], bssid_data[5],
1167 bssid_info->ifname = g_strdup(ifname);
1168 bssid_list = g_slist_prepend(bssid_list, bssid_info);
1173 void connman_technology_mac_policy_notify(struct connman_technology *technology,
1174 unsigned int policy)
1176 DBG("Mac polict set to %u", policy);
1178 technology->mac_policy = policy;
1179 technology_save(technology);
1182 void __connman_technology_notify_mac_policy_by_device(struct connman_device *device,
1183 int result, unsigned int policy)
1185 struct connman_technology *technology;
1186 enum connman_service_type type;
1188 type = __connman_device_get_service_type(device);
1189 technology = technology_find(type);
1194 connman_technology_mac_policy_notify(technology, policy);
1197 static DBusMessage *set_mac_policy(struct connman_technology *technology,
1198 DBusMessage *msg, unsigned int policy)
1200 DBusMessage *reply = NULL;
1202 unsigned int last_policy = technology->mac_policy;
1204 if (technology->rfkill_driven && technology->hardblocked) {
1209 for (GSList *list = technology->device_list; list; list = list->next) {
1210 struct connman_device *device = list->data;
1212 err = connman_device_set_mac_policy(device, policy);
1219 if (err != -EACCES && err != -EOPNOTSUPP) {
1220 for (GSList *list = technology->device_list; list; list = list->next) {
1221 struct connman_device *device = list->data;
1223 connman_device_set_mac_policy(device, last_policy);
1227 reply = __connman_error_failed(msg, -err);
1229 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1235 void connman_technology_preassoc_mac_policy_notify(struct connman_technology *technology,
1236 unsigned int policy)
1238 DBG("Preassoc mac polict set to %u", policy);
1240 technology->preassoc_mac_policy = policy;
1241 technology_save(technology);
1244 void __connman_technology_notify_preassoc_mac_policy_by_device(struct connman_device *device,
1245 int result, unsigned int policy)
1247 struct connman_technology *technology;
1248 enum connman_service_type type;
1250 type = __connman_device_get_service_type(device);
1251 technology = technology_find(type);
1256 connman_technology_preassoc_mac_policy_notify(technology, policy);
1259 static DBusMessage *set_preassoc_mac_policy(struct connman_technology *technology,
1260 DBusMessage *msg, unsigned int policy)
1262 DBusMessage *reply = NULL;
1264 unsigned int last_policy = technology->preassoc_mac_policy;
1266 if (technology->rfkill_driven && technology->hardblocked) {
1271 for (GSList *list = technology->device_list; list; list = list->next) {
1272 struct connman_device *device = list->data;
1274 err = connman_device_set_preassoc_mac_policy(device, policy);
1281 if (err != -EACCES && err != -EOPNOTSUPP) {
1282 for (GSList *list = technology->device_list; list; list = list->next) {
1283 struct connman_device *device = list->data;
1285 connman_device_set_preassoc_mac_policy(device, last_policy);
1289 reply = __connman_error_failed(msg, -err);
1291 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1297 void connman_technology_random_mac_lifetime_notify(struct connman_technology *technology,
1298 unsigned int lifetime)
1300 DBG("Random mac lifetime set to %u", lifetime);
1302 technology->random_mac_lifetime = lifetime;
1303 technology_save(technology);
1306 void __connman_technology_notify_random_mac_lifetime_by_device(struct connman_device *device,
1307 int result, unsigned int lifetime)
1309 struct connman_technology *technology;
1310 enum connman_service_type type;
1312 type = __connman_device_get_service_type(device);
1313 technology = technology_find(type);
1318 connman_technology_random_mac_lifetime_notify(technology, lifetime);
1321 static DBusMessage *set_random_mac_lifetime(struct connman_technology *technology,
1322 DBusMessage *msg, unsigned int lifetime)
1324 DBusMessage *reply = NULL;
1326 unsigned int last_lifetime = technology->random_mac_lifetime;
1328 if (technology->rfkill_driven && technology->hardblocked) {
1333 for (GSList *list = technology->device_list; list; list = list->next) {
1334 struct connman_device *device = list->data;
1336 err = connman_device_set_random_mac_lifetime(device, lifetime);
1341 if (err != -EACCES && err != -EOPNOTSUPP) {
1342 for (GSList *list = technology->device_list; list; list = list->next) {
1343 struct connman_device *device = list->data;
1345 connman_device_set_random_mac_lifetime(device, last_lifetime);
1349 reply = __connman_error_failed(msg, -err);
1351 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1358 static DBusMessage *set_property(DBusConnection *conn,
1359 DBusMessage *msg, void *data)
1361 struct connman_technology *technology = data;
1362 DBusMessageIter iter, value;
1366 DBG("conn %p", conn);
1368 if (!dbus_message_iter_init(msg, &iter))
1369 return __connman_error_invalid_arguments(msg);
1371 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1372 return __connman_error_invalid_arguments(msg);
1374 dbus_message_iter_get_basic(&iter, &name);
1375 dbus_message_iter_next(&iter);
1377 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
1378 return __connman_error_invalid_arguments(msg);
1380 dbus_message_iter_recurse(&iter, &value);
1382 type = dbus_message_iter_get_arg_type(&value);
1384 DBG("property %s", name);
1386 if (g_str_equal(name, "Tethering")) {
1387 dbus_bool_t tethering;
1390 if (type != DBUS_TYPE_BOOLEAN)
1391 return __connman_error_invalid_arguments(msg);
1393 if (!connman_technology_is_tethering_allowed(technology->type)) {
1394 DBG("%s tethering not allowed by config file",
1395 __connman_service_type2string(technology->type));
1396 return __connman_error_not_supported(msg);
1399 dbus_message_iter_get_basic(&value, &tethering);
1401 if (technology->tethering == tethering) {
1403 return __connman_error_already_disabled(msg);
1405 return __connman_error_already_enabled(msg);
1408 err = set_tethering(technology, tethering);
1410 return __connman_error_failed(msg, -err);
1412 technology->tethering_persistent = tethering;
1414 technology_save(technology);
1416 } else if (g_str_equal(name, "TetheringIdentifier")) {
1419 dbus_message_iter_get_basic(&value, &str);
1421 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1422 return __connman_error_not_supported(msg);
1424 if (strlen(str) < 1 || strlen(str) > 32)
1425 return __connman_error_invalid_arguments(msg);
1427 if (g_strcmp0(technology->tethering_ident, str) != 0) {
1428 g_free(technology->tethering_ident);
1429 technology->tethering_ident = g_strdup(str);
1430 technology_save(technology);
1432 connman_dbus_property_changed_basic(technology->path,
1433 CONNMAN_TECHNOLOGY_INTERFACE,
1434 "TetheringIdentifier",
1436 &technology->tethering_ident);
1438 } else if (g_str_equal(name, "TetheringPassphrase")) {
1441 dbus_message_iter_get_basic(&value, &str);
1443 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1444 return __connman_error_not_supported(msg);
1446 err = __connman_service_check_passphrase(CONNMAN_SERVICE_SECURITY_PSK,
1449 return __connman_error_passphrase_required(msg);
1451 if (g_strcmp0(technology->tethering_passphrase, str) != 0) {
1452 g_free(technology->tethering_passphrase);
1453 technology->tethering_passphrase = g_strdup(str);
1454 technology_save(technology);
1456 connman_dbus_property_changed_basic(technology->path,
1457 CONNMAN_TECHNOLOGY_INTERFACE,
1458 "TetheringPassphrase",
1460 &technology->tethering_passphrase);
1462 } else if (g_str_equal(name, "TetheringFreq")) {
1465 if (type != DBUS_TYPE_INT32)
1466 return __connman_error_invalid_arguments(msg);
1468 dbus_message_iter_get_basic(&value, &freq);
1470 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1471 return __connman_error_not_supported(msg);
1474 technology->tethering_freq = freq;
1475 technology_save(technology);
1477 connman_dbus_property_changed_basic(technology->path,
1478 CONNMAN_TECHNOLOGY_INTERFACE,
1481 &technology->tethering_freq);
1483 } else if (g_str_equal(name, "Powered")) {
1486 if (type != DBUS_TYPE_BOOLEAN)
1487 return __connman_error_invalid_arguments(msg);
1489 dbus_message_iter_get_basic(&value, &enable);
1491 return set_powered(technology, msg, enable);
1492 #if defined TIZEN_EXT
1493 } else if (g_str_equal(name, "SetBSSID")) {
1496 if (type != DBUS_TYPE_STRING)
1497 return __connman_error_invalid_arguments(msg);
1499 dbus_message_iter_get_basic(&value, &key);
1500 DBG("BSSID %s", key);
1501 set_connman_bssid(SET_BSSID, key, NULL);
1502 } else if (g_str_equal(name, "MacPolicy")) {
1503 dbus_uint32_t mac_policy;
1505 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1506 return __connman_error_not_supported(msg);
1508 if (type != DBUS_TYPE_UINT32)
1509 return __connman_error_invalid_arguments(msg);
1511 dbus_message_iter_get_basic(&value, &mac_policy);
1513 if (mac_policy <= 2)
1514 return set_mac_policy(technology, msg, mac_policy);
1516 return __connman_error_invalid_arguments(msg);
1518 } else if (g_str_equal(name, "PreassocMacPolicy")) {
1519 dbus_uint32_t preassoc_mac_policy;
1521 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1522 return __connman_error_not_supported(msg);
1524 if (type != DBUS_TYPE_UINT32)
1525 return __connman_error_invalid_arguments(msg);
1527 dbus_message_iter_get_basic(&value, &preassoc_mac_policy);
1529 if (preassoc_mac_policy <= 2)
1530 return set_preassoc_mac_policy(technology, msg, preassoc_mac_policy);
1532 return __connman_error_invalid_arguments(msg);
1534 } else if (g_str_equal(name, "RandomMacLifetime")) {
1535 dbus_uint32_t random_mac_lifetime;
1537 if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
1538 return __connman_error_not_supported(msg);
1540 if (type != DBUS_TYPE_UINT32)
1541 return __connman_error_invalid_arguments(msg);
1543 dbus_message_iter_get_basic(&value, &random_mac_lifetime);
1545 if (random_mac_lifetime > 0)
1546 return set_random_mac_lifetime(technology, msg, random_mac_lifetime);
1548 return __connman_error_invalid_arguments(msg);
1550 } else if (g_str_equal(name, "CountryCode")) {
1553 dbus_message_iter_get_basic(&value, &str);
1554 DBG("country code %s", str);
1555 connman_technology_set_regdom(str);
1558 return __connman_error_invalid_property(msg);
1560 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1563 static void reply_scan_pending(struct connman_technology *technology, int err)
1567 DBG("technology %p err %d", technology, err);
1569 while (technology->scan_pending) {
1570 #if defined TIZEN_EXT
1571 struct connman_scan_pending *pending_data = technology->scan_pending->data;
1572 DBusMessage *msg = pending_data->msg;
1574 DBusMessage *msg = technology->scan_pending->data;
1576 DBG("reply to %s", dbus_message_get_sender(msg));
1579 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1581 reply = __connman_error_failed(msg, -err);
1582 g_dbus_send_message(connection, reply);
1583 dbus_message_unref(msg);
1585 technology->scan_pending =
1586 g_slist_delete_link(technology->scan_pending,
1587 technology->scan_pending);
1588 #if defined TIZEN_EXT
1589 g_free(pending_data->ifname);
1590 g_free(pending_data);
1595 #if defined TIZEN_EXT
1596 dbus_bool_t __connman_technology_notify_scan_changed(const char *key, void *val)
1599 DBusMessage *signal;
1600 DBusMessageIter iter;
1601 dbus_bool_t result = FALSE;
1603 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
1604 CONNMAN_MANAGER_INTERFACE, "ScanChanged");
1608 dbus_message_iter_init_append(signal, &iter);
1610 connman_dbus_property_append_basic(&iter, key, DBUS_TYPE_BOOLEAN, val);
1612 connman_dbus_property_append_basic(&iter, "", DBUS_TYPE_BOOLEAN, val);
1614 result = dbus_connection_send(connection, signal, NULL);
1615 dbus_message_unref(signal);
1617 DBG("Successfuly sent signal");
1622 void __connman_technology_notify_scan_done(const char *ifname, int val)
1625 DBusMessage *signal;
1626 DBusMessageIter iter;
1628 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
1629 CONNMAN_MANAGER_INTERFACE, "ScanDone");
1633 dbus_message_iter_init_append(signal, &iter);
1635 connman_dbus_property_append_basic(&iter, ifname,
1636 DBUS_TYPE_INT32, &val);
1638 connman_dbus_property_append_basic(&iter, "",
1639 DBUS_TYPE_INT32, &val);
1641 dbus_connection_send(connection, signal, NULL);
1642 dbus_message_unref(signal);
1644 DBG("Successfuly sent ScanDone signal");
1647 static void reply_scan_pending_device(
1648 struct connman_technology *technology, const char *ifname, int count)
1652 dbus_bool_t status = 0;
1653 connman_scan_type_e scan_type = CONNMAN_SCAN_TYPE_UNKNOWN;
1655 DBG("technology %p ifname %s count %d", technology, ifname, count);
1657 list = technology->scan_pending;
1660 struct connman_scan_pending *pending_data = list->data;
1661 DBusMessage *msg = pending_data->msg;
1664 if (scan_type == CONNMAN_SCAN_TYPE_UNKNOWN)
1665 scan_type = pending_data->scan_type;
1667 if (count != 0 && g_strcmp0(pending_data->ifname, ifname) != 0)
1670 scan_type = pending_data->scan_type;
1672 DBG("reply to %s", dbus_message_get_sender(msg));
1673 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1675 g_dbus_send_message(connection, reply);
1676 dbus_message_unref(msg);
1678 technology->scan_pending =
1679 g_slist_remove(technology->scan_pending, pending_data);
1681 g_free(pending_data->ifname);
1682 g_free(pending_data);
1685 if (scan_type == CONNMAN_SCAN_TYPE_UNKNOWN)
1686 scan_type = CONNMAN_SCAN_TYPE_FULL_CHANNEL;
1688 __connman_technology_notify_scan_changed(ifname, &status);
1689 __connman_technology_notify_scan_done(ifname, scan_type);
1692 static void __connman_technology_notify_device_detected(
1693 struct connman_technology *technology, const char *ifname, bool val)
1696 DBusMessage *signal;
1697 DBusMessageIter iter;
1698 dbus_bool_t detected = val;
1703 signal = dbus_message_new_signal(technology->path,
1704 CONNMAN_TECHNOLOGY_INTERFACE, "DeviceDetected");
1708 dbus_message_iter_init_append(signal, &iter);
1709 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ifname);
1710 dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &detected);
1712 dbus_connection_send(connection, signal, NULL);
1713 dbus_message_unref(signal);
1715 DBG("Successfuly sent DeviceDetected signal");
1718 void __connman_technology_notify_roaming_state(const char *ifname,
1719 const char *state, const char *cur_bssid, const char *dst_bssid)
1722 DBusMessage *signal;
1723 DBusMessageIter array, dict;
1725 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
1726 CONNMAN_MANAGER_INTERFACE, "RoamingStateChanged");
1730 dbus_message_iter_init_append(signal, &array);
1732 connman_dbus_dict_open(&array, &dict);
1735 connman_dbus_dict_append_basic(&dict, "Interface",
1736 DBUS_TYPE_STRING, &ifname);
1738 connman_dbus_dict_append_basic(&dict, "State",
1739 DBUS_TYPE_STRING, &state);
1741 connman_dbus_dict_append_basic(&dict, "ConnectedBSSID",
1742 DBUS_TYPE_STRING, &cur_bssid);
1744 connman_dbus_dict_append_basic(&dict, "TargetBSSID",
1745 DBUS_TYPE_STRING, &dst_bssid);
1747 connman_dbus_dict_close(&array, &dict);
1749 dbus_connection_send(connection, signal, NULL);
1750 dbus_message_unref(signal);
1752 DBG("Successfully sent Roaming State Changed signal");
1756 void __connman_technology_scan_started(struct connman_device *device)
1758 DBG("device %p", device);
1759 #if defined TIZEN_EXT
1760 dbus_bool_t status = 1;
1761 const char *ifname = connman_device_get_string(device, "Interface");
1763 __connman_technology_notify_scan_changed(ifname, &status);
1767 void __connman_technology_scan_stopped(struct connman_device *device,
1768 enum connman_service_type type)
1771 struct connman_technology *technology;
1774 technology = technology_find(type);
1776 DBG("technology %p device %p", technology, device);
1781 for (list = technology->device_list; list; list = list->next) {
1782 struct connman_device *other_device = list->data;
1784 if (device == other_device)
1787 if (connman_device_get_scanning(other_device, type))
1791 #if defined TIZEN_EXT
1792 const char *ifname = connman_device_get_string(device, "Interface");
1793 reply_scan_pending_device(technology, ifname, count);
1798 reply_scan_pending(technology, 0);
1802 void __connman_technology_notify_regdom_by_device(struct connman_device *device,
1803 int result, const char *alpha2)
1805 bool regdom_set = false;
1806 struct connman_technology *technology;
1807 enum connman_service_type type;
1808 GSList *tech_drivers;
1810 type = __connman_device_get_service_type(device);
1811 technology = technology_find(type);
1818 for (tech_drivers = technology->driver_list;
1820 tech_drivers = g_slist_next(tech_drivers)) {
1821 struct connman_technology_driver *driver =
1824 if (driver->set_regdom) {
1825 driver->set_regdom(technology, alpha2);
1835 connman_technology_regdom_notify(technology, alpha2);
1838 static DBusMessage *scan(DBusConnection *conn, DBusMessage *msg, void *data)
1840 struct connman_technology *technology = data;
1843 DBG("technology %p request from %s", technology,
1844 dbus_message_get_sender(msg));
1846 if (technology->type == CONNMAN_SERVICE_TYPE_P2P &&
1847 !technology->enabled)
1848 return __connman_error_permission_denied(msg);
1850 #if !defined TIZEN_EXT
1851 dbus_message_ref(msg);
1852 technology->scan_pending =
1853 g_slist_prepend(technology->scan_pending, msg);
1856 err = __connman_device_request_scan_full(technology->type);
1858 #if defined TIZEN_EXT
1859 return __connman_error_failed(msg, -err);
1861 reply_scan_pending(technology, err);
1864 #if defined TIZEN_EXT
1865 struct connman_scan_pending *pending_data =
1866 g_try_malloc0(sizeof(struct connman_scan_pending));
1868 return __connman_error_failed(msg, ENOMEM);
1870 pending_data->scan_type = CONNMAN_SCAN_TYPE_FULL_CHANNEL;
1871 DBG("scan_type %d", pending_data->scan_type);
1873 pending_data->msg = dbus_message_ref(msg);
1875 technology->scan_pending =
1876 g_slist_prepend(technology->scan_pending, pending_data);
1881 #if defined TIZEN_EXT
1882 static DBusMessage *scan_device(DBusConnection *conn, DBusMessage *msg, void *data)
1884 struct connman_technology *technology = data;
1885 DBusMessageIter iter;
1889 DBG("technology %p request from %s", technology,
1890 dbus_message_get_sender(msg));
1892 if (!dbus_message_iter_init(msg, &iter))
1893 return __connman_error_invalid_arguments(msg);
1895 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1896 return __connman_error_invalid_arguments(msg);
1898 dbus_message_iter_get_basic(&iter, &ifname);
1899 DBG("Interface name %s", ifname);
1901 if (!ifname || strlen(ifname) == 0)
1902 return __connman_error_invalid_arguments(msg);
1904 err = connman_device_request_device_scan(technology->type, ifname, true);
1906 return __connman_error_failed(msg, -err);
1908 struct connman_scan_pending *pending_data =
1909 g_try_malloc0(sizeof(struct connman_scan_pending));
1911 return __connman_error_failed(msg, ENOMEM);
1913 pending_data->ifname = g_strdup(ifname);
1914 if (pending_data->ifname == NULL) {
1915 g_free(pending_data);
1916 return __connman_error_failed(msg, ENOMEM);
1919 pending_data->scan_type = CONNMAN_SCAN_TYPE_FULL_CHANNEL;
1920 DBG("scan_type %d", pending_data->scan_type);
1922 pending_data->msg = dbus_message_ref(msg);
1924 technology->scan_pending =
1925 g_slist_prepend(technology->scan_pending, pending_data);
1930 static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void *data)
1932 struct connman_technology *technology = data;
1933 GSList *specific_scan_list = NULL;
1935 const char *name = NULL;
1936 const char *freq = NULL;
1937 const char *ifname = NULL;
1938 DBusMessageIter iter, dict;
1941 DBG("technology %p request from %s", technology,
1942 dbus_message_get_sender(msg));
1944 if (!dbus_message_iter_init(msg, &iter))
1945 return __connman_error_invalid_arguments(msg);
1947 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
1948 return __connman_error_invalid_arguments(msg);
1950 dbus_message_iter_recurse(&iter, &dict);
1951 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1952 DBusMessageIter entry, value2;
1956 dbus_message_iter_recurse(&dict, &entry);
1957 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) {
1958 g_slist_free_full(specific_scan_list, g_free);
1959 return __connman_error_invalid_arguments(msg);
1962 dbus_message_iter_get_basic(&entry, &key);
1963 dbus_message_iter_next(&entry);
1965 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) {
1966 g_slist_free_full(specific_scan_list, g_free);
1967 return __connman_error_invalid_arguments(msg);
1970 dbus_message_iter_recurse(&entry, &value2);
1971 type = dbus_message_iter_get_arg_type(&value2);
1972 if (g_str_equal(key, "Ifname") && type == DBUS_TYPE_STRING) {
1974 dbus_message_iter_get_basic(&value2, &ifname);
1975 DBG("ifname %s", ifname);
1976 } else if (g_str_equal(key, "SSID")) {
1977 if (type != DBUS_TYPE_STRING) {
1978 g_slist_free_full(specific_scan_list, g_free);
1979 return __connman_error_invalid_arguments(msg);
1982 scan_type = CONNMAN_MULTI_SCAN_SSID; /* SSID based scan */
1983 dbus_message_iter_get_basic(&value2, &name);
1984 DBG("name %s", name);
1985 specific_scan_list = g_slist_append(specific_scan_list, g_strdup(name));
1986 } else if (g_str_equal(key, "Frequency")) {
1987 if (type != DBUS_TYPE_STRING) {
1988 g_slist_free_full(specific_scan_list, g_free);
1989 return __connman_error_invalid_arguments(msg);
1992 scan_type = CONNMAN_MULTI_SCAN_FREQ; /* Frequency based scan */
1993 dbus_message_iter_get_basic(&value2, &freq);
1994 DBG("freq %s", freq);
1995 specific_scan_list = g_slist_append(specific_scan_list, GINT_TO_POINTER(atoi(freq)));
1996 } else if (g_str_equal(key, "SSID_Mixed")) {
1997 if (type != DBUS_TYPE_STRING) {
1998 g_slist_free_full(specific_scan_list, g_free);
1999 return __connman_error_invalid_arguments(msg);
2002 scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */
2003 dbus_message_iter_get_basic(&value2, &name);
2005 connman_multi_scan_ap_s *ap =
2006 (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s));
2008 g_strlcpy(ap->str, name, strlen(name) + 1);
2010 specific_scan_list = g_slist_append(specific_scan_list, ap);
2012 DBG("Failed to allocate memory");
2014 } else if (g_str_equal(key, "Frequency_Mixed")) {
2015 if (type != DBUS_TYPE_STRING) {
2016 g_slist_free_full(specific_scan_list, g_free);
2017 return __connman_error_invalid_arguments(msg);
2020 scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */
2021 dbus_message_iter_get_basic(&value2, &freq);
2023 connman_multi_scan_ap_s *ap =
2024 (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s));
2026 g_strlcpy(ap->str, freq, strlen(freq) + 1);
2028 specific_scan_list = g_slist_append(specific_scan_list, ap);
2030 DBG("Failed to allocate memory");
2032 dbus_message_iter_next(&dict);
2035 err = __connman_device_request_specific_scan(technology->type, ifname, scan_type, specific_scan_list);
2037 return __connman_error_failed(msg, -err);
2039 guint list_size = g_slist_length(specific_scan_list);
2041 if (scan_type == CONNMAN_MULTI_SCAN_SSID ||
2042 scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ)
2043 g_slist_free_full(specific_scan_list, g_free);
2045 struct connman_scan_pending *pending_data =
2046 g_try_malloc0(sizeof(struct connman_scan_pending));
2048 return __connman_error_failed(msg, ENOMEM);
2051 pending_data->ifname = g_strdup(ifname);
2052 if (pending_data->ifname == NULL) {
2053 g_free(pending_data);
2054 return __connman_error_failed(msg, ENOMEM);
2059 pending_data->scan_type = CONNMAN_SCAN_TYPE_SPECIFIC_AP;
2061 pending_data->scan_type = CONNMAN_SCAN_TYPE_MULTI_AP;
2062 DBG("list_size %u scan_type %d", list_size, pending_data->scan_type);
2064 pending_data->msg = dbus_message_ref(msg);
2066 technology->scan_pending =
2067 g_slist_prepend(technology->scan_pending, pending_data);
2072 static DBusMessage *get_5ghz_supported(DBusConnection *conn, DBusMessage *msg, void *data)
2075 DBusMessageIter iter, dict;
2077 struct connman_technology *technology = data;
2078 dbus_bool_t supported = false;
2079 const char *ifname = NULL;
2081 DBG("technology %p", technology);
2083 reply = dbus_message_new_method_return(msg);
2087 dbus_message_iter_init_append(reply, &iter);
2088 connman_dbus_dict_open(&iter, &dict);
2090 for (list = technology->device_list; list; list = list->next) {
2091 struct connman_device *device = list->data;
2093 supported = connman_device_get_wifi_5ghz_supported(device);
2094 ifname = connman_device_get_string(device, "Interface");
2096 DBG("ifname %s supported : %d", ifname, supported);
2097 connman_dbus_dict_append_basic(&dict, ifname,
2102 connman_dbus_dict_close(&iter, &dict);
2107 static DBusMessage *get_6ghz_supported(DBusConnection *conn, DBusMessage *msg, void *data)
2110 DBusMessageIter iter, dict;
2112 struct connman_technology *technology = data;
2113 dbus_bool_t supported = false;
2114 const char *ifname = NULL;
2116 DBG("technology %p", technology);
2118 reply = dbus_message_new_method_return(msg);
2122 dbus_message_iter_init_append(reply, &iter);
2123 connman_dbus_dict_open(&iter, &dict);
2125 for (list = technology->device_list; list; list = list->next) {
2126 struct connman_device *device = list->data;
2128 supported = connman_device_get_wifi_6ghz_supported(device);
2129 ifname = connman_device_get_string(device, "Interface");
2131 DBG("ifname %s supported : %d", ifname, supported);
2132 connman_dbus_dict_append_basic(&dict, ifname,
2137 connman_dbus_dict_close(&iter, &dict);
2142 static DBusMessage *get_scan_state(DBusConnection *conn, DBusMessage *msg, void *data)
2145 DBusMessageIter iter, dict;
2147 struct connman_technology *technology = data;
2148 dbus_bool_t scanning = false;
2149 const char *ifname = NULL;
2151 DBG("technology %p", technology);
2153 reply = dbus_message_new_method_return(msg);
2157 dbus_message_iter_init_append(reply, &iter);
2158 connman_dbus_dict_open(&iter, &dict);
2160 for (list = technology->device_list; list; list = list->next) {
2161 struct connman_device *device = list->data;
2163 scanning = connman_device_get_scanning(device, technology->type);
2164 ifname = connman_device_get_string(device, "Interface");
2166 DBG("ifname %s scanning : %d", ifname, scanning);
2167 connman_dbus_dict_append_basic(&dict, ifname,
2172 connman_dbus_dict_close(&iter, &dict);
2177 static DBusMessage *get_max_scan_ssid(DBusConnection *conn, DBusMessage *msg, void *data)
2180 DBusMessageIter iter, dict;
2182 struct connman_technology *technology = data;
2183 dbus_int32_t max_scan_ssids = 0;
2184 const char *ifname = NULL;
2186 DBG("technology %p", technology);
2188 reply = dbus_message_new_method_return(msg);
2192 dbus_message_iter_init_append(reply, &iter);
2193 connman_dbus_dict_open(&iter, &dict);
2195 for (list = technology->device_list; list; list = list->next) {
2196 struct connman_device *device = list->data;
2198 max_scan_ssids = connman_device_get_max_scan_ssids(device);
2199 ifname = connman_device_get_string(device, "Interface");
2201 DBG("ifname %s max_scan_ssids : %d", ifname, max_scan_ssids);
2202 connman_dbus_dict_append_basic(&dict, ifname,
2207 connman_dbus_dict_close(&iter, &dict);
2212 static int technology_enable_device(struct connman_technology *technology,
2213 bool enable_device, const char *ifname, struct connman_device **device_out)
2218 for (list = technology->device_list; list; list = list->next) {
2219 struct connman_device *device = list->data;
2220 const char *str = connman_device_get_string(device, "Interface");
2222 if (g_strcmp0(str, ifname) != 0)
2226 err = __connman_device_enable(device);
2228 err = __connman_device_disable(device);
2230 *device_out = device;
2237 static DBusMessage *technology_set_device_powered(struct connman_technology *technology,
2238 DBusMessage *msg, bool powered, const char *ifname)
2240 DBusMessage *reply = NULL;
2241 struct connman_device *device = NULL;
2244 err = technology_enable_device(technology, powered, ifname, &device);
2246 if (err == -EINPROGRESS) {
2248 connman_device_set_pending_reply(device, msg);
2250 } else if (err == -EALREADY) {
2252 reply = __connman_error_already_enabled(msg);
2254 reply = __connman_error_already_disabled(msg);
2256 reply = __connman_error_failed(msg, -err);
2258 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2263 static DBusMessage *set_device_power(DBusConnection *conn,
2264 DBusMessage *msg, void *data)
2266 struct connman_technology *technology = data;
2267 DBusMessageIter iter;
2272 DBG("conn %p", conn);
2274 if (!dbus_message_iter_init(msg, &iter))
2275 return __connman_error_invalid_arguments(msg);
2277 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
2278 return __connman_error_invalid_arguments(msg);
2280 dbus_message_iter_get_basic(&iter, &name);
2281 dbus_message_iter_next(&iter);
2283 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
2284 return __connman_error_invalid_arguments(msg);
2286 DBG("interface name %s", name);
2290 if (len + 1 > IFNAMSIZ)
2291 return __connman_error_invalid_arguments(msg);
2293 dbus_message_iter_get_basic(&iter, &enable);
2294 DBG("powered %s", enable ? "TRUE" : "FALSE");
2296 return technology_set_device_powered(technology, msg, enable, name);
2299 static DBusMessage *set_bssid(DBusConnection *conn,
2300 DBusMessage *msg, void *data)
2302 DBusMessageIter iter;
2306 DBG("conn %p", conn);
2308 if (!dbus_message_iter_init(msg, &iter))
2309 return __connman_error_invalid_arguments(msg);
2311 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
2312 return __connman_error_invalid_arguments(msg);
2314 dbus_message_iter_get_basic(&iter, &name);
2315 dbus_message_iter_next(&iter);
2317 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
2318 return __connman_error_invalid_arguments(msg);
2320 dbus_message_iter_get_basic(&iter, &bssid);
2322 DBG("interface name %s bssid %s", name, bssid);
2326 if (len + 1 > IFNAMSIZ)
2327 return __connman_error_invalid_arguments(msg);
2329 set_connman_bssid(SET_BSSID, bssid, name);
2331 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2333 static struct connman_technology *technology_get(enum connman_service_type type);
2335 void technology_save_device(struct connman_device *device)
2337 struct connman_technology *technology;
2338 enum connman_service_type type;
2340 type = __connman_device_get_service_type(device);
2342 if (type != CONNMAN_SERVICE_TYPE_WIFI)
2345 technology = technology_get(type);
2349 if (!g_slist_find(technology->device_list, device))
2354 const char *name = get_name(technology->type);
2356 DBG("technology %p type %d name %s", technology, technology->type,
2361 keyfile = __connman_storage_load_global();
2363 keyfile = g_key_file_new();
2365 identifier = g_strdup_printf("%s", name);
2369 GSList *list = NULL;
2370 gchar **ifname_list = NULL;
2371 guint dev_count = g_slist_length(technology->device_list);
2373 if (dev_count >= 1) {
2374 GString *ifname_str = g_string_new(NULL);
2377 for (list = technology->device_list; list; list = list->next) {
2378 struct connman_device *device = list->data;
2380 if (connman_device_get_powered(device)) {
2381 const char *ifname = connman_device_get_string(device, "Interface");
2383 if (ifname_str->len > 0)
2384 g_string_append_printf(ifname_str, " %s", ifname);
2386 g_string_append(ifname_str, ifname);
2390 if (ifname_str->len > 0) {
2391 ifname_list = g_strsplit_set(ifname_str->str, " ", 0);
2392 dev_count = g_strv_length(ifname_list);
2393 g_key_file_set_string_list(keyfile, identifier, "Enable.Devices",
2394 (const gchar **) ifname_list, dev_count);
2396 technology->enable_persistent = true;
2398 g_key_file_remove_key(keyfile, identifier, "Enable.Devices", NULL);
2399 technology->enable_persistent = false;
2402 g_strfreev(ifname_list);
2403 g_string_free(ifname_str, TRUE);
2407 g_key_file_set_boolean(keyfile, identifier, "Enable",
2408 technology->enable_persistent);
2410 g_key_file_set_boolean(keyfile, identifier, "Tethering",
2411 technology->tethering_persistent);
2413 if (technology->tethering_ident)
2414 g_key_file_set_string(keyfile, identifier,
2415 "Tethering.Identifier",
2416 technology->tethering_ident);
2418 if (technology->tethering_passphrase)
2419 g_key_file_set_string(keyfile, identifier,
2420 "Tethering.Passphrase",
2421 technology->tethering_passphrase);
2426 __connman_storage_save_global(keyfile);
2428 g_key_file_free(keyfile);
2432 #if defined TIZEN_EXT_WIFI_MESH
2433 bool __connman_technology_get_connected(enum connman_service_type type)
2435 struct connman_technology *technology;
2437 technology = technology_find(type);
2442 return technology->connected;
2445 void __connman_technology_mesh_interface_create_finished(
2446 enum connman_service_type type, bool success,
2450 struct connman_technology *technology;
2452 technology = technology_find(type);
2454 DBG("technology %p success %d", technology, success);
2459 msg = technology->mesh_dbus_msg;
2461 DBG("No pending dbus message");
2466 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2467 __connman_device_request_scan(technology->type);
2469 reply = g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
2470 ".MeshInterfaceAddFailed", "%s", error);
2471 g_dbus_send_message(connection, reply);
2472 dbus_message_unref(msg);
2473 technology->mesh_dbus_msg = NULL;
2476 void __connman_technology_mesh_interface_remove_finished(
2477 enum connman_service_type type, bool success)
2480 struct connman_technology *technology;
2482 technology = technology_find(type);
2484 DBG("technology %p success %d", technology, success);
2486 if (!technology || !technology->mesh_dbus_msg)
2489 msg = technology->mesh_dbus_msg;
2491 DBG("No pending dbus message");
2496 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2498 reply = __connman_error_failed(msg, EINVAL);
2499 g_dbus_send_message(connection, reply);
2500 dbus_message_unref(msg);
2501 technology->mesh_dbus_msg = NULL;
2504 void __connman_technology_notify_abort_scan(enum connman_service_type type,
2508 struct connman_technology *technology;
2510 technology = technology_find(type);
2512 DBG("technology %p result %d", technology, result);
2514 if (!technology || !technology->mesh_dbus_msg)
2517 msg = technology->mesh_dbus_msg;
2519 DBG("No pending dbus message");
2524 reply = __connman_error_scan_abort_failed(msg);
2526 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2528 g_dbus_send_message(connection, reply);
2529 dbus_message_unref(msg);
2530 technology->mesh_dbus_msg = NULL;
2533 static DBusMessage *mesh_commands(DBusConnection *conn,
2534 DBusMessage *msg, void *data)
2536 struct connman_technology *technology = data;
2537 DBusMessageIter iter, value, dict;
2538 const char *cmd = NULL, *ifname = NULL, *parent_ifname = NULL;
2541 DBG("conn %p", conn);
2543 if (technology->type != CONNMAN_SERVICE_TYPE_MESH)
2544 return __connman_error_invalid_arguments(msg);
2546 if (!dbus_message_iter_init(msg, &iter))
2547 return __connman_error_invalid_arguments(msg);
2549 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
2550 return __connman_error_invalid_arguments(msg);
2552 dbus_message_iter_get_basic(&iter, &cmd);
2553 dbus_message_iter_next(&iter);
2555 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
2556 return __connman_error_invalid_arguments(msg);
2558 dbus_message_iter_recurse(&iter, &value);
2560 if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_ARRAY)
2561 return __connman_error_invalid_arguments(msg);
2563 DBG("Mesh Command %s", cmd);
2564 if (g_str_equal(cmd, "MeshInterfaceAdd")) {
2565 dbus_message_iter_recurse(&value, &dict);
2566 const char *bridge_ifname = NULL;
2567 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2568 DBusMessageIter entry, value2;
2572 dbus_message_iter_recurse(&dict, &entry);
2574 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2575 return __connman_error_invalid_arguments(msg);
2577 dbus_message_iter_get_basic(&entry, &key);
2578 dbus_message_iter_next(&entry);
2580 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2581 return __connman_error_invalid_arguments(msg);
2583 dbus_message_iter_recurse(&entry, &value2);
2585 type = dbus_message_iter_get_arg_type(&value2);
2587 if (g_str_equal(key, "Ifname")) {
2588 if (type != DBUS_TYPE_STRING)
2589 return __connman_error_invalid_arguments(msg);
2591 dbus_message_iter_get_basic(&value2, &ifname);
2592 } else if (g_str_equal(key, "ParentIfname")) {
2593 if (type != DBUS_TYPE_STRING)
2594 return __connman_error_invalid_arguments(msg);
2596 dbus_message_iter_get_basic(&value2, &parent_ifname);
2597 } else if (g_str_equal(key, "BridgeIfname")) {
2598 if (type != DBUS_TYPE_STRING)
2599 return __connman_error_invalid_arguments(msg);
2601 dbus_message_iter_get_basic(&value2, &bridge_ifname);
2603 dbus_message_iter_next(&dict);
2605 DBG("Mesh Ifname %s parent %s bridge %s", ifname, parent_ifname,
2606 bridge_ifname ? bridge_ifname : "NULL");
2607 err = __connman_mesh_add_virtual_interface(ifname, parent_ifname,
2611 DBG("Failed to add virtual mesh interface");
2612 return __connman_error_failed(msg, -err);
2615 DBG("Successfully added virtual mesh interface");
2617 dbus_message_ref(msg);
2618 technology->mesh_dbus_msg = msg;
2620 } else if (g_str_equal(cmd, "MeshInterfaceRemove")) {
2621 dbus_message_iter_recurse(&value, &dict);
2622 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2623 DBusMessageIter entry, value2;
2627 dbus_message_iter_recurse(&dict, &entry);
2629 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2630 return __connman_error_invalid_arguments(msg);
2632 dbus_message_iter_get_basic(&entry, &key);
2633 dbus_message_iter_next(&entry);
2635 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2636 return __connman_error_invalid_arguments(msg);
2638 dbus_message_iter_recurse(&entry, &value2);
2640 type = dbus_message_iter_get_arg_type(&value2);
2642 if (g_str_equal(key, "Ifname")) {
2643 if (type != DBUS_TYPE_STRING)
2644 return __connman_error_invalid_arguments(msg);
2646 dbus_message_iter_get_basic(&value2, &ifname);
2648 dbus_message_iter_next(&dict);
2650 DBG("Mesh Ifname %s", ifname);
2651 err = __connman_mesh_remove_virtual_interface(ifname);
2654 DBG("Failed to remove virtual mesh interface");
2655 return __connman_error_failed(msg, -err);
2658 DBG("Successfully removed virtual mesh interface");
2660 dbus_message_ref(msg);
2661 technology->mesh_dbus_msg = msg;
2663 } else if (g_str_equal(cmd, "MeshCreateNetwork")) {
2664 struct connman_mesh *connman_mesh;
2665 const char *name = NULL;
2666 const char *sec_type = NULL;
2667 const char *mesh_ifname = NULL;
2668 char *identifier, *group, *address;
2669 unsigned int freq = 0;
2670 unsigned int ieee80211w = 0;
2673 dbus_message_iter_recurse(&value, &dict);
2674 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2675 DBusMessageIter entry, value2;
2679 dbus_message_iter_recurse(&dict, &entry);
2681 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2682 return __connman_error_invalid_arguments(msg);
2684 dbus_message_iter_get_basic(&entry, &key);
2685 dbus_message_iter_next(&entry);
2687 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2688 return __connman_error_invalid_arguments(msg);
2690 dbus_message_iter_recurse(&entry, &value2);
2692 type = dbus_message_iter_get_arg_type(&value2);
2694 if (g_str_equal(key, "Name")) {
2695 if (type != DBUS_TYPE_STRING)
2696 return __connman_error_invalid_arguments(msg);
2698 dbus_message_iter_get_basic(&value2, &name);
2699 } else if (g_str_equal(key, "Frequency")) {
2700 if (type != DBUS_TYPE_UINT16)
2701 return __connman_error_invalid_arguments(msg);
2703 dbus_message_iter_get_basic(&value2, &freq);
2704 } else if (g_str_equal(key, "Security")) {
2705 if (type != DBUS_TYPE_STRING)
2706 return __connman_error_invalid_arguments(msg);
2708 dbus_message_iter_get_basic(&value2, &sec_type);
2709 } else if (g_str_equal(key, "Pmf")) {
2710 if (type != DBUS_TYPE_UINT16)
2711 return __connman_error_invalid_arguments(msg);
2713 dbus_message_iter_get_basic(&value2, &ieee80211w);
2715 dbus_message_iter_next(&dict);
2718 if (name == NULL || sec_type == NULL || freq == 0)
2719 return __connman_error_invalid_arguments(msg);
2721 DBG("Name %s Frequency %d Security type %s Pmf %u",
2722 name, freq, sec_type, ieee80211w);
2724 if (g_strcmp0(sec_type, "none") != 0 &&
2725 g_strcmp0(sec_type, "sae") != 0) {
2726 DBG("Unsupported security");
2727 return __connman_error_invalid_arguments(msg);
2730 mesh_ifname = connman_mesh_get_interface_name();
2732 if (!connman_mesh_is_interface_created()) {
2733 DBG("Mesh interface doesn't exists");
2734 return __connman_error_invalid_command(msg);
2737 str = g_string_sized_new((strlen(name) * 2) + 24);
2739 for (i = 0; name[i]; i++)
2740 g_string_append_printf(str, "%02x", name[i]);
2742 g_string_append_printf(str, "_mesh");
2744 if (g_strcmp0(sec_type, "none") == 0)
2745 g_string_append_printf(str, "_none");
2746 else if (g_strcmp0(sec_type, "sae") == 0)
2747 g_string_append_printf(str, "_sae");
2749 group = g_string_free(str, FALSE);
2751 identifier = connman_inet_ifaddr(mesh_ifname);
2752 address = connman_inet_ifname2addr(mesh_ifname);
2754 connman_mesh = connman_mesh_create(identifier, group);
2755 connman_mesh_set_name(connman_mesh, name);
2756 connman_mesh_set_address(connman_mesh, address);
2757 connman_mesh_set_security(connman_mesh, sec_type);
2758 connman_mesh_set_frequency(connman_mesh, freq);
2759 connman_mesh_set_index(connman_mesh, connman_inet_ifindex(mesh_ifname));
2760 connman_mesh_set_peer_type(connman_mesh,
2761 CONNMAN_MESH_PEER_TYPE_CREATED);
2762 connman_mesh_set_ieee80211w(connman_mesh, ieee80211w);
2764 connman_mesh_register(connman_mesh);
2768 DBG("Successfully Created Mesh Network");
2769 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2771 } else if (g_str_equal(cmd, "AbortScan")) {
2772 DBG("Abort Scan method");
2773 err = __connman_device_abort_scan(technology->type);
2775 DBG("Failed to abort scan");
2776 return __connman_error_failed(msg, -err);
2779 DBG("Successfully requested to abort scan");
2780 dbus_message_ref(msg);
2781 technology->mesh_dbus_msg = msg;
2783 } else if (g_str_equal(cmd, "MeshSpecificScan")) {
2784 const char *name = NULL;
2785 unsigned int freq = 0;
2786 dbus_message_iter_recurse(&value, &dict);
2787 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2788 DBusMessageIter entry, value2;
2792 dbus_message_iter_recurse(&dict, &entry);
2794 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2795 return __connman_error_invalid_arguments(msg);
2797 dbus_message_iter_get_basic(&entry, &key);
2798 dbus_message_iter_next(&entry);
2800 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2801 return __connman_error_invalid_arguments(msg);
2803 dbus_message_iter_recurse(&entry, &value2);
2805 type = dbus_message_iter_get_arg_type(&value2);
2807 if (g_str_equal(key, "Name")) {
2808 if (type != DBUS_TYPE_STRING)
2809 return __connman_error_invalid_arguments(msg);
2811 dbus_message_iter_get_basic(&value2, &name);
2812 } else if (g_str_equal(key, "Frequency")) {
2813 if (type != DBUS_TYPE_UINT16)
2814 return __connman_error_invalid_arguments(msg);
2816 dbus_message_iter_get_basic(&value2, &freq);
2818 dbus_message_iter_next(&dict);
2821 DBG("MeshID %s Frequency %d sender %s", name, freq,
2822 dbus_message_get_sender(msg));
2824 struct connman_scan_pending *pending_data =
2825 g_try_malloc0(sizeof(struct connman_scan_pending));
2827 return __connman_error_failed(msg, ENOMEM);
2829 pending_data->msg = dbus_message_ref(msg);
2831 technology->scan_pending =
2832 g_slist_prepend(technology->scan_pending, pending_data);
2834 err = __connman_device_request_mesh_specific_scan(technology->type,
2837 reply_scan_pending(technology, err);
2839 DBG("Successfully requested to scan specific Mesh Network");
2841 } else if (g_str_equal(cmd, "SetMeshGate")) {
2842 unsigned int hwmp_rootmode = 0;
2843 bool gate_announce = false;
2844 unsigned int stp = 0;
2846 dbus_message_iter_recurse(&value, &dict);
2847 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2848 DBusMessageIter entry, value2;
2852 dbus_message_iter_recurse(&dict, &entry);
2854 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2855 return __connman_error_invalid_arguments(msg);
2857 dbus_message_iter_get_basic(&entry, &key);
2858 dbus_message_iter_next(&entry);
2860 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
2861 return __connman_error_invalid_arguments(msg);
2863 dbus_message_iter_recurse(&entry, &value2);
2865 type = dbus_message_iter_get_arg_type(&value2);
2867 if (g_str_equal(key, "GateAnnounce")) {
2868 if (type != DBUS_TYPE_BOOLEAN)
2869 return __connman_error_invalid_arguments(msg);
2871 dbus_message_iter_get_basic(&value2, &gate_announce);
2872 } else if (g_str_equal(key, "HWMPRootMode")) {
2873 if (type != DBUS_TYPE_UINT16)
2874 return __connman_error_invalid_arguments(msg);
2876 dbus_message_iter_get_basic(&value2, &hwmp_rootmode);
2877 } else if (g_str_equal(key, "STP")) {
2878 if (type != DBUS_TYPE_UINT16)
2879 return __connman_error_invalid_arguments(msg);
2881 dbus_message_iter_get_basic(&value2, &stp);
2883 dbus_message_iter_next(&dict);
2886 DBG("GateAnnounce %d HWMPRootMode %d STP %d sender %s",
2887 gate_announce, hwmp_rootmode, stp, dbus_message_get_sender(msg));
2889 err = __connman_mesh_set_stp_gate_announce(gate_announce,
2894 return __connman_error_failed(msg, -err);
2896 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2898 return __connman_error_invalid_command(msg);
2903 static const GDBusMethodTable technology_methods[] = {
2904 { GDBUS_DEPRECATED_METHOD("GetProperties",
2905 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
2907 { GDBUS_ASYNC_METHOD("SetProperty",
2908 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
2909 NULL, set_property) },
2910 { GDBUS_ASYNC_METHOD("Scan", NULL, NULL, scan) },
2911 #if defined TIZEN_EXT
2912 { GDBUS_ASYNC_METHOD("ScanDevice", GDBUS_ARGS({ "interface_name", "s" }),
2913 NULL, scan_device) },
2914 { GDBUS_ASYNC_METHOD("SpecificScan", GDBUS_ARGS({ "specificscan", "a{sv}" }),
2915 NULL, specific_scan) },
2916 { GDBUS_METHOD("GetScanState", NULL, GDBUS_ARGS({ "scan_state", "a{sv}" }),
2918 { GDBUS_METHOD("Get5GhzSupported", NULL, GDBUS_ARGS({ "supported", "a{sv}" }),
2919 get_5ghz_supported) },
2920 { GDBUS_METHOD("Get6GHzSupported", NULL, GDBUS_ARGS({ "supported", "a{sv}" }),
2921 get_6ghz_supported) },
2922 { GDBUS_METHOD("GetMaxScanSsid", NULL, GDBUS_ARGS({ "maxscanssid", "a{sv}" }),
2923 get_max_scan_ssid) },
2924 { GDBUS_ASYNC_METHOD("SetDevicePower",
2925 GDBUS_ARGS({ "ifname", "s" }, { "value", "b" }),
2926 NULL, set_device_power) },
2927 { GDBUS_ASYNC_METHOD("SetBSSID",
2928 GDBUS_ARGS({ "ifname", "s" }, { "bssid", "s" }),
2931 #if defined TIZEN_EXT_WIFI_MESH
2932 { GDBUS_ASYNC_METHOD("MeshCommands",
2933 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
2934 NULL, mesh_commands) },
2939 static const GDBusSignalTable technology_signals[] = {
2940 { GDBUS_SIGNAL("PropertyChanged",
2941 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
2942 #if defined TIZEN_EXT
2943 { GDBUS_SIGNAL("DeviceChanged",
2944 GDBUS_ARGS({ "device_property", "a{sv}" })) },
2945 { GDBUS_SIGNAL("DeviceDetected",
2946 GDBUS_ARGS({ "ifname", "s" }, { "detected", "b" })) },
2951 static bool technology_dbus_register(struct connman_technology *technology)
2953 if (technology->dbus_registered ||
2954 (technology->rfkill_driven &&
2955 technology->hardblocked))
2958 if (!g_dbus_register_interface(connection, technology->path,
2959 CONNMAN_TECHNOLOGY_INTERFACE,
2960 technology_methods, technology_signals,
2961 NULL, technology, NULL)) {
2962 connman_error("Failed to register %s", technology->path);
2966 technology_added_signal(technology);
2967 technology->dbus_registered = true;
2972 static void technology_dbus_unregister(struct connman_technology *technology)
2974 if (!technology->dbus_registered)
2977 technology_removed_signal(technology);
2978 g_dbus_unregister_interface(connection, technology->path,
2979 CONNMAN_TECHNOLOGY_INTERFACE);
2981 technology->dbus_registered = false;
2984 static void technology_put(struct connman_technology *technology)
2986 DBG("technology %p", technology);
2988 if (__sync_sub_and_fetch(&technology->refcount, 1) > 0)
2991 reply_scan_pending(technology, -EINTR);
2993 while (technology->driver_list) {
2994 struct connman_technology_driver *driver;
2996 driver = technology->driver_list->data;
2999 driver->remove(technology);
3001 technology->driver_list =
3002 g_slist_delete_link(technology->driver_list,
3003 technology->driver_list);
3006 technology_list = g_slist_remove(technology_list, technology);
3008 technology_dbus_unregister(technology);
3010 g_slist_free(technology->device_list);
3012 if (technology->pending_reply) {
3013 dbus_message_unref(technology->pending_reply);
3014 technology->pending_reply = NULL;
3015 g_source_remove(technology->pending_timeout);
3016 technology->pending_timeout = 0;
3019 g_strfreev(technology->enabled_devices);
3021 g_free(technology->path);
3022 g_free(technology->regdom);
3023 g_free(technology->tethering_ident);
3024 g_free(technology->tethering_passphrase);
3028 static struct connman_technology *technology_get(enum connman_service_type type)
3030 GSList *tech_drivers = NULL;
3031 struct connman_technology_driver *driver;
3032 struct connman_technology *technology;
3036 DBG("type %d", type);
3038 str = __connman_service_type2string(type);
3042 technology = technology_find(type);
3044 #if defined TIZEN_EXT_WIFI_MESH
3045 if (type != CONNMAN_SERVICE_TYPE_P2P &&
3046 type != CONNMAN_SERVICE_TYPE_MESH)
3048 if (type != CONNMAN_SERVICE_TYPE_P2P)
3050 __sync_fetch_and_add(&technology->refcount, 1);
3054 /* First check if we have a driver for this technology type */
3055 for (list = driver_list; list; list = list->next) {
3056 driver = list->data;
3058 if (driver->type == type) {
3059 DBG("technology %p driver %p", technology, driver);
3060 tech_drivers = g_slist_append(tech_drivers, driver);
3064 if (!tech_drivers) {
3065 DBG("No matching drivers found for %s.",
3066 __connman_service_type2string(type));
3070 technology = g_try_new0(struct connman_technology, 1);
3074 technology->refcount = 1;
3075 technology->type = type;
3076 technology->path = g_strdup_printf("%s/technology/%s",
3079 #if defined TIZEN_EXT_WIFI_MESH
3080 if (type == CONNMAN_SERVICE_TYPE_MESH) {
3081 struct connman_technology *wifi;
3083 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
3085 technology->enabled = wifi->enabled;
3089 technology_load(technology);
3090 technology_list = g_slist_prepend(technology_list, technology);
3091 technology->driver_list = tech_drivers;
3093 for (list = tech_drivers; list; list = list->next) {
3094 driver = list->data;
3096 if (driver->probe && driver->probe(technology) < 0)
3097 DBG("Driver probe failed for technology %p",
3101 if (!technology_dbus_register(technology)) {
3102 technology_put(technology);
3106 if (type == CONNMAN_SERVICE_TYPE_P2P) {
3107 struct connman_technology *wifi;
3110 enable = technology->enable_persistent;
3112 wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
3114 enable = wifi->enabled;
3116 technology_affect_devices(technology, enable);
3119 DBG("technology %p %s", technology, get_name(technology->type));
3124 int connman_technology_driver_register(struct connman_technology_driver *driver)
3127 struct connman_device *device;
3128 enum connman_service_type type;
3130 for (list = driver_list; list; list = list->next) {
3131 if (list->data == driver)
3135 DBG("Registering %s driver", driver->name);
3137 driver_list = g_slist_insert_sorted(driver_list, driver,
3141 * Check for technology less devices if this driver
3142 * can service any of them.
3144 for (list = techless_device_list; list; list = list->next) {
3145 device = list->data;
3147 type = __connman_device_get_service_type(device);
3148 if (type != driver->type)
3151 techless_device_list = g_slist_remove(techless_device_list,
3154 __connman_technology_add_device(device);
3157 /* Check for orphaned rfkill switches. */
3158 g_hash_table_foreach(rfkill_list, rfkill_check,
3159 GINT_TO_POINTER(driver->type));
3162 if (driver->type == CONNMAN_SERVICE_TYPE_P2P) {
3163 if (!technology_get(CONNMAN_SERVICE_TYPE_P2P))
3167 #if defined TIZEN_EXT_WIFI_MESH
3168 if (driver->type == CONNMAN_SERVICE_TYPE_MESH) {
3169 if (!technology_get(CONNMAN_SERVICE_TYPE_MESH))
3177 void connman_technology_driver_unregister(struct connman_technology_driver *driver)
3179 GSList *list, *tech_drivers;
3180 struct connman_technology *technology;
3181 struct connman_technology_driver *current;
3183 DBG("Unregistering driver %p name %s", driver, driver->name);
3185 for (list = technology_list; list; list = list->next) {
3186 technology = list->data;
3188 for (tech_drivers = technology->driver_list; tech_drivers;
3189 tech_drivers = g_slist_next(tech_drivers)) {
3190 current = tech_drivers->data;
3191 if (driver != current)
3195 driver->remove(technology);
3197 technology->driver_list =
3198 g_slist_remove(technology->driver_list,
3204 driver_list = g_slist_remove(driver_list, driver);
3206 if (driver->type == CONNMAN_SERVICE_TYPE_P2P) {
3207 technology = technology_find(CONNMAN_SERVICE_TYPE_P2P);
3209 technology_put(technology);
3211 #if defined TIZEN_EXT_WIFI_MESH
3212 if (driver->type == CONNMAN_SERVICE_TYPE_MESH) {
3213 technology = technology_find(CONNMAN_SERVICE_TYPE_MESH);
3215 technology_put(technology);
3220 void __connman_technology_add_interface(enum connman_service_type type,
3221 int index, const char *ident)
3223 struct connman_technology *technology;
3224 GSList *tech_drivers;
3225 struct connman_technology_driver *driver;
3229 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3230 case CONNMAN_SERVICE_TYPE_SYSTEM:
3232 case CONNMAN_SERVICE_TYPE_ETHERNET:
3233 case CONNMAN_SERVICE_TYPE_WIFI:
3234 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3235 case CONNMAN_SERVICE_TYPE_CELLULAR:
3236 case CONNMAN_SERVICE_TYPE_GPS:
3237 case CONNMAN_SERVICE_TYPE_VPN:
3238 case CONNMAN_SERVICE_TYPE_GADGET:
3239 case CONNMAN_SERVICE_TYPE_P2P:
3240 #if defined TIZEN_EXT_WIFI_MESH
3241 case CONNMAN_SERVICE_TYPE_MESH:
3246 name = connman_inet_ifname(index);
3247 connman_info("Adding interface %s [ %s ]", name,
3248 __connman_service_type2string(type));
3250 technology = technology_find(type);
3255 for (tech_drivers = technology->driver_list; tech_drivers;
3256 tech_drivers = g_slist_next(tech_drivers)) {
3257 driver = tech_drivers->data;
3259 if (driver->add_interface)
3260 driver->add_interface(technology, index, name, ident);
3264 * At this point we can try to enable tethering automatically as
3265 * now the interfaces are set properly.
3267 if (technology->tethering_persistent)
3268 enable_tethering(technology);
3274 void __connman_technology_remove_interface(enum connman_service_type type,
3275 int index, const char *ident)
3277 struct connman_technology *technology;
3278 GSList *tech_drivers;
3279 struct connman_technology_driver *driver;
3283 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3284 case CONNMAN_SERVICE_TYPE_SYSTEM:
3286 case CONNMAN_SERVICE_TYPE_ETHERNET:
3287 case CONNMAN_SERVICE_TYPE_WIFI:
3288 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3289 case CONNMAN_SERVICE_TYPE_CELLULAR:
3290 case CONNMAN_SERVICE_TYPE_GPS:
3291 case CONNMAN_SERVICE_TYPE_VPN:
3292 case CONNMAN_SERVICE_TYPE_GADGET:
3293 case CONNMAN_SERVICE_TYPE_P2P:
3294 #if defined TIZEN_EXT_WIFI_MESH
3295 case CONNMAN_SERVICE_TYPE_MESH:
3300 name = connman_inet_ifname(index);
3301 connman_info("Remove interface %s [ %s ]", name,
3302 __connman_service_type2string(type));
3305 technology = technology_find(type);
3310 for (tech_drivers = technology->driver_list; tech_drivers;
3311 tech_drivers = g_slist_next(tech_drivers)) {
3312 driver = tech_drivers->data;
3314 if (driver->remove_interface)
3315 driver->remove_interface(technology, index);
3319 int __connman_technology_add_device(struct connman_device *device)
3321 struct connman_technology *technology;
3322 enum connman_service_type type;
3324 type = __connman_device_get_service_type(device);
3326 DBG("device %p type %s", device, get_name(type));
3328 technology = technology_get(type);
3331 * Since no driver can be found for this device at the moment we
3332 * add it to the techless device list.
3334 techless_device_list = g_slist_prepend(techless_device_list,
3340 __sync_synchronize();
3341 if (technology->rfkill_driven) {
3342 if (technology->enabled)
3343 __connman_device_enable(device);
3345 __connman_device_disable(device);
3350 if (technology->enable_persistent &&
3351 !global_offlinemode) {
3352 #if defined TIZEN_EXT
3355 if (technology->enabled_devices && type == CONNMAN_SERVICE_TYPE_WIFI) {
3358 const char *ifname = connman_device_get_string(device, "Interface");
3360 while (technology->enabled_devices[i]) {
3361 if (g_strcmp0(technology->enabled_devices[i], ifname) == 0) {
3370 err = __connman_device_enable(device);
3372 int err = __connman_device_enable(device);
3375 * connman_technology_add_device() calls __connman_device_enable()
3376 * but since the device is already enabled, the call does not
3377 * propagate through to connman_technology_enabled via
3378 * connman_device_set_powered.
3380 if (err == -EALREADY)
3381 __connman_technology_enabled(type);
3383 /* if technology persistent state is offline */
3384 if (!technology->enable_persistent)
3385 __connman_device_disable(device);
3388 technology->device_list = g_slist_prepend(technology->device_list,
3391 #if defined TIZEN_EXT
3392 technology_save_device(device);
3394 const char *ifname = connman_device_get_string(device, "Interface");
3395 __connman_technology_notify_device_detected(technology, ifname, true);
3397 connman_device_set_mac_policy(device, technology->mac_policy);
3398 connman_device_set_preassoc_mac_policy(device, technology->preassoc_mac_policy);
3399 connman_device_set_random_mac_lifetime(device, technology->random_mac_lifetime);
3404 int __connman_technology_remove_device(struct connman_device *device)
3406 struct connman_technology *technology;
3407 enum connman_service_type type;
3409 DBG("device %p", device);
3411 type = __connman_device_get_service_type(device);
3413 technology = technology_find(type);
3415 techless_device_list = g_slist_remove(techless_device_list,
3420 technology->device_list = g_slist_remove(technology->device_list,
3423 #if defined TIZEN_EXT
3424 technology_save_device(device);
3426 const char *ifname = connman_device_get_string(device, "Interface");
3427 __connman_technology_notify_device_detected(technology, ifname, false);
3430 if (technology->tethering)
3431 set_tethering(technology, false);
3433 technology_put(technology);
3438 int __connman_technology_enabled(enum connman_service_type type)
3440 struct connman_technology *technology;
3442 technology = technology_find(type);
3446 DBG("technology %p type %s rfkill %d enabled %d", technology,
3447 get_name(type), technology->rfkill_driven,
3448 technology->enabled);
3450 #if !defined TIZEN_EXT
3451 if (technology->rfkill_driven) {
3452 if (technology->tethering_persistent)
3453 enable_tethering(technology);
3458 return technology_enabled(technology);
3461 int __connman_technology_disabled(enum connman_service_type type)
3463 struct connman_technology *technology;
3466 technology = technology_find(type);
3470 #if !defined TIZEN_EXT
3471 if (technology->rfkill_driven)
3475 for (list = technology->device_list; list; list = list->next) {
3476 struct connman_device *device = list->data;
3478 if (connman_device_get_powered(device))
3482 return technology_disabled(technology);
3485 int __connman_technology_set_offlinemode(bool offlinemode)
3488 int err = -EINVAL, enabled_tech_count = 0;
3490 if (global_offlinemode == offlinemode)
3493 DBG("offlinemode %s", offlinemode ? "On" : "Off");
3496 * This is a bit tricky. When you set offlinemode, there is no
3497 * way to differentiate between attempting offline mode and
3498 * resuming offlinemode from last saved profile. We need that
3499 * information in rfkill_update, otherwise it falls back on the
3500 * technology's persistent state. Hence we set the offline mode here
3501 * but save it & call the notifier only if it is successful.
3504 global_offlinemode = offlinemode;
3506 /* Traverse technology list, enable/disable each technology. */
3507 for (list = technology_list; list; list = list->next) {
3508 struct connman_technology *technology = list->data;
3511 err = technology_disable(technology);
3513 if (technology->hardblocked)
3516 if (technology->enable_persistent) {
3517 err = technology_enable(technology);
3518 enabled_tech_count++;
3523 if (err == 0 || err == -EINPROGRESS || err == -EALREADY ||
3524 (err == -EINVAL && enabled_tech_count == 0)) {
3525 connman_technology_save_offlinemode();
3526 __connman_notifier_offlinemode(offlinemode);
3528 global_offlinemode = connman_technology_load_offlinemode();
3533 #if defined TIZEN_EXT_WIFI_MESH
3534 static gboolean __add_ethernet_to_bridge(gpointer data)
3537 __connman_mesh_add_ethernet_to_bridge();
3542 void __connman_technology_set_connected(enum connman_service_type type,
3545 struct connman_technology *technology;
3548 technology = technology_find(type);
3552 DBG("technology %p connected %d", technology, connected);
3554 technology->connected = connected;
3556 #if defined TIZEN_EXT_WIFI_MESH
3557 if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET && connected)
3558 g_idle_add(__add_ethernet_to_bridge, NULL);
3562 connman_dbus_property_changed_basic(technology->path,
3563 CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
3564 DBUS_TYPE_BOOLEAN, &val);
3567 static bool technology_apply_rfkill_change(struct connman_technology *technology,
3572 bool hardblock_changed = false;
3574 GList *start, *list;
3576 DBG("technology %p --> %d/%d vs %d/%d",
3577 technology, softblock, hardblock,
3578 technology->softblocked, technology->hardblocked);
3580 if (technology->hardblocked == hardblock)
3581 goto softblock_change;
3583 if (!(new_rfkill && !hardblock)) {
3584 start = g_hash_table_get_values(rfkill_list);
3586 for (list = start; list; list = list->next) {
3587 struct connman_rfkill *rfkill = list->data;
3589 if (rfkill->type != technology->type)
3592 if (rfkill->hardblock != hardblock)
3600 goto softblock_change;
3602 technology->hardblocked = hardblock;
3603 hardblock_changed = true;
3606 if (!apply && technology->softblocked != softblock)
3610 return technology->hardblocked;
3612 technology->softblocked = softblock;
3614 if (technology->hardblocked ||
3615 technology->softblocked) {
3616 if (technology_disabled(technology) != -EALREADY)
3617 technology_affect_devices(technology, false);
3618 } else if (!technology->hardblocked &&
3619 !technology->softblocked) {
3620 if (technology_enabled(technology) != -EALREADY)
3621 technology_affect_devices(technology, true);
3624 if (hardblock_changed) {
3625 if (technology->hardblocked) {
3626 DBG("%s is switched off.", get_name(technology->type));
3627 technology_dbus_unregister(technology);
3629 DBG("%s is switched on.", get_name(technology->type));
3630 technology_dbus_register(technology);
3632 if (global_offlinemode)
3633 __connman_rfkill_block(technology->type, true);
3637 return technology->hardblocked;
3640 int __connman_technology_add_rfkill(unsigned int index,
3641 enum connman_service_type type,
3645 struct connman_technology *technology;
3646 struct connman_rfkill *rfkill;
3648 DBG("index %u type %d soft %u hard %u", index, type,
3649 softblock, hardblock);
3651 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
3655 rfkill = g_try_new0(struct connman_rfkill, 1);
3659 rfkill->index = index;
3660 rfkill->type = type;
3661 rfkill->softblock = softblock;
3662 rfkill->hardblock = hardblock;
3664 g_hash_table_insert(rfkill_list, GINT_TO_POINTER(index), rfkill);
3667 #if defined TIZEN_EXT
3668 /* Fix Svace Issue [WGID: 1348]. */
3671 technology = technology_get(type);
3672 /* If there is no driver for this type, ignore it. */
3676 technology->rfkill_driven = true;
3678 #if !defined TIZEN_EXT
3679 /* If hardblocked, there is no need to handle softblocked state */
3680 if (technology_apply_rfkill_change(technology,
3681 softblock, hardblock, true))
3685 if (global_offlinemode)
3689 * Depending on softblocked state we unblock/block according to
3690 * offlinemode and persistente state.
3692 if (technology->softblocked &&
3693 technology->enable_persistent)
3694 return __connman_rfkill_block(type, false);
3695 else if (!technology->softblocked &&
3696 !technology->enable_persistent)
3697 return __connman_rfkill_block(type, true);
3702 int __connman_technology_update_rfkill(unsigned int index,
3703 enum connman_service_type type,
3707 struct connman_technology *technology;
3708 struct connman_rfkill *rfkill;
3710 DBG("index %u soft %u hard %u", index, softblock, hardblock);
3712 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
3716 if (rfkill->softblock == softblock &&
3717 rfkill->hardblock == hardblock)
3720 rfkill->softblock = softblock;
3721 rfkill->hardblock = hardblock;
3723 technology = technology_find(type);
3724 /* If there is no driver for this type, ignore it. */
3728 technology_apply_rfkill_change(technology, softblock, hardblock,
3731 if (technology->hardblocked)
3732 DBG("%s hardblocked", get_name(technology->type));
3734 DBG("%s is%s softblocked", get_name(technology->type),
3735 technology->softblocked ? "" : " not");
3740 int __connman_technology_remove_rfkill(unsigned int index,
3741 enum connman_service_type type)
3743 struct connman_technology *technology;
3744 struct connman_rfkill *rfkill;
3746 DBG("index %u", index);
3748 rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
3752 g_hash_table_remove(rfkill_list, GINT_TO_POINTER(index));
3754 technology = technology_find(type);
3758 technology_apply_rfkill_change(technology,
3759 technology->softblocked, !technology->hardblocked, false);
3761 technology_put(technology);
3766 int __connman_technology_init(void)
3770 connection = connman_dbus_get_connection();
3772 rfkill_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
3775 global_offlinemode = connman_technology_load_offlinemode();
3777 /* This will create settings file if it is missing */
3778 connman_technology_save_offlinemode();
3783 void __connman_technology_cleanup(void)
3787 while (technology_list) {
3788 struct connman_technology *technology = technology_list->data;
3789 technology_list = g_slist_remove(technology_list, technology);
3790 technology_put(technology);
3793 g_hash_table_destroy(rfkill_list);
3795 dbus_connection_unref(connection);