Saturday, November 8, 2014

MR3020 Configuration After Installing a Snapshot

The MR3020 is a really neat and cheap router with a ton of capability if it's running Openwrt.  There have been a few formal releases over the past couple of years that are now considered obsolete.  The packages that are available to those releases are hardly ever upgraded as they were designed to work as they were at the time of the release.  If one would like to acquire and use the latest packages available to the Openwrt line, they would have to install a snapshot.  A snapshot is a nightly build of the very active Openwrt source.  These snapshots can be very unstable and possibly unusable, but the tradeoff can be worth it.  For me it was since I use dnsmasq a lot.
If you install a snapshot version on your router, you will not have luci.  This means everything has to be done by hand.  Here is how you do it on a MR3020.

Here are all of the packages currently installed with my snapshot:

base-files - 156-r43124
busybox - 1.22.1-3
dnsmasq - 2.72-1
dropbear - 2014.65-2
firewall - 2014-09-19
fstools - 2014-10-27-d71297353dc45eaf8f7c252246490746708530f9
hostapd-common - 2014-10-25-1
ip6tables - 1.4.21-1
iptables - 1.4.21-1
iw - 3.15-1
iwinfo - 2014-10-27.1-d5dc3d0605f76fbbbad005d998497e53a236aeda
jshn - 2014-10-14-464e05e33b4c086be0bd932760a41ddcf9373187
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
kernel - 3.10.58-1-8ba75c28f46d1c58a922f1e15f98d811
kmod-ath - 3.10.58+2014-10-08-1
kmod-ath9k - 3.10.58+2014-10-08-1
kmod-ath9k-common - 3.10.58+2014-10-08-1
kmod-cfg80211 - 3.10.58+2014-10-08-1
kmod-crypto-aes - 3.10.58-1
kmod-crypto-arc4 - 3.10.58-1
kmod-crypto-core - 3.10.58-1
kmod-gpio-button-hotplug - 3.10.58-1
kmod-ip6tables - 3.10.58-1
kmod-ipt-conntrack - 3.10.58-1
kmod-ipt-core - 3.10.58-1
kmod-ipt-nat - 3.10.58-1
kmod-ipv6 - 3.10.58-1
kmod-ledtrig-usbdev - 3.10.58-1
kmod-lib-crc-ccitt - 3.10.58-1
kmod-mac80211 - 3.10.58+2014-10-08-1
kmod-nf-conntrack - 3.10.58-1
kmod-nf-conntrack6 - 3.10.58-1
kmod-nf-ipt - 3.10.58-1
kmod-nf-ipt6 - 3.10.58-1
kmod-nf-nat - 3.10.58-1
kmod-nf-nathelper - 3.10.58-1
kmod-nls-base - 3.10.58-1
kmod-ppp - 3.10.58-1
kmod-pppoe - 3.10.58-1
kmod-pppox - 3.10.58-1
kmod-slhc - 3.10.58-1
kmod-usb-core - 3.10.58-1
kmod-usb-ohci - 3.10.58-1
kmod-usb2 - 3.10.58-1
libblobmsg-json - 2014-10-14-464e05e33b4c086be0bd932760a41ddcf9373187
libc - 0.9.33.2-1
libgcc - 4.8-linaro-1
libip4tc - 1.4.21-1
libip6tc - 1.4.21-1
libiwinfo - 2014-10-27.1-d5dc3d0605f76fbbbad005d998497e53a236aeda
libjson-c - 0.11-2
libjson-script - 2014-10-14-464e05e33b4c086be0bd932760a41ddcf9373187
libnl-tiny - 0.1-3
libubox - 2014-10-14-464e05e33b4c086be0bd932760a41ddcf9373187
libubus - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
libuci - 2014-04-11.1-1
libxtables - 1.4.21-1
mtd - 20
netifd - 2014-10-24-b46a8f3b9794efed197ffd2f6f62eb946de5f235
odhcp6c - 2014-10-25-940e2141ab13727af6323c4d30002f785e466318
odhcpd - 2014-10-18-b461334ab277b6e8fd1622ab7c8a655363bd3f6c
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-7
ppp - 2.4.7-3
ppp-mod-pppoe - 2.4.7-3
procd - 2014-10-30-07c7864d49723b1264ee8bcd6861ea92f679ee98
swconfig - 10
uboot-envtools - 2014.07-1
ubox - 2014-10-06-0b274c16a3f9d235735a4b84215071e1e004caa9
ubus - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
ubusd - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
uci - 2014-04-11.1-1
wpad-mini - 2014-10-25-1

