WR703N with GPS Module

WR703N with GPS Module
This tutorial uses the WR703N serial port with a u-blox REYAX RY836AI GNSS receiver module for a super-portable War-Walking / War-Driving device.

Obtaining Openwrt
*Note: Everything is done from the latest version of Ubuntu LTS (14.04).

For this tutorial we will work out of your home directory. We will download the latest code for Openwrt Barrier Breaker 14.07 (BB). We are using BB since gpsd will compile. I haven’t gotten it to work in Chaos Calmer 15.05 yet.

Make sure your environment has the software required.

$ sudo apt-get update
$ sudo apt-get install git-core build-essential libssl-dev subversion libncurses5-dev zlib1g-dev gawk gcc-multilib flex gettext quilt xsltproc libxml-parser-perl mercurial bzr ecj cvs unzip

Get the latest code for Barrier Breaker

$ cd ~/
$ git clone git://git.openwrt.org/14.07/openwrt.git barrier_breaker
Cloning into 'barrier_breaker'...
remote: Counting objects: 10545, done.
remote: Compressing objects: 100% (7917/7917), done.
remote: Total 10545 (delta 3667), reused 8061 (delta 2033)
Receiving objects: 100% (10545/10545), 12.92 MiB | 2.24 MiB/s, done.
Resolving deltas: 100% (3667/3667), done.
Checking connectivity... done.

Download and install all available “feeds”, create our configuration file to build what we need.

$ cd ~/barrier_breaker
~/barrier_breaker$ ./scripts/feeds update -a
~/barrier_breaker$ ./scripts/feeds install -a
~/barrier_breaker$ make menuconfig

Go forth and select all of these packages to be included in the image and not as a modules (asterisk (*) instead of (M)).

Target System (Atheros AR7xxx/AR9xxx)
Target Profile (TP-LINK TL-WR703N)

[*] Build the OpenWrt Image Builder
[*] Build the OpenWrt SDK
[*] Build the OpenWrt based Toolchain

Network β€”> (gpsd & gpsd-clients)
Network β€”>wireless (kismet-server)
Utilities β€”>coreutils β€”> coreutils-stty
The pre-requisite libraries and support packages will automatically be selected for gpsd and kismet.

You may also want support for USB storage especially if you also plan on capturing the wireless network traffic.

Kernel modules β€”>Filesystems (kmod-fs-ext4, kmod-fs-ntfs & kmod-fs-vfat)
Kernel modules β€”>USB Support (kmod-usb-ohci, kmod-usb-uhci, kmod-usb2, kmod-usb-storage, kmod-usb-storage-extras)
Kernel modules β€”>Native Language Support (kmod-nls-cp437, kmod-nls-base & kmod-nls-iso8859-1)

I also like to add support for my USB Wireless Devices including my Alfa AWUS036H, Alfa AWUS036EW, and TP-LINK TL-WN722N

Kernel modules β€”>Wireless Drivers β€”>kmod-ath9k-htc & kmod-rtl8187

Terminate console on serial port (UART)
We can’t have our kernel spitting error messages to the serial port. Nor can we allow the console to interact with it. You can visit the OpenWrt Wiki page at here.

~/barrier_breaker$ grep -n CONFIG_CMDLINE target/linux/ar71xx/config-3.10
138:CONFIG_CMDLINE="rootfstype=squashfs,jffs2 noinitrd"
139:CONFIG_CMDLINE_BOOL=y
140:# CONFIG_CMDLINE_OVERRIDE is not set
Line 138 it is! Modify rootfstype=squashfs,jffs2 noinitrd to rootfstype=squashfs,jffs2 noinitrd console=null
~/barrier_breaker$ sed -i '138s/.*/CONFIG_CMDLINE="rootfstype=squashfs,jffs2 noinitrd console=null"/' target/linux/ar71xx/config-3.10

Custom Files
The best place to learn about adding custom files to your image build is the OpenWrt Wiki, specifically here.

Create Directories to Store Out Custom Files

$ mkdir -p ~/barrier_breaker/files/etc/init.d
$ mkdir -p ~/barrier_breaker/files/etc/config
$ mkdir -p ~/barrier_breaker/files/etc/rc.d
$ mkdir -p ~/barrier_breaker/files/etc/kismet

Disable Console on serial port
I know we disabled the console by editing the kernel but I want to be sure…or maybe you don’t want to modify the console via the kernel. You can visit the OpenWrt Wiki page at here.

$ vim ~/barrier_breaker/files/etc/inittab
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
#::askconsole:/bin/ash --login

$ vim ~/barrier_breaker/files/etc/sysctl.conf
kernel.printk = 0 4 1 7
kernel.panic=3
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.all.arp_ignore=1
net.ipv4.ip_forward=1
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.icmp_ignore_bogus_error_responses=1
net.ipv4.igmp_max_memberships=100
net.ipv4.tcp_ecn=0
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_keepalive_time=120
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_timestamps=1
net.ipv4.tcp_sack=1
net.ipv4.tcp_dsack=1

net.ipv6.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1

