admin管理员组文章数量:1574959
wifi模块调试笔记
- 移植wifi测试工具
- 移植wpa_*系列工具
- 移植hostapd 工具
- 附录:AP模式密码错误问题
- 配置内核
- 移植wifi模块驱动
- 测试
- 加载驱动
- 用作AP
- rtl_hostapd_2G.conf
- udhcpd.conf
- AP测试脚本
- 附录:hostapd的加密方式
- WEP
- WPA/WPA2
- WPA-PSK/WPA2-PSK
- 附录:AP模式下,热点配置为加密方式,密码错误
- 附录:udhcpd.conf参考
- 作为STA
- udhcpc.script
- STA测试
- 用作P2P
- 确认我们编译好的wap工具是否支持p2p功能
- 附录 (仅用作参考,不一定有效,未验证)
移植wifi测试工具
wifi工具下载地址:http://w1.fi/
移植wpa_*系列工具
移植hostapd 工具
该工具依赖2个库:libnl、openssl;因此首先得先完成这两个库的移植,指定好这两个库的安装位置。
cd hostapd
cp defconfig .config
.config编译配置修改(在默认配置的基础上确认下述配置已打开):
(特别要在其中指定好上述libnl、openssl的头文件以及库文件路径)
CONFIG_DRIVER_NL80211=y
CONFIG_LIBNL20=y
CONFIG_WPS=y
CONFIG_DRIVER_RTW=y
CONFIG_IEEE80211N=y
CFLAGS += -I/opt/novatek-sdk/nt9833x/v3.03.103.uclibc/na51103_linux_sdk/code/lib/external/__install/include
LIBS += -L/opt/novatek-sdk/nt9833x/v3.03.103.uclibc/na51103_linux_sdk/code/lib/external/__install/lib
附录:AP模式密码错误问题
如果上述配置CONFIG_DRIVER_NL80211
没有打开时,hostapd会使用默认driver创建AP。此时会导致手机连接该热点时报“密码错误”。
解决办法:
step1. 编译hostapd工具前,配置CONFIG_DRIVER_NL80211=y
step2. 在hostapd.conf中配置driver=nl80211
配置内核
--------------------------------------------------------------------------------------------------
Wifi增加802.11 协议栈的支持
[*] Networking support --->
[*] Wireless ---> (勾选)
<*> cfg80211 - wireless configuration API
[*] enable powersave by default (NEW)
[*] cfg80211 wireless extensions compatibility
<*> Generic IEEE 802.11 Networking Stack (mac80211)
[*] Enable mac80211 mesh networking (pre-802.11s) support
USB 支持WIFI 的配置
Device Drivers --->
[*]usb support
<*> USB Wireless Device Management support
-----------------------------------------------------------------------------------------------------
配置 wireless Extension(不配置会有 error: unknown field 'private' specified in initializer 之类错误)
Device Drivers --->
Network device support --->
[*] Wireless LAN --->
<*> USB ZD1201 based Wireless device support
-------------------------------------------------------------------------------------------------------
Wifi其它配置(配置项可能在menuconfig没有呈现出来,但是要保证下述配置项的状态为y):
[*] Networking support --->
[*] WIRELESS_EXT (该选项在novatek平台上被选中时,会导致sta错误)
<*> CONFIG_LIB80211
<*> LIB80211_CRYPT_WEP
<*> LIB80211_CRYPT_CCMP
<*> LIB80211_CRYPT_TKIP
Device drivers -->
[*] Staging drivers --->
<*> Support for rtllib wireless devices
<*> Support for rtllib CCMP crypto
<*> Support for rtllib TKIP crypto
<*> Support for rtllib WEP crypto
------------------------------------------------------------------------------------------------------
错误解决 rfkill是一个内核级别的管理工具,可以打开和关闭设备的蓝牙和wifi
CONFIG_RFKILL
rfkill: Cannot open RFKILL control device
先选Device Drivers --->
[*] Voltage and Current Regulator Support --->
再
[*] Networking support --->
<*> RF switch subsystem support --->
<*> Generic rfkill regulator driver
移植wifi模块驱动
- 修改makefile指定交叉编译工具链、内核路径、输出路径
- make
注意:每当修改了与wifi模块相关的内核配置后(包括网络相关配置),都要重新编译wifi模块驱动。否则有可能会导致各种异常现象。现象包括(1、加载驱动则崩溃;2、调用驱动时崩溃;3、其它异常)。
测试
加载驱动
insmod 8188eu.ko
用作AP
一般需要用到2个工具(hostapd,udhcpd);这两个工具分别对应两个配置文件(rtl_hostapd_2G.conf,udhcpd.conf)
hostapd:初始化wifi模块,并生成热点
udhcpd:(dhcp服务器)用于分配IP地址
rtl_hostapd_2G.conf
##### hostapd configuration file ##############################################
interface=wlan0
ctrl_interface=/var/run/hostapd
ssid=rtwap
channel=6
#wpa=0 //open mode
wpa=2
wpa_passphrase=87654321
#bridge=br0
##### Wi-Fi Protected Setup (WPS) #############################################
eap_server=1
# WPS state
# 0 = WPS disabled (default)
# 1 = WPS enabled, not configured
# 2 = WPS enabled, configured
wps_state=2
uuid=12345678-9abc-def0-1234-56789abcdef0
# Device Name
# User-friendly description of device; up to 32 octets encoded in UTF-8
device_name=RTL8192EU
# Manufacturer
# The manufacturer of the device (up to 64 ASCII characters)
manufacturer=Realtek
# Model Name
# Model of the device (up to 32 ASCII characters)
model_name=RTW_SOFTAP
# Model Number
# Additional device description (up to 32 ASCII characters)
model_number=WLAN_CU
# Serial Number
# Serial number of the device (up to 32 characters)
serial_number=12345
# Primary Device Type
# Used format: <categ>-<OUI>-<subcateg>
# categ = Category as an integer value
# OUI = OUI and type octet as a 4-octet hex-encoded value; 0050F204 for
# default WPS OUI
# subcateg = OUI-specific Sub Category as an integer value
# Examples:
# 1-0050F204-1 (Computer / PC)
# 1-0050F204-2 (Computer / Server)
# 5-0050F204-1 (Storage / NAS)
# 6-0050F204-1 (Network Infrastructure / AP)
device_type=6-0050F204-1
# OS Version
# 4-octet operating system version number (hex string)
os_version=01020300
# Config Methods
# List of the supported configuration methods
config_methods=label display push_button keypad
##### default configuration #######################################
#driver=rtl871xdrv #该rtl871xdrv会导致手机连接时报密码错误
driver=nl80211 #启用nl80211,当提示不存在该driver时,在编译hostapd工具是,在.config文件中配置启用。
#driver=wext
beacon_int=100
hw_mode=g
ieee80211n=1
wme_enabled=1
ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40+]
wpa_key_mgmt=WPA-PSK WPA-EAP
wpa_pairwise=CCMP TKIP
rsn_pairwise=CCMP TKIP
max_num_sta=8
wpa_group_rekey=86400
udhcpd.conf
# Sample udhcpd configuration file (/etc/udhcpd.conf)
# Values shown are defaults
# The start and end of the IP lease block
start 192.168.0.20
end 192.168.0.254
# The interface that udhcpd will use
#interface eth0
interface wlan0
# The maximum number of leases (includes addresses reserved
# by OFFER's, DECLINE's, and ARP conflicts). Will be corrected
# if it's bigger than IP lease block, but it ok to make it
# smaller than lease block.
#max_leases 254
# The amount of time that an IP will be reserved (leased to nobody)
# if a DHCP decline message is received (seconds)
#decline_time 3600
# The amount of time that an IP will be reserved
# if an ARP conflict occurs (seconds)
#conflict_time 3600
# How long an offered address is reserved (seconds)
#offer_time 60
# If client asks for lease below this value, it will be rounded up
# to this value (seconds)
#min_lease 60
# The location of the pid file
#pidfile /var/run/udhcpd.pid
# The location of the leases file
#lease_file /var/lib/misc/udhcpd.leases
# The time period at which udhcpd will write out leases file.
# If this is 0, udhcpd will never automatically write leases file.
# Specified in seconds.
#auto_time 7200
# Every time udhcpd writes a leases file, the below script will be called
#notify_file # default: no script
#notify_file dumpleases # useful for debugging
# The following are bootp specific options
# next server to use in bootstrap
#siaddr 192.168.0.22 # default: 0.0.0.0 (none)
# tftp server name
#sname zorak # default: none
# tftp file to download (e.g. kernel image)
#boot_file /var/nfs_root # default: none
# Static leases map
#static_lease 00:60:08:11:CE:4E 192.168.0.54
#static_lease 00:60:08:11:CE:3E 192.168.0.44
# The remainder of options are DHCP options and can be specified with the
# keyword 'opt' or 'option'. If an option can take multiple items, such
# as the dns option, they can be listed on the same line, or multiple
# lines.
# Examples:
#opt dns 192.168.10.2 192.168.10.10
opt dns 0.0.0.0
option subnet 255.255.255.0
#opt router 192.168.10.2
opt router 192.168.0.2
#opt wins 192.168.10.10
opt wins 0.0.0.0
option dns 129.219.13.81 # appended to above DNS servers for a total of 3
option domain local
option lease 864000 # default: 10 days
option msstaticroutes 10.0.0.0/8 10.127.0.1 # single static route
option staticroutes 10.0.0.0/8 10.127.0.1, 10.11.12.0/24 10.11.12.1
# Arbitrary option in hex form:
option 0x08 01020304 # option 8: "cookie server IP addr: 1.2.3.4"
# Currently supported options (for more info, see options.c):
#opt lease NUM
#opt subnet IP
#opt broadcast IP
#opt router IP_LIST
#opt ipttl NUM
#opt mtu NUM
#opt hostname STRING # client's hostname
#opt domain STRING # client's domain suffix
#opt search STRING_LIST # search domains
#opt nisdomain STRING
#opt timezone NUM # (localtime - UTC_time) in seconds. signed
#opt tftp STRING # tftp server name
#opt bootfile STRING # tftp file to download (e.g. kernel image)
#opt bootsize NUM # size of that file
#opt rootpath STRING # (NFS) path to mount as root fs
#opt wpad STRING
#opt serverid IP # default: server's IP
#opt message STRING # error message (udhcpd sends it on success too)
#opt vlanid NUM # 802.1P VLAN ID
#opt vlanpriority NUM # 802.1Q VLAN priority
# Options specifying server(s)
#opt dns IP_LIST
#opt wins IP_LIST
#opt nissrv IP_LIST
#opt ntpsrv IP_LIST
#opt lprsrv IP_LIST
#opt swapsrv IP
# Options specifying routes
#opt routes IP_PAIR_LIST
#opt staticroutes STATIC_ROUTES # RFC 3442 classless static route option
#opt msstaticroutes STATIC_ROUTES # same, using MS option number
# Obsolete options, no longer supported
#opt logsrv IP_LIST # 704/UDP log server (not syslog!)
#opt namesrv IP_LIST # IEN 116 name server, obsolete (August 1979!!!)
#opt cookiesrv IP_LIST # RFC 865 "quote of the day" server, rarely (never?) used
#opt timesrv IP_LIST # RFC 868 time server, rarely (never?) used
# TODO: in development
#opt userclass STRING # RFC 3004. set of LASCII strings. "I am a printer" etc
#opt sipserv STRING LIST # RFC 3361. flag byte, then: 0: domain names, 1: IP addrs
AP测试脚本
#!/bin/sh
ifconfig wlan0 up
ifconfig wlan0 192.168.0.1 netmask 255.255.255.0
udhcpd -fS /etc/udhcpd.conf &
hostapd /etc/rtl_hostapd_2G.conf -B
#设置路由表
echo 0 > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
#桥接对外网卡
iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
#iptables-restore < /mnt/flash/1111
echo 1 >/proc/sys/net/ipv4/ip_forward
附录:hostapd的加密方式
参考:https://www.ibm/developerworks/cn/linux/l-wifiencrypthostapd/#resources
参考:https://wwwblogs/zhuwenger/archive/2011/03/11/1980294.html
参考: https://www.21ic/tougao/article/585.html
hostapd有三种加密方式:WEP、WPA/WPA2、WPA-PSK/WPA2-PSK
WEP
比较差的加密方式,已被破解并且不支持80211n。
配置文件中wep加密为:
wep_key0=“xxxx”
WPA/WPA2
WPA/WPA2是一种比WEP强壮的加密算法,挑选这种安全类型,路由器将选用Radius服务器进行身份认证并得到密钥的WPA或WPA2安全形式。因为要架起一台专用的认证服务器,价值对比贵重且保护也很杂乱,所以不推荐普通用户运用此安全类型。
WPA-PSK/WPA2-PSK
WPA-PSK/WPA2-PSK安全类型其实是WPA/WPA2的一种简化版别,它是依据同享密钥的WPA形式,安全性很高,设置也对比简单,合适普通家庭用户和小型企业运用。
常见家用路由器的加密方式有:
WPA-Personal(TKIP+AES、AES)
WPA2-Personal(AES)
WPA2-Personal Mixed(TKIP+AES)
配置文件中加密实现:
auth_algs=1
wpa=3
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP TKIP
wpa_passphrase=12345678
当wpa=3时,
是WPA2-Personal Mixed模式,即
WPA-PSK-CCMP+TKIP WPA2PSK-CCMP+TKIP
当wpa=2时,
WPA2PSK-CCMP+TKIP
当wpa=1时,
WPAPSK-CCMP+TKIP
这儿格外需求阐明的是,三种无线加密办法对无线网络传输速率的影响也不尽相同。因为IEEE 802.11n规范不支持以WEP加密或TKIP加密算法的高吞吐率,所以假如用户挑选了WEP加密办法或WPA-PSK/WPA2-PSK加密办法的TKIP算法,无线传输速率将会主动限制在11g水平。
也就是说,假如用户运用的是契合IEEE 802.11n规范的无线商品,那么无线加密办法只能挑选WPA-PSK/WPA2-PSK的AES算法加密,不然无线传输速率将会显着下降。而假如用户 运用的是契合IEEE 802.11g规范的无线商品,那么三种加密办法都能够极好的兼容,不过仍然不主张我们挑选WEP这种较老且现已被破解的加密办法,最好能够晋级一下无线路由。
附录:AP模式下,热点配置为加密方式,密码错误
参考:https://wwwblogs/tid-think/p/9110620.html
解决办法已确认:编译hostapd工具前要确定是否配置启用nl80211的driver
。
附录:udhcpd.conf参考
参考自 https://www.xuebuyuan/2044396.html
start 192.168.0.2
end 192.168.0.100
interface wlan1 #default: eth0
max_leases 20 #default: 254
remaining yes #default: yes
auto_time 7200 #default: 7200 (2 hours)
decline_time 3600 #default: 3600 (1 hour)
conflict_time 3600 #default: 3600 (1 hour)
offer_time 60 #default: 60 (1 minute)
min_lease 60 #defult: 60
lease_file /etc/udhcpd.leases
opt dns 10.221.0.11 8.8.8.8
option subnet 255.255.255.0
opt router 192.168.0.1
作为STA
一般需要用到三个工具(wpa_passphrase ,wpa_supplicant ,udhcpc )
wpa_passphrase :用于根据wifi用户名及密码生成配置文件,如下:wpa_supplicant_rtw.conf。
wpa_supplicant :初始化wifi设备并接入热点。
udhcpc:(dhcp客户端程序)自动获取“由DHCP服务器分配的IP地址”
udhcpc.script
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers>
RESOLV_CONF="/etc/resolv.conf"
[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
NETMASK=""
[ -n "$subnet" ] && NETMASK="netmask $subnet"
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
case "$1" in
deconfig)
echo "Setting IP address 0.0.0.0 on $interface"
ifconfig $interface 0.0.0.0
;;
renew|bound)
echo "Setting IP address $ip on $interface"
ifconfig $interface $ip $NETMASK $BROADCAST
if [ -n "$router" ] ; then
echo "Deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
metric=0
for i in $router ; do
echo "Adding router $i"
route add default gw $i dev $interface metric $metric
: $(( metric += 1 ))
done
fi
echo "Recreating $RESOLV_CONF"
# If the file is a symlink somewhere (like /etc/resolv.conf
# pointing to /run/resolv.conf), make sure things work.
realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
tmpfile="$realconf-$$"
> "$tmpfile"
[ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
for i in $dns ; do
echo " Adding DNS server $i"
echo "nameserver $i" >> "$tmpfile"
done
mv "$tmpfile" "$realconf"
;;
esac
exit 0
STA测试
#!/bin/sh
#step1: select ap
wpa_passphrase Test_Jinny 88889999 | tee -a /etc/wpa_supplicant_rtw.conf
#wpa_passphrase TL-TEST TL12345678 | tee -a /etc/wpa_supplicant_rtw.conf
#step2: connect ap
ifconfig wlan1 up
wpa_supplicant -i wlan1 -D wext -c /etc/wpa_supplicant_rtw.conf -B
#wpa_supplicant -i wlan1 -D nl80211 -c /etc/wpa_supplicant_rtw.conf -B
#step3: get ip
udhcpc -i wlan1 -s /etc/udhcpc.script &
#route add default gw 192.168.80.254
用作P2P
确认我们编译好的wap工具是否支持p2p功能
根据wpa_supplicant源码中的README-P2P可知,需要使能下述的配置:
CONFIG_DRIVER_NL80211=y
CONFIG_CTRL_IFACE=y
CONFIG_P2P=y
CONFIG_AP=y
CONFIG_WPS=y
修改源码下的.config文件,将上述配置使能,接着重新编译wpa工具
wpa_p2p.conf:
ctrl_interface=/run/wpa_supplicant
ap_scan=1
device_name=mwifiex-p2p-device
device_type=1-0050F204-1
p2p_listen_reg_class=81
p2p_listen_channel=1
p2p_oper_reg_class=81
p2p_oper_channel=1
p2p_no_group_iface=1
p2p_go_intent=15
ctrl_interface=/var/run/wpa_supplicant
update_config=1
device_name=mint
device_type=2-0050F204-1
p2p_listen_reg_class=81
p2p_listen_channel=1
p2p_oper_reg_class=81
p2p_oper_channel=1
p2p_go_intent=1
p2p_no_group_iface=1
wpa_supplicant -i p2p0 -c wpa_p2p.conf -Dnl80211
wpa_cli -i p2p0
p2p_find 10
p2p_peers
附录 (仅用作参考,不一定有效,未验证)
参考自:it610/article/1279353238881058816.htm
1、准备好Realtek提供的RTL8188EUS驱动源码;
2、将RTL8188EUS驱动源码拷贝进开发板的内核源文件目录/driver/net/wireless/rtl818x;
3、修改/driver/net/wireless/rtl818x目录下的Kconfig目录,增加配置语句:
config RTL8188EUS
tristate “rtl8188eus usb wifi”
4、修改/driver/net/wireless/rtl818x目录的Makefile,增加内容:
obj-$(CONFIG_RTL8188EUS) += rtl8188EUS/
5、在/driver/net/wireless目录的Kconfig末尾增加语句:
source “drivers/net/wireless/rtl818x/Kconfig”
6、在编译内核时,Make Menuconfig时进行编译配置。首先USB支持设备,是能HOST USB相关功能;然后配置WIFI设备勾选IEEE802.11 for Host AP,以及子目录;最后配置网络支持IEEE802.11与cfg80211 wireless extensions compatibility;勾选rtl8188eus usb wifi设备。
7、编译完内核后加载到开发板,确保USB WIFI设备已经安装到了USB插座。然后安装wireless tools与wpa_supplicant工具可以进行测试。注意 wpa_supplicant依赖于libopenssl,因此先安装libopenssl和libnl,最后安装wpa_supplicant。(编译后的文件库见上传的资料:需要将libnl、libopenssl的lib目录下的全部文件拷贝到开发板的文件系统对应目录即 /rootfs/usr/lib/内;在wpa_supplicant的config中指定编译器和这些libopenssl和libnl下的include和lib目录。)
版权声明:本文标题:wifi模块调试笔记 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1727780226a1129235.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论