diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-09-29 21:54:01 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-09-29 21:54:01 +0000 |
commit | b204b83a3c74d221d95053e134503a3153f515a7 (patch) | |
tree | cf5a81e0e520e167284dd3f16ddc321f4d4c6877 | |
parent | c8538de5ad0acdea59ecc5649e0d5297029d7769 (diff) |
if_media support, from freebsd
-rw-r--r-- | sys/dev/ic/an.c | 120 | ||||
-rw-r--r-- | sys/dev/ic/anreg.h | 10 | ||||
-rw-r--r-- | sys/dev/ic/anvar.h | 3 | ||||
-rw-r--r-- | sys/dev/pci/if_an_pci.c | 3 |
4 files changed, 129 insertions, 7 deletions
diff --git a/sys/dev/ic/an.c b/sys/dev/ic/an.c index eaf938f0ee5..764fd6627b6 100644 --- a/sys/dev/ic/an.c +++ b/sys/dev/ic/an.c @@ -1,4 +1,4 @@ -/* $OpenBSD: an.c,v 1.19 2001/07/08 23:38:05 fgsch Exp $ */ +/* $OpenBSD: an.c,v 1.20 2001/09/29 21:54:00 mickey 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. * - * $FreeBSD: src/sys/dev/an/if_an.c,v 1.2 2000/01/16 06:41:49 wpaul Exp $ + * $FreeBSD: src/sys/dev/an/if_an.c,v 1.21 2001/09/10 02:05:09 brooks Exp $ */ /* @@ -162,6 +162,8 @@ void an_setdef __P((struct an_softc *, struct an_req *)); void an_cache_store __P((struct an_softc *, struct ether_header *, struct mbuf *, unsigned short)); #endif +int an_media_change __P((struct ifnet *)); +void an_media_status __P((struct ifnet *, struct ifmediareq *)); static __inline void an_swap16(u_int16_t *p, int cnt) @@ -255,6 +257,31 @@ an_attach(sc) sc->an_sigitems = sc->an_nextitem = 0; #endif + ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status); +#define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL) + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, + IFM_IEEE80211_ADHOC, 0), 0); + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0); + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, + IFM_IEEE80211_ADHOC, 0), 0); + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0); + if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) { + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, + IFM_IEEE80211_ADHOC, 0), 0); + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0); + } + if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) { + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, + IFM_IEEE80211_ADHOC, 0), 0); + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0); + } + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, + IFM_IEEE80211_ADHOC, 0), 0); + ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0); +#undef ADD + ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, + 0, 0)); + /* * Call MI attach routines. */ @@ -583,7 +610,7 @@ an_read_record(sc, ltv) u_int16_t *ptr, len; int i; - if (ltv->an_len == 0 || ltv->an_type == 0) + if (ltv->an_len < 4 || ltv->an_type == 0) return(EINVAL); /* Tell the NIC to enter record read mode. */ @@ -1017,6 +1044,10 @@ an_ioctl(ifp, command, data) 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. */ @@ -1493,3 +1524,86 @@ an_cache_store (sc, eh, m, rx_quality) sc->an_sigcache[cache_slot].signal = rx_quality; } #endif + +int +an_media_change(ifp) + struct ifnet *ifp; +{ + struct an_softc *sc = ifp->if_softc; + int otype = sc->an_config.an_opmode; + int orate = sc->an_tx_rate; + + if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0) + sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC; + else + sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION; + + switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) { + case IFM_IEEE80211_DS1: + sc->an_tx_rate = AN_RATE_1MBPS; + break; + case IFM_IEEE80211_DS2: + sc->an_tx_rate = AN_RATE_2MBPS; + break; + case IFM_IEEE80211_DS5: + sc->an_tx_rate = AN_RATE_5_5MBPS; + break; + case IFM_IEEE80211_DS11: + sc->an_tx_rate = AN_RATE_11MBPS; + break; + case IFM_AUTO: + sc->an_tx_rate = 0; + break; + } + + if (otype != sc->an_config.an_opmode || + orate != sc->an_tx_rate) + an_init(sc); + + return(0); +} + +void +an_media_status(ifp, imr) + struct ifnet *ifp; + struct ifmediareq *imr; +{ + struct an_ltv_status status; + struct an_softc *sc = ifp->if_softc; + + 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; + } + + 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; + switch (status.an_current_tx_rate) { + case AN_RATE_1MBPS: + imr->ifm_active |= IFM_IEEE80211_DS1; + break; + case AN_RATE_2MBPS: + imr->ifm_active |= IFM_IEEE80211_DS2; + break; + case AN_RATE_5_5MBPS: + imr->ifm_active |= IFM_IEEE80211_DS5; + break; + case AN_RATE_11MBPS: + imr->ifm_active |= IFM_IEEE80211_DS11; + break; + } + } else { + imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media; + } + + imr->ifm_status = IFM_AVALID; + if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC) + imr->ifm_status |= IFM_ACTIVE; + else if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED) + imr->ifm_status |= IFM_ACTIVE; +} diff --git a/sys/dev/ic/anreg.h b/sys/dev/ic/anreg.h index 902afd048c2..4560ec017c1 100644 --- a/sys/dev/ic/anreg.h +++ b/sys/dev/ic/anreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: anreg.h,v 1.7 2001/06/25 21:11:17 mickey Exp $ */ +/* $OpenBSD: anreg.h,v 1.8 2001/09/29 21:54:00 mickey 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. * - * $FreeBSD: src/sys/dev/an/if_anreg.h,v 1.1 2000/01/14 20:40:56 wpaul Exp $ + * $FreeBSD: src/sys/dev/an/if_anreg.h,v 1.9 2001/07/27 16:05:21 brooks Exp $ */ #pragma pack(1) @@ -96,6 +96,7 @@ #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 @@ -444,6 +445,9 @@ struct an_snap_hdr { #define AN_TXCNTL_MACPORT 0x00FF #define AN_TXCNTL_STRUCTTYPE 0xFF00 +#define AN_RID_WEP_TEMP 0xFF15 +#define AN_RID_WEP_PERM 0xFF16 + /* * SNAP (sub-network access protocol) constants for transmission * of IP datagrams over IEEE 802 networks, taken from RFC1042. @@ -457,4 +461,6 @@ struct an_snap_hdr { #define AN_SNAP_WORD1 (AN_SNAP_K2 | (AN_SNAP_CONTROL << 8)) #define AN_SNAPHDR_LEN 0x6 + + #pragma pack() diff --git a/sys/dev/ic/anvar.h b/sys/dev/ic/anvar.h index bb77509d03b..f8549a6bc25 100644 --- a/sys/dev/ic/anvar.h +++ b/sys/dev/ic/anvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: anvar.h,v 1.4 2001/06/25 21:11:17 mickey Exp $ */ +/* $OpenBSD: anvar.h,v 1.5 2001/09/29 21:54:00 mickey Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -645,6 +645,7 @@ struct an_tx_ring_data { struct an_softc { struct device sc_dev; struct arpcom arpcom; + struct ifmedia an_ifmedia; void *sc_ih; bus_space_tag_t an_btag; diff --git a/sys/dev/pci/if_an_pci.c b/sys/dev/pci/if_an_pci.c index 712ee051236..fb70b138608 100644 --- a/sys/dev/pci/if_an_pci.c +++ b/sys/dev/pci/if_an_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_an_pci.c,v 1.5 2001/08/25 10:13:29 art Exp $ */ +/* $OpenBSD: if_an_pci.c,v 1.6 2001/09/29 21:54:00 mickey Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -62,6 +62,7 @@ #include <net/if.h> #include <net/if_dl.h> +#include <net/if_media.h> #include <netinet/in.h> #include <netinet/if_ether.h> |