Chip: USB On The Go Ethernet Connection

Da raspibo.
Jump to navigation Jump to search

Chip can create a TCP-IP networking connection on USB. (it creates a virtual ethernet on USB, RNDIS protocol). If you run ChipOS (i.e. the pre-installed OS on the v.1 Chip) you do not need to re-compile your kernel or doing hard hacking. It needs just some configuration commands.

When Chip is connected to a host computer by a USB cable (USB-A to the host, USB micro to chip) it normally provides a serial emulation on USB. (Chip is powered from the host, too).

Edit /etc/modules:

#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
#g_serial
g_ether

Add an IP address to the usbnet interface (10.1.1.2 is just an example):

sudo nmcli con add type ethernet con-name usbnet ifname usb0 ip4 10.1.1.2/24 gw4 10.1.1.1
sudo nmcli con mod usbnet ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con up usbnet

Reboot chip.

sudo reboot

If everything is okay, after the boot on the host there will be a new network interface. On my debian laptop the new interface appears like this:

# ip addr
....
27: enx2a661f404b74: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 2a:66:1f:40:4b:74 brd ff:ff:ff:ff:ff:ff

Now on the host add a suitable address to the new interface:

# ip addr add 10.1.1.1/24 dev enx2a661f404b74
# ip link set enx2a661f404b74 up

Chip is now "online" using the virtual ethernet on the USB.

# ping 10.1.1.2
PING 10.1.1.2 (10.1.1.2) 56(84) bytes of data.
64 bytes from 10.1.1.2: icmp_seq=1 ttl=64 time=0.245 ms
64 bytes from 10.1.1.2: icmp_seq=2 ttl=64 time=0.172 ms
...

Now you can use ssh to reach your chip computer.

$ ssh chip@10.1.1.2
chip@10.1.1.2's password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Feb 11 13:51:27 2016 from 10.1.1.1
chip@chip:~$ 

It is convenient to set up NAT and forwarding on the host.

# modprobe iptable_nat
# echo "1" > /proc/sys/net/ipv4/ip_forward

(if the host is connected through eth0)

# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

(if the host is connected through wlan0)

# iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

In this way chip is connected to the world using a wired connection.

When you want switch back to the "terminal emulation mode" on the USB it is sufficient to swap the comments in the file /etc/modules:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
#g_serial
g_ether

Nota Bene: If something goes wrong (the networking connection does not work properly) you have two ways to have a shell access to edit /etc/modules:

  • plug a monitor and a keyboard
  • use a USB uart cable (e.g. Adafruit's console cable)