static int handle_reg_set(struct nl80211_state *state, struct nl_msg *msg, int argc, char **argv, enum id_input id) { char alpha2[3]; if (argc < 1) return 1; if (!is_alpha2(argv[0]) && !is_world_regdom(argv[0])) { fprintf(stderr, "not a valid ISO/IEC 3166-1 alpha2\n"); fprintf(stderr, "Special non-alpha2 usable entries:\n"); fprintf(stderr, "\t00\tWorld Regulatory domain\n"); return 2; } alpha2[0] = argv[0][0]; alpha2[1] = argv[0][1]; alpha2[2] = '\0'; argc--; argv++; if (argc) return 1; NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); return 0; nla_put_failure: return -ENOBUFS; }
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; }