1 /* $NetBSD: umodem.c,v 1.6 1999/01/10 11:13:36 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@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 * Comm Class spec: http://www.usb.org/developers/data/cdc109c1.pdf 42 */ 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/kernel.h> 47 #include <sys/malloc.h> 48 #if defined(__NetBSD__) 49 #include <sys/ioctl.h> 50 #elif defined(__FreeBSD__) 51 #include <sys/module.h> 52 #include <sys/bus.h> 53 #include <sys/ioccom.h> 54 #include <sys/conf.h> 55 #endif 56 #include <sys/tty.h> 57 #include <sys/file.h> 58 #include <sys/select.h> 59 #include <sys/proc.h> 60 #include <sys/vnode.h> 61 #include <sys/device.h> 62 #include <sys/poll.h> 63 64 #include <dev/usb/usb.h> 65 #include <dev/usb/usbcdc.h> 66 67 #include <dev/usb/usbdi.h> 68 #include <dev/usb/usbdi_util.h> 69 #include <dev/usb/usbdevs.h> 70 #include <dev/usb/usb_quirks.h> 71 72 #ifdef USB_DEBUG 73 #define DPRINTF(x) if (umodemdebug) printf x 74 #define DPRINTFN(n,x) if (umodemdebug>(n)) printf x 75 int umodemdebug = 0; 76 #else 77 #define DPRINTF(x) 78 #define DPRINTFN(n,x) 79 #endif 80 81 struct umodem_softc { 82 bdevice sc_dev; /* base device */ 83 usbd_interface_handle sc_ctl; /* control interface */ 84 usbd_interface_handle sc_data; /* data interface */ 85 uByte cmCaps; 86 uByte acmCaps; 87 }; 88 89 void umodem_intr __P((usbd_request_handle, usbd_private_handle, usbd_status)); 90 void umodem_disco __P((void *)); 91 92 USB_DECLARE_DRIVER(umodem); 93 94 USB_MATCH(umodem) 95 { 96 USB_MATCH_START(umodem, uaa); 97 98 usb_interface_descriptor_t *id; 99 100 if (!uaa->iface) 101 return (UMATCH_NONE); 102 id = usbd_get_interface_descriptor(uaa->iface); 103 if (!id || 104 id->bInterfaceClass != UCLASS_CDC || 105 id->bInterfaceSubClass != USUBCLASS_ABSTRACT_CONTROL_MODEL || 106 id->bInterfaceProtocol != UPROTO_CDC_AT) 107 return (UMATCH_NONE); 108 return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO); 109 } 110 111 USB_ATTACH(umodem) 112 { 113 USB_ATTACH_START(umodem, sc, uaa); 114 usbd_interface_handle iface = uaa->iface; 115 usb_interface_descriptor_t *id; 116 char devinfo[1024]; 117 118 sc->sc_ctl = iface; 119 id = usbd_get_interface_descriptor(iface); 120 usbd_devinfo(uaa->device, 0, devinfo); 121 USB_ATTACH_SETUP; 122 printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev), 123 devinfo, id->bInterfaceClass, id->bInterfaceSubClass); 124 125 USB_ATTACH_SUCCESS_RETURN; 126 } 127 128 #if defined(__FreeBSD__) 129 static int 130 umodem_detach(device_t self) 131 { 132 struct umodem_softc *sc = device_get_softc(self); 133 char *devinfo = (char *) device_get_desc(self); 134 135 if (devinfo) { 136 device_set_desc(self, NULL); 137 free(devinfo, M_USB); 138 } 139 140 return 0; 141 } 142 #endif 143 144 #if defined(__FreeBSD__) 145 DRIVER_MODULE(umodem, usb, umodem_driver, umodem_devclass, usbd_driver_load,0); 146 #endif 147 148