uhmodem.c revision 1.22.6.1 1 /* $NetBSD: uhmodem.c,v 1.22.6.1 2021/03/22 02:01:02 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 2008 Yojiro UO <yuo (at) nui.org>.
5 * All rights reserved.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
16 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19 /*-
20 * Copyright (c) 2002, Alexander Kabaev <kan.FreeBSD.org>.
21 * All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 */
44 /*
45 * Copyright (c) 2001 The NetBSD Foundation, Inc.
46 * All rights reserved.
47 *
48 * This code is derived from software contributed to The NetBSD Foundation
49 * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
50 *
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
53 * are met:
54 * 1. Redistributions of source code must retain the above copyright
55 * notice, this list of conditions and the following disclaimer.
56 * 2. Redistributions in binary form must reproduce the above copyright
57 * notice, this list of conditions and the following disclaimer in the
58 * documentation and/or other materials provided with the distribution.
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
61 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
62 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
63 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
64 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
65 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
66 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
67 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
68 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
69 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
70 * POSSIBILITY OF SUCH DAMAGE.
71 */
72
73 #include <sys/cdefs.h>
74 __KERNEL_RCSID(0, "$NetBSD: uhmodem.c,v 1.22.6.1 2021/03/22 02:01:02 thorpej Exp $");
75
76 #ifdef _KERNEL_OPT
77 #include "opt_usb.h"
78 #endif
79
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/kernel.h>
83 #include <sys/kmem.h>
84 #include <sys/ioccom.h>
85 #include <sys/fcntl.h>
86 #include <sys/conf.h>
87 #include <sys/tty.h>
88 #include <sys/file.h>
89 #include <sys/select.h>
90 #include <sys/proc.h>
91 #include <sys/device.h>
92 #include <sys/poll.h>
93 #include <sys/sysctl.h>
94 #include <sys/bus.h>
95
96 #include <dev/usb/usb.h>
97 #include <dev/usb/usbdi.h>
98 #include <dev/usb/usbdi_util.h>
99 #include <dev/usb/usbdivar.h>
100
101 #include <dev/usb/usbcdc.h>
102 #include <dev/usb/usbdevs.h>
103 #include <dev/usb/usb_quirks.h>
104 #include <dev/usb/ucomvar.h>
105 #include <dev/usb/ubsavar.h>
106
107 /* vendor specific bRequest */
108 #define UHMODEM_REGWRITE 0x20
109 #define UHMODEM_REGREAD 0x21
110 #define UHMODEM_SETUP 0x22
111
112 #define UHMODEMIBUFSIZE 4096
113 #define UHMODEMOBUFSIZE 4096
114
115 #ifdef UHMODEM_DEBUG
116 static int uhmodemdebug = 0;
117 #define DPRINTFN(n, x) do { \
118 if (uhmodemdebug > (n)) \
119 printf x; \
120 } while (0)
121 #else
122 #define DPRINTFN(n, x)
123 #endif
124 #define DPRINTF(x) DPRINTFN(0, x)
125
126 static int uhmodem_open(void *, int);
127 static usbd_status e220_modechange_request(struct usbd_device *);
128 static usbd_status uhmodem_endpointhalt(struct ubsa_softc *, int);
129 static usbd_status uhmodem_regwrite(struct usbd_device *, uint8_t *, size_t);
130 static usbd_status uhmodem_regread(struct usbd_device *, uint8_t *, size_t);
131 static usbd_status a2502_init(struct usbd_device *);
132 #if 0
133 static usbd_status uhmodem_regsetup(struct usbd_device *, uint16_t);
134 static usbd_status e220_init(struct usbd_device *);
135 #endif
136
137 /* this driver uses the ubsa_softc and methods directly as-is. */
138 struct ucom_methods uhmodem_methods = {
139 .ucom_get_status = ubsa_get_status,
140 .ucom_set = ubsa_set,
141 .ucom_param = ubsa_param,
142 .ucom_open = uhmodem_open,
143 .ucom_close = ubsa_close,
144 };
145
146 struct uhmodem_type {
147 struct usb_devno uhmodem_dev;
148 uint16_t uhmodem_coms; /* number of serial interfaces on the device */
149 uint16_t uhmodem_flags;
150 #define E220 0x0001
151 #define A2502 0x0002
152 #define E620 0x0004 /* XXX */
153 /* Whether or not it is a device different from E220 is not clear. */
154 };
155
156 static const struct uhmodem_type uhmodem_devs[] = {
157 /* HUAWEI E220 / Emobile D0[12]HW */
158 {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220 }, 2, E220},
159 /* ANYDATA / NTT DoCoMo A2502 */
160 {{ USB_VENDOR_ANYDATA, USB_PRODUCT_ANYDATA_A2502 }, 3, A2502},
161 /* HUAWEI E620 */
162 {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_MOBILE }, 3, E620},
163 };
164 #define uhmodem_lookup(v, p) ((const struct uhmodem_type *)usb_lookup(uhmodem_devs, v, p))
165
166 static int uhmodem_match(device_t, cfdata_t, void *);
167 static void uhmodem_attach(device_t, device_t, void *);
168 static void uhmodem_childdet(device_t, device_t);
169 static int uhmodem_detach(device_t, int);
170
171 CFATTACH_DECL2_NEW(uhmodem, sizeof(struct ubsa_softc), uhmodem_match,
172 uhmodem_attach, uhmodem_detach, NULL, NULL, uhmodem_childdet);
173
174 static int
175 uhmodem_match(device_t parent, cfdata_t match, void *aux)
176 {
177 struct usbif_attach_arg *uiaa = aux;
178
179 if (uhmodem_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product) != NULL)
180 /* XXX interface# 0,1 provide modem function, but this driver
181 handles all modem in single device. */
182 if (uiaa->uiaa_ifaceno == 0)
183 return UMATCH_VENDOR_PRODUCT;
184 return UMATCH_NONE;
185 }
186
187 static void
188 uhmodem_attach(device_t parent, device_t self, void *aux)
189 {
190 struct ubsa_softc *sc = device_private(self);
191 struct usbif_attach_arg *uiaa = aux;
192 struct usbd_device *dev = uiaa->uiaa_device;
193 usb_config_descriptor_t *cdesc;
194 usb_interface_descriptor_t *id;
195 usb_endpoint_descriptor_t *ed;
196 char *devinfop;
197 usbd_status err;
198 struct ucom_attach_args ucaa;
199 int i;
200 int j;
201 char comname[16];
202
203 aprint_naive("\n");
204 aprint_normal("\n");
205
206 devinfop = usbd_devinfo_alloc(dev, 0);
207 aprint_normal_dev(self, "%s\n", devinfop);
208 usbd_devinfo_free(devinfop);
209
210 sc->sc_dev = self;
211 sc->sc_udev = dev;
212 sc->sc_config_index = UBSA_DEFAULT_CONFIG_INDEX;
213 sc->sc_numif = 1; /* default device has one interface */
214 sc->sc_dying = false;
215
216 /* Hauwei E220 need special request to change its mode to modem */
217 if ((uiaa->uiaa_ifaceno == 0) && (uiaa->uiaa_class != 255)) {
218 err = e220_modechange_request(dev);
219 if (err) {
220 aprint_error_dev(self, "failed to change mode: %s\n",
221 usbd_errstr(err));
222 goto error;
223 }
224 aprint_error_dev(self,
225 "mass storage only mode, reattach to enable modem\n");
226 goto error;
227 }
228
229 /*
230 * initialize rts, dtr variables to something
231 * different from boolean 0, 1
232 */
233 sc->sc_dtr = -1;
234 sc->sc_rts = -1;
235
236 sc->sc_quadumts = 1;
237 sc->sc_config_index = 0;
238 sc->sc_numif = uhmodem_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product)->uhmodem_coms;
239 sc->sc_devflags = uhmodem_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product)->uhmodem_flags;
240
241 DPRINTF(("uhmodem attach: sc = %p\n", sc));
242
243 /* Move the device into the configured state. */
244 err = usbd_set_config_index(dev, sc->sc_config_index, 1);
245 if (err) {
246 aprint_error_dev(self, "failed to set configuration: %s\n",
247 usbd_errstr(err));
248 goto error;
249 }
250
251 /* get the config descriptor */
252 cdesc = usbd_get_config_descriptor(sc->sc_udev);
253 if (cdesc == NULL) {
254 aprint_error_dev(self,
255 "failed to get configuration descriptor\n");
256 goto error;
257 }
258
259 sc->sc_intr_number = -1;
260 sc->sc_intr_pipe = NULL;
261
262 /* get the interfaces */
263 for (i = 0; i < sc->sc_numif; i++) {
264 err = usbd_device2interface_handle(dev, UBSA_IFACE_INDEX_OFFSET+i,
265 &sc->sc_iface[i]);
266 if (err) {
267 if (i == 0){
268 /* can not get main interface */
269 goto error;
270 } else
271 break;
272 }
273
274 /* Find the endpoints */
275 id = usbd_get_interface_descriptor(sc->sc_iface[i]);
276 sc->sc_iface_number[i] = id->bInterfaceNumber;
277
278 /* initialize endpoints */
279 ucaa.ucaa_bulkin = ucaa.ucaa_bulkout = -1;
280
281 for (j = 0; j < id->bNumEndpoints; j++) {
282 ed = usbd_interface2endpoint_descriptor(
283 sc->sc_iface[i], j);
284 if (ed == NULL) {
285 aprint_error_dev(self,
286 "no endpoint descriptor for %d "
287 "(interface: %d)\n", j, i);
288 break;
289 }
290
291 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
292 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
293 sc->sc_intr_number = ed->bEndpointAddress;
294 sc->sc_isize = UGETW(ed->wMaxPacketSize);
295 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
296 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
297 ucaa.ucaa_bulkin = ed->bEndpointAddress;
298 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
299 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
300 ucaa.ucaa_bulkout = ed->bEndpointAddress;
301 }
302 } /* end of Endpoint loop */
303
304 if (sc->sc_intr_number == -1) {
305 aprint_error_dev(self, "HUAWEI E220 need to re-attach "
306 "to enable modem function\n");
307 if (i == 0) {
308 /* could not get intr for main tty */
309 goto error;
310 } else
311 break;
312 }
313 if (ucaa.ucaa_bulkin == -1) {
314 aprint_error_dev(self,
315 "Could not find data bulk in\n");
316 goto error;
317 }
318
319 if (ucaa.ucaa_bulkout == -1) {
320 aprint_error_dev(self,
321 "Could not find data bulk out\n");
322 goto error;
323 }
324
325 switch (i) {
326 case 0:
327 snprintf(comname, sizeof(comname), "modem");
328 break;
329 case 1:
330 snprintf(comname, sizeof(comname), "alt#1");
331 break;
332 case 2:
333 snprintf(comname, sizeof(comname), "alt#2");
334 break;
335 default:
336 snprintf(comname, sizeof(comname), "int#%d", i);
337 break;
338 }
339
340 ucaa.ucaa_portno = i;
341 /* ucaa_bulkin, ucaa_bulkout set above */
342 ucaa.ucaa_ibufsize = UHMODEMIBUFSIZE;
343 ucaa.ucaa_obufsize = UHMODEMOBUFSIZE;
344 ucaa.ucaa_ibufsizepad = UHMODEMIBUFSIZE;
345 ucaa.ucaa_opkthdrlen = 0;
346 ucaa.ucaa_device = dev;
347 ucaa.ucaa_iface = sc->sc_iface[i];
348 ucaa.ucaa_methods = &uhmodem_methods;
349 ucaa.ucaa_arg = sc;
350 ucaa.ucaa_info = comname;
351 DPRINTF(("uhmodem: int#=%d, in = %#x, out = %#x, intr = %#x\n",
352 i, ucaa.ucaa_bulkin, ucaa.ucaa_bulkout,
353 sc->sc_intr_number));
354 sc->sc_subdevs[i] = config_found(self, &ucaa, ucomprint,
355 CFARG_SUBMATCH, ucomsubmatch,
356 CFARG_IATTR, "ucombus",
357 CFARG_EOL);
358
359 /* issue endpoint halt to each interface */
360 err = uhmodem_endpointhalt(sc, i);
361 if (err)
362 aprint_error("%s: endpointhalt fail\n", __func__);
363 else
364 usbd_delay_ms(sc->sc_udev, 50);
365 } /* end of Interface loop */
366
367 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
368 sc->sc_dev);
369
370 if (!pmf_device_register(self, NULL, NULL))
371 aprint_error_dev(self, "couldn't establish power handler\n");
372
373 return;
374
375 error:
376 sc->sc_dying = true;
377 return;
378 }
379
380 static void
381 uhmodem_childdet(device_t self, device_t child)
382 {
383 int i;
384 struct ubsa_softc *sc = device_private(self);
385
386 for (i = 0; i < sc->sc_numif; i++) {
387 if (sc->sc_subdevs[i] == child)
388 break;
389 }
390 KASSERT(i < sc->sc_numif);
391 sc->sc_subdevs[i] = NULL;
392 }
393
394 static int
395 uhmodem_detach(device_t self, int flags)
396 {
397 struct ubsa_softc *sc = device_private(self);
398 int i;
399 int rv = 0;
400
401 DPRINTF(("uhmodem_detach: sc = %p\n", sc));
402
403 sc->sc_dying = true;
404
405 ubsa_close_pipe(sc);
406
407 for (i = 0; i < sc->sc_numif; i++) {
408 if (sc->sc_subdevs[i] != NULL) {
409 rv |= config_detach(sc->sc_subdevs[i], flags);
410 sc->sc_subdevs[i] = NULL;
411 }
412 }
413
414 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
415 sc->sc_dev);
416
417 return rv;
418 }
419
420 static int
421 uhmodem_open(void *addr, int portno)
422 {
423 struct ubsa_softc *sc = addr;
424 usbd_status err;
425
426 DPRINTF(("%s: sc = %p\n", __func__, sc));
427
428 if (sc->sc_dying)
429 return EIO;
430
431 err = uhmodem_endpointhalt(sc, 0);
432 if (err) {
433 aprint_error("%s: endpointhalt fail\n", __func__);
434 return EIO;
435 } else
436 usbd_delay_ms(sc->sc_udev, 50);
437
438 if (sc->sc_devflags & A2502) {
439 err = a2502_init(sc->sc_udev);
440 if (err) {
441 aprint_error("%s: a2502init fail\n", __func__);
442 return EIO;
443 } else
444 usbd_delay_ms(sc->sc_udev, 50);
445 }
446 #if 0 /* currently disabled */
447 if (sc->sc_devflags & E220) {
448 err = e220_init(sc->sc_udev);
449 if (err) {
450 aprint_error("%s: e220init fail\n", __func__);
451 return EIO;
452 } else
453 usbd_delay_ms(sc->sc_udev, 50);
454 }
455 #endif
456 if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
457 sc->sc_intr_buf = kmem_alloc(sc->sc_isize, KM_SLEEP);
458 /* XXX only iface# = 0 has intr line */
459 /* XXX E220 specific? need to check */
460 err = usbd_open_pipe_intr(sc->sc_iface[0],
461 sc->sc_intr_number,
462 USBD_SHORT_XFER_OK,
463 &sc->sc_intr_pipe,
464 sc,
465 sc->sc_intr_buf,
466 sc->sc_isize,
467 ubsa_intr,
468 UBSA_INTR_INTERVAL);
469 if (err) {
470 aprint_error_dev(sc->sc_dev,
471 "cannot open interrupt pipe (addr %d)\n",
472 sc->sc_intr_number);
473 return EIO;
474 }
475 }
476
477 return 0;
478 }
479
480 /*
481 * Hauwei E220 needs special request to enable modem function.
482 * -- DEVICE_REMOTE_WAKEUP ruquest to endpoint 2.
483 */
484 static usbd_status
485 e220_modechange_request(struct usbd_device *dev)
486 {
487 #define E220_MODE_CHANGE_REQUEST 0x2
488 usb_device_request_t req;
489 usbd_status err;
490
491 req.bmRequestType = UT_WRITE_DEVICE;
492 req.bRequest = UR_SET_FEATURE;
493 USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
494 USETW(req.wIndex, E220_MODE_CHANGE_REQUEST);
495 USETW(req.wLength, 0);
496
497 DPRINTF(("%s: send e220 mode change request\n", __func__));
498 err = usbd_do_request(dev, &req, 0);
499 if (err) {
500 DPRINTF(("%s: E220 mode change fail\n", __func__));
501 return EIO;
502 }
503
504 return 0;
505 #undef E220_MODE_CHANGE_REQUEST
506 }
507
508 static usbd_status
509 uhmodem_endpointhalt(struct ubsa_softc *sc, int iface)
510 {
511 usb_endpoint_descriptor_t *ed;
512 usb_interface_descriptor_t *id;
513 usbd_status err;
514 int i;
515
516 /* Find the endpoints */
517 id = usbd_get_interface_descriptor(sc->sc_iface[iface]);
518
519 for (i = 0; i < id->bNumEndpoints; i++) {
520 ed = usbd_interface2endpoint_descriptor(sc->sc_iface[iface], i);
521 if (ed == NULL)
522 return EIO;
523
524 if (UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
525 err = usbd_clear_endpoint_feature(sc->sc_udev,
526 ed->bEndpointAddress, UF_ENDPOINT_HALT);
527 if (err) {
528 DPRINTF(("%s: ENDPOINT_HALT to EP:%d fail\n",
529 __func__, ed->bEndpointAddress));
530 return EIO;
531 }
532
533 }
534 } /* end of Endpoint loop */
535
536 return 0;
537 }
538
539 static usbd_status
540 uhmodem_regwrite(struct usbd_device *dev, uint8_t *data, size_t len)
541 {
542 usb_device_request_t req;
543 usbd_status err;
544
545 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
546 req.bRequest = UHMODEM_REGWRITE;
547 USETW(req.wValue, 0x0000);
548 USETW(req.wIndex, 0x0000);
549 USETW(req.wLength, len);
550 err = usbd_do_request(dev, &req, data);
551 if (err)
552 return err;
553
554 return 0;
555 }
556
557 static usbd_status
558 uhmodem_regread(struct usbd_device *dev, uint8_t *data, size_t len)
559 {
560 usb_device_request_t req;
561 usbd_status err;
562
563 req.bmRequestType = UT_READ_CLASS_INTERFACE;
564 req.bRequest = UHMODEM_REGREAD;
565 USETW(req.wValue, 0x0000);
566 USETW(req.wIndex, 0x0000);
567 USETW(req.wLength, len);
568 err = usbd_do_request(dev, &req, data);
569
570 if (err)
571 return err;
572
573 return 0;
574 }
575
576 #if 0
577 static usbd_status
578 uhmodem_regsetup(struct usbd_device *dev, uint16_t cmd)
579 {
580 usb_device_request_t req;
581 usbd_status err;
582
583 req.bmRequestType = UT_READ_CLASS_INTERFACE;
584 req.bRequest = UHMODEM_SETUP;
585 USETW(req.wValue, cmd);
586 USETW(req.wIndex, 0x0000);
587 USETW(req.wLength, 0);
588 err = usbd_do_request(dev, &req, 0);
589
590 if (err)
591 return err;
592
593 return 0;
594 }
595 #endif
596
597 static usbd_status
598 a2502_init(struct usbd_device *dev)
599 {
600 uint8_t data[8];
601 static uint8_t init_cmd[] = {0x00, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x08};
602 #ifdef UHMODEM_DEBUG
603 int i;
604 #endif
605 if (uhmodem_regread(dev, data, 7)) {
606 DPRINTF(("%s: read fail\n", __func__));
607 return EIO;
608 }
609 #ifdef UHMODEM_DEBUG
610 printf("%s: readdata: ", __func__);
611 for (i = 0; i < 7; i++)
612 printf("%#x ", data[i]);
613 #endif
614 if (uhmodem_regwrite(dev, init_cmd, sizeof(init_cmd)) ) {
615 DPRINTF(("%s: write fail\n", __func__));
616 return EIO;
617 }
618
619 if (uhmodem_regread(dev, data, 7)) {
620 DPRINTF(("%s: read fail\n", __func__));
621 return EIO;
622 }
623 #ifdef UHMODEM_DEBUG
624 printf("%s: readdata: ", __func__);
625 printf(" => ");
626 for (i = 0; i < 7; i++)
627 printf("%#x ", data[i]);
628 printf("\n");
629 #endif
630 return 0;
631 }
632
633
634 #if 0
635 /*
636 * Windows device driver send these sequens of USB requests.
637 * However currently I can't understand what the messege is,
638 * disable this code when I get more information about it.
639 */
640 static usbd_status
641 e220_init(struct usbd_device *dev)
642 {
643 uint8_t data[8];
644 usb_device_request_t req;
645 int i;
646
647 /* vendor specific unknown request */
648 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
649 req.bRequest = 0x02;
650 USETW(req.wValue, 0x0001);
651 USETW(req.wIndex, 0x0000);
652 USETW(req.wLength, 2);
653 data[0] = 0x0;
654 data[1] = 0x0;
655 if (usbd_do_request(dev, &req, data))
656 goto error;
657
658 /* vendor specific unknown sequence */
659 if(uhmodem_regsetup(dev, 0x1))
660 goto error;
661
662 if (uhmodem_regread(dev, data, 7))
663 goto error;
664
665 data[1] = 0x8;
666 data[2] = 0x7;
667 if (uhmodem_regwrite(dev, data, sizeof(data)) )
668 goto error;
669
670 if (uhmodem_regread(dev, data, 7))
671 goto error;
672 /* XXX should verify the read data ? */
673
674 if (uhmodem_regsetup(dev, 0x3))
675 goto error;
676
677 return 0;
678 error:
679 DPRINTF(("%s: E220 init request fail\n", __func__));
680 return EIO;
681 }
682 #endif
683
684