ifconfig: 802.11: print node unicast key (PTK) if available in STA mode

Add a variable when querying the BSSID so we can later use it rather
than losing the "data" buffer.

When printing key information also query the node unicast key if in
STA mode (the key for the BSSID).  Do not error in case we fail.
This is helpful for debugging mostly; was also useful when testing
GCMP support.

Sponsored by:	The FreeBSD Foundation
MFC after;	3 days
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D50554
This commit is contained in:
Bjoern A. Zeeb 2025-05-27 19:44:42 +00:00
parent 54ad06cad1
commit e277735ce0

View file

@ -4898,6 +4898,7 @@ ieee80211_status(if_ctx *ctx)
{
int s = ctx->io_s;
static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
uint8_t bssid[IEEE80211_ADDR_LEN];
enum ieee80211_opmode opmode = get80211opmode(ctx);
int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
uint8_t data[32];
@ -4948,10 +4949,10 @@ ieee80211_status(if_ctx *ctx)
} else if (verbose)
printf(" channel UNDEF");
if (get80211(ctx, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
(memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose)) {
printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
printbssidname((struct ether_addr *)data);
if (get80211(ctx, IEEE80211_IOC_BSSID, bssid, IEEE80211_ADDR_LEN) >= 0 &&
(memcmp(bssid, zerobssid, sizeof(zerobssid)) != 0 || verbose)) {
printf(" bssid %s", ether_ntoa((struct ether_addr *)bssid));
printbssidname((struct ether_addr *)bssid);
}
if (get80211len(ctx, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
@ -5107,6 +5108,21 @@ ieee80211_status(if_ctx *ctx)
printkey(ctx, &ik);
}
}
if (opmode == IEEE80211_M_STA && wpa >= 2) {
struct ieee80211req_key ik;
int error;
memset(&ik, 0, sizeof(ik));
ik.ik_keyix = IEEE80211_KEYIX_NONE;
memcpy(ik.ik_macaddr, bssid, sizeof(ik.ik_macaddr));
error = get80211(ctx, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik));
if (error == 0 && ik.ik_keylen != 0) {
if (verbose)
LINE_BREAK();
printkey(ctx, &ik);
i++;
}
}
if (i > 0 && verbose)
LINE_BREAK();
end: