From 3913f138cfc22ae70305bd3f0500ceba7ce2914a Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 21 Jun 2024 13:03:38 +0200 Subject: [PATCH] vwifi: add package Signed-off-by: Jo-Philipp Wich --- package/network/utils/vwifi/Makefile | 65 +++++++++++++++++ package/network/utils/vwifi/files/vwifi.init | 69 +++++++++++++++++++ .../vwifi/patches/100-compile-fixes.patch | 43 ++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 package/network/utils/vwifi/Makefile create mode 100755 package/network/utils/vwifi/files/vwifi.init create mode 100644 package/network/utils/vwifi/patches/100-compile-fixes.patch diff --git a/package/network/utils/vwifi/Makefile b/package/network/utils/vwifi/Makefile new file mode 100644 index 0000000000..e28bf192a0 --- /dev/null +++ b/package/network/utils/vwifi/Makefile @@ -0,0 +1,65 @@ +# +# Copyright (C) 2012 Jo-Philipp Wich +# +# This is free software, licensed under the Apache 2 license. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=vwifi +PKG_RELEASE:=1 + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://github.com/Raizo62/vwifi.git +PKG_SOURCE_DATE:=2023-12-31 +PKG_SOURCE_VERSION:=e0019422225aa11fcc5e435ccda39f3486f590ed +PKG_MIRROR_HASH:=880259f7fd0b105cee1dae693602d904c7daed08dc45aaca38a93a29b0a839d1 +PKG_MAINTAINER:=Jo-Philipp Wich + +PKG_LICENSE:=LGPL-3.0-only +PKG_LICENSE_FILES:=LICENSE.md + +include $(INCLUDE_DIR)/package.mk + + +define Package/vwifi + SECTION:=utils + CATEGORY:=Utilities + TITLE:=Wi-Fi protocol simulation + DEPENDS:=+libstdcpp +libnl-tiny +kmod-virtio-vsockets +endef + +define Package/vwifi/description + Simulate Wi-Fi (802.11) between Linux Virtual Machines. + + The vwifi utilities can be used in Hypervisors such as GNS3, QEMU, + VirtualBox, VMware, Hyper-V etc. to simulate 802.11 traffic between + different virtual machines. + + The utilities use the mac80211_hwsim driver to provide simulated + virtual wireless devices to Linux systems and transport the 802.11 + frames via TCP connections across different machines. +endef + + +MAKE_VARS += \ + NETLINK_FLAGS="-I$(STAGING_DIR)/usr/include/libnl-tiny -DNL_AUTO_PORT=0 -Dnl_send_auto=nl_send_auto_complete" \ + NETLINK_LIBS="-lnl-tiny" + +define Build/Configure + $(INSTALL_DIR) $(PKG_BUILD_DIR)/src/netlink/route + touch $(PKG_BUILD_DIR)/src/netlink/route/link.h +endef + +define Package/vwifi/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/vwifi-add-interfaces $(1)/usr/sbin/vwifi-add-interfaces + $(INSTALL_BIN) $(PKG_BUILD_DIR)/vwifi-client $(1)/usr/sbin/vwifi-client + $(INSTALL_BIN) $(PKG_BUILD_DIR)/vwifi-ctrl $(1)/usr/sbin/vwifi-ctrl + $(INSTALL_BIN) $(PKG_BUILD_DIR)/vwifi-server $(1)/usr/sbin/vwifi-server + + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/vwifi.init $(1)/etc/init.d/vwifi +endef + +$(eval $(call BuildPackage,vwifi)) diff --git a/package/network/utils/vwifi/files/vwifi.init b/package/network/utils/vwifi/files/vwifi.init new file mode 100755 index 0000000000..e3a4676493 --- /dev/null +++ b/package/network/utils/vwifi/files/vwifi.init @@ -0,0 +1,69 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2024 Jo-Philipp Wich + +START=90 + +USE_PROCD=1 + +VWIFI_CLIENT_BIN="/usr/sbin/vwifi-client" + +delete_iface() { + local cfg=$1 + local radio=$2 + local device + + config_get device "$cfg" device + + [ "$device" != "$radio" ] || { + uci delete "wireless.$cfg" + } +} + +delete_device() { + local cfg=$1 + local path + + config_get path "$cfg" path + + case "$path" in virtual/mac80211_hwsim/*) + config_foreach delete_iface wifi-iface "$cfg" + uci delete "wireless.$cfg" + ;; esac +} + +fixup_config() { + . /lib/functions.sh + + config_load wireless + config_foreach delete_device wifi-device + + [ -z "$(uci changes wireless)" ] || uci commit wireless +} + +fixup_hwsim() { + local num_radios=$(cat /sys/module/mac80211_hwsim/parameters/radios 2>/dev/null) + + [ -n "$num_radios" ] || { + echo "vwifi-client: mac80211_hwsim module is not loaded, aborting!" >&2 + exit 1 + } + + [ $num_radios = 0 ] || { + echo "vwifi-client: reloading mac80211_hwsim module without default radios" >&2 + rmmod mac80211_hwsim + insmod mac80211_hwsim radios=0 + + fixup_config + } +} + +start_service() { + fixup_hwsim + + procd_open_instance + procd_set_param respawn + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param command $VWIFI_CLIENT_BIN + procd_close_instance +} diff --git a/package/network/utils/vwifi/patches/100-compile-fixes.patch b/package/network/utils/vwifi/patches/100-compile-fixes.patch new file mode 100644 index 0000000000..7bb43dc380 --- /dev/null +++ b/package/network/utils/vwifi/patches/100-compile-fixes.patch @@ -0,0 +1,43 @@ +--- a/Makefile ++++ b/Makefile +@@ -24,9 +24,9 @@ MODE+= -O3 -s -Wall -Wextra -pedantic # + EDITOR ?= geany + + NETLINK_FLAGS_PATH := /usr/include/libnl3 +-NETLINK_FLAGS := -I $(NETLINK_FLAGS_PATH) ++NETLINK_FLAGS ?= -I $(NETLINK_FLAGS_PATH) + NETLINK_LIBS_PATH := . +-NETLINK_LIBS := -L $(NETLINK_LIBS_PATH) -lnl-genl-3 -lnl-3 ++NETLINK_LIBS ?= -L $(NETLINK_LIBS_PATH) -lnl-genl-3 -lnl-3 + + THREAD_LIBS := -lpthread + +--- a/src/cmonwirelessdevice.cc ++++ b/src/cmonwirelessdevice.cc +@@ -20,7 +20,6 @@ + #include + #include + #include +-#include + + #include + +@@ -207,7 +206,7 @@ void MonitorWirelessDevice::recv_inet_ev + char buf[IFLIST_REPLY_BUFFER]; + struct iovec iov = { buf, sizeof(buf) }; + struct sockaddr_nl snl; +- struct msghdr msg = { (void *)&snl, sizeof(snl), &iov, 1, NULL, 0, 0 }; ++ struct msghdr msg = { (void *)&snl, sizeof(snl), &iov, 1, 0, 0, 0 }; + struct nlmsghdr *nlmsgheader; + + /* read the waiting message */ +--- a/src/ckernelwifi.cc ++++ b/src/ckernelwifi.cc +@@ -5,7 +5,6 @@ + #include + #include + #include +-#include + + #include + #include -- 2.30.2