3 * WPA supplicant library with GLib integration
5 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include <netinet/if_ether.h>
35 #include <netinet/in.h>
41 #include "gsupplicant.h"
47 #define IEEE80211_CAP_ESS 0x0001
48 #define IEEE80211_CAP_IBSS 0x0002
49 #define IEEE80211_CAP_PRIVACY 0x0010
52 #define WLAN_EID_HT_CAP 45
53 #define WLAN_EID_VHT_CAP 191
54 #define WLAN_EID_SUPP_RATES 1
55 #define WLAN_EID_EXT_SUPP_RATES 50
56 #define COUNTRY_CODE_LENGTH 2
60 #define LAST_CONNECTED_TIMEOUT (5 * 60)
61 #define ASSOC_REJECT_TIMEOUT 10
62 #define FREQ_RANGE_24GHZ_CHANNEL_1 2412
63 #define FREQ_RANGE_24GHZ_CHANNEL_14 2484
64 #define FREQ_RANGE_5GHZ_CHANNEL_32 5160
65 #define FREQ_RANGE_5GHZ_CHANNEL_165 5825
67 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
68 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
71 #define BSS_UNKNOWN_STRENGTH -90
73 static DBusConnection *connection;
75 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
76 static GSupplicantCallbacks *callbacks_pointer;
77 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
78 static const GSupplicantCallbacks *callbacks_pointer;
79 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
81 static dbus_bool_t system_available = FALSE;
82 static dbus_bool_t system_ready = FALSE;
84 static dbus_int32_t debug_level;
85 static dbus_bool_t debug_timestamp = FALSE;
86 static dbus_bool_t debug_showkeys = FALSE;
88 static const char *debug_strings[] = {
89 "msgdump", "debug", "info", "warning", "error", NULL
92 static unsigned int eap_methods;
99 static struct strvalmap eap_method_map[] = {
100 { "MD5", G_SUPPLICANT_EAP_METHOD_MD5 },
101 { "TLS", G_SUPPLICANT_EAP_METHOD_TLS },
102 { "MSCHAPV2", G_SUPPLICANT_EAP_METHOD_MSCHAPV2 },
103 { "PEAP", G_SUPPLICANT_EAP_METHOD_PEAP },
104 { "TTLS", G_SUPPLICANT_EAP_METHOD_TTLS },
105 { "GTC", G_SUPPLICANT_EAP_METHOD_GTC },
106 { "OTP", G_SUPPLICANT_EAP_METHOD_OTP },
107 { "LEAP", G_SUPPLICANT_EAP_METHOD_LEAP },
108 { "WSC", G_SUPPLICANT_EAP_METHOD_WSC },
112 static struct strvalmap keymgmt_map[] = {
113 { "none", G_SUPPLICANT_KEYMGMT_NONE },
114 { "ieee8021x", G_SUPPLICANT_KEYMGMT_IEEE8021X },
115 { "wpa-none", G_SUPPLICANT_KEYMGMT_WPA_NONE },
116 { "wpa-psk", G_SUPPLICANT_KEYMGMT_WPA_PSK },
117 { "wpa-psk-sha256", G_SUPPLICANT_KEYMGMT_WPA_PSK_256 },
118 { "wpa-ft-psk", G_SUPPLICANT_KEYMGMT_WPA_FT_PSK },
119 { "wpa-ft-eap", G_SUPPLICANT_KEYMGMT_WPA_FT_EAP },
120 { "wpa-eap", G_SUPPLICANT_KEYMGMT_WPA_EAP },
121 { "wpa-eap-sha256", G_SUPPLICANT_KEYMGMT_WPA_EAP_256 },
122 { "wps", G_SUPPLICANT_KEYMGMT_WPS },
123 #if defined TIZEN_EXT
124 { "sae", G_SUPPLICANT_KEYMGMT_SAE },
125 { "ft-sae", G_SUPPLICANT_KEYMGMT_FT_SAE },
126 { "owe", G_SUPPLICANT_KEYMGMT_OWE },
127 { "dpp", G_SUPPLICANT_KEYMGMT_DPP },
132 static struct strvalmap authalg_capa_map[] = {
133 { "open", G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN },
134 { "shared", G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED },
135 { "leap", G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP },
139 static struct strvalmap proto_capa_map[] = {
140 { "wpa", G_SUPPLICANT_CAPABILITY_PROTO_WPA },
141 { "rsn", G_SUPPLICANT_CAPABILITY_PROTO_RSN },
145 static struct strvalmap group_map[] = {
146 { "wep40", G_SUPPLICANT_GROUP_WEP40 },
147 { "wep104", G_SUPPLICANT_GROUP_WEP104 },
148 { "tkip", G_SUPPLICANT_GROUP_TKIP },
149 { "ccmp", G_SUPPLICANT_GROUP_CCMP },
153 static struct strvalmap pairwise_map[] = {
154 { "none", G_SUPPLICANT_PAIRWISE_NONE },
155 { "tkip", G_SUPPLICANT_PAIRWISE_TKIP },
156 { "ccmp", G_SUPPLICANT_PAIRWISE_CCMP },
160 static struct strvalmap scan_capa_map[] = {
161 { "active", G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE },
162 { "passive", G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE },
163 { "ssid", G_SUPPLICANT_CAPABILITY_SCAN_SSID },
167 static struct strvalmap mode_capa_map[] = {
168 { "infrastructure", G_SUPPLICANT_CAPABILITY_MODE_INFRA },
169 { "ad-hoc", G_SUPPLICANT_CAPABILITY_MODE_IBSS },
170 { "ap", G_SUPPLICANT_CAPABILITY_MODE_AP },
171 { "p2p", G_SUPPLICANT_CAPABILITY_MODE_P2P },
172 #if defined TIZEN_EXT_WIFI_MESH
173 { "mesh", G_SUPPLICANT_CAPABILITY_MODE_MESH },
178 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
179 struct _GSupplicantINSSettings {
180 GSupplicantINSPreferredFreq preferred_freq_bssid;
181 unsigned int preferred_freq_bssid_score;
182 bool last_connected_bssid;
183 unsigned int last_connected_bssid_score;
185 unsigned int assoc_reject_score;
187 int signal_level3_5ghz;
188 int signal_level3_24ghz;
191 static struct _GSupplicantINSSettings ins_settings;
192 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
194 #if defined TIZEN_EXT
195 static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
200 static GHashTable *interface_table;
201 static GHashTable *bss_mapping;
202 static GHashTable *peer_mapping;
203 static GHashTable *group_mapping;
204 static GHashTable *pending_peer_connection;
205 static GHashTable *config_file_table;
207 struct _GSupplicantWpsCredentials {
208 unsigned char ssid[32];
209 unsigned int ssid_len;
213 struct added_network_information {
215 GSupplicantSecurity security;
217 char * private_passphrase;
218 #if defined TIZEN_EXT
221 char *net_access_key;
225 #if defined TIZEN_EXT_WIFI_MESH
226 struct _GSupplicantMeshGroupInfo {
227 unsigned char ssid[32];
228 unsigned int ssid_len;
229 int disconnect_reason;
233 struct _GSupplicantInterface {
236 unsigned int keymgmt_capa;
237 unsigned int authalg_capa;
238 unsigned int proto_capa;
239 unsigned int group_capa;
240 unsigned int pairwise_capa;
241 unsigned int scan_capa;
242 unsigned int mode_capa;
243 unsigned int max_scan_ssids;
246 bool ap_create_in_progress;
248 GSupplicantState state;
249 dbus_bool_t scanning;
250 GSupplicantInterfaceCallback scan_callback;
256 struct _GSupplicantWpsCredentials wps_cred;
257 GSupplicantWpsState wps_state;
258 GHashTable *network_table;
259 GHashTable *peer_table;
260 GHashTable *group_table;
261 GHashTable *bss_mapping;
263 const char *pending_peer_path;
264 GSupplicantNetwork *current_network;
265 struct added_network_information network_info;
266 #if defined TIZEN_EXT
267 dbus_bool_t is_5_0_Ghz_supported;
268 int disconnect_reason;
270 #if defined TIZEN_EXT
271 unsigned char add_network_bssid[WIFI_BSSID_LEN_MAX];
272 unsigned char connected_bssid[WIFI_BSSID_LEN_MAX];
274 #if defined TIZEN_EXT_WIFI_MESH
276 struct _GSupplicantMeshGroupInfo group_info;
280 struct g_supplicant_bss {
281 GSupplicantInterface *interface;
283 unsigned char bssid[6];
284 unsigned char ssid[32];
285 unsigned int ssid_len;
286 dbus_uint16_t frequency;
287 dbus_uint32_t maxrate;
289 GSupplicantMode mode;
290 GSupplicantSecurity security;
291 dbus_bool_t rsn_selected;
292 unsigned int wpa_keymgmt;
293 unsigned int wpa_pairwise;
294 unsigned int wpa_group;
295 unsigned int rsn_keymgmt;
296 unsigned int rsn_pairwise;
297 unsigned int rsn_group;
298 unsigned int keymgmt;
301 dbus_bool_t ieee8021x;
302 #if defined TIZEN_EXT
304 dbus_bool_t ft_ieee8021x;
307 unsigned char country_code[COUNTRY_CODE_LENGTH];
308 GSupplicantPhy_mode phy_mode;
310 dbus_uint32_t est_throughput;
312 unsigned int wps_capabilities;
313 #if defined TIZEN_EXT
317 dbus_bool_t owe_transition_mode;
318 unsigned int transition_mode_ssid_len;
319 unsigned char transition_mode_bssid[6];
320 unsigned char transition_mode_ssid[32];
321 dbus_bool_t pmf_required;
325 struct _GSupplicantNetwork {
326 GSupplicantInterface *interface;
330 unsigned char ssid[32];
331 unsigned int ssid_len;
333 dbus_uint16_t frequency;
334 struct g_supplicant_bss *best_bss;
335 GSupplicantMode mode;
336 GSupplicantSecurity security;
338 unsigned int wps_capabilities;
339 GHashTable *bss_table;
340 GHashTable *config_table;
341 #if defined TIZEN_EXT
346 unsigned int keymgmt;
348 unsigned char country_code[COUNTRY_CODE_LENGTH];
349 GSupplicantPhy_mode phy_mode;
350 dbus_bool_t owe_transition_mode;
352 unsigned int transition_mode_ssid_len;
353 unsigned char transition_mode_bssid[6];
354 unsigned char transition_mode_ssid[32];
355 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
356 GHashTable *assoc_reject_table;
360 struct _GSupplicantPeer {
361 GSupplicantInterface *interface;
363 unsigned char device_address[ETH_ALEN];
364 unsigned char iface_address[ETH_ALEN];
366 unsigned char *widi_ies;
369 unsigned int wps_capabilities;
371 const GSupplicantInterface *current_group_iface;
372 bool connection_requested;
375 struct _GSupplicantGroup {
376 GSupplicantInterface *interface;
377 GSupplicantInterface *orig_interface;
383 struct interface_data {
384 GSupplicantInterface *interface;
385 char *path; /* Interface path cannot be taken from interface (above) as
386 * it might have been freed already.
388 GSupplicantInterfaceCallback callback;
390 bool network_remove_in_progress;
391 GSupplicantSSID *ssid;
394 #if defined TIZEN_EXT
395 struct interface_signalpoll_data {
396 GSupplicantInterface *interface;
398 GSupplicantMaxSpeedCallback callback;
403 struct interface_create_data {
407 #if defined TIZEN_EXT
408 unsigned int mac_addr;
409 unsigned int preassoc_mac_addr;
410 unsigned int random_mac_lifetime;
411 #endif /* TIZEN_EXT */
412 #if defined TIZEN_EXT_WIFI_MESH
414 bool is_mesh_interface;
416 GSupplicantInterface *interface;
417 GSupplicantInterfaceCallback callback;
421 struct interface_connect_data {
422 GSupplicantInterface *interface;
424 GSupplicantInterfaceCallback callback;
427 GSupplicantSSID *ssid;
428 GSupplicantPeerParams *peer;
432 struct interface_scan_data {
433 GSupplicantInterface *interface;
435 GSupplicantInterfaceCallback callback;
436 GSupplicantScanParams *scan_params;
440 #if defined TIZEN_EXT
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;
459 static bool simplified_log = true;
462 static int network_remove(struct interface_data *data);
464 #if defined TIZEN_EXT_WIFI_MESH
465 struct _GSupplicantMeshPeer {
466 GSupplicantInterface *interface;
468 int disconnect_reason;
472 static inline void debug(const char *format, ...)
477 if (!callbacks_pointer || !callbacks_pointer->debug)
480 va_start(ap, format);
482 if (vsnprintf(str, sizeof(str), format, ap) > 0)
483 callbacks_pointer->debug(str);
488 #define SUPPLICANT_DBG(fmt, arg...) \
489 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
491 static GSupplicantMode string2mode(const char *mode)
494 return G_SUPPLICANT_MODE_UNKNOWN;
496 if (g_str_equal(mode, "infrastructure"))
497 return G_SUPPLICANT_MODE_INFRA;
498 else if (g_str_equal(mode, "ad-hoc"))
499 return G_SUPPLICANT_MODE_IBSS;
500 #if defined TIZEN_EXT_WIFI_MESH
501 else if (g_str_equal(mode, "mesh"))
502 return G_SUPPLICANT_MODE_MESH;
505 return G_SUPPLICANT_MODE_UNKNOWN;
508 static const char *mode2string(GSupplicantMode mode)
511 case G_SUPPLICANT_MODE_UNKNOWN:
513 case G_SUPPLICANT_MODE_INFRA:
515 case G_SUPPLICANT_MODE_IBSS:
517 case G_SUPPLICANT_MODE_MASTER:
519 #if defined TIZEN_EXT_WIFI_MESH
520 case G_SUPPLICANT_MODE_MESH:
528 static const char *security2string(GSupplicantSecurity security)
531 case G_SUPPLICANT_SECURITY_UNKNOWN:
533 case G_SUPPLICANT_SECURITY_NONE:
535 case G_SUPPLICANT_SECURITY_WEP:
537 case G_SUPPLICANT_SECURITY_PSK:
539 case G_SUPPLICANT_SECURITY_IEEE8021X:
541 #if defined TIZEN_EXT
542 case G_SUPPLICANT_SECURITY_FT_PSK:
544 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
545 return "ft_ieee8021x";
546 case G_SUPPLICANT_SECURITY_SAE:
548 case G_SUPPLICANT_SECURITY_OWE:
550 case G_SUPPLICANT_SECURITY_DPP:
558 static GSupplicantState string2state(const char *state)
561 return G_SUPPLICANT_STATE_UNKNOWN;
563 if (g_str_equal(state, "unknown"))
564 return G_SUPPLICANT_STATE_UNKNOWN;
565 else if (g_str_equal(state, "interface_disabled"))
566 return G_SUPPLICANT_STATE_DISABLED;
567 else if (g_str_equal(state, "disconnected"))
568 return G_SUPPLICANT_STATE_DISCONNECTED;
569 else if (g_str_equal(state, "inactive"))
570 return G_SUPPLICANT_STATE_INACTIVE;
571 else if (g_str_equal(state, "scanning"))
572 return G_SUPPLICANT_STATE_SCANNING;
573 else if (g_str_equal(state, "authenticating"))
574 return G_SUPPLICANT_STATE_AUTHENTICATING;
575 else if (g_str_equal(state, "associating"))
576 return G_SUPPLICANT_STATE_ASSOCIATING;
577 else if (g_str_equal(state, "associated"))
578 return G_SUPPLICANT_STATE_ASSOCIATED;
579 else if (g_str_equal(state, "group_handshake"))
580 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
581 else if (g_str_equal(state, "4way_handshake"))
582 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
583 else if (g_str_equal(state, "completed"))
584 return G_SUPPLICANT_STATE_COMPLETED;
586 return G_SUPPLICANT_STATE_UNKNOWN;
589 static bool compare_network_parameters(GSupplicantInterface *interface,
590 GSupplicantSSID *ssid)
592 #if defined TIZEN_EXT
593 if (!interface->network_info.ssid)
597 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
600 if (interface->network_info.security != ssid->security)
603 if (interface->network_info.passphrase &&
604 g_strcmp0(interface->network_info.passphrase,
605 ssid->passphrase) != 0) {
609 if (interface->network_info.private_passphrase &&
610 g_strcmp0(interface->network_info.private_passphrase,
611 ssid->private_key_passphrase) != 0) {
615 #if defined TIZEN_EXT
616 if (interface->network_info.connector &&
617 g_strcmp0(interface->network_info.connector,
618 ssid->connector) != 0) {
621 if (interface->network_info.c_sign_key &&
622 g_strcmp0(interface->network_info.c_sign_key,
623 ssid->c_sign_key) != 0) {
626 if (interface->network_info.net_access_key &&
627 g_strcmp0(interface->network_info.net_access_key,
628 ssid->net_access_key) != 0) {
635 static void remove_network_information(GSupplicantInterface * interface)
637 g_free(interface->network_info.ssid);
638 g_free(interface->network_info.passphrase);
639 g_free(interface->network_info.private_passphrase);
640 #if defined TIZEN_EXT
641 g_free(interface->network_info.connector);
642 g_free(interface->network_info.c_sign_key);
643 g_free(interface->network_info.net_access_key);
645 interface->network_info.ssid = NULL;
646 interface->network_info.passphrase = NULL;
647 interface->network_info.private_passphrase = NULL;
648 #if defined TIZEN_EXT
649 interface->network_info.connector = NULL;
650 interface->network_info.c_sign_key = NULL;
651 interface->network_info.net_access_key = NULL;
655 static int store_network_information(GSupplicantInterface * interface,
656 GSupplicantSSID *ssid)
658 interface->network_info.ssid = g_malloc(ssid->ssid_len + 1);
659 if (interface->network_info.ssid != NULL) {
660 memcpy(interface->network_info.ssid, ssid->ssid,
662 interface->network_info.ssid[ssid->ssid_len] = '\0';
667 interface->network_info.security = ssid->security;
669 if ((ssid->security == G_SUPPLICANT_SECURITY_WEP ||
670 ssid->security == G_SUPPLICANT_SECURITY_PSK ||
671 #if defined TIZEN_EXT
672 ssid->security == G_SUPPLICANT_SECURITY_SAE ||
674 ssid->security == G_SUPPLICANT_SECURITY_NONE) &&
676 interface->network_info.passphrase = g_strdup(ssid->passphrase);
679 if (ssid->security == G_SUPPLICANT_SECURITY_IEEE8021X &&
680 ssid->private_key_passphrase) {
681 interface->network_info.private_passphrase =
682 g_strdup(ssid->private_key_passphrase);
688 static void callback_system_ready(void)
695 if (!callbacks_pointer)
698 if (!callbacks_pointer->system_ready)
701 callbacks_pointer->system_ready();
704 static void callback_system_killed(void)
706 system_ready = FALSE;
708 if (!callbacks_pointer)
711 if (!callbacks_pointer->system_killed)
714 callbacks_pointer->system_killed();
717 static void callback_interface_added(GSupplicantInterface *interface)
721 if (!callbacks_pointer)
724 if (!callbacks_pointer->interface_added)
727 callbacks_pointer->interface_added(interface);
730 static void callback_interface_state(GSupplicantInterface *interface)
732 if (!callbacks_pointer)
735 if (!callbacks_pointer->interface_state)
738 callbacks_pointer->interface_state(interface);
741 static void callback_interface_removed(GSupplicantInterface *interface)
743 if (!callbacks_pointer)
746 if (!callbacks_pointer->interface_removed)
749 callbacks_pointer->interface_removed(interface);
752 #if !defined TIZEN_EXT
753 static void callback_p2p_support(GSupplicantInterface *interface)
757 if (!interface->p2p_support)
760 if (callbacks_pointer && callbacks_pointer->p2p_support)
761 callbacks_pointer->p2p_support(interface);
765 #if defined TIZEN_EXT_WIFI_MESH
766 static void callback_mesh_support(GSupplicantInterface *interface)
770 if (!interface->mesh_support)
773 if (callbacks_pointer && callbacks_pointer->mesh_support)
774 callbacks_pointer->mesh_support(interface);
777 bool g_supplicant_interface_has_mesh(GSupplicantInterface *interface)
782 return interface->mesh_support;
786 static void callback_scan_started(GSupplicantInterface *interface)
788 if (!callbacks_pointer)
791 if (!callbacks_pointer->scan_started)
794 callbacks_pointer->scan_started(interface);
797 static void callback_ap_create_fail(GSupplicantInterface *interface)
799 if (!callbacks_pointer)
802 if (!callbacks_pointer->ap_create_fail)
805 callbacks_pointer->ap_create_fail(interface);
808 static void callback_scan_finished(GSupplicantInterface *interface)
810 if (!callbacks_pointer)
813 if (!callbacks_pointer->scan_finished)
816 callbacks_pointer->scan_finished(interface);
819 static void callback_network_added(GSupplicantNetwork *network)
821 if (!callbacks_pointer)
824 if (!callbacks_pointer->network_added)
827 callbacks_pointer->network_added(network);
830 static void callback_network_removed(GSupplicantNetwork *network)
832 if (!callbacks_pointer)
835 if (!callbacks_pointer->network_removed)
838 callbacks_pointer->network_removed(network);
841 #if defined TIZEN_EXT
842 static void callback_network_merged(GSupplicantNetwork *network)
844 if (!callbacks_pointer)
847 if (!callbacks_pointer->network_merged)
850 callbacks_pointer->network_merged(network);
853 static void callback_assoc_failed(void *user_data)
855 if (!callbacks_pointer)
858 if (!callbacks_pointer->assoc_failed)
861 callbacks_pointer->assoc_failed(user_data);
864 static void callback_scan_done(GSupplicantInterface *interface)
866 if (!callbacks_pointer)
869 if (!callbacks_pointer->scan_done)
872 callbacks_pointer->scan_done(interface);
876 static void callback_network_changed(GSupplicantNetwork *network,
877 const char *property)
879 if (!callbacks_pointer)
882 if (!callbacks_pointer->network_changed)
885 callbacks_pointer->network_changed(network, property);
888 static void callback_network_associated(GSupplicantNetwork *network)
890 if (!callbacks_pointer)
893 if (!callbacks_pointer->network_associated)
896 callbacks_pointer->network_associated(network);
899 static void callback_sta_authorized(GSupplicantInterface *interface,
902 if (!callbacks_pointer)
905 if (!callbacks_pointer->sta_authorized)
908 callbacks_pointer->sta_authorized(interface, addr);
911 static void callback_sta_deauthorized(GSupplicantInterface *interface,
914 if (!callbacks_pointer)
917 if (!callbacks_pointer->sta_deauthorized)
920 callbacks_pointer->sta_deauthorized(interface, addr);
923 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
924 static void callback_eap(GSupplicantInterface *interface, bool status)
926 if (!callbacks_pointer)
929 if (!callbacks_pointer->eap)
932 callbacks_pointer->eap(interface, status);
934 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
936 static void callback_peer_found(GSupplicantPeer *peer)
938 if (!callbacks_pointer)
941 if (!callbacks_pointer->peer_found)
944 callbacks_pointer->peer_found(peer);
947 static void callback_peer_lost(GSupplicantPeer *peer)
949 if (!callbacks_pointer)
952 if (!callbacks_pointer->peer_lost)
955 callbacks_pointer->peer_lost(peer);
958 static void callback_peer_changed(GSupplicantPeer *peer,
959 GSupplicantPeerState state)
961 if (!callbacks_pointer)
964 if (!callbacks_pointer->peer_changed)
967 callbacks_pointer->peer_changed(peer, state);
970 static void callback_peer_request(GSupplicantPeer *peer)
972 if (!callbacks_pointer)
975 if (!callbacks_pointer->peer_request)
978 peer->connection_requested = true;
980 callbacks_pointer->peer_request(peer);
983 static void callback_disconnect_reason_code(GSupplicantInterface *interface,
986 if (!callbacks_pointer)
989 if (!callbacks_pointer->disconnect_reasoncode)
992 if (reason_code != 0)
993 callbacks_pointer->disconnect_reasoncode(interface,
997 static void callback_assoc_status_code(GSupplicantInterface *interface,
1000 if (!callbacks_pointer)
1003 if (!callbacks_pointer->assoc_status_code)
1006 callbacks_pointer->assoc_status_code(interface, status_code);
1010 static void remove_group(gpointer data)
1012 GSupplicantGroup *group = data;
1015 g_slist_free_full(group->members, g_free);
1017 g_free(group->path);
1021 static void remove_interface(gpointer data)
1023 GSupplicantInterface *interface = data;
1025 g_hash_table_destroy(interface->bss_mapping);
1026 g_hash_table_destroy(interface->network_table);
1027 g_hash_table_destroy(interface->peer_table);
1028 g_hash_table_destroy(interface->group_table);
1030 if (interface->scan_callback) {
1031 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
1032 interface, interface->scan_callback,
1033 interface->scanning);
1035 interface->scan_callback(-EIO, interface, interface->scan_data);
1036 interface->scan_callback = NULL;
1037 interface->scan_data = NULL;
1039 if (interface->scanning) {
1040 interface->scanning = FALSE;
1041 callback_scan_finished(interface);
1045 callback_interface_removed(interface);
1047 g_free(interface->wps_cred.key);
1048 g_free(interface->path);
1049 g_free(interface->network_path);
1050 #if defined TIZEN_EXT
1051 interface->network_path = NULL;
1053 g_free(interface->ifname);
1054 g_free(interface->driver);
1055 g_free(interface->bridge);
1056 remove_network_information(interface);
1060 static void remove_network(gpointer data)
1062 GSupplicantNetwork *network = data;
1064 g_hash_table_destroy(network->bss_table);
1066 callback_network_removed(network);
1068 g_hash_table_destroy(network->config_table);
1069 #if defined TIZEN_EXT
1070 g_hash_table_destroy(network->assoc_reject_table);
1073 g_free(network->path);
1074 g_free(network->group);
1075 g_free(network->name);
1076 #if defined TIZEN_EXT
1077 g_free(network->eap);
1078 g_free(network->identity);
1079 g_free(network->phase2);
1081 #if defined TIZEN_EXT
1082 g_slist_free_full(network->vsie_list, g_free);
1088 static void remove_bss(gpointer data)
1090 struct g_supplicant_bss *bss = data;
1092 supplicant_dbus_property_call_cancel_all(bss);
1095 #if defined TIZEN_EXT
1096 g_slist_free_full(bss->vsie_list, g_free);
1101 static void remove_peer(gpointer data)
1103 GSupplicantPeer *peer = data;
1105 callback_peer_lost(peer);
1108 g_slist_free_full(peer->groups, g_free);
1111 g_hash_table_remove(peer_mapping, peer->path);
1113 if (pending_peer_connection)
1114 g_hash_table_remove(pending_peer_connection, peer->path);
1118 g_free(peer->identifier);
1119 g_free(peer->widi_ies);
1124 #if defined TIZEN_EXT
1125 static void remove_assoc_data(gpointer data)
1127 struct assoc_reject_data *assoc_data = data;
1129 g_free(assoc_data->bssid);
1130 g_slist_free(assoc_data->reject_time_list);
1136 static void debug_strvalmap(const char *label, struct strvalmap *map,
1140 #if defined TIZEN_EXT
1141 if (!simplified_log)
1143 for (i = 0; map[i].str; i++) {
1144 if (val & map[i].val)
1145 SUPPLICANT_DBG("%s: %s", label, map[i].str);
1149 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
1151 GSupplicantInterface *interface = user_data;
1152 const char *str = NULL;
1155 dbus_message_iter_get_basic(iter, &str);
1159 for (i = 0; keymgmt_map[i].str; i++)
1160 if (strcmp(str, keymgmt_map[i].str) == 0) {
1161 interface->keymgmt_capa |= keymgmt_map[i].val;
1166 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
1168 GSupplicantInterface *interface = user_data;
1169 const char *str = NULL;
1172 dbus_message_iter_get_basic(iter, &str);
1176 for (i = 0; authalg_capa_map[i].str; i++)
1177 if (strcmp(str, authalg_capa_map[i].str) == 0) {
1178 interface->authalg_capa |= authalg_capa_map[i].val;
1183 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
1185 GSupplicantInterface *interface = user_data;
1186 const char *str = NULL;
1189 dbus_message_iter_get_basic(iter, &str);
1193 for (i = 0; proto_capa_map[i].str; i++)
1194 if (strcmp(str, proto_capa_map[i].str) == 0) {
1195 interface->proto_capa |= proto_capa_map[i].val;
1200 static void interface_capability_pairwise(DBusMessageIter *iter,
1203 GSupplicantInterface *interface = user_data;
1204 const char *str = NULL;
1207 dbus_message_iter_get_basic(iter, &str);
1211 for (i = 0; pairwise_map[i].str; i++)
1212 if (strcmp(str, pairwise_map[i].str) == 0) {
1213 interface->pairwise_capa |= pairwise_map[i].val;
1218 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
1220 GSupplicantInterface *interface = user_data;
1221 const char *str = NULL;
1224 dbus_message_iter_get_basic(iter, &str);
1228 for (i = 0; group_map[i].str; i++)
1229 if (strcmp(str, group_map[i].str) == 0) {
1230 interface->group_capa |= group_map[i].val;
1235 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
1237 GSupplicantInterface *interface = user_data;
1238 const char *str = NULL;
1241 dbus_message_iter_get_basic(iter, &str);
1245 for (i = 0; scan_capa_map[i].str; i++)
1246 if (strcmp(str, scan_capa_map[i].str) == 0) {
1247 interface->scan_capa |= scan_capa_map[i].val;
1252 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
1254 GSupplicantInterface *interface = user_data;
1255 const char *str = NULL;
1258 dbus_message_iter_get_basic(iter, &str);
1262 for (i = 0; mode_capa_map[i].str; i++)
1263 if (strcmp(str, mode_capa_map[i].str) == 0) {
1264 interface->mode_capa |= mode_capa_map[i].val;
1269 static void interface_capability(const char *key, DBusMessageIter *iter,
1272 GSupplicantInterface *interface = user_data;
1277 if (g_strcmp0(key, "KeyMgmt") == 0)
1278 supplicant_dbus_array_foreach(iter,
1279 interface_capability_keymgmt, interface);
1280 else if (g_strcmp0(key, "AuthAlg") == 0)
1281 supplicant_dbus_array_foreach(iter,
1282 interface_capability_authalg, interface);
1283 else if (g_strcmp0(key, "Protocol") == 0)
1284 supplicant_dbus_array_foreach(iter,
1285 interface_capability_proto, interface);
1286 else if (g_strcmp0(key, "Pairwise") == 0)
1287 supplicant_dbus_array_foreach(iter,
1288 interface_capability_pairwise, interface);
1289 else if (g_strcmp0(key, "Group") == 0)
1290 supplicant_dbus_array_foreach(iter,
1291 interface_capability_group, interface);
1292 else if (g_strcmp0(key, "Scan") == 0)
1293 supplicant_dbus_array_foreach(iter,
1294 interface_capability_scan, interface);
1295 else if (g_strcmp0(key, "Modes") == 0)
1296 supplicant_dbus_array_foreach(iter,
1297 interface_capability_mode, interface);
1298 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
1299 dbus_int32_t max_scan_ssid;
1301 dbus_message_iter_get_basic(iter, &max_scan_ssid);
1302 if (max_scan_ssid < 2)
1304 interface->max_scan_ssids = max_scan_ssid;
1305 #if defined TIZEN_EXT
1306 } else if (g_strcmp0(key, "Is5GhzSupported") == 0) {
1307 dbus_bool_t is_5_0_Ghz_supported;
1309 dbus_message_iter_get_basic(iter, &is_5_0_Ghz_supported);
1310 interface->is_5_0_Ghz_supported = is_5_0_Ghz_supported;
1313 SUPPLICANT_DBG("key %s type %c",
1314 key, dbus_message_iter_get_arg_type(iter));
1317 static void set_bss_expiration_age(DBusMessageIter *iter, void *user_data)
1319 unsigned int bss_expiration_age = GPOINTER_TO_UINT(user_data);
1321 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32,
1322 &bss_expiration_age);
1325 int g_supplicant_interface_set_bss_expiration_age(GSupplicantInterface *interface,
1326 unsigned int bss_expiration_age)
1328 return supplicant_dbus_property_set(interface->path,
1329 SUPPLICANT_INTERFACE ".Interface",
1330 "BSSExpireAge", DBUS_TYPE_UINT32_AS_STRING,
1331 set_bss_expiration_age, NULL,
1332 GUINT_TO_POINTER(bss_expiration_age), NULL);
1335 struct set_apscan_data
1337 unsigned int ap_scan;
1338 GSupplicantInterface *interface;
1341 static void set_apscan(DBusMessageIter *iter, void *user_data)
1343 struct set_apscan_data *data = user_data;
1344 unsigned int ap_scan = data->ap_scan;
1346 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
1349 static void set_apscan_complete(const char *error,
1350 DBusMessageIter *iter, void *user_data)
1352 struct set_apscan_data *data = user_data;
1353 GSupplicantInterface *interface = data->interface;
1356 interface->ap_create_in_progress = false;
1357 SUPPLICANT_DBG("Set AP scan error %s", error);
1361 interface->ap_create_in_progress = true;
1366 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
1367 unsigned int ap_scan)
1369 struct set_apscan_data *data;
1372 data = dbus_malloc0(sizeof(*data));
1377 data->ap_scan = ap_scan;
1378 data->interface = interface;
1380 ret = supplicant_dbus_property_set(interface->path,
1381 SUPPLICANT_INTERFACE ".Interface",
1382 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
1383 set_apscan, set_apscan_complete, data, NULL);
1390 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
1396 interface->data = data;
1399 interface->scan_callback = NULL;
1402 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
1407 return interface->data;
1410 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
1415 return interface->ifname;
1418 #if defined TIZEN_EXT
1419 bool g_supplicant_interface_get_is_5_0_ghz_supported(GSupplicantInterface *interface)
1424 return interface->is_5_0_Ghz_supported;
1427 unsigned char *g_supplicant_interface_get_add_network_bssid(GSupplicantInterface *interface)
1432 return (unsigned char *)interface->add_network_bssid;
1436 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
1441 return interface->driver;
1444 GSupplicantState g_supplicant_interface_get_state(
1445 GSupplicantInterface *interface)
1448 return G_SUPPLICANT_STATE_UNKNOWN;
1450 return interface->state;
1453 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
1458 return (const char *)interface->wps_cred.key;
1461 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
1462 unsigned int *ssid_len)
1467 if (!interface || interface->wps_cred.ssid_len == 0) {
1472 *ssid_len = interface->wps_cred.ssid_len;
1473 return interface->wps_cred.ssid;
1476 GSupplicantWpsState g_supplicant_interface_get_wps_state(
1477 GSupplicantInterface *interface)
1480 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
1482 return interface->wps_state;
1485 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
1490 return interface->mode_capa;
1493 unsigned int g_supplicant_interface_get_max_scan_ssids(
1494 GSupplicantInterface *interface)
1499 if (interface->max_scan_ssids == 0)
1500 return WPAS_MAX_SCAN_SSIDS;
1502 return interface->max_scan_ssids;
1505 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
1507 dbus_bool_t enable = *(dbus_bool_t *)user_data;
1509 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
1512 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
1518 if (!interface->network_path)
1521 SUPPLICANT_DBG(" ");
1522 return supplicant_dbus_property_set(interface->network_path,
1523 SUPPLICANT_INTERFACE ".Network",
1524 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
1525 set_network_enabled, NULL, &enable, NULL);
1528 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
1533 return interface->ready;
1536 GSupplicantInterface *g_supplicant_network_get_interface(
1537 GSupplicantNetwork *network)
1542 return network->interface;
1545 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
1547 if (!network || !network->name)
1550 return network->name;
1553 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
1555 if (!network || !network->group)
1558 return network->group;
1561 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1563 if (!network || !network->path)
1566 return network->path;
1569 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1572 return G_SUPPLICANT_MODE_UNKNOWN;
1574 return mode2string(network->mode);
1577 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1580 return G_SUPPLICANT_SECURITY_UNKNOWN;
1582 return security2string(network->security);
1585 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1586 unsigned int *ssid_len)
1593 *ssid_len = network->ssid_len;
1594 return network->ssid;
1597 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1602 return network->signal;
1605 #if defined TIZEN_EXT
1606 void g_supplicant_network_set_signal(GSupplicantNetwork *network, int signal)
1611 network->signal = (dbus_int16_t)signal;
1614 void g_supplicant_network_set_bss_signal(GSupplicantNetwork *network,
1615 int signal, int snr)
1617 struct g_supplicant_bss *best_bss;
1622 best_bss = network->best_bss;
1626 best_bss->signal = (dbus_int16_t)signal;
1627 best_bss->snr = (dbus_int16_t)snr;
1631 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1636 return network->frequency;
1639 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1644 return network->wps;
1647 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1652 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1658 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1663 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1669 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1674 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1681 GSupplicantPhy_mode g_supplicant_network_get_phy_mode(GSupplicantNetwork *network)
1684 return G_SUPPLICANT_MODE_IEEE80211_UNKNOWN;
1686 return network->phy_mode;
1690 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1695 return peer->interface;
1698 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1706 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1711 return peer->identifier;
1714 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1719 return peer->device_address;
1722 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1727 return peer->iface_address;
1730 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1738 #if defined TIZEN_EXT
1739 bool g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1744 return network->isHS20AP;
1747 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1749 if (!network || !network->eap)
1752 return network->eap;
1755 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1757 if (!network || !network->identity)
1760 return network->identity;
1763 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1765 if (!network || !network->phase2)
1768 return network->phase2;
1771 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
1776 return network->keymgmt;
1779 dbus_bool_t g_supplicant_network_get_privacy(GSupplicantNetwork *network)
1784 return network->privacy;
1787 const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
1793 return network->country_code;
1796 dbus_bool_t g_supplicant_network_is_pmf_required(GSupplicantNetwork *network)
1801 return network->best_bss->pmf_required;
1805 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1808 if (!peer || !length)
1811 *length = peer->widi_ies_length;
1812 return peer->widi_ies;
1815 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1820 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1826 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1831 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1837 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1839 if (!peer || !peer->groups)
1845 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1850 return (GSupplicantInterface *) peer->current_group_iface;
1853 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1855 GSupplicantGroup *group;
1861 for (list = peer->groups; list; list = list->next) {
1862 const char *path = list->data;
1864 group = g_hash_table_lookup(group_mapping, path);
1868 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1869 group->orig_interface != peer->interface)
1872 if (group->interface == peer->current_group_iface)
1879 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1884 return peer->connection_requested;
1887 #if defined TIZEN_EXT
1889 * Description: Network client requires additional wifi specific info
1891 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1893 if (network == NULL || network->best_bss == NULL)
1896 return (const unsigned char *)network->best_bss->bssid;
1899 dbus_bool_t g_supplicant_network_get_transition_mode(GSupplicantNetwork *network)
1901 if (network == NULL)
1904 return network->owe_transition_mode;
1907 const unsigned char *g_supplicant_network_get_transition_mode_bssid(GSupplicantNetwork *network)
1909 if (network == NULL)
1912 return (const unsigned char *)network->transition_mode_bssid;
1915 const void *g_supplicant_network_get_transition_mode_ssid(GSupplicantNetwork *network,
1916 unsigned int *transition_mode_ssid_len)
1919 *transition_mode_ssid_len = 0;
1923 *transition_mode_ssid_len = network->transition_mode_ssid_len;
1924 return network->transition_mode_ssid;
1927 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1929 if (network == NULL || network->best_bss == NULL)
1932 return network->best_bss->maxrate;
1935 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1937 if (network == NULL || network->best_bss == NULL)
1940 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1941 network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1942 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1943 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP ||
1944 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1945 unsigned int pairwise;
1947 pairwise = network->best_bss->rsn_pairwise |
1948 network->best_bss->wpa_pairwise;
1950 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1951 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1953 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1955 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1958 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1960 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1966 bool g_supplicant_network_get_rsn_mode(GSupplicantNetwork *network)
1968 if (network == NULL || network->best_bss == NULL)
1971 if (network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1972 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP)
1975 if (network->best_bss->rsn_selected) {
1976 const char *mode = g_supplicant_network_get_enc_mode(network);
1977 if (g_strcmp0(mode, "aes") == 0 ||
1978 g_strcmp0(mode, "mixed") == 0)
1986 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
1988 GSList *vsie_list = NULL;
1993 if (g_slist_length(network->vsie_list) > 0) {
1994 GSList *list = NULL;
1995 unsigned char *vsie = NULL;
1996 for (list = network->vsie_list; list; list = list->next) {
1997 unsigned char *ie = (unsigned char *)list->data;
2000 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2003 memcpy(vsie, ie, ie[1]+2);
2004 vsie_list = g_slist_append(vsie_list, vsie);
2006 SUPPLICANT_DBG("Failed to allocate memory");
2013 static bool compare_bssid(unsigned char *bssid_a, unsigned char *bssid_b)
2015 if (!memcmp(bssid_a, bssid_b, WIFI_BSSID_LEN_MAX))
2021 static gchar *convert_bssid_to_str(unsigned char *bssid)
2026 bssid_str = g_string_sized_new(18);
2030 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
2031 g_string_append_printf(bssid_str, "%02x", bssid[i]);
2032 if (i < WIFI_BSSID_LEN_MAX - 1)
2033 g_string_append(bssid_str, ":");
2036 return g_string_free(bssid_str, FALSE);
2039 #if defined TIZEN_EXT_INS
2040 static void count_assoc_reject(gpointer data, gpointer user_data)
2042 time_t assoc_reject_time = GPOINTER_TO_INT(data);
2043 struct assoc_count_data *assoc_count = user_data;
2045 if (assoc_reject_time > assoc_count->ref_time)
2046 assoc_count->assoc_count++;
2049 static uint16_t get_assoc_reject_cnt(GHashTable *assoc_reject_table, unsigned char *bssid)
2052 struct assoc_reject_data *assoc_data;
2053 struct assoc_count_data assoc_count;
2055 struct tm* timeinfo;
2057 if (g_hash_table_size(assoc_reject_table) < 1)
2063 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2066 bssid_str = convert_bssid_to_str(bssid);
2070 assoc_data = g_hash_table_lookup(assoc_reject_table, bssid_str);
2076 if (g_slist_length(assoc_data->reject_time_list) < 1) {
2081 /* Only events that occur within one hour are appened. */
2082 curr_time = time(NULL);
2083 timeinfo = localtime(&curr_time);
2084 timeinfo->tm_hour -= 1;
2086 assoc_count.ref_time = mktime(timeinfo);
2087 assoc_count.assoc_count = 0;
2089 g_slist_foreach(assoc_data->reject_time_list, count_assoc_reject, &assoc_count);
2092 return assoc_count.assoc_count;
2095 static int calculate_score_last_connected_bssid(bool is_last_connected)
2099 if (ins_settings.last_connected_bssid) {
2100 if (is_last_connected)
2101 score += ins_settings.last_connected_bssid_score;
2107 static int calculate_score_assoc_reject(uint16_t assoc_reject_cnt)
2111 if (ins_settings.assoc_reject)
2112 score -= (assoc_reject_cnt * ins_settings.assoc_reject_score);
2117 static int calculate_score_frequency(dbus_int16_t strength, dbus_uint16_t frequency)
2121 switch (ins_settings.preferred_freq_bssid) {
2122 case G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ:
2123 if ((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
2124 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
2125 (strength > ins_settings.signal_level3_24ghz))
2126 score += ins_settings.preferred_freq_bssid_score;
2129 case G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ:
2130 if ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
2131 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
2132 (strength > ins_settings.signal_level3_5ghz))
2133 score += ins_settings.preferred_freq_bssid_score;
2143 static int calculate_score_strength(dbus_int16_t strength)
2147 if (ins_settings.signal_bssid)
2148 score += (((strength > -60) ? -60 : strength) + 85);
2153 static int calculate_score_est_throughput(dbus_uint32_t est_throughput)
2157 if (est_throughput >= 10000)
2158 score = est_throughput / 10000;
2166 static int calculate_score(bool is_last_connected, uint16_t assoc_reject_cnt,
2167 dbus_uint16_t frequency, dbus_int16_t strength,
2168 dbus_int16_t snr, dbus_uint32_t est_throughput)
2172 score += calculate_score_last_connected_bssid(is_last_connected);
2173 score += calculate_score_assoc_reject(assoc_reject_cnt);
2174 score += calculate_score_frequency(strength, frequency);
2175 score += calculate_score_strength(strength);
2177 score += calculate_score_est_throughput(est_throughput);
2183 static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
2185 struct g_supplicant_bss *bss = value;
2186 struct g_connman_bssids *bssids = NULL;
2187 struct update_bssid_data *bssid_data = (struct update_bssid_data *)user_data;
2189 bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
2192 memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
2194 bssids->strength = bss->signal;
2195 bssids->strength += 120;
2197 if (bssids->strength > 100)
2198 bssids->strength = 100;
2200 bssids->frequency = bss->frequency;
2201 bssids->score_snr = (int)bss->snr;
2203 #if defined TIZEN_EXT_INS
2204 bssids->assoc_reject_cnt = get_assoc_reject_cnt(bssid_data->assoc_reject_table, bssids->bssid);
2205 bssids->is_last_connected = compare_bssid(bssids->bssid, bssid_data->last_connected_bssid);
2207 bssids->score_last_connected_bssid = calculate_score_last_connected_bssid(bssids->is_last_connected);
2208 bssids->score_assoc_reject = calculate_score_assoc_reject(bssids->assoc_reject_cnt);
2209 bssids->score_frequency = calculate_score_frequency(bss->signal, bssids->frequency);
2210 bssids->score_strength = calculate_score_strength(bss->signal);
2211 bssids->score_est_throughput = calculate_score_est_throughput(bss->est_throughput);
2213 bssids->ins_score = calculate_score(bssids->is_last_connected,
2214 bssids->assoc_reject_cnt, bssids->frequency, bss->signal,
2215 bss->snr, bss->est_throughput);
2217 bssids->ins_score = bss->signal;
2219 bssid_data->bssid_list = g_slist_append(bssid_data->bssid_list, bssids);
2221 SUPPLICANT_DBG("Failed to allocate memory");
2224 static gint cmp_bss(gconstpointer a, gconstpointer b)
2226 struct g_connman_bssids *entry_a = (struct g_connman_bssids *)a;
2227 struct g_connman_bssids *entry_b = (struct g_connman_bssids *)b;
2229 if (entry_a->ins_score > entry_b->ins_score)
2232 if (entry_a->ins_score < entry_b->ins_score)
2238 #if defined TIZEN_EXT_INS
2239 static void print_bssid_sort(gpointer data, gpointer user_data)
2241 struct g_connman_bssids *bssids = data;
2243 SUPPLICANT_DBG("bssid[" MACSTR "] total[%2d] freq[%2d] "
2244 "last_conn[%2d] assoc_reject[%2d] strength[%2d]",
2245 MAC2STR(bssids->bssid), bssids->ins_score,
2246 bssids->score_frequency, bssids->score_last_connected_bssid,
2247 bssids->score_assoc_reject, bssids->score_strength);
2251 void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network)
2253 struct update_bssid_data bssid_data;
2255 if (g_hash_table_size(network->bss_table) < 1)
2258 bssid_data.network = network;
2259 memset(&bssid_data, 0, sizeof(bssid_data));
2260 memcpy(bssid_data.last_connected_bssid, network->last_connected_bssid, WIFI_BSSID_LEN_MAX);
2261 bssid_data.assoc_reject_table = network->assoc_reject_table;
2263 g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_data);
2264 bssid_data.bssid_list = g_slist_sort(bssid_data.bssid_list, cmp_bss);
2265 #if defined TIZEN_EXT_INS
2266 g_slist_foreach(bssid_data.bssid_list, print_bssid_sort, NULL);
2269 return bssid_data.bssid_list;
2272 void g_supplicant_network_set_last_connected_bssid(GSupplicantNetwork *network, const unsigned char *bssid)
2277 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2280 memcpy(network->last_connected_bssid, bssid, WIFI_BSSID_LEN_MAX);
2282 SUPPLICANT_DBG("last connected bssid [" MACSTR "]", MAC2STR(bssid));
2285 const unsigned char *g_supplicant_network_get_last_connected_bssid(GSupplicantNetwork *network)
2287 if (network == NULL)
2290 return (const unsigned char *)network->last_connected_bssid;
2293 void g_supplicant_network_update_assoc_reject(GSupplicantInterface *interface,
2294 GSupplicantNetwork *network)
2296 struct assoc_reject_data *assoc_data;
2303 bssid_str = convert_bssid_to_str(interface->add_network_bssid);
2307 assoc_data = g_hash_table_lookup(network->assoc_reject_table, bssid_str);
2309 assoc_data = g_try_new0(struct assoc_reject_data, 1);
2315 assoc_data->bssid = g_strdup(bssid_str);
2316 g_hash_table_insert(network->assoc_reject_table, assoc_data->bssid, assoc_data);
2319 curr_time = time(NULL);
2320 assoc_data->reject_time_list = g_slist_append(assoc_data->reject_time_list, GINT_TO_POINTER(curr_time));
2322 SUPPLICANT_DBG("bssid [%s] time [%u]", bssid_str, curr_time);
2326 callback_network_changed(network, "UpdateAssocReject");
2329 GHashTable *g_supplicant_network_get_assoc_reject_table(GSupplicantNetwork *network)
2334 return network->assoc_reject_table;
2337 GSupplicantNetwork *g_supplicant_interface_get_network(GSupplicantInterface *interface,
2343 return g_hash_table_lookup(interface->network_table, group);
2346 static void copy_assoc_reject(gpointer key, gpointer value, gpointer user_data)
2348 struct assoc_reject_data *cloned_assoc_data;
2349 struct assoc_reject_data *assoc_data = value;
2350 GHashTable *cloned_assoc_reject_table = user_data;
2352 if (assoc_data && cloned_assoc_reject_table) {
2353 cloned_assoc_data = g_try_new0(struct assoc_reject_data, 1);
2354 if (!cloned_assoc_data)
2357 cloned_assoc_data->bssid = g_strdup(assoc_data->bssid);
2358 cloned_assoc_data->reject_time_list = g_slist_copy(assoc_data->reject_time_list);
2359 g_hash_table_insert(cloned_assoc_reject_table,
2360 cloned_assoc_data->bssid, cloned_assoc_data);
2364 GHashTable *g_supplicant_network_clone_assoc_reject_table(GSupplicantNetwork *network)
2366 GHashTable *cloned_assoc_reject_table;
2371 GHashTable *assoc_reject_table = g_supplicant_network_get_assoc_reject_table(network);
2372 if (!assoc_reject_table)
2375 cloned_assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2376 NULL, remove_assoc_data);
2377 g_hash_table_foreach(assoc_reject_table, copy_assoc_reject, cloned_assoc_reject_table);
2379 return cloned_assoc_reject_table;
2384 static void merge_network(GSupplicantNetwork *network)
2387 const char *ssid, *mode, *key_mgmt;
2388 #if defined TIZEN_EXT
2389 const char *isHS20AP;
2390 const char *eap, *identity, *phase2;
2392 unsigned int i, ssid_len;
2395 ssid = g_hash_table_lookup(network->config_table, "ssid");
2396 mode = g_hash_table_lookup(network->config_table, "mode");
2397 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
2398 #if defined TIZEN_EXT
2399 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
2400 eap = g_hash_table_lookup(network->config_table, "eap");
2401 identity = g_hash_table_lookup(network->config_table, "identity");
2402 phase2 = g_hash_table_lookup(network->config_table, "phase2");
2405 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
2408 ssid_len = strlen(ssid);
2412 str = g_string_sized_new((ssid_len * 2) + 24);
2416 for (i = 0; i < ssid_len; i++)
2417 #if defined TIZEN_EXT
2421 g_string_append_printf(str, "%02x", ssid[i]);
2422 #if defined TIZEN_EXT
2426 if (g_strcmp0(mode, "0") == 0)
2427 g_string_append_printf(str, "_managed");
2428 else if (g_strcmp0(mode, "1") == 0)
2429 g_string_append_printf(str, "_adhoc");
2430 #if defined TIZEN_EXT_WIFI_MESH
2431 else if (g_strcmp0(mode, "5") == 0)
2432 g_string_append_printf(str, "_mesh");
2435 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
2436 g_string_append_printf(str, "_psk");
2437 #if defined TIZEN_EXT
2438 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
2439 g_string_append_printf(str, "_ieee8021x");
2441 g_string_append_printf(str, "_none");
2444 group = g_string_free(str, FALSE);
2446 SUPPLICANT_DBG("%s", group);
2448 #if defined TIZEN_EXT
2449 if (g_strcmp0(isHS20AP, "1") == 0) {
2450 network->isHS20AP = 1;
2452 g_free(network->eap);
2453 network->eap = g_strdup(eap);
2455 if (network->identity)
2456 g_free(network->identity);
2457 network->identity = g_strdup(identity);
2459 if (network->phase2)
2460 g_free(network->phase2);
2461 network->phase2 = g_strdup(phase2);
2463 network->isHS20AP = 0;
2465 network->group = g_strdup(group);
2466 callback_network_merged(network);
2467 g_free(network->group);
2472 g_hash_table_destroy(network->config_table);
2474 g_free(network->path);
2478 static void network_property(const char *key, DBusMessageIter *iter,
2481 GSupplicantNetwork *network = user_data;
2483 if (!network->interface)
2487 merge_network(network);
2491 if (g_strcmp0(key, "Enabled") == 0) {
2492 dbus_bool_t enabled = FALSE;
2494 dbus_message_iter_get_basic(iter, &enabled);
2495 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
2496 const char *str = NULL;
2498 dbus_message_iter_get_basic(iter, &str);
2500 g_hash_table_replace(network->config_table,
2501 g_strdup(key), g_strdup(str));
2504 SUPPLICANT_DBG("key %s type %c",
2505 key, dbus_message_iter_get_arg_type(iter));
2508 static void interface_network_added(DBusMessageIter *iter, void *user_data)
2510 GSupplicantInterface *interface = user_data;
2511 GSupplicantNetwork *network;
2512 const char *path = NULL;
2516 dbus_message_iter_get_basic(iter, &path);
2520 if (g_strcmp0(path, "/") == 0)
2523 network = g_try_new0(GSupplicantNetwork, 1);
2527 network->interface = interface;
2528 network->path = g_strdup(path);
2530 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2533 dbus_message_iter_next(iter);
2534 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
2535 supplicant_dbus_property_foreach(iter, network_property,
2537 network_property(NULL, NULL, network);
2541 supplicant_dbus_property_get_all(path,
2542 SUPPLICANT_INTERFACE ".Network",
2543 network_property, network, NULL);
2546 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
2551 static char *create_name(unsigned char *ssid, int ssid_len)
2554 const gchar *remainder, *invalid;
2555 int valid_bytes, remaining_bytes;
2557 if (ssid_len < 1 || ssid[0] == '\0')
2558 return g_strdup("");
2561 remainder = (const gchar *)ssid;
2562 remaining_bytes = ssid_len;
2564 while (remaining_bytes != 0) {
2565 if (g_utf8_validate(remainder, remaining_bytes,
2570 valid_bytes = invalid - remainder;
2573 string = g_string_sized_new(remaining_bytes);
2575 g_string_append_len(string, remainder, valid_bytes);
2577 /* append U+FFFD REPLACEMENT CHARACTER */
2578 g_string_append(string, "\357\277\275");
2580 remaining_bytes -= valid_bytes + 1;
2581 remainder = invalid + 1;
2585 return g_strndup((const gchar *)ssid, ssid_len + 1);
2587 g_string_append(string, remainder);
2589 return g_string_free(string, FALSE);
2592 static char *create_group(struct g_supplicant_bss *bss)
2596 const char *mode, *security;
2598 str = g_string_sized_new((bss->ssid_len * 2) + 24);
2602 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
2603 for (i = 0; i < bss->ssid_len; i++)
2604 g_string_append_printf(str, "%02x", bss->ssid[i]);
2606 g_string_append_printf(str, "hidden");
2608 mode = mode2string(bss->mode);
2610 g_string_append_printf(str, "_%s", mode);
2612 security = security2string(bss->security);
2614 g_string_append_printf(str, "_%s", security);
2616 return g_string_free(str, FALSE);
2618 #if defined TIZEN_EXT
2619 static void update_network_with_best_bss(GSupplicantNetwork *network,
2620 struct g_supplicant_bss *best_bss)
2623 * Do not change best BSS if we are connected.
2625 if (network->interface->state == G_SUPPLICANT_STATE_COMPLETED)
2628 network->signal = best_bss->signal;
2629 network->frequency = best_bss->frequency;
2630 network->best_bss = best_bss;
2633 static bool update_best_bss(GSupplicantNetwork *network,
2634 struct g_supplicant_bss *bss, struct g_supplicant_bss *best_bss)
2639 if (network->best_bss == NULL) {
2640 update_network_with_best_bss(network, bss);
2644 #if defined TIZEN_EXT_INS
2645 score_new = calculate_score(
2646 compare_bssid(bss->bssid, network->last_connected_bssid),
2647 get_assoc_reject_cnt(network->assoc_reject_table, bss->bssid),
2648 bss->frequency, bss->signal, bss->snr, bss->est_throughput);
2650 score_best = calculate_score(
2651 compare_bssid(network->best_bss->bssid, network->last_connected_bssid),
2652 get_assoc_reject_cnt(network->assoc_reject_table, network->best_bss->bssid),
2653 network->best_bss->frequency, network->best_bss->signal,
2654 network->best_bss->snr, network->best_bss->est_throughput);
2656 score_new = bss->signal;
2657 score_best = network->best_bss->signal;
2660 if (score_new > score_best) {
2661 SUPPLICANT_DBG("new[" MACSTR "][%d] : best[" MACSTR "][%d]",
2662 MAC2STR(bss->bssid), score_new,
2663 MAC2STR(network->best_bss->bssid), score_best);
2665 update_network_with_best_bss(network, bss);
2667 SUPPLICANT_DBG("Update best BSS for %s", network->name);
2675 static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
2677 GSupplicantInterface *interface = bss->interface;
2678 GSupplicantNetwork *network;
2680 bool is_new_network;
2682 group = create_group(bss);
2683 SUPPLICANT_DBG("New group created: %s", group);
2688 network = g_hash_table_lookup(interface->network_table, group);
2691 SUPPLICANT_DBG("Network %s already exist", network->name);
2692 is_new_network = false;
2697 is_new_network = true;
2699 network = g_try_new0(GSupplicantNetwork, 1);
2705 network->interface = interface;
2707 network->path = g_strdup(bss->path);
2708 network->group = group;
2709 network->name = create_name(bss->ssid, bss->ssid_len);
2710 network->mode = bss->mode;
2711 network->security = bss->security;
2712 network->ssid_len = bss->ssid_len;
2713 memcpy(network->ssid, bss->ssid, bss->ssid_len);
2714 network->signal = bss->signal;
2715 network->frequency = bss->frequency;
2716 network->best_bss = bss;
2718 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2719 network->wps = TRUE;
2720 network->wps_capabilities = bss->wps_capabilities;
2723 #if defined TIZEN_EXT
2724 network->owe_transition_mode = bss->owe_transition_mode;
2725 network->privacy = bss->privacy;
2726 memcpy(network->transition_mode_ssid, bss->transition_mode_ssid, bss->transition_mode_ssid_len);
2727 memcpy(network->transition_mode_bssid, bss->transition_mode_bssid, WIFI_BSSID_LEN_MAX);
2729 network->keymgmt = bss->keymgmt;
2731 if (g_slist_length(bss->vsie_list) > 0) {
2732 GSList *list = NULL;
2733 unsigned char *vsie = NULL;
2734 for (list = bss->vsie_list; list; list = list->next) {
2735 unsigned char *ie = (unsigned char *)list->data;
2736 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2739 memcpy(vsie, ie, ie[1]+2);
2740 network->vsie_list = g_slist_append(network->vsie_list, vsie);
2742 SUPPLICANT_DBG("Failed to allocate memory.");
2746 network->isHS20AP = bss->hs20;
2747 memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
2748 network->phy_mode = bss->phy_mode;
2751 SUPPLICANT_DBG("New network %s created", network->name);
2753 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2756 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2759 #if defined TIZEN_EXT
2760 network->assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2761 NULL, remove_assoc_data);
2764 g_hash_table_replace(interface->network_table,
2765 network->group, network);
2767 callback_network_added(network);
2770 /* We update network's WPS properties if only bss provides WPS. */
2771 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2772 network->wps = TRUE;
2773 network->wps_capabilities = bss->wps_capabilities;
2775 if (!is_new_network)
2776 callback_network_changed(network, "WPSCapabilities");
2780 * Do not change best BSS if we are connected. It will be done through
2781 * CurrentBSS property in case of misalignment with wpa_s or roaming.
2783 #if defined TIZEN_EXT
2784 if (network != interface->current_network) {
2785 if (update_best_bss(network, bss, network->best_bss))
2786 callback_network_changed(network, "Signal");
2789 if (network != interface->current_network &&
2790 bss->signal > network->signal) {
2791 network->signal = bss->signal;
2792 network->best_bss = bss;
2793 callback_network_changed(network, "Signal");
2797 g_hash_table_replace(interface->bss_mapping, bss->path, network);
2798 g_hash_table_replace(network->bss_table, bss->path, bss);
2800 g_hash_table_replace(bss_mapping, bss->path, interface);
2805 static void bss_rates(DBusMessageIter *iter, void *user_data)
2807 struct g_supplicant_bss *bss = user_data;
2808 dbus_uint32_t rate = 0;
2810 dbus_message_iter_get_basic(iter, &rate);
2814 if (rate > bss->maxrate)
2815 bss->maxrate = rate;
2818 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
2820 unsigned int *keymgmt = user_data;
2821 const char *str = NULL;
2824 dbus_message_iter_get_basic(iter, &str);
2828 for (i = 0; keymgmt_map[i].str; i++)
2829 if (strcmp(str, keymgmt_map[i].str) == 0) {
2830 SUPPLICANT_DBG("Keymgmt: %s", str);
2831 *keymgmt |= keymgmt_map[i].val;
2836 static void bss_group(DBusMessageIter *iter, void *user_data)
2838 unsigned int *group = user_data;
2839 const char *str = NULL;
2842 dbus_message_iter_get_basic(iter, &str);
2846 for (i = 0; group_map[i].str; i++)
2847 if (strcmp(str, group_map[i].str) == 0) {
2848 SUPPLICANT_DBG("Group: %s", str);
2849 *group |= group_map[i].val;
2854 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
2856 unsigned int *pairwise = user_data;
2857 const char *str = NULL;
2860 dbus_message_iter_get_basic(iter, &str);
2864 for (i = 0; pairwise_map[i].str; i++)
2865 if (strcmp(str, pairwise_map[i].str) == 0) {
2866 SUPPLICANT_DBG("Pairwise: %s", str);
2867 *pairwise |= pairwise_map[i].val;
2872 static void bss_wpa(const char *key, DBusMessageIter *iter,
2875 struct g_supplicant_bss *bss = user_data;
2876 unsigned int value = 0;
2878 SUPPLICANT_DBG("Key: %s", key);
2880 if (g_strcmp0(key, "KeyMgmt") == 0) {
2881 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
2883 if (bss->rsn_selected)
2884 bss->rsn_keymgmt = value;
2886 bss->wpa_keymgmt = value;
2887 } else if (g_strcmp0(key, "Group") == 0) {
2888 supplicant_dbus_array_foreach(iter, bss_group, &value);
2890 if (bss->rsn_selected)
2891 bss->rsn_group = value;
2893 bss->wpa_group = value;
2894 } else if (g_strcmp0(key, "Pairwise") == 0) {
2895 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
2897 if (bss->rsn_selected)
2898 bss->rsn_pairwise = value;
2900 bss->wpa_pairwise = value;
2904 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
2907 unsigned int len = 0;
2909 while (len + 4 < ie_size) {
2910 unsigned int hi = ie[len];
2911 unsigned int lo = ie[len + 1];
2912 unsigned int tmp_type = (hi << 8) + lo;
2913 unsigned int v_len = 0;
2915 /* hi and lo are used to recreate an unsigned int
2916 * based on 2 8bits length unsigned int. */
2920 v_len = (hi << 8) + lo;
2922 if (tmp_type == type) {
2923 unsigned int ret_value = 0;
2924 unsigned char *value = (unsigned char *)&ret_value;
2926 SUPPLICANT_DBG("IE: match type 0x%x", type);
2928 /* Verifying length relevance */
2929 if (v_len > sizeof(unsigned int) ||
2930 len + 4 + v_len > ie_size)
2933 memcpy(value, ie + len + 4, v_len);
2935 SUPPLICANT_DBG("returning 0x%x", ret_value);
2942 SUPPLICANT_DBG("returning 0");
2946 #if defined TIZEN_EXT
2947 static void get_bss_phy_mode(unsigned int max_rate,
2948 unsigned int max_ext_rate, bool ht, bool vht, void *data)
2950 struct g_supplicant_bss *bss = data;
2951 unsigned int freq = bss->frequency;
2953 /* Following conditions are used to determine
2954 * IEEE 802.11 Protocol Modes:-
2956 * 1. If “Supported rates” is only till 11 Mbps,
2957 * and frequency is in 2.4GHz band, then protocol is 11B.
2958 * 2. If “Supported rates” is till 54Mbps or
2959 * “Extended supported rates” are present,
2960 * and frequency is in 2.4GHz band, then protocol is 11G.
2961 * 3. If “Supported rates” is only till 54 Mbps,
2962 * frequency is in 5GHz band , then protocol is 11A.
2963 * 4. If “HT capabilities” is supported , then protocol is 11N.
2964 * 5. If “HT capabilities” & “VHT” is supported and
2965 * frequency is in 5 GHz band, then protocol is 11AC.
2968 if (freq >= 2412 && freq <= 2484) { /* 2.4 Ghz Band */
2969 if (max_rate <= 11 && max_ext_rate <= 0 && !ht)
2970 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211B;
2971 else if ((max_rate <= 54 || max_ext_rate > 0) && !ht)
2972 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BG;
2973 else if ((max_rate >= 54 || max_ext_rate > 0) && ht)
2974 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BGN;
2976 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2977 } else if (freq >= 5180 && freq <= 5825) { /* 5 Ghz Band */
2978 if (max_rate <= 54 && !ht)
2979 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211A;
2980 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && !vht)
2981 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211AN;
2982 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && vht)
2983 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211ANAC;
2985 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2990 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
2992 struct g_supplicant_bss *bss = user_data;
2993 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
2994 unsigned char *ie, *ie_end;
2995 DBusMessageIter array;
2998 #if defined TIZEN_EXT
2999 const unsigned char OWE_WFA_OUI[] = { 0x50, 0x6f, 0x9a, 0x1c };
3001 unsigned char *rates = NULL;
3002 unsigned char *ext_rates = NULL;
3003 unsigned int max_rate = 0;
3004 unsigned int max_ext_rate = 0;
3005 unsigned int offset = 0;
3010 #define WMM_WPA1_WPS_INFO 221
3011 #define WPS_INFO_MIN_LEN 6
3012 #define WPS_VERSION_TLV 0x104A
3013 #define WPS_STATE_TLV 0x1044
3014 #define WPS_METHODS_TLV 0x1012
3015 #define WPS_REGISTRAR_TLV 0x1041
3016 #define WPS_VERSION 0x10
3017 #define WPS_PBC 0x04
3018 #define WPS_PIN 0x00
3019 #define WPS_CONFIGURED 0x02
3020 #if defined TIZEN_EXT
3021 #define VENDOR_SPECIFIC_INFO 0xDD
3022 #define WLAN_EID_COUNTRY 7
3023 #define WLAN_EID_RSN_INFO 48
3024 #define RSN_CAPABILITY_MFP_REQ (1 << 6)
3027 dbus_message_iter_recurse(iter, &array);
3028 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
3030 if (!ie || ie_len < 2)
3033 bss->wps_capabilities = 0;
3036 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
3038 #if defined TIZEN_EXT
3039 unsigned char *vsie;
3042 if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, OWE_WFA_OUI, sizeof(OWE_WFA_OUI)) == 0) {
3043 SUPPLICANT_DBG("IE: match vendor specific data : OWE Transition Mode");
3046 Tag: Vendor Specific: Wi-Fi Alliance: OWE Transition Mode
3047 Tag Number: Vendor Specific (221) -> ie[0]
3048 Tag length: 26 -> ie[1]
3049 OUI: 50:6f:9a (Wi-Fi Alliance) -> ie[2]
3050 Vendor Specific OUI Type: 28 -> ie[5]
3051 BSSID: 92:fd:f0:20:2b:09 -> ie[6]
3052 SSID length: 15 -> ie[12]
3053 SSID: Wi-Fi-5.2.3-owe -> ie[13]
3055 0000 dd 1a 50 6f 9a 1c 92 fd f0 20 2b 09 0f 57 69 2d ..Po..... +..Wi-
3056 0010 46 69 2d 35 2e 32 2e 33 2d 6f 77 65 Fi-5.2.3-owe
3059 bss->owe_transition_mode = TRUE;
3060 if (ie[1] >= 11) { // Tag length is at least up to ssid length position.
3061 memcpy(bss->transition_mode_bssid, ie+6, WIFI_BSSID_LEN_MAX);
3062 if (ie[12] > 0 && ie[12] < 32) {
3063 memcpy(bss->transition_mode_ssid, ie+13, ie[12]);
3064 bss->transition_mode_ssid_len = ie[12];
3066 bss->transition_mode_ssid_len = 0;
3068 bss->owe_transition_mode = FALSE;
3072 if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
3074 if (!simplified_log)
3075 SUPPLICANT_DBG("IE: match vendor specific data");
3077 vsie_len = ie[1]+2; // tag number size(1), tag length size(1)
3078 vsie = (unsigned char *)g_try_malloc0(vsie_len);
3081 memcpy(vsie, ie, vsie_len);
3082 bss->vsie_list = g_slist_append(bss->vsie_list, vsie);
3084 SUPPLICANT_DBG("Failed to allocate memory");
3088 if (ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
3089 /* Add country code only if it is a valid alphabet */
3090 if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
3091 memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
3096 if (ie[0] == WLAN_EID_HT_CAP && ie[1]) {
3101 if (ie[0] == WLAN_EID_VHT_CAP && ie[1]) {
3106 if (ie[0] == WLAN_EID_SUPP_RATES && ie[1]) {
3108 rates = g_malloc0(r_len);
3112 for (j = 0; ie && j < r_len; j++) {
3113 rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3114 if (max_rate < rates[j])
3115 max_rate = rates[j];
3120 if (ie[0] == WLAN_EID_EXT_SUPP_RATES && ie[1] > 0) {
3122 ext_rates = g_malloc0(r_len);
3126 for (j = 0; ie && j < r_len; j++) {
3127 ext_rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3128 if (max_ext_rate < ext_rates[j])
3129 max_ext_rate = ext_rates[j];
3134 if (ie[0] == WLAN_EID_RSN_INFO && ie[1] >= 20) {
3136 offset = 10 + ie[8] * 4;
3137 offset += ie[offset] * 4 + 2;
3139 if (offset <= r_len + 1 &&
3140 (ie[offset] & RSN_CAPABILITY_MFP_REQ) != 0)
3141 bss->pmf_required = TRUE;
3146 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
3147 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
3150 SUPPLICANT_DBG("IE: match WPS_OUI");
3152 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
3153 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
3155 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
3157 if (value == WPS_CONFIGURED)
3158 bss->wps_capabilities |=
3159 G_SUPPLICANT_WPS_CONFIGURED;
3162 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
3164 if (GUINT16_FROM_BE(value) == WPS_PBC)
3165 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3166 if (GUINT16_FROM_BE(value) == WPS_PIN)
3167 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3169 bss->wps_capabilities |=
3170 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
3172 /* If the AP sends this it means it's advertizing
3173 * as a registrar and the WPS process is launched
3175 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
3176 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
3178 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
3181 get_bss_phy_mode(max_rate, max_ext_rate, ht, vht, user_data);
3189 static void bss_compute_security(struct g_supplicant_bss *bss)
3192 * Combining RSN and WPA keymgmt
3193 * We combine it since parsing IEs might have set something for WPS. */
3194 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
3196 bss->ieee8021x = FALSE;
3198 #if defined TIZEN_EXT
3199 bss->ft_ieee8021x = FALSE;
3200 bss->ft_psk = FALSE;
3203 #if defined TIZEN_EXT
3205 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3206 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3207 bss->ieee8021x = TRUE;
3208 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
3209 bss->ft_ieee8021x = TRUE;
3212 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3213 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
3214 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3215 bss->ieee8021x = TRUE;
3218 #if defined TIZEN_EXT
3220 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3221 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3223 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
3227 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3228 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
3229 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3233 #if defined TIZEN_EXT
3234 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_SAE |
3235 bss->keymgmt & G_SUPPLICANT_KEYMGMT_FT_SAE)
3237 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_OWE)
3239 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_DPP)
3244 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3245 #if defined TIZEN_EXT
3246 else if (bss->ft_ieee8021x)
3247 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3249 bss->security = G_SUPPLICANT_SECURITY_SAE;
3252 bss->security = G_SUPPLICANT_SECURITY_PSK;
3253 #if defined TIZEN_EXT
3254 else if (bss->ft_psk)
3255 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
3256 else if (bss->owe || bss->owe_transition_mode)
3257 bss->security = G_SUPPLICANT_SECURITY_OWE;
3259 bss->security = G_SUPPLICANT_SECURITY_DPP;
3261 else if (bss->privacy)
3262 bss->security = G_SUPPLICANT_SECURITY_WEP;
3264 bss->security = G_SUPPLICANT_SECURITY_NONE;
3268 static void bss_property(const char *key, DBusMessageIter *iter,
3271 struct g_supplicant_bss *bss = user_data;
3273 if (!bss->interface)
3275 #if defined TIZEN_EXT
3276 if (!simplified_log)
3278 SUPPLICANT_DBG("key %s", key);
3283 if (g_strcmp0(key, "BSSID") == 0) {
3284 DBusMessageIter array;
3285 unsigned char *addr;
3288 dbus_message_iter_recurse(iter, &array);
3289 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
3292 memcpy(bss->bssid, addr, addr_len);
3293 } else if (g_strcmp0(key, "SSID") == 0) {
3294 DBusMessageIter array;
3295 unsigned char *ssid;
3298 dbus_message_iter_recurse(iter, &array);
3299 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
3301 if (ssid_len > 0 && ssid_len < 33) {
3302 memcpy(bss->ssid, ssid, ssid_len);
3303 bss->ssid_len = ssid_len;
3305 memset(bss->ssid, 0, sizeof(bss->ssid));
3308 } else if (g_strcmp0(key, "Capabilities") == 0) {
3309 dbus_uint16_t capabilities = 0x0000;
3311 dbus_message_iter_get_basic(iter, &capabilities);
3313 if (capabilities & IEEE80211_CAP_ESS)
3314 bss->mode = G_SUPPLICANT_MODE_INFRA;
3315 else if (capabilities & IEEE80211_CAP_IBSS)
3316 bss->mode = G_SUPPLICANT_MODE_IBSS;
3318 if (capabilities & IEEE80211_CAP_PRIVACY)
3319 bss->privacy = TRUE;
3320 } else if (g_strcmp0(key, "Mode") == 0) {
3321 const char *mode = NULL;
3323 dbus_message_iter_get_basic(iter, &mode);
3324 bss->mode = string2mode(mode);
3325 } else if (g_strcmp0(key, "Frequency") == 0) {
3326 dbus_uint16_t frequency = 0;
3328 dbus_message_iter_get_basic(iter, &frequency);
3329 bss->frequency = frequency;
3330 } else if (g_strcmp0(key, "Signal") == 0) {
3331 dbus_int16_t signal = 0;
3333 dbus_message_iter_get_basic(iter, &signal);
3335 bss->signal = signal;
3337 bss->signal = BSS_UNKNOWN_STRENGTH;
3339 } else if (g_strcmp0(key, "Level") == 0) {
3340 dbus_int32_t level = 0;
3342 dbus_message_iter_get_basic(iter, &level);
3343 } else if (g_strcmp0(key, "Rates") == 0) {
3344 supplicant_dbus_array_foreach(iter, bss_rates, bss);
3345 } else if (g_strcmp0(key, "MaxRate") == 0) {
3346 dbus_uint32_t maxrate = 0;
3348 dbus_message_iter_get_basic(iter, &maxrate);
3350 bss->maxrate = maxrate;
3351 } else if (g_strcmp0(key, "Privacy") == 0) {
3352 dbus_bool_t privacy = FALSE;
3354 dbus_message_iter_get_basic(iter, &privacy);
3355 bss->privacy = privacy;
3356 } else if (g_strcmp0(key, "RSN") == 0) {
3357 bss->rsn_selected = TRUE;
3359 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3360 } else if (g_strcmp0(key, "WPA") == 0) {
3361 bss->rsn_selected = FALSE;
3363 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3364 #if defined TIZEN_EXT
3365 } else if (g_strcmp0(key, "HS20") == 0) {
3366 dbus_bool_t hs20 = FALSE;
3367 dbus_message_iter_get_basic(iter, &hs20);
3369 } else if (g_strcmp0(key, "SNR") == 0) {
3370 dbus_int16_t snr = 0;
3372 dbus_message_iter_get_basic(iter, &snr);
3374 } else if (g_strcmp0(key, "EstThroughput") == 0) {
3375 dbus_uint32_t est_throughput = 0;
3377 dbus_message_iter_get_basic(iter, &est_throughput);
3378 if (est_throughput != 0)
3379 bss->est_throughput = est_throughput;
3381 } else if (g_strcmp0(key, "IEs") == 0)
3382 bss_process_ies(iter, bss);
3384 SUPPLICANT_DBG("key %s type %c",
3385 key, dbus_message_iter_get_arg_type(iter));
3388 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
3391 GSupplicantInterface *interface = user_data;
3392 GSupplicantNetwork *network;
3393 struct g_supplicant_bss *bss;
3394 const char *path = NULL;
3395 #if defined TIZEN_EXT
3396 if (!simplified_log)
3400 dbus_message_iter_get_basic(iter, &path);
3404 if (g_strcmp0(path, "/") == 0)
3406 #if defined TIZEN_EXT
3407 if (!simplified_log)
3409 SUPPLICANT_DBG("%s", path);
3411 network = g_hash_table_lookup(interface->bss_mapping, path);
3413 bss = g_hash_table_lookup(network->bss_table, path);
3418 bss = g_try_new0(struct g_supplicant_bss, 1);
3422 bss->interface = interface;
3423 bss->path = g_strdup(path);
3424 bss->signal = BSS_UNKNOWN_STRENGTH;
3429 static void interface_bss_added_with_keys(DBusMessageIter *iter,
3432 struct g_supplicant_bss *bss;
3433 #if defined TIZEN_EXT
3434 if (!simplified_log)
3438 bss = interface_bss_added(iter, user_data);
3442 dbus_message_iter_next(iter);
3444 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
3445 #if defined TIZEN_EXT
3455 supplicant_dbus_property_foreach(iter, bss_property, bss);
3457 bss_compute_security(bss);
3458 if (add_or_replace_bss_to_network(bss) < 0)
3459 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3462 static void interface_bss_added_without_keys(DBusMessageIter *iter,
3465 struct g_supplicant_bss *bss;
3466 #if defined TIZEN_EXT
3467 if (!simplified_log)
3471 bss = interface_bss_added(iter, user_data);
3475 supplicant_dbus_property_get_all(bss->path,
3476 SUPPLICANT_INTERFACE ".BSS",
3477 bss_property, bss, bss);
3479 bss_compute_security(bss);
3480 if (add_or_replace_bss_to_network(bss) < 0)
3481 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3484 static void update_signal(gpointer key, gpointer value,
3487 struct g_supplicant_bss *bss = value;
3488 GSupplicantNetwork *network = user_data;
3490 #if defined TIZEN_EXT
3491 if (!network->best_bss || (network->best_bss == bss)) {
3492 if (bss->signal > network->signal) {
3493 network->signal = bss->signal;
3494 network->best_bss = bss;
3499 update_best_bss(network, bss, network->best_bss);
3501 if (bss->signal > network->signal) {
3502 network->signal = bss->signal;
3503 network->best_bss = bss;
3508 static void update_network_signal(GSupplicantNetwork *network)
3510 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
3513 g_hash_table_foreach(network->bss_table,
3514 update_signal, network);
3516 SUPPLICANT_DBG("New network signal %d", network->signal);
3519 #if defined TIZEN_EXT
3520 static gboolean last_connected_timeout(gpointer data)
3522 GSupplicantInterface *interface = data;
3523 GSupplicantNetwork *current_network = interface->current_network;
3525 SUPPLICANT_DBG("Timeout last connected bss");
3527 if (current_network && current_network->best_bss) {
3528 if (compare_bssid(current_network->best_bss->bssid, interface->connected_bssid)) {
3529 g_supplicant_network_set_last_connected_bssid(current_network, interface->connected_bssid);
3530 callback_network_changed(current_network, "LastConnectedBSSID");
3534 last_connected_bss_timeout = 0;
3538 static void add_timer_for_last_connected(GSupplicantInterface *interface)
3540 GSupplicantNetwork *current_network = interface->current_network;
3542 if (interface->state == G_SUPPLICANT_STATE_COMPLETED) {
3543 if (current_network) {
3544 struct g_supplicant_bss *best_bss = current_network->best_bss;
3546 memcpy(interface->connected_bssid, best_bss->bssid, WIFI_BSSID_LEN_MAX);
3548 if (last_connected_bss_timeout)
3549 g_source_remove(last_connected_bss_timeout);
3551 last_connected_bss_timeout = g_timeout_add_seconds(LAST_CONNECTED_TIMEOUT,
3552 last_connected_timeout, interface);
3554 SUPPLICANT_DBG("Add timer for last connected bssid [" MACSTR "]",
3555 MAC2STR(best_bss->bssid));
3560 static void remove_timer_for_last_connected(GSupplicantInterface *interface)
3562 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED) {
3563 if (last_connected_bss_timeout != 0) {
3564 g_source_remove(last_connected_bss_timeout);
3565 last_connected_bss_timeout = 0;
3566 SUPPLICANT_DBG("Remove timer for last connected bss");
3572 static void interface_current_bss(GSupplicantInterface *interface,
3573 DBusMessageIter *iter)
3575 GSupplicantNetwork *network;
3576 struct g_supplicant_bss *bss;
3578 #if defined TIZEN_EXT
3579 char bssid_buff1[WIFI_BSSID_STR_LEN] = {0,};
3580 char bssid_buff2[WIFI_BSSID_STR_LEN] = {0,};
3581 char *bssid_str1 = bssid_buff1;
3582 char *bssid_str2 = bssid_buff2;
3583 gboolean update = FALSE;
3586 dbus_message_iter_get_basic(iter, &path);
3587 if (g_strcmp0(path, "/") == 0) {
3588 interface->current_network = NULL;
3592 interface_bss_added_without_keys(iter, interface);
3594 network = g_hash_table_lookup(interface->bss_mapping, path);
3598 bss = g_hash_table_lookup(network->bss_table, path);
3602 interface->current_network = network;
3603 #if defined TIZEN_EXT
3604 snprintf(bssid_str1, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bss->bssid));
3605 snprintf(bssid_str2, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(network->best_bss->bssid));
3607 SUPPLICANT_DBG("current network [%p], Passed bss %s, best bss %s",
3608 interface->current_network, bssid_str1, bssid_str2);
3610 if (network->frequency != bss->frequency) {
3611 network->frequency = bss->frequency;
3616 if (bss != network->best_bss) {
3618 * This is the case where either wpa_s got associated
3619 * to a BSS different than the one ConnMan considers
3620 * the best, or we are roaming.
3622 SUPPLICANT_DBG("Update best BSS for %s", network->name);
3624 network->best_bss = bss;
3626 if (network->signal != bss->signal) {
3627 SUPPLICANT_DBG("New network signal %d dBm",
3630 network->signal = bss->signal;
3631 callback_network_changed(network, "Signal");
3632 #if defined TIZEN_EXT
3640 #if defined TIZEN_EXT
3642 callback_network_changed(network, "");
3646 * wpa_s could notify about CurrentBSS in any state once
3647 * it got associated. It is not sure such notification will
3648 * arrive together with transition to ASSOCIATED state.
3649 * In fact, for networks with security WEP or OPEN, it
3650 * always arrives together with transition to COMPLETED.
3652 switch (interface->state) {
3653 case G_SUPPLICANT_STATE_UNKNOWN:
3654 case G_SUPPLICANT_STATE_DISABLED:
3655 case G_SUPPLICANT_STATE_DISCONNECTED:
3656 case G_SUPPLICANT_STATE_INACTIVE:
3657 case G_SUPPLICANT_STATE_SCANNING:
3658 case G_SUPPLICANT_STATE_AUTHENTICATING:
3659 case G_SUPPLICANT_STATE_ASSOCIATING:
3661 case G_SUPPLICANT_STATE_ASSOCIATED:
3662 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
3663 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
3664 case G_SUPPLICANT_STATE_COMPLETED:
3665 callback_network_associated(network);
3666 #if defined TIZEN_EXT
3667 add_timer_for_last_connected(interface);
3673 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
3675 GSupplicantInterface *interface = user_data;
3676 GSupplicantNetwork *network;
3677 struct g_supplicant_bss *bss = NULL;
3678 const char *path = NULL;
3679 bool is_current_network_bss = false;
3681 dbus_message_iter_get_basic(iter, &path);
3685 network = g_hash_table_lookup(interface->bss_mapping, path);
3689 bss = g_hash_table_lookup(network->bss_table, path);
3690 if (network->best_bss == bss) {
3691 network->best_bss = NULL;
3692 network->signal = BSS_UNKNOWN_STRENGTH;
3693 is_current_network_bss = true;
3696 g_hash_table_remove(bss_mapping, path);
3698 g_hash_table_remove(interface->bss_mapping, path);
3699 g_hash_table_remove(network->bss_table, path);
3701 update_network_signal(network);
3703 if (g_hash_table_size(network->bss_table) == 0) {
3704 g_hash_table_remove(interface->network_table, network->group);
3706 if (is_current_network_bss && network->best_bss)
3707 #if defined TIZEN_EXT
3708 callback_network_changed(network, "CheckMultiBssidConnect");
3710 callback_network_changed(network, "");
3715 static void set_config_methods(DBusMessageIter *iter, void *user_data)
3717 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
3720 static void wps_property(const char *key, DBusMessageIter *iter,
3723 GSupplicantInterface *interface = user_data;
3727 #if defined TIZEN_EXT
3728 if (!simplified_log)
3730 SUPPLICANT_DBG("key: %s", key);
3732 if (g_strcmp0(key, "ConfigMethods") == 0) {
3733 const char *config_methods = "push_button", *str = NULL;
3735 dbus_message_iter_get_basic(iter, &str);
3736 if (str && strlen(str) > 0) {
3737 /* It was already set at wpa_s level, don't modify it. */
3738 SUPPLICANT_DBG("%s", str);
3742 supplicant_dbus_property_set(interface->path,
3743 SUPPLICANT_INTERFACE ".Interface.WPS",
3744 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
3745 set_config_methods, NULL, &config_methods, NULL);
3747 SUPPLICANT_DBG("No value. Set %s", config_methods);
3752 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3753 void g_supplicant_replace_config_file(const char *ifname, const char *config_file)
3761 SUPPLICANT_DBG("New {%s, %s}", ifname, config_file);
3762 g_hash_table_replace(config_file_table,
3763 g_strdup(ifname), g_strdup(config_file));
3765 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3767 static void interface_property(const char *key, DBusMessageIter *iter,
3770 GSupplicantInterface *interface = user_data;
3774 #if defined TIZEN_EXT
3775 if (!simplified_log)
3777 SUPPLICANT_DBG("%s", key);
3780 debug_strvalmap("KeyMgmt capability", keymgmt_map,
3781 interface->keymgmt_capa);
3782 debug_strvalmap("AuthAlg capability", authalg_capa_map,
3783 interface->authalg_capa);
3784 debug_strvalmap("Protocol capability", proto_capa_map,
3785 interface->proto_capa);
3786 debug_strvalmap("Pairwise capability", pairwise_map,
3787 interface->pairwise_capa);
3788 debug_strvalmap("Group capability", group_map,
3789 interface->group_capa);
3790 debug_strvalmap("Scan capability", scan_capa_map,
3791 interface->scan_capa);
3792 debug_strvalmap("Mode capability", mode_capa_map,
3793 interface->mode_capa);
3795 supplicant_dbus_property_get_all(interface->path,
3796 SUPPLICANT_INTERFACE ".Interface.WPS",
3797 wps_property, interface, interface);
3799 if (interface->ready)
3800 callback_interface_added(interface);
3805 if (g_strcmp0(key, "Capabilities") == 0) {
3806 supplicant_dbus_property_foreach(iter, interface_capability,
3808 #if !defined TIZEN_EXT
3809 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
3810 interface->p2p_support = true;
3812 #if defined TIZEN_EXT_WIFI_MESH
3813 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_MESH)
3814 interface->mesh_support = true;
3816 } else if (g_strcmp0(key, "State") == 0) {
3817 const char *str = NULL;
3819 dbus_message_iter_get_basic(iter, &str);
3821 if (string2state(str) != interface->state) {
3822 interface->state = string2state(str);
3823 callback_interface_state(interface);
3825 #if defined TIZEN_EXT
3826 switch (interface->state) {
3827 case G_SUPPLICANT_STATE_COMPLETED:
3828 add_timer_for_last_connected(interface);
3830 case G_SUPPLICANT_STATE_DISCONNECTED:
3831 remove_timer_for_last_connected(interface);
3837 if (interface->ap_create_in_progress) {
3838 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
3839 callback_ap_create_fail(interface);
3841 interface->ap_create_in_progress = false;
3844 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
3845 interface->ready = FALSE;
3847 interface->ready = TRUE;
3849 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
3850 } else if (g_strcmp0(key, "Scanning") == 0) {
3851 dbus_bool_t scanning = FALSE;
3853 dbus_message_iter_get_basic(iter, &scanning);
3854 interface->scanning = scanning;
3856 if (interface->ready) {
3857 if (interface->scanning)
3858 callback_scan_started(interface);
3860 callback_scan_finished(interface);
3862 } else if (g_strcmp0(key, "ApScan") == 0) {
3865 dbus_message_iter_get_basic(iter, &apscan);
3866 interface->apscan = apscan;
3867 } else if (g_strcmp0(key, "Ifname") == 0) {
3868 const char *str = NULL;
3870 dbus_message_iter_get_basic(iter, &str);
3872 g_free(interface->ifname);
3873 interface->ifname = g_strdup(str);
3875 } else if (g_strcmp0(key, "Driver") == 0) {
3876 const char *str = NULL;
3878 dbus_message_iter_get_basic(iter, &str);
3880 g_free(interface->driver);
3881 interface->driver = g_strdup(str);
3883 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
3884 const char *str = NULL;
3886 dbus_message_iter_get_basic(iter, &str);
3888 g_free(interface->bridge);
3889 interface->bridge = g_strdup(str);
3891 } else if (g_strcmp0(key, "ConfigFile") == 0) {
3892 const char *str = NULL;
3894 dbus_message_iter_get_basic(iter, &str);
3895 if (str && strlen(str) > 0 && interface->ifname) {
3896 SUPPLICANT_DBG("New {%s, %s}", interface->ifname, str);
3897 g_hash_table_replace(config_file_table,
3898 g_strdup(interface->ifname), g_strdup(str));
3900 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
3901 interface_current_bss(interface, iter);
3902 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
3903 #if defined TIZEN_EXT
3904 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
3906 interface_network_added(iter, interface);
3907 } else if (g_strcmp0(key, "BSSs") == 0) {
3908 supplicant_dbus_array_foreach(iter,
3909 interface_bss_added_without_keys,
3911 } else if (g_strcmp0(key, "Blobs") == 0) {
3913 } else if (g_strcmp0(key, "Networks") == 0) {
3914 supplicant_dbus_array_foreach(iter, interface_network_added,
3916 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
3918 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3919 dbus_message_iter_get_basic(iter, &reason_code);
3920 callback_disconnect_reason_code(interface, reason_code);
3921 #if defined TIZEN_EXT
3922 SUPPLICANT_DBG("reason code (%d)", reason_code);
3925 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
3927 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3928 dbus_message_iter_get_basic(iter, &status_code);
3929 callback_assoc_status_code(interface, status_code);
3930 #if defined TIZEN_EXT
3931 SUPPLICANT_DBG("status code (%d)", status_code);
3935 SUPPLICANT_DBG("key %s type %c",
3936 key, dbus_message_iter_get_arg_type(iter));
3940 static void scan_network_update(DBusMessageIter *iter, void *user_data)
3942 GSupplicantInterface *interface = user_data;
3943 GSupplicantNetwork *network;
3949 dbus_message_iter_get_basic(iter, &path);
3954 if (g_strcmp0(path, "/") == 0)
3957 /* Update the network details based on scan BSS data */
3958 network = g_hash_table_lookup(interface->bss_mapping, path);
3960 callback_network_added(network);
3963 static void scan_bss_data(const char *key, DBusMessageIter *iter,
3966 GSupplicantInterface *interface = user_data;
3968 /*Fixed : stucking in scanning state when scan failed*/
3969 #if defined TIZEN_EXT
3970 GSupplicantInterfaceCallback scan_callback;
3975 supplicant_dbus_array_foreach(iter, scan_network_update,
3978 #if defined TIZEN_EXT
3979 scan_callback = interface->scan_callback;
3980 callback_scan_done(interface);
3983 if (interface->scan_callback)
3984 interface->scan_callback(0, interface, interface->scan_data);
3986 #if defined TIZEN_EXT
3987 if (interface->scan_callback == scan_callback) {
3989 interface->scan_callback = NULL;
3990 interface->scan_data = NULL;
3991 #if defined TIZEN_EXT
3996 static GSupplicantInterface *interface_alloc(const char *path)
3998 GSupplicantInterface *interface;
4000 interface = g_try_new0(GSupplicantInterface, 1);
4004 interface->path = g_strdup(path);
4006 interface->network_table = g_hash_table_new_full(g_str_hash,
4007 g_str_equal, NULL, remove_network);
4008 interface->peer_table = g_hash_table_new_full(g_str_hash,
4009 g_str_equal, NULL, remove_peer);
4010 interface->group_table = g_hash_table_new_full(g_str_hash,
4011 g_str_equal, NULL, remove_group);
4012 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
4015 g_hash_table_replace(interface_table, interface->path, interface);
4020 static void interface_added(DBusMessageIter *iter, void *user_data)
4022 GSupplicantInterface *interface;
4023 const char *path = NULL;
4024 bool properties_appended = GPOINTER_TO_UINT(user_data);
4028 dbus_message_iter_get_basic(iter, &path);
4032 if (g_strcmp0(path, "/") == 0)
4035 interface = g_hash_table_lookup(interface_table, path);
4039 interface = interface_alloc(path);
4043 if (!properties_appended) {
4044 supplicant_dbus_property_get_all(path,
4045 SUPPLICANT_INTERFACE ".Interface",
4046 interface_property, interface,
4051 dbus_message_iter_next(iter);
4052 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4053 supplicant_dbus_property_foreach(iter, interface_property,
4055 interface_property(NULL, NULL, interface);
4059 static void interface_removed(DBusMessageIter *iter, void *user_data)
4061 const char *path = NULL;
4062 GSupplicantInterface *interface = user_data;
4064 dbus_message_iter_get_basic(iter, &path);
4068 interface = g_hash_table_lookup(interface_table, path);
4069 g_supplicant_interface_cancel(interface);
4071 g_hash_table_remove(interface_table, path);
4074 static void eap_method(DBusMessageIter *iter, void *user_data)
4076 const char *str = NULL;
4079 dbus_message_iter_get_basic(iter, &str);
4083 for (i = 0; eap_method_map[i].str; i++)
4084 if (strcmp(str, eap_method_map[i].str) == 0) {
4085 eap_methods |= eap_method_map[i].val;
4090 static void service_property(const char *key, DBusMessageIter *iter,
4094 callback_system_ready();
4098 if (g_strcmp0(key, "DebugLevel") == 0) {
4099 const char *str = NULL;
4102 dbus_message_iter_get_basic(iter, &str);
4103 for (i = 0; debug_strings[i]; i++)
4104 if (g_strcmp0(debug_strings[i], str) == 0) {
4108 SUPPLICANT_DBG("Debug level %d", debug_level);
4109 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
4110 dbus_message_iter_get_basic(iter, &debug_timestamp);
4111 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
4112 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
4113 dbus_message_iter_get_basic(iter, &debug_showkeys);
4114 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
4115 } else if (g_strcmp0(key, "Interfaces") == 0) {
4116 supplicant_dbus_array_foreach(iter, interface_added, NULL);
4117 } else if (g_strcmp0(key, "EapMethods") == 0) {
4118 supplicant_dbus_array_foreach(iter, eap_method, NULL);
4119 debug_strvalmap("EAP method", eap_method_map, eap_methods);
4120 } else if (g_strcmp0(key, "Country") == 0) {
4121 const char *country = NULL;
4123 dbus_message_iter_get_basic(iter, &country);
4124 SUPPLICANT_DBG("Country %s", country);
4126 SUPPLICANT_DBG("key %s type %c",
4127 key, dbus_message_iter_get_arg_type(iter));
4130 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
4132 const char *name = NULL, *old = NULL, *new = NULL;
4136 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
4139 dbus_message_iter_get_basic(iter, &name);
4143 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
4146 dbus_message_iter_next(iter);
4147 dbus_message_iter_get_basic(iter, &old);
4148 dbus_message_iter_next(iter);
4149 dbus_message_iter_get_basic(iter, &new);
4154 if (strlen(old) > 0 && strlen(new) == 0) {
4155 system_available = FALSE;
4156 g_hash_table_remove_all(bss_mapping);
4157 g_hash_table_remove_all(peer_mapping);
4158 g_hash_table_remove_all(group_mapping);
4159 g_hash_table_remove_all(config_file_table);
4160 g_hash_table_remove_all(interface_table);
4161 callback_system_killed();
4164 if (strlen(new) > 0 && strlen(old) == 0) {
4165 system_available = TRUE;
4166 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
4167 SUPPLICANT_INTERFACE,
4168 service_property, NULL, NULL);
4172 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
4176 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
4179 supplicant_dbus_property_foreach(iter, service_property, NULL);
4182 static void signal_interface_added(const char *path, DBusMessageIter *iter)
4184 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
4186 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4187 interface_added(iter, GUINT_TO_POINTER(true));
4190 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
4194 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4195 interface_removed(iter, NULL);
4198 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
4200 GSupplicantInterface *interface;
4201 #if defined TIZEN_EXT
4202 if (!simplified_log)
4206 interface = g_hash_table_lookup(interface_table, path);
4210 supplicant_dbus_property_foreach(iter, interface_property, interface);
4213 static void signal_scan_done(const char *path, DBusMessageIter *iter)
4215 GSupplicantInterface *interface;
4216 dbus_bool_t success = FALSE;
4220 interface = g_hash_table_lookup(interface_table, path);
4224 dbus_message_iter_get_basic(iter, &success);
4226 if (interface->scanning) {
4227 callback_scan_finished(interface);
4228 interface->scanning = FALSE;
4232 * If scan is unsuccessful return -EIO else get the scanned BSSs
4233 * and update the network details accordingly
4236 if (interface->scan_callback)
4237 interface->scan_callback(-EIO, interface,
4238 interface->scan_data);
4240 interface->scan_callback = NULL;
4241 interface->scan_data = NULL;
4246 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
4247 "BSSs", scan_bss_data, interface, interface);
4250 static void signal_bss_added(const char *path, DBusMessageIter *iter)
4252 GSupplicantInterface *interface;
4253 #if defined TIZEN_EXT
4254 if (!simplified_log)
4258 interface = g_hash_table_lookup(interface_table, path);
4262 interface_bss_added_with_keys(iter, interface);
4265 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
4267 GSupplicantInterface *interface;
4271 interface = g_hash_table_lookup(interface_table, path);
4275 interface_bss_removed(iter, interface);
4278 static void signal_network_added(const char *path, DBusMessageIter *iter)
4280 GSupplicantInterface *interface;
4284 interface = g_hash_table_lookup(interface_table, path);
4288 interface_network_added(iter, interface);
4291 static void signal_network_removed(const char *path, DBusMessageIter *iter)
4293 GSupplicantInterface *interface;
4297 interface = g_hash_table_lookup(interface_table, path);
4301 interface_network_removed(iter, interface);
4303 #if defined TIZEN_EXT
4304 void *copy_vsie_list(gconstpointer src, gpointer data)
4306 return g_strdup(src);
4311 static void signal_sta_authorized(const char *path, DBusMessageIter *iter)
4313 GSupplicantInterface *interface;
4314 const char *addr = NULL;
4318 interface = g_hash_table_lookup(interface_table, path);
4322 dbus_message_iter_get_basic(iter, &addr);
4326 callback_sta_authorized(interface, addr);
4329 static void signal_sta_deauthorized(const char *path, DBusMessageIter *iter)
4331 GSupplicantInterface *interface;
4332 const char *addr = NULL;
4336 interface = g_hash_table_lookup(interface_table, path);
4340 dbus_message_iter_get_basic(iter, &addr);
4344 callback_sta_deauthorized(interface, addr);
4347 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4348 static void signal_eap(const char *path, DBusMessageIter *iter)
4350 GSupplicantInterface *interface;
4351 const char *str = NULL;
4353 SUPPLICANT_DBG("EAPOL_DEBUG callback eap signal");
4355 interface = g_hash_table_lookup(interface_table, path);
4359 // TODO: Identify EAP fail condition, currently timeout is used for failure.
4361 dbus_message_iter_get_basic(iter, &str);
4365 if (g_strcmp0("completion", str))
4368 dbus_message_iter_next(iter);
4370 dbus_message_iter_get_basic(iter, &str);
4374 if (!g_strcmp0("success", str))
4375 callback_eap(interface, true);
4377 callback_eap(interface, false);
4379 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4381 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
4383 GSupplicantInterface *interface;
4384 GSupplicantNetwork *network;
4385 GSupplicantSecurity old_security;
4386 unsigned int old_wps_capabilities;
4387 struct g_supplicant_bss *bss;
4389 #if defined TIZEN_EXT
4390 if (!simplified_log)
4394 interface = g_hash_table_lookup(bss_mapping, path);
4398 network = g_hash_table_lookup(interface->bss_mapping, path);
4402 bss = g_hash_table_lookup(network->bss_table, path);
4406 supplicant_dbus_property_foreach(iter, bss_property, bss);
4408 #if defined TIZEN_EXT
4409 if (network->interface->state != G_SUPPLICANT_STATE_COMPLETED) {
4410 network->frequency = bss->frequency;
4411 network->phy_mode = bss->phy_mode;
4414 old_security = network->security;
4415 bss_compute_security(bss);
4417 if (old_security != bss->security) {
4418 struct g_supplicant_bss *new_bss;
4420 SUPPLICANT_DBG("New network security for %s with path %s",
4421 bss->ssid, bss->path);
4424 * Security change policy:
4425 * - We first copy the current bss into a new one with
4426 * its own pointer (path)
4427 * - Clear the old bss pointer and remove the network completely
4428 * if there are no more BSSs in the bss table.
4429 * - The new bss will be added either to an existing network
4430 * or an additional network will be created
4433 new_bss = g_try_new0(struct g_supplicant_bss, 1);
4437 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
4438 new_bss->path = g_strdup(bss->path);
4439 #if defined TIZEN_EXT
4440 new_bss->vsie_list = g_slist_copy_deep(bss->vsie_list, copy_vsie_list, NULL);
4443 if (network->best_bss == bss) {
4444 network->best_bss = NULL;
4445 network->signal = BSS_UNKNOWN_STRENGTH;
4448 g_hash_table_remove(bss_mapping, path);
4450 g_hash_table_remove(interface->bss_mapping, path);
4451 g_hash_table_remove(network->bss_table, path);
4453 update_network_signal(network);
4455 if (g_hash_table_size(network->bss_table) == 0)
4456 g_hash_table_remove(interface->network_table,
4459 if (add_or_replace_bss_to_network(new_bss) < 0) {
4461 * Prevent a memory leak on failure in
4462 * add_or_replace_bss_to_network
4464 SUPPLICANT_DBG("Failed to add bss %s to network table",
4466 g_free(new_bss->path);
4473 old_wps_capabilities = network->wps_capabilities;
4475 if (old_wps_capabilities != bss->wps_capabilities) {
4476 network->wps_capabilities = bss->wps_capabilities;
4477 callback_network_changed(network, "WPSCapabilities");
4480 #if defined TIZEN_EXT
4481 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
4482 network->wps = TRUE;
4483 network->wps_capabilities |= bss->wps_capabilities;
4485 network->wps = FALSE;
4488 /* Consider only property changes of the connected BSS */
4489 if (network == interface->current_network && bss != network->best_bss)
4492 if (bss->signal == network->signal)
4497 callback_network_changed(network, "");
4503 * If the new signal is lower than the SSID signal, we need
4504 * to check for the new maximum.
4506 #if defined TIZEN_EXT
4507 if (!update_best_bss(network, bss, network->best_bss)) {
4508 if (bss != network->best_bss) {
4509 callback_network_changed(network, "");
4513 network->signal = bss->signal;
4514 update_network_signal(network);
4517 if (bss->signal < network->signal) {
4518 if (bss != network->best_bss)
4521 network->signal = bss->signal;
4522 update_network_signal(network);
4524 network->signal = bss->signal;
4525 network->best_bss = bss;
4529 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
4532 callback_network_changed(network, "Signal");
4535 static void wps_credentials(const char *key, DBusMessageIter *iter,
4538 GSupplicantInterface *interface = user_data;
4543 SUPPLICANT_DBG("key %s", key);
4545 if (g_strcmp0(key, "Key") == 0) {
4546 DBusMessageIter array;
4547 unsigned char *key_val;
4550 dbus_message_iter_recurse(iter, &array);
4551 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
4553 g_free(interface->wps_cred.key);
4554 interface->wps_cred.key = g_try_malloc0(
4555 sizeof(char) * key_len + 1);
4557 if (!interface->wps_cred.key)
4560 memcpy(interface->wps_cred.key, key_val,
4561 sizeof(char) * key_len);
4563 SUPPLICANT_DBG("WPS key present");
4564 } else if (g_strcmp0(key, "SSID") == 0) {
4565 DBusMessageIter array;
4566 unsigned char *ssid;
4569 dbus_message_iter_recurse(iter, &array);
4570 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
4572 if (ssid_len > 0 && ssid_len < 33) {
4573 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
4574 interface->wps_cred.ssid_len = ssid_len;
4576 memset(interface->wps_cred.ssid, 0, 32);
4577 interface->wps_cred.ssid_len = 0;
4582 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
4584 GSupplicantInterface *interface;
4588 interface = g_hash_table_lookup(interface_table, path);
4592 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
4595 static void wps_event_args(const char *key, DBusMessageIter *iter,
4598 GSupplicantInterface *interface = user_data;
4600 if (!key || !interface)
4603 SUPPLICANT_DBG("Arg Key %s", key);
4606 static void signal_wps_event(const char *path, DBusMessageIter *iter)
4608 GSupplicantInterface *interface;
4609 const char *name = NULL;
4613 interface = g_hash_table_lookup(interface_table, path);
4617 dbus_message_iter_get_basic(iter, &name);
4619 SUPPLICANT_DBG("Name: %s", name);
4621 if (g_strcmp0(name, "success") == 0)
4622 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
4623 else if (g_strcmp0(name, "fail") == 0)
4624 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
4626 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
4628 if (!dbus_message_iter_has_next(iter))
4631 dbus_message_iter_next(iter);
4633 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
4636 #if defined TIZEN_EXT
4637 static void signal_power_off(const char *path, DBusMessageIter *iter)
4639 int poweroff_state = 0;
4641 dbus_message_iter_get_basic(iter, &poweroff_state);
4643 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
4645 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
4646 if (poweroff_state != 2 && poweroff_state != 3)
4649 if (callbacks_pointer == NULL)
4652 if (callbacks_pointer->system_power_off == NULL)
4655 callbacks_pointer->system_power_off();
4659 static void create_peer_identifier(GSupplicantPeer *peer)
4661 const unsigned char test[ETH_ALEN] = {};
4666 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
4667 peer->identifier = g_strdup(peer->name);
4671 peer->identifier = g_malloc0(19);
4672 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
4673 peer->device_address[0],
4674 peer->device_address[1],
4675 peer->device_address[2],
4676 peer->device_address[3],
4677 peer->device_address[4],
4678 peer->device_address[5]);
4681 struct peer_property_data {
4682 GSupplicantPeer *peer;
4684 bool groups_changed;
4685 bool services_changed;
4688 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
4690 struct peer_property_data *data = user_data;
4691 GSupplicantPeer *peer = data->peer;
4692 GSupplicantGroup *group;
4693 const char *str = NULL;
4696 dbus_message_iter_get_basic(iter, &str);
4700 group = g_hash_table_lookup(group_mapping, str);
4704 elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
4706 data->old_groups = g_slist_remove_link(data->old_groups, elem);
4707 peer->groups = g_slist_concat(elem, peer->groups);
4709 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
4710 data->groups_changed = true;
4714 static void peer_property(const char *key, DBusMessageIter *iter,
4717 GSupplicantPeer *pending_peer;
4718 struct peer_property_data *data = user_data;
4719 GSupplicantPeer *peer = data->peer;
4721 SUPPLICANT_DBG("key: %s", key);
4723 if (!peer->interface)
4728 create_peer_identifier(peer);
4729 callback_peer_found(peer);
4730 pending_peer = g_hash_table_lookup(
4731 pending_peer_connection, peer->path);
4733 if (pending_peer && pending_peer == peer) {
4734 callback_peer_request(peer);
4735 g_hash_table_remove(pending_peer_connection,
4745 if (g_strcmp0(key, "DeviceAddress") == 0) {
4746 unsigned char *dev_addr;
4747 DBusMessageIter array;
4750 dbus_message_iter_recurse(iter, &array);
4751 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4753 if (len == ETH_ALEN)
4754 memcpy(peer->device_address, dev_addr, len);
4755 } else if (g_strcmp0(key, "DeviceName") == 0) {
4756 const char *str = NULL;
4758 dbus_message_iter_get_basic(iter, &str);
4760 peer->name = g_strdup(str);
4761 } else if (g_strcmp0(key, "config_method") == 0) {
4762 uint16_t wps_config;
4764 dbus_message_iter_get_basic(iter, &wps_config);
4766 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
4767 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
4768 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
4769 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
4770 } else if (g_strcmp0(key, "Groups") == 0) {
4771 data->old_groups = peer->groups;
4772 peer->groups = NULL;
4774 supplicant_dbus_array_foreach(iter,
4775 peer_groups_relation, data);
4776 if (g_slist_length(data->old_groups) > 0) {
4777 g_slist_free_full(data->old_groups, g_free);
4778 data->groups_changed = true;
4780 } else if (g_strcmp0(key, "IEs") == 0) {
4781 DBusMessageIter array;
4785 dbus_message_iter_recurse(iter, &array);
4786 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
4788 if (!ie || ie_len < 2)
4791 if (peer->widi_ies) {
4792 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
4795 g_free(peer->widi_ies);
4796 peer->widi_ies_length = 0;
4799 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
4801 memcpy(peer->widi_ies, ie, ie_len);
4802 peer->widi_ies_length = ie_len;
4803 data->services_changed = true;
4807 static void signal_peer_found(const char *path, DBusMessageIter *iter)
4809 struct peer_property_data *property_data;
4810 GSupplicantInterface *interface;
4811 const char *obj_path = NULL;
4812 GSupplicantPeer *peer;
4816 interface = g_hash_table_lookup(interface_table, path);
4820 dbus_message_iter_get_basic(iter, &obj_path);
4821 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4824 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4828 peer = g_try_new0(GSupplicantPeer, 1);
4832 peer->interface = interface;
4833 peer->path = g_strdup(obj_path);
4834 g_hash_table_insert(interface->peer_table, peer->path, peer);
4835 g_hash_table_replace(peer_mapping, peer->path, interface);
4837 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4838 property_data->peer = peer;
4840 dbus_message_iter_next(iter);
4841 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4842 supplicant_dbus_property_foreach(iter, peer_property,
4844 peer_property(NULL, NULL, property_data);
4848 supplicant_dbus_property_get_all(obj_path,
4849 SUPPLICANT_INTERFACE ".Peer",
4850 peer_property, property_data, NULL);
4853 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
4855 GSupplicantInterface *interface;
4856 const char *obj_path = NULL;
4857 GSupplicantPeer *peer;
4861 interface = g_hash_table_lookup(interface_table, path);
4865 dbus_message_iter_get_basic(iter, &obj_path);
4866 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4869 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4873 g_hash_table_remove(interface->peer_table, obj_path);
4876 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
4878 struct peer_property_data *property_data;
4879 GSupplicantInterface *interface;
4880 GSupplicantPeer *peer;
4884 interface = g_hash_table_lookup(peer_mapping, path);
4888 peer = g_hash_table_lookup(interface->peer_table, path);
4890 g_hash_table_remove(peer_mapping, path);
4894 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4895 property_data->peer = peer;
4897 supplicant_dbus_property_foreach(iter, peer_property, property_data);
4898 if (property_data->services_changed)
4899 callback_peer_changed(peer,
4900 G_SUPPLICANT_PEER_SERVICES_CHANGED);
4902 if (property_data->groups_changed)
4903 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
4905 dbus_free(property_data);
4907 if (!g_supplicant_peer_is_in_a_group(peer))
4908 peer->connection_requested = false;
4911 struct group_sig_data {
4912 const char *peer_obj_path;
4913 unsigned char iface_address[ETH_ALEN];
4914 const char *interface_obj_path;
4915 const char *group_obj_path;
4919 static void group_sig_property(const char *key, DBusMessageIter *iter,
4922 struct group_sig_data *data = user_data;
4927 if (g_strcmp0(key, "peer_interface_addr") == 0) {
4928 unsigned char *dev_addr;
4929 DBusMessageIter array;
4932 dbus_message_iter_recurse(iter, &array);
4933 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4935 if (len == ETH_ALEN)
4936 memcpy(data->iface_address, dev_addr, len);
4937 } else if (g_strcmp0(key, "role") == 0) {
4938 const char *str = NULL;
4940 dbus_message_iter_get_basic(iter, &str);
4941 if (g_strcmp0(str, "GO") == 0)
4942 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
4944 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
4945 } else if (g_strcmp0(key, "peer_object") == 0)
4946 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
4947 else if (g_strcmp0(key, "interface_object") == 0)
4948 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
4949 else if (g_strcmp0(key, "group_object") == 0)
4950 dbus_message_iter_get_basic(iter, &data->group_obj_path);
4954 static void signal_group_success(const char *path, DBusMessageIter *iter)
4956 GSupplicantInterface *interface;
4957 struct group_sig_data data = {};
4958 GSupplicantPeer *peer;
4962 interface = g_hash_table_lookup(interface_table, path);
4966 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4967 if (!data.peer_obj_path)
4970 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4974 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
4975 interface->pending_peer_path = peer->path;
4978 static void signal_group_failure(const char *path, DBusMessageIter *iter)
4980 GSupplicantInterface *interface;
4981 struct group_sig_data data = {};
4982 GSupplicantPeer *peer;
4986 interface = g_hash_table_lookup(interface_table, path);
4990 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4991 if (!data.peer_obj_path)
4994 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4998 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
4999 peer->connection_requested = false;
5002 static void signal_group_started(const char *path, DBusMessageIter *iter)
5004 GSupplicantInterface *interface, *g_interface;
5005 struct group_sig_data data = {};
5006 GSupplicantGroup *group;
5007 GSupplicantPeer *peer;
5011 interface = g_hash_table_lookup(interface_table, path);
5015 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5016 if (!data.interface_obj_path || !data.group_obj_path)
5019 peer = g_hash_table_lookup(interface->peer_table,
5020 interface->pending_peer_path);
5021 interface->pending_peer_path = NULL;
5025 g_interface = g_hash_table_lookup(interface_table,
5026 data.interface_obj_path);
5030 group = g_hash_table_lookup(interface->group_table,
5031 data.group_obj_path);
5035 group = g_try_new0(GSupplicantGroup, 1);
5039 group->interface = g_interface;
5040 group->orig_interface = interface;
5041 group->path = g_strdup(data.group_obj_path);
5042 group->role = data.role;
5044 g_hash_table_insert(interface->group_table, group->path, group);
5045 g_hash_table_replace(group_mapping, group->path, group);
5047 peer->current_group_iface = g_interface;
5048 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
5051 static void remove_peer_group_interface(GHashTable *group_table,
5054 GSupplicantGroup *group;
5055 GHashTableIter iter;
5056 gpointer value, key;
5061 group = g_hash_table_lookup(group_table, path);
5063 if (!group || !group->orig_interface)
5066 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
5068 while (g_hash_table_iter_next(&iter, &key, &value)) {
5069 GSupplicantPeer *peer = value;
5071 if (peer->current_group_iface == group->interface)
5072 peer->current_group_iface = NULL;
5076 static void signal_group_finished(const char *path, DBusMessageIter *iter)
5078 GSupplicantInterface *interface;
5079 struct group_sig_data data = {};
5083 interface = g_hash_table_lookup(interface_table, path);
5087 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5088 if (!data.interface_obj_path || !data.group_obj_path)
5091 remove_peer_group_interface(interface->group_table, data.group_obj_path);
5093 g_hash_table_remove(group_mapping, data.group_obj_path);
5095 g_hash_table_remove(interface->group_table, data.group_obj_path);
5098 static void signal_group_request(const char *path, DBusMessageIter *iter)
5100 GSupplicantInterface *interface;
5101 GSupplicantPeer *peer;
5102 const char *obj_path;
5106 interface = g_hash_table_lookup(interface_table, path);
5110 dbus_message_iter_get_basic(iter, &obj_path);
5111 if (!obj_path || !g_strcmp0(obj_path, "/"))
5114 peer = g_hash_table_lookup(interface->peer_table, obj_path);
5119 * Peer has been previously found and property set,
5120 * otherwise, defer connection to when peer property
5123 if (peer->identifier)
5124 callback_peer_request(peer);
5126 g_hash_table_replace(pending_peer_connection, peer->path, peer);
5129 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
5131 const char *peer_path = NULL;
5132 GSupplicantInterface *interface;
5133 GSupplicantGroup *group;
5134 GSupplicantPeer *peer;
5138 group = g_hash_table_lookup(group_mapping, path);
5142 dbus_message_iter_get_basic(iter, &peer_path);
5146 interface = g_hash_table_lookup(peer_mapping, peer_path);
5150 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5154 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
5156 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
5159 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
5161 const char *peer_path = NULL;
5162 GSupplicantInterface *interface;
5163 GSupplicantGroup *group;
5164 GSupplicantPeer *peer;
5169 group = g_hash_table_lookup(group_mapping, path);
5173 dbus_message_iter_get_basic(iter, &peer_path);
5177 for (elem = group->members; elem; elem = elem->next) {
5178 if (!g_strcmp0(elem->data, peer_path))
5186 group->members = g_slist_delete_link(group->members, elem);
5188 interface = g_hash_table_lookup(peer_mapping, peer_path);
5192 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5196 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
5197 peer->connection_requested = false;
5200 #if defined TIZEN_EXT_WIFI_MESH
5201 const void *g_supplicant_interface_get_mesh_group_ssid(
5202 GSupplicantInterface *interface,
5203 unsigned int *ssid_len)
5208 if (!interface || interface->group_info.ssid_len == 0) {
5213 *ssid_len = interface->group_info.ssid_len;
5214 return interface->group_info.ssid;
5217 int g_supplicant_mesh_get_disconnect_reason(GSupplicantInterface *interface)
5222 return interface->group_info.disconnect_reason;
5225 const char *g_supplicant_mesh_peer_get_address(GSupplicantMeshPeer *mesh_peer)
5227 if (!mesh_peer || !mesh_peer->peer_address)
5230 return mesh_peer->peer_address;
5233 int g_supplicant_mesh_peer_get_disconnect_reason(GSupplicantMeshPeer *mesh_peer)
5238 return mesh_peer->disconnect_reason;
5241 static void callback_mesh_group_started(GSupplicantInterface *interface)
5243 if (!callbacks_pointer)
5246 if (!callbacks_pointer->mesh_group_started)
5249 callbacks_pointer->mesh_group_started(interface);
5252 static void callback_mesh_group_removed(GSupplicantInterface *interface)
5254 if (!callbacks_pointer)
5257 if (!callbacks_pointer->mesh_group_removed)
5260 callbacks_pointer->mesh_group_removed(interface);
5263 static void mesh_group_info(const char *key, DBusMessageIter *iter,
5266 GSupplicantInterface *interface = user_data;
5270 if (g_strcmp0(key, "SSID") == 0) {
5271 DBusMessageIter array;
5272 unsigned char *ssid;
5275 dbus_message_iter_recurse(iter, &array);
5276 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
5278 if (ssid_len > 0 && ssid_len < 33) {
5279 memcpy(interface->group_info.ssid, ssid, ssid_len);
5280 interface->group_info.ssid_len = ssid_len;
5282 memset(interface->group_info.ssid, 0, 32);
5283 interface->group_info.ssid_len = 0;
5285 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5286 int disconnect_reason = 0;
5287 dbus_message_iter_get_basic(iter, &disconnect_reason);
5288 interface->group_info.disconnect_reason = disconnect_reason;
5292 static void signal_mesh_group_started(const char *path, DBusMessageIter *iter)
5294 GSupplicantInterface *interface;
5296 interface = g_hash_table_lookup(interface_table, path);
5300 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5302 callback_mesh_group_started(interface);
5305 static void signal_mesh_group_removed(const char *path, DBusMessageIter *iter)
5307 GSupplicantInterface *interface;
5309 interface = g_hash_table_lookup(interface_table, path);
5313 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5315 callback_mesh_group_removed(interface);
5318 static void callback_mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
5320 if (!callbacks_pointer)
5323 if (!callbacks_pointer->mesh_peer_connected)
5326 callbacks_pointer->mesh_peer_connected(mesh_peer);
5329 static void callback_mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
5331 if (!callbacks_pointer)
5334 if (!callbacks_pointer->mesh_peer_disconnected)
5337 callbacks_pointer->mesh_peer_disconnected(mesh_peer);
5340 static void mesh_peer_info(const char *key, DBusMessageIter *iter,
5343 GSupplicantMeshPeer *mesh_peer = user_data;
5347 if (g_strcmp0(key, "PeerAddress") == 0) {
5348 DBusMessageIter array;
5349 unsigned char *addr;
5352 dbus_message_iter_recurse(iter, &array);
5353 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
5355 if (addr_len == 6) {
5356 mesh_peer->peer_address = g_malloc0(19);
5357 snprintf(mesh_peer->peer_address, 19,
5358 "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1],
5359 addr[2], addr[3], addr[4], addr[5]);
5361 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5362 int disconnect_reason = 0;
5363 dbus_message_iter_get_basic(iter, &disconnect_reason);
5364 mesh_peer->disconnect_reason = disconnect_reason;
5368 static void signal_mesh_peer_connected(const char *path, DBusMessageIter *iter)
5370 GSupplicantInterface *interface;
5371 GSupplicantMeshPeer *mesh_peer;
5373 interface = g_hash_table_lookup(interface_table, path);
5377 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5378 mesh_peer->interface = interface;
5380 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5382 callback_mesh_peer_connected(mesh_peer);
5383 g_free(mesh_peer->peer_address);
5387 static void signal_mesh_peer_disconnected(const char *path,
5388 DBusMessageIter *iter)
5390 GSupplicantInterface *interface;
5391 GSupplicantMeshPeer *mesh_peer;
5393 interface = g_hash_table_lookup(interface_table, path);
5397 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5398 mesh_peer->interface = interface;
5400 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5402 callback_mesh_peer_disconnected(mesh_peer);
5403 g_free(mesh_peer->peer_address);
5409 const char *interface;
5411 void (*function) (const char *path, DBusMessageIter *iter);
5413 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
5415 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
5416 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
5417 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
5418 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
5420 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
5421 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
5422 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
5423 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
5424 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
5425 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
5426 { SUPPLICANT_INTERFACE ".Interface", "StaAuthorized", signal_sta_authorized },
5427 { SUPPLICANT_INTERFACE ".Interface", "StaDeauthorized", signal_sta_deauthorized },
5429 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
5431 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
5432 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
5433 #if defined TIZEN_EXT
5434 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
5437 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
5438 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
5440 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
5442 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
5443 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
5444 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
5445 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
5446 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
5448 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
5449 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
5450 #if defined TIZEN_EXT_WIFI_MESH
5451 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupStarted",
5452 signal_mesh_group_started },
5453 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupRemoved",
5454 signal_mesh_group_removed },
5455 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerConnected",
5456 signal_mesh_peer_connected },
5457 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerDisconnected",
5458 signal_mesh_peer_disconnected },
5461 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5462 { SUPPLICANT_INTERFACE ".Interface", "EAP", signal_eap },
5463 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5468 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
5469 DBusMessage *message, void *data)
5471 DBusMessageIter iter;
5475 path = dbus_message_get_path(message);
5477 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5479 if (!dbus_message_iter_init(message, &iter))
5480 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5482 for (i = 0; signal_map[i].interface; i++) {
5483 if (!dbus_message_has_interface(message, signal_map[i].interface))
5486 if (!dbus_message_has_member(message, signal_map[i].member))
5489 signal_map[i].function(path, &iter);
5493 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5496 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
5498 SUPPLICANT_DBG("Cancelling any pending DBus calls");
5499 supplicant_dbus_method_call_cancel_all(interface);
5500 supplicant_dbus_property_call_cancel_all(interface);
5503 struct supplicant_regdom {
5504 GSupplicantCountryCallback callback;
5506 const void *user_data;
5509 static void country_result(const char *error,
5510 DBusMessageIter *iter, void *user_data)
5512 struct supplicant_regdom *regdom = user_data;
5515 SUPPLICANT_DBG("Country setting result");
5521 SUPPLICANT_DBG("Country setting failure %s", error);
5525 if (regdom->callback)
5526 regdom->callback(result, regdom->alpha2,
5527 (void *) regdom->user_data);
5532 static void country_params(DBusMessageIter *iter, void *user_data)
5534 struct supplicant_regdom *regdom = user_data;
5536 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
5540 int g_supplicant_set_country(const char *alpha2,
5541 GSupplicantCountryCallback callback,
5542 const void *user_data)
5544 struct supplicant_regdom *regdom;
5547 SUPPLICANT_DBG("Country setting %s", alpha2);
5549 if (!system_available)
5552 regdom = dbus_malloc0(sizeof(*regdom));
5556 regdom->callback = callback;
5557 regdom->alpha2 = alpha2;
5558 regdom->user_data = user_data;
5560 ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
5561 "Country", DBUS_TYPE_STRING_AS_STRING,
5562 country_params, country_result,
5566 SUPPLICANT_DBG("Unable to set Country configuration");
5571 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
5572 GSupplicantCountryCallback callback,
5576 struct supplicant_regdom *regdom;
5579 regdom = dbus_malloc0(sizeof(*regdom));
5583 regdom->callback = callback;
5584 regdom->alpha2 = alpha2;
5585 regdom->user_data = user_data;
5587 ret = supplicant_dbus_property_set(interface->path,
5588 SUPPLICANT_INTERFACE ".Interface",
5589 "Country", DBUS_TYPE_STRING_AS_STRING,
5590 country_params, country_result,
5594 SUPPLICANT_DBG("Unable to set Country configuration");
5600 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
5605 return interface->p2p_support;
5608 struct supplicant_p2p_dev_config {
5613 static void p2p_device_config_result(const char *error,
5614 DBusMessageIter *iter, void *user_data)
5616 struct supplicant_p2p_dev_config *config = user_data;
5619 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
5622 g_free(config->device_name);
5623 g_free(config->dev_type);
5627 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
5629 int length, pos, end;
5634 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
5641 dev_type[length] = strtol(b, &e, 16);
5642 if (e && *e != '\0')
5651 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
5653 struct supplicant_p2p_dev_config *config = user_data;
5654 DBusMessageIter dict;
5656 supplicant_dbus_dict_open(iter, &dict);
5658 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
5659 DBUS_TYPE_STRING, &config->device_name);
5661 if (config->dev_type) {
5662 unsigned char dev_type[8] = {}, *type;
5665 len = dev_type_str2bin(config->dev_type, dev_type);
5668 supplicant_dbus_dict_append_fixed_array(&dict,
5669 "PrimaryDeviceType",
5670 DBUS_TYPE_BYTE, &type, len);
5674 supplicant_dbus_dict_close(iter, &dict);
5677 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
5678 const char *device_name,
5679 const char *primary_dev_type)
5681 struct supplicant_p2p_dev_config *config;
5684 SUPPLICANT_DBG("P2P Device settings %s/%s",
5685 device_name, primary_dev_type);
5687 config = dbus_malloc0(sizeof(*config));
5691 config->device_name = g_strdup(device_name);
5692 config->dev_type = g_strdup(primary_dev_type);
5694 ret = supplicant_dbus_property_set(interface->path,
5695 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5697 DBUS_TYPE_ARRAY_AS_STRING
5698 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
5699 DBUS_TYPE_STRING_AS_STRING
5700 DBUS_TYPE_VARIANT_AS_STRING
5701 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
5702 p2p_device_config_params,
5703 p2p_device_config_result, config, NULL);
5705 g_free(config->device_name);
5706 g_free(config->dev_type);
5708 SUPPLICANT_DBG("Unable to set P2P Device configuration");
5714 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
5717 const GSupplicantPeer *peer = value;
5718 const char *identifier = user_data;
5720 if (!g_strcmp0(identifier, peer->identifier))
5726 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
5727 const char *identifier)
5729 GSupplicantPeer *peer;
5731 peer = g_hash_table_find(interface->peer_table,
5732 peer_lookup_by_identifier,
5733 (void *) identifier);
5737 static void interface_create_data_free(struct interface_create_data *data)
5739 g_free(data->ifname);
5740 g_free(data->driver);
5741 g_free(data->bridge);
5742 #if defined TIZEN_EXT_WIFI_MESH
5743 g_free(data->parent_ifname);
5748 static bool interface_exists(GSupplicantInterface *interface,
5751 GSupplicantInterface *tmp;
5753 tmp = g_hash_table_lookup(interface_table, path);
5754 if (tmp && tmp == interface)
5760 static void interface_create_property(const char *key, DBusMessageIter *iter,
5763 struct interface_create_data *data = user_data;
5764 GSupplicantInterface *interface = data->interface;
5767 if (data->callback) {
5768 data->callback(0, data->interface, data->user_data);
5769 #if !defined TIZEN_EXT
5770 callback_p2p_support(interface);
5772 #if defined TIZEN_EXT_WIFI_MESH
5773 callback_mesh_support(interface);
5777 interface_create_data_free(data);
5780 interface_property(key, iter, interface);
5783 static void interface_create_result(const char *error,
5784 DBusMessageIter *iter, void *user_data)
5786 struct interface_create_data *data = user_data;
5787 const char *path = NULL;
5793 g_warning("error %s", error);
5798 dbus_message_iter_get_basic(iter, &path);
5804 if (!system_available) {
5809 data->interface = g_hash_table_lookup(interface_table, path);
5810 if (!data->interface) {
5811 data->interface = interface_alloc(path);
5812 if (!data->interface) {
5818 err = supplicant_dbus_property_get_all(path,
5819 SUPPLICANT_INTERFACE ".Interface",
5820 interface_create_property, data,
5827 data->callback(err, NULL, data->user_data);
5829 interface_create_data_free(data);
5832 static void interface_create_params(DBusMessageIter *iter, void *user_data)
5834 struct interface_create_data *data = user_data;
5835 DBusMessageIter dict;
5836 char *config_file = NULL;
5840 supplicant_dbus_dict_open(iter, &dict);
5842 supplicant_dbus_dict_append_basic(&dict, "Ifname",
5843 DBUS_TYPE_STRING, &data->ifname);
5846 supplicant_dbus_dict_append_basic(&dict, "Driver",
5847 DBUS_TYPE_STRING, &data->driver);
5850 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
5851 DBUS_TYPE_STRING, &data->bridge);
5853 config_file = g_hash_table_lookup(config_file_table, data->ifname);
5855 SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
5857 supplicant_dbus_dict_append_basic(&dict, "ConfigFile",
5858 DBUS_TYPE_STRING, &config_file);
5862 if (data->driver && g_strstr_len(data->driver, strlen(data->driver), "nl80211")) {
5863 supplicant_dbus_dict_append_basic(&dict, "MacAddr",
5864 DBUS_TYPE_UINT32, &data->mac_addr);
5866 supplicant_dbus_dict_append_basic(&dict, "PreassocMacAddr",
5867 DBUS_TYPE_UINT32, &data->preassoc_mac_addr);
5869 supplicant_dbus_dict_append_basic(&dict, "RandAddrLifetime",
5870 DBUS_TYPE_UINT32, &data->random_mac_lifetime);
5872 #endif /* TIZEN_EXT */
5874 #if defined TIZEN_EXT_WIFI_MESH
5875 if (data->is_mesh_interface) {
5876 if (data->parent_ifname)
5877 supplicant_dbus_dict_append_basic(&dict, "ParentIfname",
5878 DBUS_TYPE_STRING, &data->parent_ifname);
5880 supplicant_dbus_dict_append_basic(&dict, "IsMeshInterface",
5881 DBUS_TYPE_BOOLEAN, &data->is_mesh_interface);
5885 supplicant_dbus_dict_close(iter, &dict);
5888 #if defined TIZEN_EXT
5889 static void interface_get_state(const char *key, DBusMessageIter *iter,
5892 struct interface_create_data *data = user_data;
5893 GSupplicantInterface *interface = NULL;
5894 const char *str = NULL;
5896 SUPPLICANT_DBG("key[%s]", key);
5899 SUPPLICANT_DBG("data is NULL");
5903 interface = data->interface;
5905 SUPPLICANT_DBG("interface is NULL");
5910 dbus_message_iter_get_basic(iter, &str);
5913 if (string2state(str) != interface->state)
5914 interface->state = string2state(str);
5917 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
5918 interface->ready = FALSE;
5920 interface->ready = TRUE;
5922 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
5924 if (data->callback) {
5925 data->callback(0, interface, data->user_data);
5926 #if defined TIZEN_EXT_WIFI_MESH
5927 callback_mesh_support(interface);
5931 interface_create_data_free(data);
5935 static void interface_get_result(const char *error,
5936 DBusMessageIter *iter, void *user_data)
5938 struct interface_create_data *data = user_data;
5939 GSupplicantInterface *interface;
5940 const char *path = NULL;
5943 #if defined TIZEN_EXT
5944 if (!simplified_log)
5949 SUPPLICANT_DBG("Interface not created yet");
5953 dbus_message_iter_get_basic(iter, &path);
5959 interface = g_hash_table_lookup(interface_table, path);
5965 #if defined TIZEN_EXT
5966 data->interface = interface;
5967 err = supplicant_dbus_property_get(path,
5968 SUPPLICANT_INTERFACE ".Interface",
5969 "State", interface_get_state, data, NULL);
5975 if (data->callback) {
5976 data->callback(0, interface, data->user_data);
5977 #if !defined TIZEN_EXT
5978 callback_p2p_support(interface);
5980 #if defined TIZEN_EXT_WIFI_MESH
5981 callback_mesh_support(interface);
5985 interface_create_data_free(data);
5990 if (!system_available) {
5995 SUPPLICANT_DBG("Creating interface");
5997 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
5998 SUPPLICANT_INTERFACE,
6000 interface_create_params,
6001 interface_create_result, data,
6008 data->callback(err, NULL, data->user_data);
6010 interface_create_data_free(data);
6013 static void interface_get_params(DBusMessageIter *iter, void *user_data)
6015 struct interface_create_data *data = user_data;
6016 #if defined TIZEN_EXT
6017 if (!simplified_log)
6021 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
6024 #if defined TIZEN_EXT_WIFI_MESH
6025 int g_supplicant_mesh_interface_create(const char *ifname, const char *driver,
6026 const char *bridge, const char *parent_ifname,
6027 GSupplicantInterfaceCallback callback, void *user_data)
6029 struct interface_create_data *data;
6032 SUPPLICANT_DBG("ifname %s", ifname);
6034 if (!ifname || !parent_ifname)
6037 if (!system_available)
6040 data = dbus_malloc0(sizeof(*data));
6044 data->ifname = g_strdup(ifname);
6045 data->driver = g_strdup(driver);
6046 data->bridge = g_strdup(bridge);
6047 data->is_mesh_interface = true;
6048 data->parent_ifname = g_strdup(parent_ifname);
6049 data->callback = callback;
6050 data->user_data = user_data;
6052 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6053 SUPPLICANT_INTERFACE,
6055 interface_create_params,
6056 interface_create_result, data,
6061 struct interface_mesh_peer_data {
6064 GSupplicantInterface *interface;
6065 GSupplicantInterfaceCallback callback;
6069 static void interface_mesh_change_peer_params(DBusMessageIter *iter,
6072 struct interface_mesh_peer_data *data = user_data;
6076 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->peer_address);
6079 static void interface_mesh_change_peer_result(const char *error,
6080 DBusMessageIter *iter, void *user_data)
6082 struct interface_mesh_peer_data *data = user_data;
6085 SUPPLICANT_DBG("%s", data->method);
6089 SUPPLICANT_DBG("error %s", error);
6093 data->callback(err, data->interface, data->user_data);
6095 g_free(data->peer_address);
6096 g_free(data->method);
6100 int g_supplicant_interface_mesh_peer_change_status(
6101 GSupplicantInterface *interface,
6102 GSupplicantInterfaceCallback callback, const char *peer_address,
6103 const char *method, void *user_data)
6105 struct interface_mesh_peer_data *data;
6111 data = dbus_malloc0(sizeof(*data));
6115 data->peer_address = g_strdup(peer_address);
6116 data->method = g_strdup(method);
6117 data->interface = interface;
6118 data->callback = callback;
6119 data->user_data = user_data;
6121 ret = supplicant_dbus_method_call(interface->path,
6122 SUPPLICANT_INTERFACE ".Interface.Mesh",
6123 method, interface_mesh_change_peer_params,
6124 interface_mesh_change_peer_result, data, NULL);
6126 g_free(data->peer_address);
6127 g_free(data->method);
6135 int g_supplicant_interface_create(const char *ifname, const char *driver,
6138 unsigned int mac_policy,
6139 unsigned int preassoc_mac_policy,
6140 unsigned int random_mac_lifetime,
6141 #endif /* TIZEN_EXT */
6142 GSupplicantInterfaceCallback callback,
6145 struct interface_create_data *data;
6148 SUPPLICANT_DBG("ifname %s", ifname);
6153 if (!system_available)
6156 data = dbus_malloc0(sizeof(*data));
6160 data->ifname = g_strdup(ifname);
6161 data->driver = g_strdup(driver);
6162 data->bridge = g_strdup(bridge);
6163 data->callback = callback;
6165 data->mac_addr = mac_policy;
6166 data->preassoc_mac_addr = preassoc_mac_policy;
6167 data->random_mac_lifetime = random_mac_lifetime;
6168 #endif /* TIZEN_EXT */
6169 data->user_data = user_data;
6171 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6172 SUPPLICANT_INTERFACE,
6174 interface_get_params,
6175 interface_get_result, data,
6178 interface_create_data_free(data);
6183 static void interface_remove_result(const char *error,
6184 DBusMessageIter *iter, void *user_data)
6186 struct interface_data *data = user_data;
6191 SUPPLICANT_DBG("error: %s", error);
6195 if (!system_available) {
6201 * The gsupplicant interface is already freed by the InterfaceRemoved
6202 * signal callback. Simply invoke the interface_data callback.
6210 data->callback(err, NULL, data->user_data);
6216 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
6218 struct interface_data *data = user_data;
6220 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6221 &data->interface->path);
6224 int g_supplicant_interface_remove(GSupplicantInterface *interface,
6225 GSupplicantInterfaceCallback callback,
6228 struct interface_data *data;
6234 if (!system_available)
6237 g_supplicant_interface_cancel(interface);
6239 data = dbus_malloc0(sizeof(*data));
6243 data->interface = interface;
6244 data->path = g_strdup(interface->path);
6245 data->callback = callback;
6246 data->user_data = user_data;
6248 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6249 SUPPLICANT_INTERFACE,
6251 interface_remove_params,
6252 interface_remove_result, data,
6261 static void interface_scan_result(const char *error,
6262 DBusMessageIter *iter, void *user_data)
6264 struct interface_scan_data *data = user_data;
6268 SUPPLICANT_DBG("error %s", error);
6272 /* A non ready interface cannot send/receive anything */
6273 if (interface_exists(data->interface, data->path)) {
6274 if (!data->interface->ready)
6282 data->callback(err, data->interface, data->user_data);
6284 data->interface->scan_callback = data->callback;
6285 data->interface->scan_data = data->user_data;
6288 if (data->scan_params)
6289 g_supplicant_free_scan_params(data->scan_params);
6294 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
6296 DBusMessageIter data;
6297 unsigned int width = 0; /* Not used by wpa_supplicant atm */
6299 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
6301 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
6302 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
6304 dbus_message_iter_close_container(iter, &data);
6307 static void add_scan_frequencies(DBusMessageIter *iter,
6310 GSupplicantScanParams *scan_data = user_data;
6314 for (i = 0; i < scan_data->num_freqs; i++) {
6315 freq = scan_data->freqs[i];
6319 add_scan_frequency(iter, freq);
6323 static void append_ssid(DBusMessageIter *iter,
6324 const void *ssid, unsigned int len)
6326 DBusMessageIter array;
6328 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
6329 DBUS_TYPE_BYTE_AS_STRING, &array);
6331 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
6333 dbus_message_iter_close_container(iter, &array);
6336 static void append_ssids(DBusMessageIter *iter, void *user_data)
6338 GSupplicantScanParams *scan_data = user_data;
6341 for (list = scan_data->ssids; list; list = list->next) {
6342 struct scan_ssid *scan_ssid = list->data;
6344 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
6348 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
6349 supplicant_dbus_array_function function,
6352 GSupplicantScanParams *scan_params = user_data;
6353 DBusMessageIter entry, value, array;
6354 const char *key = "Channels";
6356 if (scan_params->freqs && scan_params->freqs[0] != 0) {
6357 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
6360 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
6362 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
6363 DBUS_TYPE_ARRAY_AS_STRING
6364 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6365 DBUS_TYPE_UINT32_AS_STRING
6366 DBUS_TYPE_UINT32_AS_STRING
6367 DBUS_STRUCT_END_CHAR_AS_STRING,
6370 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
6371 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6372 DBUS_TYPE_UINT32_AS_STRING
6373 DBUS_TYPE_UINT32_AS_STRING
6374 DBUS_STRUCT_END_CHAR_AS_STRING,
6378 function(&array, user_data);
6380 dbus_message_iter_close_container(&value, &array);
6381 dbus_message_iter_close_container(&entry, &value);
6382 dbus_message_iter_close_container(dict, &entry);
6386 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
6388 DBusMessageIter dict;
6389 const char *type = "passive";
6390 struct interface_scan_data *data = user_data;
6392 supplicant_dbus_dict_open(iter, &dict);
6394 if (data && data->scan_params) {
6397 supplicant_dbus_dict_append_basic(&dict, "Type",
6398 DBUS_TYPE_STRING, &type);
6400 #if defined TIZEN_EXT
6401 SUPPLICANT_DBG("[specific_scan] num_ssids %d",
6402 data->scan_params->num_ssids);
6405 if (data->scan_params->ssids) {
6406 supplicant_dbus_dict_append_array(&dict, "SSIDs",
6411 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
6414 supplicant_dbus_dict_append_basic(&dict, "Type",
6415 DBUS_TYPE_STRING, &type);
6417 supplicant_dbus_dict_close(iter, &dict);
6420 static int interface_ready_to_scan(GSupplicantInterface *interface)
6425 if (!system_available)
6428 if (interface->scanning)
6431 switch (interface->state) {
6432 case G_SUPPLICANT_STATE_AUTHENTICATING:
6433 case G_SUPPLICANT_STATE_ASSOCIATING:
6434 case G_SUPPLICANT_STATE_ASSOCIATED:
6435 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
6436 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
6438 #if defined TIZEN_EXT
6439 case G_SUPPLICANT_STATE_DISABLED:
6441 case G_SUPPLICANT_STATE_UNKNOWN:
6443 case G_SUPPLICANT_STATE_UNKNOWN:
6444 case G_SUPPLICANT_STATE_DISABLED:
6446 case G_SUPPLICANT_STATE_DISCONNECTED:
6447 case G_SUPPLICANT_STATE_INACTIVE:
6448 case G_SUPPLICANT_STATE_SCANNING:
6449 case G_SUPPLICANT_STATE_COMPLETED:
6456 #if defined TIZEN_EXT_WIFI_MESH
6457 static void interface_abort_scan_result(const char *error,
6458 DBusMessageIter *iter, void *user_data)
6460 struct interface_scan_data *data = user_data;
6464 SUPPLICANT_DBG("error %s", error);
6471 data->callback(err, data->interface, data->user_data);
6476 int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
6477 GSupplicantInterfaceCallback callback, void *user_data)
6479 struct interface_scan_data *data;
6482 if (!interface->scanning)
6485 data = dbus_malloc0(sizeof(*data));
6489 data->interface = interface;
6490 data->path = g_strdup(interface->path);
6491 data->callback = callback;
6492 data->user_data = user_data;
6494 ret = supplicant_dbus_method_call(interface->path,
6495 SUPPLICANT_INTERFACE ".Interface", "AbortScan", NULL,
6496 interface_abort_scan_result, data, interface);
6507 int g_supplicant_interface_scan(GSupplicantInterface *interface,
6508 GSupplicantScanParams *scan_data,
6509 GSupplicantInterfaceCallback callback,
6512 struct interface_scan_data *data;
6515 ret = interface_ready_to_scan(interface);
6519 data = dbus_malloc0(sizeof(*data));
6523 data->interface = interface;
6524 data->path = g_strdup(interface->path);
6525 #if defined TIZEN_EXT
6526 data->interface->scan_callback = data->callback = callback;
6527 data->interface->scan_data = data->user_data = user_data;
6529 data->callback = callback;
6530 data->user_data = user_data;
6532 data->scan_params = scan_data;
6534 interface->scan_callback = callback;
6535 interface->scan_data = user_data;
6537 ret = supplicant_dbus_method_call(interface->path,
6538 SUPPLICANT_INTERFACE ".Interface", "Scan",
6539 interface_scan_params, interface_scan_result, data,
6550 #if defined TIZEN_EXT
6551 static void interface_signalpoll_result(const char *error,
6552 DBusMessageIter *iter, void *user_data)
6554 struct interface_signalpoll_data *data = user_data;
6556 dbus_int32_t maxspeed = 0;
6557 dbus_int32_t strength = 0;
6558 dbus_int32_t snr = 0;
6559 DBusMessageIter sub_iter, dict;
6563 SUPPLICANT_DBG("error: %s", error);
6567 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
6569 SUPPLICANT_DBG("invalid reply");
6573 dbus_message_iter_recurse(iter, &sub_iter);
6574 dbus_message_iter_recurse(&sub_iter, &dict);
6576 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
6577 DBusMessageIter entry, value;
6580 dbus_message_iter_recurse(&dict, &entry);
6581 dbus_message_iter_get_basic(&entry, &key);
6582 dbus_message_iter_next(&entry);
6583 dbus_message_iter_recurse(&entry, &value);
6585 switch (dbus_message_iter_get_arg_type(&value)) {
6586 case DBUS_TYPE_INT32:
6587 if (g_strcmp0(key, "linkspeed") == 0) {
6588 dbus_message_iter_get_basic(&value, &maxspeed);
6589 SUPPLICANT_DBG("linkspeed = %d", maxspeed);
6591 } else if (g_strcmp0(key, "rssi") == 0) {
6592 dbus_message_iter_get_basic(&value, &strength);
6593 SUPPLICANT_DBG("Strength = %d", strength);
6595 } else if (g_strcmp0(key, "SNR") == 0) {
6596 dbus_message_iter_get_basic(&value, &snr);
6597 SUPPLICANT_DBG("SNR = %d", snr);
6601 dbus_message_iter_next(&dict);
6606 data->callback(err, maxspeed, strength, snr, data->user_data);
6612 int g_supplicant_interface_signalpoll(GSupplicantInterface *interface,
6613 GSupplicantMaxSpeedCallback callback,
6616 struct interface_signalpoll_data *data;
6622 if (!system_available)
6625 data = dbus_malloc0(sizeof(*data));
6629 data->interface = interface;
6630 data->path = g_strdup(interface->path);
6631 data->callback = callback;
6632 data->user_data = user_data;
6634 ret = supplicant_dbus_method_call(interface->path,
6635 SUPPLICANT_INTERFACE ".Interface", "SignalPoll",
6636 NULL, interface_signalpoll_result, data,
6648 static int parse_supplicant_error(DBusMessageIter *iter)
6650 int err = -ECONNABORTED;
6656 /* If the given passphrase is malformed wpa_s returns
6657 * "invalid message format" but this error should be interpreted as
6660 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
6661 dbus_message_iter_get_basic(iter, &key);
6662 if (strncmp(key, "psk", 3) == 0 ||
6663 strncmp(key, "wep_key", 7) == 0 ||
6664 strcmp(key, "invalid message format") == 0) {
6668 dbus_message_iter_next(iter);
6674 static void interface_select_network_result(const char *error,
6675 DBusMessageIter *iter, void *user_data)
6677 struct interface_connect_data *data = user_data;
6684 #if defined TIZEN_EXT
6685 SUPPLICANT_DBG("SelectNetwork errorFreq %s", error);
6687 SUPPLICANT_DBG("SelectNetwork error %s", error);
6689 err = parse_supplicant_error(iter);
6695 data->callback(err, data->interface, data->user_data);
6697 #if defined TIZEN_EXT
6698 g_free(data->ssid->ssid);
6699 g_free((char *)data->ssid->passphrase);
6700 g_free((char *)data->ssid->connector);
6701 g_free((char *)data->ssid->c_sign_key);
6702 g_free((char *)data->ssid->net_access_key);
6708 static void interface_select_network_params(DBusMessageIter *iter,
6711 struct interface_connect_data *data = user_data;
6712 GSupplicantInterface *interface = data->interface;
6713 #if defined TIZEN_EXT
6714 GSupplicantSSID *ssid = data->ssid;
6717 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6718 &interface->network_path);
6719 #if defined TIZEN_EXT
6720 if (!ssid->bssid_for_connect_len)
6721 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
6725 static void interface_add_network_result(const char *error,
6726 DBusMessageIter *iter, void *user_data)
6728 struct interface_connect_data *data = user_data;
6729 GSupplicantInterface *interface = data->interface;
6736 dbus_message_iter_get_basic(iter, &path);
6740 SUPPLICANT_DBG("PATH: %s", path);
6742 #if defined TIZEN_EXT
6743 if (interface->network_path)
6744 g_free(interface->network_path);
6746 interface->network_path = g_strdup(path);
6748 store_network_information(interface, data->ssid);
6750 #if defined TIZEN_EXT
6751 SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
6752 GSupplicantSSID *ssid = data->ssid;
6754 if (!ssid->bssid_for_connect_len)
6755 supplicant_dbus_method_call(data->interface->path,
6756 SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
6757 interface_select_network_params,
6758 interface_select_network_result, data,
6761 supplicant_dbus_method_call(data->interface->path,
6762 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6763 interface_select_network_params,
6764 interface_select_network_result, data,
6767 supplicant_dbus_method_call(data->interface->path,
6768 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6769 interface_select_network_params,
6770 interface_select_network_result, data,
6777 SUPPLICANT_DBG("AddNetwork error %s", error);
6779 if (interface_exists(data->interface, data->interface->path)) {
6780 err = parse_supplicant_error(iter);
6782 data->callback(err, data->interface, data->user_data);
6784 g_free(interface->network_path);
6785 interface->network_path = NULL;
6789 #if defined TIZEN_EXT
6790 g_free(data->ssid->ssid);
6791 g_free((char *)data->ssid->passphrase);
6792 g_free((char *)data->ssid->connector);
6793 g_free((char *)data->ssid->c_sign_key);
6794 g_free((char *)data->ssid->net_access_key);
6800 static void add_network_security_none(DBusMessageIter *dict)
6802 const char *auth_alg = "OPEN";
6804 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6805 DBUS_TYPE_STRING, &auth_alg);
6808 static void add_network_security_wep(DBusMessageIter *dict,
6809 GSupplicantSSID *ssid)
6811 const char *auth_alg = "OPEN SHARED";
6812 dbus_uint32_t key_index = 0;
6814 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6815 DBUS_TYPE_STRING, &auth_alg);
6817 if (ssid->passphrase) {
6818 int size = strlen(ssid->passphrase);
6819 if (size == 10 || size == 26) {
6820 unsigned char *key = g_try_malloc(13);
6824 memset(tmp, 0, sizeof(tmp));
6828 for (i = 0; i < size / 2; i++) {
6829 memcpy(tmp, ssid->passphrase + (i * 2), 2);
6830 key[i] = (unsigned char) strtol(tmp, NULL, 16);
6833 supplicant_dbus_dict_append_fixed_array(dict,
6838 } else if (size == 5 || size == 13) {
6839 unsigned char *key = g_try_malloc(13);
6845 for (i = 0; i < size; i++)
6846 key[i] = (unsigned char) ssid->passphrase[i];
6848 supplicant_dbus_dict_append_fixed_array(dict,
6854 supplicant_dbus_dict_append_basic(dict,
6859 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
6860 DBUS_TYPE_UINT32, &key_index);
6864 static dbus_bool_t is_psk_raw_key(const char *psk)
6868 /* A raw key is always 64 bytes length... */
6869 if (strlen(psk) != 64)
6872 /* ... and its content is in hex representation */
6873 for (i = 0; i < 64; i++)
6874 if (!isxdigit((unsigned char) psk[i]))
6880 static unsigned char hexchar2bin(char c)
6882 if ((c >= '0') && (c <= '9'))
6884 else if ((c >= 'A') && (c <= 'F'))
6885 return c - 'A' + 10;
6886 else if ((c >= 'a') && (c <= 'f'))
6887 return c - 'a' + 10;
6892 static void hexstring2bin(const char *string, unsigned char *data,
6897 for (i = 0; i < data_len; i++)
6898 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
6899 hexchar2bin(string[i * 2 + 1]) << 0);
6902 static void add_network_security_psk(DBusMessageIter *dict,
6903 GSupplicantSSID *ssid)
6905 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
6906 const char *key = "psk";
6908 if (is_psk_raw_key(ssid->passphrase)) {
6909 unsigned char data[32];
6910 unsigned char *datap = data;
6912 /* The above pointer alias is required by D-Bus because
6913 * with D-Bus and GCC, non-heap-allocated arrays cannot
6914 * be passed directly by their base pointer. */
6916 hexstring2bin(ssid->passphrase, datap, sizeof(data));
6918 supplicant_dbus_dict_append_fixed_array(dict,
6919 key, DBUS_TYPE_BYTE,
6920 &datap, sizeof(data));
6922 supplicant_dbus_dict_append_basic(dict,
6923 key, DBUS_TYPE_STRING,
6928 static void add_network_security_tls(DBusMessageIter *dict,
6929 GSupplicantSSID *ssid)
6932 * For TLS, we at least need:
6933 * The client certificate
6934 * The client private key file
6935 * The client private key file password
6937 * The Authority certificate is optional.
6939 if (!ssid->client_cert_path)
6942 if (!ssid->private_key_path)
6945 if (!ssid->private_key_passphrase)
6948 if (ssid->ca_cert_path)
6949 supplicant_dbus_dict_append_basic(dict, "ca_cert",
6950 DBUS_TYPE_STRING, &ssid->ca_cert_path);
6952 supplicant_dbus_dict_append_basic(dict, "private_key",
6954 &ssid->private_key_path);
6955 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
6957 &ssid->private_key_passphrase);
6958 supplicant_dbus_dict_append_basic(dict, "client_cert",
6960 &ssid->client_cert_path);
6963 static void add_network_security_peap(DBusMessageIter *dict,
6964 GSupplicantSSID *ssid)
6969 * For PEAP/TTLS, we at least need
6970 * The authority certificate
6971 * The 2nd phase authentication method
6972 * The 2nd phase passphrase
6974 * The Client certificate is optional although strongly recommended
6975 * When setting it, we need in addition
6976 * The Client private key file
6977 * The Client private key file password
6979 if (!ssid->passphrase)
6982 if (!ssid->phase2_auth)
6985 if (ssid->client_cert_path) {
6986 if (!ssid->private_key_path)
6989 #if !defined TIZEN_EXT
6990 if (!ssid->private_key_passphrase)
6994 supplicant_dbus_dict_append_basic(dict, "client_cert",
6996 &ssid->client_cert_path);
6998 supplicant_dbus_dict_append_basic(dict, "private_key",
7000 &ssid->private_key_path);
7002 #if !defined TIZEN_EXT
7003 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
7005 &ssid->private_key_passphrase);
7010 if(g_strcmp0(ssid->phase2_auth, "GTC") == 0 && g_strcmp0(ssid->eap, "ttls") == 0)
7011 phase2_auth = g_strdup_printf("autheap=%s", ssid->phase2_auth);
7012 else if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
7013 phase2_auth = g_strdup_printf("autheap=%s",
7014 ssid->phase2_auth + strlen("EAP-"));
7016 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
7018 supplicant_dbus_dict_append_basic(dict, "password",
7022 if (ssid->ca_cert_path)
7023 supplicant_dbus_dict_append_basic(dict, "ca_cert",
7025 &ssid->ca_cert_path);
7027 supplicant_dbus_dict_append_basic(dict, "phase2",
7031 g_free(phase2_auth);
7034 #if defined TIZEN_EXT
7035 static void add_network_security_aka_sim(DBusMessageIter *dict,
7036 GSupplicantSSID *ssid)
7038 if (!ssid->passphrase)
7041 supplicant_dbus_dict_append_basic(dict, "password",
7046 static void add_network_security_fast(DBusMessageIter *dict,
7047 GSupplicantSSID *ssid)
7050 * For FAST, we at least need:
7052 * phase1 (provisiong information)
7056 /* Allow provisioing both authenticated and unauthenticated */
7057 const char *phase1 = "fast_provisioning=2";
7058 supplicant_dbus_dict_append_basic(dict, "phase1",
7062 SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
7064 supplicant_dbus_dict_append_basic(dict, "pac_file",
7068 supplicant_dbus_dict_append_basic(dict, "password",
7074 static void add_network_security_eap(DBusMessageIter *dict,
7075 GSupplicantSSID *ssid)
7079 #if defined TIZEN_EXT
7082 if (!ssid->eap || !ssid->identity)
7086 if (g_strcmp0(ssid->eap, "tls") == 0) {
7087 add_network_security_tls(dict, ssid);
7088 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
7089 g_strcmp0(ssid->eap, "ttls") == 0) {
7090 #if defined TIZEN_EXT
7091 if (!ssid->identity)
7094 add_network_security_peap(dict, ssid);
7096 #if defined TIZEN_EXT
7097 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
7098 g_strcmp0(ssid->eap, "aka") == 0 ||
7099 g_strcmp0(ssid->eap, "aka'") == 0) {
7100 add_network_security_aka_sim(dict, ssid);
7101 } else if (g_strcmp0(ssid->eap, "pwd") == 0) {
7102 if(!ssid->passphrase)
7104 supplicant_dbus_dict_append_basic(dict, "password",
7107 } else if (g_strcmp0(ssid->eap, "fast") == 0){
7108 if (!ssid->identity || !ssid->passphrase)
7111 add_network_security_fast(dict, ssid);
7116 eap_value = g_ascii_strup(ssid->eap, -1);
7118 supplicant_dbus_dict_append_basic(dict, "eap",
7121 #if defined TIZEN_EXT
7122 if (ssid->identity != NULL)
7123 supplicant_dbus_dict_append_basic(dict, "identity",
7127 supplicant_dbus_dict_append_basic(dict, "identity",
7131 if(ssid->anonymous_identity)
7132 supplicant_dbus_dict_append_basic(dict, "anonymous_identity",
7134 &ssid->anonymous_identity);
7136 if(ssid->subject_match)
7137 supplicant_dbus_dict_append_basic(dict, "subject_match",
7139 &ssid->subject_match);
7141 if(ssid->altsubject_match)
7142 supplicant_dbus_dict_append_basic(dict, "altsubject_match",
7144 &ssid->altsubject_match);
7146 if(ssid->domain_suffix_match)
7147 supplicant_dbus_dict_append_basic(dict, "domain_suffix_match",
7149 &ssid->domain_suffix_match);
7151 if(ssid->domain_match)
7152 supplicant_dbus_dict_append_basic(dict, "domain_match",
7154 &ssid->domain_match);
7159 static void add_network_security_ciphers(DBusMessageIter *dict,
7160 GSupplicantSSID *ssid)
7162 unsigned int p_cipher, g_cipher, i;
7163 char *pairwise, *group;
7164 char *pair_ciphers[4];
7165 char *group_ciphers[5];
7167 p_cipher = ssid->pairwise_cipher;
7168 g_cipher = ssid->group_cipher;
7170 if (p_cipher == 0 && g_cipher == 0)
7175 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
7176 pair_ciphers[i++] = "CCMP";
7178 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
7179 pair_ciphers[i++] = "TKIP";
7181 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
7182 pair_ciphers[i++] = "NONE";
7184 pair_ciphers[i] = NULL;
7188 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
7189 group_ciphers[i++] = "CCMP";
7191 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
7192 group_ciphers[i++] = "TKIP";
7194 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
7195 group_ciphers[i++] = "WEP104";
7197 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
7198 group_ciphers[i++] = "WEP40";
7200 group_ciphers[i] = NULL;
7202 pairwise = g_strjoinv(" ", pair_ciphers);
7203 group = g_strjoinv(" ", group_ciphers);
7205 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
7207 supplicant_dbus_dict_append_basic(dict, "pairwise",
7210 supplicant_dbus_dict_append_basic(dict, "group",
7218 static void add_network_security_proto(DBusMessageIter *dict,
7219 GSupplicantSSID *ssid)
7221 unsigned int protocol, i;
7225 protocol = ssid->protocol;
7232 if (protocol & G_SUPPLICANT_PROTO_RSN)
7233 protos[i++] = "RSN";
7235 if (protocol & G_SUPPLICANT_PROTO_WPA)
7236 protos[i++] = "WPA";
7240 proto = g_strjoinv(" ", protos);
7242 SUPPLICANT_DBG("proto %s", proto);
7244 supplicant_dbus_dict_append_basic(dict, "proto",
7251 #if defined TIZEN_EXT
7252 static void add_network_ieee80211w(DBusMessageIter *dict, GSupplicantSSID *ssid)
7254 if (ssid->security != G_SUPPLICANT_SECURITY_SAE
7255 && ssid->security != G_SUPPLICANT_SECURITY_OWE
7256 && ssid->security != G_SUPPLICANT_SECURITY_DPP)
7259 supplicant_dbus_dict_append_basic(dict, "ieee80211w", DBUS_TYPE_UINT32,
7263 static void add_network_security_connector(DBusMessageIter *dict, GSupplicantSSID *ssid)
7265 if (ssid->connector && strlen(ssid->connector) > 0) {
7266 const char *key = "dpp_connector";
7268 supplicant_dbus_dict_append_basic(dict,
7269 key, DBUS_TYPE_STRING,
7274 static size_t convert_hexstr_to_bin(const char *hex_str, unsigned char **bin)
7276 unsigned char *bin_res = NULL;
7277 unsigned int i, j, hex;
7280 if (!hex_str || strlen(hex_str) == 0)
7283 hex_str_len = strlen(hex_str);
7284 bin_res = g_try_malloc0(hex_str_len / 2);
7289 for (i = 0; i < hex_str_len; i+=2) {
7290 sscanf(hex_str + i, "%02x", &hex);
7295 return hex_str_len / 2;
7298 static void add_network_security_c_sign_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7300 if (ssid->c_sign_key && strlen(ssid->c_sign_key) > 0) {
7301 const char *key = "dpp_csign";
7302 unsigned char *bin_csign = NULL;
7303 size_t bin_csign_len = convert_hexstr_to_bin(ssid->c_sign_key, &bin_csign);
7304 if (bin_csign_len != 0)
7305 supplicant_dbus_dict_append_fixed_array(dict,
7306 key, DBUS_TYPE_BYTE,
7307 &bin_csign, bin_csign_len);
7312 static void add_network_security_net_access_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7314 if (ssid->net_access_key && strlen(ssid->net_access_key) > 0) {
7315 const char *key = "dpp_netaccesskey";
7316 unsigned char *bin_netaccesskey = NULL;
7317 size_t bin_netaccesskey_len = convert_hexstr_to_bin(ssid->net_access_key, &bin_netaccesskey);
7318 if (bin_netaccesskey_len != 0)
7319 supplicant_dbus_dict_append_fixed_array(dict,
7320 key, DBUS_TYPE_BYTE,
7321 &bin_netaccesskey, bin_netaccesskey_len);
7322 g_free(bin_netaccesskey);
7328 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
7332 switch (ssid->security) {
7333 case G_SUPPLICANT_SECURITY_NONE:
7335 add_network_security_none(dict);
7336 add_network_security_ciphers(dict, ssid);
7338 case G_SUPPLICANT_SECURITY_UNKNOWN:
7339 case G_SUPPLICANT_SECURITY_WEP:
7341 add_network_security_wep(dict, ssid);
7342 add_network_security_ciphers(dict, ssid);
7344 case G_SUPPLICANT_SECURITY_PSK:
7345 #if defined TIZEN_EXT
7346 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
7347 key_mgmt = "FT-PSK WPA-PSK";
7349 key_mgmt = "WPA-PSK";
7351 key_mgmt = "WPA-PSK";
7353 add_network_security_psk(dict, ssid);
7354 add_network_security_ciphers(dict, ssid);
7355 add_network_security_proto(dict, ssid);
7357 case G_SUPPLICANT_SECURITY_IEEE8021X:
7358 key_mgmt = "WPA-EAP";
7359 add_network_security_eap(dict, ssid);
7360 add_network_security_ciphers(dict, ssid);
7361 add_network_security_proto(dict, ssid);
7363 #if defined TIZEN_EXT
7364 case G_SUPPLICANT_SECURITY_FT_PSK:
7365 key_mgmt = "FT-PSK";
7366 add_network_security_psk(dict, ssid);
7367 add_network_security_ciphers(dict, ssid);
7368 add_network_security_proto(dict, ssid);
7370 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
7371 key_mgmt = "FT-EAP";
7372 add_network_security_eap(dict, ssid);
7373 add_network_security_ciphers(dict, ssid);
7374 add_network_security_proto(dict, ssid);
7376 case G_SUPPLICANT_SECURITY_SAE:
7377 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_FT_SAE) {
7378 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
7379 key_mgmt = "FT-SAE SAE";
7381 key_mgmt = "FT-SAE";
7382 } else if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK)
7383 key_mgmt = "SAE WPA-PSK";
7386 add_network_security_psk(dict, ssid);
7388 case G_SUPPLICANT_SECURITY_OWE:
7390 add_network_security_ciphers(dict, ssid);
7391 add_network_security_proto(dict, ssid);
7393 case G_SUPPLICANT_SECURITY_DPP:
7395 add_network_security_connector(dict, ssid);
7396 add_network_security_c_sign_key(dict, ssid);
7397 add_network_security_net_access_key(dict, ssid);
7402 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
7403 DBUS_TYPE_STRING, &key_mgmt);
7406 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
7410 switch (ssid->mode) {
7411 case G_SUPPLICANT_MODE_UNKNOWN:
7412 case G_SUPPLICANT_MODE_INFRA:
7415 case G_SUPPLICANT_MODE_IBSS:
7418 case G_SUPPLICANT_MODE_MASTER:
7421 #if defined TIZEN_EXT_WIFI_MESH
7422 case G_SUPPLICANT_MODE_MESH:
7428 supplicant_dbus_dict_append_basic(dict, "mode",
7429 DBUS_TYPE_UINT32, &mode);
7432 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
7434 DBusMessageIter dict;
7435 struct interface_connect_data *data = user_data;
7436 GSupplicantSSID *ssid = data->ssid;
7437 #if defined TIZEN_EXT
7438 GSupplicantInterface *interface = data->interface;
7441 supplicant_dbus_dict_open(iter, &dict);
7443 if (ssid->scan_ssid)
7444 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
7445 DBUS_TYPE_UINT32, &ssid->scan_ssid);
7448 supplicant_dbus_dict_append_basic(&dict, "frequency",
7449 DBUS_TYPE_UINT32, &ssid->freq);
7452 supplicant_dbus_dict_append_basic(&dict, "bgscan",
7453 DBUS_TYPE_STRING, &ssid->bgscan);
7455 add_network_mode(&dict, ssid);
7457 add_network_security(&dict, ssid);
7459 #if defined TIZEN_EXT
7460 add_network_ieee80211w(&dict, ssid);
7463 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
7464 DBUS_TYPE_BYTE, &ssid->ssid,
7467 #if defined TIZEN_EXT
7468 bool owe_transition_mode = FALSE;
7469 if ((ssid->security == G_SUPPLICANT_SECURITY_OWE) && !(ssid->keymgmt & G_SUPPLICANT_KEYMGMT_OWE))
7470 owe_transition_mode = TRUE;
7472 if (ssid->bssid && !owe_transition_mode) {
7474 bssid = g_try_malloc0(18);
7475 if (bssid == NULL) {
7476 SUPPLICANT_DBG("memory allocation error");
7477 supplicant_dbus_dict_close(iter, &dict);
7481 if (ssid->bssid_for_connect_len) {
7482 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid_for_connect));
7483 memcpy(interface->add_network_bssid, ssid->bssid_for_connect, WIFI_BSSID_LEN_MAX);
7485 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid));
7486 memcpy(interface->add_network_bssid, ssid->bssid, WIFI_BSSID_LEN_MAX);
7489 SUPPLICANT_DBG("bssid [" MACSTR "]", MAC2STR(interface->add_network_bssid));
7491 supplicant_dbus_dict_append_basic(&dict, "bssid",
7492 DBUS_TYPE_STRING, &bssid);
7497 supplicant_dbus_dict_close(iter, &dict);
7500 static void interface_wps_start_result(const char *error,
7501 DBusMessageIter *iter, void *user_data)
7503 struct interface_connect_data *data = user_data;
7510 SUPPLICANT_DBG("error: %s", error);
7511 err = parse_supplicant_error(iter);
7515 data->callback(err, data->interface, data->user_data);
7522 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
7524 struct interface_connect_data *data = user_data;
7525 GSupplicantSSID *ssid = data->ssid;
7526 const char *role = "enrollee", *type;
7527 DBusMessageIter dict;
7531 supplicant_dbus_dict_open(iter, &dict);
7533 supplicant_dbus_dict_append_basic(&dict, "Role",
7534 DBUS_TYPE_STRING, &role);
7537 if (ssid->pin_wps) {
7539 supplicant_dbus_dict_append_basic(&dict, "Pin",
7540 DBUS_TYPE_STRING, &ssid->pin_wps);
7543 supplicant_dbus_dict_append_basic(&dict, "Type",
7544 DBUS_TYPE_STRING, &type);
7546 #if defined TIZEN_EXT
7548 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
7549 DBUS_TYPE_BYTE, &ssid->bssid, 6);
7552 supplicant_dbus_dict_close(iter, &dict);
7555 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
7557 struct interface_connect_data *data = user_data;
7562 SUPPLICANT_DBG("error: %s", error);
7569 #if defined TIZEN_EXT
7570 GSupplicantSSID *ssid = data->ssid;
7571 if (ssid->pin_wps != NULL) {
7572 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
7573 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
7580 supplicant_dbus_method_call(data->interface->path,
7581 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
7582 interface_add_wps_params,
7583 interface_wps_start_result, data, NULL);
7586 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
7588 dbus_bool_t credentials = TRUE;
7592 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
7596 #if defined TIZEN_EXT
7597 #define NETCONFIG_SERVICE "net.netconfig"
7598 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
7599 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
7601 struct dec_method_call_data {
7602 struct interface_connect_data *data;
7603 DBusPendingCall *pending_call;
7606 static struct dec_method_call_data decrypt_request_data;
7608 static void crypt_method_call_cancel(void)
7610 if (decrypt_request_data.pending_call) {
7611 dbus_pending_call_cancel(decrypt_request_data.pending_call);
7612 dbus_pending_call_unref(decrypt_request_data.pending_call);
7613 decrypt_request_data.pending_call = NULL;
7616 g_free(decrypt_request_data.data->path);
7617 g_free(decrypt_request_data.data->ssid);
7618 dbus_free(decrypt_request_data.data);
7619 decrypt_request_data.data = NULL;
7622 static void decryption_request_reply(DBusPendingCall *call,
7627 DBusMessageIter args;
7630 struct interface_connect_data *data = user_data;
7634 reply = dbus_pending_call_steal_reply(call);
7636 dbus_error_init(&error);
7637 if (dbus_set_error_from_message(&error, reply)) {
7638 SUPPLICANT_DBG("decryption_request_reply() %s %s", error.name, error.message);
7639 dbus_error_free(&error);
7644 if (!g_str_has_prefix(data->interface->path, "/")) {
7645 SUPPLICANT_DBG("Invalid path %s", data->interface->path);
7650 if (dbus_message_iter_init(reply, &args) == FALSE) {
7651 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7656 dbus_message_iter_get_basic(&args, &out_data);
7657 data->ssid->passphrase = g_strdup((const gchar *)out_data);
7659 ret = supplicant_dbus_method_call(data->interface->path,
7660 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7661 interface_add_network_params,
7662 interface_add_network_result, data,
7667 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7668 callback_assoc_failed(decrypt_request_data.data->user_data);
7670 g_free(data->ssid->ssid);
7671 g_free((char *)data->ssid->passphrase);
7672 g_free((char *)data->ssid->connector);
7673 g_free((char *)data->ssid->c_sign_key);
7674 g_free((char *)data->ssid->net_access_key);
7679 dbus_message_unref(reply);
7680 dbus_pending_call_unref(call);
7682 decrypt_request_data.pending_call = NULL;
7683 decrypt_request_data.data = NULL;
7686 static int send_decryption_request(const char *passphrase,
7687 struct interface_connect_data *data)
7689 DBusMessage *msg = NULL;
7690 DBusPendingCall *call;
7692 SUPPLICANT_DBG("Decryption request");
7695 SUPPLICANT_DBG("Invalid parameter");
7702 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7703 NETCONFIG_WIFI_INTERFACE, "DecryptPassphrase");
7707 #if defined TIZEN_EXT
7708 if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7709 DBUS_TYPE_INVALID)) {
7710 SUPPLICANT_DBG("Could not fulfill decryption request");
7714 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7718 if (!dbus_connection_send_with_reply(connection, msg,
7719 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7720 dbus_message_unref(msg);
7725 dbus_message_unref(msg);
7729 decrypt_request_data.pending_call = call;
7730 decrypt_request_data.data = data;
7732 dbus_pending_call_set_notify(call, decryption_request_reply, data, NULL);
7733 dbus_message_unref(msg);
7735 SUPPLICANT_DBG("Decryption request succeeded");
7740 static void decrypt_conf_obj_reply(DBusPendingCall *call,
7745 DBusMessageIter iter, dict;
7748 struct interface_connect_data *data = user_data;
7750 reply = dbus_pending_call_steal_reply(call);
7752 dbus_error_init(&error);
7753 if (dbus_set_error_from_message(&error, reply)) {
7754 SUPPLICANT_DBG("decryption_conf_obj_reply() %s %s", error.name, error.message);
7755 dbus_error_free(&error);
7760 if (dbus_message_iter_init(reply, &iter) == FALSE) {
7761 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7766 dbus_message_iter_recurse(&iter, &dict);
7768 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
7769 DBusMessageIter entry, value;
7772 dbus_message_iter_recurse(&dict, &entry);
7773 dbus_message_iter_get_basic(&entry, &key);
7774 dbus_message_iter_next(&entry);
7775 dbus_message_iter_recurse(&entry, &value);
7776 if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
7777 if (g_strcmp0(key, "connector") == 0) {
7778 dbus_message_iter_get_basic(&value, &out_data);
7779 data->ssid->connector = g_strdup((const gchar *)out_data);
7780 SUPPLICANT_DBG("connector %s", data->ssid->connector);
7781 } else if (g_strcmp0(key, "c_sign_key") == 0) {
7782 dbus_message_iter_get_basic(&value, &out_data);
7783 data->ssid->c_sign_key = g_strdup((const gchar *)out_data);
7784 SUPPLICANT_DBG("c_sign_key %s", data->ssid->c_sign_key);
7785 } else if (g_strcmp0(key, "net_access_key") == 0) {
7786 dbus_message_iter_get_basic(&value, &out_data);
7787 data->ssid->net_access_key = g_strdup((const gchar *)out_data);
7788 SUPPLICANT_DBG("net_access_key %s", data->ssid->net_access_key);
7791 dbus_message_iter_next(&dict);
7794 ret = supplicant_dbus_method_call(data->interface->path,
7795 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7796 interface_add_network_params,
7797 interface_add_network_result, data,
7802 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7803 callback_assoc_failed(decrypt_request_data.data->user_data);
7805 g_free(data->ssid->ssid);
7806 g_free((char *)data->ssid->connector);
7807 g_free((char *)data->ssid->c_sign_key);
7808 g_free((char *)data->ssid->net_access_key);
7813 dbus_message_unref(reply);
7814 dbus_pending_call_unref(call);
7816 decrypt_request_data.pending_call = NULL;
7817 decrypt_request_data.data = NULL;
7820 static int send_decryption_conf_obj_request(GSupplicantSSID *ssid,
7821 struct interface_connect_data *data)
7823 DBusMessage *msg = NULL;
7824 DBusPendingCall *call;
7826 SUPPLICANT_DBG("Decryption configuration object request");
7829 SUPPLICANT_DBG("Invalid parameter");
7836 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7837 NETCONFIG_WIFI_INTERFACE, "DecryptConfObj");
7841 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->connector,
7843 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->c_sign_key,
7845 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->net_access_key,
7848 if (!dbus_connection_send_with_reply(connection, msg,
7849 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7850 dbus_message_unref(msg);
7855 dbus_message_unref(msg);
7859 decrypt_request_data.pending_call = call;
7860 decrypt_request_data.data = data;
7862 dbus_pending_call_set_notify(call, decrypt_conf_obj_reply, data, NULL);
7863 dbus_message_unref(msg);
7865 SUPPLICANT_DBG("Decrypt Conf Obj request succeeded");
7870 static bool is_valid_config_object(GSupplicantSSID *ssid)
7872 return ((ssid->connector &&
7873 g_strcmp0(ssid->connector, "") != 0) &&
7874 (ssid->c_sign_key &&
7875 g_strcmp0(ssid->c_sign_key, "") != 0) &&
7876 (ssid->net_access_key &&
7877 g_strcmp0(ssid->net_access_key, "") != 0));
7881 int g_supplicant_interface_connect(GSupplicantInterface *interface,
7882 GSupplicantSSID *ssid,
7883 GSupplicantInterfaceCallback callback,
7886 struct interface_connect_data *data;
7887 struct interface_data *intf_data;
7895 if (!system_available)
7898 /* TODO: Check if we're already connected and switch */
7900 data = dbus_malloc0(sizeof(*data));
7904 data->interface = interface;
7905 data->path = g_strdup(interface->path);
7906 data->callback = callback;
7908 data->user_data = user_data;
7910 if (ssid->use_wps) {
7911 g_free(interface->wps_cred.key);
7912 memset(&interface->wps_cred, 0,
7913 sizeof(struct _GSupplicantWpsCredentials));
7915 ret = supplicant_dbus_property_set(interface->path,
7916 SUPPLICANT_INTERFACE ".Interface.WPS",
7917 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
7918 wps_process_credentials, wps_start, data, interface);
7920 /* By the time there is a request for connect and the network
7921 * path is not NULL it means that connman has not removed the
7922 * previous network pointer. This can happen in the case AP
7923 * deauthenticated client and connman does not remove the
7924 * previously connected network pointer. This causes supplicant
7925 * to reallocate the memory for struct wpa_ssid again even if it
7926 * is the same SSID. This causes memory usage of wpa_supplicnat
7927 * to go high. The idea here is that if the previously connected
7928 * network is not removed at the time of next connection attempt
7929 * check if the network path is not NULL. In case it is non-NULL
7930 * first remove the network and then once removal is successful, add
7934 if (interface->network_path != NULL) {
7939 * If this add network is for the same network for
7940 * which wpa_supplicant already has a profile then do
7941 * not need to add another profile. Only if the
7942 * profile that needs to get added is different from
7943 * what is there in wpa_s delete the current one. A
7944 * network is identified by its SSID, security_type
7945 * and passphrase (private passphrase in case security
7948 if (compare_network_parameters(interface, ssid)) {
7952 intf_data = dbus_malloc0(sizeof(*intf_data));
7956 intf_data->interface = interface;
7957 intf_data->path = g_strdup(interface->path);
7958 intf_data->callback = callback;
7959 intf_data->ssid = ssid;
7960 intf_data->user_data = user_data;
7961 intf_data->network_remove_in_progress = TRUE;
7962 network_remove(intf_data);
7964 #if defined TIZEN_EXT
7965 if (ssid->passphrase &&
7966 g_strcmp0(ssid->passphrase, "") != 0 &&
7967 #if defined TIZEN_EXT_WIFI_MESH
7968 ssid->mode != G_SUPPLICANT_MODE_MESH &&
7971 ret = send_decryption_request(ssid->passphrase, data);
7973 SUPPLICANT_DBG("Decryption request failed %d", ret);
7974 } else if (is_valid_config_object(ssid)) {
7975 ret = send_decryption_conf_obj_request(ssid, data);
7977 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
7981 ret = supplicant_dbus_method_call(interface->path,
7982 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7983 interface_add_network_params,
7984 interface_add_network_result, data,
7995 return -EINPROGRESS;
7998 static void network_remove_result(const char *error,
7999 DBusMessageIter *iter, void *user_data)
8001 struct interface_data *data = user_data;
8002 struct interface_connect_data *connect_data;
8009 SUPPLICANT_DBG("error: %s", error);
8011 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
8013 result = -ECONNABORTED;
8016 g_free(data->interface->network_path);
8017 data->interface->network_path = NULL;
8019 remove_network_information(data->interface);
8021 if (data->network_remove_in_progress == TRUE) {
8022 data->network_remove_in_progress = FALSE;
8023 connect_data = dbus_malloc0(sizeof(*connect_data));
8027 connect_data->interface = data->interface;
8028 connect_data->path = g_strdup(data->path);
8029 connect_data->callback = data->callback;
8030 connect_data->ssid = data->ssid;
8031 connect_data->user_data = data->user_data;
8033 #if defined TIZEN_EXT
8035 if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
8036 && !data->ssid->eap) {
8037 ret = send_decryption_request(data->ssid->passphrase, connect_data);
8039 SUPPLICANT_DBG("Decryption request failed %d", ret);
8040 g_free(connect_data->ssid);
8041 g_free(connect_data->path);
8042 dbus_free(connect_data);
8044 } else if (is_valid_config_object(data->ssid)) {
8045 ret = send_decryption_conf_obj_request(data->ssid, connect_data);
8047 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
8048 g_free(connect_data->ssid);
8049 g_free(connect_data->path);
8050 dbus_free(connect_data);
8054 supplicant_dbus_method_call(data->interface->path,
8055 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
8056 interface_add_network_params,
8057 interface_add_network_result, connect_data,
8058 connect_data->interface);
8061 data->callback(result, data->interface, data->user_data);
8067 static void network_remove_params(DBusMessageIter *iter, void *user_data)
8069 struct interface_data *data = user_data;
8070 const char *path = data->interface->network_path;
8072 SUPPLICANT_DBG("path %s", path);
8074 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
8077 static int network_remove(struct interface_data *data)
8079 GSupplicantInterface *interface = data->interface;
8083 #if defined TIZEN_EXT
8084 GSupplicantInterface *intf = NULL;
8086 * Check if 'interface' is valid
8088 intf = g_hash_table_lookup(interface_table, interface->path);
8093 return supplicant_dbus_method_call(interface->path,
8094 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
8095 network_remove_params, network_remove_result, data,
8099 static void interface_disconnect_result(const char *error,
8100 DBusMessageIter *iter, void *user_data)
8102 struct interface_data *data = user_data;
8109 SUPPLICANT_DBG("error: %s", error);
8111 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
8113 result = -ECONNABORTED;
8116 /* If we are disconnecting from previous WPS successful
8117 * association. i.e.: it did not went through AddNetwork,
8118 * and interface->network_path was never set. */
8119 if (!data->interface->network_path) {
8121 data->callback(result, data->interface,
8129 if (result < 0 && data->callback) {
8130 data->callback(result, data->interface, data->user_data);
8131 data->callback = NULL;
8134 if (result != -ECONNABORTED) {
8135 if (network_remove(data) < 0) {
8145 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
8146 GSupplicantInterfaceCallback callback,
8149 struct interface_data *data;
8157 if (!system_available)
8159 #if defined TIZEN_EXT
8160 if (decrypt_request_data.pending_call &&
8161 decrypt_request_data.data &&
8162 decrypt_request_data.data->user_data == user_data) {
8164 callback_assoc_failed(decrypt_request_data.data->user_data);
8165 crypt_method_call_cancel();
8170 data = dbus_malloc0(sizeof(*data));
8174 data->interface = interface;
8175 data->path = g_strdup(interface->path);
8176 data->callback = callback;
8177 data->user_data = user_data;
8179 ret = supplicant_dbus_method_call(interface->path,
8180 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
8181 NULL, interface_disconnect_result, data,
8192 #if defined TIZEN_EXT
8193 void g_supplicant_interface_remove_network(GSupplicantInterface *interface,
8194 GSupplicantSSID *ssid)
8196 struct interface_data *data;
8204 if (interface->network_path == NULL)
8207 if (!interface->network_info.ssid)
8210 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
8213 if (interface->network_info.security != ssid->security)
8216 data = dbus_malloc0(sizeof(*data));
8220 data->interface = interface;
8221 data->path = g_strdup(interface->path);
8223 ret = supplicant_dbus_method_call(interface->path,
8224 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
8225 network_remove_params, network_remove_result, data,
8235 static void interface_p2p_find_result(const char *error,
8236 DBusMessageIter *iter, void *user_data)
8238 struct interface_scan_data *data = user_data;
8241 SUPPLICANT_DBG("error %s", error);
8246 if (interface_exists(data->interface, data->path)) {
8247 if (!data->interface->ready)
8250 data->interface->p2p_finding = true;
8254 data->callback(err, data->interface, data->user_data);
8260 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
8262 DBusMessageIter dict;
8264 supplicant_dbus_dict_open(iter, &dict);
8265 supplicant_dbus_dict_close(iter, &dict);
8268 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
8269 GSupplicantInterfaceCallback callback,
8272 struct interface_scan_data *data;
8275 if (!interface->p2p_support)
8278 ret = interface_ready_to_scan(interface);
8279 if (ret && ret != -EALREADY)
8282 data = dbus_malloc0(sizeof(*data));
8286 data->interface = interface;
8287 data->path = g_strdup(interface->path);
8288 data->callback = callback;
8289 data->user_data = user_data;
8291 ret = supplicant_dbus_method_call(interface->path,
8292 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
8293 interface_p2p_find_params, interface_p2p_find_result,
8303 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
8308 return interface->p2p_finding;
8311 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
8313 if (!interface->p2p_finding)
8318 interface->p2p_finding = false;
8320 return supplicant_dbus_method_call(interface->path,
8321 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
8322 NULL, NULL, NULL, NULL);
8325 static void interface_p2p_connect_result(const char *error,
8326 DBusMessageIter *iter, void *user_data)
8328 struct interface_connect_data *data = user_data;
8334 SUPPLICANT_DBG("error: %s", error);
8335 err = parse_supplicant_error(iter);
8339 data->callback(err, data->interface, data->user_data);
8342 g_free(data->peer->wps_pin);
8343 g_free(data->peer->path);
8348 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
8350 struct interface_connect_data *data = user_data;
8351 const char *wps = "pbc";
8352 DBusMessageIter dict;
8357 supplicant_dbus_dict_open(iter, &dict);
8359 if (data->peer->master)
8362 if (data->peer->wps_pin)
8365 supplicant_dbus_dict_append_basic(&dict, "peer",
8366 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
8367 supplicant_dbus_dict_append_basic(&dict, "wps_method",
8368 DBUS_TYPE_STRING, &wps);
8369 if (data->peer->wps_pin) {
8370 supplicant_dbus_dict_append_basic(&dict, "pin",
8371 DBUS_TYPE_STRING, &data->peer->wps_pin);
8374 supplicant_dbus_dict_append_basic(&dict, "go_intent",
8375 DBUS_TYPE_INT32, &go_intent);
8377 supplicant_dbus_dict_close(iter, &dict);
8380 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
8381 GSupplicantPeerParams *peer_params,
8382 GSupplicantInterfaceCallback callback,
8385 struct interface_connect_data *data;
8390 if (!interface->p2p_support)
8393 data = dbus_malloc0(sizeof(*data));
8397 data->interface = interface;
8398 data->path = g_strdup(interface->path);
8399 data->peer = peer_params;
8400 data->callback = callback;
8401 data->user_data = user_data;
8403 ret = supplicant_dbus_method_call(interface->path,
8404 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
8405 interface_p2p_connect_params, interface_p2p_connect_result,
8413 return -EINPROGRESS;
8416 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
8417 GSupplicantPeerParams *peer_params)
8419 GSupplicantPeer *peer;
8425 if (!interface->p2p_support)
8428 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
8432 for (list = peer->groups; list; list = list->next, count++) {
8433 const char *group_obj_path = list->data;
8434 GSupplicantInterface *g_interface;
8435 GSupplicantGroup *group;
8437 group = g_hash_table_lookup(group_mapping, group_obj_path);
8438 if (!group || !group->interface)
8441 g_interface = group->interface;
8442 supplicant_dbus_method_call(g_interface->path,
8443 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8444 "Disconnect", NULL, NULL, NULL, g_interface);
8447 if (count == 0 && peer->current_group_iface) {
8448 supplicant_dbus_method_call(peer->current_group_iface->path,
8449 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8450 "Disconnect", NULL, NULL, NULL,
8451 peer->current_group_iface->path);
8454 peer->current_group_iface = NULL;
8456 return -EINPROGRESS;
8459 struct p2p_service_data {
8461 GSupplicantInterface *interface;
8462 GSupplicantP2PServiceParams *service;
8463 GSupplicantInterfaceCallback callback;
8467 static void interface_p2p_service_result(const char *error,
8468 DBusMessageIter *iter, void *user_data)
8470 struct p2p_service_data *data = user_data;
8473 SUPPLICANT_DBG("%s result - %s", data->registration ?
8474 "Registration" : "Deletion",
8475 error ? error : "Success");
8480 data->callback(result, data->interface, data->user_data);
8482 g_free(data->service->query);
8483 g_free(data->service->response);
8484 g_free(data->service->service);
8485 g_free(data->service->wfd_ies);
8486 g_free(data->service);
8490 static void interface_p2p_service_params(DBusMessageIter *iter,
8493 struct p2p_service_data *data = user_data;
8494 GSupplicantP2PServiceParams *service;
8495 DBusMessageIter dict;
8500 service = data->service;
8502 supplicant_dbus_dict_open(iter, &dict);
8504 if (service->query && service->response) {
8506 supplicant_dbus_dict_append_basic(&dict, "service_type",
8507 DBUS_TYPE_STRING, &type);
8508 supplicant_dbus_dict_append_fixed_array(&dict, "query",
8509 DBUS_TYPE_BYTE, &service->query,
8510 service->query_length);
8511 supplicant_dbus_dict_append_fixed_array(&dict, "response",
8512 DBUS_TYPE_BYTE, &service->response,
8513 service->response_length);
8514 } else if (service->version && service->service) {
8516 supplicant_dbus_dict_append_basic(&dict, "service_type",
8517 DBUS_TYPE_STRING, &type);
8518 supplicant_dbus_dict_append_basic(&dict, "version",
8519 DBUS_TYPE_INT32, &service->version);
8520 supplicant_dbus_dict_append_basic(&dict, "service",
8521 DBUS_TYPE_STRING, &service->service);
8524 supplicant_dbus_dict_close(iter, &dict);
8527 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
8528 GSupplicantInterfaceCallback callback,
8529 GSupplicantP2PServiceParams *p2p_service_params,
8532 struct p2p_service_data *data;
8537 if (!interface->p2p_support)
8540 data = dbus_malloc0(sizeof(*data));
8544 data->registration = true;
8545 data->interface = interface;
8546 data->service = p2p_service_params;
8547 data->callback = callback;
8548 data->user_data = user_data;
8550 ret = supplicant_dbus_method_call(interface->path,
8551 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
8552 interface_p2p_service_params, interface_p2p_service_result,
8559 return -EINPROGRESS;
8562 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
8563 GSupplicantP2PServiceParams *p2p_service_params)
8565 struct p2p_service_data *data;
8570 if (!interface->p2p_support)
8573 data = dbus_malloc0(sizeof(*data));
8577 data->interface = interface;
8578 data->service = p2p_service_params;
8580 ret = supplicant_dbus_method_call(interface->path,
8581 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
8582 interface_p2p_service_params, interface_p2p_service_result,
8589 return -EINPROGRESS;
8592 struct p2p_listen_data {
8597 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
8599 struct p2p_listen_data *params = user_data;
8600 DBusMessageIter dict;
8602 supplicant_dbus_dict_open(iter, &dict);
8604 supplicant_dbus_dict_append_basic(&dict, "period",
8605 DBUS_TYPE_INT32, ¶ms->period);
8606 supplicant_dbus_dict_append_basic(&dict, "interval",
8607 DBUS_TYPE_INT32, ¶ms->interval);
8608 supplicant_dbus_dict_close(iter, &dict);
8611 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
8612 int period, int interval)
8614 struct p2p_listen_data params;
8618 if (!interface->p2p_support)
8621 params.period = period;
8622 params.interval = interval;
8624 return supplicant_dbus_method_call(interface->path,
8625 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8626 "ExtendedListen", interface_p2p_listen_params,
8627 NULL, ¶ms, NULL);
8630 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
8632 struct p2p_service_data *data = user_data;
8633 GSupplicantP2PServiceParams *service = data->service;
8634 DBusMessageIter array;
8636 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
8638 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
8639 DBUS_TYPE_BYTE_AS_STRING, &array);
8641 if (service->wfd_ies && service->wfd_ies_length > 0) {
8642 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
8643 &service->wfd_ies, service->wfd_ies_length);
8646 dbus_message_iter_close_container(iter, &array);
8649 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
8650 GSupplicantInterfaceCallback callback,
8653 struct p2p_service_data *data;
8658 if (!system_available)
8661 data = dbus_malloc0(sizeof(*data));
8665 data->service = p2p_service_params;
8666 data->callback = callback;
8667 data->user_data = user_data;
8669 if (p2p_service_params->wfd_ies)
8670 data->registration = true;
8672 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
8673 SUPPLICANT_INTERFACE, "WFDIEs",
8674 DBUS_TYPE_ARRAY_AS_STRING
8675 DBUS_TYPE_BYTE_AS_STRING,
8677 interface_p2p_service_result,
8679 if (ret < 0 && ret != -EINPROGRESS) {
8684 return -EINPROGRESS;
8688 static const char *g_supplicant_rule0 = "type=signal,"
8689 "path=" DBUS_PATH_DBUS ","
8690 "sender=" DBUS_SERVICE_DBUS ","
8691 "interface=" DBUS_INTERFACE_DBUS ","
8692 "member=NameOwnerChanged,"
8693 "arg0=" SUPPLICANT_SERVICE;
8694 static const char *g_supplicant_rule1 = "type=signal,"
8695 "interface=" SUPPLICANT_INTERFACE;
8696 static const char *g_supplicant_rule2 = "type=signal,"
8697 "interface=" SUPPLICANT_INTERFACE ".Interface";
8698 static const char *g_supplicant_rule3 = "type=signal,"
8699 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
8700 static const char *g_supplicant_rule4 = "type=signal,"
8701 "interface=" SUPPLICANT_INTERFACE ".BSS";
8702 static const char *g_supplicant_rule5 = "type=signal,"
8703 "interface=" SUPPLICANT_INTERFACE ".Network";
8704 #if !defined TIZEN_EXT
8705 static const char *g_supplicant_rule6 = "type=signal,"
8706 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
8707 static const char *g_supplicant_rule7 = "type=signal,"
8708 "interface=" SUPPLICANT_INTERFACE ".Peer";
8709 static const char *g_supplicant_rule8 = "type=signal,"
8710 "interface=" SUPPLICANT_INTERFACE ".Group";
8712 #if defined TIZEN_EXT_WIFI_MESH
8713 static const char *g_supplicant_rule9 = "type=signal,"
8714 "interface=" SUPPLICANT_INTERFACE ".Interface.Mesh";
8717 static void invoke_introspect_method(void)
8719 DBusMessage *message;
8721 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
8723 DBUS_INTERFACE_INTROSPECTABLE,
8729 dbus_message_set_no_reply(message, TRUE);
8730 dbus_connection_send(connection, message, NULL);
8731 dbus_message_unref(message);
8734 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
8735 void g_supplicant_set_ins_settings(GSupplicantINSPreferredFreq preferred_freq_bssid,
8736 bool last_connected_bssid, bool assoc_reject, bool signal_bssid,
8737 unsigned int preferred_freq_bssid_score, unsigned int last_connected_bssid_score,
8738 unsigned int assoc_reject_score, int signal_level3_5ghz, int signal_level3_24ghz)
8740 ins_settings.preferred_freq_bssid = preferred_freq_bssid;
8741 ins_settings.last_connected_bssid = last_connected_bssid;
8742 ins_settings.assoc_reject = assoc_reject;
8743 ins_settings.signal_bssid = signal_bssid;
8744 ins_settings.preferred_freq_bssid_score = preferred_freq_bssid_score;
8745 ins_settings.last_connected_bssid_score = last_connected_bssid_score;
8746 ins_settings.assoc_reject_score = assoc_reject_score;
8747 ins_settings.signal_level3_5ghz = signal_level3_5ghz;
8748 ins_settings.signal_level3_24ghz = signal_level3_24ghz;
8750 SUPPLICANT_DBG("preferred_freq_bssid [%s]", preferred_freq_bssid ? "true" : "false");
8751 SUPPLICANT_DBG("preferred_freq_bssid_score [%d]", preferred_freq_bssid_score);
8752 SUPPLICANT_DBG("last_connected_bssid [%s]", last_connected_bssid ? "true" : "false");
8753 SUPPLICANT_DBG("last_connected_bssid_score [%d]", last_connected_bssid_score);
8754 SUPPLICANT_DBG("assoc_reject [%s]", assoc_reject ? "true" : "false");
8755 SUPPLICANT_DBG("assoc_reject_score [%d]", assoc_reject_score);
8756 SUPPLICANT_DBG("signal_bssid [%s]", signal_bssid ? "true" : "false");
8757 SUPPLICANT_DBG("signal_level3_5ghz [%d]", signal_level3_5ghz);
8758 SUPPLICANT_DBG("signal_level3_24ghz [%d]", signal_level3_24ghz);
8760 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
8762 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8763 void g_supplicant_register_eap_callback(g_supplicant_eap_callback cb)
8765 SUPPLICANT_DBG("g_supplicant_register_eap_callback %p", cb);
8767 if (!callbacks_pointer) {
8768 SUPPLICANT_DBG("callbacks_pointer is NULL");
8772 callbacks_pointer->eap = cb;
8775 void g_supplicant_unregister_eap_callback(void)
8777 SUPPLICANT_DBG("g_supplicant_unregister_eap_callback");
8779 if (!callbacks_pointer) {
8780 SUPPLICANT_DBG("callbacks_pointer is NULL");
8784 callbacks_pointer->eap = NULL;
8786 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8788 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8789 int g_supplicant_register(GSupplicantCallbacks *callbacks)
8790 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8791 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
8792 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8794 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8798 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
8800 dbus_connection_unref(connection);
8804 #if defined TIZEN_EXT
8805 simplified_log = connman_setting_get_bool("SimplifiedLog");
8807 callbacks_pointer = callbacks;
8810 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8811 NULL, remove_interface);
8813 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8815 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8817 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8819 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
8821 config_file_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8824 supplicant_dbus_setup(connection);
8826 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
8827 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
8828 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
8829 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
8830 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
8831 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
8832 #if defined TIZEN_EXT
8833 dbus_bus_add_match(connection,
8834 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
8835 "member=ChangeState", NULL);
8837 #if !defined TIZEN_EXT
8838 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
8839 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
8840 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
8842 #if defined TIZEN_EXT_WIFI_MESH
8843 dbus_bus_add_match(connection, g_supplicant_rule9, NULL);
8845 dbus_connection_flush(connection);
8847 if (dbus_bus_name_has_owner(connection,
8848 SUPPLICANT_SERVICE, NULL)) {
8849 system_available = TRUE;
8850 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
8851 SUPPLICANT_INTERFACE,
8852 service_property, NULL, NULL);
8854 invoke_introspect_method();
8856 SUPPLICANT_DBG("supplicant dbus setup completed");
8860 static void unregister_interface_remove_params(DBusMessageIter *iter,
8863 const char *path = user_data;
8865 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
8870 static void unregister_remove_interface(gpointer key, gpointer value,
8873 GSupplicantInterface *interface = value;
8875 supplicant_dbus_method_call(SUPPLICANT_PATH,
8876 SUPPLICANT_INTERFACE,
8878 unregister_interface_remove_params,
8879 NULL, interface->path, NULL);
8882 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
8887 #if defined TIZEN_EXT_WIFI_MESH
8888 dbus_bus_remove_match(connection, g_supplicant_rule9, NULL);
8890 #if !defined TIZEN_EXT
8891 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
8892 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
8893 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
8895 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
8896 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
8897 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
8898 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
8899 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
8900 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
8901 dbus_connection_flush(connection);
8903 dbus_connection_remove_filter(connection,
8904 g_supplicant_filter, NULL);
8907 if (config_file_table) {
8908 g_hash_table_destroy(config_file_table);
8909 config_file_table = NULL;
8913 g_hash_table_destroy(bss_mapping);
8918 g_hash_table_destroy(peer_mapping);
8919 peer_mapping = NULL;
8922 if (group_mapping) {
8923 g_hash_table_destroy(group_mapping);
8924 group_mapping = NULL;
8927 if (interface_table) {
8928 g_hash_table_foreach(interface_table,
8929 unregister_remove_interface, NULL);
8930 g_hash_table_destroy(interface_table);
8931 interface_table = NULL;
8934 if (system_available)
8935 callback_system_killed();
8938 dbus_connection_unref(connection);
8942 callbacks_pointer = NULL;
8947 struct supplicant_mac_policy {
8948 GSupplicantMacPolicyCallback callback;
8949 dbus_uint32_t policy;
8950 const void *user_data;
8953 static void mac_policy_result(const char *error,
8954 DBusMessageIter *iter, void *user_data)
8956 struct supplicant_mac_policy *data = user_data;
8963 SUPPLICANT_DBG("Mac policy setting failure %s", error);
8968 data->callback(result, data->policy,
8969 (void *) data->user_data);
8974 static void mac_policy_params(DBusMessageIter *iter, void *user_data)
8976 struct supplicant_mac_policy *data = user_data;
8978 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(data->policy));
8981 int g_supplicant_interface_set_mac_policy(GSupplicantInterface *interface,
8982 GSupplicantMacPolicyCallback callback,
8983 unsigned int policy,
8986 struct supplicant_mac_policy *data = NULL;
8989 if (!system_available)
8995 data = dbus_malloc0(sizeof(*data));
8999 data->callback = callback;
9000 data->policy = policy;
9001 data->user_data = user_data;
9003 ret = supplicant_dbus_property_set(interface->path,
9004 SUPPLICANT_INTERFACE ".Interface",
9005 "MacAddr", DBUS_TYPE_INT32_AS_STRING,
9006 mac_policy_params, mac_policy_result, data, NULL);
9008 SUPPLICANT_DBG("Unable to set MacAddr configuration");
9015 int g_supplicant_interface_set_preassoc_mac_policy(GSupplicantInterface *interface,
9016 GSupplicantMacPolicyCallback callback,
9017 unsigned int policy,
9020 struct supplicant_mac_policy *data;
9023 if (!system_available)
9029 data = dbus_malloc0(sizeof(*data));
9033 data->callback = callback;
9034 data->policy = policy;
9035 data->user_data = user_data;
9037 ret = supplicant_dbus_property_set(interface->path,
9038 SUPPLICANT_INTERFACE ".Interface",
9039 "PreassocMacAddr", DBUS_TYPE_INT32_AS_STRING,
9040 mac_policy_params, mac_policy_result, data, NULL);
9042 SUPPLICANT_DBG("Unable to set PreassocMacAddr configuration");
9049 struct supplicant_random_mac_lifetime {
9050 GSupplicantRandomMaclifetimeCallback callback;
9051 dbus_uint32_t lifetime;
9052 const void *user_data;
9055 static void random_mac_lifetime_result(const char *error,
9056 DBusMessageIter *iter, void *user_data)
9058 struct supplicant_random_mac_lifetime *data = user_data;
9065 SUPPLICANT_DBG("Random Mac lifetime setting failure %s", error);
9070 data->callback(result, data->lifetime,
9071 (void *) data->user_data);
9076 static void random_mac_lifetime_params(DBusMessageIter *iter, void *user_data)
9078 struct supplicant_random_mac_lifetime *data = user_data;
9080 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &(data->lifetime));
9083 int g_supplicant_interface_set_random_mac_lifetime(GSupplicantInterface *interface,
9084 GSupplicantRandomMaclifetimeCallback callback,
9085 unsigned int lifetime,
9088 struct supplicant_random_mac_lifetime *data;
9091 if (!system_available)
9097 data = dbus_malloc0(sizeof(*data));
9101 data->callback = callback;
9102 data->lifetime = lifetime;
9103 data->user_data = user_data;
9105 ret = supplicant_dbus_property_set(interface->path,
9106 SUPPLICANT_INTERFACE ".Interface",
9107 "RandAddrLifetime", DBUS_TYPE_UINT32_AS_STRING,
9108 random_mac_lifetime_params, random_mac_lifetime_result,
9111 SUPPLICANT_DBG("Unable to set RandAddrLifetime configuration");