Example #1
0
void lamp_shutdown(){
  int ret = usb_release_interface(launcher, 0);
  printf("Released interface 0: %d\n", ret);
  ret = usb_release_interface(launcher, 1);
  printf("Released interface 1: %d\n", ret);
  usb_close(launcher);
}
Example #2
0
int main(void)
{
	struct usb_device *dev;
	usb_dev_handle *handle;
	uint16_t iface;
	int state;
	uint32_t offset;

	banner();
	usb_init();

retry:
	if(!(dev = find_dev()) || !(handle = get_dfu_interface(dev, &iface))) {
		puts("FATAL: No compatible device found!\n");
#ifdef WIN32
		system("pause");
#endif
		return -1;
	}

	state = dfu_getstate(handle, iface);
	if((state < 0) || (state == STATE_APP_IDLE)) {
		puts("Resetting device in firmware upgrade mode...");
		dfu_detach(handle, iface, 1000);
		usb_release_interface(handle, iface);
		usb_close(handle);
#ifdef WIN32
		Sleep(5000);
#else
		sleep(5);
#endif
		goto retry;
	}
	printf("Found device at %s:%s\n", dev->bus->dirname, dev->filename);

	dfu_makeidle(handle, iface);

	for(offset = 0; offset < bindatalen; offset += 1024) {
		printf("Progress: %d%%\r", (offset*100)/bindatalen);
		fflush(stdout);
		assert(stm32_mem_erase(handle, iface, LOAD_ADDRESS + offset) == 0);
		stm32_mem_write(handle, iface, (void*)&bindata[offset], 1024);
	}
	stm32_mem_manifest(handle, iface);

	usb_release_interface(handle, iface);
	usb_close(handle);

	puts("All operations complete!\n");

#ifdef WIN32
		system("pause");
#endif

	return 0;
}
Example #3
0
/*
 * Function usbobex_connect_request (self)
 *
 *    Open the USB connection
 *
 */
