2014-02-12 18:54:38

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

Introduce DFS CAC time as a regd param, configured
per REG_RULE and set per channel in cfg80211.
DFS CAC time is close connected with regulatory
database configuration. Instead of using hardcoded
values, get DFS CAC time form regulatory database.
Pass DFS CAC time to user mode (mainly for iw reg get,
iw list, iw info). Allow setting DFS CAC time via CRDA.

Signed-off-by: Janusz Dziedzic <[email protected]>
---
include/net/cfg80211.h | 2 ++
include/net/regulatory.h | 21 +++++++++++++--------
include/uapi/linux/nl80211.h | 6 ++++++
net/wireless/nl80211.c | 13 ++++++++++++-
net/wireless/reg.c | 39 +++++++++++++++++++++++++++++++--------
5 files changed, 64 insertions(+), 17 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 9f90554..e1ea2ed 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -151,6 +151,7 @@ enum ieee80211_channel_flags {
* @dfs_state: current state of this channel. Only relevant if radar is required
* on this channel.
* @dfs_state_entered: timestamp (jiffies) when the dfs state was entered.
+ * @dfs_cac_ms: DFS CAC time in milliseconds, this is valid for DFS channels.
*/
struct ieee80211_channel {
enum ieee80211_band band;
@@ -165,6 +166,7 @@ struct ieee80211_channel {
int orig_mag, orig_mpwr;
enum nl80211_dfs_state dfs_state;
unsigned long dfs_state_entered;
+ unsigned int dfs_cac_ms;
};

/**
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index b07cdc9..75fc1f5 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -155,6 +155,7 @@ struct ieee80211_reg_rule {
struct ieee80211_freq_range freq_range;
struct ieee80211_power_rule power_rule;
u32 flags;
+ u32 dfs_cac_ms;
};

struct ieee80211_regdomain {
@@ -172,14 +173,18 @@ struct ieee80211_regdomain {
#define DBM_TO_MBM(gain) ((gain) * 100)
#define MBM_TO_DBM(gain) ((gain) / 100)

-#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
-{ \
- .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
- .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
- .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
- .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
- .power_rule.max_eirp = DBM_TO_MBM(eirp), \
- .flags = reg_flags, \
+#define REG_RULE_EXT(start, end, bw, gain, eirp, dfs_cac, reg_flags) \
+{ \
+ .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
+ .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
+ .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
+ .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \
+ .power_rule.max_eirp = DBM_TO_MBM(eirp), \
+ .flags = reg_flags, \
+ .dfs_cac_ms = dfs_cac, \
}

+#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
+ REG_RULE_EXT(start, end, bw, gain, eirp, 0, reg_flags)
+
#endif
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index ba1f762..353d61c6 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -2329,6 +2329,7 @@ enum nl80211_band_attr {
* @NL80211_FREQUENCY_ATTR_NO_160MHZ: any 160 MHz (but not 80+80) channel
* using this channel as the primary or any of the secondary channels
* isn't possible
+ * @NL80211_FREQUENCY_ATTR_DFS_CAC_TIME: DFS CAC time in milliseconds.
* @NL80211_FREQUENCY_ATTR_MAX: highest frequency attribute number
* currently defined
* @__NL80211_FREQUENCY_ATTR_AFTER_LAST: internal use
@@ -2347,6 +2348,7 @@ enum nl80211_frequency_attr {
NL80211_FREQUENCY_ATTR_NO_HT40_PLUS,
NL80211_FREQUENCY_ATTR_NO_80MHZ,
NL80211_FREQUENCY_ATTR_NO_160MHZ,
+ NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,

/* keep last */
__NL80211_FREQUENCY_ATTR_AFTER_LAST,
@@ -2446,6 +2448,8 @@ enum nl80211_reg_type {
* If you don't have one then don't send this.
* @NL80211_ATTR_POWER_RULE_MAX_EIRP: the maximum allowed EIRP for
* a given frequency range. The value is in mBm (100 * dBm).
+ * @NL80211_ATTR_DFS_CAC_TIME: DFS CAC time in milliseconds.
+ * If not present or 0 default CAC time will be used.
* @NL80211_REG_RULE_ATTR_MAX: highest regulatory rule attribute number
* currently defined
* @__NL80211_REG_RULE_ATTR_AFTER_LAST: internal use
@@ -2461,6 +2465,8 @@ enum nl80211_reg_rule_attr {
NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
NL80211_ATTR_POWER_RULE_MAX_EIRP,

+ NL80211_ATTR_DFS_CAC_TIME,
+
/* keep last */
__NL80211_REG_RULE_ATTR_AFTER_LAST,
NL80211_REG_RULE_ATTR_MAX = __NL80211_REG_RULE_ATTR_AFTER_LAST - 1
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 1797864..0bf69da 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -592,6 +592,10 @@ static int nl80211_msg_put_channel(struct sk_buff *msg,
if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
time))
goto nla_put_failure;
+ if (nla_put_u32(msg,
+ NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
+ chan->dfs_cac_ms))
+ goto nla_put_failure;
}
}

@@ -4612,6 +4616,7 @@ static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] =
[NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
[NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
+ [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
};

static int parse_reg_rule(struct nlattr *tb[],
@@ -4646,6 +4651,10 @@ static int parse_reg_rule(struct nlattr *tb[],
power_rule->max_antenna_gain =
nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);

+ if (tb[NL80211_ATTR_DFS_CAC_TIME])
+ reg_rule->dfs_cac_ms =
+ nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
+
return 0;
}

@@ -5133,7 +5142,9 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
power_rule->max_antenna_gain) ||
nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
- power_rule->max_eirp))
+ power_rule->max_eirp) ||
+ nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
+ reg_rule->dfs_cac_ms))
goto nla_put_failure_rcu;

