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 | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 99 | static u16 s_vGenerateTxParameter(struct vnt_private *pDevice, |
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, |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 105 | u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 106 | int bNeedEncrypt, u16 wFragType, u32 uFragIdx); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 107 | |
Malcolm Priestley | 3ba0938 | 2013-10-15 21:41:38 +0100 | [diff] [blame] | 108 | static void s_vFillTxKey(struct vnt_private *pDevice, |
| 109 | struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead, |
| 110 | PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen, |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 111 | 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 | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 122 | static u16 s_vFillCTSHead(struct vnt_private *pDevice, |
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 | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 126 | static u16 s_vFillRTSHead(struct vnt_private *pDevice, 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); |
| 154 | return context; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | if (ii == priv->cbTD) |
| 159 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n"); |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 160 | |
Malcolm Priestley | 5c85138 | 2013-11-26 19:12:38 +0000 | [diff] [blame] | 161 | return NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 162 | } |
| 163 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 164 | static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum, |
| 165 | u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 166 | { |
Malcolm Priestley | ae27b14 | 2013-12-09 22:23:19 +0000 | [diff] [blame] | 167 | struct net_device_stats *stats = &pDevice->stats; |
Malcolm Priestley | 51934e7 | 2013-12-09 22:30:14 +0000 | [diff] [blame] | 168 | struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 169 | |
Malcolm Priestley | 51934e7 | 2013-12-09 22:30:14 +0000 | [diff] [blame] | 170 | pkt_info[byPktNum].fifo_ctl = wFIFOCtl; |
| 171 | memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN); |
Malcolm Priestley | ae27b14 | 2013-12-09 22:23:19 +0000 | [diff] [blame] | 172 | |
| 173 | stats->tx_bytes += wPktLength; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 174 | } |
| 175 | |
Malcolm Priestley | 3ba0938 | 2013-10-15 21:41:38 +0100 | [diff] [blame] | 176 | static void s_vFillTxKey(struct vnt_private *pDevice, |
| 177 | struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead, |
| 178 | PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen, |
| 179 | struct vnt_mic_hdr *mic_hdr) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 180 | { |
Malcolm Priestley | 3ba0938 | 2013-10-15 21:41:38 +0100 | [diff] [blame] | 181 | u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0]; |
Malcolm Priestley | fb453db | 2014-03-22 09:01:24 +0000 | [diff] [blame] | 182 | __le32 *pdwIV = (__le32 *)pbyIVHead; |
Malcolm Priestley | 2fbb230 | 2014-03-22 09:01:25 +0000 | [diff] [blame] | 183 | __le32 *pdwExtIV = (__le32 *)((u8 *)pbyIVHead + 4); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 184 | struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf; |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 185 | __le32 rev_iv_counter; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 186 | |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 187 | /* Fill TXKEY */ |
| 188 | if (pTransmitKey == NULL) |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 189 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 190 | |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 191 | rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter); |
Malcolm Priestley | fb453db | 2014-03-22 09:01:24 +0000 | [diff] [blame] | 192 | *pdwIV = cpu_to_le32(pDevice->dwIVCounter); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 193 | pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 194 | |
Malcolm Priestley | f6804f3 | 2013-08-27 12:32:01 +0100 | [diff] [blame] | 195 | switch (pTransmitKey->byCipherSuite) { |
| 196 | case KEY_CTL_WEP: |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 197 | if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) { |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 198 | memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 199 | memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey, |
| 200 | pTransmitKey->uKeyLength); |
| 201 | } else { |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 202 | memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 203 | memcpy(pbyBuf + 3, pTransmitKey->abyKey, |
| 204 | pTransmitKey->uKeyLength); |
| 205 | if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) { |
Malcolm Priestley | fbfaccf | 2014-03-22 09:01:23 +0000 | [diff] [blame] | 206 | memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 207 | memcpy(pbyBuf+11, pTransmitKey->abyKey, |
| 208 | pTransmitKey->uKeyLength); |
| 209 | } |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 210 | |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 211 | memcpy(pDevice->abyPRNG, pbyBuf, 16); |
| 212 | } |
| 213 | /* Append IV after Mac Header */ |
Malcolm Priestley | fb453db | 2014-03-22 09:01:24 +0000 | [diff] [blame] | 214 | *pdwIV &= cpu_to_le32(WEP_IV_MASK); |
| 215 | *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30); |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 216 | |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 217 | pDevice->dwIVCounter++; |
| 218 | if (pDevice->dwIVCounter > WEP_IV_MASK) |
| 219 | pDevice->dwIVCounter = 0; |
Malcolm Priestley | f6804f3 | 2013-08-27 12:32:01 +0100 | [diff] [blame] | 220 | |
| 221 | break; |
| 222 | case KEY_CTL_TKIP: |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 223 | pTransmitKey->wTSC15_0++; |
| 224 | if (pTransmitKey->wTSC15_0 == 0) |
| 225 | pTransmitKey->dwTSC47_16++; |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 226 | |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 227 | TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr, |
| 228 | pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, |
| 229 | pDevice->abyPRNG); |
| 230 | memcpy(pbyBuf, pDevice->abyPRNG, 16); |
| 231 | |
| 232 | /* Make IV */ |
| 233 | memcpy(pdwIV, pDevice->abyPRNG, 3); |
| 234 | |
| 235 | *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & |
| 236 | 0xc0) | 0x20); |
| 237 | /* Append IV&ExtIV after Mac Header */ |
| 238 | *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16); |
| 239 | |
| 240 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 241 | "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV); |
| 242 | |
Malcolm Priestley | f6804f3 | 2013-08-27 12:32:01 +0100 | [diff] [blame] | 243 | break; |
| 244 | case KEY_CTL_CCMP: |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 245 | pTransmitKey->wTSC15_0++; |
| 246 | if (pTransmitKey->wTSC15_0 == 0) |
| 247 | pTransmitKey->dwTSC47_16++; |
| 248 | |
| 249 | memcpy(pbyBuf, pTransmitKey->abyKey, 16); |
| 250 | |
| 251 | /* Make IV */ |
| 252 | *pdwIV = 0; |
| 253 | *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & |
| 254 | 0xc0) | 0x20); |
| 255 | |
Malcolm Priestley | fb453db | 2014-03-22 09:01:24 +0000 | [diff] [blame] | 256 | *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0)); |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 257 | |
| 258 | /* Append IV&ExtIV after Mac Header */ |
| 259 | *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16); |
| 260 | |
| 261 | if (!mic_hdr) |
| 262 | return; |
| 263 | |
| 264 | /* MICHDR0 */ |
| 265 | mic_hdr->id = 0x59; |
| 266 | mic_hdr->payload_len = cpu_to_be16(wPayloadLen); |
| 267 | memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN); |
| 268 | |
| 269 | mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16); |
| 270 | mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0); |
| 271 | |
| 272 | /* MICHDR1 */ |
Malcolm Priestley | 078d0cf | 2013-11-25 22:14:16 +0000 | [diff] [blame] | 273 | if (ieee80211_has_a4(pMACHeader->frame_control)) |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 274 | mic_hdr->hlen = cpu_to_be16(28); |
| 275 | else |
| 276 | mic_hdr->hlen = cpu_to_be16(22); |
| 277 | |
| 278 | memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN); |
| 279 | memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN); |
| 280 | |
| 281 | /* MICHDR2 */ |
| 282 | memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN); |
Malcolm Priestley | 5d4fe75 | 2014-03-22 09:01:26 +0000 | [diff] [blame] | 283 | mic_hdr->frame_control = cpu_to_le16( |
| 284 | le16_to_cpu(pMACHeader->frame_control) & 0xc78f); |
| 285 | mic_hdr->seq_ctrl = cpu_to_le16( |
| 286 | le16_to_cpu(pMACHeader->seq_ctrl) & 0xf); |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 287 | |
Malcolm Priestley | 078d0cf | 2013-11-25 22:14:16 +0000 | [diff] [blame] | 288 | if (ieee80211_has_a4(pMACHeader->frame_control)) |
Malcolm Priestley | 95bfb1a | 2013-08-27 12:29:10 +0100 | [diff] [blame] | 289 | memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN); |
| 290 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 293 | static void s_vSWencryption(struct vnt_private *pDevice, |
| 294 | PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 295 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 296 | u32 cbICVlen = 4; |
| 297 | u32 dwICV = 0xffffffff; |
| 298 | u32 *pdwICV; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 299 | |
| 300 | if (pTransmitKey == NULL) |
| 301 | return; |
| 302 | |
| 303 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { |
| 304 | //======================================================================= |
| 305 | // Append ICV after payload |
Malcolm Priestley | 929cb31 | 2014-05-21 21:09:42 +0100 | [diff] [blame] | 306 | dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead); |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 307 | pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 308 | // finally, we must invert dwCRC to get the correct answer |
| 309 | *pdwICV = cpu_to_le32(~dwICV); |
| 310 | // RC4 encryption |
| 311 | rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3); |
| 312 | rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen); |
| 313 | //======================================================================= |
| 314 | } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { |
| 315 | //======================================================================= |
| 316 | //Append ICV after payload |
Malcolm Priestley | 929cb31 | 2014-05-21 21:09:42 +0100 | [diff] [blame] | 317 | dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead); |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 318 | pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 319 | // finally, we must invert dwCRC to get the correct answer |
| 320 | *pdwICV = cpu_to_le32(~dwICV); |
| 321 | // RC4 encryption |
| 322 | rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN); |
| 323 | rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen); |
| 324 | //======================================================================= |
| 325 | } |
| 326 | } |
| 327 | |
Malcolm Priestley | dab085b | 2014-03-18 19:25:03 +0000 | [diff] [blame] | 328 | static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate) |
Malcolm Priestley | f115e76 | 2013-08-23 11:48:46 +0100 | [diff] [blame] | 329 | { |
| 330 | return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2] |
| 331 | [rate % MAX_RATE]); |
| 332 | } |
| 333 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 334 | /*byPktType : PK_TYPE_11A 0 |
| 335 | PK_TYPE_11B 1 |
| 336 | PK_TYPE_11GB 2 |
| 337 | PK_TYPE_11GA 3 |
| 338 | */ |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 339 | static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type, |
| 340 | u32 frame_length, u16 rate, int need_ack) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 341 | { |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 342 | u32 data_time, ack_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 343 | |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 344 | data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, |
| 345 | frame_length, rate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 346 | |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 347 | if (pkt_type == PK_TYPE_11B) |
| 348 | ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14, |
| 349 | (u16)priv->byTopCCKBasicRate); |
| 350 | else |
| 351 | ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14, |
| 352 | (u16)priv->byTopOFDMBasicRate); |
| 353 | |
| 354 | if (need_ack) |
| 355 | return data_time + priv->uSIFS + ack_time; |
| 356 | |
| 357 | return data_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 358 | } |
| 359 | |
Malcolm Priestley | 2075f65 | 2014-03-18 19:25:07 +0000 | [diff] [blame] | 360 | 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] | 361 | u32 frame_length, u16 rate, int need_ack) |
| 362 | { |
| 363 | return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type, |
| 364 | frame_length, rate, need_ack)); |
| 365 | } |
| 366 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 367 | //byFreqType: 0=>5GHZ 1=>2.4GHZ |
Malcolm Priestley | 2033801 | 2014-03-18 19:25:08 +0000 | [diff] [blame] | 368 | static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv, |
Malcolm Priestley | 3b6cee7be | 2014-05-25 21:36:27 +0100 | [diff] [blame^] | 369 | u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 370 | { |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 371 | u32 rrv_time, rts_time, cts_time, ack_time, data_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 372 | |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 373 | rrv_time = rts_time = cts_time = ack_time = data_time = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 374 | |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 375 | data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 3b6cee7be | 2014-05-25 21:36:27 +0100 | [diff] [blame^] | 376 | frame_length, current_rate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 377 | |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 378 | if (rsv_type == 0) { |
| 379 | rts_time = BBuGetFrameTime(priv->byPreambleType, |
| 380 | pkt_type, 20, priv->byTopCCKBasicRate); |
| 381 | cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType, |
| 382 | pkt_type, 14, priv->byTopCCKBasicRate); |
| 383 | } else if (rsv_type == 1) { |
| 384 | rts_time = BBuGetFrameTime(priv->byPreambleType, |
| 385 | pkt_type, 20, priv->byTopCCKBasicRate); |
| 386 | cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, |
| 387 | 14, priv->byTopCCKBasicRate); |
| 388 | ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, |
| 389 | 14, priv->byTopOFDMBasicRate); |
| 390 | } else if (rsv_type == 2) { |
| 391 | rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, |
| 392 | 20, priv->byTopOFDMBasicRate); |
| 393 | cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType, |
| 394 | pkt_type, 14, priv->byTopOFDMBasicRate); |
| 395 | } else if (rsv_type == 3) { |
| 396 | cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, |
| 397 | 14, priv->byTopCCKBasicRate); |
| 398 | ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, |
| 399 | 14, priv->byTopOFDMBasicRate); |
| 400 | |
| 401 | rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS; |
| 402 | |
Malcolm Priestley | 2033801 | 2014-03-18 19:25:08 +0000 | [diff] [blame] | 403 | return cpu_to_le16((u16)rrv_time); |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS; |
| 407 | |
| 408 | return cpu_to_le16((u16)rrv_time); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | //byFreqType 0: 5GHz, 1:2.4Ghz |
Malcolm Priestley | 5abe3d6 | 2014-03-18 19:25:06 +0000 | [diff] [blame] | 412 | static __le16 s_uGetDataDuration(struct vnt_private *pDevice, |
Malcolm Priestley | 6b5ad9d | 2013-08-21 22:16:04 +0100 | [diff] [blame] | 413 | u8 byPktType, int bNeedAck) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 414 | { |
Malcolm Priestley | 0005cb0 | 2013-08-07 21:26:12 +0100 | [diff] [blame] | 415 | u32 uAckTime = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 416 | |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 417 | if (bNeedAck) { |
Malcolm Priestley | 6b5ad9d | 2013-08-21 22:16:04 +0100 | [diff] [blame] | 418 | if (byPktType == PK_TYPE_11B) |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 419 | uAckTime = BBuGetFrameTime(pDevice->byPreambleType, |
| 420 | byPktType, 14, pDevice->byTopCCKBasicRate); |
| 421 | else |
| 422 | uAckTime = BBuGetFrameTime(pDevice->byPreambleType, |
| 423 | byPktType, 14, pDevice->byTopOFDMBasicRate); |
Malcolm Priestley | d500595 | 2013-08-21 21:58:37 +0100 | [diff] [blame] | 424 | return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime)); |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 425 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 426 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 430 | //byFreqType: 0=>5GHZ 1=>2.4GHZ |
Malcolm Priestley | 7f591a1 | 2014-03-18 19:25:05 +0000 | [diff] [blame] | 431 | static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType, |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 432 | u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck, |
| 433 | u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 434 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 435 | u32 uCTSTime = 0, uDurTime = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 436 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 437 | switch (byDurType) { |
| 438 | case RTSDUR_BB: |
| 439 | case RTSDUR_BA: |
| 440 | case RTSDUR_BA_F0: |
| 441 | case RTSDUR_BA_F1: |
| 442 | uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, |
| 443 | 14, pDevice->byTopCCKBasicRate); |
| 444 | uDurTime = uCTSTime + 2 * pDevice->uSIFS + |
| 445 | s_uGetTxRsvTime(pDevice, byPktType, |
| 446 | cbFrameLength, wRate, bNeedAck); |
| 447 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 448 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 449 | case RTSDUR_AA: |
| 450 | case RTSDUR_AA_F0: |
| 451 | case RTSDUR_AA_F1: |
| 452 | uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, |
| 453 | 14, pDevice->byTopOFDMBasicRate); |
| 454 | uDurTime = uCTSTime + 2 * pDevice->uSIFS + |
| 455 | s_uGetTxRsvTime(pDevice, byPktType, |
| 456 | cbFrameLength, wRate, bNeedAck); |
| 457 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 458 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 459 | case CTSDUR_BA: |
| 460 | case CTSDUR_BA_F0: |
| 461 | case CTSDUR_BA_F1: |
| 462 | uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 463 | byPktType, cbFrameLength, wRate, bNeedAck); |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 464 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 465 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 466 | default: |
| 467 | break; |
| 468 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 469 | |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 470 | return cpu_to_le16((u16)uDurTime); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 471 | } |
| 472 | |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 473 | static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate, |
| 474 | struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack) |
| 475 | { |
| 476 | /* Get SignalField,ServiceField,Length */ |
| 477 | BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a); |
| 478 | BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate, |
| 479 | PK_TYPE_11B, &buf->b); |
| 480 | |
| 481 | /* Get Duration and TimeStamp */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 482 | buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 483 | buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack); |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 484 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 485 | buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); |
| 486 | buf->time_stamp_off_b = vnt_time_stamp_off(priv, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 487 | priv->byTopCCKBasicRate); |
| 488 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 489 | return le16_to_cpu(buf->duration_a); |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 490 | } |
| 491 | |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 492 | static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type, |
| 493 | u16 rate, struct vnt_tx_datahead_g_fb *buf, |
| 494 | u32 frame_len, int need_ack) |
| 495 | { |
| 496 | /* Get SignalField,ServiceField,Length */ |
| 497 | BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a); |
| 498 | |
| 499 | BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate, |
| 500 | PK_TYPE_11B, &buf->b); |
| 501 | |
| 502 | /* Get Duration and TimeStamp */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 503 | buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 504 | buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 505 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 506 | buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 507 | buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 508 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 509 | buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); |
| 510 | buf->time_stamp_off_b = vnt_time_stamp_off(priv, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 511 | priv->byTopCCKBasicRate); |
| 512 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 513 | return le16_to_cpu(buf->duration_a); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 516 | static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type, |
| 517 | u16 rate, struct vnt_tx_datahead_a_fb *buf, |
| 518 | u32 frame_len, int need_ack) |
| 519 | { |
| 520 | /* Get SignalField,ServiceField,Length */ |
| 521 | BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a); |
| 522 | /* Get Duration and TimeStampOff */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 523 | buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 524 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 525 | buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 526 | buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 527 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 528 | buf->time_stamp_off = vnt_time_stamp_off(priv, rate); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 529 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 530 | return le16_to_cpu(buf->duration); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 533 | static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type, |
| 534 | u16 rate, struct vnt_tx_datahead_ab *buf, |
| 535 | u32 frame_len, int need_ack) |
| 536 | { |
| 537 | /* Get SignalField,ServiceField,Length */ |
| 538 | BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab); |
| 539 | /* Get Duration and TimeStampOff */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 540 | buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 541 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 542 | buf->time_stamp_off = vnt_time_stamp_off(priv, rate); |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 543 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 544 | return le16_to_cpu(buf->duration); |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 547 | static int vnt_fill_ieee80211_rts(struct vnt_private *priv, |
| 548 | struct ieee80211_rts *rts, struct ethhdr *eth_hdr, |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 549 | __le16 duration) |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 550 | { |
| 551 | rts->duration = duration; |
Malcolm Priestley | f4554d3 | 2014-03-22 09:01:31 +0000 | [diff] [blame] | 552 | rts->frame_control = |
| 553 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 554 | |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 555 | if (priv->op_mode == NL80211_IFTYPE_ADHOC || |
| 556 | priv->op_mode == NL80211_IFTYPE_AP) |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 557 | memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN); |
| 558 | else |
| 559 | memcpy(rts->ra, priv->abyBSSID, ETH_ALEN); |
| 560 | |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 561 | if (priv->op_mode == NL80211_IFTYPE_AP) |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 562 | memcpy(rts->ta, priv->abyBSSID, ETH_ALEN); |
| 563 | else |
| 564 | memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN); |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 569 | static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 570 | struct vnt_rts_g *buf, struct ethhdr *eth_hdr, |
| 571 | u8 pkt_type, u32 frame_len, int need_ack, |
| 572 | u16 current_rate, u8 fb_option) |
| 573 | { |
| 574 | u16 rts_frame_len = 20; |
| 575 | |
| 576 | BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate, |
| 577 | PK_TYPE_11B, &buf->b); |
| 578 | BBvCalculateParameter(priv, rts_frame_len, |
| 579 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 580 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 581 | buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 582 | PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 583 | buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 584 | pkt_type, current_rate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 585 | buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 586 | pkt_type, current_rate, need_ack, fb_option); |
| 587 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 588 | vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 589 | |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 590 | return vnt_rxtx_datahead_g(priv, pkt_type, current_rate, |
| 591 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 594 | static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 595 | struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr, |
| 596 | u8 pkt_type, u32 frame_len, int need_ack, |
| 597 | u16 current_rate, u8 fb_option) |
| 598 | { |
| 599 | u16 rts_frame_len = 20; |
| 600 | |
| 601 | BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate, |
| 602 | PK_TYPE_11B, &buf->b); |
| 603 | BBvCalculateParameter(priv, rts_frame_len, |
| 604 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 605 | |
| 606 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 607 | buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 608 | PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 609 | buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 610 | pkt_type, current_rate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 611 | buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 612 | pkt_type, current_rate, need_ack, fb_option); |
| 613 | |
| 614 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 615 | buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 616 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 617 | buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 618 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 619 | buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 620 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 621 | buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 622 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 623 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 624 | vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 625 | |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 626 | return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate, |
| 627 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 628 | } |
| 629 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 630 | static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 631 | struct vnt_rts_ab *buf, struct ethhdr *eth_hdr, |
| 632 | u8 pkt_type, u32 frame_len, int need_ack, |
| 633 | u16 current_rate, u8 fb_option) |
| 634 | { |
| 635 | u16 rts_frame_len = 20; |
| 636 | |
| 637 | BBvCalculateParameter(priv, rts_frame_len, |
| 638 | priv->byTopOFDMBasicRate, pkt_type, &buf->ab); |
| 639 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 640 | buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 641 | pkt_type, current_rate, need_ack, fb_option); |
| 642 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 643 | vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration); |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 644 | |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 645 | return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate, |
| 646 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 647 | } |
| 648 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 649 | static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv, |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 650 | struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr, |
| 651 | u8 pkt_type, u32 frame_len, int need_ack, |
| 652 | u16 current_rate, u8 fb_option) |
| 653 | { |
| 654 | u16 rts_frame_len = 20; |
| 655 | |
| 656 | BBvCalculateParameter(priv, rts_frame_len, |
| 657 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 658 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 659 | buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 660 | pkt_type, current_rate, need_ack, fb_option); |
| 661 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 662 | buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 663 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 664 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 665 | buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 666 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 667 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 668 | vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 669 | |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 670 | return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate, |
| 671 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 672 | } |
| 673 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 674 | static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType, |
Malcolm Priestley | 5fb8e41 | 2013-08-27 12:07:58 +0100 | [diff] [blame] | 675 | union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck, |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 676 | struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 677 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 678 | |
Malcolm Priestley | 13fe62a | 2013-08-26 11:17:52 +0100 | [diff] [blame] | 679 | if (!head) |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 680 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 681 | |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 682 | /* Note: So far RTSHead doesn't appear in ATIM |
| 683 | * & Beacom DMA, so we don't need to take them |
| 684 | * into account. |
| 685 | * Otherwise, we need to modified codes for them. |
| 686 | */ |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 687 | switch (byPktType) { |
| 688 | case PK_TYPE_11GB: |
| 689 | case PK_TYPE_11GA: |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 690 | if (byFBOption == AUTO_FB_NONE) |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 691 | return vnt_rxtx_rts_g_head(pDevice, &head->rts_g, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 692 | psEthHeader, byPktType, cbFrameLength, |
| 693 | bNeedAck, wCurrentRate, byFBOption); |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 694 | else |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 695 | return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 696 | psEthHeader, byPktType, cbFrameLength, |
| 697 | bNeedAck, wCurrentRate, byFBOption); |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 698 | break; |
| 699 | case PK_TYPE_11A: |
Malcolm Priestley | 2b83ebd | 2013-08-27 09:58:21 +0100 | [diff] [blame] | 700 | if (byFBOption) { |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 701 | return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb, |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 702 | psEthHeader, byPktType, cbFrameLength, |
| 703 | bNeedAck, wCurrentRate, byFBOption); |
Malcolm Priestley | 2b83ebd | 2013-08-27 09:58:21 +0100 | [diff] [blame] | 704 | break; |
| 705 | } |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 706 | case PK_TYPE_11B: |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 707 | return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 708 | psEthHeader, byPktType, cbFrameLength, |
| 709 | bNeedAck, wCurrentRate, byFBOption); |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 710 | } |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 711 | |
| 712 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 715 | static u16 s_vFillCTSHead(struct vnt_private *pDevice, |
Malcolm Priestley | 5fb8e41 | 2013-08-27 12:07:58 +0100 | [diff] [blame] | 716 | u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength, |
| 717 | int bNeedAck, u16 wCurrentRate, u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 718 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 719 | u32 uCTSFrameLen = 14; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 720 | |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 721 | if (!head) |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 722 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 723 | |
Malcolm Priestley | c921cc8 | 2013-08-20 20:47:49 +0100 | [diff] [blame] | 724 | if (byFBOption != AUTO_FB_NONE) { |
| 725 | /* Auto Fall back */ |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 726 | struct vnt_cts_fb *pBuf = &head->cts_g_fb; |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 727 | /* Get SignalField,ServiceField,Length */ |
| 728 | BBvCalculateParameter(pDevice, uCTSFrameLen, |
| 729 | pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 730 | pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 731 | cbFrameLength, byPktType, |
| 732 | wCurrentRate, bNeedAck, byFBOption); |
| 733 | /* Get CTSDuration_ba_f0 */ |
Malcolm Priestley | 7fd5747 | 2014-03-18 19:24:59 +0000 | [diff] [blame] | 734 | pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 735 | CTSDUR_BA_F0, cbFrameLength, byPktType, |
| 736 | pDevice->tx_rate_fb0, bNeedAck, byFBOption); |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 737 | /* Get CTSDuration_ba_f1 */ |
Malcolm Priestley | 7fd5747 | 2014-03-18 19:24:59 +0000 | [diff] [blame] | 738 | pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 739 | CTSDUR_BA_F1, cbFrameLength, byPktType, |
| 740 | pDevice->tx_rate_fb1, bNeedAck, byFBOption); |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 741 | /* Get CTS Frame body */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 742 | pBuf->data.duration = pBuf->duration_ba; |
Malcolm Priestley | d9560ae | 2014-03-22 09:01:32 +0000 | [diff] [blame] | 743 | pBuf->data.frame_control = |
| 744 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); |
| 745 | |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 746 | memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 747 | |
| 748 | return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate, |
| 749 | &pBuf->data_head, cbFrameLength, bNeedAck); |
Malcolm Priestley | c921cc8 | 2013-08-20 20:47:49 +0100 | [diff] [blame] | 750 | } else { |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 751 | struct vnt_cts *pBuf = &head->cts_g; |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 752 | /* Get SignalField,ServiceField,Length */ |
| 753 | BBvCalculateParameter(pDevice, uCTSFrameLen, |
| 754 | pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b); |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 755 | /* Get CTSDuration_ba */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 756 | pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 757 | CTSDUR_BA, cbFrameLength, byPktType, |
| 758 | wCurrentRate, bNeedAck, byFBOption); |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 759 | /*Get CTS Frame body*/ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 760 | pBuf->data.duration = pBuf->duration_ba; |
Malcolm Priestley | d9560ae | 2014-03-22 09:01:32 +0000 | [diff] [blame] | 761 | pBuf->data.frame_control = |
| 762 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); |
| 763 | |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 764 | memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 765 | |
| 766 | return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate, |
| 767 | &pBuf->data_head, cbFrameLength, bNeedAck); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 768 | } |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 769 | |
| 770 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 773 | /*+ |
| 774 | * |
| 775 | * Description: |
| 776 | * Generate FIFO control for MAC & Baseband controller |
| 777 | * |
| 778 | * Parameters: |
| 779 | * In: |
| 780 | * pDevice - Pointer to adpater |
| 781 | * pTxDataHead - Transmit Data Buffer |
| 782 | * pTxBufHead - pTxBufHead |
| 783 | * pvRrvTime - pvRrvTime |
| 784 | * pvRTS - RTS Buffer |
| 785 | * pCTS - CTS Buffer |
| 786 | * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS) |
| 787 | * bNeedACK - If need ACK |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 788 | * Out: |
| 789 | * none |
| 790 | * |
| 791 | * Return Value: none |
| 792 | * |
| 793 | -*/ |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 794 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 795 | static u16 s_vGenerateTxParameter(struct vnt_private *pDevice, |
Malcolm Priestley | 8e344c8 | 2013-09-17 19:58:11 +0100 | [diff] [blame] | 796 | u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer, |
Malcolm Priestley | fa57560 | 2013-09-26 19:00:41 +0100 | [diff] [blame] | 797 | struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 798 | int bNeedACK, struct ethhdr *psEthHeader, bool need_rts) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 799 | { |
Malcolm Priestley | 8e344c8 | 2013-09-17 19:58:11 +0100 | [diff] [blame] | 800 | struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 801 | union vnt_tx_data_head *head = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 802 | u16 wFifoCtl; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 803 | u8 byFBOption = AUTO_FB_NONE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 804 | |
Malcolm Priestley | 03a9cf3 | 2014-03-22 09:01:30 +0000 | [diff] [blame] | 805 | pFifoHead->current_rate = cpu_to_le16(wCurrentRate); |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 806 | wFifoCtl = pFifoHead->wFIFOCtl; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 807 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 808 | if (wFifoCtl & FIFOCTL_AUTO_FB_0) |
| 809 | byFBOption = AUTO_FB_0; |
| 810 | else if (wFifoCtl & FIFOCTL_AUTO_FB_1) |
| 811 | byFBOption = AUTO_FB_1; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 812 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 813 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) { |
| 814 | if (need_rts) { |
| 815 | struct vnt_rrv_time_rts *pBuf = |
| 816 | &tx_buffer->tx_head.tx_rts.rts; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 817 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 818 | pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 819 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 820 | pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 821 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 822 | pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 823 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 824 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 825 | pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 826 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 827 | pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 828 | PK_TYPE_11B, cbFrameSize, |
| 829 | pDevice->byTopCCKBasicRate, bNeedACK); |
| 830 | |
| 831 | if (need_mic) { |
| 832 | *mic_hdr = &tx_buffer-> |
| 833 | tx_head.tx_rts.tx.mic.hdr; |
| 834 | head = &tx_buffer->tx_head.tx_rts.tx.mic.head; |
| 835 | } else { |
| 836 | head = &tx_buffer->tx_head.tx_rts.tx.head; |
| 837 | } |
| 838 | |
| 839 | /* Fill RTS */ |
| 840 | return s_vFillRTSHead(pDevice, byPktType, head, |
| 841 | cbFrameSize, bNeedACK, psEthHeader, |
| 842 | wCurrentRate, byFBOption); |
| 843 | |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 844 | } else { |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 845 | struct vnt_rrv_time_cts *pBuf = &tx_buffer-> |
| 846 | tx_head.tx_cts.cts; |
| 847 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 848 | pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 849 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 850 | pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 851 | PK_TYPE_11B, cbFrameSize, |
| 852 | pDevice->byTopCCKBasicRate, bNeedACK); |
| 853 | |
Malcolm Priestley | 372108e | 2014-03-18 19:25:00 +0000 | [diff] [blame] | 854 | pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 855 | byPktType, cbFrameSize, wCurrentRate); |
| 856 | |
| 857 | if (need_mic) { |
| 858 | *mic_hdr = &tx_buffer-> |
| 859 | tx_head.tx_cts.tx.mic.hdr; |
| 860 | head = &tx_buffer->tx_head.tx_cts.tx.mic.head; |
| 861 | } else { |
| 862 | head = &tx_buffer->tx_head.tx_cts.tx.head; |
| 863 | } |
| 864 | |
| 865 | /* Fill CTS */ |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 866 | return s_vFillCTSHead(pDevice, byPktType, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 867 | head, cbFrameSize, bNeedACK, wCurrentRate, |
| 868 | byFBOption); |
| 869 | } |
| 870 | } else if (byPktType == PK_TYPE_11A) { |
| 871 | if (need_mic) { |
| 872 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; |
| 873 | head = &tx_buffer->tx_head.tx_ab.tx.mic.head; |
| 874 | } else { |
| 875 | head = &tx_buffer->tx_head.tx_ab.tx.head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 876 | } |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 877 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 878 | if (need_rts) { |
| 879 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 880 | tx_head.tx_ab.ab; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 881 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 882 | pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 883 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 884 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 885 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 886 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
| 887 | |
| 888 | /* Fill RTS */ |
| 889 | return s_vFillRTSHead(pDevice, byPktType, head, |
| 890 | cbFrameSize, bNeedACK, psEthHeader, |
| 891 | wCurrentRate, byFBOption); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 892 | } else { |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 893 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 894 | tx_head.tx_ab.ab; |
| 895 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 896 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 897 | PK_TYPE_11A, cbFrameSize, |
| 898 | wCurrentRate, bNeedACK); |
| 899 | |
| 900 | return vnt_rxtx_datahead_a_fb(pDevice, byPktType, |
| 901 | wCurrentRate, &head->data_head_a_fb, |
| 902 | cbFrameSize, bNeedACK); |
| 903 | } |
| 904 | } else if (byPktType == PK_TYPE_11B) { |
| 905 | if (need_mic) { |
| 906 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; |
| 907 | head = &tx_buffer->tx_head.tx_ab.tx.mic.head; |
| 908 | } else { |
| 909 | head = &tx_buffer->tx_head.tx_ab.tx.head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 910 | } |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 911 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 912 | if (need_rts) { |
| 913 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 914 | tx_head.tx_ab.ab; |
Malcolm Priestley | a90186e | 2013-10-01 15:58:54 +0100 | [diff] [blame] | 915 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 916 | pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 917 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 918 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 919 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 920 | PK_TYPE_11B, cbFrameSize, wCurrentRate, |
| 921 | bNeedACK); |
| 922 | |
| 923 | /* Fill RTS */ |
| 924 | return s_vFillRTSHead(pDevice, byPktType, head, |
| 925 | cbFrameSize, |
Malcolm Priestley | 351c7dc | 2013-08-27 12:02:54 +0100 | [diff] [blame] | 926 | bNeedACK, psEthHeader, wCurrentRate, byFBOption); |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 927 | } else { |
| 928 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 929 | tx_head.tx_ab.ab; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 930 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 931 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 932 | PK_TYPE_11B, cbFrameSize, |
| 933 | wCurrentRate, bNeedACK); |
Malcolm Priestley | a90186e | 2013-10-01 15:58:54 +0100 | [diff] [blame] | 934 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 935 | return vnt_rxtx_datahead_ab(pDevice, byPktType, |
| 936 | wCurrentRate, &head->data_head_ab, |
| 937 | cbFrameSize, bNeedACK); |
| 938 | } |
Malcolm Priestley | c12dca0 | 2013-10-01 16:03:40 +0100 | [diff] [blame] | 939 | } |
| 940 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 941 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 942 | } |
| 943 | /* |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 944 | u8 * pbyBuffer,//point to pTxBufHead |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 945 | u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 946 | unsigned int cbFragmentSize,//Hdr+payoad+FCS |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 947 | */ |
| 948 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 949 | static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 950 | struct vnt_tx_buffer *tx_buffer, int bNeedEncryption, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 951 | u32 uSkbPacketLen, struct ethhdr *psEthHeader, |
Malcolm Priestley | d0a2b8f | 2013-08-15 19:37:04 +0100 | [diff] [blame] | 952 | u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate, |
| 953 | u32 *pcbHeaderLen, u32 *pcbTotalLen) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 954 | { |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 955 | struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 956 | u32 cbFrameSize, cbFrameBodySize; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 957 | u32 cb802_1_H_len; |
| 958 | u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0; |
| 959 | u32 cbFCSlen = 4, cbMICHDR = 0; |
Malcolm Priestley | f46142b | 2013-08-27 11:56:33 +0100 | [diff] [blame] | 960 | int bNeedACK; |
| 961 | bool bRTS = false; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 962 | u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr; |
| 963 | u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; |
| 964 | u8 abySNAP_Bridgetunnel[ETH_ALEN] |
| 965 | = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; |
| 966 | u32 uDuration; |
| 967 | u32 cbHeaderLength = 0, uPadding = 0; |
Malcolm Priestley | 5a5d6a8 | 2013-08-23 14:33:55 +0100 | [diff] [blame] | 968 | struct vnt_mic_hdr *pMICHDR; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 969 | u8 byFBOption = AUTO_FB_NONE, byFragType; |
| 970 | u16 wTxBufSize; |
Malcolm Priestley | 4235f72 | 2013-08-24 12:42:01 +0100 | [diff] [blame] | 971 | u32 dwMICKey0, dwMICKey1, dwMIC_Priority; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 972 | u32 *pdwMIC_L, *pdwMIC_R; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 973 | int bSoftWEP = false; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 974 | |
Malcolm Priestley | c545e6a | 2013-10-01 16:07:25 +0100 | [diff] [blame] | 975 | pMICHDR = NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 976 | |
Malcolm Priestley | e2efba7 | 2012-11-11 15:20:52 +0000 | [diff] [blame] | 977 | if (bNeedEncryption && pTransmitKey->pvKeyTable) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 978 | if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true) |
| 979 | bSoftWEP = true; /* WEP 256 */ |
Malcolm Priestley | e2efba7 | 2012-11-11 15:20:52 +0000 | [diff] [blame] | 980 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 981 | |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 982 | /* Get pkt type */ |
| 983 | if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) |
| 984 | cb802_1_H_len = 8; |
| 985 | else |
| 986 | cb802_1_H_len = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 987 | |
Charles Clément | 21ec51f | 2010-05-18 10:08:14 -0700 | [diff] [blame] | 988 | cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 989 | |
| 990 | //Set packet type |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 991 | pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 992 | |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 993 | if (pDevice->op_mode == NL80211_IFTYPE_ADHOC || |
| 994 | pDevice->op_mode == NL80211_IFTYPE_AP) { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 995 | if (is_multicast_ether_addr(psEthHeader->h_dest)) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 996 | bNeedACK = false; |
Andres More | 22040bb | 2010-08-02 20:21:44 -0300 | [diff] [blame] | 997 | pTxBufHead->wFIFOCtl = |
| 998 | pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); |
| 999 | } else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1000 | bNeedACK = true; |
Andres More | 22040bb | 2010-08-02 20:21:44 -0300 | [diff] [blame] | 1001 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
| 1002 | } |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1003 | } else { |
| 1004 | /* MSDUs in Infra mode always need ACK */ |
| 1005 | bNeedACK = true; |
| 1006 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
| 1007 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1008 | |
Malcolm Priestley | 5846251 | 2014-03-22 09:01:27 +0000 | [diff] [blame] | 1009 | pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1010 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1011 | //Set FRAGCTL_MACHDCNT |
Malcolm Priestley | 078d0cf | 2013-11-25 22:14:16 +0000 | [diff] [blame] | 1012 | cbMACHdLen = WLAN_HDR_ADDR3_LEN; |
| 1013 | |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1014 | pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1015 | |
| 1016 | //Set FIFOCTL_GrpAckPolicy |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1017 | if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1018 | pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; |
| 1019 | } |
| 1020 | |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 1021 | /* Set Auto Fallback Ctl */ |
| 1022 | if (wCurrentRate >= RATE_18M) { |
| 1023 | if (pDevice->byAutoFBCtrl == AUTO_FB_0) { |
| 1024 | pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0; |
| 1025 | |
| 1026 | pDevice->tx_rate_fb0 = |
| 1027 | wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M]; |
| 1028 | pDevice->tx_rate_fb1 = |
| 1029 | wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M]; |
| 1030 | |
| 1031 | byFBOption = AUTO_FB_0; |
| 1032 | } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) { |
| 1033 | pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1; |
| 1034 | pDevice->tx_rate_fb0 = |
| 1035 | wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M]; |
| 1036 | pDevice->tx_rate_fb1 = |
| 1037 | wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M]; |
| 1038 | |
| 1039 | byFBOption = AUTO_FB_1; |
| 1040 | } |
| 1041 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1042 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1043 | if (bSoftWEP != true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1044 | if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled |
| 1045 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104 |
| 1046 | pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; |
| 1047 | } |
| 1048 | if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { |
| 1049 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n"); |
| 1050 | pTxBufHead->wFragCtl |= FRAGCTL_TKIP; |
| 1051 | } |
| 1052 | else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP |
| 1053 | pTxBufHead->wFragCtl |= FRAGCTL_AES; |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1058 | if ((bNeedEncryption) && (pTransmitKey != NULL)) { |
| 1059 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { |
| 1060 | cbIVlen = 4; |
| 1061 | cbICVlen = 4; |
| 1062 | } |
| 1063 | else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { |
| 1064 | cbIVlen = 8;//IV+ExtIV |
| 1065 | cbMIClen = 8; |
| 1066 | cbICVlen = 4; |
| 1067 | } |
| 1068 | if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { |
| 1069 | cbIVlen = 8;//RSN Header |
| 1070 | cbICVlen = 8;//MIC |
Malcolm Priestley | 5a5d6a8 | 2013-08-23 14:33:55 +0100 | [diff] [blame] | 1071 | cbMICHDR = sizeof(struct vnt_mic_hdr); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1072 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1073 | if (bSoftWEP == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1074 | //MAC Header should be padding 0 to DW alignment. |
| 1075 | uPadding = 4 - (cbMACHdLen%4); |
| 1076 | uPadding %= 4; |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen; |
| 1081 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1082 | if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) { |
| 1083 | bRTS = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1084 | } else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1085 | bRTS = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1086 | pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY); |
| 1087 | } |
| 1088 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1089 | pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]); |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1090 | wTxBufSize = sizeof(struct vnt_tx_fifo_head); |
| 1091 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1092 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet |
| 1093 | if (byFBOption == AUTO_FB_NONE) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1094 | if (bRTS == true) {//RTS_need |
Malcolm Priestley | 6398a59 | 2013-08-16 21:26:55 +0100 | [diff] [blame] | 1095 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) + |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1096 | cbMICHDR + sizeof(struct vnt_rts_g); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1097 | } |
| 1098 | else { //RTS_needless |
Malcolm Priestley | 4f99005 | 2013-08-16 23:38:57 +0100 | [diff] [blame] | 1099 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1100 | cbMICHDR + sizeof(struct vnt_cts); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1101 | } |
| 1102 | } else { |
| 1103 | // Auto Fall Back |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1104 | if (bRTS == true) {//RTS_need |
Malcolm Priestley | 6398a59 | 2013-08-16 21:26:55 +0100 | [diff] [blame] | 1105 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) + |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 1106 | cbMICHDR + sizeof(struct vnt_rts_g_fb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1107 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1108 | else if (bRTS == false) { //RTS_needless |
Malcolm Priestley | 4f99005 | 2013-08-16 23:38:57 +0100 | [diff] [blame] | 1109 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 1110 | cbMICHDR + sizeof(struct vnt_cts_fb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1111 | } |
| 1112 | } // Auto Fall Back |
| 1113 | } |
| 1114 | else {//802.11a/b packet |
| 1115 | if (byFBOption == AUTO_FB_NONE) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1116 | if (bRTS == true) {//RTS_need |
Malcolm Priestley | 976467d | 2013-08-16 23:44:04 +0100 | [diff] [blame] | 1117 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 1118 | cbMICHDR + sizeof(struct vnt_rts_ab); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1119 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1120 | else if (bRTS == false) { //RTS_needless, no MICHDR |
Malcolm Priestley | 976467d | 2013-08-16 23:44:04 +0100 | [diff] [blame] | 1121 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
Malcolm Priestley | 558becf | 2013-08-16 23:50:32 +0100 | [diff] [blame] | 1122 | cbMICHDR + sizeof(struct vnt_tx_datahead_ab); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1123 | } |
| 1124 | } else { |
| 1125 | // Auto Fall Back |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1126 | if (bRTS == true) {//RTS_need |
Malcolm Priestley | 976467d | 2013-08-16 23:44:04 +0100 | [diff] [blame] | 1127 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 1128 | cbMICHDR + sizeof(struct vnt_rts_a_fb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1129 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1130 | else if (bRTS == false) { //RTS_needless |
Malcolm Priestley | 976467d | 2013-08-16 23:44:04 +0100 | [diff] [blame] | 1131 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
Malcolm Priestley | 1da4ee2 | 2013-08-16 23:51:38 +0100 | [diff] [blame] | 1132 | cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1133 | } |
| 1134 | } // Auto Fall Back |
| 1135 | } |
| 1136 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1137 | pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength); |
| 1138 | pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding); |
| 1139 | pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1140 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1141 | //========================= |
| 1142 | // No Fragmentation |
| 1143 | //========================= |
| 1144 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n"); |
| 1145 | byFragType = FRAGCTL_NONFRAG; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1146 | //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]); |
| 1147 | |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1148 | /* Fill FIFO, RrvTime, RTS and CTS */ |
| 1149 | uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, |
| 1150 | tx_buffer, &pMICHDR, cbMICHDR, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1151 | cbFrameSize, bNeedACK, psEthHeader, bRTS); |
Malcolm Priestley | c12dca0 | 2013-10-01 16:03:40 +0100 | [diff] [blame] | 1152 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1153 | // Generate TX MAC Header |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1154 | s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1155 | byFragType, 0); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1156 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1157 | if (bNeedEncryption == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1158 | //Fill TXKEY |
Malcolm Priestley | 3ba0938 | 2013-10-15 21:41:38 +0100 | [diff] [blame] | 1159 | s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey, |
Malcolm Priestley | ec37d8b | 2013-08-23 14:37:48 +0100 | [diff] [blame] | 1160 | pbyMacHdr, (u16)cbFrameBodySize, pMICHDR); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1161 | } |
| 1162 | |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1163 | /* 802.1H */ |
| 1164 | if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1165 | if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) || |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1166 | (psEthHeader->h_proto == cpu_to_le16(0xF380))) |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1167 | memcpy((u8 *) (pbyPayloadHead), |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1168 | abySNAP_Bridgetunnel, 6); |
| 1169 | else |
| 1170 | memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1171 | |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1172 | pbyType = (u8 *) (pbyPayloadHead + 6); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1173 | |
Malcolm Priestley | c47b0a3 | 2013-11-24 11:51:49 +0000 | [diff] [blame] | 1174 | memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16)); |
| 1175 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1176 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1177 | if (pPacket != NULL) { |
| 1178 | // Copy the Packet into a tx Buffer |
Jim Lieb | 3e36259 | 2009-08-12 14:54:11 -0700 | [diff] [blame] | 1179 | memcpy((pbyPayloadHead + cb802_1_H_len), |
Charles Clément | 21ec51f | 2010-05-18 10:08:14 -0700 | [diff] [blame] | 1180 | (pPacket + ETH_HLEN), |
| 1181 | uSkbPacketLen - ETH_HLEN |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1182 | ); |
| 1183 | |
| 1184 | } else { |
| 1185 | // while bRelayPacketSend psEthHeader is point to header+payload |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1186 | 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] | 1187 | } |
| 1188 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1189 | if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1190 | |
| 1191 | /////////////////////////////////////////////////////////////////// |
| 1192 | |
Malcolm Priestley | 14c5ef5 | 2013-01-17 23:19:37 +0000 | [diff] [blame] | 1193 | if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) { |
| 1194 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]); |
| 1195 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]); |
| 1196 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1197 | else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) { |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 1198 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]); |
| 1199 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1200 | } |
| 1201 | else { |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 1202 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]); |
| 1203 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1204 | } |
| 1205 | // DO Software Michael |
| 1206 | MIC_vInit(dwMICKey0, dwMICKey1); |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1207 | MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1208 | dwMIC_Priority = 0; |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1209 | MIC_vAppend((u8 *)&dwMIC_Priority, 4); |
Malcolm Priestley | b4dc03a | 2012-11-11 15:45:52 +0000 | [diff] [blame] | 1210 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n", |
| 1211 | dwMICKey0, dwMICKey1); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1212 | |
| 1213 | /////////////////////////////////////////////////////////////////// |
| 1214 | |
| 1215 | //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength)); |
| 1216 | //for (ii = 0; ii < cbFrameBodySize; ii++) { |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1217 | // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii)))); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1218 | //} |
| 1219 | //DBG_PRN_GRP12(("\n\n\n")); |
| 1220 | |
| 1221 | MIC_vAppend(pbyPayloadHead, cbFrameBodySize); |
| 1222 | |
Andres More | 52a7e64 | 2013-02-25 20:32:53 -0500 | [diff] [blame] | 1223 | pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize); |
| 1224 | pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1225 | |
| 1226 | MIC_vGetMIC(pdwMIC_L, pdwMIC_R); |
| 1227 | MIC_vUnInit(); |
| 1228 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1229 | if (pDevice->bTxMICFail == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1230 | *pdwMIC_L = 0; |
| 1231 | *pdwMIC_R = 0; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1232 | pDevice->bTxMICFail = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1233 | } |
| 1234 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize); |
| 1235 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen); |
| 1236 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R); |
| 1237 | } |
| 1238 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1239 | if (bSoftWEP == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1240 | |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1241 | s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1242 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1243 | } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) || |
| 1244 | ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) || |
| 1245 | ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1246 | cbFrameSize -= cbICVlen; |
| 1247 | } |
| 1248 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1249 | cbFrameSize -= cbFCSlen; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1250 | |
| 1251 | *pcbHeaderLen = cbHeaderLength; |
| 1252 | *pcbTotalLen = cbHeaderLength + cbFrameSize ; |
| 1253 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1254 | //Set FragCtl in TxBufferHead |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1255 | pTxBufHead->wFragCtl |= (u16)byFragType; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1256 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1257 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1258 | |
| 1259 | } |
| 1260 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1261 | /*+ |
| 1262 | * |
| 1263 | * Description: |
| 1264 | * Translate 802.3 to 802.11 header |
| 1265 | * |
| 1266 | * Parameters: |
| 1267 | * In: |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 1268 | * pDevice - Pointer to adapter |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1269 | * dwTxBufferAddr - Transmit Buffer |
| 1270 | * pPacket - Packet from upper layer |
| 1271 | * cbPacketSize - Transmit Data Length |
| 1272 | * Out: |
| 1273 | * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header |
| 1274 | * pcbAppendPayload - size of append payload for 802.1H translation |
| 1275 | * |
| 1276 | * Return Value: none |
| 1277 | * |
| 1278 | -*/ |
| 1279 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1280 | static void s_vGenerateMACHeader(struct vnt_private *pDevice, |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1281 | u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1282 | int bNeedEncrypt, u16 wFragType, u32 uFragIdx) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1283 | { |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1284 | struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1285 | |
Malcolm Priestley | c921cc8 | 2013-08-20 20:47:49 +0100 | [diff] [blame] | 1286 | pMACHeader->frame_control = TYPE_802_11_DATA; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1287 | |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1288 | if (pDevice->op_mode == NL80211_IFTYPE_AP) { |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1289 | memcpy(&(pMACHeader->addr1[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1290 | &(psEthHeader->h_dest[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1291 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1292 | memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN); |
| 1293 | memcpy(&(pMACHeader->addr3[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1294 | &(psEthHeader->h_source[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1295 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1296 | pMACHeader->frame_control |= FC_FROMDS; |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1297 | } else { |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1298 | if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) { |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1299 | memcpy(&(pMACHeader->addr1[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1300 | &(psEthHeader->h_dest[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1301 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1302 | memcpy(&(pMACHeader->addr2[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1303 | &(psEthHeader->h_source[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1304 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1305 | memcpy(&(pMACHeader->addr3[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1306 | &(pDevice->abyBSSID[0]), |
| 1307 | ETH_ALEN); |
| 1308 | } else { |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1309 | memcpy(&(pMACHeader->addr3[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1310 | &(psEthHeader->h_dest[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1311 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1312 | memcpy(&(pMACHeader->addr2[0]), |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1313 | &(psEthHeader->h_source[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1314 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1315 | memcpy(&(pMACHeader->addr1[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1316 | &(pDevice->abyBSSID[0]), |
| 1317 | ETH_ALEN); |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1318 | pMACHeader->frame_control |= FC_TODS; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | if (bNeedEncrypt) |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1323 | pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1324 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1325 | pMACHeader->duration_id = cpu_to_le16(wDuration); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1326 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1327 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1328 | |
| 1329 | //Set FragNumber in Sequence Control |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1330 | pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1331 | |
| 1332 | if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) { |
| 1333 | pDevice->wSeqCounter++; |
| 1334 | if (pDevice->wSeqCounter > 0x0fff) |
| 1335 | pDevice->wSeqCounter = 0; |
| 1336 | } |
| 1337 | |
| 1338 | if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1339 | pMACHeader->frame_control |= FC_MOREFRAG; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1343 | /*+ |
| 1344 | * |
| 1345 | * Description: |
| 1346 | * Request instructs a MAC to transmit a 802.11 management packet through |
| 1347 | * the adapter onto the medium. |
| 1348 | * |
| 1349 | * Parameters: |
| 1350 | * In: |
| 1351 | * hDeviceContext - Pointer to the adapter |
| 1352 | * pPacket - A pointer to a descriptor for the packet to transmit |
| 1353 | * Out: |
| 1354 | * none |
| 1355 | * |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1356 | * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1357 | * |
| 1358 | -*/ |
| 1359 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1360 | CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, |
| 1361 | struct vnt_tx_mgmt *pPacket) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1362 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1363 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
Malcolm Priestley | f39c0d8 | 2013-08-15 19:34:37 +0100 | [diff] [blame] | 1364 | struct vnt_tx_buffer *pTX_Buffer; |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 1365 | struct vnt_usb_send_context *pContext; |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1366 | struct vnt_tx_fifo_head *pTxBufHead; |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1367 | struct ieee80211_hdr *pMACHeader; |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1368 | struct ethhdr sEthHeader; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1369 | u8 byPktType, *pbyTxBufferAddr; |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 1370 | struct vnt_mic_hdr *pMICHDR = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1371 | u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1372 | int bNeedACK, bIsPSPOLL = false; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1373 | u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4; |
| 1374 | u32 uPadding = 0; |
| 1375 | u16 wTxBufSize; |
| 1376 | u32 cbMacHdLen; |
| 1377 | u16 wCurrentRate = RATE_1M; |
Malcolm Priestley | 931cb9f | 2014-05-15 22:49:15 +0100 | [diff] [blame] | 1378 | unsigned long flags; |
| 1379 | |
| 1380 | if (pDevice->byBBType == BB_TYPE_11A) { |
| 1381 | wCurrentRate = RATE_6M; |
| 1382 | byPktType = PK_TYPE_11A; |
| 1383 | } else { |
| 1384 | wCurrentRate = RATE_1M; |
| 1385 | byPktType = PK_TYPE_11B; |
| 1386 | } |
| 1387 | |
| 1388 | if (pMgmt->eScanState != WMAC_NO_SCANNING) |
| 1389 | RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh); |
| 1390 | else |
| 1391 | RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel); |
| 1392 | |
| 1393 | pDevice->wCurrentRate = wCurrentRate; |
| 1394 | |
| 1395 | spin_lock_irqsave(&pDevice->lock, flags); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1396 | |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 1397 | pContext = s_vGetFreeContext(pDevice); |
Malcolm Priestley | 931cb9f | 2014-05-15 22:49:15 +0100 | [diff] [blame] | 1398 | if (!pContext) { |
| 1399 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO |
| 1400 | "ManagementSend TX...NO CONTEXT!\n"); |
| 1401 | spin_unlock_irqrestore(&pDevice->lock, flags); |
| 1402 | return CMD_STATUS_RESOURCES; |
| 1403 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1404 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 1405 | pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1406 | cbFrameBodySize = pPacket->cbPayloadLen; |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1407 | pTxBufHead = &pTX_Buffer->fifo_head; |
| 1408 | pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0]; |
| 1409 | wTxBufSize = sizeof(struct vnt_tx_fifo_head); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1410 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1411 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1412 | //Set packet type |
| 1413 | if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000 |
| 1414 | pTxBufHead->wFIFOCtl = 0; |
| 1415 | } |
| 1416 | else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000 |
| 1417 | pTxBufHead->wFIFOCtl |= FIFOCTL_11B; |
| 1418 | } |
| 1419 | else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000 |
| 1420 | pTxBufHead->wFIFOCtl |= FIFOCTL_11GB; |
| 1421 | } |
| 1422 | else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000 |
| 1423 | pTxBufHead->wFIFOCtl |= FIFOCTL_11GA; |
| 1424 | } |
| 1425 | |
| 1426 | pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN; |
Malcolm Priestley | 5846251 | 2014-03-22 09:01:27 +0000 | [diff] [blame] | 1427 | pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1428 | |
Andres More | 22040bb | 2010-08-02 20:21:44 -0300 | [diff] [blame] | 1429 | if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1430 | bNeedACK = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1431 | } |
| 1432 | else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1433 | bNeedACK = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1434 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
| 1435 | }; |
| 1436 | |
| 1437 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || |
| 1438 | (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) { |
| 1439 | |
| 1440 | pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY; |
| 1441 | //Set Preamble type always long |
| 1442 | //pDevice->byPreambleType = PREAMBLE_LONG; |
| 1443 | // probe-response don't retry |
| 1444 | //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1445 | // bNeedACK = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1446 | // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK); |
| 1447 | //} |
| 1448 | } |
| 1449 | |
| 1450 | pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); |
| 1451 | |
| 1452 | if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1453 | bIsPSPOLL = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1454 | cbMacHdLen = WLAN_HDR_ADDR2_LEN; |
| 1455 | } else { |
| 1456 | cbMacHdLen = WLAN_HDR_ADDR3_LEN; |
| 1457 | } |
| 1458 | |
| 1459 | //Set FRAGCTL_MACHDCNT |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1460 | pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1461 | |
| 1462 | // Notes: |
| 1463 | // Although spec says MMPDU can be fragmented; In most case, |
| 1464 | // no one will send a MMPDU under fragmentation. With RTS may occur. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1465 | |
| 1466 | if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { |
| 1467 | if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) { |
| 1468 | cbIVlen = 4; |
| 1469 | cbICVlen = 4; |
| 1470 | pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; |
| 1471 | } |
| 1472 | else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { |
| 1473 | cbIVlen = 8;//IV+ExtIV |
| 1474 | cbMIClen = 8; |
| 1475 | cbICVlen = 4; |
| 1476 | pTxBufHead->wFragCtl |= FRAGCTL_TKIP; |
| 1477 | //We need to get seed here for filling TxKey entry. |
| 1478 | //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr, |
| 1479 | // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG); |
| 1480 | } |
| 1481 | else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { |
| 1482 | cbIVlen = 8;//RSN Header |
| 1483 | cbICVlen = 8;//MIC |
| 1484 | pTxBufHead->wFragCtl |= FRAGCTL_AES; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1485 | } |
| 1486 | //MAC Header should be padding 0 to DW alignment. |
| 1487 | uPadding = 4 - (cbMacHdLen%4); |
| 1488 | uPadding %= 4; |
| 1489 | } |
| 1490 | |
| 1491 | cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen; |
| 1492 | |
| 1493 | //Set FIFOCTL_GrpAckPolicy |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1494 | if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1495 | pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; |
| 1496 | } |
| 1497 | //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() |
| 1498 | |
| 1499 | //Set RrvTime/RTS/CTS Buffer |
| 1500 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet |
Malcolm Priestley | 4f99005 | 2013-08-16 23:38:57 +0100 | [diff] [blame] | 1501 | cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1502 | sizeof(struct vnt_cts); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1503 | } |
| 1504 | else { // 802.11a/b packet |
Malcolm Priestley | 976467d | 2013-08-16 23:44:04 +0100 | [diff] [blame] | 1505 | cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
Malcolm Priestley | 558becf | 2013-08-16 23:50:32 +0100 | [diff] [blame] | 1506 | sizeof(struct vnt_tx_datahead_ab); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1507 | } |
| 1508 | |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1509 | memcpy(&(sEthHeader.h_dest[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1510 | &(pPacket->p80211Header->sA3.abyAddr1[0]), |
| 1511 | ETH_ALEN); |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1512 | memcpy(&(sEthHeader.h_source[0]), |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 1513 | &(pPacket->p80211Header->sA3.abyAddr2[0]), |
| 1514 | ETH_ALEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1515 | //========================= |
| 1516 | // No Fragmentation |
| 1517 | //========================= |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1518 | pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1519 | |
Malcolm Priestley | 351c7dc | 2013-08-27 12:02:54 +0100 | [diff] [blame] | 1520 | /* Fill FIFO,RrvTime,RTS,and CTS */ |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1521 | uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, |
Malcolm Priestley | fa57560 | 2013-09-26 19:00:41 +0100 | [diff] [blame] | 1522 | pTX_Buffer, &pMICHDR, 0, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1523 | cbFrameSize, bNeedACK, &sEthHeader, false); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1524 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1525 | pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1526 | |
| 1527 | cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize; |
| 1528 | |
| 1529 | if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1530 | u8 * pbyIVHead; |
| 1531 | u8 * pbyPayloadHead; |
| 1532 | u8 * pbyBSSID; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1533 | PSKeyItem pTransmitKey = NULL; |
| 1534 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1535 | pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding); |
| 1536 | pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1537 | do { |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1538 | if (pDevice->op_mode == NL80211_IFTYPE_STATION && |
| 1539 | pDevice->bLinkPass == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1540 | pbyBSSID = pDevice->abyBSSID; |
| 1541 | // get pairwise key |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1542 | if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1543 | // get group key |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1544 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1545 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); |
| 1546 | break; |
| 1547 | } |
| 1548 | } else { |
| 1549 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n"); |
| 1550 | break; |
| 1551 | } |
| 1552 | } |
| 1553 | // get group key |
| 1554 | pbyBSSID = pDevice->abyBroadcastAddr; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1555 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1556 | pTransmitKey = NULL; |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1557 | 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] | 1558 | } else { |
| 1559 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); |
| 1560 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1561 | } while(false); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1562 | //Fill TXKEY |
Malcolm Priestley | 3ba0938 | 2013-10-15 21:41:38 +0100 | [diff] [blame] | 1563 | s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey, |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1564 | (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1565 | |
Jim Lieb | 3e36259 | 2009-08-12 14:54:11 -0700 | [diff] [blame] | 1566 | memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen); |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1567 | memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen), |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1568 | cbFrameBodySize); |
| 1569 | } |
| 1570 | else { |
| 1571 | // Copy the Packet into a tx Buffer |
Jim Lieb | 3e36259 | 2009-08-12 14:54:11 -0700 | [diff] [blame] | 1572 | memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1573 | } |
| 1574 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1575 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1576 | pDevice->wSeqCounter++ ; |
| 1577 | if (pDevice->wSeqCounter > 0x0fff) |
| 1578 | pDevice->wSeqCounter = 0; |
| 1579 | |
| 1580 | if (bIsPSPOLL) { |
| 1581 | // 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] | 1582 | // of FIFO control header. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1583 | // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is |
| 1584 | // in the same place of other packet's Duration-field). |
| 1585 | // And it will cause Cisco-AP to issue Disassociation-packet |
Malcolm Priestley | 7e60a3de | 2013-08-16 23:48:03 +0100 | [diff] [blame] | 1586 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) { |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 1587 | struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head. |
| 1588 | tx_cts.tx.head.cts_g.data_head; |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 1589 | data_head->duration_a = |
Malcolm Priestley | 7e60a3de | 2013-08-16 23:48:03 +0100 | [diff] [blame] | 1590 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 1591 | data_head->duration_b = |
Malcolm Priestley | 7e60a3de | 2013-08-16 23:48:03 +0100 | [diff] [blame] | 1592 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
| 1593 | } else { |
Malcolm Priestley | c12dca0 | 2013-10-01 16:03:40 +0100 | [diff] [blame] | 1594 | struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head. |
| 1595 | tx_ab.tx.head.data_head_ab; |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 1596 | data_head->duration = |
Malcolm Priestley | 558becf | 2013-08-16 23:50:32 +0100 | [diff] [blame] | 1597 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
| 1598 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1599 | } |
| 1600 | |
Malcolm Priestley | ca34759 | 2014-03-22 09:01:28 +0000 | [diff] [blame] | 1601 | pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount)); |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1602 | pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1603 | pTX_Buffer->byType = 0x00; |
| 1604 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 1605 | pContext->skb = NULL; |
| 1606 | pContext->type = CONTEXT_MGMT_PACKET; |
| 1607 | pContext->buf_len = (u16)cbReqCount + 4; /* USB header */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1608 | |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1609 | if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) { |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1610 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
| 1611 | &pMACHeader->addr1[0], (u16)cbFrameSize, |
| 1612 | pTxBufHead->wFIFOCtl); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1613 | } |
| 1614 | else { |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 1615 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
| 1616 | &pMACHeader->addr3[0], (u16)cbFrameSize, |
| 1617 | pTxBufHead->wFIFOCtl); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | PIPEnsSendBulkOut(pDevice,pContext); |
Malcolm Priestley | 931cb9f | 2014-05-15 22:49:15 +0100 | [diff] [blame] | 1621 | |
| 1622 | spin_unlock_irqrestore(&pDevice->lock, flags); |
| 1623 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1624 | return CMD_STATUS_PENDING; |
| 1625 | } |
| 1626 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1627 | CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice, |
| 1628 | struct vnt_tx_mgmt *pPacket) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1629 | { |
Malcolm Priestley | 01f865b | 2013-08-15 19:40:08 +0100 | [diff] [blame] | 1630 | struct vnt_beacon_buffer *pTX_Buffer; |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1631 | struct vnt_tx_short_buf_head *short_head; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1632 | u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN; |
| 1633 | u32 cbHeaderSize = 0; |
Andres More | 1cac4a4 | 2013-03-18 20:33:50 -0500 | [diff] [blame] | 1634 | struct ieee80211_hdr *pMACHeader; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1635 | u16 wCurrentRate; |
| 1636 | u32 cbFrameBodySize; |
| 1637 | u32 cbReqCount; |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 1638 | struct vnt_usb_send_context *pContext; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1639 | CMD_STATUS status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1640 | |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 1641 | pContext = s_vGetFreeContext(pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1642 | if (NULL == pContext) { |
| 1643 | status = CMD_STATUS_RESOURCES; |
| 1644 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n"); |
| 1645 | return status ; |
| 1646 | } |
Malcolm Priestley | 01f865b | 2013-08-15 19:40:08 +0100 | [diff] [blame] | 1647 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 1648 | pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->data[0]; |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1649 | short_head = &pTX_Buffer->short_head; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1650 | |
| 1651 | cbFrameBodySize = pPacket->cbPayloadLen; |
| 1652 | |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1653 | cbHeaderSize = sizeof(struct vnt_tx_short_buf_head); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1654 | |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1655 | if (pDevice->byBBType == BB_TYPE_11A) { |
| 1656 | wCurrentRate = RATE_6M; |
| 1657 | |
| 1658 | /* Get SignalField,ServiceField,Length */ |
| 1659 | BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, |
| 1660 | PK_TYPE_11A, &short_head->ab); |
| 1661 | |
| 1662 | /* Get Duration and TimeStampOff */ |
| 1663 | short_head->duration = s_uGetDataDuration(pDevice, |
| 1664 | PK_TYPE_11A, false); |
| 1665 | short_head->time_stamp_off = |
| 1666 | vnt_time_stamp_off(pDevice, wCurrentRate); |
| 1667 | } else { |
| 1668 | wCurrentRate = RATE_1M; |
| 1669 | short_head->fifo_ctl |= FIFOCTL_11B; |
| 1670 | |
| 1671 | /* Get SignalField,ServiceField,Length */ |
| 1672 | BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, |
| 1673 | PK_TYPE_11B, &short_head->ab); |
| 1674 | |
| 1675 | /* Get Duration and TimeStampOff */ |
| 1676 | short_head->duration = s_uGetDataDuration(pDevice, |
Malcolm Priestley | 6b5ad9d | 2013-08-21 22:16:04 +0100 | [diff] [blame] | 1677 | PK_TYPE_11B, false); |
Malcolm Priestley | c7c57b2 | 2013-11-24 13:25:25 +0000 | [diff] [blame] | 1678 | short_head->time_stamp_off = |
| 1679 | vnt_time_stamp_off(pDevice, wCurrentRate); |
| 1680 | } |
| 1681 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1682 | |
Malcolm Priestley | 0b71fe3 | 2013-11-24 13:27:32 +0000 | [diff] [blame] | 1683 | /* Generate Beacon Header */ |
| 1684 | pMACHeader = &pTX_Buffer->hdr; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1685 | |
Malcolm Priestley | 0b71fe3 | 2013-11-24 13:27:32 +0000 | [diff] [blame] | 1686 | memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen); |
| 1687 | |
| 1688 | pMACHeader->duration_id = 0; |
| 1689 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); |
| 1690 | pDevice->wSeqCounter++; |
| 1691 | if (pDevice->wSeqCounter > 0x0fff) |
| 1692 | pDevice->wSeqCounter = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1693 | |
| 1694 | cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize; |
| 1695 | |
Malcolm Priestley | fad8e4a | 2014-03-22 09:01:29 +0000 | [diff] [blame] | 1696 | pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount); |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1697 | pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1698 | pTX_Buffer->byType = 0x01; |
| 1699 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 1700 | pContext->skb = NULL; |
| 1701 | pContext->type = CONTEXT_MGMT_PACKET; |
| 1702 | pContext->buf_len = (u16)cbReqCount + 4; /* USB header */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1703 | |
| 1704 | PIPEnsSendBulkOut(pDevice,pContext); |
| 1705 | return CMD_STATUS_PENDING; |
| 1706 | |
| 1707 | } |
| 1708 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1709 | //TYPE_AC0DMA data tx |
| 1710 | /* |
| 1711 | * Description: |
| 1712 | * Tx packet via AC0DMA(DMA1) |
| 1713 | * |
| 1714 | * Parameters: |
| 1715 | * In: |
| 1716 | * pDevice - Pointer to the adapter |
| 1717 | * skb - Pointer to tx skb packet |
| 1718 | * Out: |
| 1719 | * void |
| 1720 | * |
| 1721 | * Return Value: NULL |
| 1722 | */ |
| 1723 | |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 1724 | int nsDMA_tx_packet(struct vnt_private *pDevice, struct sk_buff *skb) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1725 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1726 | struct net_device_stats *pStats = &pDevice->stats; |
| 1727 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
Malcolm Priestley | f39c0d8 | 2013-08-15 19:34:37 +0100 | [diff] [blame] | 1728 | struct vnt_tx_buffer *pTX_Buffer; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1729 | u32 BytesToWrite = 0, uHeaderLen = 0; |
| 1730 | u32 uNodeIndex = 0; |
| 1731 | u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; |
| 1732 | u16 wAID; |
| 1733 | u8 byPktType; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1734 | int bNeedEncryption = false; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1735 | PSKeyItem pTransmitKey = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1736 | int ii; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1737 | int bTKIP_UseGTK = false; |
| 1738 | int bNeedDeAuth = false; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1739 | u8 *pbyBSSID; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1740 | int bNodeExist = false; |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 1741 | struct vnt_usb_send_context *pContext; |
Andres More | dfdcc42 | 2013-02-12 20:36:28 -0500 | [diff] [blame] | 1742 | bool fConvertedPacket; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 1743 | u32 status; |
| 1744 | u16 wKeepRate = pDevice->wCurrentRate; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1745 | int bTxeapol_key = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1746 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1747 | if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { |
| 1748 | |
| 1749 | if (pDevice->uAssocCount == 0) { |
| 1750 | dev_kfree_skb_irq(skb); |
| 1751 | return 0; |
| 1752 | } |
| 1753 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1754 | if (is_multicast_ether_addr((u8 *)(skb->data))) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1755 | uNodeIndex = 0; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1756 | bNodeExist = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1757 | if (pMgmt->sNodeDBTable[0].bPSEnable) { |
| 1758 | |
| 1759 | skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb); |
| 1760 | pMgmt->sNodeDBTable[0].wEnQueueCnt++; |
| 1761 | // set tx map |
| 1762 | pMgmt->abyPSTxMap[0] |= byMask[0]; |
| 1763 | return 0; |
| 1764 | } |
Masanari Iida | 9318469 | 2012-08-13 21:21:50 +0900 | [diff] [blame] | 1765 | // multicast/broadcast data rate |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1766 | |
| 1767 | if (pDevice->byBBType != BB_TYPE_11A) |
| 1768 | pDevice->wCurrentRate = RATE_2M; |
| 1769 | else |
| 1770 | pDevice->wCurrentRate = RATE_24M; |
| 1771 | // long preamble type |
| 1772 | pDevice->byPreambleType = PREAMBLE_SHORT; |
| 1773 | |
| 1774 | }else { |
| 1775 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1776 | if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1777 | |
| 1778 | if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) { |
| 1779 | |
| 1780 | skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb); |
| 1781 | |
| 1782 | pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++; |
| 1783 | // set tx map |
| 1784 | wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID; |
| 1785 | pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7]; |
| 1786 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n", |
| 1787 | (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]); |
| 1788 | |
| 1789 | return 0; |
| 1790 | } |
| 1791 | // AP rate decided from node |
| 1792 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate; |
| 1793 | // tx preamble decided from node |
| 1794 | |
| 1795 | if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) { |
| 1796 | pDevice->byPreambleType = pDevice->byShortPreamble; |
| 1797 | |
| 1798 | }else { |
| 1799 | pDevice->byPreambleType = PREAMBLE_LONG; |
| 1800 | } |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1801 | bNodeExist = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1802 | } |
| 1803 | } |
| 1804 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1805 | if (bNodeExist == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1806 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n"); |
| 1807 | dev_kfree_skb_irq(skb); |
| 1808 | return 0; |
| 1809 | } |
| 1810 | } |
| 1811 | |
Tobias Klauser | 838c2d6 | 2014-04-25 11:53:58 +0200 | [diff] [blame] | 1812 | memcpy(&pDevice->sTxEthHeader, skb->data, ETH_HLEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1813 | |
| 1814 | //mike add:station mode check eapol-key challenge---> |
| 1815 | { |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1816 | u8 Protocol_Version; //802.1x Authentication |
| 1817 | u8 Packet_Type; //802.1x Authentication |
| 1818 | u8 Descriptor_type; |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1819 | u16 Key_info; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1820 | |
Charles Clément | 21ec51f | 2010-05-18 10:08:14 -0700 | [diff] [blame] | 1821 | Protocol_Version = skb->data[ETH_HLEN]; |
| 1822 | Packet_Type = skb->data[ETH_HLEN+1]; |
| 1823 | Descriptor_type = skb->data[ETH_HLEN+1+1+2]; |
| 1824 | 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] | 1825 | if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) { |
Malcolm Priestley | aa209ee | 2012-08-29 23:08:21 +0100 | [diff] [blame] | 1826 | /* 802.1x OR eapol-key challenge frame transfer */ |
| 1827 | if (((Protocol_Version == 1) || (Protocol_Version == 2)) && |
| 1828 | (Packet_Type == 3)) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1829 | bTxeapol_key = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1830 | if(!(Key_info & BIT3) && //WPA or RSN group-key challenge |
| 1831 | (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key |
| 1832 | if(Descriptor_type==254) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1833 | pDevice->fWPA_Authened = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1834 | PRINT_K("WPA "); |
| 1835 | } |
| 1836 | else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1837 | pDevice->fWPA_Authened = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1838 | PRINT_K("WPA2(re-keying) "); |
| 1839 | } |
| 1840 | PRINT_K("Authentication completed!!\n"); |
| 1841 | } |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 1842 | else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1843 | (Key_info & BIT8) && (Key_info & BIT9)) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1844 | pDevice->fWPA_Authened = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1845 | PRINT_K("WPA2 Authentication completed!!\n"); |
| 1846 | } |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | //mike add:station mode check eapol-key challenge<--- |
| 1851 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1852 | if (pDevice->bEncryptionEnable == true) { |
| 1853 | bNeedEncryption = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1854 | // get Transmit key |
| 1855 | do { |
| 1856 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && |
| 1857 | (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { |
| 1858 | pbyBSSID = pDevice->abyBSSID; |
| 1859 | // get pairwise key |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1860 | if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1861 | // get group key |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1862 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { |
| 1863 | bTKIP_UseGTK = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1864 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); |
| 1865 | break; |
| 1866 | } |
| 1867 | } else { |
| 1868 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n"); |
| 1869 | break; |
| 1870 | } |
| 1871 | }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1872 | /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */ |
| 1873 | pbyBSSID = pDevice->sTxEthHeader.h_dest; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1874 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n"); |
| 1875 | for (ii = 0; ii< 6; ii++) |
| 1876 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii)); |
| 1877 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n"); |
| 1878 | |
| 1879 | // get pairwise key |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1880 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1881 | break; |
| 1882 | } |
| 1883 | // get group key |
| 1884 | pbyBSSID = pDevice->abyBroadcastAddr; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1885 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1886 | pTransmitKey = NULL; |
| 1887 | if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { |
| 1888 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); |
| 1889 | } |
| 1890 | else |
| 1891 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); |
| 1892 | } else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1893 | bTKIP_UseGTK = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1894 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); |
| 1895 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1896 | } while(false); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1897 | } |
| 1898 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1899 | byPktType = (u8)pDevice->byPacketType; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1900 | |
| 1901 | if (pDevice->bFixRate) { |
| 1902 | if (pDevice->byBBType == BB_TYPE_11B) { |
| 1903 | if (pDevice->uConnectionRate >= RATE_11M) { |
| 1904 | pDevice->wCurrentRate = RATE_11M; |
| 1905 | } else { |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1906 | pDevice->wCurrentRate = (u16)pDevice->uConnectionRate; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1907 | } |
| 1908 | } else { |
| 1909 | if ((pDevice->byBBType == BB_TYPE_11A) && |
| 1910 | (pDevice->uConnectionRate <= RATE_6M)) { |
| 1911 | pDevice->wCurrentRate = RATE_6M; |
| 1912 | } else { |
| 1913 | if (pDevice->uConnectionRate >= RATE_54M) |
| 1914 | pDevice->wCurrentRate = RATE_54M; |
| 1915 | else |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 1916 | pDevice->wCurrentRate = (u16)pDevice->uConnectionRate; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | else { |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1921 | if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1922 | // Adhoc Tx rate decided from node DB |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1923 | if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1924 | // Multicast use highest data rate |
| 1925 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate; |
| 1926 | // preamble type |
| 1927 | pDevice->byPreambleType = pDevice->byShortPreamble; |
| 1928 | } |
| 1929 | else { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1930 | if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1931 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate; |
| 1932 | if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) { |
| 1933 | pDevice->byPreambleType = pDevice->byShortPreamble; |
| 1934 | |
| 1935 | } |
| 1936 | else { |
| 1937 | pDevice->byPreambleType = PREAMBLE_LONG; |
| 1938 | } |
| 1939 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate); |
| 1940 | } |
| 1941 | else { |
| 1942 | if (pDevice->byBBType != BB_TYPE_11A) |
| 1943 | pDevice->wCurrentRate = RATE_2M; |
| 1944 | else |
| 1945 | pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s |
| 1946 | // abyCurrExtSuppRates[] |
| 1947 | pDevice->byPreambleType = PREAMBLE_SHORT; |
| 1948 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n"); |
| 1949 | } |
| 1950 | } |
| 1951 | } |
Malcolm Priestley | a0ad277 | 2014-02-15 21:56:20 +0000 | [diff] [blame] | 1952 | if (pDevice->op_mode == NL80211_IFTYPE_STATION) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1953 | // Infra STA rate decided from AP Node, index = 0 |
| 1954 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate; |
| 1955 | } |
| 1956 | } |
| 1957 | |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1958 | if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) { |
Malcolm Priestley | aa209ee | 2012-08-29 23:08:21 +0100 | [diff] [blame] | 1959 | if (pDevice->byBBType != BB_TYPE_11A) { |
| 1960 | pDevice->wCurrentRate = RATE_1M; |
Malcolm Priestley | aa209ee | 2012-08-29 23:08:21 +0100 | [diff] [blame] | 1961 | pDevice->byTopCCKBasicRate = RATE_1M; |
| 1962 | pDevice->byTopOFDMBasicRate = RATE_6M; |
| 1963 | } else { |
| 1964 | pDevice->wCurrentRate = RATE_6M; |
Malcolm Priestley | aa209ee | 2012-08-29 23:08:21 +0100 | [diff] [blame] | 1965 | pDevice->byTopCCKBasicRate = RATE_1M; |
| 1966 | pDevice->byTopOFDMBasicRate = RATE_6M; |
| 1967 | } |
| 1968 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1969 | |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 1970 | DBG_PRT(MSG_LEVEL_DEBUG, |
| 1971 | KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n", |
| 1972 | pDevice->wCurrentRate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1973 | |
| 1974 | if (wKeepRate != pDevice->wCurrentRate) { |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 1975 | bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | if (pDevice->wCurrentRate <= RATE_11M) { |
| 1979 | byPktType = PK_TYPE_11B; |
| 1980 | } |
| 1981 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1982 | if (bNeedEncryption == true) { |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1983 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto)); |
| 1984 | if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1985 | bNeedEncryption = false; |
Andres More | ceb8c5d | 2013-03-18 20:33:49 -0500 | [diff] [blame] | 1986 | 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] | 1987 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { |
| 1988 | if (pTransmitKey == NULL) { |
| 1989 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n"); |
| 1990 | } |
| 1991 | else { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1992 | if (bTKIP_UseGTK == true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1993 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n"); |
| 1994 | } |
| 1995 | else { |
Malcolm Priestley | b4dc03a | 2012-11-11 15:45:52 +0000 | [diff] [blame] | 1996 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n", |
| 1997 | pTransmitKey->dwKeyIndex); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1998 | bNeedEncryption = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1999 | } |
| 2000 | } |
| 2001 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2002 | } |
| 2003 | else { |
| 2004 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2005 | if (pTransmitKey == NULL) { |
| 2006 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n"); |
| 2007 | dev_kfree_skb_irq(skb); |
| 2008 | pStats->tx_dropped++; |
| 2009 | return STATUS_FAILURE; |
| 2010 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | |
Malcolm Priestley | b674ee1 | 2014-05-15 22:49:10 +0100 | [diff] [blame] | 2014 | pContext = s_vGetFreeContext(pDevice); |
| 2015 | if (!pContext) { |
| 2016 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n"); |
| 2017 | dev_kfree_skb_irq(skb); |
| 2018 | return STATUS_RESOURCES; |
| 2019 | } |
| 2020 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2021 | pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0]; |
Malcolm Priestley | d0a2b8f | 2013-08-15 19:37:04 +0100 | [diff] [blame] | 2022 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2023 | fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType, |
Malcolm Priestley | d0a2b8f | 2013-08-15 19:37:04 +0100 | [diff] [blame] | 2024 | pTX_Buffer, bNeedEncryption, |
Malcolm Priestley | 05cc617 | 2014-04-30 21:31:12 +0100 | [diff] [blame] | 2025 | skb->len, &pDevice->sTxEthHeader, |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 2026 | (u8 *)skb->data, pTransmitKey, uNodeIndex, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2027 | pDevice->wCurrentRate, |
| 2028 | &uHeaderLen, &BytesToWrite |
| 2029 | ); |
| 2030 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2031 | if (fConvertedPacket == false) { |
| 2032 | pContext->in_use = false; |
| 2033 | dev_kfree_skb_irq(skb); |
| 2034 | return STATUS_FAILURE; |
| 2035 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2036 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 2037 | if ( pDevice->bEnablePSMode == true ) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2038 | if ( !pDevice->bPSModeTxBurst ) { |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 2039 | bScheduleCommand((void *) pDevice, |
| 2040 | WLAN_CMD_MAC_DISPOWERSAVING, |
| 2041 | NULL); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 2042 | pDevice->bPSModeTxBurst = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 2046 | pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
Malcolm Priestley | ca34759 | 2014-03-22 09:01:28 +0000 | [diff] [blame] | 2047 | pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2048 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2049 | pContext->skb = skb; |
| 2050 | pContext->type = CONTEXT_DATA_PACKET; |
| 2051 | pContext->buf_len = (u16)BytesToWrite + 4 ; /* USB header */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2052 | |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 2053 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
Malcolm Priestley | 81aec60 | 2014-02-27 23:06:11 +0000 | [diff] [blame] | 2054 | &pDevice->sTxEthHeader.h_dest[0], |
Malcolm Priestley | d66caad | 2013-09-17 19:54:35 +0100 | [diff] [blame] | 2055 | (u16)(BytesToWrite-uHeaderLen), |
| 2056 | pTX_Buffer->fifo_head.wFIFOCtl); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2057 | |
| 2058 | status = PIPEnsSendBulkOut(pDevice,pContext); |
| 2059 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 2060 | if (bNeedDeAuth == true) { |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 2061 | u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2062 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 2063 | bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2064 | } |
| 2065 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2066 | if (status != STATUS_PENDING) { |
| 2067 | pContext->in_use = false; |
| 2068 | dev_kfree_skb_irq(skb); |
| 2069 | return STATUS_FAILURE; |
| 2070 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2071 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 2072 | |
| 2073 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 2074 | } |