From patchwork Wed Nov 26 20:56:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arik Nemtsov X-Patchwork-Id: 5387901 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 118D0C11AC for ; Wed, 26 Nov 2014 20:56:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 173B52011B for ; Wed, 26 Nov 2014 20:56:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F98020142 for ; Wed, 26 Nov 2014 20:56:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752787AbaKZU4g (ORCPT ); Wed, 26 Nov 2014 15:56:36 -0500 Received: from mail-wi0-f181.google.com ([209.85.212.181]:56609 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752251AbaKZU4e (ORCPT ); Wed, 26 Nov 2014 15:56:34 -0500 Received: by mail-wi0-f181.google.com with SMTP id r20so6316739wiv.14 for ; Wed, 26 Nov 2014 12:56:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vFs0b+hjEEJ/RyShykxTxC8GlxmHJ+4oE4XoxmCFl3I=; b=aGRHaBN2N7/NiEeh5RyWMQ9yKlHQZBo+vNSGo3NTOzWfzi4sPJsSmg34834g2a5CbV VWcyy21526xDjMKqr1tst0I22Kj7VG7eLeYqVv+Vgh6bYr9/e5EVjjUetCkLRm1eg58U gDcaSw0VJT1dlj+BPmRmQZm8bGkj2t26d389VVSkiYsmJfgxaBT/u2kK7u7vqJ0HMRpJ KAwt4Tu+7+yD7RAOwdNKwejOEqEQ62ZX4g3d5ut35WYfUpj6Y1QVr/rzqbfLi3y4bAfH pwGeGntdR/ZZUT3RDbk+RYjA+ePNt5hR+1rmOUEYFVHJAXK88XLNz0JPevTMMFpwur+T X9Ng== X-Gm-Message-State: ALoCoQk2MRXH2m4VnoIzInyq/rqk8oCCNDGS11gdAVzR0GJyngoyobNqVu3sHEu/5DL50Os6jnFk X-Received: by 10.194.187.235 with SMTP id fv11mr23058485wjc.16.1417035392838; Wed, 26 Nov 2014 12:56:32 -0800 (PST) Received: from athena.amr.corp.intel.com (85-250-108-142.bb.netvision.net.il. [85.250.108.142]) by mx.google.com with ESMTPSA id e7sm7843063wjx.31.2014.11.26.12.56.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Nov 2014 12:56:32 -0800 (PST) From: Arik Nemtsov To: Cc: Johannes Berg , "Luis R. Rodriguez" , Arik Nemtsov Subject: [PATCH v4 4/4] cfg80211: return private regdom for self-managed devices Date: Wed, 26 Nov 2014 22:56:28 +0200 Message-Id: <1417035388-2511-4-git-send-email-arik@wizery.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417035388-2511-1-git-send-email-arik@wizery.com> References: <1417035388-2511-1-git-send-email-arik@wizery.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a device has self-managed regulatory, insist on returning the wiphy specific regdomain if a wiphy-idx is specified. The global regdomain is meaningless for such devices. Also add an attribute for self-managed devices, so usermode can distinguish them as such. Signed-off-by: Arik Nemtsov --- include/uapi/linux/nl80211.h | 7 +++++++ net/wireless/nl80211.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 6517210..00a00ca 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1703,6 +1703,11 @@ enum nl80211_commands { * @NL80211_ATTR_WIPHY_REGDOM_LIST: Nested set of attributes containing * a list of wiphy specific regdomains. * + * @NL80211_ATTR_WIPHY_SELF_MANAGED_REG: flag attribute indicating this device + * is self-managing its regulatory information and any regulatory domain + * obtained from it is coming from the device's wiphy and not the global + * cfg80211 regdomain. + * * @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use @@ -2064,6 +2069,8 @@ enum nl80211_attrs { NL80211_ATTR_WIPHY_REGDOM_LIST, + NL80211_ATTR_WIPHY_SELF_MANAGED_REG, + /* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 65bab11..2a7f051 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -398,6 +398,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, [NL80211_ATTR_WIPHY_PRIV_REG] = { .type = NLA_FLAG }, [NL80211_ATTR_WIPHY_REGDOM_LIST] = { .type = NLA_NESTED }, + [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, }; /* policy for the key attributes */ @@ -5409,6 +5410,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) goto put_failure; if (info->attrs[NL80211_ATTR_WIPHY]) { + bool self_managed; rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); if (IS_ERR(rdev)) { nlmsg_free(msg); @@ -5416,10 +5418,22 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) } wiphy = &rdev->wiphy; + self_managed = wiphy->regulatory_flags & + REGULATORY_WIPHY_SELF_MANAGED; regdom = get_wiphy_regdom(wiphy); if (regdom && nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) goto nla_put_failure; + + /* a self-managed-reg device must have a private regdom */ + if (WARN_ON(!regdom && self_managed)) { + nlmsg_free(msg); + return -EINVAL; + } + + if (self_managed && + nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) + goto nla_put_failure; } if (!regdom) { @@ -5463,6 +5477,10 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) if (nla_put_flag(msg, NL80211_ATTR_WIPHY_PRIV_REG)) goto nla_put_failure_rcu; + if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && + nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) + goto nla_put_failure_rcu; + nla_nest_end(msg, nl_priv_regdom); i++; } @@ -11031,9 +11049,16 @@ static bool nl80211_reg_change_event_fill(struct sk_buff *msg, goto nla_put_failure; } - if (request->wiphy_idx != WIPHY_IDX_INVALID && - nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) - goto nla_put_failure; + if (request->wiphy_idx != WIPHY_IDX_INVALID) { + struct wiphy *wiphy; + + wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); + if (wiphy && + nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx) && + wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && + nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) + goto nla_put_failure; + } return true;