crda: make reg_rules_intersect() style match Linux

This makes reg_rules_intersect() style match exactly
as it is upstream as of next-20130522.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: port over Linux is_valid_reg_rule() change bd05f28e

This was added upstream:

mcgrof@frijol ~/linux-stable (git::master)$ git describe --contains bd05f28e
v2.6.29~3^2~47

commit bd05f28e1a15ae62994fe309a524695fe26dd834
Author: Roel Kluin <roel.kluin@gmail.com>
Date:   Tue Mar 3 22:55:21 2009 +0100

    cfg80211: test before subtraction on unsigned

    freq_diff is unsigned, so test before subtraction

    Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    Signed-off-by: John W. Linville <linville@tuxdriver.com>

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: remove verbose errors out of regdom_intersect()

We want to move this to reglib so nuke all that fluff.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: constify usage of struct ieee80211_regdomain

Where we can use const.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: remove unused BUG_ON() from intersect.c

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: move regdom_intersect() to reglib

This will be used later by other code so just share it.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: fix regression when using reglib_for_each_country()

When reglib_for_each_country() was introduced via ebcbfcf4
its users were not updated with the possibility of rd being
NULL due to the fact that the parsed file could be invalid
or empty. The users

mcgrof@frijol ~/devel/crda (git::master)$ git describe --contains 7a09f4dd
v1.1.3~8

mcgrof@frijol ~/devel/crda (git::master)$ git describe --contains ebcbfcf45
v1.1.3~9

This regression exists since v1.1. Fix this.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: move intersection if first attempt failed

The intersection should be able to continue on even if
the first two countries could not be intersected.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: do not double count on reglib_for_each_country()

Commit ebcbfcf4 introduced reglib_for_each_country() used
by regdbump and later intersect. This helper however only
increased the index count after we requestd getting a new
regulatory domain, this is incorrect and causes us to iterate
over the same element twice in the beginning. This means
intersection and regdb printing was going over the first
element twice. This has been present since v1.1.

This also requires an adjustment on intersect due to the
way things were being handled before.

mcgrof@frijol ~/devel/crda (git::master)$ git describe --contains ebcbfcf4
v1.1.3~9

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: annotate intersection worst case scenerio

In the worst case scenerio of regulatory domain intersections
between a different set of regulatory rules you will end up
without being able to initiate radiation on any frequency
range. Provide a hint as to what needs to be done next in
order to actually build a useful regulatory domain. Currently
we do this manually but building the mathematics would be
even more useful as we grow usage of the spectrum.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: fix intersect.c memory management

We didn't free memory in some cases, fix this and
to help with the complexity also simplify the case
where any regdom_intersect() fails by completely
failing. In such cases we need an alternative strategy
to build "world regulatory" domains.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: explicitly munmap() on reglib_get_rd_alpha2()

Although the region mapped by mmap() is also automatically
unmapped when the process is terminated lets just munmap()
it ourselves to be more tidy.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: explicitly close file descriptor and munmap() on failures

Just do this explicitly.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: separate crda_verify_db_signature() implementations

This will allow us to handle the error codes more cleanly
and in a readible manner. This change should have no
functional change.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: use gcry_sexp_release() on crda_verify_db_signature()

This fixes 6 of 10 reported valgrind errors when
crda_verify_db_signature() is used through regdbdump.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: explicitly use close() and munmap() on reglib_get_rd_alpha2()

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: use gcry_mpi_release() when using gcry_mpi_scan()

Its not well documented you should do this but I found out
through valgrind. This fixes the last 4 valgrind issues
I was seeing with regdbdump.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: rename world and prev_world on intersect.c

The assumption was that intersect.c was creating a world
regulatory domain for by doing an intersection of all
regulatory domains. This is technically still true however
it does not add passive scan flag'd frequency ranges and
as such to be precise lets just rename the "world" and
"prev_world" variables as intersection variables.

This change introduces no functional changes.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: remove verbosity out of intersect.c

No need for such much verbosity, additionally,
we'll move this eventually to reglib.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
crda: rename regdom_intersect() to reglib_intersect_rds()

This fits more in line with the reglib prefix usage.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>