20 #include <asm/byteorder.h>
28 static int is_clear_halt_cmd(
struct urb *
urb)
39 static int is_set_interface_cmd(
struct urb *urb)
49 static int is_set_configuration_cmd(
struct urb *urb)
59 static int is_reset_device_cmd(
struct urb *urb)
78 static int tweak_clear_halt_cmd(
struct urb *urb)
99 target_pipe = usb_rcvctrlpipe(urb->dev, target_endp);
101 target_pipe = usb_sndctrlpipe(urb->dev, target_endp);
105 dev_err(&urb->dev->dev,
"usb_clear_halt error: devnum %d endp "
106 "%d ret %d\n", urb->dev->devnum, target_endp, ret);
108 dev_info(&urb->dev->dev,
"usb_clear_halt done: devnum %d endp "
109 "%d\n", urb->dev->devnum, target_endp);
114 static int tweak_set_interface_cmd(
struct urb *urb)
126 interface, alternate);
130 dev_err(&urb->dev->dev,
"usb_set_interface error: inf %u alt "
131 "%u ret %d\n", interface, alternate, ret);
133 dev_info(&urb->dev->dev,
"usb_set_interface done: inf %u alt "
134 "%u\n", interface, alternate);
139 static int tweak_set_configuration_cmd(
struct urb *urb)
163 dev_info(&urb->dev->dev,
"usb_set_configuration %d to %s... skip!\n",
164 config, dev_name(&urb->dev->dev));
170 static int tweak_reset_device_cmd(
struct urb *urb)
175 dev_info(&urb->dev->dev,
"usb_queue_reset_device\n");
183 dev_err(&urb->dev->dev,
"could not obtain lock to reset device\n");
187 usb_unlock_device(
sdev->udev);
195 static void tweak_special_requests(
struct urb *urb)
197 if (!urb || !urb->setup_packet)
200 if (usb_pipetype(urb->pipe) != PIPE_CONTROL)
203 if (is_clear_halt_cmd(urb))
205 tweak_clear_halt_cmd(urb);
207 else if (is_set_interface_cmd(urb))
209 tweak_set_interface_cmd(urb);
211 else if (is_set_configuration_cmd(urb))
213 tweak_set_configuration_cmd(urb);
215 else if (is_reset_device_cmd(urb))
216 tweak_reset_device_cmd(urb);
263 spin_unlock_irqrestore(&sdev->
priv_lock, flags);
283 "failed to unlink a urb %p, ret %d\n",
300 spin_unlock_irqrestore(&sdev->
priv_lock, flags);
311 spin_lock(&ud->
lock);
316 spin_unlock(&ud->
lock);
334 spin_unlock_irqrestore(&sdev->
priv_lock, flags);
348 spin_unlock_irqrestore(&sdev->
priv_lock, flags);
353 static int get_pipe(
struct stub_device *sdev,
int epnum,
int dir)
355 struct usb_device *
udev = sdev->
udev;
356 struct usb_host_endpoint *ep;
360 ep = udev->ep_in[epnum & 0x7f];
362 ep = udev->ep_out[epnum & 0x7f];
370 if (usb_endpoint_xfer_control(epd)) {
372 return usb_sndctrlpipe(udev, epnum);
374 return usb_rcvctrlpipe(udev, epnum);
377 if (usb_endpoint_xfer_bulk(epd)) {
379 return usb_sndbulkpipe(udev, epnum);
381 return usb_rcvbulkpipe(udev, epnum);
384 if (usb_endpoint_xfer_int(epd)) {
386 return usb_sndintpipe(udev, epnum);
388 return usb_rcvintpipe(udev, epnum);
391 if (usb_endpoint_xfer_isoc(epd)) {
393 return usb_sndisocpipe(udev, epnum);
395 return usb_rcvisocpipe(udev, epnum);
403 static void masking_bogus_flags(
struct urb *urb)
406 struct usb_device *
dev;
407 struct usb_host_endpoint *ep;
409 unsigned int allowed;
411 if (!urb || urb->hcpriv || !urb->complete)
417 ep = (usb_pipein(urb->pipe) ? dev->ep_in : dev->ep_out)
418 [usb_pipeendpoint(urb->pipe)];
422 xfertype = usb_endpoint_type(&ep->desc);
432 is_out = usb_endpoint_dir_out(&ep->desc);
436 allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT |
437 URB_DIR_MASK | URB_FREE_BUFFER);
441 allowed |= URB_ZERO_PACKET;
444 allowed |= URB_NO_FSBR;
448 allowed |= URB_SHORT_NOT_OK;
451 allowed |= URB_ISO_ASAP;
454 urb->transfer_flags &= allowed;
457 static void stub_recv_cmd_submit(
struct stub_device *sdev,
463 struct usb_device *udev = sdev->
udev;
464 int pipe = get_pipe(sdev, pdu->
base.ep, pdu->
base.direction);
466 priv = stub_priv_alloc(sdev, pdu);
471 if (usb_pipeisoc(pipe))
484 if (pdu->
u.
cmd_submit.transfer_buffer_length > 0) {
485 priv->
urb->transfer_buffer =
488 if (!priv->
urb->transfer_buffer) {
498 if (!priv->
urb->setup_packet) {
505 priv->
urb->context = (
void *) priv;
520 tweak_special_requests(priv->
urb);
522 masking_bogus_flags(priv->
urb);
555 memset(&pdu, 0,
sizeof(pdu));
559 if (ret !=
sizeof(pdu)) {
560 dev_err(dev,
"recv a header, %d\n", ret);
570 if (!valid_request(sdev, &pdu)) {
571 dev_err(dev,
"recv invalid request\n");
576 switch (pdu.
base.command) {
578 stub_recv_cmd_unlink(sdev, &pdu);
582 stub_recv_cmd_submit(sdev, &pdu);