Skip to content

Install on OpenWRT X86_64

Raizo62 edited this page Sep 6, 2021 · 39 revisions

Build libnl for OpenWRT

On cross-compiler

  • Install necessary packages for libnl

    sudo apt install bison flex
    sudo apt install gcc make
    
  • Create the working folder ~/OpenWRT

    mkdir ~/OpenWRT
    cd ~/OpenWRT
    

Download the SDK of OpenWRT

Download the code of libnl

  • The file is here : https://github.com/thom311/libnl

  • Download it

    wget https://github.com/thom311/libnl/releases/download/libnl3_5_0/libnl-3.5.0.tar.gz
    
  • Uncompress and rename it to ~/OpenWRT/libnlsrc

    tar xvf libnl-3.5.0.tar.gz
    mv libnl-3.5.0 libnlsrc
    

Compilation of libnl for OpenWRT

  • Go to the folder ~/OpenWRT/libnlsrc

    cd ~/OpenWRT/libnlsrc
    
  • Update PATH

    PATH=$PATH:"~/OpenWRT/SDK/staging_dir/toolchain-x86_64_gcc-7.5.0_musl/x86_64-openwrt-linux-musl/bin"
    export PATH
    
    STAGING_DIR="~/OpenWRT/SDK/staging_dir/toolchain-x86_64_gcc-7.5.0_musl/x86_64-openwrt-linux-musl/"
    export STAGING_DIR
    
  • Build

    ./configure --build=x86_64-unknown-linux-gnu  --host=x86_64-openwrt-linux-musl LDFLAGS="-static"
    make
    
  • Save necessary files in ~/OpenWRT/libnl

    mkdir ~/OpenWRT/libnl
    cp -R ~/OpenWRT/libnlsrc/include ~/OpenWRT/libnl
    cp -R ~/OpenWRT/libnlsrc/lib/.libs ~/OpenWRT/libnl/libs
    

Build vwifi for OpenWRT

On OpenWRT

Necessary files

  • Get the folder ~/OpenWRT/libnl from the cross-compiler and save it in /root/libnl of OpenWRT

  • Get the sources of vwifi and save it in /root/vwifi of OpenWRT

Necessary to build

  • Packages required to compile vwifi

    opkg update
    opkg install gcc make
    
  • For libpthread

    ar -rc /usr/lib/libpthread.a
    

Build

  • Go to the folder of vwifi : /root/vwifi

    cd /root/vwifi
    
  • Edit the file "Makefile" to modify the values of NETLINK_FLAGS and NETLINK_LIBS

    sed -i 's#^NETLINK_FLAGS.*#NETLINK_FLAGS=-I/root/libnl/include#g' /root/vwifi/Makefile
    sed -i 's#^NETLINK_LIBS.*#NETLINK_LIBS=-L/root/libnl/libs -lnl-genl-3 -lnl-3#g' /root/vwifi/Makefile
    
    • NETLINK_FLAGS = -I/root/libnl/include
    • NETLINK_LIBS = -L/root/libnl/libs -lnl-genl-3 -lnl-3
  • If you will not build vsock for OpenWRT, you can disable it in vwifi-client :

    sed -i 's$^#define ENABLE_VHOST$//#define ENABLE_VHOST$g' /root/vwifi/src/config.h
    
  • Build vwifi-client

    make directories
    make vwifi-client
    

Use vwifi on OpenWRT

Prerequisites

  • Package required to use : mac80211-hwsim

    opkg install kmod-mac80211-hwsim
    
  • Package required if vwifi has been compiled on other OpenWRT

    opkg install libstdcpp6
    

Run with command line

  • vwifi-client 172.16.0.1 with 172.16.0.1 the IP of vwifi-server

Run like a service

  • Copy vwifi-client into /usr/sbin

    cp vwifi-client /usr/sbin/
    
  • Create the service file : /etc/init.d/vwifi-client

    #!/bin/sh /etc/rc.common
    
    START=10
    STOP=15
    
    start() {        
            echo start vwifi-client
            vwifi-client 172.16.0.1 &> /dev/null &
    }                 
    
    stop() {          
            echo stop vwifi-client
            kill -9 $(pgrep vwifi-client) 
    }
    
    • Modify 172.16.0.1 with the IP of vwifi-server
  • Make /etc/init.d/vwifi-client executable

    chmod +x /etc/init.d/vwifi-client
    
  • Configure to run the service when OpenWRT boots

    service vwifi-client enable
    
  • Run the service

    service vwifi-client start
    

Test Wifi from OpenWRT

  • Don't forget to install "wpa-supplicant" and "hostapd"

    opkg install hostapd
    
    opkg install wpa-supplicant
    

Clone this wiki locally