USB Linux Device Driver - linux-kernel

I'm trying to learn Unix kernel development and I'm asked to "play around with the usb driver code and learn things".
where should I start?
Thanks in advance!

First go through basics of USB
Try to understand USB document from free electronic website
After that go to Linux kernel document
Continuously try to go through Linux kernel codes in USB module and corelate with document contains.
If any board is available then try to put debugs in kernel code, dump to board and observe the code flow for different USB devices.

I think you should start with learning USB protocol first and then analysing usb linux drivers. Read the usb specifications from www.usb.org.

Related

Writing a UMDF virtual device driver (or software device) like Virtual DVD

I have an "off the shelf" commercial software using an ANT USB dongle to communicate with a cycling trainer.
My trainer is not compatible with the software because the protocol is slightly different (not a lot).
My goal is to write a protocol translator. The only thing I can think of is to write a UMDF virtual device driver (like Magic ISO Virtual DVD) looking like an ANT USB Device in the device manager (same PID\VID) while connecting itself to the physical ANT device. The virtual device driver will perform the protocol translation.
I looked at several examples from Microsoft here https://github.com/Microsoft/Windows-driver-samples but I was unable to find anything relevant. I thought this example would be a good start https://github.com/Microsoft/Windows-driver-samples-master/Sensors/CustomSensors but it is impossible to load the driver using the given procedure from the inf file.
BTW I am familiar with the content of INF files and the basics of KMDF & UMDF device drivers programming. My problem is to write something that will load in the device manager and present itself as a real USB device even if it is not enumerated by the USB bus subsystem.
Can anybody with driver development experience point me to some relevant code sample or documentation?
Best regards !
I am currently developing a UMDF CCID (smartcard reader) driver. This project helped me at the beginning because it compiles out of the box and creates virtual device nodes (smartcard readers) visible in the device manager.

How to program midi-driver software?

I am creating my own midi-instrument and would like to know how to create a PC driver program for this instrument. Does anyone have any pointers or resources I could look at to help me complete this task?
All i have found so far is
1) https://msdn.microsoft.com/en-us/library/windows/hardware/mt187811(v=vs.85).aspx --> USB drivers
Just make your device conform to the USB MIDI device class specification, and you do not need to write any driver for the PC.
Check out the Driver samples for Windows 10. The Sample KMDF Function Driver for OSR USB-FX2 might be closer to what you need, if you want to write a USB device driver.

Is it possible to override a driver that has been compiled into the kernel?

I have a USB device for which I have an API. This API only works if the USB device doesn't use the ftdi_sio/usbserial drivers.
On my laptop, if I plug the USB device in, these drivers get loaded (as modules) and I have to unload them using modprobe -r after which code using the API can see the device.
I have another device which experiences the same issue although no modules are loaded so I'm guessing these drivers are compiled into the kernel. My question is this - is there any way to stop this device from using these drivers or do I have to recompile the kernel, etc?
Thanks for any help!
You are essentially looking for a way to :
unbind the default driver from your USB device
and
bind a driver of your choice to it.
Take a quick look at this to get you started.
A slightly more detailed description of the same is available in this excellent LWN article of (un)binding device drivers.

How to start learn linux device driver development?(worked on windows only)

I want to learn Linux device driver development.
Positives:
I have developed small drivers on WinCE and worked on SPI, i2c interface from application i.e. opening, reading and writing driver.
I'm good in operating system and data structures.
Negatives:
I have never worked on Linux.
My background is not embedded system.
How should I proceed to learn Linux device driver development?
EDIT: any book reference would be appreciable thanks
Linux Device Drivers, Third Edition : http://lwn.net/Kernel/LDD3/ should help you along.
THE FOLLOWING LINKS WILL HELP TO START LEARNING DEVICE DRIVERS
http://www.freesoftwaremagazine.com/articles/drivers_linux
http://lwn.net/Articles/driver-porting/

Custom USB Driver for Windows? Mac?

I'd like to modify a USB driver to send and receive USB data over a network.
Take for example, an iMac and a PC. I have an iPod plugged in to my PC (in NY). I want my iMac (in LA) to recognize the iPod as plugged in to a local USB port and be able to communicate with the iPod.
Forget my qualifications, or lack thereof (I have background in web, iOS apps, I've toyed with Java and C).
Where can I get source code for a USB driver for Windows that I can modify? Mac OS?
Any tips or pointers towards accomplishing my goal would be appreciated as well.
It looks like folks are coming up with something close to what you want. If you do decide to roll your own, the USB driver source you asked for is libusb.
On the Mac OS X end, drivers are built up in a stack. What you want to do should be relatively simple (nothing is really simple in kernel land). You need to create a driver that can communicate over ethernet with the PC and looks like a USB device to the driver matching software. Then everything else will happen automatically.
The source code is available for Apple's USB stack. You should also read about the IOKit API and IOKit device driver guidelines and IOKit fundamentals.
Oh yes and you say you have toyed with Java and C. To write device drivers on OS X, you'll need to learn some C++.
I suggest you to go see USBIP project. This is available on Linux and Windows, but not clear for MAC. If you can get a VHCI-Controller driver installed for MAC, we can kick start USBIP for MAC.
Sounds quite like this product, a bit unsure if theirs works over wide-area networks though.
I have a general idea of how I'd go about it, but not any specifics. Basically, I'd use the platform's driver development kit to write a USB device emulator on the client machine. I'd then add a virtual device to that system called "Networked USB Host", or something similar that maintains an open port to listen for communication from the server and passes it on to your virtual USB device. IIRC, the Windows DDK comes with a USB simulation framework that might be able to help you with this.
On the server, you'd have to hook into the USB subsystem to send raw USB packets to the client machine. libpcap and wireshark have USB capturing facilities for that, but I'm not sure if this works with winpcap and the Windows version of wireshark as well.
EDIT: Look at this for cross-platform USB capture alternatives.
You can buy OSR USB learning kit: https://www.osronline.com/custom.cfm?name=index_fullframeset.cfm&pageURL=https://www.osronline.com/store/index.cfm
This is actually small USB device with known interface. Windows Driver Kit (WDK) contains sample KMDF driver for this device: http://www.microsoft.com/whdc/driver/wdk/
This is good starting point to learn Windows Drivers development, and USB drivers development specifically. However, it is still far away from your problem solution.
Can't you use some sort of Remote Desktop?

Resources