if_zyd.c (203141) | if_zyd.c (206358) |
---|---|
1/* $OpenBSD: if_zyd.c,v 1.52 2007/02/11 00:08:04 jsg Exp $ */ 2/* $NetBSD: if_zyd.c,v 1.7 2007/06/21 04:04:29 kiyohara Exp $ */ | 1/* $OpenBSD: if_zyd.c,v 1.52 2007/02/11 00:08:04 jsg Exp $ */ 2/* $NetBSD: if_zyd.c,v 1.7 2007/06/21 04:04:29 kiyohara Exp $ */ |
3/* $FreeBSD: head/sys/dev/usb/wlan/if_zyd.c 203141 2010-01-29 02:31:33Z thompsa $ */ | 3/* $FreeBSD: head/sys/dev/usb/wlan/if_zyd.c 206358 2010-04-07 15:29:13Z rpaulo $ */ |
4 5/*- 6 * Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr> 7 * Copyright (c) 2006 by Florian Stoehr <ich@florian-stoehr.de> 8 * 9 * Permission to use, copy, modify, and distribute this software for any 10 * purpose with or without fee is hereby granted, provided that the above 11 * copyright notice and this permission notice appear in all copies. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 */ 21 22#include <sys/cdefs.h> | 4 5/*- 6 * Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr> 7 * Copyright (c) 2006 by Florian Stoehr <ich@florian-stoehr.de> 8 * 9 * Permission to use, copy, modify, and distribute this software for any 10 * purpose with or without fee is hereby granted, provided that the above 11 * copyright notice and this permission notice appear in all copies. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 */ 21 22#include <sys/cdefs.h> |
23__FBSDID("$FreeBSD: head/sys/dev/usb/wlan/if_zyd.c 203141 2010-01-29 02:31:33Z thompsa $"); | 23__FBSDID("$FreeBSD: head/sys/dev/usb/wlan/if_zyd.c 206358 2010-04-07 15:29:13Z rpaulo $"); |
24 25/* 26 * ZyDAS ZD1211/ZD1211B USB WLAN driver. 27 */ 28 29#include <sys/param.h> 30#include <sys/sockio.h> 31#include <sys/sysctl.h> --- 28 unchanged lines hidden (view full) --- 60#include <netinet/in_var.h> 61#include <netinet/if_ether.h> 62#include <netinet/ip.h> 63#endif 64 65#include <net80211/ieee80211_var.h> 66#include <net80211/ieee80211_regdomain.h> 67#include <net80211/ieee80211_radiotap.h> | 24 25/* 26 * ZyDAS ZD1211/ZD1211B USB WLAN driver. 27 */ 28 29#include <sys/param.h> 30#include <sys/sockio.h> 31#include <sys/sysctl.h> --- 28 unchanged lines hidden (view full) --- 60#include <netinet/in_var.h> 61#include <netinet/if_ether.h> 62#include <netinet/ip.h> 63#endif 64 65#include <net80211/ieee80211_var.h> 66#include <net80211/ieee80211_regdomain.h> 67#include <net80211/ieee80211_radiotap.h> |
68#include <net80211/ieee80211_amrr.h> | 68#include <net80211/ieee80211_ratectl.h> |
69 70#include <dev/usb/usb.h> 71#include <dev/usb/usbdi.h> 72#include <dev/usb/usbdi_util.h> 73#include "usbdevs.h" 74 75#include <dev/usb/wlan/if_zydreg.h> 76#include <dev/usb/wlan/if_zydfw.h> --- 43 unchanged lines hidden (view full) --- 120static struct ieee80211vap *zyd_vap_create(struct ieee80211com *, 121 const char name[IFNAMSIZ], int unit, int opmode, 122 int flags, const uint8_t bssid[IEEE80211_ADDR_LEN], 123 const uint8_t mac[IEEE80211_ADDR_LEN]); 124static void zyd_vap_delete(struct ieee80211vap *); 125static void zyd_tx_free(struct zyd_tx_data *, int); 126static void zyd_setup_tx_list(struct zyd_softc *); 127static void zyd_unsetup_tx_list(struct zyd_softc *); | 69 70#include <dev/usb/usb.h> 71#include <dev/usb/usbdi.h> 72#include <dev/usb/usbdi_util.h> 73#include "usbdevs.h" 74 75#include <dev/usb/wlan/if_zydreg.h> 76#include <dev/usb/wlan/if_zydfw.h> --- 43 unchanged lines hidden (view full) --- 120static struct ieee80211vap *zyd_vap_create(struct ieee80211com *, 121 const char name[IFNAMSIZ], int unit, int opmode, 122 int flags, const uint8_t bssid[IEEE80211_ADDR_LEN], 123 const uint8_t mac[IEEE80211_ADDR_LEN]); 124static void zyd_vap_delete(struct ieee80211vap *); 125static void zyd_tx_free(struct zyd_tx_data *, int); 126static void zyd_setup_tx_list(struct zyd_softc *); 127static void zyd_unsetup_tx_list(struct zyd_softc *); |
128static struct ieee80211_node *zyd_node_alloc(struct ieee80211vap *, 129 const uint8_t mac[IEEE80211_ADDR_LEN]); | |
130static int zyd_newstate(struct ieee80211vap *, enum ieee80211_state, int); 131static int zyd_cmd(struct zyd_softc *, uint16_t, const void *, int, 132 void *, int, int); 133static int zyd_read16(struct zyd_softc *, uint16_t, uint16_t *); 134static int zyd_read32(struct zyd_softc *, uint16_t, uint32_t *); 135static int zyd_write16(struct zyd_softc *, uint16_t, uint16_t); 136static int zyd_write32(struct zyd_softc *, uint16_t, uint32_t); 137static int zyd_rfwrite(struct zyd_softc *, uint32_t); --- 20 unchanged lines hidden (view full) --- 158static void zyd_start(struct ifnet *); 159static int zyd_raw_xmit(struct ieee80211_node *, struct mbuf *, 160 const struct ieee80211_bpf_params *); 161static int zyd_ioctl(struct ifnet *, u_long, caddr_t); 162static void zyd_init_locked(struct zyd_softc *); 163static void zyd_init(void *); 164static void zyd_stop(struct zyd_softc *); 165static int zyd_loadfirmware(struct zyd_softc *); | 128static int zyd_newstate(struct ieee80211vap *, enum ieee80211_state, int); 129static int zyd_cmd(struct zyd_softc *, uint16_t, const void *, int, 130 void *, int, int); 131static int zyd_read16(struct zyd_softc *, uint16_t, uint16_t *); 132static int zyd_read32(struct zyd_softc *, uint16_t, uint32_t *); 133static int zyd_write16(struct zyd_softc *, uint16_t, uint16_t); 134static int zyd_write32(struct zyd_softc *, uint16_t, uint32_t); 135static int zyd_rfwrite(struct zyd_softc *, uint32_t); --- 20 unchanged lines hidden (view full) --- 156static void zyd_start(struct ifnet *); 157static int zyd_raw_xmit(struct ieee80211_node *, struct mbuf *, 158 const struct ieee80211_bpf_params *); 159static int zyd_ioctl(struct ifnet *, u_long, caddr_t); 160static void zyd_init_locked(struct zyd_softc *); 161static void zyd_init(void *); 162static void zyd_stop(struct zyd_softc *); 163static int zyd_loadfirmware(struct zyd_softc *); |
166static void zyd_newassoc(struct ieee80211_node *, int); | |
167static void zyd_scan_start(struct ieee80211com *); 168static void zyd_scan_end(struct ieee80211com *); 169static void zyd_set_channel(struct ieee80211com *); 170static int zyd_rfmd_init(struct zyd_rf *); 171static int zyd_rfmd_switch_radio(struct zyd_rf *, int); 172static int zyd_rfmd_set_channel(struct zyd_rf *, uint8_t); 173static int zyd_al2230_init(struct zyd_rf *); 174static int zyd_al2230_switch_radio(struct zyd_rf *, int); --- 228 unchanged lines hidden (view full) --- 403 ; 404 405 bands = 0; 406 setbit(&bands, IEEE80211_MODE_11B); 407 setbit(&bands, IEEE80211_MODE_11G); 408 ieee80211_init_channels(ic, NULL, &bands); 409 410 ieee80211_ifattach(ic, sc->sc_bssid); | 164static void zyd_scan_start(struct ieee80211com *); 165static void zyd_scan_end(struct ieee80211com *); 166static void zyd_set_channel(struct ieee80211com *); 167static int zyd_rfmd_init(struct zyd_rf *); 168static int zyd_rfmd_switch_radio(struct zyd_rf *, int); 169static int zyd_rfmd_set_channel(struct zyd_rf *, uint8_t); 170static int zyd_al2230_init(struct zyd_rf *); 171static int zyd_al2230_switch_radio(struct zyd_rf *, int); --- 228 unchanged lines hidden (view full) --- 400 ; 401 402 bands = 0; 403 setbit(&bands, IEEE80211_MODE_11B); 404 setbit(&bands, IEEE80211_MODE_11G); 405 ieee80211_init_channels(ic, NULL, &bands); 406 407 ieee80211_ifattach(ic, sc->sc_bssid); |
411 ic->ic_newassoc = zyd_newassoc; | |
412 ic->ic_raw_xmit = zyd_raw_xmit; | 408 ic->ic_raw_xmit = zyd_raw_xmit; |
413 ic->ic_node_alloc = zyd_node_alloc; | |
414 ic->ic_scan_start = zyd_scan_start; 415 ic->ic_scan_end = zyd_scan_end; 416 ic->ic_set_channel = zyd_set_channel; 417 418 ic->ic_vap_create = zyd_vap_create; 419 ic->ic_vap_delete = zyd_vap_delete; 420 ic->ic_update_mcast = zyd_update_mcast; 421 ic->ic_update_promisc = zyd_update_mcast; --- 56 unchanged lines hidden (view full) --- 478 /* enable s/w bmiss handling for sta mode */ 479 ieee80211_vap_setup(ic, vap, name, unit, opmode, 480 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac); 481 482 /* override state transition machine */ 483 zvp->newstate = vap->iv_newstate; 484 vap->iv_newstate = zyd_newstate; 485 | 409 ic->ic_scan_start = zyd_scan_start; 410 ic->ic_scan_end = zyd_scan_end; 411 ic->ic_set_channel = zyd_set_channel; 412 413 ic->ic_vap_create = zyd_vap_create; 414 ic->ic_vap_delete = zyd_vap_delete; 415 ic->ic_update_mcast = zyd_update_mcast; 416 ic->ic_update_promisc = zyd_update_mcast; --- 56 unchanged lines hidden (view full) --- 473 /* enable s/w bmiss handling for sta mode */ 474 ieee80211_vap_setup(ic, vap, name, unit, opmode, 475 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac); 476 477 /* override state transition machine */ 478 zvp->newstate = vap->iv_newstate; 479 vap->iv_newstate = zyd_newstate; 480 |
486 ieee80211_amrr_init(&zvp->amrr, vap, 487 IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD, 488 IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD, 489 1000 /* 1 sec */); | 481 ieee80211_ratectl_init(vap); 482 ieee80211_ratectl_setinterval(vap, 1000 /* 1 sec */); |
490 491 /* complete setup */ 492 ieee80211_vap_attach(vap, ieee80211_media_change, 493 ieee80211_media_status); 494 ic->ic_opmode = opmode; 495 return (vap); 496} 497 498static void 499zyd_vap_delete(struct ieee80211vap *vap) 500{ 501 struct zyd_vap *zvp = ZYD_VAP(vap); 502 | 483 484 /* complete setup */ 485 ieee80211_vap_attach(vap, ieee80211_media_change, 486 ieee80211_media_status); 487 ic->ic_opmode = opmode; 488 return (vap); 489} 490 491static void 492zyd_vap_delete(struct ieee80211vap *vap) 493{ 494 struct zyd_vap *zvp = ZYD_VAP(vap); 495 |
503 ieee80211_amrr_cleanup(&zvp->amrr); | 496 ieee80211_ratectl_deinit(vap); |
504 ieee80211_vap_detach(vap); 505 free(zvp, M_80211_VAP); 506} 507 508static void 509zyd_tx_free(struct zyd_tx_data *data, int txerr) 510{ 511 struct zyd_softc *sc = data->sc; 512 513 if (data->m != NULL) { 514 if (data->m->m_flags & M_TXCB) 515 ieee80211_process_callback(data->ni, data->m, 516 txerr ? ETIMEDOUT : 0); 517 m_freem(data->m); 518 data->m = NULL; 519 520 if (txerr == 0) | 497 ieee80211_vap_detach(vap); 498 free(zvp, M_80211_VAP); 499} 500 501static void 502zyd_tx_free(struct zyd_tx_data *data, int txerr) 503{ 504 struct zyd_softc *sc = data->sc; 505 506 if (data->m != NULL) { 507 if (data->m->m_flags & M_TXCB) 508 ieee80211_process_callback(data->ni, data->m, 509 txerr ? ETIMEDOUT : 0); 510 m_freem(data->m); 511 data->m = NULL; 512 513 if (txerr == 0) |
521 ieee80211_amrr_tx_complete(&ZYD_NODE(data->ni)->amn, 522 IEEE80211_AMRR_SUCCESS, 0); | 514 ieee80211_ratectl_tx_complete(data->ni->ni_vap, 515 data->ni, IEEE80211_RATECTL_TX_SUCCESS, NULL, NULL); |
523 ieee80211_free_node(data->ni); 524 data->ni = NULL; 525 } 526 STAILQ_INSERT_TAIL(&sc->tx_free, data, next); 527 sc->tx_nfree++; 528} 529 530static void --- 36 unchanged lines hidden (view full) --- 567 } 568 if (data->ni != NULL) { 569 ieee80211_free_node(data->ni); 570 data->ni = NULL; 571 } 572 } 573} 574 | 516 ieee80211_free_node(data->ni); 517 data->ni = NULL; 518 } 519 STAILQ_INSERT_TAIL(&sc->tx_free, data, next); 520 sc->tx_nfree++; 521} 522 523static void --- 36 unchanged lines hidden (view full) --- 560 } 561 if (data->ni != NULL) { 562 ieee80211_free_node(data->ni); 563 data->ni = NULL; 564 } 565 } 566} 567 |
575/* ARGUSED */ 576static struct ieee80211_node * 577zyd_node_alloc(struct ieee80211vap *vap __unused, 578 const uint8_t mac[IEEE80211_ADDR_LEN] __unused) 579{ 580 struct zyd_node *zn; 581 582 zn = malloc(sizeof(struct zyd_node), M_80211_NODE, M_NOWAIT | M_ZERO); 583 return (zn != NULL) ? (&zn->ni) : (NULL); 584} 585 | |
586static int 587zyd_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 588{ 589 struct zyd_vap *zvp = ZYD_VAP(vap); 590 struct ieee80211com *ic = vap->iv_ic; 591 struct zyd_softc *sc = ic->ic_ifp->if_softc; 592 struct ieee80211_node *ni; 593 int error; --- 70 unchanged lines hidden (view full) --- 664 /* 665 * Find the node to which the packet was sent and 666 * update its retry statistics. In BSS mode, this node 667 * is the AP we're associated to so no lookup is 668 * actually needed. 669 */ 670 ni = ieee80211_find_txnode(vap, retry->macaddr); 671 if (ni != NULL) { | 568static int 569zyd_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 570{ 571 struct zyd_vap *zvp = ZYD_VAP(vap); 572 struct ieee80211com *ic = vap->iv_ic; 573 struct zyd_softc *sc = ic->ic_ifp->if_softc; 574 struct ieee80211_node *ni; 575 int error; --- 70 unchanged lines hidden (view full) --- 646 /* 647 * Find the node to which the packet was sent and 648 * update its retry statistics. In BSS mode, this node 649 * is the AP we're associated to so no lookup is 650 * actually needed. 651 */ 652 ni = ieee80211_find_txnode(vap, retry->macaddr); 653 if (ni != NULL) { |
672 ieee80211_amrr_tx_complete(&ZYD_NODE(ni)->amn, 673 IEEE80211_AMRR_FAILURE, 674 (int)(le16toh(retry->count) & 0xff)); | 654 int retrycnt = 655 (int)(le16toh(retry->count) & 0xff); 656 657 ieee80211_ratectl_tx_complete(vap, ni, 658 IEEE80211_RATECTL_TX_FAILURE, 659 &retrycnt, NULL); |
675 ieee80211_free_node(ni); 676 } 677 if (le16toh(retry->count) & 0x100) 678 ifp->if_oerrors++; /* too many retries */ 679 break; 680 } 681 case ZYD_NOTIF_IORD: 682 { --- 1810 unchanged lines hidden (view full) --- 2493 } else { 2494 tp = &vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)]; 2495 /* for data frames */ 2496 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) 2497 rate = tp->mcastrate; 2498 else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) 2499 rate = tp->ucastrate; 2500 else { | 660 ieee80211_free_node(ni); 661 } 662 if (le16toh(retry->count) & 0x100) 663 ifp->if_oerrors++; /* too many retries */ 664 break; 665 } 666 case ZYD_NOTIF_IORD: 667 { --- 1810 unchanged lines hidden (view full) --- 2478 } else { 2479 tp = &vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)]; 2480 /* for data frames */ 2481 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) 2482 rate = tp->mcastrate; 2483 else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) 2484 rate = tp->ucastrate; 2485 else { |
2501 (void) ieee80211_amrr_choose(ni, &ZYD_NODE(ni)->amn); | 2486 (void) ieee80211_ratectl_rate(ni, NULL, 0); |
2502 rate = ni->ni_txrate; 2503 } 2504 } 2505 2506 if (wh->i_fc[1] & IEEE80211_FC1_WEP) { 2507 k = ieee80211_crypto_encap(ni, m0); 2508 if (k == NULL) { 2509 m_freem(m0); --- 395 unchanged lines hidden (view full) --- 2905 return (EIO); 2906 2907 sc->sc_flags |= ZYD_FLAG_FWLOADED; 2908 2909 return (stat & 0x80) ? (EIO) : (0); 2910} 2911 2912static void | 2487 rate = ni->ni_txrate; 2488 } 2489 } 2490 2491 if (wh->i_fc[1] & IEEE80211_FC1_WEP) { 2492 k = ieee80211_crypto_encap(ni, m0); 2493 if (k == NULL) { 2494 m_freem(m0); --- 395 unchanged lines hidden (view full) --- 2890 return (EIO); 2891 2892 sc->sc_flags |= ZYD_FLAG_FWLOADED; 2893 2894 return (stat & 0x80) ? (EIO) : (0); 2895} 2896 2897static void |
2913zyd_newassoc(struct ieee80211_node *ni, int isnew) 2914{ 2915 struct ieee80211vap *vap = ni->ni_vap; 2916 2917 ieee80211_amrr_node_init(&ZYD_VAP(vap)->amrr, &ZYD_NODE(ni)->amn, ni); 2918} 2919 2920static void | |
2921zyd_scan_start(struct ieee80211com *ic) 2922{ 2923 struct ifnet *ifp = ic->ic_ifp; 2924 struct zyd_softc *sc = ifp->if_softc; 2925 2926 ZYD_LOCK(sc); 2927 /* want broadcast address while scanning */ 2928 zyd_set_bssid(sc, ifp->if_broadcastaddr); --- 36 unchanged lines hidden (view full) --- 2965 sizeof(struct zyd_softc) 2966}; 2967 2968static devclass_t zyd_devclass; 2969 2970DRIVER_MODULE(zyd, uhub, zyd_driver, zyd_devclass, NULL, 0); 2971MODULE_DEPEND(zyd, usb, 1, 1, 1); 2972MODULE_DEPEND(zyd, wlan, 1, 1, 1); | 2898zyd_scan_start(struct ieee80211com *ic) 2899{ 2900 struct ifnet *ifp = ic->ic_ifp; 2901 struct zyd_softc *sc = ifp->if_softc; 2902 2903 ZYD_LOCK(sc); 2904 /* want broadcast address while scanning */ 2905 zyd_set_bssid(sc, ifp->if_broadcastaddr); --- 36 unchanged lines hidden (view full) --- 2942 sizeof(struct zyd_softc) 2943}; 2944 2945static devclass_t zyd_devclass; 2946 2947DRIVER_MODULE(zyd, uhub, zyd_driver, zyd_devclass, NULL, 0); 2948MODULE_DEPEND(zyd, usb, 1, 1, 1); 2949MODULE_DEPEND(zyd, wlan, 1, 1, 1); |
2973MODULE_DEPEND(zyd, wlan_amrr, 1, 1, 1); | |