umodem.c revision 1.51 1 /* $NetBSD: umodem.c,v 1.51 2005/04/15 14:14:09 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.51 2005/04/15 14:14:09 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/usbdevs.h>
78 #include <dev/usb/ucomvar.h>
79 #include <dev/usb/umodemvar.h>
80
81 #ifdef UMODEM_DEBUG
82 #define DPRINTFN(n, x) if (umodemdebug > (n)) logprintf x
83 int umodemdebug = 0;
84 #else
85 #define DPRINTFN(n, x)
86 #endif
87 #define DPRINTF(x) DPRINTFN(0, x)
88
89 Static struct ucom_methods umodem_methods = {
90 umodem_get_status,
91 umodem_set,
92 umodem_param,
93 umodem_ioctl,
94 umodem_open,
95 umodem_close,
96 NULL,
97 NULL,
98 };
99
100 USB_DECLARE_DRIVER(umodem);
101
102 USB_MATCH(umodem)
103 {
104 USB_MATCH_START(umodem, uaa);
105 usb_interface_descriptor_t *id;
106 int cm, acm;
107
108 if (uaa->iface == NULL)
109 return (UMATCH_NONE);
110
111 id = usbd_get_interface_descriptor(uaa->iface);
112 if (id == NULL ||
113 id->bInterfaceClass != UICLASS_CDC ||
114 id->bInterfaceSubClass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
115 id->bInterfaceProtocol != UIPROTO_CDC_AT)
116 return (UMATCH_NONE);
117
118 umodem_get_caps(uaa->device, &cm, &acm, id);
119 if (!(cm & USB_CDC_CM_DOES_CM) ||
120 !(cm & USB_CDC_CM_OVER_DATA) ||
121 !(acm & USB_CDC_ACM_HAS_LINE))
122 return (UMATCH_NONE);
123
124 return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
125 }
126
127 USB_ATTACH(umodem)
128 {
129 USB_ATTACH_START(umodem, sc, uaa);
130 struct ucom_attach_args uca;
131
132 uca.portno = UCOM_UNK_PORTNO;
133 uca.methods = &umodem_methods;
134 uca.info = NULL;
135
136 if (umodem_common_attach(self, sc, uaa, &uca))
137 USB_ATTACH_ERROR_RETURN;
138 USB_ATTACH_SUCCESS_RETURN;
139 }
140
141 #ifdef __strong_alias
142 __strong_alias(umodem_activate,umodem_common_activate)
143 #else
144 int
145 umodem_activate(device_ptr_t self, enum devact act)
146 {
147 struct umodem_softc *sc = (struct umodem_softc *)self;
148
149 return umodem_common_activate(sc, act);
150 }
151 #endif
152
153 USB_DETACH(umodem)
154 {
155 USB_DETACH_START(umodem, sc);
156 #ifdef __FreeBSD__
157 int flags = 0;
158 #endif
159
160 return umodem_common_detach(sc, flags);
161 }
162