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