1 /*
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD$
33 */
34
35 struct wi_counters {
36 u_int32_t wi_tx_unicast_frames;
37 u_int32_t wi_tx_multicast_frames;
38 u_int32_t wi_tx_fragments;
39 u_int32_t wi_tx_unicast_octets;
40 u_int32_t wi_tx_multicast_octets;
41 u_int32_t wi_tx_deferred_xmits;
42 u_int32_t wi_tx_single_retries;
43 u_int32_t wi_tx_multi_retries;
44 u_int32_t wi_tx_retry_limit;
45 u_int32_t wi_tx_discards;
46 u_int32_t wi_rx_unicast_frames;
47 u_int32_t wi_rx_multicast_frames;
48 u_int32_t wi_rx_fragments;
49 u_int32_t wi_rx_unicast_octets;
50 u_int32_t wi_rx_multicast_octets;
51 u_int32_t wi_rx_fcs_errors;
52 u_int32_t wi_rx_discards_nobuf;
53 u_int32_t wi_tx_discards_wrong_sa;
54 u_int32_t wi_rx_WEP_cant_decrypt;
55 u_int32_t wi_rx_msg_in_msg_frags;
56 u_int32_t wi_rx_msg_in_bad_msg_frags;
57 };
58
59 struct wi_softc {
60 struct arpcom arpcom;
61 struct ifmedia ifmedia;
62 int wi_unit;
63 bus_space_handle_t wi_bhandle;
64 bus_space_tag_t wi_btag;
65 int wi_tx_data_id;
66 int wi_tx_mgmt_id;
67 int wi_gone;
68 int wi_if_flags;
69 u_int16_t wi_ptype;
70 u_int16_t wi_portnum;
71 u_int16_t wi_max_data_len;
72 u_int16_t wi_rts_thresh;
73 u_int16_t wi_ap_density;
74 u_int16_t wi_tx_rate;
75 u_int16_t wi_create_ibss;
76 u_int16_t wi_channel;
77 u_int16_t wi_pm_enabled;
78 u_int16_t wi_max_sleep;
79 char wi_node_name[32];
80 char wi_net_name[32];
81 char wi_ibss_name[32];
82 u_int8_t wi_txbuf[1536];
83 struct wi_counters wi_stats;
84 struct callout_handle wi_stat_ch;
85 };
86
87 #define WI_TIMEOUT 65536
88
89 #define WI_PORT0 0
90 #define WI_PORT1 1
91 #define WI_PORT2 2
92 #define WI_PORT3 3
93 #define WI_PORT4 4
94 #define WI_PORT5 5
95
96 /* Default port: 0 (only 0 exists on stations) */
97 #define WI_DEFAULT_PORT (WI_PORT0 << 8)
98
99 /* Default TX rate: 2Mbps, auto fallback */
100 #define WI_DEFAULT_TX_RATE 3
101
102 /* Default network name: ANY */
103 #define WI_DEFAULT_NETNAME "ANY"
104
105 #define WI_DEFAULT_AP_DENSITY 1
106
107 #define WI_DEFAULT_RTS_THRESH 2347
108
109 #define WI_DEFAULT_DATALEN 2304
110
111 #define WI_DEFAULT_CREATE_IBSS 0
112
113 #define WI_DEFAULT_PM_ENABLED 0
114
115 #define WI_DEFAULT_MAX_SLEEP 100
116
117 #define WI_DEFAULT_NODENAME "FreeBSD WaveLAN/IEEE node"
118
119 #define WI_DEFAULT_IBSS "FreeBSD IBSS"
120
121 #define WI_DEFAULT_CHAN 3
122
123 /*
124 * register space access macros
125 */
126 #define CSR_WRITE_4(sc, reg, val) \
127 bus_space_write_4(sc->wi_btag, sc->wi_bhandle, reg, val)
128 #define CSR_WRITE_2(sc, reg, val) \
129 bus_space_write_2(sc->wi_btag, sc->wi_bhandle, reg, val)
130 #define CSR_WRITE_1(sc, reg, val) \
131 bus_space_write_1(sc->wi_btag, sc->wi_bhandle, reg, val)
132
133 #define CSR_READ_4(sc, reg) \
134 bus_space_read_4(sc->wi_btag, sc->wi_bhandle, reg)
135 #define CSR_READ_2(sc, reg) \
136 bus_space_read_2(sc->wi_btag, sc->wi_bhandle, reg)
137 #define CSR_READ_1(sc, reg) \
138 bus_space_read_1(sc->wi_btag, sc->wi_bhandle, reg)
139
140 /*
141 * The WaveLAN/IEEE cards contain an 802.11 MAC controller which Lucent
142 * calls 'Hermes.' In typical fashion, getting documentation about this
143 * controller is about as easy as squeezing blood from a stone. Here
144 * is more or less what I know:
145 *
146 * - The Hermes controller is firmware driven, and the host interacts
147 * with the Hermes via a firmware interface, which can change.
148 *
149 * - The Hermes is described in a document called: "Hermes Firmware
150 * WaveLAN/IEEE Station Functions," document #010245, which of course
151 * Lucent will not release without an NDA.
152 *
153 * - Lucent has created a library called HCF (Hardware Control Functions)
154 * though which it wants developers to interact with the card. The HCF
155 * is needlessly complex, ill conceived and badly documented. Actually,
156 * the comments in the HCP code itself aren't bad, but the publically
157 * available manual that comes with it is awful, probably due largely to
158 * the fact that it has been emasculated in order to hide information
159 * that Lucent wants to keep proprietary. The purpose of the HCF seems
160 * to be to insulate the driver programmer from the Hermes itself so that
161 * Lucent has an excuse not to release programming in for it.
162 *
163 * - Lucent only makes available documentation and code for 'HCF Light'
164 * which is a stripped down version of HCF with certain features not
165 * implemented, most notably support for 802.11 frames.
166 *
167 * - The HCF code which I have seen blows goats. Whoever decided to
168 * use a 132 column format should be shot.
169 *
170 * Rather than actually use the Lucent HCF library, I have stripped all
171 * the useful information from it and used it to create a driver in the
172 * usual BSD form. Note: I don't want to hear anybody whining about the
173 * fact that the Lucent code is GPLed and mine isn't. I did not actually
174 * put any of Lucent's code in this driver: I only used it as a reference
175 * to obtain information about the underlying hardware. The Hermes
176 * programming interface is not GPLed, so bite me.
177 */
178
179 /*
180 * Size of Hermes I/O space.
181 */
182 #define WI_IOSIZ 0x40
183
184 /*
185 * Hermes register definitions and what little I know about them.
186 */
187
188 /* Hermes command/status registers. */
189 #define WI_COMMAND 0x00
190 #define WI_PARAM0 0x02
191 #define WI_PARAM1 0x04
192 #define WI_PARAM2 0x06
193 #define WI_STATUS 0x08
194 #define WI_RESP0 0x0A
195 #define WI_RESP1 0x0C
196 #define WI_RESP2 0x0E
197
198 /* Command register values. */
199 #define WI_CMD_BUSY 0x8000 /* busy bit */
200 #define WI_CMD_INI 0x0000 /* initialize */
201 #define WI_CMD_ENABLE 0x0001 /* enable */
202 #define WI_CMD_DISABLE 0x0002 /* disable */
203 #define WI_CMD_DIAG 0x0003
204 #define WI_CMD_ALLOC_MEM 0x000A /* allocate NIC memory */
205 #define WI_CMD_TX 0x000B /* transmit */
206 #define WI_CMD_NOTIFY 0x0010
207 #define WI_CMD_INQUIRE 0x0011
208 #define WI_CMD_ACCESS 0x0021
209 #define WI_CMD_PROGRAM 0x0022
210
211 #define WI_CMD_CODE_MASK 0x003F
212
213 /*
214 * Reclaim qualifier bit, applicable to the
215 * TX and INQUIRE commands.
216 */
217 #define WI_RECLAIM 0x0100 /* reclaim NIC memory */
218
219 /*
220 * ACCESS command qualifier bits.
221 */
222 #define WI_ACCESS_READ 0x0000
223 #define WI_ACCESS_WRITE 0x0100
224
225 /*
226 * PROGRAM command qualifier bits.
227 */
228 #define WI_PROGRAM_DISABLE 0x0000
229 #define WI_PROGRAM_ENABLE_RAM 0x0100
230 #define WI_PROGRAM_ENABLE_NVRAM 0x0200
231 #define WI_PROGRAM_NVRAM 0x0300
232
233 /* Status register values */
234 #define WI_STAT_CMD_CODE 0x003F
235 #define WI_STAT_DIAG_ERR 0x0100
236 #define WI_STAT_INQ_ERR 0x0500
237 #define WI_STAT_CMD_RESULT 0x7F00
238
239 /* memory handle management registers */
240 #define WI_INFO_FID 0x10
241 #define WI_RX_FID 0x20
242 #define WI_ALLOC_FID 0x22
243 #define WI_TX_CMP_FID 0x24
244
245 /*
246 * Buffer Access Path (BAP) registers.
247 * These are I/O channels. I believe you can use each one for
248 * any desired purpose independently of the other. In general
249 * though, we use BAP1 for reading and writing LTV records and
250 * reading received data frames, and BAP0 for writing transmit
251 * frames. This is a convention though, not a rule.
252 */
253 #define WI_SEL0 0x18
254 #define WI_SEL1 0x1A
255 #define WI_OFF0 0x1C
256 #define WI_OFF1 0x1E
257 #define WI_DATA0 0x36
258 #define WI_DATA1 0x38
259 #define WI_BAP0 WI_DATA0
260 #define WI_BAP1 WI_DATA1
261
262 #define WI_OFF_BUSY 0x8000
263 #define WI_OFF_ERR 0x4000
264 #define WI_OFF_DATAOFF 0x0FFF
265
266 /* Event registers */
267 #define WI_EVENT_STAT 0x30 /* Event status */
268 #define WI_INT_EN 0x32 /* Interrupt enable/disable */
269 #define WI_EVENT_ACK 0x34 /* Ack event */
270
271 /* Events */
272 #define WI_EV_TICK 0x8000 /* aux timer tick */
273 #define WI_EV_RES 0x4000 /* controller h/w error (time out) */
274 #define WI_EV_INFO_DROP 0x2000 /* no RAM to build unsolicited frame */
275 #define WI_EV_NO_CARD 0x0800 /* card removed (hunh?) */
276 #define WI_EV_DUIF_RX 0x0400 /* wavelan management packet received */
277 #define WI_EV_INFO 0x0080 /* async info frame */
278 #define WI_EV_CMD 0x0010 /* command completed */
279 #define WI_EV_ALLOC 0x0008 /* async alloc/reclaim completed */
280 #define WI_EV_TX_EXC 0x0004 /* async xmit completed with failure */
281 #define WI_EV_TX 0x0002 /* async xmit completed succesfully */
282 #define WI_EV_RX 0x0001 /* async rx completed */
283
284 #define WI_INTRS \
285 (WI_EV_RX|WI_EV_TX|WI_EV_TX_EXC|WI_EV_ALLOC|WI_EV_INFO|WI_EV_INFO_DROP)
286
287 /* Host software registers */
288 #define WI_SW0 0x28
289 #define WI_SW1 0x2A
290 #define WI_SW2 0x2C
291 #define WI_SW3 0x2E
292
293 #define WI_CNTL 0x14
294
295 #define WI_CNTL_AUX_ENA 0xC000
296 #define WI_CNTL_AUX_ENA_STAT 0xC000
297 #define WI_CNTL_AUX_DIS_STAT 0x0000
298 #define WI_CNTL_AUX_ENA_CNTL 0x8000
299 #define WI_CNTL_AUX_DIS_CNTL 0x4000
300
301 #define WI_AUX_PAGE 0x3A
302 #define WI_AUX_OFFSET 0x3C
303 #define WI_AUX_DATA 0x3E
304
305 /*
306 * One form of communication with the Hermes is with what Lucent calls
307 * LTV records, where LTV stands for Length, Type and Value. The length
308 * and type are 16 bits and are in native byte order. The value is in
309 * multiples of 16 bits and is in little endian byte order.
310 */
311 struct wi_ltv_gen {
312 u_int16_t wi_len;
313 u_int16_t wi_type;
314 u_int16_t wi_val;
315 };
316
317 struct wi_ltv_str {
318 u_int16_t wi_len;
319 u_int16_t wi_type;
320 u_int16_t wi_str[17];
321 };
322
323 #define WI_SETVAL(recno, val) \
324 do { \
325 struct wi_ltv_gen g; \
326 \
327 g.wi_len = 2; \
328 g.wi_type = recno; \
329 g.wi_val = val; \
330 wi_write_record(sc, &g); \
331 } while (0)
332
333 #define WI_SETSTR(recno, str) \
334 do { \
335 struct wi_ltv_str s; \
336 int l; \
337 \
338 l = (strlen(str) + 1) & ~0x1; \
339 bzero((char *)&s, sizeof(s)); \
340 s.wi_len = (l / 2) + 2; \
341 s.wi_type = recno; \
342 s.wi_str[0] = strlen(str); \
343 bcopy(str, (char *)&s.wi_str[1], strlen(str)); \
344 wi_write_record(sc, (struct wi_ltv_gen *)&s); \
345 } while (0)
346
347 /*
348 * Download buffer location and length (0xFD01).
349 */
350 #define WI_RID_DNLD_BUF 0xFD01
351 struct wi_ltv_dnld_buf {
352 u_int16_t wi_len;
353 u_int16_t wi_type;
354 u_int16_t wi_buf_pg; /* page addr of intermediate dl buf*/
355 u_int16_t wi_buf_off; /* offset of idb */
356 u_int16_t wi_buf_len; /* len of idb */
357 };
358
359 /*
360 * Mem sizes (0xFD02).
361 */
362 #define WI_RID_MEMSZ 0xFD02
363 struct wi_ltv_memsz {
364 u_int16_t wi_len;
365 u_int16_t wi_type;
366 u_int16_t wi_mem_ram;
367 u_int16_t wi_mem_nvram;
368 };
369
370 /*
371 * List of intended regulatory domains (0xFD11).
372 */
373 #define WI_RID_DOMAINS 0xFD11
374 struct wi_ltv_domains {
375 u_int16_t wi_len;
376 u_int16_t wi_type;
377 u_int16_t wi_domains[6];
378 };
379
380 /*
381 * CIS struct (0xFD13).
382 */
383 #define WI_RID_CIS 0xFD13
384 struct wi_ltv_cis {
385 u_int16_t wi_len;
386 u_int16_t wi_type;
387 u_int16_t wi_cis[240];
388 };
389
390 /*
391 * Communications quality (0xFD43).
392 */
393 #define WI_RID_COMMQUAL 0xFD43
394 struct wi_ltv_commqual {
395 u_int16_t wi_len;
396 u_int16_t wi_type;
397 u_int16_t wi_coms_qual;
398 u_int16_t wi_sig_lvl;
399 u_int16_t wi_noise_lvl;
400 };
401
402 /*
403 * Actual system scale thresholds (0xFD46).
404 */
405 #define WI_RID_SYSTEM_SCALE 0xFC06
406 #define WI_RID_SCALETHRESH 0xFD46
407 struct wi_ltv_scalethresh {
408 u_int16_t wi_len;
409 u_int16_t wi_type;
410 u_int16_t wi_energy_detect;
411 u_int16_t wi_carrier_detect;
412 u_int16_t wi_defer;
413 u_int16_t wi_cell_search;
414 u_int16_t wi_out_of_range;
415 u_int16_t wi_delta_snr;
416 };
417
418 /*
419 * PCF info struct (0xFD87).
420 */
421 #define WI_RID_PCF 0xFD87
422 struct wi_ltv_pcf {
423 u_int16_t wi_len;
424 u_int16_t wi_type;
425 u_int16_t wi_energy_detect;
426 u_int16_t wi_carrier_detect;
427 u_int16_t wi_defer;
428 u_int16_t wi_cell_search;
429 u_int16_t wi_range;
430 };
431
432 /*
433 * Connection control characteristics.
434 * 1 == Basic Service Set (BSS)
435 * 2 == Wireless Distribudion System (WDS)
436 * 3 == Pseudo IBSS
437 */
438 #define WI_RID_PORTTYPE 0xFC00
439 #define WI_PORTTYPE_BSS 0x1
440 #define WI_PORTTYPE_WDS 0x2
441 #define WI_PORTTYPE_ADHOC 0x3
442
443 /*
444 * Mac addresses.
445 */
446 #define WI_RID_MAC_NODE 0xFC01
447 #define WI_RID_MAC_WDS 0xFC08
448 struct wi_ltv_macaddr {
449 u_int16_t wi_len;
450 u_int16_t wi_type;
451 u_int16_t wi_mac_addr[3];
452 };
453
454 /*
455 * Station set identification (SSID).
456 */
457 #define WI_RID_DESIRED_SSID 0xFC02
458 #define WI_RID_OWN_SSID 0xFC04
459 struct wi_ltv_ssid {
460 u_int16_t wi_len;
461 u_int16_t wi_type;
462 u_int16_t wi_id[17];
463 };
464
465 /*
466 * Set communications channel (radio frequency).
467 */
468 #define WI_RID_OWN_CHNL 0xFC03
469
470 /*
471 * Frame data size.
472 */
473 #define WI_RID_MAX_DATALEN 0xFC07
474
475 /*
476 * ESS power management enable
477 */
478 #define WI_RID_PM_ENABLED 0xFC09
479
480 /*
481 * ESS max PM sleep internal
482 */
483 #define WI_RID_MAX_SLEEP 0xFC0C
484
485 /*
486 * Set our station name.
487 */
488 #define WI_RID_NODENAME 0xFC0E
489 struct wi_ltv_nodename {
490 u_int16_t wi_len;
491 u_int16_t wi_type;
492 u_int16_t wi_nodename[17];
493 };
494
495 /*
496 * Multicast addresses to be put in filter. We're
497 * allowed up to 16 addresses in the filter.
498 */
499 #define WI_RID_MCAST 0xFC80
500 struct wi_ltv_mcast {
501 u_int16_t wi_len;
502 u_int16_t wi_type;
503 struct ether_addr wi_mcast[16];
504 };
505
506 /*
507 * Create IBSS.
508 */
509 #define WI_RID_CREATE_IBSS 0xFC81
510
511 #define WI_RID_FRAG_THRESH 0xFC82
512 #define WI_RID_RTS_THRESH 0xFC83
513
514 /*
515 * TX rate control
516 * 0 == Fixed 1mbps
517 * 1 == Fixed 2mbps
518 * 2 == auto fallback
519 */
520 #define WI_RID_TX_RATE 0xFC84
521
522 /*
523 * promiscuous mode.
524 */
525 #define WI_RID_PROMISC 0xFC85
526
527 /*
528 * Auxiliary Timer tick interval
529 */
530 #define WI_RID_TICK_TIME 0xFCE0
531
532 /*
533 * Information frame types.
534 */
535 #define WI_INFO_NOTIFY 0xF000 /* Handover address */
536 #define WI_INFO_COUNTERS 0xF100 /* Statistics counters */
537 #define WI_INFO_SCAN_RESULTS 0xF101 /* Scan results */
538 #define WI_INFO_LINK_STAT 0xF200 /* Link status */
539 #define WI_INFO_ASSOC_STAT 0xF201 /* Association status */
540
541 /*
542 * Hermes transmit/receive frame structure
543 */
544 struct wi_frame {
545 u_int16_t wi_status; /* 0x00 */
546 u_int16_t wi_rsvd0; /* 0x02 */
547 u_int16_t wi_rsvd1; /* 0x04 */
548 u_int16_t wi_q_info; /* 0x06 */
549 u_int16_t wi_rsvd2; /* 0x08 */
550 u_int16_t wi_rsvd3; /* 0x0A */
551 u_int16_t wi_tx_ctl; /* 0x0C */
552 u_int16_t wi_frame_ctl; /* 0x0E */
553 u_int16_t wi_id; /* 0x10 */
554 u_int8_t wi_addr1[6]; /* 0x12 */
555 u_int8_t wi_addr2[6]; /* 0x18 */
556 u_int8_t wi_addr3[6]; /* 0x1E */
557 u_int16_t wi_seq_ctl; /* 0x24 */
558 u_int8_t wi_addr4[6]; /* 0x26 */
559 u_int16_t wi_dat_len; /* 0x2C */
560 u_int8_t wi_dst_addr[6]; /* 0x2E */
561 u_int8_t wi_src_addr[6]; /* 0x34 */
562 u_int16_t wi_len; /* 0x3A */
563 u_int16_t wi_dat[3]; /* 0x3C */ /* SNAP header */
564 u_int16_t wi_type; /* 0x42 */
565 };
566
567 #define WI_802_3_OFFSET 0x2E
568 #define WI_802_11_OFFSET 0x44
569 #define WI_802_11_OFFSET_RAW 0x3C
570
571 #define WI_STAT_BADCRC 0x0001
572 #define WI_STAT_UNDECRYPTABLE 0x0002
573 #define WI_STAT_ERRSTAT 0x0003
574 #define WI_STAT_MAC_PORT 0x0700
575 #define WI_STAT_1042 0x2000 /* RFC1042 encoded */
576 #define WI_STAT_TUNNEL 0x4000 /* Bridge-tunnel encoded */
577 #define WI_STAT_WMP_MSG 0x6000 /* WaveLAN-II management protocol */
578 #define WI_RXSTAT_MSG_TYPE 0xE000
579
580 #define WI_ENC_TX_802_3 0x00
581 #define WI_ENC_TX_802_11 0x11
582 #define WI_ENC_TX_E_II 0x0E
583
584 #define WI_ENC_TX_1042 0x00
585 #define WI_ENC_TX_TUNNEL 0xF8
586
587 #define WI_TXCNTL_MACPORT 0x00FF
588 #define WI_TXCNTL_STRUCTTYPE 0xFF00
589
590 /*
591 * SNAP (sub-network access protocol) constants for transmission
592 * of IP datagrams over IEEE 802 networks, taken from RFC1042.
593 * We need these for the LLC/SNAP header fields in the TX/RX frame
594 * structure.
595 */
596 #define WI_SNAP_K1 0xaa /* assigned global SAP for SNAP */
597 #define WI_SNAP_K2 0x00
598 #define WI_SNAP_CONTROL 0x03 /* unnumbered information format */
599 #define WI_SNAP_WORD0 (WI_SNAP_K1 | (WI_SNAP_K1 << 8))
600 #define WI_SNAP_WORD1 (WI_SNAP_K2 | (WI_SNAP_CONTROL << 8))
601 #define WI_SNAPHDR_LEN 0x6
Cache object: eb696c99e9ae16fef5607d6d55eca984
|