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 <andrea.merello@gmail.com>
30 A special thanks goes to Realtek for their support !
32 ******************************************************************************/
34 #include <linux/compiler.h>
35 //#include <linux/config.h>
36 #include <linux/errno.h>
37 #include <linux/if_arp.h>
38 #include <linux/in6.h>
41 #include <linux/kernel.h>
42 #include <linux/module.h>
43 #include <linux/netdevice.h>
44 #include <linux/pci.h>
45 #include <linux/proc_fs.h>
46 #include <linux/skbuff.h>
47 #include <linux/slab.h>
48 #include <linux/tcp.h>
49 #include <linux/types.h>
50 #include <linux/wireless.h>
51 #include <linux/etherdevice.h>
52 #include <asm/uaccess.h>
53 #include <linux/if_vlan.h>
55 #include "ieee80211.h"
64 802.11 frame_contorl for data frames - 2 bytes
65 ,-----------------------------------------------------------------------------------------.
66 bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e |
67 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
68 val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x | x | x |
69 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
70 desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep |
71 | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | |
72 '-----------------------------------------------------------------------------------------'
76 ,--------- 'ctrl' expands to >-----------'
78 ,--'---,-------------------------------------------------------------.
79 Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
80 |------|------|---------|---------|---------|------|---------|------|
81 Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs |
82 | | tion | (BSSID) | | | ence | data | |
83 `--------------------------------------------------| |------'
84 Total: 28 non-data bytes `----.----'
86 .- 'Frame data' expands to <---------------------------'
89 ,---------------------------------------------------.
90 Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 |
91 |------|------|---------|----------|------|---------|
92 Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
93 | DSAP | SSAP | | | | Packet |
94 | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
95 `-----------------------------------------| |
96 Total: 8 non-data bytes `----.----'
98 .- 'IP Packet' expands, if WEP enabled, to <--'
101 ,-----------------------.
102 Bytes | 4 | 0-2296 | 4 |
103 |-----|-----------|-----|
104 Desc. | IV | Encrypted | ICV |
106 `-----------------------'
107 Total: 8 non-data bytes
110 802.3 Ethernet Data Frame
112 ,-----------------------------------------.
113 Bytes | 6 | 6 | 2 | Variable | 4 |
114 |-------|-------|------|-----------|------|
115 Desc. | Dest. | Source| Type | IP Packet | fcs |
117 `-----------------------------------------'
118 Total: 18 non-data bytes
120 In the event that fragmentation is required, the incoming payload is split into
121 N parts of size ieee->fts. The first fragment contains the SNAP header and the
122 remaining packets are just data.
124 If encryption is enabled, each fragment payload size is reduced by enough space
125 to add the prefix and postfix (IV and ICV totalling 8 bytes in the case of WEP)
126 So if you have 1500 bytes of payload with ieee->fts set to 500 without
127 encryption it will take 3 frames. With WEP it will take 4 frames as the
128 payload of each frame is reduced to 492 bytes.
134 * | ETHERNET HEADER ,-<-- PAYLOAD
135 * | | 14 bytes from skb->data
136 * | 2 bytes for Type --> ,T. | (sizeof ethhdr)
138 * |,-Dest.--. ,--Src.---. | | |
139 * | 6 bytes| | 6 bytes | | | |
142 * 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
145 * | | | | `T' <---- 2 bytes for Type
147 * | | '---SNAP--' <-------- 6 bytes for SNAP
149 * `-IV--' <-------------------- 4 bytes for IV (WEP)
155 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
156 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
158 static inline int ieee80211_put_snap(u8 *data, u16 h_proto)
160 struct ieee80211_snap_hdr *snap;
163 snap = (struct ieee80211_snap_hdr *)data;
168 if (h_proto == 0x8137 || h_proto == 0x80f3)
172 snap->oui[0] = oui[0];
173 snap->oui[1] = oui[1];
174 snap->oui[2] = oui[2];
176 *(u16 *)(data + SNAP_SIZE) = htons(h_proto);
178 return SNAP_SIZE + sizeof(u16);
181 int ieee80211_encrypt_fragment(
182 struct ieee80211_device *ieee,
183 struct sk_buff *frag,
186 struct ieee80211_crypt_data *crypt = ieee->crypt[ieee->tx_keyidx];
189 if (!(crypt && crypt->ops))
191 printk("=========>%s(), crypt is null\n", __FUNCTION__);
194 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
195 struct ieee80211_hdr *header;
197 if (ieee->tkip_countermeasures &&
198 crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) {
199 header = (struct ieee80211_hdr *) frag->data;
200 if (net_ratelimit()) {
201 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
202 "TX packet to %pM\n",
203 ieee->dev->name, header->addr1);
208 /* To encrypt, frame format is:
209 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */
211 // PR: FIXME: Copied from hostap. Check fragmentation/MSDU/MPDU encryption.
212 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so
213 * call both MSDU and MPDU encryption functions from here. */
214 atomic_inc(&crypt->refcnt);
216 if (crypt->ops->encrypt_msdu)
217 res = crypt->ops->encrypt_msdu(frag, hdr_len, crypt->priv);
218 if (res == 0 && crypt->ops->encrypt_mpdu)
219 res = crypt->ops->encrypt_mpdu(frag, hdr_len, crypt->priv);
221 atomic_dec(&crypt->refcnt);
223 printk(KERN_INFO "%s: Encryption failed: len=%d.\n",
224 ieee->dev->name, frag->len);
225 ieee->ieee_stats.tx_discards++;
233 void ieee80211_txb_free(struct ieee80211_txb *txb) {
240 static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size,
243 struct ieee80211_txb *txb;
246 sizeof(struct ieee80211_txb) + (sizeof(u8 *) * nr_frags),
251 memset(txb, 0, sizeof(struct ieee80211_txb));
252 txb->nr_frags = nr_frags;
253 txb->frag_size = txb_size;
255 for (i = 0; i < nr_frags; i++) {
256 txb->fragments[i] = dev_alloc_skb(txb_size);
257 if (unlikely(!txb->fragments[i])) {
261 memset(txb->fragments[i]->cb, 0, sizeof(txb->fragments[i]->cb));
263 if (unlikely(i != nr_frags)) {
265 dev_kfree_skb_any(txb->fragments[i--]);
272 // Classify the to-be send data packet
273 // Need to acquire the sent queue index.
275 ieee80211_classify(struct sk_buff *skb, struct ieee80211_network *network)
279 eth = (struct ethhdr *)skb->data;
280 if (eth->h_proto != htons(ETH_P_IP))
283 // IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
285 switch (ip->tos & 0xfc) {
305 #define SN_LESS(a, b) (((a-b)&0x800)!=0)
306 static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
307 struct sk_buff *skb, cb_desc *tcb_desc)
309 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
310 PTX_TS_RECORD pTxTs = NULL;
311 struct ieee80211_hdr_1addr *hdr = (struct ieee80211_hdr_1addr *)skb->data;
313 if (!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT)
315 if (!IsQoSDataFrame(skb->data))
318 if (is_multicast_ether_addr(hdr->addr1))
320 //check packet and mode later
322 if(pTcb->PacketLength >= 4096)
324 // For RTL819X, if pairwisekey = wep/tkip, we don't aggrregation.
325 if(!Adapter->HalFunc.GetNmodeSupportBySecCfgHandler(Adapter))
328 if(!ieee->GetNmodeSupportBySecCfg(ieee->dev))
332 if(pHTInfo->bCurrentAMPDUEnable)
334 if (!GetTs(ieee, (PTS_COMMON_INFO *)(&pTxTs), hdr->addr1, skb->priority, TX_DIR, true))
336 printk("===>can't get TS\n");
339 if (pTxTs->TxAdmittedBARecord.bValid == false)
341 TsStartAddBaProcess(ieee, pTxTs);
342 goto FORCED_AGG_SETTING;
344 else if (pTxTs->bUsingBa == false)
346 if (SN_LESS(pTxTs->TxAdmittedBARecord.BaStartSeqCtrl.field.SeqNum, (pTxTs->TxCurSeq+1)%4096))
347 pTxTs->bUsingBa = true;
349 goto FORCED_AGG_SETTING;
352 if (ieee->iw_mode == IW_MODE_INFRA)
354 tcb_desc->bAMPDUEnable = true;
355 tcb_desc->ampdu_factor = pHTInfo->CurrentAMPDUFactor;
356 tcb_desc->ampdu_density = pHTInfo->CurrentMPDUDensity;
360 switch (pHTInfo->ForcedAMPDUMode )
365 case HT_AGG_FORCE_ENABLE:
366 tcb_desc->bAMPDUEnable = true;
367 tcb_desc->ampdu_density = pHTInfo->ForcedMPDUDensity;
368 tcb_desc->ampdu_factor = pHTInfo->ForcedAMPDUFactor;
371 case HT_AGG_FORCE_DISABLE:
372 tcb_desc->bAMPDUEnable = false;
373 tcb_desc->ampdu_density = 0;
374 tcb_desc->ampdu_factor = 0;
381 extern void ieee80211_qurey_ShortPreambleMode(struct ieee80211_device *ieee, cb_desc *tcb_desc)
383 tcb_desc->bUseShortPreamble = false;
384 if (tcb_desc->data_rate == 2)
385 {//// 1M can only use Long Preamble. 11B spec
388 else if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
390 tcb_desc->bUseShortPreamble = true;
395 ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, cb_desc *tcb_desc)
397 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
399 tcb_desc->bUseShortGI = false;
401 if(!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT)
404 if(pHTInfo->bForcedShortGI)
406 tcb_desc->bUseShortGI = true;
410 if((pHTInfo->bCurBW40MHz==true) && pHTInfo->bCurShortGI40MHz)
411 tcb_desc->bUseShortGI = true;
412 else if((pHTInfo->bCurBW40MHz==false) && pHTInfo->bCurShortGI20MHz)
413 tcb_desc->bUseShortGI = true;
416 static void ieee80211_query_BandwidthMode(struct ieee80211_device *ieee,
419 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
421 tcb_desc->bPacketBW = false;
423 if(!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT)
426 if(tcb_desc->bMulticast || tcb_desc->bBroadcast)
429 if((tcb_desc->data_rate & 0x80)==0) // If using legacy rate, it shall use 20MHz channel.
431 //BandWidthAutoSwitch is for auto switch to 20 or 40 in long distance
432 if(pHTInfo->bCurBW40MHz && pHTInfo->bCurTxBW40MHz && !ieee->bandwidth_auto_switch.bforced_tx20Mhz)
433 tcb_desc->bPacketBW = true;
437 static void ieee80211_query_protectionmode(struct ieee80211_device *ieee,
442 tcb_desc->bRTSSTBC = false;
443 tcb_desc->bRTSUseShortGI = false; // Since protection frames are always sent by legacy rate, ShortGI will never be used.
444 tcb_desc->bCTSEnable = false; // Most of protection using RTS/CTS
445 tcb_desc->RTSSC = 0; // 20MHz: Don't care; 40MHz: Duplicate.
446 tcb_desc->bRTSBW = false; // RTS frame bandwidth is always 20MHz
448 if(tcb_desc->bBroadcast || tcb_desc->bMulticast)//only unicast frame will use rts/cts
451 if (is_broadcast_ether_addr(skb->data+16)) //check addr3 as infrastructure add3 is DA.
454 if (ieee->mode < IEEE_N_24G) //b, g mode
456 // (1) RTS_Threshold is compared to the MPDU, not MSDU.
457 // (2) If there are more than one frag in this MSDU, only the first frag uses protection frame.
458 // Other fragments are protected by previous fragment.
459 // So we only need to check the length of first fragment.
460 if (skb->len > ieee->rts)
462 tcb_desc->bRTSEnable = true;
463 tcb_desc->rts_rate = MGN_24M;
465 else if (ieee->current_network.buseprotection)
467 // Use CTS-to-SELF in protection mode.
468 tcb_desc->bRTSEnable = true;
469 tcb_desc->bCTSEnable = true;
470 tcb_desc->rts_rate = MGN_24M;
476 {// 11n High throughput case.
477 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
480 //check ERP protection
481 if (ieee->current_network.buseprotection)
483 tcb_desc->bRTSEnable = true;
484 tcb_desc->bCTSEnable = true;
485 tcb_desc->rts_rate = MGN_24M;
489 if(pHTInfo->bCurrentHTSupport && pHTInfo->bEnableHT)
491 u8 HTOpMode = pHTInfo->CurrentOpMode;
492 if((pHTInfo->bCurBW40MHz && (HTOpMode == 2 || HTOpMode == 3)) ||
493 (!pHTInfo->bCurBW40MHz && HTOpMode == 3) )
495 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
496 tcb_desc->bRTSEnable = true;
501 if (skb->len > ieee->rts)
503 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
504 tcb_desc->bRTSEnable = true;
507 //to do list: check MIMO power save condition.
508 //check AMPDU aggregation for TXOP
509 if(tcb_desc->bAMPDUEnable)
511 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
512 // According to 8190 design, firmware sends CF-End only if RTS/CTS is enabled. However, it degrads
513 // throughput around 10M, so we disable of this mechanism. 2007.08.03 by Emily
514 tcb_desc->bRTSEnable = false;
518 if(pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF)
520 tcb_desc->bCTSEnable = true;
521 tcb_desc->rts_rate = MGN_24M;
522 tcb_desc->bRTSEnable = true;
525 // Totally no protection case!!
529 // For test , CTS replace with RTS
532 tcb_desc->bCTSEnable = true;
533 tcb_desc->rts_rate = MGN_24M;
534 tcb_desc->bRTSEnable = true;
536 if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
537 tcb_desc->bUseShortPreamble = true;
538 if (ieee->mode == IW_MODE_MASTER)
542 tcb_desc->bRTSEnable = false;
543 tcb_desc->bCTSEnable = false;
544 tcb_desc->rts_rate = 0;
546 tcb_desc->bRTSBW = false;
550 static void ieee80211_txrate_selectmode(struct ieee80211_device *ieee,
554 if(!IsDataFrame(pFrame))
556 pTcb->bTxDisableRateFallBack = TRUE;
557 pTcb->bTxUseDriverAssingedRate = TRUE;
562 if(pMgntInfo->ForcedDataRate!= 0)
564 pTcb->bTxDisableRateFallBack = TRUE;
565 pTcb->bTxUseDriverAssingedRate = TRUE;
569 if(ieee->bTxDisableRateFallBack)
570 tcb_desc->bTxDisableRateFallBack = true;
572 if(ieee->bTxUseDriverAssingedRate)
573 tcb_desc->bTxUseDriverAssingedRate = true;
574 if(!tcb_desc->bTxDisableRateFallBack || !tcb_desc->bTxUseDriverAssingedRate)
576 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
577 tcb_desc->RATRIndex = 0;
581 static void ieee80211_query_seqnum(struct ieee80211_device *ieee,
582 struct sk_buff *skb, u8 *dst)
584 if (is_multicast_ether_addr(dst))
586 if (IsQoSDataFrame(skb->data)) //we deal qos data only
588 PTX_TS_RECORD pTS = NULL;
589 if (!GetTs(ieee, (PTS_COMMON_INFO *)(&pTS), dst, skb->priority, TX_DIR, true))
593 pTS->TxCurSeq = (pTS->TxCurSeq+1)%4096;
597 int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
599 struct ieee80211_device *ieee = netdev_priv(dev);
600 struct ieee80211_txb *txb = NULL;
601 struct ieee80211_hdr_3addrqos *frag_hdr;
602 int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size;
604 struct net_device_stats *stats = &ieee->stats;
605 int ether_type = 0, encrypt;
606 int bytes, fc, qos_ctl = 0, hdr_len;
607 struct sk_buff *skb_frag;
608 struct ieee80211_hdr_3addrqos header = { /* Ensure zero initialized */
613 u8 dest[ETH_ALEN], src[ETH_ALEN];
614 int qos_actived = ieee->current_network.qos_data.active;
616 struct ieee80211_crypt_data *crypt;
620 spin_lock_irqsave(&ieee->lock, flags);
622 /* If there is no driver handler to take the TXB, dont' bother
624 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE))||
625 ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) {
626 printk(KERN_WARNING "%s: No xmit handler.\n",
632 if(likely(ieee->raw_tx == 0)){
633 if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) {
634 printk(KERN_WARNING "%s: skb too small (%d).\n",
635 ieee->dev->name, skb->len);
639 memset(skb->cb, 0, sizeof(skb->cb));
640 ether_type = ntohs(((struct ethhdr *)skb->data)->h_proto);
642 crypt = ieee->crypt[ieee->tx_keyidx];
644 encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) &&
645 ieee->host_encrypt && crypt && crypt->ops;
647 if (!encrypt && ieee->ieee802_1x &&
648 ieee->drop_unencrypted && ether_type != ETH_P_PAE) {
652 #ifdef CONFIG_IEEE80211_DEBUG
653 if (crypt && !encrypt && ether_type == ETH_P_PAE) {
654 struct eapol *eap = (struct eapol *)(skb->data +
655 sizeof(struct ethhdr) - SNAP_SIZE - sizeof(u16));
656 IEEE80211_DEBUG_EAP("TX: IEEE 802.11 EAPOL frame: %s\n",
657 eap_get_type(eap->type));
661 /* Save source and destination addresses */
662 memcpy(&dest, skb->data, ETH_ALEN);
663 memcpy(&src, skb->data+ETH_ALEN, ETH_ALEN);
665 /* Advance the SKB to the start of the payload */
666 skb_pull(skb, sizeof(struct ethhdr));
668 /* Determine total amount of storage required for TXB packets */
669 bytes = skb->len + SNAP_SIZE + sizeof(u16);
672 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_WEP;
675 fc = IEEE80211_FTYPE_DATA;
677 //if(ieee->current_network.QoS_Enable)
679 fc |= IEEE80211_STYPE_QOS_DATA;
681 fc |= IEEE80211_STYPE_DATA;
683 if (ieee->iw_mode == IW_MODE_INFRA) {
684 fc |= IEEE80211_FCTL_TODS;
685 /* To DS: Addr1 = BSSID, Addr2 = SA,
687 memcpy(&header.addr1, ieee->current_network.bssid, ETH_ALEN);
688 memcpy(&header.addr2, &src, ETH_ALEN);
689 memcpy(&header.addr3, &dest, ETH_ALEN);
690 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
691 /* not From/To DS: Addr1 = DA, Addr2 = SA,
693 memcpy(&header.addr1, dest, ETH_ALEN);
694 memcpy(&header.addr2, src, ETH_ALEN);
695 memcpy(&header.addr3, ieee->current_network.bssid, ETH_ALEN);
698 header.frame_ctl = cpu_to_le16(fc);
700 /* Determine fragmentation size based on destination (multicast
701 * and broadcast are not fragmented) */
702 if (is_multicast_ether_addr(header.addr1)) {
703 frag_size = MAX_FRAG_THRESHOLD;
704 qos_ctl |= QOS_CTL_NOTCONTAIN_ACK;
707 frag_size = ieee->fts;//default:392
711 //if (ieee->current_network.QoS_Enable)
714 hdr_len = IEEE80211_3ADDR_LEN + 2;
716 skb->priority = ieee80211_classify(skb, &ieee->current_network);
717 qos_ctl |= skb->priority; //set in the ieee80211_classify
718 header.qos_ctl = cpu_to_le16(qos_ctl & IEEE80211_QOS_TID);
720 hdr_len = IEEE80211_3ADDR_LEN;
722 /* Determine amount of payload per fragment. Regardless of if
723 * this stack is providing the full 802.11 header, one will
724 * eventually be affixed to this fragment -- so we must account for
725 * it when determining the amount of payload space. */
726 bytes_per_frag = frag_size - hdr_len;
728 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
729 bytes_per_frag -= IEEE80211_FCS_LEN;
731 /* Each fragment may need to have room for encryption pre/postfix */
733 bytes_per_frag -= crypt->ops->extra_prefix_len +
734 crypt->ops->extra_postfix_len;
736 /* Number of fragments is the total bytes_per_frag /
737 * payload_per_fragment */
738 nr_frags = bytes / bytes_per_frag;
739 bytes_last_frag = bytes % bytes_per_frag;
743 bytes_last_frag = bytes_per_frag;
745 /* When we allocate the TXB we allocate enough space for the reserve
746 * and full fragment bytes (bytes_per_frag doesn't include prefix,
747 * postfix, header, FCS, etc.) */
748 txb = ieee80211_alloc_txb(nr_frags, frag_size + ieee->tx_headroom, GFP_ATOMIC);
749 if (unlikely(!txb)) {
750 printk(KERN_WARNING "%s: Could not allocate TXB\n",
754 txb->encrypted = encrypt;
755 txb->payload_size = bytes;
757 //if (ieee->current_network.QoS_Enable)
760 txb->queue_index = UP2AC(skb->priority);
762 txb->queue_index = WME_AC_BK;
767 for (i = 0; i < nr_frags; i++) {
768 skb_frag = txb->fragments[i];
769 tcb_desc = (cb_desc *)(skb_frag->cb + MAX_DEV_ADDR_SIZE);
771 skb_frag->priority = skb->priority;//UP2AC(skb->priority);
772 tcb_desc->queue_index = UP2AC(skb->priority);
774 skb_frag->priority = WME_AC_BK;
775 tcb_desc->queue_index = WME_AC_BK;
777 skb_reserve(skb_frag, ieee->tx_headroom);
780 if (ieee->hwsec_active)
781 tcb_desc->bHwSec = 1;
783 tcb_desc->bHwSec = 0;
784 skb_reserve(skb_frag, crypt->ops->extra_prefix_len);
788 tcb_desc->bHwSec = 0;
790 frag_hdr = (struct ieee80211_hdr_3addrqos *)skb_put(skb_frag, hdr_len);
791 memcpy(frag_hdr, &header, hdr_len);
793 /* If this is not the last fragment, then add the MOREFRAGS
794 * bit to the frame control */
795 if (i != nr_frags - 1) {
796 frag_hdr->frame_ctl = cpu_to_le16(
797 fc | IEEE80211_FCTL_MOREFRAGS);
798 bytes = bytes_per_frag;
801 /* The last fragment takes the remaining length */
802 bytes = bytes_last_frag;
804 //if(ieee->current_network.QoS_Enable)
807 // add 1 only indicate to corresponding seq number control 2006/7/12
808 frag_hdr->seq_ctl = cpu_to_le16(ieee->seq_ctrl[UP2AC(skb->priority)+1]<<4 | i);
810 frag_hdr->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4 | i);
813 /* Put a SNAP header on the first fragment */
816 skb_put(skb_frag, SNAP_SIZE + sizeof(u16)),
818 bytes -= SNAP_SIZE + sizeof(u16);
821 memcpy(skb_put(skb_frag, bytes), skb->data, bytes);
823 /* Advance the SKB... */
824 skb_pull(skb, bytes);
826 /* Encryption routine will move the header forward in order
827 * to insert the IV between the header and the payload */
829 ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len);
831 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
832 skb_put(skb_frag, 4);
837 if (ieee->seq_ctrl[UP2AC(skb->priority) + 1] == 0xFFF)
838 ieee->seq_ctrl[UP2AC(skb->priority) + 1] = 0;
840 ieee->seq_ctrl[UP2AC(skb->priority) + 1]++;
842 if (ieee->seq_ctrl[0] == 0xFFF)
843 ieee->seq_ctrl[0] = 0;
848 if (unlikely(skb->len < sizeof(struct ieee80211_hdr_3addr))) {
849 printk(KERN_WARNING "%s: skb too small (%d).\n",
850 ieee->dev->name, skb->len);
854 txb = ieee80211_alloc_txb(1, skb->len, GFP_ATOMIC);
856 printk(KERN_WARNING "%s: Could not allocate TXB\n",
862 txb->payload_size = skb->len;
863 memcpy(skb_put(txb->fragments[0],skb->len), skb->data, skb->len);
867 //WB add to fill data tcb_desc here. only first fragment is considered, need to change, and you may remove to other place.
870 cb_desc *tcb_desc = (cb_desc *)(txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE);
871 tcb_desc->bTxEnableFwCalcDur = 1;
872 if (is_multicast_ether_addr(header.addr1))
873 tcb_desc->bMulticast = 1;
874 if (is_broadcast_ether_addr(header.addr1))
875 tcb_desc->bBroadcast = 1;
876 ieee80211_txrate_selectmode(ieee, tcb_desc);
877 if ( tcb_desc->bMulticast || tcb_desc->bBroadcast)
878 tcb_desc->data_rate = ieee->basic_rate;
880 //tcb_desc->data_rate = CURRENT_RATE(ieee->current_network.mode, ieee->rate, ieee->HTCurrentOperaRate);
881 tcb_desc->data_rate = CURRENT_RATE(ieee->mode, ieee->rate, ieee->HTCurrentOperaRate);
882 ieee80211_qurey_ShortPreambleMode(ieee, tcb_desc);
883 ieee80211_tx_query_agg_cap(ieee, txb->fragments[0], tcb_desc);
884 ieee80211_query_HTCapShortGI(ieee, tcb_desc);
885 ieee80211_query_BandwidthMode(ieee, tcb_desc);
886 ieee80211_query_protectionmode(ieee, tcb_desc, txb->fragments[0]);
887 ieee80211_query_seqnum(ieee, txb->fragments[0], header.addr1);
888 // IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, txb->fragments[0]->data, txb->fragments[0]->len);
889 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, tcb_desc, sizeof(cb_desc));
891 spin_unlock_irqrestore(&ieee->lock, flags);
892 dev_kfree_skb_any(skb);
894 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE){
895 ieee80211_softmac_xmit(txb, ieee);
897 if ((*ieee->hard_start_xmit)(txb, dev) == 0) {
899 stats->tx_bytes += txb->payload_size;
902 ieee80211_txb_free(txb);
909 spin_unlock_irqrestore(&ieee->lock, flags);
910 netif_stop_queue(dev);
916 EXPORT_SYMBOL(ieee80211_txb_free);