Home | History | Annotate | Line # | Download | only in usb
umodem.c revision 1.54.20.1
      1 /*	$NetBSD: umodem.c,v 1.54.20.1 2007/02/01 08:48:29 ad 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.54.20.1 2007/02/01 08:48:29 ad 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_MATCH_START(umodem, uaa);
     96 	usb_interface_descriptor_t *id;
     97 	int cm, acm;
     98 
     99 	if (uaa->iface == NULL)
    100 		return (UMATCH_NONE);
    101 
    102 	id = usbd_get_interface_descriptor(uaa->iface);
    103 	if (id == NULL ||
    104 	    id->bInterfaceClass != UICLASS_CDC ||
    105 	    id->bInterfaceSubClass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
    106 	    id->bInterfaceProtocol != UIPROTO_CDC_AT)
    107 		return (UMATCH_NONE);
    108 
    109 	if (umodem_get_caps(uaa->device, &cm, &acm, id) == -1)
    110 		return (UMATCH_NONE);
    111 
    112 	return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
    113 }
    114 
    115 USB_ATTACH(umodem)
    116 {
    117 	USB_ATTACH_START(umodem, sc, uaa);
    118 	struct ucom_attach_args uca;
    119 
    120 	uca.portno = UCOM_UNK_PORTNO;
    121 	uca.methods = &umodem_methods;
    122 	uca.info = NULL;
    123 
    124 	if (umodem_common_attach(self, sc, uaa, &uca))
    125 		USB_ATTACH_ERROR_RETURN;
    126 	USB_ATTACH_SUCCESS_RETURN;
    127 }
    128 
    129 #ifdef __strong_alias
    130 __strong_alias(umodem_activate,umodem_common_activate)
    131 #else
    132 int
    133 umodem_activate(device_ptr_t self, enum devact act)
    134 {
    135 	struct umodem_softc *sc = (struct umodem_softc *)self;
    136 
    137 	return umodem_common_activate(sc, act);
    138 }
    139 #endif
    140 
    141 USB_DETACH(umodem)
    142 {
    143 	USB_DETACH_START(umodem, sc);
    144 #ifdef __FreeBSD__
    145 	int flags = 0;
    146 #endif
    147 
    148 	return umodem_common_detach(sc, flags);
    149 }
    150