From johannes at sipsolutions.net  Tue Oct  1 08:15:14 2013
From: johannes at sipsolutions.net (Johannes Berg)
Date: Tue, 01 Oct 2013 14:15:14 +0200
Subject: [wireless-regdb] [PATCH] regulatory: enable channels 52-64 and
 100-144 for world roaming
In-Reply-To: <1368738412-7740-1-git-send-email-johannes@sipsolutions.net>
References: <1368738412-7740-1-git-send-email-johannes@sipsolutions.net>
Message-ID: <1380629714.14430.39.camel@jlt4.sipsolutions.net>

On Thu, 2013-05-16 at 23:06 +0200, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg at intel.com>
> 
> If allowed in a country, these channels typically require DFS
> so mark them as such. Channel 144 is a bit special, it's coming
> into use now to allow more VHT 80 channels, but world roaming
> with passive scanning is acceptable anyway. It seems fairly
> unlikely that it'll be used as the control channel for a VHT
> AP, but it needs to be present to allow a full VHT connection
> to an AP that uses it as one of the secondary channels.
> 
> Also enable VHT 160 on these channels, and also for channels
> 36-48 to be able to use VHT 160 there.

So many months later ... I'm merging this now.

johannes



From johannes at sipsolutions.net  Mon Oct  7 04:30:05 2013
From: johannes at sipsolutions.net (Johannes Berg)
Date: Mon, 07 Oct 2013 10:30:05 +0200
Subject: [wireless-regdb] [PATCH 2/2] mac80211: implement support for
 configuring antenna gain
In-Reply-To: <1381134567.13586.3.camel@jlt4.sipsolutions.net>
 (sfid-20131007_102934_686779_457D9E72)
References: <1378472763-36062-1-git-send-email-nbd@openwrt.org>
 <1378472763-36062-2-git-send-email-nbd@openwrt.org>
 <1380625512.14430.19.camel@jlt4.sipsolutions.net>
 <524AAE97.5020708@openwrt.org>
 <1380628244.14430.37.camel@jlt4.sipsolutions.net>
 <524FF599.5040706@openwrt.org>
 <1381134567.13586.3.camel@jlt4.sipsolutions.net>
 (sfid-20131007_102934_686779_457D9E72)
Message-ID: <1381134605.13586.4.camel@jlt4.sipsolutions.net>

+ wireless-regdb

On Mon, 2013-10-07 at 10:29 +0200, Johannes Berg wrote:
> On Sat, 2013-10-05 at 13:18 +0200, Felix Fietkau wrote:
> 
> > > I understand. I don't understand the pieces about "max_antenna_gain".
> 
> > Right now ath9k has an antenna gain value in the EEPROM, and it compares
> > it against the channel max_antenna_gain value.
> 
> I just don't understand what the max means. If I connect a 5dBi gain
> antenna, but the "max antenna gain" is 3dBi, what should happen?
> 
> > Let's assume we have configured the tx power to the maximum value, the
> > regdb allows 3 dB antenna gain, and the ath9k EEPROM contains an antenna
> > gain of 3 dB as well.
> > If we now add another 3 dB of user-configured antenna gain, it first
> > starts tapping into the regulatory-allowed antenna gain before reducing
> > tx power in mac80211. The driver needs to know about this, so I put the
> > calculated maximum antenna gain into the hw conf as well.
> 
> I don't think it really works this way, does it? I don't believe the
> "regulatory-allowed antenna gain" is really something that's allowed on
> top of the EIRP?
> 
> johannes
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 




From linville at tuxdriver.com  Fri Oct 11 16:12:26 2013
From: linville at tuxdriver.com (John W. Linville)
Date: Fri, 11 Oct 2013 16:12:26 -0400
Subject: [wireless-regdb] [ANN] wireless-regdb: master-2013-10-11
Message-ID: <20131011201226.GD14329@tuxdriver.com>

A new release of wireless-regdb (master-2013-10-11) is available at:

http://www.kernel.org/pub/software/network/wireless-regdb/wireless-regdb-2013.10.11.tar.gz

Here is the short log of the changes included since the 2013-02-13
release:

Emanuel Taube (1):
      Remove obsolete country code CS from regdb

John W. Linville (1):
      wireless-regdb: update regulatory.bin based on preceding changes.

Luis R. Rodriguez (53):
      wireless-regdb: AU, Australia - enable VHT80
      wireless-regdb: BR, Brazil - enable VHT80
      wireless-regdb: CA, Canada - enable VHT80
      wireless-regdb: HK, Hong Kong - enable VHT80
      wireless-regdb: NZ, New Zealand - enable VHT80
      wireless-regdb: AR, Argentina - enable VHT80
      wireless-regdb: CO, Colombia - enable VHT80
      wireless-regdb: GU, Guam - enable VHT80
      wireless-regdb: MX, Mexico - enable VHT80
      wireless-regdb: PE, Peru - enable VHT80
      wireless-regdb: PH, Philippines - enable VHT80
      wireless-regdb: PR, Puerto Rico - enable VHT80
      wireless-regdb: SA, Saudi Arabia - enable VHT80
      wireless-regdb: SG, Singapore - enable VHT80
      wireless-regdb: ZA, South Africa - enable VHT80
      wireless-regdb: TH, Thailand - enable VHT80
      wireless-regdb: AE, United Arab Emirates - enable VHT80
      wireless-regdb: VN, Vietnam - enable VHT80
      wireless-regdb: AT, Austria - enable VHT80
      wireless-regdb: FR, France - enable VHT80
      wireless-regdb: DE, Germany - enable VHT80
      wireless-regdb: GB, United Kingdom - enable VHT80
      wireless-regdb: BE, Belgium - enable VHT80
      wireless-regdb: CZ, Czech Republic - enable VHT80
      wireless-regdb: DK, Denmark - enable VHT80
      wireless-regdb: FI, Finland - enable VHT80
      wireless-regdb: GR, Greece- enable VHT80
      wireless-regdb: IE, Ireland - enable VHT80
      wireless-regdb: IT, Italy - enable VHT80
      wireless-regdb: LU, Luxembourg - enable VHT80
      wireless-regdb: NL, Netherlands - enable VHT80
      wireless-regdb: PL, Poland - enable VHT80
      wireless-regdb: PT, Portugal - enable VHT80
      wireless-regdb: SK, Slovakia - enable VHT80
      wireless-regdb: ES, Spain - enable VHT80
      wireless-regdb: SE, Sweden - enable VHT80
      wireless-regdb: CH, Switzerland - enable VHT80
      wireless-regdb: TR, Turkey - enable VHT80
      wireless-regdb: CN, China - enable VHT80
      wireless-regdb: enable VHT80 and VHT160 for JP
      wireless-regdb: US, United States - enable VHT80
      wireless-regdb: ID, Indonesia - enable 5 GHz and VHT80
      wireless-regdb: IL, Isreal - enable VHT80
      wireless-regdb: KW, Kuwait - enable VHT80
      wireless-regdb: MY, Malaysia - enable VHT80
      wireless-regdb: MA, Morocco - enable 5 GHz and VHT80
      wireless-regdb: enable HT40 in RU - Russian Federation
      wireless-regdb: KR, Republic of Korea - enable VHT80
      wireless-regdb: TW, Taiwan - enable VHT80
      wireless-regdb: enable VHT80 when world roaming
      wireless-regdb: add 802.11ad 60 GHz channels 1..3 to world regdom
      wireless-regdb: CR, Costa Rica - enable VHT80
      wireless-regdb: EC, Ecauador - enable VHT80

-- 
John W. Linville		Someday the world will need a hero, and you
linville at tuxdriver.com			might be all we have.  Be ready.


From linville at tuxdriver.com  Fri Oct 11 16:24:59 2013
From: linville at tuxdriver.com (John W. Linville)
Date: Fri, 11 Oct 2013 16:24:59 -0400
Subject: [wireless-regdb] [ANN] wireless-regdb: master-2013-10-11
Message-ID: <20131011202459.GF14329@tuxdriver.com>

(Cutting the short log, since the original version got classified as
SPAM on vger.kernel.org...??)

A new release of wireless-regdb (master-2013-10-11) is available at:

http://www.kernel.org/pub/software/network/wireless-regdb/wireless-regdb-2013.10.11.tar.gz

Here is the short log of the changes included since the 2013-02-13
release:

SNIP -- you'll have to check it yourself:

	git log master-2013-02-13..master-2013-10-11 | git shortlog

-- 
John W. Linville		Someday the world will need a hero, and you
linville at tuxdriver.com			might be all we have.  Be ready.


From linville at tuxdriver.com  Fri Oct 11 16:39:01 2013
From: linville at tuxdriver.com (John W. Linville)
Date: Fri, 11 Oct 2013 16:39:01 -0400
Subject: [wireless-regdb] [ANN] wireless-regdb: master-2013-10-11
In-Reply-To: <20131011202459.GF14329@tuxdriver.com>
References: <20131011202459.GF14329@tuxdriver.com>
Message-ID: <20131011203901.GA23477@tuxdriver.com>

On Fri, Oct 11, 2013 at 04:24:59PM -0400, John W. Linville wrote:
> (Cutting the short log, since the original version got classified as
> SPAM on vger.kernel.org...??)
> 
> A new release of wireless-regdb (master-2013-10-11) is available at:
> 
> http://www.kernel.org/pub/software/network/wireless-regdb/wireless-regdb-2013.10.11.tar.gz
> 
> Here is the short log of the changes included since the 2013-02-13
> release:
> 
> SNIP -- you'll have to check it yourself:
> 
> 	git log master-2013-02-13..master-2013-10-11 | git shortlog

FYI -- I've purged my folders of all other old/pending wireless-regdb
stuff.  If you have a change that you still want to propose to the
regulatory database, please send it as a _patch_ at your leisure.

Thanks,

John
-- 
John W. Linville		Someday the world will need a hero, and you
linville at tuxdriver.com			might be all we have.  Be ready.


From bjorn at mork.no  Fri Oct 11 19:27:22 2013
From: bjorn at mork.no (=?UTF-8?q?Bj=C3=B8rn=20Mork?=)
Date: Sat, 12 Oct 2013 01:27:22 +0200
Subject: [wireless-regdb] [PATCH] wireless-regdb: NO, Norway - enable VHT80
Message-ID: <1381534042-28273-1-git-send-email-bjorn@mork.no>

This enables 80 MHz bandwidth usage on all 5 GHz
frequencies.

This is a country that belongs to CEPT [0] and an available
regulatory source is ECC/DEC/(04)08 [1].

Quoting:

considering [...]
   e. that the systems covered by this ECC Decision operate
   typically in a 20 MHz channel bandwidth, other values for
   the channel bandwidth are also feasible provided they
   comply with the relevant maximum mean e.i.r.p. and the
   corresponding maximum mean e.i.r.p. density limits;

[0] https://en.wikipedia.org/wiki/European_Conference_of_Postal_and_Telecommunications_Administrations
[1] http://www.erodocdb.dk/Docs/doc98/official/pdf/ECCDEC0408.PDF

Cc: Luis R. Rodriguez <mcgrof at do-not-panic.com>
Signed-off-by: Bj?rn Mork <bjorn at mork.no>
---
I have no idea why this was left out of the big CEPT VHT80 batch...

 db.txt |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/db.txt b/db.txt
index d0d1a3f..8c61b14 100644
--- a/db.txt
+++ b/db.txt
@@ -569,9 +569,9 @@ country NL: DFS-ETSI
 
 country NO: DFS-ETSI
 	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(5170 - 5250 @ 80), (N/A, 20)
+	(5250 - 5330 @ 80), (N/A, 20), DFS
+	(5490 - 5710 @ 80), (N/A, 27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
 
-- 
1.7.10.4



From mcgrof at do-not-panic.com  Wed Oct 23 14:53:33 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 23 Oct 2013 20:53:33 +0200
Subject: [wireless-regdb] [RFC] wireless-regdb: remove antenna gain
Message-ID: <1382554413-27650-1-git-send-email-mcgrof@do-not-panic.com>

This data is not accurate, cannot be relied upon given
that antenna gain is very specific to the device being
manufactured, and we never used it. Just kill it to
simplify the database.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 db.txt     | 998 ++++++++++++++++++++++++++++++-------------------------------
 dbparse.py |   7 +-
 2 files changed, 501 insertions(+), 504 deletions(-)

diff --git a/db.txt b/db.txt
index b8ddb1b..c938767 100644
--- a/db.txt
+++ b/db.txt
@@ -1,211 +1,211 @@
 # This is the world regulatory domain
 country 00:
-	(2402 - 2472 @ 40), (3, 20)
+	(2402 - 2472 @ 40), (20)
 	# Channel 12 - 13.
-	(2457 - 2482 @ 40), (3, 20), NO-IR
+	(2457 - 2482 @ 40), (20), NO-IR
 	# Channel 14. Only JP enables this and for 802.11b only
-	(2474 - 2494 @ 20), (3, 20), NO-IR, NO-OFDM
+	(2474 - 2494 @ 20), (20), NO-IR
 	# Channel 36 - 48
-	(5170 - 5250 @ 80), (3, 20), NO-IR
+	(5170 - 5250 @ 80), (20), NO-IR
 	# NB: 5260 MHz - 5700 MHz requies DFS
 	# Channel 149 - 165
-	(5735 - 5835 @ 80), (3, 20), NO-IR
+	(5735 - 5835 @ 80), (20), NO-IR
 	# IEEE 802.11ad (60GHz), channels 1..3
-	(57240 - 63720 @ 2160), (N/A, 0)
+	(57240 - 63720 @ 2160), (0)
 
 
 country AD:
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country AE:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country AL:
-	(2402 - 2482 @ 20), (N/A, 20)
+	(2402 - 2482 @ 20), (20)
 
 country AM:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 20), (N/A, 18)
-	(5250 - 5330 @ 20), (N/A, 18), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 20), (18)
+	(5250 - 5330 @ 20), (18), DFS
 
 country AN:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 
 country AR:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country AT: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country AU:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country AW:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 
 country AZ:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 18)
-	(5250 - 5330 @ 40), (N/A, 18), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (18)
+	(5250 - 5330 @ 40), (18), DFS
 
 country BA: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country BB:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (3, 23)
-	(5250 - 5330 @ 40), (3, 23), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (23)
+	(5250 - 5330 @ 40), (23), DFS
+	(5735 - 5835 @ 40), (30)
 
 country BD:
-	(2402 - 2482 @ 40), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
 
 country BE: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country BG: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 23)
-	(5250 - 5290 @ 40), (N/A, 23), DFS
-	(5490 - 5710 @ 40), (N/A, 30), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (23)
+	(5250 - 5290 @ 40), (23), DFS
+	(5490 - 5710 @ 40), (30), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country BH:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 20), (N/A, 20)
-	(5250 - 5330 @ 20), (N/A, 20), DFS
-	(5735 - 5835 @ 20), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 20), (20)
+	(5250 - 5330 @ 20), (20), DFS
+	(5735 - 5835 @ 20), (20)
 
 country BL:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 18)
-	(5250 - 5330 @ 40), (N/A, 18), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (18)
+	(5250 - 5330 @ 40), (18), DFS
 
 country BN:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (30)
 
 country BO:
-	(2402 - 2482 @ 40), (N/A, 30)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (30)
+	(5735 - 5835 @ 40), (30)
 
 country BR:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country BY:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 
 country BZ:
-	(2402 - 2482 @ 40), (N/A, 30)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (30)
+	(5735 - 5835 @ 40), (30)
 
 country CA:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country CH: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country CL:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5735 - 5835 @ 40), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (20)
 
 country CN:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5835 @ 80), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5835 @ 80), (30)
 	# 60 gHz band channels 1,4: 28dBm, channels 2,3: 44dBm
 	# ref: http://www.miit.gov.cn/n11293472/n11505629/n11506593/n11960250/n11960606/n11960700/n12330791.files/n12330790.pdf
-	(57240 - 59400 @ 2160), (N/A, 28)
-	(59400 - 63720 @ 2160), (N/A, 44)
-	(63720 - 65880 @ 2160), (N/A, 28)
+	(57240 - 59400 @ 2160), (28)
+	(59400 - 63720 @ 2160), (44)
+	(63720 - 65880 @ 2160), (28)
 
 country CO:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country CR:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country CY: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 # Data from http://www.ctu.eu/164/download/VOR/VOR-12-08-2005-34.pdf
 # and http://www.ctu.eu/164/download/VOR/VOR-12-05-2007-6-AN.pdf
 # Power at 5250 - 5350 MHz and 5470 - 5725 MHz can be doubled if TPC is
 # implemented.
 country CZ: DFS-ETSI
-	(2400 - 2483.5 @ 40), (N/A, 100 mW)
-	(5150 - 5250 @ 80), (N/A, 200 mW), NO-OUTDOOR
-	(5250 - 5350 @ 80), (N/A, 100 mW), NO-OUTDOOR, DFS
-	(5470 - 5725 @ 80), (N/A, 500 mW), DFS
+	(2400 - 2483.5 @ 40), (100 mW)
+	(5150 - 5250 @ 80), (200 mW), NO-OUTDOOR
+	(5250 - 5350 @ 80), (100 mW), NO-OUTDOOR
+	(5470 - 5725 @ 80), (500 mW), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 # Data from "Frequenznutzungsplan" (as published in April 2008), downloaded from
 # http://www.bundesnetzagentur.de/cae/servlet/contentblob/38448/publicationFile/2659/Frequenznutzungsplan2008_Id17448pdf.pdf
@@ -221,542 +221,542 @@ country CZ: DFS-ETSI
 
 country DE: DFS-ETSI
 	# entries 279004 and 280006
-	(2400 - 2483.5 @ 40), (N/A, 100 mW)
+	(2400 - 2483.5 @ 40), (100 mW)
 	# entry 303005
-	(5150 - 5250 @ 80), (N/A, 100 mW), NO-OUTDOOR
+	(5150 - 5250 @ 80), (100 mW), NO-OUTDOOR
 	# entries 304002 and 305002
-	(5250 - 5350 @ 80), (N/A, 100 mW), NO-OUTDOOR, DFS
+	(5250 - 5350 @ 80), (100 mW), NO-OUTDOOR
 	# entries 308002, 309001 and 310003
-	(5470 - 5725 @ 80), (N/A, 500 mW), DFS
+	(5470 - 5725 @ 80), (500 mW), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country DK: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country DO:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 23), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (23), DFS
+	(5735 - 5835 @ 40), (30)
 
 country DZ:
-	(2402 - 2482 @ 40), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
 
 country EC:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country EE: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country EG:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 20), (N/A, 20)
-	(5250 - 5330 @ 20), (N/A, 20), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 20), (20)
+	(5250 - 5330 @ 20), (20), DFS
 
 country ES: DFS-ETSI
-	(2400 - 2483.5 @ 40), (N/A, 100 mW)
-	(5150 - 5250 @ 80), (N/A, 100 mW), NO-OUTDOOR
-	(5250 - 5350 @ 80), (N/A, 100 mW), NO-OUTDOOR, DFS
-	(5470 - 5725 @ 80), (N/A, 500 mW), DFS
+	(2400 - 2483.5 @ 40), (100 mW)
+	(5150 - 5250 @ 80), (100 mW), NO-OUTDOOR
+	(5250 - 5350 @ 80), (100 mW), NO-OUTDOOR
+	(5470 - 5725 @ 80), (500 mW), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country FI: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country FR: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country GE:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 18)
-	(5250 - 5330 @ 40), (N/A, 18), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (18)
+	(5250 - 5330 @ 40), (18), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country GB: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country GD:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 20), DFS
-	(5490 - 5710 @ 40), (3, 20), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (30)
 
 country GR: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country GL: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 20), (N/A, 20)
-	(5250 - 5330 @ 20), (N/A, 20), DFS
-	(5490 - 5710 @ 20), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 20), (20)
+	(5250 - 5330 @ 20), (20), DFS
+	(5490 - 5710 @ 20), (27), DFS
 
 country GT:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 23), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (23), DFS
+	(5735 - 5835 @ 40), (30)
 
 country GU:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country HN:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 20), DFS
-	(5490 - 5710 @ 40), (3, 20), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (30)
 
 country HK:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country HR: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country HT:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 
 country HU: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country ID:
 	# ref: http://www.postel.go.id/content/ID/regulasi/standardisasi/kepdir/bwa%205,8%20ghz.pdf
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5815 @ 80), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5815 @ 80), (20)
 
 country IE: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country IL:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5150 - 5250 @ 80), (N/A, 200 mW), NO-OUTDOOR
-	(5250 - 5350 @ 80), (N/A, 200 mW), NO-OUTDOOR, DFS
+	(2402 - 2482 @ 40), (20)
+	(5150 - 5250 @ 80), (200 mW), NO-OUTDOOR
+	(5250 - 5350 @ 80), (200 mW), NO-OUTDOOR
 
 country IN:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5735 - 5835 @ 40), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (20)
 
 country IS: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country IR:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5835 @ 40), (30)
 
 country IT: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country JM:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 20), DFS
-	(5490 - 5710 @ 40), (3, 20), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (30)
 
 country JP:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(2474 - 2494 @ 20), (N/A, 20), NO-OFDM
-	(4910 - 4990 @ 40), (N/A, 23)
-	(5030 - 5090 @ 40), (N/A, 23)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 160), (N/A, 23), DFS
+	(2402 - 2482 @ 40), (20)
+	(2474 - 2494 @ 20), (20), NO-OFDM
+	(4910 - 4990 @ 40), (23)
+	(5030 - 5090 @ 40), (23)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 160), (23), DFS
 
 country JO:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 18)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (18)
 
 country KE:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5835 @ 40), (30)
 
 country KH:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 
 country KP:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5330 @ 40), (3, 20)
-	(5160 - 5250 @ 40), (3, 20), DFS
-	(5490 - 5630 @ 40), (3, 30), DFS
-	(5735 - 5815 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5330 @ 40), (20)
+	(5160 - 5250 @ 40), (20), DFS
+	(5490 - 5630 @ 40), (30), DFS
+	(5735 - 5815 @ 40), (30)
 
 country KR:
-	(2402 - 2482 @ 20), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 20)
-	(5250 - 5330 @ 80), (3, 20), DFS
-	(5490 - 5630 @ 80), (3, 30), DFS
-	(5735 - 5815 @ 80), (3, 30)
+	(2402 - 2482 @ 20), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5630 @ 80), (30), DFS
+	(5735 - 5815 @ 80), (30)
 
 country KW:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
 
 country KZ:
-	(2402 - 2482 @ 40), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
 
 country LB:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5835 @ 40), (30)
 
 country LI: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 
 country LK:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 20), (3, 17)
-	(5250 - 5330 @ 20), (3, 20), DFS
-	(5490 - 5710 @ 20), (3, 20), DFS
-	(5735 - 5835 @ 20), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 20), (17)
+	(5250 - 5330 @ 20), (20), DFS
+	(5490 - 5710 @ 20), (20), DFS
+	(5735 - 5835 @ 20), (30)
 
 country LT: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country LU: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country LV: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country MC: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 18)
-	(5250 - 5330 @ 40), (N/A, 18), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (18)
+	(5250 - 5330 @ 40), (18), DFS
 
 country MA:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 23)
-	(5735 - 5835 @ 80), (N/A, 23)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (23)
+	(5735 - 5835 @ 80), (23)
 
 country MO:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (3, 23)
