Home | History | Annotate | Line # | Download | only in usb
umodem_common.c revision 1.3.2.4
      1 /*	$NetBSD: umodem_common.c,v 1.3.2.4 2005/04/17 10:30:40 tron Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (lennart (at) augustsson.net) at
      9  * Carlstedt Research & Technology.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *        This product includes software developed by the NetBSD
     22  *        Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Comm Class spec:  http://www.usb.org/developers/devclass_docs/usbccs10.pdf
     42  *                   http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
     43  */
     44 
     45 /*
     46  * TODO:
     47  * - Add error recovery in various places; the big problem is what
     48  *   to do in a callback if there is an error.
     49  * - Implement a Call Device for modems without multiplexed commands.
     50  *
     51  */
     52 
     53 #include <sys/cdefs.h>
     54 __KERNEL_RCSID(0, "$NetBSD: umodem_common.c,v 1.3.2.4 2005/04/17 10:30:40 tron Exp $");
     55 
     56 #include <sys/param.h>
     57 #include <sys/systm.h>
     58 #include <sys/kernel.h>
     59 #include <sys/ioctl.h>
     60 #include <sys/conf.h>
     61 #include <sys/tty.h>
     62 #include <sys/file.h>
     63 #include <sys/select.h>
     64 #include <sys/proc.h>
     65 #include <sys/vnode.h>
     66 #include <sys/device.h>
     67 #include <sys/poll.h>
     68 
     69 #include <dev/usb/usb.h>
     70 #include <dev/usb/usbcdc.h>
     71 
     72 #include <dev/usb/usbdi.h>
     73 #include <dev/usb/usbdi_util.h>
     74 #include <dev/usb/usbdevs.h>
     75 #include <dev/usb/usb_quirks.h>
     76 
     77 #include <dev/usb/usbdevs.h>
     78 #include <dev/usb/ucomvar.h>
     79 #include <dev/usb/umodemvar.h>
     80 
     81 #ifdef UMODEM_DEBUG
     82 #define DPRINTFN(n, x)	if (umodemdebug > (n)) logprintf x
     83 int	umodemdebug = 0;
     84 #else
     85 #define DPRINTFN(n, x)
     86 #endif
     87 #define DPRINTF(x) DPRINTFN(0, x)
     88 
     89 /*
     90  * These are the maximum number of bytes transferred per frame.
     91  * If some really high speed devices should use this driver they
     92  * may need to be increased, but this is good enough for normal modems.
     93  */
     94 #define UMODEMIBUFSIZE 64
     95 #define UMODEMOBUFSIZE 256
     96 
     97 Static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
     98 					   int feature, int state);
     99 Static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
    100 					  usb_cdc_line_state_t *state);
    101 
    102 Static void	umodem_dtr(struct umodem_softc *, int);
    103 Static void	umodem_rts(struct umodem_softc *, int);
    104 Static void	umodem_break(struct umodem_softc *, int);
    105 Static void	umodem_set_line_state(struct umodem_softc *);
    106 Static void	umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
    107 
    108 int
    109 umodem_common_attach(device_ptr_t self, struct umodem_softc *sc,
    110 		     struct usb_attach_arg *uaa, struct ucom_attach_args *uca)
    111 {
    112 	usbd_device_handle dev = uaa->device;
    113 	usb_interface_descriptor_t *id;
    114 	usb_endpoint_descriptor_t *ed;
    115 	char devinfo[1024];
    116 	usbd_status err;
    117 	int data_ifcno;
    118 	int i;
    119 
    120 	usbd_devinfo(uaa->device, 0, devinfo, sizeof(devinfo));
    121 	USB_ATTACH_SETUP;
    122 
    123 	sc->sc_udev = dev;
    124 	sc->sc_ctl_iface = uaa->iface;
    125 
    126 	id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
    127 	printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
    128 	       devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
    129 	sc->sc_ctl_iface_no = id->bInterfaceNumber;
    130 
    131 	/* Get the data interface no. */
    132 	sc->sc_data_iface_no = data_ifcno =
    133 	    umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap, id);
    134 
    135 	if (data_ifcno == -1) {
    136 		printf("%s: no pointer to data interface\n",
    137 		       USBDEVNAME(sc->sc_dev));
    138 		goto bad;
    139 	}
    140 
    141 	printf("%s: data interface %d, has %sCM over data, has %sbreak\n",
    142 	       USBDEVNAME(sc->sc_dev), data_ifcno,
    143 	       sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
    144 	       sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
    145 
    146 	/* Get the data interface too. */
    147 	for (i = 0; i < uaa->nifaces; i++) {
    148 		if (uaa->ifaces[i] != NULL) {
    149 			id = usbd_get_interface_descriptor(uaa->ifaces[i]);
    150 			if (id != NULL && id->bInterfaceNumber == data_ifcno) {
    151 				sc->sc_data_iface = uaa->ifaces[i];
    152 				uaa->ifaces[i] = NULL;
    153 			}
    154 		}
    155 	}
    156 	if (sc->sc_data_iface == NULL) {
    157 		printf("%s: no data interface\n", USBDEVNAME(sc->sc_dev));
    158 		goto bad;
    159 	}
    160 
    161 	/*
    162 	 * Find the bulk endpoints.
    163 	 * Iterate over all endpoints in the data interface and take note.
    164 	 */
    165 	uca->bulkin = uca->bulkout = -1;
    166 
    167 	id = usbd_get_interface_descriptor(sc->sc_data_iface);
    168 	for (i = 0; i < id->bNumEndpoints; i++) {
    169 		ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
    170 		if (ed == NULL) {
    171 			printf("%s: no endpoint descriptor for %d\n",
    172 				USBDEVNAME(sc->sc_dev), i);
    173 			goto bad;
    174 		}
    175 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    176 		    (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
    177 			uca->bulkin = ed->bEndpointAddress;
    178 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    179 			   (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
    180 			uca->bulkout = ed->bEndpointAddress;
    181 		}
    182 	}
    183 
    184 	if (uca->bulkin == -1) {
    185 		printf("%s: Could not find data bulk in\n",
    186 		       USBDEVNAME(sc->sc_dev));
    187 		goto bad;
    188 	}
    189 	if (uca->bulkout == -1) {
    190 		printf("%s: Could not find data bulk out\n",
    191 			USBDEVNAME(sc->sc_dev));
    192 		goto bad;
    193 	}
    194 
    195 	if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) {
    196 		sc->sc_cm_over_data = 1;
    197 	} else {
    198 		if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
    199 			if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
    200 				err = umodem_set_comm_feature(sc,
    201 				    UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
    202 			else
    203 				err = 0;
    204 			if (err) {
    205 				printf("%s: could not set data multiplex mode\n",
    206 				       USBDEVNAME(sc->sc_dev));
    207 				goto bad;
    208 			}
    209 			sc->sc_cm_over_data = 1;
    210 		}
    211 	}
    212 
    213 	/*
    214 	 * The standard allows for notification messages (to indicate things
    215 	 * like a modem hangup) to come in via an interrupt endpoint
    216 	 * off of the control interface.  Iterate over the endpoints on
    217 	 * the control interface and see if there are any interrupt
    218 	 * endpoints; if there are, then register it.
    219 	 */
    220 
    221 	sc->sc_ctl_notify = -1;
    222 	sc->sc_notify_pipe = NULL;
    223 
    224 	for (i = 0; i < id->bNumEndpoints; i++) {
    225 		ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i);
    226 		if (ed == NULL)
    227 			continue;
    228 
    229 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    230 		    (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
    231 			printf("%s: status change notification available\n",
    232 			       USBDEVNAME(sc->sc_dev));
    233 			sc->sc_ctl_notify = ed->bEndpointAddress;
    234 		}
    235 	}
    236 
    237 	sc->sc_dtr = -1;
    238 
    239 	/* bulkin, bulkout set above */
    240 	uca->ibufsize = UMODEMIBUFSIZE;
    241 	uca->obufsize = UMODEMOBUFSIZE;
    242 	uca->ibufsizepad = UMODEMIBUFSIZE;
    243 	uca->opkthdrlen = 0;
    244 	uca->device = sc->sc_udev;
    245 	uca->iface = sc->sc_data_iface;
    246 	uca->arg = sc;
    247 
    248 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
    249 			   USBDEV(sc->sc_dev));
    250 
    251 	DPRINTF(("umodem_common_attach: sc=%p\n", sc));
    252 	sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, uca,
    253 					    ucomprint, ucomsubmatch);
    254 
    255 	return 0;
    256 
    257  bad:
    258 	sc->sc_dying = 1;
    259 	return 1;
    260 }
    261 
    262 int
    263 umodem_open(void *addr, int portno)
    264 {
    265 	struct umodem_softc *sc = addr;
    266 	int err;
    267 
    268 	DPRINTF(("umodem_open: sc=%p\n", sc));
    269 
    270 	if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) {
    271 		err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify,
    272 		    USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc,
    273 		    &sc->sc_notify_buf, sizeof(sc->sc_notify_buf),
    274 		    umodem_intr, USBD_DEFAULT_INTERVAL);
    275 
    276 		if (err) {
    277 			DPRINTF(("Failed to establish notify pipe: %s\n",
    278 				usbd_errstr(err)));
    279 			return EIO;
    280 		}
    281 	}
    282 
    283 	return 0;
    284 }
    285 
    286 void
    287 umodem_close(void *addr, int portno)
    288 {
    289 	struct umodem_softc *sc = addr;
    290 	int err;
    291 
    292 	DPRINTF(("umodem_close: sc=%p\n", sc));
    293 
    294 	if (sc->sc_notify_pipe != NULL) {
    295 		err = usbd_abort_pipe(sc->sc_notify_pipe);
    296 		if (err)
    297 			printf("%s: abort notify pipe failed: %s\n",
    298 			    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    299 		err = usbd_close_pipe(sc->sc_notify_pipe);
    300 		if (err)
    301 			printf("%s: close notify pipe failed: %s\n",
    302 			    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    303 		sc->sc_notify_pipe = NULL;
    304 	}
    305 }
    306 
    307 Static void
    308 umodem_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
    309 {
    310 	struct umodem_softc *sc = priv;
    311 	u_char mstatus;
    312 
    313 	if (sc->sc_dying)
    314 		return;
    315 
    316 	if (status != USBD_NORMAL_COMPLETION) {
    317 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
    318 			return;
    319 		printf("%s: abnormal status: %s\n", USBDEVNAME(sc->sc_dev),
    320 		       usbd_errstr(status));
    321 		return;
    322 	}
    323 
    324 	if (sc->sc_notify_buf.bmRequestType != UCDC_NOTIFICATION) {
    325 		DPRINTF(("%s: unknown message type (%02x) on notify pipe\n",
    326 			 USBDEVNAME(sc->sc_dev),
    327 			 sc->sc_notify_buf.bmRequestType));
    328 		return;
    329 	}
    330 
    331 	switch (sc->sc_notify_buf.bNotification) {
    332 	case UCDC_N_SERIAL_STATE:
    333 		/*
    334 		 * Set the serial state in ucom driver based on
    335 		 * the bits from the notify message
    336 		 */
    337 		if (UGETW(sc->sc_notify_buf.wLength) != 2) {
    338 			printf("%s: Invalid notification length! (%d)\n",
    339 			       USBDEVNAME(sc->sc_dev),
    340 			       UGETW(sc->sc_notify_buf.wLength));
    341 			break;
    342 		}
    343 		DPRINTF(("%s: notify bytes = %02x%02x\n",
    344 			 USBDEVNAME(sc->sc_dev),
    345 			 sc->sc_notify_buf.data[0],
    346 			 sc->sc_notify_buf.data[1]));
    347 		/* Currently, lsr is always zero. */
    348 		sc->sc_lsr = sc->sc_msr = 0;
    349 		mstatus = sc->sc_notify_buf.data[0];
    350 
    351 		if (ISSET(mstatus, UCDC_N_SERIAL_RI))
    352 			sc->sc_msr |= UMSR_RI;
    353 		if (ISSET(mstatus, UCDC_N_SERIAL_DSR))
    354 			sc->sc_msr |= UMSR_DSR;
    355 		if (ISSET(mstatus, UCDC_N_SERIAL_DCD))
    356 			sc->sc_msr |= UMSR_DCD;
    357 		ucom_status_change((struct ucom_softc *)sc->sc_subdev);
    358 		break;
    359 	default:
    360 		DPRINTF(("%s: unknown notify message: %02x\n",
    361 			 USBDEVNAME(sc->sc_dev),
    362 			 sc->sc_notify_buf.bNotification));
    363 		break;
    364 	}
    365 }
    366 
    367 int
    368 umodem_get_caps(usbd_device_handle dev, int *cm, int *acm,
    369 		usb_interface_descriptor_t *id)
    370 {
    371 	const usb_cdc_cm_descriptor_t *cmd;
    372 	const usb_cdc_acm_descriptor_t *cad;
    373 	const usb_cdc_union_descriptor_t *cud;
    374 
    375 	*cm = *acm = 0;
    376 
    377 	cmd = (usb_cdc_cm_descriptor_t *)usb_find_desc_if(dev,
    378 							  UDESC_CS_INTERFACE,
    379 							  UDESCSUB_CDC_CM, id);
    380 	if (cmd == NULL) {
    381 		DPRINTF(("umodem_get_caps: no CM desc\n"));
    382 	} else {
    383 		*cm = cmd->bmCapabilities;
    384 	}
    385 
    386 	cad = (usb_cdc_acm_descriptor_t *)usb_find_desc_if(dev,
    387 							   UDESC_CS_INTERFACE,
    388 							   UDESCSUB_CDC_ACM,
    389 							   id);
    390 	if (cad == NULL) {
    391 		DPRINTF(("umodem_get_caps: no ACM desc\n"));
    392 	} else {
    393 		*acm = cad->bmCapabilities;
    394 	}
    395 
    396 	cud = (usb_cdc_union_descriptor_t *)usb_find_desc_if(dev,
    397 							     UDESC_CS_INTERFACE,
    398 							     UDESCSUB_CDC_UNION,
    399 							     id);
    400 	if (cud == NULL) {
    401 		DPRINTF(("umodem_get_caps: no UNION desc\n"));
    402 	}
    403 
    404 	return cmd ? cmd->bDataInterface : cud ? cud->bSlaveInterface[0] : -1;
    405 }
    406 
    407 void
    408 umodem_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    409 {
    410 	struct umodem_softc *sc = addr;
    411 
    412 	DPRINTF(("umodem_get_status:\n"));
    413 
    414 	if (lsr != NULL)
    415 		*lsr = sc->sc_lsr;
    416 	if (msr != NULL)
    417 		*msr = sc->sc_msr;
    418 }
    419 
    420 int
    421 umodem_param(void *addr, int portno, struct termios *t)
    422 {
    423 	struct umodem_softc *sc = addr;
    424 	usbd_status err;
    425 	usb_cdc_line_state_t ls;
    426 
    427 	DPRINTF(("umodem_param: sc=%p\n", sc));
    428 
    429 	USETDW(ls.dwDTERate, t->c_ospeed);
    430 	if (ISSET(t->c_cflag, CSTOPB))
    431 		ls.bCharFormat = UCDC_STOP_BIT_2;
    432 	else
    433 		ls.bCharFormat = UCDC_STOP_BIT_1;
    434 	if (ISSET(t->c_cflag, PARENB)) {
    435 		if (ISSET(t->c_cflag, PARODD))
    436 			ls.bParityType = UCDC_PARITY_ODD;
    437 		else
    438 			ls.bParityType = UCDC_PARITY_EVEN;
    439 	} else
    440 		ls.bParityType = UCDC_PARITY_NONE;
    441 	switch (ISSET(t->c_cflag, CSIZE)) {
    442 	case CS5:
    443 		ls.bDataBits = 5;
    444 		break;
    445 	case CS6:
    446 		ls.bDataBits = 6;
    447 		break;
    448 	case CS7:
    449 		ls.bDataBits = 7;
    450 		break;
    451 	case CS8:
    452 		ls.bDataBits = 8;
    453 		break;
    454 	}
    455 
    456 	err = umodem_set_line_coding(sc, &ls);
    457 	if (err) {
    458 		DPRINTF(("umodem_param: err=%s\n", usbd_errstr(err)));
    459 		return (EPASSTHROUGH);
    460 	}
    461 	return (0);
    462 }
    463 
    464 int
    465 umodem_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
    466 	     usb_proc_ptr p)
    467 {
    468 	struct umodem_softc *sc = addr;
    469 	int error = 0;
    470 
    471 	if (sc->sc_dying)
    472 		return (EIO);
    473 
    474 	DPRINTF(("umodem_ioctl: cmd=0x%08lx\n", cmd));
    475 
    476 	switch (cmd) {
    477 	case USB_GET_CM_OVER_DATA:
    478 		*(int *)data = sc->sc_cm_over_data;
    479 		break;
    480 
    481 	case USB_SET_CM_OVER_DATA:
    482 		if (*(int *)data != sc->sc_cm_over_data) {
    483 			/* XXX change it */
    484 		}
    485 		break;
    486 
    487 	default:
    488 		DPRINTF(("umodem_ioctl: unknown\n"));
    489 		error = EPASSTHROUGH;
    490 		break;
    491 	}
    492 
    493 	return (error);
    494 }
    495 
    496 void
    497 umodem_dtr(struct umodem_softc *sc, int onoff)
    498 {
    499 	DPRINTF(("umodem_dtr: onoff=%d\n", onoff));
    500 
    501 	if (sc->sc_dtr == onoff)
    502 		return;
    503 	sc->sc_dtr = onoff;
    504 
    505 	umodem_set_line_state(sc);
    506 }
    507 
    508 void
    509 umodem_rts(struct umodem_softc *sc, int onoff)
    510 {
    511 	DPRINTF(("umodem_rts: onoff=%d\n", onoff));
    512 
    513 	if (sc->sc_rts == onoff)
    514 		return;
    515 	sc->sc_rts = onoff;
    516 
    517 	umodem_set_line_state(sc);
    518 }
    519 
    520 void
    521 umodem_set_line_state(struct umodem_softc *sc)
    522 {
    523 	usb_device_request_t req;
    524 	int ls;
    525 
    526 	ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
    527 	     (sc->sc_rts ? UCDC_LINE_RTS : 0);
    528 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    529 	req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
    530 	USETW(req.wValue, ls);
    531 	USETW(req.wIndex, sc->sc_ctl_iface_no);
    532 	USETW(req.wLength, 0);
    533 
    534 	(void)usbd_do_request(sc->sc_udev, &req, 0);
    535 
    536 }
    537 
    538 void
    539 umodem_break(struct umodem_softc *sc, int onoff)
    540 {
    541 	usb_device_request_t req;
    542 
    543 	DPRINTF(("umodem_break: onoff=%d\n", onoff));
    544 
    545 	if (!(sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK))
    546 		return;
    547 
    548 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    549 	req.bRequest = UCDC_SEND_BREAK;
    550 	USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
    551 	USETW(req.wIndex, sc->sc_ctl_iface_no);
    552 	USETW(req.wLength, 0);
    553 
    554 	(void)usbd_do_request(sc->sc_udev, &req, 0);
    555 }
    556 
    557 void
    558 umodem_set(void *addr, int portno, int reg, int onoff)
    559 {
    560 	struct umodem_softc *sc = addr;
    561 
    562 	switch (reg) {
    563 	case UCOM_SET_DTR:
    564 		umodem_dtr(sc, onoff);
    565 		break;
    566 	case UCOM_SET_RTS:
    567 		umodem_rts(sc, onoff);
    568 		break;
    569 	case UCOM_SET_BREAK:
    570 		umodem_break(sc, onoff);
    571 		break;
    572 	default:
    573 		break;
    574 	}
    575 }
    576 
    577 usbd_status
    578 umodem_set_line_coding(struct umodem_softc *sc, usb_cdc_line_state_t *state)
    579 {
    580 	usb_device_request_t req;
    581 	usbd_status err;
    582 
    583 	DPRINTF(("umodem_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
    584 		 UGETDW(state->dwDTERate), state->bCharFormat,
    585 		 state->bParityType, state->bDataBits));
    586 
    587 	if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
    588 		DPRINTF(("umodem_set_line_coding: already set\n"));
    589 		return (USBD_NORMAL_COMPLETION);
    590 	}
    591 
    592 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    593 	req.bRequest = UCDC_SET_LINE_CODING;
    594 	USETW(req.wValue, 0);
    595 	USETW(req.wIndex, sc->sc_ctl_iface_no);
    596 	USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
    597 
    598 	err = usbd_do_request(sc->sc_udev, &req, state);
    599 	if (err) {
    600 		DPRINTF(("umodem_set_line_coding: failed, err=%s\n",
    601 			 usbd_errstr(err)));
    602 		return (err);
    603 	}
    604 
    605 	sc->sc_line_state = *state;
    606 
    607 	return (USBD_NORMAL_COMPLETION);
    608 }
    609 
    610 usbd_status
    611 umodem_set_comm_feature(struct umodem_softc *sc, int feature, int state)
    612 {
    613 	usb_device_request_t req;
    614 	usbd_status err;
    615 	usb_cdc_abstract_state_t ast;
    616 
    617 	DPRINTF(("umodem_set_comm_feature: feature=%d state=%d\n", feature,
    618 		 state));
    619 
    620 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    621 	req.bRequest = UCDC_SET_COMM_FEATURE;
    622 	USETW(req.wValue, feature);
    623 	USETW(req.wIndex, sc->sc_ctl_iface_no);
    624 	USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH);
    625 	USETW(ast.wState, state);
    626 
    627 	err = usbd_do_request(sc->sc_udev, &req, &ast);
    628 	if (err) {
    629 		DPRINTF(("umodem_set_comm_feature: feature=%d, err=%s\n",
    630 			 feature, usbd_errstr(err)));
    631 		return (err);
    632 	}
    633 
    634 	return (USBD_NORMAL_COMPLETION);
    635 }
    636 
    637 int
    638 umodem_common_activate(struct umodem_softc *sc, enum devact act)
    639 {
    640 	int rv = 0;
    641 
    642 	switch (act) {
    643 	case DVACT_ACTIVATE:
    644 		return (EOPNOTSUPP);
    645 
    646 	case DVACT_DEACTIVATE:
    647 		sc->sc_dying = 1;
    648 		if (sc->sc_subdev)
    649 			rv = config_deactivate(sc->sc_subdev);
    650 		break;
    651 	}
    652 	return (rv);
    653 }
    654 
    655 int
    656 umodem_common_detach(struct umodem_softc *sc, int flags)
    657 {
    658 	int rv = 0;
    659 
    660 	DPRINTF(("umodem_common_detach: sc=%p flags=%d\n", sc, flags));
    661 
    662 	sc->sc_dying = 1;
    663 
    664 	if (sc->sc_subdev != NULL)
    665 		rv = config_detach(sc->sc_subdev, flags);
    666 
    667 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
    668 			   USBDEV(sc->sc_dev));
    669 
    670 	return (rv);
    671 }
    672