3 * WPA supplicant library with GLib integration
5 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include <netinet/if_ether.h>
35 #include <netinet/in.h>
41 #include "gsupplicant.h"
43 #define IEEE80211_CAP_ESS 0x0001
44 #define IEEE80211_CAP_IBSS 0x0002
45 #define IEEE80211_CAP_PRIVACY 0x0010
48 #define WLAN_EID_HT_CAP 45
49 #define WLAN_EID_VHT_CAP 191
50 #define WLAN_EID_SUPP_RATES 1
51 #define WLAN_EID_EXT_SUPP_RATES 50
52 #define COUNTRY_CODE_LENGTH 2
53 #define WIFI_BSSID_LEN_MAX 6
57 #define LAST_CONNECTED_TIMEOUT (5 * 60)
58 #define ASSOC_REJECT_TIMEOUT 10
59 #define FREQ_RANGE_24GHZ_CHANNEL_1 2412
60 #define FREQ_RANGE_24GHZ_CHANNEL_14 2484
61 #define FREQ_RANGE_5GHZ_CHANNEL_32 5160
62 #define FREQ_RANGE_5GHZ_CHANNEL_165 5825
64 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
65 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
68 #define BSS_UNKNOWN_STRENGTH -90
70 static DBusConnection *connection;
72 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
73 static GSupplicantCallbacks *callbacks_pointer;
74 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
75 static const GSupplicantCallbacks *callbacks_pointer;
76 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
78 static dbus_bool_t system_available = FALSE;
79 static dbus_bool_t system_ready = FALSE;
81 static dbus_int32_t debug_level;
82 static dbus_bool_t debug_timestamp = FALSE;
83 static dbus_bool_t debug_showkeys = FALSE;
85 static const char *debug_strings[] = {
86 "msgdump", "debug", "info", "warning", "error", NULL
89 static unsigned int eap_methods;
96 static struct strvalmap eap_method_map[] = {
97 { "MD5", G_SUPPLICANT_EAP_METHOD_MD5 },
98 { "TLS", G_SUPPLICANT_EAP_METHOD_TLS },
99 { "MSCHAPV2", G_SUPPLICANT_EAP_METHOD_MSCHAPV2 },
100 { "PEAP", G_SUPPLICANT_EAP_METHOD_PEAP },
101 { "TTLS", G_SUPPLICANT_EAP_METHOD_TTLS },
102 { "GTC", G_SUPPLICANT_EAP_METHOD_GTC },
103 { "OTP", G_SUPPLICANT_EAP_METHOD_OTP },
104 { "LEAP", G_SUPPLICANT_EAP_METHOD_LEAP },
105 { "WSC", G_SUPPLICANT_EAP_METHOD_WSC },
109 static struct strvalmap keymgmt_map[] = {
110 { "none", G_SUPPLICANT_KEYMGMT_NONE },
111 { "ieee8021x", G_SUPPLICANT_KEYMGMT_IEEE8021X },
112 { "wpa-none", G_SUPPLICANT_KEYMGMT_WPA_NONE },
113 { "wpa-psk", G_SUPPLICANT_KEYMGMT_WPA_PSK },
114 { "wpa-psk-sha256", G_SUPPLICANT_KEYMGMT_WPA_PSK_256 },
115 { "wpa-ft-psk", G_SUPPLICANT_KEYMGMT_WPA_FT_PSK },
116 { "wpa-ft-eap", G_SUPPLICANT_KEYMGMT_WPA_FT_EAP },
117 { "wpa-eap", G_SUPPLICANT_KEYMGMT_WPA_EAP },
118 { "wpa-eap-sha256", G_SUPPLICANT_KEYMGMT_WPA_EAP_256 },
119 { "wps", G_SUPPLICANT_KEYMGMT_WPS },
120 #if defined TIZEN_EXT
121 { "sae", G_SUPPLICANT_KEYMGMT_SAE },
122 { "owe", G_SUPPLICANT_KEYMGMT_OWE },
123 { "dpp", G_SUPPLICANT_KEYMGMT_DPP },
128 static struct strvalmap authalg_capa_map[] = {
129 { "open", G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN },
130 { "shared", G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED },
131 { "leap", G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP },
135 static struct strvalmap proto_capa_map[] = {
136 { "wpa", G_SUPPLICANT_CAPABILITY_PROTO_WPA },
137 { "rsn", G_SUPPLICANT_CAPABILITY_PROTO_RSN },
141 static struct strvalmap group_map[] = {
142 { "wep40", G_SUPPLICANT_GROUP_WEP40 },
143 { "wep104", G_SUPPLICANT_GROUP_WEP104 },
144 { "tkip", G_SUPPLICANT_GROUP_TKIP },
145 { "ccmp", G_SUPPLICANT_GROUP_CCMP },
149 static struct strvalmap pairwise_map[] = {
150 { "none", G_SUPPLICANT_PAIRWISE_NONE },
151 { "tkip", G_SUPPLICANT_PAIRWISE_TKIP },
152 { "ccmp", G_SUPPLICANT_PAIRWISE_CCMP },
156 static struct strvalmap scan_capa_map[] = {
157 { "active", G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE },
158 { "passive", G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE },
159 { "ssid", G_SUPPLICANT_CAPABILITY_SCAN_SSID },
163 static struct strvalmap mode_capa_map[] = {
164 { "infrastructure", G_SUPPLICANT_CAPABILITY_MODE_INFRA },
165 { "ad-hoc", G_SUPPLICANT_CAPABILITY_MODE_IBSS },
166 { "ap", G_SUPPLICANT_CAPABILITY_MODE_AP },
167 { "p2p", G_SUPPLICANT_CAPABILITY_MODE_P2P },
168 #if defined TIZEN_EXT_WIFI_MESH
169 { "mesh", G_SUPPLICANT_CAPABILITY_MODE_MESH },
174 #if defined TIZEN_EXT
175 struct _GSupplicantINSSettings {
176 GSupplicantINSPreferredFreq preferred_freq_bssid;
177 unsigned int preferred_freq_bssid_score;
178 bool last_connected_bssid;
179 unsigned int last_connected_bssid_score;
181 unsigned int assoc_reject_score;
183 int signal_level3_5ghz;
184 int signal_level3_24ghz;
187 static struct _GSupplicantINSSettings ins_settings;
189 static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
194 static GHashTable *interface_table;
195 static GHashTable *bss_mapping;
196 static GHashTable *peer_mapping;
197 static GHashTable *group_mapping;
198 static GHashTable *pending_peer_connection;
199 static GHashTable *config_file_table;
201 struct _GSupplicantWpsCredentials {
202 unsigned char ssid[32];
203 unsigned int ssid_len;
207 struct added_network_information {
209 GSupplicantSecurity security;
211 char * private_passphrase;
212 #if defined TIZEN_EXT
215 char *net_access_key;
219 #if defined TIZEN_EXT_WIFI_MESH
220 struct _GSupplicantMeshGroupInfo {
221 unsigned char ssid[32];
222 unsigned int ssid_len;
223 int disconnect_reason;
227 struct _GSupplicantInterface {
230 unsigned int keymgmt_capa;
231 unsigned int authalg_capa;
232 unsigned int proto_capa;
233 unsigned int group_capa;
234 unsigned int pairwise_capa;
235 unsigned int scan_capa;
236 unsigned int mode_capa;
237 unsigned int max_scan_ssids;
240 bool ap_create_in_progress;
242 GSupplicantState state;
243 dbus_bool_t scanning;
244 GSupplicantInterfaceCallback scan_callback;
250 struct _GSupplicantWpsCredentials wps_cred;
251 GSupplicantWpsState wps_state;
252 GHashTable *network_table;
253 GHashTable *peer_table;
254 GHashTable *group_table;
255 GHashTable *bss_mapping;
257 const char *pending_peer_path;
258 GSupplicantNetwork *current_network;
259 struct added_network_information network_info;
260 #if defined TIZEN_EXT
261 dbus_bool_t is_5_0_Ghz_supported;
262 int disconnect_reason;
264 #if defined TIZEN_EXT
265 unsigned char add_network_bssid[WIFI_BSSID_LEN_MAX];
266 unsigned char connected_bssid[WIFI_BSSID_LEN_MAX];
268 #if defined TIZEN_EXT_WIFI_MESH
270 struct _GSupplicantMeshGroupInfo group_info;
274 struct g_supplicant_bss {
275 GSupplicantInterface *interface;
277 unsigned char bssid[6];
278 unsigned char ssid[32];
279 unsigned int ssid_len;
280 dbus_uint16_t frequency;
281 dbus_uint32_t maxrate;
283 GSupplicantMode mode;
284 GSupplicantSecurity security;
285 dbus_bool_t rsn_selected;
286 unsigned int wpa_keymgmt;
287 unsigned int wpa_pairwise;
288 unsigned int wpa_group;
289 unsigned int rsn_keymgmt;
290 unsigned int rsn_pairwise;
291 unsigned int rsn_group;
292 unsigned int keymgmt;
295 dbus_bool_t ieee8021x;
296 #if defined TIZEN_EXT
298 dbus_bool_t ft_ieee8021x;
301 unsigned char country_code[COUNTRY_CODE_LENGTH];
302 GSupplicantPhy_mode phy_mode;
304 unsigned int wps_capabilities;
305 #if defined TIZEN_EXT
309 dbus_bool_t owe_transition_mode;
310 unsigned int transition_mode_ssid_len;
311 unsigned char transition_mode_bssid[6];
312 unsigned char transition_mode_ssid[32];
316 struct _GSupplicantNetwork {
317 GSupplicantInterface *interface;
321 unsigned char ssid[32];
322 unsigned int ssid_len;
324 dbus_uint16_t frequency;
325 struct g_supplicant_bss *best_bss;
326 GSupplicantMode mode;
327 GSupplicantSecurity security;
329 unsigned int wps_capabilities;
330 GHashTable *bss_table;
331 GHashTable *config_table;
332 #if defined TIZEN_EXT
337 unsigned int keymgmt;
339 unsigned char country_code[COUNTRY_CODE_LENGTH];
340 GSupplicantPhy_mode phy_mode;
341 dbus_bool_t owe_transition_mode;
342 unsigned int transition_mode_ssid_len;
343 unsigned char transition_mode_bssid[6];
344 unsigned char transition_mode_ssid[32];
345 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
346 GHashTable *assoc_reject_table;
350 struct _GSupplicantPeer {
351 GSupplicantInterface *interface;
353 unsigned char device_address[ETH_ALEN];
354 unsigned char iface_address[ETH_ALEN];
356 unsigned char *widi_ies;
359 unsigned int wps_capabilities;
361 const GSupplicantInterface *current_group_iface;
362 bool connection_requested;
365 struct _GSupplicantGroup {
366 GSupplicantInterface *interface;
367 GSupplicantInterface *orig_interface;
373 struct interface_data {
374 GSupplicantInterface *interface;
375 char *path; /* Interface path cannot be taken from interface (above) as
376 * it might have been freed already.
378 GSupplicantInterfaceCallback callback;
380 bool network_remove_in_progress;
381 GSupplicantSSID *ssid;
384 #if defined TIZEN_EXT
385 struct interface_signalpoll_data {
386 GSupplicantInterface *interface;
388 GSupplicantMaxSpeedCallback callback;
393 struct interface_create_data {
397 #if defined TIZEN_EXT_WIFI_MESH
399 bool is_mesh_interface;
401 GSupplicantInterface *interface;
402 GSupplicantInterfaceCallback callback;
406 struct interface_connect_data {
407 GSupplicantInterface *interface;
409 GSupplicantInterfaceCallback callback;
412 GSupplicantSSID *ssid;
413 GSupplicantPeerParams *peer;
417 struct interface_scan_data {
418 GSupplicantInterface *interface;
420 GSupplicantInterfaceCallback callback;
421 GSupplicantScanParams *scan_params;
425 #if defined TIZEN_EXT
426 struct g_connman_bssids {
427 unsigned char bssid[WIFI_BSSID_LEN_MAX];
430 uint16_t assoc_reject_cnt;
431 bool is_last_connected;
432 #if defined TIZEN_EXT_INS
433 int score_last_connected_bssid;
434 int score_assoc_reject;
441 struct update_bssid_data {
442 GSupplicantNetwork *network;
443 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
444 GHashTable *assoc_reject_table;
448 struct assoc_reject_data {
450 GSList *reject_time_list;
453 struct assoc_count_data {
458 static unsigned int last_connected_bss_timeout = 0;
461 static int network_remove(struct interface_data *data);
463 #if defined TIZEN_EXT_WIFI_MESH
464 struct _GSupplicantMeshPeer {
465 GSupplicantInterface *interface;
467 int disconnect_reason;
471 static inline void debug(const char *format, ...)
476 if (!callbacks_pointer || !callbacks_pointer->debug)
479 va_start(ap, format);
481 if (vsnprintf(str, sizeof(str), format, ap) > 0)
482 callbacks_pointer->debug(str);
487 #define SUPPLICANT_DBG(fmt, arg...) \
488 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
490 static GSupplicantMode string2mode(const char *mode)
493 return G_SUPPLICANT_MODE_UNKNOWN;
495 if (g_str_equal(mode, "infrastructure"))
496 return G_SUPPLICANT_MODE_INFRA;
497 else if (g_str_equal(mode, "ad-hoc"))
498 return G_SUPPLICANT_MODE_IBSS;
499 #if defined TIZEN_EXT_WIFI_MESH
500 else if (g_str_equal(mode, "mesh"))
501 return G_SUPPLICANT_MODE_MESH;
504 return G_SUPPLICANT_MODE_UNKNOWN;
507 static const char *mode2string(GSupplicantMode mode)
510 case G_SUPPLICANT_MODE_UNKNOWN:
512 case G_SUPPLICANT_MODE_INFRA:
514 case G_SUPPLICANT_MODE_IBSS:
516 case G_SUPPLICANT_MODE_MASTER:
518 #if defined TIZEN_EXT_WIFI_MESH
519 case G_SUPPLICANT_MODE_MESH:
527 static const char *security2string(GSupplicantSecurity security)
530 case G_SUPPLICANT_SECURITY_UNKNOWN:
532 case G_SUPPLICANT_SECURITY_NONE:
534 case G_SUPPLICANT_SECURITY_WEP:
536 case G_SUPPLICANT_SECURITY_PSK:
538 case G_SUPPLICANT_SECURITY_IEEE8021X:
540 #if defined TIZEN_EXT
541 case G_SUPPLICANT_SECURITY_FT_PSK:
543 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
544 return "ft_ieee8021x";
545 case G_SUPPLICANT_SECURITY_SAE:
547 case G_SUPPLICANT_SECURITY_OWE:
549 case G_SUPPLICANT_SECURITY_DPP:
557 static GSupplicantState string2state(const char *state)
560 return G_SUPPLICANT_STATE_UNKNOWN;
562 if (g_str_equal(state, "unknown"))
563 return G_SUPPLICANT_STATE_UNKNOWN;
564 else if (g_str_equal(state, "interface_disabled"))
565 return G_SUPPLICANT_STATE_DISABLED;
566 else if (g_str_equal(state, "disconnected"))
567 return G_SUPPLICANT_STATE_DISCONNECTED;
568 else if (g_str_equal(state, "inactive"))
569 return G_SUPPLICANT_STATE_INACTIVE;
570 else if (g_str_equal(state, "scanning"))
571 return G_SUPPLICANT_STATE_SCANNING;
572 else if (g_str_equal(state, "authenticating"))
573 return G_SUPPLICANT_STATE_AUTHENTICATING;
574 else if (g_str_equal(state, "associating"))
575 return G_SUPPLICANT_STATE_ASSOCIATING;
576 else if (g_str_equal(state, "associated"))
577 return G_SUPPLICANT_STATE_ASSOCIATED;
578 else if (g_str_equal(state, "group_handshake"))
579 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
580 else if (g_str_equal(state, "4way_handshake"))
581 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
582 else if (g_str_equal(state, "completed"))
583 return G_SUPPLICANT_STATE_COMPLETED;
585 return G_SUPPLICANT_STATE_UNKNOWN;
588 static bool compare_network_parameters(GSupplicantInterface *interface,
589 GSupplicantSSID *ssid)
591 #if defined TIZEN_EXT
592 if (!interface->network_info.ssid)
596 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
599 if (interface->network_info.security != ssid->security)
602 if (interface->network_info.passphrase &&
603 g_strcmp0(interface->network_info.passphrase,
604 ssid->passphrase) != 0) {
608 if (interface->network_info.private_passphrase &&
609 g_strcmp0(interface->network_info.private_passphrase,
610 ssid->private_key_passphrase) != 0) {
614 #if defined TIZEN_EXT
615 if (interface->network_info.connector &&
616 g_strcmp0(interface->network_info.connector,
617 ssid->connector) != 0) {
620 if (interface->network_info.c_sign_key &&
621 g_strcmp0(interface->network_info.c_sign_key,
622 ssid->c_sign_key) != 0) {
625 if (interface->network_info.net_access_key &&
626 g_strcmp0(interface->network_info.net_access_key,
627 ssid->net_access_key) != 0) {
634 static void remove_network_information(GSupplicantInterface * interface)
636 g_free(interface->network_info.ssid);
637 g_free(interface->network_info.passphrase);
638 g_free(interface->network_info.private_passphrase);
639 #if defined TIZEN_EXT
640 g_free(interface->network_info.connector);
641 g_free(interface->network_info.c_sign_key);
642 g_free(interface->network_info.net_access_key);
644 interface->network_info.ssid = NULL;
645 interface->network_info.passphrase = NULL;
646 interface->network_info.private_passphrase = NULL;
647 #if defined TIZEN_EXT
648 interface->network_info.connector = NULL;
649 interface->network_info.c_sign_key = NULL;
650 interface->network_info.net_access_key = NULL;
654 static int store_network_information(GSupplicantInterface * interface,
655 GSupplicantSSID *ssid)
657 interface->network_info.ssid = g_malloc(ssid->ssid_len + 1);
658 if (interface->network_info.ssid != NULL) {
659 memcpy(interface->network_info.ssid, ssid->ssid,
661 interface->network_info.ssid[ssid->ssid_len] = '\0';
666 interface->network_info.security = ssid->security;
668 if ((ssid->security == G_SUPPLICANT_SECURITY_WEP ||
669 ssid->security == G_SUPPLICANT_SECURITY_PSK ||
670 ssid->security == G_SUPPLICANT_SECURITY_NONE) &&
672 interface->network_info.passphrase = g_strdup(ssid->passphrase);
675 if (ssid->security == G_SUPPLICANT_SECURITY_IEEE8021X &&
676 ssid->private_key_passphrase) {
677 interface->network_info.private_passphrase =
678 g_strdup(ssid->private_key_passphrase);
684 static void callback_system_ready(void)
691 if (!callbacks_pointer)
694 if (!callbacks_pointer->system_ready)
697 callbacks_pointer->system_ready();
700 static void callback_system_killed(void)
702 system_ready = FALSE;
704 if (!callbacks_pointer)
707 if (!callbacks_pointer->system_killed)
710 callbacks_pointer->system_killed();
713 static void callback_interface_added(GSupplicantInterface *interface)
717 if (!callbacks_pointer)
720 if (!callbacks_pointer->interface_added)
723 callbacks_pointer->interface_added(interface);
726 static void callback_interface_state(GSupplicantInterface *interface)
728 if (!callbacks_pointer)
731 if (!callbacks_pointer->interface_state)
734 callbacks_pointer->interface_state(interface);
737 static void callback_interface_removed(GSupplicantInterface *interface)
739 if (!callbacks_pointer)
742 if (!callbacks_pointer->interface_removed)
745 callbacks_pointer->interface_removed(interface);
748 #if !defined TIZEN_EXT
749 static void callback_p2p_support(GSupplicantInterface *interface)
753 if (!interface->p2p_support)
756 if (callbacks_pointer && callbacks_pointer->p2p_support)
757 callbacks_pointer->p2p_support(interface);
761 #if defined TIZEN_EXT_WIFI_MESH
762 static void callback_mesh_support(GSupplicantInterface *interface)
766 if (!interface->mesh_support)
769 if (callbacks_pointer && callbacks_pointer->mesh_support)
770 callbacks_pointer->mesh_support(interface);
773 bool g_supplicant_interface_has_mesh(GSupplicantInterface *interface)
778 return interface->mesh_support;
782 static void callback_scan_started(GSupplicantInterface *interface)
784 if (!callbacks_pointer)
787 if (!callbacks_pointer->scan_started)
790 callbacks_pointer->scan_started(interface);
793 static void callback_ap_create_fail(GSupplicantInterface *interface)
795 if (!callbacks_pointer)
798 if (!callbacks_pointer->ap_create_fail)
801 callbacks_pointer->ap_create_fail(interface);
804 static void callback_scan_finished(GSupplicantInterface *interface)
806 if (!callbacks_pointer)
809 if (!callbacks_pointer->scan_finished)
812 callbacks_pointer->scan_finished(interface);
815 static void callback_network_added(GSupplicantNetwork *network)
817 if (!callbacks_pointer)
820 if (!callbacks_pointer->network_added)
823 callbacks_pointer->network_added(network);
826 static void callback_network_removed(GSupplicantNetwork *network)
828 if (!callbacks_pointer)
831 if (!callbacks_pointer->network_removed)
834 callbacks_pointer->network_removed(network);
837 #if defined TIZEN_EXT
838 static void callback_network_merged(GSupplicantNetwork *network)
840 if (!callbacks_pointer)
843 if (!callbacks_pointer->network_merged)
846 callbacks_pointer->network_merged(network);
849 static void callback_assoc_failed(void *user_data)
851 if (!callbacks_pointer)
854 if (!callbacks_pointer->assoc_failed)
857 callbacks_pointer->assoc_failed(user_data);
860 static void callback_scan_done(GSupplicantInterface *interface)
862 if (!callbacks_pointer)
865 if (!callbacks_pointer->scan_done)
868 callbacks_pointer->scan_done(interface);
872 static void callback_network_changed(GSupplicantNetwork *network,
873 const char *property)
875 if (!callbacks_pointer)
878 if (!callbacks_pointer->network_changed)
881 callbacks_pointer->network_changed(network, property);
884 static void callback_network_associated(GSupplicantNetwork *network)
886 if (!callbacks_pointer)
889 if (!callbacks_pointer->network_associated)
892 callbacks_pointer->network_associated(network);
895 static void callback_sta_authorized(GSupplicantInterface *interface,
898 if (!callbacks_pointer)
901 if (!callbacks_pointer->sta_authorized)
904 callbacks_pointer->sta_authorized(interface, addr);
907 static void callback_sta_deauthorized(GSupplicantInterface *interface,
910 if (!callbacks_pointer)
913 if (!callbacks_pointer->sta_deauthorized)
916 callbacks_pointer->sta_deauthorized(interface, addr);
919 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
920 static void callback_eap(GSupplicantInterface *interface, bool status)
922 if (!callbacks_pointer)
925 if (!callbacks_pointer->eap)
928 callbacks_pointer->eap(interface, status);
930 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
932 static void callback_peer_found(GSupplicantPeer *peer)
934 if (!callbacks_pointer)
937 if (!callbacks_pointer->peer_found)
940 callbacks_pointer->peer_found(peer);
943 static void callback_peer_lost(GSupplicantPeer *peer)
945 if (!callbacks_pointer)
948 if (!callbacks_pointer->peer_lost)
951 callbacks_pointer->peer_lost(peer);
954 static void callback_peer_changed(GSupplicantPeer *peer,
955 GSupplicantPeerState state)
957 if (!callbacks_pointer)
960 if (!callbacks_pointer->peer_changed)
963 callbacks_pointer->peer_changed(peer, state);
966 static void callback_peer_request(GSupplicantPeer *peer)
968 if (!callbacks_pointer)
971 if (!callbacks_pointer->peer_request)
974 peer->connection_requested = true;
976 callbacks_pointer->peer_request(peer);
979 static void callback_disconnect_reason_code(GSupplicantInterface *interface,
982 if (!callbacks_pointer)
985 if (!callbacks_pointer->disconnect_reasoncode)
988 if (reason_code != 0)
989 callbacks_pointer->disconnect_reasoncode(interface,
993 static void callback_assoc_status_code(GSupplicantInterface *interface,
996 if (!callbacks_pointer)
999 if (!callbacks_pointer->assoc_status_code)
1002 callbacks_pointer->assoc_status_code(interface, status_code);
1006 static void remove_group(gpointer data)
1008 GSupplicantGroup *group = data;
1011 g_slist_free_full(group->members, g_free);
1013 g_free(group->path);
1017 static void remove_interface(gpointer data)
1019 GSupplicantInterface *interface = data;
1021 g_hash_table_destroy(interface->bss_mapping);
1022 g_hash_table_destroy(interface->network_table);
1023 g_hash_table_destroy(interface->peer_table);
1024 g_hash_table_destroy(interface->group_table);
1026 if (interface->scan_callback) {
1027 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
1028 interface, interface->scan_callback,
1029 interface->scanning);
1031 interface->scan_callback(-EIO, interface, interface->scan_data);
1032 interface->scan_callback = NULL;
1033 interface->scan_data = NULL;
1035 if (interface->scanning) {
1036 interface->scanning = FALSE;
1037 callback_scan_finished(interface);
1041 callback_interface_removed(interface);
1043 g_free(interface->wps_cred.key);
1044 g_free(interface->path);
1045 g_free(interface->network_path);
1046 #if defined TIZEN_EXT
1047 interface->network_path = NULL;
1049 g_free(interface->ifname);
1050 g_free(interface->driver);
1051 g_free(interface->bridge);
1052 remove_network_information(interface);
1056 static void remove_network(gpointer data)
1058 GSupplicantNetwork *network = data;
1060 g_hash_table_destroy(network->bss_table);
1062 callback_network_removed(network);
1064 g_hash_table_destroy(network->config_table);
1065 #if defined TIZEN_EXT
1066 g_hash_table_destroy(network->assoc_reject_table);
1069 g_free(network->path);
1070 g_free(network->group);
1071 g_free(network->name);
1072 #if defined TIZEN_EXT
1073 g_free(network->eap);
1074 g_free(network->identity);
1075 g_free(network->phase2);
1077 #if defined TIZEN_EXT
1078 g_slist_free_full(network->vsie_list, g_free);
1084 static void remove_bss(gpointer data)
1086 struct g_supplicant_bss *bss = data;
1088 supplicant_dbus_property_call_cancel_all(bss);
1091 #if defined TIZEN_EXT
1092 g_slist_free_full(bss->vsie_list, g_free);
1097 static void remove_peer(gpointer data)
1099 GSupplicantPeer *peer = data;
1101 callback_peer_lost(peer);
1104 g_slist_free_full(peer->groups, g_free);
1107 g_hash_table_remove(peer_mapping, peer->path);
1109 if (pending_peer_connection)
1110 g_hash_table_remove(pending_peer_connection, peer->path);
1114 g_free(peer->identifier);
1115 g_free(peer->widi_ies);
1120 #if defined TIZEN_EXT
1121 static void remove_assoc_data(gpointer data)
1123 struct assoc_reject_data *assoc_data = data;
1125 g_free(assoc_data->bssid);
1126 g_slist_free(assoc_data->reject_time_list);
1132 static void debug_strvalmap(const char *label, struct strvalmap *map,
1137 for (i = 0; map[i].str; i++) {
1138 if (val & map[i].val)
1139 SUPPLICANT_DBG("%s: %s", label, map[i].str);
1143 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
1145 GSupplicantInterface *interface = user_data;
1146 const char *str = NULL;
1149 dbus_message_iter_get_basic(iter, &str);
1153 for (i = 0; keymgmt_map[i].str; i++)
1154 if (strcmp(str, keymgmt_map[i].str) == 0) {
1155 interface->keymgmt_capa |= keymgmt_map[i].val;
1160 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
1162 GSupplicantInterface *interface = user_data;
1163 const char *str = NULL;
1166 dbus_message_iter_get_basic(iter, &str);
1170 for (i = 0; authalg_capa_map[i].str; i++)
1171 if (strcmp(str, authalg_capa_map[i].str) == 0) {
1172 interface->authalg_capa |= authalg_capa_map[i].val;
1177 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
1179 GSupplicantInterface *interface = user_data;
1180 const char *str = NULL;
1183 dbus_message_iter_get_basic(iter, &str);
1187 for (i = 0; proto_capa_map[i].str; i++)
1188 if (strcmp(str, proto_capa_map[i].str) == 0) {
1189 interface->proto_capa |= proto_capa_map[i].val;
1194 static void interface_capability_pairwise(DBusMessageIter *iter,
1197 GSupplicantInterface *interface = user_data;
1198 const char *str = NULL;
1201 dbus_message_iter_get_basic(iter, &str);
1205 for (i = 0; pairwise_map[i].str; i++)
1206 if (strcmp(str, pairwise_map[i].str) == 0) {
1207 interface->pairwise_capa |= pairwise_map[i].val;
1212 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
1214 GSupplicantInterface *interface = user_data;
1215 const char *str = NULL;
1218 dbus_message_iter_get_basic(iter, &str);
1222 for (i = 0; group_map[i].str; i++)
1223 if (strcmp(str, group_map[i].str) == 0) {
1224 interface->group_capa |= group_map[i].val;
1229 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
1231 GSupplicantInterface *interface = user_data;
1232 const char *str = NULL;
1235 dbus_message_iter_get_basic(iter, &str);
1239 for (i = 0; scan_capa_map[i].str; i++)
1240 if (strcmp(str, scan_capa_map[i].str) == 0) {
1241 interface->scan_capa |= scan_capa_map[i].val;
1246 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
1248 GSupplicantInterface *interface = user_data;
1249 const char *str = NULL;
1252 dbus_message_iter_get_basic(iter, &str);
1256 for (i = 0; mode_capa_map[i].str; i++)
1257 if (strcmp(str, mode_capa_map[i].str) == 0) {
1258 interface->mode_capa |= mode_capa_map[i].val;
1263 static void interface_capability(const char *key, DBusMessageIter *iter,
1266 GSupplicantInterface *interface = user_data;
1271 if (g_strcmp0(key, "KeyMgmt") == 0)
1272 supplicant_dbus_array_foreach(iter,
1273 interface_capability_keymgmt, interface);
1274 else if (g_strcmp0(key, "AuthAlg") == 0)
1275 supplicant_dbus_array_foreach(iter,
1276 interface_capability_authalg, interface);
1277 else if (g_strcmp0(key, "Protocol") == 0)
1278 supplicant_dbus_array_foreach(iter,
1279 interface_capability_proto, interface);
1280 else if (g_strcmp0(key, "Pairwise") == 0)
1281 supplicant_dbus_array_foreach(iter,
1282 interface_capability_pairwise, interface);
1283 else if (g_strcmp0(key, "Group") == 0)
1284 supplicant_dbus_array_foreach(iter,
1285 interface_capability_group, interface);
1286 else if (g_strcmp0(key, "Scan") == 0)
1287 supplicant_dbus_array_foreach(iter,
1288 interface_capability_scan, interface);
1289 else if (g_strcmp0(key, "Modes") == 0)
1290 supplicant_dbus_array_foreach(iter,
1291 interface_capability_mode, interface);
1292 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
1293 dbus_int32_t max_scan_ssid;
1295 dbus_message_iter_get_basic(iter, &max_scan_ssid);
1296 if (max_scan_ssid < 2)
1298 interface->max_scan_ssids = max_scan_ssid;
1299 #if defined TIZEN_EXT
1300 } else if (g_strcmp0(key, "Is5GhzSupported") == 0) {
1301 dbus_bool_t is_5_0_Ghz_supported;
1303 dbus_message_iter_get_basic(iter, &is_5_0_Ghz_supported);
1304 interface->is_5_0_Ghz_supported = is_5_0_Ghz_supported;
1307 SUPPLICANT_DBG("key %s type %c",
1308 key, dbus_message_iter_get_arg_type(iter));
1311 struct set_apscan_data
1313 unsigned int ap_scan;
1314 GSupplicantInterface *interface;
1317 static void set_apscan(DBusMessageIter *iter, void *user_data)
1319 struct set_apscan_data *data = user_data;
1320 unsigned int ap_scan = data->ap_scan;
1322 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
1325 static void set_apscan_complete(const char *error,
1326 DBusMessageIter *iter, void *user_data)
1328 struct set_apscan_data *data = user_data;
1329 GSupplicantInterface *interface = data->interface;
1332 interface->ap_create_in_progress = false;
1333 SUPPLICANT_DBG("Set AP scan error %s", error);
1337 interface->ap_create_in_progress = true;
1342 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
1343 unsigned int ap_scan)
1345 struct set_apscan_data *data;
1348 data = dbus_malloc0(sizeof(*data));
1353 data->ap_scan = ap_scan;
1354 data->interface = interface;
1356 ret = supplicant_dbus_property_set(interface->path,
1357 SUPPLICANT_INTERFACE ".Interface",
1358 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
1359 set_apscan, set_apscan_complete, data, NULL);
1366 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
1372 interface->data = data;
1375 interface->scan_callback = NULL;
1378 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
1383 return interface->data;
1386 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
1391 return interface->ifname;
1394 #if defined TIZEN_EXT
1395 bool g_supplicant_interface_get_is_5_0_ghz_supported(GSupplicantInterface *interface)
1400 return interface->is_5_0_Ghz_supported;
1404 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
1409 return interface->driver;
1412 GSupplicantState g_supplicant_interface_get_state(
1413 GSupplicantInterface *interface)
1416 return G_SUPPLICANT_STATE_UNKNOWN;
1418 return interface->state;
1421 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
1426 return (const char *)interface->wps_cred.key;
1429 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
1430 unsigned int *ssid_len)
1435 if (!interface || interface->wps_cred.ssid_len == 0) {
1440 *ssid_len = interface->wps_cred.ssid_len;
1441 return interface->wps_cred.ssid;
1444 GSupplicantWpsState g_supplicant_interface_get_wps_state(
1445 GSupplicantInterface *interface)
1448 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
1450 return interface->wps_state;
1453 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
1458 return interface->mode_capa;
1461 unsigned int g_supplicant_interface_get_max_scan_ssids(
1462 GSupplicantInterface *interface)
1467 if (interface->max_scan_ssids == 0)
1468 return WPAS_MAX_SCAN_SSIDS;
1470 return interface->max_scan_ssids;
1473 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
1475 dbus_bool_t enable = *(dbus_bool_t *)user_data;
1477 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
1480 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
1486 if (!interface->network_path)
1489 SUPPLICANT_DBG(" ");
1490 return supplicant_dbus_property_set(interface->network_path,
1491 SUPPLICANT_INTERFACE ".Network",
1492 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
1493 set_network_enabled, NULL, &enable, NULL);
1496 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
1501 return interface->ready;
1504 GSupplicantInterface *g_supplicant_network_get_interface(
1505 GSupplicantNetwork *network)
1510 return network->interface;
1513 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
1515 if (!network || !network->name)
1518 return network->name;
1521 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
1523 if (!network || !network->group)
1526 return network->group;
1529 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1531 if (!network || !network->path)
1534 return network->path;
1537 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1540 return G_SUPPLICANT_MODE_UNKNOWN;
1542 return mode2string(network->mode);
1545 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1548 return G_SUPPLICANT_SECURITY_UNKNOWN;
1550 return security2string(network->security);
1553 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1554 unsigned int *ssid_len)
1561 *ssid_len = network->ssid_len;
1562 return network->ssid;
1565 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1570 return network->signal;
1573 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1578 return network->frequency;
1581 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1586 return network->wps;
1589 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1594 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1600 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1605 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1611 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1616 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1623 GSupplicantPhy_mode g_supplicant_network_get_phy_mode(GSupplicantNetwork *network)
1626 return G_SUPPLICANT_MODE_IEEE80211_UNKNOWN;
1628 return network->phy_mode;
1632 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1637 return peer->interface;
1640 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1648 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1653 return peer->identifier;
1656 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1661 return peer->device_address;
1664 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1669 return peer->iface_address;
1672 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1680 #if defined TIZEN_EXT
1681 bool g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1686 return network->isHS20AP;
1689 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1691 if (!network || !network->eap)
1694 return network->eap;
1697 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1699 if (!network || !network->identity)
1702 return network->identity;
1705 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1707 if (!network || !network->phase2)
1710 return network->phase2;
1713 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
1715 if (network == NULL)
1718 return network->keymgmt;
1721 const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
1727 return network->country_code;
1731 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1734 if (!peer || !length)
1737 *length = peer->widi_ies_length;
1738 return peer->widi_ies;
1741 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1746 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1752 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1757 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1763 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1765 if (!peer || !peer->groups)
1771 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1776 return (GSupplicantInterface *) peer->current_group_iface;
1779 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1781 GSupplicantGroup *group;
1787 for (list = peer->groups; list; list = list->next) {
1788 const char *path = list->data;
1790 group = g_hash_table_lookup(group_mapping, path);
1794 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1795 group->orig_interface != peer->interface)
1798 if (group->interface == peer->current_group_iface)
1805 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1810 return peer->connection_requested;
1813 #if defined TIZEN_EXT
1815 * Description: Network client requires additional wifi specific info
1817 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1819 if (network == NULL || network->best_bss == NULL)
1822 return (const unsigned char *)network->best_bss->bssid;
1824 dbus_bool_t g_supplicant_network_get_transition_mode(GSupplicantNetwork *network)
1826 if (network == NULL)
1829 return network->owe_transition_mode;
1833 const unsigned char *g_supplicant_network_get_transition_mode_bssid(GSupplicantNetwork *network)
1835 if (network == NULL)
1838 return (const unsigned char *)network->transition_mode_bssid;
1841 const void *g_supplicant_network_get_transition_mode_ssid(GSupplicantNetwork *network,
1842 unsigned int *transition_mode_ssid_len)
1845 *transition_mode_ssid_len = 0;
1849 *transition_mode_ssid_len = network->transition_mode_ssid_len;
1850 return network->transition_mode_ssid;
1853 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1855 if (network == NULL || network->best_bss == NULL)
1858 return network->best_bss->maxrate;
1861 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1863 if (network == NULL || network->best_bss == NULL)
1866 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1867 #if defined TIZEN_EXT
1868 network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1869 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1870 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP ||
1871 #endif /* TIZEN_EXT */
1872 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1873 unsigned int pairwise;
1875 pairwise = network->best_bss->rsn_pairwise |
1876 network->best_bss->wpa_pairwise;
1878 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1879 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1881 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1883 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1886 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1888 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1894 bool g_supplicant_network_get_rsn_mode(GSupplicantNetwork *network)
1896 if (network == NULL || network->best_bss == NULL)
1899 #if defined TIZEN_EXT
1900 if (network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1901 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1902 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP)
1904 #endif /* TIZEN_EXT */
1906 if (network->best_bss->rsn_selected) {
1907 const char *mode = g_supplicant_network_get_enc_mode(network);
1908 if (g_strcmp0(mode, "aes") == 0 ||
1909 g_strcmp0(mode, "mixed") == 0)
1917 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
1919 GSList *vsie_list = NULL;
1924 if (g_slist_length(network->vsie_list) > 0) {
1925 GSList *list = NULL;
1926 unsigned char *vsie = NULL;
1927 for (list = network->vsie_list; list; list = list->next) {
1928 unsigned char *ie = (unsigned char *)list->data;
1931 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
1934 memcpy(vsie, ie, ie[1]+2);
1935 vsie_list = g_slist_append(vsie_list, vsie);
1937 SUPPLICANT_DBG("Failed to allocate memory");
1944 static bool compare_bssid(unsigned char *bssid_a, unsigned char *bssid_b)
1946 if (!memcmp(bssid_a, bssid_b, WIFI_BSSID_LEN_MAX))
1952 static gchar *convert_bssid_to_str(unsigned char *bssid)
1957 bssid_str = g_string_sized_new(18);
1961 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
1962 g_string_append_printf(bssid_str, "%02x", bssid[i]);
1963 if (i < WIFI_BSSID_LEN_MAX - 1)
1964 g_string_append(bssid_str, ":");
1967 return g_string_free(bssid_str, FALSE);
1970 static void count_assoc_reject(gpointer data, gpointer user_data)
1972 time_t assoc_reject_time = GPOINTER_TO_INT(data);
1973 struct assoc_count_data *assoc_count = user_data;
1975 if (assoc_reject_time > assoc_count->ref_time)
1976 assoc_count->assoc_count++;
1979 static uint16_t get_assoc_reject_cnt(GHashTable *assoc_reject_table, unsigned char *bssid)
1982 struct assoc_reject_data *assoc_data;
1983 struct assoc_count_data assoc_count;
1985 struct tm* timeinfo;
1987 if (g_hash_table_size(assoc_reject_table) < 1)
1993 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
1996 bssid_str = convert_bssid_to_str(bssid);
2000 assoc_data = g_hash_table_lookup(assoc_reject_table, bssid_str);
2006 if (g_slist_length(assoc_data->reject_time_list) < 1) {
2011 /* Only events that occur within one hour are appened. */
2012 curr_time = time(NULL);
2013 timeinfo = localtime(&curr_time);
2014 timeinfo->tm_hour -= 1;
2016 assoc_count.ref_time = mktime(timeinfo);
2017 assoc_count.assoc_count = 0;
2019 g_slist_foreach(assoc_data->reject_time_list, count_assoc_reject, &assoc_count);
2022 return assoc_count.assoc_count;
2025 static int calculate_score_last_connected_bssid(bool is_last_connected)
2029 if (ins_settings.last_connected_bssid) {
2030 if (is_last_connected)
2031 score += ins_settings.last_connected_bssid_score;
2037 static int calculate_score_assoc_reject(uint16_t assoc_reject_cnt)
2041 if (ins_settings.assoc_reject)
2042 score -= (assoc_reject_cnt * ins_settings.assoc_reject_score);
2047 static int calculate_score_frequency(dbus_int16_t strength, dbus_uint16_t frequency)
2051 switch (ins_settings.preferred_freq_bssid) {
2052 case G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ:
2053 if ((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
2054 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
2055 (strength > ins_settings.signal_level3_24ghz))
2056 score += ins_settings.preferred_freq_bssid_score;
2059 case G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ:
2060 if ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
2061 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
2062 (strength > ins_settings.signal_level3_5ghz))
2063 score += ins_settings.preferred_freq_bssid_score;
2073 static int calculate_score_strength(dbus_int16_t strength)
2077 if (ins_settings.signal_bssid)
2078 score += (((strength > -60) ? -60 : strength) + 85);
2083 static int calculate_score(bool is_last_connected, uint16_t assoc_reject_cnt,
2084 dbus_int16_t strength, dbus_uint16_t frequency)
2088 score += calculate_score_last_connected_bssid(is_last_connected);
2089 score += calculate_score_assoc_reject(assoc_reject_cnt);
2090 score += calculate_score_frequency(strength, frequency);
2091 score += calculate_score_strength(strength);
2096 static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
2098 struct g_supplicant_bss *bss = value;
2099 struct g_connman_bssids *bssids = NULL;
2100 struct update_bssid_data *bssid_data = (struct update_bssid_data *)user_data;
2102 bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
2105 memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
2107 bssids->strength = bss->signal;
2108 bssids->strength += 120;
2110 if (bssids->strength > 100)
2111 bssids->strength = 100;
2113 bssids->frequency = bss->frequency;
2115 bssids->assoc_reject_cnt = get_assoc_reject_cnt(bssid_data->assoc_reject_table, bssids->bssid);
2117 bssids->is_last_connected = compare_bssid(bssids->bssid, bssid_data->last_connected_bssid);
2119 #if defined TIZEN_EXT_INS
2120 bssids->score_last_connected_bssid = calculate_score_last_connected_bssid(bssids->is_last_connected);
2121 bssids->score_assoc_reject = calculate_score_assoc_reject(bssids->assoc_reject_cnt);
2122 bssids->score_frequency = calculate_score_frequency(bss->signal, bssids->frequency);
2123 bssids->score_strength = calculate_score_strength(bssids->strength);
2126 bssids->ins_score = calculate_score(bssids->is_last_connected,
2127 bssids->assoc_reject_cnt, bssids->frequency, bss->signal);
2129 bssid_data->bssid_list = g_slist_append(bssid_data->bssid_list, bssids);
2131 SUPPLICANT_DBG("Failed to allocate memory");
2134 static gint cmp_bss(gconstpointer a, gconstpointer b)
2136 struct g_connman_bssids *entry_a = (struct g_connman_bssids *)a;
2137 struct g_connman_bssids *entry_b = (struct g_connman_bssids *)b;
2139 if (entry_a->ins_score > entry_b->ins_score)
2142 if (entry_a->ins_score < entry_b->ins_score)
2148 #if defined TIZEN_EXT_INS
2149 static void print_bssid_sort(gpointer data, gpointer user_data)
2151 struct g_connman_bssids *bssids = data;
2153 SUPPLICANT_DBG("bssid[" MACSTR "] total[%2d] freq[%2d] "
2154 "last_conn[%2d] assoc_reject[%2d] strength[%2d]",
2155 MAC2STR(bssids->bssid), bssids->ins_score,
2156 bssids->score_frequency, bssids->score_last_connected_bssid,
2157 bssids->score_assoc_reject, bssids->score_strength);
2161 void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network)
2163 struct update_bssid_data bssid_data;
2165 if (g_hash_table_size(network->bss_table) < 1)
2168 bssid_data.network = network;
2169 memset(&bssid_data, 0, sizeof(bssid_data));
2170 memcpy(bssid_data.last_connected_bssid, network->last_connected_bssid, WIFI_BSSID_LEN_MAX);
2171 bssid_data.assoc_reject_table = network->assoc_reject_table;
2173 g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_data);
2174 bssid_data.bssid_list = g_slist_sort(bssid_data.bssid_list, cmp_bss);
2175 #if defined TIZEN_EXT_INS
2176 g_slist_foreach(bssid_data.bssid_list, print_bssid_sort, NULL);
2179 return bssid_data.bssid_list;
2182 void g_supplicant_network_set_last_connected_bssid(GSupplicantNetwork *network, const unsigned char *bssid)
2187 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2190 memcpy(network->last_connected_bssid, bssid, WIFI_BSSID_LEN_MAX);
2192 SUPPLICANT_DBG("last connected bssid [" MACSTR "]", MAC2STR(bssid));
2195 const unsigned char *g_supplicant_network_get_last_connected_bssid(GSupplicantNetwork *network)
2197 if (network == NULL)
2200 return (const unsigned char *)network->last_connected_bssid;
2203 void g_supplicant_network_update_assoc_reject(GSupplicantInterface *interface,
2204 GSupplicantNetwork *network)
2206 struct assoc_reject_data *assoc_data;
2213 bssid_str = convert_bssid_to_str(interface->add_network_bssid);
2217 assoc_data = g_hash_table_lookup(network->assoc_reject_table, bssid_str);
2219 assoc_data = g_try_new0(struct assoc_reject_data, 1);
2225 assoc_data->bssid = g_strdup(bssid_str);
2226 g_hash_table_insert(network->assoc_reject_table, assoc_data->bssid, assoc_data);
2229 curr_time = time(NULL);
2230 assoc_data->reject_time_list = g_slist_append(assoc_data->reject_time_list, GINT_TO_POINTER(curr_time));
2232 SUPPLICANT_DBG("bssid [%s] time [%u]", bssid_str, curr_time);
2236 callback_network_changed(network, "UpdateAssocReject");
2239 GHashTable *g_supplicant_network_get_assoc_reject_table(GSupplicantNetwork *network)
2244 return network->assoc_reject_table;
2247 GSupplicantNetwork *g_supplicant_interface_get_network(GSupplicantInterface *interface,
2253 return g_hash_table_lookup(interface->network_table, group);
2257 static void merge_network(GSupplicantNetwork *network)
2260 const char *ssid, *mode, *key_mgmt;
2261 #if defined TIZEN_EXT
2262 const char *isHS20AP;
2263 const char *eap, *identity, *phase2;
2265 unsigned int i, ssid_len;
2268 ssid = g_hash_table_lookup(network->config_table, "ssid");
2269 mode = g_hash_table_lookup(network->config_table, "mode");
2270 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
2271 #if defined TIZEN_EXT
2272 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
2273 eap = g_hash_table_lookup(network->config_table, "eap");
2274 identity = g_hash_table_lookup(network->config_table, "identity");
2275 phase2 = g_hash_table_lookup(network->config_table, "phase2");
2278 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
2281 ssid_len = strlen(ssid);
2285 str = g_string_sized_new((ssid_len * 2) + 24);
2289 for (i = 0; i < ssid_len; i++)
2290 #if defined TIZEN_EXT
2294 g_string_append_printf(str, "%02x", ssid[i]);
2295 #if defined TIZEN_EXT
2299 if (g_strcmp0(mode, "0") == 0)
2300 g_string_append_printf(str, "_managed");
2301 else if (g_strcmp0(mode, "1") == 0)
2302 g_string_append_printf(str, "_adhoc");
2303 #if defined TIZEN_EXT_WIFI_MESH
2304 else if (g_strcmp0(mode, "5") == 0)
2305 g_string_append_printf(str, "_mesh");
2308 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
2309 g_string_append_printf(str, "_psk");
2310 #if defined TIZEN_EXT
2311 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
2312 g_string_append_printf(str, "_ieee8021x");
2314 g_string_append_printf(str, "_none");
2317 group = g_string_free(str, FALSE);
2319 SUPPLICANT_DBG("%s", group);
2321 #if defined TIZEN_EXT
2322 if (g_strcmp0(isHS20AP, "1") == 0) {
2323 network->isHS20AP = 1;
2325 g_free(network->eap);
2326 network->eap = g_strdup(eap);
2328 if (network->identity)
2329 g_free(network->identity);
2330 network->identity = g_strdup(identity);
2332 if (network->phase2)
2333 g_free(network->phase2);
2334 network->phase2 = g_strdup(phase2);
2336 network->isHS20AP = 0;
2338 network->group = g_strdup(group);
2339 callback_network_merged(network);
2340 g_free(network->group);
2345 g_hash_table_destroy(network->config_table);
2347 g_free(network->path);
2351 static void network_property(const char *key, DBusMessageIter *iter,
2354 GSupplicantNetwork *network = user_data;
2356 if (!network->interface)
2360 merge_network(network);
2364 if (g_strcmp0(key, "Enabled") == 0) {
2365 dbus_bool_t enabled = FALSE;
2367 dbus_message_iter_get_basic(iter, &enabled);
2368 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
2369 const char *str = NULL;
2371 dbus_message_iter_get_basic(iter, &str);
2373 g_hash_table_replace(network->config_table,
2374 g_strdup(key), g_strdup(str));
2377 SUPPLICANT_DBG("key %s type %c",
2378 key, dbus_message_iter_get_arg_type(iter));
2381 static void interface_network_added(DBusMessageIter *iter, void *user_data)
2383 GSupplicantInterface *interface = user_data;
2384 GSupplicantNetwork *network;
2385 const char *path = NULL;
2389 dbus_message_iter_get_basic(iter, &path);
2393 if (g_strcmp0(path, "/") == 0)
2396 network = g_try_new0(GSupplicantNetwork, 1);
2400 network->interface = interface;
2401 network->path = g_strdup(path);
2403 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2406 dbus_message_iter_next(iter);
2407 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
2408 supplicant_dbus_property_foreach(iter, network_property,
2410 network_property(NULL, NULL, network);
2414 supplicant_dbus_property_get_all(path,
2415 SUPPLICANT_INTERFACE ".Network",
2416 network_property, network, NULL);
2419 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
2424 static char *create_name(unsigned char *ssid, int ssid_len)
2427 const gchar *remainder, *invalid;
2428 int valid_bytes, remaining_bytes;
2430 if (ssid_len < 1 || ssid[0] == '\0')
2431 return g_strdup("");
2434 remainder = (const gchar *)ssid;
2435 remaining_bytes = ssid_len;
2437 while (remaining_bytes != 0) {
2438 if (g_utf8_validate(remainder, remaining_bytes,
2443 valid_bytes = invalid - remainder;
2446 string = g_string_sized_new(remaining_bytes);
2448 g_string_append_len(string, remainder, valid_bytes);
2450 /* append U+FFFD REPLACEMENT CHARACTER */
2451 g_string_append(string, "\357\277\275");
2453 remaining_bytes -= valid_bytes + 1;
2454 remainder = invalid + 1;
2458 return g_strndup((const gchar *)ssid, ssid_len + 1);
2460 g_string_append(string, remainder);
2462 return g_string_free(string, FALSE);
2465 static char *create_group(struct g_supplicant_bss *bss)
2469 const char *mode, *security;
2471 str = g_string_sized_new((bss->ssid_len * 2) + 24);
2475 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
2476 for (i = 0; i < bss->ssid_len; i++)
2477 g_string_append_printf(str, "%02x", bss->ssid[i]);
2479 g_string_append_printf(str, "hidden");
2481 mode = mode2string(bss->mode);
2483 g_string_append_printf(str, "_%s", mode);
2485 security = security2string(bss->security);
2487 g_string_append_printf(str, "_%s", security);
2489 return g_string_free(str, FALSE);
2491 #if defined TIZEN_EXT
2492 static void update_network_with_best_bss(GSupplicantNetwork *network,
2493 struct g_supplicant_bss *best_bss)
2495 network->signal = best_bss->signal;
2496 network->frequency = best_bss->frequency;
2497 network->best_bss = best_bss;
2500 static bool update_best_bss(GSupplicantNetwork *network,
2501 struct g_supplicant_bss *bss, struct g_supplicant_bss *best_bss)
2506 if (network->best_bss == NULL) {
2507 update_network_with_best_bss(network, bss);
2511 score_new = calculate_score(
2512 compare_bssid(bss->bssid, network->last_connected_bssid),
2513 get_assoc_reject_cnt(network->assoc_reject_table, bss->bssid),
2514 bss->frequency, bss->signal);
2516 score_best = calculate_score(
2517 compare_bssid(network->best_bss->bssid, network->last_connected_bssid),
2518 get_assoc_reject_cnt(network->assoc_reject_table, network->best_bss->bssid),
2519 network->best_bss->frequency, network->best_bss->signal);
2521 if (score_new > score_best) {
2522 SUPPLICANT_DBG("new[" MACSTR "][%u] : best[" MACSTR "][%u]",
2523 MAC2STR(bss->bssid), score_new,
2524 MAC2STR(network->best_bss->bssid), score_best);
2526 update_network_with_best_bss(network, bss);
2528 SUPPLICANT_DBG("Update best BSS for %s", network->name);
2536 static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
2538 GSupplicantInterface *interface = bss->interface;
2539 GSupplicantNetwork *network;
2541 bool is_new_network;
2543 group = create_group(bss);
2544 SUPPLICANT_DBG("New group created: %s", group);
2549 network = g_hash_table_lookup(interface->network_table, group);
2552 SUPPLICANT_DBG("Network %s already exist", network->name);
2553 is_new_network = false;
2558 is_new_network = true;
2560 network = g_try_new0(GSupplicantNetwork, 1);
2566 network->interface = interface;
2568 network->path = g_strdup(bss->path);
2569 network->group = group;
2570 network->name = create_name(bss->ssid, bss->ssid_len);
2571 network->mode = bss->mode;
2572 network->security = bss->security;
2573 network->ssid_len = bss->ssid_len;
2574 memcpy(network->ssid, bss->ssid, bss->ssid_len);
2575 network->signal = bss->signal;
2576 network->frequency = bss->frequency;
2577 network->best_bss = bss;
2579 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2580 network->wps = TRUE;
2581 network->wps_capabilities = bss->wps_capabilities;
2584 #if defined TIZEN_EXT
2585 network->owe_transition_mode = bss->owe_transition_mode;
2586 memcpy(network->transition_mode_ssid, bss->transition_mode_ssid, bss->transition_mode_ssid_len);
2587 memcpy(network->transition_mode_bssid, bss->transition_mode_bssid, WIFI_BSSID_LEN_MAX);
2589 network->keymgmt = bss->keymgmt;
2591 if (g_slist_length(bss->vsie_list) > 0) {
2592 GSList *list = NULL;
2593 unsigned char *vsie = NULL;
2594 for (list = bss->vsie_list; list; list = list->next) {
2595 unsigned char *ie = (unsigned char *)list->data;
2596 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2599 memcpy(vsie, ie, ie[1]+2);
2600 network->vsie_list = g_slist_append(network->vsie_list, vsie);
2602 SUPPLICANT_DBG("Failed to allocate memory.");
2606 network->isHS20AP = bss->hs20;
2607 memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
2608 network->phy_mode = bss->phy_mode;
2611 SUPPLICANT_DBG("New network %s created", network->name);
2613 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2616 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2619 #if defined TIZEN_EXT
2620 network->assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2621 NULL, remove_assoc_data);
2624 g_hash_table_replace(interface->network_table,
2625 network->group, network);
2627 callback_network_added(network);
2630 /* We update network's WPS properties if only bss provides WPS. */
2631 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2632 network->wps = TRUE;
2633 network->wps_capabilities = bss->wps_capabilities;
2635 if (!is_new_network)
2636 callback_network_changed(network, "WPSCapabilities");
2640 * Do not change best BSS if we are connected. It will be done through
2641 * CurrentBSS property in case of misalignment with wpa_s or roaming.
2643 #if defined TIZEN_EXT
2644 if (network != interface->current_network) {
2645 if (update_best_bss(network, bss, network->best_bss))
2646 callback_network_changed(network, "Signal");
2649 if (network != interface->current_network &&
2650 bss->signal > network->signal) {
2651 network->signal = bss->signal;
2652 network->best_bss = bss;
2653 callback_network_changed(network, "Signal");
2657 g_hash_table_replace(interface->bss_mapping, bss->path, network);
2658 g_hash_table_replace(network->bss_table, bss->path, bss);
2660 g_hash_table_replace(bss_mapping, bss->path, interface);
2665 static void bss_rates(DBusMessageIter *iter, void *user_data)
2667 struct g_supplicant_bss *bss = user_data;
2668 dbus_uint32_t rate = 0;
2670 dbus_message_iter_get_basic(iter, &rate);
2674 if (rate > bss->maxrate)
2675 bss->maxrate = rate;
2678 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
2680 unsigned int *keymgmt = user_data;
2681 const char *str = NULL;
2684 dbus_message_iter_get_basic(iter, &str);
2688 for (i = 0; keymgmt_map[i].str; i++)
2689 if (strcmp(str, keymgmt_map[i].str) == 0) {
2690 SUPPLICANT_DBG("Keymgmt: %s", str);
2691 *keymgmt |= keymgmt_map[i].val;
2696 static void bss_group(DBusMessageIter *iter, void *user_data)
2698 unsigned int *group = user_data;
2699 const char *str = NULL;
2702 dbus_message_iter_get_basic(iter, &str);
2706 for (i = 0; group_map[i].str; i++)
2707 if (strcmp(str, group_map[i].str) == 0) {
2708 SUPPLICANT_DBG("Group: %s", str);
2709 *group |= group_map[i].val;
2714 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
2716 unsigned int *pairwise = user_data;
2717 const char *str = NULL;
2720 dbus_message_iter_get_basic(iter, &str);
2724 for (i = 0; pairwise_map[i].str; i++)
2725 if (strcmp(str, pairwise_map[i].str) == 0) {
2726 SUPPLICANT_DBG("Pairwise: %s", str);
2727 *pairwise |= pairwise_map[i].val;
2732 static void bss_wpa(const char *key, DBusMessageIter *iter,
2735 struct g_supplicant_bss *bss = user_data;
2736 unsigned int value = 0;
2738 SUPPLICANT_DBG("Key: %s", key);
2740 if (g_strcmp0(key, "KeyMgmt") == 0) {
2741 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
2743 if (bss->rsn_selected)
2744 bss->rsn_keymgmt = value;
2746 bss->wpa_keymgmt = value;
2747 } else if (g_strcmp0(key, "Group") == 0) {
2748 supplicant_dbus_array_foreach(iter, bss_group, &value);
2750 if (bss->rsn_selected)
2751 bss->rsn_group = value;
2753 bss->wpa_group = value;
2754 } else if (g_strcmp0(key, "Pairwise") == 0) {
2755 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
2757 if (bss->rsn_selected)
2758 bss->rsn_pairwise = value;
2760 bss->wpa_pairwise = value;
2764 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
2767 unsigned int len = 0;
2769 while (len + 4 < ie_size) {
2770 unsigned int hi = ie[len];
2771 unsigned int lo = ie[len + 1];
2772 unsigned int tmp_type = (hi << 8) + lo;
2773 unsigned int v_len = 0;
2775 /* hi and lo are used to recreate an unsigned int
2776 * based on 2 8bits length unsigned int. */
2780 v_len = (hi << 8) + lo;
2782 if (tmp_type == type) {
2783 unsigned int ret_value = 0;
2784 unsigned char *value = (unsigned char *)&ret_value;
2786 SUPPLICANT_DBG("IE: match type 0x%x", type);
2788 /* Verifying length relevance */
2789 if (v_len > sizeof(unsigned int) ||
2790 len + 4 + v_len > ie_size)
2793 memcpy(value, ie + len + 4, v_len);
2795 SUPPLICANT_DBG("returning 0x%x", ret_value);
2802 SUPPLICANT_DBG("returning 0");
2806 #if defined TIZEN_EXT
2807 static void get_bss_phy_mode(unsigned int max_rate,
2808 unsigned int max_ext_rate, bool ht, bool vht, void *data)
2810 struct g_supplicant_bss *bss = data;
2811 unsigned int freq = bss->frequency;
2813 /* Following conditions are used to determine
2814 * IEEE 802.11 Protocol Modes:-
2816 * 1. If “Supported rates” is only till 11 Mbps,
2817 * and frequency is in 2.4GHz band, then protocol is 11B.
2818 * 2. If “Supported rates” is till 54Mbps or
2819 * “Extended supported rates” are present,
2820 * and frequency is in 2.4GHz band, then protocol is 11G.
2821 * 3. If “Supported rates” is only till 54 Mbps,
2822 * frequency is in 5GHz band , then protocol is 11A.
2823 * 4. If “HT capabilities” is supported , then protocol is 11N.
2824 * 5. If “HT capabilities” & “VHT” is supported and
2825 * frequency is in 5 GHz band, then protocol is 11AC.
2828 if (freq >= 2412 && freq <= 2484) { /* 2.4 Ghz Band */
2829 if (max_rate <= 11 && max_ext_rate <= 0 && !ht)
2830 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211B;
2831 else if ((max_rate <= 54 || max_ext_rate > 0) && !ht)
2832 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BG;
2833 else if ((max_rate >= 54 || max_ext_rate > 0) && ht)
2834 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BGN;
2836 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2837 } else if (freq >= 5180 && freq <= 5825) { /* 5 Ghz Band */
2838 if (max_rate <= 54 && !ht)
2839 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211A;
2840 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && !vht)
2841 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211AN;
2842 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && vht)
2843 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211ANAC;
2845 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2850 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
2852 struct g_supplicant_bss *bss = user_data;
2853 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
2854 unsigned char *ie, *ie_end;
2855 DBusMessageIter array;
2858 #if defined TIZEN_EXT
2859 const unsigned char OWE_WFA_OUI[] = { 0x50, 0x6f, 0x9a, 0x1c };
2861 unsigned char *rates = NULL;
2862 unsigned char *ext_rates = NULL;
2863 unsigned int max_rate = 0;
2864 unsigned int max_ext_rate = 0;
2869 #define WMM_WPA1_WPS_INFO 221
2870 #define WPS_INFO_MIN_LEN 6
2871 #define WPS_VERSION_TLV 0x104A
2872 #define WPS_STATE_TLV 0x1044
2873 #define WPS_METHODS_TLV 0x1012
2874 #define WPS_REGISTRAR_TLV 0x1041
2875 #define WPS_VERSION 0x10
2876 #define WPS_PBC 0x04
2877 #define WPS_PIN 0x00
2878 #define WPS_CONFIGURED 0x02
2879 #if defined TIZEN_EXT
2880 #define VENDOR_SPECIFIC_INFO 0xDD
2881 #define WLAN_EID_COUNTRY 7
2884 dbus_message_iter_recurse(iter, &array);
2885 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
2887 if (!ie || ie_len < 2)
2890 bss->wps_capabilities = 0;
2893 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
2895 #if defined TIZEN_EXT
2896 unsigned char *vsie;
2899 if(ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, OWE_WFA_OUI, sizeof(OWE_WFA_OUI)) == 0) {
2900 SUPPLICANT_DBG("IE: match vendor specific data : OWE Transition Mode");
2903 Tag: Vendor Specific: Wi-Fi Alliance: OWE Transition Mode
2904 Tag Number: Vendor Specific (221) -> ie[0]
2905 Tag length: 26 -> ie[1]
2906 OUI: 50:6f:9a (Wi-Fi Alliance) -> ie[2]
2907 Vendor Specific OUI Type: 28 -> ie[5]
2908 BSSID: 92:fd:f0:20:2b:09 -> ie[6]
2909 SSID length: 15 -> ie[12]
2910 SSID: Wi-Fi-5.2.3-owe -> ie[13]
2912 0000 dd 1a 50 6f 9a 1c 92 fd f0 20 2b 09 0f 57 69 2d ..Po..... +..Wi-
2913 0010 46 69 2d 35 2e 32 2e 33 2d 6f 77 65 Fi-5.2.3-owe
2916 bss->owe_transition_mode = TRUE;
2917 if (ie[1] >= 11) { // Tag length is at least up to ssid length position.
2918 memcpy(bss->transition_mode_bssid, ie+6, WIFI_BSSID_LEN_MAX);
2919 if (ie[12] > 0 && ie[12] < 32) {
2920 memcpy(bss->transition_mode_ssid, ie+13, ie[12]);
2921 bss->transition_mode_ssid_len = ie[12];
2923 bss->transition_mode_ssid_len = 0;
2925 bss->owe_transition_mode = FALSE;
2929 if(ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
2930 SUPPLICANT_DBG("IE: match vendor specific data");
2932 vsie_len = ie[1]+2; // tag number size(1), tag length size(1)
2933 vsie = (unsigned char *)g_try_malloc0(vsie_len);
2936 memcpy(vsie, ie, vsie_len);
2937 bss->vsie_list = g_slist_append(bss->vsie_list, vsie);
2939 SUPPLICANT_DBG("Failed to allocate memory");
2943 if(ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
2944 /* Add country code only if it is a valid alphabet */
2945 if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
2946 memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
2951 if (ie[0] == WLAN_EID_HT_CAP && ie[1]) {
2956 if (ie[0] == WLAN_EID_VHT_CAP && ie[1]) {
2961 if (ie[0] == WLAN_EID_SUPP_RATES && ie[1]) {
2963 rates = g_malloc0(r_len);
2967 for (j = 0; ie && j < r_len; j++) {
2968 rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
2969 if (max_rate < rates[j])
2970 max_rate = rates[j];
2975 if (ie[0] == WLAN_EID_EXT_SUPP_RATES && ie[1] > 0) {
2977 ext_rates = g_malloc0(r_len);
2981 for (j = 0; ie && j < r_len; j++) {
2982 ext_rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
2983 if (max_ext_rate < ext_rates[j])
2984 max_ext_rate = ext_rates[j];
2989 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
2990 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
2993 SUPPLICANT_DBG("IE: match WPS_OUI");
2995 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
2996 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
2998 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
3000 if (value == WPS_CONFIGURED)
3001 bss->wps_capabilities |=
3002 G_SUPPLICANT_WPS_CONFIGURED;
3005 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
3007 if (GUINT16_FROM_BE(value) == WPS_PBC)
3008 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3009 if (GUINT16_FROM_BE(value) == WPS_PIN)
3010 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3012 bss->wps_capabilities |=
3013 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
3015 /* If the AP sends this it means it's advertizing
3016 * as a registrar and the WPS process is launched
3018 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
3019 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
3021 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
3024 get_bss_phy_mode(max_rate, max_ext_rate, ht, vht, user_data);
3032 static void bss_compute_security(struct g_supplicant_bss *bss)
3035 * Combining RSN and WPA keymgmt
3036 * We combine it since parsing IEs might have set something for WPS. */
3037 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
3039 bss->ieee8021x = FALSE;
3041 #if defined TIZEN_EXT
3042 bss->ft_ieee8021x = FALSE;
3043 bss->ft_psk = FALSE;
3046 #if defined TIZEN_EXT
3048 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3049 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3050 bss->ieee8021x = TRUE;
3051 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
3052 bss->ft_ieee8021x = TRUE;
3055 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3056 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
3057 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3058 bss->ieee8021x = TRUE;
3061 #if defined TIZEN_EXT
3063 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3064 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3066 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
3070 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3071 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
3072 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3076 #if defined TIZEN_EXT
3077 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
3079 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_OWE)
3081 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_DPP)
3086 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3088 bss->security = G_SUPPLICANT_SECURITY_PSK;
3089 #if defined TIZEN_EXT
3090 else if (bss->ft_psk)
3091 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
3092 else if (bss->ft_ieee8021x == TRUE)
3093 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3095 bss->security = G_SUPPLICANT_SECURITY_SAE;
3096 else if (bss->owe || bss->owe_transition_mode)
3097 bss->security = G_SUPPLICANT_SECURITY_OWE;
3099 bss->security = G_SUPPLICANT_SECURITY_DPP;
3101 else if (bss->privacy)
3102 bss->security = G_SUPPLICANT_SECURITY_WEP;
3104 bss->security = G_SUPPLICANT_SECURITY_NONE;
3108 static void bss_property(const char *key, DBusMessageIter *iter,
3111 struct g_supplicant_bss *bss = user_data;
3113 if (!bss->interface)
3116 SUPPLICANT_DBG("key %s", key);
3121 if (g_strcmp0(key, "BSSID") == 0) {
3122 DBusMessageIter array;
3123 unsigned char *addr;
3126 dbus_message_iter_recurse(iter, &array);
3127 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
3130 memcpy(bss->bssid, addr, addr_len);
3131 } else if (g_strcmp0(key, "SSID") == 0) {
3132 DBusMessageIter array;
3133 unsigned char *ssid;
3136 dbus_message_iter_recurse(iter, &array);
3137 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
3139 if (ssid_len > 0 && ssid_len < 33) {
3140 memcpy(bss->ssid, ssid, ssid_len);
3141 bss->ssid_len = ssid_len;
3143 memset(bss->ssid, 0, sizeof(bss->ssid));
3146 } else if (g_strcmp0(key, "Capabilities") == 0) {
3147 dbus_uint16_t capabilities = 0x0000;
3149 dbus_message_iter_get_basic(iter, &capabilities);
3151 if (capabilities & IEEE80211_CAP_ESS)
3152 bss->mode = G_SUPPLICANT_MODE_INFRA;
3153 else if (capabilities & IEEE80211_CAP_IBSS)
3154 bss->mode = G_SUPPLICANT_MODE_IBSS;
3156 if (capabilities & IEEE80211_CAP_PRIVACY)
3157 bss->privacy = TRUE;
3158 } else if (g_strcmp0(key, "Mode") == 0) {
3159 const char *mode = NULL;
3161 dbus_message_iter_get_basic(iter, &mode);
3162 bss->mode = string2mode(mode);
3163 } else if (g_strcmp0(key, "Frequency") == 0) {
3164 dbus_uint16_t frequency = 0;
3166 dbus_message_iter_get_basic(iter, &frequency);
3167 bss->frequency = frequency;
3168 } else if (g_strcmp0(key, "Signal") == 0) {
3169 dbus_int16_t signal = 0;
3171 dbus_message_iter_get_basic(iter, &signal);
3173 bss->signal = signal;
3175 bss->signal = BSS_UNKNOWN_STRENGTH;
3177 } else if (g_strcmp0(key, "Level") == 0) {
3178 dbus_int32_t level = 0;
3180 dbus_message_iter_get_basic(iter, &level);
3181 } else if (g_strcmp0(key, "Rates") == 0) {
3182 supplicant_dbus_array_foreach(iter, bss_rates, bss);
3183 } else if (g_strcmp0(key, "MaxRate") == 0) {
3184 dbus_uint32_t maxrate = 0;
3186 dbus_message_iter_get_basic(iter, &maxrate);
3188 bss->maxrate = maxrate;
3189 } else if (g_strcmp0(key, "Privacy") == 0) {
3190 dbus_bool_t privacy = FALSE;
3192 dbus_message_iter_get_basic(iter, &privacy);
3193 bss->privacy = privacy;
3194 } else if (g_strcmp0(key, "RSN") == 0) {
3195 bss->rsn_selected = TRUE;
3197 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3198 } else if (g_strcmp0(key, "WPA") == 0) {
3199 bss->rsn_selected = FALSE;
3201 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3202 #if defined TIZEN_EXT
3203 } else if (g_strcmp0(key, "HS20") == 0) {
3204 dbus_bool_t hs20 = FALSE;
3205 dbus_message_iter_get_basic(iter, &hs20);
3208 } else if (g_strcmp0(key, "IEs") == 0)
3209 bss_process_ies(iter, bss);
3211 SUPPLICANT_DBG("key %s type %c",
3212 key, dbus_message_iter_get_arg_type(iter));
3215 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
3218 GSupplicantInterface *interface = user_data;
3219 GSupplicantNetwork *network;
3220 struct g_supplicant_bss *bss;
3221 const char *path = NULL;
3225 dbus_message_iter_get_basic(iter, &path);
3229 if (g_strcmp0(path, "/") == 0)
3232 SUPPLICANT_DBG("%s", path);
3234 network = g_hash_table_lookup(interface->bss_mapping, path);
3236 bss = g_hash_table_lookup(network->bss_table, path);
3241 bss = g_try_new0(struct g_supplicant_bss, 1);
3245 bss->interface = interface;
3246 bss->path = g_strdup(path);
3247 bss->signal = BSS_UNKNOWN_STRENGTH;
3252 static void interface_bss_added_with_keys(DBusMessageIter *iter,
3255 struct g_supplicant_bss *bss;
3259 bss = interface_bss_added(iter, user_data);
3263 dbus_message_iter_next(iter);
3265 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
3266 #if defined TIZEN_EXT
3276 supplicant_dbus_property_foreach(iter, bss_property, bss);
3278 bss_compute_security(bss);
3279 if (add_or_replace_bss_to_network(bss) < 0)
3280 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3283 static void interface_bss_added_without_keys(DBusMessageIter *iter,
3286 struct g_supplicant_bss *bss;
3290 bss = interface_bss_added(iter, user_data);
3294 supplicant_dbus_property_get_all(bss->path,
3295 SUPPLICANT_INTERFACE ".BSS",
3296 bss_property, bss, bss);
3298 bss_compute_security(bss);
3299 if (add_or_replace_bss_to_network(bss) < 0)
3300 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3303 static void update_signal(gpointer key, gpointer value,
3306 struct g_supplicant_bss *bss = value;
3307 GSupplicantNetwork *network = user_data;
3309 #if defined TIZEN_EXT
3310 if (!network->best_bss || (network->best_bss == bss)) {
3311 if (bss->signal > network->signal) {
3312 network->signal = bss->signal;
3313 network->best_bss = bss;
3318 update_best_bss(network, bss, network->best_bss);
3320 if (bss->signal > network->signal) {
3321 network->signal = bss->signal;
3322 network->best_bss = bss;
3327 static void update_network_signal(GSupplicantNetwork *network)
3329 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
3332 g_hash_table_foreach(network->bss_table,
3333 update_signal, network);
3335 SUPPLICANT_DBG("New network signal %d", network->signal);
3338 #if defined TIZEN_EXT
3339 static gboolean last_connected_timeout(gpointer data)
3341 GSupplicantInterface *interface = data;
3342 GSupplicantNetwork *current_network = interface->current_network;
3344 SUPPLICANT_DBG("Timeout last connected bss");
3346 if (current_network && current_network->best_bss) {
3347 if (compare_bssid(current_network->best_bss->bssid, interface->connected_bssid)) {
3348 g_supplicant_network_set_last_connected_bssid(current_network, interface->connected_bssid);
3349 callback_network_changed(current_network, "LastConnectedBSSID");
3353 last_connected_bss_timeout = 0;
3357 static void add_timer_for_last_connected(GSupplicantInterface *interface)
3359 GSupplicantNetwork *current_network = interface->current_network;
3361 if (interface->state == G_SUPPLICANT_STATE_COMPLETED) {
3362 if (current_network) {
3363 struct g_supplicant_bss *best_bss = current_network->best_bss;
3365 memcpy(interface->connected_bssid, best_bss->bssid, WIFI_BSSID_LEN_MAX);
3367 if (last_connected_bss_timeout)
3368 g_source_remove(last_connected_bss_timeout);
3370 last_connected_bss_timeout = g_timeout_add_seconds(LAST_CONNECTED_TIMEOUT,
3371 last_connected_timeout, interface);
3373 SUPPLICANT_DBG("Add timer for last connected bssid [" MACSTR "]",
3374 MAC2STR(best_bss->bssid));
3379 static void remove_timer_for_last_connected(GSupplicantInterface *interface)
3381 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED) {
3382 if (last_connected_bss_timeout != 0) {
3383 g_source_remove(last_connected_bss_timeout);
3384 last_connected_bss_timeout = 0;
3385 SUPPLICANT_DBG("Remove timer for last connected bss");
3391 static void interface_current_bss(GSupplicantInterface *interface,
3392 DBusMessageIter *iter)
3394 GSupplicantNetwork *network;
3395 struct g_supplicant_bss *bss;
3398 dbus_message_iter_get_basic(iter, &path);
3399 if (g_strcmp0(path, "/") == 0) {
3400 interface->current_network = NULL;
3404 interface_bss_added_without_keys(iter, interface);
3406 network = g_hash_table_lookup(interface->bss_mapping, path);
3410 bss = g_hash_table_lookup(network->bss_table, path);
3414 interface->current_network = network;
3415 #if defined TIZEN_EXT
3416 SUPPLICANT_DBG("current network [%p]", interface->current_network);
3419 if (bss != network->best_bss) {
3421 * This is the case where either wpa_s got associated
3422 * to a BSS different than the one ConnMan considers
3423 * the best, or we are roaming.
3425 SUPPLICANT_DBG("Update best BSS for %s", network->name);
3427 network->best_bss = bss;
3429 if (network->signal != bss->signal) {
3430 SUPPLICANT_DBG("New network signal %d dBm",
3433 network->signal = bss->signal;
3434 callback_network_changed(network, "Signal");
3439 * wpa_s could notify about CurrentBSS in any state once
3440 * it got associated. It is not sure such notification will
3441 * arrive together with transition to ASSOCIATED state.
3442 * In fact, for networks with security WEP or OPEN, it
3443 * always arrives together with transition to COMPLETED.
3445 switch (interface->state) {
3446 case G_SUPPLICANT_STATE_UNKNOWN:
3447 case G_SUPPLICANT_STATE_DISABLED:
3448 case G_SUPPLICANT_STATE_DISCONNECTED:
3449 case G_SUPPLICANT_STATE_INACTIVE:
3450 case G_SUPPLICANT_STATE_SCANNING:
3451 case G_SUPPLICANT_STATE_AUTHENTICATING:
3452 case G_SUPPLICANT_STATE_ASSOCIATING:
3454 case G_SUPPLICANT_STATE_ASSOCIATED:
3455 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
3456 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
3457 case G_SUPPLICANT_STATE_COMPLETED:
3458 callback_network_associated(network);
3459 #if defined TIZEN_EXT
3460 add_timer_for_last_connected(interface);
3466 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
3468 GSupplicantInterface *interface = user_data;
3469 GSupplicantNetwork *network;
3470 struct g_supplicant_bss *bss = NULL;
3471 const char *path = NULL;
3472 bool is_current_network_bss = false;
3474 dbus_message_iter_get_basic(iter, &path);
3478 network = g_hash_table_lookup(interface->bss_mapping, path);
3482 bss = g_hash_table_lookup(network->bss_table, path);
3483 if (network->best_bss == bss) {
3484 network->best_bss = NULL;
3485 network->signal = BSS_UNKNOWN_STRENGTH;
3486 is_current_network_bss = true;
3489 g_hash_table_remove(bss_mapping, path);
3491 g_hash_table_remove(interface->bss_mapping, path);
3492 g_hash_table_remove(network->bss_table, path);
3494 update_network_signal(network);
3496 if (g_hash_table_size(network->bss_table) == 0) {
3497 g_hash_table_remove(interface->network_table, network->group);
3499 if (is_current_network_bss && network->best_bss)
3500 #if defined TIZEN_EXT
3501 callback_network_changed(network, "CheckMultiBssidConnect");
3503 callback_network_changed(network, "");
3508 static void set_config_methods(DBusMessageIter *iter, void *user_data)
3510 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
3513 static void wps_property(const char *key, DBusMessageIter *iter,
3516 GSupplicantInterface *interface = user_data;
3521 SUPPLICANT_DBG("key: %s", key);
3523 if (g_strcmp0(key, "ConfigMethods") == 0) {
3524 const char *config_methods = "push_button", *str = NULL;
3526 dbus_message_iter_get_basic(iter, &str);
3527 if (str && strlen(str) > 0) {
3528 /* It was already set at wpa_s level, don't modify it. */
3529 SUPPLICANT_DBG("%s", str);
3533 supplicant_dbus_property_set(interface->path,
3534 SUPPLICANT_INTERFACE ".Interface.WPS",
3535 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
3536 set_config_methods, NULL, &config_methods, NULL);
3538 SUPPLICANT_DBG("No value. Set %s", config_methods);
3543 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3544 void g_supplicant_replace_config_file(const char *ifname, const char *config_file)
3552 SUPPLICANT_DBG("New {%s, %s}", ifname, config_file);
3553 g_hash_table_replace(config_file_table,
3554 g_strdup(ifname), g_strdup(config_file));
3556 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3558 static void interface_property(const char *key, DBusMessageIter *iter,
3561 GSupplicantInterface *interface = user_data;
3566 SUPPLICANT_DBG("%s", key);
3569 debug_strvalmap("KeyMgmt capability", keymgmt_map,
3570 interface->keymgmt_capa);
3571 debug_strvalmap("AuthAlg capability", authalg_capa_map,
3572 interface->authalg_capa);
3573 debug_strvalmap("Protocol capability", proto_capa_map,
3574 interface->proto_capa);
3575 debug_strvalmap("Pairwise capability", pairwise_map,
3576 interface->pairwise_capa);
3577 debug_strvalmap("Group capability", group_map,
3578 interface->group_capa);
3579 debug_strvalmap("Scan capability", scan_capa_map,
3580 interface->scan_capa);
3581 debug_strvalmap("Mode capability", mode_capa_map,
3582 interface->mode_capa);
3584 supplicant_dbus_property_get_all(interface->path,
3585 SUPPLICANT_INTERFACE ".Interface.WPS",
3586 wps_property, interface, interface);
3588 if (interface->ready)
3589 callback_interface_added(interface);
3594 if (g_strcmp0(key, "Capabilities") == 0) {
3595 supplicant_dbus_property_foreach(iter, interface_capability,
3597 #if !defined TIZEN_EXT
3598 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
3599 interface->p2p_support = true;
3601 #if defined TIZEN_EXT_WIFI_MESH
3602 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_MESH)
3603 interface->mesh_support = true;
3605 } else if (g_strcmp0(key, "State") == 0) {
3606 const char *str = NULL;
3608 dbus_message_iter_get_basic(iter, &str);
3610 if (string2state(str) != interface->state) {
3611 interface->state = string2state(str);
3612 callback_interface_state(interface);
3614 #if defined TIZEN_EXT
3615 switch (interface->state) {
3616 case G_SUPPLICANT_STATE_COMPLETED:
3617 add_timer_for_last_connected(interface);
3619 case G_SUPPLICANT_STATE_DISCONNECTED:
3620 remove_timer_for_last_connected(interface);
3626 if (interface->ap_create_in_progress) {
3627 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
3628 callback_ap_create_fail(interface);
3630 interface->ap_create_in_progress = false;
3633 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
3634 interface->ready = FALSE;
3636 interface->ready = TRUE;
3638 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
3639 } else if (g_strcmp0(key, "Scanning") == 0) {
3640 dbus_bool_t scanning = FALSE;
3642 dbus_message_iter_get_basic(iter, &scanning);
3643 interface->scanning = scanning;
3645 if (interface->ready) {
3646 if (interface->scanning)
3647 callback_scan_started(interface);
3649 callback_scan_finished(interface);
3651 } else if (g_strcmp0(key, "ApScan") == 0) {
3654 dbus_message_iter_get_basic(iter, &apscan);
3655 interface->apscan = apscan;
3656 } else if (g_strcmp0(key, "Ifname") == 0) {
3657 const char *str = NULL;
3659 dbus_message_iter_get_basic(iter, &str);
3661 g_free(interface->ifname);
3662 interface->ifname = g_strdup(str);
3664 } else if (g_strcmp0(key, "Driver") == 0) {
3665 const char *str = NULL;
3667 dbus_message_iter_get_basic(iter, &str);
3669 g_free(interface->driver);
3670 interface->driver = g_strdup(str);
3672 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
3673 const char *str = NULL;
3675 dbus_message_iter_get_basic(iter, &str);
3677 g_free(interface->bridge);
3678 interface->bridge = g_strdup(str);
3680 } else if (g_strcmp0(key, "ConfigFile") == 0) {
3681 const char *str = NULL;
3683 dbus_message_iter_get_basic(iter, &str);
3684 if (str && strlen(str) > 0 && interface->ifname) {
3685 SUPPLICANT_DBG("New {%s, %s}", interface->ifname, str);
3686 g_hash_table_replace(config_file_table,
3687 g_strdup(interface->ifname), g_strdup(str));
3689 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
3690 interface_current_bss(interface, iter);
3691 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
3692 #if defined TIZEN_EXT
3693 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
3695 interface_network_added(iter, interface);
3696 } else if (g_strcmp0(key, "BSSs") == 0) {
3697 supplicant_dbus_array_foreach(iter,
3698 interface_bss_added_without_keys,
3700 } else if (g_strcmp0(key, "Blobs") == 0) {
3702 } else if (g_strcmp0(key, "Networks") == 0) {
3703 supplicant_dbus_array_foreach(iter, interface_network_added,
3705 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
3707 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3708 dbus_message_iter_get_basic(iter, &reason_code);
3709 callback_disconnect_reason_code(interface, reason_code);
3710 #if defined TIZEN_EXT
3711 SUPPLICANT_DBG("reason code (%d)", reason_code);
3714 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
3716 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3717 dbus_message_iter_get_basic(iter, &status_code);
3718 callback_assoc_status_code(interface, status_code);
3719 #if defined TIZEN_EXT
3720 SUPPLICANT_DBG("status code (%d)", status_code);
3724 SUPPLICANT_DBG("key %s type %c",
3725 key, dbus_message_iter_get_arg_type(iter));
3729 static void scan_network_update(DBusMessageIter *iter, void *user_data)
3731 GSupplicantInterface *interface = user_data;
3732 GSupplicantNetwork *network;
3738 dbus_message_iter_get_basic(iter, &path);
3743 if (g_strcmp0(path, "/") == 0)
3746 /* Update the network details based on scan BSS data */
3747 network = g_hash_table_lookup(interface->bss_mapping, path);
3749 callback_network_added(network);
3752 static void scan_bss_data(const char *key, DBusMessageIter *iter,
3755 GSupplicantInterface *interface = user_data;
3757 /*Fixed : stucking in scanning state when scan failed*/
3758 #if defined TIZEN_EXT
3759 GSupplicantInterfaceCallback scan_callback;
3764 supplicant_dbus_array_foreach(iter, scan_network_update,
3767 #if defined TIZEN_EXT
3768 scan_callback = interface->scan_callback;
3769 callback_scan_done(interface);
3772 if (interface->scan_callback)
3773 interface->scan_callback(0, interface, interface->scan_data);
3775 #if defined TIZEN_EXT
3776 if (interface->scan_callback == scan_callback) {
3778 interface->scan_callback = NULL;
3779 interface->scan_data = NULL;
3780 #if defined TIZEN_EXT
3785 static GSupplicantInterface *interface_alloc(const char *path)
3787 GSupplicantInterface *interface;
3789 interface = g_try_new0(GSupplicantInterface, 1);
3793 interface->path = g_strdup(path);
3795 interface->network_table = g_hash_table_new_full(g_str_hash,
3796 g_str_equal, NULL, remove_network);
3797 interface->peer_table = g_hash_table_new_full(g_str_hash,
3798 g_str_equal, NULL, remove_peer);
3799 interface->group_table = g_hash_table_new_full(g_str_hash,
3800 g_str_equal, NULL, remove_group);
3801 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
3804 g_hash_table_replace(interface_table, interface->path, interface);
3809 static void interface_added(DBusMessageIter *iter, void *user_data)
3811 GSupplicantInterface *interface;
3812 const char *path = NULL;
3813 bool properties_appended = GPOINTER_TO_UINT(user_data);
3817 dbus_message_iter_get_basic(iter, &path);
3821 if (g_strcmp0(path, "/") == 0)
3824 interface = g_hash_table_lookup(interface_table, path);
3828 interface = interface_alloc(path);
3832 if (!properties_appended) {
3833 supplicant_dbus_property_get_all(path,
3834 SUPPLICANT_INTERFACE ".Interface",
3835 interface_property, interface,
3840 dbus_message_iter_next(iter);
3841 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3842 supplicant_dbus_property_foreach(iter, interface_property,
3844 interface_property(NULL, NULL, interface);
3848 static void interface_removed(DBusMessageIter *iter, void *user_data)
3850 const char *path = NULL;
3851 GSupplicantInterface *interface = user_data;
3853 dbus_message_iter_get_basic(iter, &path);
3857 interface = g_hash_table_lookup(interface_table, path);
3858 g_supplicant_interface_cancel(interface);
3860 g_hash_table_remove(interface_table, path);
3863 static void eap_method(DBusMessageIter *iter, void *user_data)
3865 const char *str = NULL;
3868 dbus_message_iter_get_basic(iter, &str);
3872 for (i = 0; eap_method_map[i].str; i++)
3873 if (strcmp(str, eap_method_map[i].str) == 0) {
3874 eap_methods |= eap_method_map[i].val;
3879 static void service_property(const char *key, DBusMessageIter *iter,
3883 callback_system_ready();
3887 if (g_strcmp0(key, "DebugLevel") == 0) {
3888 const char *str = NULL;
3891 dbus_message_iter_get_basic(iter, &str);
3892 for (i = 0; debug_strings[i]; i++)
3893 if (g_strcmp0(debug_strings[i], str) == 0) {
3897 SUPPLICANT_DBG("Debug level %d", debug_level);
3898 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
3899 dbus_message_iter_get_basic(iter, &debug_timestamp);
3900 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
3901 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
3902 dbus_message_iter_get_basic(iter, &debug_showkeys);
3903 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
3904 } else if (g_strcmp0(key, "Interfaces") == 0) {
3905 supplicant_dbus_array_foreach(iter, interface_added, NULL);
3906 } else if (g_strcmp0(key, "EapMethods") == 0) {
3907 supplicant_dbus_array_foreach(iter, eap_method, NULL);
3908 debug_strvalmap("EAP method", eap_method_map, eap_methods);
3909 } else if (g_strcmp0(key, "Country") == 0) {
3910 const char *country = NULL;
3912 dbus_message_iter_get_basic(iter, &country);
3913 SUPPLICANT_DBG("Country %s", country);
3915 SUPPLICANT_DBG("key %s type %c",
3916 key, dbus_message_iter_get_arg_type(iter));
3919 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
3921 const char *name = NULL, *old = NULL, *new = NULL;
3925 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
3928 dbus_message_iter_get_basic(iter, &name);
3932 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
3935 dbus_message_iter_next(iter);
3936 dbus_message_iter_get_basic(iter, &old);
3937 dbus_message_iter_next(iter);
3938 dbus_message_iter_get_basic(iter, &new);
3943 if (strlen(old) > 0 && strlen(new) == 0) {
3944 system_available = FALSE;
3945 g_hash_table_remove_all(bss_mapping);
3946 g_hash_table_remove_all(peer_mapping);
3947 g_hash_table_remove_all(group_mapping);
3948 g_hash_table_remove_all(config_file_table);
3949 g_hash_table_remove_all(interface_table);
3950 callback_system_killed();
3953 if (strlen(new) > 0 && strlen(old) == 0) {
3954 system_available = TRUE;
3955 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
3956 SUPPLICANT_INTERFACE,
3957 service_property, NULL, NULL);
3961 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
3965 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
3968 supplicant_dbus_property_foreach(iter, service_property, NULL);
3971 static void signal_interface_added(const char *path, DBusMessageIter *iter)
3973 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
3975 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
3976 interface_added(iter, GUINT_TO_POINTER(true));
3979 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
3983 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
3984 interface_removed(iter, NULL);
3987 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
3989 GSupplicantInterface *interface;
3993 interface = g_hash_table_lookup(interface_table, path);
3997 supplicant_dbus_property_foreach(iter, interface_property, interface);
4000 static void signal_scan_done(const char *path, DBusMessageIter *iter)
4002 GSupplicantInterface *interface;
4003 dbus_bool_t success = FALSE;
4007 interface = g_hash_table_lookup(interface_table, path);
4011 dbus_message_iter_get_basic(iter, &success);
4013 if (interface->scanning) {
4014 callback_scan_finished(interface);
4015 interface->scanning = FALSE;
4019 * If scan is unsuccessful return -EIO else get the scanned BSSs
4020 * and update the network details accordingly
4023 if (interface->scan_callback)
4024 interface->scan_callback(-EIO, interface,
4025 interface->scan_data);
4027 interface->scan_callback = NULL;
4028 interface->scan_data = NULL;
4033 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
4034 "BSSs", scan_bss_data, interface, interface);
4037 static void signal_bss_added(const char *path, DBusMessageIter *iter)
4039 GSupplicantInterface *interface;
4043 interface = g_hash_table_lookup(interface_table, path);
4047 interface_bss_added_with_keys(iter, interface);
4050 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
4052 GSupplicantInterface *interface;
4056 interface = g_hash_table_lookup(interface_table, path);
4060 interface_bss_removed(iter, interface);
4063 static void signal_network_added(const char *path, DBusMessageIter *iter)
4065 GSupplicantInterface *interface;
4069 interface = g_hash_table_lookup(interface_table, path);
4073 interface_network_added(iter, interface);
4076 static void signal_network_removed(const char *path, DBusMessageIter *iter)
4078 GSupplicantInterface *interface;
4082 interface = g_hash_table_lookup(interface_table, path);
4086 interface_network_removed(iter, interface);
4088 #if defined TIZEN_EXT
4089 void *copy_vsie_list(gconstpointer src, gpointer data)
4091 return g_strdup(src);
4096 static void signal_sta_authorized(const char *path, DBusMessageIter *iter)
4098 GSupplicantInterface *interface;
4099 const char *addr = NULL;
4103 interface = g_hash_table_lookup(interface_table, path);
4107 dbus_message_iter_get_basic(iter, &addr);
4111 callback_sta_authorized(interface, addr);
4114 static void signal_sta_deauthorized(const char *path, DBusMessageIter *iter)
4116 GSupplicantInterface *interface;
4117 const char *addr = NULL;
4121 interface = g_hash_table_lookup(interface_table, path);
4125 dbus_message_iter_get_basic(iter, &addr);
4129 callback_sta_deauthorized(interface, addr);
4132 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4133 static void signal_eap(const char *path, DBusMessageIter *iter)
4135 GSupplicantInterface *interface;
4136 const char *str = NULL;
4138 SUPPLICANT_DBG("EAPOL_DEBUG callback eap signal");
4140 interface = g_hash_table_lookup(interface_table, path);
4144 // TODO: Identify EAP fail condition, currently timeout is used for failure.
4146 dbus_message_iter_get_basic(iter, &str);
4150 if (g_strcmp0("completion", str))
4153 dbus_message_iter_next(iter);
4155 dbus_message_iter_get_basic(iter, &str);
4159 if (!g_strcmp0("success", str))
4160 callback_eap(interface, true);
4162 callback_eap(interface, false);
4164 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4166 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
4168 GSupplicantInterface *interface;
4169 GSupplicantNetwork *network;
4170 GSupplicantSecurity old_security;
4171 unsigned int old_wps_capabilities;
4172 struct g_supplicant_bss *bss;
4176 interface = g_hash_table_lookup(bss_mapping, path);
4180 network = g_hash_table_lookup(interface->bss_mapping, path);
4184 bss = g_hash_table_lookup(network->bss_table, path);
4188 supplicant_dbus_property_foreach(iter, bss_property, bss);
4190 #if defined TIZEN_EXT
4191 network->frequency = bss->frequency;
4192 network->phy_mode = bss->phy_mode;
4194 old_security = network->security;
4195 bss_compute_security(bss);
4197 if (old_security != bss->security) {
4198 struct g_supplicant_bss *new_bss;
4200 SUPPLICANT_DBG("New network security for %s with path %s",
4201 bss->ssid, bss->path);
4204 * Security change policy:
4205 * - We first copy the current bss into a new one with
4206 * its own pointer (path)
4207 * - Clear the old bss pointer and remove the network completely
4208 * if there are no more BSSs in the bss table.
4209 * - The new bss will be added either to an existing network
4210 * or an additional network will be created
4213 new_bss = g_try_new0(struct g_supplicant_bss, 1);
4217 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
4218 new_bss->path = g_strdup(bss->path);
4219 #if defined TIZEN_EXT
4220 new_bss->vsie_list = g_slist_copy_deep(bss->vsie_list, copy_vsie_list, NULL);
4223 if (network->best_bss == bss) {
4224 network->best_bss = NULL;
4225 network->signal = BSS_UNKNOWN_STRENGTH;
4228 g_hash_table_remove(bss_mapping, path);
4230 g_hash_table_remove(interface->bss_mapping, path);
4231 g_hash_table_remove(network->bss_table, path);
4233 update_network_signal(network);
4235 if (g_hash_table_size(network->bss_table) == 0)
4236 g_hash_table_remove(interface->network_table,
4239 if (add_or_replace_bss_to_network(new_bss) < 0) {
4241 * Prevent a memory leak on failure in
4242 * add_or_replace_bss_to_network
4244 SUPPLICANT_DBG("Failed to add bss %s to network table",
4246 g_free(new_bss->path);
4253 old_wps_capabilities = network->wps_capabilities;
4255 if (old_wps_capabilities != bss->wps_capabilities) {
4256 network->wps_capabilities = bss->wps_capabilities;
4257 callback_network_changed(network, "WPSCapabilities");
4260 #if defined TIZEN_EXT
4261 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
4262 network->wps = TRUE;
4263 network->wps_capabilities |= bss->wps_capabilities;
4265 network->wps = FALSE;
4268 /* Consider only property changes of the connected BSS */
4269 if (network == interface->current_network && bss != network->best_bss)
4272 if (bss->signal == network->signal)
4277 callback_network_changed(network, "");
4283 * If the new signal is lower than the SSID signal, we need
4284 * to check for the new maximum.
4286 #if defined TIZEN_EXT
4287 if (!update_best_bss(network, bss, network->best_bss)) {
4288 if (bss != network->best_bss) {
4289 callback_network_changed(network, "");
4293 network->signal = bss->signal;
4294 update_network_signal(network);
4297 if (bss->signal < network->signal) {
4298 if (bss != network->best_bss)
4301 network->signal = bss->signal;
4302 update_network_signal(network);
4304 network->signal = bss->signal;
4305 network->best_bss = bss;
4309 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
4312 callback_network_changed(network, "Signal");
4315 static void wps_credentials(const char *key, DBusMessageIter *iter,
4318 GSupplicantInterface *interface = user_data;
4323 SUPPLICANT_DBG("key %s", key);
4325 if (g_strcmp0(key, "Key") == 0) {
4326 DBusMessageIter array;
4327 unsigned char *key_val;
4330 dbus_message_iter_recurse(iter, &array);
4331 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
4333 g_free(interface->wps_cred.key);
4334 interface->wps_cred.key = g_try_malloc0(
4335 sizeof(char) * key_len + 1);
4337 if (!interface->wps_cred.key)
4340 memcpy(interface->wps_cred.key, key_val,
4341 sizeof(char) * key_len);
4343 SUPPLICANT_DBG("WPS key present");
4344 } else if (g_strcmp0(key, "SSID") == 0) {
4345 DBusMessageIter array;
4346 unsigned char *ssid;
4349 dbus_message_iter_recurse(iter, &array);
4350 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
4352 if (ssid_len > 0 && ssid_len < 33) {
4353 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
4354 interface->wps_cred.ssid_len = ssid_len;
4356 memset(interface->wps_cred.ssid, 0, 32);
4357 interface->wps_cred.ssid_len = 0;
4362 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
4364 GSupplicantInterface *interface;
4368 interface = g_hash_table_lookup(interface_table, path);
4372 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
4375 static void wps_event_args(const char *key, DBusMessageIter *iter,
4378 GSupplicantInterface *interface = user_data;
4380 if (!key || !interface)
4383 SUPPLICANT_DBG("Arg Key %s", key);
4386 static void signal_wps_event(const char *path, DBusMessageIter *iter)
4388 GSupplicantInterface *interface;
4389 const char *name = NULL;
4393 interface = g_hash_table_lookup(interface_table, path);
4397 dbus_message_iter_get_basic(iter, &name);
4399 SUPPLICANT_DBG("Name: %s", name);
4401 if (g_strcmp0(name, "success") == 0)
4402 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
4403 else if (g_strcmp0(name, "fail") == 0)
4404 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
4406 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
4408 if (!dbus_message_iter_has_next(iter))
4411 dbus_message_iter_next(iter);
4413 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
4416 #if defined TIZEN_EXT
4417 static void signal_power_off(const char *path, DBusMessageIter *iter)
4419 int poweroff_state = 0;
4421 dbus_message_iter_get_basic(iter, &poweroff_state);
4423 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
4425 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
4426 if (poweroff_state != 2 && poweroff_state != 3)
4429 if (callbacks_pointer == NULL)
4432 if (callbacks_pointer->system_power_off == NULL)
4435 callbacks_pointer->system_power_off();
4439 static void create_peer_identifier(GSupplicantPeer *peer)
4441 const unsigned char test[ETH_ALEN] = {};
4446 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
4447 peer->identifier = g_strdup(peer->name);
4451 peer->identifier = g_malloc0(19);
4452 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
4453 peer->device_address[0],
4454 peer->device_address[1],
4455 peer->device_address[2],
4456 peer->device_address[3],
4457 peer->device_address[4],
4458 peer->device_address[5]);
4461 struct peer_property_data {
4462 GSupplicantPeer *peer;
4464 bool groups_changed;
4465 bool services_changed;
4468 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
4470 struct peer_property_data *data = user_data;
4471 GSupplicantPeer *peer = data->peer;
4472 GSupplicantGroup *group;
4473 const char *str = NULL;
4476 dbus_message_iter_get_basic(iter, &str);
4480 group = g_hash_table_lookup(group_mapping, str);
4484 elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
4486 data->old_groups = g_slist_remove_link(data->old_groups, elem);
4487 peer->groups = g_slist_concat(elem, peer->groups);
4489 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
4490 data->groups_changed = true;
4494 static void peer_property(const char *key, DBusMessageIter *iter,
4497 GSupplicantPeer *pending_peer;
4498 struct peer_property_data *data = user_data;
4499 GSupplicantPeer *peer = data->peer;
4501 SUPPLICANT_DBG("key: %s", key);
4503 if (!peer->interface)
4508 create_peer_identifier(peer);
4509 callback_peer_found(peer);
4510 pending_peer = g_hash_table_lookup(
4511 pending_peer_connection, peer->path);
4513 if (pending_peer && pending_peer == peer) {
4514 callback_peer_request(peer);
4515 g_hash_table_remove(pending_peer_connection,
4525 if (g_strcmp0(key, "DeviceAddress") == 0) {
4526 unsigned char *dev_addr;
4527 DBusMessageIter array;
4530 dbus_message_iter_recurse(iter, &array);
4531 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4533 if (len == ETH_ALEN)
4534 memcpy(peer->device_address, dev_addr, len);
4535 } else if (g_strcmp0(key, "DeviceName") == 0) {
4536 const char *str = NULL;
4538 dbus_message_iter_get_basic(iter, &str);
4540 peer->name = g_strdup(str);
4541 } else if (g_strcmp0(key, "config_method") == 0) {
4542 uint16_t wps_config;
4544 dbus_message_iter_get_basic(iter, &wps_config);
4546 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
4547 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
4548 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
4549 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
4550 } else if (g_strcmp0(key, "Groups") == 0) {
4551 data->old_groups = peer->groups;
4552 peer->groups = NULL;
4554 supplicant_dbus_array_foreach(iter,
4555 peer_groups_relation, data);
4556 if (g_slist_length(data->old_groups) > 0) {
4557 g_slist_free_full(data->old_groups, g_free);
4558 data->groups_changed = true;
4560 } else if (g_strcmp0(key, "IEs") == 0) {
4561 DBusMessageIter array;
4565 dbus_message_iter_recurse(iter, &array);
4566 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
4568 if (!ie || ie_len < 2)
4571 if (peer->widi_ies) {
4572 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
4575 g_free(peer->widi_ies);
4576 peer->widi_ies_length = 0;
4579 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
4581 memcpy(peer->widi_ies, ie, ie_len);
4582 peer->widi_ies_length = ie_len;
4583 data->services_changed = true;
4587 static void signal_peer_found(const char *path, DBusMessageIter *iter)
4589 struct peer_property_data *property_data;
4590 GSupplicantInterface *interface;
4591 const char *obj_path = NULL;
4592 GSupplicantPeer *peer;
4596 interface = g_hash_table_lookup(interface_table, path);
4600 dbus_message_iter_get_basic(iter, &obj_path);
4601 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4604 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4608 peer = g_try_new0(GSupplicantPeer, 1);
4612 peer->interface = interface;
4613 peer->path = g_strdup(obj_path);
4614 g_hash_table_insert(interface->peer_table, peer->path, peer);
4615 g_hash_table_replace(peer_mapping, peer->path, interface);
4617 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4618 property_data->peer = peer;
4620 dbus_message_iter_next(iter);
4621 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4622 supplicant_dbus_property_foreach(iter, peer_property,
4624 peer_property(NULL, NULL, property_data);
4628 supplicant_dbus_property_get_all(obj_path,
4629 SUPPLICANT_INTERFACE ".Peer",
4630 peer_property, property_data, NULL);
4633 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
4635 GSupplicantInterface *interface;
4636 const char *obj_path = NULL;
4637 GSupplicantPeer *peer;
4641 interface = g_hash_table_lookup(interface_table, path);
4645 dbus_message_iter_get_basic(iter, &obj_path);
4646 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4649 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4653 g_hash_table_remove(interface->peer_table, obj_path);
4656 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
4658 struct peer_property_data *property_data;
4659 GSupplicantInterface *interface;
4660 GSupplicantPeer *peer;
4664 interface = g_hash_table_lookup(peer_mapping, path);
4668 peer = g_hash_table_lookup(interface->peer_table, path);
4670 g_hash_table_remove(peer_mapping, path);
4674 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4675 property_data->peer = peer;
4677 supplicant_dbus_property_foreach(iter, peer_property, property_data);
4678 if (property_data->services_changed)
4679 callback_peer_changed(peer,
4680 G_SUPPLICANT_PEER_SERVICES_CHANGED);
4682 if (property_data->groups_changed)
4683 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
4685 dbus_free(property_data);
4687 if (!g_supplicant_peer_is_in_a_group(peer))
4688 peer->connection_requested = false;
4691 struct group_sig_data {
4692 const char *peer_obj_path;
4693 unsigned char iface_address[ETH_ALEN];
4694 const char *interface_obj_path;
4695 const char *group_obj_path;
4699 static void group_sig_property(const char *key, DBusMessageIter *iter,
4702 struct group_sig_data *data = user_data;
4707 if (g_strcmp0(key, "peer_interface_addr") == 0) {
4708 unsigned char *dev_addr;
4709 DBusMessageIter array;
4712 dbus_message_iter_recurse(iter, &array);
4713 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4715 if (len == ETH_ALEN)
4716 memcpy(data->iface_address, dev_addr, len);
4717 } else if (g_strcmp0(key, "role") == 0) {
4718 const char *str = NULL;
4720 dbus_message_iter_get_basic(iter, &str);
4721 if (g_strcmp0(str, "GO") == 0)
4722 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
4724 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
4725 } else if (g_strcmp0(key, "peer_object") == 0)
4726 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
4727 else if (g_strcmp0(key, "interface_object") == 0)
4728 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
4729 else if (g_strcmp0(key, "group_object") == 0)
4730 dbus_message_iter_get_basic(iter, &data->group_obj_path);
4734 static void signal_group_success(const char *path, DBusMessageIter *iter)
4736 GSupplicantInterface *interface;
4737 struct group_sig_data data = {};
4738 GSupplicantPeer *peer;
4742 interface = g_hash_table_lookup(interface_table, path);
4746 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4747 if (!data.peer_obj_path)
4750 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4754 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
4755 interface->pending_peer_path = peer->path;
4758 static void signal_group_failure(const char *path, DBusMessageIter *iter)
4760 GSupplicantInterface *interface;
4761 struct group_sig_data data = {};
4762 GSupplicantPeer *peer;
4766 interface = g_hash_table_lookup(interface_table, path);
4770 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4771 if (!data.peer_obj_path)
4774 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4778 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
4779 peer->connection_requested = false;
4782 static void signal_group_started(const char *path, DBusMessageIter *iter)
4784 GSupplicantInterface *interface, *g_interface;
4785 struct group_sig_data data = {};
4786 GSupplicantGroup *group;
4787 GSupplicantPeer *peer;
4791 interface = g_hash_table_lookup(interface_table, path);
4795 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4796 if (!data.interface_obj_path || !data.group_obj_path)
4799 peer = g_hash_table_lookup(interface->peer_table,
4800 interface->pending_peer_path);
4801 interface->pending_peer_path = NULL;
4805 g_interface = g_hash_table_lookup(interface_table,
4806 data.interface_obj_path);
4810 group = g_hash_table_lookup(interface->group_table,
4811 data.group_obj_path);
4815 group = g_try_new0(GSupplicantGroup, 1);
4819 group->interface = g_interface;
4820 group->orig_interface = interface;
4821 group->path = g_strdup(data.group_obj_path);
4822 group->role = data.role;
4824 g_hash_table_insert(interface->group_table, group->path, group);
4825 g_hash_table_replace(group_mapping, group->path, group);
4827 peer->current_group_iface = g_interface;
4828 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
4831 static void remove_peer_group_interface(GHashTable *group_table,
4834 GSupplicantGroup *group;
4835 GHashTableIter iter;
4836 gpointer value, key;
4841 group = g_hash_table_lookup(group_table, path);
4843 if (!group || !group->orig_interface)
4846 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
4848 while (g_hash_table_iter_next(&iter, &key, &value)) {
4849 GSupplicantPeer *peer = value;
4851 if (peer->current_group_iface == group->interface)
4852 peer->current_group_iface = NULL;
4856 static void signal_group_finished(const char *path, DBusMessageIter *iter)
4858 GSupplicantInterface *interface;
4859 struct group_sig_data data = {};
4863 interface = g_hash_table_lookup(interface_table, path);
4867 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4868 if (!data.interface_obj_path || !data.group_obj_path)
4871 remove_peer_group_interface(interface->group_table, data.group_obj_path);
4873 g_hash_table_remove(group_mapping, data.group_obj_path);
4875 g_hash_table_remove(interface->group_table, data.group_obj_path);
4878 static void signal_group_request(const char *path, DBusMessageIter *iter)
4880 GSupplicantInterface *interface;
4881 GSupplicantPeer *peer;
4882 const char *obj_path;
4886 interface = g_hash_table_lookup(interface_table, path);
4890 dbus_message_iter_get_basic(iter, &obj_path);
4891 if (!obj_path || !g_strcmp0(obj_path, "/"))
4894 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4899 * Peer has been previously found and property set,
4900 * otherwise, defer connection to when peer property
4903 if (peer->identifier)
4904 callback_peer_request(peer);
4906 g_hash_table_replace(pending_peer_connection, peer->path, peer);
4909 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
4911 const char *peer_path = NULL;
4912 GSupplicantInterface *interface;
4913 GSupplicantGroup *group;
4914 GSupplicantPeer *peer;
4918 group = g_hash_table_lookup(group_mapping, path);
4922 dbus_message_iter_get_basic(iter, &peer_path);
4926 interface = g_hash_table_lookup(peer_mapping, peer_path);
4930 peer = g_hash_table_lookup(interface->peer_table, peer_path);
4934 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
4936 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
4939 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
4941 const char *peer_path = NULL;
4942 GSupplicantInterface *interface;
4943 GSupplicantGroup *group;
4944 GSupplicantPeer *peer;
4949 group = g_hash_table_lookup(group_mapping, path);
4953 dbus_message_iter_get_basic(iter, &peer_path);
4957 for (elem = group->members; elem; elem = elem->next) {
4958 if (!g_strcmp0(elem->data, peer_path))
4966 group->members = g_slist_delete_link(group->members, elem);
4968 interface = g_hash_table_lookup(peer_mapping, peer_path);
4972 peer = g_hash_table_lookup(interface->peer_table, peer_path);
4976 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
4977 peer->connection_requested = false;
4980 #if defined TIZEN_EXT_WIFI_MESH
4981 const void *g_supplicant_interface_get_mesh_group_ssid(
4982 GSupplicantInterface *interface,
4983 unsigned int *ssid_len)
4988 if (!interface || interface->group_info.ssid_len == 0) {
4993 *ssid_len = interface->group_info.ssid_len;
4994 return interface->group_info.ssid;
4997 int g_supplicant_mesh_get_disconnect_reason(GSupplicantInterface *interface)
5002 return interface->group_info.disconnect_reason;
5005 const char *g_supplicant_mesh_peer_get_address(GSupplicantMeshPeer *mesh_peer)
5007 if (!mesh_peer || !mesh_peer->peer_address)
5010 return mesh_peer->peer_address;
5013 int g_supplicant_mesh_peer_get_disconnect_reason(GSupplicantMeshPeer *mesh_peer)
5018 return mesh_peer->disconnect_reason;
5021 static void callback_mesh_group_started(GSupplicantInterface *interface)
5023 if (!callbacks_pointer)
5026 if (!callbacks_pointer->mesh_group_started)
5029 callbacks_pointer->mesh_group_started(interface);
5032 static void callback_mesh_group_removed(GSupplicantInterface *interface)
5034 if (!callbacks_pointer)
5037 if (!callbacks_pointer->mesh_group_removed)
5040 callbacks_pointer->mesh_group_removed(interface);
5043 static void mesh_group_info(const char *key, DBusMessageIter *iter,
5046 GSupplicantInterface *interface = user_data;
5050 if (g_strcmp0(key, "SSID") == 0) {
5051 DBusMessageIter array;
5052 unsigned char *ssid;
5055 dbus_message_iter_recurse(iter, &array);
5056 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
5058 if (ssid_len > 0 && ssid_len < 33) {
5059 memcpy(interface->group_info.ssid, ssid, ssid_len);
5060 interface->group_info.ssid_len = ssid_len;
5062 memset(interface->group_info.ssid, 0, 32);
5063 interface->group_info.ssid_len = 0;
5065 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5066 int disconnect_reason = 0;
5067 dbus_message_iter_get_basic(iter, &disconnect_reason);
5068 interface->group_info.disconnect_reason = disconnect_reason;
5072 static void signal_mesh_group_started(const char *path, DBusMessageIter *iter)
5074 GSupplicantInterface *interface;
5076 interface = g_hash_table_lookup(interface_table, path);
5080 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5082 callback_mesh_group_started(interface);
5085 static void signal_mesh_group_removed(const char *path, DBusMessageIter *iter)
5087 GSupplicantInterface *interface;
5089 interface = g_hash_table_lookup(interface_table, path);
5093 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5095 callback_mesh_group_removed(interface);
5098 static void callback_mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
5100 if (!callbacks_pointer)
5103 if (!callbacks_pointer->mesh_peer_connected)
5106 callbacks_pointer->mesh_peer_connected(mesh_peer);
5109 static void callback_mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
5111 if (!callbacks_pointer)
5114 if (!callbacks_pointer->mesh_peer_disconnected)
5117 callbacks_pointer->mesh_peer_disconnected(mesh_peer);
5120 static void mesh_peer_info(const char *key, DBusMessageIter *iter,
5123 GSupplicantMeshPeer *mesh_peer = user_data;
5127 if (g_strcmp0(key, "PeerAddress") == 0) {
5128 DBusMessageIter array;
5129 unsigned char *addr;
5132 dbus_message_iter_recurse(iter, &array);
5133 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
5135 if (addr_len == 6) {
5136 mesh_peer->peer_address = g_malloc0(19);
5137 snprintf(mesh_peer->peer_address, 19,
5138 "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1],
5139 addr[2], addr[3], addr[4], addr[5]);
5141 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5142 int disconnect_reason = 0;
5143 dbus_message_iter_get_basic(iter, &disconnect_reason);
5144 mesh_peer->disconnect_reason = disconnect_reason;
5148 static void signal_mesh_peer_connected(const char *path, DBusMessageIter *iter)
5150 GSupplicantInterface *interface;
5151 GSupplicantMeshPeer *mesh_peer;
5153 interface = g_hash_table_lookup(interface_table, path);
5157 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5158 mesh_peer->interface = interface;
5160 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5162 callback_mesh_peer_connected(mesh_peer);
5163 g_free(mesh_peer->peer_address);
5167 static void signal_mesh_peer_disconnected(const char *path,
5168 DBusMessageIter *iter)
5170 GSupplicantInterface *interface;
5171 GSupplicantMeshPeer *mesh_peer;
5173 interface = g_hash_table_lookup(interface_table, path);
5177 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5178 mesh_peer->interface = interface;
5180 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5182 callback_mesh_peer_disconnected(mesh_peer);
5183 g_free(mesh_peer->peer_address);
5189 const char *interface;
5191 void (*function) (const char *path, DBusMessageIter *iter);
5193 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
5195 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
5196 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
5197 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
5198 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
5200 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
5201 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
5202 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
5203 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
5204 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
5205 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
5206 { SUPPLICANT_INTERFACE ".Interface", "StaAuthorized", signal_sta_authorized },
5207 { SUPPLICANT_INTERFACE ".Interface", "StaDeauthorized", signal_sta_deauthorized },
5209 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
5211 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
5212 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
5213 #if defined TIZEN_EXT
5214 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
5217 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
5218 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
5220 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
5222 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
5223 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
5224 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
5225 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
5226 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
5228 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
5229 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
5230 #if defined TIZEN_EXT_WIFI_MESH
5231 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupStarted",
5232 signal_mesh_group_started },
5233 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupRemoved",
5234 signal_mesh_group_removed },
5235 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerConnected",
5236 signal_mesh_peer_connected },
5237 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerDisconnected",
5238 signal_mesh_peer_disconnected },
5241 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5242 { SUPPLICANT_INTERFACE ".Interface", "EAP", signal_eap },
5243 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5248 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
5249 DBusMessage *message, void *data)
5251 DBusMessageIter iter;
5255 path = dbus_message_get_path(message);
5257 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5259 if (!dbus_message_iter_init(message, &iter))
5260 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5262 for (i = 0; signal_map[i].interface; i++) {
5263 if (!dbus_message_has_interface(message, signal_map[i].interface))
5266 if (!dbus_message_has_member(message, signal_map[i].member))
5269 signal_map[i].function(path, &iter);
5273 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5276 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
5278 SUPPLICANT_DBG("Cancelling any pending DBus calls");
5279 supplicant_dbus_method_call_cancel_all(interface);
5280 supplicant_dbus_property_call_cancel_all(interface);
5283 struct supplicant_regdom {
5284 GSupplicantCountryCallback callback;
5286 const void *user_data;
5289 static void country_result(const char *error,
5290 DBusMessageIter *iter, void *user_data)
5292 struct supplicant_regdom *regdom = user_data;
5295 SUPPLICANT_DBG("Country setting result");
5301 SUPPLICANT_DBG("Country setting failure %s", error);
5305 if (regdom->callback)
5306 regdom->callback(result, regdom->alpha2,
5307 (void *) regdom->user_data);
5312 static void country_params(DBusMessageIter *iter, void *user_data)
5314 struct supplicant_regdom *regdom = user_data;
5316 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
5320 int g_supplicant_set_country(const char *alpha2,
5321 GSupplicantCountryCallback callback,
5322 const void *user_data)
5324 struct supplicant_regdom *regdom;
5327 SUPPLICANT_DBG("Country setting %s", alpha2);
5329 if (!system_available)
5332 regdom = dbus_malloc0(sizeof(*regdom));
5336 regdom->callback = callback;
5337 regdom->alpha2 = alpha2;
5338 regdom->user_data = user_data;
5340 ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
5341 "Country", DBUS_TYPE_STRING_AS_STRING,
5342 country_params, country_result,
5346 SUPPLICANT_DBG("Unable to set Country configuration");
5351 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
5352 GSupplicantCountryCallback callback,
5356 struct supplicant_regdom *regdom;
5359 regdom = dbus_malloc0(sizeof(*regdom));
5363 regdom->callback = callback;
5364 regdom->alpha2 = alpha2;
5365 regdom->user_data = user_data;
5367 ret = supplicant_dbus_property_set(interface->path,
5368 SUPPLICANT_INTERFACE ".Interface",
5369 "Country", DBUS_TYPE_STRING_AS_STRING,
5370 country_params, country_result,
5374 SUPPLICANT_DBG("Unable to set Country configuration");
5380 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
5385 return interface->p2p_support;
5388 struct supplicant_p2p_dev_config {
5393 static void p2p_device_config_result(const char *error,
5394 DBusMessageIter *iter, void *user_data)
5396 struct supplicant_p2p_dev_config *config = user_data;
5399 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
5402 g_free(config->device_name);
5403 g_free(config->dev_type);
5407 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
5409 int length, pos, end;
5414 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
5421 dev_type[length] = strtol(b, &e, 16);
5422 if (e && *e != '\0')
5431 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
5433 struct supplicant_p2p_dev_config *config = user_data;
5434 DBusMessageIter dict;
5436 supplicant_dbus_dict_open(iter, &dict);
5438 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
5439 DBUS_TYPE_STRING, &config->device_name);
5441 if (config->dev_type) {
5442 unsigned char dev_type[8] = {}, *type;
5445 len = dev_type_str2bin(config->dev_type, dev_type);
5448 supplicant_dbus_dict_append_fixed_array(&dict,
5449 "PrimaryDeviceType",
5450 DBUS_TYPE_BYTE, &type, len);
5454 supplicant_dbus_dict_close(iter, &dict);
5457 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
5458 const char *device_name,
5459 const char *primary_dev_type)
5461 struct supplicant_p2p_dev_config *config;
5464 SUPPLICANT_DBG("P2P Device settings %s/%s",
5465 device_name, primary_dev_type);
5467 config = dbus_malloc0(sizeof(*config));
5471 config->device_name = g_strdup(device_name);
5472 config->dev_type = g_strdup(primary_dev_type);
5474 ret = supplicant_dbus_property_set(interface->path,
5475 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5477 DBUS_TYPE_ARRAY_AS_STRING
5478 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
5479 DBUS_TYPE_STRING_AS_STRING
5480 DBUS_TYPE_VARIANT_AS_STRING
5481 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
5482 p2p_device_config_params,
5483 p2p_device_config_result, config, NULL);
5485 g_free(config->device_name);
5486 g_free(config->dev_type);
5488 SUPPLICANT_DBG("Unable to set P2P Device configuration");
5494 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
5497 const GSupplicantPeer *peer = value;
5498 const char *identifier = user_data;
5500 if (!g_strcmp0(identifier, peer->identifier))
5506 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
5507 const char *identifier)
5509 GSupplicantPeer *peer;
5511 peer = g_hash_table_find(interface->peer_table,
5512 peer_lookup_by_identifier,
5513 (void *) identifier);
5517 static void interface_create_data_free(struct interface_create_data *data)
5519 g_free(data->ifname);
5520 g_free(data->driver);
5521 g_free(data->bridge);
5522 #if defined TIZEN_EXT_WIFI_MESH
5523 g_free(data->parent_ifname);
5528 static bool interface_exists(GSupplicantInterface *interface,
5531 GSupplicantInterface *tmp;
5533 tmp = g_hash_table_lookup(interface_table, path);
5534 if (tmp && tmp == interface)
5540 static void interface_create_property(const char *key, DBusMessageIter *iter,
5543 struct interface_create_data *data = user_data;
5544 GSupplicantInterface *interface = data->interface;
5547 if (data->callback) {
5548 data->callback(0, data->interface, data->user_data);
5549 #if !defined TIZEN_EXT
5550 callback_p2p_support(interface);
5552 #if defined TIZEN_EXT_WIFI_MESH
5553 callback_mesh_support(interface);
5557 interface_create_data_free(data);
5560 interface_property(key, iter, interface);
5563 static void interface_create_result(const char *error,
5564 DBusMessageIter *iter, void *user_data)
5566 struct interface_create_data *data = user_data;
5567 const char *path = NULL;
5573 g_message("error %s", error);
5578 dbus_message_iter_get_basic(iter, &path);
5584 if (!system_available) {
5589 data->interface = g_hash_table_lookup(interface_table, path);
5590 if (!data->interface) {
5591 data->interface = interface_alloc(path);
5592 if (!data->interface) {
5598 err = supplicant_dbus_property_get_all(path,
5599 SUPPLICANT_INTERFACE ".Interface",
5600 interface_create_property, data,
5607 data->callback(err, NULL, data->user_data);
5609 interface_create_data_free(data);
5612 static void interface_create_params(DBusMessageIter *iter, void *user_data)
5614 struct interface_create_data *data = user_data;
5615 DBusMessageIter dict;
5616 char *config_file = NULL;
5620 supplicant_dbus_dict_open(iter, &dict);
5622 supplicant_dbus_dict_append_basic(&dict, "Ifname",
5623 DBUS_TYPE_STRING, &data->ifname);
5626 supplicant_dbus_dict_append_basic(&dict, "Driver",
5627 DBUS_TYPE_STRING, &data->driver);
5630 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
5631 DBUS_TYPE_STRING, &data->bridge);
5633 config_file = g_hash_table_lookup(config_file_table, data->ifname);
5635 SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
5637 supplicant_dbus_dict_append_basic(&dict, "ConfigFile",
5638 DBUS_TYPE_STRING, &config_file);
5641 #if defined TIZEN_EXT_WIFI_MESH
5642 if (data->is_mesh_interface) {
5643 if (data->parent_ifname)
5644 supplicant_dbus_dict_append_basic(&dict, "ParentIfname",
5645 DBUS_TYPE_STRING, &data->parent_ifname);
5647 supplicant_dbus_dict_append_basic(&dict, "IsMeshInterface",
5648 DBUS_TYPE_BOOLEAN, &data->is_mesh_interface);
5652 supplicant_dbus_dict_close(iter, &dict);
5655 #if defined TIZEN_EXT
5656 static void interface_get_state(const char *key, DBusMessageIter *iter,
5659 struct interface_create_data *data = user_data;
5660 GSupplicantInterface *interface = NULL;
5661 const char *str = NULL;
5663 SUPPLICANT_DBG("key[%s]", key);
5666 SUPPLICANT_DBG("data is NULL");
5670 interface = data->interface;
5672 SUPPLICANT_DBG("interface is NULL");
5677 dbus_message_iter_get_basic(iter, &str);
5680 if (string2state(str) != interface->state)
5681 interface->state = string2state(str);
5684 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
5685 interface->ready = FALSE;
5687 interface->ready = TRUE;
5689 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
5691 if (data->callback) {
5692 data->callback(0, interface, data->user_data);
5693 #if defined TIZEN_EXT_WIFI_MESH
5694 callback_mesh_support(interface);
5698 interface_create_data_free(data);
5702 static void interface_get_result(const char *error,
5703 DBusMessageIter *iter, void *user_data)
5705 struct interface_create_data *data = user_data;
5706 GSupplicantInterface *interface;
5707 const char *path = NULL;
5713 SUPPLICANT_DBG("Interface not created yet");
5717 dbus_message_iter_get_basic(iter, &path);
5723 interface = g_hash_table_lookup(interface_table, path);
5729 #if defined TIZEN_EXT
5730 data->interface = interface;
5731 err = supplicant_dbus_property_get(path,
5732 SUPPLICANT_INTERFACE ".Interface",
5733 "State", interface_get_state, data, NULL);
5739 if (data->callback) {
5740 data->callback(0, interface, data->user_data);
5741 #if !defined TIZEN_EXT
5742 callback_p2p_support(interface);
5744 #if defined TIZEN_EXT_WIFI_MESH
5745 callback_mesh_support(interface);
5749 interface_create_data_free(data);
5754 if (!system_available) {
5759 SUPPLICANT_DBG("Creating interface");
5761 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
5762 SUPPLICANT_INTERFACE,
5764 interface_create_params,
5765 interface_create_result, data,
5772 data->callback(err, NULL, data->user_data);
5774 interface_create_data_free(data);
5777 static void interface_get_params(DBusMessageIter *iter, void *user_data)
5779 struct interface_create_data *data = user_data;
5783 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
5786 #if defined TIZEN_EXT_WIFI_MESH
5787 int g_supplicant_mesh_interface_create(const char *ifname, const char *driver,
5788 const char *bridge, const char *parent_ifname,
5789 GSupplicantInterfaceCallback callback, void *user_data)
5791 struct interface_create_data *data;
5794 SUPPLICANT_DBG("ifname %s", ifname);
5796 if (!ifname || !parent_ifname)
5799 if (!system_available)
5802 data = dbus_malloc0(sizeof(*data));
5806 data->ifname = g_strdup(ifname);
5807 data->driver = g_strdup(driver);
5808 data->bridge = g_strdup(bridge);
5809 data->is_mesh_interface = true;
5810 data->parent_ifname = g_strdup(parent_ifname);
5811 data->callback = callback;
5812 data->user_data = user_data;
5814 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5815 SUPPLICANT_INTERFACE,
5817 interface_create_params,
5818 interface_create_result, data,
5823 struct interface_mesh_peer_data {
5826 GSupplicantInterface *interface;
5827 GSupplicantInterfaceCallback callback;
5831 static void interface_mesh_change_peer_params(DBusMessageIter *iter,
5834 struct interface_mesh_peer_data *data = user_data;
5838 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->peer_address);
5841 static void interface_mesh_change_peer_result(const char *error,
5842 DBusMessageIter *iter, void *user_data)
5844 struct interface_mesh_peer_data *data = user_data;
5847 SUPPLICANT_DBG("%s", data->method);
5851 SUPPLICANT_DBG("error %s", error);
5855 data->callback(err, data->interface, data->user_data);
5857 g_free(data->peer_address);
5858 g_free(data->method);
5862 int g_supplicant_interface_mesh_peer_change_status(
5863 GSupplicantInterface *interface,
5864 GSupplicantInterfaceCallback callback, const char *peer_address,
5865 const char *method, void *user_data)
5867 struct interface_mesh_peer_data *data;
5873 data = dbus_malloc0(sizeof(*data));
5877 data->peer_address = g_strdup(peer_address);
5878 data->method = g_strdup(method);
5879 data->interface = interface;
5880 data->callback = callback;
5881 data->user_data = user_data;
5883 ret = supplicant_dbus_method_call(interface->path,
5884 SUPPLICANT_INTERFACE ".Interface.Mesh",
5885 method, interface_mesh_change_peer_params,
5886 interface_mesh_change_peer_result, data, NULL);
5888 g_free(data->peer_address);
5889 g_free(data->method);
5897 int g_supplicant_interface_create(const char *ifname, const char *driver,
5899 GSupplicantInterfaceCallback callback,
5902 struct interface_create_data *data;
5905 SUPPLICANT_DBG("ifname %s", ifname);
5910 if (!system_available)
5913 data = dbus_malloc0(sizeof(*data));
5917 data->ifname = g_strdup(ifname);
5918 data->driver = g_strdup(driver);
5919 data->bridge = g_strdup(bridge);
5920 data->callback = callback;
5921 data->user_data = user_data;
5923 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5924 SUPPLICANT_INTERFACE,
5926 interface_get_params,
5927 interface_get_result, data,
5930 interface_create_data_free(data);
5935 static void interface_remove_result(const char *error,
5936 DBusMessageIter *iter, void *user_data)
5938 struct interface_data *data = user_data;
5943 SUPPLICANT_DBG("error: %s", error);
5947 if (!system_available) {
5953 * The gsupplicant interface is already freed by the InterfaceRemoved
5954 * signal callback. Simply invoke the interface_data callback.
5962 data->callback(err, NULL, data->user_data);
5968 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
5970 struct interface_data *data = user_data;
5972 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
5973 &data->interface->path);
5976 int g_supplicant_interface_remove(GSupplicantInterface *interface,
5977 GSupplicantInterfaceCallback callback,
5980 struct interface_data *data;
5986 if (!system_available)
5989 g_supplicant_interface_cancel(interface);
5991 data = dbus_malloc0(sizeof(*data));
5995 data->interface = interface;
5996 data->path = g_strdup(interface->path);
5997 data->callback = callback;
5998 data->user_data = user_data;
6000 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6001 SUPPLICANT_INTERFACE,
6003 interface_remove_params,
6004 interface_remove_result, data,
6013 static void interface_scan_result(const char *error,
6014 DBusMessageIter *iter, void *user_data)
6016 struct interface_scan_data *data = user_data;
6020 SUPPLICANT_DBG("error %s", error);
6024 /* A non ready interface cannot send/receive anything */
6025 if (interface_exists(data->interface, data->path)) {
6026 if (!data->interface->ready)
6034 data->callback(err, data->interface, data->user_data);
6036 data->interface->scan_callback = data->callback;
6037 data->interface->scan_data = data->user_data;
6040 if (data->scan_params)
6041 g_supplicant_free_scan_params(data->scan_params);
6046 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
6048 DBusMessageIter data;
6049 unsigned int width = 0; /* Not used by wpa_supplicant atm */
6051 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
6053 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
6054 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
6056 dbus_message_iter_close_container(iter, &data);
6059 static void add_scan_frequencies(DBusMessageIter *iter,
6062 GSupplicantScanParams *scan_data = user_data;
6066 for (i = 0; i < scan_data->num_freqs; i++) {
6067 freq = scan_data->freqs[i];
6071 add_scan_frequency(iter, freq);
6075 static void append_ssid(DBusMessageIter *iter,
6076 const void *ssid, unsigned int len)
6078 DBusMessageIter array;
6080 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
6081 DBUS_TYPE_BYTE_AS_STRING, &array);
6083 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
6085 dbus_message_iter_close_container(iter, &array);
6088 static void append_ssids(DBusMessageIter *iter, void *user_data)
6090 GSupplicantScanParams *scan_data = user_data;
6093 for (list = scan_data->ssids; list; list = list->next) {
6094 struct scan_ssid *scan_ssid = list->data;
6096 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
6100 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
6101 supplicant_dbus_array_function function,
6104 GSupplicantScanParams *scan_params = user_data;
6105 DBusMessageIter entry, value, array;
6106 const char *key = "Channels";
6108 if (scan_params->freqs && scan_params->freqs[0] != 0) {
6109 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
6112 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
6114 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
6115 DBUS_TYPE_ARRAY_AS_STRING
6116 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6117 DBUS_TYPE_UINT32_AS_STRING
6118 DBUS_TYPE_UINT32_AS_STRING
6119 DBUS_STRUCT_END_CHAR_AS_STRING,
6122 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
6123 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6124 DBUS_TYPE_UINT32_AS_STRING
6125 DBUS_TYPE_UINT32_AS_STRING
6126 DBUS_STRUCT_END_CHAR_AS_STRING,
6130 function(&array, user_data);
6132 dbus_message_iter_close_container(&value, &array);
6133 dbus_message_iter_close_container(&entry, &value);
6134 dbus_message_iter_close_container(dict, &entry);
6138 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
6140 DBusMessageIter dict;
6141 const char *type = "passive";
6142 struct interface_scan_data *data = user_data;
6144 supplicant_dbus_dict_open(iter, &dict);
6146 if (data && data->scan_params) {
6149 supplicant_dbus_dict_append_basic(&dict, "Type",
6150 DBUS_TYPE_STRING, &type);
6152 #if defined TIZEN_EXT
6153 SUPPLICANT_DBG("[specific_scan] num_ssids %d",
6154 data->scan_params->num_ssids);
6157 if (data->scan_params->ssids) {
6158 supplicant_dbus_dict_append_array(&dict, "SSIDs",
6163 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
6166 supplicant_dbus_dict_append_basic(&dict, "Type",
6167 DBUS_TYPE_STRING, &type);
6169 supplicant_dbus_dict_close(iter, &dict);
6172 static int interface_ready_to_scan(GSupplicantInterface *interface)
6177 if (!system_available)
6180 if (interface->scanning)
6183 switch (interface->state) {
6184 case G_SUPPLICANT_STATE_AUTHENTICATING:
6185 case G_SUPPLICANT_STATE_ASSOCIATING:
6186 case G_SUPPLICANT_STATE_ASSOCIATED:
6187 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
6188 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
6190 #if defined TIZEN_EXT
6191 case G_SUPPLICANT_STATE_DISABLED:
6193 case G_SUPPLICANT_STATE_UNKNOWN:
6195 case G_SUPPLICANT_STATE_UNKNOWN:
6196 case G_SUPPLICANT_STATE_DISABLED:
6198 case G_SUPPLICANT_STATE_DISCONNECTED:
6199 case G_SUPPLICANT_STATE_INACTIVE:
6200 case G_SUPPLICANT_STATE_SCANNING:
6201 case G_SUPPLICANT_STATE_COMPLETED:
6208 #if defined TIZEN_EXT_WIFI_MESH
6209 static void interface_abort_scan_result(const char *error,
6210 DBusMessageIter *iter, void *user_data)
6212 struct interface_scan_data *data = user_data;
6216 SUPPLICANT_DBG("error %s", error);
6223 data->callback(err, data->interface, data->user_data);
6228 int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
6229 GSupplicantInterfaceCallback callback, void *user_data)
6231 struct interface_scan_data *data;
6234 if (!interface->scanning)
6237 data = dbus_malloc0(sizeof(*data));
6241 data->interface = interface;
6242 data->path = g_strdup(interface->path);
6243 data->callback = callback;
6244 data->user_data = user_data;
6246 ret = supplicant_dbus_method_call(interface->path,
6247 SUPPLICANT_INTERFACE ".Interface", "AbortScan", NULL,
6248 interface_abort_scan_result, data, interface);
6259 int g_supplicant_interface_scan(GSupplicantInterface *interface,
6260 GSupplicantScanParams *scan_data,
6261 GSupplicantInterfaceCallback callback,
6264 struct interface_scan_data *data;
6267 ret = interface_ready_to_scan(interface);
6271 data = dbus_malloc0(sizeof(*data));
6275 data->interface = interface;
6276 data->path = g_strdup(interface->path);
6277 #if defined TIZEN_EXT
6278 data->interface->scan_callback = data->callback = callback;
6279 data->interface->scan_data = data->user_data = user_data;
6281 data->callback = callback;
6282 data->user_data = user_data;
6284 data->scan_params = scan_data;
6286 interface->scan_callback = callback;
6287 interface->scan_data = user_data;
6289 ret = supplicant_dbus_method_call(interface->path,
6290 SUPPLICANT_INTERFACE ".Interface", "Scan",
6291 interface_scan_params, interface_scan_result, data,
6302 #if defined TIZEN_EXT
6303 static void interface_signalpoll_result(const char *error,
6304 DBusMessageIter *iter, void *user_data)
6306 struct interface_signalpoll_data *data = user_data;
6308 dbus_int32_t maxspeed = 0;
6309 dbus_int32_t strength = 0;
6310 DBusMessageIter sub_iter, dict;
6314 SUPPLICANT_DBG("error: %s", error);
6318 dbus_message_iter_get_arg_type(iter);
6319 dbus_message_iter_recurse(iter, &sub_iter);
6320 dbus_message_iter_recurse(&sub_iter, &dict);
6322 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
6323 DBusMessageIter entry, value;
6326 dbus_message_iter_recurse(&dict, &entry);
6327 dbus_message_iter_get_basic(&entry, &key);
6328 dbus_message_iter_next(&entry);
6329 dbus_message_iter_recurse(&entry, &value);
6331 switch (dbus_message_iter_get_arg_type(&value)) {
6332 case DBUS_TYPE_INT32:
6333 if (g_strcmp0(key, "linkspeed") == 0) {
6334 dbus_message_iter_get_basic(&value, &maxspeed);
6335 SUPPLICANT_DBG("linkspeed = %d", maxspeed);
6337 } else if (g_strcmp0(key, "rssi") == 0) {
6338 dbus_message_iter_get_basic(&value, &strength);
6339 SUPPLICANT_DBG("Strength = %d", strength);
6343 dbus_message_iter_next(&dict);
6348 data->callback(err, maxspeed, strength, data->user_data);
6354 int g_supplicant_interface_signalpoll(GSupplicantInterface *interface,
6355 GSupplicantMaxSpeedCallback callback,
6358 struct interface_signalpoll_data *data;
6364 if (!system_available)
6367 data = dbus_malloc0(sizeof(*data));
6371 data->interface = interface;
6372 data->path = g_strdup(interface->path);
6373 data->callback = callback;
6374 data->user_data = user_data;
6376 ret = supplicant_dbus_method_call(interface->path,
6377 SUPPLICANT_INTERFACE ".Interface", "SignalPoll",
6378 NULL, interface_signalpoll_result, data,
6390 static int parse_supplicant_error(DBusMessageIter *iter)
6392 int err = -ECONNABORTED;
6398 /* If the given passphrase is malformed wpa_s returns
6399 * "invalid message format" but this error should be interpreted as
6402 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
6403 dbus_message_iter_get_basic(iter, &key);
6404 if (strncmp(key, "psk", 3) == 0 ||
6405 strncmp(key, "wep_key", 7) == 0 ||
6406 strcmp(key, "invalid message format") == 0) {
6410 dbus_message_iter_next(iter);
6416 static void interface_select_network_result(const char *error,
6417 DBusMessageIter *iter, void *user_data)
6419 struct interface_connect_data *data = user_data;
6426 #if defined TIZEN_EXT
6427 SUPPLICANT_DBG("SelectNetwork errorFreq %s", error);
6429 SUPPLICANT_DBG("SelectNetwork error %s", error);
6431 err = parse_supplicant_error(iter);
6437 data->callback(err, data->interface, data->user_data);
6439 #if defined TIZEN_EXT
6440 g_free(data->ssid->ssid);
6441 g_free((char *)data->ssid->passphrase);
6442 g_free((char *)data->ssid->connector);
6443 g_free((char *)data->ssid->c_sign_key);
6444 g_free((char *)data->ssid->net_access_key);
6450 static void interface_select_network_params(DBusMessageIter *iter,
6453 struct interface_connect_data *data = user_data;
6454 GSupplicantInterface *interface = data->interface;
6455 #if defined TIZEN_EXT
6456 GSupplicantSSID *ssid = data->ssid;
6459 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6460 &interface->network_path);
6461 #if defined TIZEN_EXT
6462 if (!ssid->bssid_for_connect_len)
6463 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
6467 static void interface_add_network_result(const char *error,
6468 DBusMessageIter *iter, void *user_data)
6470 struct interface_connect_data *data = user_data;
6471 GSupplicantInterface *interface = data->interface;
6478 dbus_message_iter_get_basic(iter, &path);
6482 SUPPLICANT_DBG("PATH: %s", path);
6484 #if defined TIZEN_EXT
6485 if (interface->network_path)
6486 g_free(interface->network_path);
6488 interface->network_path = g_strdup(path);
6490 store_network_information(interface, data->ssid);
6492 #if defined TIZEN_EXT
6493 SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
6494 GSupplicantSSID *ssid = data->ssid;
6496 if (!ssid->bssid_for_connect_len)
6497 supplicant_dbus_method_call(data->interface->path,
6498 SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
6499 interface_select_network_params,
6500 interface_select_network_result, data,
6503 supplicant_dbus_method_call(data->interface->path,
6504 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6505 interface_select_network_params,
6506 interface_select_network_result, data,
6509 supplicant_dbus_method_call(data->interface->path,
6510 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6511 interface_select_network_params,
6512 interface_select_network_result, data,
6519 SUPPLICANT_DBG("AddNetwork error %s", error);
6521 if (interface_exists(data->interface, data->interface->path)) {
6522 err = parse_supplicant_error(iter);
6524 data->callback(err, data->interface, data->user_data);
6526 g_free(interface->network_path);
6527 interface->network_path = NULL;
6531 #if defined TIZEN_EXT
6532 g_free(data->ssid->ssid);
6533 g_free((char *)data->ssid->passphrase);
6534 g_free((char *)data->ssid->connector);
6535 g_free((char *)data->ssid->c_sign_key);
6536 g_free((char *)data->ssid->net_access_key);
6542 static void add_network_security_none(DBusMessageIter *dict)
6544 const char *auth_alg = "OPEN";
6546 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6547 DBUS_TYPE_STRING, &auth_alg);
6550 static void add_network_security_wep(DBusMessageIter *dict,
6551 GSupplicantSSID *ssid)
6553 const char *auth_alg = "OPEN SHARED";
6554 dbus_uint32_t key_index = 0;
6556 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6557 DBUS_TYPE_STRING, &auth_alg);
6559 if (ssid->passphrase) {
6560 int size = strlen(ssid->passphrase);
6561 if (size == 10 || size == 26) {
6562 unsigned char *key = g_try_malloc(13);
6566 memset(tmp, 0, sizeof(tmp));
6570 for (i = 0; i < size / 2; i++) {
6571 memcpy(tmp, ssid->passphrase + (i * 2), 2);
6572 key[i] = (unsigned char) strtol(tmp, NULL, 16);
6575 supplicant_dbus_dict_append_fixed_array(dict,
6580 } else if (size == 5 || size == 13) {
6581 unsigned char *key = g_try_malloc(13);
6587 for (i = 0; i < size; i++)
6588 key[i] = (unsigned char) ssid->passphrase[i];
6590 supplicant_dbus_dict_append_fixed_array(dict,
6596 supplicant_dbus_dict_append_basic(dict,
6601 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
6602 DBUS_TYPE_UINT32, &key_index);
6606 static dbus_bool_t is_psk_raw_key(const char *psk)
6610 /* A raw key is always 64 bytes length... */
6611 if (strlen(psk) != 64)
6614 /* ... and its content is in hex representation */
6615 for (i = 0; i < 64; i++)
6616 if (!isxdigit((unsigned char) psk[i]))
6622 static unsigned char hexchar2bin(char c)
6624 if ((c >= '0') && (c <= '9'))
6626 else if ((c >= 'A') && (c <= 'F'))
6627 return c - 'A' + 10;
6628 else if ((c >= 'a') && (c <= 'f'))
6629 return c - 'a' + 10;
6634 static void hexstring2bin(const char *string, unsigned char *data,
6639 for (i = 0; i < data_len; i++)
6640 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
6641 hexchar2bin(string[i * 2 + 1]) << 0);
6644 static void add_network_security_psk(DBusMessageIter *dict,
6645 GSupplicantSSID *ssid)
6647 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
6648 const char *key = "psk";
6650 if (is_psk_raw_key(ssid->passphrase)) {
6651 unsigned char data[32];
6652 unsigned char *datap = data;
6654 /* The above pointer alias is required by D-Bus because
6655 * with D-Bus and GCC, non-heap-allocated arrays cannot
6656 * be passed directly by their base pointer. */
6658 hexstring2bin(ssid->passphrase, datap, sizeof(data));
6660 supplicant_dbus_dict_append_fixed_array(dict,
6661 key, DBUS_TYPE_BYTE,
6662 &datap, sizeof(data));
6664 supplicant_dbus_dict_append_basic(dict,
6665 key, DBUS_TYPE_STRING,
6670 static void add_network_security_tls(DBusMessageIter *dict,
6671 GSupplicantSSID *ssid)
6674 * For TLS, we at least need:
6675 * The client certificate
6676 * The client private key file
6677 * The client private key file password
6679 * The Authority certificate is optional.
6681 if (!ssid->client_cert_path)
6684 if (!ssid->private_key_path)
6687 #if !defined TIZEN_EXT
6688 if (!ssid->private_key_passphrase)
6692 if (ssid->ca_cert_path)
6693 supplicant_dbus_dict_append_basic(dict, "ca_cert",
6694 DBUS_TYPE_STRING, &ssid->ca_cert_path);
6696 supplicant_dbus_dict_append_basic(dict, "private_key",
6698 &ssid->private_key_path);
6699 #if !defined TIZEN_EXT
6700 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
6702 &ssid->private_key_passphrase);
6704 supplicant_dbus_dict_append_basic(dict, "client_cert",
6706 &ssid->client_cert_path);
6709 static void add_network_security_peap(DBusMessageIter *dict,
6710 GSupplicantSSID *ssid)
6715 * For PEAP/TTLS, we at least need
6716 * The authority certificate
6717 * The 2nd phase authentication method
6718 * The 2nd phase passphrase
6720 * The Client certificate is optional although strongly recommended
6721 * When setting it, we need in addition
6722 * The Client private key file
6723 * The Client private key file password
6725 if (!ssid->passphrase)
6728 if (!ssid->phase2_auth)
6731 if (ssid->client_cert_path) {
6732 if (!ssid->private_key_path)
6735 #if !defined TIZEN_EXT
6736 if (!ssid->private_key_passphrase)
6740 supplicant_dbus_dict_append_basic(dict, "client_cert",
6742 &ssid->client_cert_path);
6744 supplicant_dbus_dict_append_basic(dict, "private_key",
6746 &ssid->private_key_path);
6748 #if !defined TIZEN_EXT
6749 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
6751 &ssid->private_key_passphrase);
6756 if(g_strcmp0(ssid->phase2_auth, "GTC") == 0 && g_strcmp0(ssid->eap, "ttls") == 0)
6757 phase2_auth = g_strdup_printf("autheap=%s", ssid->phase2_auth);
6758 else if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
6759 phase2_auth = g_strdup_printf("autheap=%s",
6760 ssid->phase2_auth + strlen("EAP-"));
6762 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
6764 supplicant_dbus_dict_append_basic(dict, "password",
6768 if (ssid->ca_cert_path)
6769 supplicant_dbus_dict_append_basic(dict, "ca_cert",
6771 &ssid->ca_cert_path);
6773 supplicant_dbus_dict_append_basic(dict, "phase2",
6777 g_free(phase2_auth);
6780 #if defined TIZEN_EXT
6781 static void add_network_security_aka_sim(DBusMessageIter *dict,
6782 GSupplicantSSID *ssid)
6784 if (!ssid->passphrase)
6787 supplicant_dbus_dict_append_basic(dict, "password",
6792 static void add_network_security_fast(DBusMessageIter *dict,
6793 GSupplicantSSID *ssid)
6796 * For FAST, we at least need:
6798 * phase1 (provisiong information)
6802 /* Allow provisioing both authenticated and unauthenticated */
6803 const char *phase1 = "fast_provisioning=2";
6804 supplicant_dbus_dict_append_basic(dict, "phase1",
6808 SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
6810 supplicant_dbus_dict_append_basic(dict, "pac_file",
6814 supplicant_dbus_dict_append_basic(dict, "password",
6820 static void add_network_security_eap(DBusMessageIter *dict,
6821 GSupplicantSSID *ssid)
6825 #if defined TIZEN_EXT
6828 if (!ssid->eap || !ssid->identity)
6832 if (g_strcmp0(ssid->eap, "tls") == 0) {
6833 add_network_security_tls(dict, ssid);
6834 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
6835 g_strcmp0(ssid->eap, "ttls") == 0) {
6836 #if defined TIZEN_EXT
6837 if (!ssid->identity)
6840 add_network_security_peap(dict, ssid);
6842 #if defined TIZEN_EXT
6843 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
6844 g_strcmp0(ssid->eap, "aka") == 0 ||
6845 g_strcmp0(ssid->eap, "aka'") == 0) {
6846 add_network_security_aka_sim(dict, ssid);
6847 } else if (g_strcmp0(ssid->eap, "pwd") == 0) {
6848 if(!ssid->passphrase)
6850 supplicant_dbus_dict_append_basic(dict, "password",
6853 } else if (g_strcmp0(ssid->eap, "fast") == 0){
6854 if (!ssid->identity || !ssid->passphrase)
6857 add_network_security_fast(dict, ssid);
6862 eap_value = g_ascii_strup(ssid->eap, -1);
6864 supplicant_dbus_dict_append_basic(dict, "eap",
6867 #if defined TIZEN_EXT
6868 if (ssid->identity != NULL)
6869 supplicant_dbus_dict_append_basic(dict, "identity",
6873 supplicant_dbus_dict_append_basic(dict, "identity",
6877 if(ssid->anonymous_identity)
6878 supplicant_dbus_dict_append_basic(dict, "anonymous_identity",
6880 &ssid->anonymous_identity);
6882 if(ssid->subject_match)
6883 supplicant_dbus_dict_append_basic(dict, "subject_match",
6885 &ssid->subject_match);
6887 if(ssid->altsubject_match)
6888 supplicant_dbus_dict_append_basic(dict, "altsubject_match",
6890 &ssid->altsubject_match);
6892 if(ssid->domain_suffix_match)
6893 supplicant_dbus_dict_append_basic(dict, "domain_suffix_match",
6895 &ssid->domain_suffix_match);
6897 if(ssid->domain_match)
6898 supplicant_dbus_dict_append_basic(dict, "domain_match",
6900 &ssid->domain_match);
6905 static void add_network_security_ciphers(DBusMessageIter *dict,
6906 GSupplicantSSID *ssid)
6908 unsigned int p_cipher, g_cipher, i;
6909 char *pairwise, *group;
6910 char *pair_ciphers[4];
6911 char *group_ciphers[5];
6913 p_cipher = ssid->pairwise_cipher;
6914 g_cipher = ssid->group_cipher;
6916 if (p_cipher == 0 && g_cipher == 0)
6921 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
6922 pair_ciphers[i++] = "CCMP";
6924 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
6925 pair_ciphers[i++] = "TKIP";
6927 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
6928 pair_ciphers[i++] = "NONE";
6930 pair_ciphers[i] = NULL;
6934 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
6935 group_ciphers[i++] = "CCMP";
6937 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
6938 group_ciphers[i++] = "TKIP";
6940 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
6941 group_ciphers[i++] = "WEP104";
6943 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
6944 group_ciphers[i++] = "WEP40";
6946 group_ciphers[i] = NULL;
6948 pairwise = g_strjoinv(" ", pair_ciphers);
6949 group = g_strjoinv(" ", group_ciphers);
6951 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
6953 supplicant_dbus_dict_append_basic(dict, "pairwise",
6956 supplicant_dbus_dict_append_basic(dict, "group",
6964 static void add_network_security_proto(DBusMessageIter *dict,
6965 GSupplicantSSID *ssid)
6967 unsigned int protocol, i;
6971 protocol = ssid->protocol;
6978 if (protocol & G_SUPPLICANT_PROTO_RSN)
6979 protos[i++] = "RSN";
6981 if (protocol & G_SUPPLICANT_PROTO_WPA)
6982 protos[i++] = "WPA";
6986 proto = g_strjoinv(" ", protos);
6988 SUPPLICANT_DBG("proto %s", proto);
6990 supplicant_dbus_dict_append_basic(dict, "proto",
6997 #if defined TIZEN_EXT
6998 static void add_network_ieee80211w(DBusMessageIter *dict, GSupplicantSSID *ssid)
7000 if (ssid->security != G_SUPPLICANT_SECURITY_SAE
7001 && ssid->security != G_SUPPLICANT_SECURITY_OWE
7002 && ssid->security != G_SUPPLICANT_SECURITY_DPP)
7005 supplicant_dbus_dict_append_basic(dict, "ieee80211w", DBUS_TYPE_UINT32,
7009 static void add_network_security_connector(DBusMessageIter *dict, GSupplicantSSID *ssid)
7011 if (ssid->connector && strlen(ssid->connector) > 0) {
7012 const char *key = "dpp_connector";
7014 supplicant_dbus_dict_append_basic(dict,
7015 key, DBUS_TYPE_STRING,
7020 static size_t convert_hexstr_to_bin(const char *hex_str, unsigned char **bin)
7022 unsigned char *bin_res = NULL;
7023 unsigned int i, j, hex;
7026 if (!hex_str || strlen(hex_str) == 0)
7029 hex_str_len = strlen(hex_str);
7030 bin_res = g_try_malloc0(hex_str_len / 2);
7035 for (i = 0; i < hex_str_len; i+=2) {
7036 sscanf(hex_str + i, "%02x", &hex);
7041 return hex_str_len / 2;
7044 static void add_network_security_c_sign_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7046 if (ssid->c_sign_key && strlen(ssid->c_sign_key) > 0) {
7047 const char *key = "dpp_csign";
7048 unsigned char *bin_csign = NULL;
7049 size_t bin_csign_len = convert_hexstr_to_bin(ssid->c_sign_key, &bin_csign);
7050 if (bin_csign_len != 0)
7051 supplicant_dbus_dict_append_fixed_array(dict,
7052 key, DBUS_TYPE_BYTE,
7053 &bin_csign, bin_csign_len);
7058 static void add_network_security_net_access_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7060 if (ssid->net_access_key && strlen(ssid->net_access_key) > 0) {
7061 const char *key = "dpp_netaccesskey";
7062 unsigned char *bin_netaccesskey = NULL;
7063 size_t bin_netaccesskey_len = convert_hexstr_to_bin(ssid->net_access_key, &bin_netaccesskey);
7064 if (bin_netaccesskey_len != 0)
7065 supplicant_dbus_dict_append_fixed_array(dict,
7066 key, DBUS_TYPE_BYTE,
7067 &bin_netaccesskey, bin_netaccesskey_len);
7068 g_free(bin_netaccesskey);
7074 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
7078 switch (ssid->security) {
7079 case G_SUPPLICANT_SECURITY_NONE:
7081 add_network_security_none(dict);
7082 add_network_security_ciphers(dict, ssid);
7084 case G_SUPPLICANT_SECURITY_UNKNOWN:
7085 case G_SUPPLICANT_SECURITY_WEP:
7087 add_network_security_wep(dict, ssid);
7088 add_network_security_ciphers(dict, ssid);
7090 case G_SUPPLICANT_SECURITY_PSK:
7091 key_mgmt = "WPA-PSK";
7092 add_network_security_psk(dict, ssid);
7093 add_network_security_ciphers(dict, ssid);
7094 add_network_security_proto(dict, ssid);
7096 case G_SUPPLICANT_SECURITY_IEEE8021X:
7097 key_mgmt = "WPA-EAP";
7098 add_network_security_eap(dict, ssid);
7099 add_network_security_ciphers(dict, ssid);
7100 add_network_security_proto(dict, ssid);
7102 #if defined TIZEN_EXT
7103 case G_SUPPLICANT_SECURITY_FT_PSK:
7104 key_mgmt = "FT-PSK";
7105 add_network_security_psk(dict, ssid);
7106 add_network_security_ciphers(dict, ssid);
7107 add_network_security_proto(dict, ssid);
7109 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
7110 key_mgmt = "FT-EAP";
7111 add_network_security_eap(dict, ssid);
7112 add_network_security_ciphers(dict, ssid);
7113 add_network_security_proto(dict, ssid);
7115 case G_SUPPLICANT_SECURITY_SAE:
7116 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK)
7117 key_mgmt = "SAE WPA-PSK"; // WFA (WPA3 & WPA2 Mixed -> WPA2 only)
7120 add_network_security_psk(dict, ssid);
7122 case G_SUPPLICANT_SECURITY_OWE:
7124 add_network_security_ciphers(dict, ssid);
7125 add_network_security_proto(dict, ssid);
7127 case G_SUPPLICANT_SECURITY_DPP:
7129 add_network_security_connector(dict, ssid);
7130 add_network_security_c_sign_key(dict, ssid);
7131 add_network_security_net_access_key(dict, ssid);
7136 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
7137 DBUS_TYPE_STRING, &key_mgmt);
7140 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
7144 switch (ssid->mode) {
7145 case G_SUPPLICANT_MODE_UNKNOWN:
7146 case G_SUPPLICANT_MODE_INFRA:
7149 case G_SUPPLICANT_MODE_IBSS:
7152 case G_SUPPLICANT_MODE_MASTER:
7155 #if defined TIZEN_EXT_WIFI_MESH
7156 case G_SUPPLICANT_MODE_MESH:
7162 supplicant_dbus_dict_append_basic(dict, "mode",
7163 DBUS_TYPE_UINT32, &mode);
7166 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
7168 DBusMessageIter dict;
7169 struct interface_connect_data *data = user_data;
7170 GSupplicantSSID *ssid = data->ssid;
7171 #if defined TIZEN_EXT
7172 GSupplicantInterface *interface = data->interface;
7175 supplicant_dbus_dict_open(iter, &dict);
7177 if (ssid->scan_ssid)
7178 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
7179 DBUS_TYPE_UINT32, &ssid->scan_ssid);
7182 supplicant_dbus_dict_append_basic(&dict, "frequency",
7183 DBUS_TYPE_UINT32, &ssid->freq);
7186 supplicant_dbus_dict_append_basic(&dict, "bgscan",
7187 DBUS_TYPE_STRING, &ssid->bgscan);
7189 add_network_mode(&dict, ssid);
7191 add_network_security(&dict, ssid);
7193 #if defined TIZEN_EXT
7194 add_network_ieee80211w(&dict, ssid);
7197 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
7198 DBUS_TYPE_BYTE, &ssid->ssid,
7201 #if defined TIZEN_EXT
7202 bool owe_transition_mode = FALSE;
7203 if ((ssid->security == G_SUPPLICANT_SECURITY_OWE) && !(ssid->keymgmt & G_SUPPLICANT_KEYMGMT_OWE))
7204 owe_transition_mode = TRUE;
7206 if (ssid->bssid && !owe_transition_mode) {
7208 bssid = g_try_malloc0(18);
7209 if (bssid == NULL) {
7210 SUPPLICANT_DBG("memory allocation error");
7211 supplicant_dbus_dict_close(iter, &dict);
7215 if (ssid->bssid_for_connect_len) {
7216 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid_for_connect));
7217 memcpy(interface->add_network_bssid, ssid->bssid_for_connect, WIFI_BSSID_LEN_MAX);
7219 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid));
7220 memcpy(interface->add_network_bssid, ssid->bssid, WIFI_BSSID_LEN_MAX);
7223 SUPPLICANT_DBG("bssid [" MACSTR "]", MAC2STR(interface->add_network_bssid));
7225 supplicant_dbus_dict_append_basic(&dict, "bssid",
7226 DBUS_TYPE_STRING, &bssid);
7231 supplicant_dbus_dict_close(iter, &dict);
7234 static void interface_wps_start_result(const char *error,
7235 DBusMessageIter *iter, void *user_data)
7237 struct interface_connect_data *data = user_data;
7244 SUPPLICANT_DBG("error: %s", error);
7245 err = parse_supplicant_error(iter);
7249 data->callback(err, data->interface, data->user_data);
7256 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
7258 struct interface_connect_data *data = user_data;
7259 GSupplicantSSID *ssid = data->ssid;
7260 const char *role = "enrollee", *type;
7261 DBusMessageIter dict;
7265 supplicant_dbus_dict_open(iter, &dict);
7267 supplicant_dbus_dict_append_basic(&dict, "Role",
7268 DBUS_TYPE_STRING, &role);
7271 if (ssid->pin_wps) {
7273 supplicant_dbus_dict_append_basic(&dict, "Pin",
7274 DBUS_TYPE_STRING, &ssid->pin_wps);
7277 supplicant_dbus_dict_append_basic(&dict, "Type",
7278 DBUS_TYPE_STRING, &type);
7280 #if defined TIZEN_EXT
7282 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
7283 DBUS_TYPE_BYTE, &ssid->bssid, 6);
7286 supplicant_dbus_dict_close(iter, &dict);
7289 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
7291 struct interface_connect_data *data = user_data;
7296 SUPPLICANT_DBG("error: %s", error);
7303 #if defined TIZEN_EXT
7304 GSupplicantSSID *ssid = data->ssid;
7305 if (ssid->pin_wps != NULL) {
7306 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
7307 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
7314 supplicant_dbus_method_call(data->interface->path,
7315 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
7316 interface_add_wps_params,
7317 interface_wps_start_result, data, NULL);
7320 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
7322 dbus_bool_t credentials = TRUE;
7326 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
7330 #if defined TIZEN_EXT
7331 #define NETCONFIG_SERVICE "net.netconfig"
7332 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
7333 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
7335 struct dec_method_call_data {
7336 struct interface_connect_data *data;
7337 DBusPendingCall *pending_call;
7340 static struct dec_method_call_data decrypt_request_data;
7342 static void crypt_method_call_cancel(void)
7344 if (decrypt_request_data.pending_call) {
7345 dbus_pending_call_cancel(decrypt_request_data.pending_call);
7346 dbus_pending_call_unref(decrypt_request_data.pending_call);
7347 decrypt_request_data.pending_call = NULL;
7350 g_free(decrypt_request_data.data->path);
7351 g_free(decrypt_request_data.data->ssid);
7352 dbus_free(decrypt_request_data.data);
7353 decrypt_request_data.data = NULL;
7356 static void decryption_request_reply(DBusPendingCall *call,
7361 DBusMessageIter args;
7364 struct interface_connect_data *data = user_data;
7368 reply = dbus_pending_call_steal_reply(call);
7370 dbus_error_init(&error);
7371 if (dbus_set_error_from_message(&error, reply)) {
7372 SUPPLICANT_DBG("decryption_request_reply() %s %s", error.name, error.message);
7373 dbus_error_free(&error);
7378 if (dbus_message_iter_init(reply, &args) == FALSE) {
7379 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7384 dbus_message_iter_get_basic(&args, &out_data);
7385 data->ssid->passphrase = g_strdup((const gchar *)out_data);
7387 ret = supplicant_dbus_method_call(data->interface->path,
7388 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7389 interface_add_network_params,
7390 interface_add_network_result, data,
7395 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7396 callback_assoc_failed(decrypt_request_data.data->user_data);
7398 g_free(data->ssid->ssid);
7399 g_free((char *)data->ssid->passphrase);
7400 g_free((char *)data->ssid->connector);
7401 g_free((char *)data->ssid->c_sign_key);
7402 g_free((char *)data->ssid->net_access_key);
7407 dbus_message_unref(reply);
7408 dbus_pending_call_unref(call);
7410 decrypt_request_data.pending_call = NULL;
7411 decrypt_request_data.data = NULL;
7414 static int send_decryption_request(const char *passphrase,
7415 struct interface_connect_data *data)
7417 DBusMessage *msg = NULL;
7418 DBusPendingCall *call;
7420 SUPPLICANT_DBG("Decryption request");
7423 SUPPLICANT_DBG("Invalid parameter");
7430 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7431 NETCONFIG_WIFI_INTERFACE, "DecryptPassphrase");
7435 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7438 if (!dbus_connection_send_with_reply(connection, msg,
7439 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7440 dbus_message_unref(msg);
7445 dbus_message_unref(msg);
7449 decrypt_request_data.pending_call = call;
7450 decrypt_request_data.data = data;
7452 dbus_pending_call_set_notify(call, decryption_request_reply, data, NULL);
7453 dbus_message_unref(msg);
7455 SUPPLICANT_DBG("Decryption request succeeded");
7460 static void decrypt_conf_obj_reply(DBusPendingCall *call,
7465 DBusMessageIter iter, dict;
7468 struct interface_connect_data *data = user_data;
7470 reply = dbus_pending_call_steal_reply(call);
7472 dbus_error_init(&error);
7473 if (dbus_set_error_from_message(&error, reply)) {
7474 SUPPLICANT_DBG("decryption_conf_obj_reply() %s %s", error.name, error.message);
7475 dbus_error_free(&error);
7480 if (dbus_message_iter_init(reply, &iter) == FALSE) {
7481 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7486 dbus_message_iter_recurse(&iter, &dict);
7488 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
7489 DBusMessageIter entry, value;
7492 dbus_message_iter_recurse(&dict, &entry);
7493 dbus_message_iter_get_basic(&entry, &key);
7494 dbus_message_iter_next(&entry);
7495 dbus_message_iter_recurse(&entry, &value);
7496 if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
7497 if (g_strcmp0(key, "connector") == 0) {
7498 dbus_message_iter_get_basic(&value, &out_data);
7499 data->ssid->connector = g_strdup((const gchar *)out_data);
7500 SUPPLICANT_DBG("connector %s", data->ssid->connector);
7501 } else if (g_strcmp0(key, "c_sign_key") == 0) {
7502 dbus_message_iter_get_basic(&value, &out_data);
7503 data->ssid->c_sign_key = g_strdup((const gchar *)out_data);
7504 SUPPLICANT_DBG("c_sign_key %s", data->ssid->c_sign_key);
7505 } else if (g_strcmp0(key, "net_access_key") == 0) {
7506 dbus_message_iter_get_basic(&value, &out_data);
7507 data->ssid->net_access_key = g_strdup((const gchar *)out_data);
7508 SUPPLICANT_DBG("net_access_key %s", data->ssid->net_access_key);
7511 dbus_message_iter_next(&dict);
7514 ret = supplicant_dbus_method_call(data->interface->path,
7515 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7516 interface_add_network_params,
7517 interface_add_network_result, data,
7522 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7523 callback_assoc_failed(decrypt_request_data.data->user_data);
7525 g_free(data->ssid->ssid);
7526 g_free((char *)data->ssid->connector);
7527 g_free((char *)data->ssid->c_sign_key);
7528 g_free((char *)data->ssid->net_access_key);
7533 dbus_message_unref(reply);
7534 dbus_pending_call_unref(call);
7536 decrypt_request_data.pending_call = NULL;
7537 decrypt_request_data.data = NULL;
7540 static int send_decryption_conf_obj_request(GSupplicantSSID *ssid,
7541 struct interface_connect_data *data)
7543 DBusMessage *msg = NULL;
7544 DBusPendingCall *call;
7546 SUPPLICANT_DBG("Decryption configuration object request");
7549 SUPPLICANT_DBG("Invalid parameter");
7556 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7557 NETCONFIG_WIFI_INTERFACE, "DecryptConfObj");
7561 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->connector,
7563 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->c_sign_key,
7565 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->net_access_key,
7568 if (!dbus_connection_send_with_reply(connection, msg,
7569 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7570 dbus_message_unref(msg);
7575 dbus_message_unref(msg);
7579 decrypt_request_data.pending_call = call;
7580 decrypt_request_data.data = data;
7582 dbus_pending_call_set_notify(call, decrypt_conf_obj_reply, data, NULL);
7583 dbus_message_unref(msg);
7585 SUPPLICANT_DBG("Decrypt Conf Obj request succeeded");
7590 static bool is_valid_config_object(GSupplicantSSID *ssid)
7592 return ((ssid->connector &&
7593 g_strcmp0(ssid->connector, "") != 0) &&
7594 (ssid->c_sign_key &&
7595 g_strcmp0(ssid->c_sign_key, "") != 0) &&
7596 (ssid->net_access_key &&
7597 g_strcmp0(ssid->net_access_key, "") != 0));
7601 int g_supplicant_interface_connect(GSupplicantInterface *interface,
7602 GSupplicantSSID *ssid,
7603 GSupplicantInterfaceCallback callback,
7606 struct interface_connect_data *data;
7607 struct interface_data *intf_data;
7615 if (!system_available)
7618 /* TODO: Check if we're already connected and switch */
7620 data = dbus_malloc0(sizeof(*data));
7624 data->interface = interface;
7625 data->path = g_strdup(interface->path);
7626 data->callback = callback;
7628 data->user_data = user_data;
7630 if (ssid->use_wps) {
7631 g_free(interface->wps_cred.key);
7632 memset(&interface->wps_cred, 0,
7633 sizeof(struct _GSupplicantWpsCredentials));
7635 ret = supplicant_dbus_property_set(interface->path,
7636 SUPPLICANT_INTERFACE ".Interface.WPS",
7637 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
7638 wps_process_credentials, wps_start, data, interface);
7640 /* By the time there is a request for connect and the network
7641 * path is not NULL it means that connman has not removed the
7642 * previous network pointer. This can happen in the case AP
7643 * deauthenticated client and connman does not remove the
7644 * previously connected network pointer. This causes supplicant
7645 * to reallocate the memory for struct wpa_ssid again even if it
7646 * is the same SSID. This causes memory usage of wpa_supplicnat
7647 * to go high. The idea here is that if the previously connected
7648 * network is not removed at the time of next connection attempt
7649 * check if the network path is not NULL. In case it is non-NULL
7650 * first remove the network and then once removal is successful, add
7654 if (interface->network_path != NULL) {
7659 * If this add network is for the same network for
7660 * which wpa_supplicant already has a profile then do
7661 * not need to add another profile. Only if the
7662 * profile that needs to get added is different from
7663 * what is there in wpa_s delete the current one. A
7664 * network is identified by its SSID, security_type
7665 * and passphrase (private passphrase in case security
7668 if (compare_network_parameters(interface, ssid)) {
7672 intf_data = dbus_malloc0(sizeof(*intf_data));
7676 intf_data->interface = interface;
7677 intf_data->path = g_strdup(interface->path);
7678 intf_data->callback = callback;
7679 intf_data->ssid = ssid;
7680 intf_data->user_data = user_data;
7681 intf_data->network_remove_in_progress = TRUE;
7682 network_remove(intf_data);
7684 #if defined TIZEN_EXT
7685 if (ssid->passphrase &&
7686 g_strcmp0(ssid->passphrase, "") != 0 &&
7687 #if defined TIZEN_EXT_WIFI_MESH
7688 ssid->mode != G_SUPPLICANT_MODE_MESH &&
7691 ret = send_decryption_request(ssid->passphrase, data);
7693 SUPPLICANT_DBG("Decryption request failed %d", ret);
7694 } else if (is_valid_config_object(ssid)) {
7695 ret = send_decryption_conf_obj_request(ssid, data);
7697 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
7701 ret = supplicant_dbus_method_call(interface->path,
7702 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7703 interface_add_network_params,
7704 interface_add_network_result, data,
7715 return -EINPROGRESS;
7718 static void network_remove_result(const char *error,
7719 DBusMessageIter *iter, void *user_data)
7721 struct interface_data *data = user_data;
7722 struct interface_connect_data *connect_data;
7729 SUPPLICANT_DBG("error: %s", error);
7731 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
7733 result = -ECONNABORTED;
7736 g_free(data->interface->network_path);
7737 data->interface->network_path = NULL;
7739 remove_network_information(data->interface);
7741 if (data->network_remove_in_progress == TRUE) {
7742 data->network_remove_in_progress = FALSE;
7743 connect_data = dbus_malloc0(sizeof(*connect_data));
7747 connect_data->interface = data->interface;
7748 connect_data->path = g_strdup(data->path);
7749 connect_data->callback = data->callback;
7750 connect_data->ssid = data->ssid;
7751 connect_data->user_data = data->user_data;
7753 #if defined TIZEN_EXT
7755 if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
7756 && !data->ssid->eap) {
7757 ret = send_decryption_request(data->ssid->passphrase, connect_data);
7759 SUPPLICANT_DBG("Decryption request failed %d", ret);
7760 g_free(connect_data->ssid);
7761 g_free(connect_data->path);
7762 dbus_free(connect_data);
7764 } else if (is_valid_config_object(data->ssid)) {
7765 ret = send_decryption_conf_obj_request(data->ssid, connect_data);
7767 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
7768 g_free(connect_data->ssid);
7769 g_free(connect_data->path);
7770 dbus_free(connect_data);
7774 supplicant_dbus_method_call(data->interface->path,
7775 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7776 interface_add_network_params,
7777 interface_add_network_result, connect_data,
7778 connect_data->interface);
7781 data->callback(result, data->interface, data->user_data);
7787 static void network_remove_params(DBusMessageIter *iter, void *user_data)
7789 struct interface_data *data = user_data;
7790 const char *path = data->interface->network_path;
7792 SUPPLICANT_DBG("path %s", path);
7794 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
7797 static int network_remove(struct interface_data *data)
7799 GSupplicantInterface *interface = data->interface;
7803 #if defined TIZEN_EXT
7804 GSupplicantInterface *intf = NULL;
7806 * Check if 'interface' is valid
7808 intf = g_hash_table_lookup(interface_table, interface->path);
7813 return supplicant_dbus_method_call(interface->path,
7814 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
7815 network_remove_params, network_remove_result, data,
7819 static void interface_disconnect_result(const char *error,
7820 DBusMessageIter *iter, void *user_data)
7822 struct interface_data *data = user_data;
7829 SUPPLICANT_DBG("error: %s", error);
7831 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
7833 result = -ECONNABORTED;
7836 /* If we are disconnecting from previous WPS successful
7837 * association. i.e.: it did not went through AddNetwork,
7838 * and interface->network_path was never set. */
7839 if (!data->interface->network_path) {
7841 data->callback(result, data->interface,
7849 if (result < 0 && data->callback) {
7850 data->callback(result, data->interface, data->user_data);
7851 data->callback = NULL;
7854 if (result != -ECONNABORTED) {
7855 if (network_remove(data) < 0) {
7865 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
7866 GSupplicantInterfaceCallback callback,
7869 struct interface_data *data;
7877 if (!system_available)
7879 #if defined TIZEN_EXT
7880 if (decrypt_request_data.pending_call &&
7881 decrypt_request_data.data &&
7882 decrypt_request_data.data->user_data == user_data) {
7884 callback_assoc_failed(decrypt_request_data.data->user_data);
7885 crypt_method_call_cancel();
7890 data = dbus_malloc0(sizeof(*data));
7894 data->interface = interface;
7895 data->path = g_strdup(interface->path);
7896 data->callback = callback;
7897 data->user_data = user_data;
7899 ret = supplicant_dbus_method_call(interface->path,
7900 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
7901 NULL, interface_disconnect_result, data,
7912 static void interface_p2p_find_result(const char *error,
7913 DBusMessageIter *iter, void *user_data)
7915 struct interface_scan_data *data = user_data;
7918 SUPPLICANT_DBG("error %s", error);
7923 if (interface_exists(data->interface, data->path)) {
7924 if (!data->interface->ready)
7927 data->interface->p2p_finding = true;
7931 data->callback(err, data->interface, data->user_data);
7937 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
7939 DBusMessageIter dict;
7941 supplicant_dbus_dict_open(iter, &dict);
7942 supplicant_dbus_dict_close(iter, &dict);
7945 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
7946 GSupplicantInterfaceCallback callback,
7949 struct interface_scan_data *data;
7952 if (!interface->p2p_support)
7955 ret = interface_ready_to_scan(interface);
7956 if (ret && ret != -EALREADY)
7959 data = dbus_malloc0(sizeof(*data));
7963 data->interface = interface;
7964 data->path = g_strdup(interface->path);
7965 data->callback = callback;
7966 data->user_data = user_data;
7968 ret = supplicant_dbus_method_call(interface->path,
7969 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
7970 interface_p2p_find_params, interface_p2p_find_result,
7980 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
7985 return interface->p2p_finding;
7988 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
7990 if (!interface->p2p_finding)
7995 interface->p2p_finding = false;
7997 return supplicant_dbus_method_call(interface->path,
7998 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
7999 NULL, NULL, NULL, NULL);
8002 static void interface_p2p_connect_result(const char *error,
8003 DBusMessageIter *iter, void *user_data)
8005 struct interface_connect_data *data = user_data;
8011 SUPPLICANT_DBG("error: %s", error);
8012 err = parse_supplicant_error(iter);
8016 data->callback(err, data->interface, data->user_data);
8019 g_free(data->peer->wps_pin);
8020 g_free(data->peer->path);
8025 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
8027 struct interface_connect_data *data = user_data;
8028 const char *wps = "pbc";
8029 DBusMessageIter dict;
8034 supplicant_dbus_dict_open(iter, &dict);
8036 if (data->peer->master)
8039 if (data->peer->wps_pin)
8042 supplicant_dbus_dict_append_basic(&dict, "peer",
8043 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
8044 supplicant_dbus_dict_append_basic(&dict, "wps_method",
8045 DBUS_TYPE_STRING, &wps);
8046 if (data->peer->wps_pin) {
8047 supplicant_dbus_dict_append_basic(&dict, "pin",
8048 DBUS_TYPE_STRING, &data->peer->wps_pin);
8051 supplicant_dbus_dict_append_basic(&dict, "go_intent",
8052 DBUS_TYPE_INT32, &go_intent);
8054 supplicant_dbus_dict_close(iter, &dict);
8057 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
8058 GSupplicantPeerParams *peer_params,
8059 GSupplicantInterfaceCallback callback,
8062 struct interface_connect_data *data;
8067 if (!interface->p2p_support)
8070 data = dbus_malloc0(sizeof(*data));
8074 data->interface = interface;
8075 data->path = g_strdup(interface->path);
8076 data->peer = peer_params;
8077 data->callback = callback;
8078 data->user_data = user_data;
8080 ret = supplicant_dbus_method_call(interface->path,
8081 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
8082 interface_p2p_connect_params, interface_p2p_connect_result,
8090 return -EINPROGRESS;
8093 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
8094 GSupplicantPeerParams *peer_params)
8096 GSupplicantPeer *peer;
8102 if (!interface->p2p_support)
8105 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
8109 for (list = peer->groups; list; list = list->next, count++) {
8110 const char *group_obj_path = list->data;
8111 GSupplicantInterface *g_interface;
8112 GSupplicantGroup *group;
8114 group = g_hash_table_lookup(group_mapping, group_obj_path);
8115 if (!group || !group->interface)
8118 g_interface = group->interface;
8119 supplicant_dbus_method_call(g_interface->path,
8120 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8121 "Disconnect", NULL, NULL, NULL, g_interface);
8124 if (count == 0 && peer->current_group_iface) {
8125 supplicant_dbus_method_call(peer->current_group_iface->path,
8126 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8127 "Disconnect", NULL, NULL, NULL,
8128 peer->current_group_iface->path);
8131 peer->current_group_iface = NULL;
8133 return -EINPROGRESS;
8136 struct p2p_service_data {
8138 GSupplicantInterface *interface;
8139 GSupplicantP2PServiceParams *service;
8140 GSupplicantInterfaceCallback callback;
8144 static void interface_p2p_service_result(const char *error,
8145 DBusMessageIter *iter, void *user_data)
8147 struct p2p_service_data *data = user_data;
8150 SUPPLICANT_DBG("%s result - %s", data->registration ?
8151 "Registration" : "Deletion",
8152 error ? error : "Success");
8157 data->callback(result, data->interface, data->user_data);
8159 g_free(data->service->query);
8160 g_free(data->service->response);
8161 g_free(data->service->service);
8162 g_free(data->service->wfd_ies);
8163 g_free(data->service);
8167 static void interface_p2p_service_params(DBusMessageIter *iter,
8170 struct p2p_service_data *data = user_data;
8171 GSupplicantP2PServiceParams *service;
8172 DBusMessageIter dict;
8177 service = data->service;
8179 supplicant_dbus_dict_open(iter, &dict);
8181 if (service->query && service->response) {
8183 supplicant_dbus_dict_append_basic(&dict, "service_type",
8184 DBUS_TYPE_STRING, &type);
8185 supplicant_dbus_dict_append_fixed_array(&dict, "query",
8186 DBUS_TYPE_BYTE, &service->query,
8187 service->query_length);
8188 supplicant_dbus_dict_append_fixed_array(&dict, "response",
8189 DBUS_TYPE_BYTE, &service->response,
8190 service->response_length);
8191 } else if (service->version && service->service) {
8193 supplicant_dbus_dict_append_basic(&dict, "service_type",
8194 DBUS_TYPE_STRING, &type);
8195 supplicant_dbus_dict_append_basic(&dict, "version",
8196 DBUS_TYPE_INT32, &service->version);
8197 supplicant_dbus_dict_append_basic(&dict, "service",
8198 DBUS_TYPE_STRING, &service->service);
8201 supplicant_dbus_dict_close(iter, &dict);
8204 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
8205 GSupplicantInterfaceCallback callback,
8206 GSupplicantP2PServiceParams *p2p_service_params,
8209 struct p2p_service_data *data;
8214 if (!interface->p2p_support)
8217 data = dbus_malloc0(sizeof(*data));
8221 data->registration = true;
8222 data->interface = interface;
8223 data->service = p2p_service_params;
8224 data->callback = callback;
8225 data->user_data = user_data;
8227 ret = supplicant_dbus_method_call(interface->path,
8228 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
8229 interface_p2p_service_params, interface_p2p_service_result,
8236 return -EINPROGRESS;
8239 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
8240 GSupplicantP2PServiceParams *p2p_service_params)
8242 struct p2p_service_data *data;
8247 if (!interface->p2p_support)
8250 data = dbus_malloc0(sizeof(*data));
8254 data->interface = interface;
8255 data->service = p2p_service_params;
8257 ret = supplicant_dbus_method_call(interface->path,
8258 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
8259 interface_p2p_service_params, interface_p2p_service_result,
8266 return -EINPROGRESS;
8269 struct p2p_listen_data {
8274 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
8276 struct p2p_listen_data *params = user_data;
8277 DBusMessageIter dict;
8279 supplicant_dbus_dict_open(iter, &dict);
8281 supplicant_dbus_dict_append_basic(&dict, "period",
8282 DBUS_TYPE_INT32, ¶ms->period);
8283 supplicant_dbus_dict_append_basic(&dict, "interval",
8284 DBUS_TYPE_INT32, ¶ms->interval);
8285 supplicant_dbus_dict_close(iter, &dict);
8288 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
8289 int period, int interval)
8291 struct p2p_listen_data params;
8295 if (!interface->p2p_support)
8298 params.period = period;
8299 params.interval = interval;
8301 return supplicant_dbus_method_call(interface->path,
8302 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8303 "ExtendedListen", interface_p2p_listen_params,
8304 NULL, ¶ms, NULL);
8307 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
8309 struct p2p_service_data *data = user_data;
8310 GSupplicantP2PServiceParams *service = data->service;
8311 DBusMessageIter array;
8313 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
8315 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
8316 DBUS_TYPE_BYTE_AS_STRING, &array);
8318 if (service->wfd_ies && service->wfd_ies_length > 0) {
8319 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
8320 &service->wfd_ies, service->wfd_ies_length);
8323 dbus_message_iter_close_container(iter, &array);
8326 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
8327 GSupplicantInterfaceCallback callback,
8330 struct p2p_service_data *data;
8335 if (!system_available)
8338 data = dbus_malloc0(sizeof(*data));
8342 data->service = p2p_service_params;
8343 data->callback = callback;
8344 data->user_data = user_data;
8346 if (p2p_service_params->wfd_ies)
8347 data->registration = true;
8349 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
8350 SUPPLICANT_INTERFACE, "WFDIEs",
8351 DBUS_TYPE_ARRAY_AS_STRING
8352 DBUS_TYPE_BYTE_AS_STRING,
8354 interface_p2p_service_result,
8356 if (ret < 0 && ret != -EINPROGRESS) {
8361 return -EINPROGRESS;
8365 static const char *g_supplicant_rule0 = "type=signal,"
8366 "path=" DBUS_PATH_DBUS ","
8367 "sender=" DBUS_SERVICE_DBUS ","
8368 "interface=" DBUS_INTERFACE_DBUS ","
8369 "member=NameOwnerChanged,"
8370 "arg0=" SUPPLICANT_SERVICE;
8371 static const char *g_supplicant_rule1 = "type=signal,"
8372 "interface=" SUPPLICANT_INTERFACE;
8373 static const char *g_supplicant_rule2 = "type=signal,"
8374 "interface=" SUPPLICANT_INTERFACE ".Interface";
8375 static const char *g_supplicant_rule3 = "type=signal,"
8376 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
8377 static const char *g_supplicant_rule4 = "type=signal,"
8378 "interface=" SUPPLICANT_INTERFACE ".BSS";
8379 static const char *g_supplicant_rule5 = "type=signal,"
8380 "interface=" SUPPLICANT_INTERFACE ".Network";
8381 #if !defined TIZEN_EXT
8382 static const char *g_supplicant_rule6 = "type=signal,"
8383 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
8384 static const char *g_supplicant_rule7 = "type=signal,"
8385 "interface=" SUPPLICANT_INTERFACE ".Peer";
8386 static const char *g_supplicant_rule8 = "type=signal,"
8387 "interface=" SUPPLICANT_INTERFACE ".Group";
8389 #if defined TIZEN_EXT_WIFI_MESH
8390 static const char *g_supplicant_rule9 = "type=signal,"
8391 "interface=" SUPPLICANT_INTERFACE ".Interface.Mesh";
8394 static void invoke_introspect_method(void)
8396 DBusMessage *message;
8398 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
8400 DBUS_INTERFACE_INTROSPECTABLE,
8406 dbus_message_set_no_reply(message, TRUE);
8407 dbus_connection_send(connection, message, NULL);
8408 dbus_message_unref(message);
8411 #if defined TIZEN_EXT
8412 void g_supplicant_set_ins_settings(GSupplicantINSPreferredFreq preferred_freq_bssid,
8413 bool last_connected_bssid, bool assoc_reject, bool signal_bssid,
8414 unsigned int preferred_freq_bssid_score, unsigned int last_connected_bssid_score,
8415 unsigned int assoc_reject_score, int signal_level3_5ghz, int signal_level3_24ghz)
8417 ins_settings.preferred_freq_bssid = preferred_freq_bssid;
8418 ins_settings.last_connected_bssid = last_connected_bssid;
8419 ins_settings.assoc_reject = assoc_reject;
8420 ins_settings.signal_bssid = signal_bssid;
8421 ins_settings.preferred_freq_bssid_score = preferred_freq_bssid_score;
8422 ins_settings.last_connected_bssid_score = last_connected_bssid_score;
8423 ins_settings.assoc_reject_score = assoc_reject_score;
8424 ins_settings.signal_level3_5ghz = signal_level3_5ghz;
8425 ins_settings.signal_level3_24ghz = signal_level3_24ghz;
8427 SUPPLICANT_DBG("preferred_freq_bssid [%s]", preferred_freq_bssid ? "true" : "false");
8428 SUPPLICANT_DBG("preferred_freq_bssid_score [%d]", preferred_freq_bssid_score);
8429 SUPPLICANT_DBG("last_connected_bssid [%s]", last_connected_bssid ? "true" : "false");
8430 SUPPLICANT_DBG("last_connected_bssid_score [%d]", last_connected_bssid_score);
8431 SUPPLICANT_DBG("assoc_reject [%s]", assoc_reject ? "true" : "false");
8432 SUPPLICANT_DBG("assoc_reject_score [%d]", assoc_reject_score);
8433 SUPPLICANT_DBG("signal_bssid [%s]", signal_bssid ? "true" : "false");
8434 SUPPLICANT_DBG("signal_level3_5ghz [%d]", signal_level3_5ghz);
8435 SUPPLICANT_DBG("signal_level3_24ghz [%d]", signal_level3_24ghz);
8439 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8440 void g_supplicant_register_eap_callback(g_supplicant_eap_callback cb)
8442 SUPPLICANT_DBG("g_supplicant_register_eap_callback %p", cb);
8444 if (!callbacks_pointer) {
8445 SUPPLICANT_DBG("callbacks_pointer is NULL");
8449 callbacks_pointer->eap = cb;
8452 void g_supplicant_unregister_eap_callback(void)
8454 SUPPLICANT_DBG("g_supplicant_unregister_eap_callback");
8456 if (!callbacks_pointer) {
8457 SUPPLICANT_DBG("callbacks_pointer is NULL");
8461 callbacks_pointer->eap = NULL;
8463 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8465 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8466 int g_supplicant_register(GSupplicantCallbacks *callbacks)
8467 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8468 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
8469 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8471 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8475 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
8477 dbus_connection_unref(connection);
8482 callbacks_pointer = callbacks;
8485 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8486 NULL, remove_interface);
8488 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8490 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8492 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8494 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
8496 config_file_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8499 supplicant_dbus_setup(connection);
8501 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
8502 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
8503 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
8504 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
8505 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
8506 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
8507 #if defined TIZEN_EXT
8508 dbus_bus_add_match(connection,
8509 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
8510 "member=ChangeState", NULL);
8512 #if !defined TIZEN_EXT
8513 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
8514 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
8515 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
8517 #if defined TIZEN_EXT_WIFI_MESH
8518 dbus_bus_add_match(connection, g_supplicant_rule9, NULL);
8520 dbus_connection_flush(connection);
8522 if (dbus_bus_name_has_owner(connection,
8523 SUPPLICANT_SERVICE, NULL)) {
8524 system_available = TRUE;
8525 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
8526 SUPPLICANT_INTERFACE,
8527 service_property, NULL, NULL);
8529 invoke_introspect_method();
8531 SUPPLICANT_DBG("supplicant dbus setup completed");
8535 static void unregister_interface_remove_params(DBusMessageIter *iter,
8538 const char *path = user_data;
8540 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
8545 static void unregister_remove_interface(gpointer key, gpointer value,
8548 GSupplicantInterface *interface = value;
8550 supplicant_dbus_method_call(SUPPLICANT_PATH,
8551 SUPPLICANT_INTERFACE,
8553 unregister_interface_remove_params,
8554 NULL, interface->path, NULL);
8557 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
8562 #if defined TIZEN_EXT_WIFI_MESH
8563 dbus_bus_remove_match(connection, g_supplicant_rule9, NULL);
8565 #if !defined TIZEN_EXT
8566 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
8567 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
8568 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
8570 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
8571 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
8572 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
8573 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
8574 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
8575 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
8576 dbus_connection_flush(connection);
8578 dbus_connection_remove_filter(connection,
8579 g_supplicant_filter, NULL);
8582 if (config_file_table) {
8583 g_hash_table_destroy(config_file_table);
8584 config_file_table = NULL;
8588 g_hash_table_destroy(bss_mapping);
8593 g_hash_table_destroy(peer_mapping);
8594 peer_mapping = NULL;
8597 if (group_mapping) {
8598 g_hash_table_destroy(group_mapping);
8599 group_mapping = NULL;
8602 if (interface_table) {
8603 g_hash_table_foreach(interface_table,
8604 unregister_remove_interface, NULL);
8605 g_hash_table_destroy(interface_table);
8606 interface_table = NULL;
8609 if (system_available)
8610 callback_system_killed();
8613 dbus_connection_unref(connection);
8617 callbacks_pointer = NULL;