Ethernet over USB

From Qi-Hardware
Revision as of 09:54, 27 November 2011 by Jon Phillips (Talk | contribs)
Jump to: navigation, search

Contents

The recently uboot/kernel images have Ethernet-over-USB support enabled by default, which you can use to give the NanoNote a connection to the internet.

Setup on the host

To let your NanoNote use your laptops/PCs (host) internet connection, you have to enable NAT and routing on your host and set a default route on your NanoNote via your host.

The NanoNote's IP address is set to 192.168.254.101 by default.

Note - if you use Ubuntu, consider removing the default connection-manager, and replacing it with wicd. The connection manager has issues with adding & removing networking hardware, while wicd ignores usb0.

Network config

On your linux/unix host run:

$ ifconfig usb0 192.168.254.100

to give your host an IP address which is in the same subnet as your NanoNote.

To review that, you can use ifconfig as well

$ ifconfig usb0

and should get the following

usb0      Link encap:Ethernet  HWaddr 16:90:89:ea:82:6f  
          inet addr:192.168.254.100  Bcast:192.168.3.255  Mask:255.255.255.0
          inet6 addr: fe80::1490:89ff:feea:826f/64 Scope:Link
          UP BROADCAST RUNNING 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)

To verify the proper connection, you can try to ping your NanoNote from your host and vice versa (note: NanoNote has the 101 in the end).

$ ping 192.168.254.101 # pinging your NanoNote from your host


Now we have successfully established a network connection between host and NanoNote.

To let your NanoNote use your hosts internet connection, we have to enable routing and NATting on the hosts side:

NAT config

NOTE: Replace eth0 below with the interface your host is connected to on the Internet.


# modprobe iptable_nat
# echo "1" > /proc/sys/net/ipv4/ip_forward
# eth0 in this example is the interface on your host connected to the internet, adjust if needed
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Setup on the NanoNote

Network config

NO NEEDS after OpenWrt Release 2010-12-14 Login into your NanoNote, either with:

$ telnet 192.168.254.101

or - if you already set a root password on your NanoNote - with:

$  ssh root@192.168.254.101
$ route add default gw 192.168.254.100 # set a route on your NanoNote through your host
$ echo "nameserver 8.8.8.8" >> /etc/resolv.conf

In this example we use google's nameserver (8.8.8.8) but you can use any you'd like.

We're done now! :)

You may want to verify your setup by connecting an outer server by your NanoNote with pinging e.g. google.com:

$ ping google.com

You should see sth. like:

PING google.com (209.85.129.105) 56(84) bytes of data.
64 bytes from fk-in-f105.1e100.net (209.85.129.105): icmp_seq=1 ttl=57 time=44.2 ms
64 bytes from fk-in-f105.1e100.net (209.85.129.105): icmp_seq=2 ttl=57 time=44.1 ms

and "voilà"! your Ben is now conected to the evil internet :)

Transfer files

using scp

$ scp PC_FILE root@192.168.254.101:~/
$ scp root@192.168.254.101:/PATH/TO/NANONOTE_FILE ./

using sftp

$ sftp root@192.168.254.101
sftp> get FILE_NAME

using sshfs, like mount a disk to your pc.

$ sshfs root@192.168.254.101:/ /mountpoint
$ fusermount -u /mountpoint

To make this work with the dropbear SSH server:

$ opkg install gesftpserver
$ ln -s /usr/bin/gesftpserver /usr/libexec/sftp-server
$ opkg install openssh-sftp-server

I had file corruption using gesftpserver - r228-1. Maybe it was unrelated, maybe not.

Automatic script files

UDEV

  1. save those as "/etc/udev/rules.d/72-BenNanoNote-net.rules "
SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="0525", ATTR{idProduct}=="a4a1", RUN+="/usr/local/bin/ben-net.sh"
  1. save those under "/usr/local/bin/ben-net.sh", don't forget chmod +x /usr/local/bin/ben-net.sh
