net80211: adjust more VHT structures/fields

Replace ieee80211_ie_vhtcap with ieee80211_vht_cap and
ieee80211_ie_vht_operation with ieee80211_vht_operation.
The "ie" version has the two bytes type/length at the beginning which
we did not actually use as such (the one place doing did just as unused
extra work).

Using the non-"ie" versions allows us to re-use them on shared code.
Using an enum helps us to not accidentally get unsuppored or unhandled
values tough we cannot use it in the struct as we need to ensure the
field width.

ieee80211_vht_operation is guarded by _KERNEL/WANT_NET80211.  While the
header is supposed to be exported to user land historically, software
such as wpa bring their own structure definitions.  For in-tree usage
it is only ifconfig which really cares (at least for now).

Sponsored by:	The FreeBSD Foundation
Reviewed by:	adrian (earlier), cc
Differential Revision: https://reviews.freebsd.org/D42901

(cherry picked from commit e85eb4c8d7bd8051c351a6fc6982a8b3bcfdbb2d)
This commit is contained in:
Bjoern A. Zeeb 2023-12-02 20:40:51 +00:00 committed by Franco Fichtner
parent f7b006edfa
commit f5dc1318ce
7 changed files with 61 additions and 60 deletions

View File

@ -70,6 +70,7 @@
#include <net/if_media.h>
#include <net/route.h>
#define WANT_NET80211 1
#include <net80211/ieee80211_ioctl.h>
#include <net80211/ieee80211_freebsd.h>
#include <net80211/ieee80211_superg.h>
@ -2780,10 +2781,18 @@ printvhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
{
printf("%s", tag);
if (verbose) {
const struct ieee80211_ie_vhtcap *vhtcap =
(const struct ieee80211_ie_vhtcap *) ie;
uint32_t vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
const struct ieee80211_vht_cap *vhtcap;
uint32_t vhtcap_info;
/* Check that the the right size. */
if (ie[1] != sizeof(*vhtcap)) {
printf("<err: vht_cap inval. length>");
return;
}
/* Skip Element ID and Length. */
vhtcap = (const struct ieee80211_vht_cap *)(ie + 2);
vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
printf("<cap 0x%08x", vhtcap_info);
printf(" rx_mcs_map 0x%x",
LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
@ -2803,13 +2812,20 @@ printvhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
{
printf("%s", tag);
if (verbose) {
const struct ieee80211_ie_vht_operation *vhtinfo =
(const struct ieee80211_ie_vht_operation *) ie;
const struct ieee80211_vht_operation *vhtinfo;
printf("<chw %d freq1_idx %d freq2_idx %d basic_mcs_set 0x%04x>",
/* Check that the the right size. */
if (ie[1] != sizeof(*vhtinfo)) {
printf("<err: vht_operation inval. length>");
return;
}
/* Skip Element ID and Length. */
vhtinfo = (const struct ieee80211_vht_operation *)(ie + 2);
printf("<chw %d freq0_idx %d freq1_idx %d basic_mcs_set 0x%04x>",
vhtinfo->chan_width,
vhtinfo->center_freq_seg1_idx,
vhtinfo->center_freq_seg2_idx,
vhtinfo->center_freq_seq0_idx,
vhtinfo->center_freq_seq1_idx,
LE_READ_2(&vhtinfo->basic_mcs_set));
}
}

View File

@ -866,29 +866,25 @@ struct ieee80211_vht_cap {
struct ieee80211_vht_mcs_info supp_mcs;
} __packed;
/* VHT capabilities element: 802.11ac-2013 8.4.2.160 */
struct ieee80211_ie_vhtcap {
uint8_t ie;
uint8_t len;
uint32_t vht_cap_info;
struct ieee80211_vht_mcs_info supp_mcs;
} __packed;
/* 802.11ac-2013, Table 8-183x-VHT Operation Information subfields */
enum ieee80211_vht_chanwidth {
IEEE80211_VHT_CHANWIDTH_USE_HT = 0, /* 20 MHz or 40 MHz */
IEEE80211_VHT_CHANWIDTH_80MHZ = 1, /* 80MHz */
IEEE80211_VHT_CHANWIDTH_160MHZ = 2, /* 160MHz */
IEEE80211_VHT_CHANWIDTH_80P80MHZ = 3, /* 80+80MHz */
/* 4..255 reserved. */
};
/* VHT operation mode subfields - 802.11ac-2013 Table 8.183x */
#define IEEE80211_VHT_CHANWIDTH_USE_HT 0 /* Use HT IE for chw */
#define IEEE80211_VHT_CHANWIDTH_80MHZ 1 /* 80MHz */
#define IEEE80211_VHT_CHANWIDTH_160MHZ 2 /* 160MHz */
#define IEEE80211_VHT_CHANWIDTH_80P80MHZ 3 /* 80+80MHz */
/* VHT operation IE - 802.11ac-2013 8.4.2.161 */
struct ieee80211_ie_vht_operation {
uint8_t ie;
uint8_t len;
uint8_t chan_width;
uint8_t center_freq_seg1_idx;
uint8_t center_freq_seg2_idx;
uint16_t basic_mcs_set;
/* The name conflicts with the same structure in wpa. Only ifconfig needs this. */
#if defined(_KERNEL) || defined(WANT_NET80211)
/* 802.11ac-2013 8.4.2.161 VHT Operation element */
struct ieee80211_vht_operation {
uint8_t chan_width; /* enum ieee80211_vht_chanwidth */
uint8_t center_freq_seq0_idx; /* 20/40/80/160 - VHT chan1 */
uint8_t center_freq_seq1_idx; /* 80+80 - VHT chan2 */
uint16_t basic_mcs_set; /* Basic VHT-MCS and NSS Set */
} __packed;
#endif
/* 802.11ac VHT Capabilities */
#define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_3895 0x00000000

View File

@ -2125,12 +2125,12 @@ hostap_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0,
/* Validate VHT IEs */
if (vhtcap != NULL) {
IEEE80211_VERIFY_LENGTH(vhtcap[1],
sizeof(struct ieee80211_ie_vhtcap) - 2,
sizeof(struct ieee80211_vht_cap),
return);
}
if (vhtinfo != NULL) {
IEEE80211_VERIFY_LENGTH(vhtinfo[1],
sizeof(struct ieee80211_ie_vht_operation) - 2,
sizeof(struct ieee80211_vht_operation),
return);
}

View File

@ -771,12 +771,12 @@ ieee80211_parse_beacon(struct ieee80211_node *ni, struct mbuf *m,
/* Process VHT IEs */
if (scan->vhtcap != NULL) {
IEEE80211_VERIFY_LENGTH(scan->vhtcap[1],
sizeof(struct ieee80211_ie_vhtcap) - 2,
sizeof(struct ieee80211_vht_cap),
scan->vhtcap = NULL);
}
if (scan->vhtopmode != NULL) {
IEEE80211_VERIFY_LENGTH(scan->vhtopmode[1],
sizeof(struct ieee80211_ie_vht_operation) - 2,
sizeof(struct ieee80211_vht_operation),
scan->vhtopmode = NULL);
}

View File

@ -2457,7 +2457,7 @@ ieee80211_probereq_ie_len(struct ieee80211vap *vap, struct ieee80211com *ic)
sizeof(struct ieee80211_ie_htcap) : 0)
#ifdef notyet
+ sizeof(struct ieee80211_ie_htinfo) /* XXX not needed? */
+ sizeof(struct ieee80211_ie_vhtcap)
+ 2 + sizeof(struct ieee80211_vht_cap)
#endif
+ ((vap->iv_flags & IEEE80211_F_WPA1 && vap->iv_wpa_ie != NULL) ?
vap->iv_wpa_ie[1] : 0)
@ -2822,7 +2822,7 @@ ieee80211_send_mgmt(struct ieee80211_node *ni, int type, int arg)
+ 2 + 26
+ sizeof(struct ieee80211_wme_info)
+ sizeof(struct ieee80211_ie_htcap)
+ sizeof(struct ieee80211_ie_vhtcap)
+ 2 + sizeof(struct ieee80211_vht_cap)
+ 4 + sizeof(struct ieee80211_ie_htcap)
#ifdef IEEE80211_SUPPORT_SUPERG
+ sizeof(struct ieee80211_ath_ie)
@ -2955,8 +2955,8 @@ ieee80211_send_mgmt(struct ieee80211_node *ni, int type, int arg)
+ 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
+ sizeof(struct ieee80211_ie_htcap) + 4
+ sizeof(struct ieee80211_ie_htinfo) + 4
+ sizeof(struct ieee80211_ie_vhtcap)
+ sizeof(struct ieee80211_ie_vht_operation)
+ 2 + sizeof(struct ieee80211_vht_cap)
+ 2 + sizeof(struct ieee80211_vht_operation)
+ sizeof(struct ieee80211_wme_param)
#ifdef IEEE80211_SUPPORT_SUPERG
+ sizeof(struct ieee80211_ath_ie)
@ -3114,8 +3114,8 @@ ieee80211_alloc_proberesp(struct ieee80211_node *bss, int legacy)
+ sizeof(struct ieee80211_wme_param)
+ 4 + sizeof(struct ieee80211_ie_htcap)
+ 4 + sizeof(struct ieee80211_ie_htinfo)
+ sizeof(struct ieee80211_ie_vhtcap)
+ sizeof(struct ieee80211_ie_vht_operation)
+ 2 + sizeof(struct ieee80211_vht_cap)
+ 2 + sizeof(struct ieee80211_vht_operation)
#ifdef IEEE80211_SUPPORT_SUPERG
+ sizeof(struct ieee80211_ath_ie)
#endif
@ -3729,8 +3729,8 @@ ieee80211_beacon_alloc(struct ieee80211_node *ni)
/* XXX conditional? */
+ 4+2*sizeof(struct ieee80211_ie_htcap)/* HT caps */
+ 4+2*sizeof(struct ieee80211_ie_htinfo)/* HT info */
+ sizeof(struct ieee80211_ie_vhtcap)/* VHT caps */
+ sizeof(struct ieee80211_ie_vht_operation)/* VHT info */
+ 2 + sizeof(struct ieee80211_vht_cap)/* VHT caps */
+ 2 + sizeof(struct ieee80211_vht_operation)/* VHT info */
+ (vap->iv_caps & IEEE80211_C_WME ? /* WME */
sizeof(struct ieee80211_wme_param) : 0)
#ifdef IEEE80211_SUPPORT_SUPERG

View File

@ -343,7 +343,7 @@ ieee80211_vht_node_leave(struct ieee80211_node *ni)
*/
void
ieee80211_vht_get_vhtcap_ie(struct ieee80211_node *ni,
struct ieee80211_ie_vhtcap *vhtcap, int opmode)
struct ieee80211_vht_cap *vhtcap, int opmode)
{
struct ieee80211vap *vap = ni->ni_vap;
// struct ieee80211com *ic = vap->iv_ic;
@ -351,9 +351,6 @@ ieee80211_vht_get_vhtcap_ie(struct ieee80211_node *ni,
uint32_t new_vhtcap;
int i;
vhtcap->ie = IEEE80211_ELEMID_VHT_CAP;
vhtcap->len = sizeof(struct ieee80211_ie_vhtcap) - 2;
/*
* Capabilities - it depends on whether we are a station
* or not.
@ -681,19 +678,12 @@ ieee80211_vht_get_vhtcap_ie(struct ieee80211_node *ni,
uint8_t *
ieee80211_add_vhtcap(uint8_t *frm, struct ieee80211_node *ni)
{
struct ieee80211_ie_vhtcap vhtcap;
int opmode;
struct ieee80211_vht_cap vhtcap;
opmode = 0;
if (ni->ni_vap->iv_opmode == IEEE80211_M_STA)
opmode = 1;
ieee80211_vht_get_vhtcap_ie(ni, &vhtcap, opmode);
memset(frm, '\0', sizeof(struct ieee80211_ie_vhtcap));
ieee80211_vht_get_vhtcap_ie(ni, &vhtcap, 1);
frm[0] = IEEE80211_ELEMID_VHT_CAP;
frm[1] = sizeof(struct ieee80211_ie_vhtcap) - 2;
frm[1] = sizeof(vhtcap);
frm += 2;
/* 32-bit VHT capability */
@ -749,10 +739,9 @@ ieee80211_vht_get_chwidth_ie(struct ieee80211_channel *c)
uint8_t *
ieee80211_add_vhtinfo(uint8_t *frm, struct ieee80211_node *ni)
{
memset(frm, '\0', sizeof(struct ieee80211_ie_vht_operation));
frm[0] = IEEE80211_ELEMID_VHT_OPMODE;
frm[1] = sizeof(struct ieee80211_ie_vht_operation) - 2;
frm[1] = sizeof(struct ieee80211_vht_operation);
frm += 2;
/* 8-bit chanwidth */
@ -860,7 +849,7 @@ ieee80211_vht_adjust_channel(struct ieee80211com *ic,
*/
void
ieee80211_vht_get_vhtinfo_ie(struct ieee80211_node *ni,
struct ieee80211_ie_vht_operation *vhtop, int opmode)
struct ieee80211_vht_operation *vhtop, int opmode)
{
printf("%s: called; TODO!\n", __func__);
}

View File

@ -59,8 +59,8 @@ struct ieee80211_channel *
struct ieee80211_channel *, int);
void ieee80211_vht_get_vhtcap_ie(struct ieee80211_node *ni,
struct ieee80211_ie_vhtcap *, int);
struct ieee80211_vht_cap *, int);
void ieee80211_vht_get_vhtinfo_ie(struct ieee80211_node *ni,
struct ieee80211_ie_vht_operation *, int);
struct ieee80211_vht_operation *, int);
#endif /* _NET80211_IEEE80211_VHT_H_ */