Bluetooth: Fix race condition with L2CAP information request
[pandora-kernel.git] / include / net / mac80211.h
1 /*
2  * mac80211 <-> driver interface
3  *
4  * Copyright 2002-2005, Devicescape Software, Inc.
5  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
6  * Copyright 2007-2008  Johannes Berg <johannes@sipsolutions.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #ifndef MAC80211_H
14 #define MAC80211_H
15
16 #include <linux/kernel.h>
17 #include <linux/if_ether.h>
18 #include <linux/skbuff.h>
19 #include <linux/wireless.h>
20 #include <linux/device.h>
21 #include <linux/ieee80211.h>
22 #include <net/wireless.h>
23 #include <net/cfg80211.h>
24
25 /**
26  * DOC: Introduction
27  *
28  * mac80211 is the Linux stack for 802.11 hardware that implements
29  * only partial functionality in hard- or firmware. This document
30  * defines the interface between mac80211 and low-level hardware
31  * drivers.
32  */
33
34 /**
35  * DOC: Calling mac80211 from interrupts
36  *
37  * Only ieee80211_tx_status_irqsafe() and ieee80211_rx_irqsafe() can be
38  * called in hardware interrupt context. The low-level driver must not call any
39  * other functions in hardware interrupt context. If there is a need for such
40  * call, the low-level driver should first ACK the interrupt and perform the
41  * IEEE 802.11 code call after this, e.g. from a scheduled workqueue or even
42  * tasklet function.
43  *
44  * NOTE: If the driver opts to use the _irqsafe() functions, it may not also
45  *       use the non-IRQ-safe functions!
46  */
47
48 /**
49  * DOC: Warning
50  *
51  * If you're reading this document and not the header file itself, it will
52  * be incomplete because not all documentation has been converted yet.
53  */
54
55 /**
56  * DOC: Frame format
57  *
58  * As a general rule, when frames are passed between mac80211 and the driver,
59  * they start with the IEEE 802.11 header and include the same octets that are
60  * sent over the air except for the FCS which should be calculated by the
61  * hardware.
62  *
63  * There are, however, various exceptions to this rule for advanced features:
64  *
65  * The first exception is for hardware encryption and decryption offload
66  * where the IV/ICV may or may not be generated in hardware.
67  *
68  * Secondly, when the hardware handles fragmentation, the frame handed to
69  * the driver from mac80211 is the MSDU, not the MPDU.
70  *
71  * Finally, for received frames, the driver is able to indicate that it has
72  * filled a radiotap header and put that in front of the frame; if it does
73  * not do so then mac80211 may add this under certain circumstances.
74  */
75
76 /**
77  * struct ieee80211_ht_bss_info - describing BSS's HT characteristics
78  *
79  * This structure describes most essential parameters needed
80  * to describe 802.11n HT characteristics in a BSS.
81  *
82  * @primary_channel: channel number of primery channel
83  * @bss_cap: 802.11n's general BSS capabilities (e.g. channel width)
84  * @bss_op_mode: 802.11n's BSS operation modes (e.g. HT protection)
85  */
86 struct ieee80211_ht_bss_info {
87         u8 primary_channel;
88         u8 bss_cap;  /* use IEEE80211_HT_IE_CHA_ */
89         u8 bss_op_mode; /* use IEEE80211_HT_IE_ */
90 };
91
92 /**
93  * enum ieee80211_max_queues - maximum number of queues
94  *
95  * @IEEE80211_MAX_QUEUES: Maximum number of regular device queues.
96  * @IEEE80211_MAX_AMPDU_QUEUES: Maximum number of queues usable
97  *      for A-MPDU operation.
98  */
99 enum ieee80211_max_queues {
100         IEEE80211_MAX_QUEUES =          16,
101         IEEE80211_MAX_AMPDU_QUEUES =    16,
102 };
103
104 /**
105  * struct ieee80211_tx_queue_params - transmit queue configuration
106  *
107  * The information provided in this structure is required for QoS
108  * transmit queue configuration. Cf. IEEE 802.11 7.3.2.29.
109  *
110  * @aifs: arbitration interframe space [0..255]
111  * @cw_min: minimum contention window [a value of the form
112  *      2^n-1 in the range 1..32767]
113  * @cw_max: maximum contention window [like @cw_min]
114  * @txop: maximum burst time in units of 32 usecs, 0 meaning disabled
115  */
116 struct ieee80211_tx_queue_params {
117         u16 txop;
118         u16 cw_min;
119         u16 cw_max;
120         u8 aifs;
121 };
122
123 /**
124  * struct ieee80211_tx_queue_stats - transmit queue statistics
125  *
126  * @len: number of packets in queue
127  * @limit: queue length limit
128  * @count: number of frames sent
129  */
130 struct ieee80211_tx_queue_stats {
131         unsigned int len;
132         unsigned int limit;
133         unsigned int count;
134 };
135
136 struct ieee80211_low_level_stats {
137         unsigned int dot11ACKFailureCount;
138         unsigned int dot11RTSFailureCount;
139         unsigned int dot11FCSErrorCount;
140         unsigned int dot11RTSSuccessCount;
141 };
142
143 /**
144  * enum ieee80211_bss_change - BSS change notification flags
145  *
146  * These flags are used with the bss_info_changed() callback
147  * to indicate which BSS parameter changed.
148  *
149  * @BSS_CHANGED_ASSOC: association status changed (associated/disassociated),
150  *      also implies a change in the AID.
151  * @BSS_CHANGED_ERP_CTS_PROT: CTS protection changed
152  * @BSS_CHANGED_ERP_PREAMBLE: preamble changed
153  * @BSS_CHANGED_ERP_SLOT: slot timing changed
154  * @BSS_CHANGED_HT: 802.11n parameters changed
155  * @BSS_CHANGED_BASIC_RATES: Basic rateset changed
156  */
157 enum ieee80211_bss_change {
158         BSS_CHANGED_ASSOC               = 1<<0,
159         BSS_CHANGED_ERP_CTS_PROT        = 1<<1,
160         BSS_CHANGED_ERP_PREAMBLE        = 1<<2,
161         BSS_CHANGED_ERP_SLOT            = 1<<3,
162         BSS_CHANGED_HT                  = 1<<4,
163         BSS_CHANGED_BASIC_RATES         = 1<<5,
164 };
165
166 /**
167  * struct ieee80211_bss_ht_conf - BSS's changing HT configuration
168  * @operation_mode: HT operation mode (like in &struct ieee80211_ht_info)
169  */
170 struct ieee80211_bss_ht_conf {
171         u16 operation_mode;
172 };
173
174 /**
175  * struct ieee80211_bss_conf - holds the BSS's changing parameters
176  *
177  * This structure keeps information about a BSS (and an association
178  * to that BSS) that can change during the lifetime of the BSS.
179  *
180  * @assoc: association status
181  * @aid: association ID number, valid only when @assoc is true
182  * @use_cts_prot: use CTS protection
183  * @use_short_preamble: use 802.11b short preamble;
184  *      if the hardware cannot handle this it must set the
185  *      IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE hardware flag
186  * @use_short_slot: use short slot time (only relevant for ERP);
187  *      if the hardware cannot handle this it must set the
188  *      IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE hardware flag
189  * @dtim_period: num of beacons before the next DTIM, for PSM
190  * @timestamp: beacon timestamp
191  * @beacon_int: beacon interval
192  * @assoc_capability: capabilities taken from assoc resp
193  * @ht: BSS's HT configuration
194  * @basic_rates: bitmap of basic rates, each bit stands for an
195  *      index into the rate table configured by the driver in
196  *      the current band.
197  */
198 struct ieee80211_bss_conf {
199         /* association related data */
200         bool assoc;
201         u16 aid;
202         /* erp related data */
203         bool use_cts_prot;
204         bool use_short_preamble;
205         bool use_short_slot;
206         u8 dtim_period;
207         u16 beacon_int;
208         u16 assoc_capability;
209         u64 timestamp;
210         u32 basic_rates;
211         struct ieee80211_bss_ht_conf ht;
212 };
213
214 /**
215  * enum mac80211_tx_control_flags - flags to describe transmission information/status
216  *
217  * These flags are used with the @flags member of &ieee80211_tx_info.
218  *
219  * @IEEE80211_TX_CTL_REQ_TX_STATUS: request TX status callback for this frame.
220  * @IEEE80211_TX_CTL_ASSIGN_SEQ: The driver has to assign a sequence
221  *      number to this frame, taking care of not overwriting the fragment
222  *      number and increasing the sequence number only when the
223  *      IEEE80211_TX_CTL_FIRST_FRAGMENT flag is set. mac80211 will properly
224  *      assign sequence numbers to QoS-data frames but cannot do so correctly
225  *      for non-QoS-data and management frames because beacons need them from
226  *      that counter as well and mac80211 cannot guarantee proper sequencing.
227  *      If this flag is set, the driver should instruct the hardware to
228  *      assign a sequence number to the frame or assign one itself. Cf. IEEE
229  *      802.11-2007 7.1.3.4.1 paragraph 3. This flag will always be set for
230  *      beacons and always be clear for frames without a sequence number field.
231  * @IEEE80211_TX_CTL_NO_ACK: tell the low level not to wait for an ack
232  * @IEEE80211_TX_CTL_CLEAR_PS_FILT: clear powersave filter for destination
233  *      station
234  * @IEEE80211_TX_CTL_FIRST_FRAGMENT: this is a first fragment of the frame
235  * @IEEE80211_TX_CTL_SEND_AFTER_DTIM: send this frame after DTIM beacon
236  * @IEEE80211_TX_CTL_AMPDU: this frame should be sent as part of an A-MPDU
237  * @IEEE80211_TX_CTL_INJECTED: Frame was injected, internal to mac80211.
238  * @IEEE80211_TX_STAT_TX_FILTERED: The frame was not transmitted
239  *      because the destination STA was in powersave mode.
240  * @IEEE80211_TX_STAT_ACK: Frame was acknowledged
241  * @IEEE80211_TX_STAT_AMPDU: The frame was aggregated, so status
242  *      is for the whole aggregation.
243  * @IEEE80211_TX_STAT_AMPDU_NO_BACK: no block ack was returned,
244  *      so consider using block ack request (BAR).
245  * @IEEE80211_TX_CTL_RATE_CTRL_PROBE: internal to mac80211, can be
246  *      set by rate control algorithms to indicate probe rate, will
247  *      be cleared for fragmented frames (except on the last fragment)
248  */
249 enum mac80211_tx_control_flags {
250         IEEE80211_TX_CTL_REQ_TX_STATUS          = BIT(0),
251         IEEE80211_TX_CTL_ASSIGN_SEQ             = BIT(1),
252         IEEE80211_TX_CTL_NO_ACK                 = BIT(2),
253         IEEE80211_TX_CTL_CLEAR_PS_FILT          = BIT(3),
254         IEEE80211_TX_CTL_FIRST_FRAGMENT         = BIT(4),
255         IEEE80211_TX_CTL_SEND_AFTER_DTIM        = BIT(5),
256         IEEE80211_TX_CTL_AMPDU                  = BIT(6),
257         IEEE80211_TX_CTL_INJECTED               = BIT(7),
258         IEEE80211_TX_STAT_TX_FILTERED           = BIT(8),
259         IEEE80211_TX_STAT_ACK                   = BIT(9),
260         IEEE80211_TX_STAT_AMPDU                 = BIT(10),
261         IEEE80211_TX_STAT_AMPDU_NO_BACK         = BIT(11),
262         IEEE80211_TX_CTL_RATE_CTRL_PROBE        = BIT(12),
263 };
264
265 /**
266  * enum mac80211_rate_control_flags - per-rate flags set by the
267  *      Rate Control algorithm.
268  *
269  * These flags are set by the Rate control algorithm for each rate during tx,
270  * in the @flags member of struct ieee80211_tx_rate.
271  *
272  * @IEEE80211_TX_RC_USE_RTS_CTS: Use RTS/CTS exchange for this rate.
273  * @IEEE80211_TX_RC_USE_CTS_PROTECT: CTS-to-self protection is required.
274  *      This is set if the current BSS requires ERP protection.
275  * @IEEE80211_TX_RC_USE_SHORT_PREAMBLE: Use short preamble.
276  * @IEEE80211_TX_RC_MCS: HT rate.
277  * @IEEE80211_TX_RC_GREEN_FIELD: Indicates whether this rate should be used in
278  *      Greenfield mode.
279  * @IEEE80211_TX_RC_40_MHZ_WIDTH: Indicates if the Channel Width should be 40 MHz.
280  * @IEEE80211_TX_RC_DUP_DATA: The frame should be transmitted on both of the
281  *      adjacent 20 MHz channels, if the current channel type is
282  *      NL80211_CHAN_HT40MINUS or NL80211_CHAN_HT40PLUS.
283  * @IEEE80211_TX_RC_SHORT_GI: Short Guard interval should be used for this rate.
284  */
285 enum mac80211_rate_control_flags {
286         IEEE80211_TX_RC_USE_RTS_CTS             = BIT(0),
287         IEEE80211_TX_RC_USE_CTS_PROTECT         = BIT(1),
288         IEEE80211_TX_RC_USE_SHORT_PREAMBLE      = BIT(2),
289
290         /* rate index is an MCS rate number instead of an index */
291         IEEE80211_TX_RC_MCS                     = BIT(3),
292         IEEE80211_TX_RC_GREEN_FIELD             = BIT(4),
293         IEEE80211_TX_RC_40_MHZ_WIDTH            = BIT(5),
294         IEEE80211_TX_RC_DUP_DATA                = BIT(6),
295         IEEE80211_TX_RC_SHORT_GI                = BIT(7),
296 };
297
298
299 /* there are 40 bytes if you don't need the rateset to be kept */
300 #define IEEE80211_TX_INFO_DRIVER_DATA_SIZE 40
301
302 /* if you do need the rateset, then you have less space */
303 #define IEEE80211_TX_INFO_RATE_DRIVER_DATA_SIZE 24
304
305 /* maximum number of rate stages */
306 #define IEEE80211_TX_MAX_RATES  5
307
308 /**
309  * struct ieee80211_tx_rate - rate selection/status
310  *
311  * @idx: rate index to attempt to send with
312  * @flags: rate control flags (&enum mac80211_rate_control_flags)
313  * @count: number of tries in this rate before going to the next rate
314  *
315  * A value of -1 for @idx indicates an invalid rate and, if used
316  * in an array of retry rates, that no more rates should be tried.
317  *
318  * When used for transmit status reporting, the driver should
319  * always report the rate along with the flags it used.
320  */
321 struct ieee80211_tx_rate {
322         s8 idx;
323         u8 count;
324         u8 flags;
325 } __attribute__((packed));
326
327 /**
328  * struct ieee80211_tx_info - skb transmit information
329  *
330  * This structure is placed in skb->cb for three uses:
331  *  (1) mac80211 TX control - mac80211 tells the driver what to do
332  *  (2) driver internal use (if applicable)
333  *  (3) TX status information - driver tells mac80211 what happened
334  *
335  * The TX control's sta pointer is only valid during the ->tx call,
336  * it may be NULL.
337  *
338  * @flags: transmit info flags, defined above
339  * @band: the band to transmit on (use for checking for races)
340  * @antenna_sel_tx: antenna to use, 0 for automatic diversity
341  * @pad: padding, ignore
342  * @control: union for control data
343  * @status: union for status data
344  * @driver_data: array of driver_data pointers
345  * @ampdu_ack_len: number of aggregated frames.
346  *      relevant only if IEEE80211_TX_STATUS_AMPDU was set.
347  * @ampdu_ack_map: block ack bit map for the aggregation.
348  *      relevant only if IEEE80211_TX_STATUS_AMPDU was set.
349  * @ack_signal: signal strength of the ACK frame
350  */
351 struct ieee80211_tx_info {
352         /* common information */
353         u32 flags;
354         u8 band;
355
356         u8 antenna_sel_tx;
357
358         /* 2 byte hole */
359         u8 pad[2];
360
361         union {
362                 struct {
363                         union {
364                                 /* rate control */
365                                 struct {
366                                         struct ieee80211_tx_rate rates[
367                                                 IEEE80211_TX_MAX_RATES];
368                                         s8 rts_cts_rate_idx;
369                                 };
370                                 /* only needed before rate control */
371                                 unsigned long jiffies;
372                         };
373                         /* NB: vif can be NULL for injected frames */
374                         struct ieee80211_vif *vif;
375                         struct ieee80211_key_conf *hw_key;
376                         struct ieee80211_sta *sta;
377                 } control;
378                 struct {
379                         struct ieee80211_tx_rate rates[IEEE80211_TX_MAX_RATES];
380                         u8 ampdu_ack_len;
381                         u64 ampdu_ack_map;
382                         int ack_signal;
383                         /* 8 bytes free */
384                 } status;
385                 struct {
386                         struct ieee80211_tx_rate driver_rates[
387                                 IEEE80211_TX_MAX_RATES];
388                         void *rate_driver_data[
389                                 IEEE80211_TX_INFO_RATE_DRIVER_DATA_SIZE / sizeof(void *)];
390                 };
391                 void *driver_data[
392                         IEEE80211_TX_INFO_DRIVER_DATA_SIZE / sizeof(void *)];
393         };
394 };
395
396 static inline struct ieee80211_tx_info *IEEE80211_SKB_CB(struct sk_buff *skb)
397 {
398         return (struct ieee80211_tx_info *)skb->cb;
399 }
400
401 /**
402  * ieee80211_tx_info_clear_status - clear TX status
403  *
404  * @info: The &struct ieee80211_tx_info to be cleared.
405  *
406  * When the driver passes an skb back to mac80211, it must report
407  * a number of things in TX status. This function clears everything
408  * in the TX status but the rate control information (it does clear
409  * the count since you need to fill that in anyway).
410  *
411  * NOTE: You can only use this function if you do NOT use
412  *       info->driver_data! Use info->rate_driver_data
413  *       instead if you need only the less space that allows.
414  */
415 static inline void
416 ieee80211_tx_info_clear_status(struct ieee80211_tx_info *info)
417 {
418         int i;
419
420         BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, status.rates) !=
421                      offsetof(struct ieee80211_tx_info, control.rates));
422         BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, status.rates) !=
423                      offsetof(struct ieee80211_tx_info, driver_rates));
424         BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, status.rates) != 8);
425         /* clear the rate counts */
426         for (i = 0; i < IEEE80211_TX_MAX_RATES; i++)
427                 info->status.rates[i].count = 0;
428
429         BUILD_BUG_ON(
430             offsetof(struct ieee80211_tx_info, status.ampdu_ack_len) != 23);
431         memset(&info->status.ampdu_ack_len, 0,
432                sizeof(struct ieee80211_tx_info) -
433                offsetof(struct ieee80211_tx_info, status.ampdu_ack_len));
434 }
435
436
437 /**
438  * enum mac80211_rx_flags - receive flags
439  *
440  * These flags are used with the @flag member of &struct ieee80211_rx_status.
441  * @RX_FLAG_MMIC_ERROR: Michael MIC error was reported on this frame.
442  *      Use together with %RX_FLAG_MMIC_STRIPPED.
443  * @RX_FLAG_DECRYPTED: This frame was decrypted in hardware.
444  * @RX_FLAG_RADIOTAP: This frame starts with a radiotap header.
445  * @RX_FLAG_MMIC_STRIPPED: the Michael MIC is stripped off this frame,
446  *      verification has been done by the hardware.
447  * @RX_FLAG_IV_STRIPPED: The IV/ICV are stripped from this frame.
448  *      If this flag is set, the stack cannot do any replay detection
449  *      hence the driver or hardware will have to do that.
450  * @RX_FLAG_FAILED_FCS_CRC: Set this flag if the FCS check failed on
451  *      the frame.
452  * @RX_FLAG_FAILED_PLCP_CRC: Set this flag if the PCLP check failed on
453  *      the frame.
454  * @RX_FLAG_TSFT: The timestamp passed in the RX status (@mactime field)
455  *      is valid. This is useful in monitor mode and necessary for beacon frames
456  *      to enable IBSS merging.
457  * @RX_FLAG_SHORTPRE: Short preamble was used for this frame
458  * @RX_FLAG_HT: HT MCS was used and rate_idx is MCS index
459  * @RX_FLAG_40MHZ: HT40 (40 MHz) was used
460  * @RX_FLAG_SHORT_GI: Short guard interval was used
461  */
462 enum mac80211_rx_flags {
463         RX_FLAG_MMIC_ERROR      = 1<<0,
464         RX_FLAG_DECRYPTED       = 1<<1,
465         RX_FLAG_RADIOTAP        = 1<<2,
466         RX_FLAG_MMIC_STRIPPED   = 1<<3,
467         RX_FLAG_IV_STRIPPED     = 1<<4,
468         RX_FLAG_FAILED_FCS_CRC  = 1<<5,
469         RX_FLAG_FAILED_PLCP_CRC = 1<<6,
470         RX_FLAG_TSFT            = 1<<7,
471         RX_FLAG_SHORTPRE        = 1<<8,
472         RX_FLAG_HT              = 1<<9,
473         RX_FLAG_40MHZ           = 1<<10,
474         RX_FLAG_SHORT_GI        = 1<<11,
475 };
476
477 /**
478  * struct ieee80211_rx_status - receive status
479  *
480  * The low-level driver should provide this information (the subset
481  * supported by hardware) to the 802.11 code with each received
482  * frame.
483  *
484  * @mactime: value in microseconds of the 64-bit Time Synchronization Function
485  *      (TSF) timer when the first data symbol (MPDU) arrived at the hardware.
486  * @band: the active band when this frame was received
487  * @freq: frequency the radio was tuned to when receiving this frame, in MHz
488  * @signal: signal strength when receiving this frame, either in dBm, in dB or
489  *      unspecified depending on the hardware capabilities flags
490  *      @IEEE80211_HW_SIGNAL_*
491  * @noise: noise when receiving this frame, in dBm.
492  * @qual: overall signal quality indication, in percent (0-100).
493  * @antenna: antenna used
494  * @rate_idx: index of data rate into band's supported rates or MCS index if
495  *      HT rates are use (RX_FLAG_HT)
496  * @flag: %RX_FLAG_*
497  */
498 struct ieee80211_rx_status {
499         u64 mactime;
500         enum ieee80211_band band;
501         int freq;
502         int signal;
503         int noise;
504         int qual;
505         int antenna;
506         int rate_idx;
507         int flag;
508 };
509
510 /**
511  * enum ieee80211_conf_flags - configuration flags
512  *
513  * Flags to define PHY configuration options
514  *
515  * @IEEE80211_CONF_RADIOTAP: add radiotap header at receive time (if supported)
516  * @IEEE80211_CONF_PS: Enable 802.11 power save mode
517  */
518 enum ieee80211_conf_flags {
519         IEEE80211_CONF_RADIOTAP         = (1<<0),
520         IEEE80211_CONF_PS               = (1<<1),
521 };
522
523 /* XXX: remove all this once drivers stop trying to use it */
524 static inline int __deprecated __IEEE80211_CONF_SHORT_SLOT_TIME(void)
525 {
526         return 0;
527 }
528 #define IEEE80211_CONF_SHORT_SLOT_TIME (__IEEE80211_CONF_SHORT_SLOT_TIME())
529
530 /**
531  * enum ieee80211_conf_changed - denotes which configuration changed
532  *
533  * @IEEE80211_CONF_CHANGE_RADIO_ENABLED: the value of radio_enabled changed
534  * @IEEE80211_CONF_CHANGE_BEACON_INTERVAL: the beacon interval changed
535  * @IEEE80211_CONF_CHANGE_LISTEN_INTERVAL: the listen interval changed
536  * @IEEE80211_CONF_CHANGE_RADIOTAP: the radiotap flag changed
537  * @IEEE80211_CONF_CHANGE_PS: the PS flag changed
538  * @IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT: the dynamic PS timeout changed
539  * @IEEE80211_CONF_CHANGE_POWER: the TX power changed
540  * @IEEE80211_CONF_CHANGE_CHANNEL: the channel/channel_type changed
541  * @IEEE80211_CONF_CHANGE_RETRY_LIMITS: retry limits changed
542  */
543 enum ieee80211_conf_changed {
544         IEEE80211_CONF_CHANGE_RADIO_ENABLED     = BIT(0),
545         IEEE80211_CONF_CHANGE_BEACON_INTERVAL   = BIT(1),
546         IEEE80211_CONF_CHANGE_LISTEN_INTERVAL   = BIT(2),
547         IEEE80211_CONF_CHANGE_RADIOTAP          = BIT(3),
548         IEEE80211_CONF_CHANGE_PS                = BIT(4),
549         IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT     = BIT(5),
550         IEEE80211_CONF_CHANGE_POWER             = BIT(6),
551         IEEE80211_CONF_CHANGE_CHANNEL           = BIT(7),
552         IEEE80211_CONF_CHANGE_RETRY_LIMITS      = BIT(8),
553 };
554
555 /**
556  * struct ieee80211_conf - configuration of the device
557  *
558  * This struct indicates how the driver shall configure the hardware.
559  *
560  * @radio_enabled: when zero, driver is required to switch off the radio.
561  * @beacon_int: beacon interval (TODO make interface config)
562  * @listen_interval: listen interval in units of beacon interval
563  * @flags: configuration flags defined above
564  * @power_level: requested transmit power (in dBm)
565  * @dynamic_ps_timeout: dynamic powersave timeout (in ms)
566  * @channel: the channel to tune to
567  * @channel_type: the channel (HT) type
568  * @long_frame_max_tx_count: Maximum number of transmissions for a "long" frame
569  *    (a frame not RTS protected), called "dot11LongRetryLimit" in 802.11,
570  *    but actually means the number of transmissions not the number of retries
571  * @short_frame_max_tx_count: Maximum number of transmissions for a "short"
572  *    frame, called "dot11ShortRetryLimit" in 802.11, but actually means the
573  *    number of transmissions not the number of retries
574  */
575 struct ieee80211_conf {
576         int beacon_int;
577         u32 flags;
578         int power_level, dynamic_ps_timeout;
579
580         u16 listen_interval;
581         bool radio_enabled;
582
583         u8 long_frame_max_tx_count, short_frame_max_tx_count;
584
585         struct ieee80211_channel *channel;
586         enum nl80211_channel_type channel_type;
587 };
588
589 /**
590  * struct ieee80211_vif - per-interface data
591  *
592  * Data in this structure is continually present for driver
593  * use during the life of a virtual interface.
594  *
595  * @type: type of this virtual interface
596  * @bss_conf: BSS configuration for this interface, either our own
597  *      or the BSS we're associated to
598  * @drv_priv: data area for driver use, will always be aligned to
599  *      sizeof(void *).
600  */
601 struct ieee80211_vif {
602         enum nl80211_iftype type;
603         struct ieee80211_bss_conf bss_conf;
604         /* must be last */
605         u8 drv_priv[0] __attribute__((__aligned__(sizeof(void *))));
606 };
607
608 static inline bool ieee80211_vif_is_mesh(struct ieee80211_vif *vif)
609 {
610 #ifdef CONFIG_MAC80211_MESH
611         return vif->type == NL80211_IFTYPE_MESH_POINT;
612 #endif
613         return false;
614 }
615
616 /**
617  * struct ieee80211_if_init_conf - initial configuration of an interface
618  *
619  * @vif: pointer to a driver-use per-interface structure. The pointer
620  *      itself is also used for various functions including
621  *      ieee80211_beacon_get() and ieee80211_get_buffered_bc().
622  * @type: one of &enum nl80211_iftype constants. Determines the type of
623  *      added/removed interface.
624  * @mac_addr: pointer to MAC address of the interface. This pointer is valid
625  *      until the interface is removed (i.e. it cannot be used after
626  *      remove_interface() callback was called for this interface).
627  *
628  * This structure is used in add_interface() and remove_interface()
629  * callbacks of &struct ieee80211_hw.
630  *
631  * When you allow multiple interfaces to be added to your PHY, take care
632  * that the hardware can actually handle multiple MAC addresses. However,
633  * also take care that when there's no interface left with mac_addr != %NULL
634  * you remove the MAC address from the device to avoid acknowledging packets
635  * in pure monitor mode.
636  */
637 struct ieee80211_if_init_conf {
638         enum nl80211_iftype type;
639         struct ieee80211_vif *vif;
640         void *mac_addr;
641 };
642
643 /**
644  * enum ieee80211_if_conf_change - interface config change flags
645  *
646  * @IEEE80211_IFCC_BSSID: The BSSID changed.
647  * @IEEE80211_IFCC_BEACON: The beacon for this interface changed
648  *      (currently AP and MESH only), use ieee80211_beacon_get().
649  * @IEEE80211_IFCC_BEACON_ENABLED: The enable_beacon value changed.
650  */
651 enum ieee80211_if_conf_change {
652         IEEE80211_IFCC_BSSID            = BIT(0),
653         IEEE80211_IFCC_BEACON           = BIT(1),
654         IEEE80211_IFCC_BEACON_ENABLED   = BIT(2),
655 };
656
657 /**
658  * struct ieee80211_if_conf - configuration of an interface
659  *
660  * @changed: parameters that have changed, see &enum ieee80211_if_conf_change.
661  * @bssid: BSSID of the network we are associated to/creating.
662  * @enable_beacon: Indicates whether beacons can be sent.
663  *      This is valid only for AP/IBSS/MESH modes.
664  *
665  * This structure is passed to the config_interface() callback of
666  * &struct ieee80211_hw.
667  */
668 struct ieee80211_if_conf {
669         u32 changed;
670         const u8 *bssid;
671         bool enable_beacon;
672 };
673
674 /**
675  * enum ieee80211_key_alg - key algorithm
676  * @ALG_WEP: WEP40 or WEP104
677  * @ALG_TKIP: TKIP
678  * @ALG_CCMP: CCMP (AES)
679  * @ALG_AES_CMAC: AES-128-CMAC
680  */
681 enum ieee80211_key_alg {
682         ALG_WEP,
683         ALG_TKIP,
684         ALG_CCMP,
685         ALG_AES_CMAC,
686 };
687
688 /**
689  * enum ieee80211_key_len - key length
690  * @LEN_WEP40: WEP 5-byte long key
691  * @LEN_WEP104: WEP 13-byte long key
692  */
693 enum ieee80211_key_len {
694         LEN_WEP40 = 5,
695         LEN_WEP104 = 13,
696 };
697
698 /**
699  * enum ieee80211_key_flags - key flags
700  *
701  * These flags are used for communication about keys between the driver
702  * and mac80211, with the @flags parameter of &struct ieee80211_key_conf.
703  *
704  * @IEEE80211_KEY_FLAG_WMM_STA: Set by mac80211, this flag indicates
705  *      that the STA this key will be used with could be using QoS.
706  * @IEEE80211_KEY_FLAG_GENERATE_IV: This flag should be set by the
707  *      driver to indicate that it requires IV generation for this
708  *      particular key.
709  * @IEEE80211_KEY_FLAG_GENERATE_MMIC: This flag should be set by
710  *      the driver for a TKIP key if it requires Michael MIC
711  *      generation in software.
712  * @IEEE80211_KEY_FLAG_PAIRWISE: Set by mac80211, this flag indicates
713  *      that the key is pairwise rather then a shared key.
714  * @IEEE80211_KEY_FLAG_SW_MGMT: This flag should be set by the driver for a
715  *      CCMP key if it requires CCMP encryption of management frames (MFP) to
716  *      be done in software.
717  */
718 enum ieee80211_key_flags {
719         IEEE80211_KEY_FLAG_WMM_STA      = 1<<0,
720         IEEE80211_KEY_FLAG_GENERATE_IV  = 1<<1,
721         IEEE80211_KEY_FLAG_GENERATE_MMIC= 1<<2,
722         IEEE80211_KEY_FLAG_PAIRWISE     = 1<<3,
723         IEEE80211_KEY_FLAG_SW_MGMT      = 1<<4,
724 };
725
726 /**
727  * struct ieee80211_key_conf - key information
728  *
729  * This key information is given by mac80211 to the driver by
730  * the set_key() callback in &struct ieee80211_ops.
731  *
732  * @hw_key_idx: To be set by the driver, this is the key index the driver
733  *      wants to be given when a frame is transmitted and needs to be
734  *      encrypted in hardware.
735  * @alg: The key algorithm.
736  * @flags: key flags, see &enum ieee80211_key_flags.
737  * @keyidx: the key index (0-3)
738  * @keylen: key material length
739  * @key: key material. For ALG_TKIP the key is encoded as a 256-bit (32 byte)
740  *      data block:
741  *      - Temporal Encryption Key (128 bits)
742  *      - Temporal Authenticator Tx MIC Key (64 bits)
743  *      - Temporal Authenticator Rx MIC Key (64 bits)
744  * @icv_len: The ICV length for this key type
745  * @iv_len: The IV length for this key type
746  */
747 struct ieee80211_key_conf {
748         enum ieee80211_key_alg alg;
749         u8 icv_len;
750         u8 iv_len;
751         u8 hw_key_idx;
752         u8 flags;
753         s8 keyidx;
754         u8 keylen;
755         u8 key[0];
756 };
757
758 /**
759  * enum set_key_cmd - key command
760  *
761  * Used with the set_key() callback in &struct ieee80211_ops, this
762  * indicates whether a key is being removed or added.
763  *
764  * @SET_KEY: a key is set
765  * @DISABLE_KEY: a key must be disabled
766  */
767 enum set_key_cmd {
768         SET_KEY, DISABLE_KEY,
769 };
770
771 /**
772  * struct ieee80211_sta - station table entry
773  *
774  * A station table entry represents a station we are possibly
775  * communicating with. Since stations are RCU-managed in
776  * mac80211, any ieee80211_sta pointer you get access to must
777  * either be protected by rcu_read_lock() explicitly or implicitly,
778  * or you must take good care to not use such a pointer after a
779  * call to your sta_notify callback that removed it.
780  *
781  * @addr: MAC address
782  * @aid: AID we assigned to the station if we're an AP
783  * @supp_rates: Bitmap of supported rates (per band)
784  * @ht_cap: HT capabilities of this STA; restricted to our own TX capabilities
785  * @drv_priv: data area for driver use, will always be aligned to
786  *      sizeof(void *), size is determined in hw information.
787  */
788 struct ieee80211_sta {
789         u32 supp_rates[IEEE80211_NUM_BANDS];
790         u8 addr[ETH_ALEN];
791         u16 aid;
792         struct ieee80211_sta_ht_cap ht_cap;
793
794         /* must be last */
795         u8 drv_priv[0] __attribute__((__aligned__(sizeof(void *))));
796 };
797
798 /**
799  * enum sta_notify_cmd - sta notify command
800  *
801  * Used with the sta_notify() callback in &struct ieee80211_ops, this
802  * indicates addition and removal of a station to station table,
803  * or if a associated station made a power state transition.
804  *
805  * @STA_NOTIFY_ADD: a station was added to the station table
806  * @STA_NOTIFY_REMOVE: a station being removed from the station table
807  * @STA_NOTIFY_SLEEP: a station is now sleeping
808  * @STA_NOTIFY_AWAKE: a sleeping station woke up
809  */
810 enum sta_notify_cmd {
811         STA_NOTIFY_ADD, STA_NOTIFY_REMOVE,
812         STA_NOTIFY_SLEEP, STA_NOTIFY_AWAKE,
813 };
814
815 /**
816  * enum ieee80211_tkip_key_type - get tkip key
817  *
818  * Used by drivers which need to get a tkip key for skb. Some drivers need a
819  * phase 1 key, others need a phase 2 key. A single function allows the driver
820  * to get the key, this enum indicates what type of key is required.
821  *
822  * @IEEE80211_TKIP_P1_KEY: the driver needs a phase 1 key
823  * @IEEE80211_TKIP_P2_KEY: the driver needs a phase 2 key
824  */
825 enum ieee80211_tkip_key_type {
826         IEEE80211_TKIP_P1_KEY,
827         IEEE80211_TKIP_P2_KEY,
828 };
829
830 /**
831  * enum ieee80211_hw_flags - hardware flags
832  *
833  * These flags are used to indicate hardware capabilities to
834  * the stack. Generally, flags here should have their meaning
835  * done in a way that the simplest hardware doesn't need setting
836  * any particular flags. There are some exceptions to this rule,
837  * however, so you are advised to review these flags carefully.
838  *
839  * @IEEE80211_HW_RX_INCLUDES_FCS:
840  *      Indicates that received frames passed to the stack include
841  *      the FCS at the end.
842  *
843  * @IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING:
844  *      Some wireless LAN chipsets buffer broadcast/multicast frames
845  *      for power saving stations in the hardware/firmware and others
846  *      rely on the host system for such buffering. This option is used
847  *      to configure the IEEE 802.11 upper layer to buffer broadcast and
848  *      multicast frames when there are power saving stations so that
849  *      the driver can fetch them with ieee80211_get_buffered_bc().
850  *
851  * @IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE:
852  *      Hardware is not capable of short slot operation on the 2.4 GHz band.
853  *
854  * @IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE:
855  *      Hardware is not capable of receiving frames with short preamble on
856  *      the 2.4 GHz band.
857  *
858  * @IEEE80211_HW_SIGNAL_UNSPEC:
859  *      Hardware can provide signal values but we don't know its units. We
860  *      expect values between 0 and @max_signal.
861  *      If possible please provide dB or dBm instead.
862  *
863  * @IEEE80211_HW_SIGNAL_DBM:
864  *      Hardware gives signal values in dBm, decibel difference from
865  *      one milliwatt. This is the preferred method since it is standardized
866  *      between different devices. @max_signal does not need to be set.
867  *
868  * @IEEE80211_HW_NOISE_DBM:
869  *      Hardware can provide noise (radio interference) values in units dBm,
870  *      decibel difference from one milliwatt.
871  *
872  * @IEEE80211_HW_SPECTRUM_MGMT:
873  *      Hardware supports spectrum management defined in 802.11h
874  *      Measurement, Channel Switch, Quieting, TPC
875  *
876  * @IEEE80211_HW_AMPDU_AGGREGATION:
877  *      Hardware supports 11n A-MPDU aggregation.
878  *
879  * @IEEE80211_HW_SUPPORTS_PS:
880  *      Hardware has power save support (i.e. can go to sleep).
881  *
882  * @IEEE80211_HW_PS_NULLFUNC_STACK:
883  *      Hardware requires nullfunc frame handling in stack, implies
884  *      stack support for dynamic PS.
885  *
886  * @IEEE80211_HW_SUPPORTS_DYNAMIC_PS:
887  *      Hardware has support for dynamic PS.
888  *
889  * @IEEE80211_HW_MFP_CAPABLE:
890  *      Hardware supports management frame protection (MFP, IEEE 802.11w).
891  */
892 enum ieee80211_hw_flags {
893         IEEE80211_HW_RX_INCLUDES_FCS                    = 1<<1,
894         IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING        = 1<<2,
895         IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE          = 1<<3,
896         IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE      = 1<<4,
897         IEEE80211_HW_SIGNAL_UNSPEC                      = 1<<5,
898         IEEE80211_HW_SIGNAL_DBM                         = 1<<6,
899         IEEE80211_HW_NOISE_DBM                          = 1<<7,
900         IEEE80211_HW_SPECTRUM_MGMT                      = 1<<8,
901         IEEE80211_HW_AMPDU_AGGREGATION                  = 1<<9,
902         IEEE80211_HW_SUPPORTS_PS                        = 1<<10,
903         IEEE80211_HW_PS_NULLFUNC_STACK                  = 1<<11,
904         IEEE80211_HW_SUPPORTS_DYNAMIC_PS                = 1<<12,
905         IEEE80211_HW_MFP_CAPABLE                        = 1<<13,
906 };
907
908 /**
909  * struct ieee80211_hw - hardware information and state
910  *
911  * This structure contains the configuration and hardware
912  * information for an 802.11 PHY.
913  *
914  * @wiphy: This points to the &struct wiphy allocated for this
915  *      802.11 PHY. You must fill in the @perm_addr and @dev
916  *      members of this structure using SET_IEEE80211_DEV()
917  *      and SET_IEEE80211_PERM_ADDR(). Additionally, all supported
918  *      bands (with channels, bitrates) are registered here.
919  *
920  * @conf: &struct ieee80211_conf, device configuration, don't use.
921  *
922  * @workqueue: single threaded workqueue available for driver use,
923  *      allocated by mac80211 on registration and flushed when an
924  *      interface is removed.
925  *      NOTICE: All work performed on this workqueue must not
926  *      acquire the RTNL lock.
927  *
928  * @priv: pointer to private area that was allocated for driver use
929  *      along with this structure.
930  *
931  * @flags: hardware flags, see &enum ieee80211_hw_flags.
932  *
933  * @extra_tx_headroom: headroom to reserve in each transmit skb
934  *      for use by the driver (e.g. for transmit headers.)
935  *
936  * @channel_change_time: time (in microseconds) it takes to change channels.
937  *
938  * @max_signal: Maximum value for signal (rssi) in RX information, used
939  *     only when @IEEE80211_HW_SIGNAL_UNSPEC or @IEEE80211_HW_SIGNAL_DB
940  *
941  * @max_listen_interval: max listen interval in units of beacon interval
942  *     that HW supports
943  *
944  * @queues: number of available hardware transmit queues for
945  *      data packets. WMM/QoS requires at least four, these
946  *      queues need to have configurable access parameters.
947  *
948  * @ampdu_queues: number of available hardware transmit queues
949  *      for A-MPDU packets, these have no access parameters
950  *      because they're used only for A-MPDU frames. Note that
951  *      mac80211 will not currently use any of the regular queues
952  *      for aggregation.
953  *
954  * @rate_control_algorithm: rate control algorithm for this hardware.
955  *      If unset (NULL), the default algorithm will be used. Must be
956  *      set before calling ieee80211_register_hw().
957  *
958  * @vif_data_size: size (in bytes) of the drv_priv data area
959  *      within &struct ieee80211_vif.
960  * @sta_data_size: size (in bytes) of the drv_priv data area
961  *      within &struct ieee80211_sta.
962  *
963  * @max_rates: maximum number of alternate rate retry stages
964  * @max_rate_tries: maximum number of tries for each stage
965  */
966 struct ieee80211_hw {
967         struct ieee80211_conf conf;
968         struct wiphy *wiphy;
969         struct workqueue_struct *workqueue;
970         const char *rate_control_algorithm;
971         void *priv;
972         u32 flags;
973         unsigned int extra_tx_headroom;
974         int channel_change_time;
975         int vif_data_size;
976         int sta_data_size;
977         u16 queues;
978         u16 ampdu_queues;
979         u16 max_listen_interval;
980         s8 max_signal;
981         u8 max_rates;
982         u8 max_rate_tries;
983 };
984
985 /**
986  * wiphy_to_ieee80211_hw - return a mac80211 driver hw struct from a wiphy
987  *
988  * @wiphy: the &struct wiphy which we want to query
989  *
990  * mac80211 drivers can use this to get to their respective
991  * &struct ieee80211_hw. Drivers wishing to get to their own private
992  * structure can then access it via hw->priv. Note that mac802111 drivers should
993  * not use wiphy_priv() to try to get their private driver structure as this
994  * is already used internally by mac80211.
995  */
996 struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy);
997
998 /**
999  * SET_IEEE80211_DEV - set device for 802.11 hardware
1000  *
1001  * @hw: the &struct ieee80211_hw to set the device for
1002  * @dev: the &struct device of this 802.11 device
1003  */
1004 static inline void SET_IEEE80211_DEV(struct ieee80211_hw *hw, struct device *dev)
1005 {
1006         set_wiphy_dev(hw->wiphy, dev);
1007 }
1008
1009 /**
1010  * SET_IEEE80211_PERM_ADDR - set the permanent MAC address for 802.11 hardware
1011  *
1012  * @hw: the &struct ieee80211_hw to set the MAC address for
1013  * @addr: the address to set
1014  */
1015 static inline void SET_IEEE80211_PERM_ADDR(struct ieee80211_hw *hw, u8 *addr)
1016 {
1017         memcpy(hw->wiphy->perm_addr, addr, ETH_ALEN);
1018 }
1019
1020 static inline int ieee80211_num_regular_queues(struct ieee80211_hw *hw)
1021 {
1022         return hw->queues;
1023 }
1024
1025 static inline int ieee80211_num_queues(struct ieee80211_hw *hw)
1026 {
1027         return hw->queues + hw->ampdu_queues;
1028 }
1029
1030 static inline struct ieee80211_rate *
1031 ieee80211_get_tx_rate(const struct ieee80211_hw *hw,
1032                       const struct ieee80211_tx_info *c)
1033 {
1034         if (WARN_ON(c->control.rates[0].idx < 0))
1035                 return NULL;
1036         return &hw->wiphy->bands[c->band]->bitrates[c->control.rates[0].idx];
1037 }
1038
1039 static inline struct ieee80211_rate *
1040 ieee80211_get_rts_cts_rate(const struct ieee80211_hw *hw,
1041                            const struct ieee80211_tx_info *c)
1042 {
1043         if (c->control.rts_cts_rate_idx < 0)
1044                 return NULL;
1045         return &hw->wiphy->bands[c->band]->bitrates[c->control.rts_cts_rate_idx];
1046 }
1047
1048 static inline struct ieee80211_rate *
1049 ieee80211_get_alt_retry_rate(const struct ieee80211_hw *hw,
1050                              const struct ieee80211_tx_info *c, int idx)
1051 {
1052         if (c->control.rates[idx + 1].idx < 0)
1053                 return NULL;
1054         return &hw->wiphy->bands[c->band]->bitrates[c->control.rates[idx + 1].idx];
1055 }
1056
1057 /**
1058  * DOC: Hardware crypto acceleration
1059  *
1060  * mac80211 is capable of taking advantage of many hardware
1061  * acceleration designs for encryption and decryption operations.
1062  *
1063  * The set_key() callback in the &struct ieee80211_ops for a given
1064  * device is called to enable hardware acceleration of encryption and
1065  * decryption. The callback takes a @sta parameter that will be NULL
1066  * for default keys or keys used for transmission only, or point to
1067  * the station information for the peer for individual keys.
1068  * Multiple transmission keys with the same key index may be used when
1069  * VLANs are configured for an access point.
1070  *
1071  * When transmitting, the TX control data will use the @hw_key_idx
1072  * selected by the driver by modifying the &struct ieee80211_key_conf
1073  * pointed to by the @key parameter to the set_key() function.
1074  *
1075  * The set_key() call for the %SET_KEY command should return 0 if
1076  * the key is now in use, -%EOPNOTSUPP or -%ENOSPC if it couldn't be
1077  * added; if you return 0 then hw_key_idx must be assigned to the
1078  * hardware key index, you are free to use the full u8 range.
1079  *
1080  * When the cmd is %DISABLE_KEY then it must succeed.
1081  *
1082  * Note that it is permissible to not decrypt a frame even if a key
1083  * for it has been uploaded to hardware, the stack will not make any
1084  * decision based on whether a key has been uploaded or not but rather
1085  * based on the receive flags.
1086  *
1087  * The &struct ieee80211_key_conf structure pointed to by the @key
1088  * parameter is guaranteed to be valid until another call to set_key()
1089  * removes it, but it can only be used as a cookie to differentiate
1090  * keys.
1091  *
1092  * In TKIP some HW need to be provided a phase 1 key, for RX decryption
1093  * acceleration (i.e. iwlwifi). Those drivers should provide update_tkip_key
1094  * handler.
1095  * The update_tkip_key() call updates the driver with the new phase 1 key.
1096  * This happens everytime the iv16 wraps around (every 65536 packets). The
1097  * set_key() call will happen only once for each key (unless the AP did
1098  * rekeying), it will not include a valid phase 1 key. The valid phase 1 key is
1099  * provided by update_tkip_key only. The trigger that makes mac80211 call this
1100  * handler is software decryption with wrap around of iv16.
1101  */
1102
1103 /**
1104  * DOC: Powersave support
1105  *
1106  * mac80211 has support for various powersave implementations.
1107  *
1108  * First, it can support hardware that handles all powersaving by
1109  * itself, such hardware should simply set the %IEEE80211_HW_SUPPORTS_PS
1110  * hardware flag. In that case, it will be told about the desired
1111  * powersave mode depending on the association status, and the driver
1112  * must take care of sending nullfunc frames when necessary, i.e. when
1113  * entering and leaving powersave mode. The driver is required to look at
1114  * the AID in beacons and signal to the AP that it woke up when it finds
1115  * traffic directed to it. This mode supports dynamic PS by simply
1116  * enabling/disabling PS.
1117  *
1118  * Additionally, such hardware may set the %IEEE80211_HW_SUPPORTS_DYNAMIC_PS
1119  * flag to indicate that it can support dynamic PS mode itself (see below).
1120  *
1121  * Other hardware designs cannot send nullfunc frames by themselves and also
1122  * need software support for parsing the TIM bitmap. This is also supported
1123  * by mac80211 by combining the %IEEE80211_HW_SUPPORTS_PS and
1124  * %IEEE80211_HW_PS_NULLFUNC_STACK flags. The hardware is of course still
1125  * required to pass up beacons. Additionally, in this case, mac80211 will
1126  * wake up the hardware when multicast traffic is announced in the beacon.
1127  *
1128  * FIXME: I don't think we can be fast enough in software when we want to
1129  *        receive multicast traffic?
1130  *
1131  * Dynamic powersave mode is an extension to normal powersave mode in which
1132  * the hardware stays awake for a user-specified period of time after sending
1133  * a frame so that reply frames need not be buffered and therefore delayed
1134  * to the next wakeup. This can either be supported by hardware, in which case
1135  * the driver needs to look at the @dynamic_ps_timeout hardware configuration
1136  * value, or by the stack if all nullfunc handling is in the stack.
1137  */
1138
1139 /**
1140  * DOC: Frame filtering
1141  *
1142  * mac80211 requires to see many management frames for proper
1143  * operation, and users may want to see many more frames when
1144  * in monitor mode. However, for best CPU usage and power consumption,
1145  * having as few frames as possible percolate through the stack is
1146  * desirable. Hence, the hardware should filter as much as possible.
1147  *
1148  * To achieve this, mac80211 uses filter flags (see below) to tell
1149  * the driver's configure_filter() function which frames should be
1150  * passed to mac80211 and which should be filtered out.
1151  *
1152  * The configure_filter() callback is invoked with the parameters
1153  * @mc_count and @mc_list for the combined multicast address list
1154  * of all virtual interfaces, @changed_flags telling which flags
1155  * were changed and @total_flags with the new flag states.
1156  *
1157  * If your device has no multicast address filters your driver will
1158  * need to check both the %FIF_ALLMULTI flag and the @mc_count
1159  * parameter to see whether multicast frames should be accepted
1160  * or dropped.
1161  *
1162  * All unsupported flags in @total_flags must be cleared.
1163  * Hardware does not support a flag if it is incapable of _passing_
1164  * the frame to the stack. Otherwise the driver must ignore
1165  * the flag, but not clear it.
1166  * You must _only_ clear the flag (announce no support for the
1167  * flag to mac80211) if you are not able to pass the packet type
1168  * to the stack (so the hardware always filters it).
1169  * So for example, you should clear @FIF_CONTROL, if your hardware
1170  * always filters control frames. If your hardware always passes
1171  * control frames to the kernel and is incapable of filtering them,
1172  * you do _not_ clear the @FIF_CONTROL flag.
1173  * This rule applies to all other FIF flags as well.
1174  */
1175
1176 /**
1177  * enum ieee80211_filter_flags - hardware filter flags
1178  *
1179  * These flags determine what the filter in hardware should be
1180  * programmed to let through and what should not be passed to the
1181  * stack. It is always safe to pass more frames than requested,
1182  * but this has negative impact on power consumption.
1183  *
1184  * @FIF_PROMISC_IN_BSS: promiscuous mode within your BSS,
1185  *      think of the BSS as your network segment and then this corresponds
1186  *      to the regular ethernet device promiscuous mode.
1187  *
1188  * @FIF_ALLMULTI: pass all multicast frames, this is used if requested
1189  *      by the user or if the hardware is not capable of filtering by
1190  *      multicast address.
1191  *
1192  * @FIF_FCSFAIL: pass frames with failed FCS (but you need to set the
1193  *      %RX_FLAG_FAILED_FCS_CRC for them)
1194  *
1195  * @FIF_PLCPFAIL: pass frames with failed PLCP CRC (but you need to set
1196  *      the %RX_FLAG_FAILED_PLCP_CRC for them
1197  *
1198  * @FIF_BCN_PRBRESP_PROMISC: This flag is set during scanning to indicate
1199  *      to the hardware that it should not filter beacons or probe responses
1200  *      by BSSID. Filtering them can greatly reduce the amount of processing
1201  *      mac80211 needs to do and the amount of CPU wakeups, so you should
1202  *      honour this flag if possible.
1203  *
1204  * @FIF_CONTROL: pass control frames, if PROMISC_IN_BSS is not set then
1205  *      only those addressed to this station
1206  *
1207  * @FIF_OTHER_BSS: pass frames destined to other BSSes
1208  */
1209 enum ieee80211_filter_flags {
1210         FIF_PROMISC_IN_BSS      = 1<<0,
1211         FIF_ALLMULTI            = 1<<1,
1212         FIF_FCSFAIL             = 1<<2,
1213         FIF_PLCPFAIL            = 1<<3,
1214         FIF_BCN_PRBRESP_PROMISC = 1<<4,
1215         FIF_CONTROL             = 1<<5,
1216         FIF_OTHER_BSS           = 1<<6,
1217 };
1218
1219 /**
1220  * enum ieee80211_ampdu_mlme_action - A-MPDU actions
1221  *
1222  * These flags are used with the ampdu_action() callback in
1223  * &struct ieee80211_ops to indicate which action is needed.
1224  * @IEEE80211_AMPDU_RX_START: start Rx aggregation
1225  * @IEEE80211_AMPDU_RX_STOP: stop Rx aggregation
1226  * @IEEE80211_AMPDU_TX_START: start Tx aggregation
1227  * @IEEE80211_AMPDU_TX_STOP: stop Tx aggregation
1228  * @IEEE80211_AMPDU_TX_RESUME: resume TX aggregation
1229  */
1230 enum ieee80211_ampdu_mlme_action {
1231         IEEE80211_AMPDU_RX_START,
1232         IEEE80211_AMPDU_RX_STOP,
1233         IEEE80211_AMPDU_TX_START,
1234         IEEE80211_AMPDU_TX_STOP,
1235         IEEE80211_AMPDU_TX_RESUME,
1236 };
1237
1238 /**
1239  * struct ieee80211_ops - callbacks from mac80211 to the driver
1240  *
1241  * This structure contains various callbacks that the driver may
1242  * handle or, in some cases, must handle, for example to configure
1243  * the hardware to a new channel or to transmit a frame.
1244  *
1245  * @tx: Handler that 802.11 module calls for each transmitted frame.
1246  *      skb contains the buffer starting from the IEEE 802.11 header.
1247  *      The low-level driver should send the frame out based on
1248  *      configuration in the TX control data. This handler should,
1249  *      preferably, never fail and stop queues appropriately, more
1250  *      importantly, however, it must never fail for A-MPDU-queues.
1251  *      This function should return NETDEV_TX_OK except in very
1252  *      limited cases.
1253  *      Must be implemented and atomic.
1254  *
1255  * @start: Called before the first netdevice attached to the hardware
1256  *      is enabled. This should turn on the hardware and must turn on
1257  *      frame reception (for possibly enabled monitor interfaces.)
1258  *      Returns negative error codes, these may be seen in userspace,
1259  *      or zero.
1260  *      When the device is started it should not have a MAC address
1261  *      to avoid acknowledging frames before a non-monitor device
1262  *      is added.
1263  *      Must be implemented.
1264  *
1265  * @stop: Called after last netdevice attached to the hardware
1266  *      is disabled. This should turn off the hardware (at least
1267  *      it must turn off frame reception.)
1268  *      May be called right after add_interface if that rejects
1269  *      an interface.
1270  *      Must be implemented.
1271  *
1272  * @add_interface: Called when a netdevice attached to the hardware is
1273  *      enabled. Because it is not called for monitor mode devices, @start
1274  *      and @stop must be implemented.
1275  *      The driver should perform any initialization it needs before
1276  *      the device can be enabled. The initial configuration for the
1277  *      interface is given in the conf parameter.
1278  *      The callback may refuse to add an interface by returning a
1279  *      negative error code (which will be seen in userspace.)
1280  *      Must be implemented.
1281  *
1282  * @remove_interface: Notifies a driver that an interface is going down.
1283  *      The @stop callback is called after this if it is the last interface
1284  *      and no monitor interfaces are present.
1285  *      When all interfaces are removed, the MAC address in the hardware
1286  *      must be cleared so the device no longer acknowledges packets,
1287  *      the mac_addr member of the conf structure is, however, set to the
1288  *      MAC address of the device going away.
1289  *      Hence, this callback must be implemented.
1290  *
1291  * @config: Handler for configuration requests. IEEE 802.11 code calls this
1292  *      function to change hardware configuration, e.g., channel.
1293  *      This function should never fail but returns a negative error code
1294  *      if it does.
1295  *
1296  * @config_interface: Handler for configuration requests related to interfaces
1297  *      (e.g. BSSID changes.)
1298  *      Returns a negative error code which will be seen in userspace.
1299  *
1300  * @bss_info_changed: Handler for configuration requests related to BSS
1301  *      parameters that may vary during BSS's lifespan, and may affect low
1302  *      level driver (e.g. assoc/disassoc status, erp parameters).
1303  *      This function should not be used if no BSS has been set, unless
1304  *      for association indication. The @changed parameter indicates which
1305  *      of the bss parameters has changed when a call is made.
1306  *
1307  * @configure_filter: Configure the device's RX filter.
1308  *      See the section "Frame filtering" for more information.
1309  *      This callback must be implemented and atomic.
1310  *
1311  * @set_tim: Set TIM bit. mac80211 calls this function when a TIM bit
1312  *      must be set or cleared for a given STA. Must be atomic.
1313  *
1314  * @set_key: See the section "Hardware crypto acceleration"
1315  *      This callback can sleep, and is only called between add_interface
1316  *      and remove_interface calls, i.e. while the given virtual interface
1317  *      is enabled.
1318  *      Returns a negative error code if the key can't be added.
1319  *
1320  * @update_tkip_key: See the section "Hardware crypto acceleration"
1321  *      This callback will be called in the context of Rx. Called for drivers
1322  *      which set IEEE80211_KEY_FLAG_TKIP_REQ_RX_P1_KEY.
1323  *
1324  * @hw_scan: Ask the hardware to service the scan request, no need to start
1325  *      the scan state machine in stack. The scan must honour the channel
1326  *      configuration done by the regulatory agent in the wiphy's registered
1327  *      bands. When the scan finishes, ieee80211_scan_completed() must be
1328  *      called; note that it also must be called when the scan cannot finish
1329  *      because the hardware is turned off! Anything else is a bug!
1330  *      Returns a negative error code which will be seen in userspace.
1331  *
1332  * @get_stats: Return low-level statistics.
1333  *      Returns zero if statistics are available.
1334  *
1335  * @get_tkip_seq: If your device implements TKIP encryption in hardware this
1336  *      callback should be provided to read the TKIP transmit IVs (both IV32
1337  *      and IV16) for the given key from hardware.
1338  *
1339  * @set_rts_threshold: Configuration of RTS threshold (if device needs it)
1340  *
1341  * @sta_notify: Notifies low level driver about addition, removal or power
1342  *      state transition of an associated station, AP,  IBSS/WDS/mesh peer etc.
1343  *      Must be atomic.
1344  *
1345  * @conf_tx: Configure TX queue parameters (EDCF (aifs, cw_min, cw_max),
1346  *      bursting) for a hardware TX queue.
1347  *      Returns a negative error code on failure.
1348  *
1349  * @get_tx_stats: Get statistics of the current TX queue status. This is used
1350  *      to get number of currently queued packets (queue length), maximum queue
1351  *      size (limit), and total number of packets sent using each TX queue
1352  *      (count). The 'stats' pointer points to an array that has hw->queues +
1353  *      hw->ampdu_queues items.
1354  *
1355  * @get_tsf: Get the current TSF timer value from firmware/hardware. Currently,
1356  *      this is only used for IBSS mode BSSID merging and debugging. Is not a
1357  *      required function.
1358  *
1359  * @set_tsf: Set the TSF timer to the specified value in the firmware/hardware.
1360  *      Currently, this is only used for IBSS mode debugging. Is not a
1361  *      required function.
1362  *
1363  * @reset_tsf: Reset the TSF timer and allow firmware/hardware to synchronize
1364  *      with other STAs in the IBSS. This is only used in IBSS mode. This
1365  *      function is optional if the firmware/hardware takes full care of
1366  *      TSF synchronization.
1367  *
1368  * @tx_last_beacon: Determine whether the last IBSS beacon was sent by us.
1369  *      This is needed only for IBSS mode and the result of this function is
1370  *      used to determine whether to reply to Probe Requests.
1371  *      Returns non-zero if this device sent the last beacon.
1372  *
1373  * @ampdu_action: Perform a certain A-MPDU action
1374  *      The RA/TID combination determines the destination and TID we want
1375  *      the ampdu action to be performed for. The action is defined through
1376  *      ieee80211_ampdu_mlme_action. Starting sequence number (@ssn)
1377  *      is the first frame we expect to perform the action on. Notice
1378  *      that TX/RX_STOP can pass NULL for this parameter.
1379  *      Returns a negative error code on failure.
1380  */
1381 struct ieee80211_ops {
1382         int (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb);
1383         int (*start)(struct ieee80211_hw *hw);
1384         void (*stop)(struct ieee80211_hw *hw);
1385         int (*add_interface)(struct ieee80211_hw *hw,
1386                              struct ieee80211_if_init_conf *conf);
1387         void (*remove_interface)(struct ieee80211_hw *hw,
1388                                  struct ieee80211_if_init_conf *conf);
1389         int (*config)(struct ieee80211_hw *hw, u32 changed);
1390         int (*config_interface)(struct ieee80211_hw *hw,
1391                                 struct ieee80211_vif *vif,
1392                                 struct ieee80211_if_conf *conf);
1393         void (*bss_info_changed)(struct ieee80211_hw *hw,
1394                                  struct ieee80211_vif *vif,
1395                                  struct ieee80211_bss_conf *info,
1396                                  u32 changed);
1397         void (*configure_filter)(struct ieee80211_hw *hw,
1398                                  unsigned int changed_flags,
1399                                  unsigned int *total_flags,
1400                                  int mc_count, struct dev_addr_list *mc_list);
1401         int (*set_tim)(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
1402                        bool set);
1403         int (*set_key)(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1404                        struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1405                        struct ieee80211_key_conf *key);
1406         void (*update_tkip_key)(struct ieee80211_hw *hw,
1407                         struct ieee80211_key_conf *conf, const u8 *address,
1408                         u32 iv32, u16 *phase1key);
1409         int (*hw_scan)(struct ieee80211_hw *hw,
1410                        struct cfg80211_scan_request *req);
1411         int (*get_stats)(struct ieee80211_hw *hw,
1412                          struct ieee80211_low_level_stats *stats);
1413         void (*get_tkip_seq)(struct ieee80211_hw *hw, u8 hw_key_idx,
1414                              u32 *iv32, u16 *iv16);
1415         int (*set_rts_threshold)(struct ieee80211_hw *hw, u32 value);
1416         void (*sta_notify)(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1417                         enum sta_notify_cmd, struct ieee80211_sta *sta);
1418         int (*conf_tx)(struct ieee80211_hw *hw, u16 queue,
1419                        const struct ieee80211_tx_queue_params *params);
1420         int (*get_tx_stats)(struct ieee80211_hw *hw,
1421                             struct ieee80211_tx_queue_stats *stats);
1422         u64 (*get_tsf)(struct ieee80211_hw *hw);
1423         void (*set_tsf)(struct ieee80211_hw *hw, u64 tsf);
1424         void (*reset_tsf)(struct ieee80211_hw *hw);
1425         int (*tx_last_beacon)(struct ieee80211_hw *hw);
1426         int (*ampdu_action)(struct ieee80211_hw *hw,
1427                             enum ieee80211_ampdu_mlme_action action,
1428                             struct ieee80211_sta *sta, u16 tid, u16 *ssn);
1429 };
1430
1431 /**
1432  * ieee80211_alloc_hw -  Allocate a new hardware device
1433  *
1434  * This must be called once for each hardware device. The returned pointer
1435  * must be used to refer to this device when calling other functions.
1436  * mac80211 allocates a private data area for the driver pointed to by
1437  * @priv in &struct ieee80211_hw, the size of this area is given as
1438  * @priv_data_len.
1439  *
1440  * @priv_data_len: length of private data
1441  * @ops: callbacks for this device
1442  */
1443 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1444                                         const struct ieee80211_ops *ops);
1445
1446 /**
1447  * ieee80211_register_hw - Register hardware device
1448  *
1449  * You must call this function before any other functions in
1450  * mac80211. Note that before a hardware can be registered, you
1451  * need to fill the contained wiphy's information.
1452  *
1453  * @hw: the device to register as returned by ieee80211_alloc_hw()
1454  */
1455 int ieee80211_register_hw(struct ieee80211_hw *hw);
1456
1457 #ifdef CONFIG_MAC80211_LEDS
1458 extern char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw);
1459 extern char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw);
1460 extern char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw);
1461 extern char *__ieee80211_get_radio_led_name(struct ieee80211_hw *hw);
1462 #endif
1463 /**
1464  * ieee80211_get_tx_led_name - get name of TX LED
1465  *
1466  * mac80211 creates a transmit LED trigger for each wireless hardware
1467  * that can be used to drive LEDs if your driver registers a LED device.
1468  * This function returns the name (or %NULL if not configured for LEDs)
1469  * of the trigger so you can automatically link the LED device.
1470  *
1471  * @hw: the hardware to get the LED trigger name for
1472  */
1473 static inline char *ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
1474 {
1475 #ifdef CONFIG_MAC80211_LEDS
1476         return __ieee80211_get_tx_led_name(hw);
1477 #else
1478         return NULL;
1479 #endif
1480 }
1481
1482 /**
1483  * ieee80211_get_rx_led_name - get name of RX LED
1484  *
1485  * mac80211 creates a receive LED trigger for each wireless hardware
1486  * that can be used to drive LEDs if your driver registers a LED device.
1487  * This function returns the name (or %NULL if not configured for LEDs)
1488  * of the trigger so you can automatically link the LED device.
1489  *
1490  * @hw: the hardware to get the LED trigger name for
1491  */
1492 static inline char *ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
1493 {
1494 #ifdef CONFIG_MAC80211_LEDS
1495         return __ieee80211_get_rx_led_name(hw);
1496 #else
1497         return NULL;
1498 #endif
1499 }
1500
1501 /**
1502  * ieee80211_get_assoc_led_name - get name of association LED
1503  *
1504  * mac80211 creates a association LED trigger for each wireless hardware
1505  * that can be used to drive LEDs if your driver registers a LED device.
1506  * This function returns the name (or %NULL if not configured for LEDs)
1507  * of the trigger so you can automatically link the LED device.
1508  *
1509  * @hw: the hardware to get the LED trigger name for
1510  */
1511 static inline char *ieee80211_get_assoc_led_name(struct ieee80211_hw *hw)
1512 {
1513 #ifdef CONFIG_MAC80211_LEDS
1514         return __ieee80211_get_assoc_led_name(hw);
1515 #else
1516         return NULL;
1517 #endif
1518 }
1519
1520 /**
1521  * ieee80211_get_radio_led_name - get name of radio LED
1522  *
1523  * mac80211 creates a radio change LED trigger for each wireless hardware
1524  * that can be used to drive LEDs if your driver registers a LED device.
1525  * This function returns the name (or %NULL if not configured for LEDs)
1526  * of the trigger so you can automatically link the LED device.
1527  *
1528  * @hw: the hardware to get the LED trigger name for
1529  */
1530 static inline char *ieee80211_get_radio_led_name(struct ieee80211_hw *hw)
1531 {
1532 #ifdef CONFIG_MAC80211_LEDS
1533         return __ieee80211_get_radio_led_name(hw);
1534 #else
1535         return NULL;
1536 #endif
1537 }
1538
1539 /**
1540  * ieee80211_unregister_hw - Unregister a hardware device
1541  *
1542  * This function instructs mac80211 to free allocated resources
1543  * and unregister netdevices from the networking subsystem.
1544  *
1545  * @hw: the hardware to unregister
1546  */
1547 void ieee80211_unregister_hw(struct ieee80211_hw *hw);
1548
1549 /**
1550  * ieee80211_free_hw - free hardware descriptor
1551  *
1552  * This function frees everything that was allocated, including the
1553  * private data for the driver. You must call ieee80211_unregister_hw()
1554  * before calling this function.
1555  *
1556  * @hw: the hardware to free
1557  */
1558 void ieee80211_free_hw(struct ieee80211_hw *hw);
1559
1560 /* trick to avoid symbol clashes with the ieee80211 subsystem */
1561 void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1562                     struct ieee80211_rx_status *status);
1563
1564 /**
1565  * ieee80211_rx - receive frame
1566  *
1567  * Use this function to hand received frames to mac80211. The receive
1568  * buffer in @skb must start with an IEEE 802.11 header or a radiotap
1569  * header if %RX_FLAG_RADIOTAP is set in the @status flags.
1570  *
1571  * This function may not be called in IRQ context. Calls to this function
1572  * for a single hardware must be synchronized against each other. Calls
1573  * to this function and ieee80211_rx_irqsafe() may not be mixed for a
1574  * single hardware.
1575  *
1576  * @hw: the hardware this frame came in on
1577  * @skb: the buffer to receive, owned by mac80211 after this call
1578  * @status: status of this frame; the status pointer need not be valid
1579  *      after this function returns
1580  */
1581 static inline void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1582                                 struct ieee80211_rx_status *status)
1583 {
1584         __ieee80211_rx(hw, skb, status);
1585 }
1586
1587 /**
1588  * ieee80211_rx_irqsafe - receive frame
1589  *
1590  * Like ieee80211_rx() but can be called in IRQ context
1591  * (internally defers to a tasklet.)
1592  *
1593  * Calls to this function and ieee80211_rx() may not be mixed for a
1594  * single hardware.
1595  *
1596  * @hw: the hardware this frame came in on
1597  * @skb: the buffer to receive, owned by mac80211 after this call
1598  * @status: status of this frame; the status pointer need not be valid
1599  *      after this function returns and is not freed by mac80211,
1600  *      it is recommended that it points to a stack area
1601  */
1602 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw,
1603                           struct sk_buff *skb,
1604                           struct ieee80211_rx_status *status);
1605
1606 /**
1607  * ieee80211_tx_status - transmit status callback
1608  *
1609  * Call this function for all transmitted frames after they have been
1610  * transmitted. It is permissible to not call this function for
1611  * multicast frames but this can affect statistics.
1612  *
1613  * This function may not be called in IRQ context. Calls to this function
1614  * for a single hardware must be synchronized against each other. Calls
1615  * to this function and ieee80211_tx_status_irqsafe() may not be mixed
1616  * for a single hardware.
1617  *
1618  * @hw: the hardware the frame was transmitted by
1619  * @skb: the frame that was transmitted, owned by mac80211 after this call
1620  */
1621 void ieee80211_tx_status(struct ieee80211_hw *hw,
1622                          struct sk_buff *skb);
1623
1624 /**
1625  * ieee80211_tx_status_irqsafe - IRQ-safe transmit status callback
1626  *
1627  * Like ieee80211_tx_status() but can be called in IRQ context
1628  * (internally defers to a tasklet.)
1629  *
1630  * Calls to this function and ieee80211_tx_status() may not be mixed for a
1631  * single hardware.
1632  *
1633  * @hw: the hardware the frame was transmitted by
1634  * @skb: the frame that was transmitted, owned by mac80211 after this call
1635  */
1636 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
1637                                  struct sk_buff *skb);
1638
1639 /**
1640  * ieee80211_beacon_get - beacon generation function
1641  * @hw: pointer obtained from ieee80211_alloc_hw().
1642  * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf.
1643  *
1644  * If the beacon frames are generated by the host system (i.e., not in
1645  * hardware/firmware), the low-level driver uses this function to receive
1646  * the next beacon frame from the 802.11 code. The low-level is responsible
1647  * for calling this function before beacon data is needed (e.g., based on
1648  * hardware interrupt). Returned skb is used only once and low-level driver
1649  * is responsible for freeing it.
1650  */
1651 struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1652                                      struct ieee80211_vif *vif);
1653
1654 /**
1655  * ieee80211_rts_get - RTS frame generation function
1656  * @hw: pointer obtained from ieee80211_alloc_hw().
1657  * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf.
1658  * @frame: pointer to the frame that is going to be protected by the RTS.
1659  * @frame_len: the frame length (in octets).
1660  * @frame_txctl: &struct ieee80211_tx_info of the frame.
1661  * @rts: The buffer where to store the RTS frame.
1662  *
1663  * If the RTS frames are generated by the host system (i.e., not in
1664  * hardware/firmware), the low-level driver uses this function to receive
1665  * the next RTS frame from the 802.11 code. The low-level is responsible
1666  * for calling this function before and RTS frame is needed.
1667  */
1668 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1669                        const void *frame, size_t frame_len,
1670                        const struct ieee80211_tx_info *frame_txctl,
1671                        struct ieee80211_rts *rts);
1672
1673 /**
1674  * ieee80211_rts_duration - Get the duration field for an RTS frame
1675  * @hw: pointer obtained from ieee80211_alloc_hw().
1676  * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf.
1677  * @frame_len: the length of the frame that is going to be protected by the RTS.
1678  * @frame_txctl: &struct ieee80211_tx_info of the frame.
1679  *
1680  * If the RTS is generated in firmware, but the host system must provide
1681  * the duration field, the low-level driver uses this function to receive
1682  * the duration field value in little-endian byteorder.
1683  */
1684 __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
1685                               struct ieee80211_vif *vif, size_t frame_len,
1686                               const struct ieee80211_tx_info *frame_txctl);
1687
1688 /**
1689  * ieee80211_ctstoself_get - CTS-to-self frame generation function
1690  * @hw: pointer obtained from ieee80211_alloc_hw().
1691  * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf.
1692  * @frame: pointer to the frame that is going to be protected by the CTS-to-self.
1693  * @frame_len: the frame length (in octets).
1694  * @frame_txctl: &struct ieee80211_tx_info of the frame.
1695  * @cts: The buffer where to store the CTS-to-self frame.
1696  *
1697  * If the CTS-to-self frames are generated by the host system (i.e., not in
1698  * hardware/firmware), the low-level driver uses this function to receive
1699  * the next CTS-to-self frame from the 802.11 code. The low-level is responsible
1700  * for calling this function before and CTS-to-self frame is needed.
1701  */
1702 void ieee80211_ctstoself_get(struct ieee80211_hw *hw,
1703                              struct ieee80211_vif *vif,
1704                              const void *frame, size_t frame_len,
1705                              const struct ieee80211_tx_info *frame_txctl,
1706                              struct ieee80211_cts *cts);
1707
1708 /**
1709  * ieee80211_ctstoself_duration - Get the duration field for a CTS-to-self frame
1710  * @hw: pointer obtained from ieee80211_alloc_hw().
1711  * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf.
1712  * @frame_len: the length of the frame that is going to be protected by the CTS-to-self.
1713  * @frame_txctl: &struct ieee80211_tx_info of the frame.
1714  *
1715  * If the CTS-to-self is generated in firmware, but the host system must provide
1716  * the duration field, the low-level driver uses this function to receive
1717  * the duration field value in little-endian byteorder.
1718  */
1719 __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
1720                                     struct ieee80211_vif *vif,
1721                                     size_t frame_len,
1722                                     const struct ieee80211_tx_info *frame_txctl);
1723
1724 /**
1725  * ieee80211_generic_frame_duration - Calculate the duration field for a frame
1726  * @hw: pointer obtained from ieee80211_alloc_hw().
1727  * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf.
1728  * @frame_len: the length of the frame.
1729  * @rate: the rate at which the frame is going to be transmitted.
1730  *
1731  * Calculate the duration field of some generic frame, given its
1732  * length and transmission rate (in 100kbps).
1733  */
1734 __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
1735                                         struct ieee80211_vif *vif,
1736                                         size_t frame_len,
1737                                         struct ieee80211_rate *rate);
1738
1739 /**
1740  * ieee80211_get_buffered_bc - accessing buffered broadcast and multicast frames
1741  * @hw: pointer as obtained from ieee80211_alloc_hw().
1742  * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf.
1743  *
1744  * Function for accessing buffered broadcast and multicast frames. If
1745  * hardware/firmware does not implement buffering of broadcast/multicast
1746  * frames when power saving is used, 802.11 code buffers them in the host
1747  * memory. The low-level driver uses this function to fetch next buffered
1748  * frame. In most cases, this is used when generating beacon frame. This
1749  * function returns a pointer to the next buffered skb or NULL if no more
1750  * buffered frames are available.
1751  *
1752  * Note: buffered frames are returned only after DTIM beacon frame was
1753  * generated with ieee80211_beacon_get() and the low-level driver must thus
1754  * call ieee80211_beacon_get() first. ieee80211_get_buffered_bc() returns
1755  * NULL if the previous generated beacon was not DTIM, so the low-level driver
1756  * does not need to check for DTIM beacons separately and should be able to
1757  * use common code for all beacons.
1758  */
1759 struct sk_buff *
1760 ieee80211_get_buffered_bc(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
1761
1762 /**
1763  * ieee80211_get_hdrlen_from_skb - get header length from data
1764  *
1765  * Given an skb with a raw 802.11 header at the data pointer this function
1766  * returns the 802.11 header length in bytes (not including encryption
1767  * headers). If the data in the sk_buff is too short to contain a valid 802.11
1768  * header the function returns 0.
1769  *
1770  * @skb: the frame
1771  */
1772 unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);
1773
1774 /**
1775  * ieee80211_hdrlen - get header length in bytes from frame control
1776  * @fc: frame control field in little-endian format
1777  */
1778 unsigned int ieee80211_hdrlen(__le16 fc);
1779
1780 /**
1781  * ieee80211_get_tkip_key - get a TKIP rc4 for skb
1782  *
1783  * This function computes a TKIP rc4 key for an skb. It computes
1784  * a phase 1 key if needed (iv16 wraps around). This function is to
1785  * be used by drivers which can do HW encryption but need to compute
1786  * to phase 1/2 key in SW.
1787  *
1788  * @keyconf: the parameter passed with the set key
1789  * @skb: the skb for which the key is needed
1790  * @type: TBD
1791  * @key: a buffer to which the key will be written
1792  */
1793 void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
1794                                 struct sk_buff *skb,
1795                                 enum ieee80211_tkip_key_type type, u8 *key);
1796 /**
1797  * ieee80211_wake_queue - wake specific queue
1798  * @hw: pointer as obtained from ieee80211_alloc_hw().
1799  * @queue: queue number (counted from zero).
1800  *
1801  * Drivers should use this function instead of netif_wake_queue.
1802  */
1803 void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue);
1804
1805 /**
1806  * ieee80211_stop_queue - stop specific queue
1807  * @hw: pointer as obtained from ieee80211_alloc_hw().
1808  * @queue: queue number (counted from zero).
1809  *
1810  * Drivers should use this function instead of netif_stop_queue.
1811  */
1812 void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue);
1813
1814 /**
1815  * ieee80211_queue_stopped - test status of the queue
1816  * @hw: pointer as obtained from ieee80211_alloc_hw().
1817  * @queue: queue number (counted from zero).
1818  *
1819  * Drivers should use this function instead of netif_stop_queue.
1820  */
1821
1822 int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue);
1823
1824 /**
1825  * ieee80211_stop_queues - stop all queues
1826  * @hw: pointer as obtained from ieee80211_alloc_hw().
1827  *
1828  * Drivers should use this function instead of netif_stop_queue.
1829  */
1830 void ieee80211_stop_queues(struct ieee80211_hw *hw);
1831
1832 /**
1833  * ieee80211_wake_queues - wake all queues
1834  * @hw: pointer as obtained from ieee80211_alloc_hw().
1835  *
1836  * Drivers should use this function instead of netif_wake_queue.
1837  */
1838 void ieee80211_wake_queues(struct ieee80211_hw *hw);
1839
1840 /**
1841  * ieee80211_scan_completed - completed hardware scan
1842  *
1843  * When hardware scan offload is used (i.e. the hw_scan() callback is
1844  * assigned) this function needs to be called by the driver to notify
1845  * mac80211 that the scan finished.
1846  *
1847  * @hw: the hardware that finished the scan
1848  * @aborted: set to true if scan was aborted
1849  */
1850 void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted);
1851
1852 /**
1853  * ieee80211_iterate_active_interfaces - iterate active interfaces
1854  *
1855  * This function iterates over the interfaces associated with a given
1856  * hardware that are currently active and calls the callback for them.
1857  * This function allows the iterator function to sleep, when the iterator
1858  * function is atomic @ieee80211_iterate_active_interfaces_atomic can
1859  * be used.
1860  *
1861  * @hw: the hardware struct of which the interfaces should be iterated over
1862  * @iterator: the iterator function to call
1863  * @data: first argument of the iterator function
1864  */
1865 void ieee80211_iterate_active_interfaces(struct ieee80211_hw *hw,
1866                                          void (*iterator)(void *data, u8 *mac,
1867                                                 struct ieee80211_vif *vif),
1868                                          void *data);
1869
1870 /**
1871  * ieee80211_iterate_active_interfaces_atomic - iterate active interfaces
1872  *
1873  * This function iterates over the interfaces associated with a given
1874  * hardware that are currently active and calls the callback for them.
1875  * This function requires the iterator callback function to be atomic,
1876  * if that is not desired, use @ieee80211_iterate_active_interfaces instead.
1877  *
1878  * @hw: the hardware struct of which the interfaces should be iterated over
1879  * @iterator: the iterator function to call, cannot sleep
1880  * @data: first argument of the iterator function
1881  */
1882 void ieee80211_iterate_active_interfaces_atomic(struct ieee80211_hw *hw,
1883                                                 void (*iterator)(void *data,
1884                                                     u8 *mac,
1885                                                     struct ieee80211_vif *vif),
1886                                                 void *data);
1887
1888 /**
1889  * ieee80211_start_tx_ba_session - Start a tx Block Ack session.
1890  * @hw: pointer as obtained from ieee80211_alloc_hw().
1891  * @ra: receiver address of the BA session recipient
1892  * @tid: the TID to BA on.
1893  *
1894  * Return: success if addBA request was sent, failure otherwise
1895  *
1896  * Although mac80211/low level driver/user space application can estimate
1897  * the need to start aggregation on a certain RA/TID, the session level
1898  * will be managed by the mac80211.
1899  */
1900 int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid);
1901
1902 /**
1903  * ieee80211_start_tx_ba_cb - low level driver ready to aggregate.
1904  * @hw: pointer as obtained from ieee80211_alloc_hw().
1905  * @ra: receiver address of the BA session recipient.
1906  * @tid: the TID to BA on.
1907  *
1908  * This function must be called by low level driver once it has
1909  * finished with preparations for the BA session.
1910  */
1911 void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid);
1912
1913 /**
1914  * ieee80211_start_tx_ba_cb_irqsafe - low level driver ready to aggregate.
1915  * @hw: pointer as obtained from ieee80211_alloc_hw().
1916  * @ra: receiver address of the BA session recipient.
1917  * @tid: the TID to BA on.
1918  *
1919  * This function must be called by low level driver once it has
1920  * finished with preparations for the BA session.
1921  * This version of the function is IRQ-safe.
1922  */
1923 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, const u8 *ra,
1924                                       u16 tid);
1925
1926 /**
1927  * ieee80211_stop_tx_ba_session - Stop a Block Ack session.
1928  * @hw: pointer as obtained from ieee80211_alloc_hw().
1929  * @ra: receiver address of the BA session recipient
1930  * @tid: the TID to stop BA.
1931  * @initiator: if indicates initiator DELBA frame will be sent.
1932  *
1933  * Return: error if no sta with matching da found, success otherwise
1934  *
1935  * Although mac80211/low level driver/user space application can estimate
1936  * the need to stop aggregation on a certain RA/TID, the session level
1937  * will be managed by the mac80211.
1938  */
1939 int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
1940                                  u8 *ra, u16 tid,
1941                                  enum ieee80211_back_parties initiator);
1942
1943 /**
1944  * ieee80211_stop_tx_ba_cb - low level driver ready to stop aggregate.
1945  * @hw: pointer as obtained from ieee80211_alloc_hw().
1946  * @ra: receiver address of the BA session recipient.
1947  * @tid: the desired TID to BA on.
1948  *
1949  * This function must be called by low level driver once it has
1950  * finished with preparations for the BA session tear down.
1951  */
1952 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid);
1953
1954 /**
1955  * ieee80211_stop_tx_ba_cb_irqsafe - low level driver ready to stop aggregate.
1956  * @hw: pointer as obtained from ieee80211_alloc_hw().
1957  * @ra: receiver address of the BA session recipient.
1958  * @tid: the desired TID to BA on.
1959  *
1960  * This function must be called by low level driver once it has
1961  * finished with preparations for the BA session tear down.
1962  * This version of the function is IRQ-safe.
1963  */
1964 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, const u8 *ra,
1965                                      u16 tid);
1966
1967 /**
1968  * ieee80211_find_sta - find a station
1969  *
1970  * @hw: pointer as obtained from ieee80211_alloc_hw()
1971  * @addr: station's address
1972  *
1973  * This function must be called under RCU lock and the
1974  * resulting pointer is only valid under RCU lock as well.
1975  */
1976 struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_hw *hw,
1977                                          const u8 *addr);
1978
1979
1980 /* Rate control API */
1981
1982 /**
1983  * struct ieee80211_tx_rate_control - rate control information for/from RC algo
1984  *
1985  * @hw: The hardware the algorithm is invoked for.
1986  * @sband: The band this frame is being transmitted on.
1987  * @bss_conf: the current BSS configuration
1988  * @reported_rate: The rate control algorithm can fill this in to indicate
1989  *      which rate should be reported to userspace as the current rate and
1990  *      used for rate calculations in the mesh network.
1991  * @rts: whether RTS will be used for this frame because it is longer than the
1992  *      RTS threshold
1993  * @short_preamble: whether mac80211 will request short-preamble transmission
1994  *      if the selected rate supports it
1995  * @max_rate_idx: user-requested maximum rate (not MCS for now)
1996  * @skb: the skb that will be transmitted, the control information in it needs
1997  *      to be filled in
1998  */
1999 struct ieee80211_tx_rate_control {
2000         struct ieee80211_hw *hw;
2001         struct ieee80211_supported_band *sband;
2002         struct ieee80211_bss_conf *bss_conf;
2003         struct sk_buff *skb;
2004         struct ieee80211_tx_rate reported_rate;
2005         bool rts, short_preamble;
2006         u8 max_rate_idx;
2007 };
2008
2009 struct rate_control_ops {
2010         struct module *module;
2011         const char *name;
2012         void *(*alloc)(struct ieee80211_hw *hw, struct dentry *debugfsdir);
2013         void (*free)(void *priv);
2014
2015         void *(*alloc_sta)(void *priv, struct ieee80211_sta *sta, gfp_t gfp);
2016         void (*rate_init)(void *priv, struct ieee80211_supported_band *sband,
2017                           struct ieee80211_sta *sta, void *priv_sta);
2018         void (*free_sta)(void *priv, struct ieee80211_sta *sta,
2019                          void *priv_sta);
2020
2021         void (*tx_status)(void *priv, struct ieee80211_supported_band *sband,
2022                           struct ieee80211_sta *sta, void *priv_sta,
2023                           struct sk_buff *skb);
2024         void (*get_rate)(void *priv, struct ieee80211_sta *sta, void *priv_sta,
2025                          struct ieee80211_tx_rate_control *txrc);
2026
2027         void (*add_sta_debugfs)(void *priv, void *priv_sta,
2028                                 struct dentry *dir);
2029         void (*remove_sta_debugfs)(void *priv, void *priv_sta);
2030 };
2031
2032 static inline int rate_supported(struct ieee80211_sta *sta,
2033                                  enum ieee80211_band band,
2034                                  int index)
2035 {
2036         return (sta == NULL || sta->supp_rates[band] & BIT(index));
2037 }
2038
2039 static inline s8
2040 rate_lowest_index(struct ieee80211_supported_band *sband,
2041                   struct ieee80211_sta *sta)
2042 {
2043         int i;
2044
2045         for (i = 0; i < sband->n_bitrates; i++)
2046                 if (rate_supported(sta, sband->band, i))
2047                         return i;
2048
2049         /* warn when we cannot find a rate. */
2050         WARN_ON(1);
2051
2052         return 0;
2053 }
2054
2055
2056 int ieee80211_rate_control_register(struct rate_control_ops *ops);
2057 void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
2058
2059 static inline bool
2060 conf_is_ht20(struct ieee80211_conf *conf)
2061 {
2062         return conf->channel_type == NL80211_CHAN_HT20;
2063 }
2064
2065 static inline bool
2066 conf_is_ht40_minus(struct ieee80211_conf *conf)
2067 {
2068         return conf->channel_type == NL80211_CHAN_HT40MINUS;
2069 }
2070
2071 static inline bool
2072 conf_is_ht40_plus(struct ieee80211_conf *conf)
2073 {
2074         return conf->channel_type == NL80211_CHAN_HT40PLUS;
2075 }
2076
2077 static inline bool
2078 conf_is_ht40(struct ieee80211_conf *conf)
2079 {
2080         return conf_is_ht40_minus(conf) || conf_is_ht40_plus(conf);
2081 }
2082
2083 static inline bool
2084 conf_is_ht(struct ieee80211_conf *conf)
2085 {
2086         return conf->channel_type != NL80211_CHAN_NO_HT;
2087 }
2088
2089 #endif /* MAC80211_H */