huawei.patch

alexh, 05/06/2009 07:06 AM

Download (2.84 KB)

View differences:

sys/dev/usbmisc/ugensa/ugensa.c
76 76
static void ugensa_get_status(void *, int, u_char *, u_char *);
77 77
static void ugensa_set(void *, int, int, int);
78 78

  
79
static void ugensa_e220_changemode(usbd_device_handle);
79
static int ugensa_e220_changemode(struct usb_attach_arg *);
80 80

  
81 81
static device_method_t ugensa_methods[] = {
82 82
	/* Device interface */
......
173 173

  
174 174
	if (uaa->iface == NULL)
175 175
		return UMATCH_NONE;
176

  
177
	/*
178
	 * Some devices have massstorage interfaces - don't claim ownership
179
	 * of these ... in general.
180
	 * 
181
	 * Some devices (most notably Huawei E220) need special handling
182
	 * though. These come up with single umass interface, waiting for
183
	 * magic sent to it, detach and attach again with three interfaces.
184
	 * We have to claim such mass storage interface to send a magic to
185
	 * it.
186
	 */
187
	id = usbd_get_interface_descriptor(uaa->iface);
188
	if (id == NULL || id->bInterfaceClass == UICLASS_MASS) {
189
		if ((uaa->vendor == 0x12d1 && uaa->product == 0x1003) ||
190
		    (uaa->vendor == 0x12d1 && uaa->product == 0x1004)) {
191
			if (uaa->nifaces == 1)
192
				return UMATCH_VENDOR_IFACESUBCLASS;
193
			else
194
				return UMATCH_NONE;
195
		} else
196
			return UMATCH_NONE;
197
	}
176
		
177
	if (uaa->vendor == 0x12d1)
178
		return ugensa_e220_changemode(uaa);
198 179

  
199 180
	return (usb_lookup(ugensa_devs, uaa->vendor, uaa->product) != NULL) ?
200 181
	    UMATCH_VENDOR_IFACESUBCLASS : UMATCH_NONE;
......
218 199
	ucom->sc_iface = uaa->iface;
219 200

  
220 201
	id = usbd_get_interface_descriptor(ucom->sc_iface);
221
	if (id == NULL || id->bInterfaceClass == UICLASS_MASS) {
222
		if ((uaa->vendor == 0x12d1 && uaa->product == 0x1003) ||
223
		    (uaa->vendor == 0x12d1 && uaa->product == 0x1004)) {
224
			ugensa_e220_changemode(uaa->device);
225
		}
226
		return ENXIO;
227
	}
228 202

  
229 203
	sc->sc_iface_no = id->bInterfaceNumber;
230 204
	ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
......
468 442
	(void)usbd_do_request(sc->sc_ucom.sc_udev, &req, 0);
469 443
}
470 444

  
471
static void
472
ugensa_e220_changemode(usbd_device_handle dev)
445
static int
446
ugensa_e220_changemode(struct usb_attach_arg *uaa)
473 447
{
474 448
	usb_device_request_t req;
449
	usbd_device_handle dev;
450
	//usb_interface_descriptor_t *id;
451
	
452
	//id = usbd_get_interface_descriptor(uaa->iface);
453

  
454
	if (uaa->nifaces > 1)
455
		return UMATCH_VENDOR_IFACESUBCLASS;
456

  
457
	dev = uaa->device;
475 458

  
476 459
	req.bmRequestType = UT_WRITE_DEVICE;
477 460
	req.bRequest = UR_SET_FEATURE;
......
480 463
	USETW(req.wLength, 0);
481 464

  
482 465
	usbd_do_request(dev, &req, 0);
466
	
467
	return -1; // from NetBSD: avoid umass to reattach (UMATCH_HIGHEST)
483 468
}
484 469