nla_nest_end(msg, nl_reg_rule);
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 27c5253..c80f20e 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -755,6 +755,11 @@ static int reg_rules_intersect(const struct ieee80211_regdomain *rd1,

intersected_rule->flags = rule1->flags | rule2->flags;

+ if (rule1->dfs_cac_ms > rule2->dfs_cac_ms)
+ intersected_rule->dfs_cac_ms = rule1->dfs_cac_ms;
+ else
+ intersected_rule->dfs_cac_ms = rule2->dfs_cac_ms;
+
if (!is_valid_reg_rule(intersected_rule))
return -EINVAL;

@@ -1067,6 +1072,14 @@ static void handle_channel(struct wiphy *wiphy,
min_t(int, chan->orig_mag,
MBI_TO_DBI(power_rule->max_antenna_gain));
chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp);
+
+ if (chan->flags & IEEE80211_CHAN_RADAR) {
+ if (reg_rule->dfs_cac_ms)
+ chan->dfs_cac_ms = reg_rule->dfs_cac_ms;
+ else
+ chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
+ }
+
if (chan->orig_mpwr) {
/*
* Devices that use REGULATORY_COUNTRY_IE_FOLLOW_POWER
@@ -2245,9 +2258,10 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
const struct ieee80211_reg_rule *reg_rule = NULL;
const struct ieee80211_freq_range *freq_range = NULL;
const struct ieee80211_power_rule *power_rule = NULL;
- char bw[32];
+ const int size = 32;
+ char bw[size], cac_time[size];

- pr_info(" (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)\n");
+ pr_info(" (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)\n");

for (i = 0; i < rd->n_reg_rules; i++) {
reg_rule = &rd->reg_rules[i];
@@ -2255,29 +2269,38 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
power_rule = &reg_rule->power_rule;

if (!freq_range->max_bandwidth_khz)
- snprintf(bw, 32, "%d KHz, AUTO",
+ snprintf(bw, size, "%d KHz, AUTO",
reg_get_max_bandwidth(rd, reg_rule));
else
- snprintf(bw, 32, "%d KHz",
+ snprintf(bw, size, "%d KHz",
freq_range->max_bandwidth_khz);

+ if (reg_rule->flags & NL80211_RRF_DFS)
+ scnprintf(cac_time, size, "%u ms",
+ reg_rule->dfs_cac_ms);
+ else
+ scnprintf(cac_time, size, "N/A");
+
+
/*
* There may not be documentation for max antenna gain
* in certain regions
*/
if (power_rule->max_antenna_gain)
- pr_info(" (%d KHz - %d KHz @ %s), (%d mBi, %d mBm)\n",
+ pr_info(" (%d KHz - %d KHz @ %s), (%d mBi, %d mBm), (%s)\n",
freq_range->start_freq_khz,
freq_range->end_freq_khz,
bw,
power_rule->max_antenna_gain,
- power_rule->max_eirp);
+ power_rule->max_eirp,
+ cac_time);
else
- pr_info(" (%d KHz - %d KHz @ %s), (N/A, %d mBm)\n",
+ pr_info(" (%d KHz - %d KHz @ %s), (N/A, %d mBm), (%s)\n",
freq_range->start_freq_khz,
freq_range->end_freq_khz,
bw,
- power_rule->max_eirp);
+ power_rule->max_eirp,
+ cac_time);
}
}

--
1.7.9.5



2014-02-12 18:54:41

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH 4/4] cfg80211: DFS get CAC time from regulatory

Get CAC time from regulatory database.

Signed-off-by: Janusz Dziedzic <[email protected]>
---
include/net/cfg80211.h | 2 ++
net/wireless/chan.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
net/wireless/core.h | 3 +++
net/wireless/mlme.c | 2 +-
net/wireless/nl80211.c | 8 ++++++-
5 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 14e2671..03951c2 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -3173,6 +3173,7 @@ struct cfg80211_cached_keys;
* @p2p_started: true if this is a P2P Device that has been started
* @cac_started: true if DFS channel availability check has been started
* @cac_start_time: timestamp (jiffies) when the dfs state was entered.
+ * @cac_time_ms: CAC time in ms
* @ps: powersave mode is enabled
* @ps_timeout: dynamic powersave timeout
* @ap_unexpected_nlportid: (private) netlink port ID of application
@@ -3228,6 +3229,7 @@ struct wireless_dev {

bool cac_started;
unsigned long cac_start_time;
+ unsigned int cac_time_ms;

#ifdef CONFIG_CFG80211_WEXT
/* wext data */
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index 5946450..78ba96d 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -490,6 +490,65 @@ static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy,
return r;
}

+static unsigned int cfg80211_get_chans_dfs_cac_time(struct wiphy *wiphy,
+ u32 center_freq,
+ u32 bandwidth)
+{
+ struct ieee80211_channel *c;
+ u32 start_freq, end_freq, freq;
+ unsigned int dfs_cac_ms = 0;
+
+ start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
+ end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
+
+ for (freq = start_freq; freq <= end_freq; freq += 20) {
+ c = ieee80211_get_channel(wiphy, freq);
+ if (!c)
+ return 0;
+
+ if (c->flags & IEEE80211_CHAN_DISABLED)
+ return 0;
+
+ if (!(c->flags & IEEE80211_CHAN_RADAR))
+ continue;
+
+ if (c->dfs_cac_ms > dfs_cac_ms)
+ dfs_cac_ms = c->dfs_cac_ms;
+ }
+
+ return dfs_cac_ms;
+}
+
+unsigned int
+cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy,
+ const struct cfg80211_chan_def *chandef)
+{
+ int width;
+ unsigned int t1 = 0, t2 = 0;
+
+ if (WARN_ON(!cfg80211_chandef_valid(chandef)))
+ return 0;
+
+ width = cfg80211_chandef_get_width(chandef);
+ if (width < 0)
+ return 0;
+
+ t1 = cfg80211_get_chans_dfs_cac_time(wiphy,
+ chandef->center_freq1,
+ width);
+
+ if (!chandef->center_freq2)
+ return t1;
+
+ t2 = cfg80211_get_chans_dfs_cac_time(wiphy,
+ chandef->center_freq2,
+ width);
+
+ if (t2 > t1)
+ t1 = t2;
+
+ return t1;
+}

static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
u32 center_freq, u32 bandwidth,
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 9895ab1..78be8cd 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -400,6 +400,9 @@ void cfg80211_set_dfs_state(struct wiphy *wiphy,

void cfg80211_dfs_channels_update_work(struct work_struct *work);

+unsigned int
+cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy,
+ const struct cfg80211_chan_def *chandef);

static inline int
cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index d47c9d1..c52ff59 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -778,7 +778,7 @@ void cfg80211_cac_event(struct net_device *netdev,
switch (event) {
case NL80211_RADAR_CAC_FINISHED:
timeout = wdev->cac_start_time +
- msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
+ msecs_to_jiffies(wdev->cac_time_ms);
WARN_ON(!time_after_eq(jiffies, timeout));
cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_AVAILABLE);
break;
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 4a4c988..6d28cc2 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5776,6 +5776,7 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
struct wireless_dev *wdev = dev->ieee80211_ptr;
struct cfg80211_chan_def chandef;
enum nl80211_dfs_regions dfs_region;
+ unsigned int cac_time_ms;
int err;

dfs_region = reg_get_dfs_region(wdev->wiphy);
@@ -5811,12 +5812,17 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
if (err)
return err;

+ cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
+ if (WARN_ON(!cac_time_ms))
+ cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
+
err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
- IEEE80211_DFS_MIN_CAC_TIME_MS);
+ cac_time_ms);
if (!err) {
wdev->chandef = chandef;
wdev->cac_started = true;
wdev->cac_start_time = jiffies;
+ wdev->cac_time_ms = cac_time_ms;
}
return err;
}
--
1.7.9.5


2014-02-21 08:54:54

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 4/4] cfg80211: DFS get CAC time from regulatory

On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:

> + if (t2 > t1)
> + t1 = t2;
> +
> + return t1;

return max(t1, t2);

Is there any real reason to split patches 3/4? It seems to me they
should go together.

johannes


