Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 1 | /* dvb-usb-urb.c is part of the DVB USB library. |
| 2 | * |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 3 | * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 4 | * see dvb-usb-init.c for copyright information. |
| 5 | * |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 6 | * This file keeps functions for initializing and handling the |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 7 | * USB and URB stuff. |
| 8 | */ |
| 9 | #include "dvb-usb-common.h" |
| 10 | |
| 11 | int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf, |
| 12 | u16 rlen, int delay_ms) |
| 13 | { |
| 14 | int actlen,ret = -ENOMEM; |
| 15 | |
Daniel J Blueman | 8268c8f | 2008-06-02 20:05:14 -0300 | [diff] [blame] | 16 | if (!d || wbuf == NULL || wlen == 0) |
| 17 | return -EINVAL; |
| 18 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 19 | if (d->props.generic_bulk_ctrl_endpoint == 0) { |
| 20 | err("endpoint for generic control not specified."); |
| 21 | return -EINVAL; |
| 22 | } |
| 23 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 24 | if ((ret = mutex_lock_interruptible(&d->usb_mutex))) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 25 | return ret; |
| 26 | |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 27 | deb_xfer(">>> "); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 28 | debug_dump(wbuf,wlen,deb_xfer); |
| 29 | |
| 30 | ret = usb_bulk_msg(d->udev,usb_sndbulkpipe(d->udev, |
| 31 | d->props.generic_bulk_ctrl_endpoint), wbuf,wlen,&actlen, |
Patrick Boettcher | e161f81 | 2005-07-07 17:58:27 -0700 | [diff] [blame] | 32 | 2000); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 33 | |
| 34 | if (ret) |
| 35 | err("bulk message failed: %d (%d/%d)",ret,wlen,actlen); |
| 36 | else |
| 37 | ret = actlen != wlen ? -1 : 0; |
| 38 | |
| 39 | /* an answer is expected, and no error before */ |
| 40 | if (!ret && rbuf && rlen) { |
| 41 | if (delay_ms) |
| 42 | msleep(delay_ms); |
| 43 | |
| 44 | ret = usb_bulk_msg(d->udev,usb_rcvbulkpipe(d->udev, |
| 45 | d->props.generic_bulk_ctrl_endpoint),rbuf,rlen,&actlen, |
Patrick Boettcher | e161f81 | 2005-07-07 17:58:27 -0700 | [diff] [blame] | 46 | 2000); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 47 | |
| 48 | if (ret) |
| 49 | err("recv bulk message failed: %d",ret); |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 50 | else { |
| 51 | deb_xfer("<<< "); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 52 | debug_dump(rbuf,actlen,deb_xfer); |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 53 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 56 | mutex_unlock(&d->usb_mutex); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 57 | return ret; |
| 58 | } |
| 59 | EXPORT_SYMBOL(dvb_usb_generic_rw); |
| 60 | |
| 61 | int dvb_usb_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len) |
| 62 | { |
| 63 | return dvb_usb_generic_rw(d,buf,len,NULL,0,0); |
| 64 | } |
| 65 | EXPORT_SYMBOL(dvb_usb_generic_write); |
| 66 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 67 | static void dvb_usb_data_complete(struct usb_data_stream *stream, u8 *buffer, size_t length) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 68 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 69 | struct dvb_usb_adapter *adap = stream->user_priv; |
| 70 | if (adap->feedcount > 0 && adap->state & DVB_USB_ADAP_STATE_DVB) |
| 71 | dvb_dmx_swfilter(&adap->demux, buffer, length); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Patrick Boettcher | 0540c49 | 2006-09-19 12:51:43 -0300 | [diff] [blame] | 74 | static void dvb_usb_data_complete_204(struct usb_data_stream *stream, u8 *buffer, size_t length) |
| 75 | { |
| 76 | struct dvb_usb_adapter *adap = stream->user_priv; |
| 77 | if (adap->feedcount > 0 && adap->state & DVB_USB_ADAP_STATE_DVB) |
| 78 | dvb_dmx_swfilter_204(&adap->demux, buffer, length); |
| 79 | } |
| 80 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 81 | int dvb_usb_adapter_stream_init(struct dvb_usb_adapter *adap) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 82 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 83 | adap->stream.udev = adap->dev->udev; |
Patrick Boettcher | 0540c49 | 2006-09-19 12:51:43 -0300 | [diff] [blame] | 84 | if (adap->props.caps & DVB_USB_ADAP_RECEIVES_204_BYTE_TS) |
| 85 | adap->stream.complete = dvb_usb_data_complete_204; |
| 86 | else |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 87 | adap->stream.complete = dvb_usb_data_complete; |
| 88 | adap->stream.user_priv = adap; |
| 89 | return usb_urb_init(&adap->stream, &adap->props.stream); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 92 | int dvb_usb_adapter_stream_exit(struct dvb_usb_adapter *adap) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 93 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 94 | return usb_urb_exit(&adap->stream); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 95 | } |