mac80211: clean up mesh code
[pandora-kernel.git] / net / 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 <linux/etherdevice.h>
25 #include <net/wireless.h>
26 #include "ieee80211_key.h"
27 #include "sta_info.h"
28
29 /* ieee80211.o internal definitions, etc. These are not included into
30  * low-level drivers. */
31
32 #ifndef ETH_P_PAE
33 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
34 #endif /* ETH_P_PAE */
35
36 #define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
37
38 struct ieee80211_local;
39
40 #define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
41
42 /* Maximum number of broadcast/multicast frames to buffer when some of the
43  * associated stations are using power saving. */
44 #define AP_MAX_BC_BUFFER 128
45
46 /* Maximum number of frames buffered to all STAs, including multicast frames.
47  * Note: increasing this limit increases the potential memory requirement. Each
48  * frame can be up to about 2 kB long. */
49 #define TOTAL_MAX_TX_BUFFER 512
50
51 /* Required encryption head and tailroom */
52 #define IEEE80211_ENCRYPT_HEADROOM 8
53 #define IEEE80211_ENCRYPT_TAILROOM 12
54
55 /* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
56  * reception of at least three fragmented frames. This limit can be increased
57  * by changing this define, at the cost of slower frame reassembly and
58  * increased memory use (about 2 kB of RAM per entry). */
59 #define IEEE80211_FRAGMENT_MAX 4
60
61 struct ieee80211_fragment_entry {
62         unsigned long first_frag_time;
63         unsigned int seq;
64         unsigned int rx_queue;
65         unsigned int last_frag;
66         unsigned int extra_len;
67         struct sk_buff_head skb_list;
68         int ccmp; /* Whether fragments were encrypted with CCMP */
69         u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
70 };
71
72
73 struct ieee80211_sta_bss {
74         struct list_head list;
75         struct ieee80211_sta_bss *hnext;
76         atomic_t users;
77
78         u8 bssid[ETH_ALEN];
79         u8 ssid[IEEE80211_MAX_SSID_LEN];
80         size_t ssid_len;
81         u16 capability; /* host byte order */
82         enum ieee80211_band band;
83         int freq;
84         int rssi, signal, noise;
85         u8 *wpa_ie;
86         size_t wpa_ie_len;
87         u8 *rsn_ie;
88         size_t rsn_ie_len;
89         u8 *wmm_ie;
90         size_t wmm_ie_len;
91         u8 *ht_ie;
92         size_t ht_ie_len;
93 #ifdef CONFIG_MAC80211_MESH
94         u8 *mesh_id;
95         size_t mesh_id_len;
96         u8 *mesh_cfg;
97 #endif
98 #define IEEE80211_MAX_SUPP_RATES 32
99         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
100         size_t supp_rates_len;
101         int beacon_int;
102         u64 timestamp;
103
104         int probe_resp;
105         unsigned long last_update;
106
107         /* during assocation, we save an ERP value from a probe response so
108          * that we can feed ERP info to the driver when handling the
109          * association completes. these fields probably won't be up-to-date
110          * otherwise, you probably don't want to use them. */
111         int has_erp_value;
112         u8 erp_value;
113 };
114
115 static inline u8 *bss_mesh_cfg(struct ieee80211_sta_bss *bss)
116 {
117 #ifdef CONFIG_MAC80211_MESH
118         return bss->mesh_cfg;
119 #endif
120         return NULL;
121 }
122
123 static inline u8 *bss_mesh_id(struct ieee80211_sta_bss *bss)
124 {
125 #ifdef CONFIG_MAC80211_MESH
126         return bss->mesh_id;
127 #endif
128         return NULL;
129 }
130
131 static inline u8 bss_mesh_id_len(struct ieee80211_sta_bss *bss)
132 {
133 #ifdef CONFIG_MAC80211_MESH
134         return bss->mesh_id_len;
135 #endif
136         return 0;
137 }
138
139
140 typedef unsigned __bitwise__ ieee80211_tx_result;
141 #define TX_CONTINUE     ((__force ieee80211_tx_result) 0u)
142 #define TX_DROP         ((__force ieee80211_tx_result) 1u)
143 #define TX_QUEUED       ((__force ieee80211_tx_result) 2u)
144
145 typedef unsigned __bitwise__ ieee80211_rx_result;
146 #define RX_CONTINUE             ((__force ieee80211_rx_result) 0u)
147 #define RX_DROP_UNUSABLE        ((__force ieee80211_rx_result) 1u)
148 #define RX_DROP_MONITOR         ((__force ieee80211_rx_result) 2u)
149 #define RX_QUEUED               ((__force ieee80211_rx_result) 3u)
150
151
152 /* flags used in struct ieee80211_txrx_data.flags */
153 /* whether the MSDU was fragmented */
154 #define IEEE80211_TXRXD_FRAGMENTED              BIT(0)
155 #define IEEE80211_TXRXD_TXUNICAST               BIT(1)
156 #define IEEE80211_TXRXD_TXPS_BUFFERED           BIT(2)
157 #define IEEE80211_TXRXD_TXPROBE_LAST_FRAG       BIT(3)
158 #define IEEE80211_TXRXD_RXIN_SCAN               BIT(4)
159 /* frame is destined to interface currently processed (incl. multicast frames) */
160 #define IEEE80211_TXRXD_RXRA_MATCH              BIT(5)
161 #define IEEE80211_TXRXD_TX_INJECTED             BIT(6)
162 #define IEEE80211_TXRXD_RX_AMSDU                BIT(7)
163 #define IEEE80211_TXRXD_RX_CMNTR_REPORTED       BIT(8)
164 struct ieee80211_txrx_data {
165         struct sk_buff *skb;
166         struct net_device *dev;
167         struct ieee80211_local *local;
168         struct ieee80211_sub_if_data *sdata;
169         struct sta_info *sta;
170         u16 fc, ethertype;
171         struct ieee80211_key *key;
172         unsigned int flags;
173         union {
174                 struct {
175                         struct ieee80211_tx_control *control;
176                         struct ieee80211_channel *channel;
177                         struct ieee80211_rate *rate;
178                         /* use this rate (if set) for last fragment; rate can
179                          * be set to lower rate for the first fragments, e.g.,
180                          * when using CTS protection with IEEE 802.11g. */
181                         struct ieee80211_rate *last_frag_rate;
182
183                         /* Extra fragments (in addition to the first fragment
184                          * in skb) */
185                         int num_extra_frag;
186                         struct sk_buff **extra_frag;
187                 } tx;
188                 struct {
189                         struct ieee80211_rx_status *status;
190                         struct ieee80211_rate *rate;
191                         int sent_ps_buffered;
192                         int queue;
193                         int load;
194                         u32 tkip_iv32;
195                         u16 tkip_iv16;
196                 } rx;
197         } u;
198 };
199
200 /* flags used in struct ieee80211_tx_packet_data.flags */
201 #define IEEE80211_TXPD_REQ_TX_STATUS    BIT(0)
202 #define IEEE80211_TXPD_DO_NOT_ENCRYPT   BIT(1)
203 #define IEEE80211_TXPD_REQUEUE          BIT(2)
204 #define IEEE80211_TXPD_EAPOL_FRAME      BIT(3)
205 #define IEEE80211_TXPD_AMPDU            BIT(4)
206 /* Stored in sk_buff->cb */
207 struct ieee80211_tx_packet_data {
208         int ifindex;
209         unsigned long jiffies;
210         unsigned int flags;
211         u8 queue;
212 };
213
214 struct ieee80211_tx_stored_packet {
215         struct ieee80211_tx_control control;
216         struct sk_buff *skb;
217         int num_extra_frag;
218         struct sk_buff **extra_frag;
219         struct ieee80211_rate *last_frag_rate;
220         unsigned int last_frag_rate_ctrl_probe;
221 };
222
223 struct beacon_data {
224         u8 *head, *tail;
225         int head_len, tail_len;
226         int dtim_period;
227 };
228
229 struct ieee80211_if_ap {
230         struct beacon_data *beacon;
231
232         struct list_head vlans;
233
234         u8 ssid[IEEE80211_MAX_SSID_LEN];
235         size_t ssid_len;
236
237         /* yes, this looks ugly, but guarantees that we can later use
238          * bitmap_empty :)
239          * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */
240         u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
241         atomic_t num_sta_ps; /* number of stations in PS mode */
242         struct sk_buff_head ps_bc_buf;
243         int dtim_count;
244         int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
245         int max_ratectrl_rateidx; /* max TX rateidx for rate control */
246         int num_beacons; /* number of TXed beacon frames for this BSS */
247 };
248
249 struct ieee80211_if_wds {
250         u8 remote_addr[ETH_ALEN];
251         struct sta_info *sta;
252 };
253
254 struct ieee80211_if_vlan {
255         struct ieee80211_sub_if_data *ap;
256         struct list_head list;
257 };
258
259 struct mesh_stats {
260         __u32 fwded_frames;             /* Mesh forwarded frames */
261         __u32 dropped_frames_ttl;       /* Not transmitted since mesh_ttl == 0*/
262         __u32 dropped_frames_no_route;  /* Not transmitted, no route found */
263         atomic_t estab_plinks;
264 };
265
266 #define PREQ_Q_F_START          0x1
267 #define PREQ_Q_F_REFRESH        0x2
268 struct mesh_preq_queue {
269         struct list_head list;
270         u8 dst[ETH_ALEN];
271         u8 flags;
272 };
273
274 struct mesh_config {
275         /* Timeouts in ms */
276         /* Mesh plink management parameters */
277         u16 dot11MeshRetryTimeout;
278         u16 dot11MeshConfirmTimeout;
279         u16 dot11MeshHoldingTimeout;
280         u16 dot11MeshMaxPeerLinks;
281         u8  dot11MeshMaxRetries;
282         u8  dot11MeshTTL;
283         bool auto_open_plinks;
284         /* HWMP parameters */
285         u32 dot11MeshHWMPactivePathTimeout;
286         u16 dot11MeshHWMPpreqMinInterval;
287         u16 dot11MeshHWMPnetDiameterTraversalTime;
288         u8  dot11MeshHWMPmaxPREQretries;
289         u32 path_refresh_time;
290         u16 min_discovery_timeout;
291 };
292
293
294 /* flags used in struct ieee80211_if_sta.flags */
295 #define IEEE80211_STA_SSID_SET          BIT(0)
296 #define IEEE80211_STA_BSSID_SET         BIT(1)
297 #define IEEE80211_STA_PREV_BSSID_SET    BIT(2)
298 #define IEEE80211_STA_AUTHENTICATED     BIT(3)
299 #define IEEE80211_STA_ASSOCIATED        BIT(4)
300 #define IEEE80211_STA_PROBEREQ_POLL     BIT(5)
301 #define IEEE80211_STA_CREATE_IBSS       BIT(6)
302 #define IEEE80211_STA_MIXED_CELL        BIT(7)
303 #define IEEE80211_STA_WMM_ENABLED       BIT(8)
304 #define IEEE80211_STA_AUTO_SSID_SEL     BIT(10)
305 #define IEEE80211_STA_AUTO_BSSID_SEL    BIT(11)
306 #define IEEE80211_STA_AUTO_CHANNEL_SEL  BIT(12)
307 #define IEEE80211_STA_PRIVACY_INVOKED   BIT(13)
308 struct ieee80211_if_sta {
309         enum {
310                 IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
311                 IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
312                 IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED,
313                 IEEE80211_MESH_UP
314         } state;
315         struct timer_list timer;
316         struct work_struct work;
317         u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
318         u8 ssid[IEEE80211_MAX_SSID_LEN];
319         size_t ssid_len;
320         u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
321         size_t scan_ssid_len;
322 #ifdef CONFIG_MAC80211_MESH
323         struct timer_list mesh_path_timer;
324         u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
325         bool accepting_plinks;
326         size_t mesh_id_len;
327         /* Active Path Selection Protocol Identifier */
328         u8 mesh_pp_id[4];
329         /* Active Path Selection Metric Identifier */
330         u8 mesh_pm_id[4];
331         /* Congestion Control Mode Identifier */
332         u8 mesh_cc_id[4];
333         /* Local mesh Destination Sequence Number */
334         u32 dsn;
335         /* Last used PREQ ID */
336         u32 preq_id;
337         atomic_t mpaths;
338         /* Timestamp of last DSN update */
339         unsigned long last_dsn_update;
340         /* Timestamp of last DSN sent */
341         unsigned long last_preq;
342         struct mesh_rmc *rmc;
343         spinlock_t mesh_preq_queue_lock;
344         struct mesh_preq_queue preq_queue;
345         int preq_queue_len;
346         struct mesh_stats mshstats;
347         struct mesh_config mshcfg;
348         u8 mesh_seqnum[3];
349 #endif
350         u16 aid;
351         u16 ap_capab, capab;
352         u8 *extra_ie; /* to be added to the end of AssocReq */
353         size_t extra_ie_len;
354
355         /* The last AssocReq/Resp IEs */
356         u8 *assocreq_ies, *assocresp_ies;
357         size_t assocreq_ies_len, assocresp_ies_len;
358
359         int auth_tries, assoc_tries;
360
361         unsigned int flags;
362 #define IEEE80211_STA_REQ_SCAN 0
363 #define IEEE80211_STA_REQ_AUTH 1
364 #define IEEE80211_STA_REQ_RUN  2
365         unsigned long request;
366         struct sk_buff_head skb_queue;
367
368         unsigned long last_probe;
369
370 #define IEEE80211_AUTH_ALG_OPEN BIT(0)
371 #define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
372 #define IEEE80211_AUTH_ALG_LEAP BIT(2)
373         unsigned int auth_algs; /* bitfield of allowed auth algs */
374         int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
375         int auth_transaction;
376
377         unsigned long ibss_join_req;
378         struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
379         u32 supp_rates_bits[IEEE80211_NUM_BANDS];
380
381         int wmm_last_param_set;
382         int num_beacons; /* number of TXed beacon frames by this STA */
383 };
384
385 static inline void ieee80211_if_sta_set_mesh_id(struct ieee80211_if_sta *ifsta,
386                                                 u8 mesh_id_len, u8 *mesh_id)
387 {
388 #ifdef CONFIG_MAC80211_MESH
389         ifsta->mesh_id_len = mesh_id_len;
390         memcpy(ifsta->mesh_id, mesh_id, mesh_id_len);
391 #endif
392 }
393
394 #ifdef CONFIG_MAC80211_MESH
395 #define IEEE80211_IFSTA_MESH_CTR_INC(sta, name) \
396         do { (sta)->mshstats.name++; } while (0)
397 #else
398 #define IEEE80211_IFSTA_MESH_CTR_INC(sta, name) \
399         do { } while (0)
400 #endif
401
402 /* flags used in struct ieee80211_sub_if_data.flags */
403 #define IEEE80211_SDATA_ALLMULTI        BIT(0)
404 #define IEEE80211_SDATA_PROMISC         BIT(1)
405 #define IEEE80211_SDATA_USERSPACE_MLME  BIT(2)
406 #define IEEE80211_SDATA_OPERATING_GMODE BIT(3)
407 struct ieee80211_sub_if_data {
408         struct list_head list;
409
410         struct wireless_dev wdev;
411
412         /* keys */
413         struct list_head key_list;
414
415         struct net_device *dev;
416         struct ieee80211_local *local;
417
418         unsigned int flags;
419
420         int drop_unencrypted;
421
422         /*
423          * basic rates of this AP or the AP we're associated to
424          */
425         u64 basic_rates;
426
427         u16 sequence;
428
429         /* Fragment table for host-based reassembly */
430         struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
431         unsigned int fragment_next;
432
433 #define NUM_DEFAULT_KEYS 4
434         struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
435         struct ieee80211_key *default_key;
436
437         /*
438          * BSS configuration for this interface.
439          *
440          * FIXME: I feel bad putting this here when we already have a
441          *        bss pointer, but the bss pointer is just wrong when
442          *        you have multiple virtual STA mode interfaces...
443          *        This needs to be fixed.
444          */
445         struct ieee80211_bss_conf bss_conf;
446         struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
447
448         union {
449                 struct ieee80211_if_ap ap;
450                 struct ieee80211_if_wds wds;
451                 struct ieee80211_if_vlan vlan;
452                 struct ieee80211_if_sta sta;
453                 u32 mntr_flags;
454         } u;
455         int channel_use;
456         int channel_use_raw;
457
458 #ifdef CONFIG_MAC80211_DEBUGFS
459         struct dentry *debugfsdir;
460         union {
461                 struct {
462                         struct dentry *channel_use;
463                         struct dentry *drop_unencrypted;
464                         struct dentry *state;
465                         struct dentry *bssid;
466                         struct dentry *prev_bssid;
467                         struct dentry *ssid_len;
468                         struct dentry *aid;
469                         struct dentry *ap_capab;
470                         struct dentry *capab;
471                         struct dentry *extra_ie_len;
472                         struct dentry *auth_tries;
473                         struct dentry *assoc_tries;
474                         struct dentry *auth_algs;
475                         struct dentry *auth_alg;
476                         struct dentry *auth_transaction;
477                         struct dentry *flags;
478                         struct dentry *num_beacons_sta;
479                 } sta;
480                 struct {
481                         struct dentry *channel_use;
482                         struct dentry *drop_unencrypted;
483                         struct dentry *num_sta_ps;
484                         struct dentry *dtim_count;
485                         struct dentry *num_beacons;
486                         struct dentry *force_unicast_rateidx;
487                         struct dentry *max_ratectrl_rateidx;
488                         struct dentry *num_buffered_multicast;
489                 } ap;
490                 struct {
491                         struct dentry *channel_use;
492                         struct dentry *drop_unencrypted;
493                         struct dentry *peer;
494                 } wds;
495                 struct {
496                         struct dentry *channel_use;
497                         struct dentry *drop_unencrypted;
498                 } vlan;
499                 struct {
500                         struct dentry *mode;
501                 } monitor;
502                 struct dentry *default_key;
503         } debugfs;
504
505 #ifdef CONFIG_MAC80211_MESH
506         struct dentry *mesh_stats_dir;
507         struct {
508                 struct dentry *fwded_frames;
509                 struct dentry *dropped_frames_ttl;
510                 struct dentry *dropped_frames_no_route;
511                 struct dentry *estab_plinks;
512                 struct timer_list mesh_path_timer;
513         } mesh_stats;
514
515         struct dentry *mesh_config_dir;
516         struct {
517                 struct dentry *dot11MeshRetryTimeout;
518                 struct dentry *dot11MeshConfirmTimeout;
519                 struct dentry *dot11MeshHoldingTimeout;
520                 struct dentry *dot11MeshMaxRetries;
521                 struct dentry *dot11MeshTTL;
522                 struct dentry *auto_open_plinks;
523                 struct dentry *dot11MeshMaxPeerLinks;
524                 struct dentry *dot11MeshHWMPactivePathTimeout;
525                 struct dentry *dot11MeshHWMPpreqMinInterval;
526                 struct dentry *dot11MeshHWMPnetDiameterTraversalTime;
527                 struct dentry *dot11MeshHWMPmaxPREQretries;
528                 struct dentry *path_refresh_time;
529                 struct dentry *min_discovery_timeout;
530         } mesh_config;
531 #endif
532
533 #endif
534         /* must be last, dynamically sized area in this! */
535         struct ieee80211_vif vif;
536 };
537
538 static inline
539 struct ieee80211_sub_if_data *vif_to_sdata(struct ieee80211_vif *p)
540 {
541         return container_of(p, struct ieee80211_sub_if_data, vif);
542 }
543
544 #define IEEE80211_DEV_TO_SUB_IF(dev) netdev_priv(dev)
545
546 enum {
547         IEEE80211_RX_MSG        = 1,
548         IEEE80211_TX_STATUS_MSG = 2,
549         IEEE80211_DELBA_MSG     = 3,
550         IEEE80211_ADDBA_MSG     = 4,
551 };
552
553 struct ieee80211_local {
554         /* embed the driver visible part.
555          * don't cast (use the static inlines below), but we keep
556          * it first anyway so they become a no-op */
557         struct ieee80211_hw hw;
558
559         const struct ieee80211_ops *ops;
560
561         struct net_device *mdev; /* wmaster# - "master" 802.11 device */
562         int open_count;
563         int monitors, cooked_mntrs;
564         /* number of interfaces with corresponding FIF_ flags */
565         int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss;
566         unsigned int filter_flags; /* FIF_* */
567         struct iw_statistics wstats;
568         u8 wstats_flags;
569         int tx_headroom; /* required headroom for hardware/radiotap */
570
571         enum {
572                 IEEE80211_DEV_UNINITIALIZED = 0,
573                 IEEE80211_DEV_REGISTERED,
574                 IEEE80211_DEV_UNREGISTERED,
575         } reg_state;
576
577         /* Tasklet and skb queue to process calls from IRQ mode. All frames
578          * added to skb_queue will be processed, but frames in
579          * skb_queue_unreliable may be dropped if the total length of these
580          * queues increases over the limit. */
581 #define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
582         struct tasklet_struct tasklet;
583         struct sk_buff_head skb_queue;
584         struct sk_buff_head skb_queue_unreliable;
585
586         /* Station data structures */
587         rwlock_t sta_lock; /* protects STA data structures */
588         int num_sta; /* number of stations in sta_list */
589         struct list_head sta_list;
590         struct sta_info *sta_hash[STA_HASH_SIZE];
591         struct timer_list sta_cleanup;
592
593         unsigned long state[NUM_TX_DATA_QUEUES_AMPDU];
594         struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES_AMPDU];
595         struct tasklet_struct tx_pending_tasklet;
596
597         /* number of interfaces with corresponding IFF_ flags */
598         atomic_t iff_allmultis, iff_promiscs;
599
600         struct rate_control_ref *rate_ctrl;
601
602         int rts_threshold;
603         int fragmentation_threshold;
604         int short_retry_limit; /* dot11ShortRetryLimit */
605         int long_retry_limit; /* dot11LongRetryLimit */
606
607         struct crypto_blkcipher *wep_tx_tfm;
608         struct crypto_blkcipher *wep_rx_tfm;
609         u32 wep_iv;
610
611         int bridge_packets; /* bridge packets between associated stations and
612                              * deliver multicast frames both back to wireless
613                              * media and to the local net stack */
614
615         struct list_head interfaces;
616
617         bool sta_sw_scanning;
618         bool sta_hw_scanning;
619         int scan_channel_idx;
620         enum ieee80211_band scan_band;
621
622         enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
623         unsigned long last_scan_completed;
624         struct delayed_work scan_work;
625         struct net_device *scan_dev;
626         struct ieee80211_channel *oper_channel, *scan_channel;
627         u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
628         size_t scan_ssid_len;
629         struct list_head sta_bss_list;
630         struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
631         spinlock_t sta_bss_lock;
632
633         /* SNMP counters */
634         /* dot11CountersTable */
635         u32 dot11TransmittedFragmentCount;
636         u32 dot11MulticastTransmittedFrameCount;
637         u32 dot11FailedCount;
638         u32 dot11RetryCount;
639         u32 dot11MultipleRetryCount;
640         u32 dot11FrameDuplicateCount;
641         u32 dot11ReceivedFragmentCount;
642         u32 dot11MulticastReceivedFrameCount;
643         u32 dot11TransmittedFrameCount;
644         u32 dot11WEPUndecryptableCount;
645
646 #ifdef CONFIG_MAC80211_LEDS
647         int tx_led_counter, rx_led_counter;
648         struct led_trigger *tx_led, *rx_led, *assoc_led, *radio_led;
649         char tx_led_name[32], rx_led_name[32],
650              assoc_led_name[32], radio_led_name[32];
651 #endif
652
653         u32 channel_use;
654         u32 channel_use_raw;
655
656 #ifdef CONFIG_MAC80211_DEBUGFS
657         struct work_struct sta_debugfs_add;
658 #endif
659
660 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
661         /* TX/RX handler statistics */
662         unsigned int tx_handlers_drop;
663         unsigned int tx_handlers_queued;
664         unsigned int tx_handlers_drop_unencrypted;
665         unsigned int tx_handlers_drop_fragment;
666         unsigned int tx_handlers_drop_wep;
667         unsigned int tx_handlers_drop_not_assoc;
668         unsigned int tx_handlers_drop_unauth_port;
669         unsigned int rx_handlers_drop;
670         unsigned int rx_handlers_queued;
671         unsigned int rx_handlers_drop_nullfunc;
672         unsigned int rx_handlers_drop_defrag;
673         unsigned int rx_handlers_drop_short;
674         unsigned int rx_handlers_drop_passive_scan;
675         unsigned int tx_expand_skb_head;
676         unsigned int tx_expand_skb_head_cloned;
677         unsigned int rx_expand_skb_head;
678         unsigned int rx_expand_skb_head2;
679         unsigned int rx_handlers_fragments;
680         unsigned int tx_status_drop;
681         unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
682         unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
683 #define I802_DEBUG_INC(c) (c)++
684 #else /* CONFIG_MAC80211_DEBUG_COUNTERS */
685 #define I802_DEBUG_INC(c) do { } while (0)
686 #endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
687
688
689         int total_ps_buffered; /* total number of all buffered unicast and
690                                 * multicast packets for power saving stations
691                                 */
692         int wifi_wme_noack_test;
693         unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
694
695 #ifdef CONFIG_MAC80211_DEBUGFS
696         struct local_debugfsdentries {
697                 struct dentry *frequency;
698                 struct dentry *antenna_sel_tx;
699                 struct dentry *antenna_sel_rx;
700                 struct dentry *bridge_packets;
701                 struct dentry *rts_threshold;
702                 struct dentry *fragmentation_threshold;
703                 struct dentry *short_retry_limit;
704                 struct dentry *long_retry_limit;
705                 struct dentry *total_ps_buffered;
706                 struct dentry *wep_iv;
707                 struct dentry *statistics;
708                 struct local_debugfsdentries_statsdentries {
709                         struct dentry *transmitted_fragment_count;
710                         struct dentry *multicast_transmitted_frame_count;
711                         struct dentry *failed_count;
712                         struct dentry *retry_count;
713                         struct dentry *multiple_retry_count;
714                         struct dentry *frame_duplicate_count;
715                         struct dentry *received_fragment_count;
716                         struct dentry *multicast_received_frame_count;
717                         struct dentry *transmitted_frame_count;
718                         struct dentry *wep_undecryptable_count;
719                         struct dentry *num_scans;
720 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
721                         struct dentry *tx_handlers_drop;
722                         struct dentry *tx_handlers_queued;
723                         struct dentry *tx_handlers_drop_unencrypted;
724                         struct dentry *tx_handlers_drop_fragment;
725                         struct dentry *tx_handlers_drop_wep;
726                         struct dentry *tx_handlers_drop_not_assoc;
727                         struct dentry *tx_handlers_drop_unauth_port;
728                         struct dentry *rx_handlers_drop;
729                         struct dentry *rx_handlers_queued;
730                         struct dentry *rx_handlers_drop_nullfunc;
731                         struct dentry *rx_handlers_drop_defrag;
732                         struct dentry *rx_handlers_drop_short;
733                         struct dentry *rx_handlers_drop_passive_scan;
734                         struct dentry *tx_expand_skb_head;
735                         struct dentry *tx_expand_skb_head_cloned;
736                         struct dentry *rx_expand_skb_head;
737                         struct dentry *rx_expand_skb_head2;
738                         struct dentry *rx_handlers_fragments;
739                         struct dentry *tx_status_drop;
740                         struct dentry *wme_tx_queue;
741                         struct dentry *wme_rx_queue;
742 #endif
743                         struct dentry *dot11ACKFailureCount;
744                         struct dentry *dot11RTSFailureCount;
745                         struct dentry *dot11FCSErrorCount;
746                         struct dentry *dot11RTSSuccessCount;
747                 } stats;
748                 struct dentry *stations;
749                 struct dentry *keys;
750         } debugfs;
751 #endif
752 };
753
754 /* this struct represents 802.11n's RA/TID combination */
755 struct ieee80211_ra_tid {
756         u8 ra[ETH_ALEN];
757         u16 tid;
758 };
759
760 /* Parsed Information Elements */
761 struct ieee802_11_elems {
762         /* pointers to IEs */
763         u8 *ssid;
764         u8 *supp_rates;
765         u8 *fh_params;
766         u8 *ds_params;
767         u8 *cf_params;
768         u8 *tim;
769         u8 *ibss_params;
770         u8 *challenge;
771         u8 *wpa;
772         u8 *rsn;
773         u8 *erp_info;
774         u8 *ext_supp_rates;
775         u8 *wmm_info;
776         u8 *wmm_param;
777         u8 *ht_cap_elem;
778         u8 *ht_info_elem;
779         u8 *mesh_config;
780         u8 *mesh_id;
781         u8 *peer_link;
782         u8 *preq;
783         u8 *prep;
784         u8 *perr;
785
786         /* length of them, respectively */
787         u8 ssid_len;
788         u8 supp_rates_len;
789         u8 fh_params_len;
790         u8 ds_params_len;
791         u8 cf_params_len;
792         u8 tim_len;
793         u8 ibss_params_len;
794         u8 challenge_len;
795         u8 wpa_len;
796         u8 rsn_len;
797         u8 erp_info_len;
798         u8 ext_supp_rates_len;
799         u8 wmm_info_len;
800         u8 wmm_param_len;
801         u8 ht_cap_elem_len;
802         u8 ht_info_elem_len;
803         u8 mesh_config_len;
804         u8 mesh_id_len;
805         u8 peer_link_len;
806         u8 preq_len;
807         u8 prep_len;
808         u8 perr_len;
809 };
810
811 static inline struct ieee80211_local *hw_to_local(
812         struct ieee80211_hw *hw)
813 {
814         return container_of(hw, struct ieee80211_local, hw);
815 }
816
817 static inline struct ieee80211_hw *local_to_hw(
818         struct ieee80211_local *local)
819 {
820         return &local->hw;
821 }
822
823 enum ieee80211_link_state_t {
824         IEEE80211_LINK_STATE_XOFF = 0,
825         IEEE80211_LINK_STATE_PENDING,
826 };
827
828 struct sta_attribute {
829         struct attribute attr;
830         ssize_t (*show)(const struct sta_info *, char *buf);
831         ssize_t (*store)(struct sta_info *, const char *buf, size_t count);
832 };
833
834 static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
835 {
836         return compare_ether_addr(raddr, addr) == 0 ||
837                is_broadcast_ether_addr(raddr);
838 }
839
840
841 /* ieee80211.c */
842 int ieee80211_hw_config(struct ieee80211_local *local);
843 int ieee80211_if_config(struct net_device *dev);
844 int ieee80211_if_config_beacon(struct net_device *dev);
845 void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
846 int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr);
847 void ieee80211_if_setup(struct net_device *dev);
848 int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
849                            struct ieee80211_ht_info *req_ht_cap,
850                            struct ieee80211_ht_bss_info *req_bss_cap);
851
852 /* ieee80211_ioctl.c */
853 extern const struct iw_handler_def ieee80211_iw_handler_def;
854
855
856 /* Least common multiple of the used rates (in 100 kbps). This is used to
857  * calculate rate_inv values for each rate so that only integers are needed. */
858 #define CHAN_UTIL_RATE_LCM 95040
859 /* 1 usec is 1/8 * (95040/10) = 1188 */
860 #define CHAN_UTIL_PER_USEC 1188
861 /* Amount of bits to shift the result right to scale the total utilization
862  * to values that will not wrap around 32-bit integers. */
863 #define CHAN_UTIL_SHIFT 9
864 /* Theoretical maximum of channel utilization counter in 10 ms (stat_time=1):
865  * (CHAN_UTIL_PER_USEC * 10000) >> CHAN_UTIL_SHIFT = 23203. So dividing the
866  * raw value with about 23 should give utilization in 10th of a percentage
867  * (1/1000). However, utilization is only estimated and not all intervals
868  * between frames etc. are calculated. 18 seems to give numbers that are closer
869  * to the real maximum. */
870 #define CHAN_UTIL_PER_10MS 18
871 #define CHAN_UTIL_HDR_LONG (202 * CHAN_UTIL_PER_USEC)
872 #define CHAN_UTIL_HDR_SHORT (40 * CHAN_UTIL_PER_USEC)
873
874
875 /* ieee80211_ioctl.c */
876 int ieee80211_set_compression(struct ieee80211_local *local,
877                               struct net_device *dev, struct sta_info *sta);
878 int ieee80211_set_freq(struct ieee80211_local *local, int freq);
879 /* ieee80211_sta.c */
880 #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
881 void ieee80211_sta_timer(unsigned long data);
882 void ieee80211_sta_work(struct work_struct *work);
883 void ieee80211_sta_scan_work(struct work_struct *work);
884 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
885                            struct ieee80211_rx_status *rx_status);
886 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len);
887 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len);
888 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid);
889 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
890 void ieee80211_sta_req_auth(struct net_device *dev,
891                             struct ieee80211_if_sta *ifsta);
892 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
893 ieee80211_rx_result ieee80211_sta_rx_scan(
894         struct net_device *dev, struct sk_buff *skb,
895         struct ieee80211_rx_status *rx_status);
896 void ieee80211_rx_bss_list_init(struct net_device *dev);
897 void ieee80211_rx_bss_list_deinit(struct net_device *dev);
898 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
899 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
900                                          struct sk_buff *skb, u8 *bssid,
901                                          u8 *addr);
902 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
903 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
904 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
905                                       u32 changed);
906 void ieee80211_reset_erp_info(struct net_device *dev);
907 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
908                                    struct ieee80211_ht_info *ht_info);
909 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
910                         struct ieee80211_ht_addt_info *ht_add_info_ie,
911                         struct ieee80211_ht_bss_info *bss_info);
912 void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
913                                   u16 tid, u8 dialog_token, u16 start_seq_num,
914                                   u16 agg_size, u16 timeout);
915 void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
916                                 u16 initiator, u16 reason_code);
917 void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *da,
918                                 u16 tid, u16 initiator, u16 reason);
919 void sta_rx_agg_session_timer_expired(unsigned long data);
920 void sta_addba_resp_timer_expired(unsigned long data);
921 u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
922                             struct ieee802_11_elems *elems,
923                             enum ieee80211_band band);
924 void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
925                 int encrypt);
926 void ieee802_11_parse_elems(u8 *start, size_t len,
927                                    struct ieee802_11_elems *elems);
928
929 #ifdef CONFIG_MAC80211_MESH
930 void ieee80211_start_mesh(struct net_device *dev);
931 #else
932 static inline void ieee80211_start_mesh(struct net_device *dev)
933 {}
934 #endif
935
936 /* ieee80211_iface.c */
937 int ieee80211_if_add(struct net_device *dev, const char *name,
938                      struct net_device **new_dev, int type,
939                      struct vif_params *params);
940 void ieee80211_if_set_type(struct net_device *dev, int type);
941 void ieee80211_if_reinit(struct net_device *dev);
942 void __ieee80211_if_del(struct ieee80211_local *local,
943                         struct ieee80211_sub_if_data *sdata);
944 int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
945 void ieee80211_if_free(struct net_device *dev);
946 void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
947
948 /* tx handling */
949 void ieee80211_clear_tx_pending(struct ieee80211_local *local);
950 void ieee80211_tx_pending(unsigned long data);
951 int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev);
952 int ieee80211_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
953 int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
954
955 /* utility functions/constants */
956 extern void *mac80211_wiphy_privid; /* for wiphy privid */
957 extern const unsigned char rfc1042_header[6];
958 extern const unsigned char bridge_tunnel_header[6];
959 u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
960                         enum ieee80211_if_types type);
961 int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
962                              int rate, int erp, int short_preamble);
963 void mac80211_ev_michael_mic_failure(struct net_device *dev, int keyidx,
964                                      struct ieee80211_hdr *hdr);
965
966 #endif /* IEEE80211_I_H */