2014-02-21 09:55:38

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On Fri, 2014-02-21 at 10:47 +0100, Janusz Dziedzic wrote:
> On 21 February 2014 09:52, Johannes Berg <[email protected]> wrote:
> > On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:
> >
> >> +++ b/include/net/regulatory.h
> >> @@ -155,6 +155,7 @@ struct ieee80211_reg_rule {
> >> struct ieee80211_freq_range freq_range;
> >> struct ieee80211_power_rule power_rule;
> >> u32 flags;
> >> + u32 dfs_cac_ms;
> >> };
> >
> > Does that really have to be per channel? That's a significant investment
> > into bss size since we have a lot of channel structs.
> >
> This seems easiest way to handle ETSI VHT80/40 case for channels with
> different CAC time (eg):
> VHT80:
> - 116 (60s)
> - 120 (600s)
> - 124 (600s)
> - 128 (600s)
>
> VHT40/HT40:
> - 132 (600s)
> - 136 (60s)

Huh, but you don't distinguish between channel widths in this whole
patchset?

johannes


2014-02-21 10:12:04

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On Fri, 2014-02-21 at 11:09 +0100, Janusz Dziedzic wrote:
> On 21 February 2014 10:55, Johannes Berg <[email protected]> wrote:
> > On Fri, 2014-02-21 at 10:47 +0100, Janusz Dziedzic wrote:
> >> On 21 February 2014 09:52, Johannes Berg <[email protected]> wrote:
> >> > On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:
> >> >
> >> >> +++ b/include/net/regulatory.h
> >> >> @@ -155,6 +155,7 @@ struct ieee80211_reg_rule {
> >> >> struct ieee80211_freq_range freq_range;
> >> >> struct ieee80211_power_rule power_rule;
> >> >> u32 flags;
> >> >> + u32 dfs_cac_ms;
> >> >> };
> >> >
> >> > Does that really have to be per channel? That's a significant investment
> >> > into bss size since we have a lot of channel structs.
> >> >
> >> This seems easiest way to handle ETSI VHT80/40 case for channels with
> >> different CAC time (eg):
> >> VHT80:
> >> - 116 (60s)
> >> - 120 (600s)
> >> - 124 (600s)
> >> - 128 (600s)
> >>
> >> VHT40/HT40:
> >> - 132 (600s)
> >> - 136 (60s)
> >
> > Huh, but you don't distinguish between channel widths in this whole
> > patchset?
> >
> In patch cfg80211: DFS get CAC time from regulatory I check whole
> chandef and get max channel cac value.

Oh, right, I misunderstood your other email.

johannes


2014-02-19 22:12:03

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On Wed, Feb 19, 2014 at 3:28 AM, Johannes Berg
<[email protected]> wrote:
> Ah ok, thanks.

Let me know if you merge this so I can apply and push the respective
patch for CRDA. Not sure if you saw but as proposed this means this
bumps the wireless-regdb format. Janusz, I see you submitted a
respective patch for iw and CRDA but not one for wireless-regdb, we'll
need one there in order to parse the new entries in db.txt.

John, this should mean we will need two releases for wireless-regdb
moving on so that older versions of CRDA can read the new rules under
the old format. Another option may be to have wireless-regdb spit out
the file in two formats and we modify the new CRDA to jump to the new
format section if it supports it. Otherwise I'm afraid we get stuck
with the latest rules for old kernels forever, or we make a branch on
wireless-regdb for the old format.

Thoughts folks?

Luis

2014-02-19 11:27:48

by Janusz Dziedzic

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On 19 February 2014 12:03, Johannes Berg <[email protected]> wrote:
> On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:
>
>> -#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
>> -{ \
>> - .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
>> - .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
>> - .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
>> - .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
>> - .power_rule.max_eirp = DBM_TO_MBM(eirp), \
>> - .flags = reg_flags, \
>> +#define REG_RULE_EXT(start, end, bw, gain, eirp, dfs_cac, reg_flags) \
>> +{ \
>> + .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
>> + .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
>> + .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
>> + .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \
>> + .power_rule.max_eirp = DBM_TO_MBM(eirp), \
>> + .flags = reg_flags, \
>> + .dfs_cac_ms = dfs_cac, \
>> }
>>
>> +#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
>> + REG_RULE_EXT(start, end, bw, gain, eirp, 0, reg_flags)
>
> I don't see any users of this, is that really useful?
>

genregdb.awk using this when internal regdb is used.

BR
Janusz

2014-02-22 00:31:36

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On Wed, Feb 19, 2014 at 11:12 PM, Janusz Dziedzic
<[email protected]> wrote:
> We can allow VERSION=19 and VERSION=20, and handle this in CRDA
> dynamically. This should be quite easy.

My point was what about older versions of CRDA that get a new
wireless-regdb tossed onto the system?

Luis

2014-02-19 11:03:30

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:

> -#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
> -{ \
> - .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
> - .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
> - .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
> - .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
> - .power_rule.max_eirp = DBM_TO_MBM(eirp), \
> - .flags = reg_flags, \
> +#define REG_RULE_EXT(start, end, bw, gain, eirp, dfs_cac, reg_flags) \
> +{ \
> + .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
> + .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
> + .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
> + .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \
> + .power_rule.max_eirp = DBM_TO_MBM(eirp), \
> + .flags = reg_flags, \
> + .dfs_cac_ms = dfs_cac, \
> }
>
> +#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
> + REG_RULE_EXT(start, end, bw, gain, eirp, 0, reg_flags)

I don't see any users of this, is that really useful?

johannes


2014-02-21 08:53:48

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 3/4] cfg80211/mac80211: DFS pass CAC time as a parameter

Regarding the subject, the '/mac80211' part should probably not be there
since it's just an API update and the real change is in cfg80211.

johannes


2014-02-21 08:52:34

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:

> +++ b/include/net/regulatory.h
> @@ -155,6 +155,7 @@ struct ieee80211_reg_rule {
> struct ieee80211_freq_range freq_range;
> struct ieee80211_power_rule power_rule;
> u32 flags;
> + u32 dfs_cac_ms;
> };

Does that really have to be per channel? That's a significant investment
into bss size since we have a lot of channel structs.

> + if (rule1->dfs_cac_ms > rule2->dfs_cac_ms)
> + intersected_rule->dfs_cac_ms = rule1->dfs_cac_ms;
> + else
> + intersected_rule->dfs_cac_ms = rule2->dfs_cac_ms;

please just use max() or max_t() if needed (shouldn't be)

> @@ -2245,9 +2258,10 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
> const struct ieee80211_reg_rule *reg_rule = NULL;
> const struct ieee80211_freq_range *freq_range = NULL;
> const struct ieee80211_power_rule *power_rule = NULL;
> - char bw[32];
> + const int size = 32;
> + char bw[size], cac_time[size];

I don't like that, size is const but it seems likely that sparse/smatch
may complain. I've already changed some of the below code to just use
sizeof(bw), please do that here as well.

johannes


2014-02-12 18:54:40

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH 3/4] cfg80211/mac80211: DFS pass CAC time as a parameter

Send Channel Availability Check time as a parameter
of start_radar_detection() callback.
We will get this time from regulatory database.

Signed-off-by: Janusz Dziedzic <[email protected]>
---
include/net/cfg80211.h | 3 ++-
net/mac80211/cfg.c | 8 ++++----
net/wireless/nl80211.c | 3 ++-
3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index e1ea2ed..14e2671 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2499,7 +2499,8 @@ struct cfg80211_ops {

int (*start_radar_detection)(struct wiphy *wiphy,
struct net_device *dev,
- struct cfg80211_chan_def *chandef);
+ struct cfg80211_chan_def *chandef,
+ u32 cac_time_ms);
int (*update_ft_ies)(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_update_ft_ies_params *ftie);
int (*crit_proto_start)(struct wiphy *wiphy,
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 7f01f2ae..f504205 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -2912,11 +2912,11 @@ static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,

static int ieee80211_start_radar_detection(struct wiphy *wiphy,
struct net_device *dev,
- struct cfg80211_chan_def *chandef)
+ struct cfg80211_chan_def *chandef,
+ u32 cac_time_ms)
{
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
struct ieee80211_local *local = sdata->local;
- unsigned long timeout;
int err;

mutex_lock(&local->mtx);
@@ -2935,9 +2935,9 @@ static int ieee80211_start_radar_detection(struct wiphy *wiphy,
if (err)
goto out_unlock;

- timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
ieee80211_queue_delayed_work(&sdata->local->hw,
- &sdata->dfs_cac_timer_work, timeout);
+ &sdata->dfs_cac_timer_work,
+ msecs_to_jiffies(cac_time_ms));

out_unlock:
mutex_unlock(&local->mtx);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 0bf69da..4a4c988 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5811,7 +5811,8 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
if (err)
return err;

- err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
+ err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
+ IEEE80211_DFS_MIN_CAC_TIME_MS);
if (!err) {
wdev->chandef = chandef;
wdev->cac_started = true;
--
1.7.9.5


2014-02-12 18:54:44

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH] crda: add DFS CAC time support

Add DFS CAC time support. Get this
value form regulatory.bin file.
Add parsers required by db2rd.

Change REGDB_VERSION while binary file
format was changed little bit (rule structure).

Signed-off-by: Janusz Dziedzic <[email protected]>
---
crda.c | 3 ++
regdb.h | 5 ++-
reglib.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
reglib.h | 1 +
4 files changed, 150 insertions(+), 8 deletions(-)

diff --git a/crda.c b/crda.c
index 4c156a4..2fc5bce 100644
--- a/crda.c
+++ b/crda.c
@@ -132,6 +132,9 @@ static int put_reg_rule(const struct ieee80211_reg_rule *rule, struct nl_msg *ms
NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, power_rule->max_antenna_gain);
NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, power_rule->max_eirp);

