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