Re: musb gadget HUB traffic sniffing/forwarding

2015-07-03 Thread Alan Stern
On Thu, 2 Jul 2015, Y. Zhang wrote:

> Hi all,
> 
> I'm new to linux usb and would like some guidance on achieving some of
> the following goals.
> I have a beaglebone black (BBB - currently running kernel v3.12) with
> OTG in peripheral mode on usb bus#1 and a host port to connect devices
> on usb bus#2.
> 
> 1. usb bus#1: connect OTG on BBB as a musb gadget (via gadgetfs) to
> another PC host (e.g. linux, windows, etc); usb bus#2: connect a hub
> to BBB host
> + using libusb to control the hub

You cannot use libusb to control a hub.  It won't work.

More precisely, you can _control_ the hub with libusb, but if you do 
then you won't be able to communicate with any devices plugged into the 
hub.

> + relay all traffics from host->musb gadget->libusb->hub->(applicable
> multiple devices hot-plugged to the hub), and vice versa

You can't do this either.  There are all sorts of problems, not least 
of which is that the gadget uses a single USB address but devices 
plugged into the hub will need to use multiple USB addresses.

> So far I'm able to see traffics between the PC host and the hub before

What do you mean?  The PC host is connected to the musb gadget, not to 
the hub.  So how can there be any traffic between the PC and the hub?

> plugging any device into the hub. That is, usb traffics for endpoints
> of the hub itself. Once I plug in a device, after certain actions on
> the hub port, the host will send requests (get_descriptor/set_address)
> to address 0, which are not forwarded to the gadhetfs user space. I'd
> like to know:
> * Are traffics for address 0 visible to musb gadget? What code in
> usb/musb and/or usb/gadget can be used/revised to retrieve/handle
> them?

Traffic for any address other than the gadget's address is not visible 
to the gadget.  This is part of the hardware design; there is nothing 
you can do to change it in software.

> * If it is feasible to accomplish the above, then the PC host would
> enumerate devices plugged into the hub. What code usage/change would
> be necessary to further retrieve messages addressed to endpoints of
> individual devices and relay them to the HUB (so the HUB can broadcast
> to individual devices), and also forward messages from devices
> received via hub (with libusb) back to host via musb gadget?

This is a moot question.