+ if (rule->dfs_cac_ms)
+ NLA_PUT_U32(msg, NL80211_ATTR_DFS_CAC_TIME, rule->dfs_cac_ms);
+
return 0;

nla_put_failure:
diff --git a/regdb.h b/regdb.h
index 20f29e9..a940ecd 100644
--- a/regdb.h
+++ b/regdb.h
@@ -21,7 +21,7 @@
* to have some more magic. We still consider this to be
* "Version 1" of the file.
*/
-#define REGDB_VERSION 19
+#define REGDB_VERSION 20

/*
* The signature at the end of the file is an RSA-signed
@@ -106,6 +106,7 @@ struct regdb_file_reg_rule {
uint32_t power_rule_ptr; /* pointer to a struct regdb_file_power_rule */
/* rule flags using enum reg_rule_flags */
uint32_t flags;
+ uint32_t dfs_cac_ms;
};

struct regdb_file_reg_rules_collection {
@@ -142,7 +143,7 @@ static inline void check_db_binary_structs(void)
CHECK_STRUCT(regdb_file_header, 20);
CHECK_STRUCT(regdb_file_freq_range, 12);
CHECK_STRUCT(regdb_file_power_rule, 8);
- CHECK_STRUCT(regdb_file_reg_rule, 12);
+ CHECK_STRUCT(regdb_file_reg_rule, 16);
CHECK_STRUCT(regdb_file_reg_rules_collection, 4);
CHECK_STRUCT(regdb_file_reg_country, 8);
}
diff --git a/reglib.c b/reglib.c
index 7484c11..d8829ff 100644
--- a/reglib.c
+++ b/reglib.c
@@ -326,6 +326,7 @@ static void reg_rule2rd(uint8_t *db, size_t dblen,
rd_power_rule->max_eirp = ntohl(power->max_eirp);

rd_reg_rule->flags = ntohl(rule->flags);
+ rd_reg_rule->dfs_cac_ms = ntohl(rule->dfs_cac_ms);

if (rd_reg_rule->flags & RRF_NO_IR_ALL)
rd_reg_rule->flags |= RRF_NO_IR_ALL;
@@ -734,6 +735,9 @@ static void print_reg_rule(const struct ieee80211_reg_rule *rule)
else
printf("N/A)");

+ if ((rule->flags & RRF_DFS) && rule->dfs_cac_ms)
+ printf(", (%u)", rule->dfs_cac_ms);
+
if (rule->flags & RRF_NO_OFDM)
printf(", NO-OFDM");
if (rule->flags & RRF_NO_CCK)
@@ -822,6 +826,7 @@ reglib_parse_rule_simple(char *line, struct ieee80211_reg_rule *reg_rule)
REGLIB_DBM_TO_MBM(max_eirp);

reg_rule->flags = 0;
+ reg_rule->dfs_cac_ms = 0;

if (debug)
printf("reglib_parse_rule_simple(): %d line: %s", hits, line);
@@ -857,6 +862,7 @@ reglib_parse_rule_simple_mw(char *line, struct ieee80211_reg_rule *reg_rule)
REGLIB_MW_TO_MBM(max_eirp);

reg_rule->flags = 0;
+ reg_rule->dfs_cac_ms = 0;

if (debug)
printf("reglib_parse_rule_simple_mw(): %d line: %s",
@@ -916,6 +922,8 @@ reglib_parse_rule_args(char *line, struct ieee80211_reg_rule *reg_rule)
for (i = 0; i < 8; i++)
reg_rule->flags |= reglib_parse_rule_flag(flag_list[i]);

+ reg_rule->dfs_cac_ms = 0;
+
if (debug)
printf("reglib_parse_rule_args(): %d flags: %d, line: %s",
hits, reg_rule->flags, line);
@@ -978,6 +986,8 @@ reglib_parse_rule_args_mw(char *line, struct ieee80211_reg_rule *reg_rule)
for (i = 0; i < 8; i++)
reg_rule->flags |= reglib_parse_rule_flag(flag_list[i]);

+ reg_rule->dfs_cac_ms = 0;
+
if (debug)
printf("reglib_parse_rule_args_mw(): %d flags: %d, line: %s",
hits, reg_rule->flags, line);
@@ -985,6 +995,130 @@ reglib_parse_rule_args_mw(char *line, struct ieee80211_reg_rule *reg_rule)
#undef IGNORE_COMMA_OR_SPACE
}

+static int
+reglib_parse_rule_args_mw_cac(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+#define IGNORE_COMMA_OR_SPACE "%*[ ,]"
+ int hits;
+ char flag_list[9][100];
+ unsigned int i = 0, dfs_cac_ms;
+ char mw[3];
+ float start_freq_khz, end_freq_khz, max_bandwidth_khz, max_eirp;
+
+ for (i = 0; i < 9; i++)
+ memset(flag_list[i], 0, sizeof(flag_list[i]));
+
+ hits = sscanf(line, "\t(%f - %f @ %f), (%f %2[mW]), (%u),"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s",
+ &start_freq_khz,
+ &end_freq_khz,
+ &max_bandwidth_khz,
+ &max_eirp,
+ mw,
+ &dfs_cac_ms,
+ flag_list[0],
+ flag_list[1],
+ flag_list[2],
+ flag_list[3],
+ flag_list[4],
+ flag_list[5],
+ flag_list[6],
+ flag_list[7],
+ flag_list[8]);
+
+ if (hits < 6)
+ return -EINVAL;
+
+ reg_rule->freq_range.start_freq_khz =
+ REGLIB_MHZ_TO_KHZ(start_freq_khz);
+ reg_rule->freq_range.end_freq_khz =
+ REGLIB_MHZ_TO_KHZ(end_freq_khz);
+ reg_rule->freq_range.max_bandwidth_khz =
+ REGLIB_MHZ_TO_KHZ(max_bandwidth_khz);
+ reg_rule->power_rule.max_eirp =
+ REGLIB_MW_TO_MBM(max_eirp);
+
+ for (i = 0; i < 8; i++)
+ reg_rule->flags |= reglib_parse_rule_flag(flag_list[i]);
+
+ reg_rule->dfs_cac_ms = dfs_cac_ms;
+
+ if (debug)
+ printf("reglib_parse_rule_args_mw_cac(): %d flags: %d, line: %s",
+ hits, reg_rule->flags, line);
+ return 0;
+#undef IGNORE_COMMA_OR_SPACE
+}
+
+static int
+reglib_parse_rule_args_cac(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+#define IGNORE_COMMA_OR_SPACE "%*[ ,]"
+ int hits;
+ char flag_list[9][100];
+ unsigned int i = 0, dfs_cac_ms;
+ float start_freq_khz, end_freq_khz, max_bandwidth_khz, max_eirp;
+
+ for (i = 0; i < 9; i++)
+ memset(flag_list[i], 0, sizeof(flag_list[i]));
+
+ hits = sscanf(line, "\t(%f - %f @ %f), (%f), (%u)"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s"
+ IGNORE_COMMA_OR_SPACE "%s",
+ &start_freq_khz,
+ &end_freq_khz,
+ &max_bandwidth_khz,
+ &max_eirp,
+ &dfs_cac_ms,
+ flag_list[0],
+ flag_list[1],
+ flag_list[2],
+ flag_list[3],
+ flag_list[4],
+ flag_list[5],
+ flag_list[6],
+ flag_list[7],
+ flag_list[8]);
+
+ if (hits < 6)
+ return -EINVAL;
+
+ reg_rule->freq_range.start_freq_khz =
+ REGLIB_MHZ_TO_KHZ(start_freq_khz);
+ reg_rule->freq_range.end_freq_khz =
+ REGLIB_MHZ_TO_KHZ(end_freq_khz);
+ reg_rule->freq_range.max_bandwidth_khz =
+ REGLIB_MHZ_TO_KHZ(max_bandwidth_khz);
+ reg_rule->power_rule.max_eirp =
+ REGLIB_DBM_TO_MBM(max_eirp);
+
+ for (i = 0; i < 8; i++)
+ reg_rule->flags |= reglib_parse_rule_flag(flag_list[i]);
+
+ reg_rule->dfs_cac_ms = dfs_cac_ms;
+
+ if (debug)
+ printf("reglib_parse_rule_args_cac(): %d flags: %d, line: %s",
+ hits, reg_rule->flags, line);
+
+ return 0;
+#undef IGNORE_COMMA_OR_SPACE
+}
static int reglib_parse_rule(FILE *fp, struct ieee80211_reg_rule *reg_rule)
{
char line[1024];
@@ -993,24 +1127,27 @@ static int reglib_parse_rule(FILE *fp, struct ieee80211_reg_rule *reg_rule)
int r = 0;
struct reglib_rule_parse_list *reglib_rule_parsers;
size_t size_parsers = sizeof(struct reglib_rule_parse_list) +
- 4 * sizeof(int (*)(char *, struct ieee80211_reg_rule *));
+ 6 * sizeof(int (*)(char *, struct ieee80211_reg_rule *));

reglib_rule_parsers = malloc(size_parsers);
if (!reglib_rule_parsers)
return -EINVAL;
memset(reglib_rule_parsers, 0, size_parsers);

- reglib_rule_parsers->n_parsers = 4;
+ reglib_rule_parsers->n_parsers = 6;
+

/*
* XXX: sscanf() is a bit odd with picking up mW
* case over the simple one, this order however works,
* gotta figure out how to be more precise.
*/
- reglib_rule_parsers->rule_parsers[0] = reglib_parse_rule_args_mw;
- reglib_rule_parsers->rule_parsers[1] = reglib_parse_rule_args;
- reglib_rule_parsers->rule_parsers[2] = reglib_parse_rule_simple;
- reglib_rule_parsers->rule_parsers[3] = reglib_parse_rule_simple_mw;
+ reglib_rule_parsers->rule_parsers[0] = reglib_parse_rule_args_mw_cac;
+ reglib_rule_parsers->rule_parsers[1] = reglib_parse_rule_args_cac;
+ reglib_rule_parsers->rule_parsers[2] = reglib_parse_rule_args_mw;
+ reglib_rule_parsers->rule_parsers[3] = reglib_parse_rule_args;
+ reglib_rule_parsers->rule_parsers[4] = reglib_parse_rule_simple;
+ reglib_rule_parsers->rule_parsers[5] = reglib_parse_rule_simple_mw;

memset(line, 0, sizeof(line));
line_p = fgets(line, sizeof(line), fp);
diff --git a/reglib.h b/reglib.h
index d570c36..75b14bc 100644
--- a/reglib.h
+++ b/reglib.h
@@ -28,6 +28,7 @@ struct ieee80211_reg_rule {
struct ieee80211_freq_range freq_range;
struct ieee80211_power_rule power_rule;
uint32_t flags;
+ uint32_t dfs_cac_ms;
};

struct ieee80211_regdomain {
--
1.7.9.5


2014-02-21 10:09:10

by Janusz Dziedzic

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On 21 February 2014 10:55, Johannes Berg <[email protected]> wrote:
> On Fri, 2014-02-21 at 10:47 +0100, Janusz Dziedzic wrote:
>> On 21 February 2014 09:52, Johannes Berg <[email protected]> wrote:
>> > On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:
>> >
>> >> +++ b/include/net/regulatory.h
>> >> @@ -155,6 +155,7 @@ struct ieee80211_reg_rule {
>> >> struct ieee80211_freq_range freq_range;
>> >> struct ieee80211_power_rule power_rule;
>> >> u32 flags;
>> >> + u32 dfs_cac_ms;
>> >> };
>> >
>> > Does that really have to be per channel? That's a significant investment
>> > into bss size since we have a lot of channel structs.
>> >
>> This seems easiest way to handle ETSI VHT80/40 case for channels with
>> different CAC time (eg):
>> VHT80:
>> - 116 (60s)
>> - 120 (600s)
>> - 124 (600s)
>> - 128 (600s)
>>
>> VHT40/HT40:
>> - 132 (600s)
>> - 136 (60s)
>
> Huh, but you don't distinguish between channel widths in this whole
> patchset?
>
In patch cfg80211: DFS get CAC time from regulatory I check whole
chandef and get max channel cac value.

BR
Janusz

2014-02-20 07:12:23

by Janusz Dziedzic

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On 19 February 2014 23:11, Luis R. Rodriguez <[email protected]> wrote:
> On Wed, Feb 19, 2014 at 3:28 AM, Johannes Berg
> <[email protected]> wrote:
>> Ah ok, thanks.
>
> Let me know if you merge this so I can apply and push the respective
> patch for CRDA. Not sure if you saw but as proposed this means this
> bumps the wireless-regdb format. Janusz, I see you submitted a
> respective patch for iw and CRDA but not one for wireless-regdb, we'll
> need one there in order to parse the new entries in db.txt.
>
[PATCH] wireless-regdb: add DFS CAC time parameter

This one parse CAC time in wireless-regdb. I also change VERSION while
binary format was changed.
Didn't touch db.txt while will work as today (CAC = 0 - default CAC
time defined in mac80211).

> John, this should mean we will need two releases for wireless-regdb
> moving on so that older versions of CRDA can read the new rules under
> the old format. Another option may be to have wireless-regdb spit out
> the file in two formats and we modify the new CRDA to jump to the new
> format section if it supports it. Otherwise I'm afraid we get stuck
> with the latest rules for old kernels forever, or we make a branch on
> wireless-regdb for the old format.
>
We can allow VERSION=19 and VERSION=20, and handle this in CRDA
dynamically. This should be quite easy.

> Thoughts folks?
>
> Luis

2014-02-21 09:47:07

by Janusz Dziedzic

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On 21 February 2014 09:52, Johannes Berg <[email protected]> wrote:
> On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:
>
>> +++ b/include/net/regulatory.h
>> @@ -155,6 +155,7 @@ struct ieee80211_reg_rule {
>> struct ieee80211_freq_range freq_range;
>> struct ieee80211_power_rule power_rule;
>> u32 flags;
>> + u32 dfs_cac_ms;
>> };
>
> Does that really have to be per channel? That's a significant investment
> into bss size since we have a lot of channel structs.
>
This seems easiest way to handle ETSI VHT80/40 case for channels with
different CAC time (eg):
VHT80:
- 116 (60s)
- 120 (600s)
- 124 (600s)
- 128 (600s)

VHT40/HT40:
- 132 (600s)
- 136 (60s)

>> + if (rule1->dfs_cac_ms > rule2->dfs_cac_ms)
>> + intersected_rule->dfs_cac_ms = rule1->dfs_cac_ms;
>> + else
>> + intersected_rule->dfs_cac_ms = rule2->dfs_cac_ms;
>
> please just use max() or max_t() if needed (shouldn't be)
>
OK

>> @@ -2245,9 +2258,10 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
>> const struct ieee80211_reg_rule *reg_rule = NULL;
>> const struct ieee80211_freq_range *freq_range = NULL;
>> const struct ieee80211_power_rule *power_rule = NULL;
>> - char bw[32];
>> + const int size = 32;
>> + char bw[size], cac_time[size];
>
> I don't like that, size is const but it seems likely that sparse/smatch
> may complain. I've already changed some of the below code to just use
> sizeof(bw), please do that here as well.
>
OK

BR
Janusz

2014-02-12 18:54:45

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH] iw: handle DFS CAC time param

Handle DFS CAC time param for
iw list/info, iw reg get

Signed-off-by: Janusz Dziedzic <[email protected]>
---
info.c | 3 +++
reg.c | 6 ++++++
2 files changed, 9 insertions(+)

diff --git a/info.c b/info.c
index a696503..073f3a3 100644
--- a/info.c
+++ b/info.c
@@ -199,6 +199,9 @@ next:
printf(" (for %lu sec)", time/1000);
}
printf("\n");
+ if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME])
+ printf("\t\t\t DFS CAC time: %u ms\n",
+ nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]));
}

}
diff --git a/reg.c b/reg.c
index f2481fe..e1bb0d2 100644
--- a/reg.c
+++ b/reg.c
@@ -134,6 +134,7 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
[NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
[NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
+ [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
};

nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
@@ -181,6 +182,11 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)

printf(", %d)", MBM_TO_DBM(max_eirp_mbm));

+ if ((flags & NL80211_RRF_DFS) && tb_rule[NL80211_ATTR_DFS_CAC_TIME])
+ printf(", (%u ms)", nla_get_u32(tb_rule[NL80211_ATTR_DFS_CAC_TIME]));
+ else
+ printf(", (N/A)");
+
if (!flags) {
printf("\n");
continue;
--
1.7.9.5


2014-02-12 18:54:39

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH 2/4] cfg80211: parse DFS CAC time for internal regdb option

Add support for parsing DFS CAC time when internal
regulatory database is used.

Signed-off-by: Janusz Dziedzic <[email protected]>
---
net/wireless/genregdb.awk | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
index 9a8217d..7683b47 100644
--- a/net/wireless/genregdb.awk
+++ b/net/wireless/genregdb.awk
@@ -66,6 +66,7 @@ function parse_reg_rule()
units = $8
sub(/\)/, "", units)
sub(/,/, "", units)
+ dfs_cac = $9
if (units == "mW") {
if (power == 100) {
power = 20
@@ -78,7 +79,12 @@ function parse_reg_rule()
} else {
print "Unknown power value in database!"
}
+ } else {
+ dfs_cac = $8
}
+ sub(/,/, "", dfs_cac)
+ sub(/\(/, "", dfs_cac)
+ sub(/\)/, "", dfs_cac)
flagstr = ""
for (i=8; i<=NF; i++)
flagstr = flagstr $i
@@ -109,7 +115,7 @@ function parse_reg_rule()

}
flags = flags "0"
- printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags
+ printf "\t\tREG_RULE_EXT(%d, %d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, dfs_cac, flags
rules++
}

