下载kernel
wget http://mirrors.163.com/kernel/v6.x/linux-6.0.9.tar.xz
解压kernel
tar -Jxvf linux-6.0.9.tar.xz
mac80211_hwsim.ko编译
mkdir mac80211_hwsim
cd mac80211_hwsim
cp linux-6.0.9/drivers/net/wireless/mac80211_hwsim.c mac80211_hwsim/
cp linux-6.0.9/drivers/net/wireless/mac80211_hwsim.h mac80211_hwsim/
在mac80211_hwsim
目录下新建Makefile文件,添加如下内容
KERNEL_VERSION = $(shell uname -r)
obj-m += mac80211_hwsim.o
build: kernel_modules
kernel_modules:
make -C /lib/modules/$(KERNEL_VERSION)/build M=$(CURDIR) modules
clean:
make -C /lib/modules/$(KERNEL_VERSION)/build M=$(CURDIR) clean
执行make
命令
make
libarc4.ko编译
mkdir lib_crypto
cp linux-6.0.9/lib/crypto/* lib_crypto/.
cd lib_crypto/
修改其中的Makefile,如下
# SPDX-License-Identifier: GPL-2.0
KERNEL_VERSION = $(shell uname -r)
# chacha is used by the /dev/random driver which is always builtin
obj-y += chacha.o
obj-$(CONFIG_CRYPTO_LIB_CHACHA_GENERIC) += libchacha.o
obj-$(CONFIG_CRYPTO_LIB_AES) += libaes.o
libaes-y := aes.o
obj-$(CONFIG_CRYPTO_LIB_ARC4) += libarc4.o
libarc4-y := arc4.o
# blake2s is used by the /dev/random driver which is always builtin
obj-y += libblake2s.o
libblake2s-y := blake2s.o
libblake2s-$(CONFIG_CRYPTO_LIB_BLAKE2S_GENERIC) += blake2s-generic.o
obj-$(CONFIG_CRYPTO_LIB_CHACHA20POLY1305) += libchacha20poly1305.o
libchacha20poly1305-y += chacha20poly1305.o
obj-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC) += libcurve25519-generic.o
libcurve25519-generic-y := curve25519-fiat32.o
libcurve25519-generic-$(CONFIG_ARCH_SUPPORTS_INT128) := curve25519-hacl64.o
libcurve25519-generic-y += curve25519-generic.o
obj-$(CONFIG_CRYPTO_LIB_CURVE25519) += libcurve25519.o
libcurve25519-y += curve25519.o
obj-$(CONFIG_CRYPTO_LIB_DES) += libdes.o
libdes-y := des.o
obj-$(CONFIG_CRYPTO_LIB_POLY1305_GENERIC) += libpoly1305.o
libpoly1305-y := poly1305-donna32.o
libpoly1305-$(CONFIG_ARCH_SUPPORTS_INT128) := poly1305-donna64.o
libpoly1305-y += poly1305.o
obj-$(CONFIG_CRYPTO_LIB_SHA1) += libsha1.o
libsha1-y := sha1.o
obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
libsha256-y := sha256.o
ifneq ($(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS),y)
libblake2s-y += blake2s-selftest.o
libchacha20poly1305-y += chacha20poly1305-selftest.o
libcurve25519-y += curve25519-selftest.o
endif
build: kernel_modules
kernel_modules:
make -C /lib/modules/$(KERNEL_VERSION)/build M=$(CURDIR) modules
clean:
make -C /lib/modules/$(KERNEL_VERSION)/build M=$(CURDIR) clean
执行make
命令即可
w512@w512-pc:~/wlan_test/lib_crypto$ make
w512@w512-pc:~/wlan_test/lib_crypto$ ls *.ko -alh
-rw-rw-r-- 1 w512 w512 110K 11月 26 22:16 libarc4.ko
-rw-rw-r-- 1 w512 w512 324K 11月 26 22:16 libchacha20poly1305.ko
-rw-rw-r-- 1 w512 w512 109K 11月 26 22:16 libchacha.ko
-rw-rw-r-- 1 w512 w512 631K 11月 26 22:16 libcurve25519-generic.ko
-rw-rw-r-- 1 w512 w512 105K 11月 26 22:16 libcurve25519.ko
-rw-rw-r-- 1 w512 w512 215K 11月 26 22:16 libdes.ko
-rw-rw-r-- 1 w512 w512 143K 11月 26 22:16 libpoly1305.ko
cfg80211.ko编译
mkdir cfg80211
cp -r linux-6.0.9/net/wireless/* cfg80211/
cd cfg80211/
修改其中的Makefile,如下
# SPDX-License-Identifier: GPL-2.0
KERNEL_VERSION = $(shell uname -r)
obj-$(CONFIG_CFG80211) += cfg80211.o
obj-$(CONFIG_LIB80211) += lib80211.o
obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib80211_crypt_wep.o
obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o
obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o
obj-$(CONFIG_WEXT_CORE) += wext-core.o
obj-$(CONFIG_WEXT_PROC) += wext-proc.o
obj-$(CONFIG_WEXT_SPY) += wext-spy.o
obj-$(CONFIG_WEXT_PRIV) += wext-priv.o
cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o
cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o mesh.o ap.o trace.o ocb.o
cfg80211-y += pmsr.o
cfg80211-$(CONFIG_OF) += of.o
cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o
cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o
CFLAGS_trace.o := -I$(src)
cfg80211-$(CONFIG_CFG80211_USE_KERNEL_REGDB_KEYS) += shipped-certs.o
ifneq ($(CONFIG_CFG80211_EXTRA_REGDB_KEYDIR),)
cfg80211-y += extra-certs.o
endif
build: kernel_modules
$(obj)/shipped-certs.c: $(wildcard $(srctree)/$(src)/certs/*.hex)
@$(kecho) " GEN $@"
$(Q)(echo '#include "reg.h"'; \
echo 'const u8 shipped_regdb_certs[] = {'; \
echo | cat - $^ ; \
echo '};'; \
echo 'unsigned int shipped_regdb_certs_len = sizeof(shipped_regdb_certs);'; \
) > $@
$(obj)/extra-certs.c: $(CONFIG_CFG80211_EXTRA_REGDB_KEYDIR) \
$(wildcard $(CONFIG_CFG80211_EXTRA_REGDB_KEYDIR)/*.x509)
@$(kecho) " GEN $@"
$(Q)(set -e; \
allf=""; \
for f in $^ ; do \
test -f $$f || continue;\
# similar to hexdump -v -e '1/1 "0x%.2x," "\n"' \
thisf=$$(od -An -v -tx1 < $$f | \
sed -e 's/ /\n/g' | \
sed -e 's/^[0-9a-f]\+$$/\0/;t;d' | \
sed -e 's/^/0x/;s/$$/,/'); \
# file should not be empty - maybe command substitution failed? \
test ! -z "$$thisf";\
allf=$$allf$$thisf;\
done; \
( \
echo '#include "reg.h"'; \
echo 'const u8 extra_regdb_certs[] = {'; \
echo "$$allf"; \
echo '};'; \
echo 'unsigned int extra_regdb_certs_len = sizeof(extra_regdb_certs);'; \
) > $@)
clean-files += shipped-certs.c extra-certs.c
kernel_modules:
make -C /lib/modules/$(KERNEL_VERSION)/build M=$(CURDIR) modules
clean:
make -C /lib/modules/$(KERNEL_VERSION)/build M=$(CURDIR) clean
执行make
命令即可
w512@w512-pc:~/wlan_test/lib_crypto$ make
w512@w512-pc:~/wlan_test/cfg80211$ ls *.ko -alh
-rw-rw-r-- 1 w512 w512 18M 11月 26 22:37 cfg80211.ko
-rw-rw-r-- 1 w512 w512 422K 11月 26 22:37 lib80211_crypt_ccmp.ko
-rw-rw-r-- 1 w512 w512 448K 11月 26 22:37 lib80211_crypt_tkip.ko
-rw-rw-r-- 1 w512 w512 385K 11月 26 22:37 lib80211_crypt_wep.ko
-rw-rw-r-- 1 w512 w512 397K 11月 26 22:37 lib80211.ko
mac80211.ko编译
mkdir cfg80211
cp -r linux-6.0.9/net/wireless/* cfg80211/
cd cfg80211/
修改其中的Makefile,如下
# SPDX-License-Identifier: GPL-2.0
KERNEL_VERSION = $(shell uname -r)
obj-$(CONFIG_MAC80211) += mac80211.o
# mac80211 objects
mac80211-y := \
main.o status.o \
driver-ops.o \
sta_info.o \
wep.o \
aead_api.o \
wpa.o \
scan.o offchannel.o \
ht.o agg-tx.o agg-rx.o \
vht.o \
he.o \
s1g.o \
ibss.o \
iface.o \
rate.o \
michael.o \
tkip.o \
aes_cmac.o \
aes_gmac.o \
fils_aead.o \
cfg.o \
ethtool.o \
rx.o \
spectmgmt.o \
tx.o \
key.o \
util.o \
wme.o \
chan.o \
trace.o mlme.o \
tdls.o \
ocb.o \
airtime.o \
eht.o
mac80211-$(CONFIG_MAC80211_LEDS) += led.o
mac80211-$(CONFIG_MAC80211_DEBUGFS) += \
debugfs.o \
debugfs_sta.o \
debugfs_netdev.o \
debugfs_key.o
mac80211-$(CONFIG_MAC80211_MESH) += \
mesh.o \
mesh_pathtbl.o \
mesh_plink.o \
mesh_hwmp.o \
mesh_sync.o \
mesh_ps.o
mac80211-$(CONFIG_PM) += pm.o
CFLAGS_trace.o := -I$(src)
rc80211_minstrel-y := \
rc80211_minstrel_ht.o
rc80211_minstrel-$(CONFIG_MAC80211_DEBUGFS) += \
rc80211_minstrel_ht_debugfs.o
mac80211-$(CONFIG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
ccflags-y += -DDEBUG
build: kernel_modules
kernel_modules:
make -C /lib/modules/$(KERNEL_VERSION)/build M=$(CURDIR) modules
clean:
make -C /lib/modules/$(KERNEL_VERSION)/build M=$(CURDIR) clean
执行make
命令即可
w512@w512-pc:~/wlan_test/lib_crypto$ make
w512@w512-pc:~/wlan_test/cfg80211$ ls *.ko -alh
-rw-rw-r-- 1 w512 w512 36M 11月 26 22:44 mac80211.ko
ko安装
由于mac80211_hwsim.ko
依赖mac80211.ko, cfg80211.ko
和libarc.ko
, 因此insmod相关的ko的脚本ko_install.sh
如下
# /bin/bash
# insmod libarc4.ko
sudo insmod lib_crypto/libarc4.ko
# insmod cfg80211.ko
sudo insmod cfg80211/cfg80211.ko
# insmod mac80211.ko
sudo insmod mac80211/mac80211.ko
# insmod mac80211_hwsim.ko
sudo insmod mac80211_hwsim/mac80211_hwsim.ko radios=2
通过如下命令执行安装
chmod +x ko_install.sh
./ko_install.sh