I'm writing a usb device driver for a data acquisition device in Ubuntu 16.04.
The data acquisition device is currently working in Windows and the manufacturer only provides the driver for Windows and I need it to be working in Linux.
So, to do the reverse engineering, I captured the data with Wireshark in Windows.
I figured out all the setup urbs and I can send data to the data acquisition device and works well but the problem is to receive the data.
It seems that there are continuous(periodic) data coming from endpoints 1 and 3(which are the bulk in endpoints). In Windows, there doesn't seem to be any request packet going to the usb device to receive the data from endpoints 1 and 3 but in Linux, the data is received only when I send some kind of request(for example, read file operation).
I've found that there is something called "Continuous Reader" in Windows, but I can't find any hint in Linux for reading continuous data from usb device.
https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/how-to-use-the-continous-reader-for-getting-data-from-a-usb-endpoint--umdf-
I would really appreciate your help, Thank you!
Are you sure the device doesn't have an intr-IN endpoint to announce availability of data, which is then fetched using bulk IN transfers? How does it configure EP2, which I assume is interrupt? If you use something like libusb you may need to set up an interrupt poller based on the intr-EP description.
Related
I am doing some research on the WebUSB API for our company because we are going to start to manufacture devices in house.
Our current device manufacture comes with an application so the team can plug the device into a computer and diagnose it. Their application allows us to read outputs from the device, as well as pushing commands/configuration to the device over a wired connection.
Since this device is 100% ours, we are also responsible for building out the diagnostic tooling. We need some sort of interface that allows a user to read outputs and send commands/configuration to the device over a wired USB connection.
Is the webUSB the correct API? If not, what are some suggestions for accomplishing the requirement? Are we limited to building some sort of desktop or mobile application?
I would recommend resources below to read to help you understand if the WebUSB API fits your needs or not:
https://web.dev/devices-introduction/ helps you pick the appropriate API to communicate with a hardware device of your choice.
https://web.dev/build-for-webusb/ explains how to build a device to take full advantage of the WebUSB API.
From what you describe, WebUSB isn't strictly required but won't hurt either.
First and foremost, you will need to implement the USB interfaces reading data and sending configurations. It will be a custom protocol, and not one of the standard USB device classes such as HID, video or mass storage. The details of the protocol and if you use control, interrupt or bulk transfers is your choice.
I'm assuming you will connect the devices to Windows PCs, and you likely don't want to put money into writing device drivers. If so, the easiest approach is to add the required descriptors and control requests required for Microsoft OS 2.0 Descriptors. That way, the WinUSB driver will be installed automatically when the device is plugged in.
Using the WinUSB API, a Windows application will then be able to communicate with the USB device. No additional drivers are needed. (On macOS and Linux it's even easier as you don't need the Microsoft OS 2.0 Descriptors in the first place.)
On top of that you can implement the additional descriptors and control requests for WebUSB. It will provide the additional benefit that you can write a web application (instead of a native application) for communicating with the USB device. (Currently, you are restricted to the Chrome browser.) WebUSB devices should implement the WinUSB descriptors as the alternative (.INF files, manual installation process) is a pain.
The already mentioned web page https://web.dev/build-for-webusb/ is a complete example of how to implement it.
I have this configuration of the devices HOST_PS <----> Transmitter<---- Touchscreen.
Currently on my transmitter I have created a composite USB gadget device which could contain up to 5 HID devices, (2Mouse, 2Keyboard, Touchscreen). HOST PC could enumerate all of them and everything is working properly. From transmitter side I am writing HID report data comeing from the touchscreen to the corresponding /dev/hidg device and Host PC acts correctly. The problem occurred when
I have bought a new usb_touchscreen.
Extracted the report descriptor from that touchscreen.
Pass the report descriptor and all the corresponding data(dev, no_out_endpoint, protocol, report_desc, report_length, subclass) to /sys/kernel/config/usb_gadget/Nhid/functions/hid.usb0/.
After all this steps the HOST_PC could enumerate the touchscreen properly but the tocushes doesn't work(I also know why).
HOST_PC printing this message hid-multitouch xxx:yyy:zzz.uuu: failed to fetch feature 7.
Some touchscreens using Feature reports for allowing the HOST to have configurable device. If I connect the Touchscreen directly to the PC I can see the following under the hood. I'll describe the final steps before sending the input reports from the touchscreen.
pc -> touchscreen (GetDescriptor(Report))
pc -> touchscreen (GetReport(Feature eport))
touchscreen ->pc (Input Report)This is already HID report that sends the touchscreen
The problem hid-multitouch xxx:yyy:zzz.uuu: failed to fetch feature 7 is though I am setting the report descriptor to USB_GADGET's HID device and HOST_PS enumerates it properly, I am not sending the feature report to the host as it requested in step 2 above.
QUESTION:
How to send feature report from device to HOST_PC, if the device is USB_GADGET composite HID device. In usual for sending the Input report (HID data) I am writing the incoming data from the touchscreen to the corresponding /dev/hidg<N> device.
NOTES:
The HOST_PC is Linux(Ubuntu, CentOS,... doesn't metter) and I ma not interested on Windows.
The Touchscreen works perfectly if I connect it to the PC directly.
I don't want to modify the touchscreen's report descriptor, remove feature report part and solve the problem like that.
PS:
I know this is a little bit complicated but Thanks in advance.
In case someone would have this kind of problem in future.
This is not a bug in Linux USB_GADGET driver but I would honestly say that it is a missing feature which is not implemented. This is a link to the place where the implementation wasn't done
https://github.com/torvalds/linux/blob/master/drivers/usb/gadget/function/f_hid.c#L652.
If someone wants to send feature_report(s) from device to HOST, than you probably will need to implement it in driver.
This is my modification to USB_GADGET driver that will allow to send feature reports to the HOST.
https://github.com/torvalds/linux/compare/master...AydinyanNarek:patch-1
PS. I don't have enough time to create pull request and other staff for applying this patch to the kernel. If someone would be interested on this than you can take this patch that I have created, polish the code and apply for a patch.
I'm currently in a situation that my SoC will be connected via its I2C bus through a I2C-to-UART converter MAX3107 to the UART port of a microprocessor.
Although the communication between the two shouldn't be an issue, the part were the Soc should update the firmware of the microprocessor has to be done with the Y-Modem file transfer protocol.
Although a question is pending at the manufacturer, I still wanted to check here:
Would this even be possible
The SoC runs Linux, is this depending on the MAX3107 driver
Does this concern the I2C bus or is only the UART driver and bus interesting.
https://datasheets.maximintegrated.com/en/ds/MAX3107.pdf
I used the SC16IS750 instead with the Linux kernel driver.
Sending a file via Y-Modem doesn't seem to be a problem. I tried both Minicom and TeraTerm to send a file and it works. The receiver responds is just 1 character each time before sending a part of the file. If the responds would have been more than 64-byte at a time (instead of the one character) this would have been a problem, because the FIFO first needs to be read and cleared before another sting can be received.
I have developed a kernel driver for a USB device. Such a device has some pins that can provide functionality both as CDC ACM serial port or as input buttons. So to implement that I had to use two different USB configuration descriptors.
The driver works as expected, but I have to hardcode the chosen setup before compiling and loading the firmware to the micro-controller. I am searching a mechanism to change that device configuration from userspace.
I read about a SET_CONFIGURATION message on USB documentation, but coudn't find any Linux tool to send such kind of standard USB messages from userspace to the USB bus.
Does some of you (with more experience on this topic) know some userspace Linux tool to send a SET_CONFIGURATION message to a device connected to the USB bus?
Thanks in advance! :)
The function libusb_set_configuration() in LibUSB could do that in theory, but there is no need.
One can simply put both HID (for the button) and CDC (serial port) into one configuration using an "Interface association descriptor" (IAD).
This github repo resolves my issue:
https://github.com/avtolstoy/usbtool
No need for any special tools. You can simply do it via sysfs:
Find your device cd /sys/bus/usb/devices/X-Y/ where X is the bus number and Y is the device number.
Edit bConfigurationValue e.g., using sudoedit
Set the file contents to the desired configuration number and save it
That’s it!
I have to simulate a USB Device for automation and testing purposes (in Linux). Original driver/application for this device uses “libusb” to communicate with it.
I don’t have much experience in Linux and Simulation, after some searching I have understood that I need to write a kernel level driver and an application in user-space to simulate that device. Is this right? If Yes, How can this be done?
Thanks in Advance.
Finally implemented it by modifying "libusb", modified it to send and receive usb transfers from message queue instead of usbfs. Programmed my simulator to create libsub type transfers and send/receive them using message queues as well.
Simulator now interprets the incoming transfers and sends it to a command parser, which sends request/message to automation system using sockets in a specific format. Automation system sends it's instruction by sending to command parser using socket. This socket invokes method specific to each request in simulator, Now simulator forms an appropriate transfer structure and passes to device plugin (via libusb) through message queue.
I think what you're looking for would be called a virtual USB device. Currently there is nothing in standard Kernel.Some virtual machine provides USB emulation.e.g. KVM provides USB emulation. There is framework gadget in which might look for your solution.
Or find something in Linux USB project
Thanks,
Abhijeet
The usb-vhci project could be of use if you want the device to be presented to the kernel in the same way as real hardware.