2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2004-03-01 02:34:49 +00:00
|
|
|
* Copyright (c) 2004 Bernd Walter <ticso@freebsd.org>
|
|
|
|
*
|
|
|
|
* $URL: https://devel.bwct.de/svn/projects/ubser/ubser.c $
|
|
|
|
* $Date: 2004-02-29 01:53:10 +0100 (Sun, 29 Feb 2004) $
|
|
|
|
* $Author: ticso $
|
|
|
|
* $Rev: 1127 $
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2004-03-01 02:34:49 +00:00
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Lennart Augustsson (lennart@augustsson.net).
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BWCT serial adapter driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2004-03-01 02:34:49 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/conf.h>
|
2004-10-12 09:18:37 +00:00
|
|
|
#include <sys/serial.h>
|
2004-03-01 02:34:49 +00:00
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/clist.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
|
|
|
|
#include <sys/selinfo.h>
|
|
|
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
#include <dev/usb/usbhid.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
2004-06-27 12:41:44 +00:00
|
|
|
#include "usbdevs.h"
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
#include <dev/usb/ubser.h>
|
|
|
|
|
|
|
|
#ifdef USB_DEBUG
|
|
|
|
static int ubserdebug = 0;
|
|
|
|
SYSCTL_NODE(_hw_usb, OID_AUTO, ubser, CTLFLAG_RW, 0, "USB ubser");
|
|
|
|
SYSCTL_INT(_hw_usb_ubser, OID_AUTO, debug, CTLFLAG_RW,
|
|
|
|
&ubserdebug, 0, "ubser debug level");
|
|
|
|
#define DPRINTF(x) do { \
|
|
|
|
if (ubserdebug) \
|
|
|
|
logprintf x; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define DPRINTFN(n, x) do { \
|
|
|
|
if (ubserdebug > (n)) \
|
|
|
|
logprintf x; \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ISSET(t, f) ((t) & (f))
|
|
|
|
#define SET(t, f) (t) |= (f)
|
|
|
|
#define CLR(t, f) (t) &= ~((unsigned)(f))
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port {
|
|
|
|
int p_port;
|
|
|
|
struct ubser_softc *p_sc;
|
|
|
|
usbd_xfer_handle p_oxfer; /* write request */
|
|
|
|
u_char *p_obuf; /* write buffer */
|
|
|
|
struct tty *p_tty;
|
|
|
|
};
|
|
|
|
|
2004-03-01 02:34:49 +00:00
|
|
|
struct ubser_softc {
|
2006-09-07 00:06:42 +00:00
|
|
|
device_t sc_dev;
|
2004-03-01 02:34:49 +00:00
|
|
|
usbd_device_handle sc_udev;
|
|
|
|
usbd_interface_handle sc_iface; /* data interface */
|
|
|
|
int sc_ifaceno;
|
|
|
|
|
|
|
|
int sc_refcnt;
|
|
|
|
u_char sc_dying;
|
|
|
|
u_char sc_opening;
|
|
|
|
int sc_state;
|
|
|
|
uint8_t sc_numser;
|
|
|
|
|
|
|
|
int sc_bulkin_no; /* bulk in endpoint address */
|
|
|
|
usbd_pipe_handle sc_bulkin_pipe; /* bulk in pipe */
|
|
|
|
usbd_xfer_handle sc_ixfer; /* read request */
|
|
|
|
u_char *sc_ibuf; /* read buffer */
|
|
|
|
u_int sc_ibufsize; /* read buffer size */
|
|
|
|
u_int sc_ibufsizepad; /* read buffer size padded */
|
|
|
|
|
|
|
|
int sc_bulkout_no; /* bulk out endpoint address */
|
|
|
|
usbd_pipe_handle sc_bulkout_pipe;/* bulk out pipe */
|
|
|
|
u_int sc_obufsize; /* write buffer size */
|
|
|
|
u_int sc_opkthdrlen; /* header length of
|
|
|
|
output packet */
|
|
|
|
|
2005-03-17 22:47:18 +00:00
|
|
|
struct ubser_port *sc_port;
|
2004-10-12 09:18:37 +00:00
|
|
|
};
|
2004-03-01 02:34:49 +00:00
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int ubserparam(struct tty *, struct termios *);
|
|
|
|
static void ubserstart(struct tty *);
|
|
|
|
static void ubserstop(struct tty *, int);
|
|
|
|
static usbd_status ubserstartread(struct ubser_softc *);
|
|
|
|
static void ubserreadcb(usbd_xfer_handle, usbd_private_handle, usbd_status);
|
|
|
|
static void ubserwritecb(usbd_xfer_handle, usbd_private_handle, usbd_status);
|
|
|
|
static void ubser_cleanup(struct ubser_softc *sc);
|
|
|
|
|
|
|
|
static t_break_t ubserbreak;
|
|
|
|
static t_open_t ubseropen;
|
|
|
|
static t_close_t ubserclose;
|
|
|
|
static t_modem_t ubsermodem;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
USB_DECLARE_DRIVER(ubser);
|
|
|
|
|
|
|
|
USB_MATCH(ubser)
|
|
|
|
{
|
|
|
|
USB_MATCH_START(ubser, uaa);
|
|
|
|
usb_string_descriptor_t us;
|
|
|
|
usb_interface_descriptor_t *id;
|
|
|
|
usb_device_descriptor_t *dd;
|
2004-06-26 13:21:31 +00:00
|
|
|
int err, size;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
if (uaa->iface == NULL)
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
|
|
|
|
DPRINTFN(20,("ubser: vendor=0x%x, product=0x%x\n",
|
|
|
|
uaa->vendor, uaa->product));
|
|
|
|
|
|
|
|
dd = usbd_get_device_descriptor(uaa->device);
|
|
|
|
if (dd == NULL) {
|
|
|
|
printf("ubser: failed to get device descriptor\n");
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
id = usbd_get_interface_descriptor(uaa->iface);
|
|
|
|
if (id == NULL) {
|
|
|
|
printf("ubser: failed to get interface descriptor\n");
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
}
|
|
|
|
|
2004-06-26 13:21:31 +00:00
|
|
|
err = usbd_get_string_desc(uaa->device, dd->iManufacturer, 0, &us,
|
|
|
|
&size);
|
2004-03-01 02:34:49 +00:00
|
|
|
if (err != 0)
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
|
|
|
|
/* check if this is a BWCT vendor specific ubser interface */
|
|
|
|
if (strcmp((char*)us.bString, "B\0W\0C\0T\0") == 0 &&
|
|
|
|
id->bInterfaceClass == 0xff && id->bInterfaceSubClass == 0x00)
|
|
|
|
return (UMATCH_VENDOR_IFACESUBCLASS);
|
|
|
|
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
USB_ATTACH(ubser)
|
|
|
|
{
|
|
|
|
USB_ATTACH_START(ubser, sc, uaa);
|
|
|
|
usbd_device_handle udev = uaa->device;
|
|
|
|
usb_endpoint_descriptor_t *ed;
|
|
|
|
usb_interface_descriptor_t *id;
|
|
|
|
usb_device_request_t req;
|
|
|
|
struct tty *tp;
|
|
|
|
usbd_status err;
|
|
|
|
int i;
|
|
|
|
int alen;
|
|
|
|
uint8_t epcount;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
2007-06-09 06:39:43 +00:00
|
|
|
sc->sc_dev = self;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
DPRINTFN(10,("\nubser_attach: sc=%p\n", sc));
|
|
|
|
|
|
|
|
sc->sc_udev = udev = uaa->device;
|
|
|
|
sc->sc_iface = uaa->iface;
|
2005-03-17 22:47:18 +00:00
|
|
|
sc->sc_numser = 0;
|
|
|
|
sc->sc_port = NULL;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
/* get interface index */
|
|
|
|
id = usbd_get_interface_descriptor(uaa->iface);
|
|
|
|
if (id == NULL) {
|
|
|
|
printf("ubser: failed to get interface descriptor\n");
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
}
|
|
|
|
sc->sc_ifaceno = id->bInterfaceNumber;
|
|
|
|
|
|
|
|
/* get number of serials */
|
|
|
|
req.bmRequestType = UT_READ_VENDOR_INTERFACE;
|
|
|
|
req.bRequest = VENDOR_GET_NUMSER;
|
|
|
|
USETW(req.wValue, 0);
|
|
|
|
USETW(req.wIndex, sc->sc_ifaceno);
|
|
|
|
USETW(req.wLength, 1);
|
|
|
|
err = usbd_do_request_flags(udev, &req, &sc->sc_numser,
|
|
|
|
USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT);
|
|
|
|
if (err) {
|
2005-03-17 22:47:18 +00:00
|
|
|
printf("%s: failed to get number of serials\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev));
|
2004-03-01 02:34:49 +00:00
|
|
|
goto bad;
|
|
|
|
} else if (alen != 1) {
|
|
|
|
printf("%s: bogus answer on get_numser\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev));
|
2004-03-01 02:34:49 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2005-03-17 22:47:18 +00:00
|
|
|
if (sc->sc_numser > MAX_SER)
|
|
|
|
sc->sc_numser = MAX_SER;
|
2006-09-07 00:06:42 +00:00
|
|
|
printf("%s: found %i serials\n", device_get_nameunit(sc->sc_dev), sc->sc_numser);
|
2004-03-01 02:34:49 +00:00
|
|
|
|
2005-03-17 22:47:18 +00:00
|
|
|
sc->sc_port = malloc(sizeof(*sc->sc_port) * sc->sc_numser,
|
|
|
|
M_USBDEV, M_WAITOK);
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
/* find our bulk endpoints */
|
|
|
|
epcount = 0;
|
2007-04-01 13:46:39 +00:00
|
|
|
(void)usbd_endpoint_count(sc->sc_iface, &epcount);
|
2004-03-01 02:34:49 +00:00
|
|
|
sc->sc_bulkin_no = -1;
|
|
|
|
sc->sc_bulkout_no = -1;
|
|
|
|
for (i = 0; i < epcount; i++) {
|
|
|
|
ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
|
|
|
|
if (ed == NULL) {
|
|
|
|
printf("%s: couldn't get ep %d\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), i);
|
2007-06-12 15:37:19 +00:00
|
|
|
return ENXIO;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
|
|
|
|
sc->sc_bulkin_no = ed->bEndpointAddress;
|
2005-03-17 22:47:18 +00:00
|
|
|
sc->sc_ibufsizepad = UGETW(ed->wMaxPacketSize);
|
|
|
|
sc->sc_ibufsizepad = UGETW(ed->wMaxPacketSize) - 1;
|
2004-03-01 02:34:49 +00:00
|
|
|
} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
|
|
|
|
sc->sc_bulkout_no = ed->bEndpointAddress;
|
2005-03-17 22:47:18 +00:00
|
|
|
sc->sc_obufsize = UGETW(ed->wMaxPacketSize) - 1;
|
|
|
|
sc->sc_opkthdrlen = 1;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-12 09:18:37 +00:00
|
|
|
if (sc->sc_bulkin_no == -1 || sc->sc_bulkout_no == -1) {
|
|
|
|
printf("%s: could not find bulk in/out endpoint\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev));
|
2004-03-01 02:34:49 +00:00
|
|
|
sc->sc_dying = 1;
|
2005-03-17 22:47:18 +00:00
|
|
|
goto bad;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the bulk pipes */
|
|
|
|
/* Bulk-in pipe */
|
|
|
|
err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin_no, 0,
|
|
|
|
&sc->sc_bulkin_pipe);
|
|
|
|
if (err) {
|
|
|
|
printf("%s: open bulk in error (addr %d): %s\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), sc->sc_bulkin_no,
|
2004-03-01 02:34:49 +00:00
|
|
|
usbd_errstr(err));
|
|
|
|
goto fail_0;
|
|
|
|
}
|
|
|
|
/* Bulk-out pipe */
|
|
|
|
err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkout_no,
|
|
|
|
USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
|
|
|
|
if (err) {
|
|
|
|
printf("%s: open bulk out error (addr %d): %s\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), sc->sc_bulkout_no,
|
2004-03-01 02:34:49 +00:00
|
|
|
usbd_errstr(err));
|
|
|
|
goto fail_1;
|
|
|
|
}
|
|
|
|
|
2005-03-17 22:47:18 +00:00
|
|
|
/* Allocate a request and an input buffer */
|
2004-03-01 02:34:49 +00:00
|
|
|
sc->sc_ixfer = usbd_alloc_xfer(sc->sc_udev);
|
|
|
|
if (sc->sc_ixfer == NULL) {
|
|
|
|
goto fail_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_ibuf = usbd_alloc_buffer(sc->sc_ixfer,
|
|
|
|
sc->sc_ibufsizepad);
|
|
|
|
if (sc->sc_ibuf == NULL) {
|
|
|
|
goto fail_3;
|
|
|
|
}
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
for (i = 0; i < sc->sc_numser; i++) {
|
|
|
|
pp = &sc->sc_port[i];
|
|
|
|
pp->p_port = i;
|
2005-03-17 22:47:18 +00:00
|
|
|
pp->p_sc = sc;
|
2004-10-12 09:18:37 +00:00
|
|
|
tp = pp->p_tty = ttyalloc();
|
|
|
|
tp->t_sc = pp;
|
|
|
|
DPRINTF(("ubser_attach: tty_attach tp = %p\n", tp));
|
|
|
|
tp->t_oproc = ubserstart;
|
|
|
|
tp->t_param = ubserparam;
|
|
|
|
tp->t_stop = ubserstop;
|
|
|
|
tp->t_break = ubserbreak;
|
|
|
|
tp->t_open = ubseropen;
|
|
|
|
tp->t_close = ubserclose;
|
|
|
|
tp->t_modem = ubsermodem;
|
2006-09-07 00:06:42 +00:00
|
|
|
ttycreate(tp, 0, "y%r%r", device_get_unit(sc->sc_dev), i);
|
2004-10-12 09:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-17 22:47:18 +00:00
|
|
|
for (i = 0; i < sc->sc_numser; i++) {
|
2004-10-12 09:18:37 +00:00
|
|
|
sc->sc_port[i].p_oxfer = NULL;
|
|
|
|
sc->sc_port[i].p_obuf = NULL;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < sc->sc_numser; i++) {
|
2004-10-12 09:18:37 +00:00
|
|
|
sc->sc_port[i].p_oxfer = usbd_alloc_xfer(sc->sc_udev);
|
|
|
|
if (sc->sc_port[i].p_oxfer == NULL) {
|
2004-03-01 02:34:49 +00:00
|
|
|
goto fail_4;
|
|
|
|
}
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
sc->sc_port[i].p_obuf = usbd_alloc_buffer(sc->sc_port[i].p_oxfer,
|
2004-03-01 02:34:49 +00:00
|
|
|
sc->sc_obufsize +
|
|
|
|
sc->sc_opkthdrlen);
|
2004-10-12 09:18:37 +00:00
|
|
|
if (sc->sc_port[i].p_obuf == NULL) {
|
2004-03-01 02:34:49 +00:00
|
|
|
goto fail_4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ubserstartread(sc);
|
2007-06-12 15:37:19 +00:00
|
|
|
return 0;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
fail_4:
|
|
|
|
for (i = 0; i < sc->sc_numser; i++) {
|
2004-10-12 09:18:37 +00:00
|
|
|
if (sc->sc_port[i].p_oxfer != NULL) {
|
|
|
|
usbd_free_xfer(sc->sc_port[i].p_oxfer);
|
|
|
|
sc->sc_port[i].p_oxfer = NULL;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fail_3:
|
|
|
|
usbd_free_xfer(sc->sc_ixfer);
|
|
|
|
sc->sc_ixfer = NULL;
|
|
|
|
fail_2:
|
|
|
|
usbd_close_pipe(sc->sc_bulkout_pipe);
|
|
|
|
sc->sc_bulkout_pipe = NULL;
|
|
|
|
fail_1:
|
|
|
|
usbd_close_pipe(sc->sc_bulkin_pipe);
|
|
|
|
sc->sc_bulkin_pipe = NULL;
|
|
|
|
fail_0:
|
|
|
|
sc->sc_opening = 0;
|
|
|
|
wakeup(&sc->sc_opening);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
ubser_cleanup(sc);
|
2005-03-17 22:47:18 +00:00
|
|
|
if (sc->sc_port != NULL) {
|
|
|
|
for (i = 0; i < sc->sc_numser; i++) {
|
|
|
|
pp = &sc->sc_port[i];
|
|
|
|
if (pp->p_tty != NULL)
|
|
|
|
ttyfree(pp->p_tty);
|
|
|
|
}
|
|
|
|
free(sc->sc_port, M_USBDEV);
|
|
|
|
sc->sc_port = NULL;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(("ubser_attach: ATTACH ERROR\n"));
|
2007-06-12 15:37:19 +00:00
|
|
|
return ENXIO;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
USB_DETACH(ubser)
|
|
|
|
{
|
|
|
|
USB_DETACH_START(ubser, sc);
|
2005-11-05 17:17:57 +00:00
|
|
|
int i;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
DPRINTF(("ubser_detach: sc=%p\n", sc));
|
|
|
|
|
|
|
|
sc->sc_dying = 1;
|
2004-10-12 09:18:37 +00:00
|
|
|
for (i = 0; i < sc->sc_numser; i++) {
|
|
|
|
pp = &sc->sc_port[i];
|
|
|
|
if (pp->p_tty != NULL)
|
|
|
|
ttygone(pp->p_tty);
|
|
|
|
}
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
if (sc->sc_bulkin_pipe != NULL)
|
|
|
|
usbd_abort_pipe(sc->sc_bulkin_pipe);
|
|
|
|
if (sc->sc_bulkout_pipe != NULL)
|
|
|
|
usbd_abort_pipe(sc->sc_bulkout_pipe);
|
|
|
|
|
2005-03-17 22:47:18 +00:00
|
|
|
if (sc->sc_port != NULL) {
|
|
|
|
for (i = 0; i < sc->sc_numser; i++) {
|
|
|
|
pp = &sc->sc_port[i];
|
|
|
|
if (pp->p_tty != NULL)
|
|
|
|
ttyfree(pp->p_tty);
|
|
|
|
}
|
|
|
|
free(sc->sc_port, M_USBDEV);
|
|
|
|
sc->sc_port = NULL;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (--sc->sc_refcnt >= 0) {
|
|
|
|
/* Wait for processes to go away. */
|
2007-06-12 16:52:07 +00:00
|
|
|
usb_detach_wait(sc->sc_dev);
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2004-03-01 02:34:49 +00:00
|
|
|
ubserparam(struct tty *tp, struct termios *t)
|
|
|
|
{
|
|
|
|
struct ubser_softc *sc;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
pp = tp->t_sc;
|
|
|
|
sc = pp->p_sc;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
|
|
|
|
|
|
|
DPRINTF(("ubserparam: sc = %p\n", sc));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The firmware on our devices can only do 8n1@9600bps
|
|
|
|
* without handshake.
|
|
|
|
* We refuse to accept other configurations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* enshure 9600bps */
|
|
|
|
switch (t->c_ospeed) {
|
|
|
|
case 9600:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2 stop bits not possible */
|
|
|
|
if (ISSET(t->c_cflag, CSTOPB))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* XXX parity handling not possible with current firmware */
|
|
|
|
if (ISSET(t->c_cflag, PARENB))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* we can only do 8 data bits */
|
|
|
|
switch (ISSET(t->c_cflag, CSIZE)) {
|
|
|
|
case CS8:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we can't do any kind of hardware handshaking */
|
|
|
|
if ((t->c_cflag &
|
|
|
|
(CRTS_IFLOW | CDTR_IFLOW |CDSR_OFLOW |CCAR_OFLOW)) != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX xon/xoff not supported by the firmware!
|
|
|
|
* This is handled within FreeBSD only and may overflow buffers
|
|
|
|
* because of delayed reaction due to device buffering.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ttsetwater(tp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2004-03-01 02:34:49 +00:00
|
|
|
ubserstart(struct tty *tp)
|
|
|
|
{
|
|
|
|
struct ubser_softc *sc;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
struct cblock *cbp;
|
|
|
|
usbd_status err;
|
|
|
|
u_char *data;
|
|
|
|
int cnt;
|
|
|
|
uint8_t serial;
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
pp = tp->t_sc;
|
|
|
|
sc = pp->p_sc;
|
|
|
|
serial = pp->p_port;
|
2004-03-01 02:34:49 +00:00
|
|
|
DPRINTF(("ubserstart: sc = %p, tp = %p\n", sc, tp));
|
|
|
|
|
|
|
|
if (sc->sc_dying)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP)) {
|
|
|
|
ttwwakeup(tp);
|
|
|
|
DPRINTF(("ubserstart: stopped\n"));
|
2005-11-05 17:17:57 +00:00
|
|
|
return;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tp->t_outq.c_cc <= tp->t_olowat) {
|
|
|
|
if (ISSET(tp->t_state, TS_SO_OLOWAT)) {
|
|
|
|
CLR(tp->t_state, TS_SO_OLOWAT);
|
|
|
|
wakeup(TSA_OLOWAT(tp));
|
|
|
|
}
|
|
|
|
selwakeuppri(&tp->t_wsel, TTIPRI);
|
|
|
|
if (tp->t_outq.c_cc == 0) {
|
|
|
|
if (ISSET(tp->t_state, TS_BUSY | TS_SO_OCOMPLETE) ==
|
|
|
|
TS_SO_OCOMPLETE && tp->t_outq.c_cc == 0) {
|
|
|
|
CLR(tp->t_state, TS_SO_OCOMPLETE);
|
|
|
|
wakeup(TSA_OCOMPLETE(tp));
|
|
|
|
}
|
2005-11-05 17:17:57 +00:00
|
|
|
return;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Grab the first contiguous region of buffer space. */
|
|
|
|
data = tp->t_outq.c_cf;
|
|
|
|
cbp = (struct cblock *) ((intptr_t) tp->t_outq.c_cf & ~CROUND);
|
|
|
|
cnt = min((char *) (cbp+1) - tp->t_outq.c_cf, tp->t_outq.c_cc);
|
|
|
|
|
|
|
|
if (cnt == 0) {
|
|
|
|
DPRINTF(("ubserstart: cnt == 0\n"));
|
2005-11-05 17:17:57 +00:00
|
|
|
return;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SET(tp->t_state, TS_BUSY);
|
|
|
|
|
|
|
|
if (cnt + sc->sc_opkthdrlen > sc->sc_obufsize) {
|
|
|
|
DPRINTF(("ubserstart: big buffer %d chars\n", cnt));
|
|
|
|
cnt = sc->sc_obufsize;
|
|
|
|
}
|
2004-10-12 09:18:37 +00:00
|
|
|
sc->sc_port[serial].p_obuf[0] = serial;
|
|
|
|
memcpy(sc->sc_port[serial].p_obuf + sc->sc_opkthdrlen, data, cnt);
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
DPRINTF(("ubserstart: %d chars\n", cnt));
|
2004-10-12 09:18:37 +00:00
|
|
|
usbd_setup_xfer(sc->sc_port[serial].p_oxfer, sc->sc_bulkout_pipe,
|
|
|
|
(usbd_private_handle)tp, sc->sc_port[serial].p_obuf,
|
2004-03-01 02:34:49 +00:00
|
|
|
cnt + sc->sc_opkthdrlen,
|
|
|
|
USBD_NO_COPY, USBD_NO_TIMEOUT, ubserwritecb);
|
|
|
|
/* What can we do on error? */
|
2004-10-12 09:18:37 +00:00
|
|
|
err = usbd_transfer(sc->sc_port[serial].p_oxfer);
|
2004-03-01 02:34:49 +00:00
|
|
|
if (err != USBD_IN_PROGRESS)
|
|
|
|
printf("ubserstart: err=%s\n", usbd_errstr(err));
|
|
|
|
|
|
|
|
ttwwakeup(tp);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2004-03-01 02:34:49 +00:00
|
|
|
ubserstop(struct tty *tp, int flag)
|
|
|
|
{
|
|
|
|
struct ubser_softc *sc;
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
sc = tp->t_sc;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
DPRINTF(("ubserstop: %d\n", flag));
|
|
|
|
|
|
|
|
if (flag & FWRITE) {
|
|
|
|
DPRINTF(("ubserstop: write\n"));
|
|
|
|
if (ISSET(tp->t_state, TS_BUSY)) {
|
|
|
|
/* XXX do what? */
|
|
|
|
if (!ISSET(tp->t_state, TS_TTSTOP))
|
|
|
|
SET(tp->t_state, TS_FLUSH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(("ubserstop: done\n"));
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2004-03-01 02:34:49 +00:00
|
|
|
ubserwritecb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
|
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
struct ubser_softc *sc;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
u_int32_t cc;
|
|
|
|
|
|
|
|
tp = (struct tty *)p;
|
2004-10-12 09:18:37 +00:00
|
|
|
pp = tp->t_sc;
|
|
|
|
sc = pp->p_sc;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
DPRINTF(("ubserwritecb: status = %d\n", status));
|
|
|
|
|
|
|
|
if (status == USBD_CANCELLED || sc->sc_dying)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
|
|
|
printf("%s: ubserwritecb: %s\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), usbd_errstr(status));
|
2004-03-01 02:34:49 +00:00
|
|
|
if (status == USBD_STALLED)
|
|
|
|
usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
|
|
|
|
/* XXX we should restart after some delay. */
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
|
|
|
|
DPRINTF(("ubserwritecb: cc = %d\n", cc));
|
|
|
|
if (cc <= sc->sc_opkthdrlen) {
|
|
|
|
printf("%s: sent size too small, cc = %d\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), cc);
|
2004-03-01 02:34:49 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert from USB bytes to tty bytes */
|
|
|
|
cc -= sc->sc_opkthdrlen;
|
|
|
|
|
|
|
|
CLR(tp->t_state, TS_BUSY);
|
|
|
|
if (ISSET(tp->t_state, TS_FLUSH))
|
|
|
|
CLR(tp->t_state, TS_FLUSH);
|
|
|
|
else
|
|
|
|
ndflush(&tp->t_outq, cc);
|
2004-06-04 16:02:56 +00:00
|
|
|
ttyld_start(tp);
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
2005-11-05 17:17:57 +00:00
|
|
|
error:
|
2004-03-01 02:34:49 +00:00
|
|
|
CLR(tp->t_state, TS_BUSY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static usbd_status
|
2004-03-01 02:34:49 +00:00
|
|
|
ubserstartread(struct ubser_softc *sc)
|
|
|
|
{
|
|
|
|
usbd_status err;
|
|
|
|
|
|
|
|
DPRINTF(("ubserstartread: start\n"));
|
|
|
|
|
|
|
|
if (sc->sc_bulkin_pipe == NULL)
|
|
|
|
return (USBD_NORMAL_COMPLETION);
|
|
|
|
|
|
|
|
usbd_setup_xfer(sc->sc_ixfer, sc->sc_bulkin_pipe,
|
|
|
|
(usbd_private_handle)sc,
|
|
|
|
sc->sc_ibuf, sc->sc_ibufsizepad,
|
|
|
|
USBD_SHORT_XFER_OK | USBD_NO_COPY,
|
|
|
|
USBD_NO_TIMEOUT, ubserreadcb);
|
|
|
|
|
|
|
|
err = usbd_transfer(sc->sc_ixfer);
|
|
|
|
if (err != USBD_IN_PROGRESS) {
|
|
|
|
DPRINTF(("ubserstartread: err = %s\n", usbd_errstr(err)));
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (USBD_NORMAL_COMPLETION);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2004-03-01 02:34:49 +00:00
|
|
|
ubserreadcb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
|
|
|
|
{
|
|
|
|
struct ubser_softc *sc = (struct ubser_softc *)p;
|
|
|
|
struct tty *tp;
|
|
|
|
usbd_status err;
|
|
|
|
u_int32_t cc;
|
|
|
|
u_char *cp;
|
|
|
|
int lostcc;
|
2005-11-05 17:17:57 +00:00
|
|
|
|
|
|
|
if (status == USBD_IOERROR) {
|
|
|
|
printf("%s: ubserreadcb: %s - restarting\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), usbd_errstr(status));
|
2005-11-05 17:17:57 +00:00
|
|
|
goto resubmit;
|
|
|
|
}
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
DPRINTF(("ubserreadcb: status = %d\n", status));
|
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
2005-11-05 17:17:57 +00:00
|
|
|
if (status != USBD_CANCELLED) {
|
|
|
|
printf("%s: ubserreadcb: %s\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), usbd_errstr(status));
|
2005-11-05 17:17:57 +00:00
|
|
|
}
|
2004-03-01 02:34:49 +00:00
|
|
|
if (status == USBD_STALLED)
|
|
|
|
usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
usbd_get_xfer_status(xfer, NULL, (void **)&cp, &cc, NULL);
|
|
|
|
|
|
|
|
DPRINTF(("ubserreadcb: got %d bytes from device\n", cc));
|
|
|
|
if (cc == 0)
|
|
|
|
goto resubmit;
|
|
|
|
|
|
|
|
if (cc > sc->sc_ibufsizepad) {
|
|
|
|
printf("%s: invalid receive data size, %d chars\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), cc);
|
2004-03-01 02:34:49 +00:00
|
|
|
goto resubmit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse header */
|
|
|
|
if (cc < 1)
|
|
|
|
goto resubmit;
|
|
|
|
DPRINTF(("ubserreadcb: got %d chars for serial %d\n", cc - 1, *cp));
|
2004-10-12 09:18:37 +00:00
|
|
|
tp = sc->sc_port[*cp].p_tty;
|
2004-03-01 02:34:49 +00:00
|
|
|
cp++;
|
|
|
|
cc--;
|
|
|
|
|
|
|
|
if (cc < 1)
|
|
|
|
goto resubmit;
|
|
|
|
|
|
|
|
if (!(tp->t_state & TS_ISOPEN)) /* drop data for unused serials */
|
|
|
|
goto resubmit;
|
|
|
|
|
|
|
|
if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
|
|
|
|
if (tp->t_rawq.c_cc + cc > tp->t_ihiwat
|
|
|
|
&& (tp->t_iflag & IXOFF)
|
|
|
|
&& !(tp->t_state & TS_TBLOCK))
|
|
|
|
ttyblock(tp);
|
|
|
|
lostcc = b_to_q((char *)cp, cc, &tp->t_rawq);
|
|
|
|
tp->t_rawcc += cc;
|
|
|
|
ttwakeup(tp);
|
|
|
|
if (tp->t_state & TS_TTSTOP
|
|
|
|
&& (tp->t_iflag & IXANY
|
|
|
|
|| tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
|
|
|
|
tp->t_state &= ~TS_TTSTOP;
|
|
|
|
tp->t_lflag &= ~FLUSHO;
|
|
|
|
ubserstart(tp);
|
|
|
|
}
|
|
|
|
if (lostcc > 0)
|
2006-09-07 00:06:42 +00:00
|
|
|
printf("%s: lost %d chars\n", device_get_nameunit(sc->sc_dev),
|
2004-03-01 02:34:49 +00:00
|
|
|
lostcc);
|
|
|
|
} else {
|
|
|
|
/* Give characters to tty layer. */
|
|
|
|
while (cc > 0) {
|
|
|
|
DPRINTFN(7, ("ubserreadcb: char = 0x%02x\n", *cp));
|
2004-06-04 20:04:52 +00:00
|
|
|
if (ttyld_rint(tp, *cp) == -1) {
|
2004-03-01 02:34:49 +00:00
|
|
|
/* XXX what should we do? */
|
|
|
|
printf("%s: lost %d chars\n",
|
2006-09-07 00:06:42 +00:00
|
|
|
device_get_nameunit(sc->sc_dev), cc);
|
2004-03-01 02:34:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
cc--;
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-05 17:17:57 +00:00
|
|
|
resubmit:
|
2004-03-01 02:34:49 +00:00
|
|
|
err = ubserstartread(sc);
|
|
|
|
if (err) {
|
2006-09-07 00:06:42 +00:00
|
|
|
printf("%s: read start failed\n", device_get_nameunit(sc->sc_dev));
|
2004-03-01 02:34:49 +00:00
|
|
|
/* XXX what should we do now? */
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2004-03-01 02:34:49 +00:00
|
|
|
ubser_cleanup(struct ubser_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
DPRINTF(("ubser_cleanup: closing pipes\n"));
|
|
|
|
|
|
|
|
if (sc->sc_bulkin_pipe != NULL) {
|
|
|
|
usbd_abort_pipe(sc->sc_bulkin_pipe);
|
|
|
|
usbd_close_pipe(sc->sc_bulkin_pipe);
|
|
|
|
sc->sc_bulkin_pipe = NULL;
|
|
|
|
}
|
|
|
|
if (sc->sc_bulkout_pipe != NULL) {
|
|
|
|
usbd_abort_pipe(sc->sc_bulkout_pipe);
|
|
|
|
usbd_close_pipe(sc->sc_bulkout_pipe);
|
|
|
|
sc->sc_bulkout_pipe = NULL;
|
|
|
|
}
|
|
|
|
if (sc->sc_ixfer != NULL) {
|
|
|
|
usbd_free_xfer(sc->sc_ixfer);
|
|
|
|
sc->sc_ixfer = NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < sc->sc_numser; i++) {
|
2004-10-12 09:18:37 +00:00
|
|
|
pp = &sc->sc_port[i];
|
|
|
|
if (pp->p_oxfer != NULL) {
|
|
|
|
usbd_free_xfer(pp->p_oxfer);
|
|
|
|
pp->p_oxfer = NULL;
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-10-12 09:18:37 +00:00
|
|
|
ubseropen(struct tty *tp, struct cdev *dev)
|
2004-03-01 02:34:49 +00:00
|
|
|
{
|
|
|
|
struct ubser_softc *sc;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
pp = tp->t_sc;
|
|
|
|
sc = pp->p_sc;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
|
|
|
sc->sc_refcnt++; /* XXX: wrong refcnt on error later on */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
static void
|
|
|
|
ubserclose(struct tty *tp)
|
2004-03-01 02:34:49 +00:00
|
|
|
{
|
|
|
|
struct ubser_softc *sc;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
pp = tp->t_sc;
|
|
|
|
sc = pp->p_sc;
|
2004-03-01 02:34:49 +00:00
|
|
|
if (--sc->sc_refcnt < 0)
|
2007-06-12 16:52:07 +00:00
|
|
|
usb_detach_wakeup(sc->sc_dev);
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
static void
|
|
|
|
ubserbreak(struct tty *tp, int sig)
|
2004-03-01 02:34:49 +00:00
|
|
|
{
|
|
|
|
usb_device_request_t req;
|
|
|
|
struct ubser_softc *sc;
|
2004-10-12 09:18:37 +00:00
|
|
|
struct ubser_port *pp;
|
2004-03-01 02:34:49 +00:00
|
|
|
int error;
|
|
|
|
int alen;
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
pp = tp->t_sc;
|
|
|
|
sc = pp->p_sc;
|
|
|
|
if (sig) {
|
|
|
|
DPRINTF(("ubser_break: TIOCSBRK\n"));
|
2004-03-01 02:34:49 +00:00
|
|
|
req.bmRequestType = UT_READ_VENDOR_INTERFACE;
|
|
|
|
req.bRequest = VENDOR_SET_BREAK;
|
2004-10-12 09:18:37 +00:00
|
|
|
USETW(req.wValue, pp->p_port);
|
2004-03-01 02:34:49 +00:00
|
|
|
USETW(req.wIndex, sc->sc_ifaceno);
|
|
|
|
USETW(req.wLength, 0);
|
|
|
|
error = usbd_do_request_flags(sc->sc_udev, &req, &sc->sc_numser,
|
|
|
|
USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-10-12 09:18:37 +00:00
|
|
|
ubsermodem(struct tty *tp, int sigon, int sigoff)
|
2004-03-01 02:34:49 +00:00
|
|
|
{
|
|
|
|
|
2004-10-12 09:18:37 +00:00
|
|
|
return (SER_DTR | SER_RTS | SER_DCD);
|
2004-03-01 02:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DRIVER_MODULE(ubser, uhub, ubser_driver, ubser_devclass, usbd_driver_load, 0);
|
|
|
|
|