-
Notifications
You must be signed in to change notification settings - Fork 17
Create OpenWrt bin image including openvswitch and the ath9k patch
UNDER CONSTRUCTION
We are using the next routers, which run with ath9k
driver:
-
Netgear R6100. More information https://wiki.openwrt.org/toh/netgear/netgear_r6100
-
TP-Link AC1750 v2 (Archer C7). More information: https://wiki.openwrt.org/toh/tp-link/archer-c5-c7-wdr7500
-
TP-Link TL-WR1043ND. More information: https://wiki.openwrt.org/toh/tp-link/tl-wr1043nd. Note. This device only has a USB port, so you cannot use an external USB memory stick, and an extra wireless card at the same time, or you can use USB Hub.
-
TP-Link TL-WDR4300. More information: https://wiki.openwrt.org/toh/tp-link/tl-wdr4300
We are connecting to them an extra WiFi interface: the USB TP-Link TL-WN722N (also uses ath9k
driver). Some of the experiences we are adding here may only be valid for this particular hardware, and may require an adaptation before being useful for other hardware.
You have three different options:
-
If you have any of the supported routers, you will find the
.bin
files here, so you can skip this step and flash them directly. -
There is a script that automatically builds an OpenWrt image which you can flash in your AP. You can find it here: (https://github.com/Wi5/odin-wi5/tree/master/Odin_Wi5_firmware_build
-
You can follow the next steps. Note: They are valid for OpenWrt 15.05.1
If you don’t have them, install these tools as root: ncurses, svn, awk, build-essential, git
-
In Debian, you can use:
apt-get update apt-get install ncurses subversion gawk build-essential git apt-get install libssl-dev zlibc
-
In Ubuntu, you can do:
apt-get update apt-get install subversion libssl-dev zlibc zlib1g zlib1g-dev gzip apt-get install gawk libncurses5-dev git build-essential
Create the folder were the source will be downloaded (e.g. openwrt )
~$ mkdir openwrt
~$ cd openwrt
Clone the repository from git (https://dev.openwrt.org/wiki/GetSource)
~/openwrt$ git clone git://git.archive.openwrt.org/15.05/openwrt.git trunk
We are going to add some extra packages to the OpenWrt sources:
-
Move
feeds.conf.default
tofeeds.conf
~/openwrt/trunk$ mv feeds.conf.default feeds.conf
-
Prepare menuconfig, to add some optional packages (including openvswitch). The configurations of
menuconfig
are stored in the.config
file.
Note: If you want to reset your menuconfig, just delete the .config
file.
-
Update the
menuconfig
with the new sources (make sure you are connected to the Internet) with:~/openwrt/trunk$ ./scripts/feeds update -a
-
Add all the packages to OpenWrt sources:
~/openwrt/trunk$ ./scripts/feeds install -a
Note: With –a
, you will install all possible packages. Another option is to install per-package (-p
). You can then install individual packages. For example, if you only want to add Luci to the menuconfig
:
~/openwrt/trunk$ ./scripts/feeds install -a -p luci
~/openwrt/trunk$ make menuconfig
- Select your architecture:
'Target System': Atheros AR71xxx/Ar9xxx
- Select the Subtarget:
For Netgear 6100 use:
Generic devices with nand flash
For TP-Link AC1750 use:
Generic devices
- Select your device
'Target Profile': Netgear R6100
'Target Profile': TP-LINK Archer C5/C7
-
Select squashfs in
Target images
. This way, you will be able to flash the new firmware maintaining the configuration files. -
Save and exit
menuconfig
.
~/openwrt/trunk$ make defconfig
Check prerequisites:
~/openwrt/trunk$ make prereq
Now, you have a complete environment for cross-compilation in OpenWrt.
Run again the menuconfig to configure the sources:
~/openwrt/trunk$ make menuconfig
Note: If you use <*>
it compiles the package and adds it to the .bin firmware. You should use this option.
If you use <M>
it compiles the package but it does not add it to the .bin firmware.
-
Select Luci
Luci / Collections / Luci
-
Select nano and joe editors you like the most:
Utilities / editors / nano Utilities / editors / joe
-
In order to support c++ calls, select:
Base system / libstdcpp GNU Standard C++ Library v3
-
In order to support USB drives, select:
kernel modules / USB support / kmod-usb-storage Kernel modules / filesystems / kmod-fs-ext4 / kmod-fs-msdos / kmod-fs-vfat Native language support / kmod-nls-cp437
-
Install hostapd utils
Network / hostapd-utils
They are needed in order to change the channel of the auxiliary interface.
-
Install support for tun/tap interface
Kernel modules / Network Support / kmod-tun
-
Optional. Install the dummy network interface (may be needed if you don't have a secondary wireless interface)
Kernel modules / Network Devices / kmod-dummy
-
Optional. Install the
ip link
commmand (may be needed if you don't have a secondary wireless interface)Base system / Busybox / Networking utilities / ip link
-
Again in Network, install tcpdump:
Network / tcpdump
-
Again in Network, install openvswitch modules and requirements:
Network / openvswitchswitch / openvswitch-ipsec Kernel modules / Cryptographic API modules / kmod-crypto-crc32c Kernel modules / Libraries / kmod-lib-crc32c
-
Optional. If you want to use
confuse
library, add it in:Libraries / confuse
-
Add the Support for wireless debugging in ath9k driver (this will call debug.c).
Kernel modules / Wireless drivers / kmod-ath / Atheros wireless debugging
Note: This will set the flag
CONFIG_PACKAGE_ATH_DEBUG=y
in the.conf
file. -
Optional. In order to avoid that the image you are trying to build is too big for the device, we will remove some packages (note that we have selected these, but others could also be removed):
Network / odhcpd Network / odhcp6c
-
Remove the "CONFIG_USE_MIPS16=y" option. Uncheck the MIPS16 option:
Advanced config. options/ Target opt./ Build packages with MIPS16 instructions
-
Add the drivers for 802.11 devices. In our case, we are using ath9k in the main interface, and also in an extra wireless interface (TP-Link TL-WN722N). So you have to mark the driver:
Kernel modules / Wireless drivers / kmod-ath9k-htc
Note. Do not mark other drivers, as then OpenWrt may use them for the main wireless card instead of ath9k.
-
Save and exit from menuconfig. The changes will be written to
.config
.
Check the prerequisites
~/openwrt/trunk$ make prereq
In order to cross-compile a complete OpenWrt, run:
~/openwrt/trunk$ make
(This may take several minutes)
Note: If you want to use more threads, use make -j 4
(this is for 4 threads). Be careful, depending on the number of threads supported by your computer.
Note: If you want to see in detail what is going on, run $ make V=s
If you have added Openvswitch, you may obtain a message WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!
It is not important.
If your computer does not find any of the required packages, you can edit trunk/scripts/download.pl
, and add www.kernel.org
:
foreach my $dir (@extra) {
push @mirrors, "https://www.kernel.org/pub/$dir";
push @mirrors, "http://www.kernel.org/pub/$dir";
push @mirrors, "ftp://kernel.org/pub/$dir";
}
(...)
push @mirrors, 'http://mirror1.openwrt.org';
push @mirrors, 'http://mirror2.openwrt.org/sources';
push @mirrors, 'http://downloads.openwrt.org/sources';
push @mirrors, 'https://www.kernel.org/pub/linux/kernel/v3.x';
push @mirrors, 'http://www.kernel.org/pub/linux/kernel/v3.x';
You have to patch the debug.c
file. The idea is that you include some new functions there, in order to modify the mask that allows the AP to send the layer-2 ACKs. Odin makes use of the debugging tools for the drivers (https://wireless.wiki.kernel.org/en/users/drivers/ath9k/debug). It creates a file called /sys/kernel/debug/ieee80211/phy0/ath9k/bssid_extra
, where the mask is stored. The driver will use it in order to decide if a frame is targeted to it, and therefore send a layer-2 ACK.
Note. A device in monitor mode does not send layer-2 ACKs. Therefore, we will create an e.g. mon0
device in addition to the e.g. wlan0
, but both interfaces must be up.
The good one is this one (45324 bytes):
~/openwrt/trunk/build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ar71xx_generic/compat-wireless-2014-05-22/drivers/net/wireless/ath/ath9k/debug.c
The patch is here: https://github.com/Wi5/odin-wi5/blob/master/odin-patch-driver-ath9k/ath9k-bssid-mask.patch
-
Apply the patch with this command:
~/openwrt/trunk/build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ar71xx_generic/compat-wireless-2016-01-10/drivers/net/wireless/ath/ath9k$ patch debug.c < /home/intelnuc/openwrt_compile_environment/ath9k-bssid-mask.patch
You should see this result:
patching file debug.c
Hunk #1 succeeded at 862 with fuzz 2 (offset -125 lines).
Hunk #2 succeeded at 1601 (offset 17 lines).
Note. You may find some help in https://www.cyberciti.biz/faq/appy-patch-file-using-patch-command/
-
If it does not work, you can apply the patch manually (i.e. manually editing the file and adding the two hunks in their corresponding places.
-
Substitute the file
debug.c
by the patched one in this directory of the machine where you are compiling.~/openwrt/trunk/build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ar71xx_generic/compat-wireless-201x-yy-zz/drivers/net/wireless/ath/ath9k/
- Remove all the
.o
and.ko
files in the(...)/drivers/net/wireless/ath/ath9k
directory and do NOT runmake clean
.
*Also remove this .ko
file:
~/openwrt/trunk$ rm build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ar71xx_generic/compat-wireless-201x-yy-zz/ipkg-ar71xx/kmod-ath9k/lib/modules/3.18.tt/ath9k.ko
Now, you have to compile and build again. You will not have to compile everything, because you have NOT run make clean
. Only the things that have been changed will be recompiled:
~/openwrt/trunk$ make
If you have added Openvswitch, you may obtain a WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!
It is not important.
After the compilation, the directory ~/openwrt/trunk/bin/ar71xx
contains the .bin
files that can be flashed in the router:
-
TPLink1043:
openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin
-
Archer C5/C7:
openwrt-ar71xx-generic-archer-c7-v2-squashfs-sysupgrade.bin
Note: You may have some problems with the size of the .bin
files. In these cases, you will not obtain some of the .bin
files. You will then have to remove some packages (don't remove kmod-* packages).
Take a PC and add an Eth address 192.168.0.x. Connect it to one of the yellow Eth ports of the wireless router.
Open the web of the wireless router. In TPLink AC1750 Archer C7, it is 192.168.0.1
. (user: admin
, password: admin
).
Go to “System tools / firmware update” and select the .bin
file you have just built.
Once it installs OpenWrt, the router is rebooted.
The first time you log in, you must do it with Telnet (use Putty). Take the PC and modify the Eth address to 192.168.1.x
. Connect it to one of the yellow Eth ports of the wireless router.
Do just a Telnet to the default IP address of OpenWrt (it is 192.168.1.1
), and you will not be requested a password (http://wiki.openwrt.org/doc/howto/firstlogin).
Run root@OpenWrt:/# passwd
and set a password for root
.
Then, you will be able to use SSH, so disconnect and try with SSH.
Put the network card of your computer in DHCP mode.
Connect a wire from your computer to one of the Ethernet (black) ports of the Netgear router.
Open www.routerlogin.net in your browser. You will see the internal web page of the router.
Go to Advanced / Administration / Firmware Upgrade
Select the file openwrt-ar71xx-nand-r6100-ubi-factory.img, which you have to download to your computer.
After flashing it, you will be able to access the OpenWrt firmware in 192.168.1.1
Go to System Administration / Router Password
, and set a new password. Tick "Allow remote hosts to connect to local SSH forwarded ports". Save & Apply. Reboot the router.
(See http://wiki.openwrt.org/doc/howto/generic.sysupgrade).
Copy the file openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin
to the router.
Log in the router
$ ssh [email protected]
Run this command
$ sysupgrade openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin