From patchwork Thu May 16 20:27:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arend van Spriel X-Patchwork-Id: 244412 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]) by ozlabs.org (Postfix) with ESMTP id 451142C008E for ; Fri, 17 May 2013 06:28:21 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 9766D9D235; Thu, 16 May 2013 16:28:18 -0400 (EDT) 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 nxRH7Qrs14sS; Thu, 16 May 2013 16:28:18 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C59269D226; Thu, 16 May 2013 16:28:13 -0400 (EDT) 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 787CC9D226 for ; Thu, 16 May 2013 16:28:12 -0400 (EDT) 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 SJycPkT5xX+7 for ; Thu, 16 May 2013 16:28:07 -0400 (EDT) Received: from mms3.broadcom.com (mms3.broadcom.com [216.31.210.19]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 3879A9D222 for ; Thu, 16 May 2013 16:28:07 -0400 (EDT) Received: from [10.9.208.57] by mms3.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.5)); Thu, 16 May 2013 13:19:18 -0700 X-Server-Uuid: B86B6450-0931-4310-942E-F00ED04CA7AF Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.1.438.0; Thu, 16 May 2013 13:27:52 -0700 Received: from mail-sj1-12.sj.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.1.438.0; Thu, 16 May 2013 13:27:52 -0700 Received: from arend-ubuntu-1 (unknown [10.177.252.31]) by mail-sj1-12.sj.broadcom.com (Postfix) with ESMTP id 385AA207D5; Thu, 16 May 2013 13:27:50 -0700 (PDT) Received: from arend by arend-ubuntu-1 with local (Exim 4.80) ( envelope-from ) id 1Ud4mE-0003nd-32; Thu, 16 May 2013 22:27:50 +0200 From: "Arend van Spriel" To: "Jouni Malinen" Subject: [PATCH] wpa_s: p2p: rework creation order of P2P Device interface Date: Thu, 16 May 2013 22:27:48 +0200 Message-ID: <1368736068-14573-1-git-send-email-arend@broadcom.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-WSS-ID: 7D8BE0CC2L816793263-01-01 Cc: hostap@lists.shmoo.com X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com Create the P2P Device in main interface creation loop when the added interface flags support and P2P supplicant is not yet initialized avoiding recursion of add_interface. Signed-hostap: Arend van Spriel --- Hi Jouni, One more patch to clean up P2P device creation and restore function interfaces of driver_init and update_mac_addr. Regards, Arend --- wpa_supplicant/events.c | 4 ++-- wpa_supplicant/main.c | 15 +++++++++++++-- wpa_supplicant/p2p_supplicant.h | 1 + wpa_supplicant/wpa_supplicant.c | 30 ++++++++++++++++-------------- wpa_supplicant/wpa_supplicant_i.h | 6 ++++-- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 6728fd3..463c8e6 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -2168,7 +2168,7 @@ wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, break; wpa_s->interface_removed = 0; wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); - if (wpa_supplicant_driver_init(wpa_s, 1) < 0) { + if (wpa_supplicant_driver_init(wpa_s) < 0) { wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " "driver after interface was added"); } @@ -2909,7 +2909,7 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event, case EVENT_INTERFACE_ENABLED: wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { - wpa_supplicant_update_mac_addr(wpa_s, 1); + wpa_supplicant_update_mac_addr(wpa_s); #ifdef CONFIG_AP if (!wpa_s->ap_iface) { wpa_supplicant_set_state(wpa_s, diff --git a/wpa_supplicant/main.c b/wpa_supplicant/main.c index f45c1b7..8eb93e5 100644 --- a/wpa_supplicant/main.c +++ b/wpa_supplicant/main.c @@ -14,6 +14,7 @@ #include "common.h" #include "wpa_supplicant_i.h" #include "driver_i.h" +#include "p2p_supplicant.h" extern struct wpa_driver_ops *wpa_drivers[]; @@ -262,7 +263,7 @@ int main(int argc, char *argv[]) if (iface == NULL) goto out; ifaces = iface; - iface = &ifaces[iface_count - 1]; + iface = &ifaces[iface_count - 1]; os_memset(iface, 0, sizeof(*iface)); break; default: @@ -284,6 +285,8 @@ int main(int argc, char *argv[]) } for (i = 0; exitcode == 0 && i < iface_count; i++) { + struct wpa_supplicant *wpa_s; + if ((ifaces[i].confname == NULL && ifaces[i].ctrl_interface == NULL) || ifaces[i].ifname == NULL) { @@ -294,8 +297,16 @@ int main(int argc, char *argv[]) exitcode = -1; break; } - if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL) + wpa_s = wpa_supplicant_add_iface(global, &ifaces[i]); + if (wpa_s == NULL) { exitcode = -1; + break; + } + if (wpa_s->global->p2p == NULL && + (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) { + if (wpas_p2p_add_p2pdev_interface(wpa_s) < 0) + exitcode = -1; + } } if (exitcode == 0) diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h index 2157cae..a7fadc0 100644 --- a/wpa_supplicant/p2p_supplicant.h +++ b/wpa_supplicant/p2p_supplicant.h @@ -14,6 +14,7 @@ struct p2p_go_neg_results; enum p2p_send_action_result; struct p2p_peer_info; struct p2p_channels; +struct wps_event_fail; int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s); void wpas_p2p_deinit(struct wpa_supplicant *wpa_s); diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 170d613..6a0b236 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -2316,14 +2316,14 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr, } -int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s, int l2_needed) +int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s) { if (wpa_s->driver->send_eapol) { const u8 *addr = wpa_drv_get_mac_addr(wpa_s); if (addr) os_memcpy(wpa_s->own_addr, addr, ETH_ALEN); - } else if (l2_needed && !(wpa_s->drv_flags & - WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) { + } else if (!wpa_s->p2p_mgmt && + !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) { l2_packet_deinit(wpa_s->l2); wpa_s->l2 = l2_packet_init(wpa_s->ifname, wpa_drv_get_mac_addr(wpa_s), @@ -2374,18 +2374,17 @@ static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr, /** * wpa_supplicant_driver_init - Initialize driver interface parameters * @wpa_s: Pointer to wpa_supplicant data - * @l2_needed: need call l2_packet_init() for this interface * Returns: 0 on success, -1 on failure * * This function is called to initialize driver interface parameters. * wpa_drv_init() must have been called before this function to initialize the * driver interface. */ -int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s, int l2_needed) +int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s) { static int interface_count = 0; - if (wpa_supplicant_update_mac_addr(wpa_s, l2_needed) < 0) + if (wpa_supplicant_update_mac_addr(wpa_s) < 0) return -1; wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR, @@ -2955,7 +2954,16 @@ next_driver: if (wpa_s->max_remain_on_chan == 0) wpa_s->max_remain_on_chan = 1000; - if (wpa_supplicant_driver_init(wpa_s, !iface->p2p_mgmt) < 0) + /* only take p2p_mgmt parameters when P2P Device is supported. + * doing it here as it determines whether l2_packet_init() + * will be done during wpa_supplicant_driver_init(). + */ + if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) + wpa_s->p2p_mgmt = iface->p2p_mgmt; + else + iface->p2p_mgmt = 1; + + if (wpa_supplicant_driver_init(wpa_s) < 0) return -1; #ifdef CONFIG_TDLS @@ -2997,13 +3005,7 @@ next_driver: } #ifdef CONFIG_P2P - if (iface->p2p_mgmt == 0 && wpa_s->global->p2p == NULL && - (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) { - if (wpas_p2p_add_p2pdev_interface(wpa_s) < 0) { - wpa_msg(wpa_s, MSG_ERROR, "Failed to create P2P Device"); - return -1; - } - } else if (wpas_p2p_init(wpa_s->global, wpa_s) < 0) { + if (iface->p2p_mgmt && wpas_p2p_init(wpa_s->global, wpa_s) < 0) { wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P"); return -1; } diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index eac9b8f..de5fcd9 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -568,6 +568,8 @@ struct wpa_supplicant { unsigned int roc_waiting_drv_freq; int action_tx_wait_time; + int p2p_mgmt; + #ifdef CONFIG_P2P struct p2p_go_neg_results *go_params; int create_p2p_iface; @@ -715,8 +717,8 @@ int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s, int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s); const char * wpa_supplicant_state_txt(enum wpa_states state); -int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s, int l2_needed); -int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s, int l2_needed); +int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s); +int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s); int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, struct wpa_ssid *ssid, u8 *wpa_ie, size_t *wpa_ie_len);