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