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