移植wpa_supplicant工具到arm linux平台
程序员文章站
2022-06-11 16:55:58
...
移植wpa_supplicant工具到arm linux平台
效果
一个脚本
#!/bin/sh
BUILD_HOST=/disk_4/toolchain/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf
ARM_GCC=${BUILD_HOST}-gcc
BASE=`pwd`
OUTPUT_PATH=${BASE}/install
OPENSSL=openssl-1.0.2t
WPA_SUPPLICANT=wpa_supplicant-0.7.3
make_dirs() {
cd ${BASE}
mkdir compressed install source -p
}
tget () { #try wget
filename=`basename $1`
echo "Downloading [${filename}]..."
if [ ! -f ${filename} ];then
wget $1
fi
echo "[OK] Downloaded [${filename}] "
}
download_package () {
cd ${BASE}/compressed
#下载包
tget https://www.openssl.org/source/${OPENSSL}.tar.gz
tget http://w1.fi/releases/${WPA_SUPPLICANT}.tar.gz
}
tar_package () {
cd ${BASE}/compressed
ls * > /tmp/list.txt
for TAR in `cat /tmp/list.txt`
do
tar -xf $TAR -C ../source
done
rm -rf /tmp/list.txt
}
pre_make_ssl () {
cd ${BASE}/source/${OPENSSL}
startLine=`sed -n '/install_html_docs\:/=' Makefile`
echo $startLine
# 为了避免 多行结果
for startline in $startLine
do
lineAfter=99
endLine=`expr $startline + 999`
sed -i $startline','$endLine'd' Makefile
echo "install_html_docs:" >> Makefile
echo "\aaa@qq.com skip by Schips" >> Makefile
echo "install_docs:" >> Makefile
echo "\aaa@qq.com skip by Schips" >> Makefile
echo "# DO NOT DELETE THIS LINE -- make depend depends on it." >> Makefile
break
done
}
pre_make_ssl_rm_char ()
{
# 匹配-m64字符串 替换为xx
#sed -i "s/-m64/xx/g" Makefile
# 匹配-m64字符串 替换为空
sed -i "s/-m64//g" Makefile
sed -i "s/-m32//g" Makefile
}
make_openssl () {
# 编译安装 ssl
cd ${BASE}/source/${OPENSSL}
echo "SSL ABOUT"
#./Configure --prefix=${OUTPUT_PATH}/${OPENSSL} os/compiler:${ARM_GCC}
#pre_make_ssl
#通过配置生成Makefile文件
./config no-asm shared --prefix=${OUTPUT_PATH}/${OPENSSL} --cross-compile-prefix=${BUILD_HOST}- #-static
#删除Makefile文件中-m64编译选项
pre_make_ssl_rm_char
make && make install
}
make_wpa () {
cd ${BASE}/source/wpa*/wpa*
cp defconfig .config
echo "CC=${ARM_GCC} -L${OUTPUT_PATH}/${OPENSSL}/lib" >> .config
echo "CFLAGS += -I${OUTPUT_PATH}/${OPENSSL}/include" >> .config
echo "LIBS += -L${OUTPUT_PATH}/${OPENSSL}/lib" >> .config
make && make install DESTDIR=${BASE}/install/wpa_supplicant/
cp ${BASE}/source/wpa*/wpa*/examples/wpa-psk-tkip.conf ${BASE}/install/wpa_supplicant/wpa.conf
# 在ctrl_interface 当前行下插入 update_config=1
sed -i '/ctrl_interface/aupdate_config=1' ${BASE}/install/wpa_supplicant/wpa.conf
}
make_dirs
download_package
tar_package
make_openssl
make_wpa
使用获取ssid
wifi信号名获取
#进行扫描wifi信号
wpa_cli -i wlan0 scan
#将扫描结果给/root/wifilog.txt文件中
wpa_cli scan_result > /root/wifilog.txt
wifilog.txt内容如下:
Selected interface 'wlan0'
bssid / frequency / signal level / flags / ssid
04:d3:b5:71:c8:50 2437 -47 [WPA2-PSK-CCMP][WPS][ESS] GNNGAP518
#打印 ESS 关键字段所在的行
awk '/ESS/' /root/wifilog.txt
#获取关键字段"ESS"所在行,第5列的字符串
awk '/ESS/ {print $5}' /root/wifilog.txt
#获取关键字段"ESS"所在行,以空格分隔 若第五列内容非空则打印 每行第5列的字符串 保存到/tmp/SSID.txt文件中
awk -F " " '/ESS/ {if($5!=""){print $5}}' /root/wifilog.txt>/tmp/SSID.txt
将awk保存为脚本文件,给外部调用
#!/bin/awk
awk -F " " '/ESS/ {if($5!=""){print $5}}'
简洁运行获取输出到文件
使用
1、etc目录下建立文件
2、生成的sbin目录下的wap_cli … 移动到开发板的/usr/sbin目录下
5、启动服务
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -B
3、扫描
4、配置好热点信息