--
1.7.9.5


2014-02-12 18:54:43

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH] wireless-regdb: add DFS CAC time parameter

Introduce support for setting DFS CAC time
in milliseconds.

Eg.
(5250 - 5330 @ AUTO), (20), (60000), DFS

will setup CAC 60 seconds CAC time.

Signed-off-by: Janusz Dziedzic <[email protected]>
---
db2bin.py | 6 +++---
dbparse.py | 17 +++++++++++++----
2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/db2bin.py b/db2bin.py
index 41d3741..f6c3bc1 100755
--- a/db2bin.py
+++ b/db2bin.py
@@ -7,7 +7,7 @@ from dbparse import DBParser
import sys

MAGIC = 0x52474442
-VERSION = 19
+VERSION = 20

if len(sys.argv) < 3:
print 'Usage: %s output-file input-file [key-file]' % sys.argv[0]
@@ -93,8 +93,8 @@ for reg_rule in rules:
freq_range, power_rule = reg_rule.freqband, reg_rule.power
reg_rules[reg_rule] = output.tell()
# struct regdb_file_reg_rule
- output.write(struct.pack('>III', freq_ranges[freq_range], power_rules[power_rule],
- reg_rule.flags))
+ output.write(struct.pack('>IIII', freq_ranges[freq_range], power_rules[power_rule],
+ reg_rule.flags, reg_rule.cac_time))


