Ubuntu系统下交叉编译hostapd

一、参考资料

non ht 和 ht mf 和 vht 和he su 都是什么-DPDK中文网

二、相关介绍

1. HT/VHT/HE模式

模式 参数 解释说明
HT (802.11n) ieee80211n=1 启用高吞吐模式 (HT)
ht_capab=[HT40+] 允许 40 MHz 宽带
VHT (802.11ac) ieee80211ac=1 启用 802.11ac 特性
vht_oper_chwidth=1 启用 80 MHz
vht_oper_centr_freq_seg0_idx=155 指定 80 MHz 中心频点
HE (802.11ax) ieee80211ax=1 启用 802.11ax
he_oper_chwidth=1 40/80 MHz HE 模式
he_oper_centr_freq_seg0_idx=155 同 VHT 中心频点
安全 wpa=2 WPA2-PSK
wpa_passphrase=12345678 密码

HT(High Throughput | 802.11n)

VHT(Very High Throughput | 802.11ac)

HE(High Efficiency | Wi-Fi 6/802.11ax)

2. 信道对应表

802.11n/ac (HT/VHT) 模式下,频宽与中心频率的关系是严格定义的。

以 5GHz 频段为例:

模式 实际信道 频宽vht_oper_chwidth 合法配置示例vht_oper_centr_freq_seg0_idx
20 MHz ch149 (5745 MHz) 20 MHz N/A
40 MHz ch149+ (次信道在上) 40 MHz center_seg0_idx = 151
40 MHz ch153- (次信道在下) 40 MHz center_seg0_idx = 151
80 MHz ch149~ch157 80 MHz center_seg0_idx = 155

5 GHz 80 MHz 配置组合:

主信道 (channel) 频率 (MHz) 80 MHz 中心信道 (vht_oper_centr_freq_seg0_idx)
36, 40, 44, 48 5180--5240 MHz 42
52, 56, 60, 64 5260--5320 MHz 58
100, 104, 108, 112 5500--5560 MHz 106
116, 120, 124, 128 5580--5640 MHz 122
132, 136, 140, 144 5660--5720 MHz 138
149, 153, 157, 161 5745--5805 MHz 155
165, 169, 173, 177 5825--5885 MHz 171

3. 常用配置

VHT_CAP_MAX_MPDU_LENGTH_MASK 对应于 最大 MPDU 长度能力,其值含义如下:

含义
0 3895 bytes
1 7991 bytes
2 11454 bytes
功能 正确配置
80 MHz VHT/HE 工作 channel=149, vht_oper_chwidth=1, he_oper_chwidth=2, *_centr_freq_seg0_idx=155
启用 802.11ax ieee80211ax=1
波束成形功能 he_su_beamformer=1, he_su_beamformee=1, he_mu_beamformer=1(若支持)

三、准备工作

1. 编译环境

  • 宿主机:Ubuntu 20.04.6 LTS
  • Host:ARM32位
  • 交叉编译器:arm-linux-gnueabihf-gcc-11.1.0

2. 设置交叉编译工具链

在交叉编译之前,需要设置交叉编译工具链的环境变量。

bash 复制代码
export PATH=/path/to/toolchains/arm-linux-gnueabihf/bin:$PATH

3. 准备依赖库

交叉编译openssl

详细步骤,请参考另一篇博客:Ubuntu系统下交叉编译openssl-CSDN博客

编译hostapd之前,需要设置pkg-config才能找到openssl。

bash 复制代码
export PKG_CONFIG_PATH=/media/sda3/360Downloads/openssl-openssl-3.5.0/arm32_install/lib/pkgconfig/:$PKG_CONFIG_PATH

交叉编译libnl

详细步骤,请参考另一篇博客:Ubuntu系统下交叉编译libnl

编译hostapd之前,需要设置pkg-config才能找到libnl。

bash 复制代码
export PKG_CONFIG_PATH=/media/sda3/360Downloads/libnl-3.2.25/arm32_install/lib/pkgconfig/:$PKG_CONFIG_PATH

四、交叉编译hostapd

1. 下载源码

Index of /releases

bash 复制代码
tar -xvzf hostapd-2.10.tar.gz
cd hostapd-2.10/hostapd

2. 创建config配置文件

创建并编辑config配置文件:

bash 复制代码
cp defconfig .config
vi .config

根据需求启用功能,常用配置示例:

bash 复制代码
# 启用 802.11ac/ax 支持(若驱动支持)
CONFIG_IEEE80211AC=y
CONFIG_IEEE80211AX=y

