umodem.c revision 1.5 1 /* $NetBSD: umodem.c,v 1.5 1999/01/08 11:58:25 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss (at) carlstedt.se) at
9 * Carlstedt Research & Technology.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/malloc.h>
44 #if defined(__NetBSD__)
45 #include <sys/ioctl.h>
46 #elif defined(__FreeBSD__)
47 #include <sys/module.h>
48 #include <sys/bus.h>
49 #include <sys/ioccom.h>
50 #include <sys/conf.h>
51 #endif
52 #include <sys/tty.h>
53 #include <sys/file.h>
54 #include <sys/select.h>
55 #include <sys/proc.h>
56 #include <sys/vnode.h>
57 #include <sys/device.h>
58 #include <sys/poll.h>
59
60 #include <dev/usb/usb.h>
61 #include <dev/usb/usbcdc.h>
62
63 #include <dev/usb/usbdi.h>
64 #include <dev/usb/usbdi_util.h>
65 #include <dev/usb/usbdevs.h>
66 #include <dev/usb/usb_quirks.h>
67
68 #ifdef USB_DEBUG
69 #define DPRINTF(x) if (umodemdebug) printf x
70 #define DPRINTFN(n,x) if (umodemdebug>(n)) printf x
71 int umodemdebug = 0;
72 #else
73 #define DPRINTF(x)
74 #define DPRINTFN(n,x)
75 #endif
76
77 struct umodem_softc {
78 bdevice sc_dev; /* base device */
79 usbd_interface_handle sc_ctl; /* control interface */
80 usbd_interface_handle sc_data; /* data interface */
81 uByte cmCaps;
82 uByte acmCaps;
83 };
84
85 void umodem_intr __P((usbd_request_handle, usbd_private_handle, usbd_status));
86 void umodem_disco __P((void *));
87
88 USB_DECLARE_DRIVER(umodem);
89
90 USB_MATCH(umodem)
91 {
92 USB_MATCH_START(umodem, uaa);
93
94 usb_interface_descriptor_t *id;
95
96 if (!uaa->iface)
97 return (UMATCH_NONE);
98 id = usbd_get_interface_descriptor(uaa->iface);
99 if (!id ||
100 id->bInterfaceClass != UCLASS_CDC ||
101 id->bInterfaceSubClass != USUBCLASS_ABSTRACT_CONTROL_MODEL ||
102 id->bInterfaceProtocol != UPROTO_CDC_AT)
103 return (UMATCH_NONE);
104 return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
105 }
106
107 USB_ATTACH(umodem)
108 {
109 USB_ATTACH_START(umodem, sc, uaa);
110 usbd_interface_handle iface = uaa->iface;
111 usb_interface_descriptor_t *id;
112 char devinfo[1024];
113
114 sc->sc_ctl = iface;
115 id = usbd_get_interface_descriptor(iface);
116 usbd_devinfo(uaa->device, 0, devinfo);
117 USB_ATTACH_SETUP;
118 printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
119 devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
120
121 USB_ATTACH_SUCCESS_RETURN;
122 }
123
124 #if defined(__FreeBSD__)
125 static int
126 umodem_detach(device_t self)
127 {
128 struct umodem_softc *sc = device_get_softc(self);
129 char *devinfo = (char *) device_get_desc(self);
130
131 if (devinfo) {
132 device_set_desc(self, NULL);
133 free(devinfo, M_USB);
134 }
135
136 return 0;
137 }
138 #endif
139
140 #if defined(__FreeBSD__)
141 DRIVER_MODULE(umodem, usb, umodem_driver, umodem_devclass, usbd_driver_load,0);
142 #endif
143
144