Changeset 4

Show
Ignore:
Timestamp:
03/15/03 19:30:16 (7 years ago)
Author:
sam
Message:

Replicated Change 22 by sam@borg_greg on 2003/02/19 16:13:27<<<

code compiles and module loads

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cvs-import/trunk/wlan/if_ieee80211.h

    r3 r4  
    3838#define _NET_IF_IEEE80211_H_ 
    3939 
    40 #include <net/ethernet.h> 
    41 #include <net/if_arp.h> 
    42  
    43 /* XXX */ 
    44 typedef struct sk_buff os_buf_t; 
    45 typedef struct netdevice os_ifnet_t; 
    46  
    47 #define IEEE80211_ADDR_LEN                      ETHER_ADDR_LEN 
     40#include <sys/queue.h> 
     41 
     42/* 
     43 * BSD portability stuff. 
     44 */ 
     45#ifndef NBBY 
     46#define NBBY    8                       /* number of bits/byte */ 
     47#endif 
     48#ifndef roundup 
     49#define roundup(x, y)   ((((x)+((y)-1))/(y))*(y))  /* to any y */ 
     50#endif 
     51 
     52#define IEEE80211_ADDR_LEN                      6 
    4853 
    4954/* 
     
    290295 */ 
    291296 
     297#ifndef SIOCSIFGENERIC 
     298#define SIOCSIFGENERIC   _IOW('i', 57, struct ifreq)    /* generic IF set op */ 
     299#endif 
     300#ifndef SIOCGIFGENERIC 
     301#define SIOCGIFGENERIC  _IOWR('i', 58, struct ifreq)    /* generic IF get op */ 
     302#endif 
     303 
    292304/* nwid is pointed at by ifr.ifr_data */ 
    293305struct ieee80211_nwid { 
     
    402414#define IEEE80211_IOC_POWERSAVESLEEP    11 
    403415 
    404 #ifdef _KERNEL 
     416#ifdef __KERNEL__ 
    405417 
    406418#define IEEE80211_ASCAN_WAIT    2               /* active scan wait */ 
     
    500512 
    501513struct ieee80211com { 
    502 #ifdef __NetBSD__ 
    503         struct ethercom         ic_ec; 
    504 #endif 
    505 #ifdef __FreeBSD__ 
    506         struct arpcom           ic_ac; 
    507         struct mtx              ic_mtx; 
    508 #endif 
     514        struct net_device       ic_dev;         /* NB: this must be first */ 
     515        int                     ic_timer;       /* equivalent of if_timer */ 
     516        void                    (*ic_watchdog)(struct net_device *); 
     517        void                    (*ic_start)(struct net_device *); 
    509518        void                    (*ic_recv_mgmt[16])(struct ieee80211com *, 
    510                                     os_buf_t *, int, u_int32_t); 
     519                                    struct sk_buff *, int, u_int32_t); 
     520        spinlock_t              ic_lock; 
     521        struct net_device_stats ic_stats;       /* interface statistics */ 
     522        u_int32_t               msg_enable;     /* interface message flags */ 
    511523        int                     (*ic_send_mgmt[16])(struct ieee80211com *, 
    512524                                    struct ieee80211_node *, int, int); 
     
    517529        u_char                  ic_chan_avail[roundup(IEEE80211_CHAN_MAX,NBBY)]; 
    518530        u_char                  ic_chan_active[roundup(IEEE80211_CHAN_MAX, NBBY)]; 
    519 #ifdef notdef 
    520         struct ifqueue          ic_mgtq; 
    521 #endif 
     531        struct sk_buff_head     ic_mgtq; 
    522532        int                     ic_flags; 
    523533        enum ieee80211_phytype  ic_phytype; 
     
    546556        u_int32_t               ic_iv;          /* initial vector for wep */ 
    547557}; 
    548 #ifdef __NetBSD__ 
    549 #define ic_if           ic_ec.ec_if 
    550 #define IEEE80211_LOCK(_ic)     do { s = splnet(); } while (0) 
    551 #define IEEE80211_UNLOCK(_ic)   splx(s) 
    552 #endif 
    553 #ifdef __FreeBSD__ 
    554 #define ic_if           ic_ac.ac_if 
    555 #define IEEE80211_LOCK(_ic)     mtx_lock(&(_ic)->ic_mtx) 
    556 #define IEEE80211_UNLOCK(_ic)   mtx_unlock(&(_ic)->ic_mtx) 
    557 #endif 
    558 #define ic_softc        ic_if.if_softc 
     558#define IEEE80211_LOCK(_ic)     spin_lock(&(_ic)->ic_lock) 
     559#define IEEE80211_UNLOCK(_ic)   spin_unlock(&(_ic)->ic_lock) 
    559560 
    560561#define IEEE80211_SEND_MGMT(ic,ni,type,arg)     do {                          \ 
     
    589590#define IEEE80211_F_DODEL       0x00000008      /* delete ignore rate */ 
    590591 
    591 void    ieee80211_ifattach(os_ifnet_t *); 
    592 void    ieee80211_ifdetach(os_ifnet_t *); 
    593 void    ieee80211_input(os_ifnet_t *, os_buf_t *, int, u_int32_t); 
    594 int     ieee80211_mgmt_output(os_ifnet_t *, struct ieee80211_node *, 
    595     os_buf_t *, int); 
    596 os_buf_t *ieee80211_encap(os_ifnet_t *, os_buf_t *); 
    597 os_buf_t *ieee80211_decap(os_ifnet_t *, os_buf_t *); 
    598 int     ieee80211_ioctl(os_ifnet_t *, u_long, caddr_t); 
     592/* private extensions to netdevice.h's netif_msg* mechanism */ 
     593#define NETIF_MSG_DEBUG         0x80000000      /* enable debugging msgs */ 
     594#define netif_msg_debug(p)      ((p)->msg_enable & NETIF_MSG_DEBUG) 
     595 
     596int     ieee80211_ifattach(struct net_device *); 
     597void    ieee80211_ifdetach(struct net_device *); 
     598void    ieee80211_input(struct net_device *, struct sk_buff *, int, u_int32_t); 
     599int     ieee80211_mgmt_output(struct net_device *, struct ieee80211_node *, 
     600    struct sk_buff *, int); 
     601struct sk_buff *ieee80211_encap(struct net_device *, struct sk_buff *); 
     602struct sk_buff *ieee80211_decap(struct net_device *, struct sk_buff *); 
     603int     ieee80211_ioctl(struct net_device *, u_long, caddr_t); 
    599604void    ieee80211_print_essid(u_int8_t *, int); 
    600605void    ieee80211_dump_pkt(u_int8_t *, int, int, int); 
    601 void    ieee80211_watchdog(os_ifnet_t *); 
    602 void    ieee80211_next_scan(os_ifnet_t *); 
    603 void    ieee80211_end_scan(os_ifnet_t *); 
     606void    ieee80211_watchdog(struct net_device *); 
     607void    ieee80211_next_scan(struct net_device *); 
     608void    ieee80211_end_scan(struct net_device *); 
    604609struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *, u_int8_t *, 
    605610    int); 
     
    608613void    ieee80211_free_allnodes(struct ieee80211com *); 
    609614int     ieee80211_fix_rate(struct ieee80211com *, struct ieee80211_node *, int); 
    610 int     ieee80211_new_state(os_ifnet_t *, enum ieee80211_state, int); 
    611 os_buf_t *ieee80211_wep_crypt(os_ifnet_t *, os_buf_t *, int); 
     615int     ieee80211_new_state(struct net_device *, enum ieee80211_state, int); 
     616struct sk_buff *ieee80211_wep_crypt(struct net_device *, struct sk_buff *, int); 
    612617int     ieee80211_rate2media(int, enum ieee80211_phytype); 
    613618int     ieee80211_media2rate(int, enum ieee80211_phytype); 
    614619 
    615 int     ieee80211_cfgget(os_ifnet_t *, u_long, caddr_t); 
    616 int     ieee80211_cfgset(os_ifnet_t *, u_long, caddr_t); 
    617  
    618 #endif /* _KERNEL */ 
     620int     ieee80211_cfgget(struct net_device *, u_long, caddr_t); 
     621int     ieee80211_cfgset(struct net_device *, u_long, caddr_t); 
     622 
     623#endif /* __KERNEL__ */ 
    619624 
    620625#endif /* _NET_IF_IEEE80211_H_ */ 
  • cvs-import/trunk/wlan/if_ieee80211subr.c

    r3 r4  
    4242 */ 
    4343 
    44 #include <sys/cdefs.h> 
    45  
    46 #include "opt_inet.h" 
    47 #define NBPFILTER       1 
    48  
    49 #include <sys/param.h> 
    50 #include <sys/systm.h>  
    51 #include <sys/mbuf.h>    
    52 #include <sys/malloc.h> 
    53 #include <sys/kernel.h> 
    54 #include <sys/socket.h> 
    55 #include <sys/sockio.h> 
    56 #include <sys/endian.h> 
    57 #include <sys/errno.h> 
    58 #include <sys/bus.h> 
    59 #include <sys/proc.h> 
    60 #include <sys/sysctl.h> 
    61  
    62 #include <crypto/rc4/rc4.h> 
     44#ifndef EXPORT_SYMTAB 
     45#define EXPORT_SYMTAB 
     46#endif 
     47 
     48#include <linux/config.h> 
     49#include <linux/version.h> 
     50#include <linux/module.h> 
     51#include <linux/init.h> 
     52#include <linux/skbuff.h> 
     53#include <linux/netdevice.h> 
     54#include <linux/utsname.h> 
     55#include <linux/random.h> 
     56 
     57#include <asm/uaccess.h> 
     58 
     59#include "rc4.h" 
    6360#define arc4_ctxlen()                   sizeof (struct rc4_state) 
    6461#define arc4_setkey(_c,_k,_l)           rc4_init(_c,_k,_l) 
    6562#define arc4_encrypt(_c,_d,_s,_l)       rc4_crypt(_c,_s,_d,_l) 
    66   
    67 #include <net/if.h> 
    68 #include <net/if_dl.h> 
    69 #include <net/if_media.h> 
    70 #include <net/ethernet.h> 
    71 #include <net/if_llc.h> 
    72 #include <net/if_ieee80211.h> 
    73  
    74 #if NBPFILTER > 0  
    75 #include <net/bpf.h> 
    76 #endif  
    77  
    78 #ifdef INET 
    79 #include <netinet/in.h>  
    80 #include <netinet/if_ether.h> 
    81 #endif 
    82  
    83 #include <dev/wi/if_wavelan_ieee.h> 
     63 
     64#include "if_ieee80211.h" 
     65#include "if_wavelan_ieee.h" 
     66#include "if_media.h" 
     67#define __packed        __attribute__((__packed__)) 
     68#include "if_llc.h" 
     69#include "if_ethersubr.h" 
     70 
     71/* Bit map related macros. */ 
     72#define setbit(a,i)     ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) 
     73#define clrbit(a,i)     ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) 
     74#define isset(a,i)      ((a)[(i)/NBBY] & (1<<((i)%NBBY))) 
     75#define isclr(a,i)      (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) 
    8476 
    8577#define IEEE80211_DEBUG 
    8678#ifdef IEEE80211_DEBUG 
    87 int ieee80211_debug = 0; 
    88 #define DPRINTF(X)      if (ieee80211_debug) printf X 
    89 #define DPRINTF2(X)     if (ieee80211_debug>1) printf X 
    90  
    91 SYSCTL_INT(_debug, OID_AUTO, ieee80211, CTLFLAG_RW, &ieee80211_debug, 
    92             0, "IEEE 802.11 media debugging printfs"); 
     79static  int ieee80211_debug = 0; 
     80#define DPRINTF(X)      if (ieee80211_debug) printk X 
     81#define DPRINTF2(X)     if (ieee80211_debug>1) printk X 
    9382#else 
    9483#define DPRINTF(X) 
     
    124113 
    125114static void ieee80211_recv_beacon(struct ieee80211com *, 
    126     struct mbuf *, int, u_int32_t); 
     115    struct sk_buff *, int, u_int32_t); 
    127116static void ieee80211_recv_prreq(struct ieee80211com *, 
    128     struct mbuf *, int, u_int32_t); 
     117    struct sk_buff *, int, u_int32_t); 
    129118static void ieee80211_recv_auth(struct ieee80211com *, 
    130     struct mbuf *, int, u_int32_t); 
     119    struct sk_buff *, int, u_int32_t); 
    131120static void ieee80211_recv_asreq(struct ieee80211com *, 
    132     struct mbuf *, int, u_int32_t); 
     121    struct sk_buff *, int, u_int32_t); 
    133122static void ieee80211_recv_asresp(struct ieee80211com *, 
    134     struct mbuf *, int, u_int32_t); 
     123    struct sk_buff *, int, u_int32_t); 
    135124static void ieee80211_recv_disassoc(struct ieee80211com *, 
    136     struct mbuf *, int, u_int32_t); 
     125    struct sk_buff *, int, u_int32_t); 
    137126static void ieee80211_recv_deauth(struct ieee80211com *, 
    138     struct mbuf *, int, u_int32_t); 
     127    struct sk_buff *, int, u_int32_t); 
    139128 
    140129static void ieee80211_crc_init(void); 
     
    148137}; 
    149138 
    150 void 
    151 ieee80211_ifattach(struct ifnet *ifp) 
    152 
    153         struct ieee80211com *ic = (void *)ifp; 
     139/* 
     140 * Format an Ethernet MAC for printing. 
     141 */ 
     142static const char* 
     143ether_sprintf(const u_int8_t *mac) 
     144
     145        static char etherbuf[18]; 
     146        snprintf(etherbuf, sizeof(etherbuf), "%02x:%02x:%02x:%02x:%02x:%02x", 
     147                mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 
     148        return etherbuf; 
     149
     150 
     151int 
     152ieee80211_ifattach(struct net_device *dev) 
     153
     154        struct ieee80211com *ic = (void *)dev; 
    154155        int i, rate; 
    155156 
    156         /* XXX need unit */ 
    157         mtx_init(&ic->ic_mtx, ifp->if_name, "802.11 link layer", MTX_DEF); 
    158  
    159         ether_ifattach(ifp, ic->ic_myaddr); 
    160 #if NBPFILTER > 0 
    161         bpfattach2(ifp, DLT_IEEE802_11, 
    162             sizeof(struct ieee80211_frame_addr4), &ic->ic_rawbpf); 
    163 #endif 
     157        if (register_netdev(&ic->ic_dev)) { 
     158               printk(KERN_WARNING "%s: unable to register device\n", 
     159                        ic->ic_dev.name); 
     160               return (EIO); 
     161        } 
     162 
     163        spin_lock_init(&ic->ic_lock); 
     164 
    164165        ieee80211_crc_init(); 
    165         ic->ic_iv = arc4random(); 
     166        get_random_bytes(&ic->ic_iv, sizeof(ic->ic_iv)); 
    166167        memcpy(ic->ic_chan_active, ic->ic_chan_avail, 
    167168            sizeof(ic->ic_chan_active)); 
     
    179180                ic->ic_lintval = 100;   /* default sleep */ 
    180181        TAILQ_INIT(&ic->ic_node); 
    181         mtx_init(&ic->ic_mgtq.ifq_mtx, ifp->if_name, "mgmt send q", MTX_DEF); 
    182  
     182        skb_queue_head_init(&ic->ic_mgtq); 
     183 
     184#ifdef notdef 
    183185        rate = 0; 
    184186        for (i = 0; i < IEEE80211_RATE_SIZE; i++) { 
     
    189191                ifp->if_baudrate = IF_Mbps(rate); 
    190192        ifp->if_hdrlen = sizeof(struct ieee80211_frame); 
     193#endif 
    191194 
    192195        /* initialize management frame handler */ 
     
    230233        ic->ic_send_mgmt[IEEE80211_FC0_SUBTYPE_DISASSOC 
    231234            >> IEEE80211_FC0_SUBTYPE_SHIFT] = ieee80211_send_disassoc; 
     235 
     236        return (0); 
    232237} 
    233238 
    234239void 
    235 ieee80211_ifdetach(struct ifnet *ifp
    236 { 
    237         struct ieee80211com *ic = (void *)ifp
     240ieee80211_ifdetach(struct net_device *dev
     241{ 
     242        struct ieee80211com *ic = (void *)dev
    238243 
    239244        IEEE80211_LOCK(ic); 
    240         IF_DRAIN(&ic->ic_mgtq); 
    241         mtx_destroy(&ic->ic_mgtq.ifq_mtx); 
     245        skb_queue_purge(&ic->ic_mgtq); 
    242246        if (ic->ic_wep_ctx != NULL) { 
    243                 free(ic->ic_wep_ctx, M_DEVBUF); 
     247                kfree(ic->ic_wep_ctx); 
    244248                ic->ic_wep_ctx = NULL; 
    245249        } 
    246250        ieee80211_free_allnodes(ic); 
    247 #if NBPFILTER > 0 
    248         bpfdetach(ifp); 
    249 #endif 
    250         ether_ifdetach(ifp); 
     251        unregister_netdev(&ic->ic_dev); 
    251252        IEEE80211_UNLOCK(ic); 
    252         mtx_destroy(&ic->ic_mtx); 
    253253} 
    254254 
    255255void 
    256 ieee80211_input(struct ifnet *ifp, struct mbuf *m, int rssi, u_int32_t rstamp) 
    257 
    258         struct ieee80211com *ic = (void *)ifp; 
     256ieee80211_input(struct net_device *dev, struct sk_buff *skb, 
     257        int rssi, u_int32_t rstamp) 
     258
     259        struct ieee80211com *ic = (void *)dev; 
    259260        struct ieee80211_node *ni = NULL; 
    260261        struct ieee80211_frame *wh; 
    261262        struct ether_header *eh; 
    262         void (*rh)(struct ieee80211com *, struct mbuf *, int, u_int); 
    263         struct mbuf *m1; 
     263        void (*rh)(struct ieee80211com *, struct sk_buff *, int, u_int); 
     264        struct sk_buff *skb1; 
    264265        int len; 
    265266        u_int8_t dir, subtype; 
     
    267268        u_int16_t rxseq; 
    268269 
    269         /* trim CRC here for WEP can find its own CRC at the end of packet. */ 
    270         if (m->m_flags & M_HASFCS) { 
    271                 m_adj(m, -IEEE80211_CRC_LEN); 
    272                 m->m_flags &= ~M_HASFCS; 
    273         } 
    274  
    275         wh = mtod(m, struct ieee80211_frame *); 
     270        wh = (struct ieee80211_frame *) skb->data; 
    276271        if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) != 
    277272            IEEE80211_FC0_VERSION_0) { 
    278                 if (ifp->if_flags & IFF_DEBUG
    279                         if_printf(ifp, "receive packet with wrong version: %x\n", 
    280                             wh->i_fc[0]); 
     273                if (netif_msg_debug(ic)
     274                        printk("%s: receive packet with wrong version: %x\n", 
     275                            dev->name, wh->i_fc[0]); 
    281276                goto err; 
    282277        } 
     
    303298                                bssid = wh->i_addr1; 
    304299                        if (!IEEE80211_ADDR_EQ(bssid, ic->ic_bss.ni_bssid) && 
    305                             !IEEE80211_ADDR_EQ(bssid, ifp->if_broadcastaddr)) { 
     300                            !IEEE80211_ADDR_EQ(bssid, dev->broadcast)) { 
    306301                                /* not interested in */ 
    307302                                DPRINTF2(("ieee80211_input: other bss %s\n", 
     
    321316                rxseq = ni->ni_rxseq; 
    322317                ni->ni_rxseq = 
    323                     le16toh(*(u_int16_t *)wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT; 
     318                    le16_to_cpu(*(u_int16_t *)wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT; 
    324319                /* TODO: fragment */ 
    325320                if ((wh->i_fc[1] & IEEE80211_FC1_RETRY) && 
     
    337332                        if (dir != IEEE80211_FC1_DIR_FROMDS) 
    338333                                goto out; 
     334#ifdef IFF_SIMPLEX 
    339335                        if ((ifp->if_flags & IFF_SIMPLEX) && 
    340336                            IEEE80211_IS_MULTICAST(wh->i_addr1) && 
     
    348344                                goto out; 
    349345                        } 
     346#endif 
    350347                        break; 
    351348                case IEEE80211_M_IBSS: 
     
    385382                if (wh->i_fc[1] & IEEE80211_FC1_WEP) { 
    386383                        if (ic->ic_flags & IEEE80211_F_WEPON) { 
    387                                 m = ieee80211_wep_crypt(ifp, m, 0); 
    388                                 if (m == NULL) 
     384                                skb = ieee80211_wep_crypt(dev, skb, 0); 
     385                                if (skb == NULL) 
    389386                                        goto err; 
    390                                 wh = mtod(m, struct ieee80211_frame *)
     387                                wh = (struct ieee80211_frame *) skb->data
    391388                        } else 
    392389                                goto out; 
    393390                } 
    394391                /* copy to listener after decrypt */ 
    395 #if NBPFILTER > 0 
    396                 if (ic->ic_rawbpf) 
    397                         bpf_mtap(ic->ic_rawbpf, m); 
    398 #endif 
    399                 m = ieee80211_decap(ifp, m); 
    400                 if (m == NULL) 
     392                skb = ieee80211_decap(dev, skb); 
     393                if (skb == NULL) 
    401394                        goto err; 
    402                 ifp->if_ipackets++; 
     395                ic->ic_stats.rx_packets++; 
    403396 
    404397                /* perform as a bridge within the AP */ 
    405                 m1 = NULL; 
     398                skb1 = NULL; 
    406399                if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 
    407                         eh = mtod(m, struct ether_header *)
     400                        eh = (struct ether_header *) skb->data
    408401                        if (ETHER_IS_MULTICAST(eh->ether_dhost)) { 
    409                                 m1 = m_copym(m, 0, M_COPYALL, M_NOWAIT); 
    410                                 if (m1 == NULL) 
    411                                         ifp->if_oerrors++; 
    412                                 else 
    413                                         m1->m_flags |= M_MCAST; 
     402                                skb1 = skb_copy(skb, 0); 
     403                                if (skb1 == NULL) 
     404                                        ic->ic_stats.tx_errors++; 
    414405                        } else { 
    415406                                ni = ieee80211_find_node(ic, eh->ether_dhost); 
    416407                                if (ni != NULL && ni->ni_associd != 0) { 
    417                                         m1 = m
    418                                         m = NULL; 
     408                                        skb1 = skb
     409                                        skb = NULL; 
    419410                                } 
    420411                        } 
    421                         if (m1 != NULL) { 
    422 #ifdef ALTQ 
    423                                 if (ALTQ_IS_ENABLED(&ifp->if_snd)) 
    424                                         altq_etherclassify(&ifp->if_snd, m1, 
    425                                             &pktattr); 
    426 #endif 
    427                                 len = m1->m_pkthdr.len; 
    428                                 IF_ENQUEUE(&ifp->if_snd, m1); 
    429                                 if (m != NULL) 
    430                                         ifp->if_omcasts++; 
    431                                 ifp->if_obytes += len; 
    432                         } 
    433                 } 
    434                 if (m != NULL) 
    435                         (*ifp->if_input)(ifp, m); 
     412                        if (skb1 != NULL) { 
     413                                len = skb1->len; 
     414                                skb1->dev = dev; 
     415                                skb1->protocol = __constant_htons(ETH_P_802_2); 
     416                                dev_queue_xmit(skb1); 
     417                                ic->ic_stats.tx_bytes += len; 
     418                        } 
     419                } 
     420                if (skb != NULL) { 
     421                        skb->dev = dev; 
     422                        skb->mac.raw = skb->data; 
     423                        skb_pull(skb, sizeof(struct ether_header)); 
     424                        skb->pkt_type = PACKET_OTHERHOST; 
     425                        skb->protocol = __constant_htons(ETH_P_802_2); 
     426                        netif_rx(skb); 
     427                } 
    436428                return; 
    437429 
     
    454446                } 
    455447 
    456                 if (ifp->if_flags & IFF_DEBUG) { 
     448                if (netif_msg_debug(ic)) { 
    457449                        /* avoid to print too many frames */ 
    458450                        int doprint = 0; 
     
    475467#endif 
    476468                        if (doprint) 
    477                                 if_printf(ifp, "received %s from %s rssi %d\n", 
     469                                printk("%s: received %s from %s rssi %d\n", 
     470                                    dev->name, 
    478471                                    ieee80211_mgt_subtype_name[subtype 
    479472                                    >> IEEE80211_FC0_SUBTYPE_SHIFT], 
    480473                                    ether_sprintf(wh->i_addr2), rssi); 
    481474                } 
    482 #if NBPFILTER > 0 
    483                 if (ic->ic_rawbpf) 
    484                         bpf_mtap(ic->ic_rawbpf, m); 
    485 #endif 
    486475                rh = ic->ic_recv_mgmt[subtype >> IEEE80211_FC0_SUBTYPE_SHIFT]; 
    487476                if (rh != NULL) 
    488                         (*rh)(ic, m, rssi, rstamp); 
    489                 m_freem(m); 
     477                        (*rh)(ic, skb, rssi, rstamp); 
     478                dev_kfree_skb(skb); 
    490479                return; 
    491480 
     
    497486        } 
    498487  err: 
    499         ifp->if_ierrors++; 
     488        ic->ic_stats.rx_errors++; 
    500489  out: 
    501         if (m != NULL) { 
    502 #if NBPFILTER > 0 
    503                 if (ic->ic_rawbpf) 
    504                         bpf_mtap(ic->ic_rawbpf, m); 
    505 #endif 
    506                 m_freem(m); 
    507         } 
     490        if (skb != NULL) 
     491                dev_kfree_skb(skb); 
    508492} 
    509493 
    510494int 
    511 ieee80211_mgmt_output(struct ifnet *ifp, struct ieee80211_node *ni, 
    512     struct mbuf *m, int type) 
    513 { 
    514         struct ieee80211com *ic = (void *)ifp
     495ieee80211_mgmt_output(struct net_device *dev, struct ieee80211_node *ni, 
     496    struct sk_buff *skb, int type) 
     497{ 
     498        struct ieee80211com *ic = (void *)dev
    515499        struct ieee80211_frame *wh; 
    516500 
     
    518502                ni = &ic->ic_bss; 
    519503        ni->ni_inact = 0; 
    520         M_PREPEND(m, sizeof(struct ieee80211_frame), M_NOWAIT); 
    521         if (m == NULL) 
    522                 return ENOMEM; 
    523         wh = mtod(m, struct ieee80211_frame *); 
     504 
     505        wh = (struct ieee80211_frame *) 
     506                skb_push(skb, sizeof(struct ieee80211_frame)); 
    524507        wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | type; 
    525508        wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; 
    526509        *(u_int16_t *)wh->i_dur = 0; 
    527510        *(u_int16_t *)wh->i_seq = 
    528             htole16(ni->ni_txseq << IEEE80211_SEQ_SEQ_SHIFT); 
     511            cpu_to_le16(ni->ni_txseq << IEEE80211_SEQ_SEQ_SHIFT); 
    529512        ni->ni_txseq++; 
    530513        IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr); 
     
    532515        IEEE80211_ADDR_COPY(wh->i_addr3, ni->ni_bssid); 
    533516 
    534         if (ifp->if_flags & IFF_DEBUG) { 
     517        if (netif_msg_debug(ic)) { 
    535518                /* avoid to print too many frames */ 
    536519                if (ic->ic_opmode == IEEE80211_M_IBSS || 
     
    540523                    (type & IEEE80211_FC0_SUBTYPE_MASK) != 
    541524                    IEEE80211_FC0_SUBTYPE_PROBE_RESP) 
    542                         if_printf(ifp, "sending %s to %s\n", 
     525                        printk("%s: sending %s to %s\n", 
     526                            dev->name, 
    543527                            ieee80211_mgt_subtype_name[ 
    544528                            (type & IEEE80211_FC0_SUBTYPE_MASK) 
     
    546530                            ether_sprintf(ni->ni_macaddr)); 
    547531        } 
    548         IF_ENQUEUE(&ic->ic_mgtq, m); 
    549         ifp->if_timer = 1; 
    550         (*ifp->if_start)(ifp); 
     532        skb_queue_tail(&ic->ic_mgtq, skb); 
     533        ic->ic_timer = 1; 
     534        (*ic->ic_start)(dev); 
    551535        return 0; 
    552536} 
    553537 
    554 struct mbuf * 
    555 ieee80211_encap(struct ifnet *ifp, struct mbuf *m
    556 { 
    557         struct ieee80211com *ic = (void *)ifp
     538struct sk_buff * 
     539ieee80211_encap(struct net_device *dev, struct sk_buff *skb
     540{ 
     541        struct ieee80211com *ic = (void *)dev
    558542        struct ether_header eh; 
    559543        struct ieee80211_frame *wh; 
     
    561545        struct ieee80211_node *ni; 
    562546 
    563         if (m->m_len < sizeof(struct ether_header)) { 
    564                 m = m_pullup(m, sizeof(struct ether_header)); 
    565                 if (m == NULL) 
    566                         return NULL; 
    567         } 
    568         memcpy(&eh, mtod(m, caddr_t), sizeof(struct ether_header)); 
     547        memcpy(&eh, skb->data, sizeof(struct ether_header)); 
    569548 
    570549        if (!IEEE80211_IS_MULTICAST(eh.ether_dhost) && 
     
    578557        ni->ni_inact = 0; 
    579558 
    580         m_adj(m, sizeof(struct ether_header) - sizeof(struct llc)); 
    581         llc = mtod(m, struct llc *); 
     559        llc = (struct llc *) skb_push(skb, 
     560               sizeof(struct ether_header) - sizeof(struct llc)); 
    582561        llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; 
    583562        llc->llc_control = LLC_UI; 
     
    586565        llc->llc_snap.org_code[2] = 0; 
    587566        llc->llc_snap.ether_type = eh.ether_type; 
    588         M_PREPEND(m, sizeof(struct ieee80211_frame), M_NOWAIT); 
    589         if (m == NULL) 
    590                 return NULL; 
    591         wh = mtod(m, struct ieee80211_frame *); 
     567        wh = (struct ieee80211_frame *) skb_push(skb, sizeof(*wh)); 
    592568        wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA; 
    593569        *(u_int16_t *)wh->i_dur = 0; 
    594570        *(u_int16_t *)wh->i_seq = 
    595             htole16(ni->ni_txseq << IEEE80211_SEQ_SEQ_SHIFT); 
     571            cpu_to_le16(ni->ni_txseq << IEEE80211_SEQ_SEQ_SHIFT); 
    596572        ni->ni_txseq++; 
    597573        switch (ic->ic_opmode) { 
     
    616592                break; 
    617593        } 
    618         return m
    619 } 
    620  
    621 struct mbuf * 
    622 ieee80211_decap(struct ifnet *ifp, struct mbuf *m
     594        return skb
     595} 
     596 
     597struct sk_buff * 
     598ieee80211_decap(struct net_device *dev, struct sk_buff *skb
    623599{ 
    624600        struct ether_header *eh; 
     
    626602        struct llc *llc; 
    627603 
    628         if (m->m_len < sizeof(wh) + sizeof(*llc)) { 
    629                 m = m_pullup(m, sizeof(wh) + sizeof(*llc)); 
    630                 if (m == NULL) 
    631                         return NULL; 
    632         } 
    633         memcpy(&wh, mtod(m, caddr_t), sizeof(wh)); 
    634         llc = (struct llc *)(mtod(m, caddr_t) + sizeof(wh)); 
     604        memcpy(&wh, skb->data, sizeof(wh)); 
     605        llc = (struct llc *)(skb->data + sizeof(wh)); 
    635606        if (llc->llc_dsap == LLC_SNAP_LSAP && llc->llc_ssap == LLC_SNAP_LSAP && 
    636607            llc->llc_control == LLC_UI && llc->llc_snap.org_code[0] == 0 && 
    637608            llc->llc_snap.org_code[1] == 0 && llc->llc_snap.org_code[2] == 0) { 
    638                 m_adj(m, sizeof(wh) + sizeof(struct llc) - sizeof(*eh)); 
     609                skb_pull(skb, sizeof(wh) + sizeof(struct llc) - sizeof(*eh)); 
    639610                llc = NULL; 
    640611        } else { 
    641                 m_adj(m, sizeof(wh) - sizeof(*eh)); 
    642         } 
    643         eh = mtod(m, struct ether_header *)
     612                skb_pull(skb, sizeof(wh) - sizeof(*eh)); 
     613        } 
     614        eh = (struct ether_header *) skb->data
    644615        switch (wh.i_fc[1] & IEEE80211_FC1_DIR_MASK) { 
    645616        case IEEE80211_FC1_DIR_NODS: 
     
    658629                /* not yet supported */ 
    659630                DPRINTF(("ieee80211_decap: DS to DS\n")); 
    660                 m_freem(m); 
     631                dev_kfree_skb(skb); 
    661632                return NULL; 
    662633        } 
    663         if (!ALIGNED_POINTER(mtod(m, caddr_t) + sizeof(*eh), u_int32_t)) { 
    664                 struct mbuf *n, *n0, **np; 
    665                 caddr_t newdata; 
    666                 int off, pktlen; 
    667  
    668                 n0 = NULL; 
    669                 np = &n0; 
    670                 off = 0; 
    671                 pktlen = m->m_pkthdr.len; 
    672                 while (pktlen > off) { 
    673                         if (n0 == NULL) { 
    674                                 MGETHDR(n, M_NOWAIT, MT_DATA); 
    675                                 if (n == NULL) { 
    676                                         m_freem(m); 
    677                                         return NULL; 
    678                                 } 
    679                                 M_MOVE_PKTHDR(n, m); 
    680                                 n->m_len = MHLEN; 
    681                         } else { 
    682                                 MGET(n, M_NOWAIT, MT_DATA); 
    683                                 if (n == NULL) { 
    684                                         m_freem(m); 
    685                                         m_freem(n0); 
    686                                         return NULL; 
    687                                 } 
    688                                 n->m_len = MLEN; 
    689                         } 
    690                         if (pktlen - off >= MINCLSIZE) { 
    691                                 MCLGET(n, M_NOWAIT); 
    692                                 if (n->m_flags & M_EXT) 
    693                                         n->m_len = n->m_ext.ext_size; 
    694                         } 
    695                         if (n0 == NULL) { 
    696                                 newdata = 
    697                                     (caddr_t)ALIGN(n->m_data + sizeof(*eh)) - 
    698                                     sizeof(*eh); 
    699                                 n->m_len -= newdata - n->m_data; 
    700                                 n->m_data = newdata; 
    701                         } 
    702                         if (n->m_len > pktlen - off) 
    703                                 n->m_len = pktlen - off; 
    704                         m_copydata(m, off, n->m_len, mtod(n, caddr_t)); 
    705                         off += n->m_len; 
    706                         *np = n; 
    707                         np = &n->m_next; 
    708                 } 
    709                 m_freem(m); 
    710                 m = n0; 
     634        if (!ALIGNED_POINTER(skb->data + sizeof(*eh), u_int32_t)) { 
     635                struct sk_buff *n; 
     636 
     637                /* XXX does this always work? */ 
     638                n = skb_copy(skb, 0); 
     639                if (n == NULL) { 
     640                        dev_kfree_skb(skb); 
     641                        return NULL; 
     642                } 
     643                dev_kfree_skb(skb); 
     644                skb = n; 
    711645        } 
    712646        if (llc != NULL) { 
    713                 eh = mtod(m, struct ether_header *)
    714                 eh->ether_type = htons(m->m_pkthdr.len - sizeof(*eh)); 
    715         } 
    716         return m
     647                eh = (struct ether_header *) skb->data
     648                eh->ether_type = htons(skb->len - sizeof(*eh)); 
     649        } 
     650        return skb
    717651} 
    718652 
    719653int 
    720 ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 
    721 { 
    722         struct ieee80211com *ic = (void *)ifp
     654ieee80211_ioctl(struct net_device *dev, u_long cmd, caddr_t data) 
     655{ 
     656        struct ieee80211com *ic = (void *)dev
    723657        int error = 0; 
    724658        u_int kid, len; 
     
    744678                                break; 
    745679                        } 
    746                         error = copyout(tmpssid, ireq->i_data, ireq->i_len); 
     680                        error = copy_to_user(ireq->i_data, tmpssid, ireq->i_len); 
    747681                        break; 
    748682                case IEEE80211_IOC_NUMSSIDS: 
     
    774708                        len = (u_int) ic->ic_nw_keys[kid].wk_len; 
    775709                        /* NB: only root can read WEP keys */ 
    776                         if (suser(curthread)) { 
    777                                 bcopy(ic->ic_nw_keys[kid].wk_key, tmpkey, len); 
     710                        if (capable(CAP_SYS_ADMIN)) { 
     711                                memcpy(tmpkey, ic->ic_nw_keys[kid].wk_key, len); 
    778712                        } else { 
    779                                 bzero(tmpkey, len); 
     713                                memset(tmpkey, 0, len); 
    780714                        } 
    781715                        ireq->i_len = len; 
    782                         error = copyout(tmpkey, ireq->i_data, len); 
     716                        error = copy_to_user(ireq->i_data, tmpkey, len); 
    783717                        break; 
    784718                case IEEE80211_IOC_NUMWEPKEYS: 
     
    825759                break; 
    826760        case SIOCS80211: 
    827                 error = suser(curthread); 
    828                 if (error) 
    829                         break; 
     761                if (!capable(CAP_SYS_ADMIN)) { 
     762                        error = EPERM; 
     763                        break; 
     764                } 
    830765                ireq = (struct ieee80211req *) data; 
    831766                switch (ireq->i_type) { 
     
    836771                                break; 
    837772                        } 
    838                         error = copyin(ireq->i_data, tmpssid, ireq->i_len); 
     773                        error = copy_from_user(tmpssid, ireq->i_data, ireq->i_len); 
    839774                        if (error) 
    840775                                break; 
     
    872807                        } 
    873808                        memset(tmpkey, 0, sizeof(tmpkey)); 
    874                         error = copyin(ireq->i_data, tmpkey, ireq->i_len); 
     809                        error = copy_from_user(tmpkey, ireq->i_data, ireq->i_len); 
    875810                        if (error) 
    876811                                break; 
     
    956891                break; 
    957892        case SIOCGIFGENERIC: 
    958                 error = ieee80211_cfgget(ifp, cmd, data); 
     893                error = ieee80211_cfgget(dev, cmd, data); 
    959894                break; 
    960895        case SIOCSIFGENERIC: 
    961                 error = suser(curthread); 
    962                 if (error) 
    963                        break; 
    964                 error = ieee80211_cfgset(ifp, cmd, data)
     896                if (capable(CAP_SYS_ADMIN)) 
     897                       error = ieee80211_cfgset(dev, cmd, data); 
     898                else 
     899                       error = EPERM
    965900                break; 
    966901        default: 
    967                 error = ether_ioctl(ifp, cmd, data); 
     902#ifdef notdef 
     903                error = ether_ioctl(ifp, cmd, data);    /* XXX */ 
     904#else 
     905                error = EINVAL; 
     906#endif 
    968907                break; 
    969908        } 
     
    985924        } 
    986925        if (i == len) { 
    987                 printf("\""); 
     926                printk("\""); 
    988927                for (i = 0, p = essid; i < len; i++, p++) 
    989                         printf("%c", *p); 
    990                 printf("\""); 
     928                        printk("%c", *p); 
     929                printk("\""); 
    991930        } else { 
    992                 printf("0x"); 
     931                printk("0x"); 
    993932                for (i = 0, p = essid; i < len; i++, p++) 
    994                         printf("%02x", *p); 
     933                        printk("%02x", *p); 
    995934        } 
    996935} 
     
    1005944        switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) { 
    1006945        case IEEE80211_FC1_DIR_NODS: 
    1007                 printf("NODS %s", ether_sprintf(wh->i_addr2)); 
    1008                 printf("->%s", ether_sprintf(wh->i_addr1)); 
    1009                 printf("(%s)", ether_sprintf(wh->i_addr3)); 
     946                printk("NODS %s", ether_sprintf(wh->i_addr2)); 
     947                printk("->%s", ether_sprintf(wh->i_addr1)); 
     948                printk("(%s)", ether_sprintf(wh->i_addr3)); 
    1010949                break; 
    1011950        case IEEE80211_FC1_DIR_TODS: 
    1012                 printf("TODS %s", ether_sprintf(wh->i_addr2)); 
    1013                 printf("->%s", ether_sprintf(wh->i_addr3)); 
    1014                 printf("(%s)", ether_sprintf(wh->i_addr1)); 
     951                printk("TODS %s", ether_sprintf(wh->i_addr2)); 
     952                printk("->%s", ether_sprintf(wh->i_addr3)); 
     953                printk("(%s)", ether_sprintf(wh->i_addr1)); 
    1015954                break; 
    1016955        case IEEE80211_FC1_DIR_FROMDS: 
    1017                 printf("FRDS %s", ether_sprintf(wh->i_addr3)); 
    1018                 printf("->%s", ether_sprintf(wh->i_addr1)); 
    1019                 printf("(%s)", ether_sprintf(wh->i_addr2)); 
     956                printk("FRDS %s", ether_sprintf(wh->i_addr3)); 
     957                printk("->%s", ether_sprintf(wh->i_addr1)); 
     958                printk("(%s)", ether_sprintf(wh->i_addr2)); 
    1020959                break; 
    1021960        case IEEE80211_FC1_DIR_DSTODS: 
    1022                 printf("DSDS %s", ether_sprintf((u_int8_t *)&wh[1])); 
    1023                 printf("->%s", ether_sprintf(wh->i_addr3)); 
    1024                 printf("(%s", ether_sprintf(wh->i_addr2)); 
    1025                 printf("->%s)", ether_sprintf(wh->i_addr1)); 
     961                printk("DSDS %s", ether_sprintf((u_int8_t *)&wh[1])); 
     962                printk("->%s", ether_sprintf(wh->i_addr3)); 
     963                printk("(%s", ether_sprintf(wh->i_addr2)); 
     964                printk("->%s)", ether_sprintf(wh->i_addr1)); 
    1026965                break; 
    1027966        } 
    1028967        switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { 
    1029968        case IEEE80211_FC0_TYPE_DATA: 
    1030                 printf(" data"); 
     969                printk(" data"); 
    1031970                break; 
    1032971        case IEEE80211_FC0_TYPE_MGT: 
    1033                 printf(" %s", ieee80211_mgt_subtype_name[ 
     972                printk(" %s", ieee80211_mgt_subtype_name[ 
    1034973                    (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) 
    1035974                    >> IEEE80211_FC0_SUBTYPE_SHIFT]); 
    1036975                break; 
    1037976        default: 
    1038                 printf(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK); 
     977                printk(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK); 
    1039978                break; 
    1040979        } 
    1041980        if (wh->i_fc[1] & IEEE80211_FC1_WEP) 
    1042                 printf(" WEP"); 
     981                printk(" WEP"); 
    1043982        if (rate >= 0) 
    1044                 printf(" %dM", rate / 2); 
     983                printk(" %dM", rate / 2); 
    1045984        if (rssi >= 0) 
    1046                 printf(" +%d", rssi); 
    1047         printf("\n"); 
     985                printk(" +%d", rssi); 
     986        printk("\n"); 
    1048987        if (len > 0) { 
    1049988                for (i = 0; i < len; i++) { 
    1050989                        if ((i & 1) == 0) 
    1051                                 printf(" "); 
    1052                         printf("%02x", buf[i]); 
    1053                 } 
    1054                 printf("\n"); 
     990                                printk(" "); 
     991                        printk("%02x", buf[i]); 
     992                } 
     993                printk("\n"); 
    1055994        } 
    1056995} 
    1057996 
    1058997void 
    1059 ieee80211_watchdog(struct ifnet *ifp
    1060 { 
    1061         struct ieee80211com *ic = (void *)ifp
     998ieee80211_watchdog(struct net_device *dev
     999{ 
     1000        struct ieee80211com *ic = (void *)dev
    10621001        struct ieee80211_node *ni, *nextbs; 
    10631002 
     
    10651004                if (--ic->ic_scan_timer == 0) { 
    10661005                        if (ic->ic_state == IEEE80211_S_SCAN) 
    1067                                 ieee80211_end_scan(ifp); 
     1006                                ieee80211_end_scan(dev); 
    10681007                } 
    10691008        } 
    10701009        if (ic->ic_mgt_timer) { 
    10711010                if (--ic->ic_mgt_timer == 0) 
    1072                         ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1); 
     1011                        ieee80211_new_state(dev, IEEE80211_S_SCAN, -1); 
    10731012        } 
    10741013        if (ic->ic_inact_timer) { 
     
    10791018                                        continue; 
    10801019                                } 
    1081                                 if (ifp->if_flags & IFF_DEBUG
    1082                                         if_printf(ifp, "station %s deauthenticate" 
     1020                                if (netif_msg_debug(ic)
     1021                                        printk("%s: station %s deauthenticate" 
    10831022                                            " (reason %d)\n", 
     1023                                            dev->name, 
    10841024                                            ether_sprintf(ni->ni_macaddr), 
    10851025                                            IEEE80211_REASON_AUTH_EXPIRE); 
     
    10971037        if (ic->ic_scan_timer != 0 || ic->ic_mgt_timer != 0 || 
    10981038            ic->ic_inact_timer != 0) 
    1099                 ifp->if_timer = 1; 
     1039                ic->ic_timer = 1; 
    11001040} 
    11011041 
    11021042void 
    1103 ieee80211_next_scan(struct ifnet *ifp
    1104 { 
    1105         struct ieee80211com *ic = (void *)ifp
     1043ieee80211_next_scan(struct net_device *dev
     1044{ 
     1045        struct ieee80211com *ic = (void *)dev
    11061046        int chan; 
    11071047 
     
    11191059            ic->ic_bss.ni_chan, chan)); 
    11201060        ic->ic_bss.ni_chan = chan; 
    1121         ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1); 
     1061        ieee80211_new_state(dev, IEEE80211_S_SCAN, -1); 
    11221062} 
    11231063 
    11241064void 
    1125 ieee80211_end_scan(struct ifnet *ifp
    1126 { 
    1127         struct ieee80211com *ic = (void *)ifp
     1065ieee80211_end_scan(struct net_device *dev
     1066{ 
     1067        struct ieee80211com *ic = (void *)dev
    11281068        struct ieee80211_node *ni, *nextbs, *selbs; 
    11291069        void *p; 
     
    11391079                    ic->ic_des_esslen != 0) { 
    11401080                        ni = &ic->ic_bss; 
    1141                         if (ifp->if_flags & IFF_DEBUG
    1142                                 if_printf(ifp, "creating ibss\n"); 
     1081                        if (netif_msg_debug(ic)
     1082                                printk("%s: creating ibss\n", dev->name); 
    11431083                        ic->ic_flags |= IEEE80211_F_SIBSS; 
    11441084                        ni->ni_nrate = 0; 
     
    11651105                                ni->ni_fhindex = 1; 
    11661106                        } 
    1167                         ieee80211_new_state(ifp, IEEE80211_S_RUN, -1); 
     1107                        ieee80211_new_state(dev, IEEE80211_S_RUN, -1); 
    11681108                        return; 
    11691109                } 
    11701110                if (ic->ic_flags & IEEE80211_F_ASCAN) { 
    1171                         if (ifp->if_flags & IFF_DEBUG) 
    1172                                 if_printf(ifp, "entering passive scan mode\n"); 
     1111                        if (netif_msg_debug(ic)) 
     1112                                printk("%s: entering passive scan mode\n", 
     1113                                        dev->name); 
    11731114                        ic->ic_flags &= ~IEEE80211_F_ASCAN; 
    11741115                } 
    1175                 ieee80211_next_scan(ifp); 
     1116                ieee80211_next_scan(dev); 
    11761117                return; 
    11771118        } 
    11781119        selbs = NULL; 
    1179         if (ifp->if_flags & IFF_DEBUG
    1180                 if_printf(ifp, "\tmacaddr          bssid         chan  rssi rate flag  wep  essid\n"); 
     1120        if (netif_msg_debug(ic)
     1121                printk("%s: \tmacaddr          bssid         chan  rssi rate flag  wep  essid\n", dev->name); 
    11811122        for (; ni != NULL; ni = nextbs) { 
    11821123                nextbs = TAILQ_NEXT(ni, ni_list); 
     
    12221163                    !IEEE80211_ADDR_EQ(ic->ic_des_bssid, ni->ni_bssid)) 
    12231164                        fail |= 0x20; 
    1224                 if (ifp->if_flags & IFF_DEBUG) { 
    1225                         printf(" %c %s", fail ? '-' : '+', 
     1165                if (netif_msg_debug(ic)) { 
     1166                        printk(" %c %s", fail ? '-' : '+', 
    12261167                            ether_sprintf(ni->ni_macaddr)); 
    1227                         printf(" %s%c", ether_sprintf(ni->ni_bssid), 
     1168                        printk(" %s%c", ether_sprintf(ni->ni_bssid), 
    12281169                            fail & 0x20 ? '!' : ' '); 
    1229                         printf(" %3d%c", ni->ni_chan, fail & 0x01 ? '!' : ' '); 
    1230                         printf(" %+4d", ni->ni_rssi); 
    1231                         printf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2, 
     1170                        printk(" %3d%c", ni->ni_chan, fail & 0x01 ? '!' : ' '); 
     1171                        printk(" %+4d", ni->ni_rssi); 
     1172                        printk(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2, 
    12321173                            fail & 0x08 ? '!' : ' '); 
    1233                         printf(" %4s%c", 
     1174                        printk(" %4s%c", 
    12341175                            (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" : 
    12351176                            (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" : 
    12361177                            "????", 
    12371178                            fail & 0x02 ? '!' : ' '); 
    1238                         printf(" %3s%c ", 
     1179                        printk(" %3s%c ", 
    12391180                            (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ? 
    12401181                            "wep" : "no", 
    12411182                            fail & 0x04 ? '!' : ' '); 
    12421183                        ieee80211_print_essid(ni->ni_essid, ni->ni_esslen); 
    1243                         printf("%s\n", fail & 0x10 ? "!" : ""); 
     1184                        printk("%s\n", fail & 0x10 ? "!" : ""); 
    12441185                } 
    12451186                if (!fail) { 
     
    12621203                        goto notfound; 
    12631204                } 
    1264                 ieee80211_new_state(ifp, IEEE80211_S_RUN, -1); 
     1205                ieee80211_new_state(dev, IEEE80211_S_RUN, -1); 
    12651206        } else 
    1266                 ieee80211_new_state(ifp, IEEE80211_S_AUTH, -1); 
     1207                ieee80211_new_state(dev, IEEE80211_S_AUTH, -1); 
    12671208} 
    12681209 
     
    12731214        int hash; 
    12741215 
    1275         ni = malloc(sizeof(struct ieee80211_node) + ic->ic_node_privlen, 
    1276             M_DEVBUF, M_NOWAIT); 
     1216        ni = kmalloc(sizeof(struct ieee80211_node) + ic->ic_node_privlen, 
     1217               GFP_KERNEL); 
    12771218        if (ni == NULL) 
    12781219                return NULL; 
     
    13221263        LIST_REMOVE(ni, ni_hash); 
    13231264        IEEE80211_UNLOCK(ic); 
    1324         free(ni, M_DEVBUF); 
     1265        kfree(ni); 
    13251266        if (TAILQ_EMPTY(&ic->ic_node)) 
    13261267                ic->ic_inact_timer = 0; 
     
    14001341{ 
    14011342        int i, ret; 
    1402         struct mbuf *m
     1343        struct sk_buff *skb
    14031344        u_int8_t *frm; 
    14041345 
     
    14081349         *      [tlv] supported rates 
    14091350         */ 
    1410         MGETHDR(m, M_NOWAIT, MT_DATA); 
    1411         if (m == NULL) 
     1351        skb = dev_alloc_skb(sizeof(struct ieee80211_frame) 
     1352                          + 2 + ic->ic_des_esslen 
     1353                          + 1 + IEEE80211_RATE_SIZE + 1); 
     1354        if (skb == NULL) 
    14121355                return ENOMEM; 
    1413         m->m_data += sizeof(struct ieee80211_frame); 
    1414         frm = mtod(m, u_int8_t *); 
     1356        frm = (u_int8_t *) skb_pull(skb, sizeof(struct ieee80211_frame)); 
    14151357 
    14161358        *frm++ = IEEE80211_ELEMID_SSID; 
     
    14261368        *frm++ = i; 
    14271369        frm += i; 
    1428         m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); 
    1429  
    1430         ret = ieee80211_mgmt_output(&ic->ic_if, ni, m, type); 
     1370        skb_trim(skb, frm - skb->data); 
     1371 
     1372        ret = ieee80211_mgmt_output(&ic->ic_dev, ni, skb, type); 
    14311373        ic->ic_mgt_timer = IEEE80211_TRANS_WAIT; 
    14321374        return ret; 
     
    14371379    int type, int dummy) 
    14381380{ 
    1439         struct mbuf *m
     1381        struct sk_buff *skb
    14401382        u_int8_t *frm; 
    14411383        struct ieee80211_node *ni = &ic->ic_bss; 
     
    14511393         *      [tlv] parameter set (IBSS) 
    14521394         */ 
    1453         MGETHDR(m, M_NOWAIT, MT_DATA); 
    1454         if (m == NULL) 
     1395        skb = dev_alloc_skb(sizeof(struct ieee80211_frame) 
     1396                          + 8 + 2 + 2 + 2 
     1397                          + 2 + ni->ni_esslen 
     1398                          + 2 + ni->ni_nrate  
     1399                          + 6); 
     1400        if (skb == NULL) 
    14551401                return ENOMEM; 
    1456         m->m_data += sizeof(struct ieee80211_frame); 
    1457         frm = mtod(m, u_int8_t *); 
     1402        frm = (u_int8_t *) skb_pull(skb, sizeof(struct ieee80211_frame)); 
    14581403 
    14591404        memset(frm, 0, 8);      /* timestamp should be filled later */ 
    14601405        frm += 8; 
    1461         *(u_int16_t *)frm = htole16(ni->ni_intval); 
     1406        *(u_int16_t *)frm = cpu_to_le16(ni->ni_intval); 
    14621407        frm += 2; 
    14631408        if (ic->ic_opmode == IEEE80211_M_IBSS) 
     
    14671412        if (ic->ic_flags & IEEE80211_F_WEPON) 
    14681413                capinfo |= IEEE80211_CAPINFO_PRIVACY; 
    1469         *(u_int16_t *)frm = htole16(capinfo); 
     1414        *(u_int16_t *)frm = cpu_to_le16(capinfo); 
    14701415        frm += 2; 
    14711416        *frm++ = IEEE80211_ELEMID_SSID; 
     
    14901435                *frm++ = 0;     /* Partial Virtual Bitmap (variable length) */ 
    14911436        } 
    1492         /* TODO: check MHLEN limit */ 
    1493         m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); 
    1494  
    1495         return ieee80211_mgmt_output(&ic->ic_if, bs0, m, type); 
     1437        skb_trim(skb, frm - skb->data); 
     1438 
     1439        return ieee80211_mgmt_output(&ic->ic_dev, bs0, skb, type); 
    14961440} 
    14971441 
     
    15001444    int type, int seq) 
    15011445{ 
    1502         struct mbuf *m
     1446        struct sk_buff *skb
    15031447        u_int16_t *frm; 
    15041448        int ret; 
    15051449 
    1506         MGETHDR(m, M_NOWAIT, MT_DATA); 
    1507         if (m == NULL) 
     1450        skb = dev_alloc_skb(sizeof(struct ieee80211_frame) 
     1451                          + 3*sizeof(u_int16_t)); 
     1452        if (skb == NULL) 
    15081453                return ENOMEM; 
    1509         MH_ALIGN(m, 2 * 3); 
    1510         m->m_pkthdr.len = m->m_len = 6; 
    1511         frm = mtod(m, u_int16_t *); 
     1454        /* XXX alignment? */ 
     1455        frm = (u_int16_t *) skb_pull(skb, sizeof(struct ieee80211_frame)); 
    15121456        /* TODO: shared key auth */ 
    1513         frm[0] = htole16(IEEE80211_AUTH_ALG_OPEN); 
    1514         frm[1] = htole16(seq); 
     1457        frm[0] = cpu_to_le16(IEEE80211_AUTH_ALG_OPEN); 
     1458        frm[1] = cpu_to_le16(seq); 
    15151459        frm[2] = 0;                     /* status */ 
    1516         ret = ieee80211_mgmt_output(&ic->ic_if, ni, m, type); 
     1460        ret = ieee80211_mgmt_output(&ic->ic_dev, ni, skb, type); 
    15171461        if (ic->ic_opmode == IEEE80211_M_STA) 
    15181462                ic->ic_mgt_timer = IEEE80211_TRANS_WAIT; 
     
    15241468    int type, int reason) 
    15251469{ 
    1526         struct ifnet *ifp = &ic->ic_if; 
    1527         struct mbuf *m; 
    1528  
    1529         if (ifp->if_flags & IFF_DEBUG) 
    1530                 if_printf(ifp, "station %s deauthenticate (reason %d)\n", 
    1531                     ether_sprintf(ni->ni_macaddr), reason); 
    1532         MGETHDR(m, M_NOWAIT, MT_DATA); 
    1533         if (m == NULL) 
     1470        struct net_device *dev = &ic->ic_dev; 
     1471        struct sk_buff *skb; 
     1472        u_int16_t *frm; 
     1473 
     1474        if (netif_msg_debug(ic)) 
     1475                printk("%s: station %s deauthenticate (reason %d)\n", 
     1476                    dev->name, ether_sprintf(ni->ni_macaddr), reason); 
     1477        skb = dev_alloc_skb(sizeof(struct ieee80211_frame) + sizeof(u_int16_t)); 
     1478        if (skb == NULL) 
    15341479                return ENOMEM; 
    1535         MH_ALIGN(m, 2); 
    1536         m->m_pkthdr.len = m->m_len = 2; 
    1537         *mtod(m, u_int16_t *) = htole16(reason); 
    1538         return ieee80211_mgmt_output(&ic->ic_if, ni, m, type); 
     1480        /* XXX alignment? */ 
     1481        frm = (u_int16_t *) skb_pull(skb, sizeof(struct ieee80211_frame)); 
     1482        frm[0] = cpu_to_le16(reason); 
     1483 
     1484        return ieee80211_mgmt_output(&ic->ic_dev, ni, skb, type); 
    15391485} 
    15401486 
     
    15431489    int type, int dummy) 
    15441490{ 
    1545         struct mbuf *m
     1491        struct sk_buff *skb
    15461492        u_int8_t *frm, *rates; 
    15471493        u_int16_t capinfo; 
     
    15561502         *      [tlv] supported rates 
    15571503         */ 
    1558         MGETHDR(m, M_NOWAIT, MT_DATA); 
    1559         if (m == NULL) 
     1504        skb = dev_alloc_skb(sizeof(struct ieee80211_frame) 
     1505                          + sizeof(capinfo) 
     1506                          + sizeof(u_int16_t) 
     1507                          + IEEE80211_ADDR_LEN 
     1508                          + 2 + ni->ni_esslen 
     1509                          + 1 + IEEE80211_RATE_SIZE); 
     1510        if (skb == NULL) 
    15601511                return ENOMEM; 
    1561         m->m_data += sizeof(struct ieee80211_frame); 
    1562         frm = mtod(m, u_int8_t *); 
     1512        frm = (u_int8_t *) skb_pull(skb, sizeof(struct ieee80211_frame)); 
    15631513 
    15641514        capinfo = 0; 
     
    15691519        if (ic->ic_flags & IEEE80211_F_WEPON) 
    15701520                capinfo |= IEEE80211_CAPINFO_PRIVACY; 
    1571         *(u_int16_t *)frm = htole16(capinfo); 
     1521        *(u_int16_t *)frm = cpu_to_le16(capinfo); 
    15721522        frm += 2; 
    15731523 
    1574         *(u_int16_t *)frm = htole16(ic->ic_lintval); 
     1524        *(u_int16_t *)frm = cpu_to_le16(ic->ic_lintval); 
    15751525        frm += 2; 
    15761526 
     
    15921542        } 
    15931543        *rates = frm - (rates + 1); 
    1594         m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); 
    1595         ret = ieee80211_mgmt_output(&ic->ic_if, ni, m, type); 
     1544        skb_trim(skb, frm - skb->data); 
     1545 
     1546        ret = ieee80211_mgmt_output(&ic->ic_dev, ni, skb, type); 
    15961547        ic->ic_mgt_timer = IEEE80211_TRANS_WAIT; 
    15971548        return ret; 
     
    16021553    int type, int status) 
    16031554{ 
    1604         struct mbuf *m
     1555        struct sk_buff *skb
    16051556        u_int8_t *frm, *rates, *r; 
    16061557        u_int16_t capinfo; 
     
    16141565         *      [tlv] supported rates 
    16151566         */ 
    1616         MGETHDR(m, M_NOWAIT, MT_DATA); 
    1617         if (m == NULL) 
     1567        skb = dev_alloc_skb(sizeof(struct ieee80211_frame) 
     1568                          + sizeof(capinfo) 
     1569                          + sizeof(u_int16_t) 
     1570                          + sizeof(u_int16_t) 
     1571                          + 1 + IEEE80211_RATE_SIZE); 
     1572        if (skb == NULL) 
    16181573                return ENOMEM; 
    1619         m->m_data += sizeof(struct ieee80211_frame); 
    1620         frm = mtod(m, u_int8_t *); 
     1574        frm = (u_int8_t *) skb_pull(skb, sizeof(struct ieee80211_frame)); 
    16211575 
    16221576        capinfo = IEEE80211_CAPINFO_ESS; 
    16231577        if (ic->ic_flags & IEEE80211_F_WEPON) 
    16241578                capinfo |= IEEE80211_CAPINFO_PRIVACY; 
    1625         *(u_int16_t *)frm = htole16(capinfo); 
     1579        *(u_int16_t *)frm = cpu_to_le16(capinfo); 
    16261580        frm += 2; 
    16271581 
    1628         *(u_int16_t *)frm = htole16(status); 
     1582        *(u_int16_t *)frm = cpu_to_le16(status); 
    16291583        frm += 2; 
    16301584 
    16311585        if (status == IEEE80211_STATUS_SUCCESS && ni != NULL) 
    1632                 *(u_int16_t *)frm = htole16(ni->ni_associd); 
     1586                *(u_int16_t *)frm = cpu_to_le16(ni->ni_associd); 
    16331587        else 
    1634                 *(u_int16_t *)frm = htole16(0); 
     1588                *(u_int16_t *)frm = cpu_to_le16(0); 
    16351589        frm += 2; 
    16361590 
     
    16461600        } 
    16471601        *rates = frm - (rates + 1); 
    1648         m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); 
    1649         return ieee80211_mgmt_output(&ic->ic_if, ni, m, type); 
     1602        skb_trim(skb, frm - skb->data); 
     1603 
     1604        return ieee80211_mgmt_output(&ic->ic_dev, ni, skb, type); 
    16501605} 
    16511606 
     
    16541609    int type, int reason) 
    16551610{ 
    1656         struct ifnet *ifp = &ic->ic_if; 
    1657         struct mbuf *m; 
    1658  
    1659         if (ifp->if_flags & IFF_DEBUG) 
    1660                 if_printf(ifp, "station %s disassociate (reason %d)\n", 
    1661                     ether_sprintf(ni->ni_macaddr), reason); 
    1662         MGETHDR(m, M_NOWAIT, MT_DATA); 
    1663         if (m == NULL) 
     1611        struct net_device *dev = &ic->ic_dev; 
     1612        struct sk_buff *skb; 
     1613        u_int16_t *frm; 
     1614 
     1615        if (netif_msg_debug(ic)) 
     1616                printk("%s: station %s disassociate (reason %d)\n", 
     1617                    dev->name, ether_sprintf(ni->ni_macaddr), reason); 
     1618        skb = dev_alloc_skb(sizeof(struct ieee80211_frame) + sizeof(u_int16_t)); 
     1619        if (skb == NULL) 
    16641620                return ENOMEM; 
    1665         MH_ALIGN(m, 2); 
    1666         m->m_pkthdr.len = m->m_len = 2; 
    1667         *mtod(m, u_int16_t *) = htole16(reason); 
    1668         return ieee80211_mgmt_output(&ic->ic_if, ni, m, 
     1621        /* XXX alignment? */ 
     1622        frm = (u_int16_t *) skb_pull(skb, sizeof(struct ieee80211_frame)); 
     1623        frm[0] = cpu_to_le16(reason); 
     1624 
     1625        return ieee80211_mgmt_output(&ic->ic_dev, ni, skb, 
    16691626            IEEE80211_FC0_SUBTYPE_DISASSOC); 
    16701627} 
    16711628 
    16721629static void 
    1673 ieee80211_recv_beacon(struct ieee80211com *ic, struct mbuf *m0, int rssi, 
     1630ieee80211_recv_beacon(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 
    16741631    u_int32_t rstamp) 
    16751632{ 
     
    16861643        } 
    16871644 
    1688         wh = mtod(m0, struct ieee80211_frame *)
     1645        wh = (struct ieee80211_frame *) skb0->data
    16891646        frm = (u_int8_t *)&wh[1]; 
    1690         efrm = mtod(m0, u_int8_t *) + m0->m_len; 
     1647        efrm = skb0->data + skb0->len; 
    16911648        /* 
    16921649         * beacon frame format 
     
    17421699            (ieee80211_debug > 1 || ni == NULL || 
    17431700            ic->ic_state == IEEE80211_S_SCAN)) { 
    1744                 printf("ieee80211_recv_prreq: %sbeacon on chan %u (bss chan %u) ", 
     1701                printk("ieee80211_recv_prreq: %sbeacon on chan %u (bss chan %u) ", 
    17451702                    (ni == NULL ? "new " : ""), chan, ic->ic_bss.ni_chan); 
    17461703                ieee80211_print_essid(ssid + 2, ssid[1]); 
    1747                 printf(" from %s\n", ether_sprintf(wh->i_addr2)); 
     1704                printk(" from %s\n", ether_sprintf(wh->i_addr2)); 
    17481705        } 
    17491706#endif 
     
    17761733        ni->ni_rstamp = rstamp; 
    17771734        memcpy(ni->ni_tstamp, tstamp, sizeof(ni->ni_tstamp)); 
    1778         ni->ni_intval = le16toh(*(u_int16_t *)bintval); 
    1779         ni->ni_capinfo = le16toh(*(u_int16_t *)capinfo); 
     1735        ni->ni_intval = le16_to_cpu(*(u_int16_t *)bintval); 
     1736        ni->ni_capinfo = le16_to_cpu(*(u_int16_t *)capinfo); 
    17801737        ni->ni_chan = chan; 
    17811738        ni->ni_fhdwell = fhdwell; 
    17821739        ni->ni_fhindex = fhindex; 
    17831740        if (ic->ic_state == IEEE80211_S_SCAN && ic->ic_scan_timer == 0) 
    1784                 ieee80211_end_scan(&ic->ic_if); 
     1741                ieee80211_end_scan(&ic->ic_dev); 
    17851742} 
    17861743 
    17871744static void 
    1788 ieee80211_recv_prreq(struct ieee80211com *ic, struct mbuf *m0, int rssi, 
     1745ieee80211_recv_prreq(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 
    17891746    u_int32_t rstamp) 
    17901747{ 
     
    18001757                return; 
    18011758 
    1802         wh = mtod(m0, struct ieee80211_frame *)
     1759        wh = (struct ieee80211_frame *) skb0->data
    18031760        frm = (u_int8_t *)&wh[1]; 
    1804         efrm = mtod(m0, u_int8_t *) + m0->m_len; 
     1761        efrm = skb0->data + skb0->len; 
    18051762        /* 
    18061763         * prreq frame format 
     
    18301787#ifdef IEEE80211_DEBUG 
    18311788                if (ieee80211_debug) { 
    1832                         printf("ieee80211_recv_prreq: ssid unmatch "); 
     1789                        printk("ieee80211_recv_prreq: ssid unmatch "); 
    18331790                        ieee80211_print_essid(ssid + 2, ssid[1]); 
    1834                         printf(" from %s\n", ether_sprintf(wh->i_addr2)); 
     1791                        printk(" from %s\n", ether_sprintf(wh->i_addr2)); 
    18351792                } 
    18361793#endif 
     
    18661823 
    18671824static void 
    1868 ieee80211_recv_auth(struct ieee80211com *ic, struct mbuf *m0, int rssi, 
     1825ieee80211_recv_auth(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 
    18691826    u_int32_t rstamp) 
    18701827{ 
    1871         struct ifnet *ifp = &ic->ic_if
     1828        struct net_device *dev = &ic->ic_dev
    18721829        struct ieee80211_frame *wh; 
    18731830        struct ieee80211_node *ni; 
     
    18761833        int allocbs; 
    18771834 
    1878         wh = mtod(m0, struct ieee80211_frame *)
     1835        wh = (struct ieee80211_frame *) skb0->data
    18791836        frm = (u_int8_t *)&wh[1]; 
    1880         efrm = mtod(m0, u_int8_t *) + m0->m_len; 
     1837        efrm = skb0->data + skb0->len; 
    18811838        /* 
    18821839         * auth frame format 
     
    18911848                return; 
    18921849        } 
    1893         algo   = le16toh(*(u_int16_t *)frm); 
    1894         seq    = le16toh(*(u_int16_t *)(frm + 2)); 
    1895         status = le16toh(*(u_int16_t *)(frm + 4)); 
     1850        algo   = le16_to_cpu(*(u_int16_t *)frm); 
     1851        seq    = le16_to_cpu(*(u_int16_t *)(frm + 2)); 
     1852        status = le16_to_cpu(*(u_int16_t *)(frm + 4)); 
    18961853        if (algo != IEEE80211_AUTH_ALG_OPEN) { 
    18971854                /* TODO: shared key auth */ 
     
    19041861                if (ic->ic_state != IEEE80211_S_RUN || seq != 1) 
    19051862                        return; 
    1906                 ieee80211_new_state(&ic->ic_if, IEEE80211_S_AUTH, 
     1863                ieee80211_new_state(&ic->ic_dev, IEEE80211_S_AUTH, 
    19071864                    wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 
    19081865                break; 
     
    19251882                } 
    19261883                IEEE80211_SEND_MGMT(ic, ni, IEEE80211_FC0_SUBTYPE_AUTH, 2); 
    1927                 if (ifp->if_flags & IFF_DEBUG) 
    1928                         if_printf(ifp, "station %s %s authenticated\n", 
     1884                if (netif_msg_debug(ic)) 
     1885                        printk("%s: station %s %s authenticated\n", 
     1886                            dev->name, 
    19291887                            (allocbs ? "newly" : "already"), 
    19301888                            ether_sprintf(ni->ni_macaddr)); 
     
    19351893                        return; 
    19361894                if (status != 0) { 
    1937                         if_printf(&ic->ic_if, 
    1938                             "authentication failed (reason %d) for %s\n", 
    1939                             status, 
     1895                        printk("%s: authentication failed (reason %d) for %s\n", 
     1896                            dev->name, status, 
    19401897                            ether_sprintf(wh->i_addr3)); 
    19411898                        ni = ieee80211_find_node(ic, wh->i_addr2); 
     
    19441901                        return; 
    19451902                } 
    1946                 ieee80211_new_state(&ic->ic_if, IEEE80211_S_ASSOC, 
     1903                ieee80211_new_state(&ic->ic_dev, IEEE80211_S_ASSOC, 
    19471904                    wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 
    19481905                break; 
     
    19511908 
    19521909static void 
    1953 ieee80211_recv_asreq(struct ieee80211com *ic, struct mbuf *m0, int rssi, 
     1910ieee80211_recv_asreq(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 
    19541911    u_int32_t rstamp) 
    19551912{ 
    1956         struct ifnet *ifp = &ic->ic_if
     1913        struct net_device *dev = &ic->ic_dev
    19571914        struct ieee80211_frame *wh; 
    19581915        struct ieee80211_node *ni = &ic->ic_bss; 
     
    19651922                return; 
    19661923 
    1967         wh = mtod(m0, struct ieee80211_frame *)
     1924        wh = (struct ieee80211_frame *) skb0->data
    19681925        frm = (u_int8_t *)&wh[1]; 
    1969         efrm = mtod(m0, u_int8_t *) + m0->m_len; 
     1926        efrm = skb0->data + skb0->len; 
    19701927        if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == 
    19711928            IEEE80211_FC0_SUBTYPE_REASSOC_REQ) { 
     
    19951952                return; 
    19961953        } 
    1997         capinfo = le16toh(*(u_int16_t *)frm); frm += 2; 
    1998         bintval = le16toh(*(u_int16_t *)frm); frm += 2; 
     1954        capinfo = le16_to_cpu(*(u_int16_t *)frm);     frm += 2; 
     1955        bintval = le16_to_cpu(*(u_int16_t *)frm);     frm += 2; 
    19991956        if (reassoc) 
    20001957                frm += 6;       /* ignore current AP info */ 
     
    20251982#ifdef IEEE80211_DEBUG 
    20261983                if (ieee80211_debug) { 
    2027                         printf("ieee80211_recv_asreq: ssid unmatch "); 
     1984                        printk("ieee80211_recv_asreq: ssid unmatch "); 
    20281985                        ieee80211_print_essid(ssid + 2, ssid[1]); 
    2029                         printf(" from %s\n", ether_sprintf(wh->i_addr2)); 
     1986                        printk(" from %s\n", ether_sprintf(wh->i_addr2)); 
    20301987                } 
    20311988#endif 
     
    20782035                newassoc = 0; 
    20792036        IEEE80211_SEND_MGMT(ic, ni, resp, IEEE80211_STATUS_SUCCESS); 
    2080         if (ifp->if_flags & IFF_DEBUG) 
    2081                 if_printf(ifp, "station %s %s associated\n", 
     2037        if (netif_msg_debug(ic)) 
     2038                printk("%s: station %s %s associated\n", 
     2039                    dev->name, 
    20822040                    (newassoc ? "newly" : "already"), 
    20832041                    ether_sprintf(ni->ni_macaddr)); 
     
    20852043 
    20862044static void 
    2087 ieee80211_recv_asresp(struct ieee80211com *ic, struct mbuf *m0, int rssi, 
     2045ieee80211_recv_asresp(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 
    20882046    u_int32_t rstamp) 
    20892047{ 
    2090         struct ifnet *ifp = &ic->ic_if
     2048        struct net_device *dev = &ic->ic_dev
    20912049        struct ieee80211_frame *wh; 
    20922050        struct ieee80211_node *ni = &ic->ic_bss; 
     
    20982056                return; 
    20992057 
    2100         wh = mtod(m0, struct ieee80211_frame *)
     2058        wh = (struct ieee80211_frame *) skb0->data
    21012059        frm = (u_int8_t *)&wh[1]; 
    2102         efrm = mtod(m0, u_int8_t *) + m0->m_len; 
     2060        efrm = skb0->data + skb0->len; 
    21032061        /* 
    21042062         * asresp frame format 
     
    21142072        } 
    21152073 
    2116         ni->ni_capinfo = le16toh(*(u_int16_t *)frm); 
     2074        ni->ni_capinfo = le16_to_cpu(*(u_int16_t *)frm); 
    21172075        frm += 2; 
    21182076 
    2119         status = le16toh(*(u_int16_t *)frm); 
     2077        status = le16_to_cpu(*(u_int16_t *)frm); 
    21202078        frm += 2; 
    21212079        if (status != 0) { 
    2122                 if_printf(ifp, "association failed (reason %d) for %s\n", 
    2123                     status, ether_sprintf(wh->i_addr3)); 
     2080                printk("%s: association failed (reason %d) for %s\n", 
     2081                    dev->name, status, ether_sprintf(wh->i_addr3)); 
    21242082                ni = ieee80211_find_node(ic, wh->i_addr2); 
    21252083                if (ni != NULL) 
     
    21272085                return; 
    21282086        } 
    2129         ni->ni_associd = le16toh(*(u_int16_t *)frm); 
     2087        ni->ni_associd = le16_to_cpu(*(u_int16_t *)frm); 
    21302088        frm += 2; 
    21312089        rates = frm; 
     
    21382096        if (ni->ni_nrate == 0) 
    21392097                return; 
    2140         ieee80211_new_state(ifp, IEEE80211_S_RUN, 
     2098        ieee80211_new_state(&ic->ic_dev, IEEE80211_S_RUN, 
    21412099            wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 
    21422100} 
    21432101 
    21442102static void 
    2145 ieee80211_recv_disassoc(struct ieee80211com *ic, struct mbuf *m0, int rssi, 
     2103ieee80211_recv_disassoc(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 
    21462104    u_int32_t rstamp) 
    21472105{ 
    2148         struct ifnet *ifp = &ic->ic_if
     2106        struct net_device *dev = &ic->ic_dev
    21492107        struct ieee80211_frame *wh; 
    21502108        struct ieee80211_node *ni; 
     
    21522110        u_int16_t reason; 
    21532111 
    2154         wh = mtod(m0, struct ieee80211_frame *)
     2112        wh = (struct ieee80211_frame *) skb0->data
    21552113        frm = (u_int8_t *)&wh[1]; 
    2156         efrm = mtod(m0, u_int8_t *) + m0->m_len; 
     2114        efrm = skb0->data + skb0->len; 
    21572115        /* 
    21582116         * disassoc frame format 
     
    21642122                return; 
    21652123        } 
    2166         reason = le16toh(*(u_int16_t *)frm); 
     2124        reason = le16_to_cpu(*(u_int16_t *)frm); 
    21672125        switch (ic->ic_opmode) { 
    21682126        case IEEE80211_M_STA: 
    2169                 ieee80211_new_state(&ic->ic_if, IEEE80211_S_ASSOC, 
     2127                ieee80211_new_state(&ic->ic_dev, IEEE80211_S_ASSOC, 
    21702128                    wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 
    21712129                break; 
    21722130        case IEEE80211_M_HOSTAP: 
    21732131                if ((ni = ieee80211_find_node(ic, wh->i_addr2)) != NULL) { 
    2174                         if (ifp->if_flags & IFF_DEBUG
    2175                                 if_printf(ifp, "station %s disassociated" 
     2132                        if (netif_msg_debug(ic)
     2133                                printk("%s: station %s disassociated" 
    21762134                                    " by peer (reason %d)\n", 
     2135                                    dev->name, 
    21772136                                    ether_sprintf(ni->ni_macaddr), reason); 
    21782137                        ni->ni_associd = 0; 
     
    21852144 
    21862145static void 
    2187 ieee80211_recv_deauth(struct ieee80211com *ic, struct mbuf *m0, int rssi, 
     2146ieee80211_recv_deauth(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 
    21882147    u_int32_t rstamp) 
    21892148{ 
    2190         struct ifnet *ifp = &ic->ic_if
     2149        struct net_device *dev = &ic->ic_dev
    21912150        struct ieee80211_frame *wh; 
    21922151        struct ieee80211_node *ni; 
     
    21942153        u_int16_t reason; 
    21952154 
    2196         wh = mtod(m0, struct ieee80211_frame *)
     2155        wh = (struct ieee80211_frame *) skb0->data
    21972156        frm = (u_int8_t *)&wh[1]; 
    2198         efrm = mtod(m0, u_int8_t *) + m0->m_len; 
     2157        efrm = skb0->data + skb0->len; 
    21992158        /* 
    22002159         * dauth frame format 
     
    22062165                return; 
    22072166        } 
    2208         reason = le16toh(*(u_int16_t *)frm); 
     2167        reason = le16_to_cpu(*(u_int16_t *)frm); 
    22092168        switch (ic->ic_opmode) { 
    22102169        case IEEE80211_M_STA: 
    2211                 ieee80211_new_state(&ic->ic_if, IEEE80211_S_AUTH, 
     2170                ieee80211_new_state(&ic->ic_dev, IEEE80211_S_AUTH, 
    22122171                    wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 
    22132172                break; 
    22142173        case IEEE80211_M_HOSTAP: 
    22152174                if ((ni = ieee80211_find_node(ic, wh->i_addr2)) != NULL) { 
    2216                         if (ifp->if_flags & IFF_DEBUG
    2217                                 if_printf(ifp, "station %s deauthenticated" 
     2175                        if (netif_msg_debug(ic)
     2176                                printk("%s: station %s deauthenticated" 
    22182177                                    " by peer (reason %d)\n", 
     2178                                    dev->name, 
    22192179                                    ether_sprintf(ni->ni_macaddr), reason); 
    22202180                        ieee80211_free_node(ic, ni); 
     
    22272187 
    22282188int 
    2229 ieee80211_new_state(struct ifnet *ifp, enum ieee80211_state nstate, int mgt) 
    2230 { 
    2231         struct ieee80211com *ic = (void *)ifp
     2189ieee80211_new_state(struct net_device *dev, enum ieee80211_state nstate, int mgt) 
     2190{ 
     2191        struct ieee80211com *ic = (void *)dev
    22322192        struct ieee80211_node *ni = &ic->ic_bss; 
    22332193        int i, error, ostate; 
     
    22412201            stname[ostate], stname[nstate])); 
    22422202        if (ic->ic_newstate) { 
    2243                 error = (*ic->ic_newstate)(ic->ic_softc, nstate); 
     2203                error = (*ic->ic_newstate)(dev, nstate); 
    22442204                if (error == EINPROGRESS) 
    22452205                        return 0; 
     
    22972257                        ic->ic_scan_timer = 0; 
    22982258                        ic->ic_mgt_timer = 0; 
    2299                         IF_DRAIN(&ic->ic_mgtq); 
     2259                        skb_queue_purge(&ic->ic_mgtq); 
    23002260                        if (ic->ic_wep_ctx != NULL) { 
    2301                                 free(ic->ic_wep_ctx, M_DEVBUF); 
     2261                                kfree(ic->ic_wep_ctx); 
    23022262                                ic->ic_wep_ctx = NULL; 
    23032263                        } 
     
    23102270                ni = &ic->ic_bss; 
    23112271                /* initialize bss for probe request */ 
    2312                 IEEE80211_ADDR_COPY(ni->ni_macaddr, ifp->if_broadcastaddr); 
    2313                 IEEE80211_ADDR_COPY(ni->ni_bssid, ifp->if_broadcastaddr); 
     2272                IEEE80211_ADDR_COPY(ni->ni_macaddr, dev->broadcast); 
     2273                IEEE80211_ADDR_COPY(ni->ni_bssid, dev->broadcast); 
    23142274                ni->ni_nrate = 0; 
    23152275                memset(ni->ni_rates, 0, IEEE80211_RATE_SIZE); 
     
    23422302                                        ic->ic_scan_timer = 
    23432303                                            IEEE80211_PSCAN_WAIT; 
    2344                                 ifp->if_timer = 1; 
     2304                                ic->ic_timer = 1; 
    23452305                        } 
    23462306                        break; 
    23472307                case IEEE80211_S_RUN: 
    23482308                        /* beacon miss */ 
    2349                         if (ifp->if_flags & IFF_DEBUG) { 
     2309                        if (netif_msg_debug(ic)) { 
    23502310                                /* XXX bssid clobbered above */ 
    2351                                 if_printf(ifp, "no recent beacons from %s;" 
     2311                                printk("%s: no recent beacons from %s;" 
    23522312                                    " rescanning\n", 
     2313                                    dev->name, 
    23532314                                    ether_sprintf(ic->ic_bss.ni_bssid)); 
    23542315                        } 
     
    24322393                case IEEE80211_S_SCAN:          /* adhoc mode */ 
    24332394                case IEEE80211_S_ASSOC:         /* infra mode */ 
    2434                         if (ifp->if_flags & IFF_DEBUG) { 
    2435                                 if_printf(ifp, " "); 
     2395                        if (netif_msg_debug(ic)) { 
     2396                                printk("%s: ", dev->name); 
    24362397                                if (ic->ic_opmode == IEEE80211_M_STA) 
    2437                                         printf("associated "); 
     2398                                        printk("associated "); 
    24382399                                else 
    2439                                         printf("synchronized "); 
    2440                                 printf("with %s ssid ", 
     2400                                        printk("synchronized "); 
     2401                                printk("with %s ssid ", 
    24412402                                    ether_sprintf(ic->ic_bss.ni_bssid)); 
    24422403                                ieee80211_print_essid(ic->ic_bss.ni_essid, 
    24432404                                    ic->ic_bss.ni_esslen); 
    2444                                 printf(" channel %d\n", ic->ic_bss.ni_chan); 
     2405                                printk(" channel %d\n", ic->ic_bss.ni_chan); 
    24452406                        } 
    24462407                        /* start with highest negotiated rate */ 
    24472408                        ic->ic_bss.ni_txrate = ic->ic_bss.ni_nrate - 1; 
    24482409                        ic->ic_mgt_timer = 0; 
    2449                         (*ifp->if_start)(ifp); 
     2410                        (*ic->ic_start)(dev); 
    24502411                        break; 
    24512412                } 
     
    24552416} 
    24562417 
    2457 struct mbuf * 
    2458 ieee80211_wep_crypt(struct ifnet *ifp, struct mbuf *m0, int txflag) 
    2459 { 
    2460         struct ieee80211com *ic = (void *)ifp
    2461         struct mbuf *m, *n, *n0; 
     2418struct sk_buff * 
     2419ieee80211_wep_crypt(struct net_device *dev, struct sk_buff *skb0, int txflag) 
     2420{ 
     2421        struct ieee80211com *ic = (void *)dev
     2422        struct sk_buff *skb, *n, *n0; 
    24622423        struct ieee80211_frame *wh; 
    24632424        int i, left, len, moff, noff, kid; 
     
    24702431        n0 = NULL; 
    24712432        if ((ctx = ic->ic_wep_ctx) == NULL) { 
    2472                 ctx = malloc(arc4_ctxlen(), M_DEVBUF, M_NOWAIT); 
     2433                ctx = kmalloc(arc4_ctxlen(), GFP_KERNEL); 
    24732434                if (ctx == NULL) 
    24742435                        goto fail; 
    24752436                ic->ic_wep_ctx = ctx; 
    24762437        } 
    2477         m = m0; 
    2478         left = m->m_pkthdr.len; 
    2479         MGET(n, M_NOWAIT, m->m_type); 
    2480         n0 = n; 
     2438        skb = skb0; 
     2439        left = skb->len; 
     2440        len = IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN; 
     2441        if (txflag) { 
     2442                n = dev_alloc_skb(skb->len + len); 
     2443        } else { 
     2444                n = dev_alloc_skb(skb->len - len); 
     2445                left -= len; 
     2446        } 
    24812447        if (n == NULL) 
    24822448                goto fail; 
    2483         M_MOVE_PKTHDR(n, m); 
    2484         len = IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN; 
    2485         if (txflag) { 
    2486                 n->m_pkthdr.len += len; 
    2487         } else { 
    2488                 n->m_pkthdr.len -= len; 
    2489                 left -= len; 
    2490         } 
    2491         n->m_len = MHLEN; 
    2492         if (n->m_pkthdr.len >= MINCLSIZE) { 
    2493                 MCLGET(n, M_NOWAIT); 
    2494                 if (n->m_flags & M_EXT) 
    2495                         n->m_len = n->m_ext.ext_size; 
    2496         } 
    2497         len = sizeof(struct ieee80211_frame); 
    2498         memcpy(mtod(n, caddr_t), mtod(m, caddr_t), len); 
    2499         wh = mtod(n, struct ieee80211_frame *); 
    2500         left -= len; 
    2501         moff = len; 
    2502         noff = len; 
     2449        n0 = n; 
     2450        memcpy(n->data, skb->data, sizeof(struct ieee80211_frame)); 
     2451        wh = (struct ieee80211_frame *) n->data; 
     2452        left -= sizeof(struct ieee80211_frame); 
     2453        moff = sizeof(struct ieee80211_frame); 
     2454        noff = sizeof(struct ieee80211_frame); 
    25032455        if (txflag) { 
    25042456                kid = ic->ic_wep_txkey; 
     
    25142466                ic->ic_iv = iv + 1; 
    25152467                /* put iv in little endian to prepare 802.11i */ 
    2516                 ivp = mtod(n, u_int8_t *) + noff; 
     2468                ivp = n->data + noff; 
    25172469                for (i = 0; i < IEEE80211_WEP_IVLEN; i++) { 
    25182470                        ivp[i] = iv & 0xff; 
     
    25232475        } else { 
    25242476                wh->i_fc[1] &= ~IEEE80211_FC1_WEP; 
    2525                 ivp = mtod(m, u_int8_t *) + moff; 
     2477                ivp = skb->data + moff; 
    25262478                kid = ivp[IEEE80211_WEP_IVLEN] >> 6; 
    25272479                moff += IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN; 
     
    25352487        /* encrypt with calculating CRC */ 
    25362488        crc = ~0; 
    2537         while (left > 0) { 
    2538                 len = m->m_len - moff; 
    2539                 if (len == 0) { 
    2540                         m = m->m_next; 
    2541                         moff = 0; 
    2542                         continue; 
    2543                 } 
    2544                 if (len > n->m_len - noff) { 
    2545                         len = n->m_len - noff; 
    2546                         if (len == 0) { 
    2547                                 MGET(n->m_next, M_NOWAIT, n->m_type); 
    2548                                 if (n->m_next == NULL) 
    2549                                         goto fail; 
    2550                                 n = n->m_next; 
    2551                                 n->m_len = MLEN; 
    2552                                 if (left >= MINCLSIZE) { 
    2553                                         MCLGET(n, M_NOWAIT); 
    2554                                         if (n->m_flags & M_EXT) 
    2555                                                 n->m_len = n->m_ext.ext_size; 
    2556                                 } 
    2557                                 noff = 0; 
    2558                                 continue; 
    2559                         } 
    2560                 } 
    2561                 if (len > left) 
    2562                         len = left; 
    2563                 arc4_encrypt(ctx, mtod(n, caddr_t) + noff, 
    2564                     mtod(m, caddr_t) + moff, len); 
    2565                 if (txflag) 
    2566                         crc = ieee80211_crc_update(crc, 
    2567                             mtod(m, u_int8_t *) + moff, len); 
    2568                 else 
    2569                         crc = ieee80211_crc_update(crc, 
    2570                             mtod(n, u_int8_t *) + noff, len); 
    2571                 left -= len; 
    2572                 moff += len; 
    2573                 noff += len; 
     2489        arc4_encrypt(ctx, n->data + noff, skb->data + moff, left); 
     2490        if (txflag) { 
     2491                crc = ieee80211_crc_update(crc, skb->data + moff, left); 
     2492                moff += left; 
     2493        } else { 
     2494                crc = ieee80211_crc_update(crc, n->data + noff, left); 
     2495                noff += left; 
    25742496        } 
    25752497        crc = ~crc; 
    25762498        if (txflag) { 
    2577                 *(u_int32_t *)crcbuf = htole32(crc); 
    2578                 if (n->m_len >= noff + sizeof(crcbuf)) 
    2579                         n->m_len = noff + sizeof(crcbuf); 
    2580                 else { 
    2581                         n->m_len = noff; 
    2582                         MGET(n->m_next, M_NOWAIT, n->m_type); 
    2583                         if (n->m_next == NULL) 
    2584                                 goto fail; 
    2585                         n = n->m_next; 
    2586                         n->m_len = sizeof(crcbuf); 
    2587                         noff = 0; 
    2588                 } 
    2589                 arc4_encrypt(ctx, mtod(n, caddr_t) + noff, crcbuf, 
    2590                     sizeof(crcbuf)); 
     2499                *(u_int32_t *)crcbuf = cpu_to_le32(crc); 
     2500                arc4_encrypt(ctx, n->data + noff, crcbuf, sizeof(crcbuf)); 
    25912501        } else { 
    2592                 n->m_len = noff; 
    2593                 for (noff = 0; noff < sizeof(crcbuf); noff += len) { 
    2594                         len = sizeof(crcbuf) - noff; 
    2595                         if (len > m->m_len - moff) 
    2596                                 len = m->m_len - moff; 
    2597                         if (len > 0) 
    2598                                 arc4_encrypt(ctx, crcbuf + noff, 
    2599                                     mtod(m, caddr_t) + moff, len); 
    2600                         m = m->m_next; 
    2601                         moff = 0; 
    2602                 } 
    2603                 if (crc != le32toh(*(u_int32_t *)crcbuf)) { 
     2502                arc4_encrypt(ctx, crcbuf, skb->data + moff, sizeof(crcbuf)); 
     2503                if (crc != le32_to_cpu(*(u_int32_t *)crcbuf)) { 
    26042504#ifdef IEEE80211_DEBUG 
    26052505                        if (ieee80211_debug) { 
    2606                                 if_printf(ifp, "decrypt CRC error\n"); 
     2506                                printk("%s: decrypt CRC error\n", dev->name); 
    26072507                                if (ieee80211_debug > 1) 
    2608                                         ieee80211_dump_pkt(n0->m_data, 
    2609                                             n0->m_len, -1, -1); 
     2508                                        ieee80211_dump_pkt(n0->data, 
     2509                                            n0->len, -1, -1); 
    26102510                        } 
    26112511#endif 
     
    26132513                } 
    26142514        } 
    2615         m_freem(m0); 
     2515        dev_kfree_skb(skb0); 
    26162516        return n0; 
    26172517 
    26182518  fail: 
    2619         m_freem(m0); 
    2620         m_freem(n0); 
     2519        dev_kfree_skb(skb0); 
     2520        dev_kfree_skb(n0); 
    26212521        return NULL; 
    26222522} 
     
    28062706 
    28072707int 
    2808 ieee80211_cfgget(struct ifnet *ifp, u_long cmd, caddr_t data) 
    2809 { 
    2810         struct ieee80211com *ic = (void *)ifp
     2708ieee80211_cfgget(struct net_device *dev, u_long cmd, caddr_t data) 
     2709{ 
     2710        struct ieee80211com *ic = (void *)dev
    28112711        int i, j, error; 
    28122712        struct ifreq *ifr = (struct ifreq *)data; 
     
    28172717        struct wi_sigcache wsc; 
    28182718 
    2819         error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); 
     2719        error = copy_from_user(&wreq, ifr->ifr_data, sizeof(wreq)); 
    28202720        if (error) 
    28212721                return error; 
     
    28262726                break; 
    28272727        case WI_RID_NODENAME: 
    2828                 strcpy((char *)&wreq.wi_val[1], hostname); 
    2829                 wreq.wi_val[0] = htole16(strlen(hostname)); 
    2830                 wreq.wi_len = (1 + strlen(hostname) + 1) / 2; 
     2728                strcpy((char *)&wreq.wi_val[1], system_utsname.nodename); 
     2729                wreq.wi_val[0] = cpu_to_le16(strlen(system_utsname.nodename)); 
     2730                wreq.wi_len = (1 + strlen(system_utsname.nodename) + 1) / 2; 
    28312731                break; 
    28322732        case WI_RID_CURRENT_SSID: 
     
    28362736                        break; 
    28372737                } 
    2838                 wreq.wi_val[0] = htole16(ic->ic_bss.ni_esslen); 
     2738                wreq.wi_val[0] = cpu_to_le16(ic->ic_bss.ni_esslen); 
    28392739                memcpy(&wreq.wi_val[1], ic->ic_bss.ni_essid, 
    28402740                    ic->ic_bss.ni_esslen); 
     
    28432743        case WI_RID_OWN_SSID: 
    28442744        case WI_RID_DESIRED_SSID: 
    2845                 wreq.wi_val[0] = htole16(ic->ic_des_esslen); 
     2745                wreq.wi_val[0] = cpu_to_le16(ic->ic_des_esslen); 
    28462746                memcpy(&wreq.wi_val[1], ic->ic_des_essid, ic->ic_des_esslen); 
    28472747                wreq.wi_len = (1 + ic->ic_des_esslen + 1) / 2; 
     
    28722772                break; 
    28732773        case WI_RID_OWN_CHNL: 
    2874                 wreq.wi_val[0] = htole16(ic->ic_ibss_chan); 
     2774                wreq.wi_val[0] = cpu_to_le16(ic->ic_ibss_chan); 
    28752775                wreq.wi_len = 1; 
    28762776                break; 
    28772777        case WI_RID_CURRENT_CHAN: 
    2878                 wreq.wi_val[0] = htole16(ic->ic_bss.ni_chan); 
     2778                wreq.wi_val[0] = cpu_to_le16(ic->ic_bss.ni_chan); 
    28792779                wreq.wi_len = 1; 
    28802780                break; 
    28812781        case WI_RID_COMMS_QUALITY: 
    28822782                wreq.wi_val[0] = 0;                             /* quality */ 
    2883                 wreq.wi_val[1] = htole16(ic->ic_bss.ni_rssi); /* signal */ 
     2783                wreq.wi_val[1] = cpu_to_le16(ic->ic_bss.ni_rssi);     /* signal */ 
    28842784                wreq.wi_val[2] = 0;                             /* noise */ 
    28852785                wreq.wi_len = 3; 
    28862786                break; 
    28872787        case WI_RID_PROMISC: 
    2888                 wreq.wi_val[0] = htole16((ifp->if_flags & IFF_PROMISC) ? 1 : 0); 
     2788                wreq.wi_val[0] = cpu_to_le16((dev->flags & IFF_PROMISC) ? 1 : 0); 
    28892789                wreq.wi_len = 1; 
    28902790                break; 
    28912791        case WI_RID_PORTTYPE: 
    2892                 wreq.wi_val[0] = htole16(ic->ic_opmode); 
     2792                wreq.wi_val[0] = cpu_to_le16(ic->ic_opmode); 
    28932793                wreq.wi_len = 1; 
    28942794                break; 
     
    29012801                        wreq.wi_val[0] = 0;     /* auto */ 
    29022802                else 
    2903                         wreq.wi_val[0] = htole16( 
     2803                        wreq.wi_val[0] = cpu_to_le16( 
    29042804                            (ic->ic_sup_rates[ic->ic_fixed_rate] & 
    29052805                            IEEE80211_RATE_VAL) / 2); 
     
    29072807                break; 
    29082808        case WI_RID_CUR_TX_RATE: 
    2909                 wreq.wi_val[0] = htole16( 
     2809                wreq.wi_val[0] = cpu_to_le16( 
    29102810                    (ic->ic_bss.ni_rates[ic->ic_bss.ni_txrate] & 
    29112811                    IEEE80211_RATE_VAL) / 2); 
     
    29132813                break; 
    29142814        case WI_RID_RTS_THRESH: 
    2915                 wreq.wi_val[0] = htole16(IEEE80211_MAX_LEN);  /* TODO: RTS */ 
     2815                wreq.wi_val[0] = cpu_to_le16(IEEE80211_MAX_LEN);      /* TODO: RTS */ 
    29162816                wreq.wi_len = 1; 
    29172817                break; 
    29182818        case WI_RID_CREATE_IBSS: 
    29192819                wreq.wi_val[0] = 
    2920                     htole16((ic->ic_flags & IEEE80211_F_IBSSON) ? 1 : 0); 
     2820                    cpu_to_le16((ic->ic_flags & IEEE80211_F_IBSSON) ? 1 : 0); 
    29212821                wreq.wi_len = 1; 
    29222822                break; 
     
    29262826                break; 
    29272827        case WI_RID_ROAMING_MODE: 
    2928                 wreq.wi_val[0] = htole16(1);  /* enabled ... not supported */ 
     2828                wreq.wi_val[0] = cpu_to_le16(1);      /* enabled ... not supported */ 
    29292829                wreq.wi_len = 1; 
    29302830                break; 
    29312831        case WI_RID_SYSTEM_SCALE: 
    2932                 wreq.wi_val[0] = htole16(1);  /* low density ... not supp */ 
     2832                wreq.wi_val[0] = cpu_to_le16(1);      /* low density ... not supp */ 
    29332833                wreq.wi_len = 1; 
    29342834                break; 
    29352835        case WI_RID_PM_ENABLED: 
    29362836                wreq.wi_val[0] = 
    2937                     htole16((ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0); 
     2837                    cpu_to_le16((ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0); 
    29382838                wreq.wi_len = 1; 
    29392839                break; 
    29402840        case WI_RID_MAX_SLEEP: 
    2941                 wreq.wi_val[0] = htole16(ic->ic_lintval); 
     2841                wreq.wi_val[0] = cpu_to_le16(ic->ic_lintval); 
    29422842                wreq.wi_len = 1; 
    29432843                break; 
    29442844        case WI_RID_CUR_BEACON_INT: 
    2945                 wreq.wi_val[0] = htole16(ic->ic_bss.ni_intval); 
     2845                wreq.wi_val[0] = cpu_to_le16(ic->ic_bss.ni_intval); 
    29462846                wreq.wi_len = 1; 
    29472847                break; 
    29482848        case WI_RID_WEP_AVAIL: 
    29492849                wreq.wi_val[0] = 
    2950                     htole16((ic->ic_flags & IEEE80211_F_HASWEP) ? 1 : 0); 
     2850                    cpu_to_le16((ic->ic_flags & IEEE80211_F_HASWEP) ? 1 : 0); 
    29512851                wreq.wi_len = 1; 
    29522852                break; 
    29532853        case WI_RID_CNFAUTHMODE: 
    2954                 wreq.wi_val[0] = htole16(1);  /* TODO: open system only */ 
     2854                wreq.wi_val[0] = cpu_to_le16(1);      /* TODO: open system only */ 
    29552855                wreq.wi_len = 1; 
    29562856                break; 
    29572857        case WI_RID_ENCRYPTION: 
    29582858                wreq.wi_val[0] = 
    2959                     htole16((ic->ic_flags & IEEE80211_F_WEPON) ? 1 : 0); 
     2859                    cpu_to_le16((ic->ic_flags & IEEE80211_F_WEPON) ? 1 : 0); 
    29602860                wreq.wi_len = 1; 
    29612861                break; 
    29622862        case WI_RID_TX_CRYPT_KEY: 
    2963                 wreq.wi_val[0] = htole16(ic->ic_wep_txkey); 
     2863                wreq.wi_val[0] = cpu_to_le16(ic->ic_wep_txkey); 
    29642864                wreq.wi_len = 1; 
    29652865                break; 
     
    29672867                keys = (struct wi_ltv_keys *)&wreq; 
    29682868                /* do not show keys to non-root user */ 
    2969                 error = suser(curthread); 
    2970                 if (error) { 
     2869                if (!capable(CAP_SYS_ADMIN)) { 
    29712870                        memset(keys, 0, sizeof(*keys)); 
    2972                         error = 0; 
    29732871                        break; 
    29742872                } 
    29752873                for (i = 0; i < IEEE80211_WEP_NKID; i++) { 
    29762874                        keys->wi_keys[i].wi_keylen = 
    2977                             htole16(ic->ic_nw_keys[i].wk_len); 
     2875                            cpu_to_le16(ic->ic_nw_keys[i].wk_len); 
    29782876                        memcpy(keys->wi_keys[i].wi_keydat, 
    29792877                            ic->ic_nw_keys[i].wk_key, ic->ic_nw_keys[i].wk_len); 
     
    29822880                break; 
    29832881        case WI_RID_MAX_DATALEN: 
    2984                 wreq.wi_val[0] = htole16(IEEE80211_MAX_LEN);  /* TODO: frag */ 
     2882                wreq.wi_val[0] = cpu_to_le16(IEEE80211_MAX_LEN);      /* TODO: frag */ 
    29852883                wreq.wi_len = 1; 
    29862884                break; 
     
    29912889                if (ic->ic_opmode != IEEE80211_M_HOSTAP) { 
    29922890                        for (i = 0; i < IEEE80211_PSCAN_WAIT; i++) { 
    2993                                 tsleep((caddr_t)ic, PWAIT | PCATCH, "i80211", 
    2994                                     hz); 
     2891                                /* XXX is this interruptible? */ 
     2892                                (void) schedule_timeout(HZ); 
    29952893                                if (ic->ic_state != IEEE80211_S_SCAN || 
    29962894                                    (ic->ic_flags & IEEE80211_F_SCANAP) == 0 || 
     
    30622960        if (error == 0) { 
    30632961                wreq.wi_len++; 
    3064                 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq)); 
     2962                error = copy_to_user(ifr->ifr_data, &wreq, sizeof(wreq)); 
    30652963        } 
    30662964        return error; 
     
    30682966 
    30692967int 
    3070 ieee80211_cfgset(struct ifnet *ifp, u_long cmd, caddr_t data) 
    3071 { 
    3072         struct ieee80211com *ic = (void *)ifp
     2968ieee80211_cfgset(struct net_device *dev, u_long cmd, caddr_t data) 
     2969{ 
     2970        struct ieee80211com *ic = (void *)dev
    30732971        int i, j, len, error; 
    30742972        struct ifreq *ifr = (struct ifreq *)data; 
     
    30772975        u_char chanlist[roundup(IEEE80211_CHAN_MAX, NBBY)]; 
    30782976 
    3079         error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); 
     2977        error = copy_from_user(&wreq, ifr->ifr_data, sizeof(wreq)); 
    30802978        if (error) 
    30812979                return error; 
     
    30902988        case WI_RID_OWN_SSID: 
    30912989        case WI_RID_DESIRED_SSID: 
    3092                 len = le16toh(wreq.wi_val[0]); 
     2990                len = le16_to_cpu(wreq.wi_val[0]); 
    30932991                if (wreq.wi_len < (1 + len + 1) / 2) 
    30942992                        return EINVAL; 
     
    31053003                if (wreq.wi_len != 1) 
    31063004                        return EINVAL; 
    3107                 i = le16toh(wreq.wi_val[0]); 
     3005                i = le16_to_cpu(wreq.wi_val[0]); 
    31083006                if (i < 0 || 
    31093007                    i > IEEE80211_CHAN_MAX || 
     
    31213019                if (wreq.wi_len != 1) 
    31223020                        return EINVAL; 
    3123                 if (ifp->if_flags & IFF_PROMISC) { 
     3021                if (dev->flags & IFF_PROMISC) { 
    31243022                        if (wreq.wi_val[0] == 0) { 
    3125                                 ifp->if_flags &= ~IFF_PROMISC
     3023                                dev_set_promiscuity(dev, dev->promiscuity)
    31263024                                error = ENETRESET; 
    31273025                        } 
    31283026                } else { 
    31293027                        if (wreq.wi_val[0] != 0) { 
    3130                                 ifp->if_flags |= IFF_PROMISC
     3028                                dev_set_promiscuity(dev, 1)
    31313029                                error = ENETRESET; 
    31323030                        } 
     
    31363034                if (wreq.wi_len != 1) 
    31373035                        return EINVAL; 
    3138                 switch (le16toh(wreq.wi_val[0])) { 
     3036                switch (le16_to_cpu(wreq.wi_val[0])) { 
    31393037                case IEEE80211_M_STA: 
    31403038                        break; 
     
    31553053                        return EINVAL; 
    31563054                } 
    3157                 if (le16toh(wreq.wi_val[0]) != ic->ic_opmode) { 
    3158                         ic->ic_opmode = le16toh(wreq.wi_val[0]); 
     3055                if (le16_to_cpu(wreq.wi_val[0]) != ic->ic_opmode) { 
     3056                        ic->ic_opmode = le16_to_cpu(wreq.wi_val[0]); 
    31593057                        error = ENETRESET; 
    31603058                } 
     
    31783076                } 
    31793077                for (i = 0; i < IEEE80211_RATE_SIZE; i++) { 
    3180                         if (le16toh(wreq.wi_val[0]) == 
     3078                        if (le16_to_cpu(wreq.wi_val[0]) == 
    31813079                            (ic->ic_sup_rates[i] & IEEE80211_RATE_VAL) / 2) 
    31823080                                break; 
     
    31933091                if (wreq.wi_len != 1) 
    31943092                        return EINVAL; 
    3195                 if (le16toh(wreq.wi_val[0]) != IEEE80211_MAX_LEN) 
     3093                if (le16_to_cpu(wreq.wi_val[0]) != IEEE80211_MAX_LEN) 
    31963094                        return EINVAL;          /* TODO: RTS */ 
    31973095                break; 
     
    32273125                if (wreq.wi_len != 1) 
    32283126                        return EINVAL; 
    3229                 if (le16toh(wreq.wi_val[0]) != 1) 
     3127                if (le16_to_cpu(wreq.wi_val[0]) != 1) 
    32303128                        return EINVAL;          /* not supported */ 
    32313129                break; 
     
    32333131                if (wreq.wi_len != 1) 
    32343132                        return EINVAL; 
    3235                 if (le16toh(wreq.wi_val[0]) != 1) 
     3133                if (le16_to_cpu(wreq.wi_val[0]) != 1) 
    32363134                        return EINVAL;          /* not supported */ 
    32373135                break; 
     
    32563154                if (wreq.wi_len != 1) 
    32573155                        return EINVAL; 
    3258                 ic->ic_lintval = le16toh(wreq.wi_val[0]); 
     3156                ic->ic_lintval = le16_to_cpu(wreq.wi_val[0]); 
    32593157                if (ic->ic_flags & IEEE80211_F_PMGTON) 
    32603158                        error = ENETRESET; 
     
    32673165                if (wreq.wi_len != 1) 
    32683166                        return EINVAL; 
    3269                 if (le16toh(wreq.wi_val[0]) != 1) 
     3167                if (le16_to_cpu(wreq.wi_val[0]) != 1) 
    32703168                        return EINVAL;          /* TODO: shared key auth */ 
    32713169                break; 
     
    32903188                if (wreq.wi_len != 1) 
    32913189                        return EINVAL; 
    3292                 i = le16toh(wreq.wi_val[0]); 
     3190                i = le16_to_cpu(wreq.wi_val[0]); 
    32933191                if (i >= IEEE80211_WEP_NKID) 
    32943192                        return EINVAL; 
     
    33003198                keys = (struct wi_ltv_keys *)&wreq; 
    33013199                for (i = 0; i < IEEE80211_WEP_NKID; i++) { 
    3302                         len = le16toh(keys->wi_keys[i].wi_keylen); 
     3200                        len = le16_to_cpu(keys->wi_keys[i].wi_keylen); 
    33033201                        if (len != 0 && len < IEEE80211_WEP_KEYLEN) 
    33043202                                return EINVAL; 
     
    33083206                memset(ic->ic_nw_keys, 0, sizeof(ic->ic_nw_keys)); 
    33093207                for (i = 0; i < IEEE80211_WEP_NKID; i++) { 
    3310                         len = le16toh(keys->wi_keys[i].wi_keylen); 
     3208                        len = le16_to_cpu(keys->wi_keys[i].wi_keylen); 
    33113209                        ic->ic_nw_keys[i].wk_len = len; 
    33123210                        memcpy(ic->ic_nw_keys[i].wk_key, 
     
    33183216                if (wreq.wi_len != 1) 
    33193217                        return EINVAL; 
    3320                 len = le16toh(wreq.wi_val[0]); 
     3218                len = le16_to_cpu(wreq.wi_val[0]); 
    33213219                if (len < 350 /* ? */ || len > IEEE80211_MAX_LEN) 
    33223220                        return EINVAL; 
     
    33563254                } 
    33573255                if (error == EPERM && ic->ic_chancheck != NULL) 
    3358                         error = (*ic->ic_chancheck)(ic->ic_softc, chanlist); 
     3256                        error = (*ic->ic_chancheck)(dev, chanlist); 
    33593257                if (error) 
    33603258                        return error; 
     
    33743272                else { 
    33753273                        ic->ic_flags |= IEEE80211_F_SCANAP; 
    3376                         error = ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1); 
     3274                        error = ieee80211_new_state(dev, IEEE80211_S_SCAN, -1); 
    33773275                } 
    33783276                break; 
     
    33863284/* 
    33873285 * Module glue. 
    3388  * 
    3389  * NB: the module name is "wlan" for compatibility with NetBSD. 
    33903286 */ 
    3391  
    3392 static int 
    3393 ieee80211_modevent(module_t mod, int type, void *unused) 
    3394 
    3395         switch (type) { 
    3396         case MOD_LOAD: 
    3397                 if (bootverbose) 
    3398                         printf("wlan: <802.11 Link Layer>\n"); 
    3399                 return 0; 
    3400         case MOD_UNLOAD: 
    3401                 return 0; 
    3402         } 
    3403         return EINVAL; 
    3404 
    3405  
    3406 static moduledata_t ieee80211_mod = { 
    3407         "wlan", 
    3408         ieee80211_modevent, 
    3409         0 
    3410 }; 
    3411 DECLARE_MODULE(wlan, ieee80211_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST); 
    3412 MODULE_VERSION(wlan, 1); 
    3413 MODULE_DEPEND(wlan, rc4, 1, 1, 1); 
     3287static  char *version = "802.11 Wireless Support (Sam Leffler <sam@errno.com>)"; 
     3288static  char *dev_info = "wlan"; 
     3289 
     3290MODULE_AUTHOR("Errno Consulting, Sam Leffler"); 
     3291MODULE_DESCRIPTION("802.11 wireless LAN protocol support"); 
     3292#ifdef MODULE_LICENSE 
     3293MODULE_LICENSE("Dual BSD/GPL");         /* XXX really BSD only */ 
     3294#endif 
     3295 
     3296EXPORT_SYMBOL(ieee80211_ifattach); 
     3297EXPORT_SYMBOL(ieee80211_ifdetach); 
     3298EXPORT_SYMBOL(ieee80211_input); 
     3299EXPORT_SYMBOL(ieee80211_mgmt_output); 
     3300EXPORT_SYMBOL(ieee80211_encap); 
     3301EXPORT_SYMBOL(ieee80211_decap); 
     3302EXPORT_SYMBOL(ieee80211_ioctl); 
     3303EXPORT_SYMBOL(ieee80211_print_essid); 
     3304EXPORT_SYMBOL(ieee80211_dump_pkt); 
     3305EXPORT_SYMBOL(ieee80211_watchdog); 
     3306EXPORT_SYMBOL(ieee80211_next_scan); 
     3307EXPORT_SYMBOL(ieee80211_end_scan); 
     3308EXPORT_SYMBOL(ieee80211_alloc_node); 
     3309EXPORT_SYMBOL(ieee80211_find_node); 
     3310EXPORT_SYMBOL(ieee80211_free_node); 
     3311EXPORT_SYMBOL(ieee80211_free_allnodes); 
     3312EXPORT_SYMBOL(ieee80211_fix_rate); 
     3313EXPORT_SYMBOL(ieee80211_new_state); 
     3314EXPORT_SYMBOL(ieee80211_wep_crypt); 
     3315EXPORT_SYMBOL(ieee80211_rate2media); 
     3316EXPORT_SYMBOL(ieee80211_media2rate); 
     3317 
     3318EXPORT_SYMBOL(ieee80211_cfgget); 
     3319EXPORT_SYMBOL(ieee80211_cfgset); 
     3320 
     3321static int __init 
     3322init_wlan(void) 
     3323
     3324        printk(KERN_INFO "%s: %s\n", dev_info, version); 
     3325        return 0; 
     3326
     3327module_init(init_wlan); 
     3328 
     3329static void __exit 
     3330exit_wlan(void) 
     3331
     3332        printk(KERN_INFO "%s: driver unloaded\n", dev_info); 
     3333
     3334module_exit(exit_wlan);