From: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>
To: wireless-regdb@lists.infradead.org
Cc: linux-wireless@vger.kernel.org,
"Luis R. Rodriguez" <mcgrof@do-not-panic.com>
Subject: [PATCH 40/40] crda: make reglib_for_each_country() use the reglib context
Date: Thu, 30 May 2013 19:09:29 -0700 [thread overview]
Message-ID: <1369966169-23640-41-git-send-email-mcgrof@do-not-panic.com> (raw)
In-Reply-To: <1369966169-23640-1-git-send-email-mcgrof@do-not-panic.com>
From: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>
This allows users of reglib to iterate over the regdb
with just one open() and mmap() to be kept sharing as
much code as possible. This makes the regdbdump and
intersection code use the context therefore sharing
all that boiler plate code.
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
---
intersect.c | 15 +++++++++++++--
regdbdump.c | 28 ++++++++++++++--------------
reglib.c | 23 +++++++++--------------
reglib.h | 11 ++++++-----
4 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/intersect.c b/intersect.c
index 56d0d35..ae9ca1b 100644
--- a/intersect.c
+++ b/intersect.c
@@ -8,21 +8,32 @@
int main(int argc, char **argv)
{
+ const struct reglib_regdb_ctx *ctx;
const struct ieee80211_regdomain *rd;
if (argc != 2) {
- fprintf(stderr, "You must specify a file\n");
+ fprintf(stderr, "Usage: %s <regulatory-binary-file>\n", argv[0]);
return -EINVAL;
}
- rd = reglib_intersect_regdb(argv[1]);
+ ctx = reglib_malloc_regdb_ctx(argv[1]);
+ if (!ctx) {
+ fprintf(stderr, "Invalid or empty regulatory file, note: "
+ "a binary regulatory file should be used.\n");
+ return -EINVAL;
+ }
+
+ rd = reglib_intersect_regdb(ctx);
if (!rd) {
fprintf(stderr, "Intersection not possible\n");
+ reglib_free_regdb_ctx(ctx);
return -ENOENT;
}
reglib_print_regdom(rd);
+
free((struct ieee80211_regdomain *) rd);
+ reglib_free_regdb_ctx(ctx);
return 0;
}
diff --git a/regdbdump.c b/regdbdump.c
index edf3e7c..cc7eb85 100644
--- a/regdbdump.c
+++ b/regdbdump.c
@@ -2,35 +2,35 @@
#include <errno.h>
#include "reglib.h"
-static int reglib_regdbdump(char *regdb_file)
+static void reglib_regdbdump(const struct reglib_regdb_ctx *ctx)
{
const struct ieee80211_regdomain *rd = NULL;
unsigned int idx = 0;
- reglib_for_each_country(rd, idx, regdb_file) {
+ reglib_for_each_country(rd, idx, ctx) {
reglib_print_regdom(rd);
free((struct ieee80211_regdomain *) rd);
}
-
- if (!idx) {
- fprintf(stderr, "Invalid or empty regulatory file, note: "
- "a binary regulatory file should be used.\n");
- return -EINVAL;
- }
-
- return 0;
}
int main(int argc, char **argv)
{
- int r;
+ const struct reglib_regdb_ctx *ctx;
if (argc != 2) {
fprintf(stderr, "Usage: %s <regulatory-binary-file>\n", argv[0]);
- return 2;
+ return -EINVAL;
+ }
+
+ ctx = reglib_malloc_regdb_ctx(argv[1]);
+ if (!ctx) {
+ fprintf(stderr, "Invalid or empty regulatory file, note: "
+ "a binary regulatory file should be used.\n");
+ return -EINVAL;
}
- r = reglib_regdbdump(argv[1]);
+ reglib_regdbdump(ctx);
+ reglib_free_regdb_ctx(ctx);
- return r;
+ return 0;
}
diff --git a/reglib.c b/reglib.c
index ff05aaa..c4d00f8 100644
--- a/reglib.c
+++ b/reglib.c
@@ -336,28 +336,19 @@ country2rd(const struct reglib_regdb_ctx *ctx,
}
const struct ieee80211_regdomain *
-reglib_get_rd_idx(unsigned int idx, const char *file)
+reglib_get_rd_idx(unsigned int idx, const struct reglib_regdb_ctx *ctx)
{
- const struct reglib_regdb_ctx *ctx;
struct regdb_file_reg_country *country;
- const struct ieee80211_regdomain *rd = NULL;
- ctx = reglib_malloc_regdb_ctx(file);
if (!ctx)
return NULL;
if (idx >= ctx->num_countries)
- goto out;
+ return NULL;
country = ctx->countries + idx;
- rd = country2rd(ctx, country);
- if (!rd)
- goto out;
-
-out:
- reglib_free_regdb_ctx(ctx);
- return rd;
+ return country2rd(ctx, country);
}
const struct ieee80211_regdomain *
@@ -552,14 +543,18 @@ reglib_intersect_rds(const struct ieee80211_regdomain *rd1,
return rd;
}
-const struct ieee80211_regdomain *reglib_intersect_regdb(char *regdb_file)
+const struct ieee80211_regdomain *
+reglib_intersect_regdb(const struct reglib_regdb_ctx *ctx)
{
const struct ieee80211_regdomain *rd;
struct ieee80211_regdomain *prev_rd_intsct = NULL, *rd_intsct = NULL;
int intersected = 0;
unsigned int idx = 0;
- reglib_for_each_country(rd, idx, regdb_file) {
+ if (!ctx)
+ return NULL;
+
+ reglib_for_each_country(rd, idx, ctx) {
if (reglib_is_world_regdom((const char *) rd->alpha2)) {
free((struct ieee80211_regdomain *) rd);
continue;
diff --git a/reglib.h b/reglib.h
index f1bd6b8..86087e3 100644
--- a/reglib.h
+++ b/reglib.h
@@ -139,12 +139,12 @@ const struct reglib_regdb_ctx *reglib_malloc_regdb_ctx(const char *regdb_file);
void reglib_free_regdb_ctx(const struct reglib_regdb_ctx *regdb_ctx);
const struct ieee80211_regdomain *
-reglib_get_rd_idx(unsigned int idx, const char *file);
+reglib_get_rd_idx(unsigned int idx, const struct reglib_regdb_ctx *ctx);
-#define reglib_for_each_country(__rd, __idx, __file) \
- for (__rd = reglib_get_rd_idx(__idx, __file); \
+#define reglib_for_each_country(__rd, __idx, __ctx) \
+ for (__rd = reglib_get_rd_idx(__idx, __ctx); \
__rd != NULL; \
- __rd = reglib_get_rd_idx(++__idx, __file)) \
+ __rd = reglib_get_rd_idx(++__idx, __ctx)) \
const struct ieee80211_regdomain *
reglib_get_rd_alpha2(const char *alpha2, const char *file);
@@ -166,6 +166,7 @@ reglib_intersect_rds(const struct ieee80211_regdomain *rd1,
* to find rules that fit all regulatory domains it return a regulatory
* domain with such rules otherwise it returns NULL.
*/
-const struct ieee80211_regdomain *reglib_intersect_regdb(char *regdb_file);
+const struct ieee80211_regdomain *
+reglib_intersect_regdb(const struct reglib_regdb_ctx *ctx);
#endif
--
1.7.10.4
next prev parent reply other threads:[~2013-05-31 2:12 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-31 2:08 [PATCH 00/40] crda: reglib enhancements Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 01/40] crda: make reg_rules_intersect() style match Linux Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 02/40] crda: port over Linux is_valid_reg_rule() change bd05f28e Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 03/40] crda: remove verbose errors out of regdom_intersect() Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 04/40] crda: constify usage of struct ieee80211_regdomain Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 05/40] crda: remove unused BUG_ON() from intersect.c Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 06/40] crda: move regdom_intersect() to reglib Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 07/40] crda: fix regression when using reglib_for_each_country() Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 08/40] crda: move intersection if first attempt failed Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 09/40] crda: do not double count on reglib_for_each_country() Luis R. Rodriguez
2013-05-31 2:08 ` [PATCH 10/40] crda: annotate intersection worst case scenerio Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 11/40] crda: fix intersect.c memory management Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 12/40] crda: explicitly munmap() on reglib_get_rd_alpha2() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 13/40] crda: explicitly close file descriptor and munmap() on failures Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 14/40] crda: separate crda_verify_db_signature() implementations Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 15/40] crda: use gcry_sexp_release() on crda_verify_db_signature() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 16/40] crda: explicitly use close() and munmap() on reglib_get_rd_alpha2() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 17/40] crda: use gcry_mpi_release() when using gcry_mpi_scan() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 18/40] crda: rename world and prev_world on intersect.c Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 19/40] crda: remove verbosity out of intersect.c Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 20/40] crda: rename regdom_intersect() to reglib_intersect_rds() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 21/40] crda: rename crda_get_file_ptr() to reglib_get_file_ptr() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 22/40] crda: rename crda_verify_db_signature() to reglib_verify_db_signature() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 23/40] crda: rename print_regdom() to reglib_print_regdom() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 24/40] crda: add regdb_dfs_regions Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 25/40] crda: make print-regdom use internal flags Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 26/40] crda: move reg print helpers to reglib Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 27/40] crda: rename is_world_regdom() to reglib_is_world_regdom() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 28/40] crda: rename isalpha_upper() to reglib_isalpha_upper() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 29/40] crda: rename is_alpha2() to reglib_is_alpha2() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 30/40] crda: rename is_valid_regdom() to reglib_is_valid_regdom() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 31/40] crda: rename max() to reglib_max() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 32/40] crda: rename min() to reglib_min() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 33/40] crda: fix spacing on reglib_for_each_country() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 34/40] crda: clarify intersect.c only computes an intersection Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 35/40] crda: separate intersecting a full db into a helper Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 36/40] crda: move reglib_intersect_regdb() to reglib Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 37/40] crda: move regdbprint to its own helper Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 38/40] crda: add reglib regdb context helpers: reglib_(malloc|free)_regdb_ctx() Luis R. Rodriguez
2013-05-31 2:09 ` [PATCH 39/40] crda: pass struct reglib_regdb_ctx to country2rd() Luis R. Rodriguez
2013-05-31 2:09 ` Luis R. Rodriguez [this message]
2013-06-30 23:08 ` [PATCH 00/40] crda: reglib enhancements Luis R. Rodriguez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1369966169-23640-41-git-send-email-mcgrof@do-not-panic.com \
--to=mcgrof@do-not-panic.com \
--cc=linux-wireless@vger.kernel.org \
--cc=wireless-regdb@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).