How to use USB device networking

From RidgeRun Developer Connection

(Difference between revisions)
Jump to:navigation, search
m (Load USB Ethernet network gadget driver)
m
Line 62: Line 62:
</pre>
</pre>
 +
== Connect device to host PC ==
 +
 +
Before connecting the target device to the host PC, watch the syslog, by running the following command on the host PC:
 +
 +
<pre>
 +
sudo tail -f /var/log/messages
 +
</pre>
 +
 +
Connect the USB cable between the target device and the host PC.  The messages file on the host PC should indicate the new USB device was detected.
 +
 +
<pre>
 +
Jun  6 10:15:29 contra-lx kernel: [1638241.377831] usb 1-4.4.2: new high speed USB device using ehci_hcd and address 47
 +
Jun  6 10:15:29 contra-lx kernel: [1638241.510787] cdc_subset: probe of 1-4.4.2:1.0 failed with error -22
 +
Jun  6 10:15:29 contra-lx kernel: [1638241.513437] cdc_subset 1-4.4.2:1.1: usb0: register 'cdc_subset' at usb-0000:00:02.1-4.4.2, Linux Device, 82:13:56:20:b4:cb
 +
Jun  6 10:15:29 contra-lx kernel: [1638241.513490] usbcore: registered new interface driver cdc_subset
 +
Jun  6 10:15:29 contra-lx kernel: [1638241.533442] cdc_ether: probe of 1-4.4.2:1.0 failed with error -16
 +
Jun  6 10:15:29 contra-lx kernel: [1638241.533619] usbcore: registered new interface driver cdc_ether
 +
</pre>
 +
 +
On the host you can verify the new <tt>usb0</tt> interface exists by running:
 +
 +
<pre>
 +
ifconfig usb0
 +
</pre>
 +
 +
with the output being similar to:
 +
 +
<pre>
 +
usb0      Link encap:Ethernet  HWaddr 82:13:56:20:b4:cb 
 +
          inet6 addr: fe80::8013:56ff:fe20:b4cb/64 Scope:Link
 +
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 +
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:1000
 +
          RX bytes:0 (0.0 B)  TX bytes:78 (78.0 B)
 +
</pre>
 +
 +
When you connect the cable, in the target device console, you should see:
 +
 +
<pre>
 +
g_ether gadget: high speed config #1: CDC Ethernet (ECM)
 +
</pre>
 +
 +
== Assigning IP addresses ==
 +
 +
For this simple example, fixed IP addresses are assigned to the both the host PC USB network interface and the target device USB network interface.
 +
 +
On the host
 +
 +
<pre>
 +
HOST_USB_IP=10.0.1.1
 +
sudo ifconfig usb0 $HOST_USB_IP netmask 255.255.255.0
 +
route
 +
</pre>
 +
 +
On the target device
 +
 +
<pre>
 +
TARGET_USB_IP=10.0.1.2
 +
ifconfig usb0 $TARGET_USB_IP netmask 255.255.255.0
 +
route
 +
</pre>
 +
 +
with the route showing the default gateway is
 +
 +
==
[[Category:HowTo]] [[Category:USB]]
[[Category:HowTo]] [[Category:USB]]

Revision as of 16:28, 6 June 2011

The Linux USB gadget sub-system supports USB device functionality, including USB networking.

Contents

Configure hardware for USB OTG or USB device support

Depending on your hardware, you can use either USB OTG or USB device to enable support for USB networking.

Build USB Ethernet network gadget driver

The USB Ethernet network gadget driver caused the device to appear to be a USB network dongle when connected to a host computer. Generally it is best to build USB gadget drivers as modules instead of building them into the kernel so you can unload one and load another.

Symbol: USB_ETH [=m]
   Prompt: Ethernet Gadget (with CDC Ethernet support)
     Defined at drivers/usb/gadget/Kconfig:628
     Depends on: <choice> && NET
     Location:
       -> Kernel configuration
         -> Device Drivers
           -> USB support (USB_SUPPORT [=y])
             -> USB Gadget Support (USB_GADGET [=y])
               -> USB Gadget Drivers (<choice> [=m])

Build and install the kernel to the target hardware.

Load USB Ethernet network gadget driver

After booting the target hardware to a shell prompt, run:

modprobe g_ether

and you should see output similar to:

g_ether gadget: using random self ethernet address
g_ether gadget: using random host ethernet address
usb0: MAC be:b5:85:ef:48:33
usb0: HOST MAC 1a:b2:c3:43:8a:6e
g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
g_ether gadget: g_ether ready

You can then verify the usb0 network interface exists:

ifconfig usb0

with output similar to:

usb0      Link encap:Ethernet  HWaddr BE:B5:85:EF:48:33  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Connect device to host PC

Before connecting the target device to the host PC, watch the syslog, by running the following command on the host PC:

sudo tail -f /var/log/messages

Connect the USB cable between the target device and the host PC. The messages file on the host PC should indicate the new USB device was detected.

Jun  6 10:15:29 contra-lx kernel: [1638241.377831] usb 1-4.4.2: new high speed USB device using ehci_hcd and address 47
Jun  6 10:15:29 contra-lx kernel: [1638241.510787] cdc_subset: probe of 1-4.4.2:1.0 failed with error -22
Jun  6 10:15:29 contra-lx kernel: [1638241.513437] cdc_subset 1-4.4.2:1.1: usb0: register 'cdc_subset' at usb-0000:00:02.1-4.4.2, Linux Device, 82:13:56:20:b4:cb
Jun  6 10:15:29 contra-lx kernel: [1638241.513490] usbcore: registered new interface driver cdc_subset
Jun  6 10:15:29 contra-lx kernel: [1638241.533442] cdc_ether: probe of 1-4.4.2:1.0 failed with error -16
Jun  6 10:15:29 contra-lx kernel: [1638241.533619] usbcore: registered new interface driver cdc_ether

On the host you can verify the new usb0 interface exists by running:

ifconfig usb0

with the output being similar to:

usb0      Link encap:Ethernet  HWaddr 82:13:56:20:b4:cb  
          inet6 addr: fe80::8013:56ff:fe20:b4cb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:78 (78.0 B)

When you connect the cable, in the target device console, you should see:

g_ether gadget: high speed config #1: CDC Ethernet (ECM)

Assigning IP addresses

For this simple example, fixed IP addresses are assigned to the both the host PC USB network interface and the target device USB network interface.

On the host

HOST_USB_IP=10.0.1.1
sudo ifconfig usb0 $HOST_USB_IP netmask 255.255.255.0
route

On the target device

TARGET_USB_IP=10.0.1.2
ifconfig usb0 $TARGET_USB_IP netmask 255.255.255.0
route

with the route showing the default gateway is

==

Navigation
Toolbox