if_otusvar.h revision 1.6 1 1.6 christos /* $NetBSD: if_otusvar.h,v 1.6 2013/01/29 13:54:26 christos Exp $ */
2 1.1 christos /* $OpenBSD: if_otusreg.h,v 1.6 2009/04/06 18:17:01 damien Exp $ */
3 1.1 christos
4 1.1 christos /*-
5 1.1 christos * Copyright (c) 2009 Damien Bergamini <damien.bergamini (at) free.fr>
6 1.1 christos * Copyright (c) 2007-2008 Atheros Communications, Inc.
7 1.1 christos *
8 1.1 christos * Permission to use, copy, modify, and distribute this software for any
9 1.1 christos * purpose with or without fee is hereby granted, provided that the above
10 1.1 christos * copyright notice and this permission notice appear in all copies.
11 1.1 christos *
12 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 1.1 christos */
20 1.2 christos #ifndef _IF_OTUSVAR_H_
21 1.2 christos #define _IF_OTUSVAR_H_
22 1.1 christos
23 1.4 christos #ifdef EDCA_NUM_AC
24 1.4 christos #define HAVE_EDCA
25 1.4 christos #endif
26 1.4 christos
27 1.1 christos #ifndef HAVE_EDCA
28 1.1 christos /************************************************************
29 1.1 christos * XXX: This block belongs in sys/net80211/ieee80211_var.h.
30 1.1 christos */
31 1.1 christos /*
32 1.1 christos * EDCA AC parameters.
33 1.1 christos */
34 1.1 christos struct ieee80211_edca_ac_params {
35 1.1 christos u_int8_t ac_ecwmin; /* CWmin = 2^ECWmin - 1 */
36 1.1 christos u_int8_t ac_ecwmax; /* CWmax = 2^ECWmax - 1 */
37 1.1 christos u_int8_t ac_aifsn;
38 1.1 christos u_int16_t ac_txoplimit; /* 32TU */
39 1.1 christos u_int8_t ac_acm;
40 1.1 christos };
41 1.1 christos /************************************************************/
42 1.1 christos #endif /* ! HAVE_EDCA */
43 1.1 christos
44 1.1 christos #ifndef HAVE_EDCA
45 1.1 christos /************************************************************
46 1.1 christos * XXX: This block belongs in sys/net80211/ieee80211.h.
47 1.1 christos */
48 1.1 christos
49 1.1 christos /*
50 1.1 christos * EDCA Access Categories.
51 1.1 christos */
52 1.1 christos enum ieee80211_edca_ac {
53 1.1 christos EDCA_AC_BK = 1, /* Background */
54 1.1 christos EDCA_AC_BE = 0, /* Best Effort */
55 1.1 christos EDCA_AC_VI = 2, /* Video */
56 1.1 christos EDCA_AC_VO = 3 /* Voice */
57 1.1 christos };
58 1.1 christos #define EDCA_NUM_AC 4
59 1.1 christos
60 1.4 christos /* XXX: OpenBSD has more of these defined with the standard referenced */
61 1.4 christos #define IEEE80211_QOS_ACK_POLICY_NOACK 0x0020
62 1.4 christos #define IEEE80211_QOS_ACK_POLICY_MASK 0x0060
63 1.4 christos
64 1.1 christos static __inline int
65 1.1 christos ieee80211_has_addr4(const struct ieee80211_frame *wh)
66 1.1 christos {
67 1.1 christos return (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) ==
68 1.1 christos IEEE80211_FC1_DIR_DSTODS;
69 1.1 christos }
70 1.1 christos
71 1.1 christos static __inline int
72 1.1 christos ieee80211_has_qos(const struct ieee80211_frame *wh)
73 1.1 christos {
74 1.1 christos return (wh->i_fc[0] &
75 1.1 christos (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) ==
76 1.1 christos (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS);
77 1.1 christos }
78 1.1 christos
79 1.1 christos static __inline u_int16_t
80 1.1 christos ieee80211_get_qos(const struct ieee80211_frame *wh)
81 1.1 christos {
82 1.1 christos const u_int8_t *frm;
83 1.1 christos
84 1.1 christos if (ieee80211_has_addr4(wh))
85 1.1 christos frm = ((const struct ieee80211_qosframe_addr4 *)wh)->i_qos;
86 1.1 christos else
87 1.1 christos frm = ((const struct ieee80211_qosframe *)wh)->i_qos;
88 1.1 christos
89 1.1 christos return le16toh(*(const u_int16_t *)frm);
90 1.1 christos }
91 1.1 christos /************************************************************/
92 1.1 christos #endif /* ! HAVE_EDCA */
93 1.1 christos
94 1.1 christos /* Default EDCA parameters for when QoS is disabled. */
95 1.1 christos static const struct ieee80211_edca_ac_params otus_edca_def[] = {
96 1.1 christos { 4, 10, 3, 0, 0 },
97 1.1 christos { 4, 10, 7, 0, 0 },
98 1.1 christos { 3, 4, 2, 94, 0 },
99 1.1 christos { 2, 3, 2, 47, 0 }
100 1.1 christos };
101 1.1 christos
102 1.1 christos #define OTUS_TX_DATA_LIST_COUNT 8
103 1.1 christos #define OTUS_RX_DATA_LIST_COUNT 1
104 1.1 christos
105 1.1 christos #define OTUS_CMD_TIMEOUT 1000
106 1.1 christos #define OTUS_TX_TIMEOUT 1000
107 1.1 christos
108 1.1 christos #define OTUS_UID(aid) (IEEE80211_AID(aid) + 4)
109 1.1 christos
110 1.1 christos #define OTUS_MAX_TXCMDSZ 64
111 1.1 christos #define OTUS_RXBUFSZ (8 * 1024)
112 1.1 christos #define OTUS_TXBUFSZ (4 * 1024)
113 1.1 christos
114 1.1 christos #define OTUS_RIDX_CCK1 0
115 1.1 christos #define OTUS_RIDX_OFDM6 4
116 1.1 christos #define OTUS_RIDX_OFDM24 8
117 1.1 christos #define OTUS_RIDX_MAX 11
118 1.1 christos static const struct otus_rate {
119 1.1 christos uint8_t rate;
120 1.1 christos uint8_t mcs;
121 1.1 christos } otus_rates[] = {
122 1.1 christos { 2, 0x0 },
123 1.1 christos { 4, 0x1 },
124 1.1 christos { 11, 0x2 },
125 1.1 christos { 22, 0x3 },
126 1.1 christos { 12, 0xb },
127 1.1 christos { 18, 0xf },
128 1.1 christos { 24, 0xa },
129 1.1 christos { 36, 0xe },
130 1.1 christos { 48, 0x9 },
131 1.1 christos { 72, 0xd },
132 1.1 christos { 96, 0x8 },
133 1.1 christos { 108, 0xc }
134 1.1 christos };
135 1.1 christos
136 1.1 christos struct otus_rx_radiotap_header {
137 1.1 christos struct ieee80211_radiotap_header wr_ihdr;
138 1.1 christos uint8_t wr_flags;
139 1.1 christos uint8_t wr_rate;
140 1.1 christos uint16_t wr_chan_freq;
141 1.1 christos uint16_t wr_chan_flags;
142 1.1 christos uint8_t wr_antsignal;
143 1.1 christos } __packed;
144 1.1 christos
145 1.1 christos #define OTUS_RX_RADIOTAP_PRESENT \
146 1.1 christos (1 << IEEE80211_RADIOTAP_FLAGS | \
147 1.1 christos 1 << IEEE80211_RADIOTAP_RATE | \
148 1.1 christos 1 << IEEE80211_RADIOTAP_CHANNEL | \
149 1.1 christos 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
150 1.1 christos
151 1.1 christos struct otus_tx_radiotap_header {
152 1.1 christos struct ieee80211_radiotap_header wt_ihdr;
153 1.1 christos uint8_t wt_flags;
154 1.1 christos uint8_t wt_rate;
155 1.1 christos uint16_t wt_chan_freq;
156 1.1 christos uint16_t wt_chan_flags;
157 1.1 christos } __packed;
158 1.1 christos
159 1.1 christos #define OTUS_TX_RADIOTAP_PRESENT \
160 1.1 christos (1 << IEEE80211_RADIOTAP_FLAGS | \
161 1.1 christos 1 << IEEE80211_RADIOTAP_RATE | \
162 1.1 christos 1 << IEEE80211_RADIOTAP_CHANNEL)
163 1.1 christos
164 1.1 christos
165 1.1 christos struct otus_softc;
166 1.1 christos
167 1.1 christos struct otus_tx_cmd {
168 1.1 christos usbd_xfer_handle xfer;
169 1.1 christos uint8_t *buf;
170 1.1 christos void *odata;
171 1.1 christos uint16_t token;
172 1.1 christos uint8_t done;
173 1.1 christos };
174 1.1 christos
175 1.1 christos struct otus_rx_data {
176 1.1 christos struct otus_softc *sc;
177 1.1 christos usbd_xfer_handle xfer;
178 1.1 christos uint8_t *buf;
179 1.1 christos };
180 1.1 christos
181 1.1 christos struct otus_tx_data {
182 1.4 christos struct otus_softc *sc;
183 1.4 christos usbd_xfer_handle xfer;
184 1.4 christos uint8_t *buf;
185 1.4 christos TAILQ_ENTRY(otus_tx_data) next;
186 1.1 christos };
187 1.1 christos
188 1.1 christos struct otus_host_cmd {
189 1.1 christos void (*cb)(struct otus_softc *, void *);
190 1.1 christos uint8_t data[256];
191 1.1 christos };
192 1.1 christos
193 1.1 christos #define OTUS_HOST_CMD_RING_COUNT 32
194 1.1 christos struct otus_host_cmd_ring {
195 1.1 christos struct otus_host_cmd cmd[OTUS_HOST_CMD_RING_COUNT];
196 1.1 christos int cur;
197 1.1 christos int next;
198 1.1 christos int queued;
199 1.1 christos };
200 1.1 christos
201 1.1 christos struct otus_node {
202 1.1 christos struct ieee80211_node ni; /* must be first */
203 1.1 christos struct ieee80211_amrr_node amn;
204 1.1 christos uint8_t ridx[IEEE80211_RATE_MAXSIZE];
205 1.1 christos };
206 1.1 christos
207 1.1 christos struct otus_cmd_newstate {
208 1.1 christos enum ieee80211_state state;
209 1.1 christos int arg;
210 1.1 christos };
211 1.1 christos
212 1.1 christos struct otus_cmd_key {
213 1.1 christos struct ieee80211_key key;
214 1.1 christos uint16_t associd;
215 1.1 christos };
216 1.1 christos
217 1.1 christos struct otus_softc {
218 1.1 christos device_t sc_dev;
219 1.1 christos struct ieee80211com sc_ic;
220 1.1 christos struct ethercom sc_ec;
221 1.1 christos #define sc_if sc_ec.ec_if
222 1.1 christos int (*sc_newstate)(struct ieee80211com *,
223 1.1 christos enum ieee80211_state, int);
224 1.1 christos void (*sc_led_newstate)(struct otus_softc *);
225 1.1 christos
226 1.1 christos usbd_device_handle sc_udev;
227 1.1 christos usbd_interface_handle sc_iface;
228 1.1 christos
229 1.1 christos struct ar5416eeprom sc_eeprom;
230 1.1 christos uint8_t sc_capflags;
231 1.1 christos uint8_t sc_rxmask;
232 1.1 christos uint8_t sc_txmask;
233 1.1 christos
234 1.1 christos usbd_pipe_handle sc_data_tx_pipe;
235 1.1 christos usbd_pipe_handle sc_data_rx_pipe;
236 1.1 christos usbd_pipe_handle sc_cmd_tx_pipe;
237 1.1 christos usbd_pipe_handle sc_cmd_rx_pipe;
238 1.1 christos uint8_t *sc_ibuf;
239 1.1 christos
240 1.1 christos int sc_if_flags;
241 1.1 christos int sc_tx_timer;
242 1.1 christos int sc_fixed_ridx;
243 1.1 christos int sc_bb_reset;
244 1.1 christos
245 1.1 christos struct ieee80211_channel *sc_curchan;
246 1.1 christos
247 1.1 christos struct usb_task sc_task;
248 1.1 christos callout_t sc_scan_to;
249 1.1 christos callout_t sc_calib_to;
250 1.1 christos struct ieee80211_amrr sc_amrr;
251 1.1 christos
252 1.1 christos unsigned int sc_write_idx;
253 1.1 christos uint32_t sc_led_state;
254 1.1 christos
255 1.1 christos kmutex_t sc_cmd_mtx;
256 1.1 christos kmutex_t sc_task_mtx;
257 1.1 christos kmutex_t sc_write_mtx;
258 1.4 christos kmutex_t sc_tx_mtx;
259 1.1 christos
260 1.1 christos const uint32_t *sc_phy_vals;
261 1.1 christos
262 1.1 christos struct {
263 1.1 christos uint32_t reg;
264 1.1 christos uint32_t val;
265 1.1 christos } __packed sc_write_buf[AR_FW_MAX_WRITES];
266 1.1 christos
267 1.1 christos struct otus_host_cmd_ring sc_cmdq;
268 1.1 christos struct otus_tx_cmd sc_tx_cmd;
269 1.1 christos struct otus_tx_data sc_tx_data[OTUS_TX_DATA_LIST_COUNT];
270 1.4 christos TAILQ_HEAD(, otus_tx_data) sc_tx_free_list;
271 1.1 christos struct otus_rx_data sc_rx_data[OTUS_RX_DATA_LIST_COUNT];
272 1.1 christos
273 1.1 christos struct bpf_if * sc_drvbpf;
274 1.1 christos union {
275 1.1 christos struct otus_rx_radiotap_header th;
276 1.1 christos uint8_t pad[64];
277 1.1 christos } sc_rxtapu;
278 1.1 christos #define sc_rxtap sc_rxtapu.th
279 1.1 christos int sc_rxtap_len;
280 1.1 christos union {
281 1.1 christos struct otus_tx_radiotap_header th;
282 1.1 christos uint8_t pad[64];
283 1.1 christos } sc_txtapu;
284 1.1 christos #define sc_txtap sc_txtapu.th
285 1.1 christos int sc_txtap_len;
286 1.4 christos
287 1.4 christos uint8_t sc_rx_error_msk;
288 1.4 christos int sc_dying;
289 1.1 christos };
290 1.2 christos
291 1.2 christos #endif /* _IF_OTUSVAR_H_ */
292