# 启用 Linux 驱动接口(nl80211)
CONFIG_DRIVER_NL80211=y

# 启用 OpenSSL 支持(若使用 WPA2/WPA3)
CONFIG_TLS=openssl

# 如果嵌入式系统空间有限,可关闭调试输出:
CONFIG_NO_STDOUT_DEBUG=y
CONFIG_NO_ACCOUNTING=y

# 指定交叉编译工具链
CC=/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc

# driver_nl80211.c requires libnl. If you are compiling it yourself
# you may need to point hostapd to your version of libnl.
#
CFLAGS += -I/media/sda3/360Downloads/libnl-3.2.25/arm32_install/include
LIBS += -L/media/sda3/360Downloads/libnl-3.2.25/arm32_install/lib

# 指定 OpenSSL 库路径(交叉编译环境下非常重要)
# 例如:
#   你的 openssl 交叉库路径:/opt/target/usr/lib
#   头文件路径:/opt/target/usr/include
CFLAGS += -I/media/sda3/360Downloads/openssl-openssl-3.5.0/arm32_install/include
LIBS += -L/media/sda3/360Downloads/openssl-openssl-3.5.0/arm32_install/lib

# Use libnl v2.0 (or 3.0) libraries.
CONFIG_LIBNL20=y

# Use libnl 3.2 libraries (if this is selected, CONFIG_LIBNL20 is ignored)
CONFIG_LIBNL32=y

3. 编译

bash 复制代码
make clean 
make

编译成功后,生成的文件为:

bash 复制代码
hostapd/hostapd
hostapd/hostapd_cli

4. 移植到开发板

将生成的二进制文件和配置文件复制到目标系统,例如:

bash 复制代码
cp hostapd/hostapd /usr/sbin/
cp hostapd/hostapd_cli /usr/sbin/
cp hostapd/hostapd.conf /etc/hostapd/

5. 运行测试

在目标设备上运行:

bash 复制代码
hostapd /etc/hostapd/hostapd.conf

如果出现如下输出表示启动成功:

bash 复制代码
Configuration file: /etc/hostapd/hostapd.conf
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
bash 复制代码
sudo hostapd -dd /etc/hostapd/hostapd.conf

使用 -dd 查看详细日志,确认能进入:

bash 复制代码
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED

6. hostapd配置文件

2.4G wifi:

复制代码
interface=wlan0
driver=nl80211
ssid=MyAP
hw_mode=g  # 2.4GHz
ieee80211n=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=12345678
rsn_pairwise=CCMP
wpa_pairwise=CCMP
channel=6

5G wifi:

bash 复制代码
interface=wlan0
ssid=MyAP
hw_mode=a
channel=36
ieee80211n=1
ht_capab=[HT40+][HT40-]
ieee80211ac=1
vht_oper_chwidth=2
vht_oper_centr_freq_seg0_idx=42
ieee80211ax=1
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
auth_algs=3
driver=nl80211
beacon_int=100

7. 相关日志

bash 复制代码
nl80211: 2380-2520 @ 40 MHz 20 mBm
nl80211: 5140-5980 @ 80 MHz 20 mBm
nl80211: Added 802.11b mode based on 802.11g information
nl80211: Mode IEEE 802.11g: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 2484
nl80211: Mode IEEE 802.11a: 5180 5200 5220 5240 5260 5280 5300 5320 5500 5520 5540 5560 5580 5600 5620 5640 5660 5680 5700 5720 5745 5765 5785 5805 5825
nl80211: Mode IEEE 802.11b: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 2484
Allowed channel: mode=1 chan=1 freq=2412 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=2 freq=2417 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=3 freq=2422 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=4 freq=2427 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=5 freq=2432 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=6 freq=2437 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=7 freq=2442 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=8 freq=2447 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=9 freq=2452 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=10 freq=2457 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=11 freq=2462 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=12 freq=2467 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=13 freq=2472 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=14 freq=2484 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=36 freq=5180 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=40 freq=5200 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=44 freq=5220 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=48 freq=5240 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=52 freq=5260 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=56 freq=5280 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=60 freq=5300 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=64 freq=5320 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=100 freq=5500 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=104 freq=5520 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=108 freq=5540 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=112 freq=5560 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=116 freq=5580 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=120 freq=5600 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=124 freq=5620 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=128 freq=5640 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=132 freq=5660 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=136 freq=5680 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=140 freq=5700 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=144 freq=5720 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=149 freq=5745 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=153 freq=5765 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=157 freq=5785 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=161 freq=5805 MHz max_tx_power=20 dBm
Allowed channel: mode=2 chan=165 freq=5825 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=1 freq=2412 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=2 freq=2417 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=3 freq=2422 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=4 freq=2427 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=5 freq=2432 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=6 freq=2437 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=7 freq=2442 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=8 freq=2447 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=9 freq=2452 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=10 freq=2457 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=11 freq=2462 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=12 freq=2467 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=13 freq=2472 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=14 freq=2484 MHz max_tx_power=20 dBm