GATEWAY_IF=ppp0
if (/usr/bin/lsusb -t -d "0525:a4a1"); then
       echo .
       echo "Ben NanoNote found, setting up USB network ... "
       if !( /sbin/lsmod | grep 'ip_tables' ) && ( /sbin/modprobe -l ip_tables ); then
       	/sbin/modprobe ip_tables
       	echo "ip_tables is now loaded"
       else
           	echo "ip_tables already loaded"
       fi
       if ( grep '0' /proc/sys/net/ipv4/ip_forward ); then
       	echo "1" > /proc/sys/net/ipv4/ip_forward
       	echo "IP forwarding is now enabled"
       else
           	echo "IP forwarding already enabled"
       fi
       if !( /usr/sbin/iptables -L | grep $GATEWAY_IF ); then
       	/usr/sbin/iptables -t nat -A POSTROUTING -o $GATEWAY_IF -j MASQUERADE
       	echo "Routing is now enabled"
       else
           	echo "Routing already setup on "$GATEWAY_IF
       fi
       /sbin/ifconfig usb0 192.168.254.100 netmask 255.255.255.0
fi
  1. Reboot, or log in as root and run # udevadm control --reload-rules
  2. Connect your Nanonote, observe the magic!
Note this will not work when the Nanonote is connected to the PC at boot time, only if you plug it in while udev is running!

/etc/network/interfaces

add those to your /etc/network/interfaces, setup by ifup usb0, ifdown usb0. if you are using Debian/Ubuntu with NetworkManager installed you may needs edit: /etc/NetworkManager/NetworkManager.conf, make sure the managed=false.

allow-hotplug usb0
iface usb0 inet static
       address 192.168.254.100
       netmask 255.255.255.0
       network 192.168.254.0
       broadcast 192.168.254.255
       up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.254.0/24
       up sysctl -w net.ipv4.ip_forward=1
       up route add -host 192.168.254.101 usb0
       down iptables -D POSTROUTING -t nat -j MASQUERADE -s 192.168.254.0/24

Static Mac Address

this can by done by add those text to kernel command line: (also check issues_7 )

 g_ether.dev_addr=5a:77:1e:af:8e:9e
 g_ether.host_addr=72:8d:1f:c4:e8:ca 

if your rootfs have mtd.nn you can using those command:

mtd.nn fw_setenv_default
fw_setenv bootargs   g_ether.host_addr=72:8d:1f:c4:e8:ca mem=32M console=tty0 console=ttyS0,57600n8 ubi.mtd=2 rootfstype=ubifs root=ubi0:rootfs rw rootwait

if your rootfs don't have mtd.nn please run those commands before you change the default bootargs

fw_setenv bootargs mem=32M console=tty0 console=ttyS0,57600n8 ubi.mtd=2 rootfstype=ubifs root=ubi0:rootfs rw rootwait
fw_setenv bootcmd nand read 0x80600000 0x400000 0x200000\;bootm
fw_setenv bootargsfromsd mem=32M console=tty0 console=ttyS0,57600n8 rootfstype=ext2 root=/dev/mmcblk0p1 rw rootwait
fw_setenv bootcmdfromsd mmc init\; ext2load mmc 0 0x80600000 /boot/uImage\; bootm
......
then :
fw_setenv bootargs g_ether.host_addr=72:8d:1f:c4:e8:ca mem=32M console=tty0 console=ttyS0,57600n8 ubi.mtd=2 rootfstype=ubifs root=ubi0:rootfs rw rootwait 

always check mtd.nn for last default bootloader ENVs.

authorized_keys

Keys for the root user go into /etc/dropbear/authorized_keys, not into /root/.ssh.

sftp

$ opkg update
$ opkg install openssh-sftp-server  (works with dropbear)

Issue

  1. reboot BEN or SIE and make new ssh connection the connection freeze and I need to make a new connection, why?

the issue is on your PC, as some popular distros around will try to automatically setup you news usb0 interface after you configured, by adding

iface usb0 inet manual

to /etc/network/interfaces, then NetworkManager daemon won't try to assign an IP with dhcp.

Personal tools
Namespaces
Variants
Actions
Navigation
interactive
Toolbox
Print/export