From: Jo-Philipp Wich Date: Mon, 23 Jul 2018 15:33:09 +0000 (+0200) Subject: nl80211: add support for obtaining bssid from NL80211_CMD_GET_INTERFACE X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=44956b780db9aa71ac86152577275ff235d7afef;p=oweals%2Fiwinfo.git nl80211: add support for obtaining bssid from NL80211_CMD_GET_INTERFACE Fixes missing "BSSID" on Mesh Point interfaces Signed-off-by: Jo-Philipp Wich --- diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index d135d30..fe307ab 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -1026,6 +1026,20 @@ struct nl80211_ssid_bssid { unsigned char bssid[7]; }; +static int nl80211_get_macaddr_cb(struct nl_msg *msg, void *arg) +{ + struct nl80211_ssid_bssid *sb = arg; + struct nlattr **tb = nl80211_parse(msg); + + if (tb[NL80211_ATTR_MAC]) { + sb->bssid[0] = 1; + memcpy(sb->bssid + 1, nla_data(tb[NL80211_ATTR_MAC]), + sizeof(sb->bssid) - 1); + } + + return NL_SKIP; +} + static int nl80211_get_ssid_bssid_cb(struct nl_msg *msg, void *arg) { int ielen; @@ -1109,11 +1123,17 @@ static int nl80211_get_bssid(const char *ifname, char *buf) char *res, bssid[sizeof("FF:FF:FF:FF:FF:FF\0")]; struct nl80211_ssid_bssid sb = { }; - /* try to find bssid from scan dump results */ res = nl80211_phy2ifname(ifname); - nl80211_request(res ? res : ifname, NL80211_CMD_GET_SCAN, NLM_F_DUMP, - nl80211_get_ssid_bssid_cb, &sb); + /* try to obtain mac address via NL80211_CMD_GET_INTERFACE */ + nl80211_request(res ? res : ifname, NL80211_CMD_GET_INTERFACE, 0, + nl80211_get_macaddr_cb, &sb); + + /* failed, try to find bssid from scan dump results */ + if (sb.bssid[0] == 0) + nl80211_request(res ? res : ifname, + NL80211_CMD_GET_SCAN, NLM_F_DUMP, + nl80211_get_ssid_bssid_cb, &sb); /* failed, try to find mac from hostapd info */ if ((sb.bssid[0] == 0) &&