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