Пример #1
0
static int usb_open(struct aura_node *node, const char *opts)
{
	int ret; 
	struct usb_dev_info *inf = calloc(1, sizeof(*inf));

	if (!inf)
		return -ENOMEM;

	ret = libusb_init(&inf->ctx);
	if (ret != 0) 
		return -EIO;

	inf->io_buf_size = 256;
	inf->optbuf = strdup(opts);
	inf->dev_descr.device_found_func = usb_start_ops;
	inf->dev_descr.arg = inf;
	inf->node = node;
	parse_params(inf);
	
	ncusb_start_descriptor_watching(node, inf->ctx);
	aura_set_transportdata(node, inf);	

	slog(4, SLOG_INFO, "usb: vid 0x%x pid 0x%x vendor %s product %s serial %s", 
	     inf->dev_descr.vid, inf->dev_descr.pid, inf->dev_descr.vendor, 
	     inf->dev_descr.product, inf->dev_descr.serial);

	inf->ctrlbuf   = malloc(inf->io_buf_size);
	if (!inf->ctrlbuf)
		goto err_free_inf;
	inf->itransfer = libusb_alloc_transfer(0);
	if (!inf->itransfer)
		goto err_free_cbuf;

 	inf->ctransfer = libusb_alloc_transfer(0);
	if (!inf->ctransfer)
		goto err_free_int;
	
	slog(1, SLOG_INFO, "usb: Now looking for a matching device");

	ncusb_watch_for_device(inf->ctx, &inf->dev_descr);

	return 0;
	
err_free_int:
	libusb_free_transfer(inf->itransfer);
err_free_cbuf:
	free(inf->ctrlbuf);
err_free_inf:
	libusb_exit(inf->ctx);
	free(inf);
	return -ENOMEM;
}
Пример #2
0
static void activate_run_state(struct fpi_ssm *ssm)
{
	struct fp_img_dev *dev = ssm->priv;
	struct upektc_dev *upekdev = dev->priv;
	int r;

	switch (ssm->cur_state) {
	case WRITE_INIT:
	{
		struct libusb_transfer *transfer = libusb_alloc_transfer(0);
		if (!transfer) {
			fpi_ssm_mark_aborted(ssm, -ENOMEM);
			return;
		}
		libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_out,
			(unsigned char*)upekdev->setup_commands[upekdev->init_idx].cmd,
			UPEKTC_CMD_LEN, write_init_cb, ssm, BULK_TIMEOUT);
		r = libusb_submit_transfer(transfer);
		if (r < 0) {
			libusb_free_transfer(transfer);
			fpi_ssm_mark_aborted(ssm, -ENOMEM);
		}
	}
	break;
	case READ_DATA:
	{
		struct libusb_transfer *transfer = libusb_alloc_transfer(0);
		unsigned char *data;

		if (!transfer) {
			fpi_ssm_mark_aborted(ssm, -ENOMEM);
			break;
		}

		data = g_malloc(upekdev->setup_commands[upekdev->init_idx].response_len);
		libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_in, data,
			upekdev->setup_commands[upekdev->init_idx].response_len,
			read_init_data_cb, ssm, BULK_TIMEOUT);

		r = libusb_submit_transfer(transfer);
		if (r < 0) {
			g_free(data);
			libusb_free_transfer(transfer);
			fpi_ssm_mark_aborted(ssm, r);
		}
	}
	break;
	}
}
Пример #3
0
static void capture_run_state(struct fpi_ssm *ssm)
{
	struct fp_img_dev *dev = ssm->priv;
	struct upektc_dev *upekdev = dev->priv;
	int r;

	switch (ssm->cur_state) {
	case CAPTURE_WRITE_CMD:
	{
		struct libusb_transfer *transfer = libusb_alloc_transfer(0);
		if (!transfer) {
			fpi_ssm_mark_aborted(ssm, -ENOMEM);
			return;
		}
		libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_out,
			(unsigned char *)scan_cmd, UPEKTC_CMD_LEN,
			capture_cmd_cb, ssm, BULK_TIMEOUT);
		r = libusb_submit_transfer(transfer);
		if (r < 0) {
			libusb_free_transfer(transfer);
			fpi_ssm_mark_aborted(ssm, -ENOMEM);
		}
	}
	break;
	case CAPTURE_READ_DATA:
	{
		struct libusb_transfer *transfer = libusb_alloc_transfer(0);
		unsigned char *data;

		if (!transfer) {
			fpi_ssm_mark_aborted(ssm, -ENOMEM);
			break;
		}

		data = g_malloc(IMAGE_SIZE);
		libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_in, data, IMAGE_SIZE,
			capture_read_data_cb, ssm, BULK_TIMEOUT);

		r = libusb_submit_transfer(transfer);
		if (r < 0) {
			g_free(data);
			libusb_free_transfer(transfer);
			fpi_ssm_mark_aborted(ssm, r);
		}
	}
	break;
	};
}
Пример #4
0
static void dev_deactivate(struct fp_img_dev *dev)
{
    struct vfs0050_dev *vfs_dev = dev->priv;
    int err = 0;
    int tmpoffset;
    int to_send;
    struct libusb_transfer *t;
    vfs_dev->is_active = 0;
    //EP2 IN
    t = libusb_alloc_transfer(0);
    libusb_fill_bulk_transfer(t, dev->udev, EP2_IN, vfs_dev->tmpbuf, 64, generic_async_cb, NULL, 100);
    libusb_submit_transfer(t);
    //EP1_IN
    t = libusb_alloc_transfer(0);
    libusb_fill_bulk_transfer(t, dev->udev, EP1_IN, vfs_dev->tmpbuf, 64, generic_async_cb, NULL, 100);
    libusb_submit_transfer(t);
    //EP1_OUT
    t = libusb_alloc_transfer(0);
    vfs_dev->tmpbuf[0] = 0x04;
    libusb_fill_bulk_transfer(t, dev->udev, EP1_OUT, vfs_dev->tmpbuf, 1, generic_async_cb, NULL, 100);
    libusb_submit_transfer(t);
    //EP1_IN
    t = libusb_alloc_transfer(0);
    libusb_fill_bulk_transfer(t, dev->udev, EP1_IN, vfs_dev->tmpbuf, 64, generic_async_cb, NULL, 100);
    libusb_submit_transfer(t);
    //EP1_OUT
    t = libusb_alloc_transfer(0);
    libusb_fill_bulk_transfer(t, dev->udev, EP1_OUT, vfs0050_deactivate1, 64, generic_async_cb, NULL, 100);
    libusb_submit_transfer(t);
    //EP1_OUT
    t = libusb_alloc_transfer(0);
    libusb_fill_bulk_transfer(t, dev->udev, EP1_OUT, &vfs0050_deactivate1[64], 61, generic_async_cb, NULL, 100);
    libusb_submit_transfer(t);
    tmpoffset = 0;
    do {
        to_send = sizeof(vfs0050_activate2) - tmpoffset;
        to_send = to_send >= 64 ? 64 : to_send;
        t = libusb_alloc_transfer(0);
        libusb_fill_bulk_transfer(t, dev->udev, EP1_OUT, vfs0050_activate2 + tmpoffset, to_send, generic_async_cb, NULL, 100);
        libusb_submit_transfer(t);
        tmpoffset += err;
    } while (err == 64);
    do {
        t = libusb_alloc_transfer(0);
        libusb_fill_bulk_transfer(t, dev->udev, EP1_IN, vfs_dev->tmpbuf, 64, generic_async_cb, NULL, 100);
        libusb_submit_transfer(t);
    } while(err == 64);
    t = libusb_alloc_transfer(0);
    libusb_fill_bulk_transfer(t, dev->udev, EP1_IN, vfs_dev->tmpbuf, 64, generic_async_cb, NULL, 100);
    libusb_submit_transfer(t);
    //TODO: finish this, leaves device in inconsistent state.
    fpi_imgdev_deactivate_complete(dev);
}
Пример #5
0
int main() {
	int i;
	for (i=0;i<2000;i++) {
		sinbuffer[i] = sin(i*567*2*M_PI/2000.);
	}

	file = fopen("20k.bin","r");
	assert(file);

	struct libusb_transfer *xfrs[NUMTRANSFERS];

	libusb_init(NULL);
	libusb_device_handle *dev = libusb_open_device_with_vid_pid(NULL,0x03eb,0x204f);
	assert(dev);

	for (i=0;i<NUMTRANSFERS;i++) {
		xfrs[i] = libusb_alloc_transfer(50);
		char *buf = malloc(PACKETS*PACKETSIZE);
		libusb_fill_iso_transfer(xfrs[i],dev,0x01,buf,PACKETS*PACKETSIZE,PACKETS,callback,NULL,0);
		libusb_set_iso_packet_lengths(xfrs[i],PACKETSIZE);
		transfer(xfrs[i]);
	}
	t = dtime();
	while (1) libusb_handle_events(NULL);
}
Пример #6
0
SR_PRIV int hantek_6xxx_get_channeldata(const struct sr_dev_inst *sdi,
		libusb_transfer_cb_fn cb, uint32_t data_amount)
{
	struct sr_usb_dev_inst *usb;
	struct libusb_transfer *transfer;
	int ret;
	unsigned char *buf;

	sr_dbg("Request channel data.");

	usb = sdi->conn;

	if (!(buf = g_try_malloc(data_amount))) {
		sr_err("Failed to malloc USB endpoint buffer.");
		return SR_ERR_MALLOC;
	}
	transfer = libusb_alloc_transfer(0);
	libusb_fill_bulk_transfer(transfer, usb->devhdl, HANTEK_EP_IN, buf,
			data_amount, cb, (void *)sdi, 4000);
	if ((ret = libusb_submit_transfer(transfer)) < 0) {
		sr_err("Failed to submit transfer: %s.",
			libusb_error_name(ret));
		/* TODO: Free them all. */
		libusb_free_transfer(transfer);
		g_free(buf);
		return SR_ERR;
	}

	return SR_OK;
}
Пример #7
0
int usb_send_interrupt_out(int usb_number, unsigned char* buffer, unsigned char length)
{
  struct usb_state* state = usb_states+usb_number;

  if(!state->devh)
  {
    fprintf(stderr, "no usb device opened for index %d\n", usb_number);
    return -1;
  }

  unsigned char* buf = calloc(length, sizeof(unsigned char));
  if(!buf)
  {
    fprintf(stderr, "calloc failed\n");
    return -1;
  }

  memcpy(buf, buffer, length);

  if(state->type == C_TYPE_XONE_PAD && length > 2)
  {
    buf[2] = state->counter++;
  }

  struct libusb_transfer* transfer = libusb_alloc_transfer(0);

  transfer->flags = LIBUSB_TRANSFER_FREE_BUFFER | LIBUSB_TRANSFER_FREE_TRANSFER;

  libusb_fill_interrupt_transfer(transfer, state->devh, controller[state->type].endpoints.out.address, buf, length, (libusb_transfer_cb_fn)usb_callback, usb_state_indexes+usb_number, 1000);

  return submit_transfer(transfer);
}
Пример #8
0
A2300::BulkDataPort::TransferContext*	A2300::BulkDataPort::CreateReadTransferContext(
		byte* bufFrame, size_t sizeFrame)
{
    libusb_transfer *lut = libusb_alloc_transfer(0);
    TransferContext* pctxt = new TransferContext();

     libusb_fill_bulk_transfer(
         lut,                                                    // transfer
         DeviceHandle(),                                         // dev_handle
         epidIn(),                                               // endpoint
         bufFrame,      // buffer
         (int) sizeFrame,                                 // length
         &A2300::BulkDataPort::LibusbAsyncReadCallback,                // callback
         pctxt,          // user_data
         0                                                       // timeout (ms)
     );

     pctxt->pSrc = this;
     pctxt->lut = lut;
     pctxt->bufFrame = bufFrame;
     pctxt->nFrameSize = sizeFrame;
     //m_listReadContexts.push_back( pctxt);

     return pctxt;
}
Пример #9
0
void
USBInterface::submit_write(int endpoint, uint8_t* data_in, int len,
                           const boost::function<bool (libusb_transfer*)>& callback)
{
  libusb_transfer* transfer = libusb_alloc_transfer(0);
  transfer->flags |= LIBUSB_TRANSFER_FREE_BUFFER;

  // copy data into a newly allocated buffer
  uint8_t* data = static_cast<uint8_t*>(malloc(sizeof(uint8_t) * len));
  memcpy(data, data_in, len);

  libusb_fill_interrupt_transfer(transfer, m_handle,
                                 static_cast<unsigned char>(endpoint | LIBUSB_ENDPOINT_OUT),
                                 data, len,
                                 &USBInterface::on_write_data_wrap, 
                                 new USBWriteCallback(this, callback),
                                 0); // timeout

  int ret;
  ret = libusb_submit_transfer(transfer);
  if (ret != LIBUSB_SUCCESS)
  {
    libusb_free_transfer(transfer);
    raise_exception(std::runtime_error, "libusb_submit_transfer(): " << usb_strerror(ret));
  }
  else
  {
    m_endpoints[endpoint | LIBUSB_ENDPOINT_OUT] = transfer;
  }
}
Пример #10
0
static void sm_write_reg(struct fpi_ssm *ssm, unsigned char reg,
	unsigned char value)
{
	struct fp_img_dev *dev = ssm->priv;
	struct libusb_transfer *transfer = libusb_alloc_transfer(0);
	unsigned char *data;
	int r;
	
	if (!transfer) {
		fpi_ssm_mark_aborted(ssm, -ENOMEM);
		return;
	}

	fp_dbg("set %02x=%02x", reg, value);
	data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE);
	libusb_fill_control_setup(data, CTRL_OUT, reg, value, 0, 0);
	libusb_fill_control_transfer(transfer, dev->udev, data, sm_write_reg_cb,
		ssm, CTRL_TIMEOUT);
	r = libusb_submit_transfer(transfer);
	if (r < 0) {
		g_free(data);
		libusb_free_transfer(transfer);
		fpi_ssm_mark_aborted(ssm, r);
	}
}
Пример #11
0
static void sm_exec_cmd(struct fpi_ssm *ssm, unsigned char cmd,
	unsigned char param)
{
	struct fp_img_dev *dev = ssm->priv;
	struct libusb_transfer *transfer = libusb_alloc_transfer(0);
	unsigned char *data;
	int r;
	
	if (!transfer) {
		fpi_ssm_mark_aborted(ssm, -ENOMEM);
		return;
	}

	fp_dbg("cmd %02x param %02x", cmd, param);
	data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE);
	libusb_fill_control_setup(data, CTRL_IN, cmd, param, 0, 0);
	libusb_fill_control_transfer(transfer, dev->udev, data, sm_exec_cmd_cb,
		ssm, CTRL_TIMEOUT);
	r = libusb_submit_transfer(transfer);
	if (r < 0) {
		g_free(data);
		libusb_free_transfer(transfer);
		fpi_ssm_mark_aborted(ssm, r);
	}
}
Пример #12
0
void FX3Dev::startRead( DeviceDataHandlerIfce* handler ) {
    fprintf(stderr,"FX3Dev::startRead()\n");
    size_tx_mb = 0.0;
    
    int res;
    for(uint32_t i = 0;i<buffers_count;i++) {
        transfers[i] = libusb_alloc_transfer(0);
        if ( transfers[i] == NULL ) {
            fprintf( stderr, "FX3Dev::startRead() __error__ libusb_alloc_transfer(0) returned NULL\n" );
            abort();
        }
    }

    for(uint32_t i = 0;i<buffers_count;i++) {
        libusb_fill_bulk_transfer(transfers[i], device_handle, (endpoint_from_dev_num | LIBUSB_ENDPOINT_IN), half_full_buffers[i],
                                  half_full_size8, FX3Dev::onDataReady, this, DEV_DOWNLOAD_TIMEOUT_MS);
    }
    
    data_handler = handler;
    event_loop_running = true;
    event_thread = std::thread(&FX3Dev::event_loop, this);
    
    for(uint32_t i = 0;i<buffers_count;i++) {
        res = libusb_submit_transfer(transfers[i]);
        if(res != 0) {
            fprintf(stderr,"FX3Dev::startRead() __error__ libusb_submit_transfer%d %d %s\n", i, res, libusb_error_name(res));
            abort();
        }
    }
}
Пример #13
0
static void aesX660_read_response(struct fpi_ssm *ssm, size_t buf_len,
	libusb_transfer_cb_fn callback)
{
	struct fp_img_dev *dev = ssm->priv;
	struct libusb_transfer *transfer = libusb_alloc_transfer(0);
	unsigned char *data;
	int r;

	if (!transfer) {
		fpi_ssm_mark_aborted(ssm, -ENOMEM);
		return;
	}

	data = g_malloc(buf_len);
	libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN,
		data, buf_len,
		callback, ssm, BULK_TIMEOUT);

	r = libusb_submit_transfer(transfer);
	if (r < 0) {
		fp_dbg("Failed to submit rx transfer: %d\n", r);
		g_free(data);
		libusb_free_transfer(transfer);
		fpi_ssm_mark_aborted(ssm, r);
	}
}
Пример #14
0
bool TransferBuffer::initTransfers(void)
	{
	/* Allocate the transfer backing buffer: */
	buffer=new unsigned char[numTransfers*transferSize];
	
	/* Allocate all USB transfer objects: */
	transfers=new libusb_transfer*[numTransfers];
	for(unsigned int i=0;i<numTransfers;++i)
		transfers[i]=0;
	unsigned char* bufPtr=buffer;
	bool ok=true;
	for(unsigned int i=0;i<numTransfers&&ok;++i,bufPtr+=transferSize)
		ok=(transfers[i]=libusb_alloc_transfer(numPackets))!=0;
	
	/* Check for errors: */
	if(!ok)
		{
		/* Delete all transfers that were successfully allocated: */
		for(unsigned int i=0;i<numTransfers;++i)
			libusb_free_transfer(transfers[i]);
		delete[] transfers;
		
		/* Delete the backing buffer: */
		delete[] buffer;
		}
	
	return ok;
	}
