1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved.
6 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
7 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
9 * Few modifications for Realtek's Wi-Fi drivers by
10 * Andrea Merello <andrea.merello@gmail.com>
12 * A special thanks goes to Realtek for their support !
14 #include <linux/compiler.h>
15 #include <linux/errno.h>
16 #include <linux/if_arp.h>
17 #include <linux/in6.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/netdevice.h>
23 #include <linux/pci.h>
24 #include <linux/proc_fs.h>
25 #include <linux/skbuff.h>
26 #include <linux/slab.h>
27 #include <linux/tcp.h>
28 #include <linux/types.h>
29 #include <linux/wireless.h>
30 #include <linux/etherdevice.h>
31 #include <linux/uaccess.h>
32 #include <linux/if_vlan.h>
39 * 802.11 frame_control for data frames - 2 bytes
40 * ,--------------------------------------------------------------------.
41 * bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e |
42 * |---|---|---|---|---|---|---|---|---|----|----|-----|-----|-----|----|
43 * val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x | x | x |
44 * |---|---|---|---|---|---|---|---|---|----|----|-----|-----|-----|----|
45 * desc | ver | type | ^-subtype-^ |to |from|more|retry| pwr |more |wep |
46 * | | | x=0 data |DS | DS |frag| | mgm |data | |
47 * | | | x=1 data+ack | | | | | | | |
48 * '--------------------------------------------------------------------'
52 * ,--------- 'ctrl' expands to >---'
54 * ,--'---,-------------------------------------------------------------.
55 * Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
56 * |------|------|---------|---------|---------|------|---------|------|
57 * Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs |
58 * | | tion | (BSSID) | | | ence | data | |
59 * `--------------------------------------------------| |------'
60 * Total: 28 non-data bytes `----.----'
62 * .- 'Frame data' expands to <---------------------------'
65 * ,---------------------------------------------------.
66 * Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 |
67 * |------|------|---------|----------|------|---------|
68 * Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
69 * | DSAP | SSAP | | | | Packet |
70 * | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
71 * `-----------------------------------------| |
72 * Total: 8 non-data bytes `----.----'
74 * .- 'IP Packet' expands, if WEP enabled, to <--'
77 * ,-----------------------.
78 * Bytes | 4 | 0-2296 | 4 |
79 * |-----|-----------|-----|
80 * Desc. | IV | Encrypted | ICV |
82 * `-----------------------'
83 * Total: 8 non-data bytes
86 * 802.3 Ethernet Data Frame
88 * ,-----------------------------------------.
89 * Bytes | 6 | 6 | 2 | Variable | 4 |
90 * |-------|-------|------|-----------|------|
91 * Desc. | Dest. | Source| Type | IP Packet | fcs |
93 * `-----------------------------------------'
94 * Total: 18 non-data bytes
96 * In the event that fragmentation is required, the incoming payload is split
97 * into N parts of size ieee->fts. The first fragment contains the SNAP header
98 * and the remaining packets are just data.
100 * If encryption is enabled, each fragment payload size is reduced by enough
101 * space to add the prefix and postfix (IV and ICV totalling 8 bytes in
102 * the case of WEP) So if you have 1500 bytes of payload with ieee->fts set to
103 * 500 without encryption it will take 3 frames. With WEP it will take 4 frames
104 * as the payload of each frame is reduced to 492 bytes.
110 * | ETHERNET HEADER ,-<-- PAYLOAD
111 * | | 14 bytes from skb->data
112 * | 2 bytes for Type --> ,T. | (sizeof ethhdr)
114 * |,-Dest.--. ,--Src.---. | | |
115 * | 6 bytes| | 6 bytes | | | |
118 * 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
121 * | | | | `T' <---- 2 bytes for Type
123 * | | '---SNAP--' <-------- 6 bytes for SNAP
125 * `-IV--' <-------------------- 4 bytes for IV (WEP)
131 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
132 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
134 static int rtllib_put_snap(u8 *data, u16 h_proto)
136 struct rtllib_snap_hdr *snap;
139 snap = (struct rtllib_snap_hdr *)data;
144 if (h_proto == 0x8137 || h_proto == 0x80f3)
148 snap->oui[0] = oui[0];
149 snap->oui[1] = oui[1];
150 snap->oui[2] = oui[2];
152 *(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
154 return SNAP_SIZE + sizeof(u16);
157 int rtllib_encrypt_fragment(struct rtllib_device *ieee, struct sk_buff *frag,
160 struct lib80211_crypt_data *crypt = NULL;
163 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
165 if (!(crypt && crypt->ops)) {
166 netdev_info(ieee->dev, "=========>%s(), crypt is null\n",
170 /* To encrypt, frame format is:
171 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes)
174 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so
175 * call both MSDU and MPDU encryption functions from here.
177 atomic_inc(&crypt->refcnt);
179 if (crypt->ops->encrypt_msdu)
180 res = crypt->ops->encrypt_msdu(frag, hdr_len, crypt->priv);
181 if (res == 0 && crypt->ops->encrypt_mpdu)
182 res = crypt->ops->encrypt_mpdu(frag, hdr_len, crypt->priv);
184 atomic_dec(&crypt->refcnt);
186 netdev_info(ieee->dev, "%s: Encryption failed: len=%d.\n",
187 ieee->dev->name, frag->len);
195 void rtllib_txb_free(struct rtllib_txb *txb)
202 static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,
205 struct rtllib_txb *txb;
208 txb = kmalloc(sizeof(struct rtllib_txb) + (sizeof(u8 *) * nr_frags),
213 memset(txb, 0, sizeof(struct rtllib_txb));
214 txb->nr_frags = nr_frags;
215 txb->frag_size = cpu_to_le16(txb_size);
217 for (i = 0; i < nr_frags; i++) {
218 txb->fragments[i] = dev_alloc_skb(txb_size);
219 if (unlikely(!txb->fragments[i])) {
223 memset(txb->fragments[i]->cb, 0, sizeof(txb->fragments[i]->cb));
225 if (unlikely(i != nr_frags)) {
227 dev_kfree_skb_any(txb->fragments[i--]);
234 static int rtllib_classify(struct sk_buff *skb, u8 bIsAmsdu)
239 eth = (struct ethhdr *)skb->data;
240 if (eth->h_proto != htons(ETH_P_IP))
244 print_hex_dump_bytes("%s: ", __func__, DUMP_PREFIX_NONE, skb->data,
248 switch (ip->tos & 0xfc) {
268 static void rtllib_tx_query_agg_cap(struct rtllib_device *ieee,
270 struct cb_desc *tcb_desc)
272 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
273 struct tx_ts_record *pTxTs = NULL;
274 struct rtllib_hdr_1addr *hdr = (struct rtllib_hdr_1addr *)skb->data;
276 if (rtllib_act_scanning(ieee, false))
279 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
281 if (!IsQoSDataFrame(skb->data))
283 if (is_multicast_ether_addr(hdr->addr1))
286 if (tcb_desc->bdhcp || ieee->CntAfterLink < 2)
289 if (pHTInfo->IOTAction & HT_IOT_ACT_TX_NO_AGGREGATION)
292 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev))
294 if (pHTInfo->bCurrentAMPDUEnable) {
295 if (!GetTs(ieee, (struct ts_common_info **)(&pTxTs), hdr->addr1,
296 skb->priority, TX_DIR, true)) {
297 netdev_info(ieee->dev, "%s: can't get TS\n", __func__);
300 if (pTxTs->TxAdmittedBARecord.bValid == false) {
301 if (ieee->wpa_ie_len && (ieee->pairwise_key_type ==
304 } else if (tcb_desc->bdhcp == 1) {
306 } else if (!pTxTs->bDisable_AddBa) {
307 TsStartAddBaProcess(ieee, pTxTs);
309 goto FORCED_AGG_SETTING;
310 } else if (pTxTs->bUsingBa == false) {
311 if (SN_LESS(pTxTs->TxAdmittedBARecord.BaStartSeqCtrl.field.SeqNum,
312 (pTxTs->TxCurSeq+1)%4096))
313 pTxTs->bUsingBa = true;
315 goto FORCED_AGG_SETTING;
317 if (ieee->iw_mode == IW_MODE_INFRA) {
318 tcb_desc->bAMPDUEnable = true;
319 tcb_desc->ampdu_factor = pHTInfo->CurrentAMPDUFactor;
320 tcb_desc->ampdu_density = pHTInfo->CurrentMPDUDensity;
324 switch (pHTInfo->ForcedAMPDUMode) {
328 case HT_AGG_FORCE_ENABLE:
329 tcb_desc->bAMPDUEnable = true;
330 tcb_desc->ampdu_density = pHTInfo->ForcedMPDUDensity;
331 tcb_desc->ampdu_factor = pHTInfo->ForcedAMPDUFactor;
334 case HT_AGG_FORCE_DISABLE:
335 tcb_desc->bAMPDUEnable = false;
336 tcb_desc->ampdu_density = 0;
337 tcb_desc->ampdu_factor = 0;
342 static void rtllib_qurey_ShortPreambleMode(struct rtllib_device *ieee,
343 struct cb_desc *tcb_desc)
345 tcb_desc->bUseShortPreamble = false;
346 if (tcb_desc->data_rate == 2)
348 else if (ieee->current_network.capability &
349 WLAN_CAPABILITY_SHORT_PREAMBLE)
350 tcb_desc->bUseShortPreamble = true;
353 static void rtllib_query_HTCapShortGI(struct rtllib_device *ieee,
354 struct cb_desc *tcb_desc)
356 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
358 tcb_desc->bUseShortGI = false;
360 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
363 if (pHTInfo->bForcedShortGI) {
364 tcb_desc->bUseShortGI = true;
368 if ((pHTInfo->bCurBW40MHz == true) && pHTInfo->bCurShortGI40MHz)
369 tcb_desc->bUseShortGI = true;
370 else if ((pHTInfo->bCurBW40MHz == false) && pHTInfo->bCurShortGI20MHz)
371 tcb_desc->bUseShortGI = true;
374 static void rtllib_query_BandwidthMode(struct rtllib_device *ieee,
375 struct cb_desc *tcb_desc)
377 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
379 tcb_desc->bPacketBW = false;
381 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
384 if (tcb_desc->bMulticast || tcb_desc->bBroadcast)
387 if ((tcb_desc->data_rate & 0x80) == 0)
389 if (pHTInfo->bCurBW40MHz && pHTInfo->bCurTxBW40MHz &&
390 !ieee->bandwidth_auto_switch.bforced_tx20Mhz)
391 tcb_desc->bPacketBW = true;
394 static void rtllib_query_protectionmode(struct rtllib_device *ieee,
395 struct cb_desc *tcb_desc,
398 struct rt_hi_throughput *pHTInfo;
400 tcb_desc->bRTSSTBC = false;
401 tcb_desc->bRTSUseShortGI = false;
402 tcb_desc->bCTSEnable = false;
404 tcb_desc->bRTSBW = false;
406 if (tcb_desc->bBroadcast || tcb_desc->bMulticast)
409 if (is_broadcast_ether_addr(skb->data+16))
412 if (ieee->mode < IEEE_N_24G) {
413 if (skb->len > ieee->rts) {
414 tcb_desc->bRTSEnable = true;
415 tcb_desc->rts_rate = MGN_24M;
416 } else if (ieee->current_network.buseprotection) {
417 tcb_desc->bRTSEnable = true;
418 tcb_desc->bCTSEnable = true;
419 tcb_desc->rts_rate = MGN_24M;
424 pHTInfo = ieee->pHTInfo;
427 if (pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF) {
428 tcb_desc->bCTSEnable = true;
429 tcb_desc->rts_rate = MGN_24M;
430 tcb_desc->bRTSEnable = true;
432 } else if (pHTInfo->IOTAction & (HT_IOT_ACT_FORCED_RTS |
433 HT_IOT_ACT_PURE_N_MODE)) {
434 tcb_desc->bRTSEnable = true;
435 tcb_desc->rts_rate = MGN_24M;
438 if (ieee->current_network.buseprotection) {
439 tcb_desc->bRTSEnable = true;
440 tcb_desc->bCTSEnable = true;
441 tcb_desc->rts_rate = MGN_24M;
444 if (pHTInfo->bCurrentHTSupport && pHTInfo->bEnableHT) {
445 u8 HTOpMode = pHTInfo->CurrentOpMode;
447 if ((pHTInfo->bCurBW40MHz && (HTOpMode == 2 ||
449 (!pHTInfo->bCurBW40MHz && HTOpMode == 3)) {
450 tcb_desc->rts_rate = MGN_24M;
451 tcb_desc->bRTSEnable = true;
455 if (skb->len > ieee->rts) {
456 tcb_desc->rts_rate = MGN_24M;
457 tcb_desc->bRTSEnable = true;
460 if (tcb_desc->bAMPDUEnable) {
461 tcb_desc->rts_rate = MGN_24M;
462 tcb_desc->bRTSEnable = false;
467 if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
468 tcb_desc->bUseShortPreamble = true;
469 if (ieee->iw_mode == IW_MODE_MASTER)
473 tcb_desc->bRTSEnable = false;
474 tcb_desc->bCTSEnable = false;
475 tcb_desc->rts_rate = 0;
477 tcb_desc->bRTSBW = false;
481 static void rtllib_txrate_selectmode(struct rtllib_device *ieee,
482 struct cb_desc *tcb_desc)
484 if (ieee->bTxDisableRateFallBack)
485 tcb_desc->bTxDisableRateFallBack = true;
487 if (ieee->bTxUseDriverAssingedRate)
488 tcb_desc->bTxUseDriverAssingedRate = true;
489 if (!tcb_desc->bTxDisableRateFallBack ||
490 !tcb_desc->bTxUseDriverAssingedRate) {
491 if (ieee->iw_mode == IW_MODE_INFRA ||
492 ieee->iw_mode == IW_MODE_ADHOC)
493 tcb_desc->RATRIndex = 0;
497 static u16 rtllib_query_seqnum(struct rtllib_device *ieee, struct sk_buff *skb,
502 if (is_multicast_ether_addr(dst))
504 if (IsQoSDataFrame(skb->data)) {
505 struct tx_ts_record *pTS = NULL;
507 if (!GetTs(ieee, (struct ts_common_info **)(&pTS), dst,
508 skb->priority, TX_DIR, true))
510 seqnum = pTS->TxCurSeq;
511 pTS->TxCurSeq = (pTS->TxCurSeq+1)%4096;
517 static int wme_downgrade_ac(struct sk_buff *skb)
519 switch (skb->priority) {
522 skb->priority = 5; /* VO -> VI */
526 skb->priority = 3; /* VI -> BE */
530 skb->priority = 1; /* BE -> BK */
537 static u8 rtllib_current_rate(struct rtllib_device *ieee)
539 if (ieee->mode & IEEE_MODE_MASK)
542 if (ieee->HTCurrentOperaRate)
543 return ieee->HTCurrentOperaRate;
545 return ieee->rate & 0x7F;
548 static int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
550 struct rtllib_device *ieee = (struct rtllib_device *)
551 netdev_priv_rsl(dev);
552 struct rtllib_txb *txb = NULL;
553 struct rtllib_hdr_3addrqos *frag_hdr;
554 int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size;
556 struct net_device_stats *stats = &ieee->stats;
557 int ether_type = 0, encrypt;
558 int bytes, fc, qos_ctl = 0, hdr_len;
559 struct sk_buff *skb_frag;
560 struct rtllib_hdr_3addrqos header = { /* Ensure zero initialized */
565 int qos_activated = ieee->current_network.qos_data.active;
568 struct lib80211_crypt_data *crypt = NULL;
569 struct cb_desc *tcb_desc;
570 u8 bIsMulticast = false;
574 spin_lock_irqsave(&ieee->lock, flags);
576 /* If there is no driver handler to take the TXB, don't bother
579 if ((!ieee->hard_start_xmit && !(ieee->softmac_features &
580 IEEE_SOFTMAC_TX_QUEUE)) ||
581 ((!ieee->softmac_data_hard_start_xmit &&
582 (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) {
583 netdev_warn(ieee->dev, "No xmit handler.\n");
588 if (likely(ieee->raw_tx == 0)) {
589 if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) {
590 netdev_warn(ieee->dev, "skb too small (%d).\n",
594 /* Save source and destination addresses */
595 ether_addr_copy(dest, skb->data);
596 ether_addr_copy(src, skb->data + ETH_ALEN);
598 memset(skb->cb, 0, sizeof(skb->cb));
599 ether_type = ntohs(((struct ethhdr *)skb->data)->h_proto);
601 if (ieee->iw_mode == IW_MODE_MONITOR) {
602 txb = rtllib_alloc_txb(1, skb->len, GFP_ATOMIC);
603 if (unlikely(!txb)) {
604 netdev_warn(ieee->dev,
605 "Could not allocate TXB\n");
610 txb->payload_size = cpu_to_le16(skb->len);
611 skb_put_data(txb->fragments[0], skb->data, skb->len);
616 if (skb->len > 282) {
617 if (ether_type == ETH_P_IP) {
618 const struct iphdr *ip = (struct iphdr *)
619 ((u8 *)skb->data+14);
620 if (ip->protocol == IPPROTO_UDP) {
623 udp = (struct udphdr *)((u8 *)ip +
625 if (((((u8 *)udp)[1] == 68) &&
626 (((u8 *)udp)[3] == 67)) ||
627 ((((u8 *)udp)[1] == 67) &&
628 (((u8 *)udp)[3] == 68))) {
630 ieee->LPSDelayCnt = 200;
633 } else if (ether_type == ETH_P_ARP) {
634 netdev_info(ieee->dev,
635 "=================>DHCP Protocol start tx ARP pkt!!\n");
638 ieee->current_network.tim.tim_count;
642 skb->priority = rtllib_classify(skb, IsAmsdu);
643 crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
644 encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) &&
645 ieee->host_encrypt && crypt && crypt->ops;
646 if (!encrypt && ieee->ieee802_1x &&
647 ieee->drop_unencrypted && ether_type != ETH_P_PAE) {
651 if (crypt && !encrypt && ether_type == ETH_P_PAE) {
652 struct eapol *eap = (struct eapol *)(skb->data +
653 sizeof(struct ethhdr) - SNAP_SIZE -
655 netdev_dbg(ieee->dev,
656 "TX: IEEE 802.11 EAPOL frame: %s\n",
657 eap_get_type(eap->type));
660 /* Advance the SKB to the start of the payload */
661 skb_pull(skb, sizeof(struct ethhdr));
663 /* Determine total amount of storage required for TXB packets */
664 bytes = skb->len + SNAP_SIZE + sizeof(u16);
667 fc = RTLLIB_FTYPE_DATA | RTLLIB_FCTL_WEP;
669 fc = RTLLIB_FTYPE_DATA;
672 fc |= RTLLIB_STYPE_QOS_DATA;
674 fc |= RTLLIB_STYPE_DATA;
676 if (ieee->iw_mode == IW_MODE_INFRA) {
677 fc |= RTLLIB_FCTL_TODS;
678 /* To DS: Addr1 = BSSID, Addr2 = SA,
681 ether_addr_copy(header.addr1,
682 ieee->current_network.bssid);
683 ether_addr_copy(header.addr2, src);
685 ether_addr_copy(header.addr3,
686 ieee->current_network.bssid);
688 ether_addr_copy(header.addr3, dest);
689 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
690 /* not From/To DS: Addr1 = DA, Addr2 = SA,
693 ether_addr_copy(header.addr1, dest);
694 ether_addr_copy(header.addr2, src);
695 ether_addr_copy(header.addr3,
696 ieee->current_network.bssid);
699 bIsMulticast = is_multicast_ether_addr(header.addr1);
701 header.frame_ctl = cpu_to_le16(fc);
703 /* Determine fragmentation size based on destination (multicast
704 * and broadcast are not fragmented)
707 frag_size = MAX_FRAG_THRESHOLD;
708 qos_ctl |= QOS_CTL_NOTCONTAIN_ACK;
710 frag_size = ieee->fts;
715 hdr_len = RTLLIB_3ADDR_LEN + 2;
717 /* in case we are a client verify acm is not set for this ac */
718 while (unlikely(ieee->wmm_acm & (0x01 << skb->priority))) {
719 netdev_info(ieee->dev, "skb->priority = %x\n",
721 if (wme_downgrade_ac(skb))
723 netdev_info(ieee->dev, "converted skb->priority = %x\n",
727 qos_ctl |= skb->priority;
728 header.qos_ctl = cpu_to_le16(qos_ctl & RTLLIB_QOS_TID);
731 hdr_len = RTLLIB_3ADDR_LEN;
733 /* Determine amount of payload per fragment. Regardless of if
734 * this stack is providing the full 802.11 header, one will
735 * eventually be affixed to this fragment -- so we must account
736 * for it when determining the amount of payload space.
738 bytes_per_frag = frag_size - hdr_len;
740 (CFG_RTLLIB_COMPUTE_FCS | CFG_RTLLIB_RESERVE_FCS))
741 bytes_per_frag -= RTLLIB_FCS_LEN;
743 /* Each fragment may need to have room for encrypting
747 bytes_per_frag -= crypt->ops->extra_mpdu_prefix_len +
748 crypt->ops->extra_mpdu_postfix_len +
749 crypt->ops->extra_msdu_prefix_len +
750 crypt->ops->extra_msdu_postfix_len;
752 /* Number of fragments is the total bytes_per_frag /
753 * payload_per_fragment
755 nr_frags = bytes / bytes_per_frag;
756 bytes_last_frag = bytes % bytes_per_frag;
760 bytes_last_frag = bytes_per_frag;
762 /* When we allocate the TXB we allocate enough space for the
763 * reserve and full fragment bytes (bytes_per_frag doesn't
764 * include prefix, postfix, header, FCS, etc.)
766 txb = rtllib_alloc_txb(nr_frags, frag_size +
767 ieee->tx_headroom, GFP_ATOMIC);
768 if (unlikely(!txb)) {
769 netdev_warn(ieee->dev, "Could not allocate TXB\n");
772 txb->encrypted = encrypt;
773 txb->payload_size = cpu_to_le16(bytes);
776 txb->queue_index = UP2AC(skb->priority);
778 txb->queue_index = WME_AC_BE;
780 for (i = 0; i < nr_frags; i++) {
781 skb_frag = txb->fragments[i];
782 tcb_desc = (struct cb_desc *)(skb_frag->cb +
785 skb_frag->priority = skb->priority;
786 tcb_desc->queue_index = UP2AC(skb->priority);
788 skb_frag->priority = WME_AC_BE;
789 tcb_desc->queue_index = WME_AC_BE;
791 skb_reserve(skb_frag, ieee->tx_headroom);
794 if (ieee->hwsec_active)
795 tcb_desc->bHwSec = 1;
797 tcb_desc->bHwSec = 0;
798 skb_reserve(skb_frag,
799 crypt->ops->extra_mpdu_prefix_len +
800 crypt->ops->extra_msdu_prefix_len);
802 tcb_desc->bHwSec = 0;
804 frag_hdr = skb_put_data(skb_frag, &header, hdr_len);
806 /* If this is not the last fragment, then add the
807 * MOREFRAGS bit to the frame control
809 if (i != nr_frags - 1) {
810 frag_hdr->frame_ctl = cpu_to_le16(
811 fc | RTLLIB_FCTL_MOREFRAGS);
812 bytes = bytes_per_frag;
815 /* The last fragment has the remaining length */
816 bytes = bytes_last_frag;
818 if ((qos_activated) && (!bIsMulticast)) {
820 cpu_to_le16(rtllib_query_seqnum(ieee, skb_frag,
823 cpu_to_le16(le16_to_cpu(frag_hdr->seq_ctl)<<4 | i);
826 cpu_to_le16(ieee->seq_ctrl[0]<<4 | i);
828 /* Put a SNAP header on the first fragment */
831 skb_put(skb_frag, SNAP_SIZE +
832 sizeof(u16)), ether_type);
833 bytes -= SNAP_SIZE + sizeof(u16);
836 skb_put_data(skb_frag, skb->data, bytes);
838 /* Advance the SKB... */
839 skb_pull(skb, bytes);
841 /* Encryption routine will move the header forward in
842 * order to insert the IV between the header and the
846 rtllib_encrypt_fragment(ieee, skb_frag,
849 (CFG_RTLLIB_COMPUTE_FCS | CFG_RTLLIB_RESERVE_FCS))
850 skb_put(skb_frag, 4);
853 if ((qos_activated) && (!bIsMulticast)) {
854 if (ieee->seq_ctrl[UP2AC(skb->priority) + 1] == 0xFFF)
855 ieee->seq_ctrl[UP2AC(skb->priority) + 1] = 0;
857 ieee->seq_ctrl[UP2AC(skb->priority) + 1]++;
859 if (ieee->seq_ctrl[0] == 0xFFF)
860 ieee->seq_ctrl[0] = 0;
865 if (unlikely(skb->len < sizeof(struct rtllib_hdr_3addr))) {
866 netdev_warn(ieee->dev, "skb too small (%d).\n",
871 txb = rtllib_alloc_txb(1, skb->len, GFP_ATOMIC);
873 netdev_warn(ieee->dev, "Could not allocate TXB\n");
878 txb->payload_size = cpu_to_le16(skb->len);
879 skb_put_data(txb->fragments[0], skb->data, skb->len);
884 struct cb_desc *tcb_desc = (struct cb_desc *)
885 (txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE);
886 tcb_desc->bTxEnableFwCalcDur = 1;
887 tcb_desc->priority = skb->priority;
889 if (ether_type == ETH_P_PAE) {
890 if (ieee->pHTInfo->IOTAction &
891 HT_IOT_ACT_WA_IOT_Broadcom) {
892 tcb_desc->data_rate =
893 MgntQuery_TxRateExcludeCCKRates(ieee);
894 tcb_desc->bTxDisableRateFallBack = false;
896 tcb_desc->data_rate = ieee->basic_rate;
897 tcb_desc->bTxDisableRateFallBack = 1;
901 tcb_desc->RATRIndex = 7;
902 tcb_desc->bTxUseDriverAssingedRate = 1;
904 if (is_multicast_ether_addr(header.addr1))
905 tcb_desc->bMulticast = 1;
906 if (is_broadcast_ether_addr(header.addr1))
907 tcb_desc->bBroadcast = 1;
908 rtllib_txrate_selectmode(ieee, tcb_desc);
909 if (tcb_desc->bMulticast || tcb_desc->bBroadcast)
910 tcb_desc->data_rate = ieee->basic_rate;
912 tcb_desc->data_rate = rtllib_current_rate(ieee);
915 if (ieee->pHTInfo->IOTAction &
916 HT_IOT_ACT_WA_IOT_Broadcom) {
917 tcb_desc->data_rate =
918 MgntQuery_TxRateExcludeCCKRates(ieee);
919 tcb_desc->bTxDisableRateFallBack = false;
921 tcb_desc->data_rate = MGN_1M;
922 tcb_desc->bTxDisableRateFallBack = 1;
926 tcb_desc->RATRIndex = 7;
927 tcb_desc->bTxUseDriverAssingedRate = 1;
931 rtllib_qurey_ShortPreambleMode(ieee, tcb_desc);
932 rtllib_tx_query_agg_cap(ieee, txb->fragments[0],
934 rtllib_query_HTCapShortGI(ieee, tcb_desc);
935 rtllib_query_BandwidthMode(ieee, tcb_desc);
936 rtllib_query_protectionmode(ieee, tcb_desc,
940 spin_unlock_irqrestore(&ieee->lock, flags);
941 dev_kfree_skb_any(skb);
943 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE) {
944 dev->stats.tx_packets++;
945 dev->stats.tx_bytes += le16_to_cpu(txb->payload_size);
946 rtllib_softmac_xmit(txb, ieee);
948 if ((*ieee->hard_start_xmit)(txb, dev) == 0) {
950 stats->tx_bytes += le16_to_cpu(txb->payload_size);
953 rtllib_txb_free(txb);
960 spin_unlock_irqrestore(&ieee->lock, flags);
961 netif_stop_queue(dev);
967 int rtllib_xmit(struct sk_buff *skb, struct net_device *dev)
969 memset(skb->cb, 0, sizeof(skb->cb));
970 return rtllib_xmit_inter(skb, dev);
972 EXPORT_SYMBOL(rtllib_xmit);