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