Re: [PATCH 1/3] mac80211: TDLS: always downgrade invalid chandefs

2016-03-06 Thread Arik Nemtsov
On Sun, Mar 6, 2016 at 5:58 PM, Jouni Malinen  wrote:
>
> On Wed, Mar 02, 2016 at 11:28:31PM +0200, Emmanuel Grumbach wrote:
> > Even if the current chandef width is equal to the station's max-BW, it
> > doesn't mean it's a valid width for TDLS. Make sure to always check
> > regulatory constraints in these cases.
>
> I'm not sure this change is the trigger for this issue, but since I
> noticed this for the first time today and this commit went just in into
> wireless-testing.git, it sounds quite likely that this was indeed behind
> the busy loop I saw here:
>
> > diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
> > @@ -332,7 +332,7 @@ ieee80211_tdls_chandef_vht_upgrade(struct 
> > ieee80211_sub_if_data *sdata,
> >   /* proceed to downgrade the chandef until usable or the same */
> > - while (uc.width > max_width &&
> > + while (uc.width > max_width ||
> >  !cfg80211_reg_can_beacon_relax(sdata->local->hw.wiphy, ,
> > sdata->wdev.iftype))
> >   ieee80211_chandef_downgrade();

Good catch :)
We actually just noticed this as well and have a suggested fix already
- basically the code was trying to *upgrade* a 80p80 channel to a 80
one.

I guess it will be out in a couple days after some internal testing.

Arik
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] mac80211: recalc min_def chanctx even when chandef is identical

2016-03-03 Thread Arik Nemtsov
On Thu, Mar 3, 2016 at 5:40 PM, Johannes Berg  wrote:
> All three applied, but I had to fix your Fixes tag commit ID, no idea
> what that referred to :)

Yea I might have taken it from some internal tree :)

Arik
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mac80211: Fix Public Action frame RX in AP mode

2016-03-01 Thread Arik Nemtsov
On Tue, Mar 1, 2016 at 12:29 AM, Jouni Malinen  wrote:
> Public Action frames use special rules for how the BSSID field (Address
> 3) is set. A wildcard BSSID is used in cases where the transmitter and
> recipient are not members of the same BSS. As such, we need to accept
> Public Action frames with wildcard BSSID.
>
> Commit db8e17324553 ("mac80211: ignore frames between TDLS peers when
> operating as AP") added a rule that drops Action frames to TDLS-peers
> based on an Action frame having different DA (Address 1) and BSSID
> (Address 3) values. This is not correct since it misses the possibility
> of BSSID being a wildcard BSSID in which case the Address 1 would not
> necessarily match.
>
> Fix this by allowing mac80211 to accept wildcard BSSID in an Action
> frame when in AP mode.
>
> Fixes: db8e17324553 ("mac80211: ignore frames between TDLS peers when 
> operating as AP")

Fix looks good (I'm the author of the bug) :)

Arik
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mac80211: Let VHT work on 2.4Ghz

2016-02-24 Thread Arik Nemtsov
On Wed, Feb 24, 2016 at 3:37 PM, Ben Greear <gree...@candelatech.com> wrote:
>
>
> On 02/24/2016 05:32 AM, Arik Nemtsov wrote:
>>
>> On Wed, Feb 24, 2016 at 3:24 PM, Ben Greear <gree...@candelatech.com>
>> wrote:
>>>>
>>>> Also it's pretty easy to just leave the code there and condition the
>>>> check on the 5GHz band. There's no need to remove it.
>>>
>>>
>>>
>>> Ok, so I can enable VHT on any band as long as the 5Ghz band exists and
>>> allows 80Mhz?
>>>
>>
>> No idea about that. I'm not sure how/if rate modulation is regulated
>> on 2GHz. The ISM band itself is supposed to be open (microwave heating
>> etc.) so it seems fine to me.
>> But don't take me up on that. This is lawyer domain.
>
>
> I'm trying to understand your suggestion.
>
> Maybe you mean I change my patch to only disable VHT if band == 5Ghz AND
> 80Mhz is not available?

Yes. But I'm not saying you can enable 2.4GHz VHT in that case. I
don't know about that.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mac80211: Let VHT work on 2.4Ghz

2016-02-24 Thread Arik Nemtsov
On Wed, Feb 24, 2016 at 3:24 PM, Ben Greear  wrote:
>> Also it's pretty easy to just leave the code there and condition the
>> check on the 5GHz band. There's no need to remove it.
>
>
> Ok, so I can enable VHT on any band as long as the 5Ghz band exists and
> allows 80Mhz?
>

No idea about that. I'm not sure how/if rate modulation is regulated
on 2GHz. The ISM band itself is supposed to be open (microwave heating
etc.) so it seems fine to me.
But don't take me up on that. This is lawyer domain.

Arik
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mac80211: Let VHT work on 2.4Ghz

2016-02-24 Thread Arik Nemtsov
On Tue, Feb 23, 2016 at 3:46 PM, Ben Greear <gree...@candelatech.com> wrote:
>
>
> On 02/23/2016 02:47 AM, Arik Nemtsov wrote:
>>
>> On Tue, Feb 23, 2016 at 12:42 AM, <gree...@candelatech.com> wrote:
>>>
>>>
>>> From: Ben Greear <gree...@candelatech.com>
>>>
>>> ath10k supports VHT on 2.4Ghz band.
>>> If supplicant and hostapd and radio think
>>> VHT should be allowed, then kernel should let them
>>> try.
>>
>>
>> Removing the 80Mhz check entirely is not the right way to go IMO. The
>> check is there because there are countries where VHT rates are not
>> allowed, even on 20MHz channels. We use the fact these countries have
>> no 80MHz-allowed ranges as a crude regulatory hint to disable VHT
>> entirely. I'm not sure about the regulatory landscape in these
>> countries regarding VHT in 2.4GHz, but please don't break compliance
>> for the 5Ghz use-case.
>
>
> Maybe someone can fix the regulatory logic then?
>
> Add a no-vht flag or whatever?

This is more tricky that it looks at first - basically current
regulatory "hooks" concern channel width and location, transmit power
etc. Here regulatory compliance means never emitting the VHT IE in
probe requests etc. So a "no vht" flag would be useless to the reg.c
code - it currently never looks at IEs. Some cards even generate them
at the FW level.
All in all I think the current small bit of ugliness is justified for
regulatory compliance.

Also it's pretty easy to just leave the code there and condition the
check on the 5GHz band. There's no need to remove it.

>
> Any idea which countries this applies to?

I know Russia is one such country. Not sure about others.

Arik
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mac80211: Let VHT work on 2.4Ghz

2016-02-23 Thread Arik Nemtsov
On Tue, Feb 23, 2016 at 12:42 AM,  wrote:
>
> From: Ben Greear 
>
> ath10k supports VHT on 2.4Ghz band.
> If supplicant and hostapd and radio think
> VHT should be allowed, then kernel should let them
> try.

Removing the 80Mhz check entirely is not the right way to go IMO. The
check is there because there are countries where VHT rates are not
allowed, even on 20MHz channels. We use the fact these countries have
no 80MHz-allowed ranges as a crude regulatory hint to disable VHT
entirely. I'm not sure about the regulatory landscape in these
countries regarding VHT in 2.4GHz, but please don't break compliance
for the 5Ghz use-case.

Arik
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] iw: remove android-nl.c with unneeded workaround

2015-08-02 Thread Arik Nemtsov
On Fri, Jul 31, 2015 at 7:01 PM, enh e...@google.com wrote:
 no, because this is meant for the platform build system rather than
 the NDK. although the NDK has a concept of target API level, the
 platform only has current.

Don't you have PLATFORM_VERSION?
http://androidxref.com/5.1.1_r6/xref/build/core/version_defaults.mk

And I see it's already used in some places.

My 2c is that it's a bad idea to break older version compatibility
when Android is not the owner of the project/git. Basically you don't
really have the same level of control over where this is used.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/2] iw: fix references to libnl in Android.mk

2015-07-31 Thread Arik Nemtsov
Won't this break iw build with earlier Android trees? Did you test
this on something like KK?

On Fri, Jul 31, 2015 at 12:47 AM, Filipe Brandenburger
filbran...@google.com wrote:
 The latest AOSP refers to that library as libnl and not libnl_2.

 TEST=Built AOSP tree with this patchset, tested the generated iw binary.

 Signed-off-by: Filipe Brandenburger filbran...@google.com
 ---
 v2: Removed now redundant LOCAL_C_INCLUDES as suggested by Elliott.
 Retested to confirm it still builds and works as intended.

  Android.mk | 6 +-
  1 file changed, 1 insertion(+), 5 deletions(-)

 diff --git a/Android.mk b/Android.mk
 index 735b236809ef..03bcc3e93d4d 100644
 --- a/Android.mk
 +++ b/Android.mk
 @@ -9,15 +9,11 @@ include $(LOCAL_PATH)/Makefile

  LOCAL_SRC_FILES := $(patsubst %.o,%.c,$(OBJS)) android-nl.c

 -LOCAL_C_INCLUDES := \
 -   $(LOCAL_PATH) \
 -   external/libnl-headers/
 -
  LOCAL_CFLAGS += -DCONFIG_LIBNL20
  LOCAL_LDFLAGS := -Wl,--no-gc-sections
  #LOCAL_MODULE_TAGS := optional
  LOCAL_MODULE_TAGS := eng
 -LOCAL_STATIC_LIBRARIES := libnl_2
 +LOCAL_STATIC_LIBRARIES := libnl
  LOCAL_MODULE := iw

  $(IW_SOURCE_DIR)/version.c:
 --
 2.5.0.rc2.392.g76e840b

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] iw: remove android-nl.c with unneeded workaround

2015-07-31 Thread Arik Nemtsov
On Fri, Jul 31, 2015 at 12:35 AM, Filipe Brandenburger
filbran...@google.com wrote:
 The workaround might have been necessary in the past, however now it
 produces the following error:

   .../libnl.a(attr.o): multiple definition of 'nla_put_flag'
   .../android-nl.o: previous definition here
   collect2: error: ld returned 1 exit status

Since this is required by earlier versions, can't you #ifdef the code
according to version? Also for the makefile change..
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] mac80211: TDLS: correctly configure SMPS state

2015-06-14 Thread Arik Nemtsov
The IEEE802.11-2012 specification is vague regarding SMPS operation during
TDLS. It does not define a clear way to transition between SMPS states.

To avoid interop issues, set SMPS to off when TDLS peers are connected.
Accomplish this by extending the definition of the AUTOMATIC state. If the
driver forces a state other than OFF, disconnect all TDLS peers.

While at it, avoid changing the SMPS state of the peer STA. We have no
way to control it, so try and behave correctly towards it.

Move the TDLS peer-teardown function to where the rest of the TDLS code
resides.

Also update Intel copyright to 2015.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Johannes Berg johannes.b...@intel.com
---
 net/mac80211/cfg.c | 21 ++---
 net/mac80211/ieee80211_i.h |  1 +
 net/mac80211/mlme.c| 18 --
 net/mac80211/tdls.c| 36 
 4 files changed, 51 insertions(+), 25 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index bf7023f..c17f91f 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -2358,6 +2358,8 @@ int __ieee80211_request_smps_mgd(struct 
ieee80211_sub_if_data *sdata,
const u8 *ap;
enum ieee80211_smps_mode old_req;
int err;
+   struct sta_info *sta;
+   bool tdls_peer_found = false;
 
lockdep_assert_held(sdata-wdev.mtx);
 
@@ -2382,11 +2384,22 @@ int __ieee80211_request_smps_mgd(struct 
ieee80211_sub_if_data *sdata,
 
ap = sdata-u.mgd.associated-bssid;
 
+   rcu_read_lock();
+   list_for_each_entry_rcu(sta, sdata-local-sta_list, list) {
+   if (!sta-sta.tdls || sta-sdata != sdata || !sta-uploaded ||
+   !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
+   continue;
+
+   tdls_peer_found = true;
+   break;
+   }
+   rcu_read_unlock();
+
if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
-   if (sdata-u.mgd.powersave)
-   smps_mode = IEEE80211_SMPS_DYNAMIC;
-   else
+   if (tdls_peer_found || !sdata-u.mgd.powersave)
smps_mode = IEEE80211_SMPS_OFF;
+   else
+   smps_mode = IEEE80211_SMPS_DYNAMIC;
}
 
/* send SM PS frame to AP */
@@ -2394,6 +2407,8 @@ int __ieee80211_request_smps_mgd(struct 
ieee80211_sub_if_data *sdata,
 ap, ap);
if (err)
sdata-u.mgd.req_smps = old_req;
+   else if (smps_mode != IEEE80211_SMPS_OFF  tdls_peer_found)
+   ieee80211_teardown_tdls_peers(sdata);
 
return err;
 }
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index b12f615..a5081e6 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2060,6 +2060,7 @@ void ieee80211_tdls_cancel_channel_switch(struct wiphy 
*wiphy,
  const u8 *addr);
 void ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata,
   struct sk_buff *skb);
+void ieee80211_teardown_tdls_peers(struct ieee80211_sub_if_data *sdata);
 
 extern const struct ethtool_ops ieee80211_ethtool_ops;
 
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 9b2cc27..60dd6151 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1096,24 +1096,6 @@ static void ieee80211_chswitch_timer(unsigned long data)
ieee80211_queue_work(sdata-local-hw, sdata-u.mgd.chswitch_work);
 }
 
-static void ieee80211_teardown_tdls_peers(struct ieee80211_sub_if_data *sdata)
-{
-   struct sta_info *sta;
-   u16 reason = WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED;
-
-   rcu_read_lock();
-   list_for_each_entry_rcu(sta, sdata-local-sta_list, list) {
-   if (!sta-sta.tdls || sta-sdata != sdata || !sta-uploaded ||
-   !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
-   continue;
-
-   ieee80211_tdls_oper_request(sdata-vif, sta-sta.addr,
-   NL80211_TDLS_TEARDOWN, reason,
-   GFP_ATOMIC);
-   }
-   rcu_read_unlock();
-}
-
 static void
 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
 u64 timestamp, u32 device_timestamp,
diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
index ad31b2d..b074c85 100644
--- a/net/mac80211/tdls.c
+++ b/net/mac80211/tdls.c
@@ -4,6 +4,7 @@
  * Copyright 2006-2010 Johannes Berg johan...@sipsolutions.net
  * Copyright 2014, Intel Corporation
  * Copyright 2014  Intel Mobile Communications GmbH
+ * Copyright 2015  Intel Deutschland GmbH
  *
  * This file is GPLv2 as found in COPYING.
  */
@@ -384,10 +385,6 @@ ieee80211_tdls_add_setup_start_ies(struct 
ieee80211_sub_if_data *sdata,
ieee80211_ie_build_ht_cap(pos, ht_cap, ht_cap.cap

Re: [PATCH] cfg80211: change GO_CONCURRENT to IR_CONCURRENT for STA

2015-04-27 Thread Arik Nemtsov
On Fri, Apr 24, 2015 at 1:33 PM, Johannes Berg
johan...@sipsolutions.net wrote:

 On Tue, 2015-03-31 at 12:14 +0300, Arik Nemtsov wrote:
  The GO_CONCURRENT regulatory definition can be extended to station
  interfaces requesting to IR as part of TDLS off-channel operations.
  Rename the GO_CONCURRENT flag to IR_CONCURRENT and allow the added
  use-case.
 
  Change internal users of GO_CONCURRENT to use the new definition.
 
  Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
  Reviewed-by: Johannes Berg johannes.b...@intel.com
  ---
  This patch depends on cfg80211: Allow GO concurrent relaxation after
  BSS disconnetion which was recently sent by Emmanuel. It will also
  conflict with a different change to iwlwifi/iwl-nvm-parse.c that's currently
  in Kalle's tree (iwlwifi: mvm: consider LAR support during NVM parse).
  But that's not too hard to fix.

 Perhaps you should rebase it to not have that dependency since we're
 still discussing that other patch.

I think Ilan will send an updated version pretty soon for the
dependency. Otherwise, the conflict will happen on his side..

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cfg80211: change GO_CONCURRENT to IR_CONCURRENT for STA

2015-03-31 Thread Arik Nemtsov
The GO_CONCURRENT regulatory definition can be extended to station
interfaces requesting to IR as part of TDLS off-channel operations.
Rename the GO_CONCURRENT flag to IR_CONCURRENT and allow the added
use-case.

Change internal users of GO_CONCURRENT to use the new definition.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Johannes Berg johannes.b...@intel.com
---
This patch depends on cfg80211: Allow GO concurrent relaxation after
BSS disconnetion which was recently sent by Emmanuel. It will also
conflict with a different change to iwlwifi/iwl-nvm-parse.c that's currently
in Kalle's tree (iwlwifi: mvm: consider LAR support during NVM parse).
But that's not too hard to fix.

 drivers/net/wireless/iwlwifi/iwl-nvm-parse.c |  2 +-
 include/net/cfg80211.h   |  4 +--
 include/uapi/linux/nl80211.h | 28 +++-
 net/wireless/chan.c  | 38 
 net/wireless/nl80211.c   |  4 +--
 net/wireless/reg.c   |  4 +--
 6 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c 
b/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
index c74f1a4..62ce5a3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
+++ b/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
@@ -287,7 +287,7 @@ static int iwl_init_channel_map(struct device *dev, const 
struct iwl_cfg *cfg,
 */
if ((ch_flags  NVM_CHANNEL_GO_CONCURRENT) 
(channel-flags  IEEE80211_CHAN_NO_IR))
-   channel-flags |= IEEE80211_CHAN_GO_CONCURRENT;
+   channel-flags |= IEEE80211_CHAN_IR_CONCURRENT;
 
/* Initialize regulatory-based run-time data */
 
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index ab667fb..0b21cfb 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -111,7 +111,7 @@ enum ieee80211_band {
  * This may be due to the driver or due to regulatory bandwidth
  * restrictions.
  * @IEEE80211_CHAN_INDOOR_ONLY: see %NL80211_FREQUENCY_ATTR_INDOOR_ONLY
- * @IEEE80211_CHAN_GO_CONCURRENT: see %NL80211_FREQUENCY_ATTR_GO_CONCURRENT
+ * @IEEE80211_CHAN_IR_CONCURRENT: see %NL80211_FREQUENCY_ATTR_IR_CONCURRENT
  * @IEEE80211_CHAN_NO_20MHZ: 20 MHz bandwidth is not permitted
  * on this channel.
  * @IEEE80211_CHAN_NO_10MHZ: 10 MHz bandwidth is not permitted
@@ -129,7 +129,7 @@ enum ieee80211_channel_flags {
IEEE80211_CHAN_NO_80MHZ = 17,
IEEE80211_CHAN_NO_160MHZ= 18,
IEEE80211_CHAN_INDOOR_ONLY  = 19,
-   IEEE80211_CHAN_GO_CONCURRENT= 110,
+   IEEE80211_CHAN_IR_CONCURRENT= 110,
IEEE80211_CHAN_NO_20MHZ = 111,
IEEE80211_CHAN_NO_10MHZ = 112,
 };
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 241220c..c0ab6b0 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -2620,16 +2620,17 @@ enum nl80211_band_attr {
  * an indoor surroundings, i.e., it is connected to AC power (and not
  * through portable DC inverters) or is under the control of a master
  * that is acting as an AP and is connected to AC power.
- * @NL80211_FREQUENCY_ATTR_GO_CONCURRENT: GO operation is allowed on this
+ * @NL80211_FREQUENCY_ATTR_IR_CONCURRENT: IR operation is allowed on this
  * channel if it's connected concurrently to a BSS on the same channel on
  * the 2 GHz band or to a channel in the same UNII band (on the 5 GHz
- * band), and IEEE80211_CHAN_RADAR is not set. Instantiating a GO on a
- * channel that has the GO_CONCURRENT attribute set can be done when there
- * is a clear assessment that the device is operating under the guidance of
- * an authorized master, i.e., setting up a GO while the device is also
- * connected to an AP with DFS and radar detection on the UNII band (it is
- * up to user-space, i.e., wpa_supplicant to perform the required
- * verifications)
+ * band), and IEEE80211_CHAN_RADAR is not set. Instantiating a GO or TDLS
+ * off-channel on a channel that has the IR_CONCURRENT attribute set can be
+ * done when there is a clear assessment that the device is operating under
+ * the guidance of an authorized master, i.e., setting up a GO or TDLS
+ * off-channel while the device is also connected to an AP with DFS and
+ * radar detection on the UNII band (it is up to user-space, i.e.,
+ * wpa_supplicant to perform the required verifications). Using this
+ * attribute for IR is disallowed for master interfaces (IBSS, AP).
  * @NL80211_FREQUENCY_ATTR_NO_20MHZ: 20 MHz operation is not allowed
  * on this channel in current regulatory domain.
  * @NL80211_FREQUENCY_ATTR_NO_10MHZ: 10 MHz operation is not allowed
@@ -2641,7 +2642,7 @@ enum nl80211_band_attr {
  * See 
https://apps.fcc.gov/eas/comments

Re: [PATCH 1/4] mac80211: don't look up destination station twice

2015-03-22 Thread Arik Nemtsov
On Fri, Mar 20, 2015 at 5:24 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 From: Johannes Berg johannes.b...@intel.com

 There's no need to look up the destination station twice while
 building the 802.11 header for a given frame if the frame will
 actually be transmitted to the station we initially looked up.

 This happens for 4-addr VLAN interfaces and TDLS connections, which
 both directly send the frame to the station they looked up, though
 in the case of TDLS some station conditions need to be checked.

 To avoid that, add a variable indicating that we've looked up the
 station that the frame is going to be transmitted to, and avoid the
 lookup/flag checking if it already has been done.

 In the TDLS case, also move the authorized/wme_sta flag assignment
 to the correct place, i.e. only when that station is really used.
 Before this change, the new lookup should always have succeeded so
 that the potentially erroneous data would be overwritten.

 Signed-off-by: Johannes Berg johannes.b...@intel.com

The TDLS parts look good.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 5/6] ath10k: add wmi support for tdls

2015-03-22 Thread Arik Nemtsov
On Fri, Mar 20, 2015 at 1:02 PM, Marek Puzyniak
marek.puzyn...@tieto.com wrote:
 As a part of tdls implementation introduce
 tdls related wmi data structures, constant
 values and functions.

 Signed-off-by: Marek Puzyniak marek.puzyn...@tieto.com
 ---
  drivers/net/wireless/ath/ath10k/wmi-ops.h |  42 
  drivers/net/wireless/ath/ath10k/wmi-tlv.c | 153 
 ++
  drivers/net/wireless/ath/ath10k/wmi-tlv.h |  53 +++
  drivers/net/wireless/ath/ath10k/wmi.h |  37 
  4 files changed, 285 insertions(+)
[...]
 +
 +   cmd = (void *)tlv-value;
 +   cmd-vdev_id = __cpu_to_le32(vdev_id);
 +   cmd-state = __cpu_to_le32(state);
 +   cmd-notification_interval_ms = __cpu_to_le32(5000);
 +   cmd-tx_discovery_threshold = __cpu_to_le32(100);
 +   cmd-tx_teardown_threshold = __cpu_to_le32(5);
 +   cmd-rssi_teardown_threshold = __cpu_to_le32(-75);
 +   cmd-rssi_delta = __cpu_to_le32(-20);
 +   cmd-tdls_options = __cpu_to_le32(options);
 +   cmd-tdls_peer_traffic_ind_window = __cpu_to_le32(2);
 +   cmd-tdls_peer_traffic_response_timeout_ms = __cpu_to_le32(5000);
 +   cmd-tdls_puapsd_mask = __cpu_to_le32(0xf);
 +   cmd-tdls_puapsd_inactivity_time_ms = __cpu_to_le32(0);
 +   cmd-tdls_puapsd_rx_frame_threshold = __cpu_to_le32(10);

Do the above lines assume all TDLS peers support TDLS buffer-sta
(which is required for peer UAPSD)? Especially the value of
tdls_puapsd_mask.
I can assure you not all peers support this :) For instance iwlwifi
does not (for now).

But I might be misinterpreting this - perhaps there some other code in
the driver/FW that checks the peer's extended-capabilities IE for
buffer-sta support (bit 28)?
That would be the best option.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] mac80211: initialize rate control earlier for tdls station

2015-03-08 Thread Arik Nemtsov
From: Marek Puzyniak marek.puzyn...@tieto.com

Currently when TDLS station in driver goes from authorized
to associated state it can not use rate control parameters
because rate control is not initialized yet. Some drivers
require parameters already initialized by rate control when
entering associated state. It can be done by initializing
rate control after station transition to associated state
but before notifying driver about that.

Signed-off-by: Marek Puzyniak marek.puzyn...@tieto.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 net/mac80211/cfg.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 94889de..0e43e6e 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -977,6 +977,14 @@ static int sta_apply_auth_flags(struct ieee80211_local 
*local,
if (mask  BIT(NL80211_STA_FLAG_ASSOCIATED) 
set  BIT(NL80211_STA_FLAG_ASSOCIATED) 
!test_sta_flag(sta, WLAN_STA_ASSOC)) {
+   /*
+* When peer becomes authorized, init rate control as
+* well. Some drivers require rate control initialized
+* before drv_sta_state() is called.
+*/
+   if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
+   rate_control_rate_init(sta);
+
ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
if (ret)
return ret;
@@ -1378,11 +1386,6 @@ static int ieee80211_change_station(struct wiphy *wiphy,
if (err)
goto out_err;
 
-   /* When peer becomes authorized, init rate control as well */
-   if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) 
-   test_sta_flag(sta, WLAN_STA_AUTHORIZED))
-   rate_control_rate_init(sta);
-
mutex_unlock(local-sta_mtx);
 
if ((sdata-vif.type == NL80211_IFTYPE_AP ||
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 3/4] mac80211: initialize rate control earlier for tdls station

2015-03-04 Thread Arik Nemtsov
On Wed, Mar 4, 2015 at 12:38 PM, Marek Puzyniak
marek.puzyn...@tieto.com wrote:
 On 4 March 2015 at 11:04, Arik Nemtsov a...@wizery.com wrote:
 I can do it, but I'll probably only get to it next week.

 I will try to prepare patch this week, if not I will wait for Arik's
 proposition.

 For ath10k rate control need to be initialised before moving to
 STA_AUTHORIZED, so initialising rate control before STA_ASSOC is
 perfectly fine.

Ok I did get to it today :)
With the attached patch applied, and the patch mac80211: update TDLS
sta spatial streams before auth reverted, I'm getting good
performance on iwlwifi.

Arik
From 133a9b280c23fa0d49e93dae8655b9514ac71fee Mon Sep 17 00:00:00 2001
From: Marek Puzyniak marek.puzyn...@tieto.com
Date: Wed, 25 Feb 2015 08:55:10 +0100
Subject: [PATCH] mac80211: initialize rate control earlier for tdls station

Currently when TDLS station in driver goes from assoc
to authorized state it can not use rate control parameters
because rate control is not initialized yet. Some drivers
require parameters already initialized by rate control when
entering authorized state. It can be done by initializing
rate control after station transition to authorized state
but before notifying driver about that.

Signed-off-by: Marek Puzyniak marek.puzyn...@tieto.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 net/mac80211/cfg.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index c13b1af..55b88c7 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -977,6 +977,14 @@ static int sta_apply_auth_flags(struct ieee80211_local *local,
 	if (mask  BIT(NL80211_STA_FLAG_ASSOCIATED) 
 	set  BIT(NL80211_STA_FLAG_ASSOCIATED) 
 	!test_sta_flag(sta, WLAN_STA_ASSOC)) {
+		/*
+		 * When peer becomes authorized, init rate control as
+		 * well. Some drivers require rate control initialized
+		 * before drv_sta_state() is called.
+		 */
+		if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
+			rate_control_rate_init(sta);
+
 		ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
 		if (ret)
 			return ret;
@@ -1381,11 +1389,6 @@ static int ieee80211_change_station(struct wiphy *wiphy,
 	if (err)
 		goto out_err;
 
-	/* When peer becomes authorized, init rate control as well */
-	if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) 
-	test_sta_flag(sta, WLAN_STA_AUTHORIZED))
-		rate_control_rate_init(sta);
-
 	mutex_unlock(local-sta_mtx);
 
 	if ((sdata-vif.type == NL80211_IFTYPE_AP ||
-- 
2.1.0



Re: [PATCH v2 3/4] mac80211: initialize rate control earlier for tdls station

2015-03-04 Thread Arik Nemtsov
On Wed, Mar 4, 2015 at 10:16 AM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Tue, 2015-03-03 at 12:07 +0200, Arik Nemtsov wrote:

  And doing so would also address the nss problem, right? IIRC that's done
  in the rate control init inline.

 Right.

 Can one of you (Marek/Arik) send a combined patch then please? :)

I can do it, but I'll probably only get to it next week.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 3/4] mac80211: initialize rate control earlier for tdls station

2015-03-03 Thread Arik Nemtsov
On Tue, Mar 3, 2015 at 11:18 AM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Sun, 2015-03-01 at 10:21 +0200, Arik Nemtsov wrote:

  Arik, you have a similar patch handling only NSS. Does this one look
  fine to you, and would it solve the problem your other patch solved?

 Well currently iwlmvm requires the NSS to be set before
 IEEE80211_STA_ASSOC (earlier), so this doesn't help directly.
 I could change mvm a bit to make it work, but I don't really see a
 good reason for it :)

 The patch looks good. Shouldn't introduce new issues (at least for iwlwifi).

 Ok, thanks. Do you think it would be possible to move all of this before
 ASSOC?

We can probably move his rate_control_rate_init() to assoc, since we have this:

/*
* TDLS -- everything follows authorized, but
* only becoming authorized is possible, not
* going back
*/
if (set  BIT(NL80211_STA_FLAG_AUTHORIZED)) {
set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  BIT(NL80211_STA_FLAG_ASSOCIATED);
mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
BIT(NL80211_STA_FLAG_ASSOCIATED);
}
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 3/4] mac80211: initialize rate control earlier for tdls station

2015-03-03 Thread Arik Nemtsov
On Tue, Mar 3, 2015 at 12:06 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Tue, 2015-03-03 at 12:02 +0200, Arik Nemtsov wrote:
 On Tue, Mar 3, 2015 at 11:18 AM, Johannes Berg
 johan...@sipsolutions.net wrote:
  On Sun, 2015-03-01 at 10:21 +0200, Arik Nemtsov wrote:
 
   Arik, you have a similar patch handling only NSS. Does this one look
   fine to you, and would it solve the problem your other patch solved?
 
  Well currently iwlmvm requires the NSS to be set before
  IEEE80211_STA_ASSOC (earlier), so this doesn't help directly.
  I could change mvm a bit to make it work, but I don't really see a
  good reason for it :)
 
  The patch looks good. Shouldn't introduce new issues (at least for 
  iwlwifi).
 
  Ok, thanks. Do you think it would be possible to move all of this before
  ASSOC?

 We can probably move his rate_control_rate_init() to assoc, since we have 
 this:

 And doing so would also address the nss problem, right? IIRC that's done
 in the rate control init inline.

Right.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 3/4] mac80211: initialize rate control earlier for tdls station

2015-03-01 Thread Arik Nemtsov
On Fri, Feb 27, 2015 at 2:50 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 +Arik.

 It'd be nice (for me anyway) if you didn't send this in a series of
 other patches I don't care about - I only ever saw this due to
 patchwork.

 On Wed, 2015-02-25 at 08:55 +0100, Marek Puzyniak wrote:
 Currently when TDLS station in driver goes from assoc
 to authorized state it can not use rate control parameters
 because rate control is not initialized yet. Some drivers
 require parameters already initialized by rate control when
 entering authorized state. It can be done by initializing
 rate control after station transition to authorized state
 but before notifyiIEEE80211_STA_ASSOCng driver about that.

 Arik, you have a similar patch handling only NSS. Does this one look
 fine to you, and would it solve the problem your other patch solved?

Well currently iwlmvm requires the NSS to be set before
IEEE80211_STA_ASSOC (earlier), so this doesn't help directly.
I could change mvm a bit to make it work, but I don't really see a
good reason for it :)

