New: mac80211 stack from the wireless-dev tree
[openwrt.git] / package / mac80211 / src / mac80211 / ieee80211_i.h
1 /*
2  * Copyright 2002-2005, Instant802 Networks, Inc.
3  * Copyright 2005, Devicescape Software, Inc.
4  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #ifndef IEEE80211_I_H
12 #define IEEE80211_I_H
13
14 #include <linux/kernel.h>
15 #include <linux/device.h>
16 #include <linux/if_ether.h>
17 #include <linux/interrupt.h>
18 #include <linux/list.h>
19 #include <linux/netdevice.h>
20 #include <linux/skbuff.h>
21 #include <linux/workqueue.h>
22 #include <linux/types.h>
23 #include <linux/spinlock.h>
24 #include <net/wireless.h>
25 #include "ieee80211_key.h"
26 #include "sta_info.h"
27
28 /* ieee80211.o internal definitions, etc. These are not included into
29  * low-level drivers. */
30
31 #ifndef ETH_P_PAE
32 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
33 #endif /* ETH_P_PAE */
34
35 #define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
36
37 struct ieee80211_local;
38
39 #define BIT(x) (1 << (x))
40
41 #define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
42
43 /* Maximum number of broadcast/multicast frames to buffer when some of the
44  * associated stations are using power saving. */
45 #define AP_MAX_BC_BUFFER 128
46
47 /* Maximum number of frames buffered to all STAs, including multicast frames.
48  * Note: increasing this limit increases the potential memory requirement. Each
49  * frame can be up to about 2 kB long. */
50 #define TOTAL_MAX_TX_BUFFER 512
51
52 /* Required encryption head and tailroom */
53 #define IEEE80211_ENCRYPT_HEADROOM 8
54 #define IEEE80211_ENCRYPT_TAILROOM 12
55
56 /* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
57  * reception of at least three fragmented frames. This limit can be increased
58  * by changing this define, at the cost of slower frame reassembly and
59  * increased memory use (about 2 kB of RAM per entry). */
60 #define IEEE80211_FRAGMENT_MAX 4
61
62 /* Minimum and Maximum TSID used by EDCA. EDCA uses 0~7; HCCA uses 8~15 */
63 #define EDCA_TSID_MIN 0
64 #define EDCA_TSID_MAX 7
65
66 struct ieee80211_fragment_entry {
67         unsigned long first_frag_time;
68         unsigned int seq;
69         unsigned int rx_queue;
70         unsigned int last_frag;
71         unsigned int extra_len;
72         struct sk_buff_head skb_list;
73         int ccmp; /* Whether fragments were encrypted with CCMP */
74         u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
75 };
76
77
78 struct ieee80211_sta_bss {
79         struct list_head list;
80         struct ieee80211_sta_bss *hnext;
81         atomic_t users;
82
83         u8 bssid[ETH_ALEN];
84         u8 ssid[IEEE80211_MAX_SSID_LEN];
85         size_t ssid_len;
86         u16 capability; /* host byte order */
87         int hw_mode;
88         int channel;
89         int freq;
90         int rssi, signal, noise;
91         u8 *wpa_ie;
92         size_t wpa_ie_len;
93         u8 *rsn_ie;
94         size_t rsn_ie_len;
95         u8 *wmm_ie;
96         size_t wmm_ie_len;
97         u8 *ht_ie;
98         size_t ht_ie_len;
99 #define IEEE80211_MAX_SUPP_RATES 32
100         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
101         size_t supp_rates_len;
102         int beacon_int;
103         u64 timestamp;
104
105         int probe_resp;
106         unsigned long last_update;
107
108 };
109
110
111 typedef enum {
112         TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
113 } ieee80211_txrx_result;
114
115 struct ieee80211_txrx_data {
116         struct sk_buff *skb;
117         struct net_device *dev;
118         struct ieee80211_local *local;
119         struct ieee80211_sub_if_data *sdata;
120         struct sta_info *sta;
121         u16 fc, ethertype;
122         struct ieee80211_key *key;
123         unsigned int fragmented:1; /* whether the MSDU was fragmented */
124         union {
125                 struct {
126                         struct ieee80211_tx_control *control;
127                         unsigned int unicast:1;
128                         unsigned int ps_buffered:1;
129                         unsigned int short_preamble:1;
130                         unsigned int probe_last_frag:1;
131                         struct ieee80211_hw_mode *mode;
132                         struct ieee80211_rate *rate;
133                         /* use this rate (if set) for last fragment; rate can
134                          * be set to lower rate for the first fragments, e.g.,
135                          * when using CTS protection with IEEE 802.11g. */
136                         struct ieee80211_rate *last_frag_rate;
137                         int last_frag_hwrate;
138                         int mgmt_interface;
139
140                         /* Extra fragments (in addition to the first fragment
141                          * in skb) */
142                         int num_extra_frag;
143                         struct sk_buff **extra_frag;
144                 } tx;
145                 struct {
146                         struct ieee80211_rx_status *status;
147                         int sent_ps_buffered;
148                         int queue;
149                         int load;
150                         u16 qos_control;
151                         unsigned int in_scan:1;
152                         /* frame is destined to interface currently processed
153                          * (including multicast frames) */
154                         unsigned int ra_match:1;
155                         unsigned int is_agg_frame:1;
156                 } rx;
157         } u;
158 #ifdef CONFIG_HOSTAPD_WPA_TESTING
159         int wpa_test;
160 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
161 };
162
163 /* Stored in sk_buff->cb */
164 struct ieee80211_tx_packet_data {
165         int ifindex;
166         unsigned long jiffies;
167         unsigned int req_tx_status:1;
168         unsigned int do_not_encrypt:1;
169         unsigned int requeue:1;
170         unsigned int mgmt_iface:1;
171         unsigned int queue:4;
172 };
173
174 struct ieee80211_tx_stored_packet {
175         struct ieee80211_tx_control control;
176         struct sk_buff *skb;
177         int num_extra_frag;
178         struct sk_buff **extra_frag;
179         int last_frag_rateidx;
180         int last_frag_hwrate;
181         struct ieee80211_rate *last_frag_rate;
182         unsigned int last_frag_rate_ctrl_probe:1;
183 };
184
185 struct sta_ts_data {
186         enum {
187                 TS_STATUS_UNUSED        = 0,
188                 TS_STATUS_ACTIVE        = 1,
189                 TS_STATUS_INACTIVE      = 2,
190                 TS_STATUS_THROTTLING    = 3,
191         } status;
192         u8 dialog_token;
193         u8 up;
194         u32 admitted_time_usec;
195         u32 used_time_usec;
196 };
197
198 typedef ieee80211_txrx_result (*ieee80211_tx_handler)
199 (struct ieee80211_txrx_data *tx);
200
201 typedef ieee80211_txrx_result (*ieee80211_rx_handler)
202 (struct ieee80211_txrx_data *rx);
203
204 struct ieee80211_if_ap {
205         u8 *beacon_head, *beacon_tail;
206         int beacon_head_len, beacon_tail_len;
207
208         u8 ssid[IEEE80211_MAX_SSID_LEN];
209         size_t ssid_len;
210         u8 *generic_elem;
211         size_t generic_elem_len;
212
213         /* yes, this looks ugly, but guarantees that we can later use
214          * bitmap_empty :)
215          * NB: don't ever use set_bit, use bss_tim_set/bss_tim_clear! */
216         u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
217         atomic_t num_sta_ps; /* number of stations in PS mode */
218         struct sk_buff_head ps_bc_buf;
219         int dtim_period, dtim_count;
220         int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
221         int max_ratectrl_rateidx; /* max TX rateidx for rate control */
222         int num_beacons; /* number of TXed beacon frames for this BSS */
223 };
224
225 struct ieee80211_if_wds {
226         u8 remote_addr[ETH_ALEN];
227         struct sta_info *sta;
228 };
229
230 struct ieee80211_if_vlan {
231         u8 id;
232 };
233
234 struct ieee80211_if_sta {
235         enum {
236                 IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
237                 IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
238                 IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
239         } state;
240         struct timer_list timer;
241         struct work_struct work;
242         struct timer_list admit_timer; /* Recompute EDCA admitted time */
243         u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
244         u8 ssid[IEEE80211_MAX_SSID_LEN];
245         size_t ssid_len;
246         u16 aid;
247         u16 ap_capab, capab;
248         u8 *extra_ie; /* to be added to the end of AssocReq */
249         size_t extra_ie_len;
250
251         /* The last AssocReq/Resp IEs */
252         u8 *assocreq_ies, *assocresp_ies;
253         size_t assocreq_ies_len, assocresp_ies_len;
254
255         int auth_tries, assoc_tries;
256
257         unsigned int ssid_set:1;
258         unsigned int bssid_set:1;
259         unsigned int prev_bssid_set:1;
260         unsigned int authenticated:1;
261         unsigned int associated:1;
262         unsigned int probereq_poll:1;
263         unsigned int use_protection:1;
264         unsigned int create_ibss:1;
265         unsigned int mixed_cell:1;
266         unsigned int wmm_enabled:1;
267         unsigned int ht_enabled:1;
268         unsigned int auto_ssid_sel:1;
269         unsigned int auto_bssid_sel:1;
270         unsigned int auto_channel_sel:1;
271 #define IEEE80211_STA_REQ_SCAN 0
272 #define IEEE80211_STA_REQ_AUTH 1
273 #define IEEE80211_STA_REQ_RUN  2
274         unsigned long request;
275         struct sk_buff_head skb_queue;
276
277         int key_mgmt;
278         unsigned long last_probe;
279
280 #define IEEE80211_AUTH_ALG_OPEN BIT(0)
281 #define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
282 #define IEEE80211_AUTH_ALG_LEAP BIT(2)
283         unsigned int auth_algs; /* bitfield of allowed auth algs */
284         int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
285         int auth_transaction;
286
287         unsigned long ibss_join_req;
288         struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
289         u32 supp_rates_bits;
290
291         int wmm_last_param_set;
292
293         u32 dot11EDCAAveragingPeriod;
294         u32 MPDUExchangeTime;
295 #define STA_TSID_NUM   16
296 #define STA_TSDIR_NUM  2
297         /* EDCA: 0~7, HCCA: 8~15 */
298         struct sta_ts_data ts_data[STA_TSID_NUM][STA_TSDIR_NUM];
299 };
300
301
302 struct ieee80211_sub_if_data {
303         struct list_head list;
304         unsigned int type;
305
306         struct wireless_dev wdev;
307
308         struct net_device *dev;
309         struct ieee80211_local *local;
310
311         int mc_count;
312         unsigned int allmulti:1;
313         unsigned int promisc:1;
314
315         struct net_device_stats stats;
316         int drop_unencrypted;
317         int eapol; /* 0 = process EAPOL frames as normal data frames,
318                     * 1 = send EAPOL frames through wlan#ap to hostapd
319                     *     (default) */
320         int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
321                          * port */
322
323         u16 sequence;
324
325         /* Fragment table for host-based reassembly */
326         struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
327         unsigned int fragment_next;
328
329 #define NUM_DEFAULT_KEYS 4
330         struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
331         struct ieee80211_key *default_key;
332
333         struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
334
335         union {
336                 struct ieee80211_if_ap ap;
337                 struct ieee80211_if_wds wds;
338                 struct ieee80211_if_vlan vlan;
339                 struct ieee80211_if_sta sta;
340         } u;
341         int channel_use;
342         int channel_use_raw;
343
344 #ifdef CONFIG_MAC80211_DEBUGFS
345         struct dentry *debugfsdir;
346         union {
347                 struct {
348                         struct dentry *channel_use;
349                         struct dentry *drop_unencrypted;
350                         struct dentry *eapol;
351                         struct dentry *ieee8021_x;
352                         struct dentry *state;
353                         struct dentry *bssid;
354                         struct dentry *prev_bssid;
355                         struct dentry *ssid_len;
356                         struct dentry *aid;
357                         struct dentry *ap_capab;
358                         struct dentry *capab;
359                         struct dentry *extra_ie_len;
360                         struct dentry *auth_tries;
361                         struct dentry *assoc_tries;
362                         struct dentry *auth_algs;
363                         struct dentry *auth_alg;
364                         struct dentry *auth_transaction;
365                         struct dentry *flags;
366                         struct dentry *qos_dir;
367                         struct {
368                                 struct dentry *addts_11e;
369                                 struct dentry *addts_wmm;
370                                 struct dentry *delts_11e;
371                                 struct dentry *delts_wmm;
372                                 struct dentry *dls_mac;
373                                 struct dentry *dls_op;
374                         } qos;
375                         struct dentry *tsinfo_dir;
376                         struct {
377                                 struct dentry *tsid;
378                                 struct dentry *direction;
379                                 struct dentry *up;
380                         } tsinfo;
381                         struct dentry *tspec_dir;
382                         struct {
383                                 struct dentry *nominal_msdu_size;
384                                 struct dentry *max_msdu_size;
385                                 struct dentry *min_service_interval;
386                                 struct dentry *max_service_interval;
387                                 struct dentry *inactivity_interval;
388                                 struct dentry *suspension_interval;
389                                 struct dentry *service_start_time;
390                                 struct dentry *min_data_rate;
391                                 struct dentry *mean_data_rate;
392                                 struct dentry *peak_data_rate;
393                                 struct dentry *burst_size;
394                                 struct dentry *delay_bound;
395                                 struct dentry *min_phy_rate;
396                                 struct dentry *surplus_band_allow;
397                                 struct dentry *medium_time;
398                         } tspec;
399                 } sta;
400                 struct {
401                         struct dentry *channel_use;
402                         struct dentry *drop_unencrypted;
403                         struct dentry *eapol;
404                         struct dentry *ieee8021_x;
405                         struct dentry *num_sta_ps;
406                         struct dentry *dtim_period;
407                         struct dentry *dtim_count;
408                         struct dentry *num_beacons;
409                         struct dentry *force_unicast_rateidx;
410                         struct dentry *max_ratectrl_rateidx;
411                         struct dentry *num_buffered_multicast;
412                         struct dentry *beacon_head_len;
413                         struct dentry *beacon_tail_len;
414                 } ap;
415                 struct {
416                         struct dentry *channel_use;
417                         struct dentry *drop_unencrypted;
418                         struct dentry *eapol;
419                         struct dentry *ieee8021_x;
420                         struct dentry *peer;
421                 } wds;
422                 struct {
423                         struct dentry *channel_use;
424                         struct dentry *drop_unencrypted;
425                         struct dentry *eapol;
426                         struct dentry *ieee8021_x;
427                         struct dentry *vlan_id;
428                 } vlan;
429                 struct {
430                         struct dentry *mode;
431                 } monitor;
432                 struct dentry *default_key;
433         } debugfs;
434 #endif
435 };
436
437 #define IEEE80211_DEV_TO_SUB_IF(dev) netdev_priv(dev)
438
439 enum {
440         IEEE80211_RX_MSG        = 1,
441         IEEE80211_TX_STATUS_MSG = 2,
442 };
443
444 struct ieee80211_local {
445         /* embed the driver visible part.
446          * don't cast (use the static inlines below), but we keep
447          * it first anyway so they become a no-op */
448         struct ieee80211_hw hw;
449
450         const struct ieee80211_ops *ops;
451
452         /* List of registered struct ieee80211_hw_mode */
453         struct list_head modes_list;
454
455         struct net_device *mdev; /* wmaster# - "master" 802.11 device */
456         struct net_device *apdev; /* wlan#ap - management frames (hostapd) */
457         int open_count;
458         int monitors;
459         struct iw_statistics wstats;
460         u8 wstats_flags;
461
462         enum {
463                 IEEE80211_DEV_UNINITIALIZED = 0,
464                 IEEE80211_DEV_REGISTERED,
465                 IEEE80211_DEV_UNREGISTERED,
466         } reg_state;
467
468         /* Tasklet and skb queue to process calls from IRQ mode. All frames
469          * added to skb_queue will be processed, but frames in
470          * skb_queue_unreliable may be dropped if the total length of these
471          * queues increases over the limit. */
472 #define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
473         struct tasklet_struct tasklet;
474         struct sk_buff_head skb_queue;
475         struct sk_buff_head skb_queue_unreliable;
476
477         /* Station data structures */
478         spinlock_t sta_lock; /* mutex for STA data structures */
479         int num_sta; /* number of stations in sta_list */
480         struct list_head sta_list;
481         struct list_head deleted_sta_list;
482         struct sta_info *sta_hash[STA_HASH_SIZE];
483         struct timer_list sta_cleanup;
484
485         unsigned long state[NUM_TX_DATA_QUEUES];
486         struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES];
487         struct tasklet_struct tx_pending_tasklet;
488
489         int mc_count;   /* total count of multicast entries in all interfaces */
490         int iff_allmultis, iff_promiscs;
491                         /* number of interfaces with corresponding IFF_ flags */
492
493         struct rate_control_ref *rate_ctrl;
494
495         int next_mode; /* MODE_IEEE80211*
496                         * The mode preference for next channel change. This is
497                         * used to select .11g vs. .11b channels (or 4.9 GHz vs.
498                         * .11a) when the channel number is not unique. */
499
500         /* Supported and basic rate filters for different modes. These are
501          * pointers to -1 terminated lists and rates in 100 kbps units. */
502         int *supp_rates[NUM_IEEE80211_MODES];
503         int *basic_rates[NUM_IEEE80211_MODES];
504
505         int rts_threshold;
506         int cts_protect_erp_frames;
507         int fragmentation_threshold;
508         int short_retry_limit; /* dot11ShortRetryLimit */
509         int long_retry_limit; /* dot11LongRetryLimit */
510         int short_preamble; /* use short preamble with IEEE 802.11b */
511
512         struct crypto_blkcipher *wep_tx_tfm;
513         struct crypto_blkcipher *wep_rx_tfm;
514         u32 wep_iv;
515         int key_tx_rx_threshold; /* number of times any key can be used in TX
516                                   * or RX before generating a rekey
517                                   * notification; 0 = notification disabled. */
518
519         int bridge_packets; /* bridge packets between associated stations and
520                              * deliver multicast frames both back to wireless
521                              * media and to the local net stack */
522
523         ieee80211_rx_handler *rx_pre_handlers;
524         ieee80211_rx_handler *rx_handlers;
525         ieee80211_tx_handler *tx_handlers;
526
527         rwlock_t sub_if_lock; /* Protects sub_if_list. Cannot be taken under
528                                * sta_bss_lock or sta_lock. */
529         struct list_head sub_if_list;
530         int sta_scanning;
531         int scan_channel_idx;
532         enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
533         unsigned long last_scan_completed;
534         struct delayed_work scan_work;
535         struct net_device *scan_dev;
536         struct ieee80211_channel *oper_channel, *scan_channel;
537         struct ieee80211_hw_mode *oper_hw_mode, *scan_hw_mode;
538         u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
539         size_t scan_ssid_len;
540         struct list_head sta_bss_list;
541         struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
542         spinlock_t sta_bss_lock;
543 #define IEEE80211_SCAN_MATCH_SSID BIT(0)
544 #define IEEE80211_SCAN_WPA_ONLY BIT(1)
545 #define IEEE80211_SCAN_EXTRA_INFO BIT(2)
546         int scan_flags;
547
548 #ifdef CONFIG_HOSTAPD_WPA_TESTING
549         u32 wpa_trigger;
550 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
551         /* SNMP counters */
552         /* dot11CountersTable */
553         u32 dot11TransmittedFragmentCount;
554         u32 dot11MulticastTransmittedFrameCount;
555         u32 dot11FailedCount;
556         u32 dot11RetryCount;
557         u32 dot11MultipleRetryCount;
558         u32 dot11FrameDuplicateCount;
559         u32 dot11ReceivedFragmentCount;
560         u32 dot11MulticastReceivedFrameCount;
561         u32 dot11TransmittedFrameCount;
562         u32 dot11WEPUndecryptableCount;
563
564 #ifdef CONFIG_MAC80211_LEDS
565         int tx_led_counter, rx_led_counter;
566         struct led_trigger *tx_led, *rx_led;
567         char tx_led_name[32], rx_led_name[32];
568 #endif
569
570         u32 channel_use;
571         u32 channel_use_raw;
572         u32 stat_time;
573         struct timer_list stat_timer;
574
575 #ifdef CONFIG_MAC80211_DEBUGFS
576         struct work_struct sta_debugfs_add;
577 #endif
578
579         enum {
580                 STA_ANTENNA_SEL_AUTO = 0,
581                 STA_ANTENNA_SEL_SW_CTRL = 1,
582                 STA_ANTENNA_SEL_SW_CTRL_DEBUG = 2
583         } sta_antenna_sel;
584
585         int rate_ctrl_num_up, rate_ctrl_num_down;
586
587 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
588         /* TX/RX handler statistics */
589         unsigned int tx_handlers_drop;
590         unsigned int tx_handlers_queued;
591         unsigned int tx_handlers_drop_unencrypted;
592         unsigned int tx_handlers_drop_fragment;
593         unsigned int tx_handlers_drop_wep;
594         unsigned int tx_handlers_drop_not_assoc;
595         unsigned int tx_handlers_drop_unauth_port;
596         unsigned int rx_handlers_drop;
597         unsigned int rx_handlers_queued;
598         unsigned int rx_handlers_drop_nullfunc;
599         unsigned int rx_handlers_drop_defrag;
600         unsigned int rx_handlers_drop_short;
601         unsigned int rx_handlers_drop_passive_scan;
602         unsigned int tx_expand_skb_head;
603         unsigned int tx_expand_skb_head_cloned;
604         unsigned int rx_expand_skb_head;
605         unsigned int rx_expand_skb_head2;
606         unsigned int rx_handlers_fragments;
607         unsigned int tx_status_drop;
608         unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
609         unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
610 #define I802_DEBUG_INC(c) (c)++
611 #else /* CONFIG_MAC80211_DEBUG_COUNTERS */
612 #define I802_DEBUG_INC(c) do { } while (0)
613 #endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
614
615
616         int default_wep_only; /* only default WEP keys are used with this
617                                * interface; this is used to decide when hwaccel
618                                * can be used with default keys */
619         int total_ps_buffered; /* total number of all buffered unicast and
620                                 * multicast packets for power saving stations
621                                 */
622         int allow_broadcast_always; /* whether to allow TX of broadcast frames
623                                      * even when there are no associated STAs
624                                      */
625
626         int wifi_wme_noack_test;
627         unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
628
629         unsigned int enabled_modes; /* bitfield of allowed modes;
630                                       * (1 << MODE_*) */
631         unsigned int hw_modes; /* bitfield of supported hardware modes;
632                                 * (1 << MODE_*) */
633
634         int user_space_mlme;
635
636 #ifdef CONFIG_MAC80211_DEBUGFS
637         struct local_debugfsdentries {
638                 struct dentry *channel;
639                 struct dentry *frequency;
640                 struct dentry *radar_detect;
641                 struct dentry *antenna_sel_tx;
642                 struct dentry *antenna_sel_rx;
643                 struct dentry *bridge_packets;
644                 struct dentry *key_tx_rx_threshold;
645                 struct dentry *rts_threshold;
646                 struct dentry *fragmentation_threshold;
647                 struct dentry *short_retry_limit;
648                 struct dentry *long_retry_limit;
649                 struct dentry *total_ps_buffered;
650                 struct dentry *mode;
651                 struct dentry *wep_iv;
652                 struct dentry *rate_ctrl_alg;
653                 struct dentry *tx_power_reduction;
654                 struct dentry *modes;
655                 struct dentry *statistics;
656                 struct local_debugfsdentries_statsdentries {
657                         struct dentry *transmitted_fragment_count;
658                         struct dentry *multicast_transmitted_frame_count;
659                         struct dentry *failed_count;
660                         struct dentry *retry_count;
661                         struct dentry *multiple_retry_count;
662                         struct dentry *frame_duplicate_count;
663                         struct dentry *received_fragment_count;
664                         struct dentry *multicast_received_frame_count;
665                         struct dentry *transmitted_frame_count;
666                         struct dentry *wep_undecryptable_count;
667                         struct dentry *num_scans;
668 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
669                         struct dentry *tx_handlers_drop;
670                         struct dentry *tx_handlers_queued;
671                         struct dentry *tx_handlers_drop_unencrypted;
672                         struct dentry *tx_handlers_drop_fragment;
673                         struct dentry *tx_handlers_drop_wep;
674                         struct dentry *tx_handlers_drop_not_assoc;
675                         struct dentry *tx_handlers_drop_unauth_port;
676                         struct dentry *rx_handlers_drop;
677                         struct dentry *rx_handlers_queued;
678                         struct dentry *rx_handlers_drop_nullfunc;
679                         struct dentry *rx_handlers_drop_defrag;
680                         struct dentry *rx_handlers_drop_short;
681                         struct dentry *rx_handlers_drop_passive_scan;
682                         struct dentry *tx_expand_skb_head;
683                         struct dentry *tx_expand_skb_head_cloned;
684                         struct dentry *rx_expand_skb_head;
685                         struct dentry *rx_expand_skb_head2;
686                         struct dentry *rx_handlers_fragments;
687                         struct dentry *tx_status_drop;
688                         struct dentry *wme_tx_queue;
689                         struct dentry *wme_rx_queue;
690 #endif
691                         struct dentry *dot11ACKFailureCount;
692                         struct dentry *dot11RTSFailureCount;
693                         struct dentry *dot11FCSErrorCount;
694                         struct dentry *dot11RTSSuccessCount;
695                 } stats;
696                 struct dentry *stations;
697                 struct dentry *keys;
698         } debugfs;
699 #endif
700 };
701
702 enum sta_link_direction {
703         STA_TS_UPLINK = 0,
704         STA_TS_DOWNLINK = 1,
705 };
706
707 static inline struct ieee80211_local *hw_to_local(
708         struct ieee80211_hw *hw)
709 {
710         return container_of(hw, struct ieee80211_local, hw);
711 }
712
713 static inline struct ieee80211_hw *local_to_hw(
714         struct ieee80211_local *local)
715 {
716         return &local->hw;
717 }
718
719 enum ieee80211_link_state_t {
720         IEEE80211_LINK_STATE_XOFF = 0,
721         IEEE80211_LINK_STATE_PENDING,
722 };
723
724 struct sta_attribute {
725         struct attribute attr;
726         ssize_t (*show)(const struct sta_info *, char *buf);
727         ssize_t (*store)(struct sta_info *, const char *buf, size_t count);
728 };
729
730 static inline void __bss_tim_set(struct ieee80211_if_ap *bss, int aid)
731 {
732         /*
733          * This format has ben mandated by the IEEE specifications,
734          * so this line may not be changed to use the __set_bit() format.
735          */
736         bss->tim[(aid)/8] |= 1<<((aid) % 8);
737 }
738
739 static inline void bss_tim_set(struct ieee80211_local *local,
740                                struct ieee80211_if_ap *bss, int aid)
741 {
742         spin_lock_bh(&local->sta_lock);
743         __bss_tim_set(bss, aid);
744         spin_unlock_bh(&local->sta_lock);
745 }
746
747 static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, int aid)
748 {
749         /*
750          * This format has ben mandated by the IEEE specifications,
751          * so this line may not be changed to use the __clear_bit() format.
752          */
753         bss->tim[(aid)/8] &= !(1<<((aid) % 8));
754 }
755
756 static inline void bss_tim_clear(struct ieee80211_local *local,
757                                  struct ieee80211_if_ap *bss, int aid)
758 {
759         spin_lock_bh(&local->sta_lock);
760         __bss_tim_clear(bss, aid);
761         spin_unlock_bh(&local->sta_lock);
762 }
763
764 /**
765  * ieee80211_is_erp_rate - Check if a rate is an ERP rate
766  * @phymode: The PHY-mode for this rate (MODE_IEEE80211...)
767  * @rate: Transmission rate to check, in 100 kbps
768  *
769  * Check if a given rate is an Extended Rate PHY (ERP) rate.
770  */
771 static inline int ieee80211_is_erp_rate(int phymode, int rate)
772 {
773         if (phymode == MODE_IEEE80211G) {
774                 if (rate != 10 && rate != 20 &&
775                     rate != 55 && rate != 110)
776                         return 1;
777         }
778         return 0;
779 }
780
781 /* ieee80211.c */
782 int ieee80211_hw_config(struct ieee80211_local *local);
783 int ieee80211_if_config(struct net_device *dev);
784 int ieee80211_if_config_beacon(struct net_device *dev);
785 struct ieee80211_key_conf *
786 ieee80211_key_data2conf(struct ieee80211_local *local,
787                         const struct ieee80211_key *data);
788 struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
789                                           int idx, size_t key_len, gfp_t flags);
790 void ieee80211_key_free(struct ieee80211_key *key);
791 void ieee80211_rx_mgmt(struct ieee80211_local *local, struct sk_buff *skb,
792                        struct ieee80211_rx_status *status, u32 msg_type);
793 void ieee80211_prepare_rates(struct ieee80211_local *local,
794                              struct ieee80211_hw_mode *mode);
795 void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
796 int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr);
797 void ieee80211_if_setup(struct net_device *dev);
798 void ieee80211_if_mgmt_setup(struct net_device *dev);
799 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
800                                  const char *name);
801 struct net_device_stats *ieee80211_dev_stats(struct net_device *dev);
802
803 /* ieee80211_ioctl.c */
804 int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
805 extern const struct iw_handler_def ieee80211_iw_handler_def;
806
807 /* Set hw encryption from ieee80211 */
808 int ieee80211_set_hw_encryption(struct net_device *dev,
809                                 struct sta_info *sta, u8 addr[ETH_ALEN],
810                                 struct ieee80211_key *key);
811 void ieee80211_update_default_wep_only(struct ieee80211_local *local);
812
813
814 /* Least common multiple of the used rates (in 100 kbps). This is used to
815  * calculate rate_inv values for each rate so that only integers are needed. */
816 #define CHAN_UTIL_RATE_LCM 95040
817 /* 1 usec is 1/8 * (95040/10) = 1188 */
818 #define CHAN_UTIL_PER_USEC 1188
819 /* Amount of bits to shift the result right to scale the total utilization
820  * to values that will not wrap around 32-bit integers. */
821 #define CHAN_UTIL_SHIFT 9
822 /* Theoretical maximum of channel utilization counter in 10 ms (stat_time=1):
823  * (CHAN_UTIL_PER_USEC * 10000) >> CHAN_UTIL_SHIFT = 23203. So dividing the
824  * raw value with about 23 should give utilization in 10th of a percentage
825  * (1/1000). However, utilization is only estimated and not all intervals
826  * between frames etc. are calculated. 18 seems to give numbers that are closer
827  * to the real maximum. */
828 #define CHAN_UTIL_PER_10MS 18
829 #define CHAN_UTIL_HDR_LONG (202 * CHAN_UTIL_PER_USEC)
830 #define CHAN_UTIL_HDR_SHORT (40 * CHAN_UTIL_PER_USEC)
831
832
833 /* ieee80211_ioctl.c */
834 int ieee80211_set_compression(struct ieee80211_local *local,
835                               struct net_device *dev, struct sta_info *sta);
836 int ieee80211_init_client(struct net_device *dev);
837 int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq);
838 /* ieee80211_sta.c */
839 void ieee80211_sta_timer(unsigned long data);
840 void ieee80211_sta_work(struct work_struct *work);
841 void ieee80211_admit_refresh(unsigned long ptr);
842 void ieee80211_sta_scan_work(struct work_struct *work);
843 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
844                            struct ieee80211_rx_status *rx_status);
845 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len);
846 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len);
847 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid);
848 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
849 void ieee80211_sta_req_auth(struct net_device *dev,
850                             struct ieee80211_if_sta *ifsta);
851 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
852 void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
853                            struct ieee80211_rx_status *rx_status);
854 void ieee80211_rx_bss_list_init(struct net_device *dev);
855 void ieee80211_rx_bss_list_deinit(struct net_device *dev);
856 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
857 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
858                                          struct sk_buff *skb, u8 *bssid,
859                                          u8 *addr);
860 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
861 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
862 void ieee80211_send_addts(struct net_device *dev,
863                           struct ieee80211_if_sta *ifsta,
864                           struct ieee80211_elem_tspec *tspec);
865 void wmm_send_addts(struct net_device *dev,
866                     struct ieee80211_if_sta *ifsta,
867                     struct ieee80211_elem_tspec *tspec);
868 void ieee80211_send_delts(struct net_device *dev,
869                           struct ieee80211_if_sta *ifsta,
870                           struct ieee80211_elem_tspec *tp);
871 void wmm_send_delts(struct net_device *dev,
872                     struct ieee80211_if_sta *ifsta,
873                     struct ieee80211_elem_tspec *tp);
874 void ieee80211_send_dls_req(struct net_device *dev,
875                             struct ieee80211_if_sta *ifsta,
876                             u8 *addr, u32 timeout);
877 void ieee80211_send_dls_teardown(struct net_device *dev,
878                                  struct ieee80211_if_sta *ifsta,
879                                  u8 *mac, u16 reason);
880 struct sta_info *dls_info_get(struct ieee80211_local *local, u8 *addr);
881 void dls_info_add(struct ieee80211_if_sta *ifsta, struct sta_info *dls);
882 void dls_info_stop(struct ieee80211_if_sta *ifsta);
883 int dls_link_status(struct ieee80211_local *local, u8 *addr);
884
885 /* ieee80211_iface.c */
886 int ieee80211_if_add(struct net_device *dev, const char *name,
887                      struct net_device **new_dev, int type);
888 void ieee80211_if_set_type(struct net_device *dev, int type);
889 void ieee80211_if_reinit(struct net_device *dev);
890 void __ieee80211_if_del(struct ieee80211_local *local,
891                         struct ieee80211_sub_if_data *sdata);
892 int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
893 void ieee80211_if_free(struct net_device *dev);
894 void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
895 int ieee80211_if_add_mgmt(struct ieee80211_local *local);
896 void ieee80211_if_del_mgmt(struct ieee80211_local *local);
897
898 /* for wiphy privid */
899 extern void *mac80211_wiphy_privid;
900
901 #endif /* IEEE80211_I_H */