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