-	(5250 - 5330 @ 40), (3, 23), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (23)
+	(5250 - 5330 @ 40), (23), DFS
+	(5735 - 5835 @ 40), (30)
 
 country MK: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country MT: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country MY:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 17)
-	(5250 - 5330 @ 80), (N/A, 23), DFS
-	(5735 - 5835 @ 80), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (23), DFS
+	(5735 - 5835 @ 80), (30)
 
 country MX:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country NL: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20), NO-OUTDOOR
-	(5250 - 5330 @ 80), (N/A, 20), NO-OUTDOOR, DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20), NO-OUTDOOR
+	(5250 - 5330 @ 80), (20), NO-OUTDOOR
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country NO: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country NP:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5835 @ 40), (30)
 
 country NZ:
-	(2402 - 2482 @ 40), (N/A, 30)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (30)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country OM:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 20), DFS
-	(5490 - 5710 @ 40), (3, 20), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (30)
 
 country PA:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 23), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (23), DFS
+	(5735 - 5835 @ 40), (30)
 
 country PE:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country PG:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 23), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (23), DFS
+	(5735 - 5835 @ 40), (30)
 
 country PH:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country PK:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5835 @ 40), (30)
 
 country PL: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country PT: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country PR:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country QA:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5835 @ 40), (30)
 
 country RO: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 
 # Source:
 # http://www.ratel.rs/upload/documents/Plan_namene/Plan_namene-sl_glasnik.pdf
 country RS:
-	(2400 - 2483.5 @ 40), (N/A, 100 mW)
-	(5150 - 5350 @ 40), (N/A, 200 mW), NO-OUTDOOR
-	(5470 - 5725 @ 20), (3, 1000 mW), DFS
+	(2400 - 2483.5 @ 40), (100 mW)
+	(5150 - 5350 @ 40), (200 mW), NO-OUTDOOR
+	(5470 - 5725 @ 20), (1000 mW), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country RU:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5330 @ 40), (N/A, 20)
-	(5650 - 5710 @ 40), (N/A, 30)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5330 @ 40), (20)
+	(5650 - 5710 @ 40), (30)
+	(5735 - 5835 @ 40), (30)
 
 country RW:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5835 @ 40), (N/A, 30)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5835 @ 40), (30)
 
 country SA:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country SE: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country SG:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country SI: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (N/A, 20)
-	(5250 - 5330 @ 40), (N/A, 20), DFS
-	(5490 - 5710 @ 40), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (20)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country SK: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country SV:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 20), (3, 17)
-	(5250 - 5330 @ 20), (3, 23), DFS
-	(5735 - 5835 @ 20), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 20), (17)
+	(5250 - 5330 @ 20), (23), DFS
+	(5735 - 5835 @ 20), (30)
 
 country SY:
-	(2402 - 2482 @ 40), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
 
 country TW:
-	(2402 - 2472 @ 40), (3, 27)
-	(5270 - 5330 @ 40), (3, 17), DFS
-	(5490 - 5710 @ 80), (3, 30), DFS
-	(5735 - 5815 @ 80), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5270 - 5330 @ 40), (17), DFS
+	(5490 - 5710 @ 80), (30), DFS
+	(5735 - 5815 @ 80), (30)
 
 country TH:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country TT:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 20), DFS
-	(5490 - 5710 @ 40), (3, 20), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (30)
 
 country TN:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 20), (N/A, 20)
-	(5250 - 5330 @ 20), (N/A, 20), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 20), (20)
+	(5250 - 5330 @ 20), (20), DFS
 
 country TR: DFS-ETSI
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (N/A, 20)
-	(5250 - 5330 @ 80), (N/A, 20), DFS
-	(5490 - 5710 @ 80), (N/A, 27), DFS
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (20)
+	(5250 - 5330 @ 80), (20), DFS
+	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
  
 # Source:
 # #914 / 06 Sep 2007: http://www.ucrf.gov.ua/uk/doc/nkrz/1196068874
@@ -766,58 +766,58 @@ country TR: DFS-ETSI
 # rules in the referenced laws. Such a range is used because of
 # disputable definitions there.
 country UA:
-	(2400 - 2483.5 @ 40), (N/A, 20), NO-OUTDOOR
-	(5150 - 5350 @ 40), (N/A, 20), NO-OUTDOOR
+	(2400 - 2483.5 @ 40), (20), NO-OUTDOOR
+	(5150 - 5350 @ 40), (20), NO-OUTDOOR
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
+	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
 country US: DFS-FCC
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5600 @ 80), (3, 24), DFS
-	(5650 - 5710 @ 40), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5600 @ 80), (24), DFS
+	(5650 - 5710 @ 40), (24), DFS
+	(5735 - 5835 @ 80), (30)
 	# 60g band
 	# reference: http://cfr.regstoday.com/47cfr15.aspx#47_CFR_15p255
 	# channels 1,2,3, EIRP=40dBm(43dBm peak)
-	(57240 - 63720 @ 2160), (N/A, 40)
+	(57240 - 63720 @ 2160), (40)
 
 country UY:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 20), DFS
-	(5490 - 5710 @ 40), (3, 20), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (30)
 
 country UZ:
-	(2402 - 2472 @ 40), (3, 27)
-	(5170 - 5250 @ 40), (3, 17)
-	(5250 - 5330 @ 40), (3, 20), DFS
-	(5490 - 5710 @ 40), (3, 20), DFS
-	(5735 - 5835 @ 40), (3, 30)
+	(2402 - 2472 @ 40), (27)
+	(5170 - 5250 @ 40), (17)
+	(5250 - 5330 @ 40), (20), DFS
+	(5490 - 5710 @ 40), (20), DFS
+	(5735 - 5835 @ 40), (30)
 
 country VE:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5735 - 5815 @ 40), (N/A, 23)
+	(2402 - 2482 @ 40), (20)
+	(5735 - 5815 @ 40), (23)
 
 country VN:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country YE:
-	(2402 - 2482 @ 40), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
 
 country ZA:
-	(2402 - 2482 @ 40), (N/A, 20)
-	(5170 - 5250 @ 80), (3, 17)
-	(5250 - 5330 @ 80), (3, 24), DFS
-	(5490 - 5710 @ 80), (3, 24), DFS
-	(5735 - 5835 @ 80), (3, 30)
+	(2402 - 2482 @ 40), (20)
+	(5170 - 5250 @ 80), (17)
+	(5250 - 5330 @ 80), (24), DFS
+	(5490 - 5710 @ 80), (24), DFS
+	(5735 - 5835 @ 80), (30)
 
 country ZW:
-	(2402 - 2482 @ 40), (N/A, 20)
+	(2402 - 2482 @ 40), (20)
 
diff --git a/dbparse.py b/dbparse.py
index 29eb9d6..ac7234b 100755
--- a/dbparse.py
+++ b/dbparse.py
@@ -205,13 +205,10 @@ class DBParser(object):
 
     def _parse_power_def(self, pname, line, dupwarn=True):
         try:
-            (max_ant_gain,
-             max_eirp) = line.split(',')
-            if max_ant_gain == 'N/A':
-                max_ant_gain = '0'
+            max_eirp = line
             if max_eirp == 'N/A':
                 max_eirp = '0'
-            max_ant_gain = float(max_ant_gain)
+            max_ant_gain = float(0)
             def conv_pwr(pwr):
                 if pwr.endswith('mW'):
                     pwr = float(pwr[:-2])
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 23 14:54:21 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 23 Oct 2013 20:54:21 +0200
Subject: [wireless-regdb] [RFC] crda: remove antenna gain
Message-ID: <1382554461-27746-1-git-send-email-mcgrof@do-not-panic.com>

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 reglib.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/reglib.c b/reglib.c
index fa6efe0..b0c61e5 100644
--- a/reglib.c
+++ b/reglib.c
@@ -673,11 +673,6 @@ static void print_reg_rule(const struct ieee80211_reg_rule *rule)
 
 	printf("(");
 
-	if (power->max_antenna_gain)
-		printf("%.2f, ", ((float)(power->max_antenna_gain)/100.0));
-	else
-		printf("N/A, ");
-
 	if (power->max_eirp)
 		printf("%.2f)", ((float)(power->max_eirp)/100.0));
 	else
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 23 14:55:36 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 23 Oct 2013 20:55:36 +0200
Subject: [wireless-regdb] [RFC] cfg80211: make genregdb.awk skip antenna gain
Message-ID: <1382554536-27943-1-git-send-email-mcgrof@do-not-panic.com>

Now that wireless-regdb doesn't include
antenna gain lets skip parsing it completely
for when CONFIG_CFG80211_INTERNAL_REGDB is
enabled.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 net/wireless/genregdb.awk | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
 mode change 100644 => 100755 net/wireless/genregdb.awk

diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
old mode 100644
new mode 100755
index c808619..3e241e4e
--- a/net/wireless/genregdb.awk
+++ b/net/wireless/genregdb.awk
@@ -63,14 +63,11 @@ active && /^[ \t]*\(/ {
 	end = $3
 	bw = $5
 	sub(/\),/, "", bw)
-	gain = $6
-	sub(/\(/, "", gain)
-	sub(/,/, "", gain)
-	power = $7
-	sub(/\)/, "", power)
+	power = $6
+	sub(/\(/, "", power)
 	sub(/,/, "", power)
 	# power might be in mW...
-	units = $8
+	units = $7
 	sub(/\)/, "", units)
 	sub(/,/, "", units)
 	if (units == "mW") {
@@ -87,7 +84,7 @@ active && /^[ \t]*\(/ {
 		}
 	}
 	flagstr = ""
-	for (i=8; i<=NF; i++)
+	for (i=7; i<=NF; i++)
 		flagstr = flagstr $i
 	split(flagstr, flagarray, ",")
 	flags = ""
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 21:52:56 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 02:52:56 +0100
Subject: [wireless-regdb] [PATCH 0/6] crda: few updates and license changes
Message-ID: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>

Here's a few updates to CRDA. This depends on the removal of
antenna gain patches I posted last week. The tools developed
in this series are designed to help folks who want to contribute
to wireless-regdb but have a regulatory database format in some
other form that is non-optimized. The stream parser helps users
get their data out into non optimized form, and provide also
optimizers.

The optimizer work by doing a union and intersections on the
set of rules of a regulatory domain. Lastly as I mentioned the
last wireless summit I'd be making a library here, making CRDA
and its other tools share code. Other tools may use the library
later but these require a bit more work and as it is right now
the db2rd and optimizer require a bit more work to be shipped
by default.

This work has all been valgrinized.

Luis R. Rodriguez (6):
  crda: relicense under copyleft-next-0.3.0
  crda: fix -pedantic gcc compilation
  crda: add regulatory domain stream parser
  crda: add regulatory domain optimizer
  crda: make ssl keys include stdint.h
  crda: make reglib a shared library

 LICENSE             |  14 +-
 Makefile            |  54 +++-
 copyleft-next-0.3.0 | 219 +++++++++++++++
 crda.c              |   4 +-
 db2rd.c             |  30 ++
 optimize.c          |  38 +++
 reglib.c            | 790 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 reglib.h            |  60 ++++
 utils/key2pub.py    |   2 +
 9 files changed, 1199 insertions(+), 12 deletions(-)
 create mode 100644 copyleft-next-0.3.0
 create mode 100644 db2rd.c
 create mode 100644 optimize.c

-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 21:52:57 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 02:52:57 +0100
Subject: [wireless-regdb] [PATCH 1/6] crda: relicense under
	copyleft-next-0.3.0
In-Reply-To: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382925182-7393-2-git-send-email-mcgrof@do-not-panic.com>

I'm relicensing CRDA to copyleft-next-0.3.0. The original
motivation was to help with the BSD family but they are not
using any of this software and as this software grows I'd
like to ensure we use the best free software license
possible.

Fontana's work on copyleft-next is great and has good
community traction. At this point development for
copyleft-next has slowed down as copyleft-next-0.3.0
is already a good, usable alternative to GPLv2 and GPLv3.

A few notes:

  * With copyleft we don't have to specify 'at your option
    any later version' since the license allows that by
    default.

  * Some folks might wonder if copyleft-next-0.3.0 is
    OSI OSD-conformant or FSF-free since neither of
    those bodies have examined the license officially,
    but note, although IANAL, that copyleft-next is
    outbound-compatible with GPLv2 and GPLv3

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 LICENSE             |  14 +++-
 copyleft-next-0.3.0 | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 232 insertions(+), 1 deletion(-)
 create mode 100644 copyleft-next-0.3.0

diff --git a/LICENSE b/LICENSE
index 652a6dd..cc26ff2 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,16 @@
-Copyright (c) 2008, Luis R. Rodriguez <mcgrof at gmail.com>
+Copyright (c) 2013, Luis R. Rodriguez <mcgrof at do-not-panic.com>
+
+CRDA is licensed under copyleft-next 0.3.0
+
+Refer to copyleft-next-0.3.0 for license details, you can
+also always get the latest updates of copyleft-next from:
+
+https://gitorious.org/copyleft-next/
+
+This file incorporates work covered by the following copyright and
+permission notice:
+
+Copyright (c) 2008, Luis R. Rodriguez <mcgrof at do-not-panic.com>
 Copyright (c) 2008, Johannes Berg <johannes at sipsolutions.net>
 Copyright (c) 2008, Michael Green <Michael.Green at Atheros.com>
 
diff --git a/copyleft-next-0.3.0 b/copyleft-next-0.3.0
new file mode 100644
index 0000000..a66d5bf
--- /dev/null
+++ b/copyleft-next-0.3.0
@@ -0,0 +1,219 @@
+                   copyleft-next 0.3.0 ("this License")
+                         Release date: 2013-05-16
+
+1. License Grants; No Trademark License
+
+   Subject to the terms of this License, I grant You:
+
+   a) A non-exclusive, worldwide, perpetual, royalty-free, irrevocable
+      copyright license, to reproduce, Distribute, prepare derivative works
+      of, publicly perform and publicly display My Work.
+
+   b) A non-exclusive, worldwide, perpetual, royalty-free, irrevocable
+      patent license under Licensed Patents to make, have made, use, sell,
+      offer for sale, and import Covered Works.
+
+   This License does not grant any rights in My name, trademarks, service
+   marks, or logos.
+
+2. Distribution: General Conditions
+
+   You may Distribute Covered Works, provided that You (i) inform
+   recipients how they can obtain a copy of this License; (ii) satisfy the
+   applicable conditions of sections 3 through 6; and (iii) preserve all
+   Legal Notices contained in My Work (to the extent they remain
+   pertinent). "Legal Notices" means copyright notices, license notices,
+   license texts, and author attributions, but does not include logos,
+   other graphical images, trademarks or trademark legends.
+
+3. Conditions for Distributing Derived Works; Outbound GPL Compatibility
+
+   If You Distribute a Derived Work, You must license the entire Derived
+   Work as a whole under this License, with prominent notice of such
+   licensing. This condition may not be avoided through such means as
+   separate Distribution of portions of the Derived Work. You may
+   additionally license the Derived Work under the GPL, so that the
+   recipient may further Distribute the Derived Work under either this
+   License or the GPL.
+
+4. Condition Against Further Restrictions; Inbound License Compatibility
+
+   When Distributing a Covered Work, You may not impose further
+   restrictions on the exercise of rights in the Covered Work granted under
+   this License. This condition is not excused merely because such
+   restrictions result from Your compliance with conditions or obligations
+   extrinsic to this License (such as a court order or an agreement with a
+   third party).
+
+   However, You may Distribute a Covered Work incorporating material
+   governed by a license that is both OSI-Approved and FSF-Free as of the
+   release date of this License, provided that Your Distribution complies
+   with such other license.
+
+5. Conditions for Distributing Object Code
+
+   You may Distribute an Object Code form of a Covered Work, provided that
+   you accompany the Object Code with a URL through which the Corresponding
+   Source is made available, at no charge, by some standard or customary
+   means of providing network access to source code.
+
+   If you Distribute the Object Code in a physical product or tangible
+   storage medium ("Product"), the Corresponding Source must be available
+   through such URL for two years from the date of Your most recent
+   Distribution of the Object Code in the Product. However, if the Product
+   itself contains or is accompanied by the Corresponding Source (made
+   available in a customarily accessible manner), You need not also comply
+   with the first paragraph of this section.
+
+   Each recipient of the Covered Work from You is an intended third-party
+   beneficiary of this License solely as to this section 5, with the right
+   to enforce its terms.
+
+6. Symmetrical Licensing Condition for Upstream Contributions
+
+   If You Distribute a work to Me specifically for inclusion in or
+   modification of a Covered Work (a "Patch"), and no explicit licensing
+   terms apply to the Patch, You license the Patch under this License, to
+   the extent of Your copyright in the Patch. This condition does not
+   negate the other conditions of this License, if applicable to the Patch.
+
+7. Nullification of Copyleft/Proprietary Dual Licensing
+
+   If I offer to license, for a fee, a Covered Work under terms other than
+   a license that is OSI-Approved or FSF-Free as of the release date of this
+   License or a numbered version of copyleft-next released by the
+   Copyleft-Next Project, then the license I grant You under section 1 is no
+   longer subject to the conditions in sections 2 through 5.
+
+8. Copyleft Sunset
+
+   The conditions in sections 2 through 5 no longer apply once fifteen
+   years have elapsed from the date of My first Distribution of My Work
+   under this License.
+
+9. Pass-Through
+
+   When You Distribute a Covered Work, the recipient automatically receives
+   a license to My Work from Me, subject to the terms of this License.
+
+10. Termination
+
+    Your license grants under section 1 are automatically terminated if You
+
+    a) fail to comply with the conditions of this License, unless You cure
+       such noncompliance within thirty days after becoming aware of it, or
+
+    b) initiate a patent infringement litigation claim (excluding
+       declaratory judgment actions, counterclaims, and cross-claims)
+       alleging that any part of My Work directly or indirectly infringes
+       any patent.
+
+    Termination of Your license grants extends to all copies of Covered
+    Works You subsequently obtain. Termination does not terminate the
+    rights of those who have received copies or rights from You subject to
+    this License.
+
+    To the extent permission to make copies of a Covered Work is necessary
+    merely for running it, such permission is not terminable.
+
+11. Later License Versions
+
+    The Copyleft-Next Project may release new versions of copyleft-next,
+    designated by a distinguishing version number ("Later Versions").
+    Unless I explicitly remove the option of Distributing Covered Works
+    under Later Versions, You may Distribute Covered Works under any Later
+    Version.
+
+** 12. No Warranty                                                       **
+**                                                                       **
+**     My Work is provided "as-is", without warranty. You bear the risk  **
+**     of using it. To the extent permitted by applicable law, each      **
+**     Distributor of My Work excludes the implied warranties of title,  **
+**     merchantability, fitness for a particular purpose and             **
+**     non-infringement.                                                 **
+
+** 13. Limitation of Liability                                           **
+**                                                                       **
+**     To the extent permitted by applicable law, in no event will any   **
+**     Distributor of My Work be liable to You for any damages           **
+**     whatsoever, whether direct, indirect, special, incidental, or     **
+**     consequential damages, whether arising under contract, tort       **
+**     (including negligence), or otherwise, even where the Distributor  **
+**     knew or should have known about the possibility of such damages.  **
+
+14. Severability
+
+    The invalidity or unenforceability of any provision of this License
+    does not affect the validity or enforceability of the remainder of
+    this License. Such provision is to be reformed to the minimum extent
+    necessary to make it valid and enforceable.
+
+15. Definitions
+
+    "Copyleft-Next Project" means the project that maintains the source
+    code repository at <https://gitorious.org/copyleft-next/> as of the
+    release date of this License.
+
+    "Corresponding Source" of a Covered Work in Object Code form means (i)
+    the Source Code form of the Covered Work; (ii) all scripts,
+    instructions and similar information that are reasonably necessary for
+    a skilled developer to generate such Object Code from the Source Code
+    provided under (i); and (iii) a list clearly identifying all Separate
+    Works (other than those provided in compliance with (ii)) that were
+    specifically used in building and (if applicable) installing the
+    Covered Work (for example, a specified proprietary compiler including
+    its version number). Corresponding Source must be machine-readable.
+
+    "Covered Work" means My Work or a Derived Work.
+
+    "Derived Work" means a work of authorship that copies from, modifies,
+    adapts, is based on, is a derivative work of, transforms, translates or
+    contains all or part of My Work, such that copyright permission is
+    required. The following are not Derived Works: (i) Mere Aggregation;
+    (ii) a mere reproduction of My Work; and (iii) if My Work fails to
+    explicitly state an expectation otherwise, a work that merely makes
+    reference to My Work.
+
+    "Distribute" means to distribute, transfer or make a copy available to
+    someone else, such that copyright permission is required.
+
+    "Distributor" means Me and anyone else who Distributes a Covered Work.
+
+    "FSF-Free" means classified as 'free' by the Free Software Foundation.
+
+    "GPL" means a version of the GNU General Public License or the GNU
+    Affero General Public License.
+
+    "I"/"Me"/"My" refers to the individual or legal entity that places My
+    Work under this License. "You"/"Your" refers to the individual or legal
+    entity exercising rights in My Work under this License. A legal entity
+    includes each entity that controls, is controlled by, or is under
+    common control with such legal entity. "Control" means (a) the power to
+    direct the actions of such legal entity, whether by contract or
+    otherwise, or (b) ownership of more than fifty percent of the
+    outstanding shares or beneficial ownership of such legal entity.
+
+    "Licensed Patents" means all patent claims licensable royalty-free by
+    Me, now or in the future, that are necessarily infringed by making,
+    using, or selling My Work, and excludes claims that would be infringed
+    only as a consequence of further modification of My Work.
+
+    "Mere Aggregation" means an aggregation of a Covered Work with a
+    Separate Work.
+
+    "My Work" means the particular work of authorship I license to You
+    under this License.
+
+    "Object Code" means any form of a work that is not Source Code.
+
+    "OSI-Approved" means approved as 'Open Source' by the Open Source
+    Initiative.
+
+    "Separate Work" means a work that is separate from and independent of a
+    particular Covered Work and is not by its nature an extension or
+    enhancement of the Covered Work, and/or a runtime library, standard
+    library or similar component that is used to generate an Object Code
+    form of a Covered Work.
+
+    "Source Code" means the preferred form of a work for making
+    modifications to it.
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 21:52:58 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 02:52:58 +0100
Subject: [wireless-regdb] [PATCH 2/6] crda: fix -pedantic gcc compilation
In-Reply-To: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382925182-7393-3-git-send-email-mcgrof@do-not-panic.com>

