Skip to content

Commit 6145db2

Browse files
committed
reglib: add reglib_is_valid_rd() and verify data upon build
This will verify the sanity of a regulatory domain upon build time. This is useful if you are making modifications to wireless-regdb and need to verify the regulatory domains won't be rejected by a similar checker. In the case of the Linux kernel regulatory domain data structures that get a complaint would have been rejected completely. Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
1 parent f4c3e3f commit 6145db2

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

regdbdump.c

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ static void reglib_regdbdump(const struct reglib_regdb_ctx *ctx)
88
unsigned int idx = 0;
99

1010
reglib_for_each_country(rd, idx, ctx) {
11+
if (!reglib_is_valid_rd(rd)) {
12+
fprintf(stderr, "country %.2s: invalid\n", rd->alpha2);
13+
free((struct ieee80211_regdomain *) rd);
14+
continue;
15+
}
1116
reglib_print_regdom(rd);
1217
free((struct ieee80211_regdomain *) rd);
1318
}

reglib.c

+16
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,22 @@ static int is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
427427
return 1;
428428
}
429429

430+
int reglib_is_valid_rd(const struct ieee80211_regdomain *rd)
431+
{
432+
const struct ieee80211_reg_rule *reg_rule = NULL;
433+
unsigned int i;
434+
435+
if (!rd->n_reg_rules)
436+
return 0;
437+
438+
for (i = 0; i < rd->n_reg_rules; i++) {
439+
reg_rule = &rd->reg_rules[i];
440+
if (!is_valid_reg_rule(reg_rule))
441+
return 0;
442+
}
443+
return 1;
444+
}
445+
430446
/*
431447
* Helper for reglib_intersect_rds(), this does the real
432448
* mathematical intersection fun

reglib.h

+10
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ reglib_get_rd_idx(unsigned int idx, const struct reglib_regdb_ctx *ctx);
150150
const struct ieee80211_regdomain *
151151
reglib_get_rd_alpha2(const char *alpha2, const char *file);
152152

153+
/**
154+
* reglib_is_valid_rd - validate regulatory domain data structure
155+
*
156+
* @rd: regulatory domain data structure to validate
157+
*
158+
* You can use this to validate regulatory domain data structures
159+
* for possible inconsistencies.
160+
*/
161+
int reglib_is_valid_rd(const struct ieee80211_regdomain *rd);
162+
153163
/* reg helpers */
154164
void reglib_print_regdom(const struct ieee80211_regdomain *rd);
155165
struct ieee80211_regdomain *

0 commit comments

Comments
 (0)