Пример #15
0
static libusb_transfer*
alloc_lut (fusb_ephandle *self, int buffer_length, int endpoint,
           bool input_p, unsigned char *write_buffer,
           fusb_devhandle *dh)
{

  struct libusb_transfer* lut = libusb_alloc_transfer(0);

  endpoint = (endpoint & 0x7f) | (input_p ? 0x80 : 0);

  if (input_p)
    write_buffer = new unsigned char [buffer_length];

  // We need the base class libusb_device_handle
  libusb_device_handle *dev_handle = dh->get_usb_dev_handle();

  // Load the libusb_transfer for bulk transfer
  libusb_fill_bulk_transfer (lut,		// transfer
                             dev_handle,        // dev_handle
                             endpoint,		// endpoint
                             write_buffer,	// buffer
                             buffer_length,	// length
                             generic_callback,	// callback
                             self,		// user_data
                             0);	// timeout
  return lut;
}
Пример #16
0
int cmd_rx_data(struct libusb_device_handle* devh) {
	empty_usb_buf =(u8 *) malloc(BUFFER_SIZE);
	rx_xfer = libusb_alloc_transfer(0);
	libusb_fill_bulk_transfer(rx_xfer, devh, DATA_IN, empty_usb_buf,
			BUFFER_SIZE, cb_xfer, NULL, TIMEOUT);

	cmd_rx_syms(devh, num_blocks);

	r = libusb_submit_transfer(rx_xfer);
	if (r < 0) {
		fprintf(stderr, "rx_xfer submission: %d\n", r);
		return -1;
	}

	while (1) {
		while (!usb_really_full) {
			handle_events_wrapper();
		}

		/* process each received block */
		for (i = 0; i < xfer_blocks; i++) {
			rx = (usb_pkt_rx *)(full_usb_buf + PKT_LEN * i);
			if(rx->pkt_type != KEEP_ALIVE) 
				(*cb)(cb_args, rx, bank);
			bank = (bank + 1) % NUM_BANKS;

		}
		usb_really_full = 0;
	}
}
Пример #17
0
int fnusb_start_iso(fnusb_dev *dev, fnusb_isoc_stream *strm, fnusb_iso_cb cb, int ep, int xfers, int pkts, int len)
{
	freenect_context *ctx = dev->parent->parent;
	int ret, i;

	strm->parent = dev;
	strm->cb = cb;
	strm->num_xfers = xfers;
	strm->pkts = pkts;
	strm->len = len;
	strm->buffer = (uint8_t*)malloc(xfers * pkts * len);
	strm->xfers = (struct libusb_transfer**)malloc(sizeof(struct libusb_transfer*) * xfers);
	strm->dead = 0;
	strm->dead_xfers = 0;

	uint8_t *bufp = strm->buffer;

	for (i=0; i<xfers; i++) {
		FN_SPEW("Creating EP %02x transfer #%d\n", ep, i);
		strm->xfers[i] = libusb_alloc_transfer(pkts);

		libusb_fill_iso_transfer(strm->xfers[i], dev->dev, ep, bufp, pkts * len, pkts, iso_callback, strm, 0);

		libusb_set_iso_packet_lengths(strm->xfers[i], len);

		ret = libusb_submit_transfer(strm->xfers[i]);
		if (ret < 0)
			FN_WARNING("Failed to submit isochronous transfer %d: %d\n", i, ret);

		bufp += pkts*len;
	}

	return 0;

}
Пример #18
0
void
cp_usb_async_read(struct cp_usb_async *cp, uint8_t *valuep)
{
	int	p;
	int	ret;

	if (cp->p == MAX_OUTSTANDING)
		cp_usb_async_sync(cp);
	p = cp->p;
	if (!cp->packet[p].transfer)
		cp->packet[p].transfer = libusb_alloc_transfer(0);
	cp->packet[p].valuep = valuep;
	cp->packet[p].direction = packet_read;
	libusb_fill_control_setup(cp->packet[p].data,
				  0xc0,			/* request */
				  0xff,			/* request type */
				  0x00c2,		/* value */
				  0,			/* index */
				  1);			/* length */

	libusb_fill_control_transfer(cp->packet[p].transfer,
				     cp->handle,
				     cp->packet[p].data,
				     cp_usb_async_transfer_callback,
				     cp,
				     CP_TIMEOUT);
	ccdbg_debug(CC_DEBUG_USB_ASYNC, "Read packet %d\n", p);
	ret = libusb_submit_transfer(cp->packet[p].transfer);
	if (ret)
		fprintf(stderr, "libusb_submit_transfer failed %d\n", ret);
	cp->p++;
}
Пример #19
0
static void start_finger_detection(struct fp_img_dev *dev)
{
	int r;
	struct upektc_dev *upekdev = dev->priv;
	struct libusb_transfer *transfer;
	fp_dbg("");

	if (upekdev->deactivating) {
		complete_deactivation(dev);
		return;
	}

	transfer = libusb_alloc_transfer(0);
	if (!transfer) {
		fpi_imgdev_session_error(dev, -ENOMEM);
		return;
	}
	libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_out,
		(unsigned char *)scan_cmd, UPEKTC_CMD_LEN,
		finger_det_cmd_cb, dev, BULK_TIMEOUT);
	r = libusb_submit_transfer(transfer);
	if (r < 0) {
		libusb_free_transfer(transfer);
		fpi_imgdev_session_error(dev, r);
	}
}
Пример #20
0
FCDevice::Transfer::Transfer(FCDevice *device, void *buffer, int length)
    : transfer(libusb_alloc_transfer(0)),
      device(device)
{
    libusb_fill_bulk_transfer(transfer, device->mHandle,
        OUT_ENDPOINT, (uint8_t*) buffer, length, FCDevice::completeTransfer, this, 2000);
}
Пример #21
0
void
USBInterface::submit_read(int endpoint, int len, 
                          const boost::function<bool (uint8_t*, int)>& callback)
{
  assert(m_endpoints.find(endpoint) == m_endpoints.end());
  libusb_transfer* transfer = libusb_alloc_transfer(0);
  transfer->flags |= LIBUSB_TRANSFER_FREE_BUFFER;

  uint8_t* data = static_cast<uint8_t*>(malloc(sizeof(uint8_t) * len));

  libusb_fill_interrupt_transfer(transfer, m_handle,
                                 static_cast<unsigned char>(endpoint | LIBUSB_ENDPOINT_IN),
                                 data, len,
                                 &USBInterface::on_read_data_wrap, 
                                 new USBReadCallback(this, callback),
                                 0); // timeout
  int ret;
  ret = libusb_submit_transfer(transfer);
  if (ret != LIBUSB_SUCCESS)
  {
    libusb_free_transfer(transfer);
    raise_exception(std::runtime_error, "libusb_submit_transfer(): " << usb_strerror(ret));
  }
  else
  {
    // transfer is send on its way, so store it
    m_endpoints[endpoint | LIBUSB_ENDPOINT_IN] = transfer;
  }
}
Пример #22
0
	bool FalconCommLibUSB::write(uint8_t* buffer, unsigned int size)
	{
		LOG_DEBUG("Writing " << size << " bytes");
		if(!m_isCommOpen)
		{
			LOG_ERROR("Device not open");
			m_errorCode = FALCON_COMM_DEVICE_NOT_VALID_ERROR;
			return false;
		}

		m_lastBytesWritten = size;
		in_transfer = libusb_alloc_transfer(0);
		if (!in_transfer)
		{
			m_errorCode = FALCON_COMM_DEVICE_ERROR;
			LOG_ERROR("Cannot allocate inbound transfer");
			return false;
		}

		libusb_fill_bulk_transfer(in_transfer, m_falconDevice, 0x02, buffer,
								  size, FalconCommLibUSB::cb_in, this, 0);
		libusb_submit_transfer(in_transfer);
		m_isWriteAllocated = true;
		m_hasBytesAvailable = false;
		issueRead();
		return true;
	}