gcc likes to complain about this, fix that as we're
going to get a bit more anal with code here soon as
we're moving towards making a library out of reglib.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 crda.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/crda.c b/crda.c
index 2a601eb..4751a39 100644
--- a/crda.c
+++ b/crda.c
@@ -141,13 +141,15 @@ int main(int argc, char **argv)
 {
 	int fd = -1;
 	int i = 0, j, r;
-	char alpha2[3] = {}; /* NUL-terminate */
+	char alpha2[3];
 	char *env_country;
 	struct nl80211_state nlstate;
 	struct nl_cb *cb = NULL;
 	struct nl_msg *msg;
 	int finished = 0;
 
+	memset(alpha2, 0, 3);
+
 	struct nlattr *nl_reg_rules;
 	const struct ieee80211_regdomain *rd = NULL;
 
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 21:52:59 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 02:52:59 +0100
Subject: [wireless-regdb] [PATCH 3/6] crda: add regulatory domain stream
	parser
In-Reply-To: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382925182-7393-4-git-send-email-mcgrof@do-not-panic.com>

This adds a stream parser for regulatory domains. This
allows developers to build regulatory domains now using
the db.txt from a stream, either stdin, or a from an
opened file.

This also adds a simple db2rd which for now only uses the
library but with a bit of effort can also be used as a
suitable replacement for the kernel's genregdb.awk.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 Makefile |  10 +-
 db2rd.c  |  30 ++++
 reglib.c | 539 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 reglib.h |  44 ++++++
 4 files changed, 621 insertions(+), 2 deletions(-)
 create mode 100644 db2rd.c

diff --git a/Makefile b/Makefile
index 7d2e33f..bd9c220 100644
--- a/Makefile
+++ b/Makefile
@@ -24,10 +24,11 @@ PUBKEY_DIR?=pubkeys
 RUNTIME_PUBKEY_DIR?=/etc/wireless-regdb/pubkeys
 
 CFLAGS += -Wall -g
+LDLIBS += -lm
 
 all: all_noverify verify
 
-all_noverify: crda intersect regdbdump
+all_noverify: crda intersect regdbdump db2rd
 
 ifeq ($(USE_OPENSSL),1)
 CFLAGS += -DUSE_OPENSSL -DPUBKEY_DIR=\"$(RUNTIME_PUBKEY_DIR)\" `pkg-config --cflags openssl`
@@ -121,6 +122,10 @@ intersect: reglib.o intersect.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
+db2rd: reglib.o db2rd.o
+	$(NQ) '  LD  ' $@
+	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
 verify: $(REG_BIN) regdbdump
 	$(NQ) '  CHK  $(REG_BIN)'
 	$(Q)./regdbdump $(REG_BIN) >/dev/null
@@ -152,5 +157,6 @@ install: crda crda.8.gz regdbdump.8.gz
 	$(Q)$(INSTALL) -m 644 -t $(DESTDIR)/$(MANDIR)/man8/ regdbdump.8.gz
 
 clean:
-	$(Q)rm -f crda regdbdump intersect *.o *~ *.pyc keys-*.c *.gz \
+	$(Q)rm -f crda regdbdump intersect db2rd \
+		*.o *~ *.pyc keys-*.c *.gz \
 	udev/$(UDEV_LEVEL)regulatory.rules udev/regulatory.rules.parsed
diff --git a/db2rd.c b/db2rd.c
new file mode 100644
index 0000000..fe6f55b
--- /dev/null
+++ b/db2rd.c
@@ -0,0 +1,30 @@
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <arpa/inet.h> /* ntohl */
+#include <string.h>
+
+#include "nl80211.h"
+#include "reglib.h"
+
+int main(int argc, char **argv)
+{
+	struct ieee80211_regdomain *rd = NULL;
+	FILE *fp;
+
+	if (argc != 1) {
+		fprintf(stderr, "Usage: cat db.txt | %s\n", argv[0]);
+		return -EINVAL;
+	}
+
+	fp = reglib_create_parse_stream(stdin);
+
+	reglib_for_each_country_stream(fp, rd) {
+		reglib_print_regdom(rd);
+		free(rd);
+	}
+
+	fclose(fp);
+
+	return 0;
+}
diff --git a/reglib.c b/reglib.c
index b0c61e5..0793fab 100644
--- a/reglib.c
+++ b/reglib.c
@@ -38,6 +38,19 @@
 #include "keys-gcrypt.c"
 #endif
 
+int debug = 0;
+
+struct reglib_rule_parse_list {
+	int n_parsers;
+	int (*rule_parsers[])(char *line, struct ieee80211_reg_rule *reg_rule);
+};
+
+struct reglib_country_parse_list {
+	int n_parsers;
+	int (*country_parsers[])(char *line, struct ieee80211_regdomain *rd);
+};
+
+
 void *
 reglib_get_file_ptr(uint8_t *db, size_t dblen, size_t structlen, uint32_t ptr)
 {
@@ -707,3 +720,529 @@ void reglib_print_regdom(const struct ieee80211_regdomain *rd)
 		print_reg_rule(&rd->reg_rules[i]);
 	printf("\n");
 }
+
+static unsigned int reglib_parse_dfs_region(char *dfs_region)
+{
+	if (strncmp(dfs_region, "DFS-FCC", 7) == 0)
+		return REGDB_DFS_FCC;
+	if (strncmp(dfs_region, "DFS-ETSI", 8) == 0)
+		return REGDB_DFS_ETSI;
+	if (strncmp(dfs_region, "DFS-JP", 6) == 0)
+		return REGDB_DFS_JP;
+	return REGDB_DFS_UNSET;
+}
+
+static uint32_t reglib_parse_rule_flag(char *flag_s)
+{
+	if (strncmp(flag_s, "NO-OFDM", 7) == 0)
+		return RRF_NO_OFDM;
+	if (strncmp(flag_s, "NO-CCK", 6) == 0)
+		return RRF_NO_CCK;
+	if (strncmp(flag_s, "NO-INDOOR", 9) == 0)
+		return RRF_NO_INDOOR;
+	if (strncmp(flag_s, "NO-OUTDOOR", 10) == 0)
+		return RRF_NO_OUTDOOR;
+	if (strncmp(flag_s, "DFS", 3) == 0)
+		return RRF_DFS;
+	if (strncmp(flag_s, "PTP-ONLY", 8) == 0)
+		return RRF_PTP_ONLY;
+	if (strncmp(flag_s, "PTMP-ONLY", 9) == 0)
+		return RRF_PTMP_ONLY;
+	if (strncmp(flag_s, "NO-IR", 5) == 0)
+		return RRF_NO_IR;
+
+	return 0;
+}
+
+static int
+reglib_parse_rule_simple(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+	int hits;
+	float start_freq_khz, end_freq_khz, max_bandwidth_khz, max_eirp;
+
+	hits = sscanf(line, "\t(%f - %f @ %f), (%f)\n",
+		      &start_freq_khz,
+		      &end_freq_khz,
+		      &max_bandwidth_khz,
+		      &max_eirp);
+
+	if (hits != 4)
+		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);
+
+	reg_rule->flags = 0;
+
+	if (debug)
+		printf("reglib_parse_rule_simple(): %d line: %s", hits, line);
+
+
+	return 0;
+}
+
+static int
+reglib_parse_rule_simple_mw(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+	int hits;
+	float start_freq_khz, end_freq_khz, max_bandwidth_khz, max_eirp;
+	char mw[3];
+
+	hits = sscanf(line, "\t(%f - %f @ %f), (%f %2[mW])\n",
+		      &start_freq_khz,
+		      &end_freq_khz,
+		      &max_bandwidth_khz,
+		      &max_eirp, mw);
+
+	if (hits != 4)
+		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);
+
+	reg_rule->flags = 0;
+
+	if (debug)
+		printf("reglib_parse_rule_simple_mw(): %d line: %s",
+		       hits, line);
+
+	return 0;
+}
+
+static int
+reglib_parse_rule_args(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+#define IGNORE_COMMA_OR_SPACE "%*[ ,]"
+	int hits;
+	char flag_list[9][100];
+	unsigned int i = 0;
+	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)"
+		      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,
+		      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 < 5)
+		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]);
+
+	if (debug)
+		printf("reglib_parse_rule_args(): %d flags: %d, line: %s",
+		       hits, reg_rule->flags, line);
+
+	return 0;
+#undef IGNORE_COMMA_OR_SPACE
+}
+
+
+static int
+reglib_parse_rule_args_mw(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+#define IGNORE_COMMA_OR_SPACE "%*[ ,]"
+	int hits;
+	char flag_list[9][100];
+	unsigned int i = 0;
+	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])"
+		      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,
+		      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 < 5)
+		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]);
+
+	if (debug)
+		printf("reglib_parse_rule_args_mw(): %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];
+	char *line_p;
+	unsigned int i;
+	int r = 0;
+	struct reglib_rule_parse_list *reglib_rule_parsers;
+
+	reglib_rule_parsers = malloc(sizeof(struct reglib_rule_parse_list) + 
+				     4 * sizeof(int (*)(char *, struct ieee80211_reg_rule *)));
+	if (!reglib_rule_parsers)
+		return -EINVAL;
+
+	reglib_rule_parsers->n_parsers = 4;
+
+	/*
+	 * 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;
+
+	memset(line, 0, sizeof(line));
+	line_p = fgets(line, sizeof(line), fp);
+	if (line_p != line)
+		return -EINVAL;
+
+	for (i = 0; i < reglib_rule_parsers->n_parsers; i++) {
+		r = reglib_rule_parsers->rule_parsers[i](line, reg_rule);
+		if (r == 0)
+			break;
+	}
+
+	return r;
+}
+
+static uint32_t
+reglib_get_n_rules(FILE *fp, struct ieee80211_reg_rule *reg_rule)
+{
+	uint32_t n_rules = 0;
+	int r;
+	bool save_debug = false;
+
+	save_debug = debug;
+	debug = false;
+
+	while (1) {
+		r = reglib_parse_rule(fp, reg_rule);
+		if (r != 0)
+			break;
+		n_rules++;
+	}
+
+	debug = save_debug;
+
+	return n_rules;
+}
+
+static int reglib_parse_reg_rule(FILE *fp, struct ieee80211_reg_rule *reg_rule)
+{
+	int r;
+
+	while (1) {
+		r = reglib_parse_rule(fp, reg_rule);
+		if (r != 0)
+			continue;
+		return 0;
+	}
+}
+
+static struct ieee80211_regdomain *
+reglib_parse_rules(FILE *fp, struct ieee80211_regdomain *trd)
+{
+	struct ieee80211_regdomain *rd;
+	struct ieee80211_reg_rule rule;
+	struct ieee80211_reg_rule *reg_rule;
+	fpos_t pos;
+	unsigned int i;
+	uint32_t size_of_regd = 0, num_rules = 0;
+	int r;
+
+	memset(&rule, 0, sizeof(rule));
+	reg_rule = &rule;
+
+	r = fgetpos(fp, &pos);
+	if (r != 0) {
+		fprintf(stderr, "fgetpos() failed: %s\n",
+			strerror(errno));
+		return NULL;
+	}
+
+	num_rules = reglib_get_n_rules(fp, reg_rule);
+	if (!num_rules)
+		return NULL;
+
+	size_of_regd = reglib_array_len(sizeof(struct ieee80211_regdomain),
+					num_rules + 1,
+					sizeof(struct ieee80211_reg_rule));
+	rd = malloc(size_of_regd);
+	if (!rd)
+		return NULL;
+
+	memset(rd, 0, size_of_regd);
+	memcpy(rd, trd, sizeof(*trd));
+
+	rd->n_reg_rules = num_rules;
+
+	r = fsetpos(fp, &pos);
+	if (r != 0) {
+		fprintf(stderr, "fsetpos() failed: %s\n",
+			strerror(errno));
+		free(rd);
+		return NULL;
+	}
+	for (i = 0; i < num_rules; i++) {
+		struct ieee80211_reg_rule *rrule = &rd->reg_rules[i];
+
+		if (reglib_parse_reg_rule(fp, rrule) != 0) {
+			fprintf(stderr, "rule parse failed\n");
+			free(rd);
+			return NULL;
+		}
+	}
+	return rd;
+}
+
+static int
+reglib_parse_country_simple(char *line, struct ieee80211_regdomain *rd)
+{
+	char dfs_region_alpha[9];
+	char alpha2[2];
+	int hits;
+
+	memset(rd, 0, sizeof(rd));
+	memset(alpha2, 0, sizeof(alpha2));
+	memset(dfs_region_alpha, 0, sizeof(dfs_region_alpha));
+
+	hits = sscanf(line, "country %2[a-zA-Z0-9]:",
+		      alpha2);
+
+	if (hits != 1)
+		return -EINVAL;
+
+	rd->alpha2[0] = alpha2[0];
+	rd->alpha2[1] = alpha2[1];
+
+	return 0;
+}
+
+static int reglib_parse_country_dfs(char *line, struct ieee80211_regdomain *rd)
+{
+	char dfs_region_alpha[9];
+	char alpha2[2];
+	int hits;
+
+	memset(rd, 0, sizeof(rd));
+	memset(alpha2, 0, sizeof(alpha2));
+	memset(dfs_region_alpha, 0, sizeof(dfs_region_alpha));
+
+	hits = sscanf(line, "country %2[a-zA-Z0-9]:%*[ ]%s\n",
+		      alpha2,
+		      dfs_region_alpha);
+	if (hits <= 0)
+		return -EINVAL;
+
+	if (hits != 2)
+		return -EINVAL;
+
+
+	rd->alpha2[0] = alpha2[0];
+	rd->alpha2[1] = alpha2[1];
+	rd->dfs_region = reglib_parse_dfs_region(dfs_region_alpha);
+
+	return 0;
+}
+
+struct ieee80211_regdomain *__reglib_parse_country(FILE *fp)
+{
+	struct ieee80211_regdomain *rd;
+	struct ieee80211_regdomain tmp_rd;
+	char line[1024];
+	char *line_p;
+	unsigned int i;
+	int r = 0;
+	struct reglib_country_parse_list *reglib_country_parsers;
+
+	reglib_country_parsers = malloc(sizeof(struct reglib_country_parse_list) +
+					2 * sizeof(int (*)(char *, struct ieee80211_regdomain *)));
+	if (!reglib_country_parsers)
+		return NULL;
+
+	reglib_country_parsers->n_parsers = 2;
+	reglib_country_parsers->country_parsers[0] =
+			reglib_parse_country_simple;
+	reglib_country_parsers->country_parsers[1] =
+			reglib_parse_country_dfs;
+
+	memset(&tmp_rd, 0, sizeof(tmp_rd));
+	memset(line, 0, sizeof(line));
+
+	line_p = fgets(line, sizeof(line), fp);
+
+	if (line_p != line)
+		return NULL;
+
+	for (i = 0; i < reglib_country_parsers->n_parsers; i++) {
+		r = reglib_country_parsers->country_parsers[i](line, &tmp_rd);
+		if (r == 0)
+			break;
+	}
+
+	if (r != 0) {
+		fprintf(stderr, "Invalid country line: %s", line);
+		return NULL;
+	}
+
+	rd = reglib_parse_rules(fp, &tmp_rd);
+
+	return rd;
+}
+
+static int reglib_find_next_country_stream(FILE *fp)
+{
+	fpos_t prev_pos;
+	int r;
+	unsigned int i = 0;
+
+	while(1) {
+		char line[1024];
+		char *line_p;
+
+		r = fgetpos(fp, &prev_pos);
+		if (r != 0) {
+			fprintf(stderr, "fgetpos() failed: %s\n",
+				strerror(errno));
+			return r;
+		}
+
+		memset(line, 0, sizeof(line));
+
+		line_p = fgets(line, sizeof(line), fp);
+		if (line_p == line) {
+			if (strspn(line, "\n") == strlen(line)) {
+				i++;
+				continue;
+			}
+			if (strncmp(line, "country", 7) != 0)
+				continue;
+			r = fsetpos(fp, &prev_pos);
+			if (r != 0) {
+				fprintf(stderr, "fsetpos() failed: %s\n",
+					strerror(errno));
+				return r;
+			}
+			return 0;
+		} else
+			return EOF;
+	}
+}
+
+struct ieee80211_regdomain *reglib_parse_country(FILE *fp)
+{
+	int r;
+
+	r = reglib_find_next_country_stream(fp);
+	if (r != 0)
+		return NULL;
+	return __reglib_parse_country(fp);
+}
+
+FILE *reglib_create_parse_stream(FILE *f)
+{
+	unsigned int lines = 0;
+	FILE *fp;
+
+	fp = tmpfile();
+	if (errno) {
+		fprintf(stderr, "%s\n", strerror(errno));
+		return NULL;
+	}
+
+	while(1) {
+		char line[1024];
+		char *line_p;
+
+		line_p = fgets(line, sizeof(line), f);
+		if (line_p == line) {
+			if (strchr(line, '#') == NULL) {
+				fputs(line, fp);
+				lines++;
+			}
+			continue;
+		} else
+			break;
+	}
+
+	rewind(fp);
+	fflush(fp);
+
+	return fp;
+}
diff --git a/reglib.h b/reglib.h
index 7a586a3..885792e 100644
--- a/reglib.h
+++ b/reglib.h
@@ -1,10 +1,12 @@
 #ifndef REG_LIB_H
 #define REG_LIB_H
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <sys/stat.h>
+#include <math.h>
 
 #include "regdb.h"
 
@@ -35,6 +37,19 @@ struct ieee80211_regdomain {
 	struct ieee80211_reg_rule reg_rules[];
 };
 
+/* Remove this once upstream nl80211.h gets this */
+#define NL80211_RRF_NO_IR (1<<7)
+
+#define REGLIB_MHZ_TO_KHZ(freq) ((freq) * 1000)
+#define REGLIB_KHZ_TO_MHZ(freq) ((freq) / 1000)
+#define REGLIB_DBI_TO_MBI(gain) ((gain) * 100)
+#define REGLIB_MBI_TO_DBI(gain) ((gain) / 100)
+#define REGLIB_DBM_TO_MBM(gain) ((gain) * 100)
+#define REGLIB_MBM_TO_DBM(gain) ((gain) / 100)
+
+#define REGLIB_MW_TO_DBM(gain) (10 * log10(gain))
+#define REGLIB_MW_TO_MBM(gain) (REGLIB_DBM_TO_MBM(REGLIB_MW_TO_DBM(gain)))
+
 /**
  * struct reglib_regdb_ctx - reglib regdb context
  *
@@ -180,4 +195,33 @@ reglib_intersect_rds(const struct ieee80211_regdomain *rd1,
 const struct ieee80211_regdomain *
 reglib_intersect_regdb(const struct reglib_regdb_ctx *ctx);
 
+/**
+ * @reglib_create_parse_stream - provide a clean new stream for processing
+ *
+ * @fp: FILE stream, could be stdin, or a stream from an open file.
+ *
+ * In order to parse a stream we recommend to create a new stream
+ * using this helper. A new stream is preferred in order to work
+ * with stdin, as otherwise we cannot rewind() and move around
+ * the stream. This helper will create new stream using tmpfile()
+ * and also remove all comments. It will be closed and the file
+ * deleted when the process terminates.
+ */
+FILE *reglib_create_parse_stream(FILE *fp);
+
+/**
+ * @reglib_parse_country - parse stream to build a regulatory domain
+ *
+ * @fp: FILE stream, could be stdin, or a stream from an open file.
+ *
+ * Parse stream and return back a built regulatory domain. Returns
+ * NULL if one could not be built.
+ */
+struct ieee80211_regdomain *reglib_parse_country(FILE *fp);
+
+#define reglib_for_each_country_stream(__fp, __rd)		\
+	for (__rd = reglib_parse_country(__fp);			\
+	     __rd != NULL;					\
+	     __rd = reglib_parse_country(__fp))			\
+
 #endif
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 21:53:01 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 02:53:01 +0100
Subject: [wireless-regdb] [PATCH 5/6] crda: make ssl keys include stdint.h
In-Reply-To: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382925182-7393-6-git-send-email-mcgrof@do-not-panic.com>

This is required to fix compilation if we
move reglig to its own library.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 utils/key2pub.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/utils/key2pub.py b/utils/key2pub.py
index 4d85369..3e84cd2 100755
--- a/utils/key2pub.py
+++ b/utils/key2pub.py
@@ -59,6 +59,7 @@ def print_ssl_32(output, name, val):
 
 def print_ssl(output, name, val):
     import struct
+    output.write('#include <stdint.h>\n')
     if len(struct.pack('@L', 0)) == 8:
         return print_ssl_64(output, name, val)
     else:
@@ -85,6 +86,7 @@ static struct pubkey keys[] = {
     pass
 
 def print_gcrypt(output, name, val):
+    output.write('#include <stdint.h>\n')
     while val[0] == '\0':
         val = val[1:]
     output.write('static const uint8_t %s[%d] = {\n' % (name, len(val)))
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 21:53:00 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 02:53:00 +0100
Subject: [wireless-regdb] [PATCH 4/6] crda: add regulatory domain optimizer
In-Reply-To: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382925182-7393-5-git-send-email-mcgrof@do-not-panic.com>

This adds a regulatory domain optimizer which can be
used with information of a regulatory domain in db.txt
format in stdin. It makes use of the new shiny regulatory
domain stream parser.

The way this works is it iterates over the regulatory domain
computing unions between each frequency, starting from each
frequency as a pivot. If a union leads to a valid regulatory
rule we verify that the pivot and othre frequency rules that
provided that valid union can fit into that union regulatory
rule by computing an intersection. If an intersection is
possible it means two rules can be optimized out. We do
this repetitively.

Screenshot:

mcgrof at frijol ~/devel/crda (git::master)$ cat us
country US: DFS-FCC
        (5170 - 5190 @ 20), (17)
        (5190 - 5210 @ 20), (17)
        (5210 - 5230 @ 20), (17)
        (5230 - 5250 @ 20), (17)
        (5250 - 5270 @ 20), (23), DFS
        (5270 - 5290 @ 20), (23), DFS
        (5290 - 5310 @ 20), (23), DFS
        (5310 - 5330 @ 20), (23), DFS
        (5735 - 5755 @ 20), (30)
        (5755 - 5775 @ 20), (30)
        (5775 - 5795 @ 20), (30)
        (5795 - 5815 @ 20), (30)
        (5815 - 5835 @ 20), (30)
        (5170 - 5210 @ 40), (17)
        (5210 - 5250 @ 40), (17)
        (5250 - 5290 @ 40), (23), DFS
        (5290 - 5330 @ 40), (23), DFS
        (5735 - 5775 @ 40), (30)
        (5775 - 5815 @ 40), (30)
        (5170 - 5250 @ 80), (17)
        (5250 - 5330 @ 80), (23), DFS
        (5735 - 5815 @ 80), (30)

mcgrof at frijol ~/devel/crda (git::master)$ cat us | ./optimize
country US: DFS-UNSET
        (5170.000 - 5250.000 @ 80.000), (17.00)
        (5250.000 - 5330.000 @ 80.000), (23.00), DFS
        (5735.000 - 5835.000 @ 80.000), (30.00)

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 Makefile   |   8 +-
 optimize.c |  38 ++++++++++
 reglib.c   | 251 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 reglib.h   |  16 ++++
 4 files changed, 311 insertions(+), 2 deletions(-)
 create mode 100644 optimize.c

diff --git a/Makefile b/Makefile
index bd9c220..9e37ccd 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ LDLIBS += -lm
 
 all: all_noverify verify
 
-all_noverify: crda intersect regdbdump db2rd
+all_noverify: crda intersect regdbdump db2rd optimize
 
 ifeq ($(USE_OPENSSL),1)
 CFLAGS += -DUSE_OPENSSL -DPUBKEY_DIR=\"$(RUNTIME_PUBKEY_DIR)\" `pkg-config --cflags openssl`
@@ -126,6 +126,10 @@ db2rd: reglib.o db2rd.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
+optimize: reglib.o optimize.o
+	$(NQ) '  LD  ' $@
+	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
 verify: $(REG_BIN) regdbdump
 	$(NQ) '  CHK  $(REG_BIN)'
 	$(Q)./regdbdump $(REG_BIN) >/dev/null
@@ -157,6 +161,6 @@ install: crda crda.8.gz regdbdump.8.gz
 	$(Q)$(INSTALL) -m 644 -t $(DESTDIR)/$(MANDIR)/man8/ regdbdump.8.gz
 
 clean:
-	$(Q)rm -f crda regdbdump intersect db2rd \
+	$(Q)rm -f crda regdbdump intersect db2rd optimize \
 		*.o *~ *.pyc keys-*.c *.gz \
 	udev/$(UDEV_LEVEL)regulatory.rules udev/regulatory.rules.parsed
diff --git a/optimize.c b/optimize.c
new file mode 100644
index 0000000..c87371d
--- /dev/null
+++ b/optimize.c
@@ -0,0 +1,38 @@
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <arpa/inet.h> /* ntohl */
+#include <string.h>
+
+#include "nl80211.h"
+#include "reglib.h"
+
+int main(int argc, char **argv)
+{
+	struct ieee80211_regdomain *rd = NULL, *rd_opt = NULL;
+	FILE *fp;
+
+	if (argc != 1) {
+		fprintf(stderr, "Usage: cat db.txt | %s\n", argv[0]);
+		return -EINVAL;
+	}
+
+	fp = reglib_create_parse_stream(stdin);
+
+	reglib_for_each_country_stream(fp, rd) {
+		rd_opt = reglib_optimize_regdom(rd);
+		if (!rd_opt){
+			fprintf(stderr, "Unable to optimize %c%c\n",
+				rd->alpha2[0],
+				rd->alpha2[1]);
+			free(rd);
+			continue;
+		}
+		reglib_print_regdom(rd_opt);
+		free(rd);
+		free(rd_opt);
+	}
+
+	fclose(fp);
+	return 0;
+}
diff --git a/reglib.c b/reglib.c
index 0793fab..ae4b017 100644
--- a/reglib.c
+++ b/reglib.c
@@ -459,6 +459,43 @@ int reglib_is_valid_rd(const struct ieee80211_regdomain *rd)
 	return 1;
 }
 
+static int reg_rules_union(const struct ieee80211_reg_rule *rule1,
+			   const struct ieee80211_reg_rule *rule2,
+			   struct ieee80211_reg_rule *union_rule)
+{
+	const struct ieee80211_freq_range *freq_range1, *freq_range2;
+	struct ieee80211_freq_range *freq_range;
+	const struct ieee80211_power_rule *power_rule1, *power_rule2;
+	struct ieee80211_power_rule *power_rule;
+
+	freq_range1 = &rule1->freq_range;
+	freq_range2 = &rule2->freq_range;
+	freq_range = &union_rule->freq_range;
+
+	power_rule1 = &rule1->power_rule;
+	power_rule2 = &rule2->power_rule;
+	power_rule = &union_rule->power_rule;
+
+	freq_range->start_freq_khz = reglib_min(freq_range1->start_freq_khz,
+					 freq_range2->start_freq_khz);
+	freq_range->end_freq_khz = reglib_max(freq_range1->end_freq_khz,
+				       freq_range2->end_freq_khz);
+	freq_range->max_bandwidth_khz = reglib_max(freq_range1->max_bandwidth_khz,
+					    freq_range2->max_bandwidth_khz);
+
+	power_rule->max_eirp = reglib_max(power_rule1->max_eirp,
+		power_rule2->max_eirp);
+	power_rule->max_antenna_gain = reglib_max(power_rule1->max_antenna_gain,
+		power_rule2->max_antenna_gain);
+
+	union_rule->flags = rule1->flags | rule2->flags;
+
+	if (!is_valid_reg_rule(union_rule))
+		return -EINVAL;
+
+	return 0;
+}
+
 /*
  * Helper for reglib_intersect_rds(), this does the real
  * mathematical intersection fun
@@ -1246,3 +1283,217 @@ FILE *reglib_create_parse_stream(FILE *f)
 
 	return fp;
 }
+
+/*
+ * The idea behind a rule key is that if two rule keys share the
+ * same key they can be merged together if their frequencies overlap.
+ */
+static uint64_t reglib_rule_key(struct ieee80211_reg_rule *reg_rule)
+{
+	struct ieee80211_power_rule *power_rule;
+	uint32_t key;
+
+	power_rule = &reg_rule->power_rule;
+
+	key = ((power_rule->max_eirp ^ 0) << 0) ^
+	      ((reg_rule->flags      ^ 8) << 8);
+
+	return key;
+}
+
+/* XXX: cannot support > 32 rules */
+struct reglib_optimize_map {
+	bool optimized[32];
+	uint32_t keys[32];
+};
+
+/* Does the provided rule suffice both of the other two */
+static int reglib_opt_rule_fit(struct ieee80211_reg_rule *rule1,
+			       struct ieee80211_reg_rule *rule2,
+			       struct ieee80211_reg_rule *opt_rule)
+{
+	struct ieee80211_reg_rule interesected_rule;
+	struct ieee80211_reg_rule *int_rule;
+	int r;
+
+	memset(&interesected_rule, 0, sizeof(struct ieee80211_reg_rule));
+	int_rule = &interesected_rule;
+
+	r = reg_rules_intersect(rule1, opt_rule, int_rule);
+	if (r != 0)
+		return r;
+	r = reg_rules_intersect(rule2, opt_rule, int_rule);
+	if (r != 0)
+		return r;
+
+	return 0;
+}
+
+static int reg_rule_optimize(struct ieee80211_reg_rule *rule1,
+			     struct ieee80211_reg_rule *rule2,
+			     struct ieee80211_reg_rule *opt_rule)
+{
+	int r;
+
+	r = reg_rules_union(rule1, rule2, opt_rule);
+	if (r != 0)
+		return r;
+	r = reglib_opt_rule_fit(rule1, rule2, opt_rule);
+	if (r != 0)
+		return r;
+
+	return 0;
+}
+
+/*
+ * Here's the math explanation:
+ *
+ * This takes each pivot frequency on the regulatory domain, computes
+ * the union between it each regulatory rule on the regulatory domain
+ * sequentially, and after that it tries to verify that the pivot frequency
+ * fits on it by computing an intersection between it and the union, if
+ * a rule exist as a possible intersection then we know the rule can be
+ * subset of the combination of the two frequency ranges (union) computed.
+ */
+static unsigned int reg_rule_optimize_rd(struct ieee80211_regdomain *rd,
+					 unsigned int rule_idx,
+					 struct ieee80211_reg_rule *opt_rule,
+					 struct reglib_optimize_map *opt_map)
+{
+	unsigned int i;
+	struct ieee80211_reg_rule *rule1;
+	struct ieee80211_reg_rule *rule2;
+
+	struct ieee80211_reg_rule tmp_optimized_rule;
+	struct ieee80211_reg_rule *tmp_opt_rule;
+
+	struct ieee80211_reg_rule *target_rule;
+
+	unsigned int optimized = 0;
+	int r;
+
+	if (rule_idx > rd->n_reg_rules)
+		return 0;
+
+	rule1 = &rd->reg_rules[rule_idx];
+
+	memset(&tmp_optimized_rule, 0, sizeof(struct ieee80211_reg_rule));
+	tmp_opt_rule = &tmp_optimized_rule;
+
+	memset(opt_rule, 0, sizeof(*opt_rule));
+
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		if (rule_idx == i)
+			continue;
+		rule2 = &rd->reg_rules[i];
+		if (opt_map->keys[rule_idx] != opt_map->keys[i])
+			continue;
+
+		target_rule = optimized ? opt_rule : rule1;
+		r = reg_rule_optimize(target_rule, rule2, tmp_opt_rule);
+		if (r != 0)
+			continue;
+		memcpy(opt_rule, tmp_opt_rule, sizeof(*tmp_opt_rule));
+
+		if (!opt_map->optimized[i]) {
+			opt_map->optimized[i] = true;
+			optimized++;
+		}
+		if (!opt_map->optimized[rule_idx]) {
+			opt_map->optimized[rule_idx] = true;
+			optimized++;
+		}
+	}
+	return optimized;
+}
+
+struct ieee80211_regdomain *
+reglib_optimize_regdom(struct ieee80211_regdomain *rd)
+{
+	struct ieee80211_regdomain *opt_rd = NULL;
+	struct ieee80211_reg_rule *reg_rule;
+	struct ieee80211_reg_rule *reg_rule_dst;
+	struct ieee80211_reg_rule optimized_reg_rule;
+	struct ieee80211_reg_rule *opt_reg_rule;
+	struct reglib_optimize_map opt_map;
+	unsigned int i, idx = 0, non_opt = 0, opt = 0;
+	size_t num_rules, size_of_regd;
+	unsigned int num_opts = 0;
+
+	memset(&opt_map, 0, sizeof(struct reglib_optimize_map));
+	memset(&optimized_reg_rule, 0, sizeof(struct ieee80211_reg_rule));
+
+	opt_reg_rule = &optimized_reg_rule;
+
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		reg_rule = &rd->reg_rules[i];
+		opt_map.keys[i] = reglib_rule_key(reg_rule);
+	}
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		reg_rule = &rd->reg_rules[i];
+		if (opt_map.optimized[i])
+			continue;
+		num_opts = reg_rule_optimize_rd(rd, i, opt_reg_rule, &opt_map);
+		if (!num_opts)
+			non_opt++;
+		else
+			opt += (num_opts ? 1 : 0);
+	}
+
+	num_rules = non_opt + opt;
+
+	if (num_rules > rd->n_reg_rules)
+		return NULL;
+
+	size_of_regd = reglib_array_len(sizeof(struct ieee80211_regdomain),
+					num_rules + 1,
+					sizeof(struct ieee80211_reg_rule));
+
+	opt_rd = malloc(size_of_regd);
+	if (!opt_rd)
+		return NULL;
+	memset(opt_rd, 0, size_of_regd);
+
+	opt_rd->n_reg_rules = num_rules;
+	opt_rd->alpha2[0] = rd->alpha2[0];
+	opt_rd->alpha2[1] = rd->alpha2[1];
+	opt_rd->dfs_region = rd->dfs_region;
+
+	memset(&opt_map, 0, sizeof(struct reglib_optimize_map));
+	memset(&optimized_reg_rule, 0, sizeof(struct ieee80211_reg_rule));
+
+	opt_reg_rule = &optimized_reg_rule;
+
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		reg_rule = &rd->reg_rules[i];
+		opt_map.keys[i] = reglib_rule_key(reg_rule);
+	}
+
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		reg_rule = &rd->reg_rules[i];
+		reg_rule_dst = &opt_rd->reg_rules[idx];
+		if (opt_map.optimized[i])
+			continue;
+		num_opts = reg_rule_optimize_rd(rd, i, opt_reg_rule, &opt_map);
+		if (!num_opts)
+			memcpy(reg_rule_dst, reg_rule, sizeof(struct ieee80211_reg_rule));
+		else
+			memcpy(reg_rule_dst, opt_reg_rule, sizeof(struct ieee80211_reg_rule));
+		idx++;
+	}
+
+	if (idx != num_rules) {
+		free(opt_rd);
+		return NULL;
+	}
+
+	for (i = 0; i < opt_rd->n_reg_rules; i++) {
+		reg_rule = &opt_rd->reg_rules[i];
+		if (!is_valid_reg_rule(reg_rule)) {
+			free(opt_rd);
+			return NULL;
+		}
+	}
+
+	return opt_rd;
+}
diff --git a/reglib.h b/reglib.h
index 885792e..d570c36 100644
--- a/reglib.h
+++ b/reglib.h
@@ -219,6 +219,22 @@ FILE *reglib_create_parse_stream(FILE *fp);
  */
 struct ieee80211_regdomain *reglib_parse_country(FILE *fp);
 
