diff options
author | Luis R. Rodriguez | 2013-05-30 17:20:55 -0500 |
---|---|---|
committer | Luis R. Rodriguez | 2013-05-30 20:56:14 -0500 |
commit | aa5f20519b16f9ba4ec1cb76724d8bba65dde1f9 (patch) | |
tree | 50e342156fd43af316a29486a9100f58f0f5e56a | |
parent | 73d19506cd587cc3ac3bd96f17e258e3d45447e3 (diff) | |
download | crda-aa5f20519b16f9ba4ec1cb76724d8bba65dde1f9.tar.gz crda-aa5f20519b16f9ba4ec1cb76724d8bba65dde1f9.tar.xz crda-aa5f20519b16f9ba4ec1cb76724d8bba65dde1f9.zip |
crda: move reglib_intersect_regdb() to reglib
There are no functional changes in this change.
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
-rw-r--r-- | intersect.c | 63 | ||||
-rw-r--r-- | reglib.c | 52 | ||||
-rw-r--r-- | reglib.h | 13 |
3 files changed, 65 insertions, 63 deletions
diff --git a/intersect.c b/intersect.c index b9e3429..56d0d35 100644 --- a/intersect.c +++ b/intersect.c | |||
@@ -6,69 +6,6 @@ | |||
6 | 6 | ||
7 | #include "reglib.h" | 7 | #include "reglib.h" |
8 | 8 | ||
9 | /** | ||
10 | * reglib_intersect_regdb - intersects a regulatory database | ||
11 | * | ||
12 | * @regdb_file: the regulatory database to intersect | ||
13 | * | ||
14 | * Goes through an entire regulatory database and intersects all regulatory | ||
15 | * domains. This will skip any regulatory marked with an alpha2 of '00', which | ||
16 | * is used to indicate a world regulatory domain. If intersection is able | ||
17 | * to find rules that fit all regulatory domains it return a regulatory | ||
18 | * domain with such rules otherwise it returns NULL. | ||
19 | */ | ||
20 | const struct ieee80211_regdomain *reglib_intersect_regdb(char *regdb_file) | ||
21 | { | ||
22 | const struct ieee80211_regdomain *rd; | ||
23 | struct ieee80211_regdomain *prev_rd_intsct = NULL, *rd_intsct = NULL; | ||
24 | int intersected = 0; | ||
25 | unsigned int idx = 0; | ||
26 | |||
27 | reglib_for_each_country(rd, idx, regdb_file) { | ||
28 | if (reglib_is_world_regdom((const char *) rd->alpha2)) { | ||
29 | free((struct ieee80211_regdomain *) rd); | ||
30 | continue; | ||
31 | } | ||
32 | |||
33 | if (!prev_rd_intsct) { | ||
34 | prev_rd_intsct = (struct ieee80211_regdomain *) rd; | ||
35 | continue; | ||
36 | } | ||
37 | |||
38 | if (rd_intsct) { | ||
39 | free(prev_rd_intsct); | ||
40 | prev_rd_intsct = (struct ieee80211_regdomain *) rd_intsct; | ||
41 | } | ||
42 | |||
43 | rd_intsct = reglib_intersect_rds(prev_rd_intsct, rd); | ||
44 | if (!rd_intsct) { | ||
45 | free(prev_rd_intsct); | ||
46 | free((struct ieee80211_regdomain *) rd); | ||
47 | return NULL; | ||
48 | } | ||
49 | |||
50 | intersected++; | ||
51 | free((struct ieee80211_regdomain *) rd); | ||
52 | } | ||
53 | |||
54 | if (!idx) | ||
55 | return NULL; | ||
56 | |||
57 | if (intersected <= 0) { | ||
58 | rd_intsct = prev_rd_intsct; | ||
59 | prev_rd_intsct = NULL; | ||
60 | if (idx > 1) { | ||
61 | free(rd_intsct); | ||
62 | return NULL; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | if (prev_rd_intsct) | ||
67 | free(prev_rd_intsct); | ||
68 | |||
69 | return rd_intsct; | ||
70 | } | ||
71 | |||
72 | int main(int argc, char **argv) | 9 | int main(int argc, char **argv) |
73 | { | 10 | { |
74 | const struct ieee80211_regdomain *rd; | 11 | const struct ieee80211_regdomain *rd; |
@@ -554,6 +554,58 @@ reglib_intersect_rds(const struct ieee80211_regdomain *rd1, | |||
554 | return rd; | 554 | return rd; |
555 | } | 555 | } |
556 | 556 | ||
557 | const struct ieee80211_regdomain *reglib_intersect_regdb(char *regdb_file) | ||
558 | { | ||
559 | const struct ieee80211_regdomain *rd; | ||
560 | struct ieee80211_regdomain *prev_rd_intsct = NULL, *rd_intsct = NULL; | ||
561 | int intersected = 0; | ||
562 | unsigned int idx = 0; | ||
563 | |||
564 | reglib_for_each_country(rd, idx, regdb_file) { | ||
565 | if (reglib_is_world_regdom((const char *) rd->alpha2)) { | ||
566 | free((struct ieee80211_regdomain *) rd); | ||
567 | continue; | ||
568 | } | ||
569 | |||
570 | if (!prev_rd_intsct) { | ||
571 | prev_rd_intsct = (struct ieee80211_regdomain *) rd; | ||
572 | continue; | ||
573 | } | ||
574 | |||
575 | if (rd_intsct) { | ||
576 | free(prev_rd_intsct); | ||
577 | prev_rd_intsct = (struct ieee80211_regdomain *) rd_intsct; | ||
578 | } | ||
579 | |||
580 | rd_intsct = reglib_intersect_rds(prev_rd_intsct, rd); | ||
581 | if (!rd_intsct) { | ||
582 | free(prev_rd_intsct); | ||
583 | free((struct ieee80211_regdomain *) rd); | ||
584 | return NULL; | ||
585 | } | ||
586 | |||
587 | intersected++; | ||
588 | free((struct ieee80211_regdomain *) rd); | ||
589 | } | ||
590 | |||
591 | if (!idx) | ||
592 | return NULL; | ||
593 | |||
594 | if (intersected <= 0) { | ||
595 | rd_intsct = prev_rd_intsct; | ||
596 | prev_rd_intsct = NULL; | ||
597 | if (idx > 1) { | ||
598 | free(rd_intsct); | ||
599 | return NULL; | ||
600 | } | ||
601 | } | ||
602 | |||
603 | if (prev_rd_intsct) | ||
604 | free(prev_rd_intsct); | ||
605 | |||
606 | return rd_intsct; | ||
607 | } | ||
608 | |||
557 | static const char *dfs_domain_name(enum regdb_dfs_regions region) | 609 | static const char *dfs_domain_name(enum regdb_dfs_regions region) |
558 | { | 610 | { |
559 | switch (region) { | 611 | switch (region) { |
@@ -90,4 +90,17 @@ struct ieee80211_regdomain * | |||
90 | reglib_intersect_rds(const struct ieee80211_regdomain *rd1, | 90 | reglib_intersect_rds(const struct ieee80211_regdomain *rd1, |
91 | const struct ieee80211_regdomain *rd2); | 91 | const struct ieee80211_regdomain *rd2); |
92 | 92 | ||
93 | /** | ||
94 | * reglib_intersect_regdb - intersects a regulatory database | ||
95 | * | ||
96 | * @regdb_file: the regulatory database to intersect | ||
97 | * | ||
98 | * Goes through an entire regulatory database and intersects all regulatory | ||
99 | * domains. This will skip any regulatory marked with an alpha2 of '00', which | ||
100 | * is used to indicate a world regulatory domain. If intersection is able | ||
101 | * to find rules that fit all regulatory domains it return a regulatory | ||
102 | * domain with such rules otherwise it returns NULL. | ||
103 | */ | ||
104 | const struct ieee80211_regdomain *reglib_intersect_regdb(char *regdb_file); | ||
105 | |||
93 | #endif | 106 | #endif |