The patch looks good. Shouldn't introduce new issues (at least for iwlwifi).

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFCv3 4/4] mac80211: add VHT support for IBSS

2015-01-26 Thread Arik Nemtsov
On Mon, Jan 26, 2015 at 10:26 AM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Sun, 2015-01-25 at 12:30 +0200, Arik Nemtsov wrote:

  +   switch (chandef-width) {
  +   case NL80211_CHAN_WIDTH_80:
  +   vht_oper-chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  +   break;
  +   case NL80211_CHAN_WIDTH_80P80:
  +   vht_oper-chan_width = IEEE80211_VHT_CHANWIDTH_80P80MHZ;
  +   vht_oper-center_freq_seg2_idx =
  +   
  ieee80211_frequency_to_channel(chandef-center_freq2);
  +   break;
  +   case NL80211_CHAN_WIDTH_160:
  +   vht_oper-chan_width = IEEE80211_VHT_CHANWIDTH_160MHZ;
  +   break;
  +   default:
  +   return pos;
  +   }

 Shouldn't you also set vht_oper-basic_mcs_set here? Of course if you
 have no use for it in IBSS I can add it later.

 Why would you want to require VHT rates?

Are you sure it's required and no the other way around in this case?
As in specifying which rates are not supported.
Not sure it means the same thing as in the HT instance.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mac80211: tdls: disentangle HT supported conditions

2015-01-25 Thread Arik Nemtsov
On Fri, Jan 23, 2015 at 12:45 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 From: Johannes Berg johannes.b...@intel.com

 These conditions are rather difficult to follow, for example
 because !sta only exists to not crash in the case that we
 don't have a station pointer (WLAN_TDLS_SETUP_REQUEST) in
 which the additional condition (peer supports HT) doesn't
 actually matter anyway.

 Cleaning this up only duplicates two lines of code but makes
 the rest far easier to read, so do that.

 As a side effect, smatch stops complaining about the lack of
 a sta pointer test after the !sta (since the !sta goes away)

 Signed-off-by: Johannes Berg johannes.b...@intel.com

Reviewed-by: Arik Nemtsov a...@wizery.com

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFCv3 4/4] mac80211: add VHT support for IBSS

2015-01-25 Thread Arik Nemtsov
On Tue, Jan 20, 2015 at 2:35 PM, Janusz Dziedzic
janusz.dzied...@tieto.com wrote:
 Add VHT80/VHT160 support for IBSS.
 Drivers could activate this feature by
 setting NL80211_FEATURE_VHT_IBSS flag.

 Signed-off-by: Janusz Dziedzic janusz.dzied...@tieto.com
[...]
 +u8 *ieee80211_ie_build_vht_oper(u8 *pos, struct ieee80211_sta_vht_cap 
 *vht_cap,
 +   const struct cfg80211_chan_def *chandef)
 +{
 +   struct ieee80211_vht_operation *vht_oper;
 +
 +   /* Build VHT Operation */
 +   *pos++ = WLAN_EID_VHT_OPERATION;
 +   *pos++ = sizeof(struct ieee80211_vht_operation);
 +
 +   vht_oper = (struct ieee80211_vht_operation *)pos;
 +
 +   vht_oper-center_freq_seg1_idx =
 +   ieee80211_frequency_to_channel(chandef-center_freq1);
 +   vht_oper-center_freq_seg2_idx = 0;
 +   vht_oper-basic_mcs_set = vht_cap-vht_mcs.rx_mcs_map;
 +
 +   switch (chandef-width) {
 +   case NL80211_CHAN_WIDTH_80:
 +   vht_oper-chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
 +   break;
 +   case NL80211_CHAN_WIDTH_80P80:
 +   vht_oper-chan_width = IEEE80211_VHT_CHANWIDTH_80P80MHZ;
 +   vht_oper-center_freq_seg2_idx =
 +   ieee80211_frequency_to_channel(chandef-center_freq2);
 +   break;
 +   case NL80211_CHAN_WIDTH_160:
 +   vht_oper-chan_width = IEEE80211_VHT_CHANWIDTH_160MHZ;
 +   break;
 +   default:
 +   return pos;
 +   }

Shouldn't you also set vht_oper-basic_mcs_set here? Of course if you
have no use for it in IBSS I can add it later.
Some peers (notably mac80211-based ones) might not use the info, but
others might..

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFCv3 4/4] mac80211: add VHT support for IBSS

2015-01-25 Thread Arik Nemtsov
On Fri, Jan 23, 2015 at 12:04 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 +++ b/net/mac80211/util.c
 @@ -2317,6 +2317,41 @@ u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct 
 ieee80211_sta_ht_cap *ht_cap,
   return pos + sizeof(struct ieee80211_ht_operation);
  }

 +u8 *ieee80211_ie_build_vht_oper(u8 *pos, struct ieee80211_sta_vht_cap 
 *vht_cap,
 + const struct cfg80211_chan_def *chandef)

 I still think you should keep this a static function in ibss.c since
 nobody else is going to use it soon - the only possible user is mesh
 anyway I think.

Actually TDLS needs to use it pretty soon as well :)

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/2] cfg80211: avoid reg-hints in self-managed only systems

2015-01-13 Thread Arik Nemtsov
On Tue, Jan 13, 2015 at 12:30 PM, Julian Calaby julian.cal...@gmail.com wrote:
 Hi Arik,

 On Tue, Jan 13, 2015 at 9:11 PM, Arik Nemtsov a...@wizery.com wrote:
 On Tue, Jan 13, 2015 at 6:26 AM, Julian Calaby julian.cal...@gmail.com 
 wrote:
 Hi Arik,

 On Thu, Jan 8, 2015 at 1:47 AM, Arik Nemtsov a...@wizery.com wrote:
 When a system contains only self-managed regulatory devices all hints
 from the regulatory core are ignored. Stop hint processing early in this
 case. These systems usually don't have CRDA deployed, which results in
 endless (irrelevent) logs of the form:
 cfg80211: Calling CRDA to update world regulatory domain

 Make sure there's at least one self-managed device before discarding a
 hint, in order to prevent initial hints from disappearing on CRDA
 managed systems.

 Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
 ---
  net/wireless/reg.c | 25 +
  1 file changed, 25 insertions(+)

 diff --git a/net/wireless/reg.c b/net/wireless/reg.c
 index 521f3a4..588e45f 100644
 --- a/net/wireless/reg.c
 +++ b/net/wireless/reg.c
 @@ -2120,6 +2120,26 @@ out_free:
 reg_free_request(reg_request);
  }

 +static bool reg_only_self_managed_wiphys(void)
 +{
 +   struct cfg80211_registered_device *rdev;
 +   struct wiphy *wiphy;
 +   bool self_managed_found = false;
 +
 +   ASSERT_RTNL();

 Would it make sense to quickly return false here if the list is empty
 rather than the whole mess with the new variable?

 I'm thinking the mess isn't really such a mess - are you expecting a
 real performance hit?

 Personally, purely for readability, I prefer the style of checking and
 returning as early as possible.

Actually I thought readability was on my side - wanted to point out
the shorter version of the code is more legible.
I guess it's a matter of personal taste :)


 Arguably doing it my way trades speed for memory efficiency and your
 way trades memory efficiency for speed, but it's so small (and this is
 so far from a hot path) that there's no real argument either way
 whatsoever.

Agree it doesn't matter for these reasons.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/2] cfg80211: avoid reg-hints in self-managed only systems

2015-01-13 Thread Arik Nemtsov
On Tue, Jan 13, 2015 at 6:26 AM, Julian Calaby julian.cal...@gmail.com wrote:
 Hi Arik,

 On Thu, Jan 8, 2015 at 1:47 AM, Arik Nemtsov a...@wizery.com wrote:
 When a system contains only self-managed regulatory devices all hints
 from the regulatory core are ignored. Stop hint processing early in this
 case. These systems usually don't have CRDA deployed, which results in
 endless (irrelevent) logs of the form:
 cfg80211: Calling CRDA to update world regulatory domain

 Make sure there's at least one self-managed device before discarding a
 hint, in order to prevent initial hints from disappearing on CRDA
 managed systems.

 Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
 ---
  net/wireless/reg.c | 25 +
  1 file changed, 25 insertions(+)

 diff --git a/net/wireless/reg.c b/net/wireless/reg.c
 index 521f3a4..588e45f 100644
 --- a/net/wireless/reg.c
 +++ b/net/wireless/reg.c
 @@ -2120,6 +2120,26 @@ out_free:
 reg_free_request(reg_request);
  }

 +static bool reg_only_self_managed_wiphys(void)
 +{
 +   struct cfg80211_registered_device *rdev;
 +   struct wiphy *wiphy;
 +   bool self_managed_found = false;
 +
 +   ASSERT_RTNL();

 Would it make sense to quickly return false here if the list is empty
 rather than the whole mess with the new variable?

I'm thinking the mess isn't really such a mess - are you expecting a
real performance hit?

Also this is a corner case - you won't really get regulatory updates
when no network cards are presents. You only get a single update to
the core.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] cfg80211: fix deadlock during reg chan check

2015-01-07 Thread Arik Nemtsov
On Tue, Jan 6, 2015 at 12:51 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Mon, 2014-12-29 at 11:59 +0200, Arik Nemtsov wrote:
 If a P2P GO is active, the cfg80211_reg_can_beacon function will take
 the wdev lock, in its call to cfg80211_go_permissive_chan. But the wdev lock
 is already taken by the parent channel-checking function, causing a
 deadlock.
 Split the checking code into two parts. The first part will check if the
 wdev is active and saves the channel under the wdev lock. The second part
 will check actual channel validity according to type.

 I'm not convinced this is the right thing to do. When checking for the
 current wdev that it can use a channel, then it seems that it's own
 current BSS connection (if any) shouldn't actually be taken into account
 - ergo the lock shouldn't have to be taken, that interface should be
 excluded from the can beacon due to concurrent check anyway.

We have a couple of checks we want to add in the pipeline that also
need this wdev in the concurrent check, so I'd prefer to avoid this.

Unless we treat the exclude_wdev as already locked wdev, which I
think is unglier than what I do here.


 Also, the only reason this can happen anyway is when you call can
 beacon for a station interface - which seems nonsensical. Given that

This is not true. This happens with current code for a p2p-go
interface during channel validity checks in reg.c.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] cfg80211: fix deadlock during reg chan check

2015-01-07 Thread Arik Nemtsov
On Wed, Jan 7, 2015 at 3:50 PM, Johannes Berg johan...@sipsolutions.net wrote:
 On Wed, 2015-01-07 at 15:48 +0200, Arik Nemtsov wrote:
 
  
Also, the only reason this can happen anyway is when you call can
beacon for a station interface - which seems nonsensical. Given that
  
   This is not true. This happens with current code for a p2p-go
   interface during channel validity checks in reg.c.
  
   Not sure I see this? The only thing doing wdev locking is
   cfg80211_go_permissive_chan(), no? And that only for station interfaces.
 
  cfg80211_go_permissive_chan is called from cfg80211_reg_can_beacon,
  currently only for GO interfaces, but for STA also in the future
  (hopefully).
  The latter is called during channel validity checks for GO.
 
  Ok.
 
  Should I just apply the patch as it is then?

 It fixes a real existing deadlock, so I think so, yea.

 Is it needed on 3.19?

Yes, since the channel validity checking is already there. Basically
everyone that sets up a GO and has some regulatory change afterwards
might deadlock..

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mac80211: add TDLS supported channels correctly

2015-01-07 Thread Arik Nemtsov
On Tue, Jan 6, 2015 at 12:43 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Mon, 2014-12-29 at 11:59 +0200, Arik Nemtsov wrote:
 The function adding the supported channels IE during a TDLS connection had
 several issues:
 1. If the entire subband is usable, the function exitted the loop without
 adding it
 2. The function only checked chandef_usable, ignoring flags like RADAR
 which would prevent TDLS off-channel communcation.
 3. HT20 was explicitly required in the chandef, while not a requirement
 for TDLS off-channel.


 That's a strangely formatted commit message ... :)

I thought it's clearer this way. You disagree?



 + if (cfg80211_reg_can_beacon(sdata-local-hw.wiphy,
 + chandef,
 + sdata-wdev.iftype)) {
   ch_cnt++;
   continue;

 With some thinking, I can understand it - but that means you need a
 comment here.

Sure.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] cfg80211: introduce sync regdom set API for self-managed

2015-01-07 Thread Arik Nemtsov
On Tue, Jan 6, 2015 at 12:54 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Thu, 2015-01-01 at 13:42 +0200, Arik Nemtsov wrote:
 A self-managed device will sometimes need to set its regdomain synchronously.
 Notably it should be set before usermode has a chance to query it. Expose
 a new API to accomplish this which requires the RTNL.

 + ret = regulatory_set_wiphy_regd(wiphy, rd);
 + if (ret)
 + return ret;

 It seems to me you should refactor that and avoid scheduling the work
 struct when you're going to run the necessary work below by hand.

Sounds good.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] cfg80211: fix deadlock during reg chan check

2015-01-07 Thread Arik Nemtsov
On Wed, Jan 7, 2015 at 3:37 PM, Johannes Berg johan...@sipsolutions.net wrote:
 On Wed, 2015-01-07 at 15:34 +0200, Arik Nemtsov wrote:

  I'm not convinced this is the right thing to do. When checking for the
  current wdev that it can use a channel, then it seems that it's own
  current BSS connection (if any) shouldn't actually be taken into account
  - ergo the lock shouldn't have to be taken, that interface should be
  excluded from the can beacon due to concurrent check anyway.

 We have a couple of checks we want to add in the pipeline that also
 need this wdev in the concurrent check, so I'd prefer to avoid this.

 Why would you need to check this wdev when doing something for this
 wdev? Seems odd? But I'm willing to learn :)

There's some convoluted regulatory logic where if this GO (or any
other) are operating on this GO_CONCURRENT (and not indoor-only)
channel, then it may continue in its operation even after the STA that
operated concurrently has disconnected.


  Also, the only reason this can happen anyway is when you call can
  beacon for a station interface - which seems nonsensical. Given that

 This is not true. This happens with current code for a p2p-go
 interface during channel validity checks in reg.c.

 Not sure I see this? The only thing doing wdev locking is
 cfg80211_go_permissive_chan(), no? And that only for station interfaces.

cfg80211_go_permissive_chan is called from cfg80211_reg_can_beacon,
currently only for GO interfaces, but for STA also in the future
(hopefully).
The latter is called during channel validity checks for GO.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] cfg80211: avoid reg-hints in self-managed only systems

2015-01-07 Thread Arik Nemtsov
On Wed, Jan 7, 2015 at 3:42 PM, Johannes Berg johan...@sipsolutions.net wrote:
 On Wed, 2015-01-07 at 15:38 +0200, Arik Nemtsov wrote:
 On Tue, Jan 6, 2015 at 4:04 PM, Arik Nemtsov a...@wizery.com wrote:
  On Tue, Jan 6, 2015 at 3:59 PM, Johannes Berg johan...@sipsolutions.net 
  wrote:
  On Tue, 2015-01-06 at 11:56 +0100, Johannes Berg wrote:
  On Thu, 2015-01-01 at 13:42 +0200, Arik Nemtsov wrote:
   When a system contains only self-managed regulatory devices all hints
   from the regulatory core are ignored. Stop hint processing early in 
   this
   case. These systems usually don't have CRDA deployed, which results in
   endless (irrelevent) logs of the form:
   cfg80211: Calling CRDA to update world regulatory domain
 
  Applied.
 
  I take that back - dropped again. This was causing spurious messages in
  the hwsim test run VM, saying something like couldn't set reg domain:
  -7. Maybe at that point not a single wiphy existed?
 
  Interesting. I guess I should fix this to only drop the request in
  case there's at least one self-managed wiphy.

 Could you point me to the hwsim test that failed for you?

 I don't think it was a specific test case - the message seems to have
 come during boot. OTOH, I also reverted some of Eliad's patches, so
 perhaps I should retest without those?

It's a good check to add anyway (at least one self-managed device).
Since the regulatory queues us the world-update core hint right away..
Not sure why I haven't encountered it, I'll try to introduce some
sleep() calls to reproduce. It's a real bug I believe.


 Also where is that message coming from? I don't see it in wpa_s or the 
 kernel.

 I have no idea! I can't even explain where the -7 (-E2BIG) came from!

Yea that's what I was after as well. :)

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] mac80211: add TDLS supported channels correctly

2015-01-07 Thread Arik Nemtsov
The function adding the supported channels IE during a TDLS connection had
several issues:
1. If the entire subband is usable, the function exitted the loop without
   adding it
2. The function only checked chandef_usable, ignoring flags like RADAR
   which would prevent TDLS off-channel communcation.
3. HT20 was explicitly required in the chandef, while not a requirement
   for TDLS off-channel.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Emmanuel Grumbach emmanuel.grumb...@intel.com
---
 net/mac80211/tdls.c | 26 +-
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
index 55ddd77..9b789c6 100644
--- a/net/mac80211/tdls.c
+++ b/net/mac80211/tdls.c
@@ -68,17 +68,24 @@ ieee80211_tdls_add_subband(struct ieee80211_sub_if_data 
*sdata,
ch = ieee80211_get_channel(sdata-local-hw.wiphy, i);
if (ch) {
/* we will be active on the channel */
-   u32 flags = IEEE80211_CHAN_DISABLED |
-   IEEE80211_CHAN_NO_IR;
cfg80211_chandef_create(chandef, ch,
-   NL80211_CHAN_HT20);
-   if (cfg80211_chandef_usable(sdata-local-hw.wiphy,
-   chandef, flags)) {
+   NL80211_CHAN_NO_HT);
+   if (cfg80211_reg_can_beacon(sdata-local-hw.wiphy,
+   chandef,
+   sdata-wdev.iftype)) {
ch_cnt++;
+   /*
+* check if the next channel is also part of
+* this allowed range
+*/
continue;
}
}
 
+   /*
+* we've reached the end of a range, with allowed channels
+* found
+*/
if (ch_cnt) {
u8 *pos = skb_put(skb, 2);
*pos++ = ieee80211_frequency_to_channel(subband_start);
@@ -89,6 +96,15 @@ ieee80211_tdls_add_subband(struct ieee80211_sub_if_data 
*sdata,
}
}
 
+   /* all channels in the requested range are allowed - add them here */
+   if (ch_cnt) {
+   u8 *pos = skb_put(skb, 2);
+   *pos++ = ieee80211_frequency_to_channel(subband_start);
+   *pos++ = ch_cnt;
+
+   subband_cnt++;
+   }
+
return subband_cnt;
 }
 
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] cfg80211: avoid reg-hints in self-managed only systems

