1 /******************************************************************************
3 Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 The full GNU General Public License is included in this distribution in the
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************
27 Few modifications for Realtek's Wi-Fi drivers by
28 Andrea Merello <andreamrl@tiscali.it>
30 A special thanks goes to Realtek for their support !
32 ******************************************************************************/
34 #include <linux/compiler.h>
35 #include <linux/errno.h>
36 #include <linux/if_arp.h>
37 #include <linux/in6.h>
40 #include <linux/kernel.h>
41 #include <linux/module.h>
42 #include <linux/netdevice.h>
43 #include <linux/pci.h>
44 #include <linux/proc_fs.h>
45 #include <linux/skbuff.h>
46 #include <linux/slab.h>
47 #include <linux/tcp.h>
48 #include <linux/types.h>
49 #include <linux/version.h>
50 #include <linux/wireless.h>
51 #include <linux/etherdevice.h>
52 #include <asm/uaccess.h>
53 #include <linux/if_vlan.h>
63 802.11 frame_contorl for data frames - 2 bytes
64 ,-----------------------------------------------------------------------------------------.
65 bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e |
66 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
67 val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x | x | x |
68 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
69 desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep |
70 | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | |
71 '-----------------------------------------------------------------------------------------'
75 ,--------- 'ctrl' expands to >-----------'
77 ,--'---,-------------------------------------------------------------.
78 Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
79 |------|------|---------|---------|---------|------|---------|------|
80 Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs |
81 | | tion | (BSSID) | | | ence | data | |
82 `--------------------------------------------------| |------'
83 Total: 28 non-data bytes `----.----'
85 .- 'Frame data' expands to <---------------------------'
88 ,---------------------------------------------------.
89 Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 |
90 |------|------|---------|----------|------|---------|
91 Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
92 | DSAP | SSAP | | | | Packet |
93 | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
94 `-----------------------------------------| |
95 Total: 8 non-data bytes `----.----'
97 .- 'IP Packet' expands, if WEP enabled, to <--'
100 ,-----------------------.
101 Bytes | 4 | 0-2296 | 4 |
102 |-----|-----------|-----|
103 Desc. | IV | Encrypted | ICV |
105 `-----------------------'
106 Total: 8 non-data bytes
109 802.3 Ethernet Data Frame
111 ,-----------------------------------------.
112 Bytes | 6 | 6 | 2 | Variable | 4 |
113 |-------|-------|------|-----------|------|
114 Desc. | Dest. | Source| Type | IP Packet | fcs |
116 `-----------------------------------------'
117 Total: 18 non-data bytes
119 In the event that fragmentation is required, the incoming payload is split into
120 N parts of size ieee->fts. The first fragment contains the SNAP header and the
121 remaining packets are just data.
123 If encryption is enabled, each fragment payload size is reduced by enough space
124 to add the prefix and postfix (IV and ICV totalling 8 bytes in the case of WEP)
125 So if you have 1500 bytes of payload with ieee->fts set to 500 without
126 encryption it will take 3 frames. With WEP it will take 4 frames as the
127 payload of each frame is reduced to 492 bytes.
133 * | ETHERNET HEADER ,-<-- PAYLOAD
134 * | | 14 bytes from skb->data
135 * | 2 bytes for Type --> ,T. | (sizeof ethhdr)
137 * |,-Dest.--. ,--Src.---. | | |
138 * | 6 bytes| | 6 bytes | | | |
141 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
144 * | | | | `T' <---- 2 bytes for Type
146 * | | '---SNAP--' <-------- 6 bytes for SNAP
148 * `-IV--' <-------------------- 4 bytes for IV (WEP)
154 static u8 P802_1H_OUI
[P80211_OUI_LEN
] = { 0x00, 0x00, 0xf8 };
155 static u8 RFC1042_OUI
[P80211_OUI_LEN
] = { 0x00, 0x00, 0x00 };
157 inline int rtllib_put_snap(u8
*data
, u16 h_proto
)
159 struct rtllib_snap_hdr
*snap
;
162 snap
= (struct rtllib_snap_hdr
*)data
;
167 if (h_proto
== 0x8137 || h_proto
== 0x80f3)
171 snap
->oui
[0] = oui
[0];
172 snap
->oui
[1] = oui
[1];
173 snap
->oui
[2] = oui
[2];
175 *(u16
*)(data
+ SNAP_SIZE
) = htons(h_proto
);
177 return SNAP_SIZE
+ sizeof(u16
);
180 int rtllib_encrypt_fragment(
181 struct rtllib_device
*ieee
,
182 struct sk_buff
*frag
,
185 struct rtllib_crypt_data
* crypt
= NULL
;
188 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
190 if (!(crypt
&& crypt
->ops
))
192 printk("=========>%s(), crypt is null\n", __func__
);
195 /* To encrypt, frame format is:
196 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */
198 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so
199 * call both MSDU and MPDU encryption functions from here. */
200 atomic_inc(&crypt
->refcnt
);
202 if (crypt
->ops
->encrypt_msdu
)
203 res
= crypt
->ops
->encrypt_msdu(frag
, hdr_len
, crypt
->priv
);
204 if (res
== 0 && crypt
->ops
->encrypt_mpdu
)
205 res
= crypt
->ops
->encrypt_mpdu(frag
, hdr_len
, crypt
->priv
);
207 atomic_dec(&crypt
->refcnt
);
209 printk(KERN_INFO
"%s: Encryption failed: len=%d.\n",
210 ieee
->dev
->name
, frag
->len
);
211 ieee
->ieee_stats
.tx_discards
++;
219 void rtllib_txb_free(struct rtllib_txb
*txb
) {
225 struct rtllib_txb
*rtllib_alloc_txb(int nr_frags
, int txb_size
,
228 struct rtllib_txb
*txb
;
231 sizeof(struct rtllib_txb
) + (sizeof(u8
*) * nr_frags
),
236 memset(txb
, 0, sizeof(struct rtllib_txb
));
237 txb
->nr_frags
= nr_frags
;
238 txb
->frag_size
= txb_size
;
240 for (i
= 0; i
< nr_frags
; i
++) {
241 txb
->fragments
[i
] = dev_alloc_skb(txb_size
);
242 if (unlikely(!txb
->fragments
[i
])) {
246 memset(txb
->fragments
[i
]->cb
, 0, sizeof(txb
->fragments
[i
]->cb
));
248 if (unlikely(i
!= nr_frags
)) {
250 dev_kfree_skb_any(txb
->fragments
[i
--]);
258 rtllib_classify(struct sk_buff
*skb
, u8 bIsAmsdu
)
263 eth
= (struct ethhdr
*)skb
->data
;
264 if (eth
->h_proto
!= htons(ETH_P_IP
))
267 RTLLIB_DEBUG_DATA(RTLLIB_DL_DATA
, skb
->data
, skb
->len
);
269 switch (ip
->tos
& 0xfc) {
289 #define SN_LESS(a, b) (((a-b)&0x800)!=0)
290 void rtllib_tx_query_agg_cap(struct rtllib_device
* ieee
, struct sk_buff
* skb
, struct cb_desc
* tcb_desc
)
292 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
293 struct tx_ts_record
*pTxTs
= NULL
;
294 struct rtllib_hdr_1addr
* hdr
= (struct rtllib_hdr_1addr
*)skb
->data
;
296 if (rtllib_act_scanning(ieee
,false))
299 if (!pHTInfo
->bCurrentHTSupport
||!pHTInfo
->bEnableHT
)
301 if (!IsQoSDataFrame(skb
->data
))
303 if (is_multicast_ether_addr(hdr
->addr1
) || is_broadcast_ether_addr(hdr
->addr1
))
306 if (tcb_desc
->bdhcp
|| ieee
->CntAfterLink
<2)
309 if (pHTInfo
->IOTAction
& HT_IOT_ACT_TX_NO_AGGREGATION
)
312 if (!ieee
->GetNmodeSupportBySecCfg(ieee
->dev
))
314 if (pHTInfo
->bCurrentAMPDUEnable
){
315 if (!GetTs(ieee
, (struct ts_common_info
**)(&pTxTs
), hdr
->addr1
, skb
->priority
, TX_DIR
, true)){
316 printk("%s: can't get TS\n", __func__
);
319 if (pTxTs
->TxAdmittedBARecord
.bValid
== false){
320 if (ieee
->wpa_ie_len
&& (ieee
->pairwise_key_type
== KEY_TYPE_NA
)) {
322 } else if (tcb_desc
->bdhcp
== 1){
324 } else if (!pTxTs
->bDisable_AddBa
){
325 TsStartAddBaProcess(ieee
, pTxTs
);
327 goto FORCED_AGG_SETTING
;
328 } else if (pTxTs
->bUsingBa
== false) {
329 if (SN_LESS(pTxTs
->TxAdmittedBARecord
.BaStartSeqCtrl
.field
.SeqNum
, (pTxTs
->TxCurSeq
+1)%4096))
330 pTxTs
->bUsingBa
= true;
332 goto FORCED_AGG_SETTING
;
334 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
335 tcb_desc
->bAMPDUEnable
= true;
336 tcb_desc
->ampdu_factor
= pHTInfo
->CurrentAMPDUFactor
;
337 tcb_desc
->ampdu_density
= pHTInfo
->CurrentMPDUDensity
;
341 switch (pHTInfo
->ForcedAMPDUMode
) {
345 case HT_AGG_FORCE_ENABLE
:
346 tcb_desc
->bAMPDUEnable
= true;
347 tcb_desc
->ampdu_density
= pHTInfo
->ForcedMPDUDensity
;
348 tcb_desc
->ampdu_factor
= pHTInfo
->ForcedAMPDUFactor
;
351 case HT_AGG_FORCE_DISABLE
:
352 tcb_desc
->bAMPDUEnable
= false;
353 tcb_desc
->ampdu_density
= 0;
354 tcb_desc
->ampdu_factor
= 0;
361 extern void rtllib_qurey_ShortPreambleMode(struct rtllib_device
* ieee
, struct cb_desc
* tcb_desc
)
363 tcb_desc
->bUseShortPreamble
= false;
364 if (tcb_desc
->data_rate
== 2)
368 else if (ieee
->current_network
.capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
370 tcb_desc
->bUseShortPreamble
= true;
376 rtllib_query_HTCapShortGI(struct rtllib_device
*ieee
, struct cb_desc
*tcb_desc
)
378 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
380 tcb_desc
->bUseShortGI
= false;
382 if (!pHTInfo
->bCurrentHTSupport
||!pHTInfo
->bEnableHT
)
385 if (pHTInfo
->bForcedShortGI
)
387 tcb_desc
->bUseShortGI
= true;
391 if ((pHTInfo
->bCurBW40MHz
==true) && pHTInfo
->bCurShortGI40MHz
)
392 tcb_desc
->bUseShortGI
= true;
393 else if ((pHTInfo
->bCurBW40MHz
==false) && pHTInfo
->bCurShortGI20MHz
)
394 tcb_desc
->bUseShortGI
= true;
397 void rtllib_query_BandwidthMode(struct rtllib_device
* ieee
, struct cb_desc
*tcb_desc
)
399 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
401 tcb_desc
->bPacketBW
= false;
403 if (!pHTInfo
->bCurrentHTSupport
||!pHTInfo
->bEnableHT
)
406 if (tcb_desc
->bMulticast
|| tcb_desc
->bBroadcast
)
409 if ((tcb_desc
->data_rate
& 0x80)==0)
411 if (pHTInfo
->bCurBW40MHz
&& pHTInfo
->bCurTxBW40MHz
&& !ieee
->bandwidth_auto_switch
.bforced_tx20Mhz
)
412 tcb_desc
->bPacketBW
= true;
416 void rtllib_query_protectionmode(struct rtllib_device
* ieee
, struct cb_desc
* tcb_desc
, struct sk_buff
* skb
)
418 tcb_desc
->bRTSSTBC
= false;
419 tcb_desc
->bRTSUseShortGI
= false;
420 tcb_desc
->bCTSEnable
= false;
422 tcb_desc
->bRTSBW
= false;
424 if (tcb_desc
->bBroadcast
|| tcb_desc
->bMulticast
)
427 if (is_broadcast_ether_addr(skb
->data
+16))
430 if (ieee
->mode
< IEEE_N_24G
)
432 if (skb
->len
> ieee
->rts
)
434 tcb_desc
->bRTSEnable
= true;
435 tcb_desc
->rts_rate
= MGN_24M
;
437 else if (ieee
->current_network
.buseprotection
)
439 tcb_desc
->bRTSEnable
= true;
440 tcb_desc
->bCTSEnable
= true;
441 tcb_desc
->rts_rate
= MGN_24M
;
447 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
450 if (pHTInfo
->IOTAction
& HT_IOT_ACT_FORCED_CTS2SELF
)
452 tcb_desc
->bCTSEnable
= true;
453 tcb_desc
->rts_rate
= MGN_24M
;
454 tcb_desc
->bRTSEnable
= true;
457 else if (pHTInfo
->IOTAction
& (HT_IOT_ACT_FORCED_RTS
|HT_IOT_ACT_PURE_N_MODE
))
459 tcb_desc
->bRTSEnable
= true;
460 tcb_desc
->rts_rate
= MGN_24M
;
463 if (ieee
->current_network
.buseprotection
)
465 tcb_desc
->bRTSEnable
= true;
466 tcb_desc
->bCTSEnable
= true;
467 tcb_desc
->rts_rate
= MGN_24M
;
470 if (pHTInfo
->bCurrentHTSupport
&& pHTInfo
->bEnableHT
)
472 u8 HTOpMode
= pHTInfo
->CurrentOpMode
;
473 if ((pHTInfo
->bCurBW40MHz
&& (HTOpMode
== 2 || HTOpMode
== 3)) ||
474 (!pHTInfo
->bCurBW40MHz
&& HTOpMode
== 3) )
476 tcb_desc
->rts_rate
= MGN_24M
;
477 tcb_desc
->bRTSEnable
= true;
481 if (skb
->len
> ieee
->rts
)
483 tcb_desc
->rts_rate
= MGN_24M
;
484 tcb_desc
->bRTSEnable
= true;
487 if (tcb_desc
->bAMPDUEnable
)
489 tcb_desc
->rts_rate
= MGN_24M
;
490 tcb_desc
->bRTSEnable
= false;
498 tcb_desc
->bCTSEnable
= true;
499 tcb_desc
->rts_rate
= MGN_24M
;
500 tcb_desc
->bRTSEnable
= true;
502 if (ieee
->current_network
.capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
503 tcb_desc
->bUseShortPreamble
= true;
504 if (ieee
->iw_mode
== IW_MODE_MASTER
)
508 tcb_desc
->bRTSEnable
= false;
509 tcb_desc
->bCTSEnable
= false;
510 tcb_desc
->rts_rate
= 0;
512 tcb_desc
->bRTSBW
= false;
516 void rtllib_txrate_selectmode(struct rtllib_device
* ieee
, struct cb_desc
* tcb_desc
)
518 if (ieee
->bTxDisableRateFallBack
)
519 tcb_desc
->bTxDisableRateFallBack
= true;
521 if (ieee
->bTxUseDriverAssingedRate
)
522 tcb_desc
->bTxUseDriverAssingedRate
= true;
523 if (!tcb_desc
->bTxDisableRateFallBack
|| !tcb_desc
->bTxUseDriverAssingedRate
)
525 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
)
526 tcb_desc
->RATRIndex
= 0;
530 u16
rtllib_query_seqnum(struct rtllib_device
*ieee
, struct sk_buff
* skb
, u8
* dst
)
534 if (is_multicast_ether_addr(dst
) || is_broadcast_ether_addr(dst
))
536 if (IsQoSDataFrame(skb
->data
))
538 struct tx_ts_record
*pTS
= NULL
;
539 if (!GetTs(ieee
, (struct ts_common_info
**)(&pTS
), dst
, skb
->priority
, TX_DIR
, true))
543 seqnum
= pTS
->TxCurSeq
;
544 pTS
->TxCurSeq
= (pTS
->TxCurSeq
+1)%4096;
550 static int wme_downgrade_ac(struct sk_buff
*skb
)
552 switch (skb
->priority
) {
555 skb
->priority
= 5; /* VO -> VI */
559 skb
->priority
= 3; /* VI -> BE */
563 skb
->priority
= 1; /* BE -> BK */
570 int rtllib_xmit_inter(struct sk_buff
*skb
, struct net_device
*dev
)
572 struct rtllib_device
*ieee
= (struct rtllib_device
*)netdev_priv_rsl(dev
);
573 struct rtllib_txb
*txb
= NULL
;
574 struct rtllib_hdr_3addrqos
*frag_hdr
;
575 int i
, bytes_per_frag
, nr_frags
, bytes_last_frag
, frag_size
;
577 struct net_device_stats
*stats
= &ieee
->stats
;
578 int ether_type
= 0, encrypt
;
579 int bytes
, fc
, qos_ctl
= 0, hdr_len
;
580 struct sk_buff
*skb_frag
;
581 struct rtllib_hdr_3addrqos header
= { /* Ensure zero initialized */
586 u8 dest
[ETH_ALEN
], src
[ETH_ALEN
];
587 int qos_actived
= ieee
->current_network
.qos_data
.active
;
588 struct rtllib_crypt_data
* crypt
= NULL
;
589 struct cb_desc
*tcb_desc
;
590 u8 bIsMulticast
= false;
594 spin_lock_irqsave(&ieee
->lock
, flags
);
596 /* If there is no driver handler to take the TXB, dont' bother
598 if ((!ieee
->hard_start_xmit
&& !(ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
))||
599 ((!ieee
->softmac_data_hard_start_xmit
&& (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
)))) {
600 printk(KERN_WARNING
"%s: No xmit handler.\n",
606 if (likely(ieee
->raw_tx
== 0)){
607 if (unlikely(skb
->len
< SNAP_SIZE
+ sizeof(u16
))) {
608 printk(KERN_WARNING
"%s: skb too small (%d).\n",
609 ieee
->dev
->name
, skb
->len
);
612 /* Save source and destination addresses */
613 memcpy(dest
, skb
->data
, ETH_ALEN
);
614 memcpy(src
, skb
->data
+ETH_ALEN
, ETH_ALEN
);
616 memset(skb
->cb
, 0, sizeof(skb
->cb
));
617 ether_type
= ntohs(((struct ethhdr
*)skb
->data
)->h_proto
);
619 if (ieee
->iw_mode
== IW_MODE_MONITOR
)
621 txb
= rtllib_alloc_txb(1, skb
->len
, GFP_ATOMIC
);
622 if (unlikely(!txb
)) {
623 printk(KERN_WARNING
"%s: Could not allocate TXB\n",
629 txb
->payload_size
= skb
->len
;
630 memcpy(skb_put(txb
->fragments
[0],skb
->len
), skb
->data
, skb
->len
);
636 if (ETH_P_IP
== ether_type
) {
637 const struct iphdr
*ip
= (struct iphdr
*)((u8
*)skb
->data
+14);
638 if (IPPROTO_UDP
== ip
->protocol
) {
639 struct udphdr
*udp
= (struct udphdr
*)((u8
*)ip
+ (ip
->ihl
<< 2));
640 if (((((u8
*)udp
)[1] == 68) && (((u8
*)udp
)[3] == 67)) ||
641 ((((u8
*)udp
)[1] == 67) && (((u8
*)udp
)[3] == 68))) {
642 printk("DHCP pkt src port:%d, dest port:%d!!\n", ((u8
*)udp
)[1],((u8
*)udp
)[3]);
645 ieee
->LPSDelayCnt
= 200;
648 }else if (ETH_P_ARP
== ether_type
){
649 printk("=================>DHCP Protocol start tx ARP pkt!!\n");
651 ieee
->LPSDelayCnt
= ieee
->current_network
.tim
.tim_count
;
657 skb
->priority
= rtllib_classify(skb
, IsAmsdu
);
658 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
659 encrypt
= !(ether_type
== ETH_P_PAE
&& ieee
->ieee802_1x
) &&
660 ieee
->host_encrypt
&& crypt
&& crypt
->ops
;
661 if (!encrypt
&& ieee
->ieee802_1x
&&
662 ieee
->drop_unencrypted
&& ether_type
!= ETH_P_PAE
) {
666 if (crypt
&& !encrypt
&& ether_type
== ETH_P_PAE
) {
667 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
668 sizeof(struct ethhdr
) - SNAP_SIZE
- sizeof(u16
));
669 RTLLIB_DEBUG_EAP("TX: IEEE 802.11 EAPOL frame: %s\n",
670 eap_get_type(eap
->type
));
673 /* Advance the SKB to the start of the payload */
674 skb_pull(skb
, sizeof(struct ethhdr
));
676 /* Determine total amount of storage required for TXB packets */
677 bytes
= skb
->len
+ SNAP_SIZE
+ sizeof(u16
);
680 fc
= RTLLIB_FTYPE_DATA
| RTLLIB_FCTL_WEP
;
682 fc
= RTLLIB_FTYPE_DATA
;
685 fc
|= RTLLIB_STYPE_QOS_DATA
;
687 fc
|= RTLLIB_STYPE_DATA
;
689 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
690 fc
|= RTLLIB_FCTL_TODS
;
691 /* To DS: Addr1 = BSSID, Addr2 = SA,
693 memcpy(&header
.addr1
, ieee
->current_network
.bssid
, ETH_ALEN
);
694 memcpy(&header
.addr2
, &src
, ETH_ALEN
);
696 memcpy(&header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
698 memcpy(&header
.addr3
, &dest
, ETH_ALEN
);
699 } else if (ieee
->iw_mode
== IW_MODE_ADHOC
) {
700 /* not From/To DS: Addr1 = DA, Addr2 = SA,
702 memcpy(&header
.addr1
, dest
, ETH_ALEN
);
703 memcpy(&header
.addr2
, src
, ETH_ALEN
);
704 memcpy(&header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
707 bIsMulticast
= is_broadcast_ether_addr(header
.addr1
) ||is_multicast_ether_addr(header
.addr1
);
709 header
.frame_ctl
= cpu_to_le16(fc
);
711 /* Determine fragmentation size based on destination (multicast
712 * and broadcast are not fragmented) */
714 frag_size
= MAX_FRAG_THRESHOLD
;
715 qos_ctl
|= QOS_CTL_NOTCONTAIN_ACK
;
717 frag_size
= ieee
->fts
;
722 hdr_len
= RTLLIB_3ADDR_LEN
+ 2;
724 /* in case we are a client verify acm is not set for this ac */
725 while (unlikely(ieee
->wmm_acm
& (0x01 << skb
->priority
))) {
726 printk("skb->priority = %x\n", skb
->priority
);
727 if (wme_downgrade_ac(skb
)) {
730 printk("converted skb->priority = %x\n", skb
->priority
);
732 qos_ctl
|= skb
->priority
;
733 header
.qos_ctl
= cpu_to_le16(qos_ctl
& RTLLIB_QOS_TID
);
735 hdr_len
= RTLLIB_3ADDR_LEN
;
737 /* Determine amount of payload per fragment. Regardless of if
738 * this stack is providing the full 802.11 header, one will
739 * eventually be affixed to this fragment -- so we must account for
740 * it when determining the amount of payload space. */
741 bytes_per_frag
= frag_size
- hdr_len
;
743 (CFG_RTLLIB_COMPUTE_FCS
| CFG_RTLLIB_RESERVE_FCS
))
744 bytes_per_frag
-= RTLLIB_FCS_LEN
;
746 /* Each fragment may need to have room for encryptiong pre/postfix */
748 bytes_per_frag
-= crypt
->ops
->extra_prefix_len
+
749 crypt
->ops
->extra_postfix_len
;
751 /* Number of fragments is the total bytes_per_frag /
752 * payload_per_fragment */
753 nr_frags
= bytes
/ bytes_per_frag
;
754 bytes_last_frag
= bytes
% bytes_per_frag
;
758 bytes_last_frag
= bytes_per_frag
;
760 /* When we allocate the TXB we allocate enough space for the reserve
761 * and full fragment bytes (bytes_per_frag doesn't include prefix,
762 * postfix, header, FCS, etc.) */
763 txb
= rtllib_alloc_txb(nr_frags
, frag_size
+ ieee
->tx_headroom
, GFP_ATOMIC
);
764 if (unlikely(!txb
)) {
765 printk(KERN_WARNING
"%s: Could not allocate TXB\n",
769 txb
->encrypted
= encrypt
;
770 txb
->payload_size
= bytes
;
774 txb
->queue_index
= UP2AC(skb
->priority
);
776 txb
->queue_index
= WME_AC_BE
;;
779 for (i
= 0; i
< nr_frags
; i
++) {
780 skb_frag
= txb
->fragments
[i
];
781 tcb_desc
= (struct cb_desc
*)(skb_frag
->cb
+ MAX_DEV_ADDR_SIZE
);
783 skb_frag
->priority
= skb
->priority
;
784 tcb_desc
->queue_index
= UP2AC(skb
->priority
);
786 skb_frag
->priority
= WME_AC_BE
;
787 tcb_desc
->queue_index
= WME_AC_BE
;
789 skb_reserve(skb_frag
, ieee
->tx_headroom
);
792 if (ieee
->hwsec_active
)
793 tcb_desc
->bHwSec
= 1;
795 tcb_desc
->bHwSec
= 0;
796 skb_reserve(skb_frag
, crypt
->ops
->extra_prefix_len
);
798 tcb_desc
->bHwSec
= 0;
800 frag_hdr
= (struct rtllib_hdr_3addrqos
*)skb_put(skb_frag
, hdr_len
);
801 memcpy(frag_hdr
, &header
, hdr_len
);
803 /* If this is not the last fragment, then add the MOREFRAGS
804 * bit to the frame control */
805 if (i
!= nr_frags
- 1) {
806 frag_hdr
->frame_ctl
= cpu_to_le16(
807 fc
| RTLLIB_FCTL_MOREFRAGS
);
808 bytes
= bytes_per_frag
;
811 /* The last fragment takes the remaining length */
812 bytes
= bytes_last_frag
;
814 if ((qos_actived
) && (!bIsMulticast
))
816 frag_hdr
->seq_ctl
= rtllib_query_seqnum(ieee
, skb_frag
, header
.addr1
);
817 frag_hdr
->seq_ctl
= cpu_to_le16(frag_hdr
->seq_ctl
<<4 | i
);
819 frag_hdr
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0]<<4 | i
);
821 /* Put a SNAP header on the first fragment */
824 skb_put(skb_frag
, SNAP_SIZE
+ sizeof(u16
)),
826 bytes
-= SNAP_SIZE
+ sizeof(u16
);
829 memcpy(skb_put(skb_frag
, bytes
), skb
->data
, bytes
);
831 /* Advance the SKB... */
832 skb_pull(skb
, bytes
);
834 /* Encryption routine will move the header forward in order
835 * to insert the IV between the header and the payload */
837 rtllib_encrypt_fragment(ieee
, skb_frag
, hdr_len
);
839 (CFG_RTLLIB_COMPUTE_FCS
| CFG_RTLLIB_RESERVE_FCS
))
840 skb_put(skb_frag
, 4);
843 if ((qos_actived
) && (!bIsMulticast
)) {
844 if (ieee
->seq_ctrl
[UP2AC(skb
->priority
) + 1] == 0xFFF)
845 ieee
->seq_ctrl
[UP2AC(skb
->priority
) + 1] = 0;
847 ieee
->seq_ctrl
[UP2AC(skb
->priority
) + 1]++;
849 if (ieee
->seq_ctrl
[0] == 0xFFF)
850 ieee
->seq_ctrl
[0] = 0;
855 if (unlikely(skb
->len
< sizeof(struct rtllib_hdr_3addr
))) {
856 printk(KERN_WARNING
"%s: skb too small (%d).\n",
857 ieee
->dev
->name
, skb
->len
);
861 txb
= rtllib_alloc_txb(1, skb
->len
, GFP_ATOMIC
);
863 printk(KERN_WARNING
"%s: Could not allocate TXB\n",
869 txb
->payload_size
= skb
->len
;
870 memcpy(skb_put(txb
->fragments
[0],skb
->len
), skb
->data
, skb
->len
);
876 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(txb
->fragments
[0]->cb
+ MAX_DEV_ADDR_SIZE
);
877 tcb_desc
->bTxEnableFwCalcDur
= 1;
878 tcb_desc
->priority
= skb
->priority
;
880 if (ether_type
== ETH_P_PAE
) {
881 if (ieee
->pHTInfo
->IOTAction
& HT_IOT_ACT_WA_IOT_Broadcom
)
883 tcb_desc
->data_rate
= MgntQuery_TxRateExcludeCCKRates(ieee
);
884 tcb_desc
->bTxDisableRateFallBack
= false;
886 tcb_desc
->data_rate
= ieee
->basic_rate
;
887 tcb_desc
->bTxDisableRateFallBack
= 1;
891 tcb_desc
->RATRIndex
= 7;
892 tcb_desc
->bTxUseDriverAssingedRate
= 1;
894 if (is_multicast_ether_addr(header
.addr1
))
895 tcb_desc
->bMulticast
= 1;
896 if (is_broadcast_ether_addr(header
.addr1
))
897 tcb_desc
->bBroadcast
= 1;
898 rtllib_txrate_selectmode(ieee
, tcb_desc
);
899 if ( tcb_desc
->bMulticast
|| tcb_desc
->bBroadcast
)
900 tcb_desc
->data_rate
= ieee
->basic_rate
;
902 tcb_desc
->data_rate
= CURRENT_RATE(ieee
->mode
, ieee
->rate
, ieee
->HTCurrentOperaRate
);
905 if (ieee
->pHTInfo
->IOTAction
& HT_IOT_ACT_WA_IOT_Broadcom
)
907 tcb_desc
->data_rate
= MgntQuery_TxRateExcludeCCKRates(ieee
);
908 tcb_desc
->bTxDisableRateFallBack
= false;
910 tcb_desc
->data_rate
= MGN_1M
;
911 tcb_desc
->bTxDisableRateFallBack
= 1;
915 tcb_desc
->RATRIndex
= 7;
916 tcb_desc
->bTxUseDriverAssingedRate
= 1;
920 rtllib_qurey_ShortPreambleMode(ieee
, tcb_desc
);
921 rtllib_tx_query_agg_cap(ieee
, txb
->fragments
[0], tcb_desc
);
922 rtllib_query_HTCapShortGI(ieee
, tcb_desc
);
923 rtllib_query_BandwidthMode(ieee
, tcb_desc
);
924 rtllib_query_protectionmode(ieee
, tcb_desc
, txb
->fragments
[0]);
927 spin_unlock_irqrestore(&ieee
->lock
, flags
);
928 dev_kfree_skb_any(skb
);
930 if (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
){
931 dev
->stats
.tx_packets
++;
932 dev
->stats
.tx_bytes
+= txb
->payload_size
;
933 rtllib_softmac_xmit(txb
, ieee
);
935 if ((*ieee
->hard_start_xmit
)(txb
, dev
) == 0) {
937 stats
->tx_bytes
+= txb
->payload_size
;
940 rtllib_txb_free(txb
);
947 spin_unlock_irqrestore(&ieee
->lock
, flags
);
948 netif_stop_queue(dev
);
953 int rtllib_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
955 memset(skb
->cb
, 0, sizeof(skb
->cb
));
956 return rtllib_xmit_inter(skb
, dev
);