2e1aab1230c542590d16b1890dc65bc00ffa9df1
[deliverable/linux.git] / drivers / staging / rtl8192e / rtllib_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/errno.h>
36 #include <linux/if_arp.h>
37 #include <linux/in6.h>
38 #include <linux/in.h>
39 #include <linux/ip.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/wireless.h>
50 #include <linux/etherdevice.h>
51 #include <linux/uaccess.h>
52 #include <linux/if_vlan.h>
53
54 #include "rtllib.h"
55
56 /*
57
58
59 802.11 Data Frame
60
61
62 802.11 frame_control for data frames - 2 bytes
63 ,-----------------------------------------------------------------------------------------.
64 bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e |
65 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
66 val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x | x | x |
67 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
68 desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep |
69 | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | |
70 '-----------------------------------------------------------------------------------------'
71 /\
72 |
73 802.11 Data Frame |
74 ,--------- 'ctrl' expands to >-----------'
75 |
76 ,--'---,-------------------------------------------------------------.
77 Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
78 |------|------|---------|---------|---------|------|---------|------|
79 Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs |
80 | | tion | (BSSID) | | | ence | data | |
81 `--------------------------------------------------| |------'
82 Total: 28 non-data bytes `----.----'
83 |
84 .- 'Frame data' expands to <---------------------------'
85 |
86 V
87 ,---------------------------------------------------.
88 Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 |
89 |------|------|---------|----------|------|---------|
90 Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
91 | DSAP | SSAP | | | | Packet |
92 | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
93 `-----------------------------------------| |
94 Total: 8 non-data bytes `----.----'
95 |
96 .- 'IP Packet' expands, if WEP enabled, to <--'
97 |
98 V
99 ,-----------------------.
100 Bytes | 4 | 0-2296 | 4 |
101 |-----|-----------|-----|
102 Desc. | IV | Encrypted | ICV |
103 | | IP Packet | |
104 `-----------------------'
105 Total: 8 non-data bytes
106
107
108 802.3 Ethernet Data Frame
109
110 ,-----------------------------------------.
111 Bytes | 6 | 6 | 2 | Variable | 4 |
112 |-------|-------|------|-----------|------|
113 Desc. | Dest. | Source| Type | IP Packet | fcs |
114 | MAC | MAC | | | |
115 `-----------------------------------------'
116 Total: 18 non-data bytes
117
118 In the event that fragmentation is required, the incoming payload is split into
119 N parts of size ieee->fts. The first fragment contains the SNAP header and the
120 remaining packets are just data.
121
122 If encryption is enabled, each fragment payload size is reduced by enough space
123 to add the prefix and postfix (IV and ICV totalling 8 bytes in the case of WEP)
124 So if you have 1500 bytes of payload with ieee->fts set to 500 without
125 encryption it will take 3 frames. With WEP it will take 4 frames as the
126 payload of each frame is reduced to 492 bytes.
127
128 * SKB visualization
129 *
130 * ,- skb->data
131 * |
132 * | ETHERNET HEADER ,-<-- PAYLOAD
133 * | | 14 bytes from skb->data
134 * | 2 bytes for Type --> ,T. | (sizeof ethhdr)
135 * | | | |
136 * |,-Dest.--. ,--Src.---. | | |
137 * | 6 bytes| | 6 bytes | | | |
138 * v | | | | | |
139 * 0 | v 1 | v | v 2
140 * 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
141 * ^ | ^ | ^ |
142 * | | | | | |
143 * | | | | `T' <---- 2 bytes for Type
144 * | | | |
145 * | | '---SNAP--' <-------- 6 bytes for SNAP
146 * | |
147 * `-IV--' <-------------------- 4 bytes for IV (WEP)
148 *
149 * SNAP HEADER
150 *
151 */
152
153 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
154 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
155
156 inline int rtllib_put_snap(u8 *data, u16 h_proto)
157 {
158 struct rtllib_snap_hdr *snap;
159 u8 *oui;
160
161 snap = (struct rtllib_snap_hdr *)data;
162 snap->dsap = 0xaa;
163 snap->ssap = 0xaa;
164 snap->ctrl = 0x03;
165
166 if (h_proto == 0x8137 || h_proto == 0x80f3)
167 oui = P802_1H_OUI;
168 else
169 oui = RFC1042_OUI;
170 snap->oui[0] = oui[0];
171 snap->oui[1] = oui[1];
172 snap->oui[2] = oui[2];
173
174 *(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
175
176 return SNAP_SIZE + sizeof(u16);
177 }
178
179 int rtllib_encrypt_fragment(struct rtllib_device *ieee, struct sk_buff *frag,
180 int hdr_len)
181 {
182 struct lib80211_crypt_data *crypt = NULL;
183 int res;
184
185 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
186
187 if (!(crypt && crypt->ops)) {
188 netdev_info(ieee->dev, "=========>%s(), crypt is null\n",
189 __func__);
190 return -1;
191 }
192 /* To encrypt, frame format is:
193 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */
194
195 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so
196 * call both MSDU and MPDU encryption functions from here. */
197 atomic_inc(&crypt->refcnt);
198 res = 0;
199 if (crypt->ops->encrypt_msdu)
200 res = crypt->ops->encrypt_msdu(frag, hdr_len, crypt->priv);
201 if (res == 0 && crypt->ops->encrypt_mpdu)
202 res = crypt->ops->encrypt_mpdu(frag, hdr_len, crypt->priv);
203
204 atomic_dec(&crypt->refcnt);
205 if (res < 0) {
206 netdev_info(ieee->dev, "%s: Encryption failed: len=%d.\n",
207 ieee->dev->name, frag->len);
208 ieee->ieee_stats.tx_discards++;
209 return -1;
210 }
211
212 return 0;
213 }
214
215
216 void rtllib_txb_free(struct rtllib_txb *txb)
217 {
218 if (unlikely(!txb))
219 return;
220 kfree(txb);
221 }
222
223 static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,
224 gfp_t gfp_mask)
225 {
226 struct rtllib_txb *txb;
227 int i;
228
229 txb = kmalloc(sizeof(struct rtllib_txb) + (sizeof(u8 *) * nr_frags),
230 gfp_mask);
231 if (!txb)
232 return NULL;
233
234 memset(txb, 0, sizeof(struct rtllib_txb));
235 txb->nr_frags = nr_frags;
236 txb->frag_size = cpu_to_le16(txb_size);
237
238 for (i = 0; i < nr_frags; i++) {
239 txb->fragments[i] = dev_alloc_skb(txb_size);
240 if (unlikely(!txb->fragments[i])) {
241 i--;
242 break;
243 }
244 memset(txb->fragments[i]->cb, 0, sizeof(txb->fragments[i]->cb));
245 }
246 if (unlikely(i != nr_frags)) {
247 while (i >= 0)
248 dev_kfree_skb_any(txb->fragments[i--]);
249 kfree(txb);
250 return NULL;
251 }
252 return txb;
253 }
254
255 static int rtllib_classify(struct sk_buff *skb, u8 bIsAmsdu)
256 {
257 struct ethhdr *eth;
258 struct iphdr *ip;
259
260 eth = (struct ethhdr *)skb->data;
261 if (eth->h_proto != htons(ETH_P_IP))
262 return 0;
263
264 RTLLIB_DEBUG_DATA(RTLLIB_DL_DATA, skb->data, skb->len);
265 ip = ip_hdr(skb);
266 switch (ip->tos & 0xfc) {
267 case 0x20:
268 return 2;
269 case 0x40:
270 return 1;
271 case 0x60:
272 return 3;
273 case 0x80:
274 return 4;
275 case 0xa0:
276 return 5;
277 case 0xc0:
278 return 6;
279 case 0xe0:
280 return 7;
281 default:
282 return 0;
283 }
284 }
285
286 static void rtllib_tx_query_agg_cap(struct rtllib_device *ieee,
287 struct sk_buff *skb,
288 struct cb_desc *tcb_desc)
289 {
290 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
291 struct tx_ts_record *pTxTs = NULL;
292 struct rtllib_hdr_1addr *hdr = (struct rtllib_hdr_1addr *)skb->data;
293
294 if (rtllib_act_scanning(ieee, false))
295 return;
296
297 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
298 return;
299 if (!IsQoSDataFrame(skb->data))
300 return;
301 if (is_multicast_ether_addr(hdr->addr1))
302 return;
303
304 if (tcb_desc->bdhcp || ieee->CntAfterLink < 2)
305 return;
306
307 if (pHTInfo->IOTAction & HT_IOT_ACT_TX_NO_AGGREGATION)
308 return;
309
310 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev))
311 return;
312 if (pHTInfo->bCurrentAMPDUEnable) {
313 if (!GetTs(ieee, (struct ts_common_info **)(&pTxTs), hdr->addr1,
314 skb->priority, TX_DIR, true)) {
315 netdev_info(ieee->dev, "%s: can't get TS\n", __func__);
316 return;
317 }
318 if (pTxTs->TxAdmittedBARecord.bValid == false) {
319 if (ieee->wpa_ie_len && (ieee->pairwise_key_type ==
320 KEY_TYPE_NA)) {
321 ;
322 } else if (tcb_desc->bdhcp == 1) {
323 ;
324 } else if (!pTxTs->bDisable_AddBa) {
325 TsStartAddBaProcess(ieee, pTxTs);
326 }
327 goto FORCED_AGG_SETTING;
328 } else if (pTxTs->bUsingBa == false) {
329 if (SN_LESS(pTxTs->TxAdmittedBARecord.BaStartSeqCtrl.field.SeqNum,
330 (pTxTs->TxCurSeq+1)%4096))
331 pTxTs->bUsingBa = true;
332 else
333 goto FORCED_AGG_SETTING;
334 }
335 if (ieee->iw_mode == IW_MODE_INFRA) {
336 tcb_desc->bAMPDUEnable = true;
337 tcb_desc->ampdu_factor = pHTInfo->CurrentAMPDUFactor;
338 tcb_desc->ampdu_density = pHTInfo->CurrentMPDUDensity;
339 }
340 }
341 FORCED_AGG_SETTING:
342 switch (pHTInfo->ForcedAMPDUMode) {
343 case HT_AGG_AUTO:
344 break;
345
346 case HT_AGG_FORCE_ENABLE:
347 tcb_desc->bAMPDUEnable = true;
348 tcb_desc->ampdu_density = pHTInfo->ForcedMPDUDensity;
349 tcb_desc->ampdu_factor = pHTInfo->ForcedAMPDUFactor;
350 break;
351
352 case HT_AGG_FORCE_DISABLE:
353 tcb_desc->bAMPDUEnable = false;
354 tcb_desc->ampdu_density = 0;
355 tcb_desc->ampdu_factor = 0;
356 break;
357 }
358 }
359
360 static void rtllib_qurey_ShortPreambleMode(struct rtllib_device *ieee,
361 struct cb_desc *tcb_desc)
362 {
363 tcb_desc->bUseShortPreamble = false;
364 if (tcb_desc->data_rate == 2)
365 return;
366 else if (ieee->current_network.capability &
367 WLAN_CAPABILITY_SHORT_PREAMBLE)
368 tcb_desc->bUseShortPreamble = true;
369 }
370
371 static void rtllib_query_HTCapShortGI(struct rtllib_device *ieee,
372 struct cb_desc *tcb_desc)
373 {
374 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
375
376 tcb_desc->bUseShortGI = false;
377
378 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
379 return;
380
381 if (pHTInfo->bForcedShortGI) {
382 tcb_desc->bUseShortGI = true;
383 return;
384 }
385
386 if ((pHTInfo->bCurBW40MHz == true) && pHTInfo->bCurShortGI40MHz)
387 tcb_desc->bUseShortGI = true;
388 else if ((pHTInfo->bCurBW40MHz == false) && pHTInfo->bCurShortGI20MHz)
389 tcb_desc->bUseShortGI = true;
390 }
391
392 static void rtllib_query_BandwidthMode(struct rtllib_device *ieee,
393 struct cb_desc *tcb_desc)
394 {
395 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
396
397 tcb_desc->bPacketBW = false;
398
399 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
400 return;
401
402 if (tcb_desc->bMulticast || tcb_desc->bBroadcast)
403 return;
404
405 if ((tcb_desc->data_rate & 0x80) == 0)
406 return;
407 if (pHTInfo->bCurBW40MHz && pHTInfo->bCurTxBW40MHz &&
408 !ieee->bandwidth_auto_switch.bforced_tx20Mhz)
409 tcb_desc->bPacketBW = true;
410 }
411
412 static void rtllib_query_protectionmode(struct rtllib_device *ieee,
413 struct cb_desc *tcb_desc,
414 struct sk_buff *skb)
415 {
416 struct rt_hi_throughput *pHTInfo;
417
418 tcb_desc->bRTSSTBC = false;
419 tcb_desc->bRTSUseShortGI = false;
420 tcb_desc->bCTSEnable = false;
421 tcb_desc->RTSSC = 0;
422 tcb_desc->bRTSBW = false;
423
424 if (tcb_desc->bBroadcast || tcb_desc->bMulticast)
425 return;
426
427 if (is_broadcast_ether_addr(skb->data+16))
428 return;
429
430 if (ieee->mode < IEEE_N_24G) {
431 if (skb->len > ieee->rts) {
432 tcb_desc->bRTSEnable = true;
433 tcb_desc->rts_rate = MGN_24M;
434 } else if (ieee->current_network.buseprotection) {
435 tcb_desc->bRTSEnable = true;
436 tcb_desc->bCTSEnable = true;
437 tcb_desc->rts_rate = MGN_24M;
438 }
439 return;
440 }
441
442 pHTInfo = ieee->pHTInfo;
443
444 while (true) {
445 if (pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF) {
446 tcb_desc->bCTSEnable = true;
447 tcb_desc->rts_rate = MGN_24M;
448 tcb_desc->bRTSEnable = true;
449 break;
450 } else if (pHTInfo->IOTAction & (HT_IOT_ACT_FORCED_RTS |
451 HT_IOT_ACT_PURE_N_MODE)) {
452 tcb_desc->bRTSEnable = true;
453 tcb_desc->rts_rate = MGN_24M;
454 break;
455 }
456 if (ieee->current_network.buseprotection) {
457 tcb_desc->bRTSEnable = true;
458 tcb_desc->bCTSEnable = true;
459 tcb_desc->rts_rate = MGN_24M;
460 break;
461 }
462 if (pHTInfo->bCurrentHTSupport && pHTInfo->bEnableHT) {
463 u8 HTOpMode = pHTInfo->CurrentOpMode;
464
465 if ((pHTInfo->bCurBW40MHz && (HTOpMode == 2 ||
466 HTOpMode == 3)) ||
467 (!pHTInfo->bCurBW40MHz && HTOpMode == 3)) {
468 tcb_desc->rts_rate = MGN_24M;
469 tcb_desc->bRTSEnable = true;
470 break;
471 }
472 }
473 if (skb->len > ieee->rts) {
474 tcb_desc->rts_rate = MGN_24M;
475 tcb_desc->bRTSEnable = true;
476 break;
477 }
478 if (tcb_desc->bAMPDUEnable) {
479 tcb_desc->rts_rate = MGN_24M;
480 tcb_desc->bRTSEnable = false;
481 break;
482 }
483 goto NO_PROTECTION;
484 }
485 if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
486 tcb_desc->bUseShortPreamble = true;
487 if (ieee->iw_mode == IW_MODE_MASTER)
488 goto NO_PROTECTION;
489 return;
490 NO_PROTECTION:
491 tcb_desc->bRTSEnable = false;
492 tcb_desc->bCTSEnable = false;
493 tcb_desc->rts_rate = 0;
494 tcb_desc->RTSSC = 0;
495 tcb_desc->bRTSBW = false;
496 }
497
498
499 static void rtllib_txrate_selectmode(struct rtllib_device *ieee,
500 struct cb_desc *tcb_desc)
501 {
502 if (ieee->bTxDisableRateFallBack)
503 tcb_desc->bTxDisableRateFallBack = true;
504
505 if (ieee->bTxUseDriverAssingedRate)
506 tcb_desc->bTxUseDriverAssingedRate = true;
507 if (!tcb_desc->bTxDisableRateFallBack ||
508 !tcb_desc->bTxUseDriverAssingedRate) {
509 if (ieee->iw_mode == IW_MODE_INFRA ||
510 ieee->iw_mode == IW_MODE_ADHOC)
511 tcb_desc->RATRIndex = 0;
512 }
513 }
514
515 u16 rtllib_query_seqnum(struct rtllib_device *ieee, struct sk_buff *skb,
516 u8 *dst)
517 {
518 u16 seqnum = 0;
519
520 if (is_multicast_ether_addr(dst))
521 return 0;
522 if (IsQoSDataFrame(skb->data)) {
523 struct tx_ts_record *pTS = NULL;
524
525 if (!GetTs(ieee, (struct ts_common_info **)(&pTS), dst,
526 skb->priority, TX_DIR, true))
527 return 0;
528 seqnum = pTS->TxCurSeq;
529 pTS->TxCurSeq = (pTS->TxCurSeq+1)%4096;
530 return seqnum;
531 }
532 return 0;
533 }
534
535 static int wme_downgrade_ac(struct sk_buff *skb)
536 {
537 switch (skb->priority) {
538 case 6:
539 case 7:
540 skb->priority = 5; /* VO -> VI */
541 return 0;
542 case 4:
543 case 5:
544 skb->priority = 3; /* VI -> BE */
545 return 0;
546 case 0:
547 case 3:
548 skb->priority = 1; /* BE -> BK */
549 return 0;
550 default:
551 return -1;
552 }
553 }
554
555 static u8 rtllib_current_rate(struct rtllib_device *ieee)
556 {
557 if (ieee->mode & IEEE_MODE_MASK)
558 return ieee->rate;
559
560 if (ieee->HTCurrentOperaRate)
561 return ieee->HTCurrentOperaRate;
562 else
563 return ieee->rate & 0x7F;
564 }
565
566 int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
567 {
568 struct rtllib_device *ieee = (struct rtllib_device *)
569 netdev_priv_rsl(dev);
570 struct rtllib_txb *txb = NULL;
571 struct rtllib_hdr_3addrqos *frag_hdr;
572 int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size;
573 unsigned long flags;
574 struct net_device_stats *stats = &ieee->stats;
575 int ether_type = 0, encrypt;
576 int bytes, fc, qos_ctl = 0, hdr_len;
577 struct sk_buff *skb_frag;
578 struct rtllib_hdr_3addrqos header = { /* Ensure zero initialized */
579 .duration_id = 0,
580 .seq_ctl = 0,
581 .qos_ctl = 0
582 };
583 u8 dest[ETH_ALEN], src[ETH_ALEN];
584 int qos_actived = ieee->current_network.qos_data.active;
585 struct lib80211_crypt_data *crypt = NULL;
586 struct cb_desc *tcb_desc;
587 u8 bIsMulticast = false;
588 u8 IsAmsdu = false;
589 bool bdhcp = false;
590
591 spin_lock_irqsave(&ieee->lock, flags);
592
593 /* If there is no driver handler to take the TXB, don't bother
594 * creating it... */
595 if ((!ieee->hard_start_xmit && !(ieee->softmac_features &
596 IEEE_SOFTMAC_TX_QUEUE)) ||
597 ((!ieee->softmac_data_hard_start_xmit &&
598 (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) {
599 netdev_warn(ieee->dev, "No xmit handler.\n");
600 goto success;
601 }
602
603
604 if (likely(ieee->raw_tx == 0)) {
605 if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) {
606 netdev_warn(ieee->dev, "skb too small (%d).\n",
607 skb->len);
608 goto success;
609 }
610 /* Save source and destination addresses */
611 memcpy(dest, skb->data, ETH_ALEN);
612 memcpy(src, skb->data+ETH_ALEN, ETH_ALEN);
613
614 memset(skb->cb, 0, sizeof(skb->cb));
615 ether_type = ntohs(((struct ethhdr *)skb->data)->h_proto);
616
617 if (ieee->iw_mode == IW_MODE_MONITOR) {
618 txb = rtllib_alloc_txb(1, skb->len, GFP_ATOMIC);
619 if (unlikely(!txb)) {
620 netdev_warn(ieee->dev,
621 "Could not allocate TXB\n");
622 goto failed;
623 }
624
625 txb->encrypted = 0;
626 txb->payload_size = cpu_to_le16(skb->len);
627 memcpy(skb_put(txb->fragments[0], skb->len), skb->data,
628 skb->len);
629
630 goto success;
631 }
632
633 if (skb->len > 282) {
634 if (ETH_P_IP == ether_type) {
635 const struct iphdr *ip = (struct iphdr *)
636 ((u8 *)skb->data+14);
637 if (IPPROTO_UDP == ip->protocol) {
638 struct udphdr *udp;
639
640 udp = (struct udphdr *)((u8 *)ip +
641 (ip->ihl << 2));
642 if (((((u8 *)udp)[1] == 68) &&
643 (((u8 *)udp)[3] == 67)) ||
644 ((((u8 *)udp)[1] == 67) &&
645 (((u8 *)udp)[3] == 68))) {
646 bdhcp = true;
647 ieee->LPSDelayCnt = 200;
648 }
649 }
650 } else if (ETH_P_ARP == ether_type) {
651 netdev_info(ieee->dev,
652 "=================>DHCP Protocol start tx ARP pkt!!\n");
653 bdhcp = true;
654 ieee->LPSDelayCnt =
655 ieee->current_network.tim.tim_count;
656 }
657 }
658
659 skb->priority = rtllib_classify(skb, IsAmsdu);
660 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
661 encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) &&
662 ieee->host_encrypt && crypt && crypt->ops;
663 if (!encrypt && ieee->ieee802_1x &&
664 ieee->drop_unencrypted && ether_type != ETH_P_PAE) {
665 stats->tx_dropped++;
666 goto success;
667 }
668 if (crypt && !encrypt && ether_type == ETH_P_PAE) {
669 struct eapol *eap = (struct eapol *)(skb->data +
670 sizeof(struct ethhdr) - SNAP_SIZE -
671 sizeof(u16));
672 RTLLIB_DEBUG_EAP("TX: IEEE 802.11 EAPOL frame: %s\n",
673 eap_get_type(eap->type));
674 }
675
676 /* Advance the SKB to the start of the payload */
677 skb_pull(skb, sizeof(struct ethhdr));
678
679 /* Determine total amount of storage required for TXB packets */
680 bytes = skb->len + SNAP_SIZE + sizeof(u16);
681
682 if (encrypt)
683 fc = RTLLIB_FTYPE_DATA | RTLLIB_FCTL_WEP;
684 else
685 fc = RTLLIB_FTYPE_DATA;
686
687 if (qos_actived)
688 fc |= RTLLIB_STYPE_QOS_DATA;
689 else
690 fc |= RTLLIB_STYPE_DATA;
691
692 if (ieee->iw_mode == IW_MODE_INFRA) {
693 fc |= RTLLIB_FCTL_TODS;
694 /* To DS: Addr1 = BSSID, Addr2 = SA,
695 Addr3 = DA */
696 memcpy(&header.addr1, ieee->current_network.bssid,
697 ETH_ALEN);
698 memcpy(&header.addr2, &src, ETH_ALEN);
699 if (IsAmsdu)
700 memcpy(&header.addr3,
701 ieee->current_network.bssid, ETH_ALEN);
702 else
703 memcpy(&header.addr3, &dest, ETH_ALEN);
704 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
705 /* not From/To DS: Addr1 = DA, Addr2 = SA,
706 Addr3 = BSSID */
707 memcpy(&header.addr1, dest, ETH_ALEN);
708 memcpy(&header.addr2, src, ETH_ALEN);
709 memcpy(&header.addr3, ieee->current_network.bssid,
710 ETH_ALEN);
711 }
712
713 bIsMulticast = is_multicast_ether_addr(header.addr1);
714
715 header.frame_ctl = cpu_to_le16(fc);
716
717 /* Determine fragmentation size based on destination (multicast
718 * and broadcast are not fragmented) */
719 if (bIsMulticast) {
720 frag_size = MAX_FRAG_THRESHOLD;
721 qos_ctl |= QOS_CTL_NOTCONTAIN_ACK;
722 } else {
723 frag_size = ieee->fts;
724 qos_ctl = 0;
725 }
726
727 if (qos_actived) {
728 hdr_len = RTLLIB_3ADDR_LEN + 2;
729
730 /* in case we are a client verify acm is not set for this ac */
731 while (unlikely(ieee->wmm_acm & (0x01 << skb->priority))) {
732 netdev_info(ieee->dev, "skb->priority = %x\n",
733 skb->priority);
734 if (wme_downgrade_ac(skb))
735 break;
736 netdev_info(ieee->dev, "converted skb->priority = %x\n",
737 skb->priority);
738 }
739 qos_ctl |= skb->priority;
740 header.qos_ctl = cpu_to_le16(qos_ctl & RTLLIB_QOS_TID);
741 } else {
742 hdr_len = RTLLIB_3ADDR_LEN;
743 }
744 /* Determine amount of payload per fragment. Regardless of if
745 * this stack is providing the full 802.11 header, one will
746 * eventually be affixed to this fragment -- so we must account
747 * for it when determining the amount of payload space. */
748 bytes_per_frag = frag_size - hdr_len;
749 if (ieee->config &
750 (CFG_RTLLIB_COMPUTE_FCS | CFG_RTLLIB_RESERVE_FCS))
751 bytes_per_frag -= RTLLIB_FCS_LEN;
752
753 /* Each fragment may need to have room for encrypting
754 * pre/postfix */
755 if (encrypt) {
756 bytes_per_frag -= crypt->ops->extra_mpdu_prefix_len +
757 crypt->ops->extra_mpdu_postfix_len +
758 crypt->ops->extra_msdu_prefix_len +
759 crypt->ops->extra_msdu_postfix_len;
760 }
761 /* Number of fragments is the total bytes_per_frag /
762 * payload_per_fragment */
763 nr_frags = bytes / bytes_per_frag;
764 bytes_last_frag = bytes % bytes_per_frag;
765 if (bytes_last_frag)
766 nr_frags++;
767 else
768 bytes_last_frag = bytes_per_frag;
769
770 /* When we allocate the TXB we allocate enough space for the
771 * reserve and full fragment bytes (bytes_per_frag doesn't
772 * include prefix, postfix, header, FCS, etc.) */
773 txb = rtllib_alloc_txb(nr_frags, frag_size +
774 ieee->tx_headroom, GFP_ATOMIC);
775 if (unlikely(!txb)) {
776 netdev_warn(ieee->dev, "Could not allocate TXB\n");
777 goto failed;
778 }
779 txb->encrypted = encrypt;
780 txb->payload_size = cpu_to_le16(bytes);
781
782 if (qos_actived)
783 txb->queue_index = UP2AC(skb->priority);
784 else
785 txb->queue_index = WME_AC_BE;
786
787 for (i = 0; i < nr_frags; i++) {
788 skb_frag = txb->fragments[i];
789 tcb_desc = (struct cb_desc *)(skb_frag->cb +
790 MAX_DEV_ADDR_SIZE);
791 if (qos_actived) {
792 skb_frag->priority = skb->priority;
793 tcb_desc->queue_index = UP2AC(skb->priority);
794 } else {
795 skb_frag->priority = WME_AC_BE;
796 tcb_desc->queue_index = WME_AC_BE;
797 }
798 skb_reserve(skb_frag, ieee->tx_headroom);
799
800 if (encrypt) {
801 if (ieee->hwsec_active)
802 tcb_desc->bHwSec = 1;
803 else
804 tcb_desc->bHwSec = 0;
805 skb_reserve(skb_frag,
806 crypt->ops->extra_mpdu_prefix_len +
807 crypt->ops->extra_msdu_prefix_len);
808 } else {
809 tcb_desc->bHwSec = 0;
810 }
811 frag_hdr = (struct rtllib_hdr_3addrqos *)
812 skb_put(skb_frag, hdr_len);
813 memcpy(frag_hdr, &header, hdr_len);
814
815 /* If this is not the last fragment, then add the
816 * MOREFRAGS bit to the frame control */
817 if (i != nr_frags - 1) {
818 frag_hdr->frame_ctl = cpu_to_le16(
819 fc | RTLLIB_FCTL_MOREFRAGS);
820 bytes = bytes_per_frag;
821
822 } else {
823 /* The last fragment has the remaining length */
824 bytes = bytes_last_frag;
825 }
826 if ((qos_actived) && (!bIsMulticast)) {
827 frag_hdr->seq_ctl =
828 cpu_to_le16(rtllib_query_seqnum(ieee, skb_frag,
829 header.addr1));
830 frag_hdr->seq_ctl =
831 cpu_to_le16(le16_to_cpu(frag_hdr->seq_ctl)<<4 | i);
832 } else {
833 frag_hdr->seq_ctl =
834 cpu_to_le16(ieee->seq_ctrl[0]<<4 | i);
835 }
836 /* Put a SNAP header on the first fragment */
837 if (i == 0) {
838 rtllib_put_snap(
839 skb_put(skb_frag, SNAP_SIZE +
840 sizeof(u16)), ether_type);
841 bytes -= SNAP_SIZE + sizeof(u16);
842 }
843
844 memcpy(skb_put(skb_frag, bytes), skb->data, bytes);
845
846 /* Advance the SKB... */
847 skb_pull(skb, bytes);
848
849 /* Encryption routine will move the header forward in
850 * order to insert the IV between the header and the
851 * payload */
852 if (encrypt)
853 rtllib_encrypt_fragment(ieee, skb_frag,
854 hdr_len);
855 if (ieee->config &
856 (CFG_RTLLIB_COMPUTE_FCS | CFG_RTLLIB_RESERVE_FCS))
857 skb_put(skb_frag, 4);
858 }
859
860 if ((qos_actived) && (!bIsMulticast)) {
861 if (ieee->seq_ctrl[UP2AC(skb->priority) + 1] == 0xFFF)
862 ieee->seq_ctrl[UP2AC(skb->priority) + 1] = 0;
863 else
864 ieee->seq_ctrl[UP2AC(skb->priority) + 1]++;
865 } else {
866 if (ieee->seq_ctrl[0] == 0xFFF)
867 ieee->seq_ctrl[0] = 0;
868 else
869 ieee->seq_ctrl[0]++;
870 }
871 } else {
872 if (unlikely(skb->len < sizeof(struct rtllib_hdr_3addr))) {
873 netdev_warn(ieee->dev, "skb too small (%d).\n",
874 skb->len);
875 goto success;
876 }
877
878 txb = rtllib_alloc_txb(1, skb->len, GFP_ATOMIC);
879 if (!txb) {
880 netdev_warn(ieee->dev, "Could not allocate TXB\n");
881 goto failed;
882 }
883
884 txb->encrypted = 0;
885 txb->payload_size = cpu_to_le16(skb->len);
886 memcpy(skb_put(txb->fragments[0], skb->len), skb->data,
887 skb->len);
888 }
889
890 success:
891 if (txb) {
892 struct cb_desc *tcb_desc = (struct cb_desc *)
893 (txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE);
894 tcb_desc->bTxEnableFwCalcDur = 1;
895 tcb_desc->priority = skb->priority;
896
897 if (ether_type == ETH_P_PAE) {
898 if (ieee->pHTInfo->IOTAction &
899 HT_IOT_ACT_WA_IOT_Broadcom) {
900 tcb_desc->data_rate =
901 MgntQuery_TxRateExcludeCCKRates(ieee);
902 tcb_desc->bTxDisableRateFallBack = false;
903 } else {
904 tcb_desc->data_rate = ieee->basic_rate;
905 tcb_desc->bTxDisableRateFallBack = 1;
906 }
907
908
909 tcb_desc->RATRIndex = 7;
910 tcb_desc->bTxUseDriverAssingedRate = 1;
911 } else {
912 if (is_multicast_ether_addr(header.addr1))
913 tcb_desc->bMulticast = 1;
914 if (is_broadcast_ether_addr(header.addr1))
915 tcb_desc->bBroadcast = 1;
916 rtllib_txrate_selectmode(ieee, tcb_desc);
917 if (tcb_desc->bMulticast || tcb_desc->bBroadcast)
918 tcb_desc->data_rate = ieee->basic_rate;
919 else
920 tcb_desc->data_rate = rtllib_current_rate(ieee);
921
922 if (bdhcp) {
923 if (ieee->pHTInfo->IOTAction &
924 HT_IOT_ACT_WA_IOT_Broadcom) {
925 tcb_desc->data_rate =
926 MgntQuery_TxRateExcludeCCKRates(ieee);
927 tcb_desc->bTxDisableRateFallBack = false;
928 } else {
929 tcb_desc->data_rate = MGN_1M;
930 tcb_desc->bTxDisableRateFallBack = 1;
931 }
932
933
934 tcb_desc->RATRIndex = 7;
935 tcb_desc->bTxUseDriverAssingedRate = 1;
936 tcb_desc->bdhcp = 1;
937 }
938
939 rtllib_qurey_ShortPreambleMode(ieee, tcb_desc);
940 rtllib_tx_query_agg_cap(ieee, txb->fragments[0],
941 tcb_desc);
942 rtllib_query_HTCapShortGI(ieee, tcb_desc);
943 rtllib_query_BandwidthMode(ieee, tcb_desc);
944 rtllib_query_protectionmode(ieee, tcb_desc,
945 txb->fragments[0]);
946 }
947 }
948 spin_unlock_irqrestore(&ieee->lock, flags);
949 dev_kfree_skb_any(skb);
950 if (txb) {
951 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE) {
952 dev->stats.tx_packets++;
953 dev->stats.tx_bytes += le16_to_cpu(txb->payload_size);
954 rtllib_softmac_xmit(txb, ieee);
955 } else {
956 if ((*ieee->hard_start_xmit)(txb, dev) == 0) {
957 stats->tx_packets++;
958 stats->tx_bytes += le16_to_cpu(txb->payload_size);
959 return 0;
960 }
961 rtllib_txb_free(txb);
962 }
963 }
964
965 return 0;
966
967 failed:
968 spin_unlock_irqrestore(&ieee->lock, flags);
969 netif_stop_queue(dev);
970 stats->tx_errors++;
971 return 1;
972
973 }
974 int rtllib_xmit(struct sk_buff *skb, struct net_device *dev)
975 {
976 memset(skb->cb, 0, sizeof(skb->cb));
977 return rtllib_xmit_inter(skb, dev);
978 }
979 EXPORT_SYMBOL(rtllib_xmit);
This page took 0.05152 seconds and 5 git commands to generate.