Home | History | Annotate | Line # | Download | only in usb
umodem_common.c revision 1.7
      1 /*	$NetBSD: umodem_common.c,v 1.7 2006/06/07 18:03:00 smb 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.7 2006/06/07 18:03:00 smb 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  * Note: increased from 64/256, to better support EVDO wireless PPP.
     95  * The sizes should not be increased further, or there
     96  * will be problems with contiguous storage allocation.
     97  */
     98 #define UMODEMIBUFSIZE 4096
     99 #define UMODEMOBUFSIZE 4096
    100 
    101 Static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
    102 					   int feature, int state);
    103 Static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
    104 					  usb_cdc_line_state_t *state);
    105 
    106 Static void	umodem_dtr(struct umodem_softc *, int);
    107 Static void	umodem_rts(struct umodem_softc *, int);
    108 Static void	umodem_break(struct umodem_softc *, int);
    109 Static void	umodem_set_line_state(struct umodem_softc *);
    110 Static void	umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
    111 
    112 int
    113 umodem_common_attach(device_ptr_t self, struct umodem_softc *sc,
    114 		     struct usb_attach_arg *uaa, struct ucom_attach_args *uca)
    115 {
    116 	usbd_device_handle dev = uaa->device;
    117 	usb_interface_descriptor_t *id;
    118 	usb_endpoint_descriptor_t *ed;
    119 	char *devinfop;
    120 	usbd_status err;
    121 	int data_ifcno;
    122 	int i;
    123 
    124 	devinfop = usbd_devinfo_alloc(uaa->device, 0);
    125 	USB_ATTACH_SETUP;
    126 
    127 	sc->sc_udev = dev;
    128 	sc->sc_ctl_iface = uaa->iface;
    129 
    130 	id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
    131 	printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
    132 	       devinfop, id->bInterfaceClass, id->bInterfaceSubClass);
    133 	usbd_devinfo_free(devinfop);
    134 	sc->sc_ctl_iface_no = id->bInterfaceNumber;
    135 
    136 	/* Get the data interface no. */
    137 	sc->sc_data_iface_no = data_ifcno =
    138 	    umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap, id);
    139 
    140 	if (data_ifcno == -1) {
    141 		printf("%s: no pointer to data interface\n",
    142 		       USBDEVNAME(sc->sc_dev));
    143 		goto bad;
    144 	}
    145 
    146 	printf("%s: data interface %d, has %sCM over data, has %sbreak\n",
    147 	       USBDEVNAME(sc->sc_dev), data_ifcno,
    148 	       sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
    149 	       sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
    150 
    151 	/* Get the data interface too. */
    152 	for (i = 0; i < uaa->nifaces; i++) {
    153 		if (uaa->ifaces[i] != NULL) {
    154 			id = usbd_get_interface_descriptor(uaa->ifaces[i]);
    155 			if (id != NULL && id->bInterfaceNumber == data_ifcno) {
    156 				sc->sc_data_iface = uaa->ifaces[i];
    157 				uaa->ifaces[i] = NULL;
    158 			}
    159 		}
    160 	}
    161 	if (sc->sc_data_iface == NULL) {
    162 		printf("%s: no data interface\n", USBDEVNAME(sc->sc_dev));
    163 		goto bad;
    164 	}
    165 
    166 	/*
    167 	 * Find the bulk endpoints.
    168 	 * Iterate over all endpoints in the data interface and take note.
    169 	 */
    170 	uca->bulkin = uca->bulkout = -1;
    171 
    172 	id = usbd_get_interface_descriptor(sc->sc_data_iface);
    173 	for (i = 0; i < id->bNumEndpoints; i++) {
    174 		ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
    175 		if (ed == NULL) {
    176 			printf("%s: no endpoint descriptor for %d\n",
    177 				USBDEVNAME(sc->sc_dev), i);
    178 			goto bad;
    179 		}
    180 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    181 		    (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
    182 			uca->bulkin = ed->bEndpointAddress;
    183 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    184 			   (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
    185 			uca->bulkout = ed->bEndpointAddress;
    186 		}
    187 	}
    188 
    189 	if (uca->bulkin == -1) {
    190 		printf("%s: Could not find data bulk in\n",
    191 		       USBDEVNAME(sc->sc_dev));
    192 		goto bad;
    193 	}
    194 	if (uca->bulkout == -1) {
    195 		printf("%s: Could not find data bulk out\n",
    196 			USBDEVNAME(sc->sc_dev));
    197 		goto bad;
    198 	}
    199 
    200 	if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) {
    201 		sc->sc_cm_over_data = 1;
    202 	} else {
    203 		if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
    204 			if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
    205 				err = umodem_set_comm_feature(sc,
    206 				    UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
    207 			else
    208 				err = 0;
    209 			if (err) {
    210 				printf("%s: could not set data multiplex mode\n",
    211 				       USBDEVNAME(sc->sc_dev));
    212 				goto bad;
    213 			}
    214 			sc->sc_cm_over_data = 1;
    215 		}
    216 	}
    217 
    218 	/*
    219 	 * The standard allows for notification messages (to indicate things
    220 	 * like a modem hangup) to come in via an interrupt endpoint
    221 	 * off of the control interface.  Iterate over the endpoints on
    222 	 * the control interface and see if there are any interrupt
    223 	 * endpoints; if there are, then register it.
    224 	 */
    225 
    226 	sc->sc_ctl_notify = -1;
    227 	sc->sc_notify_pipe = NULL;
    228 
    229 	for (i = 0; i < id->bNumEndpoints; i++) {
    230 		ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i);
    231 		if (ed == NULL)
    232 			continue;
    233 
    234 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    235 		    (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
    236 			printf("%s: status change notification available\n",
    237 			       USBDEVNAME(sc->sc_dev));
    238 			sc->sc_ctl_notify = ed->bEndpointAddress;
    239 		}
    240 	}
    241 
    242 	sc->sc_dtr = -1;
    243 
    244 	/* bulkin, bulkout set above */
    245 	uca->ibufsize = UMODEMIBUFSIZE;
    246 	uca->obufsize = UMODEMOBUFSIZE;
    247 	uca->ibufsizepad = UMODEMIBUFSIZE;
    248 	uca->opkthdrlen = 0;
    249 	uca->device = sc->sc_udev;
    250 	uca->iface = sc->sc_data_iface;
    251 	uca->arg = sc;
    252 
    253 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
    254 			   USBDEV(sc->sc_dev));
    255 
    256 	DPRINTF(("umodem_common_attach: sc=%p\n", sc));
    257 	sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, uca,
    258 					    ucomprint, ucomsubmatch);
    259 
    260 	return 0;
    261 
    262  bad:
    263 	sc->sc_dying = 1;
    264 	return 1;
    265 }
    266 
    267 int
    268 umodem_open(void *addr, int portno)
    269 {
    270 	struct umodem_softc *sc = addr;
    271 	int err;
    272 
    273 	DPRINTF(("umodem_open: sc=%p\n", sc));
    274 
    275 	if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) {
    276 		err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify,
    277 		    USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc,
    278 		    &sc->sc_notify_buf, sizeof(sc->sc_notify_buf),
    279 		    umodem_intr, USBD_DEFAULT_INTERVAL);
    280 
    281 		if (err) {
    282 			DPRINTF(("Failed to establish notify pipe: %s\n",
    283 				usbd_errstr(err)));
    284 			return EIO;
    285 		}
    286 	}
    287 
    288 	return 0;
    289 }
    290 
    291 void
    292 umodem_close(void *addr, int portno)
    293 {
    294 	struct umodem_softc *sc = addr;
    295 	int err;
    296 
    297 	DPRINTF(("umodem_close: sc=%p\n", sc));
    298 
    299 	if (sc->sc_notify_pipe != NULL) {
    300 		err = usbd_abort_pipe(sc->sc_notify_pipe);
    301 		if (err)
    302 			printf("%s: abort notify pipe failed: %s\n",
    303 			    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    304 		err = usbd_close_pipe(sc->sc_notify_pipe);
    305 		if (err)
    306 			printf("%s: close notify pipe failed: %s\n",
    307 			    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    308 		sc->sc_notify_pipe = NULL;
    309 	}
    310 }
    311 
    312 Static void
    313 umodem_intr(usbd_xfer_handle xfer, usbd_private_handle priv, 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, caddr_t data, int flag,
    471 	     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