2 * Copyright (c) 2004 Bernd Walter <ticso@freebsd.org>
4 * $URL: https://devel.bwct.de/svn/projects/ubser/ubser.c $
5 * $Date: 2004-02-29 01:53:10 +0100 (Sun, 29 Feb 2004) $
11 * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * Copyright (c) 2000 The NetBSD Foundation, Inc.
38 * All rights reserved.
40 * This code is derived from software contributed to The NetBSD Foundation
41 * by Lennart Augustsson (lennart@augustsson.net).
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the NetBSD
54 * Foundation, Inc. and its contributors.
55 * 4. Neither the name of The NetBSD Foundation nor the names of its
56 * contributors may be used to endorse or promote products derived
57 * from this software without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
60 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
69 * POSSIBILITY OF SUCH DAMAGE.
72 #include <sys/cdefs.h>
73 __FBSDID("$FreeBSD$");
76 * BWCT serial adapter driver
79 #include <sys/cdefs.h>
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #include <sys/kernel.h>
84 #include <sys/module.h>
85 #include <sys/malloc.h>
87 #include <sys/ioccom.h>
88 #include <sys/fcntl.h>
90 #include <sys/serial.h>
92 #include <sys/clist.h>
95 #include <sys/selinfo.h>
97 #include <sys/sysctl.h>
99 #include <dev/usb/usb.h>
100 #include <dev/usb/usbhid.h>
102 #include <dev/usb/usbdi.h>
103 #include <dev/usb/usbdi_util.h>
106 #include <dev/usb/ubser.h>
109 static int ubserdebug = 0;
110 SYSCTL_NODE(_hw_usb, OID_AUTO, ubser, CTLFLAG_RW, 0, "USB ubser");
111 SYSCTL_INT(_hw_usb_ubser, OID_AUTO, debug, CTLFLAG_RW,
112 &ubserdebug, 0, "ubser debug level");
113 #define DPRINTF(x) do { \
118 #define DPRINTFN(n, x) do { \
119 if (ubserdebug > (n)) \
124 #define DPRINTFN(n,x)
127 #define ISSET(t, f) ((t) & (f))
128 #define SET(t, f) (t) |= (f)
129 #define CLR(t, f) (t) &= ~((unsigned)(f))
133 struct ubser_softc *p_sc;
134 usbd_xfer_handle p_oxfer; /* write request */
135 u_char *p_obuf; /* write buffer */
141 usbd_device_handle sc_udev;
142 usbd_interface_handle sc_iface; /* data interface */
151 int sc_bulkin_no; /* bulk in endpoint address */
152 usbd_pipe_handle sc_bulkin_pipe; /* bulk in pipe */
153 usbd_xfer_handle sc_ixfer; /* read request */
154 u_char *sc_ibuf; /* read buffer */
155 u_int sc_ibufsize; /* read buffer size */
156 u_int sc_ibufsizepad; /* read buffer size padded */
158 int sc_bulkout_no; /* bulk out endpoint address */
159 usbd_pipe_handle sc_bulkout_pipe;/* bulk out pipe */
160 u_int sc_obufsize; /* write buffer size */
161 u_int sc_opkthdrlen; /* header length of
164 struct ubser_port *sc_port;
167 static int ubserparam(struct tty *, struct termios *);
168 static void ubserstart(struct tty *);
169 static void ubserstop(struct tty *, int);
170 static usbd_status ubserstartread(struct ubser_softc *);
171 static void ubserreadcb(usbd_xfer_handle, usbd_private_handle, usbd_status);
172 static void ubserwritecb(usbd_xfer_handle, usbd_private_handle, usbd_status);
173 static void ubser_cleanup(struct ubser_softc *sc);
175 static t_break_t ubserbreak;
176 static t_open_t ubseropen;
177 static t_close_t ubserclose;
178 static t_modem_t ubsermodem;
180 static device_probe_t ubser_match;
181 static device_attach_t ubser_attach;
182 static device_detach_t ubser_detach;
184 static device_method_t ubser_methods[] = {
185 /* Device interface */
186 DEVMETHOD(device_probe, ubser_match),
187 DEVMETHOD(device_attach, ubser_attach),
188 DEVMETHOD(device_detach, ubser_detach),
193 static driver_t ubser_driver = {
196 sizeof(struct ubser_softc)
199 static devclass_t ubser_devclass;
202 ubser_match(device_t self)
204 struct usb_attach_arg *uaa = device_get_ivars(self);
205 usb_string_descriptor_t us;
206 usb_interface_descriptor_t *id;
207 usb_device_descriptor_t *dd;
210 if (uaa->iface == NULL)
211 return (UMATCH_NONE);
213 DPRINTFN(20,("ubser: vendor=0x%x, product=0x%x\n",
214 uaa->vendor, uaa->product));
216 dd = usbd_get_device_descriptor(uaa->device);
218 printf("ubser: failed to get device descriptor\n");
219 return (UMATCH_NONE);
222 id = usbd_get_interface_descriptor(uaa->iface);
224 printf("ubser: failed to get interface descriptor\n");
225 return (UMATCH_NONE);
228 err = usbd_get_string_desc(uaa->device, dd->iManufacturer, 0, &us,
231 return (UMATCH_NONE);
233 /* check if this is a BWCT vendor specific ubser interface */
234 if (strcmp((char*)us.bString, "B\0W\0C\0T\0") == 0 &&
235 id->bInterfaceClass == 0xff && id->bInterfaceSubClass == 0x00)
236 return (UMATCH_VENDOR_IFACESUBCLASS);
238 return (UMATCH_NONE);
242 ubser_attach(device_t self)
244 struct ubser_softc *sc = device_get_softc(self);
245 struct usb_attach_arg *uaa = device_get_ivars(self);
246 usbd_device_handle udev = uaa->device;
247 usb_endpoint_descriptor_t *ed;
248 usb_interface_descriptor_t *id;
249 usb_device_request_t req;
255 struct ubser_port *pp;
259 DPRINTFN(10,("\nubser_attach: sc=%p\n", sc));
261 sc->sc_udev = udev = uaa->device;
262 sc->sc_iface = uaa->iface;
266 /* get interface index */
267 id = usbd_get_interface_descriptor(uaa->iface);
269 printf("ubser: failed to get interface descriptor\n");
270 return (UMATCH_NONE);
272 sc->sc_ifaceno = id->bInterfaceNumber;
274 /* get number of serials */
275 req.bmRequestType = UT_READ_VENDOR_INTERFACE;
276 req.bRequest = VENDOR_GET_NUMSER;
277 USETW(req.wValue, 0);
278 USETW(req.wIndex, sc->sc_ifaceno);
279 USETW(req.wLength, 1);
280 err = usbd_do_request_flags(udev, &req, &sc->sc_numser,
281 USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT);
283 device_printf(self, "failed to get number of serials\n");
285 } else if (alen != 1) {
286 device_printf(self, "bogus answer on get_numser\n");
289 if (sc->sc_numser > MAX_SER)
290 sc->sc_numser = MAX_SER;
291 device_printf(self, "found %i serials\n", sc->sc_numser);
293 sc->sc_port = malloc(sizeof(*sc->sc_port) * sc->sc_numser,
296 /* find our bulk endpoints */
298 (void)usbd_endpoint_count(sc->sc_iface, &epcount);
299 sc->sc_bulkin_no = -1;
300 sc->sc_bulkout_no = -1;
301 for (i = 0; i < epcount; i++) {
302 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
304 device_printf(self, "couldn't get ep %d\n", i);
307 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
308 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
309 sc->sc_bulkin_no = ed->bEndpointAddress;
310 sc->sc_ibufsizepad = UGETW(ed->wMaxPacketSize);
311 sc->sc_ibufsizepad = UGETW(ed->wMaxPacketSize) - 1;
312 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
313 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
314 sc->sc_bulkout_no = ed->bEndpointAddress;
315 sc->sc_obufsize = UGETW(ed->wMaxPacketSize) - 1;
316 sc->sc_opkthdrlen = 1;
319 if (sc->sc_bulkin_no == -1 || sc->sc_bulkout_no == -1) {
320 device_printf(self, "could not find bulk in/out endpoint\n");
325 /* Open the bulk pipes */
327 err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin_no, 0,
328 &sc->sc_bulkin_pipe);
330 device_printf(self, "open bulk in error (addr %d): %s\n",
331 sc->sc_bulkin_no, usbd_errstr(err));
335 err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkout_no,
336 USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
338 device_printf(self, "open bulk out error (addr %d): %s\n",
339 sc->sc_bulkout_no, usbd_errstr(err));
343 /* Allocate a request and an input buffer */
344 sc->sc_ixfer = usbd_alloc_xfer(sc->sc_udev);
345 if (sc->sc_ixfer == NULL) {
349 sc->sc_ibuf = usbd_alloc_buffer(sc->sc_ixfer,
351 if (sc->sc_ibuf == NULL) {
355 for (i = 0; i < sc->sc_numser; i++) {
356 pp = &sc->sc_port[i];
359 tp = pp->p_tty = ttyalloc();
361 DPRINTF(("ubser_attach: tty_attach tp = %p\n", tp));
362 tp->t_oproc = ubserstart;
363 tp->t_param = ubserparam;
364 tp->t_stop = ubserstop;
365 tp->t_break = ubserbreak;
366 tp->t_open = ubseropen;
367 tp->t_close = ubserclose;
368 tp->t_modem = ubsermodem;
369 ttycreate(tp, 0, "y%r%r", device_get_unit(sc->sc_dev), i);
373 for (i = 0; i < sc->sc_numser; i++) {
374 sc->sc_port[i].p_oxfer = NULL;
375 sc->sc_port[i].p_obuf = NULL;
377 for (i = 0; i < sc->sc_numser; i++) {
378 sc->sc_port[i].p_oxfer = usbd_alloc_xfer(sc->sc_udev);
379 if (sc->sc_port[i].p_oxfer == NULL) {
383 sc->sc_port[i].p_obuf = usbd_alloc_buffer(sc->sc_port[i].p_oxfer,
386 if (sc->sc_port[i].p_obuf == NULL) {
395 for (i = 0; i < sc->sc_numser; i++) {
396 if (sc->sc_port[i].p_oxfer != NULL) {
397 usbd_free_xfer(sc->sc_port[i].p_oxfer);
398 sc->sc_port[i].p_oxfer = NULL;
402 usbd_free_xfer(sc->sc_ixfer);
405 usbd_close_pipe(sc->sc_bulkout_pipe);
406 sc->sc_bulkout_pipe = NULL;
408 usbd_close_pipe(sc->sc_bulkin_pipe);
409 sc->sc_bulkin_pipe = NULL;
412 wakeup(&sc->sc_opening);
416 if (sc->sc_port != NULL) {
417 for (i = 0; i < sc->sc_numser; i++) {
418 pp = &sc->sc_port[i];
419 if (pp->p_tty != NULL)
422 free(sc->sc_port, M_USBDEV);
426 DPRINTF(("ubser_attach: ATTACH ERROR\n"));
431 ubser_detach(device_t self)
433 struct ubser_softc *sc = device_get_softc(self);
435 struct ubser_port *pp;
437 DPRINTF(("ubser_detach: sc=%p\n", sc));
440 for (i = 0; i < sc->sc_numser; i++) {
441 pp = &sc->sc_port[i];
442 if (pp->p_tty != NULL)
446 if (sc->sc_bulkin_pipe != NULL)
447 usbd_abort_pipe(sc->sc_bulkin_pipe);
448 if (sc->sc_bulkout_pipe != NULL)
449 usbd_abort_pipe(sc->sc_bulkout_pipe);
451 if (sc->sc_port != NULL) {
452 for (i = 0; i < sc->sc_numser; i++) {
453 pp = &sc->sc_port[i];
454 if (pp->p_tty != NULL)
457 free(sc->sc_port, M_USBDEV);
461 if (--sc->sc_refcnt >= 0) {
462 /* Wait for processes to go away. */
463 usb_detach_wait(sc->sc_dev);
470 ubserparam(struct tty *tp, struct termios *t)
472 struct ubser_softc *sc;
473 struct ubser_port *pp;
481 DPRINTF(("ubserparam: sc = %p\n", sc));
484 * The firmware on our devices can only do 8n1@9600bps
486 * We refuse to accept other configurations.
489 /* enshure 9600bps */
490 switch (t->c_ospeed) {
497 /* 2 stop bits not possible */
498 if (ISSET(t->c_cflag, CSTOPB))
501 /* XXX parity handling not possible with current firmware */
502 if (ISSET(t->c_cflag, PARENB))
505 /* we can only do 8 data bits */
506 switch (ISSET(t->c_cflag, CSIZE)) {
513 /* we can't do any kind of hardware handshaking */
515 (CRTS_IFLOW | CDTR_IFLOW |CDSR_OFLOW |CCAR_OFLOW)) != 0)
519 * XXX xon/xoff not supported by the firmware!
520 * This is handled within FreeBSD only and may overflow buffers
521 * because of delayed reaction due to device buffering.
530 ubserstart(struct tty *tp)
532 struct ubser_softc *sc;
533 struct ubser_port *pp;
543 DPRINTF(("ubserstart: sc = %p, tp = %p\n", sc, tp));
548 if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP)) {
550 DPRINTF(("ubserstart: stopped\n"));
554 if (tp->t_outq.c_cc <= tp->t_olowat) {
555 if (ISSET(tp->t_state, TS_SO_OLOWAT)) {
556 CLR(tp->t_state, TS_SO_OLOWAT);
557 wakeup(TSA_OLOWAT(tp));
559 selwakeuppri(&tp->t_wsel, TTIPRI);
560 if (tp->t_outq.c_cc == 0) {
561 if (ISSET(tp->t_state, TS_BUSY | TS_SO_OCOMPLETE) ==
562 TS_SO_OCOMPLETE && tp->t_outq.c_cc == 0) {
563 CLR(tp->t_state, TS_SO_OCOMPLETE);
564 wakeup(TSA_OCOMPLETE(tp));
570 /* Grab the first contiguous region of buffer space. */
571 data = tp->t_outq.c_cf;
572 cbp = (struct cblock *) ((intptr_t) tp->t_outq.c_cf & ~CROUND);
573 cnt = min((char *) (cbp+1) - tp->t_outq.c_cf, tp->t_outq.c_cc);
576 DPRINTF(("ubserstart: cnt == 0\n"));
580 SET(tp->t_state, TS_BUSY);
582 if (cnt + sc->sc_opkthdrlen > sc->sc_obufsize) {
583 DPRINTF(("ubserstart: big buffer %d chars\n", cnt));
584 cnt = sc->sc_obufsize;
586 sc->sc_port[serial].p_obuf[0] = serial;
587 memcpy(sc->sc_port[serial].p_obuf + sc->sc_opkthdrlen, data, cnt);
590 DPRINTF(("ubserstart: %d chars\n", cnt));
591 usbd_setup_xfer(sc->sc_port[serial].p_oxfer, sc->sc_bulkout_pipe,
592 (usbd_private_handle)tp, sc->sc_port[serial].p_obuf,
593 cnt + sc->sc_opkthdrlen,
594 USBD_NO_COPY, USBD_NO_TIMEOUT, ubserwritecb);
595 /* What can we do on error? */
596 err = usbd_transfer(sc->sc_port[serial].p_oxfer);
597 if (err != USBD_IN_PROGRESS)
598 printf("ubserstart: err=%s\n", usbd_errstr(err));
604 ubserstop(struct tty *tp, int flag)
606 struct ubser_softc *sc;
610 DPRINTF(("ubserstop: %d\n", flag));
613 DPRINTF(("ubserstop: write\n"));
614 if (ISSET(tp->t_state, TS_BUSY)) {
616 if (!ISSET(tp->t_state, TS_TTSTOP))
617 SET(tp->t_state, TS_FLUSH);
621 DPRINTF(("ubserstop: done\n"));
625 ubserwritecb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
628 struct ubser_softc *sc;
629 struct ubser_port *pp;
632 tp = (struct tty *)p;
636 DPRINTF(("ubserwritecb: status = %d\n", status));
638 if (status == USBD_CANCELLED || sc->sc_dying)
641 if (status != USBD_NORMAL_COMPLETION) {
642 device_printf(sc->sc_dev, "ubserwritecb: %s\n",
643 usbd_errstr(status));
644 if (status == USBD_STALLED)
645 usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
646 /* XXX we should restart after some delay. */
650 usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
651 DPRINTF(("ubserwritecb: cc = %d\n", cc));
652 if (cc <= sc->sc_opkthdrlen) {
653 device_printf(sc->sc_dev, "sent size too small, cc = %d\n",
658 /* convert from USB bytes to tty bytes */
659 cc -= sc->sc_opkthdrlen;
661 CLR(tp->t_state, TS_BUSY);
662 if (ISSET(tp->t_state, TS_FLUSH))
663 CLR(tp->t_state, TS_FLUSH);
665 ndflush(&tp->t_outq, cc);
671 CLR(tp->t_state, TS_BUSY);
676 ubserstartread(struct ubser_softc *sc)
680 DPRINTF(("ubserstartread: start\n"));
682 if (sc->sc_bulkin_pipe == NULL)
683 return (USBD_NORMAL_COMPLETION);
685 usbd_setup_xfer(sc->sc_ixfer, sc->sc_bulkin_pipe,
686 (usbd_private_handle)sc,
687 sc->sc_ibuf, sc->sc_ibufsizepad,
688 USBD_SHORT_XFER_OK | USBD_NO_COPY,
689 USBD_NO_TIMEOUT, ubserreadcb);
691 err = usbd_transfer(sc->sc_ixfer);
692 if (err != USBD_IN_PROGRESS) {
693 DPRINTF(("ubserstartread: err = %s\n", usbd_errstr(err)));
697 return (USBD_NORMAL_COMPLETION);
701 ubserreadcb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
703 struct ubser_softc *sc = (struct ubser_softc *)p;
710 if (status == USBD_IOERROR) {
711 device_printf(sc->sc_dev, "ubserreadcb: %s - restarting\n",
712 usbd_errstr(status));
716 DPRINTF(("ubserreadcb: status = %d\n", status));
718 if (status != USBD_NORMAL_COMPLETION) {
719 if (status != USBD_CANCELLED) {
720 device_printf(sc->sc_dev, "ubserreadcb: %s\n",
721 usbd_errstr(status));
723 if (status == USBD_STALLED)
724 usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
728 usbd_get_xfer_status(xfer, NULL, (void **)&cp, &cc, NULL);
730 DPRINTF(("ubserreadcb: got %d bytes from device\n", cc));
734 if (cc > sc->sc_ibufsizepad) {
735 device_printf(sc->sc_dev, "invalid receive data size, %d chars\n",
743 DPRINTF(("ubserreadcb: got %d chars for serial %d\n", cc - 1, *cp));
744 tp = sc->sc_port[*cp].p_tty;
751 if (!(tp->t_state & TS_ISOPEN)) /* drop data for unused serials */
754 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
755 if (tp->t_rawq.c_cc + cc > tp->t_ihiwat
756 && (tp->t_iflag & IXOFF)
757 && !(tp->t_state & TS_TBLOCK))
759 lostcc = b_to_q((char *)cp, cc, &tp->t_rawq);
762 if (tp->t_state & TS_TTSTOP
763 && (tp->t_iflag & IXANY
764 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
765 tp->t_state &= ~TS_TTSTOP;
766 tp->t_lflag &= ~FLUSHO;
770 device_printf(sc->sc_dev, "lost %d chars\n", lostcc);
772 /* Give characters to tty layer. */
774 DPRINTFN(7, ("ubserreadcb: char = 0x%02x\n", *cp));
775 if (ttyld_rint(tp, *cp) == -1) {
776 /* XXX what should we do? */
777 device_printf(sc->sc_dev, "lost %d chars\n",
787 err = ubserstartread(sc);
789 device_printf(sc->sc_dev, "read start failed\n");
790 /* XXX what should we do now? */
796 ubser_cleanup(struct ubser_softc *sc)
799 struct ubser_port *pp;
801 DPRINTF(("ubser_cleanup: closing pipes\n"));
803 if (sc->sc_bulkin_pipe != NULL) {
804 usbd_abort_pipe(sc->sc_bulkin_pipe);
805 usbd_close_pipe(sc->sc_bulkin_pipe);
806 sc->sc_bulkin_pipe = NULL;
808 if (sc->sc_bulkout_pipe != NULL) {
809 usbd_abort_pipe(sc->sc_bulkout_pipe);
810 usbd_close_pipe(sc->sc_bulkout_pipe);
811 sc->sc_bulkout_pipe = NULL;
813 if (sc->sc_ixfer != NULL) {
814 usbd_free_xfer(sc->sc_ixfer);
817 for (i = 0; i < sc->sc_numser; i++) {
818 pp = &sc->sc_port[i];
819 if (pp->p_oxfer != NULL) {
820 usbd_free_xfer(pp->p_oxfer);
827 ubseropen(struct tty *tp, struct cdev *dev)
829 struct ubser_softc *sc;
830 struct ubser_port *pp;
835 sc->sc_refcnt++; /* XXX: wrong refcnt on error later on */
840 ubserclose(struct tty *tp)
842 struct ubser_softc *sc;
843 struct ubser_port *pp;
847 if (--sc->sc_refcnt < 0)
848 usb_detach_wakeup(sc->sc_dev);
852 ubserbreak(struct tty *tp, int sig)
854 usb_device_request_t req;
855 struct ubser_softc *sc;
856 struct ubser_port *pp;
863 DPRINTF(("ubser_break: TIOCSBRK\n"));
864 req.bmRequestType = UT_READ_VENDOR_INTERFACE;
865 req.bRequest = VENDOR_SET_BREAK;
866 USETW(req.wValue, pp->p_port);
867 USETW(req.wIndex, sc->sc_ifaceno);
868 USETW(req.wLength, 0);
869 error = usbd_do_request_flags(sc->sc_udev, &req, &sc->sc_numser,
870 USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT);
875 ubsermodem(struct tty *tp, int sigon, int sigoff)
878 return (SER_DTR | SER_RTS | SER_DCD);
881 MODULE_DEPEND(ubser, usb, 1, 1, 1);
882 DRIVER_MODULE(ubser, uhub, ubser_driver, ubser_devclass, usbd_driver_load, 0);