From patchwork Thu Nov 27 07:44:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arik Nemtsov X-Patchwork-Id: 5392801 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 013209F319 for ; Thu, 27 Nov 2014 07:45:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0BCE8201B9 for ; Thu, 27 Nov 2014 07:45:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1698F2016C for ; Thu, 27 Nov 2014 07:45:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752482AbaK0HpG (ORCPT ); Thu, 27 Nov 2014 02:45:06 -0500 Received: from mail-wi0-f182.google.com ([209.85.212.182]:50869 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751173AbaK0HpD (ORCPT ); Thu, 27 Nov 2014 02:45:03 -0500 Received: by mail-wi0-f182.google.com with SMTP id h11so7344580wiw.9 for ; Wed, 26 Nov 2014 23:45:02 -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=leGJ3Cb5HnSQgy6Oy2NM/CRJCiLL+2DZ0zzf7ts+A/o=; b=XYmBCVTRYTh6s05LZkLllphu5IwiBaUM2jVsEsZY3sXn9VE4RyVAuO4Q953crSHBDV K7dpG813zLxP2z0mgHA37EEC4DCUBviR8NN+BBhfXxw8bJSSuRksUVZl3Rnko3ki0Ti6 Gkt3ruLX6OT1KbP1TPXOF7fyrmQTWByMTfartNEc3npma+cMjy5A/c7X2ESrjSbM2JQy CiSf/N0nmSIaTQToJnM7m/TZenQ3DxTEw2qKzRc5pthsxpmu52fqP8RBjWnCvnuejDuM 8ciefgssk2pnAU7YY2jDnrh5AxUtCbrup6Do1zO8IeKXU+DATpXdX+roN3gTfzKO/9au lbtg== X-Gm-Message-State: ALoCoQmD+lhvypdVef09mszst5BnxAENzp74lF57nVjaA8HJLgsEcgzsUN975flsK/fwg+Hg/Hf9 X-Received: by 10.194.57.43 with SMTP id f11mr45951381wjq.6.1417074302434; Wed, 26 Nov 2014 23:45:02 -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 wz5sm9505013wjc.29.2014.11.26.23.45.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Nov 2014 23:45:01 -0800 (PST) From: Arik Nemtsov To: Cc: Johannes Berg , "Luis R. Rodriguez" , Arik Nemtsov Subject: [PATCH v5 4/4] cfg80211: return private regdom for self-managed devices Date: Thu, 27 Nov 2014 09:44:58 +0200 Message-Id: <1417074298-12254-4-git-send-email-arik@wizery.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417074298-12254-1-git-send-email-arik@wizery.com> References: <1417074298-12254-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 0143c59..67eb8ff 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 361a897..42bc9ed 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) { @@ -5467,6 +5481,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++; } @@ -11035,9 +11053,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;