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"
47 #define IEEE80211_CAP_ESS 0x0001
48 #define IEEE80211_CAP_IBSS 0x0002
49 #define IEEE80211_CAP_PRIVACY 0x0010
52 #define WLAN_EID_HT_CAP 45
53 #define WLAN_EID_VHT_CAP 191
54 #define WLAN_EID_SUPP_RATES 1
55 #define WLAN_EID_EXT_SUPP_RATES 50
56 #define COUNTRY_CODE_LENGTH 2
57 #define WIFI_BSSID_LEN_MAX 6
61 #define LAST_CONNECTED_TIMEOUT (5 * 60)
62 #define ASSOC_REJECT_TIMEOUT 10
63 #define FREQ_RANGE_24GHZ_CHANNEL_1 2412
64 #define FREQ_RANGE_24GHZ_CHANNEL_14 2484
65 #define FREQ_RANGE_5GHZ_CHANNEL_32 5160
66 #define FREQ_RANGE_5GHZ_CHANNEL_165 5825
68 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
69 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
72 #define BSS_UNKNOWN_STRENGTH -90
74 static DBusConnection *connection;
76 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
77 static GSupplicantCallbacks *callbacks_pointer;
78 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
79 static const GSupplicantCallbacks *callbacks_pointer;
80 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
82 static dbus_bool_t system_available = FALSE;
83 static dbus_bool_t system_ready = FALSE;
85 static dbus_int32_t debug_level;
86 static dbus_bool_t debug_timestamp = FALSE;
87 static dbus_bool_t debug_showkeys = FALSE;
89 static const char *debug_strings[] = {
90 "msgdump", "debug", "info", "warning", "error", NULL
93 static unsigned int eap_methods;
100 static struct strvalmap eap_method_map[] = {
101 { "MD5", G_SUPPLICANT_EAP_METHOD_MD5 },
102 { "TLS", G_SUPPLICANT_EAP_METHOD_TLS },
103 { "MSCHAPV2", G_SUPPLICANT_EAP_METHOD_MSCHAPV2 },
104 { "PEAP", G_SUPPLICANT_EAP_METHOD_PEAP },
105 { "TTLS", G_SUPPLICANT_EAP_METHOD_TTLS },
106 { "GTC", G_SUPPLICANT_EAP_METHOD_GTC },
107 { "OTP", G_SUPPLICANT_EAP_METHOD_OTP },
108 { "LEAP", G_SUPPLICANT_EAP_METHOD_LEAP },
109 { "WSC", G_SUPPLICANT_EAP_METHOD_WSC },
113 static struct strvalmap keymgmt_map[] = {
114 { "none", G_SUPPLICANT_KEYMGMT_NONE },
115 { "ieee8021x", G_SUPPLICANT_KEYMGMT_IEEE8021X },
116 { "wpa-none", G_SUPPLICANT_KEYMGMT_WPA_NONE },
117 { "wpa-psk", G_SUPPLICANT_KEYMGMT_WPA_PSK },
118 { "wpa-psk-sha256", G_SUPPLICANT_KEYMGMT_WPA_PSK_256 },
119 { "wpa-ft-psk", G_SUPPLICANT_KEYMGMT_WPA_FT_PSK },
120 { "wpa-ft-eap", G_SUPPLICANT_KEYMGMT_WPA_FT_EAP },
121 { "wpa-eap", G_SUPPLICANT_KEYMGMT_WPA_EAP },
122 { "wpa-eap-sha256", G_SUPPLICANT_KEYMGMT_WPA_EAP_256 },
123 { "wps", G_SUPPLICANT_KEYMGMT_WPS },
124 #if defined TIZEN_EXT
125 { "sae", G_SUPPLICANT_KEYMGMT_SAE },
126 { "owe", G_SUPPLICANT_KEYMGMT_OWE },
127 { "dpp", G_SUPPLICANT_KEYMGMT_DPP },
132 static struct strvalmap authalg_capa_map[] = {
133 { "open", G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN },
134 { "shared", G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED },
135 { "leap", G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP },
139 static struct strvalmap proto_capa_map[] = {
140 { "wpa", G_SUPPLICANT_CAPABILITY_PROTO_WPA },
141 { "rsn", G_SUPPLICANT_CAPABILITY_PROTO_RSN },
145 static struct strvalmap group_map[] = {
146 { "wep40", G_SUPPLICANT_GROUP_WEP40 },
147 { "wep104", G_SUPPLICANT_GROUP_WEP104 },
148 { "tkip", G_SUPPLICANT_GROUP_TKIP },
149 { "ccmp", G_SUPPLICANT_GROUP_CCMP },
153 static struct strvalmap pairwise_map[] = {
154 { "none", G_SUPPLICANT_PAIRWISE_NONE },
155 { "tkip", G_SUPPLICANT_PAIRWISE_TKIP },
156 { "ccmp", G_SUPPLICANT_PAIRWISE_CCMP },
160 static struct strvalmap scan_capa_map[] = {
161 { "active", G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE },
162 { "passive", G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE },
163 { "ssid", G_SUPPLICANT_CAPABILITY_SCAN_SSID },
167 static struct strvalmap mode_capa_map[] = {
168 { "infrastructure", G_SUPPLICANT_CAPABILITY_MODE_INFRA },
169 { "ad-hoc", G_SUPPLICANT_CAPABILITY_MODE_IBSS },
170 { "ap", G_SUPPLICANT_CAPABILITY_MODE_AP },
171 { "p2p", G_SUPPLICANT_CAPABILITY_MODE_P2P },
172 #if defined TIZEN_EXT_WIFI_MESH
173 { "mesh", G_SUPPLICANT_CAPABILITY_MODE_MESH },
178 #if defined TIZEN_EXT
179 struct _GSupplicantINSSettings {
180 GSupplicantINSPreferredFreq preferred_freq_bssid;
181 unsigned int preferred_freq_bssid_score;
182 bool last_connected_bssid;
183 unsigned int last_connected_bssid_score;
185 unsigned int assoc_reject_score;
187 int signal_level3_5ghz;
188 int signal_level3_24ghz;
191 static struct _GSupplicantINSSettings ins_settings;
193 static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
198 static GHashTable *interface_table;
199 static GHashTable *bss_mapping;
200 static GHashTable *peer_mapping;
201 static GHashTable *group_mapping;
202 static GHashTable *pending_peer_connection;
203 static GHashTable *config_file_table;
205 struct _GSupplicantWpsCredentials {
206 unsigned char ssid[32];
207 unsigned int ssid_len;
211 struct added_network_information {
213 GSupplicantSecurity security;
215 char * private_passphrase;
216 #if defined TIZEN_EXT
219 char *net_access_key;
223 #if defined TIZEN_EXT_WIFI_MESH
224 struct _GSupplicantMeshGroupInfo {
225 unsigned char ssid[32];
226 unsigned int ssid_len;
227 int disconnect_reason;
231 struct _GSupplicantInterface {
234 unsigned int keymgmt_capa;
235 unsigned int authalg_capa;
236 unsigned int proto_capa;
237 unsigned int group_capa;
238 unsigned int pairwise_capa;
239 unsigned int scan_capa;
240 unsigned int mode_capa;
241 unsigned int max_scan_ssids;
244 bool ap_create_in_progress;
246 GSupplicantState state;
247 dbus_bool_t scanning;
248 GSupplicantInterfaceCallback scan_callback;
254 struct _GSupplicantWpsCredentials wps_cred;
255 GSupplicantWpsState wps_state;
256 GHashTable *network_table;
257 GHashTable *peer_table;
258 GHashTable *group_table;
259 GHashTable *bss_mapping;
261 const char *pending_peer_path;
262 GSupplicantNetwork *current_network;
263 struct added_network_information network_info;
264 #if defined TIZEN_EXT
265 dbus_bool_t is_5_0_Ghz_supported;
266 int disconnect_reason;
268 #if defined TIZEN_EXT
269 unsigned char add_network_bssid[WIFI_BSSID_LEN_MAX];
270 unsigned char connected_bssid[WIFI_BSSID_LEN_MAX];
272 #if defined TIZEN_EXT_WIFI_MESH
274 struct _GSupplicantMeshGroupInfo group_info;
278 struct g_supplicant_bss {
279 GSupplicantInterface *interface;
281 unsigned char bssid[6];
282 unsigned char ssid[32];
283 unsigned int ssid_len;
284 dbus_uint16_t frequency;
285 dbus_uint32_t maxrate;
287 GSupplicantMode mode;
288 GSupplicantSecurity security;
289 dbus_bool_t rsn_selected;
290 unsigned int wpa_keymgmt;
291 unsigned int wpa_pairwise;
292 unsigned int wpa_group;
293 unsigned int rsn_keymgmt;
294 unsigned int rsn_pairwise;
295 unsigned int rsn_group;
296 unsigned int keymgmt;
299 dbus_bool_t ieee8021x;
300 #if defined TIZEN_EXT
302 dbus_bool_t ft_ieee8021x;
305 unsigned char country_code[COUNTRY_CODE_LENGTH];
306 GSupplicantPhy_mode phy_mode;
308 dbus_uint32_t est_throughput;
310 unsigned int wps_capabilities;
311 #if defined TIZEN_EXT
315 dbus_bool_t owe_transition_mode;
316 unsigned int transition_mode_ssid_len;
317 unsigned char transition_mode_bssid[6];
318 unsigned char transition_mode_ssid[32];
322 struct _GSupplicantNetwork {
323 GSupplicantInterface *interface;
327 unsigned char ssid[32];
328 unsigned int ssid_len;
330 dbus_uint16_t frequency;
331 struct g_supplicant_bss *best_bss;
332 GSupplicantMode mode;
333 GSupplicantSecurity security;
335 unsigned int wps_capabilities;
336 GHashTable *bss_table;
337 GHashTable *config_table;
338 #if defined TIZEN_EXT
343 unsigned int keymgmt;
345 unsigned char country_code[COUNTRY_CODE_LENGTH];
346 GSupplicantPhy_mode phy_mode;
347 dbus_bool_t owe_transition_mode;
348 unsigned int transition_mode_ssid_len;
349 unsigned char transition_mode_bssid[6];
350 unsigned char transition_mode_ssid[32];
351 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
352 GHashTable *assoc_reject_table;
356 struct _GSupplicantPeer {
357 GSupplicantInterface *interface;
359 unsigned char device_address[ETH_ALEN];
360 unsigned char iface_address[ETH_ALEN];
362 unsigned char *widi_ies;
365 unsigned int wps_capabilities;
367 const GSupplicantInterface *current_group_iface;
368 bool connection_requested;
371 struct _GSupplicantGroup {
372 GSupplicantInterface *interface;
373 GSupplicantInterface *orig_interface;
379 struct interface_data {
380 GSupplicantInterface *interface;
381 char *path; /* Interface path cannot be taken from interface (above) as
382 * it might have been freed already.
384 GSupplicantInterfaceCallback callback;
386 bool network_remove_in_progress;
387 GSupplicantSSID *ssid;
390 #if defined TIZEN_EXT
391 struct interface_signalpoll_data {
392 GSupplicantInterface *interface;
394 GSupplicantMaxSpeedCallback callback;
399 struct interface_create_data {
403 #if defined TIZEN_EXT
404 unsigned int mac_addr;
405 unsigned int preassoc_mac_addr;
406 unsigned int random_mac_lifetime;
407 #endif /* TIZEN_EXT */
408 #if defined TIZEN_EXT_WIFI_MESH
410 bool is_mesh_interface;
412 GSupplicantInterface *interface;
413 GSupplicantInterfaceCallback callback;
417 struct interface_connect_data {
418 GSupplicantInterface *interface;
420 GSupplicantInterfaceCallback callback;
423 GSupplicantSSID *ssid;
424 GSupplicantPeerParams *peer;
428 struct interface_scan_data {
429 GSupplicantInterface *interface;
431 GSupplicantInterfaceCallback callback;
432 GSupplicantScanParams *scan_params;
436 #if defined TIZEN_EXT
437 struct g_connman_bssids {
438 unsigned char bssid[WIFI_BSSID_LEN_MAX];
441 uint16_t assoc_reject_cnt;
442 bool is_last_connected;
443 #if defined TIZEN_EXT_INS
444 int score_last_connected_bssid;
445 int score_assoc_reject;
449 int score_est_throughput;
454 struct update_bssid_data {
455 GSupplicantNetwork *network;
456 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
457 GHashTable *assoc_reject_table;
461 struct assoc_reject_data {
463 GSList *reject_time_list;
466 struct assoc_count_data {
471 static unsigned int last_connected_bss_timeout = 0;
472 static bool simplified_log = true;
475 static int network_remove(struct interface_data *data);
477 #if defined TIZEN_EXT_WIFI_MESH
478 struct _GSupplicantMeshPeer {
479 GSupplicantInterface *interface;
481 int disconnect_reason;
485 static inline void debug(const char *format, ...)
490 if (!callbacks_pointer || !callbacks_pointer->debug)
493 va_start(ap, format);
495 if (vsnprintf(str, sizeof(str), format, ap) > 0)
496 callbacks_pointer->debug(str);
501 #define SUPPLICANT_DBG(fmt, arg...) \
502 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
504 static GSupplicantMode string2mode(const char *mode)
507 return G_SUPPLICANT_MODE_UNKNOWN;
509 if (g_str_equal(mode, "infrastructure"))
510 return G_SUPPLICANT_MODE_INFRA;
511 else if (g_str_equal(mode, "ad-hoc"))
512 return G_SUPPLICANT_MODE_IBSS;
513 #if defined TIZEN_EXT_WIFI_MESH
514 else if (g_str_equal(mode, "mesh"))
515 return G_SUPPLICANT_MODE_MESH;
518 return G_SUPPLICANT_MODE_UNKNOWN;
521 static const char *mode2string(GSupplicantMode mode)
524 case G_SUPPLICANT_MODE_UNKNOWN:
526 case G_SUPPLICANT_MODE_INFRA:
528 case G_SUPPLICANT_MODE_IBSS:
530 case G_SUPPLICANT_MODE_MASTER:
532 #if defined TIZEN_EXT_WIFI_MESH
533 case G_SUPPLICANT_MODE_MESH:
541 static const char *security2string(GSupplicantSecurity security)
544 case G_SUPPLICANT_SECURITY_UNKNOWN:
546 case G_SUPPLICANT_SECURITY_NONE:
548 case G_SUPPLICANT_SECURITY_WEP:
550 case G_SUPPLICANT_SECURITY_PSK:
552 case G_SUPPLICANT_SECURITY_IEEE8021X:
554 #if defined TIZEN_EXT
555 case G_SUPPLICANT_SECURITY_FT_PSK:
557 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
558 return "ft_ieee8021x";
559 case G_SUPPLICANT_SECURITY_SAE:
561 case G_SUPPLICANT_SECURITY_OWE:
563 case G_SUPPLICANT_SECURITY_DPP:
571 static GSupplicantState string2state(const char *state)
574 return G_SUPPLICANT_STATE_UNKNOWN;
576 if (g_str_equal(state, "unknown"))
577 return G_SUPPLICANT_STATE_UNKNOWN;
578 else if (g_str_equal(state, "interface_disabled"))
579 return G_SUPPLICANT_STATE_DISABLED;
580 else if (g_str_equal(state, "disconnected"))
581 return G_SUPPLICANT_STATE_DISCONNECTED;
582 else if (g_str_equal(state, "inactive"))
583 return G_SUPPLICANT_STATE_INACTIVE;
584 else if (g_str_equal(state, "scanning"))
585 return G_SUPPLICANT_STATE_SCANNING;
586 else if (g_str_equal(state, "authenticating"))
587 return G_SUPPLICANT_STATE_AUTHENTICATING;
588 else if (g_str_equal(state, "associating"))
589 return G_SUPPLICANT_STATE_ASSOCIATING;
590 else if (g_str_equal(state, "associated"))
591 return G_SUPPLICANT_STATE_ASSOCIATED;
592 else if (g_str_equal(state, "group_handshake"))
593 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
594 else if (g_str_equal(state, "4way_handshake"))
595 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
596 else if (g_str_equal(state, "completed"))
597 return G_SUPPLICANT_STATE_COMPLETED;
599 return G_SUPPLICANT_STATE_UNKNOWN;
602 static bool compare_network_parameters(GSupplicantInterface *interface,
603 GSupplicantSSID *ssid)
605 #if defined TIZEN_EXT
606 if (!interface->network_info.ssid)
610 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
613 if (interface->network_info.security != ssid->security)
616 if (interface->network_info.passphrase &&
617 g_strcmp0(interface->network_info.passphrase,
618 ssid->passphrase) != 0) {
622 if (interface->network_info.private_passphrase &&
623 g_strcmp0(interface->network_info.private_passphrase,
624 ssid->private_key_passphrase) != 0) {
628 #if defined TIZEN_EXT
629 if (interface->network_info.connector &&
630 g_strcmp0(interface->network_info.connector,
631 ssid->connector) != 0) {
634 if (interface->network_info.c_sign_key &&
635 g_strcmp0(interface->network_info.c_sign_key,
636 ssid->c_sign_key) != 0) {
639 if (interface->network_info.net_access_key &&
640 g_strcmp0(interface->network_info.net_access_key,
641 ssid->net_access_key) != 0) {
648 static void remove_network_information(GSupplicantInterface * interface)
650 g_free(interface->network_info.ssid);
651 g_free(interface->network_info.passphrase);
652 g_free(interface->network_info.private_passphrase);
653 #if defined TIZEN_EXT
654 g_free(interface->network_info.connector);
655 g_free(interface->network_info.c_sign_key);
656 g_free(interface->network_info.net_access_key);
658 interface->network_info.ssid = NULL;
659 interface->network_info.passphrase = NULL;
660 interface->network_info.private_passphrase = NULL;
661 #if defined TIZEN_EXT
662 interface->network_info.connector = NULL;
663 interface->network_info.c_sign_key = NULL;
664 interface->network_info.net_access_key = NULL;
668 static int store_network_information(GSupplicantInterface * interface,
669 GSupplicantSSID *ssid)
671 interface->network_info.ssid = g_malloc(ssid->ssid_len + 1);
672 if (interface->network_info.ssid != NULL) {
673 memcpy(interface->network_info.ssid, ssid->ssid,
675 interface->network_info.ssid[ssid->ssid_len] = '\0';
680 interface->network_info.security = ssid->security;
682 if ((ssid->security == G_SUPPLICANT_SECURITY_WEP ||
683 ssid->security == G_SUPPLICANT_SECURITY_PSK ||
684 ssid->security == G_SUPPLICANT_SECURITY_NONE) &&
686 interface->network_info.passphrase = g_strdup(ssid->passphrase);
689 if (ssid->security == G_SUPPLICANT_SECURITY_IEEE8021X &&
690 ssid->private_key_passphrase) {
691 interface->network_info.private_passphrase =
692 g_strdup(ssid->private_key_passphrase);
698 static void callback_system_ready(void)
705 if (!callbacks_pointer)
708 if (!callbacks_pointer->system_ready)
711 callbacks_pointer->system_ready();
714 static void callback_system_killed(void)
716 system_ready = FALSE;
718 if (!callbacks_pointer)
721 if (!callbacks_pointer->system_killed)
724 callbacks_pointer->system_killed();
727 static void callback_interface_added(GSupplicantInterface *interface)
731 if (!callbacks_pointer)
734 if (!callbacks_pointer->interface_added)
737 callbacks_pointer->interface_added(interface);
740 static void callback_interface_state(GSupplicantInterface *interface)
742 if (!callbacks_pointer)
745 if (!callbacks_pointer->interface_state)
748 callbacks_pointer->interface_state(interface);
751 static void callback_interface_removed(GSupplicantInterface *interface)
753 if (!callbacks_pointer)
756 if (!callbacks_pointer->interface_removed)
759 callbacks_pointer->interface_removed(interface);
762 #if !defined TIZEN_EXT
763 static void callback_p2p_support(GSupplicantInterface *interface)
767 if (!interface->p2p_support)
770 if (callbacks_pointer && callbacks_pointer->p2p_support)
771 callbacks_pointer->p2p_support(interface);
775 #if defined TIZEN_EXT_WIFI_MESH
776 static void callback_mesh_support(GSupplicantInterface *interface)
780 if (!interface->mesh_support)
783 if (callbacks_pointer && callbacks_pointer->mesh_support)
784 callbacks_pointer->mesh_support(interface);
787 bool g_supplicant_interface_has_mesh(GSupplicantInterface *interface)
792 return interface->mesh_support;
796 static void callback_scan_started(GSupplicantInterface *interface)
798 if (!callbacks_pointer)
801 if (!callbacks_pointer->scan_started)
804 callbacks_pointer->scan_started(interface);
807 static void callback_ap_create_fail(GSupplicantInterface *interface)
809 if (!callbacks_pointer)
812 if (!callbacks_pointer->ap_create_fail)
815 callbacks_pointer->ap_create_fail(interface);
818 static void callback_scan_finished(GSupplicantInterface *interface)
820 if (!callbacks_pointer)
823 if (!callbacks_pointer->scan_finished)
826 callbacks_pointer->scan_finished(interface);
829 static void callback_network_added(GSupplicantNetwork *network)
831 if (!callbacks_pointer)
834 if (!callbacks_pointer->network_added)
837 callbacks_pointer->network_added(network);
840 static void callback_network_removed(GSupplicantNetwork *network)
842 if (!callbacks_pointer)
845 if (!callbacks_pointer->network_removed)
848 callbacks_pointer->network_removed(network);
851 #if defined TIZEN_EXT
852 static void callback_network_merged(GSupplicantNetwork *network)
854 if (!callbacks_pointer)
857 if (!callbacks_pointer->network_merged)
860 callbacks_pointer->network_merged(network);
863 static void callback_assoc_failed(void *user_data)
865 if (!callbacks_pointer)
868 if (!callbacks_pointer->assoc_failed)
871 callbacks_pointer->assoc_failed(user_data);
874 static void callback_scan_done(GSupplicantInterface *interface)
876 if (!callbacks_pointer)
879 if (!callbacks_pointer->scan_done)
882 callbacks_pointer->scan_done(interface);
886 static void callback_network_changed(GSupplicantNetwork *network,
887 const char *property)
889 if (!callbacks_pointer)
892 if (!callbacks_pointer->network_changed)
895 callbacks_pointer->network_changed(network, property);
898 static void callback_network_associated(GSupplicantNetwork *network)
900 if (!callbacks_pointer)
903 if (!callbacks_pointer->network_associated)
906 callbacks_pointer->network_associated(network);
909 static void callback_sta_authorized(GSupplicantInterface *interface,
912 if (!callbacks_pointer)
915 if (!callbacks_pointer->sta_authorized)
918 callbacks_pointer->sta_authorized(interface, addr);
921 static void callback_sta_deauthorized(GSupplicantInterface *interface,
924 if (!callbacks_pointer)
927 if (!callbacks_pointer->sta_deauthorized)
930 callbacks_pointer->sta_deauthorized(interface, addr);
933 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
934 static void callback_eap(GSupplicantInterface *interface, bool status)
936 if (!callbacks_pointer)
939 if (!callbacks_pointer->eap)
942 callbacks_pointer->eap(interface, status);
944 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
946 static void callback_peer_found(GSupplicantPeer *peer)
948 if (!callbacks_pointer)
951 if (!callbacks_pointer->peer_found)
954 callbacks_pointer->peer_found(peer);
957 static void callback_peer_lost(GSupplicantPeer *peer)
959 if (!callbacks_pointer)
962 if (!callbacks_pointer->peer_lost)
965 callbacks_pointer->peer_lost(peer);
968 static void callback_peer_changed(GSupplicantPeer *peer,
969 GSupplicantPeerState state)
971 if (!callbacks_pointer)
974 if (!callbacks_pointer->peer_changed)
977 callbacks_pointer->peer_changed(peer, state);
980 static void callback_peer_request(GSupplicantPeer *peer)
982 if (!callbacks_pointer)
985 if (!callbacks_pointer->peer_request)
988 peer->connection_requested = true;
990 callbacks_pointer->peer_request(peer);
993 static void callback_disconnect_reason_code(GSupplicantInterface *interface,
996 if (!callbacks_pointer)
999 if (!callbacks_pointer->disconnect_reasoncode)
1002 if (reason_code != 0)
1003 callbacks_pointer->disconnect_reasoncode(interface,
1007 static void callback_assoc_status_code(GSupplicantInterface *interface,
1010 if (!callbacks_pointer)
1013 if (!callbacks_pointer->assoc_status_code)
1016 callbacks_pointer->assoc_status_code(interface, status_code);
1020 static void remove_group(gpointer data)
1022 GSupplicantGroup *group = data;
1025 g_slist_free_full(group->members, g_free);
1027 g_free(group->path);
1031 static void remove_interface(gpointer data)
1033 GSupplicantInterface *interface = data;
1035 g_hash_table_destroy(interface->bss_mapping);
1036 g_hash_table_destroy(interface->network_table);
1037 g_hash_table_destroy(interface->peer_table);
1038 g_hash_table_destroy(interface->group_table);
1040 if (interface->scan_callback) {
1041 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
1042 interface, interface->scan_callback,
1043 interface->scanning);
1045 interface->scan_callback(-EIO, interface, interface->scan_data);
1046 interface->scan_callback = NULL;
1047 interface->scan_data = NULL;
1049 if (interface->scanning) {
1050 interface->scanning = FALSE;
1051 callback_scan_finished(interface);
1055 callback_interface_removed(interface);
1057 g_free(interface->wps_cred.key);
1058 g_free(interface->path);
1059 g_free(interface->network_path);
1060 #if defined TIZEN_EXT
1061 interface->network_path = NULL;
1063 g_free(interface->ifname);
1064 g_free(interface->driver);
1065 g_free(interface->bridge);
1066 remove_network_information(interface);
1070 static void remove_network(gpointer data)
1072 GSupplicantNetwork *network = data;
1074 g_hash_table_destroy(network->bss_table);
1076 callback_network_removed(network);
1078 g_hash_table_destroy(network->config_table);
1079 #if defined TIZEN_EXT
1080 g_hash_table_destroy(network->assoc_reject_table);
1083 g_free(network->path);
1084 g_free(network->group);
1085 g_free(network->name);
1086 #if defined TIZEN_EXT
1087 g_free(network->eap);
1088 g_free(network->identity);
1089 g_free(network->phase2);
1091 #if defined TIZEN_EXT
1092 g_slist_free_full(network->vsie_list, g_free);
1098 static void remove_bss(gpointer data)
1100 struct g_supplicant_bss *bss = data;
1102 supplicant_dbus_property_call_cancel_all(bss);
1105 #if defined TIZEN_EXT
1106 g_slist_free_full(bss->vsie_list, g_free);
1111 static void remove_peer(gpointer data)
1113 GSupplicantPeer *peer = data;
1115 callback_peer_lost(peer);
1118 g_slist_free_full(peer->groups, g_free);
1121 g_hash_table_remove(peer_mapping, peer->path);
1123 if (pending_peer_connection)
1124 g_hash_table_remove(pending_peer_connection, peer->path);
1128 g_free(peer->identifier);
1129 g_free(peer->widi_ies);
1134 #if defined TIZEN_EXT
1135 static void remove_assoc_data(gpointer data)
1137 struct assoc_reject_data *assoc_data = data;
1139 g_free(assoc_data->bssid);
1140 g_slist_free(assoc_data->reject_time_list);
1146 static void debug_strvalmap(const char *label, struct strvalmap *map,
1150 #if defined TIZEN_EXT
1151 if (!simplified_log)
1153 for (i = 0; map[i].str; i++) {
1154 if (val & map[i].val)
1155 SUPPLICANT_DBG("%s: %s", label, map[i].str);
1159 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
1161 GSupplicantInterface *interface = user_data;
1162 const char *str = NULL;
1165 dbus_message_iter_get_basic(iter, &str);
1169 for (i = 0; keymgmt_map[i].str; i++)
1170 if (strcmp(str, keymgmt_map[i].str) == 0) {
1171 interface->keymgmt_capa |= keymgmt_map[i].val;
1176 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
1178 GSupplicantInterface *interface = user_data;
1179 const char *str = NULL;
1182 dbus_message_iter_get_basic(iter, &str);
1186 for (i = 0; authalg_capa_map[i].str; i++)
1187 if (strcmp(str, authalg_capa_map[i].str) == 0) {
1188 interface->authalg_capa |= authalg_capa_map[i].val;
1193 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
1195 GSupplicantInterface *interface = user_data;
1196 const char *str = NULL;
1199 dbus_message_iter_get_basic(iter, &str);
1203 for (i = 0; proto_capa_map[i].str; i++)
1204 if (strcmp(str, proto_capa_map[i].str) == 0) {
1205 interface->proto_capa |= proto_capa_map[i].val;
1210 static void interface_capability_pairwise(DBusMessageIter *iter,
1213 GSupplicantInterface *interface = user_data;
1214 const char *str = NULL;
1217 dbus_message_iter_get_basic(iter, &str);
1221 for (i = 0; pairwise_map[i].str; i++)
1222 if (strcmp(str, pairwise_map[i].str) == 0) {
1223 interface->pairwise_capa |= pairwise_map[i].val;
1228 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
1230 GSupplicantInterface *interface = user_data;
1231 const char *str = NULL;
1234 dbus_message_iter_get_basic(iter, &str);
1238 for (i = 0; group_map[i].str; i++)
1239 if (strcmp(str, group_map[i].str) == 0) {
1240 interface->group_capa |= group_map[i].val;
1245 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
1247 GSupplicantInterface *interface = user_data;
1248 const char *str = NULL;
1251 dbus_message_iter_get_basic(iter, &str);
1255 for (i = 0; scan_capa_map[i].str; i++)
1256 if (strcmp(str, scan_capa_map[i].str) == 0) {
1257 interface->scan_capa |= scan_capa_map[i].val;
1262 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
1264 GSupplicantInterface *interface = user_data;
1265 const char *str = NULL;
1268 dbus_message_iter_get_basic(iter, &str);
1272 for (i = 0; mode_capa_map[i].str; i++)
1273 if (strcmp(str, mode_capa_map[i].str) == 0) {
1274 interface->mode_capa |= mode_capa_map[i].val;
1279 static void interface_capability(const char *key, DBusMessageIter *iter,
1282 GSupplicantInterface *interface = user_data;
1287 if (g_strcmp0(key, "KeyMgmt") == 0)
1288 supplicant_dbus_array_foreach(iter,
1289 interface_capability_keymgmt, interface);
1290 else if (g_strcmp0(key, "AuthAlg") == 0)
1291 supplicant_dbus_array_foreach(iter,
1292 interface_capability_authalg, interface);
1293 else if (g_strcmp0(key, "Protocol") == 0)
1294 supplicant_dbus_array_foreach(iter,
1295 interface_capability_proto, interface);
1296 else if (g_strcmp0(key, "Pairwise") == 0)
1297 supplicant_dbus_array_foreach(iter,
1298 interface_capability_pairwise, interface);
1299 else if (g_strcmp0(key, "Group") == 0)
1300 supplicant_dbus_array_foreach(iter,
1301 interface_capability_group, interface);
1302 else if (g_strcmp0(key, "Scan") == 0)
1303 supplicant_dbus_array_foreach(iter,
1304 interface_capability_scan, interface);
1305 else if (g_strcmp0(key, "Modes") == 0)
1306 supplicant_dbus_array_foreach(iter,
1307 interface_capability_mode, interface);
1308 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
1309 dbus_int32_t max_scan_ssid;
1311 dbus_message_iter_get_basic(iter, &max_scan_ssid);
1312 if (max_scan_ssid < 2)
1314 interface->max_scan_ssids = max_scan_ssid;
1315 #if defined TIZEN_EXT
1316 } else if (g_strcmp0(key, "Is5GhzSupported") == 0) {
1317 dbus_bool_t is_5_0_Ghz_supported;
1319 dbus_message_iter_get_basic(iter, &is_5_0_Ghz_supported);
1320 interface->is_5_0_Ghz_supported = is_5_0_Ghz_supported;
1323 SUPPLICANT_DBG("key %s type %c",
1324 key, dbus_message_iter_get_arg_type(iter));
1327 static void set_bss_expiration_age(DBusMessageIter *iter, void *user_data)
1329 unsigned int bss_expiration_age = GPOINTER_TO_UINT(user_data);
1331 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32,
1332 &bss_expiration_age);
1335 int g_supplicant_interface_set_bss_expiration_age(GSupplicantInterface *interface,
1336 unsigned int bss_expiration_age)
1338 return supplicant_dbus_property_set(interface->path,
1339 SUPPLICANT_INTERFACE ".Interface",
1340 "BSSExpireAge", DBUS_TYPE_UINT32_AS_STRING,
1341 set_bss_expiration_age, NULL,
1342 GUINT_TO_POINTER(bss_expiration_age), NULL);
1345 struct set_apscan_data
1347 unsigned int ap_scan;
1348 GSupplicantInterface *interface;
1351 static void set_apscan(DBusMessageIter *iter, void *user_data)
1353 struct set_apscan_data *data = user_data;
1354 unsigned int ap_scan = data->ap_scan;
1356 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
1359 static void set_apscan_complete(const char *error,
1360 DBusMessageIter *iter, void *user_data)
1362 struct set_apscan_data *data = user_data;
1363 GSupplicantInterface *interface = data->interface;
1366 interface->ap_create_in_progress = false;
1367 SUPPLICANT_DBG("Set AP scan error %s", error);
1371 interface->ap_create_in_progress = true;
1376 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
1377 unsigned int ap_scan)
1379 struct set_apscan_data *data;
1382 data = dbus_malloc0(sizeof(*data));
1387 data->ap_scan = ap_scan;
1388 data->interface = interface;
1390 ret = supplicant_dbus_property_set(interface->path,
1391 SUPPLICANT_INTERFACE ".Interface",
1392 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
1393 set_apscan, set_apscan_complete, data, NULL);
1400 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
1406 interface->data = data;
1409 interface->scan_callback = NULL;
1412 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
1417 return interface->data;
1420 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
1425 return interface->ifname;
1428 #if defined TIZEN_EXT
1429 bool g_supplicant_interface_get_is_5_0_ghz_supported(GSupplicantInterface *interface)
1434 return interface->is_5_0_Ghz_supported;
1438 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
1443 return interface->driver;
1446 GSupplicantState g_supplicant_interface_get_state(
1447 GSupplicantInterface *interface)
1450 return G_SUPPLICANT_STATE_UNKNOWN;
1452 return interface->state;
1455 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
1460 return (const char *)interface->wps_cred.key;
1463 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
1464 unsigned int *ssid_len)
1469 if (!interface || interface->wps_cred.ssid_len == 0) {
1474 *ssid_len = interface->wps_cred.ssid_len;
1475 return interface->wps_cred.ssid;
1478 GSupplicantWpsState g_supplicant_interface_get_wps_state(
1479 GSupplicantInterface *interface)
1482 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
1484 return interface->wps_state;
1487 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
1492 return interface->mode_capa;
1495 unsigned int g_supplicant_interface_get_max_scan_ssids(
1496 GSupplicantInterface *interface)
1501 if (interface->max_scan_ssids == 0)
1502 return WPAS_MAX_SCAN_SSIDS;
1504 return interface->max_scan_ssids;
1507 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
1509 dbus_bool_t enable = *(dbus_bool_t *)user_data;
1511 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
1514 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
1520 if (!interface->network_path)
1523 SUPPLICANT_DBG(" ");
1524 return supplicant_dbus_property_set(interface->network_path,
1525 SUPPLICANT_INTERFACE ".Network",
1526 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
1527 set_network_enabled, NULL, &enable, NULL);
1530 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
1535 return interface->ready;
1538 GSupplicantInterface *g_supplicant_network_get_interface(
1539 GSupplicantNetwork *network)
1544 return network->interface;
1547 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
1549 if (!network || !network->name)
1552 return network->name;
1555 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
1557 if (!network || !network->group)
1560 return network->group;
1563 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1565 if (!network || !network->path)
1568 return network->path;
1571 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1574 return G_SUPPLICANT_MODE_UNKNOWN;
1576 return mode2string(network->mode);
1579 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1582 return G_SUPPLICANT_SECURITY_UNKNOWN;
1584 return security2string(network->security);
1587 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1588 unsigned int *ssid_len)
1595 *ssid_len = network->ssid_len;
1596 return network->ssid;
1599 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1604 return network->signal;
1607 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1612 return network->frequency;
1615 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1620 return network->wps;
1623 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1628 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1634 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1639 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1645 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1650 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1657 GSupplicantPhy_mode g_supplicant_network_get_phy_mode(GSupplicantNetwork *network)
1660 return G_SUPPLICANT_MODE_IEEE80211_UNKNOWN;
1662 return network->phy_mode;
1666 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1671 return peer->interface;
1674 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1682 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1687 return peer->identifier;
1690 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1695 return peer->device_address;
1698 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1703 return peer->iface_address;
1706 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1714 #if defined TIZEN_EXT
1715 bool g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1720 return network->isHS20AP;
1723 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1725 if (!network || !network->eap)
1728 return network->eap;
1731 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1733 if (!network || !network->identity)
1736 return network->identity;
1739 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1741 if (!network || !network->phase2)
1744 return network->phase2;
1747 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
1749 if (network == NULL)
1752 return network->keymgmt;
1755 const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
1761 return network->country_code;
1765 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1768 if (!peer || !length)
1771 *length = peer->widi_ies_length;
1772 return peer->widi_ies;
1775 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1780 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1786 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1791 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1797 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1799 if (!peer || !peer->groups)
1805 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1810 return (GSupplicantInterface *) peer->current_group_iface;
1813 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1815 GSupplicantGroup *group;
1821 for (list = peer->groups; list; list = list->next) {
1822 const char *path = list->data;
1824 group = g_hash_table_lookup(group_mapping, path);
1828 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1829 group->orig_interface != peer->interface)
1832 if (group->interface == peer->current_group_iface)
1839 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1844 return peer->connection_requested;
1847 #if defined TIZEN_EXT
1849 * Description: Network client requires additional wifi specific info
1851 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1853 if (network == NULL || network->best_bss == NULL)
1856 return (const unsigned char *)network->best_bss->bssid;
1858 dbus_bool_t g_supplicant_network_get_transition_mode(GSupplicantNetwork *network)
1860 if (network == NULL)
1863 return network->owe_transition_mode;
1867 const unsigned char *g_supplicant_network_get_transition_mode_bssid(GSupplicantNetwork *network)
1869 if (network == NULL)
1872 return (const unsigned char *)network->transition_mode_bssid;
1875 const void *g_supplicant_network_get_transition_mode_ssid(GSupplicantNetwork *network,
1876 unsigned int *transition_mode_ssid_len)
1879 *transition_mode_ssid_len = 0;
1883 *transition_mode_ssid_len = network->transition_mode_ssid_len;
1884 return network->transition_mode_ssid;
1887 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1889 if (network == NULL || network->best_bss == NULL)
1892 return network->best_bss->maxrate;
1895 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1897 if (network == NULL || network->best_bss == NULL)
1900 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1901 #if defined TIZEN_EXT
1902 network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1903 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1904 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP ||
1905 #endif /* TIZEN_EXT */
1906 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1907 unsigned int pairwise;
1909 pairwise = network->best_bss->rsn_pairwise |
1910 network->best_bss->wpa_pairwise;
1912 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1913 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1915 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1917 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1920 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1922 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1928 bool g_supplicant_network_get_rsn_mode(GSupplicantNetwork *network)
1930 if (network == NULL || network->best_bss == NULL)
1933 #if defined TIZEN_EXT
1934 if (network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1935 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1936 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP)
1938 #endif /* TIZEN_EXT */
1940 if (network->best_bss->rsn_selected) {
1941 const char *mode = g_supplicant_network_get_enc_mode(network);
1942 if (g_strcmp0(mode, "aes") == 0 ||
1943 g_strcmp0(mode, "mixed") == 0)
1951 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
1953 GSList *vsie_list = NULL;
1958 if (g_slist_length(network->vsie_list) > 0) {
1959 GSList *list = NULL;
1960 unsigned char *vsie = NULL;
1961 for (list = network->vsie_list; list; list = list->next) {
1962 unsigned char *ie = (unsigned char *)list->data;
1965 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
1968 memcpy(vsie, ie, ie[1]+2);
1969 vsie_list = g_slist_append(vsie_list, vsie);
1971 SUPPLICANT_DBG("Failed to allocate memory");
1978 static bool compare_bssid(unsigned char *bssid_a, unsigned char *bssid_b)
1980 if (!memcmp(bssid_a, bssid_b, WIFI_BSSID_LEN_MAX))
1986 static gchar *convert_bssid_to_str(unsigned char *bssid)
1991 bssid_str = g_string_sized_new(18);
1995 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
1996 g_string_append_printf(bssid_str, "%02x", bssid[i]);
1997 if (i < WIFI_BSSID_LEN_MAX - 1)
1998 g_string_append(bssid_str, ":");
2001 return g_string_free(bssid_str, FALSE);
2004 static void count_assoc_reject(gpointer data, gpointer user_data)
2006 time_t assoc_reject_time = GPOINTER_TO_INT(data);
2007 struct assoc_count_data *assoc_count = user_data;
2009 if (assoc_reject_time > assoc_count->ref_time)
2010 assoc_count->assoc_count++;
2013 static uint16_t get_assoc_reject_cnt(GHashTable *assoc_reject_table, unsigned char *bssid)
2016 struct assoc_reject_data *assoc_data;
2017 struct assoc_count_data assoc_count;
2019 struct tm* timeinfo;
2021 if (g_hash_table_size(assoc_reject_table) < 1)
2027 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2030 bssid_str = convert_bssid_to_str(bssid);
2034 assoc_data = g_hash_table_lookup(assoc_reject_table, bssid_str);
2040 if (g_slist_length(assoc_data->reject_time_list) < 1) {
2045 /* Only events that occur within one hour are appened. */
2046 curr_time = time(NULL);
2047 timeinfo = localtime(&curr_time);
2048 timeinfo->tm_hour -= 1;
2050 assoc_count.ref_time = mktime(timeinfo);
2051 assoc_count.assoc_count = 0;
2053 g_slist_foreach(assoc_data->reject_time_list, count_assoc_reject, &assoc_count);
2056 return assoc_count.assoc_count;
2059 static int calculate_score_last_connected_bssid(bool is_last_connected)
2063 if (ins_settings.last_connected_bssid) {
2064 if (is_last_connected)
2065 score += ins_settings.last_connected_bssid_score;
2071 static int calculate_score_assoc_reject(uint16_t assoc_reject_cnt)
2075 if (ins_settings.assoc_reject)
2076 score -= (assoc_reject_cnt * ins_settings.assoc_reject_score);
2081 static int calculate_score_frequency(dbus_int16_t strength, dbus_uint16_t frequency)
2085 switch (ins_settings.preferred_freq_bssid) {
2086 case G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ:
2087 if ((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
2088 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
2089 (strength > ins_settings.signal_level3_24ghz))
2090 score += ins_settings.preferred_freq_bssid_score;
2093 case G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ:
2094 if ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
2095 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
2096 (strength > ins_settings.signal_level3_5ghz))
2097 score += ins_settings.preferred_freq_bssid_score;
2107 static int calculate_score_strength(dbus_int16_t strength)
2111 if (ins_settings.signal_bssid)
2112 score += (((strength > -60) ? -60 : strength) + 85);
2117 static int calculate_score_est_throughput(dbus_uint32_t est_throughput)
2121 if (est_throughput >= 10000)
2122 score = est_throughput / 10000;
2130 static int calculate_score(bool is_last_connected, uint16_t assoc_reject_cnt,
2131 dbus_uint16_t frequency, dbus_int16_t strength,
2132 dbus_int16_t snr, dbus_uint32_t est_throughput)
2136 score += calculate_score_last_connected_bssid(is_last_connected);
2137 score += calculate_score_assoc_reject(assoc_reject_cnt);
2138 score += calculate_score_frequency(strength, frequency);
2139 score += calculate_score_strength(strength);
2141 score += calculate_score_est_throughput(est_throughput);
2146 static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
2148 struct g_supplicant_bss *bss = value;
2149 struct g_connman_bssids *bssids = NULL;
2150 struct update_bssid_data *bssid_data = (struct update_bssid_data *)user_data;
2152 bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
2155 memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
2157 bssids->strength = bss->signal;
2158 bssids->strength += 120;
2160 if (bssids->strength > 100)
2161 bssids->strength = 100;
2163 bssids->frequency = bss->frequency;
2165 bssids->assoc_reject_cnt = get_assoc_reject_cnt(bssid_data->assoc_reject_table, bssids->bssid);
2167 bssids->is_last_connected = compare_bssid(bssids->bssid, bssid_data->last_connected_bssid);
2169 #if defined TIZEN_EXT_INS
2170 bssids->score_last_connected_bssid = calculate_score_last_connected_bssid(bssids->is_last_connected);
2171 bssids->score_assoc_reject = calculate_score_assoc_reject(bssids->assoc_reject_cnt);
2172 bssids->score_frequency = calculate_score_frequency(bss->signal, bssids->frequency);
2173 bssids->score_strength = calculate_score_strength(bssids->strength);
2174 bssids->score_snr = (int)bss->snr;
2175 bssids->score_est_throughput = calculate_score_est_throughput(bss->est_throughput);
2178 bssids->ins_score = calculate_score(bssids->is_last_connected,
2179 bssids->assoc_reject_cnt, bssids->frequency, bss->signal,
2180 bss->snr, bss->est_throughput);
2182 bssid_data->bssid_list = g_slist_append(bssid_data->bssid_list, bssids);
2184 SUPPLICANT_DBG("Failed to allocate memory");
2187 static gint cmp_bss(gconstpointer a, gconstpointer b)
2189 struct g_connman_bssids *entry_a = (struct g_connman_bssids *)a;
2190 struct g_connman_bssids *entry_b = (struct g_connman_bssids *)b;
2192 if (entry_a->ins_score > entry_b->ins_score)
2195 if (entry_a->ins_score < entry_b->ins_score)
2201 #if defined TIZEN_EXT_INS
2202 static void print_bssid_sort(gpointer data, gpointer user_data)
2204 struct g_connman_bssids *bssids = data;
2206 SUPPLICANT_DBG("bssid[" MACSTR "] total[%2d] freq[%2d] "
2207 "last_conn[%2d] assoc_reject[%2d] strength[%2d]",
2208 MAC2STR(bssids->bssid), bssids->ins_score,
2209 bssids->score_frequency, bssids->score_last_connected_bssid,
2210 bssids->score_assoc_reject, bssids->score_strength);
2214 void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network)
2216 struct update_bssid_data bssid_data;
2218 if (g_hash_table_size(network->bss_table) < 1)
2221 bssid_data.network = network;
2222 memset(&bssid_data, 0, sizeof(bssid_data));
2223 memcpy(bssid_data.last_connected_bssid, network->last_connected_bssid, WIFI_BSSID_LEN_MAX);
2224 bssid_data.assoc_reject_table = network->assoc_reject_table;
2226 g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_data);
2227 bssid_data.bssid_list = g_slist_sort(bssid_data.bssid_list, cmp_bss);
2228 #if defined TIZEN_EXT_INS
2229 g_slist_foreach(bssid_data.bssid_list, print_bssid_sort, NULL);
2232 return bssid_data.bssid_list;
2235 void g_supplicant_network_set_last_connected_bssid(GSupplicantNetwork *network, const unsigned char *bssid)
2240 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2243 memcpy(network->last_connected_bssid, bssid, WIFI_BSSID_LEN_MAX);
2245 SUPPLICANT_DBG("last connected bssid [" MACSTR "]", MAC2STR(bssid));
2248 const unsigned char *g_supplicant_network_get_last_connected_bssid(GSupplicantNetwork *network)
2250 if (network == NULL)
2253 return (const unsigned char *)network->last_connected_bssid;
2256 void g_supplicant_network_update_assoc_reject(GSupplicantInterface *interface,
2257 GSupplicantNetwork *network)
2259 struct assoc_reject_data *assoc_data;
2266 bssid_str = convert_bssid_to_str(interface->add_network_bssid);
2270 assoc_data = g_hash_table_lookup(network->assoc_reject_table, bssid_str);
2272 assoc_data = g_try_new0(struct assoc_reject_data, 1);
2278 assoc_data->bssid = g_strdup(bssid_str);
2279 g_hash_table_insert(network->assoc_reject_table, assoc_data->bssid, assoc_data);
2282 curr_time = time(NULL);
2283 assoc_data->reject_time_list = g_slist_append(assoc_data->reject_time_list, GINT_TO_POINTER(curr_time));
2285 SUPPLICANT_DBG("bssid [%s] time [%u]", bssid_str, curr_time);
2289 callback_network_changed(network, "UpdateAssocReject");
2292 GHashTable *g_supplicant_network_get_assoc_reject_table(GSupplicantNetwork *network)
2297 return network->assoc_reject_table;
2300 GSupplicantNetwork *g_supplicant_interface_get_network(GSupplicantInterface *interface,
2306 return g_hash_table_lookup(interface->network_table, group);
2310 static void merge_network(GSupplicantNetwork *network)
2313 const char *ssid, *mode, *key_mgmt;
2314 #if defined TIZEN_EXT
2315 const char *isHS20AP;
2316 const char *eap, *identity, *phase2;
2318 unsigned int i, ssid_len;
2321 ssid = g_hash_table_lookup(network->config_table, "ssid");
2322 mode = g_hash_table_lookup(network->config_table, "mode");
2323 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
2324 #if defined TIZEN_EXT
2325 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
2326 eap = g_hash_table_lookup(network->config_table, "eap");
2327 identity = g_hash_table_lookup(network->config_table, "identity");
2328 phase2 = g_hash_table_lookup(network->config_table, "phase2");
2331 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
2334 ssid_len = strlen(ssid);
2338 str = g_string_sized_new((ssid_len * 2) + 24);
2342 for (i = 0; i < ssid_len; i++)
2343 #if defined TIZEN_EXT
2347 g_string_append_printf(str, "%02x", ssid[i]);
2348 #if defined TIZEN_EXT
2352 if (g_strcmp0(mode, "0") == 0)
2353 g_string_append_printf(str, "_managed");
2354 else if (g_strcmp0(mode, "1") == 0)
2355 g_string_append_printf(str, "_adhoc");
2356 #if defined TIZEN_EXT_WIFI_MESH
2357 else if (g_strcmp0(mode, "5") == 0)
2358 g_string_append_printf(str, "_mesh");
2361 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
2362 g_string_append_printf(str, "_psk");
2363 #if defined TIZEN_EXT
2364 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
2365 g_string_append_printf(str, "_ieee8021x");
2367 g_string_append_printf(str, "_none");
2370 group = g_string_free(str, FALSE);
2372 SUPPLICANT_DBG("%s", group);
2374 #if defined TIZEN_EXT
2375 if (g_strcmp0(isHS20AP, "1") == 0) {
2376 network->isHS20AP = 1;
2378 g_free(network->eap);
2379 network->eap = g_strdup(eap);
2381 if (network->identity)
2382 g_free(network->identity);
2383 network->identity = g_strdup(identity);
2385 if (network->phase2)
2386 g_free(network->phase2);
2387 network->phase2 = g_strdup(phase2);
2389 network->isHS20AP = 0;
2391 network->group = g_strdup(group);
2392 callback_network_merged(network);
2393 g_free(network->group);
2398 g_hash_table_destroy(network->config_table);
2400 g_free(network->path);
2404 static void network_property(const char *key, DBusMessageIter *iter,
2407 GSupplicantNetwork *network = user_data;
2409 if (!network->interface)
2413 merge_network(network);
2417 if (g_strcmp0(key, "Enabled") == 0) {
2418 dbus_bool_t enabled = FALSE;
2420 dbus_message_iter_get_basic(iter, &enabled);
2421 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
2422 const char *str = NULL;
2424 dbus_message_iter_get_basic(iter, &str);
2426 g_hash_table_replace(network->config_table,
2427 g_strdup(key), g_strdup(str));
2430 SUPPLICANT_DBG("key %s type %c",
2431 key, dbus_message_iter_get_arg_type(iter));
2434 static void interface_network_added(DBusMessageIter *iter, void *user_data)
2436 GSupplicantInterface *interface = user_data;
2437 GSupplicantNetwork *network;
2438 const char *path = NULL;
2442 dbus_message_iter_get_basic(iter, &path);
2446 if (g_strcmp0(path, "/") == 0)
2449 network = g_try_new0(GSupplicantNetwork, 1);
2453 network->interface = interface;
2454 network->path = g_strdup(path);
2456 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2459 dbus_message_iter_next(iter);
2460 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
2461 supplicant_dbus_property_foreach(iter, network_property,
2463 network_property(NULL, NULL, network);
2467 supplicant_dbus_property_get_all(path,
2468 SUPPLICANT_INTERFACE ".Network",
2469 network_property, network, NULL);
2472 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
2477 static char *create_name(unsigned char *ssid, int ssid_len)
2480 const gchar *remainder, *invalid;
2481 int valid_bytes, remaining_bytes;
2483 if (ssid_len < 1 || ssid[0] == '\0')
2484 return g_strdup("");
2487 remainder = (const gchar *)ssid;
2488 remaining_bytes = ssid_len;
2490 while (remaining_bytes != 0) {
2491 if (g_utf8_validate(remainder, remaining_bytes,
2496 valid_bytes = invalid - remainder;
2499 string = g_string_sized_new(remaining_bytes);
2501 g_string_append_len(string, remainder, valid_bytes);
2503 /* append U+FFFD REPLACEMENT CHARACTER */
2504 g_string_append(string, "\357\277\275");
2506 remaining_bytes -= valid_bytes + 1;
2507 remainder = invalid + 1;
2511 return g_strndup((const gchar *)ssid, ssid_len + 1);
2513 g_string_append(string, remainder);
2515 return g_string_free(string, FALSE);
2518 static char *create_group(struct g_supplicant_bss *bss)
2522 const char *mode, *security;
2524 str = g_string_sized_new((bss->ssid_len * 2) + 24);
2528 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
2529 for (i = 0; i < bss->ssid_len; i++)
2530 g_string_append_printf(str, "%02x", bss->ssid[i]);
2532 g_string_append_printf(str, "hidden");
2534 mode = mode2string(bss->mode);
2536 g_string_append_printf(str, "_%s", mode);
2538 security = security2string(bss->security);
2540 g_string_append_printf(str, "_%s", security);
2542 return g_string_free(str, FALSE);
2544 #if defined TIZEN_EXT
2545 static void update_network_with_best_bss(GSupplicantNetwork *network,
2546 struct g_supplicant_bss *best_bss)
2548 network->signal = best_bss->signal;
2549 network->frequency = best_bss->frequency;
2550 network->best_bss = best_bss;
2553 static bool update_best_bss(GSupplicantNetwork *network,
2554 struct g_supplicant_bss *bss, struct g_supplicant_bss *best_bss)
2559 if (network->best_bss == NULL) {
2560 update_network_with_best_bss(network, bss);
2564 score_new = calculate_score(
2565 compare_bssid(bss->bssid, network->last_connected_bssid),
2566 get_assoc_reject_cnt(network->assoc_reject_table, bss->bssid),
2567 bss->frequency, bss->signal, bss->snr, bss->est_throughput);
2569 score_best = calculate_score(
2570 compare_bssid(network->best_bss->bssid, network->last_connected_bssid),
2571 get_assoc_reject_cnt(network->assoc_reject_table, network->best_bss->bssid),
2572 network->best_bss->frequency, network->best_bss->signal,
2573 network->best_bss->snr, network->best_bss->est_throughput);
2575 if (score_new > score_best) {
2576 SUPPLICANT_DBG("new[" MACSTR "][%u] : best[" MACSTR "][%u]",
2577 MAC2STR(bss->bssid), score_new,
2578 MAC2STR(network->best_bss->bssid), score_best);
2580 update_network_with_best_bss(network, bss);
2582 SUPPLICANT_DBG("Update best BSS for %s", network->name);
2590 static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
2592 GSupplicantInterface *interface = bss->interface;
2593 GSupplicantNetwork *network;
2595 bool is_new_network;
2597 group = create_group(bss);
2598 SUPPLICANT_DBG("New group created: %s", group);
2603 network = g_hash_table_lookup(interface->network_table, group);
2606 SUPPLICANT_DBG("Network %s already exist", network->name);
2607 is_new_network = false;
2612 is_new_network = true;
2614 network = g_try_new0(GSupplicantNetwork, 1);
2620 network->interface = interface;
2622 network->path = g_strdup(bss->path);
2623 network->group = group;
2624 network->name = create_name(bss->ssid, bss->ssid_len);
2625 network->mode = bss->mode;
2626 network->security = bss->security;
2627 network->ssid_len = bss->ssid_len;
2628 memcpy(network->ssid, bss->ssid, bss->ssid_len);
2629 network->signal = bss->signal;
2630 network->frequency = bss->frequency;
2631 network->best_bss = bss;
2633 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2634 network->wps = TRUE;
2635 network->wps_capabilities = bss->wps_capabilities;
2638 #if defined TIZEN_EXT
2639 network->owe_transition_mode = bss->owe_transition_mode;
2640 memcpy(network->transition_mode_ssid, bss->transition_mode_ssid, bss->transition_mode_ssid_len);
2641 memcpy(network->transition_mode_bssid, bss->transition_mode_bssid, WIFI_BSSID_LEN_MAX);
2643 network->keymgmt = bss->keymgmt;
2645 if (g_slist_length(bss->vsie_list) > 0) {
2646 GSList *list = NULL;
2647 unsigned char *vsie = NULL;
2648 for (list = bss->vsie_list; list; list = list->next) {
2649 unsigned char *ie = (unsigned char *)list->data;
2650 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2653 memcpy(vsie, ie, ie[1]+2);
2654 network->vsie_list = g_slist_append(network->vsie_list, vsie);
2656 SUPPLICANT_DBG("Failed to allocate memory.");
2660 network->isHS20AP = bss->hs20;
2661 memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
2662 network->phy_mode = bss->phy_mode;
2665 SUPPLICANT_DBG("New network %s created", network->name);
2667 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2670 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2673 #if defined TIZEN_EXT
2674 network->assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2675 NULL, remove_assoc_data);
2678 g_hash_table_replace(interface->network_table,
2679 network->group, network);
2681 callback_network_added(network);
2684 /* We update network's WPS properties if only bss provides WPS. */
2685 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2686 network->wps = TRUE;
2687 network->wps_capabilities = bss->wps_capabilities;
2689 if (!is_new_network)
2690 callback_network_changed(network, "WPSCapabilities");
2694 * Do not change best BSS if we are connected. It will be done through
2695 * CurrentBSS property in case of misalignment with wpa_s or roaming.
2697 #if defined TIZEN_EXT
2698 if (network != interface->current_network) {
2699 if (update_best_bss(network, bss, network->best_bss))
2700 callback_network_changed(network, "Signal");
2703 if (network != interface->current_network &&
2704 bss->signal > network->signal) {
2705 network->signal = bss->signal;
2706 network->best_bss = bss;
2707 callback_network_changed(network, "Signal");
2711 g_hash_table_replace(interface->bss_mapping, bss->path, network);
2712 g_hash_table_replace(network->bss_table, bss->path, bss);
2714 g_hash_table_replace(bss_mapping, bss->path, interface);
2719 static void bss_rates(DBusMessageIter *iter, void *user_data)
2721 struct g_supplicant_bss *bss = user_data;
2722 dbus_uint32_t rate = 0;
2724 dbus_message_iter_get_basic(iter, &rate);
2728 if (rate > bss->maxrate)
2729 bss->maxrate = rate;
2732 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
2734 unsigned int *keymgmt = user_data;
2735 const char *str = NULL;
2738 dbus_message_iter_get_basic(iter, &str);
2742 for (i = 0; keymgmt_map[i].str; i++)
2743 if (strcmp(str, keymgmt_map[i].str) == 0) {
2744 SUPPLICANT_DBG("Keymgmt: %s", str);
2745 *keymgmt |= keymgmt_map[i].val;
2750 static void bss_group(DBusMessageIter *iter, void *user_data)
2752 unsigned int *group = user_data;
2753 const char *str = NULL;
2756 dbus_message_iter_get_basic(iter, &str);
2760 for (i = 0; group_map[i].str; i++)
2761 if (strcmp(str, group_map[i].str) == 0) {
2762 SUPPLICANT_DBG("Group: %s", str);
2763 *group |= group_map[i].val;
2768 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
2770 unsigned int *pairwise = user_data;
2771 const char *str = NULL;
2774 dbus_message_iter_get_basic(iter, &str);
2778 for (i = 0; pairwise_map[i].str; i++)
2779 if (strcmp(str, pairwise_map[i].str) == 0) {
2780 SUPPLICANT_DBG("Pairwise: %s", str);
2781 *pairwise |= pairwise_map[i].val;
2786 static void bss_wpa(const char *key, DBusMessageIter *iter,
2789 struct g_supplicant_bss *bss = user_data;
2790 unsigned int value = 0;
2792 SUPPLICANT_DBG("Key: %s", key);
2794 if (g_strcmp0(key, "KeyMgmt") == 0) {
2795 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
2797 if (bss->rsn_selected)
2798 bss->rsn_keymgmt = value;
2800 bss->wpa_keymgmt = value;
2801 } else if (g_strcmp0(key, "Group") == 0) {
2802 supplicant_dbus_array_foreach(iter, bss_group, &value);
2804 if (bss->rsn_selected)
2805 bss->rsn_group = value;
2807 bss->wpa_group = value;
2808 } else if (g_strcmp0(key, "Pairwise") == 0) {
2809 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
2811 if (bss->rsn_selected)
2812 bss->rsn_pairwise = value;
2814 bss->wpa_pairwise = value;
2818 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
2821 unsigned int len = 0;
2823 while (len + 4 < ie_size) {
2824 unsigned int hi = ie[len];
2825 unsigned int lo = ie[len + 1];
2826 unsigned int tmp_type = (hi << 8) + lo;
2827 unsigned int v_len = 0;
2829 /* hi and lo are used to recreate an unsigned int
2830 * based on 2 8bits length unsigned int. */
2834 v_len = (hi << 8) + lo;
2836 if (tmp_type == type) {
2837 unsigned int ret_value = 0;
2838 unsigned char *value = (unsigned char *)&ret_value;
2840 SUPPLICANT_DBG("IE: match type 0x%x", type);
2842 /* Verifying length relevance */
2843 if (v_len > sizeof(unsigned int) ||
2844 len + 4 + v_len > ie_size)
2847 memcpy(value, ie + len + 4, v_len);
2849 SUPPLICANT_DBG("returning 0x%x", ret_value);
2856 SUPPLICANT_DBG("returning 0");
2860 #if defined TIZEN_EXT
2861 static void get_bss_phy_mode(unsigned int max_rate,
2862 unsigned int max_ext_rate, bool ht, bool vht, void *data)
2864 struct g_supplicant_bss *bss = data;
2865 unsigned int freq = bss->frequency;
2867 /* Following conditions are used to determine
2868 * IEEE 802.11 Protocol Modes:-
2870 * 1. If “Supported rates” is only till 11 Mbps,
2871 * and frequency is in 2.4GHz band, then protocol is 11B.
2872 * 2. If “Supported rates” is till 54Mbps or
2873 * “Extended supported rates” are present,
2874 * and frequency is in 2.4GHz band, then protocol is 11G.
2875 * 3. If “Supported rates” is only till 54 Mbps,
2876 * frequency is in 5GHz band , then protocol is 11A.
2877 * 4. If “HT capabilities” is supported , then protocol is 11N.
2878 * 5. If “HT capabilities” & “VHT” is supported and
2879 * frequency is in 5 GHz band, then protocol is 11AC.
2882 if (freq >= 2412 && freq <= 2484) { /* 2.4 Ghz Band */
2883 if (max_rate <= 11 && max_ext_rate <= 0 && !ht)
2884 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211B;
2885 else if ((max_rate <= 54 || max_ext_rate > 0) && !ht)
2886 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BG;
2887 else if ((max_rate >= 54 || max_ext_rate > 0) && ht)
2888 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BGN;
2890 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2891 } else if (freq >= 5180 && freq <= 5825) { /* 5 Ghz Band */
2892 if (max_rate <= 54 && !ht)
2893 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211A;
2894 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && !vht)
2895 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211AN;
2896 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && vht)
2897 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211ANAC;
2899 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2904 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
2906 struct g_supplicant_bss *bss = user_data;
2907 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
2908 unsigned char *ie, *ie_end;
2909 DBusMessageIter array;
2912 #if defined TIZEN_EXT
2913 const unsigned char OWE_WFA_OUI[] = { 0x50, 0x6f, 0x9a, 0x1c };
2915 unsigned char *rates = NULL;
2916 unsigned char *ext_rates = NULL;
2917 unsigned int max_rate = 0;
2918 unsigned int max_ext_rate = 0;
2923 #define WMM_WPA1_WPS_INFO 221
2924 #define WPS_INFO_MIN_LEN 6
2925 #define WPS_VERSION_TLV 0x104A
2926 #define WPS_STATE_TLV 0x1044
2927 #define WPS_METHODS_TLV 0x1012
2928 #define WPS_REGISTRAR_TLV 0x1041
2929 #define WPS_VERSION 0x10
2930 #define WPS_PBC 0x04
2931 #define WPS_PIN 0x00
2932 #define WPS_CONFIGURED 0x02
2933 #if defined TIZEN_EXT
2934 #define VENDOR_SPECIFIC_INFO 0xDD
2935 #define WLAN_EID_COUNTRY 7
2938 dbus_message_iter_recurse(iter, &array);
2939 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
2941 if (!ie || ie_len < 2)
2944 bss->wps_capabilities = 0;
2947 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
2949 #if defined TIZEN_EXT
2950 unsigned char *vsie;
2953 if(ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, OWE_WFA_OUI, sizeof(OWE_WFA_OUI)) == 0) {
2954 SUPPLICANT_DBG("IE: match vendor specific data : OWE Transition Mode");
2957 Tag: Vendor Specific: Wi-Fi Alliance: OWE Transition Mode
2958 Tag Number: Vendor Specific (221) -> ie[0]
2959 Tag length: 26 -> ie[1]
2960 OUI: 50:6f:9a (Wi-Fi Alliance) -> ie[2]
2961 Vendor Specific OUI Type: 28 -> ie[5]
2962 BSSID: 92:fd:f0:20:2b:09 -> ie[6]
2963 SSID length: 15 -> ie[12]
2964 SSID: Wi-Fi-5.2.3-owe -> ie[13]
2966 0000 dd 1a 50 6f 9a 1c 92 fd f0 20 2b 09 0f 57 69 2d ..Po..... +..Wi-
2967 0010 46 69 2d 35 2e 32 2e 33 2d 6f 77 65 Fi-5.2.3-owe
2970 bss->owe_transition_mode = TRUE;
2971 if (ie[1] >= 11) { // Tag length is at least up to ssid length position.
2972 memcpy(bss->transition_mode_bssid, ie+6, WIFI_BSSID_LEN_MAX);
2973 if (ie[12] > 0 && ie[12] < 32) {
2974 memcpy(bss->transition_mode_ssid, ie+13, ie[12]);
2975 bss->transition_mode_ssid_len = ie[12];
2977 bss->transition_mode_ssid_len = 0;
2979 bss->owe_transition_mode = FALSE;
2983 if(ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
2985 if (!simplified_log)
2986 SUPPLICANT_DBG("IE: match vendor specific data");
2988 vsie_len = ie[1]+2; // tag number size(1), tag length size(1)
2989 vsie = (unsigned char *)g_try_malloc0(vsie_len);
2992 memcpy(vsie, ie, vsie_len);
2993 bss->vsie_list = g_slist_append(bss->vsie_list, vsie);
2995 SUPPLICANT_DBG("Failed to allocate memory");
2999 if(ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
3000 /* Add country code only if it is a valid alphabet */
3001 if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
3002 memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
3007 if (ie[0] == WLAN_EID_HT_CAP && ie[1]) {
3012 if (ie[0] == WLAN_EID_VHT_CAP && ie[1]) {
3017 if (ie[0] == WLAN_EID_SUPP_RATES && ie[1]) {
3019 rates = g_malloc0(r_len);
3023 for (j = 0; ie && j < r_len; j++) {
3024 rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3025 if (max_rate < rates[j])
3026 max_rate = rates[j];
3031 if (ie[0] == WLAN_EID_EXT_SUPP_RATES && ie[1] > 0) {
3033 ext_rates = g_malloc0(r_len);
3037 for (j = 0; ie && j < r_len; j++) {
3038 ext_rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3039 if (max_ext_rate < ext_rates[j])
3040 max_ext_rate = ext_rates[j];
3045 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
3046 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
3049 SUPPLICANT_DBG("IE: match WPS_OUI");
3051 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
3052 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
3054 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
3056 if (value == WPS_CONFIGURED)
3057 bss->wps_capabilities |=
3058 G_SUPPLICANT_WPS_CONFIGURED;
3061 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
3063 if (GUINT16_FROM_BE(value) == WPS_PBC)
3064 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3065 if (GUINT16_FROM_BE(value) == WPS_PIN)
3066 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3068 bss->wps_capabilities |=
3069 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
3071 /* If the AP sends this it means it's advertizing
3072 * as a registrar and the WPS process is launched
3074 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
3075 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
3077 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
3080 get_bss_phy_mode(max_rate, max_ext_rate, ht, vht, user_data);
3088 static void bss_compute_security(struct g_supplicant_bss *bss)
3091 * Combining RSN and WPA keymgmt
3092 * We combine it since parsing IEs might have set something for WPS. */
3093 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
3095 bss->ieee8021x = FALSE;
3097 #if defined TIZEN_EXT
3098 bss->ft_ieee8021x = FALSE;
3099 bss->ft_psk = FALSE;
3102 #if defined TIZEN_EXT
3104 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3105 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3106 bss->ieee8021x = TRUE;
3107 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
3108 bss->ft_ieee8021x = TRUE;
3111 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3112 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
3113 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3114 bss->ieee8021x = TRUE;
3117 #if defined TIZEN_EXT
3119 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3120 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3122 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
3126 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3127 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
3128 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3132 #if defined TIZEN_EXT
3133 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
3135 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_OWE)
3137 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_DPP)
3142 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3143 #if defined TIZEN_EXT
3145 bss->security = G_SUPPLICANT_SECURITY_SAE;
3148 bss->security = G_SUPPLICANT_SECURITY_PSK;
3149 #if defined TIZEN_EXT
3150 else if (bss->ft_psk)
3151 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
3152 else if (bss->ft_ieee8021x == TRUE)
3153 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3154 else if (bss->owe || bss->owe_transition_mode)
3155 bss->security = G_SUPPLICANT_SECURITY_OWE;
3157 bss->security = G_SUPPLICANT_SECURITY_DPP;
3159 else if (bss->privacy)
3160 bss->security = G_SUPPLICANT_SECURITY_WEP;
3162 bss->security = G_SUPPLICANT_SECURITY_NONE;
3166 static void bss_property(const char *key, DBusMessageIter *iter,
3169 struct g_supplicant_bss *bss = user_data;
3171 if (!bss->interface)
3173 #if defined TIZEN_EXT
3174 if (!simplified_log)
3176 SUPPLICANT_DBG("key %s", key);
3181 if (g_strcmp0(key, "BSSID") == 0) {
3182 DBusMessageIter array;
3183 unsigned char *addr;
3186 dbus_message_iter_recurse(iter, &array);
3187 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
3190 memcpy(bss->bssid, addr, addr_len);
3191 } else if (g_strcmp0(key, "SSID") == 0) {
3192 DBusMessageIter array;
3193 unsigned char *ssid;
3196 dbus_message_iter_recurse(iter, &array);
3197 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
3199 if (ssid_len > 0 && ssid_len < 33) {
3200 memcpy(bss->ssid, ssid, ssid_len);
3201 bss->ssid_len = ssid_len;
3203 memset(bss->ssid, 0, sizeof(bss->ssid));
3206 } else if (g_strcmp0(key, "Capabilities") == 0) {
3207 dbus_uint16_t capabilities = 0x0000;
3209 dbus_message_iter_get_basic(iter, &capabilities);
3211 if (capabilities & IEEE80211_CAP_ESS)
3212 bss->mode = G_SUPPLICANT_MODE_INFRA;
3213 else if (capabilities & IEEE80211_CAP_IBSS)
3214 bss->mode = G_SUPPLICANT_MODE_IBSS;
3216 if (capabilities & IEEE80211_CAP_PRIVACY)
3217 bss->privacy = TRUE;
3218 } else if (g_strcmp0(key, "Mode") == 0) {
3219 const char *mode = NULL;
3221 dbus_message_iter_get_basic(iter, &mode);
3222 bss->mode = string2mode(mode);
3223 } else if (g_strcmp0(key, "Frequency") == 0) {
3224 dbus_uint16_t frequency = 0;
3226 dbus_message_iter_get_basic(iter, &frequency);
3227 bss->frequency = frequency;
3228 } else if (g_strcmp0(key, "Signal") == 0) {
3229 dbus_int16_t signal = 0;
3231 dbus_message_iter_get_basic(iter, &signal);
3233 bss->signal = signal;
3235 bss->signal = BSS_UNKNOWN_STRENGTH;
3237 } else if (g_strcmp0(key, "Level") == 0) {
3238 dbus_int32_t level = 0;
3240 dbus_message_iter_get_basic(iter, &level);
3241 } else if (g_strcmp0(key, "Rates") == 0) {
3242 supplicant_dbus_array_foreach(iter, bss_rates, bss);
3243 } else if (g_strcmp0(key, "MaxRate") == 0) {
3244 dbus_uint32_t maxrate = 0;
3246 dbus_message_iter_get_basic(iter, &maxrate);
3248 bss->maxrate = maxrate;
3249 } else if (g_strcmp0(key, "Privacy") == 0) {
3250 dbus_bool_t privacy = FALSE;
3252 dbus_message_iter_get_basic(iter, &privacy);
3253 bss->privacy = privacy;
3254 } else if (g_strcmp0(key, "RSN") == 0) {
3255 bss->rsn_selected = TRUE;
3257 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3258 } else if (g_strcmp0(key, "WPA") == 0) {
3259 bss->rsn_selected = FALSE;
3261 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3262 #if defined TIZEN_EXT
3263 } else if (g_strcmp0(key, "HS20") == 0) {
3264 dbus_bool_t hs20 = FALSE;
3265 dbus_message_iter_get_basic(iter, &hs20);
3267 } else if (g_strcmp0(key, "SNR") == 0) {
3268 dbus_int16_t snr = 0;
3270 dbus_message_iter_get_basic(iter, &snr);
3272 } else if (g_strcmp0(key, "EstThroughput") == 0) {
3273 dbus_uint32_t est_throughput = 0;
3275 dbus_message_iter_get_basic(iter, &est_throughput);
3276 if (est_throughput != 0)
3277 bss->est_throughput = est_throughput;
3279 } else if (g_strcmp0(key, "IEs") == 0)
3280 bss_process_ies(iter, bss);
3282 SUPPLICANT_DBG("key %s type %c",
3283 key, dbus_message_iter_get_arg_type(iter));
3286 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
3289 GSupplicantInterface *interface = user_data;
3290 GSupplicantNetwork *network;
3291 struct g_supplicant_bss *bss;
3292 const char *path = NULL;
3293 #if defined TIZEN_EXT
3294 if (!simplified_log)
3298 dbus_message_iter_get_basic(iter, &path);
3302 if (g_strcmp0(path, "/") == 0)
3304 #if defined TIZEN_EXT
3305 if (!simplified_log)
3307 SUPPLICANT_DBG("%s", path);
3309 network = g_hash_table_lookup(interface->bss_mapping, path);
3311 bss = g_hash_table_lookup(network->bss_table, path);
3316 bss = g_try_new0(struct g_supplicant_bss, 1);
3320 bss->interface = interface;
3321 bss->path = g_strdup(path);
3322 bss->signal = BSS_UNKNOWN_STRENGTH;
3327 static void interface_bss_added_with_keys(DBusMessageIter *iter,
3330 struct g_supplicant_bss *bss;
3331 #if defined TIZEN_EXT
3332 if (!simplified_log)
3336 bss = interface_bss_added(iter, user_data);
3340 dbus_message_iter_next(iter);
3342 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
3343 #if defined TIZEN_EXT
3353 supplicant_dbus_property_foreach(iter, bss_property, bss);
3355 bss_compute_security(bss);
3356 if (add_or_replace_bss_to_network(bss) < 0)
3357 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3360 static void interface_bss_added_without_keys(DBusMessageIter *iter,
3363 struct g_supplicant_bss *bss;
3364 #if defined TIZEN_EXT
3365 if (!simplified_log)
3369 bss = interface_bss_added(iter, user_data);
3373 supplicant_dbus_property_get_all(bss->path,
3374 SUPPLICANT_INTERFACE ".BSS",
3375 bss_property, bss, bss);
3377 bss_compute_security(bss);
3378 if (add_or_replace_bss_to_network(bss) < 0)
3379 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3382 static void update_signal(gpointer key, gpointer value,
3385 struct g_supplicant_bss *bss = value;
3386 GSupplicantNetwork *network = user_data;
3388 #if defined TIZEN_EXT
3389 if (!network->best_bss || (network->best_bss == bss)) {
3390 if (bss->signal > network->signal) {
3391 network->signal = bss->signal;
3392 network->best_bss = bss;
3397 update_best_bss(network, bss, network->best_bss);
3399 if (bss->signal > network->signal) {
3400 network->signal = bss->signal;
3401 network->best_bss = bss;
3406 static void update_network_signal(GSupplicantNetwork *network)
3408 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
3411 g_hash_table_foreach(network->bss_table,
3412 update_signal, network);
3414 SUPPLICANT_DBG("New network signal %d", network->signal);
3417 #if defined TIZEN_EXT
3418 static gboolean last_connected_timeout(gpointer data)
3420 GSupplicantInterface *interface = data;
3421 GSupplicantNetwork *current_network = interface->current_network;
3423 SUPPLICANT_DBG("Timeout last connected bss");
3425 if (current_network && current_network->best_bss) {
3426 if (compare_bssid(current_network->best_bss->bssid, interface->connected_bssid)) {
3427 g_supplicant_network_set_last_connected_bssid(current_network, interface->connected_bssid);
3428 callback_network_changed(current_network, "LastConnectedBSSID");
3432 last_connected_bss_timeout = 0;
3436 static void add_timer_for_last_connected(GSupplicantInterface *interface)
3438 GSupplicantNetwork *current_network = interface->current_network;
3440 if (interface->state == G_SUPPLICANT_STATE_COMPLETED) {
3441 if (current_network) {
3442 struct g_supplicant_bss *best_bss = current_network->best_bss;
3444 memcpy(interface->connected_bssid, best_bss->bssid, WIFI_BSSID_LEN_MAX);
3446 if (last_connected_bss_timeout)
3447 g_source_remove(last_connected_bss_timeout);
3449 last_connected_bss_timeout = g_timeout_add_seconds(LAST_CONNECTED_TIMEOUT,
3450 last_connected_timeout, interface);
3452 SUPPLICANT_DBG("Add timer for last connected bssid [" MACSTR "]",
3453 MAC2STR(best_bss->bssid));
3458 static void remove_timer_for_last_connected(GSupplicantInterface *interface)
3460 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED) {
3461 if (last_connected_bss_timeout != 0) {
3462 g_source_remove(last_connected_bss_timeout);
3463 last_connected_bss_timeout = 0;
3464 SUPPLICANT_DBG("Remove timer for last connected bss");
3470 static void interface_current_bss(GSupplicantInterface *interface,
3471 DBusMessageIter *iter)
3473 GSupplicantNetwork *network;
3474 struct g_supplicant_bss *bss;
3477 dbus_message_iter_get_basic(iter, &path);
3478 if (g_strcmp0(path, "/") == 0) {
3479 interface->current_network = NULL;
3483 interface_bss_added_without_keys(iter, interface);
3485 network = g_hash_table_lookup(interface->bss_mapping, path);
3489 bss = g_hash_table_lookup(network->bss_table, path);
3493 interface->current_network = network;
3494 #if defined TIZEN_EXT
3495 SUPPLICANT_DBG("current network [%p]", interface->current_network);
3498 if (bss != network->best_bss) {
3500 * This is the case where either wpa_s got associated
3501 * to a BSS different than the one ConnMan considers
3502 * the best, or we are roaming.
3504 SUPPLICANT_DBG("Update best BSS for %s", network->name);
3506 network->best_bss = bss;
3508 if (network->signal != bss->signal) {
3509 SUPPLICANT_DBG("New network signal %d dBm",
3512 network->signal = bss->signal;
3513 callback_network_changed(network, "Signal");
3518 * wpa_s could notify about CurrentBSS in any state once
3519 * it got associated. It is not sure such notification will
3520 * arrive together with transition to ASSOCIATED state.
3521 * In fact, for networks with security WEP or OPEN, it
3522 * always arrives together with transition to COMPLETED.
3524 switch (interface->state) {
3525 case G_SUPPLICANT_STATE_UNKNOWN:
3526 case G_SUPPLICANT_STATE_DISABLED:
3527 case G_SUPPLICANT_STATE_DISCONNECTED:
3528 case G_SUPPLICANT_STATE_INACTIVE:
3529 case G_SUPPLICANT_STATE_SCANNING:
3530 case G_SUPPLICANT_STATE_AUTHENTICATING:
3531 case G_SUPPLICANT_STATE_ASSOCIATING:
3533 case G_SUPPLICANT_STATE_ASSOCIATED:
3534 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
3535 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
3536 case G_SUPPLICANT_STATE_COMPLETED:
3537 callback_network_associated(network);
3538 #if defined TIZEN_EXT
3539 add_timer_for_last_connected(interface);
3545 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
3547 GSupplicantInterface *interface = user_data;
3548 GSupplicantNetwork *network;
3549 struct g_supplicant_bss *bss = NULL;
3550 const char *path = NULL;
3551 bool is_current_network_bss = false;
3553 dbus_message_iter_get_basic(iter, &path);
3557 network = g_hash_table_lookup(interface->bss_mapping, path);
3561 bss = g_hash_table_lookup(network->bss_table, path);
3562 if (network->best_bss == bss) {
3563 network->best_bss = NULL;
3564 network->signal = BSS_UNKNOWN_STRENGTH;
3565 is_current_network_bss = true;
3568 g_hash_table_remove(bss_mapping, path);
3570 g_hash_table_remove(interface->bss_mapping, path);
3571 g_hash_table_remove(network->bss_table, path);
3573 update_network_signal(network);
3575 if (g_hash_table_size(network->bss_table) == 0) {
3576 g_hash_table_remove(interface->network_table, network->group);
3578 if (is_current_network_bss && network->best_bss)
3579 #if defined TIZEN_EXT
3580 callback_network_changed(network, "CheckMultiBssidConnect");
3582 callback_network_changed(network, "");
3587 static void set_config_methods(DBusMessageIter *iter, void *user_data)
3589 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
3592 static void wps_property(const char *key, DBusMessageIter *iter,
3595 GSupplicantInterface *interface = user_data;
3599 #if defined TIZEN_EXT
3600 if (!simplified_log)
3602 SUPPLICANT_DBG("key: %s", key);
3604 if (g_strcmp0(key, "ConfigMethods") == 0) {
3605 const char *config_methods = "push_button", *str = NULL;
3607 dbus_message_iter_get_basic(iter, &str);
3608 if (str && strlen(str) > 0) {
3609 /* It was already set at wpa_s level, don't modify it. */
3610 SUPPLICANT_DBG("%s", str);
3614 supplicant_dbus_property_set(interface->path,
3615 SUPPLICANT_INTERFACE ".Interface.WPS",
3616 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
3617 set_config_methods, NULL, &config_methods, NULL);
3619 SUPPLICANT_DBG("No value. Set %s", config_methods);
3624 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3625 void g_supplicant_replace_config_file(const char *ifname, const char *config_file)
3633 SUPPLICANT_DBG("New {%s, %s}", ifname, config_file);
3634 g_hash_table_replace(config_file_table,
3635 g_strdup(ifname), g_strdup(config_file));
3637 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3639 static void interface_property(const char *key, DBusMessageIter *iter,
3642 GSupplicantInterface *interface = user_data;
3646 #if defined TIZEN_EXT
3647 if (!simplified_log)
3649 SUPPLICANT_DBG("%s", key);
3652 debug_strvalmap("KeyMgmt capability", keymgmt_map,
3653 interface->keymgmt_capa);
3654 debug_strvalmap("AuthAlg capability", authalg_capa_map,
3655 interface->authalg_capa);
3656 debug_strvalmap("Protocol capability", proto_capa_map,
3657 interface->proto_capa);
3658 debug_strvalmap("Pairwise capability", pairwise_map,
3659 interface->pairwise_capa);
3660 debug_strvalmap("Group capability", group_map,
3661 interface->group_capa);
3662 debug_strvalmap("Scan capability", scan_capa_map,
3663 interface->scan_capa);
3664 debug_strvalmap("Mode capability", mode_capa_map,
3665 interface->mode_capa);
3667 supplicant_dbus_property_get_all(interface->path,
3668 SUPPLICANT_INTERFACE ".Interface.WPS",
3669 wps_property, interface, interface);
3671 if (interface->ready)
3672 callback_interface_added(interface);
3677 if (g_strcmp0(key, "Capabilities") == 0) {
3678 supplicant_dbus_property_foreach(iter, interface_capability,
3680 #if !defined TIZEN_EXT
3681 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
3682 interface->p2p_support = true;
3684 #if defined TIZEN_EXT_WIFI_MESH
3685 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_MESH)
3686 interface->mesh_support = true;
3688 } else if (g_strcmp0(key, "State") == 0) {
3689 const char *str = NULL;
3691 dbus_message_iter_get_basic(iter, &str);
3693 if (string2state(str) != interface->state) {
3694 interface->state = string2state(str);
3695 callback_interface_state(interface);
3697 #if defined TIZEN_EXT
3698 switch (interface->state) {
3699 case G_SUPPLICANT_STATE_COMPLETED:
3700 add_timer_for_last_connected(interface);
3702 case G_SUPPLICANT_STATE_DISCONNECTED:
3703 remove_timer_for_last_connected(interface);
3709 if (interface->ap_create_in_progress) {
3710 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
3711 callback_ap_create_fail(interface);
3713 interface->ap_create_in_progress = false;
3716 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
3717 interface->ready = FALSE;
3719 interface->ready = TRUE;
3721 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
3722 } else if (g_strcmp0(key, "Scanning") == 0) {
3723 dbus_bool_t scanning = FALSE;
3725 dbus_message_iter_get_basic(iter, &scanning);
3726 interface->scanning = scanning;
3728 if (interface->ready) {
3729 if (interface->scanning)
3730 callback_scan_started(interface);
3732 callback_scan_finished(interface);
3734 } else if (g_strcmp0(key, "ApScan") == 0) {
3737 dbus_message_iter_get_basic(iter, &apscan);
3738 interface->apscan = apscan;
3739 } else if (g_strcmp0(key, "Ifname") == 0) {
3740 const char *str = NULL;
3742 dbus_message_iter_get_basic(iter, &str);
3744 g_free(interface->ifname);
3745 interface->ifname = g_strdup(str);
3747 } else if (g_strcmp0(key, "Driver") == 0) {
3748 const char *str = NULL;
3750 dbus_message_iter_get_basic(iter, &str);
3752 g_free(interface->driver);
3753 interface->driver = g_strdup(str);
3755 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
3756 const char *str = NULL;
3758 dbus_message_iter_get_basic(iter, &str);
3760 g_free(interface->bridge);
3761 interface->bridge = g_strdup(str);
3763 } else if (g_strcmp0(key, "ConfigFile") == 0) {
3764 const char *str = NULL;
3766 dbus_message_iter_get_basic(iter, &str);
3767 if (str && strlen(str) > 0 && interface->ifname) {
3768 SUPPLICANT_DBG("New {%s, %s}", interface->ifname, str);
3769 g_hash_table_replace(config_file_table,
3770 g_strdup(interface->ifname), g_strdup(str));
3772 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
3773 interface_current_bss(interface, iter);
3774 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
3775 #if defined TIZEN_EXT
3776 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
3778 interface_network_added(iter, interface);
3779 } else if (g_strcmp0(key, "BSSs") == 0) {
3780 supplicant_dbus_array_foreach(iter,
3781 interface_bss_added_without_keys,
3783 } else if (g_strcmp0(key, "Blobs") == 0) {
3785 } else if (g_strcmp0(key, "Networks") == 0) {
3786 supplicant_dbus_array_foreach(iter, interface_network_added,
3788 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
3790 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3791 dbus_message_iter_get_basic(iter, &reason_code);
3792 callback_disconnect_reason_code(interface, reason_code);
3793 #if defined TIZEN_EXT
3794 SUPPLICANT_DBG("reason code (%d)", reason_code);
3797 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
3799 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3800 dbus_message_iter_get_basic(iter, &status_code);
3801 callback_assoc_status_code(interface, status_code);
3802 #if defined TIZEN_EXT
3803 SUPPLICANT_DBG("status code (%d)", status_code);
3807 SUPPLICANT_DBG("key %s type %c",
3808 key, dbus_message_iter_get_arg_type(iter));
3812 static void scan_network_update(DBusMessageIter *iter, void *user_data)
3814 GSupplicantInterface *interface = user_data;
3815 GSupplicantNetwork *network;
3821 dbus_message_iter_get_basic(iter, &path);
3826 if (g_strcmp0(path, "/") == 0)
3829 /* Update the network details based on scan BSS data */
3830 network = g_hash_table_lookup(interface->bss_mapping, path);
3832 callback_network_added(network);
3835 static void scan_bss_data(const char *key, DBusMessageIter *iter,
3838 GSupplicantInterface *interface = user_data;
3840 /*Fixed : stucking in scanning state when scan failed*/
3841 #if defined TIZEN_EXT
3842 GSupplicantInterfaceCallback scan_callback;
3847 supplicant_dbus_array_foreach(iter, scan_network_update,
3850 #if defined TIZEN_EXT
3851 scan_callback = interface->scan_callback;
3852 callback_scan_done(interface);
3855 if (interface->scan_callback)
3856 interface->scan_callback(0, interface, interface->scan_data);
3858 #if defined TIZEN_EXT
3859 if (interface->scan_callback == scan_callback) {
3861 interface->scan_callback = NULL;
3862 interface->scan_data = NULL;
3863 #if defined TIZEN_EXT
3868 static GSupplicantInterface *interface_alloc(const char *path)
3870 GSupplicantInterface *interface;
3872 interface = g_try_new0(GSupplicantInterface, 1);
3876 interface->path = g_strdup(path);
3878 interface->network_table = g_hash_table_new_full(g_str_hash,
3879 g_str_equal, NULL, remove_network);
3880 interface->peer_table = g_hash_table_new_full(g_str_hash,
3881 g_str_equal, NULL, remove_peer);
3882 interface->group_table = g_hash_table_new_full(g_str_hash,
3883 g_str_equal, NULL, remove_group);
3884 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
3887 g_hash_table_replace(interface_table, interface->path, interface);
3892 static void interface_added(DBusMessageIter *iter, void *user_data)
3894 GSupplicantInterface *interface;
3895 const char *path = NULL;
3896 bool properties_appended = GPOINTER_TO_UINT(user_data);
3900 dbus_message_iter_get_basic(iter, &path);
3904 if (g_strcmp0(path, "/") == 0)
3907 interface = g_hash_table_lookup(interface_table, path);
3911 interface = interface_alloc(path);
3915 if (!properties_appended) {
3916 supplicant_dbus_property_get_all(path,
3917 SUPPLICANT_INTERFACE ".Interface",
3918 interface_property, interface,
3923 dbus_message_iter_next(iter);
3924 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3925 supplicant_dbus_property_foreach(iter, interface_property,
3927 interface_property(NULL, NULL, interface);
3931 static void interface_removed(DBusMessageIter *iter, void *user_data)
3933 const char *path = NULL;
3934 GSupplicantInterface *interface = user_data;
3936 dbus_message_iter_get_basic(iter, &path);
3940 interface = g_hash_table_lookup(interface_table, path);
3941 g_supplicant_interface_cancel(interface);
3943 g_hash_table_remove(interface_table, path);
3946 static void eap_method(DBusMessageIter *iter, void *user_data)
3948 const char *str = NULL;
3951 dbus_message_iter_get_basic(iter, &str);
3955 for (i = 0; eap_method_map[i].str; i++)
3956 if (strcmp(str, eap_method_map[i].str) == 0) {
3957 eap_methods |= eap_method_map[i].val;
3962 static void service_property(const char *key, DBusMessageIter *iter,
3966 callback_system_ready();
3970 if (g_strcmp0(key, "DebugLevel") == 0) {
3971 const char *str = NULL;
3974 dbus_message_iter_get_basic(iter, &str);
3975 for (i = 0; debug_strings[i]; i++)
3976 if (g_strcmp0(debug_strings[i], str) == 0) {
3980 SUPPLICANT_DBG("Debug level %d", debug_level);
3981 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
3982 dbus_message_iter_get_basic(iter, &debug_timestamp);
3983 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
3984 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
3985 dbus_message_iter_get_basic(iter, &debug_showkeys);
3986 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
3987 } else if (g_strcmp0(key, "Interfaces") == 0) {
3988 supplicant_dbus_array_foreach(iter, interface_added, NULL);
3989 } else if (g_strcmp0(key, "EapMethods") == 0) {
3990 supplicant_dbus_array_foreach(iter, eap_method, NULL);
3991 debug_strvalmap("EAP method", eap_method_map, eap_methods);
3992 } else if (g_strcmp0(key, "Country") == 0) {
3993 const char *country = NULL;
3995 dbus_message_iter_get_basic(iter, &country);
3996 SUPPLICANT_DBG("Country %s", country);
3998 SUPPLICANT_DBG("key %s type %c",
3999 key, dbus_message_iter_get_arg_type(iter));
4002 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
4004 const char *name = NULL, *old = NULL, *new = NULL;
4008 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
4011 dbus_message_iter_get_basic(iter, &name);
4015 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
4018 dbus_message_iter_next(iter);
4019 dbus_message_iter_get_basic(iter, &old);
4020 dbus_message_iter_next(iter);
4021 dbus_message_iter_get_basic(iter, &new);
4026 if (strlen(old) > 0 && strlen(new) == 0) {
4027 system_available = FALSE;
4028 g_hash_table_remove_all(bss_mapping);
4029 g_hash_table_remove_all(peer_mapping);
4030 g_hash_table_remove_all(group_mapping);
4031 g_hash_table_remove_all(config_file_table);
4032 g_hash_table_remove_all(interface_table);
4033 callback_system_killed();
4036 if (strlen(new) > 0 && strlen(old) == 0) {
4037 system_available = TRUE;
4038 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
4039 SUPPLICANT_INTERFACE,
4040 service_property, NULL, NULL);
4044 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
4048 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
4051 supplicant_dbus_property_foreach(iter, service_property, NULL);
4054 static void signal_interface_added(const char *path, DBusMessageIter *iter)
4056 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
4058 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4059 interface_added(iter, GUINT_TO_POINTER(true));
4062 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
4066 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4067 interface_removed(iter, NULL);
4070 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
4072 GSupplicantInterface *interface;
4073 #if defined TIZEN_EXT
4074 if (!simplified_log)
4078 interface = g_hash_table_lookup(interface_table, path);
4082 supplicant_dbus_property_foreach(iter, interface_property, interface);
4085 static void signal_scan_done(const char *path, DBusMessageIter *iter)
4087 GSupplicantInterface *interface;
4088 dbus_bool_t success = FALSE;
4092 interface = g_hash_table_lookup(interface_table, path);
4096 dbus_message_iter_get_basic(iter, &success);
4098 if (interface->scanning) {
4099 callback_scan_finished(interface);
4100 interface->scanning = FALSE;
4104 * If scan is unsuccessful return -EIO else get the scanned BSSs
4105 * and update the network details accordingly
4108 if (interface->scan_callback)
4109 interface->scan_callback(-EIO, interface,
4110 interface->scan_data);
4112 interface->scan_callback = NULL;
4113 interface->scan_data = NULL;
4118 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
4119 "BSSs", scan_bss_data, interface, interface);
4122 static void signal_bss_added(const char *path, DBusMessageIter *iter)
4124 GSupplicantInterface *interface;
4125 #if defined TIZEN_EXT
4126 if (!simplified_log)
4130 interface = g_hash_table_lookup(interface_table, path);
4134 interface_bss_added_with_keys(iter, interface);
4137 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
4139 GSupplicantInterface *interface;
4143 interface = g_hash_table_lookup(interface_table, path);
4147 interface_bss_removed(iter, interface);
4150 static void signal_network_added(const char *path, DBusMessageIter *iter)
4152 GSupplicantInterface *interface;
4156 interface = g_hash_table_lookup(interface_table, path);
4160 interface_network_added(iter, interface);
4163 static void signal_network_removed(const char *path, DBusMessageIter *iter)
4165 GSupplicantInterface *interface;
4169 interface = g_hash_table_lookup(interface_table, path);
4173 interface_network_removed(iter, interface);
4175 #if defined TIZEN_EXT
4176 void *copy_vsie_list(gconstpointer src, gpointer data)
4178 return g_strdup(src);
4183 static void signal_sta_authorized(const char *path, DBusMessageIter *iter)
4185 GSupplicantInterface *interface;
4186 const char *addr = NULL;
4190 interface = g_hash_table_lookup(interface_table, path);
4194 dbus_message_iter_get_basic(iter, &addr);
4198 callback_sta_authorized(interface, addr);
4201 static void signal_sta_deauthorized(const char *path, DBusMessageIter *iter)
4203 GSupplicantInterface *interface;
4204 const char *addr = NULL;
4208 interface = g_hash_table_lookup(interface_table, path);
4212 dbus_message_iter_get_basic(iter, &addr);
4216 callback_sta_deauthorized(interface, addr);
4219 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4220 static void signal_eap(const char *path, DBusMessageIter *iter)
4222 GSupplicantInterface *interface;
4223 const char *str = NULL;
4225 SUPPLICANT_DBG("EAPOL_DEBUG callback eap signal");
4227 interface = g_hash_table_lookup(interface_table, path);
4231 // TODO: Identify EAP fail condition, currently timeout is used for failure.
4233 dbus_message_iter_get_basic(iter, &str);
4237 if (g_strcmp0("completion", str))
4240 dbus_message_iter_next(iter);
4242 dbus_message_iter_get_basic(iter, &str);
4246 if (!g_strcmp0("success", str))
4247 callback_eap(interface, true);
4249 callback_eap(interface, false);
4251 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4253 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
4255 GSupplicantInterface *interface;
4256 GSupplicantNetwork *network;
4257 GSupplicantSecurity old_security;
4258 unsigned int old_wps_capabilities;
4259 struct g_supplicant_bss *bss;
4261 #if defined TIZEN_EXT
4262 if (!simplified_log)
4266 interface = g_hash_table_lookup(bss_mapping, path);
4270 network = g_hash_table_lookup(interface->bss_mapping, path);
4274 bss = g_hash_table_lookup(network->bss_table, path);
4278 supplicant_dbus_property_foreach(iter, bss_property, bss);
4280 #if defined TIZEN_EXT
4281 network->frequency = bss->frequency;
4282 network->phy_mode = bss->phy_mode;
4284 old_security = network->security;
4285 bss_compute_security(bss);
4287 if (old_security != bss->security) {
4288 struct g_supplicant_bss *new_bss;
4290 SUPPLICANT_DBG("New network security for %s with path %s",
4291 bss->ssid, bss->path);
4294 * Security change policy:
4295 * - We first copy the current bss into a new one with
4296 * its own pointer (path)
4297 * - Clear the old bss pointer and remove the network completely
4298 * if there are no more BSSs in the bss table.
4299 * - The new bss will be added either to an existing network
4300 * or an additional network will be created
4303 new_bss = g_try_new0(struct g_supplicant_bss, 1);
4307 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
4308 new_bss->path = g_strdup(bss->path);
4309 #if defined TIZEN_EXT
4310 new_bss->vsie_list = g_slist_copy_deep(bss->vsie_list, copy_vsie_list, NULL);
4313 if (network->best_bss == bss) {
4314 network->best_bss = NULL;
4315 network->signal = BSS_UNKNOWN_STRENGTH;
4318 g_hash_table_remove(bss_mapping, path);
4320 g_hash_table_remove(interface->bss_mapping, path);
4321 g_hash_table_remove(network->bss_table, path);
4323 update_network_signal(network);
4325 if (g_hash_table_size(network->bss_table) == 0)
4326 g_hash_table_remove(interface->network_table,
4329 if (add_or_replace_bss_to_network(new_bss) < 0) {
4331 * Prevent a memory leak on failure in
4332 * add_or_replace_bss_to_network
4334 SUPPLICANT_DBG("Failed to add bss %s to network table",
4336 g_free(new_bss->path);
4343 old_wps_capabilities = network->wps_capabilities;
4345 if (old_wps_capabilities != bss->wps_capabilities) {
4346 network->wps_capabilities = bss->wps_capabilities;
4347 callback_network_changed(network, "WPSCapabilities");
4350 #if defined TIZEN_EXT
4351 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
4352 network->wps = TRUE;
4353 network->wps_capabilities |= bss->wps_capabilities;
4355 network->wps = FALSE;
4358 /* Consider only property changes of the connected BSS */
4359 if (network == interface->current_network && bss != network->best_bss)
4362 if (bss->signal == network->signal)
4367 callback_network_changed(network, "");
4373 * If the new signal is lower than the SSID signal, we need
4374 * to check for the new maximum.
4376 #if defined TIZEN_EXT
4377 if (!update_best_bss(network, bss, network->best_bss)) {
4378 if (bss != network->best_bss) {
4379 callback_network_changed(network, "");
4383 network->signal = bss->signal;
4384 update_network_signal(network);
4387 if (bss->signal < network->signal) {
4388 if (bss != network->best_bss)
4391 network->signal = bss->signal;
4392 update_network_signal(network);
4394 network->signal = bss->signal;
4395 network->best_bss = bss;
4399 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
4402 callback_network_changed(network, "Signal");
4405 static void wps_credentials(const char *key, DBusMessageIter *iter,
4408 GSupplicantInterface *interface = user_data;
4413 SUPPLICANT_DBG("key %s", key);
4415 if (g_strcmp0(key, "Key") == 0) {
4416 DBusMessageIter array;
4417 unsigned char *key_val;
4420 dbus_message_iter_recurse(iter, &array);
4421 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
4423 g_free(interface->wps_cred.key);
4424 interface->wps_cred.key = g_try_malloc0(
4425 sizeof(char) * key_len + 1);
4427 if (!interface->wps_cred.key)
4430 memcpy(interface->wps_cred.key, key_val,
4431 sizeof(char) * key_len);
4433 SUPPLICANT_DBG("WPS key present");
4434 } else if (g_strcmp0(key, "SSID") == 0) {
4435 DBusMessageIter array;
4436 unsigned char *ssid;
4439 dbus_message_iter_recurse(iter, &array);
4440 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
4442 if (ssid_len > 0 && ssid_len < 33) {
4443 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
4444 interface->wps_cred.ssid_len = ssid_len;
4446 memset(interface->wps_cred.ssid, 0, 32);
4447 interface->wps_cred.ssid_len = 0;
4452 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
4454 GSupplicantInterface *interface;
4458 interface = g_hash_table_lookup(interface_table, path);
4462 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
4465 static void wps_event_args(const char *key, DBusMessageIter *iter,
4468 GSupplicantInterface *interface = user_data;
4470 if (!key || !interface)
4473 SUPPLICANT_DBG("Arg Key %s", key);
4476 static void signal_wps_event(const char *path, DBusMessageIter *iter)
4478 GSupplicantInterface *interface;
4479 const char *name = NULL;
4483 interface = g_hash_table_lookup(interface_table, path);
4487 dbus_message_iter_get_basic(iter, &name);
4489 SUPPLICANT_DBG("Name: %s", name);
4491 if (g_strcmp0(name, "success") == 0)
4492 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
4493 else if (g_strcmp0(name, "fail") == 0)
4494 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
4496 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
4498 if (!dbus_message_iter_has_next(iter))
4501 dbus_message_iter_next(iter);
4503 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
4506 #if defined TIZEN_EXT
4507 static void signal_power_off(const char *path, DBusMessageIter *iter)
4509 int poweroff_state = 0;
4511 dbus_message_iter_get_basic(iter, &poweroff_state);
4513 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
4515 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
4516 if (poweroff_state != 2 && poweroff_state != 3)
4519 if (callbacks_pointer == NULL)
4522 if (callbacks_pointer->system_power_off == NULL)
4525 callbacks_pointer->system_power_off();
4529 static void create_peer_identifier(GSupplicantPeer *peer)
4531 const unsigned char test[ETH_ALEN] = {};
4536 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
4537 peer->identifier = g_strdup(peer->name);
4541 peer->identifier = g_malloc0(19);
4542 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
4543 peer->device_address[0],
4544 peer->device_address[1],
4545 peer->device_address[2],
4546 peer->device_address[3],
4547 peer->device_address[4],
4548 peer->device_address[5]);
4551 struct peer_property_data {
4552 GSupplicantPeer *peer;
4554 bool groups_changed;
4555 bool services_changed;
4558 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
4560 struct peer_property_data *data = user_data;
4561 GSupplicantPeer *peer = data->peer;
4562 GSupplicantGroup *group;
4563 const char *str = NULL;
4566 dbus_message_iter_get_basic(iter, &str);
4570 group = g_hash_table_lookup(group_mapping, str);
4574 elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
4576 data->old_groups = g_slist_remove_link(data->old_groups, elem);
4577 peer->groups = g_slist_concat(elem, peer->groups);
4579 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
4580 data->groups_changed = true;
4584 static void peer_property(const char *key, DBusMessageIter *iter,
4587 GSupplicantPeer *pending_peer;
4588 struct peer_property_data *data = user_data;
4589 GSupplicantPeer *peer = data->peer;
4591 SUPPLICANT_DBG("key: %s", key);
4593 if (!peer->interface)
4598 create_peer_identifier(peer);
4599 callback_peer_found(peer);
4600 pending_peer = g_hash_table_lookup(
4601 pending_peer_connection, peer->path);
4603 if (pending_peer && pending_peer == peer) {
4604 callback_peer_request(peer);
4605 g_hash_table_remove(pending_peer_connection,
4615 if (g_strcmp0(key, "DeviceAddress") == 0) {
4616 unsigned char *dev_addr;
4617 DBusMessageIter array;
4620 dbus_message_iter_recurse(iter, &array);
4621 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4623 if (len == ETH_ALEN)
4624 memcpy(peer->device_address, dev_addr, len);
4625 } else if (g_strcmp0(key, "DeviceName") == 0) {
4626 const char *str = NULL;
4628 dbus_message_iter_get_basic(iter, &str);
4630 peer->name = g_strdup(str);
4631 } else if (g_strcmp0(key, "config_method") == 0) {
4632 uint16_t wps_config;
4634 dbus_message_iter_get_basic(iter, &wps_config);
4636 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
4637 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
4638 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
4639 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
4640 } else if (g_strcmp0(key, "Groups") == 0) {
4641 data->old_groups = peer->groups;
4642 peer->groups = NULL;
4644 supplicant_dbus_array_foreach(iter,
4645 peer_groups_relation, data);
4646 if (g_slist_length(data->old_groups) > 0) {
4647 g_slist_free_full(data->old_groups, g_free);
4648 data->groups_changed = true;
4650 } else if (g_strcmp0(key, "IEs") == 0) {
4651 DBusMessageIter array;
4655 dbus_message_iter_recurse(iter, &array);
4656 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
4658 if (!ie || ie_len < 2)
4661 if (peer->widi_ies) {
4662 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
4665 g_free(peer->widi_ies);
4666 peer->widi_ies_length = 0;
4669 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
4671 memcpy(peer->widi_ies, ie, ie_len);
4672 peer->widi_ies_length = ie_len;
4673 data->services_changed = true;
4677 static void signal_peer_found(const char *path, DBusMessageIter *iter)
4679 struct peer_property_data *property_data;
4680 GSupplicantInterface *interface;
4681 const char *obj_path = NULL;
4682 GSupplicantPeer *peer;
4686 interface = g_hash_table_lookup(interface_table, path);
4690 dbus_message_iter_get_basic(iter, &obj_path);
4691 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4694 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4698 peer = g_try_new0(GSupplicantPeer, 1);
4702 peer->interface = interface;
4703 peer->path = g_strdup(obj_path);
4704 g_hash_table_insert(interface->peer_table, peer->path, peer);
4705 g_hash_table_replace(peer_mapping, peer->path, interface);
4707 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4708 property_data->peer = peer;
4710 dbus_message_iter_next(iter);
4711 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4712 supplicant_dbus_property_foreach(iter, peer_property,
4714 peer_property(NULL, NULL, property_data);
4718 supplicant_dbus_property_get_all(obj_path,
4719 SUPPLICANT_INTERFACE ".Peer",
4720 peer_property, property_data, NULL);
4723 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
4725 GSupplicantInterface *interface;
4726 const char *obj_path = NULL;
4727 GSupplicantPeer *peer;
4731 interface = g_hash_table_lookup(interface_table, path);
4735 dbus_message_iter_get_basic(iter, &obj_path);
4736 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4739 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4743 g_hash_table_remove(interface->peer_table, obj_path);
4746 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
4748 struct peer_property_data *property_data;
4749 GSupplicantInterface *interface;
4750 GSupplicantPeer *peer;
4754 interface = g_hash_table_lookup(peer_mapping, path);
4758 peer = g_hash_table_lookup(interface->peer_table, path);
4760 g_hash_table_remove(peer_mapping, path);
4764 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4765 property_data->peer = peer;
4767 supplicant_dbus_property_foreach(iter, peer_property, property_data);
4768 if (property_data->services_changed)
4769 callback_peer_changed(peer,
4770 G_SUPPLICANT_PEER_SERVICES_CHANGED);
4772 if (property_data->groups_changed)
4773 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
4775 dbus_free(property_data);
4777 if (!g_supplicant_peer_is_in_a_group(peer))
4778 peer->connection_requested = false;
4781 struct group_sig_data {
4782 const char *peer_obj_path;
4783 unsigned char iface_address[ETH_ALEN];
4784 const char *interface_obj_path;
4785 const char *group_obj_path;
4789 static void group_sig_property(const char *key, DBusMessageIter *iter,
4792 struct group_sig_data *data = user_data;
4797 if (g_strcmp0(key, "peer_interface_addr") == 0) {
4798 unsigned char *dev_addr;
4799 DBusMessageIter array;
4802 dbus_message_iter_recurse(iter, &array);
4803 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4805 if (len == ETH_ALEN)
4806 memcpy(data->iface_address, dev_addr, len);
4807 } else if (g_strcmp0(key, "role") == 0) {
4808 const char *str = NULL;
4810 dbus_message_iter_get_basic(iter, &str);
4811 if (g_strcmp0(str, "GO") == 0)
4812 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
4814 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
4815 } else if (g_strcmp0(key, "peer_object") == 0)
4816 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
4817 else if (g_strcmp0(key, "interface_object") == 0)
4818 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
4819 else if (g_strcmp0(key, "group_object") == 0)
4820 dbus_message_iter_get_basic(iter, &data->group_obj_path);
4824 static void signal_group_success(const char *path, DBusMessageIter *iter)
4826 GSupplicantInterface *interface;
4827 struct group_sig_data data = {};
4828 GSupplicantPeer *peer;
4832 interface = g_hash_table_lookup(interface_table, path);
4836 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4837 if (!data.peer_obj_path)
4840 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4844 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
4845 interface->pending_peer_path = peer->path;
4848 static void signal_group_failure(const char *path, DBusMessageIter *iter)
4850 GSupplicantInterface *interface;
4851 struct group_sig_data data = {};
4852 GSupplicantPeer *peer;
4856 interface = g_hash_table_lookup(interface_table, path);
4860 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4861 if (!data.peer_obj_path)
4864 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4868 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
4869 peer->connection_requested = false;
4872 static void signal_group_started(const char *path, DBusMessageIter *iter)
4874 GSupplicantInterface *interface, *g_interface;
4875 struct group_sig_data data = {};
4876 GSupplicantGroup *group;
4877 GSupplicantPeer *peer;
4881 interface = g_hash_table_lookup(interface_table, path);
4885 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4886 if (!data.interface_obj_path || !data.group_obj_path)
4889 peer = g_hash_table_lookup(interface->peer_table,
4890 interface->pending_peer_path);
4891 interface->pending_peer_path = NULL;
4895 g_interface = g_hash_table_lookup(interface_table,
4896 data.interface_obj_path);
4900 group = g_hash_table_lookup(interface->group_table,
4901 data.group_obj_path);
4905 group = g_try_new0(GSupplicantGroup, 1);
4909 group->interface = g_interface;
4910 group->orig_interface = interface;
4911 group->path = g_strdup(data.group_obj_path);
4912 group->role = data.role;
4914 g_hash_table_insert(interface->group_table, group->path, group);
4915 g_hash_table_replace(group_mapping, group->path, group);
4917 peer->current_group_iface = g_interface;
4918 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
4921 static void remove_peer_group_interface(GHashTable *group_table,
4924 GSupplicantGroup *group;
4925 GHashTableIter iter;
4926 gpointer value, key;
4931 group = g_hash_table_lookup(group_table, path);
4933 if (!group || !group->orig_interface)
4936 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
4938 while (g_hash_table_iter_next(&iter, &key, &value)) {
4939 GSupplicantPeer *peer = value;
4941 if (peer->current_group_iface == group->interface)
4942 peer->current_group_iface = NULL;
4946 static void signal_group_finished(const char *path, DBusMessageIter *iter)
4948 GSupplicantInterface *interface;
4949 struct group_sig_data data = {};
4953 interface = g_hash_table_lookup(interface_table, path);
4957 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4958 if (!data.interface_obj_path || !data.group_obj_path)
4961 remove_peer_group_interface(interface->group_table, data.group_obj_path);
4963 g_hash_table_remove(group_mapping, data.group_obj_path);
4965 g_hash_table_remove(interface->group_table, data.group_obj_path);
4968 static void signal_group_request(const char *path, DBusMessageIter *iter)
4970 GSupplicantInterface *interface;
4971 GSupplicantPeer *peer;
4972 const char *obj_path;
4976 interface = g_hash_table_lookup(interface_table, path);
4980 dbus_message_iter_get_basic(iter, &obj_path);
4981 if (!obj_path || !g_strcmp0(obj_path, "/"))
4984 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4989 * Peer has been previously found and property set,
4990 * otherwise, defer connection to when peer property
4993 if (peer->identifier)
4994 callback_peer_request(peer);
4996 g_hash_table_replace(pending_peer_connection, peer->path, peer);
4999 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
5001 const char *peer_path = NULL;
5002 GSupplicantInterface *interface;
5003 GSupplicantGroup *group;
5004 GSupplicantPeer *peer;
5008 group = g_hash_table_lookup(group_mapping, path);
5012 dbus_message_iter_get_basic(iter, &peer_path);
5016 interface = g_hash_table_lookup(peer_mapping, peer_path);
5020 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5024 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
5026 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
5029 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
5031 const char *peer_path = NULL;
5032 GSupplicantInterface *interface;
5033 GSupplicantGroup *group;
5034 GSupplicantPeer *peer;
5039 group = g_hash_table_lookup(group_mapping, path);
5043 dbus_message_iter_get_basic(iter, &peer_path);
5047 for (elem = group->members; elem; elem = elem->next) {
5048 if (!g_strcmp0(elem->data, peer_path))
5056 group->members = g_slist_delete_link(group->members, elem);
5058 interface = g_hash_table_lookup(peer_mapping, peer_path);
5062 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5066 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
5067 peer->connection_requested = false;
5070 #if defined TIZEN_EXT_WIFI_MESH
5071 const void *g_supplicant_interface_get_mesh_group_ssid(
5072 GSupplicantInterface *interface,
5073 unsigned int *ssid_len)
5078 if (!interface || interface->group_info.ssid_len == 0) {
5083 *ssid_len = interface->group_info.ssid_len;
5084 return interface->group_info.ssid;
5087 int g_supplicant_mesh_get_disconnect_reason(GSupplicantInterface *interface)
5092 return interface->group_info.disconnect_reason;
5095 const char *g_supplicant_mesh_peer_get_address(GSupplicantMeshPeer *mesh_peer)
5097 if (!mesh_peer || !mesh_peer->peer_address)
5100 return mesh_peer->peer_address;
5103 int g_supplicant_mesh_peer_get_disconnect_reason(GSupplicantMeshPeer *mesh_peer)
5108 return mesh_peer->disconnect_reason;
5111 static void callback_mesh_group_started(GSupplicantInterface *interface)
5113 if (!callbacks_pointer)
5116 if (!callbacks_pointer->mesh_group_started)
5119 callbacks_pointer->mesh_group_started(interface);
5122 static void callback_mesh_group_removed(GSupplicantInterface *interface)
5124 if (!callbacks_pointer)
5127 if (!callbacks_pointer->mesh_group_removed)
5130 callbacks_pointer->mesh_group_removed(interface);
5133 static void mesh_group_info(const char *key, DBusMessageIter *iter,
5136 GSupplicantInterface *interface = user_data;
5140 if (g_strcmp0(key, "SSID") == 0) {
5141 DBusMessageIter array;
5142 unsigned char *ssid;
5145 dbus_message_iter_recurse(iter, &array);
5146 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
5148 if (ssid_len > 0 && ssid_len < 33) {
5149 memcpy(interface->group_info.ssid, ssid, ssid_len);
5150 interface->group_info.ssid_len = ssid_len;
5152 memset(interface->group_info.ssid, 0, 32);
5153 interface->group_info.ssid_len = 0;
5155 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5156 int disconnect_reason = 0;
5157 dbus_message_iter_get_basic(iter, &disconnect_reason);
5158 interface->group_info.disconnect_reason = disconnect_reason;
5162 static void signal_mesh_group_started(const char *path, DBusMessageIter *iter)
5164 GSupplicantInterface *interface;
5166 interface = g_hash_table_lookup(interface_table, path);
5170 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5172 callback_mesh_group_started(interface);
5175 static void signal_mesh_group_removed(const char *path, DBusMessageIter *iter)
5177 GSupplicantInterface *interface;
5179 interface = g_hash_table_lookup(interface_table, path);
5183 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5185 callback_mesh_group_removed(interface);
5188 static void callback_mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
5190 if (!callbacks_pointer)
5193 if (!callbacks_pointer->mesh_peer_connected)
5196 callbacks_pointer->mesh_peer_connected(mesh_peer);
5199 static void callback_mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
5201 if (!callbacks_pointer)
5204 if (!callbacks_pointer->mesh_peer_disconnected)
5207 callbacks_pointer->mesh_peer_disconnected(mesh_peer);
5210 static void mesh_peer_info(const char *key, DBusMessageIter *iter,
5213 GSupplicantMeshPeer *mesh_peer = user_data;
5217 if (g_strcmp0(key, "PeerAddress") == 0) {
5218 DBusMessageIter array;
5219 unsigned char *addr;
5222 dbus_message_iter_recurse(iter, &array);
5223 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
5225 if (addr_len == 6) {
5226 mesh_peer->peer_address = g_malloc0(19);
5227 snprintf(mesh_peer->peer_address, 19,
5228 "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1],
5229 addr[2], addr[3], addr[4], addr[5]);
5231 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5232 int disconnect_reason = 0;
5233 dbus_message_iter_get_basic(iter, &disconnect_reason);
5234 mesh_peer->disconnect_reason = disconnect_reason;
5238 static void signal_mesh_peer_connected(const char *path, DBusMessageIter *iter)
5240 GSupplicantInterface *interface;
5241 GSupplicantMeshPeer *mesh_peer;
5243 interface = g_hash_table_lookup(interface_table, path);
5247 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5248 mesh_peer->interface = interface;
5250 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5252 callback_mesh_peer_connected(mesh_peer);
5253 g_free(mesh_peer->peer_address);
5257 static void signal_mesh_peer_disconnected(const char *path,
5258 DBusMessageIter *iter)
5260 GSupplicantInterface *interface;
5261 GSupplicantMeshPeer *mesh_peer;
5263 interface = g_hash_table_lookup(interface_table, path);
5267 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5268 mesh_peer->interface = interface;
5270 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5272 callback_mesh_peer_disconnected(mesh_peer);
5273 g_free(mesh_peer->peer_address);
5279 const char *interface;
5281 void (*function) (const char *path, DBusMessageIter *iter);
5283 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
5285 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
5286 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
5287 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
5288 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
5290 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
5291 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
5292 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
5293 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
5294 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
5295 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
5296 { SUPPLICANT_INTERFACE ".Interface", "StaAuthorized", signal_sta_authorized },
5297 { SUPPLICANT_INTERFACE ".Interface", "StaDeauthorized", signal_sta_deauthorized },
5299 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
5301 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
5302 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
5303 #if defined TIZEN_EXT
5304 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
5307 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
5308 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
5310 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
5312 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
5313 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
5314 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
5315 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
5316 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
5318 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
5319 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
5320 #if defined TIZEN_EXT_WIFI_MESH
5321 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupStarted",
5322 signal_mesh_group_started },
5323 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupRemoved",
5324 signal_mesh_group_removed },
5325 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerConnected",
5326 signal_mesh_peer_connected },
5327 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerDisconnected",
5328 signal_mesh_peer_disconnected },
5331 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5332 { SUPPLICANT_INTERFACE ".Interface", "EAP", signal_eap },
5333 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5338 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
5339 DBusMessage *message, void *data)
5341 DBusMessageIter iter;
5345 path = dbus_message_get_path(message);
5347 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5349 if (!dbus_message_iter_init(message, &iter))
5350 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5352 for (i = 0; signal_map[i].interface; i++) {
5353 if (!dbus_message_has_interface(message, signal_map[i].interface))
5356 if (!dbus_message_has_member(message, signal_map[i].member))
5359 signal_map[i].function(path, &iter);
5363 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5366 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
5368 SUPPLICANT_DBG("Cancelling any pending DBus calls");
5369 supplicant_dbus_method_call_cancel_all(interface);
5370 supplicant_dbus_property_call_cancel_all(interface);
5373 struct supplicant_regdom {
5374 GSupplicantCountryCallback callback;
5376 const void *user_data;
5379 static void country_result(const char *error,
5380 DBusMessageIter *iter, void *user_data)
5382 struct supplicant_regdom *regdom = user_data;
5385 SUPPLICANT_DBG("Country setting result");
5391 SUPPLICANT_DBG("Country setting failure %s", error);
5395 if (regdom->callback)
5396 regdom->callback(result, regdom->alpha2,
5397 (void *) regdom->user_data);
5402 static void country_params(DBusMessageIter *iter, void *user_data)
5404 struct supplicant_regdom *regdom = user_data;
5406 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
5410 int g_supplicant_set_country(const char *alpha2,
5411 GSupplicantCountryCallback callback,
5412 const void *user_data)
5414 struct supplicant_regdom *regdom;
5417 SUPPLICANT_DBG("Country setting %s", alpha2);
5419 if (!system_available)
5422 regdom = dbus_malloc0(sizeof(*regdom));
5426 regdom->callback = callback;
5427 regdom->alpha2 = alpha2;
5428 regdom->user_data = user_data;
5430 ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
5431 "Country", DBUS_TYPE_STRING_AS_STRING,
5432 country_params, country_result,
5436 SUPPLICANT_DBG("Unable to set Country configuration");
5441 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
5442 GSupplicantCountryCallback callback,
5446 struct supplicant_regdom *regdom;
5449 regdom = dbus_malloc0(sizeof(*regdom));
5453 regdom->callback = callback;
5454 regdom->alpha2 = alpha2;
5455 regdom->user_data = user_data;
5457 ret = supplicant_dbus_property_set(interface->path,
5458 SUPPLICANT_INTERFACE ".Interface",
5459 "Country", DBUS_TYPE_STRING_AS_STRING,
5460 country_params, country_result,
5464 SUPPLICANT_DBG("Unable to set Country configuration");
5470 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
5475 return interface->p2p_support;
5478 struct supplicant_p2p_dev_config {
5483 static void p2p_device_config_result(const char *error,
5484 DBusMessageIter *iter, void *user_data)
5486 struct supplicant_p2p_dev_config *config = user_data;
5489 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
5492 g_free(config->device_name);
5493 g_free(config->dev_type);
5497 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
5499 int length, pos, end;
5504 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
5511 dev_type[length] = strtol(b, &e, 16);
5512 if (e && *e != '\0')
5521 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
5523 struct supplicant_p2p_dev_config *config = user_data;
5524 DBusMessageIter dict;
5526 supplicant_dbus_dict_open(iter, &dict);
5528 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
5529 DBUS_TYPE_STRING, &config->device_name);
5531 if (config->dev_type) {
5532 unsigned char dev_type[8] = {}, *type;
5535 len = dev_type_str2bin(config->dev_type, dev_type);
5538 supplicant_dbus_dict_append_fixed_array(&dict,
5539 "PrimaryDeviceType",
5540 DBUS_TYPE_BYTE, &type, len);
5544 supplicant_dbus_dict_close(iter, &dict);
5547 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
5548 const char *device_name,
5549 const char *primary_dev_type)
5551 struct supplicant_p2p_dev_config *config;
5554 SUPPLICANT_DBG("P2P Device settings %s/%s",
5555 device_name, primary_dev_type);
5557 config = dbus_malloc0(sizeof(*config));
5561 config->device_name = g_strdup(device_name);
5562 config->dev_type = g_strdup(primary_dev_type);
5564 ret = supplicant_dbus_property_set(interface->path,
5565 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5567 DBUS_TYPE_ARRAY_AS_STRING
5568 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
5569 DBUS_TYPE_STRING_AS_STRING
5570 DBUS_TYPE_VARIANT_AS_STRING
5571 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
5572 p2p_device_config_params,
5573 p2p_device_config_result, config, NULL);
5575 g_free(config->device_name);
5576 g_free(config->dev_type);
5578 SUPPLICANT_DBG("Unable to set P2P Device configuration");
5584 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
5587 const GSupplicantPeer *peer = value;
5588 const char *identifier = user_data;
5590 if (!g_strcmp0(identifier, peer->identifier))
5596 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
5597 const char *identifier)
5599 GSupplicantPeer *peer;
5601 peer = g_hash_table_find(interface->peer_table,
5602 peer_lookup_by_identifier,
5603 (void *) identifier);
5607 static void interface_create_data_free(struct interface_create_data *data)
5609 g_free(data->ifname);
5610 g_free(data->driver);
5611 g_free(data->bridge);
5612 #if defined TIZEN_EXT_WIFI_MESH
5613 g_free(data->parent_ifname);
5618 static bool interface_exists(GSupplicantInterface *interface,
5621 GSupplicantInterface *tmp;
5623 tmp = g_hash_table_lookup(interface_table, path);
5624 if (tmp && tmp == interface)
5630 static void interface_create_property(const char *key, DBusMessageIter *iter,
5633 struct interface_create_data *data = user_data;
5634 GSupplicantInterface *interface = data->interface;
5637 if (data->callback) {
5638 data->callback(0, data->interface, data->user_data);
5639 #if !defined TIZEN_EXT
5640 callback_p2p_support(interface);
5642 #if defined TIZEN_EXT_WIFI_MESH
5643 callback_mesh_support(interface);
5647 interface_create_data_free(data);
5650 interface_property(key, iter, interface);
5653 static void interface_create_result(const char *error,
5654 DBusMessageIter *iter, void *user_data)
5656 struct interface_create_data *data = user_data;
5657 const char *path = NULL;
5663 g_message("error %s", error);
5668 dbus_message_iter_get_basic(iter, &path);
5674 if (!system_available) {
5679 data->interface = g_hash_table_lookup(interface_table, path);
5680 if (!data->interface) {
5681 data->interface = interface_alloc(path);
5682 if (!data->interface) {
5688 err = supplicant_dbus_property_get_all(path,
5689 SUPPLICANT_INTERFACE ".Interface",
5690 interface_create_property, data,
5697 data->callback(err, NULL, data->user_data);
5699 interface_create_data_free(data);
5702 static void interface_create_params(DBusMessageIter *iter, void *user_data)
5704 struct interface_create_data *data = user_data;
5705 DBusMessageIter dict;
5706 char *config_file = NULL;
5710 supplicant_dbus_dict_open(iter, &dict);
5712 supplicant_dbus_dict_append_basic(&dict, "Ifname",
5713 DBUS_TYPE_STRING, &data->ifname);
5716 supplicant_dbus_dict_append_basic(&dict, "Driver",
5717 DBUS_TYPE_STRING, &data->driver);
5720 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
5721 DBUS_TYPE_STRING, &data->bridge);
5723 config_file = g_hash_table_lookup(config_file_table, data->ifname);
5725 SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
5727 supplicant_dbus_dict_append_basic(&dict, "ConfigFile",
5728 DBUS_TYPE_STRING, &config_file);
5732 if (data->driver && g_strstr_len(data->driver, strlen(data->driver), "nl80211")) {
5733 supplicant_dbus_dict_append_basic(&dict, "MacAddr",
5734 DBUS_TYPE_UINT32, &data->mac_addr);
5736 supplicant_dbus_dict_append_basic(&dict, "PreassocMacAddr",
5737 DBUS_TYPE_UINT32, &data->preassoc_mac_addr);
5739 supplicant_dbus_dict_append_basic(&dict, "RandAddrLifetime",
5740 DBUS_TYPE_UINT32, &data->random_mac_lifetime);
5742 #endif /* TIZEN_EXT */
5744 #if defined TIZEN_EXT_WIFI_MESH
5745 if (data->is_mesh_interface) {
5746 if (data->parent_ifname)
5747 supplicant_dbus_dict_append_basic(&dict, "ParentIfname",
5748 DBUS_TYPE_STRING, &data->parent_ifname);
5750 supplicant_dbus_dict_append_basic(&dict, "IsMeshInterface",
5751 DBUS_TYPE_BOOLEAN, &data->is_mesh_interface);
5755 supplicant_dbus_dict_close(iter, &dict);
5758 #if defined TIZEN_EXT
5759 static void interface_get_state(const char *key, DBusMessageIter *iter,
5762 struct interface_create_data *data = user_data;
5763 GSupplicantInterface *interface = NULL;
5764 const char *str = NULL;
5766 SUPPLICANT_DBG("key[%s]", key);
5769 SUPPLICANT_DBG("data is NULL");
5773 interface = data->interface;
5775 SUPPLICANT_DBG("interface is NULL");
5780 dbus_message_iter_get_basic(iter, &str);
5783 if (string2state(str) != interface->state)
5784 interface->state = string2state(str);
5787 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
5788 interface->ready = FALSE;
5790 interface->ready = TRUE;
5792 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
5794 if (data->callback) {
5795 data->callback(0, interface, data->user_data);
5796 #if defined TIZEN_EXT_WIFI_MESH
5797 callback_mesh_support(interface);
5801 interface_create_data_free(data);
5805 static void interface_get_result(const char *error,
5806 DBusMessageIter *iter, void *user_data)
5808 struct interface_create_data *data = user_data;
5809 GSupplicantInterface *interface;
5810 const char *path = NULL;
5813 #if defined TIZEN_EXT
5814 if (!simplified_log)
5819 SUPPLICANT_DBG("Interface not created yet");
5823 dbus_message_iter_get_basic(iter, &path);
5829 interface = g_hash_table_lookup(interface_table, path);
5835 #if defined TIZEN_EXT
5836 data->interface = interface;
5837 err = supplicant_dbus_property_get(path,
5838 SUPPLICANT_INTERFACE ".Interface",
5839 "State", interface_get_state, data, NULL);
5845 if (data->callback) {
5846 data->callback(0, interface, data->user_data);
5847 #if !defined TIZEN_EXT
5848 callback_p2p_support(interface);
5850 #if defined TIZEN_EXT_WIFI_MESH
5851 callback_mesh_support(interface);
5855 interface_create_data_free(data);
5860 if (!system_available) {
5865 SUPPLICANT_DBG("Creating interface");
5867 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
5868 SUPPLICANT_INTERFACE,
5870 interface_create_params,
5871 interface_create_result, data,
5878 data->callback(err, NULL, data->user_data);
5880 interface_create_data_free(data);
5883 static void interface_get_params(DBusMessageIter *iter, void *user_data)
5885 struct interface_create_data *data = user_data;
5886 #if defined TIZEN_EXT
5887 if (!simplified_log)
5891 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
5894 #if defined TIZEN_EXT_WIFI_MESH
5895 int g_supplicant_mesh_interface_create(const char *ifname, const char *driver,
5896 const char *bridge, const char *parent_ifname,
5897 GSupplicantInterfaceCallback callback, void *user_data)
5899 struct interface_create_data *data;
5902 SUPPLICANT_DBG("ifname %s", ifname);
5904 if (!ifname || !parent_ifname)
5907 if (!system_available)
5910 data = dbus_malloc0(sizeof(*data));
5914 data->ifname = g_strdup(ifname);
5915 data->driver = g_strdup(driver);
5916 data->bridge = g_strdup(bridge);
5917 data->is_mesh_interface = true;
5918 data->parent_ifname = g_strdup(parent_ifname);
5919 data->callback = callback;
5920 data->user_data = user_data;
5922 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5923 SUPPLICANT_INTERFACE,
5925 interface_create_params,
5926 interface_create_result, data,
5931 struct interface_mesh_peer_data {
5934 GSupplicantInterface *interface;
5935 GSupplicantInterfaceCallback callback;
5939 static void interface_mesh_change_peer_params(DBusMessageIter *iter,
5942 struct interface_mesh_peer_data *data = user_data;
5946 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->peer_address);
5949 static void interface_mesh_change_peer_result(const char *error,
5950 DBusMessageIter *iter, void *user_data)
5952 struct interface_mesh_peer_data *data = user_data;
5955 SUPPLICANT_DBG("%s", data->method);
5959 SUPPLICANT_DBG("error %s", error);
5963 data->callback(err, data->interface, data->user_data);
5965 g_free(data->peer_address);
5966 g_free(data->method);
5970 int g_supplicant_interface_mesh_peer_change_status(
5971 GSupplicantInterface *interface,
5972 GSupplicantInterfaceCallback callback, const char *peer_address,
5973 const char *method, void *user_data)
5975 struct interface_mesh_peer_data *data;
5981 data = dbus_malloc0(sizeof(*data));
5985 data->peer_address = g_strdup(peer_address);
5986 data->method = g_strdup(method);
5987 data->interface = interface;
5988 data->callback = callback;
5989 data->user_data = user_data;
5991 ret = supplicant_dbus_method_call(interface->path,
5992 SUPPLICANT_INTERFACE ".Interface.Mesh",
5993 method, interface_mesh_change_peer_params,
5994 interface_mesh_change_peer_result, data, NULL);
5996 g_free(data->peer_address);
5997 g_free(data->method);
6005 int g_supplicant_interface_create(const char *ifname, const char *driver,
6008 unsigned int mac_policy,
6009 unsigned int preassoc_mac_policy,
6010 unsigned int random_mac_lifetime,
6011 #endif /* TIZEN_EXT */
6012 GSupplicantInterfaceCallback callback,
6015 struct interface_create_data *data;
6018 SUPPLICANT_DBG("ifname %s", ifname);
6023 if (!system_available)
6026 data = dbus_malloc0(sizeof(*data));
6030 data->ifname = g_strdup(ifname);
6031 data->driver = g_strdup(driver);
6032 data->bridge = g_strdup(bridge);
6033 data->callback = callback;
6035 data->mac_addr = mac_policy;
6036 data->preassoc_mac_addr = preassoc_mac_policy;
6037 data->random_mac_lifetime = random_mac_lifetime;
6038 #endif /* TIZEN_EXT */
6039 data->user_data = user_data;
6041 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6042 SUPPLICANT_INTERFACE,
6044 interface_get_params,
6045 interface_get_result, data,
6048 interface_create_data_free(data);
6053 static void interface_remove_result(const char *error,
6054 DBusMessageIter *iter, void *user_data)
6056 struct interface_data *data = user_data;
6061 SUPPLICANT_DBG("error: %s", error);
6065 if (!system_available) {
6071 * The gsupplicant interface is already freed by the InterfaceRemoved
6072 * signal callback. Simply invoke the interface_data callback.
6080 data->callback(err, NULL, data->user_data);
6086 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
6088 struct interface_data *data = user_data;
6090 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6091 &data->interface->path);
6094 int g_supplicant_interface_remove(GSupplicantInterface *interface,
6095 GSupplicantInterfaceCallback callback,
6098 struct interface_data *data;
6104 if (!system_available)
6107 g_supplicant_interface_cancel(interface);
6109 data = dbus_malloc0(sizeof(*data));
6113 data->interface = interface;
6114 data->path = g_strdup(interface->path);
6115 data->callback = callback;
6116 data->user_data = user_data;
6118 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6119 SUPPLICANT_INTERFACE,
6121 interface_remove_params,
6122 interface_remove_result, data,
6131 static void interface_scan_result(const char *error,
6132 DBusMessageIter *iter, void *user_data)
6134 struct interface_scan_data *data = user_data;
6138 SUPPLICANT_DBG("error %s", error);
6142 /* A non ready interface cannot send/receive anything */
6143 if (interface_exists(data->interface, data->path)) {
6144 if (!data->interface->ready)
6152 data->callback(err, data->interface, data->user_data);
6154 data->interface->scan_callback = data->callback;
6155 data->interface->scan_data = data->user_data;
6158 if (data->scan_params)
6159 g_supplicant_free_scan_params(data->scan_params);
6164 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
6166 DBusMessageIter data;
6167 unsigned int width = 0; /* Not used by wpa_supplicant atm */
6169 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
6171 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
6172 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
6174 dbus_message_iter_close_container(iter, &data);
6177 static void add_scan_frequencies(DBusMessageIter *iter,
6180 GSupplicantScanParams *scan_data = user_data;
6184 for (i = 0; i < scan_data->num_freqs; i++) {
6185 freq = scan_data->freqs[i];
6189 add_scan_frequency(iter, freq);
6193 static void append_ssid(DBusMessageIter *iter,
6194 const void *ssid, unsigned int len)
6196 DBusMessageIter array;
6198 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
6199 DBUS_TYPE_BYTE_AS_STRING, &array);
6201 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
6203 dbus_message_iter_close_container(iter, &array);
6206 static void append_ssids(DBusMessageIter *iter, void *user_data)
6208 GSupplicantScanParams *scan_data = user_data;
6211 for (list = scan_data->ssids; list; list = list->next) {
6212 struct scan_ssid *scan_ssid = list->data;
6214 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
6218 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
6219 supplicant_dbus_array_function function,
6222 GSupplicantScanParams *scan_params = user_data;
6223 DBusMessageIter entry, value, array;
6224 const char *key = "Channels";
6226 if (scan_params->freqs && scan_params->freqs[0] != 0) {
6227 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
6230 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
6232 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
6233 DBUS_TYPE_ARRAY_AS_STRING
6234 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6235 DBUS_TYPE_UINT32_AS_STRING
6236 DBUS_TYPE_UINT32_AS_STRING
6237 DBUS_STRUCT_END_CHAR_AS_STRING,
6240 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
6241 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6242 DBUS_TYPE_UINT32_AS_STRING
6243 DBUS_TYPE_UINT32_AS_STRING
6244 DBUS_STRUCT_END_CHAR_AS_STRING,
6248 function(&array, user_data);
6250 dbus_message_iter_close_container(&value, &array);
6251 dbus_message_iter_close_container(&entry, &value);
6252 dbus_message_iter_close_container(dict, &entry);
6256 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
6258 DBusMessageIter dict;
6259 const char *type = "passive";
6260 struct interface_scan_data *data = user_data;
6262 supplicant_dbus_dict_open(iter, &dict);
6264 if (data && data->scan_params) {
6267 supplicant_dbus_dict_append_basic(&dict, "Type",
6268 DBUS_TYPE_STRING, &type);
6270 #if defined TIZEN_EXT
6271 SUPPLICANT_DBG("[specific_scan] num_ssids %d",
6272 data->scan_params->num_ssids);
6275 if (data->scan_params->ssids) {
6276 supplicant_dbus_dict_append_array(&dict, "SSIDs",
6281 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
6284 supplicant_dbus_dict_append_basic(&dict, "Type",
6285 DBUS_TYPE_STRING, &type);
6287 supplicant_dbus_dict_close(iter, &dict);
6290 static int interface_ready_to_scan(GSupplicantInterface *interface)
6295 if (!system_available)
6298 if (interface->scanning)
6301 switch (interface->state) {
6302 case G_SUPPLICANT_STATE_AUTHENTICATING:
6303 case G_SUPPLICANT_STATE_ASSOCIATING:
6304 case G_SUPPLICANT_STATE_ASSOCIATED:
6305 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
6306 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
6308 #if defined TIZEN_EXT
6309 case G_SUPPLICANT_STATE_DISABLED:
6311 case G_SUPPLICANT_STATE_UNKNOWN:
6313 case G_SUPPLICANT_STATE_UNKNOWN:
6314 case G_SUPPLICANT_STATE_DISABLED:
6316 case G_SUPPLICANT_STATE_DISCONNECTED:
6317 case G_SUPPLICANT_STATE_INACTIVE:
6318 case G_SUPPLICANT_STATE_SCANNING:
6319 case G_SUPPLICANT_STATE_COMPLETED:
6326 #if defined TIZEN_EXT_WIFI_MESH
6327 static void interface_abort_scan_result(const char *error,
6328 DBusMessageIter *iter, void *user_data)
6330 struct interface_scan_data *data = user_data;
6334 SUPPLICANT_DBG("error %s", error);
6341 data->callback(err, data->interface, data->user_data);
6346 int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
6347 GSupplicantInterfaceCallback callback, void *user_data)
6349 struct interface_scan_data *data;
6352 if (!interface->scanning)
6355 data = dbus_malloc0(sizeof(*data));
6359 data->interface = interface;
6360 data->path = g_strdup(interface->path);
6361 data->callback = callback;
6362 data->user_data = user_data;
6364 ret = supplicant_dbus_method_call(interface->path,
6365 SUPPLICANT_INTERFACE ".Interface", "AbortScan", NULL,
6366 interface_abort_scan_result, data, interface);
6377 int g_supplicant_interface_scan(GSupplicantInterface *interface,
6378 GSupplicantScanParams *scan_data,
6379 GSupplicantInterfaceCallback callback,
6382 struct interface_scan_data *data;
6385 ret = interface_ready_to_scan(interface);
6389 data = dbus_malloc0(sizeof(*data));
6393 data->interface = interface;
6394 data->path = g_strdup(interface->path);
6395 #if defined TIZEN_EXT
6396 data->interface->scan_callback = data->callback = callback;
6397 data->interface->scan_data = data->user_data = user_data;
6399 data->callback = callback;
6400 data->user_data = user_data;
6402 data->scan_params = scan_data;
6404 interface->scan_callback = callback;
6405 interface->scan_data = user_data;
6407 ret = supplicant_dbus_method_call(interface->path,
6408 SUPPLICANT_INTERFACE ".Interface", "Scan",
6409 interface_scan_params, interface_scan_result, data,
6420 #if defined TIZEN_EXT
6421 static void interface_signalpoll_result(const char *error,
6422 DBusMessageIter *iter, void *user_data)
6424 struct interface_signalpoll_data *data = user_data;
6426 dbus_int32_t maxspeed = 0;
6427 dbus_int32_t strength = 0;
6428 DBusMessageIter sub_iter, dict;
6432 SUPPLICANT_DBG("error: %s", error);
6436 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
6438 SUPPLICANT_DBG("invalid reply");
6442 dbus_message_iter_recurse(iter, &sub_iter);
6443 dbus_message_iter_recurse(&sub_iter, &dict);
6445 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
6446 DBusMessageIter entry, value;
6449 dbus_message_iter_recurse(&dict, &entry);
6450 dbus_message_iter_get_basic(&entry, &key);
6451 dbus_message_iter_next(&entry);
6452 dbus_message_iter_recurse(&entry, &value);
6454 switch (dbus_message_iter_get_arg_type(&value)) {
6455 case DBUS_TYPE_INT32:
6456 if (g_strcmp0(key, "linkspeed") == 0) {
6457 dbus_message_iter_get_basic(&value, &maxspeed);
6458 SUPPLICANT_DBG("linkspeed = %d", maxspeed);
6460 } else if (g_strcmp0(key, "rssi") == 0) {
6461 dbus_message_iter_get_basic(&value, &strength);
6462 SUPPLICANT_DBG("Strength = %d", strength);
6466 dbus_message_iter_next(&dict);
6471 data->callback(err, maxspeed, strength, data->user_data);
6477 int g_supplicant_interface_signalpoll(GSupplicantInterface *interface,
6478 GSupplicantMaxSpeedCallback callback,
6481 struct interface_signalpoll_data *data;
6487 if (!system_available)
6490 data = dbus_malloc0(sizeof(*data));
6494 data->interface = interface;
6495 data->path = g_strdup(interface->path);
6496 data->callback = callback;
6497 data->user_data = user_data;
6499 ret = supplicant_dbus_method_call(interface->path,
6500 SUPPLICANT_INTERFACE ".Interface", "SignalPoll",
6501 NULL, interface_signalpoll_result, data,
6513 static int parse_supplicant_error(DBusMessageIter *iter)
6515 int err = -ECONNABORTED;
6521 /* If the given passphrase is malformed wpa_s returns
6522 * "invalid message format" but this error should be interpreted as
6525 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
6526 dbus_message_iter_get_basic(iter, &key);
6527 if (strncmp(key, "psk", 3) == 0 ||
6528 strncmp(key, "wep_key", 7) == 0 ||
6529 strcmp(key, "invalid message format") == 0) {
6533 dbus_message_iter_next(iter);
6539 static void interface_select_network_result(const char *error,
6540 DBusMessageIter *iter, void *user_data)
6542 struct interface_connect_data *data = user_data;
6549 #if defined TIZEN_EXT
6550 SUPPLICANT_DBG("SelectNetwork errorFreq %s", error);
6552 SUPPLICANT_DBG("SelectNetwork error %s", error);
6554 err = parse_supplicant_error(iter);
6560 data->callback(err, data->interface, data->user_data);
6562 #if defined TIZEN_EXT
6563 g_free(data->ssid->ssid);
6564 g_free((char *)data->ssid->passphrase);
6565 g_free((char *)data->ssid->connector);
6566 g_free((char *)data->ssid->c_sign_key);
6567 g_free((char *)data->ssid->net_access_key);
6573 static void interface_select_network_params(DBusMessageIter *iter,
6576 struct interface_connect_data *data = user_data;
6577 GSupplicantInterface *interface = data->interface;
6578 #if defined TIZEN_EXT
6579 GSupplicantSSID *ssid = data->ssid;
6582 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6583 &interface->network_path);
6584 #if defined TIZEN_EXT
6585 if (!ssid->bssid_for_connect_len)
6586 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
6590 static void interface_add_network_result(const char *error,
6591 DBusMessageIter *iter, void *user_data)
6593 struct interface_connect_data *data = user_data;
6594 GSupplicantInterface *interface = data->interface;
6601 dbus_message_iter_get_basic(iter, &path);
6605 SUPPLICANT_DBG("PATH: %s", path);
6607 #if defined TIZEN_EXT
6608 if (interface->network_path)
6609 g_free(interface->network_path);
6611 interface->network_path = g_strdup(path);
6613 store_network_information(interface, data->ssid);
6615 #if defined TIZEN_EXT
6616 SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
6617 GSupplicantSSID *ssid = data->ssid;
6619 if (!ssid->bssid_for_connect_len)
6620 supplicant_dbus_method_call(data->interface->path,
6621 SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
6622 interface_select_network_params,
6623 interface_select_network_result, data,
6626 supplicant_dbus_method_call(data->interface->path,
6627 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6628 interface_select_network_params,
6629 interface_select_network_result, data,
6632 supplicant_dbus_method_call(data->interface->path,
6633 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6634 interface_select_network_params,
6635 interface_select_network_result, data,
6642 SUPPLICANT_DBG("AddNetwork error %s", error);
6644 if (interface_exists(data->interface, data->interface->path)) {
6645 err = parse_supplicant_error(iter);
6647 data->callback(err, data->interface, data->user_data);
6649 g_free(interface->network_path);
6650 interface->network_path = NULL;
6654 #if defined TIZEN_EXT
6655 g_free(data->ssid->ssid);
6656 g_free((char *)data->ssid->passphrase);
6657 g_free((char *)data->ssid->connector);
6658 g_free((char *)data->ssid->c_sign_key);
6659 g_free((char *)data->ssid->net_access_key);
6665 static void add_network_security_none(DBusMessageIter *dict)
6667 const char *auth_alg = "OPEN";
6669 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6670 DBUS_TYPE_STRING, &auth_alg);
6673 static void add_network_security_wep(DBusMessageIter *dict,
6674 GSupplicantSSID *ssid)
6676 const char *auth_alg = "OPEN SHARED";
6677 dbus_uint32_t key_index = 0;
6679 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6680 DBUS_TYPE_STRING, &auth_alg);
6682 if (ssid->passphrase) {
6683 int size = strlen(ssid->passphrase);
6684 if (size == 10 || size == 26) {
6685 unsigned char *key = g_try_malloc(13);
6689 memset(tmp, 0, sizeof(tmp));
6693 for (i = 0; i < size / 2; i++) {
6694 memcpy(tmp, ssid->passphrase + (i * 2), 2);
6695 key[i] = (unsigned char) strtol(tmp, NULL, 16);
6698 supplicant_dbus_dict_append_fixed_array(dict,
6703 } else if (size == 5 || size == 13) {
6704 unsigned char *key = g_try_malloc(13);
6710 for (i = 0; i < size; i++)
6711 key[i] = (unsigned char) ssid->passphrase[i];
6713 supplicant_dbus_dict_append_fixed_array(dict,
6719 supplicant_dbus_dict_append_basic(dict,
6724 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
6725 DBUS_TYPE_UINT32, &key_index);
6729 static dbus_bool_t is_psk_raw_key(const char *psk)
6733 /* A raw key is always 64 bytes length... */
6734 if (strlen(psk) != 64)
6737 /* ... and its content is in hex representation */
6738 for (i = 0; i < 64; i++)
6739 if (!isxdigit((unsigned char) psk[i]))
6745 static unsigned char hexchar2bin(char c)
6747 if ((c >= '0') && (c <= '9'))
6749 else if ((c >= 'A') && (c <= 'F'))
6750 return c - 'A' + 10;
6751 else if ((c >= 'a') && (c <= 'f'))
6752 return c - 'a' + 10;
6757 static void hexstring2bin(const char *string, unsigned char *data,
6762 for (i = 0; i < data_len; i++)
6763 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
6764 hexchar2bin(string[i * 2 + 1]) << 0);
6767 static void add_network_security_psk(DBusMessageIter *dict,
6768 GSupplicantSSID *ssid)
6770 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
6771 const char *key = "psk";
6773 if (is_psk_raw_key(ssid->passphrase)) {
6774 unsigned char data[32];
6775 unsigned char *datap = data;
6777 /* The above pointer alias is required by D-Bus because
6778 * with D-Bus and GCC, non-heap-allocated arrays cannot
6779 * be passed directly by their base pointer. */
6781 hexstring2bin(ssid->passphrase, datap, sizeof(data));
6783 supplicant_dbus_dict_append_fixed_array(dict,
6784 key, DBUS_TYPE_BYTE,
6785 &datap, sizeof(data));
6787 supplicant_dbus_dict_append_basic(dict,
6788 key, DBUS_TYPE_STRING,
6793 static void add_network_security_tls(DBusMessageIter *dict,
6794 GSupplicantSSID *ssid)
6797 * For TLS, we at least need:
6798 * The client certificate
6799 * The client private key file
6800 * The client private key file password
6802 * The Authority certificate is optional.
6804 if (!ssid->client_cert_path)
6807 if (!ssid->private_key_path)
6810 #if !defined TIZEN_EXT
6811 if (!ssid->private_key_passphrase)
6815 if (ssid->ca_cert_path)
6816 supplicant_dbus_dict_append_basic(dict, "ca_cert",
6817 DBUS_TYPE_STRING, &ssid->ca_cert_path);
6819 supplicant_dbus_dict_append_basic(dict, "private_key",
6821 &ssid->private_key_path);
6822 #if !defined TIZEN_EXT
6823 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
6825 &ssid->private_key_passphrase);
6827 supplicant_dbus_dict_append_basic(dict, "client_cert",
6829 &ssid->client_cert_path);
6832 static void add_network_security_peap(DBusMessageIter *dict,
6833 GSupplicantSSID *ssid)
6838 * For PEAP/TTLS, we at least need
6839 * The authority certificate
6840 * The 2nd phase authentication method
6841 * The 2nd phase passphrase
6843 * The Client certificate is optional although strongly recommended
6844 * When setting it, we need in addition
6845 * The Client private key file
6846 * The Client private key file password
6848 if (!ssid->passphrase)
6851 if (!ssid->phase2_auth)
6854 if (ssid->client_cert_path) {
6855 if (!ssid->private_key_path)
6858 #if !defined TIZEN_EXT
6859 if (!ssid->private_key_passphrase)
6863 supplicant_dbus_dict_append_basic(dict, "client_cert",
6865 &ssid->client_cert_path);
6867 supplicant_dbus_dict_append_basic(dict, "private_key",
6869 &ssid->private_key_path);
6871 #if !defined TIZEN_EXT
6872 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
6874 &ssid->private_key_passphrase);
6879 if(g_strcmp0(ssid->phase2_auth, "GTC") == 0 && g_strcmp0(ssid->eap, "ttls") == 0)
6880 phase2_auth = g_strdup_printf("autheap=%s", ssid->phase2_auth);
6881 else if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
6882 phase2_auth = g_strdup_printf("autheap=%s",
6883 ssid->phase2_auth + strlen("EAP-"));
6885 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
6887 supplicant_dbus_dict_append_basic(dict, "password",
6891 if (ssid->ca_cert_path)
6892 supplicant_dbus_dict_append_basic(dict, "ca_cert",
6894 &ssid->ca_cert_path);
6896 supplicant_dbus_dict_append_basic(dict, "phase2",
6900 g_free(phase2_auth);
6903 #if defined TIZEN_EXT
6904 static void add_network_security_aka_sim(DBusMessageIter *dict,
6905 GSupplicantSSID *ssid)
6907 if (!ssid->passphrase)
6910 supplicant_dbus_dict_append_basic(dict, "password",
6915 static void add_network_security_fast(DBusMessageIter *dict,
6916 GSupplicantSSID *ssid)
6919 * For FAST, we at least need:
6921 * phase1 (provisiong information)
6925 /* Allow provisioing both authenticated and unauthenticated */
6926 const char *phase1 = "fast_provisioning=2";
6927 supplicant_dbus_dict_append_basic(dict, "phase1",
6931 SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
6933 supplicant_dbus_dict_append_basic(dict, "pac_file",
6937 supplicant_dbus_dict_append_basic(dict, "password",
6943 static void add_network_security_eap(DBusMessageIter *dict,
6944 GSupplicantSSID *ssid)
6948 #if defined TIZEN_EXT
6951 if (!ssid->eap || !ssid->identity)
6955 if (g_strcmp0(ssid->eap, "tls") == 0) {
6956 add_network_security_tls(dict, ssid);
6957 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
6958 g_strcmp0(ssid->eap, "ttls") == 0) {
6959 #if defined TIZEN_EXT
6960 if (!ssid->identity)
6963 add_network_security_peap(dict, ssid);
6965 #if defined TIZEN_EXT
6966 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
6967 g_strcmp0(ssid->eap, "aka") == 0 ||
6968 g_strcmp0(ssid->eap, "aka'") == 0) {
6969 add_network_security_aka_sim(dict, ssid);
6970 } else if (g_strcmp0(ssid->eap, "pwd") == 0) {
6971 if(!ssid->passphrase)
6973 supplicant_dbus_dict_append_basic(dict, "password",
6976 } else if (g_strcmp0(ssid->eap, "fast") == 0){
6977 if (!ssid->identity || !ssid->passphrase)
6980 add_network_security_fast(dict, ssid);
6985 eap_value = g_ascii_strup(ssid->eap, -1);
6987 supplicant_dbus_dict_append_basic(dict, "eap",
6990 #if defined TIZEN_EXT
6991 if (ssid->identity != NULL)
6992 supplicant_dbus_dict_append_basic(dict, "identity",
6996 supplicant_dbus_dict_append_basic(dict, "identity",
7000 if(ssid->anonymous_identity)
7001 supplicant_dbus_dict_append_basic(dict, "anonymous_identity",
7003 &ssid->anonymous_identity);
7005 if(ssid->subject_match)
7006 supplicant_dbus_dict_append_basic(dict, "subject_match",
7008 &ssid->subject_match);
7010 if(ssid->altsubject_match)
7011 supplicant_dbus_dict_append_basic(dict, "altsubject_match",
7013 &ssid->altsubject_match);
7015 if(ssid->domain_suffix_match)
7016 supplicant_dbus_dict_append_basic(dict, "domain_suffix_match",
7018 &ssid->domain_suffix_match);
7020 if(ssid->domain_match)
7021 supplicant_dbus_dict_append_basic(dict, "domain_match",
7023 &ssid->domain_match);
7028 static void add_network_security_ciphers(DBusMessageIter *dict,
7029 GSupplicantSSID *ssid)
7031 unsigned int p_cipher, g_cipher, i;
7032 char *pairwise, *group;
7033 char *pair_ciphers[4];
7034 char *group_ciphers[5];
7036 p_cipher = ssid->pairwise_cipher;
7037 g_cipher = ssid->group_cipher;
7039 if (p_cipher == 0 && g_cipher == 0)
7044 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
7045 pair_ciphers[i++] = "CCMP";
7047 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
7048 pair_ciphers[i++] = "TKIP";
7050 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
7051 pair_ciphers[i++] = "NONE";
7053 pair_ciphers[i] = NULL;
7057 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
7058 group_ciphers[i++] = "CCMP";
7060 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
7061 group_ciphers[i++] = "TKIP";
7063 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
7064 group_ciphers[i++] = "WEP104";
7066 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
7067 group_ciphers[i++] = "WEP40";
7069 group_ciphers[i] = NULL;
7071 pairwise = g_strjoinv(" ", pair_ciphers);
7072 group = g_strjoinv(" ", group_ciphers);
7074 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
7076 supplicant_dbus_dict_append_basic(dict, "pairwise",
7079 supplicant_dbus_dict_append_basic(dict, "group",
7087 static void add_network_security_proto(DBusMessageIter *dict,
7088 GSupplicantSSID *ssid)
7090 unsigned int protocol, i;
7094 protocol = ssid->protocol;
7101 if (protocol & G_SUPPLICANT_PROTO_RSN)
7102 protos[i++] = "RSN";
7104 if (protocol & G_SUPPLICANT_PROTO_WPA)
7105 protos[i++] = "WPA";
7109 proto = g_strjoinv(" ", protos);
7111 SUPPLICANT_DBG("proto %s", proto);
7113 supplicant_dbus_dict_append_basic(dict, "proto",
7120 #if defined TIZEN_EXT
7121 static void add_network_ieee80211w(DBusMessageIter *dict, GSupplicantSSID *ssid)
7123 if (ssid->security != G_SUPPLICANT_SECURITY_SAE
7124 && ssid->security != G_SUPPLICANT_SECURITY_OWE
7125 && ssid->security != G_SUPPLICANT_SECURITY_DPP)
7128 supplicant_dbus_dict_append_basic(dict, "ieee80211w", DBUS_TYPE_UINT32,
7132 static void add_network_security_connector(DBusMessageIter *dict, GSupplicantSSID *ssid)
7134 if (ssid->connector && strlen(ssid->connector) > 0) {
7135 const char *key = "dpp_connector";
7137 supplicant_dbus_dict_append_basic(dict,
7138 key, DBUS_TYPE_STRING,
7143 static size_t convert_hexstr_to_bin(const char *hex_str, unsigned char **bin)
7145 unsigned char *bin_res = NULL;
7146 unsigned int i, j, hex;
7149 if (!hex_str || strlen(hex_str) == 0)
7152 hex_str_len = strlen(hex_str);
7153 bin_res = g_try_malloc0(hex_str_len / 2);
7158 for (i = 0; i < hex_str_len; i+=2) {
7159 sscanf(hex_str + i, "%02x", &hex);
7164 return hex_str_len / 2;
7167 static void add_network_security_c_sign_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7169 if (ssid->c_sign_key && strlen(ssid->c_sign_key) > 0) {
7170 const char *key = "dpp_csign";
7171 unsigned char *bin_csign = NULL;
7172 size_t bin_csign_len = convert_hexstr_to_bin(ssid->c_sign_key, &bin_csign);
7173 if (bin_csign_len != 0)
7174 supplicant_dbus_dict_append_fixed_array(dict,
7175 key, DBUS_TYPE_BYTE,
7176 &bin_csign, bin_csign_len);
7181 static void add_network_security_net_access_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7183 if (ssid->net_access_key && strlen(ssid->net_access_key) > 0) {
7184 const char *key = "dpp_netaccesskey";
7185 unsigned char *bin_netaccesskey = NULL;
7186 size_t bin_netaccesskey_len = convert_hexstr_to_bin(ssid->net_access_key, &bin_netaccesskey);
7187 if (bin_netaccesskey_len != 0)
7188 supplicant_dbus_dict_append_fixed_array(dict,
7189 key, DBUS_TYPE_BYTE,
7190 &bin_netaccesskey, bin_netaccesskey_len);
7191 g_free(bin_netaccesskey);
7197 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
7201 switch (ssid->security) {
7202 case G_SUPPLICANT_SECURITY_NONE:
7204 add_network_security_none(dict);
7205 add_network_security_ciphers(dict, ssid);
7207 case G_SUPPLICANT_SECURITY_UNKNOWN:
7208 case G_SUPPLICANT_SECURITY_WEP:
7210 add_network_security_wep(dict, ssid);
7211 add_network_security_ciphers(dict, ssid);
7213 case G_SUPPLICANT_SECURITY_PSK:
7214 key_mgmt = "WPA-PSK";
7215 add_network_security_psk(dict, ssid);
7216 add_network_security_ciphers(dict, ssid);
7217 add_network_security_proto(dict, ssid);
7219 case G_SUPPLICANT_SECURITY_IEEE8021X:
7220 key_mgmt = "WPA-EAP";
7221 add_network_security_eap(dict, ssid);
7222 add_network_security_ciphers(dict, ssid);
7223 add_network_security_proto(dict, ssid);
7225 #if defined TIZEN_EXT
7226 case G_SUPPLICANT_SECURITY_FT_PSK:
7227 key_mgmt = "FT-PSK";
7228 add_network_security_psk(dict, ssid);
7229 add_network_security_ciphers(dict, ssid);
7230 add_network_security_proto(dict, ssid);
7232 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
7233 key_mgmt = "FT-EAP";
7234 add_network_security_eap(dict, ssid);
7235 add_network_security_ciphers(dict, ssid);
7236 add_network_security_proto(dict, ssid);
7238 case G_SUPPLICANT_SECURITY_SAE:
7239 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK)
7240 key_mgmt = "SAE WPA-PSK"; // WFA (WPA3 & WPA2 Mixed -> WPA2 only)
7243 add_network_security_psk(dict, ssid);
7245 case G_SUPPLICANT_SECURITY_OWE:
7247 add_network_security_ciphers(dict, ssid);
7248 add_network_security_proto(dict, ssid);
7250 case G_SUPPLICANT_SECURITY_DPP:
7252 add_network_security_connector(dict, ssid);
7253 add_network_security_c_sign_key(dict, ssid);
7254 add_network_security_net_access_key(dict, ssid);
7259 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
7260 DBUS_TYPE_STRING, &key_mgmt);
7263 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
7267 switch (ssid->mode) {
7268 case G_SUPPLICANT_MODE_UNKNOWN:
7269 case G_SUPPLICANT_MODE_INFRA:
7272 case G_SUPPLICANT_MODE_IBSS:
7275 case G_SUPPLICANT_MODE_MASTER:
7278 #if defined TIZEN_EXT_WIFI_MESH
7279 case G_SUPPLICANT_MODE_MESH:
7285 supplicant_dbus_dict_append_basic(dict, "mode",
7286 DBUS_TYPE_UINT32, &mode);
7289 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
7291 DBusMessageIter dict;
7292 struct interface_connect_data *data = user_data;
7293 GSupplicantSSID *ssid = data->ssid;
7294 #if defined TIZEN_EXT
7295 GSupplicantInterface *interface = data->interface;
7298 supplicant_dbus_dict_open(iter, &dict);
7300 if (ssid->scan_ssid)
7301 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
7302 DBUS_TYPE_UINT32, &ssid->scan_ssid);
7305 supplicant_dbus_dict_append_basic(&dict, "frequency",
7306 DBUS_TYPE_UINT32, &ssid->freq);
7309 supplicant_dbus_dict_append_basic(&dict, "bgscan",
7310 DBUS_TYPE_STRING, &ssid->bgscan);
7312 add_network_mode(&dict, ssid);
7314 add_network_security(&dict, ssid);
7316 #if defined TIZEN_EXT
7317 add_network_ieee80211w(&dict, ssid);
7320 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
7321 DBUS_TYPE_BYTE, &ssid->ssid,
7324 #if defined TIZEN_EXT
7325 bool owe_transition_mode = FALSE;
7326 if ((ssid->security == G_SUPPLICANT_SECURITY_OWE) && !(ssid->keymgmt & G_SUPPLICANT_KEYMGMT_OWE))
7327 owe_transition_mode = TRUE;
7329 if (ssid->bssid && !owe_transition_mode) {
7331 bssid = g_try_malloc0(18);
7332 if (bssid == NULL) {
7333 SUPPLICANT_DBG("memory allocation error");
7334 supplicant_dbus_dict_close(iter, &dict);
7338 if (ssid->bssid_for_connect_len) {
7339 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid_for_connect));
7340 memcpy(interface->add_network_bssid, ssid->bssid_for_connect, WIFI_BSSID_LEN_MAX);
7342 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid));
7343 memcpy(interface->add_network_bssid, ssid->bssid, WIFI_BSSID_LEN_MAX);
7346 SUPPLICANT_DBG("bssid [" MACSTR "]", MAC2STR(interface->add_network_bssid));
7348 supplicant_dbus_dict_append_basic(&dict, "bssid",
7349 DBUS_TYPE_STRING, &bssid);
7354 supplicant_dbus_dict_close(iter, &dict);
7357 static void interface_wps_start_result(const char *error,
7358 DBusMessageIter *iter, void *user_data)
7360 struct interface_connect_data *data = user_data;
7367 SUPPLICANT_DBG("error: %s", error);
7368 err = parse_supplicant_error(iter);
7372 data->callback(err, data->interface, data->user_data);
7379 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
7381 struct interface_connect_data *data = user_data;
7382 GSupplicantSSID *ssid = data->ssid;
7383 const char *role = "enrollee", *type;
7384 DBusMessageIter dict;
7388 supplicant_dbus_dict_open(iter, &dict);
7390 supplicant_dbus_dict_append_basic(&dict, "Role",
7391 DBUS_TYPE_STRING, &role);
7394 if (ssid->pin_wps) {
7396 supplicant_dbus_dict_append_basic(&dict, "Pin",
7397 DBUS_TYPE_STRING, &ssid->pin_wps);
7400 supplicant_dbus_dict_append_basic(&dict, "Type",
7401 DBUS_TYPE_STRING, &type);
7403 #if defined TIZEN_EXT
7405 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
7406 DBUS_TYPE_BYTE, &ssid->bssid, 6);
7409 supplicant_dbus_dict_close(iter, &dict);
7412 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
7414 struct interface_connect_data *data = user_data;
7419 SUPPLICANT_DBG("error: %s", error);
7426 #if defined TIZEN_EXT
7427 GSupplicantSSID *ssid = data->ssid;
7428 if (ssid->pin_wps != NULL) {
7429 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
7430 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
7437 supplicant_dbus_method_call(data->interface->path,
7438 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
7439 interface_add_wps_params,
7440 interface_wps_start_result, data, NULL);
7443 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
7445 dbus_bool_t credentials = TRUE;
7449 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
7453 #if defined TIZEN_EXT
7454 #define NETCONFIG_SERVICE "net.netconfig"
7455 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
7456 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
7458 struct dec_method_call_data {
7459 struct interface_connect_data *data;
7460 DBusPendingCall *pending_call;
7463 static struct dec_method_call_data decrypt_request_data;
7465 static void crypt_method_call_cancel(void)
7467 if (decrypt_request_data.pending_call) {
7468 dbus_pending_call_cancel(decrypt_request_data.pending_call);
7469 dbus_pending_call_unref(decrypt_request_data.pending_call);
7470 decrypt_request_data.pending_call = NULL;
7473 g_free(decrypt_request_data.data->path);
7474 g_free(decrypt_request_data.data->ssid);
7475 dbus_free(decrypt_request_data.data);
7476 decrypt_request_data.data = NULL;
7479 static void decryption_request_reply(DBusPendingCall *call,
7484 DBusMessageIter args;
7487 struct interface_connect_data *data = user_data;
7491 reply = dbus_pending_call_steal_reply(call);
7493 dbus_error_init(&error);
7494 if (dbus_set_error_from_message(&error, reply)) {
7495 SUPPLICANT_DBG("decryption_request_reply() %s %s", error.name, error.message);
7496 dbus_error_free(&error);
7501 if (dbus_message_iter_init(reply, &args) == FALSE) {
7502 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7507 dbus_message_iter_get_basic(&args, &out_data);
7508 data->ssid->passphrase = g_strdup((const gchar *)out_data);
7510 ret = supplicant_dbus_method_call(data->interface->path,
7511 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7512 interface_add_network_params,
7513 interface_add_network_result, data,
7518 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7519 callback_assoc_failed(decrypt_request_data.data->user_data);
7521 g_free(data->ssid->ssid);
7522 g_free((char *)data->ssid->passphrase);
7523 g_free((char *)data->ssid->connector);
7524 g_free((char *)data->ssid->c_sign_key);
7525 g_free((char *)data->ssid->net_access_key);
7530 dbus_message_unref(reply);
7531 dbus_pending_call_unref(call);
7533 decrypt_request_data.pending_call = NULL;
7534 decrypt_request_data.data = NULL;
7537 static int send_decryption_request(const char *passphrase,
7538 struct interface_connect_data *data)
7540 DBusMessage *msg = NULL;
7541 DBusPendingCall *call;
7543 SUPPLICANT_DBG("Decryption request");
7546 SUPPLICANT_DBG("Invalid parameter");
7553 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7554 NETCONFIG_WIFI_INTERFACE, "DecryptPassphrase");
7558 #if defined TIZEN_EXT
7559 if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7560 DBUS_TYPE_INVALID)) {
7561 SUPPLICANT_DBG("Could not fulfill decryption request");
7565 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7569 if (!dbus_connection_send_with_reply(connection, msg,
7570 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7571 dbus_message_unref(msg);
7576 dbus_message_unref(msg);
7580 decrypt_request_data.pending_call = call;
7581 decrypt_request_data.data = data;
7583 dbus_pending_call_set_notify(call, decryption_request_reply, data, NULL);
7584 dbus_message_unref(msg);
7586 SUPPLICANT_DBG("Decryption request succeeded");
7591 static void decrypt_conf_obj_reply(DBusPendingCall *call,
7596 DBusMessageIter iter, dict;
7599 struct interface_connect_data *data = user_data;
7601 reply = dbus_pending_call_steal_reply(call);
7603 dbus_error_init(&error);
7604 if (dbus_set_error_from_message(&error, reply)) {
7605 SUPPLICANT_DBG("decryption_conf_obj_reply() %s %s", error.name, error.message);
7606 dbus_error_free(&error);
7611 if (dbus_message_iter_init(reply, &iter) == FALSE) {
7612 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7617 dbus_message_iter_recurse(&iter, &dict);
7619 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
7620 DBusMessageIter entry, value;
7623 dbus_message_iter_recurse(&dict, &entry);
7624 dbus_message_iter_get_basic(&entry, &key);
7625 dbus_message_iter_next(&entry);
7626 dbus_message_iter_recurse(&entry, &value);
7627 if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
7628 if (g_strcmp0(key, "connector") == 0) {
7629 dbus_message_iter_get_basic(&value, &out_data);
7630 data->ssid->connector = g_strdup((const gchar *)out_data);
7631 SUPPLICANT_DBG("connector %s", data->ssid->connector);
7632 } else if (g_strcmp0(key, "c_sign_key") == 0) {
7633 dbus_message_iter_get_basic(&value, &out_data);
7634 data->ssid->c_sign_key = g_strdup((const gchar *)out_data);
7635 SUPPLICANT_DBG("c_sign_key %s", data->ssid->c_sign_key);
7636 } else if (g_strcmp0(key, "net_access_key") == 0) {
7637 dbus_message_iter_get_basic(&value, &out_data);
7638 data->ssid->net_access_key = g_strdup((const gchar *)out_data);
7639 SUPPLICANT_DBG("net_access_key %s", data->ssid->net_access_key);
7642 dbus_message_iter_next(&dict);
7645 ret = supplicant_dbus_method_call(data->interface->path,
7646 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7647 interface_add_network_params,
7648 interface_add_network_result, data,
7653 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7654 callback_assoc_failed(decrypt_request_data.data->user_data);
7656 g_free(data->ssid->ssid);
7657 g_free((char *)data->ssid->connector);
7658 g_free((char *)data->ssid->c_sign_key);
7659 g_free((char *)data->ssid->net_access_key);
7664 dbus_message_unref(reply);
7665 dbus_pending_call_unref(call);
7667 decrypt_request_data.pending_call = NULL;
7668 decrypt_request_data.data = NULL;
7671 static int send_decryption_conf_obj_request(GSupplicantSSID *ssid,
7672 struct interface_connect_data *data)
7674 DBusMessage *msg = NULL;
7675 DBusPendingCall *call;
7677 SUPPLICANT_DBG("Decryption configuration object request");
7680 SUPPLICANT_DBG("Invalid parameter");
7687 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7688 NETCONFIG_WIFI_INTERFACE, "DecryptConfObj");
7692 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->connector,
7694 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->c_sign_key,
7696 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->net_access_key,
7699 if (!dbus_connection_send_with_reply(connection, msg,
7700 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7701 dbus_message_unref(msg);
7706 dbus_message_unref(msg);
7710 decrypt_request_data.pending_call = call;
7711 decrypt_request_data.data = data;
7713 dbus_pending_call_set_notify(call, decrypt_conf_obj_reply, data, NULL);
7714 dbus_message_unref(msg);
7716 SUPPLICANT_DBG("Decrypt Conf Obj request succeeded");
7721 static bool is_valid_config_object(GSupplicantSSID *ssid)
7723 return ((ssid->connector &&
7724 g_strcmp0(ssid->connector, "") != 0) &&
7725 (ssid->c_sign_key &&
7726 g_strcmp0(ssid->c_sign_key, "") != 0) &&
7727 (ssid->net_access_key &&
7728 g_strcmp0(ssid->net_access_key, "") != 0));
7732 int g_supplicant_interface_connect(GSupplicantInterface *interface,
7733 GSupplicantSSID *ssid,
7734 GSupplicantInterfaceCallback callback,
7737 struct interface_connect_data *data;
7738 struct interface_data *intf_data;
7746 if (!system_available)
7749 /* TODO: Check if we're already connected and switch */
7751 data = dbus_malloc0(sizeof(*data));
7755 data->interface = interface;
7756 data->path = g_strdup(interface->path);
7757 data->callback = callback;
7759 data->user_data = user_data;
7761 if (ssid->use_wps) {
7762 g_free(interface->wps_cred.key);
7763 memset(&interface->wps_cred, 0,
7764 sizeof(struct _GSupplicantWpsCredentials));
7766 ret = supplicant_dbus_property_set(interface->path,
7767 SUPPLICANT_INTERFACE ".Interface.WPS",
7768 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
7769 wps_process_credentials, wps_start, data, interface);
7771 /* By the time there is a request for connect and the network
7772 * path is not NULL it means that connman has not removed the
7773 * previous network pointer. This can happen in the case AP
7774 * deauthenticated client and connman does not remove the
7775 * previously connected network pointer. This causes supplicant
7776 * to reallocate the memory for struct wpa_ssid again even if it
7777 * is the same SSID. This causes memory usage of wpa_supplicnat
7778 * to go high. The idea here is that if the previously connected
7779 * network is not removed at the time of next connection attempt
7780 * check if the network path is not NULL. In case it is non-NULL
7781 * first remove the network and then once removal is successful, add
7785 if (interface->network_path != NULL) {
7790 * If this add network is for the same network for
7791 * which wpa_supplicant already has a profile then do
7792 * not need to add another profile. Only if the
7793 * profile that needs to get added is different from
7794 * what is there in wpa_s delete the current one. A
7795 * network is identified by its SSID, security_type
7796 * and passphrase (private passphrase in case security
7799 if (compare_network_parameters(interface, ssid)) {
7803 intf_data = dbus_malloc0(sizeof(*intf_data));
7807 intf_data->interface = interface;
7808 intf_data->path = g_strdup(interface->path);
7809 intf_data->callback = callback;
7810 intf_data->ssid = ssid;
7811 intf_data->user_data = user_data;
7812 intf_data->network_remove_in_progress = TRUE;
7813 network_remove(intf_data);
7815 #if defined TIZEN_EXT
7816 if (ssid->passphrase &&
7817 g_strcmp0(ssid->passphrase, "") != 0 &&
7818 #if defined TIZEN_EXT_WIFI_MESH
7819 ssid->mode != G_SUPPLICANT_MODE_MESH &&
7822 ret = send_decryption_request(ssid->passphrase, data);
7824 SUPPLICANT_DBG("Decryption request failed %d", ret);
7825 } else if (is_valid_config_object(ssid)) {
7826 ret = send_decryption_conf_obj_request(ssid, data);
7828 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
7832 ret = supplicant_dbus_method_call(interface->path,
7833 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7834 interface_add_network_params,
7835 interface_add_network_result, data,
7846 return -EINPROGRESS;
7849 static void network_remove_result(const char *error,
7850 DBusMessageIter *iter, void *user_data)
7852 struct interface_data *data = user_data;
7853 struct interface_connect_data *connect_data;
7860 SUPPLICANT_DBG("error: %s", error);
7862 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
7864 result = -ECONNABORTED;
7867 g_free(data->interface->network_path);
7868 data->interface->network_path = NULL;
7870 remove_network_information(data->interface);
7872 if (data->network_remove_in_progress == TRUE) {
7873 data->network_remove_in_progress = FALSE;
7874 connect_data = dbus_malloc0(sizeof(*connect_data));
7878 connect_data->interface = data->interface;
7879 connect_data->path = g_strdup(data->path);
7880 connect_data->callback = data->callback;
7881 connect_data->ssid = data->ssid;
7882 connect_data->user_data = data->user_data;
7884 #if defined TIZEN_EXT
7886 if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
7887 && !data->ssid->eap) {
7888 ret = send_decryption_request(data->ssid->passphrase, connect_data);
7890 SUPPLICANT_DBG("Decryption request failed %d", ret);
7891 g_free(connect_data->ssid);
7892 g_free(connect_data->path);
7893 dbus_free(connect_data);
7895 } else if (is_valid_config_object(data->ssid)) {
7896 ret = send_decryption_conf_obj_request(data->ssid, connect_data);
7898 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
7899 g_free(connect_data->ssid);
7900 g_free(connect_data->path);
7901 dbus_free(connect_data);
7905 supplicant_dbus_method_call(data->interface->path,
7906 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7907 interface_add_network_params,
7908 interface_add_network_result, connect_data,
7909 connect_data->interface);
7912 data->callback(result, data->interface, data->user_data);
7918 static void network_remove_params(DBusMessageIter *iter, void *user_data)
7920 struct interface_data *data = user_data;
7921 const char *path = data->interface->network_path;
7923 SUPPLICANT_DBG("path %s", path);
7925 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
7928 static int network_remove(struct interface_data *data)
7930 GSupplicantInterface *interface = data->interface;
7934 #if defined TIZEN_EXT
7935 GSupplicantInterface *intf = NULL;
7937 * Check if 'interface' is valid
7939 intf = g_hash_table_lookup(interface_table, interface->path);
7944 return supplicant_dbus_method_call(interface->path,
7945 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
7946 network_remove_params, network_remove_result, data,
7950 static void interface_disconnect_result(const char *error,
7951 DBusMessageIter *iter, void *user_data)
7953 struct interface_data *data = user_data;
7960 SUPPLICANT_DBG("error: %s", error);
7962 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
7964 result = -ECONNABORTED;
7967 /* If we are disconnecting from previous WPS successful
7968 * association. i.e.: it did not went through AddNetwork,
7969 * and interface->network_path was never set. */
7970 if (!data->interface->network_path) {
7972 data->callback(result, data->interface,
7980 if (result < 0 && data->callback) {
7981 data->callback(result, data->interface, data->user_data);
7982 data->callback = NULL;
7985 if (result != -ECONNABORTED) {
7986 if (network_remove(data) < 0) {
7996 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
7997 GSupplicantInterfaceCallback callback,
8000 struct interface_data *data;
8008 if (!system_available)
8010 #if defined TIZEN_EXT
8011 if (decrypt_request_data.pending_call &&
8012 decrypt_request_data.data &&
8013 decrypt_request_data.data->user_data == user_data) {
8015 callback_assoc_failed(decrypt_request_data.data->user_data);
8016 crypt_method_call_cancel();
8021 data = dbus_malloc0(sizeof(*data));
8025 data->interface = interface;
8026 data->path = g_strdup(interface->path);
8027 data->callback = callback;
8028 data->user_data = user_data;
8030 ret = supplicant_dbus_method_call(interface->path,
8031 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
8032 NULL, interface_disconnect_result, data,
8043 static void interface_p2p_find_result(const char *error,
8044 DBusMessageIter *iter, void *user_data)
8046 struct interface_scan_data *data = user_data;
8049 SUPPLICANT_DBG("error %s", error);
8054 if (interface_exists(data->interface, data->path)) {
8055 if (!data->interface->ready)
8058 data->interface->p2p_finding = true;
8062 data->callback(err, data->interface, data->user_data);
8068 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
8070 DBusMessageIter dict;
8072 supplicant_dbus_dict_open(iter, &dict);
8073 supplicant_dbus_dict_close(iter, &dict);
8076 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
8077 GSupplicantInterfaceCallback callback,
8080 struct interface_scan_data *data;
8083 if (!interface->p2p_support)
8086 ret = interface_ready_to_scan(interface);
8087 if (ret && ret != -EALREADY)
8090 data = dbus_malloc0(sizeof(*data));
8094 data->interface = interface;
8095 data->path = g_strdup(interface->path);
8096 data->callback = callback;
8097 data->user_data = user_data;
8099 ret = supplicant_dbus_method_call(interface->path,
8100 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
8101 interface_p2p_find_params, interface_p2p_find_result,
8111 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
8116 return interface->p2p_finding;
8119 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
8121 if (!interface->p2p_finding)
8126 interface->p2p_finding = false;
8128 return supplicant_dbus_method_call(interface->path,
8129 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
8130 NULL, NULL, NULL, NULL);
8133 static void interface_p2p_connect_result(const char *error,
8134 DBusMessageIter *iter, void *user_data)
8136 struct interface_connect_data *data = user_data;
8142 SUPPLICANT_DBG("error: %s", error);
8143 err = parse_supplicant_error(iter);
8147 data->callback(err, data->interface, data->user_data);
8150 g_free(data->peer->wps_pin);
8151 g_free(data->peer->path);
8156 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
8158 struct interface_connect_data *data = user_data;
8159 const char *wps = "pbc";
8160 DBusMessageIter dict;
8165 supplicant_dbus_dict_open(iter, &dict);
8167 if (data->peer->master)
8170 if (data->peer->wps_pin)
8173 supplicant_dbus_dict_append_basic(&dict, "peer",
8174 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
8175 supplicant_dbus_dict_append_basic(&dict, "wps_method",
8176 DBUS_TYPE_STRING, &wps);
8177 if (data->peer->wps_pin) {
8178 supplicant_dbus_dict_append_basic(&dict, "pin",
8179 DBUS_TYPE_STRING, &data->peer->wps_pin);
8182 supplicant_dbus_dict_append_basic(&dict, "go_intent",
8183 DBUS_TYPE_INT32, &go_intent);
8185 supplicant_dbus_dict_close(iter, &dict);
8188 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
8189 GSupplicantPeerParams *peer_params,
8190 GSupplicantInterfaceCallback callback,
8193 struct interface_connect_data *data;
8198 if (!interface->p2p_support)
8201 data = dbus_malloc0(sizeof(*data));
8205 data->interface = interface;
8206 data->path = g_strdup(interface->path);
8207 data->peer = peer_params;
8208 data->callback = callback;
8209 data->user_data = user_data;
8211 ret = supplicant_dbus_method_call(interface->path,
8212 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
8213 interface_p2p_connect_params, interface_p2p_connect_result,
8221 return -EINPROGRESS;
8224 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
8225 GSupplicantPeerParams *peer_params)
8227 GSupplicantPeer *peer;
8233 if (!interface->p2p_support)
8236 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
8240 for (list = peer->groups; list; list = list->next, count++) {
8241 const char *group_obj_path = list->data;
8242 GSupplicantInterface *g_interface;
8243 GSupplicantGroup *group;
8245 group = g_hash_table_lookup(group_mapping, group_obj_path);
8246 if (!group || !group->interface)
8249 g_interface = group->interface;
8250 supplicant_dbus_method_call(g_interface->path,
8251 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8252 "Disconnect", NULL, NULL, NULL, g_interface);
8255 if (count == 0 && peer->current_group_iface) {
8256 supplicant_dbus_method_call(peer->current_group_iface->path,
8257 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8258 "Disconnect", NULL, NULL, NULL,
8259 peer->current_group_iface->path);
8262 peer->current_group_iface = NULL;
8264 return -EINPROGRESS;
8267 struct p2p_service_data {
8269 GSupplicantInterface *interface;
8270 GSupplicantP2PServiceParams *service;
8271 GSupplicantInterfaceCallback callback;
8275 static void interface_p2p_service_result(const char *error,
8276 DBusMessageIter *iter, void *user_data)
8278 struct p2p_service_data *data = user_data;
8281 SUPPLICANT_DBG("%s result - %s", data->registration ?
8282 "Registration" : "Deletion",
8283 error ? error : "Success");
8288 data->callback(result, data->interface, data->user_data);
8290 g_free(data->service->query);
8291 g_free(data->service->response);
8292 g_free(data->service->service);
8293 g_free(data->service->wfd_ies);
8294 g_free(data->service);
8298 static void interface_p2p_service_params(DBusMessageIter *iter,
8301 struct p2p_service_data *data = user_data;
8302 GSupplicantP2PServiceParams *service;
8303 DBusMessageIter dict;
8308 service = data->service;
8310 supplicant_dbus_dict_open(iter, &dict);
8312 if (service->query && service->response) {
8314 supplicant_dbus_dict_append_basic(&dict, "service_type",
8315 DBUS_TYPE_STRING, &type);
8316 supplicant_dbus_dict_append_fixed_array(&dict, "query",
8317 DBUS_TYPE_BYTE, &service->query,
8318 service->query_length);
8319 supplicant_dbus_dict_append_fixed_array(&dict, "response",
8320 DBUS_TYPE_BYTE, &service->response,
8321 service->response_length);
8322 } else if (service->version && service->service) {
8324 supplicant_dbus_dict_append_basic(&dict, "service_type",
8325 DBUS_TYPE_STRING, &type);
8326 supplicant_dbus_dict_append_basic(&dict, "version",
8327 DBUS_TYPE_INT32, &service->version);
8328 supplicant_dbus_dict_append_basic(&dict, "service",
8329 DBUS_TYPE_STRING, &service->service);
8332 supplicant_dbus_dict_close(iter, &dict);
8335 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
8336 GSupplicantInterfaceCallback callback,
8337 GSupplicantP2PServiceParams *p2p_service_params,
8340 struct p2p_service_data *data;
8345 if (!interface->p2p_support)
8348 data = dbus_malloc0(sizeof(*data));
8352 data->registration = true;
8353 data->interface = interface;
8354 data->service = p2p_service_params;
8355 data->callback = callback;
8356 data->user_data = user_data;
8358 ret = supplicant_dbus_method_call(interface->path,
8359 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
8360 interface_p2p_service_params, interface_p2p_service_result,
8367 return -EINPROGRESS;
8370 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
8371 GSupplicantP2PServiceParams *p2p_service_params)
8373 struct p2p_service_data *data;
8378 if (!interface->p2p_support)
8381 data = dbus_malloc0(sizeof(*data));
8385 data->interface = interface;
8386 data->service = p2p_service_params;
8388 ret = supplicant_dbus_method_call(interface->path,
8389 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
8390 interface_p2p_service_params, interface_p2p_service_result,
8397 return -EINPROGRESS;
8400 struct p2p_listen_data {
8405 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
8407 struct p2p_listen_data *params = user_data;
8408 DBusMessageIter dict;
8410 supplicant_dbus_dict_open(iter, &dict);
8412 supplicant_dbus_dict_append_basic(&dict, "period",
8413 DBUS_TYPE_INT32, ¶ms->period);
8414 supplicant_dbus_dict_append_basic(&dict, "interval",
8415 DBUS_TYPE_INT32, ¶ms->interval);
8416 supplicant_dbus_dict_close(iter, &dict);
8419 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
8420 int period, int interval)
8422 struct p2p_listen_data params;
8426 if (!interface->p2p_support)
8429 params.period = period;
8430 params.interval = interval;
8432 return supplicant_dbus_method_call(interface->path,
8433 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8434 "ExtendedListen", interface_p2p_listen_params,
8435 NULL, ¶ms, NULL);
8438 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
8440 struct p2p_service_data *data = user_data;
8441 GSupplicantP2PServiceParams *service = data->service;
8442 DBusMessageIter array;
8444 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
8446 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
8447 DBUS_TYPE_BYTE_AS_STRING, &array);
8449 if (service->wfd_ies && service->wfd_ies_length > 0) {
8450 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
8451 &service->wfd_ies, service->wfd_ies_length);
8454 dbus_message_iter_close_container(iter, &array);
8457 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
8458 GSupplicantInterfaceCallback callback,
8461 struct p2p_service_data *data;
8466 if (!system_available)
8469 data = dbus_malloc0(sizeof(*data));
8473 data->service = p2p_service_params;
8474 data->callback = callback;
8475 data->user_data = user_data;
8477 if (p2p_service_params->wfd_ies)
8478 data->registration = true;
8480 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
8481 SUPPLICANT_INTERFACE, "WFDIEs",
8482 DBUS_TYPE_ARRAY_AS_STRING
8483 DBUS_TYPE_BYTE_AS_STRING,
8485 interface_p2p_service_result,
8487 if (ret < 0 && ret != -EINPROGRESS) {
8492 return -EINPROGRESS;
8496 static const char *g_supplicant_rule0 = "type=signal,"
8497 "path=" DBUS_PATH_DBUS ","
8498 "sender=" DBUS_SERVICE_DBUS ","
8499 "interface=" DBUS_INTERFACE_DBUS ","
8500 "member=NameOwnerChanged,"
8501 "arg0=" SUPPLICANT_SERVICE;
8502 static const char *g_supplicant_rule1 = "type=signal,"
8503 "interface=" SUPPLICANT_INTERFACE;
8504 static const char *g_supplicant_rule2 = "type=signal,"
8505 "interface=" SUPPLICANT_INTERFACE ".Interface";
8506 static const char *g_supplicant_rule3 = "type=signal,"
8507 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
8508 static const char *g_supplicant_rule4 = "type=signal,"
8509 "interface=" SUPPLICANT_INTERFACE ".BSS";
8510 static const char *g_supplicant_rule5 = "type=signal,"
8511 "interface=" SUPPLICANT_INTERFACE ".Network";
8512 #if !defined TIZEN_EXT
8513 static const char *g_supplicant_rule6 = "type=signal,"
8514 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
8515 static const char *g_supplicant_rule7 = "type=signal,"
8516 "interface=" SUPPLICANT_INTERFACE ".Peer";
8517 static const char *g_supplicant_rule8 = "type=signal,"
8518 "interface=" SUPPLICANT_INTERFACE ".Group";
8520 #if defined TIZEN_EXT_WIFI_MESH
8521 static const char *g_supplicant_rule9 = "type=signal,"
8522 "interface=" SUPPLICANT_INTERFACE ".Interface.Mesh";
8525 static void invoke_introspect_method(void)
8527 DBusMessage *message;
8529 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
8531 DBUS_INTERFACE_INTROSPECTABLE,
8537 dbus_message_set_no_reply(message, TRUE);
8538 dbus_connection_send(connection, message, NULL);
8539 dbus_message_unref(message);
8542 #if defined TIZEN_EXT
8543 void g_supplicant_set_ins_settings(GSupplicantINSPreferredFreq preferred_freq_bssid,
8544 bool last_connected_bssid, bool assoc_reject, bool signal_bssid,
8545 unsigned int preferred_freq_bssid_score, unsigned int last_connected_bssid_score,
8546 unsigned int assoc_reject_score, int signal_level3_5ghz, int signal_level3_24ghz)
8548 ins_settings.preferred_freq_bssid = preferred_freq_bssid;
8549 ins_settings.last_connected_bssid = last_connected_bssid;
8550 ins_settings.assoc_reject = assoc_reject;
8551 ins_settings.signal_bssid = signal_bssid;
8552 ins_settings.preferred_freq_bssid_score = preferred_freq_bssid_score;
8553 ins_settings.last_connected_bssid_score = last_connected_bssid_score;
8554 ins_settings.assoc_reject_score = assoc_reject_score;
8555 ins_settings.signal_level3_5ghz = signal_level3_5ghz;
8556 ins_settings.signal_level3_24ghz = signal_level3_24ghz;
8558 SUPPLICANT_DBG("preferred_freq_bssid [%s]", preferred_freq_bssid ? "true" : "false");
8559 SUPPLICANT_DBG("preferred_freq_bssid_score [%d]", preferred_freq_bssid_score);
8560 SUPPLICANT_DBG("last_connected_bssid [%s]", last_connected_bssid ? "true" : "false");
8561 SUPPLICANT_DBG("last_connected_bssid_score [%d]", last_connected_bssid_score);
8562 SUPPLICANT_DBG("assoc_reject [%s]", assoc_reject ? "true" : "false");
8563 SUPPLICANT_DBG("assoc_reject_score [%d]", assoc_reject_score);
8564 SUPPLICANT_DBG("signal_bssid [%s]", signal_bssid ? "true" : "false");
8565 SUPPLICANT_DBG("signal_level3_5ghz [%d]", signal_level3_5ghz);
8566 SUPPLICANT_DBG("signal_level3_24ghz [%d]", signal_level3_24ghz);
8570 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8571 void g_supplicant_register_eap_callback(g_supplicant_eap_callback cb)
8573 SUPPLICANT_DBG("g_supplicant_register_eap_callback %p", cb);
8575 if (!callbacks_pointer) {
8576 SUPPLICANT_DBG("callbacks_pointer is NULL");
8580 callbacks_pointer->eap = cb;
8583 void g_supplicant_unregister_eap_callback(void)
8585 SUPPLICANT_DBG("g_supplicant_unregister_eap_callback");
8587 if (!callbacks_pointer) {
8588 SUPPLICANT_DBG("callbacks_pointer is NULL");
8592 callbacks_pointer->eap = NULL;
8594 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8596 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8597 int g_supplicant_register(GSupplicantCallbacks *callbacks)
8598 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8599 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
8600 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8602 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8606 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
8608 dbus_connection_unref(connection);
8612 #if defined TIZEN_EXT
8613 simplified_log = connman_setting_get_bool("SimplifiedLog");
8615 callbacks_pointer = callbacks;
8618 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8619 NULL, remove_interface);
8621 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8623 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8625 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8627 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
8629 config_file_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8632 supplicant_dbus_setup(connection);
8634 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
8635 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
8636 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
8637 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
8638 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
8639 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
8640 #if defined TIZEN_EXT
8641 dbus_bus_add_match(connection,
8642 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
8643 "member=ChangeState", NULL);
8645 #if !defined TIZEN_EXT
8646 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
8647 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
8648 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
8650 #if defined TIZEN_EXT_WIFI_MESH
8651 dbus_bus_add_match(connection, g_supplicant_rule9, NULL);
8653 dbus_connection_flush(connection);
8655 if (dbus_bus_name_has_owner(connection,
8656 SUPPLICANT_SERVICE, NULL)) {
8657 system_available = TRUE;
8658 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
8659 SUPPLICANT_INTERFACE,
8660 service_property, NULL, NULL);
8662 invoke_introspect_method();
8664 SUPPLICANT_DBG("supplicant dbus setup completed");
8668 static void unregister_interface_remove_params(DBusMessageIter *iter,
8671 const char *path = user_data;
8673 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
8678 static void unregister_remove_interface(gpointer key, gpointer value,
8681 GSupplicantInterface *interface = value;
8683 supplicant_dbus_method_call(SUPPLICANT_PATH,
8684 SUPPLICANT_INTERFACE,
8686 unregister_interface_remove_params,
8687 NULL, interface->path, NULL);
8690 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
8695 #if defined TIZEN_EXT_WIFI_MESH
8696 dbus_bus_remove_match(connection, g_supplicant_rule9, NULL);
8698 #if !defined TIZEN_EXT
8699 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
8700 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
8701 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
8703 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
8704 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
8705 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
8706 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
8707 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
8708 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
8709 dbus_connection_flush(connection);
8711 dbus_connection_remove_filter(connection,
8712 g_supplicant_filter, NULL);
8715 if (config_file_table) {
8716 g_hash_table_destroy(config_file_table);
8717 config_file_table = NULL;
8721 g_hash_table_destroy(bss_mapping);
8726 g_hash_table_destroy(peer_mapping);
8727 peer_mapping = NULL;
8730 if (group_mapping) {
8731 g_hash_table_destroy(group_mapping);
8732 group_mapping = NULL;
8735 if (interface_table) {
8736 g_hash_table_foreach(interface_table,
8737 unregister_remove_interface, NULL);
8738 g_hash_table_destroy(interface_table);
8739 interface_table = NULL;
8742 if (system_available)
8743 callback_system_killed();
8746 dbus_connection_unref(connection);
8750 callbacks_pointer = NULL;
8755 struct supplicant_mac_policy {
8756 GSupplicantMacPolicyCallback callback;
8757 dbus_uint32_t policy;
8758 const void *user_data;
8761 static void mac_policy_result(const char *error,
8762 DBusMessageIter *iter, void *user_data)
8764 struct supplicant_mac_policy *data = user_data;
8771 SUPPLICANT_DBG("Mac policy setting failure %s", error);
8776 data->callback(result, data->policy,
8777 (void *) data->user_data);
8782 static void mac_policy_params(DBusMessageIter *iter, void *user_data)
8784 struct supplicant_mac_policy *data = user_data;
8786 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(data->policy));
8789 int g_supplicant_interface_set_mac_policy(GSupplicantInterface *interface,
8790 GSupplicantMacPolicyCallback callback,
8791 unsigned int policy,
8794 struct supplicant_mac_policy *data = NULL;
8797 if (!system_available)
8803 data = dbus_malloc0(sizeof(*data));
8807 data->callback = callback;
8808 data->policy = policy;
8809 data->user_data = user_data;
8811 ret = supplicant_dbus_property_set(interface->path,
8812 SUPPLICANT_INTERFACE ".Interface",
8813 "MacAddr", DBUS_TYPE_INT32_AS_STRING,
8814 mac_policy_params, mac_policy_result, data, NULL);
8816 SUPPLICANT_DBG("Unable to set MacAddr configuration");
8823 int g_supplicant_interface_set_preassoc_mac_policy(GSupplicantInterface *interface,
8824 GSupplicantMacPolicyCallback callback,
8825 unsigned int policy,
8828 struct supplicant_mac_policy *data;
8831 if (!system_available)
8837 data = dbus_malloc0(sizeof(*data));
8841 data->callback = callback;
8842 data->policy = policy;
8843 data->user_data = user_data;
8845 ret = supplicant_dbus_property_set(interface->path,
8846 SUPPLICANT_INTERFACE ".Interface",
8847 "PreassocMacAddr", DBUS_TYPE_INT32_AS_STRING,
8848 mac_policy_params, mac_policy_result, data, NULL);
8850 SUPPLICANT_DBG("Unable to set PreassocMacAddr configuration");
8857 struct supplicant_random_mac_lifetime {
8858 GSupplicantRandomMaclifetimeCallback callback;
8859 dbus_uint32_t lifetime;
8860 const void *user_data;
8863 static void random_mac_lifetime_result(const char *error,
8864 DBusMessageIter *iter, void *user_data)
8866 struct supplicant_random_mac_lifetime *data = user_data;
8873 SUPPLICANT_DBG("Random Mac lifetime setting failure %s", error);
8878 data->callback(result, data->lifetime,
8879 (void *) data->user_data);
8884 static void random_mac_lifetime_params(DBusMessageIter *iter, void *user_data)
8886 struct supplicant_random_mac_lifetime *data = user_data;
8888 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &(data->lifetime));
8891 int g_supplicant_interface_set_random_mac_lifetime(GSupplicantInterface *interface,
8892 GSupplicantRandomMaclifetimeCallback callback,
8893 unsigned int lifetime,
8896 struct supplicant_random_mac_lifetime *data;
8899 if (!system_available)
8905 data = dbus_malloc0(sizeof(*data));
8909 data->callback = callback;
8910 data->lifetime = lifetime;
8911 data->user_data = user_data;
8913 ret = supplicant_dbus_property_set(interface->path,
8914 SUPPLICANT_INTERFACE ".Interface",
8915 "RandAddrLifetime", DBUS_TYPE_UINT32_AS_STRING,
8916 random_mac_lifetime_params, random_mac_lifetime_result,
8919 SUPPLICANT_DBG("Unable to set RandAddrLifetime configuration");