nl80211: fix phy/netdev index lookup
Don't assume a fixed naming pattern. Check all options in this order: - netdev - phy name - wifi device in uci Use the first one that matches Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
1f695d9c7f
commit
b7f9f06e15
1 changed files with 13 additions and 11 deletions
|
@ -409,7 +409,8 @@ out:
|
||||||
static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname,
|
static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname,
|
||||||
int cmd, int flags)
|
int cmd, int flags)
|
||||||
{
|
{
|
||||||
int ifidx = -1, phyidx = -1;
|
unsigned int ifidx = 0;
|
||||||
|
int phyidx = -1;
|
||||||
struct nl80211_msg_conveyor *cv;
|
struct nl80211_msg_conveyor *cv;
|
||||||
|
|
||||||
if (ifname == NULL)
|
if (ifname == NULL)
|
||||||
|
@ -418,16 +419,17 @@ static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname,
|
||||||
if (nl80211_init() < 0)
|
if (nl80211_init() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!strncmp(ifname, "phy", 3))
|
|
||||||
phyidx = atoi(&ifname[3]);
|
|
||||||
else if (!strncmp(ifname, "radio", 5))
|
|
||||||
phyidx = nl80211_phy_idx_from_uci(ifname);
|
|
||||||
|
|
||||||
if (!strncmp(ifname, "mon.", 4))
|
if (!strncmp(ifname, "mon.", 4))
|
||||||
ifidx = if_nametoindex(&ifname[4]);
|
ifidx = if_nametoindex(&ifname[4]);
|
||||||
else
|
else
|
||||||
ifidx = if_nametoindex(ifname);
|
ifidx = if_nametoindex(ifname);
|
||||||
|
|
||||||
|
if (!ifidx) {
|
||||||
|
phyidx = nl80211_phy_idx_from_phy(ifname);
|
||||||
|
if (phyidx < 0)
|
||||||
|
phyidx = nl80211_phy_idx_from_uci(ifname);
|
||||||
|
}
|
||||||
|
|
||||||
/* Valid ifidx must be greater than 0 */
|
/* Valid ifidx must be greater than 0 */
|
||||||
if ((ifidx <= 0) && (phyidx < 0))
|
if ((ifidx <= 0) && (phyidx < 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -715,11 +717,11 @@ static char * nl80211_phy2ifname(const char *ifname)
|
||||||
/* Only accept phy name of the form phy%d or radio%d */
|
/* Only accept phy name of the form phy%d or radio%d */
|
||||||
if (!ifname)
|
if (!ifname)
|
||||||
return NULL;
|
return NULL;
|
||||||
else if (!strncmp(ifname, "phy", 3))
|
|
||||||
phyidx = atoi(&ifname[3]);
|
phyidx = nl80211_phy_idx_from_phy(ifname);
|
||||||
else if (!strncmp(ifname, "radio", 5))
|
if (phyidx < 0)
|
||||||
phyidx = nl80211_phy_idx_from_uci(ifname);
|
phyidx = nl80211_phy_idx_from_uci(ifname);;
|
||||||
else
|
if (phyidx < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(nif, 0, sizeof(nif));
|
memset(nif, 0, sizeof(nif));
|
||||||
|
|
Loading…
Add table
Reference in a new issue