+/**
+ * @reglib_optimize_regdom - optimize a regulatory domain
+ *
+ * @rd: a regulatory domain to be optimized
+ *
+ * A regulatory domain may exist without optimal expressions
+ * over its rules. This will look for regulatory rules that can
+ * be combined together to reduce the size of the regulatory
+ * domain and its expression.
+ *
+ * Regulatory rules will be combined if their max allowed
+ * bandwidth, max EIRP, and flags all match.
+ */
+struct ieee80211_regdomain *
+reglib_optimize_regdom(struct ieee80211_regdomain *rd);
+
 #define reglib_for_each_country_stream(__fp, __rd)		\
 	for (__rd = reglib_parse_country(__fp);			\
 	     __rd != NULL;					\
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 21:53:02 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 02:53:02 +0100
Subject: [wireless-regdb] [PATCH 6/6] crda: make reglib a shared library
In-Reply-To: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382925182-7393-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382925182-7393-7-git-send-email-mcgrof@do-not-panic.com>

Now that we have quite a few helpers this puts the more
valuable helpers into a library.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 Makefile | 48 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index 9e37ccd..4a351c6 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,8 @@ REG_GIT?=git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-regdb.g
 
 PREFIX ?= /usr/
 MANDIR ?= $(PREFIX)/share/man/
+INCLUDE_DIR ?= $(PREFIX)/include/reglib/
+LIBDIR ?= $(PREFIX)/lib
 
 SBINDIR ?= /sbin/
 
@@ -23,24 +25,29 @@ UDEV_RULE_DIR?=/lib/udev/rules.d/
 PUBKEY_DIR?=pubkeys
 RUNTIME_PUBKEY_DIR?=/etc/wireless-regdb/pubkeys
 
+CFLAGS += -O2 -fpic
+CFLAGS += -std=gnu99 -Wall -Werror -pedantic
 CFLAGS += -Wall -g
 LDLIBS += -lm
+LDLIBREG += -lreg
+LIBREG += libreg.so
+LDFLAGS += -L ./ $(LDLIBREG)
 
 all: all_noverify verify
 
-all_noverify: crda intersect regdbdump db2rd optimize
+all_noverify: $(LIBREG) crda intersect regdbdump db2rd optimize
 
 ifeq ($(USE_OPENSSL),1)
 CFLAGS += -DUSE_OPENSSL -DPUBKEY_DIR=\"$(RUNTIME_PUBKEY_DIR)\" `pkg-config --cflags openssl`
 LDLIBS += `pkg-config --libs openssl`
 
-reglib.o: keys-ssl.c
+$(LIBREG): keys-ssl.c
 
 else
 CFLAGS += -DUSE_GCRYPT
 LDLIBS += -lgcrypt
 
-reglib.o: keys-gcrypt.c
+$(LIBREG): keys-gcrypt.c
 
 endif
 MKDIR ?= mkdir -p
@@ -106,39 +113,56 @@ keys-%.c: utils/key2pub.py $(wildcard $(PUBKEY_DIR)/*.pem)
 	$(NQ) '  Trusted pubkeys:' $(wildcard $(PUBKEY_DIR)/*.pem)
 	$(Q)./utils/key2pub.py --$* $(wildcard $(PUBKEY_DIR)/*.pem) $@
 
-%.o: %.c regdb.h reglib.h
+$(LIBREG): regdb.h reglib.h reglib.c
+	$(NQ) '  CC  ' $@
+	$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -shared -Wl,-soname,$(LIBREG) $^
+
+install-libreg-headers:
+	$(NQ) '  INSTALL  libreg-headers'
+	$(Q)mkdir -p $(INCLUDE_DIR)
+	$(Q)cp *.h $(INCLUDE_DIR)/
+
+install-libreg:
+	$(NQ) '  INSTALL  libreg'
+	$(Q)mkdir -p $(LIBDIR)
+	$(Q)cp $(LIBREG) $(LIBDIR)/
+	$(Q)ldconfig
+
+%.o: %.c regdb.h $(LIBREG)
 	$(NQ) '  CC  ' $@
 	$(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
 
-crda: reglib.o crda.o
+crda: crda.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(NLLIBS)
 
-regdbdump: reglib.o regdbdump.o
+regdbdump: regdbdump.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-intersect: reglib.o intersect.o
+intersect: intersect.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-db2rd: reglib.o db2rd.o
+db2rd: db2rd.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-optimize: reglib.o optimize.o
+optimize: optimize.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
 verify: $(REG_BIN) regdbdump
 	$(NQ) '  CHK  $(REG_BIN)'
-	$(Q)./regdbdump $(REG_BIN) >/dev/null
+	$(Q)\
+		LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) \
+		./regdbdump $(REG_BIN) >/dev/null
 
 %.gz: %
 	@$(NQ) ' GZIP' $<
 	$(Q)gzip < $< > $@
 
-install: crda crda.8.gz regdbdump.8.gz
+install: install-libreg install-libreg-headers crda crda.8.gz regdbdump.8.gz
 	$(NQ) '  INSTALL  crda'
 	$(Q)$(MKDIR) $(DESTDIR)/$(SBINDIR)
 	$(Q)$(INSTALL) -m 755 -t $(DESTDIR)/$(SBINDIR) crda
@@ -161,6 +185,6 @@ install: crda crda.8.gz regdbdump.8.gz
 	$(Q)$(INSTALL) -m 644 -t $(DESTDIR)/$(MANDIR)/man8/ regdbdump.8.gz
 
 clean:
-	$(Q)rm -f crda regdbdump intersect db2rd optimize \
+	$(Q)rm -f $(LIBREG) crda regdbdump intersect db2rd optimize \
 		*.o *~ *.pyc keys-*.c *.gz \
 	udev/$(UDEV_LEVEL)regulatory.rules udev/regulatory.rules.parsed
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 22:19:44 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 03:19:44 +0100
Subject: [wireless-regdb] [PATCH 0/2] cfg80211: a few genregdb.awk updates
Message-ID: <1382926786-7904-1-git-send-email-mcgrof@do-not-panic.com>

A few updates while toying with genregdb.awk for small
regulatory domains. This depends on the antenna gain removal
patch.

Luis R. Rodriguez (2):
  cfg80211: add function helpers to genregdb.awk
  cfg80211: fix parsing when db.txt ends on a rule

 net/wireless/genregdb.awk | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 22:19:45 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 03:19:45 +0100
Subject: [wireless-regdb] [PATCH 1/2] cfg80211: add function helpers to
	genregdb.awk
In-Reply-To: <1382926786-7904-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382926786-7904-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382926786-7904-2-git-send-email-mcgrof@do-not-panic.com>

This has no functional change, this just lets us reuse
helpers at a later time.

Cc: John W. Linville <linville at tuxdriver.com>
Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 net/wireless/genregdb.awk | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
index 3e241e4e..95baf61 100755
--- a/net/wireless/genregdb.awk
+++ b/net/wireless/genregdb.awk
@@ -33,15 +33,7 @@ BEGIN {
 	regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n"
 }
 
-/^[ \t]*#/ {
-	# Ignore
-}
-
-!active && /^[ \t]*$/ {
-	# Ignore
-}
-
-!active && /country/ {
+function parse_country_head() {
 	country=$2
 	sub(/:/, "", country)
 	printf "static const struct ieee80211_regdomain regdom_%s = {\n", country
@@ -57,7 +49,8 @@ BEGIN {
 	regdb = regdb "\t&regdom_" country ",\n"
 }
 
-active && /^[ \t]*\(/ {
+function parse_reg_rule()
+{
 	start = $1
 	sub(/\(/, "", start)
 	end = $3
@@ -117,7 +110,8 @@ active && /^[ \t]*\(/ {
 	rules++
 }
 
-active && /^[ \t]*$/ {
+function print_tail_country()
+{
 	active = 0
 	printf "\t},\n"
 	printf "\t.n_reg_rules = %d\n", rules
@@ -125,6 +119,26 @@ active && /^[ \t]*$/ {
 	rules = 0;
 }
 
+/^[ \t]*#/ {
+	# Ignore
+}
+
+!active && /^[ \t]*$/ {
+	# Ignore
+}
+
+!active && /country/ {
+	parse_country_head()
+}
+
+active && /^[ \t]*\(/ {
+	parse_reg_rule()
+}
+
+active && /^[ \t]*$/ {
+	print_tail_country()
+}
+
 END {
 	print regdb "};"
 	print ""
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Sun Oct 27 22:19:46 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 03:19:46 +0100
Subject: [wireless-regdb] [PATCH 2/2] cfg80211: fix parsing when db.txt ends
	on a rule
In-Reply-To: <1382926786-7904-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382926786-7904-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382926786-7904-3-git-send-email-mcgrof@do-not-panic.com>

If genregdb.awk assumes the file will end with an
extra empty line or a comment line. This is could
not be true so just address this.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 net/wireless/genregdb.awk | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
index 95baf61..13b982d 100755
--- a/net/wireless/genregdb.awk
+++ b/net/wireless/genregdb.awk
@@ -140,6 +140,8 @@ active && /^[ \t]*$/ {
 }
 
 END {
+	if (active)
+		print_tail_country()
 	print regdb "};"
 	print ""
 	print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);"
-- 
1.8.4.rc3



From johannes at sipsolutions.net  Mon Oct 28 09:58:55 2013
From: johannes at sipsolutions.net (Johannes Berg)
Date: Mon, 28 Oct 2013 14:58:55 +0100
Subject: [wireless-regdb] [PATCH 0/2] cfg80211: a few genregdb.awk
	updates
In-Reply-To: <1382926786-7904-1-git-send-email-mcgrof@do-not-panic.com>
 (sfid-20131028_031957_213221_A0C78DB8)
References: <1382926786-7904-1-git-send-email-mcgrof@do-not-panic.com>
 (sfid-20131028_031957_213221_A0C78DB8)
Message-ID: <1382968735.17956.12.camel@jlt4.sipsolutions.net>

I'd apply this, but would prefer John to take a look - he wrote the awk
script and I'm not familiar with it.

johannes



From mcgrof at do-not-panic.com  Mon Oct 28 12:42:00 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 17:42:00 +0100
Subject: [wireless-regdb] [PATCH v2 0/6] crda: few more updates
Message-ID: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>

Here's a second spin, after quite a bit more testing I ran
into a few small issues with the parser and library. This
has these additional fixes / enhancements:

  * Lifts the restriction on 32 rules, although the kernel
    is limited by this we don't adhere to this limit on our
    stream parser or optimizer

  * The union code got updated to address two cases that are
    invalid for unions

  * A few fixes on db2rd and optimizer on using the stream
    parser, if its NULL, bail, we weren't checking for it

  * The optimizer was not considering band differences as
    part of its key broker (when it decides it can use
    two rules for optimization), to address this we deduce
    the band and add that to the key mixing. Note that this
    will need to be updated upon new frequency band additions.
    This limits the scope of optimizations between their own
    respective bands.

I've also gone ahead and tested this with a huge fluffy
non optimized regulatory domain of 40 rules, and also with
the wireless-regdb db.txt. I'll send some optimizations
based on this for wireless-regdb.

The only patches that go modified are the stream parser
and the optimizer.

Luis R. Rodriguez (6):
  crda: relicense under copyleft-next-0.3.0
  crda: fix -pedantic gcc compilation
  crda: add regulatory domain stream parser
  crda: add regulatory domain optimizer
  crda: make ssl keys include stdint.h
  crda: make reglib a shared library

 LICENSE             |  14 +-
 Makefile            |  54 +++-
 copyleft-next-0.3.0 | 219 ++++++++++++++
 crda.c              |   4 +-
 db2rd.c             |  32 ++
 optimize.c          |  40 +++
 reglib.c            | 839 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 reglib.h            |  60 ++++
 utils/key2pub.py    |   2 +
 9 files changed, 1252 insertions(+), 12 deletions(-)
 create mode 100644 copyleft-next-0.3.0
 create mode 100644 db2rd.c
 create mode 100644 optimize.c

-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Mon Oct 28 12:42:01 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 17:42:01 +0100
Subject: [wireless-regdb] [PATCH v2 1/6] crda: relicense under
	copyleft-next-0.3.0
In-Reply-To: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382978526-23929-2-git-send-email-mcgrof@do-not-panic.com>

I'm relicensing CRDA to copyleft-next-0.3.0. The original
motivation was to help with the BSD family but they are not
using any of this software and as this software grows I'd
like to ensure we use the best free software license
possible.

Fontana's work on copyleft-next is great and has good
community traction. At this point development for
copyleft-next has slowed down as copyleft-next-0.3.0
is already a good, usable alternative to GPLv2 and GPLv3.

A few notes:

  * With copyleft we don't have to specify 'at your option
    any later version' since the license allows that by
    default.

  * Some folks might wonder if copyleft-next-0.3.0 is
    OSI OSD-conformant or FSF-free since neither of
    those bodies have examined the license officially,
    but note, although IANAL, that copyleft-next is
    outbound-compatible with GPLv2 and GPLv3

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 LICENSE             |  14 +++-
 copyleft-next-0.3.0 | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 232 insertions(+), 1 deletion(-)
 create mode 100644 copyleft-next-0.3.0

diff --git a/LICENSE b/LICENSE
index 652a6dd..cc26ff2 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,16 @@
-Copyright (c) 2008, Luis R. Rodriguez <mcgrof at gmail.com>
+Copyright (c) 2013, Luis R. Rodriguez <mcgrof at do-not-panic.com>
+
+CRDA is licensed under copyleft-next 0.3.0
+
+Refer to copyleft-next-0.3.0 for license details, you can
+also always get the latest updates of copyleft-next from:
+
+https://gitorious.org/copyleft-next/
+
+This file incorporates work covered by the following copyright and
+permission notice:
+
+Copyright (c) 2008, Luis R. Rodriguez <mcgrof at do-not-panic.com>
 Copyright (c) 2008, Johannes Berg <johannes at sipsolutions.net>
 Copyright (c) 2008, Michael Green <Michael.Green at Atheros.com>
 
diff --git a/copyleft-next-0.3.0 b/copyleft-next-0.3.0
new file mode 100644
index 0000000..a66d5bf
--- /dev/null
+++ b/copyleft-next-0.3.0
@@ -0,0 +1,219 @@
+                   copyleft-next 0.3.0 ("this License")
+                         Release date: 2013-05-16
+
+1. License Grants; No Trademark License
+
+   Subject to the terms of this License, I grant You:
+
+   a) A non-exclusive, worldwide, perpetual, royalty-free, irrevocable
+      copyright license, to reproduce, Distribute, prepare derivative works
+      of, publicly perform and publicly display My Work.
+
+   b) A non-exclusive, worldwide, perpetual, royalty-free, irrevocable
+      patent license under Licensed Patents to make, have made, use, sell,
+      offer for sale, and import Covered Works.
+
+   This License does not grant any rights in My name, trademarks, service
+   marks, or logos.
+
+2. Distribution: General Conditions
+
+   You may Distribute Covered Works, provided that You (i) inform
+   recipients how they can obtain a copy of this License; (ii) satisfy the
+   applicable conditions of sections 3 through 6; and (iii) preserve all
+   Legal Notices contained in My Work (to the extent they remain
+   pertinent). "Legal Notices" means copyright notices, license notices,
+   license texts, and author attributions, but does not include logos,
+   other graphical images, trademarks or trademark legends.
+
+3. Conditions for Distributing Derived Works; Outbound GPL Compatibility
+
+   If You Distribute a Derived Work, You must license the entire Derived
+   Work as a whole under this License, with prominent notice of such
+   licensing. This condition may not be avoided through such means as
+   separate Distribution of portions of the Derived Work. You may
+   additionally license the Derived Work under the GPL, so that the
+   recipient may further Distribute the Derived Work under either this
+   License or the GPL.
+
+4. Condition Against Further Restrictions; Inbound License Compatibility
+
+   When Distributing a Covered Work, You may not impose further
+   restrictions on the exercise of rights in the Covered Work granted under
+   this License. This condition is not excused merely because such
+   restrictions result from Your compliance with conditions or obligations
+   extrinsic to this License (such as a court order or an agreement with a
+   third party).
+
+   However, You may Distribute a Covered Work incorporating material
+   governed by a license that is both OSI-Approved and FSF-Free as of the
+   release date of this License, provided that Your Distribution complies
+   with such other license.
+
+5. Conditions for Distributing Object Code
+
+   You may Distribute an Object Code form of a Covered Work, provided that
+   you accompany the Object Code with a URL through which the Corresponding
+   Source is made available, at no charge, by some standard or customary
+   means of providing network access to source code.
+
+   If you Distribute the Object Code in a physical product or tangible
+   storage medium ("Product"), the Corresponding Source must be available
+   through such URL for two years from the date of Your most recent
+   Distribution of the Object Code in the Product. However, if the Product
+   itself contains or is accompanied by the Corresponding Source (made
+   available in a customarily accessible manner), You need not also comply
+   with the first paragraph of this section.
+
+   Each recipient of the Covered Work from You is an intended third-party
+   beneficiary of this License solely as to this section 5, with the right
+   to enforce its terms.
+
+6. Symmetrical Licensing Condition for Upstream Contributions
+
+   If You Distribute a work to Me specifically for inclusion in or
+   modification of a Covered Work (a "Patch"), and no explicit licensing
+   terms apply to the Patch, You license the Patch under this License, to
+   the extent of Your copyright in the Patch. This condition does not
+   negate the other conditions of this License, if applicable to the Patch.
+
+7. Nullification of Copyleft/Proprietary Dual Licensing
+
+   If I offer to license, for a fee, a Covered Work under terms other than
+   a license that is OSI-Approved or FSF-Free as of the release date of this
+   License or a numbered version of copyleft-next released by the
+   Copyleft-Next Project, then the license I grant You under section 1 is no
+   longer subject to the conditions in sections 2 through 5.
+
+8. Copyleft Sunset
+
+   The conditions in sections 2 through 5 no longer apply once fifteen
+   years have elapsed from the date of My first Distribution of My Work
+   under this License.
+
+9. Pass-Through
+
+   When You Distribute a Covered Work, the recipient automatically receives
+   a license to My Work from Me, subject to the terms of this License.
+
+10. Termination
+
+    Your license grants under section 1 are automatically terminated if You
+
+    a) fail to comply with the conditions of this License, unless You cure
+       such noncompliance within thirty days after becoming aware of it, or
+
+    b) initiate a patent infringement litigation claim (excluding
+       declaratory judgment actions, counterclaims, and cross-claims)
+       alleging that any part of My Work directly or indirectly infringes
+       any patent.
+
+    Termination of Your license grants extends to all copies of Covered
+    Works You subsequently obtain. Termination does not terminate the
+    rights of those who have received copies or rights from You subject to
+    this License.
+
+    To the extent permission to make copies of a Covered Work is necessary
+    merely for running it, such permission is not terminable.
+
+11. Later License Versions
+
+    The Copyleft-Next Project may release new versions of copyleft-next,
+    designated by a distinguishing version number ("Later Versions").
+    Unless I explicitly remove the option of Distributing Covered Works
+    under Later Versions, You may Distribute Covered Works under any Later
+    Version.
+
+** 12. No Warranty                                                       **
+**                                                                       **
+**     My Work is provided "as-is", without warranty. You bear the risk  **
+**     of using it. To the extent permitted by applicable law, each      **
+**     Distributor of My Work excludes the implied warranties of title,  **
+**     merchantability, fitness for a particular purpose and             **
+**     non-infringement.                                                 **
+
+** 13. Limitation of Liability                                           **
+**                                                                       **
+**     To the extent permitted by applicable law, in no event will any   **
+**     Distributor of My Work be liable to You for any damages           **
+**     whatsoever, whether direct, indirect, special, incidental, or     **
+**     consequential damages, whether arising under contract, tort       **
+**     (including negligence), or otherwise, even where the Distributor  **
+**     knew or should have known about the possibility of such damages.  **
+
+14. Severability
+
+    The invalidity or unenforceability of any provision of this License
+    does not affect the validity or enforceability of the remainder of
+    this License. Such provision is to be reformed to the minimum extent
+    necessary to make it valid and enforceable.
+
+15. Definitions
+
+    "Copyleft-Next Project" means the project that maintains the source
+    code repository at <https://gitorious.org/copyleft-next/> as of the
+    release date of this License.
+
+    "Corresponding Source" of a Covered Work in Object Code form means (i)
+    the Source Code form of the Covered Work; (ii) all scripts,
+    instructions and similar information that are reasonably necessary for
+    a skilled developer to generate such Object Code from the Source Code
+    provided under (i); and (iii) a list clearly identifying all Separate
+    Works (other than those provided in compliance with (ii)) that were
+    specifically used in building and (if applicable) installing the
+    Covered Work (for example, a specified proprietary compiler including
+    its version number). Corresponding Source must be machine-readable.
+
+    "Covered Work" means My Work or a Derived Work.
+
+    "Derived Work" means a work of authorship that copies from, modifies,
+    adapts, is based on, is a derivative work of, transforms, translates or
+    contains all or part of My Work, such that copyright permission is
+    required. The following are not Derived Works: (i) Mere Aggregation;
+    (ii) a mere reproduction of My Work; and (iii) if My Work fails to
+    explicitly state an expectation otherwise, a work that merely makes
+    reference to My Work.
+
+    "Distribute" means to distribute, transfer or make a copy available to
+    someone else, such that copyright permission is required.
+
+    "Distributor" means Me and anyone else who Distributes a Covered Work.
+
+    "FSF-Free" means classified as 'free' by the Free Software Foundation.
+
+    "GPL" means a version of the GNU General Public License or the GNU
+    Affero General Public License.
+
+    "I"/"Me"/"My" refers to the individual or legal entity that places My
+    Work under this License. "You"/"Your" refers to the individual or legal
+    entity exercising rights in My Work under this License. A legal entity
+    includes each entity that controls, is controlled by, or is under
+    common control with such legal entity. "Control" means (a) the power to
+    direct the actions of such legal entity, whether by contract or
+    otherwise, or (b) ownership of more than fifty percent of the
+    outstanding shares or beneficial ownership of such legal entity.
+
+    "Licensed Patents" means all patent claims licensable royalty-free by
+    Me, now or in the future, that are necessarily infringed by making,
+    using, or selling My Work, and excludes claims that would be infringed
+    only as a consequence of further modification of My Work.
+
+    "Mere Aggregation" means an aggregation of a Covered Work with a
+    Separate Work.
+
+    "My Work" means the particular work of authorship I license to You
+    under this License.
+
+    "Object Code" means any form of a work that is not Source Code.
+
+    "OSI-Approved" means approved as 'Open Source' by the Open Source
+    Initiative.
+
+    "Separate Work" means a work that is separate from and independent of a
+    particular Covered Work and is not by its nature an extension or
+    enhancement of the Covered Work, and/or a runtime library, standard
+    library or similar component that is used to generate an Object Code
+    form of a Covered Work.
+
+    "Source Code" means the preferred form of a work for making
+    modifications to it.
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Mon Oct 28 12:42:02 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 17:42:02 +0100
Subject: [wireless-regdb] [PATCH v2 2/6] crda: fix -pedantic gcc compilation
In-Reply-To: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382978526-23929-3-git-send-email-mcgrof@do-not-panic.com>

gcc likes to complain about this, fix that as we're
going to get a bit more anal with code here soon as
we're moving towards making a library out of reglib.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 crda.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/crda.c b/crda.c
index 2a601eb..4751a39 100644
--- a/crda.c
+++ b/crda.c
@@ -141,13 +141,15 @@ int main(int argc, char **argv)
 {
 	int fd = -1;
 	int i = 0, j, r;
-	char alpha2[3] = {}; /* NUL-terminate */
+	char alpha2[3];
 	char *env_country;
 	struct nl80211_state nlstate;
 	struct nl_cb *cb = NULL;
 	struct nl_msg *msg;
 	int finished = 0;
 
+	memset(alpha2, 0, 3);
+
 	struct nlattr *nl_reg_rules;
 	const struct ieee80211_regdomain *rd = NULL;
 
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Mon Oct 28 12:42:03 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 17:42:03 +0100
Subject: [wireless-regdb] [PATCH v2 3/6] crda: add regulatory domain stream
	parser
In-Reply-To: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382978526-23929-4-git-send-email-mcgrof@do-not-panic.com>

This adds a stream parser for regulatory domains. This
allows developers to build regulatory domains now using
the db.txt from a stream, either stdin, or a from an
opened file.

This also adds a simple db2rd which for now only uses the
library but with a bit of effort can also be used as a
suitable replacement for the kernel's genregdb.awk.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 Makefile |  10 +-
 db2rd.c  |  32 ++++
 reglib.c | 543 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 reglib.h |  44 ++++++
 4 files changed, 627 insertions(+), 2 deletions(-)
 create mode 100644 db2rd.c

diff --git a/Makefile b/Makefile
index 7d2e33f..bd9c220 100644
--- a/Makefile
+++ b/Makefile
@@ -24,10 +24,11 @@ PUBKEY_DIR?=pubkeys
 RUNTIME_PUBKEY_DIR?=/etc/wireless-regdb/pubkeys
 
 CFLAGS += -Wall -g
+LDLIBS += -lm
 
 all: all_noverify verify
 
-all_noverify: crda intersect regdbdump
+all_noverify: crda intersect regdbdump db2rd
 
 ifeq ($(USE_OPENSSL),1)
 CFLAGS += -DUSE_OPENSSL -DPUBKEY_DIR=\"$(RUNTIME_PUBKEY_DIR)\" `pkg-config --cflags openssl`
@@ -121,6 +122,10 @@ intersect: reglib.o intersect.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
+db2rd: reglib.o db2rd.o
+	$(NQ) '  LD  ' $@
+	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
 verify: $(REG_BIN) regdbdump
 	$(NQ) '  CHK  $(REG_BIN)'
 	$(Q)./regdbdump $(REG_BIN) >/dev/null
@@ -152,5 +157,6 @@ install: crda crda.8.gz regdbdump.8.gz
 	$(Q)$(INSTALL) -m 644 -t $(DESTDIR)/$(MANDIR)/man8/ regdbdump.8.gz
 
 clean:
-	$(Q)rm -f crda regdbdump intersect *.o *~ *.pyc keys-*.c *.gz \
+	$(Q)rm -f crda regdbdump intersect db2rd \
+		*.o *~ *.pyc keys-*.c *.gz \
 	udev/$(UDEV_LEVEL)regulatory.rules udev/regulatory.rules.parsed
diff --git a/db2rd.c b/db2rd.c
new file mode 100644
index 0000000..51ec051
--- /dev/null
+++ b/db2rd.c
@@ -0,0 +1,32 @@
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <arpa/inet.h> /* ntohl */
+#include <string.h>
+
+#include "nl80211.h"
+#include "reglib.h"
+
+int main(int argc, char **argv)
+{
+	struct ieee80211_regdomain *rd = NULL;
+	FILE *fp;
+
+	if (argc != 1) {
+		fprintf(stderr, "Usage: cat db.txt | %s\n", argv[0]);
+		return -EINVAL;
+	}
+
+	fp = reglib_create_parse_stream(stdin);
+	if (!fp)
+		return -EINVAL;
+
+	reglib_for_each_country_stream(fp, rd) {
+		reglib_print_regdom(rd);
+		free(rd);
+	}
+
+	fclose(fp);
+
+	return 0;
+}
diff --git a/reglib.c b/reglib.c
index b0c61e5..6191acd 100644
--- a/reglib.c
+++ b/reglib.c
@@ -38,6 +38,19 @@
 #include "keys-gcrypt.c"
 #endif
 
+int debug = 0;
+
+struct reglib_rule_parse_list {
+	int n_parsers;
+	int (*rule_parsers[])(char *line, struct ieee80211_reg_rule *reg_rule);
+};
+
+struct reglib_country_parse_list {
+	int n_parsers;
+	int (*country_parsers[])(char *line, struct ieee80211_regdomain *rd);
+};
+
+
 void *
 reglib_get_file_ptr(uint8_t *db, size_t dblen, size_t structlen, uint32_t ptr)
 {
@@ -707,3 +720,533 @@ void reglib_print_regdom(const struct ieee80211_regdomain *rd)
 		print_reg_rule(&rd->reg_rules[i]);
 	printf("\n");
 }
+
+static unsigned int reglib_parse_dfs_region(char *dfs_region)
+{
+	if (strncmp(dfs_region, "DFS-FCC", 7) == 0)
+		return REGDB_DFS_FCC;
+	if (strncmp(dfs_region, "DFS-ETSI", 8) == 0)
+		return REGDB_DFS_ETSI;
+	if (strncmp(dfs_region, "DFS-JP", 6) == 0)
+		return REGDB_DFS_JP;
+	return REGDB_DFS_UNSET;
+}
+
+static uint32_t reglib_parse_rule_flag(char *flag_s)
+{
+	if (strncmp(flag_s, "NO-OFDM", 7) == 0)
+		return RRF_NO_OFDM;
+	if (strncmp(flag_s, "NO-CCK", 6) == 0)
+		return RRF_NO_CCK;
+	if (strncmp(flag_s, "NO-INDOOR", 9) == 0)
+		return RRF_NO_INDOOR;
+	if (strncmp(flag_s, "NO-OUTDOOR", 10) == 0)
+		return RRF_NO_OUTDOOR;
+	if (strncmp(flag_s, "DFS", 3) == 0)
+		return RRF_DFS;
+	if (strncmp(flag_s, "PTP-ONLY", 8) == 0)
+		return RRF_PTP_ONLY;
+	if (strncmp(flag_s, "PTMP-ONLY", 9) == 0)
+		return RRF_PTMP_ONLY;
+	if (strncmp(flag_s, "NO-IR", 5) == 0)
+		return RRF_NO_IR;
+
+	return 0;
+}
+
+static int
+reglib_parse_rule_simple(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+	int hits;
+	float start_freq_khz, end_freq_khz, max_bandwidth_khz, max_eirp;
+
+	hits = sscanf(line, "\t(%f - %f @ %f), (%f)\n",
+		      &start_freq_khz,
+		      &end_freq_khz,
+		      &max_bandwidth_khz,
+		      &max_eirp);
+
+	if (hits != 4)
+		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);
+
+	reg_rule->flags = 0;
+
+	if (debug)
+		printf("reglib_parse_rule_simple(): %d line: %s", hits, line);
+
+
+	return 0;
+}
+
+static int
+reglib_parse_rule_simple_mw(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+	int hits;
+	float start_freq_khz, end_freq_khz, max_bandwidth_khz, max_eirp;
+	char mw[3];
+
+	hits = sscanf(line, "\t(%f - %f @ %f), (%f %2[mW])\n",
+		      &start_freq_khz,
+		      &end_freq_khz,
+		      &max_bandwidth_khz,
+		      &max_eirp, mw);
+
+	if (hits != 4)
+		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);
+
+	reg_rule->flags = 0;
+
+	if (debug)
+		printf("reglib_parse_rule_simple_mw(): %d line: %s",
+		       hits, line);
+
+	return 0;
+}
+
+static int
+reglib_parse_rule_args(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+#define IGNORE_COMMA_OR_SPACE "%*[ ,]"
+	int hits;
+	char flag_list[9][100];
+	unsigned int i = 0;
+	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)"
+		      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,
+		      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 < 5)
+		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]);
+
+	if (debug)
+		printf("reglib_parse_rule_args(): %d flags: %d, line: %s",
+		       hits, reg_rule->flags, line);
+
+	return 0;
+#undef IGNORE_COMMA_OR_SPACE
+}
+
+
+static int
+reglib_parse_rule_args_mw(char *line, struct ieee80211_reg_rule *reg_rule)
+{
+#define IGNORE_COMMA_OR_SPACE "%*[ ,]"
+	int hits;
+	char flag_list[9][100];
+	unsigned int i = 0;
+	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])"
+		      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,
+		      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 < 5)
+		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]);
+
+	if (debug)
+		printf("reglib_parse_rule_args_mw(): %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];
+	char *line_p;
+	unsigned int i;
+	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 *));
+
+	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;
+
+	/*
+	 * 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;
+
+	memset(line, 0, sizeof(line));
+	line_p = fgets(line, sizeof(line), fp);
+	if (line_p != line)
+		return -EINVAL;
+
+	for (i = 0; i < reglib_rule_parsers->n_parsers; i++) {
+		r = reglib_rule_parsers->rule_parsers[i](line, reg_rule);
+		if (r == 0)
+			break;
+	}
+
+	return r;
+}
+
+static uint32_t
+reglib_get_n_rules(FILE *fp, struct ieee80211_reg_rule *reg_rule)
+{
+	uint32_t n_rules = 0;
+	int r;
+	bool save_debug = false;
+
+	save_debug = debug;
+	debug = false;
+
+	while (1) {
+		r = reglib_parse_rule(fp, reg_rule);
+		if (r != 0)
+			break;
+		n_rules++;
+	}
+
+	debug = save_debug;
+
+	return n_rules;
+}
+
+static int reglib_parse_reg_rule(FILE *fp, struct ieee80211_reg_rule *reg_rule)
+{
+	int r;
+
+	while (1) {
+		r = reglib_parse_rule(fp, reg_rule);
+		if (r != 0)
+			continue;
+		return 0;
+	}
+}
+
+static struct ieee80211_regdomain *
+reglib_parse_rules(FILE *fp, struct ieee80211_regdomain *trd)
+{
+	struct ieee80211_regdomain *rd;
+	struct ieee80211_reg_rule rule;
+	struct ieee80211_reg_rule *reg_rule;
+	fpos_t pos;
+	unsigned int i;
+	uint32_t size_of_regd = 0, num_rules = 0;
+	int r;
+
+	memset(&rule, 0, sizeof(rule));
+	reg_rule = &rule;
+
+	r = fgetpos(fp, &pos);
+	if (r != 0) {
+		fprintf(stderr, "fgetpos() failed: %s\n",
+			strerror(errno));
+		return NULL;
+	}
+
+	num_rules = reglib_get_n_rules(fp, reg_rule);
+	if (!num_rules)
+		return NULL;
+
+	size_of_regd = reglib_array_len(sizeof(struct ieee80211_regdomain),
+					num_rules + 1,
+					sizeof(struct ieee80211_reg_rule));
+	rd = malloc(size_of_regd);
+	if (!rd)
+		return NULL;
+
+	memset(rd, 0, size_of_regd);
+	memcpy(rd, trd, sizeof(*trd));
+
+	rd->n_reg_rules = num_rules;
+
+	r = fsetpos(fp, &pos);
+	if (r != 0) {
+		fprintf(stderr, "fsetpos() failed: %s\n",
+			strerror(errno));
+		free(rd);
+		return NULL;
+	}
+	for (i = 0; i < num_rules; i++) {
+		struct ieee80211_reg_rule *rrule = &rd->reg_rules[i];
+
+		if (reglib_parse_reg_rule(fp, rrule) != 0) {
+			fprintf(stderr, "rule parse failed\n");
+			free(rd);
+			return NULL;
+		}
+	}
+	return rd;
+}
+
+static int
+reglib_parse_country_simple(char *line, struct ieee80211_regdomain *rd)
+{
+	char dfs_region_alpha[9];
+	char alpha2[2];
+	int hits;
+
+	memset(rd, 0, sizeof(rd));
+	memset(alpha2, 0, sizeof(alpha2));
+	memset(dfs_region_alpha, 0, sizeof(dfs_region_alpha));
+
+	hits = sscanf(line, "country %2[a-zA-Z0-9]:",
+		      alpha2);
+
+	if (hits != 1)
+		return -EINVAL;
+
+	rd->alpha2[0] = alpha2[0];
+	rd->alpha2[1] = alpha2[1];
+
+	return 0;
+}
+
+static int reglib_parse_country_dfs(char *line, struct ieee80211_regdomain *rd)
+{
+	char dfs_region_alpha[9];
+	char alpha2[2];
+	int hits;
+
+	memset(rd, 0, sizeof(rd));
+	memset(alpha2, 0, sizeof(alpha2));
+	memset(dfs_region_alpha, 0, sizeof(dfs_region_alpha));
+
+	hits = sscanf(line, "country %2[a-zA-Z0-9]:%*[ ]%s\n",
+		      alpha2,
+		      dfs_region_alpha);
+	if (hits <= 0)
+		return -EINVAL;
+
+	if (hits != 2)
+		return -EINVAL;
+
+
+	rd->alpha2[0] = alpha2[0];
+	rd->alpha2[1] = alpha2[1];
+	rd->dfs_region = reglib_parse_dfs_region(dfs_region_alpha);
+
+	return 0;
+}
+
+struct ieee80211_regdomain *__reglib_parse_country(FILE *fp)
+{
+	struct ieee80211_regdomain *rd;
+	struct ieee80211_regdomain tmp_rd;
+	char line[1024];
+	char *line_p;
+	unsigned int i;
+	int r = 0;
+	struct reglib_country_parse_list *reglib_country_parsers;
+	size_t size_of_parsers = sizeof(struct reglib_country_parse_list) +
+					2 * sizeof(int (*)(char *, struct ieee80211_regdomain *));
+
+	reglib_country_parsers = malloc(size_of_parsers);
+	if (!reglib_country_parsers)
+		return NULL;
+	memset(reglib_country_parsers, 0, size_of_parsers);
+
+	reglib_country_parsers->n_parsers = 2;
+	reglib_country_parsers->country_parsers[0] =
+			reglib_parse_country_dfs;
+	reglib_country_parsers->country_parsers[1] =
+			reglib_parse_country_simple;
+
+	memset(&tmp_rd, 0, sizeof(tmp_rd));
+	memset(line, 0, sizeof(line));
+
+	line_p = fgets(line, sizeof(line), fp);
+
+	if (line_p != line)
+		return NULL;
+
+	for (i = 0; i < reglib_country_parsers->n_parsers; i++) {
+		r = reglib_country_parsers->country_parsers[i](line, &tmp_rd);
+		if (r == 0)
+			break;
+	}
+
+	if (r != 0) {
+		fprintf(stderr, "Invalid country line: %s", line);
+		return NULL;
+	}
+
+	rd = reglib_parse_rules(fp, &tmp_rd);
+
+	return rd;
+}
+
+static int reglib_find_next_country_stream(FILE *fp)
+{
+	fpos_t prev_pos;
+	int r;
+	unsigned int i = 0;
+
+	while(1) {
+		char line[1024];
+		char *line_p;
+
+		r = fgetpos(fp, &prev_pos);
+		if (r != 0) {
+			fprintf(stderr, "fgetpos() failed: %s\n",
+				strerror(errno));
+			return r;
+		}
+
+		memset(line, 0, sizeof(line));
+
+		line_p = fgets(line, sizeof(line), fp);
+		if (line_p == line) {
+			if (strspn(line, "\n") == strlen(line)) {
+				i++;
+				continue;
+			}
+			if (strncmp(line, "country", 7) != 0)
+				continue;
+			r = fsetpos(fp, &prev_pos);
+			if (r != 0) {
+				fprintf(stderr, "fsetpos() failed: %s\n",
+					strerror(errno));
+				return r;
+			}
+			return 0;
+		} else
+			return EOF;
+	}
+}
+
+struct ieee80211_regdomain *reglib_parse_country(FILE *fp)
+{
+	int r;
+
+	r = reglib_find_next_country_stream(fp);
+	if (r != 0)
+		return NULL;
+	return __reglib_parse_country(fp);
+}
+
+FILE *reglib_create_parse_stream(FILE *f)
+{
+	unsigned int lines = 0;
+	FILE *fp;
+
+	fp = tmpfile();
+	if (errno) {
+		fprintf(stderr, "%s\n", strerror(errno));
+		return NULL;
+	}
+
+	while(1) {
+		char line[1024];
+		char *line_p;
+
+		line_p = fgets(line, sizeof(line), f);
+		if (line_p == line) {
+			if (strchr(line, '#') == NULL) {
+				fputs(line, fp);
+				lines++;
+			}
+			continue;
+		} else
+			break;
+	}
+
+	rewind(fp);
+	fflush(fp);
+
+	return fp;
+}
diff --git a/reglib.h b/reglib.h
index 7a586a3..885792e 100644
--- a/reglib.h
+++ b/reglib.h
@@ -1,10 +1,12 @@
 #ifndef REG_LIB_H
 #define REG_LIB_H
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <sys/stat.h>
+#include <math.h>
 
 #include "regdb.h"
 
@@ -35,6 +37,19 @@ struct ieee80211_regdomain {
 	struct ieee80211_reg_rule reg_rules[];
 };
 
+/* Remove this once upstream nl80211.h gets this */
+#define NL80211_RRF_NO_IR (1<<7)
+
+#define REGLIB_MHZ_TO_KHZ(freq) ((freq) * 1000)
+#define REGLIB_KHZ_TO_MHZ(freq) ((freq) / 1000)
+#define REGLIB_DBI_TO_MBI(gain) ((gain) * 100)
+#define REGLIB_MBI_TO_DBI(gain) ((gain) / 100)
+#define REGLIB_DBM_TO_MBM(gain) ((gain) * 100)
+#define REGLIB_MBM_TO_DBM(gain) ((gain) / 100)
+
+#define REGLIB_MW_TO_DBM(gain) (10 * log10(gain))
+#define REGLIB_MW_TO_MBM(gain) (REGLIB_DBM_TO_MBM(REGLIB_MW_TO_DBM(gain)))
+
 /**
  * struct reglib_regdb_ctx - reglib regdb context
  *
@@ -180,4 +195,33 @@ reglib_intersect_rds(const struct ieee80211_regdomain *rd1,
 const struct ieee80211_regdomain *
 reglib_intersect_regdb(const struct reglib_regdb_ctx *ctx);
 
+/**
+ * @reglib_create_parse_stream - provide a clean new stream for processing
+ *
+ * @fp: FILE stream, could be stdin, or a stream from an open file.
+ *
+ * In order to parse a stream we recommend to create a new stream
+ * using this helper. A new stream is preferred in order to work
+ * with stdin, as otherwise we cannot rewind() and move around
+ * the stream. This helper will create new stream using tmpfile()
+ * and also remove all comments. It will be closed and the file
+ * deleted when the process terminates.
+ */
+FILE *reglib_create_parse_stream(FILE *fp);
+
+/**
+ * @reglib_parse_country - parse stream to build a regulatory domain
+ *
+ * @fp: FILE stream, could be stdin, or a stream from an open file.
+ *
+ * Parse stream and return back a built regulatory domain. Returns
+ * NULL if one could not be built.
+ */
+struct ieee80211_regdomain *reglib_parse_country(FILE *fp);
+
+#define reglib_for_each_country_stream(__fp, __rd)		\
+	for (__rd = reglib_parse_country(__fp);			\
+	     __rd != NULL;					\
+	     __rd = reglib_parse_country(__fp))			\
+
 #endif
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Mon Oct 28 12:42:06 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 17:42:06 +0100
Subject: [wireless-regdb] [PATCH v2 6/6] crda: make reglib a shared library
In-Reply-To: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382978526-23929-7-git-send-email-mcgrof@do-not-panic.com>

