Home | History | Annotate | Line # | Download | only in usb
umodem.c revision 1.51
      1  1.51     itohy /*	$NetBSD: umodem.c,v 1.51 2005/04/15 14:14:09 itohy Exp $	*/
      2   1.1  augustss 
      3   1.1  augustss /*
      4   1.1  augustss  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1  augustss  * All rights reserved.
      6   1.1  augustss  *
      7   1.1  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8  1.28  augustss  * by Lennart Augustsson (lennart (at) augustsson.net) at
      9   1.1  augustss  * Carlstedt Research & Technology.
     10   1.1  augustss  *
     11   1.1  augustss  * Redistribution and use in source and binary forms, with or without
     12   1.1  augustss  * modification, are permitted provided that the following conditions
     13   1.1  augustss  * are met:
     14   1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     15   1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     16   1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     18   1.1  augustss  *    documentation and/or other materials provided with the distribution.
     19   1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     20   1.1  augustss  *    must display the following acknowledgement:
     21   1.1  augustss  *        This product includes software developed by the NetBSD
     22   1.1  augustss  *        Foundation, Inc. and its contributors.
     23   1.1  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24   1.1  augustss  *    contributors may be used to endorse or promote products derived
     25   1.1  augustss  *    from this software without specific prior written permission.
     26   1.1  augustss  *
     27   1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28   1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29   1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30   1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31   1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32   1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33   1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34   1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35   1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36   1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37   1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     38   1.6  augustss  */
     39   1.6  augustss 
     40   1.6  augustss /*
     41  1.46       wiz  * Comm Class spec:  http://www.usb.org/developers/devclass_docs/usbccs10.pdf
     42  1.46       wiz  *                   http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
     43   1.9  augustss  */
     44   1.9  augustss 
     45   1.9  augustss /*
     46   1.9  augustss  * TODO:
     47   1.9  augustss  * - Add error recovery in various places; the big problem is what
     48   1.9  augustss  *   to do in a callback if there is an error.
     49   1.9  augustss  * - Implement a Call Device for modems without multiplexed commands.
     50   1.9  augustss  *
     51   1.1  augustss  */
     52  1.41     lukem 
     53  1.41     lukem #include <sys/cdefs.h>
     54  1.51     itohy __KERNEL_RCSID(0, "$NetBSD: umodem.c,v 1.51 2005/04/15 14:14:09 itohy Exp $");
     55   1.1  augustss 
     56   1.1  augustss #include <sys/param.h>
     57   1.1  augustss #include <sys/systm.h>
     58   1.1  augustss #include <sys/kernel.h>
     59   1.1  augustss #include <sys/ioctl.h>
     60   1.3  augustss #include <sys/conf.h>
     61   1.1  augustss #include <sys/tty.h>
     62   1.1  augustss #include <sys/file.h>
     63   1.1  augustss #include <sys/select.h>
     64   1.1  augustss #include <sys/proc.h>
     65   1.1  augustss #include <sys/vnode.h>
     66   1.1  augustss #include <sys/device.h>
     67   1.1  augustss #include <sys/poll.h>
     68   1.1  augustss 
     69   1.1  augustss #include <dev/usb/usb.h>
     70   1.9  augustss #include <dev/usb/usbcdc.h>
     71   1.9  augustss 
     72   1.1  augustss #include <dev/usb/usbdi.h>
     73   1.1  augustss #include <dev/usb/usbdi_util.h>
     74   1.1  augustss #include <dev/usb/usbdevs.h>
     75   1.1  augustss #include <dev/usb/usb_quirks.h>
     76   1.1  augustss 
     77   1.9  augustss #include <dev/usb/usbdevs.h>
     78  1.20  augustss #include <dev/usb/ucomvar.h>
     79  1.51     itohy #include <dev/usb/umodemvar.h>
     80   1.9  augustss 
     81  1.20  augustss #ifdef UMODEM_DEBUG
     82   1.9  augustss #define DPRINTFN(n, x)	if (umodemdebug > (n)) logprintf x
     83   1.1  augustss int	umodemdebug = 0;
     84   1.1  augustss #else
     85   1.9  augustss #define DPRINTFN(n, x)
     86   1.1  augustss #endif
     87   1.9  augustss #define DPRINTF(x) DPRINTFN(0, x)
     88   1.9  augustss 
     89  1.25  augustss Static struct ucom_methods umodem_methods = {
     90  1.20  augustss 	umodem_get_status,
     91  1.20  augustss 	umodem_set,
     92  1.20  augustss 	umodem_param,
     93  1.20  augustss 	umodem_ioctl,
     94  1.39      kenh 	umodem_open,
     95  1.39      kenh 	umodem_close,
     96  1.27  augustss 	NULL,
     97  1.27  augustss 	NULL,
     98  1.20  augustss };
     99   1.1  augustss 
    100   1.3  augustss USB_DECLARE_DRIVER(umodem);
    101   1.1  augustss 
    102   1.3  augustss USB_MATCH(umodem)
    103   1.3  augustss {
    104   1.3  augustss 	USB_MATCH_START(umodem, uaa);
    105   1.1  augustss 	usb_interface_descriptor_t *id;
    106   1.9  augustss 	int cm, acm;
    107  1.31  explorer 
    108  1.20  augustss 	if (uaa->iface == NULL)
    109   1.1  augustss 		return (UMATCH_NONE);
    110   1.9  augustss 
    111   1.1  augustss 	id = usbd_get_interface_descriptor(uaa->iface);
    112  1.20  augustss 	if (id == NULL ||
    113  1.23  augustss 	    id->bInterfaceClass != UICLASS_CDC ||
    114  1.23  augustss 	    id->bInterfaceSubClass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
    115  1.23  augustss 	    id->bInterfaceProtocol != UIPROTO_CDC_AT)
    116   1.1  augustss 		return (UMATCH_NONE);
    117  1.31  explorer 
    118  1.50     itohy 	umodem_get_caps(uaa->device, &cm, &acm, id);
    119   1.9  augustss 	if (!(cm & USB_CDC_CM_DOES_CM) ||
    120   1.9  augustss 	    !(cm & USB_CDC_CM_OVER_DATA) ||
    121   1.9  augustss 	    !(acm & USB_CDC_ACM_HAS_LINE))
    122   1.9  augustss 		return (UMATCH_NONE);
    123   1.9  augustss 
    124   1.2  augustss 	return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
    125   1.1  augustss }
    126   1.1  augustss 
    127   1.3  augustss USB_ATTACH(umodem)
    128   1.1  augustss {
    129   1.3  augustss 	USB_ATTACH_START(umodem, sc, uaa);
    130  1.20  augustss 	struct ucom_attach_args uca;
    131   1.9  augustss 
    132  1.20  augustss 	uca.portno = UCOM_UNK_PORTNO;
    133  1.20  augustss 	uca.methods = &umodem_methods;
    134  1.38  augustss 	uca.info = NULL;
    135  1.20  augustss 
    136  1.51     itohy 	if (umodem_common_attach(self, sc, uaa, &uca))
    137  1.51     itohy 		USB_ATTACH_ERROR_RETURN;
    138   1.3  augustss 	USB_ATTACH_SUCCESS_RETURN;
    139   1.9  augustss }
    140   1.9  augustss 
    141  1.51     itohy #ifdef __strong_alias
    142  1.51     itohy __strong_alias(umodem_activate,umodem_common_activate)
    143  1.51     itohy #else
    144   1.9  augustss int
    145  1.29  augustss umodem_activate(device_ptr_t self, enum devact act)
    146   1.9  augustss {
    147   1.9  augustss 	struct umodem_softc *sc = (struct umodem_softc *)self;
    148   1.9  augustss 
    149  1.51     itohy 	return umodem_common_activate(sc, act);
    150   1.9  augustss }
    151  1.51     itohy #endif
    152   1.9  augustss 
    153  1.21  augustss USB_DETACH(umodem)
    154   1.9  augustss {
    155  1.21  augustss 	USB_DETACH_START(umodem, sc);
    156  1.51     itohy #ifdef __FreeBSD__
    157  1.51     itohy 	int flags = 0;
    158  1.51     itohy #endif
    159   1.9  augustss 
    160  1.51     itohy 	return umodem_common_detach(sc, flags);
    161   1.9  augustss }
    162