umct.c revision 1.32.22.1 1 /* $NetBSD: umct.c,v 1.32.22.1 2017/04/05 19:54:20 snj Exp $ */
2 /*
3 * Copyright (c) 2001 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /*
32 * MCT USB-RS232 Interface Controller
33 * http://www.mct.com.tw/prod/rs232.html
34 * http://www.dlink.com/products/usb/dsbs25
35 */
36
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: umct.c,v 1.32.22.1 2017/04/05 19:54:20 snj Exp $");
39
40 #ifdef _KERNEL_OPT
41 #include "opt_usb.h"
42 #endif
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/ioctl.h>
48 #include <sys/conf.h>
49 #include <sys/tty.h>
50 #include <sys/file.h>
51 #include <sys/select.h>
52 #include <sys/proc.h>
53 #include <sys/vnode.h>
54 #include <sys/device.h>
55 #include <sys/poll.h>
56
57 #include <dev/usb/usb.h>
58 #include <dev/usb/usbcdc.h>
59
60 #include <dev/usb/usbdi.h>
61 #include <dev/usb/usbdi_util.h>
62 #include <dev/usb/usbdevs.h>
63 #include <dev/usb/usb_quirks.h>
64
65 #include <dev/usb/ucomvar.h>
66 #include <dev/usb/umct.h>
67
68 #ifdef UMCT_DEBUG
69 #define DPRINTFN(n, x) if (umctdebug > (n)) printf x
70 int umctdebug = 0;
71 #else
72 #define DPRINTFN(n, x)
73 #endif
74 #define DPRINTF(x) DPRINTFN(0, x)
75
76 #define UMCT_CONFIG_INDEX 0
77 #define UMCT_IFACE_INDEX 0
78
79 struct umct_softc {
80 device_t sc_dev; /* base device */
81 struct usbd_device *sc_udev; /* USB device */
82 struct usbd_interface *sc_iface; /* interface */
83 int sc_iface_number; /* interface number */
84 uint16_t sc_product;
85
86 int sc_inendpt; /* data in endpoint */
87 struct usbd_pipe *sc_inpipe; /* data in pipe */
88 u_char *sc_inbuf; /* interrupt buffer */
89
90 int sc_intr_number; /* interrupt number */
91 struct usbd_pipe *sc_intr_pipe; /* interrupt pipe */
92 u_char *sc_intr_buf; /* interrupt buffer */
93 int sc_isize;
94
95 usb_cdc_line_state_t sc_line_state; /* current line state */
96 u_char sc_dtr; /* current DTR state */
97 u_char sc_rts; /* current RTS state */
98 u_char sc_break; /* set break */
99
100 u_char sc_status;
101
102 device_t sc_subdev; /* ucom device */
103
104 u_char sc_dying; /* disconnecting */
105
106 u_char sc_lsr; /* Local status register */
107 u_char sc_msr; /* umct status register */
108
109 u_int last_lcr; /* keep lcr register */
110 };
111
112 /*
113 * These are the maximum number of bytes transferred per frame.
114 * The output buffer size cannot be increased due to the size encoding.
115 */
116 #define UMCTIBUFSIZE 256
117 #define UMCTOBUFSIZE 256
118
119 Static void umct_init(struct umct_softc *);
120 Static void umct_set_baudrate(struct umct_softc *, u_int);
121 Static void umct_set_lcr(struct umct_softc *, u_int);
122 Static void umct_intr(struct usbd_xfer *, void *, usbd_status);
123
124 Static void umct_rxintr(struct usbd_xfer *, void *, usbd_status);
125
126 Static void umct_set(void *, int, int, int);
127 Static void umct_dtr(struct umct_softc *, int);
128 Static void umct_rts(struct umct_softc *, int);
129 Static void umct_break(struct umct_softc *, int);
130 Static void umct_set_line_state(struct umct_softc *);
131 Static void umct_get_status(void *, int, u_char *, u_char *);
132 Static int umct_param(void *, int, struct termios *);
133 Static int umct_open(void *, int);
134 Static void umct_close(void *, int);
135
136 struct ucom_methods umct_methods = {
137 .ucom_get_status = umct_get_status,
138 .ucom_set = umct_set,
139 .ucom_param = umct_param,
140 .ucom_ioctl = NULL,
141 .ucom_open = umct_open,
142 .ucom_close = umct_close,
143 .ucom_read = NULL,
144 .ucom_write = NULL,
145 };
146
147 static const struct usb_devno umct_devs[] = {
148 /* MCT USB-232 Interface Products */
149 { USB_VENDOR_MCT, USB_PRODUCT_MCT_USB232 },
150 /* Sitecom USB-232 Products */
151 { USB_VENDOR_MCT, USB_PRODUCT_MCT_SITECOM_USB232 },
152 /* D-Link DU-H3SP USB BAY Hub Products */
153 { USB_VENDOR_MCT, USB_PRODUCT_MCT_DU_H3SP_USB232 },
154 /* BELKIN F5U109 */
155 { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U109 },
156 };
157 #define umct_lookup(v, p) usb_lookup(umct_devs, v, p)
158
159 int umct_match(device_t, cfdata_t, void *);
160 void umct_attach(device_t, device_t, void *);
161 void umct_childdet(device_t, device_t);
162 int umct_detach(device_t, int);
163 int umct_activate(device_t, enum devact);
164 extern struct cfdriver umct_cd;
165 CFATTACH_DECL2_NEW(umct, sizeof(struct umct_softc), umct_match,
166 umct_attach, umct_detach, umct_activate, NULL, umct_childdet);
167
168 int
169 umct_match(device_t parent, cfdata_t match, void *aux)
170 {
171 struct usb_attach_arg *uaa = aux;
172
173 return umct_lookup(uaa->uaa_vendor, uaa->uaa_product) != NULL ?
174 UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
175 }
176
177 void
178 umct_attach(device_t parent, device_t self, void *aux)
179 {
180 struct umct_softc *sc = device_private(self);
181 struct usb_attach_arg *uaa = aux;
182 struct usbd_device *dev = uaa->uaa_device;
183 usb_config_descriptor_t *cdesc;
184 usb_interface_descriptor_t *id;
185 usb_endpoint_descriptor_t *ed;
186
187 char *devinfop;
188 usbd_status err;
189 int i;
190 struct ucom_attach_args ucaa;
191
192 sc->sc_dev = self;
193
194 aprint_naive("\n");
195 aprint_normal("\n");
196
197 devinfop = usbd_devinfo_alloc(dev, 0);
198 aprint_normal_dev(self, "%s\n", devinfop);
199 usbd_devinfo_free(devinfop);
200
201 sc->sc_udev = dev;
202 sc->sc_product = uaa->uaa_product;
203
204 DPRINTF(("\n\numct attach: sc=%p\n", sc));
205
206 /* initialize endpoints */
207 ucaa.ucaa_bulkin = ucaa.ucaa_bulkout = -1;
208 sc->sc_intr_number = -1;
209 sc->sc_intr_pipe = NULL;
210
211 /* Move the device into the configured state. */
212 err = usbd_set_config_index(dev, UMCT_CONFIG_INDEX, 1);
213 if (err) {
214 aprint_error_dev(self, "failed to set configuration, err=%s\n",
215 usbd_errstr(err));
216 sc->sc_dying = 1;
217 return;
218 }
219
220 /* get the config descriptor */
221 cdesc = usbd_get_config_descriptor(sc->sc_udev);
222
223 if (cdesc == NULL) {
224 aprint_error_dev(self,
225 "failed to get configuration descriptor\n");
226 sc->sc_dying = 1;
227 return;
228 }
229
230 /* get the interface */
231 err = usbd_device2interface_handle(dev, UMCT_IFACE_INDEX,
232 &sc->sc_iface);
233 if (err) {
234 aprint_error_dev(self, "failed to get interface, err=%s\n",
235 usbd_errstr(err));
236 sc->sc_dying = 1;
237 return;
238 }
239
240 /* Find the bulk{in,out} and interrupt endpoints */
241
242 id = usbd_get_interface_descriptor(sc->sc_iface);
243 sc->sc_iface_number = id->bInterfaceNumber;
244
245 for (i = 0; i < id->bNumEndpoints; i++) {
246 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
247 if (ed == NULL) {
248 aprint_error_dev(self,
249 "no endpoint descriptor for %d\n", i);
250 sc->sc_dying = 1;
251 return;
252 }
253
254 /*
255 * Input is done via an interrupt endpoint, so we handle
256 * the pipe and pass RX characters up to ucom. Since
257 * we can't rely on the endpoint descriptor order, we'll
258 * check the wMaxPacketSize field to differentiate.
259 */
260 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
261 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT &&
262 UGETW(ed->wMaxPacketSize) != 0x2) {
263 sc->sc_inendpt = ed->bEndpointAddress;
264 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
265 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
266 ucaa.ucaa_bulkout = ed->bEndpointAddress;
267 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
268 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
269 sc->sc_intr_number = ed->bEndpointAddress;
270 sc->sc_isize = UGETW(ed->wMaxPacketSize);
271 }
272 }
273
274 if (sc->sc_inendpt == -1) {
275 aprint_error_dev(self, "Could not find data in\n");
276 sc->sc_dying = 1;
277 return;
278 }
279
280 if (ucaa.ucaa_bulkout == -1) {
281 aprint_error_dev(self, "Could not find data bulk out\n");
282 sc->sc_dying = 1;
283 return;
284 }
285
286 if (sc->sc_intr_number == -1) {
287 aprint_error_dev(self, "Could not find interrupt in\n");
288 sc->sc_dying = 1;
289 return;
290 }
291
292 sc->sc_dtr = sc->sc_rts = 0;
293 ucaa.ucaa_portno = UCOM_UNK_PORTNO;
294 /* ucaa_bulkin, ucaa_bulkout set above */
295 ucaa.ucaa_ibufsize = UMCTIBUFSIZE;
296 if (sc->sc_product == USB_PRODUCT_MCT_SITECOM_USB232)
297 ucaa.ucaa_obufsize = 16; /* device is broken */
298 else
299 ucaa.ucaa_obufsize = UMCTOBUFSIZE;
300 ucaa.ucaa_ibufsizepad = UMCTIBUFSIZE;
301 ucaa.ucaa_opkthdrlen = 0;
302 ucaa.ucaa_device = dev;
303 ucaa.ucaa_iface = sc->sc_iface;
304 ucaa.ucaa_methods = &umct_methods;
305 ucaa.ucaa_arg = sc;
306 ucaa.ucaa_info = NULL;
307
308 umct_init(sc);
309
310 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
311
312 DPRINTF(("umct: in=0x%x out=0x%x intr=0x%x\n",
313 ucaa.ucaa_bulkin, ucaa.ucaa_bulkout, sc->sc_intr_number));
314 sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, &ucaa,
315 ucomprint, ucomsubmatch);
316
317 return;
318 }
319
320 void
321 umct_childdet(device_t self, device_t child)
322 {
323 struct umct_softc *sc = device_private(self);
324
325 KASSERT(sc->sc_subdev == child);
326 sc->sc_subdev = NULL;
327 }
328
329 int
330 umct_detach(device_t self, int flags)
331 {
332 struct umct_softc *sc = device_private(self);
333 int rv = 0;
334
335 DPRINTF(("umct_detach: sc=%p flags=%d\n", sc, flags));
336
337 if (sc->sc_intr_pipe != NULL) {
338 usbd_abort_pipe(sc->sc_intr_pipe);
339 usbd_close_pipe(sc->sc_intr_pipe);
340 kmem_free(sc->sc_intr_buf, sc->sc_isize);
341 sc->sc_intr_pipe = NULL;
342 }
343
344 sc->sc_dying = 1;
345 if (sc->sc_subdev != NULL)
346 rv = config_detach(sc->sc_subdev, flags);
347
348 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
349
350 return rv;
351 }
352
353 int
354 umct_activate(device_t self, enum devact act)
355 {
356 struct umct_softc *sc = device_private(self);
357
358 switch (act) {
359 case DVACT_DEACTIVATE:
360 sc->sc_dying = 1;
361 return 0;
362 default:
363 return EOPNOTSUPP;
364 }
365 }
366
367 void
368 umct_set_line_state(struct umct_softc *sc)
369 {
370 usb_device_request_t req;
371 uByte ls;
372
373 ls = (sc->sc_dtr ? MCR_DTR : 0) |
374 (sc->sc_rts ? MCR_RTS : 0);
375
376 DPRINTF(("umct_set_line_state: DTR=%d,RTS=%d,ls=%02x\n",
377 sc->sc_dtr, sc->sc_rts, ls));
378
379 req.bmRequestType = UMCT_SET_REQUEST;
380 req.bRequest = REQ_SET_MCR;
381 USETW(req.wValue, 0);
382 USETW(req.wIndex, sc->sc_iface_number);
383 USETW(req.wLength, LENGTH_SET_MCR);
384
385 (void)usbd_do_request(sc->sc_udev, &req, &ls);
386 }
387
388 void
389 umct_set(void *addr, int portno, int reg, int onoff)
390 {
391 struct umct_softc *sc = addr;
392
393 switch (reg) {
394 case UCOM_SET_DTR:
395 umct_dtr(sc, onoff);
396 break;
397 case UCOM_SET_RTS:
398 umct_rts(sc, onoff);
399 break;
400 case UCOM_SET_BREAK:
401 umct_break(sc, onoff);
402 break;
403 default:
404 break;
405 }
406 }
407
408 void
409 umct_dtr(struct umct_softc *sc, int onoff)
410 {
411
412 DPRINTF(("umct_dtr: onoff=%d\n", onoff));
413
414 if (sc->sc_dtr == onoff)
415 return;
416 sc->sc_dtr = onoff;
417
418 umct_set_line_state(sc);
419 }
420
421 void
422 umct_rts(struct umct_softc *sc, int onoff)
423 {
424 DPRINTF(("umct_rts: onoff=%d\n", onoff));
425
426 if (sc->sc_rts == onoff)
427 return;
428 sc->sc_rts = onoff;
429
430 umct_set_line_state(sc);
431 }
432
433 void
434 umct_break(struct umct_softc *sc, int onoff)
435 {
436 DPRINTF(("umct_break: onoff=%d\n", onoff));
437
438 umct_set_lcr(sc, onoff ? sc->last_lcr | LCR_SET_BREAK :
439 sc->last_lcr);
440 }
441
442 void
443 umct_set_lcr(struct umct_softc *sc, u_int data)
444 {
445 usb_device_request_t req;
446 uByte adata;
447
448 adata = data;
449 req.bmRequestType = UMCT_SET_REQUEST;
450 req.bRequest = REQ_SET_LCR;
451 USETW(req.wValue, 0);
452 USETW(req.wIndex, sc->sc_iface_number);
453 USETW(req.wLength, LENGTH_SET_LCR);
454
455 (void)usbd_do_request(sc->sc_udev, &req, &adata); /* XXX should check */
456 }
457
458 void
459 umct_set_baudrate(struct umct_softc *sc, u_int rate)
460 {
461 usb_device_request_t req;
462 uDWord arate;
463 u_int val;
464
465 if (sc->sc_product == USB_PRODUCT_MCT_SITECOM_USB232 ||
466 sc->sc_product == USB_PRODUCT_BELKIN_F5U109) {
467 switch (rate) {
468 case 300: val = 0x01; break;
469 case 600: val = 0x02; break;
470 case 1200: val = 0x03; break;
471 case 2400: val = 0x04; break;
472 case 4800: val = 0x06; break;
473 case 9600: val = 0x08; break;
474 case 19200: val = 0x09; break;
475 case 38400: val = 0x0a; break;
476 case 57600: val = 0x0b; break;
477 case 115200: val = 0x0c; break;
478 default: val = -1; break;
479 }
480 } else {
481 val = UMCT_BAUD_RATE(rate);
482 }
483 USETDW(arate, val);
484
485 req.bmRequestType = UMCT_SET_REQUEST;
486 req.bRequest = REQ_SET_BAUD_RATE;
487 USETW(req.wValue, 0);
488 USETW(req.wIndex, sc->sc_iface_number);
489 USETW(req.wLength, LENGTH_BAUD_RATE);
490
491 (void)usbd_do_request(sc->sc_udev, &req, arate); /* XXX should check */
492 }
493
494 void
495 umct_init(struct umct_softc *sc)
496 {
497 umct_set_baudrate(sc, 9600);
498 umct_set_lcr(sc, LCR_DATA_BITS_8 | LCR_PARITY_NONE | LCR_STOP_BITS_1);
499 }
500
501 int
502 umct_param(void *addr, int portno, struct termios *t)
503 {
504 struct umct_softc *sc = addr;
505 u_int data = 0;
506
507 DPRINTF(("umct_param: sc=%p\n", sc));
508
509 DPRINTF(("umct_param: BAUDRATE=%d\n", t->c_ospeed));
510
511 if (ISSET(t->c_cflag, CSTOPB))
512 data |= LCR_STOP_BITS_2;
513 else
514 data |= LCR_STOP_BITS_1;
515 if (ISSET(t->c_cflag, PARENB)) {
516 if (ISSET(t->c_cflag, PARODD))
517 data |= LCR_PARITY_ODD;
518 else
519 data |= LCR_PARITY_EVEN;
520 } else
521 data |= LCR_PARITY_NONE;
522 switch (ISSET(t->c_cflag, CSIZE)) {
523 case CS5:
524 data |= LCR_DATA_BITS_5;
525 break;
526 case CS6:
527 data |= LCR_DATA_BITS_6;
528 break;
529 case CS7:
530 data |= LCR_DATA_BITS_7;
531 break;
532 case CS8:
533 data |= LCR_DATA_BITS_8;
534 break;
535 }
536
537 umct_set_baudrate(sc, t->c_ospeed);
538
539 sc->last_lcr = data;
540 umct_set_lcr(sc, data);
541
542 return 0;
543 }
544
545 int
546 umct_open(void *addr, int portno)
547 {
548 struct umct_softc *sc = addr;
549 int err, lcr_data;
550
551 if (sc->sc_dying)
552 return EIO;
553
554 DPRINTF(("umct_open: sc=%p\n", sc));
555
556 /* initialize LCR */
557 lcr_data = LCR_DATA_BITS_8 | LCR_PARITY_NONE |
558 LCR_STOP_BITS_1;
559 umct_set_lcr(sc, lcr_data);
560
561 if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
562 sc->sc_status = 0; /* clear status bit */
563 sc->sc_intr_buf = kmem_alloc(sc->sc_isize, KM_SLEEP);
564 err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_intr_number,
565 USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc,
566 sc->sc_intr_buf, sc->sc_isize,
567 umct_intr, USBD_DEFAULT_INTERVAL);
568 if (err) {
569 DPRINTF(("%s: cannot open interrupt pipe (%d)\n",
570 device_xname(sc->sc_dev), sc->sc_intr_number));
571 return EIO;
572 }
573 }
574 if (sc->sc_inendpt != -1 && sc->sc_inpipe == NULL) {
575 sc->sc_inbuf = kmem_alloc(UMCTIBUFSIZE, KM_SLEEP);
576 err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_inendpt,
577 USBD_SHORT_XFER_OK, &sc->sc_inpipe, sc, sc->sc_inbuf,
578 UMCTIBUFSIZE, umct_rxintr, USBD_DEFAULT_INTERVAL);
579 if (err) {
580 DPRINTF(("%s: cannot open rx interrupt pipe (%d)\n",
581 device_xname(sc->sc_dev), sc->sc_inendpt));
582 return EIO;
583 }
584 }
585
586 return 0;
587 }
588
589 void
590 umct_close(void *addr, int portno)
591 {
592 struct umct_softc *sc = addr;
593 int err;
594
595 if (sc->sc_dying)
596 return;
597
598 DPRINTF(("umct_close: close\n"));
599
600 if (sc->sc_intr_pipe != NULL) {
601 err = usbd_abort_pipe(sc->sc_intr_pipe);
602 if (err)
603 printf("%s: abort interrupt pipe failed: %s\n",
604 device_xname(sc->sc_dev), usbd_errstr(err));
605 err = usbd_close_pipe(sc->sc_intr_pipe);
606 if (err)
607 printf("%s: close interrupt pipe failed: %s\n",
608 device_xname(sc->sc_dev), usbd_errstr(err));
609 kmem_free(sc->sc_intr_buf, sc->sc_isize);
610 sc->sc_intr_pipe = NULL;
611 }
612 if (sc->sc_inpipe != NULL) {
613 err = usbd_abort_pipe(sc->sc_inpipe);
614 if (err)
615 printf("%s: abort rx interrupt pipe failed: %s\n",
616 device_xname(sc->sc_dev), usbd_errstr(err));
617 err = usbd_close_pipe(sc->sc_inpipe);
618 if (err)
619 printf("%s: close rx interrupt pipe failed: %s\n",
620 device_xname(sc->sc_dev), usbd_errstr(err));
621 kmem_free(sc->sc_inbuf, UMCTIBUFSIZE);
622 sc->sc_inpipe = NULL;
623 }
624 }
625
626 void
627 umct_rxintr(struct usbd_xfer *xfer, void *priv, usbd_status status)
628 {
629 struct umct_softc *sc = priv;
630
631 if (sc->sc_dying)
632 return;
633
634 ucomreadcb(xfer, device_private(sc->sc_subdev), status);
635 }
636
637 void
638 umct_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
639 {
640 struct umct_softc *sc = priv;
641 u_char *tbuf = sc->sc_intr_buf;
642 u_char mstatus;
643
644 if (sc->sc_dying)
645 return;
646
647 if (status != USBD_NORMAL_COMPLETION) {
648 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
649 return;
650
651 DPRINTF(("%s: abnormal status: %s\n", device_xname(sc->sc_dev),
652 usbd_errstr(status)));
653 usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
654 return;
655 }
656
657 DPRINTF(("%s: umct status = MSR:%02x, LSR:%02x\n",
658 device_xname(sc->sc_dev), tbuf[0],tbuf[1]));
659
660 sc->sc_lsr = sc->sc_msr = 0;
661 mstatus = tbuf[0];
662 if (ISSET(mstatus, MSR_DSR))
663 sc->sc_msr |= UMSR_DSR;
664 if (ISSET(mstatus, MSR_DCD))
665 sc->sc_msr |= UMSR_DCD;
666 ucom_status_change(device_private(sc->sc_subdev));
667 }
668
669 void
670 umct_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
671 {
672 struct umct_softc *sc = addr;
673
674 DPRINTF(("umct_get_status:\n"));
675
676 if (lsr != NULL)
677 *lsr = sc->sc_lsr;
678 if (msr != NULL)
679 *msr = sc->sc_msr;
680 }
681