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_INS
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;
311 dbus_bool_t psk_sha256;
313 unsigned int wps_capabilities;
314 #if defined TIZEN_EXT
318 dbus_bool_t owe_transition_mode;
319 unsigned int transition_mode_ssid_len;
320 unsigned char transition_mode_bssid[6];
321 unsigned char transition_mode_ssid[32];
322 dbus_bool_t pmf_required;
326 struct _GSupplicantNetwork {
327 GSupplicantInterface *interface;
331 unsigned char ssid[32];
332 unsigned int ssid_len;
334 dbus_uint16_t frequency;
335 struct g_supplicant_bss *best_bss;
336 GSupplicantMode mode;
337 GSupplicantSecurity security;
339 unsigned int wps_capabilities;
340 GHashTable *bss_table;
341 GHashTable *config_table;
342 #if defined TIZEN_EXT
347 unsigned int keymgmt;
349 unsigned char country_code[COUNTRY_CODE_LENGTH];
350 GSupplicantPhy_mode phy_mode;
351 dbus_bool_t owe_transition_mode;
353 unsigned int transition_mode_ssid_len;
354 unsigned char transition_mode_bssid[6];
355 unsigned char transition_mode_ssid[32];
356 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
357 GHashTable *assoc_reject_table;
361 struct _GSupplicantPeer {
362 GSupplicantInterface *interface;
364 unsigned char device_address[ETH_ALEN];
365 unsigned char iface_address[ETH_ALEN];
367 unsigned char *widi_ies;
370 unsigned int wps_capabilities;
372 const GSupplicantInterface *current_group_iface;
373 bool connection_requested;
376 struct _GSupplicantGroup {
377 GSupplicantInterface *interface;
378 GSupplicantInterface *orig_interface;
384 struct interface_data {
385 GSupplicantInterface *interface;
386 char *path; /* Interface path cannot be taken from interface (above) as
387 * it might have been freed already.
389 GSupplicantInterfaceCallback callback;
391 bool network_remove_in_progress;
392 GSupplicantSSID *ssid;
395 #if defined TIZEN_EXT
396 struct interface_signalpoll_data {
397 GSupplicantInterface *interface;
399 GSupplicantMaxSpeedCallback callback;
404 struct interface_create_data {
408 #if defined TIZEN_EXT
409 unsigned int mac_addr;
410 unsigned int preassoc_mac_addr;
411 unsigned int random_mac_lifetime;
412 #endif /* TIZEN_EXT */
413 #if defined TIZEN_EXT_WIFI_MESH
415 bool is_mesh_interface;
417 GSupplicantInterface *interface;
418 GSupplicantInterfaceCallback callback;
422 struct interface_connect_data {
423 GSupplicantInterface *interface;
425 GSupplicantInterfaceCallback callback;
428 GSupplicantSSID *ssid;
429 GSupplicantPeerParams *peer;
433 struct interface_scan_data {
434 GSupplicantInterface *interface;
436 GSupplicantInterfaceCallback callback;
437 GSupplicantScanParams *scan_params;
441 #if defined TIZEN_EXT
442 struct update_bssid_data {
443 GSupplicantNetwork *network;
444 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
445 GHashTable *assoc_reject_table;
449 struct assoc_reject_data {
451 GSList *reject_time_list;
454 struct assoc_count_data {
459 #if defined TIZEN_EXT_INS
460 static unsigned int last_connected_bss_timeout = 0;
462 static bool simplified_log = true;
465 static int network_remove(struct interface_data *data);
467 #if defined TIZEN_EXT_WIFI_MESH
468 struct _GSupplicantMeshPeer {
469 GSupplicantInterface *interface;
471 int disconnect_reason;
475 static inline void debug(const char *format, ...)
480 if (!callbacks_pointer || !callbacks_pointer->debug)
483 va_start(ap, format);
485 if (vsnprintf(str, sizeof(str), format, ap) > 0)
486 callbacks_pointer->debug(str);
491 #define SUPPLICANT_DBG(fmt, arg...) \
492 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
494 static GSupplicantMode string2mode(const char *mode)
497 return G_SUPPLICANT_MODE_UNKNOWN;
499 if (g_str_equal(mode, "infrastructure"))
500 return G_SUPPLICANT_MODE_INFRA;
501 else if (g_str_equal(mode, "ad-hoc"))
502 return G_SUPPLICANT_MODE_IBSS;
503 #if defined TIZEN_EXT_WIFI_MESH
504 else if (g_str_equal(mode, "mesh"))
505 return G_SUPPLICANT_MODE_MESH;
508 return G_SUPPLICANT_MODE_UNKNOWN;
511 static const char *mode2string(GSupplicantMode mode)
514 case G_SUPPLICANT_MODE_UNKNOWN:
516 case G_SUPPLICANT_MODE_INFRA:
518 case G_SUPPLICANT_MODE_IBSS:
520 case G_SUPPLICANT_MODE_MASTER:
522 #if defined TIZEN_EXT_WIFI_MESH
523 case G_SUPPLICANT_MODE_MESH:
531 static const char *security2string(GSupplicantSecurity security)
534 case G_SUPPLICANT_SECURITY_UNKNOWN:
536 case G_SUPPLICANT_SECURITY_NONE:
538 case G_SUPPLICANT_SECURITY_WEP:
540 case G_SUPPLICANT_SECURITY_PSK:
542 case G_SUPPLICANT_SECURITY_IEEE8021X:
544 #if defined TIZEN_EXT
545 case G_SUPPLICANT_SECURITY_PSK_SHA256:
547 case G_SUPPLICANT_SECURITY_FT_PSK:
549 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
550 return "ft_ieee8021x";
551 case G_SUPPLICANT_SECURITY_SAE:
553 case G_SUPPLICANT_SECURITY_OWE:
555 case G_SUPPLICANT_SECURITY_DPP:
563 static GSupplicantState string2state(const char *state)
566 return G_SUPPLICANT_STATE_UNKNOWN;
568 if (g_str_equal(state, "unknown"))
569 return G_SUPPLICANT_STATE_UNKNOWN;
570 else if (g_str_equal(state, "interface_disabled"))
571 return G_SUPPLICANT_STATE_DISABLED;
572 else if (g_str_equal(state, "disconnected"))
573 return G_SUPPLICANT_STATE_DISCONNECTED;
574 else if (g_str_equal(state, "inactive"))
575 return G_SUPPLICANT_STATE_INACTIVE;
576 else if (g_str_equal(state, "scanning"))
577 return G_SUPPLICANT_STATE_SCANNING;
578 else if (g_str_equal(state, "authenticating"))
579 return G_SUPPLICANT_STATE_AUTHENTICATING;
580 else if (g_str_equal(state, "associating"))
581 return G_SUPPLICANT_STATE_ASSOCIATING;
582 else if (g_str_equal(state, "associated"))
583 return G_SUPPLICANT_STATE_ASSOCIATED;
584 else if (g_str_equal(state, "group_handshake"))
585 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
586 else if (g_str_equal(state, "4way_handshake"))
587 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
588 else if (g_str_equal(state, "completed"))
589 return G_SUPPLICANT_STATE_COMPLETED;
591 return G_SUPPLICANT_STATE_UNKNOWN;
594 static bool compare_network_parameters(GSupplicantInterface *interface,
595 GSupplicantSSID *ssid)
597 #if defined TIZEN_EXT
598 if (!interface->network_info.ssid)
602 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
605 if (interface->network_info.security != ssid->security)
608 if (interface->network_info.passphrase &&
609 g_strcmp0(interface->network_info.passphrase,
610 ssid->passphrase) != 0) {
614 if (interface->network_info.private_passphrase &&
615 g_strcmp0(interface->network_info.private_passphrase,
616 ssid->private_key_passphrase) != 0) {
620 #if defined TIZEN_EXT
621 if (interface->network_info.connector &&
622 g_strcmp0(interface->network_info.connector,
623 ssid->connector) != 0) {
626 if (interface->network_info.c_sign_key &&
627 g_strcmp0(interface->network_info.c_sign_key,
628 ssid->c_sign_key) != 0) {
631 if (interface->network_info.net_access_key &&
632 g_strcmp0(interface->network_info.net_access_key,
633 ssid->net_access_key) != 0) {
640 static void remove_network_information(GSupplicantInterface * interface)
642 g_free(interface->network_info.ssid);
643 g_free(interface->network_info.passphrase);
644 g_free(interface->network_info.private_passphrase);
645 #if defined TIZEN_EXT
646 g_free(interface->network_info.connector);
647 g_free(interface->network_info.c_sign_key);
648 g_free(interface->network_info.net_access_key);
650 interface->network_info.ssid = NULL;
651 interface->network_info.passphrase = NULL;
652 interface->network_info.private_passphrase = NULL;
653 #if defined TIZEN_EXT
654 interface->network_info.connector = NULL;
655 interface->network_info.c_sign_key = NULL;
656 interface->network_info.net_access_key = NULL;
660 static int store_network_information(GSupplicantInterface * interface,
661 GSupplicantSSID *ssid)
663 interface->network_info.ssid = g_malloc(ssid->ssid_len + 1);
664 if (interface->network_info.ssid != NULL) {
665 memcpy(interface->network_info.ssid, ssid->ssid,
667 interface->network_info.ssid[ssid->ssid_len] = '\0';
672 interface->network_info.security = ssid->security;
674 if ((ssid->security == G_SUPPLICANT_SECURITY_WEP ||
675 ssid->security == G_SUPPLICANT_SECURITY_PSK ||
676 #if defined TIZEN_EXT
677 ssid->security == G_SUPPLICANT_SECURITY_SAE ||
678 ssid->security == G_SUPPLICANT_SECURITY_PSK_SHA256 ||
680 ssid->security == G_SUPPLICANT_SECURITY_NONE) &&
682 interface->network_info.passphrase = g_strdup(ssid->passphrase);
685 if (ssid->security == G_SUPPLICANT_SECURITY_IEEE8021X &&
686 ssid->private_key_passphrase) {
687 interface->network_info.private_passphrase =
688 g_strdup(ssid->private_key_passphrase);
694 static void callback_system_ready(void)
701 if (!callbacks_pointer)
704 if (!callbacks_pointer->system_ready)
707 callbacks_pointer->system_ready();
710 static void callback_system_killed(void)
712 system_ready = FALSE;
714 if (!callbacks_pointer)
717 if (!callbacks_pointer->system_killed)
720 callbacks_pointer->system_killed();
723 static void callback_interface_added(GSupplicantInterface *interface)
727 if (!callbacks_pointer)
730 if (!callbacks_pointer->interface_added)
733 callbacks_pointer->interface_added(interface);
736 static void callback_interface_state(GSupplicantInterface *interface)
738 if (!callbacks_pointer)
741 if (!callbacks_pointer->interface_state)
744 callbacks_pointer->interface_state(interface);
747 static void callback_interface_removed(GSupplicantInterface *interface)
749 if (!callbacks_pointer)
752 if (!callbacks_pointer->interface_removed)
755 callbacks_pointer->interface_removed(interface);
758 #if !defined TIZEN_EXT
759 static void callback_p2p_support(GSupplicantInterface *interface)
763 if (!interface->p2p_support)
766 if (callbacks_pointer && callbacks_pointer->p2p_support)
767 callbacks_pointer->p2p_support(interface);
771 #if defined TIZEN_EXT_WIFI_MESH
772 static void callback_mesh_support(GSupplicantInterface *interface)
776 if (!interface->mesh_support)
779 if (callbacks_pointer && callbacks_pointer->mesh_support)
780 callbacks_pointer->mesh_support(interface);
783 bool g_supplicant_interface_has_mesh(GSupplicantInterface *interface)
788 return interface->mesh_support;
792 static void callback_scan_started(GSupplicantInterface *interface)
794 if (!callbacks_pointer)
797 if (!callbacks_pointer->scan_started)
800 callbacks_pointer->scan_started(interface);
803 static void callback_ap_create_fail(GSupplicantInterface *interface)
805 if (!callbacks_pointer)
808 if (!callbacks_pointer->ap_create_fail)
811 callbacks_pointer->ap_create_fail(interface);
814 static void callback_scan_finished(GSupplicantInterface *interface)
816 if (!callbacks_pointer)
819 if (!callbacks_pointer->scan_finished)
822 callbacks_pointer->scan_finished(interface);
825 static void callback_network_added(GSupplicantNetwork *network)
827 if (!callbacks_pointer)
830 if (!callbacks_pointer->network_added)
833 callbacks_pointer->network_added(network);
836 static void callback_network_removed(GSupplicantNetwork *network)
838 if (!callbacks_pointer)
841 if (!callbacks_pointer->network_removed)
844 callbacks_pointer->network_removed(network);
847 #if defined TIZEN_EXT
848 static void callback_network_merged(GSupplicantNetwork *network)
850 if (!callbacks_pointer)
853 if (!callbacks_pointer->network_merged)
856 callbacks_pointer->network_merged(network);
859 static void callback_assoc_failed(void *user_data)
861 if (!callbacks_pointer)
864 if (!callbacks_pointer->assoc_failed)
867 callbacks_pointer->assoc_failed(user_data);
870 static void callback_scan_done(GSupplicantInterface *interface)
872 if (!callbacks_pointer)
875 if (!callbacks_pointer->scan_done)
878 callbacks_pointer->scan_done(interface);
882 static void callback_network_changed(GSupplicantNetwork *network,
883 const char *property)
885 if (!callbacks_pointer)
888 if (!callbacks_pointer->network_changed)
891 callbacks_pointer->network_changed(network, property);
894 static void callback_network_associated(GSupplicantNetwork *network)
896 if (!callbacks_pointer)
899 if (!callbacks_pointer->network_associated)
902 callbacks_pointer->network_associated(network);
905 static void callback_sta_authorized(GSupplicantInterface *interface,
908 if (!callbacks_pointer)
911 if (!callbacks_pointer->sta_authorized)
914 callbacks_pointer->sta_authorized(interface, addr);
917 static void callback_sta_deauthorized(GSupplicantInterface *interface,
920 if (!callbacks_pointer)
923 if (!callbacks_pointer->sta_deauthorized)
926 callbacks_pointer->sta_deauthorized(interface, addr);
929 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
930 static void callback_eap(GSupplicantInterface *interface, bool status)
932 if (!callbacks_pointer)
935 if (!callbacks_pointer->eap)
938 callbacks_pointer->eap(interface, status);
940 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
942 static void callback_peer_found(GSupplicantPeer *peer)
944 if (!callbacks_pointer)
947 if (!callbacks_pointer->peer_found)
950 callbacks_pointer->peer_found(peer);
953 static void callback_peer_lost(GSupplicantPeer *peer)
955 if (!callbacks_pointer)
958 if (!callbacks_pointer->peer_lost)
961 callbacks_pointer->peer_lost(peer);
964 static void callback_peer_changed(GSupplicantPeer *peer,
965 GSupplicantPeerState state)
967 if (!callbacks_pointer)
970 if (!callbacks_pointer->peer_changed)
973 callbacks_pointer->peer_changed(peer, state);
976 static void callback_peer_request(GSupplicantPeer *peer)
978 if (!callbacks_pointer)
981 if (!callbacks_pointer->peer_request)
984 peer->connection_requested = true;
986 callbacks_pointer->peer_request(peer);
989 static void callback_disconnect_reason_code(GSupplicantInterface *interface,
992 if (!callbacks_pointer)
995 if (!callbacks_pointer->disconnect_reasoncode)
998 if (reason_code != 0)
999 callbacks_pointer->disconnect_reasoncode(interface,
1003 static void callback_assoc_status_code(GSupplicantInterface *interface,
1006 if (!callbacks_pointer)
1009 if (!callbacks_pointer->assoc_status_code)
1012 callbacks_pointer->assoc_status_code(interface, status_code);
1016 static void remove_group(gpointer data)
1018 GSupplicantGroup *group = data;
1021 g_slist_free_full(group->members, g_free);
1023 g_free(group->path);
1027 static void remove_interface(gpointer data)
1029 GSupplicantInterface *interface = data;
1031 g_hash_table_destroy(interface->bss_mapping);
1032 g_hash_table_destroy(interface->network_table);
1033 g_hash_table_destroy(interface->peer_table);
1034 g_hash_table_destroy(interface->group_table);
1036 if (interface->scan_callback) {
1037 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
1038 interface, interface->scan_callback,
1039 interface->scanning);
1041 interface->scan_callback(-EIO, interface, interface->scan_data);
1042 interface->scan_callback = NULL;
1043 interface->scan_data = NULL;
1045 if (interface->scanning) {
1046 interface->scanning = FALSE;
1047 callback_scan_finished(interface);
1051 callback_interface_removed(interface);
1053 g_free(interface->wps_cred.key);
1054 g_free(interface->path);
1055 g_free(interface->network_path);
1056 #if defined TIZEN_EXT
1057 interface->network_path = NULL;
1059 g_free(interface->ifname);
1060 g_free(interface->driver);
1061 g_free(interface->bridge);
1062 remove_network_information(interface);
1066 static void remove_network(gpointer data)
1068 GSupplicantNetwork *network = data;
1070 g_hash_table_destroy(network->bss_table);
1072 callback_network_removed(network);
1074 g_hash_table_destroy(network->config_table);
1075 #if defined TIZEN_EXT
1076 g_hash_table_destroy(network->assoc_reject_table);
1079 g_free(network->path);
1080 g_free(network->group);
1081 g_free(network->name);
1082 #if defined TIZEN_EXT
1083 g_free(network->eap);
1084 g_free(network->identity);
1085 g_free(network->phase2);
1087 #if defined TIZEN_EXT
1088 g_slist_free_full(network->vsie_list, g_free);
1094 static void remove_bss(gpointer data)
1096 struct g_supplicant_bss *bss = data;
1098 supplicant_dbus_property_call_cancel_all(bss);
1101 #if defined TIZEN_EXT
1102 g_slist_free_full(bss->vsie_list, g_free);
1107 static void remove_peer(gpointer data)
1109 GSupplicantPeer *peer = data;
1111 callback_peer_lost(peer);
1114 g_slist_free_full(peer->groups, g_free);
1117 g_hash_table_remove(peer_mapping, peer->path);
1119 if (pending_peer_connection)
1120 g_hash_table_remove(pending_peer_connection, peer->path);
1124 g_free(peer->identifier);
1125 g_free(peer->widi_ies);
1130 #if defined TIZEN_EXT
1131 static void remove_assoc_data(gpointer data)
1133 struct assoc_reject_data *assoc_data = data;
1135 g_free(assoc_data->bssid);
1136 g_slist_free(assoc_data->reject_time_list);
1142 static void debug_strvalmap(const char *label, struct strvalmap *map,
1146 #if defined TIZEN_EXT
1147 if (!simplified_log)
1149 for (i = 0; map[i].str; i++) {
1150 if (val & map[i].val)
1151 SUPPLICANT_DBG("%s: %s", label, map[i].str);
1155 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
1157 GSupplicantInterface *interface = user_data;
1158 const char *str = NULL;
1161 dbus_message_iter_get_basic(iter, &str);
1165 for (i = 0; keymgmt_map[i].str; i++)
1166 if (strcmp(str, keymgmt_map[i].str) == 0) {
1167 interface->keymgmt_capa |= keymgmt_map[i].val;
1172 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
1174 GSupplicantInterface *interface = user_data;
1175 const char *str = NULL;
1178 dbus_message_iter_get_basic(iter, &str);
1182 for (i = 0; authalg_capa_map[i].str; i++)
1183 if (strcmp(str, authalg_capa_map[i].str) == 0) {
1184 interface->authalg_capa |= authalg_capa_map[i].val;
1189 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
1191 GSupplicantInterface *interface = user_data;
1192 const char *str = NULL;
1195 dbus_message_iter_get_basic(iter, &str);
1199 for (i = 0; proto_capa_map[i].str; i++)
1200 if (strcmp(str, proto_capa_map[i].str) == 0) {
1201 interface->proto_capa |= proto_capa_map[i].val;
1206 static void interface_capability_pairwise(DBusMessageIter *iter,
1209 GSupplicantInterface *interface = user_data;
1210 const char *str = NULL;
1213 dbus_message_iter_get_basic(iter, &str);
1217 for (i = 0; pairwise_map[i].str; i++)
1218 if (strcmp(str, pairwise_map[i].str) == 0) {
1219 interface->pairwise_capa |= pairwise_map[i].val;
1224 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
1226 GSupplicantInterface *interface = user_data;
1227 const char *str = NULL;
1230 dbus_message_iter_get_basic(iter, &str);
1234 for (i = 0; group_map[i].str; i++)
1235 if (strcmp(str, group_map[i].str) == 0) {
1236 interface->group_capa |= group_map[i].val;
1241 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
1243 GSupplicantInterface *interface = user_data;
1244 const char *str = NULL;
1247 dbus_message_iter_get_basic(iter, &str);
1251 for (i = 0; scan_capa_map[i].str; i++)
1252 if (strcmp(str, scan_capa_map[i].str) == 0) {
1253 interface->scan_capa |= scan_capa_map[i].val;
1258 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
1260 GSupplicantInterface *interface = user_data;
1261 const char *str = NULL;
1264 dbus_message_iter_get_basic(iter, &str);
1268 for (i = 0; mode_capa_map[i].str; i++)
1269 if (strcmp(str, mode_capa_map[i].str) == 0) {
1270 interface->mode_capa |= mode_capa_map[i].val;
1275 static void interface_capability(const char *key, DBusMessageIter *iter,
1278 GSupplicantInterface *interface = user_data;
1283 if (g_strcmp0(key, "KeyMgmt") == 0)
1284 supplicant_dbus_array_foreach(iter,
1285 interface_capability_keymgmt, interface);
1286 else if (g_strcmp0(key, "AuthAlg") == 0)
1287 supplicant_dbus_array_foreach(iter,
1288 interface_capability_authalg, interface);
1289 else if (g_strcmp0(key, "Protocol") == 0)
1290 supplicant_dbus_array_foreach(iter,
1291 interface_capability_proto, interface);
1292 else if (g_strcmp0(key, "Pairwise") == 0)
1293 supplicant_dbus_array_foreach(iter,
1294 interface_capability_pairwise, interface);
1295 else if (g_strcmp0(key, "Group") == 0)
1296 supplicant_dbus_array_foreach(iter,
1297 interface_capability_group, interface);
1298 else if (g_strcmp0(key, "Scan") == 0)
1299 supplicant_dbus_array_foreach(iter,
1300 interface_capability_scan, interface);
1301 else if (g_strcmp0(key, "Modes") == 0)
1302 supplicant_dbus_array_foreach(iter,
1303 interface_capability_mode, interface);
1304 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
1305 dbus_int32_t max_scan_ssid;
1307 dbus_message_iter_get_basic(iter, &max_scan_ssid);
1308 if (max_scan_ssid < 2)
1310 interface->max_scan_ssids = max_scan_ssid;
1311 #if defined TIZEN_EXT
1312 } else if (g_strcmp0(key, "Is5GhzSupported") == 0) {
1313 dbus_bool_t is_5_0_Ghz_supported;
1315 dbus_message_iter_get_basic(iter, &is_5_0_Ghz_supported);
1316 interface->is_5_0_Ghz_supported = is_5_0_Ghz_supported;
1319 SUPPLICANT_DBG("key %s type %c",
1320 key, dbus_message_iter_get_arg_type(iter));
1323 static void set_bss_expiration_age(DBusMessageIter *iter, void *user_data)
1325 unsigned int bss_expiration_age = GPOINTER_TO_UINT(user_data);
1327 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32,
1328 &bss_expiration_age);
1331 int g_supplicant_interface_set_bss_expiration_age(GSupplicantInterface *interface,
1332 unsigned int bss_expiration_age)
1334 return supplicant_dbus_property_set(interface->path,
1335 SUPPLICANT_INTERFACE ".Interface",
1336 "BSSExpireAge", DBUS_TYPE_UINT32_AS_STRING,
1337 set_bss_expiration_age, NULL,
1338 GUINT_TO_POINTER(bss_expiration_age), NULL);
1341 struct set_apscan_data
1343 unsigned int ap_scan;
1344 GSupplicantInterface *interface;
1347 static void set_apscan(DBusMessageIter *iter, void *user_data)
1349 struct set_apscan_data *data = user_data;
1350 unsigned int ap_scan = data->ap_scan;
1352 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
1355 static void set_apscan_complete(const char *error,
1356 DBusMessageIter *iter, void *user_data)
1358 struct set_apscan_data *data = user_data;
1359 GSupplicantInterface *interface = data->interface;
1362 interface->ap_create_in_progress = false;
1363 SUPPLICANT_DBG("Set AP scan error %s", error);
1367 interface->ap_create_in_progress = true;
1372 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
1373 unsigned int ap_scan)
1375 struct set_apscan_data *data;
1378 data = dbus_malloc0(sizeof(*data));
1383 data->ap_scan = ap_scan;
1384 data->interface = interface;
1386 ret = supplicant_dbus_property_set(interface->path,
1387 SUPPLICANT_INTERFACE ".Interface",
1388 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
1389 set_apscan, set_apscan_complete, data, NULL);
1396 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
1402 interface->data = data;
1405 interface->scan_callback = NULL;
1408 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
1413 return interface->data;
1416 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
1421 return interface->ifname;
1424 #if defined TIZEN_EXT
1425 bool g_supplicant_interface_get_is_5_0_ghz_supported(GSupplicantInterface *interface)
1430 return interface->is_5_0_Ghz_supported;
1433 unsigned char *g_supplicant_interface_get_add_network_bssid(GSupplicantInterface *interface)
1438 return (unsigned char *)interface->add_network_bssid;
1442 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
1447 return interface->driver;
1450 GSupplicantState g_supplicant_interface_get_state(
1451 GSupplicantInterface *interface)
1454 return G_SUPPLICANT_STATE_UNKNOWN;
1456 return interface->state;
1459 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
1464 return (const char *)interface->wps_cred.key;
1467 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
1468 unsigned int *ssid_len)
1473 if (!interface || interface->wps_cred.ssid_len == 0) {
1478 *ssid_len = interface->wps_cred.ssid_len;
1479 return interface->wps_cred.ssid;
1482 GSupplicantWpsState g_supplicant_interface_get_wps_state(
1483 GSupplicantInterface *interface)
1486 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
1488 return interface->wps_state;
1491 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
1496 return interface->mode_capa;
1499 unsigned int g_supplicant_interface_get_max_scan_ssids(
1500 GSupplicantInterface *interface)
1505 if (interface->max_scan_ssids == 0)
1506 return WPAS_MAX_SCAN_SSIDS;
1508 return interface->max_scan_ssids;
1511 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
1513 dbus_bool_t enable = *(dbus_bool_t *)user_data;
1515 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
1518 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
1524 if (!interface->network_path)
1527 SUPPLICANT_DBG(" ");
1528 return supplicant_dbus_property_set(interface->network_path,
1529 SUPPLICANT_INTERFACE ".Network",
1530 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
1531 set_network_enabled, NULL, &enable, NULL);
1534 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
1539 return interface->ready;
1542 GSupplicantInterface *g_supplicant_network_get_interface(
1543 GSupplicantNetwork *network)
1548 return network->interface;
1551 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
1553 if (!network || !network->name)
1556 return network->name;
1559 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
1561 if (!network || !network->group)
1564 return network->group;
1567 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1569 if (!network || !network->path)
1572 return network->path;
1575 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1580 return mode2string(network->mode);
1583 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1588 return security2string(network->security);
1591 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1592 unsigned int *ssid_len)
1599 *ssid_len = network->ssid_len;
1600 return network->ssid;
1603 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1608 return network->signal;
1611 #if defined TIZEN_EXT
1612 void g_supplicant_network_set_signal(GSupplicantNetwork *network, int signal)
1617 network->signal = (dbus_int16_t)signal;
1620 void g_supplicant_network_set_bss_signal(GSupplicantNetwork *network,
1621 int signal, int snr)
1623 struct g_supplicant_bss *best_bss;
1628 best_bss = network->best_bss;
1632 best_bss->signal = (dbus_int16_t)signal;
1633 best_bss->snr = (dbus_int16_t)snr;
1637 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1642 return network->frequency;
1645 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1650 return network->wps;
1653 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1658 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1664 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1669 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1675 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1680 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1687 GSupplicantPhy_mode g_supplicant_network_get_phy_mode(GSupplicantNetwork *network)
1690 return G_SUPPLICANT_MODE_IEEE80211_UNKNOWN;
1692 return network->phy_mode;
1696 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1701 return peer->interface;
1704 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1712 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1717 return peer->identifier;
1720 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1725 return peer->device_address;
1728 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1733 return peer->iface_address;
1736 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1744 #if defined TIZEN_EXT
1745 bool g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1750 return network->isHS20AP;
1753 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1755 if (!network || !network->eap)
1758 return network->eap;
1761 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1763 if (!network || !network->identity)
1766 return network->identity;
1769 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1771 if (!network || !network->phase2)
1774 return network->phase2;
1777 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
1782 return network->keymgmt;
1785 dbus_bool_t g_supplicant_network_get_privacy(GSupplicantNetwork *network)
1790 return network->privacy;
1793 const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
1799 return network->country_code;
1802 dbus_bool_t g_supplicant_network_is_pmf_required(GSupplicantNetwork *network)
1804 if (!network || !network->best_bss)
1807 return network->best_bss->pmf_required;
1811 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1814 if (!peer || !length)
1817 *length = peer->widi_ies_length;
1818 return peer->widi_ies;
1821 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1826 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1832 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1837 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1843 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1845 if (!peer || !peer->groups)
1851 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1856 return (GSupplicantInterface *) peer->current_group_iface;
1859 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1861 GSupplicantGroup *group;
1867 for (list = peer->groups; list; list = list->next) {
1868 const char *path = list->data;
1870 group = g_hash_table_lookup(group_mapping, path);
1874 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1875 group->orig_interface != peer->interface)
1878 if (group->interface == peer->current_group_iface)
1885 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1890 return peer->connection_requested;
1893 #if defined TIZEN_EXT
1895 * Description: Network client requires additional wifi specific info
1897 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1899 if (network == NULL || network->best_bss == NULL)
1902 return (const unsigned char *)network->best_bss->bssid;
1905 dbus_bool_t g_supplicant_network_get_transition_mode(GSupplicantNetwork *network)
1907 if (network == NULL)
1910 return network->owe_transition_mode;
1913 const unsigned char *g_supplicant_network_get_transition_mode_bssid(GSupplicantNetwork *network)
1915 if (network == NULL)
1918 return (const unsigned char *)network->transition_mode_bssid;
1921 const void *g_supplicant_network_get_transition_mode_ssid(GSupplicantNetwork *network,
1922 unsigned int *transition_mode_ssid_len)
1925 *transition_mode_ssid_len = 0;
1929 *transition_mode_ssid_len = network->transition_mode_ssid_len;
1930 return network->transition_mode_ssid;
1933 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1935 if (network == NULL || network->best_bss == NULL)
1938 return network->best_bss->maxrate;
1941 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1943 if (network == NULL || network->best_bss == NULL)
1946 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1947 network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1948 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1949 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP ||
1950 network->best_bss->security == G_SUPPLICANT_SECURITY_PSK_SHA256 ||
1951 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1952 unsigned int pairwise;
1954 pairwise = network->best_bss->rsn_pairwise |
1955 network->best_bss->wpa_pairwise;
1957 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1958 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1960 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1962 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1965 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1967 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1973 bool g_supplicant_network_get_rsn_mode(GSupplicantNetwork *network)
1975 if (network == NULL || network->best_bss == NULL)
1978 if (network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1979 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP)
1982 if (network->best_bss->rsn_selected) {
1983 const char *mode = g_supplicant_network_get_enc_mode(network);
1984 if (g_strcmp0(mode, "aes") == 0 ||
1985 g_strcmp0(mode, "mixed") == 0)
1993 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
1995 GSList *vsie_list = NULL;
2000 if (g_slist_length(network->vsie_list) > 0) {
2001 GSList *list = NULL;
2002 unsigned char *vsie = NULL;
2003 for (list = network->vsie_list; list; list = list->next) {
2004 unsigned char *ie = (unsigned char *)list->data;
2007 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2010 memcpy(vsie, ie, ie[1]+2);
2011 vsie_list = g_slist_append(vsie_list, vsie);
2013 SUPPLICANT_DBG("Failed to allocate memory");
2020 #if defined TIZEN_EXT_INS
2021 static bool compare_bssid(unsigned char *bssid_a, unsigned char *bssid_b)
2023 if (!memcmp(bssid_a, bssid_b, WIFI_BSSID_LEN_MAX))
2029 static gchar *convert_bssid_to_str(unsigned char *bssid)
2034 bssid_str = g_string_sized_new(18);
2038 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
2039 g_string_append_printf(bssid_str, "%02x", bssid[i]);
2040 if (i < WIFI_BSSID_LEN_MAX - 1)
2041 g_string_append(bssid_str, ":");
2044 return g_string_free(bssid_str, FALSE);
2047 static void count_assoc_reject(gpointer data, gpointer user_data)
2049 time_t assoc_reject_time = GPOINTER_TO_INT(data);
2050 struct assoc_count_data *assoc_count = user_data;
2052 if (assoc_reject_time > assoc_count->ref_time)
2053 assoc_count->assoc_count++;
2056 static uint16_t get_assoc_reject_cnt(GHashTable *assoc_reject_table, unsigned char *bssid)
2059 struct assoc_reject_data *assoc_data;
2060 struct assoc_count_data assoc_count;
2062 struct tm* timeinfo;
2064 if (g_hash_table_size(assoc_reject_table) < 1)
2070 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2073 bssid_str = convert_bssid_to_str(bssid);
2077 assoc_data = g_hash_table_lookup(assoc_reject_table, bssid_str);
2083 if (g_slist_length(assoc_data->reject_time_list) < 1) {
2088 /* Only events that occur within one hour are appened. */
2089 curr_time = time(NULL);
2090 timeinfo = localtime(&curr_time);
2091 timeinfo->tm_hour -= 1;
2093 assoc_count.ref_time = mktime(timeinfo);
2094 assoc_count.assoc_count = 0;
2096 g_slist_foreach(assoc_data->reject_time_list, count_assoc_reject, &assoc_count);
2099 return assoc_count.assoc_count;
2102 static int calculate_score_last_connected_bssid(bool is_last_connected)
2106 if (ins_settings.last_connected_bssid) {
2107 if (is_last_connected)
2108 score += ins_settings.last_connected_bssid_score;
2114 static int calculate_score_assoc_reject(uint16_t assoc_reject_cnt)
2118 if (ins_settings.assoc_reject)
2119 score -= (assoc_reject_cnt * ins_settings.assoc_reject_score);
2124 static int calculate_score_frequency(dbus_int16_t strength, dbus_uint16_t frequency)
2128 switch (ins_settings.preferred_freq_bssid) {
2129 case G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ:
2130 if ((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
2131 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
2132 (strength > ins_settings.signal_level3_24ghz))
2133 score += ins_settings.preferred_freq_bssid_score;
2136 case G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ:
2137 if ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
2138 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
2139 (strength > ins_settings.signal_level3_5ghz))
2140 score += ins_settings.preferred_freq_bssid_score;
2150 static int calculate_score_strength(dbus_int16_t strength)
2154 if (ins_settings.signal_bssid)
2155 score += (((strength > -60) ? -60 : strength) + 85);
2160 static int calculate_score_est_throughput(dbus_uint32_t est_throughput)
2164 if (est_throughput >= 10000)
2165 score = est_throughput / 10000;
2173 static int calculate_score(bool is_last_connected, uint16_t assoc_reject_cnt,
2174 dbus_uint16_t frequency, dbus_int16_t strength,
2175 dbus_int16_t snr, dbus_uint32_t est_throughput)
2179 score += calculate_score_last_connected_bssid(is_last_connected);
2180 score += calculate_score_assoc_reject(assoc_reject_cnt);
2181 score += calculate_score_frequency(strength, frequency);
2182 score += calculate_score_strength(strength);
2184 score += calculate_score_est_throughput(est_throughput);
2188 #endif /* defined TIZEN_EXT_INS */
2190 static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
2192 struct g_supplicant_bss *bss = value;
2193 struct g_connman_bssids *bssids = NULL;
2194 struct update_bssid_data *bssid_data = (struct update_bssid_data *)user_data;
2196 bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
2199 memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
2201 bssids->strength = bss->signal;
2202 bssids->strength += 120;
2204 if (bssids->strength > 100)
2205 bssids->strength = 100;
2207 bssids->frequency = bss->frequency;
2208 bssids->est_throughput = bss->est_throughput;
2209 bssids->score_snr = (int)bss->snr;
2211 #if defined TIZEN_EXT_INS
2212 bssids->assoc_reject_cnt = get_assoc_reject_cnt(bssid_data->assoc_reject_table, bssids->bssid);
2213 bssids->is_last_connected = compare_bssid(bssids->bssid, bssid_data->last_connected_bssid);
2215 bssids->score_last_connected_bssid = calculate_score_last_connected_bssid(bssids->is_last_connected);
2216 bssids->score_assoc_reject = calculate_score_assoc_reject(bssids->assoc_reject_cnt);
2217 bssids->score_frequency = calculate_score_frequency(bss->signal, bssids->frequency);
2218 bssids->score_strength = calculate_score_strength(bss->signal);
2219 bssids->score_est_throughput = calculate_score_est_throughput(bss->est_throughput);
2221 bssids->ins_score = calculate_score(bssids->is_last_connected,
2222 bssids->assoc_reject_cnt, bssids->frequency, bss->signal,
2223 bss->snr, bss->est_throughput);
2225 bssids->ins_score = bss->signal;
2227 bssid_data->bssid_list = g_slist_append(bssid_data->bssid_list, bssids);
2229 SUPPLICANT_DBG("Failed to allocate memory");
2232 static gint cmp_bss(gconstpointer a, gconstpointer b)
2234 struct g_connman_bssids *entry_a = (struct g_connman_bssids *)a;
2235 struct g_connman_bssids *entry_b = (struct g_connman_bssids *)b;
2237 if (entry_a->ins_score > entry_b->ins_score)
2240 if (entry_a->ins_score < entry_b->ins_score)
2243 if (entry_a->ins_score == entry_b->ins_score) {
2244 if (entry_a->strength >= entry_b->strength)
2253 #if defined TIZEN_EXT_INS
2254 static void print_bssid_sort(gpointer data, gpointer user_data)
2256 struct g_connman_bssids *bssids = data;
2258 GSupplicantNetwork *network = (GSupplicantNetwork *) user_data;
2260 if (!bssids || !network)
2263 if (!simplified_log)
2264 SUPPLICANT_DBG("ssid [%-20s] bssid[" MACSTR "] total[%2d] freq[%2d] "
2265 "last_conn[%2d] assoc_reject[%2d] strength[%2d] rssi[%2d]",
2266 network->ssid, MAC2STR(bssids->bssid), bssids->ins_score,
2267 bssids->score_frequency, bssids->score_last_connected_bssid,
2268 bssids->score_assoc_reject, bssids->score_strength, bssids->strength - 120);
2272 void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network)
2274 struct update_bssid_data bssid_data;
2276 if (g_hash_table_size(network->bss_table) < 1)
2279 bssid_data.network = network;
2280 memset(&bssid_data, 0, sizeof(bssid_data));
2281 memcpy(bssid_data.last_connected_bssid, network->last_connected_bssid, WIFI_BSSID_LEN_MAX);
2282 bssid_data.assoc_reject_table = network->assoc_reject_table;
2284 g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_data);
2285 bssid_data.bssid_list = g_slist_sort(bssid_data.bssid_list, cmp_bss);
2286 #if defined TIZEN_EXT_INS
2287 g_slist_foreach(bssid_data.bssid_list, print_bssid_sort, (gpointer)network);
2290 return bssid_data.bssid_list;
2293 #if defined TIZEN_EXT_INS
2294 void g_supplicant_network_set_last_connected_bssid(GSupplicantNetwork *network, const unsigned char *bssid)
2299 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2302 memcpy(network->last_connected_bssid, bssid, WIFI_BSSID_LEN_MAX);
2304 SUPPLICANT_DBG("last connected bssid [" MACSTR "]", MAC2STR(bssid));
2307 const unsigned char *g_supplicant_network_get_last_connected_bssid(GSupplicantNetwork *network)
2309 if (network == NULL)
2312 return (const unsigned char *)network->last_connected_bssid;
2315 void g_supplicant_network_update_assoc_reject(GSupplicantInterface *interface,
2316 GSupplicantNetwork *network)
2318 struct assoc_reject_data *assoc_data;
2325 bssid_str = convert_bssid_to_str(interface->add_network_bssid);
2329 assoc_data = g_hash_table_lookup(network->assoc_reject_table, bssid_str);
2331 assoc_data = g_try_new0(struct assoc_reject_data, 1);
2337 assoc_data->bssid = g_strdup(bssid_str);
2338 g_hash_table_insert(network->assoc_reject_table, assoc_data->bssid, assoc_data);
2341 curr_time = time(NULL);
2342 assoc_data->reject_time_list = g_slist_append(assoc_data->reject_time_list, GINT_TO_POINTER(curr_time));
2344 SUPPLICANT_DBG("bssid [%s] time [%u]", bssid_str, curr_time);
2348 callback_network_changed(network, "UpdateAssocReject");
2351 GHashTable *g_supplicant_network_get_assoc_reject_table(GSupplicantNetwork *network)
2356 return network->assoc_reject_table;
2359 static void copy_assoc_reject(gpointer key, gpointer value, gpointer user_data)
2361 struct assoc_reject_data *cloned_assoc_data;
2362 struct assoc_reject_data *assoc_data = value;
2363 GHashTable *cloned_assoc_reject_table = user_data;
2365 if (assoc_data && cloned_assoc_reject_table) {
2366 cloned_assoc_data = g_try_new0(struct assoc_reject_data, 1);
2367 if (!cloned_assoc_data)
2370 cloned_assoc_data->bssid = g_strdup(assoc_data->bssid);
2371 cloned_assoc_data->reject_time_list = g_slist_copy(assoc_data->reject_time_list);
2372 g_hash_table_insert(cloned_assoc_reject_table,
2373 cloned_assoc_data->bssid, cloned_assoc_data);
2377 GHashTable *g_supplicant_network_clone_assoc_reject_table(GSupplicantNetwork *network)
2379 GHashTable *cloned_assoc_reject_table;
2384 GHashTable *assoc_reject_table = g_supplicant_network_get_assoc_reject_table(network);
2385 if (!assoc_reject_table)
2388 cloned_assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2389 NULL, remove_assoc_data);
2390 g_hash_table_foreach(assoc_reject_table, copy_assoc_reject, cloned_assoc_reject_table);
2392 return cloned_assoc_reject_table;
2394 #endif /* defined TIZEN_EXT_INS */
2396 GSupplicantNetwork *g_supplicant_interface_get_network(GSupplicantInterface *interface,
2402 return g_hash_table_lookup(interface->network_table, group);
2404 #endif /* defined TIZEN_EXT */
2406 static void merge_network(GSupplicantNetwork *network)
2409 const char *ssid, *mode, *key_mgmt;
2410 #if defined TIZEN_EXT
2411 const char *isHS20AP;
2412 const char *eap, *identity, *phase2;
2414 unsigned int i, ssid_len;
2417 ssid = g_hash_table_lookup(network->config_table, "ssid");
2418 mode = g_hash_table_lookup(network->config_table, "mode");
2419 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
2420 #if defined TIZEN_EXT
2421 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
2422 eap = g_hash_table_lookup(network->config_table, "eap");
2423 identity = g_hash_table_lookup(network->config_table, "identity");
2424 phase2 = g_hash_table_lookup(network->config_table, "phase2");
2427 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
2430 ssid_len = strlen(ssid);
2434 str = g_string_sized_new((ssid_len * 2) + 24);
2438 for (i = 0; i < ssid_len; i++)
2439 #if defined TIZEN_EXT
2443 g_string_append_printf(str, "%02x", ssid[i]);
2444 #if defined TIZEN_EXT
2448 if (g_strcmp0(mode, "0") == 0)
2449 g_string_append_printf(str, "_managed");
2450 else if (g_strcmp0(mode, "1") == 0)
2451 g_string_append_printf(str, "_adhoc");
2452 #if defined TIZEN_EXT_WIFI_MESH
2453 else if (g_strcmp0(mode, "5") == 0)
2454 g_string_append_printf(str, "_mesh");
2457 if ((g_strcmp0(key_mgmt, "WPA-PSK") == 0) ||
2458 (g_strcmp0(key_mgmt, "SAE") == 0))
2459 g_string_append_printf(str, "_psk");
2460 #if defined TIZEN_EXT
2461 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
2462 g_string_append_printf(str, "_ieee8021x");
2464 g_string_append_printf(str, "_none");
2467 group = g_string_free(str, FALSE);
2469 SUPPLICANT_DBG("%s", group);
2471 #if defined TIZEN_EXT
2472 if (g_strcmp0(isHS20AP, "1") == 0) {
2473 network->isHS20AP = 1;
2475 g_free(network->eap);
2476 network->eap = g_strdup(eap);
2478 if (network->identity)
2479 g_free(network->identity);
2480 network->identity = g_strdup(identity);
2482 if (network->phase2)
2483 g_free(network->phase2);
2484 network->phase2 = g_strdup(phase2);
2486 network->isHS20AP = 0;
2488 network->group = g_strdup(group);
2489 callback_network_merged(network);
2490 g_free(network->group);
2495 g_hash_table_destroy(network->config_table);
2497 g_free(network->path);
2501 static void network_property(const char *key, DBusMessageIter *iter,
2504 GSupplicantNetwork *network = user_data;
2506 if (!network->interface)
2510 merge_network(network);
2514 if (g_strcmp0(key, "Enabled") == 0) {
2515 dbus_bool_t enabled = FALSE;
2517 dbus_message_iter_get_basic(iter, &enabled);
2518 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
2519 const char *str = NULL;
2521 dbus_message_iter_get_basic(iter, &str);
2523 g_hash_table_replace(network->config_table,
2524 g_strdup(key), g_strdup(str));
2527 SUPPLICANT_DBG("key %s type %c",
2528 key, dbus_message_iter_get_arg_type(iter));
2531 static void interface_network_added(DBusMessageIter *iter, void *user_data)
2533 GSupplicantInterface *interface = user_data;
2534 GSupplicantNetwork *network;
2535 const char *path = NULL;
2539 dbus_message_iter_get_basic(iter, &path);
2543 if (g_strcmp0(path, "/") == 0)
2546 network = g_try_new0(GSupplicantNetwork, 1);
2550 network->interface = interface;
2551 network->path = g_strdup(path);
2553 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2556 dbus_message_iter_next(iter);
2557 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
2558 supplicant_dbus_property_foreach(iter, network_property,
2560 network_property(NULL, NULL, network);
2564 supplicant_dbus_property_get_all(path,
2565 SUPPLICANT_INTERFACE ".Network",
2566 network_property, network, NULL);
2569 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
2574 static char *create_name(unsigned char *ssid, int ssid_len)
2577 const gchar *remainder, *invalid;
2578 int valid_bytes, remaining_bytes;
2580 if (ssid_len < 1 || ssid[0] == '\0')
2581 return g_strdup("");
2584 remainder = (const gchar *)ssid;
2585 remaining_bytes = ssid_len;
2587 while (remaining_bytes != 0) {
2588 if (g_utf8_validate(remainder, remaining_bytes,
2593 valid_bytes = invalid - remainder;
2596 string = g_string_sized_new(remaining_bytes);
2598 g_string_append_len(string, remainder, valid_bytes);
2600 /* append U+FFFD REPLACEMENT CHARACTER */
2601 g_string_append(string, "\357\277\275");
2603 remaining_bytes -= valid_bytes + 1;
2604 remainder = invalid + 1;
2608 return g_strndup((const gchar *)ssid, ssid_len + 1);
2610 g_string_append(string, remainder);
2612 return g_string_free(string, FALSE);
2615 static char *create_group(struct g_supplicant_bss *bss)
2619 const char *mode, *security;
2621 str = g_string_sized_new((bss->ssid_len * 2) + 24);
2625 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
2626 for (i = 0; i < bss->ssid_len; i++)
2627 g_string_append_printf(str, "%02x", bss->ssid[i]);
2629 g_string_append_printf(str, "hidden");
2631 mode = mode2string(bss->mode);
2633 g_string_append_printf(str, "_%s", mode);
2635 #if defined TIZEN_EXT
2636 if (bss->security == G_SUPPLICANT_SECURITY_PSK_SHA256)
2639 security = security2string(bss->security);
2641 security = security2string(bss->security);
2644 g_string_append_printf(str, "_%s", security);
2646 return g_string_free(str, FALSE);
2648 #if defined TIZEN_EXT
2649 static void update_network_with_best_bss(GSupplicantNetwork *network,
2650 struct g_supplicant_bss *best_bss)
2653 * Do not change best BSS if we are connected.
2655 if (network->interface->state == G_SUPPLICANT_STATE_COMPLETED && network->best_bss)
2658 network->signal = best_bss->signal;
2659 network->frequency = best_bss->frequency;
2660 network->best_bss = best_bss;
2663 static bool update_best_bss(GSupplicantNetwork *network,
2664 struct g_supplicant_bss *bss, struct g_supplicant_bss *best_bss)
2669 if (network->best_bss == NULL) {
2670 update_network_with_best_bss(network, bss);
2674 #if defined TIZEN_EXT_INS
2675 score_new = calculate_score(
2676 compare_bssid(bss->bssid, network->last_connected_bssid),
2677 get_assoc_reject_cnt(network->assoc_reject_table, bss->bssid),
2678 bss->frequency, bss->signal, bss->snr, bss->est_throughput);
2680 score_best = calculate_score(
2681 compare_bssid(network->best_bss->bssid, network->last_connected_bssid),
2682 get_assoc_reject_cnt(network->assoc_reject_table, network->best_bss->bssid),
2683 network->best_bss->frequency, network->best_bss->signal,
2684 network->best_bss->snr, network->best_bss->est_throughput);
2686 score_new = bss->signal;
2687 score_best = network->best_bss->signal;
2690 if (score_new > score_best) {
2691 SUPPLICANT_DBG("new[" MACSTR "][%d] : best[" MACSTR "][%d]",
2692 MAC2STR(bss->bssid), score_new,
2693 MAC2STR(network->best_bss->bssid), score_best);
2695 update_network_with_best_bss(network, bss);
2697 SUPPLICANT_DBG("Update best BSS for %s", network->name);
2705 static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
2707 GSupplicantInterface *interface = bss->interface;
2708 GSupplicantNetwork *network;
2710 bool is_new_network;
2712 group = create_group(bss);
2713 SUPPLICANT_DBG("New group created: %s", group);
2718 network = g_hash_table_lookup(interface->network_table, group);
2721 SUPPLICANT_DBG("Network %s already exist", network->name);
2722 is_new_network = false;
2727 is_new_network = true;
2729 network = g_try_new0(GSupplicantNetwork, 1);
2735 network->interface = interface;
2737 network->path = g_strdup(bss->path);
2738 network->group = group;
2739 network->name = create_name(bss->ssid, bss->ssid_len);
2740 network->mode = bss->mode;
2741 network->security = bss->security;
2742 network->keymgmt = bss->keymgmt;
2743 network->ssid_len = bss->ssid_len;
2744 memcpy(network->ssid, bss->ssid, bss->ssid_len);
2745 network->signal = bss->signal;
2746 network->frequency = bss->frequency;
2747 network->best_bss = bss;
2749 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2750 network->wps = TRUE;
2751 network->wps_capabilities = bss->wps_capabilities;
2754 #if defined TIZEN_EXT
2755 network->owe_transition_mode = bss->owe_transition_mode;
2756 network->privacy = bss->privacy;
2757 memcpy(network->transition_mode_ssid, bss->transition_mode_ssid, bss->transition_mode_ssid_len);
2758 memcpy(network->transition_mode_bssid, bss->transition_mode_bssid, WIFI_BSSID_LEN_MAX);
2760 network->keymgmt = bss->keymgmt;
2762 if (g_slist_length(bss->vsie_list) > 0) {
2763 GSList *list = NULL;
2764 unsigned char *vsie = NULL;
2765 for (list = bss->vsie_list; list; list = list->next) {
2766 unsigned char *ie = (unsigned char *)list->data;
2767 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2770 memcpy(vsie, ie, ie[1]+2);
2771 network->vsie_list = g_slist_append(network->vsie_list, vsie);
2773 SUPPLICANT_DBG("Failed to allocate memory.");
2777 network->isHS20AP = bss->hs20;
2778 memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
2779 network->phy_mode = bss->phy_mode;
2782 SUPPLICANT_DBG("New network %s created", network->name);
2784 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2787 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2790 #if defined TIZEN_EXT
2791 network->assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2792 NULL, remove_assoc_data);
2795 g_hash_table_replace(interface->network_table,
2796 network->group, network);
2798 callback_network_added(network);
2801 /* We update network's WPS properties if only bss provides WPS. */
2802 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2803 network->wps = TRUE;
2804 network->wps_capabilities = bss->wps_capabilities;
2806 if (!is_new_network)
2807 callback_network_changed(network, "WPSCapabilities");
2811 * Do not change best BSS if we are connected. It will be done through
2812 * CurrentBSS property in case of misalignment with wpa_s or roaming.
2814 #if defined TIZEN_EXT
2815 if (network != interface->current_network) {
2816 if (update_best_bss(network, bss, network->best_bss))
2817 callback_network_changed(network, "Signal");
2820 if (network != interface->current_network &&
2821 bss->signal > network->signal) {
2822 network->signal = bss->signal;
2823 network->best_bss = bss;
2824 callback_network_changed(network, "Signal");
2828 g_hash_table_replace(interface->bss_mapping, bss->path, network);
2829 g_hash_table_replace(network->bss_table, bss->path, bss);
2831 g_hash_table_replace(bss_mapping, bss->path, interface);
2836 static void bss_rates(DBusMessageIter *iter, void *user_data)
2838 struct g_supplicant_bss *bss = user_data;
2839 dbus_uint32_t rate = 0;
2841 dbus_message_iter_get_basic(iter, &rate);
2845 if (rate > bss->maxrate)
2846 bss->maxrate = rate;
2849 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
2851 unsigned int *keymgmt = user_data;
2852 const char *str = NULL;
2855 dbus_message_iter_get_basic(iter, &str);
2859 for (i = 0; keymgmt_map[i].str; i++)
2860 if (strcmp(str, keymgmt_map[i].str) == 0) {
2861 SUPPLICANT_DBG("Keymgmt: %s", str);
2862 *keymgmt |= keymgmt_map[i].val;
2867 static void bss_group(DBusMessageIter *iter, void *user_data)
2869 unsigned int *group = user_data;
2870 const char *str = NULL;
2873 dbus_message_iter_get_basic(iter, &str);
2877 for (i = 0; group_map[i].str; i++)
2878 if (strcmp(str, group_map[i].str) == 0) {
2879 SUPPLICANT_DBG("Group: %s", str);
2880 *group |= group_map[i].val;
2885 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
2887 unsigned int *pairwise = user_data;
2888 const char *str = NULL;
2891 dbus_message_iter_get_basic(iter, &str);
2895 for (i = 0; pairwise_map[i].str; i++)
2896 if (strcmp(str, pairwise_map[i].str) == 0) {
2897 SUPPLICANT_DBG("Pairwise: %s", str);
2898 *pairwise |= pairwise_map[i].val;
2903 static void bss_wpa(const char *key, DBusMessageIter *iter,
2906 struct g_supplicant_bss *bss = user_data;
2907 unsigned int value = 0;
2909 SUPPLICANT_DBG("Key: %s", key);
2911 if (g_strcmp0(key, "KeyMgmt") == 0) {
2912 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
2914 if (bss->rsn_selected)
2915 bss->rsn_keymgmt = value;
2917 bss->wpa_keymgmt = value;
2918 } else if (g_strcmp0(key, "Group") == 0) {
2919 supplicant_dbus_array_foreach(iter, bss_group, &value);
2921 if (bss->rsn_selected)
2922 bss->rsn_group = value;
2924 bss->wpa_group = value;
2925 } else if (g_strcmp0(key, "Pairwise") == 0) {
2926 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
2928 if (bss->rsn_selected)
2929 bss->rsn_pairwise = value;
2931 bss->wpa_pairwise = value;
2935 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
2938 unsigned int len = 0;
2940 while (len + 4 < ie_size) {
2941 unsigned int hi = ie[len];
2942 unsigned int lo = ie[len + 1];
2943 unsigned int tmp_type = (hi << 8) + lo;
2944 unsigned int v_len = 0;
2946 /* hi and lo are used to recreate an unsigned int
2947 * based on 2 8bits length unsigned int. */
2951 v_len = (hi << 8) + lo;
2953 if (tmp_type == type) {
2954 unsigned int ret_value = 0;
2955 unsigned char *value = (unsigned char *)&ret_value;
2957 SUPPLICANT_DBG("IE: match type 0x%x", type);
2959 /* Verifying length relevance */
2960 if (v_len > sizeof(unsigned int) ||
2961 len + 4 + v_len > ie_size)
2964 memcpy(value, ie + len + 4, v_len);
2966 SUPPLICANT_DBG("returning 0x%x", ret_value);
2973 SUPPLICANT_DBG("returning 0");
2977 #if defined TIZEN_EXT
2978 static void get_bss_phy_mode(unsigned int max_rate,
2979 unsigned int max_ext_rate, bool ht, bool vht, void *data)
2981 struct g_supplicant_bss *bss = data;
2982 unsigned int freq = bss->frequency;
2984 /* Following conditions are used to determine
2985 * IEEE 802.11 Protocol Modes:-
2987 * 1. If “Supported rates” is only till 11 Mbps,
2988 * and frequency is in 2.4GHz band, then protocol is 11B.
2989 * 2. If “Supported rates” is till 54Mbps or
2990 * “Extended supported rates” are present,
2991 * and frequency is in 2.4GHz band, then protocol is 11G.
2992 * 3. If “Supported rates” is only till 54 Mbps,
2993 * frequency is in 5GHz band , then protocol is 11A.
2994 * 4. If “HT capabilities” is supported , then protocol is 11N.
2995 * 5. If “HT capabilities” & “VHT” is supported and
2996 * frequency is in 5 GHz band, then protocol is 11AC.
2999 if (freq >= 2412 && freq <= 2484) { /* 2.4 Ghz Band */
3000 if (max_rate <= 11 && max_ext_rate <= 0 && !ht)
3001 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211B;
3002 else if ((max_rate <= 54 || max_ext_rate > 0) && !ht)
3003 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BG;
3004 else if ((max_rate >= 54 || max_ext_rate > 0) && ht)
3005 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BGN;
3007 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
3008 } else if (freq >= 5180 && freq <= 5825) { /* 5 Ghz Band */
3009 if (max_rate <= 54 && !ht)
3010 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211A;
3011 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && !vht)
3012 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211AN;
3013 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && vht)
3014 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211ANAC;
3016 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
3021 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
3023 struct g_supplicant_bss *bss = user_data;
3024 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
3025 unsigned char *ie, *ie_end;
3026 DBusMessageIter array;
3029 #if defined TIZEN_EXT
3030 const unsigned char OWE_WFA_OUI[] = { 0x50, 0x6f, 0x9a, 0x1c };
3032 unsigned char *rates = NULL;
3033 unsigned char *ext_rates = NULL;
3034 unsigned int max_rate = 0;
3035 unsigned int max_ext_rate = 0;
3036 unsigned int offset = 0;
3041 #define WMM_WPA1_WPS_INFO 221
3042 #define WPS_INFO_MIN_LEN 6
3043 #define WPS_VERSION_TLV 0x104A
3044 #define WPS_STATE_TLV 0x1044
3045 #define WPS_METHODS_TLV 0x1012
3046 #define WPS_REGISTRAR_TLV 0x1041
3047 #define WPS_VERSION 0x10
3048 #define WPS_PBC 0x04
3049 #define WPS_PIN 0x00
3050 #define WPS_CONFIGURED 0x02
3051 #if defined TIZEN_EXT
3052 #define VENDOR_SPECIFIC_INFO 0xDD
3053 #define WLAN_EID_COUNTRY 7
3054 #define WLAN_EID_RSN_INFO 48
3055 #define RSN_CAPABILITY_MFP_REQ (1 << 6)
3058 dbus_message_iter_recurse(iter, &array);
3059 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
3061 if (!ie || ie_len < 2)
3064 bss->wps_capabilities = 0;
3067 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
3069 #if defined TIZEN_EXT
3070 unsigned char *vsie;
3073 if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, OWE_WFA_OUI, sizeof(OWE_WFA_OUI)) == 0) {
3074 SUPPLICANT_DBG("IE: match vendor specific data : OWE Transition Mode");
3077 Tag: Vendor Specific: Wi-Fi Alliance: OWE Transition Mode
3078 Tag Number: Vendor Specific (221) -> ie[0]
3079 Tag length: 26 -> ie[1]
3080 OUI: 50:6f:9a (Wi-Fi Alliance) -> ie[2]
3081 Vendor Specific OUI Type: 28 -> ie[5]
3082 BSSID: 92:fd:f0:20:2b:09 -> ie[6]
3083 SSID length: 15 -> ie[12]
3084 SSID: Wi-Fi-5.2.3-owe -> ie[13]
3086 0000 dd 1a 50 6f 9a 1c 92 fd f0 20 2b 09 0f 57 69 2d ..Po..... +..Wi-
3087 0010 46 69 2d 35 2e 32 2e 33 2d 6f 77 65 Fi-5.2.3-owe
3090 bss->owe_transition_mode = TRUE;
3091 if (ie[1] >= 11) { // Tag length is at least up to ssid length position.
3092 memcpy(bss->transition_mode_bssid, ie+6, WIFI_BSSID_LEN_MAX);
3093 if (ie[12] > 0 && ie[12] < 32) {
3094 memcpy(bss->transition_mode_ssid, ie+13, ie[12]);
3095 bss->transition_mode_ssid_len = ie[12];
3097 bss->transition_mode_ssid_len = 0;
3099 bss->owe_transition_mode = FALSE;
3103 if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
3105 if (!simplified_log)
3106 SUPPLICANT_DBG("IE: match vendor specific data");
3108 vsie_len = ie[1]+2; // tag number size(1), tag length size(1)
3109 vsie = (unsigned char *)g_try_malloc0(vsie_len);
3112 memcpy(vsie, ie, vsie_len);
3113 bss->vsie_list = g_slist_append(bss->vsie_list, vsie);
3115 SUPPLICANT_DBG("Failed to allocate memory");
3119 if (ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
3120 /* Add country code only if it is a valid alphabet */
3121 if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
3122 memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
3127 if (ie[0] == WLAN_EID_HT_CAP && ie[1]) {
3132 if (ie[0] == WLAN_EID_VHT_CAP && ie[1]) {
3137 if (ie[0] == WLAN_EID_SUPP_RATES && ie[1]) {
3139 rates = g_malloc0(r_len);
3143 for (j = 0; ie && j < r_len; j++) {
3144 rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3145 if (max_rate < rates[j])
3146 max_rate = rates[j];
3151 if (ie[0] == WLAN_EID_EXT_SUPP_RATES && ie[1] > 0) {
3153 ext_rates = g_malloc0(r_len);
3157 for (j = 0; ie && j < r_len; j++) {
3158 ext_rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3159 if (max_ext_rate < ext_rates[j])
3160 max_ext_rate = ext_rates[j];
3165 if (ie[0] == WLAN_EID_RSN_INFO && ie[1] >= 20) {
3167 offset = 10 + ie[8] * 4;
3168 offset += ie[offset] * 4 + 2;
3170 if (offset <= r_len + 1 &&
3171 (ie[offset] & RSN_CAPABILITY_MFP_REQ) != 0)
3172 bss->pmf_required = TRUE;
3177 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
3178 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
3181 SUPPLICANT_DBG("IE: match WPS_OUI");
3183 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
3184 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
3186 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
3188 if (value == WPS_CONFIGURED)
3189 bss->wps_capabilities |=
3190 G_SUPPLICANT_WPS_CONFIGURED;
3193 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
3195 if (GUINT16_FROM_BE(value) == WPS_PBC)
3196 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3197 if (GUINT16_FROM_BE(value) == WPS_PIN)
3198 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3200 bss->wps_capabilities |=
3201 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
3203 /* If the AP sends this it means it's advertizing
3204 * as a registrar and the WPS process is launched
3206 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
3207 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
3209 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
3212 get_bss_phy_mode(max_rate, max_ext_rate, ht, vht, user_data);
3220 static void bss_compute_security(struct g_supplicant_bss *bss)
3223 * Combining RSN and WPA keymgmt
3224 * We combine it since parsing IEs might have set something for WPS. */
3225 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
3227 bss->ieee8021x = FALSE;
3229 #if defined TIZEN_EXT
3230 bss->ft_ieee8021x = FALSE;
3231 bss->ft_psk = FALSE;
3234 #if defined TIZEN_EXT
3236 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3237 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3238 bss->ieee8021x = TRUE;
3239 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
3240 bss->ft_ieee8021x = TRUE;
3243 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3244 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
3245 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3246 bss->ieee8021x = TRUE;
3249 #if defined TIZEN_EXT
3251 G_SUPPLICANT_KEYMGMT_WPA_PSK_256) {
3252 bss->psk_sha256 = TRUE;
3256 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3257 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3259 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
3263 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3264 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
3265 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3269 #if defined TIZEN_EXT
3271 (G_SUPPLICANT_KEYMGMT_SAE |
3272 G_SUPPLICANT_KEYMGMT_FT_SAE))
3274 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_OWE)
3276 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_DPP)
3281 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3282 #if defined TIZEN_EXT
3283 else if (bss->ft_ieee8021x)
3284 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3286 bss->security = G_SUPPLICANT_SECURITY_SAE;
3287 else if (bss->psk_sha256)
3288 bss->security = G_SUPPLICANT_SECURITY_PSK_SHA256;
3291 bss->security = G_SUPPLICANT_SECURITY_PSK;
3292 #if defined TIZEN_EXT
3293 else if (bss->ft_psk)
3294 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
3295 else if (bss->owe || bss->owe_transition_mode)
3296 bss->security = G_SUPPLICANT_SECURITY_OWE;
3298 bss->security = G_SUPPLICANT_SECURITY_DPP;
3300 else if (bss->privacy)
3301 bss->security = G_SUPPLICANT_SECURITY_WEP;
3303 bss->security = G_SUPPLICANT_SECURITY_NONE;
3307 static void bss_property(const char *key, DBusMessageIter *iter,
3310 struct g_supplicant_bss *bss = user_data;
3312 if (!bss->interface)
3314 #if defined TIZEN_EXT
3315 if (!simplified_log)
3317 SUPPLICANT_DBG("key %s", key);
3322 if (g_strcmp0(key, "BSSID") == 0) {
3323 DBusMessageIter array;
3324 unsigned char *addr;
3327 dbus_message_iter_recurse(iter, &array);
3328 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
3331 memcpy(bss->bssid, addr, addr_len);
3332 } else if (g_strcmp0(key, "SSID") == 0) {
3333 DBusMessageIter array;
3334 unsigned char *ssid;
3337 dbus_message_iter_recurse(iter, &array);
3338 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
3340 if (ssid_len > 0 && ssid_len < 33) {
3341 memcpy(bss->ssid, ssid, ssid_len);
3342 bss->ssid_len = ssid_len;
3344 memset(bss->ssid, 0, sizeof(bss->ssid));
3347 } else if (g_strcmp0(key, "Capabilities") == 0) {
3348 dbus_uint16_t capabilities = 0x0000;
3350 dbus_message_iter_get_basic(iter, &capabilities);
3352 if (capabilities & IEEE80211_CAP_ESS)
3353 bss->mode = G_SUPPLICANT_MODE_INFRA;
3354 else if (capabilities & IEEE80211_CAP_IBSS)
3355 bss->mode = G_SUPPLICANT_MODE_IBSS;
3357 if (capabilities & IEEE80211_CAP_PRIVACY)
3358 bss->privacy = TRUE;
3359 } else if (g_strcmp0(key, "Mode") == 0) {
3360 const char *mode = NULL;
3362 dbus_message_iter_get_basic(iter, &mode);
3363 bss->mode = string2mode(mode);
3364 } else if (g_strcmp0(key, "Frequency") == 0) {
3365 dbus_uint16_t frequency = 0;
3367 dbus_message_iter_get_basic(iter, &frequency);
3368 bss->frequency = frequency;
3369 } else if (g_strcmp0(key, "Signal") == 0) {
3370 dbus_int16_t signal = 0;
3372 dbus_message_iter_get_basic(iter, &signal);
3374 bss->signal = signal;
3376 bss->signal = BSS_UNKNOWN_STRENGTH;
3378 } else if (g_strcmp0(key, "Level") == 0) {
3379 dbus_int32_t level = 0;
3381 dbus_message_iter_get_basic(iter, &level);
3382 } else if (g_strcmp0(key, "Rates") == 0) {
3383 supplicant_dbus_array_foreach(iter, bss_rates, bss);
3384 } else if (g_strcmp0(key, "MaxRate") == 0) {
3385 dbus_uint32_t maxrate = 0;
3387 dbus_message_iter_get_basic(iter, &maxrate);
3389 bss->maxrate = maxrate;
3390 } else if (g_strcmp0(key, "Privacy") == 0) {
3391 dbus_bool_t privacy = FALSE;
3393 dbus_message_iter_get_basic(iter, &privacy);
3394 bss->privacy = privacy;
3395 } else if (g_strcmp0(key, "RSN") == 0) {
3396 bss->rsn_selected = TRUE;
3398 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3399 } else if (g_strcmp0(key, "WPA") == 0) {
3400 bss->rsn_selected = FALSE;
3402 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3403 #if defined TIZEN_EXT
3404 } else if (g_strcmp0(key, "HS20") == 0) {
3405 dbus_bool_t hs20 = FALSE;
3406 dbus_message_iter_get_basic(iter, &hs20);
3408 } else if (g_strcmp0(key, "SNR") == 0) {
3409 dbus_int16_t snr = 0;
3411 dbus_message_iter_get_basic(iter, &snr);
3413 } else if (g_strcmp0(key, "EstThroughput") == 0) {
3414 dbus_uint32_t est_throughput = 0;
3416 dbus_message_iter_get_basic(iter, &est_throughput);
3417 if (est_throughput != 0)
3418 bss->est_throughput = est_throughput;
3420 } else if (g_strcmp0(key, "IEs") == 0)
3421 bss_process_ies(iter, bss);
3423 SUPPLICANT_DBG("key %s type %c",
3424 key, dbus_message_iter_get_arg_type(iter));
3427 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
3430 GSupplicantInterface *interface = user_data;
3431 GSupplicantNetwork *network;
3432 struct g_supplicant_bss *bss;
3433 const char *path = NULL;
3434 #if defined TIZEN_EXT
3435 if (!simplified_log)
3439 dbus_message_iter_get_basic(iter, &path);
3443 if (g_strcmp0(path, "/") == 0)
3445 #if defined TIZEN_EXT
3446 if (!simplified_log)
3448 SUPPLICANT_DBG("%s", path);
3450 network = g_hash_table_lookup(interface->bss_mapping, path);
3452 bss = g_hash_table_lookup(network->bss_table, path);
3457 bss = g_try_new0(struct g_supplicant_bss, 1);
3461 bss->interface = interface;
3462 bss->path = g_strdup(path);
3463 bss->signal = BSS_UNKNOWN_STRENGTH;
3468 static void interface_bss_added_with_keys(DBusMessageIter *iter,
3471 struct g_supplicant_bss *bss;
3472 #if defined TIZEN_EXT
3473 if (!simplified_log)
3477 bss = interface_bss_added(iter, user_data);
3481 dbus_message_iter_next(iter);
3483 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
3484 #if defined TIZEN_EXT
3494 supplicant_dbus_property_foreach(iter, bss_property, bss);
3496 bss_compute_security(bss);
3497 if (add_or_replace_bss_to_network(bss) < 0)
3498 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3501 static void interface_bss_added_without_keys(DBusMessageIter *iter,
3504 struct g_supplicant_bss *bss;
3505 #if defined TIZEN_EXT
3506 if (!simplified_log)
3510 bss = interface_bss_added(iter, user_data);
3514 supplicant_dbus_property_get_all(bss->path,
3515 SUPPLICANT_INTERFACE ".BSS",
3516 bss_property, bss, bss);
3518 bss_compute_security(bss);
3519 if (add_or_replace_bss_to_network(bss) < 0)
3520 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3523 static void update_signal(gpointer key, gpointer value,
3526 struct g_supplicant_bss *bss = value;
3527 GSupplicantNetwork *network = user_data;
3529 #if defined TIZEN_EXT
3530 if (!network->best_bss || (network->best_bss == bss)) {
3531 if (bss->signal > network->signal) {
3532 network->signal = bss->signal;
3533 network->best_bss = bss;
3538 update_best_bss(network, bss, network->best_bss);
3540 if (bss->signal > network->signal) {
3541 network->signal = bss->signal;
3542 network->best_bss = bss;
3547 static void update_network_signal(GSupplicantNetwork *network)
3549 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
3552 g_hash_table_foreach(network->bss_table,
3553 update_signal, network);
3555 SUPPLICANT_DBG("New network signal %d", network->signal);
3558 #if defined TIZEN_EXT_INS
3559 static gboolean last_connected_timeout(gpointer data)
3561 GSupplicantInterface *interface = data;
3562 GSupplicantNetwork *current_network = interface->current_network;
3564 SUPPLICANT_DBG("Timeout last connected bss");
3566 if (current_network && current_network->best_bss) {
3567 if (compare_bssid(current_network->best_bss->bssid, interface->connected_bssid)) {
3568 g_supplicant_network_set_last_connected_bssid(current_network, interface->connected_bssid);
3569 callback_network_changed(current_network, "LastConnectedBSSID");
3573 last_connected_bss_timeout = 0;
3577 static void add_timer_for_last_connected(GSupplicantInterface *interface)
3579 GSupplicantNetwork *current_network = interface->current_network;
3581 if (interface->state == G_SUPPLICANT_STATE_COMPLETED) {
3582 if (current_network) {
3583 struct g_supplicant_bss *best_bss = current_network->best_bss;
3585 memcpy(interface->connected_bssid, best_bss->bssid, WIFI_BSSID_LEN_MAX);
3587 if (last_connected_bss_timeout)
3588 g_source_remove(last_connected_bss_timeout);
3590 last_connected_bss_timeout = g_timeout_add_seconds(LAST_CONNECTED_TIMEOUT,
3591 last_connected_timeout, interface);
3593 SUPPLICANT_DBG("Add timer for last connected bssid [" MACSTR "]",
3594 MAC2STR(best_bss->bssid));
3599 static void remove_timer_for_last_connected(GSupplicantInterface *interface)
3601 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED) {
3602 if (last_connected_bss_timeout != 0) {
3603 g_source_remove(last_connected_bss_timeout);
3604 last_connected_bss_timeout = 0;
3605 SUPPLICANT_DBG("Remove timer for last connected bss");
3609 #endif /* defined TIZEN_EXT_INS */
3611 static void interface_current_bss(GSupplicantInterface *interface,
3612 DBusMessageIter *iter)
3614 GSupplicantNetwork *network;
3615 struct g_supplicant_bss *bss;
3617 #if defined TIZEN_EXT
3618 char bssid_buff1[WIFI_BSSID_STR_LEN] = {0,};
3619 char bssid_buff2[WIFI_BSSID_STR_LEN] = {0,};
3620 char *bssid_str1 = bssid_buff1;
3621 char *bssid_str2 = bssid_buff2;
3622 gboolean update = FALSE;
3625 dbus_message_iter_get_basic(iter, &path);
3626 if (g_strcmp0(path, "/") == 0) {
3627 interface->current_network = NULL;
3631 interface_bss_added_without_keys(iter, interface);
3633 network = g_hash_table_lookup(interface->bss_mapping, path);
3637 bss = g_hash_table_lookup(network->bss_table, path);
3641 interface->current_network = network;
3642 #if defined TIZEN_EXT
3643 snprintf(bssid_str1, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bss->bssid));
3644 snprintf(bssid_str2, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(network->best_bss->bssid));
3646 SUPPLICANT_DBG("current network [%p], Passed bss %s, best bss %s",
3647 interface->current_network, bssid_str1, bssid_str2);
3649 if (network->frequency != bss->frequency) {
3650 network->frequency = bss->frequency;
3655 if (bss != network->best_bss) {
3657 * This is the case where either wpa_s got associated
3658 * to a BSS different than the one ConnMan considers
3659 * the best, or we are roaming.
3661 SUPPLICANT_DBG("Update best BSS for %s", network->name);
3663 network->best_bss = bss;
3665 if (network->signal != bss->signal) {
3666 SUPPLICANT_DBG("New network signal %d dBm",
3669 network->signal = bss->signal;
3670 callback_network_changed(network, "Signal");
3671 #if defined TIZEN_EXT
3679 #if defined TIZEN_EXT
3681 callback_network_changed(network, "");
3685 * wpa_s could notify about CurrentBSS in any state once
3686 * it got associated. It is not sure such notification will
3687 * arrive together with transition to ASSOCIATED state.
3688 * In fact, for networks with security WEP or OPEN, it
3689 * always arrives together with transition to COMPLETED.
3691 switch (interface->state) {
3692 case G_SUPPLICANT_STATE_UNKNOWN:
3693 case G_SUPPLICANT_STATE_DISABLED:
3694 case G_SUPPLICANT_STATE_DISCONNECTED:
3695 case G_SUPPLICANT_STATE_INACTIVE:
3696 case G_SUPPLICANT_STATE_SCANNING:
3697 case G_SUPPLICANT_STATE_AUTHENTICATING:
3698 case G_SUPPLICANT_STATE_ASSOCIATING:
3700 case G_SUPPLICANT_STATE_ASSOCIATED:
3701 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
3702 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
3703 case G_SUPPLICANT_STATE_COMPLETED:
3704 callback_network_associated(network);
3705 #if defined TIZEN_EXT_INS
3706 add_timer_for_last_connected(interface);
3712 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
3714 GSupplicantInterface *interface = user_data;
3715 GSupplicantNetwork *network;
3716 struct g_supplicant_bss *bss = NULL;
3717 const char *path = NULL;
3718 bool is_current_network_bss = false;
3720 dbus_message_iter_get_basic(iter, &path);
3724 network = g_hash_table_lookup(interface->bss_mapping, path);
3728 bss = g_hash_table_lookup(network->bss_table, path);
3729 if (network->best_bss == bss) {
3730 network->best_bss = NULL;
3731 network->signal = BSS_UNKNOWN_STRENGTH;
3732 is_current_network_bss = true;
3735 g_hash_table_remove(bss_mapping, path);
3737 g_hash_table_remove(interface->bss_mapping, path);
3738 g_hash_table_remove(network->bss_table, path);
3740 update_network_signal(network);
3742 if (g_hash_table_size(network->bss_table) == 0) {
3743 g_hash_table_remove(interface->network_table, network->group);
3745 if (is_current_network_bss && network->best_bss)
3746 #if defined TIZEN_EXT
3747 callback_network_changed(network, "CheckMultiBssidConnect");
3749 callback_network_changed(network, "");
3754 static void set_config_methods(DBusMessageIter *iter, void *user_data)
3756 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
3759 static void wps_property(const char *key, DBusMessageIter *iter,
3762 GSupplicantInterface *interface = user_data;
3766 #if defined TIZEN_EXT
3767 if (!simplified_log)
3769 SUPPLICANT_DBG("key: %s", key);
3771 if (g_strcmp0(key, "ConfigMethods") == 0) {
3772 const char *config_methods = "push_button", *str = NULL;
3774 dbus_message_iter_get_basic(iter, &str);
3775 if (str && strlen(str) > 0) {
3776 /* It was already set at wpa_s level, don't modify it. */
3777 SUPPLICANT_DBG("%s", str);
3781 supplicant_dbus_property_set(interface->path,
3782 SUPPLICANT_INTERFACE ".Interface.WPS",
3783 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
3784 set_config_methods, NULL, &config_methods, NULL);
3786 SUPPLICANT_DBG("No value. Set %s", config_methods);
3791 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3792 void g_supplicant_replace_config_file(const char *ifname, const char *config_file)
3800 SUPPLICANT_DBG("New {%s, %s}", ifname, config_file);
3801 g_hash_table_replace(config_file_table,
3802 g_strdup(ifname), g_strdup(config_file));
3804 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3806 static void interface_property(const char *key, DBusMessageIter *iter,
3809 GSupplicantInterface *interface = user_data;
3813 #if defined TIZEN_EXT
3814 if (!simplified_log)
3816 SUPPLICANT_DBG("%s", key);
3819 debug_strvalmap("KeyMgmt capability", keymgmt_map,
3820 interface->keymgmt_capa);
3821 debug_strvalmap("AuthAlg capability", authalg_capa_map,
3822 interface->authalg_capa);
3823 debug_strvalmap("Protocol capability", proto_capa_map,
3824 interface->proto_capa);
3825 debug_strvalmap("Pairwise capability", pairwise_map,
3826 interface->pairwise_capa);
3827 debug_strvalmap("Group capability", group_map,
3828 interface->group_capa);
3829 debug_strvalmap("Scan capability", scan_capa_map,
3830 interface->scan_capa);
3831 debug_strvalmap("Mode capability", mode_capa_map,
3832 interface->mode_capa);
3834 supplicant_dbus_property_get_all(interface->path,
3835 SUPPLICANT_INTERFACE ".Interface.WPS",
3836 wps_property, interface, interface);
3838 if (interface->ready)
3839 callback_interface_added(interface);
3844 if (g_strcmp0(key, "Capabilities") == 0) {
3845 supplicant_dbus_property_foreach(iter, interface_capability,
3847 #if !defined TIZEN_EXT
3848 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
3849 interface->p2p_support = true;
3851 #if defined TIZEN_EXT_WIFI_MESH
3852 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_MESH)
3853 interface->mesh_support = true;
3855 } else if (g_strcmp0(key, "State") == 0) {
3856 const char *str = NULL;
3858 dbus_message_iter_get_basic(iter, &str);
3860 if (string2state(str) != interface->state) {
3861 interface->state = string2state(str);
3862 callback_interface_state(interface);
3864 #if defined TIZEN_EXT_INS
3865 switch (interface->state) {
3866 case G_SUPPLICANT_STATE_COMPLETED:
3867 add_timer_for_last_connected(interface);
3869 case G_SUPPLICANT_STATE_DISCONNECTED:
3870 remove_timer_for_last_connected(interface);
3876 if (interface->ap_create_in_progress) {
3877 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
3878 callback_ap_create_fail(interface);
3880 interface->ap_create_in_progress = false;
3883 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
3884 interface->ready = FALSE;
3886 interface->ready = TRUE;
3888 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
3889 } else if (g_strcmp0(key, "Scanning") == 0) {
3890 dbus_bool_t scanning = FALSE;
3892 dbus_message_iter_get_basic(iter, &scanning);
3893 interface->scanning = scanning;
3895 if (interface->ready) {
3896 if (interface->scanning)
3897 callback_scan_started(interface);
3899 callback_scan_finished(interface);
3901 } else if (g_strcmp0(key, "ApScan") == 0) {
3904 dbus_message_iter_get_basic(iter, &apscan);
3905 interface->apscan = apscan;
3906 } else if (g_strcmp0(key, "Ifname") == 0) {
3907 const char *str = NULL;
3909 dbus_message_iter_get_basic(iter, &str);
3911 g_free(interface->ifname);
3912 interface->ifname = g_strdup(str);
3914 } else if (g_strcmp0(key, "Driver") == 0) {
3915 const char *str = NULL;
3917 dbus_message_iter_get_basic(iter, &str);
3919 g_free(interface->driver);
3920 interface->driver = g_strdup(str);
3922 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
3923 const char *str = NULL;
3925 dbus_message_iter_get_basic(iter, &str);
3927 g_free(interface->bridge);
3928 interface->bridge = g_strdup(str);
3930 } else if (g_strcmp0(key, "ConfigFile") == 0) {
3931 const char *str = NULL;
3933 dbus_message_iter_get_basic(iter, &str);
3934 if (str && strlen(str) > 0 && interface->ifname) {
3935 SUPPLICANT_DBG("New {%s, %s}", interface->ifname, str);
3936 g_hash_table_replace(config_file_table,
3937 g_strdup(interface->ifname), g_strdup(str));
3939 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
3940 interface_current_bss(interface, iter);
3941 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
3942 #if defined TIZEN_EXT
3943 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
3945 interface_network_added(iter, interface);
3946 } else if (g_strcmp0(key, "BSSs") == 0) {
3947 supplicant_dbus_array_foreach(iter,
3948 interface_bss_added_without_keys,
3950 } else if (g_strcmp0(key, "Blobs") == 0) {
3952 } else if (g_strcmp0(key, "Networks") == 0) {
3953 supplicant_dbus_array_foreach(iter, interface_network_added,
3955 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
3957 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3958 dbus_message_iter_get_basic(iter, &reason_code);
3959 callback_disconnect_reason_code(interface, reason_code);
3960 #if defined TIZEN_EXT
3961 SUPPLICANT_DBG("reason code (%d)", reason_code);
3964 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
3966 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3967 dbus_message_iter_get_basic(iter, &status_code);
3968 callback_assoc_status_code(interface, status_code);
3969 #if defined TIZEN_EXT
3970 SUPPLICANT_DBG("status code (%d)", status_code);
3974 SUPPLICANT_DBG("key %s type %c",
3975 key, dbus_message_iter_get_arg_type(iter));
3979 static void scan_network_update(DBusMessageIter *iter, void *user_data)
3981 GSupplicantInterface *interface = user_data;
3982 GSupplicantNetwork *network;
3988 dbus_message_iter_get_basic(iter, &path);
3993 if (g_strcmp0(path, "/") == 0)
3996 /* Update the network details based on scan BSS data */
3997 network = g_hash_table_lookup(interface->bss_mapping, path);
3999 callback_network_added(network);
4002 static void scan_bss_data(const char *key, DBusMessageIter *iter,
4005 GSupplicantInterface *interface = user_data;
4007 /*Fixed : stucking in scanning state when scan failed*/
4008 #if defined TIZEN_EXT
4009 GSupplicantInterfaceCallback scan_callback;
4014 supplicant_dbus_array_foreach(iter, scan_network_update,
4017 #if defined TIZEN_EXT
4018 scan_callback = interface->scan_callback;
4019 callback_scan_done(interface);
4022 if (interface->scan_callback)
4023 interface->scan_callback(0, interface, interface->scan_data);
4025 #if defined TIZEN_EXT
4026 if (interface->scan_callback == scan_callback) {
4028 interface->scan_callback = NULL;
4029 interface->scan_data = NULL;
4030 #if defined TIZEN_EXT
4035 static GSupplicantInterface *interface_alloc(const char *path)
4037 GSupplicantInterface *interface;
4039 interface = g_try_new0(GSupplicantInterface, 1);
4043 interface->path = g_strdup(path);
4045 interface->network_table = g_hash_table_new_full(g_str_hash,
4046 g_str_equal, NULL, remove_network);
4047 interface->peer_table = g_hash_table_new_full(g_str_hash,
4048 g_str_equal, NULL, remove_peer);
4049 interface->group_table = g_hash_table_new_full(g_str_hash,
4050 g_str_equal, NULL, remove_group);
4051 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
4054 g_hash_table_replace(interface_table, interface->path, interface);
4059 static void interface_added(DBusMessageIter *iter, void *user_data)
4061 GSupplicantInterface *interface;
4062 const char *path = NULL;
4063 bool properties_appended = GPOINTER_TO_UINT(user_data);
4067 dbus_message_iter_get_basic(iter, &path);
4071 if (g_strcmp0(path, "/") == 0)
4074 interface = g_hash_table_lookup(interface_table, path);
4078 interface = interface_alloc(path);
4082 if (!properties_appended) {
4083 supplicant_dbus_property_get_all(path,
4084 SUPPLICANT_INTERFACE ".Interface",
4085 interface_property, interface,
4090 dbus_message_iter_next(iter);
4091 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4092 supplicant_dbus_property_foreach(iter, interface_property,
4094 interface_property(NULL, NULL, interface);
4098 static void interface_removed(DBusMessageIter *iter, void *user_data)
4100 const char *path = NULL;
4101 GSupplicantInterface *interface = user_data;
4103 dbus_message_iter_get_basic(iter, &path);
4107 interface = g_hash_table_lookup(interface_table, path);
4108 g_supplicant_interface_cancel(interface);
4110 g_hash_table_remove(interface_table, path);
4113 static void eap_method(DBusMessageIter *iter, void *user_data)
4115 const char *str = NULL;
4118 dbus_message_iter_get_basic(iter, &str);
4122 for (i = 0; eap_method_map[i].str; i++)
4123 if (strcmp(str, eap_method_map[i].str) == 0) {
4124 eap_methods |= eap_method_map[i].val;
4129 static void service_property(const char *key, DBusMessageIter *iter,
4133 callback_system_ready();
4137 if (g_strcmp0(key, "DebugLevel") == 0) {
4138 const char *str = NULL;
4141 dbus_message_iter_get_basic(iter, &str);
4142 for (i = 0; debug_strings[i]; i++)
4143 if (g_strcmp0(debug_strings[i], str) == 0) {
4147 SUPPLICANT_DBG("Debug level %d", debug_level);
4148 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
4149 dbus_message_iter_get_basic(iter, &debug_timestamp);
4150 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
4151 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
4152 dbus_message_iter_get_basic(iter, &debug_showkeys);
4153 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
4154 } else if (g_strcmp0(key, "Interfaces") == 0) {
4155 supplicant_dbus_array_foreach(iter, interface_added, NULL);
4156 } else if (g_strcmp0(key, "EapMethods") == 0) {
4157 supplicant_dbus_array_foreach(iter, eap_method, NULL);
4158 debug_strvalmap("EAP method", eap_method_map, eap_methods);
4159 } else if (g_strcmp0(key, "Country") == 0) {
4160 const char *country = NULL;
4162 dbus_message_iter_get_basic(iter, &country);
4163 SUPPLICANT_DBG("Country %s", country);
4165 SUPPLICANT_DBG("key %s type %c",
4166 key, dbus_message_iter_get_arg_type(iter));
4169 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
4171 const char *name = NULL, *old = NULL, *new = NULL;
4175 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
4178 dbus_message_iter_get_basic(iter, &name);
4182 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
4185 dbus_message_iter_next(iter);
4186 dbus_message_iter_get_basic(iter, &old);
4187 dbus_message_iter_next(iter);
4188 dbus_message_iter_get_basic(iter, &new);
4193 if (strlen(old) > 0 && strlen(new) == 0) {
4194 system_available = FALSE;
4195 g_hash_table_remove_all(bss_mapping);
4196 g_hash_table_remove_all(peer_mapping);
4197 g_hash_table_remove_all(group_mapping);
4198 g_hash_table_remove_all(config_file_table);
4199 g_hash_table_remove_all(interface_table);
4200 callback_system_killed();
4203 if (strlen(new) > 0 && strlen(old) == 0) {
4204 system_available = TRUE;
4205 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
4206 SUPPLICANT_INTERFACE,
4207 service_property, NULL, NULL);
4211 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
4215 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
4218 supplicant_dbus_property_foreach(iter, service_property, NULL);
4221 static void signal_interface_added(const char *path, DBusMessageIter *iter)
4223 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
4225 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4226 interface_added(iter, GUINT_TO_POINTER(true));
4229 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
4233 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4234 interface_removed(iter, NULL);
4237 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
4239 GSupplicantInterface *interface;
4240 #if defined TIZEN_EXT
4241 if (!simplified_log)
4245 interface = g_hash_table_lookup(interface_table, path);
4249 supplicant_dbus_property_foreach(iter, interface_property, interface);
4252 static void signal_scan_done(const char *path, DBusMessageIter *iter)
4254 GSupplicantInterface *interface;
4255 dbus_bool_t success = FALSE;
4259 interface = g_hash_table_lookup(interface_table, path);
4263 dbus_message_iter_get_basic(iter, &success);
4265 if (interface->scanning) {
4266 callback_scan_finished(interface);
4267 interface->scanning = FALSE;
4271 * If scan is unsuccessful return -EIO else get the scanned BSSs
4272 * and update the network details accordingly
4275 if (interface->scan_callback)
4276 interface->scan_callback(-EIO, interface,
4277 interface->scan_data);
4279 interface->scan_callback = NULL;
4280 interface->scan_data = NULL;
4285 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
4286 "BSSs", scan_bss_data, interface, interface);
4289 static void signal_bss_added(const char *path, DBusMessageIter *iter)
4291 GSupplicantInterface *interface;
4292 #if defined TIZEN_EXT
4293 if (!simplified_log)
4297 interface = g_hash_table_lookup(interface_table, path);
4301 interface_bss_added_with_keys(iter, interface);
4304 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
4306 GSupplicantInterface *interface;
4310 interface = g_hash_table_lookup(interface_table, path);
4314 interface_bss_removed(iter, interface);
4317 static void signal_network_added(const char *path, DBusMessageIter *iter)
4319 GSupplicantInterface *interface;
4323 interface = g_hash_table_lookup(interface_table, path);
4327 interface_network_added(iter, interface);
4330 static void signal_network_removed(const char *path, DBusMessageIter *iter)
4332 GSupplicantInterface *interface;
4336 interface = g_hash_table_lookup(interface_table, path);
4340 interface_network_removed(iter, interface);
4342 #if defined TIZEN_EXT
4343 void *copy_vsie_list(gconstpointer src, gpointer data)
4345 return g_strdup(src);
4350 static void signal_sta_authorized(const char *path, DBusMessageIter *iter)
4352 GSupplicantInterface *interface;
4353 const char *addr = NULL;
4357 interface = g_hash_table_lookup(interface_table, path);
4361 dbus_message_iter_get_basic(iter, &addr);
4365 callback_sta_authorized(interface, addr);
4368 static void signal_sta_deauthorized(const char *path, DBusMessageIter *iter)
4370 GSupplicantInterface *interface;
4371 const char *addr = NULL;
4375 interface = g_hash_table_lookup(interface_table, path);
4379 dbus_message_iter_get_basic(iter, &addr);
4383 callback_sta_deauthorized(interface, addr);
4386 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4387 static void signal_eap(const char *path, DBusMessageIter *iter)
4389 GSupplicantInterface *interface;
4390 const char *str = NULL;
4392 SUPPLICANT_DBG("EAPOL_DEBUG callback eap signal");
4394 interface = g_hash_table_lookup(interface_table, path);
4398 // TODO: Identify EAP fail condition, currently timeout is used for failure.
4400 dbus_message_iter_get_basic(iter, &str);
4404 if (g_strcmp0("completion", str))
4407 dbus_message_iter_next(iter);
4409 dbus_message_iter_get_basic(iter, &str);
4413 if (!g_strcmp0("success", str))
4414 callback_eap(interface, true);
4416 callback_eap(interface, false);
4418 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4420 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
4422 GSupplicantInterface *interface;
4423 GSupplicantNetwork *network;
4424 GSupplicantSecurity old_security;
4425 unsigned int old_wps_capabilities;
4426 struct g_supplicant_bss *bss;
4428 #if defined TIZEN_EXT
4429 if (!simplified_log)
4433 interface = g_hash_table_lookup(bss_mapping, path);
4437 network = g_hash_table_lookup(interface->bss_mapping, path);
4441 bss = g_hash_table_lookup(network->bss_table, path);
4445 supplicant_dbus_property_foreach(iter, bss_property, bss);
4447 #if defined TIZEN_EXT
4448 if (network->interface->state != G_SUPPLICANT_STATE_COMPLETED) {
4449 network->frequency = bss->frequency;
4450 network->phy_mode = bss->phy_mode;
4453 old_security = network->security;
4454 bss_compute_security(bss);
4456 if (old_security != bss->security) {
4457 struct g_supplicant_bss *new_bss;
4459 SUPPLICANT_DBG("New network security for %s with path %s",
4460 bss->ssid, bss->path);
4463 * Security change policy:
4464 * - We first copy the current bss into a new one with
4465 * its own pointer (path)
4466 * - Clear the old bss pointer and remove the network completely
4467 * if there are no more BSSs in the bss table.
4468 * - The new bss will be added either to an existing network
4469 * or an additional network will be created
4472 new_bss = g_try_new0(struct g_supplicant_bss, 1);
4476 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
4477 new_bss->path = g_strdup(bss->path);
4478 #if defined TIZEN_EXT
4479 new_bss->vsie_list = g_slist_copy_deep(bss->vsie_list, copy_vsie_list, NULL);
4482 if (network->best_bss == bss) {
4483 network->best_bss = NULL;
4484 network->signal = BSS_UNKNOWN_STRENGTH;
4487 g_hash_table_remove(bss_mapping, path);
4489 g_hash_table_remove(interface->bss_mapping, path);
4490 g_hash_table_remove(network->bss_table, path);
4492 update_network_signal(network);
4494 if (g_hash_table_size(network->bss_table) == 0)
4495 g_hash_table_remove(interface->network_table,
4498 if (add_or_replace_bss_to_network(new_bss) < 0) {
4500 * Prevent a memory leak on failure in
4501 * add_or_replace_bss_to_network
4503 SUPPLICANT_DBG("Failed to add bss %s to network table",
4505 g_free(new_bss->path);
4512 old_wps_capabilities = network->wps_capabilities;
4514 if (old_wps_capabilities != bss->wps_capabilities) {
4515 network->wps_capabilities = bss->wps_capabilities;
4516 callback_network_changed(network, "WPSCapabilities");
4519 #if defined TIZEN_EXT
4520 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
4521 network->wps = TRUE;
4522 network->wps_capabilities |= bss->wps_capabilities;
4524 network->wps = FALSE;
4527 /* Consider only property changes of the connected BSS */
4528 if (network == interface->current_network && bss != network->best_bss)
4531 if (bss->signal == network->signal)
4536 callback_network_changed(network, "");
4542 * If the new signal is lower than the SSID signal, we need
4543 * to check for the new maximum.
4545 #if defined TIZEN_EXT
4546 if (!update_best_bss(network, bss, network->best_bss)) {
4547 if (bss != network->best_bss) {
4548 callback_network_changed(network, "");
4552 network->signal = bss->signal;
4553 update_network_signal(network);
4556 if (bss->signal < network->signal) {
4557 if (bss != network->best_bss)
4560 network->signal = bss->signal;
4561 update_network_signal(network);
4563 network->signal = bss->signal;
4564 network->best_bss = bss;
4568 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
4571 callback_network_changed(network, "Signal");
4574 static void wps_credentials(const char *key, DBusMessageIter *iter,
4577 GSupplicantInterface *interface = user_data;
4582 SUPPLICANT_DBG("key %s", key);
4584 if (g_strcmp0(key, "Key") == 0) {
4585 DBusMessageIter array;
4586 unsigned char *key_val;
4589 dbus_message_iter_recurse(iter, &array);
4590 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
4592 g_free(interface->wps_cred.key);
4593 interface->wps_cred.key = g_try_malloc0(
4594 sizeof(char) * key_len + 1);
4596 if (!interface->wps_cred.key)
4599 memcpy(interface->wps_cred.key, key_val,
4600 sizeof(char) * key_len);
4602 SUPPLICANT_DBG("WPS key present");
4603 } else if (g_strcmp0(key, "SSID") == 0) {
4604 DBusMessageIter array;
4605 unsigned char *ssid;
4608 dbus_message_iter_recurse(iter, &array);
4609 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
4611 if (ssid_len > 0 && ssid_len < 33) {
4612 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
4613 interface->wps_cred.ssid_len = ssid_len;
4615 memset(interface->wps_cred.ssid, 0, 32);
4616 interface->wps_cred.ssid_len = 0;
4621 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
4623 GSupplicantInterface *interface;
4627 interface = g_hash_table_lookup(interface_table, path);
4631 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
4634 static void wps_event_args(const char *key, DBusMessageIter *iter,
4637 GSupplicantInterface *interface = user_data;
4639 if (!key || !interface)
4642 SUPPLICANT_DBG("Arg Key %s", key);
4645 static void signal_wps_event(const char *path, DBusMessageIter *iter)
4647 GSupplicantInterface *interface;
4648 const char *name = NULL;
4652 interface = g_hash_table_lookup(interface_table, path);
4656 dbus_message_iter_get_basic(iter, &name);
4658 SUPPLICANT_DBG("Name: %s", name);
4660 if (g_strcmp0(name, "success") == 0)
4661 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
4662 else if (g_strcmp0(name, "fail") == 0)
4663 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
4665 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
4667 if (!dbus_message_iter_has_next(iter))
4670 dbus_message_iter_next(iter);
4672 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
4675 #if defined TIZEN_EXT
4676 static void signal_power_off(const char *path, DBusMessageIter *iter)
4678 int poweroff_state = 0;
4680 dbus_message_iter_get_basic(iter, &poweroff_state);
4682 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
4684 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
4685 if (poweroff_state != 2 && poweroff_state != 3)
4688 if (callbacks_pointer == NULL)
4691 if (callbacks_pointer->system_power_off == NULL)
4694 callbacks_pointer->system_power_off();
4698 static void create_peer_identifier(GSupplicantPeer *peer)
4700 const unsigned char test[ETH_ALEN] = {};
4705 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
4706 peer->identifier = g_strdup(peer->name);
4710 peer->identifier = g_malloc0(19);
4711 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
4712 peer->device_address[0],
4713 peer->device_address[1],
4714 peer->device_address[2],
4715 peer->device_address[3],
4716 peer->device_address[4],
4717 peer->device_address[5]);
4720 struct peer_property_data {
4721 GSupplicantPeer *peer;
4723 bool groups_changed;
4724 bool services_changed;
4727 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
4729 struct peer_property_data *data = user_data;
4730 GSupplicantPeer *peer = data->peer;
4731 GSupplicantGroup *group;
4732 const char *str = NULL;
4735 dbus_message_iter_get_basic(iter, &str);
4739 group = g_hash_table_lookup(group_mapping, str);
4743 elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
4745 data->old_groups = g_slist_remove_link(data->old_groups, elem);
4746 peer->groups = g_slist_concat(elem, peer->groups);
4748 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
4749 data->groups_changed = true;
4753 static void peer_property(const char *key, DBusMessageIter *iter,
4756 GSupplicantPeer *pending_peer;
4757 struct peer_property_data *data = user_data;
4758 GSupplicantPeer *peer = data->peer;
4760 SUPPLICANT_DBG("key: %s", key);
4762 if (!peer->interface)
4767 create_peer_identifier(peer);
4768 callback_peer_found(peer);
4769 pending_peer = g_hash_table_lookup(
4770 pending_peer_connection, peer->path);
4772 if (pending_peer && pending_peer == peer) {
4773 callback_peer_request(peer);
4774 g_hash_table_remove(pending_peer_connection,
4784 if (g_strcmp0(key, "DeviceAddress") == 0) {
4785 unsigned char *dev_addr;
4786 DBusMessageIter array;
4789 dbus_message_iter_recurse(iter, &array);
4790 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4792 if (len == ETH_ALEN)
4793 memcpy(peer->device_address, dev_addr, len);
4794 } else if (g_strcmp0(key, "DeviceName") == 0) {
4795 const char *str = NULL;
4797 dbus_message_iter_get_basic(iter, &str);
4799 peer->name = g_strdup(str);
4800 } else if (g_strcmp0(key, "config_method") == 0) {
4801 uint16_t wps_config;
4803 dbus_message_iter_get_basic(iter, &wps_config);
4805 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
4806 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
4807 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
4808 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
4809 } else if (g_strcmp0(key, "Groups") == 0) {
4810 data->old_groups = peer->groups;
4811 peer->groups = NULL;
4813 supplicant_dbus_array_foreach(iter,
4814 peer_groups_relation, data);
4815 if (g_slist_length(data->old_groups) > 0) {
4816 g_slist_free_full(data->old_groups, g_free);
4817 data->groups_changed = true;
4819 } else if (g_strcmp0(key, "IEs") == 0) {
4820 DBusMessageIter array;
4824 dbus_message_iter_recurse(iter, &array);
4825 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
4827 if (!ie || ie_len < 2)
4830 if (peer->widi_ies) {
4831 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
4834 g_free(peer->widi_ies);
4835 peer->widi_ies_length = 0;
4838 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
4840 memcpy(peer->widi_ies, ie, ie_len);
4841 peer->widi_ies_length = ie_len;
4842 data->services_changed = true;
4846 static void signal_peer_found(const char *path, DBusMessageIter *iter)
4848 struct peer_property_data *property_data;
4849 GSupplicantInterface *interface;
4850 const char *obj_path = NULL;
4851 GSupplicantPeer *peer;
4855 interface = g_hash_table_lookup(interface_table, path);
4859 dbus_message_iter_get_basic(iter, &obj_path);
4860 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4863 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4867 peer = g_try_new0(GSupplicantPeer, 1);
4871 peer->interface = interface;
4872 peer->path = g_strdup(obj_path);
4873 g_hash_table_insert(interface->peer_table, peer->path, peer);
4874 g_hash_table_replace(peer_mapping, peer->path, interface);
4876 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4877 property_data->peer = peer;
4879 dbus_message_iter_next(iter);
4880 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4881 supplicant_dbus_property_foreach(iter, peer_property,
4883 peer_property(NULL, NULL, property_data);
4887 supplicant_dbus_property_get_all(obj_path,
4888 SUPPLICANT_INTERFACE ".Peer",
4889 peer_property, property_data, NULL);
4892 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
4894 GSupplicantInterface *interface;
4895 const char *obj_path = NULL;
4896 GSupplicantPeer *peer;
4900 interface = g_hash_table_lookup(interface_table, path);
4904 dbus_message_iter_get_basic(iter, &obj_path);
4905 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4908 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4912 g_hash_table_remove(interface->peer_table, obj_path);
4915 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
4917 struct peer_property_data *property_data;
4918 GSupplicantInterface *interface;
4919 GSupplicantPeer *peer;
4923 interface = g_hash_table_lookup(peer_mapping, path);
4927 peer = g_hash_table_lookup(interface->peer_table, path);
4929 g_hash_table_remove(peer_mapping, path);
4933 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4934 property_data->peer = peer;
4936 supplicant_dbus_property_foreach(iter, peer_property, property_data);
4937 if (property_data->services_changed)
4938 callback_peer_changed(peer,
4939 G_SUPPLICANT_PEER_SERVICES_CHANGED);
4941 if (property_data->groups_changed)
4942 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
4944 dbus_free(property_data);
4946 if (!g_supplicant_peer_is_in_a_group(peer))
4947 peer->connection_requested = false;
4950 struct group_sig_data {
4951 const char *peer_obj_path;
4952 unsigned char iface_address[ETH_ALEN];
4953 const char *interface_obj_path;
4954 const char *group_obj_path;
4958 static void group_sig_property(const char *key, DBusMessageIter *iter,
4961 struct group_sig_data *data = user_data;
4966 if (g_strcmp0(key, "peer_interface_addr") == 0) {
4967 unsigned char *dev_addr;
4968 DBusMessageIter array;
4971 dbus_message_iter_recurse(iter, &array);
4972 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4974 if (len == ETH_ALEN)
4975 memcpy(data->iface_address, dev_addr, len);
4976 } else if (g_strcmp0(key, "role") == 0) {
4977 const char *str = NULL;
4979 dbus_message_iter_get_basic(iter, &str);
4980 if (g_strcmp0(str, "GO") == 0)
4981 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
4983 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
4984 } else if (g_strcmp0(key, "peer_object") == 0)
4985 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
4986 else if (g_strcmp0(key, "interface_object") == 0)
4987 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
4988 else if (g_strcmp0(key, "group_object") == 0)
4989 dbus_message_iter_get_basic(iter, &data->group_obj_path);
4993 static void signal_group_success(const char *path, DBusMessageIter *iter)
4995 GSupplicantInterface *interface;
4996 struct group_sig_data data = {};
4997 GSupplicantPeer *peer;
5001 interface = g_hash_table_lookup(interface_table, path);
5005 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5006 if (!data.peer_obj_path)
5009 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
5013 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
5014 interface->pending_peer_path = peer->path;
5017 static void signal_group_failure(const char *path, DBusMessageIter *iter)
5019 GSupplicantInterface *interface;
5020 struct group_sig_data data = {};
5021 GSupplicantPeer *peer;
5025 interface = g_hash_table_lookup(interface_table, path);
5029 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5030 if (!data.peer_obj_path)
5033 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
5037 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
5038 peer->connection_requested = false;
5041 static void signal_group_started(const char *path, DBusMessageIter *iter)
5043 GSupplicantInterface *interface, *g_interface;
5044 struct group_sig_data data = {};
5045 GSupplicantGroup *group;
5046 GSupplicantPeer *peer;
5050 interface = g_hash_table_lookup(interface_table, path);
5054 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5055 if (!data.interface_obj_path || !data.group_obj_path)
5058 peer = g_hash_table_lookup(interface->peer_table,
5059 interface->pending_peer_path);
5060 interface->pending_peer_path = NULL;
5064 g_interface = g_hash_table_lookup(interface_table,
5065 data.interface_obj_path);
5069 group = g_hash_table_lookup(interface->group_table,
5070 data.group_obj_path);
5074 group = g_try_new0(GSupplicantGroup, 1);
5078 group->interface = g_interface;
5079 group->orig_interface = interface;
5080 group->path = g_strdup(data.group_obj_path);
5081 group->role = data.role;
5083 g_hash_table_insert(interface->group_table, group->path, group);
5084 g_hash_table_replace(group_mapping, group->path, group);
5086 peer->current_group_iface = g_interface;
5087 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
5090 static void remove_peer_group_interface(GHashTable *group_table,
5093 GSupplicantGroup *group;
5094 GHashTableIter iter;
5095 gpointer value, key;
5100 group = g_hash_table_lookup(group_table, path);
5102 if (!group || !group->orig_interface)
5105 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
5107 while (g_hash_table_iter_next(&iter, &key, &value)) {
5108 GSupplicantPeer *peer = value;
5110 if (peer->current_group_iface == group->interface)
5111 peer->current_group_iface = NULL;
5115 static void signal_group_finished(const char *path, DBusMessageIter *iter)
5117 GSupplicantInterface *interface;
5118 struct group_sig_data data = {};
5122 interface = g_hash_table_lookup(interface_table, path);
5126 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5127 if (!data.interface_obj_path || !data.group_obj_path)
5130 remove_peer_group_interface(interface->group_table, data.group_obj_path);
5132 g_hash_table_remove(group_mapping, data.group_obj_path);
5134 g_hash_table_remove(interface->group_table, data.group_obj_path);
5137 static void signal_group_request(const char *path, DBusMessageIter *iter)
5139 GSupplicantInterface *interface;
5140 GSupplicantPeer *peer;
5141 const char *obj_path;
5145 interface = g_hash_table_lookup(interface_table, path);
5149 dbus_message_iter_get_basic(iter, &obj_path);
5150 if (!obj_path || !g_strcmp0(obj_path, "/"))
5153 peer = g_hash_table_lookup(interface->peer_table, obj_path);
5158 * Peer has been previously found and property set,
5159 * otherwise, defer connection to when peer property
5162 if (peer->identifier)
5163 callback_peer_request(peer);
5165 g_hash_table_replace(pending_peer_connection, peer->path, peer);
5168 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
5170 const char *peer_path = NULL;
5171 GSupplicantInterface *interface;
5172 GSupplicantGroup *group;
5173 GSupplicantPeer *peer;
5177 group = g_hash_table_lookup(group_mapping, path);
5181 dbus_message_iter_get_basic(iter, &peer_path);
5185 interface = g_hash_table_lookup(peer_mapping, peer_path);
5189 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5193 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
5195 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
5198 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
5200 const char *peer_path = NULL;
5201 GSupplicantInterface *interface;
5202 GSupplicantGroup *group;
5203 GSupplicantPeer *peer;
5208 group = g_hash_table_lookup(group_mapping, path);
5212 dbus_message_iter_get_basic(iter, &peer_path);
5216 for (elem = group->members; elem; elem = elem->next) {
5217 if (!g_strcmp0(elem->data, peer_path))
5225 group->members = g_slist_delete_link(group->members, elem);
5227 interface = g_hash_table_lookup(peer_mapping, peer_path);
5231 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5235 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
5236 peer->connection_requested = false;
5239 #if defined TIZEN_EXT_WIFI_MESH
5240 const void *g_supplicant_interface_get_mesh_group_ssid(
5241 GSupplicantInterface *interface,
5242 unsigned int *ssid_len)
5247 if (!interface || interface->group_info.ssid_len == 0) {
5252 *ssid_len = interface->group_info.ssid_len;
5253 return interface->group_info.ssid;
5256 int g_supplicant_mesh_get_disconnect_reason(GSupplicantInterface *interface)
5261 return interface->group_info.disconnect_reason;
5264 const char *g_supplicant_mesh_peer_get_address(GSupplicantMeshPeer *mesh_peer)
5266 if (!mesh_peer || !mesh_peer->peer_address)
5269 return mesh_peer->peer_address;
5272 int g_supplicant_mesh_peer_get_disconnect_reason(GSupplicantMeshPeer *mesh_peer)
5277 return mesh_peer->disconnect_reason;
5280 static void callback_mesh_group_started(GSupplicantInterface *interface)
5282 if (!callbacks_pointer)
5285 if (!callbacks_pointer->mesh_group_started)
5288 callbacks_pointer->mesh_group_started(interface);
5291 static void callback_mesh_group_removed(GSupplicantInterface *interface)
5293 if (!callbacks_pointer)
5296 if (!callbacks_pointer->mesh_group_removed)
5299 callbacks_pointer->mesh_group_removed(interface);
5302 static void mesh_group_info(const char *key, DBusMessageIter *iter,
5305 GSupplicantInterface *interface = user_data;
5309 if (g_strcmp0(key, "SSID") == 0) {
5310 DBusMessageIter array;
5311 unsigned char *ssid;
5314 dbus_message_iter_recurse(iter, &array);
5315 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
5317 if (ssid_len > 0 && ssid_len < 33) {
5318 memcpy(interface->group_info.ssid, ssid, ssid_len);
5319 interface->group_info.ssid_len = ssid_len;
5321 memset(interface->group_info.ssid, 0, 32);
5322 interface->group_info.ssid_len = 0;
5324 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5325 int disconnect_reason = 0;
5326 dbus_message_iter_get_basic(iter, &disconnect_reason);
5327 interface->group_info.disconnect_reason = disconnect_reason;
5331 static void signal_mesh_group_started(const char *path, DBusMessageIter *iter)
5333 GSupplicantInterface *interface;
5335 interface = g_hash_table_lookup(interface_table, path);
5339 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5341 callback_mesh_group_started(interface);
5344 static void signal_mesh_group_removed(const char *path, DBusMessageIter *iter)
5346 GSupplicantInterface *interface;
5348 interface = g_hash_table_lookup(interface_table, path);
5352 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5354 callback_mesh_group_removed(interface);
5357 static void callback_mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
5359 if (!callbacks_pointer)
5362 if (!callbacks_pointer->mesh_peer_connected)
5365 callbacks_pointer->mesh_peer_connected(mesh_peer);
5368 static void callback_mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
5370 if (!callbacks_pointer)
5373 if (!callbacks_pointer->mesh_peer_disconnected)
5376 callbacks_pointer->mesh_peer_disconnected(mesh_peer);
5379 static void mesh_peer_info(const char *key, DBusMessageIter *iter,
5382 GSupplicantMeshPeer *mesh_peer = user_data;
5386 if (g_strcmp0(key, "PeerAddress") == 0) {
5387 DBusMessageIter array;
5388 unsigned char *addr;
5391 dbus_message_iter_recurse(iter, &array);
5392 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
5394 if (addr_len == 6) {
5395 mesh_peer->peer_address = g_malloc0(19);
5396 snprintf(mesh_peer->peer_address, 19,
5397 "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1],
5398 addr[2], addr[3], addr[4], addr[5]);
5400 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5401 int disconnect_reason = 0;
5402 dbus_message_iter_get_basic(iter, &disconnect_reason);
5403 mesh_peer->disconnect_reason = disconnect_reason;
5407 static void signal_mesh_peer_connected(const char *path, DBusMessageIter *iter)
5409 GSupplicantInterface *interface;
5410 GSupplicantMeshPeer *mesh_peer;
5412 interface = g_hash_table_lookup(interface_table, path);
5416 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5417 mesh_peer->interface = interface;
5419 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5421 callback_mesh_peer_connected(mesh_peer);
5422 g_free(mesh_peer->peer_address);
5426 static void signal_mesh_peer_disconnected(const char *path,
5427 DBusMessageIter *iter)
5429 GSupplicantInterface *interface;
5430 GSupplicantMeshPeer *mesh_peer;
5432 interface = g_hash_table_lookup(interface_table, path);
5436 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5437 mesh_peer->interface = interface;
5439 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5441 callback_mesh_peer_disconnected(mesh_peer);
5442 g_free(mesh_peer->peer_address);
5448 const char *interface;
5450 void (*function) (const char *path, DBusMessageIter *iter);
5452 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
5454 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
5455 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
5456 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
5457 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
5459 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
5460 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
5461 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
5462 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
5463 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
5464 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
5465 { SUPPLICANT_INTERFACE ".Interface", "StaAuthorized", signal_sta_authorized },
5466 { SUPPLICANT_INTERFACE ".Interface", "StaDeauthorized", signal_sta_deauthorized },
5468 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
5470 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
5471 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
5472 #if defined TIZEN_EXT
5473 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
5476 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
5477 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
5479 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
5481 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
5482 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
5483 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
5484 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
5485 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
5487 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
5488 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
5489 #if defined TIZEN_EXT_WIFI_MESH
5490 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupStarted",
5491 signal_mesh_group_started },
5492 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupRemoved",
5493 signal_mesh_group_removed },
5494 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerConnected",
5495 signal_mesh_peer_connected },
5496 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerDisconnected",
5497 signal_mesh_peer_disconnected },
5500 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5501 { SUPPLICANT_INTERFACE ".Interface", "EAP", signal_eap },
5502 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5507 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
5508 DBusMessage *message, void *data)
5510 DBusMessageIter iter;
5514 path = dbus_message_get_path(message);
5516 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5518 if (!dbus_message_iter_init(message, &iter))
5519 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5521 for (i = 0; signal_map[i].interface; i++) {
5522 if (!dbus_message_has_interface(message, signal_map[i].interface))
5525 if (!dbus_message_has_member(message, signal_map[i].member))
5528 signal_map[i].function(path, &iter);
5532 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5535 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
5537 SUPPLICANT_DBG("Cancelling any pending DBus calls");
5538 supplicant_dbus_method_call_cancel_all(interface);
5539 supplicant_dbus_property_call_cancel_all(interface);
5542 struct supplicant_regdom {
5543 GSupplicantCountryCallback callback;
5545 const void *user_data;
5548 static void country_result(const char *error,
5549 DBusMessageIter *iter, void *user_data)
5551 struct supplicant_regdom *regdom = user_data;
5554 SUPPLICANT_DBG("Country setting result");
5560 SUPPLICANT_DBG("Country setting failure %s", error);
5564 if (regdom->callback)
5565 regdom->callback(result, regdom->alpha2,
5566 (void *) regdom->user_data);
5571 static void country_params(DBusMessageIter *iter, void *user_data)
5573 struct supplicant_regdom *regdom = user_data;
5575 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
5579 int g_supplicant_set_country(const char *alpha2,
5580 GSupplicantCountryCallback callback,
5581 const void *user_data)
5583 struct supplicant_regdom *regdom;
5586 SUPPLICANT_DBG("Country setting %s", alpha2);
5588 if (!system_available)
5591 regdom = dbus_malloc0(sizeof(*regdom));
5595 regdom->callback = callback;
5596 regdom->alpha2 = alpha2;
5597 regdom->user_data = user_data;
5599 ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
5600 "Country", DBUS_TYPE_STRING_AS_STRING,
5601 country_params, country_result,
5605 SUPPLICANT_DBG("Unable to set Country configuration");
5610 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
5611 GSupplicantCountryCallback callback,
5615 struct supplicant_regdom *regdom;
5618 regdom = dbus_malloc0(sizeof(*regdom));
5622 regdom->callback = callback;
5623 regdom->alpha2 = alpha2;
5624 regdom->user_data = user_data;
5626 ret = supplicant_dbus_property_set(interface->path,
5627 SUPPLICANT_INTERFACE ".Interface",
5628 "Country", DBUS_TYPE_STRING_AS_STRING,
5629 country_params, country_result,
5633 SUPPLICANT_DBG("Unable to set Country configuration");
5639 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
5644 return interface->p2p_support;
5647 struct supplicant_p2p_dev_config {
5652 static void p2p_device_config_result(const char *error,
5653 DBusMessageIter *iter, void *user_data)
5655 struct supplicant_p2p_dev_config *config = user_data;
5658 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
5661 g_free(config->device_name);
5662 g_free(config->dev_type);
5666 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
5668 int length, pos, end;
5673 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
5680 dev_type[length] = strtol(b, &e, 16);
5681 if (e && *e != '\0')
5690 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
5692 struct supplicant_p2p_dev_config *config = user_data;
5693 DBusMessageIter dict;
5695 supplicant_dbus_dict_open(iter, &dict);
5697 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
5698 DBUS_TYPE_STRING, &config->device_name);
5700 if (config->dev_type) {
5701 unsigned char dev_type[8] = {}, *type;
5704 len = dev_type_str2bin(config->dev_type, dev_type);
5707 supplicant_dbus_dict_append_fixed_array(&dict,
5708 "PrimaryDeviceType",
5709 DBUS_TYPE_BYTE, &type, len);
5713 supplicant_dbus_dict_close(iter, &dict);
5716 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
5717 const char *device_name,
5718 const char *primary_dev_type)
5720 struct supplicant_p2p_dev_config *config;
5723 SUPPLICANT_DBG("P2P Device settings %s/%s",
5724 device_name, primary_dev_type);
5726 config = dbus_malloc0(sizeof(*config));
5730 config->device_name = g_strdup(device_name);
5731 config->dev_type = g_strdup(primary_dev_type);
5733 ret = supplicant_dbus_property_set(interface->path,
5734 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5736 DBUS_TYPE_ARRAY_AS_STRING
5737 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
5738 DBUS_TYPE_STRING_AS_STRING
5739 DBUS_TYPE_VARIANT_AS_STRING
5740 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
5741 p2p_device_config_params,
5742 p2p_device_config_result, config, NULL);
5744 g_free(config->device_name);
5745 g_free(config->dev_type);
5747 SUPPLICANT_DBG("Unable to set P2P Device configuration");
5753 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
5756 const GSupplicantPeer *peer = value;
5757 const char *identifier = user_data;
5759 if (!g_strcmp0(identifier, peer->identifier))
5765 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
5766 const char *identifier)
5768 GSupplicantPeer *peer;
5770 peer = g_hash_table_find(interface->peer_table,
5771 peer_lookup_by_identifier,
5772 (void *) identifier);
5776 static void interface_create_data_free(struct interface_create_data *data)
5778 g_free(data->ifname);
5779 g_free(data->driver);
5780 g_free(data->bridge);
5781 #if defined TIZEN_EXT_WIFI_MESH
5782 g_free(data->parent_ifname);
5787 static bool interface_exists(GSupplicantInterface *interface,
5790 GSupplicantInterface *tmp;
5792 tmp = g_hash_table_lookup(interface_table, path);
5793 if (tmp && tmp == interface)
5799 static void interface_create_property(const char *key, DBusMessageIter *iter,
5802 struct interface_create_data *data = user_data;
5803 GSupplicantInterface *interface = data->interface;
5806 if (data->callback) {
5807 data->callback(0, data->interface, data->user_data);
5808 #if !defined TIZEN_EXT
5809 callback_p2p_support(interface);
5811 #if defined TIZEN_EXT_WIFI_MESH
5812 callback_mesh_support(interface);
5816 interface_create_data_free(data);
5819 interface_property(key, iter, interface);
5822 static void interface_create_result(const char *error,
5823 DBusMessageIter *iter, void *user_data)
5825 struct interface_create_data *data = user_data;
5826 const char *path = NULL;
5832 g_warning("error %s", error);
5837 dbus_message_iter_get_basic(iter, &path);
5843 if (!system_available) {
5848 data->interface = g_hash_table_lookup(interface_table, path);
5849 if (!data->interface) {
5850 data->interface = interface_alloc(path);
5851 if (!data->interface) {
5857 err = supplicant_dbus_property_get_all(path,
5858 SUPPLICANT_INTERFACE ".Interface",
5859 interface_create_property, data,
5866 data->callback(err, NULL, data->user_data);
5868 interface_create_data_free(data);
5871 static void interface_create_params(DBusMessageIter *iter, void *user_data)
5873 struct interface_create_data *data = user_data;
5874 DBusMessageIter dict;
5875 char *config_file = NULL;
5879 supplicant_dbus_dict_open(iter, &dict);
5881 supplicant_dbus_dict_append_basic(&dict, "Ifname",
5882 DBUS_TYPE_STRING, &data->ifname);
5885 supplicant_dbus_dict_append_basic(&dict, "Driver",
5886 DBUS_TYPE_STRING, &data->driver);
5889 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
5890 DBUS_TYPE_STRING, &data->bridge);
5892 config_file = g_hash_table_lookup(config_file_table, data->ifname);
5894 SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
5896 supplicant_dbus_dict_append_basic(&dict, "ConfigFile",
5897 DBUS_TYPE_STRING, &config_file);
5901 if (data->driver && g_strstr_len(data->driver, strlen(data->driver), "nl80211")) {
5902 supplicant_dbus_dict_append_basic(&dict, "MacAddr",
5903 DBUS_TYPE_UINT32, &data->mac_addr);
5905 supplicant_dbus_dict_append_basic(&dict, "PreassocMacAddr",
5906 DBUS_TYPE_UINT32, &data->preassoc_mac_addr);
5908 supplicant_dbus_dict_append_basic(&dict, "RandAddrLifetime",
5909 DBUS_TYPE_UINT32, &data->random_mac_lifetime);
5911 #endif /* TIZEN_EXT */
5913 #if defined TIZEN_EXT_WIFI_MESH
5914 if (data->is_mesh_interface) {
5915 if (data->parent_ifname)
5916 supplicant_dbus_dict_append_basic(&dict, "ParentIfname",
5917 DBUS_TYPE_STRING, &data->parent_ifname);
5919 supplicant_dbus_dict_append_basic(&dict, "IsMeshInterface",
5920 DBUS_TYPE_BOOLEAN, &data->is_mesh_interface);
5924 supplicant_dbus_dict_close(iter, &dict);
5927 #if defined TIZEN_EXT
5928 static void interface_get_state(const char *key, DBusMessageIter *iter,
5931 struct interface_create_data *data = user_data;
5932 GSupplicantInterface *interface = NULL;
5933 const char *str = NULL;
5935 SUPPLICANT_DBG("key[%s]", key);
5938 SUPPLICANT_DBG("data is NULL");
5942 interface = data->interface;
5944 SUPPLICANT_DBG("interface is NULL");
5949 dbus_message_iter_get_basic(iter, &str);
5952 if (string2state(str) != interface->state)
5953 interface->state = string2state(str);
5956 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
5957 interface->ready = FALSE;
5959 interface->ready = TRUE;
5961 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
5963 if (data->callback) {
5964 data->callback(0, interface, data->user_data);
5965 #if defined TIZEN_EXT_WIFI_MESH
5966 callback_mesh_support(interface);
5970 interface_create_data_free(data);
5974 static void interface_get_result(const char *error,
5975 DBusMessageIter *iter, void *user_data)
5977 struct interface_create_data *data = user_data;
5978 GSupplicantInterface *interface;
5979 const char *path = NULL;
5982 #if defined TIZEN_EXT
5983 if (!simplified_log)
5988 SUPPLICANT_DBG("Interface not created yet");
5992 dbus_message_iter_get_basic(iter, &path);
5998 interface = g_hash_table_lookup(interface_table, path);
6004 #if defined TIZEN_EXT
6005 data->interface = interface;
6006 err = supplicant_dbus_property_get(path,
6007 SUPPLICANT_INTERFACE ".Interface",
6008 "State", interface_get_state, data, NULL);
6014 if (data->callback) {
6015 data->callback(0, interface, data->user_data);
6016 #if !defined TIZEN_EXT
6017 callback_p2p_support(interface);
6019 #if defined TIZEN_EXT_WIFI_MESH
6020 callback_mesh_support(interface);
6024 interface_create_data_free(data);
6029 if (!system_available) {
6034 SUPPLICANT_DBG("Creating interface");
6036 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
6037 SUPPLICANT_INTERFACE,
6039 interface_create_params,
6040 interface_create_result, data,
6047 data->callback(err, NULL, data->user_data);
6049 interface_create_data_free(data);
6052 static void interface_get_params(DBusMessageIter *iter, void *user_data)
6054 struct interface_create_data *data = user_data;
6055 #if defined TIZEN_EXT
6056 if (!simplified_log)
6060 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
6063 #if defined TIZEN_EXT_WIFI_MESH
6064 int g_supplicant_mesh_interface_create(const char *ifname, const char *driver,
6065 const char *bridge, const char *parent_ifname,
6066 GSupplicantInterfaceCallback callback, void *user_data)
6068 struct interface_create_data *data;
6071 SUPPLICANT_DBG("ifname %s", ifname);
6073 if (!ifname || !parent_ifname)
6076 if (!system_available)
6079 data = dbus_malloc0(sizeof(*data));
6083 data->ifname = g_strdup(ifname);
6084 data->driver = g_strdup(driver);
6085 data->bridge = g_strdup(bridge);
6086 data->is_mesh_interface = true;
6087 data->parent_ifname = g_strdup(parent_ifname);
6088 data->callback = callback;
6089 data->user_data = user_data;
6091 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6092 SUPPLICANT_INTERFACE,
6094 interface_create_params,
6095 interface_create_result, data,
6100 struct interface_mesh_peer_data {
6103 GSupplicantInterface *interface;
6104 GSupplicantInterfaceCallback callback;
6108 static void interface_mesh_change_peer_params(DBusMessageIter *iter,
6111 struct interface_mesh_peer_data *data = user_data;
6115 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->peer_address);
6118 static void interface_mesh_change_peer_result(const char *error,
6119 DBusMessageIter *iter, void *user_data)
6121 struct interface_mesh_peer_data *data = user_data;
6124 SUPPLICANT_DBG("%s", data->method);
6128 SUPPLICANT_DBG("error %s", error);
6132 data->callback(err, data->interface, data->user_data);
6134 g_free(data->peer_address);
6135 g_free(data->method);
6139 int g_supplicant_interface_mesh_peer_change_status(
6140 GSupplicantInterface *interface,
6141 GSupplicantInterfaceCallback callback, const char *peer_address,
6142 const char *method, void *user_data)
6144 struct interface_mesh_peer_data *data;
6150 data = dbus_malloc0(sizeof(*data));
6154 data->peer_address = g_strdup(peer_address);
6155 data->method = g_strdup(method);
6156 data->interface = interface;
6157 data->callback = callback;
6158 data->user_data = user_data;
6160 ret = supplicant_dbus_method_call(interface->path,
6161 SUPPLICANT_INTERFACE ".Interface.Mesh",
6162 method, interface_mesh_change_peer_params,
6163 interface_mesh_change_peer_result, data, NULL);
6165 g_free(data->peer_address);
6166 g_free(data->method);
6174 int g_supplicant_interface_create(const char *ifname, const char *driver,
6177 unsigned int mac_policy,
6178 unsigned int preassoc_mac_policy,
6179 unsigned int random_mac_lifetime,
6180 #endif /* TIZEN_EXT */
6181 GSupplicantInterfaceCallback callback,
6184 struct interface_create_data *data;
6187 SUPPLICANT_DBG("ifname %s", ifname);
6192 if (!system_available)
6195 data = dbus_malloc0(sizeof(*data));
6199 data->ifname = g_strdup(ifname);
6200 data->driver = g_strdup(driver);
6201 data->bridge = g_strdup(bridge);
6202 data->callback = callback;
6204 data->mac_addr = mac_policy;
6205 data->preassoc_mac_addr = preassoc_mac_policy;
6206 data->random_mac_lifetime = random_mac_lifetime;
6207 #endif /* TIZEN_EXT */
6208 data->user_data = user_data;
6210 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6211 SUPPLICANT_INTERFACE,
6213 interface_get_params,
6214 interface_get_result, data,
6217 interface_create_data_free(data);
6222 static void interface_remove_result(const char *error,
6223 DBusMessageIter *iter, void *user_data)
6225 struct interface_data *data = user_data;
6230 SUPPLICANT_DBG("error: %s", error);
6234 if (!system_available) {
6240 * The gsupplicant interface is already freed by the InterfaceRemoved
6241 * signal callback. Simply invoke the interface_data callback.
6249 data->callback(err, NULL, data->user_data);
6255 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
6257 struct interface_data *data = user_data;
6259 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6260 &data->interface->path);
6263 int g_supplicant_interface_remove(GSupplicantInterface *interface,
6264 GSupplicantInterfaceCallback callback,
6267 struct interface_data *data;
6273 if (!system_available)
6276 g_supplicant_interface_cancel(interface);
6278 data = dbus_malloc0(sizeof(*data));
6282 data->interface = interface;
6283 data->path = g_strdup(interface->path);
6284 data->callback = callback;
6285 data->user_data = user_data;
6287 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6288 SUPPLICANT_INTERFACE,
6290 interface_remove_params,
6291 interface_remove_result, data,
6300 static void interface_scan_result(const char *error,
6301 DBusMessageIter *iter, void *user_data)
6303 struct interface_scan_data *data = user_data;
6307 SUPPLICANT_DBG("error %s", error);
6311 /* A non ready interface cannot send/receive anything */
6312 if (interface_exists(data->interface, data->path)) {
6313 if (!data->interface->ready)
6321 data->callback(err, data->interface, data->user_data);
6323 data->interface->scan_callback = data->callback;
6324 data->interface->scan_data = data->user_data;
6327 if (data->scan_params)
6328 g_supplicant_free_scan_params(data->scan_params);
6333 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
6335 DBusMessageIter data;
6336 unsigned int width = 0; /* Not used by wpa_supplicant atm */
6338 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
6340 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
6341 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
6343 dbus_message_iter_close_container(iter, &data);
6346 static void add_scan_frequencies(DBusMessageIter *iter,
6349 GSupplicantScanParams *scan_data = user_data;
6353 for (i = 0; i < scan_data->num_freqs; i++) {
6354 freq = scan_data->freqs[i];
6358 add_scan_frequency(iter, freq);
6362 static void append_ssid(DBusMessageIter *iter,
6363 const void *ssid, unsigned int len)
6365 DBusMessageIter array;
6367 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
6368 DBUS_TYPE_BYTE_AS_STRING, &array);
6370 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
6372 dbus_message_iter_close_container(iter, &array);
6375 static void append_ssids(DBusMessageIter *iter, void *user_data)
6377 GSupplicantScanParams *scan_data = user_data;
6380 for (list = scan_data->ssids; list; list = list->next) {
6381 struct scan_ssid *scan_ssid = list->data;
6383 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
6387 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
6388 supplicant_dbus_array_function function,
6391 GSupplicantScanParams *scan_params = user_data;
6392 DBusMessageIter entry, value, array;
6393 const char *key = "Channels";
6395 if (scan_params->freqs && scan_params->freqs[0] != 0) {
6396 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
6399 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
6401 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
6402 DBUS_TYPE_ARRAY_AS_STRING
6403 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6404 DBUS_TYPE_UINT32_AS_STRING
6405 DBUS_TYPE_UINT32_AS_STRING
6406 DBUS_STRUCT_END_CHAR_AS_STRING,
6409 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
6410 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6411 DBUS_TYPE_UINT32_AS_STRING
6412 DBUS_TYPE_UINT32_AS_STRING
6413 DBUS_STRUCT_END_CHAR_AS_STRING,
6417 function(&array, user_data);
6419 dbus_message_iter_close_container(&value, &array);
6420 dbus_message_iter_close_container(&entry, &value);
6421 dbus_message_iter_close_container(dict, &entry);
6425 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
6427 DBusMessageIter dict;
6428 const char *type = "passive";
6429 struct interface_scan_data *data = user_data;
6431 supplicant_dbus_dict_open(iter, &dict);
6433 if (data && data->scan_params) {
6436 supplicant_dbus_dict_append_basic(&dict, "Type",
6437 DBUS_TYPE_STRING, &type);
6439 #if defined TIZEN_EXT
6440 SUPPLICANT_DBG("[specific_scan] num_ssids %d",
6441 data->scan_params->num_ssids);
6444 if (data->scan_params->ssids) {
6445 supplicant_dbus_dict_append_array(&dict, "SSIDs",
6450 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
6453 supplicant_dbus_dict_append_basic(&dict, "Type",
6454 DBUS_TYPE_STRING, &type);
6456 supplicant_dbus_dict_close(iter, &dict);
6459 static int interface_ready_to_scan(GSupplicantInterface *interface)
6464 if (!system_available)
6467 if (interface->scanning)
6470 switch (interface->state) {
6471 case G_SUPPLICANT_STATE_AUTHENTICATING:
6472 case G_SUPPLICANT_STATE_ASSOCIATING:
6473 case G_SUPPLICANT_STATE_ASSOCIATED:
6474 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
6475 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
6477 #if defined TIZEN_EXT
6478 case G_SUPPLICANT_STATE_DISABLED:
6480 case G_SUPPLICANT_STATE_UNKNOWN:
6482 case G_SUPPLICANT_STATE_UNKNOWN:
6483 case G_SUPPLICANT_STATE_DISABLED:
6485 case G_SUPPLICANT_STATE_DISCONNECTED:
6486 case G_SUPPLICANT_STATE_INACTIVE:
6487 case G_SUPPLICANT_STATE_SCANNING:
6488 case G_SUPPLICANT_STATE_COMPLETED:
6495 #if defined TIZEN_EXT_WIFI_MESH
6496 static void interface_abort_scan_result(const char *error,
6497 DBusMessageIter *iter, void *user_data)
6499 struct interface_scan_data *data = user_data;
6503 SUPPLICANT_DBG("error %s", error);
6510 data->callback(err, data->interface, data->user_data);
6515 int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
6516 GSupplicantInterfaceCallback callback, void *user_data)
6518 struct interface_scan_data *data;
6521 if (!interface->scanning)
6524 data = dbus_malloc0(sizeof(*data));
6528 data->interface = interface;
6529 data->path = g_strdup(interface->path);
6530 data->callback = callback;
6531 data->user_data = user_data;
6533 ret = supplicant_dbus_method_call(interface->path,
6534 SUPPLICANT_INTERFACE ".Interface", "AbortScan", NULL,
6535 interface_abort_scan_result, data, interface);
6546 int g_supplicant_interface_scan(GSupplicantInterface *interface,
6547 GSupplicantScanParams *scan_data,
6548 GSupplicantInterfaceCallback callback,
6551 struct interface_scan_data *data;
6554 ret = interface_ready_to_scan(interface);
6558 data = dbus_malloc0(sizeof(*data));
6562 data->interface = interface;
6563 data->path = g_strdup(interface->path);
6564 #if defined TIZEN_EXT
6565 data->interface->scan_callback = data->callback = callback;
6566 data->interface->scan_data = data->user_data = user_data;
6568 data->callback = callback;
6569 data->user_data = user_data;
6571 data->scan_params = scan_data;
6573 interface->scan_callback = callback;
6574 interface->scan_data = user_data;
6576 ret = supplicant_dbus_method_call(interface->path,
6577 SUPPLICANT_INTERFACE ".Interface", "Scan",
6578 interface_scan_params, interface_scan_result, data,
6589 #if defined TIZEN_EXT
6590 static void interface_signalpoll_result(const char *error,
6591 DBusMessageIter *iter, void *user_data)
6593 struct interface_signalpoll_data *data = user_data;
6595 dbus_int32_t maxspeed = 0;
6596 dbus_int32_t strength = 0;
6597 dbus_int32_t snr = 0;
6598 dbus_uint32_t est_throughput = 0;
6599 DBusMessageIter sub_iter, dict;
6603 SUPPLICANT_DBG("error: %s", error);
6607 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
6609 SUPPLICANT_DBG("invalid reply");
6613 dbus_message_iter_recurse(iter, &sub_iter);
6614 dbus_message_iter_recurse(&sub_iter, &dict);
6616 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
6617 DBusMessageIter entry, value;
6620 dbus_message_iter_recurse(&dict, &entry);
6621 dbus_message_iter_get_basic(&entry, &key);
6622 dbus_message_iter_next(&entry);
6623 dbus_message_iter_recurse(&entry, &value);
6625 switch (dbus_message_iter_get_arg_type(&value)) {
6626 case DBUS_TYPE_INT32:
6627 if (g_strcmp0(key, "linkspeed") == 0) {
6628 dbus_message_iter_get_basic(&value, &maxspeed);
6629 SUPPLICANT_DBG("linkspeed = %d", maxspeed);
6630 } else if (g_strcmp0(key, "rssi") == 0) {
6631 dbus_message_iter_get_basic(&value, &strength);
6632 SUPPLICANT_DBG("Strength = %d", strength);
6633 } else if (g_strcmp0(key, "SNR") == 0) {
6634 dbus_message_iter_get_basic(&value, &snr);
6635 SUPPLICANT_DBG("SNR = %d", snr);
6638 case DBUS_TYPE_UINT32:
6639 if (g_strcmp0(key, "est_throughput") == 0) {
6640 dbus_message_iter_get_basic(&value, &est_throughput);
6641 SUPPLICANT_DBG("est_throughput = %u", est_throughput);
6645 dbus_message_iter_next(&dict);
6650 data->callback(err, maxspeed, strength, snr, data->user_data, est_throughput);
6656 int g_supplicant_interface_signalpoll(GSupplicantInterface *interface,
6657 GSupplicantMaxSpeedCallback callback,
6660 struct interface_signalpoll_data *data;
6666 if (!system_available)
6669 data = dbus_malloc0(sizeof(*data));
6673 data->interface = interface;
6674 data->path = g_strdup(interface->path);
6675 data->callback = callback;
6676 data->user_data = user_data;
6678 ret = supplicant_dbus_method_call(interface->path,
6679 SUPPLICANT_INTERFACE ".Interface", "SignalPoll",
6680 NULL, interface_signalpoll_result, data,
6692 static int parse_supplicant_error(DBusMessageIter *iter)
6694 int err = -ECONNABORTED;
6700 /* If the given passphrase is malformed wpa_s returns
6701 * "invalid message format" but this error should be interpreted as
6704 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
6705 dbus_message_iter_get_basic(iter, &key);
6706 if (strncmp(key, "psk", 3) == 0 ||
6707 strncmp(key, "wep_key", 7) == 0 ||
6708 strcmp(key, "invalid message format") == 0) {
6712 dbus_message_iter_next(iter);
6718 static void interface_select_network_result(const char *error,
6719 DBusMessageIter *iter, void *user_data)
6721 struct interface_connect_data *data = user_data;
6728 #if defined TIZEN_EXT
6729 SUPPLICANT_DBG("SelectNetwork errorFreq %s", error);
6731 SUPPLICANT_DBG("SelectNetwork error %s", error);
6733 err = parse_supplicant_error(iter);
6739 data->callback(err, data->interface, data->user_data);
6741 #if defined TIZEN_EXT
6742 g_free(data->ssid->ssid);
6743 if (data->ssid->is_passphrase_alloc)
6744 g_free((char *)data->ssid->passphrase);
6745 if (data->ssid->is_connector_alloc)
6746 g_free((char *)data->ssid->connector);
6747 if (data->ssid->is_c_sign_key_alloc)
6748 g_free((char *)data->ssid->c_sign_key);
6749 if (data->ssid->is_net_access_key_alloc)
6750 g_free((char *)data->ssid->net_access_key);
6756 static void interface_select_network_params(DBusMessageIter *iter,
6759 struct interface_connect_data *data = user_data;
6760 GSupplicantInterface *interface = data->interface;
6761 #if defined TIZEN_EXT
6762 GSupplicantSSID *ssid = data->ssid;
6765 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6766 &interface->network_path);
6767 #if defined TIZEN_EXT
6768 if (!ssid->bssid_for_connect_len)
6769 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
6773 static void interface_add_network_result(const char *error,
6774 DBusMessageIter *iter, void *user_data)
6776 struct interface_connect_data *data = user_data;
6777 GSupplicantInterface *interface = data->interface;
6784 dbus_message_iter_get_basic(iter, &path);
6788 SUPPLICANT_DBG("PATH: %s", path);
6790 #if defined TIZEN_EXT
6791 if (interface->network_path)
6792 g_free(interface->network_path);
6794 interface->network_path = g_strdup(path);
6796 store_network_information(interface, data->ssid);
6798 #if defined TIZEN_EXT
6799 SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
6800 GSupplicantSSID *ssid = data->ssid;
6802 if (!ssid->bssid_for_connect_len)
6803 supplicant_dbus_method_call(data->interface->path,
6804 SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
6805 interface_select_network_params,
6806 interface_select_network_result, data,
6809 supplicant_dbus_method_call(data->interface->path,
6810 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6811 interface_select_network_params,
6812 interface_select_network_result, data,
6815 supplicant_dbus_method_call(data->interface->path,
6816 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6817 interface_select_network_params,
6818 interface_select_network_result, data,
6825 SUPPLICANT_DBG("AddNetwork error %s", error);
6827 if (interface_exists(data->interface, data->interface->path)) {
6828 err = parse_supplicant_error(iter);
6830 data->callback(err, data->interface, data->user_data);
6832 g_free(interface->network_path);
6833 interface->network_path = NULL;
6837 #if defined TIZEN_EXT
6838 g_free(data->ssid->ssid);
6839 if (data->ssid->is_passphrase_alloc)
6840 g_free((char *)data->ssid->passphrase);
6841 if (data->ssid->is_connector_alloc)
6842 g_free((char *)data->ssid->connector);
6843 if (data->ssid->is_c_sign_key_alloc)
6844 g_free((char *)data->ssid->c_sign_key);
6845 if (data->ssid->is_net_access_key_alloc)
6846 g_free((char *)data->ssid->net_access_key);
6852 static void add_network_security_none(DBusMessageIter *dict)
6854 const char *auth_alg = "OPEN";
6856 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6857 DBUS_TYPE_STRING, &auth_alg);
6860 static void add_network_security_wep(DBusMessageIter *dict,
6861 GSupplicantSSID *ssid)
6863 const char *auth_alg = "OPEN SHARED";
6864 dbus_uint32_t key_index = 0;
6866 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6867 DBUS_TYPE_STRING, &auth_alg);
6869 if (ssid->passphrase) {
6870 int size = strlen(ssid->passphrase);
6871 if (size == 10 || size == 26) {
6872 unsigned char *key = g_try_malloc(13);
6876 memset(tmp, 0, sizeof(tmp));
6880 for (i = 0; i < size / 2; i++) {
6881 memcpy(tmp, ssid->passphrase + (i * 2), 2);
6882 key[i] = (unsigned char) strtol(tmp, NULL, 16);
6885 supplicant_dbus_dict_append_fixed_array(dict,
6890 } else if (size == 5 || size == 13) {
6891 unsigned char *key = g_try_malloc(13);
6897 for (i = 0; i < size; i++)
6898 key[i] = (unsigned char) ssid->passphrase[i];
6900 supplicant_dbus_dict_append_fixed_array(dict,
6906 supplicant_dbus_dict_append_basic(dict,
6911 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
6912 DBUS_TYPE_UINT32, &key_index);
6916 static dbus_bool_t is_psk_raw_key(const char *psk)
6920 /* A raw key is always 64 bytes length... */
6921 if (strlen(psk) != 64)
6924 /* ... and its content is in hex representation */
6925 for (i = 0; i < 64; i++)
6926 if (!isxdigit((unsigned char) psk[i]))
6932 static unsigned char hexchar2bin(char c)
6934 if ((c >= '0') && (c <= '9'))
6936 else if ((c >= 'A') && (c <= 'F'))
6937 return c - 'A' + 10;
6938 else if ((c >= 'a') && (c <= 'f'))
6939 return c - 'a' + 10;
6944 static void hexstring2bin(const char *string, unsigned char *data,
6949 for (i = 0; i < data_len; i++)
6950 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
6951 hexchar2bin(string[i * 2 + 1]) << 0);
6954 static void add_network_security_psk(DBusMessageIter *dict,
6955 GSupplicantSSID *ssid)
6957 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
6958 const char *key = "psk";
6960 if (is_psk_raw_key(ssid->passphrase)) {
6961 unsigned char data[32];
6962 unsigned char *datap = data;
6964 /* The above pointer alias is required by D-Bus because
6965 * with D-Bus and GCC, non-heap-allocated arrays cannot
6966 * be passed directly by their base pointer. */
6968 hexstring2bin(ssid->passphrase, datap, sizeof(data));
6970 supplicant_dbus_dict_append_fixed_array(dict,
6971 key, DBUS_TYPE_BYTE,
6972 &datap, sizeof(data));
6974 supplicant_dbus_dict_append_basic(dict,
6975 key, DBUS_TYPE_STRING,
6980 static void add_network_security_tls(DBusMessageIter *dict,
6981 GSupplicantSSID *ssid)
6984 * For TLS, we at least need:
6985 * The client certificate
6986 * The client private key file
6987 * The client private key file password
6989 * The Authority certificate is optional.
6991 if (!ssid->client_cert_path)
6994 if (!ssid->private_key_path)
6997 if (!ssid->private_key_passphrase)
7000 if (ssid->ca_cert_path)
7001 supplicant_dbus_dict_append_basic(dict, "ca_cert",
7002 DBUS_TYPE_STRING, &ssid->ca_cert_path);
7004 supplicant_dbus_dict_append_basic(dict, "private_key",
7006 &ssid->private_key_path);
7007 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
7009 &ssid->private_key_passphrase);
7010 supplicant_dbus_dict_append_basic(dict, "client_cert",
7012 &ssid->client_cert_path);
7015 static void add_network_security_peap(DBusMessageIter *dict,
7016 GSupplicantSSID *ssid)
7021 * For PEAP/TTLS, we at least need
7022 * The authority certificate
7023 * The 2nd phase authentication method
7024 * The 2nd phase passphrase
7026 * The Client certificate is optional although strongly recommended
7027 * When setting it, we need in addition
7028 * The Client private key file
7029 * The Client private key file password
7031 if (!ssid->passphrase)
7034 if (!ssid->phase2_auth)
7037 if (ssid->client_cert_path) {
7038 if (!ssid->private_key_path)
7041 #if !defined TIZEN_EXT
7042 if (!ssid->private_key_passphrase)
7046 supplicant_dbus_dict_append_basic(dict, "client_cert",
7048 &ssid->client_cert_path);
7050 supplicant_dbus_dict_append_basic(dict, "private_key",
7052 &ssid->private_key_path);
7054 #if !defined TIZEN_EXT
7055 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
7057 &ssid->private_key_passphrase);
7062 if(g_strcmp0(ssid->phase2_auth, "GTC") == 0 && g_strcmp0(ssid->eap, "ttls") == 0)
7063 phase2_auth = g_strdup_printf("autheap=%s", ssid->phase2_auth);
7064 else if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
7065 phase2_auth = g_strdup_printf("autheap=%s",
7066 ssid->phase2_auth + strlen("EAP-"));
7068 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
7070 supplicant_dbus_dict_append_basic(dict, "password",
7074 if (ssid->ca_cert_path)
7075 supplicant_dbus_dict_append_basic(dict, "ca_cert",
7077 &ssid->ca_cert_path);
7079 supplicant_dbus_dict_append_basic(dict, "phase2",
7083 g_free(phase2_auth);
7086 #if defined TIZEN_EXT
7087 static void add_network_security_aka_sim(DBusMessageIter *dict,
7088 GSupplicantSSID *ssid)
7090 if (!ssid->passphrase)
7093 supplicant_dbus_dict_append_basic(dict, "password",
7098 static void add_network_security_fast(DBusMessageIter *dict,
7099 GSupplicantSSID *ssid)
7102 * For FAST, we at least need:
7104 * phase1 (provisiong information)
7108 /* Allow provisioing both authenticated and unauthenticated */
7109 const char *phase1 = "fast_provisioning=2";
7110 supplicant_dbus_dict_append_basic(dict, "phase1",
7114 SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
7116 supplicant_dbus_dict_append_basic(dict, "pac_file",
7120 supplicant_dbus_dict_append_basic(dict, "password",
7126 static void add_network_security_eap(DBusMessageIter *dict,
7127 GSupplicantSSID *ssid)
7131 #if defined TIZEN_EXT
7134 if (!ssid->eap || !ssid->identity)
7138 if (g_strcmp0(ssid->eap, "tls") == 0) {
7139 add_network_security_tls(dict, ssid);
7140 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
7141 g_strcmp0(ssid->eap, "ttls") == 0) {
7142 #if defined TIZEN_EXT
7143 if (!ssid->identity)
7146 add_network_security_peap(dict, ssid);
7148 #if defined TIZEN_EXT
7149 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
7150 g_strcmp0(ssid->eap, "aka") == 0 ||
7151 g_strcmp0(ssid->eap, "aka'") == 0) {
7152 add_network_security_aka_sim(dict, ssid);
7153 } else if (g_strcmp0(ssid->eap, "pwd") == 0) {
7154 if(!ssid->passphrase)
7156 supplicant_dbus_dict_append_basic(dict, "password",
7159 } else if (g_strcmp0(ssid->eap, "fast") == 0){
7160 if (!ssid->identity || !ssid->passphrase)
7163 add_network_security_fast(dict, ssid);
7168 eap_value = g_ascii_strup(ssid->eap, -1);
7170 supplicant_dbus_dict_append_basic(dict, "eap",
7173 #if defined TIZEN_EXT
7174 if (ssid->identity != NULL)
7175 supplicant_dbus_dict_append_basic(dict, "identity",
7179 supplicant_dbus_dict_append_basic(dict, "identity",
7183 if(ssid->anonymous_identity)
7184 supplicant_dbus_dict_append_basic(dict, "anonymous_identity",
7186 &ssid->anonymous_identity);
7188 if(ssid->subject_match)
7189 supplicant_dbus_dict_append_basic(dict, "subject_match",
7191 &ssid->subject_match);
7193 if(ssid->altsubject_match)
7194 supplicant_dbus_dict_append_basic(dict, "altsubject_match",
7196 &ssid->altsubject_match);
7198 if(ssid->domain_suffix_match)
7199 supplicant_dbus_dict_append_basic(dict, "domain_suffix_match",
7201 &ssid->domain_suffix_match);
7203 if(ssid->domain_match)
7204 supplicant_dbus_dict_append_basic(dict, "domain_match",
7206 &ssid->domain_match);
7211 static void add_network_security_ciphers(DBusMessageIter *dict,
7212 GSupplicantSSID *ssid)
7214 unsigned int p_cipher, g_cipher, i;
7215 char *pairwise, *group;
7216 char *pair_ciphers[4];
7217 char *group_ciphers[5];
7219 p_cipher = ssid->pairwise_cipher;
7220 g_cipher = ssid->group_cipher;
7222 if (p_cipher == 0 && g_cipher == 0)
7227 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
7228 pair_ciphers[i++] = "CCMP";
7230 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
7231 pair_ciphers[i++] = "TKIP";
7233 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
7234 pair_ciphers[i++] = "NONE";
7236 pair_ciphers[i] = NULL;
7240 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
7241 group_ciphers[i++] = "CCMP";
7243 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
7244 group_ciphers[i++] = "TKIP";
7246 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
7247 group_ciphers[i++] = "WEP104";
7249 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
7250 group_ciphers[i++] = "WEP40";
7252 group_ciphers[i] = NULL;
7254 pairwise = g_strjoinv(" ", pair_ciphers);
7255 group = g_strjoinv(" ", group_ciphers);
7257 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
7259 supplicant_dbus_dict_append_basic(dict, "pairwise",
7262 supplicant_dbus_dict_append_basic(dict, "group",
7270 static void add_network_security_proto(DBusMessageIter *dict,
7271 GSupplicantSSID *ssid)
7273 unsigned int protocol, i;
7277 protocol = ssid->protocol;
7284 if (protocol & G_SUPPLICANT_PROTO_RSN)
7285 protos[i++] = "RSN";
7287 if (protocol & G_SUPPLICANT_PROTO_WPA)
7288 protos[i++] = "WPA";
7292 proto = g_strjoinv(" ", protos);
7294 SUPPLICANT_DBG("proto %s", proto);
7296 supplicant_dbus_dict_append_basic(dict, "proto",
7303 #if defined TIZEN_EXT
7304 static void add_network_security_connector(DBusMessageIter *dict, GSupplicantSSID *ssid)
7306 if (ssid->connector && strlen(ssid->connector) > 0) {
7307 const char *key = "dpp_connector";
7309 supplicant_dbus_dict_append_basic(dict,
7310 key, DBUS_TYPE_STRING,
7315 static size_t convert_hexstr_to_bin(const char *hex_str, unsigned char **bin)
7317 unsigned char *bin_res = NULL;
7318 unsigned int i, j, hex;
7321 if (!hex_str || strlen(hex_str) == 0)
7324 hex_str_len = strlen(hex_str);
7325 bin_res = g_try_malloc0(hex_str_len / 2);
7330 for (i = 0; i < hex_str_len; i+=2) {
7331 sscanf(hex_str + i, "%02x", &hex);
7336 return hex_str_len / 2;
7339 static void add_network_security_c_sign_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7341 if (ssid->c_sign_key && strlen(ssid->c_sign_key) > 0) {
7342 const char *key = "dpp_csign";
7343 unsigned char *bin_csign = NULL;
7344 size_t bin_csign_len = convert_hexstr_to_bin(ssid->c_sign_key, &bin_csign);
7345 if (bin_csign_len != 0)
7346 supplicant_dbus_dict_append_fixed_array(dict,
7347 key, DBUS_TYPE_BYTE,
7348 &bin_csign, bin_csign_len);
7353 static void add_network_security_net_access_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7355 if (ssid->net_access_key && strlen(ssid->net_access_key) > 0) {
7356 const char *key = "dpp_netaccesskey";
7357 unsigned char *bin_netaccesskey = NULL;
7358 size_t bin_netaccesskey_len = convert_hexstr_to_bin(ssid->net_access_key, &bin_netaccesskey);
7359 if (bin_netaccesskey_len != 0)
7360 supplicant_dbus_dict_append_fixed_array(dict,
7361 key, DBUS_TYPE_BYTE,
7362 &bin_netaccesskey, bin_netaccesskey_len);
7363 g_free(bin_netaccesskey);
7369 static void add_network_ieee80211w(DBusMessageIter *dict, GSupplicantSSID *ssid,
7370 GSupplicantMfpOptions ieee80211w)
7372 #if defined TIZEN_EXT
7373 if (ssid->security != G_SUPPLICANT_SECURITY_OWE
7374 && ssid->security != G_SUPPLICANT_SECURITY_PSK_SHA256
7375 && ssid->security != G_SUPPLICANT_SECURITY_DPP)
7378 supplicant_dbus_dict_append_basic(dict, "ieee80211w", DBUS_TYPE_UINT32,
7382 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
7384 GSupplicantMfpOptions ieee80211w;
7387 switch (ssid->security) {
7388 case G_SUPPLICANT_SECURITY_NONE:
7390 add_network_security_none(dict);
7391 add_network_security_ciphers(dict, ssid);
7393 case G_SUPPLICANT_SECURITY_UNKNOWN:
7394 case G_SUPPLICANT_SECURITY_WEP:
7396 add_network_security_wep(dict, ssid);
7397 add_network_security_ciphers(dict, ssid);
7399 case G_SUPPLICANT_SECURITY_PSK:
7400 #if defined TIZEN_EXT
7401 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
7402 key_mgmt = "FT-PSK WPA-PSK";
7404 key_mgmt = "WPA-PSK";
7406 key_mgmt = "WPA-PSK";
7408 add_network_security_psk(dict, ssid);
7409 add_network_security_ciphers(dict, ssid);
7410 add_network_security_proto(dict, ssid);
7412 case G_SUPPLICANT_SECURITY_IEEE8021X:
7413 key_mgmt = "WPA-EAP";
7414 add_network_security_eap(dict, ssid);
7415 add_network_security_ciphers(dict, ssid);
7416 add_network_security_proto(dict, ssid);
7418 #if defined TIZEN_EXT
7419 case G_SUPPLICANT_SECURITY_PSK_SHA256:
7420 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK)
7421 key_mgmt = "WPA-PSK-SHA256 WPA-PSK";
7423 key_mgmt = "WPA-PSK-SHA256";
7424 add_network_security_psk(dict, ssid);
7425 add_network_security_ciphers(dict, ssid);
7426 add_network_security_proto(dict, ssid);
7428 case G_SUPPLICANT_SECURITY_FT_PSK:
7429 key_mgmt = "FT-PSK";
7430 add_network_security_psk(dict, ssid);
7431 add_network_security_ciphers(dict, ssid);
7432 add_network_security_proto(dict, ssid);
7434 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
7435 key_mgmt = "FT-EAP";
7436 add_network_security_eap(dict, ssid);
7437 add_network_security_ciphers(dict, ssid);
7438 add_network_security_proto(dict, ssid);
7440 case G_SUPPLICANT_SECURITY_SAE:
7441 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_FT_SAE) {
7442 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
7443 key_mgmt = "FT-SAE SAE";
7445 key_mgmt = "FT-SAE";
7447 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK) {
7448 key_mgmt = "SAE WPA-PSK";
7449 ieee80211w = G_SUPPLICANT_MFP_OPTIONAL;
7452 ieee80211w = G_SUPPLICANT_MFP_REQUIRED;
7454 add_network_ieee80211w(dict, ssid, ieee80211w);
7456 add_network_security_psk(dict, ssid);
7458 case G_SUPPLICANT_SECURITY_OWE:
7460 add_network_security_ciphers(dict, ssid);
7461 add_network_security_proto(dict, ssid);
7463 case G_SUPPLICANT_SECURITY_DPP:
7465 add_network_security_connector(dict, ssid);
7466 add_network_security_c_sign_key(dict, ssid);
7467 add_network_security_net_access_key(dict, ssid);
7472 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
7473 DBUS_TYPE_STRING, &key_mgmt);
7476 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
7480 switch (ssid->mode) {
7481 case G_SUPPLICANT_MODE_UNKNOWN:
7482 case G_SUPPLICANT_MODE_INFRA:
7485 case G_SUPPLICANT_MODE_IBSS:
7488 case G_SUPPLICANT_MODE_MASTER:
7491 #if defined TIZEN_EXT_WIFI_MESH
7492 case G_SUPPLICANT_MODE_MESH:
7498 supplicant_dbus_dict_append_basic(dict, "mode",
7499 DBUS_TYPE_UINT32, &mode);
7502 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
7504 DBusMessageIter dict;
7505 struct interface_connect_data *data = user_data;
7506 GSupplicantSSID *ssid = data->ssid;
7507 #if defined TIZEN_EXT
7508 GSupplicantInterface *interface = data->interface;
7511 supplicant_dbus_dict_open(iter, &dict);
7513 if (ssid->scan_ssid)
7514 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
7515 DBUS_TYPE_UINT32, &ssid->scan_ssid);
7518 supplicant_dbus_dict_append_basic(&dict, "frequency",
7519 DBUS_TYPE_UINT32, &ssid->freq);
7522 supplicant_dbus_dict_append_basic(&dict, "bgscan",
7523 DBUS_TYPE_STRING, &ssid->bgscan);
7525 add_network_mode(&dict, ssid);
7527 add_network_security(&dict, ssid);
7529 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
7530 DBUS_TYPE_BYTE, &ssid->ssid,
7533 #if defined TIZEN_EXT
7534 bool owe_transition_mode = FALSE;
7535 if ((ssid->security == G_SUPPLICANT_SECURITY_OWE) && !(ssid->keymgmt & G_SUPPLICANT_KEYMGMT_OWE))
7536 owe_transition_mode = TRUE;
7538 if (ssid->bssid && !owe_transition_mode) {
7540 bssid = g_try_malloc0(18);
7541 if (bssid == NULL) {
7542 SUPPLICANT_DBG("memory allocation error");
7543 supplicant_dbus_dict_close(iter, &dict);
7547 if (ssid->bssid_for_connect_len) {
7548 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid_for_connect));
7549 memcpy(interface->add_network_bssid, ssid->bssid_for_connect, WIFI_BSSID_LEN_MAX);
7551 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid));
7552 memcpy(interface->add_network_bssid, ssid->bssid, WIFI_BSSID_LEN_MAX);
7555 SUPPLICANT_DBG("bssid [" MACSTR "]", MAC2STR(interface->add_network_bssid));
7557 supplicant_dbus_dict_append_basic(&dict, "bssid",
7558 DBUS_TYPE_STRING, &bssid);
7563 supplicant_dbus_dict_close(iter, &dict);
7566 static void interface_wps_start_result(const char *error,
7567 DBusMessageIter *iter, void *user_data)
7569 struct interface_connect_data *data = user_data;
7576 SUPPLICANT_DBG("error: %s", error);
7577 err = parse_supplicant_error(iter);
7581 data->callback(err, data->interface, data->user_data);
7588 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
7590 struct interface_connect_data *data = user_data;
7591 GSupplicantSSID *ssid = data->ssid;
7592 const char *role = "enrollee", *type;
7593 DBusMessageIter dict;
7597 supplicant_dbus_dict_open(iter, &dict);
7599 supplicant_dbus_dict_append_basic(&dict, "Role",
7600 DBUS_TYPE_STRING, &role);
7603 if (ssid->pin_wps) {
7605 supplicant_dbus_dict_append_basic(&dict, "Pin",
7606 DBUS_TYPE_STRING, &ssid->pin_wps);
7609 supplicant_dbus_dict_append_basic(&dict, "Type",
7610 DBUS_TYPE_STRING, &type);
7612 #if defined TIZEN_EXT
7614 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
7615 DBUS_TYPE_BYTE, &ssid->bssid, 6);
7618 supplicant_dbus_dict_close(iter, &dict);
7621 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
7623 struct interface_connect_data *data = user_data;
7628 SUPPLICANT_DBG("error: %s", error);
7635 #if defined TIZEN_EXT
7636 GSupplicantSSID *ssid = data->ssid;
7637 if (ssid->pin_wps != NULL) {
7638 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
7639 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
7646 supplicant_dbus_method_call(data->interface->path,
7647 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
7648 interface_add_wps_params,
7649 interface_wps_start_result, data, NULL);
7652 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
7654 dbus_bool_t credentials = TRUE;
7658 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
7662 #if defined TIZEN_EXT
7663 #define NETCONFIG_SERVICE "net.netconfig"
7664 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
7665 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
7667 struct dec_method_call_data {
7668 struct interface_connect_data *data;
7669 DBusPendingCall *pending_call;
7672 static struct dec_method_call_data decrypt_request_data;
7674 static void crypt_method_call_cancel(void)
7676 if (decrypt_request_data.pending_call) {
7677 dbus_pending_call_cancel(decrypt_request_data.pending_call);
7678 dbus_pending_call_unref(decrypt_request_data.pending_call);
7679 decrypt_request_data.pending_call = NULL;
7682 g_free(decrypt_request_data.data->path);
7683 g_free(decrypt_request_data.data->ssid);
7684 dbus_free(decrypt_request_data.data);
7685 decrypt_request_data.data = NULL;
7688 static void decryption_request_reply(DBusPendingCall *call,
7693 DBusMessageIter args;
7696 struct interface_connect_data *data = user_data;
7700 reply = dbus_pending_call_steal_reply(call);
7702 dbus_error_init(&error);
7703 if (dbus_set_error_from_message(&error, reply)) {
7704 SUPPLICANT_DBG("decryption_request_reply() %s %s", error.name, error.message);
7705 dbus_error_free(&error);
7710 if (!g_str_has_prefix(data->interface->path, "/")) {
7711 SUPPLICANT_DBG("Invalid path %s", data->interface->path);
7716 if (dbus_message_iter_init(reply, &args) == FALSE) {
7717 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7722 dbus_message_iter_get_basic(&args, &out_data);
7723 data->ssid->passphrase = g_strdup((const gchar *)out_data);
7724 data->ssid->is_passphrase_alloc = true;
7726 ret = supplicant_dbus_method_call(data->interface->path,
7727 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7728 interface_add_network_params,
7729 interface_add_network_result, data,
7734 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7735 callback_assoc_failed(decrypt_request_data.data->user_data);
7737 g_free(data->ssid->ssid);
7738 if (data->ssid->is_passphrase_alloc)
7739 g_free((char *)data->ssid->passphrase);
7740 if (data->ssid->is_connector_alloc)
7741 g_free((char *)data->ssid->connector);
7742 if (data->ssid->is_c_sign_key_alloc)
7743 g_free((char *)data->ssid->c_sign_key);
7744 if (data->ssid->is_net_access_key_alloc)
7745 g_free((char *)data->ssid->net_access_key);
7750 dbus_message_unref(reply);
7751 dbus_pending_call_unref(call);
7753 decrypt_request_data.pending_call = NULL;
7754 decrypt_request_data.data = NULL;
7757 static int send_decryption_request(const char *passphrase,
7758 struct interface_connect_data *data)
7760 DBusMessage *msg = NULL;
7761 DBusPendingCall *call;
7763 SUPPLICANT_DBG("Decryption request");
7766 SUPPLICANT_DBG("Invalid parameter");
7773 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7774 NETCONFIG_WIFI_INTERFACE, "DecryptPassphrase");
7778 #if defined TIZEN_EXT
7779 if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7780 DBUS_TYPE_INVALID)) {
7781 SUPPLICANT_DBG("Could not fulfill decryption request");
7785 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7789 if (!dbus_connection_send_with_reply(connection, msg,
7790 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7791 dbus_message_unref(msg);
7796 dbus_message_unref(msg);
7800 decrypt_request_data.pending_call = call;
7801 decrypt_request_data.data = data;
7803 dbus_pending_call_set_notify(call, decryption_request_reply, data, NULL);
7804 dbus_message_unref(msg);
7806 SUPPLICANT_DBG("Decryption request succeeded");
7811 static void decrypt_conf_obj_reply(DBusPendingCall *call,
7816 DBusMessageIter iter, dict;
7819 struct interface_connect_data *data = user_data;
7821 reply = dbus_pending_call_steal_reply(call);
7823 dbus_error_init(&error);
7824 if (dbus_set_error_from_message(&error, reply)) {
7825 SUPPLICANT_DBG("decryption_conf_obj_reply() %s %s", error.name, error.message);
7826 dbus_error_free(&error);
7831 if (dbus_message_iter_init(reply, &iter) == FALSE) {
7832 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7837 dbus_message_iter_recurse(&iter, &dict);
7839 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
7840 DBusMessageIter entry, value;
7843 dbus_message_iter_recurse(&dict, &entry);
7844 dbus_message_iter_get_basic(&entry, &key);
7845 dbus_message_iter_next(&entry);
7846 dbus_message_iter_recurse(&entry, &value);
7847 if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
7848 if (g_strcmp0(key, "connector") == 0) {
7849 dbus_message_iter_get_basic(&value, &out_data);
7850 data->ssid->connector = g_strdup((const gchar *)out_data);
7851 data->ssid->is_connector_alloc = true;
7852 SUPPLICANT_DBG("connector %s", data->ssid->connector);
7853 } else if (g_strcmp0(key, "c_sign_key") == 0) {
7854 dbus_message_iter_get_basic(&value, &out_data);
7855 data->ssid->c_sign_key = g_strdup((const gchar *)out_data);
7856 data->ssid->is_c_sign_key_alloc = true;
7857 SUPPLICANT_DBG("c_sign_key %s", data->ssid->c_sign_key);
7858 } else if (g_strcmp0(key, "net_access_key") == 0) {
7859 dbus_message_iter_get_basic(&value, &out_data);
7860 data->ssid->net_access_key = g_strdup((const gchar *)out_data);
7861 data->ssid->is_net_access_key_alloc = true;
7862 SUPPLICANT_DBG("net_access_key %s", data->ssid->net_access_key);
7865 dbus_message_iter_next(&dict);
7868 ret = supplicant_dbus_method_call(data->interface->path,
7869 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7870 interface_add_network_params,
7871 interface_add_network_result, data,
7876 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7877 callback_assoc_failed(decrypt_request_data.data->user_data);
7879 g_free(data->ssid->ssid);
7880 if (data->ssid->is_connector_alloc)
7881 g_free((char *)data->ssid->connector);
7882 if (data->ssid->is_c_sign_key_alloc)
7883 g_free((char *)data->ssid->c_sign_key);
7884 if (data->ssid->is_net_access_key_alloc)
7885 g_free((char *)data->ssid->net_access_key);
7890 dbus_message_unref(reply);
7891 dbus_pending_call_unref(call);
7893 decrypt_request_data.pending_call = NULL;
7894 decrypt_request_data.data = NULL;
7897 static int send_decryption_conf_obj_request(GSupplicantSSID *ssid,
7898 struct interface_connect_data *data)
7900 DBusMessage *msg = NULL;
7901 DBusPendingCall *call;
7903 SUPPLICANT_DBG("Decryption configuration object request");
7906 SUPPLICANT_DBG("Invalid parameter");
7913 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7914 NETCONFIG_WIFI_INTERFACE, "DecryptConfObj");
7918 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->connector,
7920 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->c_sign_key,
7922 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->net_access_key,
7925 if (!dbus_connection_send_with_reply(connection, msg,
7926 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7927 dbus_message_unref(msg);
7932 dbus_message_unref(msg);
7936 decrypt_request_data.pending_call = call;
7937 decrypt_request_data.data = data;
7939 dbus_pending_call_set_notify(call, decrypt_conf_obj_reply, data, NULL);
7940 dbus_message_unref(msg);
7942 SUPPLICANT_DBG("Decrypt Conf Obj request succeeded");
7947 static bool is_valid_config_object(GSupplicantSSID *ssid)
7949 return ((ssid->connector &&
7950 g_strcmp0(ssid->connector, "") != 0) &&
7951 (ssid->c_sign_key &&
7952 g_strcmp0(ssid->c_sign_key, "") != 0) &&
7953 (ssid->net_access_key &&
7954 g_strcmp0(ssid->net_access_key, "") != 0));
7958 int g_supplicant_interface_connect(GSupplicantInterface *interface,
7959 GSupplicantSSID *ssid,
7960 GSupplicantInterfaceCallback callback,
7963 struct interface_connect_data *data;
7964 struct interface_data *intf_data;
7972 if (!system_available)
7975 /* TODO: Check if we're already connected and switch */
7977 data = dbus_malloc0(sizeof(*data));
7981 data->interface = interface;
7982 data->path = g_strdup(interface->path);
7983 data->callback = callback;
7985 data->user_data = user_data;
7987 if (ssid->use_wps) {
7988 g_free(interface->wps_cred.key);
7989 memset(&interface->wps_cred, 0,
7990 sizeof(struct _GSupplicantWpsCredentials));
7992 ret = supplicant_dbus_property_set(interface->path,
7993 SUPPLICANT_INTERFACE ".Interface.WPS",
7994 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
7995 wps_process_credentials, wps_start, data, interface);
7997 /* By the time there is a request for connect and the network
7998 * path is not NULL it means that connman has not removed the
7999 * previous network pointer. This can happen in the case AP
8000 * deauthenticated client and connman does not remove the
8001 * previously connected network pointer. This causes supplicant
8002 * to reallocate the memory for struct wpa_ssid again even if it
8003 * is the same SSID. This causes memory usage of wpa_supplicnat
8004 * to go high. The idea here is that if the previously connected
8005 * network is not removed at the time of next connection attempt
8006 * check if the network path is not NULL. In case it is non-NULL
8007 * first remove the network and then once removal is successful, add
8011 if (interface->network_path != NULL) {
8016 * If this add network is for the same network for
8017 * which wpa_supplicant already has a profile then do
8018 * not need to add another profile. Only if the
8019 * profile that needs to get added is different from
8020 * what is there in wpa_s delete the current one. A
8021 * network is identified by its SSID, security_type
8022 * and passphrase (private passphrase in case security
8025 if (compare_network_parameters(interface, ssid)) {
8029 intf_data = dbus_malloc0(sizeof(*intf_data));
8033 intf_data->interface = interface;
8034 intf_data->path = g_strdup(interface->path);
8035 intf_data->callback = callback;
8036 intf_data->ssid = ssid;
8037 intf_data->user_data = user_data;
8038 intf_data->network_remove_in_progress = TRUE;
8039 network_remove(intf_data);
8041 #if defined TIZEN_EXT
8042 if (ssid->passphrase &&
8043 g_strcmp0(ssid->passphrase, "") != 0 &&
8044 #if defined TIZEN_EXT_WIFI_MESH
8045 ssid->mode != G_SUPPLICANT_MODE_MESH &&
8048 ret = send_decryption_request(ssid->passphrase, data);
8050 SUPPLICANT_DBG("Decryption request failed %d", ret);
8051 } else if (is_valid_config_object(ssid)) {
8052 ret = send_decryption_conf_obj_request(ssid, data);
8054 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
8058 ret = supplicant_dbus_method_call(interface->path,
8059 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
8060 interface_add_network_params,
8061 interface_add_network_result, data,
8072 return -EINPROGRESS;
8075 static void network_remove_result(const char *error,
8076 DBusMessageIter *iter, void *user_data)
8078 struct interface_data *data = user_data;
8079 struct interface_connect_data *connect_data;
8086 SUPPLICANT_DBG("error: %s", error);
8088 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
8090 result = -ECONNABORTED;
8093 g_free(data->interface->network_path);
8094 data->interface->network_path = NULL;
8096 remove_network_information(data->interface);
8098 if (data->network_remove_in_progress == TRUE) {
8099 data->network_remove_in_progress = FALSE;
8100 connect_data = dbus_malloc0(sizeof(*connect_data));
8104 connect_data->interface = data->interface;
8105 connect_data->path = g_strdup(data->path);
8106 connect_data->callback = data->callback;
8107 connect_data->ssid = data->ssid;
8108 connect_data->user_data = data->user_data;
8110 #if defined TIZEN_EXT
8112 if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
8113 && !data->ssid->eap) {
8114 ret = send_decryption_request(data->ssid->passphrase, connect_data);
8116 SUPPLICANT_DBG("Decryption request failed %d", ret);
8117 g_free(connect_data->ssid);
8118 g_free(connect_data->path);
8119 dbus_free(connect_data);
8121 } else if (is_valid_config_object(data->ssid)) {
8122 ret = send_decryption_conf_obj_request(data->ssid, connect_data);
8124 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
8125 g_free(connect_data->ssid);
8126 g_free(connect_data->path);
8127 dbus_free(connect_data);
8131 supplicant_dbus_method_call(data->interface->path,
8132 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
8133 interface_add_network_params,
8134 interface_add_network_result, connect_data,
8135 connect_data->interface);
8138 data->callback(result, data->interface, data->user_data);
8144 static void network_remove_params(DBusMessageIter *iter, void *user_data)
8146 struct interface_data *data = user_data;
8147 const char *path = data->interface->network_path;
8149 SUPPLICANT_DBG("path %s", path);
8151 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
8154 static int network_remove(struct interface_data *data)
8156 GSupplicantInterface *interface = data->interface;
8160 #if defined TIZEN_EXT
8161 GSupplicantInterface *intf = NULL;
8163 * Check if 'interface' is valid
8165 intf = g_hash_table_lookup(interface_table, interface->path);
8170 return supplicant_dbus_method_call(interface->path,
8171 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
8172 network_remove_params, network_remove_result, data,
8176 static void interface_disconnect_result(const char *error,
8177 DBusMessageIter *iter, void *user_data)
8179 struct interface_data *data = user_data;
8186 SUPPLICANT_DBG("error: %s", error);
8188 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
8190 result = -ECONNABORTED;
8193 /* If we are disconnecting from previous WPS successful
8194 * association. i.e.: it did not went through AddNetwork,
8195 * and interface->network_path was never set. */
8196 if (!data->interface->network_path) {
8198 data->callback(result, data->interface,
8206 if (result < 0 && data->callback) {
8207 data->callback(result, data->interface, data->user_data);
8208 data->callback = NULL;
8211 if (result != -ECONNABORTED) {
8212 if (network_remove(data) < 0) {
8222 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
8223 GSupplicantInterfaceCallback callback,
8226 struct interface_data *data;
8234 if (!system_available)
8236 #if defined TIZEN_EXT
8237 if (decrypt_request_data.pending_call &&
8238 decrypt_request_data.data &&
8239 decrypt_request_data.data->user_data == user_data) {
8241 callback_assoc_failed(decrypt_request_data.data->user_data);
8242 crypt_method_call_cancel();
8247 data = dbus_malloc0(sizeof(*data));
8251 data->interface = interface;
8252 data->path = g_strdup(interface->path);
8253 data->callback = callback;
8254 data->user_data = user_data;
8256 ret = supplicant_dbus_method_call(interface->path,
8257 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
8258 NULL, interface_disconnect_result, data,
8269 #if defined TIZEN_EXT
8270 void g_supplicant_interface_remove_network(GSupplicantInterface *interface,
8271 GSupplicantSSID *ssid)
8273 struct interface_data *data;
8281 if (interface->network_path == NULL)
8284 if (!interface->network_info.ssid)
8287 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
8290 if (interface->network_info.security != ssid->security)
8293 data = dbus_malloc0(sizeof(*data));
8297 data->interface = interface;
8298 data->path = g_strdup(interface->path);
8300 ret = supplicant_dbus_method_call(interface->path,
8301 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
8302 network_remove_params, network_remove_result, data,
8312 static void interface_p2p_find_result(const char *error,
8313 DBusMessageIter *iter, void *user_data)
8315 struct interface_scan_data *data = user_data;
8318 SUPPLICANT_DBG("error %s", error);
8323 if (interface_exists(data->interface, data->path)) {
8324 if (!data->interface->ready)
8327 data->interface->p2p_finding = true;
8331 data->callback(err, data->interface, data->user_data);
8337 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
8339 DBusMessageIter dict;
8341 supplicant_dbus_dict_open(iter, &dict);
8342 supplicant_dbus_dict_close(iter, &dict);
8345 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
8346 GSupplicantInterfaceCallback callback,
8349 struct interface_scan_data *data;
8352 if (!interface->p2p_support)
8355 ret = interface_ready_to_scan(interface);
8356 if (ret && ret != -EALREADY)
8359 data = dbus_malloc0(sizeof(*data));
8363 data->interface = interface;
8364 data->path = g_strdup(interface->path);
8365 data->callback = callback;
8366 data->user_data = user_data;
8368 ret = supplicant_dbus_method_call(interface->path,
8369 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
8370 interface_p2p_find_params, interface_p2p_find_result,
8380 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
8385 return interface->p2p_finding;
8388 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
8390 if (!interface->p2p_finding)
8395 interface->p2p_finding = false;
8397 return supplicant_dbus_method_call(interface->path,
8398 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
8399 NULL, NULL, NULL, NULL);
8402 static void interface_p2p_connect_result(const char *error,
8403 DBusMessageIter *iter, void *user_data)
8405 struct interface_connect_data *data = user_data;
8411 SUPPLICANT_DBG("error: %s", error);
8412 err = parse_supplicant_error(iter);
8416 data->callback(err, data->interface, data->user_data);
8419 g_free(data->peer->wps_pin);
8420 g_free(data->peer->path);
8425 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
8427 struct interface_connect_data *data = user_data;
8428 const char *wps = "pbc";
8429 DBusMessageIter dict;
8434 supplicant_dbus_dict_open(iter, &dict);
8436 if (data->peer->master)
8439 if (data->peer->wps_pin)
8442 supplicant_dbus_dict_append_basic(&dict, "peer",
8443 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
8444 supplicant_dbus_dict_append_basic(&dict, "wps_method",
8445 DBUS_TYPE_STRING, &wps);
8446 if (data->peer->wps_pin) {
8447 supplicant_dbus_dict_append_basic(&dict, "pin",
8448 DBUS_TYPE_STRING, &data->peer->wps_pin);
8451 supplicant_dbus_dict_append_basic(&dict, "go_intent",
8452 DBUS_TYPE_INT32, &go_intent);
8454 supplicant_dbus_dict_close(iter, &dict);
8457 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
8458 GSupplicantPeerParams *peer_params,
8459 GSupplicantInterfaceCallback callback,
8462 struct interface_connect_data *data;
8467 if (!interface->p2p_support)
8470 data = dbus_malloc0(sizeof(*data));
8474 data->interface = interface;
8475 data->path = g_strdup(interface->path);
8476 data->peer = peer_params;
8477 data->callback = callback;
8478 data->user_data = user_data;
8480 ret = supplicant_dbus_method_call(interface->path,
8481 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
8482 interface_p2p_connect_params, interface_p2p_connect_result,
8490 return -EINPROGRESS;
8493 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
8494 GSupplicantPeerParams *peer_params)
8496 GSupplicantPeer *peer;
8502 if (!interface->p2p_support)
8505 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
8509 for (list = peer->groups; list; list = list->next, count++) {
8510 const char *group_obj_path = list->data;
8511 GSupplicantInterface *g_interface;
8512 GSupplicantGroup *group;
8514 group = g_hash_table_lookup(group_mapping, group_obj_path);
8515 if (!group || !group->interface)
8518 g_interface = group->interface;
8519 supplicant_dbus_method_call(g_interface->path,
8520 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8521 "Disconnect", NULL, NULL, NULL, g_interface);
8524 if (count == 0 && peer->current_group_iface) {
8525 supplicant_dbus_method_call(peer->current_group_iface->path,
8526 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8527 "Disconnect", NULL, NULL, NULL,
8528 peer->current_group_iface->path);
8531 peer->current_group_iface = NULL;
8533 return -EINPROGRESS;
8536 struct p2p_service_data {
8538 GSupplicantInterface *interface;
8539 GSupplicantP2PServiceParams *service;
8540 GSupplicantInterfaceCallback callback;
8544 static void interface_p2p_service_result(const char *error,
8545 DBusMessageIter *iter, void *user_data)
8547 struct p2p_service_data *data = user_data;
8550 SUPPLICANT_DBG("%s result - %s", data->registration ?
8551 "Registration" : "Deletion",
8552 error ? error : "Success");
8557 data->callback(result, data->interface, data->user_data);
8559 g_free(data->service->query);
8560 g_free(data->service->response);
8561 g_free(data->service->service);
8562 g_free(data->service->wfd_ies);
8563 g_free(data->service);
8567 static void interface_p2p_service_params(DBusMessageIter *iter,
8570 struct p2p_service_data *data = user_data;
8571 GSupplicantP2PServiceParams *service;
8572 DBusMessageIter dict;
8577 service = data->service;
8579 supplicant_dbus_dict_open(iter, &dict);
8581 if (service->query && service->response) {
8583 supplicant_dbus_dict_append_basic(&dict, "service_type",
8584 DBUS_TYPE_STRING, &type);
8585 supplicant_dbus_dict_append_fixed_array(&dict, "query",
8586 DBUS_TYPE_BYTE, &service->query,
8587 service->query_length);
8588 supplicant_dbus_dict_append_fixed_array(&dict, "response",
8589 DBUS_TYPE_BYTE, &service->response,
8590 service->response_length);
8591 } else if (service->version && service->service) {
8593 supplicant_dbus_dict_append_basic(&dict, "service_type",
8594 DBUS_TYPE_STRING, &type);
8595 supplicant_dbus_dict_append_basic(&dict, "version",
8596 DBUS_TYPE_INT32, &service->version);
8597 supplicant_dbus_dict_append_basic(&dict, "service",
8598 DBUS_TYPE_STRING, &service->service);
8601 supplicant_dbus_dict_close(iter, &dict);
8604 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
8605 GSupplicantInterfaceCallback callback,
8606 GSupplicantP2PServiceParams *p2p_service_params,
8609 struct p2p_service_data *data;
8614 if (!interface->p2p_support)
8617 data = dbus_malloc0(sizeof(*data));
8621 data->registration = true;
8622 data->interface = interface;
8623 data->service = p2p_service_params;
8624 data->callback = callback;
8625 data->user_data = user_data;
8627 ret = supplicant_dbus_method_call(interface->path,
8628 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
8629 interface_p2p_service_params, interface_p2p_service_result,
8636 return -EINPROGRESS;
8639 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
8640 GSupplicantP2PServiceParams *p2p_service_params)
8642 struct p2p_service_data *data;
8647 if (!interface->p2p_support)
8650 data = dbus_malloc0(sizeof(*data));
8654 data->interface = interface;
8655 data->service = p2p_service_params;
8657 ret = supplicant_dbus_method_call(interface->path,
8658 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
8659 interface_p2p_service_params, interface_p2p_service_result,
8666 return -EINPROGRESS;
8669 struct p2p_listen_data {
8674 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
8676 struct p2p_listen_data *params = user_data;
8677 DBusMessageIter dict;
8679 supplicant_dbus_dict_open(iter, &dict);
8681 supplicant_dbus_dict_append_basic(&dict, "period",
8682 DBUS_TYPE_INT32, ¶ms->period);
8683 supplicant_dbus_dict_append_basic(&dict, "interval",
8684 DBUS_TYPE_INT32, ¶ms->interval);
8685 supplicant_dbus_dict_close(iter, &dict);
8688 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
8689 int period, int interval)
8691 struct p2p_listen_data params;
8695 if (!interface->p2p_support)
8698 params.period = period;
8699 params.interval = interval;
8701 return supplicant_dbus_method_call(interface->path,
8702 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8703 "ExtendedListen", interface_p2p_listen_params,
8704 NULL, ¶ms, NULL);
8707 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
8709 struct p2p_service_data *data = user_data;
8710 GSupplicantP2PServiceParams *service = data->service;
8711 DBusMessageIter array;
8713 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
8715 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
8716 DBUS_TYPE_BYTE_AS_STRING, &array);
8718 if (service->wfd_ies && service->wfd_ies_length > 0) {
8719 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
8720 &service->wfd_ies, service->wfd_ies_length);
8723 dbus_message_iter_close_container(iter, &array);
8726 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
8727 GSupplicantInterfaceCallback callback,
8730 struct p2p_service_data *data;
8735 if (!system_available)
8738 data = dbus_malloc0(sizeof(*data));
8742 data->service = p2p_service_params;
8743 data->callback = callback;
8744 data->user_data = user_data;
8746 if (p2p_service_params->wfd_ies)
8747 data->registration = true;
8749 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
8750 SUPPLICANT_INTERFACE, "WFDIEs",
8751 DBUS_TYPE_ARRAY_AS_STRING
8752 DBUS_TYPE_BYTE_AS_STRING,
8754 interface_p2p_service_result,
8756 if (ret < 0 && ret != -EINPROGRESS) {
8761 return -EINPROGRESS;
8765 static const char *g_supplicant_rule0 = "type=signal,"
8766 "path=" DBUS_PATH_DBUS ","
8767 "sender=" DBUS_SERVICE_DBUS ","
8768 "interface=" DBUS_INTERFACE_DBUS ","
8769 "member=NameOwnerChanged,"
8770 "arg0=" SUPPLICANT_SERVICE;
8771 static const char *g_supplicant_rule1 = "type=signal,"
8772 "interface=" SUPPLICANT_INTERFACE;
8773 static const char *g_supplicant_rule2 = "type=signal,"
8774 "interface=" SUPPLICANT_INTERFACE ".Interface";
8775 static const char *g_supplicant_rule3 = "type=signal,"
8776 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
8777 static const char *g_supplicant_rule4 = "type=signal,"
8778 "interface=" SUPPLICANT_INTERFACE ".BSS";
8779 static const char *g_supplicant_rule5 = "type=signal,"
8780 "interface=" SUPPLICANT_INTERFACE ".Network";
8781 #if !defined TIZEN_EXT
8782 static const char *g_supplicant_rule6 = "type=signal,"
8783 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
8784 static const char *g_supplicant_rule7 = "type=signal,"
8785 "interface=" SUPPLICANT_INTERFACE ".Peer";
8786 static const char *g_supplicant_rule8 = "type=signal,"
8787 "interface=" SUPPLICANT_INTERFACE ".Group";
8789 #if defined TIZEN_EXT_WIFI_MESH
8790 static const char *g_supplicant_rule9 = "type=signal,"
8791 "interface=" SUPPLICANT_INTERFACE ".Interface.Mesh";
8794 static void invoke_introspect_method(void)
8796 DBusMessage *message;
8798 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
8800 DBUS_INTERFACE_INTROSPECTABLE,
8806 dbus_message_set_no_reply(message, TRUE);
8807 dbus_connection_send(connection, message, NULL);
8808 dbus_message_unref(message);
8811 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
8812 void g_supplicant_set_ins_settings(GSupplicantINSPreferredFreq preferred_freq_bssid,
8813 bool last_connected_bssid, bool assoc_reject, bool signal_bssid,
8814 unsigned int preferred_freq_bssid_score, unsigned int last_connected_bssid_score,
8815 unsigned int assoc_reject_score, int signal_level3_5ghz, int signal_level3_24ghz)
8817 ins_settings.preferred_freq_bssid = preferred_freq_bssid;
8818 ins_settings.last_connected_bssid = last_connected_bssid;
8819 ins_settings.assoc_reject = assoc_reject;
8820 ins_settings.signal_bssid = signal_bssid;
8821 ins_settings.preferred_freq_bssid_score = preferred_freq_bssid_score;
8822 ins_settings.last_connected_bssid_score = last_connected_bssid_score;
8823 ins_settings.assoc_reject_score = assoc_reject_score;
8824 ins_settings.signal_level3_5ghz = signal_level3_5ghz;
8825 ins_settings.signal_level3_24ghz = signal_level3_24ghz;
8827 SUPPLICANT_DBG("preferred_freq_bssid [%s]", preferred_freq_bssid ? "true" : "false");
8828 SUPPLICANT_DBG("preferred_freq_bssid_score [%d]", preferred_freq_bssid_score);
8829 SUPPLICANT_DBG("last_connected_bssid [%s]", last_connected_bssid ? "true" : "false");
8830 SUPPLICANT_DBG("last_connected_bssid_score [%d]", last_connected_bssid_score);
8831 SUPPLICANT_DBG("assoc_reject [%s]", assoc_reject ? "true" : "false");
8832 SUPPLICANT_DBG("assoc_reject_score [%d]", assoc_reject_score);
8833 SUPPLICANT_DBG("signal_bssid [%s]", signal_bssid ? "true" : "false");
8834 SUPPLICANT_DBG("signal_level3_5ghz [%d]", signal_level3_5ghz);
8835 SUPPLICANT_DBG("signal_level3_24ghz [%d]", signal_level3_24ghz);
8837 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
8839 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8840 void g_supplicant_register_eap_callback(g_supplicant_eap_callback cb)
8842 SUPPLICANT_DBG("g_supplicant_register_eap_callback %p", cb);
8844 if (!callbacks_pointer) {
8845 SUPPLICANT_DBG("callbacks_pointer is NULL");
8849 callbacks_pointer->eap = cb;
8852 void g_supplicant_unregister_eap_callback(void)
8854 SUPPLICANT_DBG("g_supplicant_unregister_eap_callback");
8856 if (!callbacks_pointer) {
8857 SUPPLICANT_DBG("callbacks_pointer is NULL");
8861 callbacks_pointer->eap = NULL;
8863 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8865 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8866 int g_supplicant_register(GSupplicantCallbacks *callbacks)
8867 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8868 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
8869 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8871 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8875 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
8877 dbus_connection_unref(connection);
8881 #if defined TIZEN_EXT
8882 simplified_log = connman_setting_get_bool("SimplifiedLog");
8884 callbacks_pointer = callbacks;
8887 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8888 NULL, remove_interface);
8890 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8892 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8894 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8896 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
8898 config_file_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8901 supplicant_dbus_setup(connection);
8903 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
8904 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
8905 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
8906 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
8907 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
8908 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
8909 #if defined TIZEN_EXT
8910 dbus_bus_add_match(connection,
8911 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
8912 "member=ChangeState", NULL);
8914 #if !defined TIZEN_EXT
8915 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
8916 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
8917 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
8919 #if defined TIZEN_EXT_WIFI_MESH
8920 dbus_bus_add_match(connection, g_supplicant_rule9, NULL);
8922 dbus_connection_flush(connection);
8924 if (dbus_bus_name_has_owner(connection,
8925 SUPPLICANT_SERVICE, NULL)) {
8926 system_available = TRUE;
8927 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
8928 SUPPLICANT_INTERFACE,
8929 service_property, NULL, NULL);
8931 invoke_introspect_method();
8933 SUPPLICANT_DBG("supplicant dbus setup completed");
8937 static void unregister_interface_remove_params(DBusMessageIter *iter,
8940 const char *path = user_data;
8942 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
8947 static void unregister_remove_interface(gpointer key, gpointer value,
8950 GSupplicantInterface *interface = value;
8952 supplicant_dbus_method_call(SUPPLICANT_PATH,
8953 SUPPLICANT_INTERFACE,
8955 unregister_interface_remove_params,
8956 NULL, interface->path, NULL);
8959 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
8964 #if defined TIZEN_EXT_WIFI_MESH
8965 dbus_bus_remove_match(connection, g_supplicant_rule9, NULL);
8967 #if !defined TIZEN_EXT
8968 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
8969 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
8970 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
8972 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
8973 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
8974 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
8975 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
8976 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
8977 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
8978 dbus_connection_flush(connection);
8980 dbus_connection_remove_filter(connection,
8981 g_supplicant_filter, NULL);
8984 if (config_file_table) {
8985 g_hash_table_destroy(config_file_table);
8986 config_file_table = NULL;
8990 g_hash_table_destroy(bss_mapping);
8995 g_hash_table_destroy(peer_mapping);
8996 peer_mapping = NULL;
8999 if (group_mapping) {
9000 g_hash_table_destroy(group_mapping);
9001 group_mapping = NULL;
9004 if (interface_table) {
9005 g_hash_table_foreach(interface_table,
9006 unregister_remove_interface, NULL);
9007 g_hash_table_destroy(interface_table);
9008 interface_table = NULL;
9011 if (system_available)
9012 callback_system_killed();
9015 dbus_connection_unref(connection);
9019 callbacks_pointer = NULL;
9024 struct supplicant_mac_policy {
9025 GSupplicantMacPolicyCallback callback;
9026 dbus_uint32_t policy;
9027 const void *user_data;
9030 static void mac_policy_result(const char *error,
9031 DBusMessageIter *iter, void *user_data)
9033 struct supplicant_mac_policy *data = user_data;
9040 SUPPLICANT_DBG("Mac policy setting failure %s", error);
9045 data->callback(result, data->policy,
9046 (void *) data->user_data);
9051 static void mac_policy_params(DBusMessageIter *iter, void *user_data)
9053 struct supplicant_mac_policy *data = user_data;
9055 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(data->policy));
9058 int g_supplicant_interface_set_mac_policy(GSupplicantInterface *interface,
9059 GSupplicantMacPolicyCallback callback,
9060 unsigned int policy,
9063 struct supplicant_mac_policy *data = NULL;
9066 if (!system_available)
9072 data = dbus_malloc0(sizeof(*data));
9076 data->callback = callback;
9077 data->policy = policy;
9078 data->user_data = user_data;
9080 ret = supplicant_dbus_property_set(interface->path,
9081 SUPPLICANT_INTERFACE ".Interface",
9082 "MacAddr", DBUS_TYPE_INT32_AS_STRING,
9083 mac_policy_params, mac_policy_result, data, NULL);
9085 SUPPLICANT_DBG("Unable to set MacAddr configuration");
9092 int g_supplicant_interface_set_preassoc_mac_policy(GSupplicantInterface *interface,
9093 GSupplicantMacPolicyCallback callback,
9094 unsigned int policy,
9097 struct supplicant_mac_policy *data;
9100 if (!system_available)
9106 data = dbus_malloc0(sizeof(*data));
9110 data->callback = callback;
9111 data->policy = policy;
9112 data->user_data = user_data;
9114 ret = supplicant_dbus_property_set(interface->path,
9115 SUPPLICANT_INTERFACE ".Interface",
9116 "PreassocMacAddr", DBUS_TYPE_INT32_AS_STRING,
9117 mac_policy_params, mac_policy_result, data, NULL);
9119 SUPPLICANT_DBG("Unable to set PreassocMacAddr configuration");
9126 struct supplicant_random_mac_lifetime {
9127 GSupplicantRandomMaclifetimeCallback callback;
9128 dbus_uint32_t lifetime;
9129 const void *user_data;
9132 static void random_mac_lifetime_result(const char *error,
9133 DBusMessageIter *iter, void *user_data)
9135 struct supplicant_random_mac_lifetime *data = user_data;
9142 SUPPLICANT_DBG("Random Mac lifetime setting failure %s", error);
9147 data->callback(result, data->lifetime,
9148 (void *) data->user_data);
9153 static void random_mac_lifetime_params(DBusMessageIter *iter, void *user_data)
9155 struct supplicant_random_mac_lifetime *data = user_data;
9157 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &(data->lifetime));
9160 int g_supplicant_interface_set_random_mac_lifetime(GSupplicantInterface *interface,
9161 GSupplicantRandomMaclifetimeCallback callback,
9162 unsigned int lifetime,
9165 struct supplicant_random_mac_lifetime *data;
9168 if (!system_available)
9174 data = dbus_malloc0(sizeof(*data));
9178 data->callback = callback;
9179 data->lifetime = lifetime;
9180 data->user_data = user_data;
9182 ret = supplicant_dbus_property_set(interface->path,
9183 SUPPLICANT_INTERFACE ".Interface",
9184 "RandAddrLifetime", DBUS_TYPE_UINT32_AS_STRING,
9185 random_mac_lifetime_params, random_mac_lifetime_result,
9188 SUPPLICANT_DBG("Unable to set RandAddrLifetime configuration");