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