You will notice luci is absent.

Here we go:

  1. First, here is the default configuration:
    1. The ethernet is configured with a dhcp server with a lan'd firewall with a static ip of 192.168.1.1
    2. The wifi is disabled and is not configured
      1. The default configuration for the enabled wireless interface is an access point, we need to get access to the internet so we can update and install the packages available to us in order to get luci.
      2. It is much easier to setup the wireless as a client with a wan and a gateway then to use the ethernet in the same manner since the majority is already setup to do so.
    3. The sliding switch (AP, WISP, 3G) is not active and currently does not serve a purpose besides allowing for a method to resort in a "failsafe" mode upon booting
  2. Connect your computer through ethernet is if it were a typical client accepting a dhcp lease
  3. Telnet to the static ip and change the root password by doing the following
    1. telnet 192.168.1.1
    2. passwd 
      1. enter the desired password
    3. exit
  4. Now ssh into the router by doing the following
    1. ssh root@192.168.1.1
    2. enter the password
  5. We are now in the router and will begin performing the configuration
  6. Enable the wireless
    1. vim /etc/config/wireless
    2. comment or delete the line that has "enabled 0"
    3. wifi down; wifi up
    4. The wifi has a default configuration as an access point
    5. see configuration below
  7. Setup the network configuration for the wireless as a client to get internet
    1. vim /etc/config/network
    2. see configuration below and append that to the end of the file
    3. wifi down; wifi up
  8. Setup the wireless network to interface with your external router or access point; the location where your local internet connection is coming from
    1. vim /etc/config/wireless
    2. see configuration below and edit the existing "radio0" device
    3. wifi down; wifi up
  9. Analyze the dmesg of the router.  If everything is configured correctly, you will notice that there will be a message that reads "wlan0 associated!"
  10. Verify that you are connected the internet
    1. ping google.com
      1. If you get ping responses then everything is good!
      2. If not, troubleshooting my need to take place... dmesg is your friend in this case
    2. opkg update
  11. We are now connected to the internet. You have 2 options at this point:
    1. You can read my previous post on how to make an extroot filesystem to allow more space for packages
    2. You can go ahead and install luci and luci-ssl (both are required in order for it to work correctly) and risk the possibility of a completely full disk
  12. With luci you can now easily configure your router
  13. As mentioned in my previous post on how to extroot your filesystem, you can restore the defaults if you screw up somehow by simply entering "firstboot"
  14. Finished!

Network file configuration to enable the wan firewall configuration for the client router with a couple of my favorite dns servers to get the best results (open dns and google):

config interface 'wan'       
        option ifname 'wlan0'
        option proto 'dhcp'
        option peerdns '0'   
        option dns '208.67.222.222 208.67.220.220 8.8.8.8 8.8.4.4'


Second wifi configuration for associating wireless with access point or router. This is configured to be a client (mode sta) to my wpa2 encrypted (encryption psk2) access point with a wan'd firewall and no dhcp since it will be accepting an ip lease (network wan):

config wifi-device 'radio0'               
        option type 'mac80211'            
        option channel '11'               
        option hwmode '11g'               
        option path 'platform/ar933x_wmac'
        option htmode 'HT20'    
                                
config wifi-iface               
        option device 'radio0'  
        option network 'wan'    
        option mode 'sta'       
        option ssid 'yourwifiSSIDhere' 
        option encryption 'psk2'                                    
        option key 'yourpasswordhere' 


Finished, enjoy! I hope this helped somebody and if you need any help with any of the above steps I'll the best I can to assist.

Monday, November 3, 2014

How to unbrick TP-Link mr3020 on OSX Yosemite

For reasons that were less than desirable, i accidentally bricked my router; tired, hungry, rushed, not really thinking.  Anyway, I installed my other router's firmware (WNDR3700) into the MR3020.  Yea, as you might have predicted that didn't go over well.  I learned.