Пример #23
0
int freespace_initiateReceiveTransfers(struct FreespaceDevice* device) {
    int rc = LIBUSB_SUCCESS;
    int i;

    device->receiveQueueHead_ = 0;
    for (i = 0; i < FREESPACE_RECEIVE_QUEUE_SIZE; i++) {
        struct FreespaceReceiveTransfer* rt = &device->receiveQueue_[i];
        rt->device_ = device;
        rt->transfer_ = libusb_alloc_transfer(0);
        libusb_fill_interrupt_transfer(rt->transfer_,
                                       device->handle_,
                                       device->readEndpointAddress_,
                                       rt->buffer_,
                                       device->maxReadSize_,
                                       receiveCallback,
                                       rt,
                                       0);
        rc = libusb_submit_transfer(rt->transfer_);
        if (rc != LIBUSB_SUCCESS) {
            freespace_terminateReceiveTransfers(device);
            break;
        }

        rt->submitted_ = 1;
    }

    return libusb_to_freespace_error(rc);
}
Пример #24
0
	void FalconCommLibUSB::issueRead()
	{
		//If a read is already allocated, don't reallocate
		//We'll expect someone else to do this for us again later
		if(m_isReadAllocated)
		{
			return;
		}

		//Try to read over 64 and you'll fry libusb-1.0. Try to read under
		//64 and you'll fry OS X. So, read 64.
		out_transfer = libusb_alloc_transfer(0);
		if (!out_transfer)
		{
			m_errorCode = FALCON_COMM_DEVICE_ERROR;
			LOG_ERROR("Cannot allocate outbound transfer");
			return;
		}

		libusb_fill_bulk_transfer(out_transfer, m_falconDevice, 0x81, output,
								  64, FalconCommLibUSB::cb_out, this, 1000);
		libusb_submit_transfer(out_transfer);
		m_isReadAllocated = true;

	}