Now that we have quite a few helpers this puts the more
valuable helpers into a library.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 Makefile | 48 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index 9e37ccd..4a351c6 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,8 @@ REG_GIT?=git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-regdb.g
 
 PREFIX ?= /usr/
 MANDIR ?= $(PREFIX)/share/man/
+INCLUDE_DIR ?= $(PREFIX)/include/reglib/
+LIBDIR ?= $(PREFIX)/lib
 
 SBINDIR ?= /sbin/
 
@@ -23,24 +25,29 @@ UDEV_RULE_DIR?=/lib/udev/rules.d/
 PUBKEY_DIR?=pubkeys
 RUNTIME_PUBKEY_DIR?=/etc/wireless-regdb/pubkeys
 
+CFLAGS += -O2 -fpic
+CFLAGS += -std=gnu99 -Wall -Werror -pedantic
 CFLAGS += -Wall -g
 LDLIBS += -lm
+LDLIBREG += -lreg
+LIBREG += libreg.so
+LDFLAGS += -L ./ $(LDLIBREG)
 
 all: all_noverify verify
 
-all_noverify: crda intersect regdbdump db2rd optimize
+all_noverify: $(LIBREG) crda intersect regdbdump db2rd optimize
 
 ifeq ($(USE_OPENSSL),1)
 CFLAGS += -DUSE_OPENSSL -DPUBKEY_DIR=\"$(RUNTIME_PUBKEY_DIR)\" `pkg-config --cflags openssl`
 LDLIBS += `pkg-config --libs openssl`
 