2015-01-07 Thread Arik Nemtsov
On Tue, Jan 6, 2015 at 4:04 PM, Arik Nemtsov a...@wizery.com wrote:
 On Tue, Jan 6, 2015 at 3:59 PM, Johannes Berg johan...@sipsolutions.net 
 wrote:
 On Tue, 2015-01-06 at 11:56 +0100, Johannes Berg wrote:
 On Thu, 2015-01-01 at 13:42 +0200, Arik Nemtsov wrote:
  When a system contains only self-managed regulatory devices all hints
  from the regulatory core are ignored. Stop hint processing early in this
  case. These systems usually don't have CRDA deployed, which results in
  endless (irrelevent) logs of the form:
  cfg80211: Calling CRDA to update world regulatory domain

 Applied.

 I take that back - dropped again. This was causing spurious messages in
 the hwsim test run VM, saying something like couldn't set reg domain:
 -7. Maybe at that point not a single wiphy existed?

 Interesting. I guess I should fix this to only drop the request in
 case there's at least one self-managed wiphy.

Could you point me to the hwsim test that failed for you?
Also where is that message coming from? I don't see it in wpa_s or the kernel.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/2] cfg80211: introduce sync regdom set API for self-managed

2015-01-07 Thread Arik Nemtsov
A self-managed device will sometimes need to set its regdomain synchronously.
Notably it should be set before usermode has a chance to query it. Expose
a new API to accomplish this which requires the RTNL.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Ilan Peer ilan.p...@intel.com
Reviewed-by: Emmanuel Grumbach emmanuel.grumb...@intel.com
---
 include/net/cfg80211.h | 14 ++
 net/wireless/reg.c | 31 +--
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index f38645f..39d102d 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -3830,6 +3830,20 @@ int regulatory_set_wiphy_regd(struct wiphy *wiphy,
  struct ieee80211_regdomain *rd);
 
 /**
+ * regulatory_set_wiphy_regd_sync_rtnl - set regdom for self-managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain information to use for this wiphy
+ *
+ * This functions requires the RTNL to be held and applies the new regdomain
+ * synchronously to this wiphy. For more details see
+ * regulatory_set_wiphy_regd().
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd_sync_rtnl(struct wiphy *wiphy,
+   struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index fde4e17..521f3a4 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -2909,8 +2909,8 @@ int set_regdom(const struct ieee80211_regdomain *rd)
return 0;
 }
 
-int regulatory_set_wiphy_regd(struct wiphy *wiphy,
- struct ieee80211_regdomain *rd)
+static int __regulatory_set_wiphy_regd(struct wiphy *wiphy,
+  struct ieee80211_regdomain *rd)
 {
const struct ieee80211_regdomain *regd;
const struct ieee80211_regdomain *prev_regd;
@@ -2940,12 +2940,39 @@ int regulatory_set_wiphy_regd(struct wiphy *wiphy,
spin_unlock(reg_requests_lock);
 
kfree(prev_regd);
+   return 0;
+}
+
+int regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct ieee80211_regdomain *rd)
+{
+   int ret = __regulatory_set_wiphy_regd(wiphy, rd);
+
+   if (ret)
+   return ret;
 
schedule_work(reg_work);
return 0;
 }
 EXPORT_SYMBOL(regulatory_set_wiphy_regd);
 
+int regulatory_set_wiphy_regd_sync_rtnl(struct wiphy *wiphy,
+   struct ieee80211_regdomain *rd)
+{
+   int ret;
+
+   ASSERT_RTNL();
+
+   ret = __regulatory_set_wiphy_regd(wiphy, rd);
+   if (ret)
+   return ret;
+
+   /* process the request immediately */
+   reg_process_self_managed_hints();
+   return 0;
+}
+EXPORT_SYMBOL(regulatory_set_wiphy_regd_sync_rtnl);
+
 void wiphy_regulatory_register(struct wiphy *wiphy)
 {
struct regulatory_request *lr;
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] cfg80211: fix deadlock during reg chan check

2015-01-07 Thread Arik Nemtsov

 
   Also, the only reason this can happen anyway is when you call can
   beacon for a station interface - which seems nonsensical. Given that
 
  This is not true. This happens with current code for a p2p-go
  interface during channel validity checks in reg.c.
 
  Not sure I see this? The only thing doing wdev locking is
  cfg80211_go_permissive_chan(), no? And that only for station interfaces.

 cfg80211_go_permissive_chan is called from cfg80211_reg_can_beacon,
 currently only for GO interfaces, but for STA also in the future
 (hopefully).
 The latter is called during channel validity checks for GO.

 Ok.

 Should I just apply the patch as it is then?

It fixes a real existing deadlock, so I think so, yea.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/2] cfg80211: avoid reg-hints in self-managed only systems

2015-01-07 Thread Arik Nemtsov
When a system contains only self-managed regulatory devices all hints
from the regulatory core are ignored. Stop hint processing early in this
case. These systems usually don't have CRDA deployed, which results in
endless (irrelevent) logs of the form:
cfg80211: Calling CRDA to update world regulatory domain

Make sure there's at least one self-managed device before discarding a
hint, in order to prevent initial hints from disappearing on CRDA
managed systems.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 net/wireless/reg.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 521f3a4..588e45f 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -2120,6 +2120,26 @@ out_free:
reg_free_request(reg_request);
 }
 
+static bool reg_only_self_managed_wiphys(void)
+{
+   struct cfg80211_registered_device *rdev;
+   struct wiphy *wiphy;
+   bool self_managed_found = false;
+
+   ASSERT_RTNL();
+
+   list_for_each_entry(rdev, cfg80211_rdev_list, list) {
+   wiphy = rdev-wiphy;
+   if (wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED)
+   self_managed_found = true;
+   else
+   return false;
+   }
+
+   /* make sure at least one self-managed wiphy exists */
+   return self_managed_found;
+}
+
 /*
  * Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_*
  * Regulatory hints come on a first come first serve basis and we
@@ -2151,6 +2171,11 @@ static void reg_process_pending_hints(void)
 
spin_unlock(reg_requests_lock);
 
+   if (reg_only_self_managed_wiphys()) {
+   reg_free_request(reg_request);
+   return;
+   }
+
reg_process_hint(reg_request);
 }
 
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] iw: fix android build

2015-01-06 Thread Arik Nemtsov
Don't define iw build target in the regular Makefile which gets
included. This confuses the Android build system (coincides with module
name).

Also correct libnl_2 to a be static library, as compiled on Android.

Signed-off-by: Arik Nemtsov a...@wizery.com
---
 Android.mk | 3 ++-
 Makefile   | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Android.mk b/Android.mk
index 8afda1d..735b236 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,6 +3,7 @@ IW_SOURCE_DIR := $(LOCAL_PATH)
 
 include $(CLEAR_VARS)
 
+IW_ANDROID_BUILD=y
 NO_PKG_CONFIG=y
 include $(LOCAL_PATH)/Makefile
 
@@ -16,7 +17,7 @@ LOCAL_CFLAGS += -DCONFIG_LIBNL20
 LOCAL_LDFLAGS := -Wl,--no-gc-sections
 #LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_TAGS := eng
-LOCAL_SHARED_LIBRARIES := libnl_2
+LOCAL_STATIC_LIBRARIES := libnl_2
 LOCAL_MODULE := iw
 
 $(IW_SOURCE_DIR)/version.c:
diff --git a/Makefile b/Makefile
index 5bf955d..58755dc 100644
--- a/Makefile
+++ b/Makefile
@@ -101,9 +101,11 @@ version.c: version.sh $(patsubst %.o,%.c,$(VERSION_OBJS)) 
nl80211.h iw.h Makefil
@$(NQ) ' CC  ' $@
$(Q)$(CC) $(CFLAGS) -c -o $@ $
 
+ifeq ($(IW_ANDROID_BUILD),)
 iw:$(OBJS)
@$(NQ) ' CC  ' iw
$(Q)$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o iw
+endif
 
 check:
$(Q)$(MAKE) all CC=REAL_CC=$(CC) CHECK=\sparse -Wall\ cgcc
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] iw: don't define iw target in Android build

2015-01-06 Thread Arik Nemtsov
Otherwise Android gets confused and tries to build the Makefile target

Signed-off-by: Arik Nemtsov a...@wizery.com
---
 Android.mk | 1 +
 Makefile   | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/Android.mk b/Android.mk
index 8afda1d..00c8c49 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,6 +3,7 @@ IW_SOURCE_DIR := $(LOCAL_PATH)
 
 include $(CLEAR_VARS)
 
+IW_ANDROID_BUILD=y
 NO_PKG_CONFIG=y
 include $(LOCAL_PATH)/Makefile
 
diff --git a/Makefile b/Makefile
index 5bf955d..58755dc 100644
--- a/Makefile
+++ b/Makefile
@@ -101,9 +101,11 @@ version.c: version.sh $(patsubst %.o,%.c,$(VERSION_OBJS)) 
nl80211.h iw.h Makefil
@$(NQ) ' CC  ' $@
$(Q)$(CC) $(CFLAGS) -c -o $@ $
 
+ifeq ($(IW_ANDROID_BUILD),)
 iw:$(OBJS)
@$(NQ) ' CC  ' iw
$(Q)$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o iw
+endif
 
 check:
$(Q)$(MAKE) all CC=REAL_CC=$(CC) CHECK=\sparse -Wall\ cgcc
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] cfg80211: avoid reg-hints in self-managed only systems

2015-01-06 Thread Arik Nemtsov
On Tue, Jan 6, 2015 at 3:59 PM, Johannes Berg johan...@sipsolutions.net wrote:
 On Tue, 2015-01-06 at 11:56 +0100, Johannes Berg wrote:
 On Thu, 2015-01-01 at 13:42 +0200, Arik Nemtsov wrote:
  When a system contains only self-managed regulatory devices all hints
  from the regulatory core are ignored. Stop hint processing early in this
  case. These systems usually don't have CRDA deployed, which results in
  endless (irrelevent) logs of the form:
  cfg80211: Calling CRDA to update world regulatory domain

 Applied.

 I take that back - dropped again. This was causing spurious messages in
 the hwsim test run VM, saying something like couldn't set reg domain:
 -7. Maybe at that point not a single wiphy existed?

Interesting. I guess I should fix this to only drop the request in
case there's at least one self-managed wiphy.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] mac80211: skip disabled channels in VHT check

2015-01-01 Thread Arik Nemtsov
The patch 40a11ca mac80211: check if channels allow 80 MHz for VHT
probe requests considered disabled channels as VHT enabled, and
mistakenly sent out probe-requests with the VHT IE.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 net/mac80211/util.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 0f9bf47..ad8cb4f 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -1470,10 +1470,12 @@ static int ieee80211_build_preq_ies_band(struct 
ieee80211_local *local,
 
/* Check if any channel in this sband supports at least 80 MHz */
for (i = 0; i  sband-n_channels; i++) {
-   if (!(sband-channels[i].flags  IEEE80211_CHAN_NO_80MHZ)) {
-   have_80mhz = true;
-   break;
-   }
+   if (sband-channels[i].flags  (IEEE80211_CHAN_DISABLED |
+   IEEE80211_CHAN_NO_80MHZ))
+   continue;
+
+   have_80mhz = true;
+   break;
}
 
if (sband-vht_cap.vht_supported  have_80mhz) {
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] mac80211: add TDLS supported channels correctly

2014-12-29 Thread Arik Nemtsov
The function adding the supported channels IE during a TDLS connection had
several issues:
1. If the entire subband is usable, the function exitted the loop without
adding it
2. The function only checked chandef_usable, ignoring flags like RADAR
which would prevent TDLS off-channel communcation.
3. HT20 was explicitly required in the chandef, while not a requirement
for TDLS off-channel.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Emmanuel Grumbach emmanuel.grumb...@intel.com
---
 net/mac80211/tdls.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
index 55ddd77..bd89249 100644
--- a/net/mac80211/tdls.c
+++ b/net/mac80211/tdls.c
@@ -68,12 +68,11 @@ ieee80211_tdls_add_subband(struct ieee80211_sub_if_data 
*sdata,
ch = ieee80211_get_channel(sdata-local-hw.wiphy, i);
if (ch) {
/* we will be active on the channel */
-   u32 flags = IEEE80211_CHAN_DISABLED |
-   IEEE80211_CHAN_NO_IR;
cfg80211_chandef_create(chandef, ch,
-   NL80211_CHAN_HT20);
-   if (cfg80211_chandef_usable(sdata-local-hw.wiphy,
-   chandef, flags)) {
+   NL80211_CHAN_NO_HT);
+   if (cfg80211_reg_can_beacon(sdata-local-hw.wiphy,
+   chandef,
+   sdata-wdev.iftype)) {
ch_cnt++;
continue;
}
@@ -89,6 +88,14 @@ ieee80211_tdls_add_subband(struct ieee80211_sub_if_data 
*sdata,
}
}
 
+   if (ch_cnt) {
+   u8 *pos = skb_put(skb, 2);
+   *pos++ = ieee80211_frequency_to_channel(subband_start);
+   *pos++ = ch_cnt;
+
+   subband_cnt++;
+   }
+
return subband_cnt;
 }
 
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cfg80211: fix deadlock during reg chan check

2014-12-29 Thread Arik Nemtsov
If a P2P GO is active, the cfg80211_reg_can_beacon function will take
the wdev lock, in its call to cfg80211_go_permissive_chan. But the wdev lock
is already taken by the parent channel-checking function, causing a
deadlock.
Split the checking code into two parts. The first part will check if the
wdev is active and saves the channel under the wdev lock. The second part
will check actual channel validity according to type.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Ilan Peer ilan.p...@intel.com
Reviewed-by: Emmanuel Grumbach emmanuel.grumb...@intel.com
---
Requires the patch cfg80211: correctly check ad-hoc channels to be applied
first.

 net/wireless/reg.c | 56 +-
 1 file changed, 34 insertions(+), 22 deletions(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 978a5fd..fde4e17 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1533,45 +1533,40 @@ static void reg_call_notifier(struct wiphy *wiphy,
 
 static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev)
 {
-   struct ieee80211_channel *ch;
struct cfg80211_chan_def chandef;
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
-   bool ret = true;
+   enum nl80211_iftype iftype;
 
wdev_lock(wdev);
+   iftype = wdev-iftype;
 
+   /* make sure the interface is active */
if (!wdev-netdev || !netif_running(wdev-netdev))
-   goto out;
+   goto wdev_inactive_unlock;
 
-   switch (wdev-iftype) {
+   switch (iftype) {
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_P2P_GO:
if (!wdev-beacon_interval)
-   goto out;
-
-   ret = cfg80211_reg_can_beacon(wiphy,
- wdev-chandef, wdev-iftype);
+   goto wdev_inactive_unlock;
+   chandef = wdev-chandef;
break;
case NL80211_IFTYPE_ADHOC:
if (!wdev-ssid_len)
-   goto out;
-
-   ret = cfg80211_reg_can_beacon(wiphy,
- wdev-chandef, wdev-iftype);
+   goto wdev_inactive_unlock;
+   chandef = wdev-chandef;
break;
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
if (!wdev-current_bss ||
!wdev-current_bss-pub.channel)
-   goto out;
+   goto wdev_inactive_unlock;
 
-   ch = wdev-current_bss-pub.channel;
-   if (rdev-ops-get_channel 
-   !rdev_get_channel(rdev, wdev, chandef))
-   ret = cfg80211_chandef_usable(wiphy, chandef,
- IEEE80211_CHAN_DISABLED);
-   else
-   ret = !(ch-flags  IEEE80211_CHAN_DISABLED);
+   if (!rdev-ops-get_channel ||
+   rdev_get_channel(rdev, wdev, chandef))
+   cfg80211_chandef_create(chandef,
+   wdev-current_bss-pub.channel,
+   NL80211_CHAN_NO_HT);
break;
case NL80211_IFTYPE_MONITOR:
case NL80211_IFTYPE_AP_VLAN:
@@ -1584,9 +1579,26 @@ static bool reg_wdev_chan_valid(struct wiphy *wiphy, 
struct wireless_dev *wdev)
break;
}
 
-out:
wdev_unlock(wdev);
-   return ret;
+
+   switch (iftype) {
+   case NL80211_IFTYPE_AP:
+   case NL80211_IFTYPE_P2P_GO:
+   case NL80211_IFTYPE_ADHOC:
+   return cfg80211_reg_can_beacon(wiphy, chandef, iftype);
+   case NL80211_IFTYPE_STATION:
+   case NL80211_IFTYPE_P2P_CLIENT:
+   return cfg80211_chandef_usable(wiphy, chandef,
+  IEEE80211_CHAN_DISABLED);
+   default:
+   break;
+   }
+
+   return true;
+
+wdev_inactive_unlock:
+   wdev_unlock(wdev);
+   return true;
 }
 
 static void reg_leave_invalid_chans(struct wiphy *wiphy)
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] brmc80211: dont use jiffies for BSS TSF

2014-12-23 Thread Arik Nemtsov
On Mon, Dec 22, 2014 at 3:26 PM, Arend van Spriel ar...@broadcom.com wrote:
 On 12/22/14 14:14, Johannes Berg wrote:

 On Mon, 2014-12-22 at 14:13 +0100, Arend van Spriel wrote:

 On 12/22/14 13:58, Johannes Berg wrote:

 By the way - I know now that the proprietary Broadcom driver has the
 same bug, to the point where this is apparently getting encoded into the
 Android framework.

 I urge you to fix this issue there as well. If an absolute last
 updated timestamp is needed (and last seen [ms] ago isn't sufficient)
 then new API will be needed.


 Sorry, seem to have missed the original patches somehow. Guess because
 it says *brmc*80211.


 No no - it's a looong time ago and was also applied a long time ago. It
 just reared it's head again in another place.


 Found the commit in git log. So you mean the proprietary DHD driver or
 Android bcmdhd still uses host timestamp. I agree it should be fixed, but I
 may need some good arguments to convince my co-workers. So what kind of
 issues are rearing their (ugly) heads? supplicant issues?

Basically the Android framework is using the TSF from the scan results
as a timestamp for when the BSS was seen. In Android LL a new CTS test
was added to verify these values.
This of course means the CTS test fails for every vendor besides BRCM :)

It seems the framework knows it's a driver bug, since in the java code
they explicitly name the variable tsf, before assigning it to the
scan result timestamp..

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] nl80211: increase the max number of rules in regdomain

2014-12-18 Thread Arik Nemtsov
On Thu, Dec 18, 2014 at 3:56 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Wed, 2014-12-17 at 18:00 +0200, Arik Nemtsov wrote:
 Some network cards (Intel) produce per-channel regdomains and rely on
 cfg80211 to merge rules as needed. This hits the max rules limit and
 fails.

 Maybe we should consider just getting rid of this or bumping it to
 something ridiculously large like 1000? Looking at how this is (not)
 used, there's no real sense in limiting it. The only possible problem is
 the O(n^2) complexity when doing an intersection, but processing a
 million combinations is probably not a big deal? In fact, even if that
 becomes a problem, we can easily optimise that complexity away by
 sorting the rules or so. Then it becomes O(n log n)...

Well when someone does NL80211_CMD_GET_REG from usermode, we send the
entire regdom in a single message, so 1000 rules may become
problematic..

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] nl80211: increase the max number of rules in regdomain

2014-12-17 Thread Arik Nemtsov
Some network cards (Intel) produce per-channel regdomains and rely on
cfg80211 to merge rules as needed. This hits the max rules limit and
fails.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 include/uapi/linux/nl80211.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index c0383e9..18cb0aa 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -2112,7 +2112,7 @@ enum nl80211_attrs {
 
 #define NL80211_MAX_SUPP_RATES 32
 #define NL80211_MAX_SUPP_HT_RATES  77
-#define NL80211_MAX_SUPP_REG_RULES 32
+#define NL80211_MAX_SUPP_REG_RULES 64
 #define NL80211_TKIP_DATA_OFFSET_ENCR_KEY  0
 #define NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY16
 #define NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY24
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] iw: support multiple regdom print

2014-12-15 Thread Arik Nemtsov
When a phy is given, print only its regdomain. Otherwise, use the newly
implement dump functionality to print all regdomains in the system.

Signed-off-by: Arik Nemtsov a...@wizery.com
---
v2: fix reg get for older kernels

 reg.c | 40 
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/reg.c b/reg.c
index a02c982..0aef7ba 100644
--- a/reg.c
+++ b/reg.c
@@ -114,7 +114,6 @@ COMMAND(reg, set, ISO/IEC 3166-1 alpha2,
Notify the kernel about the current regulatory domain.);
 
 static int print_reg_handler(struct nl_msg *msg, void *arg)
-
 {
 #define PARSE_FLAG(nl_flag, string_value)  do { \
if ((flags  nl_flag)) { \
@@ -150,6 +149,13 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
return NL_SKIP;
}
 
+   if (tb_msg[NL80211_ATTR_WIPHY])
+   printf(phy#%d%s\n, nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]),
+  tb_msg[NL80211_ATTR_WIPHY_SELF_MANAGED_REG] ?
+   (self-managed) : );
+   else
+   printf(global\n);
+
if (tb_msg[NL80211_ATTR_DFS_REGION])
dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
else
@@ -216,18 +222,44 @@ static int print_reg_handler(struct nl_msg *msg, void 
*arg)
 
printf(\n);
}
-   return NL_OK;
+
+   printf(\n);
+   return NL_SKIP;
 #undef PARSE_FLAG
 }
 
+static int handle_reg_dump(struct nl80211_state *state,
+  struct nl_cb *cb,
+  struct nl_msg *msg,
+  int argc, char **argv,
+  enum id_input id)
+{
+   nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_reg_handler, NULL);
+   return 0;
+}
+
 static int handle_reg_get(struct nl80211_state *state,
  struct nl_cb *cb,
  struct nl_msg *msg,
  int argc, char **argv,
  enum id_input id)
 {
-   nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_reg_handler, NULL);
-   return 0;
+   char *dump_args[] = { reg, dump };
+   int err;
+
+   err = handle_cmd(state, CIB_NONE, 2, dump_args);
+   /* dump might fail since it's not supported on older kernels */
+   if (err == -EOPNOTSUPP) {
+   nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_reg_handler,
+ NULL);
+   return 0;
+   }
+
+   return err;
 }
 COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_NONE, handle_reg_get,
Print out the kernel's current regulatory domain information.);
+COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_PHY, handle_reg_get,
+   Print out the devices' current regulatory domain information.);
+HIDDEN(reg, dump, NULL, NL80211_CMD_GET_REG, NLM_F_DUMP, CIB_NONE,
+   handle_reg_dump);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8 1/4] cfg80211: allow usermode to query wiphy specific regdom

2014-12-15 Thread Arik Nemtsov
On Fri, Dec 12, 2014 at 2:37 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Wed, 2014-12-03 at 18:08 +0200, Arik Nemtsov wrote:

   * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
 - *   regulatory domain.
 + *   regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
 + *   has a private regulatory domain, it will be returned. Otherwise, the
 + *   global regdomain will be returned.
 + *   A device will have a private regulatory domain if it uses the
 + *   regulatory_hint() API. Even when a private regdomain is used the 
 channel
 + *   information will still be mended according to further hints from
 + *   the regulatory core to help with compliance.

 I think you need to document the new availability of the dump version of
 this now.

Sure.


 + if (!regdom  !cfg80211_regdomain) {

 I'm not sure why sparse doesn't warn here, but I think that should
 probably use rcu_access_pointer(cfg80211_regdomain).

 More realistically, the regdomain can never be NULL I think, so is that
 even needed? OTOH, if it can be NULL, then you must make this check
 after the rcu_dereference, which would make this code easier to follow.

You're right. I'll remove the check. I don't see a way where it can be
set to NULL at any point.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8 2/4] cfg80211: allow wiphy specific regdomain management

2014-12-15 Thread Arik Nemtsov
On Fri, Dec 12, 2014 at 2:39 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Wed, 2014-12-03 at 18:08 +0200, Arik Nemtsov wrote:

 +void nl80211_send_reg_change_event(struct regulatory_request *request)
 +{
 + nl80211_common_reg_change_event(NL80211_CMD_REG_CHANGE, request);
 +}
 +
 +void nl80211_send_wiphy_reg_change_event(struct regulatory_request *request)
 +{
 + nl80211_common_reg_change_event(NL80211_CMD_WIPHY_REG_CHANGE, request);
 +}

 These are trivial wrappers, I'd make them inlines.

