Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * File: rxtx.c |
| 20 | * |
| 21 | * Purpose: handle WMAC/802.3/802.11 rx & tx functions |
| 22 | * |
| 23 | * Author: Lyndon Chen |
| 24 | * |
| 25 | * Date: May 20, 2003 |
| 26 | * |
| 27 | * Functions: |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 28 | * s_vGenerateTxParameter - Generate tx dma required parameter. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 29 | * s_vGenerateMACHeader - Translate 802.3 to 802.11 header |
| 30 | * csBeacon_xmit - beacon tx function |
| 31 | * csMgmt_xmit - management tx function |
| 32 | * s_uGetDataDuration - get tx data required duration |
| 33 | * s_uFillDataHead- fulfill tx data duration header |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 34 | * s_uGetRTSCTSDuration- get rtx/cts required duration |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 35 | * s_uGetRTSCTSRsvTime- get rts/cts reserved time |
| 36 | * s_uGetTxRsvTime- get frame reserved time |
| 37 | * s_vFillCTSHead- fulfill CTS ctl header |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 38 | * s_vFillFragParameter- Set fragment ctl parameter. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 39 | * s_vFillRTSHead- fulfill RTS ctl header |
| 40 | * s_vFillTxKey- fulfill tx encrypt key |
| 41 | * s_vSWencryption- Software encrypt header |
| 42 | * vDMA0_tx_80211- tx 802.11 frame via dma0 |
| 43 | * vGenerateFIFOHeader- Generate tx FIFO ctl header |
| 44 | * |
| 45 | * Revision History: |
| 46 | * |
| 47 | */ |
| 48 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 49 | #include "device.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 50 | #include "rxtx.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 51 | #include "tether.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 52 | #include "card.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 53 | #include "bssdb.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 54 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 55 | #include "michael.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 56 | #include "tkip.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 57 | #include "wctl.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 58 | #include "rf.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 59 | #include "datarate.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 60 | #include "usbpipe.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 61 | #include "iocmd.h" |
Jim Lieb | 9d26d60 | 2009-08-12 14:54:08 -0700 | [diff] [blame] | 62 | |
Mariano Reingart | 4a499de | 2010-10-29 19:15:26 -0300 | [diff] [blame] | 63 | static int msglevel = MSG_LEVEL_INFO; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 64 | |
Valentina Manea | 3b13885 | 2013-11-04 10:44:02 +0200 | [diff] [blame] | 65 | static const u16 wTimeStampOff[2][MAX_RATE] = { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 66 | {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble |
| 67 | {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble |
| 68 | }; |
| 69 | |
Valentina Manea | 3b13885 | 2013-11-04 10:44:02 +0200 | [diff] [blame] | 70 | static const u16 wFB_Opt0[2][5] = { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 71 | {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0 |
| 72 | {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1 |
| 73 | }; |
Valentina Manea | 3b13885 | 2013-11-04 10:44:02 +0200 | [diff] [blame] | 74 | static const u16 wFB_Opt1[2][5] = { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 75 | {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0 |
| 76 | {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1 |
| 77 | }; |
| 78 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 79 | #define RTSDUR_BB 0 |
| 80 | #define RTSDUR_BA 1 |
| 81 | #define RTSDUR_AA 2 |
| 82 | #define CTSDUR_BA 3 |
| 83 | #define RTSDUR_BA_F0 4 |
| 84 | #define RTSDUR_AA_F0 5 |
| 85 | #define RTSDUR_BA_F1 6 |
| 86 | #define RTSDUR_AA_F1 7 |
| 87 | #define CTSDUR_BA_F0 8 |
| 88 | #define CTSDUR_BA_F1 9 |
| 89 | #define DATADUR_B 10 |
| 90 | #define DATADUR_A 11 |
| 91 | #define DATADUR_A_F0 12 |
| 92 | #define DATADUR_A_F1 13 |
| 93 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 94 | static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum, |
| 95 | u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 96 | |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 97 | static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *); |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 98 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 99 | static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 8e344c8 | 2013-09-17 19:58:11 +0100 | [diff] [blame] | 100 | u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer, |
Malcolm Priestley | fa57560 | 2013-09-26 19:00:41 +0100 | [diff] [blame] | 101 | struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 102 | int bNeedACK, struct ethhdr *psEthHeader, bool need_rts); |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 103 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 104 | static void s_vGenerateMACHeader(struct vnt_private *pDevice, |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 105 | struct ieee80211_hdr *pMACHeader, u16 wDuration, |
| 106 | struct ethhdr *psEthHeader, int bNeedEncrypt, u16 wFragType, |
| 107 | u32 uFragIdx); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 108 | |
Malcolm Priestley | 3695c46 | 2014-05-31 13:34:59 +0100 | [diff] [blame] | 109 | static void s_vFillTxKey(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 3ba0938 | 2013-10-15 21:41:38 +0100 | [diff] [blame] | 110 | struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead, |
Malcolm Priestley | 3695c46 | 2014-05-31 13:34:59 +0100 | [diff] [blame] | 111 | PSKeyItem pTransmitKey, u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 112 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 113 | static void s_vSWencryption(struct vnt_private *pDevice, |
| 114 | PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 115 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 116 | static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType, |
| 117 | u32 cbFrameLength, u16 wRate, int bNeedAck); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 118 | |
Malcolm Priestley | 2033801 | 2014-03-18 19:25:08 +0000 | [diff] [blame] | 119 | static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv, |
Malcolm Priestley | 3b6cee7be | 2014-05-25 21:36:27 +0100 | [diff] [blame] | 120 | u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 121 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 122 | static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 5fb8e41 | 2013-08-27 12:07:58 +0100 | [diff] [blame] | 123 | u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength, |
| 124 | int bNeedAck, u16 wCurrentRate, u8 byFBOption); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 125 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 126 | static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType, |
Malcolm Priestley | 5fb8e41 | 2013-08-27 12:07:58 +0100 | [diff] [blame] | 127 | union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck, |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 128 | struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 129 | |
Malcolm Priestley | 5abe3d6 | 2014-03-18 19:25:06 +0000 | [diff] [blame] | 130 | static __le16 s_uGetDataDuration(struct vnt_private *pDevice, |
Malcolm Priestley | 3ed210e | 2013-08-07 21:28:45 +0100 | [diff] [blame] | 131 | u8 byPktType, int bNeedAck); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 132 | |
Malcolm Priestley | 7f591a1 | 2014-03-18 19:25:05 +0000 | [diff] [blame] | 133 | static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 134 | u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate, |
| 135 | int bNeedAck, u8 byFBOption); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 136 | |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 137 | static struct vnt_usb_send_context |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 138 | *s_vGetFreeContext(struct vnt_private *priv) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 139 | { |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 140 | struct vnt_usb_send_context *context = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 141 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 142 | |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 143 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 144 | |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 145 | for (ii = 0; ii < priv->cbTD; ii++) { |
| 146 | if (!priv->apTD[ii]) |
| 147 | return NULL; |
| 148 | |
| 149 | context = priv->apTD[ii]; |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 150 | if (context->in_use == false) { |
| 151 | context->in_use = true; |
| 152 | memset(context->data, 0, |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 153 | MAX_TOTAL_SIZE_WITH_ALL_HEADERS); |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 154 | |
| 155 | context->hdr = NULL; |
| 156 | |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 157 | return context; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if (ii == priv->cbTD) |
| 162 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n"); |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 163 | |
Malcolm Priestley | 5c85138 | 2013-11-26 19:12:38 +0000 | [diff] [blame] | 164 | return NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 165 | } |
| 166 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 167 | static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum, |
| 168 | u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 169 | { |
Malcolm Priestley | ae27b14 | 2013-12-09 22:23:19 +0000 | [diff] [blame] | 170 | struct net_device_stats *stats = &pDevice->stats; |
Malcolm Priestley | 51934e7 | 2013-12-09 22:30:14 +0000 | [diff] [blame] | 171 | struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 172 | |
Malcolm Priestley | 51934e7 | 2013-12-09 22:30:14 +0000 | [diff] [blame] | 173 | pkt_info[byPktNum].fifo_ctl = wFIFOCtl; |
| 174 | memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN); |
Malcolm Priestley | ae27b14 | 2013-12-09 22:23:19 +0000 | [diff] [blame] | 175 | |
| 176 | stats->tx_bytes += wPktLength; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 177 | } |
| 178 | |
Malcolm Priestley | 3695c46 | 2014-05-31 13:34:59 +0100 | [diff] [blame] | 179 | static void s_vFillTxKey(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 3ba0938 | 2013-10-15 21:41:38 +0100 | [diff] [blame] | 180 | struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead, |
Malcolm Priestley | 3695c46 | 2014-05-31 13:34:59 +0100 | [diff] [blame] | 181 | PSKeyItem pTransmitKey, u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 182 | { |
Malcolm Priestley | 3695c46 | 2014-05-31 13:34:59 +0100 | [diff] [blame] | 183 | struct vnt_private *pDevice = tx_context->priv; |
| 184 | struct ieee80211_hdr *pMACHeader = tx_context->hdr; |
Malcolm Priestley | ab51f51 | 2014-05-31 13:35:00 +0100 | [diff] [blame] | 185 | u8 *pbyBuf = fifo_head->tx_key; |
Malcolm Priestley | fb453db | 2014-03-22 09:01:24 +0000 | [diff] [blame] | 186 | __le32 *pdwIV = (__le32 *)pbyIVHead; |
Malcolm Priestley | 2fbb230 | 2014-03-22 09:01:25 +0000 | [diff] [blame] | 187 | __le32 *pdwExtIV = (__le32 *)((u8 *)pbyIVHead + 4); |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 188 | __le32 rev_iv_counter; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 189 | |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 190 | /* Fill TXKEY */ |
| 191 | if (pTransmitKey == NULL) |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 192 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 193 | |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 194 | rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter); |
Malcolm Priestley | fb453db | 2014-03-22 09:01:24 +0000 | [diff] [blame] | 195 | *pdwIV = cpu_to_le32(pDevice->dwIVCounter); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 196 | pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 197 | |
Malcolm Priestley | f6804f3 | 2013-08-27 12:32:01 +0100 | [diff] [blame] | 198 | switch (pTransmitKey->byCipherSuite) { |
| 199 | case KEY_CTL_WEP: |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 200 | if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) { |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 201 | memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 202 | memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey, |
| 203 | pTransmitKey->uKeyLength); |
| 204 | } else { |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 205 | memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 206 | memcpy(pbyBuf + 3, pTransmitKey->abyKey, |
| 207 | pTransmitKey->uKeyLength); |
| 208 | if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) { |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 209 | memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3); |
Malcolm Priestley | 5cb5bff7 | 2014-05-25 21:36:28 +0100 | [diff] [blame] | 210 | memcpy(pbyBuf+11, pTransmitKey->abyKey, |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 211 | pTransmitKey->uKeyLength); |
| 212 | } |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 213 | |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 214 | memcpy(pDevice->abyPRNG, pbyBuf, 16); |
| 215 | } |
| 216 | /* Append IV after Mac Header */ |
Malcolm Priestley | fb453db | 2014-03-22 09:01:24 +0000 | [diff] [blame] | 217 | *pdwIV &= cpu_to_le32(WEP_IV_MASK); |
| 218 | *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30); |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 219 | |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 220 | pDevice->dwIVCounter++; |
| 221 | if (pDevice->dwIVCounter > WEP_IV_MASK) |
| 222 | pDevice->dwIVCounter = 0; |
Malcolm Priestley | f6804f3 | 2013-08-27 12:32:01 +0100 | [diff] [blame] | 223 | |
| 224 | break; |
| 225 | case KEY_CTL_TKIP: |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 226 | pTransmitKey->wTSC15_0++; |
| 227 | if (pTransmitKey->wTSC15_0 == 0) |
| 228 | pTransmitKey->dwTSC47_16++; |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 229 | |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 230 | TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr, |
| 231 | pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, |
| 232 | pDevice->abyPRNG); |
| 233 | memcpy(pbyBuf, pDevice->abyPRNG, 16); |
| 234 | |
| 235 | /* Make IV */ |
| 236 | memcpy(pdwIV, pDevice->abyPRNG, 3); |
| 237 | |
| 238 | *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & |
| 239 | 0xc0) | 0x20); |
| 240 | /* Append IV&ExtIV after Mac Header */ |
| 241 | *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16); |
| 242 | |
| 243 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 244 | "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV); |
| 245 | |
Malcolm Priestley | f6804f3 | 2013-08-27 12:32:01 +0100 | [diff] [blame] | 246 | break; |
| 247 | case KEY_CTL_CCMP: |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 248 | pTransmitKey->wTSC15_0++; |
| 249 | if (pTransmitKey->wTSC15_0 == 0) |
| 250 | pTransmitKey->dwTSC47_16++; |
| 251 | |
| 252 | memcpy(pbyBuf, pTransmitKey->abyKey, 16); |
| 253 | |
| 254 | /* Make IV */ |
| 255 | *pdwIV = 0; |
| 256 | *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & |
| 257 | 0xc0) | 0x20); |
| 258 | |
Malcolm Priestley | fb453db | 2014-03-22 09:01:24 +0000 | [diff] [blame] | 259 | *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0)); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 260 | |
| 261 | /* Append IV&ExtIV after Mac Header */ |
| 262 | *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16); |
| 263 | |
| 264 | if (!mic_hdr) |
| 265 | return; |
| 266 | |
| 267 | /* MICHDR0 */ |
| 268 | mic_hdr->id = 0x59; |
| 269 | mic_hdr->payload_len = cpu_to_be16(wPayloadLen); |
| 270 | memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN); |
| 271 | |
| 272 | mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16); |
| 273 | mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0); |
| 274 | |
| 275 | /* MICHDR1 */ |
Malcolm Priestley | 078d0cf | 2013-11-25 22:14:16 +0000 | [diff] [blame] | 276 | if (ieee80211_has_a4(pMACHeader->frame_control)) |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 277 | mic_hdr->hlen = cpu_to_be16(28); |
| 278 | else |
| 279 | mic_hdr->hlen = cpu_to_be16(22); |
| 280 | |
| 281 | memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN); |
| 282 | memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN); |
| 283 | |
| 284 | /* MICHDR2 */ |
| 285 | memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN); |
Malcolm Priestley | 5d4fe75 | 2014-03-22 09:01:26 +0000 | [diff] [blame] | 286 | mic_hdr->frame_control = cpu_to_le16( |
| 287 | le16_to_cpu(pMACHeader->frame_control) & 0xc78f); |
| 288 | mic_hdr->seq_ctrl = cpu_to_le16( |
| 289 | le16_to_cpu(pMACHeader->seq_ctrl) & 0xf); |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 290 | |
Malcolm Priestley | 078d0cf | 2013-11-25 22:14:16 +0000 | [diff] [blame] | 291 | if (ieee80211_has_a4(pMACHeader->frame_control)) |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 292 | memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN); |
| 293 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 296 | static void s_vSWencryption(struct vnt_private *pDevice, |
| 297 | PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 298 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 299 | u32 cbICVlen = 4; |
| 300 | u32 dwICV = 0xffffffff; |
| 301 | u32 *pdwICV; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 302 | |
| 303 | if (pTransmitKey == NULL) |
| 304 | return; |
| 305 | |
| 306 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { |
| 307 | //======================================================================= |
| 308 | // Append ICV after payload |
Malcolm Priestley | 929cb31 | 2014-05-21 21:09:42 +0100 | [diff] [blame] | 309 | dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead); |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 310 | pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 311 | // finally, we must invert dwCRC to get the correct answer |
| 312 | *pdwICV = cpu_to_le32(~dwICV); |
| 313 | // RC4 encryption |
| 314 | rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3); |
| 315 | rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen); |
| 316 | //======================================================================= |
| 317 | } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { |
| 318 | //======================================================================= |
| 319 | //Append ICV after payload |
Malcolm Priestley | 929cb31 | 2014-05-21 21:09:42 +0100 | [diff] [blame] | 320 | dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead); |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 321 | pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 322 | // finally, we must invert dwCRC to get the correct answer |
| 323 | *pdwICV = cpu_to_le32(~dwICV); |
| 324 | // RC4 encryption |
| 325 | rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN); |
| 326 | rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen); |
| 327 | //======================================================================= |
| 328 | } |
| 329 | } |
| 330 | |
Malcolm Priestley | dab085b | 2014-03-18 19:25:03 +0000 | [diff] [blame] | 331 | static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate) |
Malcolm Priestley | f115e76 | 2013-08-23 11:48:46 +0100 | [diff] [blame] | 332 | { |
| 333 | return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2] |
| 334 | [rate % MAX_RATE]); |
| 335 | } |
| 336 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 337 | /*byPktType : PK_TYPE_11A 0 |
| 338 | PK_TYPE_11B 1 |
| 339 | PK_TYPE_11GB 2 |
| 340 | PK_TYPE_11GA 3 |
| 341 | */ |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 342 | static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type, |
| 343 | u32 frame_length, u16 rate, int need_ack) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 344 | { |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 345 | u32 data_time, ack_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 346 | |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 347 | data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 348 | frame_length, rate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 349 | |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 350 | if (pkt_type == PK_TYPE_11B) |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 351 | ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
| 352 | 14, (u16)priv->byTopCCKBasicRate); |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 353 | else |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 354 | ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
| 355 | 14, (u16)priv->byTopOFDMBasicRate); |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 356 | |
| 357 | if (need_ack) |
| 358 | return data_time + priv->uSIFS + ack_time; |
| 359 | |
| 360 | return data_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 361 | } |
| 362 | |
Malcolm Priestley | 2075f65 | 2014-03-18 19:25:07 +0000 | [diff] [blame] | 363 | static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type, |
Malcolm Priestley | 9c3806d | 2013-08-23 11:32:26 +0100 | [diff] [blame] | 364 | u32 frame_length, u16 rate, int need_ack) |
| 365 | { |
| 366 | return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type, |
| 367 | frame_length, rate, need_ack)); |
| 368 | } |
| 369 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 370 | //byFreqType: 0=>5GHZ 1=>2.4GHZ |
Malcolm Priestley | 2033801 | 2014-03-18 19:25:08 +0000 | [diff] [blame] | 371 | static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv, |
Malcolm Priestley | 3b6cee7be | 2014-05-25 21:36:27 +0100 | [diff] [blame] | 372 | u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 373 | { |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 374 | u32 rrv_time, rts_time, cts_time, ack_time, data_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 375 | |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 376 | rrv_time = rts_time = cts_time = ack_time = data_time = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 377 | |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 378 | data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 3b6cee7be | 2014-05-25 21:36:27 +0100 | [diff] [blame] | 379 | frame_length, current_rate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 380 | |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 381 | if (rsv_type == 0) { |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 382 | rts_time = vnt_get_frame_time(priv->byPreambleType, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 383 | pkt_type, 20, priv->byTopCCKBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 384 | cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 385 | pkt_type, 14, priv->byTopCCKBasicRate); |
| 386 | } else if (rsv_type == 1) { |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 387 | rts_time = vnt_get_frame_time(priv->byPreambleType, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 388 | pkt_type, 20, priv->byTopCCKBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 389 | cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 390 | 14, priv->byTopCCKBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 391 | ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 392 | 14, priv->byTopOFDMBasicRate); |
| 393 | } else if (rsv_type == 2) { |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 394 | rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 395 | 20, priv->byTopOFDMBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 396 | cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 397 | pkt_type, 14, priv->byTopOFDMBasicRate); |
| 398 | } else if (rsv_type == 3) { |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 399 | cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 400 | 14, priv->byTopCCKBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 401 | ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 402 | 14, priv->byTopOFDMBasicRate); |
| 403 | |
| 404 | rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS; |
| 405 | |
Malcolm Priestley | 2033801 | 2014-03-18 19:25:08 +0000 | [diff] [blame] | 406 | return cpu_to_le16((u16)rrv_time); |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS; |
| 410 | |
| 411 | return cpu_to_le16((u16)rrv_time); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | //byFreqType 0: 5GHz, 1:2.4Ghz |
Malcolm Priestley | 5abe3d6 | 2014-03-18 19:25:06 +0000 | [diff] [blame] | 415 | static __le16 s_uGetDataDuration(struct vnt_private *pDevice, |
Malcolm Priestley | 6b5ad9d | 2013-08-21 22:16:04 +0100 | [diff] [blame] | 416 | u8 byPktType, int bNeedAck) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 417 | { |
Malcolm Priestley | 0005cb0 | 2013-08-07 21:26:12 +0100 | [diff] [blame] | 418 | u32 uAckTime = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 419 | |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 420 | if (bNeedAck) { |
Malcolm Priestley | 6b5ad9d | 2013-08-21 22:16:04 +0100 | [diff] [blame] | 421 | if (byPktType == PK_TYPE_11B) |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 422 | uAckTime = vnt_get_frame_time(pDevice->byPreambleType, |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 423 | byPktType, 14, pDevice->byTopCCKBasicRate); |
| 424 | else |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 425 | uAckTime = vnt_get_frame_time(pDevice->byPreambleType, |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 426 | byPktType, 14, pDevice->byTopOFDMBasicRate); |
Malcolm Priestley | d500595 | 2013-08-21 21:58:37 +0100 | [diff] [blame] | 427 | return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime)); |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 428 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 429 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 433 | //byFreqType: 0=>5GHZ 1=>2.4GHZ |
Malcolm Priestley | 7f591a1 | 2014-03-18 19:25:05 +0000 | [diff] [blame] | 434 | static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType, |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 435 | u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck, |
| 436 | u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 437 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 438 | u32 uCTSTime = 0, uDurTime = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 439 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 440 | switch (byDurType) { |
| 441 | case RTSDUR_BB: |
| 442 | case RTSDUR_BA: |
| 443 | case RTSDUR_BA_F0: |
| 444 | case RTSDUR_BA_F1: |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 445 | uCTSTime = vnt_get_frame_time(pDevice->byPreambleType, |
| 446 | byPktType, 14, pDevice->byTopCCKBasicRate); |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 447 | uDurTime = uCTSTime + 2 * pDevice->uSIFS + |
| 448 | s_uGetTxRsvTime(pDevice, byPktType, |
| 449 | cbFrameLength, wRate, bNeedAck); |
| 450 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 451 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 452 | case RTSDUR_AA: |
| 453 | case RTSDUR_AA_F0: |
| 454 | case RTSDUR_AA_F1: |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 455 | uCTSTime = vnt_get_frame_time(pDevice->byPreambleType, |
| 456 | byPktType, 14, pDevice->byTopOFDMBasicRate); |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 457 | uDurTime = uCTSTime + 2 * pDevice->uSIFS + |
| 458 | s_uGetTxRsvTime(pDevice, byPktType, |
| 459 | cbFrameLength, wRate, bNeedAck); |
| 460 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 461 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 462 | case CTSDUR_BA: |
| 463 | case CTSDUR_BA_F0: |
| 464 | case CTSDUR_BA_F1: |
| 465 | uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 466 | byPktType, cbFrameLength, wRate, bNeedAck); |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 467 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 468 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 469 | default: |
| 470 | break; |
| 471 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 472 | |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 473 | return cpu_to_le16((u16)uDurTime); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 474 | } |
| 475 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 476 | static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context, |
| 477 | struct ieee80211_hdr *hdr) |
| 478 | { |
| 479 | u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head); |
| 480 | u8 *hdr_pos = (u8 *)hdr; |
| 481 | |
| 482 | tx_context->hdr = hdr; |
| 483 | if (!tx_context->hdr) |
| 484 | return 0; |
| 485 | |
| 486 | return (u16)(hdr_pos - head); |
| 487 | } |
| 488 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 489 | static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context, |
| 490 | u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf, |
| 491 | u32 frame_len, int need_ack) |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 492 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 493 | |
| 494 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame^] | 495 | struct ieee80211_hdr *hdr = |
| 496 | (struct ieee80211_hdr *)tx_context->skb->data; |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 497 | |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 498 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 499 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a); |
| 500 | vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 501 | PK_TYPE_11B, &buf->b); |
| 502 | |
| 503 | /* Get Duration and TimeStamp */ |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame^] | 504 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
| 505 | __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15)); |
| 506 | |
| 507 | buf->duration_a = dur; |
| 508 | buf->duration_b = dur; |
| 509 | } else { |
| 510 | buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 511 | buf->duration_b = s_uGetDataDuration(priv, |
| 512 | PK_TYPE_11B, need_ack); |
| 513 | } |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 514 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 515 | buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); |
| 516 | buf->time_stamp_off_b = vnt_time_stamp_off(priv, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 517 | priv->byTopCCKBasicRate); |
| 518 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 519 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
| 520 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 521 | return le16_to_cpu(buf->duration_a); |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 522 | } |
| 523 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 524 | static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context, |
| 525 | u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 526 | u32 frame_len, int need_ack) |
| 527 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 528 | struct vnt_private *priv = tx_context->priv; |
| 529 | |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 530 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 531 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 532 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 533 | vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 534 | PK_TYPE_11B, &buf->b); |
| 535 | |
| 536 | /* Get Duration and TimeStamp */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 537 | buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 538 | buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 539 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 540 | buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 541 | buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 542 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 543 | buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); |
| 544 | buf->time_stamp_off_b = vnt_time_stamp_off(priv, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 545 | priv->byTopCCKBasicRate); |
| 546 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 547 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
| 548 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 549 | return le16_to_cpu(buf->duration_a); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 550 | } |
| 551 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 552 | static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context, |
| 553 | u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf, |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 554 | u32 frame_len, int need_ack) |
| 555 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 556 | struct vnt_private *priv = tx_context->priv; |
| 557 | |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 558 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 559 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 560 | /* Get Duration and TimeStampOff */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 561 | buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 562 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 563 | buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 564 | buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 565 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 566 | buf->time_stamp_off = vnt_time_stamp_off(priv, rate); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 567 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 568 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
| 569 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 570 | return le16_to_cpu(buf->duration); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 571 | } |
| 572 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 573 | static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context, |
| 574 | u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf, |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 575 | u32 frame_len, int need_ack) |
| 576 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 577 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame^] | 578 | struct ieee80211_hdr *hdr = |
| 579 | (struct ieee80211_hdr *)tx_context->skb->data; |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 580 | |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 581 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 582 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab); |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame^] | 583 | |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 584 | /* Get Duration and TimeStampOff */ |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame^] | 585 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
| 586 | __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15)); |
| 587 | |
| 588 | buf->duration = dur; |
| 589 | } else { |
| 590 | buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 591 | } |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 592 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 593 | buf->time_stamp_off = vnt_time_stamp_off(priv, rate); |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 594 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 595 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
| 596 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 597 | return le16_to_cpu(buf->duration); |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 598 | } |
| 599 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 600 | static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context, |
| 601 | struct ieee80211_rts *rts, __le16 duration) |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 602 | { |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 603 | struct ieee80211_hdr *hdr = |
| 604 | (struct ieee80211_hdr *)tx_context->skb->data; |
| 605 | |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 606 | rts->duration = duration; |
Malcolm Priestley | f4554d3 | 2014-03-22 09:01:31 +0000 | [diff] [blame] | 607 | rts->frame_control = |
| 608 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 609 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 610 | memcpy(rts->ra, hdr->addr1, ETH_ALEN); |
| 611 | memcpy(rts->ta, hdr->addr2, ETH_ALEN); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 612 | |
| 613 | return 0; |
| 614 | } |
| 615 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 616 | static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 617 | struct vnt_rts_g *buf, struct ethhdr *eth_hdr, |
| 618 | u8 pkt_type, u32 frame_len, int need_ack, |
| 619 | u16 current_rate, u8 fb_option) |
| 620 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 621 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 622 | u16 rts_frame_len = 20; |
| 623 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 624 | vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 625 | PK_TYPE_11B, &buf->b); |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 626 | vnt_get_phy_field(priv, rts_frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 627 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 628 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 629 | buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 630 | PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 631 | buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 632 | pkt_type, current_rate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 633 | buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 634 | pkt_type, current_rate, need_ack, fb_option); |
| 635 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 636 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 637 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 638 | return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 639 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 640 | } |
| 641 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 642 | static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 643 | struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr, |
| 644 | u8 pkt_type, u32 frame_len, int need_ack, |
| 645 | u16 current_rate, u8 fb_option) |
| 646 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 647 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 648 | u16 rts_frame_len = 20; |
| 649 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 650 | vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 651 | PK_TYPE_11B, &buf->b); |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 652 | vnt_get_phy_field(priv, rts_frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 653 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 654 | |
| 655 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 656 | buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 657 | PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 658 | buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 659 | pkt_type, current_rate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 660 | buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 661 | pkt_type, current_rate, need_ack, fb_option); |
| 662 | |
| 663 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 664 | buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 665 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 666 | buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 667 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 668 | buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 669 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 670 | buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 671 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 672 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 673 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 674 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 675 | return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 676 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 679 | static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 680 | struct vnt_rts_ab *buf, struct ethhdr *eth_hdr, |
| 681 | u8 pkt_type, u32 frame_len, int need_ack, |
| 682 | u16 current_rate, u8 fb_option) |
| 683 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 684 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 685 | u16 rts_frame_len = 20; |
| 686 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 687 | vnt_get_phy_field(priv, rts_frame_len, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 688 | priv->byTopOFDMBasicRate, pkt_type, &buf->ab); |
| 689 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 690 | buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 691 | pkt_type, current_rate, need_ack, fb_option); |
| 692 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 693 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration); |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 694 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 695 | return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate, |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 696 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 697 | } |
| 698 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 699 | static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 700 | struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr, |
| 701 | u8 pkt_type, u32 frame_len, int need_ack, |
| 702 | u16 current_rate, u8 fb_option) |
| 703 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 704 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 705 | u16 rts_frame_len = 20; |
| 706 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 707 | vnt_get_phy_field(priv, rts_frame_len, |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 708 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 709 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 710 | buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 711 | pkt_type, current_rate, need_ack, fb_option); |
| 712 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 713 | buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 714 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 715 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 716 | buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 717 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 718 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 719 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 720 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 721 | return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate, |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 722 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 723 | } |
| 724 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 725 | static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType, |
Malcolm Priestley | 5fb8e41 | 2013-08-27 12:07:58 +0100 | [diff] [blame] | 726 | union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck, |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 727 | struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 728 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 729 | |
Malcolm Priestley | 13fe62a | 2013-08-26 11:17:52 +0100 | [diff] [blame] | 730 | if (!head) |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 731 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 732 | |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 733 | /* Note: So far RTSHead doesn't appear in ATIM |
| 734 | * & Beacom DMA, so we don't need to take them |
| 735 | * into account. |
| 736 | * Otherwise, we need to modified codes for them. |
| 737 | */ |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 738 | switch (byPktType) { |
| 739 | case PK_TYPE_11GB: |
| 740 | case PK_TYPE_11GA: |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 741 | if (byFBOption == AUTO_FB_NONE) |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 742 | return vnt_rxtx_rts_g_head(tx_context, &head->rts_g, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 743 | psEthHeader, byPktType, cbFrameLength, |
| 744 | bNeedAck, wCurrentRate, byFBOption); |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 745 | else |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 746 | return vnt_rxtx_rts_g_fb_head(tx_context, |
| 747 | &head->rts_g_fb, psEthHeader, byPktType, |
| 748 | cbFrameLength, bNeedAck, wCurrentRate, |
| 749 | byFBOption); |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 750 | break; |
| 751 | case PK_TYPE_11A: |
Malcolm Priestley | 2b83ebd | 2013-08-27 09:58:21 +0100 | [diff] [blame] | 752 | if (byFBOption) { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 753 | return vnt_rxtx_rts_a_fb_head(tx_context, |
| 754 | &head->rts_a_fb, psEthHeader, byPktType, |
| 755 | cbFrameLength, bNeedAck, wCurrentRate, |
| 756 | byFBOption); |
Malcolm Priestley | 2b83ebd | 2013-08-27 09:58:21 +0100 | [diff] [blame] | 757 | break; |
| 758 | } |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 759 | case PK_TYPE_11B: |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 760 | return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 761 | psEthHeader, byPktType, cbFrameLength, |
| 762 | bNeedAck, wCurrentRate, byFBOption); |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 763 | } |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 764 | |
| 765 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 766 | } |
| 767 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 768 | static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 5fb8e41 | 2013-08-27 12:07:58 +0100 | [diff] [blame] | 769 | u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength, |
| 770 | int bNeedAck, u16 wCurrentRate, u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 771 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 772 | struct vnt_private *pDevice = tx_context->priv; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 773 | u32 uCTSFrameLen = 14; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 774 | |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 775 | if (!head) |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 776 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 777 | |
Malcolm Priestley | c921cc8 | 2013-08-20 20:47:49 +0100 | [diff] [blame] | 778 | if (byFBOption != AUTO_FB_NONE) { |
| 779 | /* Auto Fall back */ |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 780 | struct vnt_cts_fb *pBuf = &head->cts_g_fb; |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 781 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 782 | vnt_get_phy_field(pDevice, uCTSFrameLen, |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 783 | pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 784 | pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 785 | cbFrameLength, byPktType, |
| 786 | wCurrentRate, bNeedAck, byFBOption); |
| 787 | /* Get CTSDuration_ba_f0 */ |
Malcolm Priestley | 7fd5747 | 2014-03-18 19:24:59 +0000 | [diff] [blame] | 788 | pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 789 | CTSDUR_BA_F0, cbFrameLength, byPktType, |
| 790 | pDevice->tx_rate_fb0, bNeedAck, byFBOption); |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 791 | /* Get CTSDuration_ba_f1 */ |
Malcolm Priestley | 7fd5747 | 2014-03-18 19:24:59 +0000 | [diff] [blame] | 792 | pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 793 | CTSDUR_BA_F1, cbFrameLength, byPktType, |
| 794 | pDevice->tx_rate_fb1, bNeedAck, byFBOption); |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 795 | /* Get CTS Frame body */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 796 | pBuf->data.duration = pBuf->duration_ba; |
Malcolm Priestley | d9560ae | 2014-03-22 09:01:32 +0000 | [diff] [blame] | 797 | pBuf->data.frame_control = |
| 798 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); |
| 799 | |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 800 | memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 801 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 802 | return vnt_rxtx_datahead_g_fb(tx_context, byPktType, |
| 803 | wCurrentRate, &pBuf->data_head, cbFrameLength, |
| 804 | bNeedAck); |
Malcolm Priestley | c921cc8 | 2013-08-20 20:47:49 +0100 | [diff] [blame] | 805 | } else { |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 806 | struct vnt_cts *pBuf = &head->cts_g; |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 807 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 808 | vnt_get_phy_field(pDevice, uCTSFrameLen, |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 809 | pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b); |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 810 | /* Get CTSDuration_ba */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 811 | pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 812 | CTSDUR_BA, cbFrameLength, byPktType, |
| 813 | wCurrentRate, bNeedAck, byFBOption); |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 814 | /*Get CTS Frame body*/ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 815 | pBuf->data.duration = pBuf->duration_ba; |
Malcolm Priestley | d9560ae | 2014-03-22 09:01:32 +0000 | [diff] [blame] | 816 | pBuf->data.frame_control = |
| 817 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); |
| 818 | |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 819 | memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 820 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 821 | return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 822 | &pBuf->data_head, cbFrameLength, bNeedAck); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 823 | } |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 824 | |
| 825 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 826 | } |
| 827 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 828 | /*+ |
| 829 | * |
| 830 | * Description: |
| 831 | * Generate FIFO control for MAC & Baseband controller |
| 832 | * |
| 833 | * Parameters: |
| 834 | * In: |
| 835 | * pDevice - Pointer to adpater |
| 836 | * pTxDataHead - Transmit Data Buffer |
| 837 | * pTxBufHead - pTxBufHead |
| 838 | * pvRrvTime - pvRrvTime |
| 839 | * pvRTS - RTS Buffer |
| 840 | * pCTS - CTS Buffer |
| 841 | * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS) |
| 842 | * bNeedACK - If need ACK |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 843 | * Out: |
| 844 | * none |
| 845 | * |
| 846 | * Return Value: none |
| 847 | * |
| 848 | -*/ |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 849 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 850 | static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 8e344c8 | 2013-09-17 19:58:11 +0100 | [diff] [blame] | 851 | u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer, |
Malcolm Priestley | fa57560 | 2013-09-26 19:00:41 +0100 | [diff] [blame] | 852 | struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 853 | int bNeedACK, struct ethhdr *psEthHeader, bool need_rts) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 854 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 855 | struct vnt_private *pDevice = tx_context->priv; |
Malcolm Priestley | 8e344c8 | 2013-09-17 19:58:11 +0100 | [diff] [blame] | 856 | struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 857 | union vnt_tx_data_head *head = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 858 | u16 wFifoCtl; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 859 | u8 byFBOption = AUTO_FB_NONE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 860 | |
Malcolm Priestley | 03a9cf3 | 2014-03-22 09:01:30 +0000 | [diff] [blame] | 861 | pFifoHead->current_rate = cpu_to_le16(wCurrentRate); |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 862 | wFifoCtl = pFifoHead->wFIFOCtl; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 863 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 864 | if (wFifoCtl & FIFOCTL_AUTO_FB_0) |
| 865 | byFBOption = AUTO_FB_0; |
| 866 | else if (wFifoCtl & FIFOCTL_AUTO_FB_1) |
| 867 | byFBOption = AUTO_FB_1; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 868 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 869 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) { |
| 870 | if (need_rts) { |
| 871 | struct vnt_rrv_time_rts *pBuf = |
| 872 | &tx_buffer->tx_head.tx_rts.rts; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 873 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 874 | pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 875 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 876 | pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 877 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 878 | pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 879 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 880 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 881 | pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 882 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 883 | pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 884 | PK_TYPE_11B, cbFrameSize, |
| 885 | pDevice->byTopCCKBasicRate, bNeedACK); |
| 886 | |
| 887 | if (need_mic) { |
| 888 | *mic_hdr = &tx_buffer-> |
| 889 | tx_head.tx_rts.tx.mic.hdr; |
| 890 | head = &tx_buffer->tx_head.tx_rts.tx.mic.head; |
| 891 | } else { |
| 892 | head = &tx_buffer->tx_head.tx_rts.tx.head; |
| 893 | } |
| 894 | |
| 895 | /* Fill RTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 896 | return s_vFillRTSHead(tx_context, byPktType, head, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 897 | cbFrameSize, bNeedACK, psEthHeader, |
| 898 | wCurrentRate, byFBOption); |
| 899 | |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 900 | } else { |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 901 | struct vnt_rrv_time_cts *pBuf = &tx_buffer-> |
| 902 | tx_head.tx_cts.cts; |
| 903 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 904 | pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 905 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 906 | pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 907 | PK_TYPE_11B, cbFrameSize, |
| 908 | pDevice->byTopCCKBasicRate, bNeedACK); |
| 909 | |
Malcolm Priestley | 372108e | 2014-03-18 19:25:00 +0000 | [diff] [blame] | 910 | pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 911 | byPktType, cbFrameSize, wCurrentRate); |
| 912 | |
| 913 | if (need_mic) { |
| 914 | *mic_hdr = &tx_buffer-> |
| 915 | tx_head.tx_cts.tx.mic.hdr; |
| 916 | head = &tx_buffer->tx_head.tx_cts.tx.mic.head; |
| 917 | } else { |
| 918 | head = &tx_buffer->tx_head.tx_cts.tx.head; |
| 919 | } |
| 920 | |
| 921 | /* Fill CTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 922 | return s_vFillCTSHead(tx_context, byPktType, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 923 | head, cbFrameSize, bNeedACK, wCurrentRate, |
| 924 | byFBOption); |
| 925 | } |
| 926 | } else if (byPktType == PK_TYPE_11A) { |
| 927 | if (need_mic) { |
| 928 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; |
| 929 | head = &tx_buffer->tx_head.tx_ab.tx.mic.head; |
| 930 | } else { |
| 931 | head = &tx_buffer->tx_head.tx_ab.tx.head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 932 | } |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 933 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 934 | if (need_rts) { |
| 935 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 936 | tx_head.tx_ab.ab; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 937 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 938 | pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 939 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 940 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 941 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 942 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
| 943 | |
| 944 | /* Fill RTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 945 | return s_vFillRTSHead(tx_context, byPktType, head, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 946 | cbFrameSize, bNeedACK, psEthHeader, |
| 947 | wCurrentRate, byFBOption); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 948 | } else { |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 949 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 950 | tx_head.tx_ab.ab; |
| 951 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 952 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 953 | PK_TYPE_11A, cbFrameSize, |
| 954 | wCurrentRate, bNeedACK); |
| 955 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 956 | return vnt_rxtx_datahead_a_fb(tx_context, byPktType, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 957 | wCurrentRate, &head->data_head_a_fb, |
| 958 | cbFrameSize, bNeedACK); |
| 959 | } |
| 960 | } else if (byPktType == PK_TYPE_11B) { |
| 961 | if (need_mic) { |
| 962 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; |
| 963 | head = &tx_buffer->tx_head.tx_ab.tx.mic.head; |
| 964 | } else { |
| 965 | head = &tx_buffer->tx_head.tx_ab.tx.head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 966 | } |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 967 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 968 | if (need_rts) { |
| 969 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 970 | tx_head.tx_ab.ab; |
Malcolm Priestley | a90186e | 2013-10-01 15:58:54 +0100 | [diff] [blame] | 971 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 972 | pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 973 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 974 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 975 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 976 | PK_TYPE_11B, cbFrameSize, wCurrentRate, |
| 977 | bNeedACK); |
| 978 | |
| 979 | /* Fill RTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 980 | return s_vFillRTSHead(tx_context, byPktType, head, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 981 | cbFrameSize, |
Malcolm Priestley | 351c7dc | 2013-08-27 12:02:54 +0100 | [diff] [blame] | 982 | bNeedACK, psEthHeader, wCurrentRate, byFBOption); |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 983 | } else { |
| 984 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 985 | tx_head.tx_ab.ab; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 986 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 987 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 988 | PK_TYPE_11B, cbFrameSize, |
| 989 | wCurrentRate, bNeedACK); |
Malcolm Priestley | a90186e | 2013-10-01 15:58:54 +0100 | [diff] [blame] | 990 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 991 | return vnt_rxtx_datahead_ab(tx_context, byPktType, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 992 | wCurrentRate, &head->data_head_ab, |
| 993 | cbFrameSize, bNeedACK); |
| 994 | } |
Malcolm Priestley | c12dca0 | 2013-10-01 16:03:40 +0100 | [diff] [blame] | 995 | } |
| 996 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 997 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 998 | } |
| 999 | /* |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1000 | u8 * pbyBuffer,//point to pTxBufHead |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1001 | u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 1002 | unsigned int cbFragmentSize,//Hdr+payoad+FCS |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1003 | */ |
| 1004 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 1005 | static int s_bPacketToWirelessUsb(struct vnt_usb_send_context *tx_context, |
| 1006 | u8 byPktType, struct vnt_tx_buffer *tx_buffer, int bNeedEncryption, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1007 | u32 uSkbPacketLen, struct ethhdr *psEthHeader, |
Malcolm Priestley | d0a2b8f | 2013-08-15 19:37:04 +0100 | [diff] [blame] | 1008 | u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate, |
| 1009 | u32 *pcbHeaderLen, u32 *pcbTotalLen) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1010 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 1011 | struct vnt_private *pDevice = tx_context->priv; |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1012 | struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1013 | u32 cbFrameSize, cbFrameBodySize; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1014 | u32 cb802_1_H_len; |
| 1015 | u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0; |
| 1016 | u32 cbFCSlen = 4, cbMICHDR = 0; |
Malcolm Priestley | f46142b | 2013-08-27 11:56:33 +0100 | [diff] [blame] | 1017 | int bNeedACK; |
| 1018 | bool bRTS = false; |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 1019 | u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1020 | u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; |
| 1021 | u8 abySNAP_Bridgetunnel[ETH_ALEN] |
| 1022 | = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; |
| 1023 | u32 uDuration; |
| 1024 | u32 cbHeaderLength = 0, uPadding = 0; |
Malcolm Priestley | 5a5d6a8 | 2013-08-23 14:33:55 +0100 | [diff] [blame] | 1025 | struct vnt_mic_hdr *pMICHDR; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1026 | u8 byFBOption = AUTO_FB_NONE, byFragType; |
Malcolm Priestley | 4235f72 | 2013-08-24 12:42:01 +0100 | [diff] [blame] | 1027 | u32 dwMICKey0, dwMICKey1, dwMIC_Priority; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1028 | u32 *pdwMIC_L, *pdwMIC_R; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1029 | int bSoftWEP = false; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 1030 | |
Malcolm Priestley | c545e6a | 2013-10-01 16:07:25 +0100 | [diff] [blame] | 1031 | pMICHDR = NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1032 | |
Malcolm Priestley | e2efba7 | 2012-11-11 15:20:52 +0000 | [diff] [blame] | 1033 | if (bNeedEncryption && pTransmitKey->pvKeyTable) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1034 | if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true) |
| 1035 | bSoftWEP = true; /* WEP 256 */ |
Malcolm Priestley | e2efba7 | 2012-11-11 15:20:52 +0000 | [diff] [blame] | 1036 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1037 | |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1038 | /* Get pkt type */ |
| 1039 | if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) |
| 1040 | cb802_1_H_len = 8; |
| 1041 | else |
| 1042 | cb802_1_H_len = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1043 | |
Charles Clément | 21ec51f | 2010-05-18 10:08:14 -0700 | [diff] [blame] | 1044 | cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1045 | |
| 1046 | //Set packet type |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1047 | pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1048 | |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1049 | if (pDevice->op_mode == NL80211_IFTYPE_ADHOC || |
| 1050 | pDevice->op_mode == NL80211_IFTYPE_AP) { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1051 | if (is_multicast_ether_addr(psEthHeader->h_dest)) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1052 | bNeedACK = false; |
Andres More | 22040bb | 2010-08-02 20:21:44 -0300 | [diff] [blame] | 1053 | pTxBufHead->wFIFOCtl = |
| 1054 | pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); |
| 1055 | } else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1056 | bNeedACK = true; |
Andres More | 22040bb | 2010-08-02 20:21:44 -0300 | [diff] [blame] | 1057 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
| 1058 | } |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1059 | } else { |
| 1060 | /* MSDUs in Infra mode always need ACK */ |
| 1061 | bNeedACK = true; |
| 1062 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
| 1063 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1064 | |
Malcolm Priestley | 5846251 | 2014-03-22 09:01:27 +0000 | [diff] [blame] | 1065 | pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1066 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1067 | //Set FRAGCTL_MACHDCNT |
Malcolm Priestley | 078d0cf | 2013-11-25 22:14:16 +0000 | [diff] [blame] | 1068 | cbMACHdLen = WLAN_HDR_ADDR3_LEN; |
| 1069 | |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1070 | pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1071 | |
| 1072 | //Set FIFOCTL_GrpAckPolicy |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1073 | if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1074 | pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; |
| 1075 | } |
| 1076 | |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 1077 | /* Set Auto Fallback Ctl */ |
| 1078 | if (wCurrentRate >= RATE_18M) { |
| 1079 | if (pDevice->byAutoFBCtrl == AUTO_FB_0) { |
| 1080 | pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0; |
| 1081 | |
| 1082 | pDevice->tx_rate_fb0 = |
| 1083 | wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M]; |
| 1084 | pDevice->tx_rate_fb1 = |
| 1085 | wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M]; |
| 1086 | |
| 1087 | byFBOption = AUTO_FB_0; |
| 1088 | } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) { |
| 1089 | pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1; |
| 1090 | pDevice->tx_rate_fb0 = |
| 1091 | wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M]; |
| 1092 | pDevice->tx_rate_fb1 = |
| 1093 | wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M]; |
| 1094 | |
| 1095 | byFBOption = AUTO_FB_1; |
| 1096 | } |
| 1097 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1098 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1099 | if (bSoftWEP != true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1100 | if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled |
| 1101 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104 |
| 1102 | pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; |
| 1103 | } |
| 1104 | if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { |
| 1105 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n"); |
| 1106 | pTxBufHead->wFragCtl |= FRAGCTL_TKIP; |
| 1107 | } |
| 1108 | else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP |
| 1109 | pTxBufHead->wFragCtl |= FRAGCTL_AES; |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1114 | if ((bNeedEncryption) && (pTransmitKey != NULL)) { |
| 1115 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { |
| 1116 | cbIVlen = 4; |
| 1117 | cbICVlen = 4; |
| 1118 | } |
| 1119 | else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { |
| 1120 | cbIVlen = 8;//IV+ExtIV |
| 1121 | cbMIClen = 8; |
| 1122 | cbICVlen = 4; |
| 1123 | } |
| 1124 | if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { |
| 1125 | cbIVlen = 8;//RSN Header |
| 1126 | cbICVlen = 8;//MIC |
Malcolm Priestley | 5a5d6a8 | 2013-08-23 14:33:55 +0100 | [diff] [blame] | 1127 | cbMICHDR = sizeof(struct vnt_mic_hdr); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1128 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1129 | if (bSoftWEP == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1130 | //MAC Header should be padding 0 to DW alignment. |
| 1131 | uPadding = 4 - (cbMACHdLen%4); |
| 1132 | uPadding %= 4; |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen; |
| 1137 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1138 | if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) { |
| 1139 | bRTS = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1140 | } else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1141 | bRTS = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1142 | pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY); |
| 1143 | } |
| 1144 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1145 | //========================= |
| 1146 | // No Fragmentation |
| 1147 | //========================= |
| 1148 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n"); |
| 1149 | byFragType = FRAGCTL_NONFRAG; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1150 | //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]); |
| 1151 | |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1152 | /* Fill FIFO, RrvTime, RTS and CTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 1153 | uDuration = s_vGenerateTxParameter(tx_context, byPktType, wCurrentRate, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1154 | tx_buffer, &pMICHDR, cbMICHDR, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1155 | cbFrameSize, bNeedACK, psEthHeader, bRTS); |
Malcolm Priestley | c12dca0 | 2013-10-01 16:03:40 +0100 | [diff] [blame] | 1156 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 1157 | cbHeaderLength = tx_context->tx_hdr_size; |
| 1158 | if (!cbHeaderLength) |
| 1159 | return false; |
| 1160 | |
| 1161 | pbyMacHdr = (u8 *)tx_context->hdr; |
| 1162 | pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding); |
| 1163 | pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen); |
| 1164 | |
| 1165 | /* Generate TX MAC Header */ |
| 1166 | s_vGenerateMACHeader(pDevice, tx_context->hdr, (u16)uDuration, |
| 1167 | psEthHeader, bNeedEncryption, byFragType, 0); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1168 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1169 | if (bNeedEncryption == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1170 | //Fill TXKEY |
Malcolm Priestley | 3695c46 | 2014-05-31 13:34:59 +0100 | [diff] [blame] | 1171 | s_vFillTxKey(tx_context, pTxBufHead, pbyIVHead, pTransmitKey, |
| 1172 | (u16)cbFrameBodySize, pMICHDR); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1175 | /* 802.1H */ |
| 1176 | if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1177 | if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) || |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1178 | (psEthHeader->h_proto == cpu_to_le16(0xF380))) |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1179 | memcpy((u8 *) (pbyPayloadHead), |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1180 | abySNAP_Bridgetunnel, 6); |
| 1181 | else |
| 1182 | memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1183 | |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1184 | pbyType = (u8 *) (pbyPayloadHead + 6); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1185 | |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1186 | memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16)); |
| 1187 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1188 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1189 | if (pPacket != NULL) { |
| 1190 | // Copy the Packet into a tx Buffer |
Jim Lieb | 3e36259 | 2009-08-12 14:54:11 -0700 | [diff] [blame] | 1191 | memcpy((pbyPayloadHead + cb802_1_H_len), |
Charles Clément | 21ec51f | 2010-05-18 10:08:14 -0700 | [diff] [blame] | 1192 | (pPacket + ETH_HLEN), |
| 1193 | uSkbPacketLen - ETH_HLEN |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1194 | ); |
| 1195 | |
| 1196 | } else { |
| 1197 | // while bRelayPacketSend psEthHeader is point to header+payload |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1198 | memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1199 | } |
| 1200 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1201 | if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1202 | |
| 1203 | /////////////////////////////////////////////////////////////////// |
| 1204 | |
Malcolm Priestley | 14c5ef5 | 2013-01-17 23:19:37 +0000 | [diff] [blame] | 1205 | if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) { |
| 1206 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]); |
| 1207 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]); |
| 1208 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1209 | else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) { |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 1210 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]); |
| 1211 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1212 | } |
| 1213 | else { |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 1214 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]); |
| 1215 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1216 | } |
| 1217 | // DO Software Michael |
| 1218 | MIC_vInit(dwMICKey0, dwMICKey1); |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1219 | MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1220 | dwMIC_Priority = 0; |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1221 | MIC_vAppend((u8 *)&dwMIC_Priority, 4); |
Malcolm Priestley | b4dc03a | 2012-11-11 15:45:52 +0000 | [diff] [blame] | 1222 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n", |
| 1223 | dwMICKey0, dwMICKey1); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1224 | |
| 1225 | /////////////////////////////////////////////////////////////////// |
| 1226 | |
| 1227 | //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength)); |
| 1228 | //for (ii = 0; ii < cbFrameBodySize; ii++) { |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1229 | // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii)))); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1230 | //} |
| 1231 | //DBG_PRN_GRP12(("\n\n\n")); |
| 1232 | |
| 1233 | MIC_vAppend(pbyPayloadHead, cbFrameBodySize); |
| 1234 | |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 1235 | pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize); |
| 1236 | pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1237 | |
| 1238 | MIC_vGetMIC(pdwMIC_L, pdwMIC_R); |
| 1239 | MIC_vUnInit(); |
| 1240 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1241 | if (pDevice->bTxMICFail == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1242 | *pdwMIC_L = 0; |
| 1243 | *pdwMIC_R = 0; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1244 | pDevice->bTxMICFail = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1245 | } |
| 1246 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize); |
| 1247 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen); |
| 1248 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R); |
| 1249 | } |
| 1250 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1251 | if (bSoftWEP == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1252 | |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1253 | s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1254 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1255 | } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) || |
| 1256 | ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) || |
| 1257 | ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1258 | cbFrameSize -= cbICVlen; |
| 1259 | } |
| 1260 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1261 | cbFrameSize -= cbFCSlen; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1262 | |
| 1263 | *pcbHeaderLen = cbHeaderLength; |
| 1264 | *pcbTotalLen = cbHeaderLength + cbFrameSize ; |
| 1265 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1266 | //Set FragCtl in TxBufferHead |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1267 | pTxBufHead->wFragCtl |= (u16)byFragType; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1268 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1269 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1270 | |
| 1271 | } |
| 1272 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1273 | /*+ |
| 1274 | * |
| 1275 | * Description: |
| 1276 | * Translate 802.3 to 802.11 header |
| 1277 | * |
| 1278 | * Parameters: |
| 1279 | * In: |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 1280 | * pDevice - Pointer to adapter |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1281 | * dwTxBufferAddr - Transmit Buffer |
| 1282 | * pPacket - Packet from upper layer |
| 1283 | * cbPacketSize - Transmit Data Length |
| 1284 | * Out: |
| 1285 | * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header |
| 1286 | * pcbAppendPayload - size of append payload for 802.1H translation |
| 1287 | * |
| 1288 | * Return Value: none |
| 1289 | * |
| 1290 | -*/ |
| 1291 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1292 | static void s_vGenerateMACHeader(struct vnt_private *pDevice, |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 1293 | struct ieee80211_hdr *pMACHeader, u16 wDuration, |
| 1294 | struct ethhdr *psEthHeader, int bNeedEncrypt, u16 wFragType, |
| 1295 | u32 uFragIdx) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1296 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1297 | |
Malcolm Priestley | c921cc8 | 2013-08-20 20:47:49 +0100 | [diff] [blame] | 1298 | pMACHeader->frame_control = TYPE_802_11_DATA; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1299 | |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1300 | if (pDevice->op_mode == NL80211_IFTYPE_AP) { |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1301 | memcpy(&(pMACHeader->addr1[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1302 | &(psEthHeader->h_dest[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1303 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1304 | memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN); |
| 1305 | memcpy(&(pMACHeader->addr3[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1306 | &(psEthHeader->h_source[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1307 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1308 | pMACHeader->frame_control |= FC_FROMDS; |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1309 | } else { |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1310 | if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) { |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1311 | memcpy(&(pMACHeader->addr1[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1312 | &(psEthHeader->h_dest[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1313 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1314 | memcpy(&(pMACHeader->addr2[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1315 | &(psEthHeader->h_source[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1316 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1317 | memcpy(&(pMACHeader->addr3[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1318 | &(pDevice->abyBSSID[0]), |
| 1319 | ETH_ALEN); |
| 1320 | } else { |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1321 | memcpy(&(pMACHeader->addr3[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1322 | &(psEthHeader->h_dest[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1323 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1324 | memcpy(&(pMACHeader->addr2[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1325 | &(psEthHeader->h_source[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1326 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1327 | memcpy(&(pMACHeader->addr1[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1328 | &(pDevice->abyBSSID[0]), |
| 1329 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1330 | pMACHeader->frame_control |= FC_TODS; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | if (bNeedEncrypt) |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1335 | pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1336 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1337 | pMACHeader->duration_id = cpu_to_le16(wDuration); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1338 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1339 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1340 | |
| 1341 | //Set FragNumber in Sequence Control |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1342 | pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1343 | |
| 1344 | if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) { |
| 1345 | pDevice->wSeqCounter++; |
| 1346 | if (pDevice->wSeqCounter > 0x0fff) |
| 1347 | pDevice->wSeqCounter = 0; |
| 1348 | } |
| 1349 | |
| 1350 | if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1351 | pMACHeader->frame_control |= FC_MOREFRAG; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1355 | /*+ |
| 1356 | * |
| 1357 | * Description: |
| 1358 | * Request instructs a MAC to transmit a 802.11 management packet through |
| 1359 | * the adapter onto the medium. |
| 1360 | * |
| 1361 | * Parameters: |
| 1362 | * In: |
| 1363 | * hDeviceContext - Pointer to the adapter |
| 1364 | * pPacket - A pointer to a descriptor for the packet to transmit |
| 1365 | * Out: |
| 1366 | * none |
| 1367 | * |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1368 | * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1369 | * |
| 1370 | -*/ |
| 1371 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1372 | CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, |
| 1373 | struct vnt_tx_mgmt *pPacket) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1374 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1375 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
Malcolm Priestley | f39c0d8 | 2013-08-15 19:34:37 +0100 | [diff] [blame] | 1376 | struct vnt_tx_buffer *pTX_Buffer; |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 1377 | struct vnt_usb_send_context *pContext; |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1378 | struct vnt_tx_fifo_head *pTxBufHead; |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1379 | struct ieee80211_hdr *pMACHeader; |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1380 | struct ethhdr sEthHeader; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1381 | u8 byPktType, *pbyTxBufferAddr; |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 1382 | struct vnt_mic_hdr *pMICHDR = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1383 | u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1384 | int bNeedACK, bIsPSPOLL = false; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1385 | u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4; |
| 1386 | u32 uPadding = 0; |
| 1387 | u16 wTxBufSize; |
| 1388 | u32 cbMacHdLen; |
| 1389 | u16 wCurrentRate = RATE_1M; |
Malcolm Priestley | 931cb9f | 2014-05-15 22:49:15 +0100 | [diff] [blame] | 1390 | unsigned long flags; |
| 1391 | |
| 1392 | if (pDevice->byBBType == BB_TYPE_11A) { |
| 1393 | wCurrentRate = RATE_6M; |
| 1394 | byPktType = PK_TYPE_11A; |
| 1395 | } else { |
| 1396 | wCurrentRate = RATE_1M; |
| 1397 | byPktType = PK_TYPE_11B; |
| 1398 | } |
| 1399 | |
| 1400 | if (pMgmt->eScanState != WMAC_NO_SCANNING) |
Malcolm Priestley | 4f5290e | 2014-05-27 21:05:21 +0100 | [diff] [blame] | 1401 | vnt_rf_setpower(pDevice, wCurrentRate, pDevice->byCurrentCh); |
Malcolm Priestley | 931cb9f | 2014-05-15 22:49:15 +0100 | [diff] [blame] | 1402 | else |
Malcolm Priestley | 4f5290e | 2014-05-27 21:05:21 +0100 | [diff] [blame] | 1403 | vnt_rf_setpower(pDevice, wCurrentRate, pMgmt->uCurrChannel); |
Malcolm Priestley | 931cb9f | 2014-05-15 22:49:15 +0100 | [diff] [blame] | 1404 | |
| 1405 | pDevice->wCurrentRate = wCurrentRate; |
| 1406 | |
| 1407 | spin_lock_irqsave(&pDevice->lock, flags); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1408 | |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 1409 | pContext = s_vGetFreeContext(pDevice); |
Malcolm Priestley | 931cb9f | 2014-05-15 22:49:15 +0100 | [diff] [blame] | 1410 | if (!pContext) { |
| 1411 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 1412 | "ManagementSend TX...NO CONTEXT!\n"); |
| 1413 | spin_unlock_irqrestore(&pDevice->lock, flags); |
| 1414 | return CMD_STATUS_RESOURCES; |
| 1415 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1416 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 1417 | pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1418 | cbFrameBodySize = pPacket->cbPayloadLen; |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1419 | pTxBufHead = &pTX_Buffer->fifo_head; |
Malcolm Priestley | ab51f51 | 2014-05-31 13:35:00 +0100 | [diff] [blame] | 1420 | pbyTxBufferAddr = (u8 *)pTxBufHead; |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1421 | wTxBufSize = sizeof(struct vnt_tx_fifo_head); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1422 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1423 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1424 | //Set packet type |
| 1425 | if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000 |
| 1426 | pTxBufHead->wFIFOCtl = 0; |
| 1427 | } |
| 1428 | else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000 |
| 1429 | pTxBufHead->wFIFOCtl |= FIFOCTL_11B; |
| 1430 | } |
| 1431 | else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000 |
| 1432 | pTxBufHead->wFIFOCtl |= FIFOCTL_11GB; |
| 1433 | } |
| 1434 | else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000 |
| 1435 | pTxBufHead->wFIFOCtl |= FIFOCTL_11GA; |
| 1436 | } |
| 1437 | |
| 1438 | pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN; |
Malcolm Priestley | 5846251 | 2014-03-22 09:01:27 +0000 | [diff] [blame] | 1439 | pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1440 | |
Andres More | 22040bb | 2010-08-02 20:21:44 -0300 | [diff] [blame] | 1441 | if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1442 | bNeedACK = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1443 | } |
| 1444 | else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1445 | bNeedACK = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1446 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
| 1447 | }; |
| 1448 | |
| 1449 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || |
| 1450 | (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) { |
| 1451 | |
| 1452 | pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY; |
| 1453 | //Set Preamble type always long |
| 1454 | //pDevice->byPreambleType = PREAMBLE_LONG; |
| 1455 | // probe-response don't retry |
| 1456 | //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1457 | // bNeedACK = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1458 | // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK); |
| 1459 | //} |
| 1460 | } |
| 1461 | |
| 1462 | pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); |
| 1463 | |
| 1464 | if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1465 | bIsPSPOLL = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1466 | cbMacHdLen = WLAN_HDR_ADDR2_LEN; |
| 1467 | } else { |
| 1468 | cbMacHdLen = WLAN_HDR_ADDR3_LEN; |
| 1469 | } |
| 1470 | |
| 1471 | //Set FRAGCTL_MACHDCNT |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1472 | pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1473 | |
| 1474 | // Notes: |
| 1475 | // Although spec says MMPDU can be fragmented; In most case, |
| 1476 | // no one will send a MMPDU under fragmentation. With RTS may occur. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1477 | |
| 1478 | if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { |
| 1479 | if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) { |
| 1480 | cbIVlen = 4; |
| 1481 | cbICVlen = 4; |
| 1482 | pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; |
| 1483 | } |
| 1484 | else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { |
| 1485 | cbIVlen = 8;//IV+ExtIV |
| 1486 | cbMIClen = 8; |
| 1487 | cbICVlen = 4; |
| 1488 | pTxBufHead->wFragCtl |= FRAGCTL_TKIP; |
| 1489 | //We need to get seed here for filling TxKey entry. |
| 1490 | //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr, |
| 1491 | // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG); |
| 1492 | } |
| 1493 | else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { |
| 1494 | cbIVlen = 8;//RSN Header |
| 1495 | cbICVlen = 8;//MIC |
| 1496 | pTxBufHead->wFragCtl |= FRAGCTL_AES; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1497 | } |
| 1498 | //MAC Header should be padding 0 to DW alignment. |
| 1499 | uPadding = 4 - (cbMacHdLen%4); |
| 1500 | uPadding %= 4; |
| 1501 | } |
| 1502 | |
| 1503 | cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen; |
| 1504 | |
| 1505 | //Set FIFOCTL_GrpAckPolicy |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1506 | if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1507 | pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; |
| 1508 | } |
| 1509 | //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() |
| 1510 | |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1511 | memcpy(&(sEthHeader.h_dest[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1512 | &(pPacket->p80211Header->sA3.abyAddr1[0]), |
| 1513 | ETH_ALEN); |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1514 | memcpy(&(sEthHeader.h_source[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1515 | &(pPacket->p80211Header->sA3.abyAddr2[0]), |
| 1516 | ETH_ALEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1517 | //========================= |
| 1518 | // No Fragmentation |
| 1519 | //========================= |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1520 | pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1521 | |
Malcolm Priestley | 351c7dc | 2013-08-27 12:02:54 +0100 | [diff] [blame] | 1522 | /* Fill FIFO,RrvTime,RTS,and CTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 1523 | uDuration = s_vGenerateTxParameter(pContext, byPktType, wCurrentRate, |
Malcolm Priestley | fa57560 | 2013-09-26 19:00:41 +0100 | [diff] [blame] | 1524 | pTX_Buffer, &pMICHDR, 0, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1525 | cbFrameSize, bNeedACK, &sEthHeader, false); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1526 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 1527 | cbHeaderSize = pContext->tx_hdr_size; |
| 1528 | if (!cbHeaderSize) { |
| 1529 | pContext->in_use = false; |
| 1530 | return CMD_STATUS_RESOURCES; |
| 1531 | } |
| 1532 | |
| 1533 | pMACHeader = pContext->hdr; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1534 | |
| 1535 | cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize; |
| 1536 | |
| 1537 | if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1538 | u8 * pbyIVHead; |
| 1539 | u8 * pbyPayloadHead; |
| 1540 | u8 * pbyBSSID; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1541 | PSKeyItem pTransmitKey = NULL; |
| 1542 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1543 | pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding); |
| 1544 | pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1545 | do { |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1546 | if (pDevice->op_mode == NL80211_IFTYPE_STATION && |
| 1547 | pDevice->bLinkPass == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1548 | pbyBSSID = pDevice->abyBSSID; |
| 1549 | // get pairwise key |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1550 | if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1551 | // get group key |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1552 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1553 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); |
| 1554 | break; |
| 1555 | } |
| 1556 | } else { |
| 1557 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n"); |
| 1558 | break; |
| 1559 | } |
| 1560 | } |
| 1561 | // get group key |
| 1562 | pbyBSSID = pDevice->abyBroadcastAddr; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1563 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1564 | pTransmitKey = NULL; |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1565 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1566 | } else { |
| 1567 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); |
| 1568 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1569 | } while(false); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1570 | //Fill TXKEY |
Malcolm Priestley | 3695c46 | 2014-05-31 13:34:59 +0100 | [diff] [blame] | 1571 | s_vFillTxKey(pContext, pTxBufHead, pbyIVHead, pTransmitKey, |
| 1572 | (u16)cbFrameBodySize, NULL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1573 | |
Jim Lieb | 3e36259 | 2009-08-12 14:54:11 -0700 | [diff] [blame] | 1574 | memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen); |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1575 | memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen), |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1576 | cbFrameBodySize); |
| 1577 | } |
| 1578 | else { |
| 1579 | // Copy the Packet into a tx Buffer |
Jim Lieb | 3e36259 | 2009-08-12 14:54:11 -0700 | [diff] [blame] | 1580 | memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1581 | } |
| 1582 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1583 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1584 | pDevice->wSeqCounter++ ; |
| 1585 | if (pDevice->wSeqCounter > 0x0fff) |
| 1586 | pDevice->wSeqCounter = 0; |
| 1587 | |
| 1588 | if (bIsPSPOLL) { |
| 1589 | // The MAC will automatically replace the Duration-field of MAC header by Duration-field |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 1590 | // of FIFO control header. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1591 | // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is |
| 1592 | // in the same place of other packet's Duration-field). |
| 1593 | // And it will cause Cisco-AP to issue Disassociation-packet |
Malcolm Priestley | 7e60a3de | 2013-08-16 23:48:03 +0100 | [diff] [blame] | 1594 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) { |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1595 | struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head. |
| 1596 | tx_cts.tx.head.cts_g.data_head; |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 1597 | data_head->duration_a = |
Malcolm Priestley | 7e60a3de | 2013-08-16 23:48:03 +0100 | [diff] [blame] | 1598 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 1599 | data_head->duration_b = |
Malcolm Priestley | 7e60a3de | 2013-08-16 23:48:03 +0100 | [diff] [blame] | 1600 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
| 1601 | } else { |
Malcolm Priestley | c12dca0 | 2013-10-01 16:03:40 +0100 | [diff] [blame] | 1602 | struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head. |
| 1603 | tx_ab.tx.head.data_head_ab; |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 1604 | data_head->duration = |
Malcolm Priestley | 558becf | 2013-08-16 23:50:32 +0100 | [diff] [blame] | 1605 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
| 1606 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1607 | } |
| 1608 | |
Malcolm Priestley | ca34759 | 2014-03-22 09:01:28 +0000 | [diff] [blame] | 1609 | pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount)); |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1610 | pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1611 | pTX_Buffer->byType = 0x00; |
| 1612 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 1613 | pContext->skb = NULL; |
| 1614 | pContext->type = CONTEXT_MGMT_PACKET; |
| 1615 | pContext->buf_len = (u16)cbReqCount + 4; /* USB header */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1616 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1617 | if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) { |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1618 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
| 1619 | &pMACHeader->addr1[0], (u16)cbFrameSize, |
| 1620 | pTxBufHead->wFIFOCtl); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1621 | } |
| 1622 | else { |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1623 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
| 1624 | &pMACHeader->addr3[0], (u16)cbFrameSize, |
| 1625 | pTxBufHead->wFIFOCtl); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | PIPEnsSendBulkOut(pDevice,pContext); |
Malcolm Priestley | 931cb9f | 2014-05-15 22:49:15 +0100 | [diff] [blame] | 1629 | |
| 1630 | spin_unlock_irqrestore(&pDevice->lock, flags); |
| 1631 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1632 | return CMD_STATUS_PENDING; |
| 1633 | } |
| 1634 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1635 | CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice, |
| 1636 | struct vnt_tx_mgmt *pPacket) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1637 | { |
Malcolm Priestley | 01f865b | 2013-08-15 19:40:08 +0100 | [diff] [blame] | 1638 | struct vnt_beacon_buffer *pTX_Buffer; |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1639 | struct vnt_tx_short_buf_head *short_head; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1640 | u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN; |
| 1641 | u32 cbHeaderSize = 0; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1642 | u16 wCurrentRate; |
| 1643 | u32 cbFrameBodySize; |
| 1644 | u32 cbReqCount; |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 1645 | struct vnt_usb_send_context *pContext; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1646 | CMD_STATUS status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1647 | |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 1648 | pContext = s_vGetFreeContext(pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1649 | if (NULL == pContext) { |
| 1650 | status = CMD_STATUS_RESOURCES; |
| 1651 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n"); |
| 1652 | return status ; |
| 1653 | } |
Malcolm Priestley | 01f865b | 2013-08-15 19:40:08 +0100 | [diff] [blame] | 1654 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 1655 | pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->data[0]; |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1656 | short_head = &pTX_Buffer->short_head; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1657 | |
| 1658 | cbFrameBodySize = pPacket->cbPayloadLen; |
| 1659 | |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1660 | cbHeaderSize = sizeof(struct vnt_tx_short_buf_head); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1661 | |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1662 | if (pDevice->byBBType == BB_TYPE_11A) { |
| 1663 | wCurrentRate = RATE_6M; |
| 1664 | |
| 1665 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 1666 | vnt_get_phy_field(pDevice, cbFrameSize, wCurrentRate, |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1667 | PK_TYPE_11A, &short_head->ab); |
| 1668 | |
| 1669 | /* Get Duration and TimeStampOff */ |
| 1670 | short_head->duration = s_uGetDataDuration(pDevice, |
| 1671 | PK_TYPE_11A, false); |
| 1672 | short_head->time_stamp_off = |
| 1673 | vnt_time_stamp_off(pDevice, wCurrentRate); |
| 1674 | } else { |
| 1675 | wCurrentRate = RATE_1M; |
| 1676 | short_head->fifo_ctl |= FIFOCTL_11B; |
| 1677 | |
| 1678 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 1679 | vnt_get_phy_field(pDevice, cbFrameSize, wCurrentRate, |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1680 | PK_TYPE_11B, &short_head->ab); |
| 1681 | |
| 1682 | /* Get Duration and TimeStampOff */ |
| 1683 | short_head->duration = s_uGetDataDuration(pDevice, |
Malcolm Priestley | 6b5ad9d | 2013-08-21 22:16:04 +0100 | [diff] [blame] | 1684 | PK_TYPE_11B, false); |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1685 | short_head->time_stamp_off = |
| 1686 | vnt_time_stamp_off(pDevice, wCurrentRate); |
| 1687 | } |
| 1688 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1689 | |
Malcolm Priestley | 0b71fe3 | 2013-11-24 13:27:32 +0000 | [diff] [blame] | 1690 | /* Generate Beacon Header */ |
Malcolm Priestley | 0b71fe3 | 2013-11-24 13:27:32 +0000 | [diff] [blame] | 1691 | pDevice->wSeqCounter++; |
| 1692 | if (pDevice->wSeqCounter > 0x0fff) |
| 1693 | pDevice->wSeqCounter = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1694 | |
| 1695 | cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize; |
| 1696 | |
Malcolm Priestley | fad8e4a | 2014-03-22 09:01:29 +0000 | [diff] [blame] | 1697 | pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount); |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1698 | pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1699 | pTX_Buffer->byType = 0x01; |
| 1700 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 1701 | pContext->skb = NULL; |
| 1702 | pContext->type = CONTEXT_MGMT_PACKET; |
| 1703 | pContext->buf_len = (u16)cbReqCount + 4; /* USB header */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1704 | |
| 1705 | PIPEnsSendBulkOut(pDevice,pContext); |
| 1706 | return CMD_STATUS_PENDING; |
| 1707 | |
| 1708 | } |
| 1709 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1710 | //TYPE_AC0DMA data tx |
| 1711 | /* |
| 1712 | * Description: |
| 1713 | * Tx packet via AC0DMA(DMA1) |
| 1714 | * |
| 1715 | * Parameters: |
| 1716 | * In: |
| 1717 | * pDevice - Pointer to the adapter |
| 1718 | * skb - Pointer to tx skb packet |
| 1719 | * Out: |
| 1720 | * void |
| 1721 | * |
| 1722 | * Return Value: NULL |
| 1723 | */ |
| 1724 | |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1725 | int nsDMA_tx_packet(struct vnt_private *pDevice, struct sk_buff *skb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1726 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1727 | struct net_device_stats *pStats = &pDevice->stats; |
| 1728 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
Malcolm Priestley | f39c0d8 | 2013-08-15 19:34:37 +0100 | [diff] [blame] | 1729 | struct vnt_tx_buffer *pTX_Buffer; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1730 | u32 BytesToWrite = 0, uHeaderLen = 0; |
| 1731 | u32 uNodeIndex = 0; |
| 1732 | u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; |
| 1733 | u16 wAID; |
| 1734 | u8 byPktType; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1735 | int bNeedEncryption = false; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1736 | PSKeyItem pTransmitKey = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1737 | int ii; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1738 | int bTKIP_UseGTK = false; |
| 1739 | int bNeedDeAuth = false; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1740 | u8 *pbyBSSID; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1741 | int bNodeExist = false; |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 1742 | struct vnt_usb_send_context *pContext; |
Andres More | dfdcc42 | 2013-02-12 20:36:28 -0500 | [diff] [blame] | 1743 | bool fConvertedPacket; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1744 | u32 status; |
| 1745 | u16 wKeepRate = pDevice->wCurrentRate; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1746 | int bTxeapol_key = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1747 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1748 | if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { |
| 1749 | |
| 1750 | if (pDevice->uAssocCount == 0) { |
| 1751 | dev_kfree_skb_irq(skb); |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1755 | if (is_multicast_ether_addr((u8 *)(skb->data))) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1756 | uNodeIndex = 0; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1757 | bNodeExist = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1758 | if (pMgmt->sNodeDBTable[0].bPSEnable) { |
| 1759 | |
| 1760 | skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb); |
| 1761 | pMgmt->sNodeDBTable[0].wEnQueueCnt++; |
| 1762 | // set tx map |
| 1763 | pMgmt->abyPSTxMap[0] |= byMask[0]; |
| 1764 | return 0; |
| 1765 | } |
Masanari Iida | 9318469 | 2012-08-13 21:21:50 +0900 | [diff] [blame] | 1766 | // multicast/broadcast data rate |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1767 | |
| 1768 | if (pDevice->byBBType != BB_TYPE_11A) |
| 1769 | pDevice->wCurrentRate = RATE_2M; |
| 1770 | else |
| 1771 | pDevice->wCurrentRate = RATE_24M; |
| 1772 | // long preamble type |
| 1773 | pDevice->byPreambleType = PREAMBLE_SHORT; |
| 1774 | |
| 1775 | }else { |
| 1776 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1777 | if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1778 | |
| 1779 | if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) { |
| 1780 | |
| 1781 | skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb); |
| 1782 | |
| 1783 | pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++; |
| 1784 | // set tx map |
| 1785 | wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID; |
| 1786 | pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7]; |
| 1787 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n", |
| 1788 | (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]); |
| 1789 | |
| 1790 | return 0; |
| 1791 | } |
| 1792 | // AP rate decided from node |
| 1793 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate; |
| 1794 | // tx preamble decided from node |
| 1795 | |
| 1796 | if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) { |
| 1797 | pDevice->byPreambleType = pDevice->byShortPreamble; |
| 1798 | |
| 1799 | }else { |
| 1800 | pDevice->byPreambleType = PREAMBLE_LONG; |
| 1801 | } |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1802 | bNodeExist = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1803 | } |
| 1804 | } |
| 1805 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1806 | if (bNodeExist == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1807 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n"); |
| 1808 | dev_kfree_skb_irq(skb); |
| 1809 | return 0; |
| 1810 | } |
| 1811 | } |
| 1812 | |
Tobias Klauser | 838c2d6 | 2014-04-25 11:53:58 +0200 | [diff] [blame] | 1813 | memcpy(&pDevice->sTxEthHeader, skb->data, ETH_HLEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1814 | |
| 1815 | //mike add:station mode check eapol-key challenge---> |
| 1816 | { |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1817 | u8 Protocol_Version; //802.1x Authentication |
| 1818 | u8 Packet_Type; //802.1x Authentication |
| 1819 | u8 Descriptor_type; |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1820 | u16 Key_info; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1821 | |
Charles Clément | 21ec51f | 2010-05-18 10:08:14 -0700 | [diff] [blame] | 1822 | Protocol_Version = skb->data[ETH_HLEN]; |
| 1823 | Packet_Type = skb->data[ETH_HLEN+1]; |
| 1824 | Descriptor_type = skb->data[ETH_HLEN+1+1+2]; |
| 1825 | Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]); |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1826 | if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) { |
Malcolm Priestley | aa209ee | 2012-08-29 23:08:21 +0100 | [diff] [blame] | 1827 | /* 802.1x OR eapol-key challenge frame transfer */ |
| 1828 | if (((Protocol_Version == 1) || (Protocol_Version == 2)) && |
| 1829 | (Packet_Type == 3)) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1830 | bTxeapol_key = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1831 | if(!(Key_info & BIT3) && //WPA or RSN group-key challenge |
| 1832 | (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key |
| 1833 | if(Descriptor_type==254) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1834 | pDevice->fWPA_Authened = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1835 | PRINT_K("WPA "); |
| 1836 | } |
| 1837 | else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1838 | pDevice->fWPA_Authened = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1839 | PRINT_K("WPA2(re-keying) "); |
| 1840 | } |
| 1841 | PRINT_K("Authentication completed!!\n"); |
| 1842 | } |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 1843 | else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1844 | (Key_info & BIT8) && (Key_info & BIT9)) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1845 | pDevice->fWPA_Authened = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1846 | PRINT_K("WPA2 Authentication completed!!\n"); |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | } |
| 1851 | //mike add:station mode check eapol-key challenge<--- |
| 1852 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1853 | if (pDevice->bEncryptionEnable == true) { |
| 1854 | bNeedEncryption = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1855 | // get Transmit key |
| 1856 | do { |
| 1857 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && |
| 1858 | (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { |
| 1859 | pbyBSSID = pDevice->abyBSSID; |
| 1860 | // get pairwise key |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1861 | if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1862 | // get group key |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1863 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { |
| 1864 | bTKIP_UseGTK = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1865 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); |
| 1866 | break; |
| 1867 | } |
| 1868 | } else { |
| 1869 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n"); |
| 1870 | break; |
| 1871 | } |
| 1872 | }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1873 | /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */ |
| 1874 | pbyBSSID = pDevice->sTxEthHeader.h_dest; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1875 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n"); |
| 1876 | for (ii = 0; ii< 6; ii++) |
| 1877 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii)); |
| 1878 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n"); |
| 1879 | |
| 1880 | // get pairwise key |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1881 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1882 | break; |
| 1883 | } |
| 1884 | // get group key |
| 1885 | pbyBSSID = pDevice->abyBroadcastAddr; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1886 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1887 | pTransmitKey = NULL; |
| 1888 | if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { |
| 1889 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); |
| 1890 | } |
| 1891 | else |
| 1892 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); |
| 1893 | } else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1894 | bTKIP_UseGTK = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1895 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); |
| 1896 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1897 | } while(false); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1898 | } |
| 1899 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1900 | byPktType = (u8)pDevice->byPacketType; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1901 | |
| 1902 | if (pDevice->bFixRate) { |
| 1903 | if (pDevice->byBBType == BB_TYPE_11B) { |
| 1904 | if (pDevice->uConnectionRate >= RATE_11M) { |
| 1905 | pDevice->wCurrentRate = RATE_11M; |
| 1906 | } else { |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1907 | pDevice->wCurrentRate = (u16)pDevice->uConnectionRate; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1908 | } |
| 1909 | } else { |
| 1910 | if ((pDevice->byBBType == BB_TYPE_11A) && |
| 1911 | (pDevice->uConnectionRate <= RATE_6M)) { |
| 1912 | pDevice->wCurrentRate = RATE_6M; |
| 1913 | } else { |
| 1914 | if (pDevice->uConnectionRate >= RATE_54M) |
| 1915 | pDevice->wCurrentRate = RATE_54M; |
| 1916 | else |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1917 | pDevice->wCurrentRate = (u16)pDevice->uConnectionRate; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | else { |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1922 | if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1923 | // Adhoc Tx rate decided from node DB |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1924 | if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1925 | // Multicast use highest data rate |
| 1926 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate; |
| 1927 | // preamble type |
| 1928 | pDevice->byPreambleType = pDevice->byShortPreamble; |
| 1929 | } |
| 1930 | else { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1931 | if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1932 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate; |
| 1933 | if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) { |
| 1934 | pDevice->byPreambleType = pDevice->byShortPreamble; |
| 1935 | |
| 1936 | } |
| 1937 | else { |
| 1938 | pDevice->byPreambleType = PREAMBLE_LONG; |
| 1939 | } |
| 1940 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate); |
| 1941 | } |
| 1942 | else { |
| 1943 | if (pDevice->byBBType != BB_TYPE_11A) |
| 1944 | pDevice->wCurrentRate = RATE_2M; |
| 1945 | else |
| 1946 | pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s |
| 1947 | // abyCurrExtSuppRates[] |
| 1948 | pDevice->byPreambleType = PREAMBLE_SHORT; |
| 1949 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n"); |
| 1950 | } |
| 1951 | } |
| 1952 | } |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1953 | if (pDevice->op_mode == NL80211_IFTYPE_STATION) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1954 | // Infra STA rate decided from AP Node, index = 0 |
| 1955 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate; |
| 1956 | } |
| 1957 | } |
| 1958 | |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1959 | if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) { |
Malcolm Priestley | aa209ee | 2012-08-29 23:08:21 +0100 | [diff] [blame] | 1960 | if (pDevice->byBBType != BB_TYPE_11A) { |
| 1961 | pDevice->wCurrentRate = RATE_1M; |
Malcolm Priestley | aa209ee | 2012-08-29 23:08:21 +0100 | [diff] [blame] | 1962 | pDevice->byTopCCKBasicRate = RATE_1M; |
| 1963 | pDevice->byTopOFDMBasicRate = RATE_6M; |
| 1964 | } else { |
| 1965 | pDevice->wCurrentRate = RATE_6M; |
Malcolm Priestley | aa209ee | 2012-08-29 23:08:21 +0100 | [diff] [blame] | 1966 | pDevice->byTopCCKBasicRate = RATE_1M; |
| 1967 | pDevice->byTopOFDMBasicRate = RATE_6M; |
| 1968 | } |
| 1969 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1970 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 1971 | DBG_PRT(MSG_LEVEL_DEBUG, |
| 1972 | KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n", |
| 1973 | pDevice->wCurrentRate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1974 | |
| 1975 | if (wKeepRate != pDevice->wCurrentRate) { |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 1976 | bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | if (pDevice->wCurrentRate <= RATE_11M) { |
| 1980 | byPktType = PK_TYPE_11B; |
| 1981 | } |
| 1982 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1983 | if (bNeedEncryption == true) { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1984 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto)); |
| 1985 | if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1986 | bNeedEncryption = false; |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1987 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1988 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { |
| 1989 | if (pTransmitKey == NULL) { |
| 1990 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n"); |
| 1991 | } |
| 1992 | else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1993 | if (bTKIP_UseGTK == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1994 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n"); |
| 1995 | } |
| 1996 | else { |
Malcolm Priestley | b4dc03a | 2012-11-11 15:45:52 +0000 | [diff] [blame] | 1997 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n", |
| 1998 | pTransmitKey->dwKeyIndex); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1999 | bNeedEncryption = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2000 | } |
| 2001 | } |
| 2002 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2003 | } |
| 2004 | else { |
| 2005 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2006 | if (pTransmitKey == NULL) { |
| 2007 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n"); |
| 2008 | dev_kfree_skb_irq(skb); |
| 2009 | pStats->tx_dropped++; |
| 2010 | return STATUS_FAILURE; |
| 2011 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | |
Malcolm Priestley | b674ee1 | 2014-05-15 22:49:10 +0100 | [diff] [blame] | 2015 | pContext = s_vGetFreeContext(pDevice); |
| 2016 | if (!pContext) { |
| 2017 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n"); |
| 2018 | dev_kfree_skb_irq(skb); |
| 2019 | return STATUS_RESOURCES; |
| 2020 | } |
| 2021 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2022 | pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0]; |
Malcolm Priestley | d0a2b8f | 2013-08-15 19:37:04 +0100 | [diff] [blame] | 2023 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 2024 | fConvertedPacket = s_bPacketToWirelessUsb(pContext, byPktType, |
Malcolm Priestley | d0a2b8f | 2013-08-15 19:37:04 +0100 | [diff] [blame] | 2025 | pTX_Buffer, bNeedEncryption, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 2026 | skb->len, &pDevice->sTxEthHeader, |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 2027 | (u8 *)skb->data, pTransmitKey, uNodeIndex, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2028 | pDevice->wCurrentRate, |
| 2029 | &uHeaderLen, &BytesToWrite |
| 2030 | ); |
| 2031 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2032 | if (fConvertedPacket == false) { |
| 2033 | pContext->in_use = false; |
| 2034 | dev_kfree_skb_irq(skb); |
| 2035 | return STATUS_FAILURE; |
| 2036 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2037 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 2038 | if ( pDevice->bEnablePSMode == true ) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2039 | if ( !pDevice->bPSModeTxBurst ) { |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 2040 | bScheduleCommand((void *) pDevice, |
| 2041 | WLAN_CMD_MAC_DISPOWERSAVING, |
| 2042 | NULL); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 2043 | pDevice->bPSModeTxBurst = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 2047 | pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
Malcolm Priestley | ca34759 | 2014-03-22 09:01:28 +0000 | [diff] [blame] | 2048 | pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2049 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2050 | pContext->skb = skb; |
| 2051 | pContext->type = CONTEXT_DATA_PACKET; |
| 2052 | pContext->buf_len = (u16)BytesToWrite + 4 ; /* USB header */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2053 | |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 2054 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
Malcolm Priestley | 81aec60 | 2014-02-27 23:06:11 +0000 | [diff] [blame] | 2055 | &pDevice->sTxEthHeader.h_dest[0], |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 2056 | (u16)(BytesToWrite-uHeaderLen), |
| 2057 | pTX_Buffer->fifo_head.wFIFOCtl); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2058 | |
| 2059 | status = PIPEnsSendBulkOut(pDevice,pContext); |
| 2060 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 2061 | if (bNeedDeAuth == true) { |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 2062 | u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2063 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 2064 | bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2065 | } |
| 2066 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2067 | if (status != STATUS_PENDING) { |
| 2068 | pContext->in_use = false; |
| 2069 | dev_kfree_skb_irq(skb); |
| 2070 | return STATUS_FAILURE; |
| 2071 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2072 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2073 | |
| 2074 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2075 | } |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 2076 | |
| 2077 | static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context, |
| 2078 | u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb, |
| 2079 | u16 payload_len, struct vnt_mic_hdr *mic_hdr) |
| 2080 | { |
| 2081 | struct ieee80211_hdr *hdr = tx_context->hdr; |
| 2082 | struct ieee80211_key_seq seq; |
| 2083 | u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb)); |
| 2084 | |
| 2085 | /* strip header and icv len from payload */ |
| 2086 | payload_len -= ieee80211_get_hdrlen_from_skb(skb); |
| 2087 | payload_len -= tx_key->icv_len; |
| 2088 | |
| 2089 | switch (tx_key->cipher) { |
| 2090 | case WLAN_CIPHER_SUITE_WEP40: |
| 2091 | case WLAN_CIPHER_SUITE_WEP104: |
| 2092 | memcpy(key_buffer, iv, 3); |
| 2093 | memcpy(key_buffer + 3, tx_key->key, tx_key->keylen); |
| 2094 | |
| 2095 | if (tx_key->keylen == WLAN_KEY_LEN_WEP40) { |
| 2096 | memcpy(key_buffer + 8, iv, 3); |
| 2097 | memcpy(key_buffer + 11, |
| 2098 | tx_key->key, WLAN_KEY_LEN_WEP40); |
| 2099 | } |
| 2100 | |
| 2101 | break; |
| 2102 | case WLAN_CIPHER_SUITE_TKIP: |
| 2103 | ieee80211_get_tkip_p2k(tx_key, skb, key_buffer); |
| 2104 | |
| 2105 | break; |
| 2106 | case WLAN_CIPHER_SUITE_CCMP: |
| 2107 | |
| 2108 | if (!mic_hdr) |
| 2109 | return; |
| 2110 | |
| 2111 | mic_hdr->id = 0x59; |
| 2112 | mic_hdr->payload_len = cpu_to_be16(payload_len); |
| 2113 | memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN); |
| 2114 | |
| 2115 | ieee80211_get_key_tx_seq(tx_key, &seq); |
| 2116 | |
| 2117 | mic_hdr->tsc_47_16 = cpu_to_be32((u32)seq.ccmp.pn[3] | |
| 2118 | ((u32)seq.ccmp.pn[2] << 8) | |
| 2119 | ((u32)seq.ccmp.pn[1] << 16) | |
| 2120 | ((u32)seq.ccmp.pn[0] << 24)); |
| 2121 | |
| 2122 | mic_hdr->tsc_15_0 = cpu_to_be16((u16)seq.ccmp.pn[5] | |
| 2123 | ((u16)seq.ccmp.pn[4] << 8)); |
| 2124 | |
| 2125 | if (ieee80211_has_a4(hdr->frame_control)) |
| 2126 | mic_hdr->hlen = cpu_to_be16(28); |
| 2127 | else |
| 2128 | mic_hdr->hlen = cpu_to_be16(22); |
| 2129 | |
| 2130 | memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN); |
| 2131 | memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN); |
| 2132 | memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN); |
| 2133 | |
| 2134 | mic_hdr->frame_control = cpu_to_le16( |
| 2135 | le16_to_cpu(hdr->frame_control) & 0xc78f); |
| 2136 | mic_hdr->seq_ctrl = cpu_to_le16( |
| 2137 | le16_to_cpu(hdr->seq_ctrl) & 0xf); |
| 2138 | |
| 2139 | if (ieee80211_has_a4(hdr->frame_control)) |
| 2140 | memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN); |
| 2141 | |
| 2142 | |
| 2143 | memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP); |
| 2144 | |
| 2145 | break; |
| 2146 | default: |
| 2147 | break; |
| 2148 | } |
| 2149 | |
| 2150 | } |
| 2151 | |
| 2152 | int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) |
| 2153 | { |
| 2154 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2155 | struct ieee80211_tx_rate *tx_rate = &info->control.rates[0]; |
| 2156 | struct ieee80211_rate *rate; |
| 2157 | struct ieee80211_key_conf *tx_key; |
| 2158 | struct ieee80211_hdr *hdr; |
| 2159 | struct vnt_mic_hdr *mic_hdr = NULL; |
| 2160 | struct vnt_tx_buffer *tx_buffer; |
| 2161 | struct vnt_tx_fifo_head *tx_buffer_head; |
| 2162 | struct vnt_usb_send_context *tx_context; |
| 2163 | unsigned long flags; |
| 2164 | u32 frame_size = 0; |
| 2165 | u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id; |
| 2166 | u8 pkt_type, fb_option = AUTO_FB_NONE; |
| 2167 | bool need_rts = false, need_ack = false, is_pspoll = false; |
| 2168 | bool need_mic = false; |
| 2169 | |
| 2170 | hdr = (struct ieee80211_hdr *)(skb->data); |
| 2171 | |
| 2172 | rate = ieee80211_get_tx_rate(priv->hw, info); |
| 2173 | |
| 2174 | current_rate = rate->hw_value; |
| 2175 | if (priv->wCurrentRate != current_rate) { |
| 2176 | priv->wCurrentRate = current_rate; |
| 2177 | bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL); |
| 2178 | } |
| 2179 | |
| 2180 | if (current_rate > RATE_11M) |
| 2181 | pkt_type = priv->byPacketType; |
| 2182 | else |
| 2183 | pkt_type = PK_TYPE_11B; |
| 2184 | |
| 2185 | spin_lock_irqsave(&priv->lock, flags); |
| 2186 | |
| 2187 | tx_context = s_vGetFreeContext(priv); |
| 2188 | if (!tx_context) { |
| 2189 | dev_dbg(&priv->usb->dev, "%s No free context\n", __func__); |
| 2190 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2191 | return -ENOMEM; |
| 2192 | } |
| 2193 | |
| 2194 | tx_context->skb = skb; |
| 2195 | |
| 2196 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2197 | |
| 2198 | tx_buffer = (struct vnt_tx_buffer *)tx_context->data; |
| 2199 | tx_buffer_head = &tx_buffer->fifo_head; |
| 2200 | tx_body_size = skb->len; |
| 2201 | |
| 2202 | frame_size = tx_body_size + 4; |
| 2203 | |
| 2204 | /* Set time stamp */ |
| 2205 | tx_buffer_head->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); |
| 2206 | |
| 2207 | /*Set fifo controls */ |
| 2208 | if (pkt_type == PK_TYPE_11A) |
| 2209 | tx_buffer_head->wFIFOCtl = 0; |
| 2210 | else if (pkt_type == PK_TYPE_11B) |
| 2211 | tx_buffer_head->wFIFOCtl = FIFOCTL_11B; |
| 2212 | else if (pkt_type == PK_TYPE_11GB) |
| 2213 | tx_buffer_head->wFIFOCtl = FIFOCTL_11GB; |
| 2214 | else if (pkt_type == PK_TYPE_11GA) |
| 2215 | tx_buffer_head->wFIFOCtl = FIFOCTL_11GA; |
| 2216 | |
| 2217 | if (!ieee80211_is_data(hdr->frame_control)) { |
| 2218 | tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT | |
| 2219 | FIFOCTL_ISDMA0); |
| 2220 | tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN; |
| 2221 | |
| 2222 | tx_buffer_head->time_stamp = |
| 2223 | cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); |
| 2224 | } else { |
| 2225 | tx_buffer_head->time_stamp = |
| 2226 | cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us); |
| 2227 | } |
| 2228 | |
| 2229 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
| 2230 | tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK; |
| 2231 | need_ack = true; |
| 2232 | } |
| 2233 | |
| 2234 | if (ieee80211_has_retry(hdr->frame_control)) |
| 2235 | tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY; |
| 2236 | |
| 2237 | if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 2238 | priv->byPreambleType = PREAMBLE_SHORT; |
| 2239 | else |
| 2240 | priv->byPreambleType = PREAMBLE_LONG; |
| 2241 | |
| 2242 | if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 2243 | need_rts = true; |
| 2244 | tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS; |
| 2245 | } |
| 2246 | |
| 2247 | if (ieee80211_has_a4(hdr->frame_control)) |
| 2248 | tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD; |
| 2249 | |
| 2250 | if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) |
| 2251 | is_pspoll = true; |
| 2252 | |
| 2253 | tx_buffer_head->wFragCtl = |
| 2254 | cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb)) << 10; |
| 2255 | |
| 2256 | if (info->control.hw_key) { |
| 2257 | tx_key = info->control.hw_key; |
| 2258 | switch (info->control.hw_key->cipher) { |
| 2259 | case WLAN_CIPHER_SUITE_WEP40: |
| 2260 | case WLAN_CIPHER_SUITE_WEP104: |
| 2261 | tx_buffer_head->wFragCtl |= FRAGCTL_LEGACY; |
| 2262 | break; |
| 2263 | case WLAN_CIPHER_SUITE_TKIP: |
| 2264 | tx_buffer_head->wFragCtl |= FRAGCTL_TKIP; |
| 2265 | break; |
| 2266 | case WLAN_CIPHER_SUITE_CCMP: |
| 2267 | tx_buffer_head->wFragCtl |= FRAGCTL_AES; |
| 2268 | need_mic = true; |
| 2269 | default: |
| 2270 | break; |
| 2271 | } |
| 2272 | frame_size += tx_key->icv_len; |
| 2273 | } |
| 2274 | |
| 2275 | /* legacy rates TODO use ieee80211_tx_rate */ |
| 2276 | if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) { |
| 2277 | if (priv->byAutoFBCtrl == AUTO_FB_0) { |
| 2278 | tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0; |
| 2279 | |
| 2280 | priv->tx_rate_fb0 = |
| 2281 | wFB_Opt0[FB_RATE0][current_rate - RATE_18M]; |
| 2282 | priv->tx_rate_fb1 = |
| 2283 | wFB_Opt0[FB_RATE1][current_rate - RATE_18M]; |
| 2284 | |
| 2285 | fb_option = AUTO_FB_0; |
| 2286 | } else if (priv->byAutoFBCtrl == AUTO_FB_1) { |
| 2287 | tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1; |
| 2288 | |
| 2289 | priv->tx_rate_fb0 = |
| 2290 | wFB_Opt1[FB_RATE0][current_rate - RATE_18M]; |
| 2291 | priv->tx_rate_fb1 = |
| 2292 | wFB_Opt1[FB_RATE1][current_rate - RATE_18M]; |
| 2293 | |
| 2294 | fb_option = AUTO_FB_1; |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | duration_id = s_vGenerateTxParameter(tx_context, pkt_type, current_rate, |
| 2299 | tx_buffer, &mic_hdr, need_mic, frame_size, |
| 2300 | need_ack, NULL, need_rts); |
| 2301 | |
| 2302 | tx_header_size = tx_context->tx_hdr_size; |
| 2303 | if (!tx_header_size) { |
| 2304 | tx_context->in_use = false; |
| 2305 | return -ENOMEM; |
| 2306 | } |
| 2307 | |
| 2308 | tx_buffer_head->wFragCtl |= (u16)FRAGCTL_NONFRAG; |
| 2309 | |
| 2310 | tx_bytes = tx_header_size + tx_body_size; |
| 2311 | |
| 2312 | memcpy(tx_context->hdr, skb->data, tx_body_size); |
| 2313 | |
| 2314 | hdr->duration_id = cpu_to_le16(duration_id); |
| 2315 | |
| 2316 | if (info->control.hw_key) { |
| 2317 | tx_key = info->control.hw_key; |
| 2318 | if (tx_key->keylen > 0) |
| 2319 | vnt_fill_txkey(tx_context, tx_buffer_head->tx_key, |
| 2320 | tx_key, skb, tx_body_size, mic_hdr); |
| 2321 | } |
| 2322 | |
| 2323 | priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) & |
| 2324 | IEEE80211_SCTL_SEQ) >> 4; |
| 2325 | |
| 2326 | tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes); |
| 2327 | tx_buffer->byPKTNO = (u8)(((current_rate << 4) & 0xf0) | |
| 2328 | (priv->wSeqCounter & 0xf)); |
| 2329 | tx_buffer->byType = 0x00; |
| 2330 | |
| 2331 | tx_bytes += 4; |
| 2332 | |
| 2333 | tx_context->type = CONTEXT_DATA_PACKET; |
| 2334 | tx_context->buf_len = tx_bytes; |
| 2335 | |
| 2336 | spin_lock_irqsave(&priv->lock, flags); |
| 2337 | |
| 2338 | if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) { |
| 2339 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2340 | return -EIO; |
| 2341 | } |
| 2342 | |
| 2343 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2344 | |
| 2345 | return 0; |
| 2346 | } |
| 2347 | |
| 2348 | static int vnt_beacon_xmit(struct vnt_private *priv, |
| 2349 | struct sk_buff *skb) |
| 2350 | { |
| 2351 | struct vnt_beacon_buffer *beacon_buffer; |
| 2352 | struct vnt_tx_short_buf_head *short_head; |
| 2353 | struct ieee80211_tx_info *info; |
| 2354 | struct vnt_usb_send_context *context; |
| 2355 | struct ieee80211_mgmt *mgmt_hdr; |
| 2356 | unsigned long flags; |
| 2357 | u32 frame_size = skb->len + 4; |
| 2358 | u16 current_rate, count; |
| 2359 | |
| 2360 | spin_lock_irqsave(&priv->lock, flags); |
| 2361 | |
| 2362 | context = s_vGetFreeContext(priv); |
| 2363 | if (!context) { |
| 2364 | dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__); |
| 2365 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2366 | return -ENOMEM; |
| 2367 | } |
| 2368 | |
| 2369 | context->skb = skb; |
| 2370 | |
| 2371 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2372 | |
| 2373 | beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0]; |
| 2374 | short_head = &beacon_buffer->short_head; |
| 2375 | |
| 2376 | if (priv->byBBType == BB_TYPE_11A) { |
| 2377 | current_rate = RATE_6M; |
| 2378 | |
| 2379 | /* Get SignalField,ServiceField,Length */ |
| 2380 | vnt_get_phy_field(priv, frame_size, current_rate, |
| 2381 | PK_TYPE_11A, &short_head->ab); |
| 2382 | |
| 2383 | /* Get Duration and TimeStampOff */ |
| 2384 | short_head->duration = s_uGetDataDuration(priv, |
| 2385 | PK_TYPE_11A, false); |
| 2386 | short_head->time_stamp_off = |
| 2387 | vnt_time_stamp_off(priv, current_rate); |
| 2388 | } else { |
| 2389 | current_rate = RATE_1M; |
| 2390 | short_head->fifo_ctl |= FIFOCTL_11B; |
| 2391 | |
| 2392 | /* Get SignalField,ServiceField,Length */ |
| 2393 | vnt_get_phy_field(priv, frame_size, current_rate, |
| 2394 | PK_TYPE_11B, &short_head->ab); |
| 2395 | |
| 2396 | /* Get Duration and TimeStampOff */ |
| 2397 | short_head->duration = s_uGetDataDuration(priv, |
| 2398 | PK_TYPE_11B, false); |
| 2399 | short_head->time_stamp_off = |
| 2400 | vnt_time_stamp_off(priv, current_rate); |
| 2401 | } |
| 2402 | |
| 2403 | /* Generate Beacon Header */ |
| 2404 | mgmt_hdr = &beacon_buffer->mgmt_hdr; |
| 2405 | memcpy(mgmt_hdr, skb->data, skb->len); |
| 2406 | |
| 2407 | /* time stamp always 0 */ |
| 2408 | mgmt_hdr->u.beacon.timestamp = 0; |
| 2409 | |
| 2410 | info = IEEE80211_SKB_CB(skb); |
| 2411 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 2412 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr; |
| 2413 | hdr->duration_id = 0; |
| 2414 | hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4); |
| 2415 | } |
| 2416 | |
| 2417 | priv->wSeqCounter++; |
| 2418 | if (priv->wSeqCounter > 0x0fff) |
| 2419 | priv->wSeqCounter = 0; |
| 2420 | |
| 2421 | count = sizeof(struct vnt_tx_short_buf_head) + skb->len; |
| 2422 | |
| 2423 | beacon_buffer->tx_byte_count = cpu_to_le16(count); |
| 2424 | beacon_buffer->byPKTNO = (u8)(((current_rate << 4) & 0xf0) | |
| 2425 | ((priv->wSeqCounter - 1) & 0x000f)); |
| 2426 | beacon_buffer->byType = 0x01; |
| 2427 | |
| 2428 | context->type = CONTEXT_BEACON_PACKET; |
| 2429 | context->buf_len = count + 4; /* USB header */ |
| 2430 | |
| 2431 | spin_lock_irqsave(&priv->lock, flags); |
| 2432 | |
| 2433 | if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING) |
| 2434 | ieee80211_free_txskb(priv->hw, context->skb); |
| 2435 | |
| 2436 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2437 | |
| 2438 | return 0; |
| 2439 | } |
| 2440 | |
| 2441 | int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif) |
| 2442 | { |
| 2443 | struct sk_buff *beacon; |
| 2444 | |
| 2445 | beacon = ieee80211_beacon_get(priv->hw, vif); |
| 2446 | if (!beacon) |
| 2447 | return -ENOMEM; |
| 2448 | |
| 2449 | if (vnt_beacon_xmit(priv, beacon)) { |
| 2450 | ieee80211_free_txskb(priv->hw, beacon); |
| 2451 | return -ENODEV; |
| 2452 | } |
| 2453 | |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
| 2457 | int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif, |
| 2458 | struct ieee80211_bss_conf *conf) |
| 2459 | { |
| 2460 | int ret; |
| 2461 | |
| 2462 | vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); |
| 2463 | |
| 2464 | vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); |
| 2465 | |
| 2466 | vnt_mac_set_beacon_interval(priv, conf->beacon_int); |
| 2467 | |
| 2468 | vnt_clear_current_tsf(priv); |
| 2469 | |
| 2470 | vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); |
| 2471 | |
| 2472 | vnt_reset_next_tbtt(priv, conf->beacon_int); |
| 2473 | |
| 2474 | ret = vnt_beacon_make(priv, vif); |
| 2475 | |
| 2476 | return ret; |
| 2477 | } |