-reglib.o: keys-ssl.c
+$(LIBREG): keys-ssl.c
 
 else
 CFLAGS += -DUSE_GCRYPT
 LDLIBS += -lgcrypt
 
-reglib.o: keys-gcrypt.c
+$(LIBREG): keys-gcrypt.c
 
 endif
 MKDIR ?= mkdir -p
@@ -106,39 +113,56 @@ keys-%.c: utils/key2pub.py $(wildcard $(PUBKEY_DIR)/*.pem)
 	$(NQ) '  Trusted pubkeys:' $(wildcard $(PUBKEY_DIR)/*.pem)
 	$(Q)./utils/key2pub.py --$* $(wildcard $(PUBKEY_DIR)/*.pem) $@
 
-%.o: %.c regdb.h reglib.h
+$(LIBREG): regdb.h reglib.h reglib.c
+	$(NQ) '  CC  ' $@
+	$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -shared -Wl,-soname,$(LIBREG) $^
+
+install-libreg-headers:
+	$(NQ) '  INSTALL  libreg-headers'
+	$(Q)mkdir -p $(INCLUDE_DIR)
+	$(Q)cp *.h $(INCLUDE_DIR)/
+
+install-libreg:
+	$(NQ) '  INSTALL  libreg'
+	$(Q)mkdir -p $(LIBDIR)
+	$(Q)cp $(LIBREG) $(LIBDIR)/
+	$(Q)ldconfig
+
+%.o: %.c regdb.h $(LIBREG)
 	$(NQ) '  CC  ' $@
 	$(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
 
-crda: reglib.o crda.o
+crda: crda.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(NLLIBS)
 
-regdbdump: reglib.o regdbdump.o
+regdbdump: regdbdump.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-intersect: reglib.o intersect.o
+intersect: intersect.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-db2rd: reglib.o db2rd.o
+db2rd: db2rd.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-optimize: reglib.o optimize.o
+optimize: optimize.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
 verify: $(REG_BIN) regdbdump
 	$(NQ) '  CHK  $(REG_BIN)'
-	$(Q)./regdbdump $(REG_BIN) >/dev/null
+	$(Q)\
+		LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) \
+		./regdbdump $(REG_BIN) >/dev/null
 
 %.gz: %
 	@$(NQ) ' GZIP' $<
 	$(Q)gzip < $< > $@
 
-install: crda crda.8.gz regdbdump.8.gz
+install: install-libreg install-libreg-headers crda crda.8.gz regdbdump.8.gz
 	$(NQ) '  INSTALL  crda'
 	$(Q)$(MKDIR) $(DESTDIR)/$(SBINDIR)
 	$(Q)$(INSTALL) -m 755 -t $(DESTDIR)/$(SBINDIR) crda
@@ -161,6 +185,6 @@ install: crda crda.8.gz regdbdump.8.gz
 	$(Q)$(INSTALL) -m 644 -t $(DESTDIR)/$(MANDIR)/man8/ regdbdump.8.gz
 
 clean:
-	$(Q)rm -f crda regdbdump intersect db2rd optimize \
+	$(Q)rm -f $(LIBREG) crda regdbdump intersect db2rd optimize \
 		*.o *~ *.pyc keys-*.c *.gz \
 	udev/$(UDEV_LEVEL)regulatory.rules udev/regulatory.rules.parsed
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Mon Oct 28 12:42:04 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 17:42:04 +0100
Subject: [wireless-regdb] [PATCH v2 4/6] crda: add regulatory domain
	optimizer
In-Reply-To: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382978526-23929-5-git-send-email-mcgrof@do-not-panic.com>

This adds a regulatory domain optimizer which can be
used with information of a regulatory domain in db.txt
format in stdin. It makes use of the new shiny regulatory
domain stream parser.

The way this works is it iterates over the regulatory domain
computing unions between each frequency, starting from each
frequency as a pivot. If a union leads to a valid regulatory
rule we verify that the pivot and othre frequency rules that
provided that valid union can fit into that union regulatory
rule by computing an intersection. If an intersection is
possible it means two rules can be optimized out. We do
this repetitively.

Note: cfg80211's nl80211.h API has:

      #define NL80211_MAX_SUPP_REG_RULES              32

Our tools, both the stream parser and the optimizer are not
limited to these artificial limits ! We can work on extending
the kernel's limit but so far we have had no needs. A few
notes below though on the existing reasoning for the limit
and possible future enhancements.

This is used nl80211_set_reg() upon intercept of a regulatory
domain being sent from userspace to it. We picked a limitation
to at least have a stopping gap to avoid userpace flooding the
kernel with a denial of service requests on memory from userspace.
This means that userspace can only request at most a kmalloc
of up to 32 regulatory rules for processing for the regulatory
data that we are copying from userspace. There's a Linux kernel
enhancement that will be made soon so that we invalidate bogus
requests, by checking to see if the incomming regulatory domain
alpha2 was not expected upon a regulatory hint initiator (even
if userspace first tells the kernel it is waiting for a response
from kernel space), and if its invalid then we drop the userspace
supplied request, therefore avoiding some form of flooding on
memory to the kernel.

Note that we can still get flooding if the userspace API is used
to *request* to the kernel for a regulatory domain to be sent
from userspace, in that case the kernel will properly expect the
regulatory data for the alpha2. To prevent flooding there perhaps
its a good idea for us to check whether a userspace pending request
is pendingg and if so deny new updates until the last one triggers
a timeout.

Screenshot for a US file with 40 rules:

mcgrof at frijol ~/devel/xlreg (git::master)$ cat us | grep --"(" | wc -l
40

mcgrof at frijol ~/devel/crda (git::master)$ cat us
country US: DFS-FCC
        (2402.000 - 2422.000 @ 20.000), (30.00)
        (2407.000 - 2427.000 @ 20.000), (30.00)
        (2412.000 - 2432.000 @ 20.000), (30.00)
        (2417.000 - 2437.000 @ 20.000), (30.00)
        (2422.000 - 2442.000 @ 20.000), (30.00)
        (2427.000 - 2447.000 @ 20.000), (30.00)
        (2432.000 - 2452.000 @ 20.000), (30.00)
        (2437.000 - 2457.000 @ 20.000), (30.00)
        (2442.000 - 2462.000 @ 20.000), (30.00)
        (2447.000 - 2467.000 @ 20.000), (30.00)
        (2452.000 - 2472.000 @ 20.000), (30.00)
        (2402.000 - 2442.000 @ 40.000), (30.00)
        (2407.000 - 2447.000 @ 40.000), (30.00)
        (2412.000 - 2452.000 @ 40.000), (30.00)
        (2417.000 - 2457.000 @ 40.000), (30.00)
        (2422.000 - 2462.000 @ 40.000), (30.00)
        (2427.000 - 2467.000 @ 40.000), (30.00)
        (2432.000 - 2472.000 @ 40.000), (30.00)
        (5170.000 - 5190.000 @ 20.000), (17.00)
        (5190.000 - 5210.000 @ 20.000), (17.00)
        (5210.000 - 5230.000 @ 20.000), (17.00)
        (5230.000 - 5250.000 @ 20.000), (17.00)
        (5250.000 - 5270.000 @ 20.000), (23.00), DFS
        (5270.000 - 5290.000 @ 20.000), (23.00), DFS
        (5290.000 - 5310.000 @ 20.000), (23.00), DFS
        (5310.000 - 5330.000 @ 20.000), (23.00), DFS
        (5735.000 - 5755.000 @ 20.000), (30.00)
        (5755.000 - 5775.000 @ 20.000), (30.00)
        (5775.000 - 5795.000 @ 20.000), (30.00)
        (5795.000 - 5815.000 @ 20.000), (30.00)
        (5815.000 - 5835.000 @ 20.000), (30.00)
        (5170.000 - 5210.000 @ 40.000), (17.00)
        (5210.000 - 5250.000 @ 40.000), (17.00)
        (5250.000 - 5290.000 @ 40.000), (23.00), DFS
        (5290.000 - 5330.000 @ 40.000), (23.00), DFS
        (5735.000 - 5775.000 @ 40.000), (30.00)
        (5775.000 - 5815.000 @ 40.000), (30.00)
        (5170.000 - 5250.000 @ 80.000), (17.00)
        (5250.000 - 5330.000 @ 80.000), (23.00), DFS
        (5735.000 - 5815.000 @ 80.000), (30.00)

mcgrof at frijol ~/devel/crda (git::master)$ cat us | ./optimize
country US: DFS-FCC
        (2402.000 - 2472.000 @ 40.000), (30.00)
        (5170.000 - 5250.000 @ 80.000), (17.00)
        (5250.000 - 5330.000 @ 80.000), (23.00), DFS
        (5735.000 - 5835.000 @ 80.000), (30.00)

I've also tested this with the current db.txt from wireless-regdb
and get real optimiziations which I will post later.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 Makefile   |   8 +-
 optimize.c |  40 +++++++++
 reglib.c   | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 reglib.h   |  16 ++++
 4 files changed, 360 insertions(+), 4 deletions(-)
 create mode 100644 optimize.c

diff --git a/Makefile b/Makefile
index bd9c220..9e37ccd 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ LDLIBS += -lm
 
 all: all_noverify verify
 
-all_noverify: crda intersect regdbdump db2rd
+all_noverify: crda intersect regdbdump db2rd optimize
 
 ifeq ($(USE_OPENSSL),1)
 CFLAGS += -DUSE_OPENSSL -DPUBKEY_DIR=\"$(RUNTIME_PUBKEY_DIR)\" `pkg-config --cflags openssl`
@@ -126,6 +126,10 @@ db2rd: reglib.o db2rd.o
 	$(NQ) '  LD  ' $@
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
+optimize: reglib.o optimize.o
+	$(NQ) '  LD  ' $@
+	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
 verify: $(REG_BIN) regdbdump
 	$(NQ) '  CHK  $(REG_BIN)'
 	$(Q)./regdbdump $(REG_BIN) >/dev/null
@@ -157,6 +161,6 @@ install: crda crda.8.gz regdbdump.8.gz
 	$(Q)$(INSTALL) -m 644 -t $(DESTDIR)/$(MANDIR)/man8/ regdbdump.8.gz
 
 clean:
-	$(Q)rm -f crda regdbdump intersect db2rd \
+	$(Q)rm -f crda regdbdump intersect db2rd optimize \
 		*.o *~ *.pyc keys-*.c *.gz \
 	udev/$(UDEV_LEVEL)regulatory.rules udev/regulatory.rules.parsed
diff --git a/optimize.c b/optimize.c
new file mode 100644
index 0000000..89d714b
--- /dev/null
+++ b/optimize.c
@@ -0,0 +1,40 @@
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <arpa/inet.h> /* ntohl */
+#include <string.h>
+
+#include "nl80211.h"
+#include "reglib.h"
+
+int main(int argc, char **argv)
+{
+	struct ieee80211_regdomain *rd = NULL, *rd_opt = NULL;
+	FILE *fp;
+
+	if (argc != 1) {
+		fprintf(stderr, "Usage: cat db.txt | %s\n", argv[0]);
+		return -EINVAL;
+	}
+
+	fp = reglib_create_parse_stream(stdin);
+	if (!fp)
+		return -EINVAL;
+
+	reglib_for_each_country_stream(fp, rd) {
+		rd_opt = reglib_optimize_regdom(rd);
+		if (!rd_opt){
+			fprintf(stderr, "Unable to optimize %c%c\n",
+				rd->alpha2[0],
+				rd->alpha2[1]);
+			free(rd);
+			continue;
+		}
+		reglib_print_regdom(rd_opt);
+		free(rd);
+		free(rd_opt);
+	}
+
+	fclose(fp);
+	return 0;
+}
diff --git a/reglib.c b/reglib.c
index 6191acd..9577ada 100644
--- a/reglib.c
+++ b/reglib.c
@@ -459,6 +459,49 @@ int reglib_is_valid_rd(const struct ieee80211_regdomain *rd)
 	return 1;
 }
 
