umodem.c revision 1.56 1 /* $NetBSD: umodem.c,v 1.56 2007/03/13 13:51:56 drochner 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.56 2007/03/13 13:51:56 drochner 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 USB_IFMATCH_START(umodem, uaa);
96 usb_interface_descriptor_t *id;
97 int cm, acm;
98
99 if (uaa->class != UICLASS_CDC ||
100 uaa->subclass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
101 uaa->proto != UIPROTO_CDC_AT)
102 return (UMATCH_NONE);
103
104 id = usbd_get_interface_descriptor(uaa->iface);
105 if (umodem_get_caps(uaa->device, &cm, &acm, id) == -1)
106 return (UMATCH_NONE);
107
108 return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
109 }
110
111 USB_ATTACH(umodem)
112 {
113 USB_IFATTACH_START(umodem, sc, uaa);
114 struct ucom_attach_args uca;
115
116 uca.portno = UCOM_UNK_PORTNO;
117 uca.methods = &umodem_methods;
118 uca.info = NULL;
119
120 if (umodem_common_attach(self, sc, uaa, &uca))
121 USB_ATTACH_ERROR_RETURN;
122 USB_ATTACH_SUCCESS_RETURN;
123 }
124
125 #ifdef __strong_alias
126 __strong_alias(umodem_activate,umodem_common_activate)
127 #else
128 int
129 umodem_activate(device_ptr_t self, enum devact act)
130 {
131 struct umodem_softc *sc = (struct umodem_softc *)self;
132
133 return umodem_common_activate(sc, act);
134 }
135 #endif
136
137 USB_DETACH(umodem)
138 {
139 USB_DETACH_START(umodem, sc);
140 #ifdef __FreeBSD__
141 int flags = 0;
142 #endif
143
144 return umodem_common_detach(sc, flags);
145 }
146