Changeset 4
- Timestamp:
- 03/15/03 19:30:16 (7 years ago)
- Files:
-
- cvs-import/trunk/wlan/Makefile (added)
- cvs-import/trunk/wlan/if_ethersubr.h (added)
- cvs-import/trunk/wlan/if_ieee80211.h (modified) (8 diffs)
- cvs-import/trunk/wlan/if_ieee80211subr.c (modified) (133 diffs)
- cvs-import/trunk/wlan/if_llc.h (added)
- cvs-import/trunk/wlan/rc4.c (added)
- cvs-import/trunk/wlan/rc4.h (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cvs-import/trunk/wlan/if_ieee80211.h
r3 r4 38 38 #define _NET_IF_IEEE80211_H_ 39 39 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 48 53 49 54 /* … … 290 295 */ 291 296 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 292 304 /* nwid is pointed at by ifr.ifr_data */ 293 305 struct ieee80211_nwid { … … 402 414 #define IEEE80211_IOC_POWERSAVESLEEP 11 403 415 404 #ifdef _ KERNEL416 #ifdef __KERNEL__ 405 417 406 418 #define IEEE80211_ASCAN_WAIT 2 /* active scan wait */ … … 500 512 501 513 struct 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 *); 509 518 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 */ 511 523 int (*ic_send_mgmt[16])(struct ieee80211com *, 512 524 struct ieee80211_node *, int, int); … … 517 529 u_char ic_chan_avail[roundup(IEEE80211_CHAN_MAX,NBBY)]; 518 530 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; 522 532 int ic_flags; 523 533 enum ieee80211_phytype ic_phytype; … … 546 556 u_int32_t ic_iv; /* initial vector for wep */ 547 557 }; 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) 559 560 560 561 #define IEEE80211_SEND_MGMT(ic,ni,type,arg) do { \ … … 589 590 #define IEEE80211_F_DODEL 0x00000008 /* delete ignore rate */ 590 591 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 596 int ieee80211_ifattach(struct net_device *); 597 void ieee80211_ifdetach(struct net_device *); 598 void ieee80211_input(struct net_device *, struct sk_buff *, int, u_int32_t); 599 int ieee80211_mgmt_output(struct net_device *, struct ieee80211_node *, 600 struct sk_buff *, int); 601 struct sk_buff *ieee80211_encap(struct net_device *, struct sk_buff *); 602 struct sk_buff *ieee80211_decap(struct net_device *, struct sk_buff *); 603 int ieee80211_ioctl(struct net_device *, u_long, caddr_t); 599 604 void ieee80211_print_essid(u_int8_t *, int); 600 605 void 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*);606 void ieee80211_watchdog(struct net_device *); 607 void ieee80211_next_scan(struct net_device *); 608 void ieee80211_end_scan(struct net_device *); 604 609 struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *, u_int8_t *, 605 610 int); … … 608 613 void ieee80211_free_allnodes(struct ieee80211com *); 609 614 int 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);615 int ieee80211_new_state(struct net_device *, enum ieee80211_state, int); 616 struct sk_buff *ieee80211_wep_crypt(struct net_device *, struct sk_buff *, int); 612 617 int ieee80211_rate2media(int, enum ieee80211_phytype); 613 618 int ieee80211_media2rate(int, enum ieee80211_phytype); 614 619 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*/620 int ieee80211_cfgget(struct net_device *, u_long, caddr_t); 621 int ieee80211_cfgset(struct net_device *, u_long, caddr_t); 622 623 #endif /* __KERNEL__ */ 619 624 620 625 #endif /* _NET_IF_IEEE80211_H_ */ cvs-import/trunk/wlan/if_ieee80211subr.c
r3 r4 42 42 */ 43 43 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" 63 60 #define arc4_ctxlen() sizeof (struct rc4_state) 64 61 #define arc4_setkey(_c,_k,_l) rc4_init(_c,_k,_l) 65 62 #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) 84 76 85 77 #define IEEE80211_DEBUG 86 78 #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"); 79 static int ieee80211_debug = 0; 80 #define DPRINTF(X) if (ieee80211_debug) printk X 81 #define DPRINTF2(X) if (ieee80211_debug>1) printk X 93 82 #else 94 83 #define DPRINTF(X) … … 124 113 125 114 static void ieee80211_recv_beacon(struct ieee80211com *, 126 struct mbuf *, int, u_int32_t);115 struct sk_buff *, int, u_int32_t); 127 116 static void ieee80211_recv_prreq(struct ieee80211com *, 128 struct mbuf *, int, u_int32_t);117 struct sk_buff *, int, u_int32_t); 129 118 static void ieee80211_recv_auth(struct ieee80211com *, 130 struct mbuf *, int, u_int32_t);119 struct sk_buff *, int, u_int32_t); 131 120 static void ieee80211_recv_asreq(struct ieee80211com *, 132 struct mbuf *, int, u_int32_t);121 struct sk_buff *, int, u_int32_t); 133 122 static void ieee80211_recv_asresp(struct ieee80211com *, 134 struct mbuf *, int, u_int32_t);123 struct sk_buff *, int, u_int32_t); 135 124 static void ieee80211_recv_disassoc(struct ieee80211com *, 136 struct mbuf *, int, u_int32_t);125 struct sk_buff *, int, u_int32_t); 137 126 static void ieee80211_recv_deauth(struct ieee80211com *, 138 struct mbuf *, int, u_int32_t);127 struct sk_buff *, int, u_int32_t); 139 128 140 129 static void ieee80211_crc_init(void); … … 148 137 }; 149 138 150 void 151 ieee80211_ifattach(struct ifnet *ifp) 152 { 153 struct ieee80211com *ic = (void *)ifp; 139 /* 140 * Format an Ethernet MAC for printing. 141 */ 142 static const char* 143 ether_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 151 int 152 ieee80211_ifattach(struct net_device *dev) 153 { 154 struct ieee80211com *ic = (void *)dev; 154 155 int i, rate; 155 156 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 164 165 ieee80211_crc_init(); 165 ic->ic_iv = arc4random();166 get_random_bytes(&ic->ic_iv, sizeof(ic->ic_iv)); 166 167 memcpy(ic->ic_chan_active, ic->ic_chan_avail, 167 168 sizeof(ic->ic_chan_active)); … … 179 180 ic->ic_lintval = 100; /* default sleep */ 180 181 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 183 185 rate = 0; 184 186 for (i = 0; i < IEEE80211_RATE_SIZE; i++) { … … 189 191 ifp->if_baudrate = IF_Mbps(rate); 190 192 ifp->if_hdrlen = sizeof(struct ieee80211_frame); 193 #endif 191 194 192 195 /* initialize management frame handler */ … … 230 233 ic->ic_send_mgmt[IEEE80211_FC0_SUBTYPE_DISASSOC 231 234 >> IEEE80211_FC0_SUBTYPE_SHIFT] = ieee80211_send_disassoc; 235 236 return (0); 232 237 } 233 238 234 239 void 235 ieee80211_ifdetach(struct ifnet *ifp)236 { 237 struct ieee80211com *ic = (void *) ifp;240 ieee80211_ifdetach(struct net_device *dev) 241 { 242 struct ieee80211com *ic = (void *)dev; 238 243 239 244 IEEE80211_LOCK(ic); 240 IF_DRAIN(&ic->ic_mgtq); 241 mtx_destroy(&ic->ic_mgtq.ifq_mtx); 245 skb_queue_purge(&ic->ic_mgtq); 242 246 if (ic->ic_wep_ctx != NULL) { 243 free(ic->ic_wep_ctx, M_DEVBUF);247 kfree(ic->ic_wep_ctx); 244 248 ic->ic_wep_ctx = NULL; 245 249 } 246 250 ieee80211_free_allnodes(ic); 247 #if NBPFILTER > 0 248 bpfdetach(ifp); 249 #endif 250 ether_ifdetach(ifp); 251 unregister_netdev(&ic->ic_dev); 251 252 IEEE80211_UNLOCK(ic); 252 mtx_destroy(&ic->ic_mtx);253 253 } 254 254 255 255 void 256 ieee80211_input(struct ifnet *ifp, struct mbuf *m, int rssi, u_int32_t rstamp) 257 { 258 struct ieee80211com *ic = (void *)ifp; 256 ieee80211_input(struct net_device *dev, struct sk_buff *skb, 257 int rssi, u_int32_t rstamp) 258 { 259 struct ieee80211com *ic = (void *)dev; 259 260 struct ieee80211_node *ni = NULL; 260 261 struct ieee80211_frame *wh; 261 262 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; 264 265 int len; 265 266 u_int8_t dir, subtype; … … 267 268 u_int16_t rxseq; 268 269 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; 276 271 if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) != 277 272 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]); 281 276 goto err; 282 277 } … … 303 298 bssid = wh->i_addr1; 304 299 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)) { 306 301 /* not interested in */ 307 302 DPRINTF2(("ieee80211_input: other bss %s\n", … … 321 316 rxseq = ni->ni_rxseq; 322 317 ni->ni_rxseq = 323 le16 toh(*(u_int16_t *)wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT;318 le16_to_cpu(*(u_int16_t *)wh->i_seq) >> IEEE80211_SEQ_SEQ_SHIFT; 324 319 /* TODO: fragment */ 325 320 if ((wh->i_fc[1] & IEEE80211_FC1_RETRY) && … … 337 332 if (dir != IEEE80211_FC1_DIR_FROMDS) 338 333 goto out; 334 #ifdef IFF_SIMPLEX 339 335 if ((ifp->if_flags & IFF_SIMPLEX) && 340 336 IEEE80211_IS_MULTICAST(wh->i_addr1) && … … 348 344 goto out; 349 345 } 346 #endif 350 347 break; 351 348 case IEEE80211_M_IBSS: … … 385 382 if (wh->i_fc[1] & IEEE80211_FC1_WEP) { 386 383 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) 389 386 goto err; 390 wh = mtod(m, struct ieee80211_frame *);387 wh = (struct ieee80211_frame *) skb->data; 391 388 } else 392 389 goto out; 393 390 } 394 391 /* 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) 401 394 goto err; 402 i fp->if_ipackets++;395 ic->ic_stats.rx_packets++; 403 396 404 397 /* perform as a bridge within the AP */ 405 m1 = NULL;398 skb1 = NULL; 406 399 if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 407 eh = mtod(m, struct ether_header *);400 eh = (struct ether_header *) skb->data; 408 401 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++; 414 405 } else { 415 406 ni = ieee80211_find_node(ic, eh->ether_dhost); 416 407 if (ni != NULL && ni->ni_associd != 0) { 417 m1 = m;418 m= NULL;408 skb1 = skb; 409 skb = NULL; 419 410 } 420 411 } 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 } 436 428 return; 437 429 … … 454 446 } 455 447 456 if ( ifp->if_flags & IFF_DEBUG) {448 if (netif_msg_debug(ic)) { 457 449 /* avoid to print too many frames */ 458 450 int doprint = 0; … … 475 467 #endif 476 468 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, 478 471 ieee80211_mgt_subtype_name[subtype 479 472 >> IEEE80211_FC0_SUBTYPE_SHIFT], 480 473 ether_sprintf(wh->i_addr2), rssi); 481 474 } 482 #if NBPFILTER > 0483 if (ic->ic_rawbpf)484 bpf_mtap(ic->ic_rawbpf, m);485 #endif486 475 rh = ic->ic_recv_mgmt[subtype >> IEEE80211_FC0_SUBTYPE_SHIFT]; 487 476 if (rh != NULL) 488 (*rh)(ic, m, rssi, rstamp);489 m_freem(m);477 (*rh)(ic, skb, rssi, rstamp); 478 dev_kfree_skb(skb); 490 479 return; 491 480 … … 497 486 } 498 487 err: 499 i fp->if_ierrors++;488 ic->ic_stats.rx_errors++; 500 489 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); 508 492 } 509 493 510 494 int 511 ieee80211_mgmt_output(struct ifnet *ifp, struct ieee80211_node *ni,512 struct mbuf *m, int type)513 { 514 struct ieee80211com *ic = (void *) ifp;495 ieee80211_mgmt_output(struct net_device *dev, struct ieee80211_node *ni, 496 struct sk_buff *skb, int type) 497 { 498 struct ieee80211com *ic = (void *)dev; 515 499 struct ieee80211_frame *wh; 516 500 … … 518 502 ni = &ic->ic_bss; 519 503 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)); 524 507 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | type; 525 508 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; 526 509 *(u_int16_t *)wh->i_dur = 0; 527 510 *(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); 529 512 ni->ni_txseq++; 530 513 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr); … … 532 515 IEEE80211_ADDR_COPY(wh->i_addr3, ni->ni_bssid); 533 516 534 if ( ifp->if_flags & IFF_DEBUG) {517 if (netif_msg_debug(ic)) { 535 518 /* avoid to print too many frames */ 536 519 if (ic->ic_opmode == IEEE80211_M_IBSS || … … 540 523 (type & IEEE80211_FC0_SUBTYPE_MASK) != 541 524 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, 543 527 ieee80211_mgt_subtype_name[ 544 528 (type & IEEE80211_FC0_SUBTYPE_MASK) … … 546 530 ether_sprintf(ni->ni_macaddr)); 547 531 } 548 IF_ENQUEUE(&ic->ic_mgtq, m);549 i fp->if_timer = 1;550 (*i fp->if_start)(ifp);532 skb_queue_tail(&ic->ic_mgtq, skb); 533 ic->ic_timer = 1; 534 (*ic->ic_start)(dev); 551 535 return 0; 552 536 } 553 537 554 struct mbuf *555 ieee80211_encap(struct ifnet *ifp, struct mbuf *m)556 { 557 struct ieee80211com *ic = (void *) ifp;538 struct sk_buff * 539 ieee80211_encap(struct net_device *dev, struct sk_buff *skb) 540 { 541 struct ieee80211com *ic = (void *)dev; 558 542 struct ether_header eh; 559 543 struct ieee80211_frame *wh; … … 561 545 struct ieee80211_node *ni; 562 546 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)); 569 548 570 549 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost) && … … 578 557 ni->ni_inact = 0; 579 558 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)); 582 561 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; 583 562 llc->llc_control = LLC_UI; … … 586 565 llc->llc_snap.org_code[2] = 0; 587 566 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)); 592 568 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA; 593 569 *(u_int16_t *)wh->i_dur = 0; 594 570 *(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); 596 572 ni->ni_txseq++; 597 573 switch (ic->ic_opmode) { … … 616 592 break; 617 593 } 618 return m;619 } 620 621 struct mbuf *622 ieee80211_decap(struct ifnet *ifp, struct mbuf *m)594 return skb; 595 } 596 597 struct sk_buff * 598 ieee80211_decap(struct net_device *dev, struct sk_buff *skb) 623 599 { 624 600 struct ether_header *eh; … … 626 602 struct llc *llc; 627 603 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)); 635 606 if (llc->llc_dsap == LLC_SNAP_LSAP && llc->llc_ssap == LLC_SNAP_LSAP && 636 607 llc->llc_control == LLC_UI && llc->llc_snap.org_code[0] == 0 && 637 608 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)); 639 610 llc = NULL; 640 611 } 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; 644 615 switch (wh.i_fc[1] & IEEE80211_FC1_DIR_MASK) { 645 616 case IEEE80211_FC1_DIR_NODS: … … 658 629 /* not yet supported */ 659 630 DPRINTF(("ieee80211_decap: DS to DS\n")); 660 m_freem(m);631 dev_kfree_skb(skb); 661 632 return NULL; 662 633 } 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; 711 645 } 712 646 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; 717 651 } 718 652 719 653 int 720 ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)721 { 722 struct ieee80211com *ic = (void *) ifp;654 ieee80211_ioctl(struct net_device *dev, u_long cmd, caddr_t data) 655 { 656 struct ieee80211com *ic = (void *)dev; 723 657 int error = 0; 724 658 u_int kid, len; … … 744 678 break; 745 679 } 746 error = copy out(tmpssid, ireq->i_data, ireq->i_len);680 error = copy_to_user(ireq->i_data, tmpssid, ireq->i_len); 747 681 break; 748 682 case IEEE80211_IOC_NUMSSIDS: … … 774 708 len = (u_int) ic->ic_nw_keys[kid].wk_len; 775 709 /* 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); 778 712 } else { 779 bzero(tmpkey, len);713 memset(tmpkey, 0, len); 780 714 } 781 715 ireq->i_len = len; 782 error = copy out(tmpkey, ireq->i_data, len);716 error = copy_to_user(ireq->i_data, tmpkey, len); 783 717 break; 784 718 case IEEE80211_IOC_NUMWEPKEYS: … … 825 759 break; 826 760 case SIOCS80211: 827 error = suser(curthread); 828 if (error) 829 break; 761 if (!capable(CAP_SYS_ADMIN)) { 762 error = EPERM; 763 break; 764 } 830 765 ireq = (struct ieee80211req *) data; 831 766 switch (ireq->i_type) { … … 836 771 break; 837 772 } 838 error = copy in(ireq->i_data, tmpssid, ireq->i_len);773 error = copy_from_user(tmpssid, ireq->i_data, ireq->i_len); 839 774 if (error) 840 775 break; … … 872 807 } 873 808 memset(tmpkey, 0, sizeof(tmpkey)); 874 error = copy in(ireq->i_data, tmpkey, ireq->i_len);809 error = copy_from_user(tmpkey, ireq->i_data, ireq->i_len); 875 810 if (error) 876 811 break; … … 956 891 break; 957 892 case SIOCGIFGENERIC: 958 error = ieee80211_cfgget( ifp, cmd, data);893 error = ieee80211_cfgget(dev, cmd, data); 959 894 break; 960 895 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; 965 900 break; 966 901 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 968 907 break; 969 908 } … … 985 924 } 986 925 if (i == len) { 987 print f("\"");926 printk("\""); 988 927 for (i = 0, p = essid; i < len; i++, p++) 989 print f("%c", *p);990 print f("\"");928 printk("%c", *p); 929 printk("\""); 991 930 } else { 992 print f("0x");931 printk("0x"); 993 932 for (i = 0, p = essid; i < len; i++, p++) 994 print f("%02x", *p);933 printk("%02x", *p); 995 934 } 996 935 } … … 1005 944 switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) { 1006 945 case IEEE80211_FC1_DIR_NODS: 1007 print f("NODS %s", ether_sprintf(wh->i_addr2));1008 print f("->%s", ether_sprintf(wh->i_addr1));1009 print f("(%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)); 1010 949 break; 1011 950 case IEEE80211_FC1_DIR_TODS: 1012 print f("TODS %s", ether_sprintf(wh->i_addr2));1013 print f("->%s", ether_sprintf(wh->i_addr3));1014 print f("(%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)); 1015 954 break; 1016 955 case IEEE80211_FC1_DIR_FROMDS: 1017 print f("FRDS %s", ether_sprintf(wh->i_addr3));1018 print f("->%s", ether_sprintf(wh->i_addr1));1019 print f("(%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)); 1020 959 break; 1021 960 case IEEE80211_FC1_DIR_DSTODS: 1022 print f("DSDS %s", ether_sprintf((u_int8_t *)&wh[1]));1023 print f("->%s", ether_sprintf(wh->i_addr3));1024 print f("(%s", ether_sprintf(wh->i_addr2));1025 print f("->%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)); 1026 965 break; 1027 966 } 1028 967 switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { 1029 968 case IEEE80211_FC0_TYPE_DATA: 1030 print f(" data");969 printk(" data"); 1031 970 break; 1032 971 case IEEE80211_FC0_TYPE_MGT: 1033 print f(" %s", ieee80211_mgt_subtype_name[972 printk(" %s", ieee80211_mgt_subtype_name[ 1034 973 (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) 1035 974 >> IEEE80211_FC0_SUBTYPE_SHIFT]); 1036 975 break; 1037 976 default: 1038 print f(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK);977 printk(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK); 1039 978 break; 1040 979 } 1041 980 if (wh->i_fc[1] & IEEE80211_FC1_WEP) 1042 print f(" WEP");981 printk(" WEP"); 1043 982 if (rate >= 0) 1044 print f(" %dM", rate / 2);983 printk(" %dM", rate / 2); 1045 984 if (rssi >= 0) 1046 print f(" +%d", rssi);1047 print f("\n");985 printk(" +%d", rssi); 986 printk("\n"); 1048 987 if (len > 0) { 1049 988 for (i = 0; i < len; i++) { 1050 989 if ((i & 1) == 0) 1051 print f(" ");1052 print f("%02x", buf[i]);1053 } 1054 print f("\n");990 printk(" "); 991 printk("%02x", buf[i]); 992 } 993 printk("\n"); 1055 994 } 1056 995 } 1057 996 1058 997 void 1059 ieee80211_watchdog(struct ifnet *ifp)1060 { 1061 struct ieee80211com *ic = (void *) ifp;998 ieee80211_watchdog(struct net_device *dev) 999 { 1000 struct ieee80211com *ic = (void *)dev; 1062 1001 struct ieee80211_node *ni, *nextbs; 1063 1002 … … 1065 1004 if (--ic->ic_scan_timer == 0) { 1066 1005 if (ic->ic_state == IEEE80211_S_SCAN) 1067 ieee80211_end_scan( ifp);1006 ieee80211_end_scan(dev); 1068 1007 } 1069 1008 } 1070 1009 if (ic->ic_mgt_timer) { 1071 1010 if (--ic->ic_mgt_timer == 0) 1072 ieee80211_new_state( ifp, IEEE80211_S_SCAN, -1);1011 ieee80211_new_state(dev, IEEE80211_S_SCAN, -1); 1073 1012 } 1074 1013 if (ic->ic_inact_timer) { … … 1079 1018 continue; 1080 1019 } 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" 1083 1022 " (reason %d)\n", 1023 dev->name, 1084 1024 ether_sprintf(ni->ni_macaddr), 1085 1025 IEEE80211_REASON_AUTH_EXPIRE); … … 1097 1037 if (ic->ic_scan_timer != 0 || ic->ic_mgt_timer != 0 || 1098 1038 ic->ic_inact_timer != 0) 1099 i fp->if_timer = 1;1039 ic->ic_timer = 1; 1100 1040 } 1101 1041 1102 1042 void 1103 ieee80211_next_scan(struct ifnet *ifp)1104 { 1105 struct ieee80211com *ic = (void *) ifp;1043 ieee80211_next_scan(struct net_device *dev) 1044 { 1045 struct ieee80211com *ic = (void *)dev; 1106 1046 int chan; 1107 1047 … … 1119 1059 ic->ic_bss.ni_chan, chan)); 1120 1060 ic->ic_bss.ni_chan = chan; 1121 ieee80211_new_state( ifp, IEEE80211_S_SCAN, -1);1061 ieee80211_new_state(dev, IEEE80211_S_SCAN, -1); 1122 1062 } 1123 1063 1124 1064 void 1125 ieee80211_end_scan(struct ifnet *ifp)1126 { 1127 struct ieee80211com *ic = (void *) ifp;1065 ieee80211_end_scan(struct net_device *dev) 1066 { 1067 struct ieee80211com *ic = (void *)dev; 1128 1068 struct ieee80211_node *ni, *nextbs, *selbs; 1129 1069 void *p; … … 1139 1079 ic->ic_des_esslen != 0) { 1140 1080 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); 1143 1083 ic->ic_flags |= IEEE80211_F_SIBSS; 1144 1084 ni->ni_nrate = 0; … … 1165 1105 ni->ni_fhindex = 1; 1166 1106 } 1167 ieee80211_new_state( ifp, IEEE80211_S_RUN, -1);1107 ieee80211_new_state(dev, IEEE80211_S_RUN, -1); 1168 1108 return; 1169 1109 } 1170 1110 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); 1173 1114 ic->ic_flags &= ~IEEE80211_F_ASCAN; 1174 1115 } 1175 ieee80211_next_scan( ifp);1116 ieee80211_next_scan(dev); 1176 1117 return; 1177 1118 } 1178 1119 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); 1181 1122 for (; ni != NULL; ni = nextbs) { 1182 1123 nextbs = TAILQ_NEXT(ni, ni_list); … … 1222 1163 !IEEE80211_ADDR_EQ(ic->ic_des_bssid, ni->ni_bssid)) 1223 1164 fail |= 0x20; 1224 if ( ifp->if_flags & IFF_DEBUG) {1225 print f(" %c %s", fail ? '-' : '+',1165 if (netif_msg_debug(ic)) { 1166 printk(" %c %s", fail ? '-' : '+', 1226 1167 ether_sprintf(ni->ni_macaddr)); 1227 print f(" %s%c", ether_sprintf(ni->ni_bssid),1168 printk(" %s%c", ether_sprintf(ni->ni_bssid), 1228 1169 fail & 0x20 ? '!' : ' '); 1229 print f(" %3d%c", ni->ni_chan, fail & 0x01 ? '!' : ' ');1230 print f(" %+4d", ni->ni_rssi);1231 print f(" %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, 1232 1173 fail & 0x08 ? '!' : ' '); 1233 print f(" %4s%c",1174 printk(" %4s%c", 1234 1175 (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" : 1235 1176 (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" : 1236 1177 "????", 1237 1178 fail & 0x02 ? '!' : ' '); 1238 print f(" %3s%c ",1179 printk(" %3s%c ", 1239 1180 (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ? 1240 1181 "wep" : "no", 1241 1182 fail & 0x04 ? '!' : ' '); 1242 1183 ieee80211_print_essid(ni->ni_essid, ni->ni_esslen); 1243 print f("%s\n", fail & 0x10 ? "!" : "");1184 printk("%s\n", fail & 0x10 ? "!" : ""); 1244 1185 } 1245 1186 if (!fail) { … … 1262 1203 goto notfound; 1263 1204 } 1264 ieee80211_new_state( ifp, IEEE80211_S_RUN, -1);1205 ieee80211_new_state(dev, IEEE80211_S_RUN, -1); 1265 1206 } else 1266 ieee80211_new_state( ifp, IEEE80211_S_AUTH, -1);1207 ieee80211_new_state(dev, IEEE80211_S_AUTH, -1); 1267 1208 } 1268 1209 … … 1273 1214 int hash; 1274 1215 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); 1277 1218 if (ni == NULL) 1278 1219 return NULL; … … 1322 1263 LIST_REMOVE(ni, ni_hash); 1323 1264 IEEE80211_UNLOCK(ic); 1324 free(ni, M_DEVBUF);1265 kfree(ni); 1325 1266 if (TAILQ_EMPTY(&ic->ic_node)) 1326 1267 ic->ic_inact_timer = 0; … … 1400 1341 { 1401 1342 int i, ret; 1402 struct mbuf *m;1343 struct sk_buff *skb; 1403 1344 u_int8_t *frm; 1404 1345 … … 1408 1349 * [tlv] supported rates 1409 1350 */ 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) 1412 1355 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)); 1415 1357 1416 1358 *frm++ = IEEE80211_ELEMID_SSID; … … 1426 1368 *frm++ = i; 1427 1369 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); 1431 1373 ic->ic_mgt_timer = IEEE80211_TRANS_WAIT; 1432 1374 return ret; … … 1437 1379 int type, int dummy) 1438 1380 { 1439 struct mbuf *m;1381 struct sk_buff *skb; 1440 1382 u_int8_t *frm; 1441 1383 struct ieee80211_node *ni = &ic->ic_bss; … … 1451 1393 * [tlv] parameter set (IBSS) 1452 1394 */ 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) 1455 1401 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)); 1458 1403 1459 1404 memset(frm, 0, 8); /* timestamp should be filled later */ 1460 1405 frm += 8; 1461 *(u_int16_t *)frm = htole16(ni->ni_intval);1406 *(u_int16_t *)frm = cpu_to_le16(ni->ni_intval); 1462 1407 frm += 2; 1463 1408 if (ic->ic_opmode == IEEE80211_M_IBSS) … … 1467 1412 if (ic->ic_flags & IEEE80211_F_WEPON) 1468 1413 capinfo |= IEEE80211_CAPINFO_PRIVACY; 1469 *(u_int16_t *)frm = htole16(capinfo);1414 *(u_int16_t *)frm = cpu_to_le16(capinfo); 1470 1415 frm += 2; 1471 1416 *frm++ = IEEE80211_ELEMID_SSID; … … 1490 1435 *frm++ = 0; /* Partial Virtual Bitmap (variable length) */ 1491 1436 } 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); 1496 1440 } 1497 1441 … … 1500 1444 int type, int seq) 1501 1445 { 1502 struct mbuf *m;1446 struct sk_buff *skb; 1503 1447 u_int16_t *frm; 1504 1448 int ret; 1505 1449 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) 1508 1453 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)); 1512 1456 /* 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); 1515 1459 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); 1517 1461 if (ic->ic_opmode == IEEE80211_M_STA) 1518 1462 ic->ic_mgt_timer = IEEE80211_TRANS_WAIT; … … 1524 1468 int type, int reason) 1525 1469 { 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) 1534 1479 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); 1539 1485 } 1540 1486 … … 1543 1489 int type, int dummy) 1544 1490 { 1545 struct mbuf *m;1491 struct sk_buff *skb; 1546 1492 u_int8_t *frm, *rates; 1547 1493 u_int16_t capinfo; … … 1556 1502 * [tlv] supported rates 1557 1503 */ 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) 1560 1511 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)); 1563 1513 1564 1514 capinfo = 0; … … 1569 1519 if (ic->ic_flags & IEEE80211_F_WEPON) 1570 1520 capinfo |= IEEE80211_CAPINFO_PRIVACY; 1571 *(u_int16_t *)frm = htole16(capinfo);1521 *(u_int16_t *)frm = cpu_to_le16(capinfo); 1572 1522 frm += 2; 1573 1523 1574 *(u_int16_t *)frm = htole16(ic->ic_lintval);1524 *(u_int16_t *)frm = cpu_to_le16(ic->ic_lintval); 1575 1525 frm += 2; 1576 1526 … … 1592 1542 } 1593 1543 *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); 1596 1547 ic->ic_mgt_timer = IEEE80211_TRANS_WAIT; 1597 1548 return ret; … … 1602 1553 int type, int status) 1603 1554 { 1604 struct mbuf *m;1555 struct sk_buff *skb; 1605 1556 u_int8_t *frm, *rates, *r; 1606 1557 u_int16_t capinfo; … … 1614 1565 * [tlv] supported rates 1615 1566 */ 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) 1618 1573 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)); 1621 1575 1622 1576 capinfo = IEEE80211_CAPINFO_ESS; 1623 1577 if (ic->ic_flags & IEEE80211_F_WEPON) 1624 1578 capinfo |= IEEE80211_CAPINFO_PRIVACY; 1625 *(u_int16_t *)frm = htole16(capinfo);1579 *(u_int16_t *)frm = cpu_to_le16(capinfo); 1626 1580 frm += 2; 1627 1581 1628 *(u_int16_t *)frm = htole16(status);1582 *(u_int16_t *)frm = cpu_to_le16(status); 1629 1583 frm += 2; 1630 1584 1631 1585 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); 1633 1587 else 1634 *(u_int16_t *)frm = htole16(0);1588 *(u_int16_t *)frm = cpu_to_le16(0); 1635 1589 frm += 2; 1636 1590 … … 1646 1600 } 1647 1601 *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); 1650 1605 } 1651 1606 … … 1654 1609 int type, int reason) 1655 1610 { 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) 1664 1620 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, 1669 1626 IEEE80211_FC0_SUBTYPE_DISASSOC); 1670 1627 } 1671 1628 1672 1629 static void 1673 ieee80211_recv_beacon(struct ieee80211com *ic, struct mbuf *m0, int rssi,1630 ieee80211_recv_beacon(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 1674 1631 u_int32_t rstamp) 1675 1632 { … … 1686 1643 } 1687 1644 1688 wh = mtod(m0, struct ieee80211_frame *);1645 wh = (struct ieee80211_frame *) skb0->data; 1689 1646 frm = (u_int8_t *)&wh[1]; 1690 efrm = mtod(m0, u_int8_t *) + m0->m_len;1647 efrm = skb0->data + skb0->len; 1691 1648 /* 1692 1649 * beacon frame format … … 1742 1699 (ieee80211_debug > 1 || ni == NULL || 1743 1700 ic->ic_state == IEEE80211_S_SCAN)) { 1744 print f("ieee80211_recv_prreq: %sbeacon on chan %u (bss chan %u) ",1701 printk("ieee80211_recv_prreq: %sbeacon on chan %u (bss chan %u) ", 1745 1702 (ni == NULL ? "new " : ""), chan, ic->ic_bss.ni_chan); 1746 1703 ieee80211_print_essid(ssid + 2, ssid[1]); 1747 print f(" from %s\n", ether_sprintf(wh->i_addr2));1704 printk(" from %s\n", ether_sprintf(wh->i_addr2)); 1748 1705 } 1749 1706 #endif … … 1776 1733 ni->ni_rstamp = rstamp; 1777 1734 memcpy(ni->ni_tstamp, tstamp, sizeof(ni->ni_tstamp)); 1778 ni->ni_intval = le16 toh(*(u_int16_t *)bintval);1779 ni->ni_capinfo = le16 toh(*(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); 1780 1737 ni->ni_chan = chan; 1781 1738 ni->ni_fhdwell = fhdwell; 1782 1739 ni->ni_fhindex = fhindex; 1783 1740 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); 1785 1742 } 1786 1743 1787 1744 static void 1788 ieee80211_recv_prreq(struct ieee80211com *ic, struct mbuf *m0, int rssi,1745 ieee80211_recv_prreq(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 1789 1746 u_int32_t rstamp) 1790 1747 { … … 1800 1757 return; 1801 1758 1802 wh = mtod(m0, struct ieee80211_frame *);1759 wh = (struct ieee80211_frame *) skb0->data; 1803 1760 frm = (u_int8_t *)&wh[1]; 1804 efrm = mtod(m0, u_int8_t *) + m0->m_len;1761 efrm = skb0->data + skb0->len; 1805 1762 /* 1806 1763 * prreq frame format … … 1830 1787 #ifdef IEEE80211_DEBUG 1831 1788 if (ieee80211_debug) { 1832 print f("ieee80211_recv_prreq: ssid unmatch ");1789 printk("ieee80211_recv_prreq: ssid unmatch "); 1833 1790 ieee80211_print_essid(ssid + 2, ssid[1]); 1834 print f(" from %s\n", ether_sprintf(wh->i_addr2));1791 printk(" from %s\n", ether_sprintf(wh->i_addr2)); 1835 1792 } 1836 1793 #endif … … 1866 1823 1867 1824 static void 1868 ieee80211_recv_auth(struct ieee80211com *ic, struct mbuf *m0, int rssi,1825 ieee80211_recv_auth(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 1869 1826 u_int32_t rstamp) 1870 1827 { 1871 struct ifnet *ifp = &ic->ic_if;1828 struct net_device *dev = &ic->ic_dev; 1872 1829 struct ieee80211_frame *wh; 1873 1830 struct ieee80211_node *ni; … … 1876 1833 int allocbs; 1877 1834 1878 wh = mtod(m0, struct ieee80211_frame *);1835 wh = (struct ieee80211_frame *) skb0->data; 1879 1836 frm = (u_int8_t *)&wh[1]; 1880 efrm = mtod(m0, u_int8_t *) + m0->m_len;1837 efrm = skb0->data + skb0->len; 1881 1838 /* 1882 1839 * auth frame format … … 1891 1848 return; 1892 1849 } 1893 algo = le16 toh(*(u_int16_t *)frm);1894 seq = le16 toh(*(u_int16_t *)(frm + 2));1895 status = le16 toh(*(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)); 1896 1853 if (algo != IEEE80211_AUTH_ALG_OPEN) { 1897 1854 /* TODO: shared key auth */ … … 1904 1861 if (ic->ic_state != IEEE80211_S_RUN || seq != 1) 1905 1862 return; 1906 ieee80211_new_state(&ic->ic_ if, IEEE80211_S_AUTH,1863 ieee80211_new_state(&ic->ic_dev, IEEE80211_S_AUTH, 1907 1864 wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 1908 1865 break; … … 1925 1882 } 1926 1883 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, 1929 1887 (allocbs ? "newly" : "already"), 1930 1888 ether_sprintf(ni->ni_macaddr)); … … 1935 1893 return; 1936 1894 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, 1940 1897 ether_sprintf(wh->i_addr3)); 1941 1898 ni = ieee80211_find_node(ic, wh->i_addr2); … … 1944 1901 return; 1945 1902 } 1946 ieee80211_new_state(&ic->ic_ if, IEEE80211_S_ASSOC,1903 ieee80211_new_state(&ic->ic_dev, IEEE80211_S_ASSOC, 1947 1904 wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 1948 1905 break; … … 1951 1908 1952 1909 static void 1953 ieee80211_recv_asreq(struct ieee80211com *ic, struct mbuf *m0, int rssi,1910 ieee80211_recv_asreq(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 1954 1911 u_int32_t rstamp) 1955 1912 { 1956 struct ifnet *ifp = &ic->ic_if;1913 struct net_device *dev = &ic->ic_dev; 1957 1914 struct ieee80211_frame *wh; 1958 1915 struct ieee80211_node *ni = &ic->ic_bss; … … 1965 1922 return; 1966 1923 1967 wh = mtod(m0, struct ieee80211_frame *);1924 wh = (struct ieee80211_frame *) skb0->data; 1968 1925 frm = (u_int8_t *)&wh[1]; 1969 efrm = mtod(m0, u_int8_t *) + m0->m_len;1926 efrm = skb0->data + skb0->len; 1970 1927 if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == 1971 1928 IEEE80211_FC0_SUBTYPE_REASSOC_REQ) { … … 1995 1952 return; 1996 1953 } 1997 capinfo = le16 toh(*(u_int16_t *)frm); frm += 2;1998 bintval = le16 toh(*(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; 1999 1956 if (reassoc) 2000 1957 frm += 6; /* ignore current AP info */ … … 2025 1982 #ifdef IEEE80211_DEBUG 2026 1983 if (ieee80211_debug) { 2027 print f("ieee80211_recv_asreq: ssid unmatch ");1984 printk("ieee80211_recv_asreq: ssid unmatch "); 2028 1985 ieee80211_print_essid(ssid + 2, ssid[1]); 2029 print f(" from %s\n", ether_sprintf(wh->i_addr2));1986 printk(" from %s\n", ether_sprintf(wh->i_addr2)); 2030 1987 } 2031 1988 #endif … … 2078 2035 newassoc = 0; 2079 2036 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, 2082 2040 (newassoc ? "newly" : "already"), 2083 2041 ether_sprintf(ni->ni_macaddr)); … … 2085 2043 2086 2044 static void 2087 ieee80211_recv_asresp(struct ieee80211com *ic, struct mbuf *m0, int rssi,2045 ieee80211_recv_asresp(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 2088 2046 u_int32_t rstamp) 2089 2047 { 2090 struct ifnet *ifp = &ic->ic_if;2048 struct net_device *dev = &ic->ic_dev; 2091 2049 struct ieee80211_frame *wh; 2092 2050 struct ieee80211_node *ni = &ic->ic_bss; … … 2098 2056 return; 2099 2057 2100 wh = mtod(m0, struct ieee80211_frame *);2058 wh = (struct ieee80211_frame *) skb0->data; 2101 2059 frm = (u_int8_t *)&wh[1]; 2102 efrm = mtod(m0, u_int8_t *) + m0->m_len;2060 efrm = skb0->data + skb0->len; 2103 2061 /* 2104 2062 * asresp frame format … … 2114 2072 } 2115 2073 2116 ni->ni_capinfo = le16 toh(*(u_int16_t *)frm);2074 ni->ni_capinfo = le16_to_cpu(*(u_int16_t *)frm); 2117 2075 frm += 2; 2118 2076 2119 status = le16 toh(*(u_int16_t *)frm);2077 status = le16_to_cpu(*(u_int16_t *)frm); 2120 2078 frm += 2; 2121 2079 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)); 2124 2082 ni = ieee80211_find_node(ic, wh->i_addr2); 2125 2083 if (ni != NULL) … … 2127 2085 return; 2128 2086 } 2129 ni->ni_associd = le16 toh(*(u_int16_t *)frm);2087 ni->ni_associd = le16_to_cpu(*(u_int16_t *)frm); 2130 2088 frm += 2; 2131 2089 rates = frm; … … 2138 2096 if (ni->ni_nrate == 0) 2139 2097 return; 2140 ieee80211_new_state( ifp, IEEE80211_S_RUN,2098 ieee80211_new_state(&ic->ic_dev, IEEE80211_S_RUN, 2141 2099 wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 2142 2100 } 2143 2101 2144 2102 static void 2145 ieee80211_recv_disassoc(struct ieee80211com *ic, struct mbuf *m0, int rssi,2103 ieee80211_recv_disassoc(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 2146 2104 u_int32_t rstamp) 2147 2105 { 2148 struct ifnet *ifp = &ic->ic_if;2106 struct net_device *dev = &ic->ic_dev; 2149 2107 struct ieee80211_frame *wh; 2150 2108 struct ieee80211_node *ni; … … 2152 2110 u_int16_t reason; 2153 2111 2154 wh = mtod(m0, struct ieee80211_frame *);2112 wh = (struct ieee80211_frame *) skb0->data; 2155 2113 frm = (u_int8_t *)&wh[1]; 2156 efrm = mtod(m0, u_int8_t *) + m0->m_len;2114 efrm = skb0->data + skb0->len; 2157 2115 /* 2158 2116 * disassoc frame format … … 2164 2122 return; 2165 2123 } 2166 reason = le16 toh(*(u_int16_t *)frm);2124 reason = le16_to_cpu(*(u_int16_t *)frm); 2167 2125 switch (ic->ic_opmode) { 2168 2126 case IEEE80211_M_STA: 2169 ieee80211_new_state(&ic->ic_ if, IEEE80211_S_ASSOC,2127 ieee80211_new_state(&ic->ic_dev, IEEE80211_S_ASSOC, 2170 2128 wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 2171 2129 break; 2172 2130 case IEEE80211_M_HOSTAP: 2173 2131 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" 2176 2134 " by peer (reason %d)\n", 2135 dev->name, 2177 2136 ether_sprintf(ni->ni_macaddr), reason); 2178 2137 ni->ni_associd = 0; … … 2185 2144 2186 2145 static void 2187 ieee80211_recv_deauth(struct ieee80211com *ic, struct mbuf *m0, int rssi,2146 ieee80211_recv_deauth(struct ieee80211com *ic, struct sk_buff *skb0, int rssi, 2188 2147 u_int32_t rstamp) 2189 2148 { 2190 struct ifnet *ifp = &ic->ic_if;2149 struct net_device *dev = &ic->ic_dev; 2191 2150 struct ieee80211_frame *wh; 2192 2151 struct ieee80211_node *ni; … … 2194 2153 u_int16_t reason; 2195 2154 2196 wh = mtod(m0, struct ieee80211_frame *);2155 wh = (struct ieee80211_frame *) skb0->data; 2197 2156 frm = (u_int8_t *)&wh[1]; 2198 efrm = mtod(m0, u_int8_t *) + m0->m_len;2157 efrm = skb0->data + skb0->len; 2199 2158 /* 2200 2159 * dauth frame format … … 2206 2165 return; 2207 2166 } 2208 reason = le16 toh(*(u_int16_t *)frm);2167 reason = le16_to_cpu(*(u_int16_t *)frm); 2209 2168 switch (ic->ic_opmode) { 2210 2169 case IEEE80211_M_STA: 2211 ieee80211_new_state(&ic->ic_ if, IEEE80211_S_AUTH,2170 ieee80211_new_state(&ic->ic_dev, IEEE80211_S_AUTH, 2212 2171 wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK); 2213 2172 break; 2214 2173 case IEEE80211_M_HOSTAP: 2215 2174 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" 2218 2177 " by peer (reason %d)\n", 2178 dev->name, 2219 2179 ether_sprintf(ni->ni_macaddr), reason); 2220 2180 ieee80211_free_node(ic, ni); … … 2227 2187 2228 2188 int 2229 ieee80211_new_state(struct ifnet *ifp, enum ieee80211_state nstate, int mgt)2230 { 2231 struct ieee80211com *ic = (void *) ifp;2189 ieee80211_new_state(struct net_device *dev, enum ieee80211_state nstate, int mgt) 2190 { 2191 struct ieee80211com *ic = (void *)dev; 2232 2192 struct ieee80211_node *ni = &ic->ic_bss; 2233 2193 int i, error, ostate; … … 2241 2201 stname[ostate], stname[nstate])); 2242 2202 if (ic->ic_newstate) { 2243 error = (*ic->ic_newstate)( ic->ic_softc, nstate);2203 error = (*ic->ic_newstate)(dev, nstate); 2244 2204 if (error == EINPROGRESS) 2245 2205 return 0; … … 2297 2257 ic->ic_scan_timer = 0; 2298 2258 ic->ic_mgt_timer = 0; 2299 IF_DRAIN(&ic->ic_mgtq);2259 skb_queue_purge(&ic->ic_mgtq); 2300 2260 if (ic->ic_wep_ctx != NULL) { 2301 free(ic->ic_wep_ctx, M_DEVBUF);2261 kfree(ic->ic_wep_ctx); 2302 2262 ic->ic_wep_ctx = NULL; 2303 2263 } … … 2310 2270 ni = &ic->ic_bss; 2311 2271 /* 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); 2314 2274 ni->ni_nrate = 0; 2315 2275 memset(ni->ni_rates, 0, IEEE80211_RATE_SIZE); … … 2342 2302 ic->ic_scan_timer = 2343 2303 IEEE80211_PSCAN_WAIT; 2344 i fp->if_timer = 1;2304 ic->ic_timer = 1; 2345 2305 } 2346 2306 break; 2347 2307 case IEEE80211_S_RUN: 2348 2308 /* beacon miss */ 2349 if ( ifp->if_flags & IFF_DEBUG) {2309 if (netif_msg_debug(ic)) { 2350 2310 /* XXX bssid clobbered above */ 2351 if_printf(ifp, "no recent beacons from %s;"2311 printk("%s: no recent beacons from %s;" 2352 2312 " rescanning\n", 2313 dev->name, 2353 2314 ether_sprintf(ic->ic_bss.ni_bssid)); 2354 2315 } … … 2432 2393 case IEEE80211_S_SCAN: /* adhoc mode */ 2433 2394 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); 2436 2397 if (ic->ic_opmode == IEEE80211_M_STA) 2437 print f("associated ");2398 printk("associated "); 2438 2399 else 2439 print f("synchronized ");2440 print f("with %s ssid ",2400 printk("synchronized "); 2401 printk("with %s ssid ", 2441 2402 ether_sprintf(ic->ic_bss.ni_bssid)); 2442 2403 ieee80211_print_essid(ic->ic_bss.ni_essid, 2443 2404 ic->ic_bss.ni_esslen); 2444 print f(" channel %d\n", ic->ic_bss.ni_chan);2405 printk(" channel %d\n", ic->ic_bss.ni_chan); 2445 2406 } 2446 2407 /* start with highest negotiated rate */ 2447 2408 ic->ic_bss.ni_txrate = ic->ic_bss.ni_nrate - 1; 2448 2409 ic->ic_mgt_timer = 0; 2449 (*i fp->if_start)(ifp);2410 (*ic->ic_start)(dev); 2450 2411 break; 2451 2412 } … … 2455 2416 } 2456 2417 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;2418 struct sk_buff * 2419 ieee80211_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; 2462 2423 struct ieee80211_frame *wh; 2463 2424 int i, left, len, moff, noff, kid; … … 2470 2431 n0 = NULL; 2471 2432 if ((ctx = ic->ic_wep_ctx) == NULL) { 2472 ctx = malloc(arc4_ctxlen(), M_DEVBUF, M_NOWAIT);2433 ctx = kmalloc(arc4_ctxlen(), GFP_KERNEL); 2473 2434 if (ctx == NULL) 2474 2435 goto fail; 2475 2436 ic->ic_wep_ctx = ctx; 2476 2437 } 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 } 2481 2447 if (n == NULL) 2482 2448 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); 2503 2455 if (txflag) { 2504 2456 kid = ic->ic_wep_txkey; … … 2514 2466 ic->ic_iv = iv + 1; 2515 2467 /* put iv in little endian to prepare 802.11i */ 2516 ivp = mtod(n, u_int8_t *)+ noff;2468 ivp = n->data + noff; 2517 2469 for (i = 0; i < IEEE80211_WEP_IVLEN; i++) { 2518 2470 ivp[i] = iv & 0xff; … … 2523 2475 } else { 2524 2476 wh->i_fc[1] &= ~IEEE80211_FC1_WEP; 2525 ivp = mtod(m, u_int8_t *)+ moff;2477 ivp = skb->data + moff; 2526 2478 kid = ivp[IEEE80211_WEP_IVLEN] >> 6; 2527 2479 moff += IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN; … … 2535 2487 /* encrypt with calculating CRC */ 2536 2488 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; 2574 2496 } 2575 2497 crc = ~crc; 2576 2498 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)); 2591 2501 } 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)) { 2604 2504 #ifdef IEEE80211_DEBUG 2605 2505 if (ieee80211_debug) { 2606 if_printf(ifp, "decrypt CRC error\n");2506 printk("%s: decrypt CRC error\n", dev->name); 2607 2507 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); 2610 2510 } 2611 2511 #endif … … 2613 2513 } 2614 2514 } 2615 m_freem(m0);2515 dev_kfree_skb(skb0); 2616 2516 return n0; 2617 2517 2618 2518 fail: 2619 m_freem(m0);2620 m_freem(n0);2519 dev_kfree_skb(skb0); 2520 dev_kfree_skb(n0); 2621 2521 return NULL; 2622 2522 } … … 2806 2706 2807 2707 int 2808 ieee80211_cfgget(struct ifnet *ifp, u_long cmd, caddr_t data)2809 { 2810 struct ieee80211com *ic = (void *) ifp;2708 ieee80211_cfgget(struct net_device *dev, u_long cmd, caddr_t data) 2709 { 2710 struct ieee80211com *ic = (void *)dev; 2811 2711 int i, j, error; 2812 2712 struct ifreq *ifr = (struct ifreq *)data; … … 2817 2717 struct wi_sigcache wsc; 2818 2718 2819 error = copy in(ifr->ifr_data, &wreq, sizeof(wreq));2719 error = copy_from_user(&wreq, ifr->ifr_data, sizeof(wreq)); 2820 2720 if (error) 2821 2721 return error; … … 2826 2726 break; 2827 2727 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; 2831 2731 break; 2832 2732 case WI_RID_CURRENT_SSID: … … 2836 2736 break; 2837 2737 } 2838 wreq.wi_val[0] = htole16(ic->ic_bss.ni_esslen);2738 wreq.wi_val[0] = cpu_to_le16(ic->ic_bss.ni_esslen); 2839 2739 memcpy(&wreq.wi_val[1], ic->ic_bss.ni_essid, 2840 2740 ic->ic_bss.ni_esslen); … … 2843 2743 case WI_RID_OWN_SSID: 2844 2744 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); 2846 2746 memcpy(&wreq.wi_val[1], ic->ic_des_essid, ic->ic_des_esslen); 2847 2747 wreq.wi_len = (1 + ic->ic_des_esslen + 1) / 2; … … 2872 2772 break; 2873 2773 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); 2875 2775 wreq.wi_len = 1; 2876 2776 break; 2877 2777 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); 2879 2779 wreq.wi_len = 1; 2880 2780 break; 2881 2781 case WI_RID_COMMS_QUALITY: 2882 2782 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 */ 2884 2784 wreq.wi_val[2] = 0; /* noise */ 2885 2785 wreq.wi_len = 3; 2886 2786 break; 2887 2787 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); 2889 2789 wreq.wi_len = 1; 2890 2790 break; 2891 2791 case WI_RID_PORTTYPE: 2892 wreq.wi_val[0] = htole16(ic->ic_opmode);2792 wreq.wi_val[0] = cpu_to_le16(ic->ic_opmode); 2893 2793 wreq.wi_len = 1; 2894 2794 break; … … 2901 2801 wreq.wi_val[0] = 0; /* auto */ 2902 2802 else 2903 wreq.wi_val[0] = htole16(2803 wreq.wi_val[0] = cpu_to_le16( 2904 2804 (ic->ic_sup_rates[ic->ic_fixed_rate] & 2905 2805 IEEE80211_RATE_VAL) / 2); … … 2907 2807 break; 2908 2808 case WI_RID_CUR_TX_RATE: 2909 wreq.wi_val[0] = htole16(2809 wreq.wi_val[0] = cpu_to_le16( 2910 2810 (ic->ic_bss.ni_rates[ic->ic_bss.ni_txrate] & 2911 2811 IEEE80211_RATE_VAL) / 2); … … 2913 2813 break; 2914 2814 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 */ 2916 2816 wreq.wi_len = 1; 2917 2817 break; 2918 2818 case WI_RID_CREATE_IBSS: 2919 2819 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); 2921 2821 wreq.wi_len = 1; 2922 2822 break; … … 2926 2826 break; 2927 2827 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 */ 2929 2829 wreq.wi_len = 1; 2930 2830 break; 2931 2831 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 */ 2933 2833 wreq.wi_len = 1; 2934 2834 break; 2935 2835 case WI_RID_PM_ENABLED: 2936 2836 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); 2938 2838 wreq.wi_len = 1; 2939 2839 break; 2940 2840 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); 2942 2842 wreq.wi_len = 1; 2943 2843 break; 2944 2844 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); 2946 2846 wreq.wi_len = 1; 2947 2847 break; 2948 2848 case WI_RID_WEP_AVAIL: 2949 2849 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); 2951 2851 wreq.wi_len = 1; 2952 2852 break; 2953 2853 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 */ 2955 2855 wreq.wi_len = 1; 2956 2856 break; 2957 2857 case WI_RID_ENCRYPTION: 2958 2858 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); 2960 2860 wreq.wi_len = 1; 2961 2861 break; 2962 2862 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); 2964 2864 wreq.wi_len = 1; 2965 2865 break; … … 2967 2867 keys = (struct wi_ltv_keys *)&wreq; 2968 2868 /* do not show keys to non-root user */ 2969 error = suser(curthread); 2970 if (error) { 2869 if (!capable(CAP_SYS_ADMIN)) { 2971 2870 memset(keys, 0, sizeof(*keys)); 2972 error = 0;2973 2871 break; 2974 2872 } 2975 2873 for (i = 0; i < IEEE80211_WEP_NKID; i++) { 2976 2874 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); 2978 2876 memcpy(keys->wi_keys[i].wi_keydat, 2979 2877 ic->ic_nw_keys[i].wk_key, ic->ic_nw_keys[i].wk_len); … … 2982 2880 break; 2983 2881 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 */ 2985 2883 wreq.wi_len = 1; 2986 2884 break; … … 2991 2889 if (ic->ic_opmode != IEEE80211_M_HOSTAP) { 2992 2890 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); 2995 2893 if (ic->ic_state != IEEE80211_S_SCAN || 2996 2894 (ic->ic_flags & IEEE80211_F_SCANAP) == 0 || … … 3062 2960 if (error == 0) { 3063 2961 wreq.wi_len++; 3064 error = copy out(&wreq, ifr->ifr_data, sizeof(wreq));2962 error = copy_to_user(ifr->ifr_data, &wreq, sizeof(wreq)); 3065 2963 } 3066 2964 return error; … … 3068 2966 3069 2967 int 3070 ieee80211_cfgset(struct ifnet *ifp, u_long cmd, caddr_t data)3071 { 3072 struct ieee80211com *ic = (void *) ifp;2968 ieee80211_cfgset(struct net_device *dev, u_long cmd, caddr_t data) 2969 { 2970 struct ieee80211com *ic = (void *)dev; 3073 2971 int i, j, len, error; 3074 2972 struct ifreq *ifr = (struct ifreq *)data; … … 3077 2975 u_char chanlist[roundup(IEEE80211_CHAN_MAX, NBBY)]; 3078 2976 3079 error = copy in(ifr->ifr_data, &wreq, sizeof(wreq));2977 error = copy_from_user(&wreq, ifr->ifr_data, sizeof(wreq)); 3080 2978 if (error) 3081 2979 return error; … … 3090 2988 case WI_RID_OWN_SSID: 3091 2989 case WI_RID_DESIRED_SSID: 3092 len = le16 toh(wreq.wi_val[0]);2990 len = le16_to_cpu(wreq.wi_val[0]); 3093 2991 if (wreq.wi_len < (1 + len + 1) / 2) 3094 2992 return EINVAL; … … 3105 3003 if (wreq.wi_len != 1) 3106 3004 return EINVAL; 3107 i = le16 toh(wreq.wi_val[0]);3005 i = le16_to_cpu(wreq.wi_val[0]); 3108 3006 if (i < 0 || 3109 3007 i > IEEE80211_CHAN_MAX || … … 3121 3019 if (wreq.wi_len != 1) 3122 3020 return EINVAL; 3123 if ( ifp->if_flags & IFF_PROMISC) {3021 if (dev->flags & IFF_PROMISC) { 3124 3022 if (wreq.wi_val[0] == 0) { 3125 ifp->if_flags &= ~IFF_PROMISC;3023 dev_set_promiscuity(dev, dev->promiscuity); 3126 3024 error = ENETRESET; 3127 3025 } 3128 3026 } else { 3129 3027 if (wreq.wi_val[0] != 0) { 3130 ifp->if_flags |= IFF_PROMISC;3028 dev_set_promiscuity(dev, 1); 3131 3029 error = ENETRESET; 3132 3030 } … … 3136 3034 if (wreq.wi_len != 1) 3137 3035 return EINVAL; 3138 switch (le16 toh(wreq.wi_val[0])) {3036 switch (le16_to_cpu(wreq.wi_val[0])) { 3139 3037 case IEEE80211_M_STA: 3140 3038 break; … … 3155 3053 return EINVAL; 3156 3054 } 3157 if (le16 toh(wreq.wi_val[0]) != ic->ic_opmode) {3158 ic->ic_opmode = le16 toh(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]); 3159 3057 error = ENETRESET; 3160 3058 } … … 3178 3076 } 3179 3077 for (i = 0; i < IEEE80211_RATE_SIZE; i++) { 3180 if (le16 toh(wreq.wi_val[0]) ==3078 if (le16_to_cpu(wreq.wi_val[0]) == 3181 3079 (ic->ic_sup_rates[i] & IEEE80211_RATE_VAL) / 2) 3182 3080 break; … … 3193 3091 if (wreq.wi_len != 1) 3194 3092 return EINVAL; 3195 if (le16 toh(wreq.wi_val[0]) != IEEE80211_MAX_LEN)3093 if (le16_to_cpu(wreq.wi_val[0]) != IEEE80211_MAX_LEN) 3196 3094 return EINVAL; /* TODO: RTS */ 3197 3095 break; … … 3227 3125 if (wreq.wi_len != 1) 3228 3126 return EINVAL; 3229 if (le16 toh(wreq.wi_val[0]) != 1)3127 if (le16_to_cpu(wreq.wi_val[0]) != 1) 3230 3128 return EINVAL; /* not supported */ 3231 3129 break; … … 3233 3131 if (wreq.wi_len != 1) 3234 3132 return EINVAL; 3235 if (le16 toh(wreq.wi_val[0]) != 1)3133 if (le16_to_cpu(wreq.wi_val[0]) != 1) 3236 3134 return EINVAL; /* not supported */ 3237 3135 break; … … 3256 3154 if (wreq.wi_len != 1) 3257 3155 return EINVAL; 3258 ic->ic_lintval = le16 toh(wreq.wi_val[0]);3156 ic->ic_lintval = le16_to_cpu(wreq.wi_val[0]); 3259 3157 if (ic->ic_flags & IEEE80211_F_PMGTON) 3260 3158 error = ENETRESET; … … 3267 3165 if (wreq.wi_len != 1) 3268 3166 return EINVAL; 3269 if (le16 toh(wreq.wi_val[0]) != 1)3167 if (le16_to_cpu(wreq.wi_val[0]) != 1) 3270 3168 return EINVAL; /* TODO: shared key auth */ 3271 3169 break; … … 3290 3188 if (wreq.wi_len != 1) 3291 3189 return EINVAL; 3292 i = le16 toh(wreq.wi_val[0]);3190 i = le16_to_cpu(wreq.wi_val[0]); 3293 3191 if (i >= IEEE80211_WEP_NKID) 3294 3192 return EINVAL; … … 3300 3198 keys = (struct wi_ltv_keys *)&wreq; 3301 3199 for (i = 0; i < IEEE80211_WEP_NKID; i++) { 3302 len = le16 toh(keys->wi_keys[i].wi_keylen);3200 len = le16_to_cpu(keys->wi_keys[i].wi_keylen); 3303 3201 if (len != 0 && len < IEEE80211_WEP_KEYLEN) 3304 3202 return EINVAL; … … 3308 3206 memset(ic->ic_nw_keys, 0, sizeof(ic->ic_nw_keys)); 3309 3207 for (i = 0; i < IEEE80211_WEP_NKID; i++) { 3310 len = le16 toh(keys->wi_keys[i].wi_keylen);3208 len = le16_to_cpu(keys->wi_keys[i].wi_keylen); 3311 3209 ic->ic_nw_keys[i].wk_len = len; 3312 3210 memcpy(ic->ic_nw_keys[i].wk_key, … … 3318 3216 if (wreq.wi_len != 1) 3319 3217 return EINVAL; 3320 len = le16 toh(wreq.wi_val[0]);3218 len = le16_to_cpu(wreq.wi_val[0]); 3321 3219 if (len < 350 /* ? */ || len > IEEE80211_MAX_LEN) 3322 3220 return EINVAL; … … 3356 3254 } 3357 3255 if (error == EPERM && ic->ic_chancheck != NULL) 3358 error = (*ic->ic_chancheck)( ic->ic_softc, chanlist);3256 error = (*ic->ic_chancheck)(dev, chanlist); 3359 3257 if (error) 3360 3258 return error; … … 3374 3272 else { 3375 3273 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); 3377 3275 } 3378 3276 break; … … 3386 3284 /* 3387 3285 * Module glue. 3388 *3389 * NB: the module name is "wlan" for compatibility with NetBSD.3390 3286 */ 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); 3287 static char *version = "802.11 Wireless Support (Sam Leffler <sam@errno.com>)"; 3288 static char *dev_info = "wlan"; 3289 3290 MODULE_AUTHOR("Errno Consulting, Sam Leffler"); 3291 MODULE_DESCRIPTION("802.11 wireless LAN protocol support"); 3292 #ifdef MODULE_LICENSE 3293 MODULE_LICENSE("Dual BSD/GPL"); /* XXX really BSD only */ 3294 #endif 3295 3296 EXPORT_SYMBOL(ieee80211_ifattach); 3297 EXPORT_SYMBOL(ieee80211_ifdetach); 3298 EXPORT_SYMBOL(ieee80211_input); 3299 EXPORT_SYMBOL(ieee80211_mgmt_output); 3300 EXPORT_SYMBOL(ieee80211_encap); 3301 EXPORT_SYMBOL(ieee80211_decap); 3302 EXPORT_SYMBOL(ieee80211_ioctl); 3303 EXPORT_SYMBOL(ieee80211_print_essid); 3304 EXPORT_SYMBOL(ieee80211_dump_pkt); 3305 EXPORT_SYMBOL(ieee80211_watchdog); 3306 EXPORT_SYMBOL(ieee80211_next_scan); 3307 EXPORT_SYMBOL(ieee80211_end_scan); 3308 EXPORT_SYMBOL(ieee80211_alloc_node); 3309 EXPORT_SYMBOL(ieee80211_find_node); 3310 EXPORT_SYMBOL(ieee80211_free_node); 3311 EXPORT_SYMBOL(ieee80211_free_allnodes); 3312 EXPORT_SYMBOL(ieee80211_fix_rate); 3313 EXPORT_SYMBOL(ieee80211_new_state); 3314 EXPORT_SYMBOL(ieee80211_wep_crypt); 3315 EXPORT_SYMBOL(ieee80211_rate2media); 3316 EXPORT_SYMBOL(ieee80211_media2rate); 3317 3318 EXPORT_SYMBOL(ieee80211_cfgget); 3319 EXPORT_SYMBOL(ieee80211_cfgset); 3320 3321 static int __init 3322 init_wlan(void) 3323 { 3324 printk(KERN_INFO "%s: %s\n", dev_info, version); 3325 return 0; 3326 } 3327 module_init(init_wlan); 3328 3329 static void __exit 3330 exit_wlan(void) 3331 { 3332 printk(KERN_INFO "%s: driver unloaded\n", dev_info); 3333 } 3334 module_exit(exit_wlan);
