From: Luis R. Rodriguez Date: Wed, 18 Jan 2012 21:59:46 +0000 (-0800) Subject: crda: make intersect.c use reglib_for_each_country() X-Git-Tag: upstream/1.1.3~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a09f4dd2ace905831cb60cf4c8f5a9ca855123f;p=platform%2Fupstream%2Fcrda.git crda: make intersect.c use reglib_for_each_country() Signed-off-by: Luis R. Rodriguez --- 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 \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