You mean inline here or in the header header? I'll do it here..

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 1/4] cfg80211: allow usermode to query wiphy specific regdom

2014-12-15 Thread Arik Nemtsov
If a wiphy-idx is specified, the kernel will return the wiphy specific
regdomain, if such exists. Otherwise return the global regdom.

When no wiphy-idx is specified, return the global regdomain as well as
all wiphy-specific regulatory domains in the system, via a new nested
list of attributes.

Add a new attribute for each wiphy-specific regdomain, for usermode to
identify it as such.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 include/uapi/linux/nl80211.h |  10 ++-
 net/wireless/nl80211.c   | 173 ++-
 net/wireless/reg.c   |   2 +-
 net/wireless/reg.h   |   1 +
 4 files changed, 151 insertions(+), 35 deletions(-)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index b37bd5a..2d384d0 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -252,7 +252,15 @@
  * %NL80211_ATTR_IFINDEX.
  *
  * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
- * regulatory domain.
+ * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
+ * has a private regulatory domain, it will be returned. Otherwise, the
+ * global regdomain will be returned.
+ * A device will have a private regulatory domain if it uses the
+ * regulatory_hint() API. Even when a private regdomain is used the channel
+ * information will still be mended according to further hints from
+ * the regulatory core to help with compliance. A dump version of this API
+ * is now available which will returns the global regdomain as well as
+ * all private regdomains of present wiphys (for those that have it).
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index a17d6bc..2d5dc42 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5327,42 +5327,20 @@ static int nl80211_update_mesh_config(struct sk_buff 
*skb,
return err;
 }
 
-static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
+static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
+ struct sk_buff *msg)
 {
-   const struct ieee80211_regdomain *regdom;
-   struct sk_buff *msg;
-   void *hdr = NULL;
struct nlattr *nl_reg_rules;
unsigned int i;
 
-   if (!cfg80211_regdomain)
-   return -EINVAL;
-
-   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
-   if (!msg)
-   return -ENOBUFS;
-
-   hdr = nl80211hdr_put(msg, info-snd_portid, info-snd_seq, 0,
-NL80211_CMD_GET_REG);
-   if (!hdr)
-   goto put_failure;
-
-   if (reg_last_request_cell_base() 
-   nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
-   NL80211_USER_REG_HINT_CELL_BASE))
-   goto nla_put_failure;
-
-   rcu_read_lock();
-   regdom = rcu_dereference(cfg80211_regdomain);
-
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom-alpha2) ||
(regdom-dfs_region 
 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom-dfs_region)))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
if (!nl_reg_rules)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
for (i = 0; i  regdom-n_reg_rules; i++) {
struct nlattr *nl_reg_rule;
@@ -5377,7 +5355,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
 
nl_reg_rule = nla_nest_start(msg, i);
if (!nl_reg_rule)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
max_bandwidth_khz = freq_range-max_bandwidth_khz;
if (!max_bandwidth_khz)
@@ -5398,13 +5376,64 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
power_rule-max_eirp) ||
nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
reg_rule-dfs_cac_ms))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nla_nest_end(msg, nl_reg_rule);
}
-   rcu_read_unlock();
 
nla_nest_end(msg, nl_reg_rules);
+   return 0;
+
+nla_put_failure:
+   return -EMSGSIZE;
+}
+
+static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
+{
+   const struct ieee80211_regdomain *regdom = NULL;
+   struct cfg80211_registered_device *rdev;
+   struct wiphy *wiphy = NULL;
+   struct sk_buff *msg;
+   void *hdr;
+
+   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL

[PATCH v9 3/4] cfg80211: return private regdom for self-managed devices

2014-12-15 Thread Arik Nemtsov
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 arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/uapi/linux/nl80211.h | 10 ++
 net/wireless/nl80211.c   | 24 
 2 files changed, 34 insertions(+)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index fb58e65..b3ada0b 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -261,6 +261,9 @@
  * the regulatory core to help with compliance. A dump version of this API
  * is now available which will returns the global regdomain as well as
  * all private regdomains of present wiphys (for those that have it).
+ * If a wiphy is self-managed (%NL80211_ATTR_WIPHY_SELF_MANAGED_REG), then
+ * its private regdomain is the only valid one for it. The regulatory
+ * core is not used to help with compliance in this case.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
@@ -1702,6 +1705,11 @@ enum nl80211_commands {
  *
  * @NL80211_ATTR_MAC_MASK: MAC address mask
  *
+ * @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
@@ -2059,6 +2067,8 @@ enum nl80211_attrs {
 
NL80211_ATTR_MAC_MASK,
 
+   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 c04a934..3d972c2 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -396,6 +396,7 @@ static const struct nla_policy 
nl80211_policy[NUM_NL80211_ATTR] = {
[NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
[NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
[NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
+   [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
 };
 
 /* policy for the key attributes */
@@ -1701,6 +1702,10 @@ static int nl80211_send_wiphy(struct 
cfg80211_registered_device *rdev,
   rdev-wiphy.max_num_csa_counters))
goto nla_put_failure;
 
+   if (rdev-wiphy.regulatory_flags  
REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
/* done */
state-split_start = 0;
break;
@@ -5406,6 +5411,8 @@ static int nl80211_get_reg_do(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);
@@ -5413,8 +5420,16 @@ static int nl80211_get_reg_do(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);
 
+   /* a self-managed-reg device must have a private regdom */
+   if (WARN_ON(!regdom  self_managed)) {
+   nlmsg_free(msg);
+   return -EINVAL;
+   }
+
if (regdom 
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
@@ -5471,6 +5486,10 @@ static int nl80211_send_regdom(struct sk_buff *msg, 
struct netlink_callback *cb,
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
 
+   if (wiphy  wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
return genlmsg_end(msg, hdr);
 
 nla_put_failure:
@@ -11076,6 +11095,11 @@ static bool nl80211_reg_change_event_fill(struct 
sk_buff *msg,
if (wiphy 
nla_put_u32(msg, NL80211_ATTR_WIPHY, request-wiphy_idx))
goto nla_put_failure;
+
+   if (wiphy

[PATCH v9 4/4] cfg80211: avoid intersection when applying self-managed reg

2014-12-15 Thread Arik Nemtsov
The custom-reg handling function can currently only add flags to a given
channel. This results in stale flags being left applied. In some cases
a channel was disabled and even the orig_flags were changed to reflect
this.

Previously the API was designed for a single invocation before wiphy
registration, so this didn't matter. The previous approach doesn't scale
well to self-managed regulatory devices, particularly when a more
permissive regdom is applied after a restrictive one.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 net/wireless/reg.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 87ef745..8aaff02 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1686,8 +1686,12 @@ static void handle_channel_custom(struct wiphy *wiphy,
if (IS_ERR(reg_rule)) {
REG_DBG_PRINT(Disabling freq %d MHz as custom regd has no rule 
that fits it\n,
  chan-center_freq);
-   chan-orig_flags |= IEEE80211_CHAN_DISABLED;
-   chan-flags = chan-orig_flags;
+   if (wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED) {
+   chan-flags |= IEEE80211_CHAN_DISABLED;
+   } else {
+   chan-orig_flags |= IEEE80211_CHAN_DISABLED;
+   chan-flags = chan-orig_flags;
+   }
return;
}
 
@@ -1712,7 +1716,13 @@ static void handle_channel_custom(struct wiphy *wiphy,
chan-dfs_state = NL80211_DFS_USABLE;
 
chan-beacon_found = false;
-   chan-flags |= map_regdom_flags(reg_rule-flags) | bw_flags;
+
+   if (wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED)
+   chan-flags = chan-orig_flags | bw_flags |
+ map_regdom_flags(reg_rule-flags);
+   else
+   chan-flags |= map_regdom_flags(reg_rule-flags) | bw_flags;
+
chan-max_antenna_gain = (int) MBI_TO_DBI(power_rule-max_antenna_gain);
chan-max_reg_power = chan-max_power =
(int) MBM_TO_DBM(power_rule-max_eirp);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 2/4] cfg80211: allow wiphy specific regdomain management

2014-12-15 Thread Arik Nemtsov
From: Jonathan Doron j...@wizery.com

Add a new regulatory flag that allows a driver to manage regdomain
changes/updates for its own wiphy.
A self-managed wiphys only employs regulatory information obtained from
the FW and driver and does not use other cfg80211 sources like
beacon-hints, country-code IEs and hints from other devices on the same
system. Conversely, a self-managed wiphy does not share its regulatory
hints with other devices in the system. If a system contains several
devices, one or more of which are self-managed, there might be
contradictory regulatory settings between them. Usage of flag is
generally discouraged. Only use it if the FW/driver is incompatible
with non-locally originated hints.

A new API lets the driver send a complete regdomain, to be applied on
its wiphy only.

After a wiphy-specific regdomain change takes place, usermode will get
a new type of change notification. The regulatory core also takes care
enforce regulatory restrictions, in case some interfaces are on
forbidden channels.

Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/net/cfg80211.h   | 14 +++
 include/net/regulatory.h | 19 ++
 include/uapi/linux/nl80211.h |  6 +++
 net/wireless/core.c  |  8 
 net/wireless/core.h  |  7 
 net/wireless/nl80211.c   | 60 +-
 net/wireless/nl80211.h   |  1 +
 net/wireless/reg.c   | 88 
 8 files changed, 185 insertions(+), 18 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 4ebb816..4bc1fc9 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -3808,6 +3808,20 @@ const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 
oui_type,
 int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
 
 /**
+ * regulatory_set_wiphy_regd - set regdom info for self managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain informatoin to use for this wiphy
+ *
+ * Set the regulatory domain information for self-managed wiphys, only they
+ * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
+ * information.
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index b776d72..ebc5a2e 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -147,6 +147,24 @@ struct regulatory_request {
  * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
  * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
  * includes any modes unsupported for enforcement checking.
+ * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
+ * regdom management. These devices will ignore all regdom changes not
+ * originating from their own wiphy.
+ * A self-managed wiphys only employs regulatory information obtained from
+ * the FW and driver and does not use other cfg80211 sources like
+ * beacon-hints, country-code IEs and hints from other devices on the same
+ * system. Conversely, a self-managed wiphy does not share its regulatory
+ * hints with other devices in the system. If a system contains several
+ * devices, one or more of which are self-managed, there might be
+ * contradictory regulatory settings between them. Usage of flag is
+ * generally discouraged. Only use it if the FW/driver is incompatible
+ * with non-locally originated hints.
+ * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
+ * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER,
+ * %REGULATORY_COUNTRY_IE_IGNORE and %REGULATORY_DISABLE_BEACON_HINTS.
+ * Mixing any of the above flags with this flag will result in a failure
+ * to register the wiphy. This flag implies
+ * %REGULATORY_DISABLE_BEACON_HINTS and %REGULATORY_COUNTRY_IE_IGNORE.
  */
 enum ieee80211_regulatory_flags {
REGULATORY_CUSTOM_REG   = BIT(0),
@@ -156,6 +174,7 @@ enum ieee80211_regulatory_flags {
REGULATORY_COUNTRY_IE_IGNORE= BIT(4),
REGULATORY_ENABLE_RELAX_NO_IR   = BIT(5),
REGULATORY_IGNORE_STALE_KICKOFF = BIT(6),
+   REGULATORY_WIPHY_SELF_MANAGED   = BIT(7),
 };
 
 struct ieee80211_freq_range {
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 2d384d0..fb58e65 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -782,6

[PATCH v10 1/4] cfg80211: allow usermode to query wiphy specific regdom

2014-12-15 Thread Arik Nemtsov
If a wiphy-idx is specified, the kernel will return the wiphy specific
regdomain, if such exists. Otherwise return the global regdom.

When no wiphy-idx is specified, return the global regdomain as well as
all wiphy-specific regulatory domains in the system, via a new nested
list of attributes.

Add a new attribute for each wiphy-specific regdomain, for usermode to
identify it as such.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 include/uapi/linux/nl80211.h |  10 ++-
 net/wireless/nl80211.c   | 173 ++-
 net/wireless/reg.c   |   2 +-
 net/wireless/reg.h   |   1 +
 4 files changed, 151 insertions(+), 35 deletions(-)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index b37bd5a..2d384d0 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -252,7 +252,15 @@
  * %NL80211_ATTR_IFINDEX.
  *
  * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
- * regulatory domain.
+ * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
+ * has a private regulatory domain, it will be returned. Otherwise, the
+ * global regdomain will be returned.
+ * A device will have a private regulatory domain if it uses the
+ * regulatory_hint() API. Even when a private regdomain is used the channel
+ * information will still be mended according to further hints from
+ * the regulatory core to help with compliance. A dump version of this API
+ * is now available which will returns the global regdomain as well as
+ * all private regdomains of present wiphys (for those that have it).
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index a17d6bc..2d5dc42 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5327,42 +5327,20 @@ static int nl80211_update_mesh_config(struct sk_buff 
*skb,
return err;
 }
 
-static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
+static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
+ struct sk_buff *msg)
 {
-   const struct ieee80211_regdomain *regdom;
-   struct sk_buff *msg;
-   void *hdr = NULL;
struct nlattr *nl_reg_rules;
unsigned int i;
 
-   if (!cfg80211_regdomain)
-   return -EINVAL;
-
-   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
-   if (!msg)
-   return -ENOBUFS;
-
-   hdr = nl80211hdr_put(msg, info-snd_portid, info-snd_seq, 0,
-NL80211_CMD_GET_REG);
-   if (!hdr)
-   goto put_failure;
-
-   if (reg_last_request_cell_base() 
-   nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
-   NL80211_USER_REG_HINT_CELL_BASE))
-   goto nla_put_failure;
-
-   rcu_read_lock();
-   regdom = rcu_dereference(cfg80211_regdomain);
-
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom-alpha2) ||
(regdom-dfs_region 
 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom-dfs_region)))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
if (!nl_reg_rules)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
for (i = 0; i  regdom-n_reg_rules; i++) {
struct nlattr *nl_reg_rule;
@@ -5377,7 +5355,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
 
nl_reg_rule = nla_nest_start(msg, i);
if (!nl_reg_rule)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
max_bandwidth_khz = freq_range-max_bandwidth_khz;
if (!max_bandwidth_khz)
@@ -5398,13 +5376,64 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
power_rule-max_eirp) ||
nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
reg_rule-dfs_cac_ms))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nla_nest_end(msg, nl_reg_rule);
}
-   rcu_read_unlock();
 
nla_nest_end(msg, nl_reg_rules);
+   return 0;
+
+nla_put_failure:
+   return -EMSGSIZE;
+}
+
+static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
+{
+   const struct ieee80211_regdomain *regdom = NULL;
+   struct cfg80211_registered_device *rdev;
+   struct wiphy *wiphy = NULL;
+   struct sk_buff *msg;
+   void *hdr;
+
+   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL

[PATCH v10 4/4] cfg80211: avoid intersection when applying self-managed reg

2014-12-15 Thread Arik Nemtsov
The custom-reg handling function can currently only add flags to a given
channel. This results in stale flags being left applied. In some cases
a channel was disabled and even the orig_flags were changed to reflect
this.

Previously the API was designed for a single invocation before wiphy
registration, so this didn't matter. The previous approach doesn't scale
well to self-managed regulatory devices, particularly when a more
permissive regdom is applied after a restrictive one.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 net/wireless/reg.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 87ef745..8aaff02 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1686,8 +1686,12 @@ static void handle_channel_custom(struct wiphy *wiphy,
if (IS_ERR(reg_rule)) {
REG_DBG_PRINT(Disabling freq %d MHz as custom regd has no rule 
that fits it\n,
  chan-center_freq);
-   chan-orig_flags |= IEEE80211_CHAN_DISABLED;
-   chan-flags = chan-orig_flags;
+   if (wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED) {
+   chan-flags |= IEEE80211_CHAN_DISABLED;
+   } else {
+   chan-orig_flags |= IEEE80211_CHAN_DISABLED;
+   chan-flags = chan-orig_flags;
+   }
return;
}
 
@@ -1712,7 +1716,13 @@ static void handle_channel_custom(struct wiphy *wiphy,
chan-dfs_state = NL80211_DFS_USABLE;
 
chan-beacon_found = false;
-   chan-flags |= map_regdom_flags(reg_rule-flags) | bw_flags;
+
+   if (wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED)
+   chan-flags = chan-orig_flags | bw_flags |
+ map_regdom_flags(reg_rule-flags);
+   else
+   chan-flags |= map_regdom_flags(reg_rule-flags) | bw_flags;
+
chan-max_antenna_gain = (int) MBI_TO_DBI(power_rule-max_antenna_gain);
chan-max_reg_power = chan-max_power =
(int) MBM_TO_DBM(power_rule-max_eirp);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 3/4] cfg80211: return private regdom for self-managed devices

2014-12-15 Thread Arik Nemtsov
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 arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/uapi/linux/nl80211.h | 10 ++
 net/wireless/nl80211.c   | 24 
 2 files changed, 34 insertions(+)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index fb58e65..b3ada0b 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -261,6 +261,9 @@
  * the regulatory core to help with compliance. A dump version of this API
  * is now available which will returns the global regdomain as well as
  * all private regdomains of present wiphys (for those that have it).
+ * If a wiphy is self-managed (%NL80211_ATTR_WIPHY_SELF_MANAGED_REG), then
+ * its private regdomain is the only valid one for it. The regulatory
+ * core is not used to help with compliance in this case.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
@@ -1702,6 +1705,11 @@ enum nl80211_commands {
  *
  * @NL80211_ATTR_MAC_MASK: MAC address mask
  *
+ * @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
@@ -2059,6 +2067,8 @@ enum nl80211_attrs {
 
NL80211_ATTR_MAC_MASK,
 
+   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 eebb7e4..5b1907f 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -396,6 +396,7 @@ static const struct nla_policy 
nl80211_policy[NUM_NL80211_ATTR] = {
[NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
[NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
[NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
+   [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
 };
 
 /* policy for the key attributes */
@@ -1701,6 +1702,10 @@ static int nl80211_send_wiphy(struct 
cfg80211_registered_device *rdev,
   rdev-wiphy.max_num_csa_counters))
goto nla_put_failure;
 
+   if (rdev-wiphy.regulatory_flags  
REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
/* done */
state-split_start = 0;
break;
@@ -5406,6 +5411,8 @@ static int nl80211_get_reg_do(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);
@@ -5413,8 +5420,16 @@ static int nl80211_get_reg_do(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);
 
+   /* a self-managed-reg device must have a private regdom */
+   if (WARN_ON(!regdom  self_managed)) {
+   nlmsg_free(msg);
+   return -EINVAL;
+   }
+
if (regdom 
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
@@ -5471,6 +5486,10 @@ static int nl80211_send_regdom(struct sk_buff *msg, 
struct netlink_callback *cb,
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
 
+   if (wiphy  wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
return genlmsg_end(msg, hdr);
 
 nla_put_failure:
@@ -11076,6 +11095,11 @@ static bool nl80211_reg_change_event_fill(struct 
sk_buff *msg,
if (wiphy 
nla_put_u32(msg, NL80211_ATTR_WIPHY, request-wiphy_idx))
goto nla_put_failure;
+
+   if (wiphy

[PATCH v10 2/4] cfg80211: allow wiphy specific regdomain management

2014-12-15 Thread Arik Nemtsov
From: Jonathan Doron j...@wizery.com

Add a new regulatory flag that allows a driver to manage regdomain
changes/updates for its own wiphy.
A self-managed wiphys only employs regulatory information obtained from
the FW and driver and does not use other cfg80211 sources like
beacon-hints, country-code IEs and hints from other devices on the same
system. Conversely, a self-managed wiphy does not share its regulatory
hints with other devices in the system. If a system contains several
devices, one or more of which are self-managed, there might be
contradictory regulatory settings between them. Usage of flag is
generally discouraged. Only use it if the FW/driver is incompatible
with non-locally originated hints.

A new API lets the driver send a complete regdomain, to be applied on
its wiphy only.

After a wiphy-specific regdomain change takes place, usermode will get
a new type of change notification. The regulatory core also takes care
enforce regulatory restrictions, in case some interfaces are on
forbidden channels.

Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
v10: making the functions inline in the header ;)

 include/net/cfg80211.h   | 14 +++
 include/net/regulatory.h | 19 ++
 include/uapi/linux/nl80211.h |  6 +++
 net/wireless/core.c  |  8 
 net/wireless/core.h  |  7 
 net/wireless/nl80211.c   | 49 +++-
 net/wireless/nl80211.h   | 16 +++-
 net/wireless/reg.c   | 88 
 8 files changed, 188 insertions(+), 19 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 4ebb816..4bc1fc9 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -3808,6 +3808,20 @@ const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 
oui_type,
 int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
 
 /**
+ * regulatory_set_wiphy_regd - set regdom info for self managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain informatoin to use for this wiphy
+ *
+ * Set the regulatory domain information for self-managed wiphys, only they
+ * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
+ * information.
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index b776d72..ebc5a2e 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -147,6 +147,24 @@ struct regulatory_request {
  * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
  * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
  * includes any modes unsupported for enforcement checking.
+ * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
+ * regdom management. These devices will ignore all regdom changes not
+ * originating from their own wiphy.
+ * A self-managed wiphys only employs regulatory information obtained from
+ * the FW and driver and does not use other cfg80211 sources like
+ * beacon-hints, country-code IEs and hints from other devices on the same
+ * system. Conversely, a self-managed wiphy does not share its regulatory
+ * hints with other devices in the system. If a system contains several
+ * devices, one or more of which are self-managed, there might be
+ * contradictory regulatory settings between them. Usage of flag is
+ * generally discouraged. Only use it if the FW/driver is incompatible
+ * with non-locally originated hints.
+ * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
+ * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER,
+ * %REGULATORY_COUNTRY_IE_IGNORE and %REGULATORY_DISABLE_BEACON_HINTS.
+ * Mixing any of the above flags with this flag will result in a failure
+ * to register the wiphy. This flag implies
+ * %REGULATORY_DISABLE_BEACON_HINTS and %REGULATORY_COUNTRY_IE_IGNORE.
  */
 enum ieee80211_regulatory_flags {
REGULATORY_CUSTOM_REG   = BIT(0),
@@ -156,6 +174,7 @@ enum ieee80211_regulatory_flags {
REGULATORY_COUNTRY_IE_IGNORE= BIT(4),
REGULATORY_ENABLE_RELAX_NO_IR   = BIT(5),
REGULATORY_IGNORE_STALE_KICKOFF = BIT(6),
+   REGULATORY_WIPHY_SELF_MANAGED   = BIT(7),
 };
 
 struct ieee80211_freq_range {
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 2d384d0..fb58e65 100644
--- a/include/uapi/linux/nl80211.h

Re: [PATCH] cfg80211: avoid intersection when applying custom reg

2014-12-14 Thread Arik Nemtsov
On Fri, Dec 12, 2014 at 2:41 PM, Johannes Berg
johan...@sipsolutions.net wrote:

 On Sun, 2014-12-07 at 18:03 +0200, Arik Nemtsov wrote:
  The custom-reg handling function can currently only add flags to a given
  channel. This results in stale flags being left applied. In some cases
  a channel was disabled and even the orig_flags were changed to reflect
  this.
 
  Previously the API was designed for a single invocation before wiphy
  registration, so this didn't matter. The previous approach doesn't scale
  well to self-managed regulatory devices, particularly when a more
  permissive regdom is applied after a restrictive one.

 This description (not the patch) only makes sense after the other series
 with self-managed, please resend it in the self-managed patchset.

Sure. I'll also make it self-managed only, so avoid possible
regressions, as Luis commented.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cfg80211: avoid intersection when applying custom reg

2014-12-07 Thread Arik Nemtsov
The custom-reg handling function can currently only add flags to a given
channel. This results in stale flags being left applied. In some cases
a channel was disabled and even the orig_flags were changed to reflect
this.

Previously the API was designed for a single invocation before wiphy
registration, so this didn't matter. The previous approach doesn't scale
well to self-managed regulatory devices, particularly when a more
permissive regdom is applied after a restrictive one.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 net/wireless/reg.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 8941e1c..e4f4619 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1686,8 +1686,7 @@ static void handle_channel_custom(struct wiphy *wiphy,
if (IS_ERR(reg_rule)) {
REG_DBG_PRINT(Disabling freq %d MHz as custom regd has no rule 
that fits it\n,
  chan-center_freq);
-   chan-orig_flags |= IEEE80211_CHAN_DISABLED;
-   chan-flags = chan-orig_flags;
+   chan-flags |= IEEE80211_CHAN_DISABLED;
return;
}
 
@@ -1712,7 +1711,7 @@ static void handle_channel_custom(struct wiphy *wiphy,
chan-dfs_state = NL80211_DFS_USABLE;
 
chan-beacon_found = false;
-   chan-flags |= map_regdom_flags(reg_rule-flags) | bw_flags;
+   chan-flags = map_regdom_flags(reg_rule-flags) | bw_flags;
chan-max_antenna_gain = (int) MBI_TO_DBI(power_rule-max_antenna_gain);
chan-max_reg_power = chan-max_power =
(int) MBM_TO_DBM(power_rule-max_eirp);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cfg80211: avoid mem leak on driver hint set

2014-12-04 Thread Arik Nemtsov
In the already-set and intersect case of a driver-hint, the previous
wiphy regdomain was not freed before being reset with a copy of the
cfg80211 regdomain.

Cc: sta...@vger.kernel.org
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 net/wireless/reg.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 004ea14..8941e1c 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1916,7 +1916,7 @@ static enum reg_request_treatment
 reg_process_hint_driver(struct wiphy *wiphy,
struct regulatory_request *driver_request)
 {
-   const struct ieee80211_regdomain *regd;
+   const struct ieee80211_regdomain *regd, *tmp;
enum reg_request_treatment treatment;
 
treatment = __reg_process_hint_driver(driver_request);
@@ -1936,7 +1936,10 @@ reg_process_hint_driver(struct wiphy *wiphy,
reg_free_request(driver_request);
return REG_REQ_IGNORE;
}
+
+   tmp = get_wiphy_regdom(wiphy);
rcu_assign_pointer(wiphy-regd, regd);
+   rcu_free_regdom(tmp);
}
 
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 3/4] cfg80211: return private regdom for self-managed devices

2014-12-03 Thread Arik Nemtsov
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 arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
v8: no need to add more splits to the wiphy info

 include/uapi/linux/nl80211.h | 10 ++
 net/wireless/nl80211.c   | 24 
 2 files changed, 34 insertions(+)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 9ee06de..5a13958 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -259,6 +259,9 @@
  * regulatory_hint() API. Even when a private regdomain is used the channel
  * information will still be mended according to further hints from
  * the regulatory core to help with compliance.
+ * If a wiphy is self-managed (%NL80211_ATTR_WIPHY_SELF_MANAGED_REG), then
+ * its private regdomain is the only valid one for it. The regulatory
+ * core is not used to help with compliance in this case.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
@@ -1700,6 +1703,11 @@ enum nl80211_commands {
  *
  * @NL80211_ATTR_MAC_MASK: MAC address mask
  *
+ * @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
@@ -2057,6 +2065,8 @@ enum nl80211_attrs {
 
NL80211_ATTR_MAC_MASK,
 
+   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 de523aa..cd85a9f 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -396,6 +396,7 @@ static const struct nla_policy 
nl80211_policy[NUM_NL80211_ATTR] = {
[NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
[NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
[NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
+   [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
 };
 
 /* policy for the key attributes */
@@ -1701,6 +1702,10 @@ static int nl80211_send_wiphy(struct 
cfg80211_registered_device *rdev,
   rdev-wiphy.max_num_csa_counters))
goto nla_put_failure;
 
+   if (rdev-wiphy.regulatory_flags  
REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
/* done */
state-split_start = 0;
break;
@@ -5406,6 +5411,8 @@ static int nl80211_get_reg_do(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);
@@ -5413,8 +5420,16 @@ static int nl80211_get_reg_do(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);
 
+   /* a self-managed-reg device must have a private regdom */
+   if (WARN_ON(!regdom  self_managed)) {
+   nlmsg_free(msg);
+   return -EINVAL;
+   }
+
if (regdom 
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
@@ -5476,6 +5491,10 @@ static int nl80211_send_regdom(struct sk_buff *msg, 
struct netlink_callback *cb,
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
 
+   if (wiphy  wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
return genlmsg_end(msg, hdr);
 
 nla_put_failure:
@@ -11081,6 +11100,11 @@ static bool nl80211_reg_change_event_fill(struct 
sk_buff *msg,
if (wiphy 
nla_put_u32(msg, NL80211_ATTR_WIPHY, request-wiphy_idx))
goto nla_put_failure

[PATCH v8 2/4] cfg80211: allow wiphy specific regdomain management

2014-12-03 Thread Arik Nemtsov
From: Jonathan Doron j...@wizery.com

Add a new regulatory flag that allows a driver to manage regdomain
changes/updates for its own wiphy.
A self-managed wiphys only employs regulatory information obtained from
the FW and driver and does not use other cfg80211 sources like
beacon-hints, country-code IEs and hints from other devices on the same
system. Conversely, a self-managed wiphy does not share its regulatory
hints with other devices in the system. If a system contains several
devices, one or more of which are self-managed, there might be
contradictory regulatory settings between them. Usage of flag is
generally discouraged. Only use it if the FW/driver is incompatible
with non-locally originated hints.

A new API lets the driver send a complete regdomain, to be applied on
its wiphy only.

After a wiphy-specific regdomain change takes place, usermode will get
a new type of change notification. The regulatory core also takes care
enforce regulatory restrictions, in case some interfaces are on
forbidden channels.

Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/net/cfg80211.h   | 14 +++
 include/net/regulatory.h | 19 ++
 include/uapi/linux/nl80211.h |  6 +++
 net/wireless/core.c  |  8 
 net/wireless/core.h  |  7 
 net/wireless/nl80211.c   | 59 -
 net/wireless/nl80211.h   |  1 +
 net/wireless/reg.c   | 88 
 8 files changed, 184 insertions(+), 18 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 4ebb816..4bc1fc9 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -3808,6 +3808,20 @@ const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 
oui_type,
 int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
 
 /**
+ * regulatory_set_wiphy_regd - set regdom info for self managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain informatoin to use for this wiphy
+ *
+ * Set the regulatory domain information for self-managed wiphys, only they
+ * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
+ * information.
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index b776d72..ebc5a2e 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -147,6 +147,24 @@ struct regulatory_request {
  * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
  * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
  * includes any modes unsupported for enforcement checking.
+ * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
+ * regdom management. These devices will ignore all regdom changes not
+ * originating from their own wiphy.
+ * A self-managed wiphys only employs regulatory information obtained from
+ * the FW and driver and does not use other cfg80211 sources like
+ * beacon-hints, country-code IEs and hints from other devices on the same
+ * system. Conversely, a self-managed wiphy does not share its regulatory
+ * hints with other devices in the system. If a system contains several
+ * devices, one or more of which are self-managed, there might be
+ * contradictory regulatory settings between them. Usage of flag is
+ * generally discouraged. Only use it if the FW/driver is incompatible
+ * with non-locally originated hints.
+ * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
+ * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER,
+ * %REGULATORY_COUNTRY_IE_IGNORE and %REGULATORY_DISABLE_BEACON_HINTS.
+ * Mixing any of the above flags with this flag will result in a failure
+ * to register the wiphy. This flag implies
+ * %REGULATORY_DISABLE_BEACON_HINTS and %REGULATORY_COUNTRY_IE_IGNORE.
  */
 enum ieee80211_regulatory_flags {
REGULATORY_CUSTOM_REG   = BIT(0),
@@ -156,6 +174,7 @@ enum ieee80211_regulatory_flags {
REGULATORY_COUNTRY_IE_IGNORE= BIT(4),
REGULATORY_ENABLE_RELAX_NO_IR   = BIT(5),
REGULATORY_IGNORE_STALE_KICKOFF = BIT(6),
+   REGULATORY_WIPHY_SELF_MANAGED   = BIT(7),
 };
 
 struct ieee80211_freq_range {
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 62176a6..9ee06de 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -780,6 +780,10

[PATCH v8 1/4] cfg80211: allow usermode to query wiphy specific regdom

2014-12-03 Thread Arik Nemtsov
If a wiphy-idx is specified, the kernel will return the wiphy specific
regdomain, if such exists. Otherwise return the global regdom.

When no wiphy-idx is specified, return the global regdomain as well as
all wiphy-specific regulatory domains in the system, via a new nested
list of attributes.

Add a new attribute for each wiphy-specific regdomain, for usermode to
identify it as such.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
v8: remove bogus documentation from cfg80211.h

 include/uapi/linux/nl80211.h |   8 +-
 net/wireless/nl80211.c   | 178 +++
 net/wireless/reg.c   |   2 +-
 net/wireless/reg.h   |   1 +
 4 files changed, 154 insertions(+), 35 deletions(-)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index b37bd5a..62176a6 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -252,7 +252,13 @@
  * %NL80211_ATTR_IFINDEX.
  *
  * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
- * regulatory domain.
+ * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
+ * has a private regulatory domain, it will be returned. Otherwise, the
+ * global regdomain will be returned.
+ * A device will have a private regulatory domain if it uses the
+ * regulatory_hint() API. Even when a private regdomain is used the channel
+ * information will still be mended according to further hints from
+ * the regulatory core to help with compliance.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index a17d6bc..6736eae 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5327,42 +5327,20 @@ static int nl80211_update_mesh_config(struct sk_buff 
*skb,
return err;
 }
 
-static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
+static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
+ struct sk_buff *msg)
 {
-   const struct ieee80211_regdomain *regdom;
-   struct sk_buff *msg;
-   void *hdr = NULL;
struct nlattr *nl_reg_rules;
unsigned int i;
 
-   if (!cfg80211_regdomain)
-   return -EINVAL;
-
-   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
-   if (!msg)
-   return -ENOBUFS;
-
-   hdr = nl80211hdr_put(msg, info-snd_portid, info-snd_seq, 0,
-NL80211_CMD_GET_REG);
-   if (!hdr)
-   goto put_failure;
-
-   if (reg_last_request_cell_base() 
-   nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
-   NL80211_USER_REG_HINT_CELL_BASE))
-   goto nla_put_failure;
-
-   rcu_read_lock();
-   regdom = rcu_dereference(cfg80211_regdomain);
-
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom-alpha2) ||
(regdom-dfs_region 
 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom-dfs_region)))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
if (!nl_reg_rules)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
for (i = 0; i  regdom-n_reg_rules; i++) {
struct nlattr *nl_reg_rule;
@@ -5377,7 +5355,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
 
nl_reg_rule = nla_nest_start(msg, i);
if (!nl_reg_rule)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
max_bandwidth_khz = freq_range-max_bandwidth_khz;
if (!max_bandwidth_khz)
@@ -5398,13 +5376,69 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
power_rule-max_eirp) ||
nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
reg_rule-dfs_cac_ms))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nla_nest_end(msg, nl_reg_rule);
}
-   rcu_read_unlock();
 
nla_nest_end(msg, nl_reg_rules);
+   return 0;
+
+nla_put_failure:
+   return -EMSGSIZE;
+}
+
+static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
+{
+   const struct ieee80211_regdomain *regdom = NULL;
+   struct cfg80211_registered_device *rdev;
+   struct wiphy *wiphy = NULL;
+   struct sk_buff *msg;
+   void *hdr;
+
+   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+   if (!msg)
+   return -ENOBUFS;
+
+   hdr = nl80211hdr_put(msg, info-snd_portid, info-snd_seq, 0

[PATCH v8 4/4] cfg80211: correctly check ad-hoc channels

2014-12-03 Thread Arik Nemtsov
Ad-hoc requires beaconing for regulatory purposes. Validate that the
channel is valid for beaconing, and not only enabled.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 net/wireless/reg.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index c3e6f80..004ea14 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1552,9 +1552,15 @@ static bool reg_wdev_chan_valid(struct wiphy *wiphy, 
struct wireless_dev *wdev)
ret = cfg80211_reg_can_beacon(wiphy,
  wdev-chandef, wdev-iftype);
break;
+   case NL80211_IFTYPE_ADHOC:
+   if (!wdev-ssid_len)
+   goto out;
+
+   ret = cfg80211_reg_can_beacon(wiphy,
+ wdev-chandef, wdev-iftype);
+   break;
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
-   case NL80211_IFTYPE_ADHOC:
if (!wdev-current_bss ||
!wdev-current_bss-pub.channel)
goto out;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 2/4] cfg80211: allow wiphy specific regdomain management

2014-12-01 Thread Arik Nemtsov
From: Jonathan Doron j...@wizery.com

Add a new regulatory flag that allows a driver to manage regdomain
changes/updates for its own wiphy.
A self-managed wiphys only employs regulatory information obtained from
the FW and driver and does not use other cfg80211 sources like
beacon-hints, country-code IEs and hints from other devices on the same
system. Conversely, a self-managed wiphy does not share its regulatory
hints with other devices in the system. If a system contains several
devices, one or more of which are self-managed, there might be
contradictory regulatory settings between them. Usage of flag is
generally discouraged. Only use it if the FW/driver is incompatible
with non-locally originated hints.

A new API lets the driver send a complete regdomain, to be applied on
its wiphy only.

After a wiphy-specific regdomain change takes place, usermode will get
a new type of change notification. The regulatory core also takes care
enforce regulatory restrictions, in case some interfaces are on
forbidden channels.

Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/net/cfg80211.h   | 18 +
 include/net/regulatory.h | 19 ++
 include/uapi/linux/nl80211.h |  6 +++
 net/wireless/core.c  |  8 
 net/wireless/core.h  |  2 +
 net/wireless/nl80211.c   | 59 -
 net/wireless/nl80211.h   |  1 +
 net/wireless/reg.c   | 88 
 8 files changed, 183 insertions(+), 18 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 4ebb816..7e1a6d7 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2971,6 +2971,10 @@ struct wiphy_vendor_command {
  * the regulatory_hint() API. This can be used by the driver
  * on the reg_notifier() if it chooses to ignore future
  * regulatory domain changes caused by other drivers.
+ * @requested_regd: the driver requests the regulatory core to set this
+ * regulatory domain as the wiphy's. Only used for
+ * %REGULATORY_WIPHY_SELF_MANAGED devices using the
+ * regulatory_set_wiphy_regd() API
  * @signal_type: signal type reported in struct cfg80211_bss.
  * @cipher_suites: supported cipher suites
  * @n_cipher_suites: number of supported cipher suites
@@ -3808,6 +3812,20 @@ const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 
oui_type,
 int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
 
 /**
+ * regulatory_set_wiphy_regd - set regdom info for self managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain informatoin to use for this wiphy
+ *
+ * Set the regulatory domain information for self-managed wiphys, only they
+ * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
+ * information.
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index b776d72..ebc5a2e 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -147,6 +147,24 @@ struct regulatory_request {
  * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
  * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
  * includes any modes unsupported for enforcement checking.
+ * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
+ * regdom management. These devices will ignore all regdom changes not
+ * originating from their own wiphy.
+ * A self-managed wiphys only employs regulatory information obtained from
+ * the FW and driver and does not use other cfg80211 sources like
+ * beacon-hints, country-code IEs and hints from other devices on the same
+ * system. Conversely, a self-managed wiphy does not share its regulatory
+ * hints with other devices in the system. If a system contains several
+ * devices, one or more of which are self-managed, there might be
+ * contradictory regulatory settings between them. Usage of flag is
+ * generally discouraged. Only use it if the FW/driver is incompatible
+ * with non-locally originated hints.
+ * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
+ * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER,
+ * %REGULATORY_COUNTRY_IE_IGNORE and %REGULATORY_DISABLE_BEACON_HINTS.
+ * Mixing any of the above flags with this flag will result in a failure
+ * to register the wiphy. This flag implies
+ * %REGULATORY_DISABLE_BEACON_HINTS

[PATCH v6 4/4] cfg80211: correctly check ad-hoc channels

2014-12-01 Thread Arik Nemtsov
Ad-hoc requires beaconing for regulatory purposes. Validate that the
channel is valid for beaconing, and not only enabled.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
Ilan Peer mentioned this bug privately, so I thought I'd roll it up into
this patch-set

 net/wireless/reg.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index c3e6f80..004ea14 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1552,9 +1552,15 @@ static bool reg_wdev_chan_valid(struct wiphy *wiphy, 
struct wireless_dev *wdev)
ret = cfg80211_reg_can_beacon(wiphy,
  wdev-chandef, wdev-iftype);
break;
+   case NL80211_IFTYPE_ADHOC:
+   if (!wdev-ssid_len)
+   goto out;
+
+   ret = cfg80211_reg_can_beacon(wiphy,
+ wdev-chandef, wdev-iftype);
+   break;
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
-   case NL80211_IFTYPE_ADHOC:
if (!wdev-current_bss ||
!wdev-current_bss-pub.channel)
goto out;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 3/4] cfg80211: return private regdom for self-managed devices

2014-12-01 Thread Arik Nemtsov
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 arikx.nemt...@intel.com
---
 net/wireless/nl80211.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index de523aa..ca60c6a 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -396,6 +396,7 @@ static const struct nla_policy 
nl80211_policy[NUM_NL80211_ATTR] = {
[NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
[NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
[NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
+   [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
 };
 
 /* policy for the key attributes */
@@ -5406,6 +5407,8 @@ static int nl80211_get_reg_do(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);
@@ -5413,8 +5416,16 @@ static int nl80211_get_reg_do(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);
 
+   /* a self-managed-reg device must have a private regdom */
+   if (WARN_ON(!regdom  self_managed)) {
+   nlmsg_free(msg);
+   return -EINVAL;
+   }
+
if (regdom 
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
@@ -5476,6 +5487,10 @@ static int nl80211_send_regdom(struct sk_buff *msg, 
struct netlink_callback *cb,
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
 
+   if (wiphy  wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
return genlmsg_end(msg, hdr);
 
 nla_put_failure:
@@ -11081,6 +11096,11 @@ static bool nl80211_reg_change_event_fill(struct 
sk_buff *msg,
if (wiphy 
nla_put_u32(msg, NL80211_ATTR_WIPHY, request-wiphy_idx))
goto nla_put_failure;
+
+   if (wiphy 
+   wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
}
 
return true;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] iw: update nl80211.h

2014-12-01 Thread Arik Nemtsov
Signed-off-by: Arik Nemtsov a...@wizery.com
---
 nl80211.h | 143 ++
 1 file changed, 135 insertions(+), 8 deletions(-)

diff --git a/nl80211.h b/nl80211.h
index f7daae5..9884464 100644
--- a/nl80211.h
+++ b/nl80211.h
@@ -252,7 +252,9 @@
  * %NL80211_ATTR_IFINDEX.
  *
  * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
- * regulatory domain.
+ * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
+ * has a private regulatory domain, it will be returned. Otherwise, the
+ * global regdomain will be returned.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
@@ -643,7 +645,18 @@
  * @NL80211_CMD_CH_SWITCH_NOTIFY: An AP or GO may decide to switch channels
  * independently of the userspace SME, send this event indicating
  * %NL80211_ATTR_IFINDEX is now on %NL80211_ATTR_WIPHY_FREQ and the
- * attributes determining channel width.
+ * attributes determining channel width.  This indication may also be
+ * sent when a remotely-initiated switch (e.g., when a STA receives a CSA
+ * from the remote AP) is completed;
+ *
+ * @NL80211_CMD_CH_SWITCH_STARTED_NOTIFY: Notify that a channel switch
+ * has been started on an interface, regardless of the initiator
+ * (ie. whether it was requested from a remote device or
+ * initiated on our own).  It indicates that
+ * %NL80211_ATTR_IFINDEX will be on %NL80211_ATTR_WIPHY_FREQ
+ * after %NL80211_ATTR_CH_SWITCH_COUNT TBTT's.  The userspace may
+ * decide to react to this indication by requesting other
+ * interfaces to change channel as well.
  *
  * @NL80211_CMD_START_P2P_DEVICE: Start the given P2P Device, identified by
  * its %NL80211_ATTR_WDEV identifier. It must have been created with
@@ -746,6 +759,27 @@
  * destination %NL80211_ATTR_MAC on the interface identified by
  * %NL80211_ATTR_IFINDEX.
  *
+ * @NL80211_CMD_JOIN_OCB: Join the OCB network. The center frequency and
+ * bandwidth of a channel must be given.
+ * @NL80211_CMD_LEAVE_OCB: Leave the OCB network -- no special arguments, the
+ * network is determined by the network interface.
+ *
+ * @NL80211_CMD_TDLS_CHANNEL_SWITCH: Start channel-switching with a TDLS peer,
+ * identified by the %NL80211_ATTR_MAC parameter. A target channel is
+ * provided via %NL80211_ATTR_WIPHY_FREQ and other attributes determining
+ * channel width/type. The target operating class is given via
+ * %NL80211_ATTR_OPER_CLASS.
+ * The driver is responsible for continually initiating channel-switching
+ * operations and returning to the base channel for communication with the
+ * AP.
+ * @NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH: Stop channel-switching with a TDLS
+ * peer given by %NL80211_ATTR_MAC. Both peers must be on the base channel
+ * when this command completes.
+ *
+ * @NL80211_CMD_WIPHY_REG_CHANGE: Similar to %NL80211_CMD_REG_CHANGE, but used
+ * as an event to indicate changes for devices with wiphy-specific regdom
+ * management.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -922,6 +956,16 @@ enum nl80211_commands {
 
NL80211_CMD_GET_MPP,
 
+   NL80211_CMD_JOIN_OCB,
+   NL80211_CMD_LEAVE_OCB,
+
+   NL80211_CMD_CH_SWITCH_STARTED_NOTIFY,
+
+   NL80211_CMD_TDLS_CHANNEL_SWITCH,
+   NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
+
+   NL80211_CMD_WIPHY_REG_CHANGE,
+
/* add new commands above here */
 
/* used to define NL80211_CMD_MAX below */
@@ -1616,9 +1660,9 @@ enum nl80211_commands {
  * @NL80211_ATTR_TDLS_PEER_CAPABILITY: flags for TDLS peer capabilities, u32.
  * As specified in the enum nl80211_tdls_peer_capability.
  *
- * @NL80211_ATTR_IFACE_SOCKET_OWNER: flag attribute, if set during interface
+ * @NL80211_ATTR_SOCKET_OWNER: Flag attribute, if set during interface
  * creation then the new interface will be owned by the netlink socket
- * that created it and will be destroyed when the socket is closed
+ * that created it and will be destroyed when the socket is closed.
  *
  * @NL80211_ATTR_TDLS_INITIATOR: flag attribute indicating the current end is
  * the TDLS link initiator.
@@ -1648,6 +1692,16 @@ enum nl80211_commands {
  * @NL80211_ATTR_SMPS_MODE: SMPS mode to use (ap mode). see
  * enum nl80211_smps_mode.
  *
+ * @NL80211_ATTR_OPER_CLASS: operating class
+ *
+ * @NL80211_ATTR_MAC_MASK: MAC address mask
+ *
+ * @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

[PATCH 4/4] iw: support multiple regdom print

2014-12-01 Thread Arik Nemtsov
When a phy is given, print only its regdomain. Otherwise, use the newly
implement dump functionality to print all regdomains in the system.

Signed-off-by: Arik Nemtsov a...@wizery.com
---
 reg.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/reg.c b/reg.c
index a02c982..4e4c707 100644
--- a/reg.c
+++ b/reg.c
@@ -114,7 +114,6 @@ COMMAND(reg, set, ISO/IEC 3166-1 alpha2,
Notify the kernel about the current regulatory domain.);
 
 static int print_reg_handler(struct nl_msg *msg, void *arg)
-
 {
 #define PARSE_FLAG(nl_flag, string_value)  do { \
if ((flags  nl_flag)) { \
@@ -150,6 +149,13 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
return NL_SKIP;
}
 
+   if (tb_msg[NL80211_ATTR_WIPHY])
+   printf(phy#%d%s\n, nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]),
+  tb_msg[NL80211_ATTR_WIPHY_SELF_MANAGED_REG] ?
+   (self-managed) : );
+   else
+   printf(global\n);
+
if (tb_msg[NL80211_ATTR_DFS_REGION])
dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
else
@@ -216,7 +222,9 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
 
printf(\n);
}
-   return NL_OK;
+
+   printf(\n);
+   return NL_SKIP;
 #undef PARSE_FLAG
 }
 
@@ -229,5 +237,8 @@ static int handle_reg_get(struct nl80211_state *state,
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_reg_handler, NULL);
return 0;
 }
-COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_NONE, handle_reg_get,
+COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, NLM_F_DUMP, CIB_NONE,
+   handle_reg_get,
Print out the kernel's current regulatory domain information.);
+COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_PHY, handle_reg_get,
+   Print out the devices' current regulatory domain information.);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/4] iw: fix attr max for reg_rule

2014-12-01 Thread Arik Nemtsov
Signed-off-by: Arik Nemtsov a...@wizery.com
---
 reg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/reg.c b/reg.c
index 9af8e7e..a02c982 100644
--- a/reg.c
+++ b/reg.c
@@ -127,7 +127,7 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
struct nlattr *nl_rule;
int rem_rule;
enum nl80211_dfs_regions dfs_domain;
-   static struct nla_policy reg_rule_policy[NL80211_FREQUENCY_ATTR_MAX + 
1] = {
+   static struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] 
= {
[NL80211_ATTR_REG_RULE_FLAGS]   = { .type = NLA_U32 },
[NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
[NL80211_ATTR_FREQ_RANGE_END]   = { .type = NLA_U32 },
@@ -159,10 +159,10 @@ static int print_reg_handler(struct nl_msg *msg, void 
*arg)
printf(country %c%c: %s\n, alpha2[0], alpha2[1], 
dfs_domain_name(dfs_domain));
 
nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) {
-   struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
+   struct nlattr *tb_rule[NL80211_REG_RULE_ATTR_MAX + 1];
__u32 flags, start_freq_khz, end_freq_khz, max_bw_khz, 
max_ant_gain_mbi, max_eirp_mbm;
 
-   nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, 
nla_data(nl_rule), nla_len(nl_rule), reg_rule_policy);
+   nla_parse(tb_rule, NL80211_REG_RULE_ATTR_MAX, 
nla_data(nl_rule), nla_len(nl_rule), reg_rule_policy);
 
flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
start_freq_khz = 
nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/4] iw: fix attr max for reg_rule

2014-12-01 Thread Arik Nemtsov
Signed-off-by: Arik Nemtsov a...@wizery.com
---
 reg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/reg.c b/reg.c
index 9af8e7e..a02c982 100644
--- a/reg.c
+++ b/reg.c
@@ -127,7 +127,7 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
struct nlattr *nl_rule;
int rem_rule;
enum nl80211_dfs_regions dfs_domain;
-   static struct nla_policy reg_rule_policy[NL80211_FREQUENCY_ATTR_MAX + 
1] = {
+   static struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] 
= {
[NL80211_ATTR_REG_RULE_FLAGS]   = { .type = NLA_U32 },
[NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
[NL80211_ATTR_FREQ_RANGE_END]   = { .type = NLA_U32 },
@@ -159,10 +159,10 @@ static int print_reg_handler(struct nl_msg *msg, void 
*arg)
printf(country %c%c: %s\n, alpha2[0], alpha2[1], 
dfs_domain_name(dfs_domain));
 
nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) {
-   struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
+   struct nlattr *tb_rule[NL80211_REG_RULE_ATTR_MAX + 1];
__u32 flags, start_freq_khz, end_freq_khz, max_bw_khz, 
max_ant_gain_mbi, max_eirp_mbm;
 
-   nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, 
nla_data(nl_rule), nla_len(nl_rule), reg_rule_policy);
+   nla_parse(tb_rule, NL80211_REG_RULE_ATTR_MAX, 
nla_data(nl_rule), nla_len(nl_rule), reg_rule_policy);
 
flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
start_freq_khz = 
nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/4] iw: update nl80211.h

2014-12-01 Thread Arik Nemtsov
Signed-off-by: Arik Nemtsov a...@wizery.com
---
 nl80211.h | 143 ++
 1 file changed, 135 insertions(+), 8 deletions(-)

diff --git a/nl80211.h b/nl80211.h
index f7daae5..9884464 100644
--- a/nl80211.h
+++ b/nl80211.h
@@ -252,7 +252,9 @@
  * %NL80211_ATTR_IFINDEX.
  *
  * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
- * regulatory domain.
+ * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
+ * has a private regulatory domain, it will be returned. Otherwise, the
+ * global regdomain will be returned.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
@@ -643,7 +645,18 @@
  * @NL80211_CMD_CH_SWITCH_NOTIFY: An AP or GO may decide to switch channels
  * independently of the userspace SME, send this event indicating
  * %NL80211_ATTR_IFINDEX is now on %NL80211_ATTR_WIPHY_FREQ and the
- * attributes determining channel width.
+ * attributes determining channel width.  This indication may also be
+ * sent when a remotely-initiated switch (e.g., when a STA receives a CSA
+ * from the remote AP) is completed;
+ *
+ * @NL80211_CMD_CH_SWITCH_STARTED_NOTIFY: Notify that a channel switch
+ * has been started on an interface, regardless of the initiator
+ * (ie. whether it was requested from a remote device or
+ * initiated on our own).  It indicates that
+ * %NL80211_ATTR_IFINDEX will be on %NL80211_ATTR_WIPHY_FREQ
+ * after %NL80211_ATTR_CH_SWITCH_COUNT TBTT's.  The userspace may
+ * decide to react to this indication by requesting other
+ * interfaces to change channel as well.
  *
  * @NL80211_CMD_START_P2P_DEVICE: Start the given P2P Device, identified by
  * its %NL80211_ATTR_WDEV identifier. It must have been created with
@@ -746,6 +759,27 @@
  * destination %NL80211_ATTR_MAC on the interface identified by
  * %NL80211_ATTR_IFINDEX.
  *
+ * @NL80211_CMD_JOIN_OCB: Join the OCB network. The center frequency and
+ * bandwidth of a channel must be given.
+ * @NL80211_CMD_LEAVE_OCB: Leave the OCB network -- no special arguments, the
+ * network is determined by the network interface.
+ *
+ * @NL80211_CMD_TDLS_CHANNEL_SWITCH: Start channel-switching with a TDLS peer,
+ * identified by the %NL80211_ATTR_MAC parameter. A target channel is
+ * provided via %NL80211_ATTR_WIPHY_FREQ and other attributes determining
+ * channel width/type. The target operating class is given via
+ * %NL80211_ATTR_OPER_CLASS.
+ * The driver is responsible for continually initiating channel-switching
+ * operations and returning to the base channel for communication with the
+ * AP.
+ * @NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH: Stop channel-switching with a TDLS
+ * peer given by %NL80211_ATTR_MAC. Both peers must be on the base channel
+ * when this command completes.
+ *
+ * @NL80211_CMD_WIPHY_REG_CHANGE: Similar to %NL80211_CMD_REG_CHANGE, but used
+ * as an event to indicate changes for devices with wiphy-specific regdom
+ * management.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -922,6 +956,16 @@ enum nl80211_commands {
 
NL80211_CMD_GET_MPP,
 
+   NL80211_CMD_JOIN_OCB,
+   NL80211_CMD_LEAVE_OCB,
+
+   NL80211_CMD_CH_SWITCH_STARTED_NOTIFY,
+
+   NL80211_CMD_TDLS_CHANNEL_SWITCH,
+   NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
+
+   NL80211_CMD_WIPHY_REG_CHANGE,
+
/* add new commands above here */
 
/* used to define NL80211_CMD_MAX below */
@@ -1616,9 +1660,9 @@ enum nl80211_commands {
  * @NL80211_ATTR_TDLS_PEER_CAPABILITY: flags for TDLS peer capabilities, u32.
  * As specified in the enum nl80211_tdls_peer_capability.
  *
- * @NL80211_ATTR_IFACE_SOCKET_OWNER: flag attribute, if set during interface
+ * @NL80211_ATTR_SOCKET_OWNER: Flag attribute, if set during interface
  * creation then the new interface will be owned by the netlink socket
- * that created it and will be destroyed when the socket is closed
+ * that created it and will be destroyed when the socket is closed.
  *
  * @NL80211_ATTR_TDLS_INITIATOR: flag attribute indicating the current end is
  * the TDLS link initiator.
@@ -1648,6 +1692,16 @@ enum nl80211_commands {
  * @NL80211_ATTR_SMPS_MODE: SMPS mode to use (ap mode). see
  * enum nl80211_smps_mode.
  *
+ * @NL80211_ATTR_OPER_CLASS: operating class
+ *
+ * @NL80211_ATTR_MAC_MASK: MAC address mask
+ *
+ * @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

[PATCH v2 2/4] iw: print new RRF_ regulatory flags

2014-12-01 Thread Arik Nemtsov
These were added to cfg80211 recently

Signed-off-by: Arik Nemtsov a...@wizery.com
---
v2: remove XXX from title, apparently the ML doesn't like them :)

 reg.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/reg.c b/reg.c
index e1bb0d2..9af8e7e 100644
--- a/reg.c
+++ b/reg.c
@@ -199,6 +199,12 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
PARSE_FLAG(NL80211_RRF_NO_OUTDOOR, NO-OUTDOOR);
PARSE_FLAG(NL80211_RRF_DFS, DFS);
PARSE_FLAG(NL80211_RRF_PTP_ONLY, PTP-ONLY);
+   PARSE_FLAG(NL80211_RRF_AUTO_BW, AUTO-BW);
+   PARSE_FLAG(NL80211_RRF_GO_CONCURRENT, GO-CONCURRENT);
+   PARSE_FLAG(NL80211_RRF_NO_HT40MINUS, NO-HT40MINUS);
+   PARSE_FLAG(NL80211_RRF_NO_HT40PLUS, NO-HT40PLUS);
+   PARSE_FLAG(NL80211_RRF_NO_80MHZ, NO-80MHZ);
+   PARSE_FLAG(NL80211_RRF_NO_160MHZ, NO-160MHZ);
 
/* Kernels that support NO_IR always turn on both flags */
if ((flags  NL80211_RRF_NO_IR)  (flags  
__NL80211_RRF_NO_IBSS)) {
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/4] iw: support multiple regdom print

2014-12-01 Thread Arik Nemtsov
When a phy is given, print only its regdomain. Otherwise, use the newly
implement dump functionality to print all regdomains in the system.

Signed-off-by: Arik Nemtsov a...@wizery.com
---
 reg.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/reg.c b/reg.c
index a02c982..4e4c707 100644
--- a/reg.c
+++ b/reg.c
@@ -114,7 +114,6 @@ COMMAND(reg, set, ISO/IEC 3166-1 alpha2,
Notify the kernel about the current regulatory domain.);
 
 static int print_reg_handler(struct nl_msg *msg, void *arg)
-
 {
 #define PARSE_FLAG(nl_flag, string_value)  do { \
if ((flags  nl_flag)) { \
@@ -150,6 +149,13 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
return NL_SKIP;
}
 
+   if (tb_msg[NL80211_ATTR_WIPHY])
+   printf(phy#%d%s\n, nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]),
+  tb_msg[NL80211_ATTR_WIPHY_SELF_MANAGED_REG] ?
+   (self-managed) : );
+   else
+   printf(global\n);
+
if (tb_msg[NL80211_ATTR_DFS_REGION])
dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
else
@@ -216,7 +222,9 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
 
printf(\n);
}
-   return NL_OK;
+
+   printf(\n);
+   return NL_SKIP;
 #undef PARSE_FLAG
 }
 
@@ -229,5 +237,8 @@ static int handle_reg_get(struct nl80211_state *state,
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_reg_handler, NULL);
return 0;
 }
-COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_NONE, handle_reg_get,
+COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, NLM_F_DUMP, CIB_NONE,
+   handle_reg_get,
Print out the kernel's current regulatory domain information.);
+COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_PHY, handle_reg_get,
+   Print out the devices' current regulatory domain information.);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] iw: print phy TDLS ch-switch support

2014-12-01 Thread Arik Nemtsov
Signed-off-by: Arik Nemtsov a...@wizery.com
---
 info.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/info.c b/info.c
index 7499290..7f8c832 100644
--- a/info.c
+++ b/info.c
@@ -587,6 +587,8 @@ broken_combination:
printf(\tDevice supports WMM-AC admission (TSPECs)\n);
if (features  NL80211_FEATURE_MAC_ON_CREATE)
printf(\tDevice supports configuring vdev MAC-addr on 
create.\n);
+   if (features  NL80211_FEATURE_TDLS_CHANNEL_SWITCH)
+   printf(\tDevice supports TDLS channel switching\n);
}
 
if (tb_msg[NL80211_ATTR_TDLS_SUPPORT])
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 3/4] cfg80211: return private regdom for self-managed devices

2014-12-01 Thread Arik Nemtsov
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 arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/uapi/linux/nl80211.h | 10 ++
 net/wireless/nl80211.c   | 27 +++
 2 files changed, 37 insertions(+)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 9ee06de..5a13958 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -259,6 +259,9 @@
  * regulatory_hint() API. Even when a private regdomain is used the channel
  * information will still be mended according to further hints from
  * the regulatory core to help with compliance.
+ * If a wiphy is self-managed (%NL80211_ATTR_WIPHY_SELF_MANAGED_REG), then
+ * its private regdomain is the only valid one for it. The regulatory
+ * core is not used to help with compliance in this case.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
@@ -1700,6 +1703,11 @@ enum nl80211_commands {
  *
  * @NL80211_ATTR_MAC_MASK: MAC address mask
  *
+ * @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
@@ -2057,6 +2065,8 @@ enum nl80211_attrs {
 
NL80211_ATTR_MAC_MASK,
 
+   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 de523aa..d88bf73 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -396,6 +396,7 @@ static const struct nla_policy 
nl80211_policy[NUM_NL80211_ATTR] = {
[NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
[NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
[NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
+   [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
 };
 
 /* policy for the key attributes */
@@ -1701,6 +1702,13 @@ static int nl80211_send_wiphy(struct 
cfg80211_registered_device *rdev,
   rdev-wiphy.max_num_csa_counters))
goto nla_put_failure;
 
+   state-split_start++;
+   break;
+   case 13:
+   if (rdev-wiphy.regulatory_flags  
REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
/* done */
state-split_start = 0;
break;
@@ -5406,6 +5414,8 @@ static int nl80211_get_reg_do(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);
@@ -5413,8 +5423,16 @@ static int nl80211_get_reg_do(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);
 
+   /* a self-managed-reg device must have a private regdom */
+   if (WARN_ON(!regdom  self_managed)) {
+   nlmsg_free(msg);
+   return -EINVAL;
+   }
+
if (regdom 
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
@@ -5476,6 +5494,10 @@ static int nl80211_send_regdom(struct sk_buff *msg, 
struct netlink_callback *cb,
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
 
+   if (wiphy  wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED 
+   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
+   goto nla_put_failure;
+
return genlmsg_end(msg, hdr);
 
 nla_put_failure:
@@ -11081,6 +11103,11 @@ static bool nl80211_reg_change_event_fill(struct 
sk_buff *msg,
if (wiphy 
nla_put_u32(msg, NL80211_ATTR_WIPHY, request-wiphy_idx))
goto

[PATCH v7 1/4] cfg80211: allow usermode to query wiphy specific regdom

2014-12-01 Thread Arik Nemtsov
If a wiphy-idx is specified, the kernel will return the wiphy specific
regdomain, if such exists. Otherwise return the global regdom.

When no wiphy-idx is specified, return the global regdomain as well as
all wiphy-specific regulatory domains in the system, via a new nested
list of attributes.

Add a new attribute for each wiphy-specific regdomain, for usermode to
identify it as such.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 include/uapi/linux/nl80211.h |   8 +-
 net/wireless/nl80211.c   | 178 +++
 net/wireless/reg.c   |   2 +-
 net/wireless/reg.h   |   1 +
 4 files changed, 154 insertions(+), 35 deletions(-)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index b37bd5a..62176a6 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -252,7 +252,13 @@
  * %NL80211_ATTR_IFINDEX.
  *
  * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
- * regulatory domain.
+ * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
+ * has a private regulatory domain, it will be returned. Otherwise, the
+ * global regdomain will be returned.
+ * A device will have a private regulatory domain if it uses the
+ * regulatory_hint() API. Even when a private regdomain is used the channel
+ * information will still be mended according to further hints from
+ * the regulatory core to help with compliance.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index a17d6bc..6736eae 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5327,42 +5327,20 @@ static int nl80211_update_mesh_config(struct sk_buff 
*skb,
return err;
 }
 
-static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
+static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
+ struct sk_buff *msg)
 {
-   const struct ieee80211_regdomain *regdom;
-   struct sk_buff *msg;
-   void *hdr = NULL;
struct nlattr *nl_reg_rules;
unsigned int i;
 
-   if (!cfg80211_regdomain)
-   return -EINVAL;
-
-   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
-   if (!msg)
-   return -ENOBUFS;
-
-   hdr = nl80211hdr_put(msg, info-snd_portid, info-snd_seq, 0,
-NL80211_CMD_GET_REG);
-   if (!hdr)
-   goto put_failure;
-
-   if (reg_last_request_cell_base() 
-   nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
-   NL80211_USER_REG_HINT_CELL_BASE))
-   goto nla_put_failure;
-
-   rcu_read_lock();
-   regdom = rcu_dereference(cfg80211_regdomain);
-
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom-alpha2) ||
(regdom-dfs_region 
 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom-dfs_region)))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
if (!nl_reg_rules)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
for (i = 0; i  regdom-n_reg_rules; i++) {
struct nlattr *nl_reg_rule;
@@ -5377,7 +5355,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
 
nl_reg_rule = nla_nest_start(msg, i);
if (!nl_reg_rule)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
max_bandwidth_khz = freq_range-max_bandwidth_khz;
if (!max_bandwidth_khz)
@@ -5398,13 +5376,69 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
power_rule-max_eirp) ||
nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
reg_rule-dfs_cac_ms))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nla_nest_end(msg, nl_reg_rule);
}
-   rcu_read_unlock();
 
nla_nest_end(msg, nl_reg_rules);
+   return 0;
+
+nla_put_failure:
+   return -EMSGSIZE;
+}
+
+static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
+{
+   const struct ieee80211_regdomain *regdom = NULL;
+   struct cfg80211_registered_device *rdev;
+   struct wiphy *wiphy = NULL;
+   struct sk_buff *msg;
+   void *hdr;
+
+   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+   if (!msg)
+   return -ENOBUFS;
+
+   hdr = nl80211hdr_put(msg, info-snd_portid, info-snd_seq, 0,
+NL80211_CMD_GET_REG

[PATCH v7 2/4] cfg80211: allow wiphy specific regdomain management

2014-12-01 Thread Arik Nemtsov
From: Jonathan Doron j...@wizery.com

Add a new regulatory flag that allows a driver to manage regdomain
changes/updates for its own wiphy.
A self-managed wiphys only employs regulatory information obtained from
the FW and driver and does not use other cfg80211 sources like
beacon-hints, country-code IEs and hints from other devices on the same
system. Conversely, a self-managed wiphy does not share its regulatory
hints with other devices in the system. If a system contains several
devices, one or more of which are self-managed, there might be
contradictory regulatory settings between them. Usage of flag is
generally discouraged. Only use it if the FW/driver is incompatible
with non-locally originated hints.

A new API lets the driver send a complete regdomain, to be applied on
its wiphy only.

After a wiphy-specific regdomain change takes place, usermode will get
a new type of change notification. The regulatory core also takes care
enforce regulatory restrictions, in case some interfaces are on
forbidden channels.

Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/net/cfg80211.h   | 18 +
 include/net/regulatory.h | 19 ++
 include/uapi/linux/nl80211.h |  6 +++
 net/wireless/core.c  |  8 
 net/wireless/core.h  |  2 +
 net/wireless/nl80211.c   | 59 -
 net/wireless/nl80211.h   |  1 +
 net/wireless/reg.c   | 88 
 8 files changed, 183 insertions(+), 18 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 4ebb816..7e1a6d7 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2971,6 +2971,10 @@ struct wiphy_vendor_command {
  * the regulatory_hint() API. This can be used by the driver
  * on the reg_notifier() if it chooses to ignore future
  * regulatory domain changes caused by other drivers.
+ * @requested_regd: the driver requests the regulatory core to set this
+ * regulatory domain as the wiphy's. Only used for
+ * %REGULATORY_WIPHY_SELF_MANAGED devices using the
+ * regulatory_set_wiphy_regd() API
  * @signal_type: signal type reported in struct cfg80211_bss.
  * @cipher_suites: supported cipher suites
  * @n_cipher_suites: number of supported cipher suites
@@ -3808,6 +3812,20 @@ const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 
oui_type,
 int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
 
 /**
+ * regulatory_set_wiphy_regd - set regdom info for self managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain informatoin to use for this wiphy
+ *
+ * Set the regulatory domain information for self-managed wiphys, only they
+ * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
+ * information.
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index b776d72..ebc5a2e 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -147,6 +147,24 @@ struct regulatory_request {
  * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
  * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
  * includes any modes unsupported for enforcement checking.
+ * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
+ * regdom management. These devices will ignore all regdom changes not
+ * originating from their own wiphy.
+ * A self-managed wiphys only employs regulatory information obtained from
+ * the FW and driver and does not use other cfg80211 sources like
+ * beacon-hints, country-code IEs and hints from other devices on the same
+ * system. Conversely, a self-managed wiphy does not share its regulatory
+ * hints with other devices in the system. If a system contains several
+ * devices, one or more of which are self-managed, there might be
+ * contradictory regulatory settings between them. Usage of flag is
+ * generally discouraged. Only use it if the FW/driver is incompatible
+ * with non-locally originated hints.
+ * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
+ * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER,
+ * %REGULATORY_COUNTRY_IE_IGNORE and %REGULATORY_DISABLE_BEACON_HINTS.
+ * Mixing any of the above flags with this flag will result in a failure
+ * to register the wiphy. This flag implies
+ * %REGULATORY_DISABLE_BEACON_HINTS

[PATCH v7 4/4] cfg80211: correctly check ad-hoc channels

2014-12-01 Thread Arik Nemtsov
Ad-hoc requires beaconing for regulatory purposes. Validate that the
channel is valid for beaconing, and not only enabled.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 net/wireless/reg.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index c3e6f80..004ea14 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1552,9 +1552,15 @@ static bool reg_wdev_chan_valid(struct wiphy *wiphy, 
struct wireless_dev *wdev)
ret = cfg80211_reg_can_beacon(wiphy,
  wdev-chandef, wdev-iftype);
break;
+   case NL80211_IFTYPE_ADHOC:
+   if (!wdev-ssid_len)
+   goto out;
+
+   ret = cfg80211_reg_can_beacon(wiphy,
+ wdev-chandef, wdev-iftype);
+   break;
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
-   case NL80211_IFTYPE_ADHOC:
if (!wdev-current_bss ||
!wdev-current_bss-pub.channel)
goto out;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 2/4] cfg80211: allow usermode to query wiphy specific regdom

2014-11-30 Thread Arik Nemtsov
On Sat, Nov 29, 2014 at 12:00 AM, Luis R. Rodriguez mcg...@suse.com wrote:
 On Fri, Nov 28, 2014 at 02:46:27PM +0100, Johannes Berg wrote:
 On Thu, 2014-11-27 at 09:44 +0200, Arik Nemtsov wrote:
  If a wiphy-idx is specified, the kernel will return the wiphy specific
  regdomain, if such exists. Otherwise return the global regdom.
 
  When no wiphy-idx is specified, return the global regdomain as well as
  all wiphy-specific regulatory domains in the system, via a new nested
  list of attributes.

 Is that really a good idea? Seems rather easy to overrun the message
 size with that, in which case your current code will not return anything
 at all... that'll cause strange errors if somebody plugs in a few
 devices or has hwsim open as well or so ...

 Good point, perhaps require 'iw reg get --all' for all listing then?
 This would mean requiring an new optional flag passed on reg get too
 then.

I think Johannes' point was that it's easy to overrun the message size
if there are a lot of wiphys.
So I'll simply add an iterator over all wiphys in iw reg get and
kernel-mode will only return a single regdomain in each GET_REG
invocation.

About the --all suggestion - I think it's fine to not have backward
compatibility in the output of iw reg get? So we can just output the
global first, and then output private regdoms for all wiphys that have
them.

Does that sound ok?


  Add a new attribute for each wiphy-specific regdomain, for usermode to
  identify it as such.

 Shouldn't userspace also *request* this for backward compatibility?
 Otherwise older userspace might assume that a returned regd applies to
 everything, when it doesn't really?

 If the flag --all is used and passed then I see no issue.

Well you have to give a wiphy-idx in order to get a private regdom in
the first place. And only new userspace will add a wiphy-idx in the
first place..

Also, when a global regdom is returned for a given wiphy-idx instead
of a private one, it is valid, since the global one is being used for
this wiphy.
If there is a private regdom (from regulatory_hint()) then we'll
return it to usermode. This is less restrictive than the global one,
and that's the one being used for channel verification for this wiphy.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 2/4] cfg80211: allow usermode to query wiphy specific regdom

2014-11-30 Thread Arik Nemtsov
On Sun, Nov 30, 2014 at 2:32 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Sun, 2014-11-30 at 14:26 +0200, Arik Nemtsov wrote:

 I think Johannes' point was that it's easy to overrun the message size
 if there are a lot of wiphys.

 Yes.

 So I'll simply add an iterator over all wiphys in iw reg get and
 kernel-mode will only return a single regdomain in each GET_REG
 invocation.

 Err, there's such a thing built into netlink already - just support
 dumpit instead of doit :)

That's cool. I'll use it then :)

 iw will have to fall back to doit for older kernels though I guess.

Well older kernels don't have this feature anyway, so it's fine to
leave the doit as is.
For backports, we are bringing this code with us anyway right?


 About the --all suggestion - I think it's fine to not have backward
 compatibility in the output of iw reg get? So we can just output the
 global first, and then output private regdoms for all wiphys that have
 them.

 Does that sound ok?

 Yeah I wasn't taking about the iw display, and adding --all there
 doesn't help for what I was concerned about.

 Well you have to give a wiphy-idx in order to get a private regdom in
 the first place. And only new userspace will add a wiphy-idx in the
 first place..

 Are you sure about the last part though? wpa_supplicant often passed a
 netdev index instead of a wiphy index for example, so I could imagine it
 passing a wiphy index here even though it was previously ignored?

 If it didn't though then I think there's no problem, there shouldn't
 really be any userspace other than wpa_s and iw for this I guess/hope.

It definitely doesn't pass it now. Otherwise we wouldn't have to change it :)

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 3/4] cfg80211: allow usermode to query wiphy specific regdom

2014-11-27 Thread Arik Nemtsov
On Thu, Nov 27, 2014 at 5:35 PM, Luis R. Rodriguez mcg...@suse.com wrote:
 On Thu, Nov 27, 2014 at 09:12:11AM +0200, Arik Nemtsov wrote:
 On Wed, Nov 26, 2014 at 11:43 PM, Luis R. Rodriguez mcg...@suse.com wrote:
  On Wed, Nov 26, 2014 at 4:35 PM, Luis R. Rodriguez mcg...@suse.com wrote:
  We're not checking here if this was a managed wiphy or not, we
  want userspace to be able to tell if a wiphy was managed or not.
 
  Ah I see what you did, yes that is what I wanted but since you allowed
  for self managed regdomains *first* the placement of this patch in
  terms of order would mean we are not giving userspace information it
  should have needed right after this commit. After your 4th patch we do
  though. We want commits to work well linearly in history so can you
  move this patch to number 2 in the series and bump number 2 to be
  patch number 3? That way right after commit 2 we are not lying to
  userspace.
 
  The question about having userspace specify the wiphy still stands as
  I'd expect userspace asking only for a regd for a wiphy would want
  only that one, not all, or the central one.

 In general, we want to return only the regdom of the wiphy the user
 asked for. And yea, I'll fix it.

 But there's a tricky part here. In the not-self-managed case, if a
 user specifies a wiphy-idx, and there's no wiphy-regd, we'll return
 the global one.

 Hm, that's fine if its well understood by userspace that even if
 a wiphy has a specific regd (priv one) that the central one is the one that is
 used for it anyway, the wiphy regd would just be informational. It may be
 a bit odd to give the central one if the wiphy-idx has no regd in this
 case then, so just think about this a bit, wihch is why I am a bit
 inclined to just have cfg80211 not return any regd if the wiphy has
 no priv or self-manged regd.

 This is fine, since in effect, the global regd is the one used by this
 wiphy anyway.
 Essentially we want this part to just be able to add the wiphy-idx to
 wpa_s code for GET_REG, and remain backward compatible. But like I
 said above, it's the right thing to do

 Sure, you have a handle of what is needed, so just make the API very
 clear to users so they don't think that if cfg80211 returns a regd
 for a wiphy if its a priv regd that its not the one that applies
 but rather informational for what it started with.

Do you see a problem with v5 of the patches?

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 1/3] cfg80211: leave invalid channels on regdomain change

2014-11-26 Thread Arik Nemtsov
On Tue, Nov 25, 2014 at 9:38 PM, Luis R. Rodriguez mcg...@suse.com wrote:

 Please rename to REGULATORY_IGNORE_STALE_KICKOFF, also please add
 some information about the amount current of grace period used,
 and types of interfaces supported. Since this is a regulatory flag
 this information will help folks decide whether to enable or not.
 Also encourage its use, and mention that once all supported devices
 get support for this will be enabled by default. In the meantime
 I'd prefer if this feature was enabled by default if the supported
 interface types of a dveice match the white list of supported
 interfaces.

Will do.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 3/3] cfg80211: Allow usermode to query wiphy specific regd info

2014-11-26 Thread Arik Nemtsov
On Tue, Nov 25, 2014 at 10:28 PM, Luis R. Rodriguez mcg...@suse.com wrote:
 On Sun, Nov 23, 2014 at 05:02:21PM +0200, Arik Nemtsov wrote:
 From: Jonathan Doron j...@wizery.com

 Allow usermode to query wiphy-specific regd info, for drivers that use
 wiphy-specific regulatory management.

 Use the existing API for sending regdomain info to usermode, but return
 the wiphy-specific regd in case wiphy index is provided and the driver
 employs wiphy-specific management. This implies user and kernel-mode
 support for the feature and is backward compatible.

 Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
 Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
 ---
  include/uapi/linux/nl80211.h | 18 ++-
  net/wireless/nl80211.c   | 71 
 
  net/wireless/reg.c   |  2 +-
  net/wireless/reg.h   |  1 +
  4 files changed, 78 insertions(+), 14 deletions(-)

 diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
 index 3771e7d..b222e5c 100644
 --- a/include/uapi/linux/nl80211.h
 +++ b/include/uapi/linux/nl80211.h
 @@ -252,7 +252,12 @@
   *   %NL80211_ATTR_IFINDEX.
   *
   * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
 - *   regulatory domain.
 + *   regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
 + *   self-manages its regulatory settings, its private regulatory domain
 + *   will be returned.
 + *   If %NL80211_ATTR_WIPHY_GET_PRIV_REG is specified in addition to
 + *   %NL80211_ATTR_WIPHY, a device's private regulatory domain will be
 + *   returned, even if it's regulatory is not self-managed.
   * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this 
 command
   *   after being queried by the kernel. CRDA replies by sending a regulatory
   *   domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
 @@ -1693,6 +1698,14 @@ enum nl80211_commands {
   *
   * @NL80211_ATTR_MAC_MASK: MAC address mask
   *
 + * @NL80211_ATTR_WIPHY_SELF_MANAGED_REG: flag attribute indicating the
 + *   regulatory information was obtained from the private regdomain
 + *   of a device with self-managed regulatory.
 + * @NL80211_ATTR_WIPHY_GET_PRIV_REG: flag attribute indicating the 
 regulatory
 + *   information should be obtained from a device's private regdomain,
 + *   if it exists. This will happen even if the device is not self-managing
 + *   its regulatory.

 As with REGULATORY_WIPHY_SELF_MANAGED we need a flag that cfg80211 sets for
 drivers that use regulatory_hint() API, perhaps REGULATORY_WIPHY_REG_HINT.
 Then this can be used by cfg80211 to send to userspace regdomains for wiphys
 that have used this API. Below you enable userspace to only query for these
 explictly but we want to be able to let userspace get all information, ie
 through 'iw reg get'. This should go in as a separate patch along with
 NL80211_ATTR_WIPHY_GET_PRIV_REG as its use predates
 NL80211_ATTR_WIPHY_SELF_MANAGED_REG, this will also let you stuff in the 
 boiler
 plate code for getting that reg first, getting self managed regd's can then
 go in as a clear secondary evolutionary step.

 The documentation for NL80211_ATTR_WIPHY_GET_PRIV_REG can refer to the new
 %REGULATORY_WIPHY_REG_HINT flag. NL80211_ATTR_WIPHY_SELF_MANAGED_REG should
 refer to %REGULATORY_WIPHY_SELF_MANAGED

 @@ -5346,13 +5345,54 @@ static int nl80211_get_reg(struct sk_buff *skb, 
 struct genl_info *info)
   if (!hdr)
   goto put_failure;

 - if (reg_last_request_cell_base() 
 - nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
 - NL80211_USER_REG_HINT_CELL_BASE))
 - goto nla_put_failure;
 + if (info-attrs[NL80211_ATTR_WIPHY]) {
 + u32 reg_flags;
 + struct wiphy *wiphy;
 + struct cfg80211_registered_device *rdev =
 + cfg80211_get_dev_from_info(genl_info_net(info), info);
 +
 + if (IS_ERR(rdev)) {
 + nlmsg_free(msg);
 + return PTR_ERR(rdev);
 + }
 +
 + wiphy = rdev-wiphy;
 + reg_flags = wiphy-regulatory_flags;
 + if (reg_flags  REGULATORY_WIPHY_SELF_MANAGED ||
 + info-attrs[NL80211_ATTR_WIPHY_GET_PRIV_REG]) {
 + regdom = get_wiphy_regdom(wiphy);
 + if (!regdom) {
 + nlmsg_free(msg);
 + return -EINVAL;
 + }
 +
 + if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
 + rdev-wiphy_idx))
 + goto nla_put_failure;
 +
 + if (reg_flags  REGULATORY_WIPHY_SELF_MANAGED 
 + nla_put_flag(msg,
 +  NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
 + goto nla_put_failure

Re: [PATCH v3 1/3] cfg80211: leave invalid channels on regdomain change

2014-11-26 Thread Arik Nemtsov
On Tue, Nov 25, 2014 at 9:38 PM, Luis R. Rodriguez mcg...@suse.com wrote:
 On Sun, Nov 23, 2014 at 05:02:19PM +0200, Arik Nemtsov wrote:
 When the regulatory settings change, some channels might become invalid.
 Disconnect interfaces acting on these channels, after giving userspace
 code a grace period to leave them.

 This mode is currently opt-in, and not all interface operating modes are
 supported for regulatory-enforcement checks. A wiphy that wishes to use
 the new enforcement code must specify an appropriate regulatory flag,
 and all its supported interface modes must be supported by the chekcing
 code.

 This is all looking beter now, since I had a few requests for the last patch
 I'll ask for some other things here without asking  to negage the flag purpose
 as I originally wanted.

 Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
 ---
  include/net/regulatory.h |   6 +++
  net/wireless/core.c  |  13 ++
  net/wireless/reg.c   | 106 
 ++-
  3 files changed, 124 insertions(+), 1 deletion(-)

 diff --git a/include/net/regulatory.h b/include/net/regulatory.h
 index dad7ab2..701177c 100644
 --- a/include/net/regulatory.h
 +++ b/include/net/regulatory.h
 @@ -136,6 +136,11 @@ struct regulatory_request {
   *  otherwise initiating radiation is not allowed. This will enable the
   *  relaxations enabled under the CFG80211_REG_RELAX_NO_IR configuration
   *  option
 + * @REGULATORY_ENFORCE_CHANNELS: the regulatory core will make sure all
 + *   interfaces on this wiphy reside on allowed channels. Upon a regdomain
 + *   change, the interfaces are given a grace period to disconnect or move
 + *   to an allowed channels. Interfaces on forbidden channels are forcibly
 + *   disconnected.

 Please rename to REGULATORY_IGNORE_STALE_KICKOFF, also please add
 some information about the amount current of grace period used,
 and types of interfaces supported. Since this is a regulatory flag
 this information will help folks decide whether to enable or not.
 Also encourage its use, and mention that once all supported devices
 get support for this will be enabled by default. In the meantime
 I'd prefer if this feature was enabled by default if the supported
 interface types of a dveice match the white list of supported
 interfaces.

btw, I think you meant REGULATORY_STALE_KICKOFF, since it's an opt-in flag.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 1/4] cfg80211: leave invalid channels on regdomain change

2014-11-26 Thread Arik Nemtsov
When the regulatory settings change, some channels might become invalid.
Disconnect interfaces acting on these channels, after giving userspace
code a grace period to leave them.

This mode is currently opt-in, and not all interface operating modes are
supported for regulatory-enforcement checks. A wiphy that wishes to use
the new enforcement code must specify an appropriate regulatory flag,
and all its supported interface modes must be supported by the chekcing
code.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 include/net/regulatory.h |  12 ++
 net/wireless/core.c  |  11 +
 net/wireless/reg.c   | 107 ++-
 3 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index dad7ab2..b776d72 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -136,6 +136,17 @@ struct regulatory_request {
  *  otherwise initiating radiation is not allowed. This will enable the
  *  relaxations enabled under the CFG80211_REG_RELAX_NO_IR configuration
  *  option
+ * @REGULATORY_IGNORE_STALE_KICKOFF: the regulatory core will _not_ make sure
+ * all interfaces on this wiphy reside on allowed channels. If this flag
+ * is not set, upon a regdomain change, the interfaces are given a grace
+ * period (currently 60 seconds) to disconnect or move to an allowed
+ * channel. Interfaces on forbidden channels are forcibly disconnected.
+ * Currently these types of interfaces are supported for enforcement:
+ * NL80211_IFTYPE_ADHOC, NL80211_IFTYPE_STATION, NL80211_IFTYPE_AP,
+ * NL80211_IFTYPE_AP_VLAN, NL80211_IFTYPE_MONITOR,
+ * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
+ * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
+ * includes any modes unsupported for enforcement checking.
  */
 enum ieee80211_regulatory_flags {
REGULATORY_CUSTOM_REG   = BIT(0),
@@ -144,6 +155,7 @@ enum ieee80211_regulatory_flags {
REGULATORY_COUNTRY_IE_FOLLOW_POWER  = BIT(3),
REGULATORY_COUNTRY_IE_IGNORE= BIT(4),
REGULATORY_ENABLE_RELAX_NO_IR   = BIT(5),
+   REGULATORY_IGNORE_STALE_KICKOFF = BIT(6),
 };
 
 struct ieee80211_freq_range {
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 4c2e501..ef0d3a0 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -546,6 +546,17 @@ int wiphy_register(struct wiphy *wiphy)
 !rdev-ops-tdls_cancel_channel_switch)))
return -EINVAL;
 
+   /*
+* if a wiphy has unsupported modes for regulatory channel enforcement,
+* opt-out of enforcement checking
+*/
+   if (wiphy-interface_modes  ~(BIT(NL80211_IFTYPE_STATION) |
+   BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_AP) |
+   BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_ADHOC) |
+   BIT(NL80211_IFTYPE_P2P_DEVICE) | BIT(NL80211_IFTYPE_AP_VLAN) |
+   BIT(NL80211_IFTYPE_MONITOR)))
+   wiphy-regulatory_flags |= REGULATORY_IGNORE_STALE_KICKOFF;
+
if (WARN_ON(wiphy-coalesce 
(!wiphy-coalesce-n_rules ||
 !wiphy-coalesce-n_patterns) 
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 32d8310..47be616 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -56,6 +56,7 @@
 #include net/cfg80211.h
 #include core.h
 #include reg.h
+#include rdev-ops.h
 #include regdb.h
 #include nl80211.h
 
@@ -66,6 +67,12 @@
 #define REG_DBG_PRINT(args...)
 #endif
 
+/*
+ * Grace period we give before making sure all current interfaces reside on
+ * channels allowed by the current regulatory domain.
+ */
+#define REG_ENFORCE_GRACE_MS 6
+
 /**
  * enum reg_request_treatment - regulatory request treatment
  *
@@ -210,6 +217,9 @@ struct reg_beacon {
struct ieee80211_channel chan;
 };
 
+static void reg_check_chans_work(struct work_struct *work);
+static DECLARE_DELAYED_WORK(reg_check_chans, reg_check_chans_work);
+
 static void reg_todo(struct work_struct *work);
 static DECLARE_WORK(reg_work, reg_todo);
 
@@ -1518,6 +1528,96 @@ static void reg_call_notifier(struct wiphy *wiphy,
wiphy-reg_notifier(wiphy, request);
 }
 
+static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev)
+{
+   struct ieee80211_channel *ch;
+   struct cfg80211_chan_def chandef;
+   struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
+   bool ret = true;
+
+   wdev_lock(wdev);
+
+   if (!wdev-netdev || !netif_running(wdev-netdev))
+   goto out;
+
+   switch (wdev-iftype) {
+   case NL80211_IFTYPE_AP:
+   case NL80211_IFTYPE_P2P_GO:
+   if (!wdev-beacon_interval)
+   goto out;
+
+   ret = cfg80211_reg_can_beacon(wiphy,
+ wdev-chandef, wdev

[PATCH v4 4/4] cfg80211: return private regdom for self-managed devices

2014-11-26 Thread Arik Nemtsov
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 arikx.nemt...@intel.com
---
 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;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 2/4] cfg80211: allow wiphy specific regdomain management

2014-11-26 Thread Arik Nemtsov
From: Jonathan Doron j...@wizery.com

Add a new regulatory flag that allows a driver to manage regdomain
changes/updates for its own wiphy.
A self-managed wiphys only employs regulatory information obtained from
the FW and driver and does not use other cfg80211 sources like
beacon-hints, country-code IEs and hints from other devices on the same
system. Conversely, a self-managed wiphy does not share its regulatory
hints with other devices in the system. If a system contains several
devices, one or more of which are self-managed, there might be
contradictory regulatory settings between them. Usage of flag is
generally discouraged. Only use it if the FW/driver is incompatible
with non-locally originated hints.

A new API lets the driver send a complete regdomain, to be applied on
its wiphy only.

After a wiphy-specific regdomain change takes place, usermode will get
a new type of change notification. The regulatory core also takes care
enforce regulatory restrictions, in case some interfaces are on
forbidden channels.

Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 include/net/cfg80211.h   | 20 +++
 include/net/regulatory.h | 19 ++
 include/uapi/linux/nl80211.h |  5 +++
 net/wireless/core.c  |  8 +
 net/wireless/nl80211.c   | 80 +++--
 net/wireless/nl80211.h   |  1 +
 net/wireless/reg.c   | 84 
 7 files changed, 199 insertions(+), 18 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index bb748c4..60f46f6 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2971,6 +2971,10 @@ struct wiphy_vendor_command {
  * the regulatory_hint() API. This can be used by the driver
  * on the reg_notifier() if it chooses to ignore future
  * regulatory domain changes caused by other drivers.
+ * @requested_regd: the driver requests the regulatory core to set this
+ * regulatory domain as the wiphy's. Only used for
+ * %REGULATORY_WIPHY_SELF_MANAGED devices using the
+ * regulatory_set_wiphy_regd() API
  * @signal_type: signal type reported in struct cfg80211_bss.
  * @cipher_suites: supported cipher suites
  * @n_cipher_suites: number of supported cipher suites
@@ -3183,6 +3187,8 @@ struct wiphy {
 
const struct ieee80211_regdomain __rcu *regd;
 
+   const struct ieee80211_regdomain *requested_regd;
+
/* the item in /sys/class/ieee80211/ points to this,
 * you need use set_wiphy_dev() (see below) */
struct device dev;
@@ -3808,6 +3814,20 @@ const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 
oui_type,
 int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
 
 /**
+ * regulatory_set_wiphy_regd - set regdom info for self managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain informatoin to use for this wiphy
+ *
+ * Set the regulatory domain information for self-managed wiphys, only they
+ * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
+ * information.
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index b776d72..d72b9a3 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -147,6 +147,24 @@ struct regulatory_request {
  * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
  * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
  * includes any modes unsupported for enforcement checking.
+ * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
+ * regdom management. These devices will ignore all regdom changes not
+ * originating from their own wiphy.
+ * A self-managed wiphys only employs regulatory information obtained from
+ * the FW and driver and does not use other cfg80211 sources like
+ * beacon-hints, country-code IEs and hints from other devices on the same
+ * system. Conversely, a self-managed wiphy does not share its regulatory
+ * hints with other devices in the system. If a system contains several
+ * devices, one or more of which are self-managed, there might be
+ * contradictory regulatory settings between them. Usage of flag is
+ * generally discouraged. Only use it if the FW/driver is incompatible
+ * with non-locally originated hints.
+ * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
+ * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER

[PATCH v4 3/4] cfg80211: allow usermode to query wiphy specific regdom

2014-11-26 Thread Arik Nemtsov
If a wiphy-idx is specified, the kernel will return the wiphy specific
regdomain, if such exists. Otherwise return the global regdom.

When no wiphy-idx is specified, return the global regdomain as well as
all wiphy-specific regulatory domains in the system, via a new nested
list of attributes.

Add a new attribute for each wiphy-specific regdomain, for usermode to
identify it as such.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
Rest assured, I have an iw version that prints all the regdomains. I just
need a bit of time to clean it up.

 include/uapi/linux/nl80211.h |  16 +-
 net/wireless/nl80211.c   | 123 +--
 net/wireless/reg.c   |   2 +-
 net/wireless/reg.h   |   1 +
 4 files changed, 111 insertions(+), 31 deletions(-)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 3771e7d..6517210 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -252,7 +252,9 @@
  * %NL80211_ATTR_IFINDEX.
  *
  * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
- * regulatory domain.
+ * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
+ * its private regulatory domain will be returned.
+ * returned, even if it's regulatory is not self-managed.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
@@ -1693,6 +1695,14 @@ enum nl80211_commands {
  *
  * @NL80211_ATTR_MAC_MASK: MAC address mask
  *
+ * @NL80211_ATTR_WIPHY_PRIV_REG: flag attribute indicating the regulatory
+ * information was obtained from the device's wiphy. This can happen
+ * when the driver uses the regulatory_hint() API for setting the device's
+ * regulatory domain.
+ *
+ * @NL80211_ATTR_WIPHY_REGDOM_LIST: Nested set of attributes containing
+ * a list of wiphy specific regdomains.
+ *
  * @NUM_NL80211_ATTR: total number of nl80211_attrs available
  * @NL80211_ATTR_MAX: highest attribute number currently defined
  * @__NL80211_ATTR_AFTER_LAST: internal use
@@ -2050,6 +2060,10 @@ enum nl80211_attrs {
 
NL80211_ATTR_MAC_MASK,
 
+   NL80211_ATTR_WIPHY_PRIV_REG,
+
+   NL80211_ATTR_WIPHY_REGDOM_LIST,
+
/* 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 f1e2f59..65bab11 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -396,6 +396,8 @@ static const struct nla_policy 
nl80211_policy[NUM_NL80211_ATTR] = {
[NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
[NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
[NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
+   [NL80211_ATTR_WIPHY_PRIV_REG] = { .type = NLA_FLAG },
+   [NL80211_ATTR_WIPHY_REGDOM_LIST] = { .type = NLA_NESTED },
 };
 
 /* policy for the key attributes */
@@ -5326,42 +5328,20 @@ static int nl80211_update_mesh_config(struct sk_buff 
*skb,
return err;
 }
 
-static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
+static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
+ struct sk_buff *msg)
 {
-   const struct ieee80211_regdomain *regdom;
-   struct sk_buff *msg;
-   void *hdr = NULL;
struct nlattr *nl_reg_rules;
unsigned int i;
 
-   if (!cfg80211_regdomain)
-   return -EINVAL;
-
-   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
-   if (!msg)
-   return -ENOBUFS;
-
-   hdr = nl80211hdr_put(msg, info-snd_portid, info-snd_seq, 0,
-NL80211_CMD_GET_REG);
-   if (!hdr)
-   goto put_failure;
-
-   if (reg_last_request_cell_base() 
-   nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
-   NL80211_USER_REG_HINT_CELL_BASE))
-   goto nla_put_failure;
-
-   rcu_read_lock();
-   regdom = rcu_dereference(cfg80211_regdomain);
-
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom-alpha2) ||
(regdom-dfs_region 
 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom-dfs_region)))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
if (!nl_reg_rules)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
for (i = 0; i  regdom-n_reg_rules; i++) {
struct nlattr *nl_reg_rule;
@@ -5376,7 +5356,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
 
nl_reg_rule = nla_nest_start(msg, i);
if (!nl_reg_rule)
-   goto nla_put_failure_rcu;
+   goto

Re: [PATCH v4 3/4] cfg80211: allow usermode to query wiphy specific regdom

2014-11-26 Thread Arik Nemtsov
On Wed, Nov 26, 2014 at 11:43 PM, Luis R. Rodriguez mcg...@suse.com wrote:
 On Wed, Nov 26, 2014 at 4:35 PM, Luis R. Rodriguez mcg...@suse.com wrote:
 We're not checking here if this was a managed wiphy or not, we
 want userspace to be able to tell if a wiphy was managed or not.

 Ah I see what you did, yes that is what I wanted but since you allowed
 for self managed regdomains *first* the placement of this patch in
 terms of order would mean we are not giving userspace information it
 should have needed right after this commit. After your 4th patch we do
 though. We want commits to work well linearly in history so can you
 move this patch to number 2 in the series and bump number 2 to be
 patch number 3? That way right after commit 2 we are not lying to
 userspace.

 The question about having userspace specify the wiphy still stands as
 I'd expect userspace asking only for a regd for a wiphy would want
 only that one, not all, or the central one.

In general, we want to return only the regdom of the wiphy the user
asked for. And yea, I'll fix it.

But there's a tricky part here. In the not-self-managed case, if a
user specifies a wiphy-idx, and there's no wiphy-regd, we'll return
the global one.
This is fine, since in effect, the global regd is the one used by this
wiphy anyway.
Essentially we want this part to just be able to add the wiphy-idx to
wpa_s code for GET_REG, and remain backward compatible. But like I
said above, it's the right thing to do.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 1/4] cfg80211: leave invalid channels on regdomain change

2014-11-26 Thread Arik Nemtsov
When the regulatory settings change, some channels might become invalid.
Disconnect interfaces acting on these channels, after giving userspace
code a grace period to leave them.

This mode is currently opt-in, and not all interface operating modes are
supported for regulatory-enforcement checks. A wiphy that wishes to use
the new enforcement code must specify an appropriate regulatory flag,
and all its supported interface modes must be supported by the chekcing
code.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/net/regulatory.h |  12 ++
 net/wireless/core.c  |  11 +
 net/wireless/reg.c   | 107 ++-
 3 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index dad7ab2..b776d72 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -136,6 +136,17 @@ struct regulatory_request {
  *  otherwise initiating radiation is not allowed. This will enable the
  *  relaxations enabled under the CFG80211_REG_RELAX_NO_IR configuration
  *  option
+ * @REGULATORY_IGNORE_STALE_KICKOFF: the regulatory core will _not_ make sure
+ * all interfaces on this wiphy reside on allowed channels. If this flag
+ * is not set, upon a regdomain change, the interfaces are given a grace
+ * period (currently 60 seconds) to disconnect or move to an allowed
+ * channel. Interfaces on forbidden channels are forcibly disconnected.
+ * Currently these types of interfaces are supported for enforcement:
+ * NL80211_IFTYPE_ADHOC, NL80211_IFTYPE_STATION, NL80211_IFTYPE_AP,
+ * NL80211_IFTYPE_AP_VLAN, NL80211_IFTYPE_MONITOR,
+ * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
+ * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
+ * includes any modes unsupported for enforcement checking.
  */
 enum ieee80211_regulatory_flags {
REGULATORY_CUSTOM_REG   = BIT(0),
@@ -144,6 +155,7 @@ enum ieee80211_regulatory_flags {
REGULATORY_COUNTRY_IE_FOLLOW_POWER  = BIT(3),
REGULATORY_COUNTRY_IE_IGNORE= BIT(4),
REGULATORY_ENABLE_RELAX_NO_IR   = BIT(5),
+   REGULATORY_IGNORE_STALE_KICKOFF = BIT(6),
 };
 
 struct ieee80211_freq_range {
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 4c2e501..ef0d3a0 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -546,6 +546,17 @@ int wiphy_register(struct wiphy *wiphy)
 !rdev-ops-tdls_cancel_channel_switch)))
return -EINVAL;
 
+   /*
+* if a wiphy has unsupported modes for regulatory channel enforcement,
+* opt-out of enforcement checking
+*/
+   if (wiphy-interface_modes  ~(BIT(NL80211_IFTYPE_STATION) |
+   BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_AP) |
+   BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_ADHOC) |
+   BIT(NL80211_IFTYPE_P2P_DEVICE) | BIT(NL80211_IFTYPE_AP_VLAN) |
+   BIT(NL80211_IFTYPE_MONITOR)))
+   wiphy-regulatory_flags |= REGULATORY_IGNORE_STALE_KICKOFF;
+
if (WARN_ON(wiphy-coalesce 
(!wiphy-coalesce-n_rules ||
 !wiphy-coalesce-n_patterns) 
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 32d8310..47be616 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -56,6 +56,7 @@
 #include net/cfg80211.h
 #include core.h
 #include reg.h
+#include rdev-ops.h
 #include regdb.h
 #include nl80211.h
 
@@ -66,6 +67,12 @@
 #define REG_DBG_PRINT(args...)
 #endif
 
+/*
+ * Grace period we give before making sure all current interfaces reside on
+ * channels allowed by the current regulatory domain.
+ */
+#define REG_ENFORCE_GRACE_MS 6
+
 /**
  * enum reg_request_treatment - regulatory request treatment
  *
@@ -210,6 +217,9 @@ struct reg_beacon {
struct ieee80211_channel chan;
 };
 
+static void reg_check_chans_work(struct work_struct *work);
+static DECLARE_DELAYED_WORK(reg_check_chans, reg_check_chans_work);
+
 static void reg_todo(struct work_struct *work);
 static DECLARE_WORK(reg_work, reg_todo);
 
@@ -1518,6 +1528,96 @@ static void reg_call_notifier(struct wiphy *wiphy,
wiphy-reg_notifier(wiphy, request);
 }
 
+static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev)
+{
+   struct ieee80211_channel *ch;
+   struct cfg80211_chan_def chandef;
+   struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
+   bool ret = true;
+
+   wdev_lock(wdev);
+
+   if (!wdev-netdev || !netif_running(wdev-netdev))
+   goto out;
+
+   switch (wdev-iftype) {
+   case NL80211_IFTYPE_AP:
+   case NL80211_IFTYPE_P2P_GO:
+   if (!wdev-beacon_interval)
+   goto out;
+
+   ret = cfg80211_reg_can_beacon(wiphy

[PATCH v5 4/4] cfg80211: return private regdom for self-managed devices

2014-11-26 Thread Arik Nemtsov
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 arikx.nemt...@intel.com
---
 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;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 3/4] cfg80211: allow wiphy specific regdomain management

2014-11-26 Thread Arik Nemtsov
From: Jonathan Doron j...@wizery.com

Add a new regulatory flag that allows a driver to manage regdomain
changes/updates for its own wiphy.
A self-managed wiphys only employs regulatory information obtained from
the FW and driver and does not use other cfg80211 sources like
beacon-hints, country-code IEs and hints from other devices on the same
system. Conversely, a self-managed wiphy does not share its regulatory
hints with other devices in the system. If a system contains several
devices, one or more of which are self-managed, there might be
contradictory regulatory settings between them. Usage of flag is
generally discouraged. Only use it if the FW/driver is incompatible
with non-locally originated hints.

A new API lets the driver send a complete regdomain, to be applied on
its wiphy only.

After a wiphy-specific regdomain change takes place, usermode will get
a new type of change notification. The regulatory core also takes care
enforce regulatory restrictions, in case some interfaces are on
forbidden channels.

Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Luis R. Rodriguez mcg...@suse.com
---
 include/net/cfg80211.h   | 20 +++
 include/net/regulatory.h | 19 ++
 include/uapi/linux/nl80211.h |  5 +++
 net/wireless/core.c  |  8 +
 net/wireless/nl80211.c   | 80 +++--
 net/wireless/nl80211.h   |  1 +
 net/wireless/reg.c   | 84 
 7 files changed, 199 insertions(+), 18 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index bb748c4..60f46f6 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2971,6 +2971,10 @@ struct wiphy_vendor_command {
  * the regulatory_hint() API. This can be used by the driver
  * on the reg_notifier() if it chooses to ignore future
  * regulatory domain changes caused by other drivers.
+ * @requested_regd: the driver requests the regulatory core to set this
+ * regulatory domain as the wiphy's. Only used for
+ * %REGULATORY_WIPHY_SELF_MANAGED devices using the
+ * regulatory_set_wiphy_regd() API
  * @signal_type: signal type reported in struct cfg80211_bss.
  * @cipher_suites: supported cipher suites
  * @n_cipher_suites: number of supported cipher suites
@@ -3183,6 +3187,8 @@ struct wiphy {
 
const struct ieee80211_regdomain __rcu *regd;
 
+   const struct ieee80211_regdomain *requested_regd;
+
/* the item in /sys/class/ieee80211/ points to this,
 * you need use set_wiphy_dev() (see below) */
struct device dev;
@@ -3808,6 +3814,20 @@ const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 
oui_type,
 int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
 
 /**
+ * regulatory_set_wiphy_regd - set regdom info for self managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain informatoin to use for this wiphy
+ *
+ * Set the regulatory domain information for self-managed wiphys, only they
+ * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
+ * information.
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index b776d72..d72b9a3 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -147,6 +147,24 @@ struct regulatory_request {
  * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
  * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
  * includes any modes unsupported for enforcement checking.
+ * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
+ * regdom management. These devices will ignore all regdom changes not
+ * originating from their own wiphy.
+ * A self-managed wiphys only employs regulatory information obtained from
+ * the FW and driver and does not use other cfg80211 sources like
+ * beacon-hints, country-code IEs and hints from other devices on the same
+ * system. Conversely, a self-managed wiphy does not share its regulatory
+ * hints with other devices in the system. If a system contains several
+ * devices, one or more of which are self-managed, there might be
+ * contradictory regulatory settings between them. Usage of flag is
+ * generally discouraged. Only use it if the FW/driver is incompatible
+ * with non-locally originated hints.
+ * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
+ * %REGULATORY_STRICT_REG

[PATCH v5 2/4] cfg80211: allow usermode to query wiphy specific regdom

2014-11-26 Thread Arik Nemtsov
If a wiphy-idx is specified, the kernel will return the wiphy specific
regdomain, if such exists. Otherwise return the global regdom.

When no wiphy-idx is specified, return the global regdomain as well as
all wiphy-specific regulatory domains in the system, via a new nested
list of attributes.

Add a new attribute for each wiphy-specific regdomain, for usermode to
identify it as such.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
v5: don't return all regdomains if a specific wiphy is requested

 include/uapi/linux/nl80211.h |  16 +-
 net/wireless/nl80211.c   | 127 +--
 net/wireless/reg.c   |   2 +-
 net/wireless/reg.h   |   1 +
 4 files changed, 115 insertions(+), 31 deletions(-)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index d775245..1f2f7d6 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -252,7 +252,9 @@
  * %NL80211_ATTR_IFINDEX.
  *
  * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
- * regulatory domain.
+ * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
+ * has a private regulatory domain, it will be returned. Otherwise, the
+ * global regdomain will be returned.
  * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
  * after being queried by the kernel. CRDA replies by sending a regulatory
  * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
@@ -1688,6 +1690,14 @@ enum nl80211_commands {
  *
  * @NL80211_ATTR_MAC_MASK: MAC address mask
  *
+ * @NL80211_ATTR_WIPHY_PRIV_REG: flag attribute indicating the regulatory
+ * information was obtained from the device's wiphy. This can happen
+ * when the driver uses the regulatory_hint() API for setting the device's
+ * regulatory domain.
+ *
+ * @NL80211_ATTR_WIPHY_REGDOM_LIST: Nested set of attributes containing
+ * a list of wiphy specific regdomains.
+ *
  * @NUM_NL80211_ATTR: total number of nl80211_attrs available
  * @NL80211_ATTR_MAX: highest attribute number currently defined
  * @__NL80211_ATTR_AFTER_LAST: internal use
@@ -2045,6 +2055,10 @@ enum nl80211_attrs {
 
NL80211_ATTR_MAC_MASK,
 
+   NL80211_ATTR_WIPHY_PRIV_REG,
+
+   NL80211_ATTR_WIPHY_REGDOM_LIST,
+
/* 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 b5e3c48..ddee3ba 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -396,6 +396,8 @@ static const struct nla_policy 
nl80211_policy[NUM_NL80211_ATTR] = {
[NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
[NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
[NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
+   [NL80211_ATTR_WIPHY_PRIV_REG] = { .type = NLA_FLAG },
+   [NL80211_ATTR_WIPHY_REGDOM_LIST] = { .type = NLA_NESTED },
 };
 
 /* policy for the key attributes */
@@ -5326,42 +5328,20 @@ static int nl80211_update_mesh_config(struct sk_buff 
*skb,
return err;
 }
 
-static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
+static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
+ struct sk_buff *msg)
 {
-   const struct ieee80211_regdomain *regdom;
-   struct sk_buff *msg;
-   void *hdr = NULL;
struct nlattr *nl_reg_rules;
unsigned int i;
 
-   if (!cfg80211_regdomain)
-   return -EINVAL;
-
-   msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
-   if (!msg)
-   return -ENOBUFS;
-
-   hdr = nl80211hdr_put(msg, info-snd_portid, info-snd_seq, 0,
-NL80211_CMD_GET_REG);
-   if (!hdr)
-   goto put_failure;
-
-   if (reg_last_request_cell_base() 
-   nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
-   NL80211_USER_REG_HINT_CELL_BASE))
-   goto nla_put_failure;
-
-   rcu_read_lock();
-   regdom = rcu_dereference(cfg80211_regdomain);
-
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom-alpha2) ||
(regdom-dfs_region 
 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom-dfs_region)))
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
if (!nl_reg_rules)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
for (i = 0; i  regdom-n_reg_rules; i++) {
struct nlattr *nl_reg_rule;
@@ -5376,7 +5356,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct 
genl_info *info)
 
nl_reg_rule = nla_nest_start(msg, i);
if (!nl_reg_rule)
-   goto nla_put_failure_rcu;
+   goto nla_put_failure;
 
max_bandwidth_khz

[PATCH v3 2/3] cfg80211: allow wiphy specific regdomain management

2014-11-23 Thread Arik Nemtsov
From: Jonathan Doron j...@wizery.com

Add a new regulatory flag that allows a driver to manage regdomain
changes/updates for its own wiphy.
A self-managed wiphys only employs regulatory information obtained from
the FW and driver and does not use other cfg80211 sources like
beacon-hints, country-code IEs and hints from other devices on the same
system. Conversely, a self-managed wiphy does not share its regulatory
hints with other devices in the system. If a system contains several
devices, one or more of which are self-managed, there might be
contradictory regulatory settings between them. Usage of flag is
generally discouraged. Only use it if the FW/driver is incompatible
with non-locally originated hints.

A new API lets the driver send a complete regdomain, to be applied on
its wiphy only.

After a wiphy-specific regdomain change takes place, usermode will get
a new type of change notification. The regulatory core also takes care
enforce regulatory restrictions, in case some interfaces are on
forbidden channels.

Signed-off-by: Jonathan Doron jonathanx.do...@intel.com
Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
---
 include/net/cfg80211.h   | 16 +
 include/net/regulatory.h | 19 +++
 include/uapi/linux/nl80211.h |  5 +++
 net/wireless/core.c  |  8 +
 net/wireless/nl80211.c   | 80 ++--
 net/wireless/nl80211.h   |  1 +
 net/wireless/reg.c   | 59 
 7 files changed, 170 insertions(+), 18 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index bb748c4..bfe630f 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -3808,6 +3808,22 @@ const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 
oui_type,
 int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
 
 /**
+ * regulatory_set_wiphy_regd_rtnl - set regdom info for self managed drivers
+ * @wiphy: the wireless device we want to process the regulatory domain on
+ * @rd: the regulatory domain informatoin to use for this wiphy
+ *
+ * Set the regulatory domain information for self-managed wiphys, only they
+ * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
+ * information.
+ *
+ * This function requires the caller to hold the rtnl_lock.
+ *
+ * Return: 0 on success. -EINVAL, -EPERM
+ */
+int regulatory_set_wiphy_regd_rtnl(struct wiphy *wiphy,
+  struct ieee80211_regdomain *rd);
+
+/**
  * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
  * @wiphy: the wireless device we want to process the regulatory domain on
  * @regd: the custom regulatory domain to use for this wiphy
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index 701177c..d69c3db 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -141,6 +141,24 @@ struct regulatory_request {
  * change, the interfaces are given a grace period to disconnect or move
  * to an allowed channels. Interfaces on forbidden channels are forcibly
  * disconnected.
+ * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
+ * regdom management. These devices will ignore all regdom changes not
+ * originating from their own wiphy.
+ * A self-managed wiphys only employs regulatory information obtained from
+ * the FW and driver and does not use other cfg80211 sources like
+ * beacon-hints, country-code IEs and hints from other devices on the same
+ * system. Conversely, a self-managed wiphy does not share its regulatory
+ * hints with other devices in the system. If a system contains several
+ * devices, one or more of which are self-managed, there might be
+ * contradictory regulatory settings between them. Usage of flag is
+ * generally discouraged. Only use it if the FW/driver is incompatible
+ * with non-locally originated hints.
+ * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
+ * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER,
+ * %REGULATORY_COUNTRY_IE_IGNORE and %REGULATORY_DISABLE_BEACON_HINTS.
+ * Mixing any of the above flags with this flag will result in a failure
+ * to register the wiphy. This flag implies
+ * %REGULATORY_DISABLE_BEACON_HINTS.
  */
 enum ieee80211_regulatory_flags {
REGULATORY_CUSTOM_REG   = BIT(0),
@@ -150,6 +168,7 @@ enum ieee80211_regulatory_flags {
REGULATORY_COUNTRY_IE_IGNORE= BIT(4),
REGULATORY_ENABLE_RELAX_NO_IR   = BIT(5),
REGULATORY_ENFORCE_CHANNELS = BIT(6),
+   REGULATORY_WIPHY_SELF_MANAGED   = BIT(7),
 };
 
 struct ieee80211_freq_range {
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index d775245..3771e7d 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -774,6 +774,9 @@
  * peer given by %NL80211_ATTR_MAC. Both peers

Re: [PATCH v2 3/4] cfg80211: allow wiphy specific regdomain management

2014-11-21 Thread Arik Nemtsov
On Thu, Nov 20, 2014 at 10:27 PM, Luis R. Rodriguez mcg...@suse.com wrote:
 On Sun, Nov 16, 2014 at 01:06:00PM +0200, Arik Nemtsov wrote:
 On Fri, Nov 14, 2014 at 1:11 AM, Luis R. Rodriguez mcg...@suse.com wrote:
  index a4d2792..656a1b1 100644
  --- a/net/wireless/core.c
  +++ b/net/wireless/core.c
  @@ -541,6 +541,13 @@ int wiphy_register(struct wiphy *wiphy)
!wiphy-wowlan-tcp))
return -EINVAL;
   #endif
  + if (WARN_ON((wiphy-regulatory_flags  
  REGULATORY_WIPHY_SELF_MANAGED) 
  + (wiphy-regulatory_flags 
  +  (REGULATORY_CUSTOM_REG | REGULATORY_STRICT_REG |
  +   REGULATORY_COUNTRY_IE_FOLLOW_POWER |
  +   REGULATORY_COUNTRY_IE_IGNORE |
  +   REGULATORY_DISABLE_BEACON_HINTS
  + return -EINVAL;
 
  Look at all those heuristics go away... That's alot. The documetnation 
  should
  reflect all this not being used because of this decision. I also want you 
  to
  think of the issues that may come up when combining devices that, one that
  uses this feature and one that does not.

 Since this is a private regdomain, I guess this just means the
 cfg80211 using device will be alone in the system for all regulatory
 purposes.
 I don't really see possible interoperability issues here. Am I missing
 something?

 It means you can technically end up with two devices that operate with
 different interpretation of rules, this can mean for example that some
 expectations of having two devices may fail and since this will be all hard
 coded you can't fix it.  The worst of the issues will be caused by the fact
 that we simply won't know what issues will creep up until the two data sets
 conflict and create an unexpected user facing issue. This is precicely why
 having support for querying information about all regulatory data is critical,
 and I'm glad you are doing that work.

 What will happen when say a user / user interface wants to restrict all 
 devices
 to say a country like Israel, 'iw reg set IL' is used, so the cfg80211 
 regulatory
 abiding devices follow the rules, but this Intel device does not?

It's nice that you've used IL in your example :)

An Intel device would basically stay in mode 00 until the FW decides
via a modem or other indication that it is in IL. At that point we
will send regulatory_hint_regd() notification.
The Intel device doesn't use/trust other devices.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 4/4] cfg80211: Allow usermode to query wiphy specific regd info

2014-11-21 Thread Arik Nemtsov
On Thu, Nov 20, 2014 at 10:54 PM, Luis R. Rodriguez mcg...@suse.com wrote:

 Then it gets the global one, and it knows it via a wiphy attribute:

   (wiphy-regulatory_flags  REGULATORY_WIPHY_SELF_MANAGED) 
 +   (nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)))
 +   goto nla_put_failure;

 (we won't do this put_flag if it's global)

 You can still follow this on wpa_s for REGULATORY_WIPHY_SELF_MANAGED, and
 the other type that uses wiphy-regd would still follow the global regdomain.
 The other flag I'm looking for is more informational for userspace in 
 particular
 'iw reg get' (for central and all devices) or 'iw reg get dev wlan0'.

I'm not sure why another flag is needed for userspace. If we have
SELF_MANAGED, we'll return the per-wiphy one (if a wiphy_idx is given
to us of course). For validation purposes, the global one is used in
other cases. And for CUSTOM_REG, we'll return the global one (we don't
have the per-wiphy information in cfg80211).

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 11/16] cfg80211: introduce TDLS channel switch commands

2014-11-19 Thread Arik Nemtsov
Introduce commands to initiate and cancel TDLS channel-switching. Once
TDLS channel-switching is started, the lower level driver is responsible
for continually initiating channel-switch operations and returning to
the base (AP) channel to listen for beacons from time to time.

Upon cancellation of the channel-switch all communication between the
relevant TDLS peers will continue on the base channel.

Signed-off-by: Arik Nemtsov arikx.nemt...@intel.com
Reviewed-by: Johannes Berg johannes.b...@intel.com
---
v2: document the operating class attribute

 include/net/cfg80211.h   |  14 ++
 include/uapi/linux/nl80211.h |  19 
 net/wireless/core.c  |   4 ++
 net/wireless/nl80211.c   | 108 +++
 net/wireless/rdev-ops.h  |  24 ++
 net/wireless/trace.h |  42 +
 6 files changed, 211 insertions(+)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 220d5f5..8d04dfe 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2367,6 +2367,12 @@ struct cfg80211_qos_map {
  * (invoked with the wireless_dev mutex held)
  * @leave_ocb: leave the current OCB network
  * (invoked with the wireless_dev mutex held)
+ *
+ * @tdls_channel_switch: Start channel-switching with a TDLS peer. The driver
+ * is responsible for continually initiating channel-switching operations
+ * and returning to the base channel for communication with the AP.
+ * @tdls_cancel_channel_switch: Stop channel-switching with a TDLS peer. Both
+ * peers must be on the base channel when the call completes.
  */
 struct cfg80211_ops {
int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -2622,6 +2628,14 @@ struct cfg80211_ops {
 u16 admitted_time);
int (*del_tx_ts)(struct wiphy *wiphy, struct net_device *dev,
 u8 tsid, const u8 *peer);
+
+   int (*tdls_channel_switch)(struct wiphy *wiphy,
+  struct net_device *dev,
+  const u8 *addr, u8 oper_class,
+  struct cfg80211_chan_def *chandef);
+   void(*tdls_cancel_channel_switch)(struct wiphy *wiphy,
+ struct net_device *dev,
+ const u8 *addr);
 };
 
 /*
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index ccdeef2..365db67 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -762,6 +762,18 @@
  * @NL80211_CMD_LEAVE_OCB: Leave the OCB network -- no special arguments, the
  * network is determined by the network interface.
  *
+ * @NL80211_CMD_TDLS_CHANNEL_SWITCH: Start channel-switching with a TDLS peer,
+ * identified by the %NL80211_ATTR_MAC parameter. A target channel is
+ * provided via %NL80211_ATTR_WIPHY_FREQ and other attributes determining
+ * channel width/type. The target operating class is given via
+ * %NL80211_ATTR_OPER_CLASS.
+ * The driver is responsible for continually initiating channel-switching
+ * operations and returning to the base channel for communication with the
+ * AP.
+ * @NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH: Stop channel-switching with a TDLS
+ * peer given by %NL80211_ATTR_MAC. Both peers must be on the base channel
+ * when this command completes.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -943,6 +955,9 @@ enum nl80211_commands {
 
NL80211_CMD_CH_SWITCH_STARTED_NOTIFY,
 
+   NL80211_CMD_TDLS_CHANNEL_SWITCH,
+   NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
+
/* add new commands above here */
 
/* used to define NL80211_CMD_MAX below */
@@ -1669,6 +1684,8 @@ enum nl80211_commands {
  * @NL80211_ATTR_SMPS_MODE: SMPS mode to use (ap mode). see
  * enum nl80211_smps_mode.
  *
+ * @NL80211_ATTR_OPER_CLASS: operating class
+ *
  * @NL80211_ATTR_MAX: highest attribute number currently defined
  * @__NL80211_ATTR_AFTER_LAST: internal use
  */
@@ -2021,6 +2038,8 @@ enum nl80211_attrs {
 
NL80211_ATTR_SMPS_MODE,
 
+   NL80211_ATTR_OPER_CLASS,
+
/* add attributes here, update the policy in nl80211.c */
 
__NL80211_ATTR_AFTER_LAST,
diff --git a/net/wireless/core.c b/net/wireless/core.c
index a4d2792..4c2e501 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -541,6 +541,10 @@ int wiphy_register(struct wiphy *wiphy)
!wiphy-wowlan-tcp))
return -EINVAL;
 #endif
+   if (WARN_ON((wiphy-features  NL80211_FEATURE_TDLS_CHANNEL_SWITCH) 
+   (!rdev-ops-tdls_channel_switch ||
+!rdev-ops-tdls_cancel_channel_switch)))
+   return -EINVAL;
 
if (WARN_ON(wiphy-coalesce 
(!wiphy-coalesce-n_rules ||
diff --git a/net/wireless

Re: [PATCH 16/16] mac80211: synchronously reserve TID per station

2014-11-19 Thread Arik Nemtsov
On Wed, Nov 19, 2014 at 1:22 PM, Johannes Berg
johan...@sipsolutions.net wrote:
 On Sun, 2014-11-09 at 18:50 +0200, Arik Nemtsov wrote:

 + if (WARN_ON(tid = IEEE80211_NUM_TIDS))
 + return -EINVAL;

 That validates  16

 + queues = BIT(sdata-vif.hw_queue[ieee802_1d_to_ac[tid]]);

 but that's only valid for  8, causing a smatch warning.

It's a valid warning. It should be tid  7 here. I'll send a fix.

Arik
--
To unsubscribe from this list: send the line unsubscribe linux-wireless in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   >