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.
14 #include <linux/config.h>
15 #include <linux/version.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/netdevice.h>
19 #include <linux/types.h>
20 #include <linux/slab.h>
21 #include <linux/skbuff.h>
22 #include <linux/etherdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/wireless.h>
25 #include <net/iw_handler.h>
26 #include <linux/compiler.h>
28 #include <net/ieee80211.h>
29 #include <net/ieee80211_common.h>
30 #include <net/ieee80211_mgmt.h>
31 #include "ieee80211_i.h"
32 #include "ieee80211_proc.h"
33 #include "rate_control.h"
40 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
41 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
42 static unsigned char rfc1042_header
[] =
43 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
44 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
45 static unsigned char bridge_tunnel_header
[] =
46 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
47 /* No encapsulation header if EtherType < 0x600 (=length) */
49 static unsigned char eapol_header
[] =
50 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
53 struct rate_control_algs
{
54 struct rate_control_algs
*next
;
55 struct rate_control_ops
*ops
;
58 static struct rate_control_algs
*ieee80211_rate_ctrl_algs
;
60 static int rate_control_initialize(struct ieee80211_local
*local
);
63 static u8
* ieee80211_get_bssid(struct ieee80211_hdr
*hdr
, size_t len
);
66 struct ieee80211_key_conf
*
67 ieee80211_key_data2conf(struct ieee80211_local
*local
,
68 struct ieee80211_key
*data
)
70 struct ieee80211_key_conf
*conf
;
72 conf
= kmalloc(sizeof(*conf
) + data
->keylen
, GFP_ATOMIC
);
76 conf
->hw_key_idx
= data
->hw_key_idx
;
77 conf
->alg
= data
->alg
;
78 conf
->keylen
= data
->keylen
;
79 conf
->force_sw_encrypt
= data
->force_sw_encrypt
;
80 conf
->keyidx
= data
->keyidx
;
81 conf
->default_tx_key
= data
->default_tx_key
;
82 conf
->default_wep_only
= local
->default_wep_only
;
83 memcpy(conf
->key
, data
->key
, data
->keylen
);
89 static int rate_list_match(int *rate_list
, int rate
)
93 if (rate_list
== NULL
)
96 for (i
= 0; rate_list
[i
] >= 0; i
++)
97 if (rate_list
[i
] == rate
)
104 void ieee80211_prepare_rates(struct net_device
*dev
)
106 struct ieee80211_local
*local
= dev
->priv
;
109 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
110 struct ieee80211_rate
*rate
= &local
->curr_rates
[i
];
112 rate
->flags
&= ~(IEEE80211_RATE_SUPPORTED
|
113 IEEE80211_RATE_BASIC
);
115 if (local
->supp_rates
[local
->conf
.phymode
]) {
116 if (!rate_list_match(local
->supp_rates
117 [local
->conf
.phymode
],
122 rate
->flags
|= IEEE80211_RATE_SUPPORTED
;
124 /* Use configured basic rate set if it is available. If not,
125 * use defaults that are sane for most cases. */
126 if (local
->basic_rates
[local
->conf
.phymode
]) {
127 if (rate_list_match(local
->basic_rates
128 [local
->conf
.phymode
],
130 rate
->flags
|= IEEE80211_RATE_BASIC
;
131 } else switch (local
->conf
.phymode
) {
132 case MODE_IEEE80211A
:
133 if (rate
->rate
== 60 || rate
->rate
== 120 ||
135 rate
->flags
|= IEEE80211_RATE_BASIC
;
137 case MODE_IEEE80211B
:
138 if (rate
->rate
== 10 || rate
->rate
== 20)
139 rate
->flags
|= IEEE80211_RATE_BASIC
;
141 case MODE_ATHEROS_TURBO
:
142 if (rate
->rate
== 120 || rate
->rate
== 240 ||
144 rate
->flags
|= IEEE80211_RATE_BASIC
;
146 case MODE_IEEE80211G
:
147 if (rate
->rate
== 10 || rate
->rate
== 20 ||
148 rate
->rate
== 55 || rate
->rate
== 110)
149 rate
->flags
|= IEEE80211_RATE_BASIC
;
153 /* Set ERP and MANDATORY flags based on phymode */
154 switch (local
->conf
.phymode
) {
155 case MODE_IEEE80211A
:
156 if (rate
->rate
== 60 || rate
->rate
== 120 ||
158 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
160 case MODE_IEEE80211B
:
161 if (rate
->rate
== 10)
162 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
164 case MODE_ATHEROS_TURBO
:
166 case MODE_IEEE80211G
:
167 if (rate
->rate
== 10 || rate
->rate
== 20 ||
168 rate
->rate
== 55 || rate
->rate
== 110 ||
169 rate
->rate
== 60 || rate
->rate
== 120 ||
171 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
172 if (rate
->rate
!= 10 && rate
->rate
!= 20 &&
173 rate
->rate
!= 55 && rate
->rate
!= 110)
174 rate
->flags
|= IEEE80211_RATE_ERP
;
181 static void ieee80211_key_threshold_notify(struct net_device
*dev
,
182 struct ieee80211_key
*key
,
183 struct sta_info
*sta
)
186 struct ieee80211_msg_key_notification
*msg
;
188 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
189 sizeof(struct ieee80211_msg_key_notification
));
193 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
194 msg
= (struct ieee80211_msg_key_notification
*)
195 skb_put(skb
, sizeof(struct ieee80211_msg_key_notification
));
196 msg
->tx_rx_count
= key
->tx_rx_count
;
197 memcpy(msg
->ifname
, dev
->name
, IFNAMSIZ
);
199 memcpy(msg
->addr
, sta
->addr
, ETH_ALEN
);
201 memset(msg
->addr
, 0xff, ETH_ALEN
);
203 key
->tx_rx_count
= 0;
205 ieee80211_rx_mgmt(dev
, skb
, 0,
206 ieee80211_msg_key_threshold_notification
);
210 int ieee80211_get_hdrlen(u16 fc
)
214 switch (WLAN_FC_GET_TYPE(fc
)) {
215 case WLAN_FC_TYPE_DATA
:
216 if ((fc
& WLAN_FC_FROMDS
) && (fc
& WLAN_FC_TODS
))
217 hdrlen
= 30; /* Addr4 */
218 if (WLAN_FC_GET_STYPE(fc
) & 0x08)
219 hdrlen
+= 2; /* QoS Control Field */
221 case WLAN_FC_TYPE_CTRL
:
222 switch (WLAN_FC_GET_STYPE(fc
)) {
223 case WLAN_FC_STYPE_CTS
:
224 case WLAN_FC_STYPE_ACK
:
238 int ieee80211_get_hdrlen_from_skb(struct sk_buff
*skb
)
240 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
243 if (unlikely(skb
->len
< 10))
245 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_control
));
246 if (unlikely(hdrlen
> skb
->len
))
252 #ifdef IEEE80211_VERBOSE_DEBUG_FRAME_DUMP
253 static void ieee80211_dump_frame(const char *ifname
, const char *title
,
256 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
260 printk(KERN_DEBUG
"%s: %s (len=%d)", ifname
, title
, skb
->len
);
266 fc
= le16_to_cpu(hdr
->frame_control
);
267 hdrlen
= ieee80211_get_hdrlen(fc
);
268 if (hdrlen
> skb
->len
)
271 printk(" FC=0x%04x DUR=0x%04x",
272 fc
, le16_to_cpu(hdr
->duration_id
));
274 printk(" A1=" MACSTR
, MAC2STR(hdr
->addr1
));
276 printk(" A2=" MACSTR
, MAC2STR(hdr
->addr2
));
278 printk(" A3=" MACSTR
, MAC2STR(hdr
->addr3
));
280 printk(" A4=" MACSTR
, MAC2STR(hdr
->addr4
));
283 #else /* IEEE80211_VERBOSE_DEBUG_FRAME_DUMP */
284 static inline void ieee80211_dump_frame(const char *ifname
, const char *title
,
288 #endif /* IEEE80211_VERBOSE_DEBUG_FRAME_DUMP */
291 static int ieee80211_is_eapol(struct sk_buff
*skb
)
293 struct ieee80211_hdr
*hdr
;
297 if (unlikely(skb
->len
< 10))
300 hdr
= (struct ieee80211_hdr
*) skb
->data
;
301 fc
= le16_to_cpu(hdr
->frame_control
);
303 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
306 hdrlen
= ieee80211_get_hdrlen(fc
);
308 if (unlikely(skb
->len
>= hdrlen
+ sizeof(eapol_header
) &&
309 memcmp(skb
->data
+ hdrlen
, eapol_header
,
310 sizeof(eapol_header
)) == 0))
317 static ieee80211_txrx_result
318 ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data
*tx
)
320 struct rate_control_extra extra
;
322 memset(&extra
, 0, sizeof(extra
));
323 extra
.mgmt_data
= tx
->sdata
&&
324 tx
->sdata
->type
== IEEE80211_SUB_IF_TYPE_MGMT
;
325 extra
.ethertype
= tx
->ethertype
;
327 extra
.endidx
= tx
->local
->num_curr_rates
;
330 tx
->u
.tx
.rate
= rate_control_get_rate(tx
->dev
, tx
->skb
, &extra
);
331 if (unlikely(extra
.probe
!= NULL
)) {
332 tx
->u
.tx
.control
->rate_ctrl_probe
= 1;
333 tx
->u
.tx
.probe_last_frag
= 1;
334 // tx->u.tx.control->alt_retry_rate = tx->u.tx.rate->val;
335 tx
->u
.tx
.rate
= extra
.probe
;
337 // tx->u.tx.control->alt_retry_rate = -1;
341 if (tx
->local
->conf
.phymode
== MODE_IEEE80211G
&&
342 tx
->local
->cts_protect_erp_frames
&& tx
->fragmented
&&
344 tx
->u
.tx
.last_frag_rate
= tx
->u
.tx
.rate
;
345 tx
->u
.tx
.last_frag_rateidx
= extra
.rateidx
;
346 tx
->u
.tx
.probe_last_frag
= extra
.probe
? 1 : 0;
348 tx
->u
.tx
.rate
= extra
.nonerp
;
349 // tx->u.tx.control->rateidx = extra.nonerp_idx;
350 tx
->u
.tx
.control
->rate_ctrl_probe
= 0;
352 tx
->u
.tx
.last_frag_rate
= tx
->u
.tx
.rate
;
353 tx
->u
.tx
.last_frag_rateidx
= extra
.rateidx
;
354 // tx->u.tx.control->rateidx = extra.rateidx;
356 tx
->u
.tx
.control
->tx_rate
= tx
->u
.tx
.rate
->val
;
357 if ((tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_PREAMBLE2
) &&
358 tx
->local
->short_preamble
&&
359 (!tx
->sta
|| (tx
->sta
->flags
& WLAN_STA_SHORT_PREAMBLE
))) {
360 tx
->u
.tx
.short_preamble
= 1;
361 tx
->u
.tx
.control
->tx_rate
= tx
->u
.tx
.rate
->val2
;
364 return TXRX_CONTINUE
;
368 static ieee80211_txrx_result
369 ieee80211_tx_h_select_key(struct ieee80211_txrx_data
*tx
)
372 tx
->u
.tx
.control
->key_idx
= tx
->sta
->key_idx_compression
;
374 tx
->u
.tx
.control
->key_idx
= HW_KEY_IDX_INVALID
;
376 if (unlikely(tx
->u
.tx
.control
->do_not_encrypt
))
378 else if (tx
->sta
&& tx
->sta
->key
)
379 tx
->key
= tx
->sta
->key
;
380 else if (tx
->sdata
->default_key
)
381 tx
->key
= tx
->sdata
->default_key
;
382 else if (tx
->sdata
->drop_unencrypted
&& !(tx
->sdata
->eapol
&& ieee80211_is_eapol(tx
->skb
))) {
383 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_unencrypted
);
389 tx
->key
->tx_rx_count
++;
390 if (unlikely(tx
->local
->key_tx_rx_threshold
&&
391 tx
->key
->tx_rx_count
>
392 tx
->local
->key_tx_rx_threshold
)) {
393 ieee80211_key_threshold_notify(tx
->dev
, tx
->key
,
398 return TXRX_CONTINUE
;
402 static ieee80211_txrx_result
403 ieee80211_tx_h_fragment(struct ieee80211_txrx_data
*tx
)
405 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
406 size_t hdrlen
, per_fragm
, num_fragm
, payload_len
, left
;
407 struct sk_buff
**frags
, *first
, *frag
;
410 int frag_threshold
= tx
->local
->fragmentation_threshold
;
413 return TXRX_CONTINUE
;
418 hdrlen
= ieee80211_get_hdrlen(tx
->fc
);
419 payload_len
= first
->len
- hdrlen
;
420 per_fragm
= frag_threshold
- hdrlen
- 4 /* FCS */;
421 num_fragm
= (payload_len
+ per_fragm
- 1) / per_fragm
;
423 frags
= (struct sk_buff
**)
424 kmalloc(num_fragm
* sizeof(struct sk_buff
*), GFP_ATOMIC
);
427 memset(frags
, 0, num_fragm
* sizeof(struct sk_buff
*));
429 hdr
->frame_control
|= cpu_to_le16(WLAN_FC_MOREFRAG
);
430 pos
= first
->data
+ hdrlen
+ per_fragm
;
431 left
= payload_len
- per_fragm
;
432 for (i
= 0; i
< num_fragm
- 1; i
++) {
433 struct ieee80211_hdr
*fhdr
;
439 /* reserve enough extra head and tail room for possible
441 #define IEEE80211_ENCRYPT_HEADROOM 8
442 #define IEEE80211_ENCRYPT_TAILROOM 12
444 dev_alloc_skb(frag_threshold
+
445 IEEE80211_ENCRYPT_HEADROOM
+
446 IEEE80211_ENCRYPT_TAILROOM
);
449 /* Make sure that all fragments use the same priority so
450 * that they end up using the same TX queue */
451 frag
->priority
= first
->priority
;
452 skb_reserve(frag
, IEEE80211_ENCRYPT_HEADROOM
);
453 fhdr
= (struct ieee80211_hdr
*) skb_put(frag
, hdrlen
);
454 memcpy(fhdr
, first
->data
, hdrlen
);
455 if (i
== num_fragm
- 2)
456 fhdr
->frame_control
&= cpu_to_le16(~WLAN_FC_MOREFRAG
);
457 fhdr
->seq_ctrl
= cpu_to_le16(i
+ 1);
458 copylen
= left
> per_fragm
? per_fragm
: left
;
459 memcpy(skb_put(frag
, copylen
), pos
, copylen
);
464 skb_trim(first
, hdrlen
+ per_fragm
);
466 tx
->u
.tx
.num_extra_frag
= num_fragm
- 1;
467 tx
->u
.tx
.extra_frag
= frags
;
469 return TXRX_CONTINUE
;
472 printk(KERN_DEBUG
"%s: failed to fragment frame\n", tx
->dev
->name
);
474 for (i
= 0; i
< num_fragm
- 1; i
++)
476 dev_kfree_skb(frags
[i
]);
479 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_fragment
);
484 static int wep_encrypt_skb(struct ieee80211_txrx_data
*tx
, struct sk_buff
*skb
)
486 if (tx
->key
->force_sw_encrypt
|| tx
->local
->conf
.sw_encrypt
) {
487 if (ieee80211_wep_encrypt(tx
->local
, skb
, tx
->key
))
490 tx
->u
.tx
.control
->key_idx
= tx
->key
->hw_key_idx
;
491 if (tx
->local
->hw
->wep_include_iv
) {
492 if (ieee80211_wep_add_iv(tx
->local
, skb
, tx
->key
) ==
501 void ieee80211_tx_set_iswep(struct ieee80211_txrx_data
*tx
)
503 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
505 hdr
->frame_control
|= cpu_to_le16(WLAN_FC_ISWEP
);
506 if (tx
->u
.tx
.extra_frag
) {
507 struct ieee80211_hdr
*fhdr
;
509 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
510 fhdr
= (struct ieee80211_hdr
*)
511 tx
->u
.tx
.extra_frag
[i
]->data
;
512 fhdr
->frame_control
|= cpu_to_le16(WLAN_FC_ISWEP
);
518 static ieee80211_txrx_result
519 ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data
*tx
)
521 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
524 fc
= le16_to_cpu(hdr
->frame_control
);
526 if (!tx
->key
|| tx
->key
->alg
!= ALG_WEP
||
527 (WLAN_FC_GET_TYPE(fc
) != WLAN_FC_TYPE_DATA
&&
528 (WLAN_FC_GET_TYPE(fc
) != WLAN_FC_TYPE_MGMT
||
529 WLAN_FC_GET_STYPE(fc
) != WLAN_FC_STYPE_AUTH
)))
530 return TXRX_CONTINUE
;
532 tx
->u
.tx
.control
->iv_len
= WEP_IV_LEN
;
533 tx
->u
.tx
.control
->icv_len
= WEP_ICV_LEN
;
534 ieee80211_tx_set_iswep(tx
);
536 if (wep_encrypt_skb(tx
, tx
->skb
) < 0) {
537 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_wep
);
541 if (tx
->u
.tx
.extra_frag
) {
543 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
544 if (wep_encrypt_skb(tx
, tx
->u
.tx
.extra_frag
[i
]) < 0) {
545 I802_DEBUG_INC(tx
->local
->
546 tx_handlers_drop_wep
);
552 return TXRX_CONTINUE
;
556 static inline int ceiling_div(int dividend
, int divisor
)
558 return ((dividend
+ divisor
- 1) / divisor
);
562 static int ieee80211_frame_duration(struct ieee80211_local
*local
, size_t len
,
563 int rate
, int erp
, int short_preamble
)
567 /* calculate duration (in microseconds, rounded up to next higher
568 * integer if it includes a fractional microsecond) to send frame of
569 * len bytes (does not include FCS) at the given rate. Duration will
572 * rate is in 100 kbps, so divident is multiplied by 10 in the
573 * ceiling_div() operations.
576 if (local
->conf
.phymode
== MODE_IEEE80211A
|| erp
||
577 local
->conf
.phymode
== MODE_ATHEROS_TURBO
) {
581 * N_DBPS = DATARATE x 4
582 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
583 * (16 = SIGNAL time, 6 = tail bits)
584 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
587 * 802.11a - 17.5.2: aSIFSTime = 16 usec
588 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
589 * signal ext = 6 usec
591 /* FIX: Atheros Turbo may have different (shorter) duration? */
592 dur
= 16; /* SIFS + signal ext */
593 dur
+= 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
594 dur
+= 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
595 dur
+= 4 * ceiling_div((16 + 8 * (len
+ 4) + 6) * 10,
596 4 * rate
); /* T_SYM x N_SYM */
599 * 802.11b or 802.11g with 802.11b compatibility:
600 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
601 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
603 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
604 * aSIFSTime = 10 usec
605 * aPreambleLength = 144 usec or 72 usec with short preamble
606 * aPLCPHeaderLength = 48 ms or 24 ms with short preamble
608 dur
= 10; /* aSIFSTime = 10 usec */
609 dur
+= short_preamble
? (72 + 24) : (144 + 48);
611 dur
+= ceiling_div(8 * (len
+ 4) * 10, rate
);
618 static u16
ieee80211_duration(struct ieee80211_txrx_data
*tx
, int group_addr
,
621 int rate
, mrate
, erp
, dur
, i
;
622 struct ieee80211_rate
*txrate
= tx
->u
.tx
.rate
;
623 struct ieee80211_local
*local
= tx
->local
;
625 erp
= txrate
->flags
& IEEE80211_RATE_ERP
;
628 * data and mgmt (except PS Poll):
629 * - during CFP: 32768
630 * - during contention period:
631 * if addr1 is group address: 0
632 * if more fragments = 0 and addr1 is individual address: time to
633 * transmit one ACK plus SIFS
634 * if more fragments = 1 and addr1 is individual address: time to
635 * transmit next fragment plus 2 x ACK plus 3 x SIFS
638 * - control response frame (CTS or ACK) shall be transmitted using the
639 * same rate as the immediately previous frame in the frame exchange
640 * sequence, if this rate belongs to the PHY mandatory rates, or else
641 * at the highest possible rate belonging to the PHY rates in the
645 if (WLAN_FC_GET_TYPE(tx
->fc
) == WLAN_FC_TYPE_CTRL
) {
646 /* TODO: These control frames are not currently sent by
647 * 80211.o, but should they be implemented, this function
648 * needs to be updated to support duration field calculation.
650 * RTS: time needed to transmit pending data/mgmt frame plus
651 * one CTS frame plus one ACK frame plus 3 x SIFS
652 * CTS: duration of immediately previous RTS minus time
653 * required to transmit CTS and its SIFS
654 * ACK: 0 if immediately previous directed data/mgmt had
655 * more=0, with more=1 duration in ACK frame is duration
656 * from previous frame minus time needed to transmit ACK
658 * PS Poll: BIT(15) | BIT(14) | aid
664 if (0 /* FIX: data/mgmt during CFP */)
667 if (group_addr
) /* Group address as the destination - no ACK */
670 /* Individual destination address:
671 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
672 * CTS and ACK frames shall be transmitted using the highest rate in
673 * basic rate set that is less than or equal to the rate of the
674 * immediately previous frame and that is using the same modulation
675 * (CCK or OFDM). If no basic rate set matches with these requirements,
676 * the highest mandatory rate of the PHY that is less than or equal to
677 * the rate of the previous frame is used.
678 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
681 mrate
= 10; /* use 1 Mbps if everything fails */
682 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
683 struct ieee80211_rate
*r
= &local
->curr_rates
[i
];
684 if (r
->rate
> txrate
->rate
)
687 if (IEEE80211_RATE_MODULATION(txrate
->flags
) !=
688 IEEE80211_RATE_MODULATION(r
->flags
))
691 if (r
->flags
& IEEE80211_RATE_BASIC
)
693 else if (r
->flags
& IEEE80211_RATE_MANDATORY
)
697 /* No matching basic rate found; use highest suitable mandatory
702 /* Time needed to transmit ACK
703 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
704 * to closest integer */
706 dur
= ieee80211_frame_duration(local
, 10, rate
, erp
,
707 local
->short_preamble
);
710 /* Frame is fragmented: duration increases with time needed to
711 * transmit next fragment plus ACK and 2 x SIFS. */
712 dur
*= 2; /* ACK + SIFS */
714 dur
+= ieee80211_frame_duration(local
, next_frag_len
,
716 local
->short_preamble
);
723 static ieee80211_txrx_result
724 ieee80211_tx_h_misc(struct ieee80211_txrx_data
*tx
)
726 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
728 struct ieee80211_tx_control
*control
= tx
->u
.tx
.control
;
730 if (!MULTICAST_ADDR(hdr
->addr1
)) {
731 if (tx
->skb
->len
>= tx
->local
->rts_threshold
&&
732 tx
->local
->rts_threshold
< IEEE80211_MAX_RTS_THRESHOLD
) {
733 control
->use_rts_cts
= 1;
734 control
->retry_limit
=
735 tx
->local
->long_retry_limit
;
737 control
->retry_limit
=
738 tx
->local
->short_retry_limit
;
741 control
->retry_limit
= 1;
744 if (tx
->fragmented
) {
745 /* Do not use multiple retry rates when sending fragmented
747 * TODO: The last fragment could still use multiple retry
749 // control->alt_retry_rate = -1;
752 /* Use CTS protection for unicast frames sent using extended rates if
753 * there are associated non-ERP stations and RTS/CTS is not configured
755 if (tx
->local
->conf
.phymode
== MODE_IEEE80211G
&&
756 (tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_ERP
) &&
758 tx
->local
->cts_protect_erp_frames
&&
759 !control
->use_rts_cts
)
760 control
->use_cts_protect
= 1;
763 /* Setup duration field for the first fragment of the frame. Duration
764 * for remaining fragments will be updated when they are being sent
765 * to low-level driver in ieee80211_tx(). */
766 dur
= ieee80211_duration(tx
, MULTICAST_ADDR(hdr
->addr1
),
767 tx
->fragmented
? tx
->u
.tx
.extra_frag
[0]->len
:
769 hdr
->duration_id
= cpu_to_le16(dur
);
771 if (control
->use_rts_cts
|| control
->use_cts_protect
) {
772 struct ieee80211_rate
*rate
;
773 int erp
= tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_ERP
;
775 /* Do not use multiple retry rates when using RTS/CTS */
776 // control->alt_retry_rate = -1;
778 /* Use min(data rate, max base rate) as CTS/RTS rate */
779 rate
= tx
->u
.tx
.rate
;
780 while (rate
> tx
->local
->curr_rates
&&
781 !(rate
->flags
& IEEE80211_RATE_BASIC
))
785 if (control
->use_rts_cts
)
786 dur
+= ieee80211_frame_duration(tx
->local
, 10,
790 dur
+= ieee80211_frame_duration(tx
->local
, tx
->skb
->len
,
791 tx
->u
.tx
.rate
->rate
, erp
,
792 tx
->u
.tx
.short_preamble
);
793 control
->rts_cts_duration
= dur
;
794 control
->rts_cts_rate
= rate
->val
;
798 tx
->sta
->tx_packets
++;
799 tx
->sta
->tx_fragments
++;
800 tx
->sta
->tx_bytes
+= tx
->skb
->len
;
801 if (tx
->u
.tx
.extra_frag
) {
803 tx
->sta
->tx_fragments
+= tx
->u
.tx
.num_extra_frag
;
804 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
806 tx
->u
.tx
.extra_frag
[i
]->len
;
810 tx
->local
->scan
.txrx_count
++;
812 return TXRX_CONTINUE
;
816 static void ieee80211_rate_limit(unsigned long data
)
818 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
820 if (local
->rate_limit
) {
821 local
->rate_limit_bucket
+= local
->rate_limit
;
822 if (local
->rate_limit_bucket
> local
->rate_limit_burst
)
823 local
->rate_limit_bucket
= local
->rate_limit_burst
;
824 local
->rate_limit_timer
.expires
= jiffies
+ HZ
;
825 add_timer(&local
->rate_limit_timer
);
830 static ieee80211_txrx_result
831 ieee80211_tx_h_rate_limit(struct ieee80211_txrx_data
*tx
)
834 if (likely(!tx
->local
->rate_limit
|| tx
->u
.tx
.unicast
))
835 return TXRX_CONTINUE
;
838 if (tx
->local
->rate_limit_bucket
) {
839 tx
->local
->rate_limit_bucket
--;
840 return TXRX_CONTINUE
;
843 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_rate_limit
);
849 static ieee80211_txrx_result
850 ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data
*tx
)
852 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
853 struct sk_buff
*skb
= tx
->skb
;
854 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
855 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
858 if (unlikely(tx
->local
->sta_scanning
!= 0) &&
859 (WLAN_FC_GET_TYPE(tx
->fc
) != WLAN_FC_TYPE_MGMT
||
860 WLAN_FC_GET_STYPE(tx
->fc
) != WLAN_FC_STYPE_PROBE_REQ
))
863 if (tx
->u
.tx
.ps_buffered
)
864 return TXRX_CONTINUE
;
866 sta_flags
= tx
->sta
? tx
->sta
->flags
: 0;
868 if (likely(tx
->u
.tx
.unicast
)) {
869 if (unlikely(!(sta_flags
& WLAN_STA_ASSOC
) &&
870 tx
->local
->conf
.mode
!= IW_MODE_ADHOC
&&
871 WLAN_FC_GET_TYPE(tx
->fc
) == WLAN_FC_TYPE_DATA
)) {
872 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
873 printk(KERN_DEBUG
"%s: dropped data frame to not "
874 "associated station " MACSTR
"\n",
875 tx
->dev
->name
, MAC2STR(hdr
->addr1
));
876 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
877 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_not_assoc
);
881 if (unlikely(WLAN_FC_GET_TYPE(tx
->fc
) == WLAN_FC_TYPE_DATA
&&
882 tx
->local
->num_sta
== 0 &&
883 !tx
->local
->allow_broadcast_always
&&
884 tx
->local
->conf
.mode
!= IW_MODE_ADHOC
)) {
886 * No associated STAs - no need to send multicast
891 return TXRX_CONTINUE
;
894 if (unlikely(!tx
->u
.tx
.mgmt_interface
&& tx
->sdata
->ieee802_1x
&&
895 !(sta_flags
& WLAN_STA_AUTHORIZED
))) {
896 #ifdef CONFIG_IEEE80211_DEBUG
897 struct ieee80211_hdr
*hdr
=
898 (struct ieee80211_hdr
*) tx
->skb
->data
;
899 printk(KERN_DEBUG
"%s: dropped frame to " MACSTR
900 " (unauthorized port)\n", tx
->dev
->name
,
901 MAC2STR(hdr
->addr1
));
903 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_unauth_port
);
907 return TXRX_CONTINUE
;
911 /* This function is called whenever the AP is about to exceed the maximum limit
912 * of buffered frames for power saving STAs. This situation should not really
913 * happen often during normal operation, so dropping the oldest buffered packet
914 * from each queue should be OK to make some room for new frames. */
915 static void purge_old_ps_buffers(struct ieee80211_local
*local
)
917 int total
= 0, purged
= 0;
919 struct list_head
*ptr
;
921 spin_lock_bh(&local
->sub_if_lock
);
922 list_for_each(ptr
, &local
->sub_if_list
) {
923 struct ieee80211_if_norm
*norm
;
924 struct ieee80211_sub_if_data
*sdata
=
925 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
926 if (sdata
->dev
== local
->mdev
||
927 sdata
->type
!= IEEE80211_SUB_IF_TYPE_NORM
)
929 norm
= &sdata
->u
.norm
;
930 skb
= skb_dequeue(&norm
->ps_bc_buf
);
935 total
+= skb_queue_len(&norm
->ps_bc_buf
);
937 spin_unlock_bh(&local
->sub_if_lock
);
939 spin_lock_bh(&local
->sta_lock
);
940 list_for_each(ptr
, &local
->sta_list
) {
941 struct sta_info
*sta
=
942 list_entry(ptr
, struct sta_info
, list
);
943 skb
= skb_dequeue(&sta
->ps_tx_buf
);
948 total
+= skb_queue_len(&sta
->ps_tx_buf
);
950 spin_unlock_bh(&local
->sta_lock
);
952 local
->total_ps_buffered
= total
;
953 printk(KERN_DEBUG
"%s: PS buffers full - purged %d frames\n",
954 local
->mdev
->name
, purged
);
958 static inline ieee80211_txrx_result
959 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data
*tx
)
961 /* broadcast/multicast frame */
962 /* If any of the associated stations is in power save mode,
963 * the frame is buffered to be sent after DTIM beacon frame */
964 if (tx
->local
->hw
->host_broadcast_ps_buffering
&&
965 tx
->sdata
->type
!= IEEE80211_SUB_IF_TYPE_WDS
&&
966 tx
->sdata
->bss
&& atomic_read(&tx
->sdata
->bss
->num_sta_ps
) &&
967 !(tx
->fc
& WLAN_FC_ORDER
)) {
968 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
969 purge_old_ps_buffers(tx
->local
);
970 if (skb_queue_len(&tx
->sdata
->bss
->ps_bc_buf
) >=
972 if (net_ratelimit()) {
973 printk(KERN_DEBUG
"%s: BC TX buffer full - "
974 "dropping the oldest frame\n",
977 dev_kfree_skb(skb_dequeue(&tx
->sdata
->bss
->ps_bc_buf
));
979 tx
->local
->total_ps_buffered
++;
980 skb_queue_tail(&tx
->sdata
->bss
->ps_bc_buf
, tx
->skb
);
984 return TXRX_CONTINUE
;
988 static inline ieee80211_txrx_result
989 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data
*tx
)
991 struct sta_info
*sta
= tx
->sta
;
994 (WLAN_FC_GET_TYPE(tx
->fc
) == WLAN_FC_TYPE_MGMT
&&
995 WLAN_FC_GET_STYPE(tx
->fc
) == WLAN_FC_STYPE_PROBE_RESP
)))
996 return TXRX_CONTINUE
;
998 if (unlikely((sta
->flags
& WLAN_STA_PS
) && !sta
->pspoll
)) {
999 struct ieee80211_tx_packet_data
*pkt_data
;
1000 #ifdef IEEE80211_VERBOSE_DEBUG_PS
1001 printk(KERN_DEBUG
"STA " MACSTR
" aid %d: PS buffer (entries "
1003 MAC2STR(sta
->addr
), sta
->aid
,
1004 skb_queue_len(&sta
->ps_tx_buf
));
1005 #endif /* IEEE80211_VERBOSE_DEBUG_PS */
1006 sta
->flags
|= WLAN_STA_TIM
;
1007 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
1008 purge_old_ps_buffers(tx
->local
);
1009 if (skb_queue_len(&sta
->ps_tx_buf
) >= STA_MAX_TX_BUFFER
) {
1010 struct sk_buff
*old
= skb_dequeue(&sta
->ps_tx_buf
);
1011 if (net_ratelimit()) {
1012 printk(KERN_DEBUG
"%s: STA " MACSTR
" TX "
1013 "buffer full - dropping oldest frame\n",
1014 tx
->dev
->name
, MAC2STR(sta
->addr
));
1018 tx
->local
->total_ps_buffered
++;
1019 /* Queue frame to be sent after STA sends an PS Poll frame */
1020 if (skb_queue_empty(&sta
->ps_tx_buf
) && tx
->local
->hw
->set_tim
)
1021 tx
->local
->hw
->set_tim(tx
->dev
, sta
->aid
, 1);
1022 pkt_data
= (struct ieee80211_tx_packet_data
*)tx
->skb
->cb
;
1023 pkt_data
->jiffies
= jiffies
;
1024 skb_queue_tail(&sta
->ps_tx_buf
, tx
->skb
);
1027 #ifdef IEEE80211_VERBOSE_DEBUG_PS
1028 else if (unlikely(sta
->flags
& WLAN_STA_PS
)) {
1029 printk(KERN_DEBUG
"%s: STA " MACSTR
" in PS mode, but pspoll "
1030 "set -> send frame\n", tx
->dev
->name
,
1031 MAC2STR(sta
->addr
));
1033 #endif /* IEEE80211_VERBOSE_DEBUG_PS */
1036 return TXRX_CONTINUE
;
1040 static ieee80211_txrx_result
1041 ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data
*tx
)
1043 if (unlikely(tx
->u
.tx
.ps_buffered
))
1044 return TXRX_CONTINUE
;
1046 if (tx
->u
.tx
.unicast
)
1047 return ieee80211_tx_h_unicast_ps_buf(tx
);
1049 return ieee80211_tx_h_multicast_ps_buf(tx
);
1053 static void inline ieee80211_tx_prepare(struct ieee80211_txrx_data
*tx
,
1054 struct sk_buff
*skb
,
1055 struct net_device
*dev
,
1056 struct ieee80211_tx_control
*control
)
1058 struct ieee80211_local
*local
= dev
->priv
;
1059 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1060 struct ieee80211_tx_packet_data
*pkt_data
;
1063 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1065 memset(tx
, 0, sizeof(*tx
));
1067 tx
->dev
= pkt_data
->sdata
->dev
; /* use original interface */
1069 tx
->sdata
= pkt_data
->sdata
;
1070 tx
->sta
= sta_info_get(local
, hdr
->addr1
);
1071 tx
->fc
= le16_to_cpu(hdr
->frame_control
);
1072 control
->power_level
= local
->conf
.power_level
;
1073 tx
->u
.tx
.control
= control
;
1074 tx
->u
.tx
.unicast
= !MULTICAST_ADDR(hdr
->addr1
);
1075 control
->no_ack
= MULTICAST_ADDR(hdr
->addr1
);
1076 tx
->fragmented
= local
->fragmentation_threshold
<
1077 IEEE80211_MAX_FRAG_THRESHOLD
&& tx
->u
.tx
.unicast
&&
1078 skb
->len
+ 4 /* FCS */ > local
->fragmentation_threshold
&&
1079 (local
->hw
->set_frag_threshold
== NULL
);
1080 if (tx
->sta
== NULL
)
1081 control
->clear_dst_mask
= 1;
1082 else if (tx
->sta
->clear_dst_mask
) {
1083 control
->clear_dst_mask
= 1;
1084 tx
->sta
->clear_dst_mask
= 0;
1086 control
->antenna_sel
= local
->conf
.antenna_sel
;
1087 if (local
->sta_antenna_sel
!= STA_ANTENNA_SEL_AUTO
&& tx
->sta
)
1088 control
->antenna_sel
= tx
->sta
->antenna_sel
;
1089 hdrlen
= ieee80211_get_hdrlen(tx
->fc
);
1090 if (skb
->len
> hdrlen
+ sizeof(rfc1042_header
) + 2) {
1091 u8
*pos
= &skb
->data
[hdrlen
+ sizeof(rfc1042_header
)];
1092 tx
->ethertype
= (pos
[0] << 8) | pos
[1];
1098 static int ieee80211_tx(struct net_device
*dev
, struct sk_buff
*skb
,
1099 struct ieee80211_tx_control
*control
, int mgmt
)
1101 struct ieee80211_local
*local
= dev
->priv
;
1102 struct sta_info
*sta
;
1103 ieee80211_tx_handler
*handler
;
1104 struct ieee80211_txrx_data tx
;
1105 ieee80211_txrx_result res
= TXRX_DROP
;
1108 if (unlikely(skb
->len
< 10)) {
1113 ieee80211_tx_prepare(&tx
, skb
, dev
, control
);
1115 tx
.u
.tx
.mgmt_interface
= mgmt
;
1117 for (handler
= local
->tx_handlers
; *handler
!= NULL
; handler
++) {
1118 res
= (*handler
)(&tx
);
1119 if (res
!= TXRX_CONTINUE
)
1123 skb
= tx
.skb
; /* handlers are allowed to change skb */
1126 sta_info_release(local
, sta
);
1128 if (unlikely(res
== TXRX_DROP
)) {
1129 I802_DEBUG_INC(local
->tx_handlers_drop
);
1133 if (unlikely(res
== TXRX_QUEUED
)) {
1134 I802_DEBUG_INC(local
->tx_handlers_queued
);
1138 ieee80211_dump_frame(dev
->name
, "TX to low-level driver", skb
);
1139 ret
= local
->hw
->tx(dev
, skb
, control
);
1140 #ifdef IEEE80211_LEDS
1141 if (!ret
&& local
->tx_led_counter
++ == 0) {
1142 ieee80211_tx_led(1, dev
);
1144 #endif /* IEEE80211_LEDS */
1145 if (tx
.u
.tx
.extra_frag
) {
1147 /* Must free all fragments and return 0 since skb data
1148 * has been fragmented into multiple buffers.
1149 * TODO: could free extra fragments and restore skb to
1150 * the original form since the data is still there and
1151 * then return nonzero so that Linux netif would
1156 skb
= NULL
; /* skb is now owned by low-level driver */
1157 control
->use_rts_cts
= 0;
1158 control
->use_cts_protect
= 0;
1159 control
->clear_dst_mask
= 0;
1160 for (i
= 0; i
< tx
.u
.tx
.num_extra_frag
; i
++) {
1162 struct ieee80211_hdr
*hdr
=
1163 (struct ieee80211_hdr
*)
1164 tx
.u
.tx
.extra_frag
[i
]->data
;
1165 if (i
+ 1 < tx
.u
.tx
.num_extra_frag
)
1166 next_len
= tx
.u
.tx
.extra_frag
[i
+ 1]->len
;
1169 tx
.u
.tx
.rate
= tx
.u
.tx
.last_frag_rate
;
1170 tx
.u
.tx
.control
->tx_rate
= tx
.u
.tx
.rate
->val
;
1171 // tx.u.tx.control->rateidx =
1172 // tx.u.tx.last_frag_rateidx;
1173 tx
.u
.tx
.control
->rate_ctrl_probe
=
1174 tx
.u
.tx
.probe_last_frag
;
1176 dur
= ieee80211_duration(&tx
, 0, next_len
);
1177 hdr
->duration_id
= cpu_to_le16(dur
);
1179 ieee80211_dump_frame(dev
->name
,
1180 "TX to low-level driver", skb
);
1181 ret
= local
->hw
->tx(dev
, tx
.u
.tx
.extra_frag
[i
],
1185 #ifdef IEEE80211_LEDS
1186 if (local
->tx_led_counter
++ == 0) {
1187 ieee80211_tx_led(1, dev
);
1189 #endif /* IEEE80211_LEDS */
1190 tx
.u
.tx
.extra_frag
[i
] = NULL
;
1192 kfree(tx
.u
.tx
.extra_frag
);
1201 for (i
= 0; i
< tx
.u
.tx
.num_extra_frag
; i
++)
1202 if (tx
.u
.tx
.extra_frag
[i
])
1203 dev_kfree_skb(tx
.u
.tx
.extra_frag
[i
]);
1204 kfree(tx
.u
.tx
.extra_frag
);
1209 static int ieee80211_master_start_xmit(struct sk_buff
*skb
,
1210 struct net_device
*dev
)
1212 struct ieee80211_tx_control control
;
1213 struct ieee80211_tx_packet_data
*pkt_data
;
1214 struct ieee80211_sub_if_data
*sdata
;
1217 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1220 * copy control out of the skb so other people can use skb->cb
1222 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1223 if (unlikely(pkt_data
->magic
!= IEEE80211_CB_MAGIC
)) {
1224 printk(KERN_WARNING
"%s: Someone messed with our skb->cb\n",
1229 memcpy(&control
, &pkt_data
->control
,
1230 sizeof(struct ieee80211_tx_control
));
1232 ret
= ieee80211_tx(dev
, skb
, &control
,
1233 pkt_data
->sdata
->type
==
1234 IEEE80211_SUB_IF_TYPE_MGMT
);
1241 * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
1242 * subinterfaces (wlan#, WDS, and VLAN interfaces)
1243 * @skb: packet to be sent
1244 * @dev: incoming interface
1246 * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
1247 * not be freed, and caller is responsible for either retrying later or freeing
1250 * This function takes in an Ethernet header and encapsulates it with suitable
1251 * IEEE 802.11 header based on which interface the packet is coming in. The
1252 * encapsulated packet will then be passed to master interface, wlan#.11, for
1253 * transmission (through low-level driver).
1255 static int ieee80211_subif_start_xmit(struct sk_buff
*skb
,
1256 struct net_device
*dev
)
1258 struct ieee80211_local
*local
= (struct ieee80211_local
*) dev
->priv
;
1259 struct ieee80211_tx_packet_data
*pkt_data
;
1260 struct ieee80211_sub_if_data
*sdata
;
1261 int ret
= 1, head_need
;
1262 u16 ethertype
, hdrlen
, fc
;
1263 struct ieee80211_hdr hdr
;
1265 int encaps_len
, skip_header_bytes
;
1266 int nh_pos
, h_pos
, no_encrypt
= 0;
1267 struct sta_info
*sta
;
1269 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1270 if (unlikely(skb
->len
< ETH_HLEN
)) {
1271 printk(KERN_DEBUG
"%s: short skb (len=%d)\n",
1272 dev
->name
, skb
->len
);
1277 nh_pos
= skb
->nh
.raw
- skb
->data
;
1278 h_pos
= skb
->h
.raw
- skb
->data
;
1280 /* convert Ethernet header to proper 802.11 header (based on
1281 * operation mode) */
1282 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
1283 /* TODO: handling for 802.1x authorized/unauthorized port */
1284 fc
= (WLAN_FC_TYPE_DATA
<< 2) | (WLAN_FC_STYPE_DATA
<< 4);
1286 if (likely(sdata
->type
== IEEE80211_SUB_IF_TYPE_NORM
||
1287 sdata
->type
== IEEE80211_SUB_IF_TYPE_VLAN
)) {
1288 if (local
->conf
.mode
== IW_MODE_MASTER
) {
1289 fc
|= WLAN_FC_FROMDS
;
1291 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
1292 memcpy(hdr
.addr2
, dev
->dev_addr
, ETH_ALEN
);
1293 memcpy(hdr
.addr3
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1294 } else if (local
->conf
.mode
== IW_MODE_INFRA
) {
1297 memcpy(hdr
.addr1
, local
->bssid
, ETH_ALEN
);
1298 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1299 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
1300 } else if (local
->conf
.mode
== IW_MODE_ADHOC
) {
1302 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
1303 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1304 memcpy(hdr
.addr3
, local
->bssid
, ETH_ALEN
);
1307 } else if (sdata
->type
== IEEE80211_SUB_IF_TYPE_WDS
) {
1308 fc
|= WLAN_FC_FROMDS
| WLAN_FC_TODS
;
1310 memcpy(hdr
.addr1
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
1311 memcpy(hdr
.addr2
, dev
->dev_addr
, ETH_ALEN
);
1312 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
1313 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1315 } else if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
1316 if (local
->conf
.mode
== IW_MODE_INFRA
) {
1319 memcpy(hdr
.addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1320 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1321 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
1324 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
1325 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1326 memcpy(hdr
.addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1334 /* receiver is QoS enabled, use a QoS type frame */
1335 sta
= sta_info_get(local
, hdr
.addr1
);
1337 if (sta
->flags
& WLAN_STA_WME
) {
1338 fc
|= WLAN_FC_STYPE_QOS_DATA
<< 4;
1341 sta_info_release(local
, sta
);
1344 hdr
.frame_control
= cpu_to_le16(fc
);
1345 hdr
.duration_id
= 0;
1348 skip_header_bytes
= ETH_HLEN
;
1349 if (ethertype
== ETH_P_AARP
|| ethertype
== ETH_P_IPX
) {
1350 encaps_data
= bridge_tunnel_header
;
1351 encaps_len
= sizeof(bridge_tunnel_header
);
1352 skip_header_bytes
-= 2;
1353 } else if (ethertype
>= 0x600) {
1354 encaps_data
= rfc1042_header
;
1355 encaps_len
= sizeof(rfc1042_header
);
1356 skip_header_bytes
-= 2;
1362 skb_pull(skb
, skip_header_bytes
);
1363 nh_pos
-= skip_header_bytes
;
1364 h_pos
-= skip_header_bytes
;
1366 /* TODO: implement support for fragments so that there is no need to
1367 * reallocate and copy payload; it might be enough to support one
1368 * extra fragment that would be copied in the beginning of the frame
1369 * data.. anyway, it would be nice to include this into skb structure
1372 * There are few options for this:
1373 * use skb->cb as an extra space for 802.11 header
1374 * allocate new buffer if not enough headroom
1375 * make sure that there is enough headroom in every skb by increasing
1376 * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
1377 * alloc_skb() (net/core/skbuff.c)
1379 head_need
= hdrlen
+ encaps_len
+ (local
->hw
->extra_hdr_room
? 2 : 0);
1380 head_need
-= skb_headroom(skb
);
1382 /* We are going to modify skb data, so make a copy of it if happens to
1383 * be cloned. This could happen, e.g., with Linux bridge code passing
1384 * us broadcast frames. */
1386 if (head_need
> 0 || skb_cloned(skb
)) {
1388 printk(KERN_DEBUG
"%s: need to reallocate buffer for %d bytes "
1389 "of headroom\n", dev
->name
, head_need
);
1392 if (skb_cloned(skb
))
1393 I802_DEBUG_INC(local
->tx_expand_skb_head_cloned
);
1395 I802_DEBUG_INC(local
->tx_expand_skb_head
);
1396 /* Since we have to reallocate the buffer, make sure that there
1397 * is enough room for possible WEP IV/ICV and TKIP (8 bytes
1398 * before payload and 12 after). */
1399 if (pskb_expand_head(skb
, (head_need
> 0 ? head_need
+ 8 : 8),
1401 printk(KERN_DEBUG
"%s: failed to reallocate TX buffer"
1408 memcpy(skb_push(skb
, encaps_len
), encaps_data
, encaps_len
);
1409 nh_pos
+= encaps_len
;
1410 h_pos
+= encaps_len
;
1412 memcpy(skb_push(skb
, hdrlen
), &hdr
, hdrlen
);
1416 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1417 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
1418 pkt_data
->magic
= IEEE80211_CB_MAGIC
;
1419 pkt_data
->sdata
= sdata
;
1420 pkt_data
->control
.do_not_encrypt
= no_encrypt
;
1422 skb
->dev
= sdata
->master
;
1423 sdata
->stats
.tx_packets
++;
1424 sdata
->stats
.tx_bytes
+= skb
->len
;
1426 /* Update skb pointers to various headers since this modified frame
1427 * is going to go through Linux networking code that may potentially
1428 * need things like pointer to IP header. */
1429 skb
->mac
.raw
= skb
->data
;
1430 skb
->nh
.raw
= skb
->data
+ nh_pos
;
1431 skb
->h
.raw
= skb
->data
+ h_pos
;
1434 dev_queue_xmit(skb
);
1447 * This is the transmit routine for the 802.11 type interfaces
1448 * called by upper layers of the linux networking
1449 * stack when it has a frame to transmit
1452 ieee80211_mgmt_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1454 struct ieee80211_sub_if_data
*sdata
;
1455 struct ieee80211_tx_packet_data
*pkt_data
;
1456 struct ieee80211_hdr
*hdr
;
1459 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1461 if (skb
->len
< 10) {
1466 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1467 fc
= le16_to_cpu(hdr
->frame_control
);
1469 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1470 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
1471 pkt_data
->magic
= IEEE80211_CB_MAGIC
;
1472 pkt_data
->sdata
= sdata
;
1474 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
1475 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
)
1476 pkt_data
->control
.pkt_type
= PKT_PROBE_RESP
;
1478 skb
->priority
= 20; /* use hardcode priority for mgmt TX queue */
1479 skb
->dev
= sdata
->master
;
1482 * We're using the protocol field of the the frame control header
1483 * to request TX callback for hostapd. BIT(1) is checked.
1485 if ((fc
& BIT(1)) == BIT(1)) {
1486 pkt_data
->control
.req_tx_status
= 1;
1488 hdr
->frame_control
= cpu_to_le16(fc
);
1493 pkt_data
->control
.do_not_encrypt
= !(fc
& WLAN_FC_ISWEP
);
1495 sdata
->stats
.tx_packets
++;
1496 sdata
->stats
.tx_bytes
+= skb
->len
;
1498 dev_queue_xmit(skb
);
1504 static void ieee80211_beacon_add_tim(struct ieee80211_local
*local
,
1505 struct ieee80211_if_norm
*bss
,
1506 struct sk_buff
*skb
)
1510 int i
, num_bits
= 0, n1
, n2
;
1513 /* Generate bitmap for TIM only if there are any STAs in power save
1515 if (atomic_read(&bss
->num_sta_ps
) > 0 && bss
->max_aid
> 0) {
1516 memset(bitmap
, 0, sizeof(bitmap
));
1517 spin_lock_bh(&local
->sta_lock
);
1518 for (i
= 0; i
< bss
->max_aid
; i
++) {
1519 if (bss
->sta_aid
[i
] &&
1520 (!skb_queue_empty(&bss
->sta_aid
[i
]->ps_tx_buf
) ||
1521 !skb_queue_empty(&bss
->sta_aid
[i
]->tx_filtered
)))
1523 bitmap
[(i
+ 1) / 8] |= 1 << (i
+ 1) % 8;
1527 spin_unlock_bh(&local
->sta_lock
);
1530 if (bss
->dtim_count
== 0)
1531 bss
->dtim_count
= bss
->dtim_period
- 1;
1535 tim
= pos
= (u8
*) skb_put(skb
, 6);
1536 *pos
++ = WLAN_EID_TIM
;
1538 *pos
++ = bss
->dtim_count
;
1539 *pos
++ = bss
->dtim_period
;
1541 if (bss
->dtim_count
== 0 && !skb_queue_empty(&bss
->ps_bc_buf
)) {
1546 /* Find largest even number N1 so that bits numbered 1 through
1547 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
1548 * (N2 + 1) x 8 through 2007 are 0. */
1550 for (i
= 0; i
< sizeof(bitmap
); i
++) {
1557 for (i
= sizeof(bitmap
) - 1; i
>= n1
; i
--) {
1564 /* Bitmap control */
1565 *pos
++ = n1
| (aid0
? 1 : 0);
1566 /* Part Virt Bitmap */
1567 memcpy(pos
, bitmap
+ n1
, n2
- n1
+ 1);
1569 tim
[1] = n2
- n1
+ 4;
1570 skb_put(skb
, n2
- n1
);
1572 *pos
++ = aid0
? 1 : 0; /* Bitmap control */
1573 *pos
++ = 0; /* Part Virt Bitmap */
1580 struct sk_buff
* ieee80211_beacon_get(struct net_device
*dev
, int bss_idx
,
1581 struct ieee80211_tx_control
*control
)
1583 struct ieee80211_local
*local
= dev
->priv
;
1584 struct sk_buff
*skb
;
1585 struct net_device
*bdev
;
1586 struct ieee80211_sub_if_data
*sdata
= NULL
;
1587 struct ieee80211_if_norm
*norm
= NULL
;
1588 struct ieee80211_rate
*rate
;
1589 struct rate_control_extra extra
;
1590 u8
*b_head
, *b_tail
;
1594 spin_lock_bh(&local
->sub_if_lock
);
1595 if (bss_idx
< 0 || bss_idx
>= local
->bss_dev_count
)
1598 bdev
= local
->bss_devs
[bss_idx
];
1599 sdata
= IEEE80211_DEV_TO_SUB_IF(bdev
);
1600 norm
= &sdata
->u
.norm
;
1602 spin_unlock_bh(&local
->sub_if_lock
);
1604 if (bdev
== NULL
|| norm
== NULL
|| norm
->beacon_head
== NULL
) {
1605 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
1606 if (net_ratelimit())
1607 printk(KERN_DEBUG
"no beacon data avail for idx=%d "
1608 "(%s)\n", bss_idx
, bdev
? bdev
->name
: "N/A");
1609 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
1613 /* Assume we are generating the normal beacon locally */
1614 b_head
= norm
->beacon_head
;
1615 b_tail
= norm
->beacon_tail
;
1616 bh_len
= norm
->beacon_head_len
;
1617 bt_len
= norm
->beacon_tail_len
;
1620 skb
= dev_alloc_skb(bh_len
+ bt_len
+ 256 /* maximum TIM len */);
1624 memcpy(skb_put(skb
, bh_len
), b_head
, bh_len
);
1626 ieee80211_beacon_add_tim(local
, norm
, skb
);
1629 memcpy(skb_put(skb
, bt_len
), b_tail
, bt_len
);
1632 memset(&extra
, 0, sizeof(extra
));
1633 extra
.endidx
= local
->num_curr_rates
;
1636 rate
= rate_control_get_rate(dev
, skb
, &extra
);
1638 if (net_ratelimit()) {
1639 printk(KERN_DEBUG
"%s: ieee80211_beacon_get: no rate "
1640 "found\n", dev
->name
);
1646 control
->tx_rate
= (local
->short_preamble
&&
1647 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
1648 rate
->val2
: rate
->val
;
1649 control
->antenna_sel
= local
->conf
.antenna_sel
;
1650 control
->power_level
= local
->conf
.power_level
;
1651 control
->no_ack
= 1;
1652 control
->retry_limit
= 1;
1653 control
->rts_cts_duration
= 0;
1654 control
->clear_dst_mask
= 1;
1657 norm
->num_beacons
++;
1662 ieee80211_get_buffered_bc(struct net_device
*dev
, int bss_idx
,
1663 struct ieee80211_tx_control
*control
)
1665 struct ieee80211_local
*local
= dev
->priv
;
1666 struct sk_buff
*skb
;
1667 struct sta_info
*sta
;
1668 ieee80211_tx_handler
*handler
;
1669 struct ieee80211_txrx_data tx
;
1670 ieee80211_txrx_result res
= TXRX_DROP
;
1671 struct net_device
*bdev
;
1672 struct ieee80211_sub_if_data
*sdata
;
1673 struct ieee80211_if_norm
*bss
;
1676 spin_lock_bh(&local
->sub_if_lock
);
1677 if (bss_idx
< 0 || bss_idx
>= local
->bss_dev_count
) {
1681 bdev
= local
->bss_devs
[bss_idx
];
1682 sdata
= IEEE80211_DEV_TO_SUB_IF(bdev
);
1683 bss
= &sdata
->u
.norm
;
1685 spin_unlock_bh(&local
->sub_if_lock
);
1686 if (bdev
== NULL
|| bss
== NULL
|| bss
->beacon_head
== NULL
)
1689 if (bss
->dtim_count
!= 0)
1690 return NULL
; /* send buffered bc/mc only after DTIM beacon */
1691 skb
= skb_dequeue(&bss
->ps_bc_buf
);
1692 memset(control
, 0, sizeof(*control
));
1695 local
->total_ps_buffered
--;
1697 if (!skb_queue_empty(&bss
->ps_bc_buf
) && skb
->len
>= 2) {
1698 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1699 /* more buffered multicast/broadcast frames ==> set MoreData
1700 * flag in IEEE 802.11 header to inform PS STAs */
1701 hdr
->frame_control
|= cpu_to_le16(WLAN_FC_MOREDATA
);
1704 ieee80211_tx_prepare(&tx
, skb
, dev
, control
);
1706 tx
.u
.tx
.ps_buffered
= 1;
1708 for (handler
= local
->tx_handlers
; *handler
!= NULL
; handler
++) {
1709 res
= (*handler
)(&tx
);
1710 if (res
== TXRX_DROP
|| res
== TXRX_QUEUED
)
1714 if (res
== TXRX_DROP
) {
1715 I802_DEBUG_INC(local
->tx_handlers_drop
);
1718 } else if (res
== TXRX_QUEUED
) {
1719 I802_DEBUG_INC(local
->tx_handlers_queued
);
1724 sta_info_release(local
, sta
);
1730 int ieee80211_hw_config(struct net_device
*dev
)
1732 struct ieee80211_local
*local
= dev
->priv
;
1735 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
1736 printk(KERN_DEBUG
"HW CONFIG: channel=%d freq=%d mode=%d "
1737 "phymode=%d\n", local
->conf
.channel
, local
->conf
.freq
,
1738 local
->conf
.mode
, local
->conf
.phymode
);
1739 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
1741 if (local
->hw
->config
)
1742 ret
= local
->hw
->config(dev
, &local
->conf
);
1744 for (i
= 0; i
< local
->hw
->num_modes
; i
++) {
1745 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[i
];
1746 if (mode
->mode
== local
->conf
.phymode
) {
1747 if (local
->curr_rates
!= mode
->rates
) {
1748 rate_control_clear(local
);
1750 local
->curr_rates
= mode
->rates
;
1751 local
->num_curr_rates
= mode
->num_rates
;
1752 ieee80211_prepare_rates(dev
);
1761 struct ieee80211_conf
*ieee80211_get_hw_conf(struct net_device
*dev
)
1763 struct ieee80211_local
*local
= dev
->priv
;
1764 return &local
->conf
;
1768 static int ieee80211_change_mtu(struct net_device
*dev
, int new_mtu
)
1770 /* FIX: what would be proper limits for MTU?
1771 * This interface uses 802.3 frames. */
1772 if (new_mtu
< 256 || new_mtu
> 2304 - 24 - 6) {
1773 printk(KERN_WARNING
"%s: invalid MTU %d\n",
1774 dev
->name
, new_mtu
);
1778 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
1779 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
1780 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
1786 static int ieee80211_change_mtu_apdev(struct net_device
*dev
, int new_mtu
)
1788 /* FIX: what would be proper limits for MTU?
1789 * This interface uses 802.11 frames. */
1790 if (new_mtu
< 256 || new_mtu
> 2304) {
1791 printk(KERN_WARNING
"%s: invalid MTU %d\n",
1792 dev
->name
, new_mtu
);
1796 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
1797 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
1798 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
1804 static void ieee80211_tx_timeout(struct net_device
*dev
)
1806 struct ieee80211_local
*local
= dev
->priv
;
1808 printk(KERN_WARNING
"%s: resetting interface.\n", dev
->name
);
1810 if (local
->hw
->reset(dev
))
1811 printk(KERN_ERR
"%s: failed to reset interface.\n", dev
->name
);
1813 netif_wake_queue(dev
);
1817 static int ieee80211_set_mac_address(struct net_device
*dev
, void *addr
)
1819 struct ieee80211_local
*local
= dev
->priv
;
1820 struct sockaddr
*a
= addr
;
1821 struct list_head
*ptr
;
1824 if (!local
->hw
->set_mac_address
)
1827 res
= local
->hw
->set_mac_address(dev
, addr
);
1831 list_for_each(ptr
, &local
->sub_if_list
) {
1832 struct ieee80211_sub_if_data
*sdata
=
1833 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
1834 memcpy(sdata
->dev
->dev_addr
, a
->sa_data
, ETH_ALEN
);
1841 static struct net_device_stats
*ieee80211_get_stats(struct net_device
*dev
)
1843 struct ieee80211_sub_if_data
*sdata
;
1844 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1845 return &(sdata
->stats
);
1849 static int ieee80211_open(struct net_device
*dev
)
1851 struct ieee80211_sub_if_data
*sdata
;
1852 struct ieee80211_local
*local
= dev
->priv
;
1855 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1857 if (local
->open_count
== 0) {
1858 res
= local
->hw
->open(sdata
->master
);
1861 ieee80211_init_scan(sdata
->master
);
1863 local
->open_count
++;
1865 netif_start_queue(dev
);
1870 static int ieee80211_stop(struct net_device
*dev
)
1872 struct ieee80211_sub_if_data
*sdata
;
1873 struct ieee80211_local
*local
= dev
->priv
;
1876 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1878 netif_stop_queue(dev
);
1880 local
->open_count
--;
1881 if (local
->open_count
== 0) {
1882 ieee80211_stop_scan(sdata
->master
);
1883 res
= local
->hw
->stop(sdata
->master
);
1892 static int header_parse_80211(struct sk_buff
*skb
, unsigned char *haddr
)
1894 memcpy(haddr
, skb
->mac
.raw
+ 10, ETH_ALEN
); /* addr2 */
1899 static struct net_device
*
1900 ieee80211_get_wds_dev(struct ieee80211_local
*local
, u8
*addr
)
1902 struct list_head
*ptr
;
1904 list_for_each(ptr
, &local
->sub_if_list
) {
1905 struct ieee80211_sub_if_data
*sdata
=
1906 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
1907 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_WDS
&&
1908 memcmp(addr
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
) == 0)
1916 static struct net_device
* ieee80211_own_bssid(struct ieee80211_local
*local
,
1920 struct net_device
*dev
= NULL
;
1922 spin_lock_bh(&local
->sub_if_lock
);
1923 for (i
= 0; i
< local
->bss_dev_count
; i
++) {
1924 if ((memcmp(local
->bss_devs
[i
]->dev_addr
, addr
, ETH_ALEN
) == 0)
1926 dev
= local
->bss_devs
[i
];
1930 spin_unlock_bh(&local
->sub_if_lock
);
1938 static struct net_device
* ieee80211_sta_bssid(struct ieee80211_local
*local
,
1942 struct list_head
*ptr
;
1944 u8
*own_addr
= local
->mdev
->dev_addr
;
1946 multicast
= a1
[0] & 0x01;
1948 /* Try O(1) lookup for a common case of only one AP being used. */
1949 if (own_addr
[0] == a1
[0] && own_addr
[1] == a1
[1] &&
1950 own_addr
[2] == a1
[2]) {
1951 int index
= (((int) a1
[3] << 16) | ((int) a1
[4] << 8) | a1
[5])
1952 - (((int) own_addr
[3] << 16) |
1953 ((int) own_addr
[4] << 8) | own_addr
[5]);
1954 if (index
>= 0 && index
< local
->conf
.bss_count
&&
1955 local
->sta_devs
[index
]) {
1956 struct net_device
*dev
= local
->sta_devs
[index
];
1957 struct ieee80211_sub_if_data
*sdata
;
1958 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1959 if (memcmp(addr
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
1960 *sta_multicast
= multicast
;
1969 /* Could not find station interface, resort to O(n) lookup. */
1970 list_for_each(ptr
, &local
->sub_if_list
) {
1971 struct ieee80211_sub_if_data
*sdata
=
1972 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
1973 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
1976 memcmp(a1
, sdata
->dev
->dev_addr
, ETH_ALEN
) != 0)
1979 if (memcmp(addr
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 ||
1980 (memcmp(addr
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0 &&
1981 local
->conf
.mode
== IW_MODE_ADHOC
)) {
1982 *sta_multicast
= multicast
;
1991 static int ieee80211_own_addr(struct net_device
*dev
, u8
*addr
)
1993 struct ieee80211_local
*local
= dev
->priv
;
1994 u8
*own
= dev
->dev_addr
;
1997 /* Optimization: assume that BSSID mask does not change for first
1999 if (own
[0] != addr
[0] || own
[1] != addr
[1] || own
[2] != addr
[2])
2002 index
= (((int) addr
[3] << 16) | ((int) addr
[4] << 8) | addr
[5]) -
2003 (((int) own
[3] << 16) | ((int) own
[4] << 8) | own
[5]);
2004 if (index
>= 0 && index
< local
->conf
.bss_count
&&
2005 local
->sta_devs
[index
])
2012 static ieee80211_txrx_result
2013 ieee80211_rx_h_data(struct ieee80211_txrx_data
*rx
)
2015 struct net_device
*dev
= rx
->dev
;
2016 struct ieee80211_local
*local
= rx
->local
;
2017 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
2018 u16 fc
, hdrlen
, ethertype
;
2022 struct sk_buff
*skb
= rx
->skb
, *skb2
;
2023 struct ieee80211_sub_if_data
*sdata
;
2026 if (unlikely(WLAN_FC_GET_TYPE(fc
) != WLAN_FC_TYPE_DATA
))
2027 return TXRX_CONTINUE
;
2029 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
2032 hdrlen
= ieee80211_get_hdrlen(fc
);
2034 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
2036 * IEEE 802.11 address fields:
2037 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
2038 * 0 0 DA SA BSSID n/a
2039 * 0 1 DA BSSID SA n/a
2040 * 1 0 BSSID SA DA n/a
2044 switch (fc
& (WLAN_FC_TODS
| WLAN_FC_FROMDS
)) {
2047 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
2048 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
2050 if (unlikely(local
->conf
.mode
!= IW_MODE_MASTER
||
2051 !ieee80211_own_bssid(local
, hdr
->addr1
))) {
2052 printk(KERN_DEBUG
"%s: dropped ToDS frame (BSSID="
2053 MACSTR
" SA=" MACSTR
" DA=" MACSTR
")\n",
2054 dev
->name
, MAC2STR(hdr
->addr1
),
2055 MAC2STR(hdr
->addr2
), MAC2STR(hdr
->addr3
));
2059 case (WLAN_FC_TODS
| WLAN_FC_FROMDS
):
2061 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
2062 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
2064 dev
= ieee80211_get_wds_dev(local
, hdr
->addr2
);
2065 if (!dev
|| memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) != 0) {
2066 printk(KERN_DEBUG
"%s: dropped FromDS&ToDS frame (RA="
2067 MACSTR
" TA=" MACSTR
" DA=" MACSTR
" SA="
2069 rx
->dev
->name
, MAC2STR(hdr
->addr1
),
2070 MAC2STR(hdr
->addr2
), MAC2STR(hdr
->addr3
),
2071 MAC2STR(hdr
->addr4
));
2075 case WLAN_FC_FROMDS
:
2077 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
2078 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
2080 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2081 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
||
2082 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0 ||
2083 memcmp(hdr
->addr2
, sdata
->u
.sta
.bssid
, ETH_ALEN
) != 0) {
2089 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
2090 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
2092 if (local
->conf
.mode
!= IW_MODE_ADHOC
||
2093 memcmp(hdr
->addr3
, local
->bssid
, ETH_ALEN
) != 0) {
2094 if (net_ratelimit()) {
2095 printk(KERN_DEBUG
"%s: dropped IBSS frame (DA="
2096 MACSTR
" SA=" MACSTR
" BSSID=" MACSTR
2098 dev
->name
, MAC2STR(hdr
->addr1
),
2099 MAC2STR(hdr
->addr2
),
2100 MAC2STR(hdr
->addr3
));
2107 payload
= skb
->data
+ hdrlen
;
2109 if (unlikely(skb
->len
- hdrlen
< 8)) {
2110 if (net_ratelimit()) {
2111 printk(KERN_DEBUG
"%s: RX too short data frame "
2112 "payload\n", dev
->name
);
2117 ethertype
= (payload
[6] << 8) | payload
[7];
2119 if (likely((memcmp(payload
, rfc1042_header
, 6) == 0 &&
2120 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
2121 memcmp(payload
, bridge_tunnel_header
, 6) == 0)) {
2122 /* remove RFC1042 or Bridge-Tunnel encapsulation and
2123 * replace EtherType */
2124 skb_pull(skb
, hdrlen
+ 6);
2125 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
2126 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
2128 struct ethhdr
*ehdr
;
2130 skb_pull(skb
, hdrlen
);
2131 len
= htons(skb
->len
);
2132 ehdr
= (struct ethhdr
*)skb_push(skb
, sizeof(struct ethhdr
));
2133 memcpy(ehdr
->h_dest
, dst
, ETH_ALEN
);
2134 memcpy(ehdr
->h_source
, src
, ETH_ALEN
);
2135 ehdr
->h_proto
= len
;
2138 if (rx
->sta
&& !rx
->sta
->assoc_ap
&&
2139 !(rx
->sta
&& (rx
->sta
->flags
& WLAN_STA_WDS
)))
2140 skb
->dev
= rx
->sta
->dev
;
2145 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2148 * don't count the master since the low level code
2149 * counts it already for us.
2151 if (skb
->dev
!= sdata
->master
) {
2152 sdata
->stats
.rx_packets
++;
2153 sdata
->stats
.rx_bytes
+= skb
->len
;
2156 if (local
->bridge_packets
&& sdata
->type
!= IEEE80211_SUB_IF_TYPE_WDS
2157 && sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
) {
2158 if (MULTICAST_ADDR(skb
->data
)) {
2159 /* send multicast frames both to higher layers in
2160 * local net stack and back to the wireless media */
2161 skb2
= skb_copy(skb
, GFP_ATOMIC
);
2163 printk(KERN_DEBUG
"%s: failed to clone "
2164 "multicast frame\n", dev
->name
);
2166 struct sta_info
*dsta
;
2167 dsta
= sta_info_get(local
, skb
->data
);
2168 if (dsta
&& dsta
->dev
== NULL
) {
2169 printk(KERN_DEBUG
"Station with null dev "
2171 } else if (dsta
&& dsta
->dev
== dev
) {
2172 /* Destination station is associated to this
2173 * AP, so send the frame directly to it and
2174 * do not pass the frame to local net stack.
2180 sta_info_release(local
, dsta
);
2185 /* deliver to local stack */
2186 skb
->protocol
= eth_type_trans(skb
, dev
);
2187 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2192 /* send to wireless media */
2193 skb2
->protocol
= __constant_htons(ETH_P_802_3
);
2194 skb2
->mac
.raw
= skb2
->nh
.raw
= skb2
->data
;
2195 dev_queue_xmit(skb2
);
2202 static struct ieee80211_rate
*
2203 ieee80211_get_rate(struct ieee80211_local
*local
, int phymode
, int hw_rate
)
2207 for (m
= 0; m
< local
->hw
->num_modes
; m
++) {
2208 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[m
];
2209 if (mode
->mode
!= phymode
)
2211 for (r
= 0; r
< mode
->num_rates
; r
++) {
2212 struct ieee80211_rate
*rate
= &mode
->rates
[r
];
2213 if (rate
->val
== hw_rate
||
2214 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
&&
2215 rate
->val2
== hw_rate
))
2225 ieee80211_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
2226 struct ieee80211_rx_status
*status
, u32 msg_type
)
2228 struct ieee80211_local
*local
= dev
->priv
;
2229 struct ieee80211_frame_info
*fi
;
2231 struct ieee80211_sub_if_data
*sdata
;
2236 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2238 if (skb_headroom(skb
) < sizeof(struct ieee80211_frame_info
)) {
2239 I802_DEBUG_INC(local
->rx_expand_skb_head
);
2240 if (pskb_expand_head(skb
, sizeof(struct ieee80211_frame_info
),
2247 hlen
= sizeof(struct ieee80211_frame_info
);
2248 if (msg_type
== ieee80211_msg_monitor
)
2249 hlen
-= sizeof(fi
->msg_type
);
2251 fi
= (struct ieee80211_frame_info
*) skb_push(skb
, hlen
);
2252 memset(fi
, 0, hlen
);
2253 if (msg_type
!= ieee80211_msg_monitor
)
2254 fi
->msg_type
= htonl(msg_type
);
2255 fi
->version
= htonl(IEEE80211_FI_VERSION
);
2256 fi
->length
= htonl(hlen
);
2258 // struct timespec ts;
2259 struct ieee80211_rate
*rate
;
2262 jiffies_to_timespec(status
->hosttime
, &ts
);
2263 fi
->hosttime
= cpu_to_be64(ts
.tv_sec
* 1000000 +
2265 fi
->mactime
= cpu_to_be64(status
->mactime
);
2267 switch (status
->phymode
) {
2268 case MODE_IEEE80211A
:
2269 fi
->phytype
= htonl(ieee80211_phytype_ofdm_dot11_a
);
2271 case MODE_IEEE80211B
:
2272 fi
->phytype
= htonl(ieee80211_phytype_dsss_dot11_b
);
2274 case MODE_IEEE80211G
:
2275 fi
->phytype
= htonl(ieee80211_phytype_pbcc_dot11_g
);
2277 case MODE_ATHEROS_TURBO
:
2279 htonl(ieee80211_phytype_dsss_dot11_turbo
);
2282 fi
->phytype
= 0xAAAAAAAA;
2285 fi
->channel
= htonl(status
->channel
);
2286 rate
= ieee80211_get_rate(local
, status
->phymode
,
2289 fi
->datarate
= htonl(rate
->rate
);
2290 if (rate
->flags
& IEEE80211_RATE_PREAMBLE2
) {
2291 if (status
->rate
== rate
->val
)
2292 fi
->preamble
= htonl(2); /* long */
2293 else if (status
->rate
== rate
->val2
)
2294 fi
->preamble
= htonl(1); /* short */
2296 fi
->preamble
= htonl(0);
2298 fi
->datarate
= htonl(0);
2299 fi
->preamble
= htonl(0);
2302 fi
->antenna
= htonl(status
->antenna
);
2303 fi
->priority
= 0xffffffff; /* no clue */
2304 fi
->ssi_type
= htonl(ieee80211_ssi_raw
);
2305 fi
->ssi_signal
= htonl(status
->ssi
);
2306 fi
->ssi_noise
= 0x00000000;
2309 fi
->ssi_type
= htonl(ieee80211_ssi_none
);
2312 sdata
->stats
.rx_packets
++;
2313 sdata
->stats
.rx_bytes
+= skb
->len
;
2315 skb
->mac
.raw
= skb
->data
;
2316 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2317 skb
->pkt_type
= PACKET_OTHERHOST
;
2318 skb
->protocol
= __constant_htons(ETH_P_802_2
);
2319 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2324 int ieee80211_radar_status(struct net_device
*dev
, int channel
, int radar
,
2327 struct sk_buff
*skb
;
2328 struct ieee80211_radar_info
*msg
;
2330 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
2331 sizeof(struct ieee80211_radar_info
));
2335 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
2337 msg
= (struct ieee80211_radar_info
*)
2338 skb_put(skb
, sizeof(struct ieee80211_radar_info
));
2339 msg
->channel
= channel
;
2341 msg
->radar_type
= radar_type
;
2343 ieee80211_rx_mgmt(dev
, skb
, 0, ieee80211_msg_radar
);
2348 int ieee80211_set_aid_for_sta(struct net_device
*dev
, u8
*peer_address
,
2351 struct sk_buff
*skb
;
2352 struct ieee80211_msg_set_aid_for_sta
*msg
;
2354 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
2355 sizeof(struct ieee80211_msg_set_aid_for_sta
));
2359 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
2361 msg
= (struct ieee80211_msg_set_aid_for_sta
*)
2362 skb_put(skb
, sizeof(struct ieee80211_msg_set_aid_for_sta
));
2363 memcpy(msg
->sta_address
, peer_address
, ETH_ALEN
);
2366 ieee80211_rx_mgmt(dev
, skb
, 0, ieee80211_msg_set_aid_for_sta
);
2371 static void ap_sta_ps_start(struct net_device
*dev
, struct sta_info
*sta
)
2373 struct ieee80211_sub_if_data
*sdata
;
2374 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
2377 atomic_inc(&sdata
->bss
->num_sta_ps
);
2378 sta
->flags
|= WLAN_STA_PS
;
2380 #ifdef IEEE80211_VERBOSE_DEBUG_PS
2381 printk(KERN_DEBUG
"%s: STA " MACSTR
" aid %d enters power "
2382 "save mode\n", dev
->name
, MAC2STR(sta
->addr
), sta
->aid
);
2383 #endif /* IEEE80211_VERBOSE_DEBUG_PS */
2387 static int ap_sta_ps_end(struct net_device
*dev
, struct sta_info
*sta
)
2389 struct ieee80211_local
*local
= dev
->priv
;
2390 struct sk_buff
*skb
;
2392 struct ieee80211_sub_if_data
*sdata
;
2393 struct ieee80211_tx_packet_data
*pkt_data
;
2395 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
2397 atomic_dec(&sdata
->bss
->num_sta_ps
);
2398 sta
->flags
&= ~(WLAN_STA_PS
| WLAN_STA_TIM
);
2400 if (!skb_queue_empty(&sta
->ps_tx_buf
) && local
->hw
->set_tim
)
2401 local
->hw
->set_tim(dev
, sta
->aid
, 0);
2402 #ifdef IEEE80211_VERBOSE_DEBUG_PS
2403 printk(KERN_DEBUG
"%s: STA " MACSTR
" aid %d exits power "
2404 "save mode\n", dev
->name
, MAC2STR(sta
->addr
), sta
->aid
);
2405 #endif /* IEEE80211_VERBOSE_DEBUG_PS */
2406 /* Send all buffered frames to the station */
2407 while ((skb
= skb_dequeue(&sta
->tx_filtered
)) != NULL
) {
2408 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
2410 pkt_data
->control
.requeue
= 1;
2411 dev_queue_xmit(skb
);
2413 while ((skb
= skb_dequeue(&sta
->ps_tx_buf
)) != NULL
) {
2414 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
2415 local
->total_ps_buffered
--;
2417 #ifdef IEEE80211_VERBOSE_DEBUG_PS
2418 printk(KERN_DEBUG
"%s: STA " MACSTR
" aid %d send PS frame "
2419 "since STA not sleeping anymore\n", dev
->name
,
2420 MAC2STR(sta
->addr
), sta
->aid
);
2421 #endif /* IEEE80211_VERBOSE_DEBUG_PS */
2422 pkt_data
->control
.requeue
= 1;
2423 dev_queue_xmit(skb
);
2430 static ieee80211_txrx_result
2431 ieee80211_rx_h_ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data
*rx
)
2433 struct sk_buff
*skb
;
2434 int no_pending_pkts
;
2436 if (likely(!rx
->sta
|| WLAN_FC_GET_TYPE(rx
->fc
) != WLAN_FC_TYPE_CTRL
||
2437 WLAN_FC_GET_STYPE(rx
->fc
) != WLAN_FC_STYPE_PSPOLL
))
2438 return TXRX_CONTINUE
;
2440 skb
= skb_dequeue(&rx
->sta
->tx_filtered
);
2442 skb
= skb_dequeue(&rx
->sta
->ps_tx_buf
);
2444 rx
->local
->total_ps_buffered
--;
2446 no_pending_pkts
= skb_queue_empty(&rx
->sta
->tx_filtered
) &&
2447 skb_queue_empty(&rx
->sta
->ps_tx_buf
);
2450 struct ieee80211_hdr
*hdr
=
2451 (struct ieee80211_hdr
*) skb
->data
;
2453 /* tell TX path to send one frame even though the STA may
2454 * still remain is PS mode after this frame exchange */
2455 rx
->sta
->pspoll
= 1;
2457 #ifdef IEEE80211_VERBOSE_DEBUG_PS
2458 printk(KERN_DEBUG
"STA " MACSTR
" aid %d: PS Poll (entries "
2460 MAC2STR(rx
->sta
->addr
), rx
->sta
->aid
,
2461 skb_queue_len(&rx
->sta
->ps_tx_buf
));
2462 #endif /* IEEE80211_VERBOSE_DEBUG_PS */
2464 /* Use MoreData flag to indicate whether there are more
2465 * buffered frames for this STA */
2466 if (no_pending_pkts
) {
2467 hdr
->frame_control
&= cpu_to_le16(~WLAN_FC_MOREDATA
);
2468 rx
->sta
->flags
&= ~WLAN_STA_TIM
;
2470 hdr
->frame_control
|= cpu_to_le16(WLAN_FC_MOREDATA
);
2472 dev_queue_xmit(skb
);
2474 if (no_pending_pkts
&& rx
->local
->hw
->set_tim
)
2475 rx
->local
->hw
->set_tim(rx
->dev
, rx
->sta
->aid
, 0);
2476 #ifdef IEEE80211_VERBOSE_DEBUG_PS
2477 } else if (!rx
->u
.rx
.sent_ps_buffered
) {
2478 printk(KERN_DEBUG
"%s: STA " MACSTR
" sent PS Poll even "
2479 "though there is no buffered frames for it\n",
2480 rx
->dev
->name
, MAC2STR(rx
->sta
->addr
));
2481 #endif /* IEEE80211_VERBOSE_DEBUG_PS */
2485 /* Free PS Poll skb here instead of returning TXRX_DROP that would
2486 * count as an dropped frame. */
2487 dev_kfree_skb(rx
->skb
);
2493 static inline struct ieee80211_fragment_entry
*
2494 ieee80211_reassemble_add(struct ieee80211_local
*local
,
2495 unsigned int frag
, unsigned int seq
, int rx_queue
,
2496 struct sk_buff
**skb
)
2498 struct ieee80211_fragment_entry
*entry
;
2501 idx
= local
->fragment_next
;
2502 entry
= &local
->fragments
[local
->fragment_next
++];
2503 if (local
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
2504 local
->fragment_next
= 0;
2507 #ifdef CONFIG_IEEE80211_DEBUG
2508 struct ieee80211_hdr
*hdr
=
2509 (struct ieee80211_hdr
*) entry
->skb
->data
;
2510 printk(KERN_DEBUG
"%s: RX reassembly removed oldest "
2511 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
2512 "addr1=" MACSTR
" addr2=" MACSTR
"\n",
2513 local
->mdev
->name
, idx
,
2514 jiffies
- entry
->first_frag_time
, entry
->seq
,
2515 entry
->last_frag
, MAC2STR(hdr
->addr1
),
2516 MAC2STR(hdr
->addr2
));
2517 #endif /* CONFIG_IEEE80211_DEBUG */
2518 dev_kfree_skb(entry
->skb
);
2523 entry
->first_frag_time
= jiffies
;
2525 entry
->rx_queue
= rx_queue
;
2526 entry
->last_frag
= frag
;
2533 static inline struct ieee80211_fragment_entry
*
2534 ieee80211_reassemble_find(struct ieee80211_local
*local
,
2535 u16 fc
, unsigned int frag
, unsigned int seq
,
2536 int rx_queue
, struct ieee80211_hdr
*hdr
)
2538 struct ieee80211_fragment_entry
*entry
;
2541 idx
= local
->fragment_next
;
2542 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
2543 struct ieee80211_hdr
*f_hdr
;
2548 idx
= IEEE80211_FRAGMENT_MAX
- 1;
2550 entry
= &local
->fragments
[idx
];
2551 if (!entry
->skb
|| entry
->seq
!= seq
||
2552 entry
->rx_queue
!= rx_queue
||
2553 entry
->last_frag
+ 1 != frag
)
2556 f_hdr
= (struct ieee80211_hdr
*) entry
->skb
->data
;
2557 f_fc
= le16_to_cpu(f_hdr
->frame_control
);
2559 if (WLAN_FC_GET_TYPE(fc
) != WLAN_FC_GET_TYPE(f_fc
) ||
2560 memcmp(hdr
->addr1
, f_hdr
->addr1
, ETH_ALEN
) != 0 ||
2561 memcmp(hdr
->addr2
, f_hdr
->addr2
, ETH_ALEN
) != 0)
2564 if (entry
->first_frag_time
+ 2 * HZ
< jiffies
) {
2565 dev_kfree_skb(entry
->skb
);
2576 static ieee80211_txrx_result
2577 ieee80211_rx_h_defragment(struct ieee80211_txrx_data
*rx
)
2579 struct ieee80211_hdr
*hdr
;
2581 unsigned int frag
, seq
;
2582 struct ieee80211_fragment_entry
*entry
;
2584 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
2585 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2586 frag
= WLAN_GET_SEQ_FRAG(sc
);
2588 if (likely((!(rx
->fc
& WLAN_FC_MOREFRAG
) && frag
== 0) ||
2589 (rx
->skb
)->len
< 24 || MULTICAST_ADDR(hdr
->addr1
))) {
2590 /* not fragmented */
2593 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
2595 seq
= WLAN_GET_SEQ_SEQ(sc
);
2598 /* This is the first fragment of a new frame. */
2599 entry
= ieee80211_reassemble_add(rx
->local
, frag
, seq
,
2600 rx
->u
.rx
.queue
, &(rx
->skb
));
2601 if (rx
->key
&& rx
->key
->alg
== ALG_CCMP
&&
2602 (rx
->fc
& WLAN_FC_ISWEP
)) {
2603 /* Store CCMP PN so that we can verify that the next
2604 * fragment has a sequential PN value. */
2606 memcpy(entry
->last_pn
,
2607 rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
],
2613 /* This is a fragment for a frame that should already be pending in
2614 * fragment cache. Add this fragment to the end of the pending entry.
2616 entry
= ieee80211_reassemble_find(rx
->local
, rx
->fc
, frag
, seq
,
2617 rx
->u
.rx
.queue
, hdr
);
2619 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
2623 /* Verify that MPDUs within one MSDU have sequential PN values.
2624 * (IEEE 802.11i, 8.3.3.4.5) */
2627 u8 pn
[CCMP_PN_LEN
], *rpn
;
2628 if (rx
->key
== NULL
|| rx
->key
->alg
!= ALG_CCMP
)
2630 memcpy(pn
, entry
->last_pn
, CCMP_PN_LEN
);
2631 for (i
= CCMP_PN_LEN
- 1; i
>= 0; i
--) {
2636 rpn
= rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
];
2637 if (memcmp(pn
, rpn
, CCMP_PN_LEN
) != 0) {
2638 printk(KERN_DEBUG
"%s: defrag: CCMP PN not sequential"
2639 " A2=" MACSTR
" PN=%02x%02x%02x%02x%02x%02x "
2640 "(expected %02x%02x%02x%02x%02x%02x)\n",
2641 rx
->dev
->name
, MAC2STR(hdr
->addr2
),
2642 rpn
[0], rpn
[1], rpn
[2], rpn
[3], rpn
[4], rpn
[5],
2643 pn
[0], pn
[1], pn
[2], pn
[3], pn
[4], pn
[5]);
2646 memcpy(entry
->last_pn
, pn
, CCMP_PN_LEN
);
2649 /* TODO: could gather list of skb's and reallocate data buffer only
2650 * after finding out the total length of the frame */
2651 skb_pull(rx
->skb
, ieee80211_get_hdrlen(rx
->fc
));
2652 if (skb_tailroom(entry
->skb
) < rx
->skb
->len
) {
2653 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head2
);
2654 if (unlikely(pskb_expand_head(entry
->skb
, 0, rx
->skb
->len
,
2656 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
2660 memcpy(skb_put(entry
->skb
, rx
->skb
->len
), rx
->skb
->data
, rx
->skb
->len
);
2661 entry
->last_frag
= frag
;
2662 dev_kfree_skb(rx
->skb
);
2664 if (rx
->fc
& WLAN_FC_MOREFRAG
) {
2669 /* Complete frame has been reassembled - process it now */
2670 rx
->skb
= entry
->skb
;
2676 rx
->sta
->rx_packets
++;
2677 if (MULTICAST_ADDR(hdr
->addr1
))
2678 rx
->local
->dot11MulticastReceivedFrameCount
++;
2679 #ifdef IEEE80211_LEDS
2681 ieee80211_rx_led(2, rx
->dev
);
2682 #endif /* IEEE80211_LEDS */
2683 return TXRX_CONTINUE
;
2687 static ieee80211_txrx_result
2688 ieee80211_rx_h_monitor(struct ieee80211_txrx_data
*rx
)
2690 if (rx
->local
->conf
.mode
== IW_MODE_MONITOR
) {
2691 ieee80211_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
,
2692 ieee80211_msg_monitor
);
2696 return TXRX_CONTINUE
;
2700 static ieee80211_txrx_result
2701 ieee80211_rx_h_check(struct ieee80211_txrx_data
*rx
)
2703 struct ieee80211_hdr
*hdr
;
2705 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
2707 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
2708 if (rx
->sta
&& !MULTICAST_ADDR(hdr
->addr1
)) {
2709 if (unlikely(rx
->fc
& WLAN_FC_RETRY
&&
2710 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] ==
2712 rx
->local
->dot11FrameDuplicateCount
++;
2713 rx
->sta
->num_duplicates
++;
2716 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] = hdr
->seq_ctrl
;
2719 if (rx
->local
->hw
->rx_includes_fcs
&& rx
->skb
->len
> FCS_LEN
)
2720 skb_trim(rx
->skb
, rx
->skb
->len
- FCS_LEN
);
2722 if (unlikely(rx
->skb
->len
< 16)) {
2723 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_short
);
2727 /* Filter out foreign unicast packets when in promiscuous mode.
2728 * FIX: Filter out multicast to foreign BSSID. */
2729 if (rx
->local
->conf
.mode
== IW_MODE_INFRA
&&
2730 !MULTICAST_ADDR(hdr
->addr1
) &&
2731 !ieee80211_own_addr(rx
->dev
, hdr
->addr1
))
2734 /* Drop disallowed frame classes based on STA auth/assoc state;
2735 * IEEE 802.11, Chap 5.5.
2737 * 80211.o does filtering only based on association state, i.e., it
2738 * drops Class 3 frames from not associated stations. hostapd sends
2739 * deauth/disassoc frames when needed. In addition, hostapd is
2740 * responsible for filtering on both auth and assoc states.
2742 if (unlikely((WLAN_FC_GET_TYPE(rx
->fc
) == WLAN_FC_TYPE_DATA
||
2743 (WLAN_FC_GET_TYPE(rx
->fc
) == WLAN_FC_TYPE_CTRL
&&
2744 WLAN_FC_GET_STYPE(rx
->fc
) == WLAN_FC_STYPE_PSPOLL
)) &&
2745 rx
->local
->conf
.mode
!= IW_MODE_ADHOC
&&
2746 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_ASSOC
)))) {
2747 if (!(rx
->fc
& WLAN_FC_FROMDS
) && !(rx
->fc
& WLAN_FC_TODS
)) {
2748 /* Drop IBSS frames silently. */
2752 ieee80211_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
,
2753 ieee80211_msg_sta_not_assoc
);
2757 if (rx
->local
->conf
.mode
== IW_MODE_INFRA
)
2762 if (rx
->sta
&& rx
->sta
->key
&& always_sta_key
) {
2763 rx
->key
= rx
->sta
->key
;
2766 printk(KERN_DEBUG
"%s: sdata was null in packet!!\n",
2768 printk(KERN_DEBUG
"%s: Addr1: " MACSTR
"\n",
2769 rx
->dev
->name
, MAC2STR(hdr
->addr1
));
2770 printk(KERN_DEBUG
"%s: Addr2: " MACSTR
"\n",
2771 rx
->dev
->name
, MAC2STR(hdr
->addr2
));
2772 printk(KERN_DEBUG
"%s: Addr3: " MACSTR
"\n",
2773 rx
->dev
->name
, MAC2STR(hdr
->addr3
));
2776 if (rx
->sta
&& rx
->sta
->key
)
2777 rx
->key
= rx
->sta
->key
;
2779 rx
->key
= rx
->sdata
->default_key
;
2781 if (rx
->local
->hw
->wep_include_iv
&&
2782 rx
->fc
& WLAN_FC_ISWEP
) {
2783 int keyidx
= ieee80211_wep_get_keyidx(rx
->skb
);
2785 if (keyidx
>= 0 && keyidx
< NUM_DEFAULT_KEYS
&&
2786 (rx
->sta
== NULL
|| rx
->sta
->key
== NULL
||
2788 rx
->key
= rx
->sdata
->keys
[keyidx
];
2791 printk(KERN_DEBUG
"%s: RX WEP frame with "
2792 "unknown keyidx %d (A1=" MACSTR
" A2="
2793 MACSTR
" A3=" MACSTR
")\n",
2794 rx
->dev
->name
, keyidx
,
2795 MAC2STR(hdr
->addr1
),
2796 MAC2STR(hdr
->addr2
),
2797 MAC2STR(hdr
->addr3
));
2799 rx
->dev
, rx
->skb
, rx
->u
.rx
.status
,
2800 ieee80211_msg_wep_frame_unknown_key
);
2806 if (rx
->fc
& WLAN_FC_ISWEP
&& rx
->key
) {
2807 rx
->key
->tx_rx_count
++;
2808 if (unlikely(rx
->local
->key_tx_rx_threshold
&&
2809 rx
->key
->tx_rx_count
>
2810 rx
->local
->key_tx_rx_threshold
)) {
2811 ieee80211_key_threshold_notify(rx
->dev
, rx
->key
,
2816 return TXRX_CONTINUE
;
2820 static ieee80211_txrx_result
2821 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data
*rx
)
2823 struct sta_info
*sta
= rx
->sta
;
2824 struct net_device
*dev
= rx
->dev
;
2825 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
2828 return TXRX_CONTINUE
;
2830 /* Update last_rx only for IBSS packets which are for the current
2831 * BSSID to avoid keeping the current IBSS network alive in cases where
2832 * other STAs are using different BSSID. */
2833 if (rx
->local
->conf
.mode
== IW_MODE_ADHOC
) {
2834 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
);
2835 if (memcmp(bssid
, rx
->local
->bssid
, ETH_ALEN
) == 0)
2836 sta
->last_rx
= jiffies
;
2838 if (!MULTICAST_ADDR(hdr
->addr1
) ||
2839 rx
->local
->conf
.mode
== IW_MODE_INFRA
) {
2840 /* Update last_rx only for unicast frames in order to prevent
2841 * the Probe Request frames (the only broadcast frames from a
2842 * STA in infrastructure mode) from keeping a connection alive.
2844 sta
->last_rx
= jiffies
;
2846 sta
->rx_fragments
++;
2847 sta
->rx_bytes
+= rx
->skb
->len
;
2848 sta
->last_rssi
= rx
->u
.rx
.status
->ssi
;
2850 if (!(rx
->fc
& WLAN_FC_MOREFRAG
)) {
2851 /* Change STA power saving mode only in the end of a frame
2852 * exchange sequence */
2853 if ((sta
->flags
& WLAN_STA_PS
) && !(rx
->fc
& WLAN_FC_PWRMGT
))
2854 rx
->u
.rx
.sent_ps_buffered
+= ap_sta_ps_end(dev
, sta
);
2855 else if (!(sta
->flags
& WLAN_STA_PS
) &&
2856 (rx
->fc
& WLAN_FC_PWRMGT
))
2857 ap_sta_ps_start(dev
, sta
);
2860 /* Drop data::nullfunc frames silently, since they are used only to
2861 * control station power saving mode. */
2862 if (WLAN_FC_GET_TYPE(rx
->fc
) == WLAN_FC_TYPE_DATA
&&
2863 WLAN_FC_GET_STYPE(rx
->fc
) == WLAN_FC_STYPE_NULLFUNC
) {
2864 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
2865 /* Update counter and free packet here to avoid counting this
2866 * as a dropped packed. */
2868 dev_kfree_skb(rx
->skb
);
2872 return TXRX_CONTINUE
;
2876 static ieee80211_txrx_result
2877 ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data
*rx
)
2879 if (!rx
->sta
|| !(rx
->fc
& WLAN_FC_ISWEP
) ||
2880 WLAN_FC_GET_TYPE(rx
->fc
) != WLAN_FC_TYPE_DATA
|| !rx
->key
||
2881 rx
->key
->alg
!= ALG_WEP
)
2882 return TXRX_CONTINUE
;
2884 /* Check for weak IVs, if hwaccel did not remove IV from the frame */
2885 if (rx
->local
->hw
->wep_include_iv
||
2886 rx
->key
->force_sw_encrypt
|| rx
->local
->conf
.sw_decrypt
) {
2887 u8
*iv
= ieee80211_wep_is_weak_iv(rx
->skb
, rx
->key
);
2889 rx
->sta
->wep_weak_iv_count
++;
2893 return TXRX_CONTINUE
;
2897 static ieee80211_txrx_result
2898 ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data
*rx
)
2900 /* If the device handles decryption totally, skip this test */
2901 if (rx
->local
->hw
->device_hides_wep
)
2902 return TXRX_CONTINUE
;
2904 if ((rx
->key
&& rx
->key
->alg
!= ALG_WEP
) ||
2905 !(rx
->fc
& WLAN_FC_ISWEP
) ||
2906 (WLAN_FC_GET_TYPE(rx
->fc
) != WLAN_FC_TYPE_DATA
&&
2907 (WLAN_FC_GET_TYPE(rx
->fc
) != WLAN_FC_TYPE_MGMT
||
2908 WLAN_FC_GET_STYPE(rx
->fc
) != WLAN_FC_STYPE_AUTH
)))
2909 return TXRX_CONTINUE
;
2912 printk(KERN_DEBUG
"%s: RX WEP frame, but no key set\n",
2917 if (!(rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
) ||
2918 rx
->key
->force_sw_encrypt
|| rx
->local
->conf
.sw_decrypt
) {
2919 if (ieee80211_wep_decrypt(rx
->local
, rx
->skb
, rx
->key
)) {
2920 printk(KERN_DEBUG
"%s: RX WEP frame, decrypt "
2921 "failed\n", rx
->dev
->name
);
2924 } else if (rx
->local
->hw
->wep_include_iv
) {
2925 ieee80211_wep_remove_iv(rx
->local
, rx
->skb
, rx
->key
);
2927 skb_trim(rx
->skb
, rx
->skb
->len
- 4);
2930 return TXRX_CONTINUE
;
2934 static ieee80211_txrx_result
2935 ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data
*rx
)
2937 if (rx
->sdata
->eapol
&& ieee80211_is_eapol(rx
->skb
) &&
2938 rx
->local
->conf
.mode
!= IW_MODE_INFRA
) {
2939 /* Pass both encrypted and unencrypted EAPOL frames to user
2940 * space for processing. */
2941 ieee80211_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
,
2942 ieee80211_msg_normal
);
2946 if (unlikely(rx
->sdata
->ieee802_1x
&&
2947 WLAN_FC_GET_TYPE(rx
->fc
) == WLAN_FC_TYPE_DATA
&&
2948 WLAN_FC_GET_STYPE(rx
->fc
) != WLAN_FC_STYPE_NULLFUNC
&&
2949 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_AUTHORIZED
)) &&
2950 !ieee80211_is_eapol(rx
->skb
))) {
2951 #ifdef CONFIG_IEEE80211_DEBUG
2952 struct ieee80211_hdr
*hdr
=
2953 (struct ieee80211_hdr
*) rx
->skb
->data
;
2954 printk(KERN_DEBUG
"%s: dropped frame from " MACSTR
2955 " (unauthorized port)\n", rx
->dev
->name
,
2956 MAC2STR(hdr
->addr2
));
2957 #endif /* CONFIG_IEEE80211_DEBUG */
2961 return TXRX_CONTINUE
;
2965 static ieee80211_txrx_result
2966 ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data
*rx
)
2968 /* If the device handles decryption totally, skip this test */
2969 if (rx
->local
->hw
->device_hides_wep
)
2970 return TXRX_CONTINUE
;
2972 /* Drop unencrypted frames if key is set. */
2973 if (unlikely(!(rx
->fc
& WLAN_FC_ISWEP
) &&
2974 WLAN_FC_GET_TYPE(rx
->fc
) == WLAN_FC_TYPE_DATA
&&
2975 WLAN_FC_GET_STYPE(rx
->fc
) != WLAN_FC_STYPE_NULLFUNC
&&
2976 (rx
->key
|| rx
->sdata
->drop_unencrypted
) &&
2977 (rx
->sdata
->eapol
== 0 ||
2978 !ieee80211_is_eapol(rx
->skb
)))) {
2979 printk(KERN_DEBUG
"%s: RX non-WEP frame, but expected "
2980 "encryption\n", rx
->dev
->name
);
2983 return TXRX_CONTINUE
;
2987 static ieee80211_txrx_result
2988 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data
*rx
)
2990 struct ieee80211_sub_if_data
*sdata
;
2991 sdata
= IEEE80211_DEV_TO_SUB_IF(rx
->dev
);
2992 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
2993 ieee80211_sta_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
);
2995 /* Management frames are sent to hostapd for processing */
2996 ieee80211_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
,
2997 ieee80211_msg_normal
);
3003 static ieee80211_txrx_result
3004 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data
*rx
)
3006 struct ieee80211_local
*local
= rx
->local
;
3007 struct sk_buff
*skb
= rx
->skb
;
3009 if (unlikely(local
->sta_scanning
!= 0)) {
3010 ieee80211_sta_rx_scan(rx
->dev
, skb
, rx
->u
.rx
.status
);
3014 if (WLAN_FC_GET_TYPE(rx
->fc
) == WLAN_FC_TYPE_DATA
)
3015 local
->scan
.txrx_count
++;
3016 if (unlikely(local
->scan
.in_scan
!= 0 &&
3017 rx
->u
.rx
.status
->freq
== local
->scan
.freq
)) {
3018 struct ieee80211_hdr
*hdr
;
3021 local
->scan
.rx_packets
++;
3023 hdr
= (struct ieee80211_hdr
*) skb
->data
;
3024 fc
= le16_to_cpu(hdr
->frame_control
);
3026 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3027 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
) {
3028 local
->scan
.rx_beacon
++;
3029 /* Need to trim FCS here because it is normally
3030 * removed only after this passive scan handler. */
3031 if (rx
->local
->hw
->rx_includes_fcs
&&
3032 rx
->skb
->len
> FCS_LEN
)
3033 skb_trim(rx
->skb
, rx
->skb
->len
- FCS_LEN
);
3035 ieee80211_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
,
3036 ieee80211_msg_passive_scan
);
3039 I802_DEBUG_INC(local
->rx_handlers_drop_passive_scan
);
3044 return TXRX_CONTINUE
;
3048 static u8
* ieee80211_get_bssid(struct ieee80211_hdr
*hdr
, size_t len
)
3055 fc
= le16_to_cpu(hdr
->frame_control
);
3057 switch (WLAN_FC_GET_TYPE(fc
)) {
3058 case WLAN_FC_TYPE_DATA
:
3059 switch (fc
& (WLAN_FC_TODS
| WLAN_FC_FROMDS
)) {
3062 case (WLAN_FC_TODS
| WLAN_FC_FROMDS
):
3064 case WLAN_FC_FROMDS
:
3070 case WLAN_FC_TYPE_MGMT
:
3072 case WLAN_FC_TYPE_CTRL
:
3073 if (WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PSPOLL
)
3083 static struct net_device
* ieee80211_get_rx_dev(struct ieee80211_local
*local
,
3084 struct ieee80211_hdr
*hdr
,
3085 size_t len
, int *sta_broadcast
)
3088 struct net_device
*dev
;
3091 bssid
= ieee80211_get_bssid(hdr
, len
);
3093 dev
= ieee80211_own_bssid(local
, bssid
);
3094 if (!dev
&& (local
->conf
.mode
== IW_MODE_INFRA
||
3095 local
->conf
.mode
== IW_MODE_ADHOC
))
3096 dev
= ieee80211_sta_bssid(local
, bssid
, hdr
->addr1
,
3103 fc
= le16_to_cpu(hdr
->frame_control
);
3104 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_DATA
&&
3105 (fc
& (WLAN_FC_TODS
| WLAN_FC_FROMDS
)) ==
3106 (WLAN_FC_TODS
| WLAN_FC_FROMDS
)) {
3107 dev
= ieee80211_get_wds_dev(local
, hdr
->addr2
);
3113 /* Default to default device if nothing else matches */
3118 static void ieee80211_rx_michael_mic_report(struct net_device
*dev
,
3119 struct ieee80211_hdr
*hdr
,
3120 struct sta_info
*sta
,
3121 struct ieee80211_txrx_data
*rx
)
3125 hdrlen
= ieee80211_get_hdrlen_from_skb(rx
->skb
);
3126 if (rx
->skb
->len
>= hdrlen
+ 4)
3127 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
3131 /* TODO: verify that this is not triggered by fragmented
3132 * frames (hw does not verify MIC for them). */
3133 printk(KERN_DEBUG
"%s: TKIP hwaccel reported Michael MIC "
3134 "failure from " MACSTR
" to " MACSTR
" keyidx=%d\n",
3135 dev
->name
, MAC2STR(hdr
->addr2
), MAC2STR(hdr
->addr1
), keyidx
);
3138 /* Some hardware versions seem to generate incorrect
3139 * Michael MIC reports; ignore them to avoid triggering
3140 * countermeasures. */
3141 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3142 "error for unknown address " MACSTR
"\n",
3143 dev
->name
, MAC2STR(hdr
->addr2
));
3147 if (!(rx
->fc
& WLAN_FC_ISWEP
)) {
3148 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3149 "error for a frame with no ISWEP flag (src "
3150 MACSTR
")\n", dev
->name
, MAC2STR(hdr
->addr2
));
3154 if (rx
->local
->hw
->wep_include_iv
&&
3155 rx
->local
->conf
.mode
== IW_MODE_MASTER
) {
3156 int keyidx
= ieee80211_wep_get_keyidx(rx
->skb
);
3157 /* AP with Pairwise keys support should never receive Michael
3158 * MIC errors for non-zero keyidx because these are reserved
3159 * for group keys and only the AP is sending real multicast
3162 printk(KERN_DEBUG
"%s: ignored Michael MIC error for "
3163 "a frame with non-zero keyidx (%d) (src " MACSTR
3164 ")\n", dev
->name
, keyidx
, MAC2STR(hdr
->addr2
));
3169 if (WLAN_FC_GET_TYPE(rx
->fc
) != WLAN_FC_TYPE_DATA
&&
3170 (WLAN_FC_GET_TYPE(rx
->fc
) != WLAN_FC_TYPE_MGMT
||
3171 WLAN_FC_GET_STYPE(rx
->fc
) != WLAN_FC_STYPE_AUTH
)) {
3172 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3173 "error for a frame that cannot be encrypted "
3174 "(fc=0x%04x) (src " MACSTR
")\n",
3175 dev
->name
, rx
->fc
, MAC2STR(hdr
->addr2
));
3180 union iwreq_data wrqu
;
3181 char *buf
= kmalloc(128, GFP_ATOMIC
);
3185 /* TODO: needed parameters: count, key type, TSC */
3186 sprintf(buf
, "MLME-MICHAELMICFAILURE.indication("
3187 "keyid=%d %scast addr=" MACSTR
")",
3188 keyidx
, hdr
->addr1
[0] & 0x01 ? "broad" : "uni",
3189 MAC2STR(hdr
->addr2
));
3190 memset(&wrqu
, 0, sizeof(wrqu
));
3191 wrqu
.data
.length
= strlen(buf
);
3192 wireless_send_event(rx
->dev
, IWEVCUSTOM
, &wrqu
, buf
);
3196 /* TODO: consider verifying the MIC error report with software
3197 * implementation if we get too many spurious reports from the
3199 ieee80211_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
,
3200 ieee80211_msg_michael_mic_failure
);
3204 dev_kfree_skb(rx
->skb
);
3209 static void ieee80211_sta_rx_broadcast(struct ieee80211_txrx_data
*rx
)
3211 struct ieee80211_local
*local
= rx
->dev
->priv
;
3212 u8
*_bssid
, bssid
[ETH_ALEN
];
3213 struct sk_buff
*orig_skb
= rx
->skb
, *skb
;
3214 struct ieee80211_hdr
*hdr
;
3215 ieee80211_rx_handler
*handler
;
3216 ieee80211_txrx_result res
;
3217 struct list_head
*ptr
;
3219 hdr
= (struct ieee80211_hdr
*) orig_skb
->data
;
3220 _bssid
= ieee80211_get_bssid(hdr
, orig_skb
->len
);
3221 if (_bssid
== NULL
) {
3222 dev_kfree_skb(orig_skb
);
3225 memcpy(bssid
, _bssid
, ETH_ALEN
);
3227 list_for_each(ptr
, &local
->sub_if_list
) {
3228 struct ieee80211_sub_if_data
*sdata
=
3229 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
3230 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
||
3231 (memcmp(bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) != 0 &&
3232 !(bssid
[0] & 0x01)))
3235 skb
= skb_copy(orig_skb
, GFP_ATOMIC
);
3237 if (net_ratelimit()) {
3238 printk(KERN_DEBUG
"%s: failed to copy "
3239 "multicast frame for %s",
3240 rx
->dev
->name
, sdata
->dev
->name
);
3245 hdr
= (struct ieee80211_hdr
*) skb
->data
;
3247 rx
->dev
= sdata
->dev
;
3248 rx
->sdata
= IEEE80211_DEV_TO_SUB_IF(rx
->dev
);
3251 for (handler
= local
->rx_handlers
; *handler
!= NULL
; handler
++)
3253 res
= (*handler
)(rx
);
3254 if (res
== TXRX_DROP
|| res
== TXRX_QUEUED
)
3258 if (res
== TXRX_DROP
|| *handler
== NULL
)
3262 dev_kfree_skb(orig_skb
);
3267 * This is the receive path handler. It is called by a low level driver when an
3268 * 802.11 MPDU is received from the hardware.
3270 void ieee80211_rx(struct net_device
*dev
, struct sk_buff
*skb
,
3271 struct ieee80211_rx_status
*status
)
3273 struct ieee80211_local
*local
= dev
->priv
;
3274 struct sta_info
*sta
;
3275 struct ieee80211_hdr
*hdr
;
3276 ieee80211_rx_handler
*handler
;
3277 struct ieee80211_txrx_data rx
;
3278 ieee80211_txrx_result res
= TXRX_DROP
;
3280 int sta_broadcast
= 0;
3282 hdr
= (struct ieee80211_hdr
*) skb
->data
;
3283 memset(&rx
, 0, sizeof(rx
));
3286 if (skb
->len
>= 16) {
3287 sta
= rx
.sta
= sta_info_get(local
, hdr
->addr2
);
3288 if (unlikely(sta
== NULL
&&
3289 local
->conf
.mode
== IW_MODE_ADHOC
)) {
3290 u8
*bssid
= ieee80211_get_bssid(hdr
, skb
->len
);
3292 memcmp(bssid
, local
->bssid
, ETH_ALEN
) == 0)
3294 ieee80211_ibss_add_sta(dev
, skb
, bssid
,
3298 sta
= rx
.sta
= NULL
;
3299 if (sta
&& !sta
->assoc_ap
&& !(sta
->flags
& WLAN_STA_WDS
))
3302 rx
.dev
= ieee80211_get_rx_dev(local
, hdr
, skb
->len
,
3305 rx
.sdata
= IEEE80211_DEV_TO_SUB_IF(rx
.dev
);
3306 rx
.u
.rx
.status
= status
;
3307 rx
.fc
= skb
->len
>= 2 ? le16_to_cpu(hdr
->frame_control
) : 0;
3308 type
= WLAN_FC_GET_TYPE(rx
.fc
);
3309 if (type
== WLAN_FC_TYPE_DATA
|| type
== WLAN_FC_TYPE_MGMT
)
3310 local
->dot11ReceivedFragmentCount
++;
3311 if (sta_broadcast
) {
3312 ieee80211_sta_rx_broadcast(&rx
);
3316 if ((status
->flag
& RX_FLAG_MMIC_ERROR
)) {
3317 ieee80211_rx_michael_mic_report(dev
, hdr
, sta
, &rx
);
3321 for (handler
= local
->rx_handlers
; *handler
!= NULL
; handler
++) {
3322 res
= (*handler
)(&rx
);
3323 if (res
!= TXRX_CONTINUE
) {
3324 if (res
== TXRX_DROP
) {
3325 I802_DEBUG_INC(local
->rx_handlers_drop
);
3329 if (res
== TXRX_QUEUED
)
3330 I802_DEBUG_INC(local
->rx_handlers_queued
);
3335 if (res
== TXRX_DROP
|| *handler
== NULL
)
3340 sta_info_release(local
, sta
);
3344 static ieee80211_txrx_result
3345 ieee80211_tx_h_load_stats(struct ieee80211_txrx_data
*tx
)
3347 struct ieee80211_local
*local
= tx
->local
;
3348 struct sk_buff
*skb
= tx
->skb
;
3349 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
3350 u32 load
= 0, hdrtime
;
3352 /* TODO: this could be part of tx_status handling, so that the number
3353 * of retries would be known; TX rate should in that case be stored
3354 * somewhere with the packet */
3356 /* Estimate total channel use caused by this frame */
3358 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
3359 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
3361 if (local
->conf
.phymode
== MODE_IEEE80211A
||
3362 local
->conf
.phymode
== MODE_ATHEROS_TURBO
||
3363 local
->conf
.phymode
== MODE_ATHEROS_TURBOG
||
3364 (local
->conf
.phymode
== MODE_IEEE80211G
&&
3365 tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_ERP
))
3366 hdrtime
= CHAN_UTIL_HDR_SHORT
;
3368 hdrtime
= CHAN_UTIL_HDR_LONG
;
3371 if (!MULTICAST_ADDR(hdr
->addr1
))
3374 if (tx
->u
.tx
.control
->use_rts_cts
)
3375 load
+= 2 * hdrtime
;
3376 else if (tx
->u
.tx
.control
->use_cts_protect
)
3379 load
+= skb
->len
* tx
->u
.tx
.rate
->rate_inv
;
3381 if (tx
->u
.tx
.extra_frag
) {
3383 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
3384 load
+= 2 * hdrtime
;
3385 load
+= tx
->u
.tx
.extra_frag
[i
]->len
*
3386 tx
->u
.tx
.rate
->rate
;
3390 /* Divide channel_use by 8 to avoid wrapping around the counter */
3391 load
>>= CHAN_UTIL_SHIFT
;
3392 local
->channel_use_raw
+= load
;
3394 tx
->sta
->channel_use_raw
+= load
;
3395 tx
->sdata
->channel_use_raw
+= load
;
3397 return TXRX_CONTINUE
;
3401 static ieee80211_txrx_result
3402 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data
*rx
)
3404 struct ieee80211_local
*local
= rx
->local
;
3405 struct sk_buff
*skb
= rx
->skb
;
3406 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
3407 u32 load
= 0, hdrtime
;
3408 struct ieee80211_rate
*rate
;
3411 /* Estimate total channel use caused by this frame */
3413 if (unlikely(local
->num_curr_rates
< 0))
3414 return TXRX_CONTINUE
;
3416 rate
= &local
->curr_rates
[0];
3417 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
3418 if (local
->curr_rates
[i
].val
== rx
->u
.rx
.status
->rate
) {
3419 rate
= &local
->curr_rates
[i
];
3424 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
3425 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
3427 if (local
->conf
.phymode
== MODE_IEEE80211A
||
3428 local
->conf
.phymode
== MODE_ATHEROS_TURBO
||
3429 local
->conf
.phymode
== MODE_ATHEROS_TURBOG
||
3430 (local
->conf
.phymode
== MODE_IEEE80211G
&&
3431 rate
->flags
& IEEE80211_RATE_ERP
))
3432 hdrtime
= CHAN_UTIL_HDR_SHORT
;
3434 hdrtime
= CHAN_UTIL_HDR_LONG
;
3437 if (!MULTICAST_ADDR(hdr
->addr1
))
3440 load
+= skb
->len
* rate
->rate_inv
;
3442 /* Divide channel_use by 8 to avoid wrapping around the counter */
3443 load
>>= CHAN_UTIL_SHIFT
;
3444 local
->channel_use_raw
+= load
;
3446 rx
->sta
->channel_use_raw
+= load
;
3447 rx
->sdata
->channel_use_raw
+= load
;
3449 return TXRX_CONTINUE
;
3453 static void ieee80211_stat_refresh(unsigned long data
)
3455 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
3456 struct list_head
*ptr
, *n
;
3458 if (!local
->stat_time
)
3461 /* go through all stations */
3462 spin_lock_bh(&local
->sta_lock
);
3463 list_for_each(ptr
, &local
->sta_list
) {
3464 struct sta_info
*sta
=
3465 list_entry(ptr
, struct sta_info
, list
);
3466 sta
->channel_use
= (sta
->channel_use_raw
/ local
->stat_time
) /
3468 sta
->channel_use_raw
= 0;
3470 spin_unlock_bh(&local
->sta_lock
);
3472 /* go through all subinterfaces */
3473 list_for_each_safe(ptr
, n
, &local
->sub_if_list
) {
3474 struct ieee80211_sub_if_data
*sdata
=
3475 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
3476 sdata
->channel_use
= (sdata
->channel_use_raw
/
3477 local
->stat_time
) / CHAN_UTIL_PER_10MS
;
3478 sdata
->channel_use_raw
= 0;
3482 /* hardware interface */
3483 local
->channel_use
= (local
->channel_use_raw
/
3484 local
->stat_time
) / CHAN_UTIL_PER_10MS
;
3485 local
->channel_use_raw
= 0;
3487 local
->stat_timer
.expires
= jiffies
+ HZ
* local
->stat_time
/ 100;
3488 add_timer(&local
->stat_timer
);
3492 /* This is a version of the rx handler that can be called from hard irq
3493 * context. Post the skb on the queue and schedule the tasklet */
3494 void ieee80211_rx_irqsafe(struct net_device
*dev
, struct sk_buff
*skb
,
3495 struct ieee80211_rx_status
*status
)
3497 struct ieee80211_local
*local
= dev
->priv
;
3500 memcpy(skb
->cb
, status
, sizeof(struct ieee80211_rx_status
));
3501 skb
->pkt_type
= ieee80211_rx_msg
;
3502 skb_queue_tail(&local
->skb_queue
, skb
);
3503 tasklet_schedule(&local
->tasklet
);
3507 void ieee80211_tx_status_irqsafe(struct net_device
*dev
, struct sk_buff
*skb
,
3508 struct ieee80211_tx_status
*status
)
3510 struct ieee80211_local
*local
= dev
->priv
;
3513 if (status
->tx_filtered
|| status
->excessive_retries
) {
3514 /* Need to save a copy of skb->cb somewhere. Storing it in the
3515 * end of the data might not be the most efficient way of doing
3516 * this (since it may require reallocation of packet data), but
3517 * should be good enough for now since tx_filtered or
3518 * excessive_retries should not be triggered that often. */
3519 if (skb_is_nonlinear(skb
)) {
3520 if (skb_linearize(skb
, GFP_ATOMIC
)) {
3521 printk(KERN_DEBUG
"%s: Failed to linearize "
3522 "skb\n", dev
->name
);
3523 dev_kfree_skb_irq(skb
);
3527 if (skb_tailroom(skb
) < sizeof(skb
->cb
) &&
3528 pskb_expand_head(skb
, 0, sizeof(skb
->cb
), GFP_ATOMIC
)) {
3529 printk(KERN_DEBUG
"%s: Failed to store skb->cb "
3530 "in skb->data for TX filtered frame\n",
3532 dev_kfree_skb_irq(skb
);
3535 memcpy(skb_put(skb
, sizeof(skb
->cb
)), skb
->cb
,
3540 memcpy(skb
->cb
, status
, sizeof(struct ieee80211_tx_status
));
3541 skb
->pkt_type
= ieee80211_tx_status_msg
;
3542 skb_queue_tail(status
->req_tx_status
?
3543 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
3544 tmp
= skb_queue_len(&local
->skb_queue
) +
3545 skb_queue_len(&local
->skb_queue_unreliable
);
3546 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
3547 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
3548 dev_kfree_skb_irq(skb
);
3550 I802_DEBUG_INC(local
->tx_status_drop
);
3552 tasklet_schedule(&local
->tasklet
);
3556 static void ieee80211_tasklet_handler(unsigned long data
)
3558 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
3559 struct sk_buff
*skb
;
3560 struct ieee80211_rx_status rx_status
;
3561 struct ieee80211_tx_status tx_status
;
3563 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
3564 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
3565 switch (skb
->pkt_type
) {
3566 case ieee80211_rx_msg
:
3567 /* Make a copy of the RX status because the original
3568 * skb may be freed during processing. Clear skb->type
3569 * in order to not confuse kernel netstack. */
3570 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
3572 ieee80211_rx(skb
->dev
, skb
, &rx_status
);
3574 case ieee80211_tx_status_msg
:
3575 /* Make a copy of the TX status because the original
3576 * skb may be freed during processing. */
3577 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
3579 if ((tx_status
.tx_filtered
||
3580 tx_status
.excessive_retries
) &&
3581 skb
->len
>= sizeof(skb
->cb
)) {
3582 /* Restore skb->cb from the copy that was made
3583 * in ieee80211_tx_status_irqsafe() */
3585 skb
->data
+ skb
->len
- sizeof(skb
->cb
),
3587 skb_trim(skb
, skb
->len
- sizeof(skb
->cb
));
3589 ieee80211_tx_status(skb
->dev
, skb
, &tx_status
);
3591 default: /* should never get here! */
3592 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
3593 local
->wdev
->name
, skb
->pkt_type
);
3601 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
3602 * make a prepared TX frame (one that has been given to hw) to look like brand
3603 * new IEEE 802.11 frame that is ready to go through TX processing again. */
3604 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
3605 struct ieee80211_key
*key
,
3606 struct sk_buff
*skb
)
3608 int hdrlen
, iv_len
, mic_len
;
3613 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
3617 iv_len
= WEP_IV_LEN
;
3618 mic_len
= WEP_ICV_LEN
;
3621 iv_len
= TKIP_IV_LEN
;
3622 mic_len
= TKIP_ICV_LEN
;
3625 iv_len
= CCMP_HDR_LEN
;
3626 mic_len
= CCMP_MIC_LEN
;
3632 if (skb
->len
>= mic_len
&& key
->force_sw_encrypt
)
3633 skb_trim(skb
, skb
->len
- mic_len
);
3634 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
3635 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
3636 skb_pull(skb
, iv_len
);
3640 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
3641 u16 fc
= le16_to_cpu(hdr
->frame_control
);
3642 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
3643 fc
&= ~(WLAN_FC_STYPE_QOS_DATA
<< 4);
3644 hdr
->frame_control
= cpu_to_le16(fc
);
3645 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
3652 void ieee80211_tx_status(struct net_device
*dev
, struct sk_buff
*skb
,
3653 struct ieee80211_tx_status
*status
)
3655 struct sk_buff
*skb2
;
3656 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
3657 struct ieee80211_local
*local
= dev
->priv
;
3658 struct ieee80211_tx_packet_data
*pkt_data
=
3659 (struct ieee80211_tx_packet_data
*) skb
->cb
;
3665 "%s: ieee80211_tx_status called with NULL status\n",
3671 if (status
->excessive_retries
) {
3672 struct sta_info
*sta
;
3675 sta
= sta_info_get(local
, hdr
->addr1
);
3677 if (sta
->flags
& WLAN_STA_PS
) {
3678 /* The STA is in power save mode, so assume
3679 * that this TX packet failed because of that.
3681 status
->excessive_retries
= 0;
3682 status
->tx_filtered
= 1;
3684 sta_info_release(local
, sta
);
3688 if (status
->tx_filtered
) {
3689 struct sta_info
*sta
;
3690 sta
= sta_info_get(local
, hdr
->addr1
);
3693 sta
->tx_filtered_count
++;
3695 /* Clear the TX filter mask for this STA when sending
3696 * the next packet. If the STA went to power save mode,
3697 * this will happen when it is waking up for the next
3699 sta
->clear_dst_mask
= 1;
3701 /* TODO: Is the WLAN_STA_PS flag always set here or is
3702 * the race between RX and TX status causing some
3703 * packets to be filtered out before 80211.o gets an
3704 * update for PS status? This seems to be the case, so
3705 * no changes are likely to be needed. */
3706 if (sta
->flags
& WLAN_STA_PS
&&
3707 skb_queue_len(&sta
->tx_filtered
) <
3708 STA_MAX_TX_BUFFER
) {
3709 ieee80211_remove_tx_extra(local
, sta
->key
,
3711 skb_queue_tail(&sta
->tx_filtered
, skb
);
3712 } else if (!(sta
->flags
& WLAN_STA_PS
) &&
3713 !pkt_data
->control
.requeue
) {
3714 /* Software retry the packet once */
3715 pkt_data
->control
.requeue
= 1;
3716 ieee80211_remove_tx_extra(local
, sta
->key
,
3718 dev_queue_xmit(skb
);
3720 if (net_ratelimit()) {
3721 printk(KERN_DEBUG
"%s: dropped TX "
3722 "filtered frame queue_len=%d "
3727 !!(sta
->flags
& WLAN_STA_PS
),
3732 sta_info_release(local
, sta
);
3736 rate_control_tx_status(dev
, skb
, status
);
3739 #ifdef IEEE80211_LEDS
3740 if (local
->tx_led_counter
&& (local
->tx_led_counter
-- == 1)) {
3741 ieee80211_tx_led(0, dev
);
3743 #endif /* IEEE80211_LEDS */
3745 * Fragments are passed to low-level drivers as separate skbs, so these
3746 * are actually fragments, not frames. Update frame counters only for
3747 * the first fragment of the frame. */
3749 frag
= WLAN_GET_SEQ_FRAG(le16_to_cpu(hdr
->seq_ctrl
));
3750 type
= WLAN_FC_GET_TYPE(le16_to_cpu(hdr
->frame_control
));
3754 local
->dot11TransmittedFrameCount
++;
3755 if (MULTICAST_ADDR(hdr
->addr1
))
3756 local
->dot11MulticastTransmittedFrameCount
++;
3757 if (status
->retry_count
> 0)
3758 local
->dot11RetryCount
++;
3759 if (status
->retry_count
> 1)
3760 local
->dot11MultipleRetryCount
++;
3763 /* This counter shall be incremented for an acknowledged MPDU
3764 * with an individual address in the address 1 field or an MPDU
3765 * with a multicast address in the address 1 field of type Data
3767 if (!MULTICAST_ADDR(hdr
->addr1
) || type
== WLAN_FC_TYPE_DATA
||
3768 type
== WLAN_FC_TYPE_MGMT
)
3769 local
->dot11TransmittedFragmentCount
++;
3772 local
->dot11FailedCount
++;
3775 if (!status
->req_tx_status
) {
3780 msg_type
= status
->ack
? ieee80211_msg_tx_callback_ack
:
3781 ieee80211_msg_tx_callback_fail
;
3783 /* skb was the original skb used for TX. Clone it and give the clone
3784 * to netif_rx(). Free original skb. */
3785 skb2
= skb_copy(skb
, GFP_ATOMIC
);
3793 /* Send frame to hostapd */
3794 ieee80211_rx_mgmt(dev
, skb
, NULL
, msg_type
);
3798 /* TODO: implement register/unregister functions for adding TX/RX handlers
3799 * into ordered list */
3801 static ieee80211_rx_handler ieee80211_rx_handlers
[] =
3803 ieee80211_rx_h_parse_qos
,
3804 ieee80211_rx_h_load_stats
,
3805 ieee80211_rx_h_monitor
,
3806 ieee80211_rx_h_passive_scan
,
3807 ieee80211_rx_h_check
,
3808 ieee80211_rx_h_sta_process
,
3809 ieee80211_rx_h_ccmp_decrypt
,
3810 ieee80211_rx_h_tkip_decrypt
,
3811 ieee80211_rx_h_wep_weak_iv_detection
,
3812 ieee80211_rx_h_wep_decrypt
,
3813 ieee80211_rx_h_defragment
,
3814 ieee80211_rx_h_ieee80211_rx_h_ps_poll
,
3815 ieee80211_rx_h_michael_mic_verify
,
3816 /* this must be after decryption - so header is counted in MPDU mic
3817 * must be before pae and data, so QOS_DATA format frames
3818 * are not passed to user space by these functions
3820 ieee80211_rx_h_remove_qos_control
,
3821 ieee80211_rx_h_802_1x_pae
,
3822 ieee80211_rx_h_drop_unencrypted
,
3823 ieee80211_rx_h_data
,
3824 ieee80211_rx_h_mgmt
,
3828 static ieee80211_tx_handler ieee80211_tx_handlers
[] =
3830 ieee80211_tx_h_rate_limit
,
3831 ieee80211_tx_h_check_assoc
,
3832 ieee80211_tx_h_ps_buf
,
3833 ieee80211_tx_h_select_key
,
3834 ieee80211_tx_h_michael_mic_add
,
3835 ieee80211_tx_h_fragment
,
3836 ieee80211_tx_h_tkip_encrypt
,
3837 ieee80211_tx_h_ccmp_encrypt
,
3838 ieee80211_tx_h_wep_encrypt
,
3839 ieee80211_tx_h_rate_ctrl
,
3840 ieee80211_tx_h_misc
,
3841 ieee80211_tx_h_load_stats
,
3846 static void ieee80211_if_sdata_init(struct ieee80211_sub_if_data
*sdata
)
3848 /* Default values for sub-interface parameters */
3849 sdata
->drop_unencrypted
= 0;
3854 static struct net_device
*ieee80211_if_add(struct net_device
*dev
,
3855 char *name
, int locked
)
3857 struct net_device
*wds_dev
= NULL
, *tmp_dev
;
3858 struct ieee80211_local
*local
= dev
->priv
;
3859 struct ieee80211_sub_if_data
*sdata
= NULL
, *sdata_parent
;
3864 /* ensure 32-bit alignment of our private data and hw private data */
3865 alloc_size
= sizeof(struct net_device
) + 3 +
3866 sizeof(struct ieee80211_sub_if_data
) + 3;
3868 wds_dev
= (struct net_device
*) kmalloc(alloc_size
, GFP_KERNEL
);
3869 if (wds_dev
== NULL
)
3872 memset(wds_dev
, 0, alloc_size
);
3873 wds_dev
->priv
= local
;
3874 ether_setup(wds_dev
);
3875 if (strlen(name
) == 0) {
3878 sprintf(wds_dev
->name
, "%s.%d", dev
->name
, i
++);
3879 tmp_dev
= dev_get_by_name(wds_dev
->name
);
3880 if (tmp_dev
== NULL
)
3883 } while (i
< 10000);
3885 snprintf(wds_dev
->name
, IFNAMSIZ
, "%s", name
);
3888 memcpy(wds_dev
->dev_addr
, dev
->dev_addr
, ETH_ALEN
);
3889 wds_dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
3890 wds_dev
->do_ioctl
= ieee80211_ioctl
;
3891 wds_dev
->change_mtu
= ieee80211_change_mtu
;
3892 wds_dev
->tx_timeout
= ieee80211_tx_timeout
;
3893 wds_dev
->get_stats
= ieee80211_get_stats
;
3894 wds_dev
->open
= ieee80211_open
;
3895 wds_dev
->stop
= ieee80211_stop
;
3896 wds_dev
->base_addr
= dev
->base_addr
;
3897 wds_dev
->irq
= dev
->irq
;
3898 wds_dev
->mem_start
= dev
->mem_start
;
3899 wds_dev
->mem_end
= dev
->mem_end
;
3900 wds_dev
->tx_queue_len
= 0;
3902 sdata
= IEEE80211_DEV_TO_SUB_IF(wds_dev
);
3903 sdata
->type
= IEEE80211_SUB_IF_TYPE_NORM
;
3904 sdata
->master
= local
->mdev
;
3905 sdata
->dev
= wds_dev
;
3906 sdata
->local
= local
;
3907 memset(&sdata
->stats
, 0, sizeof(struct net_device_stats
));
3908 sdata_parent
= IEEE80211_DEV_TO_SUB_IF(dev
);
3909 if (sdata_parent
->type
== IEEE80211_SUB_IF_TYPE_NORM
)
3910 sdata
->bss
= &sdata_parent
->u
.norm
;
3912 printk(KERN_DEBUG
"%s: could not set BSS pointer for new "
3913 "interface %s\n", dev
->name
, wds_dev
->name
);
3915 ieee80211_if_sdata_init(sdata
);
3918 ret
= register_netdevice(wds_dev
);
3920 ret
= register_netdev(wds_dev
);
3926 list_add(&sdata
->list
, &local
->sub_if_list
);
3928 strcpy(name
, wds_dev
->name
);
3934 int ieee80211_if_add_wds(struct net_device
*dev
, char *name
,
3935 struct ieee80211_if_wds
*wds
, int locked
)
3937 struct net_device
*wds_dev
= NULL
;
3938 struct ieee80211_sub_if_data
*sdata
= NULL
;
3940 if (strlen(name
) != 0) {
3941 wds_dev
= dev_get_by_name(name
);
3948 wds_dev
= ieee80211_if_add(dev
, name
, locked
);
3949 if (wds_dev
== NULL
)
3952 sdata
= IEEE80211_DEV_TO_SUB_IF(wds_dev
);
3953 sdata
->type
= IEEE80211_SUB_IF_TYPE_WDS
;
3954 memcpy(&sdata
->u
.wds
, wds
, sizeof(struct ieee80211_if_wds
));
3956 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
3958 "%s: Added WDS Link to " MACSTR
"\n",
3959 wds_dev
->name
, MAC2STR(sdata
->u
.wds
.remote_addr
));
3960 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
3963 ieee80211_proc_init_virtual(wds_dev
);
3969 int ieee80211_if_update_wds(struct net_device
*dev
, char *name
,
3970 struct ieee80211_if_wds
*wds
, int locked
)
3972 struct net_device
*wds_dev
= NULL
;
3973 struct ieee80211_local
*local
= dev
->priv
;
3974 struct ieee80211_sub_if_data
*sdata
= NULL
;
3975 struct sta_info
*sta
;
3976 struct list_head
*ptr
;
3978 list_for_each(ptr
, &local
->sub_if_list
) {
3979 sdata
= list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
3980 if (strcmp(name
, sdata
->dev
->name
) == 0) {
3981 wds_dev
= sdata
->dev
;
3986 if (wds_dev
== NULL
|| sdata
->type
!= IEEE80211_SUB_IF_TYPE_WDS
)
3989 /* Remove STA entry for the old peer */
3990 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
3992 sta_info_release(local
, sta
);
3993 sta_info_free(local
, sta
, 0);
3995 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
3996 "%s peer " MACSTR
"\n",
3997 dev
->name
, wds_dev
->name
,
3998 MAC2STR(sdata
->u
.wds
.remote_addr
));
4001 /* Update WDS link data */
4002 memcpy(&sdata
->u
.wds
, wds
, sizeof(struct ieee80211_if_wds
));
4009 static void ieee80211_if_init(struct net_device
*dev
)
4011 struct ieee80211_local
*local
= dev
->priv
;
4013 spin_lock_init(&local
->sub_if_lock
);
4014 INIT_LIST_HEAD(&local
->sub_if_list
);
4019 int ieee80211_if_add_vlan(struct net_device
*dev
,
4021 struct ieee80211_if_vlan
*vlan
,
4024 struct net_device
*vlan_dev
= NULL
;
4025 struct ieee80211_sub_if_data
*sdata
= NULL
;
4027 if (strlen(name
) != 0) {
4028 vlan_dev
= dev_get_by_name(name
);
4035 vlan_dev
= ieee80211_if_add(dev
, name
, locked
);
4036 if (vlan_dev
== NULL
)
4039 sdata
= IEEE80211_DEV_TO_SUB_IF(vlan_dev
);
4040 sdata
->type
= IEEE80211_SUB_IF_TYPE_VLAN
;
4041 ieee80211_proc_init_virtual(vlan_dev
);
4046 static void ieee80211_if_norm_init(struct ieee80211_sub_if_data
*sdata
)
4048 sdata
->type
= IEEE80211_SUB_IF_TYPE_NORM
;
4049 sdata
->u
.norm
.dtim_period
= 2;
4050 sdata
->u
.norm
.force_unicast_rateidx
= -1;
4051 sdata
->u
.norm
.max_ratectrl_rateidx
= -1;
4052 skb_queue_head_init(&sdata
->u
.norm
.ps_bc_buf
);
4053 sdata
->bss
= &sdata
->u
.norm
;
4057 int ieee80211_if_add_norm(struct net_device
*dev
, char *name
, u8
*bssid
,
4060 struct ieee80211_local
*local
= dev
->priv
;
4061 struct net_device
*norm_dev
= NULL
;
4062 struct ieee80211_sub_if_data
*sdata
= NULL
;
4064 if (local
->bss_dev_count
>= local
->conf
.bss_count
)
4067 if (strlen(name
) != 0) {
4068 norm_dev
= dev_get_by_name(name
);
4075 norm_dev
= ieee80211_if_add(dev
, name
, locked
);
4076 if (norm_dev
== NULL
)
4079 memcpy(norm_dev
->dev_addr
, bssid
, ETH_ALEN
);
4080 sdata
= IEEE80211_DEV_TO_SUB_IF(norm_dev
);
4081 ieee80211_if_norm_init(sdata
);
4082 ieee80211_proc_init_virtual(norm_dev
);
4083 spin_lock_bh(&local
->sub_if_lock
);
4084 local
->bss_devs
[local
->bss_dev_count
] = norm_dev
;
4085 local
->bss_dev_count
++;
4086 spin_unlock_bh(&local
->sub_if_lock
);
4092 static void ieee80211_addr_inc(u8
*addr
)
4104 int ieee80211_if_add_sta(struct net_device
*dev
, char *name
, int locked
)
4106 struct ieee80211_local
*local
= dev
->priv
;
4107 struct net_device
*sta_dev
;
4108 struct ieee80211_sub_if_data
*sdata
;
4109 struct ieee80211_if_sta
*ifsta
;
4112 if (local
->sta_dev_count
>= local
->conf
.bss_count
)
4115 if (strlen(name
) != 0) {
4116 sta_dev
= dev_get_by_name(name
);
4123 sta_dev
= ieee80211_if_add(dev
, name
, locked
);
4124 if (sta_dev
== NULL
)
4127 sdata
= IEEE80211_DEV_TO_SUB_IF(sta_dev
);
4128 ifsta
= &sdata
->u
.sta
;
4129 sdata
->type
= IEEE80211_SUB_IF_TYPE_STA
;
4130 ieee80211_proc_init_virtual(sta_dev
);
4132 spin_lock_bh(&local
->sub_if_lock
);
4133 for (i
= 0; i
< local
->conf
.bss_count
; i
++) {
4134 if (local
->sta_devs
[i
] == NULL
) {
4135 local
->sta_devs
[i
] = sta_dev
;
4136 local
->sta_dev_count
++;
4137 printk(KERN_DEBUG
"%s: using STA entry %d\n",
4140 ieee80211_addr_inc(sta_dev
->dev_addr
);
4143 printk(KERN_DEBUG
"%s: MAC address " MACSTR
"\n",
4144 sta_dev
->name
, MAC2STR(sta_dev
->dev_addr
));
4148 spin_unlock_bh(&local
->sub_if_lock
);
4150 init_timer(&ifsta
->timer
);
4151 ifsta
->timer
.data
= (unsigned long) sta_dev
;
4152 ifsta
->timer
.function
= ieee80211_sta_timer
;
4154 ifsta
->capab
= WLAN_CAPABILITY_ESS
;
4155 ifsta
->auth_algs
= IEEE80211_AUTH_ALG_OPEN
|
4156 IEEE80211_AUTH_ALG_SHARED_KEY
;
4157 ifsta
->create_ibss
= 1;
4158 ifsta
->wmm_enabled
= 1;
4164 static void ieee80211_if_del(struct ieee80211_local
*local
,
4165 struct ieee80211_sub_if_data
*sdata
, int locked
)
4167 struct sta_info
*sta
;
4170 struct list_head
*ptr
, *n
;
4172 memset(addr
, 0xff, ETH_ALEN
);
4173 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
4174 if (!sdata
->keys
[i
])
4177 /* Low-level driver has probably disabled hw
4178 * already, so there is not really much point
4179 * in disabling the keys at this point. */
4180 if (local
->hw
->set_key
)
4181 local
->hw
->set_key(dev
, DISABLE_KEY
, addr
,
4184 kfree(sdata
->keys
[i
]);
4187 switch (sdata
->type
) {
4188 case IEEE80211_SUB_IF_TYPE_NORM
:
4189 /* Remove all virtual interfaces that use this BSS
4190 * as their sdata->bss */
4191 list_for_each_safe(ptr
, n
, &local
->sub_if_list
) {
4192 struct ieee80211_sub_if_data
*tsdata
=
4193 list_entry(ptr
, struct ieee80211_sub_if_data
,
4196 if (tsdata
!= sdata
&& tsdata
->bss
== &sdata
->u
.norm
) {
4197 printk(KERN_DEBUG
"%s: removing virtual "
4198 "interface %s because its BSS interface"
4199 " is being removed\n",
4200 sdata
->dev
->name
, tsdata
->dev
->name
);
4201 ieee80211_if_del(local
, tsdata
, locked
);
4205 kfree(sdata
->u
.norm
.beacon_head
);
4206 kfree(sdata
->u
.norm
.beacon_tail
);
4207 spin_lock_bh(&local
->sub_if_lock
);
4208 for (j
= 0; j
< local
->bss_dev_count
; j
++) {
4209 if (sdata
->dev
== local
->bss_devs
[j
]) {
4210 if (j
+ 1 < local
->bss_dev_count
) {
4211 memcpy(&local
->bss_devs
[j
],
4212 &local
->bss_devs
[j
+ 1],
4213 (local
->bss_dev_count
- j
- 1) *
4214 sizeof(local
->bss_devs
[0]));
4215 local
->bss_devs
[local
->bss_dev_count
-
4218 local
->bss_devs
[j
] = NULL
;
4219 local
->bss_dev_count
--;
4223 spin_unlock_bh(&local
->sub_if_lock
);
4225 if (sdata
->dev
!= local
->mdev
) {
4226 struct sk_buff
*skb
;
4227 while ((skb
= skb_dequeue(&sdata
->u
.norm
.ps_bc_buf
))) {
4228 local
->total_ps_buffered
--;
4234 case IEEE80211_SUB_IF_TYPE_WDS
:
4235 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
4237 sta_info_release(local
, sta
);
4238 sta_info_free(local
, sta
, 0);
4240 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
4241 printk(KERN_DEBUG
"%s: Someone had deleted my STA "
4242 "entry for the WDS link\n", sdata
->dev
->name
);
4243 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
4246 case IEEE80211_SUB_IF_TYPE_STA
:
4247 del_timer_sync(&sdata
->u
.sta
.timer
);
4248 if (local
->scan_timer
.data
== (unsigned long) sdata
->dev
)
4249 del_timer_sync(&local
->scan_timer
);
4250 kfree(sdata
->u
.sta
.extra_ie
);
4251 sdata
->u
.sta
.extra_ie
= NULL
;
4252 kfree(sdata
->u
.sta
.assocreq_ies
);
4253 sdata
->u
.sta
.assocreq_ies
= NULL
;
4254 kfree(sdata
->u
.sta
.assocresp_ies
);
4255 sdata
->u
.sta
.assocresp_ies
= NULL
;
4256 if (sdata
->u
.sta
.probe_resp
) {
4257 dev_kfree_skb(sdata
->u
.sta
.probe_resp
);
4258 sdata
->u
.sta
.probe_resp
= NULL
;
4260 for (i
= 0; i
< local
->conf
.bss_count
; i
++) {
4261 if (local
->sta_devs
[i
] == sdata
->dev
) {
4262 local
->sta_devs
[i
] = NULL
;
4263 local
->sta_dev_count
--;
4271 /* remove all STAs that are bound to this virtual interface */
4272 sta_info_flush(local
, sdata
->dev
);
4274 list_del(&sdata
->list
);
4275 ieee80211_proc_deinit_virtual(sdata
->dev
);
4277 unregister_netdevice(sdata
->dev
);
4279 unregister_netdev(sdata
->dev
);
4280 /* Default data device and management device are allocated with the
4281 * master device. All other devices are separately allocated and will
4283 if (sdata
->dev
!= local
->mdev
&& sdata
->dev
!= local
->wdev
&&
4284 sdata
->dev
!= local
->apdev
)
4289 static int ieee80211_if_remove(struct net_device
*dev
, char *name
, int id
,
4292 struct ieee80211_local
*local
= dev
->priv
;
4293 struct list_head
*ptr
, *n
;
4295 /* Make sure not to touch sdata->master since it may
4296 * have already been deleted, etc. */
4298 list_for_each_safe(ptr
, n
, &local
->sub_if_list
) {
4299 struct ieee80211_sub_if_data
*sdata
=
4300 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
4302 if (sdata
->type
== id
&& strcmp(name
, sdata
->dev
->name
) == 0) {
4303 ieee80211_if_del(local
, sdata
, locked
);
4312 int ieee80211_if_remove_wds(struct net_device
*dev
, char *name
, int locked
)
4314 return ieee80211_if_remove(dev
, name
, IEEE80211_SUB_IF_TYPE_WDS
,
4319 int ieee80211_if_remove_vlan(struct net_device
*dev
, char *name
, int locked
)
4321 return ieee80211_if_remove(dev
, name
, IEEE80211_SUB_IF_TYPE_VLAN
,
4326 int ieee80211_if_remove_norm(struct net_device
*dev
, char *name
, int locked
)
4328 return ieee80211_if_remove(dev
, name
, IEEE80211_SUB_IF_TYPE_NORM
,
4333 int ieee80211_if_remove_sta(struct net_device
*dev
, char *name
, int locked
)
4335 return ieee80211_if_remove(dev
, name
, IEEE80211_SUB_IF_TYPE_STA
,
4340 int ieee80211_if_flush(struct net_device
*dev
, int locked
)
4342 struct ieee80211_local
*local
= dev
->priv
;
4343 struct list_head
*ptr
, *n
;
4345 list_for_each_safe(ptr
, n
, &local
->sub_if_list
) {
4346 struct ieee80211_sub_if_data
*sdata
=
4347 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
4349 if (sdata
->dev
!= local
->mdev
&&
4350 sdata
->dev
!= local
->wdev
&&
4351 sdata
->dev
!= local
->apdev
)
4352 ieee80211_if_del(local
, sdata
, locked
);
4359 static void ieee80211_precalc_rates(struct ieee80211_hw
*hw
)
4361 struct ieee80211_hw_modes
*mode
;
4362 struct ieee80211_rate
*rate
;
4365 for (m
= 0; m
< hw
->num_modes
; m
++) {
4366 mode
= &hw
->modes
[m
];
4367 for (r
= 0; r
< mode
->num_rates
; r
++) {
4368 rate
= &mode
->rates
[r
];
4369 rate
->rate_inv
= CHAN_UTIL_RATE_LCM
/ rate
->rate
;
4375 struct net_device
*ieee80211_alloc_hw(size_t priv_data_len
,
4376 void (*setup
)(struct net_device
*))
4378 struct net_device
*dev
, *apdev
, *mdev
;
4379 struct ieee80211_local
*local
;
4380 struct ieee80211_sub_if_data
*sdata
;
4383 /* Ensure 32-bit alignment of our private data and hw private data.
4384 * Each net_device is followed by a sub_if_data which which is used
4385 * for wds/vlan information; it is aligned as well.
4387 * Sample memory map looks something like:
4389 * 0000 *****************
4391 * 015c *****************
4393 * 017c *****************
4395 * 0b84 *****************
4397 * 1664 *****************
4399 * 17c0 *****************
4407 alloc_size
= sizeof(struct net_device
) +
4408 sizeof(struct ieee80211_sub_if_data
) + 3 +
4409 sizeof(struct ieee80211_local
) + 3 +
4411 sizeof(struct net_device
) + 3 +
4412 sizeof(struct ieee80211_sub_if_data
) + 3 +
4413 sizeof(struct net_device
) + 3 +
4414 sizeof(struct ieee80211_sub_if_data
) + 3 +
4416 mdev
= (struct net_device
*) kzalloc(alloc_size
, GFP_KERNEL
);
4420 mdev
->priv
= (struct net_device
*)
4422 sizeof(struct net_device
) +
4423 sizeof(struct ieee80211_sub_if_data
) + 3)
4426 local
->hw_priv
= (void *)
4427 (((long) local
+ sizeof(struct ieee80211_local
) + 3) & ~3);
4428 apdev
= (struct net_device
*)
4429 (((long) local
->hw_priv
+ priv_data_len
+ 3) & ~3);
4430 dev
= (struct net_device
*)
4432 sizeof(struct net_device
) +
4433 sizeof(struct ieee80211_sub_if_data
) + 3)
4438 memcpy(dev
->name
, "wlan%d", 7);
4440 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
4441 dev
->do_ioctl
= ieee80211_ioctl
;
4442 dev
->change_mtu
= ieee80211_change_mtu
;
4443 dev
->tx_timeout
= ieee80211_tx_timeout
;
4444 dev
->get_stats
= ieee80211_get_stats
;
4445 dev
->open
= ieee80211_open
;
4446 dev
->stop
= ieee80211_stop
;
4447 dev
->tx_queue_len
= 0;
4448 dev
->set_mac_address
= ieee80211_set_mac_address
;
4452 local
->rx_handlers
= ieee80211_rx_handlers
;
4453 local
->tx_handlers
= ieee80211_tx_handlers
;
4455 local
->bridge_packets
= 1;
4457 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
4458 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
4459 local
->short_retry_limit
= 7;
4460 local
->long_retry_limit
= 4;
4461 local
->conf
.calib_int
= 60;
4462 local
->rate_ctrl_num_up
= RATE_CONTROL_NUM_UP
;
4463 local
->rate_ctrl_num_down
= RATE_CONTROL_NUM_DOWN
;
4464 local
->conf
.bss_count
= 1;
4465 memset(local
->conf
.bssid_mask
, 0xff, ETH_ALEN
);
4466 local
->bss_devs
= kmalloc(sizeof(struct net_device
*), GFP_KERNEL
);
4467 if (local
->bss_devs
== NULL
)
4469 local
->bss_devs
[0] = local
->wdev
;
4470 local
->bss_dev_count
= 1;
4471 local
->sta_devs
= kmalloc(sizeof(struct net_device
*), GFP_KERNEL
);
4472 if (local
->sta_devs
== NULL
)
4474 local
->sta_devs
[0] = NULL
;
4476 local
->scan
.in_scan
= 0;
4477 local
->hw_modes
= (unsigned int) -1;
4479 init_timer(&local
->scan
.timer
); /* clear it out */
4481 spin_lock_init(&local
->generic_lock
);
4482 init_timer(&local
->rate_limit_timer
);
4483 local
->rate_limit_timer
.function
= ieee80211_rate_limit
;
4484 local
->rate_limit_timer
.data
= (unsigned long) local
;
4485 init_timer(&local
->stat_timer
);
4486 local
->stat_timer
.function
= ieee80211_stat_refresh
;
4487 local
->stat_timer
.data
= (unsigned long) local
;
4488 ieee80211_rx_bss_list_init(dev
);
4490 sta_info_init(local
);
4492 ieee80211_if_init(dev
);
4494 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4496 sdata
->master
= mdev
;
4497 sdata
->local
= local
;
4498 ieee80211_if_sdata_init(sdata
);
4499 ieee80211_if_norm_init(sdata
);
4500 list_add_tail(&sdata
->list
, &local
->sub_if_list
);
4502 if (strlen(dev
->name
) + 2 >= sizeof(dev
->name
))
4505 apdev
= (struct net_device
*)
4506 (((long) local
->hw_priv
+ priv_data_len
+ 3) & ~3);
4507 local
->apdev
= apdev
;
4509 apdev
->priv
= local
;
4510 apdev
->hard_start_xmit
= ieee80211_mgmt_start_xmit
;
4511 apdev
->change_mtu
= ieee80211_change_mtu_apdev
;
4512 apdev
->get_stats
= ieee80211_get_stats
;
4513 apdev
->open
= ieee80211_open
;
4514 apdev
->stop
= ieee80211_stop
;
4515 apdev
->type
= ARPHRD_IEEE80211_PRISM
;
4516 apdev
->hard_header_parse
= header_parse_80211
;
4517 apdev
->tx_queue_len
= 0;
4518 sprintf(apdev
->name
, "%sap", dev
->name
);
4520 sdata
= IEEE80211_DEV_TO_SUB_IF(apdev
);
4521 sdata
->type
= IEEE80211_SUB_IF_TYPE_MGMT
;
4523 sdata
->master
= mdev
;
4524 sdata
->local
= local
;
4525 list_add_tail(&sdata
->list
, &local
->sub_if_list
);
4528 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
4529 mdev
->do_ioctl
= ieee80211_ioctl
;
4530 mdev
->change_mtu
= ieee80211_change_mtu
;
4531 mdev
->tx_timeout
= ieee80211_tx_timeout
;
4532 mdev
->get_stats
= ieee80211_get_stats
;
4533 mdev
->open
= ieee80211_open
;
4534 mdev
->stop
= ieee80211_stop
;
4535 mdev
->type
= ARPHRD_IEEE80211
;
4536 mdev
->hard_header_parse
= header_parse_80211
;
4537 sprintf(mdev
->name
, "%s.11", dev
->name
);
4539 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
4540 sdata
->type
= IEEE80211_SUB_IF_TYPE_NORM
;
4542 sdata
->master
= mdev
;
4543 sdata
->local
= local
;
4544 list_add_tail(&sdata
->list
, &local
->sub_if_list
);
4546 tasklet_init(&local
->tasklet
,
4547 ieee80211_tasklet_handler
,
4548 (unsigned long) local
);
4549 skb_queue_head_init(&local
->skb_queue
);
4550 skb_queue_head_init(&local
->skb_queue_unreliable
);
4558 ieee80211_free_hw(mdev
);
4562 int ieee80211_register_hw(struct net_device
*dev
, struct ieee80211_hw
*hw
)
4564 struct ieee80211_local
*local
= dev
->priv
;
4570 if (hw
->version
!= IEEE80211_VERSION
) {
4571 printk("ieee80211_register_hw - version mismatch: 80211.o "
4572 "version %d, low-level driver version %d\n",
4573 IEEE80211_VERSION
, hw
->version
);
4577 local
->conf
.mode
= IW_MODE_MASTER
;
4578 local
->conf
.beacon_int
= 1000;
4580 ieee80211_update_hw(dev
, hw
); /* Don't care about the result. */
4582 sta_info_start(local
);
4584 result
= register_netdev(local
->wdev
);
4588 result
= register_netdev(local
->apdev
);
4593 dev
->features
|= NETIF_F_FRAGLIST
;
4594 result
= register_netdev(dev
);
4598 if (rate_control_initialize(local
) < 0) {
4599 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
4600 "algorithm\n", dev
->name
);
4604 /* TODO: add rtnl locking around device creation and qdisc install */
4605 ieee80211_install_qdisc(dev
);
4607 ieee80211_wep_init(local
);
4608 ieee80211_proc_init_interface(local
);
4612 unregister_netdev(dev
);
4614 unregister_netdev(local
->apdev
);
4616 unregister_netdev(local
->wdev
);
4617 sta_info_stop(local
);
4621 int ieee80211_update_hw(struct net_device
*dev
, struct ieee80211_hw
*hw
)
4623 struct ieee80211_local
*local
= dev
->priv
;
4627 /* Backwards compatibility for low-level drivers that do not set number
4629 if (hw
->queues
== 0)
4632 memcpy(local
->apdev
->dev_addr
, dev
->dev_addr
, ETH_ALEN
);
4633 local
->apdev
->base_addr
= dev
->base_addr
;
4634 local
->apdev
->irq
= dev
->irq
;
4635 local
->apdev
->mem_start
= dev
->mem_start
;
4636 local
->apdev
->mem_end
= dev
->mem_end
;
4638 memcpy(local
->wdev
->dev_addr
, dev
->dev_addr
, ETH_ALEN
);
4639 local
->wdev
->base_addr
= dev
->base_addr
;
4640 local
->wdev
->irq
= dev
->irq
;
4641 local
->wdev
->mem_start
= dev
->mem_start
;
4642 local
->wdev
->mem_end
= dev
->mem_end
;
4644 if (!hw
->modes
|| !hw
->modes
->channels
|| !hw
->modes
->rates
||
4645 !hw
->modes
->num_channels
|| !hw
->modes
->num_rates
)
4648 ieee80211_precalc_rates(hw
);
4649 local
->conf
.phymode
= hw
->modes
[0].mode
;
4650 local
->curr_rates
= hw
->modes
[0].rates
;
4651 local
->num_curr_rates
= hw
->modes
[0].num_rates
;
4652 ieee80211_prepare_rates(dev
);
4654 local
->conf
.freq
= local
->hw
->modes
[0].channels
[0].freq
;
4655 local
->conf
.channel
= local
->hw
->modes
[0].channels
[0].chan
;
4656 local
->conf
.channel_val
= local
->hw
->modes
[0].channels
[0].val
;
4657 /* FIXME: Invoke config to allow driver to set the channel. */
4662 void ieee80211_unregister_hw(struct net_device
*dev
)
4664 struct ieee80211_local
*local
= dev
->priv
;
4665 struct list_head
*ptr
, *n
;
4668 tasklet_disable(&local
->tasklet
);
4669 /* TODO: skb_queue should be empty here, no need to do anything? */
4671 if (local
->rate_limit
)
4672 del_timer_sync(&local
->rate_limit_timer
);
4673 if (local
->stat_time
)
4674 del_timer_sync(&local
->stat_timer
);
4675 if (local
->scan_timer
.data
)
4676 del_timer_sync(&local
->scan_timer
);
4677 ieee80211_rx_bss_list_deinit(dev
);
4679 list_for_each_safe(ptr
, n
, &local
->sub_if_list
) {
4680 struct ieee80211_sub_if_data
*sdata
=
4681 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
4682 ieee80211_if_del(local
, sdata
, 0);
4685 sta_info_stop(local
);
4687 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++)
4688 if (local
->fragments
[i
].skb
)
4689 dev_kfree_skb(local
->fragments
[i
].skb
);
4691 for (i
= 0; i
< NUM_IEEE80211_MODES
; i
++) {
4692 kfree(local
->supp_rates
[i
]);
4693 kfree(local
->basic_rates
[i
]);
4696 kfree(local
->conf
.ssid
);
4697 kfree(local
->conf
.generic_elem
);
4699 ieee80211_proc_deinit_interface(local
);
4701 skb_queue_purge(&local
->skb_queue
);
4702 skb_queue_purge(&local
->skb_queue_unreliable
);
4704 rate_control_free(local
);
4707 void ieee80211_free_hw(struct net_device
*dev
)
4709 struct ieee80211_local
*local
= dev
->priv
;
4711 kfree(local
->sta_devs
);
4712 kfree(local
->bss_devs
);
4716 /* Perform netif operations on all configured interfaces */
4717 int ieee80211_netif_oper(struct net_device
*sdev
, Netif_Oper op
)
4719 struct ieee80211_local
*local
= sdev
->priv
;
4720 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(sdev
);
4721 struct net_device
*dev
= sdata
->master
;
4725 netif_device_attach(dev
);
4728 netif_device_detach(dev
);
4731 netif_start_queue(dev
);
4736 if (local
->scan
.in_scan
== 0) {
4737 netif_wake_queue(dev
);
4739 if (/* FIX: 802.11 qdisc in use */ 1)
4740 __netif_schedule(dev
);
4744 case NETIF_IS_STOPPED
:
4745 if (netif_queue_stopped(dev
))
4748 case NETIF_UPDATE_TX_START
:
4749 dev
->trans_start
= jiffies
;
4757 void * ieee80211_dev_hw_data(struct net_device
*dev
)
4759 struct ieee80211_local
*local
= dev
->priv
;
4760 return local
->hw_priv
;
4764 void * ieee80211_dev_stats(struct net_device
*dev
)
4766 struct ieee80211_sub_if_data
*sdata
;
4767 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4768 return &(sdata
->stats
);
4772 int ieee80211_rate_control_register(struct rate_control_ops
*ops
)
4774 struct rate_control_algs
*alg
;
4776 alg
= kmalloc(sizeof(*alg
), GFP_KERNEL
);
4780 memset(alg
, 0, sizeof(*alg
));
4781 alg
->next
= ieee80211_rate_ctrl_algs
;
4783 ieee80211_rate_ctrl_algs
= alg
;
4789 void ieee80211_rate_control_unregister(struct rate_control_ops
*ops
)
4791 struct rate_control_algs
*alg
, *prev
;
4794 alg
= ieee80211_rate_ctrl_algs
;
4796 if (alg
->ops
== ops
) {
4798 prev
->next
= alg
->next
;
4800 ieee80211_rate_ctrl_algs
= alg
->next
;
4810 static int rate_control_initialize(struct ieee80211_local
*local
)
4812 struct rate_control_algs
*algs
;
4813 for (algs
= ieee80211_rate_ctrl_algs
; algs
; algs
= algs
->next
) {
4814 local
->rate_ctrl
= algs
->ops
;
4815 local
->rate_ctrl_priv
= rate_control_alloc(local
);
4816 if (local
->rate_ctrl_priv
) {
4817 printk(KERN_DEBUG
"%s: Selected rate control "
4818 "algorithm '%s'\n", local
->wdev
->name
,
4819 local
->rate_ctrl
->name
);
4824 printk(KERN_WARNING
"%s: Failed to select rate control algorithm\n",
4830 static int __init
ieee80211_init(void)
4832 struct sk_buff
*skb
;
4833 if (sizeof(struct ieee80211_tx_packet_data
) > (sizeof(skb
->cb
))) {
4834 printk("80211: ieee80211_tx_packet_data is bigger "
4835 "than the skb->cb (%d > %d)\n",
4836 (int) sizeof(struct ieee80211_tx_packet_data
),
4837 (int) sizeof(skb
->cb
));
4840 if (sizeof(struct ieee80211_rx_status
) > sizeof(skb
->cb
)) {
4841 printk("80211: ieee80211_rx_status is bigger "
4842 "than the skb->cb (%d > %d)\n",
4843 (int) sizeof(struct ieee80211_rx_status
),
4844 (int) sizeof(skb
->cb
));
4848 ieee80211_proc_init();
4850 int ret
= ieee80211_wme_register();
4852 printk(KERN_DEBUG
"ieee80211_init: failed to "
4853 "initialize WME (err=%d)\n", ret
);
4854 ieee80211_proc_deinit();
4863 static void __exit
ieee80211_exit(void)
4865 ieee80211_wme_unregister();
4866 ieee80211_proc_deinit();
4870 EXPORT_SYMBOL(ieee80211_alloc_hw
);
4871 EXPORT_SYMBOL(ieee80211_register_hw
);
4872 EXPORT_SYMBOL(ieee80211_update_hw
);
4873 EXPORT_SYMBOL(ieee80211_unregister_hw
);
4874 EXPORT_SYMBOL(ieee80211_free_hw
);
4875 EXPORT_SYMBOL(ieee80211_rx
);
4876 EXPORT_SYMBOL(ieee80211_tx_status
);
4877 EXPORT_SYMBOL(ieee80211_beacon_get
);
4878 EXPORT_SYMBOL(ieee80211_get_buffered_bc
);
4879 EXPORT_SYMBOL(ieee80211_netif_oper
);
4880 EXPORT_SYMBOL(ieee80211_dev_hw_data
);
4881 EXPORT_SYMBOL(ieee80211_dev_stats
);
4882 EXPORT_SYMBOL(ieee80211_get_hw_conf
);
4883 EXPORT_SYMBOL(ieee80211_set_aid_for_sta
);
4884 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);
4885 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
4886 EXPORT_SYMBOL(ieee80211_get_hdrlen
);
4887 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb
);
4888 EXPORT_SYMBOL(ieee80211_rate_control_register
);
4889 EXPORT_SYMBOL(ieee80211_rate_control_unregister
);
4890 EXPORT_SYMBOL(sta_info_get
);
4891 EXPORT_SYMBOL(sta_info_release
);
4892 EXPORT_SYMBOL(ieee80211_radar_status
);
4894 module_init(ieee80211_init
);
4895 module_exit(ieee80211_exit
);