Skip to content

Install on OpenWRT X86_64

David Ansart edited this page Aug 28, 2024 · 34 revisions

Build vwifi for OpenWRT

  • On cross-compiler

  • Install necessary packages for libnl :

    sudo apt install --yes make bison flex
    
  • Create the working folder ${HOME}/OpenWRT :

    mkdir ${HOME}/OpenWRT
    cd ${HOME}/OpenWRT
    

OpenWRT

Download the SDK of OpenWRT

Download the Toolchain of OpenWRT

  • Download it :

    wget https://downloads.openwrt.org/releases/23.05.4/targets/x86/64/openwrt-toolchain-23.05.4-x86-64_gcc-12.3.0_musl.Linux-x86_64.tar.xz
    
  • Uncompress and rename it to ${HOME}/OpenWRT/TOOLCHAIN :

    tar xvf openwrt-toolchain-23.05.4-x86-64_gcc-12.3.0_musl.Linux-x86_64.tar.xz
    mv openwrt-toolchain-23.05.4-x86-64_gcc-12.3.0_musl.Linux-x86_64 TOOLCHAIN
    
  • Update PATH :

    PATH=$PATH:"${HOME}/OpenWRT/TOOLCHAIN/toolchain-x86_64_gcc-12.3.0_musl/bin"
    
    export STAGING_DIR="/tmp"
    

LibNL

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_10_0/libnl-3.10.0.tar.gz
    
  • Uncompress and rename it to ${HOME}/OpenWRT/libnlsrc :

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

Compilation of libnl for OpenWRT

  • Go to the folder ${HOME}/OpenWRT/libnlsrc :

    cd ${HOME}/OpenWRT/libnlsrc
    
  • Build :

    ./configure --build=x86_64-unknown-linux-gnu  --host=x86_64-openwrt-linux-musl LDFLAGS="-static"
    make
    
  • Link necessary files in ${HOME}/OpenWRT/LIBNL :

    mkdir ${HOME}/OpenWRT/LIBNL
    ln -s ${HOME}/OpenWRT/libnlsrc/include ${HOME}/OpenWRT/LIBNL/include
    ln -s ${HOME}/OpenWRT/libnlsrc/lib/.libs ${HOME}/OpenWRT/LIBNL/libs
    

VWifi

Download the code of vwifi

  • Download it :

    cd ${HOME}/OpenWRT/
    wget https://github.com/Raizo62/vwifi/archive/refs/heads/master.zip
    
  • Uncompress and rename it to ${HOME}/OpenWRT/vwifi :

    unzip master.zip
    mv vwifi-master vwifi
    cd vwifi
    
  • Edit the file "Makefile" to update the values of NETLINK_FLAGS and NETLINK_LIBS :

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

    sed -i 's$^#define ENABLE_VHOST$//#define ENABLE_VHOST$g' ${HOME}/OpenWRT/vwifi/src/config.h
    
  • Apply an ugly patch to the call of "struct msghdr msg" in the file src/cmonwirelessdevice.cc :

    sed -i 's$1, NULL, 0,$1, 0, 0, 0, 0,$' ${HOME}/OpenWRT/vwifi/src/cmonwirelessdevice.cc
    
  • Build vwifi-client :

    make directories
    make vwifi-client CXX=x86_64-openwrt-linux-musl-g++ LD=x86_64-openwrt-linux-musl-ld
    
  • Copy vwifi-client on OpenWRT, in the folder /usr/sbin/ :

    scp vwifi-client [email protected]:/usr/sbin/
    

On OpenWRT

Prerequisites

mac80211-hwsim

  • Install le package kmod-mac80211-hwsim :

    opkg update
    opkg install kmod-mac80211-hwsim
    
  • Unload it and set the default number of radios to 0 :

    rmmod mac80211-hwsim
    echo 'mac80211_hwsim radios=0' > /etc/modules.d/mac80211-hwsim
    
  • Reboot Openwrt :

    reboot
    
  • Delete the configurations generated by OpenWRT for the radios created by the install of kmod-mac80211-hwsim :

    uci delete wireless.radio0
    uci delete wireless.default_radio0
    uci delete wireless.radio1
    uci delete wireless.default_radio1
    uci commit wireless
    

libstdcpp6

  • Package required because vwifi is C++ :

    opkg install libstdcpp6
    

Run with command line

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

Run like a service

  • 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 --number 2 --mac '74:f8:f6:66' &> /dev/null &
    }                 
    
    stop() {          
            echo stop vwifi-client
            kill -9 $(pgrep vwifi-client) 
    }
    
    • Modify 172.16.0.1 to 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