title: libusb bulk transfer
body: <p>I am trying to implement user space usb driver using libusb1.0.9. I have lpc2148 blueboard(ARM7) with me..This board is loaded with opensource USB stack/firmware by Mr. Bertrik Sikken. Now my user space driver is trying read write with board. I am getting garbage data.
  I want to know about the flow of bulk tranfer.
  For any transfer/transaction is there kernel device driver involved??
  and do we need usb gadget device driver also??
  I am not able to understand that where the data gets copied.
  Important thing is that when I read/write interrupt gets generated and I can see correct data on LCD. Do I need to read/write USBRxData/USBTxData?
  Please do the needfull.</p>
  
  <p>I tried the below code for bulk transfer read and write..</p>
  
  <pre><code>int usb_read(struct libusb_device *dev,struct libusb_device_handle *hDevice)  
  {  
      char *data,*data1;  
      struct  libusb_endpoint_descriptor *ep;     
      struct  libusb_interface_descriptor *id;  
      int len=64,r,ret_alt,ret_clm,ret_rst,i;  
      struct libusb_device **list;  
  
      data = (char *)malloc(512); //allocation  of buffers  
      data1 = (char *)malloc(512);  
      memset(data,'\0',512);  
      memset(data1,'\0',512);  
  
      if(hDevice==NULL)  
      {  
          printf("\nNO device found\n");  
          return 0;  
      }  
      int ret_open = libusb_open(dev,&amp;hDevice);  
      if(ret_open!=0)  
      {  
          printf("Error in libusb_open\n");  
          libusb_free_device_list(list,1);  
          return -1;  
      }       
      char str_tx[512]="G";    //data to send to device  
      char str_rx[512];        //receive string   
      data = str_tx;  
  
      printf("data::%s\t,str::%s\n",data,str_tx);  
      //printf("%c\n",data);  
      ep = active_config(dev,hDevice);  
      printf("after ep\n");  
      //printf("alt_interface = %d\n",alt_interface);  
      ret_rst = libusb_reset_device(hDevice);  
      if(ret_rst &lt; 0)  
      {  
          printf("Error in reset :: %d",ret_rst);  
          return -1;  
      }  
      printf("original data1 : %s\n",data1);  
      r = libusb_bulk_transfer(hDevice,0x08,str_tx,512,&amp;len,0);  
      //write to device buffer from data  
  
      printf("Error number :: %d\n",r);  
      int le = ep-&gt;bEndpointAddress;  
      int ty = ep-&gt;bDescriptorType;  
      int y = ep-&gt;bmAttributes;  
  
      printf("y::%d\tatt:: %d\n",y,ep-&gt;bmAttributes);  
      if(r==-1)  
          printf("Error in io\n");  
      if(r==0)  
      {  
          printf("data returned :: %s\n",data);  
          printf("len= %d\n",len);  
          printf("Device Button Pressed!!!!\n");  
      }  
      else  
      {  
          printf("Error in bulk transfer\n");  
          return -1;  
      }  
  
      r = libusb_bulk_transfer(hDevice,0x82,data1,512,&amp;len,0);   
      //read from device buffer to data1  
      //str_rx = data1;  
      //printf("End point address::%d\n",le);  
      //printf("End point desc.type::%d\n",ty);  
      if(r==-1)  
          printf("Error in io\n");  
      if(r==0)  
      {  
          printf("data1 returned::%s\n",data1);   //received string in data1  
          printf("len= %d\n",len);  
          printf("Device Button Pressed!!!!\n");  
      }  
      else  
      {  
          printf("Error in bulk transfer\n");  
          return -1;  
      }  
  
  
      return 0;  
  }  
  </code></pre>