From patchwork Mon Feb 11 11:15:44 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: 219581 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 0B4AC2C02AE for ; Mon, 11 Feb 2013 22:18:52 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 8B23C17C00D; Mon, 11 Feb 2013 06:18:48 -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 f7gO+ULPodqG; Mon, 11 Feb 2013 06:18:48 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 7EB039C246; Mon, 11 Feb 2013 06:17:43 -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 0407B9C246 for ; Mon, 11 Feb 2013 06:17:41 -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 wnQqFLNiAxFo for ; Mon, 11 Feb 2013 06:17:36 -0500 (EST) Received: from mms1.broadcom.com (mms1.broadcom.com [216.31.210.17]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id AE54B9C220 for ; Mon, 11 Feb 2013 06:16:58 -0500 (EST) Received: from [10.9.208.55] by mms1.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.5)); Mon, 11 Feb 2013 03:14:40 -0800 X-Server-Uuid: 06151B78-6688-425E-9DE2-57CB27892261 Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS07.corp.ad.broadcom.com (10.9.208.55) with Microsoft SMTP Server (TLS) id 14.1.438.0; Mon, 11 Feb 2013 03:15:53 -0800 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; Mon, 11 Feb 2013 03:15:53 -0800 Received: from linux-e6410-1 (unknown [10.176.68.31]) by mail-sj1-12.sj.broadcom.com (Postfix) with ESMTP id 69C9D207D5; Mon, 11 Feb 2013 03:15:52 -0800 (PST) Received: from arend by linux-e6410-1 with local (Exim 4.80) ( envelope-from ) id 1U4rMV-0006yy-Bg; Mon, 11 Feb 2013 12:15:51 +0100 From: "Arend van Spriel" To: hostap@lists.shmoo.com Subject: [RFC 07/10] nl80211_driver: implement init and deinit P2P device functions Date: Mon, 11 Feb 2013 12:15:44 +0100 Message-ID: <1360581347-26766-8-git-send-email-arend@broadcom.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360581347-26766-1-git-send-email-arend@broadcom.com> References: <1360581347-26766-1-git-send-email-arend@broadcom.com> MIME-Version: 1.0 X-WSS-ID: 7D060D2A1YS3450249-05-01 Cc: Jouni Malinen , Johannes Berg 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: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: David Spinadel Signed-hostap: David Spinadel --- src/drivers/driver_nl80211.c | 137 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 183761a..562b084 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -9372,6 +9372,139 @@ static int android_pno_stop(struct i802_bss *bss) #endif /* ANDROID */ +#ifdef CONFIG_P2P +static int nl80211_create_p2p_dev_handler(struct nl_msg *msg, void *arg) +{ + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *tb[NL80211_ATTR_MAX + 1]; + struct i802_bss *p2p_dev = arg; + + nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), + genlmsg_attrlen(gnlh, 0), NULL); + if (tb[NL80211_ATTR_WDEV]) + p2p_dev->wdev_id = + nla_get_u64(tb[NL80211_ATTR_WDEV]); + + if (tb[NL80211_ATTR_MAC]) + os_memcpy(p2p_dev->addr, + nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); + + return NL_SKIP; +} + +static int nl80211_p2p_device_exec_cmd(struct wpa_driver_nl80211_data *drv, + const char *ifname, + enum nl80211_commands cmd, + int64_t wdev_id) +{ + struct nl_msg *msg; + int ret = -1; + + if (wdev_id < 0) { + wpa_printf(MSG_DEBUG, "nl80211: Cannot execute p2p device" + "cmd %d without wdev_id", cmd); + return -1; + } + wpa_printf(MSG_DEBUG, "Executing p2p device cmd %d", cmd); + msg = nlmsg_alloc(); + if (!msg) + return -1; + + nl80211_cmd(drv, msg, 0, cmd); + NLA_PUT_U64(msg, NL80211_ATTR_WDEV, wdev_id); + + ret = send_and_recv_msgs(drv, msg, NULL, NULL); + msg = NULL; + if (ret) { +nla_put_failure: + nlmsg_free(msg); + wpa_printf(MSG_ERROR, "nl80211: Failed to execute CMD %d on " + "%s: error =%d:%s", cmd, ifname, ret, + strerror(-ret)); + } + return ret; +} + +static void nl80211_deinit_p2p_dev(void *priv) +{ + struct i802_bss *p2p_dev = priv; + struct wpa_driver_nl80211_data *drv = p2p_dev->drv; + struct i802_bss *last; + + if (p2p_dev->wdev_id == -1) + return; + + /* + * Not stopping the P2P device here as the kernel does that when + * deinit is called. Need to execute STOP here if that changes. + */ + nl80211_p2p_device_exec_cmd(drv, p2p_dev->ifname, + NL80211_CMD_DEL_INTERFACE, + p2p_dev->wdev_id); + + for (last = &drv->first_bss; last->next != p2p_dev; last = last->next) + ; + last->next = p2p_dev->next; + + os_free(p2p_dev); +} + +static void *nl80211_init_p2p_dev(void *priv, const char *ifname, u8 *addr) +{ + struct i802_bss *bss = priv; + struct i802_bss *last; + struct wpa_driver_nl80211_data *drv = bss->drv; + int ret; + int type; + struct i802_bss *p2p_dev = os_zalloc(sizeof(struct i802_bss)); + if (!p2p_dev) + return NULL; + + *p2p_dev = *bss; + os_strncpy(p2p_dev->ifname, ifname, IFNAMSIZ); + + for (last = bss; last->next; last = last->next) + ; + last->next = p2p_dev; + + p2p_dev->ifindex = nl80211_create_iface(drv, ifname, + NL80211_IFTYPE_P2P_DEVICE, + NULL, 0, + nl80211_create_p2p_dev_handler, + p2p_dev); + if (p2p_dev->wdev_id == -1 || p2p_dev->ifindex != 0 || + is_zero_ether_addr((const u8 *)&p2p_dev->addr)) { + wpa_printf(MSG_ERROR, "nl80211: Failed to create a p2p device" + " interface %s", ifname); + last->next = NULL; + os_free(p2p_dev); + return NULL; + } + + ret = nl80211_p2p_device_exec_cmd(drv, ifname, + NL80211_CMD_START_P2P_DEVICE, + p2p_dev->wdev_id); + + if (ret < 0) { + wpa_printf(MSG_ERROR, "nl80211: Failed to start p2p device" + " interface %s", ifname); + nl80211_deinit_p2p_dev(p2p_dev); + return NULL; + } + + os_memcpy(addr, p2p_dev->addr, ETH_ALEN); + + /* Register P2P Public Action frame on the device interface */ + type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); + nl80211_register_frame(p2p_dev, bss->nl_mgmt, type, + (u8 *) "\x04\x09\x50\x6f\x9a\x09", 6); + /* Register P2P Action frame on the device interface */ + nl80211_register_frame(p2p_dev, bss->nl_mgmt, type, + (u8 *) "\x7f\x50\x6f\x9a\x09", 5); + + return p2p_dev; +} +#endif /* CONFIG_P2P */ static int driver_nl80211_set_key(const char *ifname, void *priv, enum wpa_alg alg, const u8 *addr, @@ -9554,4 +9687,8 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = { .send_tdls_mgmt = nl80211_send_tdls_mgmt, .tdls_oper = nl80211_tdls_oper, #endif /* CONFIG_TDLS */ +#ifdef CONFIG_P2P + .init_p2p_dev = nl80211_init_p2p_dev, + .deinit_p2p_dev = nl80211_deinit_p2p_dev, +#endif /* CONFIG_P2P */ };