1 /**************************************************************************
2 Etherboot - BOOTP/TFTP Bootstrap Program
3 Prism2 NIC driver for Etherboot
5 Written by Michael Brown of Fen Systems Ltd
7 ***************************************************************************/
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2, or (at
13 * your option) any later version.
16 /* to get some global routines like printf */
17 #include "etherboot.h"
18 /* to get the interface to the body of the program */
20 /* to get the PCI support functions, if this is a PCI NIC */
25 * Leave blank in order to connect to any available SSID
28 static const char hardcoded_ssid[] = "";
31 * Maximum number of info packets to wait for on a join attempt.
32 * Some APs (including the Linksys WAP11) will send a "you are disconnected" packet
33 * before sending the "you are connected" packet, if the card has previously been
36 * 2 is probably a sensible value, but YMMV.
39 #define MAX_JOIN_INFO_COUNT 2
42 * Type of Prism2 interface to support
43 * If not already defined, select PLX
46 #define WLAN_HOSTIF WLAN_PLX
50 * Include wlan_compat, p80211 and hfa384x header files from Linux Prism2 driver
51 * We need to hack some defines in order to avoid compiling kernel-specific routines
54 #define __LINUX_WLAN__
57 #include "wlan_compat.h"
58 #include "p80211hdr.h"
60 #define BAP_TIMEOUT ( 5000 )
63 * A few hacks to make the coding environment more Linux-like. This makes it somewhat
64 * quicker to convert code from the Linux Prism2 driver.
68 #define __le16_to_cpu(x) (x)
69 #define __le32_to_cpu(x) (x)
70 #define __cpu_to_le16(x) (x)
71 #define __cpu_to_le32(x) (x)
74 * PLX9052 PCI register offsets
75 * Taken from PLX9052 datasheet available from http://www.plxtech.com/download/9052/databook/9052db-20.pdf
78 #define PLX_LOCAL_CONFIG_REGISTER_BASE ( PCI_BASE_ADDRESS_1 )
79 #define PLX_LOCAL_ADDRESS_SPACE_0_BASE ( PCI_BASE_ADDRESS_2 )
80 #define PLX_LOCAL_ADDRESS_SPACE_1_BASE ( PCI_BASE_ADDRESS_3 )
81 #define PLX_LOCAL_ADDRESS_SPACE_2_BASE ( PCI_BASE_ADDRESS_4 )
82 #define PLX_LOCAL_ADDRESS_SPACE_3_BASE ( PCI_BASE_ADDRESS_5 )
84 #define PRISM2_PLX_ATTR_MEM_BASE ( PLX_LOCAL_ADDRESS_SPACE_0_BASE )
85 #define PRISM2_PLX_IO_BASE ( PLX_LOCAL_ADDRESS_SPACE_1_BASE )
87 #define PRISM2_PCI_MEM_BASE ( PCI_BASE_ADDRESS_0 )
91 * Taken from cistpl.h in pcmcia-cs
94 #define CISTPL_VERS_1 ( 0x15 )
95 #define CISTPL_END ( 0xff )
97 #define CIS_STEP ( 2 )
98 #define CISTPL_HEADER_LEN ( 2 * CIS_STEP )
99 #define CISTPL_LEN_OFF ( 1 * CIS_STEP )
100 #define CISTPL_VERS_1_STR_OFF ( 4 * CIS_STEP )
104 * Taken from prism2sta.c in linux-wlan-ng
107 #define COR_OFFSET ( 0x3e0 ) /* COR attribute offset of Prism2 PC card */
108 #define COR_VALUE ( 0x41 ) /* Enable PC card with irq in level trigger (but interrupts disabled) */
110 /* NIC specific static variables */
112 /* The hfa384x_t structure is used extensively in the Linux driver but is ifdef'd out in our include since __KERNEL__ is not defined.
113 * This is a dummy version that contains only the fields we are interested in.
116 typedef struct hfa384x
121 UINT16 status; /* in host order */
122 UINT16 resp0; /* in host order */
123 UINT16 resp1; /* in host order */
124 UINT16 resp2; /* in host order */
125 UINT8 bssid[WLAN_BSSID_LEN];
128 /* The global instance of the hardware (i.e. where we store iobase and membase, in the absence of anywhere better to put them */
129 static hfa384x_t hw_global = {
130 0, 0, 0, 0, 0, 0, 0, {0,0,0,0,0,0}
134 * 802.11 headers in addition to those in hfa384x_tx_frame_t (LLC and SNAP)
135 * Taken from p80211conv.h
138 typedef struct wlan_llc
140 UINT8 dsap __WLAN_ATTRIB_PACK__;
141 UINT8 ssap __WLAN_ATTRIB_PACK__;
142 UINT8 ctl __WLAN_ATTRIB_PACK__;
143 } __WLAN_ATTRIB_PACK__ wlan_llc_t;
145 static const wlan_llc_t wlan_llc_snap = { 0xaa, 0xaa, 0x03 }; /* LLC header indicating SNAP (?) */
147 #define WLAN_IEEE_OUI_LEN 3
148 typedef struct wlan_snap
150 UINT8 oui[WLAN_IEEE_OUI_LEN] __WLAN_ATTRIB_PACK__;
151 UINT16 type __WLAN_ATTRIB_PACK__;
152 } __WLAN_ATTRIB_PACK__ wlan_snap_t;
154 typedef struct wlan_80211hdr
161 * Function prototypes
165 * Hardware-level hfa384x functions
166 * These are based on the ones in hfa384x.h (which are ifdef'd out since __KERNEL__ is not defined).
167 * Basically, these functions are the result of hand-evaluating all the ifdefs and defines in the hfa384x.h versions.
170 /* Retrieve the value of one of the MAC registers. */
171 static inline UINT16 hfa384x_getreg( hfa384x_t *hw, UINT reg )
173 #if (WLAN_HOSTIF == WLAN_PLX)
174 return inw ( hw->iobase + reg );
175 #elif (WLAN_HOSTIF == WLAN_PCI)
176 return readw ( hw->membase + reg );
180 /* Set the value of one of the MAC registers. */
181 static inline void hfa384x_setreg( hfa384x_t *hw, UINT16 val, UINT reg )
183 #if (WLAN_HOSTIF == WLAN_PLX)
184 outw ( val, hw->iobase + reg );
185 #elif (WLAN_HOSTIF == WLAN_PCI)
186 writew ( val, hw->membase + reg );
193 * Etherboot is i386 only, so swap and noswap are the same...
195 static inline UINT16 hfa384x_getreg_noswap( hfa384x_t *hw, UINT reg )
197 return hfa384x_getreg ( hw, reg );
199 static inline void hfa384x_setreg_noswap( hfa384x_t *hw, UINT16 val, UINT reg )
201 hfa384x_setreg ( hw, val, reg );
205 * Low-level hfa384x functions
206 * These are based on the ones in hfa384x.c, modified to work in the Etherboot environment.
212 * Waits for availability of the Command register, then
213 * issues the given command. Then polls the Evstat register
214 * waiting for command completion.
216 * hw device structure
217 * cmd Command in host order
218 * parm0 Parameter0 in host order
219 * parm1 Parameter1 in host order
220 * parm2 Parameter2 in host order
223 * >0 command indicated error, Status and Resp0-2 are
226 static int hfa384x_docmd_wait( hfa384x_t *hw, UINT16 cmd, UINT16 parm0, UINT16 parm1, UINT16 parm2)
231 /* wait for the busy bit to clear */
233 reg = hfa384x_getreg(hw, HFA384x_CMD);
234 while ( HFA384x_CMD_ISBUSY(reg) && (counter < 10) ) {
235 reg = hfa384x_getreg(hw, HFA384x_CMD);
239 if (HFA384x_CMD_ISBUSY(reg)) {
240 printf("hfa384x_cmd timeout(1), reg=0x%0hx.\n", reg);
244 /* busy bit clear, write command */
245 hfa384x_setreg(hw, parm0, HFA384x_PARAM0);
246 hfa384x_setreg(hw, parm1, HFA384x_PARAM1);
247 hfa384x_setreg(hw, parm2, HFA384x_PARAM2);
249 hfa384x_setreg(hw, cmd, HFA384x_CMD);
251 /* Now wait for completion */
253 reg = hfa384x_getreg(hw, HFA384x_EVSTAT);
254 /* Initialization is the problem. It takes about
255 100ms. "normal" commands are typically is about
256 200-400 us (I've never seen less than 200). Longer
257 is better so that we're not hammering the bus. */
258 while ( !HFA384x_EVSTAT_ISCMD(reg) && (counter < 5000)) {
259 reg = hfa384x_getreg(hw, HFA384x_EVSTAT);
263 if ( ! HFA384x_EVSTAT_ISCMD(reg) ) {
264 printf("hfa384x_cmd timeout(2), reg=0x%0hx.\n", reg);
268 /* Read status and response */
269 hw->status = hfa384x_getreg(hw, HFA384x_STATUS);
270 hw->resp0 = hfa384x_getreg(hw, HFA384x_RESP0);
271 hw->resp1 = hfa384x_getreg(hw, HFA384x_RESP1);
272 hw->resp2 = hfa384x_getreg(hw, HFA384x_RESP2);
273 hfa384x_setreg(hw, HFA384x_EVACK_CMD, HFA384x_EVACK);
274 return HFA384x_STATUS_RESULT_GET(hw->status);
278 * Prepare BAP for access. Assigns FID and RID, sets offset register
279 * and waits for BAP to become available.
282 * hw device structure
283 * id FID or RID, destined for the select register (host order)
284 * offset An _even_ offset into the buffer for the given FID/RID.
288 static int hfa384x_prepare_bap(hfa384x_t *hw, UINT16 id, UINT16 offset)
294 /* Validate offset, buf, and len */
295 if ( (offset > HFA384x_BAP_OFFSET_MAX) || (offset % 2) ) {
298 /* Write fid/rid and offset */
299 hfa384x_setreg(hw, id, HFA384x_SELECT0);
301 hfa384x_setreg(hw, offset, HFA384x_OFFSET0);
302 /* Wait for offset[busy] to clear (see BAP_TIMEOUT) */
305 reg = hfa384x_getreg(hw, HFA384x_OFFSET0);
306 if ( i > 0 ) udelay(2);
308 } while ( i < BAP_TIMEOUT && HFA384x_OFFSET_ISBUSY(reg));
309 if ( i >= BAP_TIMEOUT ) {
312 } else if ( HFA384x_OFFSET_ISERR(reg) ){
321 * Copy data from BAP to memory.
324 * hw device structure
325 * id FID or RID, destined for the select register (host order)
326 * offset An _even_ offset into the buffer for the given FID/RID.
327 * buf ptr to array of bytes
328 * len length of data to transfer in bytes
332 static int hfa384x_copy_from_bap(hfa384x_t *hw, UINT16 id, UINT16 offset,
336 UINT8 *d = (UINT8*)buf;
341 result = hfa384x_prepare_bap ( hw, id, offset );
343 /* Read even(len) buf contents from data reg */
344 for ( i = 0; i < (len & 0xfffe); i+=2 ) {
345 *(UINT16*)(&(d[i])) = hfa384x_getreg_noswap(hw, HFA384x_DATA0);
347 /* If len odd, handle last byte */
349 reg = hfa384x_getreg_noswap(hw, HFA384x_DATA0);
350 d[len-1] = ((UINT8*)(®))[0];
354 printf ( "copy_from_bap(%#hx, %#hx, %d) failed, result=%#hx\n", id, offset, len, result);
360 * Copy data from memory to BAP.
363 * hw device structure
364 * id FID or RID, destined for the select register (host order)
365 * offset An _even_ offset into the buffer for the given FID/RID.
366 * buf ptr to array of bytes
367 * len length of data to transfer in bytes
371 static int hfa384x_copy_to_bap(hfa384x_t *hw, UINT16 id, UINT16 offset,
375 UINT8 *d = (UINT8*)buf;
380 result = hfa384x_prepare_bap ( hw, id, offset );
382 /* Write even(len) buf contents to data reg */
383 for ( i = 0; i < (len & 0xfffe); i+=2 ) {
384 hfa384x_setreg_noswap(hw, *(UINT16*)(&(d[i])), HFA384x_DATA0);
386 /* If len odd, handle last byte */
388 savereg = hfa384x_getreg_noswap(hw, HFA384x_DATA0);
389 result = hfa384x_prepare_bap ( hw, id, offset + (len & 0xfffe) );
391 ((UINT8*)(&savereg))[0] = d[len-1];
392 hfa384x_setreg_noswap(hw, savereg, HFA384x_DATA0);
397 printf ( "copy_to_bap(%#hx, %#hx, %d) failed, result=%#hx\n", id, offset, len, result);
403 * Request a given record to be copied to/from the record buffer.
406 * hw device structure
407 * write [0|1] copy the record buffer to the given
408 * configuration record. (host order)
409 * rid RID of the record to read/write. (host order)
414 static inline int hfa384x_cmd_access(hfa384x_t *hw, UINT16 write, UINT16 rid)
416 return hfa384x_docmd_wait(hw, HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ACCESS) | HFA384x_CMD_WRITE_SET(write), rid, 0, 0);
420 * Performs the sequence necessary to read a config/info item.
423 * hw device structure
424 * rid config/info record id (host order)
425 * buf host side record buffer. Upon return it will
426 * contain the body portion of the record (minus the
428 * len buffer length (in bytes, should match record length)
433 static int hfa384x_drvr_getconfig(hfa384x_t *hw, UINT16 rid, void *buf, UINT16 len)
438 /* Request read of RID */
439 result = hfa384x_cmd_access( hw, 0, rid);
441 printf("Call to hfa384x_cmd_access failed\n");
444 /* Copy out record length */
445 result = hfa384x_copy_from_bap( hw, rid, 0, &rec, sizeof(rec));
449 /* Validate the record length */
450 if ( ((hfa384x2host_16(rec.reclen)-1)*2) != len ) { /* note body len calculation in bytes */
451 printf ( "RID len mismatch, rid=%#hx hlen=%d fwlen=%d\n", rid, len, (hfa384x2host_16(rec.reclen)-1)*2);
454 /* Copy out record data */
455 result = hfa384x_copy_from_bap( hw, rid, sizeof(rec), buf, len);
460 * Performs the sequence necessary to read a 16/32 bit config/info item
461 * and convert it to host order.
464 * hw device structure
465 * rid config/info record id (in host order)
466 * val ptr to 16/32 bit buffer to receive value (in host order)
471 #if 0 /* Not actually used anywhere */
472 static int hfa384x_drvr_getconfig16(hfa384x_t *hw, UINT16 rid, void *val)
475 result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(UINT16));
477 *((UINT16*)val) = hfa384x2host_16(*((UINT16*)val));
482 #if 0 /* Not actually used anywhere */
483 static int hfa384x_drvr_getconfig32(hfa384x_t *hw, UINT16 rid, void *val)
486 result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(UINT32));
488 *((UINT32*)val) = hfa384x2host_32(*((UINT32*)val));
495 * Performs the sequence necessary to write a config/info item.
498 * hw device structure
499 * rid config/info record id (in host order)
500 * buf host side record buffer
501 * len buffer length (in bytes)
506 static int hfa384x_drvr_setconfig(hfa384x_t *hw, UINT16 rid, void *buf, UINT16 len)
511 rec.rid = host2hfa384x_16(rid);
512 rec.reclen = host2hfa384x_16((len/2) + 1); /* note conversion to words, +1 for rid field */
513 /* write the record header */
514 result = hfa384x_copy_to_bap( hw, rid, 0, &rec, sizeof(rec));
516 printf("Failure writing record header\n");
519 /* write the record data (if there is any) */
521 result = hfa384x_copy_to_bap( hw, rid, sizeof(rec), buf, len);
523 printf("Failure writing record data\n");
527 /* Trigger setting of record */
528 result = hfa384x_cmd_access( hw, 1, rid);
533 * Performs the sequence necessary to write a 16/32 bit config/info item.
536 * hw device structure
537 * rid config/info record id (in host order)
538 * val 16/32 bit value to store (in host order)
543 static int hfa384x_drvr_setconfig16(hfa384x_t *hw, UINT16 rid, UINT16 *val)
546 value = host2hfa384x_16(*val);
547 return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(UINT16));
549 #if 0 /* Not actually used anywhere */
550 static int hfa384x_drvr_setconfig32(hfa384x_t *hw, UINT16 rid, UINT32 *val)
553 value = host2hfa384x_32(*val);
554 return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(UINT32));
559 * Wait for an event, with specified checking interval and timeout.
560 * Automatically acknolwedges events.
563 * hw device structure
564 * event_mask EVSTAT register mask of events to wait for
565 * event_ack EVACK register set of events to be acknowledged if they happen (can be
566 * used to acknowledge "ignorable" events in addition to the "main" event)
567 * wait Time (in us) to wait between each poll of the register
568 * timeout Maximum number of polls before timing out
569 * descr Descriptive text string of what is being waited for
570 * (will be printed out if a timeout happens)
573 * value of EVSTAT register, or 0 on failure
575 static int hfa384x_wait_for_event(hfa384x_t *hw, UINT16 event_mask, UINT16 event_ack, int wait, int timeout, const char *descr)
581 reg = hfa384x_getreg(hw, HFA384x_EVSTAT);
582 if ( count > 0 ) udelay(wait);
584 } while ( !(reg & event_mask) && count < timeout);
585 if ( count >= timeout ) {
586 printf("hfa384x: Timed out waiting for %s\n", descr);
587 return 0; /* Return failure */
589 /* Acknowledge all events that we were waiting on */
590 hfa384x_setreg(hw, reg & ( event_mask | event_ack ), HFA384x_EVACK);
594 /**************************************************************************
595 POLL - Wait for a frame
596 ***************************************************************************/
597 static int prism2_poll(struct nic *nic, int retrieve)
602 hfa384x_rx_frame_t rxdesc;
603 hfa384x_t *hw = &hw_global;
605 /* Check for received packet */
606 reg = hfa384x_getreg(hw, HFA384x_EVSTAT);
607 if ( ! HFA384x_EVSTAT_ISRX(reg) ) {
608 /* No packet received - return 0 */
612 if ( ! retrieve ) return 1;
614 /* Acknowledge RX event */
615 hfa384x_setreg(hw, HFA384x_EVACK_RX_SET(1), HFA384x_EVACK);
617 rxfid = hfa384x_getreg(hw, HFA384x_RXFID);
618 /* Get the descriptor (including headers) */
619 result = hfa384x_copy_from_bap(hw, rxfid, 0, &rxdesc, sizeof(rxdesc));
623 /* Byte order convert once up front. */
624 rxdesc.status = hfa384x2host_16(rxdesc.status);
625 rxdesc.time = hfa384x2host_32(rxdesc.time);
626 rxdesc.data_len = hfa384x2host_16(rxdesc.data_len);
628 /* Fill in nic->packetlen */
629 nic->packetlen = rxdesc.data_len;
630 if ( nic->packetlen > 0 ) {
631 /* Fill in nic->packet */
633 * NOTE: Packets as received have an 8-byte header (LLC+SNAP(?)) terminating with the packet type.
634 * Etherboot expects a 14-byte header terminating with the packet type (it ignores the rest of the
635 * header), so we use a quick hack to achieve this.
637 result = hfa384x_copy_from_bap(hw, rxfid, HFA384x_RX_DATA_OFF,
638 nic->packet + ETH_HLEN - sizeof(wlan_80211hdr_t), nic->packetlen);
643 return 1; /* Packet successfully received */
646 /**************************************************************************
647 TRANSMIT - Transmit a frame
648 ***************************************************************************/
649 static void prism2_transmit(
651 const char *d, /* Destination */
652 unsigned int t, /* Type */
653 unsigned int s, /* size */
654 const char *p) /* Packet */
656 hfa384x_t *hw = &hw_global;
657 hfa384x_tx_frame_t txdesc;
658 wlan_80211hdr_t p80211hdr = { wlan_llc_snap, {{0,0,0},0} };
663 // Request FID allocation
664 result = hfa384x_docmd_wait(hw, HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ALLOC), HFA384x_DRVR_TXBUF_MAX, 0, 0);
666 printf("hfa384x: Tx FID allocate command failed: Aborting transmit..\n");
669 if ( !hfa384x_wait_for_event(hw, HFA384x_EVSTAT_ALLOC, HFA384x_EVACK_INFO, 10, 50, "Tx FID to be allocated\n" ) ) return;
670 fid = hfa384x_getreg(hw, HFA384x_ALLOCFID);
672 /* Build Tx frame structure */
673 memset(&txdesc, 0, sizeof(txdesc));
674 txdesc.tx_control = host2hfa384x_16( HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
675 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1) );
676 txdesc.frame_control = host2ieee16( WLAN_SET_FC_FTYPE(WLAN_FTYPE_DATA) |
677 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DATAONLY) |
678 WLAN_SET_FC_TODS(1) );
679 memcpy(txdesc.address1, hw->bssid, WLAN_ADDR_LEN);
680 memcpy(txdesc.address2, nic->node_addr, WLAN_ADDR_LEN);
681 memcpy(txdesc.address3, d, WLAN_ADDR_LEN);
682 txdesc.data_len = host2hfa384x_16( sizeof(txdesc) + sizeof(p80211hdr) + s );
683 /* Set up SNAP header */
684 /* Let OUI default to RFC1042 (0x000000) */
685 p80211hdr.snap.type = htons(t);
687 /* Copy txdesc, p80211hdr and payload parts to FID */
688 result = hfa384x_copy_to_bap(hw, fid, 0, &txdesc, sizeof(txdesc));
689 if ( result ) return; /* fail */
690 result = hfa384x_copy_to_bap( hw, fid, sizeof(txdesc), &p80211hdr, sizeof(p80211hdr) );
691 if ( result ) return; /* fail */
692 result = hfa384x_copy_to_bap( hw, fid, sizeof(txdesc) + sizeof(p80211hdr), (UINT8*)p, s );
693 if ( result ) return; /* fail */
695 /* Issue Tx command */
696 result = hfa384x_docmd_wait(hw, HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_TX), fid, 0, 0);
698 printf("hfa384x: Transmit failed with result %#hx.\n", result);
702 /* Wait for transmit completion (or exception) */
703 result = hfa384x_wait_for_event(hw, HFA384x_EVSTAT_TXEXC | HFA384x_EVSTAT_TX, HFA384x_EVACK_INFO,
704 200, 500, "Tx to complete\n" );
705 if ( !result ) return; /* timeout failure */
706 if ( HFA384x_EVSTAT_ISTXEXC(result) ) {
707 fid = hfa384x_getreg(hw, HFA384x_TXCOMPLFID);
708 printf ( "Tx exception occurred with fid %#hx\n", fid );
709 result = hfa384x_copy_from_bap(hw, fid, 0, &status, sizeof(status));
710 if ( result ) return; /* fail */
711 printf("hfa384x: Tx error occurred (status %#hx):\n", status);
712 if ( HFA384x_TXSTATUS_ISACKERR(status) ) { printf(" ...acknowledgement error\n"); }
713 if ( HFA384x_TXSTATUS_ISFORMERR(status) ) { printf(" ...format error\n"); }
714 if ( HFA384x_TXSTATUS_ISDISCON(status) ) { printf(" ...disconnected error\n"); }
715 if ( HFA384x_TXSTATUS_ISAGEDERR(status) ) { printf(" ...AGED error\n"); }
716 if ( HFA384x_TXSTATUS_ISRETRYERR(status) ) { printf(" ...retry error\n"); }
721 /**************************************************************************
722 DISABLE - Turn off ethernet interface
723 ***************************************************************************/
724 static void prism2_disable ( struct nic *nic __unused ) {
725 /* put the card in its initial state */
728 /**************************************************************************
729 IRQ - Enable, Disable, or Force interrupts
730 ***************************************************************************/
731 static void prism2_irq(struct nic *nic __unused, irq_action_t action __unused)
743 /**************************************************************************
745 ***************************************************************************/
746 static struct nic_operations prism2_operations = {
747 .connect = dummy_connect,
749 .transmit = prism2_transmit,
751 .disable = prism2_disable,
754 /**************************************************************************
755 PROBE - Look for an adapter, this routine's visible to the outside
756 You should omit the last argument struct pci_device * for a non-PCI NIC
757 ***************************************************************************/
758 static int prism2_probe ( struct nic *nic, hfa384x_t *hw ) {
762 hfa384x_InfFrame_t inf;
763 char ssid[HFA384x_RID_CNFDESIREDSSID_LEN];
768 /* Initialize card */
769 result = hfa384x_docmd_wait(hw, HFA384x_CMDCODE_INIT, 0,0,0); /* Send initialize command */
770 if ( result ) printf ( "Initialize command returned %#hx\n", result );
771 hfa384x_setreg(hw, 0, HFA384x_INTEN); /* Disable interrupts */
772 hfa384x_setreg(hw, 0xffff, HFA384x_EVACK); /* Acknowledge any spurious events */
774 /* Retrieve MAC address (and fill out nic->node_addr) */
775 hfa384x_drvr_getconfig ( hw, HFA384x_RID_CNFOWNMACADDR, nic->node_addr, HFA384x_RID_CNFOWNMACADDR_LEN );
776 printf ( "MAC address %!\n", nic->node_addr );
778 /* Prepare card for autojoin */
779 /* This procedure is reverse-engineered from a register-level trace of the Linux driver's join process */
780 tmp16 = WLAN_DATA_MAXLEN; /* Set maximum data length */
781 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, &tmp16);
782 if ( result ) printf ( "Set Max Data Length command returned %#hx\n", result );
783 tmp16 = 0x000f; /* Set transmit rate(?) */
784 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, &tmp16);
785 if ( result ) printf ( "Set Transmit Rate command returned %#hx\n", result );
786 tmp16 = HFA384x_CNFAUTHENTICATION_OPENSYSTEM; /* Set authentication type to OpenSystem */
787 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, &tmp16);
788 if ( result ) printf ( "Set Authentication Type command returned %#hx\n", result );
790 memset(ssid, 0, HFA384x_RID_CNFDESIREDSSID_LEN);
791 for ( tmp16=0; tmp16<sizeof(hardcoded_ssid); tmp16++ ) { ssid[2+tmp16] = hardcoded_ssid[tmp16]; }
792 ssid[0] = sizeof(hardcoded_ssid) - 1; /* Ignore terminating zero */
793 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID, ssid, HFA384x_RID_CNFDESIREDSSID_LEN); /* Set the SSID */
794 if ( result ) printf ( "Set SSID command returned %#hx\n", result );
795 tmp16 = 1; /* Set port type to ESS port */
796 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, &tmp16);
797 if ( result ) printf ( "Set port type command returned %#hx\n", result );
799 result = hfa384x_docmd_wait(hw, HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) | HFA384x_CMD_MACPORT_SET(0), 0,0,0);
800 if ( result ) printf ( "Enable command returned %#hx\n", result );
803 /* Increment info_count, abort if too many attempts.
804 * See comment next to definition of MAX_JOIN_INFO_COUNT for explanation.
807 if ( info_count > MAX_JOIN_INFO_COUNT ) {
808 printf ( "Too many failed attempts - aborting\n" );
812 /* Wait for info frame to indicate link status */
813 if ( sizeof(hardcoded_ssid) == 1 ) {
814 /* Empty SSID => join to any SSID */
815 printf ( "Attempting to autojoin to any available access point (attempt %d)...", info_count );
817 printf ( "Attempting to autojoin to SSID %s (attempt %d)...", &ssid[2], info_count );
820 if ( !hfa384x_wait_for_event(hw, HFA384x_EVSTAT_INFO, 0, 1000, 2000, "Info event" ) ) return 0;
822 infofid = hfa384x_getreg(hw, HFA384x_INFOFID);
823 /* Retrieve the length */
824 result = hfa384x_copy_from_bap( hw, infofid, 0, &inf.framelen, sizeof(UINT16));
825 if ( result ) return 0; /* fail */
826 inf.framelen = hfa384x2host_16(inf.framelen);
827 /* Retrieve the rest */
828 result = hfa384x_copy_from_bap( hw, infofid, sizeof(UINT16),
829 &(inf.infotype), inf.framelen * sizeof(UINT16));
830 if ( result ) return 0; /* fail */
831 if ( inf.infotype != HFA384x_IT_LINKSTATUS ) {
832 /* Not a Link Status info frame: die */
833 printf ( "Unexpected info frame type %#hx (not LinkStatus type)\n", inf.infotype );
836 inf.info.linkstatus.linkstatus = hfa384x2host_16(inf.info.linkstatus.linkstatus);
837 if ( inf.info.linkstatus.linkstatus != HFA384x_LINK_CONNECTED ) {
838 /* Link not connected - retry */
839 printf ( "Link not connected (status %#hx)\n", inf.info.linkstatus.linkstatus );
841 } while ( inf.info.linkstatus.linkstatus != HFA384x_LINK_CONNECTED );
843 /* Retrieve BSSID and print Connected message */
844 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CURRENTBSSID, hw->bssid, WLAN_BSSID_LEN);
845 printf ( "Link connected (BSSID %! - MAC address %!)\n", hw->bssid, nic->node_addr );
847 /* point to NIC specific routines */
848 nic->nic_op = &prism2_operations;