2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005, Devicescape Software, Inc.
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.
13 /* ieee80211.o internal definitions, etc. These are not included into
14 * low-level drivers. */
17 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
18 #endif /* ETH_P_PAE */
20 #define IEEE80211_MAX_SSID_LEN 32
22 struct ieee80211_local
;
24 #include "ieee80211_key.h"
27 #define BIT(x) (1 << (x))
29 #define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
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
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
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"
46 #define MULTICAST_ADDR(a) ((a)[0] & 0x01)
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
55 struct ieee80211_fragment_entry
{
56 unsigned long first_frag_time
;
58 unsigned int rx_queue
;
59 unsigned int last_frag
;
61 int ccmp
; /* Whether fragments were encrypted with CCMP */
62 u8 last_pn
[6]; /* PN of the last fragment if CCMP was used */
66 struct ieee80211_sta_bss
{
67 struct list_head list
;
68 struct ieee80211_sta_bss
*hnext
;
72 u8 ssid
[IEEE80211_MAX_SSID_LEN
];
74 u16 capability
; /* host byte order */
85 #define IEEE80211_MAX_SUPP_RATES 32
86 u8 supp_rates
[IEEE80211_MAX_SUPP_RATES
];
87 size_t supp_rates_len
;
92 unsigned long last_update
;
98 TXRX_CONTINUE
, TXRX_DROP
, TXRX_QUEUED
99 } ieee80211_txrx_result
;
101 struct ieee80211_txrx_data
{
103 struct net_device
*dev
;
104 struct ieee80211_local
*local
;
105 struct ieee80211_sub_if_data
*sdata
;
106 struct sta_info
*sta
;
108 struct ieee80211_key
*key
;
109 unsigned int fragmented
:1; /* whether the MSDU was fragmented */
112 struct ieee80211_tx_control
*control
;
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
;
125 /* Extra fragments (in addition to the first fragment
128 struct sk_buff
**extra_frag
;
131 struct ieee80211_rx_status
*status
;
132 int sent_ps_buffered
;
136 #ifdef CONFIG_HOSTAPD_WPA_TESTING
138 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
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
146 int interval
; /* time in seconds between scans */
147 int time
; /* time in microseconds to scan for */
148 int channel
; /* channel to be scanned */
159 struct timer_list timer
;
161 struct sk_buff
*skb
; /* skb to transmit before changing channels,
162 * maybe null for none */
163 struct ieee80211_tx_control tx_control
;
165 unsigned int num_scans
;
168 typedef ieee80211_txrx_result (*ieee80211_tx_handler
)
169 (struct ieee80211_txrx_data
*tx
);
171 typedef ieee80211_txrx_result (*ieee80211_rx_handler
)
172 (struct ieee80211_txrx_data
*rx
);
174 struct ieee80211_if_norm
{
175 u8
*beacon_head
, *beacon_tail
;
176 int beacon_head_len
, beacon_tail_len
;
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 */
193 struct ieee80211_if_wds
{
194 u8 remote_addr
[ETH_ALEN
];
195 struct sta_info
*sta
;
198 struct ieee80211_if_vlan
{
202 struct ieee80211_if_sta
{
204 IEEE80211_DISABLED
, IEEE80211_AUTHENTICATE
,
205 IEEE80211_ASSOCIATE
, IEEE80211_ASSOCIATED
,
206 IEEE80211_IBSS_SEARCH
, IEEE80211_IBSS_JOINED
208 struct timer_list timer
;
209 u8 bssid
[ETH_ALEN
], prev_bssid
[ETH_ALEN
];
210 u8 ssid
[IEEE80211_MAX_SSID_LEN
];
214 u8
*extra_ie
; /* to be added to the end of AssocReq */
217 /* The last AssocReq/Resp IEs */
218 u8
*assocreq_ies
, *assocresp_ies
;
219 size_t assocreq_ies_len
, assocresp_ies_len
;
221 int auth_tries
, assoc_tries
;
225 int prev_bssid_set
:1;
229 int use_protection
:1;
235 unsigned long last_probe
;
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
;
244 unsigned long ibss_join_req
;
245 struct sk_buff
*probe_resp
; /* ProbeResp template for IBSS */
248 int wmm_last_param_set
;
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
258 struct ieee80211_sub_if_data
{
259 struct list_head list
;
262 struct net_device
*dev
;
263 struct net_device
*master
;
264 struct ieee80211_local
*local
;
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
271 int ieee802_1x
; /* IEEE 802.1X PAE - drop packet to/from unauthorized
274 #define NUM_DEFAULT_KEYS 4
275 struct ieee80211_key
*keys
[NUM_DEFAULT_KEYS
];
276 struct ieee80211_key
*default_key
;
278 struct ieee80211_if_norm
*bss
; /* BSS that this device belongs to */
281 struct ieee80211_if_norm norm
;
282 struct ieee80211_if_wds wds
;
283 struct ieee80211_if_vlan vlan
;
284 struct ieee80211_if_sta sta
;
290 #define IEEE80211_DEV_TO_SUB_IF(dev) ((struct ieee80211_sub_if_data *) \
291 (((long)dev + sizeof(struct net_device) + 3) & ~3))
294 struct ieee80211_local
{
295 struct ieee80211_hw
*hw
;
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) */
301 struct ieee80211_conf conf
;
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
;
312 ieee80211_rx_msg
= 1,
313 ieee80211_tx_status_msg
= 2
314 } ieee80211_msg_enum
;
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
;
324 /* Current rate table. This is a pointer to hw->modes structure. */
325 struct ieee80211_rate
*curr_rates
;
328 void *rate_ctrl_priv
;
329 struct rate_control_ops
*rate_ctrl
;
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. */
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
];
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 */
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. */
353 /* Fragment table for host-based reassembly */
354 struct ieee80211_fragment_entry fragments
[IEEE80211_FRAGMENT_MAX
];
355 unsigned int fragment_next
;
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 */
361 struct ieee80211_passive_scan scan
;
364 ieee80211_rx_handler
*rx_handlers
;
365 ieee80211_tx_handler
*tx_handlers
;
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
374 struct net_device
**sta_devs
; /* pointer to IF_TYPE_STA devices */
375 int sta_dev_count
; /* number of used entries in sta_devs */
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
;
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
;
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)
399 #ifdef CONFIG_HOSTAPD_WPA_TESTING
401 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
403 /* dot11CountersTable */
404 u32 dot11TransmittedFragmentCount
;
405 u32 dot11MulticastTransmittedFrameCount
;
406 u32 dot11FailedCount
;
408 u32 dot11MultipleRetryCount
;
409 u32 dot11FrameDuplicateCount
;
410 u32 dot11ReceivedFragmentCount
;
411 u32 dot11MulticastReceivedFrameCount
;
412 u32 dot11TransmittedFrameCount
;
413 u32 dot11WEPUndecryptableCount
;
420 struct timer_list stat_timer
;
422 u8 bssid
[ETH_ALEN
]; /* BSSID for STA modes (Adhoc/Managed) */
423 struct timer_list rate_limit_timer
;
425 u32 rate_limit_burst
;
426 u32 rate_limit_bucket
;
427 struct proc_dir_entry
*proc
, *proc_sta
, *proc_iface
;
429 struct work_struct sta_proc_add
;
432 STA_ANTENNA_SEL_AUTO
= 0,
433 STA_ANTENNA_SEL_SW_CTRL
= 1,
434 STA_ANTENNA_SEL_SW_CTRL_DEBUG
= 2
437 int rate_ctrl_num_up
, rate_ctrl_num_down
;
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 */
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
475 int allow_broadcast_always
; /* whether to allow TX of broadcast frames
476 * even when there are no associated STAs
479 int wifi_wme_noack_test
;
480 unsigned int wmm_acm
; /* bit field of ACM bits (BIT(802.1D tag)) */
482 unsigned int hw_modes
; /* bitfield of allowed hardware modes;
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
,
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
,
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
);
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
);
518 /* ieee80211_scan.c */
519 void ieee80211_init_scan(struct net_device
*dev
);
520 void ieee80211_stop_scan(struct net_device
*dev
);
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)
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
,
567 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
);
568 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
);
571 #endif /* IEEE80211_I_H */