Making TL-WR1043ND do networking

Posted: July 23rd, 2013 | Author: | Filed under: embedded, FreeBSD, mips, wifi, wireless | No Comments »

This is a followup post to Installing FreeBSD on TP-Link TL-WR1043ND

I’ve learned a few very basic networking things while trying to make this work.

After having FreeBSD run on the board, next thing was to make it do networking. How Adrian’s scripts work is, it has configuration in /etc/cfg/


# pwd
/etc/cfg
# ls
hostapd.wlan0.conf manifest rc.conf
#

Here,
manifest file has list of files to be stored in flash on “cfg_save”. Basic workflow is that you make changes you want and do “cfg_save” which writes things to flash and then “reboot”. So router comes up with the saved settings.

To create a wifi network for let’s say wlan0, we need to create a hostapd file for it:

# cat hostapd.wlan0.conf
interface=wlan0
driver=bsd
ssid=STRCDR_11N
wpa=3
wpa_key_mgmt=WPA-PSK
wpa_passphrase=NotAdminORPassword
wpa_pairwise=CCMP TKIP
ctrl_interface=/var/run/hostapd

As this is a new file and we want to preserve it across reboots, we should add an entry for this file into manifest file. This is how manifest file looks:

# cat manifest
etc/cfg/manifest
etc/master.passwd
etc/group
etc/cfg/rc.conf
etc/cfg/hostapd.wlan0.conf

rc.conf is where you specify your networking configuration:

# cat rc.conf
# Set the default system hostname
system_hostname="freebsd-wifi-build"

# Modules to load
kernel_modules="bridgestp if_bridge random"

# These interfaces are configured in-order
network_interfaces="arge0 wlan0 bridge0"

# Create arge0, no interface address
netif_arge0_enable="YES"
netif_arge0_type="ether"
netif_arge0_addrtype="none"
netif_arge0_descr="default"
netif_arge0_name="arge0"

# Create a bridge, flip on an IPv4 static address
netif_bridge0_type="bridge"
netif_bridge0_addrtype="static"
netif_bridge0_descr="default"
netif_bridge0_name="bridge0"
# These are bridge members w/ STP enabled
netif_bridge0_members_stp="arge0"
# These are bridge members w/ STP disabled
netif_bridge0_members="arge0 wlan0"
netif_bridge0_ipv4_address="192.168.1.20"
netif_bridge0_ipv4_netmask="255.255.255.0"
netif_wlan0_enable="YES"
netif_wlan0_type="wifi"
netif_wlan0_wifi_mode="hostap"
netif_wlan0_descr="default"
netif_wlan0_addrtype="none"
netif_wlan0_name="wlan0"
netif_wlan0_wifi_parent="ath0"
netif_wlan0_wifi_createargs1="country US regdomain FCC3"
netif_wlan0_wifi_createargs2="channel 1:ht/20 up"
netif_wlan0_wifi_hostapd_enable="yes"
netif_wlan0_wifi_hostapd_conf="/etc/cfg/hostapd.wlan0.conf"

A few things to notice here:
* arge0 is the ethernet interface
* wlan0 is the wifi interface
* bridge0 is the bridge interface connecting all of it together. It does the bridging of ethernet and wifi interfaces to send and receive bits (and bytes).

After making changes, to save them do:

# cfg_save
*** Storing configuration files from /etc/cfg/manifest -> /dev/map/cfg..
etc/cfg/manifest
etc/master.passwd
etc/group
etc/cfg/rc.conf
etc/cfg/hostapd.wlan0.conf
8 blocks
dd: /dev/map/cfg: end of device
0+2 records in
1+0 records out
65536 bytes transferred in 0.479322 secs (136726 bytes/sec)

And “reboot” the router. When it comes back, it _should_ have everything ready and setup which was not the case with my setup.

This is how interfaces looked:

