3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/sockio.h>
42 #include <sys/malloc.h>
43 #include <sys/kernel.h>
44 #include <sys/socket.h>
45 #include <sys/queue.h>
46 #include <sys/module.h>
47 #if __FreeBSD_version < 502113
48 #include <sys/sysctl.h>
52 #include <net/if_arp.h>
53 #include <net/ethernet.h>
54 #include <net/if_dl.h>
55 #include <net/if_media.h>
56 #include <net/route.h>
60 #include <machine/bus_memio.h>
61 #include <machine/bus_pio.h>
62 #include <machine/bus.h>
63 #include <machine/resource.h>
67 #include <net80211/ieee80211_var.h>
68 #include <net80211/ieee80211_ioctl.h>
70 #include <dev/wi/if_wavelan_ieee.h>
72 #include <dev/pci/pcireg.h>
73 #include <dev/pci/pcivar.h>
75 #include <compat/ndis/pe_var.h>
76 #include <compat/ndis/resource_var.h>
77 #include <compat/ndis/ntoskrnl_var.h>
78 #include <compat/ndis/hal_var.h>
79 #include <compat/ndis/ndis_var.h>
80 #include <compat/ndis/cfg_var.h>
81 #include <dev/if_ndis/if_ndisvar.h>
86 #include "ndis_driver_data.h"
88 int ndis_attach (device_t);
89 int ndis_detach (device_t);
90 int ndis_suspend (device_t);
91 int ndis_resume (device_t);
92 void ndis_shutdown (device_t);
94 int ndisdrv_modevent (module_t, int, void *);
96 static __stdcall void ndis_txeof (ndis_handle,
97 ndis_packet *, ndis_status);
98 static __stdcall void ndis_rxeof (ndis_handle,
99 ndis_packet **, uint32_t);
100 static __stdcall void ndis_linksts (ndis_handle,
101 ndis_status, void *, uint32_t);
102 static __stdcall void ndis_linksts_done (ndis_handle);
104 /* We need to wrap these functions for amd64. */
106 static funcptr ndis_txeof_wrap;
107 static funcptr ndis_rxeof_wrap;
108 static funcptr ndis_linksts_wrap;
109 static funcptr ndis_linksts_done_wrap;
111 static void ndis_intr (void *);
112 static void ndis_intrtask (void *);
113 static void ndis_tick (void *);
114 static void ndis_ticktask (void *);
115 static void ndis_start (struct ifnet *);
116 static void ndis_starttask (void *);
117 static int ndis_ioctl (struct ifnet *, u_long, caddr_t);
118 static int ndis_wi_ioctl_get (struct ifnet *, u_long, caddr_t);
119 static int ndis_wi_ioctl_set (struct ifnet *, u_long, caddr_t);
120 static int ndis_80211_ioctl_get (struct ifnet *, u_long, caddr_t);
121 static int ndis_80211_ioctl_set (struct ifnet *, u_long, caddr_t);
122 static void ndis_init (void *);
123 static void ndis_stop (struct ndis_softc *);
124 static void ndis_watchdog (struct ifnet *);
125 static int ndis_ifmedia_upd (struct ifnet *);
126 static void ndis_ifmedia_sts (struct ifnet *, struct ifmediareq *);
127 static int ndis_get_assoc (struct ndis_softc *, ndis_wlan_bssid_ex **);
128 static int ndis_probe_offload (struct ndis_softc *);
129 static int ndis_set_offload (struct ndis_softc *);
130 static void ndis_getstate_80211 (struct ndis_softc *);
131 static void ndis_setstate_80211 (struct ndis_softc *);
132 static void ndis_media_status (struct ifnet *, struct ifmediareq *);
134 static void ndis_setmulti (struct ndis_softc *);
135 static void ndis_map_sclist (void *, bus_dma_segment_t *,
136 int, bus_size_t, int);
138 static int ndisdrv_loaded = 0;
141 * This routine should call windrv_load() once for each driver
142 * image. This will do the relocation and dynalinking for the
143 * image, and create a Windows driver object which will be
144 * saved in our driver database.
148 ndisdrv_modevent(mod, cmd, arg)
158 if (ndisdrv_loaded > 1)
160 windrv_load(mod, (vm_offset_t)drv_data, 0);
161 windrv_wrap((funcptr)ndis_rxeof, &ndis_rxeof_wrap);
162 windrv_wrap((funcptr)ndis_txeof, &ndis_txeof_wrap);
163 windrv_wrap((funcptr)ndis_linksts, &ndis_linksts_wrap);
164 windrv_wrap((funcptr)ndis_linksts_done,
165 &ndis_linksts_done_wrap);
169 if (ndisdrv_loaded > 0)
171 windrv_unload(mod, (vm_offset_t)drv_data, 0);
172 windrv_unwrap(ndis_rxeof_wrap);
173 windrv_unwrap(ndis_txeof_wrap);
174 windrv_unwrap(ndis_linksts_wrap);
175 windrv_unwrap(ndis_linksts_done_wrap);
178 windrv_unwrap(ndis_rxeof_wrap);
179 windrv_unwrap(ndis_txeof_wrap);
180 windrv_unwrap(ndis_linksts_wrap);
181 windrv_unwrap(ndis_linksts_done_wrap);
192 * Program the 64-bit multicast hash filter.
196 struct ndis_softc *sc;
199 struct ifmultiaddr *ifma;
200 int len, mclistsz, error;
203 ifp = &sc->arpcom.ac_if;
205 if (!NDIS_INITIALIZED(sc))
208 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
209 sc->ndis_filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
210 len = sizeof(sc->ndis_filter);
211 error = ndis_set_info(sc, OID_GEN_CURRENT_PACKET_FILTER,
212 &sc->ndis_filter, &len);
214 device_printf (sc->ndis_dev,
215 "set filter failed: %d\n", error);
219 if (TAILQ_EMPTY(&ifp->if_multiaddrs))
222 len = sizeof(mclistsz);
223 ndis_get_info(sc, OID_802_3_MAXIMUM_LIST_SIZE, &mclistsz, &len);
225 mclist = malloc(ETHER_ADDR_LEN * mclistsz, M_TEMP, M_NOWAIT|M_ZERO);
227 if (mclist == NULL) {
228 sc->ndis_filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
232 sc->ndis_filter |= NDIS_PACKET_TYPE_MULTICAST;
235 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
236 if (ifma->ifma_addr->sa_family != AF_LINK)
238 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
239 mclist + (ETHER_ADDR_LEN * len), ETHER_ADDR_LEN);
241 if (len > mclistsz) {
242 sc->ndis_filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
243 sc->ndis_filter &= ~NDIS_PACKET_TYPE_MULTICAST;
248 len = len * ETHER_ADDR_LEN;
249 error = ndis_set_info(sc, OID_802_3_MULTICAST_LIST, mclist, &len);
251 device_printf (sc->ndis_dev, "set mclist failed: %d\n", error);
252 sc->ndis_filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
253 sc->ndis_filter &= ~NDIS_PACKET_TYPE_MULTICAST;
257 free(mclist, M_TEMP);
259 len = sizeof(sc->ndis_filter);
260 error = ndis_set_info(sc, OID_GEN_CURRENT_PACKET_FILTER,
261 &sc->ndis_filter, &len);
263 device_printf (sc->ndis_dev, "set filter failed: %d\n", error);
270 struct ndis_softc *sc;
272 ndis_task_offload *nto;
273 ndis_task_offload_hdr *ntoh;
274 ndis_task_tcpip_csum *nttc;
278 ifp = &sc->arpcom.ac_if;
280 if (!NDIS_INITIALIZED(sc))
283 /* See if there's anything to set. */
285 error = ndis_probe_offload(sc);
289 if (sc->ndis_hwassist == 0 && ifp->if_capabilities == 0)
292 len = sizeof(ndis_task_offload_hdr) + sizeof(ndis_task_offload) +
293 sizeof(ndis_task_tcpip_csum);
295 ntoh = malloc(len, M_TEMP, M_NOWAIT|M_ZERO);
300 ntoh->ntoh_vers = NDIS_TASK_OFFLOAD_VERSION;
301 ntoh->ntoh_len = sizeof(ndis_task_offload_hdr);
302 ntoh->ntoh_offset_firsttask = sizeof(ndis_task_offload_hdr);
303 ntoh->ntoh_encapfmt.nef_encaphdrlen = sizeof(struct ether_header);
304 ntoh->ntoh_encapfmt.nef_encap = NDIS_ENCAP_IEEE802_3;
305 ntoh->ntoh_encapfmt.nef_flags = NDIS_ENCAPFLAG_FIXEDHDRLEN;
307 nto = (ndis_task_offload *)((char *)ntoh +
308 ntoh->ntoh_offset_firsttask);
310 nto->nto_vers = NDIS_TASK_OFFLOAD_VERSION;
311 nto->nto_len = sizeof(ndis_task_offload);
312 nto->nto_task = NDIS_TASK_TCPIP_CSUM;
313 nto->nto_offset_nexttask = 0;
314 nto->nto_taskbuflen = sizeof(ndis_task_tcpip_csum);
316 nttc = (ndis_task_tcpip_csum *)nto->nto_taskbuf;
318 if (ifp->if_capenable & IFCAP_TXCSUM)
319 nttc->nttc_v4tx = sc->ndis_v4tx;
321 if (ifp->if_capenable & IFCAP_RXCSUM)
322 nttc->nttc_v4rx = sc->ndis_v4rx;
324 error = ndis_set_info(sc, OID_TCP_TASK_OFFLOAD, ntoh, &len);
331 ndis_probe_offload(sc)
332 struct ndis_softc *sc;
334 ndis_task_offload *nto;
335 ndis_task_offload_hdr *ntoh;
336 ndis_task_tcpip_csum *nttc = NULL;
338 int len, error, dummy;
340 ifp = &sc->arpcom.ac_if;
343 error = ndis_get_info(sc, OID_TCP_TASK_OFFLOAD, &dummy, &len);
348 ntoh = malloc(len, M_TEMP, M_NOWAIT|M_ZERO);
353 ntoh->ntoh_vers = NDIS_TASK_OFFLOAD_VERSION;
354 ntoh->ntoh_len = sizeof(ndis_task_offload_hdr);
355 ntoh->ntoh_encapfmt.nef_encaphdrlen = sizeof(struct ether_header);
356 ntoh->ntoh_encapfmt.nef_encap = NDIS_ENCAP_IEEE802_3;
357 ntoh->ntoh_encapfmt.nef_flags = NDIS_ENCAPFLAG_FIXEDHDRLEN;
359 error = ndis_get_info(sc, OID_TCP_TASK_OFFLOAD, ntoh, &len);
366 if (ntoh->ntoh_vers != NDIS_TASK_OFFLOAD_VERSION) {
371 nto = (ndis_task_offload *)((char *)ntoh +
372 ntoh->ntoh_offset_firsttask);
375 switch (nto->nto_task) {
376 case NDIS_TASK_TCPIP_CSUM:
377 nttc = (ndis_task_tcpip_csum *)nto->nto_taskbuf;
379 /* Don't handle these yet. */
380 case NDIS_TASK_IPSEC:
381 case NDIS_TASK_TCP_LARGESEND:
385 if (nto->nto_offset_nexttask == 0)
387 nto = (ndis_task_offload *)((char *)nto +
388 nto->nto_offset_nexttask);
396 sc->ndis_v4tx = nttc->nttc_v4tx;
397 sc->ndis_v4rx = nttc->nttc_v4rx;
399 if (nttc->nttc_v4tx & NDIS_TCPSUM_FLAGS_IP_CSUM)
400 sc->ndis_hwassist |= CSUM_IP;
401 if (nttc->nttc_v4tx & NDIS_TCPSUM_FLAGS_TCP_CSUM)
402 sc->ndis_hwassist |= CSUM_TCP;
403 if (nttc->nttc_v4tx & NDIS_TCPSUM_FLAGS_UDP_CSUM)
404 sc->ndis_hwassist |= CSUM_UDP;
406 if (sc->ndis_hwassist)
407 ifp->if_capabilities |= IFCAP_TXCSUM;
409 if (nttc->nttc_v4rx & NDIS_TCPSUM_FLAGS_IP_CSUM)
410 ifp->if_capabilities |= IFCAP_RXCSUM;
411 if (nttc->nttc_v4rx & NDIS_TCPSUM_FLAGS_TCP_CSUM)
412 ifp->if_capabilities |= IFCAP_RXCSUM;
413 if (nttc->nttc_v4rx & NDIS_TCPSUM_FLAGS_UDP_CSUM)
414 ifp->if_capabilities |= IFCAP_RXCSUM;
421 * Attach the interface. Allocate softc structures, do ifmedia
422 * setup and ethernet/BPF attach.
428 u_char eaddr[ETHER_ADDR_LEN];
429 struct ndis_softc *sc;
433 struct ifnet *ifp = NULL;
438 sc = device_get_softc(dev);
440 mtx_init(&sc->ndis_mtx, "ndis softc lock",
441 MTX_NETWORK_LOCK, MTX_DEF);
444 * Hook interrupt early, since calling the driver's
445 * init routine may trigger an interrupt. Note that
446 * we don't need to do any explicit interrupt setup
450 if (sc->ndis_iftype == PCMCIABus || sc->ndis_iftype == PCIBus) {
451 error = bus_setup_intr(dev, sc->ndis_irq,
452 INTR_TYPE_NET | INTR_MPSAFE,
453 ndis_intr, sc, &sc->ndis_intrhand);
456 device_printf(dev, "couldn't set up irq\n");
461 if (sc->ndis_iftype == PCMCIABus) {
462 error = ndis_alloc_amem(sc);
464 device_printf(dev, "failed to allocate "
465 "attribute memory\n");
470 sc->ndis_regvals = ndis_regvals;
472 #if __FreeBSD_version < 502113
473 sysctl_ctx_init(&sc->ndis_ctx);
476 /* Create sysctl registry nodes */
477 ndis_create_sysctls(sc);
479 /* Find the PDO for this device instance. */
481 if (sc->ndis_iftype == PCIBus)
482 pdrv = windrv_lookup(0, "PCI Bus");
483 else if (sc->ndis_iftype == PCMCIABus)
484 pdrv = windrv_lookup(0, "PCCARD Bus");
486 pdrv = windrv_lookup(0, "USB Bus");
487 pdo = windrv_find_pdo(pdrv, dev);
490 * Create a new functional device object for this
491 * device. This is what creates the miniport block
492 * for this device instance.
496 drv = windrv_lookup((vm_offset_t)img, NULL);
497 if (NdisAddDevice(drv, pdo) != STATUS_SUCCESS) {
498 device_printf(dev, "failed to create FDO!\n");
503 /* Tell the user what version of the API the driver is using. */
504 device_printf(dev, "NDIS API version: %d.%d\n",
505 sc->ndis_chars->nmc_version_major,
506 sc->ndis_chars->nmc_version_minor);
508 /* Do resource conversion. */
509 if (sc->ndis_iftype == PCMCIABus || sc->ndis_iftype == PCIBus)
510 ndis_convert_res(sc);
512 sc->ndis_block->nmb_rlist = NULL;
514 /* Install our RX and TX interrupt handlers. */
515 sc->ndis_block->nmb_senddone_func = ndis_txeof_wrap;
516 sc->ndis_block->nmb_pktind_func = ndis_rxeof_wrap;
518 /* Call driver's init routine. */
519 if (ndis_init_nic(sc)) {
520 device_printf (dev, "init handler failed\n");
526 * Get station address from the driver.
529 ndis_get_info(sc, OID_802_3_CURRENT_ADDRESS, &eaddr, &len);
531 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
534 * Figure out if we're allowed to use multipacket sends
535 * with this driver, and if so, how many.
538 if (sc->ndis_chars->nmc_sendsingle_func &&
539 sc->ndis_chars->nmc_sendmulti_func == NULL) {
540 sc->ndis_maxpkts = 1;
542 len = sizeof(sc->ndis_maxpkts);
543 ndis_get_info(sc, OID_GEN_MAXIMUM_SEND_PACKETS,
544 &sc->ndis_maxpkts, &len);
547 sc->ndis_txarray = malloc(sizeof(ndis_packet *) *
548 sc->ndis_maxpkts, M_DEVBUF, M_NOWAIT|M_ZERO);
550 /* Allocate a pool of ndis_packets for TX encapsulation. */
552 NdisAllocatePacketPool(&i, &sc->ndis_txpool,
553 sc->ndis_maxpkts, PROTOCOL_RESERVED_SIZE_IN_PACKET);
555 if (i != NDIS_STATUS_SUCCESS) {
556 sc->ndis_txpool = NULL;
557 device_printf(dev, "failed to allocate TX packet pool");
562 sc->ndis_txpending = sc->ndis_maxpkts;
565 /* Get supported oid list. */
566 ndis_get_supported_oids(sc, &sc->ndis_oids, &sc->ndis_oidcnt);
568 /* If the NDIS module requested scatter/gather, init maps. */
573 * See if the OID_802_11_CONFIGURATION OID is
574 * supported by this driver. If it is, then this an 802.11
575 * wireless driver, and we should set up media for wireless.
577 for (i = 0; i < sc->ndis_oidcnt; i++) {
578 if (sc->ndis_oids[i] == OID_802_11_CONFIGURATION) {
584 /* Check for task offload support. */
585 ndis_probe_offload(sc);
587 ifp = &sc->arpcom.ac_if;
589 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
590 ifp->if_mtu = ETHERMTU;
591 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
592 ifp->if_ioctl = ndis_ioctl;
593 ifp->if_start = ndis_start;
594 ifp->if_watchdog = ndis_watchdog;
595 ifp->if_init = ndis_init;
596 ifp->if_baudrate = 10000000;
597 #if __FreeBSD_version < 502114
598 ifp->if_snd.ifq_maxlen = 50;
600 IFQ_SET_MAXLEN(&ifp->if_snd, 50);
601 ifp->if_snd.ifq_drv_maxlen = 25;
602 IFQ_SET_READY(&ifp->if_snd);
604 ifp->if_capenable = ifp->if_capabilities;
605 ifp->if_hwassist = sc->ndis_hwassist;
608 if (sc->ndis_80211) {
609 struct ieee80211com *ic = (void *)&sc->ic;
610 ndis_80211_rates_ex rates;
611 struct ndis_80211_nettype_list *ntl;
616 ic->ic_phytype = IEEE80211_T_DS;
617 ic->ic_opmode = IEEE80211_M_STA;
618 ic->ic_caps = IEEE80211_C_IBSS;
619 ic->ic_state = IEEE80211_S_ASSOC;
620 ic->ic_modecaps = (1<<IEEE80211_MODE_AUTO);
622 r = ndis_get_info(sc, OID_802_11_NETWORK_TYPES_SUPPORTED,
626 ntl = malloc(len, M_DEVBUF, M_WAITOK|M_ZERO);
627 r = ndis_get_info(sc, OID_802_11_NETWORK_TYPES_SUPPORTED,
634 for (i = 0; i < ntl->ntl_items; i++) {
635 switch (ntl->ntl_type[i]) {
636 case NDIS_80211_NETTYPE_11FH:
637 case NDIS_80211_NETTYPE_11DS:
638 ic->ic_modecaps |= (1<<IEEE80211_MODE_11B);
640 case NDIS_80211_NETTYPE_11OFDM5:
641 ic->ic_modecaps |= (1<<IEEE80211_MODE_11A);
643 case NDIS_80211_NETTYPE_11OFDM24:
644 ic->ic_modecaps |= (1<<IEEE80211_MODE_11G);
653 bzero((char *)&rates, len);
654 r = ndis_get_info(sc, OID_802_11_SUPPORTED_RATES,
655 (void *)rates, &len);
657 device_printf (dev, "get rates failed: 0x%x\n", r);
659 * Since the supported rates only up to 8 can be supported,
660 * if this is not 802.11b we're just going to be faking it
664 #define TESTSETRATE(x, y) \
667 for (i = 0; i < ic->ic_sup_rates[x].rs_nrates; i++) { \
668 if (ic->ic_sup_rates[x].rs_rates[i] == (y)) \
671 if (i == ic->ic_sup_rates[x].rs_nrates) { \
672 ic->ic_sup_rates[x].rs_rates[i] = (y); \
673 ic->ic_sup_rates[x].rs_nrates++; \
677 #define SETRATE(x, y) \
678 ic->ic_sup_rates[x].rs_rates[ic->ic_sup_rates[x].rs_nrates] = (y)
680 ic->ic_sup_rates[x].rs_nrates++
682 ic->ic_curmode = IEEE80211_MODE_AUTO;
683 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11A))
684 ic->ic_sup_rates[IEEE80211_MODE_11A].rs_nrates = 0;
685 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11B))
686 ic->ic_sup_rates[IEEE80211_MODE_11B].rs_nrates = 0;
687 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11G))
688 ic->ic_sup_rates[IEEE80211_MODE_11G].rs_nrates = 0;
689 for (i = 0; i < len; i++) {
690 switch (rates[i] & IEEE80211_RATE_VAL) {
696 if (!(ic->ic_modecaps &
697 (1<<IEEE80211_MODE_11B))) {
698 /* Lazy-init 802.11b. */
700 (1<<IEEE80211_MODE_11B);
701 ic->ic_sup_rates[IEEE80211_MODE_11B].
704 SETRATE(IEEE80211_MODE_11B, rates[i]);
705 INCRATE(IEEE80211_MODE_11B);
708 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11A)) {
709 SETRATE(IEEE80211_MODE_11A, rates[i]);
710 INCRATE(IEEE80211_MODE_11A);
712 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11G)) {
713 SETRATE(IEEE80211_MODE_11G, rates[i]);
714 INCRATE(IEEE80211_MODE_11G);
721 * If the hardware supports 802.11g, it most
722 * likely supports 802.11b and all of the
723 * 802.11b and 802.11g speeds, so maybe we can
724 * just cheat here. Just how in the heck do
725 * we detect turbo modes, though?
727 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11B)) {
728 TESTSETRATE(IEEE80211_MODE_11B,
729 IEEE80211_RATE_BASIC|2);
730 TESTSETRATE(IEEE80211_MODE_11B,
731 IEEE80211_RATE_BASIC|4);
732 TESTSETRATE(IEEE80211_MODE_11B,
733 IEEE80211_RATE_BASIC|11);
734 TESTSETRATE(IEEE80211_MODE_11B,
735 IEEE80211_RATE_BASIC|22);
737 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11G)) {
738 TESTSETRATE(IEEE80211_MODE_11G, 47);
739 TESTSETRATE(IEEE80211_MODE_11G, 72);
740 TESTSETRATE(IEEE80211_MODE_11G, 96);
741 TESTSETRATE(IEEE80211_MODE_11G, 108);
743 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11A)) {
744 TESTSETRATE(IEEE80211_MODE_11A, 47);
745 TESTSETRATE(IEEE80211_MODE_11A, 72);
746 TESTSETRATE(IEEE80211_MODE_11A, 96);
747 TESTSETRATE(IEEE80211_MODE_11A, 108);
752 * Taking yet more guesses here.
754 for (i = 1; i < IEEE80211_CHAN_MAX; i++) {
757 if (ic->ic_sup_rates[IEEE80211_MODE_11G].rs_nrates)
758 chanflag |= IEEE80211_CHAN_G;
760 chanflag |= IEEE80211_CHAN_B;
761 if (ic->ic_sup_rates[IEEE80211_MODE_11A].rs_nrates &&
763 chanflag = IEEE80211_CHAN_A;
766 ic->ic_channels[i].ic_freq =
767 ieee80211_ieee2mhz(i, chanflag);
768 ic->ic_channels[i].ic_flags = chanflag;
772 r = ndis_get_info(sc, OID_802_11_WEP_STATUS, &arg, &i);
773 if (arg != NDIS_80211_WEPSTAT_NOTSUPPORTED)
774 ic->ic_caps |= IEEE80211_C_WEP;
776 r = ndis_get_info(sc, OID_802_11_POWER_MODE, &arg, &i);
778 ic->ic_caps |= IEEE80211_C_PMGT;
779 bcopy(eaddr, &ic->ic_myaddr, sizeof(eaddr));
780 ieee80211_ifattach(ic);
781 ieee80211_media_init(ic, ieee80211_media_change,
783 ic->ic_ibss_chan = IEEE80211_CHAN_ANYC;
784 ic->ic_bss->ni_chan = ic->ic_ibss_chan;
786 ifmedia_init(&sc->ifmedia, IFM_IMASK, ndis_ifmedia_upd,
788 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);
789 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL);
790 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_TX, 0, NULL);
791 ifmedia_add(&sc->ifmedia,
792 IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL);
793 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
794 ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO);
795 ether_ifattach(ifp, eaddr);
798 /* Override the status handler so we can detect link changes. */
799 sc->ndis_block->nmb_status_func = ndis_linksts_wrap;
800 sc->ndis_block->nmb_statusdone_func = ndis_linksts_done_wrap;
805 /* We're done talking to the NIC for now; halt it. */
812 * Shutdown hardware and free up resources. This can be called any
813 * time after the mutex has been initialized. It is called in both
814 * the error case in attach and the normal detach case so it needs
815 * to be careful about only freeing resources that have actually been
822 struct ndis_softc *sc;
826 sc = device_get_softc(dev);
827 KASSERT(mtx_initialized(&sc->ndis_mtx),
828 ("ndis mutex not initialized"));
830 ifp = &sc->arpcom.ac_if;
831 ifp->if_flags &= ~IFF_UP;
833 if (device_is_attached(dev)) {
837 ieee80211_ifdetach(&sc->ic);
843 bus_generic_detach(dev);
845 if (sc->ndis_intrhand)
846 bus_teardown_intr(dev, sc->ndis_irq, sc->ndis_intrhand);
848 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ndis_irq);
850 bus_release_resource(dev, SYS_RES_IOPORT,
851 sc->ndis_io_rid, sc->ndis_res_io);
852 if (sc->ndis_res_mem)
853 bus_release_resource(dev, SYS_RES_MEMORY,
854 sc->ndis_mem_rid, sc->ndis_res_mem);
855 if (sc->ndis_res_altmem)
856 bus_release_resource(dev, SYS_RES_MEMORY,
857 sc->ndis_altmem_rid, sc->ndis_res_altmem);
859 if (sc->ndis_iftype == PCMCIABus)
863 ndis_destroy_dma(sc);
865 if (sc->ndis_txarray)
866 free(sc->ndis_txarray, M_DEVBUF);
869 ifmedia_removeall(&sc->ifmedia);
871 if (sc->ndis_txpool != NULL)
872 NdisFreePacketPool(sc->ndis_txpool);
874 ndis_unload_driver(sc);
876 /* Destroy the PDO for this device. */
878 if (sc->ndis_iftype == PCIBus)
879 drv = windrv_lookup(0, "PCI Bus");
880 else if (sc->ndis_iftype == PCMCIABus)
881 drv = windrv_lookup(0, "PCCARD Bus");
883 drv = windrv_lookup(0, "USB Bus");
885 panic("couldn't find driver object");
886 windrv_destroy_pdo(drv, dev);
888 if (sc->ndis_iftype == PCIBus)
889 bus_dma_tag_destroy(sc->ndis_parent_tag);
891 #if __FreeBSD_version < 502113
892 sysctl_ctx_free(&sc->ndis_ctx);
895 mtx_destroy(&sc->ndis_mtx);
904 struct ndis_softc *sc;
907 sc = device_get_softc(dev);
908 ifp = &sc->arpcom.ac_if;
911 if (NDIS_INITIALIZED(sc))
922 struct ndis_softc *sc;
925 sc = device_get_softc(dev);
926 ifp = &sc->arpcom.ac_if;
928 if (NDIS_INITIALIZED(sc))
935 * A frame has been uploaded: pass the resulting mbuf chain up to
936 * the higher level protocols.
938 * When handling received NDIS packets, the 'status' field in the
939 * out-of-band portion of the ndis_packet has special meaning. In the
940 * most common case, the underlying NDIS driver will set this field
941 * to NDIS_STATUS_SUCCESS, which indicates that it's ok for us to
942 * take posession of it. We then change the status field to
943 * NDIS_STATUS_PENDING to tell the driver that we now own the packet,
944 * and that we will return it at some point in the future via the
945 * return packet handler.
947 * If the driver hands us a packet with a status of NDIS_STATUS_RESOURCES,
948 * this means the driver is running out of packet/buffer resources and
949 * wants to maintain ownership of the packet. In this case, we have to
950 * copy the packet data into local storage and let the driver keep the
953 __stdcall static void
954 ndis_rxeof(adapter, packets, pktcnt)
956 ndis_packet **packets;
959 struct ndis_softc *sc;
960 ndis_miniport_block *block;
963 ndis_tcpip_csum *csum;
968 block = (ndis_miniport_block *)adapter;
969 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
970 ifp = &sc->arpcom.ac_if;
972 for (i = 0; i < pktcnt; i++) {
974 /* Stash the softc here so ptom can use it. */
976 if (ndis_ptom(&m0, p)) {
977 device_printf (sc->ndis_dev, "ptom failed\n");
978 if (p->np_oob.npo_status == NDIS_STATUS_SUCCESS)
979 ndis_return_packet(sc, p);
981 if (p->np_oob.npo_status == NDIS_STATUS_RESOURCES) {
982 m = m_dup(m0, M_DONTWAIT);
984 * NOTE: we want to destroy the mbuf here, but
985 * we don't actually want to return it to the
986 * driver via the return packet handler. By
987 * bumping np_refcnt, we can prevent the
988 * ndis_return_packet() routine from actually
998 p->np_oob.npo_status = NDIS_STATUS_PENDING;
999 m0->m_pkthdr.rcvif = ifp;
1002 /* Deal with checksum offload. */
1004 if (ifp->if_capenable & IFCAP_RXCSUM &&
1005 p->np_ext.npe_info[ndis_tcpipcsum_info] != NULL) {
1007 p->np_ext.npe_info[ndis_tcpipcsum_info];
1008 csum = (ndis_tcpip_csum *)&s;
1009 if (csum->u.ntc_rxflags &
1010 NDIS_RXCSUM_IP_PASSED)
1011 m0->m_pkthdr.csum_flags |=
1012 CSUM_IP_CHECKED|CSUM_IP_VALID;
1013 if (csum->u.ntc_rxflags &
1014 (NDIS_RXCSUM_TCP_PASSED |
1015 NDIS_RXCSUM_UDP_PASSED)) {
1016 m0->m_pkthdr.csum_flags |=
1017 CSUM_DATA_VALID|CSUM_PSEUDO_HDR;
1018 m0->m_pkthdr.csum_data = 0xFFFF;
1022 (*ifp->if_input)(ifp, m0);
1030 * A frame was downloaded to the chip. It's safe for us to clean up
1033 __stdcall static void
1034 ndis_txeof(adapter, packet, status)
1035 ndis_handle adapter;
1036 ndis_packet *packet;
1040 struct ndis_softc *sc;
1041 ndis_miniport_block *block;
1046 block = (ndis_miniport_block *)adapter;
1047 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1048 ifp = &sc->arpcom.ac_if;
1051 idx = packet->np_txidx;
1053 bus_dmamap_unload(sc->ndis_ttag, sc->ndis_tmaps[idx]);
1055 ndis_free_packet(packet);
1059 sc->ndis_txarray[idx] = NULL;
1060 sc->ndis_txpending++;
1062 if (status == NDIS_STATUS_SUCCESS)
1067 ifp->if_flags &= ~IFF_OACTIVE;
1070 ndis_sched(ndis_starttask, ifp, NDIS_TASKQUEUE);
1075 __stdcall static void
1076 ndis_linksts(adapter, status, sbuf, slen)
1077 ndis_handle adapter;
1082 ndis_miniport_block *block;
1085 block->nmb_getstat = status;
1090 __stdcall static void
1091 ndis_linksts_done(adapter)
1092 ndis_handle adapter;
1094 ndis_miniport_block *block;
1095 struct ndis_softc *sc;
1099 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1100 ifp = &sc->arpcom.ac_if;
1103 if (!NDIS_INITIALIZED(sc)) {
1108 switch (block->nmb_getstat) {
1109 case NDIS_STATUS_MEDIA_CONNECT:
1110 ndis_sched(ndis_ticktask, sc, NDIS_TASKQUEUE);
1111 ndis_sched(ndis_starttask, ifp, NDIS_TASKQUEUE);
1113 case NDIS_STATUS_MEDIA_DISCONNECT:
1115 ndis_sched(ndis_ticktask, sc, NDIS_TASKQUEUE);
1129 struct ndis_softc *sc;
1134 ifp = &sc->arpcom.ac_if;
1136 irql = KeRaiseIrql(DISPATCH_LEVEL);
1140 ndis_enable_intr(sc);
1149 struct ndis_softc *sc;
1151 int is_our_intr = 0;
1154 ndis_miniport_interrupt *intr;
1157 ifp = &sc->arpcom.ac_if;
1158 intr = sc->ndis_block->nmb_interrupt;
1160 if (sc->ndis_block->nmb_miniportadapterctx == NULL)
1163 KeAcquireSpinLock(&intr->ni_dpccountlock, &irql);
1164 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
1165 ndis_isr(sc, &is_our_intr, &call_isr);
1167 ndis_disable_intr(sc);
1170 KeReleaseSpinLock(&intr->ni_dpccountlock, irql);
1172 if ((is_our_intr || call_isr))
1173 ndis_sched(ndis_intrtask, ifp->if_softc, NDIS_SWI);
1182 struct ndis_softc *sc;
1188 ndis_sched(ndis_ticktask, sc, NDIS_TASKQUEUE);
1189 sc->ndis_stat_ch = timeout(ndis_tick, sc, hz *
1190 sc->ndis_block->nmb_checkforhangsecs);
1201 struct ndis_softc *sc;
1202 __stdcall ndis_checkforhang_handler hangfunc;
1204 ndis_media_state linkstate;
1209 hangfunc = sc->ndis_chars->nmc_checkhang_func;
1211 if (hangfunc != NULL) {
1212 rval = hangfunc(sc->ndis_block->nmb_miniportadapterctx);
1219 len = sizeof(linkstate);
1220 error = ndis_get_info(sc, OID_GEN_MEDIA_CONNECT_STATUS,
1221 (void *)&linkstate, &len);
1225 if (sc->ndis_link == 0 && linkstate == nmc_connected) {
1226 device_printf(sc->ndis_dev, "link up\n");
1230 ndis_getstate_80211(sc);
1232 #ifdef LINK_STATE_UP
1233 sc->arpcom.ac_if.if_link_state = LINK_STATE_UP;
1234 rt_ifmsg(&(sc->arpcom.ac_if));
1235 #endif /* LINK_STATE_UP */
1238 if (sc->ndis_link == 1 && linkstate == nmc_disconnected) {
1239 device_printf(sc->ndis_dev, "link down\n");
1241 #ifdef LINK_STATE_DOWN
1242 sc->arpcom.ac_if.if_link_state = LINK_STATE_DOWN;
1243 rt_ifmsg(&(sc->arpcom.ac_if));
1244 #endif /* LINK_STATE_DOWN */
1253 ndis_map_sclist(arg, segs, nseg, mapsize, error)
1255 bus_dma_segment_t *segs;
1261 struct ndis_sc_list *sclist;
1264 if (error || arg == NULL)
1269 sclist->nsl_frags = nseg;
1271 for (i = 0; i < nseg; i++) {
1272 sclist->nsl_elements[i].nse_addr.np_quad = segs[i].ds_addr;
1273 sclist->nsl_elements[i].nse_len = segs[i].ds_len;
1286 #if __FreeBSD_version < 502114
1287 if (ifp->if_snd.ifq_head != NULL)
1289 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1296 * Main transmit routine. To make NDIS drivers happy, we need to
1297 * transform mbuf chains into NDIS packets and feed them to the
1298 * send packet routines. Most drivers allow you to send several
1299 * packets at once (up to the maxpkts limit). Unfortunately, rather
1300 * that accepting them in the form of a linked list, they expect
1301 * a contiguous array of pointers to packets.
1303 * For those drivers which use the NDIS scatter/gather DMA mechanism,
1304 * we need to perform busdma work here. Those that use map registers
1305 * will do the mapping themselves on a buffer by buffer basis.
1312 struct ndis_softc *sc;
1313 struct mbuf *m = NULL;
1314 ndis_packet **p0 = NULL, *p = NULL;
1315 ndis_tcpip_csum *csum;
1316 int pcnt = 0, status;
1322 if (!sc->ndis_link || ifp->if_flags & IFF_OACTIVE) {
1327 p0 = &sc->ndis_txarray[sc->ndis_txidx];
1329 while(sc->ndis_txpending) {
1330 #if __FreeBSD_version < 502114
1331 IF_DEQUEUE(&ifp->if_snd, m);
1333 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
1338 NdisAllocatePacket(&status,
1339 &sc->ndis_txarray[sc->ndis_txidx], sc->ndis_txpool);
1341 if (status != NDIS_STATUS_SUCCESS)
1344 if (ndis_mtop(m, &sc->ndis_txarray[sc->ndis_txidx])) {
1345 #if __FreeBSD_version >= 502114
1346 IFQ_DRV_PREPEND(&ifp->if_snd, m);
1349 #if __FreeBSD_version < 502114
1350 IF_PREPEND(&ifp->if_snd, m);
1356 * Save pointer to original mbuf
1357 * so we can free it later.
1360 p = sc->ndis_txarray[sc->ndis_txidx];
1361 p->np_txidx = sc->ndis_txidx;
1363 p->np_oob.npo_status = NDIS_STATUS_PENDING;
1366 * Do scatter/gather processing, if driver requested it.
1369 bus_dmamap_load_mbuf(sc->ndis_ttag,
1370 sc->ndis_tmaps[sc->ndis_txidx], m,
1371 ndis_map_sclist, &p->np_sclist, BUS_DMA_NOWAIT);
1372 bus_dmamap_sync(sc->ndis_ttag,
1373 sc->ndis_tmaps[sc->ndis_txidx],
1374 BUS_DMASYNC_PREREAD);
1375 p->np_ext.npe_info[ndis_sclist_info] = &p->np_sclist;
1378 /* Handle checksum offload. */
1380 if (ifp->if_capenable & IFCAP_TXCSUM &&
1381 m->m_pkthdr.csum_flags) {
1382 csum = (ndis_tcpip_csum *)
1383 &p->np_ext.npe_info[ndis_tcpipcsum_info];
1384 csum->u.ntc_txflags = NDIS_TXCSUM_DO_IPV4;
1385 if (m->m_pkthdr.csum_flags & CSUM_IP)
1386 csum->u.ntc_txflags |= NDIS_TXCSUM_DO_IP;
1387 if (m->m_pkthdr.csum_flags & CSUM_TCP)
1388 csum->u.ntc_txflags |= NDIS_TXCSUM_DO_TCP;
1389 if (m->m_pkthdr.csum_flags & CSUM_UDP)
1390 csum->u.ntc_txflags |= NDIS_TXCSUM_DO_UDP;
1391 p->np_private.npp_flags = NDIS_PROTOCOL_ID_TCP_IP;
1395 sc->ndis_txpending--;
1400 * If there's a BPF listener, bounce a copy of this frame
1407 * The array that p0 points to must appear contiguous,
1408 * so we must not wrap past the end of sc->ndis_txarray[].
1409 * If it looks like we're about to wrap, break out here
1410 * so the this batch of packets can be transmitted, then
1411 * wait for txeof to ask us to send the rest.
1414 if (sc->ndis_txidx == 0)
1423 if (sc->ndis_txpending == 0)
1424 ifp->if_flags |= IFF_OACTIVE;
1427 * Set a timeout in case the chip goes out to lunch.
1433 if (sc->ndis_maxpkts == 1)
1434 ndis_send_packet(sc, p);
1436 ndis_send_packets(sc, p0, pcnt);
1445 struct ndis_softc *sc = xsc;
1446 struct ifnet *ifp = &sc->arpcom.ac_if;
1450 * Avoid reintializing the link unnecessarily.
1451 * This should be dealt with in a better way by
1452 * fixing the upper layer modules so they don't
1453 * call ifp->if_init() quite as often.
1455 if (sc->ndis_link && sc->ndis_skip)
1459 * Cancel pending I/O and free all RX/TX buffers.
1462 if (ndis_init_nic(sc))
1465 /* Init our MAC address */
1467 /* Program the packet filter */
1469 sc->ndis_filter = NDIS_PACKET_TYPE_DIRECTED;
1471 if (ifp->if_flags & IFF_BROADCAST)
1472 sc->ndis_filter |= NDIS_PACKET_TYPE_BROADCAST;
1474 if (ifp->if_flags & IFF_PROMISC)
1475 sc->ndis_filter |= NDIS_PACKET_TYPE_PROMISCUOUS;
1477 i = sizeof(sc->ndis_filter);
1479 error = ndis_set_info(sc, OID_GEN_CURRENT_PACKET_FILTER,
1480 &sc->ndis_filter, &i);
1483 device_printf (sc->ndis_dev, "set filter failed: %d\n", error);
1486 * Program the multicast filter, if necessary.
1490 /* Setup task offload. */
1491 ndis_set_offload(sc);
1493 /* Enable interrupts. */
1494 ndis_enable_intr(sc);
1497 ndis_setstate_80211(sc);
1502 sc->ndis_txpending = sc->ndis_maxpkts;
1505 ifp->if_flags |= IFF_RUNNING;
1506 ifp->if_flags &= ~IFF_OACTIVE;
1511 * Some drivers don't set this value. The NDIS spec says
1512 * the default checkforhang timeout is "approximately 2
1513 * seconds." We use 3 seconds, because it seems for some
1514 * drivers, exactly 2 seconds is too fast.
1517 if (sc->ndis_block->nmb_checkforhangsecs == 0)
1518 sc->ndis_block->nmb_checkforhangsecs = 3;
1520 sc->ndis_stat_ch = timeout(ndis_tick, sc,
1521 hz * sc->ndis_block->nmb_checkforhangsecs);
1527 * Set media options.
1530 ndis_ifmedia_upd(ifp)
1533 struct ndis_softc *sc;
1537 if (NDIS_INITIALIZED(sc))
1544 * Report current media status.
1547 ndis_ifmedia_sts(ifp, ifmr)
1549 struct ifmediareq *ifmr;
1551 struct ndis_softc *sc;
1552 uint32_t media_info;
1553 ndis_media_state linkstate;
1556 ifmr->ifm_status = IFM_AVALID;
1557 ifmr->ifm_active = IFM_ETHER;
1560 if (!NDIS_INITIALIZED(sc))
1563 len = sizeof(linkstate);
1564 error = ndis_get_info(sc, OID_GEN_MEDIA_CONNECT_STATUS,
1565 (void *)&linkstate, &len);
1567 len = sizeof(media_info);
1568 error = ndis_get_info(sc, OID_GEN_LINK_SPEED,
1569 (void *)&media_info, &len);
1571 if (linkstate == nmc_connected)
1572 ifmr->ifm_status |= IFM_ACTIVE;
1574 switch(media_info) {
1576 ifmr->ifm_active |= IFM_10_T;
1579 ifmr->ifm_active |= IFM_100_TX;
1582 ifmr->ifm_active |= IFM_1000_T;
1585 device_printf(sc->ndis_dev, "unknown speed: %d\n", media_info);
1593 ndis_setstate_80211(sc)
1594 struct ndis_softc *sc;
1596 struct ieee80211com *ic;
1597 ndis_80211_ssid ssid;
1598 ndis_80211_config config;
1600 int i, rval = 0, len;
1605 ifp = &sc->arpcom.ac_if;
1607 if (!NDIS_INITIALIZED(sc))
1610 /* Set network infrastructure mode. */
1613 if (ic->ic_opmode == IEEE80211_M_IBSS)
1614 arg = NDIS_80211_NET_INFRA_IBSS;
1616 arg = NDIS_80211_NET_INFRA_BSS;
1618 rval = ndis_set_info(sc, OID_802_11_INFRASTRUCTURE_MODE, &arg, &len);
1621 device_printf (sc->ndis_dev, "set infra failed: %d\n", rval);
1625 #ifdef IEEE80211_F_PRIVACY
1626 if (ic->ic_flags & IEEE80211_F_PRIVACY) {
1628 if (ic->ic_wep_mode >= IEEE80211_WEP_ON) {
1630 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
1631 if (ic->ic_nw_keys[i].wk_keylen) {
1632 bzero((char *)&wep, sizeof(wep));
1633 wep.nw_keylen = ic->ic_nw_keys[i].wk_keylen;
1635 /* 5 and 13 are the only valid key lengths */
1636 if (ic->ic_nw_keys[i].wk_keylen < 5)
1638 else if (ic->ic_nw_keys[i].wk_keylen > 5 &&
1639 ic->ic_nw_keys[i].wk_keylen < 13)
1643 wep.nw_length = (sizeof(uint32_t) * 3)
1645 if (i == ic->ic_def_txkey)
1646 wep.nw_keyidx |= NDIS_80211_WEPKEY_TX;
1647 bcopy(ic->ic_nw_keys[i].wk_key,
1648 wep.nw_keydata, wep.nw_length);
1650 rval = ndis_set_info(sc,
1651 OID_802_11_ADD_WEP, &wep, &len);
1653 device_printf(sc->ndis_dev,
1654 "set wepkey failed: %d\n", rval);
1657 arg = NDIS_80211_WEPSTAT_ENABLED;
1659 rval = ndis_set_info(sc, OID_802_11_WEP_STATUS, &arg, &len);
1661 device_printf(sc->ndis_dev,
1662 "enable WEP failed: %d\n", rval);
1663 #ifndef IEEE80211_F_WEPON
1665 if (ic->ic_wep_mode != IEEE80211_WEP_8021X &&
1666 ic->ic_wep_mode != IEEE80211_WEP_ON)
1667 arg = NDIS_80211_PRIVFILT_ACCEPTALL;
1671 arg = NDIS_80211_PRIVFILT_8021XWEP;
1673 rval = ndis_set_info(sc, OID_802_11_PRIVACY_FILTER, &arg, &len);
1674 #ifdef IEEE80211_WEP_8021X /*IEEE80211_F_WEPON*/
1675 /* Accept that we only have "shared" and 802.1x modes. */
1677 if (arg == NDIS_80211_PRIVFILT_ACCEPTALL)
1678 ic->ic_wep_mode = IEEE80211_WEP_MIXED;
1680 ic->ic_wep_mode = IEEE80211_WEP_8021X;
1683 arg = NDIS_80211_AUTHMODE_OPEN;
1685 arg = NDIS_80211_WEPSTAT_DISABLED;
1687 ndis_set_info(sc, OID_802_11_WEP_STATUS, &arg, &len);
1688 arg = NDIS_80211_AUTHMODE_OPEN;
1692 rval = ndis_set_info(sc, OID_802_11_AUTHENTICATION_MODE, &arg, &len);
1696 device_printf (sc->ndis_dev, "set auth failed: %d\n", rval);
1700 /* Set network type. */
1704 switch (ic->ic_curmode) {
1705 case IEEE80211_MODE_11A:
1706 arg = NDIS_80211_NETTYPE_11OFDM5;
1708 case IEEE80211_MODE_11B:
1709 arg = NDIS_80211_NETTYPE_11DS;
1711 case IEEE80211_MODE_11G:
1712 arg = NDIS_80211_NETTYPE_11OFDM24;
1715 device_printf(sc->ndis_dev, "unknown mode: %d\n",
1721 rval = ndis_set_info(sc, OID_802_11_NETWORK_TYPE_IN_USE,
1724 device_printf (sc->ndis_dev,
1725 "set nettype failed: %d\n", rval);
1729 len = sizeof(config);
1730 bzero((char *)&config, len);
1731 config.nc_length = len;
1732 config.nc_fhconfig.ncf_length = sizeof(ndis_80211_config_fh);
1733 rval = ndis_get_info(sc, OID_802_11_CONFIGURATION, &config, &len);
1736 * Some drivers expect us to initialize these values, so
1737 * provide some defaults.
1739 if (config.nc_beaconperiod == 0)
1740 config.nc_beaconperiod = 100;
1741 if (config.nc_atimwin == 0)
1742 config.nc_atimwin = 100;
1743 if (config.nc_fhconfig.ncf_dwelltime == 0)
1744 config.nc_fhconfig.ncf_dwelltime = 200;
1746 if (rval == 0 && ic->ic_ibss_chan != IEEE80211_CHAN_ANYC) {
1749 chan = ieee80211_chan2ieee(ic, ic->ic_ibss_chan);
1750 chanflag = config.nc_dsconfig > 2500000 ? IEEE80211_CHAN_2GHZ :
1751 IEEE80211_CHAN_5GHZ;
1752 if (chan != ieee80211_mhz2ieee(config.nc_dsconfig / 1000, 0)) {
1753 config.nc_dsconfig =
1754 ic->ic_ibss_chan->ic_freq * 1000;
1755 ic->ic_bss->ni_chan = ic->ic_ibss_chan;
1756 len = sizeof(config);
1757 config.nc_length = len;
1758 config.nc_fhconfig.ncf_length =
1759 sizeof(ndis_80211_config_fh);
1760 rval = ndis_set_info(sc, OID_802_11_CONFIGURATION,
1763 device_printf(sc->ndis_dev, "couldn't change "
1764 "DS config to %ukHz: %d\n",
1765 config.nc_dsconfig, rval);
1768 device_printf(sc->ndis_dev, "couldn't retrieve "
1769 "channel info: %d\n", rval);
1771 /* Set SSID -- always do this last. */
1774 bzero((char *)&ssid, len);
1775 ssid.ns_ssidlen = ic->ic_des_esslen;
1776 if (ssid.ns_ssidlen == 0) {
1777 ssid.ns_ssidlen = 1;
1779 bcopy(ic->ic_des_essid, ssid.ns_ssid, ssid.ns_ssidlen);
1780 rval = ndis_set_info(sc, OID_802_11_SSID, &ssid, &len);
1783 device_printf (sc->ndis_dev, "set ssid failed: %d\n", rval);
1789 ndis_media_status(struct ifnet *ifp, struct ifmediareq *imr)
1791 struct ieee80211com *ic = &((struct ndis_softc *)ifp->if_softc)->ic;
1792 struct ieee80211_node *ni = NULL;
1794 imr->ifm_status = IFM_AVALID;
1795 imr->ifm_active = IFM_IEEE80211;
1796 if (ic->ic_state == IEEE80211_S_RUN)
1797 imr->ifm_status |= IFM_ACTIVE;
1798 imr->ifm_active |= IFM_AUTO;
1799 switch (ic->ic_opmode) {
1800 case IEEE80211_M_STA:
1802 /* calculate rate subtype */
1803 imr->ifm_active |= ieee80211_rate2media(ic,
1804 ni->ni_rates.rs_rates[ni->ni_txrate], ic->ic_curmode);
1806 case IEEE80211_M_IBSS:
1808 /* calculate rate subtype */
1809 imr->ifm_active |= ieee80211_rate2media(ic,
1810 ni->ni_rates.rs_rates[ni->ni_txrate], ic->ic_curmode);
1811 imr->ifm_active |= IFM_IEEE80211_ADHOC;
1813 case IEEE80211_M_AHDEMO:
1814 /* should not come here */
1816 case IEEE80211_M_HOSTAP:
1817 imr->ifm_active |= IFM_IEEE80211_HOSTAP;
1819 case IEEE80211_M_MONITOR:
1820 imr->ifm_active |= IFM_IEEE80211_MONITOR;
1823 switch (ic->ic_curmode) {
1824 case IEEE80211_MODE_11A:
1825 imr->ifm_active |= IFM_MAKEMODE(IFM_IEEE80211_11A);
1827 case IEEE80211_MODE_11B:
1828 imr->ifm_active |= IFM_MAKEMODE(IFM_IEEE80211_11B);
1830 case IEEE80211_MODE_11G:
1831 imr->ifm_active |= IFM_MAKEMODE(IFM_IEEE80211_11G);
1833 case IEEE80211_MODE_TURBO_A:
1834 imr->ifm_active |= IFM_MAKEMODE(IFM_IEEE80211_11A)
1835 | IFM_IEEE80211_TURBO;
1841 ndis_get_assoc(sc, assoc)
1842 struct ndis_softc *sc;
1843 ndis_wlan_bssid_ex **assoc;
1845 ndis_80211_bssid_list_ex *bl;
1846 ndis_wlan_bssid_ex *bs;
1847 ndis_80211_macaddr bssid;
1853 len = sizeof(bssid);
1854 error = ndis_get_info(sc, OID_802_11_BSSID, &bssid, &len);
1856 device_printf(sc->ndis_dev, "failed to get bssid\n");
1860 error = ndis_get_info(sc, OID_802_11_BSSID_LIST, NULL, &len);
1861 if (error != ENOSPC) {
1862 device_printf(sc->ndis_dev, "bssid_list failed\n");
1866 bl = malloc(len, M_TEMP, M_NOWAIT|M_ZERO);
1867 error = ndis_get_info(sc, OID_802_11_BSSID_LIST, bl, &len);
1870 device_printf(sc->ndis_dev, "bssid_list failed\n");
1874 bs = (ndis_wlan_bssid_ex *)&bl->nblx_bssid[0];
1875 for (i = 0; i < bl->nblx_items; i++) {
1876 if (bcmp(bs->nwbx_macaddr, bssid, sizeof(bssid)) == 0) {
1877 *assoc = malloc(bs->nwbx_len, M_TEMP, M_NOWAIT);
1878 if (*assoc == NULL) {
1882 bcopy((char *)bs, (char *)*assoc, bs->nwbx_len);
1886 bs = (ndis_wlan_bssid_ex *)((char *)bs + bs->nwbx_len);
1894 ndis_getstate_80211(sc)
1895 struct ndis_softc *sc;
1897 struct ieee80211com *ic;
1898 ndis_80211_ssid ssid;
1899 ndis_80211_config config;
1900 ndis_wlan_bssid_ex *bs;
1901 int rval, len, i = 0;
1906 ifp = &sc->arpcom.ac_if;
1908 if (!NDIS_INITIALIZED(sc))
1912 ic->ic_state = IEEE80211_S_RUN;
1914 ic->ic_state = IEEE80211_S_ASSOC;
1918 * If we're associated, retrieve info on the current bssid.
1920 if ((rval = ndis_get_assoc(sc, &bs)) == 0) {
1921 switch(bs->nwbx_nettype) {
1922 case NDIS_80211_NETTYPE_11FH:
1923 case NDIS_80211_NETTYPE_11DS:
1924 ic->ic_curmode = IEEE80211_MODE_11B;
1926 case NDIS_80211_NETTYPE_11OFDM5:
1927 ic->ic_curmode = IEEE80211_MODE_11A;
1929 case NDIS_80211_NETTYPE_11OFDM24:
1930 ic->ic_curmode = IEEE80211_MODE_11G;
1933 device_printf(sc->ndis_dev,
1934 "unknown nettype %d\n", arg);
1937 IEEE80211_ADDR_COPY(ic->ic_bss->ni_bssid, bs->nwbx_macaddr);
1943 bzero((char *)&ssid, len);
1944 rval = ndis_get_info(sc, OID_802_11_SSID, &ssid, &len);
1947 device_printf (sc->ndis_dev, "get ssid failed: %d\n", rval);
1948 bcopy(ssid.ns_ssid, ic->ic_bss->ni_essid, ssid.ns_ssidlen);
1949 ic->ic_bss->ni_esslen = ssid.ns_ssidlen;
1952 rval = ndis_get_info(sc, OID_GEN_LINK_SPEED, &arg, &len);
1954 device_printf (sc->ndis_dev, "get link speed failed: %d\n",
1957 if (ic->ic_modecaps & (1<<IEEE80211_MODE_11B)) {
1958 ic->ic_bss->ni_rates = ic->ic_sup_rates[IEEE80211_MODE_11B];
1959 for (i = 0; i < ic->ic_bss->ni_rates.rs_nrates; i++) {
1960 if ((ic->ic_bss->ni_rates.rs_rates[i] &
1961 IEEE80211_RATE_VAL) == arg / 5000)
1966 if (i == ic->ic_bss->ni_rates.rs_nrates &&
1967 ic->ic_modecaps & (1<<IEEE80211_MODE_11G)) {
1968 ic->ic_bss->ni_rates = ic->ic_sup_rates[IEEE80211_MODE_11G];
1969 for (i = 0; i < ic->ic_bss->ni_rates.rs_nrates; i++) {
1970 if ((ic->ic_bss->ni_rates.rs_rates[i] &
1971 IEEE80211_RATE_VAL) == arg / 5000)
1976 if (i == ic->ic_bss->ni_rates.rs_nrates)
1977 device_printf(sc->ndis_dev, "no matching rate for: %d\n",
1980 ic->ic_bss->ni_txrate = i;
1982 if (ic->ic_caps & IEEE80211_C_PMGT) {
1984 rval = ndis_get_info(sc, OID_802_11_POWER_MODE, &arg, &len);
1987 device_printf(sc->ndis_dev,
1988 "get power mode failed: %d\n", rval);
1989 if (arg == NDIS_80211_POWERMODE_CAM)
1990 ic->ic_flags &= ~IEEE80211_F_PMGTON;
1992 ic->ic_flags |= IEEE80211_F_PMGTON;
1995 len = sizeof(config);
1996 bzero((char *)&config, len);
1997 config.nc_length = len;
1998 config.nc_fhconfig.ncf_length = sizeof(ndis_80211_config_fh);
1999 rval = ndis_get_info(sc, OID_802_11_CONFIGURATION, &config, &len);
2003 chan = ieee80211_mhz2ieee(config.nc_dsconfig / 1000, 0);
2004 if (chan < 0 || chan >= IEEE80211_CHAN_MAX) {
2005 if (ifp->if_flags & IFF_DEBUG)
2006 device_printf(sc->ndis_dev, "current channel "
2007 "(%uMHz) out of bounds\n",
2008 config.nc_dsconfig / 1000);
2009 ic->ic_bss->ni_chan = &ic->ic_channels[1];
2011 ic->ic_bss->ni_chan = &ic->ic_channels[chan];
2013 device_printf(sc->ndis_dev, "couldn't retrieve "
2014 "channel info: %d\n", rval);
2018 rval = ndis_get_info(sc, OID_802_11_WEP_STATUS, &arg, &len);
2021 device_printf (sc->ndis_dev,
2022 "get wep status failed: %d\n", rval);
2024 if (arg == NDIS_80211_WEPSTAT_ENABLED)
2025 ic->ic_flags |= IEEE80211_F_WEPON;
2027 ic->ic_flags &= ~IEEE80211_F_WEPON;
2033 ndis_ioctl(ifp, command, data)
2038 struct ndis_softc *sc = ifp->if_softc;
2039 struct ifreq *ifr = (struct ifreq *) data;
2046 if (ifp->if_flags & IFF_UP) {
2047 if (ifp->if_flags & IFF_RUNNING &&
2048 ifp->if_flags & IFF_PROMISC &&
2049 !(sc->ndis_if_flags & IFF_PROMISC)) {
2051 NDIS_PACKET_TYPE_PROMISCUOUS;
2052 i = sizeof(sc->ndis_filter);
2053 error = ndis_set_info(sc,
2054 OID_GEN_CURRENT_PACKET_FILTER,
2055 &sc->ndis_filter, &i);
2056 } else if (ifp->if_flags & IFF_RUNNING &&
2057 !(ifp->if_flags & IFF_PROMISC) &&
2058 sc->ndis_if_flags & IFF_PROMISC) {
2060 ~NDIS_PACKET_TYPE_PROMISCUOUS;
2061 i = sizeof(sc->ndis_filter);
2062 error = ndis_set_info(sc,
2063 OID_GEN_CURRENT_PACKET_FILTER,
2064 &sc->ndis_filter, &i);
2068 if (ifp->if_flags & IFF_RUNNING)
2071 sc->ndis_if_flags = ifp->if_flags;
2081 if (sc->ndis_80211) {
2082 error = ieee80211_ioctl(&sc->ic, command, data);
2083 if (error == ENETRESET) {
2084 ndis_setstate_80211(sc);
2089 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
2092 ifp->if_capenable = ifr->ifr_reqcap;
2093 if (ifp->if_capenable & IFCAP_TXCSUM)
2094 ifp->if_hwassist = sc->ndis_hwassist;
2096 ifp->if_hwassist = 0;
2097 ndis_set_offload(sc);
2101 error = ndis_80211_ioctl_get(ifp, command, data);
2107 error = ndis_80211_ioctl_set(ifp, command, data);
2111 case SIOCGIFGENERIC:
2112 case SIOCSIFGENERIC:
2113 if (sc->ndis_80211 && NDIS_INITIALIZED(sc)) {
2114 if (command == SIOCGIFGENERIC)
2115 error = ndis_wi_ioctl_get(ifp, command, data);
2117 error = ndis_wi_ioctl_set(ifp, command, data);
2120 if (error != ENOTTY)
2124 if (sc->ndis_80211) {
2125 error = ieee80211_ioctl(&sc->ic, command, data);
2126 if (error == ENETRESET) {
2127 ndis_setstate_80211(sc);
2131 error = ether_ioctl(ifp, command, data);
2136 /*NDIS_UNLOCK(sc);*/
2142 ndis_wi_ioctl_get(ifp, command, data)
2149 struct ndis_softc *sc;
2150 ndis_80211_bssid_list_ex *bl;
2151 ndis_wlan_bssid_ex *wb;
2152 struct wi_apinfo *api;
2153 int error, i, j, len, maxaps;
2156 ifr = (struct ifreq *)data;
2157 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
2161 switch (wreq.wi_type) {
2162 case WI_RID_READ_APS:
2164 error = ndis_set_info(sc, OID_802_11_BSSID_LIST_SCAN,
2167 tsleep(&error, PPAUSE|PCATCH, "ssidscan", hz * 2);
2169 error = ndis_get_info(sc, OID_802_11_BSSID_LIST, NULL, &len);
2170 if (error != ENOSPC)
2172 bl = malloc(len, M_DEVBUF, M_WAITOK|M_ZERO);
2173 error = ndis_get_info(sc, OID_802_11_BSSID_LIST, bl, &len);
2178 maxaps = (2 * wreq.wi_len - sizeof(int)) / sizeof(*api);
2179 maxaps = MIN(maxaps, bl->nblx_items);
2180 wreq.wi_len = (maxaps * sizeof(*api) + sizeof(int)) / 2;
2181 *(int *)&wreq.wi_val = maxaps;
2182 api = (struct wi_apinfo *)&((int *)&wreq.wi_val)[1];
2183 wb = bl->nblx_bssid;
2185 bzero(api, sizeof(*api));
2186 bcopy(&wb->nwbx_macaddr, &api->bssid,
2187 sizeof(api->bssid));
2188 api->namelen = wb->nwbx_ssid.ns_ssidlen;
2189 bcopy(&wb->nwbx_ssid.ns_ssid, &api->name, api->namelen);
2190 if (wb->nwbx_privacy)
2191 api->capinfo |= IEEE80211_CAPINFO_PRIVACY;
2192 /* XXX Where can we get noise information? */
2193 api->signal = wb->nwbx_rssi + 149; /* XXX */
2194 api->quality = api->signal;
2196 ieee80211_mhz2ieee(wb->nwbx_config.nc_dsconfig /
2198 /* In "auto" infrastructure mode, this is useless. */
2199 if (wb->nwbx_netinfra == NDIS_80211_NET_INFRA_IBSS)
2200 api->capinfo |= IEEE80211_CAPINFO_IBSS;
2201 if (wb->nwbx_len > sizeof(ndis_wlan_bssid)) {
2202 j = sizeof(ndis_80211_rates_ex);
2203 /* handle other extended things */
2205 j = sizeof(ndis_80211_rates);
2206 for (i = api->rate = 0; i < j; i++)
2207 api->rate = MAX(api->rate, 5 *
2208 (wb->nwbx_supportedrates[i] & 0x7f));
2210 wb = (ndis_wlan_bssid_ex *)((char *)wb + wb->nwbx_len);
2213 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
2223 ndis_wi_ioctl_set(ifp, command, data)
2230 struct ndis_softc *sc;
2234 error = suser(curthread);
2239 ifr = (struct ifreq *)data;
2240 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
2244 switch (wreq.wi_type) {
2245 case WI_RID_SCAN_APS:
2246 case WI_RID_SCAN_REQ: /* arguments ignored */
2249 error = ndis_set_info(sc, OID_802_11_BSSID_LIST_SCAN, &foo,
2260 ndis_80211_ioctl_get(struct ifnet *ifp, u_long command, caddr_t data)
2262 struct ndis_softc *sc;
2263 struct ieee80211req *ireq;
2264 ndis_80211_bssid_list_ex *bl;
2265 ndis_wlan_bssid_ex *wb;
2266 struct ieee80211req_scan_result *sr, *bsr;
2267 int error, len, i, j;
2271 ireq = (struct ieee80211req *) data;
2273 switch (ireq->i_type) {
2274 case IEEE80211_IOC_SCAN_RESULTS:
2276 error = ndis_get_info(sc, OID_802_11_BSSID_LIST, NULL, &len);
2277 if (error != ENOSPC)
2279 bl = malloc(len, M_DEVBUF, M_WAITOK | M_ZERO);
2280 error = ndis_get_info(sc, OID_802_11_BSSID_LIST, bl, &len);
2285 sr = bsr = malloc(ireq->i_len, M_DEVBUF, M_WAITOK | M_ZERO);
2286 wb = bl->nblx_bssid;
2288 for (i = 0; i < bl->nblx_items; i++) {
2290 * Check if we have enough space left for this ap
2292 j = roundup(sizeof(*sr) + wb->nwbx_ssid.ns_ssidlen
2293 + wb->nwbx_ielen - sizeof(struct ndis_80211_fixed_ies),
2295 if (len + j > ireq->i_len)
2297 bcopy(&wb->nwbx_macaddr, &sr->isr_bssid, sizeof(sr->isr_bssid));
2298 if (wb->nwbx_privacy)
2299 sr->isr_capinfo |= IEEE80211_CAPINFO_PRIVACY;
2300 sr->isr_rssi = wb->nwbx_rssi + 200;
2301 sr->isr_freq = wb->nwbx_config.nc_dsconfig / 1000;
2302 sr->isr_intval = wb->nwbx_config.nc_beaconperiod;
2303 switch (wb->nwbx_netinfra) {
2304 case NDIS_80211_NET_INFRA_IBSS:
2305 sr->isr_capinfo |= IEEE80211_CAPINFO_IBSS;
2307 case NDIS_80211_NET_INFRA_BSS:
2308 sr->isr_capinfo |= IEEE80211_CAPINFO_ESS;
2311 for (j = 0; j < sizeof(sr->isr_rates); j++) {
2312 /* XXX - check units */
2313 if (wb->nwbx_supportedrates[j] == 0)
2315 sr->isr_rates[j] = wb->nwbx_supportedrates[j] & 0x7f;
2318 sr->isr_ssid_len = wb->nwbx_ssid.ns_ssidlen;
2319 cp = (char *)sr + sizeof(*sr);
2320 bcopy(&wb->nwbx_ssid.ns_ssid, cp, sr->isr_ssid_len);
2321 cp += sr->isr_ssid_len;
2322 sr->isr_ie_len = wb->nwbx_ielen
2323 - sizeof(struct ndis_80211_fixed_ies);
2324 bcopy((char *)wb->nwbx_ies + sizeof(struct ndis_80211_fixed_ies),
2325 cp, sr->isr_ie_len);
2326 sr->isr_len = roundup(sizeof(*sr) + sr->isr_ssid_len
2327 + sr->isr_ie_len, sizeof(uint32_t));
2329 sr = (struct ieee80211req_scan_result *)((char *)sr + sr->isr_len);
2330 wb = (ndis_wlan_bssid_ex *)((char *)wb + wb->nwbx_len);
2333 error = copyout(bsr, ireq->i_data, len);
2335 free(bsr, M_DEVBUF);
2338 error = ieee80211_ioctl(&sc->ic, command, data);
2345 ndis_80211_ioctl_set(struct ifnet *ifp, u_long command, caddr_t data)
2347 struct ndis_softc *sc;
2348 struct ieee80211req *ireq;
2352 ireq = (struct ieee80211req *) data;
2354 switch (ireq->i_type) {
2355 case IEEE80211_IOC_SCAN_REQ:
2357 error = ndis_set_info(sc, OID_802_11_BSSID_LIST_SCAN, NULL, &len);
2358 tsleep(&error, PPAUSE|PCATCH, "ssidscan", hz * 2);
2359 rt_ieee80211msg(ifp, RTM_IEEE80211_SCAN, NULL, 0);
2362 error = ieee80211_ioctl(&sc->ic, command, data);
2363 if (error == ENETRESET) {
2364 ndis_setstate_80211(sc);
2376 struct ndis_softc *sc;
2382 device_printf(sc->ndis_dev, "watchdog timeout\n");
2385 ndis_sched((void(*)(void *))ndis_reset_nic, sc, NDIS_TASKQUEUE);
2386 ndis_sched(ndis_starttask, ifp, NDIS_TASKQUEUE);
2392 * Stop the adapter and free any mbufs allocated to the
2397 struct ndis_softc *sc;
2401 ifp = &sc->arpcom.ac_if;
2402 untimeout(ndis_tick, sc, sc->ndis_stat_ch);
2409 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
2416 * Stop all chip I/O so that the kernel's probe routines don't
2417 * get confused by errant DMAs when rebooting.
2423 struct ndis_softc *sc;
2425 sc = device_get_softc(dev);
2426 ndis_shutdown_nic(sc);