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->phy_mode = best_bss->phy_mode;
2661 network->best_bss = best_bss;
2664 static bool update_best_bss(GSupplicantNetwork *network,
2665 struct g_supplicant_bss *bss, struct g_supplicant_bss *best_bss)
2670 if (network->best_bss == NULL) {
2671 update_network_with_best_bss(network, bss);
2675 #if defined TIZEN_EXT_INS
2676 score_new = calculate_score(
2677 compare_bssid(bss->bssid, network->last_connected_bssid),
2678 get_assoc_reject_cnt(network->assoc_reject_table, bss->bssid),
2679 bss->frequency, bss->signal, bss->snr, bss->est_throughput);
2681 score_best = calculate_score(
2682 compare_bssid(network->best_bss->bssid, network->last_connected_bssid),
2683 get_assoc_reject_cnt(network->assoc_reject_table, network->best_bss->bssid),
2684 network->best_bss->frequency, network->best_bss->signal,
2685 network->best_bss->snr, network->best_bss->est_throughput);
2687 score_new = bss->signal;
2688 score_best = network->best_bss->signal;
2691 if (score_new > score_best) {
2692 SUPPLICANT_DBG("new[" MACSTR "][%d] : best[" MACSTR "][%d]",
2693 MAC2STR(bss->bssid), score_new,
2694 MAC2STR(network->best_bss->bssid), score_best);
2696 update_network_with_best_bss(network, bss);
2698 SUPPLICANT_DBG("Update best BSS for %s", network->name);
2706 static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
2708 GSupplicantInterface *interface = bss->interface;
2709 GSupplicantNetwork *network;
2711 bool is_new_network;
2713 group = create_group(bss);
2714 SUPPLICANT_DBG("New group created: %s", group);
2719 network = g_hash_table_lookup(interface->network_table, group);
2722 SUPPLICANT_DBG("Network %s already exist", network->name);
2723 is_new_network = false;
2728 is_new_network = true;
2730 network = g_try_new0(GSupplicantNetwork, 1);
2736 network->interface = interface;
2738 network->path = g_strdup(bss->path);
2739 network->group = group;
2740 network->name = create_name(bss->ssid, bss->ssid_len);
2741 network->mode = bss->mode;
2742 network->security = bss->security;
2743 network->keymgmt = bss->keymgmt;
2744 network->ssid_len = bss->ssid_len;
2745 memcpy(network->ssid, bss->ssid, bss->ssid_len);
2746 network->signal = bss->signal;
2747 network->frequency = bss->frequency;
2748 network->best_bss = bss;
2750 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2751 network->wps = TRUE;
2752 network->wps_capabilities = bss->wps_capabilities;
2755 #if defined TIZEN_EXT
2756 network->owe_transition_mode = bss->owe_transition_mode;
2757 network->privacy = bss->privacy;
2758 memcpy(network->transition_mode_ssid, bss->transition_mode_ssid, bss->transition_mode_ssid_len);
2759 memcpy(network->transition_mode_bssid, bss->transition_mode_bssid, WIFI_BSSID_LEN_MAX);
2761 network->keymgmt = bss->keymgmt;
2763 if (g_slist_length(bss->vsie_list) > 0) {
2764 GSList *list = NULL;
2765 unsigned char *vsie = NULL;
2766 for (list = bss->vsie_list; list; list = list->next) {
2767 unsigned char *ie = (unsigned char *)list->data;
2768 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2771 memcpy(vsie, ie, ie[1]+2);
2772 network->vsie_list = g_slist_append(network->vsie_list, vsie);
2774 SUPPLICANT_DBG("Failed to allocate memory.");
2778 network->isHS20AP = bss->hs20;
2779 memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
2780 network->phy_mode = bss->phy_mode;
2783 SUPPLICANT_DBG("New network %s created", network->name);
2785 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2788 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2791 #if defined TIZEN_EXT
2792 network->assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2793 NULL, remove_assoc_data);
2796 g_hash_table_replace(interface->network_table,
2797 network->group, network);
2799 callback_network_added(network);
2802 /* We update network's WPS properties if only bss provides WPS. */
2803 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2804 network->wps = TRUE;
2805 network->wps_capabilities = bss->wps_capabilities;
2807 if (!is_new_network)
2808 callback_network_changed(network, "WPSCapabilities");
2812 * Do not change best BSS if we are connected. It will be done through
2813 * CurrentBSS property in case of misalignment with wpa_s or roaming.
2815 #if defined TIZEN_EXT
2816 if (network != interface->current_network) {
2817 if (update_best_bss(network, bss, network->best_bss))
2818 callback_network_changed(network, "Signal");
2821 if (network != interface->current_network &&
2822 bss->signal > network->signal) {
2823 network->signal = bss->signal;
2824 network->best_bss = bss;
2825 callback_network_changed(network, "Signal");
2829 g_hash_table_replace(interface->bss_mapping, bss->path, network);
2830 g_hash_table_replace(network->bss_table, bss->path, bss);
2832 g_hash_table_replace(bss_mapping, bss->path, interface);
2837 static void bss_rates(DBusMessageIter *iter, void *user_data)
2839 struct g_supplicant_bss *bss = user_data;
2840 dbus_uint32_t rate = 0;
2842 dbus_message_iter_get_basic(iter, &rate);
2846 if (rate > bss->maxrate)
2847 bss->maxrate = rate;
2850 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
2852 unsigned int *keymgmt = user_data;
2853 const char *str = NULL;
2856 dbus_message_iter_get_basic(iter, &str);
2860 for (i = 0; keymgmt_map[i].str; i++)
2861 if (strcmp(str, keymgmt_map[i].str) == 0) {
2862 SUPPLICANT_DBG("Keymgmt: %s", str);
2863 *keymgmt |= keymgmt_map[i].val;
2868 static void bss_group(DBusMessageIter *iter, void *user_data)
2870 unsigned int *group = user_data;
2871 const char *str = NULL;
2874 dbus_message_iter_get_basic(iter, &str);
2878 for (i = 0; group_map[i].str; i++)
2879 if (strcmp(str, group_map[i].str) == 0) {
2880 SUPPLICANT_DBG("Group: %s", str);
2881 *group |= group_map[i].val;
2886 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
2888 unsigned int *pairwise = user_data;
2889 const char *str = NULL;
2892 dbus_message_iter_get_basic(iter, &str);
2896 for (i = 0; pairwise_map[i].str; i++)
2897 if (strcmp(str, pairwise_map[i].str) == 0) {
2898 SUPPLICANT_DBG("Pairwise: %s", str);
2899 *pairwise |= pairwise_map[i].val;
2904 static void bss_wpa(const char *key, DBusMessageIter *iter,
2907 struct g_supplicant_bss *bss = user_data;
2908 unsigned int value = 0;
2910 SUPPLICANT_DBG("Key: %s", key);
2912 if (g_strcmp0(key, "KeyMgmt") == 0) {
2913 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
2915 if (bss->rsn_selected)
2916 bss->rsn_keymgmt = value;
2918 bss->wpa_keymgmt = value;
2919 } else if (g_strcmp0(key, "Group") == 0) {
2920 supplicant_dbus_array_foreach(iter, bss_group, &value);
2922 if (bss->rsn_selected)
2923 bss->rsn_group = value;
2925 bss->wpa_group = value;
2926 } else if (g_strcmp0(key, "Pairwise") == 0) {
2927 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
2929 if (bss->rsn_selected)
2930 bss->rsn_pairwise = value;
2932 bss->wpa_pairwise = value;
2936 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
2939 unsigned int len = 0;
2941 while (len + 4 < ie_size) {
2942 unsigned int hi = ie[len];
2943 unsigned int lo = ie[len + 1];
2944 unsigned int tmp_type = (hi << 8) + lo;
2945 unsigned int v_len = 0;
2947 /* hi and lo are used to recreate an unsigned int
2948 * based on 2 8bits length unsigned int. */
2952 v_len = (hi << 8) + lo;
2954 if (tmp_type == type) {
2955 unsigned int ret_value = 0;
2956 unsigned char *value = (unsigned char *)&ret_value;
2958 SUPPLICANT_DBG("IE: match type 0x%x", type);
2960 /* Verifying length relevance */
2961 if (v_len > sizeof(unsigned int) ||
2962 len + 4 + v_len > ie_size)
2965 memcpy(value, ie + len + 4, v_len);
2967 SUPPLICANT_DBG("returning 0x%x", ret_value);
2974 SUPPLICANT_DBG("returning 0");
2978 #if defined TIZEN_EXT
2979 static void get_bss_phy_mode(unsigned int max_rate,
2980 unsigned int max_ext_rate, bool ht, bool vht, void *data)
2982 struct g_supplicant_bss *bss = data;
2983 unsigned int freq = bss->frequency;
2985 /* Following conditions are used to determine
2986 * IEEE 802.11 Protocol Modes:-
2988 * 1. If “Supported rates” is only till 11 Mbps,
2989 * and frequency is in 2.4GHz band, then protocol is 11B.
2990 * 2. If “Supported rates” is till 54Mbps or
2991 * “Extended supported rates” are present,
2992 * and frequency is in 2.4GHz band, then protocol is 11G.
2993 * 3. If “Supported rates” is only till 54 Mbps,
2994 * frequency is in 5GHz band , then protocol is 11A.
2995 * 4. If “HT capabilities” is supported , then protocol is 11N.
2996 * 5. If “HT capabilities” & “VHT” is supported and
2997 * frequency is in 5 GHz band, then protocol is 11AC.
3000 if (freq >= 2412 && freq <= 2484) { /* 2.4 Ghz Band */
3001 if (max_rate <= 11 && max_ext_rate <= 0 && !ht)
3002 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211B;
3003 else if ((max_rate <= 54 || max_ext_rate > 0) && !ht)
3004 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BG;
3005 else if ((max_rate >= 54 || max_ext_rate > 0) && ht)
3006 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BGN;
3008 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
3009 } else if (freq >= 5180 && freq <= 5825) { /* 5 Ghz Band */
3010 if (max_rate <= 54 && !ht)
3011 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211A;
3012 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && !vht)
3013 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211AN;
3014 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && vht)
3015 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211ANAC;
3017 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
3022 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
3024 struct g_supplicant_bss *bss = user_data;
3025 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
3026 unsigned char *ie, *ie_end;
3027 DBusMessageIter array;
3030 #if defined TIZEN_EXT
3031 const unsigned char OWE_WFA_OUI[] = { 0x50, 0x6f, 0x9a, 0x1c };
3033 unsigned char *rates = NULL;
3034 unsigned char *ext_rates = NULL;
3035 unsigned int max_rate = 0;
3036 unsigned int max_ext_rate = 0;
3037 unsigned int offset = 0;
3042 #define WMM_WPA1_WPS_INFO 221
3043 #define WPS_INFO_MIN_LEN 6
3044 #define WPS_VERSION_TLV 0x104A
3045 #define WPS_STATE_TLV 0x1044
3046 #define WPS_METHODS_TLV 0x1012
3047 #define WPS_REGISTRAR_TLV 0x1041
3048 #define WPS_VERSION 0x10
3049 #define WPS_PBC 0x04
3050 #define WPS_PIN 0x00
3051 #define WPS_CONFIGURED 0x02
3052 #if defined TIZEN_EXT
3053 #define VENDOR_SPECIFIC_INFO 0xDD
3054 #define WLAN_EID_COUNTRY 7
3055 #define WLAN_EID_RSN_INFO 48
3056 #define RSN_CAPABILITY_MFP_REQ (1 << 6)
3059 dbus_message_iter_recurse(iter, &array);
3060 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
3062 if (!ie || ie_len < 2)
3065 bss->wps_capabilities = 0;
3068 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
3070 #if defined TIZEN_EXT
3071 unsigned char *vsie;
3074 if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, OWE_WFA_OUI, sizeof(OWE_WFA_OUI)) == 0) {
3075 SUPPLICANT_DBG("IE: match vendor specific data : OWE Transition Mode");
3078 Tag: Vendor Specific: Wi-Fi Alliance: OWE Transition Mode
3079 Tag Number: Vendor Specific (221) -> ie[0]
3080 Tag length: 26 -> ie[1]
3081 OUI: 50:6f:9a (Wi-Fi Alliance) -> ie[2]
3082 Vendor Specific OUI Type: 28 -> ie[5]
3083 BSSID: 92:fd:f0:20:2b:09 -> ie[6]
3084 SSID length: 15 -> ie[12]
3085 SSID: Wi-Fi-5.2.3-owe -> ie[13]
3087 0000 dd 1a 50 6f 9a 1c 92 fd f0 20 2b 09 0f 57 69 2d ..Po..... +..Wi-
3088 0010 46 69 2d 35 2e 32 2e 33 2d 6f 77 65 Fi-5.2.3-owe
3091 bss->owe_transition_mode = TRUE;
3092 if (ie[1] >= 11) { // Tag length is at least up to ssid length position.
3093 memcpy(bss->transition_mode_bssid, ie+6, WIFI_BSSID_LEN_MAX);
3094 if (ie[12] > 0 && ie[12] < 32) {
3095 memcpy(bss->transition_mode_ssid, ie+13, ie[12]);
3096 bss->transition_mode_ssid_len = ie[12];
3098 bss->transition_mode_ssid_len = 0;
3100 bss->owe_transition_mode = FALSE;
3104 if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
3106 if (!simplified_log)
3107 SUPPLICANT_DBG("IE: match vendor specific data");
3109 vsie_len = ie[1]+2; // tag number size(1), tag length size(1)
3110 vsie = (unsigned char *)g_try_malloc0(vsie_len);
3113 memcpy(vsie, ie, vsie_len);
3114 bss->vsie_list = g_slist_append(bss->vsie_list, vsie);
3116 SUPPLICANT_DBG("Failed to allocate memory");
3120 if (ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
3121 /* Add country code only if it is a valid alphabet */
3122 if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
3123 memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
3128 if (ie[0] == WLAN_EID_HT_CAP && ie[1]) {
3133 if (ie[0] == WLAN_EID_VHT_CAP && ie[1]) {
3138 if (ie[0] == WLAN_EID_SUPP_RATES && ie[1]) {
3140 rates = g_malloc0(r_len);
3144 for (j = 0; ie && j < r_len; j++) {
3145 rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3146 if (max_rate < rates[j])
3147 max_rate = rates[j];
3152 if (ie[0] == WLAN_EID_EXT_SUPP_RATES && ie[1] > 0) {
3154 ext_rates = g_malloc0(r_len);
3158 for (j = 0; ie && j < r_len; j++) {
3159 ext_rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3160 if (max_ext_rate < ext_rates[j])
3161 max_ext_rate = ext_rates[j];
3166 if (ie[0] == WLAN_EID_RSN_INFO && ie[1] >= 20) {
3168 offset = 10 + ie[8] * 4;
3169 offset += ie[offset] * 4 + 2;
3171 if (offset <= r_len + 1 &&
3172 (ie[offset] & RSN_CAPABILITY_MFP_REQ) != 0)
3173 bss->pmf_required = TRUE;
3178 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
3179 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
3182 SUPPLICANT_DBG("IE: match WPS_OUI");
3184 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
3185 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
3187 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
3189 if (value == WPS_CONFIGURED)
3190 bss->wps_capabilities |=
3191 G_SUPPLICANT_WPS_CONFIGURED;
3194 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
3196 if (GUINT16_FROM_BE(value) == WPS_PBC)
3197 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3198 if (GUINT16_FROM_BE(value) == WPS_PIN)
3199 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3201 bss->wps_capabilities |=
3202 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
3204 /* If the AP sends this it means it's advertizing
3205 * as a registrar and the WPS process is launched
3207 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
3208 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
3210 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
3213 get_bss_phy_mode(max_rate, max_ext_rate, ht, vht, user_data);
3221 static void bss_compute_security(struct g_supplicant_bss *bss)
3224 * Combining RSN and WPA keymgmt
3225 * We combine it since parsing IEs might have set something for WPS. */
3226 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
3228 bss->ieee8021x = FALSE;
3230 #if defined TIZEN_EXT
3231 bss->ft_ieee8021x = FALSE;
3232 bss->ft_psk = FALSE;
3235 #if defined TIZEN_EXT
3237 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3238 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3239 bss->ieee8021x = TRUE;
3240 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
3241 bss->ft_ieee8021x = TRUE;
3244 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3245 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
3246 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3247 bss->ieee8021x = TRUE;
3250 #if defined TIZEN_EXT
3252 G_SUPPLICANT_KEYMGMT_WPA_PSK_256) {
3253 bss->psk_sha256 = TRUE;
3257 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3258 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3260 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
3264 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3265 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
3266 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3270 #if defined TIZEN_EXT
3272 (G_SUPPLICANT_KEYMGMT_SAE |
3273 G_SUPPLICANT_KEYMGMT_FT_SAE))
3275 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_OWE)
3277 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_DPP)
3282 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3283 #if defined TIZEN_EXT
3284 else if (bss->ft_ieee8021x)
3285 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3287 bss->security = G_SUPPLICANT_SECURITY_SAE;
3288 else if (bss->psk_sha256)
3289 bss->security = G_SUPPLICANT_SECURITY_PSK_SHA256;
3292 bss->security = G_SUPPLICANT_SECURITY_PSK;
3293 #if defined TIZEN_EXT
3294 else if (bss->ft_psk)
3295 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
3296 else if (bss->owe || bss->owe_transition_mode)
3297 bss->security = G_SUPPLICANT_SECURITY_OWE;
3299 bss->security = G_SUPPLICANT_SECURITY_DPP;
3301 else if (bss->privacy)
3302 bss->security = G_SUPPLICANT_SECURITY_WEP;
3304 bss->security = G_SUPPLICANT_SECURITY_NONE;
3308 static void bss_property(const char *key, DBusMessageIter *iter,
3311 struct g_supplicant_bss *bss = user_data;
3313 if (!bss->interface)
3315 #if defined TIZEN_EXT
3316 if (!simplified_log)
3318 SUPPLICANT_DBG("key %s", key);
3323 if (g_strcmp0(key, "BSSID") == 0) {
3324 DBusMessageIter array;
3325 unsigned char *addr;
3328 dbus_message_iter_recurse(iter, &array);
3329 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
3332 memcpy(bss->bssid, addr, addr_len);
3333 } else if (g_strcmp0(key, "SSID") == 0) {
3334 DBusMessageIter array;
3335 unsigned char *ssid;
3338 dbus_message_iter_recurse(iter, &array);
3339 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
3341 if (ssid_len > 0 && ssid_len < 33) {
3342 memcpy(bss->ssid, ssid, ssid_len);
3343 bss->ssid_len = ssid_len;
3345 memset(bss->ssid, 0, sizeof(bss->ssid));
3348 } else if (g_strcmp0(key, "Capabilities") == 0) {
3349 dbus_uint16_t capabilities = 0x0000;
3351 dbus_message_iter_get_basic(iter, &capabilities);
3353 if (capabilities & IEEE80211_CAP_ESS)
3354 bss->mode = G_SUPPLICANT_MODE_INFRA;
3355 else if (capabilities & IEEE80211_CAP_IBSS)
3356 bss->mode = G_SUPPLICANT_MODE_IBSS;
3358 if (capabilities & IEEE80211_CAP_PRIVACY)
3359 bss->privacy = TRUE;
3360 } else if (g_strcmp0(key, "Mode") == 0) {
3361 const char *mode = NULL;
3363 dbus_message_iter_get_basic(iter, &mode);
3364 bss->mode = string2mode(mode);
3365 } else if (g_strcmp0(key, "Frequency") == 0) {
3366 dbus_uint16_t frequency = 0;
3368 dbus_message_iter_get_basic(iter, &frequency);
3369 bss->frequency = frequency;
3370 } else if (g_strcmp0(key, "Signal") == 0) {
3371 dbus_int16_t signal = 0;
3373 dbus_message_iter_get_basic(iter, &signal);
3375 bss->signal = signal;
3377 bss->signal = BSS_UNKNOWN_STRENGTH;
3379 } else if (g_strcmp0(key, "Level") == 0) {
3380 dbus_int32_t level = 0;
3382 dbus_message_iter_get_basic(iter, &level);
3383 } else if (g_strcmp0(key, "Rates") == 0) {
3384 supplicant_dbus_array_foreach(iter, bss_rates, bss);
3385 } else if (g_strcmp0(key, "MaxRate") == 0) {
3386 dbus_uint32_t maxrate = 0;
3388 dbus_message_iter_get_basic(iter, &maxrate);
3390 bss->maxrate = maxrate;
3391 } else if (g_strcmp0(key, "Privacy") == 0) {
3392 dbus_bool_t privacy = FALSE;
3394 dbus_message_iter_get_basic(iter, &privacy);
3395 bss->privacy = privacy;
3396 } else if (g_strcmp0(key, "RSN") == 0) {
3397 bss->rsn_selected = TRUE;
3399 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3400 } else if (g_strcmp0(key, "WPA") == 0) {
3401 bss->rsn_selected = FALSE;
3403 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3404 #if defined TIZEN_EXT
3405 } else if (g_strcmp0(key, "HS20") == 0) {
3406 dbus_bool_t hs20 = FALSE;
3407 dbus_message_iter_get_basic(iter, &hs20);
3409 } else if (g_strcmp0(key, "SNR") == 0) {
3410 dbus_int16_t snr = 0;
3412 dbus_message_iter_get_basic(iter, &snr);
3414 } else if (g_strcmp0(key, "EstThroughput") == 0) {
3415 dbus_uint32_t est_throughput = 0;
3417 dbus_message_iter_get_basic(iter, &est_throughput);
3418 if (est_throughput != 0)
3419 bss->est_throughput = est_throughput;
3421 } else if (g_strcmp0(key, "IEs") == 0)
3422 bss_process_ies(iter, bss);
3424 SUPPLICANT_DBG("key %s type %c",
3425 key, dbus_message_iter_get_arg_type(iter));
3428 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
3431 GSupplicantInterface *interface = user_data;
3432 GSupplicantNetwork *network;
3433 struct g_supplicant_bss *bss;
3434 const char *path = NULL;
3435 #if defined TIZEN_EXT
3436 if (!simplified_log)
3440 dbus_message_iter_get_basic(iter, &path);
3444 if (g_strcmp0(path, "/") == 0)
3446 #if defined TIZEN_EXT
3447 if (!simplified_log)
3449 SUPPLICANT_DBG("%s", path);
3451 network = g_hash_table_lookup(interface->bss_mapping, path);
3453 bss = g_hash_table_lookup(network->bss_table, path);
3458 bss = g_try_new0(struct g_supplicant_bss, 1);
3462 bss->interface = interface;
3463 bss->path = g_strdup(path);
3464 bss->signal = BSS_UNKNOWN_STRENGTH;
3469 static void interface_bss_added_with_keys(DBusMessageIter *iter,
3472 struct g_supplicant_bss *bss;
3473 #if defined TIZEN_EXT
3474 if (!simplified_log)
3478 bss = interface_bss_added(iter, user_data);
3482 dbus_message_iter_next(iter);
3484 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
3485 #if defined TIZEN_EXT
3495 supplicant_dbus_property_foreach(iter, bss_property, bss);
3497 bss_compute_security(bss);
3498 if (add_or_replace_bss_to_network(bss) < 0)
3499 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3502 static void interface_bss_added_without_keys(DBusMessageIter *iter,
3505 struct g_supplicant_bss *bss;
3506 #if defined TIZEN_EXT
3507 if (!simplified_log)
3511 bss = interface_bss_added(iter, user_data);
3515 supplicant_dbus_property_get_all(bss->path,
3516 SUPPLICANT_INTERFACE ".BSS",
3517 bss_property, bss, bss);
3519 bss_compute_security(bss);
3520 if (add_or_replace_bss_to_network(bss) < 0)
3521 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3524 static void update_signal(gpointer key, gpointer value,
3527 struct g_supplicant_bss *bss = value;
3528 GSupplicantNetwork *network = user_data;
3530 #if defined TIZEN_EXT
3531 if (!network->best_bss || (network->best_bss == bss)) {
3532 if (bss->signal > network->signal) {
3533 network->signal = bss->signal;
3534 network->frequency = bss->frequency;
3535 network->phy_mode = bss->phy_mode;
3536 network->best_bss = bss;
3541 update_best_bss(network, bss, network->best_bss);
3543 if (bss->signal > network->signal) {
3544 network->signal = bss->signal;
3545 network->best_bss = bss;
3550 static void update_network_signal(GSupplicantNetwork *network)
3552 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
3555 g_hash_table_foreach(network->bss_table,
3556 update_signal, network);
3558 SUPPLICANT_DBG("New network signal %d", network->signal);
3561 #if defined TIZEN_EXT_INS
3562 static gboolean last_connected_timeout(gpointer data)
3564 GSupplicantInterface *interface = data;
3565 GSupplicantNetwork *current_network = interface->current_network;
3567 SUPPLICANT_DBG("Timeout last connected bss");
3569 if (current_network && current_network->best_bss) {
3570 if (compare_bssid(current_network->best_bss->bssid, interface->connected_bssid)) {
3571 g_supplicant_network_set_last_connected_bssid(current_network, interface->connected_bssid);
3572 callback_network_changed(current_network, "LastConnectedBSSID");
3576 last_connected_bss_timeout = 0;
3580 static void add_timer_for_last_connected(GSupplicantInterface *interface)
3582 GSupplicantNetwork *current_network = interface->current_network;
3584 if (interface->state == G_SUPPLICANT_STATE_COMPLETED) {
3585 if (current_network) {
3586 struct g_supplicant_bss *best_bss = current_network->best_bss;
3588 memcpy(interface->connected_bssid, best_bss->bssid, WIFI_BSSID_LEN_MAX);
3590 if (last_connected_bss_timeout)
3591 g_source_remove(last_connected_bss_timeout);
3593 last_connected_bss_timeout = g_timeout_add_seconds(LAST_CONNECTED_TIMEOUT,
3594 last_connected_timeout, interface);
3596 SUPPLICANT_DBG("Add timer for last connected bssid [" MACSTR "]",
3597 MAC2STR(best_bss->bssid));
3602 static void remove_timer_for_last_connected(GSupplicantInterface *interface)
3604 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED) {
3605 if (last_connected_bss_timeout != 0) {
3606 g_source_remove(last_connected_bss_timeout);
3607 last_connected_bss_timeout = 0;
3608 SUPPLICANT_DBG("Remove timer for last connected bss");
3612 #endif /* defined TIZEN_EXT_INS */
3614 static void interface_current_bss(GSupplicantInterface *interface,
3615 DBusMessageIter *iter)
3617 GSupplicantNetwork *network;
3618 struct g_supplicant_bss *bss;
3620 #if defined TIZEN_EXT
3621 char curr_bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3622 char best_bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3623 char *curr_bssid_str = curr_bssid_buff;
3624 char *best_bssid_str = best_bssid_buff;
3625 gboolean update = FALSE;
3628 dbus_message_iter_get_basic(iter, &path);
3629 if (g_strcmp0(path, "/") == 0) {
3630 interface->current_network = NULL;
3634 interface_bss_added_without_keys(iter, interface);
3636 network = g_hash_table_lookup(interface->bss_mapping, path);
3640 bss = g_hash_table_lookup(network->bss_table, path);
3644 interface->current_network = network;
3645 #if defined TIZEN_EXT
3646 snprintf(curr_bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bss->bssid));
3647 snprintf(best_bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(network->best_bss->bssid));
3649 SUPPLICANT_DBG("current network [%p], Passed bss %s, best bss %s",
3650 interface->current_network, curr_bssid_str, best_bssid_str);
3652 if (network->frequency != bss->frequency) {
3653 network->frequency = bss->frequency;
3654 network->phy_mode = bss->phy_mode;
3659 if (bss != network->best_bss) {
3661 * This is the case where either wpa_s got associated
3662 * to a BSS different than the one ConnMan considers
3663 * the best, or we are roaming.
3665 SUPPLICANT_DBG("Update best BSS for %s", network->name);
3667 network->best_bss = bss;
3669 if (network->signal != bss->signal) {
3670 SUPPLICANT_DBG("New network signal %d dBm",
3673 network->signal = bss->signal;
3674 callback_network_changed(network, "Signal");
3675 #if defined TIZEN_EXT
3683 #if defined TIZEN_EXT
3685 callback_network_changed(network, "");
3689 * wpa_s could notify about CurrentBSS in any state once
3690 * it got associated. It is not sure such notification will
3691 * arrive together with transition to ASSOCIATED state.
3692 * In fact, for networks with security WEP or OPEN, it
3693 * always arrives together with transition to COMPLETED.
3695 switch (interface->state) {
3696 case G_SUPPLICANT_STATE_UNKNOWN:
3697 case G_SUPPLICANT_STATE_DISABLED:
3698 case G_SUPPLICANT_STATE_DISCONNECTED:
3699 case G_SUPPLICANT_STATE_INACTIVE:
3700 case G_SUPPLICANT_STATE_SCANNING:
3701 case G_SUPPLICANT_STATE_AUTHENTICATING:
3702 case G_SUPPLICANT_STATE_ASSOCIATING:
3704 case G_SUPPLICANT_STATE_ASSOCIATED:
3705 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
3706 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
3707 case G_SUPPLICANT_STATE_COMPLETED:
3708 callback_network_associated(network);
3709 #if defined TIZEN_EXT_INS
3710 add_timer_for_last_connected(interface);
3716 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
3718 GSupplicantInterface *interface = user_data;
3719 GSupplicantNetwork *network;
3720 struct g_supplicant_bss *bss = NULL;
3721 const char *path = NULL;
3722 bool is_current_network_bss = false;
3724 dbus_message_iter_get_basic(iter, &path);
3728 network = g_hash_table_lookup(interface->bss_mapping, path);
3732 bss = g_hash_table_lookup(network->bss_table, path);
3733 if (network->best_bss == bss) {
3734 network->best_bss = NULL;
3735 network->signal = BSS_UNKNOWN_STRENGTH;
3736 is_current_network_bss = true;
3739 g_hash_table_remove(bss_mapping, path);
3741 g_hash_table_remove(interface->bss_mapping, path);
3742 g_hash_table_remove(network->bss_table, path);
3744 update_network_signal(network);
3746 if (g_hash_table_size(network->bss_table) == 0) {
3747 g_hash_table_remove(interface->network_table, network->group);
3749 if (is_current_network_bss && network->best_bss)
3750 #if defined TIZEN_EXT
3751 callback_network_changed(network, "CheckMultiBssidConnect");
3753 callback_network_changed(network, "");
3758 static void set_config_methods(DBusMessageIter *iter, void *user_data)
3760 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
3763 static void wps_property(const char *key, DBusMessageIter *iter,
3766 GSupplicantInterface *interface = user_data;
3770 #if defined TIZEN_EXT
3771 if (!simplified_log)
3773 SUPPLICANT_DBG("key: %s", key);
3775 if (g_strcmp0(key, "ConfigMethods") == 0) {
3776 const char *config_methods = "push_button", *str = NULL;
3778 dbus_message_iter_get_basic(iter, &str);
3779 if (str && strlen(str) > 0) {
3780 /* It was already set at wpa_s level, don't modify it. */
3781 SUPPLICANT_DBG("%s", str);
3785 supplicant_dbus_property_set(interface->path,
3786 SUPPLICANT_INTERFACE ".Interface.WPS",
3787 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
3788 set_config_methods, NULL, &config_methods, NULL);
3790 SUPPLICANT_DBG("No value. Set %s", config_methods);
3795 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3796 void g_supplicant_replace_config_file(const char *ifname, const char *config_file)
3804 SUPPLICANT_DBG("New {%s, %s}", ifname, config_file);
3805 g_hash_table_replace(config_file_table,
3806 g_strdup(ifname), g_strdup(config_file));
3808 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3810 static void interface_property(const char *key, DBusMessageIter *iter,
3813 GSupplicantInterface *interface = user_data;
3817 #if defined TIZEN_EXT
3818 if (!simplified_log)
3820 SUPPLICANT_DBG("%s", key);
3823 debug_strvalmap("KeyMgmt capability", keymgmt_map,
3824 interface->keymgmt_capa);
3825 debug_strvalmap("AuthAlg capability", authalg_capa_map,
3826 interface->authalg_capa);
3827 debug_strvalmap("Protocol capability", proto_capa_map,
3828 interface->proto_capa);
3829 debug_strvalmap("Pairwise capability", pairwise_map,
3830 interface->pairwise_capa);
3831 debug_strvalmap("Group capability", group_map,
3832 interface->group_capa);
3833 debug_strvalmap("Scan capability", scan_capa_map,
3834 interface->scan_capa);
3835 debug_strvalmap("Mode capability", mode_capa_map,
3836 interface->mode_capa);
3838 supplicant_dbus_property_get_all(interface->path,
3839 SUPPLICANT_INTERFACE ".Interface.WPS",
3840 wps_property, interface, interface);
3842 if (interface->ready)
3843 callback_interface_added(interface);
3848 if (g_strcmp0(key, "Capabilities") == 0) {
3849 supplicant_dbus_property_foreach(iter, interface_capability,
3851 #if !defined TIZEN_EXT
3852 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
3853 interface->p2p_support = true;
3855 #if defined TIZEN_EXT_WIFI_MESH
3856 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_MESH)
3857 interface->mesh_support = true;
3859 } else if (g_strcmp0(key, "State") == 0) {
3860 const char *str = NULL;
3862 dbus_message_iter_get_basic(iter, &str);
3864 if (string2state(str) != interface->state) {
3865 interface->state = string2state(str);
3866 callback_interface_state(interface);
3868 #if defined TIZEN_EXT_INS
3869 switch (interface->state) {
3870 case G_SUPPLICANT_STATE_COMPLETED:
3871 add_timer_for_last_connected(interface);
3873 case G_SUPPLICANT_STATE_DISCONNECTED:
3874 remove_timer_for_last_connected(interface);
3880 if (interface->ap_create_in_progress) {
3881 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
3882 callback_ap_create_fail(interface);
3884 interface->ap_create_in_progress = false;
3887 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
3888 interface->ready = FALSE;
3890 interface->ready = TRUE;
3892 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
3893 } else if (g_strcmp0(key, "Scanning") == 0) {
3894 dbus_bool_t scanning = FALSE;
3896 dbus_message_iter_get_basic(iter, &scanning);
3897 interface->scanning = scanning;
3899 if (interface->ready) {
3900 if (interface->scanning)
3901 callback_scan_started(interface);
3903 callback_scan_finished(interface);
3905 } else if (g_strcmp0(key, "ApScan") == 0) {
3908 dbus_message_iter_get_basic(iter, &apscan);
3909 interface->apscan = apscan;
3910 } else if (g_strcmp0(key, "Ifname") == 0) {
3911 const char *str = NULL;
3913 dbus_message_iter_get_basic(iter, &str);
3915 g_free(interface->ifname);
3916 interface->ifname = g_strdup(str);
3918 } else if (g_strcmp0(key, "Driver") == 0) {
3919 const char *str = NULL;
3921 dbus_message_iter_get_basic(iter, &str);
3923 g_free(interface->driver);
3924 interface->driver = g_strdup(str);
3926 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
3927 const char *str = NULL;
3929 dbus_message_iter_get_basic(iter, &str);
3931 g_free(interface->bridge);
3932 interface->bridge = g_strdup(str);
3934 } else if (g_strcmp0(key, "ConfigFile") == 0) {
3935 const char *str = NULL;
3937 dbus_message_iter_get_basic(iter, &str);
3938 if (str && strlen(str) > 0 && interface->ifname) {
3939 SUPPLICANT_DBG("New {%s, %s}", interface->ifname, str);
3940 g_hash_table_replace(config_file_table,
3941 g_strdup(interface->ifname), g_strdup(str));
3943 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
3944 interface_current_bss(interface, iter);
3945 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
3946 #if defined TIZEN_EXT
3947 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
3949 interface_network_added(iter, interface);
3950 } else if (g_strcmp0(key, "BSSs") == 0) {
3951 supplicant_dbus_array_foreach(iter,
3952 interface_bss_added_without_keys,
3954 } else if (g_strcmp0(key, "Blobs") == 0) {
3956 } else if (g_strcmp0(key, "Networks") == 0) {
3957 supplicant_dbus_array_foreach(iter, interface_network_added,
3959 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
3961 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3962 dbus_message_iter_get_basic(iter, &reason_code);
3963 callback_disconnect_reason_code(interface, reason_code);
3964 #if defined TIZEN_EXT
3965 SUPPLICANT_DBG("reason code (%d)", reason_code);
3968 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
3970 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3971 dbus_message_iter_get_basic(iter, &status_code);
3972 callback_assoc_status_code(interface, status_code);
3973 #if defined TIZEN_EXT
3974 SUPPLICANT_DBG("status code (%d)", status_code);
3978 SUPPLICANT_DBG("key %s type %c",
3979 key, dbus_message_iter_get_arg_type(iter));
3983 static void scan_network_update(DBusMessageIter *iter, void *user_data)
3985 GSupplicantInterface *interface = user_data;
3986 GSupplicantNetwork *network;
3992 dbus_message_iter_get_basic(iter, &path);
3997 if (g_strcmp0(path, "/") == 0)
4000 /* Update the network details based on scan BSS data */
4001 network = g_hash_table_lookup(interface->bss_mapping, path);
4003 callback_network_added(network);
4006 static void scan_bss_data(const char *key, DBusMessageIter *iter,
4009 GSupplicantInterface *interface = user_data;
4011 /*Fixed : stucking in scanning state when scan failed*/
4012 #if defined TIZEN_EXT
4013 GSupplicantInterfaceCallback scan_callback;
4018 supplicant_dbus_array_foreach(iter, scan_network_update,
4021 #if defined TIZEN_EXT
4022 scan_callback = interface->scan_callback;
4023 callback_scan_done(interface);
4026 if (interface->scan_callback)
4027 interface->scan_callback(0, interface, interface->scan_data);
4029 #if defined TIZEN_EXT
4030 if (interface->scan_callback == scan_callback) {
4032 interface->scan_callback = NULL;
4033 interface->scan_data = NULL;
4034 #if defined TIZEN_EXT
4039 static GSupplicantInterface *interface_alloc(const char *path)
4041 GSupplicantInterface *interface;
4043 interface = g_try_new0(GSupplicantInterface, 1);
4047 interface->path = g_strdup(path);
4049 interface->network_table = g_hash_table_new_full(g_str_hash,
4050 g_str_equal, NULL, remove_network);
4051 interface->peer_table = g_hash_table_new_full(g_str_hash,
4052 g_str_equal, NULL, remove_peer);
4053 interface->group_table = g_hash_table_new_full(g_str_hash,
4054 g_str_equal, NULL, remove_group);
4055 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
4058 g_hash_table_replace(interface_table, interface->path, interface);
4063 static void interface_added(DBusMessageIter *iter, void *user_data)
4065 GSupplicantInterface *interface;
4066 const char *path = NULL;
4067 bool properties_appended = GPOINTER_TO_UINT(user_data);
4071 dbus_message_iter_get_basic(iter, &path);
4075 if (g_strcmp0(path, "/") == 0)
4078 interface = g_hash_table_lookup(interface_table, path);
4082 interface = interface_alloc(path);
4086 if (!properties_appended) {
4087 supplicant_dbus_property_get_all(path,
4088 SUPPLICANT_INTERFACE ".Interface",
4089 interface_property, interface,
4094 dbus_message_iter_next(iter);
4095 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4096 supplicant_dbus_property_foreach(iter, interface_property,
4098 interface_property(NULL, NULL, interface);
4102 static void interface_removed(DBusMessageIter *iter, void *user_data)
4104 const char *path = NULL;
4105 GSupplicantInterface *interface = user_data;
4107 dbus_message_iter_get_basic(iter, &path);
4111 interface = g_hash_table_lookup(interface_table, path);
4112 g_supplicant_interface_cancel(interface);
4114 g_hash_table_remove(interface_table, path);
4117 static void eap_method(DBusMessageIter *iter, void *user_data)
4119 const char *str = NULL;
4122 dbus_message_iter_get_basic(iter, &str);
4126 for (i = 0; eap_method_map[i].str; i++)
4127 if (strcmp(str, eap_method_map[i].str) == 0) {
4128 eap_methods |= eap_method_map[i].val;
4133 static void service_property(const char *key, DBusMessageIter *iter,
4137 callback_system_ready();
4141 if (g_strcmp0(key, "DebugLevel") == 0) {
4142 const char *str = NULL;
4145 dbus_message_iter_get_basic(iter, &str);
4146 for (i = 0; debug_strings[i]; i++)
4147 if (g_strcmp0(debug_strings[i], str) == 0) {
4151 SUPPLICANT_DBG("Debug level %d", debug_level);
4152 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
4153 dbus_message_iter_get_basic(iter, &debug_timestamp);
4154 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
4155 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
4156 dbus_message_iter_get_basic(iter, &debug_showkeys);
4157 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
4158 } else if (g_strcmp0(key, "Interfaces") == 0) {
4159 supplicant_dbus_array_foreach(iter, interface_added, NULL);
4160 } else if (g_strcmp0(key, "EapMethods") == 0) {
4161 supplicant_dbus_array_foreach(iter, eap_method, NULL);
4162 debug_strvalmap("EAP method", eap_method_map, eap_methods);
4163 } else if (g_strcmp0(key, "Country") == 0) {
4164 const char *country = NULL;
4166 dbus_message_iter_get_basic(iter, &country);
4167 SUPPLICANT_DBG("Country %s", country);
4169 SUPPLICANT_DBG("key %s type %c",
4170 key, dbus_message_iter_get_arg_type(iter));
4173 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
4175 const char *name = NULL, *old = NULL, *new = NULL;
4179 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
4182 dbus_message_iter_get_basic(iter, &name);
4186 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
4189 dbus_message_iter_next(iter);
4190 dbus_message_iter_get_basic(iter, &old);
4191 dbus_message_iter_next(iter);
4192 dbus_message_iter_get_basic(iter, &new);
4197 if (strlen(old) > 0 && strlen(new) == 0) {
4198 system_available = FALSE;
4199 g_hash_table_remove_all(bss_mapping);
4200 g_hash_table_remove_all(peer_mapping);
4201 g_hash_table_remove_all(group_mapping);
4202 g_hash_table_remove_all(config_file_table);
4203 g_hash_table_remove_all(interface_table);
4204 callback_system_killed();
4207 if (strlen(new) > 0 && strlen(old) == 0) {
4208 system_available = TRUE;
4209 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
4210 SUPPLICANT_INTERFACE,
4211 service_property, NULL, NULL);
4215 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
4219 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
4222 supplicant_dbus_property_foreach(iter, service_property, NULL);
4225 static void signal_interface_added(const char *path, DBusMessageIter *iter)
4227 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
4229 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4230 interface_added(iter, GUINT_TO_POINTER(true));
4233 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
4237 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4238 interface_removed(iter, NULL);
4241 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
4243 GSupplicantInterface *interface;
4244 #if defined TIZEN_EXT
4245 if (!simplified_log)
4249 interface = g_hash_table_lookup(interface_table, path);
4253 supplicant_dbus_property_foreach(iter, interface_property, interface);
4256 static void signal_scan_done(const char *path, DBusMessageIter *iter)
4258 GSupplicantInterface *interface;
4259 dbus_bool_t success = FALSE;
4263 interface = g_hash_table_lookup(interface_table, path);
4267 dbus_message_iter_get_basic(iter, &success);
4269 if (interface->scanning) {
4270 callback_scan_finished(interface);
4271 interface->scanning = FALSE;
4275 * If scan is unsuccessful return -EIO else get the scanned BSSs
4276 * and update the network details accordingly
4279 if (interface->scan_callback)
4280 interface->scan_callback(-EIO, interface,
4281 interface->scan_data);
4283 interface->scan_callback = NULL;
4284 interface->scan_data = NULL;
4289 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
4290 "BSSs", scan_bss_data, interface, interface);
4293 static void signal_bss_added(const char *path, DBusMessageIter *iter)
4295 GSupplicantInterface *interface;
4296 #if defined TIZEN_EXT
4297 if (!simplified_log)
4301 interface = g_hash_table_lookup(interface_table, path);
4305 interface_bss_added_with_keys(iter, interface);
4308 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
4310 GSupplicantInterface *interface;
4314 interface = g_hash_table_lookup(interface_table, path);
4318 interface_bss_removed(iter, interface);
4321 static void signal_network_added(const char *path, DBusMessageIter *iter)
4323 GSupplicantInterface *interface;
4327 interface = g_hash_table_lookup(interface_table, path);
4331 interface_network_added(iter, interface);
4334 static void signal_network_removed(const char *path, DBusMessageIter *iter)
4336 GSupplicantInterface *interface;
4340 interface = g_hash_table_lookup(interface_table, path);
4344 interface_network_removed(iter, interface);
4346 #if defined TIZEN_EXT
4347 void *copy_vsie_list(gconstpointer src, gpointer data)
4349 return g_strdup(src);
4354 static void signal_sta_authorized(const char *path, DBusMessageIter *iter)
4356 GSupplicantInterface *interface;
4357 const char *addr = NULL;
4361 interface = g_hash_table_lookup(interface_table, path);
4365 dbus_message_iter_get_basic(iter, &addr);
4369 callback_sta_authorized(interface, addr);
4372 static void signal_sta_deauthorized(const char *path, DBusMessageIter *iter)
4374 GSupplicantInterface *interface;
4375 const char *addr = NULL;
4379 interface = g_hash_table_lookup(interface_table, path);
4383 dbus_message_iter_get_basic(iter, &addr);
4387 callback_sta_deauthorized(interface, addr);
4390 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4391 static void signal_eap(const char *path, DBusMessageIter *iter)
4393 GSupplicantInterface *interface;
4394 const char *str = NULL;
4396 SUPPLICANT_DBG("EAPOL_DEBUG callback eap signal");
4398 interface = g_hash_table_lookup(interface_table, path);
4402 // TODO: Identify EAP fail condition, currently timeout is used for failure.
4404 dbus_message_iter_get_basic(iter, &str);
4408 if (g_strcmp0("completion", str))
4411 dbus_message_iter_next(iter);
4413 dbus_message_iter_get_basic(iter, &str);
4417 if (!g_strcmp0("success", str))
4418 callback_eap(interface, true);
4420 callback_eap(interface, false);
4422 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4424 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
4426 GSupplicantInterface *interface;
4427 GSupplicantNetwork *network;
4428 GSupplicantSecurity old_security;
4429 unsigned int old_wps_capabilities;
4430 struct g_supplicant_bss *bss;
4432 #if defined TIZEN_EXT
4433 if (!simplified_log)
4437 interface = g_hash_table_lookup(bss_mapping, path);
4441 network = g_hash_table_lookup(interface->bss_mapping, path);
4445 bss = g_hash_table_lookup(network->bss_table, path);
4449 supplicant_dbus_property_foreach(iter, bss_property, bss);
4451 #if defined TIZEN_EXT
4452 if (network->interface->state != G_SUPPLICANT_STATE_COMPLETED &&
4453 bss == network->best_bss) {
4454 network->frequency = bss->frequency;
4455 network->phy_mode = bss->phy_mode;
4458 old_security = network->security;
4459 bss_compute_security(bss);
4461 if (old_security != bss->security) {
4462 struct g_supplicant_bss *new_bss;
4464 SUPPLICANT_DBG("New network security for %s with path %s",
4465 bss->ssid, bss->path);
4468 * Security change policy:
4469 * - We first copy the current bss into a new one with
4470 * its own pointer (path)
4471 * - Clear the old bss pointer and remove the network completely
4472 * if there are no more BSSs in the bss table.
4473 * - The new bss will be added either to an existing network
4474 * or an additional network will be created
4477 new_bss = g_try_new0(struct g_supplicant_bss, 1);
4481 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
4482 new_bss->path = g_strdup(bss->path);
4483 #if defined TIZEN_EXT
4484 new_bss->vsie_list = g_slist_copy_deep(bss->vsie_list, copy_vsie_list, NULL);
4487 if (network->best_bss == bss) {
4488 network->best_bss = NULL;
4489 network->signal = BSS_UNKNOWN_STRENGTH;
4492 g_hash_table_remove(bss_mapping, path);
4494 g_hash_table_remove(interface->bss_mapping, path);
4495 g_hash_table_remove(network->bss_table, path);
4497 update_network_signal(network);
4499 if (g_hash_table_size(network->bss_table) == 0)
4500 g_hash_table_remove(interface->network_table,
4503 if (add_or_replace_bss_to_network(new_bss) < 0) {
4505 * Prevent a memory leak on failure in
4506 * add_or_replace_bss_to_network
4508 SUPPLICANT_DBG("Failed to add bss %s to network table",
4510 g_free(new_bss->path);
4517 old_wps_capabilities = network->wps_capabilities;
4519 if (old_wps_capabilities != bss->wps_capabilities) {
4520 network->wps_capabilities = bss->wps_capabilities;
4521 callback_network_changed(network, "WPSCapabilities");
4524 #if defined TIZEN_EXT
4525 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
4526 network->wps = TRUE;
4527 network->wps_capabilities |= bss->wps_capabilities;
4529 network->wps = FALSE;
4532 /* Consider only property changes of the connected BSS */
4533 if (network == interface->current_network && bss != network->best_bss)
4536 if (bss->signal == network->signal)
4541 callback_network_changed(network, "");
4547 * If the new signal is lower than the SSID signal, we need
4548 * to check for the new maximum.
4550 #if defined TIZEN_EXT
4551 if (!update_best_bss(network, bss, network->best_bss)) {
4552 if (bss != network->best_bss) {
4553 callback_network_changed(network, "");
4557 network->signal = bss->signal;
4558 update_network_signal(network);
4561 if (bss->signal < network->signal) {
4562 if (bss != network->best_bss)
4565 network->signal = bss->signal;
4566 update_network_signal(network);
4568 network->signal = bss->signal;
4569 network->best_bss = bss;
4573 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
4576 callback_network_changed(network, "Signal");
4579 static void wps_credentials(const char *key, DBusMessageIter *iter,
4582 GSupplicantInterface *interface = user_data;
4587 SUPPLICANT_DBG("key %s", key);
4589 if (g_strcmp0(key, "Key") == 0) {
4590 DBusMessageIter array;
4591 unsigned char *key_val;
4594 dbus_message_iter_recurse(iter, &array);
4595 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
4597 g_free(interface->wps_cred.key);
4598 interface->wps_cred.key = g_try_malloc0(
4599 sizeof(char) * key_len + 1);
4601 if (!interface->wps_cred.key)
4604 memcpy(interface->wps_cred.key, key_val,
4605 sizeof(char) * key_len);
4607 SUPPLICANT_DBG("WPS key present");
4608 } else if (g_strcmp0(key, "SSID") == 0) {
4609 DBusMessageIter array;
4610 unsigned char *ssid;
4613 dbus_message_iter_recurse(iter, &array);
4614 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
4616 if (ssid_len > 0 && ssid_len < 33) {
4617 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
4618 interface->wps_cred.ssid_len = ssid_len;
4620 memset(interface->wps_cred.ssid, 0, 32);
4621 interface->wps_cred.ssid_len = 0;
4626 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
4628 GSupplicantInterface *interface;
4632 interface = g_hash_table_lookup(interface_table, path);
4636 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
4639 static void wps_event_args(const char *key, DBusMessageIter *iter,
4642 GSupplicantInterface *interface = user_data;
4644 if (!key || !interface)
4647 SUPPLICANT_DBG("Arg Key %s", key);
4650 static void signal_wps_event(const char *path, DBusMessageIter *iter)
4652 GSupplicantInterface *interface;
4653 const char *name = NULL;
4657 interface = g_hash_table_lookup(interface_table, path);
4661 dbus_message_iter_get_basic(iter, &name);
4663 SUPPLICANT_DBG("Name: %s", name);
4665 if (g_strcmp0(name, "success") == 0)
4666 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
4667 else if (g_strcmp0(name, "fail") == 0)
4668 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
4670 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
4672 if (!dbus_message_iter_has_next(iter))
4675 dbus_message_iter_next(iter);
4677 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
4680 #if defined TIZEN_EXT
4681 static void signal_power_off(const char *path, DBusMessageIter *iter)
4683 int poweroff_state = 0;
4685 dbus_message_iter_get_basic(iter, &poweroff_state);
4687 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
4689 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
4690 if (poweroff_state != 2 && poweroff_state != 3)
4693 if (callbacks_pointer == NULL)
4696 if (callbacks_pointer->system_power_off == NULL)
4699 callbacks_pointer->system_power_off();
4703 static void create_peer_identifier(GSupplicantPeer *peer)
4705 const unsigned char test[ETH_ALEN] = {};
4710 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
4711 peer->identifier = g_strdup(peer->name);
4715 peer->identifier = g_malloc0(19);
4716 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
4717 peer->device_address[0],
4718 peer->device_address[1],
4719 peer->device_address[2],
4720 peer->device_address[3],
4721 peer->device_address[4],
4722 peer->device_address[5]);
4725 struct peer_property_data {
4726 GSupplicantPeer *peer;
4728 bool groups_changed;
4729 bool services_changed;
4732 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
4734 struct peer_property_data *data = user_data;
4735 GSupplicantPeer *peer = data->peer;
4736 GSupplicantGroup *group;
4737 const char *str = NULL;
4740 dbus_message_iter_get_basic(iter, &str);
4744 group = g_hash_table_lookup(group_mapping, str);
4748 elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
4750 data->old_groups = g_slist_remove_link(data->old_groups, elem);
4751 peer->groups = g_slist_concat(elem, peer->groups);
4753 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
4754 data->groups_changed = true;
4758 static void peer_property(const char *key, DBusMessageIter *iter,
4761 GSupplicantPeer *pending_peer;
4762 struct peer_property_data *data = user_data;
4763 GSupplicantPeer *peer = data->peer;
4765 SUPPLICANT_DBG("key: %s", key);
4767 if (!peer->interface)
4772 create_peer_identifier(peer);
4773 callback_peer_found(peer);
4774 pending_peer = g_hash_table_lookup(
4775 pending_peer_connection, peer->path);
4777 if (pending_peer && pending_peer == peer) {
4778 callback_peer_request(peer);
4779 g_hash_table_remove(pending_peer_connection,
4789 if (g_strcmp0(key, "DeviceAddress") == 0) {
4790 unsigned char *dev_addr;
4791 DBusMessageIter array;
4794 dbus_message_iter_recurse(iter, &array);
4795 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4797 if (len == ETH_ALEN)
4798 memcpy(peer->device_address, dev_addr, len);
4799 } else if (g_strcmp0(key, "DeviceName") == 0) {
4800 const char *str = NULL;
4802 dbus_message_iter_get_basic(iter, &str);
4804 peer->name = g_strdup(str);
4805 } else if (g_strcmp0(key, "config_method") == 0) {
4806 uint16_t wps_config;
4808 dbus_message_iter_get_basic(iter, &wps_config);
4810 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
4811 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
4812 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
4813 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
4814 } else if (g_strcmp0(key, "Groups") == 0) {
4815 data->old_groups = peer->groups;
4816 peer->groups = NULL;
4818 supplicant_dbus_array_foreach(iter,
4819 peer_groups_relation, data);
4820 if (g_slist_length(data->old_groups) > 0) {
4821 g_slist_free_full(data->old_groups, g_free);
4822 data->groups_changed = true;
4824 } else if (g_strcmp0(key, "IEs") == 0) {
4825 DBusMessageIter array;
4829 dbus_message_iter_recurse(iter, &array);
4830 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
4832 if (!ie || ie_len < 2)
4835 if (peer->widi_ies) {
4836 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
4839 g_free(peer->widi_ies);
4840 peer->widi_ies_length = 0;
4843 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
4845 memcpy(peer->widi_ies, ie, ie_len);
4846 peer->widi_ies_length = ie_len;
4847 data->services_changed = true;
4851 static void signal_peer_found(const char *path, DBusMessageIter *iter)
4853 struct peer_property_data *property_data;
4854 GSupplicantInterface *interface;
4855 const char *obj_path = NULL;
4856 GSupplicantPeer *peer;
4860 interface = g_hash_table_lookup(interface_table, path);
4864 dbus_message_iter_get_basic(iter, &obj_path);
4865 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4868 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4872 peer = g_try_new0(GSupplicantPeer, 1);
4876 peer->interface = interface;
4877 peer->path = g_strdup(obj_path);
4878 g_hash_table_insert(interface->peer_table, peer->path, peer);
4879 g_hash_table_replace(peer_mapping, peer->path, interface);
4881 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4882 property_data->peer = peer;
4884 dbus_message_iter_next(iter);
4885 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4886 supplicant_dbus_property_foreach(iter, peer_property,
4888 peer_property(NULL, NULL, property_data);
4892 supplicant_dbus_property_get_all(obj_path,
4893 SUPPLICANT_INTERFACE ".Peer",
4894 peer_property, property_data, NULL);
4897 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
4899 GSupplicantInterface *interface;
4900 const char *obj_path = NULL;
4901 GSupplicantPeer *peer;
4905 interface = g_hash_table_lookup(interface_table, path);
4909 dbus_message_iter_get_basic(iter, &obj_path);
4910 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4913 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4917 g_hash_table_remove(interface->peer_table, obj_path);
4920 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
4922 struct peer_property_data *property_data;
4923 GSupplicantInterface *interface;
4924 GSupplicantPeer *peer;
4928 interface = g_hash_table_lookup(peer_mapping, path);
4932 peer = g_hash_table_lookup(interface->peer_table, path);
4934 g_hash_table_remove(peer_mapping, path);
4938 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4939 property_data->peer = peer;
4941 supplicant_dbus_property_foreach(iter, peer_property, property_data);
4942 if (property_data->services_changed)
4943 callback_peer_changed(peer,
4944 G_SUPPLICANT_PEER_SERVICES_CHANGED);
4946 if (property_data->groups_changed)
4947 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
4949 dbus_free(property_data);
4951 if (!g_supplicant_peer_is_in_a_group(peer))
4952 peer->connection_requested = false;
4955 struct group_sig_data {
4956 const char *peer_obj_path;
4957 unsigned char iface_address[ETH_ALEN];
4958 const char *interface_obj_path;
4959 const char *group_obj_path;
4963 static void group_sig_property(const char *key, DBusMessageIter *iter,
4966 struct group_sig_data *data = user_data;
4971 if (g_strcmp0(key, "peer_interface_addr") == 0) {
4972 unsigned char *dev_addr;
4973 DBusMessageIter array;
4976 dbus_message_iter_recurse(iter, &array);
4977 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4979 if (len == ETH_ALEN)
4980 memcpy(data->iface_address, dev_addr, len);
4981 } else if (g_strcmp0(key, "role") == 0) {
4982 const char *str = NULL;
4984 dbus_message_iter_get_basic(iter, &str);
4985 if (g_strcmp0(str, "GO") == 0)
4986 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
4988 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
4989 } else if (g_strcmp0(key, "peer_object") == 0)
4990 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
4991 else if (g_strcmp0(key, "interface_object") == 0)
4992 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
4993 else if (g_strcmp0(key, "group_object") == 0)
4994 dbus_message_iter_get_basic(iter, &data->group_obj_path);
4998 static void signal_group_success(const char *path, DBusMessageIter *iter)
5000 GSupplicantInterface *interface;
5001 struct group_sig_data data = {};
5002 GSupplicantPeer *peer;
5006 interface = g_hash_table_lookup(interface_table, path);
5010 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5011 if (!data.peer_obj_path)
5014 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
5018 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
5019 interface->pending_peer_path = peer->path;
5022 static void signal_group_failure(const char *path, DBusMessageIter *iter)
5024 GSupplicantInterface *interface;
5025 struct group_sig_data data = {};
5026 GSupplicantPeer *peer;
5030 interface = g_hash_table_lookup(interface_table, path);
5034 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5035 if (!data.peer_obj_path)
5038 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
5042 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
5043 peer->connection_requested = false;
5046 static void signal_group_started(const char *path, DBusMessageIter *iter)
5048 GSupplicantInterface *interface, *g_interface;
5049 struct group_sig_data data = {};
5050 GSupplicantGroup *group;
5051 GSupplicantPeer *peer;
5055 interface = g_hash_table_lookup(interface_table, path);
5059 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5060 if (!data.interface_obj_path || !data.group_obj_path)
5063 peer = g_hash_table_lookup(interface->peer_table,
5064 interface->pending_peer_path);
5065 interface->pending_peer_path = NULL;
5069 g_interface = g_hash_table_lookup(interface_table,
5070 data.interface_obj_path);
5074 group = g_hash_table_lookup(interface->group_table,
5075 data.group_obj_path);
5079 group = g_try_new0(GSupplicantGroup, 1);
5083 group->interface = g_interface;
5084 group->orig_interface = interface;
5085 group->path = g_strdup(data.group_obj_path);
5086 group->role = data.role;
5088 g_hash_table_insert(interface->group_table, group->path, group);
5089 g_hash_table_replace(group_mapping, group->path, group);
5091 peer->current_group_iface = g_interface;
5092 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
5095 static void remove_peer_group_interface(GHashTable *group_table,
5098 GSupplicantGroup *group;
5099 GHashTableIter iter;
5100 gpointer value, key;
5105 group = g_hash_table_lookup(group_table, path);
5107 if (!group || !group->orig_interface)
5110 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
5112 while (g_hash_table_iter_next(&iter, &key, &value)) {
5113 GSupplicantPeer *peer = value;
5115 if (peer->current_group_iface == group->interface)
5116 peer->current_group_iface = NULL;
5120 static void signal_group_finished(const char *path, DBusMessageIter *iter)
5122 GSupplicantInterface *interface;
5123 struct group_sig_data data = {};
5127 interface = g_hash_table_lookup(interface_table, path);
5131 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5132 if (!data.interface_obj_path || !data.group_obj_path)
5135 remove_peer_group_interface(interface->group_table, data.group_obj_path);
5137 g_hash_table_remove(group_mapping, data.group_obj_path);
5139 g_hash_table_remove(interface->group_table, data.group_obj_path);
5142 static void signal_group_request(const char *path, DBusMessageIter *iter)
5144 GSupplicantInterface *interface;
5145 GSupplicantPeer *peer;
5146 const char *obj_path;
5150 interface = g_hash_table_lookup(interface_table, path);
5154 dbus_message_iter_get_basic(iter, &obj_path);
5155 if (!obj_path || !g_strcmp0(obj_path, "/"))
5158 peer = g_hash_table_lookup(interface->peer_table, obj_path);
5163 * Peer has been previously found and property set,
5164 * otherwise, defer connection to when peer property
5167 if (peer->identifier)
5168 callback_peer_request(peer);
5170 g_hash_table_replace(pending_peer_connection, peer->path, peer);
5173 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
5175 const char *peer_path = NULL;
5176 GSupplicantInterface *interface;
5177 GSupplicantGroup *group;
5178 GSupplicantPeer *peer;
5182 group = g_hash_table_lookup(group_mapping, path);
5186 dbus_message_iter_get_basic(iter, &peer_path);
5190 interface = g_hash_table_lookup(peer_mapping, peer_path);
5194 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5198 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
5200 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
5203 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
5205 const char *peer_path = NULL;
5206 GSupplicantInterface *interface;
5207 GSupplicantGroup *group;
5208 GSupplicantPeer *peer;
5213 group = g_hash_table_lookup(group_mapping, path);
5217 dbus_message_iter_get_basic(iter, &peer_path);
5221 for (elem = group->members; elem; elem = elem->next) {
5222 if (!g_strcmp0(elem->data, peer_path))
5230 group->members = g_slist_delete_link(group->members, elem);
5232 interface = g_hash_table_lookup(peer_mapping, peer_path);
5236 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5240 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
5241 peer->connection_requested = false;
5244 #if defined TIZEN_EXT_WIFI_MESH
5245 const void *g_supplicant_interface_get_mesh_group_ssid(
5246 GSupplicantInterface *interface,
5247 unsigned int *ssid_len)
5252 if (!interface || interface->group_info.ssid_len == 0) {
5257 *ssid_len = interface->group_info.ssid_len;
5258 return interface->group_info.ssid;
5261 int g_supplicant_mesh_get_disconnect_reason(GSupplicantInterface *interface)
5266 return interface->group_info.disconnect_reason;
5269 const char *g_supplicant_mesh_peer_get_address(GSupplicantMeshPeer *mesh_peer)
5271 if (!mesh_peer || !mesh_peer->peer_address)
5274 return mesh_peer->peer_address;
5277 int g_supplicant_mesh_peer_get_disconnect_reason(GSupplicantMeshPeer *mesh_peer)
5282 return mesh_peer->disconnect_reason;
5285 static void callback_mesh_group_started(GSupplicantInterface *interface)
5287 if (!callbacks_pointer)
5290 if (!callbacks_pointer->mesh_group_started)
5293 callbacks_pointer->mesh_group_started(interface);
5296 static void callback_mesh_group_removed(GSupplicantInterface *interface)
5298 if (!callbacks_pointer)
5301 if (!callbacks_pointer->mesh_group_removed)
5304 callbacks_pointer->mesh_group_removed(interface);
5307 static void mesh_group_info(const char *key, DBusMessageIter *iter,
5310 GSupplicantInterface *interface = user_data;
5314 if (g_strcmp0(key, "SSID") == 0) {
5315 DBusMessageIter array;
5316 unsigned char *ssid;
5319 dbus_message_iter_recurse(iter, &array);
5320 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
5322 if (ssid_len > 0 && ssid_len < 33) {
5323 memcpy(interface->group_info.ssid, ssid, ssid_len);
5324 interface->group_info.ssid_len = ssid_len;
5326 memset(interface->group_info.ssid, 0, 32);
5327 interface->group_info.ssid_len = 0;
5329 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5330 int disconnect_reason = 0;
5331 dbus_message_iter_get_basic(iter, &disconnect_reason);
5332 interface->group_info.disconnect_reason = disconnect_reason;
5336 static void signal_mesh_group_started(const char *path, DBusMessageIter *iter)
5338 GSupplicantInterface *interface;
5340 interface = g_hash_table_lookup(interface_table, path);
5344 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5346 callback_mesh_group_started(interface);
5349 static void signal_mesh_group_removed(const char *path, DBusMessageIter *iter)
5351 GSupplicantInterface *interface;
5353 interface = g_hash_table_lookup(interface_table, path);
5357 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5359 callback_mesh_group_removed(interface);
5362 static void callback_mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
5364 if (!callbacks_pointer)
5367 if (!callbacks_pointer->mesh_peer_connected)
5370 callbacks_pointer->mesh_peer_connected(mesh_peer);
5373 static void callback_mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
5375 if (!callbacks_pointer)
5378 if (!callbacks_pointer->mesh_peer_disconnected)
5381 callbacks_pointer->mesh_peer_disconnected(mesh_peer);
5384 static void mesh_peer_info(const char *key, DBusMessageIter *iter,
5387 GSupplicantMeshPeer *mesh_peer = user_data;
5391 if (g_strcmp0(key, "PeerAddress") == 0) {
5392 DBusMessageIter array;
5393 unsigned char *addr;
5396 dbus_message_iter_recurse(iter, &array);
5397 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
5399 if (addr_len == 6) {
5400 mesh_peer->peer_address = g_malloc0(19);
5401 snprintf(mesh_peer->peer_address, 19,
5402 "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1],
5403 addr[2], addr[3], addr[4], addr[5]);
5405 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5406 int disconnect_reason = 0;
5407 dbus_message_iter_get_basic(iter, &disconnect_reason);
5408 mesh_peer->disconnect_reason = disconnect_reason;
5412 static void signal_mesh_peer_connected(const char *path, DBusMessageIter *iter)
5414 GSupplicantInterface *interface;
5415 GSupplicantMeshPeer *mesh_peer;
5417 interface = g_hash_table_lookup(interface_table, path);
5421 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5422 mesh_peer->interface = interface;
5424 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5426 callback_mesh_peer_connected(mesh_peer);
5427 g_free(mesh_peer->peer_address);
5431 static void signal_mesh_peer_disconnected(const char *path,
5432 DBusMessageIter *iter)
5434 GSupplicantInterface *interface;
5435 GSupplicantMeshPeer *mesh_peer;
5437 interface = g_hash_table_lookup(interface_table, path);
5441 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5442 mesh_peer->interface = interface;
5444 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5446 callback_mesh_peer_disconnected(mesh_peer);
5447 g_free(mesh_peer->peer_address);
5453 const char *interface;
5455 void (*function) (const char *path, DBusMessageIter *iter);
5457 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
5459 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
5460 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
5461 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
5462 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
5464 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
5465 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
5466 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
5467 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
5468 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
5469 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
5470 { SUPPLICANT_INTERFACE ".Interface", "StaAuthorized", signal_sta_authorized },
5471 { SUPPLICANT_INTERFACE ".Interface", "StaDeauthorized", signal_sta_deauthorized },
5473 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
5475 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
5476 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
5477 #if defined TIZEN_EXT
5478 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
5481 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
5482 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
5484 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
5486 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
5487 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
5488 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
5489 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
5490 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
5492 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
5493 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
5494 #if defined TIZEN_EXT_WIFI_MESH
5495 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupStarted",
5496 signal_mesh_group_started },
5497 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupRemoved",
5498 signal_mesh_group_removed },
5499 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerConnected",
5500 signal_mesh_peer_connected },
5501 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerDisconnected",
5502 signal_mesh_peer_disconnected },
5505 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5506 { SUPPLICANT_INTERFACE ".Interface", "EAP", signal_eap },
5507 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5512 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
5513 DBusMessage *message, void *data)
5515 DBusMessageIter iter;
5519 path = dbus_message_get_path(message);
5521 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5523 if (!dbus_message_iter_init(message, &iter))
5524 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5526 for (i = 0; signal_map[i].interface; i++) {
5527 if (!dbus_message_has_interface(message, signal_map[i].interface))
5530 if (!dbus_message_has_member(message, signal_map[i].member))
5533 signal_map[i].function(path, &iter);
5537 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5540 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
5542 SUPPLICANT_DBG("Cancelling any pending DBus calls");
5543 supplicant_dbus_method_call_cancel_all(interface);
5544 supplicant_dbus_property_call_cancel_all(interface);
5547 struct supplicant_regdom {
5548 GSupplicantCountryCallback callback;
5550 const void *user_data;
5553 static void country_result(const char *error,
5554 DBusMessageIter *iter, void *user_data)
5556 struct supplicant_regdom *regdom = user_data;
5559 SUPPLICANT_DBG("Country setting result");
5565 SUPPLICANT_DBG("Country setting failure %s", error);
5569 if (regdom->callback)
5570 regdom->callback(result, regdom->alpha2,
5571 (void *) regdom->user_data);
5576 static void country_params(DBusMessageIter *iter, void *user_data)
5578 struct supplicant_regdom *regdom = user_data;
5580 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
5584 int g_supplicant_set_country(const char *alpha2,
5585 GSupplicantCountryCallback callback,
5586 const void *user_data)
5588 struct supplicant_regdom *regdom;
5591 SUPPLICANT_DBG("Country setting %s", alpha2);
5593 if (!system_available)
5596 regdom = dbus_malloc0(sizeof(*regdom));
5600 regdom->callback = callback;
5601 regdom->alpha2 = alpha2;
5602 regdom->user_data = user_data;
5604 ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
5605 "Country", DBUS_TYPE_STRING_AS_STRING,
5606 country_params, country_result,
5610 SUPPLICANT_DBG("Unable to set Country configuration");
5615 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
5616 GSupplicantCountryCallback callback,
5620 struct supplicant_regdom *regdom;
5623 regdom = dbus_malloc0(sizeof(*regdom));
5627 regdom->callback = callback;
5628 regdom->alpha2 = alpha2;
5629 regdom->user_data = user_data;
5631 ret = supplicant_dbus_property_set(interface->path,
5632 SUPPLICANT_INTERFACE ".Interface",
5633 "Country", DBUS_TYPE_STRING_AS_STRING,
5634 country_params, country_result,
5638 SUPPLICANT_DBG("Unable to set Country configuration");
5644 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
5649 return interface->p2p_support;
5652 struct supplicant_p2p_dev_config {
5657 static void p2p_device_config_result(const char *error,
5658 DBusMessageIter *iter, void *user_data)
5660 struct supplicant_p2p_dev_config *config = user_data;
5663 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
5666 g_free(config->device_name);
5667 g_free(config->dev_type);
5671 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
5673 int length, pos, end;
5678 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
5685 dev_type[length] = strtol(b, &e, 16);
5686 if (e && *e != '\0')
5695 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
5697 struct supplicant_p2p_dev_config *config = user_data;
5698 DBusMessageIter dict;
5700 supplicant_dbus_dict_open(iter, &dict);
5702 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
5703 DBUS_TYPE_STRING, &config->device_name);
5705 if (config->dev_type) {
5706 unsigned char dev_type[8] = {}, *type;
5709 len = dev_type_str2bin(config->dev_type, dev_type);
5712 supplicant_dbus_dict_append_fixed_array(&dict,
5713 "PrimaryDeviceType",
5714 DBUS_TYPE_BYTE, &type, len);
5718 supplicant_dbus_dict_close(iter, &dict);
5721 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
5722 const char *device_name,
5723 const char *primary_dev_type)
5725 struct supplicant_p2p_dev_config *config;
5728 SUPPLICANT_DBG("P2P Device settings %s/%s",
5729 device_name, primary_dev_type);
5731 config = dbus_malloc0(sizeof(*config));
5735 config->device_name = g_strdup(device_name);
5736 config->dev_type = g_strdup(primary_dev_type);
5738 ret = supplicant_dbus_property_set(interface->path,
5739 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5741 DBUS_TYPE_ARRAY_AS_STRING
5742 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
5743 DBUS_TYPE_STRING_AS_STRING
5744 DBUS_TYPE_VARIANT_AS_STRING
5745 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
5746 p2p_device_config_params,
5747 p2p_device_config_result, config, NULL);
5749 g_free(config->device_name);
5750 g_free(config->dev_type);
5752 SUPPLICANT_DBG("Unable to set P2P Device configuration");
5758 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
5761 const GSupplicantPeer *peer = value;
5762 const char *identifier = user_data;
5764 if (!g_strcmp0(identifier, peer->identifier))
5770 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
5771 const char *identifier)
5773 GSupplicantPeer *peer;
5775 peer = g_hash_table_find(interface->peer_table,
5776 peer_lookup_by_identifier,
5777 (void *) identifier);
5781 static void interface_create_data_free(struct interface_create_data *data)
5783 g_free(data->ifname);
5784 g_free(data->driver);
5785 g_free(data->bridge);
5786 #if defined TIZEN_EXT_WIFI_MESH
5787 g_free(data->parent_ifname);
5792 static bool interface_exists(GSupplicantInterface *interface,
5795 GSupplicantInterface *tmp;
5797 tmp = g_hash_table_lookup(interface_table, path);
5798 if (tmp && tmp == interface)
5804 static void interface_create_property(const char *key, DBusMessageIter *iter,
5807 struct interface_create_data *data = user_data;
5808 GSupplicantInterface *interface = data->interface;
5811 if (data->callback) {
5812 data->callback(0, data->interface, data->user_data);
5813 #if !defined TIZEN_EXT
5814 callback_p2p_support(interface);
5816 #if defined TIZEN_EXT_WIFI_MESH
5817 callback_mesh_support(interface);
5821 interface_create_data_free(data);
5824 interface_property(key, iter, interface);
5827 static void interface_create_result(const char *error,
5828 DBusMessageIter *iter, void *user_data)
5830 struct interface_create_data *data = user_data;
5831 const char *path = NULL;
5837 g_warning("error %s", error);
5842 dbus_message_iter_get_basic(iter, &path);
5848 if (!system_available) {
5853 data->interface = g_hash_table_lookup(interface_table, path);
5854 if (!data->interface) {
5855 data->interface = interface_alloc(path);
5856 if (!data->interface) {
5862 err = supplicant_dbus_property_get_all(path,
5863 SUPPLICANT_INTERFACE ".Interface",
5864 interface_create_property, data,
5871 data->callback(err, NULL, data->user_data);
5873 interface_create_data_free(data);
5876 static void interface_create_params(DBusMessageIter *iter, void *user_data)
5878 struct interface_create_data *data = user_data;
5879 DBusMessageIter dict;
5880 char *config_file = NULL;
5884 supplicant_dbus_dict_open(iter, &dict);
5886 supplicant_dbus_dict_append_basic(&dict, "Ifname",
5887 DBUS_TYPE_STRING, &data->ifname);
5890 supplicant_dbus_dict_append_basic(&dict, "Driver",
5891 DBUS_TYPE_STRING, &data->driver);
5894 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
5895 DBUS_TYPE_STRING, &data->bridge);
5897 config_file = g_hash_table_lookup(config_file_table, data->ifname);
5899 SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
5901 supplicant_dbus_dict_append_basic(&dict, "ConfigFile",
5902 DBUS_TYPE_STRING, &config_file);
5906 if (data->driver && g_strstr_len(data->driver, strlen(data->driver), "nl80211")) {
5907 supplicant_dbus_dict_append_basic(&dict, "MacAddr",
5908 DBUS_TYPE_UINT32, &data->mac_addr);
5910 supplicant_dbus_dict_append_basic(&dict, "PreassocMacAddr",
5911 DBUS_TYPE_UINT32, &data->preassoc_mac_addr);
5913 supplicant_dbus_dict_append_basic(&dict, "RandAddrLifetime",
5914 DBUS_TYPE_UINT32, &data->random_mac_lifetime);
5916 #endif /* TIZEN_EXT */
5918 #if defined TIZEN_EXT_WIFI_MESH
5919 if (data->is_mesh_interface) {
5920 if (data->parent_ifname)
5921 supplicant_dbus_dict_append_basic(&dict, "ParentIfname",
5922 DBUS_TYPE_STRING, &data->parent_ifname);
5924 supplicant_dbus_dict_append_basic(&dict, "IsMeshInterface",
5925 DBUS_TYPE_BOOLEAN, &data->is_mesh_interface);
5929 supplicant_dbus_dict_close(iter, &dict);
5932 #if defined TIZEN_EXT
5933 static void interface_get_state(const char *key, DBusMessageIter *iter,
5936 struct interface_create_data *data = user_data;
5937 GSupplicantInterface *interface = NULL;
5938 const char *str = NULL;
5940 SUPPLICANT_DBG("key[%s]", key);
5943 SUPPLICANT_DBG("data is NULL");
5947 interface = data->interface;
5949 SUPPLICANT_DBG("interface is NULL");
5954 dbus_message_iter_get_basic(iter, &str);
5957 if (string2state(str) != interface->state)
5958 interface->state = string2state(str);
5961 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
5962 interface->ready = FALSE;
5964 interface->ready = TRUE;
5966 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
5968 if (data->callback) {
5969 data->callback(0, interface, data->user_data);
5970 #if defined TIZEN_EXT_WIFI_MESH
5971 callback_mesh_support(interface);
5975 interface_create_data_free(data);
5979 static void interface_get_result(const char *error,
5980 DBusMessageIter *iter, void *user_data)
5982 struct interface_create_data *data = user_data;
5983 GSupplicantInterface *interface;
5984 const char *path = NULL;
5987 #if defined TIZEN_EXT
5988 if (!simplified_log)
5993 SUPPLICANT_DBG("Interface not created yet");
5997 dbus_message_iter_get_basic(iter, &path);
6003 interface = g_hash_table_lookup(interface_table, path);
6009 #if defined TIZEN_EXT
6010 data->interface = interface;
6011 err = supplicant_dbus_property_get(path,
6012 SUPPLICANT_INTERFACE ".Interface",
6013 "State", interface_get_state, data, NULL);
6019 if (data->callback) {
6020 data->callback(0, interface, data->user_data);
6021 #if !defined TIZEN_EXT
6022 callback_p2p_support(interface);
6024 #if defined TIZEN_EXT_WIFI_MESH
6025 callback_mesh_support(interface);
6029 interface_create_data_free(data);
6034 if (!system_available) {
6039 SUPPLICANT_DBG("Creating interface");
6041 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
6042 SUPPLICANT_INTERFACE,
6044 interface_create_params,
6045 interface_create_result, data,
6052 data->callback(err, NULL, data->user_data);
6054 interface_create_data_free(data);
6057 static void interface_get_params(DBusMessageIter *iter, void *user_data)
6059 struct interface_create_data *data = user_data;
6060 #if defined TIZEN_EXT
6061 if (!simplified_log)
6065 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
6068 #if defined TIZEN_EXT_WIFI_MESH
6069 int g_supplicant_mesh_interface_create(const char *ifname, const char *driver,
6070 const char *bridge, const char *parent_ifname,
6071 GSupplicantInterfaceCallback callback, void *user_data)
6073 struct interface_create_data *data;
6076 SUPPLICANT_DBG("ifname %s", ifname);
6078 if (!ifname || !parent_ifname)
6081 if (!system_available)
6084 data = dbus_malloc0(sizeof(*data));
6088 data->ifname = g_strdup(ifname);
6089 data->driver = g_strdup(driver);
6090 data->bridge = g_strdup(bridge);
6091 data->is_mesh_interface = true;
6092 data->parent_ifname = g_strdup(parent_ifname);
6093 data->callback = callback;
6094 data->user_data = user_data;
6096 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6097 SUPPLICANT_INTERFACE,
6099 interface_create_params,
6100 interface_create_result, data,
6105 struct interface_mesh_peer_data {
6108 GSupplicantInterface *interface;
6109 GSupplicantInterfaceCallback callback;
6113 static void interface_mesh_change_peer_params(DBusMessageIter *iter,
6116 struct interface_mesh_peer_data *data = user_data;
6120 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->peer_address);
6123 static void interface_mesh_change_peer_result(const char *error,
6124 DBusMessageIter *iter, void *user_data)
6126 struct interface_mesh_peer_data *data = user_data;
6129 SUPPLICANT_DBG("%s", data->method);
6133 SUPPLICANT_DBG("error %s", error);
6137 data->callback(err, data->interface, data->user_data);
6139 g_free(data->peer_address);
6140 g_free(data->method);
6144 int g_supplicant_interface_mesh_peer_change_status(
6145 GSupplicantInterface *interface,
6146 GSupplicantInterfaceCallback callback, const char *peer_address,
6147 const char *method, void *user_data)
6149 struct interface_mesh_peer_data *data;
6155 data = dbus_malloc0(sizeof(*data));
6159 data->peer_address = g_strdup(peer_address);
6160 data->method = g_strdup(method);
6161 data->interface = interface;
6162 data->callback = callback;
6163 data->user_data = user_data;
6165 ret = supplicant_dbus_method_call(interface->path,
6166 SUPPLICANT_INTERFACE ".Interface.Mesh",
6167 method, interface_mesh_change_peer_params,
6168 interface_mesh_change_peer_result, data, NULL);
6170 g_free(data->peer_address);
6171 g_free(data->method);
6179 int g_supplicant_interface_create(const char *ifname, const char *driver,
6182 unsigned int mac_policy,
6183 unsigned int preassoc_mac_policy,
6184 unsigned int random_mac_lifetime,
6185 #endif /* TIZEN_EXT */
6186 GSupplicantInterfaceCallback callback,
6189 struct interface_create_data *data;
6192 SUPPLICANT_DBG("ifname %s", ifname);
6197 if (!system_available)
6200 data = dbus_malloc0(sizeof(*data));
6204 data->ifname = g_strdup(ifname);
6205 data->driver = g_strdup(driver);
6206 data->bridge = g_strdup(bridge);
6207 data->callback = callback;
6209 data->mac_addr = mac_policy;
6210 data->preassoc_mac_addr = preassoc_mac_policy;
6211 data->random_mac_lifetime = random_mac_lifetime;
6212 #endif /* TIZEN_EXT */
6213 data->user_data = user_data;
6215 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6216 SUPPLICANT_INTERFACE,
6218 interface_get_params,
6219 interface_get_result, data,
6222 interface_create_data_free(data);
6227 static void interface_remove_result(const char *error,
6228 DBusMessageIter *iter, void *user_data)
6230 struct interface_data *data = user_data;
6235 SUPPLICANT_DBG("error: %s", error);
6239 if (!system_available) {
6245 * The gsupplicant interface is already freed by the InterfaceRemoved
6246 * signal callback. Simply invoke the interface_data callback.
6254 data->callback(err, NULL, data->user_data);
6260 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
6262 struct interface_data *data = user_data;
6264 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6265 &data->interface->path);
6268 int g_supplicant_interface_remove(GSupplicantInterface *interface,
6269 GSupplicantInterfaceCallback callback,
6272 struct interface_data *data;
6278 if (!system_available)
6281 g_supplicant_interface_cancel(interface);
6283 data = dbus_malloc0(sizeof(*data));
6287 data->interface = interface;
6288 data->path = g_strdup(interface->path);
6289 data->callback = callback;
6290 data->user_data = user_data;
6292 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6293 SUPPLICANT_INTERFACE,
6295 interface_remove_params,
6296 interface_remove_result, data,
6305 static void interface_scan_result(const char *error,
6306 DBusMessageIter *iter, void *user_data)
6308 struct interface_scan_data *data = user_data;
6312 SUPPLICANT_DBG("error %s", error);
6316 /* A non ready interface cannot send/receive anything */
6317 if (interface_exists(data->interface, data->path)) {
6318 if (!data->interface->ready)
6326 data->callback(err, data->interface, data->user_data);
6328 data->interface->scan_callback = data->callback;
6329 data->interface->scan_data = data->user_data;
6332 if (data->scan_params)
6333 g_supplicant_free_scan_params(data->scan_params);
6338 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
6340 DBusMessageIter data;
6341 unsigned int width = 0; /* Not used by wpa_supplicant atm */
6343 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
6345 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
6346 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
6348 dbus_message_iter_close_container(iter, &data);
6351 static void add_scan_frequencies(DBusMessageIter *iter,
6354 GSupplicantScanParams *scan_data = user_data;
6358 for (i = 0; i < scan_data->num_freqs; i++) {
6359 freq = scan_data->freqs[i];
6363 add_scan_frequency(iter, freq);
6367 static void append_ssid(DBusMessageIter *iter,
6368 const void *ssid, unsigned int len)
6370 DBusMessageIter array;
6372 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
6373 DBUS_TYPE_BYTE_AS_STRING, &array);
6375 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
6377 dbus_message_iter_close_container(iter, &array);
6380 static void append_ssids(DBusMessageIter *iter, void *user_data)
6382 GSupplicantScanParams *scan_data = user_data;
6385 for (list = scan_data->ssids; list; list = list->next) {
6386 struct scan_ssid *scan_ssid = list->data;
6388 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
6392 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
6393 supplicant_dbus_array_function function,
6396 GSupplicantScanParams *scan_params = user_data;
6397 DBusMessageIter entry, value, array;
6398 const char *key = "Channels";
6400 if (scan_params->freqs && scan_params->freqs[0] != 0) {
6401 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
6404 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
6406 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
6407 DBUS_TYPE_ARRAY_AS_STRING
6408 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6409 DBUS_TYPE_UINT32_AS_STRING
6410 DBUS_TYPE_UINT32_AS_STRING
6411 DBUS_STRUCT_END_CHAR_AS_STRING,
6414 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
6415 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6416 DBUS_TYPE_UINT32_AS_STRING
6417 DBUS_TYPE_UINT32_AS_STRING
6418 DBUS_STRUCT_END_CHAR_AS_STRING,
6422 function(&array, user_data);
6424 dbus_message_iter_close_container(&value, &array);
6425 dbus_message_iter_close_container(&entry, &value);
6426 dbus_message_iter_close_container(dict, &entry);
6430 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
6432 DBusMessageIter dict;
6433 const char *type = "passive";
6434 struct interface_scan_data *data = user_data;
6436 supplicant_dbus_dict_open(iter, &dict);
6438 if (data && data->scan_params) {
6441 supplicant_dbus_dict_append_basic(&dict, "Type",
6442 DBUS_TYPE_STRING, &type);
6444 #if defined TIZEN_EXT
6445 SUPPLICANT_DBG("[specific_scan] num_ssids %d",
6446 data->scan_params->num_ssids);
6449 if (data->scan_params->ssids) {
6450 supplicant_dbus_dict_append_array(&dict, "SSIDs",
6455 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
6458 supplicant_dbus_dict_append_basic(&dict, "Type",
6459 DBUS_TYPE_STRING, &type);
6461 supplicant_dbus_dict_close(iter, &dict);
6464 static int interface_ready_to_scan(GSupplicantInterface *interface)
6469 if (!system_available)
6472 if (interface->scanning)
6475 switch (interface->state) {
6476 case G_SUPPLICANT_STATE_AUTHENTICATING:
6477 case G_SUPPLICANT_STATE_ASSOCIATING:
6478 case G_SUPPLICANT_STATE_ASSOCIATED:
6479 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
6480 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
6482 #if defined TIZEN_EXT
6483 case G_SUPPLICANT_STATE_DISABLED:
6485 case G_SUPPLICANT_STATE_UNKNOWN:
6487 case G_SUPPLICANT_STATE_UNKNOWN:
6488 case G_SUPPLICANT_STATE_DISABLED:
6490 case G_SUPPLICANT_STATE_DISCONNECTED:
6491 case G_SUPPLICANT_STATE_INACTIVE:
6492 case G_SUPPLICANT_STATE_SCANNING:
6493 case G_SUPPLICANT_STATE_COMPLETED:
6500 #if defined TIZEN_EXT_WIFI_MESH
6501 static void interface_abort_scan_result(const char *error,
6502 DBusMessageIter *iter, void *user_data)
6504 struct interface_scan_data *data = user_data;
6508 SUPPLICANT_DBG("error %s", error);
6515 data->callback(err, data->interface, data->user_data);
6520 int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
6521 GSupplicantInterfaceCallback callback, void *user_data)
6523 struct interface_scan_data *data;
6526 if (!interface->scanning)
6529 data = dbus_malloc0(sizeof(*data));
6533 data->interface = interface;
6534 data->path = g_strdup(interface->path);
6535 data->callback = callback;
6536 data->user_data = user_data;
6538 ret = supplicant_dbus_method_call(interface->path,
6539 SUPPLICANT_INTERFACE ".Interface", "AbortScan", NULL,
6540 interface_abort_scan_result, data, interface);
6551 int g_supplicant_interface_scan(GSupplicantInterface *interface,
6552 GSupplicantScanParams *scan_data,
6553 GSupplicantInterfaceCallback callback,
6556 struct interface_scan_data *data;
6559 ret = interface_ready_to_scan(interface);
6563 data = dbus_malloc0(sizeof(*data));
6567 data->interface = interface;
6568 data->path = g_strdup(interface->path);
6569 #if defined TIZEN_EXT
6570 data->interface->scan_callback = data->callback = callback;
6571 data->interface->scan_data = data->user_data = user_data;
6573 data->callback = callback;
6574 data->user_data = user_data;
6576 data->scan_params = scan_data;
6578 interface->scan_callback = callback;
6579 interface->scan_data = user_data;
6581 ret = supplicant_dbus_method_call(interface->path,
6582 SUPPLICANT_INTERFACE ".Interface", "Scan",
6583 interface_scan_params, interface_scan_result, data,
6594 #if defined TIZEN_EXT
6595 static void interface_signalpoll_result(const char *error,
6596 DBusMessageIter *iter, void *user_data)
6598 struct interface_signalpoll_data *data = user_data;
6600 dbus_int32_t maxspeed = 0;
6601 dbus_int32_t strength = 0;
6602 dbus_int32_t snr = 0;
6603 dbus_uint32_t est_throughput = 0;
6604 DBusMessageIter sub_iter, dict;
6608 SUPPLICANT_DBG("error: %s", error);
6612 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
6614 SUPPLICANT_DBG("invalid reply");
6618 dbus_message_iter_recurse(iter, &sub_iter);
6619 dbus_message_iter_recurse(&sub_iter, &dict);
6621 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
6622 DBusMessageIter entry, value;
6625 dbus_message_iter_recurse(&dict, &entry);
6626 dbus_message_iter_get_basic(&entry, &key);
6627 dbus_message_iter_next(&entry);
6628 dbus_message_iter_recurse(&entry, &value);
6630 switch (dbus_message_iter_get_arg_type(&value)) {
6631 case DBUS_TYPE_INT32:
6632 if (g_strcmp0(key, "linkspeed") == 0) {
6633 dbus_message_iter_get_basic(&value, &maxspeed);
6634 SUPPLICANT_DBG("linkspeed = %d", maxspeed);
6635 } else if (g_strcmp0(key, "rssi") == 0) {
6636 dbus_message_iter_get_basic(&value, &strength);
6637 SUPPLICANT_DBG("Strength = %d", strength);
6638 } else if (g_strcmp0(key, "SNR") == 0) {
6639 dbus_message_iter_get_basic(&value, &snr);
6640 SUPPLICANT_DBG("SNR = %d", snr);
6643 case DBUS_TYPE_UINT32:
6644 if (g_strcmp0(key, "est_throughput") == 0) {
6645 dbus_message_iter_get_basic(&value, &est_throughput);
6646 SUPPLICANT_DBG("est_throughput = %u", est_throughput);
6650 dbus_message_iter_next(&dict);
6655 data->callback(err, maxspeed, strength, snr, data->user_data, est_throughput);
6661 int g_supplicant_interface_signalpoll(GSupplicantInterface *interface,
6662 GSupplicantMaxSpeedCallback callback,
6665 struct interface_signalpoll_data *data;
6671 if (!system_available)
6674 data = dbus_malloc0(sizeof(*data));
6678 data->interface = interface;
6679 data->path = g_strdup(interface->path);
6680 data->callback = callback;
6681 data->user_data = user_data;
6683 ret = supplicant_dbus_method_call(interface->path,
6684 SUPPLICANT_INTERFACE ".Interface", "SignalPoll",
6685 NULL, interface_signalpoll_result, data,
6697 static int parse_supplicant_error(DBusMessageIter *iter)
6699 int err = -ECONNABORTED;
6705 /* If the given passphrase is malformed wpa_s returns
6706 * "invalid message format" but this error should be interpreted as
6709 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
6710 dbus_message_iter_get_basic(iter, &key);
6711 if (strncmp(key, "psk", 3) == 0 ||
6712 strncmp(key, "wep_key", 7) == 0 ||
6713 strcmp(key, "invalid message format") == 0) {
6717 dbus_message_iter_next(iter);
6723 static void interface_select_network_result(const char *error,
6724 DBusMessageIter *iter, void *user_data)
6726 struct interface_connect_data *data = user_data;
6733 #if defined TIZEN_EXT
6734 SUPPLICANT_DBG("SelectNetwork errorFreq %s", error);
6736 SUPPLICANT_DBG("SelectNetwork error %s", error);
6738 err = parse_supplicant_error(iter);
6744 data->callback(err, data->interface, data->user_data);
6746 #if defined TIZEN_EXT
6747 g_free(data->ssid->ssid);
6748 if (data->ssid->is_passphrase_alloc)
6749 g_free((char *)data->ssid->passphrase);
6750 if (data->ssid->is_connector_alloc)
6751 g_free((char *)data->ssid->connector);
6752 if (data->ssid->is_c_sign_key_alloc)
6753 g_free((char *)data->ssid->c_sign_key);
6754 if (data->ssid->is_net_access_key_alloc)
6755 g_free((char *)data->ssid->net_access_key);
6761 static void interface_select_network_params(DBusMessageIter *iter,
6764 struct interface_connect_data *data = user_data;
6765 GSupplicantInterface *interface = data->interface;
6766 #if defined TIZEN_EXT
6767 GSupplicantSSID *ssid = data->ssid;
6770 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6771 &interface->network_path);
6772 #if defined TIZEN_EXT
6773 if (!ssid->bssid_for_connect_len)
6774 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
6778 static void interface_add_network_result(const char *error,
6779 DBusMessageIter *iter, void *user_data)
6781 struct interface_connect_data *data = user_data;
6782 GSupplicantInterface *interface = data->interface;
6789 dbus_message_iter_get_basic(iter, &path);
6793 SUPPLICANT_DBG("PATH: %s", path);
6795 #if defined TIZEN_EXT
6796 if (interface->network_path)
6797 g_free(interface->network_path);
6799 interface->network_path = g_strdup(path);
6801 store_network_information(interface, data->ssid);
6803 #if defined TIZEN_EXT
6804 SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
6805 GSupplicantSSID *ssid = data->ssid;
6807 if (!ssid->bssid_for_connect_len)
6808 supplicant_dbus_method_call(data->interface->path,
6809 SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
6810 interface_select_network_params,
6811 interface_select_network_result, data,
6814 supplicant_dbus_method_call(data->interface->path,
6815 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6816 interface_select_network_params,
6817 interface_select_network_result, data,
6820 supplicant_dbus_method_call(data->interface->path,
6821 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6822 interface_select_network_params,
6823 interface_select_network_result, data,
6830 SUPPLICANT_DBG("AddNetwork error %s", error);
6832 if (interface_exists(data->interface, data->interface->path)) {
6833 err = parse_supplicant_error(iter);
6835 data->callback(err, data->interface, data->user_data);
6837 g_free(interface->network_path);
6838 interface->network_path = NULL;
6842 #if defined TIZEN_EXT
6843 g_free(data->ssid->ssid);
6844 if (data->ssid->is_passphrase_alloc)
6845 g_free((char *)data->ssid->passphrase);
6846 if (data->ssid->is_connector_alloc)
6847 g_free((char *)data->ssid->connector);
6848 if (data->ssid->is_c_sign_key_alloc)
6849 g_free((char *)data->ssid->c_sign_key);
6850 if (data->ssid->is_net_access_key_alloc)
6851 g_free((char *)data->ssid->net_access_key);
6857 static void add_network_security_none(DBusMessageIter *dict)
6859 const char *auth_alg = "OPEN";
6861 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6862 DBUS_TYPE_STRING, &auth_alg);
6865 static void add_network_security_wep(DBusMessageIter *dict,
6866 GSupplicantSSID *ssid)
6868 const char *auth_alg = "OPEN SHARED";
6869 dbus_uint32_t key_index = 0;
6871 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6872 DBUS_TYPE_STRING, &auth_alg);
6874 if (ssid->passphrase) {
6875 int size = strlen(ssid->passphrase);
6876 if (size == 10 || size == 26) {
6877 unsigned char *key = g_try_malloc(13);
6881 memset(tmp, 0, sizeof(tmp));
6885 for (i = 0; i < size / 2; i++) {
6886 memcpy(tmp, ssid->passphrase + (i * 2), 2);
6887 key[i] = (unsigned char) strtol(tmp, NULL, 16);
6890 supplicant_dbus_dict_append_fixed_array(dict,
6895 } else if (size == 5 || size == 13) {
6896 unsigned char *key = g_try_malloc(13);
6902 for (i = 0; i < size; i++)
6903 key[i] = (unsigned char) ssid->passphrase[i];
6905 supplicant_dbus_dict_append_fixed_array(dict,
6911 supplicant_dbus_dict_append_basic(dict,
6916 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
6917 DBUS_TYPE_UINT32, &key_index);
6921 static dbus_bool_t is_psk_raw_key(const char *psk)
6925 /* A raw key is always 64 bytes length... */
6926 if (strlen(psk) != 64)
6929 /* ... and its content is in hex representation */
6930 for (i = 0; i < 64; i++)
6931 if (!isxdigit((unsigned char) psk[i]))
6937 static unsigned char hexchar2bin(char c)
6939 if ((c >= '0') && (c <= '9'))
6941 else if ((c >= 'A') && (c <= 'F'))
6942 return c - 'A' + 10;
6943 else if ((c >= 'a') && (c <= 'f'))
6944 return c - 'a' + 10;
6949 static void hexstring2bin(const char *string, unsigned char *data,
6954 for (i = 0; i < data_len; i++)
6955 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
6956 hexchar2bin(string[i * 2 + 1]) << 0);
6959 static void add_network_security_psk(DBusMessageIter *dict,
6960 GSupplicantSSID *ssid)
6962 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
6963 const char *key = "psk";
6965 if (is_psk_raw_key(ssid->passphrase)) {
6966 unsigned char data[32];
6967 unsigned char *datap = data;
6969 /* The above pointer alias is required by D-Bus because
6970 * with D-Bus and GCC, non-heap-allocated arrays cannot
6971 * be passed directly by their base pointer. */
6973 hexstring2bin(ssid->passphrase, datap, sizeof(data));
6975 supplicant_dbus_dict_append_fixed_array(dict,
6976 key, DBUS_TYPE_BYTE,
6977 &datap, sizeof(data));
6979 supplicant_dbus_dict_append_basic(dict,
6980 key, DBUS_TYPE_STRING,
6985 static void add_network_security_tls(DBusMessageIter *dict,
6986 GSupplicantSSID *ssid)
6989 * For TLS, we at least need:
6990 * The client certificate
6991 * The client private key file
6992 * The client private key file password
6994 * The Authority certificate is optional.
6996 if (!ssid->client_cert_path)
6999 if (!ssid->private_key_path)
7002 if (!ssid->private_key_passphrase)
7005 if (ssid->ca_cert_path)
7006 supplicant_dbus_dict_append_basic(dict, "ca_cert",
7007 DBUS_TYPE_STRING, &ssid->ca_cert_path);
7009 supplicant_dbus_dict_append_basic(dict, "private_key",
7011 &ssid->private_key_path);
7012 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
7014 &ssid->private_key_passphrase);
7015 supplicant_dbus_dict_append_basic(dict, "client_cert",
7017 &ssid->client_cert_path);
7020 static void add_network_security_peap(DBusMessageIter *dict,
7021 GSupplicantSSID *ssid)
7026 * For PEAP/TTLS, we at least need
7027 * The authority certificate
7028 * The 2nd phase authentication method
7029 * The 2nd phase passphrase
7031 * The Client certificate is optional although strongly recommended
7032 * When setting it, we need in addition
7033 * The Client private key file
7034 * The Client private key file password
7036 if (!ssid->passphrase)
7039 if (!ssid->phase2_auth)
7042 if (ssid->client_cert_path) {
7043 if (!ssid->private_key_path)
7046 #if !defined TIZEN_EXT
7047 if (!ssid->private_key_passphrase)
7051 supplicant_dbus_dict_append_basic(dict, "client_cert",
7053 &ssid->client_cert_path);
7055 supplicant_dbus_dict_append_basic(dict, "private_key",
7057 &ssid->private_key_path);
7059 #if !defined TIZEN_EXT
7060 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
7062 &ssid->private_key_passphrase);
7067 if(g_strcmp0(ssid->phase2_auth, "GTC") == 0 && g_strcmp0(ssid->eap, "ttls") == 0)
7068 phase2_auth = g_strdup_printf("autheap=%s", ssid->phase2_auth);
7069 else if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
7070 phase2_auth = g_strdup_printf("autheap=%s",
7071 ssid->phase2_auth + strlen("EAP-"));
7073 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
7075 supplicant_dbus_dict_append_basic(dict, "password",
7079 if (ssid->ca_cert_path)
7080 supplicant_dbus_dict_append_basic(dict, "ca_cert",
7082 &ssid->ca_cert_path);
7084 supplicant_dbus_dict_append_basic(dict, "phase2",
7088 g_free(phase2_auth);
7091 #if defined TIZEN_EXT
7092 static void add_network_security_aka_sim(DBusMessageIter *dict,
7093 GSupplicantSSID *ssid)
7095 if (!ssid->passphrase)
7098 supplicant_dbus_dict_append_basic(dict, "password",
7103 static void add_network_security_fast(DBusMessageIter *dict,
7104 GSupplicantSSID *ssid)
7107 * For FAST, we at least need:
7109 * phase1 (provisiong information)
7113 /* Allow provisioing both authenticated and unauthenticated */
7114 const char *phase1 = "fast_provisioning=2";
7115 supplicant_dbus_dict_append_basic(dict, "phase1",
7119 SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
7121 supplicant_dbus_dict_append_basic(dict, "pac_file",
7125 supplicant_dbus_dict_append_basic(dict, "password",
7131 static void add_network_security_eap(DBusMessageIter *dict,
7132 GSupplicantSSID *ssid)
7136 #if defined TIZEN_EXT
7139 if (!ssid->eap || !ssid->identity)
7143 if (g_strcmp0(ssid->eap, "tls") == 0) {
7144 add_network_security_tls(dict, ssid);
7145 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
7146 g_strcmp0(ssid->eap, "ttls") == 0) {
7147 #if defined TIZEN_EXT
7148 if (!ssid->identity)
7151 add_network_security_peap(dict, ssid);
7153 #if defined TIZEN_EXT
7154 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
7155 g_strcmp0(ssid->eap, "aka") == 0 ||
7156 g_strcmp0(ssid->eap, "aka'") == 0) {
7157 add_network_security_aka_sim(dict, ssid);
7158 } else if (g_strcmp0(ssid->eap, "pwd") == 0) {
7159 if(!ssid->passphrase)
7161 supplicant_dbus_dict_append_basic(dict, "password",
7164 } else if (g_strcmp0(ssid->eap, "fast") == 0){
7165 if (!ssid->identity || !ssid->passphrase)
7168 add_network_security_fast(dict, ssid);
7173 eap_value = g_ascii_strup(ssid->eap, -1);
7175 supplicant_dbus_dict_append_basic(dict, "eap",
7178 #if defined TIZEN_EXT
7179 if (ssid->identity != NULL)
7180 supplicant_dbus_dict_append_basic(dict, "identity",
7184 supplicant_dbus_dict_append_basic(dict, "identity",
7188 if(ssid->anonymous_identity)
7189 supplicant_dbus_dict_append_basic(dict, "anonymous_identity",
7191 &ssid->anonymous_identity);
7193 if(ssid->subject_match)
7194 supplicant_dbus_dict_append_basic(dict, "subject_match",
7196 &ssid->subject_match);
7198 if(ssid->altsubject_match)
7199 supplicant_dbus_dict_append_basic(dict, "altsubject_match",
7201 &ssid->altsubject_match);
7203 if(ssid->domain_suffix_match)
7204 supplicant_dbus_dict_append_basic(dict, "domain_suffix_match",
7206 &ssid->domain_suffix_match);
7208 if(ssid->domain_match)
7209 supplicant_dbus_dict_append_basic(dict, "domain_match",
7211 &ssid->domain_match);
7216 static void add_network_security_ciphers(DBusMessageIter *dict,
7217 GSupplicantSSID *ssid)
7219 unsigned int p_cipher, g_cipher, i;
7220 char *pairwise, *group;
7221 char *pair_ciphers[4];
7222 char *group_ciphers[5];
7224 p_cipher = ssid->pairwise_cipher;
7225 g_cipher = ssid->group_cipher;
7227 if (p_cipher == 0 && g_cipher == 0)
7232 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
7233 pair_ciphers[i++] = "CCMP";
7235 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
7236 pair_ciphers[i++] = "TKIP";
7238 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
7239 pair_ciphers[i++] = "NONE";
7241 pair_ciphers[i] = NULL;
7245 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
7246 group_ciphers[i++] = "CCMP";
7248 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
7249 group_ciphers[i++] = "TKIP";
7251 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
7252 group_ciphers[i++] = "WEP104";
7254 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
7255 group_ciphers[i++] = "WEP40";
7257 group_ciphers[i] = NULL;
7259 pairwise = g_strjoinv(" ", pair_ciphers);
7260 group = g_strjoinv(" ", group_ciphers);
7262 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
7264 supplicant_dbus_dict_append_basic(dict, "pairwise",
7267 supplicant_dbus_dict_append_basic(dict, "group",
7275 static void add_network_security_proto(DBusMessageIter *dict,
7276 GSupplicantSSID *ssid)
7278 unsigned int protocol, i;
7282 protocol = ssid->protocol;
7289 if (protocol & G_SUPPLICANT_PROTO_RSN)
7290 protos[i++] = "RSN";
7292 if (protocol & G_SUPPLICANT_PROTO_WPA)
7293 protos[i++] = "WPA";
7297 proto = g_strjoinv(" ", protos);
7299 SUPPLICANT_DBG("proto %s", proto);
7301 supplicant_dbus_dict_append_basic(dict, "proto",
7308 #if defined TIZEN_EXT
7309 static void add_network_security_connector(DBusMessageIter *dict, GSupplicantSSID *ssid)
7311 if (ssid->connector && strlen(ssid->connector) > 0) {
7312 const char *key = "dpp_connector";
7314 supplicant_dbus_dict_append_basic(dict,
7315 key, DBUS_TYPE_STRING,
7320 static size_t convert_hexstr_to_bin(const char *hex_str, unsigned char **bin)
7322 unsigned char *bin_res = NULL;
7323 unsigned int i, j, hex;
7326 if (!hex_str || strlen(hex_str) == 0)
7329 hex_str_len = strlen(hex_str);
7330 bin_res = g_try_malloc0(hex_str_len / 2);
7335 for (i = 0; i < hex_str_len; i+=2) {
7336 sscanf(hex_str + i, "%02x", &hex);
7341 return hex_str_len / 2;
7344 static void add_network_security_c_sign_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7346 if (ssid->c_sign_key && strlen(ssid->c_sign_key) > 0) {
7347 const char *key = "dpp_csign";
7348 unsigned char *bin_csign = NULL;
7349 size_t bin_csign_len = convert_hexstr_to_bin(ssid->c_sign_key, &bin_csign);
7350 if (bin_csign_len != 0)
7351 supplicant_dbus_dict_append_fixed_array(dict,
7352 key, DBUS_TYPE_BYTE,
7353 &bin_csign, bin_csign_len);
7358 static void add_network_security_net_access_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7360 if (ssid->net_access_key && strlen(ssid->net_access_key) > 0) {
7361 const char *key = "dpp_netaccesskey";
7362 unsigned char *bin_netaccesskey = NULL;
7363 size_t bin_netaccesskey_len = convert_hexstr_to_bin(ssid->net_access_key, &bin_netaccesskey);
7364 if (bin_netaccesskey_len != 0)
7365 supplicant_dbus_dict_append_fixed_array(dict,
7366 key, DBUS_TYPE_BYTE,
7367 &bin_netaccesskey, bin_netaccesskey_len);
7368 g_free(bin_netaccesskey);
7374 static void add_network_ieee80211w(DBusMessageIter *dict, GSupplicantSSID *ssid,
7375 GSupplicantMfpOptions ieee80211w)
7377 #if defined TIZEN_EXT
7378 if (ssid->security != G_SUPPLICANT_SECURITY_OWE
7379 && ssid->security != G_SUPPLICANT_SECURITY_PSK_SHA256
7380 && ssid->security != G_SUPPLICANT_SECURITY_DPP)
7383 supplicant_dbus_dict_append_basic(dict, "ieee80211w", DBUS_TYPE_UINT32,
7387 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
7389 GSupplicantMfpOptions ieee80211w;
7392 switch (ssid->security) {
7393 case G_SUPPLICANT_SECURITY_NONE:
7395 add_network_security_none(dict);
7396 add_network_security_ciphers(dict, ssid);
7398 case G_SUPPLICANT_SECURITY_UNKNOWN:
7399 case G_SUPPLICANT_SECURITY_WEP:
7401 add_network_security_wep(dict, ssid);
7402 add_network_security_ciphers(dict, ssid);
7404 case G_SUPPLICANT_SECURITY_PSK:
7405 #if defined TIZEN_EXT
7406 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
7407 key_mgmt = "FT-PSK WPA-PSK";
7409 key_mgmt = "WPA-PSK";
7411 key_mgmt = "WPA-PSK";
7413 add_network_security_psk(dict, ssid);
7414 add_network_security_ciphers(dict, ssid);
7415 add_network_security_proto(dict, ssid);
7417 case G_SUPPLICANT_SECURITY_IEEE8021X:
7418 key_mgmt = "WPA-EAP";
7419 add_network_security_eap(dict, ssid);
7420 add_network_security_ciphers(dict, ssid);
7421 add_network_security_proto(dict, ssid);
7423 #if defined TIZEN_EXT
7424 case G_SUPPLICANT_SECURITY_PSK_SHA256:
7425 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK)
7426 key_mgmt = "WPA-PSK-SHA256 WPA-PSK";
7428 key_mgmt = "WPA-PSK-SHA256";
7429 add_network_security_psk(dict, ssid);
7430 add_network_security_ciphers(dict, ssid);
7431 add_network_security_proto(dict, ssid);
7433 case G_SUPPLICANT_SECURITY_FT_PSK:
7434 key_mgmt = "FT-PSK";
7435 add_network_security_psk(dict, ssid);
7436 add_network_security_ciphers(dict, ssid);
7437 add_network_security_proto(dict, ssid);
7439 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
7440 key_mgmt = "FT-EAP";
7441 add_network_security_eap(dict, ssid);
7442 add_network_security_ciphers(dict, ssid);
7443 add_network_security_proto(dict, ssid);
7445 case G_SUPPLICANT_SECURITY_SAE:
7446 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_FT_SAE) {
7447 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
7448 key_mgmt = "FT-SAE SAE";
7450 key_mgmt = "FT-SAE";
7452 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK) {
7453 key_mgmt = "SAE WPA-PSK";
7454 ieee80211w = G_SUPPLICANT_MFP_OPTIONAL;
7457 ieee80211w = G_SUPPLICANT_MFP_REQUIRED;
7459 add_network_ieee80211w(dict, ssid, ieee80211w);
7461 add_network_security_psk(dict, ssid);
7463 case G_SUPPLICANT_SECURITY_OWE:
7465 add_network_security_ciphers(dict, ssid);
7466 add_network_security_proto(dict, ssid);
7468 case G_SUPPLICANT_SECURITY_DPP:
7470 add_network_security_connector(dict, ssid);
7471 add_network_security_c_sign_key(dict, ssid);
7472 add_network_security_net_access_key(dict, ssid);
7477 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
7478 DBUS_TYPE_STRING, &key_mgmt);
7481 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
7485 switch (ssid->mode) {
7486 case G_SUPPLICANT_MODE_UNKNOWN:
7487 case G_SUPPLICANT_MODE_INFRA:
7490 case G_SUPPLICANT_MODE_IBSS:
7493 case G_SUPPLICANT_MODE_MASTER:
7496 #if defined TIZEN_EXT_WIFI_MESH
7497 case G_SUPPLICANT_MODE_MESH:
7503 supplicant_dbus_dict_append_basic(dict, "mode",
7504 DBUS_TYPE_UINT32, &mode);
7507 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
7509 DBusMessageIter dict;
7510 struct interface_connect_data *data = user_data;
7511 GSupplicantSSID *ssid = data->ssid;
7512 #if defined TIZEN_EXT
7513 GSupplicantInterface *interface = data->interface;
7516 supplicant_dbus_dict_open(iter, &dict);
7518 if (ssid->scan_ssid)
7519 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
7520 DBUS_TYPE_UINT32, &ssid->scan_ssid);
7523 supplicant_dbus_dict_append_basic(&dict, "frequency",
7524 DBUS_TYPE_UINT32, &ssid->freq);
7527 supplicant_dbus_dict_append_basic(&dict, "bgscan",
7528 DBUS_TYPE_STRING, &ssid->bgscan);
7530 add_network_mode(&dict, ssid);
7532 add_network_security(&dict, ssid);
7534 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
7535 DBUS_TYPE_BYTE, &ssid->ssid,
7538 #if defined TIZEN_EXT
7539 bool owe_transition_mode = FALSE;
7540 if ((ssid->security == G_SUPPLICANT_SECURITY_OWE) && !(ssid->keymgmt & G_SUPPLICANT_KEYMGMT_OWE))
7541 owe_transition_mode = TRUE;
7543 if (ssid->bssid && !owe_transition_mode) {
7545 bssid = g_try_malloc0(18);
7546 if (bssid == NULL) {
7547 SUPPLICANT_DBG("memory allocation error");
7548 supplicant_dbus_dict_close(iter, &dict);
7552 if (ssid->bssid_for_connect_len) {
7553 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid_for_connect));
7554 memcpy(interface->add_network_bssid, ssid->bssid_for_connect, WIFI_BSSID_LEN_MAX);
7556 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid));
7557 memcpy(interface->add_network_bssid, ssid->bssid, WIFI_BSSID_LEN_MAX);
7560 SUPPLICANT_DBG("bssid [" MACSTR "]", MAC2STR(interface->add_network_bssid));
7562 supplicant_dbus_dict_append_basic(&dict, "bssid",
7563 DBUS_TYPE_STRING, &bssid);
7568 supplicant_dbus_dict_close(iter, &dict);
7571 static void interface_wps_start_result(const char *error,
7572 DBusMessageIter *iter, void *user_data)
7574 struct interface_connect_data *data = user_data;
7581 SUPPLICANT_DBG("error: %s", error);
7582 err = parse_supplicant_error(iter);
7586 data->callback(err, data->interface, data->user_data);
7593 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
7595 struct interface_connect_data *data = user_data;
7596 GSupplicantSSID *ssid = data->ssid;
7597 const char *role = "enrollee", *type;
7598 DBusMessageIter dict;
7602 supplicant_dbus_dict_open(iter, &dict);
7604 supplicant_dbus_dict_append_basic(&dict, "Role",
7605 DBUS_TYPE_STRING, &role);
7608 if (ssid->pin_wps) {
7610 supplicant_dbus_dict_append_basic(&dict, "Pin",
7611 DBUS_TYPE_STRING, &ssid->pin_wps);
7614 supplicant_dbus_dict_append_basic(&dict, "Type",
7615 DBUS_TYPE_STRING, &type);
7617 #if defined TIZEN_EXT
7619 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
7620 DBUS_TYPE_BYTE, &ssid->bssid, 6);
7623 supplicant_dbus_dict_close(iter, &dict);
7626 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
7628 struct interface_connect_data *data = user_data;
7633 SUPPLICANT_DBG("error: %s", error);
7640 #if defined TIZEN_EXT
7641 GSupplicantSSID *ssid = data->ssid;
7642 if (ssid->pin_wps != NULL) {
7643 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
7644 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
7651 supplicant_dbus_method_call(data->interface->path,
7652 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
7653 interface_add_wps_params,
7654 interface_wps_start_result, data, NULL);
7657 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
7659 dbus_bool_t credentials = TRUE;
7663 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
7667 #if defined TIZEN_EXT
7668 #define NETCONFIG_SERVICE "net.netconfig"
7669 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
7670 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
7672 struct dec_method_call_data {
7673 struct interface_connect_data *data;
7674 DBusPendingCall *pending_call;
7677 static struct dec_method_call_data decrypt_request_data;
7679 static void crypt_method_call_cancel(void)
7681 if (decrypt_request_data.pending_call) {
7682 dbus_pending_call_cancel(decrypt_request_data.pending_call);
7683 dbus_pending_call_unref(decrypt_request_data.pending_call);
7684 decrypt_request_data.pending_call = NULL;
7687 g_free(decrypt_request_data.data->path);
7688 g_free(decrypt_request_data.data->ssid);
7689 dbus_free(decrypt_request_data.data);
7690 decrypt_request_data.data = NULL;
7693 static void decryption_request_reply(DBusPendingCall *call,
7698 DBusMessageIter args;
7701 struct interface_connect_data *data = user_data;
7705 reply = dbus_pending_call_steal_reply(call);
7707 dbus_error_init(&error);
7708 if (dbus_set_error_from_message(&error, reply)) {
7709 SUPPLICANT_DBG("decryption_request_reply() %s %s", error.name, error.message);
7710 dbus_error_free(&error);
7715 if (!g_str_has_prefix(data->interface->path, "/")) {
7716 SUPPLICANT_DBG("Invalid path %s", data->interface->path);
7721 if (dbus_message_iter_init(reply, &args) == FALSE) {
7722 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7727 dbus_message_iter_get_basic(&args, &out_data);
7728 data->ssid->passphrase = g_strdup((const gchar *)out_data);
7729 data->ssid->is_passphrase_alloc = true;
7731 ret = supplicant_dbus_method_call(data->interface->path,
7732 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7733 interface_add_network_params,
7734 interface_add_network_result, data,
7739 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7740 callback_assoc_failed(decrypt_request_data.data->user_data);
7742 g_free(data->ssid->ssid);
7743 if (data->ssid->is_passphrase_alloc)
7744 g_free((char *)data->ssid->passphrase);
7745 if (data->ssid->is_connector_alloc)
7746 g_free((char *)data->ssid->connector);
7747 if (data->ssid->is_c_sign_key_alloc)
7748 g_free((char *)data->ssid->c_sign_key);
7749 if (data->ssid->is_net_access_key_alloc)
7750 g_free((char *)data->ssid->net_access_key);
7755 dbus_message_unref(reply);
7756 dbus_pending_call_unref(call);
7758 decrypt_request_data.pending_call = NULL;
7759 decrypt_request_data.data = NULL;
7762 static int send_decryption_request(const char *passphrase,
7763 struct interface_connect_data *data)
7765 DBusMessage *msg = NULL;
7766 DBusPendingCall *call;
7768 SUPPLICANT_DBG("Decryption request");
7771 SUPPLICANT_DBG("Invalid parameter");
7778 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7779 NETCONFIG_WIFI_INTERFACE, "DecryptPassphrase");
7783 #if defined TIZEN_EXT
7784 if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7785 DBUS_TYPE_INVALID)) {
7786 SUPPLICANT_DBG("Could not fulfill decryption request");
7790 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7794 if (!dbus_connection_send_with_reply(connection, msg,
7795 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7796 dbus_message_unref(msg);
7801 dbus_message_unref(msg);
7805 decrypt_request_data.pending_call = call;
7806 decrypt_request_data.data = data;
7808 dbus_pending_call_set_notify(call, decryption_request_reply, data, NULL);
7809 dbus_message_unref(msg);
7811 SUPPLICANT_DBG("Decryption request succeeded");
7816 static void decrypt_conf_obj_reply(DBusPendingCall *call,
7821 DBusMessageIter iter, dict;
7824 struct interface_connect_data *data = user_data;
7826 reply = dbus_pending_call_steal_reply(call);
7828 dbus_error_init(&error);
7829 if (dbus_set_error_from_message(&error, reply)) {
7830 SUPPLICANT_DBG("decryption_conf_obj_reply() %s %s", error.name, error.message);
7831 dbus_error_free(&error);
7836 if (dbus_message_iter_init(reply, &iter) == FALSE) {
7837 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7842 dbus_message_iter_recurse(&iter, &dict);
7844 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
7845 DBusMessageIter entry, value;
7848 dbus_message_iter_recurse(&dict, &entry);
7849 dbus_message_iter_get_basic(&entry, &key);
7850 dbus_message_iter_next(&entry);
7851 dbus_message_iter_recurse(&entry, &value);
7852 if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
7853 if (g_strcmp0(key, "connector") == 0) {
7854 dbus_message_iter_get_basic(&value, &out_data);
7855 data->ssid->connector = g_strdup((const gchar *)out_data);
7856 data->ssid->is_connector_alloc = true;
7857 SUPPLICANT_DBG("connector %s", data->ssid->connector);
7858 } else if (g_strcmp0(key, "c_sign_key") == 0) {
7859 dbus_message_iter_get_basic(&value, &out_data);
7860 data->ssid->c_sign_key = g_strdup((const gchar *)out_data);
7861 data->ssid->is_c_sign_key_alloc = true;
7862 SUPPLICANT_DBG("c_sign_key %s", data->ssid->c_sign_key);
7863 } else if (g_strcmp0(key, "net_access_key") == 0) {
7864 dbus_message_iter_get_basic(&value, &out_data);
7865 data->ssid->net_access_key = g_strdup((const gchar *)out_data);
7866 data->ssid->is_net_access_key_alloc = true;
7867 SUPPLICANT_DBG("net_access_key %s", data->ssid->net_access_key);
7870 dbus_message_iter_next(&dict);
7873 ret = supplicant_dbus_method_call(data->interface->path,
7874 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7875 interface_add_network_params,
7876 interface_add_network_result, data,
7881 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7882 callback_assoc_failed(decrypt_request_data.data->user_data);
7884 g_free(data->ssid->ssid);
7885 if (data->ssid->is_connector_alloc)
7886 g_free((char *)data->ssid->connector);
7887 if (data->ssid->is_c_sign_key_alloc)
7888 g_free((char *)data->ssid->c_sign_key);
7889 if (data->ssid->is_net_access_key_alloc)
7890 g_free((char *)data->ssid->net_access_key);
7895 dbus_message_unref(reply);
7896 dbus_pending_call_unref(call);
7898 decrypt_request_data.pending_call = NULL;
7899 decrypt_request_data.data = NULL;
7902 static int send_decryption_conf_obj_request(GSupplicantSSID *ssid,
7903 struct interface_connect_data *data)
7905 DBusMessage *msg = NULL;
7906 DBusPendingCall *call;
7908 SUPPLICANT_DBG("Decryption configuration object request");
7911 SUPPLICANT_DBG("Invalid parameter");
7918 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7919 NETCONFIG_WIFI_INTERFACE, "DecryptConfObj");
7923 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->connector,
7925 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->c_sign_key,
7927 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->net_access_key,
7930 if (!dbus_connection_send_with_reply(connection, msg,
7931 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7932 dbus_message_unref(msg);
7937 dbus_message_unref(msg);
7941 decrypt_request_data.pending_call = call;
7942 decrypt_request_data.data = data;
7944 dbus_pending_call_set_notify(call, decrypt_conf_obj_reply, data, NULL);
7945 dbus_message_unref(msg);
7947 SUPPLICANT_DBG("Decrypt Conf Obj request succeeded");
7952 static bool is_valid_config_object(GSupplicantSSID *ssid)
7954 return ((ssid->connector &&
7955 g_strcmp0(ssid->connector, "") != 0) &&
7956 (ssid->c_sign_key &&
7957 g_strcmp0(ssid->c_sign_key, "") != 0) &&
7958 (ssid->net_access_key &&
7959 g_strcmp0(ssid->net_access_key, "") != 0));
7963 int g_supplicant_interface_connect(GSupplicantInterface *interface,
7964 GSupplicantSSID *ssid,
7965 GSupplicantInterfaceCallback callback,
7968 struct interface_connect_data *data;
7969 struct interface_data *intf_data;
7977 if (!system_available)
7980 /* TODO: Check if we're already connected and switch */
7982 data = dbus_malloc0(sizeof(*data));
7986 data->interface = interface;
7987 data->path = g_strdup(interface->path);
7988 data->callback = callback;
7990 data->user_data = user_data;
7992 if (ssid->use_wps) {
7993 g_free(interface->wps_cred.key);
7994 memset(&interface->wps_cred, 0,
7995 sizeof(struct _GSupplicantWpsCredentials));
7997 ret = supplicant_dbus_property_set(interface->path,
7998 SUPPLICANT_INTERFACE ".Interface.WPS",
7999 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
8000 wps_process_credentials, wps_start, data, interface);
8002 /* By the time there is a request for connect and the network
8003 * path is not NULL it means that connman has not removed the
8004 * previous network pointer. This can happen in the case AP
8005 * deauthenticated client and connman does not remove the
8006 * previously connected network pointer. This causes supplicant
8007 * to reallocate the memory for struct wpa_ssid again even if it
8008 * is the same SSID. This causes memory usage of wpa_supplicnat
8009 * to go high. The idea here is that if the previously connected
8010 * network is not removed at the time of next connection attempt
8011 * check if the network path is not NULL. In case it is non-NULL
8012 * first remove the network and then once removal is successful, add
8016 if (interface->network_path != NULL) {
8021 * If this add network is for the same network for
8022 * which wpa_supplicant already has a profile then do
8023 * not need to add another profile. Only if the
8024 * profile that needs to get added is different from
8025 * what is there in wpa_s delete the current one. A
8026 * network is identified by its SSID, security_type
8027 * and passphrase (private passphrase in case security
8030 if (compare_network_parameters(interface, ssid)) {
8034 intf_data = dbus_malloc0(sizeof(*intf_data));
8038 intf_data->interface = interface;
8039 intf_data->path = g_strdup(interface->path);
8040 intf_data->callback = callback;
8041 intf_data->ssid = ssid;
8042 intf_data->user_data = user_data;
8043 intf_data->network_remove_in_progress = TRUE;
8044 network_remove(intf_data);
8046 #if defined TIZEN_EXT
8047 if (ssid->passphrase &&
8048 g_strcmp0(ssid->passphrase, "") != 0 &&
8049 #if defined TIZEN_EXT_WIFI_MESH
8050 ssid->mode != G_SUPPLICANT_MODE_MESH &&
8053 ret = send_decryption_request(ssid->passphrase, data);
8055 SUPPLICANT_DBG("Decryption request failed %d", ret);
8056 } else if (is_valid_config_object(ssid)) {
8057 ret = send_decryption_conf_obj_request(ssid, data);
8059 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
8063 ret = supplicant_dbus_method_call(interface->path,
8064 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
8065 interface_add_network_params,
8066 interface_add_network_result, data,
8077 return -EINPROGRESS;
8080 static void network_remove_result(const char *error,
8081 DBusMessageIter *iter, void *user_data)
8083 struct interface_data *data = user_data;
8084 struct interface_connect_data *connect_data;
8091 SUPPLICANT_DBG("error: %s", error);
8093 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
8095 result = -ECONNABORTED;
8098 g_free(data->interface->network_path);
8099 data->interface->network_path = NULL;
8101 remove_network_information(data->interface);
8103 if (data->network_remove_in_progress == TRUE) {
8104 data->network_remove_in_progress = FALSE;
8105 connect_data = dbus_malloc0(sizeof(*connect_data));
8109 connect_data->interface = data->interface;
8110 connect_data->path = g_strdup(data->path);
8111 connect_data->callback = data->callback;
8112 connect_data->ssid = data->ssid;
8113 connect_data->user_data = data->user_data;
8115 #if defined TIZEN_EXT
8117 if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
8118 && !data->ssid->eap) {
8119 ret = send_decryption_request(data->ssid->passphrase, connect_data);
8121 SUPPLICANT_DBG("Decryption request failed %d", ret);
8122 g_free(connect_data->ssid);
8123 g_free(connect_data->path);
8124 dbus_free(connect_data);
8126 } else if (is_valid_config_object(data->ssid)) {
8127 ret = send_decryption_conf_obj_request(data->ssid, connect_data);
8129 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
8130 g_free(connect_data->ssid);
8131 g_free(connect_data->path);
8132 dbus_free(connect_data);
8136 supplicant_dbus_method_call(data->interface->path,
8137 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
8138 interface_add_network_params,
8139 interface_add_network_result, connect_data,
8140 connect_data->interface);
8143 data->callback(result, data->interface, data->user_data);
8149 static void network_remove_params(DBusMessageIter *iter, void *user_data)
8151 struct interface_data *data = user_data;
8152 const char *path = data->interface->network_path;
8154 SUPPLICANT_DBG("path %s", path);
8156 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
8159 static int network_remove(struct interface_data *data)
8161 GSupplicantInterface *interface = data->interface;
8165 #if defined TIZEN_EXT
8166 GSupplicantInterface *intf = NULL;
8168 * Check if 'interface' is valid
8170 intf = g_hash_table_lookup(interface_table, interface->path);
8175 return supplicant_dbus_method_call(interface->path,
8176 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
8177 network_remove_params, network_remove_result, data,
8181 static void interface_disconnect_result(const char *error,
8182 DBusMessageIter *iter, void *user_data)
8184 struct interface_data *data = user_data;
8191 SUPPLICANT_DBG("error: %s", error);
8193 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
8195 result = -ECONNABORTED;
8198 /* If we are disconnecting from previous WPS successful
8199 * association. i.e.: it did not went through AddNetwork,
8200 * and interface->network_path was never set. */
8201 if (!data->interface->network_path) {
8203 data->callback(result, data->interface,
8211 if (result < 0 && data->callback) {
8212 data->callback(result, data->interface, data->user_data);
8213 data->callback = NULL;
8216 if (result != -ECONNABORTED) {
8217 if (network_remove(data) < 0) {
8227 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
8228 GSupplicantInterfaceCallback callback,
8231 struct interface_data *data;
8239 if (!system_available)
8241 #if defined TIZEN_EXT
8242 if (decrypt_request_data.pending_call &&
8243 decrypt_request_data.data &&
8244 decrypt_request_data.data->user_data == user_data) {
8246 callback_assoc_failed(decrypt_request_data.data->user_data);
8247 crypt_method_call_cancel();
8252 data = dbus_malloc0(sizeof(*data));
8256 data->interface = interface;
8257 data->path = g_strdup(interface->path);
8258 data->callback = callback;
8259 data->user_data = user_data;
8261 ret = supplicant_dbus_method_call(interface->path,
8262 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
8263 NULL, interface_disconnect_result, data,
8274 #if defined TIZEN_EXT
8275 void g_supplicant_interface_remove_network(GSupplicantInterface *interface,
8276 GSupplicantSSID *ssid)
8278 struct interface_data *data;
8286 if (interface->network_path == NULL)
8289 if (!interface->network_info.ssid)
8292 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
8295 if (interface->network_info.security != ssid->security)
8298 data = dbus_malloc0(sizeof(*data));
8302 data->interface = interface;
8303 data->path = g_strdup(interface->path);
8305 ret = supplicant_dbus_method_call(interface->path,
8306 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
8307 network_remove_params, network_remove_result, data,
8317 static void interface_p2p_find_result(const char *error,
8318 DBusMessageIter *iter, void *user_data)
8320 struct interface_scan_data *data = user_data;
8323 SUPPLICANT_DBG("error %s", error);
8328 if (interface_exists(data->interface, data->path)) {
8329 if (!data->interface->ready)
8332 data->interface->p2p_finding = true;
8336 data->callback(err, data->interface, data->user_data);
8342 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
8344 DBusMessageIter dict;
8346 supplicant_dbus_dict_open(iter, &dict);
8347 supplicant_dbus_dict_close(iter, &dict);
8350 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
8351 GSupplicantInterfaceCallback callback,
8354 struct interface_scan_data *data;
8357 if (!interface->p2p_support)
8360 ret = interface_ready_to_scan(interface);
8361 if (ret && ret != -EALREADY)
8364 data = dbus_malloc0(sizeof(*data));
8368 data->interface = interface;
8369 data->path = g_strdup(interface->path);
8370 data->callback = callback;
8371 data->user_data = user_data;
8373 ret = supplicant_dbus_method_call(interface->path,
8374 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
8375 interface_p2p_find_params, interface_p2p_find_result,
8385 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
8390 return interface->p2p_finding;
8393 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
8395 if (!interface->p2p_finding)
8400 interface->p2p_finding = false;
8402 return supplicant_dbus_method_call(interface->path,
8403 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
8404 NULL, NULL, NULL, NULL);
8407 static void interface_p2p_connect_result(const char *error,
8408 DBusMessageIter *iter, void *user_data)
8410 struct interface_connect_data *data = user_data;
8416 SUPPLICANT_DBG("error: %s", error);
8417 err = parse_supplicant_error(iter);
8421 data->callback(err, data->interface, data->user_data);
8424 g_free(data->peer->wps_pin);
8425 g_free(data->peer->path);
8430 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
8432 struct interface_connect_data *data = user_data;
8433 const char *wps = "pbc";
8434 DBusMessageIter dict;
8439 supplicant_dbus_dict_open(iter, &dict);
8441 if (data->peer->master)
8444 if (data->peer->wps_pin)
8447 supplicant_dbus_dict_append_basic(&dict, "peer",
8448 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
8449 supplicant_dbus_dict_append_basic(&dict, "wps_method",
8450 DBUS_TYPE_STRING, &wps);
8451 if (data->peer->wps_pin) {
8452 supplicant_dbus_dict_append_basic(&dict, "pin",
8453 DBUS_TYPE_STRING, &data->peer->wps_pin);
8456 supplicant_dbus_dict_append_basic(&dict, "go_intent",
8457 DBUS_TYPE_INT32, &go_intent);
8459 supplicant_dbus_dict_close(iter, &dict);
8462 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
8463 GSupplicantPeerParams *peer_params,
8464 GSupplicantInterfaceCallback callback,
8467 struct interface_connect_data *data;
8472 if (!interface->p2p_support)
8475 data = dbus_malloc0(sizeof(*data));
8479 data->interface = interface;
8480 data->path = g_strdup(interface->path);
8481 data->peer = peer_params;
8482 data->callback = callback;
8483 data->user_data = user_data;
8485 ret = supplicant_dbus_method_call(interface->path,
8486 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
8487 interface_p2p_connect_params, interface_p2p_connect_result,
8495 return -EINPROGRESS;
8498 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
8499 GSupplicantPeerParams *peer_params)
8501 GSupplicantPeer *peer;
8507 if (!interface->p2p_support)
8510 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
8514 for (list = peer->groups; list; list = list->next, count++) {
8515 const char *group_obj_path = list->data;
8516 GSupplicantInterface *g_interface;
8517 GSupplicantGroup *group;
8519 group = g_hash_table_lookup(group_mapping, group_obj_path);
8520 if (!group || !group->interface)
8523 g_interface = group->interface;
8524 supplicant_dbus_method_call(g_interface->path,
8525 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8526 "Disconnect", NULL, NULL, NULL, g_interface);
8529 if (count == 0 && peer->current_group_iface) {
8530 supplicant_dbus_method_call(peer->current_group_iface->path,
8531 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8532 "Disconnect", NULL, NULL, NULL,
8533 peer->current_group_iface->path);
8536 peer->current_group_iface = NULL;
8538 return -EINPROGRESS;
8541 struct p2p_service_data {
8543 GSupplicantInterface *interface;
8544 GSupplicantP2PServiceParams *service;
8545 GSupplicantInterfaceCallback callback;
8549 static void interface_p2p_service_result(const char *error,
8550 DBusMessageIter *iter, void *user_data)
8552 struct p2p_service_data *data = user_data;
8555 SUPPLICANT_DBG("%s result - %s", data->registration ?
8556 "Registration" : "Deletion",
8557 error ? error : "Success");
8562 data->callback(result, data->interface, data->user_data);
8564 g_free(data->service->query);
8565 g_free(data->service->response);
8566 g_free(data->service->service);
8567 g_free(data->service->wfd_ies);
8568 g_free(data->service);
8572 static void interface_p2p_service_params(DBusMessageIter *iter,
8575 struct p2p_service_data *data = user_data;
8576 GSupplicantP2PServiceParams *service;
8577 DBusMessageIter dict;
8582 service = data->service;
8584 supplicant_dbus_dict_open(iter, &dict);
8586 if (service->query && service->response) {
8588 supplicant_dbus_dict_append_basic(&dict, "service_type",
8589 DBUS_TYPE_STRING, &type);
8590 supplicant_dbus_dict_append_fixed_array(&dict, "query",
8591 DBUS_TYPE_BYTE, &service->query,
8592 service->query_length);
8593 supplicant_dbus_dict_append_fixed_array(&dict, "response",
8594 DBUS_TYPE_BYTE, &service->response,
8595 service->response_length);
8596 } else if (service->version && service->service) {
8598 supplicant_dbus_dict_append_basic(&dict, "service_type",
8599 DBUS_TYPE_STRING, &type);
8600 supplicant_dbus_dict_append_basic(&dict, "version",
8601 DBUS_TYPE_INT32, &service->version);
8602 supplicant_dbus_dict_append_basic(&dict, "service",
8603 DBUS_TYPE_STRING, &service->service);
8606 supplicant_dbus_dict_close(iter, &dict);
8609 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
8610 GSupplicantInterfaceCallback callback,
8611 GSupplicantP2PServiceParams *p2p_service_params,
8614 struct p2p_service_data *data;
8619 if (!interface->p2p_support)
8622 data = dbus_malloc0(sizeof(*data));
8626 data->registration = true;
8627 data->interface = interface;
8628 data->service = p2p_service_params;
8629 data->callback = callback;
8630 data->user_data = user_data;
8632 ret = supplicant_dbus_method_call(interface->path,
8633 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
8634 interface_p2p_service_params, interface_p2p_service_result,
8641 return -EINPROGRESS;
8644 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
8645 GSupplicantP2PServiceParams *p2p_service_params)
8647 struct p2p_service_data *data;
8652 if (!interface->p2p_support)
8655 data = dbus_malloc0(sizeof(*data));
8659 data->interface = interface;
8660 data->service = p2p_service_params;
8662 ret = supplicant_dbus_method_call(interface->path,
8663 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
8664 interface_p2p_service_params, interface_p2p_service_result,
8671 return -EINPROGRESS;
8674 struct p2p_listen_data {
8679 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
8681 struct p2p_listen_data *params = user_data;
8682 DBusMessageIter dict;
8684 supplicant_dbus_dict_open(iter, &dict);
8686 supplicant_dbus_dict_append_basic(&dict, "period",
8687 DBUS_TYPE_INT32, ¶ms->period);
8688 supplicant_dbus_dict_append_basic(&dict, "interval",
8689 DBUS_TYPE_INT32, ¶ms->interval);
8690 supplicant_dbus_dict_close(iter, &dict);
8693 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
8694 int period, int interval)
8696 struct p2p_listen_data params;
8700 if (!interface->p2p_support)
8703 params.period = period;
8704 params.interval = interval;
8706 return supplicant_dbus_method_call(interface->path,
8707 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8708 "ExtendedListen", interface_p2p_listen_params,
8709 NULL, ¶ms, NULL);
8712 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
8714 struct p2p_service_data *data = user_data;
8715 GSupplicantP2PServiceParams *service = data->service;
8716 DBusMessageIter array;
8718 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
8720 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
8721 DBUS_TYPE_BYTE_AS_STRING, &array);
8723 if (service->wfd_ies && service->wfd_ies_length > 0) {
8724 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
8725 &service->wfd_ies, service->wfd_ies_length);
8728 dbus_message_iter_close_container(iter, &array);
8731 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
8732 GSupplicantInterfaceCallback callback,
8735 struct p2p_service_data *data;
8740 if (!system_available)
8743 data = dbus_malloc0(sizeof(*data));
8747 data->service = p2p_service_params;
8748 data->callback = callback;
8749 data->user_data = user_data;
8751 if (p2p_service_params->wfd_ies)
8752 data->registration = true;
8754 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
8755 SUPPLICANT_INTERFACE, "WFDIEs",
8756 DBUS_TYPE_ARRAY_AS_STRING
8757 DBUS_TYPE_BYTE_AS_STRING,
8759 interface_p2p_service_result,
8761 if (ret < 0 && ret != -EINPROGRESS) {
8766 return -EINPROGRESS;
8770 static const char *g_supplicant_rule0 = "type=signal,"
8771 "path=" DBUS_PATH_DBUS ","
8772 "sender=" DBUS_SERVICE_DBUS ","
8773 "interface=" DBUS_INTERFACE_DBUS ","
8774 "member=NameOwnerChanged,"
8775 "arg0=" SUPPLICANT_SERVICE;
8776 static const char *g_supplicant_rule1 = "type=signal,"
8777 "interface=" SUPPLICANT_INTERFACE;
8778 static const char *g_supplicant_rule2 = "type=signal,"
8779 "interface=" SUPPLICANT_INTERFACE ".Interface";
8780 static const char *g_supplicant_rule3 = "type=signal,"
8781 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
8782 static const char *g_supplicant_rule4 = "type=signal,"
8783 "interface=" SUPPLICANT_INTERFACE ".BSS";
8784 static const char *g_supplicant_rule5 = "type=signal,"
8785 "interface=" SUPPLICANT_INTERFACE ".Network";
8786 #if !defined TIZEN_EXT
8787 static const char *g_supplicant_rule6 = "type=signal,"
8788 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
8789 static const char *g_supplicant_rule7 = "type=signal,"
8790 "interface=" SUPPLICANT_INTERFACE ".Peer";
8791 static const char *g_supplicant_rule8 = "type=signal,"
8792 "interface=" SUPPLICANT_INTERFACE ".Group";
8794 #if defined TIZEN_EXT_WIFI_MESH
8795 static const char *g_supplicant_rule9 = "type=signal,"
8796 "interface=" SUPPLICANT_INTERFACE ".Interface.Mesh";
8799 static void invoke_introspect_method(void)
8801 DBusMessage *message;
8803 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
8805 DBUS_INTERFACE_INTROSPECTABLE,
8811 dbus_message_set_no_reply(message, TRUE);
8812 dbus_connection_send(connection, message, NULL);
8813 dbus_message_unref(message);
8816 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
8817 void g_supplicant_set_ins_settings(GSupplicantINSPreferredFreq preferred_freq_bssid,
8818 bool last_connected_bssid, bool assoc_reject, bool signal_bssid,
8819 unsigned int preferred_freq_bssid_score, unsigned int last_connected_bssid_score,
8820 unsigned int assoc_reject_score, int signal_level3_5ghz, int signal_level3_24ghz)
8822 ins_settings.preferred_freq_bssid = preferred_freq_bssid;
8823 ins_settings.last_connected_bssid = last_connected_bssid;
8824 ins_settings.assoc_reject = assoc_reject;
8825 ins_settings.signal_bssid = signal_bssid;
8826 ins_settings.preferred_freq_bssid_score = preferred_freq_bssid_score;
8827 ins_settings.last_connected_bssid_score = last_connected_bssid_score;
8828 ins_settings.assoc_reject_score = assoc_reject_score;
8829 ins_settings.signal_level3_5ghz = signal_level3_5ghz;
8830 ins_settings.signal_level3_24ghz = signal_level3_24ghz;
8832 SUPPLICANT_DBG("preferred_freq_bssid [%s]", preferred_freq_bssid ? "true" : "false");
8833 SUPPLICANT_DBG("preferred_freq_bssid_score [%d]", preferred_freq_bssid_score);
8834 SUPPLICANT_DBG("last_connected_bssid [%s]", last_connected_bssid ? "true" : "false");
8835 SUPPLICANT_DBG("last_connected_bssid_score [%d]", last_connected_bssid_score);
8836 SUPPLICANT_DBG("assoc_reject [%s]", assoc_reject ? "true" : "false");
8837 SUPPLICANT_DBG("assoc_reject_score [%d]", assoc_reject_score);
8838 SUPPLICANT_DBG("signal_bssid [%s]", signal_bssid ? "true" : "false");
8839 SUPPLICANT_DBG("signal_level3_5ghz [%d]", signal_level3_5ghz);
8840 SUPPLICANT_DBG("signal_level3_24ghz [%d]", signal_level3_24ghz);
8842 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
8844 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8845 void g_supplicant_register_eap_callback(g_supplicant_eap_callback cb)
8847 SUPPLICANT_DBG("g_supplicant_register_eap_callback %p", cb);
8849 if (!callbacks_pointer) {
8850 SUPPLICANT_DBG("callbacks_pointer is NULL");
8854 callbacks_pointer->eap = cb;
8857 void g_supplicant_unregister_eap_callback(void)
8859 SUPPLICANT_DBG("g_supplicant_unregister_eap_callback");
8861 if (!callbacks_pointer) {
8862 SUPPLICANT_DBG("callbacks_pointer is NULL");
8866 callbacks_pointer->eap = NULL;
8868 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8870 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8871 int g_supplicant_register(GSupplicantCallbacks *callbacks)
8872 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8873 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
8874 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8876 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8880 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
8882 dbus_connection_unref(connection);
8886 #if defined TIZEN_EXT
8887 simplified_log = connman_setting_get_bool("SimplifiedLog");
8889 callbacks_pointer = callbacks;
8892 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8893 NULL, remove_interface);
8895 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8897 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8899 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8901 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
8903 config_file_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8906 supplicant_dbus_setup(connection);
8908 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
8909 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
8910 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
8911 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
8912 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
8913 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
8914 #if defined TIZEN_EXT
8915 dbus_bus_add_match(connection,
8916 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
8917 "member=ChangeState", NULL);
8919 #if !defined TIZEN_EXT
8920 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
8921 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
8922 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
8924 #if defined TIZEN_EXT_WIFI_MESH
8925 dbus_bus_add_match(connection, g_supplicant_rule9, NULL);
8927 dbus_connection_flush(connection);
8929 if (dbus_bus_name_has_owner(connection,
8930 SUPPLICANT_SERVICE, NULL)) {
8931 system_available = TRUE;
8932 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
8933 SUPPLICANT_INTERFACE,
8934 service_property, NULL, NULL);
8936 invoke_introspect_method();
8938 SUPPLICANT_DBG("supplicant dbus setup completed");
8942 static void unregister_interface_remove_params(DBusMessageIter *iter,
8945 const char *path = user_data;
8947 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
8952 static void unregister_remove_interface(gpointer key, gpointer value,
8955 GSupplicantInterface *interface = value;
8957 supplicant_dbus_method_call(SUPPLICANT_PATH,
8958 SUPPLICANT_INTERFACE,
8960 unregister_interface_remove_params,
8961 NULL, interface->path, NULL);
8964 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
8969 #if defined TIZEN_EXT_WIFI_MESH
8970 dbus_bus_remove_match(connection, g_supplicant_rule9, NULL);
8972 #if !defined TIZEN_EXT
8973 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
8974 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
8975 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
8977 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
8978 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
8979 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
8980 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
8981 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
8982 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
8983 dbus_connection_flush(connection);
8985 dbus_connection_remove_filter(connection,
8986 g_supplicant_filter, NULL);
8989 if (config_file_table) {
8990 g_hash_table_destroy(config_file_table);
8991 config_file_table = NULL;
8995 g_hash_table_destroy(bss_mapping);
9000 g_hash_table_destroy(peer_mapping);
9001 peer_mapping = NULL;
9004 if (group_mapping) {
9005 g_hash_table_destroy(group_mapping);
9006 group_mapping = NULL;
9009 if (interface_table) {
9010 g_hash_table_foreach(interface_table,
9011 unregister_remove_interface, NULL);
9012 g_hash_table_destroy(interface_table);
9013 interface_table = NULL;
9016 if (system_available)
9017 callback_system_killed();
9020 dbus_connection_unref(connection);
9024 callbacks_pointer = NULL;
9029 struct supplicant_mac_policy {
9030 GSupplicantMacPolicyCallback callback;
9031 dbus_uint32_t policy;
9032 const void *user_data;
9035 static void mac_policy_result(const char *error,
9036 DBusMessageIter *iter, void *user_data)
9038 struct supplicant_mac_policy *data = user_data;
9045 SUPPLICANT_DBG("Mac policy setting failure %s", error);
9050 data->callback(result, data->policy,
9051 (void *) data->user_data);
9056 static void mac_policy_params(DBusMessageIter *iter, void *user_data)
9058 struct supplicant_mac_policy *data = user_data;
9060 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(data->policy));
9063 int g_supplicant_interface_set_mac_policy(GSupplicantInterface *interface,
9064 GSupplicantMacPolicyCallback callback,
9065 unsigned int policy,
9068 struct supplicant_mac_policy *data = NULL;
9071 if (!system_available)
9077 data = dbus_malloc0(sizeof(*data));
9081 data->callback = callback;
9082 data->policy = policy;
9083 data->user_data = user_data;
9085 ret = supplicant_dbus_property_set(interface->path,
9086 SUPPLICANT_INTERFACE ".Interface",
9087 "MacAddr", DBUS_TYPE_INT32_AS_STRING,
9088 mac_policy_params, mac_policy_result, data, NULL);
9090 SUPPLICANT_DBG("Unable to set MacAddr configuration");
9097 int g_supplicant_interface_set_preassoc_mac_policy(GSupplicantInterface *interface,
9098 GSupplicantMacPolicyCallback callback,
9099 unsigned int policy,
9102 struct supplicant_mac_policy *data;
9105 if (!system_available)
9111 data = dbus_malloc0(sizeof(*data));
9115 data->callback = callback;
9116 data->policy = policy;
9117 data->user_data = user_data;
9119 ret = supplicant_dbus_property_set(interface->path,
9120 SUPPLICANT_INTERFACE ".Interface",
9121 "PreassocMacAddr", DBUS_TYPE_INT32_AS_STRING,
9122 mac_policy_params, mac_policy_result, data, NULL);
9124 SUPPLICANT_DBG("Unable to set PreassocMacAddr configuration");
9131 struct supplicant_random_mac_lifetime {
9132 GSupplicantRandomMaclifetimeCallback callback;
9133 dbus_uint32_t lifetime;
9134 const void *user_data;
9137 static void random_mac_lifetime_result(const char *error,
9138 DBusMessageIter *iter, void *user_data)
9140 struct supplicant_random_mac_lifetime *data = user_data;
9147 SUPPLICANT_DBG("Random Mac lifetime setting failure %s", error);
9152 data->callback(result, data->lifetime,
9153 (void *) data->user_data);
9158 static void random_mac_lifetime_params(DBusMessageIter *iter, void *user_data)
9160 struct supplicant_random_mac_lifetime *data = user_data;
9162 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &(data->lifetime));
9165 int g_supplicant_interface_set_random_mac_lifetime(GSupplicantInterface *interface,
9166 GSupplicantRandomMaclifetimeCallback callback,
9167 unsigned int lifetime,
9170 struct supplicant_random_mac_lifetime *data;
9173 if (!system_available)
9179 data = dbus_malloc0(sizeof(*data));
9183 data->callback = callback;
9184 data->lifetime = lifetime;
9185 data->user_data = user_data;
9187 ret = supplicant_dbus_property_set(interface->path,
9188 SUPPLICANT_INTERFACE ".Interface",
9189 "RandAddrLifetime", DBUS_TYPE_UINT32_AS_STRING,
9190 random_mac_lifetime_params, random_mac_lifetime_result,
9193 SUPPLICANT_DBG("Unable to set RandAddrLifetime configuration");