B.A.T.M.A.N. Advanced on OpenWrt How-To

Last changed: 03-Jul-2009 16:14 


OpenWrt is a linux distro for embedded devices, and is particularly well-suited for Wi-Fi routers. Batman Advanced is a tool for creating a mesh network that is transparent to IP, DHCP, etc. I needed a How-To for setting this up, but I don't think one exists yet, so here we go.

I assume that

  • you can install OpenWrt
  • you are not afraid of the command line
  • you know at least the basics about TCP/IP networks
  • you have two or three embedded computers with wifi interfaces and the option to install OpenWrt

My test environment includes three Ubiquiti NanoStation2 units and a desktop computer to work from. The three NanoStations and desktop are on a network; the mesh nodes are, and The mesh network is with no external gateway; the mesh nodes are, and Where examples below show only .101, the other nodes (.102 and .103) are implied. I won't go into how to setup an Internet gateway and such.

I have also tested this How-To with a few Ubiquiti PicoStation2HP units.

OpenWrt 8.09.1 and batman-advanced r1176

For each mesh node:

  1. Install OpenWrt 8.09.1
  2. Log in via telnet, set the root password and set the wired IP address and gateway
    jake@bernard:~$ telnet
    Connected to
    Escape character is ']'.
     === IMPORTANT ============================
      Use 'passwd' to set your login password
      this will disable telnet and enable SSH
    BusyBox v1.11.2 (2009-05-28 20:21:24 UTC) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
      _______                     ________        __
     |       |.-----.-----.-----.|  |  |  |.----.|  |_
     |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
     |_______||   __|_____|__|__||________||__|  |____|
              |__| W I R E L E S S   F R E E D O M
     KAMIKAZE (8.09.1, r16278) ----------------------------
      * 10 oz Vodka       Shake well with ice and strain
      * 10 oz Triple sec  mixture into 10 shot glasses.
      * 10 oz lime juice  Salute!
    root@OpenWrt:/# passwd
    Changing password for root
    New password:
    Retype password:
    Password for root changed by root
    root@OpenWrt:/# uci set network.lan.ipaddr=
    root@OpenWrt:/# uci set network.lan.gateway=
    root@OpenWrt:/# uci set network.lan.dns=
    root@OpenWrt:/# uci commit
    root@OpenWrt:/# /etc/init.d/network restart
    telnet> <ctrl+d>Connection closed.
  3. Connect via SSH, get the available opkg packages and install battool and kmod-batman-advanced (do not install batman-adv)
    jake@bernard:~$ ssh root@
    root@'s password: 
    BusyBox v1.11.2 (2009-05-28 20:21:24 UTC) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
      _______                     ________        __
     |       |.-----.-----.-----.|  |  |  |.----.|  |_
     |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
     |_______||   __|_____|__|__||________||__|  |____|
              |__| W I R E L E S S   F R E E D O M
     KAMIKAZE (8.09.1, r16278) ----------------------------
      * 10 oz Vodka       Shake well with ice and strain
      * 10 oz Triple sec  mixture into 10 shot glasses.
      * 10 oz lime juice  Salute!
    root@OpenWrt:~# opkg update && opkg install battool kmod-batman-advanced
    Downloading http://downloads.openwrt.org/kamikaze/8.09.1/atheros/packages/Packages.gz
    Connecting to downloads.openwrt.org (
    Packages.gz          100% |*************************************************************************|   141k 00:00:00 ETA
    Inflating http://downloads.openwrt.org/kamikaze/8.09.1/atheros/packages/Packages.gz
    Updated list of available packages in /var/opkg-lists/snapshots
    Installing battool (r1176-1) to root...
    Downloading http://downloads.openwrt.org/kamikaze/8.09.1/atheros/packages/battool_r1176-1_mips.ipk
    Connecting to downloads.openwrt.org (
    battool_r1176-1_mips 100% |*************************************************************************| 10162  --:--:-- ETA
    Installing kmod-batman-advanced ( to root...
    Downloading http://downloads.openwrt.org/kamikaze/8.09.1/atheros/packages/kmod-batman-advanced_2.6.26.8+r1176-atheros-1_mips.ipk
    Connecting to downloads.openwrt.org (
    kmod-batman-advanced 100% |*************************************************************************| 64121  00:00:00 ETA
    Configuring battool
    Configuring kmod-batman-advanced
  4. Make sure the batman_adv kernel module is loaded
    root@OpenWrt:~# lsmod | grep bat
    batman_adv             51360  0
  5. Create the wireless device that the mesh will use (ath0)
    root@OpenWrt:~# uci delete wireless.wifi0.disabled
    root@OpenWrt:~# uci delete wireless.@wifi-iface[0].network
    root@OpenWrt:~# uci set wireless.wifi0.channel=1
    root@OpenWrt:~# uci set wireless.@wifi-iface[0].mode=ahdemo
    root@OpenWrt:~# uci set wireless.@wifi-iface[0].ssid=mesh
    root@OpenWrt:~# uci set network.lan.mtu=1500
    root@OpenWrt:~# uci set network.lan.ifname="eth0 bat0"
    root@OpenWrt:~# uci set network.ath0=interface
    root@OpenWrt:~# uci set network.ath0.ifname=ath0
    root@OpenWrt:~# uci set network.ath0.proto=none
    root@OpenWrt:~# uci set network.ath0.mtu=1524
    root@OpenWrt:~# uci set network.bat0=interface
    root@OpenWrt:~# uci set network.bat0.ifname=bat0
    root@OpenWrt:~# uci set network.bat0.proto=none
    root@OpenWrt:~# uci set network.bat0.mtu=1500
    root@OpenWrt:~# uci commit
    root@OpenWrt:~# /etc/init.d/network restart
    Interface doesn't accept private ioctl...
    wds (8BE0): Operation not supported
    I'm pretty sure that error is harmless. The "uci delete" command ensures that ath0 will not have an IP address.
  6. Add the wireless interface to the batman-advanced interface
    root@OpenWrt:~# echo ath0 > /proc/net/batman-adv/interfaces
  7. Now stop. Reboot this node and do all of the previous steps to at least one more node. Rebooting the node is the only way I can find to get the MTU to be set correctly. Running
    /etc/init.d/network restart
    will leave one or two of your interfaces with incorrect MTU values. If you know how to resolve this problem without rebooting, please contact me.
    root@OpenWrt:~# reboot && exit
  8. At this point, batman-advanced should be able to see other batman-advanced nodes. To see what other nodes are visible to the current node
    root@OpenWrt:~# cat /proc/net/batman-adv/originators 
      Originator     (#/255)           Nexthop [outgoingIF]:   Potential nexthops ... [B.A.T.M.A.N. Adv 0.1 rv1176, MainIF/MAC: ath0/00:15:6d:a7:6a:14] 
    00:15:6d:a7:6a:9e  ( 18) 00:15:6d:a7:6a:9e [      ath0]: 00:15:6d:a7:6a:9e ( 18) 00:15:6d:a7:6a:9c (  3)
    00:15:6d:a7:6a:9c  ( 39) 00:15:6d:a7:6a:9c [      ath0]: 00:15:6d:a7:6a:9c ( 39) 00:15:6d:a7:6a:9e (  1)
    The first line says MainIF/MAC and the interface and MAC address of this node. Each following line is a node that the current node can see.
  9. Test the connection with battool
    root@OpenWrt:~# battool ping 00:15:6d:a7:6a:9e
    batping 0:15:6d:a7:6a:9e
    19 bytes from 0:15:6d:a7:6a:9e icmp_seq=0 ttl=0 time=3.35 ms
    19 bytes from 0:15:6d:a7:6a:9e icmp_seq=0 ttl=0 time=2.54 ms
    19 bytes from 0:15:6d:a7:6a:9e icmp_seq=0 ttl=0 time=2.56 ms
    C--- 0:15:6d:a7:6a:9e batping statistic ---
    3 packets transmitted, 3 received, 0% packet loss
    rtt min/avg/max/mdev = 2.536/2.815/3.347/0.811 ms
  10. And the mesh is running! You can treat bat0 like any other interface. For example
    root@OpenWrt:~# uci set network.mesh=interface
    root@OpenWrt:~# uci set network.mesh.ifname=bat0
    root@OpenWrt:~# uci set network.mesh.proto=static
    root@OpenWrt:~# uci set network.mesh.ipaddr=
    root@OpenWrt:~# uci set network.mesh.netmask=
    root@OpenWrt:~# uci commit
    root@OpenWrt:~# /etc/init.d/network restart
    Interface doesn't accept private ioctl...
    wds (8BE0): Operation not supported
    root@OpenWrt:~# ping
    PING ( 56 data bytes
    64 bytes from seq=0 ttl=64 time=29.766 ms
    --- ping statistics ---
    2 packets transmitted, 1 packets received, 50% packet loss
    round-trip min/avg/max = 29.766/29.766/29.766 ms
    root@OpenWrt:~# ping
    PING ( 56 data bytes
    64 bytes from seq=0 ttl=64 time=23.502 ms
    --- ping statistics ---
    1 packets transmitted, 1 packets received, 0% packet loss
    round-trip min/avg/max = 23.502/23.502/23.502 ms
  11. To enable the interface automatically
    root@OpenWrt:~# echo "echo ath0 > /proc/net/batman-adv/interfaces" > /etc/rc.d/S41batman_adv
    root@OpenWrt:~# chmod +x /etc/rc.d/S41batman_adv 
    Newer versions of batman-advanced have a nice uci interface for this. If you know of a more elegant way to automatically enable bat0 in r1176, please contact me.
  12. It's a good idea to explore /proc/net/batman-adv/ and see what's there. log and log_level are important when you get on the mailing list. After a while, you might get tired of typing
    [cat|echo] ... /proc/net/batman-adv/...
    That's when you should check out batctl.

What to do now?

Under construction

If you aren't familiar with setting up bridges and access points then this is for you.

Encrypt the mesh network


Access points

Having a bunch of mesh nodes is fun, but you probably want folks to be able to use the mesh with their WiFi devices. We'll create an access point interface and add it to the bridge. This gets tricky because OpenWrt adds the ad-hoc interface after the ap interface. i.e. ath0 becomes ath1, and ath0 becomes the access point.

  1. Add a second athX interface

OpenWrt 8.09.1 and batman-advanced SVN

Under construction

The hard part here is compiling. After that, setup is just like the directions above. You will need a Linux box, and I'll show you how this is done in Ubuntu 9.04.

  1. Install the packages you will need to compile
    sudo apt-get install build-essential subversion ncurses-dev zlib1g-dev gawk flex unzip
  2. Download the OpenWrt source code
    $ wget http://downloads.openwrt.org/kamikaze/8.09.1/kamikaze_8.09.1_source.tar.bz2
    $ tar -xf kamikaze_8.09.1_source.tar.bz2
  3. Get the packages feed, then install batman-advanced and battool
    $ cd kamikaze_8.09.1
    $ scripts/feeds update packages
    $ scripts/feeds install battool
    $ scripts/feeds install batman-advanced