2005-06-24 07:02:35 +02:00
|
|
|
/* dvb-usb-urb.c is part of the DVB USB library.
|
|
|
|
*
|
2006-09-30 11:53:48 +02:00
|
|
|
* Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
|
2005-06-24 07:02:35 +02:00
|
|
|
* see dvb-usb-init.c for copyright information.
|
|
|
|
*
|
2006-09-30 11:53:48 +02:00
|
|
|
* This file keeps functions for initializing and handling the
|
2005-06-24 07:02:35 +02:00
|
|
|
* USB and URB stuff.
|
|
|
|
*/
|
|
|
|
#include "dvb-usb-common.h"
|
|
|
|
|
|
|
|
int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
|
|
|
|
u16 rlen, int delay_ms)
|
|
|
|
{
|
|
|
|
int actlen,ret = -ENOMEM;
|
|
|
|
|
|
|
|
if (d->props.generic_bulk_ctrl_endpoint == 0) {
|
|
|
|
err("endpoint for generic control not specified.");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wbuf == NULL || wlen == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2006-02-07 09:49:14 +01:00
|
|
|
if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
|
2005-06-24 07:02:35 +02:00
|
|
|
return ret;
|
|
|
|
|
2005-07-08 02:58:08 +02:00
|
|
|
deb_xfer(">>> ");
|
2005-06-24 07:02:35 +02:00
|
|
|
debug_dump(wbuf,wlen,deb_xfer);
|
|
|
|
|
|
|
|
ret = usb_bulk_msg(d->udev,usb_sndbulkpipe(d->udev,
|
|
|
|
d->props.generic_bulk_ctrl_endpoint), wbuf,wlen,&actlen,
|
2005-07-08 02:58:27 +02:00
|
|
|
2000);
|
2005-06-24 07:02:35 +02:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
err("bulk message failed: %d (%d/%d)",ret,wlen,actlen);
|
|
|
|
else
|
|
|
|
ret = actlen != wlen ? -1 : 0;
|
|
|
|
|
|
|
|
/* an answer is expected, and no error before */
|
|
|
|
if (!ret && rbuf && rlen) {
|
|
|
|
if (delay_ms)
|
|
|
|
msleep(delay_ms);
|
|
|
|
|
|
|
|
ret = usb_bulk_msg(d->udev,usb_rcvbulkpipe(d->udev,
|
|
|
|
d->props.generic_bulk_ctrl_endpoint),rbuf,rlen,&actlen,
|
2005-07-08 02:58:27 +02:00
|
|
|
2000);
|
2005-06-24 07:02:35 +02:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
err("recv bulk message failed: %d",ret);
|
2005-07-08 02:58:08 +02:00
|
|
|
else {
|
|
|
|
deb_xfer("<<< ");
|
2005-06-24 07:02:35 +02:00
|
|
|
debug_dump(rbuf,actlen,deb_xfer);
|
2005-07-08 02:58:08 +02:00
|
|
|
}
|
2005-06-24 07:02:35 +02:00
|
|
|
}
|
|
|
|
|
2006-02-07 09:49:14 +01:00
|
|
|
mutex_unlock(&d->usb_mutex);
|
2005-06-24 07:02:35 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_usb_generic_rw);
|
|
|
|
|
|
|
|
int dvb_usb_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
|
|
|
|
{
|
|
|
|
return dvb_usb_generic_rw(d,buf,len,NULL,0,0);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_usb_generic_write);
|
|
|
|
|
2006-09-30 11:53:48 +02:00
|
|
|
static void dvb_usb_data_complete(struct usb_data_stream *stream, u8 *buffer, size_t length)
|
2005-07-08 02:58:08 +02:00
|
|
|
{
|
2006-09-30 11:53:48 +02:00
|
|
|
struct dvb_usb_adapter *adap = stream->user_priv;
|
|
|
|
if (adap->feedcount > 0 && adap->state & DVB_USB_ADAP_STATE_DVB)
|
|
|
|
dvb_dmx_swfilter(&adap->demux, buffer, length);
|
2005-06-24 07:02:35 +02:00
|
|
|
}
|
|
|
|
|
2006-09-19 17:51:43 +02:00
|
|
|
static void dvb_usb_data_complete_204(struct usb_data_stream *stream, u8 *buffer, size_t length)
|
|
|
|
{
|
|
|
|
struct dvb_usb_adapter *adap = stream->user_priv;
|
|
|
|
if (adap->feedcount > 0 && adap->state & DVB_USB_ADAP_STATE_DVB)
|
|
|
|
dvb_dmx_swfilter_204(&adap->demux, buffer, length);
|
|
|
|
}
|
|
|
|
|
2006-09-30 11:53:48 +02:00
|
|
|
int dvb_usb_adapter_stream_init(struct dvb_usb_adapter *adap)
|
2005-07-08 02:58:08 +02:00
|
|
|
{
|
2006-09-30 11:53:48 +02:00
|
|
|
adap->stream.udev = adap->dev->udev;
|
2006-09-19 17:51:43 +02:00
|
|
|
if (adap->props.caps & DVB_USB_ADAP_RECEIVES_204_BYTE_TS)
|
|
|
|
adap->stream.complete = dvb_usb_data_complete_204;
|
|
|
|
else
|
2006-09-30 11:53:48 +02:00
|
|
|
adap->stream.complete = dvb_usb_data_complete;
|
|
|
|
adap->stream.user_priv = adap;
|
|
|
|
return usb_urb_init(&adap->stream, &adap->props.stream);
|
2005-06-24 07:02:35 +02:00
|
|
|
}
|
|
|
|
|
2006-09-30 11:53:48 +02:00
|
|
|
int dvb_usb_adapter_stream_exit(struct dvb_usb_adapter *adap)
|
2005-06-24 07:02:35 +02:00
|
|
|
{
|
2006-09-30 11:53:48 +02:00
|
|
|
return usb_urb_exit(&adap->stream);
|
2005-06-24 07:02:35 +02:00
|
|
|
}
|