How to communicate with the USB Host from a Linux USB Client - linux-kernel

The host part will be a PC program made from c# in which I will use LibUSBdotnet to do the communication.
My problem is how do I make the Linux side pickup and respond. I don't really know where to start.
Whenever I try to search for it, all result show are "how linux communicates with a device attached to it".
Or it does not matter if a device is host or client, because they utilize the same pipes/bus?
Can I use something in "/dev/usb***"?
I have seen "libusb" which I believe is the linux cousin of libusbdotnet.
Can I somehow use this library? If anyone can show me the right direction, I would really appreciate it.

AFAIK libusb is the library for usb-host side, not for usb-device side. So you cannot use it in your case. I suggest the same as myninjaname said - to analyse one of the Linux usb gadget drivers as a start point.

Related

Is there any kind of udev equivalent on Windows?

I'm looking for a way to ensure that a USB device plugged into a Windows 7 machine will be mounted in a reliable, repeatable way.
I don't have that much Windows experience, but I wondered if there was a way to make the equivalent of a udev rule in Linux to match certain parameters to identify the device and then mount it on a specific COM port.
Any advice would be gratefully received.
Sarcastic answer:
I've looked for C:\Windows\etc\udev.d but there's no such directory
;)
Less sarcastic answer:
As far as I know, the only way to configure devices in windows is via the device management UI which can be started with mmc devmgmt.msc
This is obviously not even similar or even close to udev, there is no possibility to do this without the GUI.

USB linux gadget zero driver communicate with Windows host

I need to set up USB communication between a Windows 7 host and a Linux device for data transfer. I was able to compile the Linux kernel on the device to include the Gadget Zero driver in the kernel (not as a loadable module - Linux version 3.0.15). My project has some requirements, which also explains why I chose Gadget Zero:
1) On the Windows 7 host, a kernel mode driver must be used to communicate over the USB connection for sending and receiving bulk data. (speed is not important, not a lot of data at once).
2) On the linux device, no requirements on USB side except send and receive data easily over USB link. The data received will eventually be "unmarshalled" to call functions in another kernel module (and those responses packaged and sent back to the host).
3) Multiple linux devices will be connected to the host, so need easy way to enumerate connected devices and communicate with them.
So due to the requirements, I decided against the Gadget Serial. I'm having serious issues sending and receiving data over the virtual COM port in kernel mode (KMDF) in Win 7 host. WinUSB does not seem to want to open my attached device (I'm using KMDF windows USB driver from template in VS2012) Also, the gadget serial driver on the linux side, I cannot find the functions where the data is received and sent. Plus, any received data on the linux device seems to be echoed back to the host for some reason. (and to test this, I wrote a simple user-mode app in Windows, which is a no-no for my project).
Gadget Zero, it appears much simpler on the linux side. I can plug the USB cable to the Win7 host, and I can get the device to appear in the device manager. However, again I am having problems with getting communication going over the link. Gadget Zero has 2 bulk endpoints, so this shouldn't be an issue. Surely, someone has made data communication possible between a Windows host and a linux device using Gadget Zero? With Gadget Zero, it should be easy to enumerate the connected linux devices and communicate with them.
The trick is to keep the Windows side communication in kernel mode. Can someone point me in the right direction perhaps with Gadget Zero, Windows 7 KMDF, and some sample source code? I have a hard time believing no one has done this before because my internet searches don't turn up much. (and mostly user-mode solutions with Gadget Serial).
Thanks!
So you're writing a Win32 driver in which you want to communicate with your linuxed usb? I haven't written much win32 kernel code, but I believe I've seen a huge section in the doc, saying something like "This is how you make usb drivers"... That'd be it. In other words, when in kernel mode you have access to the full kernel usb layer. You don't need an existing driver or whatnot.
On the linux side you can use the serial gadget, in a different run mode. Only the default run mode, registers it self as VCP. There exist a more basic mode:
modprobe g_serial use_acm=0
Give it your own vendor id and you'll be able to attach your very own custom win32 driver. The 'multiple linux devices' will be handled by Windows. (Multiple instances of your driver, will be initiated.)
The echo you're seeing btw, is most likely a terminal feature. (The terminal mode on uarts will echo.) You have to disable it, when connecting. And now that you're at it, you also have to disable the xon/xoff, esc chars etc. (Standard legacy rubbish.)
And another thing. I'm not sure the gadget zero actually sends the data onto the line. It's meant for testing the gadget framework. (I could be mistaken though.)
Anyway, you've prolly solved this issue years ago. I'd be nice to know what you came up with.

Windows Phone 7 programming the use of the USB port

I would like to make a Windows Phone 7 application that takes advantage of it's USB port to communicate with the PC. I would like to write an application to control or push information/data to the PC from the application. But I am having problems finding information on where to start. Can anyone help point me in the right direction with some resources?
The only way to communicate over the USB connection is over HTTP.
To get this to work you'll need:
- a webservice hosted on the PC you're connecting to.
- a way for the app (on the phone) to know the hostname of the PC. (You'll probably need to enter it manually)
When you have these it should be straight forward.
You can't.
If you want to make sure to push data to a client PC, you will have to use a kind of synchronization by using the internet. For example create a wp7 application and a desktop application and let them sync the data based on a user object or anything like that.
As far as I know also the updated SDK for Mango will not support programming against the USB dataconnection.

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?

Talking to a motor driver through a CAN-BUS

I have a motor, connected to a motor
driver, connected a windows XP
computer by a CAN-BUS (through USB I believe).
I want to "talk" to the motor driver
and have some questions:
Does the USB appear as a COM port?
What protocol do I
use or how do I find out what
protocol to use? Or how do I talk to it?
Does anyone
have or know of any public
implementations of a similar
thing that I can look at?
Are there any other hints you want to share?
Thanks!
Yes, the USB device will probably appear as a COM port. Just open the hardware manager window in Windows, plug in your USB device and see if it creates a new COM port.
The CAN protocol of course! You have to order it from CAN-CIA but I believe it's free: http://www.can-cia.org/index.php (click on the download section)
Not that I know of.
I'd suggest downloading the relevant specs and start reading. It looks like there's lots of reading to be done.

Resources