if_ndis_usb.c revision 142408
1/*-
2 * Copyright (c) 2005
3 *      Bill Paul <wpaul@ee.columbia.edu>.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
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.
19 *
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.
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/dev/if_ndis/if_ndis_usb.c 142408 2005-02-24 22:54:15Z wpaul $");
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sockio.h>
39#include <sys/mbuf.h>
40#include <sys/malloc.h>
41#include <sys/kernel.h>
42#include <sys/socket.h>
43#include <sys/sysctl.h>
44
45#include <net/if.h>
46#include <net/if_arp.h>
47#include <net/ethernet.h>
48#include <net/if_dl.h>
49#include <net/if_media.h>
50
51#include <net/bpf.h>
52
53#include <sys/bus.h>
54#include <machine/bus.h>
55#include <dev/usb/usb.h>
56#include <dev/usb/usbdi.h>
57#include <dev/usb/usbdi_util.h>
58#include <dev/usb/usbdivar.h>
59#include <dev/usb/usbdevs.h>
60#include <dev/usb/usb_ethersubr.h>
61
62#include <net80211/ieee80211_var.h>
63
64#include <compat/ndis/pe_var.h>
65#include <compat/ndis/resource_var.h>
66#include <compat/ndis/ntoskrnl_var.h>
67#include <compat/ndis/ndis_var.h>
68#include <compat/ndis/cfg_var.h>
69#include <dev/if_ndis/if_ndisvar.h>
70
71MODULE_DEPEND(ndis, usb, 1, 1, 1);
72MODULE_DEPEND(ndis, ether, 1, 1, 1);
73MODULE_DEPEND(ndis, wlan, 1, 1, 1);
74MODULE_DEPEND(ndis, ndisapi, 1, 1, 1);
75
76#include "ndis_driver_data.h"
77
78#ifdef NDIS_USB_DEV_TABLE
79
80Static int ndisusb_match	(device_ptr_t);
81Static int ndisusb_attach	(device_ptr_t);
82Static struct resource_list *ndis_get_resource_list
83				(device_t, device_t);
84
85extern int ndisdrv_modevent     (module_t, int, void *);
86extern int ndis_attach          (device_t);
87extern int ndis_shutdown        (device_t);
88extern int ndis_detach          (device_t);
89extern int ndis_suspend         (device_t);
90extern int ndis_resume          (device_t);
91
92extern unsigned char drv_data[];
93
94Static device_method_t ndis_methods[] = {
95        /* Device interface */
96	DEVMETHOD(device_probe,		ndisusb_match),
97	DEVMETHOD(device_attach,	ndisusb_attach),
98	DEVMETHOD(device_detach,	ndis_detach),
99	DEVMETHOD(device_shutdown,	ndis_shutdown),
100
101        /* bus interface */
102	DEVMETHOD(bus_print_child,	bus_generic_print_child),
103	DEVMETHOD(bus_driver_added,	bus_generic_driver_added),
104	DEVMETHOD(bus_get_resource_list, ndis_get_resource_list),
105
106	{ 0, 0 }
107};
108
109Static driver_t ndis_driver = {
110#ifdef NDIS_DEVNAME
111	NDIS_DEVNAME,
112#else
113	"ndis",
114#endif
115	ndis_methods,
116	sizeof(struct ndis_softc)
117};
118
119Static devclass_t ndis_devclass;
120
121#ifdef NDIS_MODNAME
122#define NDIS_MODNAME_OVERRIDE_USB(x)
123	DRIVER_MODULE(x, usb, ndis_driver, ndis_devclass, ndisdrv_modevent, 0)
124NDIS_MODNAME_OVERRIDE_USB(NDIS_MODNAME);
125#else
126DRIVER_MODULE(ndis, uhub, ndis_driver, ndis_devclass, ndisdrv_modevent, 0);
127#endif
128
129USB_MATCH(ndisusb)
130{
131	USB_MATCH_START(ndisusb, uaa);
132
133	if (windrv_lookup(NULL, "USB Bus") == NULL)
134		return(UMATCH_NONE);
135
136	if (uaa->iface != NULL)
137		return(UMATCH_NONE);
138
139	return(UMATCH_NONE);
140}
141
142USB_ATTACH(ndisusb)
143{
144	USB_ATTACH_START(ndisusb, dummy, uaa);
145	struct ndis_softc	*sc;
146	driver_object		*drv;
147
148	sc = (struct ndis_softc *)dummy;
149
150	sc->ndis_dev = self;
151
152	/* Create PDO for this device instance */
153
154	drv = windrv_lookup(NULL, "USB Bus");
155	windrv_create_pdo(drv, self);
156
157	if (ndis_attach(self) != 0)
158		USB_ATTACH_ERROR_RETURN;
159
160	USB_ATTACH_SUCCESS_RETURN;
161}
162
163static struct resource_list *
164ndis_get_resource_list(dev, child)
165	device_t		dev;
166	device_t		child;
167{
168	struct ndis_softc       *sc;
169
170	sc = device_get_softc(dev);
171	return (BUS_GET_RESOURCE_LIST(device_get_parent(sc->ndis_dev), dev));
172}
173
174#endif /* NDIS_USB_DEV_TABLE */
175