IEEE80211(9)
π IEEE80211 β the 802.11 network layer π
okay bestie, welcome to IEEE80211(9) from the Kernel Developer's Manual, aka the group chat where all your wireless drivers come to hang out. this is part one, we're just getting started, no sign-off, we have so much to cover π¦
β¨ NAME β¨
IEEE80211 β the 802.11 network layer. yes that's the whole thing, it's giving humble but it runs your wifi π
πΈ SYNOPSIS πΈ
#include <net80211/ieee80211_var.h>
void
ieee80211_ifattach(struct ieee80211com *ic);
void
ieee80211_ifdetach(struct ieee80211com *ic);
int
ieee80211_mhz2ieee(u_int freq, u_int flags);
int
ieee80211_chan2ieee(struct ieee80211com *ic,
const struct ieee80211_channel *c);
u_int
ieee80211_ieee2mhz(u_int chan, u_int flags);
int
ieee80211_media_change(struct ifnet *ifp);
void
ieee80211_media_status(struct ifnet *ifp, struct ifmediareq *imr);
int
ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode);
enum ieee80211_phymode
ieee80211_chan2mode(const struct ieee80211_channel *chan);
int
ieee80211_rate2media(struct ieee80211com *ic, int rate,
enum ieee80211_phymode mode);
int
ieee80211_media2rate(int mword);
π DESCRIPTION π
so here's the tea π: 802.11 device drivers are written to use the infrastructure that the IEEE80211 software layer provides. this software is basically the support framework for drivers β it handles ifnet cloning, state management, and a user management API so that applications can talk to 802.11 devices. most drivers lean on the IEEE80211 layer for protocol services, but devices that off-load functionality may bypass the layer and connect directly to the device instead (like, for example, the ndis(4) emulation support does exactly that π).
an IEEE80211 device driver implements a virtual radio API that gets exported to users through network interfaces (aka vaps) that are cloned from the underlying device. these interfaces have an operating mode (station, adhoc, hostap, wds, monitor, etc.) and that mode is fixed for the lifetime of the interface β no take-backs, it is what it is π. devices that can support multiple concurrent interfaces let you clone multiple vaps, which unlocks some genuinely iconic applications like an AP vap plus one or more WDS vaps, or multiple AP vaps each with a different security model. main character energy fr fr.
the IEEE80211 layer virtualizes most 802.11 state and coordinates vap state changes, including scheduling multiple vaps. state that is not virtualized includes the current channel and WME/WMM parameters. protocol processing is typically handled entirely in the IEEE80211 layer, with drivers responsible purely for moving data between the host and device. similarly, IEEE80211 handles most ioctl(2) requests without ever entering the driver; instead, drivers get notified of state changes that actually require their involvement.
because the virtual radio interface is defined by the IEEE80211 layer, drivers must be structured to follow specific rules. and yes, even drivers that support only a single interface at any time still have to follow these rules β no exceptions, bestie π«Ά.
most of these functions require that attachment to the stack is performed before calling. do that first or things get weird.
okay now let's go function by function, stay with me:
- the
ieee80211_ifattach()function attaches the wireless network interfaceicto the 802.11 network stack layer. this one must be called before using any of theIEEE80211functions that need to store driver state across invocations. it's the "hi nice to meet you" of the whole relationship β¨ - the
ieee80211_ifdetach()function frees anyIEEE80211structures associated with the driver, and it performs Ethernet and BPF detachment on behalf of the caller. it's the "ok bye" π - the
ieee80211_mhz2ieee()utility function converts the frequencyfreq(specified in MHz) to an IEEE 802.11 channel number. theflagsargument is a hint that says whether the frequency is in the 2GHz ISM band (IEEE80211_CHAN_2GHZ) or the 5GHz band (IEEE80211_CHAN_5GHZ); appropriate clipping of the result is then performed. - the
ieee80211_chan2ieee()function converts the channel specified in*cto an IEEE channel number for the driveric. if the conversion would be invalid, an error message gets printed to the system console. this function REQUIRES that the driver is hooked up to theIEEE80211subsystem β no hookup, no vibes π - the
ieee80211_ieee2mhz()utility function converts the IEEE channel numberchanto a frequency (in MHz). theflagsargument is a hint that says whether the frequency is in the 2GHz ISM band (IEEE80211_CHAN_2GHZ) or the 5GHz band (IEEE80211_CHAN_5GHZ); appropriate clipping of the result is then performed. it's the reverse glow-up ofieee80211_mhz2ieee()π¦ - the
ieee80211_media_status()andieee80211_media_change()functions are device-independent handlers for ifmedia commands, and they are not intended to be called directly. hands off, they're doing their own thing π - the
ieee80211_setmode()function is called from within the 802.11 stack to change the mode of the driver's PHY; it is not intended to be called directly either. internal business only π - the
ieee80211_chan2mode()function returns the PHY mode required for use with the channelchan. this is typically used when selecting a rate set β to be advertised in beacons, for example. - the
ieee80211_rate2media()function converts the bit raterate(measured in units of 0.5Mbps) to an ifmedia sub-type, for the deviceicrunning in PHY modemode. and theieee80211_media2rate()function performs the reverse of this conversion, returning the bit rate (in 0.5Mbps units) corresponding to an ifmedia sub-type. they're a matched set, a duo, iconic β
π DATA STRUCTURES π
the virtual radio architecture splits state between a single per-device ieee80211com structure and one or more ieee80211vap structures. drivers are expected to set up various shared state in these structures at device attach and during vap creation, but otherwise they should treat them as read-only β look, don't touch, bestie π
- the
ieee80211comstructure is allocated by theIEEE80211layer as adjunct data to a device's ifnet; you access it through theif_l2comstructure member. - the
ieee80211vapstructure is allocated by the driver in the βvap createβ method, and it should be extended with any driver-private state.
this technique of giving the driver control to allocate data structures is used for other IEEE80211 data structures too, and you should absolutely exploit it to keep driver-private state together with public IEEE80211 state. it's a whole system, it's cute π
the other main data structures are:
- the station, or node, table, which tracks peers in the local BSS
- the channel table, which defines the current set of available radio channels
both tables are bound to the ieee80211com structure and shared by all vaps. long-lasting references to a node are counted to guard against premature reclamation β specifically, every packet sent/received holds a node reference (either explicitly for transmit or implicitly on receive). protect the node, protect the vibe π₯
the ieee80211com and ieee80211vap structures also hold a collection of method pointers that drivers fill in and/or override to take control of certain operations. these methods are the primary way drivers are bound to the IEEE80211 layer, and they're described below. lowkey the most important part, stay tuned β¨
okay that's part one, we are NOT done, more is coming, don't go anywhere π
π DRIVER ATTACH/DETACH π
okay so bestie, this is where your driver and the IEEE80211 layer become official π. Drivers attach with the ieee80211_ifattach() function, and here's the tea: your driver is expected to allocate and set up all its device-private data structures before handing over control. No pressure, just do it first.
The ieee80211com structure has to be pre-initialized with the state needed to set up the IEEE80211 layer, and that means these four things:
ic_ifpβ a backpointer to the physical device'sifnet. it's giving "who's your parent" energy.ic_capsβ the device/driver capabilities. full description below, don't skip it β¨ic_channelsβ the table of channels your device can operate on. the driver provides this at first, but it can change later through calls that change the regulatory state. so it's not forever-locked, bestie.ic_nchanβ the number of entries inic_channels. count them, queen π
On the way back from ieee80211_ifattach(), the driver is expected to override the default callback functions in the ieee80211com structure to register its private routines. And heads up: methods marked with a * must be provided by the driver. mandatory. no skips. π¨
ic_vap_create* β create a vap instance of the specified type (aka the operating mode). any fixed BSSID and/or MAC address gets provided. drivers that support multi-bssid operation may honor the requested BSSID or assign their own β their choice, their vibes.ic_vap_delete* β destroy a vap instance that was created withic_vap_create. bye bestie πic_getradiocapsβ return the list of calibrated channels for the radio. the default method returns the current list of channels (space permitting).ic_setregdomainβ process a request to change regulatory state. this routine may reject a request or constrain changes (like reducing transmit power caps). the default method accepts all proposed changes β yes, all of them, no questions.ic_send_mgmtβ send an 802.11 management frame. the default method fabricates the frame using IEEE80211 state and passes it to the driver through theic_raw_xmitmethod.ic_raw_xmitβ transmit a raw 802.11 frame. the default method just drops the frame and generates a message on the console π (rip frame).ic_updateslotβ update hardware state after an 802.11 IFS slot time change. there is no default method; the pointer may beNULL, in which case it just won't be used.ic_update_mcastβ update hardware for a change in the multicast packet filter. the default method prints a console message.ic_update_promiscβ update hardware for a change in the promiscuous mode setting. the default method prints a console message.ic_newassocβ update driver/device state for association to a new AP (in station mode) or when a new station associates (like in AP mode). there is no default method; the pointer may beNULL, in which case it won't be used.ic_node_allocβ allocate and initialize aieee80211_nodestructure. bestie, this method cannot sleep. the default method allocates zero'd memory usingmalloc(9). drivers should override this method to allocate extended storage for their own needs. and memory allocated by the driver must be tagged withM_80211_NODEto balance the memory allocation statistics. don't forget the tag, i'm begging π₯Ίic_node_freeβ reclaim storage of a node allocated byic_node_alloc. drivers are expected to interpose their own method to clean up private state, but they must call through this method so IEEE80211 can reclaim its private state. call through, bestie, it's the rule.ic_node_cleanupβ clean up state in aieee80211_nodecreated byic_node_alloc. this is different fromic_node_freebecause it may be called long before the node is actually reclaimed, just to clean up adjunct state. this can happen, for example, when a node must not be reclaimed due to references held by packets in the transmit queue. drivers typically interposeic_node_cleanupinstead ofic_node_free.ic_node_ageβ age, and potentially reclaim, resources associated with a node. the default method ages frames on the power-save queue (in AP mode) and pending frames in the receive reorder queues (for stations using A-MPDU).ic_node_drainβ reclaim all optional resources associated with a node. this call is used to free up resources when they're in short supply. scarcity era πic_node_getrssiβ return the Receive Signal Strength Indication (RSSI) in.5dBm units for the specified node. this interface returns a subset of the info returned byic_node_getsignal. the default method calculates a filtered average over the last ten samples passed in toieee80211_input(9)orieee80211_input_all(9).ic_node_getsignalβ return the RSSI and noise floor (in.5dBm units) for a station. the default method calculates RSSI as described above; the noise floor returned is the last value supplied toieee80211_input(9)orieee80211_input_all(9).ic_node_getmimoinfoβ return MIMO radio state for a station in support of theIEEE80211_IOC_STA_INFOioctl request. the default method returns nothing. literally nothing. the void πic_scan_start* β prepare driver/hardware state for scanning. this callback is done in a sleepable context.ic_scan_end* β restore driver/hardware state after scanning completes. this callback is done in a sleepable context.ic_set_channel* β set the current radio channel usingic_curchan. this callback is done in a sleepable context.ic_scan_curchanβ start scanning on a channel. this method is called immediately after each channel change and must initiate the work to scan a channel and schedule a timer to advance to the next channel in the scan list. this callback is done in a sleepable context. the default method handles active scan work (like sending ProbeRequest frames), and schedules a call toieee80211_scan_next(9)according to the maximum dwell time for the channel. drivers that off-load scan work to firmware typically use this method to trigger per-channel scan activity.ic_scan_mindwellβ handle reaching the minimum dwell time on a channel while scanning. this event triggers when one or more stations have been found on a channel and the minimum dwell time has been reached. this callback is done in a sleepable context. the default method signals the scan machinery to advance to the next channel ASAP. drivers can use this method to preempt further work (like if scanning is handled by firmware) or ignore the request to force maximum dwell time on a channel.ic_recv_actionβ process a received Action frame. the default method points toieee80211_recv_action(9), which provides a mechanism for setting up handlers for each Action frame class.ic_send_actionβ transmit an Action frame. the default method points toieee80211_send_action(9), which provides a mechanism for setting up handlers for each Action frame class.ic_ampdu_enableβ check if transmit A-MPDU should be enabled for the specified station and AC. the default method checks a per-AC traffic rate against a per-vap threshold to decide if A-MPDU should be enabled. this method also rate-limits ADDBA requests so requests aren't made too frequently when a receiver has limited resources.ic_addba_requestβ request A-MPDU transmit aggregation. the default method sets up local state and issues an ADDBA Request Action frame. drivers may interpose this method if they need to set up private state for handling transmit A-MPDU.ic_addb_responseβ process a received ADDBA Response Action frame and set up resources as needed for doing transmit A-MPDU.ic_addb_stopβ shut down an A-MPDU transmit stream for the specified station and AC. the default method reclaims local state after sending a DelBA Action frame.ic_bar_responseβ process a response to a transmitted BAR control frame.ic_ampdu_rx_startβ prepare to receive A-MPDU data from the specified station for the TID.ic_ampdu_rx_stopβ terminate receipt of A-MPDU data from the specified station for the TID.
okay once the IEEE80211 layer is attached to a driver, there are two more steps typically done to finish the job:
- Set up "radiotap support" for capturing raw 802.11 packets that pass through the device. this is done with a call to
ieee80211_radiotap_attach(9). - Do any final device setup, like enabling interrupts. β‘
State gets torn down and reclaimed with a call to ieee80211_ifdetach(). and bestie, listen: this call may result in multiple callbacks into the driver, so it should be done before any critical driver state is reclaimed. on the way back from ieee80211_ifdetach(), all associated vaps and ifnet structures are reclaimed or inaccessible to user applications, so it's safe to tear down driver state without worrying about being re-entered. the driver is responsible for calling if_free(9) on the ifnet it allocated for the physical device. that one's on you π«Ά
β¨ DRIVER CAPABILITIES β¨
okay bestie so here's the tea π
your driver tells the world what it can do by flipping a bunch of flags in the ieee80211com structure. Different flag buckets for different vibes:
ic_capsβ the general, all-purpose capabilities. the main character bucket πic_cryptocapsβ hardware crypto capabilities, i.e. your device doing cipher math in silicon instead of making the CPU cry πic_htcapsβ the 802.11n capabilities, if your device even has any.
and then the IEEE80211 layer is like a little fairy godmother π§ and propagates a subset of those up to every vap, through the matching fields: iv_caps, iv_cryptocaps, and iv_htcaps. so every vap knows what it's working with.
π the general capabilities (ic_caps)
IEEE80211_C_STAβ device can do station mode, aka Infrastructure mode. the classic. π«ΆIEEE80211_C_8023ENCAPβ device wants frames handed to it already wrapped up in 802.3 encapsulation for transmit. by default IEEE80211 wraps everything outbound as 802.11 frames (no PLCP header, just fyi).IEEE80211_C_FFβ device supports Atheros Fast-Frames. zoom zoom π₯IEEE80211_C_TURBOPβ device supports Atheros Dynamic Turbo mode. yes it's literally called Turbo. iconic.IEEE80211_C_IBSSβ device can do adhoc/IBSS mode.IEEE80211_C_PMGTβ device supports dynamic power-management (aka power save) while in station mode. naptime but make it protocol-compliant π΄IEEE80211_C_HOSTAPβ device can operate as an Access Point in Infrastructure mode. it's giving hostess with the mostest πIEEE80211_C_AHDEMOβ device can do Adhoc Demo mode. in this mode the device is used purely to send and receive raw 802.11 frames. no notes, just vibes.IEEE80211_C_SWRETRYβ device supports software retry of frames it transmitted. if at first you don't succeed πIEEE80211_C_TXPMGTβ device supports dynamic transmit power changes on transmitted frames, also known as Transmit Power Control (TPC).IEEE80211_C_SHSLOTβ device supports short slot time operation (that's an 802.11g thing).IEEE80211_C_SHPREAMBLEβ device supports short preamble operation (also 802.11g).IEEE80211_C_MONITORβ device can operate in monitor mode. π the eavesdropping girlies stay winningIEEE80211_C_DFSβ device supports radar detection and/or DFS. the DFS protocol support can be handled by IEEE80211 itself, but listen: the device must be capable of detecting radar events. that part is non-negotiable bestie.IEEE80211_C_MBSSβ device can operate in MeshBSS (MBSS) mode, as defined by 802.11s Draft 3.0.IEEE80211_C_WPA1β device supports WPA1 operation.IEEE80211_C_WPA2β device supports WPA2/802.11i operation.IEEE80211_C_BURSTβ device supports frame bursting.IEEE80211_C_WMEβ device supports WME/WMM operation. at the moment this is mostly just support for sending and receiving QoS frames with EDCF. we love a modest feature β¨IEEE80211_C_WDSβ device supports transmit/receive of 4-address frames.IEEE80211_C_BGSCANβ device supports background scanning. multitasking queen πIEEE80211_C_TXFRAGβ device supports transmit of fragmented 802.11 frames.IEEE80211_C_TDMAβ device can operate in TDMA mode.
π crypto capabilities (ic_cryptocaps)
so these are the general crypto capabilities, and here's the important bit: in general, IEEE80211 will fall back to software support whenever a device can't hardware-accelerate a given cipher. and it can do that fallback on a per-key basis, which is honestly so flexible of it. IEEE80211 can also handle software Michael calculation while the hardware does AES acceleration β a little collab π€
IEEE80211_CRYPTO_WEPβ device supports hardware WEP cipher.IEEE80211_CRYPTO_TKIPβ device supports hardware TKIP cipher.IEEE80211_CRYPTO_AES_OCBβ device supports hardware AES-OCB cipher.IEEE80211_CRYPTO_AES_CCMβ device supports hardware AES-CCM cipher.IEEE80211_CRYPTO_TKIPMICβ device supports hardware Michael, for use with TKIP.IEEE80211_CRYPTO_CKIPβ device supports hardware CKIP cipher. (yes the original says "Devices supports", we're not touching it, it's part of the lore π)
π‘ 802.11n capabilities (ic_htcaps)
the general 802.11n capabilities live here. heads up: the first batch are defined exactly as they appear in the 802.11n specification. and everything starting from IEEE80211_HTC_AMPDU is used solely by the IEEE80211 layer itself β so don't go thinking those are spec flags, bestie.
IEEE80211_HTCAP_CHWIDTH40β device supports 20/40 channel width operation.IEEE80211_HTCAP_SMPS_DYNAMICβ device supports dynamic SM power save operation.IEEE80211_HTCAP_SMPS_ENAβ device supports static SM power save operation.IEEE80211_HTCAP_GREENFIELDβ device supports Greenfield preamble. πΏIEEE80211_HTCAP_SHORTGI20β device supports Short Guard Interval on 20MHz channels.IEEE80211_HTCAP_SHORTGI40β device supports Short Guard Interval on 40MHz channels.IEEE80211_HTCAP_TXSTBCβ device supports Space Time Block Convolution (STBC) for transmit.IEEE80211_HTCAP_RXSTBC_1STREAMβ device supports 1 spatial stream for STBC receive.IEEE80211_HTCAP_RXSTBC_2STREAMβ device supports 1-2 spatial streams for STBC receive.IEEE80211_HTCAP_RXSTBC_3STREAMβ device supports 1-3 spatial streams for STBC receive.IEEE80211_HTCAP_MAXAMSDU_7935β device supports A-MSDU frames up to 7935 octets.IEEE80211_HTCAP_MAXAMSDU_3839β device supports A-MSDU frames up to 3839 octets.IEEE80211_HTCAP_DSSSCCK40β device supports use of DSSS/CCK on 40MHz channels.IEEE80211_HTCAP_PSMPβ device supports PSMP.IEEE80211_HTCAP_40INTOLERANTβ device is intolerant of 40MHz wide channel use. it said what it said π€IEEE80211_HTCAP_LSIGTXOPPROTβ device supports L-SIG TXOP protection.IEEE80211_HTC_AMPDUβ device supports A-MPDU aggregation. note that any 802.11n compliant device must support A-MPDU receive, so this implicitly means support for transmit of A-MPDU frames too.IEEE80211_HTC_AMSDUβ device supports A-MSDU aggregation. same deal: any 802.11n compliant device must support A-MSDU receive, so this implicitly means support for transmit of A-MSDU frames.IEEE80211_HTC_HTβ device supports High Throughput (HT) operation. β οΈ this capability must be set to enable 802.11n functionality in IEEE80211. like, mandatory mandatory. no HT flag, no HT, periodt.IEEE80211_HTC_SMPSβ device supports MIMO Power Save operation.IEEE80211_HTC_RIFSβ device supports Reduced Inter Frame Spacing (RIFS).
π«Ά SEE ALSO
ioctl(2), ndis(4), ieee80211_amrr(9), ieee80211_beacon(9), ieee80211_bmiss(9), ieee80211_crypto(9), ieee80211_ddb(9), ieee80211_input(9), ieee80211_node(9), ieee80211_output(9), ieee80211_proto(9), ieee80211_radiotap(9), ieee80211_regdomain(9), ieee80211_scan(9), ieee80211_vap(9), ifnet(9), malloc(9)
π HISTORY
the IEEE80211 series of functions first appeared in NetBSD 1.5, and were later ported to FreeBSD 4.6. this man page was updated with the information from the NetBSD IEEE80211 man page. a glow-up, if you will β¨
π AUTHORS
the original NetBSD IEEE80211 man page was written by Bruce M. Simpson <bms@FreeBSD.org> and Darron Broad <darron@kewl.org>. legends, honestly, we stan π
and that's the whole page bestie!! πΈ this one came from the Debian crew and it's dated December 31, 2017 β yeah, a New Year's Eve man page, absolute main character energy π₯π go forth and configure your wireless, you've got this π β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2004 Bruce M. Simpson <bms@spc.org>
- Copyright (c) 2004 Darron Broad <darron@kewl.org>
- Copyright (c) 2009 Sam Leffler, Errno Consulting
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms