int main(int argc, char **argv) { 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, "You must specify a file\n"); return -EINVAL; } /* We intersect only when we have to rd structures ready */ reglib_for_each_country(rd, idx, argv[1]) { if (is_world_regdom((const char *) rd->alpha2)) continue; if (!prev_world) { prev_world = rd; continue; } if (world) { free(prev_world); prev_world = world; } world = regdom_intersect(prev_world, rd); if (!world) { /* Could be something else but we'll live with this */ r = -ENOMEM; if (intersected) fprintf(stderr, "Could not intersect world " "with country (%.2s)\n", rd->alpha2); else fprintf(stderr, "Could not intersect country (%.2s) " "with country (%.2s)\n", prev_world->alpha2, rd->alpha2); goto out; } if (intersected) /* Use UTF-8 Intersection symbol ? (0xE2,0x88,0xA9) :) */ printf("WW (%d) intersect %c%c (%d) ==> %d rules\n", prev_world->n_reg_rules, rd->alpha2[0], rd->alpha2[1], rd->n_reg_rules, world->n_reg_rules); else printf("%c%c (%d) intersect %c%c (%d) ==> %d rules\n", prev_world->alpha2[0], prev_world->alpha2[1], prev_world->n_reg_rules, rd->alpha2[0], rd->alpha2[1], rd->n_reg_rules, world->n_reg_rules); intersected++; } if (idx == 1) { world = rd; rd = NULL; } if (intersected > 1) printf("%d regulatory domains intersected\n", intersected); else printf("Only one intersection completed\n"); /* Tada! */ printf("== World regulatory domain: ==\n"); print_regdom(world); out: if (!intersected) { free(world); return r; } if (intersected > 1) { free(rd); free(prev_world); } free(world); return r; }
int main(int argc, char **argv) { int fd; struct stat stat; __u8 *db; struct regdb_file_header *header; struct regdb_file_reg_country *countries; int dblen, siglen, num_countries, i, r = 0; struct ieee80211_regdomain *rd = NULL; 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)) return -EINVAL; num_countries = ntohl(header->reg_country_num); countries = crda_get_file_ptr(db, dblen, sizeof(struct regdb_file_reg_country) * num_countries, header->reg_country_ptr); for (i = 0; i < num_countries; i++) { struct regdb_file_reg_country *country = countries + i; rd = country2rd(db, dblen, country); if (!rd) { r = -ENOMEM; fprintf(stderr, "Could not covert country " "(%.2s) to rd\n", country->alpha2); goto out; } print_regdom(rd); free(rd); rd = NULL; } out: return r; }