Пример #25
0
/* Once setup has succeded, this is called once to start transfers. */
int usb_start_transfers(int fd) {
    if (!is_setup) {
        LOGD("Must call setup before starting.\n");
        return -1;
    }
	static uint8_t buf[PACKET_SIZE * NUM_PACKETS];
	static struct libusb_transfer *xfr[NUM_TRANSFERS];
	int num_iso_pack = NUM_PACKETS;
    int i;

    outfd = fd;
    if (outfd < 3) {
        LOGD("Set outfd to %d. Are you sure?\n", outfd);
    }

    for (i=0; i<NUM_TRANSFERS; i++) {
        xfr[i] = libusb_alloc_transfer(num_iso_pack);
        if (!xfr[i]) {
            LOGD("libusb_alloc_transfer failed.\n");
            return -ENOMEM;
        }

        libusb_fill_iso_transfer(xfr[i], devh, EP_ISO_IN, buf,
                sizeof(buf), num_iso_pack, transfer_cb, NULL, 1000);
        libusb_set_iso_packet_lengths(xfr[i], sizeof(buf)/num_iso_pack);

        libusb_submit_transfer(xfr[i]);
    }
    return 0;
}
/**
 * \brief Submit a bulk transfer to the device.
 *
 * This method allocates and fills the bulk transfer, and submits it to
 * the libusb_submit_transfer function. It then starts to handle events,
 * and only returns when the complete flag is set.
 * \param dev_handle    the libusb device handle
 */
