3 * WPA supplicant library with GLib integration
5 * Copyright (C) 2012-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
34 #include <netinet/if_ether.h>
35 #include <netinet/in.h>
41 #include "gsupplicant.h"
43 #define IEEE80211_CAP_ESS 0x0001
44 #define IEEE80211_CAP_IBSS 0x0002
45 #define IEEE80211_CAP_PRIVACY 0x0010
48 #define WLAN_EID_HT_CAP 45
49 #define WLAN_EID_VHT_CAP 191
50 #define WLAN_EID_SUPP_RATES 1
51 #define WLAN_EID_EXT_SUPP_RATES 50
52 #define COUNTRY_CODE_LENGTH 2
53 #define WIFI_BSSID_LEN_MAX 6
56 #define BSS_UNKNOWN_STRENGTH -90
58 static DBusConnection *connection;
60 static const GSupplicantCallbacks *callbacks_pointer;
62 static dbus_bool_t system_available = FALSE;
63 static dbus_bool_t system_ready = FALSE;
65 static dbus_int32_t debug_level;
66 static dbus_bool_t debug_timestamp = FALSE;
67 static dbus_bool_t debug_showkeys = FALSE;
69 static const char *debug_strings[] = {
70 "msgdump", "debug", "info", "warning", "error", NULL
73 static unsigned int eap_methods;
80 static struct strvalmap eap_method_map[] = {
81 { "MD5", G_SUPPLICANT_EAP_METHOD_MD5 },
82 { "TLS", G_SUPPLICANT_EAP_METHOD_TLS },
83 { "MSCHAPV2", G_SUPPLICANT_EAP_METHOD_MSCHAPV2 },
84 { "PEAP", G_SUPPLICANT_EAP_METHOD_PEAP },
85 { "TTLS", G_SUPPLICANT_EAP_METHOD_TTLS },
86 { "GTC", G_SUPPLICANT_EAP_METHOD_GTC },
87 { "OTP", G_SUPPLICANT_EAP_METHOD_OTP },
88 { "LEAP", G_SUPPLICANT_EAP_METHOD_LEAP },
89 { "WSC", G_SUPPLICANT_EAP_METHOD_WSC },
93 static struct strvalmap keymgmt_map[] = {
94 { "none", G_SUPPLICANT_KEYMGMT_NONE },
95 { "ieee8021x", G_SUPPLICANT_KEYMGMT_IEEE8021X },
96 { "wpa-none", G_SUPPLICANT_KEYMGMT_WPA_NONE },
97 { "wpa-psk", G_SUPPLICANT_KEYMGMT_WPA_PSK },
98 { "wpa-psk-sha256", G_SUPPLICANT_KEYMGMT_WPA_PSK_256 },
99 { "wpa-ft-psk", G_SUPPLICANT_KEYMGMT_WPA_FT_PSK },
100 { "wpa-ft-eap", G_SUPPLICANT_KEYMGMT_WPA_FT_EAP },
101 { "wpa-eap", G_SUPPLICANT_KEYMGMT_WPA_EAP },
102 { "wpa-eap-sha256", G_SUPPLICANT_KEYMGMT_WPA_EAP_256 },
103 { "wps", G_SUPPLICANT_KEYMGMT_WPS },
104 #if defined TIZEN_EXT
105 { "sae", G_SUPPLICANT_KEYMGMT_SAE },
106 { "owe", G_SUPPLICANT_KEYMGMT_OWE },
111 static struct strvalmap authalg_capa_map[] = {
112 { "open", G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN },
113 { "shared", G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED },
114 { "leap", G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP },
118 static struct strvalmap proto_capa_map[] = {
119 { "wpa", G_SUPPLICANT_CAPABILITY_PROTO_WPA },
120 { "rsn", G_SUPPLICANT_CAPABILITY_PROTO_RSN },
124 static struct strvalmap group_map[] = {
125 { "wep40", G_SUPPLICANT_GROUP_WEP40 },
126 { "wep104", G_SUPPLICANT_GROUP_WEP104 },
127 { "tkip", G_SUPPLICANT_GROUP_TKIP },
128 { "ccmp", G_SUPPLICANT_GROUP_CCMP },
132 static struct strvalmap pairwise_map[] = {
133 { "none", G_SUPPLICANT_PAIRWISE_NONE },
134 { "tkip", G_SUPPLICANT_PAIRWISE_TKIP },
135 { "ccmp", G_SUPPLICANT_PAIRWISE_CCMP },
139 static struct strvalmap scan_capa_map[] = {
140 { "active", G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE },
141 { "passive", G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE },
142 { "ssid", G_SUPPLICANT_CAPABILITY_SCAN_SSID },
146 static struct strvalmap mode_capa_map[] = {
147 { "infrastructure", G_SUPPLICANT_CAPABILITY_MODE_INFRA },
148 { "ad-hoc", G_SUPPLICANT_CAPABILITY_MODE_IBSS },
149 { "ap", G_SUPPLICANT_CAPABILITY_MODE_AP },
150 { "p2p", G_SUPPLICANT_CAPABILITY_MODE_P2P },
151 #if defined TIZEN_EXT_WIFI_MESH
152 { "mesh", G_SUPPLICANT_CAPABILITY_MODE_MESH },
157 static GHashTable *interface_table;
158 static GHashTable *bss_mapping;
159 static GHashTable *peer_mapping;
160 static GHashTable *group_mapping;
161 static GHashTable *pending_peer_connection;
162 static GHashTable *config_file_table;
164 struct _GSupplicantWpsCredentials {
165 unsigned char ssid[32];
166 unsigned int ssid_len;
170 struct added_network_information {
172 GSupplicantSecurity security;
174 char * private_passphrase;
177 #if defined TIZEN_EXT_WIFI_MESH
178 struct _GSupplicantMeshGroupInfo {
179 unsigned char ssid[32];
180 unsigned int ssid_len;
181 int disconnect_reason;
185 struct _GSupplicantInterface {
188 unsigned int keymgmt_capa;
189 unsigned int authalg_capa;
190 unsigned int proto_capa;
191 unsigned int group_capa;
192 unsigned int pairwise_capa;
193 unsigned int scan_capa;
194 unsigned int mode_capa;
195 unsigned int max_scan_ssids;
198 bool ap_create_in_progress;
200 GSupplicantState state;
201 dbus_bool_t scanning;
202 GSupplicantInterfaceCallback scan_callback;
208 struct _GSupplicantWpsCredentials wps_cred;
209 GSupplicantWpsState wps_state;
210 GHashTable *network_table;
211 GHashTable *peer_table;
212 GHashTable *group_table;
213 GHashTable *bss_mapping;
215 const char *pending_peer_path;
216 GSupplicantNetwork *current_network;
217 struct added_network_information network_info;
218 #if defined TIZEN_EXT
219 dbus_bool_t is_5_0_Ghz_supported;
220 int disconnect_reason;
222 #if defined TIZEN_EXT_WIFI_MESH
224 struct _GSupplicantMeshGroupInfo group_info;
228 struct g_supplicant_bss {
229 GSupplicantInterface *interface;
231 unsigned char bssid[6];
232 unsigned char ssid[32];
233 unsigned int ssid_len;
234 dbus_uint16_t frequency;
235 dbus_uint32_t maxrate;
237 GSupplicantMode mode;
238 GSupplicantSecurity security;
239 dbus_bool_t rsn_selected;
240 unsigned int wpa_keymgmt;
241 unsigned int wpa_pairwise;
242 unsigned int wpa_group;
243 unsigned int rsn_keymgmt;
244 unsigned int rsn_pairwise;
245 unsigned int rsn_group;
246 unsigned int keymgmt;
249 dbus_bool_t ieee8021x;
250 #if defined TIZEN_EXT
252 dbus_bool_t ft_ieee8021x;
255 unsigned char country_code[COUNTRY_CODE_LENGTH];
256 GSupplicantPhy_mode phy_mode;
258 unsigned int wps_capabilities;
259 #if defined TIZEN_EXT
265 struct _GSupplicantNetwork {
266 GSupplicantInterface *interface;
270 unsigned char ssid[32];
271 unsigned int ssid_len;
273 dbus_uint16_t frequency;
274 struct g_supplicant_bss *best_bss;
275 GSupplicantMode mode;
276 GSupplicantSecurity security;
278 unsigned int wps_capabilities;
279 GHashTable *bss_table;
280 GHashTable *config_table;
281 #if defined TIZEN_EXT
286 unsigned int keymgmt;
288 unsigned char country_code[COUNTRY_CODE_LENGTH];
289 GSupplicantPhy_mode phy_mode;
293 struct _GSupplicantPeer {
294 GSupplicantInterface *interface;
296 unsigned char device_address[ETH_ALEN];
297 unsigned char iface_address[ETH_ALEN];
299 unsigned char *widi_ies;
302 unsigned int wps_capabilities;
304 const GSupplicantInterface *current_group_iface;
305 bool connection_requested;
308 struct _GSupplicantGroup {
309 GSupplicantInterface *interface;
310 GSupplicantInterface *orig_interface;
316 struct interface_data {
317 GSupplicantInterface *interface;
318 char *path; /* Interface path cannot be taken from interface (above) as
319 * it might have been freed already.
321 GSupplicantInterfaceCallback callback;
323 bool network_remove_in_progress;
324 GSupplicantSSID *ssid;
327 #if defined TIZEN_EXT
328 struct interface_signalpoll_data {
329 GSupplicantInterface *interface;
331 GSupplicantMaxSpeedCallback callback;
336 struct interface_create_data {
340 #if defined TIZEN_EXT_WIFI_MESH
342 bool is_mesh_interface;
344 GSupplicantInterface *interface;
345 GSupplicantInterfaceCallback callback;
349 struct interface_connect_data {
350 GSupplicantInterface *interface;
352 GSupplicantInterfaceCallback callback;
355 GSupplicantSSID *ssid;
356 GSupplicantPeerParams *peer;
360 struct interface_scan_data {
361 GSupplicantInterface *interface;
363 GSupplicantInterfaceCallback callback;
364 GSupplicantScanParams *scan_params;
368 #if defined TIZEN_EXT
369 struct g_connman_bssids {
370 unsigned char bssid[WIFI_BSSID_LEN_MAX];
376 static int network_remove(struct interface_data *data);
378 #if defined TIZEN_EXT_WIFI_MESH
379 struct _GSupplicantMeshPeer {
380 GSupplicantInterface *interface;
382 int disconnect_reason;
386 static inline void debug(const char *format, ...)
391 if (!callbacks_pointer || !callbacks_pointer->debug)
394 va_start(ap, format);
396 if (vsnprintf(str, sizeof(str), format, ap) > 0)
397 callbacks_pointer->debug(str);
402 #define SUPPLICANT_DBG(fmt, arg...) \
403 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
405 static GSupplicantMode string2mode(const char *mode)
408 return G_SUPPLICANT_MODE_UNKNOWN;
410 if (g_str_equal(mode, "infrastructure"))
411 return G_SUPPLICANT_MODE_INFRA;
412 else if (g_str_equal(mode, "ad-hoc"))
413 return G_SUPPLICANT_MODE_IBSS;
414 #if defined TIZEN_EXT_WIFI_MESH
415 else if (g_str_equal(mode, "mesh"))
416 return G_SUPPLICANT_MODE_MESH;
419 return G_SUPPLICANT_MODE_UNKNOWN;
422 static const char *mode2string(GSupplicantMode mode)
425 case G_SUPPLICANT_MODE_UNKNOWN:
427 case G_SUPPLICANT_MODE_INFRA:
429 case G_SUPPLICANT_MODE_IBSS:
431 case G_SUPPLICANT_MODE_MASTER:
433 #if defined TIZEN_EXT_WIFI_MESH
434 case G_SUPPLICANT_MODE_MESH:
442 static const char *security2string(GSupplicantSecurity security)
445 case G_SUPPLICANT_SECURITY_UNKNOWN:
447 case G_SUPPLICANT_SECURITY_NONE:
449 case G_SUPPLICANT_SECURITY_WEP:
451 case G_SUPPLICANT_SECURITY_PSK:
453 case G_SUPPLICANT_SECURITY_IEEE8021X:
455 #if defined TIZEN_EXT
456 case G_SUPPLICANT_SECURITY_FT_PSK:
458 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
459 return "ft_ieee8021x";
460 case G_SUPPLICANT_SECURITY_SAE:
462 case G_SUPPLICANT_SECURITY_OWE:
470 static GSupplicantState string2state(const char *state)
473 return G_SUPPLICANT_STATE_UNKNOWN;
475 if (g_str_equal(state, "unknown"))
476 return G_SUPPLICANT_STATE_UNKNOWN;
477 else if (g_str_equal(state, "interface_disabled"))
478 return G_SUPPLICANT_STATE_DISABLED;
479 else if (g_str_equal(state, "disconnected"))
480 return G_SUPPLICANT_STATE_DISCONNECTED;
481 else if (g_str_equal(state, "inactive"))
482 return G_SUPPLICANT_STATE_INACTIVE;
483 else if (g_str_equal(state, "scanning"))
484 return G_SUPPLICANT_STATE_SCANNING;
485 else if (g_str_equal(state, "authenticating"))
486 return G_SUPPLICANT_STATE_AUTHENTICATING;
487 else if (g_str_equal(state, "associating"))
488 return G_SUPPLICANT_STATE_ASSOCIATING;
489 else if (g_str_equal(state, "associated"))
490 return G_SUPPLICANT_STATE_ASSOCIATED;
491 else if (g_str_equal(state, "group_handshake"))
492 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
493 else if (g_str_equal(state, "4way_handshake"))
494 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
495 else if (g_str_equal(state, "completed"))
496 return G_SUPPLICANT_STATE_COMPLETED;
498 return G_SUPPLICANT_STATE_UNKNOWN;
501 static bool compare_network_parameters(GSupplicantInterface *interface,
502 GSupplicantSSID *ssid)
504 #if defined TIZEN_EXT
505 if (!interface->network_info.ssid)
509 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
512 if (interface->network_info.security != ssid->security)
515 if (interface->network_info.passphrase &&
516 g_strcmp0(interface->network_info.passphrase,
517 ssid->passphrase) != 0) {
521 if (interface->network_info.private_passphrase &&
522 g_strcmp0(interface->network_info.private_passphrase,
523 ssid->private_key_passphrase) != 0) {
530 static void remove_network_information(GSupplicantInterface * interface)
532 g_free(interface->network_info.ssid);
533 g_free(interface->network_info.passphrase);
534 g_free(interface->network_info.private_passphrase);
535 interface->network_info.ssid = NULL;
536 interface->network_info.passphrase = NULL;
537 interface->network_info.private_passphrase = NULL;
540 static int store_network_information(GSupplicantInterface * interface,
541 GSupplicantSSID *ssid)
543 interface->network_info.ssid = g_malloc(ssid->ssid_len + 1);
544 if (interface->network_info.ssid != NULL) {
545 memcpy(interface->network_info.ssid, ssid->ssid,
547 interface->network_info.ssid[ssid->ssid_len] = '\0';
552 interface->network_info.security = ssid->security;
554 if ((ssid->security == G_SUPPLICANT_SECURITY_WEP ||
555 ssid->security == G_SUPPLICANT_SECURITY_PSK ||
556 ssid->security == G_SUPPLICANT_SECURITY_NONE) &&
558 interface->network_info.passphrase = g_strdup(ssid->passphrase);
561 if (ssid->security == G_SUPPLICANT_SECURITY_IEEE8021X &&
562 ssid->private_key_passphrase) {
563 interface->network_info.private_passphrase =
564 g_strdup(ssid->private_key_passphrase);
570 static void callback_system_ready(void)
577 if (!callbacks_pointer)
580 if (!callbacks_pointer->system_ready)
583 callbacks_pointer->system_ready();
586 static void callback_system_killed(void)
588 system_ready = FALSE;
590 if (!callbacks_pointer)
593 if (!callbacks_pointer->system_killed)
596 callbacks_pointer->system_killed();
599 static void callback_interface_added(GSupplicantInterface *interface)
603 if (!callbacks_pointer)
606 if (!callbacks_pointer->interface_added)
609 callbacks_pointer->interface_added(interface);
612 static void callback_interface_state(GSupplicantInterface *interface)
614 if (!callbacks_pointer)
617 if (!callbacks_pointer->interface_state)
620 callbacks_pointer->interface_state(interface);
623 static void callback_interface_removed(GSupplicantInterface *interface)
625 if (!callbacks_pointer)
628 if (!callbacks_pointer->interface_removed)
631 callbacks_pointer->interface_removed(interface);
634 #if !defined TIZEN_EXT
635 static void callback_p2p_support(GSupplicantInterface *interface)
639 if (!interface->p2p_support)
642 if (callbacks_pointer && callbacks_pointer->p2p_support)
643 callbacks_pointer->p2p_support(interface);
647 #if defined TIZEN_EXT_WIFI_MESH
648 static void callback_mesh_support(GSupplicantInterface *interface)
652 if (!interface->mesh_support)
655 if (callbacks_pointer && callbacks_pointer->mesh_support)
656 callbacks_pointer->mesh_support(interface);
659 bool g_supplicant_interface_has_mesh(GSupplicantInterface *interface)
664 return interface->mesh_support;
668 static void callback_scan_started(GSupplicantInterface *interface)
670 if (!callbacks_pointer)
673 if (!callbacks_pointer->scan_started)
676 callbacks_pointer->scan_started(interface);
679 static void callback_ap_create_fail(GSupplicantInterface *interface)
681 if (!callbacks_pointer)
684 if (!callbacks_pointer->ap_create_fail)
687 callbacks_pointer->ap_create_fail(interface);
690 static void callback_scan_finished(GSupplicantInterface *interface)
692 if (!callbacks_pointer)
695 if (!callbacks_pointer->scan_finished)
698 callbacks_pointer->scan_finished(interface);
701 static void callback_network_added(GSupplicantNetwork *network)
703 if (!callbacks_pointer)
706 if (!callbacks_pointer->network_added)
709 callbacks_pointer->network_added(network);
712 static void callback_network_removed(GSupplicantNetwork *network)
714 if (!callbacks_pointer)
717 if (!callbacks_pointer->network_removed)
720 callbacks_pointer->network_removed(network);
723 #if defined TIZEN_EXT
724 static void callback_network_merged(GSupplicantNetwork *network)
726 if (!callbacks_pointer)
729 if (!callbacks_pointer->network_merged)
732 callbacks_pointer->network_merged(network);
735 static void callback_assoc_failed(void *user_data)
737 if (!callbacks_pointer)
740 if (!callbacks_pointer->assoc_failed)
743 callbacks_pointer->assoc_failed(user_data);
747 static void callback_network_changed(GSupplicantNetwork *network,
748 const char *property)
750 if (!callbacks_pointer)
753 if (!callbacks_pointer->network_changed)
756 callbacks_pointer->network_changed(network, property);
759 static void callback_network_associated(GSupplicantNetwork *network)
761 if (!callbacks_pointer)
764 if (!callbacks_pointer->network_associated)
767 callbacks_pointer->network_associated(network);
770 static void callback_sta_authorized(GSupplicantInterface *interface,
773 if (!callbacks_pointer)
776 if (!callbacks_pointer->sta_authorized)
779 callbacks_pointer->sta_authorized(interface, addr);
782 static void callback_sta_deauthorized(GSupplicantInterface *interface,
785 if (!callbacks_pointer)
788 if (!callbacks_pointer->sta_deauthorized)
791 callbacks_pointer->sta_deauthorized(interface, addr);
794 static void callback_peer_found(GSupplicantPeer *peer)
796 if (!callbacks_pointer)
799 if (!callbacks_pointer->peer_found)
802 callbacks_pointer->peer_found(peer);
805 static void callback_peer_lost(GSupplicantPeer *peer)
807 if (!callbacks_pointer)
810 if (!callbacks_pointer->peer_lost)
813 callbacks_pointer->peer_lost(peer);
816 static void callback_peer_changed(GSupplicantPeer *peer,
817 GSupplicantPeerState state)
819 if (!callbacks_pointer)
822 if (!callbacks_pointer->peer_changed)
825 callbacks_pointer->peer_changed(peer, state);
828 static void callback_peer_request(GSupplicantPeer *peer)
830 if (!callbacks_pointer)
833 if (!callbacks_pointer->peer_request)
836 peer->connection_requested = true;
838 callbacks_pointer->peer_request(peer);
841 static void callback_disconnect_reason_code(GSupplicantInterface *interface,
844 if (!callbacks_pointer)
847 if (!callbacks_pointer->disconnect_reasoncode)
850 if (reason_code != 0)
851 callbacks_pointer->disconnect_reasoncode(interface,
855 static void callback_assoc_status_code(GSupplicantInterface *interface,
858 if (!callbacks_pointer)
861 if (!callbacks_pointer->assoc_status_code)
864 callbacks_pointer->assoc_status_code(interface, status_code);
868 static void remove_group(gpointer data)
870 GSupplicantGroup *group = data;
873 g_slist_free_full(group->members, g_free);
879 static void remove_interface(gpointer data)
881 GSupplicantInterface *interface = data;
883 g_hash_table_destroy(interface->bss_mapping);
884 g_hash_table_destroy(interface->network_table);
885 g_hash_table_destroy(interface->peer_table);
886 g_hash_table_destroy(interface->group_table);
888 if (interface->scan_callback) {
889 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
890 interface, interface->scan_callback,
891 interface->scanning);
893 interface->scan_callback(-EIO, interface, interface->scan_data);
894 interface->scan_callback = NULL;
895 interface->scan_data = NULL;
897 if (interface->scanning) {
898 interface->scanning = FALSE;
899 callback_scan_finished(interface);
903 callback_interface_removed(interface);
905 g_free(interface->wps_cred.key);
906 g_free(interface->path);
907 g_free(interface->network_path);
908 #if defined TIZEN_EXT
909 interface->network_path = NULL;
911 g_free(interface->ifname);
912 g_free(interface->driver);
913 g_free(interface->bridge);
914 remove_network_information(interface);
918 static void remove_network(gpointer data)
920 GSupplicantNetwork *network = data;
922 g_hash_table_destroy(network->bss_table);
924 callback_network_removed(network);
926 g_hash_table_destroy(network->config_table);
928 g_free(network->path);
929 g_free(network->group);
930 g_free(network->name);
931 #if defined TIZEN_EXT
932 g_free(network->eap);
933 g_free(network->identity);
934 g_free(network->phase2);
936 #if defined TIZEN_EXT
937 g_slist_free_full(network->vsie_list, g_free);
943 static void remove_bss(gpointer data)
945 struct g_supplicant_bss *bss = data;
947 supplicant_dbus_property_call_cancel_all(bss);
950 #if defined TIZEN_EXT
951 g_slist_free_full(bss->vsie_list, g_free);
956 static void remove_peer(gpointer data)
958 GSupplicantPeer *peer = data;
960 callback_peer_lost(peer);
963 g_slist_free_full(peer->groups, g_free);
966 g_hash_table_remove(peer_mapping, peer->path);
968 if (pending_peer_connection)
969 g_hash_table_remove(pending_peer_connection, peer->path);
973 g_free(peer->identifier);
974 g_free(peer->widi_ies);
979 static void debug_strvalmap(const char *label, struct strvalmap *map,
984 for (i = 0; map[i].str; i++) {
985 if (val & map[i].val)
986 SUPPLICANT_DBG("%s: %s", label, map[i].str);
990 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
992 GSupplicantInterface *interface = user_data;
993 const char *str = NULL;
996 dbus_message_iter_get_basic(iter, &str);
1000 for (i = 0; keymgmt_map[i].str; i++)
1001 if (strcmp(str, keymgmt_map[i].str) == 0) {
1002 interface->keymgmt_capa |= keymgmt_map[i].val;
1007 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
1009 GSupplicantInterface *interface = user_data;
1010 const char *str = NULL;
1013 dbus_message_iter_get_basic(iter, &str);
1017 for (i = 0; authalg_capa_map[i].str; i++)
1018 if (strcmp(str, authalg_capa_map[i].str) == 0) {
1019 interface->authalg_capa |= authalg_capa_map[i].val;
1024 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
1026 GSupplicantInterface *interface = user_data;
1027 const char *str = NULL;
1030 dbus_message_iter_get_basic(iter, &str);
1034 for (i = 0; proto_capa_map[i].str; i++)
1035 if (strcmp(str, proto_capa_map[i].str) == 0) {
1036 interface->proto_capa |= proto_capa_map[i].val;
1041 static void interface_capability_pairwise(DBusMessageIter *iter,
1044 GSupplicantInterface *interface = user_data;
1045 const char *str = NULL;
1048 dbus_message_iter_get_basic(iter, &str);
1052 for (i = 0; pairwise_map[i].str; i++)
1053 if (strcmp(str, pairwise_map[i].str) == 0) {
1054 interface->pairwise_capa |= pairwise_map[i].val;
1059 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
1061 GSupplicantInterface *interface = user_data;
1062 const char *str = NULL;
1065 dbus_message_iter_get_basic(iter, &str);
1069 for (i = 0; group_map[i].str; i++)
1070 if (strcmp(str, group_map[i].str) == 0) {
1071 interface->group_capa |= group_map[i].val;
1076 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
1078 GSupplicantInterface *interface = user_data;
1079 const char *str = NULL;
1082 dbus_message_iter_get_basic(iter, &str);
1086 for (i = 0; scan_capa_map[i].str; i++)
1087 if (strcmp(str, scan_capa_map[i].str) == 0) {
1088 interface->scan_capa |= scan_capa_map[i].val;
1093 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
1095 GSupplicantInterface *interface = user_data;
1096 const char *str = NULL;
1099 dbus_message_iter_get_basic(iter, &str);
1103 for (i = 0; mode_capa_map[i].str; i++)
1104 if (strcmp(str, mode_capa_map[i].str) == 0) {
1105 interface->mode_capa |= mode_capa_map[i].val;
1110 static void interface_capability(const char *key, DBusMessageIter *iter,
1113 GSupplicantInterface *interface = user_data;
1118 if (g_strcmp0(key, "KeyMgmt") == 0)
1119 supplicant_dbus_array_foreach(iter,
1120 interface_capability_keymgmt, interface);
1121 else if (g_strcmp0(key, "AuthAlg") == 0)
1122 supplicant_dbus_array_foreach(iter,
1123 interface_capability_authalg, interface);
1124 else if (g_strcmp0(key, "Protocol") == 0)
1125 supplicant_dbus_array_foreach(iter,
1126 interface_capability_proto, interface);
1127 else if (g_strcmp0(key, "Pairwise") == 0)
1128 supplicant_dbus_array_foreach(iter,
1129 interface_capability_pairwise, interface);
1130 else if (g_strcmp0(key, "Group") == 0)
1131 supplicant_dbus_array_foreach(iter,
1132 interface_capability_group, interface);
1133 else if (g_strcmp0(key, "Scan") == 0)
1134 supplicant_dbus_array_foreach(iter,
1135 interface_capability_scan, interface);
1136 else if (g_strcmp0(key, "Modes") == 0)
1137 supplicant_dbus_array_foreach(iter,
1138 interface_capability_mode, interface);
1139 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
1140 dbus_int32_t max_scan_ssid;
1142 dbus_message_iter_get_basic(iter, &max_scan_ssid);
1143 if (max_scan_ssid < 2)
1145 interface->max_scan_ssids = max_scan_ssid;
1146 #if defined TIZEN_EXT
1147 } else if (g_strcmp0(key, "Is5GhzSupported") == 0) {
1148 dbus_bool_t is_5_0_Ghz_supported;
1150 dbus_message_iter_get_basic(iter, &is_5_0_Ghz_supported);
1151 interface->is_5_0_Ghz_supported = is_5_0_Ghz_supported;
1154 SUPPLICANT_DBG("key %s type %c",
1155 key, dbus_message_iter_get_arg_type(iter));
1158 struct set_apscan_data
1160 unsigned int ap_scan;
1161 GSupplicantInterface *interface;
1164 static void set_apscan(DBusMessageIter *iter, void *user_data)
1166 struct set_apscan_data *data = user_data;
1167 unsigned int ap_scan = data->ap_scan;
1169 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
1172 static void set_apscan_complete(const char *error,
1173 DBusMessageIter *iter, void *user_data)
1175 struct set_apscan_data *data = user_data;
1176 GSupplicantInterface *interface = data->interface;
1179 interface->ap_create_in_progress = false;
1180 SUPPLICANT_DBG("Set AP scan error %s", error);
1184 interface->ap_create_in_progress = true;
1189 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
1190 unsigned int ap_scan)
1192 struct set_apscan_data *data;
1195 data = dbus_malloc0(sizeof(*data));
1200 data->ap_scan = ap_scan;
1201 data->interface = interface;
1203 ret = supplicant_dbus_property_set(interface->path,
1204 SUPPLICANT_INTERFACE ".Interface",
1205 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
1206 set_apscan, set_apscan_complete, data, NULL);
1213 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
1219 interface->data = data;
1222 interface->scan_callback = NULL;
1225 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
1230 return interface->data;
1233 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
1238 return interface->ifname;
1241 #if defined TIZEN_EXT
1242 bool g_supplicant_interface_get_is_5_0_ghz_supported(GSupplicantInterface *interface)
1247 return interface->is_5_0_Ghz_supported;
1251 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
1256 return interface->driver;
1259 GSupplicantState g_supplicant_interface_get_state(
1260 GSupplicantInterface *interface)
1263 return G_SUPPLICANT_STATE_UNKNOWN;
1265 return interface->state;
1268 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
1273 return (const char *)interface->wps_cred.key;
1276 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
1277 unsigned int *ssid_len)
1282 if (!interface || interface->wps_cred.ssid_len == 0) {
1287 *ssid_len = interface->wps_cred.ssid_len;
1288 return interface->wps_cred.ssid;
1291 GSupplicantWpsState g_supplicant_interface_get_wps_state(
1292 GSupplicantInterface *interface)
1295 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
1297 return interface->wps_state;
1300 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
1305 return interface->mode_capa;
1308 unsigned int g_supplicant_interface_get_max_scan_ssids(
1309 GSupplicantInterface *interface)
1314 if (interface->max_scan_ssids == 0)
1315 return WPAS_MAX_SCAN_SSIDS;
1317 return interface->max_scan_ssids;
1320 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
1322 dbus_bool_t enable = *(dbus_bool_t *)user_data;
1324 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
1327 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
1333 if (!interface->network_path)
1336 SUPPLICANT_DBG(" ");
1337 return supplicant_dbus_property_set(interface->network_path,
1338 SUPPLICANT_INTERFACE ".Network",
1339 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
1340 set_network_enabled, NULL, &enable, NULL);
1343 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
1348 return interface->ready;
1351 GSupplicantInterface *g_supplicant_network_get_interface(
1352 GSupplicantNetwork *network)
1357 return network->interface;
1360 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
1362 if (!network || !network->name)
1365 return network->name;
1368 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
1370 if (!network || !network->group)
1373 return network->group;
1376 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1378 if (!network || !network->path)
1381 return network->path;
1384 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1387 return G_SUPPLICANT_MODE_UNKNOWN;
1389 return mode2string(network->mode);
1392 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1395 return G_SUPPLICANT_SECURITY_UNKNOWN;
1397 return security2string(network->security);
1400 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1401 unsigned int *ssid_len)
1408 *ssid_len = network->ssid_len;
1409 return network->ssid;
1412 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1417 return network->signal;
1420 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1425 return network->frequency;
1428 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1433 return network->wps;
1436 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1441 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1447 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1452 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1458 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1463 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1470 GSupplicantPhy_mode g_supplicant_network_get_phy_mode(GSupplicantNetwork *network)
1473 return G_SUPPLICANT_MODE_IEEE80211_UNKNOWN;
1475 return network->phy_mode;
1479 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1484 return peer->interface;
1487 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1495 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1500 return peer->identifier;
1503 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1508 return peer->device_address;
1511 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1516 return peer->iface_address;
1519 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1527 #if defined TIZEN_EXT
1528 bool g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1533 return network->isHS20AP;
1536 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1538 if (!network || !network->eap)
1541 return network->eap;
1544 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1546 if (!network || !network->identity)
1549 return network->identity;
1552 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1554 if (!network || !network->phase2)
1557 return network->phase2;
1560 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
1562 if (network == NULL)
1565 return network->keymgmt;
1568 const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
1574 return network->country_code;
1578 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1581 if (!peer || !length)
1584 *length = peer->widi_ies_length;
1585 return peer->widi_ies;
1588 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1593 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1599 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1604 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1610 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1612 if (!peer || !peer->groups)
1618 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1623 return (GSupplicantInterface *) peer->current_group_iface;
1626 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1628 GSupplicantGroup *group;
1634 for (list = peer->groups; list; list = list->next) {
1635 const char *path = list->data;
1637 group = g_hash_table_lookup(group_mapping, path);
1641 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1642 group->orig_interface != peer->interface)
1645 if (group->interface == peer->current_group_iface)
1652 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1657 return peer->connection_requested;
1660 #if defined TIZEN_EXT
1662 * Description: Network client requires additional wifi specific info
1664 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1666 if (network == NULL || network->best_bss == NULL)
1669 return (const unsigned char *)network->best_bss->bssid;
1672 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1674 if (network == NULL || network->best_bss == NULL)
1677 return network->best_bss->maxrate;
1680 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1682 if (network == NULL || network->best_bss == NULL)
1685 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1686 #if defined TIZEN_EXT
1687 network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1688 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1689 #endif /* TIZEN_EXT */
1690 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1691 unsigned int pairwise;
1693 pairwise = network->best_bss->rsn_pairwise |
1694 network->best_bss->wpa_pairwise;
1696 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1697 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1699 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1701 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1704 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1706 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1712 bool g_supplicant_network_get_rsn_mode(GSupplicantNetwork *network)
1714 if (network == NULL || network->best_bss == NULL)
1717 #if defined TIZEN_EXT
1718 if (network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1719 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE)
1721 #endif /* TIZEN_EXT */
1723 if (network->best_bss->rsn_selected) {
1724 const char *mode = g_supplicant_network_get_enc_mode(network);
1725 if (g_strcmp0(mode, "aes") == 0 ||
1726 g_strcmp0(mode, "mixed") == 0)
1734 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
1736 GSList *vsie_list = NULL;
1741 if (g_slist_length(network->vsie_list) > 0) {
1742 GSList *list = NULL;
1743 unsigned char *vsie = NULL;
1744 for (list = network->vsie_list; list; list = list->next) {
1745 unsigned char *ie = (unsigned char *)list->data;
1748 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
1751 memcpy(vsie, ie, ie[1]+2);
1752 vsie_list = g_slist_append(vsie_list, vsie);
1754 SUPPLICANT_DBG("Failed to allocate memory");
1761 static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
1763 struct g_supplicant_bss *bss = value;
1764 struct g_connman_bssids *bssids = NULL;
1765 GSList **list = (GSList **)user_data;
1767 bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
1770 memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
1772 bssids->strength = bss->signal;
1773 bssids->strength += 120;
1775 if (bssids->strength > 100)
1776 bssids->strength = 100;
1778 bssids->frequency = bss->frequency;
1779 *list = g_slist_append(*list, bssids);
1781 SUPPLICANT_DBG("Failed to allocate memory");
1784 static gint cmp_bss(gconstpointer a, gconstpointer b)
1786 struct g_connman_bssids *entry_a = (struct g_connman_bssids *)a;
1787 struct g_connman_bssids *entry_b = (struct g_connman_bssids *)b;
1789 if (entry_a->strength > entry_b->strength)
1792 if (entry_a->strength < entry_b->strength)
1798 void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network)
1800 GSList *bssid_list = NULL;
1802 if (g_hash_table_size(network->bss_table) < 1)
1805 g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_list);
1806 bssid_list = g_slist_sort(bssid_list, cmp_bss);
1812 static void merge_network(GSupplicantNetwork *network)
1815 const char *ssid, *mode, *key_mgmt;
1816 #if defined TIZEN_EXT
1817 const char *isHS20AP;
1818 const char *eap, *identity, *phase2;
1820 unsigned int i, ssid_len;
1823 ssid = g_hash_table_lookup(network->config_table, "ssid");
1824 mode = g_hash_table_lookup(network->config_table, "mode");
1825 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
1826 #if defined TIZEN_EXT
1827 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
1828 eap = g_hash_table_lookup(network->config_table, "eap");
1829 identity = g_hash_table_lookup(network->config_table, "identity");
1830 phase2 = g_hash_table_lookup(network->config_table, "phase2");
1833 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
1836 ssid_len = strlen(ssid);
1840 str = g_string_sized_new((ssid_len * 2) + 24);
1844 for (i = 0; i < ssid_len; i++)
1845 #if defined TIZEN_EXT
1849 g_string_append_printf(str, "%02x", ssid[i]);
1850 #if defined TIZEN_EXT
1854 if (g_strcmp0(mode, "0") == 0)
1855 g_string_append_printf(str, "_managed");
1856 else if (g_strcmp0(mode, "1") == 0)
1857 g_string_append_printf(str, "_adhoc");
1858 #if defined TIZEN_EXT_WIFI_MESH
1859 else if (g_strcmp0(mode, "5") == 0)
1860 g_string_append_printf(str, "_mesh");
1863 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
1864 g_string_append_printf(str, "_psk");
1865 #if defined TIZEN_EXT
1866 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
1867 g_string_append_printf(str, "_ieee8021x");
1869 g_string_append_printf(str, "_none");
1872 group = g_string_free(str, FALSE);
1874 SUPPLICANT_DBG("%s", group);
1876 #if defined TIZEN_EXT
1877 if (g_strcmp0(isHS20AP, "1") == 0) {
1878 network->isHS20AP = 1;
1880 g_free(network->eap);
1881 network->eap = g_strdup(eap);
1883 if (network->identity)
1884 g_free(network->identity);
1885 network->identity = g_strdup(identity);
1887 if (network->phase2)
1888 g_free(network->phase2);
1889 network->phase2 = g_strdup(phase2);
1891 network->isHS20AP = 0;
1893 network->group = g_strdup(group);
1894 callback_network_merged(network);
1895 g_free(network->group);
1900 g_hash_table_destroy(network->config_table);
1902 g_free(network->path);
1906 static void network_property(const char *key, DBusMessageIter *iter,
1909 GSupplicantNetwork *network = user_data;
1911 if (!network->interface)
1915 merge_network(network);
1919 if (g_strcmp0(key, "Enabled") == 0) {
1920 dbus_bool_t enabled = FALSE;
1922 dbus_message_iter_get_basic(iter, &enabled);
1923 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
1924 const char *str = NULL;
1926 dbus_message_iter_get_basic(iter, &str);
1928 g_hash_table_replace(network->config_table,
1929 g_strdup(key), g_strdup(str));
1932 SUPPLICANT_DBG("key %s type %c",
1933 key, dbus_message_iter_get_arg_type(iter));
1936 static void interface_network_added(DBusMessageIter *iter, void *user_data)
1938 GSupplicantInterface *interface = user_data;
1939 GSupplicantNetwork *network;
1940 const char *path = NULL;
1944 dbus_message_iter_get_basic(iter, &path);
1948 if (g_strcmp0(path, "/") == 0)
1951 network = g_try_new0(GSupplicantNetwork, 1);
1955 network->interface = interface;
1956 network->path = g_strdup(path);
1958 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1961 dbus_message_iter_next(iter);
1962 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
1963 supplicant_dbus_property_foreach(iter, network_property,
1965 network_property(NULL, NULL, network);
1969 supplicant_dbus_property_get_all(path,
1970 SUPPLICANT_INTERFACE ".Network",
1971 network_property, network, NULL);
1974 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
1979 static char *create_name(unsigned char *ssid, int ssid_len)
1982 const gchar *remainder, *invalid;
1983 int valid_bytes, remaining_bytes;
1985 if (ssid_len < 1 || ssid[0] == '\0')
1986 return g_strdup("");
1989 remainder = (const gchar *)ssid;
1990 remaining_bytes = ssid_len;
1992 while (remaining_bytes != 0) {
1993 if (g_utf8_validate(remainder, remaining_bytes,
1998 valid_bytes = invalid - remainder;
2001 string = g_string_sized_new(remaining_bytes);
2003 g_string_append_len(string, remainder, valid_bytes);
2005 /* append U+FFFD REPLACEMENT CHARACTER */
2006 g_string_append(string, "\357\277\275");
2008 remaining_bytes -= valid_bytes + 1;
2009 remainder = invalid + 1;
2013 return g_strndup((const gchar *)ssid, ssid_len + 1);
2015 g_string_append(string, remainder);
2017 return g_string_free(string, FALSE);
2020 static char *create_group(struct g_supplicant_bss *bss)
2024 const char *mode, *security;
2026 str = g_string_sized_new((bss->ssid_len * 2) + 24);
2030 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
2031 for (i = 0; i < bss->ssid_len; i++)
2032 g_string_append_printf(str, "%02x", bss->ssid[i]);
2034 g_string_append_printf(str, "hidden");
2036 mode = mode2string(bss->mode);
2038 g_string_append_printf(str, "_%s", mode);
2040 security = security2string(bss->security);
2042 g_string_append_printf(str, "_%s", security);
2044 return g_string_free(str, FALSE);
2047 static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
2049 GSupplicantInterface *interface = bss->interface;
2050 GSupplicantNetwork *network;
2052 bool is_new_network;
2054 group = create_group(bss);
2055 SUPPLICANT_DBG("New group created: %s", group);
2060 network = g_hash_table_lookup(interface->network_table, group);
2063 SUPPLICANT_DBG("Network %s already exist", network->name);
2064 is_new_network = false;
2069 is_new_network = true;
2071 network = g_try_new0(GSupplicantNetwork, 1);
2077 network->interface = interface;
2079 network->path = g_strdup(bss->path);
2080 network->group = group;
2081 network->name = create_name(bss->ssid, bss->ssid_len);
2082 network->mode = bss->mode;
2083 network->security = bss->security;
2084 network->ssid_len = bss->ssid_len;
2085 memcpy(network->ssid, bss->ssid, bss->ssid_len);
2086 network->signal = bss->signal;
2087 network->frequency = bss->frequency;
2088 network->best_bss = bss;
2090 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2091 network->wps = TRUE;
2092 network->wps_capabilities = bss->wps_capabilities;
2095 #if defined TIZEN_EXT
2096 network->keymgmt = bss->keymgmt;
2098 if (g_slist_length(bss->vsie_list) > 0) {
2099 GSList *list = NULL;
2100 unsigned char *vsie = NULL;
2101 for (list = bss->vsie_list; list; list = list->next) {
2102 unsigned char *ie = (unsigned char *)list->data;
2103 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2106 memcpy(vsie, ie, ie[1]+2);
2107 network->vsie_list = g_slist_append(network->vsie_list, vsie);
2109 SUPPLICANT_DBG("Failed to allocate memory.");
2113 network->isHS20AP = bss->hs20;
2114 memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
2115 network->phy_mode = bss->phy_mode;
2118 SUPPLICANT_DBG("New network %s created", network->name);
2120 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2123 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2126 g_hash_table_replace(interface->network_table,
2127 network->group, network);
2129 callback_network_added(network);
2132 /* We update network's WPS properties if only bss provides WPS. */
2133 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2134 network->wps = TRUE;
2135 network->wps_capabilities = bss->wps_capabilities;
2137 if (!is_new_network)
2138 callback_network_changed(network, "WPSCapabilities");
2142 * Do not change best BSS if we are connected. It will be done through
2143 * CurrentBSS property in case of misalignment with wpa_s or roaming.
2145 if (network != interface->current_network &&
2146 bss->signal > network->signal) {
2147 network->signal = bss->signal;
2148 network->best_bss = bss;
2149 callback_network_changed(network, "Signal");
2152 g_hash_table_replace(interface->bss_mapping, bss->path, network);
2153 g_hash_table_replace(network->bss_table, bss->path, bss);
2155 g_hash_table_replace(bss_mapping, bss->path, interface);
2160 static void bss_rates(DBusMessageIter *iter, void *user_data)
2162 struct g_supplicant_bss *bss = user_data;
2163 dbus_uint32_t rate = 0;
2165 dbus_message_iter_get_basic(iter, &rate);
2169 if (rate > bss->maxrate)
2170 bss->maxrate = rate;
2173 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
2175 unsigned int *keymgmt = user_data;
2176 const char *str = NULL;
2179 dbus_message_iter_get_basic(iter, &str);
2183 for (i = 0; keymgmt_map[i].str; i++)
2184 if (strcmp(str, keymgmt_map[i].str) == 0) {
2185 SUPPLICANT_DBG("Keymgmt: %s", str);
2186 *keymgmt |= keymgmt_map[i].val;
2191 static void bss_group(DBusMessageIter *iter, void *user_data)
2193 unsigned int *group = user_data;
2194 const char *str = NULL;
2197 dbus_message_iter_get_basic(iter, &str);
2201 for (i = 0; group_map[i].str; i++)
2202 if (strcmp(str, group_map[i].str) == 0) {
2203 SUPPLICANT_DBG("Group: %s", str);
2204 *group |= group_map[i].val;
2209 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
2211 unsigned int *pairwise = user_data;
2212 const char *str = NULL;
2215 dbus_message_iter_get_basic(iter, &str);
2219 for (i = 0; pairwise_map[i].str; i++)
2220 if (strcmp(str, pairwise_map[i].str) == 0) {
2221 SUPPLICANT_DBG("Pairwise: %s", str);
2222 *pairwise |= pairwise_map[i].val;
2227 static void bss_wpa(const char *key, DBusMessageIter *iter,
2230 struct g_supplicant_bss *bss = user_data;
2231 unsigned int value = 0;
2233 SUPPLICANT_DBG("Key: %s", key);
2235 if (g_strcmp0(key, "KeyMgmt") == 0) {
2236 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
2238 if (bss->rsn_selected)
2239 bss->rsn_keymgmt = value;
2241 bss->wpa_keymgmt = value;
2242 } else if (g_strcmp0(key, "Group") == 0) {
2243 supplicant_dbus_array_foreach(iter, bss_group, &value);
2245 if (bss->rsn_selected)
2246 bss->rsn_group = value;
2248 bss->wpa_group = value;
2249 } else if (g_strcmp0(key, "Pairwise") == 0) {
2250 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
2252 if (bss->rsn_selected)
2253 bss->rsn_pairwise = value;
2255 bss->wpa_pairwise = value;
2259 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
2262 unsigned int len = 0;
2264 while (len + 4 < ie_size) {
2265 unsigned int hi = ie[len];
2266 unsigned int lo = ie[len + 1];
2267 unsigned int tmp_type = (hi << 8) + lo;
2268 unsigned int v_len = 0;
2270 /* hi and lo are used to recreate an unsigned int
2271 * based on 2 8bits length unsigned int. */
2275 v_len = (hi << 8) + lo;
2277 if (tmp_type == type) {
2278 unsigned int ret_value = 0;
2279 unsigned char *value = (unsigned char *)&ret_value;
2281 SUPPLICANT_DBG("IE: match type 0x%x", type);
2283 /* Verifying length relevance */
2284 if (v_len > sizeof(unsigned int) ||
2285 len + 4 + v_len > ie_size)
2288 memcpy(value, ie + len + 4, v_len);
2290 SUPPLICANT_DBG("returning 0x%x", ret_value);
2297 SUPPLICANT_DBG("returning 0");
2301 #if defined TIZEN_EXT
2302 static void get_bss_phy_mode(unsigned int max_rate,
2303 unsigned int max_ext_rate, bool ht, bool vht, void *data)
2305 struct g_supplicant_bss *bss = data;
2306 unsigned int freq = bss->frequency;
2308 /* Following conditions are used to determine
2309 * IEEE 802.11 Protocol Modes:-
2311 * 1. If “Supported rates” is only till 11 Mbps,
2312 * and frequency is in 2.4GHz band, then protocol is 11B.
2313 * 2. If “Supported rates” is till 54Mbps or
2314 * “Extended supported rates” are present,
2315 * and frequency is in 2.4GHz band, then protocol is 11G.
2316 * 3. If “Supported rates” is only till 54 Mbps,
2317 * frequency is in 5GHz band , then protocol is 11A.
2318 * 4. If “HT capabilities” is supported , then protocol is 11N.
2319 * 5. If “HT capabilities” & “VHT” is supported and
2320 * frequency is in 5 GHz band, then protocol is 11AC.
2323 if (freq >= 2412 && freq <= 2484) { /* 2.4 Ghz Band */
2324 if (max_rate <= 11 && max_ext_rate <= 0 && !ht)
2325 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211B;
2326 else if ((max_rate <= 54 || max_ext_rate > 0) && !ht)
2327 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BG;
2328 else if ((max_rate >= 54 || max_ext_rate > 0) && ht)
2329 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BGN;
2331 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2332 } else if (freq >= 5180 && freq <= 5825) { /* 5 Ghz Band */
2333 if (max_rate <= 54 && !ht)
2334 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211A;
2335 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && !vht)
2336 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211AN;
2337 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && vht)
2338 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211ANAC;
2340 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2345 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
2347 struct g_supplicant_bss *bss = user_data;
2348 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
2349 unsigned char *ie, *ie_end;
2350 DBusMessageIter array;
2353 #if defined TIZEN_EXT
2355 unsigned char *rates = NULL;
2356 unsigned char *ext_rates = NULL;
2357 unsigned int max_rate = 0;
2358 unsigned int max_ext_rate = 0;
2363 #define WMM_WPA1_WPS_INFO 221
2364 #define WPS_INFO_MIN_LEN 6
2365 #define WPS_VERSION_TLV 0x104A
2366 #define WPS_STATE_TLV 0x1044
2367 #define WPS_METHODS_TLV 0x1012
2368 #define WPS_REGISTRAR_TLV 0x1041
2369 #define WPS_VERSION 0x10
2370 #define WPS_PBC 0x04
2371 #define WPS_PIN 0x00
2372 #define WPS_CONFIGURED 0x02
2373 #if defined TIZEN_EXT
2374 #define VENDOR_SPECIFIC_INFO 0xDD
2375 #define WLAN_EID_COUNTRY 7
2378 dbus_message_iter_recurse(iter, &array);
2379 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
2381 if (!ie || ie_len < 2)
2384 bss->wps_capabilities = 0;
2387 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
2389 #if defined TIZEN_EXT
2390 unsigned char *vsie;
2392 if(ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
2393 SUPPLICANT_DBG("IE: match vendor specific data");
2395 vsie_len = ie[1]+2; // tag number size(1), tag length size(1)
2396 vsie = (unsigned char *)g_try_malloc0(vsie_len);
2399 memcpy(vsie, ie, vsie_len);
2400 bss->vsie_list = g_slist_append(bss->vsie_list, vsie);
2402 SUPPLICANT_DBG("Failed to allocate memory");
2406 if(ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
2407 /* Add country code only if it is a valid alphabet */
2408 if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
2409 memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
2414 if (ie[0] == WLAN_EID_HT_CAP && ie[1]) {
2419 if (ie[0] == WLAN_EID_VHT_CAP && ie[1]) {
2424 if (ie[0] == WLAN_EID_SUPP_RATES && ie[1]) {
2426 rates = g_malloc0(r_len);
2430 for (j = 0; ie && j < r_len; j++) {
2431 rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
2432 if (max_rate < rates[j])
2433 max_rate = rates[j];
2438 if (ie[0] == WLAN_EID_EXT_SUPP_RATES && ie[1] > 0) {
2440 ext_rates = g_malloc0(r_len);
2444 for (j = 0; ie && j < r_len; j++) {
2445 ext_rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
2446 if (max_ext_rate < ext_rates[j])
2447 max_ext_rate = ext_rates[j];
2452 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
2453 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
2456 SUPPLICANT_DBG("IE: match WPS_OUI");
2458 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
2459 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
2461 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
2463 if (value == WPS_CONFIGURED)
2464 bss->wps_capabilities |=
2465 G_SUPPLICANT_WPS_CONFIGURED;
2468 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
2470 if (GUINT16_FROM_BE(value) == WPS_PBC)
2471 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
2472 if (GUINT16_FROM_BE(value) == WPS_PIN)
2473 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
2475 bss->wps_capabilities |=
2476 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
2478 /* If the AP sends this it means it's advertizing
2479 * as a registrar and the WPS process is launched
2481 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
2482 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
2484 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
2487 get_bss_phy_mode(max_rate, max_ext_rate, ht, vht, user_data);
2495 static void bss_compute_security(struct g_supplicant_bss *bss)
2498 * Combining RSN and WPA keymgmt
2499 * We combine it since parsing IEs might have set something for WPS. */
2500 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
2502 bss->ieee8021x = FALSE;
2504 #if defined TIZEN_EXT
2505 bss->ft_ieee8021x = FALSE;
2506 bss->ft_psk = FALSE;
2509 #if defined TIZEN_EXT
2511 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
2512 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
2513 bss->ieee8021x = TRUE;
2514 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
2515 bss->ft_ieee8021x = TRUE;
2518 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
2519 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
2520 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
2521 bss->ieee8021x = TRUE;
2524 #if defined TIZEN_EXT
2526 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
2527 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
2529 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
2533 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
2534 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
2535 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
2539 #if defined TIZEN_EXT
2540 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
2542 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_OWE)
2547 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
2549 bss->security = G_SUPPLICANT_SECURITY_PSK;
2550 #if defined TIZEN_EXT
2551 else if (bss->ft_psk)
2552 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
2553 else if (bss->ft_ieee8021x == TRUE)
2554 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
2556 bss->security = G_SUPPLICANT_SECURITY_SAE;
2558 bss->security = G_SUPPLICANT_SECURITY_OWE;
2560 else if (bss->privacy)
2561 bss->security = G_SUPPLICANT_SECURITY_WEP;
2563 bss->security = G_SUPPLICANT_SECURITY_NONE;
2567 static void bss_property(const char *key, DBusMessageIter *iter,
2570 struct g_supplicant_bss *bss = user_data;
2572 if (!bss->interface)
2575 SUPPLICANT_DBG("key %s", key);
2580 if (g_strcmp0(key, "BSSID") == 0) {
2581 DBusMessageIter array;
2582 unsigned char *addr;
2585 dbus_message_iter_recurse(iter, &array);
2586 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
2589 memcpy(bss->bssid, addr, addr_len);
2590 } else if (g_strcmp0(key, "SSID") == 0) {
2591 DBusMessageIter array;
2592 unsigned char *ssid;
2595 dbus_message_iter_recurse(iter, &array);
2596 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
2598 if (ssid_len > 0 && ssid_len < 33) {
2599 memcpy(bss->ssid, ssid, ssid_len);
2600 bss->ssid_len = ssid_len;
2602 memset(bss->ssid, 0, sizeof(bss->ssid));
2605 } else if (g_strcmp0(key, "Capabilities") == 0) {
2606 dbus_uint16_t capabilities = 0x0000;
2608 dbus_message_iter_get_basic(iter, &capabilities);
2610 if (capabilities & IEEE80211_CAP_ESS)
2611 bss->mode = G_SUPPLICANT_MODE_INFRA;
2612 else if (capabilities & IEEE80211_CAP_IBSS)
2613 bss->mode = G_SUPPLICANT_MODE_IBSS;
2615 if (capabilities & IEEE80211_CAP_PRIVACY)
2616 bss->privacy = TRUE;
2617 } else if (g_strcmp0(key, "Mode") == 0) {
2618 const char *mode = NULL;
2620 dbus_message_iter_get_basic(iter, &mode);
2621 bss->mode = string2mode(mode);
2622 } else if (g_strcmp0(key, "Frequency") == 0) {
2623 dbus_uint16_t frequency = 0;
2625 dbus_message_iter_get_basic(iter, &frequency);
2626 bss->frequency = frequency;
2627 } else if (g_strcmp0(key, "Signal") == 0) {
2628 dbus_int16_t signal = 0;
2630 dbus_message_iter_get_basic(iter, &signal);
2632 bss->signal = signal;
2634 bss->signal = BSS_UNKNOWN_STRENGTH;
2636 } else if (g_strcmp0(key, "Level") == 0) {
2637 dbus_int32_t level = 0;
2639 dbus_message_iter_get_basic(iter, &level);
2640 } else if (g_strcmp0(key, "Rates") == 0) {
2641 supplicant_dbus_array_foreach(iter, bss_rates, bss);
2642 } else if (g_strcmp0(key, "MaxRate") == 0) {
2643 dbus_uint32_t maxrate = 0;
2645 dbus_message_iter_get_basic(iter, &maxrate);
2647 bss->maxrate = maxrate;
2648 } else if (g_strcmp0(key, "Privacy") == 0) {
2649 dbus_bool_t privacy = FALSE;
2651 dbus_message_iter_get_basic(iter, &privacy);
2652 bss->privacy = privacy;
2653 } else if (g_strcmp0(key, "RSN") == 0) {
2654 bss->rsn_selected = TRUE;
2656 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
2657 } else if (g_strcmp0(key, "WPA") == 0) {
2658 bss->rsn_selected = FALSE;
2660 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
2661 #if defined TIZEN_EXT
2662 } else if (g_strcmp0(key, "HS20") == 0) {
2663 dbus_bool_t hs20 = FALSE;
2664 dbus_message_iter_get_basic(iter, &hs20);
2667 } else if (g_strcmp0(key, "IEs") == 0)
2668 bss_process_ies(iter, bss);
2670 SUPPLICANT_DBG("key %s type %c",
2671 key, dbus_message_iter_get_arg_type(iter));
2674 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
2677 GSupplicantInterface *interface = user_data;
2678 GSupplicantNetwork *network;
2679 struct g_supplicant_bss *bss;
2680 const char *path = NULL;
2684 dbus_message_iter_get_basic(iter, &path);
2688 if (g_strcmp0(path, "/") == 0)
2691 SUPPLICANT_DBG("%s", path);
2693 network = g_hash_table_lookup(interface->bss_mapping, path);
2695 bss = g_hash_table_lookup(network->bss_table, path);
2700 bss = g_try_new0(struct g_supplicant_bss, 1);
2704 bss->interface = interface;
2705 bss->path = g_strdup(path);
2706 bss->signal = BSS_UNKNOWN_STRENGTH;
2711 static void interface_bss_added_with_keys(DBusMessageIter *iter,
2714 struct g_supplicant_bss *bss;
2718 bss = interface_bss_added(iter, user_data);
2722 dbus_message_iter_next(iter);
2724 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
2727 supplicant_dbus_property_foreach(iter, bss_property, bss);
2729 bss_compute_security(bss);
2730 if (add_or_replace_bss_to_network(bss) < 0)
2731 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
2734 static void interface_bss_added_without_keys(DBusMessageIter *iter,
2737 struct g_supplicant_bss *bss;
2741 bss = interface_bss_added(iter, user_data);
2745 supplicant_dbus_property_get_all(bss->path,
2746 SUPPLICANT_INTERFACE ".BSS",
2747 bss_property, bss, bss);
2749 bss_compute_security(bss);
2750 if (add_or_replace_bss_to_network(bss) < 0)
2751 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
2754 static void update_signal(gpointer key, gpointer value,
2757 struct g_supplicant_bss *bss = value;
2758 GSupplicantNetwork *network = user_data;
2760 if (bss->signal > network->signal) {
2761 network->signal = bss->signal;
2762 network->best_bss = bss;
2766 static void update_network_signal(GSupplicantNetwork *network)
2768 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
2771 g_hash_table_foreach(network->bss_table,
2772 update_signal, network);
2774 SUPPLICANT_DBG("New network signal %d", network->signal);
2777 static void interface_current_bss(GSupplicantInterface *interface,
2778 DBusMessageIter *iter)
2780 GSupplicantNetwork *network;
2781 struct g_supplicant_bss *bss;
2784 dbus_message_iter_get_basic(iter, &path);
2785 if (g_strcmp0(path, "/") == 0) {
2786 interface->current_network = NULL;
2790 interface_bss_added_without_keys(iter, interface);
2792 network = g_hash_table_lookup(interface->bss_mapping, path);
2796 bss = g_hash_table_lookup(network->bss_table, path);
2800 interface->current_network = network;
2802 if (bss != network->best_bss) {
2804 * This is the case where either wpa_s got associated
2805 * to a BSS different than the one ConnMan considers
2806 * the best, or we are roaming.
2808 SUPPLICANT_DBG("Update best BSS for %s", network->name);
2810 network->best_bss = bss;
2812 if (network->signal != bss->signal) {
2813 SUPPLICANT_DBG("New network signal %d dBm",
2816 network->signal = bss->signal;
2817 callback_network_changed(network, "Signal");
2822 * wpa_s could notify about CurrentBSS in any state once
2823 * it got associated. It is not sure such notification will
2824 * arrive together with transition to ASSOCIATED state.
2825 * In fact, for networks with security WEP or OPEN, it
2826 * always arrives together with transition to COMPLETED.
2828 switch (interface->state) {
2829 case G_SUPPLICANT_STATE_UNKNOWN:
2830 case G_SUPPLICANT_STATE_DISABLED:
2831 case G_SUPPLICANT_STATE_DISCONNECTED:
2832 case G_SUPPLICANT_STATE_INACTIVE:
2833 case G_SUPPLICANT_STATE_SCANNING:
2834 case G_SUPPLICANT_STATE_AUTHENTICATING:
2835 case G_SUPPLICANT_STATE_ASSOCIATING:
2837 case G_SUPPLICANT_STATE_ASSOCIATED:
2838 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
2839 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
2840 case G_SUPPLICANT_STATE_COMPLETED:
2841 callback_network_associated(network);
2846 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
2848 GSupplicantInterface *interface = user_data;
2849 GSupplicantNetwork *network;
2850 struct g_supplicant_bss *bss = NULL;
2851 const char *path = NULL;
2852 bool is_current_network_bss = false;
2854 dbus_message_iter_get_basic(iter, &path);
2858 network = g_hash_table_lookup(interface->bss_mapping, path);
2862 bss = g_hash_table_lookup(network->bss_table, path);
2863 if (network->best_bss == bss) {
2864 network->best_bss = NULL;
2865 network->signal = BSS_UNKNOWN_STRENGTH;
2866 is_current_network_bss = true;
2869 g_hash_table_remove(bss_mapping, path);
2871 g_hash_table_remove(interface->bss_mapping, path);
2872 g_hash_table_remove(network->bss_table, path);
2874 update_network_signal(network);
2876 if (g_hash_table_size(network->bss_table) == 0) {
2877 g_hash_table_remove(interface->network_table, network->group);
2879 if (is_current_network_bss && network->best_bss)
2880 #if defined TIZEN_EXT
2881 callback_network_changed(network, "CheckMultiBssidConnect");
2883 callback_network_changed(network, "");
2888 static void set_config_methods(DBusMessageIter *iter, void *user_data)
2890 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
2893 static void wps_property(const char *key, DBusMessageIter *iter,
2896 GSupplicantInterface *interface = user_data;
2901 SUPPLICANT_DBG("key: %s", key);
2903 if (g_strcmp0(key, "ConfigMethods") == 0) {
2904 const char *config_methods = "push_button", *str = NULL;
2906 dbus_message_iter_get_basic(iter, &str);
2907 if (str && strlen(str) > 0) {
2908 /* It was already set at wpa_s level, don't modify it. */
2909 SUPPLICANT_DBG("%s", str);
2913 supplicant_dbus_property_set(interface->path,
2914 SUPPLICANT_INTERFACE ".Interface.WPS",
2915 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
2916 set_config_methods, NULL, &config_methods, NULL);
2918 SUPPLICANT_DBG("No value. Set %s", config_methods);
2923 static void interface_property(const char *key, DBusMessageIter *iter,
2926 GSupplicantInterface *interface = user_data;
2931 SUPPLICANT_DBG("%s", key);
2934 debug_strvalmap("KeyMgmt capability", keymgmt_map,
2935 interface->keymgmt_capa);
2936 debug_strvalmap("AuthAlg capability", authalg_capa_map,
2937 interface->authalg_capa);
2938 debug_strvalmap("Protocol capability", proto_capa_map,
2939 interface->proto_capa);
2940 debug_strvalmap("Pairwise capability", pairwise_map,
2941 interface->pairwise_capa);
2942 debug_strvalmap("Group capability", group_map,
2943 interface->group_capa);
2944 debug_strvalmap("Scan capability", scan_capa_map,
2945 interface->scan_capa);
2946 debug_strvalmap("Mode capability", mode_capa_map,
2947 interface->mode_capa);
2949 supplicant_dbus_property_get_all(interface->path,
2950 SUPPLICANT_INTERFACE ".Interface.WPS",
2951 wps_property, interface, interface);
2953 if (interface->ready)
2954 callback_interface_added(interface);
2959 if (g_strcmp0(key, "Capabilities") == 0) {
2960 supplicant_dbus_property_foreach(iter, interface_capability,
2962 #if !defined TIZEN_EXT
2963 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
2964 interface->p2p_support = true;
2966 #if defined TIZEN_EXT_WIFI_MESH
2967 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_MESH)
2968 interface->mesh_support = true;
2970 } else if (g_strcmp0(key, "State") == 0) {
2971 const char *str = NULL;
2973 dbus_message_iter_get_basic(iter, &str);
2975 if (string2state(str) != interface->state) {
2976 interface->state = string2state(str);
2977 callback_interface_state(interface);
2980 if (interface->ap_create_in_progress) {
2981 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
2982 callback_ap_create_fail(interface);
2984 interface->ap_create_in_progress = false;
2987 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
2988 interface->ready = FALSE;
2990 interface->ready = TRUE;
2992 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
2993 } else if (g_strcmp0(key, "Scanning") == 0) {
2994 dbus_bool_t scanning = FALSE;
2996 dbus_message_iter_get_basic(iter, &scanning);
2997 interface->scanning = scanning;
2999 if (interface->ready) {
3000 if (interface->scanning)
3001 callback_scan_started(interface);
3003 callback_scan_finished(interface);
3005 } else if (g_strcmp0(key, "ApScan") == 0) {
3008 dbus_message_iter_get_basic(iter, &apscan);
3009 interface->apscan = apscan;
3010 } else if (g_strcmp0(key, "Ifname") == 0) {
3011 const char *str = NULL;
3013 dbus_message_iter_get_basic(iter, &str);
3015 g_free(interface->ifname);
3016 interface->ifname = g_strdup(str);
3018 } else if (g_strcmp0(key, "Driver") == 0) {
3019 const char *str = NULL;
3021 dbus_message_iter_get_basic(iter, &str);
3023 g_free(interface->driver);
3024 interface->driver = g_strdup(str);
3026 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
3027 const char *str = NULL;
3029 dbus_message_iter_get_basic(iter, &str);
3031 g_free(interface->bridge);
3032 interface->bridge = g_strdup(str);
3034 } else if (g_strcmp0(key, "ConfigFile") == 0) {
3035 const char *str = NULL;
3037 dbus_message_iter_get_basic(iter, &str);
3038 if (str && strlen(str) > 0 && interface->ifname) {
3039 SUPPLICANT_DBG("New {%s, %s}", interface->ifname, str);
3040 g_hash_table_replace(config_file_table,
3041 g_strdup(interface->ifname), g_strdup(str));
3043 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
3044 interface_current_bss(interface, iter);
3045 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
3046 #if defined TIZEN_EXT
3047 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
3049 interface_network_added(iter, interface);
3050 } else if (g_strcmp0(key, "BSSs") == 0) {
3051 supplicant_dbus_array_foreach(iter,
3052 interface_bss_added_without_keys,
3054 } else if (g_strcmp0(key, "Blobs") == 0) {
3056 } else if (g_strcmp0(key, "Networks") == 0) {
3057 supplicant_dbus_array_foreach(iter, interface_network_added,
3059 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
3061 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3062 dbus_message_iter_get_basic(iter, &reason_code);
3063 callback_disconnect_reason_code(interface, reason_code);
3065 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
3067 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3068 dbus_message_iter_get_basic(iter, &status_code);
3069 callback_assoc_status_code(interface, status_code);
3072 SUPPLICANT_DBG("key %s type %c",
3073 key, dbus_message_iter_get_arg_type(iter));
3077 static void scan_network_update(DBusMessageIter *iter, void *user_data)
3079 GSupplicantInterface *interface = user_data;
3080 GSupplicantNetwork *network;
3086 dbus_message_iter_get_basic(iter, &path);
3091 if (g_strcmp0(path, "/") == 0)
3094 /* Update the network details based on scan BSS data */
3095 network = g_hash_table_lookup(interface->bss_mapping, path);
3097 callback_network_added(network);
3100 static void scan_bss_data(const char *key, DBusMessageIter *iter,
3103 GSupplicantInterface *interface = user_data;
3105 /*Fixed : stucking in scanning state when scan failed*/
3106 #if defined TIZEN_EXT
3107 GSupplicantInterfaceCallback scan_callback;
3111 supplicant_dbus_array_foreach(iter, scan_network_update,
3114 #if defined TIZEN_EXT
3115 scan_callback = interface->scan_callback;
3118 if (interface->scan_callback)
3119 interface->scan_callback(0, interface, interface->scan_data);
3121 #if defined TIZEN_EXT
3122 if (interface->scan_callback == scan_callback) {
3124 interface->scan_callback = NULL;
3125 interface->scan_data = NULL;
3126 #if defined TIZEN_EXT
3131 static GSupplicantInterface *interface_alloc(const char *path)
3133 GSupplicantInterface *interface;
3135 interface = g_try_new0(GSupplicantInterface, 1);
3139 interface->path = g_strdup(path);
3141 interface->network_table = g_hash_table_new_full(g_str_hash,
3142 g_str_equal, NULL, remove_network);
3143 interface->peer_table = g_hash_table_new_full(g_str_hash,
3144 g_str_equal, NULL, remove_peer);
3145 interface->group_table = g_hash_table_new_full(g_str_hash,
3146 g_str_equal, NULL, remove_group);
3147 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
3150 g_hash_table_replace(interface_table, interface->path, interface);
3155 static void interface_added(DBusMessageIter *iter, void *user_data)
3157 GSupplicantInterface *interface;
3158 const char *path = NULL;
3159 bool properties_appended = GPOINTER_TO_UINT(user_data);
3163 dbus_message_iter_get_basic(iter, &path);
3167 if (g_strcmp0(path, "/") == 0)
3170 interface = g_hash_table_lookup(interface_table, path);
3174 interface = interface_alloc(path);
3178 if (!properties_appended) {
3179 supplicant_dbus_property_get_all(path,
3180 SUPPLICANT_INTERFACE ".Interface",
3181 interface_property, interface,
3186 dbus_message_iter_next(iter);
3187 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3188 supplicant_dbus_property_foreach(iter, interface_property,
3190 interface_property(NULL, NULL, interface);
3194 static void interface_removed(DBusMessageIter *iter, void *user_data)
3196 const char *path = NULL;
3197 GSupplicantInterface *interface = user_data;
3199 dbus_message_iter_get_basic(iter, &path);
3203 interface = g_hash_table_lookup(interface_table, path);
3204 g_supplicant_interface_cancel(interface);
3206 g_hash_table_remove(interface_table, path);
3209 static void eap_method(DBusMessageIter *iter, void *user_data)
3211 const char *str = NULL;
3214 dbus_message_iter_get_basic(iter, &str);
3218 for (i = 0; eap_method_map[i].str; i++)
3219 if (strcmp(str, eap_method_map[i].str) == 0) {
3220 eap_methods |= eap_method_map[i].val;
3225 static void service_property(const char *key, DBusMessageIter *iter,
3229 callback_system_ready();
3233 if (g_strcmp0(key, "DebugLevel") == 0) {
3234 const char *str = NULL;
3237 dbus_message_iter_get_basic(iter, &str);
3238 for (i = 0; debug_strings[i]; i++)
3239 if (g_strcmp0(debug_strings[i], str) == 0) {
3243 SUPPLICANT_DBG("Debug level %d", debug_level);
3244 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
3245 dbus_message_iter_get_basic(iter, &debug_timestamp);
3246 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
3247 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
3248 dbus_message_iter_get_basic(iter, &debug_showkeys);
3249 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
3250 } else if (g_strcmp0(key, "Interfaces") == 0) {
3251 supplicant_dbus_array_foreach(iter, interface_added, NULL);
3252 } else if (g_strcmp0(key, "EapMethods") == 0) {
3253 supplicant_dbus_array_foreach(iter, eap_method, NULL);
3254 debug_strvalmap("EAP method", eap_method_map, eap_methods);
3255 } else if (g_strcmp0(key, "Country") == 0) {
3256 const char *country = NULL;
3258 dbus_message_iter_get_basic(iter, &country);
3259 SUPPLICANT_DBG("Country %s", country);
3261 SUPPLICANT_DBG("key %s type %c",
3262 key, dbus_message_iter_get_arg_type(iter));
3265 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
3267 const char *name = NULL, *old = NULL, *new = NULL;
3271 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
3274 dbus_message_iter_get_basic(iter, &name);
3278 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
3281 dbus_message_iter_next(iter);
3282 dbus_message_iter_get_basic(iter, &old);
3283 dbus_message_iter_next(iter);
3284 dbus_message_iter_get_basic(iter, &new);
3289 if (strlen(old) > 0 && strlen(new) == 0) {
3290 system_available = FALSE;
3291 g_hash_table_remove_all(bss_mapping);
3292 g_hash_table_remove_all(peer_mapping);
3293 g_hash_table_remove_all(group_mapping);
3294 g_hash_table_remove_all(config_file_table);
3295 g_hash_table_remove_all(interface_table);
3296 callback_system_killed();
3299 if (strlen(new) > 0 && strlen(old) == 0) {
3300 system_available = TRUE;
3301 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
3302 SUPPLICANT_INTERFACE,
3303 service_property, NULL, NULL);
3307 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
3311 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
3314 supplicant_dbus_property_foreach(iter, service_property, NULL);
3317 static void signal_interface_added(const char *path, DBusMessageIter *iter)
3319 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
3321 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
3322 interface_added(iter, GUINT_TO_POINTER(true));
3325 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
3329 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
3330 interface_removed(iter, NULL);
3333 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
3335 GSupplicantInterface *interface;
3339 interface = g_hash_table_lookup(interface_table, path);
3343 supplicant_dbus_property_foreach(iter, interface_property, interface);
3346 static void signal_scan_done(const char *path, DBusMessageIter *iter)
3348 GSupplicantInterface *interface;
3349 dbus_bool_t success = FALSE;
3353 interface = g_hash_table_lookup(interface_table, path);
3357 dbus_message_iter_get_basic(iter, &success);
3359 if (interface->scanning) {
3360 callback_scan_finished(interface);
3361 interface->scanning = FALSE;
3365 * If scan is unsuccessful return -EIO else get the scanned BSSs
3366 * and update the network details accordingly
3369 if (interface->scan_callback)
3370 interface->scan_callback(-EIO, interface,
3371 interface->scan_data);
3373 interface->scan_callback = NULL;
3374 interface->scan_data = NULL;
3379 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
3380 "BSSs", scan_bss_data, interface, interface);
3383 static void signal_bss_added(const char *path, DBusMessageIter *iter)
3385 GSupplicantInterface *interface;
3389 interface = g_hash_table_lookup(interface_table, path);
3393 interface_bss_added_with_keys(iter, interface);
3396 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
3398 GSupplicantInterface *interface;
3402 interface = g_hash_table_lookup(interface_table, path);
3406 interface_bss_removed(iter, interface);
3409 static void signal_network_added(const char *path, DBusMessageIter *iter)
3411 GSupplicantInterface *interface;
3415 interface = g_hash_table_lookup(interface_table, path);
3419 interface_network_added(iter, interface);
3422 static void signal_network_removed(const char *path, DBusMessageIter *iter)
3424 GSupplicantInterface *interface;
3428 interface = g_hash_table_lookup(interface_table, path);
3432 interface_network_removed(iter, interface);
3434 #if defined TIZEN_EXT
3435 void *copy_vsie_list(gconstpointer src, gpointer data)
3437 return g_strdup(src);
3442 static void signal_sta_authorized(const char *path, DBusMessageIter *iter)
3444 GSupplicantInterface *interface;
3445 const char *addr = NULL;
3449 interface = g_hash_table_lookup(interface_table, path);
3453 dbus_message_iter_get_basic(iter, &addr);
3457 callback_sta_authorized(interface, addr);
3460 static void signal_sta_deauthorized(const char *path, DBusMessageIter *iter)
3462 GSupplicantInterface *interface;
3463 const char *addr = NULL;
3467 interface = g_hash_table_lookup(interface_table, path);
3471 dbus_message_iter_get_basic(iter, &addr);
3475 callback_sta_deauthorized(interface, addr);
3478 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
3480 GSupplicantInterface *interface;
3481 GSupplicantNetwork *network;
3482 GSupplicantSecurity old_security;
3483 unsigned int old_wps_capabilities;
3484 struct g_supplicant_bss *bss;
3488 interface = g_hash_table_lookup(bss_mapping, path);
3492 network = g_hash_table_lookup(interface->bss_mapping, path);
3496 bss = g_hash_table_lookup(network->bss_table, path);
3500 supplicant_dbus_property_foreach(iter, bss_property, bss);
3502 #if defined TIZEN_EXT
3503 network->frequency = bss->frequency;
3504 network->phy_mode = bss->phy_mode;
3506 old_security = network->security;
3507 bss_compute_security(bss);
3509 if (old_security != bss->security) {
3510 struct g_supplicant_bss *new_bss;
3512 SUPPLICANT_DBG("New network security for %s with path %s",
3513 bss->ssid, bss->path);
3516 * Security change policy:
3517 * - We first copy the current bss into a new one with
3518 * its own pointer (path)
3519 * - Clear the old bss pointer and remove the network completely
3520 * if there are no more BSSs in the bss table.
3521 * - The new bss will be added either to an existing network
3522 * or an additional network will be created
3525 new_bss = g_try_new0(struct g_supplicant_bss, 1);
3529 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
3530 new_bss->path = g_strdup(bss->path);
3531 #if defined TIZEN_EXT
3532 new_bss->vsie_list = g_slist_copy_deep(bss->vsie_list, copy_vsie_list, NULL);
3535 if (network->best_bss == bss) {
3536 network->best_bss = NULL;
3537 network->signal = BSS_UNKNOWN_STRENGTH;
3540 g_hash_table_remove(bss_mapping, path);
3542 g_hash_table_remove(interface->bss_mapping, path);
3543 g_hash_table_remove(network->bss_table, path);
3545 update_network_signal(network);
3547 if (g_hash_table_size(network->bss_table) == 0)
3548 g_hash_table_remove(interface->network_table,
3551 if (add_or_replace_bss_to_network(new_bss) < 0) {
3553 * Prevent a memory leak on failure in
3554 * add_or_replace_bss_to_network
3556 SUPPLICANT_DBG("Failed to add bss %s to network table",
3558 g_free(new_bss->path);
3565 old_wps_capabilities = network->wps_capabilities;
3567 if (old_wps_capabilities != bss->wps_capabilities) {
3568 network->wps_capabilities = bss->wps_capabilities;
3569 callback_network_changed(network, "WPSCapabilities");
3572 #if defined TIZEN_EXT
3573 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
3574 network->wps = TRUE;
3575 network->wps_capabilities |= bss->wps_capabilities;
3577 network->wps = FALSE;
3580 /* Consider only property changes of the connected BSS */
3581 if (network == interface->current_network && bss != network->best_bss)
3584 if (bss->signal == network->signal)
3589 callback_network_changed(network, "");
3595 * If the new signal is lower than the SSID signal, we need
3596 * to check for the new maximum.
3598 if (bss->signal < network->signal) {
3599 if (bss != network->best_bss)
3604 callback_network_changed(network, "");
3608 network->signal = bss->signal;
3609 update_network_signal(network);
3611 network->signal = bss->signal;
3612 network->best_bss = bss;
3615 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
3618 callback_network_changed(network, "Signal");
3621 static void wps_credentials(const char *key, DBusMessageIter *iter,
3624 GSupplicantInterface *interface = user_data;
3629 SUPPLICANT_DBG("key %s", key);
3631 if (g_strcmp0(key, "Key") == 0) {
3632 DBusMessageIter array;
3633 unsigned char *key_val;
3636 dbus_message_iter_recurse(iter, &array);
3637 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
3639 g_free(interface->wps_cred.key);
3640 interface->wps_cred.key = g_try_malloc0(
3641 sizeof(char) * key_len + 1);
3643 if (!interface->wps_cred.key)
3646 memcpy(interface->wps_cred.key, key_val,
3647 sizeof(char) * key_len);
3649 SUPPLICANT_DBG("WPS key present");
3650 } else if (g_strcmp0(key, "SSID") == 0) {
3651 DBusMessageIter array;
3652 unsigned char *ssid;
3655 dbus_message_iter_recurse(iter, &array);
3656 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
3658 if (ssid_len > 0 && ssid_len < 33) {
3659 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
3660 interface->wps_cred.ssid_len = ssid_len;
3662 memset(interface->wps_cred.ssid, 0, 32);
3663 interface->wps_cred.ssid_len = 0;
3668 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
3670 GSupplicantInterface *interface;
3674 interface = g_hash_table_lookup(interface_table, path);
3678 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
3681 static void wps_event_args(const char *key, DBusMessageIter *iter,
3684 GSupplicantInterface *interface = user_data;
3686 if (!key || !interface)
3689 SUPPLICANT_DBG("Arg Key %s", key);
3692 static void signal_wps_event(const char *path, DBusMessageIter *iter)
3694 GSupplicantInterface *interface;
3695 const char *name = NULL;
3699 interface = g_hash_table_lookup(interface_table, path);
3703 dbus_message_iter_get_basic(iter, &name);
3705 SUPPLICANT_DBG("Name: %s", name);
3707 if (g_strcmp0(name, "success") == 0)
3708 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
3709 else if (g_strcmp0(name, "fail") == 0)
3710 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
3712 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
3714 if (!dbus_message_iter_has_next(iter))
3717 dbus_message_iter_next(iter);
3719 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
3722 #if defined TIZEN_EXT
3723 static void signal_power_off(const char *path, DBusMessageIter *iter)
3725 int poweroff_state = 0;
3727 dbus_message_iter_get_basic(iter, &poweroff_state);
3729 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
3731 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
3732 if (poweroff_state != 2 && poweroff_state != 3)
3735 if (callbacks_pointer == NULL)
3738 if (callbacks_pointer->system_power_off == NULL)
3741 callbacks_pointer->system_power_off();
3745 static void create_peer_identifier(GSupplicantPeer *peer)
3747 const unsigned char test[ETH_ALEN] = {};
3752 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
3753 peer->identifier = g_strdup(peer->name);
3757 peer->identifier = g_malloc0(19);
3758 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
3759 peer->device_address[0],
3760 peer->device_address[1],
3761 peer->device_address[2],
3762 peer->device_address[3],
3763 peer->device_address[4],
3764 peer->device_address[5]);
3767 struct peer_property_data {
3768 GSupplicantPeer *peer;
3770 bool groups_changed;
3771 bool services_changed;
3774 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
3776 struct peer_property_data *data = user_data;
3777 GSupplicantPeer *peer = data->peer;
3778 GSupplicantGroup *group;
3779 const char *str = NULL;
3782 dbus_message_iter_get_basic(iter, &str);
3786 group = g_hash_table_lookup(group_mapping, str);
3790 elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
3792 data->old_groups = g_slist_remove_link(data->old_groups, elem);
3793 peer->groups = g_slist_concat(elem, peer->groups);
3795 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
3796 data->groups_changed = true;
3800 static void peer_property(const char *key, DBusMessageIter *iter,
3803 GSupplicantPeer *pending_peer;
3804 struct peer_property_data *data = user_data;
3805 GSupplicantPeer *peer = data->peer;
3807 SUPPLICANT_DBG("key: %s", key);
3809 if (!peer->interface)
3814 create_peer_identifier(peer);
3815 callback_peer_found(peer);
3816 pending_peer = g_hash_table_lookup(
3817 pending_peer_connection, peer->path);
3819 if (pending_peer && pending_peer == peer) {
3820 callback_peer_request(peer);
3821 g_hash_table_remove(pending_peer_connection,
3831 if (g_strcmp0(key, "DeviceAddress") == 0) {
3832 unsigned char *dev_addr;
3833 DBusMessageIter array;
3836 dbus_message_iter_recurse(iter, &array);
3837 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
3839 if (len == ETH_ALEN)
3840 memcpy(peer->device_address, dev_addr, len);
3841 } else if (g_strcmp0(key, "DeviceName") == 0) {
3842 const char *str = NULL;
3844 dbus_message_iter_get_basic(iter, &str);
3846 peer->name = g_strdup(str);
3847 } else if (g_strcmp0(key, "config_method") == 0) {
3848 uint16_t wps_config;
3850 dbus_message_iter_get_basic(iter, &wps_config);
3852 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
3853 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3854 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
3855 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3856 } else if (g_strcmp0(key, "Groups") == 0) {
3857 data->old_groups = peer->groups;
3858 peer->groups = NULL;
3860 supplicant_dbus_array_foreach(iter,
3861 peer_groups_relation, data);
3862 if (g_slist_length(data->old_groups) > 0) {
3863 g_slist_free_full(data->old_groups, g_free);
3864 data->groups_changed = true;
3866 } else if (g_strcmp0(key, "IEs") == 0) {
3867 DBusMessageIter array;
3871 dbus_message_iter_recurse(iter, &array);
3872 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
3874 if (!ie || ie_len < 2)
3877 if (peer->widi_ies) {
3878 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
3881 g_free(peer->widi_ies);
3882 peer->widi_ies_length = 0;
3885 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
3887 memcpy(peer->widi_ies, ie, ie_len);
3888 peer->widi_ies_length = ie_len;
3889 data->services_changed = true;
3893 static void signal_peer_found(const char *path, DBusMessageIter *iter)
3895 struct peer_property_data *property_data;
3896 GSupplicantInterface *interface;
3897 const char *obj_path = NULL;
3898 GSupplicantPeer *peer;
3902 interface = g_hash_table_lookup(interface_table, path);
3906 dbus_message_iter_get_basic(iter, &obj_path);
3907 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
3910 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3914 peer = g_try_new0(GSupplicantPeer, 1);
3918 peer->interface = interface;
3919 peer->path = g_strdup(obj_path);
3920 g_hash_table_insert(interface->peer_table, peer->path, peer);
3921 g_hash_table_replace(peer_mapping, peer->path, interface);
3923 property_data = dbus_malloc0(sizeof(struct peer_property_data));
3924 property_data->peer = peer;
3926 dbus_message_iter_next(iter);
3927 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3928 supplicant_dbus_property_foreach(iter, peer_property,
3930 peer_property(NULL, NULL, property_data);
3934 supplicant_dbus_property_get_all(obj_path,
3935 SUPPLICANT_INTERFACE ".Peer",
3936 peer_property, property_data, NULL);
3939 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
3941 GSupplicantInterface *interface;
3942 const char *obj_path = NULL;
3943 GSupplicantPeer *peer;
3947 interface = g_hash_table_lookup(interface_table, path);
3951 dbus_message_iter_get_basic(iter, &obj_path);
3952 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
3955 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3959 g_hash_table_remove(interface->peer_table, obj_path);
3962 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
3964 struct peer_property_data *property_data;
3965 GSupplicantInterface *interface;
3966 GSupplicantPeer *peer;
3970 interface = g_hash_table_lookup(peer_mapping, path);
3974 peer = g_hash_table_lookup(interface->peer_table, path);
3976 g_hash_table_remove(peer_mapping, path);
3980 property_data = dbus_malloc0(sizeof(struct peer_property_data));
3981 property_data->peer = peer;
3983 supplicant_dbus_property_foreach(iter, peer_property, property_data);
3984 if (property_data->services_changed)
3985 callback_peer_changed(peer,
3986 G_SUPPLICANT_PEER_SERVICES_CHANGED);
3988 if (property_data->groups_changed)
3989 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
3991 dbus_free(property_data);
3993 if (!g_supplicant_peer_is_in_a_group(peer))
3994 peer->connection_requested = false;
3997 struct group_sig_data {
3998 const char *peer_obj_path;
3999 unsigned char iface_address[ETH_ALEN];
4000 const char *interface_obj_path;
4001 const char *group_obj_path;
4005 static void group_sig_property(const char *key, DBusMessageIter *iter,
4008 struct group_sig_data *data = user_data;
4013 if (g_strcmp0(key, "peer_interface_addr") == 0) {
4014 unsigned char *dev_addr;
4015 DBusMessageIter array;
4018 dbus_message_iter_recurse(iter, &array);
4019 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4021 if (len == ETH_ALEN)
4022 memcpy(data->iface_address, dev_addr, len);
4023 } else if (g_strcmp0(key, "role") == 0) {
4024 const char *str = NULL;
4026 dbus_message_iter_get_basic(iter, &str);
4027 if (g_strcmp0(str, "GO") == 0)
4028 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
4030 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
4031 } else if (g_strcmp0(key, "peer_object") == 0)
4032 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
4033 else if (g_strcmp0(key, "interface_object") == 0)
4034 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
4035 else if (g_strcmp0(key, "group_object") == 0)
4036 dbus_message_iter_get_basic(iter, &data->group_obj_path);
4040 static void signal_group_success(const char *path, DBusMessageIter *iter)
4042 GSupplicantInterface *interface;
4043 struct group_sig_data data = {};
4044 GSupplicantPeer *peer;
4048 interface = g_hash_table_lookup(interface_table, path);
4052 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4053 if (!data.peer_obj_path)
4056 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4060 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
4061 interface->pending_peer_path = peer->path;
4064 static void signal_group_failure(const char *path, DBusMessageIter *iter)
4066 GSupplicantInterface *interface;
4067 struct group_sig_data data = {};
4068 GSupplicantPeer *peer;
4072 interface = g_hash_table_lookup(interface_table, path);
4076 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4077 if (!data.peer_obj_path)
4080 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4084 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
4085 peer->connection_requested = false;
4088 static void signal_group_started(const char *path, DBusMessageIter *iter)
4090 GSupplicantInterface *interface, *g_interface;
4091 struct group_sig_data data = {};
4092 GSupplicantGroup *group;
4093 GSupplicantPeer *peer;
4097 interface = g_hash_table_lookup(interface_table, path);
4101 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4102 if (!data.interface_obj_path || !data.group_obj_path)
4105 peer = g_hash_table_lookup(interface->peer_table,
4106 interface->pending_peer_path);
4107 interface->pending_peer_path = NULL;
4111 g_interface = g_hash_table_lookup(interface_table,
4112 data.interface_obj_path);
4116 group = g_hash_table_lookup(interface->group_table,
4117 data.group_obj_path);
4121 group = g_try_new0(GSupplicantGroup, 1);
4125 group->interface = g_interface;
4126 group->orig_interface = interface;
4127 group->path = g_strdup(data.group_obj_path);
4128 group->role = data.role;
4130 g_hash_table_insert(interface->group_table, group->path, group);
4131 g_hash_table_replace(group_mapping, group->path, group);
4133 peer->current_group_iface = g_interface;
4134 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
4137 static void remove_peer_group_interface(GHashTable *group_table,
4140 GSupplicantGroup *group;
4141 GHashTableIter iter;
4142 gpointer value, key;
4147 group = g_hash_table_lookup(group_table, path);
4149 if (!group || !group->orig_interface)
4152 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
4154 while (g_hash_table_iter_next(&iter, &key, &value)) {
4155 GSupplicantPeer *peer = value;
4157 if (peer->current_group_iface == group->interface)
4158 peer->current_group_iface = NULL;
4162 static void signal_group_finished(const char *path, DBusMessageIter *iter)
4164 GSupplicantInterface *interface;
4165 struct group_sig_data data = {};
4169 interface = g_hash_table_lookup(interface_table, path);
4173 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4174 if (!data.interface_obj_path || !data.group_obj_path)
4177 remove_peer_group_interface(interface->group_table, data.group_obj_path);
4179 g_hash_table_remove(group_mapping, data.group_obj_path);
4181 g_hash_table_remove(interface->group_table, data.group_obj_path);
4184 static void signal_group_request(const char *path, DBusMessageIter *iter)
4186 GSupplicantInterface *interface;
4187 GSupplicantPeer *peer;
4188 const char *obj_path;
4192 interface = g_hash_table_lookup(interface_table, path);
4196 dbus_message_iter_get_basic(iter, &obj_path);
4197 if (!obj_path || !g_strcmp0(obj_path, "/"))
4200 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4205 * Peer has been previously found and property set,
4206 * otherwise, defer connection to when peer property
4209 if (peer->identifier)
4210 callback_peer_request(peer);
4212 g_hash_table_replace(pending_peer_connection, peer->path, peer);
4215 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
4217 const char *peer_path = NULL;
4218 GSupplicantInterface *interface;
4219 GSupplicantGroup *group;
4220 GSupplicantPeer *peer;
4224 group = g_hash_table_lookup(group_mapping, path);
4228 dbus_message_iter_get_basic(iter, &peer_path);
4232 interface = g_hash_table_lookup(peer_mapping, peer_path);
4236 peer = g_hash_table_lookup(interface->peer_table, peer_path);
4240 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
4242 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
4245 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
4247 const char *peer_path = NULL;
4248 GSupplicantInterface *interface;
4249 GSupplicantGroup *group;
4250 GSupplicantPeer *peer;
4255 group = g_hash_table_lookup(group_mapping, path);
4259 dbus_message_iter_get_basic(iter, &peer_path);
4263 for (elem = group->members; elem; elem = elem->next) {
4264 if (!g_strcmp0(elem->data, peer_path))
4272 group->members = g_slist_delete_link(group->members, elem);
4274 interface = g_hash_table_lookup(peer_mapping, peer_path);
4278 peer = g_hash_table_lookup(interface->peer_table, peer_path);
4282 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
4283 peer->connection_requested = false;
4286 #if defined TIZEN_EXT_WIFI_MESH
4287 const void *g_supplicant_interface_get_mesh_group_ssid(
4288 GSupplicantInterface *interface,
4289 unsigned int *ssid_len)
4294 if (!interface || interface->group_info.ssid_len == 0) {
4299 *ssid_len = interface->group_info.ssid_len;
4300 return interface->group_info.ssid;
4303 int g_supplicant_mesh_get_disconnect_reason(GSupplicantInterface *interface)
4308 return interface->group_info.disconnect_reason;
4311 const char *g_supplicant_mesh_peer_get_address(GSupplicantMeshPeer *mesh_peer)
4313 if (!mesh_peer || !mesh_peer->peer_address)
4316 return mesh_peer->peer_address;
4319 int g_supplicant_mesh_peer_get_disconnect_reason(GSupplicantMeshPeer *mesh_peer)
4324 return mesh_peer->disconnect_reason;
4327 static void callback_mesh_group_started(GSupplicantInterface *interface)
4329 if (!callbacks_pointer)
4332 if (!callbacks_pointer->mesh_group_started)
4335 callbacks_pointer->mesh_group_started(interface);
4338 static void callback_mesh_group_removed(GSupplicantInterface *interface)
4340 if (!callbacks_pointer)
4343 if (!callbacks_pointer->mesh_group_removed)
4346 callbacks_pointer->mesh_group_removed(interface);
4349 static void mesh_group_info(const char *key, DBusMessageIter *iter,
4352 GSupplicantInterface *interface = user_data;
4356 if (g_strcmp0(key, "SSID") == 0) {
4357 DBusMessageIter array;
4358 unsigned char *ssid;
4361 dbus_message_iter_recurse(iter, &array);
4362 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
4364 if (ssid_len > 0 && ssid_len < 33) {
4365 memcpy(interface->group_info.ssid, ssid, ssid_len);
4366 interface->group_info.ssid_len = ssid_len;
4368 memset(interface->group_info.ssid, 0, 32);
4369 interface->group_info.ssid_len = 0;
4371 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
4372 int disconnect_reason = 0;
4373 dbus_message_iter_get_basic(iter, &disconnect_reason);
4374 interface->group_info.disconnect_reason = disconnect_reason;
4378 static void signal_mesh_group_started(const char *path, DBusMessageIter *iter)
4380 GSupplicantInterface *interface;
4382 interface = g_hash_table_lookup(interface_table, path);
4386 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
4388 callback_mesh_group_started(interface);
4391 static void signal_mesh_group_removed(const char *path, DBusMessageIter *iter)
4393 GSupplicantInterface *interface;
4395 interface = g_hash_table_lookup(interface_table, path);
4399 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
4401 callback_mesh_group_removed(interface);
4404 static void callback_mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
4406 if (!callbacks_pointer)
4409 if (!callbacks_pointer->mesh_peer_connected)
4412 callbacks_pointer->mesh_peer_connected(mesh_peer);
4415 static void callback_mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
4417 if (!callbacks_pointer)
4420 if (!callbacks_pointer->mesh_peer_disconnected)
4423 callbacks_pointer->mesh_peer_disconnected(mesh_peer);
4426 static void mesh_peer_info(const char *key, DBusMessageIter *iter,
4429 GSupplicantMeshPeer *mesh_peer = user_data;
4433 if (g_strcmp0(key, "PeerAddress") == 0) {
4434 DBusMessageIter array;
4435 unsigned char *addr;
4438 dbus_message_iter_recurse(iter, &array);
4439 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
4441 if (addr_len == 6) {
4442 mesh_peer->peer_address = g_malloc0(19);
4443 snprintf(mesh_peer->peer_address, 19,
4444 "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1],
4445 addr[2], addr[3], addr[4], addr[5]);
4447 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
4448 int disconnect_reason = 0;
4449 dbus_message_iter_get_basic(iter, &disconnect_reason);
4450 mesh_peer->disconnect_reason = disconnect_reason;
4454 static void signal_mesh_peer_connected(const char *path, DBusMessageIter *iter)
4456 GSupplicantInterface *interface;
4457 GSupplicantMeshPeer *mesh_peer;
4459 interface = g_hash_table_lookup(interface_table, path);
4463 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
4464 mesh_peer->interface = interface;
4466 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
4468 callback_mesh_peer_connected(mesh_peer);
4469 g_free(mesh_peer->peer_address);
4473 static void signal_mesh_peer_disconnected(const char *path,
4474 DBusMessageIter *iter)
4476 GSupplicantInterface *interface;
4477 GSupplicantMeshPeer *mesh_peer;
4479 interface = g_hash_table_lookup(interface_table, path);
4483 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
4484 mesh_peer->interface = interface;
4486 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
4488 callback_mesh_peer_disconnected(mesh_peer);
4489 g_free(mesh_peer->peer_address);
4495 const char *interface;
4497 void (*function) (const char *path, DBusMessageIter *iter);
4499 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
4501 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
4502 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
4503 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
4504 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
4506 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
4507 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
4508 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
4509 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
4510 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
4511 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
4512 { SUPPLICANT_INTERFACE ".Interface", "StaAuthorized", signal_sta_authorized },
4513 { SUPPLICANT_INTERFACE ".Interface", "StaDeauthorized", signal_sta_deauthorized },
4515 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
4517 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
4518 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
4519 #if defined TIZEN_EXT
4520 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
4523 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
4524 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
4526 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
4528 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
4529 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
4530 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
4531 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
4532 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
4534 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
4535 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
4536 #if defined TIZEN_EXT_WIFI_MESH
4537 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupStarted",
4538 signal_mesh_group_started },
4539 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupRemoved",
4540 signal_mesh_group_removed },
4541 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerConnected",
4542 signal_mesh_peer_connected },
4543 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerDisconnected",
4544 signal_mesh_peer_disconnected },
4550 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
4551 DBusMessage *message, void *data)
4553 DBusMessageIter iter;
4557 path = dbus_message_get_path(message);
4559 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4561 if (!dbus_message_iter_init(message, &iter))
4562 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4564 for (i = 0; signal_map[i].interface; i++) {
4565 if (!dbus_message_has_interface(message, signal_map[i].interface))
4568 if (!dbus_message_has_member(message, signal_map[i].member))
4571 signal_map[i].function(path, &iter);
4575 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4578 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
4580 SUPPLICANT_DBG("Cancelling any pending DBus calls");
4581 supplicant_dbus_method_call_cancel_all(interface);
4582 supplicant_dbus_property_call_cancel_all(interface);
4585 struct supplicant_regdom {
4586 GSupplicantCountryCallback callback;
4588 const void *user_data;
4591 static void country_result(const char *error,
4592 DBusMessageIter *iter, void *user_data)
4594 struct supplicant_regdom *regdom = user_data;
4597 SUPPLICANT_DBG("Country setting result");
4603 SUPPLICANT_DBG("Country setting failure %s", error);
4607 if (regdom->callback)
4608 regdom->callback(result, regdom->alpha2,
4609 (void *) regdom->user_data);
4614 static void country_params(DBusMessageIter *iter, void *user_data)
4616 struct supplicant_regdom *regdom = user_data;
4618 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
4622 int g_supplicant_set_country(const char *alpha2,
4623 GSupplicantCountryCallback callback,
4624 const void *user_data)
4626 struct supplicant_regdom *regdom;
4629 SUPPLICANT_DBG("Country setting %s", alpha2);
4631 if (!system_available)
4634 regdom = dbus_malloc0(sizeof(*regdom));
4638 regdom->callback = callback;
4639 regdom->alpha2 = alpha2;
4640 regdom->user_data = user_data;
4642 ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
4643 "Country", DBUS_TYPE_STRING_AS_STRING,
4644 country_params, country_result,
4648 SUPPLICANT_DBG("Unable to set Country configuration");
4653 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
4654 GSupplicantCountryCallback callback,
4658 struct supplicant_regdom *regdom;
4661 regdom = dbus_malloc0(sizeof(*regdom));
4665 regdom->callback = callback;
4666 regdom->alpha2 = alpha2;
4667 regdom->user_data = user_data;
4669 ret = supplicant_dbus_property_set(interface->path,
4670 SUPPLICANT_INTERFACE ".Interface",
4671 "Country", DBUS_TYPE_STRING_AS_STRING,
4672 country_params, country_result,
4676 SUPPLICANT_DBG("Unable to set Country configuration");
4682 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
4687 return interface->p2p_support;
4690 struct supplicant_p2p_dev_config {
4695 static void p2p_device_config_result(const char *error,
4696 DBusMessageIter *iter, void *user_data)
4698 struct supplicant_p2p_dev_config *config = user_data;
4701 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
4704 g_free(config->device_name);
4705 g_free(config->dev_type);
4709 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
4711 int length, pos, end;
4716 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
4723 dev_type[length] = strtol(b, &e, 16);
4724 if (e && *e != '\0')
4733 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
4735 struct supplicant_p2p_dev_config *config = user_data;
4736 DBusMessageIter dict;
4738 supplicant_dbus_dict_open(iter, &dict);
4740 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
4741 DBUS_TYPE_STRING, &config->device_name);
4743 if (config->dev_type) {
4744 unsigned char dev_type[8] = {}, *type;
4747 len = dev_type_str2bin(config->dev_type, dev_type);
4750 supplicant_dbus_dict_append_fixed_array(&dict,
4751 "PrimaryDeviceType",
4752 DBUS_TYPE_BYTE, &type, len);
4756 supplicant_dbus_dict_close(iter, &dict);
4759 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
4760 const char *device_name,
4761 const char *primary_dev_type)
4763 struct supplicant_p2p_dev_config *config;
4766 SUPPLICANT_DBG("P2P Device settings %s/%s",
4767 device_name, primary_dev_type);
4769 config = dbus_malloc0(sizeof(*config));
4773 config->device_name = g_strdup(device_name);
4774 config->dev_type = g_strdup(primary_dev_type);
4776 ret = supplicant_dbus_property_set(interface->path,
4777 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
4779 DBUS_TYPE_ARRAY_AS_STRING
4780 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
4781 DBUS_TYPE_STRING_AS_STRING
4782 DBUS_TYPE_VARIANT_AS_STRING
4783 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
4784 p2p_device_config_params,
4785 p2p_device_config_result, config, NULL);
4787 g_free(config->device_name);
4788 g_free(config->dev_type);
4790 SUPPLICANT_DBG("Unable to set P2P Device configuration");
4796 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
4799 const GSupplicantPeer *peer = value;
4800 const char *identifier = user_data;
4802 if (!g_strcmp0(identifier, peer->identifier))
4808 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
4809 const char *identifier)
4811 GSupplicantPeer *peer;
4813 peer = g_hash_table_find(interface->peer_table,
4814 peer_lookup_by_identifier,
4815 (void *) identifier);
4819 static void interface_create_data_free(struct interface_create_data *data)
4821 g_free(data->ifname);
4822 g_free(data->driver);
4823 g_free(data->bridge);
4824 #if defined TIZEN_EXT_WIFI_MESH
4825 g_free(data->parent_ifname);
4830 static bool interface_exists(GSupplicantInterface *interface,
4833 GSupplicantInterface *tmp;
4835 tmp = g_hash_table_lookup(interface_table, path);
4836 if (tmp && tmp == interface)
4842 static void interface_create_property(const char *key, DBusMessageIter *iter,
4845 struct interface_create_data *data = user_data;
4846 GSupplicantInterface *interface = data->interface;
4849 if (data->callback) {
4850 data->callback(0, data->interface, data->user_data);
4851 #if !defined TIZEN_EXT
4852 callback_p2p_support(interface);
4854 #if defined TIZEN_EXT_WIFI_MESH
4855 callback_mesh_support(interface);
4859 interface_create_data_free(data);
4862 interface_property(key, iter, interface);
4865 static void interface_create_result(const char *error,
4866 DBusMessageIter *iter, void *user_data)
4868 struct interface_create_data *data = user_data;
4869 const char *path = NULL;
4875 g_warning("error %s", error);
4880 dbus_message_iter_get_basic(iter, &path);
4886 if (!system_available) {
4891 data->interface = g_hash_table_lookup(interface_table, path);
4892 if (!data->interface) {
4893 data->interface = interface_alloc(path);
4894 if (!data->interface) {
4900 err = supplicant_dbus_property_get_all(path,
4901 SUPPLICANT_INTERFACE ".Interface",
4902 interface_create_property, data,
4909 data->callback(err, NULL, data->user_data);
4911 interface_create_data_free(data);
4914 static void interface_create_params(DBusMessageIter *iter, void *user_data)
4916 struct interface_create_data *data = user_data;
4917 DBusMessageIter dict;
4918 char *config_file = NULL;
4922 supplicant_dbus_dict_open(iter, &dict);
4924 supplicant_dbus_dict_append_basic(&dict, "Ifname",
4925 DBUS_TYPE_STRING, &data->ifname);
4928 supplicant_dbus_dict_append_basic(&dict, "Driver",
4929 DBUS_TYPE_STRING, &data->driver);
4932 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
4933 DBUS_TYPE_STRING, &data->bridge);
4935 config_file = g_hash_table_lookup(config_file_table, data->ifname);
4937 SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
4939 supplicant_dbus_dict_append_basic(&dict, "ConfigFile",
4940 DBUS_TYPE_STRING, &config_file);
4943 #if defined TIZEN_EXT_WIFI_MESH
4944 if (data->is_mesh_interface) {
4945 if (data->parent_ifname)
4946 supplicant_dbus_dict_append_basic(&dict, "ParentIfname",
4947 DBUS_TYPE_STRING, &data->parent_ifname);
4949 supplicant_dbus_dict_append_basic(&dict, "IsMeshInterface",
4950 DBUS_TYPE_BOOLEAN, &data->is_mesh_interface);
4954 supplicant_dbus_dict_close(iter, &dict);
4957 static void interface_get_result(const char *error,
4958 DBusMessageIter *iter, void *user_data)
4960 struct interface_create_data *data = user_data;
4961 GSupplicantInterface *interface;
4962 const char *path = NULL;
4968 SUPPLICANT_DBG("Interface not created yet");
4972 dbus_message_iter_get_basic(iter, &path);
4978 interface = g_hash_table_lookup(interface_table, path);
4984 if (data->callback) {
4985 data->callback(0, interface, data->user_data);
4986 #if !defined TIZEN_EXT
4987 callback_p2p_support(interface);
4989 #if defined TIZEN_EXT_WIFI_MESH
4990 callback_mesh_support(interface);
4994 interface_create_data_free(data);
4999 if (!system_available) {
5004 SUPPLICANT_DBG("Creating interface");
5006 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
5007 SUPPLICANT_INTERFACE,
5009 interface_create_params,
5010 interface_create_result, data,
5017 data->callback(err, NULL, data->user_data);
5019 interface_create_data_free(data);
5022 static void interface_get_params(DBusMessageIter *iter, void *user_data)
5024 struct interface_create_data *data = user_data;
5028 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
5031 #if defined TIZEN_EXT_WIFI_MESH
5032 int g_supplicant_mesh_interface_create(const char *ifname, const char *driver,
5033 const char *bridge, const char *parent_ifname,
5034 GSupplicantInterfaceCallback callback, void *user_data)
5036 struct interface_create_data *data;
5039 SUPPLICANT_DBG("ifname %s", ifname);
5041 if (!ifname || !parent_ifname)
5044 if (!system_available)
5047 data = dbus_malloc0(sizeof(*data));
5051 data->ifname = g_strdup(ifname);
5052 data->driver = g_strdup(driver);
5053 data->bridge = g_strdup(bridge);
5054 data->is_mesh_interface = true;
5055 data->parent_ifname = g_strdup(parent_ifname);
5056 data->callback = callback;
5057 data->user_data = user_data;
5059 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5060 SUPPLICANT_INTERFACE,
5062 interface_create_params,
5063 interface_create_result, data,
5068 struct interface_mesh_peer_data {
5071 GSupplicantInterface *interface;
5072 GSupplicantInterfaceCallback callback;
5076 static void interface_mesh_change_peer_params(DBusMessageIter *iter,
5079 struct interface_mesh_peer_data *data = user_data;
5083 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->peer_address);
5086 static void interface_mesh_change_peer_result(const char *error,
5087 DBusMessageIter *iter, void *user_data)
5089 struct interface_mesh_peer_data *data = user_data;
5092 SUPPLICANT_DBG("%s", data->method);
5096 SUPPLICANT_DBG("error %s", error);
5100 data->callback(err, data->interface, data->user_data);
5102 g_free(data->peer_address);
5103 g_free(data->method);
5107 int g_supplicant_interface_mesh_peer_change_status(
5108 GSupplicantInterface *interface,
5109 GSupplicantInterfaceCallback callback, const char *peer_address,
5110 const char *method, void *user_data)
5112 struct interface_mesh_peer_data *data;
5118 data = dbus_malloc0(sizeof(*data));
5122 data->peer_address = g_strdup(peer_address);
5123 data->method = g_strdup(method);
5124 data->interface = interface;
5125 data->callback = callback;
5126 data->user_data = user_data;
5128 ret = supplicant_dbus_method_call(interface->path,
5129 SUPPLICANT_INTERFACE ".Interface.Mesh",
5130 method, interface_mesh_change_peer_params,
5131 interface_mesh_change_peer_result, data, NULL);
5133 g_free(data->peer_address);
5134 g_free(data->method);
5142 int g_supplicant_interface_create(const char *ifname, const char *driver,
5144 GSupplicantInterfaceCallback callback,
5147 struct interface_create_data *data;
5150 SUPPLICANT_DBG("ifname %s", ifname);
5155 if (!system_available)
5158 data = dbus_malloc0(sizeof(*data));
5162 data->ifname = g_strdup(ifname);
5163 data->driver = g_strdup(driver);
5164 data->bridge = g_strdup(bridge);
5165 data->callback = callback;
5166 data->user_data = user_data;
5168 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5169 SUPPLICANT_INTERFACE,
5171 interface_get_params,
5172 interface_get_result, data,
5175 interface_create_data_free(data);
5180 static void interface_remove_result(const char *error,
5181 DBusMessageIter *iter, void *user_data)
5183 struct interface_data *data = user_data;
5188 SUPPLICANT_DBG("error: %s", error);
5192 if (!system_available) {
5198 * The gsupplicant interface is already freed by the InterfaceRemoved
5199 * signal callback. Simply invoke the interface_data callback.
5207 data->callback(err, NULL, data->user_data);
5213 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
5215 struct interface_data *data = user_data;
5217 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
5218 &data->interface->path);
5222 int g_supplicant_interface_remove(GSupplicantInterface *interface,
5223 GSupplicantInterfaceCallback callback,
5226 struct interface_data *data;
5232 if (!system_available)
5235 g_supplicant_interface_cancel(interface);
5237 data = dbus_malloc0(sizeof(*data));
5241 data->interface = interface;
5242 data->path = g_strdup(interface->path);
5243 data->callback = callback;
5244 data->user_data = user_data;
5246 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5247 SUPPLICANT_INTERFACE,
5249 interface_remove_params,
5250 interface_remove_result, data,
5259 static void interface_scan_result(const char *error,
5260 DBusMessageIter *iter, void *user_data)
5262 struct interface_scan_data *data = user_data;
5266 SUPPLICANT_DBG("error %s", error);
5270 /* A non ready interface cannot send/receive anything */
5271 if (interface_exists(data->interface, data->path)) {
5272 if (!data->interface->ready)
5280 data->callback(err, data->interface, data->user_data);
5282 data->interface->scan_callback = data->callback;
5283 data->interface->scan_data = data->user_data;
5286 if (data->scan_params)
5287 g_supplicant_free_scan_params(data->scan_params);
5292 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
5294 DBusMessageIter data;
5295 unsigned int width = 0; /* Not used by wpa_supplicant atm */
5297 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
5299 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
5300 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
5302 dbus_message_iter_close_container(iter, &data);
5305 static void add_scan_frequencies(DBusMessageIter *iter,
5308 GSupplicantScanParams *scan_data = user_data;
5312 for (i = 0; i < scan_data->num_freqs; i++) {
5313 freq = scan_data->freqs[i];
5317 add_scan_frequency(iter, freq);
5321 static void append_ssid(DBusMessageIter *iter,
5322 const void *ssid, unsigned int len)
5324 DBusMessageIter array;
5326 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
5327 DBUS_TYPE_BYTE_AS_STRING, &array);
5329 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
5331 dbus_message_iter_close_container(iter, &array);
5334 static void append_ssids(DBusMessageIter *iter, void *user_data)
5336 GSupplicantScanParams *scan_data = user_data;
5339 for (list = scan_data->ssids; list; list = list->next) {
5340 struct scan_ssid *scan_ssid = list->data;
5342 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
5346 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
5347 supplicant_dbus_array_function function,
5350 GSupplicantScanParams *scan_params = user_data;
5351 DBusMessageIter entry, value, array;
5352 const char *key = "Channels";
5354 if (scan_params->freqs && scan_params->freqs[0] != 0) {
5355 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
5358 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
5360 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
5361 DBUS_TYPE_ARRAY_AS_STRING
5362 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
5363 DBUS_TYPE_UINT32_AS_STRING
5364 DBUS_TYPE_UINT32_AS_STRING
5365 DBUS_STRUCT_END_CHAR_AS_STRING,
5368 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
5369 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
5370 DBUS_TYPE_UINT32_AS_STRING
5371 DBUS_TYPE_UINT32_AS_STRING
5372 DBUS_STRUCT_END_CHAR_AS_STRING,
5376 function(&array, user_data);
5378 dbus_message_iter_close_container(&value, &array);
5379 dbus_message_iter_close_container(&entry, &value);
5380 dbus_message_iter_close_container(dict, &entry);
5384 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
5386 DBusMessageIter dict;
5387 const char *type = "passive";
5388 struct interface_scan_data *data = user_data;
5390 supplicant_dbus_dict_open(iter, &dict);
5392 if (data && data->scan_params) {
5395 supplicant_dbus_dict_append_basic(&dict, "Type",
5396 DBUS_TYPE_STRING, &type);
5398 #if defined TIZEN_EXT
5399 SUPPLICANT_DBG("[specific_scan] num_ssids %d",
5400 data->scan_params->num_ssids);
5403 if (data->scan_params->ssids) {
5404 supplicant_dbus_dict_append_array(&dict, "SSIDs",
5409 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
5412 supplicant_dbus_dict_append_basic(&dict, "Type",
5413 DBUS_TYPE_STRING, &type);
5415 supplicant_dbus_dict_close(iter, &dict);
5418 static int interface_ready_to_scan(GSupplicantInterface *interface)
5423 if (!system_available)
5426 if (interface->scanning)
5429 switch (interface->state) {
5430 case G_SUPPLICANT_STATE_AUTHENTICATING:
5431 case G_SUPPLICANT_STATE_ASSOCIATING:
5432 case G_SUPPLICANT_STATE_ASSOCIATED:
5433 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
5434 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
5436 #if defined TIZEN_EXT
5437 case G_SUPPLICANT_STATE_DISABLED:
5439 case G_SUPPLICANT_STATE_UNKNOWN:
5441 case G_SUPPLICANT_STATE_UNKNOWN:
5442 case G_SUPPLICANT_STATE_DISABLED:
5444 case G_SUPPLICANT_STATE_DISCONNECTED:
5445 case G_SUPPLICANT_STATE_INACTIVE:
5446 case G_SUPPLICANT_STATE_SCANNING:
5447 case G_SUPPLICANT_STATE_COMPLETED:
5454 #if defined TIZEN_EXT_WIFI_MESH
5455 static void interface_abort_scan_result(const char *error,
5456 DBusMessageIter *iter, void *user_data)
5458 struct interface_scan_data *data = user_data;
5462 SUPPLICANT_DBG("error %s", error);
5469 data->callback(err, data->interface, data->user_data);
5474 int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
5475 GSupplicantInterfaceCallback callback, void *user_data)
5477 struct interface_scan_data *data;
5480 if (!interface->scanning)
5483 data = dbus_malloc0(sizeof(*data));
5487 data->interface = interface;
5488 data->path = g_strdup(interface->path);
5489 data->callback = callback;
5490 data->user_data = user_data;
5492 ret = supplicant_dbus_method_call(interface->path,
5493 SUPPLICANT_INTERFACE ".Interface", "AbortScan", NULL,
5494 interface_abort_scan_result, data, interface);
5505 int g_supplicant_interface_scan(GSupplicantInterface *interface,
5506 GSupplicantScanParams *scan_data,
5507 GSupplicantInterfaceCallback callback,
5510 struct interface_scan_data *data;
5513 ret = interface_ready_to_scan(interface);
5517 data = dbus_malloc0(sizeof(*data));
5521 data->interface = interface;
5522 data->path = g_strdup(interface->path);
5523 #if defined TIZEN_EXT
5524 data->interface->scan_callback = data->callback = callback;
5525 data->interface->scan_data = data->user_data = user_data;
5527 data->callback = callback;
5528 data->user_data = user_data;
5530 data->scan_params = scan_data;
5532 interface->scan_callback = callback;
5533 interface->scan_data = user_data;
5535 ret = supplicant_dbus_method_call(interface->path,
5536 SUPPLICANT_INTERFACE ".Interface", "Scan",
5537 interface_scan_params, interface_scan_result, data,
5548 #if defined TIZEN_EXT
5549 static void interface_signalpoll_result(const char *error,
5550 DBusMessageIter *iter, void *user_data)
5552 struct interface_signalpoll_data *data = user_data;
5554 dbus_int32_t maxspeed = 0;
5555 unsigned char strength = 0;
5556 DBusMessageIter sub_iter, dict;
5560 SUPPLICANT_DBG("error: %s", error);
5564 dbus_message_iter_get_arg_type(iter);
5565 dbus_message_iter_recurse(iter, &sub_iter);
5566 dbus_message_iter_recurse(&sub_iter, &dict);
5568 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
5569 DBusMessageIter entry, value;
5572 dbus_message_iter_recurse(&dict, &entry);
5573 dbus_message_iter_get_basic(&entry, &key);
5574 dbus_message_iter_next(&entry);
5575 dbus_message_iter_recurse(&entry, &value);
5577 switch (dbus_message_iter_get_arg_type(&value)) {
5578 case DBUS_TYPE_INT32:
5579 if (g_strcmp0(key, "linkspeed") == 0) {
5580 dbus_message_iter_get_basic(&value, &maxspeed);
5581 SUPPLICANT_DBG("linkspeed = %d", maxspeed);
5584 case DBUS_TYPE_BYTE:
5585 if (g_strcmp0(key, "rssi") == 0) {
5586 dbus_message_iter_get_basic(&value, &strength);
5587 SUPPLICANT_DBG("Strength = %d", strength);
5591 dbus_message_iter_next(&dict);
5596 data->callback(err, maxspeed, strength, data->user_data);
5602 int g_supplicant_interface_signalpoll(GSupplicantInterface *interface,
5603 GSupplicantMaxSpeedCallback callback,
5606 struct interface_signalpoll_data *data;
5612 if (!system_available)
5615 data = dbus_malloc0(sizeof(*data));
5619 data->interface = interface;
5620 data->path = g_strdup(interface->path);
5621 data->callback = callback;
5622 data->user_data = user_data;
5624 ret = supplicant_dbus_method_call(interface->path,
5625 SUPPLICANT_INTERFACE ".Interface", "SignalPoll",
5626 NULL, interface_signalpoll_result, data,
5638 static int parse_supplicant_error(DBusMessageIter *iter)
5640 int err = -ECONNABORTED;
5646 /* If the given passphrase is malformed wpa_s returns
5647 * "invalid message format" but this error should be interpreted as
5650 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
5651 dbus_message_iter_get_basic(iter, &key);
5652 if (strncmp(key, "psk", 3) == 0 ||
5653 strncmp(key, "wep_key", 7) == 0 ||
5654 strcmp(key, "invalid message format") == 0) {
5658 dbus_message_iter_next(iter);
5664 static void interface_select_network_result(const char *error,
5665 DBusMessageIter *iter, void *user_data)
5667 struct interface_connect_data *data = user_data;
5674 #if defined TIZEN_EXT
5675 SUPPLICANT_DBG("SelectNetwork errorFreq %s", error);
5677 SUPPLICANT_DBG("SelectNetwork error %s", error);
5679 err = parse_supplicant_error(iter);
5685 data->callback(err, data->interface, data->user_data);
5687 #if defined TIZEN_EXT
5688 g_free(data->ssid->ssid);
5689 g_free((char *)data->ssid->passphrase);
5695 static void interface_select_network_params(DBusMessageIter *iter,
5698 struct interface_connect_data *data = user_data;
5699 GSupplicantInterface *interface = data->interface;
5700 #if defined TIZEN_EXT
5701 GSupplicantSSID *ssid = data->ssid;
5704 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
5705 &interface->network_path);
5706 #if defined TIZEN_EXT
5707 if (!ssid->bssid_for_connect_len)
5708 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
5712 static void interface_add_network_result(const char *error,
5713 DBusMessageIter *iter, void *user_data)
5715 struct interface_connect_data *data = user_data;
5716 GSupplicantInterface *interface = data->interface;
5723 dbus_message_iter_get_basic(iter, &path);
5727 SUPPLICANT_DBG("PATH: %s", path);
5729 #if defined TIZEN_EXT
5730 if (interface->network_path)
5731 g_free(interface->network_path);
5733 interface->network_path = g_strdup(path);
5735 store_network_information(interface, data->ssid);
5737 #if defined TIZEN_EXT
5738 SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
5739 GSupplicantSSID *ssid = data->ssid;
5741 if (!ssid->bssid_for_connect_len)
5742 supplicant_dbus_method_call(data->interface->path,
5743 SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
5744 interface_select_network_params,
5745 interface_select_network_result, data,
5748 supplicant_dbus_method_call(data->interface->path,
5749 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
5750 interface_select_network_params,
5751 interface_select_network_result, data,
5754 supplicant_dbus_method_call(data->interface->path,
5755 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
5756 interface_select_network_params,
5757 interface_select_network_result, data,
5764 SUPPLICANT_DBG("AddNetwork error %s", error);
5766 if (interface_exists(data->interface, data->interface->path)) {
5767 err = parse_supplicant_error(iter);
5769 data->callback(err, data->interface, data->user_data);
5771 g_free(interface->network_path);
5772 interface->network_path = NULL;
5776 #if defined TIZEN_EXT
5777 g_free(data->ssid->ssid);
5778 g_free((char *)data->ssid->passphrase);
5784 static void add_network_security_none(DBusMessageIter *dict)
5786 const char *auth_alg = "OPEN";
5788 supplicant_dbus_dict_append_basic(dict, "auth_alg",
5789 DBUS_TYPE_STRING, &auth_alg);
5792 static void add_network_security_wep(DBusMessageIter *dict,
5793 GSupplicantSSID *ssid)
5795 const char *auth_alg = "OPEN SHARED";
5796 dbus_uint32_t key_index = 0;
5798 supplicant_dbus_dict_append_basic(dict, "auth_alg",
5799 DBUS_TYPE_STRING, &auth_alg);
5801 if (ssid->passphrase) {
5802 int size = strlen(ssid->passphrase);
5803 if (size == 10 || size == 26) {
5804 unsigned char *key = g_try_malloc(13);
5808 memset(tmp, 0, sizeof(tmp));
5812 for (i = 0; i < size / 2; i++) {
5813 memcpy(tmp, ssid->passphrase + (i * 2), 2);
5814 key[i] = (unsigned char) strtol(tmp, NULL, 16);
5817 supplicant_dbus_dict_append_fixed_array(dict,
5822 } else if (size == 5 || size == 13) {
5823 unsigned char *key = g_try_malloc(13);
5829 for (i = 0; i < size; i++)
5830 key[i] = (unsigned char) ssid->passphrase[i];
5832 supplicant_dbus_dict_append_fixed_array(dict,
5838 supplicant_dbus_dict_append_basic(dict,
5843 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
5844 DBUS_TYPE_UINT32, &key_index);
5848 static dbus_bool_t is_psk_raw_key(const char *psk)
5852 /* A raw key is always 64 bytes length... */
5853 if (strlen(psk) != 64)
5856 /* ... and its content is in hex representation */
5857 for (i = 0; i < 64; i++)
5858 if (!isxdigit((unsigned char) psk[i]))
5864 static unsigned char hexchar2bin(char c)
5866 if ((c >= '0') && (c <= '9'))
5868 else if ((c >= 'A') && (c <= 'F'))
5869 return c - 'A' + 10;
5870 else if ((c >= 'a') && (c <= 'f'))
5871 return c - 'a' + 10;
5876 static void hexstring2bin(const char *string, unsigned char *data,
5881 for (i = 0; i < data_len; i++)
5882 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
5883 hexchar2bin(string[i * 2 + 1]) << 0);
5886 static void add_network_security_psk(DBusMessageIter *dict,
5887 GSupplicantSSID *ssid)
5889 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
5890 const char *key = "psk";
5892 if (is_psk_raw_key(ssid->passphrase)) {
5893 unsigned char data[32];
5894 unsigned char *datap = data;
5896 /* The above pointer alias is required by D-Bus because
5897 * with D-Bus and GCC, non-heap-allocated arrays cannot
5898 * be passed directly by their base pointer. */
5900 hexstring2bin(ssid->passphrase, datap, sizeof(data));
5902 supplicant_dbus_dict_append_fixed_array(dict,
5903 key, DBUS_TYPE_BYTE,
5904 &datap, sizeof(data));
5906 supplicant_dbus_dict_append_basic(dict,
5907 key, DBUS_TYPE_STRING,
5912 static void add_network_security_tls(DBusMessageIter *dict,
5913 GSupplicantSSID *ssid)
5916 * For TLS, we at least need:
5917 * The client certificate
5918 * The client private key file
5919 * The client private key file password
5921 * The Authority certificate is optional.
5923 if (!ssid->client_cert_path)
5926 if (!ssid->private_key_path)
5929 #if !defined TIZEN_EXT
5930 if (!ssid->private_key_passphrase)
5934 if (ssid->ca_cert_path)
5935 supplicant_dbus_dict_append_basic(dict, "ca_cert",
5936 DBUS_TYPE_STRING, &ssid->ca_cert_path);
5938 supplicant_dbus_dict_append_basic(dict, "private_key",
5940 &ssid->private_key_path);
5941 #if !defined TIZEN_EXT
5942 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
5944 &ssid->private_key_passphrase);
5946 supplicant_dbus_dict_append_basic(dict, "client_cert",
5948 &ssid->client_cert_path);
5951 static void add_network_security_peap(DBusMessageIter *dict,
5952 GSupplicantSSID *ssid)
5957 * For PEAP/TTLS, we at least need
5958 * The authority certificate
5959 * The 2nd phase authentication method
5960 * The 2nd phase passphrase
5962 * The Client certificate is optional although strongly recommended
5963 * When setting it, we need in addition
5964 * The Client private key file
5965 * The Client private key file password
5967 if (!ssid->passphrase)
5970 if (!ssid->phase2_auth)
5973 if (ssid->client_cert_path) {
5974 if (!ssid->private_key_path)
5977 #if !defined TIZEN_EXT
5978 if (!ssid->private_key_passphrase)
5982 supplicant_dbus_dict_append_basic(dict, "client_cert",
5984 &ssid->client_cert_path);
5986 supplicant_dbus_dict_append_basic(dict, "private_key",
5988 &ssid->private_key_path);
5990 #if !defined TIZEN_EXT
5991 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
5993 &ssid->private_key_passphrase);
5998 if(g_strcmp0(ssid->phase2_auth, "GTC") == 0 && g_strcmp0(ssid->eap, "ttls") == 0)
5999 phase2_auth = g_strdup_printf("autheap=%s", ssid->phase2_auth);
6000 else if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
6001 phase2_auth = g_strdup_printf("autheap=%s",
6002 ssid->phase2_auth + strlen("EAP-"));
6004 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
6006 supplicant_dbus_dict_append_basic(dict, "password",
6010 if (ssid->ca_cert_path)
6011 supplicant_dbus_dict_append_basic(dict, "ca_cert",
6013 &ssid->ca_cert_path);
6015 supplicant_dbus_dict_append_basic(dict, "phase2",
6019 g_free(phase2_auth);
6022 #if defined TIZEN_EXT
6023 static void add_network_security_aka_sim(DBusMessageIter *dict,
6024 GSupplicantSSID *ssid)
6026 if (!ssid->passphrase)
6029 supplicant_dbus_dict_append_basic(dict, "password",
6034 static void add_network_security_fast(DBusMessageIter *dict,
6035 GSupplicantSSID *ssid)
6038 * For FAST, we at least need:
6040 * phase1 (provisiong information)
6044 /* Allow provisioing both authenticated and unauthenticated */
6045 const char *phase1 = "fast_provisioning=2";
6046 supplicant_dbus_dict_append_basic(dict, "phase1",
6050 SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
6052 supplicant_dbus_dict_append_basic(dict, "pac_file",
6056 supplicant_dbus_dict_append_basic(dict, "password",
6062 static void add_network_security_eap(DBusMessageIter *dict,
6063 GSupplicantSSID *ssid)
6067 #if defined TIZEN_EXT
6070 if (!ssid->eap || !ssid->identity)
6074 if (g_strcmp0(ssid->eap, "tls") == 0) {
6075 add_network_security_tls(dict, ssid);
6076 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
6077 g_strcmp0(ssid->eap, "ttls") == 0) {
6078 #if defined TIZEN_EXT
6079 if (!ssid->identity)
6082 add_network_security_peap(dict, ssid);
6084 #if defined TIZEN_EXT
6085 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
6086 g_strcmp0(ssid->eap, "aka") == 0 ||
6087 g_strcmp0(ssid->eap, "aka'") == 0) {
6088 add_network_security_aka_sim(dict, ssid);
6089 } else if (g_strcmp0(ssid->eap, "pwd") == 0) {
6090 if(!ssid->passphrase)
6092 supplicant_dbus_dict_append_basic(dict, "password",
6095 } else if (g_strcmp0(ssid->eap, "fast") == 0){
6096 if (!ssid->identity || !ssid->passphrase)
6099 add_network_security_fast(dict, ssid);
6104 eap_value = g_ascii_strup(ssid->eap, -1);
6106 supplicant_dbus_dict_append_basic(dict, "eap",
6109 #if defined TIZEN_EXT
6110 if (ssid->identity != NULL)
6111 supplicant_dbus_dict_append_basic(dict, "identity",
6115 supplicant_dbus_dict_append_basic(dict, "identity",
6119 if(ssid->anonymous_identity)
6120 supplicant_dbus_dict_append_basic(dict, "anonymous_identity",
6122 &ssid->anonymous_identity);
6124 if(ssid->subject_match)
6125 supplicant_dbus_dict_append_basic(dict, "subject_match",
6127 &ssid->subject_match);
6129 if(ssid->altsubject_match)
6130 supplicant_dbus_dict_append_basic(dict, "altsubject_match",
6132 &ssid->altsubject_match);
6134 if(ssid->domain_suffix_match)
6135 supplicant_dbus_dict_append_basic(dict, "domain_suffix_match",
6137 &ssid->domain_suffix_match);
6139 if(ssid->domain_match)
6140 supplicant_dbus_dict_append_basic(dict, "domain_match",
6142 &ssid->domain_match);
6147 static void add_network_security_ciphers(DBusMessageIter *dict,
6148 GSupplicantSSID *ssid)
6150 unsigned int p_cipher, g_cipher, i;
6151 char *pairwise, *group;
6152 char *pair_ciphers[4];
6153 char *group_ciphers[5];
6155 p_cipher = ssid->pairwise_cipher;
6156 g_cipher = ssid->group_cipher;
6158 if (p_cipher == 0 && g_cipher == 0)
6163 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
6164 pair_ciphers[i++] = "CCMP";
6166 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
6167 pair_ciphers[i++] = "TKIP";
6169 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
6170 pair_ciphers[i++] = "NONE";
6172 pair_ciphers[i] = NULL;
6176 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
6177 group_ciphers[i++] = "CCMP";
6179 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
6180 group_ciphers[i++] = "TKIP";
6182 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
6183 group_ciphers[i++] = "WEP104";
6185 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
6186 group_ciphers[i++] = "WEP40";
6188 group_ciphers[i] = NULL;
6190 pairwise = g_strjoinv(" ", pair_ciphers);
6191 group = g_strjoinv(" ", group_ciphers);
6193 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
6195 supplicant_dbus_dict_append_basic(dict, "pairwise",
6198 supplicant_dbus_dict_append_basic(dict, "group",
6206 static void add_network_security_proto(DBusMessageIter *dict,
6207 GSupplicantSSID *ssid)
6209 unsigned int protocol, i;
6213 protocol = ssid->protocol;
6220 if (protocol & G_SUPPLICANT_PROTO_RSN)
6221 protos[i++] = "RSN";
6223 if (protocol & G_SUPPLICANT_PROTO_WPA)
6224 protos[i++] = "WPA";
6228 proto = g_strjoinv(" ", protos);
6230 SUPPLICANT_DBG("proto %s", proto);
6232 supplicant_dbus_dict_append_basic(dict, "proto",
6239 #if defined TIZEN_EXT
6240 static void add_network_ieee80211w(DBusMessageIter *dict, GSupplicantSSID *ssid)
6242 if (ssid->security != G_SUPPLICANT_SECURITY_SAE
6243 && ssid->security != G_SUPPLICANT_SECURITY_OWE)
6246 supplicant_dbus_dict_append_basic(dict, "ieee80211w", DBUS_TYPE_UINT32,
6251 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
6255 switch (ssid->security) {
6256 case G_SUPPLICANT_SECURITY_NONE:
6258 add_network_security_none(dict);
6259 add_network_security_ciphers(dict, ssid);
6261 case G_SUPPLICANT_SECURITY_UNKNOWN:
6262 case G_SUPPLICANT_SECURITY_WEP:
6264 add_network_security_wep(dict, ssid);
6265 add_network_security_ciphers(dict, ssid);
6267 case G_SUPPLICANT_SECURITY_PSK:
6268 key_mgmt = "WPA-PSK";
6269 add_network_security_psk(dict, ssid);
6270 add_network_security_ciphers(dict, ssid);
6271 add_network_security_proto(dict, ssid);
6273 case G_SUPPLICANT_SECURITY_IEEE8021X:
6274 key_mgmt = "WPA-EAP";
6275 add_network_security_eap(dict, ssid);
6276 add_network_security_ciphers(dict, ssid);
6277 add_network_security_proto(dict, ssid);
6279 #if defined TIZEN_EXT
6280 case G_SUPPLICANT_SECURITY_FT_PSK:
6281 key_mgmt = "FT-PSK";
6282 add_network_security_psk(dict, ssid);
6283 add_network_security_ciphers(dict, ssid);
6284 add_network_security_proto(dict, ssid);
6286 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
6287 key_mgmt = "FT-EAP";
6288 add_network_security_eap(dict, ssid);
6289 add_network_security_ciphers(dict, ssid);
6290 add_network_security_proto(dict, ssid);
6292 case G_SUPPLICANT_SECURITY_SAE:
6294 add_network_security_psk(dict, ssid);
6296 case G_SUPPLICANT_SECURITY_OWE:
6298 add_network_security_ciphers(dict, ssid);
6299 add_network_security_proto(dict, ssid);
6304 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
6305 DBUS_TYPE_STRING, &key_mgmt);
6308 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
6312 switch (ssid->mode) {
6313 case G_SUPPLICANT_MODE_UNKNOWN:
6314 case G_SUPPLICANT_MODE_INFRA:
6317 case G_SUPPLICANT_MODE_IBSS:
6320 case G_SUPPLICANT_MODE_MASTER:
6323 #if defined TIZEN_EXT_WIFI_MESH
6324 case G_SUPPLICANT_MODE_MESH:
6330 supplicant_dbus_dict_append_basic(dict, "mode",
6331 DBUS_TYPE_UINT32, &mode);
6334 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
6336 DBusMessageIter dict;
6337 struct interface_connect_data *data = user_data;
6338 GSupplicantSSID *ssid = data->ssid;
6340 supplicant_dbus_dict_open(iter, &dict);
6342 if (ssid->scan_ssid)
6343 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
6344 DBUS_TYPE_UINT32, &ssid->scan_ssid);
6347 supplicant_dbus_dict_append_basic(&dict, "frequency",
6348 DBUS_TYPE_UINT32, &ssid->freq);
6351 supplicant_dbus_dict_append_basic(&dict, "bgscan",
6352 DBUS_TYPE_STRING, &ssid->bgscan);
6354 add_network_mode(&dict, ssid);
6356 add_network_security(&dict, ssid);
6358 #if defined TIZEN_EXT
6359 add_network_ieee80211w(&dict, ssid);
6362 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
6363 DBUS_TYPE_BYTE, &ssid->ssid,
6366 #if defined TIZEN_EXT
6369 bssid = g_try_malloc0(18);
6370 if (bssid == NULL) {
6371 SUPPLICANT_DBG("memory allocation error");
6372 supplicant_dbus_dict_close(iter, &dict);
6376 if (ssid->bssid_for_connect_len)
6377 snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
6378 ssid->bssid_for_connect[0], ssid->bssid_for_connect[1], ssid->bssid_for_connect[2],
6379 ssid->bssid_for_connect[3], ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
6381 snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
6382 ssid->bssid[0], ssid->bssid[1], ssid->bssid[2],
6383 ssid->bssid[3], ssid->bssid[4], ssid->bssid[5]);
6385 supplicant_dbus_dict_append_basic(&dict, "bssid",
6386 DBUS_TYPE_STRING, &bssid);
6391 supplicant_dbus_dict_close(iter, &dict);
6394 static void interface_wps_start_result(const char *error,
6395 DBusMessageIter *iter, void *user_data)
6397 struct interface_connect_data *data = user_data;
6404 SUPPLICANT_DBG("error: %s", error);
6405 err = parse_supplicant_error(iter);
6409 data->callback(err, data->interface, data->user_data);
6416 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
6418 struct interface_connect_data *data = user_data;
6419 GSupplicantSSID *ssid = data->ssid;
6420 const char *role = "enrollee", *type;
6421 DBusMessageIter dict;
6425 supplicant_dbus_dict_open(iter, &dict);
6427 supplicant_dbus_dict_append_basic(&dict, "Role",
6428 DBUS_TYPE_STRING, &role);
6431 if (ssid->pin_wps) {
6433 supplicant_dbus_dict_append_basic(&dict, "Pin",
6434 DBUS_TYPE_STRING, &ssid->pin_wps);
6437 supplicant_dbus_dict_append_basic(&dict, "Type",
6438 DBUS_TYPE_STRING, &type);
6440 #if defined TIZEN_EXT
6442 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
6443 DBUS_TYPE_BYTE, &ssid->bssid, 6);
6446 supplicant_dbus_dict_close(iter, &dict);
6449 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
6451 struct interface_connect_data *data = user_data;
6456 SUPPLICANT_DBG("error: %s", error);
6463 #if defined TIZEN_EXT
6464 GSupplicantSSID *ssid = data->ssid;
6465 if (ssid->pin_wps != NULL) {
6466 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
6467 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
6474 supplicant_dbus_method_call(data->interface->path,
6475 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
6476 interface_add_wps_params,
6477 interface_wps_start_result, data, NULL);
6480 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
6482 dbus_bool_t credentials = TRUE;
6486 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
6490 #if defined TIZEN_EXT
6491 #define NETCONFIG_SERVICE "net.netconfig"
6492 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
6493 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
6495 struct dec_method_call_data {
6496 struct interface_connect_data *data;
6497 DBusPendingCall *pending_call;
6500 static struct dec_method_call_data decrypt_request_data;
6502 static void crypt_method_call_cancel(void)
6504 if (decrypt_request_data.pending_call) {
6505 dbus_pending_call_cancel(decrypt_request_data.pending_call);
6506 dbus_pending_call_unref(decrypt_request_data.pending_call);
6507 decrypt_request_data.pending_call = NULL;
6510 g_free(decrypt_request_data.data->path);
6511 g_free(decrypt_request_data.data->ssid);
6512 dbus_free(decrypt_request_data.data);
6513 decrypt_request_data.data = NULL;
6516 static void decryption_request_reply(DBusPendingCall *call,
6521 DBusMessageIter args;
6524 struct interface_connect_data *data = user_data;
6528 reply = dbus_pending_call_steal_reply(call);
6530 dbus_error_init(&error);
6531 if (dbus_set_error_from_message(&error, reply)) {
6532 SUPPLICANT_DBG("decryption_request_reply() %s %s", error.name, error.message);
6533 dbus_error_free(&error);
6538 if (dbus_message_iter_init(reply, &args) == FALSE) {
6539 SUPPLICANT_DBG("dbus_message_iter_init() failed");
6544 dbus_message_iter_get_basic(&args, &out_data);
6545 data->ssid->passphrase = g_strdup((const gchar *)out_data);
6547 ret = supplicant_dbus_method_call(data->interface->path,
6548 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
6549 interface_add_network_params,
6550 interface_add_network_result, data,
6555 SUPPLICANT_DBG("AddNetwork failed %d", ret);
6556 callback_assoc_failed(decrypt_request_data.data->user_data);
6558 g_free(data->ssid->ssid);
6559 g_free((char *)data->ssid->passphrase);
6564 dbus_message_unref(reply);
6565 dbus_pending_call_unref(call);
6567 decrypt_request_data.pending_call = NULL;
6568 decrypt_request_data.data = NULL;
6571 static int send_decryption_request(const char *passphrase,
6572 struct interface_connect_data *data)
6574 DBusMessage *msg = NULL;
6575 DBusPendingCall *call;
6577 SUPPLICANT_DBG("Decryption request");
6580 SUPPLICANT_DBG("Invalid parameter");
6587 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
6588 NETCONFIG_WIFI_INTERFACE, "DecryptPassphrase");
6592 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
6595 if (!dbus_connection_send_with_reply(connection, msg,
6596 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
6597 dbus_message_unref(msg);
6602 dbus_message_unref(msg);
6606 decrypt_request_data.pending_call = call;
6607 decrypt_request_data.data = data;
6609 dbus_pending_call_set_notify(call, decryption_request_reply, data, NULL);
6610 dbus_message_unref(msg);
6612 SUPPLICANT_DBG("Decryption request succeeded");
6618 int g_supplicant_interface_connect(GSupplicantInterface *interface,
6619 GSupplicantSSID *ssid,
6620 GSupplicantInterfaceCallback callback,
6623 struct interface_connect_data *data;
6624 struct interface_data *intf_data;
6632 if (!system_available)
6635 /* TODO: Check if we're already connected and switch */
6637 data = dbus_malloc0(sizeof(*data));
6641 data->interface = interface;
6642 data->path = g_strdup(interface->path);
6643 data->callback = callback;
6645 data->user_data = user_data;
6647 if (ssid->use_wps) {
6648 g_free(interface->wps_cred.key);
6649 memset(&interface->wps_cred, 0,
6650 sizeof(struct _GSupplicantWpsCredentials));
6652 ret = supplicant_dbus_property_set(interface->path,
6653 SUPPLICANT_INTERFACE ".Interface.WPS",
6654 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
6655 wps_process_credentials, wps_start, data, interface);
6657 /* By the time there is a request for connect and the network
6658 * path is not NULL it means that connman has not removed the
6659 * previous network pointer. This can happen in the case AP
6660 * deauthenticated client and connman does not remove the
6661 * previously connected network pointer. This causes supplicant
6662 * to reallocate the memory for struct wpa_ssid again even if it
6663 * is the same SSID. This causes memory usage of wpa_supplicnat
6664 * to go high. The idea here is that if the previously connected
6665 * network is not removed at the time of next connection attempt
6666 * check if the network path is not NULL. In case it is non-NULL
6667 * first remove the network and then once removal is successful, add
6671 if (interface->network_path != NULL) {
6676 * If this add network is for the same network for
6677 * which wpa_supplicant already has a profile then do
6678 * not need to add another profile. Only if the
6679 * profile that needs to get added is different from
6680 * what is there in wpa_s delete the current one. A
6681 * network is identified by its SSID, security_type
6682 * and passphrase (private passphrase in case security
6685 if (compare_network_parameters(interface, ssid)) {
6689 intf_data = dbus_malloc0(sizeof(*intf_data));
6693 intf_data->interface = interface;
6694 intf_data->path = g_strdup(interface->path);
6695 intf_data->callback = callback;
6696 intf_data->ssid = ssid;
6697 intf_data->user_data = user_data;
6698 intf_data->network_remove_in_progress = TRUE;
6699 network_remove(intf_data);
6701 #if defined TIZEN_EXT
6702 if (ssid->passphrase &&
6703 g_strcmp0(ssid->passphrase, "") != 0 &&
6704 #if defined TIZEN_EXT_WIFI_MESH
6705 ssid->mode != G_SUPPLICANT_MODE_MESH &&
6708 ret = send_decryption_request(ssid->passphrase, data);
6710 SUPPLICANT_DBG("Decryption request failed %d", ret);
6713 ret = supplicant_dbus_method_call(interface->path,
6714 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
6715 interface_add_network_params,
6716 interface_add_network_result, data,
6727 return -EINPROGRESS;
6730 static void network_remove_result(const char *error,
6731 DBusMessageIter *iter, void *user_data)
6733 struct interface_data *data = user_data;
6734 struct interface_connect_data *connect_data;
6741 SUPPLICANT_DBG("error: %s", error);
6743 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
6745 result = -ECONNABORTED;
6748 g_free(data->interface->network_path);
6749 data->interface->network_path = NULL;
6751 remove_network_information(data->interface);
6753 if (data->network_remove_in_progress == TRUE) {
6754 data->network_remove_in_progress = FALSE;
6755 connect_data = dbus_malloc0(sizeof(*connect_data));
6759 connect_data->interface = data->interface;
6760 connect_data->path = g_strdup(data->path);
6761 connect_data->callback = data->callback;
6762 connect_data->ssid = data->ssid;
6763 connect_data->user_data = data->user_data;
6765 #if defined TIZEN_EXT
6767 if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
6768 && !data->ssid->eap) {
6769 ret = send_decryption_request(data->ssid->passphrase, connect_data);
6771 SUPPLICANT_DBG("Decryption request failed %d", ret);
6772 g_free(connect_data->ssid);
6773 g_free(connect_data->path);
6774 dbus_free(connect_data);
6778 supplicant_dbus_method_call(data->interface->path,
6779 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
6780 interface_add_network_params,
6781 interface_add_network_result, connect_data,
6782 connect_data->interface);
6785 data->callback(result, data->interface, data->user_data);
6791 static void network_remove_params(DBusMessageIter *iter, void *user_data)
6793 struct interface_data *data = user_data;
6794 const char *path = data->interface->network_path;
6796 SUPPLICANT_DBG("path %s", path);
6798 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
6801 static int network_remove(struct interface_data *data)
6803 GSupplicantInterface *interface = data->interface;
6807 #if defined TIZEN_EXT
6808 GSupplicantInterface *intf = NULL;
6810 * Check if 'interface' is valid
6812 intf = g_hash_table_lookup(interface_table, interface->path);
6817 return supplicant_dbus_method_call(interface->path,
6818 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
6819 network_remove_params, network_remove_result, data,
6823 static void interface_disconnect_result(const char *error,
6824 DBusMessageIter *iter, void *user_data)
6826 struct interface_data *data = user_data;
6833 SUPPLICANT_DBG("error: %s", error);
6835 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
6837 result = -ECONNABORTED;
6840 /* If we are disconnecting from previous WPS successful
6841 * association. i.e.: it did not went through AddNetwork,
6842 * and interface->network_path was never set. */
6843 if (!data->interface->network_path) {
6845 data->callback(result, data->interface,
6853 if (result < 0 && data->callback) {
6854 data->callback(result, data->interface, data->user_data);
6855 data->callback = NULL;
6858 if (result != -ECONNABORTED) {
6859 if (network_remove(data) < 0) {
6869 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
6870 GSupplicantInterfaceCallback callback,
6873 struct interface_data *data;
6881 if (!system_available)
6883 #if defined TIZEN_EXT
6884 if (decrypt_request_data.pending_call &&
6885 decrypt_request_data.data &&
6886 decrypt_request_data.data->user_data == user_data) {
6888 callback_assoc_failed(decrypt_request_data.data->user_data);
6889 crypt_method_call_cancel();
6894 data = dbus_malloc0(sizeof(*data));
6898 data->interface = interface;
6899 data->path = g_strdup(interface->path);
6900 data->callback = callback;
6901 data->user_data = user_data;
6903 ret = supplicant_dbus_method_call(interface->path,
6904 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
6905 NULL, interface_disconnect_result, data,
6916 static void interface_p2p_find_result(const char *error,
6917 DBusMessageIter *iter, void *user_data)
6919 struct interface_scan_data *data = user_data;
6922 SUPPLICANT_DBG("error %s", error);
6927 if (interface_exists(data->interface, data->path)) {
6928 if (!data->interface->ready)
6931 data->interface->p2p_finding = true;
6935 data->callback(err, data->interface, data->user_data);
6941 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
6943 DBusMessageIter dict;
6945 supplicant_dbus_dict_open(iter, &dict);
6946 supplicant_dbus_dict_close(iter, &dict);
6949 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
6950 GSupplicantInterfaceCallback callback,
6953 struct interface_scan_data *data;
6956 if (!interface->p2p_support)
6959 ret = interface_ready_to_scan(interface);
6960 if (ret && ret != -EALREADY)
6963 data = dbus_malloc0(sizeof(*data));
6967 data->interface = interface;
6968 data->path = g_strdup(interface->path);
6969 data->callback = callback;
6970 data->user_data = user_data;
6972 ret = supplicant_dbus_method_call(interface->path,
6973 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
6974 interface_p2p_find_params, interface_p2p_find_result,
6984 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
6989 return interface->p2p_finding;
6992 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
6994 if (!interface->p2p_finding)
6999 interface->p2p_finding = false;
7001 return supplicant_dbus_method_call(interface->path,
7002 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
7003 NULL, NULL, NULL, NULL);
7006 static void interface_p2p_connect_result(const char *error,
7007 DBusMessageIter *iter, void *user_data)
7009 struct interface_connect_data *data = user_data;
7015 SUPPLICANT_DBG("error: %s", error);
7016 err = parse_supplicant_error(iter);
7020 data->callback(err, data->interface, data->user_data);
7023 g_free(data->peer->wps_pin);
7024 g_free(data->peer->path);
7029 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
7031 struct interface_connect_data *data = user_data;
7032 const char *wps = "pbc";
7033 DBusMessageIter dict;
7038 supplicant_dbus_dict_open(iter, &dict);
7040 if (data->peer->master)
7043 if (data->peer->wps_pin)
7046 supplicant_dbus_dict_append_basic(&dict, "peer",
7047 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
7048 supplicant_dbus_dict_append_basic(&dict, "wps_method",
7049 DBUS_TYPE_STRING, &wps);
7050 if (data->peer->wps_pin) {
7051 supplicant_dbus_dict_append_basic(&dict, "pin",
7052 DBUS_TYPE_STRING, &data->peer->wps_pin);
7055 supplicant_dbus_dict_append_basic(&dict, "go_intent",
7056 DBUS_TYPE_INT32, &go_intent);
7058 supplicant_dbus_dict_close(iter, &dict);
7061 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
7062 GSupplicantPeerParams *peer_params,
7063 GSupplicantInterfaceCallback callback,
7066 struct interface_connect_data *data;
7071 if (!interface->p2p_support)
7074 data = dbus_malloc0(sizeof(*data));
7078 data->interface = interface;
7079 data->path = g_strdup(interface->path);
7080 data->peer = peer_params;
7081 data->callback = callback;
7082 data->user_data = user_data;
7084 ret = supplicant_dbus_method_call(interface->path,
7085 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
7086 interface_p2p_connect_params, interface_p2p_connect_result,
7094 return -EINPROGRESS;
7097 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
7098 GSupplicantPeerParams *peer_params)
7100 GSupplicantPeer *peer;
7106 if (!interface->p2p_support)
7109 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
7113 for (list = peer->groups; list; list = list->next, count++) {
7114 const char *group_obj_path = list->data;
7115 GSupplicantInterface *g_interface;
7116 GSupplicantGroup *group;
7118 group = g_hash_table_lookup(group_mapping, group_obj_path);
7119 if (!group || !group->interface)
7122 g_interface = group->interface;
7123 supplicant_dbus_method_call(g_interface->path,
7124 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
7125 "Disconnect", NULL, NULL, NULL, g_interface);
7128 if (count == 0 && peer->current_group_iface) {
7129 supplicant_dbus_method_call(peer->current_group_iface->path,
7130 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
7131 "Disconnect", NULL, NULL, NULL,
7132 peer->current_group_iface->path);
7135 peer->current_group_iface = NULL;
7137 return -EINPROGRESS;
7140 struct p2p_service_data {
7142 GSupplicantInterface *interface;
7143 GSupplicantP2PServiceParams *service;
7144 GSupplicantInterfaceCallback callback;
7148 static void interface_p2p_service_result(const char *error,
7149 DBusMessageIter *iter, void *user_data)
7151 struct p2p_service_data *data = user_data;
7154 SUPPLICANT_DBG("%s result - %s", data->registration ?
7155 "Registration" : "Deletion",
7156 error ? error : "Success");
7161 data->callback(result, data->interface, data->user_data);
7163 g_free(data->service->query);
7164 g_free(data->service->response);
7165 g_free(data->service->service);
7166 g_free(data->service->wfd_ies);
7167 g_free(data->service);
7171 static void interface_p2p_service_params(DBusMessageIter *iter,
7174 struct p2p_service_data *data = user_data;
7175 GSupplicantP2PServiceParams *service;
7176 DBusMessageIter dict;
7181 service = data->service;
7183 supplicant_dbus_dict_open(iter, &dict);
7185 if (service->query && service->response) {
7187 supplicant_dbus_dict_append_basic(&dict, "service_type",
7188 DBUS_TYPE_STRING, &type);
7189 supplicant_dbus_dict_append_fixed_array(&dict, "query",
7190 DBUS_TYPE_BYTE, &service->query,
7191 service->query_length);
7192 supplicant_dbus_dict_append_fixed_array(&dict, "response",
7193 DBUS_TYPE_BYTE, &service->response,
7194 service->response_length);
7195 } else if (service->version && service->service) {
7197 supplicant_dbus_dict_append_basic(&dict, "service_type",
7198 DBUS_TYPE_STRING, &type);
7199 supplicant_dbus_dict_append_basic(&dict, "version",
7200 DBUS_TYPE_INT32, &service->version);
7201 supplicant_dbus_dict_append_basic(&dict, "service",
7202 DBUS_TYPE_STRING, &service->service);
7205 supplicant_dbus_dict_close(iter, &dict);
7208 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
7209 GSupplicantInterfaceCallback callback,
7210 GSupplicantP2PServiceParams *p2p_service_params,
7213 struct p2p_service_data *data;
7218 if (!interface->p2p_support)
7221 data = dbus_malloc0(sizeof(*data));
7225 data->registration = true;
7226 data->interface = interface;
7227 data->service = p2p_service_params;
7228 data->callback = callback;
7229 data->user_data = user_data;
7231 ret = supplicant_dbus_method_call(interface->path,
7232 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
7233 interface_p2p_service_params, interface_p2p_service_result,
7240 return -EINPROGRESS;
7243 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
7244 GSupplicantP2PServiceParams *p2p_service_params)
7246 struct p2p_service_data *data;
7251 if (!interface->p2p_support)
7254 data = dbus_malloc0(sizeof(*data));
7258 data->interface = interface;
7259 data->service = p2p_service_params;
7261 ret = supplicant_dbus_method_call(interface->path,
7262 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
7263 interface_p2p_service_params, interface_p2p_service_result,
7270 return -EINPROGRESS;
7273 struct p2p_listen_data {
7278 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
7280 struct p2p_listen_data *params = user_data;
7281 DBusMessageIter dict;
7283 supplicant_dbus_dict_open(iter, &dict);
7285 supplicant_dbus_dict_append_basic(&dict, "period",
7286 DBUS_TYPE_INT32, ¶ms->period);
7287 supplicant_dbus_dict_append_basic(&dict, "interval",
7288 DBUS_TYPE_INT32, ¶ms->interval);
7289 supplicant_dbus_dict_close(iter, &dict);
7292 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
7293 int period, int interval)
7295 struct p2p_listen_data params;
7299 if (!interface->p2p_support)
7302 params.period = period;
7303 params.interval = interval;
7305 return supplicant_dbus_method_call(interface->path,
7306 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
7307 "ExtendedListen", interface_p2p_listen_params,
7308 NULL, ¶ms, NULL);
7311 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
7313 struct p2p_service_data *data = user_data;
7314 GSupplicantP2PServiceParams *service = data->service;
7315 DBusMessageIter array;
7317 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
7319 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
7320 DBUS_TYPE_BYTE_AS_STRING, &array);
7322 if (service->wfd_ies && service->wfd_ies_length > 0) {
7323 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
7324 &service->wfd_ies, service->wfd_ies_length);
7327 dbus_message_iter_close_container(iter, &array);
7330 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
7331 GSupplicantInterfaceCallback callback,
7334 struct p2p_service_data *data;
7339 if (!system_available)
7342 data = dbus_malloc0(sizeof(*data));
7346 data->service = p2p_service_params;
7347 data->callback = callback;
7348 data->user_data = user_data;
7350 if (p2p_service_params->wfd_ies)
7351 data->registration = true;
7353 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
7354 SUPPLICANT_INTERFACE, "WFDIEs",
7355 DBUS_TYPE_ARRAY_AS_STRING
7356 DBUS_TYPE_BYTE_AS_STRING,
7358 interface_p2p_service_result,
7360 if (ret < 0 && ret != -EINPROGRESS) {
7365 return -EINPROGRESS;
7369 static const char *g_supplicant_rule0 = "type=signal,"
7370 "path=" DBUS_PATH_DBUS ","
7371 "sender=" DBUS_SERVICE_DBUS ","
7372 "interface=" DBUS_INTERFACE_DBUS ","
7373 "member=NameOwnerChanged,"
7374 "arg0=" SUPPLICANT_SERVICE;
7375 static const char *g_supplicant_rule1 = "type=signal,"
7376 "interface=" SUPPLICANT_INTERFACE;
7377 static const char *g_supplicant_rule2 = "type=signal,"
7378 "interface=" SUPPLICANT_INTERFACE ".Interface";
7379 static const char *g_supplicant_rule3 = "type=signal,"
7380 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
7381 static const char *g_supplicant_rule4 = "type=signal,"
7382 "interface=" SUPPLICANT_INTERFACE ".BSS";
7383 static const char *g_supplicant_rule5 = "type=signal,"
7384 "interface=" SUPPLICANT_INTERFACE ".Network";
7385 #if !defined TIZEN_EXT
7386 static const char *g_supplicant_rule6 = "type=signal,"
7387 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
7388 static const char *g_supplicant_rule7 = "type=signal,"
7389 "interface=" SUPPLICANT_INTERFACE ".Peer";
7390 static const char *g_supplicant_rule8 = "type=signal,"
7391 "interface=" SUPPLICANT_INTERFACE ".Group";
7393 #if defined TIZEN_EXT_WIFI_MESH
7394 static const char *g_supplicant_rule9 = "type=signal,"
7395 "interface=" SUPPLICANT_INTERFACE ".Interface.Mesh";
7398 static void invoke_introspect_method(void)
7400 DBusMessage *message;
7402 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
7404 DBUS_INTERFACE_INTROSPECTABLE,
7410 dbus_message_set_no_reply(message, TRUE);
7411 dbus_connection_send(connection, message, NULL);
7412 dbus_message_unref(message);
7415 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
7417 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
7421 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
7423 dbus_connection_unref(connection);
7428 callbacks_pointer = callbacks;
7431 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
7432 NULL, remove_interface);
7434 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
7436 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
7438 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
7440 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
7442 config_file_table = g_hash_table_new_full(g_str_hash, g_str_equal,
7445 supplicant_dbus_setup(connection);
7447 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
7448 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
7449 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
7450 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
7451 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
7452 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
7453 #if defined TIZEN_EXT
7454 dbus_bus_add_match(connection,
7455 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
7456 "member=ChangeState", NULL);
7458 #if !defined TIZEN_EXT
7459 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
7460 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
7461 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
7463 #if defined TIZEN_EXT_WIFI_MESH
7464 dbus_bus_add_match(connection, g_supplicant_rule9, NULL);
7466 dbus_connection_flush(connection);
7468 if (dbus_bus_name_has_owner(connection,
7469 SUPPLICANT_SERVICE, NULL)) {
7470 system_available = TRUE;
7471 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
7472 SUPPLICANT_INTERFACE,
7473 service_property, NULL, NULL);
7475 invoke_introspect_method();
7480 static void unregister_interface_remove_params(DBusMessageIter *iter,
7483 const char *path = user_data;
7485 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
7490 static void unregister_remove_interface(gpointer key, gpointer value,
7493 GSupplicantInterface *interface = value;
7495 supplicant_dbus_method_call(SUPPLICANT_PATH,
7496 SUPPLICANT_INTERFACE,
7498 unregister_interface_remove_params,
7499 NULL, interface->path, NULL);
7502 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
7507 #if defined TIZEN_EXT_WIFI_MESH
7508 dbus_bus_remove_match(connection, g_supplicant_rule9, NULL);
7510 #if !defined TIZEN_EXT
7511 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
7512 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
7513 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
7515 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
7516 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
7517 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
7518 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
7519 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
7520 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
7521 dbus_connection_flush(connection);
7523 dbus_connection_remove_filter(connection,
7524 g_supplicant_filter, NULL);
7527 if (config_file_table) {
7528 g_hash_table_destroy(config_file_table);
7529 config_file_table = NULL;
7533 g_hash_table_destroy(bss_mapping);
7538 g_hash_table_destroy(peer_mapping);
7539 peer_mapping = NULL;
7542 if (group_mapping) {
7543 g_hash_table_destroy(group_mapping);
7544 group_mapping = NULL;
7547 if (interface_table) {
7548 g_hash_table_foreach(interface_table,
7549 unregister_remove_interface, NULL);
7550 g_hash_table_destroy(interface_table);
7551 interface_table = NULL;
7554 if (system_available)
7555 callback_system_killed();
7558 dbus_connection_unref(connection);
7562 callbacks_pointer = NULL;