> 2. usb bus#1: connect the BBB OTG to a hub attached to the PC host
>+ using musb gadget if needed: host-hub-OTG-(gadget)
>+ when the host sends any messages to the hub, it would then
> broadcast (at least for usb2.0) to all ports on the hub.
>+ sniff broadcast traffic on the OTG usb port (on bus#1)

A standard USB port (even an OTG port) cannot sniff USB traffic.  Doing 
so requires special hardware -- a USB protocol analyzer such as the 
TotalPhase Beagle-480.

> I don't necessarily need the OTG gadget to respond anything to the hub
> or PC host, but hope to sniff all usb messages broadcast by the hub,
> which means I will be able to see messages sent by the PC host to
> other devices plugged into the hub. What code in usb/musb and/or
> usb/gadget can be used/revised to sniff such traffics? I've tried
> usbmon but it only monitors devices controlled by hcd (on bus#2) not
> the OTG in peripheral mode (on bus#1)

This cannot be done.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: musb gadget HUB traffic sniffing/forwarding

2015-07-03 Thread Krzysztof Opasiak



On 07/03/2015 05:48 AM, Felipe Balbi wrote:

Hi,

On Thu, Jul 02, 2015 at 06:02:50PM -0700, Y. Zhang wrote:

Hi all,

I'm new to linux usb and would like some guidance on achieving some of
the following goals.
I have a beaglebone black (BBB - currently running kernel v3.12) with


you need to ask for support from whoever gave you that v3.12 kernel. If
you're using TI's releases, then you need to get in touch with TI's
official support channels. This forum, can't really help you out unless
you move to v4.1 kernel.


OTG in peripheral mode on usb bus#1 and a host port to connect devices
on usb bus#2.

1. usb bus#1: connect OTG on BBB as a musb gadget (via gadgetfs) to
another PC host (e.g. linux, windows, etc); usb bus#2: connect a hub
to BBB host
+ using libusb to control the hub
+ relay all traffics from host->musb gadget->libusb->hub->(applicable
multiple devices hot-plugged to the hub), and vice versa

So far I'm able to see traffics between the PC host and the hub before
plugging any device into the hub. That is, usb traffics for endpoints
of the hub itself. Once I plug in a device, after certain actions on
the hub port, the host will send requests (get_descriptor/set_address)
to address 0, which are not forwarded to the gadhetfs user space. I'd
like to know:
* Are traffics for address 0 visible to musb gadget? What code in
usb/musb and/or usb/gadget can be used/revised to retrieve/handle
them?
* If it is feasible to accomplish the above, then the PC host would
enumerate devices plugged into the hub. What code usage/change would
be necessary to further retrieve messages addressed to endpoints of
individual devices and relay them to the HUB (so the HUB can broadcast
to individual devices), and also forward messages from devices
received via hub (with libusb) back to host via musb gadget?

2. usb bus#1: connect the BBB OTG to a hub attached to the PC host
+ using musb gadget if needed: host-hub-OTG-(gadget)
+ when the host sends any messages to the hub, it would then
broadcast (at least for usb2.0) to all ports on the hub.
+ sniff broadcast traffic on the OTG usb port (on bus#1)

I don't necessarily need the OTG gadget to respond anything to the hub
or PC host, but hope to sniff all usb messages broadcast by the hub,
which means I will be able to see messages sent by the PC host to
other devices plugged into the hub. What code in usb/musb and/or
usb/gadget can be used/revised to sniff such traffics? I've tried
usbmon but it only monitors devices controlled by hcd (on bus#2) not
the OTG in peripheral mode (on bus#1)


you really want a HW sniffer. Another option is to mess around with
tracepoints and add support for tracing usb_requests and dump out the
necessary data.


I'm not sure if I understand correctly your use case but couldn't you 
use usb-mon and wireshark?


Best regards,
--
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: musb gadget HUB traffic sniffing/forwarding

2015-07-02 Thread Felipe Balbi
Hi,

On Thu, Jul 02, 2015 at 06:02:50PM -0700, Y. Zhang wrote:
> Hi all,
> 
> I'm new to linux usb and would like some guidance on achieving some of
> the following goals.
> I have a beaglebone black (BBB - currently running kernel v3.12) with

you need to ask for support from whoever gave you that v3.12 kernel. If
you're using TI's releases, then you need to get in touch with TI's
official support channels. This forum, can't really help you out unless
you move to v4.1 kernel.

> OTG in peripheral mode on usb bus#1 and a host port to connect devices
> on usb bus#2.
> 
> 1. usb bus#1: connect OTG on BBB as a musb gadget (via gadgetfs) to
> another PC host (e.g. linux, windows, etc); usb bus#2: connect a hub
> to BBB host
> + using libusb to control the hub
> + relay all traffics from host->musb gadget->libusb->hub->(applicable
> multiple devices hot-plugged to the hub), and vice versa
> 
> So far I'm able to see traffics between the PC host and the hub before
> plugging any device into the hub. That is, usb traffics for endpoints
> of the hub itself. Once I plug in a device, after certain actions on
> the hub port, the host will send requests (get_descriptor/set_address)
> to address 0, which are not forwarded to the gadhetfs user space. I'd
> like to know:
> * Are traffics for address 0 visible to musb gadget? What code in
> usb/musb and/or usb/gadget can be used/revised to retrieve/handle
> them?
> * If it is feasible to accomplish the above, then the PC host would
> enumerate devices plugged into the hub. What code usage/change would
> be necessary to further retrieve messages addressed to endpoints of
> individual devices and relay them to the HUB (so the HUB can broadcast
> to individual devices), and also forward messages from devices
> received via hub (with libusb) back to host via musb gadget?
> 
> 2. usb bus#1: connect the BBB OTG to a hub attached to the PC host
>+ using musb gadget if needed: host-hub-OTG-(gadget)
>+ when the host sends any messages to the hub, it would then
> broadcast (at least for usb2.0) to all ports on the hub.
>+ sniff broadcast traffic on the OTG usb port (on bus#1)
> 
> I don't necessarily need the OTG gadget to respond anything to the hub
> or PC host, but hope to sniff all usb messages broadcast by the hub,
> which means I will be able to see messages sent by the PC host to
> other devices plugged into the hub. What code in usb/musb and/or
> usb/gadget can be used/revised to sniff such traffics? I've tried
> usbmon but it only monitors devices controlled by hcd (on bus#2) not
> the OTG in peripheral mode (on bus#1)

you really want a HW sniffer. Another option is to mess around with
tracepoints and add support for tracing usb_requests and dump out the
necessary data.

cheers

-- 
balbi


signature.asc
Description: Digital signature


musb gadget HUB traffic sniffing/forwarding

2015-07-02 Thread Y. Zhang
Hi all,

I'm new to linux usb and would like some guidance on achieving some of
the following goals.
I have a beaglebone black (BBB - currently running kernel v3.12) with
OTG in peripheral mode on usb bus#1 and a host port to connect devices
on usb bus#2.

1. usb bus#1: connect OTG on BBB as a musb gadget (via gadgetfs) to
another PC host (e.g. linux, windows, etc); usb bus#2: connect a hub
to BBB host
+ using libusb to control the hub
+ relay all traffics from host->musb gadget->libusb->hub->(applicable
multiple devices hot-plugged to the hub), and vice versa

So far I'm able to see traffics between the PC host and the hub before
plugging any device into the hub. That is, usb traffics for endpoints
of the hub itself. Once I plug in a device, after certain actions on
the hub port, the host will send requests (get_descriptor/set_address)
to address 0, which are not forwarded to the gadhetfs user space. I'd
like to know:
* Are traffics for address 0 visible to musb gadget? What code in
usb/musb and/or usb/gadget can be used/revised to retrieve/handle
them?
* If it is feasible to accomplish the above, then the PC host would
enumerate devices plugged into the hub. What code usage/change would
be necessary to further retrieve messages addressed to endpoints of
individual devices and relay them to the HUB (so the HUB can broadcast
to individual devices), and also forward messages from devices
received via hub (with libusb) back to host via musb gadget?

2. usb bus#1: connect the BBB OTG to a hub attached to the PC host
   + using musb gadget if needed: host-hub-OTG-(gadget)
   + when the host sends any messages to the hub, it would then
broadcast (at least for usb2.0) to all ports on the hub.
   + sniff broadcast traffic on the OTG usb port (on bus#1)

I don't necessarily need the OTG gadget to respond anything to the hub
or PC host, but hope to sniff all usb messages broadcast by the hub,
which means I will be able to see messages sent by the PC host to
other devices plugged into the hub. What code in usb/musb and/or
usb/gadget can be used/revised to sniff such traffics? I've tried
usbmon but it only monitors devices controlled by hcd (on bus#2) not
the OTG in peripheral mode (on bus#1)

Thanks a lot in advance,
Gordon
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html