mac80211 compat layer for OpenWrt

Message ID 1674394.xTpvsLY2Zu@sven-edge (mailing list archive)
State RFC, archived
Headers

Commit Message

Sven Eckelmann Feb. 11, 2016, 10:25 p.m. UTC
  Hi,

it looks like the next version (with B.A.T.M.A.N. V support and cfg80211 
dependency) has to be build against the mac80211 compat version. OpenWrt right 
now uses Linux 3.18, 4.1, 4.3 and 4.4. These kernel versions don't require 
many changes (which are not already part of the compat layer) to get batman-
adv building against it. But most of the required changes are rather ugly (see
batman-adv/patches/0000-compat-hacks.patch). But at least it builds with them.

I have the basic changes for openwrt-routing attached. Maybe someone has some 
visions how to continue from here.

I've also attached the patch to build the current state of B.A.T.M.A.N. V on 
OpenWrt.

Kind regards,
	Sven
  

Patch

From: Sven Eckelmann <sven@narfation.org>
Date: Thu, 21 Jan 2016 16:04:20 +0100
Subject: [PATCH] batman-adv: Use the mac80211 compat layer
---
 batman-adv/Makefile                        | 40 +++++++++++++++++---------
 batman-adv/patches/0000-compat-hacks.patch | 46 ++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 14 deletions(-)
 create mode 100644 batman-adv/patches/0000-compat-hacks.patch

diff --git a/batman-adv/Makefile b/batman-adv/Makefile
index 1eb6bbe..6e24d4d 100644
--- a/batman-adv/Makefile
+++ b/batman-adv/Makefile
@@ -27,7 +27,7 @@  define KernelPackage/batman-adv
   URL:=https://www.open-mesh.org/
   MAINTAINER:=Marek Lindner <mareklindner@neomailbox.ch>
   SUBMENU:=Network Support
-  DEPENDS:=+KMOD_BATMAN_ADV_BLA:kmod-lib-crc16 +kmod-crypto-core +kmod-crypto-crc32c +kmod-lib-crc32c
+  DEPENDS:=+KMOD_BATMAN_ADV_BLA:kmod-lib-crc16 +kmod-crypto-core +kmod-crypto-crc32c +kmod-lib-crc32c +kmod-cfg80211
   TITLE:=B.A.T.M.A.N. Adv
   FILES:=$(PKG_BUILD_DIR)/net/batman-adv/batman-adv.$(LINUX_KMOD_SUFFIX)
   AUTOLOAD:=$(call AutoLoad,50,batman-adv)
@@ -47,20 +47,36 @@  define Package/kmod-batman-adv/conffiles
 /etc/config/batman-adv
 endef
 
-MAKE_BATMAN_ADV_ARGS += \
-	CROSS_COMPILE="$(TARGET_CROSS)" \
-	KERNELPATH="$(LINUX_DIR)" \
-	ARCH="$(LINUX_KARCH)" \
-	PATH="$(TARGET_PATH)" \
-	SUBDIRS="$(PKG_BUILD_DIR)" \
-	PWD="$(PKG_BUILD_DIR)" \
-	LINUX_VERSION="$(LINUX_VERSION)" \
+PKG_EXTRA_KCONFIG:= \
+	CONFIG_BATMAN_ADV=m \
 	CONFIG_BATMAN_ADV_DEBUG=$(if $(CONFIG_KMOD_BATMAN_ADV_DEBUG_LOG),y,n) \
 	CONFIG_BATMAN_ADV_BLA=$(if $(CONFIG_KMOD_BATMAN_ADV_BLA),y,n) \
 	CONFIG_BATMAN_ADV_DAT=$(if $(CONFIG_KMOD_BATMAN_ADV_DAT),y,n) \
 	CONFIG_BATMAN_ADV_MCAST=$(if $(CONFIG_KMOD_BATMAN_ADV_MCAST),y,n) \
 	CONFIG_BATMAN_ADV_NC=$(if $(CONFIG_KMOD_BATMAN_ADV_NC),y,n) \
-	REVISION="" all
+
+PKG_EXTRA_CFLAGS:= \
+	$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(PKG_EXTRA_KCONFIG)))) \
+	$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(PKG_EXTRA_KCONFIG)))) \
+
+NOSTDINC_FLAGS = \
+	-I$(PKG_BUILD_DIR)/net/batman-adv \
+	-I$(STAGING_DIR)/usr/include/mac80211-backport/uapi \
+	-I$(STAGING_DIR)/usr/include/mac80211-backport \
+	-I$(STAGING_DIR)/usr/include/mac80211/uapi \
+	-I$(STAGING_DIR)/usr/include/mac80211 \
+	-include backport/backport.h
+
+define Build/Compile
+	+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
+		ARCH="$(LINUX_KARCH)" \
+		CROSS_COMPILE="$(TARGET_CROSS)" \
+		SUBDIRS="$(PKG_BUILD_DIR)/net/batman-adv" \
+		$(PKG_EXTRA_KCONFIG) \
+		EXTRA_CFLAGS="$(PKG_EXTRA_CFLAGS)" \
+		NOSTDINC_FLAGS="$(NOSTDINC_FLAGS)" \
+		modules
+endef
 
 define Build/Prepare
 	$(call Build/Prepare/Default)
@@ -68,10 +84,6 @@  define Build/Prepare
 		$(PKG_BUILD_DIR)/net/batman-adv/main.h
 endef
 
-define Build/Compile
-	$(MAKE) -C "$(PKG_BUILD_DIR)" $(MAKE_BATMAN_ADV_ARGS)
-endef
-
 define Build/Clean
         rm -rf $(BUILD_DIR)/$(PKG_NAME)/
 endef
diff --git a/batman-adv/patches/0000-compat-hacks.patch b/batman-adv/patches/0000-compat-hacks.patch
new file mode 100644
index 0000000..78bdc51
--- /dev/null
+++ b/batman-adv/patches/0000-compat-hacks.patch
@@ -0,0 +1,46 @@ 
+diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
+index 730cfa8..39e5694 100644
+--- a/net/batman-adv/hard-interface.c
++++ b/net/batman-adv/hard-interface.c
+@@ -47,6 +47,24 @@
+ #include "sysfs.h"
+ #include "translation-table.h"
+ 
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)
++
++#define dev_get_iflink(_net_dev) ((_net_dev)->iflink)
++
++#endif /* < KERNEL_VERSION(4, 1, 0) */
++
++#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
++
++#define netdev_master_upper_dev_link(dev, upper_dev, upper_priv, upper_info) \
++	netdev_set_master(dev, upper_dev)
++
++#elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
++
++#define netdev_master_upper_dev_link(dev, upper_dev, upper_priv, upper_info) \
++	netdev_master_upper_dev_link(dev, upper_dev)
++
++#endif /* < KERNEL_VERSION(4, 5, 0) */
++
+ /**
+  * batadv_hardif_release - release hard interface from lists and queue for
+  *  free after rcu grace period
+diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
+index 6c65de9..06d0330 100644
+--- a/net/batman-adv/soft-interface.c
++++ b/net/batman-adv/soft-interface.c
+@@ -60,6 +60,12 @@
+ #include "sysfs.h"
+ #include "translation-table.h"
+ 
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
++
++#define IFF_NO_QUEUE	0; dev->tx_queue_len = 0
++
++#endif /* < KERNEL_VERSION(4, 3, 0) */
++
+ static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
+ static void batadv_get_drvinfo(struct net_device *dev,
+ 			       struct ethtool_drvinfo *info);