reg_rules_collections = {}
diff --git a/dbparse.py b/dbparse.py
index 7c7bc19..f79de2a 100755
--- a/dbparse.py
+++ b/dbparse.py
@@ -76,12 +76,13 @@ class FlagError(Exception):
self.flag = flag

class Permission(object):
- def __init__(self, freqband, power, flags):
+ def __init__(self, freqband, power, flags, cac_time):
assert isinstance(freqband, FreqBand)
assert isinstance(power, PowerRestriction)
self.freqband = freqband
self.power = power
self.flags = 0
+ self.cac_time = cac_time
for flag in flags:
if not flag in flag_definitions:
raise FlagError(flag)
@@ -89,7 +90,7 @@ class Permission(object):
self.textflags = flags

def _as_tuple(self):
- return (self.freqband, self.power, self.flags)
+ return (self.freqband, self.power, self.flags, self.cac_time)

def __cmp__(self, other):
if not isinstance(other, Permission):
@@ -256,6 +257,7 @@ class DBParser(object):
self._comments = []

def _parse_country_item(self, line):
+ cac_time = 0
if line[0] == '(':
try:
band, line = line[1:].split('),', 1)
@@ -284,7 +286,14 @@ class DBParser(object):
flags = []
else:
pname = items[0]
- flags = items[1].split(',')
+ pcac = items[1]
+ if pcac[0] == '(':
+ cac, flags = pcac.split('),', 1)
+ flags = flags.split(',')
+ cac_time = int(cac[1:])
+ else:
+ flags = items[1].split(',')
+
power = pname[1:]
pname = 'UNNAMED %d' % self._lineno
self._parse_power_def(pname, power, dupwarn=False)
@@ -305,7 +314,7 @@ class DBParser(object):
b = self._bands[bname]
p = self._power[pname]
try:
- perm = Permission(b, p, flags)
+ perm = Permission(b, p, flags, cac_time)
except FlagError, e:
self._syntax_error("Invalid flag '%s'" % e.flag)
for cname, c in self._current_countries.iteritems():
--
1.7.9.5


