From patchwork Sun Mar 17 20:57:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dvdspndl@gmail.com X-Patchwork-Id: 228329 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 DA5542C00B4 for ; Mon, 18 Mar 2013 07:59:54 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id A34F19C1C2; Sun, 17 Mar 2013 16:59:52 -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 yNYxEBXt5z2n; Sun, 17 Mar 2013 16:59:52 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 24F2F9C18D; Sun, 17 Mar 2013 16:58:31 -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 843849C216 for ; Sun, 17 Mar 2013 16:58:29 -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 XGwhzd5MeREp for ; Sun, 17 Mar 2013 16:58:25 -0400 (EDT) Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com [74.125.83.52]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 037F49C1C2 for ; Sun, 17 Mar 2013 16:57:49 -0400 (EDT) Received: by mail-ee0-f52.google.com with SMTP id b15so2282802eek.39 for ; Sun, 17 Mar 2013 13:57:48 -0700 (PDT) X-Received: by 10.15.34.198 with SMTP id e46mr41646239eev.27.1363553868814; Sun, 17 Mar 2013 13:57:48 -0700 (PDT) Received: from localhost (46-116-160-72.bb.netvision.net.il. [46.116.160.72]) by mx.google.com with ESMTPS id 3sm23400784eej.6.2013.03.17.13.57.47 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 17 Mar 2013 13:57:48 -0700 (PDT) From: David Spinadel To: hostap@lists.shmoo.com Subject: [PATCH v2 10/10] wpa_supplicant: init a dedicated P2P device interface Date: Sun, 17 Mar 2013 22:57:20 +0200 Message-Id: <1363553840-7844-11-git-send-email-dvdspndl@gmail.com> X-Mailer: git-send-email 1.7.10.msysgit.1 In-Reply-To: <1363553840-7844-1-git-send-email-dvdspndl@gmail.com> References: <1363553840-7844-1-git-send-email-dvdspndl@gmail.com> 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: David Spinadel Try to init a dedicated P2P device if supported in wpas_init_p2p and deinit it in wpas_deinit_p2p. Signed-off-by: David Spinadel --- src/p2p/p2p.c | 5 ++++ src/p2p/p2p.h | 6 ++++ wpa_supplicant/p2p_supplicant.c | 60 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 4418bb3..77c8f7d 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -4428,3 +4428,8 @@ int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int, return 0; } + +void p2p_set_dev_addr(struct p2p_data *p2p, u8 *addr) +{ + os_memcpy(p2p->cfg->dev_addr, addr, ETH_ALEN); +} diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index d2fa68c..b5d55eb 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1799,5 +1799,11 @@ struct wpabuf * wifi_display_encaps(struct wpabuf *subelems); */ int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int, int max_disc_tu); +/** + * p2p_set_dev_addr - Set P2P device address + * @p2p: P2P nodule context from p2p_init() + * @addr: P2P device address to assign to p2p device. + */ +void p2p_set_dev_addr(struct p2p_data *p2p, u8 *addr); #endif /* P2P_H */ diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 518e8e4..a6f7614 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -2917,6 +2917,57 @@ static int wpas_go_connected(void *ctx, const u8 *dev_addr) return 0; } +/** + * wpas_p2p_dev_interface_init - Initialize P2P device interface to be used + * for all device related operations + * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() + * @p2p: P2P module context from p2p_init() + * Returns: 0 on success, -1 on failure + */ +static int wpas_p2p_dev_interface_init(struct wpa_supplicant *wpa_s, + struct p2p_data *p2p) +{ + char *ifname; + char p2p_dev_ifname[IFNAMSIZ]; + int ifname_len; + u8 addr[ETH_ALEN]; + + if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) + return 0; + + if (!p2p) + return -1; + + wpa_printf(MSG_DEBUG, "P2P: Initialize P2P device Interface"); + + ifname = wpa_s->ifname; + /** + * If the name p2p-dev-$(wpa_s->ifname) is greater than IFNAMESIZ + * Assume the last 4 char of the wpa_s->ifname as unique + */ + ifname_len = os_strlen(ifname); + if (ifname_len > (IFNAMSIZ - 9)) + ifname += (ifname_len - 5); + + os_snprintf(p2p_dev_ifname, IFNAMSIZ, "p2p-dev-%s", ifname); + wpa_printf(MSG_DEBUG, "Creating a P2P device interface %s for %s", + p2p_dev_ifname, wpa_s->ifname); + + wpa_s->p2p_drv_priv = wpa_drv_init_p2p_dev(wpa_s, p2p_dev_ifname, addr); + if (!wpa_s->p2p_drv_priv) { + wpa_printf(MSG_ERROR, "P2P: Failed to create a new P2P " + "device interface"); + return -1; + } + + /* override p2p device address. */ + os_memcpy(wpa_s->global->p2p_dev_addr, addr, ETH_ALEN); + p2p_set_dev_addr(p2p, addr); + + wpa_printf(MSG_INFO, "P2P: Device initialization success"); + + return 0; +} /** * wpas_p2p_init - Initialize P2P module for %wpa_supplicant @@ -3075,6 +3126,12 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s) global->p2p, wpa_s->conf->wps_vendor_ext[i]); } + /* Try to initialize P2P device interface */ + if (wpas_p2p_dev_interface_init(wpa_s, global->p2p)) { + p2p_deinit(global->p2p); + return -1; + } + return 0; } @@ -3108,6 +3165,9 @@ void wpas_p2p_deinit(struct wpa_supplicant *wpa_s) /* TODO: remove group interface from the driver if this wpa_s instance * is on top of a P2P group interface */ + + if (wpa_s->p2p_drv_priv) + wpa_drv_deinit_p2p_dev(wpa_s); }