X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=iwinfo_utils.c;h=b313ea2049ca540c24b1922d085485a845c346bf;hb=7901e7c69fc793aa590529afad433ec856baca72;hp=4a824337a973bee371e447298295c2471f0bcc10;hpb=8ae758db52957939eeb6bc1c7da7be9d0339d3aa;p=project%2Fiwinfo.git diff --git a/iwinfo_utils.c b/iwinfo_utils.c index 4a82433..b313ea2 100644 --- a/iwinfo_utils.c +++ b/iwinfo_utils.c @@ -24,6 +24,7 @@ static int ioctl_socket = -1; +struct uci_context *uci_ctx = NULL; static int iwinfo_ioctl_socket(void) { @@ -365,3 +366,43 @@ void iwinfo_parse_rsn(struct iwinfo_crypto_entry *c, uint8_t *data, uint8_t len, data += 2 + (count * 4); len -= 2 + (count * 4); } + +struct uci_section *iwinfo_uci_get_radio(const char *name, const char *type) +{ + struct uci_ptr ptr = { + .package = "wireless", + .section = name, + }; + const char *opt; + + if (!uci_ctx) { + uci_ctx = uci_alloc_context(); + if (!uci_ctx) + return NULL; + } + + memset(&ptr, 0, sizeof(ptr)); + ptr.package = "wireless"; + ptr.section = name; + + if (uci_lookup_ptr(uci_ctx, &ptr, NULL, false)) + return NULL; + + if (!ptr.s || strcmp(ptr.s->type, "wifi-device") != 0) + return NULL; + + opt = uci_lookup_option_string(uci_ctx, ptr.s, "type"); + if (!opt || strcmp(opt, type) != 0) + return NULL; + + return ptr.s; +} + +void iwinfo_uci_free(void) +{ + if (!uci_ctx) + return; + + uci_free_context(uci_ctx); + uci_ctx = NULL; +}