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)) logprintf 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 * If some really high speed devices should use this driver they
136 * may need to be increased, but this is good enough for normal modems.
138 #define UMODEMIBUFSIZE 64
139 #define UMODEMOBUFSIZE 256
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, usb_proc_ptr );
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);
232 USB_MATCH_START(umodem, uaa);
233 usb_interface_descriptor_t *id;
234 usb_device_descriptor_t *dd;
237 if (uaa->iface == NULL)
238 return (UMATCH_NONE);
240 id = usbd_get_interface_descriptor(uaa->iface);
241 dd = usbd_get_device_descriptor(uaa->device);
242 if (id == NULL || dd == NULL)
243 return (UMATCH_NONE);
246 for (i = 0; umodem_products[i].vendor != 0; i++) {
247 if (umodem_products[i].vendor == UGETW(dd->idVendor) &&
248 umodem_products[i].product == UGETW(dd->idProduct) &&
249 umodem_products[i].interface == id->bInterfaceNumber) {
250 ret = UMATCH_VENDOR_PRODUCT;
255 if (ret == UMATCH_NONE &&
256 id->bInterfaceClass == UICLASS_CDC &&
257 id->bInterfaceSubClass == UISUBCLASS_ABSTRACT_CONTROL_MODEL &&
258 id->bInterfaceProtocol == UIPROTO_CDC_AT)
259 ret = UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO;
261 if (ret == UMATCH_NONE)
264 umodem_get_caps(uaa->device, &cm, &acm);
265 if (!(cm & USB_CDC_CM_DOES_CM) ||
266 !(cm & USB_CDC_CM_OVER_DATA) ||
267 !(acm & USB_CDC_ACM_HAS_LINE))
268 return (UMATCH_NONE);
275 USB_ATTACH_START(umodem, sc, uaa);
276 usbd_device_handle dev = uaa->device;
277 usb_interface_descriptor_t *id;
278 usb_endpoint_descriptor_t *ed;
279 usb_cdc_cm_descriptor_t *cmd;
280 char *devinfo = NULL;
285 struct ucom_softc *ucom;
287 devinfo = malloc(1024, M_USBDEV, M_WAITOK);
288 usbd_devinfo(dev, 0, devinfo);
292 device_set_desc_copy(self, devinfo);
294 ucom->sc_iface = uaa->iface;
295 /*USB_ATTACH_SETUP; */
298 sc->sc_ctl_iface = uaa->iface;
300 devname = device_get_nameunit(sc->sc_dev);
301 /* XXX ? use something else ? XXX */
302 id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
303 printf("%s: %s, iclass %d/%d\n", devname, devinfo,
304 id->bInterfaceClass, id->bInterfaceSubClass);
305 sc->sc_ctl_iface_no = id->bInterfaceNumber;
307 umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap);
309 /* Get the data interface no. */
310 cmd = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
312 printf("%s: no CM descriptor\n", devname);
315 sc->sc_data_iface_no = data_ifcno = cmd->bDataInterface;
317 printf("%s: data interface %d, has %sCM over data, has %sbreak\n",
319 sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
320 sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
322 /* Get the data interface too. */
323 for (i = 0; i < uaa->nifaces; i++) {
324 if (uaa->ifaces[i] != NULL) {
325 id = usbd_get_interface_descriptor(uaa->ifaces[i]);
326 if (id != NULL && id->bInterfaceNumber == data_ifcno) {
327 sc->sc_data_iface = uaa->ifaces[i];
328 uaa->ifaces[i] = NULL;
332 if (sc->sc_data_iface == NULL) {
333 printf("%s: no data interface\n", devname);
336 ucom->sc_iface = sc->sc_data_iface;
339 * Find the bulk endpoints.
340 * Iterate over all endpoints in the data interface and take note.
342 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
344 id = usbd_get_interface_descriptor(sc->sc_data_iface);
345 for (i = 0; i < id->bNumEndpoints; i++) {
346 ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
348 printf("%s: no endpoint descriptor for %d\n", devname,
352 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
353 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
354 ucom->sc_bulkin_no = ed->bEndpointAddress;
355 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
356 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
357 ucom->sc_bulkout_no = ed->bEndpointAddress;
361 if (ucom->sc_bulkin_no == -1) {
362 printf("%s: Could not find data bulk in\n", devname);
365 if (ucom->sc_bulkout_no == -1) {
366 printf("%s: Could not find data bulk out\n", devname);
370 if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) {
371 DPRINTF(("Quirk says to assume CM over data\n"));
372 sc->sc_cm_over_data = 1;
374 if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
375 if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
376 err = umodem_set_comm_feature(sc,
377 UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
381 printf("%s: could not set data multiplex mode\n",
385 sc->sc_cm_over_data = 1;
390 * The standard allows for notification messages (to indicate things
391 * like a modem hangup) to come in via an interrupt endpoint
392 * off of the control interface. Iterate over the endpoints on
393 * the control interface and see if there are any interrupt
394 * endpoints; if there are, then register it.
397 sc->sc_ctl_notify = -1;
398 sc->sc_notify_pipe = NULL;
400 for (i = 0; i < id->bNumEndpoints; i++) {
401 ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i);
405 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
406 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
407 printf("%s: status change notification available\n",
409 sc->sc_ctl_notify = ed->bEndpointAddress;
415 ucom->sc_parent = sc;
416 ucom->sc_portno = UCOM_UNK_PORTNO;
417 /* bulkin, bulkout set above */
418 ucom->sc_ibufsize = UMODEMIBUFSIZE;
419 ucom->sc_obufsize = UMODEMOBUFSIZE;
420 ucom->sc_ibufsizepad = UMODEMIBUFSIZE;
421 ucom->sc_opkthdrlen = 0;
422 ucom->sc_callback = &umodem_callback;
424 TASK_INIT(&sc->sc_task, 0, umodem_notify, sc);
425 ucom_attach(&sc->sc_ucom);
427 free(devinfo, M_USBDEV);
428 USB_ATTACH_SUCCESS_RETURN;
432 free(devinfo, M_USBDEV);
433 USB_ATTACH_ERROR_RETURN;
437 umodem_open(void *addr, int portno)
439 struct umodem_softc *sc = addr;
442 DPRINTF(("umodem_open: sc=%p\n", sc));
444 if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) {
445 err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify,
446 USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc,
447 &sc->sc_notify_buf, sizeof(sc->sc_notify_buf),
448 umodem_intr, USBD_DEFAULT_INTERVAL);
451 DPRINTF(("Failed to establish notify pipe: %s\n",
461 umodem_close(void *addr, int portno)
463 struct umodem_softc *sc = addr;
466 DPRINTF(("umodem_close: sc=%p\n", sc));
468 if (sc->sc_notify_pipe != NULL) {
469 err = usbd_abort_pipe(sc->sc_notify_pipe);
471 printf("%s: abort notify pipe failed: %s\n",
472 device_get_nameunit(sc->sc_dev), usbd_errstr(err));
473 err = usbd_close_pipe(sc->sc_notify_pipe);
475 printf("%s: close notify pipe failed: %s\n",
476 device_get_nameunit(sc->sc_dev), usbd_errstr(err));
477 sc->sc_notify_pipe = NULL;
482 umodem_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
484 struct umodem_softc *sc = priv;
487 if (sc->sc_ucom.sc_dying)
490 if (status != USBD_NORMAL_COMPLETION) {
491 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
493 printf("%s: abnormal status: %s\n", device_get_nameunit(sc->sc_dev),
494 usbd_errstr(status));
498 if (sc->sc_notify_buf.bmRequestType != UCDC_NOTIFICATION) {
499 DPRINTF(("%s: unknown message type (%02x) on notify pipe\n",
500 device_get_nameunit(sc->sc_dev),
501 sc->sc_notify_buf.bmRequestType));
505 switch (sc->sc_notify_buf.bNotification) {
506 case UCDC_N_SERIAL_STATE:
508 * Set the serial state in ucom driver based on
509 * the bits from the notify message
511 if (UGETW(sc->sc_notify_buf.wLength) != 2) {
512 printf("%s: Invalid notification length! (%d)\n",
513 device_get_nameunit(sc->sc_dev),
514 UGETW(sc->sc_notify_buf.wLength));
517 DPRINTF(("%s: notify bytes = %02x%02x\n",
518 device_get_nameunit(sc->sc_dev),
519 sc->sc_notify_buf.data[0],
520 sc->sc_notify_buf.data[1]));
521 /* Currently, lsr is always zero. */
522 sc->sc_lsr = sc->sc_msr = 0;
523 mstatus = sc->sc_notify_buf.data[0];
525 if (ISSET(mstatus, UCDC_N_SERIAL_RI))
526 sc->sc_msr |= SER_RI;
527 if (ISSET(mstatus, UCDC_N_SERIAL_DSR))
528 sc->sc_msr |= SER_DSR;
529 if (ISSET(mstatus, UCDC_N_SERIAL_DCD))
530 sc->sc_msr |= SER_DCD;
531 /* Deferred notifying to the ucom layer */
532 taskqueue_enqueue(taskqueue_swi_giant, &sc->sc_task);
535 DPRINTF(("%s: unknown notify message: %02x\n",
536 device_get_nameunit(sc->sc_dev),
537 sc->sc_notify_buf.bNotification));
543 umodem_notify(void *arg, int count)
545 struct umodem_softc *sc;
547 sc = (struct umodem_softc *)arg;
548 if (sc->sc_ucom.sc_dying)
550 ucom_status_change(&sc->sc_ucom);
554 umodem_get_caps(usbd_device_handle dev, int *cm, int *acm)
556 usb_cdc_cm_descriptor_t *cmd;
557 usb_cdc_acm_descriptor_t *cad;
561 cmd = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
563 DPRINTF(("umodem_get_desc: no CM desc\n"));
566 *cm = cmd->bmCapabilities;
568 cad = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_ACM);
570 DPRINTF(("umodem_get_desc: no ACM desc\n"));
573 *acm = cad->bmCapabilities;
577 umodem_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
579 struct umodem_softc *sc = addr;
581 DPRINTF(("umodem_get_status:\n"));
590 umodem_param(void *addr, int portno, struct termios *t)
592 struct umodem_softc *sc = addr;
594 usb_cdc_line_state_t ls;
596 DPRINTF(("umodem_param: sc=%p\n", sc));
598 USETDW(ls.dwDTERate, t->c_ospeed);
599 if (ISSET(t->c_cflag, CSTOPB))
600 ls.bCharFormat = UCDC_STOP_BIT_2;
602 ls.bCharFormat = UCDC_STOP_BIT_1;
603 if (ISSET(t->c_cflag, PARENB)) {
604 if (ISSET(t->c_cflag, PARODD))
605 ls.bParityType = UCDC_PARITY_ODD;
607 ls.bParityType = UCDC_PARITY_EVEN;
609 ls.bParityType = UCDC_PARITY_NONE;
610 switch (ISSET(t->c_cflag, CSIZE)) {
625 err = umodem_set_line_coding(sc, &ls);
627 DPRINTF(("umodem_param: err=%s\n", usbd_errstr(err)));
634 umodem_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
637 struct umodem_softc *sc = addr;
640 if (sc->sc_ucom.sc_dying)
643 DPRINTF(("umodemioctl: cmd=0x%08lx\n", cmd));
646 case USB_GET_CM_OVER_DATA:
647 *(int *)data = sc->sc_cm_over_data;
650 case USB_SET_CM_OVER_DATA:
651 if (*(int *)data != sc->sc_cm_over_data) {
657 DPRINTF(("umodemioctl: unknown\n"));
666 umodem_dtr(struct umodem_softc *sc, int onoff)
668 DPRINTF(("umodem_modem: onoff=%d\n", onoff));
670 if (sc->sc_dtr == onoff)
674 umodem_set_line_state(sc);
678 umodem_rts(struct umodem_softc *sc, int onoff)
680 DPRINTF(("umodem_modem: onoff=%d\n", onoff));
682 if (sc->sc_rts == onoff)
686 umodem_set_line_state(sc);
690 umodem_set_line_state(struct umodem_softc *sc)
692 usb_device_request_t req;
695 ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
696 (sc->sc_rts ? UCDC_LINE_RTS : 0);
697 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
698 req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
699 USETW(req.wValue, ls);
700 USETW(req.wIndex, sc->sc_ctl_iface_no);
701 USETW(req.wLength, 0);
703 (void)usbd_do_request(sc->sc_udev, &req, 0);
708 umodem_break(struct umodem_softc *sc, int onoff)
710 usb_device_request_t req;
712 DPRINTF(("umodem_break: onoff=%d\n", onoff));
714 if (!(sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK))
717 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
718 req.bRequest = UCDC_SEND_BREAK;
719 USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
720 USETW(req.wIndex, sc->sc_ctl_iface_no);
721 USETW(req.wLength, 0);
723 (void)usbd_do_request(sc->sc_udev, &req, 0);
727 umodem_set(void *addr, int portno, int reg, int onoff)
729 struct umodem_softc *sc = addr;
733 umodem_dtr(sc, onoff);
736 umodem_rts(sc, onoff);
739 umodem_break(sc, onoff);
747 umodem_set_line_coding(struct umodem_softc *sc, usb_cdc_line_state_t *state)
749 usb_device_request_t req;
752 DPRINTF(("umodem_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
753 UGETDW(state->dwDTERate), state->bCharFormat,
754 state->bParityType, state->bDataBits));
756 if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
757 DPRINTF(("umodem_set_line_coding: already set\n"));
758 return (USBD_NORMAL_COMPLETION);
761 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
762 req.bRequest = UCDC_SET_LINE_CODING;
763 USETW(req.wValue, 0);
764 USETW(req.wIndex, sc->sc_ctl_iface_no);
765 USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
767 err = usbd_do_request(sc->sc_udev, &req, state);
769 DPRINTF(("umodem_set_line_coding: failed, err=%s\n",
774 sc->sc_line_state = *state;
776 return (USBD_NORMAL_COMPLETION);
780 umodem_get_desc(usbd_device_handle dev, int type, int subtype)
782 usb_descriptor_t *desc;
783 usb_config_descriptor_t *cd = usbd_get_config_descriptor(dev);
784 uByte *p = (uByte *)cd;
785 uByte *end = p + UGETW(cd->wTotalLength);
788 desc = (usb_descriptor_t *)p;
789 if (desc->bDescriptorType == type &&
790 desc->bDescriptorSubtype == subtype)
799 umodem_set_comm_feature(struct umodem_softc *sc, int feature, int state)
801 usb_device_request_t req;
803 usb_cdc_abstract_state_t ast;
805 DPRINTF(("umodem_set_comm_feature: feature=%d state=%d\n", feature,
808 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
809 req.bRequest = UCDC_SET_COMM_FEATURE;
810 USETW(req.wValue, feature);
811 USETW(req.wIndex, sc->sc_ctl_iface_no);
812 USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH);
813 USETW(ast.wState, state);
815 err = usbd_do_request(sc->sc_udev, &req, &ast);
817 DPRINTF(("umodem_set_comm_feature: feature=%d, err=%s\n",
818 feature, usbd_errstr(err)));
822 return (USBD_NORMAL_COMPLETION);
827 USB_DETACH_START(umodem, sc);
830 DPRINTF(("umodem_detach: sc=%p\n", sc));
832 if (sc->sc_notify_pipe != NULL) {
833 usbd_abort_pipe(sc->sc_notify_pipe);
834 usbd_close_pipe(sc->sc_notify_pipe);
835 sc->sc_notify_pipe = NULL;
838 sc->sc_ucom.sc_dying = 1;
839 rv = ucom_detach(&sc->sc_ucom);