[MAC80211]: use internal network device stats
[safe/jmp/linux-2.6] / 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 BIT(x) (1 << (x))
41
42 #define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
43
44 /* Maximum number of broadcast/multicast frames to buffer when some of the
45  * associated stations are using power saving. */
46 #define AP_MAX_BC_BUFFER 128
47
48 /* Maximum number of frames buffered to all STAs, including multicast frames.
49  * Note: increasing this limit increases the potential memory requirement. Each
50  * frame can be up to about 2 kB long. */
51 #define TOTAL_MAX_TX_BUFFER 512
52
53 /* Required encryption head and tailroom */
54 #define IEEE80211_ENCRYPT_HEADROOM 8
55 #define IEEE80211_ENCRYPT_TAILROOM 12
56
57 /* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
58  * reception of at least three fragmented frames. This limit can be increased
59  * by changing this define, at the cost of slower frame reassembly and
60  * increased memory use (about 2 kB of RAM per entry). */
61 #define IEEE80211_FRAGMENT_MAX 4
62
63 struct ieee80211_fragment_entry {
64         unsigned long first_frag_time;
65         unsigned int seq;
66         unsigned int rx_queue;
67         unsigned int last_frag;
68         unsigned int extra_len;
69         struct sk_buff_head skb_list;
70         int ccmp; /* Whether fragments were encrypted with CCMP */
71         u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
72 };
73
74
75 struct ieee80211_sta_bss {
76         struct list_head list;
77         struct ieee80211_sta_bss *hnext;
78         atomic_t users;
79
80         u8 bssid[ETH_ALEN];
81         u8 ssid[IEEE80211_MAX_SSID_LEN];
82         size_t ssid_len;
83         u16 capability; /* host byte order */
84         int hw_mode;
85         int channel;
86         int freq;
87         int rssi, signal, noise;
88         u8 *wpa_ie;
89         size_t wpa_ie_len;
90         u8 *rsn_ie;
91         size_t rsn_ie_len;
92         u8 *wmm_ie;
93         size_t wmm_ie_len;
94 #define IEEE80211_MAX_SUPP_RATES 32
95         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
96         size_t supp_rates_len;
97         int beacon_int;
98         u64 timestamp;
99
100         int probe_resp;
101         unsigned long last_update;
102
103         /* during assocation, we save an ERP value from a probe response so
104          * that we can feed ERP info to the driver when handling the
105          * association completes. these fields probably won't be up-to-date
106          * otherwise, you probably don't want to use them. */
107         int has_erp_value;
108         u8 erp_value;
109 };
110
111
112 typedef enum {
113         TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
114 } ieee80211_txrx_result;
115
116 /* flags used in struct ieee80211_txrx_data.flags */
117 /* whether the MSDU was fragmented */
118 #define IEEE80211_TXRXD_FRAGMENTED              BIT(0)
119 #define IEEE80211_TXRXD_TXUNICAST               BIT(1)
120 #define IEEE80211_TXRXD_TXPS_BUFFERED           BIT(2)
121 #define IEEE80211_TXRXD_TXPROBE_LAST_FRAG       BIT(3)
122 #define IEEE80211_TXRXD_RXIN_SCAN               BIT(4)
123 /* frame is destined to interface currently processed (incl. multicast frames) */
124 #define IEEE80211_TXRXD_RXRA_MATCH              BIT(5)
125 struct ieee80211_txrx_data {
126         struct sk_buff *skb;
127         struct net_device *dev;
128         struct ieee80211_local *local;
129         struct ieee80211_sub_if_data *sdata;
130         struct sta_info *sta;
131         u16 fc, ethertype;
132         struct ieee80211_key *key;
133         unsigned int flags;
134         union {
135                 struct {
136                         struct ieee80211_tx_control *control;
137                         struct ieee80211_hw_mode *mode;
138                         struct ieee80211_rate *rate;
139                         /* use this rate (if set) for last fragment; rate can
140                          * be set to lower rate for the first fragments, e.g.,
141                          * when using CTS protection with IEEE 802.11g. */
142                         struct ieee80211_rate *last_frag_rate;
143                         int last_frag_hwrate;
144                         int mgmt_interface;
145
146                         /* Extra fragments (in addition to the first fragment
147                          * in skb) */
148                         int num_extra_frag;
149                         struct sk_buff **extra_frag;
150                 } tx;
151                 struct {
152                         struct ieee80211_rx_status *status;
153                         int sent_ps_buffered;
154                         int queue;
155                         int load;
156                 } rx;
157         } u;
158 };
159
160 /* flags used in struct ieee80211_tx_packet_data.flags */
161 #define IEEE80211_TXPD_REQ_TX_STATUS    BIT(0)
162 #define IEEE80211_TXPD_DO_NOT_ENCRYPT   BIT(1)
163 #define IEEE80211_TXPD_REQUEUE          BIT(2)
164 #define IEEE80211_TXPD_MGMT_IFACE       BIT(3)
165 /* Stored in sk_buff->cb */
166 struct ieee80211_tx_packet_data {
167         int ifindex;
168         unsigned long jiffies;
169         unsigned int flags;
170         u8 queue;
171 };
172
173 struct ieee80211_tx_stored_packet {
174         struct ieee80211_tx_control control;
175         struct sk_buff *skb;
176         int num_extra_frag;
177         struct sk_buff **extra_frag;
178         int last_frag_rateidx;
179         int last_frag_hwrate;
180         struct ieee80211_rate *last_frag_rate;
181         unsigned int last_frag_rate_ctrl_probe;
182 };
183
184 typedef ieee80211_txrx_result (*ieee80211_tx_handler)
185 (struct ieee80211_txrx_data *tx);
186
187 typedef ieee80211_txrx_result (*ieee80211_rx_handler)
188 (struct ieee80211_txrx_data *rx);
189
190 struct ieee80211_if_ap {
191         u8 *beacon_head, *beacon_tail;
192         int beacon_head_len, beacon_tail_len;
193
194         u8 ssid[IEEE80211_MAX_SSID_LEN];
195         size_t ssid_len;
196         u8 *generic_elem;
197         size_t generic_elem_len;
198
199         /* yes, this looks ugly, but guarantees that we can later use
200          * bitmap_empty :)
201          * NB: don't ever use set_bit, use bss_tim_set/bss_tim_clear! */
202         u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
203         atomic_t num_sta_ps; /* number of stations in PS mode */
204         struct sk_buff_head ps_bc_buf;
205         int dtim_period, dtim_count;
206         int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
207         int max_ratectrl_rateidx; /* max TX rateidx for rate control */
208         int num_beacons; /* number of TXed beacon frames for this BSS */
209 };
210
211 struct ieee80211_if_wds {
212         u8 remote_addr[ETH_ALEN];
213         struct sta_info *sta;
214 };
215
216 struct ieee80211_if_vlan {
217         u8 id;
218 };
219
220 /* flags used in struct ieee80211_if_sta.flags */
221 #define IEEE80211_STA_SSID_SET          BIT(0)
222 #define IEEE80211_STA_BSSID_SET         BIT(1)
223 #define IEEE80211_STA_PREV_BSSID_SET    BIT(2)
224 #define IEEE80211_STA_AUTHENTICATED     BIT(3)
225 #define IEEE80211_STA_ASSOCIATED        BIT(4)
226 #define IEEE80211_STA_PROBEREQ_POLL     BIT(5)
227 #define IEEE80211_STA_CREATE_IBSS       BIT(6)
228 #define IEEE80211_STA_MIXED_CELL        BIT(7)
229 #define IEEE80211_STA_WMM_ENABLED       BIT(8)
230 #define IEEE80211_STA_AUTO_SSID_SEL     BIT(10)
231 #define IEEE80211_STA_AUTO_BSSID_SEL    BIT(11)
232 #define IEEE80211_STA_AUTO_CHANNEL_SEL  BIT(12)
233 struct ieee80211_if_sta {
234         enum {
235                 IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
236                 IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
237                 IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
238         } state;
239         struct timer_list timer;
240         struct work_struct work;
241         u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
242         u8 ssid[IEEE80211_MAX_SSID_LEN];
243         size_t ssid_len;
244         u16 aid;
245         u16 ap_capab, capab;
246         u8 *extra_ie; /* to be added to the end of AssocReq */
247         size_t extra_ie_len;
248
249         /* The last AssocReq/Resp IEs */
250         u8 *assocreq_ies, *assocresp_ies;
251         size_t assocreq_ies_len, assocresp_ies_len;
252
253         int auth_tries, assoc_tries;
254
255         unsigned int flags;
256 #define IEEE80211_STA_REQ_SCAN 0
257 #define IEEE80211_STA_REQ_AUTH 1
258 #define IEEE80211_STA_REQ_RUN  2
259         unsigned long request;
260         struct sk_buff_head skb_queue;
261
262         int key_management_enabled;
263         unsigned long last_probe;
264
265 #define IEEE80211_AUTH_ALG_OPEN BIT(0)
266 #define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
267 #define IEEE80211_AUTH_ALG_LEAP BIT(2)
268         unsigned int auth_algs; /* bitfield of allowed auth algs */
269         int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
270         int auth_transaction;
271
272         unsigned long ibss_join_req;
273         struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
274         u32 supp_rates_bits;
275
276         int wmm_last_param_set;
277 };
278
279
280 /* flags used in struct ieee80211_sub_if_data.flags */
281 #define IEEE80211_SDATA_ALLMULTI        BIT(0)
282 #define IEEE80211_SDATA_PROMISC         BIT(1)
283 #define IEEE80211_SDATA_USE_PROTECTION  BIT(2) /* CTS protect ERP frames */
284 /* use short preamble with IEEE 802.11b: this flag is set when the AP or beacon
285  * generator reports that there are no present stations that cannot support short
286  * preambles */
287 #define IEEE80211_SDATA_SHORT_PREAMBLE  BIT(3)
288 struct ieee80211_sub_if_data {
289         struct list_head list;
290         unsigned int type;
291
292         struct wireless_dev wdev;
293
294         /* keys */
295         struct list_head key_list;
296
297         struct net_device *dev;
298         struct ieee80211_local *local;
299
300         int mc_count;
301
302         unsigned int flags;
303
304         int drop_unencrypted;
305         int eapol; /* 0 = process EAPOL frames as normal data frames,
306                     * 1 = send EAPOL frames through wlan#ap to hostapd
307                     *     (default) */
308         int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
309                          * port */
310
311         u16 sequence;
312
313         /* Fragment table for host-based reassembly */
314         struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
315         unsigned int fragment_next;
316
317 #define NUM_DEFAULT_KEYS 4
318         struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
319         struct ieee80211_key *default_key;
320
321         struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
322
323         union {
324                 struct ieee80211_if_ap ap;
325                 struct ieee80211_if_wds wds;
326                 struct ieee80211_if_vlan vlan;
327                 struct ieee80211_if_sta sta;
328         } u;
329         int channel_use;
330         int channel_use_raw;
331
332 #ifdef CONFIG_MAC80211_DEBUGFS
333         struct dentry *debugfsdir;
334         union {
335                 struct {
336                         struct dentry *channel_use;
337                         struct dentry *drop_unencrypted;
338                         struct dentry *eapol;
339                         struct dentry *ieee8021_x;
340                         struct dentry *state;
341                         struct dentry *bssid;
342                         struct dentry *prev_bssid;
343                         struct dentry *ssid_len;
344                         struct dentry *aid;
345                         struct dentry *ap_capab;
346                         struct dentry *capab;
347                         struct dentry *extra_ie_len;
348                         struct dentry *auth_tries;
349                         struct dentry *assoc_tries;
350                         struct dentry *auth_algs;
351                         struct dentry *auth_alg;
352                         struct dentry *auth_transaction;
353                         struct dentry *flags;
354                 } sta;
355                 struct {
356                         struct dentry *channel_use;
357                         struct dentry *drop_unencrypted;
358                         struct dentry *eapol;
359                         struct dentry *ieee8021_x;
360                         struct dentry *num_sta_ps;
361                         struct dentry *dtim_period;
362                         struct dentry *dtim_count;
363                         struct dentry *num_beacons;
364                         struct dentry *force_unicast_rateidx;
365                         struct dentry *max_ratectrl_rateidx;
366                         struct dentry *num_buffered_multicast;
367                         struct dentry *beacon_head_len;
368                         struct dentry *beacon_tail_len;
369                 } ap;
370                 struct {
371                         struct dentry *channel_use;
372                         struct dentry *drop_unencrypted;
373                         struct dentry *eapol;
374                         struct dentry *ieee8021_x;
375                         struct dentry *peer;
376                 } wds;
377                 struct {
378                         struct dentry *channel_use;
379                         struct dentry *drop_unencrypted;
380                         struct dentry *eapol;
381                         struct dentry *ieee8021_x;
382                         struct dentry *vlan_id;
383                 } vlan;
384                 struct {
385                         struct dentry *mode;
386                 } monitor;
387                 struct dentry *default_key;
388         } debugfs;
389 #endif
390 };
391
392 #define IEEE80211_DEV_TO_SUB_IF(dev) netdev_priv(dev)
393
394 enum {
395         IEEE80211_RX_MSG        = 1,
396         IEEE80211_TX_STATUS_MSG = 2,
397 };
398
399 struct ieee80211_local {
400         /* embed the driver visible part.
401          * don't cast (use the static inlines below), but we keep
402          * it first anyway so they become a no-op */
403         struct ieee80211_hw hw;
404
405         const struct ieee80211_ops *ops;
406
407         /* List of registered struct ieee80211_hw_mode */
408         struct list_head modes_list;
409
410         struct net_device *mdev; /* wmaster# - "master" 802.11 device */
411         struct net_device *apdev; /* wlan#ap - management frames (hostapd) */
412         int open_count;
413         int monitors;
414         struct iw_statistics wstats;
415         u8 wstats_flags;
416         int tx_headroom; /* required headroom for hardware/radiotap */
417
418         enum {
419                 IEEE80211_DEV_UNINITIALIZED = 0,
420                 IEEE80211_DEV_REGISTERED,
421                 IEEE80211_DEV_UNREGISTERED,
422         } reg_state;
423
424         /* Tasklet and skb queue to process calls from IRQ mode. All frames
425          * added to skb_queue will be processed, but frames in
426          * skb_queue_unreliable may be dropped if the total length of these
427          * queues increases over the limit. */
428 #define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
429         struct tasklet_struct tasklet;
430         struct sk_buff_head skb_queue;
431         struct sk_buff_head skb_queue_unreliable;
432
433         /* Station data structures */
434         rwlock_t sta_lock; /* protects STA data structures */
435         int num_sta; /* number of stations in sta_list */
436         struct list_head sta_list;
437         struct sta_info *sta_hash[STA_HASH_SIZE];
438         struct timer_list sta_cleanup;
439
440         unsigned long state[NUM_TX_DATA_QUEUES];
441         struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES];
442         struct tasklet_struct tx_pending_tasklet;
443
444         int mc_count;   /* total count of multicast entries in all interfaces */
445         int iff_allmultis, iff_promiscs;
446                         /* number of interfaces with corresponding IFF_ flags */
447
448         struct rate_control_ref *rate_ctrl;
449
450         int next_mode; /* MODE_IEEE80211*
451                         * The mode preference for next channel change. This is
452                         * used to select .11g vs. .11b channels (or 4.9 GHz vs.
453                         * .11a) when the channel number is not unique. */
454
455         /* Supported and basic rate filters for different modes. These are
456          * pointers to -1 terminated lists and rates in 100 kbps units. */
457         int *supp_rates[NUM_IEEE80211_MODES];
458         int *basic_rates[NUM_IEEE80211_MODES];
459
460         int rts_threshold;
461         int fragmentation_threshold;
462         int short_retry_limit; /* dot11ShortRetryLimit */
463         int long_retry_limit; /* dot11LongRetryLimit */
464
465         struct crypto_blkcipher *wep_tx_tfm;
466         struct crypto_blkcipher *wep_rx_tfm;
467         u32 wep_iv;
468         int key_tx_rx_threshold; /* number of times any key can be used in TX
469                                   * or RX before generating a rekey
470                                   * notification; 0 = notification disabled. */
471
472         int bridge_packets; /* bridge packets between associated stations and
473                              * deliver multicast frames both back to wireless
474                              * media and to the local net stack */
475
476         ieee80211_rx_handler *rx_pre_handlers;
477         ieee80211_rx_handler *rx_handlers;
478         ieee80211_tx_handler *tx_handlers;
479
480         rwlock_t sub_if_lock; /* Protects sub_if_list. Cannot be taken under
481                                * sta_bss_lock or sta_lock. */
482         struct list_head sub_if_list;
483         int sta_scanning;
484         int scan_channel_idx;
485         enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
486         unsigned long last_scan_completed;
487         struct delayed_work scan_work;
488         struct net_device *scan_dev;
489         struct ieee80211_channel *oper_channel, *scan_channel;
490         struct ieee80211_hw_mode *oper_hw_mode, *scan_hw_mode;
491         u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
492         size_t scan_ssid_len;
493         struct list_head sta_bss_list;
494         struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
495         spinlock_t sta_bss_lock;
496 #define IEEE80211_SCAN_MATCH_SSID BIT(0)
497 #define IEEE80211_SCAN_WPA_ONLY BIT(1)
498 #define IEEE80211_SCAN_EXTRA_INFO BIT(2)
499         int scan_flags;
500
501         /* SNMP counters */
502         /* dot11CountersTable */
503         u32 dot11TransmittedFragmentCount;
504         u32 dot11MulticastTransmittedFrameCount;
505         u32 dot11FailedCount;
506         u32 dot11RetryCount;
507         u32 dot11MultipleRetryCount;
508         u32 dot11FrameDuplicateCount;
509         u32 dot11ReceivedFragmentCount;
510         u32 dot11MulticastReceivedFrameCount;
511         u32 dot11TransmittedFrameCount;
512         u32 dot11WEPUndecryptableCount;
513
514 #ifdef CONFIG_MAC80211_LEDS
515         int tx_led_counter, rx_led_counter;
516         struct led_trigger *tx_led, *rx_led;
517         char tx_led_name[32], rx_led_name[32];
518 #endif
519
520         u32 channel_use;
521         u32 channel_use_raw;
522
523 #ifdef CONFIG_MAC80211_DEBUGFS
524         struct work_struct sta_debugfs_add;
525 #endif
526
527 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
528         /* TX/RX handler statistics */
529         unsigned int tx_handlers_drop;
530         unsigned int tx_handlers_queued;
531         unsigned int tx_handlers_drop_unencrypted;
532         unsigned int tx_handlers_drop_fragment;
533         unsigned int tx_handlers_drop_wep;
534         unsigned int tx_handlers_drop_not_assoc;
535         unsigned int tx_handlers_drop_unauth_port;
536         unsigned int rx_handlers_drop;
537         unsigned int rx_handlers_queued;
538         unsigned int rx_handlers_drop_nullfunc;
539         unsigned int rx_handlers_drop_defrag;
540         unsigned int rx_handlers_drop_short;
541         unsigned int rx_handlers_drop_passive_scan;
542         unsigned int tx_expand_skb_head;
543         unsigned int tx_expand_skb_head_cloned;
544         unsigned int rx_expand_skb_head;
545         unsigned int rx_expand_skb_head2;
546         unsigned int rx_handlers_fragments;
547         unsigned int tx_status_drop;
548         unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
549         unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
550 #define I802_DEBUG_INC(c) (c)++
551 #else /* CONFIG_MAC80211_DEBUG_COUNTERS */
552 #define I802_DEBUG_INC(c) do { } while (0)
553 #endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
554
555
556         int total_ps_buffered; /* total number of all buffered unicast and
557                                 * multicast packets for power saving stations
558                                 */
559         int wifi_wme_noack_test;
560         unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
561
562         unsigned int enabled_modes; /* bitfield of allowed modes;
563                                       * (1 << MODE_*) */
564         unsigned int hw_modes; /* bitfield of supported hardware modes;
565                                 * (1 << MODE_*) */
566
567         int user_space_mlme;
568
569 #ifdef CONFIG_MAC80211_DEBUGFS
570         struct local_debugfsdentries {
571                 struct dentry *channel;
572                 struct dentry *frequency;
573                 struct dentry *antenna_sel_tx;
574                 struct dentry *antenna_sel_rx;
575                 struct dentry *bridge_packets;
576                 struct dentry *key_tx_rx_threshold;
577                 struct dentry *rts_threshold;
578                 struct dentry *fragmentation_threshold;
579                 struct dentry *short_retry_limit;
580                 struct dentry *long_retry_limit;
581                 struct dentry *total_ps_buffered;
582                 struct dentry *mode;
583                 struct dentry *wep_iv;
584                 struct dentry *modes;
585                 struct dentry *statistics;
586                 struct local_debugfsdentries_statsdentries {
587                         struct dentry *transmitted_fragment_count;
588                         struct dentry *multicast_transmitted_frame_count;
589                         struct dentry *failed_count;
590                         struct dentry *retry_count;
591                         struct dentry *multiple_retry_count;
592                         struct dentry *frame_duplicate_count;
593                         struct dentry *received_fragment_count;
594                         struct dentry *multicast_received_frame_count;
595                         struct dentry *transmitted_frame_count;
596                         struct dentry *wep_undecryptable_count;
597                         struct dentry *num_scans;
598 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
599                         struct dentry *tx_handlers_drop;
600                         struct dentry *tx_handlers_queued;
601                         struct dentry *tx_handlers_drop_unencrypted;
602                         struct dentry *tx_handlers_drop_fragment;
603                         struct dentry *tx_handlers_drop_wep;
604                         struct dentry *tx_handlers_drop_not_assoc;
605                         struct dentry *tx_handlers_drop_unauth_port;
606                         struct dentry *rx_handlers_drop;
607                         struct dentry *rx_handlers_queued;
608                         struct dentry *rx_handlers_drop_nullfunc;
609                         struct dentry *rx_handlers_drop_defrag;
610                         struct dentry *rx_handlers_drop_short;
611                         struct dentry *rx_handlers_drop_passive_scan;
612                         struct dentry *tx_expand_skb_head;
613                         struct dentry *tx_expand_skb_head_cloned;
614                         struct dentry *rx_expand_skb_head;
615                         struct dentry *rx_expand_skb_head2;
616                         struct dentry *rx_handlers_fragments;
617                         struct dentry *tx_status_drop;
618                         struct dentry *wme_tx_queue;
619                         struct dentry *wme_rx_queue;
620 #endif
621                         struct dentry *dot11ACKFailureCount;
622                         struct dentry *dot11RTSFailureCount;
623                         struct dentry *dot11FCSErrorCount;
624                         struct dentry *dot11RTSSuccessCount;
625                 } stats;
626                 struct dentry *stations;
627                 struct dentry *keys;
628         } debugfs;
629 #endif
630 };
631
632 static inline struct ieee80211_local *hw_to_local(
633         struct ieee80211_hw *hw)
634 {
635         return container_of(hw, struct ieee80211_local, hw);
636 }
637
638 static inline struct ieee80211_hw *local_to_hw(
639         struct ieee80211_local *local)
640 {
641         return &local->hw;
642 }
643
644 enum ieee80211_link_state_t {
645         IEEE80211_LINK_STATE_XOFF = 0,
646         IEEE80211_LINK_STATE_PENDING,
647 };
648
649 struct sta_attribute {
650         struct attribute attr;
651         ssize_t (*show)(const struct sta_info *, char *buf);
652         ssize_t (*store)(struct sta_info *, const char *buf, size_t count);
653 };
654
655 static inline void __bss_tim_set(struct ieee80211_if_ap *bss, int aid)
656 {
657         /*
658          * This format has ben mandated by the IEEE specifications,
659          * so this line may not be changed to use the __set_bit() format.
660          */
661         bss->tim[(aid)/8] |= 1<<((aid) % 8);
662 }
663
664 static inline void bss_tim_set(struct ieee80211_local *local,
665                                struct ieee80211_if_ap *bss, int aid)
666 {
667         read_lock_bh(&local->sta_lock);
668         __bss_tim_set(bss, aid);
669         read_unlock_bh(&local->sta_lock);
670 }
671
672 static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, int aid)
673 {
674         /*
675          * This format has ben mandated by the IEEE specifications,
676          * so this line may not be changed to use the __clear_bit() format.
677          */
678         bss->tim[(aid)/8] &= !(1<<((aid) % 8));
679 }
680
681 static inline void bss_tim_clear(struct ieee80211_local *local,
682                                  struct ieee80211_if_ap *bss, int aid)
683 {
684         read_lock_bh(&local->sta_lock);
685         __bss_tim_clear(bss, aid);
686         read_unlock_bh(&local->sta_lock);
687 }
688
689 /**
690  * ieee80211_is_erp_rate - Check if a rate is an ERP rate
691  * @phymode: The PHY-mode for this rate (MODE_IEEE80211...)
692  * @rate: Transmission rate to check, in 100 kbps
693  *
694  * Check if a given rate is an Extended Rate PHY (ERP) rate.
695  */
696 static inline int ieee80211_is_erp_rate(int phymode, int rate)
697 {
698         if (phymode == MODE_IEEE80211G) {
699                 if (rate != 10 && rate != 20 &&
700                     rate != 55 && rate != 110)
701                         return 1;
702         }
703         return 0;
704 }
705
706 static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
707 {
708         return compare_ether_addr(raddr, addr) == 0 ||
709                is_broadcast_ether_addr(raddr);
710 }
711
712
713 /* ieee80211.c */
714 int ieee80211_hw_config(struct ieee80211_local *local);
715 int ieee80211_if_config(struct net_device *dev);
716 int ieee80211_if_config_beacon(struct net_device *dev);
717 void ieee80211_rx_mgmt(struct ieee80211_local *local, struct sk_buff *skb,
718                        struct ieee80211_rx_status *status, u32 msg_type);
719 void ieee80211_prepare_rates(struct ieee80211_local *local,
720                              struct ieee80211_hw_mode *mode);
721 void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
722 int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr);
723 void ieee80211_if_setup(struct net_device *dev);
724 void ieee80211_if_mgmt_setup(struct net_device *dev);
725 struct ieee80211_rate *ieee80211_get_rate(struct ieee80211_local *local,
726                                           int phymode, int hwrate);
727 void ieee80211_key_threshold_notify(struct net_device *dev,
728                                     struct ieee80211_key *key,
729                                     struct sta_info *sta);
730
731 /* ieee80211_ioctl.c */
732 extern const struct iw_handler_def ieee80211_iw_handler_def;
733
734
735 /* Least common multiple of the used rates (in 100 kbps). This is used to
736  * calculate rate_inv values for each rate so that only integers are needed. */
737 #define CHAN_UTIL_RATE_LCM 95040
738 /* 1 usec is 1/8 * (95040/10) = 1188 */
739 #define CHAN_UTIL_PER_USEC 1188
740 /* Amount of bits to shift the result right to scale the total utilization
741  * to values that will not wrap around 32-bit integers. */
742 #define CHAN_UTIL_SHIFT 9
743 /* Theoretical maximum of channel utilization counter in 10 ms (stat_time=1):
744  * (CHAN_UTIL_PER_USEC * 10000) >> CHAN_UTIL_SHIFT = 23203. So dividing the
745  * raw value with about 23 should give utilization in 10th of a percentage
746  * (1/1000). However, utilization is only estimated and not all intervals
747  * between frames etc. are calculated. 18 seems to give numbers that are closer
748  * to the real maximum. */
749 #define CHAN_UTIL_PER_10MS 18
750 #define CHAN_UTIL_HDR_LONG (202 * CHAN_UTIL_PER_USEC)
751 #define CHAN_UTIL_HDR_SHORT (40 * CHAN_UTIL_PER_USEC)
752
753
754 /* ieee80211_ioctl.c */
755 int ieee80211_set_compression(struct ieee80211_local *local,
756                               struct net_device *dev, struct sta_info *sta);
757 int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq);
758 /* ieee80211_sta.c */
759 void ieee80211_sta_timer(unsigned long data);
760 void ieee80211_sta_work(struct work_struct *work);
761 void ieee80211_sta_scan_work(struct work_struct *work);
762 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
763                            struct ieee80211_rx_status *rx_status);
764 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len);
765 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len);
766 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid);
767 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
768 void ieee80211_sta_req_auth(struct net_device *dev,
769                             struct ieee80211_if_sta *ifsta);
770 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
771 void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
772                            struct ieee80211_rx_status *rx_status);
773 void ieee80211_rx_bss_list_init(struct net_device *dev);
774 void ieee80211_rx_bss_list_deinit(struct net_device *dev);
775 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
776 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
777                                          struct sk_buff *skb, u8 *bssid,
778                                          u8 *addr);
779 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
780 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
781 void ieee80211_erp_info_change_notify(struct net_device *dev, u8 changes);
782 void ieee80211_reset_erp_info(struct net_device *dev);
783
784 /* ieee80211_iface.c */
785 int ieee80211_if_add(struct net_device *dev, const char *name,
786                      struct net_device **new_dev, int type);
787 void ieee80211_if_set_type(struct net_device *dev, int type);
788 void ieee80211_if_reinit(struct net_device *dev);
789 void __ieee80211_if_del(struct ieee80211_local *local,
790                         struct ieee80211_sub_if_data *sdata);
791 int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
792 void ieee80211_if_free(struct net_device *dev);
793 void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
794 int ieee80211_if_add_mgmt(struct ieee80211_local *local);
795 void ieee80211_if_del_mgmt(struct ieee80211_local *local);
796
797 /* regdomain.c */
798 void ieee80211_regdomain_init(void);
799 void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode);
800
801 /* rx handling */
802 extern ieee80211_rx_handler ieee80211_rx_pre_handlers[];
803 extern ieee80211_rx_handler ieee80211_rx_handlers[];
804
805 /* tx handling */
806 extern ieee80211_tx_handler ieee80211_tx_handlers[];
807 void ieee80211_clear_tx_pending(struct ieee80211_local *local);
808 void ieee80211_tx_pending(unsigned long data);
809 int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev);
810 int ieee80211_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
811 int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
812 int ieee80211_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev);
813
814 /* utility functions/constants */
815 extern void *mac80211_wiphy_privid; /* for wiphy privid */
816 extern const unsigned char rfc1042_header[6];
817 extern const unsigned char bridge_tunnel_header[6];
818 u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len);
819 int ieee80211_is_eapol(const struct sk_buff *skb);
820 int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
821                              int rate, int erp, int short_preamble);
822 void mac80211_ev_michael_mic_failure(struct net_device *dev, int keyidx,
823                                      struct ieee80211_hdr *hdr);
824
825 #endif /* IEEE80211_I_H */