improve dependency handling, fix some package makefile bugs
[10.03/openwrt.git] / target / linux / package / ieee80211-dscape / src / ieee80211_i.h
1 /*
2  * Copyright 2002-2005, Instant802 Networks, Inc.
3  * Copyright 2005, Devicescape Software, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9
10 #ifndef IEEE80211_I_H
11 #define IEEE80211_I_H
12
13 /* ieee80211.o internal definitions, etc. These are not included into
14  * low-level drivers. */
15
16 #ifndef ETH_P_PAE
17 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
18 #endif /* ETH_P_PAE */
19
20 #define IEEE80211_MAX_SSID_LEN 32
21
22 struct ieee80211_local;
23
24 #include "ieee80211_key.h"
25 #include "sta_info.h"
26
27 #define BIT(x) (1 << (x))
28
29 #define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
30
31
32 /* Maximum number of broadcast/multicast frames to buffer when some of the
33  * associated stations are using power saving. */
34 #define AP_MAX_BC_BUFFER 128
35
36 /* Maximum number of frames buffered to all STAs, including multicast frames.
37  * Note: increasing this limit increases the potential memory requirement. Each
38  * frame can be up to about 2 kB long. */
39 #define TOTAL_MAX_TX_BUFFER 512
40
41
42 #define MAC2STR(a) ((a)[0] & 0xff), ((a)[1] & 0xff), ((a)[2] & 0xff), \
43                    ((a)[3] & 0xff), ((a)[4] & 0xff), ((a)[5] & 0xff)
44 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
45
46 #define MULTICAST_ADDR(a) ((a)[0] & 0x01)
47
48
49 /* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
50  * reception of at least three fragmented frames. This limit can be increased
51  * by changing this define, at the cost of slower frame reassembly and
52  * increased memory use (about 2 kB of RAM per entry). */
53 #define IEEE80211_FRAGMENT_MAX 4
54
55 struct ieee80211_fragment_entry {
56         unsigned long first_frag_time;
57         unsigned int seq;
58         unsigned int rx_queue;
59         unsigned int last_frag;
60         struct sk_buff *skb;
61         int ccmp; /* Whether fragments were encrypted with CCMP */
62         u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
63 };
64
65
66 struct ieee80211_sta_bss {
67         struct list_head list;
68         struct ieee80211_sta_bss *hnext;
69         atomic_t users;
70
71         u8 bssid[ETH_ALEN];
72         u8 ssid[IEEE80211_MAX_SSID_LEN];
73         size_t ssid_len;
74         u16 capability; /* host byte order */
75         int hw_mode;
76         int channel;
77         int freq;
78         int rssi;
79         u8 *wpa_ie;
80         size_t wpa_ie_len;
81         u8 *rsn_ie;
82         size_t rsn_ie_len;
83         u8 *wmm_ie;
84         size_t wmm_ie_len;
85 #define IEEE80211_MAX_SUPP_RATES 32
86         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
87         size_t supp_rates_len;
88         int beacon_int;
89         u64 timestamp;
90
91         int probe_resp;
92         unsigned long last_update;
93
94 };
95
96
97 typedef enum {
98         TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
99 } ieee80211_txrx_result;
100
101 struct ieee80211_txrx_data {
102         struct sk_buff *skb;
103         struct net_device *dev;
104         struct ieee80211_local *local;
105         struct ieee80211_sub_if_data *sdata;
106         struct sta_info *sta;
107         u16 fc, ethertype;
108         struct ieee80211_key *key;
109         unsigned int fragmented:1; /* whether the MSDU was fragmented */
110         union {
111                 struct {
112                         struct ieee80211_tx_control *control;
113                         int unicast:1;
114                         int ps_buffered:1;
115                         int short_preamble:1;
116                         int probe_last_frag:1;
117                         struct ieee80211_rate *rate;
118                         /* use this rate (if set) for last fragment; rate can
119                          * be set to lower rate for the first fragments, e.g.,
120                          * when using CTS protection with IEEE 802.11g. */
121                         struct ieee80211_rate *last_frag_rate;
122                         int last_frag_rateidx;
123                         int mgmt_interface;
124
125                         /* Extra fragments (in addition to the first fragment
126                          * in skb) */
127                         int num_extra_frag;
128                         struct sk_buff **extra_frag;
129                 } tx;
130                 struct {
131                         struct ieee80211_rx_status *status;
132                         int sent_ps_buffered;
133                         int queue;
134                 } rx;
135         } u;
136 #ifdef CONFIG_HOSTAPD_WPA_TESTING
137         int wpa_test;
138 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
139 };
140
141 struct ieee80211_passive_scan {
142         unsigned int in_scan:1; /* this must be cleared before calling
143                                  * netif_oper(WAKEUP) */
144         unsigned int our_mode_only:1; /* only scan our physical mode a/b/g/etc
145                                        */
146         int interval; /* time in seconds between scans */
147         int time; /* time in microseconds to scan for */
148         int channel; /* channel to be scanned */
149         int tries;
150
151         int mode_idx;
152         int chan_idx;
153
154         int freq;
155         int rx_packets;
156         int rx_beacon;
157         int txrx_count;
158
159         struct timer_list timer;
160
161         struct sk_buff *skb; /* skb to transmit before changing channels,
162                               * maybe null for none */
163         struct ieee80211_tx_control tx_control;
164
165         unsigned int num_scans;
166 };
167
168 typedef ieee80211_txrx_result (*ieee80211_tx_handler)
169 (struct ieee80211_txrx_data *tx);
170
171 typedef ieee80211_txrx_result (*ieee80211_rx_handler)
172 (struct ieee80211_txrx_data *rx);
173
174 struct ieee80211_if_norm {
175         u8 *beacon_head, *beacon_tail;
176         int beacon_head_len, beacon_tail_len;
177
178         /* TODO: sta_aid could be replaced by 2008-bit large bitfield of
179          * that could be used in TIM element generation. This would also
180          * make TIM element generation a bit faster. */
181         /* AID mapping to station data. NULL, if AID is free. AID is in the
182          * range 1..2007 and sta_aid[i] corresponds to AID i+1. */
183         struct sta_info *sta_aid[MAX_AID_TABLE_SIZE];
184         int max_aid; /* largest aid currently in use */
185         atomic_t num_sta_ps; /* number of stations in PS mode */
186         struct sk_buff_head ps_bc_buf;
187         int dtim_period, dtim_count;
188         int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
189         int max_ratectrl_rateidx; /* max TX rateidx for rate control */
190         int num_beacons; /* number of TXed beacon frames for this BSS */
191 };
192
193 struct ieee80211_if_wds {
194         u8 remote_addr[ETH_ALEN];
195         struct sta_info *sta;
196 };
197
198 struct ieee80211_if_vlan {
199         u8 id;
200 };
201
202 struct ieee80211_if_sta {
203         enum {
204                 IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
205                 IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
206                 IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
207         } state;
208         struct timer_list timer;
209         u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
210         u8 ssid[IEEE80211_MAX_SSID_LEN];
211         size_t ssid_len;
212         u16 aid;
213         u16 ap_capab, capab;
214         u8 *extra_ie; /* to be added to the end of AssocReq */
215         size_t extra_ie_len;
216
217         /* The last AssocReq/Resp IEs */
218         u8 *assocreq_ies, *assocresp_ies;
219         size_t assocreq_ies_len, assocresp_ies_len;
220
221         int auth_tries, assoc_tries;
222
223         int ssid_set:1;
224         int bssid_set:1;
225         int prev_bssid_set:1;
226         int authenticated:1;
227         int associated:1;
228         int probereq_poll:1;
229         int use_protection:1;
230         int create_ibss:1;
231         int mixed_cell:1;
232         int wmm_enabled:1;
233
234         int key_mgmt;
235         unsigned long last_probe;
236
237 #define IEEE80211_AUTH_ALG_OPEN BIT(0)
238 #define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
239 #define IEEE80211_AUTH_ALG_LEAP BIT(2)
240         unsigned int auth_algs; /* bitfield of allowed auth algs */
241         int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
242         int auth_transaction;
243
244         unsigned long ibss_join_req;
245         struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
246         u32 supp_rates_bits;
247
248         int wmm_last_param_set;
249 };
250
251
252 #define IEEE80211_SUB_IF_TYPE_NORM 0x00000000
253 #define IEEE80211_SUB_IF_TYPE_MGMT 0x00000001
254 #define IEEE80211_SUB_IF_TYPE_STA  0x00000002
255 #define IEEE80211_SUB_IF_TYPE_WDS  0x5A580211
256 #define IEEE80211_SUB_IF_TYPE_VLAN 0x00080211
257
258 struct ieee80211_sub_if_data {
259         struct list_head list;
260         unsigned int type;
261
262         struct net_device *dev;
263         struct net_device *master;
264         struct ieee80211_local *local;
265
266         struct net_device_stats stats;
267         int drop_unencrypted;
268         int eapol; /* 0 = process EAPOL frames as normal data frames,
269                     * 1 = send EAPOL frames through wlan#ap to hostapd
270                     *     (default) */
271         int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
272                          * port */
273
274 #define NUM_DEFAULT_KEYS 4
275         struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
276         struct ieee80211_key *default_key;
277
278         struct ieee80211_if_norm *bss; /* BSS that this device belongs to */
279
280         union {
281                 struct ieee80211_if_norm norm;
282                 struct ieee80211_if_wds wds;
283                 struct ieee80211_if_vlan vlan;
284                 struct ieee80211_if_sta sta;
285         } u;
286         int channel_use;
287         int channel_use_raw;
288 };
289
290 #define IEEE80211_DEV_TO_SUB_IF(dev) ((struct ieee80211_sub_if_data *) \
291                      (((long)dev + sizeof(struct net_device) + 3) & ~3))
292
293
294 struct ieee80211_local {
295         struct ieee80211_hw *hw;
296         void *hw_priv;
297         struct net_device *mdev; /* wlan#.11 - "master" 802.11 device */
298         struct net_device *wdev; /* wlan# - default Ethernet (data) devide */
299         struct net_device *apdev; /* wlan#ap - management frames (hostapd) */
300         int open_count;
301         struct ieee80211_conf conf;
302
303         /* Tasklet and skb queue to process calls from IRQ mode. All frames
304          * added to skb_queue will be processed, but frames in
305          * skb_queue_unreliable may be dropped if the total length of these
306          * queues increases over the limit. */
307 #define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
308         struct tasklet_struct tasklet;
309         struct sk_buff_head skb_queue;
310         struct sk_buff_head skb_queue_unreliable;
311         enum {
312                 ieee80211_rx_msg = 1,
313                 ieee80211_tx_status_msg = 2
314         } ieee80211_msg_enum;
315
316         spinlock_t generic_lock;
317         /* Station data structures */
318         spinlock_t sta_lock; /* mutex for STA data structures */
319         int num_sta; /* number of stations in sta_list */
320         struct list_head sta_list;
321         struct sta_info *sta_hash[STA_HASH_SIZE];
322         struct timer_list sta_cleanup;
323
324         /* Current rate table. This is a pointer to hw->modes structure. */
325         struct ieee80211_rate *curr_rates;
326         int num_curr_rates;
327
328         void *rate_ctrl_priv;
329         struct rate_control_ops *rate_ctrl;
330
331         int next_mode; /* MODE_IEEE80211*
332                         * The mode preference for next channel change. This is
333                         * used to select .11g vs. .11b channels (or 4.9 GHz vs.
334                         * .11a) when the channel number is not unique. */
335
336         /* Supported and basic rate filters for different modes. These are
337          * pointers to -1 terminated lists and rates in 100 kbps units. */
338         int *supp_rates[NUM_IEEE80211_MODES];
339         int *basic_rates[NUM_IEEE80211_MODES];
340
341         int rts_threshold;
342         int cts_protect_erp_frames;
343         int fragmentation_threshold;
344         int short_retry_limit; /* dot11ShortRetryLimit */
345         int long_retry_limit; /* dot11LongRetryLimit */
346         int short_preamble; /* use short preamble with IEEE 802.11b */
347
348         u32 wep_iv;
349         int key_tx_rx_threshold; /* number of times any key can be used in TX
350                                   * or RX before generating a rekey
351                                   * notification; 0 = notification disabled. */
352
353         /* Fragment table for host-based reassembly */
354         struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
355         unsigned int fragment_next;
356
357         int bridge_packets; /* bridge packets between associated stations and
358                              * deliver multicast frames both back to wireless
359                              * media and to the local net stack */
360
361         struct ieee80211_passive_scan scan;
362
363
364         ieee80211_rx_handler *rx_handlers;
365         ieee80211_tx_handler *tx_handlers;
366
367         spinlock_t sub_if_lock; /* mutex for STA data structures */
368         struct list_head sub_if_list;
369         struct net_device **bss_devs; /* pointer to IF_TYPE_NORM devices for
370                                        * quick access to BSS data */
371         int bss_dev_count; /* number of used entries in bss_devs; note: the
372                             * total size of bss_devs array is stored in
373                             * conf.bss_count */
374         struct net_device **sta_devs; /* pointer to IF_TYPE_STA devices */
375         int sta_dev_count; /* number of used entries in sta_devs */
376         int sta_scanning;
377         int scan_hw_mode_idx;
378         int scan_channel_idx;
379         enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
380         unsigned long last_scan_completed;
381         struct timer_list scan_timer;
382         int scan_oper_channel;
383         int scan_oper_channel_val;
384         int scan_oper_power_level;
385         int scan_oper_freq;
386         int scan_oper_phymode;
387         int scan_oper_antenna_max;
388         u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
389         size_t scan_ssid_len;
390         int scan_skip_11b;
391         struct list_head sta_bss_list;
392         struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
393         spinlock_t sta_bss_lock;
394 #define IEEE80211_SCAN_MATCH_SSID BIT(0)
395 #define IEEE80211_SCAN_WPA_ONLY BIT(1)
396 #define IEEE80211_SCAN_EXTRA_INFO BIT(2)
397         int scan_flags;
398
399 #ifdef CONFIG_HOSTAPD_WPA_TESTING
400         u32 wpa_trigger;
401 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
402         /* SNMP counters */
403         /* dot11CountersTable */
404         u32 dot11TransmittedFragmentCount;
405         u32 dot11MulticastTransmittedFrameCount;
406         u32 dot11FailedCount;
407         u32 dot11RetryCount;
408         u32 dot11MultipleRetryCount;
409         u32 dot11FrameDuplicateCount;
410         u32 dot11ReceivedFragmentCount;
411         u32 dot11MulticastReceivedFrameCount;
412         u32 dot11TransmittedFrameCount;
413         u32 dot11WEPUndecryptableCount;
414
415         int tx_led_counter;
416
417         u32 channel_use;
418         u32 channel_use_raw;
419         u32 stat_time;
420         struct timer_list stat_timer;
421
422         u8 bssid[ETH_ALEN]; /* BSSID for STA modes (Adhoc/Managed) */
423         struct timer_list rate_limit_timer;
424         u32 rate_limit;
425         u32 rate_limit_burst;
426         u32 rate_limit_bucket;
427         struct proc_dir_entry *proc, *proc_sta, *proc_iface;
428
429         struct work_struct sta_proc_add;
430
431         enum {
432                 STA_ANTENNA_SEL_AUTO = 0,
433                 STA_ANTENNA_SEL_SW_CTRL = 1,
434                 STA_ANTENNA_SEL_SW_CTRL_DEBUG = 2
435         } sta_antenna_sel;
436
437         int rate_ctrl_num_up, rate_ctrl_num_down;
438
439 #ifdef CONFIG_IEEE80211_DEBUG_COUNTERS
440         /* TX/RX handler statistics */
441         unsigned int tx_handlers_drop;
442         unsigned int tx_handlers_queued;
443         unsigned int tx_handlers_drop_unencrypted;
444         unsigned int tx_handlers_drop_fragment;
445         unsigned int tx_handlers_drop_wep;
446         unsigned int tx_handlers_drop_rate_limit;
447         unsigned int tx_handlers_drop_not_assoc;
448         unsigned int tx_handlers_drop_unauth_port;
449         unsigned int rx_handlers_drop;
450         unsigned int rx_handlers_queued;
451         unsigned int rx_handlers_drop_nullfunc;
452         unsigned int rx_handlers_drop_defrag;
453         unsigned int rx_handlers_drop_short;
454         unsigned int rx_handlers_drop_passive_scan;
455         unsigned int tx_expand_skb_head;
456         unsigned int tx_expand_skb_head_cloned;
457         unsigned int rx_expand_skb_head;
458         unsigned int rx_expand_skb_head2;
459         unsigned int rx_handlers_fragments;
460         unsigned int tx_status_drop;
461         unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
462         unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
463 #define I802_DEBUG_INC(c) (c)++
464 #else /* CONFIG_IEEE80211_DEBUG_COUNTERS */
465 #define I802_DEBUG_INC(c) do { } while (0)
466 #endif /* CONFIG_IEEE80211_DEBUG_COUNTERS */
467
468
469         int default_wep_only; /* only default WEP keys are used with this
470                                * interface; this is used to decide when hwaccel
471                                * can be used with default keys */
472         int total_ps_buffered; /* total number of all buffered unicast and
473                                 * multicast packets for power saving stations
474                                 */
475         int allow_broadcast_always; /* whether to allow TX of broadcast frames
476                                      * even when there are no associated STAs
477                                      */
478
479         int wifi_wme_noack_test;
480         unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
481
482         unsigned int hw_modes; /* bitfield of allowed hardware modes;
483                                 * (1 << MODE_*) */
484 };
485
486
487 /* ieee80211.c */
488 int ieee80211_hw_config(struct net_device *dev);
489 struct ieee80211_key_conf *
490 ieee80211_key_data2conf(struct ieee80211_local *local,
491                         struct ieee80211_key *data);
492 void ieee80211_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
493                        struct ieee80211_rx_status *status, u32 msg_type);
494 void ieee80211_prepare_rates(struct net_device *dev);
495 void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
496 int ieee80211_if_add_wds(struct net_device *dev,
497                          char *name,
498                          struct ieee80211_if_wds *wds, int locked);
499 int ieee80211_if_add_vlan(struct net_device *dev, char *name,
500                           struct ieee80211_if_vlan *vlan, int locked);
501 int ieee80211_if_add_norm(struct net_device *dev, char *name, u8 *bssid,
502                           int locked);
503
504 int ieee80211_if_remove_wds(struct net_device *dev, char *name, int locked);
505 int ieee80211_if_remove_vlan(struct net_device *dev, char *name, int locked);
506 int ieee80211_if_remove_norm(struct net_device *dev, char *name, int locked);
507 int ieee80211_if_flush(struct net_device *dev, int locked);
508 int ieee80211_if_update_wds(struct net_device *dev, char *name,
509                             struct ieee80211_if_wds *wds, int locked);
510
511 /* ieee80211_ioctl.c */
512 int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
513 /* Set hw encryption from ieee80211 */
514 int ieee80211_set_hw_encryption(struct net_device *dev,
515                                 struct sta_info *sta, u8 addr[ETH_ALEN],
516                                 struct ieee80211_key *key);
517
518 /* ieee80211_scan.c */
519 void ieee80211_init_scan(struct net_device *dev);
520 void ieee80211_stop_scan(struct net_device *dev);
521
522
523
524 /* Least common multiple of the used rates (in 100 kbps). This is used to
525  * calculate rate_inv values for each rate so that only integers are needed. */
526 #define CHAN_UTIL_RATE_LCM 95040
527 /* 1 usec is 1/8 * (95040/10) = 1188 */
528 #define CHAN_UTIL_PER_USEC 1188
529 /* Amount of bits to shift the result right to scale the total utilization
530  * to values that will not wrap around 32-bit integers. */
531 #define CHAN_UTIL_SHIFT 9
532 /* Theoretical maximum of channel utilization counter in 10 ms (stat_time=1):
533  * (CHAN_UTIL_PER_USEC * 10000) >> CHAN_UTIL_SHIFT = 23203. So dividing the
534  * raw value with about 23 should give utilization in 10th of a percentage
535  * (1/1000). However, utilization is only estimated and not all intervals
536  * between frames etc. are calculated. 18 seems to give numbers that are closer
537  * to the real maximum. */
538 #define CHAN_UTIL_PER_10MS 18
539 #define CHAN_UTIL_HDR_LONG (202 * CHAN_UTIL_PER_USEC)
540 #define CHAN_UTIL_HDR_SHORT (40 * CHAN_UTIL_PER_USEC)
541
542
543
544 /* ieee80211.c */
545 int ieee80211_if_add_sta(struct net_device *dev, char *name, int locked);
546 int ieee80211_if_remove_sta(struct net_device *dev, char *name, int locked);
547 /* ieee80211_ioctl.c */
548 int ieee80211_set_compression(struct ieee80211_local *local,
549                               struct net_device *dev, struct sta_info *sta);
550 /* ieee80211_sta.c */
551 void ieee80211_sta_timer(unsigned long ptr);
552 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
553                            struct ieee80211_rx_status *rx_status);
554 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len);
555 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len);
556 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid);
557 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
558 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
559 void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
560                            struct ieee80211_rx_status *rx_status);
561 void ieee80211_rx_bss_list_init(struct net_device *dev);
562 void ieee80211_rx_bss_list_deinit(struct net_device *dev);
563 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
564 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
565                                          struct sk_buff *skb, u8 *bssid,
566                                          u8 *addr);
567 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
568 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
569
570
571 #endif /* IEEE80211_I_H */