五、FAQ

Q:configure: WARNING: bison not found. Please install before continuing.

Linux libnl 移植记录 - Jalyn - 博客园

bash 复制代码
configure: WARNING: bison not found. Please install before continuing.
configure: WARNING: flex not found. Please install before continuing.
configure: error: Required packages are missing. Please install them and rerun ./configure

解决方法 :安装 bisonflex

bash 复制代码
sudo apt-get install bison
sudo apt-get install flex

Q:Driver does not support configured VHT capability [VHT_CAP_TXSTBC]

错误原因

STBC(Space Time Block Coding)是一种多天线增强技术:

  • TX-STBC (Transmit STBC)要求设备具有 多个发射天线(Tx ≥ 2)
  • RX-STBC(Receive STBC)则只要求多个接收天线(Rx ≥ 2)

很多 USB / 嵌入式 Wi-Fi 芯片(尤其单天线设备)只支持 RX-STBC 或完全不支持 STBC。所以,当你在配置中启用了 [TX-STBC][TX-STBC-2BY1] 时,驱动会拒绝。

解决方法 :删除 [VHT_CAP_TXSTBC]

Q:Driver does not support configured VHT capability [VHT_CAP_SU_BEAMFORMER_CAPABLE]

解决方法 :删除 [SU-BEAMFORMEE]

Q:Driver does not support configured VHT capability [VHT_CAP_HTC_VHT]

解决方法 :删除 [HTC-VHT]

Q:Driver does not support configured HT capability [TX-STBC]

解决方法 :删除 [TX-STBC]

Q:Driver does not support configured HE capability

解决方法:注释以下配置项目。

bash 复制代码
# he_su_beamformer=1
# he_su_beamformee=1
# he_mu_beamformer=1

Q:DFS chan_idx seems wrong Could not set channel for kernel driver

bash 复制代码
DFS chan_idx seems wrong
Could not set channel for kernel driver

错误原因:国家码不符或未设置。

解决方法:请务必使用与你区域匹配的国家码(如 US、JP、EU)。

Q:80/80+80 MHz: no second channel offset Could not set channel for kernel driver

bash 复制代码
hw vht capab: 0x3987131, conf vht capab: 0x0
Completing interface initialization
Mode: IEEE 802.11a  Channel: 149  Frequency: 5745 MHz
DFS 0 channels required radar detection
80/80+80 MHz: no second channel offset
Could not set channel for kernel driver
Interface initialization failed
wlan0: interface state COUNTRY_UPDATE->DISABLED
wlan0: AP-DISABLED
相关推荐
花花少年5 天前
Ubuntu系统下交叉编译libsbc
交叉编译·libsbc
再遇当年11 天前
因为研究平台arm,RK3588交叉编译误把我笔记本X86平台的/x86_64-linux-gnu文件删除,导致联想拯救者笔记本中的ubuntu系统损坏
linux·arm开发·ros·gnu·交叉编译·x86
青云交24 天前
深度实战:Rust交叉编译适配OpenHarmony PC——ansi_term完整适配案例
rust·交叉编译·命令行工具·openharmony pc·ansi_term·适配案例·终端颜色
IT阳晨。2 个月前
【QT开发】交叉编译QT程序在ARMLinux平台上运行
c++·qt·交叉编译·armlinux·代码移植
YouEmbedded2 个月前
ARM开发板基础与文件传输
arm开发·vscode·交叉编译·mobaxterm
肖恭伟3 个月前
Qt Linux交叉编译字节数目不一样
交叉编译·long·32位·64位·字节长度·ulong·字节数目
NoirSeeker5 个月前
在windows平台上基于OpenHarmony sdk编译三方库并暴露给ArkTS使用(详细)
c++·windows·arkts·鸿蒙·交叉编译
花花少年7 个月前
Ubuntu系统下交叉编译openssl
openssl·交叉编译
有时有晌7 个月前
Qt 相关 编译流程及交叉编译 部署所遇到的问题总结-持续更新
qt·交叉编译·远端部署