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 | * csBeacon_xmit - beacon tx function |
| 30 | * csMgmt_xmit - management tx function |
| 31 | * s_uGetDataDuration - get tx data required duration |
| 32 | * s_uFillDataHead- fulfill tx data duration header |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 33 | * s_uGetRTSCTSDuration- get rtx/cts required duration |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 34 | * s_uGetRTSCTSRsvTime- get rts/cts reserved time |
| 35 | * s_uGetTxRsvTime- get frame reserved time |
| 36 | * s_vFillCTSHead- fulfill CTS ctl header |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 37 | * s_vFillFragParameter- Set fragment ctl parameter. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 38 | * s_vFillRTSHead- fulfill RTS ctl header |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 39 | * vDMA0_tx_80211- tx 802.11 frame via dma0 |
| 40 | * vGenerateFIFOHeader- Generate tx FIFO ctl header |
| 41 | * |
| 42 | * Revision History: |
| 43 | * |
| 44 | */ |
| 45 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 46 | #include "device.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 47 | #include "rxtx.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 48 | #include "card.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 49 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 50 | #include "rf.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 51 | #include "usbpipe.h" |
Jim Lieb | 9d26d60 | 2009-08-12 14:54:08 -0700 | [diff] [blame] | 52 | |
Mariano Reingart | 4a499de | 2010-10-29 19:15:26 -0300 | [diff] [blame] | 53 | static int msglevel = MSG_LEVEL_INFO; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 54 | |
Valentina Manea | 3b13885 | 2013-11-04 10:44:02 +0200 | [diff] [blame] | 55 | static const u16 wTimeStampOff[2][MAX_RATE] = { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 56 | {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble |
| 57 | {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble |
| 58 | }; |
| 59 | |
Valentina Manea | 3b13885 | 2013-11-04 10:44:02 +0200 | [diff] [blame] | 60 | static const u16 wFB_Opt0[2][5] = { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 61 | {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0 |
| 62 | {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1 |
| 63 | }; |
Valentina Manea | 3b13885 | 2013-11-04 10:44:02 +0200 | [diff] [blame] | 64 | static const u16 wFB_Opt1[2][5] = { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 65 | {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0 |
| 66 | {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1 |
| 67 | }; |
| 68 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 69 | #define RTSDUR_BB 0 |
| 70 | #define RTSDUR_BA 1 |
| 71 | #define RTSDUR_AA 2 |
| 72 | #define CTSDUR_BA 3 |
| 73 | #define RTSDUR_BA_F0 4 |
| 74 | #define RTSDUR_AA_F0 5 |
| 75 | #define RTSDUR_BA_F1 6 |
| 76 | #define RTSDUR_AA_F1 7 |
| 77 | #define CTSDUR_BA_F0 8 |
| 78 | #define CTSDUR_BA_F1 9 |
| 79 | #define DATADUR_B 10 |
| 80 | #define DATADUR_A 11 |
| 81 | #define DATADUR_A_F0 12 |
| 82 | #define DATADUR_A_F1 13 |
| 83 | |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 84 | static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *); |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 85 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 86 | static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 8e344c8 | 2013-09-17 19:58:11 +0100 | [diff] [blame] | 87 | u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer, |
Malcolm Priestley | fa57560 | 2013-09-26 19:00:41 +0100 | [diff] [blame] | 88 | struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 89 | int bNeedACK, bool need_rts); |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 90 | |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 91 | static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType, |
| 92 | u32 cbFrameLength, u16 wRate, int bNeedAck); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 93 | |
Malcolm Priestley | 2033801 | 2014-03-18 19:25:08 +0000 | [diff] [blame] | 94 | static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv, |
Malcolm Priestley | 3b6cee7be | 2014-05-25 21:36:27 +0100 | [diff] [blame] | 95 | u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 96 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 97 | static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 5fb8e41 | 2013-08-27 12:07:58 +0100 | [diff] [blame] | 98 | u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength, |
| 99 | int bNeedAck, u16 wCurrentRate, u8 byFBOption); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 100 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 101 | 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] | 102 | union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 103 | u16 wCurrentRate, u8 byFBOption); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 104 | |
Malcolm Priestley | 5abe3d6 | 2014-03-18 19:25:06 +0000 | [diff] [blame] | 105 | static __le16 s_uGetDataDuration(struct vnt_private *pDevice, |
Malcolm Priestley | 3ed210e | 2013-08-07 21:28:45 +0100 | [diff] [blame] | 106 | u8 byPktType, int bNeedAck); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 107 | |
Malcolm Priestley | 7f591a1 | 2014-03-18 19:25:05 +0000 | [diff] [blame] | 108 | static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 109 | u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate, |
| 110 | int bNeedAck, u8 byFBOption); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 111 | |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 112 | static struct vnt_usb_send_context |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 113 | *s_vGetFreeContext(struct vnt_private *priv) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 114 | { |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 115 | struct vnt_usb_send_context *context = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 116 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 117 | |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 118 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 119 | |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 120 | for (ii = 0; ii < priv->cbTD; ii++) { |
| 121 | if (!priv->apTD[ii]) |
| 122 | return NULL; |
| 123 | |
| 124 | context = priv->apTD[ii]; |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 125 | if (context->in_use == false) { |
| 126 | context->in_use = true; |
| 127 | memset(context->data, 0, |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 128 | MAX_TOTAL_SIZE_WITH_ALL_HEADERS); |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 129 | |
| 130 | context->hdr = NULL; |
| 131 | |
Malcolm Priestley | b89f3b9 | 2013-11-26 19:16:59 +0000 | [diff] [blame] | 132 | return context; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if (ii == priv->cbTD) |
| 137 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n"); |
Malcolm Priestley | aceaf01 | 2013-11-26 19:06:35 +0000 | [diff] [blame] | 138 | |
Malcolm Priestley | 5c85138 | 2013-11-26 19:12:38 +0000 | [diff] [blame] | 139 | return NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 140 | } |
| 141 | |
Malcolm Priestley | dab085b | 2014-03-18 19:25:03 +0000 | [diff] [blame] | 142 | static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate) |
Malcolm Priestley | f115e76 | 2013-08-23 11:48:46 +0100 | [diff] [blame] | 143 | { |
| 144 | return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2] |
| 145 | [rate % MAX_RATE]); |
| 146 | } |
| 147 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 148 | /*byPktType : PK_TYPE_11A 0 |
| 149 | PK_TYPE_11B 1 |
| 150 | PK_TYPE_11GB 2 |
| 151 | PK_TYPE_11GA 3 |
| 152 | */ |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 153 | static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type, |
| 154 | u32 frame_length, u16 rate, int need_ack) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 155 | { |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 156 | u32 data_time, ack_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 157 | |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 158 | data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 159 | frame_length, rate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 160 | |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 161 | if (pkt_type == PK_TYPE_11B) |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 162 | ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
| 163 | 14, (u16)priv->byTopCCKBasicRate); |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 164 | else |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 165 | ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
| 166 | 14, (u16)priv->byTopOFDMBasicRate); |
Malcolm Priestley | 3fd5620 | 2014-01-08 20:08:42 +0000 | [diff] [blame] | 167 | |
| 168 | if (need_ack) |
| 169 | return data_time + priv->uSIFS + ack_time; |
| 170 | |
| 171 | return data_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Malcolm Priestley | 2075f65 | 2014-03-18 19:25:07 +0000 | [diff] [blame] | 174 | 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] | 175 | u32 frame_length, u16 rate, int need_ack) |
| 176 | { |
| 177 | return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type, |
| 178 | frame_length, rate, need_ack)); |
| 179 | } |
| 180 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 181 | //byFreqType: 0=>5GHZ 1=>2.4GHZ |
Malcolm Priestley | 2033801 | 2014-03-18 19:25:08 +0000 | [diff] [blame] | 182 | static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv, |
Malcolm Priestley | 3b6cee7be | 2014-05-25 21:36:27 +0100 | [diff] [blame] | 183 | u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 184 | { |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 185 | u32 rrv_time, rts_time, cts_time, ack_time, data_time; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 186 | |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 187 | rrv_time = rts_time = cts_time = ack_time = data_time = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 188 | |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 189 | data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 3b6cee7be | 2014-05-25 21:36:27 +0100 | [diff] [blame] | 190 | frame_length, current_rate); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 191 | |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 192 | if (rsv_type == 0) { |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 193 | rts_time = vnt_get_frame_time(priv->byPreambleType, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 194 | pkt_type, 20, priv->byTopCCKBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 195 | cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 196 | pkt_type, 14, priv->byTopCCKBasicRate); |
| 197 | } else if (rsv_type == 1) { |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 198 | rts_time = vnt_get_frame_time(priv->byPreambleType, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 199 | pkt_type, 20, priv->byTopCCKBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 200 | cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 201 | 14, priv->byTopCCKBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 202 | ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 203 | 14, priv->byTopOFDMBasicRate); |
| 204 | } else if (rsv_type == 2) { |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 205 | rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 206 | 20, priv->byTopOFDMBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 207 | cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 208 | pkt_type, 14, priv->byTopOFDMBasicRate); |
| 209 | } else if (rsv_type == 3) { |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 210 | cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 211 | 14, priv->byTopCCKBasicRate); |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 212 | ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type, |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 213 | 14, priv->byTopOFDMBasicRate); |
| 214 | |
| 215 | rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS; |
| 216 | |
Malcolm Priestley | 2033801 | 2014-03-18 19:25:08 +0000 | [diff] [blame] | 217 | return cpu_to_le16((u16)rrv_time); |
Malcolm Priestley | 342e2e2 | 2014-01-08 20:13:29 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS; |
| 221 | |
| 222 | return cpu_to_le16((u16)rrv_time); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | //byFreqType 0: 5GHz, 1:2.4Ghz |
Malcolm Priestley | 5abe3d6 | 2014-03-18 19:25:06 +0000 | [diff] [blame] | 226 | static __le16 s_uGetDataDuration(struct vnt_private *pDevice, |
Malcolm Priestley | 6b5ad9d | 2013-08-21 22:16:04 +0100 | [diff] [blame] | 227 | u8 byPktType, int bNeedAck) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 228 | { |
Malcolm Priestley | 0005cb0 | 2013-08-07 21:26:12 +0100 | [diff] [blame] | 229 | u32 uAckTime = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 230 | |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 231 | if (bNeedAck) { |
Malcolm Priestley | 6b5ad9d | 2013-08-21 22:16:04 +0100 | [diff] [blame] | 232 | if (byPktType == PK_TYPE_11B) |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 233 | uAckTime = vnt_get_frame_time(pDevice->byPreambleType, |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 234 | byPktType, 14, pDevice->byTopCCKBasicRate); |
| 235 | else |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 236 | uAckTime = vnt_get_frame_time(pDevice->byPreambleType, |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 237 | byPktType, 14, pDevice->byTopOFDMBasicRate); |
Malcolm Priestley | d500595 | 2013-08-21 21:58:37 +0100 | [diff] [blame] | 238 | return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime)); |
Malcolm Priestley | b02ccd5 | 2013-08-13 19:59:31 +0100 | [diff] [blame] | 239 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 240 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 241 | return 0; |
| 242 | } |
| 243 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 244 | //byFreqType: 0=>5GHZ 1=>2.4GHZ |
Malcolm Priestley | 7f591a1 | 2014-03-18 19:25:05 +0000 | [diff] [blame] | 245 | static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType, |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 246 | u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck, |
| 247 | u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 248 | { |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 249 | u32 uCTSTime = 0, uDurTime = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 250 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 251 | switch (byDurType) { |
| 252 | case RTSDUR_BB: |
| 253 | case RTSDUR_BA: |
| 254 | case RTSDUR_BA_F0: |
| 255 | case RTSDUR_BA_F1: |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 256 | uCTSTime = vnt_get_frame_time(pDevice->byPreambleType, |
| 257 | byPktType, 14, pDevice->byTopCCKBasicRate); |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 258 | uDurTime = uCTSTime + 2 * pDevice->uSIFS + |
| 259 | s_uGetTxRsvTime(pDevice, byPktType, |
| 260 | cbFrameLength, wRate, bNeedAck); |
| 261 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 262 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 263 | case RTSDUR_AA: |
| 264 | case RTSDUR_AA_F0: |
| 265 | case RTSDUR_AA_F1: |
Malcolm Priestley | d38ee5b | 2014-06-04 18:25:35 +0100 | [diff] [blame] | 266 | uCTSTime = vnt_get_frame_time(pDevice->byPreambleType, |
| 267 | byPktType, 14, pDevice->byTopOFDMBasicRate); |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 268 | uDurTime = uCTSTime + 2 * pDevice->uSIFS + |
| 269 | s_uGetTxRsvTime(pDevice, byPktType, |
| 270 | cbFrameLength, wRate, bNeedAck); |
| 271 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 272 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 273 | case CTSDUR_BA: |
| 274 | case CTSDUR_BA_F0: |
| 275 | case CTSDUR_BA_F1: |
| 276 | uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 277 | byPktType, cbFrameLength, wRate, bNeedAck); |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 278 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 279 | |
Malcolm Priestley | ecd8024 | 2013-10-15 21:05:02 +0100 | [diff] [blame] | 280 | default: |
| 281 | break; |
| 282 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 283 | |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 284 | return cpu_to_le16((u16)uDurTime); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 285 | } |
| 286 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 287 | static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context, |
| 288 | struct ieee80211_hdr *hdr) |
| 289 | { |
| 290 | u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head); |
| 291 | u8 *hdr_pos = (u8 *)hdr; |
| 292 | |
| 293 | tx_context->hdr = hdr; |
| 294 | if (!tx_context->hdr) |
| 295 | return 0; |
| 296 | |
| 297 | return (u16)(hdr_pos - head); |
| 298 | } |
| 299 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 300 | static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context, |
| 301 | u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf, |
| 302 | u32 frame_len, int need_ack) |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 303 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 304 | |
| 305 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame] | 306 | struct ieee80211_hdr *hdr = |
| 307 | (struct ieee80211_hdr *)tx_context->skb->data; |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 308 | |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 309 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 310 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a); |
| 311 | vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 312 | PK_TYPE_11B, &buf->b); |
| 313 | |
| 314 | /* Get Duration and TimeStamp */ |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame] | 315 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
| 316 | __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15)); |
| 317 | |
| 318 | buf->duration_a = dur; |
| 319 | buf->duration_b = dur; |
| 320 | } else { |
| 321 | buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 322 | buf->duration_b = s_uGetDataDuration(priv, |
| 323 | PK_TYPE_11B, need_ack); |
| 324 | } |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 325 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 326 | buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); |
| 327 | buf->time_stamp_off_b = vnt_time_stamp_off(priv, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 328 | priv->byTopCCKBasicRate); |
| 329 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 330 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
| 331 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 332 | return le16_to_cpu(buf->duration_a); |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 335 | static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context, |
| 336 | u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 337 | u32 frame_len, int need_ack) |
| 338 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 339 | struct vnt_private *priv = tx_context->priv; |
| 340 | |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 341 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 342 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 343 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 344 | vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 345 | PK_TYPE_11B, &buf->b); |
| 346 | |
| 347 | /* Get Duration and TimeStamp */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 348 | buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 349 | buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 350 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 351 | buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 352 | buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 353 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 354 | buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); |
| 355 | buf->time_stamp_off_b = vnt_time_stamp_off(priv, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 356 | priv->byTopCCKBasicRate); |
| 357 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 358 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
| 359 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 360 | return le16_to_cpu(buf->duration_a); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 361 | } |
| 362 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 363 | static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context, |
| 364 | u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf, |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 365 | u32 frame_len, int need_ack) |
| 366 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 367 | struct vnt_private *priv = tx_context->priv; |
| 368 | |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 369 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 370 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 371 | /* Get Duration and TimeStampOff */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 372 | buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 373 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 374 | buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 375 | buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 376 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 377 | buf->time_stamp_off = vnt_time_stamp_off(priv, rate); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 378 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 379 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
| 380 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 381 | return le16_to_cpu(buf->duration); |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 384 | static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context, |
| 385 | u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf, |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 386 | u32 frame_len, int need_ack) |
| 387 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 388 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame] | 389 | struct ieee80211_hdr *hdr = |
| 390 | (struct ieee80211_hdr *)tx_context->skb->data; |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 391 | |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 392 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 393 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab); |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame] | 394 | |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 395 | /* Get Duration and TimeStampOff */ |
Malcolm Priestley | 893cc70 | 2014-06-25 21:14:38 +0100 | [diff] [blame] | 396 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
| 397 | __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15)); |
| 398 | |
| 399 | buf->duration = dur; |
| 400 | } else { |
| 401 | buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack); |
| 402 | } |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 403 | |
Malcolm Priestley | 10bb39a | 2014-03-18 19:25:01 +0000 | [diff] [blame] | 404 | buf->time_stamp_off = vnt_time_stamp_off(priv, rate); |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 405 | |
Malcolm Priestley | 1622c8f | 2014-05-31 13:34:58 +0100 | [diff] [blame] | 406 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
| 407 | |
Malcolm Priestley | c4cf6df | 2014-03-18 19:25:04 +0000 | [diff] [blame] | 408 | return le16_to_cpu(buf->duration); |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 409 | } |
| 410 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 411 | static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context, |
| 412 | struct ieee80211_rts *rts, __le16 duration) |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 413 | { |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 414 | struct ieee80211_hdr *hdr = |
| 415 | (struct ieee80211_hdr *)tx_context->skb->data; |
| 416 | |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 417 | rts->duration = duration; |
Malcolm Priestley | f4554d3 | 2014-03-22 09:01:31 +0000 | [diff] [blame] | 418 | rts->frame_control = |
| 419 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 420 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 421 | memcpy(rts->ra, hdr->addr1, ETH_ALEN); |
| 422 | memcpy(rts->ta, hdr->addr2, ETH_ALEN); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 427 | static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 428 | struct vnt_rts_g *buf, u8 pkt_type, u32 frame_len, int need_ack, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 429 | u16 current_rate, u8 fb_option) |
| 430 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 431 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 432 | u16 rts_frame_len = 20; |
| 433 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 434 | vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 435 | PK_TYPE_11B, &buf->b); |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 436 | vnt_get_phy_field(priv, rts_frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 437 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 438 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 439 | buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 440 | PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 441 | buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 442 | pkt_type, current_rate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 443 | buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 444 | pkt_type, current_rate, need_ack, fb_option); |
| 445 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 446 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 447 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 448 | return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 449 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 452 | static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 453 | struct vnt_rts_g_fb *buf, u8 pkt_type, u32 frame_len, int need_ack, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 454 | u16 current_rate, u8 fb_option) |
| 455 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 456 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 457 | u16 rts_frame_len = 20; |
| 458 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 459 | vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 460 | PK_TYPE_11B, &buf->b); |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 461 | vnt_get_phy_field(priv, rts_frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 462 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 463 | |
| 464 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 465 | buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 466 | PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 467 | buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 468 | pkt_type, current_rate, need_ack, fb_option); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 469 | buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len, |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 470 | pkt_type, current_rate, need_ack, fb_option); |
| 471 | |
| 472 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 473 | buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 474 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 475 | buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 476 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 477 | buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 478 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 479 | buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 480 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 481 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 482 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 483 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 484 | return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate, |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 485 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | ec91713 | 2013-08-26 11:07:46 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 488 | static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 489 | struct vnt_rts_ab *buf, u8 pkt_type, u32 frame_len, int need_ack, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 490 | u16 current_rate, u8 fb_option) |
| 491 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 492 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 493 | u16 rts_frame_len = 20; |
| 494 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 495 | vnt_get_phy_field(priv, rts_frame_len, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 496 | priv->byTopOFDMBasicRate, pkt_type, &buf->ab); |
| 497 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 498 | buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 499 | pkt_type, current_rate, need_ack, fb_option); |
| 500 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 501 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration); |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 502 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 503 | return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate, |
Malcolm Priestley | 5634a5a | 2013-10-01 16:00:20 +0100 | [diff] [blame] | 504 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 1712633 | 2013-08-26 11:09:38 +0100 | [diff] [blame] | 505 | } |
| 506 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 507 | static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 508 | struct vnt_rts_a_fb *buf, u8 pkt_type, u32 frame_len, int need_ack, |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 509 | u16 current_rate, u8 fb_option) |
| 510 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 511 | struct vnt_private *priv = tx_context->priv; |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 512 | u16 rts_frame_len = 20; |
| 513 | |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 514 | vnt_get_phy_field(priv, rts_frame_len, |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 515 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); |
| 516 | |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 517 | buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 518 | pkt_type, current_rate, need_ack, fb_option); |
| 519 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 520 | buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 521 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 522 | |
Malcolm Priestley | fadc3bd | 2014-03-18 19:24:56 +0000 | [diff] [blame] | 523 | buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 524 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 525 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 526 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 527 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 528 | return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate, |
Malcolm Priestley | bd3f51f | 2013-10-01 15:56:48 +0100 | [diff] [blame] | 529 | &buf->data_head, frame_len, need_ack); |
Malcolm Priestley | 9d2578c | 2013-08-26 11:12:00 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 532 | 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] | 533 | union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 534 | u16 wCurrentRate, u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 535 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 536 | |
Malcolm Priestley | 13fe62a | 2013-08-26 11:17:52 +0100 | [diff] [blame] | 537 | if (!head) |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 538 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 539 | |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 540 | /* Note: So far RTSHead doesn't appear in ATIM |
| 541 | * & Beacom DMA, so we don't need to take them |
| 542 | * into account. |
| 543 | * Otherwise, we need to modified codes for them. |
| 544 | */ |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 545 | switch (byPktType) { |
| 546 | case PK_TYPE_11GB: |
| 547 | case PK_TYPE_11GA: |
Malcolm Priestley | ce7b0db | 2014-07-10 19:56:03 +0100 | [diff] [blame^] | 548 | if (!tx_context->fb_option) |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 549 | return vnt_rxtx_rts_g_head(tx_context, &head->rts_g, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 550 | byPktType, cbFrameLength, |
Malcolm Priestley | 5e67ee4 | 2013-08-26 11:04:50 +0100 | [diff] [blame] | 551 | bNeedAck, wCurrentRate, byFBOption); |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 552 | else |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 553 | return vnt_rxtx_rts_g_fb_head(tx_context, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 554 | &head->rts_g_fb, byPktType, |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 555 | cbFrameLength, bNeedAck, wCurrentRate, |
| 556 | byFBOption); |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 557 | break; |
| 558 | case PK_TYPE_11A: |
Malcolm Priestley | ce7b0db | 2014-07-10 19:56:03 +0100 | [diff] [blame^] | 559 | if (tx_context->fb_option) { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 560 | return vnt_rxtx_rts_a_fb_head(tx_context, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 561 | &head->rts_a_fb, byPktType, |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 562 | cbFrameLength, bNeedAck, wCurrentRate, |
| 563 | byFBOption); |
Malcolm Priestley | 2b83ebd | 2013-08-27 09:58:21 +0100 | [diff] [blame] | 564 | break; |
| 565 | } |
Malcolm Priestley | 0bddd30 | 2013-08-27 09:56:50 +0100 | [diff] [blame] | 566 | case PK_TYPE_11B: |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 567 | return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 568 | byPktType, cbFrameLength, bNeedAck, |
| 569 | wCurrentRate, byFBOption); |
Malcolm Priestley | 9d5829b | 2013-08-26 11:21:11 +0100 | [diff] [blame] | 570 | } |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 571 | |
| 572 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 575 | static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 5fb8e41 | 2013-08-27 12:07:58 +0100 | [diff] [blame] | 576 | u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength, |
| 577 | int bNeedAck, u16 wCurrentRate, u8 byFBOption) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 578 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 579 | struct vnt_private *pDevice = tx_context->priv; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 580 | u32 uCTSFrameLen = 14; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 581 | |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 582 | if (!head) |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 583 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 584 | |
Malcolm Priestley | ce7b0db | 2014-07-10 19:56:03 +0100 | [diff] [blame^] | 585 | if (tx_context->fb_option) { |
Malcolm Priestley | c921cc8 | 2013-08-20 20:47:49 +0100 | [diff] [blame] | 586 | /* Auto Fall back */ |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 587 | struct vnt_cts_fb *pBuf = &head->cts_g_fb; |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 588 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 589 | vnt_get_phy_field(pDevice, uCTSFrameLen, |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 590 | pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b); |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 591 | pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 592 | cbFrameLength, byPktType, |
| 593 | wCurrentRate, bNeedAck, byFBOption); |
| 594 | /* Get CTSDuration_ba_f0 */ |
Malcolm Priestley | 7fd5747 | 2014-03-18 19:24:59 +0000 | [diff] [blame] | 595 | pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 596 | CTSDUR_BA_F0, cbFrameLength, byPktType, |
| 597 | pDevice->tx_rate_fb0, bNeedAck, byFBOption); |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 598 | /* Get CTSDuration_ba_f1 */ |
Malcolm Priestley | 7fd5747 | 2014-03-18 19:24:59 +0000 | [diff] [blame] | 599 | pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | f84cdf6 | 2013-10-15 21:00:09 +0100 | [diff] [blame] | 600 | CTSDUR_BA_F1, cbFrameLength, byPktType, |
| 601 | pDevice->tx_rate_fb1, bNeedAck, byFBOption); |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 602 | /* Get CTS Frame body */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 603 | pBuf->data.duration = pBuf->duration_ba; |
Malcolm Priestley | d9560ae | 2014-03-22 09:01:32 +0000 | [diff] [blame] | 604 | pBuf->data.frame_control = |
| 605 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); |
| 606 | |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 607 | memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); |
Malcolm Priestley | 5b852f5 | 2013-10-01 15:54:56 +0100 | [diff] [blame] | 608 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 609 | return vnt_rxtx_datahead_g_fb(tx_context, byPktType, |
| 610 | wCurrentRate, &pBuf->data_head, cbFrameLength, |
| 611 | bNeedAck); |
Malcolm Priestley | c921cc8 | 2013-08-20 20:47:49 +0100 | [diff] [blame] | 612 | } else { |
Malcolm Priestley | 27df3eb | 2013-08-27 11:48:34 +0100 | [diff] [blame] | 613 | struct vnt_cts *pBuf = &head->cts_g; |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 614 | /* Get SignalField,ServiceField,Length */ |
Malcolm Priestley | 205056f | 2014-06-04 18:25:34 +0100 | [diff] [blame] | 615 | vnt_get_phy_field(pDevice, uCTSFrameLen, |
Malcolm Priestley | aed387c | 2013-08-20 22:52:30 +0100 | [diff] [blame] | 616 | pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b); |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 617 | /* Get CTSDuration_ba */ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 618 | pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, |
Malcolm Priestley | e34f9db | 2013-08-13 20:17:11 +0100 | [diff] [blame] | 619 | CTSDUR_BA, cbFrameLength, byPktType, |
| 620 | wCurrentRate, bNeedAck, byFBOption); |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 621 | /*Get CTS Frame body*/ |
Malcolm Priestley | 4e01117 | 2014-03-18 19:24:55 +0000 | [diff] [blame] | 622 | pBuf->data.duration = pBuf->duration_ba; |
Malcolm Priestley | d9560ae | 2014-03-22 09:01:32 +0000 | [diff] [blame] | 623 | pBuf->data.frame_control = |
| 624 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); |
| 625 | |
Malcolm Priestley | 14840cd | 2013-08-05 22:12:42 +0100 | [diff] [blame] | 626 | memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 627 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 628 | return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate, |
Malcolm Priestley | 78363fd | 2013-10-01 15:52:16 +0100 | [diff] [blame] | 629 | &pBuf->data_head, cbFrameLength, bNeedAck); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 630 | } |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 631 | |
| 632 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 633 | } |
| 634 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 635 | /*+ |
| 636 | * |
| 637 | * Description: |
| 638 | * Generate FIFO control for MAC & Baseband controller |
| 639 | * |
| 640 | * Parameters: |
| 641 | * In: |
| 642 | * pDevice - Pointer to adpater |
| 643 | * pTxDataHead - Transmit Data Buffer |
| 644 | * pTxBufHead - pTxBufHead |
| 645 | * pvRrvTime - pvRrvTime |
| 646 | * pvRTS - RTS Buffer |
| 647 | * pCTS - CTS Buffer |
| 648 | * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS) |
| 649 | * bNeedACK - If need ACK |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 650 | * Out: |
| 651 | * none |
| 652 | * |
| 653 | * Return Value: none |
| 654 | * |
| 655 | -*/ |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 656 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 657 | static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context, |
Malcolm Priestley | 8e344c8 | 2013-09-17 19:58:11 +0100 | [diff] [blame] | 658 | u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer, |
Malcolm Priestley | fa57560 | 2013-09-26 19:00:41 +0100 | [diff] [blame] | 659 | struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 660 | int bNeedACK, bool need_rts) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 661 | { |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 662 | struct vnt_private *pDevice = tx_context->priv; |
Malcolm Priestley | 8e344c8 | 2013-09-17 19:58:11 +0100 | [diff] [blame] | 663 | struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 664 | union vnt_tx_data_head *head = NULL; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 665 | u16 wFifoCtl; |
Malcolm Priestley | d56131d | 2013-01-17 23:15:22 +0000 | [diff] [blame] | 666 | u8 byFBOption = AUTO_FB_NONE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 667 | |
Malcolm Priestley | 03a9cf3 | 2014-03-22 09:01:30 +0000 | [diff] [blame] | 668 | pFifoHead->current_rate = cpu_to_le16(wCurrentRate); |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 669 | wFifoCtl = pFifoHead->wFIFOCtl; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 670 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 671 | if (wFifoCtl & FIFOCTL_AUTO_FB_0) |
| 672 | byFBOption = AUTO_FB_0; |
| 673 | else if (wFifoCtl & FIFOCTL_AUTO_FB_1) |
| 674 | byFBOption = AUTO_FB_1; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 675 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 676 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) { |
| 677 | if (need_rts) { |
| 678 | struct vnt_rrv_time_rts *pBuf = |
| 679 | &tx_buffer->tx_head.tx_rts.rts; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 680 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 681 | pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 682 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 683 | pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 684 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 685 | pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 686 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 687 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 688 | pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 689 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 690 | pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 691 | PK_TYPE_11B, cbFrameSize, |
| 692 | pDevice->byTopCCKBasicRate, bNeedACK); |
| 693 | |
| 694 | if (need_mic) { |
| 695 | *mic_hdr = &tx_buffer-> |
| 696 | tx_head.tx_rts.tx.mic.hdr; |
| 697 | head = &tx_buffer->tx_head.tx_rts.tx.mic.head; |
| 698 | } else { |
| 699 | head = &tx_buffer->tx_head.tx_rts.tx.head; |
| 700 | } |
| 701 | |
| 702 | /* Fill RTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 703 | return s_vFillRTSHead(tx_context, byPktType, head, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 704 | cbFrameSize, bNeedACK, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 705 | wCurrentRate, byFBOption); |
| 706 | |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 707 | } else { |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 708 | struct vnt_rrv_time_cts *pBuf = &tx_buffer-> |
| 709 | tx_head.tx_cts.cts; |
| 710 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 711 | pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 712 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 713 | pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 714 | PK_TYPE_11B, cbFrameSize, |
| 715 | pDevice->byTopCCKBasicRate, bNeedACK); |
| 716 | |
Malcolm Priestley | 372108e | 2014-03-18 19:25:00 +0000 | [diff] [blame] | 717 | pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 718 | byPktType, cbFrameSize, wCurrentRate); |
| 719 | |
| 720 | if (need_mic) { |
| 721 | *mic_hdr = &tx_buffer-> |
| 722 | tx_head.tx_cts.tx.mic.hdr; |
| 723 | head = &tx_buffer->tx_head.tx_cts.tx.mic.head; |
| 724 | } else { |
| 725 | head = &tx_buffer->tx_head.tx_cts.tx.head; |
| 726 | } |
| 727 | |
| 728 | /* Fill CTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 729 | return s_vFillCTSHead(tx_context, byPktType, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 730 | head, cbFrameSize, bNeedACK, wCurrentRate, |
| 731 | byFBOption); |
| 732 | } |
| 733 | } else if (byPktType == PK_TYPE_11A) { |
| 734 | if (need_mic) { |
| 735 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; |
| 736 | head = &tx_buffer->tx_head.tx_ab.tx.mic.head; |
| 737 | } else { |
| 738 | head = &tx_buffer->tx_head.tx_ab.tx.head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 739 | } |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 740 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 741 | if (need_rts) { |
| 742 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 743 | tx_head.tx_ab.ab; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 744 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 745 | pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 746 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 747 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 748 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 749 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); |
| 750 | |
| 751 | /* Fill RTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 752 | return s_vFillRTSHead(tx_context, byPktType, head, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 753 | cbFrameSize, bNeedACK, |
| 754 | wCurrentRate, byFBOption); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 755 | } else { |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 756 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 757 | tx_head.tx_ab.ab; |
| 758 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 759 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 760 | PK_TYPE_11A, cbFrameSize, |
| 761 | wCurrentRate, bNeedACK); |
| 762 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 763 | return vnt_rxtx_datahead_a_fb(tx_context, byPktType, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 764 | wCurrentRate, &head->data_head_a_fb, |
| 765 | cbFrameSize, bNeedACK); |
| 766 | } |
| 767 | } else if (byPktType == PK_TYPE_11B) { |
| 768 | if (need_mic) { |
| 769 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; |
| 770 | head = &tx_buffer->tx_head.tx_ab.tx.mic.head; |
| 771 | } else { |
| 772 | head = &tx_buffer->tx_head.tx_ab.tx.head; |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 773 | } |
Malcolm Priestley | f0e0d50 | 2013-09-26 18:52:10 +0100 | [diff] [blame] | 774 | |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 775 | if (need_rts) { |
| 776 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 777 | tx_head.tx_ab.ab; |
Malcolm Priestley | a90186e | 2013-10-01 15:58:54 +0100 | [diff] [blame] | 778 | |
Malcolm Priestley | 85417bf | 2014-03-18 19:24:57 +0000 | [diff] [blame] | 779 | pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0, |
Malcolm Priestley | cfabe4b | 2013-08-22 21:03:40 +0100 | [diff] [blame] | 780 | byPktType, cbFrameSize, wCurrentRate); |
Malcolm Priestley | b9cc2fc | 2013-09-26 18:57:34 +0100 | [diff] [blame] | 781 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 782 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 783 | PK_TYPE_11B, cbFrameSize, wCurrentRate, |
| 784 | bNeedACK); |
| 785 | |
| 786 | /* Fill RTS */ |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 787 | return s_vFillRTSHead(tx_context, byPktType, head, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 788 | cbFrameSize, bNeedACK, |
| 789 | wCurrentRate, byFBOption); |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 790 | } else { |
| 791 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> |
| 792 | tx_head.tx_ab.ab; |
Malcolm Priestley | 9e38a5c | 2013-09-26 18:47:25 +0100 | [diff] [blame] | 793 | |
Malcolm Priestley | 5ff627a | 2014-03-18 19:24:58 +0000 | [diff] [blame] | 794 | pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 795 | PK_TYPE_11B, cbFrameSize, |
| 796 | wCurrentRate, bNeedACK); |
Malcolm Priestley | a90186e | 2013-10-01 15:58:54 +0100 | [diff] [blame] | 797 | |
Malcolm Priestley | c2c32da | 2014-05-31 13:34:57 +0100 | [diff] [blame] | 798 | return vnt_rxtx_datahead_ab(tx_context, byPktType, |
Malcolm Priestley | 92928f1 | 2013-10-07 20:14:01 +0100 | [diff] [blame] | 799 | wCurrentRate, &head->data_head_ab, |
| 800 | cbFrameSize, bNeedACK); |
| 801 | } |
Malcolm Priestley | c12dca0 | 2013-10-01 16:03:40 +0100 | [diff] [blame] | 802 | } |
| 803 | |
Malcolm Priestley | 0a0f4b6 | 2013-10-01 15:50:24 +0100 | [diff] [blame] | 804 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 805 | } |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 806 | |
| 807 | static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context, |
| 808 | u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb, |
| 809 | u16 payload_len, struct vnt_mic_hdr *mic_hdr) |
| 810 | { |
| 811 | struct ieee80211_hdr *hdr = tx_context->hdr; |
| 812 | struct ieee80211_key_seq seq; |
| 813 | u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb)); |
| 814 | |
| 815 | /* strip header and icv len from payload */ |
| 816 | payload_len -= ieee80211_get_hdrlen_from_skb(skb); |
| 817 | payload_len -= tx_key->icv_len; |
| 818 | |
| 819 | switch (tx_key->cipher) { |
| 820 | case WLAN_CIPHER_SUITE_WEP40: |
| 821 | case WLAN_CIPHER_SUITE_WEP104: |
| 822 | memcpy(key_buffer, iv, 3); |
| 823 | memcpy(key_buffer + 3, tx_key->key, tx_key->keylen); |
| 824 | |
| 825 | if (tx_key->keylen == WLAN_KEY_LEN_WEP40) { |
| 826 | memcpy(key_buffer + 8, iv, 3); |
| 827 | memcpy(key_buffer + 11, |
| 828 | tx_key->key, WLAN_KEY_LEN_WEP40); |
| 829 | } |
| 830 | |
| 831 | break; |
| 832 | case WLAN_CIPHER_SUITE_TKIP: |
| 833 | ieee80211_get_tkip_p2k(tx_key, skb, key_buffer); |
| 834 | |
| 835 | break; |
| 836 | case WLAN_CIPHER_SUITE_CCMP: |
| 837 | |
| 838 | if (!mic_hdr) |
| 839 | return; |
| 840 | |
| 841 | mic_hdr->id = 0x59; |
| 842 | mic_hdr->payload_len = cpu_to_be16(payload_len); |
| 843 | memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN); |
| 844 | |
| 845 | ieee80211_get_key_tx_seq(tx_key, &seq); |
| 846 | |
Malcolm Priestley | 79f976d | 2014-06-28 23:55:39 +0100 | [diff] [blame] | 847 | memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN); |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 848 | |
| 849 | if (ieee80211_has_a4(hdr->frame_control)) |
| 850 | mic_hdr->hlen = cpu_to_be16(28); |
| 851 | else |
| 852 | mic_hdr->hlen = cpu_to_be16(22); |
| 853 | |
| 854 | memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN); |
| 855 | memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN); |
| 856 | memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN); |
| 857 | |
| 858 | mic_hdr->frame_control = cpu_to_le16( |
| 859 | le16_to_cpu(hdr->frame_control) & 0xc78f); |
| 860 | mic_hdr->seq_ctrl = cpu_to_le16( |
| 861 | le16_to_cpu(hdr->seq_ctrl) & 0xf); |
| 862 | |
| 863 | if (ieee80211_has_a4(hdr->frame_control)) |
| 864 | memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN); |
| 865 | |
| 866 | |
| 867 | memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP); |
| 868 | |
| 869 | break; |
| 870 | default: |
| 871 | break; |
| 872 | } |
| 873 | |
| 874 | } |
| 875 | |
| 876 | int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) |
| 877 | { |
| 878 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 879 | struct ieee80211_tx_rate *tx_rate = &info->control.rates[0]; |
| 880 | struct ieee80211_rate *rate; |
| 881 | struct ieee80211_key_conf *tx_key; |
| 882 | struct ieee80211_hdr *hdr; |
| 883 | struct vnt_mic_hdr *mic_hdr = NULL; |
| 884 | struct vnt_tx_buffer *tx_buffer; |
| 885 | struct vnt_tx_fifo_head *tx_buffer_head; |
| 886 | struct vnt_usb_send_context *tx_context; |
| 887 | unsigned long flags; |
| 888 | u32 frame_size = 0; |
| 889 | u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id; |
| 890 | u8 pkt_type, fb_option = AUTO_FB_NONE; |
| 891 | bool need_rts = false, need_ack = false, is_pspoll = false; |
| 892 | bool need_mic = false; |
| 893 | |
| 894 | hdr = (struct ieee80211_hdr *)(skb->data); |
| 895 | |
| 896 | rate = ieee80211_get_tx_rate(priv->hw, info); |
| 897 | |
| 898 | current_rate = rate->hw_value; |
Malcolm Priestley | 5091d96 | 2014-07-05 19:24:23 +0100 | [diff] [blame] | 899 | if (priv->wCurrentRate != current_rate && |
| 900 | !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) { |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 901 | priv->wCurrentRate = current_rate; |
| 902 | bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL); |
| 903 | } |
| 904 | |
| 905 | if (current_rate > RATE_11M) |
| 906 | pkt_type = priv->byPacketType; |
| 907 | else |
| 908 | pkt_type = PK_TYPE_11B; |
| 909 | |
| 910 | spin_lock_irqsave(&priv->lock, flags); |
| 911 | |
| 912 | tx_context = s_vGetFreeContext(priv); |
| 913 | if (!tx_context) { |
| 914 | dev_dbg(&priv->usb->dev, "%s No free context\n", __func__); |
| 915 | spin_unlock_irqrestore(&priv->lock, flags); |
| 916 | return -ENOMEM; |
| 917 | } |
| 918 | |
| 919 | tx_context->skb = skb; |
| 920 | |
| 921 | spin_unlock_irqrestore(&priv->lock, flags); |
| 922 | |
| 923 | tx_buffer = (struct vnt_tx_buffer *)tx_context->data; |
| 924 | tx_buffer_head = &tx_buffer->fifo_head; |
| 925 | tx_body_size = skb->len; |
| 926 | |
| 927 | frame_size = tx_body_size + 4; |
| 928 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 929 | /*Set fifo controls */ |
| 930 | if (pkt_type == PK_TYPE_11A) |
| 931 | tx_buffer_head->wFIFOCtl = 0; |
| 932 | else if (pkt_type == PK_TYPE_11B) |
| 933 | tx_buffer_head->wFIFOCtl = FIFOCTL_11B; |
| 934 | else if (pkt_type == PK_TYPE_11GB) |
| 935 | tx_buffer_head->wFIFOCtl = FIFOCTL_11GB; |
| 936 | else if (pkt_type == PK_TYPE_11GA) |
| 937 | tx_buffer_head->wFIFOCtl = FIFOCTL_11GA; |
| 938 | |
| 939 | if (!ieee80211_is_data(hdr->frame_control)) { |
| 940 | tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT | |
| 941 | FIFOCTL_ISDMA0); |
| 942 | tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN; |
| 943 | |
| 944 | tx_buffer_head->time_stamp = |
| 945 | cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); |
| 946 | } else { |
| 947 | tx_buffer_head->time_stamp = |
| 948 | cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us); |
| 949 | } |
| 950 | |
| 951 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
| 952 | tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK; |
| 953 | need_ack = true; |
| 954 | } |
| 955 | |
| 956 | if (ieee80211_has_retry(hdr->frame_control)) |
| 957 | tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY; |
| 958 | |
| 959 | if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 960 | priv->byPreambleType = PREAMBLE_SHORT; |
| 961 | else |
| 962 | priv->byPreambleType = PREAMBLE_LONG; |
| 963 | |
| 964 | if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 965 | need_rts = true; |
| 966 | tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS; |
| 967 | } |
| 968 | |
| 969 | if (ieee80211_has_a4(hdr->frame_control)) |
| 970 | tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD; |
| 971 | |
| 972 | if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) |
| 973 | is_pspoll = true; |
| 974 | |
Malcolm Priestley | 5deb1cf | 2014-06-28 23:55:40 +0100 | [diff] [blame] | 975 | tx_buffer_head->frag_ctl = |
| 976 | cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10); |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 977 | |
| 978 | if (info->control.hw_key) { |
| 979 | tx_key = info->control.hw_key; |
| 980 | switch (info->control.hw_key->cipher) { |
| 981 | case WLAN_CIPHER_SUITE_WEP40: |
| 982 | case WLAN_CIPHER_SUITE_WEP104: |
Malcolm Priestley | 5deb1cf | 2014-06-28 23:55:40 +0100 | [diff] [blame] | 983 | tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY); |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 984 | break; |
| 985 | case WLAN_CIPHER_SUITE_TKIP: |
Malcolm Priestley | 5deb1cf | 2014-06-28 23:55:40 +0100 | [diff] [blame] | 986 | tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP); |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 987 | break; |
| 988 | case WLAN_CIPHER_SUITE_CCMP: |
Malcolm Priestley | 5deb1cf | 2014-06-28 23:55:40 +0100 | [diff] [blame] | 989 | tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES); |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 990 | need_mic = true; |
| 991 | default: |
| 992 | break; |
| 993 | } |
| 994 | frame_size += tx_key->icv_len; |
| 995 | } |
| 996 | |
| 997 | /* legacy rates TODO use ieee80211_tx_rate */ |
| 998 | if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) { |
| 999 | if (priv->byAutoFBCtrl == AUTO_FB_0) { |
| 1000 | tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0; |
| 1001 | |
| 1002 | priv->tx_rate_fb0 = |
| 1003 | wFB_Opt0[FB_RATE0][current_rate - RATE_18M]; |
| 1004 | priv->tx_rate_fb1 = |
| 1005 | wFB_Opt0[FB_RATE1][current_rate - RATE_18M]; |
| 1006 | |
| 1007 | fb_option = AUTO_FB_0; |
| 1008 | } else if (priv->byAutoFBCtrl == AUTO_FB_1) { |
| 1009 | tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1; |
| 1010 | |
| 1011 | priv->tx_rate_fb0 = |
| 1012 | wFB_Opt1[FB_RATE0][current_rate - RATE_18M]; |
| 1013 | priv->tx_rate_fb1 = |
| 1014 | wFB_Opt1[FB_RATE1][current_rate - RATE_18M]; |
| 1015 | |
| 1016 | fb_option = AUTO_FB_1; |
| 1017 | } |
| 1018 | } |
| 1019 | |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 1020 | tx_context->fb_option = fb_option; |
| 1021 | |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 1022 | duration_id = s_vGenerateTxParameter(tx_context, pkt_type, current_rate, |
| 1023 | tx_buffer, &mic_hdr, need_mic, frame_size, |
Malcolm Priestley | 72bf805 | 2014-07-10 19:56:02 +0100 | [diff] [blame] | 1024 | need_ack, need_rts); |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 1025 | |
| 1026 | tx_header_size = tx_context->tx_hdr_size; |
| 1027 | if (!tx_header_size) { |
| 1028 | tx_context->in_use = false; |
| 1029 | return -ENOMEM; |
| 1030 | } |
| 1031 | |
Malcolm Priestley | 5deb1cf | 2014-06-28 23:55:40 +0100 | [diff] [blame] | 1032 | tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG); |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 1033 | |
| 1034 | tx_bytes = tx_header_size + tx_body_size; |
| 1035 | |
| 1036 | memcpy(tx_context->hdr, skb->data, tx_body_size); |
| 1037 | |
| 1038 | hdr->duration_id = cpu_to_le16(duration_id); |
| 1039 | |
| 1040 | if (info->control.hw_key) { |
| 1041 | tx_key = info->control.hw_key; |
| 1042 | if (tx_key->keylen > 0) |
| 1043 | vnt_fill_txkey(tx_context, tx_buffer_head->tx_key, |
| 1044 | tx_key, skb, tx_body_size, mic_hdr); |
| 1045 | } |
| 1046 | |
| 1047 | priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) & |
| 1048 | IEEE80211_SCTL_SEQ) >> 4; |
| 1049 | |
| 1050 | tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes); |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 1051 | tx_buffer->byPKTNO = tx_context->pkt_no; |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 1052 | tx_buffer->byType = 0x00; |
| 1053 | |
| 1054 | tx_bytes += 4; |
| 1055 | |
| 1056 | tx_context->type = CONTEXT_DATA_PACKET; |
| 1057 | tx_context->buf_len = tx_bytes; |
| 1058 | |
| 1059 | spin_lock_irqsave(&priv->lock, flags); |
| 1060 | |
| 1061 | if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) { |
| 1062 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1063 | return -EIO; |
| 1064 | } |
| 1065 | |
| 1066 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1067 | |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | static int vnt_beacon_xmit(struct vnt_private *priv, |
| 1072 | struct sk_buff *skb) |
| 1073 | { |
| 1074 | struct vnt_beacon_buffer *beacon_buffer; |
| 1075 | struct vnt_tx_short_buf_head *short_head; |
| 1076 | struct ieee80211_tx_info *info; |
| 1077 | struct vnt_usb_send_context *context; |
| 1078 | struct ieee80211_mgmt *mgmt_hdr; |
| 1079 | unsigned long flags; |
| 1080 | u32 frame_size = skb->len + 4; |
| 1081 | u16 current_rate, count; |
| 1082 | |
| 1083 | spin_lock_irqsave(&priv->lock, flags); |
| 1084 | |
| 1085 | context = s_vGetFreeContext(priv); |
| 1086 | if (!context) { |
| 1087 | dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__); |
| 1088 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1089 | return -ENOMEM; |
| 1090 | } |
| 1091 | |
| 1092 | context->skb = skb; |
| 1093 | |
| 1094 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1095 | |
| 1096 | beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0]; |
| 1097 | short_head = &beacon_buffer->short_head; |
| 1098 | |
| 1099 | if (priv->byBBType == BB_TYPE_11A) { |
| 1100 | current_rate = RATE_6M; |
| 1101 | |
| 1102 | /* Get SignalField,ServiceField,Length */ |
| 1103 | vnt_get_phy_field(priv, frame_size, current_rate, |
| 1104 | PK_TYPE_11A, &short_head->ab); |
| 1105 | |
| 1106 | /* Get Duration and TimeStampOff */ |
| 1107 | short_head->duration = s_uGetDataDuration(priv, |
| 1108 | PK_TYPE_11A, false); |
| 1109 | short_head->time_stamp_off = |
| 1110 | vnt_time_stamp_off(priv, current_rate); |
| 1111 | } else { |
| 1112 | current_rate = RATE_1M; |
| 1113 | short_head->fifo_ctl |= FIFOCTL_11B; |
| 1114 | |
| 1115 | /* Get SignalField,ServiceField,Length */ |
| 1116 | vnt_get_phy_field(priv, frame_size, current_rate, |
| 1117 | PK_TYPE_11B, &short_head->ab); |
| 1118 | |
| 1119 | /* Get Duration and TimeStampOff */ |
| 1120 | short_head->duration = s_uGetDataDuration(priv, |
| 1121 | PK_TYPE_11B, false); |
| 1122 | short_head->time_stamp_off = |
| 1123 | vnt_time_stamp_off(priv, current_rate); |
| 1124 | } |
| 1125 | |
| 1126 | /* Generate Beacon Header */ |
| 1127 | mgmt_hdr = &beacon_buffer->mgmt_hdr; |
| 1128 | memcpy(mgmt_hdr, skb->data, skb->len); |
| 1129 | |
| 1130 | /* time stamp always 0 */ |
| 1131 | mgmt_hdr->u.beacon.timestamp = 0; |
| 1132 | |
| 1133 | info = IEEE80211_SKB_CB(skb); |
| 1134 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 1135 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr; |
| 1136 | hdr->duration_id = 0; |
| 1137 | hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4); |
| 1138 | } |
| 1139 | |
| 1140 | priv->wSeqCounter++; |
| 1141 | if (priv->wSeqCounter > 0x0fff) |
| 1142 | priv->wSeqCounter = 0; |
| 1143 | |
| 1144 | count = sizeof(struct vnt_tx_short_buf_head) + skb->len; |
| 1145 | |
| 1146 | beacon_buffer->tx_byte_count = cpu_to_le16(count); |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 1147 | beacon_buffer->byPKTNO = context->pkt_no; |
Malcolm Priestley | d38b13a | 2014-06-25 21:14:23 +0100 | [diff] [blame] | 1148 | beacon_buffer->byType = 0x01; |
| 1149 | |
| 1150 | context->type = CONTEXT_BEACON_PACKET; |
| 1151 | context->buf_len = count + 4; /* USB header */ |
| 1152 | |
| 1153 | spin_lock_irqsave(&priv->lock, flags); |
| 1154 | |
| 1155 | if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING) |
| 1156 | ieee80211_free_txskb(priv->hw, context->skb); |
| 1157 | |
| 1158 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1159 | |
| 1160 | return 0; |
| 1161 | } |
| 1162 | |
| 1163 | int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif) |
| 1164 | { |
| 1165 | struct sk_buff *beacon; |
| 1166 | |
| 1167 | beacon = ieee80211_beacon_get(priv->hw, vif); |
| 1168 | if (!beacon) |
| 1169 | return -ENOMEM; |
| 1170 | |
| 1171 | if (vnt_beacon_xmit(priv, beacon)) { |
| 1172 | ieee80211_free_txskb(priv->hw, beacon); |
| 1173 | return -ENODEV; |
| 1174 | } |
| 1175 | |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif, |
| 1180 | struct ieee80211_bss_conf *conf) |
| 1181 | { |
| 1182 | int ret; |
| 1183 | |
| 1184 | vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); |
| 1185 | |
| 1186 | vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); |
| 1187 | |
| 1188 | vnt_mac_set_beacon_interval(priv, conf->beacon_int); |
| 1189 | |
| 1190 | vnt_clear_current_tsf(priv); |
| 1191 | |
| 1192 | vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); |
| 1193 | |
| 1194 | vnt_reset_next_tbtt(priv, conf->beacon_int); |
| 1195 | |
| 1196 | ret = vnt_beacon_make(priv, vif); |
| 1197 | |
| 1198 | return ret; |
| 1199 | } |