# ifconfig
arge0: flags=8943 metric 0 mtu 1500
ether 64:70:02:cd:94:56
inet6 fe80::6670:2ff:fecd:9456%arge0 prefixlen 64 scopeid 0x6
nd6 options=21
media: Ethernet 1000baseT
status: active
arge1: flags=8802 metric 0 mtu 1500
ether 64:70:02:cd:94:57
nd6 options=21
media: Ethernet 100baseTX
status: active
ath0: flags=8843 metric 0 mtu 2290
ether 00:19:e0:66:66:68
nd6 options=21
media: IEEE 802.11 Wireless Ethernet autoselect mode 11ng
status: running
lo0: flags=8049 metric 0 mtu 16384
options=600003
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x9
inet 127.0.0.1 netmask 0xff000000
nd6 options=21
wlan0: flags=8943 metric 0 mtu 1500
ether 00:19:e0:66:66:68
inet6 fe80::219:e0ff:fe66:6668%wlan0 prefixlen 64 scopeid 0xa
nd6 options=21
media: IEEE 802.11 Wireless Ethernet autoselect mode 11ng
status: running
ssid STRCDR_11N channel 1 (2412 MHz 11g ht/20) bssid 00:19:e0:66:66:68
regdomain FCC3 country US ecm authmode WPA1+WPA2/802.11i
privacy MIXED deftxkey 3 TKIP 2:128-bit TKIP 3:128-bit txpower 30
scanvalid 60 protmode CTS ampdulimit 64k ampdudensity 8 shortgi wme
burst dtimperiod 1 -dfs
bridge0: flags=8843 metric 0 mtu 1500
ether 96:ce:f3:c8:09:b4
inet 192.168.1.20 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=21
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
member: wlan0 flags=143
ifmaxaddr 0 port 10 priority 128 path cost 33333
member: arge0 flags=143
ifmaxaddr 0 port 6 priority 128 path cost 2000000
#

As you can see everything looked sane and I could see it advertizing wifi network but when a client tries to associate, it would get stuck on “Obtaining IP address” and even if you assign static IP, client does not receive any packets.

We then looked at “etherswitchcfg” which provides ethernet connectivity for the board:

# etherswitchcfg
port0:
vlangroup: 1
media: Ethernet autoselect (100baseTX )
status: active
port1:
vlangroup: 0
media: Ethernet autoselect (none)
status: no carrier
port2:
vlangroup: 0
media: Ethernet autoselect (none)
status: no carrier
port3:
vlangroup: 0
media: Ethernet autoselect (none)
status: no carrier
port4:
vlangroup: 0
media: Ethernet autoselect (none)
status: no carrier
port5:
vlangroup: 0
media: Ethernet 1000baseT
status: active
vlangroup0:
vlan: 1
members 1,2,3,4,5
vlangroup1:
vlan: 2
members 0,5t
#

Now, as you can see the ethernet cable in WAN (blue) port shows up as port0 and it is in vlangroup1. But vlangroup1 is in vlan 2 and it is tagged. Moving ethernet cable from WAN port to one of the LAN ports fixed the problem.


# etherswitchcfg
port0:
vlangroup: 1
media: Ethernet autoselect (none)
status: no carrier
port1:
vlangroup: 0
media: Ethernet autoselect (100baseTX )
status: active
port2:
vlangroup: 0
media: Ethernet autoselect (none)
status: no carrier
port3:
vlangroup: 0
media: Ethernet autoselect (none)
status: no carrier
port4:
vlangroup: 0
media: Ethernet autoselect (none)
status: no carrier
port5:
vlangroup: 0
media: Ethernet 1000baseT
status: active
vlangroup0:
vlan: 1
members 1,2,3,4,5
vlangroup1:
vlan: 2
members 0,5t
#

Now a client could associate and get an IP via dhcp from the incoming ethernet connection on the router. (No dhcpd is needed/running on the router itself).

To look at connected clients:

# ifconfig wlan0 list sta
ADDR AID CHAN RATE RSSI IDLE TXSEQ RXSEQ CAPS FLAG
08:11:96:f9:b2:ec 1 1 144M 38.5 0 4012 27616 EPS AQEHTRS RSN HTCAP WME

To debug, we can look at individual ports with “tcpdump -ni “.

Verbose debugging from ath wifi stack can be obtained by:

# wlandebug -i wlan1 +assoc
net.wlan.1.debug: 0x0 => 0x800000

Just as a side-note, hostapd proc is using the configuration we provided and is running:

# ps awwux | grep hostapd
root 176 0.0 6.6 13104 2176 - Ss 6:56PM 0:00.13 hostapd -P /var/run/hostapd.wlan0.pid -B /etc/cfg/hostapd.wlan0.conf

Again a *HUGE* Thanks to Mr FreeBSD Wifi (Adrian Chadd) for all the build scripts and help with the bring-up.



Leave a Reply