iwinfo: nl80211: support looking up phy by path=.. and macaddr=...

Can be used from within mac80211.sh without the need to reference the uci
config directly

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau 2021-06-09 14:21:51 +02:00
parent dd6d6d2dec
commit 268bb26d2e

View file

@ -293,15 +293,14 @@ static const char *nl80211_phy_path_str(const char *phyname)
return link; return link;
} }
static int nl80211_phy_idx_from_uci_path(struct uci_section *s) static int nl80211_phy_idx_from_path(const char *path)
{ {
char buf[128]; char buf[128];
struct dirent *e; struct dirent *e;
const char *path, *cur_path; const char *cur_path;
int idx = -1; int idx = -1;
DIR *d; DIR *d;
path = uci_lookup_option_string(uci_ctx, s, "path");
if (!path) if (!path)
return -1; return -1;
@ -329,14 +328,12 @@ static int nl80211_phy_idx_from_uci_path(struct uci_section *s)
return idx; return idx;
} }
static int nl80211_phy_idx_from_uci_macaddr(struct uci_section *s) static int nl80211_phy_idx_from_macaddr(const char *opt)
{ {
const char *opt;
char buf[128]; char buf[128];
int i, idx = -1; int i, idx = -1;
glob_t gl; glob_t gl;
opt = uci_lookup_option_string(uci_ctx, s, "macaddr");
if (!opt) if (!opt)
return -1; return -1;
@ -363,12 +360,10 @@ static int nl80211_phy_idx_from_uci_macaddr(struct uci_section *s)
return idx; return idx;
} }
static int nl80211_phy_idx_from_uci_phy(struct uci_section *s) static int nl80211_phy_idx_from_phy(const char *opt)
{ {
const char *opt;
char buf[128]; char buf[128];
opt = uci_lookup_option_string(uci_ctx, s, "phy");
if (!opt) if (!opt)
return -1; return -1;
@ -379,21 +374,27 @@ static int nl80211_phy_idx_from_uci_phy(struct uci_section *s)
static int nl80211_phy_idx_from_uci(const char *name) static int nl80211_phy_idx_from_uci(const char *name)
{ {
struct uci_section *s; struct uci_section *s;
const char *opt;
int idx = -1; int idx = -1;
s = iwinfo_uci_get_radio(name, "mac80211"); s = iwinfo_uci_get_radio(name, "mac80211");
if (!s) if (!s)
goto free; goto out;
idx = nl80211_phy_idx_from_uci_path(s); opt = uci_lookup_option_string(uci_ctx, s, "path");
idx = nl80211_phy_idx_from_path(opt);
if (idx >= 0)
goto out;
if (idx < 0) opt = uci_lookup_option_string(uci_ctx, s, "macaddr");
idx = nl80211_phy_idx_from_uci_macaddr(s); idx = nl80211_phy_idx_from_macaddr(opt);
if (idx >= 0)
goto out;
if (idx < 0) opt = uci_lookup_option_string(uci_ctx, s, "phy");
idx = nl80211_phy_idx_from_uci_phy(s); idx = nl80211_phy_idx_from_phy(s);
free: out:
iwinfo_uci_free(); iwinfo_uci_free();
return idx; return idx;
} }
@ -3469,7 +3470,14 @@ static int nl80211_lookup_phyname(const char *section, char *buf)
{ {
int idx; int idx;
if ((idx = nl80211_phy_idx_from_uci(section)) < 0) if (!strncmp(section, "path=", 5))
idx = nl80211_phy_idx_from_path(section + 5);
else if (!strncmp(section, "macaddr=", 8))
idx = nl80211_phy_idx_from_macaddr(section + 8);
else
idx = nl80211_phy_idx_from_uci(section);
if (idx < 0)
return -1; return -1;
sprintf(buf, "phy%d", idx); sprintf(buf, "phy%d", idx);