2014-02-19 11:28:15

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On Wed, 2014-02-19 at 12:27 +0100, Janusz Dziedzic wrote:
> On 19 February 2014 12:03, Johannes Berg <[email protected]> wrote:
> > On Wed, 2014-02-12 at 19:54 +0100, Janusz Dziedzic wrote:
> >
> >> -#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
> >> -{ \
> >> - .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
> >> - .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
> >> - .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
> >> - .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
> >> - .power_rule.max_eirp = DBM_TO_MBM(eirp), \
> >> - .flags = reg_flags, \
> >> +#define REG_RULE_EXT(start, end, bw, gain, eirp, dfs_cac, reg_flags) \
> >> +{ \
> >> + .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
> >> + .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
> >> + .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
> >> + .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \
> >> + .power_rule.max_eirp = DBM_TO_MBM(eirp), \
> >> + .flags = reg_flags, \
> >> + .dfs_cac_ms = dfs_cac, \
> >> }
> >>
> >> +#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
> >> + REG_RULE_EXT(start, end, bw, gain, eirp, 0, reg_flags)
> >
> > I don't see any users of this, is that really useful?
> >
>
> genregdb.awk using this when internal regdb is used.

Ah ok, thanks.

johannes


2014-02-19 00:31:39

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [PATCH 1/4] cfg80211: regulatory, introduce DFS CAC time

On Wed, Feb 12, 2014 at 10:54 AM, Janusz Dziedzic
<[email protected]> wrote:
> Introduce DFS CAC time as a regd param, configured
> per REG_RULE and set per channel in cfg80211.
> DFS CAC time is close connected with regulatory
> database configuration. Instead of using hardcoded
> values, get DFS CAC time form regulatory database.
> Pass DFS CAC time to user mode (mainly for iw reg get,
> iw list, iw info). Allow setting DFS CAC time via CRDA.
>
> Signed-off-by: Janusz Dziedzic <[email protected]>

Reviewed-by: Luis R. Rodriguez <[email protected]>

Please also send a respective patch follow up (v2) that also addresses
the intersection of the cac time on the userspace equivalent of the
intersection.

Luis

2014-05-20 18:48:33

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [PATCH] wireless-regdb: add DFS CAC time parameter

On Tue, May 20, 2014 at 11:24 AM, Johannes Berg
<[email protected]> wrote:
> On Tue, 2014-05-20 at 14:08 -0400, John W. Linville wrote:
>
>> > I can add support for version 19 and 20 in one crda. I am not sure
>> > this is the best option.
>> > BTW what about versions < 19? How do we handle this this days?
>>
>> What about older CRDA with newer wireless-regdb? Do we need to worry about that?
>
> I think we should, but if we can't then at least can we cut to an
> extensible format?

Janusz,

this is in short part of the work I expect to be dealt with as part of
the change. What I think we should strive for since we have control
over the format, is have extensions which upkeep old CRDA versions
working, and only if new CRDA is present would we use the new
attributes. Please see if this is possible.

Luis

2014-05-21 18:15:26

by John W. Linville

[permalink] [raw]
Subject: Re: [PATCH] wireless-regdb: add DFS CAC time parameter

On Wed, May 21, 2014 at 06:03:53PM +0200, Johannes Berg wrote:
> On Tue, 2014-05-20 at 11:48 -0700, Luis R. Rodriguez wrote:
>
> > > I think we should, but if we can't then at least can we cut to an
> > > extensible format?
>
> I don't see any way to extend the format right now.
>
> There's a wrinkle with making it more extensible too though - if we do
> that then we must be extremely careful that future older crda versions
> (i.e. the next version that we're about to write) will not parse a newer
> extended file more permissively, so our extensions are limited anyway.
>
> Looks like the format update really is needed, which probably means we
> should change the scripts to generate two databases and change the
> filename, or so?

The 'do not parse more permissively' would seem to be a problem if
we still produce an older format too, no? I mean, wouldn't we have
to simply drop new rules to produce an older binary? Even worse if
we left the old binary in place, since then you could never update
any rules for old crda installations at all.

It seems like forcing a crda update to use any new format-breaking
rules might just be the right thing. Can we make crda choke and die
loudly when it sees an unknown format? Will the current crda do that?

John
--
John W. Linville Someday the world will need a hero, and you
[email protected] might be all we have. Be ready.

2014-05-20 18:24:58

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] wireless-regdb: add DFS CAC time parameter

On Tue, 2014-05-20 at 14:08 -0400, John W. Linville wrote:

> > I can add support for version 19 and 20 in one crda. I am not sure
> > this is the best option.
> > BTW what about versions < 19? How do we handle this this days?
>
> What about older CRDA with newer wireless-regdb? Do we need to worry about that?

I think we should, but if we can't then at least can we cut to an
extensible format?

(and yeah, I know I was part of defining the format ...)

johannes


2014-05-21 16:04:17

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] wireless-regdb: add DFS CAC time parameter

