diff --git a/src/add-ons/kernel/drivers/network/wlan/Jamfile b/src/add-ons/kernel/drivers/network/wlan/Jamfile index 449c287da7..7cad356caa 100644 --- a/src/add-ons/kernel/drivers/network/wlan/Jamfile +++ b/src/add-ons/kernel/drivers/network/wlan/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src add-ons kernel drivers network wlan ; #FreeBSD 8 WLAN drivers +SubInclude HAIKU_TOP src add-ons kernel drivers network wlan aironetwifi ; SubInclude HAIKU_TOP src add-ons kernel drivers network wlan atheros ; SubInclude HAIKU_TOP src add-ons kernel drivers network wlan broadcom43xx ; SubInclude HAIKU_TOP src add-ons kernel drivers network wlan iprowifi2100 ; @@ -10,3 +11,4 @@ SubInclude HAIKU_TOP src add-ons kernel drivers network wlan iprowifi4965 ; SubInclude HAIKU_TOP src add-ons kernel drivers network wlan marvell88w8363 ; SubInclude HAIKU_TOP src add-ons kernel drivers network wlan marvell88w8335 ; SubInclude HAIKU_TOP src add-ons kernel drivers network wlan ralinkwifi ; +SubInclude HAIKU_TOP src add-ons kernel drivers network wlan wavelanwifi ; diff --git a/src/add-ons/kernel/drivers/network/wlan/aironetwifi/Jamfile b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/Jamfile new file mode 100644 index 0000000000..7635aebe40 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/Jamfile @@ -0,0 +1,23 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network wlan aironetwifi ; + +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_wlan ] : true ; +UsePrivateHeaders net system ; +UsePrivateKernelHeaders ; + +SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] + -Wno-format + -Wno-unused + -Wno-uninitialized ; + +UseHeaders [ FDirName $(SUBDIR) ] : true ; + +SEARCH_SOURCE += [ FDirName $(SUBDIR) dev an ] ; + +KernelAddon aironetwifi : + if_an.c + if_an_pci.c + : + libfreebsd_wlan.a + libfreebsd_network.a + ; diff --git a/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_aironet_ieee.h b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_aironet_ieee.h new file mode 100644 index 0000000000..28e4f72148 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_aironet_ieee.h @@ -0,0 +1,798 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _IF_AIRONET_IEEE_H +#define _IF_AIRONET_IEEE_H + +/* + * This header defines a simple command interface to the FreeBSD + * Aironet driver (an) driver, which is used to set certain + * device-specific parameters which can't be easily managed through + * ifconfig(8). No, sysctl(2) is not the answer. I said a _simple_ + * interface, didn't I. + */ + +#ifndef SIOCSAIRONET +#define SIOCSAIRONET SIOCSIFGENERIC +#endif + +#ifndef SIOCGAIRONET +#define SIOCGAIRONET SIOCGIFGENERIC +#endif + +/* + * This is a make-predend RID value used only by the driver + * to allow the user to set the speed. + */ +#define AN_RID_TX_SPEED 0x1234 + +/* + * Technically I don't think there's a limit to a record + * length. The largest record is the one that contains the CIS + * data, which is 240 words long, so 256 should be a safe + * value. + */ +#define AN_MAX_DATALEN 4096 + +struct an_req { + u_int16_t an_len; + u_int16_t an_type; + u_int16_t an_val[AN_MAX_DATALEN]; +}; + +/* + * Private LTV records (interpreted only by the driver). This is + * a minor kludge to allow reading the interface statistics from + * the driver. + */ +#define AN_RID_IFACE_STATS 0x0100 +#define AN_RID_MGMT_XMIT 0x0200 +#ifdef ANCACHE +#define AN_RID_ZERO_CACHE 0x0300 +#define AN_RID_READ_CACHE 0x0400 +#endif + +#define AN_FCTL_VERS 0x0002 +#define AN_FCTL_FTYPE 0x000C +#define AN_FCTL_STYPE 0x00F0 +#define AN_FCTL_TODS 0x0100 +#define AN_FCTL_FROMDS 0x0200 +#define AN_FCTL_MOREFRAGS 0x0400 +#define AN_FCTL_RETRY 0x0800 +#define AN_FCTL_PM 0x1000 +#define AN_FCTL_MOREDATA 0x2000 +#define AN_FCTL_WEP 0x4000 +#define AN_FCTL_ORDER 0x8000 + +#define AN_FTYPE_MGMT 0x0000 +#define AN_FTYPE_CTL 0x0004 +#define AN_FTYPE_DATA 0x0008 + +#define AN_STYPE_MGMT_ASREQ 0x0000 /* association request */ +#define AN_STYPE_MGMT_ASRESP 0x0010 /* association response */ +#define AN_STYPE_MGMT_REASREQ 0x0020 /* reassociation request */ +#define AN_STYPE_MGMT_REASRESP 0x0030 /* reassociation response */ +#define AN_STYPE_MGMT_PROBEREQ 0x0040 /* probe request */ +#define AN_STYPE_MGMT_PROBERESP 0x0050 /* probe response */ +#define AN_STYPE_MGMT_BEACON 0x0080 /* beacon */ +#define AN_STYPE_MGMT_ATIM 0x0090 /* announcement traffic ind msg */ +#define AN_STYPE_MGMT_DISAS 0x00A0 /* disassociation */ +#define AN_STYPE_MGMT_AUTH 0x00B0 /* authentication */ +#define AN_STYPE_MGMT_DEAUTH 0x00C0 /* deauthentication */ + +/* + * Aironet IEEE signal strength cache + * + * driver keeps cache of last + * MAXANCACHE packets to arrive including signal strength info. + * daemons may read this via ioctl + * + * Each entry in the wi_sigcache has a unique macsrc. + */ +#ifdef ANCACHE +#define MAXANCACHE 10 + +struct an_sigcache { + char macsrc[6]; /* unique MAC address for entry */ + int ipsrc; /* ip address associated with packet */ + int signal; /* signal strength of the packet */ + int noise; /* noise value */ + int quality; /* quality of the packet */ +}; +#endif + +/* + * The card provides an 8-bit signal strength value (RSSI), which can + * be converted to a dBm power value (or a percent) using a table in + * the card's firmware (when available). The tables are slightly + * different in individual cards, even of the same model. If the + * table is not available, the mapping can be approximated by dBm = + * RSSI - 100. This approximation can be seen by plotting a few + * tables, and also matches some info on the Intersil web site (I + * think they make the RF front end for the cards. However, the linux + * driver uses the approximation dBm = RSSI/2 - 95. I think that is + * just wrong. + */ + +struct an_rssi_entry { + u_int8_t an_rss_pct; + u_int8_t an_rss_dbm; +}; + + +struct an_ltv_key { + u_int16_t an_len; + u_int16_t an_type; + u_int16_t kindex; + u_int8_t mac[6]; + u_int16_t klen; + u_int8_t key[16]; /* 128-bit keys */ +}; + +struct an_ltv_stats { + u_int16_t an_fudge; + u_int16_t an_len; /* 0x00 */ + u_int16_t an_type; /* 0xXX */ + u_int16_t an_spacer; /* 0x02 */ + u_int32_t an_rx_overruns; /* 0x04 */ + u_int32_t an_rx_plcp_csum_errs; /* 0x08 */ + u_int32_t an_rx_plcp_format_errs; /* 0x0C */ + u_int32_t an_rx_plcp_len_errs; /* 0x10 */ + u_int32_t an_rx_mac_crc_errs; /* 0x14 */ + u_int32_t an_rx_mac_crc_ok; /* 0x18 */ + u_int32_t an_rx_wep_errs; /* 0x1C */ + u_int32_t an_rx_wep_ok; /* 0x20 */ + u_int32_t an_retry_long; /* 0x24 */ + u_int32_t an_retry_short; /* 0x28 */ + u_int32_t an_retry_max; /* 0x2C */ + u_int32_t an_no_ack; /* 0x30 */ + u_int32_t an_no_cts; /* 0x34 */ + u_int32_t an_rx_ack_ok; /* 0x38 */ + u_int32_t an_rx_cts_ok; /* 0x3C */ + u_int32_t an_tx_ack_ok; /* 0x40 */ + u_int32_t an_tx_rts_ok; /* 0x44 */ + u_int32_t an_tx_cts_ok; /* 0x48 */ + u_int32_t an_tx_lmac_mcasts; /* 0x4C */ + u_int32_t an_tx_lmac_bcasts; /* 0x50 */ + u_int32_t an_tx_lmac_ucast_frags; /* 0x54 */ + u_int32_t an_tx_lmac_ucasts; /* 0x58 */ + u_int32_t an_tx_beacons; /* 0x5C */ + u_int32_t an_rx_beacons; /* 0x60 */ + u_int32_t an_tx_single_cols; /* 0x64 */ + u_int32_t an_tx_multi_cols; /* 0x68 */ + u_int32_t an_tx_defers_no; /* 0x6C */ + u_int32_t an_tx_defers_prot; /* 0x70 */ + u_int32_t an_tx_defers_energy; /* 0x74 */ + u_int32_t an_rx_dups; /* 0x78 */ + u_int32_t an_rx_partial; /* 0x7C */ + u_int32_t an_tx_too_old; /* 0x80 */ + u_int32_t an_rx_too_old; /* 0x84 */ + u_int32_t an_lostsync_max_retries;/* 0x88 */ + u_int32_t an_lostsync_missed_beacons;/* 0x8C */ + u_int32_t an_lostsync_arl_exceeded;/*0x90 */ + u_int32_t an_lostsync_deauthed; /* 0x94 */ + u_int32_t an_lostsync_disassociated;/*0x98 */ + u_int32_t an_lostsync_tsf_timing; /* 0x9C */ + u_int32_t an_tx_host_mcasts; /* 0xA0 */ + u_int32_t an_tx_host_bcasts; /* 0xA4 */ + u_int32_t an_tx_host_ucasts; /* 0xA8 */ + u_int32_t an_tx_host_failed; /* 0xAC */ + u_int32_t an_rx_host_mcasts; /* 0xB0 */ + u_int32_t an_rx_host_bcasts; /* 0xB4 */ + u_int32_t an_rx_host_ucasts; /* 0xB8 */ + u_int32_t an_rx_host_discarded; /* 0xBC */ + u_int32_t an_tx_hmac_mcasts; /* 0xC0 */ + u_int32_t an_tx_hmac_bcasts; /* 0xC4 */ + u_int32_t an_tx_hmac_ucasts; /* 0xC8 */ + u_int32_t an_tx_hmac_failed; /* 0xCC */ + u_int32_t an_rx_hmac_mcasts; /* 0xD0 */ + u_int32_t an_rx_hmac_bcasts; /* 0xD4 */ + u_int32_t an_rx_hmac_ucasts; /* 0xD8 */ + u_int32_t an_rx_hmac_discarded; /* 0xDC */ + u_int32_t an_tx_hmac_accepted; /* 0xE0 */ + u_int32_t an_ssid_mismatches; /* 0xE4 */ + u_int32_t an_ap_mismatches; /* 0xE8 */ + u_int32_t an_rates_mismatches; /* 0xEC */ + u_int32_t an_auth_rejects; /* 0xF0 */ + u_int32_t an_auth_timeouts; /* 0xF4 */ + u_int32_t an_assoc_rejects; /* 0xF8 */ + u_int32_t an_assoc_timeouts; /* 0xFC */ + u_int32_t an_reason_outside_table;/* 0x100 */ + u_int32_t an_reason1; /* 0x104 */ + u_int32_t an_reason2; /* 0x108 */ + u_int32_t an_reason3; /* 0x10C */ + u_int32_t an_reason4; /* 0x110 */ + u_int32_t an_reason5; /* 0x114 */ + u_int32_t an_reason6; /* 0x118 */ + u_int32_t an_reason7; /* 0x11C */ + u_int32_t an_reason8; /* 0x120 */ + u_int32_t an_reason9; /* 0x124 */ + u_int32_t an_reason10; /* 0x128 */ + u_int32_t an_reason11; /* 0x12C */ + u_int32_t an_reason12; /* 0x130 */ + u_int32_t an_reason13; /* 0x134 */ + u_int32_t an_reason14; /* 0x138 */ + u_int32_t an_reason15; /* 0x13C */ + u_int32_t an_reason16; /* 0x140 */ + u_int32_t an_reason17; /* 0x144 */ + u_int32_t an_reason18; /* 0x148 */ + u_int32_t an_reason19; /* 0x14C */ + u_int32_t an_rx_mgmt_pkts; /* 0x150 */ + u_int32_t an_tx_mgmt_pkts; /* 0x154 */ + u_int32_t an_rx_refresh_pkts; /* 0x158 */ + u_int32_t an_tx_refresh_pkts; /* 0x15C */ + u_int32_t an_rx_poll_pkts; /* 0x160 */ + u_int32_t an_tx_poll_pkts; /* 0x164 */ + u_int32_t an_host_retries; /* 0x168 */ + u_int32_t an_lostsync_hostreq; /* 0x16C */ + u_int32_t an_host_tx_bytes; /* 0x170 */ + u_int32_t an_host_rx_bytes; /* 0x174 */ + u_int32_t an_uptime_usecs; /* 0x178 */ + u_int32_t an_uptime_secs; /* 0x17C */ + u_int32_t an_lostsync_better_ap; /* 0x180 */ + u_int32_t an_rsvd[15]; +}; + +/* + * General configuration information. + */ +struct an_ltv_genconfig { + /* General configuration. */ + u_int16_t an_len; /* 0x00 */ + u_int16_t an_type; /* XXXX */ + u_int16_t an_opmode; /* 0x02 */ + u_int16_t an_rxmode; /* 0x04 */ + u_int16_t an_fragthresh; /* 0x06 */ + u_int16_t an_rtsthresh; /* 0x08 */ + u_int8_t an_macaddr[6]; /* 0x0A */ + u_int8_t an_rates[8]; /* 0x10 */ + u_int16_t an_shortretry_limit; /* 0x18 */ + u_int16_t an_longretry_limit; /* 0x1A */ + u_int16_t an_tx_msdu_lifetime; /* 0x1C */ + u_int16_t an_rx_msdu_lifetime; /* 0x1E */ + u_int16_t an_stationary; /* 0x20 */ + u_int16_t an_ordering; /* 0x22 */ + u_int16_t an_devtype; /* 0x24 */ + u_int16_t an_rsvd0[5]; /* 0x26 */ + /* Scanning associating. */ + u_int16_t an_scanmode; /* 0x30 */ + u_int16_t an_probedelay; /* 0x32 */ + u_int16_t an_probe_energy_timeout;/* 0x34 */ + u_int16_t an_probe_response_timeout;/*0x36 */ + u_int16_t an_beacon_listen_timeout;/*0x38 */ + u_int16_t an_ibss_join_net_timeout;/*0x3A */ + u_int16_t an_auth_timeout; /* 0x3C */ + u_int16_t an_authtype; /* 0x3E */ + u_int16_t an_assoc_timeout; /* 0x40 */ + u_int16_t an_specified_ap_timeout;/* 0x42 */ + u_int16_t an_offline_scan_interval;/*0x44 */ + u_int16_t an_offline_scan_duration;/*0x46 */ + u_int16_t an_link_loss_delay; /* 0x48 */ + u_int16_t an_max_beacon_lost_time;/* 0x4A */ + u_int16_t an_refresh_interval; /* 0x4C */ + u_int16_t an_rsvd1; /* 0x4E */ + /* Power save operation */ + u_int16_t an_psave_mode; /* 0x50 */ + u_int16_t an_sleep_for_dtims; /* 0x52 */ + u_int16_t an_listen_interval; /* 0x54 */ + u_int16_t an_fast_listen_interval;/* 0x56 */ + u_int16_t an_listen_decay; /* 0x58 */ + u_int16_t an_fast_listen_decay; /* 0x5A */ + u_int16_t an_rsvd2[2]; /* 0x5C */ + /* Ad-hoc (or AP) operation. */ + u_int16_t an_beacon_period; /* 0x60 */ + u_int16_t an_atim_duration; /* 0x62 */ + u_int16_t an_rsvd3; /* 0x64 */ + u_int16_t an_ds_channel; /* 0x66 */ + u_int16_t an_rsvd4; /* 0x68 */ + u_int16_t an_dtim_period; /* 0x6A */ + u_int16_t an_rsvd5[2]; /* 0x6C */ + /* Radio operation. */ + u_int16_t an_radiotype; /* 0x70 */ + u_int16_t an_diversity; /* 0x72 */ + u_int16_t an_tx_power; /* 0x74 */ + u_int16_t an_rss_thresh; /* 0x76 */ + u_int16_t an_modulation_type; /* 0x78 */ + u_int16_t an_short_preamble; /* 0x7A */ + u_int16_t an_home_product; /* 0x7C */ + u_int16_t an_rsvd6; /* 0x7E */ + /* Aironet extensions. */ + u_int8_t an_nodename[16]; /* 0x80 */ + u_int16_t an_arl_thresh; /* 0x90 */ + u_int16_t an_arl_decay; /* 0x92 */ + u_int16_t an_arl_delay; /* 0x94 */ + u_int8_t an_rsvd7; /* 0x96 */ + u_int8_t an_rsvd8; /* 0x97 */ + u_int8_t an_magic_packet_action; /* 0x98 */ + u_int8_t an_magic_packet_ctl; /* 0x99 */ + u_int16_t an_rsvd9; + u_int16_t an_spare[19]; +}; + +#define AN_OPMODE_IBSS_ADHOC 0x0000 +#define AN_OPMODE_INFRASTRUCTURE_STATION 0x0001 +#define AN_OPMODE_AP 0x0002 +#define AN_OPMODE_AP_REPEATER 0x0003 +#define AN_OPMODE_UNMODIFIED_PAYLOAD 0x0100 +#define AN_OPMODE_AIRONET_EXTENSIONS 0x0200 +#define AN_OPMODE_AP_EXTENSIONS 0x0400 + +#define AN_RXMODE_BC_MC_ADDR 0x0000 +#define AN_RXMODE_BC_ADDR 0x0001 +#define AN_RXMODE_ADDR 0x0002 +#define AN_RXMODE_80211_MONITOR_CURBSS 0x0003 +#define AN_RXMODE_80211_MONITOR_ANYBSS 0x0004 +#define AN_RXMODE_LAN_MONITOR_CURBSS 0x0005 +#define AN_RXMODE_NO_8023_HEADER 0x0100 +#define AN_RXMODE_NORMALIZED_RSSI 0x0200 + +#define AN_RATE_1MBPS 0x0002 +#define AN_RATE_2MBPS 0x0004 +#define AN_RATE_5_5MBPS 0x000B +#define AN_RATE_11MBPS 0x0016 + +#define AN_DEVTYPE_PC4500 0x0065 +#define AN_DEVTYPE_PC4800 0x006D + +#define AN_SCANMODE_ACTIVE 0x0000 +#define AN_SCANMODE_PASSIVE 0x0001 +#define AN_SCANMODE_AIRONET_ACTIVE 0x0002 + +#define AN_AUTHTYPE_NONE 0x0000 +#define AN_AUTHTYPE_OPEN 0x0001 +#define AN_AUTHTYPE_SHAREDKEY 0x0002 +#define AN_AUTHTYPE_MASK 0x00ff +#define AN_AUTHTYPE_ENABLE 0x0100 +#define AN_AUTHTYPE_PRIVACY_IN_USE 0x0100 +#define AN_AUTHTYPE_ALLOW_UNENCRYPTED 0x0200 +#define AN_AUTHTYPE_LEAP 0x1000 + +#define AN_PSAVE_NONE 0x0000 +#define AN_PSAVE_CAM 0x0001 +#define AN_PSAVE_PSP 0x0002 +#define AN_PSAVE_PSP_CAM 0x0003 + +#define AN_RADIOTYPE_80211_FH 0x0001 +#define AN_RADIOTYPE_80211_DS 0x0002 +#define AN_RADIOTYPE_LM2000_DS 0x0004 + +#define AN_DIVERSITY_FACTORY_DEFAULT 0x0000 +#define AN_DIVERSITY_ANTENNA_1_ONLY 0x0001 +#define AN_DIVERSITY_ANTENNA_2_ONLY 0x0002 +#define AN_DIVERSITY_ANTENNA_1_AND_2 0x0003 + +#define AN_TXPOWER_FACTORY_DEFAULT 0x0000 +#define AN_TXPOWER_50MW 50 +#define AN_TXPOWER_100MW 100 +#define AN_TXPOWER_250MW 250 + +#define AN_HOME_NETWORK 0x0001 +#define AN_HOME_INSTALL_AP 0x0002 + +/* + * Valid SSID list. You can specify up to three SSIDs denoting + * the service sets that you want to join. The first SSID always + * defaults to "tsunami" which is a handy way to detect the + * card. + */ + +struct an_ltv_ssidlist { + u_int16_t an_len; + u_int16_t an_type; + u_int16_t an_ssid1_len; + char an_ssid1[32]; + u_int16_t an_ssid2_len; + char an_ssid2[32]; + u_int16_t an_ssid3_len; + char an_ssid3[32]; +}; + +struct an_ltv_ssid_entry{ + u_int16_t an_len; + char an_ssid[32]; +}; + +#define MAX_SSIDS 25 +struct an_ltv_ssidlist_new { + u_int16_t an_len; + u_int16_t an_type; + struct an_ltv_ssid_entry an_entry[MAX_SSIDS]; +}; + +/* + * Valid AP list. + */ +struct an_ltv_aplist { + u_int16_t an_len; + u_int16_t an_type; + u_int8_t an_ap1[8]; + u_int8_t an_ap2[8]; + u_int8_t an_ap3[8]; + u_int8_t an_ap4[8]; +}; + +/* + * Driver name. + */ +struct an_ltv_drvname { + u_int16_t an_len; + u_int16_t an_type; + u_int8_t an_drvname[16]; +}; + +/* + * Frame encapsulation. + */ +struct an_rid_encap { + u_int16_t an_len; + u_int16_t an_type; + u_int16_t an_ethertype_default; + u_int16_t an_action_default; + u_int16_t an_ethertype0; + u_int16_t an_action0; + u_int16_t an_ethertype1; + u_int16_t an_action1; + u_int16_t an_ethertype2; + u_int16_t an_action2; + u_int16_t an_ethertype3; + u_int16_t an_action3; + u_int16_t an_ethertype4; + u_int16_t an_action4; + u_int16_t an_ethertype5; + u_int16_t an_action5; + u_int16_t an_ethertype6; + u_int16_t an_action6; +}; + +#define AN_ENCAP_ACTION_RX 0x0001 +#define AN_ENCAP_ACTION_TX 0x0002 + +#define AN_RXENCAP_NONE 0x0000 +#define AN_RXENCAP_RFC1024 0x0001 + +#define AN_TXENCAP_RFC1024 0x0000 +#define AN_TXENCAP_80211 0x0002 + +/* + * Card capabilities (read only). + */ +struct an_ltv_caps { + u_int16_t an_len; /* 0x00 */ + u_int16_t an_type; /* XXXX */ + u_int8_t an_oui[3]; /* 0x02 */ + u_int8_t an_rsvd0; /* 0x05 */ + u_int16_t an_prodnum; /* 0x06 */ + u_int8_t an_manufname[32]; /* 0x08 */ + u_int8_t an_prodname[16]; /* 0x28 */ + u_int8_t an_prodvers[8]; /* 0x38 */ + u_int8_t an_oemaddr[6]; /* 0x40 */ + u_int8_t an_aironetaddr[6]; /* 0x46 */ + u_int16_t an_radiotype; /* 0x4C */ + u_int16_t an_regdomain; /* 0x4E */ + u_int8_t an_callid[6]; /* 0x50 */ + u_int8_t an_rates[8]; /* 0x56 */ + u_int8_t an_rx_diversity; /* 0x5E */ + u_int8_t an_tx_diversity; /* 0x5F */ + u_int16_t an_tx_powerlevels[8]; /* 0x60 */ + u_int16_t an_hwrev; /* 0x70 */ + u_int16_t an_hwcaps; /* 0x72 */ + u_int16_t an_temprange; /* 0x74 */ + u_int16_t an_fwrev; /* 0x76 */ + u_int16_t an_fwsubrev; /* 0x78 */ + u_int16_t an_ifacerev; /* 0x7A */ + u_int16_t an_softcaps; /* 0x7C */ + u_int16_t an_bootblockrev; /* 0x7E */ + u_int16_t an_req_hw_support; /* 0x80 */ + u_int16_t an_unknown[31]; /* 0x82 */ +}; + +/* + * Access point (read only) + */ +struct an_ltv_apinfo { + u_int16_t an_len; + u_int16_t an_type; + u_int16_t an_tim_addr; + u_int16_t an_airo_addr; +}; + +/* + * Radio info (read only). + */ +struct an_ltv_radioinfo { + u_int16_t an_len; + u_int16_t an_type; + /* ??? */ +}; + +/* + * RSSI map. If available in the card's firmware, this can be used to + * convert the 8-bit RSSI values from the card into dBm. + */ +struct an_ltv_rssi_map { + u_int16_t an_len; + u_int16_t an_type; + struct an_rssi_entry an_entries[256]; +}; + +/* + * Status (read only). Note: the manual claims this RID is 108 bytes + * long (0x6A is the last datum, which is 2 bytes long) however when + * this RID is read from the NIC, it returns a length of 110. To be + * on the safe side, this structure is padded with an extra 16-bit + * word. (There is a misprint in the manual which says the macaddr + * field is 8 bytes long.) + * + * Also, the channel_set and current_channel fields appear to be + * reversed. Either that, or the hop_period field is unused. + */ +struct an_ltv_status { + u_int16_t an_len; /* 0x00 */ + u_int16_t an_type; /* 0xXX */ + u_int8_t an_macaddr[6]; /* 0x02 */ + u_int16_t an_opmode; /* 0x08 */ + u_int16_t an_errcode; /* 0x0A */ + u_int16_t an_signal_quality; /* 0x0C */ + u_int16_t an_ssidlen; /* 0x0E */ + u_int8_t an_ssid[32]; /* 0x10 */ + u_int8_t an_ap_name[16]; /* 0x30 */ + u_int8_t an_cur_bssid[6]; /* 0x40 */ + u_int8_t an_prev_bssid1[6]; /* 0x46 */ + u_int8_t an_prev_bssid2[6]; /* 0x4C */ + u_int8_t an_prev_bssid3[6]; /* 0x52 */ + u_int16_t an_beacon_period; /* 0x58 */ + u_int16_t an_dtim_period; /* 0x5A */ + u_int16_t an_atim_duration; /* 0x5C */ + u_int16_t an_hop_period; /* 0x5E */ + u_int16_t an_cur_channel; /* 0x62 */ + u_int16_t an_channel_set; /* 0x60 */ + u_int16_t an_hops_to_backbone; /* 0x64 */ + u_int16_t an_ap_total_load; /* 0x66 */ + u_int16_t an_our_generated_load; /* 0x68 */ + u_int16_t an_accumulated_arl; /* 0x6A */ + u_int16_t an_cur_signal_quality; /* 0x6C */ + u_int16_t an_current_tx_rate; /* 0x6E */ + u_int16_t an_ap_device; /* 0x70 */ + u_int16_t an_normalized_strength; /* 0x72 */ + u_int16_t an_short_pre_in_use; /* 0x74 */ + u_int8_t an_ap_ip_addr[4]; /* 0x76 */ + u_int8_t an_noise_prev_sec_pc; /* 0x7A */ + u_int8_t an_noise_prev_sec_db; /* 0x7B */ + u_int8_t an_avg_noise_prev_min_pc; /* 0x7C */ + u_int8_t an_avg_noise_prev_min_db; /* 0x7D */ + u_int8_t an_max_noise_prev_min_pc; /* 0x7E */ + u_int8_t an_max_noise_prev_min_db; /* 0x7F */ + u_int16_t an_spare[18]; +}; + +#define AN_STATUS_OPMODE_CONFIGURED 0x0001 +#define AN_STATUS_OPMODE_MAC_ENABLED 0x0002 +#define AN_STATUS_OPMODE_RX_ENABLED 0x0004 +#define AN_STATUS_OPMODE_IN_SYNC 0x0010 +#define AN_STATUS_OPMODE_ASSOCIATED 0x0020 +#define AN_STATUS_OPMODE_LEAP 0x0040 +#define AN_STATUS_OPMODE_ERROR 0x8000 + +/* + * WEP Key + */ +struct an_ltv_wepkey { + u_int16_t an_len; /* 0x00 */ + u_int16_t an_type; /* 0xXX */ + u_int16_t an_key_index; /* 0x02 */ + u_int8_t an_mac_addr[6]; /* 0x04 */ + u_int16_t an_key_len; /* 0x0A */ + u_int8_t an_key[13]; /* 0x0C */ +}; + +/* + * Receive frame structure. + */ +struct an_rxframe { + u_int32_t an_rx_time; /* 0x00 */ + u_int16_t an_rx_status; /* 0x04 */ + u_int16_t an_rx_payload_len; /* 0x06 */ + u_int8_t an_rsvd0; /* 0x08 */ + u_int8_t an_rx_signal_strength; /* 0x09 */ + u_int8_t an_rx_rate; /* 0x0A */ + u_int8_t an_rx_chan; /* 0x0B */ + u_int8_t an_rx_assoc_cnt; /* 0x0C */ + u_int8_t an_rsvd1[3]; /* 0x0D */ + u_int8_t an_plcp_hdr[4]; /* 0x10 */ + u_int16_t an_frame_ctl; /* 0x14 */ + u_int16_t an_duration; /* 0x16 */ + u_int8_t an_addr1[6]; /* 0x18 */ + u_int8_t an_addr2[6]; /* 0x1E */ + u_int8_t an_addr3[6]; /* 0x24 */ + u_int16_t an_seq_ctl; /* 0x2A */ + u_int8_t an_addr4[6]; /* 0x2C */ + u_int8_t an_gaplen; /* 0x32 */ +} __packed; + + +/* Do not modify this unless you are modifying LEAP itself */ +#define LEAP_USERNAME_MAX 32 +#define LEAP_PASSWORD_MAX 32 + +/* + * LEAP Username + */ +struct an_ltv_leap_username { + u_int16_t an_len; /* 0x00 */ + u_int16_t an_type; /* 0xXX */ + u_int16_t an_username_len; /* 0x02 */ + u_int8_t an_username[LEAP_USERNAME_MAX]; /* 0x04 */ +}; + +/* + * LEAP Password + */ +struct an_ltv_leap_password { + u_int16_t an_len; /* 0x00 */ + u_int16_t an_type; /* 0xXX */ + u_int16_t an_password_len; /* 0x02 */ + u_int8_t an_password[LEAP_PASSWORD_MAX]; /* 0x04 */ +}; + +/* + * These are all the LTV record types that we can read or write + * from the Aironet. Not all of them are temendously useful, but I + * list as many as I know about here for completeness. + */ + +/* + * Configuration (read/write) + */ +#define AN_RID_GENCONFIG 0xFF10 /* General configuration info */ +#define AN_RID_SSIDLIST 0xFF11 /* Valid SSID list */ +#define AN_RID_APLIST 0xFF12 /* Valid AP list */ +#define AN_RID_DRVNAME 0xFF13 /* ID name of this node for diag */ +#define AN_RID_ENCAPPROTO 0xFF14 /* Payload encapsulation type */ +#define AN_RID_WEP_TEMP 0xFF15 /* Temporary Key */ +#define AN_RID_WEP_PERM 0xFF16 /* Perminant Key */ +#define AN_RID_ACTUALCFG 0xFF20 /* Current configuration settings */ + +/* + * Reporting (read only) + */ +#define AN_RID_CAPABILITIES 0xFF00 /* PC 4500/4800 capabilities */ +#define AN_RID_AP_INFO 0xFF01 /* Access point info */ +#define AN_RID_RADIO_INFO 0xFF02 /* Radio info */ +#define AN_RID_RSSI_MAP 0xFF04 /* RSSI <-> dBm table */ +#define AN_RID_STATUS 0xFF50 /* Current status info */ +#define AN_RID_BEACONS_HST 0xFF51 +#define AN_RID_BUSY_HST 0xFF52 +#define AN_RID_RETRIES_HST 0xFF53 + +/* + * Statistics + */ +#define AN_RID_16BITS_CUM 0xFF60 /* Cumulative 16-bit stats counters */ +#define AN_RID_16BITS_DELTA 0xFF61 /* 16-bit stats (since last clear) */ +#define AN_RID_16BITS_DELTACLR 0xFF62 /* 16-bit stats, clear on read */ +#define AN_RID_32BITS_CUM 0xFF68 /* Cumulative 32-bit stats counters */ +#define AN_RID_32BITS_DELTA 0xFF69 /* 32-bit stats (since last clear) */ +#define AN_RID_32BITS_DELTACLR 0xFF6A /* 32-bit stats, clear on read */ + +/* + * LEAP + */ + +#define AN_RID_LEAPUSERNAME 0xFF23 /* Username */ +#define AN_RID_LEAPPASSWORD 0xFF24 /* Password */ + +/* + * OTHER Unknonwn for now + */ + +#define AN_RID_MOD 0xFF17 +#define AN_RID_OPTIONS 0xFF18 +#define AN_RID_FACTORY_CONFIG 0xFF18 + +/* + * FreeBSD fake RID + */ + +#define AN_RID_MONITOR_MODE 0x0001 /* Set monitor mode for driver */ +#define AN_MONITOR 1 +#define AN_MONITOR_ANY_BSS 2 +#define AN_MONITOR_INCLUDE_BEACON 4 +#define AN_MONITOR_AIRONET_HEADER 8 + +#define DLT_AIRONET_HEADER 120 /* Has been allocated at tcpdump.org */ + +/* + * from the Linux driver from Cisco ... no copyright header. + * Removed duplicated information that already existed in the FreeBSD driver + * provides emulation of the Cisco extensions to the Linux Aironet driver. + */ + +/* + * Ioctl constants to be used in airo_ioctl.command + */ + +#define AIROGCAP 0 /* Capability rid */ +#define AIROGCFG 1 /* USED A LOT */ +#define AIROGSLIST 2 /* System ID list */ +#define AIROGVLIST 3 /* List of specified AP's */ +#define AIROGDRVNAM 4 /* NOTUSED */ +#define AIROGEHTENC 5 /* NOTUSED */ +#define AIROGWEPKTMP 6 +#define AIROGWEPKNV 7 +#define AIROGSTAT 8 +#define AIROGSTATSC32 9 +#define AIROGSTATSD32 10 + +/* + * Leave gap of 40 commands after AIROGSTATSD32 + */ + +#define AIROPCAP AIROGSTATSD32 + 40 +#define AIROPVLIST AIROPCAP + 1 +#define AIROPSLIST AIROPVLIST + 1 +#define AIROPCFG AIROPSLIST + 1 +#define AIROPSIDS AIROPCFG + 1 +#define AIROPAPLIST AIROPSIDS + 1 +#define AIROPMACON AIROPAPLIST + 1 /* Enable mac */ +#define AIROPMACOFF AIROPMACON + 1 /* Disable mac */ +#define AIROPSTCLR AIROPMACOFF + 1 +#define AIROPWEPKEY AIROPSTCLR + 1 +#define AIROPWEPKEYNV AIROPWEPKEY + 1 +#define AIROPLEAPPWD AIROPWEPKEYNV + 1 +#define AIROPLEAPUSR AIROPLEAPPWD + 1 + +/* + * Another gap of 40 commands before flash codes + */ + +#define AIROFLSHRST AIROPWEPKEYNV + 40 +#define AIROFLSHGCHR AIROFLSHRST + 1 +#define AIROFLSHSTFL AIROFLSHGCHR + 1 +#define AIROFLSHPCHR AIROFLSHSTFL + 1 +#define AIROFLPUTBUF AIROFLSHPCHR + 1 +#define AIRORESTART AIROFLPUTBUF + 1 + +/* + * Struct to enable up to 65535 ioctl's + */ + +#define AIROMAGIC 0xa55a + +typedef struct aironet_ioctl { + unsigned short command; /* What to do */ + unsigned short len; /* Len of data */ + unsigned char *data; /* d-data */ +} airo_ioctl; + +#endif diff --git a/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an.c b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an.c new file mode 100644 index 0000000000..1d22322d8f --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an.c @@ -0,0 +1,3852 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD. + * + * Written by Bill Paul + * Electrical Engineering Department + * Columbia University, New York City + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * The Aironet 4500/4800 series cards come in PCMCIA, ISA and PCI form. + * This driver supports all three device types (PCI devices are supported + * through an extra PCI shim: /sys/dev/an/if_an_pci.c). ISA devices can be + * supported either using hard-coded IO port/IRQ settings or via Plug + * and Play. The 4500 series devices support 1Mbps and 2Mbps data rates. + * The 4800 devices support 1, 2, 5.5 and 11Mbps rates. + * + * Like the WaveLAN/IEEE cards, the Aironet NICs are all essentially + * PCMCIA devices. The ISA and PCI cards are a combination of a PCMCIA + * device and a PCMCIA to ISA or PCMCIA to PCI adapter card. There are + * a couple of important differences though: + * + * - Lucent ISA card looks to the host like a PCMCIA controller with + * a PCMCIA WaveLAN card inserted. This means that even desktop + * machines need to be configured with PCMCIA support in order to + * use WaveLAN/IEEE ISA cards. The Aironet cards on the other hand + * actually look like normal ISA and PCI devices to the host, so + * no PCMCIA controller support is needed + * + * The latter point results in a small gotcha. The Aironet PCMCIA + * cards can be configured for one of two operating modes depending + * on how the Vpp1 and Vpp2 programming voltages are set when the + * card is activated. In order to put the card in proper PCMCIA + * operation (where the CIS table is visible and the interface is + * programmed for PCMCIA operation), both Vpp1 and Vpp2 have to be + * set to 5 volts. FreeBSD by default doesn't set the Vpp voltages, + * which leaves the card in ISA/PCI mode, which prevents it from + * being activated as an PCMCIA device. + * + * Note that some PCMCIA controller software packages for Windows NT + * fail to set the voltages as well. + * + * The Aironet devices can operate in both station mode and access point + * mode. Typically, when programmed for station mode, the card can be set + * to automatically perform encapsulation/decapsulation of Ethernet II + * and 802.3 frames within 802.11 frames so that the host doesn't have + * to do it itself. This driver doesn't program the card that way: the + * driver handles all of the encapsulation/decapsulation itself. + */ + +#include "opt_inet.h" + +#ifdef INET +#define ANCACHE /* enable signal strength cache */ +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef ANCACHE +#include +#endif +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifdef INET +#include +#include +#include +#include +#endif + +#include + +#include + +#include +#include + +/* These are global because we need them in sys/pci/if_an_p.c. */ +static void an_reset(struct an_softc *); +static int an_init_mpi350_desc(struct an_softc *); +static int an_ioctl(struct ifnet *, u_long, caddr_t); +static void an_init(void *); +static int an_init_tx_ring(struct an_softc *); +static void an_start(struct ifnet *); +static void an_watchdog(struct ifnet *); +static void an_rxeof(struct an_softc *); +static void an_txeof(struct an_softc *, int); + +static void an_promisc(struct an_softc *, int); +static int an_cmd(struct an_softc *, int, int); +static int an_cmd_struct(struct an_softc *, struct an_command *, + struct an_reply *); +static int an_read_record(struct an_softc *, struct an_ltv_gen *); +static int an_write_record(struct an_softc *, struct an_ltv_gen *); +static int an_read_data(struct an_softc *, int, int, caddr_t, int); +static int an_write_data(struct an_softc *, int, int, caddr_t, int); +static int an_seek(struct an_softc *, int, int, int); +static int an_alloc_nicmem(struct an_softc *, int, int *); +static int an_dma_malloc(struct an_softc *, bus_size_t, struct an_dma_alloc *, + int); +static void an_dma_free(struct an_softc *, struct an_dma_alloc *); +static void an_dma_malloc_cb(void *, bus_dma_segment_t *, int, int); +static void an_stats_update(void *); +static void an_setdef(struct an_softc *, struct an_req *); +#ifdef ANCACHE +static void an_cache_store(struct an_softc *, struct ether_header *, + struct mbuf *, u_int8_t, u_int8_t); +#endif + +/* function definitions for use with the Cisco's Linux configuration + utilities +*/ + +static int readrids(struct ifnet*, struct aironet_ioctl*); +static int writerids(struct ifnet*, struct aironet_ioctl*); +static int flashcard(struct ifnet*, struct aironet_ioctl*); + +static int cmdreset(struct ifnet *); +static int setflashmode(struct ifnet *); +static int flashgchar(struct ifnet *,int,int); +static int flashpchar(struct ifnet *,int,int); +static int flashputbuf(struct ifnet *); +static int flashrestart(struct ifnet *); +static int WaitBusy(struct ifnet *, int); +static int unstickbusy(struct ifnet *); + +static void an_dump_record (struct an_softc *,struct an_ltv_gen *, + char *); + +static int an_media_change (struct ifnet *); +static void an_media_status (struct ifnet *, struct ifmediareq *); + +static int an_dump = 0; +static int an_cache_mode = 0; + +#define DBM 0 +#define PERCENT 1 +#define RAW 2 + +static char an_conf[256]; +static char an_conf_cache[256]; + +/* sysctl vars */ + +SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters"); + +/* XXX violate ethernet/netgraph callback hooks */ +extern void (*ng_ether_attach_p)(struct ifnet *ifp); +extern void (*ng_ether_detach_p)(struct ifnet *ifp); + +static int +sysctl_an_dump(SYSCTL_HANDLER_ARGS) +{ + int error, r, last; + char *s = an_conf; + + last = an_dump; + + switch (an_dump) { + case 0: + strcpy(an_conf, "off"); + break; + case 1: + strcpy(an_conf, "type"); + break; + case 2: + strcpy(an_conf, "dump"); + break; + default: + snprintf(an_conf, 5, "%x", an_dump); + break; + } + + error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req); + + if (strncmp(an_conf,"off", 3) == 0) { + an_dump = 0; + } + if (strncmp(an_conf,"dump", 4) == 0) { + an_dump = 1; + } + if (strncmp(an_conf,"type", 4) == 0) { + an_dump = 2; + } + if (*s == 'f') { + r = 0; + for (;;s++) { + if ((*s >= '0') && (*s <= '9')) { + r = r * 16 + (*s - '0'); + } else if ((*s >= 'a') && (*s <= 'f')) { + r = r * 16 + (*s - 'a' + 10); + } else { + break; + } + } + an_dump = r; + } + if (an_dump != last) + printf("Sysctl changed for Aironet driver\n"); + + return error; +} + +SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW, + 0, sizeof(an_conf), sysctl_an_dump, "A", ""); + +static int +sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS) +{ + int error, last; + + last = an_cache_mode; + + switch (an_cache_mode) { + case 1: + strcpy(an_conf_cache, "per"); + break; + case 2: + strcpy(an_conf_cache, "raw"); + break; + default: + strcpy(an_conf_cache, "dbm"); + break; + } + + error = sysctl_handle_string(oidp, an_conf_cache, + sizeof(an_conf_cache), req); + + if (strncmp(an_conf_cache,"dbm", 3) == 0) { + an_cache_mode = 0; + } + if (strncmp(an_conf_cache,"per", 3) == 0) { + an_cache_mode = 1; + } + if (strncmp(an_conf_cache,"raw", 3) == 0) { + an_cache_mode = 2; + } + + return error; +} + +SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW, + 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", ""); + +/* + * Setup the lock for PCI attachment since it skips the an_probe + * function. We need to setup the lock in an_probe since some + * operations need the lock. So we might as well create the + * lock in the probe. + */ +int +an_pci_probe(device_t dev) +{ + struct an_softc *sc = device_get_softc(dev); + + mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, + MTX_DEF | MTX_RECURSE); + + return(0); +} + +/* + * We probe for an Aironet 4500/4800 card by attempting to + * read the default SSID list. On reset, the first entry in + * the SSID list will contain the name "tsunami." If we don't + * find this, then there's no card present. + */ +int +an_probe(device_t dev) +{ + struct an_softc *sc = device_get_softc(dev); + struct an_ltv_ssidlist_new ssid; + int error; + + bzero((char *)&ssid, sizeof(ssid)); + + error = an_alloc_port(dev, 0, AN_IOSIZ); + if (error != 0) + return (0); + + /* can't do autoprobing */ + if (rman_get_start(sc->port_res) == -1) + return(0); + + /* + * We need to fake up a softc structure long enough + * to be able to issue commands and call some of the + * other routines. + */ + sc->an_bhandle = rman_get_bushandle(sc->port_res); + sc->an_btag = rman_get_bustag(sc->port_res); + sc->an_unit = device_get_unit(dev); + + ssid.an_len = sizeof(ssid); + ssid.an_type = AN_RID_SSIDLIST; + + /* Make sure interrupts are disabled. */ + sc->mpi350 = 0; + CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0); + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF); + + mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, + MTX_DEF | MTX_RECURSE); + AN_LOCK(sc); + an_reset(sc); + + if (an_cmd(sc, AN_CMD_READCFG, 0)) { + AN_UNLOCK(sc); + goto fail; + } + + if (an_read_record(sc, (struct an_ltv_gen *)&ssid)) { + AN_UNLOCK(sc); + goto fail; + } + + /* See if the ssid matches what we expect ... but doesn't have to */ + if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID)) { + AN_UNLOCK(sc); + goto fail; + } + + AN_UNLOCK(sc); + return(AN_IOSIZ); +fail: + mtx_destroy(&sc->an_mtx); + return(0); +} + +/* + * Allocate a port resource with the given resource id. + */ +int +an_alloc_port(device_t dev, int rid, int size) +{ + struct an_softc *sc = device_get_softc(dev); + struct resource *res; + + res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, + 0ul, ~0ul, size, RF_ACTIVE); + if (res) { + sc->port_rid = rid; + sc->port_res = res; + return (0); + } else { + return (ENOENT); + } +} + +/* + * Allocate a memory resource with the given resource id. + */ +int an_alloc_memory(device_t dev, int rid, int size) +{ + struct an_softc *sc = device_get_softc(dev); + struct resource *res; + + res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, + 0ul, ~0ul, size, RF_ACTIVE); + if (res) { + sc->mem_rid = rid; + sc->mem_res = res; + sc->mem_used = size; + return (0); + } else { + return (ENOENT); + } +} + +/* + * Allocate a auxilary memory resource with the given resource id. + */ +int an_alloc_aux_memory(device_t dev, int rid, int size) +{ + struct an_softc *sc = device_get_softc(dev); + struct resource *res; + + res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, + 0ul, ~0ul, size, RF_ACTIVE); + if (res) { + sc->mem_aux_rid = rid; + sc->mem_aux_res = res; + sc->mem_aux_used = size; + return (0); + } else { + return (ENOENT); + } +} + +/* + * Allocate an irq resource with the given resource id. + */ +int +an_alloc_irq(device_t dev, int rid, int flags) +{ + struct an_softc *sc = device_get_softc(dev); + struct resource *res; + + res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + (RF_ACTIVE | flags)); + if (res) { + sc->irq_rid = rid; + sc->irq_res = res; + return (0); + } else { + return (ENOENT); + } +} + +static void +an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + bus_addr_t *paddr = (bus_addr_t*) arg; + *paddr = segs->ds_addr; +} + +/* + * Alloc DMA memory and set the pointer to it + */ +static int +an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma, + int mapflags) +{ + int r; + + r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map); + if (r != 0) + goto fail_0; + + r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr, + BUS_DMA_NOWAIT, &dma->an_dma_map); + if (r != 0) + goto fail_1; + + r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr, + size, + an_dma_malloc_cb, + &dma->an_dma_paddr, + mapflags | BUS_DMA_NOWAIT); + if (r != 0) + goto fail_2; + + dma->an_dma_size = size; + return (0); + +fail_2: + bus_dmamap_unload(sc->an_dtag, dma->an_dma_map); +fail_1: + bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map); +fail_0: + bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map); + dma->an_dma_map = NULL; + return (r); +} + +static void +an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma) +{ + bus_dmamap_unload(sc->an_dtag, dma->an_dma_map); + bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map); + dma->an_dma_vaddr = 0; + bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map); +} + +/* + * Release all resources + */ +void +an_release_resources(device_t dev) +{ + struct an_softc *sc = device_get_softc(dev); + int i; + + if (sc->port_res) { + bus_release_resource(dev, SYS_RES_IOPORT, + sc->port_rid, sc->port_res); + sc->port_res = 0; + } + if (sc->mem_res) { + bus_release_resource(dev, SYS_RES_MEMORY, + sc->mem_rid, sc->mem_res); + sc->mem_res = 0; + } + if (sc->mem_aux_res) { + bus_release_resource(dev, SYS_RES_MEMORY, + sc->mem_aux_rid, sc->mem_aux_res); + sc->mem_aux_res = 0; + } + if (sc->irq_res) { + bus_release_resource(dev, SYS_RES_IRQ, + sc->irq_rid, sc->irq_res); + sc->irq_res = 0; + } + if (sc->an_rid_buffer.an_dma_paddr) { + an_dma_free(sc, &sc->an_rid_buffer); + } + for (i = 0; i < AN_MAX_RX_DESC; i++) + if (sc->an_rx_buffer[i].an_dma_paddr) { + an_dma_free(sc, &sc->an_rx_buffer[i]); + } + for (i = 0; i < AN_MAX_TX_DESC; i++) + if (sc->an_tx_buffer[i].an_dma_paddr) { + an_dma_free(sc, &sc->an_tx_buffer[i]); + } + if (sc->an_dtag) { + bus_dma_tag_destroy(sc->an_dtag); + } + +} + +int +an_init_mpi350_desc(struct an_softc *sc) +{ + struct an_command cmd_struct; + struct an_reply reply; + struct an_card_rid_desc an_rid_desc; + struct an_card_rx_desc an_rx_desc; + struct an_card_tx_desc an_tx_desc; + int i, desc; + + AN_LOCK_ASSERT(sc); + if(!sc->an_rid_buffer.an_dma_paddr) + an_dma_malloc(sc, AN_RID_BUFFER_SIZE, + &sc->an_rid_buffer, 0); + for (i = 0; i < AN_MAX_RX_DESC; i++) + if(!sc->an_rx_buffer[i].an_dma_paddr) + an_dma_malloc(sc, AN_RX_BUFFER_SIZE, + &sc->an_rx_buffer[i], 0); + for (i = 0; i < AN_MAX_TX_DESC; i++) + if(!sc->an_tx_buffer[i].an_dma_paddr) + an_dma_malloc(sc, AN_TX_BUFFER_SIZE, + &sc->an_tx_buffer[i], 0); + + /* + * Allocate RX descriptor + */ + bzero(&reply,sizeof(reply)); + cmd_struct.an_cmd = AN_CMD_ALLOC_DESC; + cmd_struct.an_parm0 = AN_DESCRIPTOR_RX; + cmd_struct.an_parm1 = AN_RX_DESC_OFFSET; + cmd_struct.an_parm2 = AN_MAX_RX_DESC; + if (an_cmd_struct(sc, &cmd_struct, &reply)) { + printf("an%d: failed to allocate RX descriptor\n", + sc->an_unit); + return(EIO); + } + + for (desc = 0; desc < AN_MAX_RX_DESC; desc++) { + bzero(&an_rx_desc, sizeof(an_rx_desc)); + an_rx_desc.an_valid = 1; + an_rx_desc.an_len = AN_RX_BUFFER_SIZE; + an_rx_desc.an_done = 0; + an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr; + + for (i = 0; i < sizeof(an_rx_desc) / 4; i++) + CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET + + (desc * sizeof(an_rx_desc)) + + (i * 4), + ((u_int32_t *)(void *)&an_rx_desc)[i]); + } + + /* + * Allocate TX descriptor + */ + + bzero(&reply,sizeof(reply)); + cmd_struct.an_cmd = AN_CMD_ALLOC_DESC; + cmd_struct.an_parm0 = AN_DESCRIPTOR_TX; + cmd_struct.an_parm1 = AN_TX_DESC_OFFSET; + cmd_struct.an_parm2 = AN_MAX_TX_DESC; + if (an_cmd_struct(sc, &cmd_struct, &reply)) { + printf("an%d: failed to allocate TX descriptor\n", + sc->an_unit); + return(EIO); + } + + for (desc = 0; desc < AN_MAX_TX_DESC; desc++) { + bzero(&an_tx_desc, sizeof(an_tx_desc)); + an_tx_desc.an_offset = 0; + an_tx_desc.an_eoc = 0; + an_tx_desc.an_valid = 0; + an_tx_desc.an_len = 0; + an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr; + + for (i = 0; i < sizeof(an_tx_desc) / 4; i++) + CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET + + (desc * sizeof(an_tx_desc)) + + (i * 4), + ((u_int32_t *)(void *)&an_tx_desc)[i]); + } + + /* + * Allocate RID descriptor + */ + + bzero(&reply,sizeof(reply)); + cmd_struct.an_cmd = AN_CMD_ALLOC_DESC; + cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW; + cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET; + cmd_struct.an_parm2 = 1; + if (an_cmd_struct(sc, &cmd_struct, &reply)) { + printf("an%d: failed to allocate host descriptor\n", + sc->an_unit); + return(EIO); + } + + bzero(&an_rid_desc, sizeof(an_rid_desc)); + an_rid_desc.an_valid = 1; + an_rid_desc.an_len = AN_RID_BUFFER_SIZE; + an_rid_desc.an_rid = 0; + an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr; + + for (i = 0; i < sizeof(an_rid_desc) / 4; i++) + CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4, + ((u_int32_t *)(void *)&an_rid_desc)[i]); + + return(0); +} + +int +an_attach(struct an_softc *sc, int unit, int flags) +{ + struct ifnet *ifp; + int error = EIO; + int i, nrate, mword; + u_int8_t r; + + ifp = sc->an_ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + printf("an%d: can not if_alloc()\n", sc->an_unit); + goto fail; + } + + sc->an_gone = 0; + sc->an_associated = 0; + sc->an_monitor = 0; + sc->an_was_monitor = 0; + sc->an_flash_buffer = NULL; + + /* Reset the NIC. */ + AN_LOCK(sc); + an_reset(sc); + if (sc->mpi350) { + error = an_init_mpi350_desc(sc); + if (error) + goto fail; + } + + /* Load factory config */ + if (an_cmd(sc, AN_CMD_READCFG, 0)) { + printf("an%d: failed to load config data\n", sc->an_unit); + goto fail; + } + + /* Read the current configuration */ + sc->an_config.an_type = AN_RID_GENCONFIG; + sc->an_config.an_len = sizeof(struct an_ltv_genconfig); + if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) { + printf("an%d: read record failed\n", sc->an_unit); + goto fail; + } + + /* Read the card capabilities */ + sc->an_caps.an_type = AN_RID_CAPABILITIES; + sc->an_caps.an_len = sizeof(struct an_ltv_caps); + if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) { + printf("an%d: read record failed\n", sc->an_unit); + goto fail; + } + + /* Read ssid list */ + sc->an_ssidlist.an_type = AN_RID_SSIDLIST; + sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new); + if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) { + printf("an%d: read record failed\n", sc->an_unit); + goto fail; + } + + /* Read AP list */ + sc->an_aplist.an_type = AN_RID_APLIST; + sc->an_aplist.an_len = sizeof(struct an_ltv_aplist); + if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) { + printf("an%d: read record failed\n", sc->an_unit); + goto fail; + } + +#ifdef ANCACHE + /* Read the RSSI <-> dBm map */ + sc->an_have_rssimap = 0; + if (sc->an_caps.an_softcaps & 8) { + sc->an_rssimap.an_type = AN_RID_RSSI_MAP; + sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map); + if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) { + printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit); + } else { + printf("an%d: got RSSI <-> dBM map\n", sc->an_unit); + sc->an_have_rssimap = 1; + } + } else { + printf("an%d: no RSSI <-> dBM map\n", sc->an_unit); + } +#endif + AN_UNLOCK(sc); + + ifp->if_softc = sc; + sc->an_unit = unit; + if_initname(ifp, device_get_name(sc->an_dev), + device_get_unit(sc->an_dev)); + ifp->if_mtu = ETHERMTU; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = an_ioctl; + ifp->if_start = an_start; + ifp->if_watchdog = an_watchdog; + ifp->if_init = an_init; + ifp->if_baudrate = 10000000; + IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); + ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; + IFQ_SET_READY(&ifp->if_snd); + + bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename)); + bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename, + sizeof(AN_DEFAULT_NODENAME) - 1); + + bzero(sc->an_ssidlist.an_entry[0].an_ssid, + sizeof(sc->an_ssidlist.an_entry[0].an_ssid)); + bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid, + sizeof(AN_DEFAULT_NETNAME) - 1); + sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME); + + sc->an_config.an_opmode = + AN_OPMODE_INFRASTRUCTURE_STATION; + + sc->an_tx_rate = 0; + bzero((char *)&sc->an_stats, sizeof(sc->an_stats)); + + nrate = 8; + + ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status); + if_printf(ifp, "supported rates: "); +#define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \ + IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL) + ADD(IFM_AUTO, 0); + ADD(IFM_AUTO, IFM_IEEE80211_ADHOC); + for (i = 0; i < nrate; i++) { + r = sc->an_caps.an_rates[i]; + mword = ieee80211_rate2media(NULL, r, IEEE80211_T_DS); + if (mword == 0) + continue; + printf("%s%d%sMbps", (i != 0 ? " " : ""), + (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : "")); + ADD(mword, 0); + ADD(mword, IFM_IEEE80211_ADHOC); + } + printf("\n"); + ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, + IFM_AUTO, 0, 0)); +#undef ADD + + /* + * Call MI attach routine. + */ + + ether_ifattach(ifp, sc->an_caps.an_oemaddr); + callout_init_mtx(&sc->an_stat_ch, &sc->an_mtx, 0); + + return(0); +fail: + AN_UNLOCK(sc); + mtx_destroy(&sc->an_mtx); + if (ifp != NULL) + if_free(ifp); + return(error); +} + +int +an_detach(device_t dev) +{ + struct an_softc *sc = device_get_softc(dev); + struct ifnet *ifp = sc->an_ifp; + + if (sc->an_gone) { + device_printf(dev,"already unloaded\n"); + return(0); + } + AN_LOCK(sc); + an_stop(sc); + sc->an_gone = 1; + ifmedia_removeall(&sc->an_ifmedia); + ifp->if_drv_flags &= ~IFF_DRV_RUNNING; + AN_UNLOCK(sc); + ether_ifdetach(ifp); + bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); + callout_drain(&sc->an_stat_ch); + if_free(ifp); + an_release_resources(dev); + mtx_destroy(&sc->an_mtx); + return (0); +} + +static void +an_rxeof(struct an_softc *sc) +{ + struct ifnet *ifp; + struct ether_header *eh; + struct ieee80211_frame *ih; + struct an_rxframe rx_frame; + struct an_rxframe_802_3 rx_frame_802_3; + struct mbuf *m; + int len, id, error = 0, i, count = 0; + int ieee80211_header_len; + u_char *bpf_buf; + u_short fc1; + struct an_card_rx_desc an_rx_desc; + u_int8_t *buf; + + AN_LOCK_ASSERT(sc); + + ifp = sc->an_ifp; + + if (!sc->mpi350) { + id = CSR_READ_2(sc, AN_RX_FID); + + if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) { + /* read raw 802.11 packet */ + bpf_buf = sc->buf_802_11; + + /* read header */ + if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame, + sizeof(rx_frame))) { + ifp->if_ierrors++; + return; + } + + /* + * skip beacon by default since this increases the + * system load a lot + */ + + if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) && + (rx_frame.an_frame_ctl & + IEEE80211_FC0_SUBTYPE_BEACON)) { + return; + } + + if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) { + len = rx_frame.an_rx_payload_len + + sizeof(rx_frame); + /* Check for insane frame length */ + if (len > sizeof(sc->buf_802_11)) { + printf("an%d: oversized packet " + "received (%d, %d)\n", + sc->an_unit, len, MCLBYTES); + ifp->if_ierrors++; + return; + } + + bcopy((char *)&rx_frame, + bpf_buf, sizeof(rx_frame)); + + error = an_read_data(sc, id, sizeof(rx_frame), + (caddr_t)bpf_buf+sizeof(rx_frame), + rx_frame.an_rx_payload_len); + } else { + fc1=rx_frame.an_frame_ctl >> 8; + ieee80211_header_len = + sizeof(struct ieee80211_frame); + if ((fc1 & IEEE80211_FC1_DIR_TODS) && + (fc1 & IEEE80211_FC1_DIR_FROMDS)) { + ieee80211_header_len += ETHER_ADDR_LEN; + } + + len = rx_frame.an_rx_payload_len + + ieee80211_header_len; + /* Check for insane frame length */ + if (len > sizeof(sc->buf_802_11)) { + printf("an%d: oversized packet " + "received (%d, %d)\n", + sc->an_unit, len, MCLBYTES); + ifp->if_ierrors++; + return; + } + + ih = (struct ieee80211_frame *)bpf_buf; + + bcopy((char *)&rx_frame.an_frame_ctl, + (char *)ih, ieee80211_header_len); + + error = an_read_data(sc, id, sizeof(rx_frame) + + rx_frame.an_gaplen, + (caddr_t)ih +ieee80211_header_len, + rx_frame.an_rx_payload_len); + } + /* dump raw 802.11 packet to bpf and skip ip stack */ + BPF_TAP(ifp, bpf_buf, len); + } else { + MGETHDR(m, M_DONTWAIT, MT_DATA); + if (m == NULL) { + ifp->if_ierrors++; + return; + } + MCLGET(m, M_DONTWAIT); + if (!(m->m_flags & M_EXT)) { + m_freem(m); + ifp->if_ierrors++; + return; + } + m->m_pkthdr.rcvif = ifp; + /* Read Ethernet encapsulated packet */ + +#ifdef ANCACHE + /* Read NIC frame header */ + if (an_read_data(sc, id, 0, (caddr_t)&rx_frame, + sizeof(rx_frame))) { + m_freem(m); + ifp->if_ierrors++; + return; + } +#endif + /* Read in the 802_3 frame header */ + if (an_read_data(sc, id, 0x34, + (caddr_t)&rx_frame_802_3, + sizeof(rx_frame_802_3))) { + m_freem(m); + ifp->if_ierrors++; + return; + } + if (rx_frame_802_3.an_rx_802_3_status != 0) { + m_freem(m); + ifp->if_ierrors++; + return; + } + /* Check for insane frame length */ + len = rx_frame_802_3.an_rx_802_3_payload_len; + if (len > sizeof(sc->buf_802_11)) { + m_freem(m); + printf("an%d: oversized packet " + "received (%d, %d)\n", + sc->an_unit, len, MCLBYTES); + ifp->if_ierrors++; + return; + } + m->m_pkthdr.len = m->m_len = + rx_frame_802_3.an_rx_802_3_payload_len + 12; + + eh = mtod(m, struct ether_header *); + + bcopy((char *)&rx_frame_802_3.an_rx_dst_addr, + (char *)&eh->ether_dhost, ETHER_ADDR_LEN); + bcopy((char *)&rx_frame_802_3.an_rx_src_addr, + (char *)&eh->ether_shost, ETHER_ADDR_LEN); + + /* in mbuf header type is just before payload */ + error = an_read_data(sc, id, 0x44, + (caddr_t)&(eh->ether_type), + rx_frame_802_3.an_rx_802_3_payload_len); + + if (error) { + m_freem(m); + ifp->if_ierrors++; + return; + } + ifp->if_ipackets++; + + /* Receive packet. */ +#ifdef ANCACHE + an_cache_store(sc, eh, m, + rx_frame.an_rx_signal_strength, + rx_frame.an_rsvd0); +#endif + AN_UNLOCK(sc); + (*ifp->if_input)(ifp, m); + AN_LOCK(sc); + } + + } else { /* MPI-350 */ + for (count = 0; count < AN_MAX_RX_DESC; count++){ + for (i = 0; i < sizeof(an_rx_desc) / 4; i++) + ((u_int32_t *)(void *)&an_rx_desc)[i] + = CSR_MEM_AUX_READ_4(sc, + AN_RX_DESC_OFFSET + + (count * sizeof(an_rx_desc)) + + (i * 4)); + + if (an_rx_desc.an_done && !an_rx_desc.an_valid) { + buf = sc->an_rx_buffer[count].an_dma_vaddr; + + MGETHDR(m, M_DONTWAIT, MT_DATA); + if (m == NULL) { + ifp->if_ierrors++; + return; + } + MCLGET(m, M_DONTWAIT); + if (!(m->m_flags & M_EXT)) { + m_freem(m); + ifp->if_ierrors++; + return; + } + m->m_pkthdr.rcvif = ifp; + /* Read Ethernet encapsulated packet */ + + /* + * No ANCACHE support since we just get back + * an Ethernet packet no 802.11 info + */ +#if 0 +#ifdef ANCACHE + /* Read NIC frame header */ + bcopy(buf, (caddr_t)&rx_frame, + sizeof(rx_frame)); +#endif +#endif + /* Check for insane frame length */ + len = an_rx_desc.an_len + 12; + if (len > MCLBYTES) { + m_freem(m); + printf("an%d: oversized packet " + "received (%d, %d)\n", + sc->an_unit, len, MCLBYTES); + ifp->if_ierrors++; + return; + } + + m->m_pkthdr.len = m->m_len = + an_rx_desc.an_len + 12; + + eh = mtod(m, struct ether_header *); + + bcopy(buf, (char *)eh, + m->m_pkthdr.len); + + ifp->if_ipackets++; + + /* Receive packet. */ +#if 0 +#ifdef ANCACHE + an_cache_store(sc, eh, m, + rx_frame.an_rx_signal_strength, + rx_frame.an_rsvd0); +#endif +#endif + AN_UNLOCK(sc); + (*ifp->if_input)(ifp, m); + AN_LOCK(sc); + + an_rx_desc.an_valid = 1; + an_rx_desc.an_len = AN_RX_BUFFER_SIZE; + an_rx_desc.an_done = 0; + an_rx_desc.an_phys = + sc->an_rx_buffer[count].an_dma_paddr; + + for (i = 0; i < sizeof(an_rx_desc) / 4; i++) + CSR_MEM_AUX_WRITE_4(sc, + AN_RX_DESC_OFFSET + + (count * sizeof(an_rx_desc)) + + (i * 4), + ((u_int32_t *)(void *)&an_rx_desc)[i]); + + } else { + printf("an%d: Didn't get valid RX packet " + "%x %x %d\n", + sc->an_unit, + an_rx_desc.an_done, + an_rx_desc.an_valid, an_rx_desc.an_len); + } + } + } +} + +static void +an_txeof(struct an_softc *sc, int status) +{ + struct ifnet *ifp; + int id, i; + + AN_LOCK_ASSERT(sc); + ifp = sc->an_ifp; + + ifp->if_timer = 0; + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + + if (!sc->mpi350) { + id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350)); + + if (status & AN_EV_TX_EXC) { + ifp->if_oerrors++; + } else + ifp->if_opackets++; + + for (i = 0; i < AN_TX_RING_CNT; i++) { + if (id == sc->an_rdata.an_tx_ring[i]) { + sc->an_rdata.an_tx_ring[i] = 0; + break; + } + } + + AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT); + } else { /* MPI 350 */ + id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350)); + if (!sc->an_rdata.an_tx_empty){ + if (status & AN_EV_TX_EXC) { + ifp->if_oerrors++; + } else + ifp->if_opackets++; + AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC); + if (sc->an_rdata.an_tx_prod == + sc->an_rdata.an_tx_cons) + sc->an_rdata.an_tx_empty = 1; + } + } + + return; +} + +/* + * We abuse the stats updater to check the current NIC status. This + * is important because we don't want to allow transmissions until + * the NIC has synchronized to the current cell (either as the master + * in an ad-hoc group, or as a station connected to an access point). + * + * Note that this function will be called via callout(9) with a lock held. + */ +static void +an_stats_update(void *xsc) +{ + struct an_softc *sc; + struct ifnet *ifp; + + sc = xsc; + AN_LOCK_ASSERT(sc); + ifp = sc->an_ifp; + + sc->an_status.an_type = AN_RID_STATUS; + sc->an_status.an_len = sizeof(struct an_ltv_status); + if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_status)) + return; + + if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC) + sc->an_associated = 1; + else + sc->an_associated = 0; + + /* Don't do this while we're transmitting */ + if (ifp->if_drv_flags & IFF_DRV_OACTIVE) { + callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc); + return; + } + + sc->an_stats.an_len = sizeof(struct an_ltv_stats); + sc->an_stats.an_type = AN_RID_32BITS_CUM; + if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len)) + return; + + callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc); + + return; +} + +void +an_intr(void *xsc) +{ + struct an_softc *sc; + struct ifnet *ifp; + u_int16_t status; + + sc = (struct an_softc*)xsc; + + AN_LOCK(sc); + + if (sc->an_gone) { + AN_UNLOCK(sc); + return; + } + + ifp = sc->an_ifp; + + /* Disable interrupts. */ + CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0); + + status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)); + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350)); + + if (status & AN_EV_MIC) { + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC); + } + + if (status & AN_EV_LINKSTAT) { + if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350)) + == AN_LINKSTAT_ASSOCIATED) + sc->an_associated = 1; + else + sc->an_associated = 0; + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT); + } + + if (status & AN_EV_RX) { + an_rxeof(sc); + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX); + } + + if (sc->mpi350 && status & AN_EV_TX_CPY) { + an_txeof(sc, status); + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY); + } + + if (status & AN_EV_TX) { + an_txeof(sc, status); + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX); + } + + if (status & AN_EV_TX_EXC) { + an_txeof(sc, status); + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC); + } + + if (status & AN_EV_ALLOC) + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC); + + /* Re-enable interrupts. */ + CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350)); + + if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd)) + an_start(ifp); + + AN_UNLOCK(sc); + + return; +} + + +static int +an_cmd_struct(struct an_softc *sc, struct an_command *cmd, + struct an_reply *reply) +{ + int i; + + AN_LOCK_ASSERT(sc); + for (i = 0; i != AN_TIMEOUT; i++) { + if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) { + DELAY(1000); + } else + break; + } + + if( i == AN_TIMEOUT) { + printf("BUSY\n"); + return(ETIMEDOUT); + } + + CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0); + CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1); + CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2); + CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd); + + for (i = 0; i < AN_TIMEOUT; i++) { + if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD) + break; + DELAY(1000); + } + + reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350)); + reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350)); + reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350)); + reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350)); + + if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), + AN_EV_CLR_STUCK_BUSY); + + /* Ack the command */ + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD); + + if (i == AN_TIMEOUT) + return(ETIMEDOUT); + + return(0); +} + +static int +an_cmd(struct an_softc *sc, int cmd, int val) +{ + int i, s = 0; + + AN_LOCK_ASSERT(sc); + CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val); + CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0); + CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0); + CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd); + + for (i = 0; i < AN_TIMEOUT; i++) { + if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD) + break; + else { + if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd) + CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd); + } + } + + for (i = 0; i < AN_TIMEOUT; i++) { + CSR_READ_2(sc, AN_RESP0(sc->mpi350)); + CSR_READ_2(sc, AN_RESP1(sc->mpi350)); + CSR_READ_2(sc, AN_RESP2(sc->mpi350)); + s = CSR_READ_2(sc, AN_STATUS(sc->mpi350)); + if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE)) + break; + } + + /* Ack the command */ + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD); + + if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY); + + if (i == AN_TIMEOUT) + return(ETIMEDOUT); + + return(0); +} + +/* + * This reset sequence may look a little strange, but this is the + * most reliable method I've found to really kick the NIC in the + * head and force it to reboot correctly. + */ +static void +an_reset(struct an_softc *sc) +{ + if (sc->an_gone) + return; + + AN_LOCK_ASSERT(sc); + an_cmd(sc, AN_CMD_ENABLE, 0); + an_cmd(sc, AN_CMD_FW_RESTART, 0); + an_cmd(sc, AN_CMD_NOOP2, 0); + + if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT) + printf("an%d: reset failed\n", sc->an_unit); + + an_cmd(sc, AN_CMD_DISABLE, 0); + + return; +} + +/* + * Read an LTV record from the NIC. + */ +static int +an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv) +{ + struct an_ltv_gen *an_ltv; + struct an_card_rid_desc an_rid_desc; + struct an_command cmd; + struct an_reply reply; + u_int16_t *ptr; + u_int8_t *ptr2; + int i, len; + + AN_LOCK_ASSERT(sc); + if (ltv->an_len < 4 || ltv->an_type == 0) + return(EINVAL); + + if (!sc->mpi350){ + /* Tell the NIC to enter record read mode. */ + if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) { + printf("an%d: RID access failed\n", sc->an_unit); + return(EIO); + } + + /* Seek to the record. */ + if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) { + printf("an%d: seek to record failed\n", sc->an_unit); + return(EIO); + } + + /* + * Read the length and record type and make sure they + * match what we expect (this verifies that we have enough + * room to hold all of the returned data). + * Length includes type but not length. + */ + len = CSR_READ_2(sc, AN_DATA1); + if (len > (ltv->an_len - 2)) { + printf("an%d: record length mismatch -- expected %d, " + "got %d for Rid %x\n", sc->an_unit, + ltv->an_len - 2, len, ltv->an_type); + len = ltv->an_len - 2; + } else { + ltv->an_len = len + 2; + } + + /* Now read the data. */ + len -= 2; /* skip the type */ + ptr = <v->an_val; + for (i = len; i > 1; i -= 2) + *ptr++ = CSR_READ_2(sc, AN_DATA1); + if (i) { + ptr2 = (u_int8_t *)ptr; + *ptr2 = CSR_READ_1(sc, AN_DATA1); + } + } else { /* MPI-350 */ + if (!sc->an_rid_buffer.an_dma_vaddr) + return(EIO); + an_rid_desc.an_valid = 1; + an_rid_desc.an_len = AN_RID_BUFFER_SIZE; + an_rid_desc.an_rid = 0; + an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr; + bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE); + + bzero(&cmd, sizeof(cmd)); + bzero(&reply, sizeof(reply)); + cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ; + cmd.an_parm0 = ltv->an_type; + + for (i = 0; i < sizeof(an_rid_desc) / 4; i++) + CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4, + ((u_int32_t *)(void *)&an_rid_desc)[i]); + + if (an_cmd_struct(sc, &cmd, &reply) + || reply.an_status & AN_CMD_QUAL_MASK) { + printf("an%d: failed to read RID %x %x %x %x %x, %d\n", + sc->an_unit, ltv->an_type, + reply.an_status, + reply.an_resp0, + reply.an_resp1, + reply.an_resp2, + i); + return(EIO); + } + + an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr; + if (an_ltv->an_len + 2 < an_rid_desc.an_len) { + an_rid_desc.an_len = an_ltv->an_len; + } + + len = an_rid_desc.an_len; + if (len > (ltv->an_len - 2)) { + printf("an%d: record length mismatch -- expected %d, " + "got %d for Rid %x\n", sc->an_unit, + ltv->an_len - 2, len, ltv->an_type); + len = ltv->an_len - 2; + } else { + ltv->an_len = len + 2; + } + bcopy(&an_ltv->an_type, + <v->an_val, + len); + } + + if (an_dump) + an_dump_record(sc, ltv, "Read"); + + return(0); +} + +/* + * Same as read, except we inject data instead of reading it. + */ +static int +an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv) +{ + struct an_card_rid_desc an_rid_desc; + struct an_command cmd; + struct an_reply reply; + u_int16_t *ptr; + u_int8_t *ptr2; + int i, len; + + AN_LOCK_ASSERT(sc); + if (an_dump) + an_dump_record(sc, ltv, "Write"); + + if (!sc->mpi350){ + if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) + return(EIO); + + if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) + return(EIO); + + /* + * Length includes type but not length. + */ + len = ltv->an_len - 2; + CSR_WRITE_2(sc, AN_DATA1, len); + + len -= 2; /* skip the type */ + ptr = <v->an_val; + for (i = len; i > 1; i -= 2) + CSR_WRITE_2(sc, AN_DATA1, *ptr++); + if (i) { + ptr2 = (u_int8_t *)ptr; + CSR_WRITE_1(sc, AN_DATA0, *ptr2); + } + + if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type)) + return(EIO); + } else { + /* MPI-350 */ + + for (i = 0; i != AN_TIMEOUT; i++) { + if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) + & AN_CMD_BUSY) { + DELAY(10); + } else + break; + } + if (i == AN_TIMEOUT) { + printf("BUSY\n"); + } + + an_rid_desc.an_valid = 1; + an_rid_desc.an_len = ltv->an_len - 2; + an_rid_desc.an_rid = ltv->an_type; + an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr; + + bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr, + an_rid_desc.an_len); + + bzero(&cmd,sizeof(cmd)); + bzero(&reply,sizeof(reply)); + cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE; + cmd.an_parm0 = ltv->an_type; + + for (i = 0; i < sizeof(an_rid_desc) / 4; i++) + CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4, + ((u_int32_t *)(void *)&an_rid_desc)[i]); + + DELAY(100000); + + if ((i = an_cmd_struct(sc, &cmd, &reply))) { + printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n", + sc->an_unit, ltv->an_type, + reply.an_status, + reply.an_resp0, + reply.an_resp1, + reply.an_resp2, + i); + return(EIO); + } + + + if (reply.an_status & AN_CMD_QUAL_MASK) { + printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n", + sc->an_unit, ltv->an_type, + reply.an_status, + reply.an_resp0, + reply.an_resp1, + reply.an_resp2, + i); + return(EIO); + } + DELAY(100000); + } + + return(0); +} + +static void +an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string) +{ + u_int8_t *ptr2; + int len; + int i; + int count = 0; + char buf[17], temp; + + len = ltv->an_len - 4; + printf("an%d: RID %4x, Length %4d, Mode %s\n", + sc->an_unit, ltv->an_type, ltv->an_len - 4, string); + + if (an_dump == 1 || (an_dump == ltv->an_type)) { + printf("an%d:\t", sc->an_unit); + bzero(buf,sizeof(buf)); + + ptr2 = (u_int8_t *)<v->an_val; + for (i = len; i > 0; i--) { + printf("%02x ", *ptr2); + + temp = *ptr2++; + if (isprint(temp)) + buf[count] = temp; + else + buf[count] = '.'; + if (++count == 16) { + count = 0; + printf("%s\n",buf); + printf("an%d:\t", sc->an_unit); + bzero(buf,sizeof(buf)); + } + } + for (; count != 16; count++) { + printf(" "); + } + printf(" %s\n",buf); + } +} + +static int +an_seek(struct an_softc *sc, int id, int off, int chan) +{ + int i; + int selreg, offreg; + + switch (chan) { + case AN_BAP0: + selreg = AN_SEL0; + offreg = AN_OFF0; + break; + case AN_BAP1: + selreg = AN_SEL1; + offreg = AN_OFF1; + break; + default: + printf("an%d: invalid data path: %x\n", sc->an_unit, chan); + return(EIO); + } + + CSR_WRITE_2(sc, selreg, id); + CSR_WRITE_2(sc, offreg, off); + + for (i = 0; i < AN_TIMEOUT; i++) { + if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR))) + break; + } + + if (i == AN_TIMEOUT) + return(ETIMEDOUT); + + return(0); +} + +static int +an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len) +{ + int i; + u_int16_t *ptr; + u_int8_t *ptr2; + + if (off != -1) { + if (an_seek(sc, id, off, AN_BAP1)) + return(EIO); + } + + ptr = (u_int16_t *)buf; + for (i = len; i > 1; i -= 2) + *ptr++ = CSR_READ_2(sc, AN_DATA1); + if (i) { + ptr2 = (u_int8_t *)ptr; + *ptr2 = CSR_READ_1(sc, AN_DATA1); + } + + return(0); +} + +static int +an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len) +{ + int i; + u_int16_t *ptr; + u_int8_t *ptr2; + + if (off != -1) { + if (an_seek(sc, id, off, AN_BAP0)) + return(EIO); + } + + ptr = (u_int16_t *)buf; + for (i = len; i > 1; i -= 2) + CSR_WRITE_2(sc, AN_DATA0, *ptr++); + if (i) { + ptr2 = (u_int8_t *)ptr; + CSR_WRITE_1(sc, AN_DATA0, *ptr2); + } + + return(0); +} + +/* + * Allocate a region of memory inside the NIC and zero + * it out. + */ +static int +an_alloc_nicmem(struct an_softc *sc, int len, int *id) +{ + int i; + + if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) { + printf("an%d: failed to allocate %d bytes on NIC\n", + sc->an_unit, len); + return(ENOMEM); + } + + for (i = 0; i < AN_TIMEOUT; i++) { + if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC) + break; + } + + if (i == AN_TIMEOUT) + return(ETIMEDOUT); + + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC); + *id = CSR_READ_2(sc, AN_ALLOC_FID); + + if (an_seek(sc, *id, 0, AN_BAP0)) + return(EIO); + + for (i = 0; i < len / 2; i++) + CSR_WRITE_2(sc, AN_DATA0, 0); + + return(0); +} + +static void +an_setdef(struct an_softc *sc, struct an_req *areq) +{ + struct ifnet *ifp; + struct an_ltv_genconfig *cfg; + struct an_ltv_ssidlist_new *ssid; + struct an_ltv_aplist *ap; + struct an_ltv_gen *sp; + + ifp = sc->an_ifp; + + AN_LOCK_ASSERT(sc); + switch (areq->an_type) { + case AN_RID_GENCONFIG: + cfg = (struct an_ltv_genconfig *)areq; + + bcopy((char *)&cfg->an_macaddr, IF_LLADDR(sc->an_ifp), + ETHER_ADDR_LEN); + + bcopy((char *)cfg, (char *)&sc->an_config, + sizeof(struct an_ltv_genconfig)); + break; + case AN_RID_SSIDLIST: + ssid = (struct an_ltv_ssidlist_new *)areq; + bcopy((char *)ssid, (char *)&sc->an_ssidlist, + sizeof(struct an_ltv_ssidlist_new)); + break; + case AN_RID_APLIST: + ap = (struct an_ltv_aplist *)areq; + bcopy((char *)ap, (char *)&sc->an_aplist, + sizeof(struct an_ltv_aplist)); + break; + case AN_RID_TX_SPEED: + sp = (struct an_ltv_gen *)areq; + sc->an_tx_rate = sp->an_val; + + /* Read the current configuration */ + sc->an_config.an_type = AN_RID_GENCONFIG; + sc->an_config.an_len = sizeof(struct an_ltv_genconfig); + an_read_record(sc, (struct an_ltv_gen *)&sc->an_config); + cfg = &sc->an_config; + + /* clear other rates and set the only one we want */ + bzero(cfg->an_rates, sizeof(cfg->an_rates)); + cfg->an_rates[0] = sc->an_tx_rate; + + /* Save the new rate */ + sc->an_config.an_type = AN_RID_GENCONFIG; + sc->an_config.an_len = sizeof(struct an_ltv_genconfig); + break; + case AN_RID_WEP_TEMP: + /* Cache the temp keys */ + bcopy(areq, + &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex], + sizeof(struct an_ltv_key)); + case AN_RID_WEP_PERM: + case AN_RID_LEAPUSERNAME: + case AN_RID_LEAPPASSWORD: + AN_UNLOCK(sc); + an_init(sc); + AN_LOCK(sc); + + /* Disable the MAC. */ + an_cmd(sc, AN_CMD_DISABLE, 0); + + /* Write the key */ + an_write_record(sc, (struct an_ltv_gen *)areq); + + /* Turn the MAC back on. */ + an_cmd(sc, AN_CMD_ENABLE, 0); + + break; + case AN_RID_MONITOR_MODE: + cfg = (struct an_ltv_genconfig *)areq; + bpfdetach(ifp); + if (ng_ether_detach_p != NULL) + (*ng_ether_detach_p) (ifp); + sc->an_monitor = cfg->an_len; + + if (sc->an_monitor & AN_MONITOR) { + if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) { + bpfattach(ifp, DLT_AIRONET_HEADER, + sizeof(struct ether_header)); + } else { + bpfattach(ifp, DLT_IEEE802_11, + sizeof(struct ether_header)); + } + } else { + bpfattach(ifp, DLT_EN10MB, + sizeof(struct ether_header)); + if (ng_ether_attach_p != NULL) + (*ng_ether_attach_p) (ifp); + } + break; + default: + printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type); + return; + } + + + /* Reinitialize the card. */ + if (ifp->if_flags) { + AN_UNLOCK(sc); + an_init(sc); + AN_LOCK(sc); + } + + return; +} + +/* + * Derived from Linux driver to enable promiscious mode. + */ + +static void +an_promisc(struct an_softc *sc, int promisc) +{ + AN_LOCK_ASSERT(sc); + if (sc->an_was_monitor) { + an_reset(sc); + if (sc->mpi350) + an_init_mpi350_desc(sc); + } + if (sc->an_monitor || sc->an_was_monitor) { + AN_UNLOCK(sc); + an_init(sc); + AN_LOCK(sc); + } + + sc->an_was_monitor = sc->an_monitor; + an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0); + + return; +} + +static int +an_ioctl(struct ifnet *ifp, u_long command, caddr_t data) +{ + int error = 0; + int len; + int i, max; + struct an_softc *sc; + struct ifreq *ifr; + struct thread *td = curthread; + struct ieee80211req *ireq; + struct ieee80211_channel ch; + u_int8_t tmpstr[IEEE80211_NWID_LEN*2]; + u_int8_t *tmpptr; + struct an_ltv_genconfig *config; + struct an_ltv_key *key; + struct an_ltv_status *status; + struct an_ltv_ssidlist_new *ssids; + int mode; + struct aironet_ioctl l_ioctl; + + sc = ifp->if_softc; + ifr = (struct ifreq *)data; + ireq = (struct ieee80211req *)data; + + config = (struct an_ltv_genconfig *)&sc->areq; + key = (struct an_ltv_key *)&sc->areq; + status = (struct an_ltv_status *)&sc->areq; + ssids = (struct an_ltv_ssidlist_new *)&sc->areq; + + if (sc->an_gone) { + error = ENODEV; + goto out; + } + + switch (command) { + case SIOCSIFFLAGS: + AN_LOCK(sc); + if (ifp->if_flags & IFF_UP) { + if (ifp->if_drv_flags & IFF_DRV_RUNNING && + ifp->if_flags & IFF_PROMISC && + !(sc->an_if_flags & IFF_PROMISC)) { + an_promisc(sc, 1); + } else if (ifp->if_drv_flags & IFF_DRV_RUNNING && + !(ifp->if_flags & IFF_PROMISC) && + sc->an_if_flags & IFF_PROMISC) { + an_promisc(sc, 0); + } else { + AN_UNLOCK(sc); + an_init(sc); + AN_LOCK(sc); + } + } else { + if (ifp->if_drv_flags & IFF_DRV_RUNNING) { + AN_UNLOCK(sc); + an_stop(sc); + AN_LOCK(sc); + } + } + AN_UNLOCK(sc); + sc->an_if_flags = ifp->if_flags; + error = 0; + break; + case SIOCSIFMEDIA: + case SIOCGIFMEDIA: + error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command); + break; + case SIOCADDMULTI: + case SIOCDELMULTI: + /* The Aironet has no multicast filter. */ + error = 0; + break; + case SIOCGAIRONET: + error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq)); + if (error != 0) + break; + AN_LOCK(sc); +#ifdef ANCACHE + if (sc->areq.an_type == AN_RID_ZERO_CACHE) { + error = priv_check(td, PRIV_DRIVER); + if (error) + break; + sc->an_sigitems = sc->an_nextitem = 0; + break; + } else if (sc->areq.an_type == AN_RID_READ_CACHE) { + char *pt = (char *)&sc->areq.an_val; + bcopy((char *)&sc->an_sigitems, (char *)pt, + sizeof(int)); + pt += sizeof(int); + sc->areq.an_len = sizeof(int) / 2; + bcopy((char *)&sc->an_sigcache, (char *)pt, + sizeof(struct an_sigcache) * sc->an_sigitems); + sc->areq.an_len += ((sizeof(struct an_sigcache) * + sc->an_sigitems) / 2) + 1; + } else +#endif + if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) { + AN_UNLOCK(sc); + error = EINVAL; + break; + } + AN_UNLOCK(sc); + error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq)); + break; + case SIOCSAIRONET: + if ((error = priv_check(td, PRIV_DRIVER))) + goto out; + AN_LOCK(sc); + error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq)); + if (error != 0) + break; + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + case SIOCGPRIVATE_0: /* used by Cisco client utility */ + if ((error = priv_check(td, PRIV_DRIVER))) + goto out; + error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl)); + if (error) + goto out; + mode = l_ioctl.command; + + AN_LOCK(sc); + if (mode >= AIROGCAP && mode <= AIROGSTATSD32) { + error = readrids(ifp, &l_ioctl); + } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) { + error = writerids(ifp, &l_ioctl); + } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) { + error = flashcard(ifp, &l_ioctl); + } else { + error =-1; + } + AN_UNLOCK(sc); + if (!error) { + /* copy out the updated command info */ + error = copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl)); + } + break; + case SIOCGPRIVATE_1: /* used by Cisco client utility */ + if ((error = priv_check(td, PRIV_DRIVER))) + goto out; + error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl)); + if (error) + goto out; + l_ioctl.command = 0; + error = AIROMAGIC; + (void) copyout(&error, l_ioctl.data, sizeof(error)); + error = 0; + break; + case SIOCG80211: + sc->areq.an_len = sizeof(sc->areq); + /* was that a good idea DJA we are doing a short-cut */ + switch (ireq->i_type) { + case IEEE80211_IOC_SSID: + AN_LOCK(sc); + if (ireq->i_val == -1) { + sc->areq.an_type = AN_RID_STATUS; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + len = status->an_ssidlen; + tmpptr = status->an_ssid; + } else if (ireq->i_val >= 0) { + sc->areq.an_type = AN_RID_SSIDLIST; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + max = (sc->areq.an_len - 4) + / sizeof(struct an_ltv_ssid_entry); + if ( max > MAX_SSIDS ) { + printf("To many SSIDs only using " + "%d of %d\n", + MAX_SSIDS, max); + max = MAX_SSIDS; + } + if (ireq->i_val > max) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } else { + len = ssids->an_entry[ireq->i_val].an_len; + tmpptr = ssids->an_entry[ireq->i_val].an_ssid; + } + } else { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + if (len > IEEE80211_NWID_LEN) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + ireq->i_len = len; + bzero(tmpstr, IEEE80211_NWID_LEN); + bcopy(tmpptr, tmpstr, len); + error = copyout(tmpstr, ireq->i_data, + IEEE80211_NWID_LEN); + break; + case IEEE80211_IOC_NUMSSIDS: + AN_LOCK(sc); + sc->areq.an_len = sizeof(sc->areq); + sc->areq.an_type = AN_RID_SSIDLIST; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + AN_UNLOCK(sc); + error = EINVAL; + break; + } + max = (sc->areq.an_len - 4) + / sizeof(struct an_ltv_ssid_entry); + AN_UNLOCK(sc); + if ( max > MAX_SSIDS ) { + printf("To many SSIDs only using " + "%d of %d\n", + MAX_SSIDS, max); + max = MAX_SSIDS; + } + ireq->i_val = max; + break; + case IEEE80211_IOC_WEP: + AN_LOCK(sc); + sc->areq.an_type = AN_RID_ACTUALCFG; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) { + if (config->an_authtype & + AN_AUTHTYPE_ALLOW_UNENCRYPTED) + ireq->i_val = IEEE80211_WEP_MIXED; + else + ireq->i_val = IEEE80211_WEP_ON; + } else { + ireq->i_val = IEEE80211_WEP_OFF; + } + break; + case IEEE80211_IOC_WEPKEY: + /* + * XXX: I'm not entierly convinced this is + * correct, but it's what is implemented in + * ancontrol so it will have to do until we get + * access to actual Cisco code. + */ + if (ireq->i_val < 0 || ireq->i_val > 8) { + error = EINVAL; + break; + } + len = 0; + if (ireq->i_val < 5) { + AN_LOCK(sc); + sc->areq.an_type = AN_RID_WEP_TEMP; + for (i = 0; i < 5; i++) { + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + break; + } + if (key->kindex == 0xffff) + break; + if (key->kindex == ireq->i_val) + len = key->klen; + /* Required to get next entry */ + sc->areq.an_type = AN_RID_WEP_PERM; + } + AN_UNLOCK(sc); + if (error != 0) { + break; + } + } + /* We aren't allowed to read the value of the + * key from the card so we just output zeros + * like we would if we could read the card, but + * denied the user access. + */ + bzero(tmpstr, len); + ireq->i_len = len; + error = copyout(tmpstr, ireq->i_data, len); + break; + case IEEE80211_IOC_NUMWEPKEYS: + ireq->i_val = 9; /* include home key */ + break; + case IEEE80211_IOC_WEPTXKEY: + /* + * For some strange reason, you have to read all + * keys before you can read the txkey. + */ + AN_LOCK(sc); + sc->areq.an_type = AN_RID_WEP_TEMP; + for (i = 0; i < 5; i++) { + if (an_read_record(sc, + (struct an_ltv_gen *) &sc->areq)) { + error = EINVAL; + break; + } + if (key->kindex == 0xffff) { + break; + } + /* Required to get next entry */ + sc->areq.an_type = AN_RID_WEP_PERM; + } + if (error != 0) { + AN_UNLOCK(sc); + break; + } + + sc->areq.an_type = AN_RID_WEP_PERM; + key->kindex = 0xffff; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + ireq->i_val = key->mac[0]; + /* + * Check for home mode. Map home mode into + * 5th key since that is how it is stored on + * the card + */ + sc->areq.an_len = sizeof(struct an_ltv_genconfig); + sc->areq.an_type = AN_RID_GENCONFIG; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + if (config->an_home_product & AN_HOME_NETWORK) + ireq->i_val = 4; + AN_UNLOCK(sc); + break; + case IEEE80211_IOC_AUTHMODE: + AN_LOCK(sc); + sc->areq.an_type = AN_RID_ACTUALCFG; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + if ((config->an_authtype & AN_AUTHTYPE_MASK) == + AN_AUTHTYPE_NONE) { + ireq->i_val = IEEE80211_AUTH_NONE; + } else if ((config->an_authtype & AN_AUTHTYPE_MASK) == + AN_AUTHTYPE_OPEN) { + ireq->i_val = IEEE80211_AUTH_OPEN; + } else if ((config->an_authtype & AN_AUTHTYPE_MASK) == + AN_AUTHTYPE_SHAREDKEY) { + ireq->i_val = IEEE80211_AUTH_SHARED; + } else + error = EINVAL; + break; + case IEEE80211_IOC_STATIONNAME: + AN_LOCK(sc); + sc->areq.an_type = AN_RID_ACTUALCFG; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + ireq->i_len = sizeof(config->an_nodename); + tmpptr = config->an_nodename; + bzero(tmpstr, IEEE80211_NWID_LEN); + bcopy(tmpptr, tmpstr, ireq->i_len); + error = copyout(tmpstr, ireq->i_data, + IEEE80211_NWID_LEN); + break; + case IEEE80211_IOC_CHANNEL: + AN_LOCK(sc); + sc->areq.an_type = AN_RID_STATUS; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + ireq->i_val = status->an_cur_channel; + break; + case IEEE80211_IOC_CURCHAN: + AN_LOCK(sc); + sc->areq.an_type = AN_RID_STATUS; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + bzero(&ch, sizeof(ch)); + ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel, + IEEE80211_CHAN_B); + ch.ic_flags = IEEE80211_CHAN_B; + ch.ic_ieee = status->an_cur_channel; + error = copyout(&ch, ireq->i_data, sizeof(ch)); + break; + case IEEE80211_IOC_POWERSAVE: + AN_LOCK(sc); + sc->areq.an_type = AN_RID_ACTUALCFG; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + if (config->an_psave_mode == AN_PSAVE_NONE) { + ireq->i_val = IEEE80211_POWERSAVE_OFF; + } else if (config->an_psave_mode == AN_PSAVE_CAM) { + ireq->i_val = IEEE80211_POWERSAVE_CAM; + } else if (config->an_psave_mode == AN_PSAVE_PSP) { + ireq->i_val = IEEE80211_POWERSAVE_PSP; + } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) { + ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM; + } else + error = EINVAL; + break; + case IEEE80211_IOC_POWERSAVESLEEP: + AN_LOCK(sc); + sc->areq.an_type = AN_RID_ACTUALCFG; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + ireq->i_val = config->an_listen_interval; + break; + } + break; + case SIOCS80211: + if ((error = priv_check(td, PRIV_NET80211_MANAGE))) + goto out; + AN_LOCK(sc); + sc->areq.an_len = sizeof(sc->areq); + /* + * We need a config structure for everything but the WEP + * key management and SSIDs so we get it now so avoid + * duplicating this code every time. + */ + if (ireq->i_type != IEEE80211_IOC_SSID && + ireq->i_type != IEEE80211_IOC_WEPKEY && + ireq->i_type != IEEE80211_IOC_WEPTXKEY) { + sc->areq.an_type = AN_RID_GENCONFIG; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + } + switch (ireq->i_type) { + case IEEE80211_IOC_SSID: + sc->areq.an_len = sizeof(sc->areq); + sc->areq.an_type = AN_RID_SSIDLIST; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + if (ireq->i_len > IEEE80211_NWID_LEN) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + max = (sc->areq.an_len - 4) + / sizeof(struct an_ltv_ssid_entry); + if ( max > MAX_SSIDS ) { + printf("To many SSIDs only using " + "%d of %d\n", + MAX_SSIDS, max); + max = MAX_SSIDS; + } + if (ireq->i_val > max) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } else { + error = copyin(ireq->i_data, + ssids->an_entry[ireq->i_val].an_ssid, + ireq->i_len); + ssids->an_entry[ireq->i_val].an_len + = ireq->i_len; + sc->areq.an_len = sizeof(sc->areq); + sc->areq.an_type = AN_RID_SSIDLIST; + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + } + break; + case IEEE80211_IOC_WEP: + switch (ireq->i_val) { + case IEEE80211_WEP_OFF: + config->an_authtype &= + ~(AN_AUTHTYPE_PRIVACY_IN_USE | + AN_AUTHTYPE_ALLOW_UNENCRYPTED); + break; + case IEEE80211_WEP_ON: + config->an_authtype |= + AN_AUTHTYPE_PRIVACY_IN_USE; + config->an_authtype &= + ~AN_AUTHTYPE_ALLOW_UNENCRYPTED; + break; + case IEEE80211_WEP_MIXED: + config->an_authtype |= + AN_AUTHTYPE_PRIVACY_IN_USE | + AN_AUTHTYPE_ALLOW_UNENCRYPTED; + break; + default: + error = EINVAL; + break; + } + if (error != EINVAL) + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + case IEEE80211_IOC_WEPKEY: + if (ireq->i_val < 0 || ireq->i_val > 8 || + ireq->i_len > 13) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + error = copyin(ireq->i_data, tmpstr, 13); + if (error != 0) { + AN_UNLOCK(sc); + break; + } + /* + * Map the 9th key into the home mode + * since that is how it is stored on + * the card + */ + bzero(&sc->areq, sizeof(struct an_ltv_key)); + sc->areq.an_len = sizeof(struct an_ltv_key); + key->mac[0] = 1; /* The others are 0. */ + if (ireq->i_val < 4) { + sc->areq.an_type = AN_RID_WEP_TEMP; + key->kindex = ireq->i_val; + } else { + sc->areq.an_type = AN_RID_WEP_PERM; + key->kindex = ireq->i_val - 4; + } + key->klen = ireq->i_len; + bcopy(tmpstr, key->key, key->klen); + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + case IEEE80211_IOC_WEPTXKEY: + if (ireq->i_val < 0 || ireq->i_val > 4) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + + /* + * Map the 5th key into the home mode + * since that is how it is stored on + * the card + */ + sc->areq.an_len = sizeof(struct an_ltv_genconfig); + sc->areq.an_type = AN_RID_ACTUALCFG; + if (an_read_record(sc, + (struct an_ltv_gen *)&sc->areq)) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + AN_UNLOCK(sc); + if (ireq->i_val == 4) { + config->an_home_product |= AN_HOME_NETWORK; + ireq->i_val = 0; + } else { + config->an_home_product &= ~AN_HOME_NETWORK; + } + + sc->an_config.an_home_product + = config->an_home_product; + + /* update configuration */ + an_init(sc); + + bzero(&sc->areq, sizeof(struct an_ltv_key)); + AN_LOCK(sc); + sc->areq.an_len = sizeof(struct an_ltv_key); + sc->areq.an_type = AN_RID_WEP_PERM; + key->kindex = 0xffff; + key->mac[0] = ireq->i_val; + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + case IEEE80211_IOC_AUTHMODE: + switch (ireq->i_val) { + case IEEE80211_AUTH_NONE: + config->an_authtype = AN_AUTHTYPE_NONE | + (config->an_authtype & ~AN_AUTHTYPE_MASK); + break; + case IEEE80211_AUTH_OPEN: + config->an_authtype = AN_AUTHTYPE_OPEN | + (config->an_authtype & ~AN_AUTHTYPE_MASK); + break; + case IEEE80211_AUTH_SHARED: + config->an_authtype = AN_AUTHTYPE_SHAREDKEY | + (config->an_authtype & ~AN_AUTHTYPE_MASK); + break; + default: + error = EINVAL; + } + if (error != EINVAL) { + an_setdef(sc, &sc->areq); + } + AN_UNLOCK(sc); + break; + case IEEE80211_IOC_STATIONNAME: + if (ireq->i_len > 16) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + bzero(config->an_nodename, 16); + error = copyin(ireq->i_data, + config->an_nodename, ireq->i_len); + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + case IEEE80211_IOC_CHANNEL: + /* + * The actual range is 1-14, but if you set it + * to 0 you get the default so we let that work + * too. + */ + if (ireq->i_val < 0 || ireq->i_val >14) { + error = EINVAL; + AN_UNLOCK(sc); + break; + } + config->an_ds_channel = ireq->i_val; + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + case IEEE80211_IOC_POWERSAVE: + switch (ireq->i_val) { + case IEEE80211_POWERSAVE_OFF: + config->an_psave_mode = AN_PSAVE_NONE; + break; + case IEEE80211_POWERSAVE_CAM: + config->an_psave_mode = AN_PSAVE_CAM; + break; + case IEEE80211_POWERSAVE_PSP: + config->an_psave_mode = AN_PSAVE_PSP; + break; + case IEEE80211_POWERSAVE_PSP_CAM: + config->an_psave_mode = AN_PSAVE_PSP_CAM; + break; + default: + error = EINVAL; + break; + } + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + case IEEE80211_IOC_POWERSAVESLEEP: + config->an_listen_interval = ireq->i_val; + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + break; + } + + /* + if (!error) { + AN_LOCK(sc); + an_setdef(sc, &sc->areq); + AN_UNLOCK(sc); + } + */ + break; + default: + error = ether_ioctl(ifp, command, data); + break; + } +out: + + return(error != 0); +} + +static int +an_init_tx_ring(struct an_softc *sc) +{ + int i; + int id; + + if (sc->an_gone) + return (0); + + if (!sc->mpi350) { + for (i = 0; i < AN_TX_RING_CNT; i++) { + if (an_alloc_nicmem(sc, 1518 + + 0x44, &id)) + return(ENOMEM); + sc->an_rdata.an_tx_fids[i] = id; + sc->an_rdata.an_tx_ring[i] = 0; + } + } + + sc->an_rdata.an_tx_prod = 0; + sc->an_rdata.an_tx_cons = 0; + sc->an_rdata.an_tx_empty = 1; + + return(0); +} + +static void +an_init(void *xsc) +{ + struct an_softc *sc = xsc; + struct ifnet *ifp = sc->an_ifp; + + AN_LOCK(sc); + + if (sc->an_gone) { + AN_UNLOCK(sc); + return; + } + + if (ifp->if_drv_flags & IFF_DRV_RUNNING) + an_stop(sc); + + sc->an_associated = 0; + + /* Allocate the TX buffers */ + if (an_init_tx_ring(sc)) { + an_reset(sc); + if (sc->mpi350) + an_init_mpi350_desc(sc); + if (an_init_tx_ring(sc)) { + printf("an%d: tx buffer allocation " + "failed\n", sc->an_unit); + AN_UNLOCK(sc); + return; + } + } + + /* Set our MAC address. */ + bcopy((char *)IF_LLADDR(sc->an_ifp), + (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN); + + if (ifp->if_flags & IFF_BROADCAST) + sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR; + else + sc->an_config.an_rxmode = AN_RXMODE_ADDR; + + if (ifp->if_flags & IFF_MULTICAST) + sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR; + + if (ifp->if_flags & IFF_PROMISC) { + if (sc->an_monitor & AN_MONITOR) { + if (sc->an_monitor & AN_MONITOR_ANY_BSS) { + sc->an_config.an_rxmode |= + AN_RXMODE_80211_MONITOR_ANYBSS | + AN_RXMODE_NO_8023_HEADER; + } else { + sc->an_config.an_rxmode |= + AN_RXMODE_80211_MONITOR_CURBSS | + AN_RXMODE_NO_8023_HEADER; + } + } + } + +#ifdef ANCACHE + if (sc->an_have_rssimap) + sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI; +#endif + + /* Set the ssid list */ + sc->an_ssidlist.an_type = AN_RID_SSIDLIST; + sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new); + if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) { + printf("an%d: failed to set ssid list\n", sc->an_unit); + AN_UNLOCK(sc); + return; + } + + /* Set the AP list */ + sc->an_aplist.an_type = AN_RID_APLIST; + sc->an_aplist.an_len = sizeof(struct an_ltv_aplist); + if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) { + printf("an%d: failed to set AP list\n", sc->an_unit); + AN_UNLOCK(sc); + return; + } + + /* Set the configuration in the NIC */ + sc->an_config.an_len = sizeof(struct an_ltv_genconfig); + sc->an_config.an_type = AN_RID_GENCONFIG; + if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) { + printf("an%d: failed to set configuration\n", sc->an_unit); + AN_UNLOCK(sc); + return; + } + + /* Enable the MAC */ + if (an_cmd(sc, AN_CMD_ENABLE, 0)) { + printf("an%d: failed to enable MAC\n", sc->an_unit); + AN_UNLOCK(sc); + return; + } + + if (ifp->if_flags & IFF_PROMISC) + an_cmd(sc, AN_CMD_SET_MODE, 0xffff); + + /* enable interrupts */ + CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350)); + + ifp->if_drv_flags |= IFF_DRV_RUNNING; + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + + callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc); + AN_UNLOCK(sc); + + return; +} + +static void +an_start(struct ifnet *ifp) +{ + struct an_softc *sc; + struct mbuf *m0 = NULL; + struct an_txframe_802_3 tx_frame_802_3; + struct ether_header *eh; + int id, idx, i; + unsigned char txcontrol; + struct an_card_tx_desc an_tx_desc; + u_int8_t *buf; + + sc = ifp->if_softc; + + if (sc->an_gone) + return; + + if (ifp->if_drv_flags & IFF_DRV_OACTIVE) + return; + + if (!sc->an_associated) + return; + + /* We can't send in monitor mode so toss any attempts. */ + if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) { + for (;;) { + IFQ_DRV_DEQUEUE(&ifp->if_snd, m0); + if (m0 == NULL) + break; + m_freem(m0); + } + return; + } + + idx = sc->an_rdata.an_tx_prod; + + AN_LOCK(sc); + if (!sc->mpi350) { + bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3)); + + while (sc->an_rdata.an_tx_ring[idx] == 0) { + IFQ_DRV_DEQUEUE(&ifp->if_snd, m0); + if (m0 == NULL) + break; + + id = sc->an_rdata.an_tx_fids[idx]; + eh = mtod(m0, struct ether_header *); + + bcopy((char *)&eh->ether_dhost, + (char *)&tx_frame_802_3.an_tx_dst_addr, + ETHER_ADDR_LEN); + bcopy((char *)&eh->ether_shost, + (char *)&tx_frame_802_3.an_tx_src_addr, + ETHER_ADDR_LEN); + + /* minus src/dest mac & type */ + tx_frame_802_3.an_tx_802_3_payload_len = + m0->m_pkthdr.len - 12; + + m_copydata(m0, sizeof(struct ether_header) - 2 , + tx_frame_802_3.an_tx_802_3_payload_len, + (caddr_t)&sc->an_txbuf); + + txcontrol = AN_TXCTL_8023; + /* write the txcontrol only */ + an_write_data(sc, id, 0x08, (caddr_t)&txcontrol, + sizeof(txcontrol)); + + /* 802_3 header */ + an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3, + sizeof(struct an_txframe_802_3)); + + /* in mbuf header type is just before payload */ + an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf, + tx_frame_802_3.an_tx_802_3_payload_len); + + /* + * If there's a BPF listner, bounce a copy of + * this frame to him. + */ + BPF_MTAP(ifp, m0); + + m_freem(m0); + m0 = NULL; + + sc->an_rdata.an_tx_ring[idx] = id; + if (an_cmd(sc, AN_CMD_TX, id)) + printf("an%d: xmit failed\n", sc->an_unit); + + AN_INC(idx, AN_TX_RING_CNT); + + /* + * Set a timeout in case the chip goes out to lunch. + */ + ifp->if_timer = 5; + } + } else { /* MPI-350 */ + /* Disable interrupts. */ + CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0); + + while (sc->an_rdata.an_tx_empty || + idx != sc->an_rdata.an_tx_cons) { + IFQ_DRV_DEQUEUE(&ifp->if_snd, m0); + if (m0 == NULL) { + break; + } + buf = sc->an_tx_buffer[idx].an_dma_vaddr; + + eh = mtod(m0, struct ether_header *); + + /* DJA optimize this to limit bcopy */ + bcopy((char *)&eh->ether_dhost, + (char *)&tx_frame_802_3.an_tx_dst_addr, + ETHER_ADDR_LEN); + bcopy((char *)&eh->ether_shost, + (char *)&tx_frame_802_3.an_tx_src_addr, + ETHER_ADDR_LEN); + + /* minus src/dest mac & type */ + tx_frame_802_3.an_tx_802_3_payload_len = + m0->m_pkthdr.len - 12; + + m_copydata(m0, sizeof(struct ether_header) - 2 , + tx_frame_802_3.an_tx_802_3_payload_len, + (caddr_t)&sc->an_txbuf); + + txcontrol = AN_TXCTL_8023; + /* write the txcontrol only */ + bcopy((caddr_t)&txcontrol, &buf[0x08], + sizeof(txcontrol)); + + /* 802_3 header */ + bcopy((caddr_t)&tx_frame_802_3, &buf[0x34], + sizeof(struct an_txframe_802_3)); + + /* in mbuf header type is just before payload */ + bcopy((caddr_t)&sc->an_txbuf, &buf[0x44], + tx_frame_802_3.an_tx_802_3_payload_len); + + + bzero(&an_tx_desc, sizeof(an_tx_desc)); + an_tx_desc.an_offset = 0; + an_tx_desc.an_eoc = 1; + an_tx_desc.an_valid = 1; + an_tx_desc.an_len = 0x44 + + tx_frame_802_3.an_tx_802_3_payload_len; + an_tx_desc.an_phys + = sc->an_tx_buffer[idx].an_dma_paddr; + for (i = 0; i < sizeof(an_tx_desc) / 4 ; i++) { + CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET + /* zero for now */ + + (0 * sizeof(an_tx_desc)) + + (i * 4), + ((u_int32_t *)(void *)&an_tx_desc)[i]); + } + + /* + * If there's a BPF listner, bounce a copy of + * this frame to him. + */ + BPF_MTAP(ifp, m0); + + m_freem(m0); + m0 = NULL; + AN_INC(idx, AN_MAX_TX_DESC); + sc->an_rdata.an_tx_empty = 0; + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC); + + /* + * Set a timeout in case the chip goes out to lunch. + */ + ifp->if_timer = 5; + } + + /* Re-enable interrupts. */ + CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350)); + } + AN_UNLOCK(sc); + + if (m0 != NULL) + ifp->if_drv_flags |= IFF_DRV_OACTIVE; + + sc->an_rdata.an_tx_prod = idx; + + return; +} + +void +an_stop(struct an_softc *sc) +{ + struct ifnet *ifp; + int i; + + AN_LOCK(sc); + + if (sc->an_gone) { + AN_UNLOCK(sc); + return; + } + + ifp = sc->an_ifp; + + an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0); + CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0); + an_cmd(sc, AN_CMD_DISABLE, 0); + + for (i = 0; i < AN_TX_RING_CNT; i++) + an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]); + + callout_stop(&sc->an_stat_ch); + + ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE); + + if (sc->an_flash_buffer) { + free(sc->an_flash_buffer, M_DEVBUF); + sc->an_flash_buffer = NULL; + } + + AN_UNLOCK(sc); + + return; +} + +static void +an_watchdog(struct ifnet *ifp) +{ + struct an_softc *sc; + + sc = ifp->if_softc; + AN_LOCK(sc); + + if (sc->an_gone) { + AN_UNLOCK(sc); + return; + } + + printf("an%d: device timeout\n", sc->an_unit); + + an_reset(sc); + if (sc->mpi350) + an_init_mpi350_desc(sc); + AN_UNLOCK(sc); + an_init(sc); + + ifp->if_oerrors++; + + return; +} + +int +an_shutdown(device_t dev) +{ + struct an_softc *sc; + + sc = device_get_softc(dev); + an_stop(sc); + sc->an_gone = 1; + + return 0; +} + +void +an_resume(device_t dev) +{ + struct an_softc *sc; + struct ifnet *ifp; + int i; + + sc = device_get_softc(dev); + AN_LOCK(sc); + ifp = sc->an_ifp; + + sc->an_gone = 0; + an_reset(sc); + if (sc->mpi350) + an_init_mpi350_desc(sc); + an_init(sc); + + /* Recovery temporary keys */ + for (i = 0; i < 4; i++) { + sc->areq.an_type = AN_RID_WEP_TEMP; + sc->areq.an_len = sizeof(struct an_ltv_key); + bcopy(&sc->an_temp_keys[i], + &sc->areq, sizeof(struct an_ltv_key)); + an_setdef(sc, &sc->areq); + } + + if (ifp->if_flags & IFF_UP) + an_start(ifp); + AN_UNLOCK(sc); + + return; +} + +#ifdef ANCACHE +/* Aironet signal strength cache code. + * store signal/noise/quality on per MAC src basis in + * a small fixed cache. The cache wraps if > MAX slots + * used. The cache may be zeroed out to start over. + * Two simple filters exist to reduce computation: + * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used + * to ignore some packets. It defaults to ip only. + * it could be used to focus on broadcast, non-IP 802.11 beacons. + * 2. multicast/broadcast only. This may be used to + * ignore unicast packets and only cache signal strength + * for multicast/broadcast packets (beacons); e.g., Mobile-IP + * beacons and not unicast traffic. + * + * The cache stores (MAC src(index), IP src (major clue), signal, + * quality, noise) + * + * No apologies for storing IP src here. It's easy and saves much + * trouble elsewhere. The cache is assumed to be INET dependent, + * although it need not be. + * + * Note: the Aironet only has a single byte of signal strength value + * in the rx frame header, and it's not scaled to anything sensible. + * This is kind of lame, but it's all we've got. + */ + +#ifdef documentation + +int an_sigitems; /* number of cached entries */ +struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */ +int an_nextitem; /* index/# of entries */ + + +#endif + +/* control variables for cache filtering. Basic idea is + * to reduce cost (e.g., to only Mobile-IP agent beacons + * which are broadcast or multicast). Still you might + * want to measure signal strength anth unicast ping packets + * on a pt. to pt. ant. setup. + */ +/* set true if you want to limit cache items to broadcast/mcast + * only packets (not unicast). Useful for mobile-ip beacons which + * are broadcast/multicast at network layer. Default is all packets + * so ping/unicast anll work say anth pt. to pt. antennae setup. + */ +static int an_cache_mcastonly = 0; +SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW, + &an_cache_mcastonly, 0, ""); + +/* set true if you want to limit cache items to IP packets only +*/ +static int an_cache_iponly = 1; +SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW, + &an_cache_iponly, 0, ""); + +/* + * an_cache_store, per rx packet store signal + * strength in MAC (src) indexed cache. + */ +static void +an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m, + u_int8_t rx_rssi, u_int8_t rx_quality) +{ + struct ip *ip = 0; + int i; + static int cache_slot = 0; /* use this cache entry */ + static int wrapindex = 0; /* next "free" cache entry */ + int type_ipv4 = 0; + + /* filters: + * 1. ip only + * 2. configurable filter to throw out unicast packets, + * keep multicast only. + */ + + if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) { + type_ipv4 = 1; + } + + /* filter for ip packets only + */ + if ( an_cache_iponly && !type_ipv4) { + return; + } + + /* filter for broadcast/multicast only + */ + if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) { + return; + } + +#ifdef SIGDEBUG + printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n", + rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff); +#endif + + /* find the ip header. we want to store the ip_src + * address. + */ + if (type_ipv4) { + ip = mtod(m, struct ip *); + } + + /* do a linear search for a matching MAC address + * in the cache table + * . MAC address is 6 bytes, + * . var w_nextitem holds total number of entries already cached + */ + for (i = 0; i < sc->an_nextitem; i++) { + if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) { + /* Match!, + * so we already have this entry, + * update the data + */ + break; + } + } + + /* did we find a matching mac address? + * if yes, then overwrite a previously existing cache entry + */ + if (i < sc->an_nextitem ) { + cache_slot = i; + } + /* else, have a new address entry,so + * add this new entry, + * if table full, then we need to replace LRU entry + */ + else { + + /* check for space in cache table + * note: an_nextitem also holds number of entries + * added in the cache table + */ + if ( sc->an_nextitem < MAXANCACHE ) { + cache_slot = sc->an_nextitem; + sc->an_nextitem++; + sc->an_sigitems = sc->an_nextitem; + } + /* no space found, so simply wrap anth wrap index + * and "zap" the next entry + */ + else { + if (wrapindex == MAXANCACHE) { + wrapindex = 0; + } + cache_slot = wrapindex++; + } + } + + /* invariant: cache_slot now points at some slot + * in cache. + */ + if (cache_slot < 0 || cache_slot >= MAXANCACHE) { + log(LOG_ERR, "an_cache_store, bad index: %d of " + "[0..%d], gross cache error\n", + cache_slot, MAXANCACHE); + return; + } + + /* store items in cache + * .ip source address + * .mac src + * .signal, etc. + */ + if (type_ipv4) { + sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr; + } + bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6); + + + switch (an_cache_mode) { + case DBM: + if (sc->an_have_rssimap) { + sc->an_sigcache[cache_slot].signal = + - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm; + sc->an_sigcache[cache_slot].quality = + - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm; + } else { + sc->an_sigcache[cache_slot].signal = rx_rssi - 100; + sc->an_sigcache[cache_slot].quality = rx_quality - 100; + } + break; + case PERCENT: + if (sc->an_have_rssimap) { + sc->an_sigcache[cache_slot].signal = + sc->an_rssimap.an_entries[rx_rssi].an_rss_pct; + sc->an_sigcache[cache_slot].quality = + sc->an_rssimap.an_entries[rx_quality].an_rss_pct; + } else { + if (rx_rssi > 100) + rx_rssi = 100; + if (rx_quality > 100) + rx_quality = 100; + sc->an_sigcache[cache_slot].signal = rx_rssi; + sc->an_sigcache[cache_slot].quality = rx_quality; + } + break; + case RAW: + sc->an_sigcache[cache_slot].signal = rx_rssi; + sc->an_sigcache[cache_slot].quality = rx_quality; + break; + } + + sc->an_sigcache[cache_slot].noise = 0; + + return; +} +#endif + +static int +an_media_change(struct ifnet *ifp) +{ + struct an_softc *sc = ifp->if_softc; + struct an_ltv_genconfig *cfg; + int otype = sc->an_config.an_opmode; + int orate = sc->an_tx_rate; + + sc->an_tx_rate = ieee80211_media2rate( + IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)); + if (sc->an_tx_rate < 0) + sc->an_tx_rate = 0; + + AN_LOCK(sc); + if (orate != sc->an_tx_rate) { + /* Read the current configuration */ + sc->an_config.an_type = AN_RID_GENCONFIG; + sc->an_config.an_len = sizeof(struct an_ltv_genconfig); + an_read_record(sc, (struct an_ltv_gen *)&sc->an_config); + cfg = &sc->an_config; + + /* clear other rates and set the only one we want */ + bzero(cfg->an_rates, sizeof(cfg->an_rates)); + cfg->an_rates[0] = sc->an_tx_rate; + + /* Save the new rate */ + sc->an_config.an_type = AN_RID_GENCONFIG; + sc->an_config.an_len = sizeof(struct an_ltv_genconfig); + } + + if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0) + sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION; + else + sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION; + AN_UNLOCK(sc); + + if (otype != sc->an_config.an_opmode || + orate != sc->an_tx_rate) + an_init(sc); + + return(0); +} + +static void +an_media_status(struct ifnet *ifp, struct ifmediareq *imr) +{ + struct an_ltv_status status; + struct an_softc *sc = ifp->if_softc; + + imr->ifm_active = IFM_IEEE80211; + + AN_LOCK(sc); + status.an_len = sizeof(status); + status.an_type = AN_RID_STATUS; + if (an_read_record(sc, (struct an_ltv_gen *)&status)) { + /* If the status read fails, just lie. */ + imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media; + imr->ifm_status = IFM_AVALID|IFM_ACTIVE; + } + AN_UNLOCK(sc); + + if (sc->an_tx_rate == 0) { + imr->ifm_active = IFM_IEEE80211|IFM_AUTO; + } + + if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC) + imr->ifm_active |= IFM_IEEE80211_ADHOC; + imr->ifm_active |= ieee80211_rate2media(NULL, + status.an_current_tx_rate, IEEE80211_T_DS); + imr->ifm_status = IFM_AVALID; + if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED) + imr->ifm_status |= IFM_ACTIVE; +} + +/********************** Cisco utility support routines *************/ + +/* + * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's + * Linux driver + */ + +static int +readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl) +{ + unsigned short rid; + struct an_softc *sc; + int error; + + switch (l_ioctl->command) { + case AIROGCAP: + rid = AN_RID_CAPABILITIES; + break; + case AIROGCFG: + rid = AN_RID_GENCONFIG; + break; + case AIROGSLIST: + rid = AN_RID_SSIDLIST; + break; + case AIROGVLIST: + rid = AN_RID_APLIST; + break; + case AIROGDRVNAM: + rid = AN_RID_DRVNAME; + break; + case AIROGEHTENC: + rid = AN_RID_ENCAPPROTO; + break; + case AIROGWEPKTMP: + rid = AN_RID_WEP_TEMP; + break; + case AIROGWEPKNV: + rid = AN_RID_WEP_PERM; + break; + case AIROGSTAT: + rid = AN_RID_STATUS; + break; + case AIROGSTATSD32: + rid = AN_RID_32BITS_DELTA; + break; + case AIROGSTATSC32: + rid = AN_RID_32BITS_CUM; + break; + default: + rid = 999; + break; + } + + if (rid == 999) /* Is bad command */ + return -EINVAL; + + sc = ifp->if_softc; + sc->areq.an_len = AN_MAX_DATALEN; + sc->areq.an_type = rid; + + an_read_record(sc, (struct an_ltv_gen *)&sc->areq); + + l_ioctl->len = sc->areq.an_len - 4; /* just data */ + + AN_UNLOCK(sc); + /* the data contains the length at first */ + if (copyout(&(sc->areq.an_len), l_ioctl->data, + sizeof(sc->areq.an_len))) { + error = -EFAULT; + goto lock_exit; + } + /* Just copy the data back */ + if (copyout(&(sc->areq.an_val), l_ioctl->data + 2, + l_ioctl->len)) { + error = -EFAULT; + goto lock_exit; + } + error = 0; +lock_exit: + AN_LOCK(sc); + return (error); +} + +static int +writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl) +{ + struct an_softc *sc; + int rid, command, error; + + sc = ifp->if_softc; + AN_LOCK_ASSERT(sc); + rid = 0; + command = l_ioctl->command; + + switch (command) { + case AIROPSIDS: + rid = AN_RID_SSIDLIST; + break; + case AIROPCAP: + rid = AN_RID_CAPABILITIES; + break; + case AIROPAPLIST: + rid = AN_RID_APLIST; + break; + case AIROPCFG: + rid = AN_RID_GENCONFIG; + break; + case AIROPMACON: + an_cmd(sc, AN_CMD_ENABLE, 0); + return 0; + break; + case AIROPMACOFF: + an_cmd(sc, AN_CMD_DISABLE, 0); + return 0; + break; + case AIROPSTCLR: + /* + * This command merely clears the counts does not actually + * store any data only reads rid. But as it changes the cards + * state, I put it in the writerid routines. + */ + + rid = AN_RID_32BITS_DELTACLR; + sc = ifp->if_softc; + sc->areq.an_len = AN_MAX_DATALEN; + sc->areq.an_type = rid; + + an_read_record(sc, (struct an_ltv_gen *)&sc->areq); + l_ioctl->len = sc->areq.an_len - 4; /* just data */ + + AN_UNLOCK(sc); + /* the data contains the length at first */ + error = copyout(&(sc->areq.an_len), l_ioctl->data, + sizeof(sc->areq.an_len)); + if (error) { + AN_LOCK(sc); + return -EFAULT; + } + /* Just copy the data */ + error = copyout(&(sc->areq.an_val), l_ioctl->data + 2, + l_ioctl->len); + AN_LOCK(sc); + if (error) + return -EFAULT; + return 0; + break; + case AIROPWEPKEY: + rid = AN_RID_WEP_TEMP; + break; + case AIROPWEPKEYNV: + rid = AN_RID_WEP_PERM; + break; + case AIROPLEAPUSR: + rid = AN_RID_LEAPUSERNAME; + break; + case AIROPLEAPPWD: + rid = AN_RID_LEAPPASSWORD; + break; + default: + return -EOPNOTSUPP; + } + + if (rid) { + if (l_ioctl->len > sizeof(sc->areq.an_val) + 4) + return -EINVAL; + sc->areq.an_len = l_ioctl->len + 4; /* add type & length */ + sc->areq.an_type = rid; + + /* Just copy the data back */ + AN_UNLOCK(sc); + error = copyin((l_ioctl->data) + 2, &sc->areq.an_val, + l_ioctl->len); + AN_LOCK(sc); + if (error) + return -EFAULT; + + an_cmd(sc, AN_CMD_DISABLE, 0); + an_write_record(sc, (struct an_ltv_gen *)&sc->areq); + an_cmd(sc, AN_CMD_ENABLE, 0); + return 0; + } + return -EOPNOTSUPP; +} + +/* + * General Flash utilities derived from Cisco driver additions to Ben Reed's + * Linux driver + */ + +#define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \ + "flash", ((x) / hz) + 1); +#define FLASH_COMMAND 0x7e7e +#define FLASH_SIZE 32 * 1024 + +static int +unstickbusy(struct ifnet *ifp) +{ + struct an_softc *sc = ifp->if_softc; + + if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) { + CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), + AN_EV_CLR_STUCK_BUSY); + return 1; + } + return 0; +} + +/* + * Wait for busy completion from card wait for delay uSec's Return true for + * success meaning command reg is clear + */ + +static int +WaitBusy(struct ifnet *ifp, int uSec) +{ + int statword = 0xffff; + int delay = 0; + struct an_softc *sc = ifp->if_softc; + + while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) { + FLASH_DELAY(sc, 10); + delay += 10; + statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350)); + + if ((AN_CMD_BUSY & statword) && (delay % 200)) { + unstickbusy(ifp); + } + } + + return 0 == (AN_CMD_BUSY & statword); +} + +/* + * STEP 1) Disable MAC and do soft reset on card. + */ + +static int +cmdreset(struct ifnet *ifp) +{ + int status; + struct an_softc *sc = ifp->if_softc; + + an_stop(sc); + + AN_LOCK(sc); + an_cmd(sc, AN_CMD_DISABLE, 0); + + if (!(status = WaitBusy(ifp, AN_TIMEOUT))) { + printf("an%d: Waitbusy hang b4 RESET =%d\n", + sc->an_unit, status); + AN_UNLOCK(sc); + return -EBUSY; + } + CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART); + + FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */ + + + if (!(status = WaitBusy(ifp, 100))) { + printf("an%d: Waitbusy hang AFTER RESET =%d\n", + sc->an_unit, status); + AN_UNLOCK(sc); + return -EBUSY; + } + AN_UNLOCK(sc); + return 0; +} + +/* + * STEP 2) Put the card in legendary flash mode + */ + +static int +setflashmode(struct ifnet *ifp) +{ + int status; + struct an_softc *sc = ifp->if_softc; + + CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND); + CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND); + CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND); + CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND); + + /* + * mdelay(500); // 500ms delay + */ + + FLASH_DELAY(sc, 500); + + if (!(status = WaitBusy(ifp, AN_TIMEOUT))) { + printf("Waitbusy hang after setflash mode\n"); + return -EIO; + } + return 0; +} + +/* + * Get a character from the card matching matchbyte Step 3) + */ + +static int +flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime) +{ + int rchar; + unsigned char rbyte = 0; + int success = -1; + struct an_softc *sc = ifp->if_softc; + + + do { + rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350)); + + if (dwelltime && !(0x8000 & rchar)) { + dwelltime -= 10; + FLASH_DELAY(sc, 10); + continue; + } + rbyte = 0xff & rchar; + + if ((rbyte == matchbyte) && (0x8000 & rchar)) { + CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0); + success = 1; + break; + } + if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar) + break; + CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0); + + } while (dwelltime > 0); + return success; +} + +/* + * Put character to SWS0 wait for dwelltime x 50us for echo . + */ + +static int +flashpchar(struct ifnet *ifp, int byte, int dwelltime) +{ + int echo; + int pollbusy, waittime; + struct an_softc *sc = ifp->if_softc; + + byte |= 0x8000; + + if (dwelltime == 0) + dwelltime = 200; + + waittime = dwelltime; + + /* + * Wait for busy bit d15 to go false indicating buffer empty + */ + do { + pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350)); + + if (pollbusy & 0x8000) { + FLASH_DELAY(sc, 50); + waittime -= 50; + continue; + } else + break; + } + while (waittime >= 0); + + /* timeout for busy clear wait */ + + if (waittime <= 0) { + printf("an%d: flash putchar busywait timeout! \n", + sc->an_unit); + return -1; + } + /* + * Port is clear now write byte and wait for it to echo back + */ + do { + CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte); + FLASH_DELAY(sc, 50); + dwelltime -= 50; + echo = CSR_READ_2(sc, AN_SW1(sc->mpi350)); + } while (dwelltime >= 0 && echo != byte); + + + CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0); + + return echo == byte; +} + +/* + * Transfer 32k of firmware data from user buffer to our buffer and send to + * the card + */ + +static int +flashputbuf(struct ifnet *ifp) +{ + unsigned short *bufp; + int nwords; + struct an_softc *sc = ifp->if_softc; + + /* Write stuff */ + + bufp = sc->an_flash_buffer; + + if (!sc->mpi350) { + CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100); + CSR_WRITE_2(sc, AN_AUX_OFFSET, 0); + + for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) { + CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff); + } + } else { + for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) { + CSR_MEM_AUX_WRITE_4(sc, 0x8000, + ((u_int32_t *)bufp)[nwords] & 0xffff); + } + } + + CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000); + + return 0; +} + +/* + * After flashing restart the card. + */ + +static int +flashrestart(struct ifnet *ifp) +{ + int status = 0; + struct an_softc *sc = ifp->if_softc; + + FLASH_DELAY(sc, 1024); /* Added 12/7/00 */ + + AN_UNLOCK(sc); + an_init(sc); + AN_LOCK(sc); + + FLASH_DELAY(sc, 1024); /* Added 12/7/00 */ + return status; +} + +/* + * Entry point for flash ioclt. + */ + +static int +flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl) +{ + int z = 0, status; + struct an_softc *sc; + + sc = ifp->if_softc; + if (sc->mpi350) { + printf("an%d: flashing not supported on MPI 350 yet\n", + sc->an_unit); + return(-1); + } + status = l_ioctl->command; + + switch (l_ioctl->command) { + case AIROFLSHRST: + return cmdreset(ifp); + break; + case AIROFLSHSTFL: + if (sc->an_flash_buffer) { + free(sc->an_flash_buffer, M_DEVBUF); + sc->an_flash_buffer = NULL; + } + sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK); + if (sc->an_flash_buffer) + return setflashmode(ifp); + else + return ENOBUFS; + break; + case AIROFLSHGCHR: /* Get char from aux */ + AN_UNLOCK(sc); + status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len); + AN_LOCK(sc); + if (status) + return status; + z = *(int *)&sc->areq; + if ((status = flashgchar(ifp, z, 8000)) == 1) + return 0; + else + return -1; + case AIROFLSHPCHR: /* Send char to card. */ + AN_UNLOCK(sc); + status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len); + AN_LOCK(sc); + if (status) + return status; + z = *(int *)&sc->areq; + if ((status = flashpchar(ifp, z, 8000)) == -1) + return -EIO; + else + return 0; + break; + case AIROFLPUTBUF: /* Send 32k to card */ + if (l_ioctl->len > FLASH_SIZE) { + printf("an%d: Buffer to big, %x %x\n", sc->an_unit, + l_ioctl->len, FLASH_SIZE); + return -EINVAL; + } + AN_UNLOCK(sc); + status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len); + AN_LOCK(sc); + if (status) + return status; + + if ((status = flashputbuf(ifp)) != 0) + return -EIO; + else + return 0; + break; + case AIRORESTART: + if ((status = flashrestart(ifp)) != 0) { + printf("an%d: FLASHRESTART returned %d\n", + sc->an_unit, status); + return -EIO; + } else + return 0; + + break; + default: + return -EINVAL; + } + + return -EINVAL; +} diff --git a/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_isa.c b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_isa.c new file mode 100644 index 0000000000..80933b18ad --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_isa.c @@ -0,0 +1,152 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD. + * + * Written by Bill Paul + * Electrical Engineering Department + * Columbia University, New York City + */ + +#include +__FBSDID("$FreeBSD$"); + +#include "opt_inet.h" + +#ifdef INET +#define ANCACHE +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +static struct isa_pnp_id an_ids[] = { + { 0x0100ec06, "Aironet ISA4500/ISA4800" }, + { 0, NULL } +}; + +static int an_probe_isa(device_t); +static int an_attach_isa(device_t); + +static int +an_probe_isa(device_t dev) +{ + int error = 0; + + error = ISA_PNP_PROBE(device_get_parent(dev), dev, an_ids); + if (error == ENXIO) + return(error); + + error = an_probe(dev); + an_release_resources(dev); + if (error == 0) + return (ENXIO); + + error = an_alloc_irq(dev, 0, 0); + an_release_resources(dev); + if (!error) + device_set_desc(dev, "Aironet ISA4500/ISA4800"); + return (error); +} + +static int +an_attach_isa(device_t dev) +{ + struct an_softc *sc = device_get_softc(dev); + int flags = device_get_flags(dev); + int error; + + an_alloc_port(dev, sc->port_rid, 1); + an_alloc_irq(dev, sc->irq_rid, 0); + + sc->an_bhandle = rman_get_bushandle(sc->port_res); + sc->an_btag = rman_get_bustag(sc->port_res); + sc->an_dev = dev; + + error = an_attach(sc, device_get_unit(dev), flags); + if (error) { + an_release_resources(dev); + return (error); + } + + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, + NULL, an_intr, sc, &sc->irq_handle); + if (error) { + an_release_resources(dev); + return (error); + } + return (0); +} + +static device_method_t an_isa_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, an_probe_isa), + DEVMETHOD(device_attach, an_attach_isa), + DEVMETHOD(device_detach, an_detach), + DEVMETHOD(device_shutdown, an_shutdown), + { 0, 0 } +}; + +static driver_t an_isa_driver = { + "an", + an_isa_methods, + sizeof(struct an_softc) +}; + +static devclass_t an_isa_devclass; + +DRIVER_MODULE(an, isa, an_isa_driver, an_isa_devclass, 0, 0); +MODULE_DEPEND(an, isa, 1, 1, 1); +MODULE_DEPEND(an, wlan, 1, 1, 1); diff --git a/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_pccard.c b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_pccard.c new file mode 100644 index 0000000000..b475265d84 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_pccard.c @@ -0,0 +1,161 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD. + * + * Written by Bill Paul + * Electrical Engineering Department + * Columbia University, New York City + */ + +#include +__FBSDID("$FreeBSD$"); + +#include "opt_inet.h" + +#ifdef INET +#define ANCACHE +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "pccarddevs.h" +#include "card_if.h" + +/* + * Support for PCMCIA cards. + */ +static int an_pccard_probe(device_t); +static int an_pccard_attach(device_t); + +static device_method_t an_pccard_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, an_pccard_probe), + DEVMETHOD(device_attach, an_pccard_attach), + DEVMETHOD(device_detach, an_detach), + DEVMETHOD(device_shutdown, an_shutdown), + + { 0, 0 } +}; + +static driver_t an_pccard_driver = { + "an", + an_pccard_methods, + sizeof(struct an_softc) +}; + +static devclass_t an_pccard_devclass; + +DRIVER_MODULE(an, pccard, an_pccard_driver, an_pccard_devclass, 0, 0); +MODULE_DEPEND(an, wlan, 1, 1, 1); + +static const struct pccard_product an_pccard_products[] = { + PCMCIA_CARD(AIRONET, PC4800), + PCMCIA_CARD(AIRONET, PC4500), + PCMCIA_CARD(AIRONET, 350), + PCMCIA_CARD(XIRCOM, CWE1130), + { NULL } +}; + +static int +an_pccard_probe(device_t dev) +{ + const struct pccard_product *pp; + + if ((pp = pccard_product_lookup(dev, an_pccard_products, + sizeof(an_pccard_products[0]), NULL)) != NULL) { + if (pp->pp_name != NULL) + device_set_desc(dev, pp->pp_name); + return (0); + } + return (ENXIO); +} + +static int +an_pccard_attach(device_t dev) +{ + struct an_softc *sc = device_get_softc(dev); + int flags = device_get_flags(dev); + int error; + + error = an_probe(dev); /* 0 is failure for now */ + if (error == 0) { + error = ENXIO; + goto fail; + } + error = an_alloc_irq(dev, 0, 0); + if (error != 0) + goto fail; + + an_alloc_irq(dev, sc->irq_rid, 0); + + sc->an_bhandle = rman_get_bushandle(sc->port_res); + sc->an_btag = rman_get_bustag(sc->port_res); + sc->an_dev = dev; + + error = an_attach(sc, device_get_unit(dev), flags); + if (error) + goto fail; + + /* + * Must setup the interrupt after the an_attach to prevent racing. + */ + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, + NULL, an_intr, sc, &sc->irq_handle); +fail: + if (error) + an_release_resources(dev); + return (error); +} diff --git a/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_pci.c b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_pci.c new file mode 100644 index 0000000000..d13e3ab597 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_an_pci.c @@ -0,0 +1,291 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * This is a PCI shim for the Aironet PC4500/4800 wireless network + * driver. Aironet makes PCMCIA, ISA and PCI versions of these devices, + * which all have basically the same interface. The ISA and PCI cards + * are actually bridge adapters with PCMCIA cards inserted into them, + * however they appear as normal PCI or ISA devices to the host. + * + * All we do here is handle the PCI probe and attach and set up an + * interrupt handler entry point. The PCI version of the card uses + * a PLX 9050 PCI to "dumb bus" bridge chip, which provides us with + * multiple PCI address space mappings. The primary mapping at PCI + * register 0x14 is for the PLX chip itself, *NOT* the Aironet card. + * The I/O address of the Aironet is actually at register 0x18, which + * is the local bus mapping register for bus space 0. There are also + * registers for additional register spaces at registers 0x1C and + * 0x20, but these are unused in the Aironet devices. To find out + * more, you need a datasheet for the 9050 from PLX, but you have + * to go through their sales office to get it. Bleh. + */ + +#include "opt_inet.h" + +#ifdef INET +#define ANCACHE +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +struct an_type { + u_int16_t an_vid; + u_int16_t an_did; + char *an_name; +}; + +#define AIRONET_VENDORID 0x14B9 +#define AIRONET_DEVICEID_35x 0x0350 +#define AIRONET_DEVICEID_4500 0x4500 +#define AIRONET_DEVICEID_4800 0x4800 +#define AIRONET_DEVICEID_4xxx 0x0001 +#define AIRONET_DEVICEID_MPI350 0xA504 +#define AN_PCI_PLX_LOIO 0x14 /* PLX chip iobase */ +#define AN_PCI_LOIO 0x18 /* Aironet iobase */ + +static struct an_type an_devs[] = { + { AIRONET_VENDORID, AIRONET_DEVICEID_35x, "Cisco Aironet 350 Series" }, + { AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" }, + { AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" }, + { AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" }, + { 0, 0, NULL } +}; + +static int an_probe_pci (device_t); +static int an_attach_pci (device_t); +static int an_suspend_pci (device_t); +static int an_resume_pci (device_t); + +static int +an_probe_pci(device_t dev) +{ + struct an_type *t; + struct an_softc *sc = device_get_softc(dev); + + bzero(sc, sizeof(struct an_softc)); + t = an_devs; + + while (t->an_name != NULL) { + if (pci_get_vendor(dev) == t->an_vid && + pci_get_device(dev) == t->an_did) { + device_set_desc(dev, t->an_name); + an_pci_probe(dev); + return(BUS_PROBE_DEFAULT); + } + t++; + } + + if (pci_get_vendor(dev) == AIRONET_VENDORID && + pci_get_device(dev) == AIRONET_DEVICEID_MPI350) { + device_set_desc(dev, "Cisco Aironet MPI350"); + an_pci_probe(dev); + return(BUS_PROBE_DEFAULT); + } + + return(ENXIO); +} + +static int +an_attach_pci(dev) + device_t dev; +{ + u_int32_t command; + struct an_softc *sc; + int unit, flags, error = 0; + + sc = device_get_softc(dev); + unit = device_get_unit(dev); + flags = device_get_flags(dev); + + if (pci_get_vendor(dev) == AIRONET_VENDORID && + pci_get_device(dev) == AIRONET_DEVICEID_MPI350) { + sc->mpi350 = 1; + sc->port_rid = PCIR_BAR(0); + } else { + /* + * Map control/status registers. + */ + command = pci_read_config(dev, PCIR_COMMAND, 4); + command |= PCIM_CMD_PORTEN; + pci_write_config(dev, PCIR_COMMAND, command, 4); + command = pci_read_config(dev, PCIR_COMMAND, 4); + + if (!(command & PCIM_CMD_PORTEN)) { + printf("an%d: failed to enable I/O ports!\n", unit); + error = ENXIO; + goto fail; + } + sc->port_rid = AN_PCI_LOIO; + } + error = an_alloc_port(dev, sc->port_rid, 1); + + if (error) { + printf("an%d: couldn't map ports\n", unit); + goto fail; + } + + sc->an_btag = rman_get_bustag(sc->port_res); + sc->an_bhandle = rman_get_bushandle(sc->port_res); + + /* Allocate memory for MPI350 */ + if (sc->mpi350) { + /* Allocate memory */ + sc->mem_rid = PCIR_BAR(1); + error = an_alloc_memory(dev, sc->mem_rid, 1); + if (error) { + printf("an%d: couldn't map memory\n", unit); + goto fail; + } + sc->an_mem_btag = rman_get_bustag(sc->mem_res); + sc->an_mem_bhandle = rman_get_bushandle(sc->mem_res); + + /* Allocate aux. memory */ + sc->mem_aux_rid = PCIR_BAR(2); + error = an_alloc_aux_memory(dev, sc->mem_aux_rid, + AN_AUX_MEM_SIZE); + if (error) { + printf("an%d: couldn't map aux memory\n", unit); + goto fail; + } + sc->an_mem_aux_btag = rman_get_bustag(sc->mem_aux_res); + sc->an_mem_aux_bhandle = rman_get_bushandle(sc->mem_aux_res); + + /* Allocate DMA region */ + error = bus_dma_tag_create(NULL, /* parent */ + 1, 0, /* alignment, bounds */ + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + 0x3ffff, /* maxsize XXX */ + 1, /* nsegments */ + 0xffff, /* maxsegsize XXX */ + BUS_DMA_ALLOCNOW, /* flags */ + NULL, /* lockfunc */ + NULL, /* lockarg */ + &sc->an_dtag); + if (error) { + printf("an%d: couldn't get DMA region\n", unit); + goto fail; + } + } + + /* Allocate interrupt */ + error = an_alloc_irq(dev, 0, RF_SHAREABLE); + if (error) { + goto fail; + } + + sc->an_dev = dev; + error = an_attach(sc, device_get_unit(dev), flags); + if (error) { + goto fail; + } + + /* + * Must setup the interrupt after the an_attach to prevent racing. + */ + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, + NULL, an_intr, sc, &sc->irq_handle); + +fail: + if (error) + an_release_resources(dev); + return(error); +} + +static int +an_suspend_pci(device_t dev) +{ + an_shutdown(dev); + + return (0); +} + +static int +an_resume_pci(device_t dev) +{ + an_resume(dev); + + return (0); +} + +static device_method_t an_pci_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, an_probe_pci), + DEVMETHOD(device_attach, an_attach_pci), + DEVMETHOD(device_detach, an_detach), + DEVMETHOD(device_shutdown, an_shutdown), + DEVMETHOD(device_suspend, an_suspend_pci), + DEVMETHOD(device_resume, an_resume_pci), + { 0, 0 } +}; + +static driver_t an_pci_driver = { + "an", + an_pci_methods, + sizeof(struct an_softc), +}; + +static devclass_t an_devclass; + +DRIVER_MODULE(an, pci, an_pci_driver, an_devclass, 0, 0); +MODULE_DEPEND(an, pci, 1, 1, 1); +MODULE_DEPEND(an, wlan, 1, 1, 1); diff --git a/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_anreg.h b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_anreg.h new file mode 100644 index 0000000000..ec0ad2bc4a --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/if_anreg.h @@ -0,0 +1,556 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#define AN_TIMEOUT 65536 + +/* Default network name: */ +#define AN_DEFAULT_NETNAME "" + +/* The nodename must be less than 16 bytes */ +#define AN_DEFAULT_NODENAME "FreeBSD" + +#define AN_DEFAULT_IBSS "FreeBSD IBSS" + +/* + * register space access macros + */ +#define CSR_WRITE_2(sc, reg, val) \ + bus_space_write_2(sc->an_btag, sc->an_bhandle, reg, val) + +#define CSR_READ_2(sc, reg) \ + bus_space_read_2(sc->an_btag, sc->an_bhandle, reg) + +#define CSR_WRITE_1(sc, reg, val) \ + bus_space_write_1(sc->an_btag, sc->an_bhandle, reg, val) + +#define CSR_READ_1(sc, reg) \ + bus_space_read_1(sc->an_btag, sc->an_bhandle, reg) + +/* + * memory space access macros + */ +#define CSR_MEM_WRITE_2(sc, reg, val) \ + bus_space_write_2(sc->an_mem_btag, sc->an_mem_bhandle, reg, val) + +#define CSR_MEM_READ_2(sc, reg) \ + bus_space_read_2(sc->an_mem_btag, sc->an_mem_bhandle, reg) + +#define CSR_MEM_WRITE_1(sc, reg, val) \ + bus_space_write_1(sc->an_mem_btag, sc->an_mem_bhandle, reg, val) + +#define CSR_MEM_READ_1(sc, reg) \ + bus_space_read_1(sc->an_mem_btag, sc->an_mem_bhandle, reg) + +/* + * aux. memory space access macros + */ +#define CSR_MEM_AUX_WRITE_4(sc, reg, val) \ + bus_space_write_4(sc->an_mem_aux_btag, sc->an_mem_aux_bhandle, reg, val) + +#define CSR_MEM_AUX_READ_4(sc, reg) \ + bus_space_read_4(sc->an_mem_aux_btag, sc->an_mem_aux_bhandle, reg) + +#define CSR_MEM_AUX_WRITE_1(sc, reg, val) \ + bus_space_write_1(sc->an_mem_aux_btag, sc->an_mem_aux_bhandle, reg, val) + +#define CSR_MEM_AUX_READ_1(sc, reg) \ + bus_space_read_1(sc->an_mem_aux_btag, sc->an_mem_aux_bhandle, reg) + +/* + * Size of Aironet I/O space. + */ +#define AN_IOSIZ 0x40 + +/* + * Size of aux. memory space ... probably not needed DJA + */ +#define AN_AUX_MEM_SIZE (256 * 1024) + +/* + * Hermes register definitions and what little I know about them. + */ + +/* Hermes command/status registers. */ +#define AN_COMMAND(x) (x ? 0x00 : 0x00) +#define AN_PARAM0(x) (x ? 0x04 : 0x02) +#define AN_PARAM1(x) (x ? 0x08 : 0x04) +#define AN_PARAM2(x) (x ? 0x0c : 0x06) +#define AN_STATUS(x) (x ? 0x10 : 0x08) +#define AN_RESP0(x) (x ? 0x14 : 0x0A) +#define AN_RESP1(x) (x ? 0x18 : 0x0C) +#define AN_RESP2(x) (x ? 0x1c : 0x0E) +#define AN_LINKSTAT(x) (x ? 0x20 : 0x10) + +/* Command register */ +#define AN_CMD_BUSY 0x8000 /* busy bit */ +#define AN_CMD_NO_ACK 0x0080 /* don't acknowledge command */ +#define AN_CMD_CODE_MASK 0x003F +#define AN_CMD_QUAL_MASK 0x7F00 + +/* Command codes */ +#define AN_CMD_NOOP 0x0000 /* no-op */ +#define AN_CMD_ENABLE 0x0001 /* enable */ +#define AN_CMD_DISABLE 0x0002 /* disable */ +#define AN_CMD_FORCE_SYNCLOSS 0x0003 /* force loss of sync */ +#define AN_CMD_FW_RESTART 0x0004 /* firmware restart */ +#define AN_CMD_HOST_SLEEP 0x0005 +#define AN_CMD_MAGIC_PKT 0x0006 +#define AN_CMD_READCFG 0x0008 +#define AN_CMD_SET_MODE 0x0009 +#define AN_CMD_ALLOC_MEM 0x000A /* allocate NIC memory */ +#define AN_CMD_TX 0x000B /* transmit */ +#define AN_CMD_DEALLOC_MEM 0x000C +#define AN_CMD_NOOP2 0x0010 +#define AN_CMD_ALLOC_DESC 0x0020 +#define AN_CMD_ACCESS 0x0021 +#define AN_CMD_ALLOC_BUF 0x0028 +#define AN_CMD_PSP_NODES 0x0030 +#define AN_CMD_SET_PHYREG 0x003E +#define AN_CMD_TX_TEST 0x003F +#define AN_CMD_SLEEP 0x0085 +#define AN_CMD_SAVECFG 0x0108 + +/* + * MPI 350 DMA descriptor information + */ +#define AN_DESCRIPTOR_TX 0x01 +#define AN_DESCRIPTOR_RX 0x02 +#define AN_DESCRIPTOR_TXCMP 0x04 +#define AN_DESCRIPTOR_HOSTWRITE 0x08 +#define AN_DESCRIPTOR_HOSTREAD 0x10 +#define AN_DESCRIPTOR_HOSTRW 0x20 + +#define AN_MAX_RX_DESC 1 +#define AN_MAX_TX_DESC 1 +#define AN_HOSTBUFSIZ 1840 + +struct an_card_rid_desc +{ + unsigned an_rid:16; + unsigned an_len:15; + unsigned an_valid:1; + u_int64_t an_phys; +}; + +struct an_card_rx_desc +{ + unsigned an_ctrl:15; + unsigned an_done:1; + unsigned an_len:15; + unsigned an_valid:1; + u_int64_t an_phys; +}; + +struct an_card_tx_desc +{ + unsigned an_offset:15; + unsigned an_eoc:1; + unsigned an_len:15; + unsigned an_valid:1; + u_int64_t an_phys; +}; + +#define AN_RID_BUFFER_SIZE AN_MAX_DATALEN +#define AN_RX_BUFFER_SIZE AN_HOSTBUFSIZ +#define AN_TX_BUFFER_SIZE AN_HOSTBUFSIZ +/*#define AN_HOST_DESC_OFFSET 0xC sort of works */ +#define AN_HOST_DESC_OFFSET 0x800 +#define AN_RX_DESC_OFFSET (AN_HOST_DESC_OFFSET + \ + sizeof(struct an_card_rid_desc)) +#define AN_TX_DESC_OFFSET (AN_RX_DESC_OFFSET + \ + (AN_MAX_RX_DESC * sizeof(struct an_card_rx_desc))) + +struct an_command { + u_int16_t an_cmd; + u_int16_t an_parm0; + u_int16_t an_parm1; + u_int16_t an_parm2; +}; + +struct an_reply { + u_int16_t an_status; + u_int16_t an_resp0; + u_int16_t an_resp1; + u_int16_t an_resp2; +}; + +/* + * Reclaim qualifier bit, applicable to the + * TX command. + */ +#define AN_RECLAIM 0x0100 /* reclaim NIC memory */ + +/* + * ACCESS command qualifier bits. + */ +#define AN_ACCESS_READ 0x0000 +#define AN_ACCESS_WRITE 0x0100 + +/* + * PROGRAM command qualifier bits. + */ +#define AN_PROGRAM_DISABLE 0x0000 +#define AN_PROGRAM_ENABLE_RAM 0x0100 +#define AN_PROGRAM_ENABLE_NVRAM 0x0200 +#define AN_PROGRAM_NVRAM 0x0300 + +/* Status register values */ +#define AN_STAT_CMD_CODE 0x003F +#define AN_STAT_CMD_RESULT 0x7F00 + +/* Linkstat register */ +#define AN_LINKSTAT_ASSOCIATED 0x0400 +#define AN_LINKSTAT_AUTHFAIL 0x0300 +#define AN_LINKSTAT_ASSOC_FAIL 0x8400 +#define AN_LINKSTAT_DISASSOC 0x8200 +#define AN_LINKSTAT_DEAUTH 0x8100 +#define AN_LINKSTAT_SYNCLOST_TSF 0x8004 +#define AN_LINKSTAT_SYNCLOST_HOSTREQ 0x8003 +#define AN_LINKSTAT_SYNCLOST_AVGRETRY 0x8002 +#define AN_LINKSTAT_SYNCLOST_MAXRETRY 0x8001 +#define AN_LINKSTAT_SYNCLOST_MISSBEACON 0x8000 + +/* memory handle management registers */ +#define AN_RX_FID 0x20 +#define AN_ALLOC_FID 0x22 +#define AN_TX_CMP_FID(x) (x ? 0x1a : 0x24) + +/* + * Buffer Access Path (BAP) registers. + * These are I/O channels. I believe you can use each one for + * any desired purpose independently of the other. In general + * though, we use BAP1 for reading and writing LTV records and + * reading received data frames, and BAP0 for writing transmit + * frames. This is a convention though, not a rule. + */ +#define AN_SEL0 0x18 +#define AN_SEL1 0x1A +#define AN_OFF0 0x1C +#define AN_OFF1 0x1E +#define AN_DATA0 0x36 +#define AN_DATA1 0x38 +#define AN_BAP0 AN_DATA0 +#define AN_BAP1 AN_DATA1 + +#define AN_OFF_BUSY 0x8000 +#define AN_OFF_ERR 0x4000 +#define AN_OFF_DONE 0x2000 +#define AN_OFF_DATAOFF 0x0FFF + +/* Event registers */ +#define AN_EVENT_STAT(x) (x ? 0x60 : 0x30) /* Event status */ +#define AN_INT_EN(x) (x ? 0x64 : 0x32) /* Interrupt enable/ + disable */ +#define AN_EVENT_ACK(x) (x ? 0x68 : 0x34) /* Ack event */ + +/* Events */ +#define AN_EV_CLR_STUCK_BUSY 0x4000 /* clear stuck busy bit */ +#define AN_EV_WAKEREQUEST 0x2000 /* awaken from PSP mode */ +#define AN_EV_MIC 0x1000 /* Message Integrity Check*/ +#define AN_EV_AWAKE 0x0100 /* station woke up from PSP mode*/ +#define AN_EV_LINKSTAT 0x0080 /* link status available */ +#define AN_EV_CMD 0x0010 /* command completed */ +#define AN_EV_ALLOC 0x0008 /* async alloc/reclaim completed */ +#define AN_EV_TX_CPY 0x0400 +#define AN_EV_TX_EXC 0x0004 /* async xmit completed with failure */ +#define AN_EV_TX 0x0002 /* async xmit completed succesfully */ +#define AN_EV_RX 0x0001 /* async rx completed */ + +#define AN_INTRS(x) \ + ( x ? (AN_EV_RX|AN_EV_TX|AN_EV_TX_EXC|AN_EV_TX_CPY|AN_EV_ALLOC \ + |AN_EV_LINKSTAT|AN_EV_MIC) \ + : \ + (AN_EV_RX|AN_EV_TX|AN_EV_TX_EXC|AN_EV_ALLOC \ + |AN_EV_LINKSTAT|AN_EV_MIC) \ + ) + +/* Host software registers */ +#define AN_SW0(x) (x ? 0x50 : 0x28) +#define AN_SW1(x) (x ? 0x54 : 0x2A) +#define AN_SW2(x) (x ? 0x58 : 0x2C) +#define AN_SW3(x) (x ? 0x5c : 0x2E) + +#define AN_CNTL 0x14 + +#define AN_CNTL_AUX_ENA 0xC000 +#define AN_CNTL_AUX_ENA_STAT 0xC000 +#define AN_CNTL_AUX_DIS_STAT 0x0000 +#define AN_CNTL_AUX_ENA_CNTL 0x8000 +#define AN_CNTL_AUX_DIS_CNTL 0x4000 + +#define AN_AUX_PAGE 0x3A +#define AN_AUX_OFFSET 0x3C +#define AN_AUX_DATA 0x3E + +/* + * Length, Type, Value (LTV) record definitions and RID values. + */ +struct an_ltv_gen { + u_int16_t an_len; + u_int16_t an_type; + u_int16_t an_val; +}; + +#define AN_DEF_SSID_LEN 7 +#define AN_DEF_SSID "tsunami" + +#define AN_RXGAP_MAX 8 + +/* + * Transmit frame structure. + */ +struct an_txframe { + u_int32_t an_tx_sw; /* 0x00 */ + u_int16_t an_tx_status; /* 0x04 */ + u_int16_t an_tx_payload_len; /* 0x06 */ + u_int16_t an_tx_ctl; /* 0x08 */ + u_int16_t an_tx_assoc_id; /* 0x0A */ + u_int16_t an_tx_retry; /* 0x0C */ + u_int8_t an_tx_assoc_cnt; /* 0x0E */ + u_int8_t an_tx_rate; /* 0x0F */ + u_int8_t an_tx_max_long_retries; /* 0x10 */ + u_int8_t an_tx_max_short_retries; /*0x11 */ + u_int8_t an_rsvd0[2]; /* 0x12 */ + u_int16_t an_frame_ctl; /* 0x14 */ + u_int16_t an_duration; /* 0x16 */ + u_int8_t an_addr1[6]; /* 0x18 */ + u_int8_t an_addr2[6]; /* 0x1E */ + u_int8_t an_addr3[6]; /* 0x24 */ + u_int16_t an_seq_ctl; /* 0x2A */ + u_int8_t an_addr4[6]; /* 0x2C */ + u_int8_t an_gaplen; /* 0x32 */ +} __packed; + +struct an_rxframe_802_3 { + u_int16_t an_rx_802_3_status; /* 0x34 */ + u_int16_t an_rx_802_3_payload_len;/* 0x36 */ + u_int8_t an_rx_dst_addr[6]; /* 0x38 */ + u_int8_t an_rx_src_addr[6]; /* 0x3E */ +}; +#define AN_RXGAP_MAX 8 + + +struct an_txframe_802_3 { +/* + * Transmit 802.3 header structure. + */ + u_int16_t an_tx_802_3_status; /* 0x34 */ + u_int16_t an_tx_802_3_payload_len;/* 0x36 */ + u_int8_t an_tx_dst_addr[6]; /* 0x38 */ + u_int8_t an_tx_src_addr[6]; /* 0x3E */ +}; + +#define AN_TXSTAT_EXCESS_RETRY 0x0002 +#define AN_TXSTAT_LIFE_EXCEEDED 0x0004 +#define AN_TXSTAT_AID_FAIL 0x0008 +#define AN_TXSTAT_MAC_DISABLED 0x0010 +#define AN_TXSTAT_ASSOC_LOST 0x0020 + +#define AN_TXCTL_RSVD 0x0001 +#define AN_TXCTL_TXOK_INTR 0x0002 +#define AN_TXCTL_TXERR_INTR 0x0004 +#define AN_TXCTL_HEADER_TYPE 0x0008 +#define AN_TXCTL_PAYLOAD_TYPE 0x0010 +#define AN_TXCTL_NORELEASE 0x0020 +#define AN_TXCTL_NORETRIES 0x0040 +#define AN_TXCTL_CLEAR_AID 0x0080 +#define AN_TXCTL_STRICT_ORDER 0x0100 +#define AN_TXCTL_USE_RTS 0x0200 + +#define AN_HEADERTYPE_8023 0x0000 +#define AN_HEADERTYPE_80211 0x0008 + +#define AN_PAYLOADTYPE_ETHER 0x0000 +#define AN_PAYLOADTYPE_LLC 0x0010 + +#define AN_TXCTL_80211 \ + (AN_TXCTL_TXOK_INTR|AN_TXCTL_TXERR_INTR|AN_HEADERTYPE_80211| \ + AN_PAYLOADTYPE_LLC|AN_TXCTL_NORELEASE) + +#define AN_TXCTL_8023 \ + (AN_TXCTL_TXOK_INTR|AN_TXCTL_TXERR_INTR|AN_HEADERTYPE_8023| \ + AN_PAYLOADTYPE_ETHER|AN_TXCTL_NORELEASE) + +#define AN_TXGAP_80211 0 +#define AN_TXGAP_8023 0 + +struct an_802_3_hdr { + u_int16_t an_8023_status; + u_int16_t an_8023_payload_len; + u_int8_t an_8023_dst_addr[6]; + u_int8_t an_8023_src_addr[6]; + u_int16_t an_8023_dat[3]; /* SNAP header */ + u_int16_t an_8023_type; +}; + +struct an_snap_hdr { + u_int16_t an_snap_dat[3]; /* SNAP header */ + u_int16_t an_snap_type; +}; + +struct an_dma_alloc { + u_int32_t an_dma_paddr; + caddr_t an_dma_vaddr; + bus_dmamap_t an_dma_map; + bus_dma_segment_t an_dma_seg; + bus_size_t an_dma_size; + int an_dma_nseg; +}; + +#define AN_TX_RING_CNT 4 +#define AN_INC(x, y) (x) = (x + 1) % y + +struct an_tx_ring_data { + u_int16_t an_tx_fids[AN_TX_RING_CNT]; + u_int16_t an_tx_ring[AN_TX_RING_CNT]; + int an_tx_prod; + int an_tx_cons; + int an_tx_empty; +}; + +struct an_softc { + struct ifnet *an_ifp; + + int an_unit; + + int port_rid; /* resource id for port range */ + struct resource* port_res; /* resource for port range */ + int mem_rid; /* resource id for memory range */ + int mem_used; /* nonzero if memory used */ + struct resource* mem_res; /* resource for memory range */ + int mem_aux_rid; /* resource id for memory range */ + int mem_aux_used; /* nonzero if memory used */ + struct resource* mem_aux_res; /* resource for memory range */ + int irq_rid; /* resource id for irq */ + void* irq_handle; /* handle for irq handler */ + struct resource* irq_res; /* resource for irq */ + + bus_space_handle_t an_bhandle_p; + bus_space_handle_t an_bhandle; + bus_space_tag_t an_btag; + bus_space_handle_t an_mem_bhandle; + bus_space_tag_t an_mem_btag; + bus_space_handle_t an_mem_aux_bhandle; + bus_space_tag_t an_mem_aux_btag; + bus_dma_tag_t an_dtag; + struct an_ltv_genconfig an_config; + struct an_ltv_caps an_caps; + struct an_ltv_ssidlist_new an_ssidlist; + struct an_ltv_aplist an_aplist; + struct an_ltv_key an_temp_keys[4]; + int an_tx_rate; + int an_rxmode; + int an_gone; + int an_if_flags; + u_int8_t an_txbuf[1536]; + struct an_tx_ring_data an_rdata; + struct an_ltv_stats an_stats; + struct an_ltv_status an_status; + u_int8_t an_associated; +#ifdef ANCACHE + int an_sigitems; + struct an_sigcache an_sigcache[MAXANCACHE]; + int an_nextitem; + int an_have_rssimap; + struct an_ltv_rssi_map an_rssimap; +#endif + struct callout an_stat_ch; + struct mtx an_mtx; + device_t an_dev; + struct ifmedia an_ifmedia; + int an_monitor; + int an_was_monitor; + u_char buf_802_11[MCLBYTES]; + struct an_req areq; + unsigned short* an_flash_buffer; + int mpi350; + struct an_dma_alloc an_rid_buffer; + struct an_dma_alloc an_rx_buffer[AN_MAX_RX_DESC]; + struct an_dma_alloc an_tx_buffer[AN_MAX_TX_DESC]; +}; + +#define AN_LOCK(_sc) mtx_lock(&(_sc)->an_mtx) +#define AN_UNLOCK(_sc) mtx_unlock(&(_sc)->an_mtx) +#define AN_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->an_mtx, MA_OWNED) + +void an_release_resources (device_t); +int an_alloc_port (device_t, int, int); +int an_alloc_memory (device_t, int, int); +int an_alloc_aux_memory (device_t, int, int); +int an_alloc_irq (device_t, int, int); +int an_pci_probe (device_t); +int an_probe (device_t); +int an_shutdown (device_t); +void an_resume (device_t); +int an_attach (struct an_softc *, int, int); +int an_detach (device_t); +void an_stop (struct an_softc *); + +driver_intr_t an_intr; + +#define AN_802_3_OFFSET 0x2E +#define AN_802_11_OFFSET 0x44 +#define AN_802_11_OFFSET_RAW 0x3C + +#define AN_STAT_BADCRC 0x0001 +#define AN_STAT_UNDECRYPTABLE 0x0002 +#define AN_STAT_ERRSTAT 0x0003 +#define AN_STAT_MAC_PORT 0x0700 +#define AN_STAT_1042 0x2000 /* RFC1042 encoded */ +#define AN_STAT_TUNNEL 0x4000 /* Bridge-tunnel encoded */ +#define AN_STAT_WMP_MSG 0x6000 /* WaveLAN-II management protocol */ +#define AN_RXSTAT_MSG_TYPE 0xE000 + +#define AN_ENC_TX_802_3 0x00 +#define AN_ENC_TX_802_11 0x11 +#define AN_ENC_TX_E_II 0x0E + +#define AN_ENC_TX_1042 0x00 +#define AN_ENC_TX_TUNNEL 0xF8 + +#define AN_TXCNTL_MACPORT 0x00FF +#define AN_TXCNTL_STRUCTTYPE 0xFF00 + +/* + * SNAP (sub-network access protocol) constants for transmission + * of IP datagrams over IEEE 802 networks, taken from RFC1042. + * We need these for the LLC/SNAP header fields in the TX/RX frame + * structure. + */ +#define AN_SNAP_K1 0xaa /* assigned global SAP for SNAP */ +#define AN_SNAP_K2 0x00 +#define AN_SNAP_CONTROL 0x03 /* unnumbered information format */ +#define AN_SNAP_WORD0 (AN_SNAP_K1 | (AN_SNAP_K1 << 8)) +#define AN_SNAP_WORD1 (AN_SNAP_K2 | (AN_SNAP_CONTROL << 8)) +#define AN_SNAPHDR_LEN 0x6 diff --git a/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/opt_inet.h b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/opt_inet.h new file mode 100644 index 0000000000..fdf700956d --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/aironetwifi/dev/an/opt_inet.h @@ -0,0 +1 @@ +#define INET 1 diff --git a/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/Jamfile b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/Jamfile new file mode 100644 index 0000000000..26158e37cf --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/Jamfile @@ -0,0 +1,23 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network wlan wavelanwifi ; + +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_wlan ] : true ; +UsePrivateHeaders net system ; +UsePrivateKernelHeaders ; + +SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] + -Wno-format + -Wno-unused + -Wno-uninitialized ; + +UseHeaders [ FDirName $(SUBDIR) ] : true ; + +SEARCH_SOURCE += [ FDirName $(SUBDIR) dev wi ] ; + +KernelAddon wavelanwifi : + if_wi.c + if_wi_pci.c + : + libfreebsd_wlan.a + libfreebsd_network.a + ; diff --git a/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wavelan_ieee.h b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wavelan_ieee.h new file mode 100644 index 0000000000..0061e638bd --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wavelan_ieee.h @@ -0,0 +1,753 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _IF_WAVELAN_IEEE_H +#define _IF_WAVELAN_IEEE_H + +/* + * This header defines a simple command interface to the FreeBSD + * WaveLAN/IEEE driver (wi) driver, which is used to set certain + * device-specific parameters which can't be easily managed through + * ifconfig(8). No, sysctl(2) is not the answer. I said a _simple_ + * interface, didn't I. + */ + +#ifndef SIOCSWAVELAN +#define SIOCSWAVELAN SIOCSIFGENERIC +#endif + +#ifndef SIOCGWAVELAN +#define SIOCGWAVELAN SIOCGIFGENERIC +#endif + +/* + * Technically I don't think there's a limit to a record + * length. The largest record is the one that contains the CIS + * data, which is 240 words long, so 256 should be a safe + * value. + */ +#define WI_MAX_DATALEN 512 + +#if 0 +struct wi_req { + u_int16_t wi_len; + u_int16_t wi_type; + u_int16_t wi_val[WI_MAX_DATALEN]; +}; +#endif + +/* + * Private LTV records (interpreted only by the driver). This is + * a minor kludge to allow reading the interface statistics from + * the driver. + */ +#define WI_RID_IFACE_STATS 0x0100 +#define WI_RID_MGMT_XMIT 0x0200 +#define WI_RID_ZERO_CACHE 0x0300 +#define WI_RID_READ_CACHE 0x0400 +#define WI_RID_FWDOWNLOAD 0x0500 +#define WI_RID_MONITOR_MODE 0x0600 +#define WI_RID_MIF 0x0700 +#define WI_RID_SCAN_APS 0x0800 +#define WI_RID_READ_APS 0x0900 + +struct wi_80211_hdr { + u_int16_t frame_ctl; + u_int16_t dur_id; + u_int8_t addr1[6]; + u_int8_t addr2[6]; + u_int8_t addr3[6]; + u_int16_t seq_ctl; + u_int8_t addr4[6]; +}; + +#define WI_FCTL_VERS 0x0002 +#define WI_FCTL_FTYPE 0x000C +#define WI_FCTL_STYPE 0x00F0 +#define WI_FCTL_TODS 0x0100 +#define WI_FCTL_FROMDS 0x0200 +#define WI_FCTL_MOREFRAGS 0x0400 +#define WI_FCTL_RETRY 0x0800 +#define WI_FCTL_PM 0x1000 +#define WI_FCTL_MOREDATA 0x2000 +#define WI_FCTL_WEP 0x4000 +#define WI_FCTL_ORDER 0x8000 + +#define WI_FTYPE_MGMT 0x0000 +#define WI_FTYPE_CTL 0x0004 +#define WI_FTYPE_DATA 0x0008 + +#define WI_STYPE_MGMT_ASREQ 0x0000 /* association request */ +#define WI_STYPE_MGMT_ASRESP 0x0010 /* association response */ +#define WI_STYPE_MGMT_REASREQ 0x0020 /* reassociation request */ +#define WI_STYPE_MGMT_REASRESP 0x0030 /* reassociation response */ +#define WI_STYPE_MGMT_PROBEREQ 0x0040 /* probe request */ +#define WI_STYPE_MGMT_PROBERESP 0x0050 /* probe response */ +#define WI_STYPE_MGMT_BEACON 0x0080 /* beacon */ +#define WI_STYPE_MGMT_ATIM 0x0090 /* announcement traffic ind msg */ +#define WI_STYPE_MGMT_DISAS 0x00A0 /* disassociation */ +#define WI_STYPE_MGMT_AUTH 0x00B0 /* authentication */ +#define WI_STYPE_MGMT_DEAUTH 0x00C0 /* deauthentication */ + +#define WI_STYPE_CTL_PSPOLL 0x00A0 +#define WI_STYPE_CTL_RTS 0x00B0 +#define WI_STYPE_CTL_CTS 0x00C0 +#define WI_STYPE_CTL_ACK 0x00D0 +#define WI_STYPE_CTL_CFEND 0x00E0 +#define WI_STYPE_CTL_CFENDACK 0x00F0 + +struct wi_mgmt_hdr { + u_int16_t frame_ctl; + u_int16_t duration; + u_int8_t dst_addr[6]; + u_int8_t src_addr[6]; + u_int8_t bssid[6]; + u_int16_t seq_ctl; +}; + +/* + * Lucent/wavelan IEEE signal strength cache + * + * driver keeps cache of last + * MAXWICACHE packets to arrive including signal strength info. + * daemons may read this via ioctl + * + * Each entry in the wi_sigcache has a unique macsrc. + */ +struct wi_sigcache { + char macsrc[6]; /* unique MAC address for entry */ + int ipsrc; /* ip address associated with packet */ + int signal; /* signal strength of the packet */ + int noise; /* noise value */ + int quality; /* quality of the packet */ +}; + +/* + * Firmware downloading API. We support downloading into RAM and into + * flash. We copy the entire .hex file for both the primary and secondary + * firmware into the kernel, which is minorly gross, but matches the + * format of the compiled in firmware. + */ +struct wi_fwdownload { + int type; /* What type of download. */ +#define WI_FW_RAM 1 +#define WI_FW_FLASH 2 + size_t pri_len; /* Primary firmware length */ + size_t sec_len; /* Secondary firmware length */ + caddr_t pri_data; /* Pointer (user) to primary data */ + caddr_t sec_data; /* Pointer (user) to secondary data */ +}; + +struct wi_counters { + u_int32_t wi_tx_unicast_frames; + u_int32_t wi_tx_multicast_frames; + u_int32_t wi_tx_fragments; + u_int32_t wi_tx_unicast_octets; + u_int32_t wi_tx_multicast_octets; + u_int32_t wi_tx_deferred_xmits; + u_int32_t wi_tx_single_retries; + u_int32_t wi_tx_multi_retries; + u_int32_t wi_tx_retry_limit; + u_int32_t wi_tx_discards; + u_int32_t wi_rx_unicast_frames; + u_int32_t wi_rx_multicast_frames; + u_int32_t wi_rx_fragments; + u_int32_t wi_rx_unicast_octets; + u_int32_t wi_rx_multicast_octets; + u_int32_t wi_rx_fcs_errors; + u_int32_t wi_rx_discards_nobuf; + u_int32_t wi_tx_discards_wrong_sa; + u_int32_t wi_rx_WEP_cant_decrypt; + u_int32_t wi_rx_msg_in_msg_frags; + u_int32_t wi_rx_msg_in_bad_msg_frags; +}; + +/* + * Network parameters, static configuration entities. + */ +#define WI_RID_PORTTYPE 0xFC00 /* Connection control characteristics */ +#define WI_RID_MAC_NODE 0xFC01 /* MAC address of this station */ +#define WI_RID_DESIRED_SSID 0xFC02 /* Service Set ID for connection */ +#define WI_RID_OWN_CHNL 0xFC03 /* Comm channel for BSS creation */ +#define WI_RID_OWN_SSID 0xFC04 /* IBSS creation ID */ +#define WI_RID_OWN_ATIM_WIN 0xFC05 /* ATIM window time for IBSS creation */ +#define WI_RID_SYSTEM_SCALE 0xFC06 /* scale that specifies AP density */ +#define WI_RID_MAX_DATALEN 0xFC07 /* Max len of MAC frame body data */ +#define WI_RID_MAC_WDS 0xFC08 /* MAC addr of corresponding WDS node */ +#define WI_RID_PM_ENABLED 0xFC09 /* ESS power management enable */ +#define WI_RID_PM_EPS 0xFC0A /* PM EPS/PS mode */ +#define WI_RID_MCAST_RX 0xFC0B /* ESS PM mcast reception */ +#define WI_RID_MAX_SLEEP 0xFC0C /* max sleep time for ESS PM */ +#define WI_RID_HOLDOVER 0xFC0D /* holdover time for ESS PM */ +#define WI_RID_NODENAME 0xFC0E /* ID name of this node for diag */ +#define WI_RID_DTIM_PERIOD 0xFC10 /* beacon interval between DTIMs */ +#define WI_RID_WDS_ADDR1 0xFC11 /* port 1 MAC of WDS link node */ +#define WI_RID_WDS_ADDR2 0xFC12 /* port 1 MAC of WDS link node */ +#define WI_RID_WDS_ADDR3 0xFC13 /* port 1 MAC of WDS link node */ +#define WI_RID_WDS_ADDR4 0xFC14 /* port 1 MAC of WDS link node */ +#define WI_RID_WDS_ADDR5 0xFC15 /* port 1 MAC of WDS link node */ +#define WI_RID_WDS_ADDR6 0xFC16 /* port 1 MAC of WDS link node */ +#define WI_RID_MCAST_PM_BUF 0xFC17 /* PM buffering of mcast */ +#define WI_RID_ENCRYPTION 0xFC20 /* enable/disable WEP */ +#define WI_RID_AUTHTYPE 0xFC21 /* specify authentication type */ +#define WI_RID_P2_TX_CRYPT_KEY 0xFC23 +#define WI_RID_P2_CRYPT_KEY0 0xFC24 +#define WI_RID_P2_CRYPT_KEY1 0xFC25 +#define WI_RID_MICROWAVE_OVEN 0xFC25 +#define WI_RID_P2_CRYPT_KEY2 0xFC26 +#define WI_RID_P2_CRYPT_KEY3 0xFC27 +#define WI_RID_P2_ENCRYPTION 0xFC28 +#define WI_RID_ALT_RETRY_CNT 0xFC32 +#define PRIVACY_INVOKED 0x01 +#define EXCLUDE_UNENCRYPTED 0x02 +#define HOST_ENCRYPT 0x10 +#define IV_EVERY_FRAME 0x00 /* IV = Initialization Vector */ +#define IV_EVERY10_FRAME 0x20 /* every 10 frame IV reuse */ +#define IV_EVERY50_FRAME 0x40 /* every 50 frame IV reuse */ +#define IV_EVERY100_FRAME 0x60 /* every 100 frame IV reuse */ +#define HOST_DECRYPT 0x80 +#define WI_RID_WEP_MAPTABLE 0xFC29 +#define WI_RID_CNFAUTHMODE 0xFC2A +#define WI_RID_ROAMING_MODE 0xFC2D +#define WI_RID_OWN_BEACON_INT 0xFC33 /* beacon xmit time for BSS creation */ +#define WI_RID_ENH_SECURITY 0xFC43 /* enhanced security (AP mode) */ +#define WI_RID_CNF_DBM_ADJUST 0xFC46 +#define WI_RID_DBM_ADJUST 0xFC46 /* RSSI - WI_RID_DBM_ADJUST ~ dBm */ +#define WI_RID_WPA_DATA 0xFC48 /* WPA IE */ +#define WI_RID_BASIC_RATE 0xFCB3 +#define WI_RID_SUPPORT_RATE 0xFCB4 +#define WI_RID_WPA_HANDLING 0xFCBB /* WPA handling procedures */ + +/* + * Network parameters, dynamic configuration entities + */ +#define WI_RID_MCAST_LIST 0xFC80 /* list of multicast addrs */ +#define WI_RID_CREATE_IBSS 0xFC81 /* create IBSS */ +#define WI_RID_FRAG_THRESH 0xFC82 /* frag len, unicast msg xmit */ +#define WI_RID_RTS_THRESH 0xFC83 /* frame len for RTS/CTS handshake */ +#define WI_RID_TX_RATE 0xFC84 /* data rate for message xmit + * 0 == Fixed 1mbps + * 1 == Fixed 2mbps + * 2 == auto fallback + */ +#define WI_RID_PROMISC 0xFC85 /* enable promisc mode */ +#define WI_RID_FRAG_THRESH0 0xFC90 +#define WI_RID_FRAG_THRESH1 0xFC91 +#define WI_RID_FRAG_THRESH2 0xFC92 +#define WI_RID_FRAG_THRESH3 0xFC93 +#define WI_RID_FRAG_THRESH4 0xFC94 +#define WI_RID_FRAG_THRESH5 0xFC95 +#define WI_RID_FRAG_THRESH6 0xFC96 +#define WI_RID_RTS_THRESH0 0xFC97 +#define WI_RID_RTS_THRESH1 0xFC98 +#define WI_RID_RTS_THRESH2 0xFC99 +#define WI_RID_RTS_THRESH3 0xFC9A +#define WI_RID_RTS_THRESH4 0xFC9B +#define WI_RID_RTS_THRESH5 0xFC9C +#define WI_RID_RTS_THRESH6 0xFC9D +#define WI_RID_TX_RATE0 0xFC9E +#define WI_RID_TX_RATE1 0xFC9F +#define WI_RID_TX_RATE2 0xFCA0 +#define WI_RID_TX_RATE3 0xFCA1 +#define WI_RID_TX_RATE4 0xFCA2 +#define WI_RID_TX_RATE5 0xFCA3 +#define WI_RID_TX_RATE6 0xFCA4 +#define WI_RID_DEFLT_CRYPT_KEYS 0xFCB0 +#define WI_RID_TX_CRYPT_KEY 0xFCB1 +#define WI_RID_TICK_TIME 0xFCE0 + +struct wi_key { + u_int16_t wi_keylen; + u_int8_t wi_keydat[14]; +}; + +#define WI_NLTV_KEYS 4 +struct wi_ltv_keys { + u_int16_t wi_len; + u_int16_t wi_type; + struct wi_key wi_keys[WI_NLTV_KEYS]; +}; + +/* + * NIC information + */ +#define WI_RID_DNLD_BUF 0xFD01 +#define WI_RID_MEMSZ 0xFD02 /* memory size info (XXX Lucent) */ + /* Looks like on lucnet pri firm too */ +#define WI_RID_PRI_IDENTITY 0xFD02 /* primary funcs firmware ident (PRISM2) */ +#define WI_RID_PRI_SUP_RANGE 0xFD03 /* primary supplier compatibility */ +#define WI_RID_CIF_ACT_RANGE 0xFD04 /* controller sup. compatibility */ +#define WI_RID_SERIALNO 0xFD0A /* card serial number */ +#define WI_RID_CARD_ID 0xFD0B /* card identification */ +#define WI_RID_MFI_SUP_RANGE 0xFD0C /* modem supplier compatibility */ +#define WI_RID_CFI_SUP_RANGE 0xFD0D /* controller sup. compatibility */ +#define WI_RID_CHANNEL_LIST 0xFD10 /* allowd comm. frequencies. */ +#define WI_RID_REG_DOMAINS 0xFD11 /* list of intendted regulatory doms */ +#define WI_RID_TEMP_TYPE 0xFD12 /* hw temp range code */ +#define WI_RID_CIS 0xFD13 /* PC card info struct */ +#define WI_RID_STA_IDENTITY 0xFD20 /* station funcs firmware ident */ +#define WI_RID_STA_SUP_RANGE 0xFD21 /* station supplier compat */ +#define WI_RID_MFI_ACT_RANGE 0xFD22 +#define WI_RID_SYMBOL_IDENTITY 0xFD24 +#define WI_RID_CFI_ACT_RANGE 0xFD33 +#define WI_RID_COMMQUAL 0xFD43 +#define WI_RID_SCALETHRESH 0xFD46 +#define WI_RID_PCF 0xFD87 + +/* + * MAC information + */ +#define WI_RID_PORT_STAT 0xFD40 /* actual MAC port con control stat */ +#define WI_RID_CURRENT_SSID 0xFD41 /* ID of actually connected SS */ +#define WI_RID_CURRENT_BSSID 0xFD42 /* ID of actually connected BSS */ +#define WI_RID_COMMS_QUALITY 0xFD43 /* quality of BSS connection */ +#define WI_RID_CUR_TX_RATE 0xFD44 /* current TX rate */ +#define WI_RID_CUR_BEACON_INT 0xFD45 /* current beacon interval */ +#define WI_RID_CUR_SCALE_THRESH 0xFD46 /* actual system scane thresh setting */ +#define WI_RID_PROT_RESP_TIME 0xFD47 /* time to wait for resp to req msg */ +#define WI_RID_SHORT_RTR_LIM 0xFD48 /* max tx attempts for short frames */ +#define WI_RID_LONG_RTS_LIM 0xFD49 /* max tx attempts for long frames */ +#define WI_RID_MAX_TX_LIFE 0xFD4A /* max tx frame handling duration */ +#define WI_RID_MAX_RX_LIFE 0xFD4B /* max rx frame handling duration */ +#define WI_RID_CF_POLL 0xFD4C /* contention free pollable ind */ +#define WI_RID_AUTH_ALGS 0xFD4D /* auth algorithms available */ +#define WI_RID_AUTH_TYPE 0xFD4E /* availanle auth types */ +#define WI_RID_WEP_AVAIL 0xFD4F /* WEP privacy option available */ +#define WI_RID_DBM_COMMS_QUAL 0xFD51 /* CommQuality normalized to dBm */ +#define WI_RID_CUR_TX_RATE1 0xFD80 +#define WI_RID_CUR_TX_RATE2 0xFD81 +#define WI_RID_CUR_TX_RATE3 0xFD82 +#define WI_RID_CUR_TX_RATE4 0xFD83 +#define WI_RID_CUR_TX_RATE5 0xFD84 +#define WI_RID_CUR_TX_RATE6 0xFD85 +#define WI_RID_OWN_MAC 0xFD86 /* unique local MAC addr */ +#define WI_RID_PCI_INFO 0xFD87 /* point coordination func cap */ + +/* + * Scan Information + */ +#define WI_RID_BCAST_SCAN_REQ 0xFCAB /* Broadcast Scan request (Symbol) */ +#define BSCAN_5SEC 0x01 +#define BSCAN_ONETIME 0x02 +#define BSCAN_PASSIVE 0x40 +#define BSCAN_BCAST 0x80 +#define WI_RID_SCAN_REQ 0xFCE1 /* Scan request (STA only) */ +#define WI_RID_JOIN_REQ 0xFCE2 /* Join request (STA only) */ +#define WI_RID_AUTH_STATION 0xFCE3 /* Authenticates Station (AP) */ +#define WI_RID_CHANNEL_REQ 0xFCE4 /* Channel Information Request (AP) */ +#define WI_RID_SCAN_RESULTS 0xFD88 /* Scan Results Table */ + +struct wi_apinfo { + int scanreason; /* ScanReason */ + char bssid[6]; /* BSSID (mac address) */ + int channel; /* Channel */ + int signal; /* Signal level */ + int noise; /* Average Noise Level*/ + int quality; /* Quality */ + int namelen; /* Length of SSID string */ + char name[32]; /* SSID string */ + int capinfo; /* Capability info. */ + int interval; /* BSS Beacon Interval */ + int rate; /* Data Rate */ +}; + +/* + * Modem information + */ +#define WI_RID_PHY_TYPE 0xFDC0 /* phys layer type indication */ +#define WI_RID_CURRENT_CHAN 0xFDC1 /* current frequency */ +#define WI_RID_PWR_STATE 0xFDC2 /* pwr consumption status */ +#define WI_RID_CCA_MODE 0xFDC3 /* clear chan assess mode indication */ +#define WI_RID_CCA_TIME 0xFDC4 /* clear chan assess time */ +#define WI_RID_MAC_PROC_DELAY 0xFDC5 /* MAC processing delay time */ +#define WI_RID_DATA_RATES 0xFDC6 /* supported data rates */ + +/* + * bsd-airtools v0.2 - source-mods v0.2 [common.h] + * by h1kari - (c) Dachb0den Labs 2001 + */ + +/* + * Copyright (c) 2001 Dachb0den Labs. + * David Hulton . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by David Hulton. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY David Hulton AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL David Hulton OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * standard hermes recieve frame used by wavelan/prism2 cards + */ +struct wi_rx_frame { + /* + * hermes prefix header. supplies information on the current status of + * the network and various other statistics gathered from the + * management/control frames as used internally. + */ + u_int16_t wi_status; + u_int16_t wi_ts0; + u_int16_t wi_ts1; + u_int8_t wi_silence; + u_int8_t wi_signal; + u_int8_t wi_rate; + u_int8_t wi_rx_flow; + u_int16_t wi_rsvd0; + u_int16_t wi_rsvd1; + /* + * standard 80211 frame header. all packets have to use this header as + * per the AN9900 from intersil, even management/control. for + * management packets, they just threw the header into the data field, + * but for control packets the headers are lost in translation and + * therefore not all control packet info can be displayed. + */ + u_int16_t wi_frame_ctl; + u_int16_t wi_id; + u_int8_t wi_addr1[6]; + u_int8_t wi_addr2[6]; + u_int8_t wi_addr3[6]; + u_int16_t wi_seq_ctl; + u_int8_t wi_addr4[6]; + u_int16_t wi_dat_len; + /* + * another wierdity with the drivers. they append a 802.3 header which + * is somewhat redundant, since all the same data is provided in the + * 802.11 header. + */ + u_int8_t wi_dst_addr[6]; + u_int8_t wi_src_addr[6]; + u_int16_t wi_len; +}; +#define WI_DATA_HDRLEN 0x3C +#define WI_MGMT_HDRLEN 0x3C +#define WI_CTL_HDRLEN 0x3C + + +/* + * all data packets have a snap (sub-network access protocol) header that + * isn't entirely definied, but added for ethernet compatibility. + */ +struct wi_snap_frame { + u_int16_t wi_dat[3]; + u_int16_t wi_type; +}; + + +/* + * management frame headers + * note: all management frames consist of a static header and variable length + * fields. + */ + +/* + * variable length field structure + */ +struct wi_mgmt_var_hdr { + u_int8_t wi_code; + u_int8_t wi_len; + u_int8_t wi_data[256]; +}; + +/* + * management beacon frame prefix + */ +struct wi_mgmt_beacon_hdr { + u_int32_t wi_ts0; + u_int32_t wi_ts1; + u_int16_t wi_interval; + u_int16_t wi_capinfo; +}; + +/* + * ibss announcement traffic indication message (atim) frame + * note: no parameters + */ + +/* + * management disassociation frame + */ +struct wi_mgmt_disas_hdr { + u_int16_t wi_reason; +}; + +/* + * management association request frame prefix + */ +struct wi_mgmt_asreq_hdr { + u_int16_t wi_capinfo; + u_int16_t wi_interval; +}; + +/* + * management association response frame prefix + */ +struct wi_mgmt_asresp_hdr { + u_int16_t wi_capinfo; + u_int16_t wi_status; + u_int16_t wi_aid; +}; + +/* + * management reassociation request frame prefix + */ +struct wi_mgmt_reasreq_hdr { + u_int16_t wi_capinfo; + u_int16_t wi_interval; + u_int8_t wi_currap[6]; +}; + +/* + * management reassociation response frame prefix + */ +struct wi_mgmt_reasresp_hdr { + u_int16_t wi_capinfo; + u_int16_t wi_status; + u_int16_t wi_aid; +}; + +/* + * management probe request frame prefix + * note: no static parameters, only variable length + */ + +/* + * management probe response frame prefix + */ +struct wi_mgmt_proberesp_hdr { + u_int32_t wi_ts0; + u_int32_t wi_ts1; + u_int16_t wi_interval; + u_int16_t wi_capinfo; +}; + +/* + * management authentication frame prefix + */ +struct wi_mgmt_auth_hdr { + u_int16_t wi_algo; + u_int16_t wi_seq; + u_int16_t wi_status; +}; + +/* + * management deauthentication frame + */ +struct wi_mgmt_deauth_hdr { + u_int16_t wi_reason; +}; + + +/* + * rid configuration register definitions + */ +#define WI_RID_SCAN_REQ 0xFCE1 /* scan request information */ +#define WI_RID_SCAN_RES 0xFD88 /* scan result information */ + +#define WI_RID_PROCFRAME 0x3137 /* Return full frame information */ +#define WI_RID_PRISM2 0x3138 /* tell if we're a prism2 card or not */ + + +/* + * 802.11 definitions + */ +#define WI_STAT_BADCRC 0x0001 +#define WI_STAT_UNDECRYPTABLE 0x0002 +#define WI_STAT_ERRSTAT 0x0003 +#define WI_STAT_MAC_PORT 0x0700 +#define WI_STAT_1042 0x2000 +#define WI_STAT_TUNNEL 0x4000 +#define WI_STAT_WMP_MSG 0x6000 +#define WI_RXSTAT_MSG_TYPE 0xE000 + +#define WI_FCTL_OPT_MASK 0xFF00 +#define WI_AID_SET 0xC000 +#define WI_AID_MASK 0x3FFF +#define WI_SCTL_FRAGNUM_MASK 0x000F +#define WI_SCTL_SEQNUM_MASK 0xFFF0 + +#define WI_STAT_UNSPEC_FAIL 1 +#define WI_STAT_CAPINFO_FAIL 10 +#define WI_STAT_REAS_DENY 11 +#define WI_STAT_ASSOC_DENY 12 +#define WI_STAT_ALGO_FAIL 13 +#define WI_STAT_SEQ_FAIL 14 +#define WI_STAT_CHAL_FAIL 15 +#define WI_STAT_TOUT_FAIL 16 +#define WI_STAT_OVERL_DENY 17 +#define WI_STAT_RATE_DENY 18 + +#define WI_FTYPE_MGMT 0x0000 +#define WI_FTYPE_CTL 0x0004 +#define WI_FTYPE_DATA 0x0008 + +#define WI_FCTL_VERS 0x0002 +#define WI_FCTL_FTYPE 0x000C +#define WI_FCTL_STYPE 0x00F0 +#define WI_FCTL_TODS 0x0100 +#define WI_FCTL_FROMDS 0x0200 +#define WI_FCTL_MOREFRAGS 0x0400 +#define WI_FCTL_RETRY 0x0800 +#define WI_FCTL_PM 0x1000 +#define WI_FCTL_MOREDATA 0x2000 +#define WI_FCTL_WEP 0x4000 +#define WI_FCTL_ORDER 0x8000 + +#define WI_FCS_LEN 0x4 /* checksum length */ + + +/* + * management definitions + */ +#define WI_STYPE_MGMT_ASREQ 0x0000 +#define WI_STYPE_MGMT_ASRESP 0x0010 +#define WI_STYPE_MGMT_REASREQ 0x0020 +#define WI_STYPE_MGMT_REASRESP 0x0030 +#define WI_STYPE_MGMT_PROBEREQ 0x0040 +#define WI_STYPE_MGMT_PROBERESP 0x0050 +#define WI_STYPE_MGMT_BEACON 0x0080 +#define WI_STYPE_MGMT_ATIM 0x0090 +#define WI_STYPE_MGMT_DISAS 0x00A0 +#define WI_STYPE_MGMT_AUTH 0x00B0 +#define WI_STYPE_MGMT_DEAUTH 0x00C0 + +#define WI_CAPINFO_ESS 0x01 +#define WI_CAPINFO_IBSS 0x02 +#define WI_CAPINFO_CFPOLL 0x04 +#define WI_CAPINFO_CFPOLLREQ 0x08 +#define WI_CAPINFO_PRIV 0x10 + +#define WI_REASON_UNSPEC 1 +#define WI_REASON_AUTH_INVALID 2 +#define WI_REASON_DEAUTH_LEAVE 3 +#define WI_REASON_DISAS_INACT 4 +#define WI_REASON_DISAS_OVERL 5 +#define WI_REASON_CLASS2 6 +#define WI_REASON_CLASS3 7 +#define WI_REASON_DISAS_LEAVE 8 +#define WI_REASON_NOAUTH 9 + +#define WI_VAR_SSID 0 +#define WI_VAR_SRATES 1 +#define WI_VAR_FH 2 +#define WI_VAR_DS 3 +#define WI_VAR_CF 4 +#define WI_VAR_TIM 5 +#define WI_VAR_IBSS 6 +#define WI_VAR_CHAL 16 + +#define WI_VAR_SRATES_MASK 0x7F + + +/* + * control definitions + */ +#define WI_STYPE_CTL_PSPOLL 0x00A0 +#define WI_STYPE_CTL_RTS 0x00B0 +#define WI_STYPE_CTL_CTS 0x00C0 +#define WI_STYPE_CTL_ACK 0x00D0 +#define WI_STYPE_CTL_CFEND 0x00E0 +#define WI_STYPE_CTL_CFENDCFACK 0x00F0 + + +/* + * ap scanning structures + */ +struct wi_scan_res { + u_int16_t wi_chan; + u_int16_t wi_noise; + u_int16_t wi_signal; + u_int8_t wi_bssid[6]; + u_int16_t wi_interval; + u_int16_t wi_capinfo; + u_int16_t wi_ssid_len; + u_int8_t wi_ssid[32]; + u_int8_t wi_srates[10]; + u_int8_t wi_rate; + u_int8_t wi_rsvd; +}; +#define WI_WAVELAN_RES_SIZE 50 + +struct wi_scan_p2_hdr { + u_int16_t wi_rsvd; + u_int16_t wi_reason; +}; +#define WI_PRISM2_RES_SIZE 62 + + +/* + * prism2 debug mode definitions + */ +#define SIOCSPRISM2DEBUG _IOW('i', 137, struct ifreq) +#define SIOCGPRISM2DEBUG _IOWR('i', 138, struct ifreq) + +#define WI_DEBUG_RESET 0x00 +#define WI_DEBUG_INIT 0x01 +#define WI_DEBUG_SLEEP 0x02 +#define WI_DEBUG_WAKE 0x03 +#define WI_DEBUG_CHAN 0x08 +#define WI_DEBUG_DELAYSUPP 0x09 +#define WI_DEBUG_TXSUPP 0x0A +#define WI_DEBUG_MONITOR 0x0B +#define WI_DEBUG_LEDTEST 0x0C +#define WI_DEBUG_CONTTX 0x0E +#define WI_DEBUG_STOPTEST 0x0F +#define WI_DEBUG_CONTRX 0x10 +#define WI_DEBUG_SIGSTATE 0x11 +#define WI_DEBUG_CALENABLE 0x13 +#define WI_DEBUG_CONFBITS 0x15 + +#endif diff --git a/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi.c b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi.c new file mode 100644 index 0000000000..616c5d7b33 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi.c @@ -0,0 +1,2124 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Lucent WaveLAN/IEEE 802.11 PCMCIA driver. + * + * Original FreeBSD driver written by Bill Paul + * Electrical Engineering Department + * Columbia University, New York City + */ + +/* + * The WaveLAN/IEEE adapter is the second generation of the WaveLAN + * from Lucent. Unlike the older cards, the new ones are programmed + * entirely via a firmware-driven controller called the Hermes. + * Unfortunately, Lucent will not release the Hermes programming manual + * without an NDA (if at all). What they do release is an API library + * called the HCF (Hardware Control Functions) which is supposed to + * do the device-specific operations of a device driver for you. The + * publically available version of the HCF library (the 'HCF Light') is + * a) extremely gross, b) lacks certain features, particularly support + * for 802.11 frames, and c) is contaminated by the GNU Public License. + * + * This driver does not use the HCF or HCF Light at all. Instead, it + * programs the Hermes controller directly, using information gleaned + * from the HCF Light code and corresponding documentation. + * + * This driver supports the ISA, PCMCIA and PCI versions of the Lucent + * WaveLan cards (based on the Hermes chipset), as well as the newer + * Prism 2 chipsets with firmware from Intersil and Symbol. + */ + +#include +__FBSDID("$FreeBSD$"); + +#define WI_HERMES_STATS_WAR /* Work around stats counter bug. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +static struct ieee80211vap *wi_vap_create(struct ieee80211com *ic, + const char name[IFNAMSIZ], int unit, int opmode, int flags, + const uint8_t bssid[IEEE80211_ADDR_LEN], + const uint8_t mac[IEEE80211_ADDR_LEN]); +static void wi_vap_delete(struct ieee80211vap *vap); +static void wi_stop_locked(struct wi_softc *sc, int disable); +static void wi_start_locked(struct ifnet *); +static void wi_start(struct ifnet *); +static int wi_start_tx(struct ifnet *ifp, struct wi_frame *frmhdr, + struct mbuf *m0); +static int wi_raw_xmit(struct ieee80211_node *, struct mbuf *, + const struct ieee80211_bpf_params *); +static int wi_newstate_sta(struct ieee80211vap *, enum ieee80211_state, int); +static int wi_newstate_hostap(struct ieee80211vap *, enum ieee80211_state, + int); +static void wi_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m, + int subtype, int rssi, int nf); +static int wi_reset(struct wi_softc *); +static void wi_watchdog(void *); +static int wi_ioctl(struct ifnet *, u_long, caddr_t); +static void wi_media_status(struct ifnet *, struct ifmediareq *); + +static void wi_rx_intr(struct wi_softc *); +static void wi_tx_intr(struct wi_softc *); +static void wi_tx_ex_intr(struct wi_softc *); + +static void wi_info_intr(struct wi_softc *); + +static int wi_write_txrate(struct wi_softc *, struct ieee80211vap *); +static int wi_write_wep(struct wi_softc *, struct ieee80211vap *); +static int wi_write_multi(struct wi_softc *); +static void wi_update_mcast(struct ifnet *); +static void wi_update_promisc(struct ifnet *); +static int wi_alloc_fid(struct wi_softc *, int, int *); +static void wi_read_nicid(struct wi_softc *); +static int wi_write_ssid(struct wi_softc *, int, u_int8_t *, int); + +static int wi_cmd(struct wi_softc *, int, int, int, int); +static int wi_seek_bap(struct wi_softc *, int, int); +static int wi_read_bap(struct wi_softc *, int, int, void *, int); +static int wi_write_bap(struct wi_softc *, int, int, void *, int); +static int wi_mwrite_bap(struct wi_softc *, int, int, struct mbuf *, int); +static int wi_read_rid(struct wi_softc *, int, void *, int *); +static int wi_write_rid(struct wi_softc *, int, void *, int); +static int wi_write_appie(struct wi_softc *, int, const struct ieee80211_appie *); + +static void wi_scan_start(struct ieee80211com *); +static void wi_scan_end(struct ieee80211com *); +static void wi_set_channel(struct ieee80211com *); + +static __inline int +wi_write_val(struct wi_softc *sc, int rid, u_int16_t val) +{ + + val = htole16(val); + return wi_write_rid(sc, rid, &val, sizeof(val)); +} + +SYSCTL_NODE(_hw, OID_AUTO, wi, CTLFLAG_RD, 0, "Wireless driver parameters"); + +static struct timeval lasttxerror; /* time of last tx error msg */ +static int curtxeps; /* current tx error msgs/sec */ +static int wi_txerate = 0; /* tx error rate: max msgs/sec */ +SYSCTL_INT(_hw_wi, OID_AUTO, txerate, CTLFLAG_RW, &wi_txerate, + 0, "max tx error msgs/sec; 0 to disable msgs"); + +#define WI_DEBUG +#ifdef WI_DEBUG +static int wi_debug = 0; +SYSCTL_INT(_hw_wi, OID_AUTO, debug, CTLFLAG_RW, &wi_debug, + 0, "control debugging printfs"); +#define DPRINTF(X) if (wi_debug) printf X +#else +#define DPRINTF(X) +#endif + +#define WI_INTRS (WI_EV_RX | WI_EV_ALLOC | WI_EV_INFO) + +struct wi_card_ident wi_card_ident[] = { + /* CARD_ID CARD_NAME FIRM_TYPE */ + { WI_NIC_LUCENT_ID, WI_NIC_LUCENT_STR, WI_LUCENT }, + { WI_NIC_SONY_ID, WI_NIC_SONY_STR, WI_LUCENT }, + { WI_NIC_LUCENT_EMB_ID, WI_NIC_LUCENT_EMB_STR, WI_LUCENT }, + { WI_NIC_EVB2_ID, WI_NIC_EVB2_STR, WI_INTERSIL }, + { WI_NIC_HWB3763_ID, WI_NIC_HWB3763_STR, WI_INTERSIL }, + { WI_NIC_HWB3163_ID, WI_NIC_HWB3163_STR, WI_INTERSIL }, + { WI_NIC_HWB3163B_ID, WI_NIC_HWB3163B_STR, WI_INTERSIL }, + { WI_NIC_EVB3_ID, WI_NIC_EVB3_STR, WI_INTERSIL }, + { WI_NIC_HWB1153_ID, WI_NIC_HWB1153_STR, WI_INTERSIL }, + { WI_NIC_P2_SST_ID, WI_NIC_P2_SST_STR, WI_INTERSIL }, + { WI_NIC_EVB2_SST_ID, WI_NIC_EVB2_SST_STR, WI_INTERSIL }, + { WI_NIC_3842_EVA_ID, WI_NIC_3842_EVA_STR, WI_INTERSIL }, + { WI_NIC_3842_PCMCIA_AMD_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL }, + { WI_NIC_3842_PCMCIA_SST_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL }, + { WI_NIC_3842_PCMCIA_ATL_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL }, + { WI_NIC_3842_PCMCIA_ATS_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL }, + { WI_NIC_3842_MINI_AMD_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL }, + { WI_NIC_3842_MINI_SST_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL }, + { WI_NIC_3842_MINI_ATL_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL }, + { WI_NIC_3842_MINI_ATS_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL }, + { WI_NIC_3842_PCI_AMD_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL }, + { WI_NIC_3842_PCI_SST_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL }, + { WI_NIC_3842_PCI_ATS_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL }, + { WI_NIC_3842_PCI_ATL_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL }, + { WI_NIC_P3_PCMCIA_AMD_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL }, + { WI_NIC_P3_PCMCIA_SST_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL }, + { WI_NIC_P3_PCMCIA_ATL_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL }, + { WI_NIC_P3_PCMCIA_ATS_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL }, + { WI_NIC_P3_MINI_AMD_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL }, + { WI_NIC_P3_MINI_SST_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL }, + { WI_NIC_P3_MINI_ATL_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL }, + { WI_NIC_P3_MINI_ATS_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL }, + { 0, NULL, 0 }, +}; + +static char *wi_firmware_names[] = { "none", "Hermes", "Intersil", "Symbol" }; + +devclass_t wi_devclass; + +int +wi_attach(device_t dev) +{ + struct wi_softc *sc = device_get_softc(dev); + struct ieee80211com *ic; + struct ifnet *ifp; + int i, nrates, buflen; + u_int16_t val; + u_int8_t ratebuf[2 + IEEE80211_RATE_SIZE]; + struct ieee80211_rateset *rs; + struct sysctl_ctx_list *sctx; + struct sysctl_oid *soid; + static const u_int8_t empty_macaddr[IEEE80211_ADDR_LEN] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + int error; + uint8_t macaddr[IEEE80211_ADDR_LEN]; + + ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); + if (ifp == NULL) { + device_printf(dev, "can not if_alloc\n"); + wi_free(dev); + return ENOSPC; + } + ic = ifp->if_l2com; + + sc->sc_firmware_type = WI_NOTYPE; + sc->wi_cmd_count = 500; + /* Reset the NIC. */ + if (wi_reset(sc) != 0) { + wi_free(dev); + return ENXIO; /* XXX */ + } + + /* Read NIC identification */ + wi_read_nicid(sc); + switch (sc->sc_firmware_type) { + case WI_LUCENT: + if (sc->sc_sta_firmware_ver < 60006) + goto reject; + break; + case WI_INTERSIL: + if (sc->sc_sta_firmware_ver < 800) + goto reject; + break; + default: + reject: + device_printf(dev, "Sorry, this card is not supported " + "(type %d, firmware ver %d)\n", + sc->sc_firmware_type, sc->sc_sta_firmware_ver); + wi_free(dev); + return EOPNOTSUPP; + } + + /* Export info about the device via sysctl */ + sctx = device_get_sysctl_ctx(dev); + soid = device_get_sysctl_tree(dev); + SYSCTL_ADD_STRING(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, + "firmware_type", CTLFLAG_RD, + wi_firmware_names[sc->sc_firmware_type], 0, + "Firmware type string"); + SYSCTL_ADD_INT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "sta_version", + CTLFLAG_RD, &sc->sc_sta_firmware_ver, 0, + "Station Firmware version"); + if (sc->sc_firmware_type == WI_INTERSIL) + SYSCTL_ADD_INT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, + "pri_version", CTLFLAG_RD, &sc->sc_pri_firmware_ver, 0, + "Primary Firmware version"); + SYSCTL_ADD_XINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "nic_id", + CTLFLAG_RD, &sc->sc_nic_id, 0, "NIC id"); + SYSCTL_ADD_STRING(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "nic_name", + CTLFLAG_RD, sc->sc_nic_name, 0, "NIC name"); + + mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, + MTX_DEF | MTX_RECURSE); + callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0); + + /* + * Read the station address. + * And do it twice. I've seen PRISM-based cards that return + * an error when trying to read it the first time, which causes + * the probe to fail. + */ + buflen = IEEE80211_ADDR_LEN; + error = wi_read_rid(sc, WI_RID_MAC_NODE, macaddr, &buflen); + if (error != 0) { + buflen = IEEE80211_ADDR_LEN; + error = wi_read_rid(sc, WI_RID_MAC_NODE, macaddr, &buflen); + } + if (error || IEEE80211_ADDR_EQ(macaddr, empty_macaddr)) { + if (error != 0) + device_printf(dev, "mac read failed %d\n", error); + else { + device_printf(dev, "mac read failed (all zeros)\n"); + error = ENXIO; + } + wi_free(dev); + return (error); + } + + ifp->if_softc = sc; + if_initname(ifp, device_get_name(dev), device_get_unit(dev)); + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = wi_ioctl; + ifp->if_start = wi_start; + ifp->if_init = wi_init; + IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); + ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; + IFQ_SET_READY(&ifp->if_snd); + + ic->ic_ifp = ifp; + ic->ic_phytype = IEEE80211_T_DS; + ic->ic_opmode = IEEE80211_M_STA; + ic->ic_caps = IEEE80211_C_STA + | IEEE80211_C_PMGT + | IEEE80211_C_MONITOR + ; + + /* + * Query the card for available channels and setup the + * channel table. We assume these are all 11b channels. + */ + buflen = sizeof(val); + if (wi_read_rid(sc, WI_RID_CHANNEL_LIST, &val, &buflen) != 0) + val = htole16(0x1fff); /* assume 1-11 */ + KASSERT(val != 0, ("wi_attach: no available channels listed!")); + + val <<= 1; /* shift for base 1 indices */ + for (i = 1; i < 16; i++) { + struct ieee80211_channel *c; + + if (!isset((u_int8_t*)&val, i)) + continue; + c = &ic->ic_channels[ic->ic_nchans++]; + c->ic_freq = ieee80211_ieee2mhz(i, IEEE80211_CHAN_B); + c->ic_flags = IEEE80211_CHAN_B; + c->ic_ieee = i; + /* XXX txpowers? */ + } + + /* + * Set flags based on firmware version. + */ + switch (sc->sc_firmware_type) { + case WI_LUCENT: + sc->sc_ntxbuf = 1; + ic->ic_caps |= IEEE80211_C_IBSS; + + sc->sc_ibss_port = WI_PORTTYPE_BSS; + sc->sc_monitor_port = WI_PORTTYPE_ADHOC; + sc->sc_min_rssi = WI_LUCENT_MIN_RSSI; + sc->sc_max_rssi = WI_LUCENT_MAX_RSSI; + sc->sc_dbm_offset = WI_LUCENT_DBM_OFFSET; + break; + case WI_INTERSIL: + sc->sc_ntxbuf = WI_NTXBUF; + sc->sc_flags |= WI_FLAGS_HAS_FRAGTHR + | WI_FLAGS_HAS_ROAMING; + /* + * Old firmware are slow, so give peace a chance. + */ + if (sc->sc_sta_firmware_ver < 10000) + sc->wi_cmd_count = 5000; + if (sc->sc_sta_firmware_ver > 10101) + sc->sc_flags |= WI_FLAGS_HAS_DBMADJUST; + ic->ic_caps |= IEEE80211_C_IBSS; + /* + * version 0.8.3 and newer are the only ones that are known + * to currently work. Earlier versions can be made to work, + * at least according to the Linux driver but we require + * monitor mode so this is irrelevant. + */ + ic->ic_caps |= IEEE80211_C_HOSTAP; + if (sc->sc_sta_firmware_ver >= 10603) + sc->sc_flags |= WI_FLAGS_HAS_ENHSECURITY; + if (sc->sc_sta_firmware_ver >= 10700) { + /* + * 1.7.0+ have the necessary support for sta mode WPA. + */ + sc->sc_flags |= WI_FLAGS_HAS_WPASUPPORT; + ic->ic_caps |= IEEE80211_C_WPA; + } + + sc->sc_ibss_port = WI_PORTTYPE_IBSS; + sc->sc_monitor_port = WI_PORTTYPE_APSILENT; + sc->sc_min_rssi = WI_PRISM_MIN_RSSI; + sc->sc_max_rssi = WI_PRISM_MAX_RSSI; + sc->sc_dbm_offset = WI_PRISM_DBM_OFFSET; + break; + } + + /* + * Find out if we support WEP on this card. + */ + buflen = sizeof(val); + if (wi_read_rid(sc, WI_RID_WEP_AVAIL, &val, &buflen) == 0 && + val != htole16(0)) + ic->ic_cryptocaps |= IEEE80211_CRYPTO_WEP; + + /* Find supported rates. */ + buflen = sizeof(ratebuf); + rs = &ic->ic_sup_rates[IEEE80211_MODE_11B]; + if (wi_read_rid(sc, WI_RID_DATA_RATES, ratebuf, &buflen) == 0) { + nrates = le16toh(*(u_int16_t *)ratebuf); + if (nrates > IEEE80211_RATE_MAXSIZE) + nrates = IEEE80211_RATE_MAXSIZE; + rs->rs_nrates = 0; + for (i = 0; i < nrates; i++) + if (ratebuf[2+i]) + rs->rs_rates[rs->rs_nrates++] = ratebuf[2+i]; + } else { + /* XXX fallback on error? */ + } + + buflen = sizeof(val); + if ((sc->sc_flags & WI_FLAGS_HAS_DBMADJUST) && + wi_read_rid(sc, WI_RID_DBM_ADJUST, &val, &buflen) == 0) { + sc->sc_dbm_offset = le16toh(val); + } + + sc->sc_portnum = WI_DEFAULT_PORT; + + ieee80211_ifattach(ic, macaddr); + ic->ic_raw_xmit = wi_raw_xmit; + ic->ic_scan_start = wi_scan_start; + ic->ic_scan_end = wi_scan_end; + ic->ic_set_channel = wi_set_channel; + + ic->ic_vap_create = wi_vap_create; + ic->ic_vap_delete = wi_vap_delete; + ic->ic_update_mcast = wi_update_mcast; + ic->ic_update_promisc = wi_update_promisc; + + ieee80211_radiotap_attach(ic, + &sc->sc_tx_th.wt_ihdr, sizeof(sc->sc_tx_th), + WI_TX_RADIOTAP_PRESENT, + &sc->sc_rx_th.wr_ihdr, sizeof(sc->sc_rx_th), + WI_RX_RADIOTAP_PRESENT); + + if (bootverbose) + ieee80211_announce(ic); + + error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, + NULL, wi_intr, sc, &sc->wi_intrhand); + if (error) { + device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); + ieee80211_ifdetach(ic); + if_free(sc->sc_ifp); + wi_free(dev); + return error; + } + + return (0); +} + +int +wi_detach(device_t dev) +{ + struct wi_softc *sc = device_get_softc(dev); + struct ifnet *ifp = sc->sc_ifp; + struct ieee80211com *ic = ifp->if_l2com; + + WI_LOCK(sc); + + /* check if device was removed */ + sc->wi_gone |= !bus_child_present(dev); + + wi_stop_locked(sc, 0); + WI_UNLOCK(sc); + ieee80211_ifdetach(ic); + + bus_teardown_intr(dev, sc->irq, sc->wi_intrhand); + if_free(sc->sc_ifp); + wi_free(dev); + mtx_destroy(&sc->sc_mtx); + return (0); +} + +static struct ieee80211vap * +wi_vap_create(struct ieee80211com *ic, + const char name[IFNAMSIZ], int unit, int opmode, int flags, + const uint8_t bssid[IEEE80211_ADDR_LEN], + const uint8_t mac[IEEE80211_ADDR_LEN]) +{ + struct wi_softc *sc = ic->ic_ifp->if_softc; + struct wi_vap *wvp; + struct ieee80211vap *vap; + + if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */ + return NULL; + wvp = (struct wi_vap *) malloc(sizeof(struct wi_vap), + M_80211_VAP, M_NOWAIT | M_ZERO); + if (wvp == NULL) + return NULL; + + vap = &wvp->wv_vap; + ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac); + + vap->iv_max_aid = WI_MAX_AID; + + switch (opmode) { + case IEEE80211_M_STA: + sc->sc_porttype = WI_PORTTYPE_BSS; + wvp->wv_newstate = vap->iv_newstate; + vap->iv_newstate = wi_newstate_sta; + /* need to filter mgt frames to avoid confusing state machine */ + wvp->wv_recv_mgmt = vap->iv_recv_mgmt; + vap->iv_recv_mgmt = wi_recv_mgmt; + break; + case IEEE80211_M_IBSS: + sc->sc_porttype = sc->sc_ibss_port; + wvp->wv_newstate = vap->iv_newstate; + vap->iv_newstate = wi_newstate_sta; + break; + case IEEE80211_M_AHDEMO: + sc->sc_porttype = WI_PORTTYPE_ADHOC; + break; + case IEEE80211_M_HOSTAP: + sc->sc_porttype = WI_PORTTYPE_HOSTAP; + wvp->wv_newstate = vap->iv_newstate; + vap->iv_newstate = wi_newstate_hostap; + break; + case IEEE80211_M_MONITOR: + sc->sc_porttype = sc->sc_monitor_port; + break; + default: + break; + } + + /* complete setup */ + ieee80211_vap_attach(vap, ieee80211_media_change, wi_media_status); + ic->ic_opmode = opmode; + return vap; +} + +static void +wi_vap_delete(struct ieee80211vap *vap) +{ + struct wi_vap *wvp = WI_VAP(vap); + + ieee80211_vap_detach(vap); + free(wvp, M_80211_VAP); +} + +int +wi_shutdown(device_t dev) +{ + struct wi_softc *sc = device_get_softc(dev); + + wi_stop(sc, 1); + return (0); +} + +void +wi_intr(void *arg) +{ + struct wi_softc *sc = arg; + struct ifnet *ifp = sc->sc_ifp; + u_int16_t status; + + WI_LOCK(sc); + + if (sc->wi_gone || !sc->sc_enabled || (ifp->if_flags & IFF_UP) == 0) { + CSR_WRITE_2(sc, WI_INT_EN, 0); + CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF); + WI_UNLOCK(sc); + return; + } + + /* Disable interrupts. */ + CSR_WRITE_2(sc, WI_INT_EN, 0); + + status = CSR_READ_2(sc, WI_EVENT_STAT); + if (status & WI_EV_RX) + wi_rx_intr(sc); + if (status & WI_EV_ALLOC) + wi_tx_intr(sc); + if (status & WI_EV_TX_EXC) + wi_tx_ex_intr(sc); + if (status & WI_EV_INFO) + wi_info_intr(sc); + if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0 && + !IFQ_DRV_IS_EMPTY(&ifp->if_snd)) + wi_start_locked(ifp); + + /* Re-enable interrupts. */ + CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS); + + WI_UNLOCK(sc); + + return; +} + +static void +wi_enable(struct wi_softc *sc) +{ + /* Enable interrupts */ + CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS); + + /* enable port */ + wi_cmd(sc, WI_CMD_ENABLE | sc->sc_portnum, 0, 0, 0); + sc->sc_enabled = 1; +} + +static int +wi_setup_locked(struct wi_softc *sc, int porttype, int mode, + uint8_t mac[IEEE80211_ADDR_LEN]) +{ + int i; + + wi_reset(sc); + + wi_write_val(sc, WI_RID_PORTTYPE, porttype); + wi_write_val(sc, WI_RID_CREATE_IBSS, mode); + wi_write_val(sc, WI_RID_MAX_DATALEN, 2304); + /* XXX IEEE80211_BPF_NOACK wants 0 */ + wi_write_val(sc, WI_RID_ALT_RETRY_CNT, 2); + if (sc->sc_flags & WI_FLAGS_HAS_ROAMING) + wi_write_val(sc, WI_RID_ROAMING_MODE, 3); /* NB: disabled */ + + wi_write_rid(sc, WI_RID_MAC_NODE, mac, IEEE80211_ADDR_LEN); + + /* Allocate fids for the card */ + sc->sc_buflen = IEEE80211_MAX_LEN + sizeof(struct wi_frame); + for (i = 0; i < sc->sc_ntxbuf; i++) { + int error = wi_alloc_fid(sc, sc->sc_buflen, + &sc->sc_txd[i].d_fid); + if (error) { + device_printf(sc->sc_dev, + "tx buffer allocation failed (error %u)\n", + error); + return error; + } + sc->sc_txd[i].d_len = 0; + } + sc->sc_txcur = sc->sc_txnext = 0; + + return 0; +} + +static void +wi_init_locked(struct wi_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + int wasenabled; + + WI_LOCK_ASSERT(sc); + + wasenabled = sc->sc_enabled; + if (wasenabled) + wi_stop_locked(sc, 1); + + if (wi_setup_locked(sc, sc->sc_porttype, 3, IF_LLADDR(ifp)) != 0) { + if_printf(ifp, "interface not running\n"); + wi_stop_locked(sc, 1); + return; + } + + ifp->if_drv_flags |= IFF_DRV_RUNNING; + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + + callout_reset(&sc->sc_watchdog, hz, wi_watchdog, sc); + + wi_enable(sc); /* Enable desired port */ +} + +void +wi_init(void *arg) +{ + struct wi_softc *sc = arg; + struct ifnet *ifp = sc->sc_ifp; + struct ieee80211com *ic = ifp->if_l2com; + + WI_LOCK(sc); + wi_init_locked(sc); + WI_UNLOCK(sc); + + if (ifp->if_drv_flags & IFF_DRV_RUNNING) + ieee80211_start_all(ic); /* start all vap's */ +} + +static void +wi_stop_locked(struct wi_softc *sc, int disable) +{ + struct ifnet *ifp = sc->sc_ifp; + + WI_LOCK_ASSERT(sc); + + if (sc->sc_enabled && !sc->wi_gone) { + CSR_WRITE_2(sc, WI_INT_EN, 0); + wi_cmd(sc, WI_CMD_DISABLE | sc->sc_portnum, 0, 0, 0); + if (disable) + sc->sc_enabled = 0; + } else if (sc->wi_gone && disable) /* gone --> not enabled */ + sc->sc_enabled = 0; + + callout_stop(&sc->sc_watchdog); + sc->sc_tx_timer = 0; + sc->sc_false_syns = 0; + + ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING); +} + +void +wi_stop(struct wi_softc *sc, int disable) +{ + WI_LOCK(sc); + wi_stop_locked(sc, disable); + WI_UNLOCK(sc); +} + +static void +wi_set_channel(struct ieee80211com *ic) +{ + struct ifnet *ifp = ic->ic_ifp; + struct wi_softc *sc = ifp->if_softc; + + DPRINTF(("%s: channel %d, %sscanning\n", __func__, + ieee80211_chan2ieee(ic, ic->ic_curchan), + ic->ic_flags & IEEE80211_F_SCAN ? "" : "!")); + + WI_LOCK(sc); + wi_write_val(sc, WI_RID_OWN_CHNL, + ieee80211_chan2ieee(ic, ic->ic_curchan)); + WI_UNLOCK(sc); +} + +static void +wi_scan_start(struct ieee80211com *ic) +{ + struct ifnet *ifp = ic->ic_ifp; + struct wi_softc *sc = ifp->if_softc; + struct ieee80211_scan_state *ss = ic->ic_scan; + + DPRINTF(("%s\n", __func__)); + + WI_LOCK(sc); + /* + * Switch device to monitor mode. + */ + wi_write_val(sc, WI_RID_PORTTYPE, sc->sc_monitor_port); + if (sc->sc_firmware_type == WI_INTERSIL) { + wi_cmd(sc, WI_CMD_DISABLE | WI_PORT0, 0, 0, 0); + wi_cmd(sc, WI_CMD_ENABLE | WI_PORT0, 0, 0, 0); + } + /* force full dwell time to compensate for firmware overhead */ + ss->ss_mindwell = ss->ss_maxdwell = msecs_to_ticks(400); + WI_UNLOCK(sc); + +} + +static void +wi_scan_end(struct ieee80211com *ic) +{ + struct ifnet *ifp = ic->ic_ifp; + struct wi_softc *sc = ifp->if_softc; + + DPRINTF(("%s: restore port type %d\n", __func__, sc->sc_porttype)); + + WI_LOCK(sc); + wi_write_val(sc, WI_RID_PORTTYPE, sc->sc_porttype); + if (sc->sc_firmware_type == WI_INTERSIL) { + wi_cmd(sc, WI_CMD_DISABLE | WI_PORT0, 0, 0, 0); + wi_cmd(sc, WI_CMD_ENABLE | WI_PORT0, 0, 0, 0); + } + WI_UNLOCK(sc); +} + +static void +wi_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m, + int subtype, int rssi, int nf) +{ + struct ieee80211vap *vap = ni->ni_vap; + + switch (subtype) { + case IEEE80211_FC0_SUBTYPE_AUTH: + case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: + case IEEE80211_FC0_SUBTYPE_REASSOC_RESP: + /* NB: filter frames that trigger state changes */ + return; + } + WI_VAP(vap)->wv_recv_mgmt(ni, m, subtype, rssi, nf); +} + +static int +wi_newstate_sta(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) +{ + struct ieee80211com *ic = vap->iv_ic; + struct ifnet *ifp = ic->ic_ifp; + struct ieee80211_node *bss; + struct wi_softc *sc = ifp->if_softc; + + DPRINTF(("%s: %s -> %s\n", __func__, + ieee80211_state_name[vap->iv_state], + ieee80211_state_name[nstate])); + + if (nstate == IEEE80211_S_AUTH) { + WI_LOCK(sc); + wi_setup_locked(sc, WI_PORTTYPE_BSS, 3, vap->iv_myaddr); + + if (vap->iv_flags & IEEE80211_F_PMGTON) { + wi_write_val(sc, WI_RID_MAX_SLEEP, ic->ic_lintval); + wi_write_val(sc, WI_RID_PM_ENABLED, 1); + } + wi_write_val(sc, WI_RID_RTS_THRESH, vap->iv_rtsthreshold); + if (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR) + wi_write_val(sc, WI_RID_FRAG_THRESH, + vap->iv_fragthreshold); + wi_write_txrate(sc, vap); + + bss = vap->iv_bss; + wi_write_ssid(sc, WI_RID_DESIRED_SSID, bss->ni_essid, bss->ni_esslen); + wi_write_val(sc, WI_RID_OWN_CHNL, + ieee80211_chan2ieee(ic, bss->ni_chan)); + + /* Configure WEP. */ + if (ic->ic_cryptocaps & IEEE80211_CRYPTO_WEP) + wi_write_wep(sc, vap); + else + sc->sc_encryption = 0; + + if ((sc->sc_flags & WI_FLAGS_HAS_WPASUPPORT) && + (vap->iv_flags & IEEE80211_F_WPA)) { + wi_write_val(sc, WI_RID_WPA_HANDLING, 1); + if (vap->iv_appie_wpa != NULL) + wi_write_appie(sc, WI_RID_WPA_DATA, + vap->iv_appie_wpa); + } + + wi_enable(sc); /* enable port */ + + /* Lucent firmware does not support the JOIN RID. */ + if (sc->sc_firmware_type == WI_INTERSIL) { + struct wi_joinreq join; + + memset(&join, 0, sizeof(join)); + IEEE80211_ADDR_COPY(&join.wi_bssid, bss->ni_bssid); + join.wi_chan = htole16( + ieee80211_chan2ieee(ic, bss->ni_chan)); + wi_write_rid(sc, WI_RID_JOIN_REQ, &join, sizeof(join)); + } + WI_UNLOCK(sc); + + /* + * NB: don't go through 802.11 layer, it'll send auth frame; + * instead we drive the state machine from the link status + * notification we get on association. + */ + vap->iv_state = nstate; + return (0); + } + return WI_VAP(vap)->wv_newstate(vap, nstate, arg); +} + +static int +wi_newstate_hostap(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) +{ + struct ieee80211com *ic = vap->iv_ic; + struct ifnet *ifp = ic->ic_ifp; + struct ieee80211_node *bss; + struct wi_softc *sc = ifp->if_softc; + int error; + + DPRINTF(("%s: %s -> %s\n", __func__, + ieee80211_state_name[vap->iv_state], + ieee80211_state_name[nstate])); + + error = WI_VAP(vap)->wv_newstate(vap, nstate, arg); + if (error == 0 && nstate == IEEE80211_S_RUN) { + WI_LOCK(sc); + wi_setup_locked(sc, WI_PORTTYPE_HOSTAP, 0, vap->iv_myaddr); + + bss = vap->iv_bss; + wi_write_ssid(sc, WI_RID_OWN_SSID, + bss->ni_essid, bss->ni_esslen); + wi_write_val(sc, WI_RID_OWN_CHNL, + ieee80211_chan2ieee(ic, bss->ni_chan)); + wi_write_val(sc, WI_RID_BASIC_RATE, 0x3); + wi_write_val(sc, WI_RID_SUPPORT_RATE, 0xf); + wi_write_txrate(sc, vap); + + wi_write_val(sc, WI_RID_OWN_BEACON_INT, bss->ni_intval); + wi_write_val(sc, WI_RID_DTIM_PERIOD, vap->iv_dtim_period); + + wi_write_val(sc, WI_RID_RTS_THRESH, vap->iv_rtsthreshold); + if (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR) + wi_write_val(sc, WI_RID_FRAG_THRESH, + vap->iv_fragthreshold); + + if ((sc->sc_flags & WI_FLAGS_HAS_ENHSECURITY) && + (vap->iv_flags & IEEE80211_F_HIDESSID)) { + /* + * bit 0 means hide SSID in beacons, + * bit 1 means don't respond to bcast probe req + */ + wi_write_val(sc, WI_RID_ENH_SECURITY, 0x3); + } + + if ((sc->sc_flags & WI_FLAGS_HAS_WPASUPPORT) && + (vap->iv_flags & IEEE80211_F_WPA) && + vap->iv_appie_wpa != NULL) + wi_write_appie(sc, WI_RID_WPA_DATA, vap->iv_appie_wpa); + + wi_write_val(sc, WI_RID_PROMISC, 0); + + /* Configure WEP. */ + if (ic->ic_cryptocaps & IEEE80211_CRYPTO_WEP) + wi_write_wep(sc, vap); + else + sc->sc_encryption = 0; + + wi_enable(sc); /* enable port */ + WI_UNLOCK(sc); + } + return error; +} + +static void +wi_start_locked(struct ifnet *ifp) +{ + struct wi_softc *sc = ifp->if_softc; + struct ieee80211_node *ni; + struct ieee80211_frame *wh; + struct mbuf *m0; + struct ieee80211_key *k; + struct wi_frame frmhdr; + const struct llc *llc; + int cur; + + WI_LOCK_ASSERT(sc); + + if (sc->wi_gone) + return; + + memset(&frmhdr, 0, sizeof(frmhdr)); + cur = sc->sc_txnext; + for (;;) { + IFQ_DRV_DEQUEUE(&ifp->if_snd, m0); + if (m0 == NULL) + break; + if (sc->sc_txd[cur].d_len != 0) { + IFQ_DRV_PREPEND(&ifp->if_snd, m0); + ifp->if_drv_flags |= IFF_DRV_OACTIVE; + break; + } + ni = (struct ieee80211_node *) m0->m_pkthdr.rcvif; + + /* reconstruct 802.3 header */ + wh = mtod(m0, struct ieee80211_frame *); + switch (wh->i_fc[1]) { + case IEEE80211_FC1_DIR_TODS: + IEEE80211_ADDR_COPY(frmhdr.wi_ehdr.ether_shost, + wh->i_addr2); + IEEE80211_ADDR_COPY(frmhdr.wi_ehdr.ether_dhost, + wh->i_addr3); + break; + case IEEE80211_FC1_DIR_NODS: + IEEE80211_ADDR_COPY(frmhdr.wi_ehdr.ether_shost, + wh->i_addr2); + IEEE80211_ADDR_COPY(frmhdr.wi_ehdr.ether_dhost, + wh->i_addr1); + break; + case IEEE80211_FC1_DIR_FROMDS: + IEEE80211_ADDR_COPY(frmhdr.wi_ehdr.ether_shost, + wh->i_addr3); + IEEE80211_ADDR_COPY(frmhdr.wi_ehdr.ether_dhost, + wh->i_addr1); + break; + } + llc = (const struct llc *)( + mtod(m0, const uint8_t *) + ieee80211_hdrsize(wh)); + frmhdr.wi_ehdr.ether_type = llc->llc_snap.ether_type; + frmhdr.wi_tx_ctl = htole16(WI_ENC_TX_802_11|WI_TXCNTL_TX_EX); + if (wh->i_fc[1] & IEEE80211_FC1_WEP) { + k = ieee80211_crypto_encap(ni, m0); + if (k == NULL) { + ieee80211_free_node(ni); + m_freem(m0); + continue; + } + frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_NOCRYPT); + } + + if (ieee80211_radiotap_active_vap(ni->ni_vap)) { + sc->sc_tx_th.wt_rate = ni->ni_txrate; + ieee80211_radiotap_tx(ni->ni_vap, m0); + } + + m_copydata(m0, 0, sizeof(struct ieee80211_frame), + (caddr_t)&frmhdr.wi_whdr); + m_adj(m0, sizeof(struct ieee80211_frame)); + frmhdr.wi_dat_len = htole16(m0->m_pkthdr.len); + ieee80211_free_node(ni); + if (wi_start_tx(ifp, &frmhdr, m0)) + continue; + + sc->sc_txnext = cur = (cur + 1) % sc->sc_ntxbuf; + ifp->if_opackets++; + } +} + +static void +wi_start(struct ifnet *ifp) +{ + struct wi_softc *sc = ifp->if_softc; + + WI_LOCK(sc); + wi_start_locked(ifp); + WI_UNLOCK(sc); +} + +static int +wi_start_tx(struct ifnet *ifp, struct wi_frame *frmhdr, struct mbuf *m0) +{ + struct wi_softc *sc = ifp->if_softc; + int cur = sc->sc_txnext; + int fid, off, error; + + fid = sc->sc_txd[cur].d_fid; + off = sizeof(*frmhdr); + error = wi_write_bap(sc, fid, 0, frmhdr, sizeof(*frmhdr)) != 0 + || wi_mwrite_bap(sc, fid, off, m0, m0->m_pkthdr.len) != 0; + m_freem(m0); + if (error) { + ifp->if_oerrors++; + return -1; + } + sc->sc_txd[cur].d_len = off; + if (sc->sc_txcur == cur) { + if (wi_cmd(sc, WI_CMD_TX | WI_RECLAIM, fid, 0, 0)) { + if_printf(ifp, "xmit failed\n"); + sc->sc_txd[cur].d_len = 0; + return -1; + } + sc->sc_tx_timer = 5; + } + return 0; +} + +static int +wi_raw_xmit(struct ieee80211_node *ni, struct mbuf *m0, + const struct ieee80211_bpf_params *params) +{ + struct ieee80211com *ic = ni->ni_ic; + struct ifnet *ifp = ic->ic_ifp; + struct ieee80211vap *vap = ni->ni_vap; + struct wi_softc *sc = ifp->if_softc; + struct ieee80211_key *k; + struct ieee80211_frame *wh; + struct wi_frame frmhdr; + int cur; + int rc = 0; + + WI_LOCK(sc); + + if (sc->wi_gone) { + rc = ENETDOWN; + goto out; + } + memset(&frmhdr, 0, sizeof(frmhdr)); + cur = sc->sc_txnext; + if (sc->sc_txd[cur].d_len != 0) { + ifp->if_drv_flags |= IFF_DRV_OACTIVE; + rc = ENOBUFS; + goto out; + } + m0->m_pkthdr.rcvif = NULL; + + m_copydata(m0, 4, ETHER_ADDR_LEN * 2, + (caddr_t)&frmhdr.wi_ehdr); + frmhdr.wi_ehdr.ether_type = 0; + wh = mtod(m0, struct ieee80211_frame *); + + frmhdr.wi_tx_ctl = htole16(WI_ENC_TX_802_11|WI_TXCNTL_TX_EX); + if (params && (params->ibp_flags & IEEE80211_BPF_NOACK)) + frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_ALTRTRY); + if ((wh->i_fc[1] & IEEE80211_FC1_WEP) && + (!params || (params && (params->ibp_flags & IEEE80211_BPF_CRYPTO)))) { + k = ieee80211_crypto_encap(ni, m0); + if (k == NULL) { + rc = ENOMEM; + goto out; + } + frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_NOCRYPT); + } + if (ieee80211_radiotap_active_vap(vap)) { + sc->sc_tx_th.wt_rate = ni->ni_txrate; + ieee80211_radiotap_tx(vap, m0); + } + m_copydata(m0, 0, sizeof(struct ieee80211_frame), + (caddr_t)&frmhdr.wi_whdr); + m_adj(m0, sizeof(struct ieee80211_frame)); + frmhdr.wi_dat_len = htole16(m0->m_pkthdr.len); + if (wi_start_tx(ifp, &frmhdr, m0) < 0) { + m0 = NULL; + rc = EIO; + goto out; + } + m0 = NULL; + + sc->sc_txnext = cur = (cur + 1) % sc->sc_ntxbuf; +out: + WI_UNLOCK(sc); + + if (m0 != NULL) + m_freem(m0); + ieee80211_free_node(ni); + return rc; +} + +static int +wi_reset(struct wi_softc *sc) +{ +#define WI_INIT_TRIES 3 + int i, error = 0; + + for (i = 0; i < WI_INIT_TRIES; i++) { + error = wi_cmd(sc, WI_CMD_INI, 0, 0, 0); + if (error == 0) + break; + DELAY(WI_DELAY * 1000); + } + sc->sc_reset = 1; + if (i == WI_INIT_TRIES) { + if_printf(sc->sc_ifp, "reset failed\n"); + return error; + } + + CSR_WRITE_2(sc, WI_INT_EN, 0); + CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF); + + /* Calibrate timer. */ + wi_write_val(sc, WI_RID_TICK_TIME, 8); + + return 0; +#undef WI_INIT_TRIES +} + +static void +wi_watchdog(void *arg) +{ + struct wi_softc *sc = arg; + struct ifnet *ifp = sc->sc_ifp; + + WI_LOCK_ASSERT(sc); + + if (!sc->sc_enabled) + return; + + if (sc->sc_tx_timer && --sc->sc_tx_timer == 0) { + if_printf(ifp, "device timeout\n"); + ifp->if_oerrors++; + wi_init_locked(ifp->if_softc); + return; + } + callout_reset(&sc->sc_watchdog, hz, wi_watchdog, sc); +} + +static int +wi_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) +{ + struct wi_softc *sc = ifp->if_softc; + struct ieee80211com *ic = ifp->if_l2com; + struct ifreq *ifr = (struct ifreq *) data; + int error = 0, startall = 0; + + switch (cmd) { + case SIOCSIFFLAGS: + WI_LOCK(sc); + /* + * Can't do promisc and hostap at the same time. If all that's + * changing is the promisc flag, try to short-circuit a call to + * wi_init() by just setting PROMISC in the hardware. + */ + if (ifp->if_flags & IFF_UP) { + if (ic->ic_opmode != IEEE80211_M_HOSTAP && + ifp->if_drv_flags & IFF_DRV_RUNNING) { + if ((ifp->if_flags ^ sc->sc_if_flags) & IFF_PROMISC) { + wi_write_val(sc, WI_RID_PROMISC, + (ifp->if_flags & IFF_PROMISC) != 0); + } else { + wi_init_locked(sc); + startall = 1; + } + } else { + wi_init_locked(sc); + startall = 1; + } + } else { + if (ifp->if_drv_flags & IFF_DRV_RUNNING) + wi_stop_locked(sc, 1); + sc->wi_gone = 0; + } + sc->sc_if_flags = ifp->if_flags; + WI_UNLOCK(sc); + if (startall) + ieee80211_start_all(ic); + break; + case SIOCGIFMEDIA: + error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd); + break; + case SIOCGIFADDR: + error = ether_ioctl(ifp, cmd, data); + break; + default: + error = EINVAL; + break; + } + return error; +} + +static void +wi_media_status(struct ifnet *ifp, struct ifmediareq *imr) +{ + struct ieee80211vap *vap = ifp->if_softc; + struct ieee80211com *ic = vap->iv_ic; + struct wi_softc *sc = ic->ic_ifp->if_softc; + u_int16_t val; + int rate, len; + + len = sizeof(val); + if (sc->sc_enabled && + wi_read_rid(sc, WI_RID_CUR_TX_RATE, &val, &len) == 0 && + len == sizeof(val)) { + /* convert to 802.11 rate */ + val = le16toh(val); + rate = val * 2; + if (sc->sc_firmware_type == WI_LUCENT) { + if (rate == 10) + rate = 11; /* 5.5Mbps */ + } else { + if (rate == 4*2) + rate = 11; /* 5.5Mbps */ + else if (rate == 8*2) + rate = 22; /* 11Mbps */ + } + vap->iv_bss->ni_txrate = rate; + } + ieee80211_media_status(ifp, imr); +} + +static void +wi_sync_bssid(struct wi_softc *sc, u_int8_t new_bssid[IEEE80211_ADDR_LEN]) +{ + struct ifnet *ifp = sc->sc_ifp; + struct ieee80211com *ic = ifp->if_l2com; + struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); + struct ieee80211_node *ni = vap->iv_bss; + + if (IEEE80211_ADDR_EQ(new_bssid, ni->ni_bssid)) + return; + + DPRINTF(("wi_sync_bssid: bssid %s -> ", ether_sprintf(ni->ni_bssid))); + DPRINTF(("%s ?\n", ether_sprintf(new_bssid))); + + /* In promiscuous mode, the BSSID field is not a reliable + * indicator of the firmware's BSSID. Damp spurious + * change-of-BSSID indications. + */ + if ((ifp->if_flags & IFF_PROMISC) != 0 && + !ppsratecheck(&sc->sc_last_syn, &sc->sc_false_syns, + WI_MAX_FALSE_SYNS)) + return; + + sc->sc_false_syns = MAX(0, sc->sc_false_syns - 1); +#if 0 + /* + * XXX hack; we should create a new node with the new bssid + * and replace the existing ic_bss with it but since we don't + * process management frames to collect state we cheat by + * reusing the existing node as we know wi_newstate will be + * called and it will overwrite the node state. + */ + ieee80211_sta_join(ic, ieee80211_ref_node(ni)); +#endif +} + +static __noinline void +wi_rx_intr(struct wi_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct ieee80211com *ic = ifp->if_l2com; + struct wi_frame frmhdr; + struct mbuf *m; + struct ieee80211_frame *wh; + struct ieee80211_node *ni; + int fid, len, off; + u_int8_t dir; + u_int16_t status; + int8_t rssi, nf; + + fid = CSR_READ_2(sc, WI_RX_FID); + + /* First read in the frame header */ + if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr))) { + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); + ifp->if_ierrors++; + DPRINTF(("wi_rx_intr: read fid %x failed\n", fid)); + return; + } + + /* + * Drop undecryptable or packets with receive errors here + */ + status = le16toh(frmhdr.wi_status); + if (status & WI_STAT_ERRSTAT) { + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); + ifp->if_ierrors++; + DPRINTF(("wi_rx_intr: fid %x error status %x\n", fid, status)); + return; + } + + len = le16toh(frmhdr.wi_dat_len); + off = ALIGN(sizeof(struct ieee80211_frame)); + + /* + * Sometimes the PRISM2.x returns bogusly large frames. Except + * in monitor mode, just throw them away. + */ + if (off + len > MCLBYTES) { + if (ic->ic_opmode != IEEE80211_M_MONITOR) { + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); + ifp->if_ierrors++; + DPRINTF(("wi_rx_intr: oversized packet\n")); + return; + } else + len = 0; + } + + if (off + len > MHLEN) + m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); + else + m = m_gethdr(M_DONTWAIT, MT_DATA); + if (m == NULL) { + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); + ifp->if_ierrors++; + DPRINTF(("wi_rx_intr: MGET failed\n")); + return; + } + m->m_data += off - sizeof(struct ieee80211_frame); + memcpy(m->m_data, &frmhdr.wi_whdr, sizeof(struct ieee80211_frame)); + wi_read_bap(sc, fid, sizeof(frmhdr), + m->m_data + sizeof(struct ieee80211_frame), len); + m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame) + len; + m->m_pkthdr.rcvif = ifp; + + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); + + rssi = frmhdr.wi_rx_signal; + nf = frmhdr.wi_rx_silence; + if (ieee80211_radiotap_active(ic)) { + struct wi_rx_radiotap_header *tap = &sc->sc_rx_th; + uint32_t rstamp; + + rstamp = (le16toh(frmhdr.wi_rx_tstamp0) << 16) | + le16toh(frmhdr.wi_rx_tstamp1); + tap->wr_tsf = htole64((uint64_t)rstamp); + /* XXX replace divide by table */ + tap->wr_rate = frmhdr.wi_rx_rate / 5; + tap->wr_flags = 0; + if (frmhdr.wi_status & WI_STAT_PCF) + tap->wr_flags |= IEEE80211_RADIOTAP_F_CFP; + if (m->m_flags & M_WEP) + tap->wr_flags |= IEEE80211_RADIOTAP_F_WEP; + tap->wr_antsignal = rssi; + tap->wr_antnoise = nf; + } + + /* synchronize driver's BSSID with firmware's BSSID */ + wh = mtod(m, struct ieee80211_frame *); + dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK; + if (ic->ic_opmode == IEEE80211_M_IBSS && dir == IEEE80211_FC1_DIR_NODS) + wi_sync_bssid(sc, wh->i_addr3); + + WI_UNLOCK(sc); + + ni = ieee80211_find_rxnode(ic, mtod(m, struct ieee80211_frame_min *)); + if (ni != NULL) { + (void) ieee80211_input(ni, m, rssi, nf); + ieee80211_free_node(ni); + } else + (void) ieee80211_input_all(ic, m, rssi, nf); + + WI_LOCK(sc); +} + +static __noinline void +wi_tx_ex_intr(struct wi_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct wi_frame frmhdr; + int fid; + + fid = CSR_READ_2(sc, WI_TX_CMP_FID); + /* Read in the frame header */ + if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) == 0) { + u_int16_t status = le16toh(frmhdr.wi_status); + /* + * Spontaneous station disconnects appear as xmit + * errors. Don't announce them and/or count them + * as an output error. + */ + if ((status & WI_TXSTAT_DISCONNECT) == 0) { + if (ppsratecheck(&lasttxerror, &curtxeps, wi_txerate)) { + if_printf(ifp, "tx failed"); + if (status & WI_TXSTAT_RET_ERR) + printf(", retry limit exceeded"); + if (status & WI_TXSTAT_AGED_ERR) + printf(", max transmit lifetime exceeded"); + if (status & WI_TXSTAT_DISCONNECT) + printf(", port disconnected"); + if (status & WI_TXSTAT_FORM_ERR) + printf(", invalid format (data len %u src %6D)", + le16toh(frmhdr.wi_dat_len), + frmhdr.wi_ehdr.ether_shost, ":"); + if (status & ~0xf) + printf(", status=0x%x", status); + printf("\n"); + } + ifp->if_oerrors++; + } else { + DPRINTF(("port disconnected\n")); + ifp->if_collisions++; /* XXX */ + } + } else + DPRINTF(("wi_tx_ex_intr: read fid %x failed\n", fid)); + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_TX_EXC); +} + +static __noinline void +wi_tx_intr(struct wi_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + int fid, cur; + + if (sc->wi_gone) + return; + + fid = CSR_READ_2(sc, WI_ALLOC_FID); + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC); + + cur = sc->sc_txcur; + if (sc->sc_txd[cur].d_fid != fid) { + if_printf(ifp, "bad alloc %x != %x, cur %d nxt %d\n", + fid, sc->sc_txd[cur].d_fid, cur, sc->sc_txnext); + return; + } + sc->sc_tx_timer = 0; + sc->sc_txd[cur].d_len = 0; + sc->sc_txcur = cur = (cur + 1) % sc->sc_ntxbuf; + if (sc->sc_txd[cur].d_len == 0) + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + else { + if (wi_cmd(sc, WI_CMD_TX | WI_RECLAIM, sc->sc_txd[cur].d_fid, + 0, 0)) { + if_printf(ifp, "xmit failed\n"); + sc->sc_txd[cur].d_len = 0; + } else { + sc->sc_tx_timer = 5; + } + } +} + +static __noinline void +wi_info_intr(struct wi_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct ieee80211com *ic = ifp->if_l2com; + struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); + int i, fid, len, off; + u_int16_t ltbuf[2]; + u_int16_t stat; + u_int32_t *ptr; + + fid = CSR_READ_2(sc, WI_INFO_FID); + wi_read_bap(sc, fid, 0, ltbuf, sizeof(ltbuf)); + + switch (le16toh(ltbuf[1])) { + case WI_INFO_LINK_STAT: + wi_read_bap(sc, fid, sizeof(ltbuf), &stat, sizeof(stat)); + DPRINTF(("wi_info_intr: LINK_STAT 0x%x\n", le16toh(stat))); + switch (le16toh(stat)) { + case WI_INFO_LINK_STAT_CONNECTED: + if (vap->iv_state == IEEE80211_S_RUN && + vap->iv_opmode != IEEE80211_M_IBSS) + break; + /* fall thru... */ + case WI_INFO_LINK_STAT_AP_CHG: + IEEE80211_LOCK(ic); + vap->iv_bss->ni_associd = 1 | 0xc000; /* NB: anything will do */ + ieee80211_new_state(vap, IEEE80211_S_RUN, 0); + IEEE80211_UNLOCK(ic); + break; + case WI_INFO_LINK_STAT_AP_INR: + break; + case WI_INFO_LINK_STAT_DISCONNECTED: + /* we dropped off the net; e.g. due to deauth/disassoc */ + IEEE80211_LOCK(ic); + vap->iv_bss->ni_associd = 0; + vap->iv_stats.is_rx_deauth++; + ieee80211_new_state(vap, IEEE80211_S_SCAN, 0); + IEEE80211_UNLOCK(ic); + break; + case WI_INFO_LINK_STAT_AP_OOR: + /* XXX does this need to be per-vap? */ + ieee80211_beacon_miss(ic); + break; + case WI_INFO_LINK_STAT_ASSOC_FAILED: + if (vap->iv_opmode == IEEE80211_M_STA) + ieee80211_new_state(vap, IEEE80211_S_SCAN, + IEEE80211_SCAN_FAIL_TIMEOUT); + break; + } + break; + case WI_INFO_COUNTERS: + /* some card versions have a larger stats structure */ + len = min(le16toh(ltbuf[0]) - 1, sizeof(sc->sc_stats) / 4); + ptr = (u_int32_t *)&sc->sc_stats; + off = sizeof(ltbuf); + for (i = 0; i < len; i++, off += 2, ptr++) { + wi_read_bap(sc, fid, off, &stat, sizeof(stat)); +#ifdef WI_HERMES_STATS_WAR + if (stat & 0xf000) + stat = ~stat; +#endif + *ptr += stat; + } + ifp->if_collisions = sc->sc_stats.wi_tx_single_retries + + sc->sc_stats.wi_tx_multi_retries + + sc->sc_stats.wi_tx_retry_limit; + break; + default: + DPRINTF(("wi_info_intr: got fid %x type %x len %d\n", fid, + le16toh(ltbuf[1]), le16toh(ltbuf[0]))); + break; + } + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_INFO); +} + +static int +wi_write_multi(struct wi_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + int n; + struct ifmultiaddr *ifma; + struct wi_mcast mlist; + + if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { +allmulti: + memset(&mlist, 0, sizeof(mlist)); + return wi_write_rid(sc, WI_RID_MCAST_LIST, &mlist, + sizeof(mlist)); + } + + n = 0; + if_maddr_rlock(ifp); + TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { + if (ifma->ifma_addr->sa_family != AF_LINK) + continue; + if (n >= 16) + goto allmulti; + IEEE80211_ADDR_COPY(&mlist.wi_mcast[n], + (LLADDR((struct sockaddr_dl *)ifma->ifma_addr))); + n++; + } + if_maddr_runlock(ifp); + return wi_write_rid(sc, WI_RID_MCAST_LIST, &mlist, + IEEE80211_ADDR_LEN * n); +} + +static void +wi_update_mcast(struct ifnet *ifp) +{ + wi_write_multi(ifp->if_softc); +} + +static void +wi_update_promisc(struct ifnet *ifp) +{ + struct wi_softc *sc = ifp->if_softc; + struct ieee80211com *ic = ifp->if_l2com; + + WI_LOCK(sc); + /* XXX handle WEP special case handling? */ + wi_write_val(sc, WI_RID_PROMISC, + (ic->ic_opmode == IEEE80211_M_MONITOR || + (ifp->if_flags & IFF_PROMISC))); + WI_UNLOCK(sc); +} + +static void +wi_read_nicid(struct wi_softc *sc) +{ + struct wi_card_ident *id; + char *p; + int len; + u_int16_t ver[4]; + + /* getting chip identity */ + memset(ver, 0, sizeof(ver)); + len = sizeof(ver); + wi_read_rid(sc, WI_RID_CARD_ID, ver, &len); + + sc->sc_firmware_type = WI_NOTYPE; + sc->sc_nic_id = le16toh(ver[0]); + for (id = wi_card_ident; id->card_name != NULL; id++) { + if (sc->sc_nic_id == id->card_id) { + sc->sc_nic_name = id->card_name; + sc->sc_firmware_type = id->firm_type; + break; + } + } + if (sc->sc_firmware_type == WI_NOTYPE) { + if (sc->sc_nic_id & 0x8000) { + sc->sc_firmware_type = WI_INTERSIL; + sc->sc_nic_name = "Unknown Prism chip"; + } else { + sc->sc_firmware_type = WI_LUCENT; + sc->sc_nic_name = "Unknown Lucent chip"; + } + } + if (bootverbose) + device_printf(sc->sc_dev, "using %s\n", sc->sc_nic_name); + + /* get primary firmware version (Only Prism chips) */ + if (sc->sc_firmware_type != WI_LUCENT) { + memset(ver, 0, sizeof(ver)); + len = sizeof(ver); + wi_read_rid(sc, WI_RID_PRI_IDENTITY, ver, &len); + sc->sc_pri_firmware_ver = le16toh(ver[2]) * 10000 + + le16toh(ver[3]) * 100 + le16toh(ver[1]); + } + + /* get station firmware version */ + memset(ver, 0, sizeof(ver)); + len = sizeof(ver); + wi_read_rid(sc, WI_RID_STA_IDENTITY, ver, &len); + sc->sc_sta_firmware_ver = le16toh(ver[2]) * 10000 + + le16toh(ver[3]) * 100 + le16toh(ver[1]); + if (sc->sc_firmware_type == WI_INTERSIL && + (sc->sc_sta_firmware_ver == 10102 || + sc->sc_sta_firmware_ver == 20102)) { + char ident[12]; + memset(ident, 0, sizeof(ident)); + len = sizeof(ident); + /* value should be the format like "V2.00-11" */ + if (wi_read_rid(sc, WI_RID_SYMBOL_IDENTITY, ident, &len) == 0 && + *(p = (char *)ident) >= 'A' && + p[2] == '.' && p[5] == '-' && p[8] == '\0') { + sc->sc_firmware_type = WI_SYMBOL; + sc->sc_sta_firmware_ver = (p[1] - '0') * 10000 + + (p[3] - '0') * 1000 + (p[4] - '0') * 100 + + (p[6] - '0') * 10 + (p[7] - '0'); + } + } + if (bootverbose) { + device_printf(sc->sc_dev, "%s Firmware: ", + wi_firmware_names[sc->sc_firmware_type]); + if (sc->sc_firmware_type != WI_LUCENT) /* XXX */ + printf("Primary (%u.%u.%u), ", + sc->sc_pri_firmware_ver / 10000, + (sc->sc_pri_firmware_ver % 10000) / 100, + sc->sc_pri_firmware_ver % 100); + printf("Station (%u.%u.%u)\n", + sc->sc_sta_firmware_ver / 10000, + (sc->sc_sta_firmware_ver % 10000) / 100, + sc->sc_sta_firmware_ver % 100); + } +} + +static int +wi_write_ssid(struct wi_softc *sc, int rid, u_int8_t *buf, int buflen) +{ + struct wi_ssid ssid; + + if (buflen > IEEE80211_NWID_LEN) + return ENOBUFS; + memset(&ssid, 0, sizeof(ssid)); + ssid.wi_len = htole16(buflen); + memcpy(ssid.wi_ssid, buf, buflen); + return wi_write_rid(sc, rid, &ssid, sizeof(ssid)); +} + +static int +wi_write_txrate(struct wi_softc *sc, struct ieee80211vap *vap) +{ + static const uint16_t lucent_rates[12] = { + [ 0] = 3, /* auto */ + [ 1] = 1, /* 1Mb/s */ + [ 2] = 2, /* 2Mb/s */ + [ 5] = 4, /* 5.5Mb/s */ + [11] = 5 /* 11Mb/s */ + }; + static const uint16_t intersil_rates[12] = { + [ 0] = 0xf, /* auto */ + [ 1] = 0, /* 1Mb/s */ + [ 2] = 1, /* 2Mb/s */ + [ 5] = 2, /* 5.5Mb/s */ + [11] = 3, /* 11Mb/s */ + }; + const uint16_t *rates = sc->sc_firmware_type == WI_LUCENT ? + lucent_rates : intersil_rates; + struct ieee80211com *ic = vap->iv_ic; + const struct ieee80211_txparam *tp; + + tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_bsschan)]; + return wi_write_val(sc, WI_RID_TX_RATE, + (tp->ucastrate == IEEE80211_FIXED_RATE_NONE ? + rates[0] : rates[tp->ucastrate / 2])); +} + +static int +wi_write_wep(struct wi_softc *sc, struct ieee80211vap *vap) +{ + int error = 0; + int i, keylen; + u_int16_t val; + struct wi_key wkey[IEEE80211_WEP_NKID]; + + switch (sc->sc_firmware_type) { + case WI_LUCENT: + val = (vap->iv_flags & IEEE80211_F_PRIVACY) ? 1 : 0; + error = wi_write_val(sc, WI_RID_ENCRYPTION, val); + if (error) + break; + if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) + break; + error = wi_write_val(sc, WI_RID_TX_CRYPT_KEY, vap->iv_def_txkey); + if (error) + break; + memset(wkey, 0, sizeof(wkey)); + for (i = 0; i < IEEE80211_WEP_NKID; i++) { + keylen = vap->iv_nw_keys[i].wk_keylen; + wkey[i].wi_keylen = htole16(keylen); + memcpy(wkey[i].wi_keydat, vap->iv_nw_keys[i].wk_key, + keylen); + } + error = wi_write_rid(sc, WI_RID_DEFLT_CRYPT_KEYS, + wkey, sizeof(wkey)); + sc->sc_encryption = 0; + break; + + case WI_INTERSIL: + val = HOST_ENCRYPT | HOST_DECRYPT; + if (vap->iv_flags & IEEE80211_F_PRIVACY) { + /* + * ONLY HWB3163 EVAL-CARD Firmware version + * less than 0.8 variant2 + * + * If promiscuous mode disable, Prism2 chip + * does not work with WEP . + * It is under investigation for details. + * (ichiro@netbsd.org) + */ + if (sc->sc_sta_firmware_ver < 802 ) { + /* firm ver < 0.8 variant 2 */ + wi_write_val(sc, WI_RID_PROMISC, 1); + } + wi_write_val(sc, WI_RID_CNFAUTHMODE, + vap->iv_bss->ni_authmode); + val |= PRIVACY_INVOKED; + } else { + wi_write_val(sc, WI_RID_CNFAUTHMODE, IEEE80211_AUTH_OPEN); + } + error = wi_write_val(sc, WI_RID_P2_ENCRYPTION, val); + if (error) + break; + sc->sc_encryption = val; + if ((val & PRIVACY_INVOKED) == 0) + break; + error = wi_write_val(sc, WI_RID_P2_TX_CRYPT_KEY, vap->iv_def_txkey); + break; + } + return error; +} + +static int +wi_cmd(struct wi_softc *sc, int cmd, int val0, int val1, int val2) +{ + int i, s = 0; + + if (sc->wi_gone) + return (ENODEV); + + /* wait for the busy bit to clear */ + for (i = sc->wi_cmd_count; i > 0; i--) { /* 500ms */ + if (!(CSR_READ_2(sc, WI_COMMAND) & WI_CMD_BUSY)) + break; + DELAY(1*1000); /* 1ms */ + } + if (i == 0) { + device_printf(sc->sc_dev, "%s: busy bit won't clear, cmd 0x%x\n", + __func__, cmd); + sc->wi_gone = 1; + return(ETIMEDOUT); + } + + CSR_WRITE_2(sc, WI_PARAM0, val0); + CSR_WRITE_2(sc, WI_PARAM1, val1); + CSR_WRITE_2(sc, WI_PARAM2, val2); + CSR_WRITE_2(sc, WI_COMMAND, cmd); + + if (cmd == WI_CMD_INI) { + /* XXX: should sleep here. */ + DELAY(100*1000); /* 100ms delay for init */ + } + for (i = 0; i < WI_TIMEOUT; i++) { + /* + * Wait for 'command complete' bit to be + * set in the event status register. + */ + s = CSR_READ_2(sc, WI_EVENT_STAT); + if (s & WI_EV_CMD) { + /* Ack the event and read result code. */ + s = CSR_READ_2(sc, WI_STATUS); + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD); + if (s & WI_STAT_CMD_RESULT) { + return(EIO); + } + break; + } + DELAY(WI_DELAY); + } + + if (i == WI_TIMEOUT) { + device_printf(sc->sc_dev, "%s: timeout on cmd 0x%04x; " + "event status 0x%04x\n", __func__, cmd, s); + if (s == 0xffff) + sc->wi_gone = 1; + return(ETIMEDOUT); + } + return (0); +} + +static int +wi_seek_bap(struct wi_softc *sc, int id, int off) +{ + int i, status; + + CSR_WRITE_2(sc, WI_SEL0, id); + CSR_WRITE_2(sc, WI_OFF0, off); + + for (i = 0; ; i++) { + status = CSR_READ_2(sc, WI_OFF0); + if ((status & WI_OFF_BUSY) == 0) + break; + if (i == WI_TIMEOUT) { + device_printf(sc->sc_dev, "%s: timeout, id %x off %x\n", + __func__, id, off); + sc->sc_bap_off = WI_OFF_ERR; /* invalidate */ + if (status == 0xffff) + sc->wi_gone = 1; + return ETIMEDOUT; + } + DELAY(1); + } + if (status & WI_OFF_ERR) { + device_printf(sc->sc_dev, "%s: error, id %x off %x\n", + __func__, id, off); + sc->sc_bap_off = WI_OFF_ERR; /* invalidate */ + return EIO; + } + sc->sc_bap_id = id; + sc->sc_bap_off = off; + return 0; +} + +static int +wi_read_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen) +{ + u_int16_t *ptr; + int i, error, cnt; + + if (buflen == 0) + return 0; + if (id != sc->sc_bap_id || off != sc->sc_bap_off) { + if ((error = wi_seek_bap(sc, id, off)) != 0) + return error; + } + cnt = (buflen + 1) / 2; + ptr = (u_int16_t *)buf; + for (i = 0; i < cnt; i++) + *ptr++ = CSR_READ_2(sc, WI_DATA0); + sc->sc_bap_off += cnt * 2; + return 0; +} + +static int +wi_write_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen) +{ + u_int16_t *ptr; + int i, error, cnt; + + if (buflen == 0) + return 0; + + if (id != sc->sc_bap_id || off != sc->sc_bap_off) { + if ((error = wi_seek_bap(sc, id, off)) != 0) + return error; + } + cnt = (buflen + 1) / 2; + ptr = (u_int16_t *)buf; + for (i = 0; i < cnt; i++) + CSR_WRITE_2(sc, WI_DATA0, ptr[i]); + sc->sc_bap_off += cnt * 2; + + return 0; +} + +static int +wi_mwrite_bap(struct wi_softc *sc, int id, int off, struct mbuf *m0, int totlen) +{ + int error, len; + struct mbuf *m; + + for (m = m0; m != NULL && totlen > 0; m = m->m_next) { + if (m->m_len == 0) + continue; + + len = min(m->m_len, totlen); + + if (((u_long)m->m_data) % 2 != 0 || len % 2 != 0) { + m_copydata(m, 0, totlen, (caddr_t)&sc->sc_txbuf); + return wi_write_bap(sc, id, off, (caddr_t)&sc->sc_txbuf, + totlen); + } + + if ((error = wi_write_bap(sc, id, off, m->m_data, len)) != 0) + return error; + + off += m->m_len; + totlen -= len; + } + return 0; +} + +static int +wi_alloc_fid(struct wi_softc *sc, int len, int *idp) +{ + int i; + + if (wi_cmd(sc, WI_CMD_ALLOC_MEM, len, 0, 0)) { + device_printf(sc->sc_dev, "%s: failed to allocate %d bytes on NIC\n", + __func__, len); + return ENOMEM; + } + + for (i = 0; i < WI_TIMEOUT; i++) { + if (CSR_READ_2(sc, WI_EVENT_STAT) & WI_EV_ALLOC) + break; + DELAY(1); + } + if (i == WI_TIMEOUT) { + device_printf(sc->sc_dev, "%s: timeout in alloc\n", __func__); + return ETIMEDOUT; + } + *idp = CSR_READ_2(sc, WI_ALLOC_FID); + CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC); + return 0; +} + +static int +wi_read_rid(struct wi_softc *sc, int rid, void *buf, int *buflenp) +{ + int error, len; + u_int16_t ltbuf[2]; + + /* Tell the NIC to enter record read mode. */ + error = wi_cmd(sc, WI_CMD_ACCESS | WI_ACCESS_READ, rid, 0, 0); + if (error) + return error; + + error = wi_read_bap(sc, rid, 0, ltbuf, sizeof(ltbuf)); + if (error) + return error; + + if (le16toh(ltbuf[1]) != rid) { + device_printf(sc->sc_dev, "record read mismatch, rid=%x, got=%x\n", + rid, le16toh(ltbuf[1])); + return EIO; + } + len = (le16toh(ltbuf[0]) - 1) * 2; /* already got rid */ + if (*buflenp < len) { + device_printf(sc->sc_dev, "record buffer is too small, " + "rid=%x, size=%d, len=%d\n", + rid, *buflenp, len); + return ENOSPC; + } + *buflenp = len; + return wi_read_bap(sc, rid, sizeof(ltbuf), buf, len); +} + +static int +wi_write_rid(struct wi_softc *sc, int rid, void *buf, int buflen) +{ + int error; + u_int16_t ltbuf[2]; + + ltbuf[0] = htole16((buflen + 1) / 2 + 1); /* includes rid */ + ltbuf[1] = htole16(rid); + + error = wi_write_bap(sc, rid, 0, ltbuf, sizeof(ltbuf)); + if (error) { + device_printf(sc->sc_dev, "%s: bap0 write failure, rid 0x%x\n", + __func__, rid); + return error; + } + error = wi_write_bap(sc, rid, sizeof(ltbuf), buf, buflen); + if (error) { + device_printf(sc->sc_dev, "%s: bap1 write failure, rid 0x%x\n", + __func__, rid); + return error; + } + + return wi_cmd(sc, WI_CMD_ACCESS | WI_ACCESS_WRITE, rid, 0, 0); +} + +static int +wi_write_appie(struct wi_softc *sc, int rid, const struct ieee80211_appie *ie) +{ + /* NB: 42 bytes is probably ok to have on the stack */ + char buf[sizeof(uint16_t) + 40]; + + if (ie->ie_len > 40) + return EINVAL; + /* NB: firmware requires 16-bit ie length before ie data */ + *(uint16_t *) buf = htole16(ie->ie_len); + memcpy(buf + sizeof(uint16_t), ie->ie_data, ie->ie_len); + return wi_write_rid(sc, rid, buf, ie->ie_len + sizeof(uint16_t)); +} + +int +wi_alloc(device_t dev, int rid) +{ + struct wi_softc *sc = device_get_softc(dev); + + if (sc->wi_bus_type != WI_BUS_PCI_NATIVE) { + sc->iobase_rid = rid; + sc->iobase = bus_alloc_resource(dev, SYS_RES_IOPORT, + &sc->iobase_rid, 0, ~0, (1 << 6), + rman_make_alignment_flags(1 << 6) | RF_ACTIVE); + if (sc->iobase == NULL) { + device_printf(dev, "No I/O space?!\n"); + return ENXIO; + } + + sc->wi_io_addr = rman_get_start(sc->iobase); + sc->wi_btag = rman_get_bustag(sc->iobase); + sc->wi_bhandle = rman_get_bushandle(sc->iobase); + } else { + sc->mem_rid = rid; + sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &sc->mem_rid, RF_ACTIVE); + if (sc->mem == NULL) { + device_printf(dev, "No Mem space on prism2.5?\n"); + return ENXIO; + } + + sc->wi_btag = rman_get_bustag(sc->mem); + sc->wi_bhandle = rman_get_bushandle(sc->mem); + } + + sc->irq_rid = 0; + sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, + RF_ACTIVE | + ((sc->wi_bus_type == WI_BUS_PCCARD) ? 0 : RF_SHAREABLE)); + if (sc->irq == NULL) { + wi_free(dev); + device_printf(dev, "No irq?!\n"); + return ENXIO; + } + + sc->sc_dev = dev; + sc->sc_unit = device_get_unit(dev); + return 0; +} + +void +wi_free(device_t dev) +{ + struct wi_softc *sc = device_get_softc(dev); + + if (sc->iobase != NULL) { + bus_release_resource(dev, SYS_RES_IOPORT, sc->iobase_rid, sc->iobase); + sc->iobase = NULL; + } + if (sc->irq != NULL) { + bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq); + sc->irq = NULL; + } + if (sc->mem != NULL) { + bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem); + sc->mem = NULL; + } +} diff --git a/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi_pccard.c b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi_pccard.c new file mode 100644 index 0000000000..382a3a34e6 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi_pccard.c @@ -0,0 +1,201 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for FreeBSD. + * + * Written by Bill Paul + * Electrical Engineering Department + * Columbia University, New York City + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#define PCCARD_API_LEVEL 6 +#include +#include + +#include +#include +#include + +#include "card_if.h" +#include "pccarddevs.h" + +static int wi_pccard_probe(device_t); +static int wi_pccard_attach(device_t); + +static device_method_t wi_pccard_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, wi_pccard_probe), + DEVMETHOD(device_attach, wi_pccard_attach), + DEVMETHOD(device_detach, wi_detach), + DEVMETHOD(device_shutdown, wi_shutdown), + + { 0, 0 } +}; + +static driver_t wi_pccard_driver = { + "wi", + wi_pccard_methods, + sizeof(struct wi_softc) +}; + +DRIVER_MODULE(wi, pccard, wi_pccard_driver, wi_devclass, 0, 0); +MODULE_DEPEND(wi, wlan, 1, 1, 1); + +static const struct pccard_product wi_pccard_products[] = { + PCMCIA_CARD(3COM, 3CRWE737A), + PCMCIA_CARD(3COM, 3CRWE777A), + PCMCIA_CARD(ACTIONTEC, PRISM), + PCMCIA_CARD(ADAPTEC2, ANW8030), + PCMCIA_CARD(ADDTRON, AWP100), + PCMCIA_CARD(AIRVAST, WN_100B), + PCMCIA_CARD(AIRVAST, WN_100), + PCMCIA_CARD(ALLIEDTELESIS, WR211PCM), + PCMCIA_CARD(ARTEM, ONAIR), + PCMCIA_CARD(ASUS, WL100), + PCMCIA_CARD(BAY, EMOBILITY_11B), + PCMCIA_CARD(BROMAX, IWN), + PCMCIA_CARD(BROMAX, IWN3), + PCMCIA_CARD(BROMAX, WCF11), + PCMCIA_CARD(BUFFALO, WLI_CF_S11G), + PCMCIA_CARD(BUFFALO, WLI_PCM_S11), + PCMCIA_CARD(COMPAQ, NC5004), + PCMCIA_CARD(CONTEC, FX_DS110_PCC), + PCMCIA_CARD(COREGA, WIRELESS_LAN_PCC_11), + PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCA_11), + PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCB_11), + PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCL_11), + PCMCIA_CARD(DLINK, DWL650H), + PCMCIA_CARD(ELSA, XI300_IEEE), + PCMCIA_CARD(ELSA, XI325_IEEE), + PCMCIA_CARD(ELSA, APDL325_IEEE), + PCMCIA_CARD(ELSA, XI330_IEEE), + PCMCIA_CARD(ELSA, XI800_IEEE), + PCMCIA_CARD(ELSA, WIFI_FLASH), + PCMCIA_CARD(EMTAC, WLAN), + PCMCIA_CARD(ERICSSON, WIRELESSLAN), + PCMCIA_CARD(GEMTEK, WLAN), + PCMCIA_CARD(HWN, AIRWAY80211), + PCMCIA_CARD(INTEL, PRO_WLAN_2011), + PCMCIA_CARD(INTERSIL, ISL37100P), + PCMCIA_CARD(INTERSIL, ISL37110P), + PCMCIA_CARD(INTERSIL, ISL37300P), + PCMCIA_CARD(INTERSIL2, PRISM2), + PCMCIA_CARD(IODATA2, WCF12), + PCMCIA_CARD(IODATA2, WNB11PCM), + PCMCIA_CARD(FUJITSU, WL110), + PCMCIA_CARD(LUCENT, WAVELAN_IEEE), + PCMCIA_CARD(MICROSOFT, MN_520), + PCMCIA_CARD(NOKIA, C020_WLAN), + PCMCIA_CARD(NOKIA, C110_WLAN), + PCMCIA_CARD(PLANEX, GWNS11H), + PCMCIA_CARD(PROXIM, HARMONY), + PCMCIA_CARD(PROXIM, RANGELANDS_8430), + PCMCIA_CARD(SAMSUNG, SWL_2000N), + PCMCIA_CARD(SIEMENS, SS1021), + PCMCIA_CARD(SIEMENS, SS1021A), + PCMCIA_CARD(SIMPLETECH, SPECTRUM24_ALT), + PCMCIA_CARD(SOCKET, LP_WLAN_CF), + PCMCIA_CARD(TDK, LAK_CD011WL), + { NULL } +}; + +static int +wi_pccard_probe(device_t dev) +{ + const struct pccard_product *pp; + u_int32_t fcn = PCCARD_FUNCTION_UNSPEC; + int error; + + /* Make sure we're a network driver */ + error = pccard_get_function(dev, &fcn); + if (error != 0) + return error; + if (fcn != PCCARD_FUNCTION_NETWORK) + return ENXIO; + + pp = pccard_product_lookup(dev, wi_pccard_products, + sizeof(wi_pccard_products[0]), NULL); + if (pp != NULL) { + if (pp->pp_name != NULL) + device_set_desc(dev, pp->pp_name); + return 0; + } + return ENXIO; +} + +static int +wi_pccard_attach(device_t dev) +{ + struct wi_softc *sc; + int error; + + sc = device_get_softc(dev); + sc->wi_gone = 0; + sc->wi_bus_type = WI_BUS_PCCARD; + + error = wi_alloc(dev, 0); + if (error == 0) { + /* Make sure interrupts are disabled. */ + CSR_WRITE_2(sc, WI_INT_EN, 0); + CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF); + + error = wi_attach(dev); + if (error != 0) + wi_free(dev); + } + return error; +} diff --git a/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi_pci.c b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi_pci.c new file mode 100644 index 0000000000..958ba7ef49 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wi_pci.c @@ -0,0 +1,271 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for FreeBSD. + * + * Written by Bill Paul + * Electrical Engineering Department + * Columbia University, New York City + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +static int wi_pci_probe(device_t); +static int wi_pci_attach(device_t); +static int wi_pci_suspend(device_t); +static int wi_pci_resume(device_t); + +static device_method_t wi_pci_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, wi_pci_probe), + DEVMETHOD(device_attach, wi_pci_attach), + DEVMETHOD(device_detach, wi_detach), + DEVMETHOD(device_shutdown, wi_shutdown), + DEVMETHOD(device_suspend, wi_pci_suspend), + DEVMETHOD(device_resume, wi_pci_resume), + + { 0, 0 } +}; + +static driver_t wi_pci_driver = { + "wi", + wi_pci_methods, + sizeof(struct wi_softc) +}; + +static struct { + unsigned int vendor,device; + int bus_type; + char *desc; +} pci_ids[] = { + /* Sorted by description */ + {0x10b7, 0x7770, WI_BUS_PCI_PLX, "3Com Airconnect"}, + {0x16ab, 0x1101, WI_BUS_PCI_PLX, "GLPRISM2 WaveLAN"}, + {0x1260, 0x3872, WI_BUS_PCI_NATIVE, "Intersil Prism3"}, + {0x1260, 0x3873, WI_BUS_PCI_NATIVE, "Intersil Prism2.5"}, + {0x16ab, 0x1102, WI_BUS_PCI_PLX, "Linksys WDT11"}, + {0x1385, 0x4100, WI_BUS_PCI_PLX, "Netgear MA301"}, + {0x1638, 0x1100, WI_BUS_PCI_PLX, "PRISM2STA WaveLAN"}, + {0x111a, 0x1023, WI_BUS_PCI_PLX, "Siemens SpeedStream"}, + {0x10b5, 0x9050, WI_BUS_PCI_PLX, "SMC 2602W"}, + {0x16ec, 0x3685, WI_BUS_PCI_PLX, "US Robotics 2415"}, + {0x4033, 0x7001, WI_BUS_PCI_PLX, "Addtron AWA-100 PCI"}, + {0, 0, 0, NULL} +}; + +DRIVER_MODULE(wi, pci, wi_pci_driver, wi_devclass, 0, 0); +MODULE_DEPEND(wi, pci, 1, 1, 1); +MODULE_DEPEND(wi, wlan, 1, 1, 1); + +static int +wi_pci_probe(dev) + device_t dev; +{ + struct wi_softc *sc; + int i; + + sc = device_get_softc(dev); + for(i=0; pci_ids[i].vendor != 0; i++) { + if ((pci_get_vendor(dev) == pci_ids[i].vendor) && + (pci_get_device(dev) == pci_ids[i].device)) { + sc->wi_bus_type = pci_ids[i].bus_type; + device_set_desc(dev, pci_ids[i].desc); + return (BUS_PROBE_DEFAULT); + } + } + return(ENXIO); +} + +static int +wi_pci_attach(device_t dev) +{ + struct wi_softc *sc; + u_int32_t command, wanted; + u_int16_t reg; + int error; + int timeout; + + sc = device_get_softc(dev); + + command = pci_read_config(dev, PCIR_COMMAND, 4); + wanted = PCIM_CMD_PORTEN|PCIM_CMD_MEMEN; + command |= wanted; + pci_write_config(dev, PCIR_COMMAND, command, 4); + command = pci_read_config(dev, PCIR_COMMAND, 4); + if ((command & wanted) != wanted) { + device_printf(dev, "wi_pci_attach() failed to enable pci!\n"); + return (ENXIO); + } + + if (sc->wi_bus_type != WI_BUS_PCI_NATIVE) { + error = wi_alloc(dev, WI_PCI_IORES); + if (error) + return (error); + + /* Make sure interrupts are disabled. */ + CSR_WRITE_2(sc, WI_INT_EN, 0); + CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF); + + /* We have to do a magic PLX poke to enable interrupts */ + sc->local_rid = WI_PCI_LOCALRES; + sc->local = bus_alloc_resource_any(dev, SYS_RES_IOPORT, + &sc->local_rid, RF_ACTIVE); + sc->wi_localtag = rman_get_bustag(sc->local); + sc->wi_localhandle = rman_get_bushandle(sc->local); + command = bus_space_read_4(sc->wi_localtag, sc->wi_localhandle, + WI_LOCAL_INTCSR); + command |= WI_LOCAL_INTEN; + bus_space_write_4(sc->wi_localtag, sc->wi_localhandle, + WI_LOCAL_INTCSR, command); + bus_release_resource(dev, SYS_RES_IOPORT, sc->local_rid, + sc->local); + sc->local = NULL; + + sc->mem_rid = WI_PCI_MEMRES; + sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &sc->mem_rid, RF_ACTIVE); + if (sc->mem == NULL) { + device_printf(dev, "couldn't allocate memory\n"); + wi_free(dev); + return (ENXIO); + } + sc->wi_bmemtag = rman_get_bustag(sc->mem); + sc->wi_bmemhandle = rman_get_bushandle(sc->mem); + + /* + * Write COR to enable PC card + * This is a subset of the protocol that the pccard bus code + * would do. In theory, we should parse the CIS to find the + * COR offset. In practice, the COR_OFFSET is always 0x3e0. + */ + CSM_WRITE_1(sc, WI_COR_OFFSET, WI_COR_VALUE); + reg = CSM_READ_1(sc, WI_COR_OFFSET); + if (reg != WI_COR_VALUE) { + device_printf(dev, "CSM_READ_1(WI_COR_OFFSET) " + "wanted %d, got %d\n", WI_COR_VALUE, reg); + wi_free(dev); + return (ENXIO); + } + } else { + error = wi_alloc(dev, WI_PCI_LMEMRES); + if (error) + return (error); + + CSR_WRITE_2(sc, WI_PCICOR_OFF, WI_PCICOR_RESET); + DELAY(250000); + + CSR_WRITE_2(sc, WI_PCICOR_OFF, 0x0000); + DELAY(500000); + + timeout=2000000; + while ((--timeout > 0) && + (CSR_READ_2(sc, WI_COMMAND) & WI_CMD_BUSY)) + DELAY(10); + + if (timeout == 0) { + device_printf(dev, "couldn't reset prism pci core.\n"); + wi_free(dev); + return(ENXIO); + } + } + + CSR_WRITE_2(sc, WI_HFA384X_SWSUPPORT0_OFF, WI_PRISM2STA_MAGIC); + reg = CSR_READ_2(sc, WI_HFA384X_SWSUPPORT0_OFF); + if (reg != WI_PRISM2STA_MAGIC) { + device_printf(dev, + "CSR_READ_2(WI_HFA384X_SWSUPPORT0_OFF) " + "wanted %d, got %d\n", WI_PRISM2STA_MAGIC, reg); + wi_free(dev); + return (ENXIO); + } + + error = wi_attach(dev); + if (error != 0) + wi_free(dev); + return (error); +} + +static int +wi_pci_suspend(device_t dev) +{ + struct wi_softc *sc = device_get_softc(dev); + + wi_stop(sc, 1); + + return (0); +} + +static int +wi_pci_resume(device_t dev) +{ + struct wi_softc *sc = device_get_softc(dev); + struct ifnet *ifp = sc->sc_ifp; + + if (sc->wi_bus_type != WI_BUS_PCI_NATIVE) + return (0); + + if (ifp->if_flags & IFF_UP) { + ifp->if_init(ifp->if_softc); + if (ifp->if_drv_flags & IFF_DRV_RUNNING) + ifp->if_start(ifp); + } + + return (0); +} diff --git a/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wireg.h b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wireg.h new file mode 100644 index 0000000000..d99e597c04 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wireg.h @@ -0,0 +1,724 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#define WI_DELAY 5 +#define WI_TIMEOUT (500000/WI_DELAY) /* 500 ms */ + +#define WI_PORT0 (0 << 8) +#define WI_PORT1 (1 << 8) +#define WI_PORT2 (2 << 8) +#define WI_PORT3 (3 << 8) +#define WI_PORT4 (4 << 8) +#define WI_PORT5 (5 << 8) + +#define WI_PCI_LMEMRES 0x10 /* PCI Memory (native PCI implementations) */ +#define WI_PCI_LOCALRES 0x14 /* The PLX chip's local registers */ +#define WI_PCI_MEMRES 0x18 /* The PCCard's attribute memory */ +#define WI_PCI_IORES 0x1C /* The PCCard's I/O space */ + +#define WI_LOCAL_INTCSR 0x4c +#define WI_LOCAL_INTEN 0x40 +#define WI_HFA384X_SWSUPPORT0_OFF 0x28 +#define WI_PRISM2STA_MAGIC 0x4A2D +#define WI_PCICOR_OFF 0x26 +#define WI_PCICOR_RESET 0x0080 + +/* Default port: 0 (only 0 exists on stations) */ +#define WI_DEFAULT_PORT WI_PORT0 + +/* Default network name: ANY */ +/* + * [sommerfeld 1999/07/15] Changed from "ANY" to ""; according to Bill Fenner, + * ANY is used in MS driver user interfaces, while "" is used over the + * wire.. + */ +#define WI_DEFAULT_NETNAME "" + +#define WI_DEFAULT_AP_DENSITY 1 + +#define WI_DEFAULT_RTS_THRESH 2347 + +#define WI_DEFAULT_DATALEN 2304 + +#define WI_DEFAULT_CREATE_IBSS 0 + +#define WI_DEFAULT_PM_ENABLED 0 + +#define WI_DEFAULT_MAX_SLEEP 100 + +#define WI_DEFAULT_ROAMING 1 + +#define WI_DEFAULT_AUTHTYPE 1 + +#ifdef __NetBSD__ +#define OS_STRING_NAME "NetBSD" +#endif +#ifdef __FreeBSD__ +#define OS_STRING_NAME "FreeBSD" +#endif +#ifdef __OpenBSD__ +#define OS_STRING_NAME "OpenBSD" +#endif + +#define WI_DEFAULT_NODENAME OS_STRING_NAME " WaveLAN/IEEE node" + +#define WI_DEFAULT_IBSS OS_STRING_NAME " IBSS" + +#define WI_BUS_PCCARD 0 /* pccard device */ +#define WI_BUS_PCI_PLX 1 /* PCI card w/ PLX PCI/PCMICA bridge */ +#define WI_BUS_PCI_NATIVE 2 /* native PCI device (Prism 2.5) */ + +/* + * register space access macros + */ +#define CSR_WRITE_4(sc, reg, val) \ + bus_space_write_4((sc)->wi_btag, (sc)->wi_bhandle, \ + (sc)->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg)*2 : (reg), val) +#define CSR_WRITE_2(sc, reg, val) \ + bus_space_write_2((sc)->wi_btag, (sc)->wi_bhandle, \ + (sc)->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg)*2 : (reg), val) +#define CSR_WRITE_1(sc, reg, val) \ + bus_space_write_1((sc)->wi_btag, (sc)->wi_bhandle, \ + (sc)->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg)*2 : (reg), val) + +#define CSR_READ_4(sc, reg) \ + bus_space_read_4((sc)->wi_btag, (sc)->wi_bhandle, \ + (sc)->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg)*2 : (reg)) +#define CSR_READ_2(sc, reg) \ + bus_space_read_2((sc)->wi_btag, (sc)->wi_bhandle, \ + (sc)->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg)*2 : (reg)) +#define CSR_READ_1(sc, reg) \ + bus_space_read_1((sc)->wi_btag, (sc)->wi_bhandle, \ + (sc)->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg)*2 : (reg)) + +#define CSM_WRITE_1(sc, off, val) \ + bus_space_write_1((sc)->wi_bmemtag, (sc)->wi_bmemhandle, off, val) + +#define CSM_READ_1(sc, off) \ + bus_space_read_1((sc)->wi_bmemtag, (sc)->wi_bmemhandle, off) + +#define CSR_WRITE_STREAM_2(sc, reg, val) \ + bus_space_write_stream_2(sc->wi_btag, sc->wi_bhandle, \ + (sc->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg) * 2 : (reg)), val) +#define CSR_WRITE_MULTI_STREAM_2(sc, reg, val, count) \ + bus_space_write_multi_stream_2(sc->wi_btag, sc->wi_bhandle, \ + (sc->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg) * 2 : (reg)), val, count) +#define CSR_READ_STREAM_2(sc, reg) \ + bus_space_read_stream_2(sc->wi_btag, sc->wi_bhandle, \ + (sc->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg) * 2 : (reg))) +#define CSR_READ_MULTI_STREAM_2(sc, reg, buf, count) \ + bus_space_read_multi_stream_2(sc->wi_btag, sc->wi_bhandle, \ + (sc->wi_bus_type == WI_BUS_PCI_NATIVE ? (reg) * 2 : (reg)), buf, count) + +/* + * The WaveLAN/IEEE cards contain an 802.11 MAC controller which Lucent + * calls 'Hermes.' In typical fashion, getting documentation about this + * controller is about as easy as squeezing blood from a stone. Here + * is more or less what I know: + * + * - The Hermes controller is firmware driven, and the host interacts + * with the Hermes via a firmware interface, which can change. + * + * - The Hermes is described in a document called: "Hermes Firmware + * WaveLAN/IEEE Station Functions," document #010245, which of course + * Lucent will not release without an NDA. + * + * - Lucent has created a library called HCF (Hardware Control Functions) + * though which it wants developers to interact with the card. The HCF + * is needlessly complex, ill conceived and badly documented. Actually, + * the comments in the HCP code itself aren't bad, but the publically + * available manual that comes with it is awful, probably due largely to + * the fact that it has been emasculated in order to hide information + * that Lucent wants to keep proprietary. The purpose of the HCF seems + * to be to insulate the driver programmer from the Hermes itself so that + * Lucent has an excuse not to release programming in for it. + * + * - Lucent only makes available documentation and code for 'HCF Light' + * which is a stripped down version of HCF with certain features not + * implemented, most notably support for 802.11 frames. + * + * - The HCF code which I have seen blows goats. Whoever decided to + * use a 132 column format should be shot. + * + * Rather than actually use the Lucent HCF library, I have stripped all + * the useful information from it and used it to create a driver in the + * usual BSD form. Note: I don't want to hear anybody whining about the + * fact that the Lucent code is GPLed and mine isn't. I did not actually + * put any of Lucent's code in this driver: I only used it as a reference + * to obtain information about the underlying hardware. The Hermes + * programming interface is not GPLed, so bite me. + */ + +/* + * Size of Hermes & Prism2 I/O space. + */ +#define WI_IOSIZ 0x40 + +/* + * Hermes & Prism2 register definitions + */ + +/* Hermes command/status registers. */ +#define WI_COMMAND 0x00 +#define WI_PARAM0 0x02 +#define WI_PARAM1 0x04 +#define WI_PARAM2 0x06 +#define WI_STATUS 0x08 +#define WI_RESP0 0x0A +#define WI_RESP1 0x0C +#define WI_RESP2 0x0E + +/* Command register values. */ +#define WI_CMD_BUSY 0x8000 /* busy bit */ +#define WI_CMD_INI 0x0000 /* initialize */ +#define WI_CMD_ENABLE 0x0001 /* enable */ +#define WI_CMD_DISABLE 0x0002 /* disable */ +#define WI_CMD_DIAG 0x0003 +#define WI_CMD_ALLOC_MEM 0x000A /* allocate NIC memory */ +#define WI_CMD_TX 0x000B /* transmit */ +#define WI_CMD_NOTIFY 0x0010 +#define WI_CMD_INQUIRE 0x0011 +#define WI_CMD_ACCESS 0x0021 +#define WI_CMD_ACCESS_WRITE 0x0121 +#define WI_CMD_PROGRAM 0x0022 +#define WI_CMD_READEE 0x0030 /* symbol only */ +#define WI_CMD_READMIF 0x0030 /* prism2 */ +#define WI_CMD_WRITEMIF 0x0031 /* prism2 */ +#define WI_CMD_DEBUG 0x0038 /* Various test commands */ + +#define WI_CMD_CODE_MASK 0x003F + +/* + * Various cmd test stuff. + */ +#define WI_TEST_MONITOR 0x0B +#define WI_TEST_STOP 0x0F +#define WI_TEST_CFG_BITS 0x15 +#define WI_TEST_CFG_BIT_ALC 0x08 + +/* + * Reclaim qualifier bit, applicable to the + * TX and INQUIRE commands. + */ +#define WI_RECLAIM 0x0100 /* reclaim NIC memory */ + +/* + * ACCESS command qualifier bits. + */ +#define WI_ACCESS_READ 0x0000 +#define WI_ACCESS_WRITE 0x0100 + +/* + * PROGRAM command qualifier bits. + */ +#define WI_PROGRAM_DISABLE 0x0000 +#define WI_PROGRAM_ENABLE_RAM 0x0100 +#define WI_PROGRAM_ENABLE_NVRAM 0x0200 +#define WI_PROGRAM_NVRAM 0x0300 + +/* Status register values */ +#define WI_STAT_CMD_CODE 0x003F +#define WI_STAT_DIAG_ERR 0x0100 +#define WI_STAT_INQ_ERR 0x0500 +#define WI_STAT_CMD_RESULT 0x7F00 + +/* memory handle management registers */ +#define WI_INFO_FID 0x10 +#define WI_RX_FID 0x20 +#define WI_ALLOC_FID 0x22 +#define WI_TX_CMP_FID 0x24 + +/* + * Buffer Access Path (BAP) registers. + * These are I/O channels. I believe you can use each one for + * any desired purpose independently of the other. In general + * though, we use BAP1 for reading and writing LTV records and + * reading received data frames, and BAP0 for writing transmit + * frames. This is a convention though, not a rule. + */ +#define WI_SEL0 0x18 +#define WI_SEL1 0x1A +#define WI_OFF0 0x1C +#define WI_OFF1 0x1E +#define WI_DATA0 0x36 +#define WI_DATA1 0x38 +#define WI_BAP0 WI_DATA0 +#define WI_BAP1 WI_DATA1 + +#define WI_OFF_BUSY 0x8000 +#define WI_OFF_ERR 0x4000 +#define WI_OFF_DATAOFF 0x0FFF + +/* Event registers */ +#define WI_EVENT_STAT 0x30 /* Event status */ +#define WI_INT_EN 0x32 /* Interrupt enable/disable */ +#define WI_EVENT_ACK 0x34 /* Ack event */ + +/* Events */ +#define WI_EV_TICK 0x8000 /* aux timer tick */ +#define WI_EV_RES 0x4000 /* controller h/w error (time out) */ +#define WI_EV_INFO_DROP 0x2000 /* no RAM to build unsolicited frame */ +#define WI_EV_NO_CARD 0x0800 /* card removed (hunh?) */ +#define WI_EV_DUIF_RX 0x0400 /* wavelan management packet received */ +#define WI_EV_INFO 0x0080 /* async info frame */ +#define WI_EV_CMD 0x0010 /* command completed */ +#define WI_EV_ALLOC 0x0008 /* async alloc/reclaim completed */ +#define WI_EV_TX_EXC 0x0004 /* async xmit completed with failure */ +#define WI_EV_TX 0x0002 /* async xmit completed succesfully */ +#define WI_EV_RX 0x0001 /* async rx completed */ + +/* Host software registers */ +#define WI_SW0 0x28 +#define WI_SW1 0x2A +#define WI_SW2 0x2C +#define WI_SW3 0x2E /* does not appear in Prism2 */ + +#define WI_CNTL 0x14 + +#define WI_CNTL_AUX_ENA 0xC000 +#define WI_CNTL_AUX_ENA_STAT 0xC000 +#define WI_CNTL_AUX_DIS_STAT 0x0000 +#define WI_CNTL_AUX_ENA_CNTL 0x8000 +#define WI_CNTL_AUX_DIS_CNTL 0x4000 + +#define WI_AUX_PAGE 0x3A +#define WI_AUX_OFFSET 0x3C +#define WI_AUX_DATA 0x3E + +#define WI_AUX_PGSZ 128 +#define WI_AUX_KEY0 0xfe01 +#define WI_AUX_KEY1 0xdc23 +#define WI_AUX_KEY2 0xba45 + +#define WI_COR 0x40 /* only for Symbol */ +#define WI_COR_RESET 0x0080 +#define WI_COR_IOMODE 0x0041 + +#define WI_HCR 0x42 /* only for Symbol */ +#define WI_HCR_4WIRE 0x0010 +#define WI_HCR_RUN 0x0007 +#define WI_HCR_HOLD 0x000f +#define WI_HCR_EEHOLD 0x00ce + +#define WI_COR_OFFSET 0x3e0 /* OK for PCI, default COR for Prism PC Card */ +#define WI_COR_VALUE 0x41 + +/* + * One form of communication with the Hermes is with what Lucent calls + * LTV records, where LTV stands for Length, Type and Value. The length + * and type are 16 bits and are in native byte order. The value is in + * multiples of 16 bits and is in little endian byte order. + */ +struct wi_lt_hdr { + u_int16_t wi_len; + u_int16_t wi_type; + /* value is vary depends on resource id */ +}; + +/* + * Download buffer location and length (0xFD01). + */ +struct wi_dnld_buf { + u_int16_t wi_buf_pg; /* page addr of intermediate dl buf*/ + u_int16_t wi_buf_off; /* offset of idb */ + u_int16_t wi_buf_len; /* len of idb */ +}; + +/* + * Mem sizes (0xFD02). + */ +struct wi_memsz { + u_int16_t wi_mem_ram; + u_int16_t wi_mem_nvram; +}; + +/* + * NIC Identification (0xFD0B, 0xFD20) + */ +struct wi_ver { + u_int16_t wi_ver[4]; +}; + +/* define card ident */ +#define WI_NIC_LUCENT_ID 0x0001 +#define WI_NIC_LUCENT_STR "Lucent Technologies, WaveLAN/IEEE" + +#define WI_NIC_SONY_ID 0x0002 +#define WI_NIC_SONY_STR "Sony WaveLAN/IEEE" + +#define WI_NIC_LUCENT_EMB_ID 0x0005 +#define WI_NIC_LUCENT_EMB_STR "Lucent Embedded WaveLAN/IEEE" + +#define WI_NIC_EVB2_ID 0x8000 +#define WI_NIC_EVB2_STR "RF:PRISM2 MAC:HFA3841" + +#define WI_NIC_HWB3763_ID 0x8001 +#define WI_NIC_HWB3763_STR "RF:PRISM2 MAC:HFA3841 CARD:HWB3763 rev.B" + +#define WI_NIC_HWB3163_ID 0x8002 +#define WI_NIC_HWB3163_STR "RF:PRISM2 MAC:HFA3841 CARD:HWB3163 rev.A" + +#define WI_NIC_HWB3163B_ID 0x8003 +#define WI_NIC_HWB3163B_STR "RF:PRISM2 MAC:HFA3841 CARD:HWB3163 rev.B" + +#define WI_NIC_EVB3_ID 0x8004 +#define WI_NIC_EVB3_STR "RF:PRISM2 MAC:HFA3842 CARD:HFA3842 EVAL" + +#define WI_NIC_HWB1153_ID 0x8007 +#define WI_NIC_HWB1153_STR "RF:PRISM1 MAC:HFA3841 CARD:HWB1153" + +#define WI_NIC_P2_SST_ID 0x8008 /* Prism2 with SST flush */ +#define WI_NIC_P2_SST_STR "RF:PRISM2 MAC:HFA3841 CARD:HWB3163-SST-flash" + +#define WI_NIC_EVB2_SST_ID 0x8009 +#define WI_NIC_EVB2_SST_STR "RF:PRISM2 MAC:HFA3841 CARD:HWB3163-SST-flash" + +#define WI_NIC_3842_EVA_ID 0x800A /* 3842 Evaluation Board */ +#define WI_NIC_3842_EVA_STR "RF:PRISM2 MAC:HFA3842 CARD:HFA3842 EVAL" + +#define WI_NIC_3842_PCMCIA_AMD_ID 0x800B /* Prism2.5 PCMCIA */ +#define WI_NIC_3842_PCMCIA_SST_ID 0x800C +#define WI_NIC_3842_PCMCIA_ATL_ID 0x800D +#define WI_NIC_3842_PCMCIA_ATS_ID 0x800E +#define WI_NIC_3842_PCMCIA_STR "RF:PRISM2.5 MAC:ISL3873" + +#define WI_NIC_3842_MINI_AMD_ID 0x8012 /* Prism2.5 Mini-PCI */ +#define WI_NIC_3842_MINI_SST_ID 0x8013 +#define WI_NIC_3842_MINI_ATL_ID 0x8014 +#define WI_NIC_3842_MINI_ATS_ID 0x8015 +#define WI_NIC_3842_MINI_STR "RF:PRISM2.5 MAC:ISL3874A(Mini-PCI)" + +#define WI_NIC_3842_PCI_AMD_ID 0x8016 /* Prism2.5 PCI-bridge */ +#define WI_NIC_3842_PCI_SST_ID 0x8017 +#define WI_NIC_3842_PCI_ATL_ID 0x8018 +#define WI_NIC_3842_PCI_ATS_ID 0x8019 +#define WI_NIC_3842_PCI_STR "RF:PRISM2.5 MAC:ISL3874A(PCI-bridge)" + +#define WI_NIC_P3_PCMCIA_AMD_ID 0x801A /* Prism3 PCMCIA */ +#define WI_NIC_P3_PCMCIA_SST_ID 0x801B +#define WI_NIC_P3_PCMCIA_ATL_ID 0x801C +#define WI_NIC_P3_PCMCIA_ATS_ID 0x801D +#define WI_NIC_P3_PCMCIA_STR "RF:PRISM3(PCMCIA)" + +#define WI_NIC_P3_USB_AMD_ID 0x801E +#define WI_NIC_P3_USB_SST_ID 0x801F +#define WI_NIC_P3_USB_ATL_ID 0x8020 + +#define WI_NIC_P3_MINI_AMD_ID 0x8021 /* Prism3 Mini-PCI */ +#define WI_NIC_P3_MINI_SST_ID 0x8022 +#define WI_NIC_P3_MINI_ATL_ID 0x8023 +#define WI_NIC_P3_MINI_ATS_ID 0x8024 +#define WI_NIC_P3_MINI_STR "RF:PRISM3(Mini-PCI)" + +/* + * List of intended regulatory domains (0xFD11). + */ +struct wi_ltv_domains { + u_int16_t wi_len; + u_int16_t wi_type; + u_int16_t wi_num_dom; + u_int8_t wi_domains[10]; +}; + +/* + * CIS struct (0xFD13). + */ +struct wi_cis { + u_int16_t wi_cis[240]; +}; + +/* + * Communications quality (0xFD43). + */ +struct wi_commqual { + u_int16_t wi_coms_qual; + u_int16_t wi_sig_lvl; + u_int16_t wi_noise_lvl; +}; + +/* + * Actual system scale thresholds (0xFC06, 0xFD46). + */ +struct wi_scalethresh { + u_int16_t wi_energy_detect; + u_int16_t wi_carrier_detect; + u_int16_t wi_defer; + u_int16_t wi_cell_search; + u_int16_t wi_out_of_range; + u_int16_t wi_delta_snr; +}; + +/* + * PCF info struct (0xFD87). + */ +struct wi_pcf { + u_int16_t wi_medium_occupancy_limit; + u_int16_t wi_cfp_period; + u_int16_t wi_cfp_max_duration; +}; + +/* + * Connection control characteristics. (0xFC00) + * 0 == IBSS (802.11 compliant mode) (Only PRISM2) + * 1 == Basic Service Set (BSS) + * 2 == Wireless Distribudion System (WDS) + * 3 == Pseudo IBSS + * (Only PRISM2; not 802.11 compliant mode, testing use only) + * 6 == HOST AP (Only PRISM2) + */ +#define WI_PORTTYPE_IBSS 0x0 +#define WI_PORTTYPE_BSS 0x1 +#define WI_PORTTYPE_WDS 0x2 +#define WI_PORTTYPE_ADHOC 0x3 +#define WI_PORTTYPE_APSILENT 0x5 +#define WI_PORTTYPE_HOSTAP 0x6 + +/* + * Mac addresses. (0xFC01, 0xFC08) + */ +struct wi_macaddr { + u_int8_t wi_mac_addr[6]; +}; + +/* + * Station set identification (SSID). (0xFC02, 0xFC04) + */ +struct wi_ssid { + u_int16_t wi_len; + u_int8_t wi_ssid[32]; +}; + +/* + * Set our station name. (0xFC0E) + */ +struct wi_nodename { + u_int16_t wi_nodelen; + u_int8_t wi_nodename[32]; +}; + +/* + * Multicast addresses to be put in filter. We're + * allowed up to 16 addresses in the filter. (0xFC80) + */ +struct wi_mcast { + struct ether_addr wi_mcast[16]; +}; + +/* + * Join request. (0xFCE2) + */ +struct wi_joinreq { + struct ether_addr wi_bssid; + u_int16_t wi_chan; +}; + +/* + * supported rates. (0xFCB4) + */ +#define WI_SUPPRATES_1M 0x0001 +#define WI_SUPPRATES_2M 0x0002 +#define WI_SUPPRATES_5M 0x0004 +#define WI_SUPPRATES_11M 0x0008 +#define WI_RATES_BITS "\20\0011M\0022M\0035.5M\00411M" + +/* + * Information frame types. + */ +#define WI_INFO_NOTIFY 0xF000 /* Handover address */ +#define WI_INFO_COUNTERS 0xF100 /* Statistics counters */ +#define WI_INFO_SCAN_RESULTS 0xF101 /* Scan results */ +#define WI_INFO_HOST_SCAN_RESULTS 0xF104 /* Scan results */ +#define WI_INFO_LINK_STAT 0xF200 /* Link status */ +#define WI_INFO_LINK_STAT_CONNECTED 1 +#define WI_INFO_LINK_STAT_DISCONNECTED 2 +#define WI_INFO_LINK_STAT_AP_CHG 3 /* AP Change */ +#define WI_INFO_LINK_STAT_AP_OOR 4 /* AP Out Of Range */ +#define WI_INFO_LINK_STAT_AP_INR 5 /* AP In Range */ +#define WI_INFO_LINK_STAT_ASSOC_FAILED 6 +#define WI_INFO_ASSOC_STAT 0xF201 /* Association status */ +#define WI_INFO_AUTH_REQUEST 0xF202 /* Authentication Request (AP) */ +#define WI_INFO_POWERSAVE_COUNT 0xF203 /* PowerSave User Count (AP) */ + +struct wi_assoc { + u_int16_t wi_assoc_stat; /* Association Status */ +#define ASSOC 1 +#define REASSOC 2 +#define DISASSOC 3 +#define ASSOCFAIL 4 +#define AUTHFAIL 5 + u_int8_t wi_assoc_sta[6]; /* Station Address */ + u_int8_t wi_assoc_osta[6]; /* OLD Station Address */ + u_int16_t wi_assoc_reason; /* Reason */ + u_int16_t wi_assoc_reserve; /* Reserved */ +}; + +/* + * Scan Results of Prism2 chip + */ + +struct wi_scan_header { + u_int16_t wi_reserve; /* future use */ + u_int16_t wi_reason; /* The reason this scan was initiated + 1: Host initiated + 2: Firmware initiated + 3: Inquiry request from host */ +}; + +struct wi_scan_data_p2 { + u_int16_t wi_chid; /* BSS Channel ID from Probe Res.(PR)*/ + u_int16_t wi_noise; /* Average Noise Level of the PR */ + u_int16_t wi_signal; /* Signal Level on the PR */ + u_int8_t wi_bssid[6]; /* MACaddress of BSS responder from PR */ + u_int16_t wi_interval; /* BSS beacon interval */ + u_int16_t wi_capinfo; /* BSS Capability Information + IEEE Std 802.11(1997) ,see 7.3.1.4 */ + u_int16_t wi_namelen; /* Length of SSID strings */ + u_int8_t wi_name[32]; /* SSID strings */ + u_int16_t wi_suprate[5]; /* Supported Rates element from the PR + IEEE Std 802.11(1997) ,see 7.3.2.2 */ + u_int16_t wi_rate; /* Data rate of the PR */ +#define WI_APRATE_1 0x0A /* 1 Mbps */ +#define WI_APRATE_2 0x14 /* 2 Mbps */ +#define WI_APRATE_5 0x37 /* 5.5 Mbps */ +#define WI_APRATE_11 0x6E /* 11 Mbps */ +}; + +/* + * Scan Results of Lucent chip + */ +struct wi_scan_data { + u_int16_t wi_chid; /* BSS Channel ID from PR */ + u_int16_t wi_noise; /* Average Noise Level of the PR */ + u_int16_t wi_signal; /* Signal Level on the PR */ + u_int8_t wi_bssid[6]; /* MACaddress of BSS responder from PR */ + u_int16_t wi_interval; /* BSS beacon interval */ + u_int16_t wi_capinfo; /* BSS Capability Information + IEEE Std 802.11(1997) ,see 7.3.1.4 */ + u_int16_t wi_namelen; /* Length of SSID strings */ + u_int8_t wi_name[32]; /* SSID strings */ +}; + +/* + * transmit/receive frame structure + */ +struct wi_frame { + u_int16_t wi_status; /* 0x00 */ + u_int16_t wi_rx_tstamp1; /* 0x02 */ + u_int16_t wi_rx_tstamp0; /* 0x04 */ + u_int8_t wi_rx_silence; /* 0x06 */ + u_int8_t wi_rx_signal; /* 0x07 */ + u_int8_t wi_rx_rate; /* 0x08 */ + u_int8_t wi_rx_flow; /* 0x09 */ + u_int8_t wi_tx_rtry; /* 0x0a */ /* Prism2 AP Only */ + u_int8_t wi_tx_rate; /* 0x0b */ /* Prism2 AP Only */ + u_int16_t wi_tx_ctl; /* 0x0c */ + struct ieee80211_frame_addr4 wi_whdr; /* 0x0e */ + u_int16_t wi_dat_len; /* 0x2c */ + struct ether_header wi_ehdr; /* 0x2e */ +} __attribute__((__packed__)); + +/* Tx Status Field */ +#define WI_TXSTAT_RET_ERR 0x0001 +#define WI_TXSTAT_AGED_ERR 0x0002 +#define WI_TXSTAT_DISCONNECT 0x0004 +#define WI_TXSTAT_FORM_ERR 0x0008 + +/* Rx Status Field */ +#define WI_STAT_BADCRC 0x0001 +#define WI_STAT_UNDECRYPTABLE 0x0002 +#define WI_STAT_ERRSTAT 0x0003 +#define WI_STAT_MAC_PORT 0x0700 +#define WI_STAT_PCF 0x1000 +#define WI_RXSTAT_MSG_TYPE 0xE000 +#define WI_STAT_1042 0x2000 /* RFC1042 encoded */ +#define WI_STAT_TUNNEL 0x4000 /* Bridge-tunnel encoded */ +#define WI_STAT_WMP_MSG 0x6000 /* WaveLAN-II management protocol */ +#define WI_STAT_MGMT 0x8000 /* 802.11b management frames */ + +#define WI_ENC_TX_E_II 0x0E + +#define WI_ENC_TX_1042 0x00 +#define WI_ENC_TX_TUNNEL 0xF8 + +/* TxControl Field (enhanced) */ +#define WI_TXCNTL_TX_OK 0x0002 +#define WI_TXCNTL_TX_EX 0x0004 +#define WI_TXCNTL_STRUCT_TYPE 0x0018 +#define WI_ENC_TX_802_3 0x00 +#define WI_ENC_TX_802_11 0x08 +#define WI_TXCNTL_ALTRTRY 0x0020 +#define WI_TXCNTL_NOCRYPT 0x0080 + +/* + * HFA3861/3863 (BBP) Control Registers + */ +#define WI_HFA386X_CR_A_D_TEST_MODES2 0x1A +#define WI_HFA386X_CR_MANUAL_TX_POWER 0x3E + +#ifdef IEEE80211_RADIOTAP_F_CFP +/* + * Radio capture format for Prism. + */ +#define WI_RX_RADIOTAP_PRESENT \ + ((1 << IEEE80211_RADIOTAP_TSFT) | \ + (1 << IEEE80211_RADIOTAP_FLAGS) | \ + (1 << IEEE80211_RADIOTAP_RATE) | \ + (1 << IEEE80211_RADIOTAP_CHANNEL) | \ + (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \ + (1 << IEEE80211_RADIOTAP_DB_ANTNOISE)) + +struct wi_rx_radiotap_header { + struct ieee80211_radiotap_header wr_ihdr; + u_int64_t wr_tsf; + u_int8_t wr_flags; + u_int8_t wr_rate; + u_int16_t wr_chan_freq; + u_int16_t wr_chan_flags; + u_int8_t wr_antsignal; + u_int8_t wr_antnoise; +}; + +#define WI_TX_RADIOTAP_PRESENT \ + ((1 << IEEE80211_RADIOTAP_FLAGS) | \ + (1 << IEEE80211_RADIOTAP_RATE) | \ + (1 << IEEE80211_RADIOTAP_CHANNEL)) + +struct wi_tx_radiotap_header { + struct ieee80211_radiotap_header wt_ihdr; + u_int8_t wt_flags; + u_int8_t wt_rate; + u_int16_t wt_chan_freq; + u_int16_t wt_chan_flags; +}; +#endif /* IEEE80211_RADIOTAP_F_CFP */ diff --git a/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wivar.h b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wivar.h new file mode 100644 index 0000000000..99b866daf1 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/wlan/wavelanwifi/dev/wi/if_wivar.h @@ -0,0 +1,186 @@ +/*- + * Copyright (c) 2002 + * M Warner Losh . All rights reserved. + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Encryption controls. We can enable or disable encryption as + * well as specify up to 4 encryption keys. We can also specify + * which of the four keys will be used for transmit encryption. + */ +#define WI_RID_ENCRYPTION 0xFC20 +#define WI_RID_AUTHTYPE 0xFC21 +#define WI_RID_DEFLT_CRYPT_KEYS 0xFCB0 +#define WI_RID_TX_CRYPT_KEY 0xFCB1 +#define WI_RID_WEP_AVAIL 0xFD4F +#define WI_RID_P2_TX_CRYPT_KEY 0xFC23 +#define WI_RID_P2_CRYPT_KEY0 0xFC24 +#define WI_RID_P2_CRYPT_KEY1 0xFC25 +#define WI_RID_MICROWAVE_OVEN 0xFC25 +#define WI_RID_P2_CRYPT_KEY2 0xFC26 +#define WI_RID_P2_CRYPT_KEY3 0xFC27 +#define WI_RID_P2_ENCRYPTION 0xFC28 +#define WI_RID_ROAMING_MODE 0xFC2D +#define WI_RID_CUR_TX_RATE 0xFD44 /* current TX rate */ + +#define WI_MAX_AID 256 /* max stations for ap operation */ + +struct wi_vap { + struct ieee80211vap wv_vap; + struct ieee80211_beacon_offsets wv_bo; + + void (*wv_recv_mgmt)(struct ieee80211_node *, struct mbuf *, + int, int, int); + int (*wv_newstate)(struct ieee80211vap *, + enum ieee80211_state, int); +}; +#define WI_VAP(vap) ((struct wi_vap *)(vap)) + +struct wi_softc { + struct ifnet *sc_ifp; + device_t sc_dev; + struct mtx sc_mtx; + struct callout sc_watchdog; + int sc_unit; + int wi_gone; + int sc_enabled; + int sc_reset; + int sc_firmware_type; +#define WI_NOTYPE 0 +#define WI_LUCENT 1 +#define WI_INTERSIL 2 +#define WI_SYMBOL 3 + int sc_pri_firmware_ver; /* Primary firmware */ + int sc_sta_firmware_ver; /* Station firmware */ + unsigned int sc_nic_id; /* Type of NIC */ + char * sc_nic_name; + + int wi_bus_type; /* Bus attachment type */ + struct resource * local; + int local_rid; + struct resource * iobase; + int iobase_rid; + struct resource * irq; + int irq_rid; + struct resource * mem; + int mem_rid; + bus_space_handle_t wi_localhandle; + bus_space_tag_t wi_localtag; + bus_space_handle_t wi_bhandle; + bus_space_tag_t wi_btag; + bus_space_handle_t wi_bmemhandle; + bus_space_tag_t wi_bmemtag; + void * wi_intrhand; + struct ieee80211_channel *wi_channel; + int wi_io_addr; + int wi_cmd_count; + + int sc_flags; + int sc_if_flags; + int sc_bap_id; + int sc_bap_off; + + int sc_porttype; + u_int16_t sc_portnum; + u_int16_t sc_encryption; + u_int16_t sc_monitor_port; + + /* RSSI interpretation */ + u_int16_t sc_min_rssi; /* clamp sc_min_rssi < RSSI */ + u_int16_t sc_max_rssi; /* clamp RSSI < sc_max_rssi */ + u_int16_t sc_dbm_offset; /* dBm ~ RSSI - sc_dbm_offset */ + + int sc_buflen; /* TX buffer size */ + int sc_ntxbuf; +#define WI_NTXBUF 3 + struct { + int d_fid; + int d_len; + } sc_txd[WI_NTXBUF]; /* TX buffers */ + int sc_txnext; /* index of next TX */ + int sc_txcur; /* index of current TX*/ + int sc_tx_timer; + + struct wi_counters sc_stats; + u_int16_t sc_ibss_port; + + struct timeval sc_last_syn; + int sc_false_syns; + + u_int16_t sc_txbuf[IEEE80211_MAX_LEN/2]; + + struct wi_tx_radiotap_header sc_tx_th; + struct wi_rx_radiotap_header sc_rx_th; +}; + +/* maximum consecutive false change-of-BSSID indications */ +#define WI_MAX_FALSE_SYNS 10 + +#define WI_FLAGS_HAS_ENHSECURITY 0x0001 +#define WI_FLAGS_HAS_WPASUPPORT 0x0002 +#define WI_FLAGS_HAS_ROAMING 0x0020 +#define WI_FLAGS_HAS_FRAGTHR 0x0200 +#define WI_FLAGS_HAS_DBMADJUST 0x0400 + +struct wi_card_ident { + u_int16_t card_id; + char *card_name; + u_int8_t firm_type; +}; + +#define WI_PRISM_MIN_RSSI 0x1b +#define WI_PRISM_MAX_RSSI 0x9a +#define WI_PRISM_DBM_OFFSET 100 /* XXX */ + +#define WI_LUCENT_MIN_RSSI 47 +#define WI_LUCENT_MAX_RSSI 138 +#define WI_LUCENT_DBM_OFFSET 149 + +#define WI_RSSI_TO_DBM(sc, rssi) (MIN((sc)->sc_max_rssi, \ + MAX((sc)->sc_min_rssi, (rssi))) - (sc)->sc_dbm_offset) + +#define WI_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) +#define WI_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) +#define WI_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) + +int wi_attach(device_t); +int wi_detach(device_t); +int wi_shutdown(device_t); +int wi_alloc(device_t, int); +void wi_free(device_t); +extern devclass_t wi_devclass; +void wi_init(void *); +void wi_intr(void *); +int wi_mgmt_xmit(struct wi_softc *, caddr_t, int); +void wi_stop(struct wi_softc *, int); diff --git a/src/libs/compat/freebsd_network/compat/machine/md_var.h b/src/libs/compat/freebsd_network/compat/machine/md_var.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/libs/compat/freebsd_network/compat/net/bpf.h b/src/libs/compat/freebsd_network/compat/net/bpf.h index 4c9dbd8183..c822dc0664 100644 --- a/src/libs/compat/freebsd_network/compat/net/bpf.h +++ b/src/libs/compat/freebsd_network/compat/net/bpf.h @@ -7,13 +7,20 @@ #define _FBSD_COMPAT_NET_BPF_H_ +#define DLT_EN10MB 1 /* Ethernet (10Mb) */ +#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */ + + struct bpf_if; #define bpf_mtap(bpf_if, mbuf) do { } while (0) #define BPF_MTAP(ifp, m) do { } while (0) -#define bpf_mtap2(bpf_if, data, dlen, mbuf) do { } while (0) -#define bpfattach2(ifnet, dlt, hdrlen, bpf_if) do { } while (0) +#define BPF_TAP(ifp, pkt, pktlen) do { } while (0) +#define bpf_mtap2(bpf_if, data, dlen, mbuf) do { } while (0) +#define bpfattach(ifnet, dlt, hdrlen) do { } while (0); +#define bpfattach2(ifnet, dlt, hdrlen, bpf_if) do { } while (0) +#define bpfdetach(ifnet) do { } while (0); static inline int diff --git a/src/libs/compat/freebsd_network/compat/sys/ctype.h b/src/libs/compat/freebsd_network/compat/sys/ctype.h new file mode 100644 index 0000000000..60cc664acf --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/ctype.h @@ -0,0 +1,11 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_CTYPE_H_ +#define _FBSD_COMPAT_SYS_CTYPE_H_ + + +#define isprint(c) ((c) >= ' ' && (c) <= '~') + +#endif /* _FBSD_COMPAT_SYS_CTYPE_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/param.h b/src/libs/compat/freebsd_network/compat/sys/param.h index 01c9978680..ca29011cc7 100644 --- a/src/libs/compat/freebsd_network/compat/sys/param.h +++ b/src/libs/compat/freebsd_network/compat/sys/param.h @@ -13,6 +13,7 @@ #include #include #include +#include /* The version this compatibility layer is based on */ diff --git a/src/libs/compat/freebsd_network/compat/sys/priority.h b/src/libs/compat/freebsd_network/compat/sys/priority.h new file mode 100644 index 0000000000..61fd7f1b27 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/priority.h @@ -0,0 +1,12 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_PRIORITY_H_ +#define _FBSD_COMPAT_SYS_PRIORITY_H_ + + +#define PRI_MIN_KERN (64) +#define PZERO (PRI_MIN_KERN + 20) + +#endif /* _FBSD_COMPAT_SYS_PRIORITY_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/proc.h b/src/libs/compat/freebsd_network/compat/sys/proc.h index 4521eecba8..6fdab128f6 100644 --- a/src/libs/compat/freebsd_network/compat/sys/proc.h +++ b/src/libs/compat/freebsd_network/compat/sys/proc.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #endif /* _FBSD_COMPAT_SYS_PROC_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/random.h b/src/libs/compat/freebsd_network/compat/sys/random.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/libs/compat/freebsd_network/compat/sys/rman.h b/src/libs/compat/freebsd_network/compat/sys/rman.h index 9ec6c00978..585dc3f88d 100644 --- a/src/libs/compat/freebsd_network/compat/sys/rman.h +++ b/src/libs/compat/freebsd_network/compat/sys/rman.h @@ -25,5 +25,7 @@ struct resource { bus_space_handle_t rman_get_bushandle(struct resource *); bus_space_tag_t rman_get_bustag(struct resource *); +uint32_t rman_make_alignment_flags(uint32_t); +u_long rman_get_start(struct resource *); #endif /* _FBSD_COMPAT_SYS_RMAN_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/sysctl.h b/src/libs/compat/freebsd_network/compat/sys/sysctl.h index 642bf299e8..0eb7ed64cb 100644 --- a/src/libs/compat/freebsd_network/compat/sys/sysctl.h +++ b/src/libs/compat/freebsd_network/compat/sys/sysctl.h @@ -18,7 +18,9 @@ struct sysctl_req { struct sysctl_ctx_list { }; -#define SYSCTL_HANDLER_ARGS void *oidp, void *arg1, void *arg2, struct sysctl_req *req + +#define SYSCTL_HANDLER_ARGS void *oidp, void *arg1, int arg2, \ + struct sysctl_req *req #define OID_AUTO (-1) @@ -46,6 +48,7 @@ struct sysctl_ctx_list { #define CTLFLAG_TUN 0x00080000 /* Tunable variable */ #define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN) + static inline int sysctl_ctx_init(struct sysctl_ctx_list *clist) { @@ -61,11 +64,9 @@ sysctl_ctx_free(struct sysctl_ctx_list *clist) static inline void * -sysctl_add_oid(struct sysctl_ctx_list *clist, - void *parent, int nbr, const char *name, - int kind, void *arg1, int arg2, - int (*handler) (SYSCTL_HANDLER_ARGS), - const char *fmt, const char *descr) +sysctl_add_oid(struct sysctl_ctx_list *clist, void *parent, int nbr, + const char *name, int kind, void *arg1, int arg2, + int (*handler) (SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr) { return NULL; } @@ -83,47 +84,52 @@ static inline int sysctl_handle_string(SYSCTL_HANDLER_ARGS) { return -1; } #define __DESCR(x) "" #define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr)) + sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, \ + __DESCR(descr)) -#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \ +#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \ 0, 0, handler, "N", __DESCR(descr)) -#define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \ +#define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \ arg, len, sysctl_handle_string, "A", __DESCR(descr)) -#define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_INT|(access), \ +#define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_INT|(access), \ ptr, val, sysctl_handle_int, "I", __DESCR(descr)) -#define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \ +#define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \ ptr, val, sysctl_handle_int, "IU", __DESCR(descr)) -#define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_LONG|(access), \ +#define SYSCTL_ADD_XINT(ctx, parent, nbr, name, access, ptr, val, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \ + ptr, val, sysctl_handle_int, "IX", __DESCR(descr)) + +#define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_LONG|(access), \ ptr, 0, sysctl_handle_long, "L", __DESCR(descr)) -#define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|(access), \ +#define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|(access), \ ptr, 0, sysctl_handle_long, "LU", __DESCR(descr)) -#define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_QUAD|(access), \ +#define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_QUAD|(access), \ ptr, 0, sysctl_handle_quad, "Q", __DESCR(descr)) -#define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr)\ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ +#define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr)) -#define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ +#define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ ptr, sizeof(struct type), sysctl_handle_opaque, "S," #type, __DESCR(descr)) #define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, (access), \ - ptr, arg, handler, fmt, __DESCR(descr)) + sysctl_add_oid(ctx, parent, nbr, name, (access), ptr, arg, handler, fmt, \ + __DESCR(descr)) static inline void * @@ -133,9 +139,9 @@ SYSCTL_CHILDREN(void *ptr) } -#define SYSCTL_STATIC_CHILDREN(...) NULL +#define SYSCTL_STATIC_CHILDREN(...) NULL -#define SYSCTL_DECL(name) \ +#define SYSCTL_DECL(name) \ extern struct sysctl_oid_list sysctl_##name##_children #define SYSCTL_NODE(...) diff --git a/src/libs/compat/freebsd_network/compat/sys/syslog.h b/src/libs/compat/freebsd_network/compat/sys/syslog.h new file mode 100644 index 0000000000..f785d64b35 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/syslog.h @@ -0,0 +1,11 @@ +/* + * Copyright 2009 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_SYSLOG_H_ +#define _FBSD_COMPAT_SYS_SYSLOG_H_ + + +#define LOG_ERR 3 /* error conditions */ + +#endif /* _FBSD_COMPAT_SYS_SYSLOG_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/systm.h b/src/libs/compat/freebsd_network/compat/sys/systm.h index da8c405f35..ae97c10211 100644 --- a/src/libs/compat/freebsd_network/compat/sys/systm.h +++ b/src/libs/compat/freebsd_network/compat/sys/systm.h @@ -25,15 +25,15 @@ int printf(const char *format, ...) __printflike(1, 2); #define ovbcopy(f, t, l) bcopy((f), (t), (l)) -#define bootverbose 1 +#define bootverbose 1 -#ifdef INVARIANTS -#define KASSERT(cond,msg) do { \ - if (!(cond)) \ - panic msg; \ +#ifdef INVARIANTS +#define KASSERT(cond,msg) do { \ + if (!(cond)) \ + panic msg; \ } while (0) #else -#define KASSERT(exp,msg) do { \ +#define KASSERT(exp,msg) do { \ } while (0) #endif @@ -47,10 +47,10 @@ int printf(const char *format, ...) __printflike(1, 2); void wakeup(void *); -#ifndef CTASSERT /* Allow lint to override */ -#define CTASSERT(x) _CTASSERT(x, __LINE__) -#define _CTASSERT(x, y) __CTASSERT(x, y) -#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] +#ifndef CTASSERT /* Allow lint to override */ +#define CTASSERT(x) _CTASSERT(x, __LINE__) +#define _CTASSERT(x, y) __CTASSERT(x, y) +#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] #endif @@ -70,11 +70,14 @@ copyout(const void * __restrict kaddr, void * __restrict udaddr, } -int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); +static inline void log(int level, const char *fmt, ...) { } + + +int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); extern int sprintf(char *buf, const char *, ...); extern void driver_vprintf(const char *format, va_list vl); -#define vprintf(fmt, vl) driver_vprintf(fmt, vl) +#define vprintf(fmt, vl) driver_vprintf(fmt, vl) extern int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0); @@ -82,7 +85,7 @@ extern int vsnprintf(char *, size_t, const char *, __va_list) int msleep(void *, struct mtx *, int, const char *, int); int _pause(const char *, int); #define pause(waitMessage, timeout) _pause((waitMessage), (timeout)) -#define tsleep(channel, priority, waitMessage, timeout) \ +#define tsleep(channel, priority, waitMessage, timeout) \ msleep((channel), NULL, (priority), (waitMessage), (timeout)) struct unrhdr;