Nest DevInfra | b9b4323 | 2019-12-18 14:53:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * WPA supplicant library with GLib integration |
| 4 | * |
| 5 | * Copyright (C) 2012-2013 Intel Corporation. All rights reserved. |
| 6 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #ifdef HAVE_CONFIG_H |
| 23 | #include <config.h> |
| 24 | #endif |
| 25 | |
| 26 | #include <errno.h> |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <stdint.h> |
| 31 | #include <syslog.h> |
| 32 | #include <ctype.h> |
| 33 | #include <stdbool.h> |
| 34 | #include <netinet/if_ether.h> |
| 35 | #include <netinet/in.h> |
| 36 | #include <net/ethernet.h> |
| 37 | #include <net/if_arp.h> |
| 38 | |
| 39 | #include <glib.h> |
| 40 | #include <gdbus.h> |
| 41 | |
| 42 | #include "dbus.h" |
| 43 | #include "gsupplicant.h" |
| 44 | |
| 45 | #define IEEE80211_CAP_ESS 0x0001 |
| 46 | #define IEEE80211_CAP_IBSS 0x0002 |
| 47 | #define IEEE80211_CAP_PRIVACY 0x0010 |
| 48 | |
| 49 | #define BSS_UNKNOWN_STRENGTH -90 |
| 50 | |
| 51 | static DBusConnection *connection; |
| 52 | |
| 53 | static const GSupplicantCallbacks *callbacks_pointer; |
| 54 | |
| 55 | static dbus_bool_t system_available = FALSE; |
| 56 | static dbus_bool_t system_ready = FALSE; |
| 57 | |
| 58 | static dbus_int32_t debug_level; |
| 59 | static dbus_bool_t debug_timestamp = FALSE; |
| 60 | static dbus_bool_t debug_showkeys = FALSE; |
| 61 | |
| 62 | static const char *debug_strings[] = { |
| 63 | "msgdump", "debug", "info", "warning", "error", NULL |
| 64 | }; |
| 65 | |
| 66 | static unsigned int eap_methods; |
| 67 | |
| 68 | struct strvalmap { |
| 69 | const char *str; |
| 70 | unsigned int val; |
| 71 | }; |
| 72 | |
| 73 | static struct strvalmap eap_method_map[] = { |
| 74 | { "MD5", G_SUPPLICANT_EAP_METHOD_MD5 }, |
| 75 | { "TLS", G_SUPPLICANT_EAP_METHOD_TLS }, |
| 76 | { "MSCHAPV2", G_SUPPLICANT_EAP_METHOD_MSCHAPV2 }, |
| 77 | { "PEAP", G_SUPPLICANT_EAP_METHOD_PEAP }, |
| 78 | { "TTLS", G_SUPPLICANT_EAP_METHOD_TTLS }, |
| 79 | { "GTC", G_SUPPLICANT_EAP_METHOD_GTC }, |
| 80 | { "OTP", G_SUPPLICANT_EAP_METHOD_OTP }, |
| 81 | { "LEAP", G_SUPPLICANT_EAP_METHOD_LEAP }, |
| 82 | { "WSC", G_SUPPLICANT_EAP_METHOD_WSC }, |
| 83 | { } |
| 84 | }; |
| 85 | |
| 86 | static struct strvalmap keymgmt_map[] = { |
| 87 | { "none", G_SUPPLICANT_KEYMGMT_NONE }, |
| 88 | { "ieee8021x", G_SUPPLICANT_KEYMGMT_IEEE8021X }, |
| 89 | { "wpa-none", G_SUPPLICANT_KEYMGMT_WPA_NONE }, |
| 90 | { "wpa-psk", G_SUPPLICANT_KEYMGMT_WPA_PSK }, |
| 91 | { "wpa-psk-sha256", G_SUPPLICANT_KEYMGMT_WPA_PSK_256 }, |
| 92 | { "wpa-ft-psk", G_SUPPLICANT_KEYMGMT_WPA_FT_PSK }, |
| 93 | { "wpa-ft-eap", G_SUPPLICANT_KEYMGMT_WPA_FT_EAP }, |
| 94 | { "wpa-eap", G_SUPPLICANT_KEYMGMT_WPA_EAP }, |
| 95 | { "wpa-eap-sha256", G_SUPPLICANT_KEYMGMT_WPA_EAP_256 }, |
| 96 | { "wps", G_SUPPLICANT_KEYMGMT_WPS }, |
| 97 | { } |
| 98 | }; |
| 99 | |
| 100 | static struct strvalmap authalg_capa_map[] = { |
| 101 | { "open", G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN }, |
| 102 | { "shared", G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED }, |
| 103 | { "leap", G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP }, |
| 104 | { } |
| 105 | }; |
| 106 | |
| 107 | static struct strvalmap proto_capa_map[] = { |
| 108 | { "wpa", G_SUPPLICANT_CAPABILITY_PROTO_WPA }, |
| 109 | { "rsn", G_SUPPLICANT_CAPABILITY_PROTO_RSN }, |
| 110 | { } |
| 111 | }; |
| 112 | |
| 113 | static struct strvalmap group_map[] = { |
| 114 | { "wep40", G_SUPPLICANT_GROUP_WEP40 }, |
| 115 | { "wep104", G_SUPPLICANT_GROUP_WEP104 }, |
| 116 | { "tkip", G_SUPPLICANT_GROUP_TKIP }, |
| 117 | { "ccmp", G_SUPPLICANT_GROUP_CCMP }, |
| 118 | { } |
| 119 | }; |
| 120 | |
| 121 | static struct strvalmap pairwise_map[] = { |
| 122 | { "none", G_SUPPLICANT_PAIRWISE_NONE }, |
| 123 | { "tkip", G_SUPPLICANT_PAIRWISE_TKIP }, |
| 124 | { "ccmp", G_SUPPLICANT_PAIRWISE_CCMP }, |
| 125 | { } |
| 126 | }; |
| 127 | |
| 128 | static struct strvalmap scan_capa_map[] = { |
| 129 | { "active", G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE }, |
| 130 | { "passive", G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE }, |
| 131 | { "ssid", G_SUPPLICANT_CAPABILITY_SCAN_SSID }, |
| 132 | { } |
| 133 | }; |
| 134 | |
| 135 | static struct strvalmap mode_capa_map[] = { |
| 136 | { "infrastructure", G_SUPPLICANT_CAPABILITY_MODE_INFRA }, |
| 137 | { "ad-hoc", G_SUPPLICANT_CAPABILITY_MODE_IBSS }, |
| 138 | { "ap", G_SUPPLICANT_CAPABILITY_MODE_AP }, |
| 139 | { } |
| 140 | }; |
| 141 | |
| 142 | static GHashTable *interface_table; |
| 143 | static GHashTable *bss_mapping; |
| 144 | static GHashTable *peer_mapping; |
| 145 | static GHashTable *group_mapping; |
| 146 | static GHashTable *pending_peer_connection; |
| 147 | |
| 148 | struct _GSupplicantWpsCredentials { |
| 149 | unsigned char ssid[32]; |
| 150 | unsigned int ssid_len; |
| 151 | char *key; |
| 152 | }; |
| 153 | |
| 154 | struct added_network_information { |
| 155 | char * ssid; |
| 156 | unsigned int ssid_len; |
| 157 | GSupplicantSecurity security; |
| 158 | char * passphrase; |
| 159 | char * private_passphrase; |
| 160 | }; |
| 161 | |
| 162 | struct _GSupplicantInterface { |
| 163 | char *path; |
| 164 | char *network_path; |
| 165 | unsigned int keymgmt_capa; |
| 166 | unsigned int authalg_capa; |
| 167 | unsigned int proto_capa; |
| 168 | unsigned int group_capa; |
| 169 | unsigned int pairwise_capa; |
| 170 | unsigned int scan_capa; |
| 171 | unsigned int mode_capa; |
| 172 | unsigned int max_scan_ssids; |
| 173 | bool p2p_support; |
| 174 | bool p2p_finding; |
| 175 | bool ap_create_in_progress; |
| 176 | dbus_bool_t ready; |
| 177 | GSupplicantState state; |
| 178 | dbus_bool_t scanning; |
| 179 | GSupplicantInterfaceCallback scan_callback; |
| 180 | void *scan_data; |
| 181 | int apscan; |
| 182 | char *ifname; |
| 183 | char *driver; |
| 184 | char *bridge; |
| 185 | struct _GSupplicantWpsCredentials wps_cred; |
| 186 | GSupplicantWpsState wps_state; |
| 187 | GHashTable *network_table; |
| 188 | GHashTable *peer_table; |
| 189 | GHashTable *group_table; |
| 190 | GHashTable *net_mapping; |
| 191 | GHashTable *bss_mapping; |
| 192 | GHashTable *config_mapping; |
| 193 | void *data; |
| 194 | const char *pending_peer_path; |
| 195 | struct added_network_information network_info; |
| 196 | }; |
| 197 | |
| 198 | struct g_supplicant_bss { |
| 199 | GSupplicantInterface *interface; |
| 200 | char *path; |
| 201 | unsigned char bssid[6]; |
| 202 | unsigned char ssid[32]; |
| 203 | unsigned int ssid_len; |
| 204 | dbus_uint16_t frequency; |
| 205 | dbus_uint32_t maxrate; |
| 206 | dbus_int16_t signal; |
| 207 | GSupplicantMode mode; |
| 208 | GSupplicantSecurity security; |
| 209 | dbus_bool_t rsn_selected; |
| 210 | unsigned int wpa_keymgmt; |
| 211 | unsigned int wpa_pairwise; |
| 212 | unsigned int wpa_group; |
| 213 | unsigned int rsn_keymgmt; |
| 214 | unsigned int rsn_pairwise; |
| 215 | unsigned int rsn_group; |
| 216 | unsigned int keymgmt; |
| 217 | dbus_bool_t privacy; |
| 218 | dbus_bool_t psk; |
| 219 | dbus_bool_t ieee8021x; |
| 220 | unsigned int wps_capabilities; |
| 221 | }; |
| 222 | |
| 223 | struct _GSupplicantNetwork { |
| 224 | GSupplicantInterface *interface; |
| 225 | char *path; |
| 226 | char *group; |
| 227 | char *name; |
| 228 | unsigned char ssid[32]; |
| 229 | unsigned int ssid_len; |
| 230 | dbus_int16_t signal; |
| 231 | dbus_uint16_t frequency; |
| 232 | struct g_supplicant_bss *best_bss; |
| 233 | GSupplicantMode mode; |
| 234 | GSupplicantSecurity security; |
| 235 | dbus_bool_t wps; |
| 236 | unsigned int wps_capabilities; |
| 237 | GHashTable *bss_table; |
| 238 | GHashTable *config_table; |
| 239 | }; |
| 240 | |
| 241 | struct _GSupplicantPeer { |
| 242 | GSupplicantInterface *interface; |
| 243 | char *path; |
| 244 | unsigned char device_address[ETH_ALEN]; |
| 245 | unsigned char iface_address[ETH_ALEN]; |
| 246 | char *name; |
| 247 | unsigned char *widi_ies; |
| 248 | int widi_ies_length; |
| 249 | char *identifier; |
| 250 | unsigned int wps_capabilities; |
| 251 | GSList *groups; |
| 252 | const GSupplicantInterface *current_group_iface; |
| 253 | bool connection_requested; |
| 254 | }; |
| 255 | |
| 256 | struct _GSupplicantGroup { |
| 257 | GSupplicantInterface *interface; |
| 258 | GSupplicantInterface *orig_interface; |
| 259 | char *path; |
| 260 | int role; |
| 261 | GSList *members; |
| 262 | }; |
| 263 | |
| 264 | struct interface_data { |
| 265 | GSupplicantInterface *interface; |
| 266 | char *path; /* Interface path cannot be taken from interface (above) as |
| 267 | * it might have been freed already. |
| 268 | */ |
| 269 | GSupplicantInterfaceCallback callback; |
| 270 | void *user_data; |
| 271 | bool network_remove_in_progress; |
| 272 | GSupplicantSSID *ssid; |
| 273 | }; |
| 274 | |
| 275 | struct interface_create_data { |
| 276 | char *ifname; |
| 277 | char *driver; |
| 278 | char *bridge; |
| 279 | GSupplicantInterface *interface; |
| 280 | GSupplicantInterfaceCallback callback; |
| 281 | void *user_data; |
| 282 | }; |
| 283 | |
| 284 | struct interface_connect_data { |
| 285 | GSupplicantInterface *interface; |
| 286 | char *path; |
| 287 | GSupplicantInterfaceCallback callback; |
| 288 | void *user_data; |
| 289 | union { |
| 290 | GSupplicantSSID *ssid; |
| 291 | GSupplicantPeerParams *peer; |
| 292 | }; |
| 293 | }; |
| 294 | |
| 295 | struct interface_scan_data { |
| 296 | GSupplicantInterface *interface; |
| 297 | char *path; |
| 298 | GSupplicantInterfaceCallback callback; |
| 299 | GSupplicantScanParams *scan_params; |
| 300 | void *user_data; |
| 301 | }; |
| 302 | |
| 303 | static int network_remove(struct interface_data *data); |
| 304 | |
| 305 | static inline void debug(const char *format, ...) |
| 306 | { |
| 307 | char str[256]; |
| 308 | va_list ap; |
| 309 | |
| 310 | if (!callbacks_pointer->debug) |
| 311 | return; |
| 312 | |
| 313 | va_start(ap, format); |
| 314 | |
| 315 | if (vsnprintf(str, sizeof(str), format, ap) > 0) |
| 316 | callbacks_pointer->debug(str); |
| 317 | |
| 318 | va_end(ap); |
| 319 | } |
| 320 | |
| 321 | #define SUPPLICANT_DBG(fmt, arg...) \ |
| 322 | debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg); |
| 323 | |
| 324 | static GSupplicantMode string2mode(const char *mode) |
| 325 | { |
| 326 | if (!mode) |
| 327 | return G_SUPPLICANT_MODE_UNKNOWN; |
| 328 | |
| 329 | if (g_str_equal(mode, "infrastructure")) |
| 330 | return G_SUPPLICANT_MODE_INFRA; |
| 331 | else if (g_str_equal(mode, "ad-hoc")) |
| 332 | return G_SUPPLICANT_MODE_IBSS; |
| 333 | |
| 334 | return G_SUPPLICANT_MODE_UNKNOWN; |
| 335 | } |
| 336 | |
| 337 | static const char *mode2string(GSupplicantMode mode) |
| 338 | { |
| 339 | switch (mode) { |
| 340 | case G_SUPPLICANT_MODE_UNKNOWN: |
| 341 | break; |
| 342 | case G_SUPPLICANT_MODE_INFRA: |
| 343 | return "managed"; |
| 344 | case G_SUPPLICANT_MODE_IBSS: |
| 345 | return "adhoc"; |
| 346 | case G_SUPPLICANT_MODE_MASTER: |
| 347 | return "ap"; |
| 348 | } |
| 349 | |
| 350 | return NULL; |
| 351 | } |
| 352 | |
| 353 | static const char *security2string(GSupplicantSecurity security) |
| 354 | { |
| 355 | switch (security) { |
| 356 | case G_SUPPLICANT_SECURITY_UNKNOWN: |
| 357 | break; |
| 358 | case G_SUPPLICANT_SECURITY_NONE: |
| 359 | return "none"; |
| 360 | case G_SUPPLICANT_SECURITY_WEP: |
| 361 | return "wep"; |
| 362 | case G_SUPPLICANT_SECURITY_PSK: |
| 363 | return "psk"; |
| 364 | case G_SUPPLICANT_SECURITY_IEEE8021X: |
| 365 | return "ieee8021x"; |
| 366 | } |
| 367 | |
| 368 | return NULL; |
| 369 | } |
| 370 | |
| 371 | static GSupplicantState string2state(const char *state) |
| 372 | { |
| 373 | if (!state) |
| 374 | return G_SUPPLICANT_STATE_UNKNOWN; |
| 375 | |
| 376 | if (g_str_equal(state, "unknown")) |
| 377 | return G_SUPPLICANT_STATE_UNKNOWN; |
| 378 | else if (g_str_equal(state, "interface_disabled")) |
| 379 | return G_SUPPLICANT_STATE_DISABLED; |
| 380 | else if (g_str_equal(state, "disconnected")) |
| 381 | return G_SUPPLICANT_STATE_DISCONNECTED; |
| 382 | else if (g_str_equal(state, "inactive")) |
| 383 | return G_SUPPLICANT_STATE_INACTIVE; |
| 384 | else if (g_str_equal(state, "scanning")) |
| 385 | return G_SUPPLICANT_STATE_SCANNING; |
| 386 | else if (g_str_equal(state, "authenticating")) |
| 387 | return G_SUPPLICANT_STATE_AUTHENTICATING; |
| 388 | else if (g_str_equal(state, "associating")) |
| 389 | return G_SUPPLICANT_STATE_ASSOCIATING; |
| 390 | else if (g_str_equal(state, "associated")) |
| 391 | return G_SUPPLICANT_STATE_ASSOCIATED; |
| 392 | else if (g_str_equal(state, "group_handshake")) |
| 393 | return G_SUPPLICANT_STATE_GROUP_HANDSHAKE; |
| 394 | else if (g_str_equal(state, "4way_handshake")) |
| 395 | return G_SUPPLICANT_STATE_4WAY_HANDSHAKE; |
| 396 | else if (g_str_equal(state, "completed")) |
| 397 | return G_SUPPLICANT_STATE_COMPLETED; |
| 398 | |
| 399 | return G_SUPPLICANT_STATE_UNKNOWN; |
| 400 | } |
| 401 | |
| 402 | static bool compare_network_parameters(GSupplicantInterface *interface, GSupplicantSSID *ssid) |
| 403 | { |
| 404 | if ((interface->network_info.ssid_len != ssid->ssid_len) || |
| 405 | memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len)) |
| 406 | return FALSE; |
| 407 | |
| 408 | if (interface->network_info.security != ssid->security) |
| 409 | return FALSE; |
| 410 | |
| 411 | if (interface->network_info.passphrase && |
| 412 | g_strcmp0(interface->network_info.passphrase, ssid->passphrase) != 0) { |
| 413 | return FALSE; |
| 414 | } |
| 415 | |
| 416 | if (interface->network_info.private_passphrase && |
| 417 | g_strcmp0(interface->network_info.private_passphrase, ssid->private_key_passphrase) != 0) { |
| 418 | return FALSE; |
| 419 | } |
| 420 | |
| 421 | return TRUE; |
| 422 | } |
| 423 | |
| 424 | static void remove_network_information(GSupplicantInterface * interface) |
| 425 | { |
| 426 | g_free(interface->network_info.ssid); |
| 427 | g_free(interface->network_info.passphrase); |
| 428 | g_free(interface->network_info.private_passphrase); |
| 429 | interface->network_info.ssid = NULL; |
| 430 | interface->network_info.ssid_len = 0; |
| 431 | interface->network_info.passphrase = NULL; |
| 432 | interface->network_info.private_passphrase = NULL; |
| 433 | } |
| 434 | |
| 435 | static int store_network_information(GSupplicantInterface * interface, GSupplicantSSID *ssid) |
| 436 | { |
| 437 | interface->network_info.ssid = g_malloc(ssid->ssid_len + 1); |
| 438 | if (interface->network_info.ssid != NULL) { |
| 439 | memcpy(interface->network_info.ssid, ssid->ssid, ssid->ssid_len); |
| 440 | interface->network_info.ssid[ssid->ssid_len] = '\0'; |
| 441 | interface->network_info.ssid_len = ssid->ssid_len; |
| 442 | } else { |
| 443 | return -ENOMEM; |
| 444 | } |
| 445 | |
| 446 | interface->network_info.security = ssid->security; |
| 447 | |
| 448 | if ((ssid->security == G_SUPPLICANT_SECURITY_WEP || |
| 449 | ssid->security == G_SUPPLICANT_SECURITY_PSK || |
| 450 | ssid->security == G_SUPPLICANT_SECURITY_NONE) && |
| 451 | ssid->passphrase) { |
| 452 | interface->network_info.passphrase = g_strdup(ssid->passphrase); |
| 453 | } |
| 454 | |
| 455 | if (ssid->security == G_SUPPLICANT_SECURITY_IEEE8021X && ssid->private_key_passphrase) { |
| 456 | interface->network_info.private_passphrase = g_strdup(ssid->private_key_passphrase); |
| 457 | } |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static void callback_system_ready(void) |
| 463 | { |
| 464 | if (system_ready) |
| 465 | return; |
| 466 | |
| 467 | system_ready = TRUE; |
| 468 | |
| 469 | if (!callbacks_pointer) |
| 470 | return; |
| 471 | |
| 472 | if (!callbacks_pointer->system_ready) |
| 473 | return; |
| 474 | |
| 475 | callbacks_pointer->system_ready(); |
| 476 | } |
| 477 | |
| 478 | static void callback_system_killed(void) |
| 479 | { |
| 480 | system_ready = FALSE; |
| 481 | |
| 482 | if (!callbacks_pointer) |
| 483 | return; |
| 484 | |
| 485 | if (!callbacks_pointer->system_killed) |
| 486 | return; |
| 487 | |
| 488 | callbacks_pointer->system_killed(); |
| 489 | } |
| 490 | |
| 491 | static void callback_interface_added(GSupplicantInterface *interface) |
| 492 | { |
| 493 | SUPPLICANT_DBG(""); |
| 494 | |
| 495 | if (!callbacks_pointer) |
| 496 | return; |
| 497 | |
| 498 | if (!callbacks_pointer->interface_added) |
| 499 | return; |
| 500 | |
| 501 | callbacks_pointer->interface_added(interface); |
| 502 | } |
| 503 | |
| 504 | static void callback_interface_state(GSupplicantInterface *interface) |
| 505 | { |
| 506 | if (!callbacks_pointer) |
| 507 | return; |
| 508 | |
| 509 | if (!callbacks_pointer->interface_state) |
| 510 | return; |
| 511 | |
| 512 | callbacks_pointer->interface_state(interface); |
| 513 | } |
| 514 | |
| 515 | static void callback_interface_removed(GSupplicantInterface *interface) |
| 516 | { |
| 517 | if (!callbacks_pointer) |
| 518 | return; |
| 519 | |
| 520 | if (!callbacks_pointer->interface_removed) |
| 521 | return; |
| 522 | |
| 523 | callbacks_pointer->interface_removed(interface); |
| 524 | } |
| 525 | |
| 526 | static void callback_p2p_support(GSupplicantInterface *interface) |
| 527 | { |
| 528 | SUPPLICANT_DBG(""); |
| 529 | |
| 530 | return; |
| 531 | |
| 532 | if (!interface->p2p_support) |
| 533 | return; |
| 534 | |
| 535 | if (callbacks_pointer && callbacks_pointer->p2p_support) |
| 536 | callbacks_pointer->p2p_support(interface); |
| 537 | } |
| 538 | |
| 539 | static void callback_scan_started(GSupplicantInterface *interface) |
| 540 | { |
| 541 | if (!callbacks_pointer) |
| 542 | return; |
| 543 | |
| 544 | if (!callbacks_pointer->scan_started) |
| 545 | return; |
| 546 | |
| 547 | callbacks_pointer->scan_started(interface); |
| 548 | } |
| 549 | |
| 550 | static void callback_ap_create_fail(GSupplicantInterface *interface) |
| 551 | { |
| 552 | if (!callbacks_pointer) |
| 553 | return; |
| 554 | |
| 555 | if (!callbacks_pointer->scan_started) |
| 556 | return; |
| 557 | |
| 558 | callbacks_pointer->ap_create_fail(interface); |
| 559 | } |
| 560 | |
| 561 | static void callback_scan_finished(GSupplicantInterface *interface) |
| 562 | { |
| 563 | if (!callbacks_pointer) |
| 564 | return; |
| 565 | |
| 566 | if (!callbacks_pointer->scan_finished) |
| 567 | return; |
| 568 | |
| 569 | callbacks_pointer->scan_finished(interface); |
| 570 | } |
| 571 | |
| 572 | static void callback_network_added(GSupplicantNetwork *network) |
| 573 | { |
| 574 | if (!callbacks_pointer) |
| 575 | return; |
| 576 | |
| 577 | if (!callbacks_pointer->network_added) |
| 578 | return; |
| 579 | |
| 580 | callbacks_pointer->network_added(network); |
| 581 | } |
| 582 | |
| 583 | static void callback_network_removed(GSupplicantNetwork *network) |
| 584 | { |
| 585 | if (!callbacks_pointer) |
| 586 | return; |
| 587 | |
| 588 | if (!callbacks_pointer->network_removed) |
| 589 | return; |
| 590 | |
| 591 | callbacks_pointer->network_removed(network); |
| 592 | } |
| 593 | |
| 594 | static void callback_network_changed(GSupplicantNetwork *network, |
| 595 | const char *property) |
| 596 | { |
| 597 | if (!callbacks_pointer) |
| 598 | return; |
| 599 | |
| 600 | if (!callbacks_pointer->network_changed) |
| 601 | return; |
| 602 | |
| 603 | callbacks_pointer->network_changed(network, property); |
| 604 | } |
| 605 | |
| 606 | static void callback_peer_found(GSupplicantPeer *peer) |
| 607 | { |
| 608 | if (!callbacks_pointer) |
| 609 | return; |
| 610 | |
| 611 | if (!callbacks_pointer->peer_found) |
| 612 | return; |
| 613 | |
| 614 | callbacks_pointer->peer_found(peer); |
| 615 | } |
| 616 | |
| 617 | static void callback_peer_lost(GSupplicantPeer *peer) |
| 618 | { |
| 619 | if (!callbacks_pointer) |
| 620 | return; |
| 621 | |
| 622 | if (!callbacks_pointer->peer_lost) |
| 623 | return; |
| 624 | |
| 625 | callbacks_pointer->peer_lost(peer); |
| 626 | } |
| 627 | |
| 628 | static void callback_peer_changed(GSupplicantPeer *peer, |
| 629 | GSupplicantPeerState state) |
| 630 | { |
| 631 | if (!callbacks_pointer) |
| 632 | return; |
| 633 | |
| 634 | if (!callbacks_pointer->peer_changed) |
| 635 | return; |
| 636 | |
| 637 | callbacks_pointer->peer_changed(peer, state); |
| 638 | } |
| 639 | |
| 640 | static void callback_peer_request(GSupplicantPeer *peer) |
| 641 | { |
| 642 | if (!callbacks_pointer) |
| 643 | return; |
| 644 | |
| 645 | if (!callbacks_pointer->peer_request) |
| 646 | return; |
| 647 | |
| 648 | peer->connection_requested = true; |
| 649 | |
| 650 | callbacks_pointer->peer_request(peer); |
| 651 | } |
| 652 | |
| 653 | static void remove_group(gpointer data) |
| 654 | { |
| 655 | GSupplicantGroup *group = data; |
| 656 | |
| 657 | if (group->members) |
| 658 | g_slist_free_full(group->members, g_free); |
| 659 | |
| 660 | g_free(group->path); |
| 661 | g_free(group); |
| 662 | } |
| 663 | |
| 664 | static void remove_interface(gpointer data) |
| 665 | { |
| 666 | GSupplicantInterface *interface = data; |
| 667 | |
| 668 | g_hash_table_destroy(interface->config_mapping); |
| 669 | g_hash_table_destroy(interface->bss_mapping); |
| 670 | g_hash_table_destroy(interface->net_mapping); |
| 671 | g_hash_table_destroy(interface->network_table); |
| 672 | g_hash_table_destroy(interface->peer_table); |
| 673 | g_hash_table_destroy(interface->group_table); |
| 674 | |
| 675 | if (interface->scan_callback) { |
| 676 | SUPPLICANT_DBG("call interface %p callback %p scanning %d", |
| 677 | interface, interface->scan_callback, |
| 678 | interface->scanning); |
| 679 | |
| 680 | interface->scan_callback(-EIO, interface, interface->scan_data); |
| 681 | interface->scan_callback = NULL; |
| 682 | interface->scan_data = NULL; |
| 683 | |
| 684 | if (interface->scanning) { |
| 685 | interface->scanning = FALSE; |
| 686 | callback_scan_finished(interface); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | callback_interface_removed(interface); |
| 691 | |
| 692 | g_free(interface->wps_cred.key); |
| 693 | g_free(interface->path); |
| 694 | g_free(interface->network_path); |
| 695 | g_free(interface->ifname); |
| 696 | g_free(interface->driver); |
| 697 | g_free(interface->bridge); |
| 698 | remove_network_information(interface); |
| 699 | g_free(interface); |
| 700 | } |
| 701 | |
| 702 | static void remove_network(gpointer data) |
| 703 | { |
| 704 | GSupplicantNetwork *network = data; |
| 705 | |
| 706 | g_hash_table_destroy(network->bss_table); |
| 707 | |
| 708 | callback_network_removed(network); |
| 709 | |
| 710 | g_hash_table_destroy(network->config_table); |
| 711 | |
| 712 | g_free(network->path); |
| 713 | g_free(network->group); |
| 714 | g_free(network->name); |
| 715 | g_free(network); |
| 716 | } |
| 717 | |
| 718 | static void remove_bss(gpointer data) |
| 719 | { |
| 720 | struct g_supplicant_bss *bss = data; |
| 721 | |
| 722 | g_free(bss->path); |
| 723 | g_free(bss); |
| 724 | } |
| 725 | |
| 726 | static void remove_peer(gpointer data) |
| 727 | { |
| 728 | GSupplicantPeer *peer = data; |
| 729 | |
| 730 | callback_peer_lost(peer); |
| 731 | |
| 732 | if (peer->groups) |
| 733 | g_slist_free_full(peer->groups, g_free); |
| 734 | |
| 735 | if (peer_mapping) |
| 736 | g_hash_table_remove(peer_mapping, peer->path); |
| 737 | |
| 738 | if (pending_peer_connection) |
| 739 | g_hash_table_remove(pending_peer_connection, peer->path); |
| 740 | |
| 741 | g_free(peer->path); |
| 742 | g_free(peer->name); |
| 743 | g_free(peer->identifier); |
| 744 | g_free(peer->widi_ies); |
| 745 | |
| 746 | g_free(peer); |
| 747 | } |
| 748 | |
| 749 | static void debug_strvalmap(const char *label, struct strvalmap *map, |
| 750 | unsigned int val) |
| 751 | { |
| 752 | int i; |
| 753 | |
| 754 | for (i = 0; map[i].str; i++) { |
| 755 | if (val & map[i].val) |
| 756 | SUPPLICANT_DBG("%s: %s", label, map[i].str); |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data) |
| 761 | { |
| 762 | GSupplicantInterface *interface = user_data; |
| 763 | const char *str = NULL; |
| 764 | int i; |
| 765 | |
| 766 | dbus_message_iter_get_basic(iter, &str); |
| 767 | if (!str) |
| 768 | return; |
| 769 | |
| 770 | for (i = 0; keymgmt_map[i].str; i++) |
| 771 | if (strcmp(str, keymgmt_map[i].str) == 0) { |
| 772 | interface->keymgmt_capa |= keymgmt_map[i].val; |
| 773 | break; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | static void interface_capability_authalg(DBusMessageIter *iter, void *user_data) |
| 778 | { |
| 779 | GSupplicantInterface *interface = user_data; |
| 780 | const char *str = NULL; |
| 781 | int i; |
| 782 | |
| 783 | dbus_message_iter_get_basic(iter, &str); |
| 784 | if (!str) |
| 785 | return; |
| 786 | |
| 787 | for (i = 0; authalg_capa_map[i].str; i++) |
| 788 | if (strcmp(str, authalg_capa_map[i].str) == 0) { |
| 789 | interface->authalg_capa |= authalg_capa_map[i].val; |
| 790 | break; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | static void interface_capability_proto(DBusMessageIter *iter, void *user_data) |
| 795 | { |
| 796 | GSupplicantInterface *interface = user_data; |
| 797 | const char *str = NULL; |
| 798 | int i; |
| 799 | |
| 800 | dbus_message_iter_get_basic(iter, &str); |
| 801 | if (!str) |
| 802 | return; |
| 803 | |
| 804 | for (i = 0; proto_capa_map[i].str; i++) |
| 805 | if (strcmp(str, proto_capa_map[i].str) == 0) { |
| 806 | interface->proto_capa |= proto_capa_map[i].val; |
| 807 | break; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | static void interface_capability_pairwise(DBusMessageIter *iter, |
| 812 | void *user_data) |
| 813 | { |
| 814 | GSupplicantInterface *interface = user_data; |
| 815 | const char *str = NULL; |
| 816 | int i; |
| 817 | |
| 818 | dbus_message_iter_get_basic(iter, &str); |
| 819 | if (!str) |
| 820 | return; |
| 821 | |
| 822 | for (i = 0; pairwise_map[i].str; i++) |
| 823 | if (strcmp(str, pairwise_map[i].str) == 0) { |
| 824 | interface->pairwise_capa |= pairwise_map[i].val; |
| 825 | break; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | static void interface_capability_group(DBusMessageIter *iter, void *user_data) |
| 830 | { |
| 831 | GSupplicantInterface *interface = user_data; |
| 832 | const char *str = NULL; |
| 833 | int i; |
| 834 | |
| 835 | dbus_message_iter_get_basic(iter, &str); |
| 836 | if (!str) |
| 837 | return; |
| 838 | |
| 839 | for (i = 0; group_map[i].str; i++) |
| 840 | if (strcmp(str, group_map[i].str) == 0) { |
| 841 | interface->group_capa |= group_map[i].val; |
| 842 | break; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | static void interface_capability_scan(DBusMessageIter *iter, void *user_data) |
| 847 | { |
| 848 | GSupplicantInterface *interface = user_data; |
| 849 | const char *str = NULL; |
| 850 | int i; |
| 851 | |
| 852 | dbus_message_iter_get_basic(iter, &str); |
| 853 | if (!str) |
| 854 | return; |
| 855 | |
| 856 | for (i = 0; scan_capa_map[i].str; i++) |
| 857 | if (strcmp(str, scan_capa_map[i].str) == 0) { |
| 858 | interface->scan_capa |= scan_capa_map[i].val; |
| 859 | break; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | static void interface_capability_mode(DBusMessageIter *iter, void *user_data) |
| 864 | { |
| 865 | GSupplicantInterface *interface = user_data; |
| 866 | const char *str = NULL; |
| 867 | int i; |
| 868 | |
| 869 | dbus_message_iter_get_basic(iter, &str); |
| 870 | if (!str) |
| 871 | return; |
| 872 | |
| 873 | for (i = 0; mode_capa_map[i].str; i++) |
| 874 | if (strcmp(str, mode_capa_map[i].str) == 0) { |
| 875 | interface->mode_capa |= mode_capa_map[i].val; |
| 876 | break; |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | static void interface_capability(const char *key, DBusMessageIter *iter, |
| 881 | void *user_data) |
| 882 | { |
| 883 | GSupplicantInterface *interface = user_data; |
| 884 | |
| 885 | if (!key) |
| 886 | return; |
| 887 | |
| 888 | if (g_strcmp0(key, "KeyMgmt") == 0) |
| 889 | supplicant_dbus_array_foreach(iter, |
| 890 | interface_capability_keymgmt, interface); |
| 891 | else if (g_strcmp0(key, "AuthAlg") == 0) |
| 892 | supplicant_dbus_array_foreach(iter, |
| 893 | interface_capability_authalg, interface); |
| 894 | else if (g_strcmp0(key, "Protocol") == 0) |
| 895 | supplicant_dbus_array_foreach(iter, |
| 896 | interface_capability_proto, interface); |
| 897 | else if (g_strcmp0(key, "Pairwise") == 0) |
| 898 | supplicant_dbus_array_foreach(iter, |
| 899 | interface_capability_pairwise, interface); |
| 900 | else if (g_strcmp0(key, "Group") == 0) |
| 901 | supplicant_dbus_array_foreach(iter, |
| 902 | interface_capability_group, interface); |
| 903 | else if (g_strcmp0(key, "Scan") == 0) |
| 904 | supplicant_dbus_array_foreach(iter, |
| 905 | interface_capability_scan, interface); |
| 906 | else if (g_strcmp0(key, "Modes") == 0) |
| 907 | supplicant_dbus_array_foreach(iter, |
| 908 | interface_capability_mode, interface); |
| 909 | else if (g_strcmp0(key, "MaxScanSSID") == 0) { |
| 910 | dbus_int32_t max_scan_ssid; |
| 911 | |
| 912 | dbus_message_iter_get_basic(iter, &max_scan_ssid); |
| 913 | if (max_scan_ssid < 2) |
| 914 | max_scan_ssid = 0; |
| 915 | interface->max_scan_ssids = max_scan_ssid; |
| 916 | |
| 917 | } else |
| 918 | SUPPLICANT_DBG("key %s type %c", |
| 919 | key, dbus_message_iter_get_arg_type(iter)); |
| 920 | } |
| 921 | |
| 922 | struct set_apscan_data |
| 923 | { |
| 924 | unsigned int ap_scan; |
| 925 | GSupplicantInterface *interface; |
| 926 | }; |
| 927 | |
| 928 | static void set_apscan(DBusMessageIter *iter, void *user_data) |
| 929 | { |
| 930 | struct set_apscan_data *data = user_data; |
| 931 | unsigned int ap_scan = data->ap_scan; |
| 932 | |
| 933 | dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan); |
| 934 | } |
| 935 | |
| 936 | static void set_apscan_complete(const char *error, |
| 937 | DBusMessageIter *iter, void *user_data) |
| 938 | { |
| 939 | struct set_apscan_data *data = user_data; |
| 940 | GSupplicantInterface *interface = data->interface; |
| 941 | |
| 942 | if (error) { |
| 943 | interface->ap_create_in_progress = false; |
| 944 | SUPPLICANT_DBG("Set AP scan error %s", error); |
| 945 | goto error; |
| 946 | } |
| 947 | |
| 948 | interface->ap_create_in_progress = true; |
| 949 | error: |
| 950 | dbus_free(data); |
| 951 | } |
| 952 | |
| 953 | int g_supplicant_interface_set_apscan(GSupplicantInterface *interface, |
| 954 | unsigned int ap_scan) |
| 955 | { |
| 956 | struct set_apscan_data *data; |
| 957 | int ret; |
| 958 | |
| 959 | data = dbus_malloc0(sizeof(*data)); |
| 960 | |
| 961 | if (!data) |
| 962 | return -ENOMEM; |
| 963 | |
| 964 | data->ap_scan = ap_scan; |
| 965 | data->interface = interface; |
| 966 | |
| 967 | ret = supplicant_dbus_property_set(interface->path, |
| 968 | SUPPLICANT_INTERFACE ".Interface", |
| 969 | "ApScan", DBUS_TYPE_UINT32_AS_STRING, |
| 970 | set_apscan, set_apscan_complete, data, NULL); |
| 971 | if (ret < 0) |
| 972 | dbus_free(data); |
| 973 | |
| 974 | return ret; |
| 975 | } |
| 976 | |
| 977 | void g_supplicant_interface_set_data(GSupplicantInterface *interface, |
| 978 | void *data) |
| 979 | { |
| 980 | if (!interface) |
| 981 | return; |
| 982 | |
| 983 | interface->data = data; |
| 984 | |
| 985 | if (!data) |
| 986 | interface->scan_callback = NULL; |
| 987 | } |
| 988 | |
| 989 | void *g_supplicant_interface_get_data(GSupplicantInterface *interface) |
| 990 | { |
| 991 | if (!interface) |
| 992 | return NULL; |
| 993 | |
| 994 | return interface->data; |
| 995 | } |
| 996 | |
| 997 | const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface) |
| 998 | { |
| 999 | if (!interface) |
| 1000 | return NULL; |
| 1001 | |
| 1002 | return interface->ifname; |
| 1003 | } |
| 1004 | |
| 1005 | const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface) |
| 1006 | { |
| 1007 | if (!interface) |
| 1008 | return NULL; |
| 1009 | |
| 1010 | return interface->driver; |
| 1011 | } |
| 1012 | |
| 1013 | GSupplicantState g_supplicant_interface_get_state( |
| 1014 | GSupplicantInterface *interface) |
| 1015 | { |
| 1016 | if (!interface) |
| 1017 | return G_SUPPLICANT_STATE_UNKNOWN; |
| 1018 | |
| 1019 | return interface->state; |
| 1020 | } |
| 1021 | |
| 1022 | const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface) |
| 1023 | { |
| 1024 | if (!interface) |
| 1025 | return NULL; |
| 1026 | |
| 1027 | return (const char *)interface->wps_cred.key; |
| 1028 | } |
| 1029 | |
| 1030 | const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface, |
| 1031 | unsigned int *ssid_len) |
| 1032 | { |
| 1033 | if (!ssid_len) |
| 1034 | return NULL; |
| 1035 | |
| 1036 | if (!interface || interface->wps_cred.ssid_len == 0) { |
| 1037 | *ssid_len = 0; |
| 1038 | return NULL; |
| 1039 | } |
| 1040 | |
| 1041 | *ssid_len = interface->wps_cred.ssid_len; |
| 1042 | return interface->wps_cred.ssid; |
| 1043 | } |
| 1044 | |
| 1045 | GSupplicantWpsState g_supplicant_interface_get_wps_state( |
| 1046 | GSupplicantInterface *interface) |
| 1047 | { |
| 1048 | if (!interface) |
| 1049 | return G_SUPPLICANT_WPS_STATE_UNKNOWN; |
| 1050 | |
| 1051 | return interface->wps_state; |
| 1052 | } |
| 1053 | |
| 1054 | unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface) |
| 1055 | { |
| 1056 | if (!interface) |
| 1057 | return 0; |
| 1058 | |
| 1059 | return interface->mode_capa; |
| 1060 | } |
| 1061 | |
| 1062 | unsigned int g_supplicant_interface_get_max_scan_ssids( |
| 1063 | GSupplicantInterface *interface) |
| 1064 | { |
| 1065 | if (!interface) |
| 1066 | return 0; |
| 1067 | |
| 1068 | return interface->max_scan_ssids; |
| 1069 | } |
| 1070 | |
| 1071 | static void set_network_enabled(DBusMessageIter *iter, void *user_data) |
| 1072 | { |
| 1073 | dbus_bool_t enable = *(dbus_bool_t *)user_data; |
| 1074 | |
| 1075 | dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable); |
| 1076 | } |
| 1077 | |
| 1078 | int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface, |
| 1079 | dbus_bool_t enable) |
| 1080 | { |
| 1081 | if (!interface) |
| 1082 | return -1; |
| 1083 | |
| 1084 | if (!interface->network_path) |
| 1085 | return -1; |
| 1086 | |
| 1087 | SUPPLICANT_DBG(" "); |
| 1088 | return supplicant_dbus_property_set(interface->network_path, |
| 1089 | SUPPLICANT_INTERFACE ".Network", |
| 1090 | "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING, |
| 1091 | set_network_enabled, NULL, &enable, NULL); |
| 1092 | } |
| 1093 | |
| 1094 | dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface) |
| 1095 | { |
| 1096 | if (!interface) |
| 1097 | return FALSE; |
| 1098 | |
| 1099 | return interface->ready; |
| 1100 | } |
| 1101 | |
| 1102 | GSupplicantInterface *g_supplicant_network_get_interface( |
| 1103 | GSupplicantNetwork *network) |
| 1104 | { |
| 1105 | if (!network) |
| 1106 | return NULL; |
| 1107 | |
| 1108 | return network->interface; |
| 1109 | } |
| 1110 | |
| 1111 | const char *g_supplicant_network_get_name(GSupplicantNetwork *network) |
| 1112 | { |
| 1113 | if (!network || !network->name) |
| 1114 | return ""; |
| 1115 | |
| 1116 | return network->name; |
| 1117 | } |
| 1118 | |
| 1119 | const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network) |
| 1120 | { |
| 1121 | if (!network || !network->group) |
| 1122 | return ""; |
| 1123 | |
| 1124 | return network->group; |
| 1125 | } |
| 1126 | |
| 1127 | const char *g_supplicant_network_get_path(GSupplicantNetwork *network) |
| 1128 | { |
| 1129 | if (!network || !network->path) |
| 1130 | return NULL; |
| 1131 | |
| 1132 | return network->path; |
| 1133 | } |
| 1134 | |
| 1135 | const char *g_supplicant_network_get_mode(GSupplicantNetwork *network) |
| 1136 | { |
| 1137 | if (!network) |
| 1138 | return G_SUPPLICANT_MODE_UNKNOWN; |
| 1139 | |
| 1140 | return mode2string(network->mode); |
| 1141 | } |
| 1142 | |
| 1143 | const char *g_supplicant_network_get_security(GSupplicantNetwork *network) |
| 1144 | { |
| 1145 | if (!network) |
| 1146 | return G_SUPPLICANT_SECURITY_UNKNOWN; |
| 1147 | |
| 1148 | return security2string(network->security); |
| 1149 | } |
| 1150 | |
| 1151 | const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network, |
| 1152 | unsigned int *ssid_len) |
| 1153 | { |
| 1154 | if (!network) { |
| 1155 | *ssid_len = 0; |
| 1156 | return NULL; |
| 1157 | } |
| 1158 | |
| 1159 | *ssid_len = network->ssid_len; |
| 1160 | return network->ssid; |
| 1161 | } |
| 1162 | |
| 1163 | dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network) |
| 1164 | { |
| 1165 | if (!network) |
| 1166 | return 0; |
| 1167 | |
| 1168 | return network->signal; |
| 1169 | } |
| 1170 | |
| 1171 | dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network) |
| 1172 | { |
| 1173 | if (!network) |
| 1174 | return 0; |
| 1175 | |
| 1176 | return network->frequency; |
| 1177 | } |
| 1178 | |
| 1179 | dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network) |
| 1180 | { |
| 1181 | if (!network) |
| 1182 | return FALSE; |
| 1183 | |
| 1184 | return network->wps; |
| 1185 | } |
| 1186 | |
| 1187 | dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network) |
| 1188 | { |
| 1189 | if (!network) |
| 1190 | return FALSE; |
| 1191 | |
| 1192 | if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED) |
| 1193 | return TRUE; |
| 1194 | |
| 1195 | return FALSE; |
| 1196 | } |
| 1197 | |
| 1198 | dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network) |
| 1199 | { |
| 1200 | if (!network) |
| 1201 | return FALSE; |
| 1202 | |
| 1203 | if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC) |
| 1204 | return TRUE; |
| 1205 | |
| 1206 | return FALSE; |
| 1207 | } |
| 1208 | |
| 1209 | dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network) |
| 1210 | { |
| 1211 | if (!network) |
| 1212 | return FALSE; |
| 1213 | |
| 1214 | if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR) |
| 1215 | return TRUE; |
| 1216 | |
| 1217 | return FALSE; |
| 1218 | } |
| 1219 | |
| 1220 | GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer) |
| 1221 | { |
| 1222 | if (!peer) |
| 1223 | return NULL; |
| 1224 | |
| 1225 | return peer->interface; |
| 1226 | } |
| 1227 | |
| 1228 | const char *g_supplicant_peer_get_path(GSupplicantPeer *peer) |
| 1229 | { |
| 1230 | if (!peer) |
| 1231 | return NULL; |
| 1232 | |
| 1233 | return peer->path; |
| 1234 | } |
| 1235 | |
| 1236 | const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer) |
| 1237 | { |
| 1238 | if (!peer) |
| 1239 | return NULL; |
| 1240 | |
| 1241 | return peer->identifier; |
| 1242 | } |
| 1243 | |
| 1244 | const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer) |
| 1245 | { |
| 1246 | if (!peer) |
| 1247 | return NULL; |
| 1248 | |
| 1249 | return peer->device_address; |
| 1250 | } |
| 1251 | |
| 1252 | const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer) |
| 1253 | { |
| 1254 | if (!peer) |
| 1255 | return NULL; |
| 1256 | |
| 1257 | return peer->iface_address; |
| 1258 | } |
| 1259 | |
| 1260 | const char *g_supplicant_peer_get_name(GSupplicantPeer *peer) |
| 1261 | { |
| 1262 | if (!peer) |
| 1263 | return NULL; |
| 1264 | |
| 1265 | return peer->name; |
| 1266 | } |
| 1267 | |
| 1268 | const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer, |
| 1269 | int *length) |
| 1270 | { |
| 1271 | if (!peer || !length) |
| 1272 | return NULL; |
| 1273 | |
| 1274 | *length = peer->widi_ies_length; |
| 1275 | return peer->widi_ies; |
| 1276 | } |
| 1277 | |
| 1278 | bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer) |
| 1279 | { |
| 1280 | if (!peer) |
| 1281 | return false; |
| 1282 | |
| 1283 | if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC) |
| 1284 | return true; |
| 1285 | |
| 1286 | return false; |
| 1287 | } |
| 1288 | |
| 1289 | bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer) |
| 1290 | { |
| 1291 | if (!peer) |
| 1292 | return false; |
| 1293 | |
| 1294 | if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN) |
| 1295 | return true; |
| 1296 | |
| 1297 | return false; |
| 1298 | } |
| 1299 | |
| 1300 | bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer) |
| 1301 | { |
| 1302 | if (!peer || !peer->groups) |
| 1303 | return false; |
| 1304 | |
| 1305 | return true; |
| 1306 | } |
| 1307 | |
| 1308 | GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer) |
| 1309 | { |
| 1310 | if (!peer) |
| 1311 | return NULL; |
| 1312 | |
| 1313 | return (GSupplicantInterface *) peer->current_group_iface; |
| 1314 | } |
| 1315 | |
| 1316 | bool g_supplicant_peer_is_client(GSupplicantPeer *peer) |
| 1317 | { |
| 1318 | GSupplicantGroup *group; |
| 1319 | GSList *list; |
| 1320 | |
| 1321 | if (!peer) |
| 1322 | return false; |
| 1323 | |
| 1324 | for (list = peer->groups; list; list = list->next) { |
| 1325 | const char *path = list->data; |
| 1326 | |
| 1327 | group = g_hash_table_lookup(group_mapping, path); |
| 1328 | if (!group) |
| 1329 | continue; |
| 1330 | |
| 1331 | if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT || |
| 1332 | group->orig_interface != peer->interface) |
| 1333 | continue; |
| 1334 | |
| 1335 | if (group->interface == peer->current_group_iface) |
| 1336 | return true; |
| 1337 | } |
| 1338 | |
| 1339 | return false; |
| 1340 | } |
| 1341 | |
| 1342 | bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer) |
| 1343 | { |
| 1344 | if (!peer) |
| 1345 | return false; |
| 1346 | |
| 1347 | return peer->connection_requested; |
| 1348 | } |
| 1349 | |
| 1350 | static void merge_network(GSupplicantNetwork *network) |
| 1351 | { |
| 1352 | GString *str; |
| 1353 | const char *ssid, *mode, *key_mgmt; |
| 1354 | unsigned int i, ssid_len; |
| 1355 | char *group; |
| 1356 | |
| 1357 | ssid = g_hash_table_lookup(network->config_table, "ssid"); |
| 1358 | mode = g_hash_table_lookup(network->config_table, "mode"); |
| 1359 | key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt"); |
| 1360 | |
| 1361 | SUPPLICANT_DBG("ssid %s mode %s", ssid, mode); |
| 1362 | |
| 1363 | if (ssid) |
| 1364 | ssid_len = strlen(ssid); |
| 1365 | else |
| 1366 | ssid_len = 0; |
| 1367 | |
| 1368 | str = g_string_sized_new((ssid_len * 2) + 24); |
| 1369 | if (!str) |
| 1370 | return; |
| 1371 | |
| 1372 | for (i = 0; i < ssid_len; i++) |
| 1373 | g_string_append_printf(str, "%02x", ssid[i]); |
| 1374 | |
| 1375 | if (g_strcmp0(mode, "0") == 0) |
| 1376 | g_string_append_printf(str, "_managed"); |
| 1377 | else if (g_strcmp0(mode, "1") == 0) |
| 1378 | g_string_append_printf(str, "_adhoc"); |
| 1379 | |
| 1380 | if (g_strcmp0(key_mgmt, "WPA-PSK") == 0) |
| 1381 | g_string_append_printf(str, "_psk"); |
| 1382 | |
| 1383 | group = g_string_free(str, FALSE); |
| 1384 | |
| 1385 | SUPPLICANT_DBG("%s", group); |
| 1386 | |
| 1387 | g_free(group); |
| 1388 | |
| 1389 | g_hash_table_destroy(network->config_table); |
| 1390 | |
| 1391 | g_free(network->path); |
| 1392 | g_free(network); |
| 1393 | } |
| 1394 | |
| 1395 | static void network_property(const char *key, DBusMessageIter *iter, |
| 1396 | void *user_data) |
| 1397 | { |
| 1398 | GSupplicantNetwork *network = user_data; |
| 1399 | |
| 1400 | if (!network->interface) |
| 1401 | return; |
| 1402 | |
| 1403 | if (!key) { |
| 1404 | merge_network(network); |
| 1405 | return; |
| 1406 | } |
| 1407 | |
| 1408 | if (g_strcmp0(key, "Enabled") == 0) { |
| 1409 | dbus_bool_t enabled = FALSE; |
| 1410 | |
| 1411 | dbus_message_iter_get_basic(iter, &enabled); |
| 1412 | } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) { |
| 1413 | const char *str = NULL; |
| 1414 | |
| 1415 | dbus_message_iter_get_basic(iter, &str); |
| 1416 | if (str) { |
| 1417 | g_hash_table_replace(network->config_table, |
| 1418 | g_strdup(key), g_strdup(str)); |
| 1419 | } |
| 1420 | } else |
| 1421 | SUPPLICANT_DBG("key %s type %c", |
| 1422 | key, dbus_message_iter_get_arg_type(iter)); |
| 1423 | } |
| 1424 | |
| 1425 | static void interface_network_added(DBusMessageIter *iter, void *user_data) |
| 1426 | { |
| 1427 | GSupplicantInterface *interface = user_data; |
| 1428 | GSupplicantNetwork *network; |
| 1429 | const char *path = NULL; |
| 1430 | |
| 1431 | SUPPLICANT_DBG(""); |
| 1432 | |
| 1433 | dbus_message_iter_get_basic(iter, &path); |
| 1434 | if (!path) |
| 1435 | return; |
| 1436 | |
| 1437 | if (g_strcmp0(path, "/") == 0) |
| 1438 | return; |
| 1439 | |
| 1440 | network = g_hash_table_lookup(interface->net_mapping, path); |
| 1441 | if (network) |
| 1442 | return; |
| 1443 | |
| 1444 | network = g_try_new0(GSupplicantNetwork, 1); |
| 1445 | if (!network) |
| 1446 | return; |
| 1447 | |
| 1448 | network->interface = interface; |
| 1449 | network->path = g_strdup(path); |
| 1450 | |
| 1451 | network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 1452 | g_free, g_free); |
| 1453 | |
| 1454 | dbus_message_iter_next(iter); |
| 1455 | if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) { |
| 1456 | supplicant_dbus_property_foreach(iter, network_property, |
| 1457 | network); |
| 1458 | network_property(NULL, NULL, network); |
| 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | supplicant_dbus_property_get_all(path, |
| 1463 | SUPPLICANT_INTERFACE ".Network", |
| 1464 | network_property, network, NULL); |
| 1465 | } |
| 1466 | |
| 1467 | static void interface_network_removed(DBusMessageIter *iter, void *user_data) |
| 1468 | { |
| 1469 | GSupplicantInterface *interface = user_data; |
| 1470 | GSupplicantNetwork *network; |
| 1471 | const char *path = NULL; |
| 1472 | |
| 1473 | dbus_message_iter_get_basic(iter, &path); |
| 1474 | if (!path) |
| 1475 | return; |
| 1476 | |
| 1477 | network = g_hash_table_lookup(interface->net_mapping, path); |
| 1478 | if (!network) |
| 1479 | return; |
| 1480 | |
| 1481 | g_hash_table_remove(interface->net_mapping, path); |
| 1482 | } |
| 1483 | |
| 1484 | static char *create_name(unsigned char *ssid, int ssid_len) |
| 1485 | { |
| 1486 | GString *string; |
| 1487 | const gchar *remainder, *invalid; |
| 1488 | int valid_bytes, remaining_bytes; |
| 1489 | |
| 1490 | if (ssid_len < 1 || ssid[0] == '\0') |
| 1491 | return g_strdup(""); |
| 1492 | |
| 1493 | string = NULL; |
| 1494 | remainder = (const gchar *)ssid; |
| 1495 | remaining_bytes = ssid_len; |
| 1496 | |
| 1497 | while (remaining_bytes != 0) { |
| 1498 | if (g_utf8_validate(remainder, remaining_bytes, |
| 1499 | &invalid)) { |
| 1500 | break; |
| 1501 | } |
| 1502 | |
| 1503 | valid_bytes = invalid - remainder; |
| 1504 | |
| 1505 | if (!string) |
| 1506 | string = g_string_sized_new(remaining_bytes); |
| 1507 | |
| 1508 | g_string_append_len(string, remainder, valid_bytes); |
| 1509 | |
| 1510 | /* append U+FFFD REPLACEMENT CHARACTER */ |
| 1511 | g_string_append(string, "\357\277\275"); |
| 1512 | |
| 1513 | remaining_bytes -= valid_bytes + 1; |
| 1514 | remainder = invalid + 1; |
| 1515 | } |
| 1516 | |
| 1517 | if (!string) |
| 1518 | return g_strndup((const gchar *)ssid, ssid_len + 1); |
| 1519 | |
| 1520 | g_string_append(string, remainder); |
| 1521 | |
| 1522 | return g_string_free(string, FALSE); |
| 1523 | } |
| 1524 | |
| 1525 | static char *create_group(struct g_supplicant_bss *bss) |
| 1526 | { |
| 1527 | GString *str; |
| 1528 | unsigned int i; |
| 1529 | const char *mode, *security; |
| 1530 | |
| 1531 | str = g_string_sized_new((bss->ssid_len * 2) + 24); |
| 1532 | if (!str) |
| 1533 | return NULL; |
| 1534 | |
| 1535 | if (bss->ssid_len > 0 && bss->ssid[0] != '\0') { |
| 1536 | for (i = 0; i < bss->ssid_len; i++) |
| 1537 | g_string_append_printf(str, "%02x", bss->ssid[i]); |
| 1538 | } else |
| 1539 | g_string_append_printf(str, "hidden"); |
| 1540 | |
| 1541 | mode = mode2string(bss->mode); |
| 1542 | if (mode) |
| 1543 | g_string_append_printf(str, "_%s", mode); |
| 1544 | |
| 1545 | security = security2string(bss->security); |
| 1546 | if (security) |
| 1547 | g_string_append_printf(str, "_%s", security); |
| 1548 | |
| 1549 | return g_string_free(str, FALSE); |
| 1550 | } |
| 1551 | |
| 1552 | static void add_or_replace_bss_to_network(struct g_supplicant_bss *bss) |
| 1553 | { |
| 1554 | GSupplicantInterface *interface = bss->interface; |
| 1555 | GSupplicantNetwork *network; |
| 1556 | char *group; |
| 1557 | |
| 1558 | group = create_group(bss); |
| 1559 | SUPPLICANT_DBG("New group created: %s", group); |
| 1560 | |
| 1561 | if (!group) |
| 1562 | return; |
| 1563 | |
| 1564 | network = g_hash_table_lookup(interface->network_table, group); |
| 1565 | if (network) { |
| 1566 | g_free(group); |
| 1567 | SUPPLICANT_DBG("Network %s already exist", network->name); |
| 1568 | |
| 1569 | goto done; |
| 1570 | } |
| 1571 | |
| 1572 | network = g_try_new0(GSupplicantNetwork, 1); |
| 1573 | if (!network) { |
| 1574 | g_free(group); |
| 1575 | return; |
| 1576 | } |
| 1577 | |
| 1578 | network->interface = interface; |
| 1579 | if (!network->path) |
| 1580 | network->path = g_strdup(bss->path); |
| 1581 | network->group = group; |
| 1582 | network->name = create_name(bss->ssid, bss->ssid_len); |
| 1583 | network->mode = bss->mode; |
| 1584 | network->security = bss->security; |
| 1585 | network->ssid_len = bss->ssid_len; |
| 1586 | memcpy(network->ssid, bss->ssid, bss->ssid_len); |
| 1587 | network->signal = bss->signal; |
| 1588 | network->frequency = bss->frequency; |
| 1589 | network->best_bss = bss; |
| 1590 | |
| 1591 | SUPPLICANT_DBG("New network %s created", network->name); |
| 1592 | |
| 1593 | network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 1594 | NULL, remove_bss); |
| 1595 | |
| 1596 | network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 1597 | g_free, g_free); |
| 1598 | |
| 1599 | g_hash_table_replace(interface->network_table, |
| 1600 | network->group, network); |
| 1601 | |
| 1602 | callback_network_added(network); |
| 1603 | |
| 1604 | done: |
| 1605 | /* We update network's WPS properties if only bss provides WPS. */ |
| 1606 | if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) { |
| 1607 | network->wps = TRUE; |
| 1608 | network->wps_capabilities |= bss->wps_capabilities; |
| 1609 | } |
| 1610 | |
| 1611 | if (bss->signal > network->signal) { |
| 1612 | network->signal = bss->signal; |
| 1613 | network->best_bss = bss; |
| 1614 | callback_network_changed(network, "Signal"); |
| 1615 | } |
| 1616 | |
| 1617 | g_hash_table_replace(interface->bss_mapping, bss->path, network); |
| 1618 | g_hash_table_replace(network->bss_table, bss->path, bss); |
| 1619 | |
| 1620 | g_hash_table_replace(bss_mapping, bss->path, interface); |
| 1621 | } |
| 1622 | |
| 1623 | static void bss_rates(DBusMessageIter *iter, void *user_data) |
| 1624 | { |
| 1625 | struct g_supplicant_bss *bss = user_data; |
| 1626 | dbus_uint32_t rate = 0; |
| 1627 | |
| 1628 | dbus_message_iter_get_basic(iter, &rate); |
| 1629 | if (rate == 0) |
| 1630 | return; |
| 1631 | |
| 1632 | if (rate > bss->maxrate) |
| 1633 | bss->maxrate = rate; |
| 1634 | } |
| 1635 | |
| 1636 | static void bss_keymgmt(DBusMessageIter *iter, void *user_data) |
| 1637 | { |
| 1638 | unsigned int *keymgmt = user_data; |
| 1639 | const char *str = NULL; |
| 1640 | int i; |
| 1641 | |
| 1642 | dbus_message_iter_get_basic(iter, &str); |
| 1643 | if (!str) |
| 1644 | return; |
| 1645 | |
| 1646 | for (i = 0; keymgmt_map[i].str; i++) |
| 1647 | if (strcmp(str, keymgmt_map[i].str) == 0) { |
| 1648 | SUPPLICANT_DBG("Keymgmt: %s", str); |
| 1649 | *keymgmt |= keymgmt_map[i].val; |
| 1650 | break; |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | static void bss_group(DBusMessageIter *iter, void *user_data) |
| 1655 | { |
| 1656 | unsigned int *group = user_data; |
| 1657 | const char *str = NULL; |
| 1658 | int i; |
| 1659 | |
| 1660 | dbus_message_iter_get_basic(iter, &str); |
| 1661 | if (!str) |
| 1662 | return; |
| 1663 | |
| 1664 | for (i = 0; group_map[i].str; i++) |
| 1665 | if (strcmp(str, group_map[i].str) == 0) { |
| 1666 | SUPPLICANT_DBG("Group: %s", str); |
| 1667 | *group |= group_map[i].val; |
| 1668 | break; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | static void bss_pairwise(DBusMessageIter *iter, void *user_data) |
| 1673 | { |
| 1674 | unsigned int *pairwise = user_data; |
| 1675 | const char *str = NULL; |
| 1676 | int i; |
| 1677 | |
| 1678 | dbus_message_iter_get_basic(iter, &str); |
| 1679 | if (!str) |
| 1680 | return; |
| 1681 | |
| 1682 | for (i = 0; pairwise_map[i].str; i++) |
| 1683 | if (strcmp(str, pairwise_map[i].str) == 0) { |
| 1684 | SUPPLICANT_DBG("Pairwise: %s", str); |
| 1685 | *pairwise |= pairwise_map[i].val; |
| 1686 | break; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | static void bss_wpa(const char *key, DBusMessageIter *iter, |
| 1691 | void *user_data) |
| 1692 | { |
| 1693 | struct g_supplicant_bss *bss = user_data; |
| 1694 | unsigned int value = 0; |
| 1695 | |
| 1696 | SUPPLICANT_DBG("Key: %s", key); |
| 1697 | |
| 1698 | if (g_strcmp0(key, "KeyMgmt") == 0) { |
| 1699 | supplicant_dbus_array_foreach(iter, bss_keymgmt, &value); |
| 1700 | |
| 1701 | if (bss->rsn_selected) |
| 1702 | bss->rsn_keymgmt = value; |
| 1703 | else |
| 1704 | bss->wpa_keymgmt = value; |
| 1705 | } else if (g_strcmp0(key, "Group") == 0) { |
| 1706 | supplicant_dbus_array_foreach(iter, bss_group, &value); |
| 1707 | |
| 1708 | if (bss->rsn_selected) |
| 1709 | bss->rsn_group = value; |
| 1710 | else |
| 1711 | bss->wpa_group = value; |
| 1712 | } else if (g_strcmp0(key, "Pairwise") == 0) { |
| 1713 | supplicant_dbus_array_foreach(iter, bss_pairwise, &value); |
| 1714 | |
| 1715 | if (bss->rsn_selected) |
| 1716 | bss->rsn_pairwise = value; |
| 1717 | else |
| 1718 | bss->wpa_pairwise = value; |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size, |
| 1723 | unsigned int type) |
| 1724 | { |
| 1725 | unsigned int len = 0; |
| 1726 | |
| 1727 | while (len + 4 < ie_size) { |
| 1728 | unsigned int hi = ie[len]; |
| 1729 | unsigned int lo = ie[len + 1]; |
| 1730 | unsigned int tmp_type = (hi << 8) + lo; |
| 1731 | unsigned int v_len = 0; |
| 1732 | |
| 1733 | /* hi and lo are used to recreate an unsigned int |
| 1734 | * based on 2 8bits length unsigned int. */ |
| 1735 | |
| 1736 | hi = ie[len + 2]; |
| 1737 | lo = ie[len + 3]; |
| 1738 | v_len = (hi << 8) + lo; |
| 1739 | |
| 1740 | if (tmp_type == type) { |
| 1741 | unsigned int ret_value = 0; |
| 1742 | unsigned char *value = (unsigned char *)&ret_value; |
| 1743 | |
| 1744 | SUPPLICANT_DBG("IE: match type 0x%x", type); |
| 1745 | |
| 1746 | /* Verifying length relevance */ |
| 1747 | if (v_len > sizeof(unsigned int) || |
| 1748 | len + 4 + v_len > ie_size) |
| 1749 | break; |
| 1750 | |
| 1751 | memcpy(value, ie + len + 4, v_len); |
| 1752 | |
| 1753 | SUPPLICANT_DBG("returning 0x%x", ret_value); |
| 1754 | return ret_value; |
| 1755 | } |
| 1756 | |
| 1757 | len += v_len + 4; |
| 1758 | } |
| 1759 | |
| 1760 | SUPPLICANT_DBG("returning 0"); |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
| 1764 | static void bss_process_ies(DBusMessageIter *iter, void *user_data) |
| 1765 | { |
| 1766 | struct g_supplicant_bss *bss = user_data; |
| 1767 | const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 }; |
| 1768 | unsigned char *ie, *ie_end; |
| 1769 | DBusMessageIter array; |
| 1770 | unsigned int value; |
| 1771 | int ie_len; |
| 1772 | |
| 1773 | #define WMM_WPA1_WPS_INFO 221 |
| 1774 | #define WPS_INFO_MIN_LEN 6 |
| 1775 | #define WPS_VERSION_TLV 0x104A |
| 1776 | #define WPS_STATE_TLV 0x1044 |
| 1777 | #define WPS_METHODS_TLV 0x1012 |
| 1778 | #define WPS_REGISTRAR_TLV 0x1041 |
| 1779 | #define WPS_VERSION 0x10 |
| 1780 | #define WPS_PBC 0x04 |
| 1781 | #define WPS_PIN 0x00 |
| 1782 | #define WPS_CONFIGURED 0x02 |
| 1783 | |
| 1784 | dbus_message_iter_recurse(iter, &array); |
| 1785 | dbus_message_iter_get_fixed_array(&array, &ie, &ie_len); |
| 1786 | |
| 1787 | if (!ie || ie_len < 2) |
| 1788 | return; |
| 1789 | |
| 1790 | bss->wps_capabilities = 0; |
| 1791 | bss->keymgmt = 0; |
| 1792 | |
| 1793 | for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end; |
| 1794 | ie += ie[1] + 2) { |
| 1795 | |
| 1796 | if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN || |
| 1797 | memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) |
| 1798 | continue; |
| 1799 | |
| 1800 | SUPPLICANT_DBG("IE: match WPS_OUI"); |
| 1801 | |
| 1802 | value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV); |
| 1803 | if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION && |
| 1804 | value != 0) { |
| 1805 | bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS; |
| 1806 | |
| 1807 | if (value == WPS_CONFIGURED) |
| 1808 | bss->wps_capabilities |= |
| 1809 | G_SUPPLICANT_WPS_CONFIGURED; |
| 1810 | } |
| 1811 | |
| 1812 | value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV); |
| 1813 | if (value != 0) { |
| 1814 | if (GUINT16_FROM_BE(value) == WPS_PBC) |
| 1815 | bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC; |
| 1816 | if (GUINT16_FROM_BE(value) == WPS_PIN) |
| 1817 | bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN; |
| 1818 | } else |
| 1819 | bss->wps_capabilities |= |
| 1820 | G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN; |
| 1821 | |
| 1822 | /* If the AP sends this it means it's advertizing |
| 1823 | * as a registrar and the WPS process is launched |
| 1824 | * on its side */ |
| 1825 | if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0) |
| 1826 | bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR; |
| 1827 | |
| 1828 | SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities); |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | static void bss_compute_security(struct g_supplicant_bss *bss) |
| 1833 | { |
| 1834 | /* |
| 1835 | * Combining RSN and WPA keymgmt |
| 1836 | * We combine it since parsing IEs might have set something for WPS. */ |
| 1837 | bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt; |
| 1838 | |
| 1839 | bss->ieee8021x = FALSE; |
| 1840 | bss->psk = FALSE; |
| 1841 | |
| 1842 | if (bss->keymgmt & |
| 1843 | (G_SUPPLICANT_KEYMGMT_WPA_EAP | |
| 1844 | G_SUPPLICANT_KEYMGMT_WPA_FT_EAP | |
| 1845 | G_SUPPLICANT_KEYMGMT_WPA_EAP_256)) |
| 1846 | bss->ieee8021x = TRUE; |
| 1847 | |
| 1848 | if (bss->keymgmt & |
| 1849 | (G_SUPPLICANT_KEYMGMT_WPA_PSK | |
| 1850 | G_SUPPLICANT_KEYMGMT_WPA_FT_PSK | |
| 1851 | G_SUPPLICANT_KEYMGMT_WPA_PSK_256)) |
| 1852 | bss->psk = TRUE; |
| 1853 | |
| 1854 | if (bss->ieee8021x) |
| 1855 | bss->security = G_SUPPLICANT_SECURITY_IEEE8021X; |
| 1856 | else if (bss->psk) |
| 1857 | bss->security = G_SUPPLICANT_SECURITY_PSK; |
| 1858 | else if (bss->privacy) |
| 1859 | bss->security = G_SUPPLICANT_SECURITY_WEP; |
| 1860 | else |
| 1861 | bss->security = G_SUPPLICANT_SECURITY_NONE; |
| 1862 | } |
| 1863 | |
| 1864 | |
| 1865 | static void bss_property(const char *key, DBusMessageIter *iter, |
| 1866 | void *user_data) |
| 1867 | { |
| 1868 | struct g_supplicant_bss *bss = user_data; |
| 1869 | |
| 1870 | if (!bss->interface) |
| 1871 | return; |
| 1872 | |
| 1873 | SUPPLICANT_DBG("key %s", key); |
| 1874 | |
| 1875 | if (!key) |
| 1876 | return; |
| 1877 | |
| 1878 | if (g_strcmp0(key, "BSSID") == 0) { |
| 1879 | DBusMessageIter array; |
| 1880 | unsigned char *addr; |
| 1881 | int addr_len; |
| 1882 | |
| 1883 | dbus_message_iter_recurse(iter, &array); |
| 1884 | dbus_message_iter_get_fixed_array(&array, &addr, &addr_len); |
| 1885 | |
| 1886 | if (addr_len == 6) |
| 1887 | memcpy(bss->bssid, addr, addr_len); |
| 1888 | } else if (g_strcmp0(key, "SSID") == 0) { |
| 1889 | DBusMessageIter array; |
| 1890 | unsigned char *ssid; |
| 1891 | int ssid_len; |
| 1892 | |
| 1893 | dbus_message_iter_recurse(iter, &array); |
| 1894 | dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len); |
| 1895 | |
| 1896 | if (ssid_len > 0 && ssid_len < 33) { |
| 1897 | memcpy(bss->ssid, ssid, ssid_len); |
| 1898 | bss->ssid_len = ssid_len; |
| 1899 | } else { |
| 1900 | memset(bss->ssid, 0, sizeof(bss->ssid)); |
| 1901 | bss->ssid_len = 0; |
| 1902 | } |
| 1903 | } else if (g_strcmp0(key, "Capabilities") == 0) { |
| 1904 | dbus_uint16_t capabilities = 0x0000; |
| 1905 | |
| 1906 | dbus_message_iter_get_basic(iter, &capabilities); |
| 1907 | |
| 1908 | if (capabilities & IEEE80211_CAP_ESS) |
| 1909 | bss->mode = G_SUPPLICANT_MODE_INFRA; |
| 1910 | else if (capabilities & IEEE80211_CAP_IBSS) |
| 1911 | bss->mode = G_SUPPLICANT_MODE_IBSS; |
| 1912 | |
| 1913 | if (capabilities & IEEE80211_CAP_PRIVACY) |
| 1914 | bss->privacy = TRUE; |
| 1915 | } else if (g_strcmp0(key, "Mode") == 0) { |
| 1916 | const char *mode = NULL; |
| 1917 | |
| 1918 | dbus_message_iter_get_basic(iter, &mode); |
| 1919 | bss->mode = string2mode(mode); |
| 1920 | } else if (g_strcmp0(key, "Frequency") == 0) { |
| 1921 | dbus_uint16_t frequency = 0; |
| 1922 | |
| 1923 | dbus_message_iter_get_basic(iter, &frequency); |
| 1924 | bss->frequency = frequency; |
| 1925 | } else if (g_strcmp0(key, "Signal") == 0) { |
| 1926 | dbus_int16_t signal = 0; |
| 1927 | |
| 1928 | dbus_message_iter_get_basic(iter, &signal); |
| 1929 | |
| 1930 | bss->signal = signal; |
| 1931 | if (!bss->signal) |
| 1932 | bss->signal = BSS_UNKNOWN_STRENGTH; |
| 1933 | |
| 1934 | } else if (g_strcmp0(key, "Level") == 0) { |
| 1935 | dbus_int32_t level = 0; |
| 1936 | |
| 1937 | dbus_message_iter_get_basic(iter, &level); |
| 1938 | } else if (g_strcmp0(key, "Rates") == 0) { |
| 1939 | supplicant_dbus_array_foreach(iter, bss_rates, bss); |
| 1940 | } else if (g_strcmp0(key, "MaxRate") == 0) { |
| 1941 | dbus_uint32_t maxrate = 0; |
| 1942 | |
| 1943 | dbus_message_iter_get_basic(iter, &maxrate); |
| 1944 | if (maxrate != 0) |
| 1945 | bss->maxrate = maxrate; |
| 1946 | } else if (g_strcmp0(key, "Privacy") == 0) { |
| 1947 | dbus_bool_t privacy = FALSE; |
| 1948 | |
| 1949 | dbus_message_iter_get_basic(iter, &privacy); |
| 1950 | bss->privacy = privacy; |
| 1951 | } else if (g_strcmp0(key, "RSN") == 0) { |
| 1952 | bss->rsn_selected = TRUE; |
| 1953 | |
| 1954 | supplicant_dbus_property_foreach(iter, bss_wpa, bss); |
| 1955 | } else if (g_strcmp0(key, "WPA") == 0) { |
| 1956 | bss->rsn_selected = FALSE; |
| 1957 | |
| 1958 | supplicant_dbus_property_foreach(iter, bss_wpa, bss); |
| 1959 | } else if (g_strcmp0(key, "IEs") == 0) |
| 1960 | bss_process_ies(iter, bss); |
| 1961 | else |
| 1962 | SUPPLICANT_DBG("key %s type %c", |
| 1963 | key, dbus_message_iter_get_arg_type(iter)); |
| 1964 | } |
| 1965 | |
| 1966 | static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter, |
| 1967 | void *user_data) |
| 1968 | { |
| 1969 | GSupplicantInterface *interface = user_data; |
| 1970 | GSupplicantNetwork *network; |
| 1971 | struct g_supplicant_bss *bss; |
| 1972 | const char *path = NULL; |
| 1973 | |
| 1974 | SUPPLICANT_DBG(""); |
| 1975 | |
| 1976 | dbus_message_iter_get_basic(iter, &path); |
| 1977 | if (!path) |
| 1978 | return NULL; |
| 1979 | |
| 1980 | if (g_strcmp0(path, "/") == 0) |
| 1981 | return NULL; |
| 1982 | |
| 1983 | SUPPLICANT_DBG("%s", path); |
| 1984 | |
| 1985 | network = g_hash_table_lookup(interface->bss_mapping, path); |
| 1986 | if (network) { |
| 1987 | bss = g_hash_table_lookup(network->bss_table, path); |
| 1988 | if (bss) |
| 1989 | return NULL; |
| 1990 | } |
| 1991 | |
| 1992 | bss = g_try_new0(struct g_supplicant_bss, 1); |
| 1993 | if (!bss) |
| 1994 | return NULL; |
| 1995 | |
| 1996 | bss->interface = interface; |
| 1997 | bss->path = g_strdup(path); |
| 1998 | bss->signal = BSS_UNKNOWN_STRENGTH; |
| 1999 | |
| 2000 | return bss; |
| 2001 | } |
| 2002 | |
| 2003 | static void interface_bss_added_with_keys(DBusMessageIter *iter, |
| 2004 | void *user_data) |
| 2005 | { |
| 2006 | struct g_supplicant_bss *bss; |
| 2007 | |
| 2008 | SUPPLICANT_DBG(""); |
| 2009 | |
| 2010 | bss = interface_bss_added(iter, user_data); |
| 2011 | if (!bss) |
| 2012 | return; |
| 2013 | |
| 2014 | dbus_message_iter_next(iter); |
| 2015 | |
| 2016 | if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID) |
| 2017 | return; |
| 2018 | |
| 2019 | supplicant_dbus_property_foreach(iter, bss_property, bss); |
| 2020 | |
| 2021 | bss_compute_security(bss); |
| 2022 | add_or_replace_bss_to_network(bss); |
| 2023 | } |
| 2024 | |
| 2025 | static void interface_bss_added_without_keys(DBusMessageIter *iter, |
| 2026 | void *user_data) |
| 2027 | { |
| 2028 | struct g_supplicant_bss *bss; |
| 2029 | |
| 2030 | SUPPLICANT_DBG(""); |
| 2031 | |
| 2032 | bss = interface_bss_added(iter, user_data); |
| 2033 | if (!bss) |
| 2034 | return; |
| 2035 | |
| 2036 | supplicant_dbus_property_get_all(bss->path, |
| 2037 | SUPPLICANT_INTERFACE ".BSS", |
| 2038 | bss_property, bss, NULL); |
| 2039 | |
| 2040 | bss_compute_security(bss); |
| 2041 | add_or_replace_bss_to_network(bss); |
| 2042 | } |
| 2043 | |
| 2044 | static void update_signal(gpointer key, gpointer value, |
| 2045 | gpointer user_data) |
| 2046 | { |
| 2047 | struct g_supplicant_bss *bss = value; |
| 2048 | GSupplicantNetwork *network = user_data; |
| 2049 | |
| 2050 | if (bss->signal > network->signal) { |
| 2051 | network->signal = bss->signal; |
| 2052 | network->best_bss = bss; |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | static void update_network_signal(GSupplicantNetwork *network) |
| 2057 | { |
| 2058 | if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss) |
| 2059 | return; |
| 2060 | |
| 2061 | g_hash_table_foreach(network->bss_table, |
| 2062 | update_signal, network); |
| 2063 | |
| 2064 | SUPPLICANT_DBG("New network signal %d", network->signal); |
| 2065 | } |
| 2066 | |
| 2067 | static void interface_bss_removed(DBusMessageIter *iter, void *user_data) |
| 2068 | { |
| 2069 | GSupplicantInterface *interface = user_data; |
| 2070 | GSupplicantNetwork *network; |
| 2071 | struct g_supplicant_bss *bss = NULL; |
| 2072 | const char *path = NULL; |
| 2073 | |
| 2074 | dbus_message_iter_get_basic(iter, &path); |
| 2075 | if (!path) |
| 2076 | return; |
| 2077 | |
| 2078 | network = g_hash_table_lookup(interface->bss_mapping, path); |
| 2079 | if (!network) |
| 2080 | return; |
| 2081 | |
| 2082 | bss = g_hash_table_lookup(network->bss_table, path); |
| 2083 | if (network->best_bss == bss) { |
| 2084 | network->best_bss = NULL; |
| 2085 | network->signal = BSS_UNKNOWN_STRENGTH; |
| 2086 | } |
| 2087 | |
| 2088 | g_hash_table_remove(bss_mapping, path); |
| 2089 | |
| 2090 | g_hash_table_remove(interface->bss_mapping, path); |
| 2091 | g_hash_table_remove(network->bss_table, path); |
| 2092 | |
| 2093 | update_network_signal(network); |
| 2094 | |
| 2095 | if (g_hash_table_size(network->bss_table) == 0) |
| 2096 | g_hash_table_remove(interface->network_table, network->group); |
| 2097 | } |
| 2098 | |
| 2099 | static void set_config_methods(DBusMessageIter *iter, void *user_data) |
| 2100 | { |
| 2101 | const char *config_methods = "push_button"; |
| 2102 | |
| 2103 | dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, |
| 2104 | &config_methods); |
| 2105 | } |
| 2106 | |
| 2107 | static void interface_property(const char *key, DBusMessageIter *iter, |
| 2108 | void *user_data) |
| 2109 | { |
| 2110 | GSupplicantInterface *interface = user_data; |
| 2111 | |
| 2112 | if (!interface) |
| 2113 | return; |
| 2114 | |
| 2115 | SUPPLICANT_DBG("%s", key); |
| 2116 | |
| 2117 | if (!key) { |
| 2118 | debug_strvalmap("KeyMgmt capability", keymgmt_map, |
| 2119 | interface->keymgmt_capa); |
| 2120 | debug_strvalmap("AuthAlg capability", authalg_capa_map, |
| 2121 | interface->authalg_capa); |
| 2122 | debug_strvalmap("Protocol capability", proto_capa_map, |
| 2123 | interface->proto_capa); |
| 2124 | debug_strvalmap("Pairwise capability", pairwise_map, |
| 2125 | interface->pairwise_capa); |
| 2126 | debug_strvalmap("Group capability", group_map, |
| 2127 | interface->group_capa); |
| 2128 | debug_strvalmap("Scan capability", scan_capa_map, |
| 2129 | interface->scan_capa); |
| 2130 | debug_strvalmap("Mode capability", mode_capa_map, |
| 2131 | interface->mode_capa); |
| 2132 | |
| 2133 | |
| 2134 | supplicant_dbus_property_set(interface->path, |
| 2135 | SUPPLICANT_INTERFACE ".Interface.WPS", |
| 2136 | "ConfigMethods", DBUS_TYPE_STRING_AS_STRING, |
| 2137 | set_config_methods, NULL, NULL, NULL); |
| 2138 | |
| 2139 | if (interface->ready) |
| 2140 | callback_interface_added(interface); |
| 2141 | |
| 2142 | return; |
| 2143 | } |
| 2144 | |
| 2145 | if (g_strcmp0(key, "Capabilities") == 0) { |
| 2146 | supplicant_dbus_property_foreach(iter, interface_capability, |
| 2147 | interface); |
| 2148 | if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P) |
| 2149 | interface->p2p_support = true; |
| 2150 | } else if (g_strcmp0(key, "State") == 0) { |
| 2151 | const char *str = NULL; |
| 2152 | |
| 2153 | dbus_message_iter_get_basic(iter, &str); |
| 2154 | if (str) |
| 2155 | if (string2state(str) != interface->state) { |
| 2156 | interface->state = string2state(str); |
| 2157 | callback_interface_state(interface); |
| 2158 | } |
| 2159 | |
| 2160 | if (interface->ap_create_in_progress) { |
| 2161 | if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED) |
| 2162 | callback_ap_create_fail(interface); |
| 2163 | |
| 2164 | interface->ap_create_in_progress = false; |
| 2165 | } |
| 2166 | |
| 2167 | if (interface->state == G_SUPPLICANT_STATE_DISABLED) |
| 2168 | interface->ready = FALSE; |
| 2169 | else |
| 2170 | interface->ready = TRUE; |
| 2171 | |
| 2172 | SUPPLICANT_DBG("state %s (%d)", str, interface->state); |
| 2173 | } else if (g_strcmp0(key, "Scanning") == 0) { |
| 2174 | dbus_bool_t scanning = FALSE; |
| 2175 | |
| 2176 | dbus_message_iter_get_basic(iter, &scanning); |
| 2177 | interface->scanning = scanning; |
| 2178 | |
| 2179 | if (interface->ready) { |
| 2180 | if (interface->scanning) |
| 2181 | callback_scan_started(interface); |
| 2182 | else |
| 2183 | callback_scan_finished(interface); |
| 2184 | } |
| 2185 | } else if (g_strcmp0(key, "ApScan") == 0) { |
| 2186 | int apscan = 1; |
| 2187 | |
| 2188 | dbus_message_iter_get_basic(iter, &apscan); |
| 2189 | interface->apscan = apscan; |
| 2190 | } else if (g_strcmp0(key, "Ifname") == 0) { |
| 2191 | const char *str = NULL; |
| 2192 | |
| 2193 | dbus_message_iter_get_basic(iter, &str); |
| 2194 | if (str) { |
| 2195 | g_free(interface->ifname); |
| 2196 | interface->ifname = g_strdup(str); |
| 2197 | } |
| 2198 | } else if (g_strcmp0(key, "Driver") == 0) { |
| 2199 | const char *str = NULL; |
| 2200 | |
| 2201 | dbus_message_iter_get_basic(iter, &str); |
| 2202 | if (str) { |
| 2203 | g_free(interface->driver); |
| 2204 | interface->driver = g_strdup(str); |
| 2205 | } |
| 2206 | } else if (g_strcmp0(key, "BridgeIfname") == 0) { |
| 2207 | const char *str = NULL; |
| 2208 | |
| 2209 | dbus_message_iter_get_basic(iter, &str); |
| 2210 | if (str) { |
| 2211 | g_free(interface->bridge); |
| 2212 | interface->bridge = g_strdup(str); |
| 2213 | } |
| 2214 | } else if (g_strcmp0(key, "CurrentBSS") == 0) { |
| 2215 | interface_bss_added_without_keys(iter, interface); |
| 2216 | } else if (g_strcmp0(key, "CurrentNetwork") == 0) { |
| 2217 | interface_network_added(iter, interface); |
| 2218 | } else if (g_strcmp0(key, "BSSs") == 0) { |
| 2219 | supplicant_dbus_array_foreach(iter, |
| 2220 | interface_bss_added_without_keys, |
| 2221 | interface); |
| 2222 | } else if (g_strcmp0(key, "Blobs") == 0) { |
| 2223 | /* Nothing */ |
| 2224 | } else if (g_strcmp0(key, "Networks") == 0) { |
| 2225 | supplicant_dbus_array_foreach(iter, interface_network_added, |
| 2226 | interface); |
| 2227 | } else if (g_strcmp0(key, "DisconnectReason") == 0) { |
| 2228 | int reason; |
| 2229 | if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) { |
| 2230 | dbus_message_iter_get_basic(iter, &reason); |
| 2231 | if (callbacks_pointer && callbacks_pointer->update_disconnect_reasoncode && reason != 0) { |
| 2232 | callbacks_pointer->update_disconnect_reasoncode(interface, reason); |
| 2233 | } |
| 2234 | } |
| 2235 | } else if (g_strcmp0(key, "AssocStatusCode") == 0) { |
| 2236 | int status_code; |
| 2237 | if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) { |
| 2238 | dbus_message_iter_get_basic(iter, &status_code); |
| 2239 | if (callbacks_pointer && callbacks_pointer->update_assoc_status_code) { |
| 2240 | callbacks_pointer->update_assoc_status_code(interface, status_code); |
| 2241 | } |
| 2242 | } |
| 2243 | } else { |
| 2244 | SUPPLICANT_DBG("key %s type %c", |
| 2245 | key, dbus_message_iter_get_arg_type(iter)); |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | static void scan_network_update(DBusMessageIter *iter, void *user_data) |
| 2250 | { |
| 2251 | GSupplicantInterface *interface = user_data; |
| 2252 | GSupplicantNetwork *network; |
| 2253 | char *path; |
| 2254 | |
| 2255 | if (!iter) |
| 2256 | return; |
| 2257 | |
| 2258 | dbus_message_iter_get_basic(iter, &path); |
| 2259 | |
| 2260 | if (!path) |
| 2261 | return; |
| 2262 | |
| 2263 | if (g_strcmp0(path, "/") == 0) |
| 2264 | return; |
| 2265 | |
| 2266 | /* Update the network details based on scan BSS data */ |
| 2267 | network = g_hash_table_lookup(interface->bss_mapping, path); |
| 2268 | if (network) |
| 2269 | callback_network_added(network); |
| 2270 | } |
| 2271 | |
| 2272 | static void scan_bss_data(const char *key, DBusMessageIter *iter, |
| 2273 | void *user_data) |
| 2274 | { |
| 2275 | GSupplicantInterface *interface = user_data; |
| 2276 | |
| 2277 | if (iter) |
| 2278 | supplicant_dbus_array_foreach(iter, scan_network_update, |
| 2279 | interface); |
| 2280 | |
| 2281 | if (interface->scan_callback) |
| 2282 | interface->scan_callback(0, interface, interface->scan_data); |
| 2283 | |
| 2284 | interface->scan_callback = NULL; |
| 2285 | interface->scan_data = NULL; |
| 2286 | } |
| 2287 | |
| 2288 | static GSupplicantInterface *interface_alloc(const char *path) |
| 2289 | { |
| 2290 | GSupplicantInterface *interface; |
| 2291 | |
| 2292 | interface = g_try_new0(GSupplicantInterface, 1); |
| 2293 | if (!interface) |
| 2294 | return NULL; |
| 2295 | |
| 2296 | interface->path = g_strdup(path); |
| 2297 | |
| 2298 | interface->network_table = g_hash_table_new_full(g_str_hash, |
| 2299 | g_str_equal, NULL, remove_network); |
| 2300 | interface->peer_table = g_hash_table_new_full(g_str_hash, |
| 2301 | g_str_equal, NULL, remove_peer); |
| 2302 | interface->group_table = g_hash_table_new_full(g_str_hash, |
| 2303 | g_str_equal, NULL, remove_group); |
| 2304 | interface->net_mapping = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 2305 | NULL, NULL); |
| 2306 | interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 2307 | NULL, NULL); |
| 2308 | interface->config_mapping = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 2309 | NULL, g_free); |
| 2310 | |
| 2311 | g_hash_table_replace(interface_table, interface->path, interface); |
| 2312 | |
| 2313 | return interface; |
| 2314 | } |
| 2315 | |
| 2316 | static void interface_added(DBusMessageIter *iter, void *user_data) |
| 2317 | { |
| 2318 | GSupplicantInterface *interface; |
| 2319 | const char *path = NULL; |
| 2320 | |
| 2321 | SUPPLICANT_DBG(""); |
| 2322 | |
| 2323 | dbus_message_iter_get_basic(iter, &path); |
| 2324 | if (!path) |
| 2325 | return; |
| 2326 | |
| 2327 | if (g_strcmp0(path, "/") == 0) |
| 2328 | return; |
| 2329 | |
| 2330 | interface = g_hash_table_lookup(interface_table, path); |
| 2331 | if (interface) |
| 2332 | return; |
| 2333 | |
| 2334 | interface = interface_alloc(path); |
| 2335 | if (!interface) |
| 2336 | return; |
| 2337 | |
| 2338 | dbus_message_iter_next(iter); |
| 2339 | if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) { |
| 2340 | supplicant_dbus_property_foreach(iter, interface_property, |
| 2341 | interface); |
| 2342 | interface_property(NULL, NULL, interface); |
| 2343 | return; |
| 2344 | } |
| 2345 | |
| 2346 | supplicant_dbus_property_get_all(path, |
| 2347 | SUPPLICANT_INTERFACE ".Interface", |
| 2348 | interface_property, interface, |
| 2349 | interface); |
| 2350 | } |
| 2351 | |
| 2352 | static void interface_removed(DBusMessageIter *iter, void *user_data) |
| 2353 | { |
| 2354 | const char *path = NULL; |
| 2355 | GSupplicantInterface *interface = user_data; |
| 2356 | |
| 2357 | dbus_message_iter_get_basic(iter, &path); |
| 2358 | if (!path) |
| 2359 | return; |
| 2360 | |
| 2361 | interface = g_hash_table_lookup(interface_table, path); |
| 2362 | if (!interface) |
| 2363 | return; |
| 2364 | |
| 2365 | g_supplicant_interface_cancel(interface); |
| 2366 | |
| 2367 | g_hash_table_remove(interface_table, path); |
| 2368 | } |
| 2369 | |
| 2370 | static void eap_method(DBusMessageIter *iter, void *user_data) |
| 2371 | { |
| 2372 | const char *str = NULL; |
| 2373 | int i; |
| 2374 | |
| 2375 | dbus_message_iter_get_basic(iter, &str); |
| 2376 | if (!str) |
| 2377 | return; |
| 2378 | |
| 2379 | for (i = 0; eap_method_map[i].str; i++) |
| 2380 | if (strcmp(str, eap_method_map[i].str) == 0) { |
| 2381 | eap_methods |= eap_method_map[i].val; |
| 2382 | break; |
| 2383 | } |
| 2384 | } |
| 2385 | |
| 2386 | static void service_property(const char *key, DBusMessageIter *iter, |
| 2387 | void *user_data) |
| 2388 | { |
| 2389 | if (!key) { |
| 2390 | connman_info("%s callback_system_ready", __FUNCTION__); |
| 2391 | callback_system_ready(); |
| 2392 | return; |
| 2393 | } |
| 2394 | |
| 2395 | if (g_strcmp0(key, "DebugLevel") == 0) { |
| 2396 | const char *str = NULL; |
| 2397 | int i; |
| 2398 | |
| 2399 | dbus_message_iter_get_basic(iter, &str); |
| 2400 | for (i = 0; debug_strings[i]; i++) |
| 2401 | if (g_strcmp0(debug_strings[i], str) == 0) { |
| 2402 | debug_level = i; |
| 2403 | break; |
| 2404 | } |
| 2405 | SUPPLICANT_DBG("Debug level %d", debug_level); |
| 2406 | } else if (g_strcmp0(key, "DebugTimestamp") == 0) { |
| 2407 | dbus_message_iter_get_basic(iter, &debug_timestamp); |
| 2408 | SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp); |
| 2409 | } else if (g_strcmp0(key, "DebugShowKeys") == 0) { |
| 2410 | dbus_message_iter_get_basic(iter, &debug_showkeys); |
| 2411 | SUPPLICANT_DBG("Debug show keys %u", debug_showkeys); |
| 2412 | } else if (g_strcmp0(key, "Interfaces") == 0) { |
| 2413 | supplicant_dbus_array_foreach(iter, interface_added, NULL); |
| 2414 | } else if (g_strcmp0(key, "EapMethods") == 0) { |
| 2415 | supplicant_dbus_array_foreach(iter, eap_method, NULL); |
| 2416 | debug_strvalmap("EAP method", eap_method_map, eap_methods); |
| 2417 | } else if (g_strcmp0(key, "Country") == 0) { |
| 2418 | const char *country = NULL; |
| 2419 | |
| 2420 | dbus_message_iter_get_basic(iter, &country); |
| 2421 | SUPPLICANT_DBG("Country %s", country); |
| 2422 | } else |
| 2423 | SUPPLICANT_DBG("key %s type %c", |
| 2424 | key, dbus_message_iter_get_arg_type(iter)); |
| 2425 | } |
| 2426 | |
| 2427 | static void signal_name_owner_changed(const char *path, DBusMessageIter *iter) |
| 2428 | { |
| 2429 | const char *name = NULL, *old = NULL, *new = NULL; |
| 2430 | |
| 2431 | SUPPLICANT_DBG(""); |
| 2432 | |
| 2433 | if (g_strcmp0(path, DBUS_PATH_DBUS) != 0) |
| 2434 | return; |
| 2435 | |
| 2436 | dbus_message_iter_get_basic(iter, &name); |
| 2437 | if (!name) |
| 2438 | return; |
| 2439 | |
| 2440 | if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0) |
| 2441 | return; |
| 2442 | |
| 2443 | dbus_message_iter_next(iter); |
| 2444 | dbus_message_iter_get_basic(iter, &old); |
| 2445 | dbus_message_iter_next(iter); |
| 2446 | dbus_message_iter_get_basic(iter, &new); |
| 2447 | |
| 2448 | if (!old || !new) |
| 2449 | return; |
| 2450 | |
| 2451 | if (strlen(old) > 0 && strlen(new) == 0) { |
| 2452 | system_available = FALSE; |
| 2453 | g_hash_table_remove_all(bss_mapping); |
| 2454 | g_hash_table_remove_all(peer_mapping); |
| 2455 | g_hash_table_remove_all(group_mapping); |
| 2456 | g_hash_table_remove_all(interface_table); |
| 2457 | callback_system_killed(); |
| 2458 | } |
| 2459 | |
| 2460 | if (strlen(new) > 0 && strlen(old) == 0) { |
| 2461 | system_available = TRUE; |
| 2462 | supplicant_dbus_property_get_all(SUPPLICANT_PATH, |
| 2463 | SUPPLICANT_INTERFACE, |
| 2464 | service_property, NULL, NULL); |
| 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | static void signal_properties_changed(const char *path, DBusMessageIter *iter) |
| 2469 | { |
| 2470 | SUPPLICANT_DBG(""); |
| 2471 | |
| 2472 | if (g_strcmp0(path, SUPPLICANT_PATH) != 0) |
| 2473 | return; |
| 2474 | |
| 2475 | supplicant_dbus_property_foreach(iter, service_property, NULL); |
| 2476 | } |
| 2477 | |
| 2478 | static void signal_interface_added(const char *path, DBusMessageIter *iter) |
| 2479 | { |
| 2480 | SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH); |
| 2481 | |
| 2482 | if (g_strcmp0(path, SUPPLICANT_PATH) == 0) |
| 2483 | interface_added(iter, NULL); |
| 2484 | } |
| 2485 | |
| 2486 | static void signal_interface_removed(const char *path, DBusMessageIter *iter) |
| 2487 | { |
| 2488 | SUPPLICANT_DBG(""); |
| 2489 | |
| 2490 | if (g_strcmp0(path, SUPPLICANT_PATH) == 0) |
| 2491 | interface_removed(iter, NULL); |
| 2492 | } |
| 2493 | |
| 2494 | static void signal_interface_changed(const char *path, DBusMessageIter *iter) |
| 2495 | { |
| 2496 | GSupplicantInterface *interface; |
| 2497 | |
| 2498 | SUPPLICANT_DBG(""); |
| 2499 | |
| 2500 | interface = g_hash_table_lookup(interface_table, path); |
| 2501 | if (!interface) |
| 2502 | return; |
| 2503 | |
| 2504 | supplicant_dbus_property_foreach(iter, interface_property, interface); |
| 2505 | } |
| 2506 | |
| 2507 | static void signal_scan_done(const char *path, DBusMessageIter *iter) |
| 2508 | { |
| 2509 | GSupplicantInterface *interface; |
| 2510 | dbus_bool_t success = FALSE; |
| 2511 | |
| 2512 | SUPPLICANT_DBG(""); |
| 2513 | |
| 2514 | interface = g_hash_table_lookup(interface_table, path); |
| 2515 | if (!interface) |
| 2516 | return; |
| 2517 | |
| 2518 | dbus_message_iter_get_basic(iter, &success); |
| 2519 | |
| 2520 | if (interface->scanning) { |
| 2521 | callback_scan_finished(interface); |
| 2522 | interface->scanning = FALSE; |
| 2523 | } |
| 2524 | |
| 2525 | /* |
| 2526 | * If scan is unsuccessful return -EIO else get the scanned BSSs |
| 2527 | * and update the network details accordingly |
| 2528 | */ |
| 2529 | if (!success) { |
| 2530 | if (interface->scan_callback) |
| 2531 | interface->scan_callback(-EIO, interface, |
| 2532 | interface->scan_data); |
| 2533 | |
| 2534 | interface->scan_callback = NULL; |
| 2535 | interface->scan_data = NULL; |
| 2536 | |
| 2537 | return; |
| 2538 | } |
| 2539 | |
| 2540 | supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface", |
| 2541 | "BSSs", scan_bss_data, interface, interface); |
| 2542 | } |
| 2543 | |
| 2544 | static void signal_bss_added(const char *path, DBusMessageIter *iter) |
| 2545 | { |
| 2546 | GSupplicantInterface *interface; |
| 2547 | |
| 2548 | SUPPLICANT_DBG(""); |
| 2549 | |
| 2550 | interface = g_hash_table_lookup(interface_table, path); |
| 2551 | if (!interface) |
| 2552 | return; |
| 2553 | |
| 2554 | interface_bss_added_with_keys(iter, interface); |
| 2555 | } |
| 2556 | |
| 2557 | static void signal_bss_removed(const char *path, DBusMessageIter *iter) |
| 2558 | { |
| 2559 | GSupplicantInterface *interface; |
| 2560 | |
| 2561 | SUPPLICANT_DBG(""); |
| 2562 | |
| 2563 | interface = g_hash_table_lookup(interface_table, path); |
| 2564 | if (!interface) |
| 2565 | return; |
| 2566 | |
| 2567 | interface_bss_removed(iter, interface); |
| 2568 | } |
| 2569 | |
| 2570 | static void signal_network_added(const char *path, DBusMessageIter *iter) |
| 2571 | { |
| 2572 | GSupplicantInterface *interface; |
| 2573 | |
| 2574 | SUPPLICANT_DBG(""); |
| 2575 | |
| 2576 | interface = g_hash_table_lookup(interface_table, path); |
| 2577 | if (!interface) |
| 2578 | return; |
| 2579 | |
| 2580 | interface_network_added(iter, interface); |
| 2581 | } |
| 2582 | |
| 2583 | static void signal_network_removed(const char *path, DBusMessageIter *iter) |
| 2584 | { |
| 2585 | GSupplicantInterface *interface; |
| 2586 | |
| 2587 | SUPPLICANT_DBG(""); |
| 2588 | |
| 2589 | interface = g_hash_table_lookup(interface_table, path); |
| 2590 | if (!interface) |
| 2591 | return; |
| 2592 | |
| 2593 | interface_network_removed(iter, interface); |
| 2594 | } |
| 2595 | |
| 2596 | static void signal_bss_changed(const char *path, DBusMessageIter *iter) |
| 2597 | { |
| 2598 | GSupplicantInterface *interface; |
| 2599 | GSupplicantNetwork *network; |
| 2600 | GSupplicantSecurity old_security; |
| 2601 | struct g_supplicant_bss *bss; |
| 2602 | |
| 2603 | SUPPLICANT_DBG(""); |
| 2604 | |
| 2605 | interface = g_hash_table_lookup(bss_mapping, path); |
| 2606 | if (!interface) |
| 2607 | return; |
| 2608 | |
| 2609 | network = g_hash_table_lookup(interface->bss_mapping, path); |
| 2610 | if (!network) |
| 2611 | return; |
| 2612 | |
| 2613 | bss = g_hash_table_lookup(network->bss_table, path); |
| 2614 | if (!bss) |
| 2615 | return; |
| 2616 | |
| 2617 | supplicant_dbus_property_foreach(iter, bss_property, bss); |
| 2618 | |
| 2619 | old_security = network->security; |
| 2620 | bss_compute_security(bss); |
| 2621 | |
| 2622 | if (old_security != bss->security) { |
| 2623 | struct g_supplicant_bss *new_bss; |
| 2624 | |
| 2625 | SUPPLICANT_DBG("New network security for %s", bss->ssid); |
| 2626 | |
| 2627 | /* Security change policy: |
| 2628 | * - we first copy the current bss into a new one with |
| 2629 | * its own pointer (path) |
| 2630 | * - we remove the current bss related network which will |
| 2631 | * tell the plugin about such removal. This is done due |
| 2632 | * to the fact that a security change means a group change |
| 2633 | * so a complete network change. |
| 2634 | * (current bss becomes invalid as well) |
| 2635 | * - we add the new bss: it adds new network and tell the |
| 2636 | * plugin about it. */ |
| 2637 | |
| 2638 | new_bss = g_try_new0(struct g_supplicant_bss, 1); |
| 2639 | if (!new_bss) |
| 2640 | return; |
| 2641 | |
| 2642 | memcpy(new_bss, bss, sizeof(struct g_supplicant_bss)); |
| 2643 | new_bss->path = g_strdup(bss->path); |
| 2644 | |
| 2645 | g_hash_table_remove(interface->network_table, network->group); |
| 2646 | |
| 2647 | add_or_replace_bss_to_network(new_bss); |
| 2648 | |
| 2649 | return; |
| 2650 | } |
| 2651 | |
| 2652 | if (bss->signal == network->signal) |
| 2653 | return; |
| 2654 | |
| 2655 | /* |
| 2656 | * If the new signal is lower than the SSID signal, we need |
| 2657 | * to check for the new maximum. |
| 2658 | */ |
| 2659 | if (bss->signal < network->signal) { |
| 2660 | if (bss != network->best_bss) |
| 2661 | return; |
| 2662 | network->signal = bss->signal; |
| 2663 | update_network_signal(network); |
| 2664 | } else { |
| 2665 | network->signal = bss->signal; |
| 2666 | network->best_bss = bss; |
| 2667 | } |
| 2668 | |
| 2669 | SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid, |
| 2670 | network->signal); |
| 2671 | |
| 2672 | callback_network_changed(network, "Signal"); |
| 2673 | } |
| 2674 | |
| 2675 | static void wps_credentials(const char *key, DBusMessageIter *iter, |
| 2676 | void *user_data) |
| 2677 | { |
| 2678 | GSupplicantInterface *interface = user_data; |
| 2679 | |
| 2680 | if (!key) |
| 2681 | return; |
| 2682 | |
| 2683 | SUPPLICANT_DBG("key %s", key); |
| 2684 | |
| 2685 | if (g_strcmp0(key, "Key") == 0) { |
| 2686 | DBusMessageIter array; |
| 2687 | unsigned char *key_val; |
| 2688 | int key_len; |
| 2689 | |
| 2690 | dbus_message_iter_recurse(iter, &array); |
| 2691 | dbus_message_iter_get_fixed_array(&array, &key_val, &key_len); |
| 2692 | |
| 2693 | g_free(interface->wps_cred.key); |
| 2694 | interface->wps_cred.key = g_try_malloc0( |
| 2695 | sizeof(char) * key_len + 1); |
| 2696 | |
| 2697 | if (!interface->wps_cred.key) |
| 2698 | return; |
| 2699 | |
| 2700 | memcpy(interface->wps_cred.key, key_val, |
| 2701 | sizeof(char) * key_len); |
| 2702 | |
| 2703 | SUPPLICANT_DBG("WPS key present"); |
| 2704 | } else if (g_strcmp0(key, "SSID") == 0) { |
| 2705 | DBusMessageIter array; |
| 2706 | unsigned char *ssid; |
| 2707 | int ssid_len; |
| 2708 | |
| 2709 | dbus_message_iter_recurse(iter, &array); |
| 2710 | dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len); |
| 2711 | |
| 2712 | if (ssid_len > 0 && ssid_len < 33) { |
| 2713 | memcpy(interface->wps_cred.ssid, ssid, ssid_len); |
| 2714 | interface->wps_cred.ssid_len = ssid_len; |
| 2715 | } else { |
| 2716 | memset(interface->wps_cred.ssid, 0, 32); |
| 2717 | interface->wps_cred.ssid_len = 0; |
| 2718 | } |
| 2719 | } |
| 2720 | } |
| 2721 | |
| 2722 | static void signal_wps_credentials(const char *path, DBusMessageIter *iter) |
| 2723 | { |
| 2724 | GSupplicantInterface *interface; |
| 2725 | |
| 2726 | SUPPLICANT_DBG(""); |
| 2727 | |
| 2728 | interface = g_hash_table_lookup(interface_table, path); |
| 2729 | if (!interface) |
| 2730 | return; |
| 2731 | |
| 2732 | supplicant_dbus_property_foreach(iter, wps_credentials, interface); |
| 2733 | } |
| 2734 | |
| 2735 | static void wps_event_args(const char *key, DBusMessageIter *iter, |
| 2736 | void *user_data) |
| 2737 | { |
| 2738 | GSupplicantInterface *interface = user_data; |
| 2739 | |
| 2740 | if (!key || !interface) |
| 2741 | return; |
| 2742 | |
| 2743 | SUPPLICANT_DBG("Arg Key %s", key); |
| 2744 | } |
| 2745 | |
| 2746 | static void signal_wps_event(const char *path, DBusMessageIter *iter) |
| 2747 | { |
| 2748 | GSupplicantInterface *interface; |
| 2749 | const char *name = NULL; |
| 2750 | |
| 2751 | SUPPLICANT_DBG(""); |
| 2752 | |
| 2753 | interface = g_hash_table_lookup(interface_table, path); |
| 2754 | if (!interface) |
| 2755 | return; |
| 2756 | |
| 2757 | dbus_message_iter_get_basic(iter, &name); |
| 2758 | |
| 2759 | SUPPLICANT_DBG("Name: %s", name); |
| 2760 | |
| 2761 | if (g_strcmp0(name, "success") == 0) |
| 2762 | interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS; |
| 2763 | else if (g_strcmp0(name, "fail") == 0) |
| 2764 | interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL; |
| 2765 | else |
| 2766 | interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN; |
| 2767 | |
| 2768 | if (!dbus_message_iter_has_next(iter)) |
| 2769 | return; |
| 2770 | |
| 2771 | dbus_message_iter_next(iter); |
| 2772 | |
| 2773 | supplicant_dbus_property_foreach(iter, wps_event_args, interface); |
| 2774 | } |
| 2775 | |
| 2776 | static void create_peer_identifier(GSupplicantPeer *peer) |
| 2777 | { |
| 2778 | const unsigned char test[ETH_ALEN] = {}; |
| 2779 | |
| 2780 | if (!peer) |
| 2781 | return; |
| 2782 | |
| 2783 | if (!memcmp(peer->device_address, test, ETH_ALEN)) { |
| 2784 | peer->identifier = g_strdup(peer->name); |
| 2785 | return; |
| 2786 | } |
| 2787 | |
| 2788 | peer->identifier = g_malloc0(19); |
| 2789 | snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x", |
| 2790 | peer->device_address[0], |
| 2791 | peer->device_address[1], |
| 2792 | peer->device_address[2], |
| 2793 | peer->device_address[3], |
| 2794 | peer->device_address[4], |
| 2795 | peer->device_address[5]); |
| 2796 | } |
| 2797 | |
| 2798 | struct peer_property_data { |
| 2799 | GSupplicantPeer *peer; |
| 2800 | GSList *old_groups; |
| 2801 | bool groups_changed; |
| 2802 | bool services_changed; |
| 2803 | }; |
| 2804 | |
| 2805 | static void peer_groups_relation(DBusMessageIter *iter, void *user_data) |
| 2806 | { |
| 2807 | struct peer_property_data *data = user_data; |
| 2808 | GSupplicantPeer *peer = data->peer; |
| 2809 | GSupplicantGroup *group; |
| 2810 | const char *str = NULL; |
| 2811 | GSList *elem; |
| 2812 | |
| 2813 | dbus_message_iter_get_basic(iter, &str); |
| 2814 | if (!str) |
| 2815 | return; |
| 2816 | |
| 2817 | group = g_hash_table_lookup(group_mapping, str); |
| 2818 | if (!group) |
| 2819 | return; |
| 2820 | |
| 2821 | elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0); |
| 2822 | if (elem) { |
| 2823 | data->old_groups = g_slist_remove_link(data->old_groups, elem); |
| 2824 | peer->groups = g_slist_concat(elem, peer->groups); |
| 2825 | } else { |
| 2826 | peer->groups = g_slist_prepend(peer->groups, g_strdup(str)); |
| 2827 | data->groups_changed = true; |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | static void peer_property(const char *key, DBusMessageIter *iter, |
| 2832 | void *user_data) |
| 2833 | { |
| 2834 | GSupplicantPeer *pending_peer; |
| 2835 | struct peer_property_data *data = user_data; |
| 2836 | GSupplicantPeer *peer = data->peer; |
| 2837 | |
| 2838 | SUPPLICANT_DBG("key: %s", key); |
| 2839 | |
| 2840 | if (!peer->interface) |
| 2841 | return; |
| 2842 | |
| 2843 | if (!key) { |
| 2844 | if (peer->name) { |
| 2845 | create_peer_identifier(peer); |
| 2846 | callback_peer_found(peer); |
| 2847 | pending_peer = g_hash_table_lookup( |
| 2848 | pending_peer_connection, peer->path); |
| 2849 | |
| 2850 | if (pending_peer && pending_peer == peer) { |
| 2851 | callback_peer_request(peer); |
| 2852 | g_hash_table_remove(pending_peer_connection, |
| 2853 | peer->path); |
| 2854 | } |
| 2855 | |
| 2856 | dbus_free(data); |
| 2857 | } |
| 2858 | |
| 2859 | return; |
| 2860 | } |
| 2861 | |
| 2862 | if (g_strcmp0(key, "DeviceAddress") == 0) { |
| 2863 | unsigned char *dev_addr; |
| 2864 | DBusMessageIter array; |
| 2865 | int len; |
| 2866 | |
| 2867 | dbus_message_iter_recurse(iter, &array); |
| 2868 | dbus_message_iter_get_fixed_array(&array, &dev_addr, &len); |
| 2869 | |
| 2870 | if (len == ETH_ALEN) |
| 2871 | memcpy(peer->device_address, dev_addr, len); |
| 2872 | } else if (g_strcmp0(key, "DeviceName") == 0) { |
| 2873 | const char *str = NULL; |
| 2874 | |
| 2875 | dbus_message_iter_get_basic(iter, &str); |
| 2876 | if (str) |
| 2877 | peer->name = g_strdup(str); |
| 2878 | } else if (g_strcmp0(key, "config_method") == 0) { |
| 2879 | uint16_t wps_config; |
| 2880 | |
| 2881 | dbus_message_iter_get_basic(iter, &wps_config); |
| 2882 | |
| 2883 | if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC) |
| 2884 | peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC; |
| 2885 | if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC) |
| 2886 | peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN; |
| 2887 | } else if (g_strcmp0(key, "Groups") == 0) { |
| 2888 | data->old_groups = peer->groups; |
| 2889 | peer->groups = NULL; |
| 2890 | |
| 2891 | supplicant_dbus_array_foreach(iter, |
| 2892 | peer_groups_relation, data); |
| 2893 | if (g_slist_length(data->old_groups) > 0) { |
| 2894 | g_slist_free_full(data->old_groups, g_free); |
| 2895 | data->groups_changed = true; |
| 2896 | } |
| 2897 | } else if (g_strcmp0(key, "IEs") == 0) { |
| 2898 | DBusMessageIter array; |
| 2899 | unsigned char *ie; |
| 2900 | int ie_len; |
| 2901 | |
| 2902 | dbus_message_iter_recurse(iter, &array); |
| 2903 | dbus_message_iter_get_fixed_array(&array, &ie, &ie_len); |
| 2904 | |
| 2905 | if (!ie || ie_len < 2) |
| 2906 | return; |
| 2907 | |
| 2908 | if (peer->widi_ies) { |
| 2909 | if (memcmp(peer->widi_ies, ie, ie_len) == 0) |
| 2910 | return; |
| 2911 | |
| 2912 | g_free(peer->widi_ies); |
| 2913 | peer->widi_ies_length = 0; |
| 2914 | } |
| 2915 | |
| 2916 | peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char)); |
| 2917 | |
| 2918 | memcpy(peer->widi_ies, ie, ie_len); |
| 2919 | peer->widi_ies_length = ie_len; |
| 2920 | data->services_changed = true; |
| 2921 | } |
| 2922 | } |
| 2923 | |
| 2924 | static void signal_peer_found(const char *path, DBusMessageIter *iter) |
| 2925 | { |
| 2926 | struct peer_property_data *property_data; |
| 2927 | GSupplicantInterface *interface; |
| 2928 | const char *obj_path = NULL; |
| 2929 | GSupplicantPeer *peer; |
| 2930 | |
| 2931 | SUPPLICANT_DBG(""); |
| 2932 | |
| 2933 | interface = g_hash_table_lookup(interface_table, path); |
| 2934 | if (!interface) |
| 2935 | return; |
| 2936 | |
| 2937 | dbus_message_iter_get_basic(iter, &obj_path); |
| 2938 | if (!obj_path || g_strcmp0(obj_path, "/") == 0) |
| 2939 | return; |
| 2940 | |
| 2941 | peer = g_hash_table_lookup(interface->peer_table, obj_path); |
| 2942 | if (peer) |
| 2943 | return; |
| 2944 | |
| 2945 | peer = g_try_new0(GSupplicantPeer, 1); |
| 2946 | if (!peer) |
| 2947 | return; |
| 2948 | |
| 2949 | peer->interface = interface; |
| 2950 | peer->path = g_strdup(obj_path); |
| 2951 | g_hash_table_insert(interface->peer_table, peer->path, peer); |
| 2952 | g_hash_table_replace(peer_mapping, peer->path, interface); |
| 2953 | |
| 2954 | property_data = dbus_malloc0(sizeof(struct peer_property_data)); |
| 2955 | property_data->peer = peer; |
| 2956 | |
| 2957 | dbus_message_iter_next(iter); |
| 2958 | if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) { |
| 2959 | supplicant_dbus_property_foreach(iter, peer_property, |
| 2960 | property_data); |
| 2961 | peer_property(NULL, NULL, property_data); |
| 2962 | return; |
| 2963 | } |
| 2964 | |
| 2965 | supplicant_dbus_property_get_all(obj_path, |
| 2966 | SUPPLICANT_INTERFACE ".Peer", |
| 2967 | peer_property, property_data, NULL); |
| 2968 | } |
| 2969 | |
| 2970 | static void signal_peer_lost(const char *path, DBusMessageIter *iter) |
| 2971 | { |
| 2972 | GSupplicantInterface *interface; |
| 2973 | const char *obj_path = NULL; |
| 2974 | GSupplicantPeer *peer; |
| 2975 | |
| 2976 | SUPPLICANT_DBG(""); |
| 2977 | |
| 2978 | interface = g_hash_table_lookup(interface_table, path); |
| 2979 | if (!interface) |
| 2980 | return; |
| 2981 | |
| 2982 | dbus_message_iter_get_basic(iter, &obj_path); |
| 2983 | if (!obj_path || g_strcmp0(obj_path, "/") == 0) |
| 2984 | return; |
| 2985 | |
| 2986 | peer = g_hash_table_lookup(interface->peer_table, obj_path); |
| 2987 | if (!peer) |
| 2988 | return; |
| 2989 | |
| 2990 | g_hash_table_remove(interface->peer_table, obj_path); |
| 2991 | } |
| 2992 | |
| 2993 | static void signal_peer_changed(const char *path, DBusMessageIter *iter) |
| 2994 | { |
| 2995 | struct peer_property_data *property_data; |
| 2996 | GSupplicantInterface *interface; |
| 2997 | GSupplicantPeer *peer; |
| 2998 | |
| 2999 | SUPPLICANT_DBG(""); |
| 3000 | |
| 3001 | interface = g_hash_table_lookup(peer_mapping, path); |
| 3002 | if (!interface) |
| 3003 | return; |
| 3004 | |
| 3005 | peer = g_hash_table_lookup(interface->peer_table, path); |
| 3006 | if (!peer) { |
| 3007 | g_hash_table_remove(peer_mapping, path); |
| 3008 | return; |
| 3009 | } |
| 3010 | |
| 3011 | property_data = dbus_malloc0(sizeof(struct peer_property_data)); |
| 3012 | property_data->peer = peer; |
| 3013 | |
| 3014 | supplicant_dbus_property_foreach(iter, peer_property, property_data); |
| 3015 | if (property_data->services_changed) |
| 3016 | callback_peer_changed(peer, |
| 3017 | G_SUPPLICANT_PEER_SERVICES_CHANGED); |
| 3018 | |
| 3019 | if (property_data->groups_changed) |
| 3020 | callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED); |
| 3021 | |
| 3022 | dbus_free(property_data); |
| 3023 | |
| 3024 | if (!g_supplicant_peer_is_in_a_group(peer)) |
| 3025 | peer->connection_requested = false; |
| 3026 | } |
| 3027 | |
| 3028 | struct group_sig_data { |
| 3029 | const char *peer_obj_path; |
| 3030 | unsigned char iface_address[ETH_ALEN]; |
| 3031 | const char *interface_obj_path; |
| 3032 | const char *group_obj_path; |
| 3033 | int role; |
| 3034 | }; |
| 3035 | |
| 3036 | static void group_sig_property(const char *key, DBusMessageIter *iter, |
| 3037 | void *user_data) |
| 3038 | { |
| 3039 | struct group_sig_data *data = user_data; |
| 3040 | |
| 3041 | if (!key) |
| 3042 | return; |
| 3043 | |
| 3044 | if (g_strcmp0(key, "peer_interface_addr") == 0) { |
| 3045 | unsigned char *dev_addr; |
| 3046 | DBusMessageIter array; |
| 3047 | int len; |
| 3048 | |
| 3049 | dbus_message_iter_recurse(iter, &array); |
| 3050 | dbus_message_iter_get_fixed_array(&array, &dev_addr, &len); |
| 3051 | |
| 3052 | if (len == ETH_ALEN) |
| 3053 | memcpy(data->iface_address, dev_addr, len); |
| 3054 | } else if (g_strcmp0(key, "role") == 0) { |
| 3055 | const char *str = NULL; |
| 3056 | |
| 3057 | dbus_message_iter_get_basic(iter, &str); |
| 3058 | if (g_strcmp0(str, "GO") == 0) |
| 3059 | data->role = G_SUPPLICANT_GROUP_ROLE_GO; |
| 3060 | else |
| 3061 | data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT; |
| 3062 | } else if (g_strcmp0(key, "peer_object") == 0) |
| 3063 | dbus_message_iter_get_basic(iter, &data->peer_obj_path); |
| 3064 | else if (g_strcmp0(key, "interface_object") == 0) |
| 3065 | dbus_message_iter_get_basic(iter, &data->interface_obj_path); |
| 3066 | else if (g_strcmp0(key, "group_object") == 0) |
| 3067 | dbus_message_iter_get_basic(iter, &data->group_obj_path); |
| 3068 | |
| 3069 | } |
| 3070 | |
| 3071 | static void signal_group_success(const char *path, DBusMessageIter *iter) |
| 3072 | { |
| 3073 | GSupplicantInterface *interface; |
| 3074 | struct group_sig_data data = {}; |
| 3075 | GSupplicantPeer *peer; |
| 3076 | |
| 3077 | SUPPLICANT_DBG(""); |
| 3078 | |
| 3079 | interface = g_hash_table_lookup(interface_table, path); |
| 3080 | if (!interface) |
| 3081 | return; |
| 3082 | |
| 3083 | supplicant_dbus_property_foreach(iter, group_sig_property, &data); |
| 3084 | if (!data.peer_obj_path) |
| 3085 | return; |
| 3086 | |
| 3087 | peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path); |
| 3088 | if (!peer) |
| 3089 | return; |
| 3090 | |
| 3091 | memcpy(peer->iface_address, data.iface_address, ETH_ALEN); |
| 3092 | interface->pending_peer_path = peer->path; |
| 3093 | } |
| 3094 | |
| 3095 | static void signal_group_failure(const char *path, DBusMessageIter *iter) |
| 3096 | { |
| 3097 | GSupplicantInterface *interface; |
| 3098 | struct group_sig_data data = {}; |
| 3099 | GSupplicantPeer *peer; |
| 3100 | |
| 3101 | SUPPLICANT_DBG(""); |
| 3102 | |
| 3103 | interface = g_hash_table_lookup(interface_table, path); |
| 3104 | if (!interface) |
| 3105 | return; |
| 3106 | |
| 3107 | supplicant_dbus_property_foreach(iter, group_sig_property, &data); |
| 3108 | if (!data.peer_obj_path) |
| 3109 | return; |
| 3110 | |
| 3111 | peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path); |
| 3112 | if (!peer) |
| 3113 | return; |
| 3114 | |
| 3115 | callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED); |
| 3116 | peer->connection_requested = false; |
| 3117 | } |
| 3118 | |
| 3119 | static void signal_group_started(const char *path, DBusMessageIter *iter) |
| 3120 | { |
| 3121 | GSupplicantInterface *interface, *g_interface; |
| 3122 | struct group_sig_data data = {}; |
| 3123 | GSupplicantGroup *group; |
| 3124 | GSupplicantPeer *peer; |
| 3125 | |
| 3126 | SUPPLICANT_DBG(""); |
| 3127 | |
| 3128 | interface = g_hash_table_lookup(interface_table, path); |
| 3129 | if (!interface) |
| 3130 | return; |
| 3131 | |
| 3132 | supplicant_dbus_property_foreach(iter, group_sig_property, &data); |
| 3133 | if (!data.interface_obj_path || !data.group_obj_path) |
| 3134 | return; |
| 3135 | |
| 3136 | peer = g_hash_table_lookup(interface->peer_table, |
| 3137 | interface->pending_peer_path); |
| 3138 | interface->pending_peer_path = NULL; |
| 3139 | if (!peer) |
| 3140 | return; |
| 3141 | |
| 3142 | g_interface = g_hash_table_lookup(interface_table, |
| 3143 | data.interface_obj_path); |
| 3144 | if (!g_interface) |
| 3145 | return; |
| 3146 | |
| 3147 | group = g_hash_table_lookup(interface->group_table, |
| 3148 | data.group_obj_path); |
| 3149 | if (group) |
| 3150 | return; |
| 3151 | |
| 3152 | group = g_try_new0(GSupplicantGroup, 1); |
| 3153 | if (!group) |
| 3154 | return; |
| 3155 | |
| 3156 | group->interface = g_interface; |
| 3157 | group->orig_interface = interface; |
| 3158 | group->path = g_strdup(data.group_obj_path); |
| 3159 | group->role = data.role; |
| 3160 | |
| 3161 | g_hash_table_insert(interface->group_table, group->path, group); |
| 3162 | g_hash_table_replace(group_mapping, group->path, group); |
| 3163 | |
| 3164 | peer->current_group_iface = g_interface; |
| 3165 | callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED); |
| 3166 | } |
| 3167 | |
| 3168 | static void remove_peer_group_interface(GHashTable *group_table, |
| 3169 | const char* path) |
| 3170 | { |
| 3171 | GSupplicantGroup *group; |
| 3172 | GHashTableIter iter; |
| 3173 | gpointer value, key; |
| 3174 | |
| 3175 | if (!group_table) |
| 3176 | return; |
| 3177 | |
| 3178 | group = g_hash_table_lookup(group_table, path); |
| 3179 | |
| 3180 | if (!group || !group->orig_interface) |
| 3181 | return; |
| 3182 | |
| 3183 | g_hash_table_iter_init(&iter, group->orig_interface->peer_table); |
| 3184 | |
| 3185 | while (g_hash_table_iter_next(&iter, &key, &value)) { |
| 3186 | GSupplicantPeer *peer = value; |
| 3187 | |
| 3188 | if (peer->current_group_iface == group->interface) |
| 3189 | peer->current_group_iface = NULL; |
| 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | static void signal_group_finished(const char *path, DBusMessageIter *iter) |
| 3194 | { |
| 3195 | GSupplicantInterface *interface; |
| 3196 | struct group_sig_data data = {}; |
| 3197 | |
| 3198 | SUPPLICANT_DBG(""); |
| 3199 | |
| 3200 | interface = g_hash_table_lookup(interface_table, path); |
| 3201 | if (!interface) |
| 3202 | return; |
| 3203 | |
| 3204 | supplicant_dbus_property_foreach(iter, group_sig_property, &data); |
| 3205 | if (!data.interface_obj_path || !data.group_obj_path) |
| 3206 | return; |
| 3207 | |
| 3208 | remove_peer_group_interface(interface->group_table, data.group_obj_path); |
| 3209 | |
| 3210 | g_hash_table_remove(group_mapping, data.group_obj_path); |
| 3211 | |
| 3212 | g_hash_table_remove(interface->group_table, data.group_obj_path); |
| 3213 | } |
| 3214 | |
| 3215 | static void signal_group_request(const char *path, DBusMessageIter *iter) |
| 3216 | { |
| 3217 | GSupplicantInterface *interface; |
| 3218 | GSupplicantPeer *peer; |
| 3219 | const char *obj_path; |
| 3220 | |
| 3221 | SUPPLICANT_DBG(""); |
| 3222 | |
| 3223 | interface = g_hash_table_lookup(interface_table, path); |
| 3224 | if (!interface) |
| 3225 | return; |
| 3226 | |
| 3227 | dbus_message_iter_get_basic(iter, &obj_path); |
| 3228 | if (!obj_path || !g_strcmp0(obj_path, "/")) |
| 3229 | return; |
| 3230 | |
| 3231 | peer = g_hash_table_lookup(interface->peer_table, obj_path); |
| 3232 | if (!peer) |
| 3233 | return; |
| 3234 | |
| 3235 | /* |
| 3236 | * Peer has been previously found and property set, |
| 3237 | * otherwise, defer connection to when peer property |
| 3238 | * is set. |
| 3239 | */ |
| 3240 | if (peer->identifier) |
| 3241 | callback_peer_request(peer); |
| 3242 | else |
| 3243 | g_hash_table_replace(pending_peer_connection, peer->path, peer); |
| 3244 | } |
| 3245 | |
| 3246 | static void signal_group_peer_joined(const char *path, DBusMessageIter *iter) |
| 3247 | { |
| 3248 | const char *peer_path = NULL; |
| 3249 | GSupplicantInterface *interface; |
| 3250 | GSupplicantGroup *group; |
| 3251 | GSupplicantPeer *peer; |
| 3252 | |
| 3253 | SUPPLICANT_DBG(""); |
| 3254 | |
| 3255 | group = g_hash_table_lookup(group_mapping, path); |
| 3256 | if (!group) |
| 3257 | return; |
| 3258 | |
| 3259 | dbus_message_iter_get_basic(iter, &peer_path); |
| 3260 | if (!peer_path) |
| 3261 | return; |
| 3262 | |
| 3263 | interface = g_hash_table_lookup(peer_mapping, peer_path); |
| 3264 | if (!interface) |
| 3265 | return; |
| 3266 | |
| 3267 | peer = g_hash_table_lookup(interface->peer_table, peer_path); |
| 3268 | if (!peer) |
| 3269 | return; |
| 3270 | |
| 3271 | group->members = g_slist_prepend(group->members, g_strdup(peer_path)); |
| 3272 | |
| 3273 | callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED); |
| 3274 | } |
| 3275 | |
| 3276 | static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter) |
| 3277 | { |
| 3278 | const char *peer_path = NULL; |
| 3279 | GSupplicantInterface *interface; |
| 3280 | GSupplicantGroup *group; |
| 3281 | GSupplicantPeer *peer; |
| 3282 | GSList *elem; |
| 3283 | |
| 3284 | SUPPLICANT_DBG(""); |
| 3285 | |
| 3286 | group = g_hash_table_lookup(group_mapping, path); |
| 3287 | if (!group) |
| 3288 | return; |
| 3289 | |
| 3290 | dbus_message_iter_get_basic(iter, &peer_path); |
| 3291 | if (!peer_path) |
| 3292 | return; |
| 3293 | |
| 3294 | for (elem = group->members; elem; elem = elem->next) { |
| 3295 | if (!g_strcmp0(elem->data, peer_path)) |
| 3296 | break; |
| 3297 | } |
| 3298 | |
| 3299 | if (!elem) |
| 3300 | return; |
| 3301 | |
| 3302 | g_free(elem->data); |
| 3303 | group->members = g_slist_delete_link(group->members, elem); |
| 3304 | |
| 3305 | interface = g_hash_table_lookup(peer_mapping, peer_path); |
| 3306 | if (!interface) |
| 3307 | return; |
| 3308 | |
| 3309 | peer = g_hash_table_lookup(interface->peer_table, peer_path); |
| 3310 | if (!peer) |
| 3311 | return; |
| 3312 | |
| 3313 | callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED); |
| 3314 | peer->connection_requested = false; |
| 3315 | } |
| 3316 | |
| 3317 | static struct { |
| 3318 | const char *interface; |
| 3319 | const char *member; |
| 3320 | void (*function) (const char *path, DBusMessageIter *iter); |
| 3321 | } signal_map[] = { |
| 3322 | { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed }, |
| 3323 | |
| 3324 | { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed }, |
| 3325 | { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added }, |
| 3326 | { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added }, |
| 3327 | { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed }, |
| 3328 | |
| 3329 | { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed }, |
| 3330 | { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done }, |
| 3331 | { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added }, |
| 3332 | { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed }, |
| 3333 | { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added }, |
| 3334 | { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed }, |
| 3335 | |
| 3336 | { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed }, |
| 3337 | |
| 3338 | { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials }, |
| 3339 | { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event }, |
| 3340 | |
| 3341 | { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found }, |
| 3342 | { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost }, |
| 3343 | |
| 3344 | { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed }, |
| 3345 | |
| 3346 | { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success }, |
| 3347 | { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure }, |
| 3348 | { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started }, |
| 3349 | { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished }, |
| 3350 | { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request }, |
| 3351 | |
| 3352 | { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined }, |
| 3353 | { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected }, |
| 3354 | |
| 3355 | { } |
| 3356 | }; |
| 3357 | |
| 3358 | static DBusHandlerResult g_supplicant_filter(DBusConnection *conn, |
| 3359 | DBusMessage *message, void *data) |
| 3360 | { |
| 3361 | DBusMessageIter iter; |
| 3362 | const char *path; |
| 3363 | int i; |
| 3364 | |
| 3365 | path = dbus_message_get_path(message); |
| 3366 | if (!path) |
| 3367 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 3368 | |
| 3369 | if (!dbus_message_iter_init(message, &iter)) |
| 3370 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 3371 | |
| 3372 | for (i = 0; signal_map[i].interface; i++) { |
| 3373 | if (!dbus_message_has_interface(message, signal_map[i].interface)) |
| 3374 | continue; |
| 3375 | |
| 3376 | if (!dbus_message_has_member(message, signal_map[i].member)) |
| 3377 | continue; |
| 3378 | |
| 3379 | signal_map[i].function(path, &iter); |
| 3380 | break; |
| 3381 | } |
| 3382 | |
| 3383 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 3384 | } |
| 3385 | |
| 3386 | void g_supplicant_interface_cancel(GSupplicantInterface *interface) |
| 3387 | { |
| 3388 | SUPPLICANT_DBG("Cancelling any pending DBus calls"); |
| 3389 | supplicant_dbus_method_call_cancel_all(interface); |
| 3390 | supplicant_dbus_property_call_cancel_all(interface); |
| 3391 | } |
| 3392 | |
| 3393 | struct supplicant_regdom { |
| 3394 | GSupplicantCountryCallback callback; |
| 3395 | const char *alpha2; |
| 3396 | const void *user_data; |
| 3397 | }; |
| 3398 | |
| 3399 | static void country_result(const char *error, |
| 3400 | DBusMessageIter *iter, void *user_data) |
| 3401 | { |
| 3402 | struct supplicant_regdom *regdom = user_data; |
| 3403 | int result = 0; |
| 3404 | |
| 3405 | SUPPLICANT_DBG("Country setting result"); |
| 3406 | |
| 3407 | if (!user_data) |
| 3408 | return; |
| 3409 | |
| 3410 | if (error) { |
| 3411 | SUPPLICANT_DBG("Country setting failure %s", error); |
| 3412 | result = -EINVAL; |
| 3413 | } |
| 3414 | |
| 3415 | if (regdom->callback) |
| 3416 | regdom->callback(result, regdom->alpha2, |
| 3417 | (void *) regdom->user_data); |
| 3418 | |
| 3419 | g_free(regdom); |
| 3420 | } |
| 3421 | |
| 3422 | static void country_params(DBusMessageIter *iter, void *user_data) |
| 3423 | { |
| 3424 | struct supplicant_regdom *regdom = user_data; |
| 3425 | |
| 3426 | dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, |
| 3427 | ®dom->alpha2); |
| 3428 | } |
| 3429 | |
| 3430 | int g_supplicant_set_country(const char *alpha2, |
| 3431 | GSupplicantCountryCallback callback, |
| 3432 | const void *user_data) |
| 3433 | { |
| 3434 | struct supplicant_regdom *regdom; |
| 3435 | int ret; |
| 3436 | |
| 3437 | SUPPLICANT_DBG("Country setting %s", alpha2); |
| 3438 | |
| 3439 | if (!system_available) |
| 3440 | return -EFAULT; |
| 3441 | |
| 3442 | regdom = dbus_malloc0(sizeof(*regdom)); |
| 3443 | if (!regdom) |
| 3444 | return -ENOMEM; |
| 3445 | |
| 3446 | regdom->callback = callback; |
| 3447 | regdom->alpha2 = alpha2; |
| 3448 | regdom->user_data = user_data; |
| 3449 | |
| 3450 | ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE, |
| 3451 | "Country", DBUS_TYPE_STRING_AS_STRING, |
| 3452 | country_params, country_result, |
| 3453 | regdom, NULL); |
| 3454 | if (ret < 0) { |
| 3455 | dbus_free(regdom); |
| 3456 | SUPPLICANT_DBG("Unable to set Country configuration"); |
| 3457 | } |
| 3458 | return ret; |
| 3459 | } |
| 3460 | |
| 3461 | int g_supplicant_interface_set_country(GSupplicantInterface *interface, |
| 3462 | GSupplicantCountryCallback callback, |
| 3463 | const char *alpha2, |
| 3464 | void *user_data) |
| 3465 | { |
| 3466 | struct supplicant_regdom *regdom; |
| 3467 | int ret; |
| 3468 | |
| 3469 | regdom = dbus_malloc0(sizeof(*regdom)); |
| 3470 | if (!regdom) |
| 3471 | return -ENOMEM; |
| 3472 | |
| 3473 | regdom->callback = callback; |
| 3474 | regdom->alpha2 = alpha2; |
| 3475 | regdom->user_data = user_data; |
| 3476 | |
| 3477 | ret = supplicant_dbus_property_set(interface->path, |
| 3478 | SUPPLICANT_INTERFACE ".Interface", |
| 3479 | "Country", DBUS_TYPE_STRING_AS_STRING, |
| 3480 | country_params, country_result, |
| 3481 | regdom, NULL); |
| 3482 | if (ret < 0) { |
| 3483 | dbus_free(regdom); |
| 3484 | SUPPLICANT_DBG("Unable to set Country configuration"); |
| 3485 | } |
| 3486 | |
| 3487 | return ret; |
| 3488 | } |
| 3489 | |
| 3490 | bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface) |
| 3491 | { |
| 3492 | if (!interface) |
| 3493 | return false; |
| 3494 | |
| 3495 | return interface->p2p_support; |
| 3496 | } |
| 3497 | |
| 3498 | struct supplicant_p2p_dev_config { |
| 3499 | char *device_name; |
| 3500 | char *dev_type; |
| 3501 | }; |
| 3502 | |
| 3503 | static void p2p_device_config_result(const char *error, |
| 3504 | DBusMessageIter *iter, void *user_data) |
| 3505 | { |
| 3506 | struct supplicant_p2p_dev_config *config = user_data; |
| 3507 | |
| 3508 | if (error) |
| 3509 | SUPPLICANT_DBG("Unable to set P2P Device configuration: %s", |
| 3510 | error); |
| 3511 | |
| 3512 | g_free(config->device_name); |
| 3513 | g_free(config->dev_type); |
| 3514 | dbus_free(config); |
| 3515 | } |
| 3516 | |
| 3517 | static int dev_type_str2bin(const char *type, unsigned char dev_type[8]) |
| 3518 | { |
| 3519 | int length, pos, end; |
| 3520 | char b[3] = {}; |
| 3521 | char *e = NULL; |
| 3522 | |
| 3523 | end = strlen(type); |
| 3524 | for (length = pos = 0; type[pos] != '\0' && length < 8; length++) { |
| 3525 | if (pos+2 > end) |
| 3526 | return 0; |
| 3527 | |
| 3528 | b[0] = type[pos]; |
| 3529 | b[1] = type[pos+1]; |
| 3530 | |
| 3531 | dev_type[length] = strtol(b, &e, 16); |
| 3532 | if (e && *e != '\0') |
| 3533 | return 0; |
| 3534 | |
| 3535 | pos += 2; |
| 3536 | } |
| 3537 | |
| 3538 | return 8; |
| 3539 | } |
| 3540 | |
| 3541 | static void p2p_device_config_params(DBusMessageIter *iter, void *user_data) |
| 3542 | { |
| 3543 | struct supplicant_p2p_dev_config *config = user_data; |
| 3544 | DBusMessageIter dict; |
| 3545 | |
| 3546 | supplicant_dbus_dict_open(iter, &dict); |
| 3547 | |
| 3548 | supplicant_dbus_dict_append_basic(&dict, "DeviceName", |
| 3549 | DBUS_TYPE_STRING, &config->device_name); |
| 3550 | |
| 3551 | if (config->dev_type) { |
| 3552 | unsigned char dev_type[8] = {}, *type; |
| 3553 | int len; |
| 3554 | |
| 3555 | len = dev_type_str2bin(config->dev_type, dev_type); |
| 3556 | if (len) { |
| 3557 | type = dev_type; |
| 3558 | supplicant_dbus_dict_append_fixed_array(&dict, |
| 3559 | "PrimaryDeviceType", |
| 3560 | DBUS_TYPE_BYTE, &type, len); |
| 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | supplicant_dbus_dict_close(iter, &dict); |
| 3565 | } |
| 3566 | |
| 3567 | int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface, |
| 3568 | const char *device_name, |
| 3569 | const char *primary_dev_type) |
| 3570 | { |
| 3571 | struct supplicant_p2p_dev_config *config; |
| 3572 | int ret; |
| 3573 | |
| 3574 | SUPPLICANT_DBG("P2P Device settings %s/%s", |
| 3575 | device_name, primary_dev_type); |
| 3576 | |
| 3577 | config = dbus_malloc0(sizeof(*config)); |
| 3578 | if (!config) |
| 3579 | return -ENOMEM; |
| 3580 | |
| 3581 | config->device_name = g_strdup(device_name); |
| 3582 | config->dev_type = g_strdup(primary_dev_type); |
| 3583 | |
| 3584 | ret = supplicant_dbus_property_set(interface->path, |
| 3585 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", |
| 3586 | "P2PDeviceConfig", |
| 3587 | DBUS_TYPE_ARRAY_AS_STRING |
| 3588 | DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING |
| 3589 | DBUS_TYPE_STRING_AS_STRING |
| 3590 | DBUS_TYPE_VARIANT_AS_STRING |
| 3591 | DBUS_DICT_ENTRY_END_CHAR_AS_STRING, |
| 3592 | p2p_device_config_params, |
| 3593 | p2p_device_config_result, config, NULL); |
| 3594 | if (ret < 0) { |
| 3595 | g_free(config->device_name); |
| 3596 | g_free(config->dev_type); |
| 3597 | dbus_free(config); |
| 3598 | SUPPLICANT_DBG("Unable to set P2P Device configuration"); |
| 3599 | } |
| 3600 | |
| 3601 | return ret; |
| 3602 | } |
| 3603 | |
| 3604 | static gboolean peer_lookup_by_identifier(gpointer key, gpointer value, |
| 3605 | gpointer user_data) |
| 3606 | { |
| 3607 | const GSupplicantPeer *peer = value; |
| 3608 | const char *identifier = user_data; |
| 3609 | |
| 3610 | if (!g_strcmp0(identifier, peer->identifier)) |
| 3611 | return TRUE; |
| 3612 | |
| 3613 | return FALSE; |
| 3614 | } |
| 3615 | |
| 3616 | GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface, |
| 3617 | const char *identifier) |
| 3618 | { |
| 3619 | GSupplicantPeer *peer; |
| 3620 | |
| 3621 | peer = g_hash_table_find(interface->peer_table, |
| 3622 | peer_lookup_by_identifier, |
| 3623 | (void *) identifier); |
| 3624 | return peer; |
| 3625 | } |
| 3626 | |
| 3627 | static void interface_create_data_free(struct interface_create_data *data) |
| 3628 | { |
| 3629 | g_free(data->ifname); |
| 3630 | g_free(data->driver); |
| 3631 | g_free(data->bridge); |
| 3632 | dbus_free(data); |
| 3633 | } |
| 3634 | |
| 3635 | static bool interface_exists(GSupplicantInterface *interface, |
| 3636 | const char *path) |
| 3637 | { |
| 3638 | GSupplicantInterface *tmp; |
| 3639 | |
| 3640 | tmp = g_hash_table_lookup(interface_table, path); |
| 3641 | if (tmp && tmp == interface) |
| 3642 | return true; |
| 3643 | |
| 3644 | return false; |
| 3645 | } |
| 3646 | |
| 3647 | static void interface_create_property(const char *key, DBusMessageIter *iter, |
| 3648 | void *user_data) |
| 3649 | { |
| 3650 | struct interface_create_data *data = user_data; |
| 3651 | GSupplicantInterface *interface = data->interface; |
| 3652 | |
| 3653 | if (!key) { |
| 3654 | if (data->callback) { |
| 3655 | data->callback(0, data->interface, data->user_data); |
| 3656 | callback_p2p_support(interface); |
| 3657 | } |
| 3658 | |
| 3659 | interface_create_data_free(data); |
| 3660 | } |
| 3661 | |
| 3662 | interface_property(key, iter, interface); |
| 3663 | } |
| 3664 | |
| 3665 | static void interface_create_result(const char *error, |
| 3666 | DBusMessageIter *iter, void *user_data) |
| 3667 | { |
| 3668 | struct interface_create_data *data = user_data; |
| 3669 | const char *path = NULL; |
| 3670 | int err; |
| 3671 | |
| 3672 | SUPPLICANT_DBG(""); |
| 3673 | |
| 3674 | if (error) { |
| 3675 | g_warning("error %s", error); |
| 3676 | err = -EIO; |
| 3677 | goto done; |
| 3678 | } |
| 3679 | |
| 3680 | dbus_message_iter_get_basic(iter, &path); |
| 3681 | if (!path) { |
| 3682 | err = -EINVAL; |
| 3683 | goto done; |
| 3684 | } |
| 3685 | |
| 3686 | if (!system_available) { |
| 3687 | err = -EFAULT; |
| 3688 | goto done; |
| 3689 | } |
| 3690 | |
| 3691 | data->interface = g_hash_table_lookup(interface_table, path); |
| 3692 | if (!data->interface) { |
| 3693 | data->interface = interface_alloc(path); |
| 3694 | if (!data->interface) { |
| 3695 | err = -ENOMEM; |
| 3696 | goto done; |
| 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | err = supplicant_dbus_property_get_all(path, |
| 3701 | SUPPLICANT_INTERFACE ".Interface", |
| 3702 | interface_create_property, data, |
| 3703 | NULL); |
| 3704 | if (err == 0) |
| 3705 | return; |
| 3706 | |
| 3707 | done: |
| 3708 | if (data->callback) |
| 3709 | data->callback(err, NULL, data->user_data); |
| 3710 | |
| 3711 | interface_create_data_free(data); |
| 3712 | } |
| 3713 | |
| 3714 | static void interface_create_params(DBusMessageIter *iter, void *user_data) |
| 3715 | { |
| 3716 | struct interface_create_data *data = user_data; |
| 3717 | DBusMessageIter dict; |
| 3718 | |
| 3719 | SUPPLICANT_DBG(""); |
| 3720 | |
| 3721 | supplicant_dbus_dict_open(iter, &dict); |
| 3722 | |
| 3723 | supplicant_dbus_dict_append_basic(&dict, "Ifname", |
| 3724 | DBUS_TYPE_STRING, &data->ifname); |
| 3725 | |
| 3726 | if (data->driver) |
| 3727 | supplicant_dbus_dict_append_basic(&dict, "Driver", |
| 3728 | DBUS_TYPE_STRING, &data->driver); |
| 3729 | |
| 3730 | if (data->bridge) |
| 3731 | supplicant_dbus_dict_append_basic(&dict, "BridgeIfname", |
| 3732 | DBUS_TYPE_STRING, &data->bridge); |
| 3733 | |
| 3734 | supplicant_dbus_dict_close(iter, &dict); |
| 3735 | } |
| 3736 | |
| 3737 | static void interface_get_result(const char *error, |
| 3738 | DBusMessageIter *iter, void *user_data) |
| 3739 | { |
| 3740 | struct interface_create_data *data = user_data; |
| 3741 | GSupplicantInterface *interface; |
| 3742 | const char *path = NULL; |
| 3743 | int err; |
| 3744 | |
| 3745 | SUPPLICANT_DBG(""); |
| 3746 | |
| 3747 | if (error) { |
| 3748 | SUPPLICANT_DBG("Interface not created yet"); |
| 3749 | goto create; |
| 3750 | } |
| 3751 | |
| 3752 | dbus_message_iter_get_basic(iter, &path); |
| 3753 | if (!path) { |
| 3754 | err = -EINVAL; |
| 3755 | goto done; |
| 3756 | } |
| 3757 | |
| 3758 | interface = g_hash_table_lookup(interface_table, path); |
| 3759 | if (!interface) { |
| 3760 | err = -ENOENT; |
| 3761 | goto done; |
| 3762 | } |
| 3763 | |
| 3764 | if (data->callback) { |
| 3765 | data->callback(0, interface, data->user_data); |
| 3766 | callback_p2p_support(interface); |
| 3767 | } |
| 3768 | |
| 3769 | interface_create_data_free(data); |
| 3770 | |
| 3771 | return; |
| 3772 | |
| 3773 | create: |
| 3774 | if (!system_available) { |
| 3775 | err = -EFAULT; |
| 3776 | goto done; |
| 3777 | } |
| 3778 | |
| 3779 | SUPPLICANT_DBG("Creating interface"); |
| 3780 | |
| 3781 | err = supplicant_dbus_method_call(SUPPLICANT_PATH, |
| 3782 | SUPPLICANT_INTERFACE, |
| 3783 | "CreateInterface", |
| 3784 | interface_create_params, |
| 3785 | interface_create_result, data, |
| 3786 | NULL); |
| 3787 | if (err == 0) |
| 3788 | return; |
| 3789 | |
| 3790 | done: |
| 3791 | if (data->callback) |
| 3792 | data->callback(err, NULL, data->user_data); |
| 3793 | |
| 3794 | interface_create_data_free(data); |
| 3795 | } |
| 3796 | |
| 3797 | static void interface_get_params(DBusMessageIter *iter, void *user_data) |
| 3798 | { |
| 3799 | struct interface_create_data *data = user_data; |
| 3800 | |
| 3801 | SUPPLICANT_DBG(""); |
| 3802 | |
| 3803 | dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname); |
| 3804 | } |
| 3805 | |
| 3806 | int g_supplicant_interface_create(const char *ifname, const char *driver, |
| 3807 | const char *bridge, |
| 3808 | GSupplicantInterfaceCallback callback, |
| 3809 | void *user_data) |
| 3810 | { |
| 3811 | struct interface_create_data *data; |
| 3812 | int ret; |
| 3813 | |
| 3814 | connman_info("%s ifname %s", __FUNCTION__, ifname); |
| 3815 | |
| 3816 | if (!ifname) |
| 3817 | return -EINVAL; |
| 3818 | |
| 3819 | if (!system_available) |
| 3820 | return -EFAULT; |
| 3821 | |
| 3822 | data = dbus_malloc0(sizeof(*data)); |
| 3823 | if (!data) |
| 3824 | return -ENOMEM; |
| 3825 | |
| 3826 | data->ifname = g_strdup(ifname); |
| 3827 | data->driver = g_strdup(driver); |
| 3828 | data->bridge = g_strdup(bridge); |
| 3829 | data->callback = callback; |
| 3830 | data->user_data = user_data; |
| 3831 | |
| 3832 | ret = supplicant_dbus_method_call(SUPPLICANT_PATH, |
| 3833 | SUPPLICANT_INTERFACE, |
| 3834 | "GetInterface", |
| 3835 | interface_get_params, |
| 3836 | interface_get_result, data, |
| 3837 | NULL); |
| 3838 | if (ret < 0) |
| 3839 | interface_create_data_free(data); |
| 3840 | |
| 3841 | return ret; |
| 3842 | } |
| 3843 | |
| 3844 | static void interface_remove_result(const char *error, |
| 3845 | DBusMessageIter *iter, void *user_data) |
| 3846 | { |
| 3847 | struct interface_data *data = user_data; |
| 3848 | int err; |
| 3849 | |
| 3850 | if (error) { |
| 3851 | err = -EIO; |
| 3852 | goto done; |
| 3853 | } |
| 3854 | |
| 3855 | if (!system_available) { |
| 3856 | err = -EFAULT; |
| 3857 | goto done; |
| 3858 | } |
| 3859 | |
| 3860 | /* |
| 3861 | * The gsupplicant interface is already freed by the InterfaceRemoved |
| 3862 | * signal callback. Simply invoke the interface_data callback. |
| 3863 | */ |
| 3864 | err = 0; |
| 3865 | |
| 3866 | done: |
| 3867 | g_free(data->path); |
| 3868 | |
| 3869 | if (data->callback) |
| 3870 | data->callback(err, NULL, data->user_data); |
| 3871 | |
| 3872 | dbus_free(data); |
| 3873 | } |
| 3874 | |
| 3875 | |
| 3876 | static void interface_remove_params(DBusMessageIter *iter, void *user_data) |
| 3877 | { |
| 3878 | struct interface_data *data = user_data; |
| 3879 | |
| 3880 | dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, |
| 3881 | &data->interface->path); |
| 3882 | } |
| 3883 | |
| 3884 | |
| 3885 | int g_supplicant_interface_remove(GSupplicantInterface *interface, |
| 3886 | GSupplicantInterfaceCallback callback, |
| 3887 | void *user_data) |
| 3888 | { |
| 3889 | struct interface_data *data; |
| 3890 | int ret; |
| 3891 | |
| 3892 | if (!interface) |
| 3893 | return -EINVAL; |
| 3894 | |
| 3895 | if (!system_available) |
| 3896 | return -EFAULT; |
| 3897 | |
| 3898 | g_supplicant_interface_cancel(interface); |
| 3899 | |
| 3900 | data = dbus_malloc0(sizeof(*data)); |
| 3901 | if (!data) |
| 3902 | return -ENOMEM; |
| 3903 | |
| 3904 | data->interface = interface; |
| 3905 | data->path = g_strdup(interface->path); |
| 3906 | data->callback = callback; |
| 3907 | data->user_data = user_data; |
| 3908 | |
| 3909 | ret = supplicant_dbus_method_call(SUPPLICANT_PATH, |
| 3910 | SUPPLICANT_INTERFACE, |
| 3911 | "RemoveInterface", |
| 3912 | interface_remove_params, |
| 3913 | interface_remove_result, data, |
| 3914 | NULL); |
| 3915 | if (ret < 0) { |
| 3916 | g_free(data->path); |
| 3917 | dbus_free(data); |
| 3918 | } |
| 3919 | return ret; |
| 3920 | } |
| 3921 | |
| 3922 | static void interface_scan_result(const char *error, |
| 3923 | DBusMessageIter *iter, void *user_data) |
| 3924 | { |
| 3925 | struct interface_scan_data *data = user_data; |
| 3926 | int err = 0; |
| 3927 | |
| 3928 | if (error) { |
| 3929 | SUPPLICANT_DBG("error %s", error); |
| 3930 | err = -EIO; |
| 3931 | } |
| 3932 | |
| 3933 | /* A non ready interface cannot send/receive anything */ |
| 3934 | if (interface_exists(data->interface, data->path)) { |
| 3935 | if (!data->interface->ready) |
| 3936 | err = -ENOLINK; |
| 3937 | } |
| 3938 | |
| 3939 | g_free(data->path); |
| 3940 | |
| 3941 | if (err != 0) { |
| 3942 | if (data->callback) |
| 3943 | data->callback(err, data->interface, data->user_data); |
| 3944 | } else { |
| 3945 | data->interface->scan_callback = data->callback; |
| 3946 | data->interface->scan_data = data->user_data; |
| 3947 | } |
| 3948 | |
| 3949 | if (data->scan_params) |
| 3950 | g_supplicant_free_scan_params(data->scan_params); |
| 3951 | |
| 3952 | dbus_free(data); |
| 3953 | } |
| 3954 | |
| 3955 | static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq) |
| 3956 | { |
| 3957 | DBusMessageIter data; |
| 3958 | unsigned int width = 0; /* Not used by wpa_supplicant atm */ |
| 3959 | |
| 3960 | dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data); |
| 3961 | |
| 3962 | dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq); |
| 3963 | dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width); |
| 3964 | |
| 3965 | dbus_message_iter_close_container(iter, &data); |
| 3966 | } |
| 3967 | |
| 3968 | static void add_scan_frequencies(DBusMessageIter *iter, |
| 3969 | void *user_data) |
| 3970 | { |
| 3971 | GSupplicantScanParams *scan_data = user_data; |
| 3972 | unsigned int freq; |
| 3973 | int i; |
| 3974 | |
| 3975 | for (i = 0; i < scan_data->num_freqs; i++) { |
| 3976 | freq = scan_data->freqs[i]; |
| 3977 | if (!freq) |
| 3978 | break; |
| 3979 | |
| 3980 | add_scan_frequency(iter, freq); |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | static void append_ssid(DBusMessageIter *iter, |
| 3985 | const void *ssid, unsigned int len) |
| 3986 | { |
| 3987 | DBusMessageIter array; |
| 3988 | |
| 3989 | dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, |
| 3990 | DBUS_TYPE_BYTE_AS_STRING, &array); |
| 3991 | |
| 3992 | dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE, |
| 3993 | &ssid, len); |
| 3994 | dbus_message_iter_close_container(iter, &array); |
| 3995 | } |
| 3996 | |
| 3997 | static void append_ssids(DBusMessageIter *iter, void *user_data) |
| 3998 | { |
| 3999 | GSupplicantScanParams *scan_data = user_data; |
| 4000 | GSList *list; |
| 4001 | |
| 4002 | for (list = scan_data->ssids; list; list = list->next) { |
| 4003 | struct scan_ssid *scan_ssid = list->data; |
| 4004 | |
| 4005 | append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len); |
| 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | static void supplicant_add_scan_frequency(DBusMessageIter *dict, |
| 4010 | supplicant_dbus_array_function function, |
| 4011 | void *user_data) |
| 4012 | { |
| 4013 | GSupplicantScanParams *scan_params = user_data; |
| 4014 | DBusMessageIter entry, value, array; |
| 4015 | const char *key = "Channels"; |
| 4016 | |
| 4017 | if (scan_params->freqs && scan_params->freqs[0] != 0) { |
| 4018 | dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, |
| 4019 | NULL, &entry); |
| 4020 | |
| 4021 | dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); |
| 4022 | |
| 4023 | dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, |
| 4024 | DBUS_TYPE_ARRAY_AS_STRING |
| 4025 | DBUS_STRUCT_BEGIN_CHAR_AS_STRING |
| 4026 | DBUS_TYPE_UINT32_AS_STRING |
| 4027 | DBUS_TYPE_UINT32_AS_STRING |
| 4028 | DBUS_STRUCT_END_CHAR_AS_STRING, |
| 4029 | &value); |
| 4030 | |
| 4031 | dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, |
| 4032 | DBUS_STRUCT_BEGIN_CHAR_AS_STRING |
| 4033 | DBUS_TYPE_UINT32_AS_STRING |
| 4034 | DBUS_TYPE_UINT32_AS_STRING |
| 4035 | DBUS_STRUCT_END_CHAR_AS_STRING, |
| 4036 | &array); |
| 4037 | |
| 4038 | if (function) |
| 4039 | function(&array, user_data); |
| 4040 | |
| 4041 | dbus_message_iter_close_container(&value, &array); |
| 4042 | dbus_message_iter_close_container(&entry, &value); |
| 4043 | dbus_message_iter_close_container(dict, &entry); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | static void interface_scan_params(DBusMessageIter *iter, void *user_data) |
| 4048 | { |
| 4049 | DBusMessageIter dict; |
| 4050 | const char *type = "passive"; |
| 4051 | struct interface_scan_data *data = user_data; |
| 4052 | |
| 4053 | supplicant_dbus_dict_open(iter, &dict); |
| 4054 | |
| 4055 | if (data && data->scan_params) { |
| 4056 | type = "active"; |
| 4057 | |
| 4058 | supplicant_dbus_dict_append_basic(&dict, "Type", |
| 4059 | DBUS_TYPE_STRING, &type); |
| 4060 | |
| 4061 | supplicant_dbus_dict_append_array(&dict, "SSIDs", |
| 4062 | DBUS_TYPE_STRING, |
| 4063 | append_ssids, |
| 4064 | data->scan_params); |
| 4065 | |
| 4066 | supplicant_add_scan_frequency(&dict, add_scan_frequencies, |
| 4067 | data->scan_params); |
| 4068 | } else |
| 4069 | supplicant_dbus_dict_append_basic(&dict, "Type", |
| 4070 | DBUS_TYPE_STRING, &type); |
| 4071 | |
| 4072 | supplicant_dbus_dict_close(iter, &dict); |
| 4073 | } |
| 4074 | |
| 4075 | static int interface_ready_to_scan(GSupplicantInterface *interface) |
| 4076 | { |
| 4077 | if (!interface) |
| 4078 | return -EINVAL; |
| 4079 | |
| 4080 | if (!system_available) |
| 4081 | return -EFAULT; |
| 4082 | |
| 4083 | if (interface->scanning) |
| 4084 | return -EALREADY; |
| 4085 | |
| 4086 | switch (interface->state) { |
| 4087 | case G_SUPPLICANT_STATE_AUTHENTICATING: |
| 4088 | case G_SUPPLICANT_STATE_ASSOCIATING: |
| 4089 | case G_SUPPLICANT_STATE_ASSOCIATED: |
| 4090 | case G_SUPPLICANT_STATE_4WAY_HANDSHAKE: |
| 4091 | case G_SUPPLICANT_STATE_GROUP_HANDSHAKE: |
| 4092 | return -EBUSY; |
| 4093 | case G_SUPPLICANT_STATE_UNKNOWN: |
| 4094 | case G_SUPPLICANT_STATE_DISABLED: |
| 4095 | case G_SUPPLICANT_STATE_DISCONNECTED: |
| 4096 | case G_SUPPLICANT_STATE_INACTIVE: |
| 4097 | case G_SUPPLICANT_STATE_SCANNING: |
| 4098 | case G_SUPPLICANT_STATE_COMPLETED: |
| 4099 | break; |
| 4100 | } |
| 4101 | |
| 4102 | return 0; |
| 4103 | } |
| 4104 | |
| 4105 | int g_supplicant_interface_scan(GSupplicantInterface *interface, |
| 4106 | GSupplicantScanParams *scan_data, |
| 4107 | GSupplicantInterfaceCallback callback, |
| 4108 | void *user_data) |
| 4109 | { |
| 4110 | struct interface_scan_data *data; |
| 4111 | int ret; |
| 4112 | |
| 4113 | ret = interface_ready_to_scan(interface); |
| 4114 | if (ret) |
| 4115 | return ret; |
| 4116 | |
| 4117 | data = dbus_malloc0(sizeof(*data)); |
| 4118 | if (!data) |
| 4119 | return -ENOMEM; |
| 4120 | |
| 4121 | data->interface = interface; |
| 4122 | data->path = g_strdup(interface->path); |
| 4123 | data->callback = callback; |
| 4124 | data->user_data = user_data; |
| 4125 | data->scan_params = scan_data; |
| 4126 | |
| 4127 | interface->scan_callback = callback; |
| 4128 | interface->scan_data = user_data; |
| 4129 | |
| 4130 | ret = supplicant_dbus_method_call(interface->path, |
| 4131 | SUPPLICANT_INTERFACE ".Interface", "Scan", |
| 4132 | interface_scan_params, interface_scan_result, data, |
| 4133 | interface); |
| 4134 | |
| 4135 | if (ret < 0) { |
| 4136 | g_free(data->path); |
| 4137 | dbus_free(data); |
| 4138 | } |
| 4139 | |
| 4140 | return ret; |
| 4141 | } |
| 4142 | |
| 4143 | static int parse_supplicant_error(DBusMessageIter *iter) |
| 4144 | { |
| 4145 | int err = -ECANCELED; |
| 4146 | char *key; |
| 4147 | |
| 4148 | if (!iter) |
| 4149 | return err; |
| 4150 | |
| 4151 | /* If the given passphrase is malformed wpa_s returns |
| 4152 | * "invalid message format" but this error should be interpreted as |
| 4153 | * invalid-key. |
| 4154 | */ |
| 4155 | while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) { |
| 4156 | dbus_message_iter_get_basic(iter, &key); |
| 4157 | if (strncmp(key, "psk", 3) == 0 || |
| 4158 | strncmp(key, "wep_key", 7) == 0 || |
| 4159 | strcmp(key, "invalid message format") == 0) { |
| 4160 | err = -ENOKEY; |
| 4161 | break; |
| 4162 | } |
| 4163 | dbus_message_iter_next(iter); |
| 4164 | } |
| 4165 | |
| 4166 | return err; |
| 4167 | } |
| 4168 | |
| 4169 | static void interface_select_network_result(const char *error, |
| 4170 | DBusMessageIter *iter, void *user_data) |
| 4171 | { |
| 4172 | struct interface_connect_data *data = user_data; |
| 4173 | int err; |
| 4174 | |
| 4175 | SUPPLICANT_DBG(""); |
| 4176 | |
| 4177 | err = 0; |
| 4178 | if (error) { |
| 4179 | SUPPLICANT_DBG("SelectNetwork error %s", error); |
| 4180 | err = parse_supplicant_error(iter); |
| 4181 | } |
| 4182 | |
| 4183 | g_free(data->path); |
| 4184 | |
| 4185 | if (data->callback) |
| 4186 | data->callback(err, data->interface, data->user_data); |
| 4187 | |
| 4188 | g_free(data->ssid); |
| 4189 | dbus_free(data); |
| 4190 | } |
| 4191 | |
| 4192 | static void interface_select_network_params(DBusMessageIter *iter, |
| 4193 | void *user_data) |
| 4194 | { |
| 4195 | struct interface_connect_data *data = user_data; |
| 4196 | GSupplicantInterface *interface = data->interface; |
| 4197 | |
| 4198 | dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, |
| 4199 | &interface->network_path); |
| 4200 | } |
| 4201 | |
| 4202 | static void interface_add_network_result(const char *error, |
| 4203 | DBusMessageIter *iter, void *user_data) |
| 4204 | { |
| 4205 | struct interface_connect_data *data = user_data; |
| 4206 | GSupplicantInterface *interface = data->interface; |
| 4207 | const char *path; |
| 4208 | int err; |
| 4209 | |
| 4210 | if (error) |
| 4211 | goto error; |
| 4212 | |
| 4213 | dbus_message_iter_get_basic(iter, &path); |
| 4214 | if (!path) |
| 4215 | goto error; |
| 4216 | |
| 4217 | SUPPLICANT_DBG("PATH: %s", path); |
| 4218 | |
| 4219 | interface->network_path = g_strdup(path); |
| 4220 | |
| 4221 | g_hash_table_insert(interface->config_mapping, data->ssid->network_group, g_strdup(path)); |
| 4222 | SUPPLICANT_DBG("Add group %s config_path %s to config_mapping", data->ssid->network_group, path); |
| 4223 | |
| 4224 | store_network_information(interface, data->ssid); |
| 4225 | |
| 4226 | supplicant_dbus_method_call(data->interface->path, |
| 4227 | SUPPLICANT_INTERFACE ".Interface", "SelectNetwork", |
| 4228 | interface_select_network_params, |
| 4229 | interface_select_network_result, data, |
| 4230 | interface); |
| 4231 | |
| 4232 | return; |
| 4233 | |
| 4234 | error: |
| 4235 | SUPPLICANT_DBG("AddNetwork error %s", error); |
| 4236 | |
| 4237 | if (interface_exists(data->interface, data->interface->path)) { |
| 4238 | err = parse_supplicant_error(iter); |
| 4239 | if (data->callback) |
| 4240 | data->callback(err, data->interface, data->user_data); |
| 4241 | |
| 4242 | g_free(interface->network_path); |
| 4243 | interface->network_path = NULL; |
| 4244 | } |
| 4245 | |
| 4246 | g_free(data->path); |
| 4247 | g_free(data->ssid); |
| 4248 | g_free(data); |
| 4249 | } |
| 4250 | |
| 4251 | static void add_network_security_none(DBusMessageIter *dict) |
| 4252 | { |
| 4253 | const char *auth_alg = "OPEN"; |
| 4254 | |
| 4255 | supplicant_dbus_dict_append_basic(dict, "auth_alg", |
| 4256 | DBUS_TYPE_STRING, &auth_alg); |
| 4257 | } |
| 4258 | |
| 4259 | static void add_network_security_wep(DBusMessageIter *dict, |
| 4260 | GSupplicantSSID *ssid) |
| 4261 | { |
| 4262 | const char *auth_alg = "OPEN SHARED"; |
| 4263 | dbus_uint32_t key_index = 0; |
| 4264 | |
| 4265 | supplicant_dbus_dict_append_basic(dict, "auth_alg", |
| 4266 | DBUS_TYPE_STRING, &auth_alg); |
| 4267 | |
| 4268 | if (ssid->passphrase) { |
| 4269 | int size = strlen(ssid->passphrase); |
| 4270 | if (size == 10 || size == 26) { |
| 4271 | unsigned char *key = g_try_malloc(13); |
| 4272 | char tmp[3]; |
| 4273 | int i; |
| 4274 | |
| 4275 | memset(tmp, 0, sizeof(tmp)); |
| 4276 | if (!key) |
| 4277 | size = 0; |
| 4278 | |
| 4279 | for (i = 0; i < size / 2; i++) { |
| 4280 | memcpy(tmp, ssid->passphrase + (i * 2), 2); |
| 4281 | key[i] = (unsigned char) strtol(tmp, NULL, 16); |
| 4282 | } |
| 4283 | |
| 4284 | supplicant_dbus_dict_append_fixed_array(dict, |
| 4285 | "wep_key0", |
| 4286 | DBUS_TYPE_BYTE, |
| 4287 | &key, size / 2); |
| 4288 | g_free(key); |
| 4289 | } else if (size == 5 || size == 13) { |
| 4290 | unsigned char *key = g_try_malloc(13); |
| 4291 | int i; |
| 4292 | |
| 4293 | if (!key) |
| 4294 | size = 0; |
| 4295 | |
| 4296 | for (i = 0; i < size; i++) |
| 4297 | key[i] = (unsigned char) ssid->passphrase[i]; |
| 4298 | |
| 4299 | supplicant_dbus_dict_append_fixed_array(dict, |
| 4300 | "wep_key0", |
| 4301 | DBUS_TYPE_BYTE, |
| 4302 | &key, size); |
| 4303 | g_free(key); |
| 4304 | } else |
| 4305 | supplicant_dbus_dict_append_basic(dict, |
| 4306 | "wep_key0", |
| 4307 | DBUS_TYPE_STRING, |
| 4308 | &ssid->passphrase); |
| 4309 | |
| 4310 | supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx", |
| 4311 | DBUS_TYPE_UINT32, &key_index); |
| 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | static dbus_bool_t is_psk_raw_key(const char *psk) |
| 4316 | { |
| 4317 | int i; |
| 4318 | |
| 4319 | /* A raw key is always 64 bytes length... */ |
| 4320 | if (strlen(psk) != 64) |
| 4321 | return FALSE; |
| 4322 | |
| 4323 | /* ... and its content is in hex representation */ |
| 4324 | for (i = 0; i < 64; i++) |
| 4325 | if (!isxdigit((unsigned char) psk[i])) |
| 4326 | return FALSE; |
| 4327 | |
| 4328 | return TRUE; |
| 4329 | } |
| 4330 | |
| 4331 | static unsigned char hexchar2bin(char c) |
| 4332 | { |
| 4333 | if ((c >= '0') && (c <= '9')) |
| 4334 | return c - '0'; |
| 4335 | else if ((c >= 'A') && (c <= 'F')) |
| 4336 | return c - 'A' + 10; |
| 4337 | else if ((c >= 'a') && (c <= 'f')) |
| 4338 | return c - 'a' + 10; |
| 4339 | else |
| 4340 | return c; |
| 4341 | } |
| 4342 | |
| 4343 | static void hexstring2bin(const char *string, unsigned char *data, |
| 4344 | size_t data_len) |
| 4345 | { |
| 4346 | size_t i; |
| 4347 | |
| 4348 | for (i = 0; i < data_len; i++) |
| 4349 | data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 | |
| 4350 | hexchar2bin(string[i * 2 + 1]) << 0); |
| 4351 | } |
| 4352 | |
| 4353 | static void add_network_security_psk(DBusMessageIter *dict, |
| 4354 | GSupplicantSSID *ssid) |
| 4355 | { |
| 4356 | if (ssid->passphrase && strlen(ssid->passphrase) > 0) { |
| 4357 | const char *key = "psk"; |
| 4358 | |
| 4359 | if (is_psk_raw_key(ssid->passphrase)) { |
| 4360 | unsigned char data[32]; |
| 4361 | unsigned char *datap = data; |
| 4362 | |
| 4363 | /* The above pointer alias is required by D-Bus because |
| 4364 | * with D-Bus and GCC, non-heap-allocated arrays cannot |
| 4365 | * be passed directly by their base pointer. */ |
| 4366 | |
| 4367 | hexstring2bin(ssid->passphrase, datap, sizeof(data)); |
| 4368 | |
| 4369 | supplicant_dbus_dict_append_fixed_array(dict, |
| 4370 | key, DBUS_TYPE_BYTE, |
| 4371 | &datap, sizeof(data)); |
| 4372 | } else |
| 4373 | supplicant_dbus_dict_append_basic(dict, |
| 4374 | key, DBUS_TYPE_STRING, |
| 4375 | &ssid->passphrase); |
| 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | static void add_network_security_tls(DBusMessageIter *dict, |
| 4380 | GSupplicantSSID *ssid) |
| 4381 | { |
| 4382 | /* |
| 4383 | * For TLS, we at least need: |
| 4384 | * The client certificate |
| 4385 | * The client private key file |
| 4386 | * The client private key file password |
| 4387 | * |
| 4388 | * The Authority certificate is optional. |
| 4389 | */ |
| 4390 | if (!ssid->client_cert_path) |
| 4391 | return; |
| 4392 | |
| 4393 | if (!ssid->private_key_path) |
| 4394 | return; |
| 4395 | |
| 4396 | if (!ssid->private_key_passphrase) |
| 4397 | return; |
| 4398 | |
| 4399 | if (ssid->ca_cert_path) |
| 4400 | supplicant_dbus_dict_append_basic(dict, "ca_cert", |
| 4401 | DBUS_TYPE_STRING, &ssid->ca_cert_path); |
| 4402 | |
| 4403 | supplicant_dbus_dict_append_basic(dict, "private_key", |
| 4404 | DBUS_TYPE_STRING, |
| 4405 | &ssid->private_key_path); |
| 4406 | supplicant_dbus_dict_append_basic(dict, "private_key_passwd", |
| 4407 | DBUS_TYPE_STRING, |
| 4408 | &ssid->private_key_passphrase); |
| 4409 | supplicant_dbus_dict_append_basic(dict, "client_cert", |
| 4410 | DBUS_TYPE_STRING, |
| 4411 | &ssid->client_cert_path); |
| 4412 | } |
| 4413 | |
| 4414 | static void add_network_security_peap(DBusMessageIter *dict, |
| 4415 | GSupplicantSSID *ssid) |
| 4416 | { |
| 4417 | char *phase2_auth; |
| 4418 | |
| 4419 | /* |
| 4420 | * For PEAP/TTLS, we at least need |
| 4421 | * The authority certificate |
| 4422 | * The 2nd phase authentication method |
| 4423 | * The 2nd phase passphrase |
| 4424 | * |
| 4425 | * The Client certificate is optional although strongly recommended |
| 4426 | * When setting it, we need in addition |
| 4427 | * The Client private key file |
| 4428 | * The Client private key file password |
| 4429 | */ |
| 4430 | if (!ssid->passphrase) |
| 4431 | return; |
| 4432 | |
| 4433 | if (!ssid->phase2_auth) |
| 4434 | return; |
| 4435 | |
| 4436 | if (ssid->client_cert_path) { |
| 4437 | if (!ssid->private_key_path) |
| 4438 | return; |
| 4439 | |
| 4440 | if (!ssid->private_key_passphrase) |
| 4441 | return; |
| 4442 | |
| 4443 | supplicant_dbus_dict_append_basic(dict, "client_cert", |
| 4444 | DBUS_TYPE_STRING, |
| 4445 | &ssid->client_cert_path); |
| 4446 | |
| 4447 | supplicant_dbus_dict_append_basic(dict, "private_key", |
| 4448 | DBUS_TYPE_STRING, |
| 4449 | &ssid->private_key_path); |
| 4450 | |
| 4451 | supplicant_dbus_dict_append_basic(dict, "private_key_passwd", |
| 4452 | DBUS_TYPE_STRING, |
| 4453 | &ssid->private_key_passphrase); |
| 4454 | |
| 4455 | } |
| 4456 | |
| 4457 | if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) { |
| 4458 | phase2_auth = g_strdup_printf("autheap=%s", |
| 4459 | ssid->phase2_auth + strlen("EAP-")); |
| 4460 | } else |
| 4461 | phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth); |
| 4462 | |
| 4463 | supplicant_dbus_dict_append_basic(dict, "password", |
| 4464 | DBUS_TYPE_STRING, |
| 4465 | &ssid->passphrase); |
| 4466 | |
| 4467 | if (ssid->ca_cert_path) |
| 4468 | supplicant_dbus_dict_append_basic(dict, "ca_cert", |
| 4469 | DBUS_TYPE_STRING, |
| 4470 | &ssid->ca_cert_path); |
| 4471 | |
| 4472 | supplicant_dbus_dict_append_basic(dict, "phase2", |
| 4473 | DBUS_TYPE_STRING, |
| 4474 | &phase2_auth); |
| 4475 | |
| 4476 | g_free(phase2_auth); |
| 4477 | } |
| 4478 | |
| 4479 | static void add_network_security_eap(DBusMessageIter *dict, |
| 4480 | GSupplicantSSID *ssid) |
| 4481 | { |
| 4482 | char *eap_value; |
| 4483 | |
| 4484 | if (!ssid->eap || !ssid->identity) |
| 4485 | return; |
| 4486 | |
| 4487 | if (g_strcmp0(ssid->eap, "tls") == 0) { |
| 4488 | add_network_security_tls(dict, ssid); |
| 4489 | } else if (g_strcmp0(ssid->eap, "peap") == 0 || |
| 4490 | g_strcmp0(ssid->eap, "ttls") == 0) { |
| 4491 | add_network_security_peap(dict, ssid); |
| 4492 | } else |
| 4493 | return; |
| 4494 | |
| 4495 | eap_value = g_ascii_strup(ssid->eap, -1); |
| 4496 | |
| 4497 | supplicant_dbus_dict_append_basic(dict, "eap", |
| 4498 | DBUS_TYPE_STRING, |
| 4499 | &eap_value); |
| 4500 | supplicant_dbus_dict_append_basic(dict, "identity", |
| 4501 | DBUS_TYPE_STRING, |
| 4502 | &ssid->identity); |
| 4503 | |
| 4504 | g_free(eap_value); |
| 4505 | } |
| 4506 | |
| 4507 | static void add_network_security_ciphers(DBusMessageIter *dict, |
| 4508 | GSupplicantSSID *ssid) |
| 4509 | { |
| 4510 | unsigned int p_cipher, g_cipher, i; |
| 4511 | char *pairwise, *group; |
| 4512 | char *pair_ciphers[4]; |
| 4513 | char *group_ciphers[5]; |
| 4514 | |
| 4515 | p_cipher = ssid->pairwise_cipher; |
| 4516 | g_cipher = ssid->group_cipher; |
| 4517 | |
| 4518 | if (p_cipher == 0 && g_cipher == 0) |
| 4519 | return; |
| 4520 | |
| 4521 | i = 0; |
| 4522 | |
| 4523 | if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP) |
| 4524 | pair_ciphers[i++] = "CCMP"; |
| 4525 | |
| 4526 | if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP) |
| 4527 | pair_ciphers[i++] = "TKIP"; |
| 4528 | |
| 4529 | if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE) |
| 4530 | pair_ciphers[i++] = "NONE"; |
| 4531 | |
| 4532 | pair_ciphers[i] = NULL; |
| 4533 | |
| 4534 | i = 0; |
| 4535 | |
| 4536 | if (g_cipher & G_SUPPLICANT_GROUP_CCMP) |
| 4537 | group_ciphers[i++] = "CCMP"; |
| 4538 | |
| 4539 | if (g_cipher & G_SUPPLICANT_GROUP_TKIP) |
| 4540 | group_ciphers[i++] = "TKIP"; |
| 4541 | |
| 4542 | if (g_cipher & G_SUPPLICANT_GROUP_WEP104) |
| 4543 | group_ciphers[i++] = "WEP104"; |
| 4544 | |
| 4545 | if (g_cipher & G_SUPPLICANT_GROUP_WEP40) |
| 4546 | group_ciphers[i++] = "WEP40"; |
| 4547 | |
| 4548 | group_ciphers[i] = NULL; |
| 4549 | |
| 4550 | pairwise = g_strjoinv(" ", pair_ciphers); |
| 4551 | group = g_strjoinv(" ", group_ciphers); |
| 4552 | |
| 4553 | SUPPLICANT_DBG("cipher %s %s", pairwise, group); |
| 4554 | |
| 4555 | supplicant_dbus_dict_append_basic(dict, "pairwise", |
| 4556 | DBUS_TYPE_STRING, |
| 4557 | &pairwise); |
| 4558 | supplicant_dbus_dict_append_basic(dict, "group", |
| 4559 | DBUS_TYPE_STRING, |
| 4560 | &group); |
| 4561 | |
| 4562 | g_free(pairwise); |
| 4563 | g_free(group); |
| 4564 | } |
| 4565 | |
| 4566 | static void add_network_security_proto(DBusMessageIter *dict, |
| 4567 | GSupplicantSSID *ssid) |
| 4568 | { |
| 4569 | unsigned int protocol, i; |
| 4570 | char *proto; |
| 4571 | char *protos[3]; |
| 4572 | |
| 4573 | protocol = ssid->protocol; |
| 4574 | |
| 4575 | if (protocol == 0) |
| 4576 | return; |
| 4577 | |
| 4578 | i = 0; |
| 4579 | |
| 4580 | if (protocol & G_SUPPLICANT_PROTO_RSN) |
| 4581 | protos[i++] = "RSN"; |
| 4582 | |
| 4583 | if (protocol & G_SUPPLICANT_PROTO_WPA) |
| 4584 | protos[i++] = "WPA"; |
| 4585 | |
| 4586 | protos[i] = NULL; |
| 4587 | |
| 4588 | proto = g_strjoinv(" ", protos); |
| 4589 | |
| 4590 | SUPPLICANT_DBG("proto %s", proto); |
| 4591 | |
| 4592 | supplicant_dbus_dict_append_basic(dict, "proto", |
| 4593 | DBUS_TYPE_STRING, |
| 4594 | &proto); |
| 4595 | |
| 4596 | g_free(proto); |
| 4597 | } |
| 4598 | |
| 4599 | static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid) |
| 4600 | { |
| 4601 | char *key_mgmt; |
| 4602 | |
| 4603 | switch (ssid->security) { |
| 4604 | case G_SUPPLICANT_SECURITY_NONE: |
| 4605 | key_mgmt = "NONE"; |
| 4606 | add_network_security_none(dict); |
| 4607 | add_network_security_ciphers(dict, ssid); |
| 4608 | break; |
| 4609 | case G_SUPPLICANT_SECURITY_UNKNOWN: |
| 4610 | case G_SUPPLICANT_SECURITY_WEP: |
| 4611 | key_mgmt = "NONE"; |
| 4612 | add_network_security_wep(dict, ssid); |
| 4613 | add_network_security_ciphers(dict, ssid); |
| 4614 | break; |
| 4615 | case G_SUPPLICANT_SECURITY_PSK: |
| 4616 | key_mgmt = "WPA-PSK"; |
| 4617 | add_network_security_psk(dict, ssid); |
| 4618 | add_network_security_ciphers(dict, ssid); |
| 4619 | add_network_security_proto(dict, ssid); |
| 4620 | break; |
| 4621 | case G_SUPPLICANT_SECURITY_IEEE8021X: |
| 4622 | key_mgmt = "WPA-EAP"; |
| 4623 | add_network_security_eap(dict, ssid); |
| 4624 | add_network_security_ciphers(dict, ssid); |
| 4625 | add_network_security_proto(dict, ssid); |
| 4626 | break; |
| 4627 | } |
| 4628 | |
| 4629 | supplicant_dbus_dict_append_basic(dict, "key_mgmt", |
| 4630 | DBUS_TYPE_STRING, &key_mgmt); |
| 4631 | } |
| 4632 | |
| 4633 | static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid) |
| 4634 | { |
| 4635 | dbus_uint32_t mode; |
| 4636 | |
| 4637 | switch (ssid->mode) { |
| 4638 | case G_SUPPLICANT_MODE_UNKNOWN: |
| 4639 | case G_SUPPLICANT_MODE_INFRA: |
| 4640 | mode = 0; |
| 4641 | break; |
| 4642 | case G_SUPPLICANT_MODE_IBSS: |
| 4643 | mode = 1; |
| 4644 | break; |
| 4645 | case G_SUPPLICANT_MODE_MASTER: |
| 4646 | mode = 2; |
| 4647 | break; |
| 4648 | } |
| 4649 | |
| 4650 | supplicant_dbus_dict_append_basic(dict, "mode", |
| 4651 | DBUS_TYPE_UINT32, &mode); |
| 4652 | } |
| 4653 | |
| 4654 | static void interface_add_network_params(DBusMessageIter *iter, void *user_data) |
| 4655 | { |
| 4656 | DBusMessageIter dict; |
| 4657 | struct interface_connect_data *data = user_data; |
| 4658 | GSupplicantSSID *ssid = data->ssid; |
| 4659 | |
| 4660 | supplicant_dbus_dict_open(iter, &dict); |
| 4661 | |
| 4662 | if (ssid->scan_ssid) |
| 4663 | supplicant_dbus_dict_append_basic(&dict, "scan_ssid", |
| 4664 | DBUS_TYPE_UINT32, &ssid->scan_ssid); |
| 4665 | |
| 4666 | if (ssid->freq) |
| 4667 | supplicant_dbus_dict_append_basic(&dict, "frequency", |
| 4668 | DBUS_TYPE_UINT32, &ssid->freq); |
| 4669 | |
| 4670 | if (ssid->bgscan) |
| 4671 | supplicant_dbus_dict_append_basic(&dict, "bgscan", |
| 4672 | DBUS_TYPE_STRING, &ssid->bgscan); |
| 4673 | |
| 4674 | add_network_mode(&dict, ssid); |
| 4675 | |
| 4676 | add_network_security(&dict, ssid); |
| 4677 | |
| 4678 | supplicant_dbus_dict_append_fixed_array(&dict, "ssid", |
| 4679 | DBUS_TYPE_BYTE, &ssid->ssid, |
| 4680 | ssid->ssid_len); |
| 4681 | |
| 4682 | supplicant_dbus_dict_close(iter, &dict); |
| 4683 | } |
| 4684 | |
| 4685 | static void interface_wps_start_result(const char *error, |
| 4686 | DBusMessageIter *iter, void *user_data) |
| 4687 | { |
| 4688 | struct interface_connect_data *data = user_data; |
| 4689 | int err; |
| 4690 | |
| 4691 | SUPPLICANT_DBG(""); |
| 4692 | |
| 4693 | err = 0; |
| 4694 | if (error) { |
| 4695 | SUPPLICANT_DBG("error: %s", error); |
| 4696 | err = parse_supplicant_error(iter); |
| 4697 | } |
| 4698 | |
| 4699 | if(data->callback) |
| 4700 | data->callback(err, data->interface, data->user_data); |
| 4701 | |
| 4702 | g_free(data->path); |
| 4703 | g_free(data->ssid); |
| 4704 | dbus_free(data); |
| 4705 | } |
| 4706 | |
| 4707 | static void interface_add_wps_params(DBusMessageIter *iter, void *user_data) |
| 4708 | { |
| 4709 | struct interface_connect_data *data = user_data; |
| 4710 | GSupplicantSSID *ssid = data->ssid; |
| 4711 | const char *role = "enrollee", *type; |
| 4712 | DBusMessageIter dict; |
| 4713 | |
| 4714 | SUPPLICANT_DBG(""); |
| 4715 | |
| 4716 | supplicant_dbus_dict_open(iter, &dict); |
| 4717 | |
| 4718 | supplicant_dbus_dict_append_basic(&dict, "Role", |
| 4719 | DBUS_TYPE_STRING, &role); |
| 4720 | |
| 4721 | type = "pbc"; |
| 4722 | if (ssid->pin_wps) { |
| 4723 | type = "pin"; |
| 4724 | supplicant_dbus_dict_append_basic(&dict, "Pin", |
| 4725 | DBUS_TYPE_STRING, &ssid->pin_wps); |
| 4726 | } |
| 4727 | |
| 4728 | supplicant_dbus_dict_append_basic(&dict, "Type", |
| 4729 | DBUS_TYPE_STRING, &type); |
| 4730 | |
| 4731 | supplicant_dbus_dict_close(iter, &dict); |
| 4732 | } |
| 4733 | |
| 4734 | static void wps_start(const char *error, DBusMessageIter *iter, void *user_data) |
| 4735 | { |
| 4736 | struct interface_connect_data *data = user_data; |
| 4737 | |
| 4738 | SUPPLICANT_DBG(""); |
| 4739 | |
| 4740 | if (error) { |
| 4741 | SUPPLICANT_DBG("error: %s", error); |
| 4742 | g_free(data->path); |
| 4743 | g_free(data->ssid); |
| 4744 | dbus_free(data); |
| 4745 | return; |
| 4746 | } |
| 4747 | |
| 4748 | supplicant_dbus_method_call(data->interface->path, |
| 4749 | SUPPLICANT_INTERFACE ".Interface.WPS", "Start", |
| 4750 | interface_add_wps_params, |
| 4751 | interface_wps_start_result, data, NULL); |
| 4752 | } |
| 4753 | |
| 4754 | static void wps_process_credentials(DBusMessageIter *iter, void *user_data) |
| 4755 | { |
| 4756 | dbus_bool_t credentials = TRUE; |
| 4757 | |
| 4758 | SUPPLICANT_DBG(""); |
| 4759 | |
| 4760 | dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials); |
| 4761 | } |
| 4762 | |
| 4763 | int g_supplicant_interface_connect(GSupplicantInterface *interface, |
| 4764 | GSupplicantSSID *ssid, |
| 4765 | GSupplicantInterfaceCallback callback, |
| 4766 | void *user_data) |
| 4767 | { |
| 4768 | struct interface_connect_data *data; |
| 4769 | struct interface_data *intf_data; |
| 4770 | int ret = 0; |
| 4771 | |
| 4772 | if (!interface) |
| 4773 | return -EINVAL; |
| 4774 | |
| 4775 | if (!system_available) |
| 4776 | return -EFAULT; |
| 4777 | |
| 4778 | /* TODO: Check if we're already connected and switch */ |
| 4779 | |
| 4780 | data = dbus_malloc0(sizeof(*data)); |
| 4781 | if (!data) |
| 4782 | return -ENOMEM; |
| 4783 | |
| 4784 | data->interface = interface; |
| 4785 | data->path = g_strdup(interface->path); |
| 4786 | data->callback = callback; |
| 4787 | data->ssid = ssid; |
| 4788 | data->user_data = user_data; |
| 4789 | |
| 4790 | if (ssid->use_wps) { |
| 4791 | g_free(interface->wps_cred.key); |
| 4792 | memset(&interface->wps_cred, 0, |
| 4793 | sizeof(struct _GSupplicantWpsCredentials)); |
| 4794 | |
| 4795 | ret = supplicant_dbus_property_set(interface->path, |
| 4796 | SUPPLICANT_INTERFACE ".Interface.WPS", |
| 4797 | "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING, |
| 4798 | wps_process_credentials, wps_start, data, interface); |
| 4799 | } else { |
| 4800 | /* By the time there is a request for connect and the network |
| 4801 | * path is not NULL it means that connman has not removed the |
| 4802 | * previous network pointer. This can happen in the case AP |
| 4803 | * deauthenticated client and connman does not remove the |
| 4804 | * previously connected network pointer. This causes supplicant |
| 4805 | * to reallocate the memory for struct wpa_ssid again even if it |
| 4806 | * is the same SSID. This causes memory usage of wpa_supplicnat |
| 4807 | * to go high. The idea here is that if the previously connected |
| 4808 | * network is not removed at the time of next connection attempt |
| 4809 | * check if the network path is not NULL. In case it is non-NULL |
| 4810 | * first remove the network and then once removal is successful, add |
| 4811 | * the network. |
| 4812 | */ |
| 4813 | |
| 4814 | if (interface->network_path != NULL) { |
| 4815 | g_free(data->path); |
| 4816 | dbus_free(data); |
| 4817 | |
| 4818 | /* |
| 4819 | * If this add network is for the same network for which |
| 4820 | * wpa_supplicant already has a profile then do not need |
| 4821 | * to add another profile. Only if the profile that needs |
| 4822 | * to get added is different from what is there in wpa_s |
| 4823 | * delete the current one. A network is identified by its |
| 4824 | * SSID, security_type and passphrase (private passphrase) |
| 4825 | * in case security type is (802.11x). |
| 4826 | */ |
| 4827 | if (compare_network_parameters(interface, ssid)) { |
| 4828 | return -EALREADY; |
| 4829 | } |
| 4830 | |
| 4831 | intf_data = dbus_malloc0(sizeof(*intf_data)); |
| 4832 | if (!intf_data) |
| 4833 | return -ENOMEM; |
| 4834 | intf_data->interface = interface; |
| 4835 | intf_data->path = g_strdup(interface->path); |
| 4836 | intf_data->callback = callback; |
| 4837 | intf_data->ssid = ssid; |
| 4838 | intf_data->user_data = user_data; |
| 4839 | intf_data->network_remove_in_progress = TRUE; |
| 4840 | network_remove(intf_data); |
| 4841 | } else { |
| 4842 | ret = supplicant_dbus_method_call(interface->path, |
| 4843 | SUPPLICANT_INTERFACE ".Interface", "AddNetwork", |
| 4844 | interface_add_network_params, |
| 4845 | interface_add_network_result, data, |
| 4846 | interface); |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | if (ret < 0) { |
| 4851 | g_free(data->path); |
| 4852 | dbus_free(data); |
| 4853 | return ret; |
| 4854 | } |
| 4855 | |
| 4856 | return -EINPROGRESS; |
| 4857 | } |
| 4858 | |
| 4859 | static void network_remove_result(const char *error, |
| 4860 | DBusMessageIter *iter, void *user_data) |
| 4861 | { |
| 4862 | struct interface_data *data = user_data; |
| 4863 | struct interface_connect_data *connect_data; |
| 4864 | int result = 0; |
| 4865 | |
| 4866 | SUPPLICANT_DBG(""); |
| 4867 | |
| 4868 | if (error) { |
| 4869 | result = -EIO; |
| 4870 | if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod", |
| 4871 | error) == 0) |
| 4872 | result = -ECONNABORTED; |
| 4873 | } |
| 4874 | |
| 4875 | if (data->interface->network_path) { |
| 4876 | GHashTableIter iter2; |
| 4877 | gpointer value, key; |
| 4878 | |
| 4879 | g_hash_table_iter_init(&iter2, data->interface->config_mapping); |
| 4880 | |
| 4881 | while (g_hash_table_iter_next(&iter2, &key, &value)) { |
| 4882 | if (!g_strcmp0(value, data->interface->network_path)) { |
| 4883 | SUPPLICANT_DBG("Remove group %s config_path %s from config_mapping", key, value); |
| 4884 | g_hash_table_iter_remove(&iter2); |
| 4885 | } |
| 4886 | } |
| 4887 | } |
| 4888 | |
| 4889 | g_free(data->interface->network_path); |
| 4890 | data->interface->network_path = NULL; |
| 4891 | |
| 4892 | remove_network_information(data->interface); |
| 4893 | |
| 4894 | if (data->network_remove_in_progress == TRUE) { |
| 4895 | data->network_remove_in_progress = FALSE; |
| 4896 | connect_data = dbus_malloc0(sizeof(*connect_data)); |
| 4897 | if (!connect_data) |
| 4898 | return; |
| 4899 | |
| 4900 | connect_data->interface = data->interface; |
| 4901 | connect_data->path = g_strdup(data->path); |
| 4902 | connect_data->callback = data->callback; |
| 4903 | connect_data->ssid = data->ssid; |
| 4904 | connect_data->user_data = data->user_data; |
| 4905 | |
| 4906 | supplicant_dbus_method_call(data->interface->path, |
| 4907 | SUPPLICANT_INTERFACE ".Interface", "AddNetwork", |
| 4908 | interface_add_network_params, |
| 4909 | interface_add_network_result, connect_data, |
| 4910 | connect_data->interface); |
| 4911 | } else { |
| 4912 | if (data->callback) |
| 4913 | data->callback(result, data->interface, data->user_data); |
| 4914 | } |
| 4915 | g_free(data->path); |
| 4916 | dbus_free(data); |
| 4917 | } |
| 4918 | |
| 4919 | static void network_remove_params(DBusMessageIter *iter, void *user_data) |
| 4920 | { |
| 4921 | struct interface_data *data = user_data; |
| 4922 | const char *path = data->interface->network_path; |
| 4923 | |
| 4924 | SUPPLICANT_DBG("path %s", path); |
| 4925 | |
| 4926 | dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); |
| 4927 | } |
| 4928 | |
| 4929 | static int network_remove(struct interface_data *data) |
| 4930 | { |
| 4931 | GSupplicantInterface *interface = data->interface; |
| 4932 | |
| 4933 | SUPPLICANT_DBG(""); |
| 4934 | |
| 4935 | return supplicant_dbus_method_call(interface->path, |
| 4936 | SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork", |
| 4937 | network_remove_params, network_remove_result, data, |
| 4938 | interface); |
| 4939 | } |
| 4940 | |
| 4941 | static void interface_disconnect_result(const char *error, |
| 4942 | DBusMessageIter *iter, void *user_data) |
| 4943 | { |
| 4944 | struct interface_data *data = user_data; |
| 4945 | int result = 0; |
| 4946 | |
| 4947 | SUPPLICANT_DBG(""); |
| 4948 | |
| 4949 | if (error) { |
| 4950 | result = -EIO; |
| 4951 | if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod", |
| 4952 | error) == 0) |
| 4953 | result = -ECONNABORTED; |
| 4954 | } |
| 4955 | |
| 4956 | if (result < 0 && data->callback) { |
| 4957 | data->callback(result, data->interface, data->user_data); |
| 4958 | data->callback = NULL; |
| 4959 | } |
| 4960 | |
| 4961 | /* If we are disconnecting from previous WPS successful |
| 4962 | * association. i.e.: it did not went through AddNetwork, |
| 4963 | * and interface->network_path was never set. */ |
| 4964 | if (!data->interface->network_path) { |
| 4965 | g_free(data->path); |
| 4966 | dbus_free(data); |
| 4967 | return; |
| 4968 | } |
| 4969 | |
| 4970 | if (result != -ECONNABORTED) { |
| 4971 | if (network_remove(data) < 0) { |
| 4972 | g_free(data->path); |
| 4973 | dbus_free(data); |
| 4974 | } |
| 4975 | } else { |
| 4976 | g_free(data->path); |
| 4977 | dbus_free(data); |
| 4978 | } |
| 4979 | } |
| 4980 | |
| 4981 | int g_supplicant_interface_disconnect(GSupplicantInterface *interface, |
| 4982 | GSupplicantInterfaceCallback callback, |
| 4983 | void *user_data) |
| 4984 | { |
| 4985 | struct interface_data *data; |
| 4986 | int ret; |
| 4987 | |
| 4988 | SUPPLICANT_DBG(""); |
| 4989 | |
| 4990 | if (!interface) |
| 4991 | return -EINVAL; |
| 4992 | |
| 4993 | if (!system_available) |
| 4994 | return -EFAULT; |
| 4995 | |
| 4996 | data = dbus_malloc0(sizeof(*data)); |
| 4997 | if (!data) |
| 4998 | return -ENOMEM; |
| 4999 | |
| 5000 | data->interface = interface; |
| 5001 | data->path = g_strdup(interface->path); |
| 5002 | data->callback = callback; |
| 5003 | data->user_data = user_data; |
| 5004 | |
| 5005 | ret = supplicant_dbus_method_call(interface->path, |
| 5006 | SUPPLICANT_INTERFACE ".Interface", "Disconnect", |
| 5007 | NULL, interface_disconnect_result, data, |
| 5008 | interface); |
| 5009 | |
| 5010 | if (ret < 0) { |
| 5011 | g_free(data->path); |
| 5012 | dbus_free(data); |
| 5013 | } |
| 5014 | |
| 5015 | return ret; |
| 5016 | } |
| 5017 | |
| 5018 | static void disable_autoconnect_params(DBusMessageIter *iter, void *user_data) |
| 5019 | { |
| 5020 | char *path = user_data; |
| 5021 | |
| 5022 | SUPPLICANT_DBG("path %s", path); |
| 5023 | |
| 5024 | dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); |
| 5025 | } |
| 5026 | |
| 5027 | int g_supplicant_interface_disable_autoconnect(GSupplicantInterface *interface, char *network_group) |
| 5028 | { |
| 5029 | char *config_path; |
| 5030 | int ret; |
| 5031 | |
| 5032 | SUPPLICANT_DBG("lookup group %s at config_mapping", network_group); |
| 5033 | |
| 5034 | config_path = g_hash_table_lookup(interface->config_mapping, network_group); |
| 5035 | if (!config_path) { |
| 5036 | SUPPLICANT_DBG("can't find group %s at config_mapping", network_group); |
| 5037 | return -EALREADY; |
| 5038 | } |
| 5039 | |
| 5040 | ret = supplicant_dbus_method_call(interface->path, |
| 5041 | SUPPLICANT_INTERFACE ".Interface", "DisableNetwork", |
| 5042 | disable_autoconnect_params, NULL, config_path, |
| 5043 | interface); |
| 5044 | |
| 5045 | return ret; |
| 5046 | } |
| 5047 | |
| 5048 | static void interface_p2p_find_result(const char *error, |
| 5049 | DBusMessageIter *iter, void *user_data) |
| 5050 | { |
| 5051 | struct interface_scan_data *data = user_data; |
| 5052 | int err = 0; |
| 5053 | |
| 5054 | SUPPLICANT_DBG("error %s", error); |
| 5055 | |
| 5056 | if (error) |
| 5057 | err = -EIO; |
| 5058 | |
| 5059 | if (interface_exists(data->interface, data->path)) { |
| 5060 | if (!data->interface->ready) |
| 5061 | err = -ENOLINK; |
| 5062 | if (!err) |
| 5063 | data->interface->p2p_finding = true; |
| 5064 | } |
| 5065 | |
| 5066 | if (data->callback) |
| 5067 | data->callback(err, data->interface, data->user_data); |
| 5068 | |
| 5069 | g_free(data->path); |
| 5070 | dbus_free(data); |
| 5071 | } |
| 5072 | |
| 5073 | static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data) |
| 5074 | { |
| 5075 | DBusMessageIter dict; |
| 5076 | |
| 5077 | supplicant_dbus_dict_open(iter, &dict); |
| 5078 | supplicant_dbus_dict_close(iter, &dict); |
| 5079 | } |
| 5080 | |
| 5081 | int g_supplicant_interface_p2p_find(GSupplicantInterface *interface, |
| 5082 | GSupplicantInterfaceCallback callback, |
| 5083 | void *user_data) |
| 5084 | { |
| 5085 | struct interface_scan_data *data; |
| 5086 | int ret; |
| 5087 | |
| 5088 | if (!interface->p2p_support) |
| 5089 | return -ENOTSUP; |
| 5090 | |
| 5091 | ret = interface_ready_to_scan(interface); |
| 5092 | if (ret && ret != -EALREADY) |
| 5093 | return ret; |
| 5094 | |
| 5095 | data = dbus_malloc0(sizeof(*data)); |
| 5096 | if (!data) |
| 5097 | return -ENOMEM; |
| 5098 | |
| 5099 | data->interface = interface; |
| 5100 | data->path = g_strdup(interface->path); |
| 5101 | data->callback = callback; |
| 5102 | data->user_data = user_data; |
| 5103 | |
| 5104 | ret = supplicant_dbus_method_call(interface->path, |
| 5105 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find", |
| 5106 | interface_p2p_find_params, interface_p2p_find_result, |
| 5107 | data, interface); |
| 5108 | if (ret < 0) { |
| 5109 | g_free(data->path); |
| 5110 | dbus_free(data); |
| 5111 | } |
| 5112 | |
| 5113 | return ret; |
| 5114 | } |
| 5115 | |
| 5116 | bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface) |
| 5117 | { |
| 5118 | if (!interface) |
| 5119 | return false; |
| 5120 | |
| 5121 | return interface->p2p_finding; |
| 5122 | } |
| 5123 | |
| 5124 | int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface) |
| 5125 | { |
| 5126 | if (!interface->p2p_finding) |
| 5127 | return 0; |
| 5128 | |
| 5129 | SUPPLICANT_DBG(""); |
| 5130 | |
| 5131 | interface->p2p_finding = false; |
| 5132 | |
| 5133 | return supplicant_dbus_method_call(interface->path, |
| 5134 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind", |
| 5135 | NULL, NULL, NULL, NULL); |
| 5136 | } |
| 5137 | |
| 5138 | static void interface_p2p_connect_result(const char *error, |
| 5139 | DBusMessageIter *iter, void *user_data) |
| 5140 | { |
| 5141 | struct interface_connect_data *data = user_data; |
| 5142 | int err = 0; |
| 5143 | |
| 5144 | SUPPLICANT_DBG(""); |
| 5145 | |
| 5146 | if (error) |
| 5147 | err = parse_supplicant_error(iter); |
| 5148 | |
| 5149 | if (data->callback) |
| 5150 | data->callback(err, data->interface, data->user_data); |
| 5151 | |
| 5152 | g_free(data->path); |
| 5153 | g_free(data->peer->wps_pin); |
| 5154 | g_free(data->peer->path); |
| 5155 | g_free(data->peer); |
| 5156 | g_free(data); |
| 5157 | } |
| 5158 | |
| 5159 | static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data) |
| 5160 | { |
| 5161 | struct interface_connect_data *data = user_data; |
| 5162 | const char *wps = "pbc"; |
| 5163 | DBusMessageIter dict; |
| 5164 | int go_intent = 7; |
| 5165 | |
| 5166 | SUPPLICANT_DBG(""); |
| 5167 | |
| 5168 | supplicant_dbus_dict_open(iter, &dict); |
| 5169 | |
| 5170 | if (data->peer->master) |
| 5171 | go_intent = 15; |
| 5172 | |
| 5173 | if (data->peer->wps_pin) |
| 5174 | wps = "pin"; |
| 5175 | |
| 5176 | supplicant_dbus_dict_append_basic(&dict, "peer", |
| 5177 | DBUS_TYPE_OBJECT_PATH, &data->peer->path); |
| 5178 | supplicant_dbus_dict_append_basic(&dict, "wps_method", |
| 5179 | DBUS_TYPE_STRING, &wps); |
| 5180 | if (data->peer->wps_pin) { |
| 5181 | supplicant_dbus_dict_append_basic(&dict, "pin", |
| 5182 | DBUS_TYPE_STRING, &data->peer->wps_pin); |
| 5183 | } |
| 5184 | |
| 5185 | supplicant_dbus_dict_append_basic(&dict, "go_intent", |
| 5186 | DBUS_TYPE_INT32, &go_intent); |
| 5187 | |
| 5188 | supplicant_dbus_dict_close(iter, &dict); |
| 5189 | } |
| 5190 | |
| 5191 | int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface, |
| 5192 | GSupplicantPeerParams *peer_params, |
| 5193 | GSupplicantInterfaceCallback callback, |
| 5194 | void *user_data) |
| 5195 | { |
| 5196 | struct interface_connect_data *data; |
| 5197 | int ret; |
| 5198 | |
| 5199 | SUPPLICANT_DBG(""); |
| 5200 | |
| 5201 | if (!interface->p2p_support) |
| 5202 | return -ENOTSUP; |
| 5203 | |
| 5204 | data = dbus_malloc0(sizeof(*data)); |
| 5205 | data->interface = interface; |
| 5206 | data->path = g_strdup(interface->path); |
| 5207 | data->peer = peer_params; |
| 5208 | data->callback = callback; |
| 5209 | data->user_data = user_data; |
| 5210 | |
| 5211 | ret = supplicant_dbus_method_call(interface->path, |
| 5212 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect", |
| 5213 | interface_p2p_connect_params, interface_p2p_connect_result, |
| 5214 | data, interface); |
| 5215 | if (ret < 0) { |
| 5216 | g_free(data->path); |
| 5217 | dbus_free(data); |
| 5218 | return ret; |
| 5219 | } |
| 5220 | |
| 5221 | return -EINPROGRESS; |
| 5222 | } |
| 5223 | |
| 5224 | int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface, |
| 5225 | GSupplicantPeerParams *peer_params) |
| 5226 | { |
| 5227 | GSupplicantPeer *peer; |
| 5228 | int count = 0; |
| 5229 | GSList *list; |
| 5230 | |
| 5231 | SUPPLICANT_DBG(""); |
| 5232 | |
| 5233 | if (!interface->p2p_support) |
| 5234 | return -ENOTSUP; |
| 5235 | |
| 5236 | peer = g_hash_table_lookup(interface->peer_table, peer_params->path); |
| 5237 | if (!peer) |
| 5238 | return -ENODEV; |
| 5239 | |
| 5240 | for (list = peer->groups; list; list = list->next, count++) { |
| 5241 | const char *group_obj_path = list->data; |
| 5242 | GSupplicantInterface *g_interface; |
| 5243 | GSupplicantGroup *group; |
| 5244 | |
| 5245 | group = g_hash_table_lookup(group_mapping, group_obj_path); |
| 5246 | if (!group || !group->interface) |
| 5247 | continue; |
| 5248 | |
| 5249 | g_interface = group->interface; |
| 5250 | supplicant_dbus_method_call(g_interface->path, |
| 5251 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", |
| 5252 | "Disconnect", NULL, NULL, NULL, g_interface); |
| 5253 | } |
| 5254 | |
| 5255 | if (count == 0 && peer->current_group_iface) { |
| 5256 | supplicant_dbus_method_call(peer->current_group_iface->path, |
| 5257 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", |
| 5258 | "Disconnect", NULL, NULL, NULL, |
| 5259 | peer->current_group_iface->path); |
| 5260 | } |
| 5261 | |
| 5262 | peer->current_group_iface = NULL; |
| 5263 | |
| 5264 | return -EINPROGRESS; |
| 5265 | } |
| 5266 | |
| 5267 | struct p2p_service_data { |
| 5268 | bool registration; |
| 5269 | GSupplicantInterface *interface; |
| 5270 | GSupplicantP2PServiceParams *service; |
| 5271 | GSupplicantInterfaceCallback callback; |
| 5272 | void *user_data; |
| 5273 | }; |
| 5274 | |
| 5275 | static void interface_p2p_service_result(const char *error, |
| 5276 | DBusMessageIter *iter, void *user_data) |
| 5277 | { |
| 5278 | struct p2p_service_data *data = user_data; |
| 5279 | int result = 0; |
| 5280 | |
| 5281 | SUPPLICANT_DBG("%s result - %s", data->registration ? |
| 5282 | "Registration" : "Deletion", |
| 5283 | error ? error : "Success"); |
| 5284 | if (error) |
| 5285 | result = -EINVAL; |
| 5286 | |
| 5287 | if (data->callback) |
| 5288 | data->callback(result, data->interface, data->user_data); |
| 5289 | |
| 5290 | g_free(data->service->query); |
| 5291 | g_free(data->service->response); |
| 5292 | g_free(data->service->service); |
| 5293 | g_free(data->service->wfd_ies); |
| 5294 | g_free(data->service); |
| 5295 | dbus_free(data); |
| 5296 | } |
| 5297 | |
| 5298 | static void interface_p2p_service_params(DBusMessageIter *iter, |
| 5299 | void *user_data) |
| 5300 | { |
| 5301 | struct p2p_service_data *data = user_data; |
| 5302 | GSupplicantP2PServiceParams *service; |
| 5303 | DBusMessageIter dict; |
| 5304 | const char *type; |
| 5305 | |
| 5306 | SUPPLICANT_DBG(""); |
| 5307 | |
| 5308 | service = data->service; |
| 5309 | |
| 5310 | supplicant_dbus_dict_open(iter, &dict); |
| 5311 | |
| 5312 | if (service->query && service->response) { |
| 5313 | type = "bonjour"; |
| 5314 | supplicant_dbus_dict_append_basic(&dict, "service_type", |
| 5315 | DBUS_TYPE_STRING, &type); |
| 5316 | supplicant_dbus_dict_append_fixed_array(&dict, "query", |
| 5317 | DBUS_TYPE_BYTE, &service->query, |
| 5318 | service->query_length); |
| 5319 | supplicant_dbus_dict_append_fixed_array(&dict, "response", |
| 5320 | DBUS_TYPE_BYTE, &service->response, |
| 5321 | service->response_length); |
| 5322 | } else if (service->version && service->service) { |
| 5323 | type = "upnp"; |
| 5324 | supplicant_dbus_dict_append_basic(&dict, "service_type", |
| 5325 | DBUS_TYPE_STRING, &type); |
| 5326 | supplicant_dbus_dict_append_basic(&dict, "version", |
| 5327 | DBUS_TYPE_INT32, &service->version); |
| 5328 | supplicant_dbus_dict_append_basic(&dict, "service", |
| 5329 | DBUS_TYPE_STRING, &service->service); |
| 5330 | } |
| 5331 | |
| 5332 | supplicant_dbus_dict_close(iter, &dict); |
| 5333 | } |
| 5334 | |
| 5335 | int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface, |
| 5336 | GSupplicantInterfaceCallback callback, |
| 5337 | GSupplicantP2PServiceParams *p2p_service_params, |
| 5338 | void *user_data) |
| 5339 | { |
| 5340 | struct p2p_service_data *data; |
| 5341 | int ret; |
| 5342 | |
| 5343 | SUPPLICANT_DBG(""); |
| 5344 | |
| 5345 | if (!interface->p2p_support) |
| 5346 | return -ENOTSUP; |
| 5347 | |
| 5348 | data = dbus_malloc0(sizeof(*data)); |
| 5349 | data->registration = true; |
| 5350 | data->interface = interface; |
| 5351 | data->service = p2p_service_params; |
| 5352 | data->callback = callback; |
| 5353 | data->user_data = user_data; |
| 5354 | |
| 5355 | ret = supplicant_dbus_method_call(interface->path, |
| 5356 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService", |
| 5357 | interface_p2p_service_params, interface_p2p_service_result, |
| 5358 | data, interface); |
| 5359 | if (ret < 0) { |
| 5360 | dbus_free(data); |
| 5361 | return ret; |
| 5362 | } |
| 5363 | |
| 5364 | return -EINPROGRESS; |
| 5365 | } |
| 5366 | |
| 5367 | int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface, |
| 5368 | GSupplicantP2PServiceParams *p2p_service_params) |
| 5369 | { |
| 5370 | struct p2p_service_data *data; |
| 5371 | int ret; |
| 5372 | |
| 5373 | SUPPLICANT_DBG(""); |
| 5374 | |
| 5375 | if (!interface->p2p_support) |
| 5376 | return -ENOTSUP; |
| 5377 | |
| 5378 | data = dbus_malloc0(sizeof(*data)); |
| 5379 | data->interface = interface; |
| 5380 | data->service = p2p_service_params; |
| 5381 | |
| 5382 | ret = supplicant_dbus_method_call(interface->path, |
| 5383 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService", |
| 5384 | interface_p2p_service_params, interface_p2p_service_result, |
| 5385 | data, interface); |
| 5386 | if (ret < 0) { |
| 5387 | dbus_free(data); |
| 5388 | return ret; |
| 5389 | } |
| 5390 | |
| 5391 | return -EINPROGRESS; |
| 5392 | } |
| 5393 | |
| 5394 | struct p2p_listen_data { |
| 5395 | int period; |
| 5396 | int interval; |
| 5397 | }; |
| 5398 | |
| 5399 | static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data) |
| 5400 | { |
| 5401 | struct p2p_listen_data *params = user_data; |
| 5402 | DBusMessageIter dict; |
| 5403 | |
| 5404 | supplicant_dbus_dict_open(iter, &dict); |
| 5405 | |
| 5406 | supplicant_dbus_dict_append_basic(&dict, "period", |
| 5407 | DBUS_TYPE_INT32, ¶ms->period); |
| 5408 | supplicant_dbus_dict_append_basic(&dict, "interval", |
| 5409 | DBUS_TYPE_INT32, ¶ms->interval); |
| 5410 | supplicant_dbus_dict_close(iter, &dict); |
| 5411 | } |
| 5412 | |
| 5413 | int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface, |
| 5414 | int period, int interval) |
| 5415 | { |
| 5416 | struct p2p_listen_data params; |
| 5417 | |
| 5418 | SUPPLICANT_DBG(""); |
| 5419 | |
| 5420 | if (!interface->p2p_support) |
| 5421 | return -ENOTSUP; |
| 5422 | |
| 5423 | params.period = period; |
| 5424 | params.interval = interval; |
| 5425 | |
| 5426 | return supplicant_dbus_method_call(interface->path, |
| 5427 | SUPPLICANT_INTERFACE ".Interface.P2PDevice", |
| 5428 | "ExtendedListen", interface_p2p_listen_params, |
| 5429 | NULL, ¶ms, NULL); |
| 5430 | } |
| 5431 | |
| 5432 | static void widi_ies_params(DBusMessageIter *iter, void *user_data) |
| 5433 | { |
| 5434 | struct p2p_service_data *data = user_data; |
| 5435 | GSupplicantP2PServiceParams *service = data->service; |
| 5436 | DBusMessageIter array; |
| 5437 | |
| 5438 | SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length); |
| 5439 | |
| 5440 | dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, |
| 5441 | DBUS_TYPE_BYTE_AS_STRING, &array); |
| 5442 | |
| 5443 | if (service->wfd_ies && service->wfd_ies_length > 0) { |
| 5444 | dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE, |
| 5445 | &service->wfd_ies, service->wfd_ies_length); |
| 5446 | } |
| 5447 | |
| 5448 | dbus_message_iter_close_container(iter, &array); |
| 5449 | } |
| 5450 | |
| 5451 | int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params, |
| 5452 | GSupplicantInterfaceCallback callback, |
| 5453 | void *user_data) |
| 5454 | { |
| 5455 | struct p2p_service_data *data; |
| 5456 | int ret; |
| 5457 | |
| 5458 | SUPPLICANT_DBG(""); |
| 5459 | |
| 5460 | if (!system_available) |
| 5461 | return -EFAULT; |
| 5462 | |
| 5463 | data = dbus_malloc0(sizeof(*data)); |
| 5464 | data->service = p2p_service_params; |
| 5465 | data->callback = callback; |
| 5466 | data->user_data = user_data; |
| 5467 | |
| 5468 | if (p2p_service_params->wfd_ies) |
| 5469 | data->registration = true; |
| 5470 | |
| 5471 | ret = supplicant_dbus_property_set(SUPPLICANT_PATH, |
| 5472 | SUPPLICANT_INTERFACE, "WFDIEs", |
| 5473 | DBUS_TYPE_ARRAY_AS_STRING |
| 5474 | DBUS_TYPE_BYTE_AS_STRING, |
| 5475 | widi_ies_params, |
| 5476 | interface_p2p_service_result, |
| 5477 | data, NULL); |
| 5478 | if (ret < 0 && ret != -EINPROGRESS) { |
| 5479 | dbus_free(data); |
| 5480 | return ret; |
| 5481 | } |
| 5482 | |
| 5483 | return -EINPROGRESS; |
| 5484 | } |
| 5485 | |
| 5486 | |
| 5487 | static const char *g_supplicant_rule0 = "type=signal," |
| 5488 | "path=" DBUS_PATH_DBUS "," |
| 5489 | "sender=" DBUS_SERVICE_DBUS "," |
| 5490 | "interface=" DBUS_INTERFACE_DBUS "," |
| 5491 | "member=NameOwnerChanged," |
| 5492 | "arg0=" SUPPLICANT_SERVICE; |
| 5493 | static const char *g_supplicant_rule1 = "type=signal," |
| 5494 | "interface=" SUPPLICANT_INTERFACE; |
| 5495 | static const char *g_supplicant_rule2 = "type=signal," |
| 5496 | "interface=" SUPPLICANT_INTERFACE ".Interface"; |
| 5497 | static const char *g_supplicant_rule3 = "type=signal," |
| 5498 | "interface=" SUPPLICANT_INTERFACE ".Interface.WPS"; |
| 5499 | static const char *g_supplicant_rule4 = "type=signal," |
| 5500 | "interface=" SUPPLICANT_INTERFACE ".BSS"; |
| 5501 | static const char *g_supplicant_rule5 = "type=signal," |
| 5502 | "interface=" SUPPLICANT_INTERFACE ".Network"; |
| 5503 | static const char *g_supplicant_rule6 = "type=signal," |
| 5504 | "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice"; |
| 5505 | static const char *g_supplicant_rule7 = "type=signal," |
| 5506 | "interface=" SUPPLICANT_INTERFACE ".Peer"; |
| 5507 | static const char *g_supplicant_rule8 = "type=signal," |
| 5508 | "interface=" SUPPLICANT_INTERFACE ".Group"; |
| 5509 | |
| 5510 | static void invoke_introspect_method(void) |
| 5511 | { |
| 5512 | DBusMessage *message; |
| 5513 | |
| 5514 | message = dbus_message_new_method_call(SUPPLICANT_SERVICE, |
| 5515 | SUPPLICANT_PATH, |
| 5516 | DBUS_INTERFACE_INTROSPECTABLE, |
| 5517 | "Introspect"); |
| 5518 | |
| 5519 | if (!message) |
| 5520 | return; |
| 5521 | |
| 5522 | dbus_message_set_no_reply(message, TRUE); |
| 5523 | dbus_connection_send(connection, message, NULL); |
| 5524 | dbus_message_unref(message); |
| 5525 | } |
| 5526 | |
| 5527 | int g_supplicant_register(const GSupplicantCallbacks *callbacks) |
| 5528 | { |
| 5529 | connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); |
| 5530 | if (!connection) |
| 5531 | return -EIO; |
| 5532 | |
| 5533 | if (!dbus_connection_add_filter(connection, g_supplicant_filter, |
| 5534 | NULL, NULL)) { |
| 5535 | dbus_connection_unref(connection); |
| 5536 | connection = NULL; |
| 5537 | return -EIO; |
| 5538 | } |
| 5539 | |
| 5540 | callbacks_pointer = callbacks; |
| 5541 | eap_methods = 0; |
| 5542 | |
| 5543 | interface_table = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 5544 | NULL, remove_interface); |
| 5545 | |
| 5546 | bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 5547 | NULL, NULL); |
| 5548 | peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 5549 | NULL, NULL); |
| 5550 | group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 5551 | NULL, NULL); |
| 5552 | pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 5553 | NULL, NULL); |
| 5554 | |
| 5555 | supplicant_dbus_setup(connection); |
| 5556 | |
| 5557 | dbus_bus_add_match(connection, g_supplicant_rule0, NULL); |
| 5558 | dbus_bus_add_match(connection, g_supplicant_rule1, NULL); |
| 5559 | dbus_bus_add_match(connection, g_supplicant_rule2, NULL); |
| 5560 | dbus_bus_add_match(connection, g_supplicant_rule3, NULL); |
| 5561 | dbus_bus_add_match(connection, g_supplicant_rule4, NULL); |
| 5562 | dbus_bus_add_match(connection, g_supplicant_rule5, NULL); |
| 5563 | dbus_bus_add_match(connection, g_supplicant_rule6, NULL); |
| 5564 | dbus_bus_add_match(connection, g_supplicant_rule7, NULL); |
| 5565 | dbus_bus_add_match(connection, g_supplicant_rule8, NULL); |
| 5566 | dbus_connection_flush(connection); |
| 5567 | |
| 5568 | if (dbus_bus_name_has_owner(connection, |
| 5569 | SUPPLICANT_SERVICE, NULL)) { |
| 5570 | system_available = TRUE; |
| 5571 | supplicant_dbus_property_get_all(SUPPLICANT_PATH, |
| 5572 | SUPPLICANT_INTERFACE, |
| 5573 | service_property, NULL, NULL); |
| 5574 | } else |
| 5575 | invoke_introspect_method(); |
| 5576 | |
| 5577 | return 0; |
| 5578 | } |
| 5579 | |
| 5580 | static void unregister_interface_remove_params(DBusMessageIter *iter, |
| 5581 | void *user_data) |
| 5582 | { |
| 5583 | const char *path = user_data; |
| 5584 | |
| 5585 | dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, |
| 5586 | &path); |
| 5587 | } |
| 5588 | |
| 5589 | |
| 5590 | static void unregister_remove_interface(gpointer key, gpointer value, |
| 5591 | gpointer user_data) |
| 5592 | { |
| 5593 | GSupplicantInterface *interface = value; |
| 5594 | |
| 5595 | supplicant_dbus_method_call(SUPPLICANT_PATH, |
| 5596 | SUPPLICANT_INTERFACE, |
| 5597 | "RemoveInterface", |
| 5598 | unregister_interface_remove_params, |
| 5599 | NULL, interface->path, NULL); |
| 5600 | } |
| 5601 | |
| 5602 | void g_supplicant_unregister(const GSupplicantCallbacks *callbacks) |
| 5603 | { |
| 5604 | SUPPLICANT_DBG(""); |
| 5605 | |
| 5606 | if (connection) { |
| 5607 | dbus_bus_remove_match(connection, g_supplicant_rule8, NULL); |
| 5608 | dbus_bus_remove_match(connection, g_supplicant_rule7, NULL); |
| 5609 | dbus_bus_remove_match(connection, g_supplicant_rule6, NULL); |
| 5610 | dbus_bus_remove_match(connection, g_supplicant_rule5, NULL); |
| 5611 | dbus_bus_remove_match(connection, g_supplicant_rule4, NULL); |
| 5612 | dbus_bus_remove_match(connection, g_supplicant_rule3, NULL); |
| 5613 | dbus_bus_remove_match(connection, g_supplicant_rule2, NULL); |
| 5614 | dbus_bus_remove_match(connection, g_supplicant_rule1, NULL); |
| 5615 | dbus_bus_remove_match(connection, g_supplicant_rule0, NULL); |
| 5616 | dbus_connection_flush(connection); |
| 5617 | |
| 5618 | dbus_connection_remove_filter(connection, |
| 5619 | g_supplicant_filter, NULL); |
| 5620 | } |
| 5621 | |
| 5622 | if (bss_mapping) { |
| 5623 | g_hash_table_destroy(bss_mapping); |
| 5624 | bss_mapping = NULL; |
| 5625 | } |
| 5626 | |
| 5627 | if (peer_mapping) { |
| 5628 | g_hash_table_destroy(peer_mapping); |
| 5629 | peer_mapping = NULL; |
| 5630 | } |
| 5631 | |
| 5632 | if (group_mapping) { |
| 5633 | g_hash_table_destroy(group_mapping); |
| 5634 | group_mapping = NULL; |
| 5635 | } |
| 5636 | |
| 5637 | if (interface_table) { |
| 5638 | g_hash_table_foreach(interface_table, |
| 5639 | unregister_remove_interface, NULL); |
| 5640 | g_hash_table_destroy(interface_table); |
| 5641 | interface_table = NULL; |
| 5642 | } |
| 5643 | |
| 5644 | if (system_available) |
| 5645 | callback_system_killed(); |
| 5646 | |
| 5647 | if (connection) { |
| 5648 | dbus_connection_unref(connection); |
| 5649 | connection = NULL; |
| 5650 | } |
| 5651 | |
| 5652 | callbacks_pointer = NULL; |
| 5653 | eap_methods = 0; |
| 5654 | } |