2 * $NetBSD: umodem.c,v 1.5 1999/01/08 11:58:25 augustss Exp $
3 * $NetBSD: umodem.c,v 1.45 2002/09/23 05:51:23 simonb Exp $
4 * $FreeBSD: src/sys/dev/usb/umodem.c,v 1.48 2003/08/24 17:55:55 obrien Exp $
5 * $DragonFly: src/sys/dev/usbmisc/umodem/umodem.c,v 1.12 2006/12/22 23:26:26 swildner Exp $
9 * Copyright (c) 2003, M. Warner Losh <imp@freebsd.org>.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Copyright (c) 1998 The NetBSD Foundation, Inc.
36 * All rights reserved.
38 * This code is derived from software contributed to The NetBSD Foundation
39 * by Lennart Augustsson (lennart@augustsson.net) at
40 * Carlstedt Research & Technology.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by the NetBSD
53 * Foundation, Inc. and its contributors.
54 * 4. Neither the name of The NetBSD Foundation nor the names of its
55 * contributors may be used to endorse or promote products derived
56 * from this software without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
59 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
61 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
62 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
64 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68 * POSSIBILITY OF SUCH DAMAGE.
72 * Comm Class spec: http://www.usb.org/developers/devclass_docs/usbccs10.pdf
73 * http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
78 * - Add error recovery in various places; the big problem is what
79 * to do in a callback if there is an error.
80 * - Implement a Call Device for modems without multiplexed commands.
84 #include <sys/param.h>
85 #include <sys/systm.h>
86 #include <sys/kernel.h>
87 #include <sys/ioccom.h>
91 #include <sys/select.h>
92 #include <sys/sysctl.h>
94 #include <sys/vnode.h>
98 #include <bus/usb/usb.h>
99 #include <bus/usb/usbcdc.h>
101 #include <bus/usb/usbdi.h>
102 #include <bus/usb/usbdi_util.h>
103 #include <bus/usb/usbdevs.h>
104 #include <dev/usbmisc/ucom/ucomvar.h>
105 #include <bus/usb/usb_quirks.h>
107 #include <bus/usb/usbdevs.h>
111 SYSCTL_NODE(_hw_usb, OID_AUTO, umodem, CTLFLAG_RW, 0, "USB umodem");
112 SYSCTL_INT(_hw_usb_umodem, OID_AUTO, debug, CTLFLAG_RW,
113 &umodemdebug, 0, "umodem debug level");
114 #define DPRINTFN(n, x) if (umodemdebug > (n)) logprintf x
116 #define DPRINTFN(n, x)
118 #define DPRINTF(x) DPRINTFN(0, x)
121 * These are the maximum number of bytes transferred per frame.
122 * If some really high speed devices should use this driver they
123 * may need to be increased, but this is good enough for normal modems.
125 #define UMODEMIBUFSIZE 64
126 #define UMODEMOBUFSIZE 256
128 #define UMODEM_MODVER 1 /* module version */
130 struct umodem_softc {
131 struct ucom_softc sc_ucom;
133 USBBASEDEVICE sc_dev; /* base device */
135 usbd_device_handle sc_udev; /* USB device */
138 usbd_interface_handle sc_ctl_iface; /* control interface */
139 int sc_data_iface_no;
140 usbd_interface_handle sc_data_iface; /* data interface */
142 int sc_cm_cap; /* CM capabilities */
143 int sc_acm_cap; /* ACM capabilities */
147 usb_cdc_line_state_t sc_line_state; /* current line state */
148 u_char sc_dtr; /* current DTR state */
149 u_char sc_rts; /* current RTS state */
151 u_char sc_opening; /* lock during open */
153 int sc_ctl_notify; /* Notification endpoint */
154 usbd_pipe_handle sc_notify_pipe; /* Notification pipe */
155 usb_cdc_notification_t sc_notify_buf; /* Notification structure */
156 u_char sc_lsr; /* Local status register */
157 u_char sc_msr; /* Modem status register */
160 Static void *umodem_get_desc(usbd_device_handle dev, int type, int subtype);
161 Static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
162 int feature, int state);
163 Static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
164 usb_cdc_line_state_t *state);
166 Static void umodem_get_caps(usbd_device_handle, int *, int *);
168 Static void umodem_get_status(void *, int portno, u_char *lsr, u_char *msr);
169 Static void umodem_set(void *, int, int, int);
170 Static void umodem_dtr(struct umodem_softc *, int);
171 Static void umodem_rts(struct umodem_softc *, int);
172 Static void umodem_break(struct umodem_softc *, int);
173 Static void umodem_set_line_state(struct umodem_softc *);
174 Static int umodem_param(void *, int, struct termios *);
175 Static int umodem_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr );
176 Static int umodem_open(void *, int portno);
177 Static void umodem_close(void *, int portno);
178 Static void umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
180 Static struct ucom_callback umodem_callback = {
191 Static device_probe_t umodem_match;
192 Static device_attach_t umodem_attach;
193 Static device_detach_t umodem_detach;
195 Static device_method_t umodem_methods[] = {
196 /* Device interface */
197 DEVMETHOD(device_probe, umodem_match),
198 DEVMETHOD(device_attach, umodem_attach),
199 DEVMETHOD(device_detach, umodem_detach),
203 Static driver_t umodem_driver = {
206 sizeof (struct umodem_softc)
209 DRIVER_MODULE(umodem, uhub, umodem_driver, ucom_devclass, usbd_driver_load, 0);
210 MODULE_DEPEND(umodem, usb, 1, 1, 1);
211 MODULE_DEPEND(umodem, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
212 MODULE_VERSION(umodem, UMODEM_MODVER);
216 USB_MATCH_START(umodem, uaa);
217 usb_interface_descriptor_t *id;
220 if (uaa->iface == NULL)
221 return (UMATCH_NONE);
223 id = usbd_get_interface_descriptor(uaa->iface);
225 id->bInterfaceClass != UICLASS_CDC ||
226 id->bInterfaceSubClass != UISUBCLASS_ABSTRACT_CONTROL_MODEL ||
227 id->bInterfaceProtocol != UIPROTO_CDC_AT)
228 return (UMATCH_NONE);
230 umodem_get_caps(uaa->device, &cm, &acm);
231 if (!(cm & USB_CDC_CM_DOES_CM) ||
232 !(cm & USB_CDC_CM_OVER_DATA) ||
233 !(acm & USB_CDC_ACM_HAS_LINE))
234 return (UMATCH_NONE);
236 return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
241 USB_ATTACH_START(umodem, sc, uaa);
242 usbd_device_handle dev = uaa->device;
243 usb_interface_descriptor_t *id;
244 usb_endpoint_descriptor_t *ed;
245 usb_cdc_cm_descriptor_t *cmd;
246 char *devinfo = NULL;
251 struct ucom_softc *ucom;
253 devinfo = kmalloc(1024, M_USBDEV, M_INTWAIT);
254 usbd_devinfo(dev, 0, devinfo);
258 device_set_desc_copy(self, devinfo);
260 ucom->sc_iface = uaa->iface;
261 /*USB_ATTACH_SETUP; */
264 sc->sc_ctl_iface = uaa->iface;
266 devname = USBDEVNAME(sc->sc_dev);
267 /* XXX ? use something else ? XXX */
268 id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
269 kprintf("%s: %s, iclass %d/%d\n", devname, devinfo,
270 id->bInterfaceClass, id->bInterfaceSubClass);
271 sc->sc_ctl_iface_no = id->bInterfaceNumber;
273 umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap);
275 /* Get the data interface no. */
276 cmd = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
278 kprintf("%s: no CM descriptor\n", devname);
281 sc->sc_data_iface_no = data_ifcno = cmd->bDataInterface;
283 kprintf("%s: data interface %d, has %sCM over data, has %sbreak\n",
285 sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
286 sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
288 /* Get the data interface too. */
289 for (i = 0; i < uaa->nifaces; i++) {
290 if (uaa->ifaces[i] != NULL) {
291 id = usbd_get_interface_descriptor(uaa->ifaces[i]);
292 if (id != NULL && id->bInterfaceNumber == data_ifcno) {
293 sc->sc_data_iface = uaa->ifaces[i];
294 uaa->ifaces[i] = NULL;
298 if (sc->sc_data_iface == NULL) {
299 kprintf("%s: no data interface\n", devname);
302 ucom->sc_iface = sc->sc_data_iface;
305 * Find the bulk endpoints.
306 * Iterate over all endpoints in the data interface and take note.
308 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
310 id = usbd_get_interface_descriptor(sc->sc_data_iface);
311 for (i = 0; i < id->bNumEndpoints; i++) {
312 ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
314 kprintf("%s: no endpoint descriptor for %d\n", devname,
318 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
319 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
320 ucom->sc_bulkin_no = ed->bEndpointAddress;
321 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
322 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
323 ucom->sc_bulkout_no = ed->bEndpointAddress;
327 if (ucom->sc_bulkin_no == -1) {
328 kprintf("%s: Could not find data bulk in\n", devname);
331 if (ucom->sc_bulkout_no == -1) {
332 kprintf("%s: Could not find data bulk out\n", devname);
336 if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) {
337 DPRINTF(("Quirk says to assume CM over data\n"));
338 sc->sc_cm_over_data = 1;
340 if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
341 if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
342 err = umodem_set_comm_feature(sc,
343 UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
347 kprintf("%s: could not set data multiplex mode\n",
351 sc->sc_cm_over_data = 1;
356 * The standard allows for notification messages (to indicate things
357 * like a modem hangup) to come in via an interrupt endpoint
358 * off of the control interface. Iterate over the endpoints on
359 * the control interface and see if there are any interrupt
360 * endpoints; if there are, then register it.
363 sc->sc_ctl_notify = -1;
364 sc->sc_notify_pipe = NULL;
366 for (i = 0; i < id->bNumEndpoints; i++) {
367 ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i);
371 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
372 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
373 kprintf("%s: status change notification available\n",
375 sc->sc_ctl_notify = ed->bEndpointAddress;
381 ucom->sc_parent = sc;
382 ucom->sc_portno = UCOM_UNK_PORTNO;
383 /* bulkin, bulkout set above */
384 ucom->sc_ibufsize = UMODEMIBUFSIZE;
385 ucom->sc_obufsize = UMODEMOBUFSIZE;
386 ucom->sc_ibufsizepad = UMODEMIBUFSIZE;
387 ucom->sc_opkthdrlen = 0;
388 ucom->sc_callback = &umodem_callback;
390 ucom_attach(&sc->sc_ucom);
392 kfree(devinfo, M_USBDEV);
393 USB_ATTACH_SUCCESS_RETURN;
397 kfree(devinfo, M_USBDEV);
398 USB_ATTACH_ERROR_RETURN;
402 umodem_open(void *addr, int portno)
404 struct umodem_softc *sc = addr;
407 DPRINTF(("umodem_open: sc=%p\n", sc));
409 if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) {
410 err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify,
411 USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc,
412 &sc->sc_notify_buf, sizeof(sc->sc_notify_buf),
413 umodem_intr, USBD_DEFAULT_INTERVAL);
416 DPRINTF(("Failed to establish notify pipe: %s\n",
426 umodem_close(void *addr, int portno)
428 struct umodem_softc *sc = addr;
431 DPRINTF(("umodem_close: sc=%p\n", sc));
433 if (sc->sc_notify_pipe != NULL) {
434 err = usbd_abort_pipe(sc->sc_notify_pipe);
436 kprintf("%s: abort notify pipe failed: %s\n",
437 USBDEVNAME(sc->sc_dev), usbd_errstr(err));
438 err = usbd_close_pipe(sc->sc_notify_pipe);
440 kprintf("%s: close notify pipe failed: %s\n",
441 USBDEVNAME(sc->sc_dev), usbd_errstr(err));
442 sc->sc_notify_pipe = NULL;
447 umodem_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
449 struct umodem_softc *sc = priv;
452 if (sc->sc_ucom.sc_dying)
455 if (status != USBD_NORMAL_COMPLETION) {
456 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
458 kprintf("%s: abnormal status: %s\n", USBDEVNAME(sc->sc_dev),
459 usbd_errstr(status));
463 if (sc->sc_notify_buf.bmRequestType != UCDC_NOTIFICATION) {
464 DPRINTF(("%s: unknown message type (%02x) on notify pipe\n",
465 USBDEVNAME(sc->sc_dev),
466 sc->sc_notify_buf.bmRequestType));
470 switch (sc->sc_notify_buf.bNotification) {
471 case UCDC_N_SERIAL_STATE:
473 * Set the serial state in ucom driver based on
474 * the bits from the notify message
476 if (UGETW(sc->sc_notify_buf.wLength) != 2) {
477 kprintf("%s: Invalid notification length! (%d)\n",
478 USBDEVNAME(sc->sc_dev),
479 UGETW(sc->sc_notify_buf.wLength));
482 DPRINTF(("%s: notify bytes = %02x%02x\n",
483 USBDEVNAME(sc->sc_dev),
484 sc->sc_notify_buf.data[0],
485 sc->sc_notify_buf.data[1]));
486 /* Currently, lsr is always zero. */
487 sc->sc_lsr = sc->sc_msr = 0;
488 mstatus = sc->sc_notify_buf.data[0];
490 if (ISSET(mstatus, UCDC_N_SERIAL_RI))
491 sc->sc_msr |= UMSR_RI;
492 if (ISSET(mstatus, UCDC_N_SERIAL_DSR))
493 sc->sc_msr |= UMSR_DSR;
494 if (ISSET(mstatus, UCDC_N_SERIAL_DCD))
495 sc->sc_msr |= UMSR_DCD;
496 ucom_status_change(&sc->sc_ucom);
499 DPRINTF(("%s: unknown notify message: %02x\n",
500 USBDEVNAME(sc->sc_dev),
501 sc->sc_notify_buf.bNotification));
507 umodem_get_caps(usbd_device_handle dev, int *cm, int *acm)
509 usb_cdc_cm_descriptor_t *cmd;
510 usb_cdc_acm_descriptor_t *cad;
514 cmd = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
516 DPRINTF(("umodem_get_desc: no CM desc\n"));
519 *cm = cmd->bmCapabilities;
521 cad = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_ACM);
523 DPRINTF(("umodem_get_desc: no ACM desc\n"));
526 *acm = cad->bmCapabilities;
530 umodem_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
532 struct umodem_softc *sc = addr;
534 DPRINTF(("umodem_get_status:\n"));
543 umodem_param(void *addr, int portno, struct termios *t)
545 struct umodem_softc *sc = addr;
547 usb_cdc_line_state_t ls;
549 DPRINTF(("umodem_param: sc=%p\n", sc));
551 USETDW(ls.dwDTERate, t->c_ospeed);
552 if (ISSET(t->c_cflag, CSTOPB))
553 ls.bCharFormat = UCDC_STOP_BIT_2;
555 ls.bCharFormat = UCDC_STOP_BIT_1;
556 if (ISSET(t->c_cflag, PARENB)) {
557 if (ISSET(t->c_cflag, PARODD))
558 ls.bParityType = UCDC_PARITY_ODD;
560 ls.bParityType = UCDC_PARITY_EVEN;
562 ls.bParityType = UCDC_PARITY_NONE;
563 switch (ISSET(t->c_cflag, CSIZE)) {
578 err = umodem_set_line_coding(sc, &ls);
580 DPRINTF(("umodem_param: err=%s\n", usbd_errstr(err)));
587 umodem_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
590 struct umodem_softc *sc = addr;
593 if (sc->sc_ucom.sc_dying)
596 DPRINTF(("umodemioctl: cmd=0x%08lx\n", cmd));
599 case USB_GET_CM_OVER_DATA:
600 *(int *)data = sc->sc_cm_over_data;
603 case USB_SET_CM_OVER_DATA:
604 if (*(int *)data != sc->sc_cm_over_data) {
610 DPRINTF(("umodemioctl: unknown\n"));
619 umodem_dtr(struct umodem_softc *sc, int onoff)
621 DPRINTF(("umodem_modem: onoff=%d\n", onoff));
623 if (sc->sc_dtr == onoff)
627 umodem_set_line_state(sc);
631 umodem_rts(struct umodem_softc *sc, int onoff)
633 DPRINTF(("umodem_modem: onoff=%d\n", onoff));
635 if (sc->sc_rts == onoff)
639 umodem_set_line_state(sc);
643 umodem_set_line_state(struct umodem_softc *sc)
645 usb_device_request_t req;
648 ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
649 (sc->sc_rts ? UCDC_LINE_RTS : 0);
650 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
651 req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
652 USETW(req.wValue, ls);
653 USETW(req.wIndex, sc->sc_ctl_iface_no);
654 USETW(req.wLength, 0);
656 (void)usbd_do_request(sc->sc_udev, &req, 0);
661 umodem_break(struct umodem_softc *sc, int onoff)
663 usb_device_request_t req;
665 DPRINTF(("umodem_break: onoff=%d\n", onoff));
667 if (!(sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK))
670 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
671 req.bRequest = UCDC_SEND_BREAK;
672 USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
673 USETW(req.wIndex, sc->sc_ctl_iface_no);
674 USETW(req.wLength, 0);
676 (void)usbd_do_request(sc->sc_udev, &req, 0);
680 umodem_set(void *addr, int portno, int reg, int onoff)
682 struct umodem_softc *sc = addr;
686 umodem_dtr(sc, onoff);
689 umodem_rts(sc, onoff);
692 umodem_break(sc, onoff);
700 umodem_set_line_coding(struct umodem_softc *sc, usb_cdc_line_state_t *state)
702 usb_device_request_t req;
705 DPRINTF(("umodem_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
706 UGETDW(state->dwDTERate), state->bCharFormat,
707 state->bParityType, state->bDataBits));
709 if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
710 DPRINTF(("umodem_set_line_coding: already set\n"));
711 return (USBD_NORMAL_COMPLETION);
714 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
715 req.bRequest = UCDC_SET_LINE_CODING;
716 USETW(req.wValue, 0);
717 USETW(req.wIndex, sc->sc_ctl_iface_no);
718 USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
720 err = usbd_do_request(sc->sc_udev, &req, state);
722 DPRINTF(("umodem_set_line_coding: failed, err=%s\n",
727 sc->sc_line_state = *state;
729 return (USBD_NORMAL_COMPLETION);
733 umodem_get_desc(usbd_device_handle dev, int type, int subtype)
735 usb_descriptor_t *desc;
736 usb_config_descriptor_t *cd = usbd_get_config_descriptor(dev);
737 uByte *p = (uByte *)cd;
738 uByte *end = p + UGETW(cd->wTotalLength);
741 desc = (usb_descriptor_t *)p;
742 if (desc->bDescriptorType == type &&
743 desc->bDescriptorSubtype == subtype)
752 umodem_set_comm_feature(struct umodem_softc *sc, int feature, int state)
754 usb_device_request_t req;
756 usb_cdc_abstract_state_t ast;
758 DPRINTF(("umodem_set_comm_feature: feature=%d state=%d\n", feature,
761 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
762 req.bRequest = UCDC_SET_COMM_FEATURE;
763 USETW(req.wValue, feature);
764 USETW(req.wIndex, sc->sc_ctl_iface_no);
765 USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH);
766 USETW(ast.wState, state);
768 err = usbd_do_request(sc->sc_udev, &req, &ast);
770 DPRINTF(("umodem_set_comm_feature: feature=%d, err=%s\n",
771 feature, usbd_errstr(err)));
775 return (USBD_NORMAL_COMPLETION);
780 USB_DETACH_START(umodem, sc);
783 DPRINTF(("umodem_detach: sc=%p\n", sc));
785 if (sc->sc_notify_pipe != NULL) {
786 usbd_abort_pipe(sc->sc_notify_pipe);
787 usbd_close_pipe(sc->sc_notify_pipe);
788 sc->sc_notify_pipe = NULL;
791 sc->sc_ucom.sc_dying = 1;
792 rv = ucom_detach(&sc->sc_ucom);