int usbobex_connect_request(obex_t *self)
{
	int ret;
#ifndef _WIN32

	DEBUG(4, "\n");

	self->trans.self.usb.dev_control = usb_open(self->trans.self.usb.device);
	self->trans.self.usb.dev_data = usb_open(self->trans.self.usb.device);

	ret = usb_set_configuration(self->trans.self.usb.dev_control, self->trans.self.usb.configuration);
	if (ret < 0) {
		DEBUG(4, "Can't set configuration %d", ret);
	}

	ret = usb_claim_interface(self->trans.self.usb.dev_control, self->trans.self.usb.control_interface);
	if (ret < 0) {
		DEBUG(4, "Can't claim control interface %d", ret);
		goto err1;
	}

	ret = usb_set_altinterface(self->trans.self.usb.dev_control, self->trans.self.usb.control_setting);
	if (ret < 0) {
		DEBUG(4, "Can't set control setting %d", ret);
		goto err2;
	}

	ret = usb_claim_interface(self->trans.self.usb.dev_data, self->trans.self.usb.data_interface);
	if (ret < 0) {
		DEBUG(4, "Can't claim data interface %d", ret);
		goto err2;
	}

	ret = usb_set_altinterface(self->trans.self.usb.dev_data, self->trans.self.usb.data_active_setting);
	if (ret < 0) {
		DEBUG(4, "Can't set data active setting %d", ret);
		goto err3;
	}
	self->trans.mtu = OBEX_MAXIMUM_MTU;
	DEBUG(2, "transport mtu=%d\n", self->trans.mtu);
	return 1;

err3:
	usb_release_interface(self->trans.self.usb.dev_data, self->trans.self.usb.data_interface);	
err2:
	usb_release_interface(self->trans.self.usb.dev_control, self->trans.self.usb.control_interface);
err1:
	usb_close(self->trans.self.usb.dev_data);
	usb_close(self->trans.self.usb.dev_control);
	return ret;

#endif /* _WIN32 */
}
Example #4
0
int k8061_ExecIO( int iCard, int nSend, int nReceive ) {

  int n_write = 0, n_read = 0;

  if ( iCard < 0 || iCard > 7 ) {
    fprintf( stderr, "*** error <k8061_ExecIO> : Card number out of range %d...\n", iCard );
    fflush( stderr );
    return -1;
  }

  if ( _k8061_IsOpen[iCard] ) {
    n_write = usb_bulk_write( _k8061_Handle[iCard] ,k8061_epWrite, _k8061_WriteBuffer, 
			      nSend, k8061_ioTimeOut );
    usleep( k8061_ioWait );
    if ( n_write < 0 ) {
      fprintf( stderr, "*** %s\n", usb_strerror() );
      fprintf( stderr, "*** error <k8061_ExecIO> : Error writing command to card %d\n", iCard );
      fflush( stderr );

      if ( _k8061_Handle[iCard] ) usb_release_interface( _k8061_Handle[iCard], k8061_iClaim );
      if ( _k8061_Handle[iCard] ) usb_close( _k8061_Handle[iCard] );
      _k8061_IsOpen[iCard] = 0;
      
      return -1;
    } 
    
    n_read = usb_bulk_read( _k8061_Handle[iCard] ,k8061_epRead, _k8061_ReadBuffer, 
			    nReceive, k8061_ioTimeOut );
    usleep( k8061_ioWait );
    if ( n_read < 0 ) {
      fprintf( stderr, "*** %s\n", usb_strerror() );
      fprintf( stderr, "*** error <k8061_ExecIO> : Error reading buffer from card %d\n", iCard );
      fflush( stderr );

      if ( _k8061_Handle[iCard] ) usb_release_interface( _k8061_Handle[iCard], k8061_iClaim );
      if ( _k8061_Handle[iCard] ) usb_close( _k8061_Handle[iCard] );
      _k8061_IsOpen[iCard] = 0;

      return -1;
    } 

  } else {
    fprintf( stderr, "*** error <k8061_ExecIO> : Card %d not found/not opened...\n", iCard );
    fflush( stderr );
    return -1;
  }
    
  return 0;
}
Example #5
0
static int drv_TF_close(void)
{
    usb_release_interface(lcd, interface);
    usb_close(lcd);

    return 0;
}
Example #6
0
int main(int argc, char * argv[])
{
	struct pwcmech * pwcmech;
	pwcmech->dev = ifinit_pwcblock();
	pwcmech->com = ifinit_usbcom();

	ifbind_pwcblock(pwcmech->dev, pwcmech->com);

	//use driver
	usb_init(pwcmech->com);
	if ( usb_open(pwcmech->com) )
	{
		finish(pwcmech);
		return 0;
	}

	//should work seamlessly
	usb_if_claim(pwcmech->com, pwcmech->com->standard_descriptors.highspeed.cameraStream.cameraStreamConf);

	setVideoMode(pwcmech, 9);

	setLeds(pwcmech, 10,5);

	usb_release_interface(pwcmech->com, pwcmech->com->standard_descriptors.highspeed.cameraStream.cameraStreamConf);

	usb_close(pwcmech->com);

	finish(pwcmech);

	return 0;
}
Example #7
0
int main( int argc, char **argv)
{
	usb_dev_handle *lvr_winusb;

	if ((lvr_winusb = setup_libusb_access()) == NULL) 
	{
		exit(-1);
	} 

	//printf("Testing control transfer: ");
	//test_control_transfer(lvr_winusb);

	//printf("Testing interrupt transfer: ");
	//test_interrupt_transfer(lvr_winusb);

	//printf("Testing bulk transfer: "); 
	//test_bulk_transfer(lvr_winusb);


	usb_release_interface(lvr_winusb, 0);
	usb_reset(lvr_winusb);
	usb_close(lvr_winusb);
	return 0;

}
Example #8
0
void hidasp_close(void)
{
	if(	usb_dev ) {
		usb_release_interface(usb_dev, 0);
		usb_close(usb_dev);
	}
}
Example #9
0
int main(void) {
    usb_dev_handle *dev = NULL; /* the device handle */
    uint8_t readBuffer[0x200*0x100];

    /* Set up USB */
    usb_init();
    usb_find_busses();
    usb_find_devices();

    if (!(dev = open_dev())) {
        perror("device not found!\n");
		exit(EXIT_FAILURE);
    }
/*
    if (usb_set_configuration(dev, 1) < 0) {
        perror("setting config 1 failed\n");
        usb_close(dev);
        exit(EXIT_FAILURE);
    }
*/
    if (usb_claim_interface(dev, 0) < 0)
    {
        perror("claiming interface failed\n");
        usb_close(dev);
        exit(EXIT_FAILURE);
    }
    //FIXME: sniffed
    read10(readBuffer,0x100,0x0,dev);
    printReadBuffer(readBuffer);

    /* Clean up */
    usb_release_interface(dev, 0);
    usb_close(dev);
    exit(0);
}
int _ykusb_read(void *dev, int report_type, int report_number,
		char *buffer, int size)
{
	int rc = usb_claim_interface((usb_dev_handle *)dev, 0);

	if (rc >= 0) {
		int rc2;
		rc = usb_control_msg((usb_dev_handle *)dev,
				     USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_ENDPOINT_IN,
				     HID_GET_REPORT,
				     report_type << 8 | report_number, 0,
				     buffer, size,
				     1000);
		/* preserve a control message error over an interface
		   release one */
		rc2 = usb_release_interface((usb_dev_handle *)dev, 0);
		if (rc >= 0 && rc2 < 0)
			rc = rc2;
	}
	if (rc >= 0)
		return rc;
	if(rc == 0)
		yk_errno = YK_ENODATA;
	else
		yk_errno = YK_EUSBERR;
	return 0;
}
Example #11
0
/*
 void test_control_transfer(usb_dev_handle *dev)
 {
//   usb_set_altinterface(dev, 0);
   usb_release_interface(dev, 0);
 }
*/
 void test_interrupt_transfer(usb_dev_handle *dev)
 {
   int r,i;
   char answer[reqIntLen];
   char question[reqIntLen];
   for (i=0;i<reqIntLen; i++) question[i]=i;
   r = usb_interrupt_write(dev, endpoint_Int_out, question, reqIntLen, timeout);
   if( r < 0 )
   {
	  perror("USB interrupt write"); bad("USB write failed"); 
   }
   r = usb_interrupt_read(dev, endpoint_Int_in, answer, reqIntLen, timeout);
   if( r != reqIntLen )
   {
	  perror("USB interrupt read"); bad("USB read failed"); 
   }
//   for (i=0;i<reqIntLen; i++) printf("%i, %i, \n",question[i],answer[i]);
	for(i = 0;i < reqIntLen; i++) {
		if(i%8 == 0)
			printf("\n");
		printf("%02x, %02x; ",question[i],answer[i]);
	}
	printf("\n");

//   usb_set_altinterface(dev, 0);
   usb_release_interface(dev, 0);
 }