net.netfilter.nf_conntrack_acct=1
net.netfilter.nf_conntrack_checksum=0
net.netfilter.nf_conntrack_max=16384
net.netfilter.nf_conntrack_tcp_timeout_established=7440
net.netfilter.nf_conntrack_udp_timeout=60
net.netfilter.nf_conntrack_udp_timeout_stream=180

# disable bridge firewalling by default
net.bridge.bridge-nf-call-arptables=0
net.bridge.bridge-nf-call-ip6tables=0
net.bridge.bridge-nf-call-iptables=0

Custom Wireless Configuration Files
$ vim ~/barrier_breaker/files/etc/config/wireless
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  lan
        option mode     ap
        option ssid     warmachine #or whatever you want to call it
        option encryption psk2
        option key      'mysupersecretPassWord'
        option hidden   1

Custom Network Configuration Files
$ vim ~/barrier_breaker/files/etc/config/network
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'
        option force_link '1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.225'
        option netmask '255.255.255.0'

Custom System Configuration Files
$ vim ~/barrier_breaker/files/etc/config/system
config system
        option hostname KisWrt #or whatever you want to call it
        option timezone UTC

Setup Serial Port
$ vim ~/barrier_breaker/files/etc/rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
stty -F /dev/ttyATH0 9600 sane
exit 0

gpsd Configuration File
$ vim ~/barrier_breaker/files/etc/config/gpsd
config gpsd core
    option device    "/dev/ttyATH0"
    option port    "2947"
    option listen_globally    "false"
    option enabled    "true"

Now for the kismet.conf file. I’m not going to list the entire file for this tutorial. Below are the options I change in /etc/kismet/kismet.conf. Then I show you how to just download the file with the changes already made.
Modify These Variables
servername=KisWrt
logprefix=/tmp
ncsource=wlan0
listen=tcp://0.0.0.0:2501
allowedhosts=127.0.0.1,192.168.1.0/24
gps=true
gpstype=gpsd
gpsreconnect=true
logtypes=gpsxml,netxml

cd ~/barrier_breaker/files/etc/kismet
~/barrier_breaker/files/etc$ wget http://www.jedge.com/code/wr703n.kismet.conf -O kismet.conf

Kismet Startup Script
This script includes code to pull the date and time from our GPS before starting Kismet.

vim ~/barrier_breaker/files/etc/init.d/kismet
#!/bin/sh /etc/rc.common
 
START=99
STOP=10
 
start() {
    date -s '2015-01-01 00:00:01'
    sleep 1
    killall ntpd 
    sleep 30 #wait for gps to get a lock
    GPSDATE=`gpspipe -w | head -10 | grep TPV | sed -r 's/.*"time":"([^"]*)".*/\1/' | head -1 |sed -r 's/T/ /g' | awk -F"." '{print $1}'`
    date -s "$GPSDATE"
    /usr/sbin/ntpd       
        kismet_server --config-file /etc/kismet/kismet.conf --daemonize --silent
}                 
 
stop() {          
       killall kismet_server
     
}

Create a symlink so kismet_server and gpsd start when the device boots.
$ cd ~/barrier_breaker/files/etc/rc.d
~/barrier_breaker/files/etc/rc.d$ ln -s ../init.d/gpsd S50gpsd
~/barrier_breaker/files/etc/rc.d$ ln -s ../init.d/gpsd K20gpsd
~/barrier_breaker/files/etc/rc.d$ ln -s ../init.d/kismet S95kismet
~/barrier_breaker/files/etc/rc.d$ ln -s ../init.d/kismet K10kismet

Why set your root password after the first boot? Why not set it in your image before you install it?

echo "yoursecret" | makepasswd --clearfrom=- --crypt-md5 |awk '{print $2}'
$1$uZ9fJ7OE$A8KGOGcOR4fP3/XEsxQaa0
$ vim ~/barrier_breaker/files/etc/shadow
root:$1$uZ9fJ7OE$A8KGOGcOR4fP3/XEsxQaa0:0:0:99999:7:::
daemon:*:0:0:99999:7:::
ftp:*:0:0:99999:7:::
network:*:0:0:99999:7:::
nobody:*:0:0:99999:7:::

Now we can compile our image. Once complete your image will be find in ~/barrier_breaker/bin/ar71xx called openwrt-ar71xx-generic-gl-inet-6416A-v1-squashfs-factory.bin

cd ~/barrier_breaker
~/barrier_breaker$ make target/linux/{clean,prepare} V=s QUILT=1
~/barrier_breaker$ make V=99

Documenting how to upgrade (or downgrade) the firmware of your wr703n is tricky as I don’t know what version you are running or what state it currently is in. I’ll leave this to you. Just follow the instructions from the OpenWrt wiki https://wiki.openwrt.org/toh/tp-link/tl-wr703n

References
http://blog.petrilopia.net/linux/raspberry-pi-set-time-gps-dongle/
http://wiki.openwrt.org/doc/techref/initscripts
http://wiki.openwrt.org/doc/recipes/serialbaudratespeed
http://wiki.openwrt.org/doc/hardware/port.serial
http://wiki.openwrt.org/doc/howto/networked.gps
http://wiki.openwrt.org/doc/recipes/terminate.console.on.serial/

Twitter
Follow by Email
LinkedIn
YouTube
Google+
RSS

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.