Home | History | Annotate | Line # | Download | only in usb
umodem.c revision 1.71
      1  1.71       mrg /*	$NetBSD: umodem.c,v 1.71 2019/05/05 03:17:54 mrg 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  *
     20   1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21   1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22   1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23   1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24   1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     31   1.6  augustss  */
     32   1.6  augustss 
     33   1.6  augustss /*
     34  1.46       wiz  * Comm Class spec:  http://www.usb.org/developers/devclass_docs/usbccs10.pdf
     35  1.46       wiz  *                   http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
     36   1.9  augustss  */
     37   1.9  augustss 
     38   1.9  augustss /*
     39   1.9  augustss  * TODO:
     40   1.9  augustss  * - Add error recovery in various places; the big problem is what
     41   1.9  augustss  *   to do in a callback if there is an error.
     42   1.9  augustss  * - Implement a Call Device for modems without multiplexed commands.
     43   1.9  augustss  *
     44   1.1  augustss  */
     45  1.41     lukem 
     46  1.41     lukem #include <sys/cdefs.h>
     47  1.71       mrg __KERNEL_RCSID(0, "$NetBSD: umodem.c,v 1.71 2019/05/05 03:17:54 mrg Exp $");
     48   1.1  augustss 
     49   1.1  augustss #include <sys/param.h>
     50   1.1  augustss #include <sys/systm.h>
     51   1.1  augustss #include <sys/kernel.h>
     52   1.1  augustss #include <sys/ioctl.h>
     53   1.3  augustss #include <sys/conf.h>
     54   1.1  augustss #include <sys/tty.h>
     55   1.1  augustss #include <sys/file.h>
     56   1.1  augustss #include <sys/select.h>
     57   1.1  augustss #include <sys/proc.h>
     58   1.1  augustss #include <sys/vnode.h>
     59   1.1  augustss #include <sys/device.h>
     60   1.1  augustss #include <sys/poll.h>
     61   1.1  augustss 
     62   1.1  augustss #include <dev/usb/usb.h>
     63   1.9  augustss #include <dev/usb/usbcdc.h>
     64   1.9  augustss 
     65   1.1  augustss #include <dev/usb/usbdi.h>
     66   1.1  augustss #include <dev/usb/usbdi_util.h>
     67   1.1  augustss #include <dev/usb/usbdevs.h>
     68   1.1  augustss #include <dev/usb/usb_quirks.h>
     69   1.1  augustss 
     70  1.20  augustss #include <dev/usb/ucomvar.h>
     71  1.51     itohy #include <dev/usb/umodemvar.h>
     72   1.9  augustss 
     73  1.25  augustss Static struct ucom_methods umodem_methods = {
     74  1.68     skrll 	.ucom_get_status = umodem_get_status,
     75  1.68     skrll 	.ucom_set = umodem_set,
     76  1.68     skrll 	.ucom_param = umodem_param,
     77  1.68     skrll 	.ucom_ioctl = umodem_ioctl,
     78  1.68     skrll 	.ucom_open = umodem_open,
     79  1.68     skrll 	.ucom_close = umodem_close,
     80  1.20  augustss };
     81   1.1  augustss 
     82  1.69   msaitoh int	umodem_match(device_t, cfdata_t, void *);
     83  1.69   msaitoh void	umodem_attach(device_t, device_t, void *);
     84  1.69   msaitoh int	umodem_detach(device_t, int);
     85  1.69   msaitoh int	umodem_activate(device_t, enum devact);
     86   1.1  augustss 
     87  1.71       mrg 
     88  1.60    dyoung 
     89  1.60    dyoung CFATTACH_DECL_NEW(umodem, sizeof(struct umodem_softc), umodem_match,
     90  1.60    dyoung     umodem_attach, umodem_detach, umodem_activate);
     91  1.60    dyoung 
     92  1.68     skrll int
     93  1.60    dyoung umodem_match(device_t parent, cfdata_t match, void *aux)
     94   1.3  augustss {
     95  1.68     skrll 	struct usbif_attach_arg *uiaa = aux;
     96   1.1  augustss 	usb_interface_descriptor_t *id;
     97   1.9  augustss 	int cm, acm;
     98  1.31  explorer 
     99  1.68     skrll 	if (uiaa->uiaa_class != UICLASS_CDC ||
    100  1.68     skrll 	    uiaa->uiaa_subclass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
    101  1.68     skrll 	    !(uiaa->uiaa_proto == UIPROTO_CDC_NOCLASS || uiaa->uiaa_proto == UIPROTO_CDC_AT))
    102  1.68     skrll 		return UMATCH_NONE;
    103  1.68     skrll 
    104  1.68     skrll 	id = usbd_get_interface_descriptor(uiaa->uiaa_iface);
    105  1.68     skrll 	if (umodem_get_caps(uiaa->uiaa_device, &cm, &acm, id) == -1)
    106  1.68     skrll 		return UMATCH_NONE;
    107   1.9  augustss 
    108  1.68     skrll 	return UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO;
    109   1.1  augustss }
    110  1.68     skrll //
    111  1.68     skrll void
    112  1.60    dyoung umodem_attach(device_t parent, device_t self, void *aux)
    113   1.1  augustss {
    114  1.60    dyoung 	struct umodem_softc *sc = device_private(self);
    115  1.68     skrll 	struct usbif_attach_arg *uiaa = aux;
    116  1.68     skrll 	struct ucom_attach_args ucaa;
    117   1.9  augustss 
    118  1.68     skrll 	ucaa.ucaa_portno = UCOM_UNK_PORTNO;
    119  1.68     skrll 	ucaa.ucaa_methods = &umodem_methods;
    120  1.68     skrll 	ucaa.ucaa_info = NULL;
    121  1.20  augustss 
    122  1.65   mlelstv 	if (!pmf_device_register(self, NULL, NULL))
    123  1.65   mlelstv 		aprint_error_dev(self, "couldn't establish power handler");
    124  1.65   mlelstv 
    125  1.68     skrll 	if (umodem_common_attach(self, sc, uiaa, &ucaa))
    126  1.60    dyoung 		return;
    127  1.60    dyoung 	return;
    128   1.9  augustss }
    129   1.9  augustss 
    130   1.9  augustss int
    131  1.60    dyoung umodem_activate(device_t self, enum devact act)
    132   1.9  augustss {
    133  1.58      cube 	struct umodem_softc *sc = device_private(self);
    134   1.9  augustss 
    135  1.51     itohy 	return umodem_common_activate(sc, act);
    136   1.9  augustss }
    137   1.9  augustss 
    138  1.68     skrll int
    139  1.60    dyoung umodem_detach(device_t self, int flags)
    140   1.9  augustss {
    141  1.60    dyoung 	struct umodem_softc *sc = device_private(self);
    142   1.9  augustss 
    143  1.65   mlelstv 	pmf_device_deregister(self);
    144  1.65   mlelstv 
    145  1.51     itohy 	return umodem_common_detach(sc, flags);
    146   1.9  augustss }
    147