+static int reg_rules_union(const struct ieee80211_reg_rule *rule1,
+			   const struct ieee80211_reg_rule *rule2,
+			   struct ieee80211_reg_rule *union_rule)
+{
+	const struct ieee80211_freq_range *freq_range1, *freq_range2;
+	struct ieee80211_freq_range *freq_range;
+	const struct ieee80211_power_rule *power_rule1, *power_rule2;
+	struct ieee80211_power_rule *power_rule;
+
+	freq_range1 = &rule1->freq_range;
+	freq_range2 = &rule2->freq_range;
+	freq_range = &union_rule->freq_range;
+
+	power_rule1 = &rule1->power_rule;
+	power_rule2 = &rule2->power_rule;
+	power_rule = &union_rule->power_rule;
+
+
+	if (freq_range1->end_freq_khz < freq_range2->start_freq_khz)
+		return -EINVAL;
+	if (freq_range2->end_freq_khz < freq_range1->start_freq_khz)
+		return -EINVAL;
+
+	freq_range->start_freq_khz = reglib_min(freq_range1->start_freq_khz,
+					 freq_range2->start_freq_khz);
+	freq_range->end_freq_khz = reglib_max(freq_range1->end_freq_khz,
+				       freq_range2->end_freq_khz);
+	freq_range->max_bandwidth_khz = reglib_max(freq_range1->max_bandwidth_khz,
+					    freq_range2->max_bandwidth_khz);
+
+	power_rule->max_eirp = reglib_max(power_rule1->max_eirp,
+		power_rule2->max_eirp);
+	power_rule->max_antenna_gain = reglib_max(power_rule1->max_antenna_gain,
+		power_rule2->max_antenna_gain);
+
+	union_rule->flags = rule1->flags | rule2->flags;
+
+	if (!is_valid_reg_rule(union_rule))
+		return -EINVAL;
+
+	return 0;
+}
+
 /*
  * Helper for reglib_intersect_rds(), this does the real
  * mathematical intersection fun
@@ -971,8 +1014,10 @@ static int reglib_parse_rule(FILE *fp, struct ieee80211_reg_rule *reg_rule)
 
 	memset(line, 0, sizeof(line));
 	line_p = fgets(line, sizeof(line), fp);
-	if (line_p != line)
+	if (line_p != line) {
+		free(reglib_rule_parsers);
 		return -EINVAL;
+	}
 
 	for (i = 0; i < reglib_rule_parsers->n_parsers; i++) {
 		r = reglib_rule_parsers->rule_parsers[i](line, reg_rule);
@@ -980,6 +1025,8 @@ static int reglib_parse_rule(FILE *fp, struct ieee80211_reg_rule *reg_rule)
 			break;
 	}
 
+	free(reglib_rule_parsers);
+
 	return r;
 }
 
@@ -1151,8 +1198,10 @@ struct ieee80211_regdomain *__reglib_parse_country(FILE *fp)
 
 	line_p = fgets(line, sizeof(line), fp);
 
-	if (line_p != line)
+	if (line_p != line) {
+		free(reglib_country_parsers);
 		return NULL;
+	}
 
 	for (i = 0; i < reglib_country_parsers->n_parsers; i++) {
 		r = reglib_country_parsers->country_parsers[i](line, &tmp_rd);
@@ -1162,11 +1211,14 @@ struct ieee80211_regdomain *__reglib_parse_country(FILE *fp)
 
 	if (r != 0) {
 		fprintf(stderr, "Invalid country line: %s", line);
+		free(reglib_country_parsers);
 		return NULL;
 	}
 
 	rd = reglib_parse_rules(fp, &tmp_rd);
 
+	free(reglib_country_parsers);
+
 	return rd;
 }
 
@@ -1250,3 +1302,247 @@ FILE *reglib_create_parse_stream(FILE *f)
 
 	return fp;
 }
+
+/*
+ * Just whatever for now, nothing formal, but note that as bands
+ * grow we'll want to make this a bit more formal somehow.
+ */
+static uint32_t reglib_deduce_band(uint32_t start_freq_khz)
+{
+	uint32_t freq_mhz = REGLIB_KHZ_TO_MHZ(start_freq_khz);
+
+	if (freq_mhz >= 4000)
+		return 5;
+	if (freq_mhz > 2000 && freq_mhz < 4000)
+		return 2;
+	if (freq_mhz > 50000)
+		return 60;
+	return 1234;
+}
+
+/*
+ * The idea behind a rule key is that if two rule keys share the
+ * same key they can be merged together if their frequencies overlap.
+ */
+static uint64_t reglib_rule_key(struct ieee80211_reg_rule *reg_rule)
+{
+	struct ieee80211_power_rule *power_rule;
+	struct ieee80211_freq_range *freq_range;
+	uint32_t band;
+	uint32_t key;
+
+	freq_range = &reg_rule->freq_range;
+	band = reglib_deduce_band(freq_range->start_freq_khz);
+
+	power_rule = &reg_rule->power_rule;
+
+	key = ((power_rule->max_eirp ^  0) <<  0) ^
+	      ((reg_rule->flags      ^  8) <<  8) ^
+	      ((band                 ^ 16) << 16);
+
+	return key;
+}
+
+struct reglib_optimize_map {
+	bool optimized;
+	uint32_t key;
+};
+
+/* Does the provided rule suffice both of the other two */
+static int reglib_opt_rule_fit(struct ieee80211_reg_rule *rule1,
+			       struct ieee80211_reg_rule *rule2,
+			       struct ieee80211_reg_rule *opt_rule)
+{
+	struct ieee80211_reg_rule interesected_rule;
+	struct ieee80211_reg_rule *int_rule;
+	int r;
+
+	memset(&interesected_rule, 0, sizeof(struct ieee80211_reg_rule));
+	int_rule = &interesected_rule;
+
+	r = reg_rules_intersect(rule1, opt_rule, int_rule);
+	if (r != 0)
+		return r;
+	r = reg_rules_intersect(rule2, opt_rule, int_rule);
+	if (r != 0)
+		return r;
+
+	return 0;
+}
+
+static int reg_rule_optimize(struct ieee80211_reg_rule *rule1,
+			     struct ieee80211_reg_rule *rule2,
+			     struct ieee80211_reg_rule *opt_rule)
+{
+	int r;
+
+	r = reg_rules_union(rule1, rule2, opt_rule);
+	if (r != 0)
+		return r;
+	r = reglib_opt_rule_fit(rule1, rule2, opt_rule);
+	if (r != 0)
+		return r;
+
+	return 0;
+}
+
+/*
+ * Here's the math explanation:
+ *
+ * This takes each pivot frequency on the regulatory domain, computes
+ * the union between it each regulatory rule on the regulatory domain
+ * sequentially, and after that it tries to verify that the pivot frequency
+ * fits on it by computing an intersection between it and the union, if
+ * a rule exist as a possible intersection then we know the rule can be
+ * subset of the combination of the two frequency ranges (union) computed.
+ */
+static unsigned int reg_rule_optimize_rd(struct ieee80211_regdomain *rd,
+					 unsigned int rule_idx,
+					 struct ieee80211_reg_rule *opt_rule,
+					 struct reglib_optimize_map *opt_map)
+{
+	unsigned int i;
+	struct ieee80211_reg_rule *rule1;
+	struct ieee80211_reg_rule *rule2;
+
+	struct ieee80211_reg_rule tmp_optimized_rule;
+	struct ieee80211_reg_rule *tmp_opt_rule;
+
+	struct ieee80211_reg_rule *target_rule;
+
+	unsigned int optimized = 0;
+	int r;
+
+	if (rule_idx > rd->n_reg_rules)
+		return 0;
+
+	rule1 = &rd->reg_rules[rule_idx];
+
+	memset(&tmp_optimized_rule, 0, sizeof(struct ieee80211_reg_rule));
+	tmp_opt_rule = &tmp_optimized_rule;
+
+	memset(opt_rule, 0, sizeof(*opt_rule));
+
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		if (rule_idx == i)
+			continue;
+		rule2 = &rd->reg_rules[i];
+		if (opt_map[rule_idx].key != opt_map[i].key)
+			continue;
+
+		target_rule = optimized ? opt_rule : rule1;
+		r = reg_rule_optimize(target_rule, rule2, tmp_opt_rule);
+		if (r != 0)
+			continue;
+		memcpy(opt_rule, tmp_opt_rule, sizeof(*tmp_opt_rule));
+
+		if (!opt_map[i].optimized) {
+			opt_map[i].optimized = true;
+			optimized++;
+		}
+		if (!opt_map[rule_idx].optimized) {
+			opt_map[rule_idx].optimized = true;
+			optimized++;
+		}
+	}
+	return optimized;
+}
+
+struct ieee80211_regdomain *
+reglib_optimize_regdom(struct ieee80211_regdomain *rd)
+{
+	struct ieee80211_regdomain *opt_rd = NULL;
+	struct ieee80211_reg_rule *reg_rule;
+	struct ieee80211_reg_rule *reg_rule_dst;
+	struct ieee80211_reg_rule optimized_reg_rule;
+	struct ieee80211_reg_rule *opt_reg_rule;
+	struct reglib_optimize_map *opt_map;
+	unsigned int i, idx = 0, non_opt = 0, opt = 0;
+	size_t num_rules, size_of_regd, size_of_opt_map;
+	unsigned int num_opts = 0;
+
+	size_of_opt_map = (rd->n_reg_rules + 2) *
+		sizeof(struct reglib_optimize_map);
+	opt_map = malloc(size_of_opt_map);
+	if (!opt_map)
+		return NULL;
+
+	memset(opt_map, 0, size_of_opt_map);
+	memset(&optimized_reg_rule, 0, sizeof(struct ieee80211_reg_rule));
+
+	opt_reg_rule = &optimized_reg_rule;
+
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		reg_rule = &rd->reg_rules[i];
+		opt_map[i].key = reglib_rule_key(reg_rule);
+	}
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		reg_rule = &rd->reg_rules[i];
+		if (opt_map[i].optimized)
+			continue;
+		num_opts = reg_rule_optimize_rd(rd, i, opt_reg_rule, opt_map);
+		if (!num_opts)
+			non_opt++;
+		else
+			opt += (num_opts ? 1 : 0);
+	}
+
+	num_rules = non_opt + opt;
+
+	if (num_rules > rd->n_reg_rules)
+		goto fail_opt_map;
+
+	size_of_regd = reglib_array_len(sizeof(struct ieee80211_regdomain),
+					num_rules + 1,
+					sizeof(struct ieee80211_reg_rule));
+
+	opt_rd = malloc(size_of_regd);
+	if (!opt_rd)
+		goto fail_opt_map;
+	memset(opt_rd, 0, size_of_regd);
+
+	opt_rd->n_reg_rules = num_rules;
+	opt_rd->alpha2[0] = rd->alpha2[0];
+	opt_rd->alpha2[1] = rd->alpha2[1];
+	opt_rd->dfs_region = rd->dfs_region;
+
+	memset(opt_map, 0, size_of_opt_map);
+	memset(&optimized_reg_rule, 0, sizeof(struct ieee80211_reg_rule));
+
+	opt_reg_rule = &optimized_reg_rule;
+
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		reg_rule = &rd->reg_rules[i];
+		opt_map[i].key = reglib_rule_key(reg_rule);
+	}
+
+	for (i = 0; i < rd->n_reg_rules; i++) {
+		reg_rule = &rd->reg_rules[i];
+		reg_rule_dst = &opt_rd->reg_rules[idx];
+		if (opt_map[i].optimized)
+			continue;
+		num_opts = reg_rule_optimize_rd(rd, i, opt_reg_rule, opt_map);
+		if (!num_opts)
+			memcpy(reg_rule_dst, reg_rule, sizeof(struct ieee80211_reg_rule));
+		else
+			memcpy(reg_rule_dst, opt_reg_rule, sizeof(struct ieee80211_reg_rule));
+		idx++;
+	}
+
+	if (idx != num_rules)
+		goto fail;
+
+	for (i = 0; i < opt_rd->n_reg_rules; i++) {
+		reg_rule = &opt_rd->reg_rules[i];
+		if (!is_valid_reg_rule(reg_rule))
+			goto fail;
+	}
+
+	free(opt_map);
+	return opt_rd;
+fail:
+	free(opt_rd);
+fail_opt_map:
+	free(opt_map);
+	return NULL;
+}
diff --git a/reglib.h b/reglib.h
index 885792e..d570c36 100644
--- a/reglib.h
+++ b/reglib.h
@@ -219,6 +219,22 @@ FILE *reglib_create_parse_stream(FILE *fp);
  */
 struct ieee80211_regdomain *reglib_parse_country(FILE *fp);
 
+/**
+ * @reglib_optimize_regdom - optimize a regulatory domain
+ *
+ * @rd: a regulatory domain to be optimized
+ *
+ * A regulatory domain may exist without optimal expressions
+ * over its rules. This will look for regulatory rules that can
+ * be combined together to reduce the size of the regulatory
+ * domain and its expression.
+ *
+ * Regulatory rules will be combined if their max allowed
+ * bandwidth, max EIRP, and flags all match.
+ */
+struct ieee80211_regdomain *
+reglib_optimize_regdom(struct ieee80211_regdomain *rd);
+
 #define reglib_for_each_country_stream(__fp, __rd)		\
 	for (__rd = reglib_parse_country(__fp);			\
 	     __rd != NULL;					\
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Mon Oct 28 12:42:05 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Mon, 28 Oct 2013 17:42:05 +0100
Subject: [wireless-regdb] [PATCH v2 5/6] crda: make ssl keys include stdint.h
In-Reply-To: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
References: <1382978526-23929-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1382978526-23929-6-git-send-email-mcgrof@do-not-panic.com>

This is required to fix compilation if we
move reglig to its own library.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 utils/key2pub.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/utils/key2pub.py b/utils/key2pub.py
index 4d85369..3e84cd2 100755
--- a/utils/key2pub.py
+++ b/utils/key2pub.py
@@ -59,6 +59,7 @@ def print_ssl_32(output, name, val):
 
 def print_ssl(output, name, val):
     import struct
+    output.write('#include <stdint.h>\n')
     if len(struct.pack('@L', 0)) == 8:
         return print_ssl_64(output, name, val)
     else:
@@ -85,6 +86,7 @@ static struct pubkey keys[] = {
     pass
 
 def print_gcrypt(output, name, val):
+    output.write('#include <stdint.h>\n')
     while val[0] == '\0':
         val = val[1:]
     output.write('static const uint8_t %s[%d] = {\n' % (name, len(val)))
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:45:04 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:45:04 +0100
Subject: [wireless-regdb] [PATCH 2/7] wireless-regdb: add DFS ETSI regions
In-Reply-To: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
References: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1383169509-22619-3-git-send-email-mcgrof@do-not-panic.com>

This associates the following countries to the
DFS ETSI region:

	AL, AM, AN, AW, AZ, BY, EG, GE, HT,
	IL, KH, KW, MA, OM, RS, RU, SA, TN,
	UA, ZA, ZW

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 db.txt | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/db.txt b/db.txt
index 94da96a..1c20be2 100644
--- a/db.txt
+++ b/db.txt
@@ -25,15 +25,15 @@ country AE: DFS-FCC
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country AL:
+country AL: DFS-ETSI
 	(2402 - 2482 @ 20), (20)
 
-country AM:
+country AM: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 20), (18)
 	(5250 - 5330 @ 20), (18), DFS
 
-country AN:
+country AN: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (20)
 	(5250 - 5330 @ 40), (20), DFS
@@ -61,13 +61,13 @@ country AU:
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country AW:
+country AW: DFS-ETSI/
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (20)
 	(5250 - 5330 @ 40), (20), DFS
 	(5490 - 5710 @ 40), (27), DFS
 
-country AZ:
+country AZ: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (18)
 	(5250 - 5330 @ 40), (18), DFS
@@ -133,7 +133,7 @@ country BR: DFS-FCC
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country BY:
+country BY: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (20)
 	(5250 - 5330 @ 40), (20), DFS
@@ -263,7 +263,7 @@ country EE: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country EG:
+country EG: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 20), (20)
 	(5250 - 5330 @ 20), (20), DFS
@@ -292,7 +292,7 @@ country FR: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country GE:
+country GE: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (18)
 	(5250 - 5330 @ 40), (18), DFS
@@ -363,7 +363,7 @@ country HR: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country HT:
+country HT: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (20)
 	(5250 - 5330 @ 40), (20), DFS
@@ -390,7 +390,7 @@ country IE: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country IL:
+country IL: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5150 - 5250 @ 80), (200 mW), NO-OUTDOOR
 	(5250 - 5350 @ 80), (200 mW), NO-OUTDOOR
@@ -445,7 +445,7 @@ country KE:
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
-country KH:
+country KH: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (20)
 	(5250 - 5330 @ 40), (20), DFS
@@ -519,7 +519,7 @@ country MC: DFS-ETSI
 	(5170 - 5250 @ 40), (18)
 	(5250 - 5330 @ 40), (18), DFS
 
-country MA:
+country MA: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (23)
 	(5735 - 5835 @ 80), (23)
@@ -586,7 +586,7 @@ country NZ: DFS-FCC
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country OM:
+country OM: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (20), DFS
@@ -661,14 +661,14 @@ country RO: DFS-ETSI
 
 # Source:
 # http://www.ratel.rs/upload/documents/Plan_namene/Plan_namene-sl_glasnik.pdf
-country RS:
+country RS: DFS-ETSI
 	(2400 - 2483.5 @ 40), (100 mW)
 	(5150 - 5350 @ 40), (200 mW), NO-OUTDOOR
 	(5470 - 5725 @ 20), (1000 mW), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country RU:
+country RU: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5330 @ 40), (20)
 	(5650 - 5710 @ 40), (30)
@@ -678,7 +678,7 @@ country RW: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
-country SA:
+country SA: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -745,7 +745,7 @@ country TT: DFS-FCC
 	(5490 - 5710 @ 40), (20), DFS
 	(5735 - 5835 @ 40), (30)
 
-country TN:
+country TN: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 20), (20)
 	(5250 - 5330 @ 20), (20), DFS
@@ -765,7 +765,7 @@ country TR: DFS-ETSI
 # Listed 5GHz range is a lowest common denominator for all related
 # rules in the referenced laws. Such a range is used because of
 # disputable definitions there.
-country UA:
+country UA: DFS-ETSI
 	(2400 - 2483.5 @ 40), (20), NO-OUTDOOR
 	(5150 - 5350 @ 40), (20), NO-OUTDOOR
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
@@ -811,13 +811,13 @@ country VN: DFS-FCC
 country YE:
 	(2402 - 2482 @ 40), (20)
 
-country ZA:
+country ZA: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country ZW:
+country ZW: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
 
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:45:03 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:45:03 +0100
Subject: [wireless-regdb] [PATCH 1/7] wireless-regdb: add DFS FCC regions
In-Reply-To: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
References: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1383169509-22619-2-git-send-email-mcgrof@do-not-panic.com>

This associates the following countries to the
DFS FCC region:

	AE, AR, BB, BR, CA, CN, CO, CR, DO, EC,
	GD, GT, GU, HN, JM, LB, LK, MY, MX, NZ,
	PA, PE, PG, PH, PR, RW, SG, SV, TH, TT,
	UY, UZ, VE, VN

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 db.txt | 68 +++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/db.txt b/db.txt
index c938767..94da96a 100644
--- a/db.txt
+++ b/db.txt
@@ -18,7 +18,7 @@ country AD:
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country AE:
+country AE: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -39,7 +39,7 @@ country AN:
 	(5250 - 5330 @ 40), (20), DFS
 	(5490 - 5710 @ 40), (27), DFS
 
-country AR:
+country AR: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -80,7 +80,7 @@ country BA: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country BB:
+country BB: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (23)
 	(5250 - 5330 @ 40), (23), DFS
@@ -126,7 +126,7 @@ country BO:
 	(2402 - 2482 @ 40), (30)
 	(5735 - 5835 @ 40), (30)
 
-country BR:
+country BR: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -143,7 +143,7 @@ country BZ:
 	(2402 - 2482 @ 40), (30)
 	(5735 - 5835 @ 40), (30)
 
-country CA:
+country CA: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -164,7 +164,7 @@ country CL:
 	(5250 - 5330 @ 40), (20), DFS
 	(5735 - 5835 @ 40), (20)
 
-country CN:
+country CN: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 80), (30)
 	# 60 gHz band channels 1,4: 28dBm, channels 2,3: 44dBm
@@ -173,14 +173,14 @@ country CN:
 	(59400 - 63720 @ 2160), (44)
 	(63720 - 65880 @ 2160), (28)
 
-country CO:
+country CO: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country CR:
+country CR: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -239,7 +239,7 @@ country DK: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country DO:
+country DO: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (23), DFS
@@ -248,7 +248,7 @@ country DO:
 country DZ:
 	(2402 - 2482 @ 40), (20)
 
-country EC:
+country EC: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -307,7 +307,7 @@ country GB: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country GD:
+country GD: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (20), DFS
@@ -328,20 +328,20 @@ country GL: DFS-ETSI
 	(5250 - 5330 @ 20), (20), DFS
 	(5490 - 5710 @ 20), (27), DFS
 
-country GT:
+country GT: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (23), DFS
 	(5735 - 5835 @ 40), (30)
 
-country GU:
+country GU: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country HN:
+country HN: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (20), DFS
@@ -421,7 +421,7 @@ country IT: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country JM:
+country JM: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (20), DFS
@@ -473,7 +473,7 @@ country KW:
 country KZ:
 	(2402 - 2482 @ 40), (20)
 
-country LB:
+country LB: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
@@ -483,7 +483,7 @@ country LI: DFS-ETSI
 	(5250 - 5330 @ 40), (20), DFS
 	(5490 - 5710 @ 40), (27), DFS
 
-country LK:
+country LK: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 20), (17)
 	(5250 - 5330 @ 20), (20), DFS
@@ -546,13 +546,13 @@ country MT: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country MY:
+country MY: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (23), DFS
 	(5735 - 5835 @ 80), (30)
 
-country MX:
+country MX: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -579,7 +579,7 @@ country NP:
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
-country NZ:
+country NZ: DFS-FCC
 	(2402 - 2482 @ 40), (30)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -593,26 +593,26 @@ country OM:
 	(5490 - 5710 @ 40), (20), DFS
 	(5735 - 5835 @ 40), (30)
 
-country PA:
+country PA: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (23), DFS
 	(5735 - 5835 @ 40), (30)
 
-country PE:
+country PE: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country PG:
+country PG: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (23), DFS
 	(5735 - 5835 @ 40), (30)
 
-country PH:
+country PH: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -639,7 +639,7 @@ country PT: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country PR:
+country PR: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -674,7 +674,7 @@ country RU:
 	(5650 - 5710 @ 40), (30)
 	(5735 - 5835 @ 40), (30)
 
-country RW:
+country RW: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
@@ -693,7 +693,7 @@ country SE: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country SG:
+country SG: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
@@ -716,7 +716,7 @@ country SK: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country SV:
+country SV: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 20), (17)
 	(5250 - 5330 @ 20), (23), DFS
@@ -731,14 +731,14 @@ country TW:
 	(5490 - 5710 @ 80), (30), DFS
 	(5735 - 5815 @ 80), (30)
 
-country TH:
+country TH: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country TT:
+country TT: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (20), DFS
@@ -783,25 +783,25 @@ country US: DFS-FCC
 	# channels 1,2,3, EIRP=40dBm(43dBm peak)
 	(57240 - 63720 @ 2160), (40)
 
-country UY:
+country UY: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (20), DFS
 	(5490 - 5710 @ 40), (20), DFS
 	(5735 - 5835 @ 40), (30)
 
-country UZ:
+country UZ: DFS-FCC
 	(2402 - 2472 @ 40), (27)
 	(5170 - 5250 @ 40), (17)
 	(5250 - 5330 @ 40), (20), DFS
 	(5490 - 5710 @ 40), (20), DFS
 	(5735 - 5835 @ 40), (30)
 
-country VE:
+country VE: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5815 @ 40), (23)
 
-country VN:
+country VN: DFS-FCC
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 80), (17)
 	(5250 - 5330 @ 80), (24), DFS
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:45:02 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:45:02 +0100
Subject: [wireless-regdb] [PATCH 0/7] wireless-regdb: DFS regions and
	optimizations
Message-ID: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>

This patch series associates a slew of countries
to DFS regions and then provides updates to 4
countries based on the new CRDA optimizer. The
optimizations have no functional changes other
than reducing the size of the regulatory domain
data strucutre that would be used to send to
the kernel.

Luis R. Rodriguez (7):
  wireless-regdb: add DFS FCC regions
  wireless-regdb: add DFS ETSI regions
  wireless-regdb: add DFS JP regions
  wireless-regdb: optimize two of DE's rules
  wireless-regdb: optimize two of ES's rules
  wireless-regdb: optimize two of IL's rules
  wireless-regdb: optimize two of NL's rules

 db.txt | 159 +++++++++++++++++++++++++++++++----------------------------------
 1 file changed, 77 insertions(+), 82 deletions(-)

