Home | History | Annotate | Line # | Download | only in usb
umodem.c revision 1.2
      1 /*	$NetBSD: umodem.c,v 1.2 1998/12/09 00:18:11 augustss 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 (augustss (at) carlstedt.se) 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 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/kernel.h>
     44 #include <sys/malloc.h>
     45 #include <sys/device.h>
     46 #include <sys/ioctl.h>
     47 #include <sys/tty.h>
     48 #include <sys/file.h>
     49 #include <sys/select.h>
     50 #include <sys/proc.h>
     51 #include <sys/vnode.h>
     52 #include <sys/device.h>
     53 #include <sys/poll.h>
     54 
     55 #include <dev/usb/usb.h>
     56 #include <dev/usb/usbhid.h>
     57 
     58 #include <dev/usb/usbdi.h>
     59 #include <dev/usb/usbdi_util.h>
     60 #include <dev/usb/usbdevs.h>
     61 #include <dev/usb/usb_quirks.h>
     62 #include <dev/usb/hid.h>
     63 
     64 #ifdef USB_DEBUG
     65 #define DPRINTF(x)	if (umodemdebug) printf x
     66 #define DPRINTFN(n,x)	if (umodemdebug>(n)) printf x
     67 int	umodemdebug = 0;
     68 #else
     69 #define DPRINTF(x)
     70 #define DPRINTFN(n,x)
     71 #endif
     72 
     73 struct umodem_softc {
     74 	struct device sc_dev;		/* base device */
     75 	usbd_interface_handle sc_iface;	/* interface */
     76 };
     77 
     78 int umodem_match __P((struct device *, struct cfdata *, void *));
     79 void umodem_attach __P((struct device *, struct device *, void *));
     80 
     81 void umodem_intr __P((usbd_request_handle, usbd_private_handle, usbd_status));
     82 void umodem_disco __P((void *));
     83 
     84 extern struct cfdriver umodem_cd;
     85 
     86 struct cfattach umodem_ca = {
     87 	sizeof(struct umodem_softc), umodem_match, umodem_attach
     88 };
     89 
     90 int
     91 umodem_match(parent, match, aux)
     92 	struct device *parent;
     93 	struct cfdata *match;
     94 	void *aux;
     95 {
     96 	struct usb_attach_arg *uaa = aux;
     97 	usb_interface_descriptor_t *id;
     98 
     99 	if (!uaa->iface)
    100 		return (UMATCH_NONE);
    101 	id = usbd_get_interface_descriptor(uaa->iface);
    102 	if (id &&
    103 	    id->bInterfaceClass != UCLASS_CDC ||
    104 	    id->bInterfaceSubClass != USUBCLASS_ABSTRACT_CONTROL_MODEL ||
    105 	    id->bInterfaceProtocol != UPROTO_CDC_AT)
    106 		return (UMATCH_NONE);
    107 	return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
    108 }
    109 
    110 void
    111 umodem_attach(parent, self, aux)
    112 	struct device *parent;
    113 	struct device *self;
    114 	void *aux;
    115 {
    116 	struct umodem_softc *sc = (struct umodem_softc *)self;
    117 	struct usb_attach_arg *uaa = aux;
    118 	usbd_interface_handle iface = uaa->iface;
    119 	usb_interface_descriptor_t *id;
    120 	char devinfo[1024];
    121 
    122 	sc->sc_iface = iface;
    123 	id = usbd_get_interface_descriptor(iface);
    124 	usbd_devinfo(uaa->device, 0, devinfo);
    125 	printf("\n%s: %s, iclass %d/%d\n", sc->sc_dev.dv_xname,
    126 	       devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
    127 }
    128