From: Alan S. <st...@ro...> - 2014-03-01 15:49:45
|
On Fri, 28 Feb 2014, rounaksingh wrote: > hi guys, > I have been working on an application to make a FAT filesystem manager > (hobby project) for USB flash drives. So I am implementing libusb as USB > operation layer. In addition, I searched for the Endpoint for IN and OUT for > USB flash drive in linux by using cmd "lsusb -v". It is showing me > configration ID as 1, Interface 0, OUT Endpoint 0x02 and IN Endpoint 0x81. > *Output of lsusb-v -d 0x0781:0x5151* > > > Therefore I wrote the program, the device opens, detach_kernel on interface > zero, set configuration 1, claim interface 0, Do you understand that this sequence makes no sense? Set-configuration will attach kernel drivers to all the interfaces, including the one you just detached. You should do the detach-kernel-driver _after_ the set-configuration, or even skip the set-configuration entirely. > then send Request Sense cmd > (SCSI command) using bulk transfer by Endpoint 0x02; everything is fine till > here. Do you understand that sending REQUEST SENSE as your first command is meaningless? REQUEST SENSE returns the status information from the _preceding_ command. Your first command should be INQUIRY (and the transfer size should be 36). Your second command should be TEST UNIT READY. If that command returns an error, then you should send REQUEST SENSE. > *Code: for init and deinit and send_data* Your code did not get included in the email message. > Although when I try to receive by bulk transfer(Endpoint 0x81) the cmd > response, the libusb_bulk_transfer produces an error -9 Pipe halt. Then I > read the manual for libusb, which says to clear the pipe halt use > libusb_clear_halt on the desired endpoint. But its no working. > > *OUTPUT* Your output didn't get included either. How do you know that libusb_clear_halt didn't work? > The number 0 and -9 are return values of the functions libusb_clear_halt and > libusb_bulk_transfer, and Send Complete 32 32 is the length of data sent and > actually sent. The code has been attached above. No, it hasn't. > The USB flash drive is working fine with the operating system. I do not > understand what's wrong. Also, I wasted a whole day on this problem, because > first I thought, I am sending the wrong SCSI commands, so the device is not > responding. However, I am pretty sure now that the problem with the my > libusb's function calls. > > Please tell me what's wrong I am unable to detect the error. It's kind of hard to say with so little information. However, you can get a better idea of what's going on by doing echo Y >/sys/module/usbcore/parameters/usbfs_snoop before running your program. This will cause the requests sent by libusb to be listed in the kernel log (use the dmesg command to read them). You can also use usbmon to get a trace of the actual USB transfers (see Documentation/usb/usbmon.txt in the kernel source for instructions). Alan Stern |