-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:45:05 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:45:05 +0100
Subject: [wireless-regdb] [PATCH 3/7] wireless-regdb: add DFS JP regions
In-Reply-To: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
References: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1383169509-22619-4-git-send-email-mcgrof@do-not-panic.com>

This associates the following countries to the
DFS JP region:

	BD, BH, BN, BO, BZ, CL, DZ, ID, IN, IR
	JP, JO, KE, KP, KR, NP, PK, QA, TW

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 db.txt | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/db.txt b/db.txt
index 1c20be2..5ca9704 100644
--- a/db.txt
+++ b/db.txt
@@ -86,7 +86,7 @@ country BB: DFS-FCC
 	(5250 - 5330 @ 40), (23), DFS
 	(5735 - 5835 @ 40), (30)
 
-country BD:
+country BD: DFS-JP
 	(2402 - 2482 @ 40), (20)
 
 country BE: DFS-ETSI
@@ -105,7 +105,7 @@ country BG: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country BH:
+country BH: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 20), (20)
 	(5250 - 5330 @ 20), (20), DFS
@@ -116,13 +116,13 @@ country BL:
 	(5170 - 5250 @ 40), (18)
 	(5250 - 5330 @ 40), (18), DFS
 
-country BN:
+country BN: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (20)
 	(5250 - 5330 @ 40), (20), DFS
 	(5735 - 5835 @ 40), (30)
 
-country BO:
+country BO: DFS-JP
 	(2402 - 2482 @ 40), (30)
 	(5735 - 5835 @ 40), (30)
 
@@ -139,7 +139,7 @@ country BY: DFS-ETSI
 	(5250 - 5330 @ 40), (20), DFS
 	(5490 - 5710 @ 40), (27), DFS
 
-country BZ:
+country BZ: DFS-JP
 	(2402 - 2482 @ 40), (30)
 	(5735 - 5835 @ 40), (30)
 
@@ -158,7 +158,7 @@ country CH: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country CL:
+country CL: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (20)
 	(5250 - 5330 @ 40), (20), DFS
@@ -245,7 +245,7 @@ country DO: DFS-FCC
 	(5250 - 5330 @ 40), (23), DFS
 	(5735 - 5835 @ 40), (30)
 
-country DZ:
+country DZ: DFS-JP
 	(2402 - 2482 @ 40), (20)
 
 country EC: DFS-FCC
@@ -377,7 +377,7 @@ country HU: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country ID:
+country ID: DFS-JP
 	# ref: http://www.postel.go.id/content/ID/regulasi/standardisasi/kepdir/bwa%205,8%20ghz.pdf
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5815 @ 80), (20)
@@ -395,7 +395,7 @@ country IL: DFS-ETSI
 	(5150 - 5250 @ 80), (200 mW), NO-OUTDOOR
 	(5250 - 5350 @ 80), (200 mW), NO-OUTDOOR
 
-country IN:
+country IN: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (20)
 	(5250 - 5330 @ 40), (20), DFS
@@ -409,7 +409,7 @@ country IS: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country IR:
+country IR: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
@@ -428,7 +428,7 @@ country JM: DFS-FCC
 	(5490 - 5710 @ 40), (20), DFS
 	(5735 - 5835 @ 40), (30)
 
-country JP:
+country JP: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(2474 - 2494 @ 20), (20), NO-OFDM
 	(4910 - 4990 @ 40), (23)
@@ -437,11 +437,11 @@ country JP:
 	(5250 - 5330 @ 80), (20), DFS
 	(5490 - 5710 @ 160), (23), DFS
 
-country JO:
+country JO: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5250 @ 40), (18)
 
-country KE:
+country KE: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
@@ -451,7 +451,7 @@ country KH: DFS-ETSI
 	(5250 - 5330 @ 40), (20), DFS
 	(5490 - 5710 @ 40), (27), DFS
 
-country KP:
+country KP: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5170 - 5330 @ 40), (20)
 	(5160 - 5250 @ 40), (20), DFS
@@ -575,7 +575,7 @@ country NO: DFS-ETSI
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
 
-country NP:
+country NP: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
@@ -619,7 +619,7 @@ country PH: DFS-FCC
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country PK:
+country PK: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
@@ -646,7 +646,7 @@ country PR: DFS-FCC
 	(5490 - 5710 @ 80), (24), DFS
 	(5735 - 5835 @ 80), (30)
 
-country QA:
+country QA: DFS-JP
 	(2402 - 2482 @ 40), (20)
 	(5735 - 5835 @ 40), (30)
 
@@ -725,7 +725,7 @@ country SV: DFS-FCC
 country SY:
 	(2402 - 2482 @ 40), (20)
 
-country TW:
+country TW: DFS-JP
 	(2402 - 2472 @ 40), (27)
 	(5270 - 5330 @ 40), (17), DFS
 	(5490 - 5710 @ 80), (30), DFS
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:45:06 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:45:06 +0100
Subject: [wireless-regdb] [PATCH 4/7] wireless-regdb: optimize two of DE's
	rules
In-Reply-To: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
References: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1383169509-22619-5-git-send-email-mcgrof@do-not-panic.com>

There's no reason not to merge these two rules.
This as picked up by the new CRDA optimizer.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 db.txt | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/db.txt b/db.txt
index 5ca9704..da8fcfe 100644
--- a/db.txt
+++ b/db.txt
@@ -222,10 +222,8 @@ country CZ: DFS-ETSI
 country DE: DFS-ETSI
 	# entries 279004 and 280006
 	(2400 - 2483.5 @ 40), (100 mW)
-	# entry 303005
-	(5150 - 5250 @ 80), (100 mW), NO-OUTDOOR
-	# entries 304002 and 305002
-	(5250 - 5350 @ 80), (100 mW), NO-OUTDOOR
+	# entry 303005, 304002 and 305002
+	(5150 - 5350 @ 80), (100 mW), NO-OUTDOOR
 	# entries 308002, 309001 and 310003
 	(5470 - 5725 @ 80), (500 mW), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:45:07 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:45:07 +0100
Subject: [wireless-regdb] [PATCH 5/7] wireless-regdb: optimize two of ES's
	rules
In-Reply-To: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
References: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1383169509-22619-6-git-send-email-mcgrof@do-not-panic.com>

There's no reason not to merge these two rules.
This as picked up by the new CRDA optimizer.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 db.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/db.txt b/db.txt
index da8fcfe..7532166 100644
--- a/db.txt
+++ b/db.txt
@@ -268,8 +268,7 @@ country EG: DFS-ETSI
 
 country ES: DFS-ETSI
 	(2400 - 2483.5 @ 40), (100 mW)
-	(5150 - 5250 @ 80), (100 mW), NO-OUTDOOR
-	(5250 - 5350 @ 80), (100 mW), NO-OUTDOOR
+	(5150 - 5350 @ 80), (100 mW), NO-OUTDOOR 
 	(5470 - 5725 @ 80), (500 mW), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:45:08 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:45:08 +0100
Subject: [wireless-regdb] [PATCH 6/7] wireless-regdb: optimize two of IL's
	rules
In-Reply-To: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
References: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1383169509-22619-7-git-send-email-mcgrof@do-not-panic.com>

There's no reason not to merge these two rules.
This as picked up by the new CRDA optimizer.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 db.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/db.txt b/db.txt
index 7532166..efd9902 100644
--- a/db.txt
+++ b/db.txt
@@ -389,8 +389,7 @@ country IE: DFS-ETSI
 
 country IL: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
-	(5150 - 5250 @ 80), (200 mW), NO-OUTDOOR
-	(5250 - 5350 @ 80), (200 mW), NO-OUTDOOR
+	(5150 - 5350 @ 80), (200 mW), NO-OUTDOOR
 
 country IN: DFS-JP
 	(2402 - 2482 @ 40), (20)
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:45:09 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:45:09 +0100
Subject: [wireless-regdb] [PATCH 7/7] wireless-regdb: optimize two of NL's
	rules
In-Reply-To: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
References: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <1383169509-22619-8-git-send-email-mcgrof@do-not-panic.com>

There's no reason not to merge these two rules.
This as picked up by the new CRDA optimizer.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 db.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/db.txt b/db.txt
index efd9902..429a380 100644
--- a/db.txt
+++ b/db.txt
@@ -557,8 +557,7 @@ country MX: DFS-FCC
 
 country NL: DFS-ETSI
 	(2402 - 2482 @ 40), (20)
-	(5170 - 5250 @ 80), (20), NO-OUTDOOR
-	(5250 - 5330 @ 80), (20), NO-OUTDOOR
+	(5170 - 5330 @ 80), (20), NO-OUTDOOR
 	(5490 - 5710 @ 80), (27), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
 	(57240 - 65880 @ 2160), (40), NO-OUTDOOR
-- 
1.8.4.rc3



From mcgrof at do-not-panic.com  Wed Oct 30 17:46:23 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Wed, 30 Oct 2013 22:46:23 +0100
Subject: [wireless-regdb] [PATCH 0/7] wireless-regdb: DFS regions and
	optimizations
In-Reply-To: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
References: <1383169509-22619-1-git-send-email-mcgrof@do-not-panic.com>
Message-ID: <CAB=NE6W7xpp_zr7a_Dtkbiqe9fo5=Si_GjkAr1wypSPgng64rw@mail.gmail.com>

On Wed, Oct 30, 2013 at 10:45 PM, Luis R. Rodriguez
<mcgrof at do-not-panic.com> wrote:
> This patch series associates a slew of countries
> to DFS regions and then provides updates to 4
> countries based on the new CRDA optimizer. The
> optimizations have no functional changes other
> than reducing the size of the regulatory domain
> data strucutre that would be used to send to
> the kernel.

I should note that this depends on the removal of antenna gain patch.

  Luis


From xose.vazquez at gmail.com  Thu Oct 31 11:07:39 2013
From: xose.vazquez at gmail.com (Xose Vazquez Perez)
Date: Thu, 31 Oct 2013 16:07:39 +0100
Subject: [wireless-regdb] [PATCH 5/7] wireless-regdb: optimize two of
	ES's rules
Message-ID: <5272723B.4090006@gmail.com>

hi Luis,

This patch is incompatible with my ("pending")patch:
http://lists.infradead.org/pipermail/wireless-regdb/2013-February/000136.html

thanks,

---cortamorena---
Subject: [PATCH] wireless-regdb: change Max_EIRP in 5150-5250 for ES (Spain)

I did cut&paste from DE rules, but DE lowers the limit
in 5150-5250 to 100mW for "neighborhood reasons" [1].
Even when 200mW is completely legal in DE.

put 200mW, as Spanish law says:

Banda 5150 ? 5350 MHz: En esta banda el uso por el servicio m?vil en sistemas de
acceso inal?mbrico incluyendo comunicaciones electr?nicas y redes de ?rea local, se
restringe para su utilizaci?n ?nicamente en el interior de recintos. La potencia isotr?pica
radiada equivalente m?xima ser? de 200 mW (p.i.r.e.), siendo la densidad m?xima de
p.i.r.e. media de 10 mW/MHz en cualquier banda de 1 MHz. Este valor se refiere a la
potencia promediada sobre una r?faga de transmisi?n ajustada a la m?xima potencia

Orden ITC/332/2010, de 12 de febrero, por la que se aprueba el cuadro
nacional de atribuci?n de frecuencias (CNAF):
https://www.boe.es/diario_boe/txt.php?id=BOE-A-2010-2719
https://www.boe.es/boe/dias/2010/02/19/pdfs/BOE-A-2010-2719.pdf

search for:
 UN - 85 RLANs y datos en 2400 a 2483,5 MHz (pag. 213)
 UN - 128 RLANs en 5 GHz (pag. 232)

more info at "Cuadro nacional de atribuci?n de frecuencias (CNAF)":
http://www.minetur.gob.es/telecomunicaciones/espectro/paginas/cnaf.aspx

[1] http://marc.info/?l=linux-wireless&m=127429049514439

Cc: John W. Linville <linville at tuxdriver.com>
Cc: Luis R. Rodriguez <mcgrof at frijolero.org>
Cc: wireless-regdb at lists.infradead.org
Cc: linux-wireless at vger.kernel.org
Signed-off-by: Xose Vazquez Perez <xose.vazquez at gmail.com>
---
 db.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/db.txt b/db.txt
index c5861b8..6f618c0 100644
--- a/db.txt
+++ b/db.txt
@@ -269,7 +269,7 @@ country EG:
  country ES: DFS-ETSI
 	(2400 - 2483.5 @ 40), (N/A, 100 mW)
-	(5150 - 5250 @ 40), (N/A, 100 mW), NO-OUTDOOR
+	(5150 - 5250 @ 40), (N/A, 200 mW), NO-OUTDOOR
 	(5250 - 5350 @ 40), (N/A, 100 mW), NO-OUTDOOR, DFS
 	(5470 - 5725 @ 40), (N/A, 500 mW), DFS
 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
-- 
1.7.11.7
---end---



From xose.vazquez at gmail.com  Thu Oct 31 14:33:35 2013
From: xose.vazquez at gmail.com (Xose Vazquez Perez)
Date: Thu, 31 Oct 2013 19:33:35 +0100
Subject: [wireless-regdb] French regulatory domain change request
Message-ID: <5272A27F.9060009@gmail.com>

hi Jean-Pierre,

> The current description for France in regdb.txt is :
> country FR: DFS-ETSI
> 	(2402 - 2482 @ 40), (N/A, 20)
> 	(5170 - 5250 @ 80), (N/A, 20)
> 	(5250 - 5330 @ 80), (N/A, 20), DFS
> 	(5490 - 5710 @ 80), (N/A, 27), DFS
> 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
> 	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
> 
> Following this paper http://www.arcep.fr/uploads/tx_gsavis/08-0568.pdf 
> " D?cision n? 2008-0568" issued by the ARCEP (French Electronic
> communications and Postoffice Regulation Authority) in the year 2008,
> 1) the frequencies 5150-5350 MHz are limited to INDOOR use.
>  (see page 5: "Dans la bande de fr?quences*5150-5350* MHz, les WAS/RLAN sont
> limit?s ? une *utilisation int?rieure* ...")
> 2) the limits of the frequency band is ~20MHz greater for all frequency
> values (5150 vs. 5170, 5350 vs. 5330, 5470 vs. 5490, 5725 vs. 5710)

> So IMHO the description for France should read: 
> country FR: DFS-ETSI
> 	(2402 - 2482 @ 40), (N/A, 20)
> 	# ref: ARCEP 08-0568
> http://www.arcep.fr/uploads/tx_gsavis/08-0568.pdf
> 	(5150 - 5250 @ 80), (N/A, 20), NO-OUTDOOR
> 	(5250 - 5350 @ 80), (N/A, 20), NO-OUTDOOR, DFS
> 	(5470 - 5725 @ 80), (N/A, 27), DFS
> 	# 60 gHz band channels 1-4, ref: Etsi En 302 567
> 	(57240 - 65880 @ 2160), (N/A, 40), NO-OUTDOOR
> By the way, this looks very like the description for Germany (DE)

You are right, but a patch is missing ;-)

BTW. It should be fixed for all, or nearly all, ETSI countries.


From mcgrof at do-not-panic.com  Thu Oct 31 16:00:32 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Thu, 31 Oct 2013 21:00:32 +0100
Subject: [wireless-regdb] [PATCH 5/7] wireless-regdb: optimize two of
	ES's rules
In-Reply-To: <5272723B.4090006@gmail.com>
References: <5272723B.4090006@gmail.com>
Message-ID: <CAB=NE6X7LJnCBVQ5bXiXs-F8MgNoRDGzzdubkVAVmoyd3EaQZw@mail.gmail.com>

2013/10/31 Xose Vazquez Perez <xose.vazquez at gmail.com>:
> hi Luis,
>
> This patch is incompatible with my ("pending")patch:
> http://lists.infradead.org/pipermail/wireless-regdb/2013-February/000136.html
>
> thanks,

I'd like Michael to review this one, in the meantime I'll drop this
one from my patch set. I have a new set of patches I'll post soon.

 Luis


From xose.vazquez at gmail.com  Thu Oct 31 16:21:11 2013
From: xose.vazquez at gmail.com (Xose Vazquez Perez)
Date: Thu, 31 Oct 2013 21:21:11 +0100
Subject: [wireless-regdb] [PATCH 5/7] wireless-regdb: optimize two of
	ES's rules
In-Reply-To: <CAB=NE6X7LJnCBVQ5bXiXs-F8MgNoRDGzzdubkVAVmoyd3EaQZw@mail.gmail.com>
References: <5272723B.4090006@gmail.com>
 <CAB=NE6X7LJnCBVQ5bXiXs-F8MgNoRDGzzdubkVAVmoyd3EaQZw@mail.gmail.com>
Message-ID: <5272BBB7.30304@gmail.com>

On 10/31/2013 09:00 PM, Luis R. Rodriguez wrote:

> 2013/10/31 Xose Vazquez Perez <xose.vazquez at gmail.com>:

>> This patch is incompatible with my ("pending")patch:
>> http://lists.infradead.org/pipermail/wireless-regdb/2013-February/000136.html

> I'd like Michael to review this one, in the meantime I'll drop this
> one from my patch set. I have a new set of patches I'll post soon.

Time ago I sent the CEPT/ECC regulation:
http://lists.infradead.org/pipermail/wireless-regdb/2012-June/000058.html

===recortamorena===
* ECC/DEC/(04)08 Harmonised use of 5 GHz for the implementation
  of WAS/RLANs: http://www.erodocdb.dk/Docs/doc98/official/pdf/ECCDEC0408.PDF

---cut---
[...]
DECIDES

1. that this Decision designates the frequency bands 5.150-5.350 MHz
and 5.470?5.725 MHz for the implementation of Wireless Access
Systems including Radio Local Area Networks (WAS/RLANs) and the
use of equipment complying with the harmonised standard EN 301 893,
which may also be demonstrated by compliance with equivalent
technical specifications (in the sense of Article 3(2) of the
R&TTE Directive);

2. that in the frequency band 5.150-5.350 MHz, WAS/RLANs stations
shall be restricted to indoor use with a maximum mean e.i.r.p.1 of
200 mW and a maximum mean e.i.r.p. density of 10 mW/MHz in any 1MHz
band;

3. that in the frequency band 5.470-5.725 MHz, the indoor and
outdoor use of WAS/RLANs stations shall be restricted to a maximum
mean e.i.r.p.1 of 1 W and a maximum mean e.i.r.p. density of 50mW/MHz
in any 1 MHz band;

4. that, WAS/RLANs operating in the bands 5.250-5.350 MHz and
5.470-5.725 MHz shall either employ transmitter power control, which
provides, on average, a mitigation factor of at least 3 dB on the
maximum permitted output power of the systems; or, if transmitter
power control is not in use, then the maximum permitted mean
e.i.r.p.1 and the corresponding mean e.i.r.p. density limits in
decides 2 and 3 shall be reduced by 3 dB;

5. that, WAS/RLANs operating in the bands 5.250-5.350 MHz and
5.470-5.725 MHz shall use dynamic frequency selection (DFS) as
described in Recommendation ITU-R M. 1652 to ensure compatible
operation with radiodetermination systems;

6. that, in addition to decides 5, the DFS mechanism shall ensure
that the probability of selecting a given channel will be the same
for all available channels. The intention is to provide, on
average, a near-uniform spread of the loading of the spectrum;

7. that this Decision replaces the previous ERC Decision (99)23;

8. that this Decision shall enter into force on 30 October 2009;

9. that CEPT administrations shall communicate the national
measures implementing this Decision to the ECC chairman and the
Office when the Decision is nationally implemented."
[...]
---end---



* Implementation by country:

http://www.erodocdb.dk/doks/implement_doc_adm.aspx?docid=2033
http://www.erodocdb.dk/doks/mapsi_implement.aspx?docid=2033


- Yes ... 38

- Yes Partly ... 2
Russian Federation
Georgia

- Under study ... 1
Albania

- No info ... 7
Andorra
Vatican City
Monaco
Moldova
San Marino
Azerbaijan
Belarus


All CEPT countries, except those listed above, and for 5GHz
bands, should be clones of the current DE configuration:

(5150 - 5250 @ 40), (N/A, 100 mW), NO-OUTDOOR
(5250 - 5350 @ 40), (N/A, 100 mW), NO-OUTDOOR, DFS
(5470 - 5725 @ 40), (N/A, 500 mW), DFS

-thanks-
===end===


I did cut&paste from DE to ES, but DE lowers the limit
in 5150-5250 to 100mW for "neighborhood reasons" [1].
Even when 200mW is completely legal in DE.

[1] http://marc.info/?l=linux-wireless&m=127429049514439


From mcgrof at do-not-panic.com  Fri Oct  4 10:39:01 2013
From: mcgrof at do-not-panic.com (Luis R. Rodriguez)
Date: Fri, 04 Oct 2013 17:39:01 -0000
Subject: [wireless-regdb] [PATCH 3/3] [RFC] cfg80211: Enable GO
	operation on additional channels
In-Reply-To: <CAB=NE6Vcqrs-US-HJzxcnFhjF0-dsnvPdcWoUpuo-UDV_5cReQ@mail.gmail.com>
References: <1372768095-26053-1-git-send-email-ilan.peer@intel.com>
 <1372768095-26053-4-git-send-email-ilan.peer@intel.com>
 <CAB=NE6VQXQPRK9_Q-Nh+ripRa+PdCd=4_EZvPxeghBjc32ejyQ@mail.gmail.com>
 <CB3B3D4774441E42AA3EA0E1BA8230A01AD2DFC5@HASMSX106.ger.corp.intel.com>
 <CAB=NE6WY43BYDehH5-MyF0GQORC1dTrNToUsRVC-Q5bDwcna3A@mail.gmail.com>
 <CB3B3D4774441E42AA3EA0E1BA8230A01AD31E3C@HASMSX106.ger.corp.intel.com>
 <CAB=NE6Vcqrs-US-HJzxcnFhjF0-dsnvPdcWoUpuo-UDV_5cReQ@mail.gmail.com>
Message-ID: <CAB=NE6WmEQg68BViF9v+2D__p8Gc_5bCFUkBMfTz0A96C1jyDw@mail.gmail.com>

On Thu, Jul 18, 2013 at 4:34 PM, Luis R. Rodriguez
<mcgrof at do-not-panic.com> wrote:
> On Wed, Jul 17, 2013 at 12:15 PM, Peer, Ilan <ilan.peer at intel.com> wrote:
>>> It was unclear for what exact channels you needed to deal with here.
>>> Given review so far wouldn't it just be DFS flagged channels on some UNII
>>> bands ? Then again if the indoor flag needs to be pegged to to a specific UNII
>>> band and we can do that on wireless-regdb do we even need the UNII band
>>> check routine helper?
>>>
>>
>> Generally it is possible that the indoor property is not pegged to the 'other_channel', or it is possible that it is pegged but they are not in the same UNII band, so the verification is still needed. I guess that once I get the list you requested things will be clearer :)
>
> OK so there are exceptions to the indoor flag affecting GO under these
> rules or not. Looking forward to the respin.

Anxiously looking forward to the respin :D

  Luis


