From patchwork Sat Feb 4 00:46:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chinchilla, Angie V" X-Patchwork-Id: 139501 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E5174104792 for ; Sat, 4 Feb 2012 11:48:15 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C069617C001; Fri, 3 Feb 2012 19:48:11 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A1tNxKSg5FbE; Fri, 3 Feb 2012 19:48:11 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 8BF7117C037; Fri, 3 Feb 2012 19:48:07 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id B5ABF17C037 for ; Fri, 3 Feb 2012 19:48:06 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uJdTNA-Qai-a for ; Fri, 3 Feb 2012 19:48:02 -0500 (EST) Received: from mga03.intel.com (mga03.intel.com [143.182.124.21]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 8E5AB17C001 for ; Fri, 3 Feb 2012 19:48:02 -0500 (EST) Received: from azsmga002.ch.intel.com ([10.2.17.35]) by azsmga101.ch.intel.com with ESMTP; 03 Feb 2012 16:48:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; d="scan'208";a="63110902" Received: from tester-laptop-1.jf.intel.com (HELO localhost.localdomain) ([134.134.163.146]) by AZSMGA002.ch.intel.com with ESMTP; 03 Feb 2012 16:48:00 -0800 From: Angie Chinchilla To: hostap@lists.shmoo.com Subject: [PATCH] p2p: Fix DBus crash and return additional information for P2P group properties Date: Fri, 3 Feb 2012 16:46:01 -0800 Message-Id: <1328316362-5956-1-git-send-email-angie.v.chinchilla@intel.com> X-Mailer: git-send-email 1.7.0.4 Cc: Todd Previte X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Todd Previte When using DBus to get group properties, a segmentation fault is generated on P2P clients due to a NULL pointer for the ap_iface struct. The current implementation only returns vendor extensions when called on a P2P group owner. The code now checks the P2P role which allows for role-specific information to be provided. This also fixes the crash issue by only looking for the correct structures based on the current P2P role. Signed-hostap: Todd Previte Signed-hostap: Angie Chinchilla --- wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 80 ++++++++++++++++++++++----- 1 files changed, 66 insertions(+), 14 deletions(-) diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c index 0f6914c..d621fb2 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c +++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c @@ -1664,14 +1664,38 @@ dbus_bool_t wpas_dbus_getter_p2p_group_properties(DBusMessageIter *iter, { struct wpa_supplicant *wpa_s = user_data; DBusMessageIter variant_iter, dict_iter; - struct hostapd_data *hapd = wpa_s->ap_iface->bss[0]; + struct hostapd_data *hapd = NULL; const struct wpabuf *vendor_ext[MAX_WPS_VENDOR_EXTENSIONS]; int num_vendor_ext = 0; int i; + u8 role = wpas_get_p2p_role(wpa_s); + u16 op_freq = 0; + u8 *p_bssid = NULL; + char *role_name = NULL; - if (!hapd) { - dbus_set_error_const(error, DBUS_ERROR_FAILED, - "internal error"); + /* Check current role and adjust information accordingly */ + switch (role) { + case WPAS_P2P_ROLE_CLIENT: + /* go_params is only valid for a client */ + if (wpa_s->go_params) { + op_freq = wpa_s->go_params->freq; + p_bssid = wpa_s->current_ssid->bssid; + role_name = "client"; + } else + return FALSE; + break; + case WPAS_P2P_ROLE_GO: + /* ap_iface is only valid for a GO */ + if (wpa_s->ap_iface) { + hapd = wpa_s->ap_iface->bss[0]; + p_bssid = hapd->own_addr; + op_freq = wpa_s->ap_iface->freq; + role_name = "GO"; + } else + return FALSE; + break; + default: + /* Error condition; this should NEVER occur */ return FALSE; } @@ -1679,19 +1703,47 @@ dbus_bool_t wpas_dbus_getter_p2p_group_properties(DBusMessageIter *iter, "a{sv}", &variant_iter) || !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) goto err_no_mem; + /* Provide the SSID */ + if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID", + (const char *)wpa_s->current_ssid->ssid, + wpa_s->current_ssid->ssid_len)) + goto err_no_mem; + /* Provide the BSSID */ + if (!wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID", + (const char *)p_bssid, ETH_ALEN)) + goto err_no_mem; + /* Provide the role within the group */ + if (!wpa_dbus_dict_append_string(&dict_iter, "Role", role_name)) + goto err_no_mem; + /* Provide the operational frequency */ + if (!wpa_dbus_dict_append_uint16(&dict_iter, "Frequency", op_freq)) + goto err_no_mem; - /* Parse WPS Vendor Extensions sent in Beacon/Probe Response */ - for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++) { - if (hapd->conf->wps_vendor_ext[i] == NULL) - continue; - vendor_ext[num_vendor_ext++] = hapd->conf->wps_vendor_ext[i]; + /* Additional information for group owners */ + if (role == WPAS_P2P_ROLE_GO) { + /* Provide the passphrase */ + if (!wpa_dbus_dict_append_string(&dict_iter, "Passphrase", + wpa_s->current_ssid->passphrase)) + goto err_no_mem; + /* Parse WPS Vendor Extensions sent in Beacon/Probe Response */ + for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++) { + if (hapd->conf->wps_vendor_ext[i] == NULL) + continue; + vendor_ext[num_vendor_ext++] = + hapd->conf->wps_vendor_ext[i]; + } + if (!wpa_dbus_dict_append_wpabuf_array(&dict_iter, + "WPSVendorExtensions", + vendor_ext, num_vendor_ext)) + goto err_no_mem; + } else { + /* If not a GO, provide the PSK */ + if (!wpa_dbus_dict_append_byte_array(&dict_iter, "PSK", + (const char *)wpa_s->current_ssid->psk, + 32)) + goto err_no_mem; } - if (!wpa_dbus_dict_append_wpabuf_array(&dict_iter, - "WPSVendorExtensions", - vendor_ext, num_vendor_ext)) - goto err_no_mem; - if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) || !dbus_message_iter_close_container(iter, &variant_iter)) goto err_no_mem;