How to intercept messages between usb device and host controller? - usb

I have to write a usb over ethernet application. Using vhci - (http://sourceforge.net/projects/usb-vhci/?source=typ_redirect) I am able to create a virtual usb device. Now I need to intercept communication between actual device and server and redirect it over ip to the virtual device created on the client. I need help regarding this interception part.

Related

How do I serially send commands (telnet) to device directly hooked up to a network?

I have a device that typically is set up to be communicated with via telnet with a serial device server and the port it is hooked up to.
However now it is connected to a different switch, directly connecting it to the network. Is there a way to serially communicate with the device using just the IP?

Transferring data from STM32F407 to libusb through USB CDC class

I'm working on the project in which I should transfer data from a microcontroller to a PC with the USB protocol. I am working with the STM32F407 microcontroller for transferring data to a PC with the USB Protocol.
I am using libsub for transferring data in Windows 7.
I have written a program with STM32cubeMX and configured the USB device class library. I can transfer data with the CDC virtual COM port, but I want to transfer data with libusb. I install the libusb driver for my device, but when I send data from the microcontroller to PC nothing is send!!!!
What is my problem? How can I send data from a USB device to a PC with USB and high speed?
Enter image description here
In USB protocol the host device initiates any transfer, for example a bulk transfer. i assume that the ST32f407 is the device and the pc ist the host so the ST32 can not initiate any USB transfer. The communication over virtual COM works because it the virtual COM is like a tunnel, but this tunnel was also initated and is (logically) kept alive by the host (pc)
Bulk transactions
Like all other USB transfers, the host always initiates a bulk
transfer. The communication takes place between the host and the
target endpoint. The USB protocol does not enforce any format on the
data sent in a bulk transaction.
source: https://msdn.microsoft.com/de-de/library/windows/hardware/ff539199%28v=vs.85%29.aspx
All data transfers are initiated and controlled by the host and USB
peripherals are slaves responding to host commands
source: https://www.midi.org/articles/basic-of-usb
in usb even interrupts have to wait until the host polls:
Any one who has had experience of interrupt requests on
microcontrollers will know that interrupts are device generated.
However under USB if a device requires the attention of the host, it must wait until the host polls it before it can report that it needs
urgent attention!
source: http://www.beyondlogic.org/usbnutshell/usb4.shtml#Interrupt
See http://www.beyondlogic.org/usbnutshell/usb4.shtml#Bulk for bulk transfers
So you can send data from the device to the host but the host has to establish the communication meaning has 'ask' for the data. This is done via the bulk IN endpoint that is used to read data from the device to the host

What is the best way to send data to PC from "MCU + Wifi Module"?

I don't know anything about wireless protocols. With this quick setup i want to get inside. I just want to write a windows desktop application which receives only a couple of bytes of data from a mcu+wifi module "NodeMCU" which is connected to the same router. I can write a simple desktop app with visual studio. But sending data over ip has many methods as far as i read.
What is the simplest way to achieve? (I'm experienced in STM32 mcu's and electronics except internet protocols.)
You can send the data from the embedded board (with the mcu) to a TTL-To-WiFi module. Then from your PC application you should open a socket and connect to the module IP to listen in the correct port the data from your board.. There are a lot of module in the market used as "bridge" or converter: you have only to setup in it the local IP address, the destination IP (your PC) and the TCP port where you want to send data. From point of view of the board you use a standard USART and the message is sent to the destination IP. In your PC application you should be able to create a socket and connect it to the wi-fi module.

How usb OTG works(master/slave)

A device has USB OTG support. Following are scenarios:
When a device is connected to a PC, the device acts as slave. (How does the device know it has to act as slave?)
When a device is connected to a printer, the device acts as master.
(How does the device know it has to act as master?)
What are the steps executed when a device is connected to OTG?
How to implement this mechanism (in brief)?
The exact behavior of USB OTG devices is described in the specification you can find at usb.org. There is a PDF inside the zip called USB_OTG.
The Host Negotiation Protocol in section 6 covers how two OTG devices decide which one is getting the embedded host. Basically this is archived by driving pull-up and pull-down resistors on the D+ line.
Note: When talking about USB the terms master/slave are not used. The master is called host and powers the bus whereas the slave is called device. In the case of OTG (in general, see specification for exceptions) both parts have the capability to be host or device. When the host was figured out by the Host Negotiation Protocol, this part becomes the so called embedded host.
In the two scenarios you mentioned the USB device is able to know whether to be a host or device by the cable. USB cables (non type-C) are not symmetrical. One side is host and the other is device. There is a pin on the connector called the ID pin which is floated on the device side and grounded on the host side. This allows the USB controller on each side to know which side of the cable it is connected to and thus which role (host or device) it should be when connected. These types of devices are called dual-role devices.
If you have a such a device, then you can plug it into a regular host (like your laptop) and it will act as a device. And you can plug it into a regular device (like a printer) and it will act as a host. This is all based on the cable.
If you plug two dual-role OTG devices to each other. Their initial roles are determined by the cable in the same way.
After the initial roles are determined, they can then swap roles from their initial cable-determined roles via the Host-Negotiation Protocol (HNP).
As far as implementing this. There is no brief way to explain it. Every controller is different and you would have to read the controller databook and programming model to implement all these procedures. As well as having a good understanding of the USB and OTG specs themselves.
A good place to start is http://usb.org where you can find all the specs.

Would WCF client work over USB in compact framework?

Would WCF work through normal USB connection or does it require WIFI when using the Mobile Device as a WCF client to a WCF service running on the PC?
Thanks
Did you mean over usb via activesync, or just over USB in general?
I have consumed RESTFul WCF services on WM6 devices over usb/activesync. The activesync connection gives you a network connection that supports TCP. Use the host name 'ppp_peer' if you want to address the host pc you are connected to.
I use ActiveSync and resolve the hostname "dtpt_peer" which maps to 169.254.2.2, the IP assigned by the CF device to the desktop peer, and then use WCF via TCP.
I would think that it wouldn't work over the USB connection because the USB is not a network connection. Unless you are referring to some kind of USB ethernet adapter, and not a USB cable plugged directly from your mobile to your computer, then you are most likely out of luck in this regard.