1 /* $NetBSD: umodem.c,v 1.45 2002/09/23 05:51:23 simonb Exp $ */
7 * Copyright (c) 2003, M. Warner Losh <imp@FreeBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 1998 The NetBSD Foundation, Inc.
34 * All rights reserved.
36 * This code is derived from software contributed to The NetBSD Foundation
37 * by Lennart Augustsson (lennart@augustsson.net) at
38 * Carlstedt Research & Technology.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the NetBSD
51 * Foundation, Inc. and its contributors.
52 * 4. Neither the name of The NetBSD Foundation nor the names of its
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
57 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
58 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
60 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
66 * POSSIBILITY OF SUCH DAMAGE.
70 * Comm Class spec: http://www.usb.org/developers/devclass_docs/usbccs10.pdf
71 * http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
72 * http://www.usb.org/developers/devclass_docs/cdc_wmc10.zip
77 * - Add error recovery in various places; the big problem is what
78 * to do in a callback if there is an error.
79 * - Implement a Call Device for modems without multiplexed commands.
83 #include <sys/stdint.h>
84 #include <sys/stddef.h>
85 #include <sys/param.h>
86 #include <sys/queue.h>
87 #include <sys/types.h>
88 #include <sys/systm.h>
89 #include <sys/kernel.h>
91 #include <sys/linker_set.h>
92 #include <sys/module.h>
94 #include <sys/mutex.h>
95 #include <sys/condvar.h>
96 #include <sys/sysctl.h>
98 #include <sys/unistd.h>
99 #include <sys/callout.h>
100 #include <sys/malloc.h>
101 #include <sys/priv.h>
103 #include <dev/usb/usb.h>
104 #include <dev/usb/usbdi.h>
105 #include <dev/usb/usbdi_util.h>
106 #include <dev/usb/usbhid.h>
107 #include <dev/usb/usb_cdc.h>
110 #include <dev/usb/usb_ioctl.h>
112 #define USB_DEBUG_VAR umodem_debug
113 #include <dev/usb/usb_debug.h>
114 #include <dev/usb/usb_process.h>
115 #include <dev/usb/quirk/usb_quirk.h>
117 #include <dev/usb/serial/usb_serial.h>
120 static int umodem_debug = 0;
122 SYSCTL_NODE(_hw_usb, OID_AUTO, umodem, CTLFLAG_RW, 0, "USB umodem");
123 SYSCTL_INT(_hw_usb_umodem, OID_AUTO, debug, CTLFLAG_RW,
124 &umodem_debug, 0, "Debug level");
127 static const struct usb_device_id umodem_devs[] = {
128 /* Generic Modem class match */
129 {USB_IFACE_CLASS(UICLASS_CDC),
130 USB_IFACE_SUBCLASS(UISUBCLASS_ABSTRACT_CONTROL_MODEL),
131 USB_IFACE_PROTOCOL(UIPROTO_CDC_AT)},
132 /* Kyocera AH-K3001V */
133 {USB_VPI(USB_VENDOR_KYOCERA, USB_PRODUCT_KYOCERA_AHK3001V, 1)},
134 {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720, 1)},
135 {USB_VPI(USB_VENDOR_CURITEL, USB_PRODUCT_CURITEL_PC5740, 1)},
139 * As speeds for umodem deivces increase, these numbers will need to
140 * be increased. They should be good for G3 speeds and below.
142 * TODO: The TTY buffers should be increased!
144 #define UMODEM_BUF_SIZE 1024
153 #define UMODEM_MODVER 1 /* module version */
155 struct umodem_softc {
156 struct ucom_super_softc sc_super_ucom;
157 struct ucom_softc sc_ucom;
159 struct usb_xfer *sc_xfer[UMODEM_N_TRANSFER];
160 struct usb_device *sc_udev;
165 uint8_t sc_lsr; /* local status register */
166 uint8_t sc_msr; /* modem status register */
167 uint8_t sc_ctrl_iface_no;
168 uint8_t sc_data_iface_no;
169 uint8_t sc_iface_index[2];
170 uint8_t sc_cm_over_data;
171 uint8_t sc_cm_cap; /* CM capabilities */
172 uint8_t sc_acm_cap; /* ACM capabilities */
175 static device_probe_t umodem_probe;
176 static device_attach_t umodem_attach;
177 static device_detach_t umodem_detach;
179 static usb_callback_t umodem_intr_callback;
180 static usb_callback_t umodem_write_callback;
181 static usb_callback_t umodem_read_callback;
183 static void umodem_start_read(struct ucom_softc *);
184 static void umodem_stop_read(struct ucom_softc *);
185 static void umodem_start_write(struct ucom_softc *);
186 static void umodem_stop_write(struct ucom_softc *);
187 static void umodem_get_caps(struct usb_attach_arg *, uint8_t *, uint8_t *);
188 static void umodem_cfg_get_status(struct ucom_softc *, uint8_t *,
190 static int umodem_pre_param(struct ucom_softc *, struct termios *);
191 static void umodem_cfg_param(struct ucom_softc *, struct termios *);
192 static int umodem_ioctl(struct ucom_softc *, uint32_t, caddr_t, int,
194 static void umodem_cfg_set_dtr(struct ucom_softc *, uint8_t);
195 static void umodem_cfg_set_rts(struct ucom_softc *, uint8_t);
196 static void umodem_cfg_set_break(struct ucom_softc *, uint8_t);
197 static void *umodem_get_desc(struct usb_attach_arg *, uint8_t, uint8_t);
198 static usb_error_t umodem_set_comm_feature(struct usb_device *, uint8_t,
200 static void umodem_poll(struct ucom_softc *ucom);
202 static const struct usb_config umodem_config[UMODEM_N_TRANSFER] = {
206 .endpoint = UE_ADDR_ANY,
207 .direction = UE_DIR_OUT,
209 .bufsize = UMODEM_BUF_SIZE,
210 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
211 .callback = &umodem_write_callback,
216 .endpoint = UE_ADDR_ANY,
217 .direction = UE_DIR_IN,
219 .bufsize = UMODEM_BUF_SIZE,
220 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
221 .callback = &umodem_read_callback,
225 .type = UE_INTERRUPT,
226 .endpoint = UE_ADDR_ANY,
227 .direction = UE_DIR_IN,
229 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,.no_pipe_ok = 1,},
230 .bufsize = 0, /* use wMaxPacketSize */
231 .callback = &umodem_intr_callback,
235 static const struct ucom_callback umodem_callback = {
236 .ucom_cfg_get_status = &umodem_cfg_get_status,
237 .ucom_cfg_set_dtr = &umodem_cfg_set_dtr,
238 .ucom_cfg_set_rts = &umodem_cfg_set_rts,
239 .ucom_cfg_set_break = &umodem_cfg_set_break,
240 .ucom_cfg_param = &umodem_cfg_param,
241 .ucom_pre_param = &umodem_pre_param,
242 .ucom_ioctl = &umodem_ioctl,
243 .ucom_start_read = &umodem_start_read,
244 .ucom_stop_read = &umodem_stop_read,
245 .ucom_start_write = &umodem_start_write,
246 .ucom_stop_write = &umodem_stop_write,
247 .ucom_poll = &umodem_poll,
250 static device_method_t umodem_methods[] = {
251 DEVMETHOD(device_probe, umodem_probe),
252 DEVMETHOD(device_attach, umodem_attach),
253 DEVMETHOD(device_detach, umodem_detach),
257 static devclass_t umodem_devclass;
259 static driver_t umodem_driver = {
261 .methods = umodem_methods,
262 .size = sizeof(struct umodem_softc),
265 DRIVER_MODULE(umodem, uhub, umodem_driver, umodem_devclass, NULL, 0);
266 MODULE_DEPEND(umodem, ucom, 1, 1, 1);
267 MODULE_DEPEND(umodem, usb, 1, 1, 1);
268 MODULE_VERSION(umodem, UMODEM_MODVER);
271 umodem_probe(device_t dev)
273 struct usb_attach_arg *uaa = device_get_ivars(dev);
278 if (uaa->usb_mode != USB_MODE_HOST) {
281 error = usbd_lookup_id_by_uaa(umodem_devs, sizeof(umodem_devs), uaa);
286 umodem_attach(device_t dev)
288 struct usb_attach_arg *uaa = device_get_ivars(dev);
289 struct umodem_softc *sc = device_get_softc(dev);
290 struct usb_cdc_cm_descriptor *cmd;
291 struct usb_cdc_union_descriptor *cud;
295 device_set_usb_desc(dev);
296 mtx_init(&sc->sc_mtx, "umodem", NULL, MTX_DEF);
298 sc->sc_ctrl_iface_no = uaa->info.bIfaceNum;
299 sc->sc_iface_index[1] = uaa->info.bIfaceIndex;
300 sc->sc_udev = uaa->device;
302 umodem_get_caps(uaa, &sc->sc_cm_cap, &sc->sc_acm_cap);
304 /* get the data interface number */
306 cmd = umodem_get_desc(uaa, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
308 if ((cmd == NULL) || (cmd->bLength < sizeof(*cmd))) {
310 cud = usbd_find_descriptor(uaa->device, NULL,
311 uaa->info.bIfaceIndex, UDESC_CS_INTERFACE,
312 0 - 1, UDESCSUB_CDC_UNION, 0 - 1);
314 if ((cud == NULL) || (cud->bLength < sizeof(*cud))) {
315 device_printf(dev, "no CM or union descriptor\n");
319 sc->sc_data_iface_no = cud->bSlaveInterface[0];
321 sc->sc_data_iface_no = cmd->bDataInterface;
324 device_printf(dev, "data interface %d, has %sCM over "
325 "data, has %sbreak\n",
326 sc->sc_data_iface_no,
327 sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
328 sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
330 /* get the data interface too */
333 struct usb_interface *iface;
334 struct usb_interface_descriptor *id;
336 iface = usbd_get_iface(uaa->device, i);
340 id = usbd_get_interface_descriptor(iface);
342 if (id && (id->bInterfaceNumber == sc->sc_data_iface_no)) {
343 sc->sc_iface_index[0] = i;
344 usbd_set_parent_iface(uaa->device, i, uaa->info.bIfaceIndex);
348 device_printf(dev, "no data interface\n");
353 if (usb_test_quirk(uaa, UQ_ASSUME_CM_OVER_DATA)) {
354 sc->sc_cm_over_data = 1;
356 if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
357 if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE) {
359 error = umodem_set_comm_feature
360 (uaa->device, sc->sc_ctrl_iface_no,
361 UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
363 /* ignore any errors */
365 sc->sc_cm_over_data = 1;
368 error = usbd_transfer_setup(uaa->device,
369 sc->sc_iface_index, sc->sc_xfer,
370 umodem_config, UMODEM_N_TRANSFER,
376 /* clear stall at first run */
377 mtx_lock(&sc->sc_mtx);
378 usbd_xfer_set_stall(sc->sc_xfer[UMODEM_BULK_WR]);
379 usbd_xfer_set_stall(sc->sc_xfer[UMODEM_BULK_RD]);
380 mtx_unlock(&sc->sc_mtx);
382 error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
383 &umodem_callback, &sc->sc_mtx);
395 umodem_start_read(struct ucom_softc *ucom)
397 struct umodem_softc *sc = ucom->sc_parent;
399 /* start interrupt endpoint, if any */
400 usbd_transfer_start(sc->sc_xfer[UMODEM_INTR_RD]);
402 /* start read endpoint */
403 usbd_transfer_start(sc->sc_xfer[UMODEM_BULK_RD]);
407 umodem_stop_read(struct ucom_softc *ucom)
409 struct umodem_softc *sc = ucom->sc_parent;
411 /* stop interrupt endpoint, if any */
412 usbd_transfer_stop(sc->sc_xfer[UMODEM_INTR_RD]);
414 /* stop read endpoint */
415 usbd_transfer_stop(sc->sc_xfer[UMODEM_BULK_RD]);
419 umodem_start_write(struct ucom_softc *ucom)
421 struct umodem_softc *sc = ucom->sc_parent;
423 usbd_transfer_start(sc->sc_xfer[UMODEM_BULK_WR]);
427 umodem_stop_write(struct ucom_softc *ucom)
429 struct umodem_softc *sc = ucom->sc_parent;
431 usbd_transfer_stop(sc->sc_xfer[UMODEM_BULK_WR]);
435 umodem_get_caps(struct usb_attach_arg *uaa, uint8_t *cm, uint8_t *acm)
437 struct usb_cdc_cm_descriptor *cmd;
438 struct usb_cdc_acm_descriptor *cad;
440 cmd = umodem_get_desc(uaa, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
441 if ((cmd == NULL) || (cmd->bLength < sizeof(*cmd))) {
442 DPRINTF("no CM desc (faking one)\n");
443 *cm = USB_CDC_CM_DOES_CM | USB_CDC_CM_OVER_DATA;
445 *cm = cmd->bmCapabilities;
447 cad = umodem_get_desc(uaa, UDESC_CS_INTERFACE, UDESCSUB_CDC_ACM);
448 if ((cad == NULL) || (cad->bLength < sizeof(*cad))) {
449 DPRINTF("no ACM desc\n");
452 *acm = cad->bmCapabilities;
456 umodem_cfg_get_status(struct ucom_softc *ucom, uint8_t *lsr, uint8_t *msr)
458 struct umodem_softc *sc = ucom->sc_parent;
467 umodem_pre_param(struct ucom_softc *ucom, struct termios *t)
469 return (0); /* we accept anything */
473 umodem_cfg_param(struct ucom_softc *ucom, struct termios *t)
475 struct umodem_softc *sc = ucom->sc_parent;
476 struct usb_cdc_line_state ls;
477 struct usb_device_request req;
479 DPRINTF("sc=%p\n", sc);
481 bzero(&ls, sizeof(ls));
483 USETDW(ls.dwDTERate, t->c_ospeed);
485 ls.bCharFormat = (t->c_cflag & CSTOPB) ?
486 UCDC_STOP_BIT_2 : UCDC_STOP_BIT_1;
488 ls.bParityType = (t->c_cflag & PARENB) ?
489 ((t->c_cflag & PARODD) ?
490 UCDC_PARITY_ODD : UCDC_PARITY_EVEN) : UCDC_PARITY_NONE;
492 switch (t->c_cflag & CSIZE) {
507 DPRINTF("rate=%d fmt=%d parity=%d bits=%d\n",
508 UGETDW(ls.dwDTERate), ls.bCharFormat,
509 ls.bParityType, ls.bDataBits);
511 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
512 req.bRequest = UCDC_SET_LINE_CODING;
513 USETW(req.wValue, 0);
514 req.wIndex[0] = sc->sc_ctrl_iface_no;
516 USETW(req.wLength, sizeof(ls));
518 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
523 umodem_ioctl(struct ucom_softc *ucom, uint32_t cmd, caddr_t data,
524 int flag, struct thread *td)
526 struct umodem_softc *sc = ucom->sc_parent;
529 DPRINTF("cmd=0x%08x\n", cmd);
532 case USB_GET_CM_OVER_DATA:
533 *(int *)data = sc->sc_cm_over_data;
536 case USB_SET_CM_OVER_DATA:
537 if (*(int *)data != sc->sc_cm_over_data) {
543 DPRINTF("unknown\n");
552 umodem_cfg_set_dtr(struct ucom_softc *ucom, uint8_t onoff)
554 struct umodem_softc *sc = ucom->sc_parent;
555 struct usb_device_request req;
557 DPRINTF("onoff=%d\n", onoff);
560 sc->sc_line |= UCDC_LINE_DTR;
562 sc->sc_line &= ~UCDC_LINE_DTR;
564 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
565 req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
566 USETW(req.wValue, sc->sc_line);
567 req.wIndex[0] = sc->sc_ctrl_iface_no;
569 USETW(req.wLength, 0);
571 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
572 &req, NULL, 0, 1000);
576 umodem_cfg_set_rts(struct ucom_softc *ucom, uint8_t onoff)
578 struct umodem_softc *sc = ucom->sc_parent;
579 struct usb_device_request req;
581 DPRINTF("onoff=%d\n", onoff);
584 sc->sc_line |= UCDC_LINE_RTS;
586 sc->sc_line &= ~UCDC_LINE_RTS;
588 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
589 req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
590 USETW(req.wValue, sc->sc_line);
591 req.wIndex[0] = sc->sc_ctrl_iface_no;
593 USETW(req.wLength, 0);
595 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
596 &req, NULL, 0, 1000);
600 umodem_cfg_set_break(struct ucom_softc *ucom, uint8_t onoff)
602 struct umodem_softc *sc = ucom->sc_parent;
603 struct usb_device_request req;
606 DPRINTF("onoff=%d\n", onoff);
608 if (sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK) {
610 temp = onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF;
612 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
613 req.bRequest = UCDC_SEND_BREAK;
614 USETW(req.wValue, temp);
615 req.wIndex[0] = sc->sc_ctrl_iface_no;
617 USETW(req.wLength, 0);
619 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
620 &req, NULL, 0, 1000);
625 umodem_intr_callback(struct usb_xfer *xfer, usb_error_t error)
627 struct usb_cdc_notification pkt;
628 struct umodem_softc *sc = usbd_xfer_softc(xfer);
629 struct usb_page_cache *pc;
633 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
635 switch (USB_GET_STATE(xfer)) {
636 case USB_ST_TRANSFERRED:
639 DPRINTF("received short packet, "
640 "%d bytes\n", actlen);
643 if (actlen > sizeof(pkt)) {
644 DPRINTF("truncating message\n");
645 actlen = sizeof(pkt);
647 pc = usbd_xfer_get_frame(xfer, 0);
648 usbd_copy_out(pc, 0, &pkt, actlen);
652 wLen = UGETW(pkt.wLength);
656 if (pkt.bmRequestType != UCDC_NOTIFICATION) {
657 DPRINTF("unknown message type, "
658 "0x%02x, on notify pipe!\n",
662 switch (pkt.bNotification) {
663 case UCDC_N_SERIAL_STATE:
665 * Set the serial state in ucom driver based on
666 * the bits from the notify message
669 DPRINTF("invalid notification "
670 "length, %d bytes!\n", actlen);
673 DPRINTF("notify bytes = %02x%02x\n",
677 /* Currently, lsr is always zero. */
681 if (pkt.data[0] & UCDC_N_SERIAL_RI) {
682 sc->sc_msr |= SER_RI;
684 if (pkt.data[0] & UCDC_N_SERIAL_DSR) {
685 sc->sc_msr |= SER_DSR;
687 if (pkt.data[0] & UCDC_N_SERIAL_DCD) {
688 sc->sc_msr |= SER_DCD;
690 ucom_status_change(&sc->sc_ucom);
694 DPRINTF("unknown notify message: 0x%02x\n",
701 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
702 usbd_transfer_submit(xfer);
706 if (error != USB_ERR_CANCELLED) {
707 /* try to clear stall first */
708 usbd_xfer_set_stall(xfer);
717 umodem_write_callback(struct usb_xfer *xfer, usb_error_t error)
719 struct umodem_softc *sc = usbd_xfer_softc(xfer);
720 struct usb_page_cache *pc;
723 switch (USB_GET_STATE(xfer)) {
725 case USB_ST_TRANSFERRED:
727 pc = usbd_xfer_get_frame(xfer, 0);
728 if (ucom_get_data(&sc->sc_ucom, pc, 0,
729 UMODEM_BUF_SIZE, &actlen)) {
731 usbd_xfer_set_frame_len(xfer, 0, actlen);
732 usbd_transfer_submit(xfer);
737 if (error != USB_ERR_CANCELLED) {
738 /* try to clear stall first */
739 usbd_xfer_set_stall(xfer);
747 umodem_read_callback(struct usb_xfer *xfer, usb_error_t error)
749 struct umodem_softc *sc = usbd_xfer_softc(xfer);
750 struct usb_page_cache *pc;
753 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
755 switch (USB_GET_STATE(xfer)) {
756 case USB_ST_TRANSFERRED:
758 DPRINTF("actlen=%d\n", actlen);
760 pc = usbd_xfer_get_frame(xfer, 0);
761 ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
765 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
766 usbd_transfer_submit(xfer);
770 if (error != USB_ERR_CANCELLED) {
771 /* try to clear stall first */
772 usbd_xfer_set_stall(xfer);
780 umodem_get_desc(struct usb_attach_arg *uaa, uint8_t type, uint8_t subtype)
782 return (usbd_find_descriptor(uaa->device, NULL, uaa->info.bIfaceIndex,
783 type, 0 - 1, subtype, 0 - 1));
787 umodem_set_comm_feature(struct usb_device *udev, uint8_t iface_no,
788 uint16_t feature, uint16_t state)
790 struct usb_device_request req;
791 struct usb_cdc_abstract_state ast;
793 DPRINTF("feature=%d state=%d\n",
796 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
797 req.bRequest = UCDC_SET_COMM_FEATURE;
798 USETW(req.wValue, feature);
799 req.wIndex[0] = iface_no;
801 USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH);
802 USETW(ast.wState, state);
804 return (usbd_do_request(udev, NULL, &req, &ast));
808 umodem_detach(device_t dev)
810 struct umodem_softc *sc = device_get_softc(dev);
812 DPRINTF("sc=%p\n", sc);
814 ucom_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1);
815 usbd_transfer_unsetup(sc->sc_xfer, UMODEM_N_TRANSFER);
816 mtx_destroy(&sc->sc_mtx);
822 umodem_poll(struct ucom_softc *ucom)
824 struct umodem_softc *sc = ucom->sc_parent;
825 usbd_transfer_poll(sc->sc_xfer, UMODEM_N_TRANSFER);