Home | History | Annotate | Line # | Download | only in usb
umodem_common.c revision 1.12
      1 /*	$NetBSD: umodem_common.c,v 1.12 2007/03/13 13:51:56 drochner 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.12 2007/03/13 13:51:56 drochner 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/ucomvar.h>
     78 #include <dev/usb/umodemvar.h>
     79 
     80 #ifdef UMODEM_DEBUG
     81 #define DPRINTFN(n, x)	if (umodemdebug > (n)) logprintf x
     82 int	umodemdebug = 0;
     83 #else
     84 #define DPRINTFN(n, x)
     85 #endif
     86 #define DPRINTF(x) DPRINTFN(0, x)
     87 
     88 /*
     89  * These are the maximum number of bytes transferred per frame.
     90  * If some really high speed devices should use this driver they
     91  * may need to be increased, but this is good enough for normal modems.
     92  *
     93  * Note: increased from 64/256, to better support EVDO wireless PPP.
     94  * The sizes should not be increased further, or there
     95  * will be problems with contiguous storage allocation.
     96  */
     97 #define UMODEMIBUFSIZE 4096
     98 #define UMODEMOBUFSIZE 4096
     99 
    100 Static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
    101 					   int feature, int state);
    102 Static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
    103 					  usb_cdc_line_state_t *state);
    104 
    105 Static void	umodem_dtr(struct umodem_softc *, int);
    106 Static void	umodem_rts(struct umodem_softc *, int);
    107 Static void	umodem_break(struct umodem_softc *, int);
    108 Static void	umodem_set_line_state(struct umodem_softc *);
    109 Static void	umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
    110 
    111 int
    112 umodem_common_attach(device_ptr_t self, struct umodem_softc *sc,
    113 		     struct usbif_attach_arg *uaa, struct ucom_attach_args *uca)
    114 {
    115 	usbd_device_handle dev = uaa->device;
    116 	usb_interface_descriptor_t *id;
    117 	usb_endpoint_descriptor_t *ed;
    118 	char *devinfop;
    119 	usbd_status err;
    120 	int data_ifcno;
    121 	int i;
    122 
    123 	devinfop = usbd_devinfo_alloc(uaa->device, 0);
    124 	USB_ATTACH_SETUP;
    125 
    126 	sc->sc_udev = dev;
    127 	sc->sc_ctl_iface = uaa->iface;
    128 
    129 	id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
    130 	printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
    131 	       devinfop, id->bInterfaceClass, id->bInterfaceSubClass);
    132 	usbd_devinfo_free(devinfop);
    133 	sc->sc_ctl_iface_no = id->bInterfaceNumber;
    134 
    135 	/* Get the data interface no. */
    136 	sc->sc_data_iface_no = data_ifcno =
    137 	    umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap, id);
    138 
    139 	if (data_ifcno == -1) {
    140 		printf("%s: no pointer to data interface\n",
    141 		       USBDEVNAME(sc->sc_dev));
    142 		goto bad;
    143 	}
    144 
    145 	printf("%s: data interface %d, has %sCM over data, has %sbreak\n",
    146 	       USBDEVNAME(sc->sc_dev), data_ifcno,
    147 	       sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
    148 	       sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
    149 
    150 	/* Get the data interface too. */
    151 	for (i = 0; i < uaa->nifaces; i++) {
    152 		if (uaa->ifaces[i] != NULL) {
    153 			id = usbd_get_interface_descriptor(uaa->ifaces[i]);
    154 			if (id != NULL && id->bInterfaceNumber == data_ifcno) {
    155 				sc->sc_data_iface = uaa->ifaces[i];
    156 				uaa->ifaces[i] = NULL;
    157 			}
    158 		}
    159 	}
    160 	if (sc->sc_data_iface == NULL) {
    161 		printf("%s: no data interface\n", USBDEVNAME(sc->sc_dev));
    162 		goto bad;
    163 	}
    164 
    165 	/*
    166 	 * Find the bulk endpoints.
    167 	 * Iterate over all endpoints in the data interface and take note.
    168 	 */
    169 	uca->bulkin = uca->bulkout = -1;
    170 
    171 	id = usbd_get_interface_descriptor(sc->sc_data_iface);
    172 	for (i = 0; i < id->bNumEndpoints; i++) {
    173 		ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
    174 		if (ed == NULL) {
    175 			printf("%s: no endpoint descriptor for %d\n",
    176 				USBDEVNAME(sc->sc_dev), i);
    177 			goto bad;
    178 		}
    179 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    180 		    (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
    181 			uca->bulkin = ed->bEndpointAddress;
    182 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    183 			   (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
    184 			uca->bulkout = ed->bEndpointAddress;
    185 		}
    186 	}
    187 
    188 	if (uca->bulkin == -1) {
    189 		printf("%s: Could not find data bulk in\n",
    190 		       USBDEVNAME(sc->sc_dev));
    191 		goto bad;
    192 	}
    193 	if (uca->bulkout == -1) {
    194 		printf("%s: Could not find data bulk out\n",
    195 			USBDEVNAME(sc->sc_dev));
    196 		goto bad;
    197 	}
    198 
    199 	if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) {
    200 		sc->sc_cm_over_data = 1;
    201 	} else {
    202 		if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
    203 			if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
    204 				err = umodem_set_comm_feature(sc,
    205 				    UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
    206 			else
    207 				err = 0;
    208 			if (err) {
    209 				printf("%s: could not set data multiplex mode\n",
    210 				       USBDEVNAME(sc->sc_dev));
    211 				goto bad;
    212 			}
    213 			sc->sc_cm_over_data = 1;
    214 		}
    215 	}
    216 
    217 	/*
    218 	 * The standard allows for notification messages (to indicate things
    219 	 * like a modem hangup) to come in via an interrupt endpoint
    220 	 * off of the control interface.  Iterate over the endpoints on
    221 	 * the control interface and see if there are any interrupt
    222 	 * endpoints; if there are, then register it.
    223 	 */
    224 
    225 	sc->sc_ctl_notify = -1;
    226 	sc->sc_notify_pipe = NULL;
    227 
    228 	for (i = 0; i < id->bNumEndpoints; i++) {
    229 		ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i);
    230 		if (ed == NULL)
    231 			continue;
    232 
    233 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    234 		    (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
    235 			printf("%s: status change notification available\n",
    236 			       USBDEVNAME(sc->sc_dev));
    237 			sc->sc_ctl_notify = ed->bEndpointAddress;
    238 		}
    239 	}
    240 
    241 	sc->sc_dtr = -1;
    242 
    243 	/* bulkin, bulkout set above */
    244 	uca->ibufsize = UMODEMIBUFSIZE;
    245 	uca->obufsize = UMODEMOBUFSIZE;
    246 	uca->ibufsizepad = UMODEMIBUFSIZE;
    247 	uca->opkthdrlen = 0;
    248 	uca->device = sc->sc_udev;
    249 	uca->iface = sc->sc_data_iface;
    250 	uca->arg = sc;
    251 
    252 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
    253 			   USBDEV(sc->sc_dev));
    254 
    255 	DPRINTF(("umodem_common_attach: sc=%p\n", sc));
    256 	sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, uca,
    257 					    ucomprint, ucomsubmatch);
    258 
    259 	return 0;
    260 
    261  bad:
    262 	sc->sc_dying = 1;
    263 	return 1;
    264 }
    265 
    266 int
    267 umodem_open(void *addr, int portno)
    268 {
    269 	struct umodem_softc *sc = addr;
    270 	int err;
    271 
    272 	DPRINTF(("umodem_open: sc=%p\n", sc));
    273 
    274 	if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) {
    275 		err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify,
    276 		    USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc,
    277 		    &sc->sc_notify_buf, sizeof(sc->sc_notify_buf),
    278 		    umodem_intr, USBD_DEFAULT_INTERVAL);
    279 
    280 		if (err) {
    281 			DPRINTF(("Failed to establish notify pipe: %s\n",
    282 				usbd_errstr(err)));
    283 			return EIO;
    284 		}
    285 	}
    286 
    287 	return 0;
    288 }
    289 
    290 void
    291 umodem_close(void *addr, int portno)
    292 {
    293 	struct umodem_softc *sc = addr;
    294 	int err;
    295 
    296 	DPRINTF(("umodem_close: sc=%p\n", sc));
    297 
    298 	if (sc->sc_notify_pipe != NULL) {
    299 		err = usbd_abort_pipe(sc->sc_notify_pipe);
    300 		if (err)
    301 			printf("%s: abort notify pipe failed: %s\n",
    302 			    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    303 		err = usbd_close_pipe(sc->sc_notify_pipe);
    304 		if (err)
    305 			printf("%s: close notify pipe failed: %s\n",
    306 			    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    307 		sc->sc_notify_pipe = NULL;
    308 	}
    309 }
    310 
    311 Static void
    312 umodem_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
    313     usbd_status status)
    314 {
    315 	struct umodem_softc *sc = priv;
    316 	u_char mstatus;
    317 
    318 	if (sc->sc_dying)
    319 		return;
    320 
    321 	if (status != USBD_NORMAL_COMPLETION) {
    322 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
    323 			return;
    324 		printf("%s: abnormal status: %s\n", USBDEVNAME(sc->sc_dev),
    325 		       usbd_errstr(status));
    326 		return;
    327 	}
    328 
    329 	if (sc->sc_notify_buf.bmRequestType != UCDC_NOTIFICATION) {
    330 		DPRINTF(("%s: unknown message type (%02x) on notify pipe\n",
    331 			 USBDEVNAME(sc->sc_dev),
    332 			 sc->sc_notify_buf.bmRequestType));
    333 		return;
    334 	}
    335 
    336 	switch (sc->sc_notify_buf.bNotification) {
    337 	case UCDC_N_SERIAL_STATE:
    338 		/*
    339 		 * Set the serial state in ucom driver based on
    340 		 * the bits from the notify message
    341 		 */
    342 		if (UGETW(sc->sc_notify_buf.wLength) != 2) {
    343 			printf("%s: Invalid notification length! (%d)\n",
    344 			       USBDEVNAME(sc->sc_dev),
    345 			       UGETW(sc->sc_notify_buf.wLength));
    346 			break;
    347 		}
    348 		DPRINTF(("%s: notify bytes = %02x%02x\n",
    349 			 USBDEVNAME(sc->sc_dev),
    350 			 sc->sc_notify_buf.data[0],
    351 			 sc->sc_notify_buf.data[1]));
    352 		/* Currently, lsr is always zero. */
    353 		sc->sc_lsr = sc->sc_msr = 0;
    354 		mstatus = sc->sc_notify_buf.data[0];
    355 
    356 		if (ISSET(mstatus, UCDC_N_SERIAL_RI))
    357 			sc->sc_msr |= UMSR_RI;
    358 		if (ISSET(mstatus, UCDC_N_SERIAL_DSR))
    359 			sc->sc_msr |= UMSR_DSR;
    360 		if (ISSET(mstatus, UCDC_N_SERIAL_DCD))
    361 			sc->sc_msr |= UMSR_DCD;
    362 		ucom_status_change((struct ucom_softc *)sc->sc_subdev);
    363 		break;
    364 	default:
    365 		DPRINTF(("%s: unknown notify message: %02x\n",
    366 			 USBDEVNAME(sc->sc_dev),
    367 			 sc->sc_notify_buf.bNotification));
    368 		break;
    369 	}
    370 }
    371 
    372 int
    373 umodem_get_caps(usbd_device_handle dev, int *cm, int *acm,
    374 		usb_interface_descriptor_t *id)
    375 {
    376 	const usb_cdc_cm_descriptor_t *cmd;
    377 	const usb_cdc_acm_descriptor_t *cad;
    378 	const usb_cdc_union_descriptor_t *cud;
    379 
    380 	*cm = *acm = 0;
    381 
    382 	cmd = (const usb_cdc_cm_descriptor_t *)usb_find_desc_if(dev,
    383 							  UDESC_CS_INTERFACE,
    384 							  UDESCSUB_CDC_CM, id);
    385 	if (cmd == NULL) {
    386 		DPRINTF(("umodem_get_caps: no CM desc\n"));
    387 	} else {
    388 		*cm = cmd->bmCapabilities;
    389 	}
    390 
    391 	cad = (const usb_cdc_acm_descriptor_t *)usb_find_desc_if(dev,
    392 							   UDESC_CS_INTERFACE,
    393 							   UDESCSUB_CDC_ACM,
    394 							   id);
    395 	if (cad == NULL) {
    396 		DPRINTF(("umodem_get_caps: no ACM desc\n"));
    397 	} else {
    398 		*acm = cad->bmCapabilities;
    399 	}
    400 
    401 	cud = (const usb_cdc_union_descriptor_t *)usb_find_desc_if(dev,
    402 							     UDESC_CS_INTERFACE,
    403 							     UDESCSUB_CDC_UNION,
    404 							     id);
    405 	if (cud == NULL) {
    406 		DPRINTF(("umodem_get_caps: no UNION desc\n"));
    407 	}
    408 
    409 	return cmd ? cmd->bDataInterface : cud ? cud->bSlaveInterface[0] : -1;
    410 }
    411 
    412 void
    413 umodem_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    414 {
    415 	struct umodem_softc *sc = addr;
    416 
    417 	DPRINTF(("umodem_get_status:\n"));
    418 
    419 	if (lsr != NULL)
    420 		*lsr = sc->sc_lsr;
    421 	if (msr != NULL)
    422 		*msr = sc->sc_msr;
    423 }
    424 
    425 int
    426 umodem_param(void *addr, int portno, struct termios *t)
    427 {
    428 	struct umodem_softc *sc = addr;
    429 	usbd_status err;
    430 	usb_cdc_line_state_t ls;
    431 
    432 	DPRINTF(("umodem_param: sc=%p\n", sc));
    433 
    434 	USETDW(ls.dwDTERate, t->c_ospeed);
    435 	if (ISSET(t->c_cflag, CSTOPB))
    436 		ls.bCharFormat = UCDC_STOP_BIT_2;
    437 	else
    438 		ls.bCharFormat = UCDC_STOP_BIT_1;
    439 	if (ISSET(t->c_cflag, PARENB)) {
    440 		if (ISSET(t->c_cflag, PARODD))
    441 			ls.bParityType = UCDC_PARITY_ODD;
    442 		else
    443 			ls.bParityType = UCDC_PARITY_EVEN;
    444 	} else
    445 		ls.bParityType = UCDC_PARITY_NONE;
    446 	switch (ISSET(t->c_cflag, CSIZE)) {
    447 	case CS5:
    448 		ls.bDataBits = 5;
    449 		break;
    450 	case CS6:
    451 		ls.bDataBits = 6;
    452 		break;
    453 	case CS7:
    454 		ls.bDataBits = 7;
    455 		break;
    456 	case CS8:
    457 		ls.bDataBits = 8;
    458 		break;
    459 	}
    460 
    461 	err = umodem_set_line_coding(sc, &ls);
    462 	if (err) {
    463 		DPRINTF(("umodem_param: err=%s\n", usbd_errstr(err)));
    464 		return (EPASSTHROUGH);
    465 	}
    466 	return (0);
    467 }
    468 
    469 int
    470 umodem_ioctl(void *addr, int portno, u_long cmd, void *data,
    471     int flag, usb_proc_ptr p)
    472 {
    473 	struct umodem_softc *sc = addr;
    474 	int error = 0;
    475 
    476 	if (sc->sc_dying)
    477 		return (EIO);
    478 
    479 	DPRINTF(("umodem_ioctl: cmd=0x%08lx\n", cmd));
    480 
    481 	switch (cmd) {
    482 	case USB_GET_CM_OVER_DATA:
    483 		*(int *)data = sc->sc_cm_over_data;
    484 		break;
    485 
    486 	case USB_SET_CM_OVER_DATA:
    487 		if (*(int *)data != sc->sc_cm_over_data) {
    488 			/* XXX change it */
    489 		}
    490 		break;
    491 
    492 	default:
    493 		DPRINTF(("umodem_ioctl: unknown\n"));
    494 		error = EPASSTHROUGH;
    495 		break;
    496 	}
    497 
    498 	return (error);
    499 }
    500 
    501 void
    502 umodem_dtr(struct umodem_softc *sc, int onoff)
    503 {
    504 	DPRINTF(("umodem_dtr: onoff=%d\n", onoff));
    505 
    506 	if (sc->sc_dtr == onoff)
    507 		return;
    508 	sc->sc_dtr = onoff;
    509 
    510 	umodem_set_line_state(sc);
    511 }
    512 
    513 void
    514 umodem_rts(struct umodem_softc *sc, int onoff)
    515 {
    516 	DPRINTF(("umodem_rts: onoff=%d\n", onoff));
    517 
    518 	if (sc->sc_rts == onoff)
    519 		return;
    520 	sc->sc_rts = onoff;
    521 
    522 	umodem_set_line_state(sc);
    523 }
    524 
    525 void
    526 umodem_set_line_state(struct umodem_softc *sc)
    527 {
    528 	usb_device_request_t req;
    529 	int ls;
    530 
    531 	ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
    532 	     (sc->sc_rts ? UCDC_LINE_RTS : 0);
    533 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    534 	req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
    535 	USETW(req.wValue, ls);
    536 	USETW(req.wIndex, sc->sc_ctl_iface_no);
    537 	USETW(req.wLength, 0);
    538 
    539 	(void)usbd_do_request(sc->sc_udev, &req, 0);
    540 
    541 }
    542 
    543 void
    544 umodem_break(struct umodem_softc *sc, int onoff)
    545 {
    546 	usb_device_request_t req;
    547 
    548 	DPRINTF(("umodem_break: onoff=%d\n", onoff));
    549 
    550 	if (!(sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK))
    551 		return;
    552 
    553 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    554 	req.bRequest = UCDC_SEND_BREAK;
    555 	USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
    556 	USETW(req.wIndex, sc->sc_ctl_iface_no);
    557 	USETW(req.wLength, 0);
    558 
    559 	(void)usbd_do_request(sc->sc_udev, &req, 0);
    560 }
    561 
    562 void
    563 umodem_set(void *addr, int portno, int reg, int onoff)
    564 {
    565 	struct umodem_softc *sc = addr;
    566 
    567 	switch (reg) {
    568 	case UCOM_SET_DTR:
    569 		umodem_dtr(sc, onoff);
    570 		break;
    571 	case UCOM_SET_RTS:
    572 		umodem_rts(sc, onoff);
    573 		break;
    574 	case UCOM_SET_BREAK:
    575 		umodem_break(sc, onoff);
    576 		break;
    577 	default:
    578 		break;
    579 	}
    580 }
    581 
    582 usbd_status
    583 umodem_set_line_coding(struct umodem_softc *sc, usb_cdc_line_state_t *state)
    584 {
    585 	usb_device_request_t req;
    586 	usbd_status err;
    587 
    588 	DPRINTF(("umodem_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
    589 		 UGETDW(state->dwDTERate), state->bCharFormat,
    590 		 state->bParityType, state->bDataBits));
    591 
    592 	if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
    593 		DPRINTF(("umodem_set_line_coding: already set\n"));
    594 		return (USBD_NORMAL_COMPLETION);
    595 	}
    596 
    597 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    598 	req.bRequest = UCDC_SET_LINE_CODING;
    599 	USETW(req.wValue, 0);
    600 	USETW(req.wIndex, sc->sc_ctl_iface_no);
    601 	USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
    602 
    603 	err = usbd_do_request(sc->sc_udev, &req, state);
    604 	if (err) {
    605 		DPRINTF(("umodem_set_line_coding: failed, err=%s\n",
    606 			 usbd_errstr(err)));
    607 		return (err);
    608 	}
    609 
    610 	sc->sc_line_state = *state;
    611 
    612 	return (USBD_NORMAL_COMPLETION);
    613 }
    614 
    615 usbd_status
    616 umodem_set_comm_feature(struct umodem_softc *sc, int feature, int state)
    617 {
    618 	usb_device_request_t req;
    619 	usbd_status err;
    620 	usb_cdc_abstract_state_t ast;
    621 
    622 	DPRINTF(("umodem_set_comm_feature: feature=%d state=%d\n", feature,
    623 		 state));
    624 
    625 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    626 	req.bRequest = UCDC_SET_COMM_FEATURE;
    627 	USETW(req.wValue, feature);
    628 	USETW(req.wIndex, sc->sc_ctl_iface_no);
    629 	USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH);
    630 	USETW(ast.wState, state);
    631 
    632 	err = usbd_do_request(sc->sc_udev, &req, &ast);
    633 	if (err) {
    634 		DPRINTF(("umodem_set_comm_feature: feature=%d, err=%s\n",
    635 			 feature, usbd_errstr(err)));
    636 		return (err);
    637 	}
    638 
    639 	return (USBD_NORMAL_COMPLETION);
    640 }
    641 
    642 int
    643 umodem_common_activate(struct umodem_softc *sc, enum devact act)
    644 {
    645 	int rv = 0;
    646 
    647 	switch (act) {
    648 	case DVACT_ACTIVATE:
    649 		return (EOPNOTSUPP);
    650 
    651 	case DVACT_DEACTIVATE:
    652 		sc->sc_dying = 1;
    653 		if (sc->sc_subdev)
    654 			rv = config_deactivate(sc->sc_subdev);
    655 		break;
    656 	}
    657 	return (rv);
    658 }
    659 
    660 int
    661 umodem_common_detach(struct umodem_softc *sc, int flags)
    662 {
    663 	int rv = 0;
    664 
    665 	DPRINTF(("umodem_common_detach: sc=%p flags=%d\n", sc, flags));
    666 
    667 	sc->sc_dying = 1;
    668 
    669 	if (sc->sc_subdev != NULL)
    670 		rv = config_detach(sc->sc_subdev, flags);
    671 
    672 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
    673 			   USBDEV(sc->sc_dev));
    674 
    675 	return (rv);
    676 }
    677