Search Linux Wireless

[RFC 03/11] crda: make intersect.c use reglib_for_each_country()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxxxxxxx>
---
 intersect.c |   93 +++++++---------------------------------------------------
 1 files changed, 12 insertions(+), 81 deletions(-)

diff --git a/intersect.c b/intersect.c
index 2e5dacf..6d3d393 100644
--- a/intersect.c
+++ b/intersect.c
@@ -182,101 +182,26 @@ static struct ieee80211_regdomain *regdom_intersect(
 
 int main(int argc, char **argv)
 {
-	int fd;
-	struct stat stat;
-	uint8_t *db;
-	struct regdb_file_header *header;
-	struct regdb_file_reg_country *countries;
-	int dblen, siglen, num_countries, i, r = 0;
+	int r = 0;
 	struct ieee80211_regdomain *prev_world = NULL, *rd = NULL, *world = NULL;
 	int intersected = 0;
+	unsigned int idx = 0;
 
 	if (argc != 2) {
-		fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
-		return 2;
-	}
-
-	fd = open(argv[1], O_RDONLY);
-	if (fd < 0) {
-		perror("failed to open db file");
-		return 2;
-	}
-
-	if (fstat(fd, &stat)) {
-		perror("failed to fstat db file");
-		return 2;
-	}
-
-	dblen = stat.st_size;
-
-	db = mmap(NULL, dblen, PROT_READ, MAP_PRIVATE, fd, 0);
-	if (db == MAP_FAILED) {
-		perror("failed to mmap db file");
-		return 2;
-	}
-
-	header = crda_get_file_ptr(db, dblen, sizeof(*header), 0);
-
-	if (ntohl(header->magic) != REGDB_MAGIC) {
-		fprintf(stderr, "Invalid database magic\n");
-		return 2;
-	}
-
-	if (ntohl(header->version) != REGDB_VERSION) {
-		fprintf(stderr, "Invalid database version\n");
-		return 2;
-	}
-
-	siglen = ntohl(header->signature_length);
-	/* adjust dblen so later sanity checks don't run into the signature */
-	dblen -= siglen;
-
-	if (dblen <= (int)sizeof(*header)) {
-		fprintf(stderr, "Invalid signature length %d\n", siglen);
-		return 2;
-	}
-
-	/* verify signature */
-	if (!crda_verify_db_signature(db, dblen, siglen))
+		fprintf(stderr, "You must specify a file\n");
 		return -EINVAL;
-
-	num_countries = ntohl(header->reg_country_num);
-
-	if (num_countries <= 0)
-		return 0;
-
-	countries = crda_get_file_ptr(db, dblen,
-			sizeof(struct regdb_file_reg_country) * num_countries,
-			header->reg_country_ptr);
+	}
 
 	/* We intersect only when we have to rd structures ready */
-	for (i = 0; i < num_countries; i++) {
-		struct regdb_file_reg_country *country = countries + i;
-
-		if (is_world_regdom((const char *) country->alpha2))
+	reglib_for_each_country(rd, idx, argv[1]) {
+		if (is_world_regdom((const char *) rd->alpha2))
 			continue;
 
-		/* Gets the rd for the current country */
-		rd = country2rd(db, dblen, country);
-		if (!rd) {
-			r = -ENOMEM;
-			fprintf(stderr, "Could not covert country "
-				"(%.2s) to rd\n", country->alpha2);
-			goto out;
-		}
-
-		if (num_countries == 1) {
-			world = rd;
-			rd = NULL;
-			break;
-		}
-
 		if (!prev_world) {
 			prev_world = rd;
 			continue;
 		}
 
-
 		if (world) {
 			free(prev_world);
 			prev_world = world;
@@ -318,6 +243,12 @@ int main(int argc, char **argv)
 		intersected++;
 	}
 
+	if (idx == 1) {
+		world = rd;
+		rd = NULL;
+	}
+
+
 	if (intersected > 1)
 		printf("%d regulatory domains intersected\n", intersected);
 	else
-- 
1.7.4.15.g7811d

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux