LinuxKPI: add 802.11 compat code

Add 802.11 compat code for mac80211 and to a minimal degree cfg80211.
This allows us to compile and use basic functionality of wireless
drivers such as iwlwifi.

This is a constant work in progress but having it in the tree will
allow others to test and more easy to track changes and avoid having
snapshots no longer applying to branches.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
This commit is contained in:
Bjoern A. Zeeb 2021-12-26 18:52:51 +00:00
parent d105895844
commit 6b4cac814e
11 changed files with 8782 additions and 2 deletions

View file

@ -0,0 +1,511 @@
/*-
* Copyright (c) 2020-2021 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _LINUXKPI_LINUX_IEEE80211_H
#define _LINUXKPI_LINUX_IEEE80211_H
#include <sys/types.h>
#include <net80211/ieee80211.h>
#include <asm/unaligned.h>
#include <linux/bitops.h>
#include <linux/if_ether.h>
/* linux_80211.c */
extern int debug_80211;
#define IEEE80211_CCMP_HDR_LEN 8 /* 802.11i .. net80211 comment */
#define IEEE80211_CCMP_PN_LEN 6
#define IEEE80211_CCMP_MIC_LEN 8 /* || 16 */
#define IEEE80211_GCMP_HDR_LEN 8
#define IEEE80211_GCMP_PN_LEN 6
#define IEEE80211_GMAC_PN_LEN 6
#define IEEE80211_MAX_PN_LEN 16
#define IEEE80211_INVAL_HW_QUEUE ((uint8_t)-1)
#define IEEE80211_MAX_AMPDU_BUF_HT 0x40
#define IEEE80211_MAX_AMPDU_BUF 256 /* for HE? */
#define IEEE80211_MAX_DATA_LEN (2300 + IEEE80211_CRC_LEN)
#define IEEE80211_MAX_MPDU_LEN_HT_BA 4095 /* 9.3.2.1 Format of Data frames; non-VHT non-DMG STA */
#define IEEE80211_MAX_MPDU_LEN_HT_3839 3839
#define IEEE80211_MAX_MPDU_LEN_VHT_3895 3895
#define IEEE80211_MAX_MPDU_LEN_VHT_7991 7991
#define IEEE80211_MAX_MPDU_LEN_VHT_11454 11454
#define IEEE80211_MAX_RTS_THRESHOLD 2346 /* net80211::IEEE80211_RTS_MAX */
#define IEEE80211_MIN_ACTION_SIZE 23 /* ? */
/* Wi-Fi Peer-to-Peer (P2P) Technical Specification */
#define IEEE80211_P2P_OPPPS_CTWINDOW_MASK 0x7f
#define IEEE80211_P2P_OPPPS_ENABLE_BIT BIT(7)
#define IEEE80211_QOS_CTL_A_MSDU_PRESENT 0x0080 /* 9.2.4.5.1, Table 9-6 QoS Control Field */
#define IEEE80211_RATE_SHORT_PREAMBLE BIT(0)
enum ieee80211_rate_control_changed_flags {
IEEE80211_RC_BW_CHANGED = BIT(0),
IEEE80211_RC_NSS_CHANGED = BIT(1),
IEEE80211_RC_SUPP_RATES_CHANGED = BIT(2),
};
#define IEEE80211_SCTL_FRAG IEEE80211_SEQ_FRAG_MASK
#define IEEE80211_SCTL_SEQ IEEE80211_SEQ_SEQ_MASK
#define IEEE80211_TKIP_ICV_LEN 4
#define IEEE80211_TKIP_IV_LEN 8 /* WEP + KID + EXT */
#define IEEE80211_VHT_EXT_NSS_BW_CAPABLE (1 << 13) /* assigned to tx_highest */
#define IEEE80211_VHT_MAX_AMPDU_1024K 7 /* 9.4.2.56.3 A-MPDU Parameters field, Table 9-163 */
#define IEEE80211_WEP_IV_LEN 3 /* net80211: IEEE80211_WEP_IVLEN */
#define IEEE80211_WEP_ICV_LEN 4
#define WLAN_AUTH_OPEN __LINE__ /* TODO FIXME brcmfmac */
#define WLAN_CAPABILITY_IBSS __LINE__ /* TODO FIXME no longer used? */
#define WLAN_CAPABILITY_SHORT_PREAMBLE __LINE__ /* TODO FIXME brcmfmac */
#define WLAN_CAPABILITY_SHORT_SLOT_TIME __LINE__ /* TODO FIXME brcmfmac */
#define WLAN_MAX_KEY_LEN 32 /* TODO FIXME brcmfmac */
#define WLAN_PMKID_LEN 16 /* TODO FIXME brcmfmac */
#define WLAN_KEY_LEN_CCMP 16
#define WLAN_KEY_LEN_GCMP_256 32
/* 9.4.2.56.3, Table 9-163 Subfields of the A-MPDU Parameters field */
enum ieee80211_min_mpdu_start_spacing {
IEEE80211_HT_MPDU_DENSITY_4 = 5, /* 4us */
IEEE80211_HT_MPDU_DENSITY_16 = 7, /* 16us */
};
/* 9.4.2.57, Table 9-168, HT Operation element fields and subfields */
#define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT 0x0080 /* B24.. */
#define IEEE80211_FCTL_STYPE IEEE80211_FC0_SUBTYPE_MASK
#define IEEE80211_STYPE_ASSOC_REQ IEEE80211_FC0_SUBTYPE_ASSOC_REQ
#define IEEE80211_STYPE_REASSOC_REQ IEEE80211_FC0_SUBTYPE_REASSOC_REQ
#define IEEE80211_STYPE_PROBE_REQ IEEE80211_FC0_SUBTYPE_PROBE_REQ
#define IEEE80211_STYPE_DISASSOC IEEE80211_FC0_SUBTYPE_DISASSOC
#define IEEE80211_STYPE_AUTH IEEE80211_FC0_SUBTYPE_AUTH
#define IEEE80211_STYPE_DEAUTH IEEE80211_FC0_SUBTYPE_DEAUTH
#define IEEE80211_STYPE_ACTION IEEE80211_FC0_SUBTYPE_ACTION
#define IEEE80211_NUM_ACS 4 /* net8021::WME_NUM_AC */
#define IEEE80211_MAX_SSID_LEN 32 /* 9.4.2.2 SSID element, net80211: IEEE80211_NWID_LEN */
/* Figure 9-27, BAR Control field */
#define IEEE80211_BAR_CTRL_TID_INFO_MASK 0xf000
#define IEEE80211_BAR_CTRL_TID_INFO_SHIFT 12
#define IEEE80211_PPE_THRES_INFO_PPET_SIZE 1 /* TODO FIXME ax? */
#define IEEE80211_PPE_THRES_NSS_MASK 2 /* TODO FIXME ax? */
#define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS 3 /* TODO FIXME ax? */
#define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK 8 /* TODO FIXME ax? */
#define IEEE80211_HT_OP_MODE_PROTECTION 0x03 /* MASK */
#define IEEE80211_HT_OP_MODE_PROTECTION_NONE 0x00
#define IEEE80211_HT_OP_MODE_PROTECTION_20MHZ 0x01
#define IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED 0x02
#define IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER 0x03
/* 9.6.13.1, Table 9-342 TDLS Action field values. */
enum ieee80211_tdls_action_code {
WLAN_TDLS_SETUP_REQUEST = 0,
WLAN_TDLS_SETUP_RESPONSE = 1,
WLAN_TDLS_SETUP_CONFIRM = 2,
WLAN_TDLS_TEARDOWN = 3,
WLAN_TDLS_PEER_TRAFFIC_INDICATION = 4,
WLAN_TDLS_CHANNEL_SWITCH_REQUEST = 5,
WLAN_TDLS_CHANNEL_SWITCH_RESPONSE = 6,
WLAN_TDLS_PEER_PSM_REQUEST = 7,
WLAN_TDLS_PEER_PSM_RESPONSE = 8,
WLAN_TDLS_PEER_TRAFFIC_RESPONSE = 9,
WLAN_TDLS_DISCOVERY_REQUEST = 10,
/* 11-255 reserved */
};
/* 9.4.2.27, Table 9-135. Extended Capabilities field. */
/* This is split up into octets CAPA1 = octet 1, ... */
#define WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING BIT(2 % 8)
#define WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT BIT(22 % 8)
#define WLAN_EXT_CAPA8_OPMODE_NOTIF BIT(62 % 8)
#define WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT BIT(5) /* XXX */
#define WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT BIT(7) /* XXX */
/* iwlwifi/mvm/utils:: for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_VI; ac++) */
/* Would be so much easier if we'd define constants to the same. */
enum ieee80211_ac_numbers {
IEEE80211_AC_VO = 0, /* net80211::WME_AC_VO */
IEEE80211_AC_VI = 1, /* net80211::WME_AC_VI */
IEEE80211_AC_BE = 2, /* net80211::WME_AC_BE */
IEEE80211_AC_BK = 3, /* net80211::WME_AC_BK */
};
#define IEEE80211_MAX_QUEUES 16 /* Assume IEEE80211_NUM_TIDS for the moment. */
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_VO 1
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_VI 2
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_BK 4
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_BE 8
#define IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL 0xf
struct vht_mcs {
uint16_t rx_mcs_map;
uint16_t rx_highest;
uint16_t tx_mcs_map;
uint16_t tx_highest;
};
struct ieee80211_vht_cap {
struct vht_mcs supp_mcs;;
__le32 vht_cap_info;
};
enum ieee80211_ht_max_ampdu_len {
IEEE80211_HT_MAX_AMPDU_64K
};
enum ieee80211_ampdu_mlme_action {
IEEE80211_AMPDU_RX_START,
IEEE80211_AMPDU_RX_STOP,
IEEE80211_AMPDU_TX_OPERATIONAL,
IEEE80211_AMPDU_TX_START,
IEEE80211_AMPDU_TX_START_DELAY_ADDBA,
IEEE80211_AMPDU_TX_START_IMMEDIATE,
IEEE80211_AMPDU_TX_STOP_CONT,
IEEE80211_AMPDU_TX_STOP_FLUSH,
IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
};
enum ieee80211_chanctx_switch_mode {
CHANCTX_SWMODE_REASSIGN_VIF,
CHANCTX_SWMODE_SWAP_CONTEXTS,
};
enum ieee80211_chanctx_change_flags {
IEEE80211_CHANCTX_CHANGE_MIN_WIDTH = BIT(0),
IEEE80211_CHANCTX_CHANGE_RADAR = BIT(1),
IEEE80211_CHANCTX_CHANGE_RX_CHAINS = BIT(2),
IEEE80211_CHANCTX_CHANGE_WIDTH = BIT(3),
};
enum ieee80211_frame_release_type {
IEEE80211_FRAME_RELEASE_PSPOLL = 1,
IEEE80211_FRAME_RELEASE_UAPSD = 2,
};
enum ieee80211_p2p_attr_ids {
IEEE80211_P2P_ATTR_DEVICE_ID,
IEEE80211_P2P_ATTR_DEVICE_INFO,
IEEE80211_P2P_ATTR_GROUP_ID,
IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
};
enum ieee80211_reconfig_type {
IEEE80211_RECONFIG_TYPE_RESTART,
IEEE80211_RECONFIG_TYPE_SUSPEND,
};
enum ieee80211_roc_type {
IEEE80211_ROC_TYPE_MGMT_TX,
IEEE80211_ROC_TYPE_NORMAL,
};
enum ieee80211_smps_mode {
IEEE80211_SMPS_OFF,
IEEE80211_SMPS_STATIC,
IEEE80211_SMPS_DYNAMIC,
IEEE80211_SMPS_AUTOMATIC,
IEEE80211_SMPS_NUM_MODES,
};
/* net80211::IEEE80211_S_* different but represents the state machine. */
/* Note: order here is important! */
enum ieee80211_sta_state {
IEEE80211_STA_NOTEXIST,
IEEE80211_STA_NONE,
IEEE80211_STA_AUTH,
IEEE80211_STA_ASSOC,
IEEE80211_STA_AUTHORIZED, /* 802.1x */
};
enum ieee80211_sta_rx_bw {
IEEE80211_STA_RX_BW_20,
IEEE80211_STA_RX_BW_40,
IEEE80211_STA_RX_BW_80,
IEEE80211_STA_RX_BW_160,
};
enum ieee80211_tx_info_flags {
/* XXX TODO .. right shift numbers - not sure where that came from? */
IEEE80211_TX_CTL_AMPDU = BIT(0),
IEEE80211_TX_CTL_ASSIGN_SEQ = BIT(1),
IEEE80211_TX_CTL_NO_ACK = BIT(2),
IEEE80211_TX_CTL_SEND_AFTER_DTIM = BIT(3),
IEEE80211_TX_CTL_TX_OFFCHAN = BIT(4),
IEEE80211_TX_CTL_REQ_TX_STATUS = BIT(5),
IEEE80211_TX_STATUS_EOSP = BIT(6),
IEEE80211_TX_STAT_ACK = BIT(7),
IEEE80211_TX_STAT_AMPDU = BIT(8),
IEEE80211_TX_STAT_AMPDU_NO_BACK = BIT(9),
IEEE80211_TX_STAT_TX_FILTERED = BIT(10),
IEEE80211_TX_STAT_NOACK_TRANSMITTED = BIT(11),
};
enum ieee80211_tx_control_flags {
/* XXX TODO .. right shift numbers */
IEEE80211_TX_CTRL_PORT_CTRL_PROTO = BIT(0),
};
enum ieee80211_tx_rate_flags {
/* XXX TODO .. right shift numbers */
IEEE80211_TX_RC_40_MHZ_WIDTH = BIT(0),
IEEE80211_TX_RC_80_MHZ_WIDTH = BIT(1),
IEEE80211_TX_RC_160_MHZ_WIDTH = BIT(2),
IEEE80211_TX_RC_GREEN_FIELD = BIT(3),
IEEE80211_TX_RC_MCS = BIT(4),
IEEE80211_TX_RC_SHORT_GI = BIT(5),
IEEE80211_TX_RC_VHT_MCS = BIT(6),
};
struct ieee80211_hdr { /* net80211::ieee80211_frame */
__le16 frame_control;
__le16 duration_id;
uint8_t addr1[ETH_ALEN];
uint8_t addr2[ETH_ALEN];
uint8_t addr3[ETH_ALEN];
__le16 seq_ctrl;
uint8_t addr4[ETH_ALEN];
};
struct ieee80211_vendor_ie {
};
/* 9.3.3.2 Format of Management frames */
struct ieee80211_mgmt {
__le16 frame_control;
__le16 duration_id;
uint8_t da[ETH_ALEN];
uint8_t sa[ETH_ALEN];
uint8_t bssid[ETH_ALEN];
__le16 seq_ctrl;
union {
/* 9.3.3.3 Beacon frame format */
struct {
uint64_t timestamp;
uint16_t beacon_int;
uint16_t capab_info;
uint8_t variable[0];
} beacon;
/* 9.3.3.10 Probe Request frame format */
struct {
uint8_t variable[0];
} probe_req;
/* 9.3.3.11 Probe Response frame format */
struct {
uint64_t timestamp;
uint16_t beacon_int;
uint16_t capab_info;
uint8_t variable[0];
} probe_resp;
/* 9.3.3.14 Action frame format */
struct {
/* 9.4.1.11 Action field */
uint8_t category;
/* 9.6.8 Public Action details */
union {
/* 9.6.8.33 Fine Timing Measurement frame format */
struct {
uint8_t dialog_token;
uint8_t follow_up;
uint8_t tod[6];
uint8_t toa[6];
uint16_t tod_error;
uint16_t toa_error;
uint8_t variable[0];
} ftm;
} u;
} action;
} u;
};
#define MHZ_TO_KHZ(_f) ((_f) * 1000)
#define DBI_TO_MBI(_g) ((_g) * 100)
#define MBI_TO_DBI(_x) ((_x) / 100)
#define DBM_TO_MBM(_g) ((_g) * 100)
#define MBM_TO_DBM(_x) ((_x) / 100)
#define IEEE80211_SEQ_TO_SN(_seqn) (((_seqn) & IEEE80211_SEQ_SEQ_MASK) >> \
IEEE80211_SEQ_SEQ_SHIFT)
/* Time unit (TU) to .. See net80211: IEEE80211_DUR_TU */
#define TU_TO_JIFFIES(_tu) (usecs_to_jiffies(_tu) * 1024)
#define TU_TO_EXP_TIME(_tu) (jiffies + TU_TO_JIFFIES(_tu))
/* 9.4.2.21.1, Table 9-82. */
#define IEEE80211_SPCT_MSR_RPRT_TYPE_LCI 8
#define IEEE80211_SPCT_MSR_RPRT_TYPE_CIVIC 11
/* 9.4.2.1, Table 9-77. Element IDs. */
enum ieee80211_eid {
WLAN_EID_SSID = 0,
WLAN_EID_SUPP_RATES = 1,
WLAN_EID_DS_PARAMS = 3,
WLAN_EID_TIM = 5,
WLAN_EID_COUNTRY = 7, /* IEEE80211_ELEMID_COUNTRY */
WLAN_EID_REQUEST = 10,
WLAN_EID_CHANNEL_SWITCH = 37,
WLAN_EID_MEASURE_REPORT = 39,
WLAN_EID_RSN = 48, /* IEEE80211_ELEMID_RSN */
WLAN_EID_EXT_SUPP_RATES = 50,
WLAN_EID_EXT_CHANSWITCH_ANN = 60,
WLAN_EID_EXT_CAPABILITY = 127,
WLAN_EID_VENDOR_SPECIFIC = 221,
};
/* 9.4.1.7, Table 9-45. Reason codes. */
enum ieee80211_reason_code {
/* reserved = 0, */
WLAN_REASON_UNSPECIFIED = 1,
WLAN_REASON_DEAUTH_LEAVING = 3, /* LEAVING_NETWORK_DEAUTH */
WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED = 26,
};
/* 9.4.1.9, Table 9-46. Status codes. */
enum ieee80211_status_code {
WLAN_STATUS_SUCCESS = 0,
WLAN_STATUS_AUTH_TIMEOUT = 16, /* REJECTED_SEQUENCE_TIMEOUT */
};
/* net80211: IEEE80211_IS_CTL() */
static __inline bool
ieee80211_is_ctl(__le16 fc)
{
__le16 v;
fc &= htole16(IEEE80211_FC0_TYPE_MASK);
v = htole16(IEEE80211_FC0_TYPE_CTL);
return (fc == v);
}
/* net80211: IEEE80211_IS_DATA() */
static __inline bool
ieee80211_is_data(__le16 fc)
{
__le16 v;
fc &= htole16(IEEE80211_FC0_TYPE_MASK);
v = htole16(IEEE80211_FC0_TYPE_DATA);
return (fc == v);
}
/* net80211: IEEE80211_IS_QOSDATA() */
static __inline bool
ieee80211_is_data_qos(__le16 fc)
{
__le16 v;
fc &= htole16(IEEE80211_FC0_SUBTYPE_QOS | IEEE80211_FC0_TYPE_MASK |
IEEE80211_FC0_VERSION_MASK);
v = htole16(IEEE80211_FC0_QOSDATA);
return (fc == v);
}
/* net80211: IEEE80211_IS_MGMT() */
static __inline bool
ieee80211_is_mgmt(__le16 fc)
{
__le16 v;
fc &= htole16(IEEE80211_FC0_TYPE_MASK);
v = htole16(IEEE80211_FC0_TYPE_MGT);
return (fc == v);
}
/* Derived from net80211::ieee80211_anyhdrsize. */
static __inline unsigned int
ieee80211_hdrlen(__le16 fc)
{
unsigned int size;
if (ieee80211_is_ctl(fc)) {
switch (fc & htole16(IEEE80211_FC0_SUBTYPE_MASK)) {
case htole16(IEEE80211_FC0_SUBTYPE_CTS):
case htole16(IEEE80211_FC0_SUBTYPE_ACK):
return sizeof(struct ieee80211_frame_ack);
case htole16(IEEE80211_FC0_SUBTYPE_BAR):
return sizeof(struct ieee80211_frame_bar);
}
return (sizeof(struct ieee80211_frame_min));
}
size = sizeof(struct ieee80211_frame);
if (ieee80211_is_data(fc)) {
if ((fc & htole16(IEEE80211_FC1_DIR_MASK << 8)) ==
htole16(IEEE80211_FC1_DIR_DSTODS << 8))
size += IEEE80211_ADDR_LEN;
if ((fc & htole16(IEEE80211_FC0_SUBTYPE_QOS |
IEEE80211_FC0_TYPE_MASK)) ==
htole16(IEEE80211_FC0_SUBTYPE_QOS |
IEEE80211_FC0_TYPE_DATA))
size += sizeof(uint16_t);
}
if (ieee80211_is_mgmt(fc)) {
#ifdef __notyet__
if (debug_80211 > 0)
printf("XXX-BZ %s: TODO? fc %#04x size %u\n",
__func__, fc, size);
#endif
;
}
return (size);
}
#endif /* _LINUXKPI_LINUX_IEEE80211_H */

View file

@ -0,0 +1,308 @@
/*-
* Copyright (c) 2020-2021 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _LINUXKPI_LINUX_NL80211_H
#define _LINUXKPI_LINUX_NL80211_H
#include <linux/bitops.h>
enum nl80211_feature_flags {
NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE = BIT(0),
NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES = BIT(1),
NL80211_FEATURE_HT_IBSS = BIT(2),
NL80211_FEATURE_LOW_PRIORITY_SCAN = BIT(3),
NL80211_FEATURE_ND_RANDOM_MAC_ADDR = BIT(4),
NL80211_FEATURE_P2P_GO_CTWIN = BIT(5),
NL80211_FEATURE_P2P_GO_OPPPS = BIT(6),
NL80211_FEATURE_QUIET = BIT(7),
NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR = BIT(8),
NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR = BIT(9),
NL80211_FEATURE_DYNAMIC_SMPS = BIT(10),
NL80211_FEATURE_STATIC_SMPS = BIT(11),
NL80211_FEATURE_SUPPORTS_WMM_ADMISSION = BIT(12),
NL80211_FEATURE_TDLS_CHANNEL_SWITCH = BIT(13),
NL80211_FEATURE_TX_POWER_INSERTION = BIT(14),
NL80211_FEATURE_WFA_TPC_IE_IN_PROBES = BIT(15),
};
enum nl80211_pmsr_ftm_failure_flags {
NL80211_PMSR_FTM_FAILURE_NO_RESPONSE = BIT(0),
NL80211_PMSR_FTM_FAILURE_PEER_BUSY = BIT(1),
NL80211_PMSR_FTM_FAILURE_UNSPECIFIED = BIT(2),
};
enum nl80211_pmsr_status_flags {
NL80211_PMSR_STATUS_FAILURE = BIT(0),
NL80211_PMSR_STATUS_SUCCESS = BIT(1),
NL80211_PMSR_STATUS_TIMEOUT = BIT(2),
};
#define NL80211_PMSR_TYPE_FTM 1
enum nl80211_reg_rule_flags {
NL80211_RRF_AUTO_BW = BIT(0),
NL80211_RRF_DFS = BIT(1),
NL80211_RRF_GO_CONCURRENT = BIT(2),
NL80211_RRF_NO_IR = BIT(3),
NL80211_RRF_NO_OUTDOOR = BIT(4),
NL80211_RRF_NO_HT40MINUS = BIT(5),
NL80211_RRF_NO_HT40PLUS = BIT(6),
NL80211_RRF_NO_80MHZ = BIT(7),
NL80211_RRF_NO_160MHZ = BIT(8),
NL80211_RRF_NO_HE = BIT(9),
};
#define NL80211_RRF_NO_HT40 (NL80211_RRF_NO_HT40MINUS|NL80211_RRF_NO_HT40PLUS)
enum nl80211_scan_flags {
NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME = BIT(0),
NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION = BIT(1),
NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE = BIT(2),
NL80211_SCAN_FLAG_RANDOM_ADDR = BIT(3),
NL80211_SCAN_FLAG_COLOCATED_6GHZ = BIT(4),
};
#define NL80211_REGDOM_SET_BY_USER 1
#define NL80211_REGDOM_SET_BY_DRIVER 2
#define NL80211_MAX_SUPP_REG_RULES 512 /* TODO FIXME, random */
#define NL80211_BSS_CHAN_WIDTH_20 __LINE__ /* TODO FIXME, brcmfmac */
enum nl80211_wpa_versions {
NL80211_WPA_VERSION_1 = 1,
NL80211_WPA_VERSION_2,
NL80211_WPA_VERSION_3,
};
enum nl80211_bss_select_attr {
__NL80211_BSS_SELECT_ATTR_INVALID = 0,
NL80211_BSS_SELECT_ATTR_BAND_PREF,
NL80211_BSS_SELECT_ATTR_RSSI,
NL80211_BSS_SELECT_ATTR_RSSI_ADJUST,
};
enum nl80211_sta_flag {
/* XXX TODO */
NL80211_STA_FLAG_ASSOCIATED,
NL80211_STA_FLAG_AUTHENTICATED,
NL80211_STA_FLAG_AUTHORIZED,
NL80211_STA_FLAG_TDLS_PEER,
NL80211_STA_FLAG_WME,
};
enum nl80211_band {
/* XXX TODO */
NL80211_BAND_2GHZ = 0,
NL80211_BAND_5GHZ,
NL80211_BAND_60GHZ,
NL80211_BAND_6GHZ,
/* Keep this last. */
NUM_NL80211_BANDS
};
enum nl80211_chan_flags {
/* XXX TODO */
NL80211_CHAN_NO_HT,
};
enum nl80211_chan_width {
/* XXX TODO */
NL80211_CHAN_WIDTH_20_NOHT,
NL80211_CHAN_WIDTH_20,
NL80211_CHAN_WIDTH_40,
NL80211_CHAN_WIDTH_80,
NL80211_CHAN_WIDTH_80P80,
NL80211_CHAN_WIDTH_160,
NL80211_CHAN_WIDTH_5,
NL80211_CHAN_WIDTH_10,
};
enum nl80211_iftype {
/* XXX TODO */
NL80211_IFTYPE_UNSPECIFIED,
NL80211_IFTYPE_ADHOC,
NL80211_IFTYPE_STATION,
NL80211_IFTYPE_AP,
NL80211_IFTYPE_AP_VLAN,
NL80211_IFTYPE_MONITOR,
NL80211_IFTYPE_P2P_CLIENT,
NL80211_IFTYPE_P2P_DEVICE,
NL80211_IFTYPE_P2P_GO,
NL80211_IFTYPE_MESH_POINT,
NL80211_IFTYPE_WDS,
/* Keep this last. */
NUM_NL80211_IFTYPES
};
enum nl80211_preamble {
/* XXX TODO */
NL80211_PREAMBLE_LEGACY,
NL80211_PREAMBLE_HT,
NL80211_PREAMBLE_VHT,
NL80211_PREAMBLE_HE,
};
enum nl80211_tdls_operation {
/* XXX TODO */
NL80211_TDLS_SETUP,
NL80211_TDLS_TEARDOWN,
NL80211_TDLS_ENABLE_LINK,
NL80211_TDLS_DISABLE_LINK,
NL80211_TDLS_DISCOVERY_REQ,
NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY,
NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY,
};
enum nl80211_cqm_rssi_threshold_event {
/* XXX TODO */
NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
};
enum nl80211_ext_feature {
/* XXX TODO */
NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP,
NL80211_EXT_FEATURE_BSS_PARENT_TSF,
NL80211_EXT_FEATURE_CAN_REPLACE_PTK0,
NL80211_EXT_FEATURE_DFS_OFFLOAD,
NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER,
NL80211_EXT_FEATURE_EXT_KEY_ID,
NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME,
NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER,
NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE,
NL80211_EXT_FEATURE_PROTECTED_TWT,
NL80211_EXT_FEATURE_SAE_OFFLOAD,
NL80211_EXT_FEATURE_SCAN_START_TIME,
NL80211_EXT_FEATURE_SET_SCAN_DWELL,
NL80211_EXT_FEATURE_VHT_IBSS,
NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X,
NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK,
NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT,
/* Keep this last. */
NUM_NL80211_EXT_FEATURES
};
enum nl80211_sta_info {
/* XXX TODO */
NL80211_STA_INFO_BEACON_RX,
NL80211_STA_INFO_BEACON_SIGNAL_AVG,
NL80211_STA_INFO_BSS_PARAM,
NL80211_STA_INFO_CHAIN_SIGNAL,
NL80211_STA_INFO_CONNECTED_TIME,
NL80211_STA_INFO_INACTIVE_TIME,
NL80211_STA_INFO_SIGNAL,
NL80211_STA_INFO_SIGNAL_AVG,
NL80211_STA_INFO_STA_FLAGS,
NL80211_STA_INFO_RX_BITRATE,
NL80211_STA_INFO_RX_PACKETS,
NL80211_STA_INFO_RX_BYTES,
NL80211_STA_INFO_RX_DROP_MISC,
NL80211_STA_INFO_TX_BITRATE,
NL80211_STA_INFO_TX_PACKETS,
NL80211_STA_INFO_TX_BYTES,
NL80211_STA_INFO_TX_FAILED,
};
enum nl80211_ftm_stats {
/* XXX TODO */
NL80211_FTM_STATS_ASAP_NUM,
NL80211_FTM_STATS_FAILED_NUM,
NL80211_FTM_STATS_NON_ASAP_NUM,
NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM,
NL80211_FTM_STATS_PARTIAL_NUM,
NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM,
NL80211_FTM_STATS_SUCCESS_NUM,
NL80211_FTM_STATS_TOTAL_DURATION_MSEC,
NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM,
};
enum nl80211_reg_initiator {
/* XXX TODO */
_XXX_FXIME_RTW88_USES_ENUM,
};
struct nl80211_sta_flag_update {
/* XXX TODO */
int mask, set;
};
enum nl80211_tx_power_setting {
/* XXX TODO */
NL80211_TX_POWER_AUTOMATIC,
NL80211_TX_POWER_FIXED,
NL80211_TX_POWER_LIMITED,
};
enum nl80211_crit_proto_id {
/* XXX TODO */
NL80211_CRIT_PROTO_DHCP,
};
enum nl80211_auth_type {
NL80211_AUTHTYPE_AUTOMATIC,
NL80211_AUTHTYPE_OPEN_SYSTEM,
NL80211_AUTHTYPE_SHARED_KEY,
NL80211_AUTHTYPE_SAE,
};
enum nl80211_key_type {
NL80211_KEYTYPE_GROUP,
NL80211_KEYTYPE_PAIRWISE,
};
enum nl80211_rate_info_he_ru_alloc {
NL80211_RATE_INFO_HE_RU_ALLOC_26,
NL80211_RATE_INFO_HE_RU_ALLOC_52,
NL80211_RATE_INFO_HE_RU_ALLOC_106,
NL80211_RATE_INFO_HE_RU_ALLOC_242,
NL80211_RATE_INFO_HE_RU_ALLOC_484,
NL80211_RATE_INFO_HE_RU_ALLOC_996,
NL80211_RATE_INFO_HE_RU_ALLOC_2x996,
};
enum nl80211_rate_info_he_gi {
NL80211_RATE_INFO_HE_GI_0_8,
NL80211_RATE_INFO_HE_GI_1_6,
NL80211_RATE_INFO_HE_GI_3_2,
};
enum nl80211_dfs_regions {
NL80211_DFS_UNSET,
NL80211_DFS_FCC,
NL80211_DFS_ETSI,
NL80211_DFS_JP,
};
#endif /* _LINUXKPI_LINUX_NL80211_H */

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,4 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020-2021 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,235 @@
/*-
* Copyright (c) 2020-2021 The FreeBSD Foundation
* Copyright (c) 2020-2021 Bjoern A. Zeeb
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Public functions are called linuxkpi_*().
* Internal (static) functions are called lkpi_*().
*
* The internal structures holding metadata over public structures are also
* called lkpi_xxx (usually with a member at the end called xxx).
* Note: we do not replicate the structure names but the general variable names
* for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta).
* There are macros to access one from the other.
* We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta).
*/
#ifndef _LKPI_SRC_LINUX_80211_H
#define _LKPI_SRC_LINUX_80211_H
struct lkpi_radiotap_tx_hdr {
struct ieee80211_radiotap_header wt_ihdr;
uint8_t wt_flags;
uint8_t wt_rate;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed;
#define LKPI_RTAP_TX_FLAGS_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \
(1 << IEEE80211_RADIOTAP_RATE) | \
(1 << IEEE80211_RADIOTAP_CHANNEL))
struct lkpi_radiotap_rx_hdr {
struct ieee80211_radiotap_header wr_ihdr;
uint64_t wr_tsft;
uint8_t wr_flags;
uint8_t wr_rate;
uint16_t wr_chan_freq;
uint16_t wr_chan_flags;
int8_t wr_dbm_antsignal;
int8_t wr_dbm_antnoise;
} __packed __aligned(8);
#define LKPI_RTAP_RX_FLAGS_PRESENT \
((1 << IEEE80211_RADIOTAP_TSFT) | \
(1 << IEEE80211_RADIOTAP_FLAGS) | \
(1 << IEEE80211_RADIOTAP_RATE) | \
(1 << IEEE80211_RADIOTAP_CHANNEL) | \
(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
struct lkpi_txq {
bool seen_dequeue;
struct sk_buff_head skbq;
/* Must be last! */
struct ieee80211_txq txq __aligned(CACHE_LINE_SIZE);
};
#define TXQ_TO_LTXQ(_txq) container_of(_txq, struct lkpi_txq, txq)
struct lkpi_sta {
TAILQ_ENTRY(lkpi_sta) lsta_entry;
struct ieee80211_node *ni;
/* Deferred TX path. */
/* Eventually we might want to migrate this into net80211 entirely. */
/* XXX-BZ can we use sta->txq[] instead directly? */
struct task txq_task;
struct mbufq txq;
struct mtx txq_mtx;
struct ieee80211_key_conf *kc;
enum ieee80211_sta_state state;
bool added_to_drv; /* Driver knows; i.e. we called ...(). */
bool in_mgd;
/* Must be last! */
struct ieee80211_sta sta __aligned(CACHE_LINE_SIZE);
};
#define STA_TO_LSTA(_sta) container_of(_sta, struct lkpi_sta, sta)
#define LSTA_TO_STA(_lsta) (&(_lsta)->sta)
struct lkpi_vif {
TAILQ_ENTRY(lkpi_vif) lvif_entry;
struct ieee80211vap iv_vap;
struct mtx mtx;
struct wireless_dev wdev;
/* Other local stuff. */
int (*iv_newstate)(struct ieee80211vap *,
enum ieee80211_state, int);
TAILQ_HEAD(, lkpi_sta) lsta_head;
bool added_to_drv; /* Driver knows; i.e. we called add_interface(). */
/* Must be last! */
struct ieee80211_vif vif __aligned(CACHE_LINE_SIZE);
};
#define VAP_TO_LVIF(_vap) container_of(_vap, struct lkpi_vif, iv_vap)
#define LVIF_TO_VAP(_lvif) (&(_lvif)->iv_vap)
#define VIF_TO_LVIF(_vif) container_of(_vif, struct lkpi_vif, vif)
#define LVIF_TO_VIF(_lvif) (&(_lvif)->vif)
struct lkpi_hw { /* name it mac80211_sc? */
const struct ieee80211_ops *ops;
struct ieee80211_scan_request *hw_req;
struct workqueue_struct *workq;
/* FreeBSD specific compat. */
/* Linux device is in hw.wiphy->dev after SET_IEEE80211_DEV(). */
struct ieee80211com *ic;
struct lkpi_radiotap_tx_hdr rtap_tx;
struct lkpi_radiotap_rx_hdr rtap_rx;
TAILQ_HEAD(, lkpi_vif) lvif_head;
struct mtx mtx;
/* Node functions we overload to sync state. */
struct ieee80211_node * (*ic_node_alloc)(struct ieee80211vap *,
const uint8_t [IEEE80211_ADDR_LEN]);
int (*ic_node_init)(struct ieee80211_node *);
void (*ic_node_cleanup)(struct ieee80211_node *);
void (*ic_node_free)(struct ieee80211_node *);
#define LKPI_MAC80211_DRV_STARTED 0x00000001
uint32_t sc_flags;
#define LKPI_SCAN_RUNNING 0x00000001
uint32_t scan_flags;
bool update_mc;
/* Must be last! */
struct ieee80211_hw hw __aligned(CACHE_LINE_SIZE);
};
#define LHW_TO_HW(_lhw) (&(_lhw)->hw)
#define HW_TO_LHW(_hw) container_of(_hw, struct lkpi_hw, hw)
struct lkpi_wiphy {
const struct cfg80211_ops *ops;
/* Must be last! */
struct wiphy wiphy __aligned(CACHE_LINE_SIZE);
};
#define WIPHY_TO_LWIPHY(_wiphy) container_of(_wiphy, struct lkpi_wiphy, wiphy)
#define LWIPHY_TO_WIPHY(_lwiphy) (&(_lwiphy)->wiphy)
#define LKPI_80211_LHW_LOCK(_lhw) mtx_lock(&(_lhw)->mtx)
#define LKPI_80211_LHW_UNLOCK(_lhw) mtx_unlock(&(_lhw)->mtx)
#define LKPI_80211_LHW_LOCK_ASSERT(_lhw) \
mtx_assert(&(_lhw)->mtx, MA_OWNED)
#define LKPI_80211_LHW_UNLOCK_ASSERT(_lhw) \
mtx_assert(&(_lhw)->mtx, MA_NOTOWNED)
#define LKPI_80211_LVIF_LOCK(_lvif) mtx_lock(&(_lvif)->mtx)
#define LKPI_80211_LVIF_UNLOCK(_lvif) mtx_unlock(&(_lvif)->mtx)
#define LKPI_80211_LSTA_LOCK(_lsta) mtx_lock(&(_lsta)->txq_mtx)
#define LKPI_80211_LSTA_UNLOCK(_lsta) mtx_unlock(&(_lsta)->txq_mtx)
int lkpi_80211_mo_start(struct ieee80211_hw *);
void lkpi_80211_mo_stop(struct ieee80211_hw *);
int lkpi_80211_mo_set_frag_threshold(struct ieee80211_hw *, uint32_t);
int lkpi_80211_mo_set_rts_threshold(struct ieee80211_hw *, uint32_t);
int lkpi_80211_mo_add_interface(struct ieee80211_hw *, struct ieee80211_vif *);
void lkpi_80211_mo_remove_interface(struct ieee80211_hw *, struct ieee80211_vif *);
int lkpi_80211_mo_hw_scan(struct ieee80211_hw *, struct ieee80211_vif *,
struct ieee80211_scan_request *);
void lkpi_80211_mo_cancel_hw_scan(struct ieee80211_hw *, struct ieee80211_vif *);
void lkpi_80211_mo_sw_scan_complete(struct ieee80211_hw *, struct ieee80211_vif *);
void lkpi_80211_mo_sw_scan_start(struct ieee80211_hw *, struct ieee80211_vif *,
const u8 *);
u64 lkpi_80211_mo_prepare_multicast(struct ieee80211_hw *,
struct netdev_hw_addr_list *);
void lkpi_80211_mo_configure_filter(struct ieee80211_hw *, unsigned int,
unsigned int *, u64);
int lkpi_80211_mo_sta_state(struct ieee80211_hw *, struct ieee80211_vif *,
struct ieee80211_sta *, enum ieee80211_sta_state);
int lkpi_80211_mo_config(struct ieee80211_hw *, uint32_t);
int lkpi_80211_mo_assign_vif_chanctx(struct ieee80211_hw *, struct ieee80211_vif *,
struct ieee80211_chanctx_conf *);
void lkpi_80211_mo_unassign_vif_chanctx(struct ieee80211_hw *, struct ieee80211_vif *,
struct ieee80211_chanctx_conf **);
int lkpi_80211_mo_add_chanctx(struct ieee80211_hw *, struct ieee80211_chanctx_conf *);
void lkpi_80211_mo_change_chanctx(struct ieee80211_hw *,
struct ieee80211_chanctx_conf *, uint32_t);
void lkpi_80211_mo_remove_chanctx(struct ieee80211_hw *,
struct ieee80211_chanctx_conf *);
void lkpi_80211_mo_bss_info_changed(struct ieee80211_hw *, struct ieee80211_vif *,
struct ieee80211_bss_conf *, uint32_t);
int lkpi_80211_mo_conf_tx(struct ieee80211_hw *, struct ieee80211_vif *,
uint16_t, const struct ieee80211_tx_queue_params *);
void lkpi_80211_mo_flush(struct ieee80211_hw *, struct ieee80211_vif *,
uint32_t, bool);
void lkpi_80211_mo_mgd_prepare_tx(struct ieee80211_hw *, struct ieee80211_vif *,
struct ieee80211_prep_tx_info *);
void lkpi_80211_mo_mgd_complete_tx(struct ieee80211_hw *, struct ieee80211_vif *,
struct ieee80211_prep_tx_info *);
void lkpi_80211_mo_tx(struct ieee80211_hw *, struct ieee80211_tx_control *,
struct sk_buff *);
void lkpi_80211_mo_wake_tx_queue(struct ieee80211_hw *, struct ieee80211_txq *);
void lkpi_80211_mo_sync_rx_queues(struct ieee80211_hw *);
void lkpi_80211_mo_sta_pre_rcu_remove(struct ieee80211_hw *,
struct ieee80211_vif *, struct ieee80211_sta *);
int lkpi_80211_mo_set_key(struct ieee80211_hw *, enum set_key_cmd,
struct ieee80211_vif *, struct ieee80211_sta *,
struct ieee80211_key_conf *);
#endif /* _LKPI_SRC_LINUX_80211_H */

View file

@ -0,0 +1,615 @@
/*-
* Copyright (c) 2021 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/types.h>
#include <sys/kernel.h>
#include <sys/errno.h>
#define LINUXKPI_NET80211
#include <net/mac80211.h>
#include "linux_80211.h"
int
lkpi_80211_mo_start(struct ieee80211_hw *hw)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->start == NULL) {
error = EOPNOTSUPP;
goto out;
}
if ((lhw->sc_flags & LKPI_MAC80211_DRV_STARTED)) {
/* Trying to start twice is an error. */
error = EEXIST;
goto out;
}
error = lhw->ops->start(hw);
if (error == 0)
lhw->sc_flags |= LKPI_MAC80211_DRV_STARTED;
out:
return (error);
}
void
lkpi_80211_mo_stop(struct ieee80211_hw *hw)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->stop == NULL)
return;
lhw->ops->stop(hw);
lhw->sc_flags &= ~LKPI_MAC80211_DRV_STARTED;
}
int
lkpi_80211_mo_set_frag_threshold(struct ieee80211_hw *hw, uint32_t frag_th)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->set_frag_threshold == NULL) {
error = EOPNOTSUPP;
goto out;
}
error = lhw->ops->set_frag_threshold(hw, frag_th);
out:
return (error);
}
int
lkpi_80211_mo_set_rts_threshold(struct ieee80211_hw *hw, uint32_t rts_th)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->set_rts_threshold == NULL) {
error = EOPNOTSUPP;
goto out;
}
error = lhw->ops->set_rts_threshold(hw, rts_th);
out:
return (error);
}
int
lkpi_80211_mo_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
{
struct lkpi_hw *lhw;
struct lkpi_vif *lvif;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->add_interface == NULL) {
error = EOPNOTSUPP;
goto out;
}
lvif = VIF_TO_LVIF(vif);
LKPI_80211_LVIF_LOCK(lvif);
if (lvif->added_to_drv) {
LKPI_80211_LVIF_UNLOCK(lvif);
/* Trying to add twice is an error. */
error = EEXIST;
goto out;
}
LKPI_80211_LVIF_UNLOCK(lvif);
error = lhw->ops->add_interface(hw, vif);
if (error == 0) {
LKPI_80211_LVIF_LOCK(lvif);
lvif->added_to_drv = true;
LKPI_80211_LVIF_UNLOCK(lvif);
}
out:
return (error);
}
void
lkpi_80211_mo_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
{
struct lkpi_hw *lhw;
struct lkpi_vif *lvif;
lhw = HW_TO_LHW(hw);
if (lhw->ops->remove_interface == NULL)
return;
lvif = VIF_TO_LVIF(vif);
LKPI_80211_LVIF_LOCK(lvif);
if (!lvif->added_to_drv) {
LKPI_80211_LVIF_UNLOCK(lvif);
return;
}
LKPI_80211_LVIF_UNLOCK(lvif);
lhw->ops->remove_interface(hw, vif);
LKPI_80211_LVIF_LOCK(lvif);
lvif->added_to_drv = false;
LKPI_80211_LVIF_UNLOCK(lvif);
}
int
lkpi_80211_mo_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_scan_request *sr)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->hw_scan == NULL) {
/* XXX-BZ can we hide other scans like we can for sta_add..? */
error = EOPNOTSUPP;
goto out;
}
lhw->scan_flags |= LKPI_SCAN_RUNNING;
error = lhw->ops->hw_scan(hw, vif, sr);
if (error != 0)
lhw->scan_flags &= ~LKPI_SCAN_RUNNING;
out:
return (error);
}
void
lkpi_80211_mo_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->cancel_hw_scan == NULL)
return;
lhw->ops->cancel_hw_scan(hw, vif);
}
void
lkpi_80211_mo_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->sw_scan_complete == NULL)
return;
lhw->ops->sw_scan_complete(hw, vif);
lhw->scan_flags &= ~LKPI_SCAN_RUNNING;
}
void
lkpi_80211_mo_sw_scan_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
const u8 *addr)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->sw_scan_start == NULL)
return;
lhw->ops->sw_scan_start(hw, vif, addr);
}
/*
* We keep the Linux type here; it really is an uintptr_t.
*/
u64
lkpi_80211_mo_prepare_multicast(struct ieee80211_hw *hw,
struct netdev_hw_addr_list *mc_list)
{
struct lkpi_hw *lhw;
u64 ptr;
lhw = HW_TO_LHW(hw);
if (lhw->ops->prepare_multicast == NULL)
return (0);
ptr = lhw->ops->prepare_multicast(hw, mc_list);
return (ptr);
}
void
lkpi_80211_mo_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
unsigned int *total_flags, u64 mc_ptr)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->configure_filter == NULL)
return;
if (mc_ptr == 0)
return;
lhw->ops->configure_filter(hw, changed_flags, total_flags, mc_ptr);
}
/*
* So far we only called sta_{add,remove} as an alternative to sta_state.
* Let's keep the implementation simpler and hid sta_{add,remove} under the
* hood here calling them if state_state is not available from mo_sta_state.
*/
static int
lkpi_80211_mo_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
struct lkpi_hw *lhw;
struct lkpi_sta *lsta;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->sta_add == NULL) {
error = EOPNOTSUPP;
goto out;
}
lsta = STA_TO_LSTA(sta);
if (lsta->added_to_drv) {
error = EEXIST;
goto out;
}
error = lhw->ops->sta_add(hw, vif, sta);
if (error == 0)
lsta->added_to_drv = true;
out:
return error;
}
static int
lkpi_80211_mo_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
struct lkpi_hw *lhw;
struct lkpi_sta *lsta;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->sta_remove == NULL) {
error = EOPNOTSUPP;
goto out;
}
lsta = STA_TO_LSTA(sta);
if (!lsta->added_to_drv) {
/* If we never added the sta, do not complain on cleanup. */
error = 0;
goto out;
}
error = lhw->ops->sta_remove(hw, vif, sta);
if (error == 0)
lsta->added_to_drv = false;
out:
return error;
}
int
lkpi_80211_mo_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_sta *sta, enum ieee80211_sta_state nstate)
{
struct lkpi_hw *lhw;
struct lkpi_sta *lsta;
int error;
lhw = HW_TO_LHW(hw);
lsta = STA_TO_LSTA(sta);
if (lhw->ops->sta_state != NULL) {
error = lhw->ops->sta_state(hw, vif, sta, lsta->state, nstate);
if (error == 0) {
if (nstate == IEEE80211_STA_NOTEXIST)
lsta->added_to_drv = false;
else
lsta->added_to_drv = true;
lsta->state = nstate;
}
goto out;
}
/* XXX-BZ is the change state AUTH or ASSOC here? */
if (lsta->state < IEEE80211_STA_ASSOC && nstate == IEEE80211_STA_ASSOC)
error = lkpi_80211_mo_sta_add(hw, vif, sta);
else if (lsta->state >= IEEE80211_STA_ASSOC &&
nstate < IEEE80211_STA_ASSOC)
error = lkpi_80211_mo_sta_remove(hw, vif, sta);
else
/* Nothing to do. */
error = 0;
out:
/* XXX-BZ should we manage state in here? */
return (error);
}
int
lkpi_80211_mo_config(struct ieee80211_hw *hw, uint32_t changed)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->config == NULL) {
error = EOPNOTSUPP;
goto out;
}
error = lhw->ops->config(hw, changed);
out:
return (error);
}
int
lkpi_80211_mo_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_chanctx_conf *chanctx_conf)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->assign_vif_chanctx == NULL) {
error = EOPNOTSUPP;
goto out;
}
error = lhw->ops->assign_vif_chanctx(hw, vif, chanctx_conf);
if (error == 0)
vif->chanctx_conf = chanctx_conf;
out:
return (error);
}
void
lkpi_80211_mo_unassign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_chanctx_conf **chanctx_conf)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->unassign_vif_chanctx == NULL)
return;
if (*chanctx_conf == NULL)
return;
lhw->ops->unassign_vif_chanctx(hw, vif, *chanctx_conf);
*chanctx_conf = NULL;
}
int
lkpi_80211_mo_add_chanctx(struct ieee80211_hw *hw,
struct ieee80211_chanctx_conf *chanctx_conf)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->add_chanctx == NULL) {
error = EOPNOTSUPP;
goto out;
}
error = lhw->ops->add_chanctx(hw, chanctx_conf);
out:
return (error);
}
void
lkpi_80211_mo_change_chanctx(struct ieee80211_hw *hw,
struct ieee80211_chanctx_conf *chanctx_conf, uint32_t changed)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->change_chanctx == NULL)
return;
lhw->ops->change_chanctx(hw, chanctx_conf, changed);
}
void
lkpi_80211_mo_remove_chanctx(struct ieee80211_hw *hw,
struct ieee80211_chanctx_conf *chanctx_conf)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->remove_chanctx == NULL)
return;
lhw->ops->remove_chanctx(hw, chanctx_conf);
}
void
lkpi_80211_mo_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_bss_conf *conf, uint32_t changed)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->bss_info_changed == NULL)
return;
lhw->ops->bss_info_changed(hw, vif, conf, changed);
}
int
lkpi_80211_mo_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
uint16_t ac, const struct ieee80211_tx_queue_params *txqp)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->conf_tx == NULL) {
error = EOPNOTSUPP;
goto out;
}
error = lhw->ops->conf_tx(hw, vif, ac, txqp);
out:
return (error);
}
void
lkpi_80211_mo_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
uint32_t nqueues, bool drop)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->flush == NULL)
return;
lhw->ops->flush(hw, vif, nqueues, drop);
}
void
lkpi_80211_mo_mgd_prepare_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_prep_tx_info *txinfo)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->mgd_prepare_tx == NULL)
return;
lhw->ops->mgd_prepare_tx(hw, vif, txinfo);
}
void
lkpi_80211_mo_mgd_complete_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_prep_tx_info *txinfo)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->mgd_complete_tx == NULL)
return;
lhw->ops->mgd_complete_tx(hw, vif, txinfo);
}
void
lkpi_80211_mo_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *txctrl,
struct sk_buff *skb)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->tx == NULL)
return;
lhw->ops->tx(hw, txctrl, skb);
}
void
lkpi_80211_mo_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->wake_tx_queue == NULL)
return;
lhw->ops->wake_tx_queue(hw, txq);
}
void
lkpi_80211_mo_sync_rx_queues(struct ieee80211_hw *hw)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->sync_rx_queues == NULL)
return;
lhw->ops->sync_rx_queues(hw);
}
void
lkpi_80211_mo_sta_pre_rcu_remove(struct ieee80211_hw *hw,
struct ieee80211_vif *vif, struct ieee80211_sta *sta)
{
struct lkpi_hw *lhw;
lhw = HW_TO_LHW(hw);
if (lhw->ops->sta_pre_rcu_remove == NULL)
return;
lhw->ops->sta_pre_rcu_remove(hw, vif, sta);
}
int
lkpi_80211_mo_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
struct ieee80211_vif *vif, struct ieee80211_sta *sta,
struct ieee80211_key_conf *kc)
{
struct lkpi_hw *lhw;
int error;
lhw = HW_TO_LHW(hw);
if (lhw->ops->set_key == NULL) {
error = EOPNOTSUPP;
goto out;
}
error = lhw->ops->set_key(hw, cmd, vif, sta, kc);
out:
return (error);
}

View file

@ -4526,6 +4526,10 @@ nlm/nlm_prot_xdr.c optional nfslockd | nfsd
nlm/sm_inter_xdr.c optional nfslockd | nfsd
# Linux Kernel Programming Interface
compat/linuxkpi/common/src/linux_80211.c optional compat_linuxkpi wlan \
compile-with "${LINUXKPI_C}"
compat/linuxkpi/common/src/linux_80211_macops.c optional compat_linuxkpi wlan \
compile-with "${LINUXKPI_C}"
compat/linuxkpi/common/src/linux_kmod.c optional compat_linuxkpi \
compile-with "${LINUXKPI_C}"
compat/linuxkpi/common/src/linux_acpi.c optional compat_linuxkpi acpi \

View file

@ -211,6 +211,7 @@ SUBDIR= \
libmchain \
lindebugfs \
linuxkpi \
linuxkpi_wlan \
${_lio} \
lpt \
mac_biba \

View file

@ -0,0 +1,15 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/compat/linuxkpi/common/src
KMOD= linuxkpi_wlan
SRCS= linux_80211.c \
linux_80211_macops.c
SRCS+= opt_wlan.h
SRCS+= ${LINUXKPI_GENSRCS}
CFLAGS+= -I${SRCTOP}/sys/compat/linuxkpi/common/include
EXPORT_SYMS= YES
.include <bsd.kmod.mk>