bring over WEP mode from FreeBSD/OpenBSD

This commit is contained in:
explorer 2000-02-04 07:48:29 +00:00
parent 6bfa70b9c6
commit 59db45db2a
4 changed files with 93 additions and 42 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_wi.c,v 1.3 1999/09/10 00:30:59 itojun Exp $ */
/* $NetBSD: if_wi.c,v 1.4 2000/02/04 07:48:29 explorer Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@ -31,7 +31,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_wi.c,v 1.3 1999/09/10 00:30:59 itojun Exp $
* $Id: if_wi.c,v 1.4 2000/02/04 07:48:29 explorer Exp $
*/
/*
@ -84,6 +84,7 @@
#include <sys/mbuf.h>
#include <sys/ioctl.h>
#include <sys/kernel.h> /* for hz */
#include <sys/proc.h>
#include <net/if.h>
#include <net/if_dl.h>
@ -109,13 +110,12 @@
#include <dev/pcmcia/pcmciavar.h>
#include <dev/pcmcia/pcmciadevs.h>
#include <dev/pcmcia/if_wivar.h>
#include <dev/pcmcia/if_wi_ieee.h>
#include <dev/pcmcia/if_wivar.h>
#if !defined(lint)
static const char rcsid[] =
"$Id: if_wi.c,v 1.3 1999/09/10 00:30:59 itojun Exp $";
"$Id: if_wi.c,v 1.4 2000/02/04 07:48:29 explorer Exp $";
#endif
#ifdef foo
@ -314,6 +314,14 @@ wi_attach(parent, self, aux)
bzero((char *)&sc->wi_stats, sizeof(sc->wi_stats));
/*
* Find out if we support WEP on this card.
*/
gen.wi_type = WI_RID_WEP_AVAIL;
gen.wi_len = 2;
wi_read_record(sc, &gen);
sc->wi_has_wep = gen.wi_val;
wi_init(sc);
wi_stop(sc);
@ -877,6 +885,12 @@ static void wi_setmulti(sc)
bzero((char *)&mcast, sizeof(mcast));
break;
}
#if 0
/* Punt on ranges. */
if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
sizeof(enm->enm_addrlo)) != 0)
break;
#endif
bcopy(enm->enm_addrlo,
(char *)&mcast.wi_mcast[i], ETHER_ADDR_LEN);
i++;
@ -944,6 +958,16 @@ static void wi_setdef(sc, wreq)
case WI_RID_MAX_SLEEP:
sc->wi_max_sleep = wreq->wi_val[0];
break;
case WI_RID_ENCRYPTION:
sc->wi_use_wep = wreq->wi_val[0];
break;
case WI_RID_TX_CRYPT_KEY:
sc->wi_tx_key = wreq->wi_val[0];
break;
case WI_RID_DEFLT_CRYPT_KEYS:
bcopy((char *)wreq, (char *)&sc->wi_keys,
sizeof(struct wi_ltv_keys));
break;
default:
break;
}
@ -963,6 +987,7 @@ static int wi_ioctl(ifp, command, data)
struct wi_softc *sc;
struct wi_req wreq;
struct ifreq *ifr;
struct proc *p = curproc;
struct ifaddr *ifa = (struct ifaddr *)data;
s = splimp();
@ -1040,6 +1065,14 @@ static int wi_ioctl(ifp, command, data)
bcopy((char *)&sc->wi_stats, (char *)&wreq.wi_val,
sizeof(sc->wi_stats));
wreq.wi_len = (sizeof(sc->wi_stats) / 2) + 1;
} else if (wreq.wi_type == WI_RID_DEFLT_CRYPT_KEYS) {
/* For non-root user, return all-zeroes keys */
if (suser(p->p_ucred, &p->p_acflag))
bzero((char *)&wreq,
sizeof(struct wi_ltv_keys));
else
bcopy((char *)&sc->wi_keys, (char *)&wreq,
sizeof(struct wi_ltv_keys));
} else {
if (wi_read_record(sc, (struct wi_ltv_gen *)&wreq)) {
error = EINVAL;
@ -1049,6 +1082,9 @@ static int wi_ioctl(ifp, command, data)
error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
break;
case SIOCSWAVELAN:
error = suser(p->p_ucred, &p->p_acflag);
if (error)
break;
error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
if (error)
break;
@ -1137,6 +1173,15 @@ static void wi_init(xsc)
memcpy(&mac.wi_mac_addr, sc->sc_macaddr, ETHER_ADDR_LEN);
wi_write_record(sc, (struct wi_ltv_gen *)&mac);
/* Configure WEP. */
if (sc->wi_has_wep) {
WI_SETVAL(WI_RID_ENCRYPTION, sc->wi_use_wep);
WI_SETVAL(WI_RID_TX_CRYPT_KEY, sc->wi_tx_key);
sc->wi_keys.wi_len = (sizeof(struct wi_ltv_keys) / 2) + 1;
sc->wi_keys.wi_type = WI_RID_DEFLT_CRYPT_KEYS;
wi_write_record(sc, (struct wi_ltv_gen *)&sc->wi_keys);
}
/* Initialize promisc mode. */
if (ifp->if_flags & IFF_PROMISC) {
WI_SETVAL(WI_RID_PROMISC, 1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_wi_ieee.h,v 1.3 2000/02/01 08:43:25 enami Exp $ */
/* $NetBSD: if_wi_ieee.h,v 1.4 2000/02/04 07:48:29 explorer Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@ -42,6 +42,8 @@
* Oslo IETF plenary meeting.
* The stuff in here should probably go into a generic extension to the
* ifmedia goop.
*
* Michael Graff brought over the encryption bits.
*/
/*
@ -162,7 +164,6 @@ struct wi_sigcache {
};
#endif
#ifndef _KERNEL
struct wi_counters {
u_int32_t wi_tx_unicast_frames;
u_int32_t wi_tx_multicast_frames;
@ -227,6 +228,8 @@ struct wi_counters {
#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 */
/*
* Network parameters, dynamic configuration entities
@ -258,8 +261,21 @@ struct wi_counters {
#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];
};
struct wi_ltv_keys {
u_int16_t wi_len;
u_int16_t wi_type;
struct wi_key wi_keys[4];
};
/*
* NIC information
*/
@ -317,7 +333,5 @@ struct wi_counters {
#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 */
#endif
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_wireg.h,v 1.4 2000/02/04 06:22:52 explorer Exp $ */
/* $NetBSD: if_wireg.h,v 1.5 2000/02/04 07:48:29 explorer Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@ -31,7 +31,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_wireg.h,v 1.4 2000/02/04 06:22:52 explorer Exp $
* $Id: if_wireg.h,v 1.5 2000/02/04 07:48:29 explorer Exp $
*/
/*
@ -74,9 +74,19 @@
#define WI_DEFAULT_MAX_SLEEP 100
#define WI_DEFAULT_NODENAME "NetBSD WaveLAN/IEEE node"
#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_IBSS "NetBSD IBSS"
#define WI_DEFAULT_NODENAME OS_STRING_NAME " WaveLAN/IEEE node"
#define WI_DEFAULT_IBSS OS_STRING_NAME " IBSS"
#define WI_DEFAULT_CHAN 3
@ -501,9 +511,11 @@ struct wi_ltv_mcast {
*/
struct wi_frame {
u_int16_t wi_status; /* 0x00 */
u_int32_t wi_rsvd0; /* 0x02 */
u_int16_t wi_rsvd0; /* 0x02 */
u_int16_t wi_rsvd1; /* 0x04 */
u_int16_t wi_q_info; /* 0x06 */
u_int16_t wi_rsvd1; /* 0x08 */
u_int16_t wi_rsvd2; /* 0x08 */
u_int16_t wi_rsvd3; /* 0x0A */
u_int16_t wi_tx_ctl; /* 0x0C */
u_int16_t wi_frame_ctl; /* 0x0E */
u_int16_t wi_id; /* 0x10 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_wivar.h,v 1.2 1999/07/14 23:07:29 sommerfeld Exp $ */
/* $NetBSD: if_wivar.h,v 1.3 2000/02/04 07:48:29 explorer Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@ -31,7 +31,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_wivar.h,v 1.2 1999/07/14 23:07:29 sommerfeld Exp $
* $Id: if_wivar.h,v 1.3 2000/02/04 07:48:29 explorer Exp $
*/
@ -40,30 +40,6 @@
* Oslo IETF plenary meeting.
*/
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;
};
struct wi_softc {
struct device sc_dev;
struct ethercom sc_ethercom;
@ -97,6 +73,10 @@ struct wi_softc {
char wi_node_name[32];
char wi_net_name[32];
char wi_ibss_name[32];
u_int8_t wi_txbuf[1536];
u_int8_t wi_txbuf[1596];
int wi_has_wep;
int wi_use_wep;
int wi_tx_key;
struct wi_ltv_keys wi_keys;
struct wi_counters wi_stats;
};