On Tue, 2014-05-20 at 11:48 -0700, Luis R. Rodriguez wrote:

> > I think we should, but if we can't then at least can we cut to an
> > extensible format?

I don't see any way to extend the format right now.

There's a wrinkle with making it more extensible too though - if we do
that then we must be extremely careful that future older crda versions
(i.e. the next version that we're about to write) will not parse a newer
extended file more permissively, so our extensions are limited anyway.

Looks like the format update really is needed, which probably means we
should change the scripts to generate two databases and change the
filename, or so?

johannes


2014-05-21 19:09:38

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] wireless-regdb: add DFS CAC time parameter

On Wed, 2014-05-21 at 14:00 -0400, John W. Linville wrote:

> The 'do not parse more permissively' would seem to be a problem if
> we still produce an older format too, no? I mean, wouldn't we have
> to simply drop new rules to produce an older binary? Even worse if
> we left the old binary in place, since then you could never update
> any rules for old crda installations at all.

That's true, in a sense.

> It seems like forcing a crda update to use any new format-breaking
> rules might just be the right thing. Can we make crda choke and die
> loudly when it sees an unknown format? Will the current crda do that?

It will, yes. If the version number is mismatched it'll print "Invalid
database version" (to stderr) and exit.

johannes


2014-06-09 07:33:54

by Janusz Dziedzic

[permalink] [raw]
Subject: Re: [PATCH] wireless-regdb: add DFS CAC time parameter

On 21 May 2014 21:09, Johannes Berg <[email protected]> wrote:
> On Wed, 2014-05-21 at 14:00 -0400, John W. Linville wrote:
>
>> The 'do not parse more permissively' would seem to be a problem if
>> we still produce an older format too, no? I mean, wouldn't we have
>> to simply drop new rules to produce an older binary? Even worse if
>> we left the old binary in place, since then you could never update
>> any rules for old crda installations at all.
>
> That's true, in a sense.
>
>> It seems like forcing a crda update to use any new format-breaking
>> rules might just be the right thing. Can we make crda choke and die
>> loudly when it sees an unknown format? Will the current crda do that?
>
> It will, yes. If the version number is mismatched it'll print "Invalid
> database version" (to stderr) and exit.
>

Why not just skip this binary interface between regdb --> crda and use
signed db.txt file?

Eg.
1) first we sign db.txt file using gpg - that will be all what
wireless-regdb will do

cat db.txt | gpg --clearsign --default-key regdbkey_private >
db_signed.txt

As a result we will get something like this:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

# This is the world regulatory domain
country 00:
(2402 - 2472 @ 40), (20)
# Channel 12 - 13.
(2457 - 2482 @ 20), (20), NO-IR AUTO-BW
# Channel 14. Only JP enables this and for 802.11b only
(2474 - 2494 @ 20), (20), NO-IR
# Channel 36 - 48
(5170 - 5250 @ 80), (20), NO-IR
# NB: 5260 MHz - 5700 MHz requies DFS
# Channel 149 - 165
(5735 - 5835 @ 80), (20), NO-IR
# IEEE 802.11ad (60GHz), channels 1..3
(57240 - 63720 @ 2160), (0)

....

country ZW: DFS-ETSI
(2402 - 2482 @ 40), (20)
(5170 - 5250 @ 80), (20)
(5250 - 5330 @ 80), (20), DFS
(5490 - 5710 @ 80), (27), DFS

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQEcBAEBAgAGBQJTkbhXAAoJEJMu885bZibypxYH+QEVe1VNDalrzS99luWrqLn1
Cfrck6l4rdb/z+Ef1lGRxjYtvad/bRTYBHLwWqJEt/R5dvf1k32sNlZU+++dBLsg
IFBHlVdYa7DQok0K0Hfw8jGU3S6+XrSnFUHhiBR0NRP/SJGzevSE+MhVNulf6bZu
/uN1nW/+VCZ46wh5EGarWO3cWFCAJKJXujPWN6Zm97ieOBtAN95BHk29h5g+aSNS
NcszEvbIy86kKquCTUWQcAgUAp0ZijlQin1NoXr87Z3k9vKSAIK4kp+8WIfnHYYE
Y3g/lOMHh6bKOKllYxBxWNZQIgLP1R2yf/qv8JyGfeQTNfNlCihIQRFQeU0Hj5U=
=pCXt
-----END PGP SIGNATURE-----

2) crda will be a script that will do something like that:

sh gpg_verify.sh && sh show_country.sh | crda_tiny

a) gpg_verify.sh will verify db.txt signature
- gpg --default-key regdb_public --verify db_signed.txt

b) show_country.sh will print text country base on COUNTRY enviroment
eg.
janusz@dell:~/work/gpg$ COUNTRY=US ./show_country.sh
country US: DFS-FCC
(2402 - 2472 @ 40), (30)
(5170 - 5250 @ 80), (17)
(5250 - 5330 @ 80), (23), DFS
(5735 - 5835 @ 80), (30)
(57240 - 63720 @ 2160), (40)

c) crda_tiny will parse this text and will pass regdb parameters using nl80211


BR
Janusz

2014-06-09 08:00:43

by Felix Fietkau

[permalink] [raw]
Subject: Re: [PATCH] wireless-regdb: add DFS CAC time parameter

On 2014-05-21 18:03, Johannes Berg wrote:
> On Tue, 2014-05-20 at 11:48 -0700, Luis R. Rodriguez wrote:
>
>> > I think we should, but if we can't then at least can we cut to an
>> > extensible format?
>
> I don't see any way to extend the format right now.
>
> There's a wrinkle with making it more extensible too though - if we do
> that then we must be extremely careful that future older crda versions
> (i.e. the next version that we're about to write) will not parse a newer
> extended file more permissively, so our extensions are limited anyway.
>
> Looks like the format update really is needed, which probably means we
> should change the scripts to generate two databases and change the
> filename, or so?
How about making the format properly extensible by reusing what we're
already doing to keep the kernel ABI stable? For example, we could store
the database in a netlink-like attribute format, with some changes to
make it fixed endian.
I'm already doing just that for a few things in OpenWrt, so I have
working C code for writing and parsing such a format.

Another nice feature would be to indicate in the attributes if crda is
required to understand them, or if it can just continue with a warning.

If done right, I think we can probably make this the last time we change
the format version.

- Felix

2014-06-10 16:46:44

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] wireless-regdb: add DFS CAC time parameter

On Mon, 2014-06-09 at 10:00 +0200, Felix Fietkau wrote:

> > Looks like the format update really is needed, which probably means we
> > should change the scripts to generate two databases and change the
> > filename, or so?

> How about making the format properly extensible by reusing what we're
> already doing to keep the kernel ABI stable? For example, we could store
> the database in a netlink-like attribute format, with some changes to
> make it fixed endian.
> I'm already doing just that for a few things in OpenWrt, so I have
> working C code for writing and parsing such a format.
>
> Another nice feature would be to indicate in the attributes if crda is
> required to understand them, or if it can just continue with a warning.
>
> If done right, I think we can probably make this the last time we change
> the format version.

Sure, that seems like a more detailed version of email :)
I don't really care about the low-level details that much.

johannes