void	BulkTransfer::submit(libusb_device_handle *dev_handle) throw(USBError) {
    // allocate the transfer structure
    transfer = libusb_alloc_transfer(0);

    // fill the transfer
    libusb_fill_bulk_transfer(transfer, dev_handle,
                              endpoint->bEndpointAddress(), data,
                              length, bulktransfer_callback, this, timeout);

    // submit the transfer
    debug(LOG_DEBUG, DEBUG_LOG, 0, "submitting bulk transfer, timeout = %d",
          timeout);
    int	rc = libusb_submit_transfer(transfer);
    if (rc != LIBUSB_SUCCESS) {
        throw USBError(libusb_error_name(rc));
    }

    // handle events until the complete flag is set
    libusb_context  *ctx = getContext();
    while (!complete) {
        libusb_handle_events(ctx);
    }

    // at this point, the transfer has somehow completed, but we
    // don't know yet what happened.
    const char	*cause = usb_status_name(transfer->status);
    if (NULL != cause) {
        debug(LOG_ERR, DEBUG_LOG, 0, "transfer failed: %s", cause);
        throw USBError(cause);
    } else {
        debug(LOG_DEBUG, DEBUG_LOG, 0, "transfer complete, %d bytes",
              transfer->actual_length);
    }
}
Пример #27
0
int fnusb_start_iso(fnusb_dev *dev, fnusb_isoc_stream *strm, fnusb_iso_cb cb, int ep, int xfers, int pkts, int len)
{
	int ret, i;

	strm->parent = dev;
	strm->cb = cb;
	strm->num_xfers = xfers;
	strm->pkts = pkts;
	strm->len = len;
	strm->buffer = malloc(xfers * pkts * len);
	strm->xfers = malloc(sizeof(struct libusb_transfer*) * xfers);

	uint8_t *bufp = strm->buffer;

	for (i=0; i<xfers; i++) {
		printf("Creating EP %02x transfer #%d\n", ep, i);
		strm->xfers[i] = libusb_alloc_transfer(pkts);

		libusb_fill_iso_transfer(strm->xfers[i], dev->dev, ep, bufp, pkts * len, pkts, iso_callback, strm, 0);

		libusb_set_iso_packet_lengths(strm->xfers[i], len);

		ret = libusb_submit_transfer(strm->xfers[i]);
		if (ret < 0)
			printf("Failed to submit xfer %d: %d\n", i, ret);

		bufp += pkts*len;
	}

	return 0;

}
Пример #28
0
int slogic_prime_data(struct slogic_ctx *handle, unsigned int transfer_id){
char * buffer;	
struct libusb_transfer *newtransfer;	

	buffer = malloc(handle->transfer_buffer_size);
	assert(buffer);
	newtransfer = libusb_alloc_transfer(0);
	newtransfer->flags |= (LIBUSB_TRANSFER_FREE_BUFFER |  LIBUSB_TRANSFER_FREE_TRANSFER );
	if (newtransfer == NULL) {
		log_printf( ERR, "libusb_alloc_transfer failed\n");
		handle->recording_state = UNKNOWN;
		return 1;
	}
	
	handle->transfers[transfer_id].logic_context = handle;
	handle->transfers[transfer_id].transfer = newtransfer;
	handle->transfers[transfer_id].transfer_id = transfer_id;
	handle->transfers[transfer_id].state = 0;
	
//FIXME return value?
	libusb_fill_bulk_transfer(newtransfer, handle->device_handle, SALEAE_STREAMING_DATA_IN_ENDPOINT, (unsigned char *)buffer, handle->transfer_buffer_size,slogic_read_samples_callback,&handle->transfers[transfer_id], handle->transfer_timeout);
	return 0;

	
}
Пример #29
0
static struct libusb_transfer *hmcfgusb_prepare_int(libusb_device_handle *devh, libusb_transfer_cb_fn cb, void *data, int in_size)
{
	unsigned char *data_buf;
	struct libusb_transfer *transfer;
	int err;

	data_buf = malloc(in_size);
	if (!data_buf) {
		fprintf(stderr, "Can't allocate memory for data-buffer!\n");
		return NULL;
	}

	transfer = libusb_alloc_transfer(0);
	if (!transfer) {
		fprintf(stderr, "Can't allocate memory for usb-transfer!\n");
		free(data_buf);
		return NULL;
	}

	libusb_fill_interrupt_transfer(transfer, devh, EP_IN,
			data_buf, in_size, cb, data, USB_TIMEOUT);

	transfer->flags = LIBUSB_TRANSFER_FREE_BUFFER;

	err = libusb_submit_transfer(transfer);
	if (err != 0) {
		fprintf(stderr, "Can't submit transfer: %s\n", usb_strerror(err));
		libusb_free_transfer(transfer);
		return NULL;
	}

	return transfer;
}
Пример #30
0
FCDevice::Transfer::Transfer(FCDevice *device, void *buffer, int length, PacketType type)
    : transfer(libusb_alloc_transfer(0)),
      type(type), finished(false)
{
    libusb_fill_bulk_transfer(transfer, device->mHandle,
        OUT_ENDPOINT, (uint8_t*) buffer, length, FCDevice::completeTransfer, this, 2000);
}