if_an.c (110104) | if_an.c (110253) |
---|---|
1/* 2 * Copyright (c) 1997, 1998, 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 * | 1/* 2 * Copyright (c) 1997, 1998, 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 * |
32 * $FreeBSD: head/sys/dev/an/if_an.c 110104 2003-01-30 15:01:17Z ambrisko $ | 32 * $FreeBSD: head/sys/dev/an/if_an.c 110253 2003-02-02 22:49:31Z ambrisko $ |
33 */ 34 35/* 36 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD. 37 * 38 * Written by Bill Paul <wpaul@ctr.columbia.edu> 39 * Electrical Engineering Department 40 * Columbia University, New York City --- 88 unchanged lines hidden (view full) --- 129 130#include <machine/md_var.h> 131 132#include <dev/an/if_aironet_ieee.h> 133#include <dev/an/if_anreg.h> 134 135#if !defined(lint) 136static const char rcsid[] = | 33 */ 34 35/* 36 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD. 37 * 38 * Written by Bill Paul <wpaul@ctr.columbia.edu> 39 * Electrical Engineering Department 40 * Columbia University, New York City --- 88 unchanged lines hidden (view full) --- 129 130#include <machine/md_var.h> 131 132#include <dev/an/if_aironet_ieee.h> 133#include <dev/an/if_anreg.h> 134 135#if !defined(lint) 136static const char rcsid[] = |
137 "$FreeBSD: head/sys/dev/an/if_an.c 110104 2003-01-30 15:01:17Z ambrisko $"; | 137 "$FreeBSD: head/sys/dev/an/if_an.c 110253 2003-02-02 22:49:31Z ambrisko $"; |
138#endif 139 140/* These are global because we need them in sys/pci/if_an_p.c. */ 141static void an_reset (struct an_softc *); 142static int an_init_mpi350_desc (struct an_softc *); 143static int an_ioctl (struct ifnet *, u_long, caddr_t); 144static void an_init (void *); 145static int an_init_tx_ring (struct an_softc *); --- 523 unchanged lines hidden (view full) --- 669int 670an_attach(sc, unit, flags) 671 struct an_softc *sc; 672 int unit; 673 int flags; 674{ 675 struct ifnet *ifp = &sc->arpcom.ac_if; 676 int error; | 138#endif 139 140/* These are global because we need them in sys/pci/if_an_p.c. */ 141static void an_reset (struct an_softc *); 142static int an_init_mpi350_desc (struct an_softc *); 143static int an_ioctl (struct ifnet *, u_long, caddr_t); 144static void an_init (void *); 145static int an_init_tx_ring (struct an_softc *); --- 523 unchanged lines hidden (view full) --- 669int 670an_attach(sc, unit, flags) 671 struct an_softc *sc; 672 int unit; 673 int flags; 674{ 675 struct ifnet *ifp = &sc->arpcom.ac_if; 676 int error; |
677 int i, nrate, mword; 678 u_int8_t r; |
|
677 678 mtx_init(&sc->an_mtx, device_get_nameunit(sc->an_dev), MTX_NETWORK_LOCK, 679 MTX_DEF | MTX_RECURSE); 680 AN_LOCK(sc); 681 682 sc->an_gone = 0; 683 sc->an_associated = 0; 684 sc->an_monitor = 0; --- 102 unchanged lines hidden (view full) --- 787 sc->an_ssidlist.an_ssid1_len = strlen(AN_DEFAULT_NETNAME); 788 789 sc->an_config.an_opmode = 790 AN_OPMODE_INFRASTRUCTURE_STATION; 791 792 sc->an_tx_rate = 0; 793 bzero((char *)&sc->an_stats, sizeof(sc->an_stats)); 794 | 679 680 mtx_init(&sc->an_mtx, device_get_nameunit(sc->an_dev), MTX_NETWORK_LOCK, 681 MTX_DEF | MTX_RECURSE); 682 AN_LOCK(sc); 683 684 sc->an_gone = 0; 685 sc->an_associated = 0; 686 sc->an_monitor = 0; --- 102 unchanged lines hidden (view full) --- 789 sc->an_ssidlist.an_ssid1_len = strlen(AN_DEFAULT_NETNAME); 790 791 sc->an_config.an_opmode = 792 AN_OPMODE_INFRASTRUCTURE_STATION; 793 794 sc->an_tx_rate = 0; 795 bzero((char *)&sc->an_stats, sizeof(sc->an_stats)); 796 |
797 nrate = 8; 798 |
|
795 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status); | 799 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status); |
796#define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL) 797 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 798 IFM_IEEE80211_ADHOC, 0), 0); 799 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0); 800 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 801 IFM_IEEE80211_ADHOC, 0), 0); 802 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0); 803 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) { 804 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 805 IFM_IEEE80211_ADHOC, 0), 0); 806 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0); | 800 if_printf(ifp, "supported rates: "); 801#define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \ 802 IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL) 803 ADD(IFM_AUTO, 0); 804 ADD(IFM_AUTO, IFM_IEEE80211_ADHOC); 805 for (i = 0; i < nrate; i++) { 806 r = sc->an_caps.an_rates[i]; 807 mword = ieee80211_rate2media(r, IEEE80211_T_DS); 808 if (mword == 0) 809 continue; 810 printf("%s%d%sMbps", (i != 0 ? " " : ""), 811 (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : "")); 812 ADD(mword, 0); 813 ADD(mword, IFM_IEEE80211_ADHOC); |
807 } | 814 } |
808 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) { 809 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 810 IFM_IEEE80211_ADHOC, 0), 0); 811 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0); 812 } 813 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 814 IFM_IEEE80211_ADHOC, 0), 0); 815 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0); 816#undef ADD 817 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 818 0, 0)); | 815 printf("\n"); 816 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, 817 IFM_AUTO, 0, 0)); 818#undef ADD |
819 820 /* 821 * Call MI attach routine. 822 */ 823 ether_ifattach(ifp, sc->arpcom.ac_enaddr); 824 callout_handle_init(&sc->an_stat_ch); 825 AN_UNLOCK(sc); 826 --- 157 unchanged lines hidden (view full) --- 984 ifp->if_ierrors++; 985 return; 986 } 987 ifp->if_ipackets++; 988 989 /* Receive packet. */ 990#ifdef ANCACHE 991 an_cache_store(sc, eh, m, | 819 820 /* 821 * Call MI attach routine. 822 */ 823 ether_ifattach(ifp, sc->arpcom.ac_enaddr); 824 callout_handle_init(&sc->an_stat_ch); 825 AN_UNLOCK(sc); 826 --- 157 unchanged lines hidden (view full) --- 984 ifp->if_ierrors++; 985 return; 986 } 987 ifp->if_ipackets++; 988 989 /* Receive packet. */ 990#ifdef ANCACHE 991 an_cache_store(sc, eh, m, |
992 rx_frame.an_rx_signal_strength, 993 rx_frame.an_rsvd0); | 992 rx_frame.an_rx_signal_strength, 993 rx_frame.an_rsvd0); |
994#endif 995 (*ifp->if_input)(ifp, m); 996 } 997 998 } else { /* MPI-350 */ 999 for (count = 0; count < AN_MAX_RX_DESC; count++){ 1000 for (i = 0; i < sizeof(an_rx_desc) / 4; i++) 1001 ((u_int32_t*)&an_rx_desc)[i] --- 49 unchanged lines hidden (view full) --- 1051 m->m_pkthdr.len); 1052 1053 ifp->if_ipackets++; 1054 1055 /* Receive packet. */ 1056#if 0 1057#ifdef ANCACHE 1058 an_cache_store(sc, eh, m, | 994#endif 995 (*ifp->if_input)(ifp, m); 996 } 997 998 } else { /* MPI-350 */ 999 for (count = 0; count < AN_MAX_RX_DESC; count++){ 1000 for (i = 0; i < sizeof(an_rx_desc) / 4; i++) 1001 ((u_int32_t*)&an_rx_desc)[i] --- 49 unchanged lines hidden (view full) --- 1051 m->m_pkthdr.len); 1052 1053 ifp->if_ipackets++; 1054 1055 /* Receive packet. */ 1056#if 0 1057#ifdef ANCACHE 1058 an_cache_store(sc, eh, m, |
1059 rx_frame.an_rx_signal_strength, 1060 rx_frame.an_rsvd0); | 1059 rx_frame.an_rx_signal_strength, 1060 rx_frame.an_rsvd0); |
1061#endif 1062#endif 1063 (*ifp->if_input)(ifp, m); 1064 1065 an_rx_desc.an_valid = 1; 1066 an_rx_desc.an_len = AN_RX_BUFFER_SIZE; 1067 an_rx_desc.an_done = 0; 1068 an_rx_desc.an_phys = --- 722 unchanged lines hidden (view full) --- 1791 case AN_RID_APLIST: 1792 ap = (struct an_ltv_aplist *)areq; 1793 bcopy((char *)ap, (char *)&sc->an_aplist, 1794 sizeof(struct an_ltv_aplist)); 1795 break; 1796 case AN_RID_TX_SPEED: 1797 sp = (struct an_ltv_gen *)areq; 1798 sc->an_tx_rate = sp->an_val; | 1061#endif 1062#endif 1063 (*ifp->if_input)(ifp, m); 1064 1065 an_rx_desc.an_valid = 1; 1066 an_rx_desc.an_len = AN_RX_BUFFER_SIZE; 1067 an_rx_desc.an_done = 0; 1068 an_rx_desc.an_phys = --- 722 unchanged lines hidden (view full) --- 1791 case AN_RID_APLIST: 1792 ap = (struct an_ltv_aplist *)areq; 1793 bcopy((char *)ap, (char *)&sc->an_aplist, 1794 sizeof(struct an_ltv_aplist)); 1795 break; 1796 case AN_RID_TX_SPEED: 1797 sp = (struct an_ltv_gen *)areq; 1798 sc->an_tx_rate = sp->an_val; |
1799 1800 /* Read the current configuration */ 1801 sc->an_config.an_type = AN_RID_GENCONFIG; 1802 sc->an_config.an_len = sizeof(struct an_ltv_genconfig); 1803 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config); 1804 cfg = &sc->an_config; 1805 1806 /* clear other rates and set the only one we want */ 1807 bzero(cfg->an_rates, sizeof(cfg->an_rates)); 1808 cfg->an_rates[0] = sc->an_tx_rate; 1809 1810 /* Save the new rate */ 1811 sc->an_config.an_type = AN_RID_GENCONFIG; 1812 sc->an_config.an_len = sizeof(struct an_ltv_genconfig); |
|
1799 break; 1800 case AN_RID_WEP_TEMP: 1801 case AN_RID_WEP_PERM: 1802 case AN_RID_LEAPUSERNAME: 1803 case AN_RID_LEAPPASSWORD: 1804 /* Disable the MAC. */ 1805 an_cmd(sc, AN_CMD_DISABLE, 0); 1806 --- 1226 unchanged lines hidden (view full) --- 3033} 3034#endif 3035 3036static int 3037an_media_change(ifp) 3038 struct ifnet *ifp; 3039{ 3040 struct an_softc *sc = ifp->if_softc; | 1813 break; 1814 case AN_RID_WEP_TEMP: 1815 case AN_RID_WEP_PERM: 1816 case AN_RID_LEAPUSERNAME: 1817 case AN_RID_LEAPPASSWORD: 1818 /* Disable the MAC. */ 1819 an_cmd(sc, AN_CMD_DISABLE, 0); 1820 --- 1226 unchanged lines hidden (view full) --- 3047} 3048#endif 3049 3050static int 3051an_media_change(ifp) 3052 struct ifnet *ifp; 3053{ 3054 struct an_softc *sc = ifp->if_softc; |
3055 struct an_ltv_genconfig *cfg; |
|
3041 int otype = sc->an_config.an_opmode; 3042 int orate = sc->an_tx_rate; 3043 3044 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0) 3045 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC; 3046 else 3047 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION; 3048 | 3056 int otype = sc->an_config.an_opmode; 3057 int orate = sc->an_tx_rate; 3058 3059 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0) 3060 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC; 3061 else 3062 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION; 3063 |
3049 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) { 3050 case IFM_IEEE80211_DS1: 3051 sc->an_tx_rate = AN_RATE_1MBPS; 3052 break; 3053 case IFM_IEEE80211_DS2: 3054 sc->an_tx_rate = AN_RATE_2MBPS; 3055 break; 3056 case IFM_IEEE80211_DS5: 3057 sc->an_tx_rate = AN_RATE_5_5MBPS; 3058 break; 3059 case IFM_IEEE80211_DS11: 3060 sc->an_tx_rate = AN_RATE_11MBPS; 3061 break; 3062 case IFM_AUTO: 3063 sc->an_tx_rate = 0; 3064 break; | 3064 sc->an_tx_rate = 3065 ieee80211_media2rate( 3066 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media), 3067 IEEE80211_T_DS); 3068 3069 if (orate != sc->an_tx_rate) { 3070 /* Read the current configuration */ 3071 sc->an_config.an_type = AN_RID_GENCONFIG; 3072 sc->an_config.an_len = sizeof(struct an_ltv_genconfig); 3073 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config); 3074 cfg = &sc->an_config; 3075 3076 /* clear other rates and set the only one we want */ 3077 bzero(cfg->an_rates, sizeof(cfg->an_rates)); 3078 cfg->an_rates[0] = sc->an_tx_rate; 3079 3080 /* Save the new rate */ 3081 sc->an_config.an_type = AN_RID_GENCONFIG; 3082 sc->an_config.an_len = sizeof(struct an_ltv_genconfig); |
3065 } 3066 | 3083 } 3084 |
3067 if (otype != sc->an_config.an_opmode || 3068 orate != sc->an_tx_rate) | 3085 if (otype != sc->an_config.an_opmode 3086 || orate != sc->an_tx_rate) |
3069 an_init(sc); 3070 3071 return(0); 3072} 3073 3074static void 3075an_media_status(ifp, imr) 3076 struct ifnet *ifp; 3077 struct ifmediareq *imr; 3078{ 3079 struct an_ltv_status status; 3080 struct an_softc *sc = ifp->if_softc; 3081 | 3087 an_init(sc); 3088 3089 return(0); 3090} 3091 3092static void 3093an_media_status(ifp, imr) 3094 struct ifnet *ifp; 3095 struct ifmediareq *imr; 3096{ 3097 struct an_ltv_status status; 3098 struct an_softc *sc = ifp->if_softc; 3099 |
3100 imr->ifm_active = IFM_IEEE80211; 3101 |
|
3082 status.an_len = sizeof(status); 3083 status.an_type = AN_RID_STATUS; 3084 if (an_read_record(sc, (struct an_ltv_gen *)&status)) { 3085 /* If the status read fails, just lie. */ 3086 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media; 3087 imr->ifm_status = IFM_AVALID|IFM_ACTIVE; 3088 } 3089 3090 if (sc->an_tx_rate == 0) { 3091 imr->ifm_active = IFM_IEEE80211|IFM_AUTO; | 3102 status.an_len = sizeof(status); 3103 status.an_type = AN_RID_STATUS; 3104 if (an_read_record(sc, (struct an_ltv_gen *)&status)) { 3105 /* If the status read fails, just lie. */ 3106 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media; 3107 imr->ifm_status = IFM_AVALID|IFM_ACTIVE; 3108 } 3109 3110 if (sc->an_tx_rate == 0) { 3111 imr->ifm_active = IFM_IEEE80211|IFM_AUTO; |
3092 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC) 3093 imr->ifm_active |= IFM_IEEE80211_ADHOC; 3094 switch (status.an_current_tx_rate) { 3095 case AN_RATE_1MBPS: 3096 imr->ifm_active |= IFM_IEEE80211_DS1; 3097 break; 3098 case AN_RATE_2MBPS: 3099 imr->ifm_active |= IFM_IEEE80211_DS2; 3100 break; 3101 case AN_RATE_5_5MBPS: 3102 imr->ifm_active |= IFM_IEEE80211_DS5; 3103 break; 3104 case AN_RATE_11MBPS: 3105 imr->ifm_active |= IFM_IEEE80211_DS11; 3106 break; 3107 } 3108 } else { 3109 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media; | |
3110 } 3111 | 3112 } 3113 |
3114 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC) 3115 imr->ifm_active |= IFM_IEEE80211_ADHOC; 3116 imr->ifm_active |= ieee80211_rate2media(status.an_current_tx_rate, 3117 IEEE80211_T_DS); |
|
3112 imr->ifm_status = IFM_AVALID; 3113 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED) 3114 imr->ifm_status |= IFM_ACTIVE; 3115} 3116 3117/********************** Cisco utility support routines *************/ 3118 3119/* --- 513 unchanged lines hidden --- | 3118 imr->ifm_status = IFM_AVALID; 3119 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED) 3120 imr->ifm_status |= IFM_ACTIVE; 3121} 3122 3123/********************** Cisco utility support routines *************/ 3124 3125/* --- 513 unchanged lines hidden --- |