1*490c53e9SAdrian Chadd# net80211 Datapath - Transmit 2*490c53e9SAdrian Chadd 3*490c53e9SAdrian Chadd## Overview 4*490c53e9SAdrian Chadd 5*490c53e9SAdrian ChaddThis document provides an overview for the transmit data path in 6*490c53e9SAdrian Chaddnet80211, between the interface to the operating system, through net80211 and 7*490c53e9SAdrian Chaddinto the driver. 8*490c53e9SAdrian Chadd 9*490c53e9SAdrian ChaddThe details about underlying implementations (eg how A-MPDU RX aggregation 10*490c53e9SAdrian Chaddis handled) will be covered in dedicated documents. 11*490c53e9SAdrian Chadd 12*490c53e9SAdrian Chadd## Concurrency Notes 13*490c53e9SAdrian Chadd 14*490c53e9SAdrian ChaddThe transmit path(s), receive path and control / ioctl paths all run 15*490c53e9SAdrian Chaddin parallel and can be scheduled on multiple concurrently running 16*490c53e9SAdrian Chaddkernel threads. It's important to keep this in mind. 17*490c53e9SAdrian Chadd 18*490c53e9SAdrian Chadd## Transmit Path 19*490c53e9SAdrian Chadd 20*490c53e9SAdrian ChaddThere are two paths from the operating system layer into the net80211 transmit 21*490c53e9SAdrian Chaddpath - the normal data path and the BPF / radiotap raw frame path. 22*490c53e9SAdrian Chadd 23*490c53e9SAdrian ChaddIt is important to note that both paths have no serialisation between 24*490c53e9SAdrian Chaddthem, and multiple sending paths in the OS can and will queue frames 25*490c53e9SAdrian Chaddsimultaneously across multiple concurrently executing threads/CPUs. 26*490c53e9SAdrian ChaddPlease keep this in mind when reading the transmit handling and 27*490c53e9SAdrian Chaddhow it interacts with 802.11 sequence numbering and encryption IV. 28*490c53e9SAdrian Chadd 29*490c53e9SAdrian Chadd### Data Path - net80211 30*490c53e9SAdrian Chadd 31*490c53e9SAdrian ChaddThis is configured at the ifnet setup in ieee80211_vap_setup() - 32*490c53e9SAdrian Chaddthe output path is ieee80211_vap_transmit(). This input path 33*490c53e9SAdrian Chaddtakes 802.3 ethernet frames with no attached metadata (such as 34*490c53e9SAdrian Chaddrate control, transmit power, etc) - it is left up to the stack. 35*490c53e9SAdrian Chadd 36*490c53e9SAdrian ChaddThis hands the packet off to ieee80211_start_pkt() which will 37*490c53e9SAdrian Chaddperform the initial 802.11 destination lookup, query the node 38*490c53e9SAdrian Chaddstate (eg whether it's in power save) and the VAP state (eg 39*490c53e9SAdrian Chaddis the vap itself in power state, or in a non-RUN state) 40*490c53e9SAdrian Chaddand drop or queue the frame appropriately. 41*490c53e9SAdrian Chadd 42*490c53e9SAdrian ChaddIt is then handed over to ieee80211_vap_pkt_send_dest() with 43*490c53e9SAdrian Chadda destination ieee80211_node reference. 44*490c53e9SAdrian Chadd 45*490c53e9SAdrian Chaddieee80211_vap_pkt_send_dest() performs the bulk of the 46*490c53e9SAdrian Chaddnet80211 transmit handling. Packets will be queued here if the 47*490c53e9SAdrian Chadddestination node is in a power saving mode. 48*490c53e9SAdrian Chadd 49*490c53e9SAdrian ChaddThis includes: 50*490c53e9SAdrian Chadd 51*490c53e9SAdrian Chadd * Firstly - checking if the packet needs to be queued for 52*490c53e9SAdrian Chadd power saving operation and will pass it via ieee80211_pwrsave() 53*490c53e9SAdrian Chadd if needed; 54*490c53e9SAdrian Chadd * QoS classification via a call to ieee80211_classify(); 55*490c53e9SAdrian Chadd * BPF TX tap via a call to BPF_MTAP(); 56*490c53e9SAdrian Chadd * handling 802.11 encapsulation via ieee80211_encap() if required; 57*490c53e9SAdrian Chadd * A-MPDU TX decisions, AMSDU and Atheros Fast-Frames decisions. 58*490c53e9SAdrian Chadd 59*490c53e9SAdrian ChaddAt this point the packet has been 802.11 encapsulated if required, 60*490c53e9SAdrian Chaddmarked as needing encryption if required, and has been optionally 61*490c53e9SAdrian Chaddfragmented into a list of 802.11 fragments. 62*490c53e9SAdrian Chadd 63*490c53e9SAdrian ChaddFinally, the packet / fragment packet chain is sent up to the driver via a call 64*490c53e9SAdrian Chaddto ieee80211_parent_xmitpkt(). The driver is expected to queue the 65*490c53e9SAdrian Chaddpacket / fragment list or discard the packet / fragment list. The specific 66*490c53e9SAdrian Chaddformat of the mbuf chain and how ieee80211_node references are kept 67*490c53e9SAdrian Chaddis documented in ieee80211_parent_xmitpkt(). 68*490c53e9SAdrian Chadd 69*490c53e9SAdrian Chadd#### Notes on transmit path serialisation 70*490c53e9SAdrian Chadd 71*490c53e9SAdrian ChaddNote that by default the IEEE80211_TX_LOCK() is held across the call to 72*490c53e9SAdrian Chaddieee80211_encap() and ieee80211_parent_xmitpkt(). Drivers can register 73*490c53e9SAdrian Chaddthat they properly handle 802.11 sequence number offloading via 74*490c53e9SAdrian ChaddIEEE80211_FEXT_SEQNO_OFFLOAD. The lock is to ensure that packets 75*490c53e9SAdrian Chaddqueued to the driver layer are added to the driver transmit queue 76*490c53e9SAdrian Chaddin the same order that they are 802.11 encapsulated - which sets the 77*490c53e9SAdrian Chadd802.11 sequence number. Drivers which set IEEE80211_FEXT_SEQNO_OFFLOAD 78*490c53e9SAdrian Chaddindicate that they will assign the sequence number themselves - likely 79*490c53e9SAdrian Chaddat the same time that the transmit encryption IV number is assigned, 80*490c53e9SAdrian Chaddor simply offloaded in firmware - and thus this lock is not 81*490c53e9SAdrian Chaddrequired. 82*490c53e9SAdrian Chadd 83*490c53e9SAdrian Chadd### Data path - Driver 84*490c53e9SAdrian Chadd 85*490c53e9SAdrian ChaddThe call ieee80211_parent_xmit() will call the driver ic->ic_transmit() 86*490c53e9SAdrian Chaddmethod. At this point the driver can choose to queue / send the frame 87*490c53e9SAdrian Chadd(and take ownership of it), or return an error, and return it back 88*490c53e9SAdrian Chaddto net80211. Currently net80211 will just free the mbuf and node reference 89*490c53e9SAdrian Chaddand return, but drivers should not assume that. 90*490c53e9SAdrian Chadd 91*490c53e9SAdrian ChaddThe mbuf passed in will be either a single 802.11/802.3 frame in an mbuf, 92*490c53e9SAdrian Chaddor a list of 802.11 fragments chained by m->m_nextpkt. If the driver 93*490c53e9SAdrian Chaddhas not set IEEE80211_FEXT_SEQNO_OFFLOAD then the packet will have 94*490c53e9SAdrian Chadda sequence number assigned which the driver can fetch via M_SEQNO_GET(). 95*490c53e9SAdrian ChaddThe mbuf also holds an ieee80211_node reference. 96*490c53e9SAdrian Chadd 97*490c53e9SAdrian Chadd(Note that fragments do not have sequence numbers assigned nor node 98*490c53e9SAdrian Chaddreferences.) 99*490c53e9SAdrian Chadd 100*490c53e9SAdrian ChaddThe driver needs to do a few things with this frame. Notably if it's 101*490c53e9SAdrian Chaddan 802.3 offload device, it will be handed an 802.3 frame with no 102*490c53e9SAdrian Chadd802.11 information. In that case, the driver just needs to queue 103*490c53e9SAdrian Chaddit for send to the hardware/firmware. 104*490c53e9SAdrian Chadd 105*490c53e9SAdrian ChaddFor devices which accept 802.11 frames, a few things are needed: 106*490c53e9SAdrian Chadd 107*490c53e9SAdrian Chadd * It needs to queue them for send, in the order they're given. 108*490c53e9SAdrian Chadd * If there are any reasons the frames need to be buffered in the 109*490c53e9SAdrian Chadd driver - eg node power state, asynchronous node/key/state updates - 110*490c53e9SAdrian Chadd then they'll be buffered here until needed. 111*490c53e9SAdrian Chadd * It needs to do any local hardware/firmware setup - rate control, 112*490c53e9SAdrian Chadd transmit configuration, destination queue decisions, etc. 113*490c53e9SAdrian Chadd * Hardware/firmware typically has some way to mark a frame as a type 114*490c53e9SAdrian Chadd (control, data, management), whether RTS/CTS is needed, 115*490c53e9SAdrian Chadd * If IEEE80211_FEXT_SEQNO_OFFLOAD is set in the driver, it may need to 116*490c53e9SAdrian Chadd allocate 802.11 sequence numbers via a call to ieee80211_output_seqno_assign(). 117*490c53e9SAdrian Chadd * If the frame is part of an MPDU (m->m_flags & M_AMPDU_MPDU) then 118*490c53e9SAdrian Chadd the frame may need to be handled differently. (For example rtwn(4) 119*490c53e9SAdrian Chadd leaves sequence number assignment up to the firmware when A-MPDU is 120*490c53e9SAdrian Chadd enabled.) 121*490c53e9SAdrian Chadd * If the mbuf is marked as needing encryption (IEEE80211_FC1_PROTECTED 122*490c53e9SAdrian Chadd is set in the 802.11 header) then the frame needs to be encrypted 123*490c53e9SAdrian Chadd with the current encryption state via a call to ieee80211_crypto_encap(). 124*490c53e9SAdrian Chadd * Finally, the frame is queued to the hardware/firmware. 125*490c53e9SAdrian Chadd 126*490c53e9SAdrian ChaddAgain it is critical that the 802.11 sequence number and encryption be 127*490c53e9SAdrian Chaddcalled together in the same order. This is typically done by the TX work 128*490c53e9SAdrian Chaddbeing done in a lock, or all frames being pushed into a single software 129*490c53e9SAdrian ChaddTX queue. 130*490c53e9SAdrian Chadd 131*490c53e9SAdrian Chadd### Data path vs control path and the need to buffer frames 132*490c53e9SAdrian Chadd 133*490c53e9SAdrian Chaddnet80211 currently treats encryption key programming, VAP state 134*490c53e9SAdrian Chaddand other updates as synchronous calls. For example, the 135*490c53e9SAdrian Chaddtransmit path will call the driver to add a node, then 136*490c53e9SAdrian Chaddset the encryption keys and then queue a frame to be transmitted. 137*490c53e9SAdrian Chadd 138*490c53e9SAdrian ChaddFor devices which are programmed directly with no queued operations 139*490c53e9SAdrian Chadd(such as the ath(4) devices) the encryption key and node programming 140*490c53e9SAdrian Chaddis immediate. However, for many other devices - firmware and 141*490c53e9SAdrian ChaddUSB are two examples - these operations are asynchronous. 142*490c53e9SAdrian ChaddAnd these code paths tend to be in the transmit paths from 143*490c53e9SAdrian Chaddupper layers that may have locks held, so sleeping is not an option. 144*490c53e9SAdrian Chadd 145*490c53e9SAdrian ChaddSo for now this needs to be implemented in the driver itself. 146*490c53e9SAdrian ChaddIt will need to maintain a per-node queue of transmit frames; 147*490c53e9SAdrian Chaddit will need to track asynchronous node creation/updates and 148*490c53e9SAdrian Chaddencryption key updates and buffer transmit frames for a node 149*490c53e9SAdrian Chadduntil the node add/update and encryption key add/update is 150*490c53e9SAdrian Chaddcompleted. 151*490c53e9SAdrian Chadd 152*490c53e9SAdrian Chadd### Transmit Completion Notifications 153*490c53e9SAdrian Chadd 154*490c53e9SAdrian ChaddThe net80211 stack may request a completion notification 155*490c53e9SAdrian Chaddto be called when a transmit frame has completed. 156*490c53e9SAdrian ChaddThis will be done via a call to ieee80211_add_callback(). 157*490c53e9SAdrian ChaddIt is used in various parts of the net80211 stack to 158*490c53e9SAdrian Chadddrive the MAC state machines - for example, being notified 159*490c53e9SAdrian Chaddonce an BAR (Block-ACK request) frame has completed so 160*490c53e9SAdrian Chaddthe retry timer can be cancelled. 161*490c53e9SAdrian Chadd 162*490c53e9SAdrian ChaddThis requires that mbufs that are transmitted with a requested 163*490c53e9SAdrian Chaddcompletion callback be checked and handled appropriately. 164*490c53e9SAdrian ChaddThis is covered in the next section. 165*490c53e9SAdrian Chadd 166*490c53e9SAdrian Chadd### Completing and freeing transmit path mbufs 167*490c53e9SAdrian Chadd 168*490c53e9SAdrian ChaddThere are two paths to freeing mbufs - ieee80211_free_mbuf() and 169*490c53e9SAdrian Chaddieee80211_tx_complete(). 170*490c53e9SAdrian Chadd 171*490c53e9SAdrian Chadd#### Before transmit - ieee80211_free_mbuf() 172*490c53e9SAdrian Chadd 173*490c53e9SAdrian Chaddieee80211_free_mbuf() is used in drivers and net80211 to free 174*490c53e9SAdrian Chadda list of mbufs as part of the transmit path setup so it can 175*490c53e9SAdrian Chaddproperly account for and free an 802.11 MPDU / 802.3 frame, 176*490c53e9SAdrian Chaddor a list of mbufs representing 802.11 fragments. It doesn't 177*490c53e9SAdrian Chaddhandle the ieee80211_node reference as at the early stage 178*490c53e9SAdrian Chaddof transmit there is a single ieee80211_node reference 179*490c53e9SAdrian Chaddcovering all of the fragments being passed to the driver 180*490c53e9SAdrian Chaddfor transmit. 181*490c53e9SAdrian Chadd 182*490c53e9SAdrian ChaddIf you're not supporting 802.11 fragment transmit (and you have 183*490c53e9SAdrian Chaddto register your driver with the IEEE80211_C_TXFRAG capability 184*490c53e9SAdrian Chaddto even support this) then you can ignore all of the above 185*490c53e9SAdrian Chaddand just not call ieee80211_free_mbuf() for now. 186*490c53e9SAdrian Chadd 187*490c53e9SAdrian ChaddThis must not be used for receive mbufs. Yes, this is not 188*490c53e9SAdrian Chaddwell named and should likely just be renamed. 189*490c53e9SAdrian Chadd 190*490c53e9SAdrian Chadd#### After transmit queueing / attempts - ieee80211_tx_complete(). 191*490c53e9SAdrian Chadd 192*490c53e9SAdrian ChaddIn the general case of an transmit mbuf being completed (either 193*490c53e9SAdrian Chaddsuccessfully or unsuccessfully) net80211 provides a call 194*490c53e9SAdrian Chaddto handle everything - ieee80211_tx_complete(). This takes 195*490c53e9SAdrian Chaddthe relevant destination node (struct ieee80211_node), 196*490c53e9SAdrian Chaddthe mbuf, and a status indiciating success or failure. 197*490c53e9SAdrian Chadd 198*490c53e9SAdrian ChaddA call to ieee80211_tx_complete() handles a variety of 199*490c53e9SAdrian Chaddcommon functions: 200*490c53e9SAdrian Chadd 201*490c53e9SAdrian Chadd * It increments the ifnet counters as appropriate; 202*490c53e9SAdrian Chadd * If the frame has a TX completion notification callback attached 203*490c53e9SAdrian Chadd it will process said callback; 204*490c53e9SAdrian Chadd * If a node is supplied then the node reference is freed 205*490c53e9SAdrian Chadd 206*490c53e9SAdrian ChaddIn the past some drivers implemented the mbuf TX callback 207*490c53e9SAdrian Chaddhandling themselves, resulting in some drivers supporting 208*490c53e9SAdrian Chaddcallback and some drivers not supporting callbacks. The goal 209*490c53e9SAdrian Chaddhere is to implement a single way for completions to be 210*490c53e9SAdrian Chaddhandled. 211*490c53e9SAdrian Chadd 212*490c53e9SAdrian ChaddNote that some hardware / firmware do not support per-frame 213*490c53e9SAdrian Chaddcompletion / status notification. For example, USB devices 214*490c53e9SAdrian Chaddtend to not send individual notifications for frames - you 215*490c53e9SAdrian Chaddmay be able to request it for specific frames, but the 216*490c53e9SAdrian Chaddstatus notifications are expensive. In these cases, drivers 217*490c53e9SAdrian Chaddmay just call ieee80211_tx_complete() with a status based 218*490c53e9SAdrian Chaddon whether the frame was queued to the USB endpoint successfully 219*490c53e9SAdrian Chaddor not. 220*490c53e9SAdrian Chadd 221*490c53e9SAdrian Chadd#### Atheros Fast Frames / 802.11n A-MSDU transmit 222*490c53e9SAdrian Chadd 223*490c53e9SAdrian Chadd(Note this is purposely short - a larger write-up for this will be 224*490c53e9SAdrian Chadddone on a separate page.) 225*490c53e9SAdrian Chadd 226*490c53e9SAdrian ChaddThe transmit path above will call ieee80211_ff_check() and 227*490c53e9SAdrian Chaddieee80211_amsdu_check() to see if the given node/frame should be 228*490c53e9SAdrian Chaddqueued for an Atheros Fast Frames MPDU or an A-MSDU. 229*490c53e9SAdrian Chadd 230*490c53e9SAdrian ChaddIf the frame should be queued it will be queued locally and NULL 231*490c53e9SAdrian Chaddwill be returned; if there's already a frame queued it may be 232*490c53e9SAdrian Chaddpaired with a queued frame and both returned as a single mbuf / MPDU 233*490c53e9SAdrian Chaddto send. 234*490c53e9SAdrian Chadd 235*490c53e9SAdrian ChaddAs far as the driver is concerned, it will be handed a single 236*490c53e9SAdrian Chadd802.11 MPDU to send. 237*490c53e9SAdrian Chadd 238*490c53e9SAdrian Chadd#### 802.11n A-MPDU transmit 239*490c53e9SAdrian Chadd 240*490c53e9SAdrian Chaddnet80211 implements the A-MPDU negotiation and block-ack request/response 241*490c53e9SAdrian Chaddhandling. However currently the driver must implement A-MPDU packet 242*490c53e9SAdrian Chaddqueuing, buffering, submission and retransmission. 243*490c53e9SAdrian Chadd 244*490c53e9SAdrian ChaddThere are some methods that the driver can override to control the 245*490c53e9SAdrian ChaddA-MPDU transmit negotiation flow (ic->ic_addba_request, ic->ic_addba_response, 246*490c53e9SAdrian Chaddic->ic_addba_response_timeout, ic->ic_addba_stop) and the Block-Ack 247*490c53e9SAdrian Chaddresponse completion or error/timeout (ic->ic_bar_response). 248*490c53e9SAdrian Chadd 249*490c53e9SAdrian Chadd#### Driver queue completion 250*490c53e9SAdrian Chadd 251*490c53e9SAdrian ChaddCurrently there are two things a driver should do when its own queues 252*490c53e9SAdrian Chaddare (mostly) empty: 253*490c53e9SAdrian Chadd 254*490c53e9SAdrian Chadd * When the transmit queue is empty or mostly empty, call ieee80211_ff_flush() 255*490c53e9SAdrian Chadd to flush out any pending A-MSDU / Atheros Fast Frames to be transmitted; 256*490c53e9SAdrian Chadd * When the receive queue is being handled, call ieee80211_ff_age_all() to 257*490c53e9SAdrian Chadd flush out any frames that are older than a provided time interval. 258*490c53e9SAdrian Chadd 259*490c53e9SAdrian ChaddThese calls ensure that any queued frames in Fast Frames / A-MSDU queue 260*490c53e9SAdrian Chadddon't stay in there permanently. 261*490c53e9SAdrian Chadd 262*490c53e9SAdrian Chadd### Non data frame transmission (management, control, action, beacon, etc) 263*490c53e9SAdrian Chadd 264*490c53e9SAdrian ChaddNon data frames are sent via ieee80211_raw_output(). The main exception to 265*490c53e9SAdrian Chaddthis is beacon frames, which are separately initialised and pulled from 266*490c53e9SAdrian Chaddnet80211 into the driver by the driver specific beacon handling routines. 267*490c53e9SAdrian Chadd 268*490c53e9SAdrian ChaddRaw frames differ from data frames in a couple of ways: 269*490c53e9SAdrian Chadd 270*490c53e9SAdrian Chadd * Transmit parameters are typically sent from userland or the caller 271*490c53e9SAdrian Chadd (struct ieee80211_bpf_params \*), and 272*490c53e9SAdrian Chadd * The input path into the driver is via ic->ic_raw_xmit(), not ic->ic_transmit(). 273*490c53e9SAdrian Chadd 274*490c53e9SAdrian ChaddThe driver can combine the data and non-data paths into a single path. 275*490c53e9SAdrian ChaddThe main reason for keeping these separate is to cleanly support drivers 276*490c53e9SAdrian Chaddand firmware which allow 802.3 frames to be sent and received, but still 277*490c53e9SAdrian Chaddneed a side channel to send and receive management frames for various other 278*490c53e9SAdrian Chaddfunctions. 279*490c53e9SAdrian Chadd 280*490c53e9SAdrian ChaddThe raw frame output path is used by: 281*490c53e9SAdrian Chadd 282*490c53e9SAdrian Chadd * The BPF output path - ieee80211_output() ; 283*490c53e9SAdrian Chadd * The management frame output path - ieee80211_mgmt_output() ; 284*490c53e9SAdrian Chadd * The NULL data output path - ieee80211_send_nulldata() ; 285*490c53e9SAdrian Chadd * Sending probe requests - ieee80211_send_probereq() ; 286*490c53e9SAdrian Chadd * Sending probe responses - ieee80211_send_proberesp() ; 287*490c53e9SAdrian Chadd * Sending 802.11n BAR frames - ieee80211_send_bar() ; 288*490c53e9SAdrian Chadd * .. and anywhere where the individual protocol (eg 802.11s) wishes to send raw 289*490c53e9SAdrian Chadd non-data frames. 290*490c53e9SAdrian Chadd 291*490c53e9SAdrian ChaddThis path is not REALLY designed for high speed data - for example, 292*490c53e9SAdrian Chaddit should work for basic packet injection, but it does not pass through 293*490c53e9SAdrian Chaddthe normal functions for encryption, power save, TX aggregation and other 294*490c53e9SAdrian Chadddata specific operations. It expects to be handed a raw, already encapsulated 295*490c53e9SAdrian Chadd802.11 frame. 296*490c53e9SAdrian Chadd 297*490c53e9SAdrian ChaddNote this is not an 802.11 MPDU - this is an 802.11 frame. For example, 298*490c53e9SAdrian Chaddnon-data frames may not have sequence numbers. NULL data frames have a sequence 299*490c53e9SAdrian Chaddnumber but that sequence number must be 0. 300*490c53e9SAdrian Chadd 301*490c53e9SAdrian ChaddOnce the driver ic->ic_raw_xmit() call is made, the driver can handle the 302*490c53e9SAdrian Chadd802.11 frame in any way it sees fit. Again, it can't assume it's an 802.11 303*490c53e9SAdrian Chadddata frame. 304*490c53e9SAdrian Chadd 305*490c53e9SAdrian Chadd### BPF path 306*490c53e9SAdrian Chadd 307*490c53e9SAdrian ChaddControl frames are injected from userland and net80211 via a raw transmit path, 308*490c53e9SAdrian Chaddseparate from the data path. This dates back to the earliest Orinoco/WaveLAN 309*490c53e9SAdrian Chaddcards, where the earlier firmware only allowed 802.3 frames to be sent/received, 310*490c53e9SAdrian Chaddbut later firmware introduced raw packet transmit to allow wpa_supplicant 311*490c53e9SAdrian Chaddoperation. 312*490c53e9SAdrian Chadd 313*490c53e9SAdrian ChaddPacket injection begins via the BPF/radiotap input path. The code in 314*490c53e9SAdrian Chaddieee80211_radiotap.c attaches a BPF operator to the VAP during the 315*490c53e9SAdrian Chaddcall to ieee80211_radiotap_vattach(). 316*490c53e9SAdrian Chadd 317*490c53e9SAdrian ChaddRaw frames start in BPF and are queued via bpf_ieee80211_write(), which will 318*490c53e9SAdrian Chaddsend the frame into the driver via a call to the VAP ifp->if_output() and then 319*490c53e9SAdrian Chaddif provided, a copy of the feedback mbuf via the VAP ifp->if_input(). 320*490c53e9SAdrian Chadd 321*490c53e9SAdrian ChaddThe ifp->if_output() method by default is ieee80211_output(). The driver 322*490c53e9SAdrian Chaddcan override this. This takes care of validating that it is an 802.11 323*490c53e9SAdrian Chaddframe, extracts the (struct ieee80211_bpf_params \*) header from the 324*490c53e9SAdrian Chadddestination sockaddr passed in via BPF, finds the relevant 325*490c53e9SAdrian Chaddstruct ieee80211_node \*) tx node, grabs a reference, some further sanity 326*490c53e9SAdrian Chaddchecks and then calls ieee80211_raw_output(). The rest of the raw output 327*490c53e9SAdrian Chaddpath is the same as net80211 sourced raw frames. 328*490c53e9SAdrian Chadd 329*490c53e9SAdrian Chadd### Power Save Management 330*490c53e9SAdrian Chadd 331*490c53e9SAdrian ChaddBy default, net80211 will track legacy power-save state between IBSS nodes 332*490c53e9SAdrian Chaddand STA <-> AP nodes (ie, full node buffering via the power management bit 333*490c53e9SAdrian Chaddin the 802.11 header; TIM/ATIM bitmaps in beacons, NULL data frames to wake up) 334*490c53e9SAdrian Chaddand PS-POLL frames being sent by stations to request individual frames. 335*490c53e9SAdrian Chadd 336*490c53e9SAdrian ChaddThe transmit path will pass frames destined to asleep stations to the power 337*490c53e9SAdrian Chaddsave queue via a call to ieee80211_pwrsave(). 338*490c53e9SAdrian Chadd 339*490c53e9SAdrian ChaddThere are a number of VAP methods for the driver to tie into if it needs to be 340*490c53e9SAdrian Chaddinformed about this state (vap->iv_set_tim, vap->iv_recv_pspoll, vap->iv_node_ps). 341*490c53e9SAdrian ChaddThese allow the driver to keep its own internal state in sync with net80211 342*490c53e9SAdrian Chaddand allows it to better maintain its own transmit queue state. 343*490c53e9SAdrian Chadd 344*490c53e9SAdrian ChaddSee the ath(4) driver for a comprehensive example of how these methods are used 345*490c53e9SAdrian Chaddto correctly transmit and buffer frames from an AP to STA device without packet 346*490c53e9SAdrian Chaddloss. 347*490c53e9SAdrian Chadd 348*490c53e9SAdrian Chadd### Transmit path encryption 349*490c53e9SAdrian Chadd 350*490c53e9SAdrian ChaddThe net80211 stack needs to handle a variety of transmit encryption schemes 351*490c53e9SAdrian Chaddbased on all the combinations that driver and firmware interfaces may require. 352*490c53e9SAdrian Chadd 353*490c53e9SAdrian ChaddIn general, the transmit encryption is done in two phases: 354*490c53e9SAdrian Chadd 355*490c53e9SAdrian Chadd * In ieee80211_encap(), the transmit key is chosen via a call 356*490c53e9SAdrian Chadd to ieee80211_crypto_getucastkey() or ieee80211_crypto_getmcastkey() - the 357*490c53e9SAdrian Chadd key index is added to the 802.11 header and space is reserved between 358*490c53e9SAdrian Chadd the 802.11 header/payload and at the end for the encryption key data to be 359*490c53e9SAdrian Chadd added; 360*490c53e9SAdrian Chadd * Then when the driver transmits the frame, it calls ieee80211_crypto_encap() 361*490c53e9SAdrian Chadd to actually do the encryption. 362*490c53e9SAdrian Chadd 363*490c53e9SAdrian ChaddSome hardware will completely offload encryption, so although the key choice 364*490c53e9SAdrian Chaddis made, various driver configuration options are set to inform net80211 not 365*490c53e9SAdrian Chaddto add all the padding. Others will offload encryption but require the 366*490c53e9SAdrian Chaddspace to be provided in the frame for the hardware/firmware to add the 367*490c53e9SAdrian Chaddencryption information into. 368*490c53e9SAdrian Chadd 369*490c53e9SAdrian Chadd### What is IEEE80211_F_DATAPAD ? 370*490c53e9SAdrian Chadd 371*490c53e9SAdrian ChaddThis is actually to support hardware such as the Atheros 802.11abgn chips, 372*490c53e9SAdrian Chaddwhich have a 4 byte alignment requirement between the 802.11 header and 373*490c53e9SAdrian Chaddthe data payload (including the encryption parts.) 374*490c53e9SAdrian Chadd 375*490c53e9SAdrian ChaddYes, it likely should be a more generic option. 376*490c53e9SAdrian Chadd 377*490c53e9SAdrian Chadd### Future work 378*490c53e9SAdrian Chadd 379*490c53e9SAdrian Chadd * It would be nice to more formally define and enforce what drivers should be 380*490c53e9SAdrian Chadd doing with mbufs during the whole transmit lifecycle of an mbuf. 381*490c53e9SAdrian Chadd * Perhaps add a function or two for the drivers to use to 382*490c53e9SAdrian Chadd query whether a given mbuf has a TX notification attached (rather 383*490c53e9SAdrian Chadd than drivers querying M_TXCB) so they can individually 384*490c53e9SAdrian Chadd register for explicit notifications so they can provide more 385*490c53e9SAdrian Chadd accurate completion information. 386*490c53e9SAdrian Chadd * The fast frames age / flush routines should really be expanded to 387*490c53e9SAdrian Chadd be required functionality in net80211 drivers rather than optional 388*490c53e9SAdrian Chadd when IEEE80211_SUPPORT_SUPERG is enabled, so further software transmit 389*490c53e9SAdrian Chadd queue management is possible in net80211. 390*490c53e9SAdrian Chadd 391