概述
文章目录
- 交叉编译
- 使用 hostapd
- 使用 DHCP 分配 IP
- 查看状态
- 开机自启动
- 1. MDEV 配置文件
- 2. MDEV 执行的脚本
- 参考链接
交叉编译
tar xzf hostapd-2.0.tar.gz
cd hostapd-2.0/hostapd
cp defconfig .config
vim Makefile
{
CC=arm-linux-gcc
}
错误
…/src/drivers/driver_nl80211.c:19:31: fatal error: netlink/genl/genl.h: No such file or directory
在我的编译器库头文件中明明有这个路径和这个文件却找不到
vim Makefile
在第 6 行添加 --verbose 选项打印 gcc 编译信息
CFLAGS = -MMD -O2 -Wall -g --verbose
得到输出:
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
../src
../src/utils
/usr/lib/gcc/x86_64-linux-gnu/5/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C11 (Ubuntu 5.4.0-6ubuntu1~16.04.12) version 5.4.0 20160609 (x86_64-linux-gnu)
compiled by GNU C version 5.4.0 20160609, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
原来是在用gcc编译,可是我明明修改了 Makefile 为 arm-linux-gcc
再次 vim Makefile 发现,第一行有判断,所以我直接在第 25 行左右直接添加一行
CC=arm-linux-gcc
再次
make
报错:
/usr/local/arm/4.3.2/bin/…/lib/gcc/arm-none-linux-gnueabi/4.3.2/…/…/…/…/arm-none-linux-gnueabi/bin/ld: cannot find -lnl
返回上一层目录
搜索
grep "-lnl" * -nR
src/drivers/drivers.mk:31: DRV_LIBS += -lnl-3
src/drivers/drivers.mk:32: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mk:36: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mk:38: DRV_LIBS += -lnl
src/drivers/drivers.mk:42: DRV_LIBS += -lnl-genl
src/drivers/drivers.mk:152: DRV_LIBS += -lnl-3
src/drivers/drivers.mk:153: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mk:154: DRV_LIBS += -lnl-route-3
src/drivers/drivers.mk:158: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mk:160: DRV_LIBS += -lnl
src/drivers/drivers.mk:164: DRV_LIBS += -lnl-genl
src/drivers/drivers.mk:165: DRV_LIBS += -lnl-route
src/drivers/drivers.mak:31: DRV_LIBS += -lnl-3
src/drivers/drivers.mak:32: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mak:36: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mak:38: DRV_LIBS += -lnl
src/drivers/drivers.mak:42: DRV_LIBS += -lnl-genl
src/drivers/drivers.mak:148: DRV_LIBS += -lnl-3
src/drivers/drivers.mak:149: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mak:150: DRV_LIBS += -lnl-route-3
src/drivers/drivers.mak:154: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mak:156: DRV_LIBS += -lnl
src/drivers/drivers.mak:160: DRV_LIBS += -lnl-genl
src/drivers/drivers.mak:161: DRV_LIBS += -lnl-route
去编译器库看一看:
cd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
ls libnl*
libnl-3.a libnl-genl-3.a libnl-nf-3.a
libnl-3.la libnl-genl-3.la libnl-nf-3.la
libnl-3.so libnl-genl-3.so libnl-nf-3.so
libnl-3.so.200 libnl-genl-3.so.200 libnl-nf-3.so.200
libnl-3.so.200.18.0 libnl-genl-3.so.200.18.0 libnl-nf-3.so.200.18.0
libnl-cli-3.a libnl-idiag-3.a libnl-route-3.a
libnl-cli-3.la libnl-idiag-3.la libnl-route-3.la
libnl-cli-3.so libnl-idiag-3.so libnl-route-3.so
libnl-cli-3.so.200 libnl-idiag-3.so.200 libnl-route-3.so.200
libnl-cli-3.so.200.18.0 libnl-idiag-3.so.200.18.0 libnl-route-3.so.200.18.0
打开 src/drivers/drivers.mk 发现
需要定义 CONFIG_LIBNL32 才能使用 -lnl-3 的库
30 ifdef CONFIG_LIBNL32
31 DRV_LIBS += -lnl-3
32 DRV_LIBS += -lnl-genl-3
33 DRV_CFLAGS += -DCONFIG_LIBNL20 -I/usr/include/libnl3
34 else
35 ifdef CONFIG_LIBNL_TINY
36 DRV_LIBS += -lnl-tiny
37 else
38 DRV_LIBS += -lnl
39 endif
40
41 ifdef CONFIG_LIBNL20
42 DRV_LIBS += -lnl-genl
43 DRV_CFLAGS += -DCONFIG_LIBNL20
44 endif
45 endif
46 endif
所以 vim .config
添加一行
CONFIG_LIBNL32=y
重新编译
make clean
make
编译成功
安装:
vim Makefile
搜索 install
847 install: all
848 mkdir -p $(DESTDIR)/usr/local/bin
849 for i in $(ALL); do cp -f $$i $(DESTDIR)/usr/local/bin/$$i; done
mkdir tmp
make DESTDIR=$PWD/tmp install
cd tmp/usr/local/bin
拷贝文件到开发板根文件系统
cp * /nfsroot/rootfs-1.20.0/bin/
使用 hostapd
hostapd.conf
/ # hostapd -h
hostapd v2.0
User space daemon for IEEE 802.11 AP management,
IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi> and contributors
usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>]
[-g <global ctrl_iface>] <configuration file(s)>
options:
-h show this usage
-d show more debug messages (-dd for even more)
-B run daemon in the background
-e entropy file
-g global control interface path
-P PID file
-K include key data in debug messages
-t include timestamps in some debug messages
-v show hostapd version
创建配置文件 /etc/hostapd.conf
无密码 AP 配置:
interface=wlan0
driver=nl80211
ssid=xhr_embedded
channel=1
WPA & WPA2 配置:
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=1234567890
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
执行命令,就可以使用手机搜索到名为 xhr_embedded 的 WLAN。
hostapd -B /etc/hostapd.conf
输入密码后,开发板打印信息已经可以看到连接成功,但手机上一直显示 “正在从 xhr_embedded 获取 IP 地址”,所以还需要设置 IP 才能正常使用。
使用 DHCP 分配 IP
修改 DHCP 的配置文件
vim /etc/dhcpd.conf
24 # add by xhr_embedded
25 subnet 192.168.13.0 netmask 255.255.255.0 {
26 range 192.168.13.10 192.168.13.255;
27 option domain-name-servers 192.168.13.1;
28 option domain-name "xhr_embedded";
29 option routers 192.168.13.1;
30 }
执行命令:
dhcpd -cf /etc/dhcpd.conf wlan0
报错:
For info, please visit https://www.isc.org/software/dhcp/
Can’t open lease database /var/db/dhcpd.leases: No such file or directory –
创建 /var/db/dhcpd.leases
mkdir -p /var/db
touch /var/db/dhcpd.leases
再次报错:
For info, please visit https://www.isc.org/software/dhcp/
Wrote 0 class decls to leases file.
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 0 leases to leases file.
No subnet declaration for wlan0 (no IPv4 addresses).
** Ignoring requests on wlan0. If this is not what
you want, please write a subnet declaration
in your dhcpd.conf file for the network segment
to which interface wlan0 is attached. **
Not configured to listen on any interfaces!
没有配置 wlan0 的 ip,所以不知道使用配置文件里的哪一个配置。
ifconfig wlan0 192.168.13.1
ping 测试
/ # ping 192.168.13.10
PING 192.168.13.10 (192.168.13.10): 56 data bytes
64 bytes from 192.168.13.10: seq=0 ttl=64 time=170.872 ms
64 bytes from 192.168.13.10: seq=1 ttl=64 time=196.023 ms
64 bytes from 192.168.13.10: seq=2 ttl=64 time=213.892 ms
64 bytes from 192.168.13.10: seq=3 ttl=64 time=27.063 ms
已经可以 ping 通手机
查看状态
使用 hostapd_cli 来连接 hostapd,可以通过命令来获取状态。
hostapd_cli
报错:
Could not connect to hostapd - re-trying
在 /etc/hostapd.conf 中添加:
# /var/run/hostapd is the recommended directory for sockets and by default,
# hostapd_cli will use it when trying to connect with hostapd.
ctrl_interface=/var/run/hostapd
使用 hostapd_cli 不加命令进入交互模式。
all_sta
查看 DHCP 的地址分配
vi /var/db/dhcpd.leases
开机自启动
1. MDEV 配置文件
vim /etc/mdev.conf
wlan0 0:0 660 * /sbin/auto_ap.sh
2. MDEV 执行的脚本
vim /sbin/auto_ap.sh
chmod +x /sbin/auto_ap.sh
#!/bin/sh
if [ $ACTION = "add" ];
then
ifconfig wlan0 192.168.13.1
dhcpd -cf /etc/dhcpd.conf wlan0
hostapd -B /etc/hostapd.conf
else
killall hostapd
killall dhcpd
fi
参考链接
hostapd 官网
hostapd.conf
最后
以上就是柔弱白猫为你收集整理的交叉编译使用 hostapd-2.0 在开发板上开机自启动无线网卡 AP 功能交叉编译使用 hostapd使用 DHCP 分配 IP查看状态开机自启动参考链接的全部内容,希望文章能够帮你解决交叉编译使用 hostapd-2.0 在开发板上开机自启动无线网卡 AP 功能交叉编译使用 hostapd使用 DHCP 分配 IP查看状态开机自启动参考链接所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复