umodem.c revision 1.55.10.1 1 /* $NetBSD: umodem.c,v 1.55.10.1 2007/06/18 13:56:52 itohy 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 (lennart (at) augustsson.net) 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 /*
41 * Comm Class spec: http://www.usb.org/developers/devclass_docs/usbccs10.pdf
42 * http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
43 */
44
45 /*
46 * TODO:
47 * - Add error recovery in various places; the big problem is what
48 * to do in a callback if there is an error.
49 * - Implement a Call Device for modems without multiplexed commands.
50 *
51 */
52
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: umodem.c,v 1.55.10.1 2007/06/18 13:56:52 itohy Exp $");
55
56 #include <sys/param.h>
57 #include <sys/systm.h>
58 #include <sys/kernel.h>
59 #include <sys/ioctl.h>
60 #include <sys/conf.h>
61 #include <sys/tty.h>
62 #include <sys/file.h>
63 #include <sys/select.h>
64 #include <sys/proc.h>
65 #include <sys/vnode.h>
66 #include <sys/device.h>
67 #include <sys/poll.h>
68
69 #include <dev/usb/usb.h>
70 #include <dev/usb/usbcdc.h>
71
72 #include <dev/usb/usbdi.h>
73 #include <dev/usb/usbdi_util.h>
74 #include <dev/usb/usbdevs.h>
75 #include <dev/usb/usb_quirks.h>
76
77 #include <dev/usb/ucomvar.h>
78 #include <dev/usb/umodemvar.h>
79
80 Static struct ucom_methods umodem_methods = {
81 umodem_get_status,
82 umodem_set,
83 umodem_param,
84 umodem_ioctl,
85 umodem_open,
86 umodem_close,
87 NULL,
88 NULL,
89 };
90
91 USB_DECLARE_DRIVER(umodem);
92
93 USB_MATCH(umodem)
94 {
95 #ifndef USB_USE_IFATTACH
96 USB_MATCH_START(umodem, uaa);
97 #else
98 USB_IFMATCH_START(umodem, uaa);
99 #endif /* USB_USE_IFATTACH */
100 usb_interface_descriptor_t *id;
101 int cm, acm;
102
103 #ifndef USB_USE_IFATTACH
104 if (uaa->iface == NULL)
105 #else
106 if (uaa->class != UICLASS_CDC ||
107 uaa->subclass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
108 uaa->proto != UIPROTO_CDC_AT)
109 #endif /* USB_USE_IFATTACH */
110 return (UMATCH_NONE);
111
112 id = usbd_get_interface_descriptor(uaa->iface);
113 #ifndef USB_USE_IFATTACH
114 if (id == NULL ||
115 id->bInterfaceClass != UICLASS_CDC ||
116 id->bInterfaceSubClass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
117 id->bInterfaceProtocol != UIPROTO_CDC_AT)
118 return (UMATCH_NONE);
119 #endif /* USB_USE_IFATTACH */
120
121 if (umodem_get_caps(uaa->device, &cm, &acm, id) == -1)
122 return (UMATCH_NONE);
123
124 return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
125 }
126
127 USB_ATTACH(umodem)
128 {
129 #ifndef USB_USE_IFATTACH
130 USB_ATTACH_START(umodem, sc, uaa);
131 #else
132 USB_IFATTACH_START(umodem, sc, uaa);
133 #endif /* USB_USE_IFATTACH */
134 struct ucom_attach_args uca;
135
136 uca.portno = UCOM_UNK_PORTNO;
137 uca.methods = &umodem_methods;
138 uca.info = NULL;
139
140 if (umodem_common_attach(self, sc, uaa, &uca))
141 USB_ATTACH_ERROR_RETURN;
142 USB_ATTACH_SUCCESS_RETURN;
143 }
144
145 #ifdef __strong_alias
146 __strong_alias(umodem_activate,umodem_common_activate)
147 #else
148 int
149 umodem_activate(device_ptr_t self, enum devact act)
150 {
151 struct umodem_softc *sc = (struct umodem_softc *)self;
152
153 return umodem_common_activate(sc, act);
154 }
155 #endif
156
157 USB_DETACH(umodem)
158 {
159 USB_DETACH_START(umodem, sc);
160 #ifdef __FreeBSD__
161 int flags = 0;
162 #endif
163
164 return umodem_common_detach(sc, flags);
165 }
166