Saturday, July 21, 2012

Installing OpenWRT on a TP-Link MR3420


The idea is to install OpenWRT on a TP-Link MR3420 and configure it to use a 3G USB modem. I'll assume you have a Windows computer where you can connect with 3G USB modem.

First flash the router with the OpenWRT image. See  http://wiki.openwrt.org/toh/tp-link/tl-mr3420 for more details. Reboot the router.

Then set your computer ethernet connection to a fixed IP address of 192.168.1.100 with subnet of 255.255.255.0. Connect the router port 1 to the computer. From the computer you should be able to ping 192.168.1.1. Then telnet to 192.168.1.1. You'll get a busybox shell, type passwd and provide a new root password. Once this is set telnet will be disabled and you'll only have access via SSH. 

Open a web browser to 192.168.1.1. Log in with username root and password as defined above. Then go set up your wireless settings & configure everything there. Reboot the router and unplug the network cable. Make sure you get a wireless connection between your computer and the router - you'll need it later on.

On you computer set you lan connection IP settings back to automatic. Then share your 3G connection to your ethernet connection (go to your adapter settings, choose Advanced and select share). Connect you computer network to the WAN port on the router. The reason is we need to access the internet from the router. SSH into your router (192.168.1.1) and make sure you can ping an internet address.

Then install the following packages
opkg update
opkg install chat comgt kmod-usb-acm kmod-usb-serial kmod-usb-serial-option kmod-usb-uhci libusb luci-proto-3g mini-sendmail usb-modeswitch usb-modeswitch-data
Reboot the router and unplug the WAN connection. Also disable internet sharing on your computer.

SSH back into the router once it is rebooted. Unplug the USB 3G device from the computer and plug it into the router. Type dmesg, you should see something like

usb 1-1: new high speed USB device using ar71xx-ehci and address 2
usb 1-1: configuration #1 chosen from 1 choice
usb 1-1: usbfs: process 2978 (usb_modeswitch) did not claim interface 0 before use
usb 1-1: USB disconnect, address 2
usb 1-1: new high speed USB device using ar71xx-ehci and address 3
usb 1-1: configuration #1 chosen from 1 choice
option 1-1:1.0: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
option 1-1:1.3: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
option 1-1:1.4: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2

Using your browser, go to router web interface on 192.168.1.1. Go to Network - Interfaces and click on wan. Change the interface to UMTS/GPRS/EV-DO and confirm the switch. Choose device /dev/ttyUSB0, service type=UMTS/GPRS, APN=internet (or whatever APN your 3G is using) and click on Save & Apply.

Then via SSH you need to add the following line to /etc/config/network section for interface wan:
option 'pppd_options' 'noipdefault'

Then via SSH type "ifup wan". wait for a couple of seconds, then type "logread".

If you need more debugging, change /etc/ppp/options and insert "debug" in the file.

My logread on a successful connection looks as follows:
Jul 21 11:53:31 OpenWrt daemon.notice pppd[10455]: pppd 2.4.4 started by root, uid 0
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: abort on (BUSY)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: abort on (NO CARRIER)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: abort on (ERROR)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: report (CONNECT)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: timeout set to 10 seconds
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: send (AT&F^M)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: expect (OK)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: AT&F^M^M
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: OK
Jul 21 11:53:32 OpenWrt local2.info chat[10460]:  -- got it
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: send (ATE1^M)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: expect (OK)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: ^M
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: ATE1^M^M
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: OK
Jul 21 11:53:32 OpenWrt local2.info chat[10460]:  -- got it
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: send (AT+CGDCONT=1,"IP","internet"^M)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: timeout set to 30 seconds
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: expect (OK)
Jul 21 11:53:32 OpenWrt local2.info chat[10460]: ^M
Jul 21 11:53:33 OpenWrt local2.info chat[10460]: AT+CGDCONT=1,"IP","internet"^M^M
Jul 21 11:53:33 OpenWrt local2.info chat[10460]: OK
Jul 21 11:53:33 OpenWrt local2.info chat[10460]:  -- got it
Jul 21 11:53:33 OpenWrt local2.info chat[10460]: send (ATD*99***1#^M)
Jul 21 11:53:33 OpenWrt local2.info chat[10460]: expect (CONNECT)
Jul 21 11:53:33 OpenWrt local2.info chat[10460]: ^M
Jul 21 11:53:33 OpenWrt local2.info chat[10460]: ATD*99***1#^M^M
Jul 21 11:53:33 OpenWrt local2.info chat[10460]: CONNECT
Jul 21 11:53:33 OpenWrt local2.info chat[10460]:  -- got it
Jul 21 11:53:33 OpenWrt local2.info chat[10460]: send ( ^M)
Jul 21 11:53:33 OpenWrt daemon.info pppd[10455]: Serial connection established.
Jul 21 11:53:33 OpenWrt daemon.info pppd[10455]: Using interface 3g-wan
Jul 21 11:53:33 OpenWrt daemon.notice pppd[10455]: Connect: 3g-wan <--> /dev/ttyUSB0
Jul 21 11:53:36 OpenWrt daemon.warn pppd[10455]: Could not determine remote IP address: defaulting to 10.64.64.64
Jul 21 11:53:36 OpenWrt daemon.notice pppd[10455]: replacing old default route to eth1 [192.168.0.1]
Jul 21 11:53:36 OpenWrt daemon.notice pppd[10455]: local  IP address 41.151.67.64
Jul 21 11:53:36 OpenWrt daemon.notice pppd[10455]: remote IP address 10.64.64.64
Jul 21 11:53:36 OpenWrt daemon.notice pppd[10455]: primary   DNS address 196.43.34.190
Jul 21 11:53:36 OpenWrt daemon.notice pppd[10455]: secondary DNS address 196.43.46.190

To disconnect, type "ifdown wan".

Modify /etc/config/network - my final version looks as follows. This is so different users on the lan (wired) can access each other:
config 'switch' 'eth0'
        option 'reset' '1'
        option 'enable_vlan' '1'
config 'switch_vlan'
        option 'device' 'eth0'
        option 'vlan' '1'
        option 'ports' '0t 1 2 3 4'
config 'switch_vlan'
        option 'device' 'eth0'
        option 'vlan' '2'
        option 'ports' '0t 5'
config 'interface' 'loopback'
        option 'ifname' 'lo'
        option 'proto' 'static'
        option 'ipaddr' '127.0.0.1'
        option 'netmask' '255.0.0.0'
config 'interface' 'lan'
        option 'ifname' 'eth0.1'
        option 'type' 'bridge'
        option 'proto' 'static'
        option 'ipaddr' '192.168.1.1'
        option 'netmask' '255.255.255.0'
config 'interface' 'wan'
        option 'proto' '3g'
        option 'device' '/dev/ttyUSB0'
        option 'service' 'umts'
        option 'apn' 'internet'
        option 'pppd_options' 'noipdefault'
Finally configure 2 LEDs: Via the web interface on 192.168.1.1, choose System - LED configuration. Add two new:
name=3g, LED name=tl-mr3420:green:3g, trigger=net dev, device=3g-wan, trigger mode=link on
name=wifi, LED name=tl-mr3420:green:qss, trigger=net dev, device=wlan0, trigger mode=transmit+receive

For some reason there is no Wifi LED - we use the QSS LED instead.

No comments: