1*490c53e9SAdrian Chadd# net80211 Datapath - Receive 2*490c53e9SAdrian Chadd 3*490c53e9SAdrian Chadd## Overview 4*490c53e9SAdrian Chadd 5*490c53e9SAdrian ChaddThis document provides an overview for receive data paths 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## Receive Path 19*490c53e9SAdrian Chadd 20*490c53e9SAdrian Chadd### Concurrency 21*490c53e9SAdrian Chadd 22*490c53e9SAdrian ChaddThere must only be one packet receive path into net80211. The net80211 stack 23*490c53e9SAdrian Chaddhas not yet been fully validated to ensure that state changes all occur under 24*490c53e9SAdrian Chaddsufficient locking. 25*490c53e9SAdrian Chadd 26*490c53e9SAdrian Chadd### Data Path 27*490c53e9SAdrian Chadd 28*490c53e9SAdrian ChaddThe receive path is split into three broad categories: 29*490c53e9SAdrian Chadd 30*490c53e9SAdrian Chadd * The normal 802.11/802.3 packet receive path from drivers; 31*490c53e9SAdrian Chadd * The input path for reinjected frames (eg WDS, 802.11s, BPF); 32*490c53e9SAdrian Chadd * Various side channels for offloaded non-data path (eg explicitly 33*490c53e9SAdrian Chadd scan results, management frames, etc.) 34*490c53e9SAdrian Chadd 35*490c53e9SAdrian Chadd#### Data Path - Initial Input 36*490c53e9SAdrian Chadd 37*490c53e9SAdrian ChaddThe driver receive path begins in ieee80211_input.c . The four 38*490c53e9SAdrian Chaddentry points are: 39*490c53e9SAdrian Chadd 40*490c53e9SAdrian Chadd * ieee80211_input() / ieee80211_input_mimo() and 41*490c53e9SAdrian Chadd * ieee80211_input_all() / ieee80211_input_mimo_all(). 42*490c53e9SAdrian Chadd 43*490c53e9SAdrian ChaddThe first two are called when the destination MAC address is a known 44*490c53e9SAdrian Chadd(struct ieee80211_node) node. These are passed up to the 45*490c53e9SAdrian ChaddVAP via a call to ni->ni_vap->iv_input(). 46*490c53e9SAdrian Chadd 47*490c53e9SAdrian ChaddThe second two are called when the destination MAC address is NOT 48*490c53e9SAdrian Chadda known node. In this instance, the frames are treated as broadcast 49*490c53e9SAdrian Chaddand routed to each VAP BSS node via a call to ieee80211_input_mimo(). 50*490c53e9SAdrian Chadd 51*490c53e9SAdrian ChaddEach VAP vap->iv_input() method handles the behavioural specific 52*490c53e9SAdrian Chaddneeds of the interface. 53*490c53e9SAdrian Chadd 54*490c53e9SAdrian Chadd#### Data Path - VAP type / behaviour 55*490c53e9SAdrian Chadd 56*490c53e9SAdrian ChaddEach VAP type will do roughly the same thing - for example see 57*490c53e9SAdrian Chaddsta_input() in ieee80211_sta.c . 58*490c53e9SAdrian Chadd 59*490c53e9SAdrian Chadd * Check the frame size and protocol ID; 60*490c53e9SAdrian Chadd * Check if the frame has been decrypted in hardware; 61*490c53e9SAdrian Chadd * Grab A-MPDU session frames and put them in the reorder queue; 62*490c53e9SAdrian Chadd * Handle control frames sent to the node, or general scan frames; 63*490c53e9SAdrian Chadd * Get the frame QoS information / TID information if present; 64*490c53e9SAdrian Chadd * If appropriate, check the 802.11 receive sequence number; 65*490c53e9SAdrian Chadd * Break the handling up into data, management and control; 66*490c53e9SAdrian Chadd * Reinject into a radiotap/BPF session via a call to 67*490c53e9SAdrian Chadd ieee80211_radiotap_rx(). 68*490c53e9SAdrian Chadd 69*490c53e9SAdrian ChaddThe data paths will typically do the following: 70*490c53e9SAdrian Chadd 71*490c53e9SAdrian Chadd * Do decryption if needed; 72*490c53e9SAdrian Chadd * Do 802.11 decap if needed; 73*490c53e9SAdrian Chadd * Enforce security requirements if needed; 74*490c53e9SAdrian Chadd * Eventually deliver the frame up to the higher level network 75*490c53e9SAdrian Chadd stack via a call to ieee80211_deliver_data() which will 76*490c53e9SAdrian Chadd strip away any last bits of 802.11 / net80211, 77*490c53e9SAdrian Chadd call ieee80211_vap_deliver_data(), which will call the 78*490c53e9SAdrian Chadd network stack input interface. 79*490c53e9SAdrian Chadd 80*490c53e9SAdrian ChaddThe control and management paths will call vap->iv_recv_mgmt() 81*490c53e9SAdrian Chaddand vap->iv_recv_ctl() which implement the per VAP type behaviours. 82*490c53e9SAdrian ChaddThese will include participating in driving the scan engine, 83*490c53e9SAdrian Chaddthe per-node state machines and the VAP state machine. 84*490c53e9SAdrian Chadd 85*490c53e9SAdrian Chadd#### Reinjected Path 86*490c53e9SAdrian Chadd 87*490c53e9SAdrian Chadd#### Side Channels 88*490c53e9SAdrian Chadd 89*490c53e9SAdrian ChaddDrivers may need a specific side channel for management/control 90*490c53e9SAdrian Chaddframes, MAC layer events (eg A-MPDU aggregation session state); 91*490c53e9SAdrian Chaddsome power state communication, scan information and other 92*490c53e9SAdrian Chaddthings that would normally show up as 802.11 frames. 93*490c53e9SAdrian Chadd 94*490c53e9SAdrian ChaddThese will be covered in more detail in other documents. 95*490c53e9SAdrian Chadd 96*490c53e9SAdrian Chadd### Receive Status and Parameters 97*490c53e9SAdrian Chadd 98*490c53e9SAdrian ChaddReceived 802.11 / 802.3 frames can come with a variety of information 99*490c53e9SAdrian Chaddthat isn't strictly the data payload. These include receive timestamps 100*490c53e9SAdrian Chadd(at beginning or end of frame), receive noise floor / signal strength, 101*490c53e9SAdrian Chaddchannel / frequency, channel width, received rate, aggregation frame 102*490c53e9SAdrian Chaddboundaries, decryption state, etc. 103*490c53e9SAdrian Chadd 104*490c53e9SAdrian ChaddThe original paths - ieee80211_input() and ieee80211_input_all() - 105*490c53e9SAdrian Chaddtook a noise floor and rssi parameter. Later drivers provide 106*490c53e9SAdrian Chaddinformation about all of the above by attaching a (struct ieee80211_rx_stats) 107*490c53e9SAdrian Chaddto the receive mbuf via a call to ieee80211_add_rx_params() bafore 108*490c53e9SAdrian Chaddcalling ieee80211_input_mimo() and ieee80211_input_mimo_all() . 109*490c53e9SAdrian Chadd 110*490c53e9SAdrian ChaddExisting drivers should be migrated to the mimo versions of these 111*490c53e9SAdrian ChaddAPIs and the existing API should eventually be deprecated and 112*490c53e9SAdrian Chaddreplace the mimo versions. 113*490c53e9SAdrian Chadd 114*490c53e9SAdrian ChaddAll new drivers must use the ieee80211_input_mimo() and 115*490c53e9SAdrian Chaddieee80211_input_mimo_all() API calls. 116*490c53e9SAdrian Chadd 117*490c53e9SAdrian Chadd### Driver Receive Path Requirements 118*490c53e9SAdrian Chadd 119*490c53e9SAdrian ChaddThe driver receive path has a few top level requirements: 120*490c53e9SAdrian Chadd 121*490c53e9SAdrian Chadd * Driver / stack locks must not be held during receive. This means that 122*490c53e9SAdrian Chadd drivers should dequeue their frames first into a local list, release 123*490c53e9SAdrian Chadd whatever locks are needed and then pass the frames up to net80211. 124*490c53e9SAdrian Chadd 125*490c53e9SAdrian Chadd * Drivers are responsible for doing the node lookup before 126*490c53e9SAdrian Chadd calling ieee80211_input() / ieee80211_input_mimo() or 127*490c53e9SAdrian Chadd calling ieee80211_input_all() / ieee80211_input_mimo_all(). 128*490c53e9SAdrian Chadd 129*490c53e9SAdrian Chadd * Drivers are also responsible for creating and attaching the 130*490c53e9SAdrian Chadd ieee80211_rx_stats information via a call to ieee80211_add_rx_params(). 131*490c53e9SAdrian Chadd 132*490c53e9SAdrian Chadd * Drivers are responsible for tagging a frame as a potential 133*490c53e9SAdrian Chadd A_MPDU by tagging the received mbuf with the M_AMPDU flag. 134*490c53e9SAdrian Chadd They should do this by just tagging all mbufs to a node 135*490c53e9SAdrian Chadd with ni->ni_flags & IEEE80211_NODE_HT set w/ the M_AMPDU flag. 136*490c53e9SAdrian Chadd This is a holdover from the 802.11n code which enforces that 137*490c53e9SAdrian Chadd only potential AMPDU frames can be added to an A-MPDU receive 138*490c53e9SAdrian Chadd aggregation session and may be relaxed / removed in the future. 139*490c53e9SAdrian Chadd 140*490c53e9SAdrian Chadd### Driver Receive Path Methods 141*490c53e9SAdrian Chadd 142*490c53e9SAdrian ChaddDrivers can hook into the receive path processing in a variety of ways. 143*490c53e9SAdrian ChaddThere are a number of vap methods that a driver can hook into 144*490c53e9SAdrian Chaddprocessing. The details will be covered in the driver document. 145*490c53e9SAdrian Chadd 146*490c53e9SAdrian ChaddThese include: 147*490c53e9SAdrian Chadd 148*490c53e9SAdrian Chadd * vap->iv_input - the driver can replace the iv_input method 149*490c53e9SAdrian Chadd with its own method to first handle frames before they are passed 150*490c53e9SAdrian Chadd to the VAP type receive path. 151*490c53e9SAdrian Chadd * vap->iv_recv_mgmt - the driver can hook here to handle 152*490c53e9SAdrian Chadd management frames before the VAP type management receive path. 153*490c53e9SAdrian Chadd * vap->iv_recv_ctl - the driver can hook here to handle 154*490c53e9SAdrian Chadd control frames before the VAP type control receive path. 155*490c53e9SAdrian Chadd * vap->iv_bmiss - the driver can hook here to be informed of 156*490c53e9SAdrian Chadd beacon miss frames. 157*490c53e9SAdrian Chadd 158*490c53e9SAdrian ChaddThese may be called at any time and overlapping with others (eg 159*490c53e9SAdrian Chaddthe beacon miss event - which may be triggered by a timer - 160*490c53e9SAdrian Chaddcan be called in parallel with the various receive path methods.) 161