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
76 * - Add error recovery in various places; the big problem is what
77 * to do in a callback if there is an error.
78 * - Implement a Call Device for modems without multiplexed commands.
82 #include <sys/param.h>
83 #include <sys/systm.h>
84 #include <sys/kernel.h>
85 #include <sys/module.h>
86 #include <sys/ioccom.h>
88 #include <sys/serial.h>
91 #include <sys/select.h>
92 #include <sys/sysctl.h>
97 #include <sys/taskqueue.h>
99 #include <dev/usb/usb.h>
100 #include <dev/usb/usbcdc.h>
102 #include <dev/usb/usbdi.h>
103 #include <dev/usb/usbdi_util.h>
104 #include <dev/usb/usb_quirks.h>
106 #include <dev/usb/ucomvar.h>
112 SYSCTL_NODE(_hw_usb, OID_AUTO, umodem, CTLFLAG_RW, 0, "USB umodem");
113 SYSCTL_INT(_hw_usb_umodem, OID_AUTO, debug, CTLFLAG_RW,
114 &umodemdebug, 0, "umodem debug level");
115 #define DPRINTFN(n, x) if (umodemdebug > (n)) printf x
117 #define DPRINTFN(n, x)
119 #define DPRINTF(x) DPRINTFN(0, x)
121 static const struct umodem_product {
125 } umodem_products[] = {
126 /* Kyocera AH-K3001V*/
127 { USB_VENDOR_KYOCERA, USB_PRODUCT_KYOCERA_AHK3001V, 0 },
128 { USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720, 0 },
129 { USB_VENDOR_CURITEL, USB_PRODUCT_CURITEL_PC5740, 0 },
134 * These are the maximum number of bytes transferred per frame.
135 * As speeds for umodem deivces increase, these numbers will need to
136 * be increased. They should be good for G3 speeds and below.
138 #define UMODEMIBUFSIZE 1024
139 #define UMODEMOBUFSIZE 1024
141 #define UMODEM_MODVER 1 /* module version */
143 struct umodem_softc {
144 struct ucom_softc sc_ucom;
146 device_t sc_dev; /* base device */
148 usbd_device_handle sc_udev; /* USB device */
151 usbd_interface_handle sc_ctl_iface; /* control interface */
152 int sc_data_iface_no;
153 usbd_interface_handle sc_data_iface; /* data interface */
155 int sc_cm_cap; /* CM capabilities */
156 int sc_acm_cap; /* ACM capabilities */
160 usb_cdc_line_state_t sc_line_state; /* current line state */
161 u_char sc_dtr; /* current DTR state */
162 u_char sc_rts; /* current RTS state */
164 u_char sc_opening; /* lock during open */
166 int sc_ctl_notify; /* Notification endpoint */
167 usbd_pipe_handle sc_notify_pipe; /* Notification pipe */
168 usb_cdc_notification_t sc_notify_buf; /* Notification structure */
169 u_char sc_lsr; /* Local status register */
170 u_char sc_msr; /* Modem status register */
175 static void *umodem_get_desc(usbd_device_handle dev, int type, int subtype);
176 static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
177 int feature, int state);
178 static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
179 usb_cdc_line_state_t *state);
181 static void umodem_get_caps(usbd_device_handle, int *, int *);
183 static void umodem_get_status(void *, int portno, u_char *lsr, u_char *msr);
184 static void umodem_set(void *, int, int, int);
185 static void umodem_dtr(struct umodem_softc *, int);
186 static void umodem_rts(struct umodem_softc *, int);
187 static void umodem_break(struct umodem_softc *, int);
188 static void umodem_set_line_state(struct umodem_softc *);
189 static int umodem_param(void *, int, struct termios *);
190 static int umodem_ioctl(void *, int, u_long, caddr_t, int, struct thread *);
191 static int umodem_open(void *, int portno);
192 static void umodem_close(void *, int portno);
193 static void umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
194 static void umodem_notify(void *, int);
196 static struct ucom_callback umodem_callback = {
207 static device_probe_t umodem_match;
208 static device_attach_t umodem_attach;
209 static device_detach_t umodem_detach;
211 static device_method_t umodem_methods[] = {
212 /* Device interface */
213 DEVMETHOD(device_probe, umodem_match),
214 DEVMETHOD(device_attach, umodem_attach),
215 DEVMETHOD(device_detach, umodem_detach),
219 static driver_t umodem_driver = {
222 sizeof (struct umodem_softc)
225 DRIVER_MODULE(umodem, uhub, umodem_driver, ucom_devclass, usbd_driver_load, 0);
226 MODULE_DEPEND(umodem, usb, 1, 1, 1);
227 MODULE_DEPEND(umodem, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
228 MODULE_VERSION(umodem, UMODEM_MODVER);
231 umodem_match(device_t self)
233 struct usb_attach_arg *uaa = device_get_ivars(self);
234 usb_interface_descriptor_t *id;
235 usb_device_descriptor_t *dd;
238 if (uaa->iface == NULL)
239 return (UMATCH_NONE);
241 id = usbd_get_interface_descriptor(uaa->iface);
242 dd = usbd_get_device_descriptor(uaa->device);
243 if (id == NULL || dd == NULL)
244 return (UMATCH_NONE);
247 for (i = 0; umodem_products[i].vendor != 0; i++) {
248 if (umodem_products[i].vendor == UGETW(dd->idVendor) &&
249 umodem_products[i].product == UGETW(dd->idProduct) &&
250 umodem_products[i].interface == id->bInterfaceNumber) {
251 ret = UMATCH_VENDOR_PRODUCT;
256 if (ret == UMATCH_NONE &&
257 id->bInterfaceClass == UICLASS_CDC &&
258 id->bInterfaceSubClass == UISUBCLASS_ABSTRACT_CONTROL_MODEL &&
259 id->bInterfaceProtocol == UIPROTO_CDC_AT)
260 ret = UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO;
262 if (ret == UMATCH_NONE)
265 umodem_get_caps(uaa->device, &cm, &acm);
266 if (!(cm & USB_CDC_CM_DOES_CM) ||
267 !(cm & USB_CDC_CM_OVER_DATA) ||
268 !(acm & USB_CDC_ACM_HAS_LINE))
269 return (UMATCH_NONE);
275 umodem_attach(device_t self)
277 struct umodem_softc *sc = device_get_softc(self);
278 struct usb_attach_arg *uaa = device_get_ivars(self);
279 usbd_device_handle dev = uaa->device;
280 usb_interface_descriptor_t *id;
281 usb_endpoint_descriptor_t *ed;
282 usb_cdc_cm_descriptor_t *cmd;
285 struct ucom_softc *ucom;
291 ucom->sc_iface = uaa->iface;
294 sc->sc_ctl_iface = uaa->iface;
295 id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
296 sc->sc_ctl_iface_no = id->bInterfaceNumber;
297 device_printf(self, "iclass %d/%d\n", id->bInterfaceClass,
298 id->bInterfaceSubClass);
300 umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap);
302 /* Get the data interface no. */
303 cmd = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
305 device_printf(sc->sc_dev, "no CM descriptor\n");
308 sc->sc_data_iface_no = data_ifcno = cmd->bDataInterface;
310 device_printf(sc->sc_dev,
311 "data interface %d, has %sCM over data, has %sbreak\n",
312 data_ifcno, sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
313 sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
315 /* Get the data interface too. */
316 for (i = 0; i < uaa->nifaces; i++) {
317 if (uaa->ifaces[i] != NULL) {
318 id = usbd_get_interface_descriptor(uaa->ifaces[i]);
319 if (id != NULL && id->bInterfaceNumber == data_ifcno) {
320 sc->sc_data_iface = uaa->ifaces[i];
321 uaa->ifaces[i] = NULL;
325 if (sc->sc_data_iface == NULL) {
326 device_printf(sc->sc_dev, "no data interface\n");
329 ucom->sc_iface = sc->sc_data_iface;
332 * Find the bulk endpoints.
333 * Iterate over all endpoints in the data interface and take note.
335 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
337 id = usbd_get_interface_descriptor(sc->sc_data_iface);
338 for (i = 0; i < id->bNumEndpoints; i++) {
339 ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
341 device_printf(sc->sc_dev,
342 "no endpoint descriptor for %d\n", i);
345 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
346 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
347 ucom->sc_bulkin_no = ed->bEndpointAddress;
348 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
349 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
350 ucom->sc_bulkout_no = ed->bEndpointAddress;
354 if (ucom->sc_bulkin_no == -1) {
355 device_printf(sc->sc_dev, "Could not find data bulk in\n");
358 if (ucom->sc_bulkout_no == -1) {
359 device_printf(sc->sc_dev, "Could not find data bulk out\n");
363 if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
364 if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
365 umodem_set_comm_feature(sc, UCDC_ABSTRACT_STATE,
366 UCDC_DATA_MULTIPLEXED);
367 sc->sc_cm_over_data = 1;
371 * The standard allows for notification messages (to indicate things
372 * like a modem hangup) to come in via an interrupt endpoint
373 * off of the control interface. Iterate over the endpoints on
374 * the control interface and see if there are any interrupt
375 * endpoints; if there are, then register it.
378 sc->sc_ctl_notify = -1;
379 sc->sc_notify_pipe = NULL;
381 for (i = 0; i < id->bNumEndpoints; i++) {
382 ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i);
386 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
387 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
388 device_printf(sc->sc_dev,
389 "status change notification available\n");
390 sc->sc_ctl_notify = ed->bEndpointAddress;
396 ucom->sc_parent = sc;
397 ucom->sc_portno = UCOM_UNK_PORTNO;
398 /* bulkin, bulkout set above */
399 ucom->sc_ibufsize = UMODEMIBUFSIZE;
400 ucom->sc_obufsize = UMODEMOBUFSIZE;
401 ucom->sc_ibufsizepad = UMODEMIBUFSIZE;
402 ucom->sc_opkthdrlen = 0;
403 ucom->sc_callback = &umodem_callback;
405 TASK_INIT(&sc->sc_task, 0, umodem_notify, sc);
406 ucom_attach(&sc->sc_ucom);
415 umodem_open(void *addr, int portno)
417 struct umodem_softc *sc = addr;
420 DPRINTF(("umodem_open: sc=%p\n", sc));
422 if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) {
423 err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify,
424 USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc,
425 &sc->sc_notify_buf, sizeof(sc->sc_notify_buf),
426 umodem_intr, USBD_DEFAULT_INTERVAL);
429 DPRINTF(("Failed to establish notify pipe: %s\n",
439 umodem_close(void *addr, int portno)
441 struct umodem_softc *sc = addr;
444 DPRINTF(("umodem_close: sc=%p\n", sc));
446 if (sc->sc_notify_pipe != NULL) {
447 err = usbd_abort_pipe(sc->sc_notify_pipe);
449 device_printf(sc->sc_dev,
450 "abort notify pipe failed: %s\n",
452 err = usbd_close_pipe(sc->sc_notify_pipe);
454 device_printf(sc->sc_dev,
455 "close notify pipe failed: %s\n",
457 sc->sc_notify_pipe = NULL;
462 umodem_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
464 struct umodem_softc *sc = priv;
467 if (sc->sc_ucom.sc_dying)
470 if (status != USBD_NORMAL_COMPLETION) {
471 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
473 device_printf(sc->sc_dev, "abnormal status: %s\n",
474 usbd_errstr(status));
478 if (sc->sc_notify_buf.bmRequestType != UCDC_NOTIFICATION) {
479 DPRINTF(("%s: unknown message type (%02x) on notify pipe\n",
480 device_get_nameunit(sc->sc_dev),
481 sc->sc_notify_buf.bmRequestType));
485 switch (sc->sc_notify_buf.bNotification) {
486 case UCDC_N_SERIAL_STATE:
488 * Set the serial state in ucom driver based on
489 * the bits from the notify message
491 if (UGETW(sc->sc_notify_buf.wLength) != 2) {
492 device_printf(sc->sc_dev,
493 "Invalid notification length! (%d)\n",
494 UGETW(sc->sc_notify_buf.wLength));
497 DPRINTF(("%s: notify bytes = %02x%02x\n",
498 device_get_nameunit(sc->sc_dev),
499 sc->sc_notify_buf.data[0],
500 sc->sc_notify_buf.data[1]));
501 /* Currently, lsr is always zero. */
502 sc->sc_lsr = sc->sc_msr = 0;
503 mstatus = sc->sc_notify_buf.data[0];
505 if (ISSET(mstatus, UCDC_N_SERIAL_RI))
506 sc->sc_msr |= SER_RI;
507 if (ISSET(mstatus, UCDC_N_SERIAL_DSR))
508 sc->sc_msr |= SER_DSR;
509 if (ISSET(mstatus, UCDC_N_SERIAL_DCD))
510 sc->sc_msr |= SER_DCD;
511 /* Deferred notifying to the ucom layer */
512 taskqueue_enqueue(taskqueue_swi_giant, &sc->sc_task);
515 DPRINTF(("%s: unknown notify message: %02x\n",
516 device_get_nameunit(sc->sc_dev),
517 sc->sc_notify_buf.bNotification));
523 umodem_notify(void *arg, int count)
525 struct umodem_softc *sc;
527 sc = (struct umodem_softc *)arg;
528 if (sc->sc_ucom.sc_dying)
530 ucom_status_change(&sc->sc_ucom);
534 umodem_get_caps(usbd_device_handle dev, int *cm, int *acm)
536 usb_cdc_cm_descriptor_t *cmd;
537 usb_cdc_acm_descriptor_t *cad;
541 cmd = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
543 DPRINTF(("umodem_get_desc: no CM desc\n"));
546 *cm = cmd->bmCapabilities;
548 cad = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_ACM);
550 DPRINTF(("umodem_get_desc: no ACM desc\n"));
553 *acm = cad->bmCapabilities;
557 umodem_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
559 struct umodem_softc *sc = addr;
561 DPRINTF(("umodem_get_status:\n"));
570 umodem_param(void *addr, int portno, struct termios *t)
572 struct umodem_softc *sc = addr;
574 usb_cdc_line_state_t ls;
576 DPRINTF(("umodem_param: sc=%p\n", sc));
578 USETDW(ls.dwDTERate, t->c_ospeed);
579 if (ISSET(t->c_cflag, CSTOPB))
580 ls.bCharFormat = UCDC_STOP_BIT_2;
582 ls.bCharFormat = UCDC_STOP_BIT_1;
583 if (ISSET(t->c_cflag, PARENB)) {
584 if (ISSET(t->c_cflag, PARODD))
585 ls.bParityType = UCDC_PARITY_ODD;
587 ls.bParityType = UCDC_PARITY_EVEN;
589 ls.bParityType = UCDC_PARITY_NONE;
590 switch (ISSET(t->c_cflag, CSIZE)) {
605 err = umodem_set_line_coding(sc, &ls);
607 DPRINTF(("umodem_param: err=%s\n", usbd_errstr(err)));
614 umodem_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
617 struct umodem_softc *sc = addr;
620 if (sc->sc_ucom.sc_dying)
623 DPRINTF(("umodemioctl: cmd=0x%08lx\n", cmd));
626 case USB_GET_CM_OVER_DATA:
627 *(int *)data = sc->sc_cm_over_data;
630 case USB_SET_CM_OVER_DATA:
631 if (*(int *)data != sc->sc_cm_over_data) {
637 DPRINTF(("umodemioctl: unknown\n"));
646 umodem_dtr(struct umodem_softc *sc, int onoff)
648 DPRINTF(("umodem_modem: onoff=%d\n", onoff));
650 if (sc->sc_dtr == onoff)
654 umodem_set_line_state(sc);
658 umodem_rts(struct umodem_softc *sc, int onoff)
660 DPRINTF(("umodem_modem: onoff=%d\n", onoff));
662 if (sc->sc_rts == onoff)
666 umodem_set_line_state(sc);
670 umodem_set_line_state(struct umodem_softc *sc)
672 usb_device_request_t req;
675 ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
676 (sc->sc_rts ? UCDC_LINE_RTS : 0);
677 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
678 req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
679 USETW(req.wValue, ls);
680 USETW(req.wIndex, sc->sc_ctl_iface_no);
681 USETW(req.wLength, 0);
683 (void)usbd_do_request(sc->sc_udev, &req, 0);
688 umodem_break(struct umodem_softc *sc, int onoff)
690 usb_device_request_t req;
692 DPRINTF(("umodem_break: onoff=%d\n", onoff));
694 if (!(sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK))
697 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
698 req.bRequest = UCDC_SEND_BREAK;
699 USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
700 USETW(req.wIndex, sc->sc_ctl_iface_no);
701 USETW(req.wLength, 0);
703 (void)usbd_do_request(sc->sc_udev, &req, 0);
707 umodem_set(void *addr, int portno, int reg, int onoff)
709 struct umodem_softc *sc = addr;
713 umodem_dtr(sc, onoff);
716 umodem_rts(sc, onoff);
719 umodem_break(sc, onoff);
727 umodem_set_line_coding(struct umodem_softc *sc, usb_cdc_line_state_t *state)
729 usb_device_request_t req;
732 DPRINTF(("umodem_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
733 UGETDW(state->dwDTERate), state->bCharFormat,
734 state->bParityType, state->bDataBits));
736 if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
737 DPRINTF(("umodem_set_line_coding: already set\n"));
738 return (USBD_NORMAL_COMPLETION);
741 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
742 req.bRequest = UCDC_SET_LINE_CODING;
743 USETW(req.wValue, 0);
744 USETW(req.wIndex, sc->sc_ctl_iface_no);
745 USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
747 err = usbd_do_request(sc->sc_udev, &req, state);
749 DPRINTF(("umodem_set_line_coding: failed, err=%s\n",
754 sc->sc_line_state = *state;
756 return (USBD_NORMAL_COMPLETION);
760 umodem_get_desc(usbd_device_handle dev, int type, int subtype)
762 usb_descriptor_t *desc;
763 usb_config_descriptor_t *cd = usbd_get_config_descriptor(dev);
764 uByte *p = (uByte *)cd;
765 uByte *end = p + UGETW(cd->wTotalLength);
768 desc = (usb_descriptor_t *)p;
769 if (desc->bDescriptorType == type &&
770 desc->bDescriptorSubtype == subtype)
779 umodem_set_comm_feature(struct umodem_softc *sc, int feature, int state)
781 usb_device_request_t req;
783 usb_cdc_abstract_state_t ast;
785 DPRINTF(("umodem_set_comm_feature: feature=%d state=%d\n", feature,
788 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
789 req.bRequest = UCDC_SET_COMM_FEATURE;
790 USETW(req.wValue, feature);
791 USETW(req.wIndex, sc->sc_ctl_iface_no);
792 USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH);
793 USETW(ast.wState, state);
795 err = usbd_do_request(sc->sc_udev, &req, &ast);
797 DPRINTF(("umodem_set_comm_feature: feature=%d, err=%s\n",
798 feature, usbd_errstr(err)));
802 return (USBD_NORMAL_COMPLETION);
806 umodem_detach(device_t self)
808 struct umodem_softc *sc = device_get_softc(self);
811 DPRINTF(("umodem_detach: sc=%p\n", sc));
813 if (sc->sc_notify_pipe != NULL) {
814 usbd_abort_pipe(sc->sc_notify_pipe);
815 usbd_close_pipe(sc->sc_notify_pipe);
816 sc->sc_notify_pipe = NULL;
819 sc->sc_ucom.sc_dying = 1;
820 rv = ucom_detach(&sc->sc_ucom);