umodem_common.c revision 1.5.10.2 1 /* $NetBSD: umodem_common.c,v 1.5.10.2 2005/10/26 22:16:27 jmc 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.5.10.2 2005/10/26 22:16:27 jmc 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 /* backport glue */
109 Static usb_descriptor_t *usb_find_desc_if(usbd_device_handle, int, int,
110 usb_interface_descriptor_t *);
111 /* end glue */
112
113 int
114 umodem_common_attach(device_ptr_t self, struct umodem_softc *sc,
115 struct usb_attach_arg *uaa, struct ucom_attach_args *uca)
116 {
117 usbd_device_handle dev = uaa->device;
118 usb_interface_descriptor_t *id;
119 usb_endpoint_descriptor_t *ed;
120 char devinfo[1024];
121 usbd_status err;
122 int data_ifcno;
123 int i;
124
125 usbd_devinfo(uaa->device, 0, devinfo);
126 USB_ATTACH_SETUP;
127
128 sc->sc_udev = dev;
129 sc->sc_ctl_iface = uaa->iface;
130
131 id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
132 printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
133 devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
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(self, uca, 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, usbd_status status)
313 {
314 struct umodem_softc *sc = priv;
315 u_char mstatus;
316
317 if (sc->sc_dying)
318 return;
319
320 if (status != USBD_NORMAL_COMPLETION) {
321 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
322 return;
323 printf("%s: abnormal status: %s\n", USBDEVNAME(sc->sc_dev),
324 usbd_errstr(status));
325 return;
326 }
327
328 if (sc->sc_notify_buf.bmRequestType != UCDC_NOTIFICATION) {
329 DPRINTF(("%s: unknown message type (%02x) on notify pipe\n",
330 USBDEVNAME(sc->sc_dev),
331 sc->sc_notify_buf.bmRequestType));
332 return;
333 }
334
335 switch (sc->sc_notify_buf.bNotification) {
336 case UCDC_N_SERIAL_STATE:
337 /*
338 * Set the serial state in ucom driver based on
339 * the bits from the notify message
340 */
341 if (UGETW(sc->sc_notify_buf.wLength) != 2) {
342 printf("%s: Invalid notification length! (%d)\n",
343 USBDEVNAME(sc->sc_dev),
344 UGETW(sc->sc_notify_buf.wLength));
345 break;
346 }
347 DPRINTF(("%s: notify bytes = %02x%02x\n",
348 USBDEVNAME(sc->sc_dev),
349 sc->sc_notify_buf.data[0],
350 sc->sc_notify_buf.data[1]));
351 /* Currently, lsr is always zero. */
352 sc->sc_lsr = sc->sc_msr = 0;
353 mstatus = sc->sc_notify_buf.data[0];
354
355 if (ISSET(mstatus, UCDC_N_SERIAL_RI))
356 sc->sc_msr |= UMSR_RI;
357 if (ISSET(mstatus, UCDC_N_SERIAL_DSR))
358 sc->sc_msr |= UMSR_DSR;
359 if (ISSET(mstatus, UCDC_N_SERIAL_DCD))
360 sc->sc_msr |= UMSR_DCD;
361 ucom_status_change((struct ucom_softc *)sc->sc_subdev);
362 break;
363 default:
364 DPRINTF(("%s: unknown notify message: %02x\n",
365 USBDEVNAME(sc->sc_dev),
366 sc->sc_notify_buf.bNotification));
367 break;
368 }
369 }
370
371 int
372 umodem_get_caps(usbd_device_handle dev, int *cm, int *acm,
373 usb_interface_descriptor_t *id)
374 {
375 const usb_cdc_cm_descriptor_t *cmd;
376 const usb_cdc_acm_descriptor_t *cad;
377 const usb_cdc_union_descriptor_t *cud;
378
379 *cm = *acm = 0;
380
381 cmd = (usb_cdc_cm_descriptor_t *)usb_find_desc_if(dev,
382 UDESC_CS_INTERFACE,
383 UDESCSUB_CDC_CM, id);
384 if (cmd == NULL) {
385 DPRINTF(("umodem_get_caps: no CM desc\n"));
386 } else {
387 *cm = cmd->bmCapabilities;
388 }
389
390 cad = (usb_cdc_acm_descriptor_t *)usb_find_desc_if(dev,
391 UDESC_CS_INTERFACE,
392 UDESCSUB_CDC_ACM,
393 id);
394 if (cad == NULL) {
395 DPRINTF(("umodem_get_caps: no ACM desc\n"));
396 } else {
397 *acm = cad->bmCapabilities;
398 }
399
400 cud = (usb_cdc_union_descriptor_t *)usb_find_desc_if(dev,
401 UDESC_CS_INTERFACE,
402 UDESCSUB_CDC_UNION,
403 id);
404 if (cud == NULL) {
405 DPRINTF(("umodem_get_caps: no UNION desc\n"));
406 }
407
408 return cmd ? cmd->bDataInterface : cud ? cud->bSlaveInterface[0] : -1;
409 }
410
411 void
412 umodem_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
413 {
414 struct umodem_softc *sc = addr;
415
416 DPRINTF(("umodem_get_status:\n"));
417
418 if (lsr != NULL)
419 *lsr = sc->sc_lsr;
420 if (msr != NULL)
421 *msr = sc->sc_msr;
422 }
423
424 int
425 umodem_param(void *addr, int portno, struct termios *t)
426 {
427 struct umodem_softc *sc = addr;
428 usbd_status err;
429 usb_cdc_line_state_t ls;
430
431 DPRINTF(("umodem_param: sc=%p\n", sc));
432
433 USETDW(ls.dwDTERate, t->c_ospeed);
434 if (ISSET(t->c_cflag, CSTOPB))
435 ls.bCharFormat = UCDC_STOP_BIT_2;
436 else
437 ls.bCharFormat = UCDC_STOP_BIT_1;
438 if (ISSET(t->c_cflag, PARENB)) {
439 if (ISSET(t->c_cflag, PARODD))
440 ls.bParityType = UCDC_PARITY_ODD;
441 else
442 ls.bParityType = UCDC_PARITY_EVEN;
443 } else
444 ls.bParityType = UCDC_PARITY_NONE;
445 switch (ISSET(t->c_cflag, CSIZE)) {
446 case CS5:
447 ls.bDataBits = 5;
448 break;
449 case CS6:
450 ls.bDataBits = 6;
451 break;
452 case CS7:
453 ls.bDataBits = 7;
454 break;
455 case CS8:
456 ls.bDataBits = 8;
457 break;
458 }
459
460 err = umodem_set_line_coding(sc, &ls);
461 if (err) {
462 DPRINTF(("umodem_param: err=%s\n", usbd_errstr(err)));
463 return (EPASSTHROUGH);
464 }
465 return (0);
466 }
467
468 int
469 umodem_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
470 usb_proc_ptr p)
471 {
472 struct umodem_softc *sc = addr;
473 int error = 0;
474
475 if (sc->sc_dying)
476 return (EIO);
477
478 DPRINTF(("umodem_ioctl: cmd=0x%08lx\n", cmd));
479
480 switch (cmd) {
481 case USB_GET_CM_OVER_DATA:
482 *(int *)data = sc->sc_cm_over_data;
483 break;
484
485 case USB_SET_CM_OVER_DATA:
486 if (*(int *)data != sc->sc_cm_over_data) {
487 /* XXX change it */
488 }
489 break;
490
491 default:
492 DPRINTF(("umodem_ioctl: unknown\n"));
493 error = EPASSTHROUGH;
494 break;
495 }
496
497 return (error);
498 }
499
500 void
501 umodem_dtr(struct umodem_softc *sc, int onoff)
502 {
503 DPRINTF(("umodem_dtr: onoff=%d\n", onoff));
504
505 if (sc->sc_dtr == onoff)
506 return;
507 sc->sc_dtr = onoff;
508
509 umodem_set_line_state(sc);
510 }
511
512 void
513 umodem_rts(struct umodem_softc *sc, int onoff)
514 {
515 DPRINTF(("umodem_rts: onoff=%d\n", onoff));
516
517 if (sc->sc_rts == onoff)
518 return;
519 sc->sc_rts = onoff;
520
521 umodem_set_line_state(sc);
522 }
523
524 void
525 umodem_set_line_state(struct umodem_softc *sc)
526 {
527 usb_device_request_t req;
528 int ls;
529
530 ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
531 (sc->sc_rts ? UCDC_LINE_RTS : 0);
532 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
533 req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
534 USETW(req.wValue, ls);
535 USETW(req.wIndex, sc->sc_ctl_iface_no);
536 USETW(req.wLength, 0);
537
538 (void)usbd_do_request(sc->sc_udev, &req, 0);
539
540 }
541
542 void
543 umodem_break(struct umodem_softc *sc, int onoff)
544 {
545 usb_device_request_t req;
546
547 DPRINTF(("umodem_break: onoff=%d\n", onoff));
548
549 if (!(sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK))
550 return;
551
552 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
553 req.bRequest = UCDC_SEND_BREAK;
554 USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
555 USETW(req.wIndex, sc->sc_ctl_iface_no);
556 USETW(req.wLength, 0);
557
558 (void)usbd_do_request(sc->sc_udev, &req, 0);
559 }
560
561 void
562 umodem_set(void *addr, int portno, int reg, int onoff)
563 {
564 struct umodem_softc *sc = addr;
565
566 switch (reg) {
567 case UCOM_SET_DTR:
568 umodem_dtr(sc, onoff);
569 break;
570 case UCOM_SET_RTS:
571 umodem_rts(sc, onoff);
572 break;
573 case UCOM_SET_BREAK:
574 umodem_break(sc, onoff);
575 break;
576 default:
577 break;
578 }
579 }
580
581 usbd_status
582 umodem_set_line_coding(struct umodem_softc *sc, usb_cdc_line_state_t *state)
583 {
584 usb_device_request_t req;
585 usbd_status err;
586
587 DPRINTF(("umodem_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
588 UGETDW(state->dwDTERate), state->bCharFormat,
589 state->bParityType, state->bDataBits));
590
591 if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
592 DPRINTF(("umodem_set_line_coding: already set\n"));
593 return (USBD_NORMAL_COMPLETION);
594 }
595
596 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
597 req.bRequest = UCDC_SET_LINE_CODING;
598 USETW(req.wValue, 0);
599 USETW(req.wIndex, sc->sc_ctl_iface_no);
600 USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
601
602 err = usbd_do_request(sc->sc_udev, &req, state);
603 if (err) {
604 DPRINTF(("umodem_set_line_coding: failed, err=%s\n",
605 usbd_errstr(err)));
606 return (err);
607 }
608
609 sc->sc_line_state = *state;
610
611 return (USBD_NORMAL_COMPLETION);
612 }
613
614 usbd_status
615 umodem_set_comm_feature(struct umodem_softc *sc, int feature, int state)
616 {
617 usb_device_request_t req;
618 usbd_status err;
619 usb_cdc_abstract_state_t ast;
620
621 DPRINTF(("umodem_set_comm_feature: feature=%d state=%d\n", feature,
622 state));
623
624 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
625 req.bRequest = UCDC_SET_COMM_FEATURE;
626 USETW(req.wValue, feature);
627 USETW(req.wIndex, sc->sc_ctl_iface_no);
628 USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH);
629 USETW(ast.wState, state);
630
631 err = usbd_do_request(sc->sc_udev, &req, &ast);
632 if (err) {
633 DPRINTF(("umodem_set_comm_feature: feature=%d, err=%s\n",
634 feature, usbd_errstr(err)));
635 return (err);
636 }
637
638 return (USBD_NORMAL_COMPLETION);
639 }
640
641 int
642 umodem_common_activate(struct umodem_softc *sc, enum devact act)
643 {
644 int rv = 0;
645
646 switch (act) {
647 case DVACT_ACTIVATE:
648 return (EOPNOTSUPP);
649
650 case DVACT_DEACTIVATE:
651 sc->sc_dying = 1;
652 if (sc->sc_subdev)
653 rv = config_deactivate(sc->sc_subdev);
654 break;
655 }
656 return (rv);
657 }
658
659 int
660 umodem_common_detach(struct umodem_softc *sc, int flags)
661 {
662 int rv = 0;
663
664 DPRINTF(("umodem_common_detach: sc=%p flags=%d\n", sc, flags));
665
666 sc->sc_dying = 1;
667
668 if (sc->sc_subdev != NULL)
669 rv = config_detach(sc->sc_subdev, flags);
670
671 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
672 USBDEV(sc->sc_dev));
673
674 return (rv);
675 }
676
677 /* backport glue */
678 /* same as usb_find_desc(), but searches only in the specified interface. */
679 Static usb_descriptor_t *
680 usb_find_desc_if(usbd_device_handle dev, int type, int subtype,
681 usb_interface_descriptor_t *id)
682 {
683 usb_descriptor_t *desc;
684 usb_config_descriptor_t *cd = usbd_get_config_descriptor(dev);
685 uByte *p = (uByte *)cd;
686 uByte *end = p + UGETW(cd->wTotalLength);
687
688 p = (void *)id; /* start from the interface desc */
689 desc = (usb_descriptor_t *)p;
690 p += desc->bLength; /* and skip it */
691
692 while (p < end) {
693 desc = (usb_descriptor_t *)p;
694 if (desc->bDescriptorType == UDESC_INTERFACE) {
695 /* we ran into the next interface --- not found */
696 return (NULL);
697 }
698 if (desc->bDescriptorType == type &&
699 subtype == desc->bDescriptorSubtype)
700 return (desc);
701 p += desc->bLength;
702 }
703
704 return (NULL);
705 }
706 /* end glue */
707