Example #12
0
int xusb_close(struct xusb *xusb)
{
	if(xusb) {
		if(xusb->handle) {
			assert(xusb->spec);
			assert(xusb->spec->name);
			DBG("Closing interface \"%s\"\n", xusb->spec->name);
			if(xusb->is_claimed) {
				if(usb_release_interface(xusb->handle, xusb->spec->my_interface_num) != 0) {
					ERR("Releasing interface: usb: %s\n", usb_strerror());
				}
				xusb->is_claimed = 0;
			}
			if(xusb->is_open) {
				if(usb_close(xusb->handle) != 0) {
					ERR("Closing device: usb: %s\n", usb_strerror());
				}
				xusb->is_open = 0;
			}
			xusb->handle = NULL;
		}
		xusb = NULL;
	}
	return 0;
}
/**
 * Close the driver (do necessary clean-up).
 * \param drvthis  Pointer to driver structure.
 */
MODULE_EXPORT void
IOWarrior_close(Driver *drvthis)
{
  PrivateData *p = drvthis->private_data;

  if (p != NULL) {
    /* don't turn display off: keep the logoff message */
    // iowlcd_display_on_off(p,0,0,0);

    /* IOW leave LCD mode */
    iowlcd_disable(p);

    /* release interface 1 */
    usb_release_interface(p->udh, 1);

    /* close USB */
    usb_close(p->udh);

    if (p->framebuf != NULL)
      free(p->framebuf);
    p->framebuf = NULL;

    if (p->backingstore != NULL)
      free(p->backingstore);
    p->backingstore = NULL;

    free(p);
  }
  drvthis->store_private_ptr(drvthis, NULL);

  debug(RPT_DEBUG, "%s: closed", drvthis->name);
}
Example #14
0
//---------------------------------------------------------------------------
// Attempt to acquire a 1-Wire net
//
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
//                indicate the symbolic port number.
// 'port_zstr'  - zero terminated port name.  
// 'return_msg' - zero terminated return message. 
//
// Returns: TRUE - success, port opened
//
SMALLINT owAcquireUSB(int portnum, char *port_zstr, char *return_msg)
{
	if (!initted_flag)
		usb_ds2490_init();
	
	/* check the port string */
	if (strcmp (port_zstr, "USB")) {
		strcpy(return_msg, "owAcquire called with invalid port string\n");
	      	return 0;
	}
	
	/* check to see if the portnumber is valid */
	if (usb_num_devices < portnum) {
		strcpy(return_msg, "Attempted to select invalid port number\n");
		return FALSE;
	}

	/* check to see if opening the device is valid */
	if (usb_dev_handle_list[portnum] != NULL) {
		strcpy(return_msg, "Device allready open\n");
		return FALSE;
	}

	/* open the device */
	usb_dev_handle_list[portnum] = usb_open(usb_dev_list[portnum]);
	if (usb_dev_handle_list[portnum] == NULL) {
		strcpy(return_msg, "Failed to open usb device\n");
		printf("%s\n", usb_strerror());
		return FALSE;
	}

	/* set the configuration */
	if (usb_set_configuration(usb_dev_handle_list[portnum], 1)) {
		strcpy(return_msg, "Failed to set configuration\n");
		printf("%s\n", usb_strerror());
		usb_close(usb_dev_handle_list[portnum]);
		return FALSE;
	}

	/* claim the interface */
	if (usb_claim_interface(usb_dev_handle_list[portnum], 0)) {
		strcpy(return_msg, "Failed to claim interface\n");
		printf("%s\n", usb_strerror());
		usb_close(usb_dev_handle_list[portnum]);
		return FALSE;
	}

	/* set the alt interface */
	if (usb_set_altinterface(usb_dev_handle_list[portnum], 3)) {
		strcpy(return_msg, "Failed to set altinterface\n");
		printf("%s\n", usb_strerror());
		usb_release_interface(usb_dev_handle_list[portnum], 0);
		usb_close(usb_dev_handle_list[portnum]);
		return FALSE;
	}

	/* we're all set here! */
	strcpy(return_msg, "DS2490 successfully acquired by USB driver\n");
	return TRUE;
}
Example #15
0
static int pickit2_shutdown(void *data)
{
	/* Set all pins to float and turn voltages off */
	uint8_t command[CMD_LENGTH] = {
		CMD_EXEC_SCRIPT,
		8,
		SCR_SET_PINS,
		3, /* Bit-0=1(PDC In), Bit-1=1(PGD In), Bit-2=0(PDC LL), Bit-3=0(PGD LL) */
		SCR_SET_AUX,
		1, /* Bit-0=1(Aux In), Bit-1=0(Aux LL) */
		SCR_MCLR_GND_OFF,
		SCR_VPP_OFF,
		SCR_VDD_OFF,
		SCR_BUSY_LED_OFF,
		CMD_END_OF_BUFFER
	};

	int ret = usb_interrupt_write(pickit2_handle, ENDPOINT_OUT, (char *)command, CMD_LENGTH, DFLT_TIMEOUT);

	if (ret != CMD_LENGTH) {
		msg_perr("Command Shutdown failed (%s)!\n", usb_strerror());
		ret = 1;
	}
	if (usb_release_interface(pickit2_handle, 0) != 0) {
		msg_perr("Could not release USB interface!\n");
		ret = 1;
	}
	if (usb_close(pickit2_handle) != 0) {
		msg_perr("Could not close USB device!\n");
		ret = 1;
	}
	return ret;
}
Example #16
0
void teensy_close(void)
{
	if (!libusb_teensy_handle) return;
	usb_release_interface(libusb_teensy_handle, 0);
	usb_close(libusb_teensy_handle);
	libusb_teensy_handle = NULL;
}
Example #17
0
//---------------------------------------------------------------------------
// Release the previously acquired a 1-Wire net.
//
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
//                indicate the symbolic port number.
// 'return_msg' - zero terminated return message. 
//
void owReleaseUSB(int portnum, char *return_msg)
{
	usb_release_interface(usb_dev_handle_list[portnum], 0);
	usb_close(usb_dev_handle_list[portnum]);
	usb_dev_handle_list[portnum] = NULL;
	strcpy(return_msg, "DS2490 successfully released by USB driver\n");
}
Example #18
0
//----------------------------------------------------------------------
//check lockdown verifier button status
int ldn_verifier_checkbuttonstatus(void){
	struct usb_dev_handle *hdl;
	int status=-1;
	int verifier_was_unplugged=0;
	
	do{
		while( (hdl = ldn_find_verifier()) == NULL){
			verifier_was_unplugged=1;
			Sleep(100);	//discover our verifier
		}
		
		if(verifier_was_unplugged){
			verifier_was_unplugged=0;
			
			if(ldn_trusted_environment)
				usbdevice_setdevicestate(hdl, GREEN_LED); 
			else
				usbdevice_setdevicestate(hdl, RED_LED); 
		}
		
		status = usbdevice_checkbuttonstatus(hdl);
			
		usb_release_interface(hdl, 0);
		usb_close(hdl);
		
	}while(status < 0);
	
	return status;
}
Example #19
0
void PeperoniDevice::close(quint32 line, OperatingMode mode)
{
    m_operatingModes[line] &= ~mode;

    if (mode == InputMode && m_running == true)
    {
        m_running = false;
        wait();
    }

    if (m_operatingModes[line] != CloseMode)
        return;

    if (m_device != NULL && m_handle != NULL)
    {
        /* Release the interface in case we claimed it */
        int r = usb_release_interface(m_handle, PEPERONI_IFACE_EP0);
        if (r < 0)
        {
            qWarning() << "PeperoniDevice" << name(m_baseLine)
                       << "is unable to release interface EP0!";
        }

        usb_close(m_handle);
    }

    m_handle = NULL;
}
Example #20
0
grub_usb_err_t
grub_usb_bulk_write (grub_usb_device_t dev,
		     int endpoint, grub_size_t size, char *data)
{
  usb_dev_handle *devh;
  struct usb_device *d = dev->data;

  devh = usb_open (d);
  if (usb_claim_interface (devh, 0) < 0)
    goto fail;

  if (usb_bulk_write (devh, endpoint, data, size, 20) < 0)
    goto fail;

  if (usb_release_interface (devh, 0) < 0)
    goto fail;

  usb_close (devh);

  return GRUB_USB_ERR_NONE;

 fail:
  usb_close (devh);
  return GRUB_USB_ERR_STALL;
}
/*****************************************************************************
 *
 *					CloseUSB
 *
 ****************************************************************************/
status_t CloseUSB(unsigned int reader_index)
{
	/* device not opened */
	if (usbDevice[reader_index].handle == NULL)
		return STATUS_UNSUCCESSFUL;

	DEBUG_COMM3("Closing USB device: %s/%s",
		usbDevice[reader_index].dirname,
		usbDevice[reader_index].filename);

	if (usbDevice[reader_index].ccid.arrayOfSupportedDataRates
		&& (usbDevice[reader_index].ccid.bCurrentSlotIndex == 0))
	{
		free(usbDevice[reader_index].ccid.arrayOfSupportedDataRates);
		usbDevice[reader_index].ccid.arrayOfSupportedDataRates = NULL;
	}

	/* one slot closed */
	(*usbDevice[reader_index].nb_opened_slots)--;

	/* release the allocated ressources for the last slot only */
	if (0 == *usbDevice[reader_index].nb_opened_slots)
	{
		DEBUG_COMM("Last slot closed. Release resources");

		/* reset so that bSeq starts at 0 again */
		if (DriverOptions & DRIVER_OPTION_RESET_ON_CLOSE)
			(void)usb_reset(usbDevice[reader_index].handle);

		(void)usb_release_interface(usbDevice[reader_index].handle,
			usbDevice[reader_index].interface);
		(void)usb_close(usbDevice[reader_index].handle);
#ifdef __APPLE__
		DEBUG_INFO3("Terminating thread: %s/%s",
			usbDevice[reader_index].dirname, usbDevice[reader_index].filename);

		// Terminate thread
		*usbDevice[reader_index].pTerminated = TRUE;
		pthread_join(usbDevice[reader_index].hThread, NULL);

		// Free bStatus lock
		pthread_mutex_destroy(usbDevice[reader_index].ccid.pbStatusLock);
#endif
		// Free array of bStatus
		free(usbDevice[reader_index].ccid.bStatus);

		free(usbDevice[reader_index].dirname);
		free(usbDevice[reader_index].filename);
	}

	/* mark the resource unused */
	usbDevice[reader_index].handle = NULL;
	usbDevice[reader_index].dirname = NULL;
	usbDevice[reader_index].filename = NULL;
	usbDevice[reader_index].interface = 0;
	usbDevice[reader_index].ccid.bStatus = NULL;		// Array of bStatus

	return STATUS_SUCCESS;
} /* CloseUSB */
Example #22
0
static void usbtr_destroy(transport_t tr_base)
{
	struct rf2500_transport *tr = (struct rf2500_transport *)tr_base;

	usb_release_interface(tr->handle, tr->int_number);
	usb_close(tr->handle);
	free(tr);
}
Example #23
0
HardwareThunder::~HardwareThunder()
{
    if (m_usbHandler)
    {
        usb_release_interface(m_usbHandler, 0);
        usb_close(m_usbHandler);
    }
}
Example #24
0
/**
 * Disconnect from current device
 */
