]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[mirror_ubuntu-zesty-kernel.git] / drivers / staging / rtl8192u / ieee80211 / ieee80211_tx.c
1 /******************************************************************************
2
3 Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved.
4
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.
8
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
12 more details.
13
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.
17
18 The full GNU General Public License is included in this distribution in the
19 file called LICENSE.
20
21 Contact Information:
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24
25 ******************************************************************************
26
27 Few modifications for Realtek's Wi-Fi drivers by
28 Andrea Merello <andrea.merello@gmail.com>
29
30 A special thanks goes to Realtek for their support !
31
32 ******************************************************************************/
33
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>
39 #include <linux/in.h>
40 #include <linux/ip.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>
54
55 #include "ieee80211.h"
56
57
58 /*
59
60
61 802.11 Data Frame
62
63
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 '-----------------------------------------------------------------------------------------'
73 /\
74 |
75 802.11 Data Frame |
76 ,--------- 'ctrl' expands to >-----------'
77 |
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 `----.----'
85 |
86 .- 'Frame data' expands to <---------------------------'
87 |
88 V
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 `----.----'
97 |
98 .- 'IP Packet' expands, if WEP enabled, to <--'
99 |
100 V
101 ,-----------------------.
102 Bytes | 4 | 0-2296 | 4 |
103 |-----|-----------|-----|
104 Desc. | IV | Encrypted | ICV |
105 | | IP Packet | |
106 `-----------------------'
107 Total: 8 non-data bytes
108
109
110 802.3 Ethernet Data Frame
111
112 ,-----------------------------------------.
113 Bytes | 6 | 6 | 2 | Variable | 4 |
114 |-------|-------|------|-----------|------|
115 Desc. | Dest. | Source| Type | IP Packet | fcs |
116 | MAC | MAC | | | |
117 `-----------------------------------------'
118 Total: 18 non-data bytes
119
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.
123
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.
129
130 * SKB visualization
131 *
132 * ,- skb->data
133 * |
134 * | ETHERNET HEADER ,-<-- PAYLOAD
135 * | | 14 bytes from skb->data
136 * | 2 bytes for Type --> ,T. | (sizeof ethhdr)
137 * | | | |
138 * |,-Dest.--. ,--Src.---. | | |
139 * | 6 bytes| | 6 bytes | | | |
140 * v | | | | | |
141 * 0 | v 1 | v | v 2
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
143 * ^ | ^ | ^ |
144 * | | | | | |
145 * | | | | `T' <---- 2 bytes for Type
146 * | | | |
147 * | | '---SNAP--' <-------- 6 bytes for SNAP
148 * | |
149 * `-IV--' <-------------------- 4 bytes for IV (WEP)
150 *
151 * SNAP HEADER
152 *
153 */
154
155 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
156 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
157
158 static inline int ieee80211_put_snap(u8 *data, u16 h_proto)
159 {
160 struct ieee80211_snap_hdr *snap;
161 u8 *oui;
162
163 snap = (struct ieee80211_snap_hdr *)data;
164 snap->dsap = 0xaa;
165 snap->ssap = 0xaa;
166 snap->ctrl = 0x03;
167
168 if (h_proto == 0x8137 || h_proto == 0x80f3)
169 oui = P802_1H_OUI;
170 else
171 oui = RFC1042_OUI;
172 snap->oui[0] = oui[0];
173 snap->oui[1] = oui[1];
174 snap->oui[2] = oui[2];
175
176 *(u16 *)(data + SNAP_SIZE) = htons(h_proto);
177
178 return SNAP_SIZE + sizeof(u16);
179 }
180
181 int ieee80211_encrypt_fragment(
182 struct ieee80211_device *ieee,
183 struct sk_buff *frag,
184 int hdr_len)
185 {
186 struct ieee80211_crypt_data *crypt = ieee->crypt[ieee->tx_keyidx];
187 int res;
188
189 if (!(crypt && crypt->ops))
190 {
191 printk("=========>%s(), crypt is null\n", __func__);
192 return -1;
193 }
194
195 if (ieee->tkip_countermeasures &&
196 crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) {
197 if (net_ratelimit()) {
198 struct ieee80211_hdr_3addrqos *header;
199
200 header = (struct ieee80211_hdr_3addrqos *)frag->data;
201 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
202 "TX packet to %pM\n",
203 ieee->dev->name, header->addr1);
204 }
205 return -1;
206 }
207
208 /* To encrypt, frame format is:
209 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */
210
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);
215 res = 0;
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);
220
221 atomic_dec(&crypt->refcnt);
222 if (res < 0) {
223 printk(KERN_INFO "%s: Encryption failed: len=%d.\n",
224 ieee->dev->name, frag->len);
225 ieee->ieee_stats.tx_discards++;
226 return -1;
227 }
228
229 return 0;
230 }
231
232
233 void ieee80211_txb_free(struct ieee80211_txb *txb) {
234 //int i;
235 if (unlikely(!txb))
236 return;
237 kfree(txb);
238 }
239 EXPORT_SYMBOL(ieee80211_txb_free);
240
241 static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size,
242 gfp_t gfp_mask)
243 {
244 struct ieee80211_txb *txb;
245 int i;
246 txb = kmalloc(
247 sizeof(struct ieee80211_txb) + (sizeof(u8 *) * nr_frags),
248 gfp_mask);
249 if (!txb)
250 return NULL;
251
252 memset(txb, 0, sizeof(struct ieee80211_txb));
253 txb->nr_frags = nr_frags;
254 txb->frag_size = txb_size;
255
256 for (i = 0; i < nr_frags; i++) {
257 txb->fragments[i] = dev_alloc_skb(txb_size);
258 if (unlikely(!txb->fragments[i])) {
259 i--;
260 break;
261 }
262 memset(txb->fragments[i]->cb, 0, sizeof(txb->fragments[i]->cb));
263 }
264 if (unlikely(i != nr_frags)) {
265 while (i >= 0)
266 dev_kfree_skb_any(txb->fragments[i--]);
267 kfree(txb);
268 return NULL;
269 }
270 return txb;
271 }
272
273 // Classify the to-be send data packet
274 // Need to acquire the sent queue index.
275 static int
276 ieee80211_classify(struct sk_buff *skb, struct ieee80211_network *network)
277 {
278 struct ethhdr *eth;
279 struct iphdr *ip;
280 eth = (struct ethhdr *)skb->data;
281 if (eth->h_proto != htons(ETH_P_IP))
282 return 0;
283
284 // IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
285 ip = ip_hdr(skb);
286 switch (ip->tos & 0xfc) {
287 case 0x20:
288 return 2;
289 case 0x40:
290 return 1;
291 case 0x60:
292 return 3;
293 case 0x80:
294 return 4;
295 case 0xa0:
296 return 5;
297 case 0xc0:
298 return 6;
299 case 0xe0:
300 return 7;
301 default:
302 return 0;
303 }
304 }
305
306 #define SN_LESS(a, b) (((a-b)&0x800)!=0)
307 static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
308 struct sk_buff *skb, cb_desc *tcb_desc)
309 {
310 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
311 PTX_TS_RECORD pTxTs = NULL;
312 struct ieee80211_hdr_1addr *hdr = (struct ieee80211_hdr_1addr *)skb->data;
313
314 if (!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT)
315 return;
316 if (!IsQoSDataFrame(skb->data))
317 return;
318
319 if (is_multicast_ether_addr(hdr->addr1))
320 return;
321 //check packet and mode later
322 #ifdef TO_DO_LIST
323 if(pTcb->PacketLength >= 4096)
324 return;
325 // For RTL819X, if pairwisekey = wep/tkip, we don't aggrregation.
326 if(!Adapter->HalFunc.GetNmodeSupportBySecCfgHandler(Adapter))
327 return;
328 #endif
329 if(!ieee->GetNmodeSupportBySecCfg(ieee->dev))
330 {
331 return;
332 }
333 if(pHTInfo->bCurrentAMPDUEnable)
334 {
335 if (!GetTs(ieee, (PTS_COMMON_INFO *)(&pTxTs), hdr->addr1, skb->priority, TX_DIR, true))
336 {
337 printk("===>can't get TS\n");
338 return;
339 }
340 if (pTxTs->TxAdmittedBARecord.bValid == false)
341 {
342 TsStartAddBaProcess(ieee, pTxTs);
343 goto FORCED_AGG_SETTING;
344 }
345 else if (pTxTs->bUsingBa == false)
346 {
347 if (SN_LESS(pTxTs->TxAdmittedBARecord.BaStartSeqCtrl.field.SeqNum, (pTxTs->TxCurSeq+1)%4096))
348 pTxTs->bUsingBa = true;
349 else
350 goto FORCED_AGG_SETTING;
351 }
352
353 if (ieee->iw_mode == IW_MODE_INFRA)
354 {
355 tcb_desc->bAMPDUEnable = true;
356 tcb_desc->ampdu_factor = pHTInfo->CurrentAMPDUFactor;
357 tcb_desc->ampdu_density = pHTInfo->CurrentMPDUDensity;
358 }
359 }
360 FORCED_AGG_SETTING:
361 switch (pHTInfo->ForcedAMPDUMode )
362 {
363 case HT_AGG_AUTO:
364 break;
365
366 case HT_AGG_FORCE_ENABLE:
367 tcb_desc->bAMPDUEnable = true;
368 tcb_desc->ampdu_density = pHTInfo->ForcedMPDUDensity;
369 tcb_desc->ampdu_factor = pHTInfo->ForcedAMPDUFactor;
370 break;
371
372 case HT_AGG_FORCE_DISABLE:
373 tcb_desc->bAMPDUEnable = false;
374 tcb_desc->ampdu_density = 0;
375 tcb_desc->ampdu_factor = 0;
376 break;
377
378 }
379 return;
380 }
381
382 static void ieee80211_qurey_ShortPreambleMode(struct ieee80211_device *ieee,
383 cb_desc *tcb_desc)
384 {
385 tcb_desc->bUseShortPreamble = false;
386 if (tcb_desc->data_rate == 2)
387 {//// 1M can only use Long Preamble. 11B spec
388 return;
389 }
390 else if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
391 {
392 tcb_desc->bUseShortPreamble = true;
393 }
394 return;
395 }
396 static void
397 ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, cb_desc *tcb_desc)
398 {
399 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
400
401 tcb_desc->bUseShortGI = false;
402
403 if(!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT)
404 return;
405
406 if(pHTInfo->bForcedShortGI)
407 {
408 tcb_desc->bUseShortGI = true;
409 return;
410 }
411
412 if((pHTInfo->bCurBW40MHz==true) && pHTInfo->bCurShortGI40MHz)
413 tcb_desc->bUseShortGI = true;
414 else if((pHTInfo->bCurBW40MHz==false) && pHTInfo->bCurShortGI20MHz)
415 tcb_desc->bUseShortGI = true;
416 }
417
418 static void ieee80211_query_BandwidthMode(struct ieee80211_device *ieee,
419 cb_desc *tcb_desc)
420 {
421 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
422
423 tcb_desc->bPacketBW = false;
424
425 if(!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT)
426 return;
427
428 if(tcb_desc->bMulticast || tcb_desc->bBroadcast)
429 return;
430
431 if((tcb_desc->data_rate & 0x80)==0) // If using legacy rate, it shall use 20MHz channel.
432 return;
433 //BandWidthAutoSwitch is for auto switch to 20 or 40 in long distance
434 if(pHTInfo->bCurBW40MHz && pHTInfo->bCurTxBW40MHz && !ieee->bandwidth_auto_switch.bforced_tx20Mhz)
435 tcb_desc->bPacketBW = true;
436 return;
437 }
438
439 static void ieee80211_query_protectionmode(struct ieee80211_device *ieee,
440 cb_desc *tcb_desc,
441 struct sk_buff *skb)
442 {
443 // Common Settings
444 tcb_desc->bRTSSTBC = false;
445 tcb_desc->bRTSUseShortGI = false; // Since protection frames are always sent by legacy rate, ShortGI will never be used.
446 tcb_desc->bCTSEnable = false; // Most of protection using RTS/CTS
447 tcb_desc->RTSSC = 0; // 20MHz: Don't care; 40MHz: Duplicate.
448 tcb_desc->bRTSBW = false; // RTS frame bandwidth is always 20MHz
449
450 if(tcb_desc->bBroadcast || tcb_desc->bMulticast)//only unicast frame will use rts/cts
451 return;
452
453 if (is_broadcast_ether_addr(skb->data+16)) //check addr3 as infrastructure add3 is DA.
454 return;
455
456 if (ieee->mode < IEEE_N_24G) //b, g mode
457 {
458 // (1) RTS_Threshold is compared to the MPDU, not MSDU.
459 // (2) If there are more than one frag in this MSDU, only the first frag uses protection frame.
460 // Other fragments are protected by previous fragment.
461 // So we only need to check the length of first fragment.
462 if (skb->len > ieee->rts)
463 {
464 tcb_desc->bRTSEnable = true;
465 tcb_desc->rts_rate = MGN_24M;
466 }
467 else if (ieee->current_network.buseprotection)
468 {
469 // Use CTS-to-SELF in protection mode.
470 tcb_desc->bRTSEnable = true;
471 tcb_desc->bCTSEnable = true;
472 tcb_desc->rts_rate = MGN_24M;
473 }
474 //otherwise return;
475 return;
476 }
477 else
478 {// 11n High throughput case.
479 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
480 while (true)
481 {
482 //check ERP protection
483 if (ieee->current_network.buseprotection)
484 {// CTS-to-SELF
485 tcb_desc->bRTSEnable = true;
486 tcb_desc->bCTSEnable = true;
487 tcb_desc->rts_rate = MGN_24M;
488 break;
489 }
490 //check HT op mode
491 if(pHTInfo->bCurrentHTSupport && pHTInfo->bEnableHT)
492 {
493 u8 HTOpMode = pHTInfo->CurrentOpMode;
494 if((pHTInfo->bCurBW40MHz && (HTOpMode == 2 || HTOpMode == 3)) ||
495 (!pHTInfo->bCurBW40MHz && HTOpMode == 3) )
496 {
497 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
498 tcb_desc->bRTSEnable = true;
499 break;
500 }
501 }
502 //check rts
503 if (skb->len > ieee->rts)
504 {
505 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
506 tcb_desc->bRTSEnable = true;
507 break;
508 }
509 //to do list: check MIMO power save condition.
510 //check AMPDU aggregation for TXOP
511 if(tcb_desc->bAMPDUEnable)
512 {
513 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
514 // According to 8190 design, firmware sends CF-End only if RTS/CTS is enabled. However, it degrads
515 // throughput around 10M, so we disable of this mechanism. 2007.08.03 by Emily
516 tcb_desc->bRTSEnable = false;
517 break;
518 }
519 //check IOT action
520 if(pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF)
521 {
522 tcb_desc->bCTSEnable = true;
523 tcb_desc->rts_rate = MGN_24M;
524 tcb_desc->bRTSEnable = true;
525 break;
526 }
527 // Totally no protection case!!
528 goto NO_PROTECTION;
529 }
530 }
531 // For test , CTS replace with RTS
532 if (0) {
533 tcb_desc->bCTSEnable = true;
534 tcb_desc->rts_rate = MGN_24M;
535 tcb_desc->bRTSEnable = true;
536 }
537 if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
538 tcb_desc->bUseShortPreamble = true;
539 if (ieee->mode == IW_MODE_MASTER)
540 goto NO_PROTECTION;
541 return;
542 NO_PROTECTION:
543 tcb_desc->bRTSEnable = false;
544 tcb_desc->bCTSEnable = false;
545 tcb_desc->rts_rate = 0;
546 tcb_desc->RTSSC = 0;
547 tcb_desc->bRTSBW = false;
548 }
549
550
551 static void ieee80211_txrate_selectmode(struct ieee80211_device *ieee,
552 cb_desc *tcb_desc)
553 {
554 #ifdef TO_DO_LIST
555 if(!IsDataFrame(pFrame))
556 {
557 pTcb->bTxDisableRateFallBack = TRUE;
558 pTcb->bTxUseDriverAssingedRate = TRUE;
559 pTcb->RATRIndex = 7;
560 return;
561 }
562
563 if(pMgntInfo->ForcedDataRate!= 0)
564 {
565 pTcb->bTxDisableRateFallBack = TRUE;
566 pTcb->bTxUseDriverAssingedRate = TRUE;
567 return;
568 }
569 #endif
570 if(ieee->bTxDisableRateFallBack)
571 tcb_desc->bTxDisableRateFallBack = true;
572
573 if(ieee->bTxUseDriverAssingedRate)
574 tcb_desc->bTxUseDriverAssingedRate = true;
575 if(!tcb_desc->bTxDisableRateFallBack || !tcb_desc->bTxUseDriverAssingedRate)
576 {
577 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
578 tcb_desc->RATRIndex = 0;
579 }
580 }
581
582 static void ieee80211_query_seqnum(struct ieee80211_device *ieee,
583 struct sk_buff *skb, u8 *dst)
584 {
585 if (is_multicast_ether_addr(dst))
586 return;
587 if (IsQoSDataFrame(skb->data)) //we deal qos data only
588 {
589 PTX_TS_RECORD pTS = NULL;
590 if (!GetTs(ieee, (PTS_COMMON_INFO *)(&pTS), dst, skb->priority, TX_DIR, true))
591 {
592 return;
593 }
594 pTS->TxCurSeq = (pTS->TxCurSeq+1)%4096;
595 }
596 }
597
598 int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
599 {
600 struct ieee80211_device *ieee = netdev_priv(dev);
601 struct ieee80211_txb *txb = NULL;
602 struct ieee80211_hdr_3addrqos *frag_hdr;
603 int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size;
604 unsigned long flags;
605 struct net_device_stats *stats = &ieee->stats;
606 int ether_type = 0, encrypt;
607 int bytes, fc, qos_ctl = 0, hdr_len;
608 struct sk_buff *skb_frag;
609 struct ieee80211_hdr_3addrqos header = { /* Ensure zero initialized */
610 .duration_id = 0,
611 .seq_ctl = 0,
612 .qos_ctl = 0
613 };
614 u8 dest[ETH_ALEN], src[ETH_ALEN];
615 int qos_actived = ieee->current_network.qos_data.active;
616
617 struct ieee80211_crypt_data *crypt;
618
619 cb_desc *tcb_desc;
620
621 spin_lock_irqsave(&ieee->lock, flags);
622
623 /* If there is no driver handler to take the TXB, dont' bother
624 * creating it... */
625 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE))||
626 ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) {
627 printk(KERN_WARNING "%s: No xmit handler.\n",
628 ieee->dev->name);
629 goto success;
630 }
631
632
633 if(likely(ieee->raw_tx == 0)){
634 if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) {
635 printk(KERN_WARNING "%s: skb too small (%d).\n",
636 ieee->dev->name, skb->len);
637 goto success;
638 }
639
640 memset(skb->cb, 0, sizeof(skb->cb));
641 ether_type = ntohs(((struct ethhdr *)skb->data)->h_proto);
642
643 crypt = ieee->crypt[ieee->tx_keyidx];
644
645 encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) &&
646 ieee->host_encrypt && crypt && crypt->ops;
647
648 if (!encrypt && ieee->ieee802_1x &&
649 ieee->drop_unencrypted && ether_type != ETH_P_PAE) {
650 stats->tx_dropped++;
651 goto success;
652 }
653 #ifdef CONFIG_IEEE80211_DEBUG
654 if (crypt && !encrypt && ether_type == ETH_P_PAE) {
655 struct eapol *eap = (struct eapol *)(skb->data +
656 sizeof(struct ethhdr) - SNAP_SIZE - sizeof(u16));
657 IEEE80211_DEBUG_EAP("TX: IEEE 802.11 EAPOL frame: %s\n",
658 eap_get_type(eap->type));
659 }
660 #endif
661
662 /* Save source and destination addresses */
663 memcpy(&dest, skb->data, ETH_ALEN);
664 memcpy(&src, skb->data+ETH_ALEN, ETH_ALEN);
665
666 /* Advance the SKB to the start of the payload */
667 skb_pull(skb, sizeof(struct ethhdr));
668
669 /* Determine total amount of storage required for TXB packets */
670 bytes = skb->len + SNAP_SIZE + sizeof(u16);
671
672 if (encrypt)
673 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_WEP;
674 else
675
676 fc = IEEE80211_FTYPE_DATA;
677
678 //if(ieee->current_network.QoS_Enable)
679 if(qos_actived)
680 fc |= IEEE80211_STYPE_QOS_DATA;
681 else
682 fc |= IEEE80211_STYPE_DATA;
683
684 if (ieee->iw_mode == IW_MODE_INFRA) {
685 fc |= IEEE80211_FCTL_TODS;
686 /* To DS: Addr1 = BSSID, Addr2 = SA,
687 Addr3 = DA */
688 memcpy(&header.addr1, ieee->current_network.bssid, ETH_ALEN);
689 memcpy(&header.addr2, &src, ETH_ALEN);
690 memcpy(&header.addr3, &dest, ETH_ALEN);
691 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
692 /* not From/To DS: Addr1 = DA, Addr2 = SA,
693 Addr3 = BSSID */
694 memcpy(&header.addr1, dest, ETH_ALEN);
695 memcpy(&header.addr2, src, ETH_ALEN);
696 memcpy(&header.addr3, ieee->current_network.bssid, ETH_ALEN);
697 }
698
699 header.frame_ctl = cpu_to_le16(fc);
700
701 /* Determine fragmentation size based on destination (multicast
702 * and broadcast are not fragmented) */
703 if (is_multicast_ether_addr(header.addr1)) {
704 frag_size = MAX_FRAG_THRESHOLD;
705 qos_ctl |= QOS_CTL_NOTCONTAIN_ACK;
706 }
707 else {
708 frag_size = ieee->fts;//default:392
709 qos_ctl = 0;
710 }
711
712 //if (ieee->current_network.QoS_Enable)
713 if(qos_actived)
714 {
715 hdr_len = IEEE80211_3ADDR_LEN + 2;
716
717 skb->priority = ieee80211_classify(skb, &ieee->current_network);
718 qos_ctl |= skb->priority; //set in the ieee80211_classify
719 header.qos_ctl = cpu_to_le16(qos_ctl & IEEE80211_QOS_TID);
720 } else {
721 hdr_len = IEEE80211_3ADDR_LEN;
722 }
723 /* Determine amount of payload per fragment. Regardless of if
724 * this stack is providing the full 802.11 header, one will
725 * eventually be affixed to this fragment -- so we must account for
726 * it when determining the amount of payload space. */
727 bytes_per_frag = frag_size - hdr_len;
728 if (ieee->config &
729 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
730 bytes_per_frag -= IEEE80211_FCS_LEN;
731
732 /* Each fragment may need to have room for encryption pre/postfix */
733 if (encrypt)
734 bytes_per_frag -= crypt->ops->extra_prefix_len +
735 crypt->ops->extra_postfix_len;
736
737 /* Number of fragments is the total bytes_per_frag /
738 * payload_per_fragment */
739 nr_frags = bytes / bytes_per_frag;
740 bytes_last_frag = bytes % bytes_per_frag;
741 if (bytes_last_frag)
742 nr_frags++;
743 else
744 bytes_last_frag = bytes_per_frag;
745
746 /* When we allocate the TXB we allocate enough space for the reserve
747 * and full fragment bytes (bytes_per_frag doesn't include prefix,
748 * postfix, header, FCS, etc.) */
749 txb = ieee80211_alloc_txb(nr_frags, frag_size + ieee->tx_headroom, GFP_ATOMIC);
750 if (unlikely(!txb)) {
751 printk(KERN_WARNING "%s: Could not allocate TXB\n",
752 ieee->dev->name);
753 goto failed;
754 }
755 txb->encrypted = encrypt;
756 txb->payload_size = bytes;
757
758 //if (ieee->current_network.QoS_Enable)
759 if(qos_actived)
760 {
761 txb->queue_index = UP2AC(skb->priority);
762 } else {
763 txb->queue_index = WME_AC_BK;
764 }
765
766
767
768 for (i = 0; i < nr_frags; i++) {
769 skb_frag = txb->fragments[i];
770 tcb_desc = (cb_desc *)(skb_frag->cb + MAX_DEV_ADDR_SIZE);
771 if(qos_actived){
772 skb_frag->priority = skb->priority;//UP2AC(skb->priority);
773 tcb_desc->queue_index = UP2AC(skb->priority);
774 } else {
775 skb_frag->priority = WME_AC_BK;
776 tcb_desc->queue_index = WME_AC_BK;
777 }
778 skb_reserve(skb_frag, ieee->tx_headroom);
779
780 if (encrypt){
781 if (ieee->hwsec_active)
782 tcb_desc->bHwSec = 1;
783 else
784 tcb_desc->bHwSec = 0;
785 skb_reserve(skb_frag, crypt->ops->extra_prefix_len);
786 }
787 else
788 {
789 tcb_desc->bHwSec = 0;
790 }
791 frag_hdr = (struct ieee80211_hdr_3addrqos *)skb_put(skb_frag, hdr_len);
792 memcpy(frag_hdr, &header, hdr_len);
793
794 /* If this is not the last fragment, then add the MOREFRAGS
795 * bit to the frame control */
796 if (i != nr_frags - 1) {
797 frag_hdr->frame_ctl = cpu_to_le16(
798 fc | IEEE80211_FCTL_MOREFRAGS);
799 bytes = bytes_per_frag;
800
801 } else {
802 /* The last fragment takes the remaining length */
803 bytes = bytes_last_frag;
804 }
805 //if(ieee->current_network.QoS_Enable)
806 if(qos_actived)
807 {
808 // add 1 only indicate to corresponding seq number control 2006/7/12
809 frag_hdr->seq_ctl = cpu_to_le16(ieee->seq_ctrl[UP2AC(skb->priority)+1]<<4 | i);
810 } else {
811 frag_hdr->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4 | i);
812 }
813
814 /* Put a SNAP header on the first fragment */
815 if (i == 0) {
816 ieee80211_put_snap(
817 skb_put(skb_frag, SNAP_SIZE + sizeof(u16)),
818 ether_type);
819 bytes -= SNAP_SIZE + sizeof(u16);
820 }
821
822 memcpy(skb_put(skb_frag, bytes), skb->data, bytes);
823
824 /* Advance the SKB... */
825 skb_pull(skb, bytes);
826
827 /* Encryption routine will move the header forward in order
828 * to insert the IV between the header and the payload */
829 if (encrypt)
830 ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len);
831 if (ieee->config &
832 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
833 skb_put(skb_frag, 4);
834 }
835
836 if(qos_actived)
837 {
838 if (ieee->seq_ctrl[UP2AC(skb->priority) + 1] == 0xFFF)
839 ieee->seq_ctrl[UP2AC(skb->priority) + 1] = 0;
840 else
841 ieee->seq_ctrl[UP2AC(skb->priority) + 1]++;
842 } else {
843 if (ieee->seq_ctrl[0] == 0xFFF)
844 ieee->seq_ctrl[0] = 0;
845 else
846 ieee->seq_ctrl[0]++;
847 }
848 }else{
849 if (unlikely(skb->len < sizeof(struct ieee80211_hdr_3addr))) {
850 printk(KERN_WARNING "%s: skb too small (%d).\n",
851 ieee->dev->name, skb->len);
852 goto success;
853 }
854
855 txb = ieee80211_alloc_txb(1, skb->len, GFP_ATOMIC);
856 if(!txb){
857 printk(KERN_WARNING "%s: Could not allocate TXB\n",
858 ieee->dev->name);
859 goto failed;
860 }
861
862 txb->encrypted = 0;
863 txb->payload_size = skb->len;
864 memcpy(skb_put(txb->fragments[0],skb->len), skb->data, skb->len);
865 }
866
867 success:
868 //WB add to fill data tcb_desc here. only first fragment is considered, need to change, and you may remove to other place.
869 if (txb)
870 {
871 cb_desc *tcb_desc = (cb_desc *)(txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE);
872 tcb_desc->bTxEnableFwCalcDur = 1;
873 if (is_multicast_ether_addr(header.addr1))
874 tcb_desc->bMulticast = 1;
875 if (is_broadcast_ether_addr(header.addr1))
876 tcb_desc->bBroadcast = 1;
877 ieee80211_txrate_selectmode(ieee, tcb_desc);
878 if (tcb_desc->bMulticast || tcb_desc->bBroadcast)
879 tcb_desc->data_rate = ieee->basic_rate;
880 else
881 //tcb_desc->data_rate = CURRENT_RATE(ieee->current_network.mode, ieee->rate, ieee->HTCurrentOperaRate);
882 tcb_desc->data_rate = CURRENT_RATE(ieee->mode, ieee->rate, ieee->HTCurrentOperaRate);
883 ieee80211_qurey_ShortPreambleMode(ieee, tcb_desc);
884 ieee80211_tx_query_agg_cap(ieee, txb->fragments[0], tcb_desc);
885 ieee80211_query_HTCapShortGI(ieee, tcb_desc);
886 ieee80211_query_BandwidthMode(ieee, tcb_desc);
887 ieee80211_query_protectionmode(ieee, tcb_desc, txb->fragments[0]);
888 ieee80211_query_seqnum(ieee, txb->fragments[0], header.addr1);
889 // IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, txb->fragments[0]->data, txb->fragments[0]->len);
890 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, tcb_desc, sizeof(cb_desc));
891 }
892 spin_unlock_irqrestore(&ieee->lock, flags);
893 dev_kfree_skb_any(skb);
894 if (txb) {
895 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE){
896 ieee80211_softmac_xmit(txb, ieee);
897 }else{
898 if ((*ieee->hard_start_xmit)(txb, dev) == 0) {
899 stats->tx_packets++;
900 stats->tx_bytes += txb->payload_size;
901 return 0;
902 }
903 ieee80211_txb_free(txb);
904 }
905 }
906
907 return 0;
908
909 failed:
910 spin_unlock_irqrestore(&ieee->lock, flags);
911 netif_stop_queue(dev);
912 stats->tx_errors++;
913 return 1;
914
915 }