Home | History | Annotate | Line # | Download | only in usb
umodem.c revision 1.49.4.1
      1 /*	$NetBSD: umodem.c,v 1.49.4.1 2005/04/29 11:29:18 kent 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.49.4.1 2005/04/29 11:29:18 kent 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 Static struct ucom_methods umodem_methods = {
     82 	umodem_get_status,
     83 	umodem_set,
     84 	umodem_param,
     85 	umodem_ioctl,
     86 	umodem_open,
     87 	umodem_close,
     88 	NULL,
     89 	NULL,
     90 };
     91 
     92 USB_DECLARE_DRIVER(umodem);
     93 
     94 USB_MATCH(umodem)
     95 {
     96 	USB_MATCH_START(umodem, uaa);
     97 	usb_interface_descriptor_t *id;
     98 	int cm, acm;
     99 
    100 	if (uaa->iface == NULL)
    101 		return (UMATCH_NONE);
    102 
    103 	id = usbd_get_interface_descriptor(uaa->iface);
    104 	if (id == NULL ||
    105 	    id->bInterfaceClass != UICLASS_CDC ||
    106 	    id->bInterfaceSubClass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
    107 	    id->bInterfaceProtocol != UIPROTO_CDC_AT)
    108 		return (UMATCH_NONE);
    109 
    110 	if (umodem_get_caps(uaa->device, &cm, &acm, id) == -1)
    111 		return (UMATCH_NONE);
    112 
    113 	return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
    114 }
    115 
    116 USB_ATTACH(umodem)
    117 {
    118 	USB_ATTACH_START(umodem, sc, uaa);
    119 	struct ucom_attach_args uca;
    120 
    121 	uca.portno = UCOM_UNK_PORTNO;
    122 	uca.methods = &umodem_methods;
    123 	uca.info = NULL;
    124 
    125 	if (umodem_common_attach(self, sc, uaa, &uca))
    126 		USB_ATTACH_ERROR_RETURN;
    127 	USB_ATTACH_SUCCESS_RETURN;
    128 }
    129 
    130 #ifdef __strong_alias
    131 __strong_alias(umodem_activate,umodem_common_activate)
    132 #else
    133 int
    134 umodem_activate(device_ptr_t self, enum devact act)
    135 {
    136 	struct umodem_softc *sc = (struct umodem_softc *)self;
    137 
    138 	return umodem_common_activate(sc, act);
    139 }
    140 #endif
    141 
    142 USB_DETACH(umodem)
    143 {
    144 	USB_DETACH_START(umodem, sc);
    145 #ifdef __FreeBSD__
    146 	int flags = 0;
    147 #endif
    148 
    149 	return umodem_common_detach(sc, flags);
    150 }
    151