void M64BirDevice::disconnectDevice()
{
    usb_release_interface( mDeviceHandle, 0 );
    if( mDeviceHandle != NULL )
    {
        usb_close( mDeviceHandle );
    }
}
Example #25
0
void dpf_ax_close(DPFAXHANDLE h)
{
    DPFContext *dpf = (DPFContext *) h;

    usb_release_interface(dpf->udev, 0);
    usb_close(dpf->udev);
    free(dpf);
}
Example #26
0
/* USB::DevHandle#usb_release_interface(interface) */
static VALUE
rusb_release_interface(VALUE v, VALUE interface)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ret = usb_release_interface(p, NUM2INT(interface));
  check_usb_error("usb_release_interface", ret);
  return Qnil;
}
Example #27
0
void cleanup_USB_CTR( usb_dev_handle *udev )
{
  if (udev) {
    usb_clear_halt(udev, USB_ENDPOINT_IN|6);
    usb_release_interface(udev, 0);
    usb_close(udev);
  }
}
Example #28
0
void canon_close_camera(usb_dev_handle *camera_handle)
{
  /* close connection to the camera */
  fprintf(stderr, "Closing connection to camera... ");
  usb_release_interface(camera_handle, 0);
  usb_close(camera_handle);
  fprintf(stderr, "done.\n");
}
Example #29
0
static int drv_MOGX_close(void)
{
    /* close whatever port you've opened */
    usb_release_interface(lcd_dev, 0);
    usb_close(lcd_dev);

    return 0;
}
Example #30
0
void disconnectDevice() {
    if ( Connection_Status == CONNECTED) {
        //The following functiom releases a previously claimed interface
        usb_release_interface(MyLibusbDeviceHandle, 0);
        //closes a device opened
        usb_close(MyLibusbDeviceHandle);
    }
}