Materials used:

  • 1 bricked mr3020
  • 1 ethernet cable
  • 1 mini usb cable
  • 1 CP2102 USB to UART breakout board  -  http://www.amazon.com/gp/product/B009T2ZR6W/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
  • 3 female to female jumper wires (mine were supplied with the CP2102)
  • 1 soldering iron
  • 1 header with 3 prongs or 3 sockets (male or female) -  http://www.amazon.com/gp/product/B005HN237S/ref=oh_aui_search_detailpage?ie=UTF8&psc=1
  • 1 OSX computer (I used 10.10 Yosemite)
    • Download
      • Correct openwrt mr3020 firmware
    • Download and install 
      • CoolTerm - http://freeware.the-meiers.org
      • TftpServer - http://ww2.unime.it/flr/tftpserver/
      • SLAB_USBtoUART - http://www.silabs.com/products/mcu/pages/usbtouartbridgevcpdrivers.aspx

Overview and a brief rundown of what is about to take place:

At this moment the router is rebooting constantly (about once every 2 seconds) because it's trying to load an incompatible firmware and it's not smart enough to do anything else but quit and reboot.  What we have to do is gain access to the routers UART pins and send instructions through it using the breakout board and a serial connection.  We have to tell it to re-flash itself with a new image from a hosted TFTP server over a standard rj45 ethernet connection.

Steps:
  1. Open up the MR3020 by taking a really hard piece of plastic or thin screw driver and pry up the edge by the mini usb and ethernet jack.  Work your way around until the whole top pops off.  It's almost impossible to not nick up or break the casing while prying and bending.
  2. Once you managed to get the top off, gently lift the board from the edge that is on the opposite side as the ethernet jack until it comes out.
  3. Holding the board vertical with the ethernet jack pointed upwards, you will notice that there are 4 pins on the bottom with a very small "p1" to the right of them.  The 3 rightmost pins are the ones we are going to use.  From left to right they are, Ground, RX, TX.
  4. Solder the 3 pins from the header in those holes, the leftmost hole should be empty.
  5. Connect your CP2102 breakout board to these pins but you must switch the TX and the RX pins so they are complementing each other, TX should never go with TX.  The ground goes with the ground.
  6. Connect the USB end of the CP2102 breakout board to your computer.
  7. On the OSX mac, download and install CoolTerm, TftpServer, and the SLAB CP2102 usb driver for the breakout board.  Installation is straightforward for all programs.
  8. Open up CoolTerm and click options.  The "Serial Port" option should be lit with a bunch of options on the right including baudrate.  Set the port to SLAB_USBtoUART, baudrate to 115200, data bits 8, parity none, and stop bits 1.  Then click on the "Terminal" option and select "Line Mode" for "Terminal Mode".
  9. Click connect.  Nothing should be showing because we don't have the router powered up.
  10. Open up the Settings app in OSX and create an ethernet connection with a manual address of 192.168.1.100 with a subnet mask of 255.255.255.0
  11. Open the TftpServer and select "Reveal" at the top.  An empty finder window should open up.  Drag your newly downloaded openwrt firmware to the finder window.  Now your Tftp server has a file to upload.
  12. Towards the upper right quadrant of the screen you should see a dropdown drop with at least one network interface.  Make sure that the 192.168.1.100 address is selected.
  13. Start the Tftp Server by pressing the "Start TFTP" button at the top right hand corner of the screen.
  14. Connect the ethernet cable from the router to your mac
  15. Plug in the router and you should see output in the CoolTerm window.  If you do not see any output or the "RX" virtual Green light is not blinking, then diagnose your connection.  It is possible that you may have the TX and RX wires switched up.
  16. Once you start seeing output, you will notice that it goes down for reboot quite frequently.
  17. Type the letters "tpl" into the CoolTerm command line and press enter.  This will cause the firmware to recognize connection and wait for further instruction.  You will know when this works when it populates the word "hornet >"
  18. Type in the following (wait for each command to fully finish, some take longer than others):
    1. setenv ipaddr 192.168.1.111
    2. setenv serverip 192.168.1.100
    3. tftpboot 0x80000000 openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin
    4. erase 0x9f020000 +0x3c0000
    5. cp.b 0x80000000 0x9f020000 0x3c0000
    6. bootm 9f020000
  19. Your router is now rebooting and unbricked! yay!
I hope this helps you and if you have any questions I'll be more than happy to answer them.  Happy hacking!

Props to the developers of CoolTerm and TftpServer.

Great documentation:
http://blog.waysquare.com/how-to-debrick-tl-mr3020/