1/* $FreeBSD: head/sys/dev/usb2/core/usb2_handle_request.c 187173 2009-01-13 19:03:12Z thompsa $ */ |
2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 71 unchanged lines hidden (view full) --- 81 82 /* handle the request */ 83 err = usb2_handle_request(xfer); 84 85 if (err) { 86 87 if (err == USB_ERR_BAD_CONTEXT) { 88 /* we need to re-setup the control transfer */ |
89 usb2_needs_explore(xfer->xroot->bus, 0); |
90 break; 91 } 92 /* 93 * If no control transfer is active, 94 * receive the next SETUP message: 95 */ 96 goto tr_restart; 97 } --- 23 unchanged lines hidden (view full) --- 121 * 122 * Returns: 123 * 0: Success 124 * Else: Failure 125 *------------------------------------------------------------------------*/ 126static usb2_error_t 127usb2_handle_set_config(struct usb2_xfer *xfer, uint8_t conf_no) 128{ |
129 struct usb2_device *udev = xfer->xroot->udev; |
130 usb2_error_t err = 0; 131 132 /* 133 * We need to protect against other threads doing probe and 134 * attach: 135 */ 136 USB_XFER_UNLOCK(xfer); 137 mtx_lock(&Giant); /* XXX */ |
138 sx_xlock(udev->default_sx + 1); |
139 140 if (conf_no == USB_UNCONFIG_NO) { 141 conf_no = USB_UNCONFIG_INDEX; 142 } else { 143 /* 144 * The relationship between config number and config index 145 * is very simple in our case: 146 */ 147 conf_no--; 148 } 149 |
150 if (usb2_set_config_index(udev, conf_no)) { |
151 DPRINTF("set config %d failed\n", conf_no); 152 err = USB_ERR_STALLED; 153 goto done; 154 } |
155 if (usb2_probe_and_attach(udev, USB_IFACE_INDEX_ANY)) { |
156 DPRINTF("probe and attach failed\n"); 157 err = USB_ERR_STALLED; 158 goto done; 159 } 160done: 161 mtx_unlock(&Giant); /* XXX */ |
162 sx_unlock(udev->default_sx + 1); |
163 USB_XFER_LOCK(xfer); 164 return (err); 165} 166 167/*------------------------------------------------------------------------* 168 * usb2_handle_iface_request 169 * 170 * Returns: 171 * 0: Success 172 * Else: Failure 173 *------------------------------------------------------------------------*/ 174static usb2_error_t 175usb2_handle_iface_request(struct usb2_xfer *xfer, 176 void **ppdata, uint16_t *plen, 177 struct usb2_device_request req, uint16_t off, uint8_t state) 178{ 179 struct usb2_interface *iface; 180 struct usb2_interface *iface_parent; /* parent interface */ |
181 struct usb2_device *udev = xfer->xroot->udev; |
182 int error; 183 uint8_t iface_index; 184 185 if ((req.bmRequestType & 0x1F) == UT_INTERFACE) { 186 iface_index = req.wIndex[0]; /* unicast */ 187 } else { 188 iface_index = 0; /* broadcast */ 189 } --- 138 unchanged lines hidden (view full) --- 328 * 329 * Returns: 330 * 0: Success 331 * Else: Failure 332 *------------------------------------------------------------------------*/ 333static usb2_error_t 334usb2_handle_set_stall(struct usb2_xfer *xfer, uint8_t ep, uint8_t do_stall) 335{ |
336 struct usb2_device *udev = xfer->xroot->udev; |
337 usb2_error_t err; 338 339 USB_XFER_UNLOCK(xfer); |
340 err = usb2_set_endpoint_stall(udev, 341 usb2_get_pipe_by_addr(udev, ep), do_stall); |
342 USB_XFER_LOCK(xfer); 343 return (err); 344} 345 346/*------------------------------------------------------------------------* 347 * usb2_handle_get_stall 348 * 349 * Returns: --- 26 unchanged lines hidden (view full) --- 376 * Else: Failure 377 *------------------------------------------------------------------------*/ 378static usb2_error_t 379usb2_handle_remote_wakeup(struct usb2_xfer *xfer, uint8_t is_on) 380{ 381 struct usb2_device *udev; 382 struct usb2_bus *bus; 383 |
384 udev = xfer->xroot->udev; |
385 bus = udev->bus; 386 387 USB_BUS_LOCK(bus); 388 389 if (is_on) { 390 udev->flags.remote_wakeup = 1; 391 } else { 392 udev->flags.remote_wakeup = 0; --- 83 unchanged lines hidden (view full) --- 476 off = UGETW(req.wLength) - rem; 477 } 478 479 /* set some defaults */ 480 481 max_len = 0; 482 src_zcopy = NULL; 483 src_mcopy = NULL; |
484 udev = xfer->xroot->udev; |
485 486 /* get some request fields decoded */ 487 488 wValue = UGETW(req.wValue); 489 wIndex = UGETW(req.wIndex); 490 491 DPRINTF("req 0x%02x 0x%02x 0x%04x 0x%04x " 492 "off=0x%x rem=0x%x, state=%d\n", req.bmRequestType, --- 264 unchanged lines hidden --- |