其他分享
首页 > 其他分享> > hi3519v101平台搭建hostapd

hi3519v101平台搭建hostapd

作者:互联网

以前是有建立过在Ubuntu下面建立hostapd,现在海思项目有这么个需求,需要移植.

1.wifi驱动移植,看上章.

2.我们需要工具:hostapd热点;udhcpd动态分配ip;wpa_supplicant配置sta,可以连接wifi.

      但是hostapd,wap_supplicant依赖于ssl和nl库.我所用的库openssl-1.0.2s , libnl-3.4.0, hostapd-2.8, udhcp-0.9.8 ,wpa_supplicant-2.8都是在他们官网上下载的.

       下面是Makefile:

###########################################################################################

DY_WIFI_ROOT:=$(shell pwd)
DY_WIFI_OWN_LIB_INTALL_DIR=wifi_lib_insdir
DY_WIFI_LIB_INSTALL_DIR=$(DY_WIFI_ROOT)/$(DY_WIFI_OWN_LIB_INTALL_DIR)
DY_SUB_LIBNL_INSTALL_DIR=$(DY_WIFI_LIB_INSTALL_DIR)/libnl-insdir
DY_SUB_OPENSSL_INSTALL_DIR=$(DY_WIFI_LIB_INSTALL_DIR)/openssl-insdir
DY_OPENSSL_DIR_NAME=openssl-1.0.2s
DY_LIBNL_DIR_NAME=libnl-3.4.0
DY_HOSTAPD_DIR_NAME=hostapd-2.8/hostapd
DY_UDHCP_DIR_NAME=udhcp-0.9.8
DY_WPA_SUPPLICANT_DIR_NAME=wpa_supplicant-2.8/wpa_supplicant

DY_LIBNL_SOURCE_DIR=$(DY_WIFI_ROOT)/$(DY_LIBNL_DIR_NAME)
DY_OPENSSL_SOURCE_DIR=$(DY_WIFI_ROOT)/$(DY_OPENSSL_DIR_NAME)
DY_HOSTAPD_SOURCE_DIR=$(DY_WIFI_ROOT)/$(DY_HOSTAPD_DIR_NAME)
DY_UDHCP_SOURCE_DIR=$(DY_WIFI_ROOT)/$(DY_UDHCP_DIR_NAME)
DY_WPA_SUPPLICANT_SOURCE_DIR=$(DY_WIFI_ROOT)/$(DY_WPA_SUPPLICANT_DIR_NAME)

DY_WIFI_OUT_DIR=$(DY_WIFI_ROOT)/outdir
DY_WIFI_EXCUTE_OUT_DIR=$(DY_WIFI_ROOT)/outdir/exe
DY_WIFI_LIB_OUT_DIR=$(DY_WIFI_ROOT)/outdir/lib


all:libopenssl libnl3_4 hostapd_targ udhcpd_targ wpa_supplicant_targ
    mkdir -p $(DY_WIFI_EXCUTE_OUT_DIR)
    mkdir -p $(DY_WIFI_LIB_OUT_DIR)
    cp $(DY_HOSTAPD_SOURCE_DIR)/hostapd $(DY_WIFI_EXCUTE_OUT_DIR)
    cp $(DY_HOSTAPD_SOURCE_DIR)/hostapd_cli $(DY_WIFI_EXCUTE_OUT_DIR)
    cp $(DY_UDHCP_SOURCE_DIR)/udhcpd $(DY_WIFI_EXCUTE_OUT_DIR)
    cp $(DY_UDHCP_SOURCE_DIR)/udhcpc $(DY_WIFI_EXCUTE_OUT_DIR)
    cp $(DY_WPA_SUPPLICANT_SOURCE_DIR)/wpa_supplicant $(DY_WIFI_EXCUTE_OUT_DIR)
    cp $(DY_WPA_SUPPLICANT_SOURCE_DIR)/wpa_cli $(DY_WIFI_EXCUTE_OUT_DIR)
    ##运行hostapd的时候需要以下库文件:拷贝到/usr/lib里面就好了!!!
    cp $(DY_SUB_LIBNL_INSTALL_DIR)/lib/libnl-3.so.200 $(DY_WIFI_LIB_OUT_DIR)
    cp $(DY_SUB_LIBNL_INSTALL_DIR)/lib/libnl-3.so.200.26.0 $(DY_WIFI_LIB_OUT_DIR)
    cp $(DY_SUB_LIBNL_INSTALL_DIR)/lib/libnl-genl-3.so.200 $(DY_WIFI_LIB_OUT_DIR)
    cp $(DY_SUB_LIBNL_INSTALL_DIR)/lib/libnl-genl-3.so.200.26.0 $(DY_WIFI_LIB_OUT_DIR)
    
    cp $(DY_SUB_OPENSSL_INSTALL_DIR)/lib/libssl.so.1.0.0 $(DY_WIFI_LIB_OUT_DIR)
    cp $(DY_SUB_OPENSSL_INSTALL_DIR)/lib/libcrypto.so.1.0.0 $(DY_WIFI_LIB_OUT_DIR)

clean:libopenssl_clean libnl3_4_clean hostapd_targ_clean udhcpd_targ_clean wpa_supplicant_targ_clean
    rm -rf $(DY_WIFI_OUT_DIR)

###########编译openssl,去掉-m64,libclean用:rm -rf;因为我编译出现了错误,因此修改.

libopenssl:
    mkdir -p $(DY_SUB_OPENSSL_INSTALL_DIR);
    pushd $(DY_OPENSSL_SOURCE_DIR);./config no-asm shared no-async --prefix=$(DY_SUB_OPENSSL_INSTALL_DIR) --cross-compile-prefix=arm-hisiv500-linux-;sed -i 's/-m64//g' Makefile;sed -i '/^libclean/{n;s/rm -f \*\.map/rm -rf \*\.map/;}' Makefile;make;make install;popd
    
libopenssl_clean:
    pushd $(DY_OPENSSL_SOURCE_DIR);make clean;popd
    rm -rf $(DY_SUB_OPENSSL_INSTALL_DIR)

####编译nl3.4库

libnl3_4:
    mkdir -p $(DY_SUB_LIBNL_INSTALL_DIR);
    pushd $(DY_LIBNL_SOURCE_DIR); ./configure --host=arm-hisiv500-linux --prefix=$(DY_SUB_LIBNL_INSTALL_DIR);make;make install;popd
libnl3_4_clean:
    pushd $(DY_LIBNL_SOURCE_DIR);make clean;popd
    rm -rf $(DY_SUB_LIBNL_INSTALL_DIR)

########下面3个目录,Makefile需要修改:hostapd和wpa_supplicant修改:CC=arm-hisiv200-linux-gcc     ;    udhcpd修改:CROSS_COMPILE=arm-hisiv200-linux-

#######对于编译hostapd和wpa_supplicant,    需要对他们目录下的.config文件添加头文件和库路径:ssl和nl的库

###CFLAGS += -I../../wifi_lib_insdir/openssl-insdir/include/
###LIBS += -L../../wifi_lib_insdir/libnl-insdir/lib/
###LIBS += -L../../wifi_lib_insdir/openssl-insdir/lib/

hostapd_targ:
    pushd $(DY_HOSTAPD_SOURCE_DIR);cp dy_3519v101_ap_config .config;make;popd
hostapd_targ_clean:
    pushd $(DY_HOSTAPD_SOURCE_DIR);make clean;popd

udhcpd_targ:
    pushd $(DY_UDHCP_SOURCE_DIR);make;popd
udhcpd_targ_clean:
    pushd $(DY_UDHCP_SOURCE_DIR);make clean;popd

wpa_supplicant_targ:
    pushd $(DY_WPA_SUPPLICANT_SOURCE_DIR);cp dy_3519v101_wpa_supplicant_config .config;make;popd
wpa_supplicant_targ_clean:
    pushd $(DY_WPA_SUPPLICANT_SOURCE_DIR);make clean;popd

 

########################################################################################

3.编译完成了,那就是运行:和Ubuntu环境下差不多:

##################################udhcpd.conf配置文件#####################################

# Sample udhcpd configuration file (/etc/udhcpd.conf)

# The start and end of the IP lease block

start         192.168.75.20    #default: 192.168.0.20
end        192.168.75.254    #default: 192.168.0.254


# The interface that udhcpd will use

interface    wlan0        #default: eth0

#DHCPD_ENABLE="yes"


# The maximim number of leases (includes addressesd reserved
# by OFFER's, DECLINE's, and ARP conficts

max_leases    200        #default: 254


# If remaining is true (default), udhcpd will store the time
# remaining for each lease in the udhcpd leases file. This is
# for embedded systems that cannot keep time between reboots.
# If you set remaining to no, the absolute time that the lease
# expires at will be stored in the dhcpd.leases file.

#remaining    yes        #default: yes


# The time period at which udhcpd will write out a dhcpd.leases
# file. If this is 0, udhcpd will never automatically write a
# lease file. (specified in seconds)

auto_time    2        #default: 7200 (2 hours)


# The amount of time that an IP will be reserved (leased) for if a
# DHCP decline message is received (seconds).

#decline_time    3600        #default: 3600 (1 hour)


# The amount of time that an IP will be reserved (leased) for if an
# ARP conflct occurs. (seconds

#conflict_time    3600        #default: 3600 (1 hour)


# How long an offered address is reserved (leased) in seconds

#offer_time    60        #default: 60 (1 minute)

# If a lease to be given is below this value, the full lease time is
# instead used (seconds).

#min_lease    60        #defult: 60


# The location of the leases file

#lease_file    /home/surpas1/actiontec/install-dir/hostapudhcpd.leases    #defualt: /var/lib/misc/udhcpd.leases

# The location of the pid file
#pidfile    /home/surpas1/actiontec/install-dir/hostapudhcpd.pid    #default: /var/run/udhcpd.pid

# Everytime udhcpd writes a leases file, the below script will be called.
# Useful for writing the lease file to flash every few hours.

#notify_file                #default: (no script)

#notify_file    dumpleases     # <--- usefull for debugging

# The following are bootp specific options, setable by udhcpd.

#siaddr        192.168.0.22        #default: 0.0.0.0

#sname        zorak            #default: (none)

#boot_file    /var/nfs_root        #default: (none)

# The remainer of options are DHCP options and can be specifed 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. The only option with a default is 'lease'.

#Examles
#opt    dns    192.168.10.2 192.168.10.10
option    subnet    255.255.255.0
#opt    router    192.168.10.2
#opt    wins    192.168.10.10
#option    dns    129.219.13.81    # appened to above DNS servers for a total of 3
#option    domain    local
option    lease    864000        # 10 days of seconds


# Currently supported options, for more info, see options.c
#subnet
#timezone
#router
#timesvr
#namesvr
#dns
#logsvr
#cookiesvr
#lprsvr
#bootsize
#domain
#swapsvr
#rootpath
#ipttl
#mtu
#broadcast
#wins
#lease
#ntpsrv
#tftp
#bootfile

########################################################################################

 

############################hostapd.conf的配置文件##################################

interface=wlan0
##指定配置网卡。

ctrl_interface=hostapd-dir
#配置hostapd的目录,当前目录的"hostapd-dir"目录,主要用于hostapd-dir/wlan0进行与ctrl端通讯.目录不能与hostapd文件重复,不然会提示失败.

ssid=Surpass
#配置SSID

driver=nl80211
#指定网卡驱动。

#ieee80211n=1
#802.11n标准,支持2.4,5G。100M+速率。

#wmm_enabled=1
#音视频媒体优先

channel=1

#无线网卡选用1信道,一般为11.如2.4G(2.40-2.48)有14个信道(一个channel=22mhz),channel之间也是有重叠处,1-6-11不重叠。5g又有:34,36,38...64,100,104,108...140,149,153,157,161.

#channel与hw_mode有密切的关系。如果channel与hw_mode不一致会导致AP启动失败。mode=1 chan=1-11(2.4g),mode=2 chan=36-165(5g)。如果用2.4gchannel对应的hw_mode=g,5gchannel对应的hw_mode=a.      802.11协议指定了802.11a对应5g,802.11g对应2g,其中802.11b也是2g,802.11n都支持。参考文档:http://wenku.baidu.com/link?url=K-I08AFxnJa0V3Y_2bW6EyvktIbkBUUfxpW6ZsjGdtD6Oxtw7kRR6x-nu2SaDeYRTJT_WdeexaTP270LiWYbSyG92u13w5t_F4bZmSPQPri

hw_mode=g
#网卡工作在802.11G模式(54M,2.4g,这样的和802.11n冲突。。) a,b,g选择  

ignore_broadcast_ssid=0
#This enables/disables broadcasting the ssid,1 disable.如果=0,广播ssid,sta可以扫描到他。=1不广播,扫描不到他。

wpa_group_rekey=86400
#指定86400s更新一次组密钥,如果手机等客服端不支持该功能,将会断开。

wpa=1
#认证方式为WPA1对饮TKIP CCMP

wpa_pairwise=TKIP CCMP
#加密方式为TKIP CCMP

#wpa=2
#wpa2对应CCMP
#rsn_pairwise=CCMP
#加密方式为TKIP CCMP

#WPA=0无加密

wpa_passphrase=12345678
#wpa密码

max_num_sta=5
#最多可以连接5个无线设备。


auth_algs=1

#auth_algs=1 只支持 WPA 身份验证算法。auth_algs=2 表示支持 WEP。永远不要使用有线等效加密 (wired equivalent privacy, WEP),因为它非常容易破解,并且多年前就已经被完全破解了。auth_algs=3 表示支持这两种方式。
#wpa=3
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP

 

####################################启动脚本,不用桥接####################################

#!/bin/sh
echo "run hostapd shell!"

killall -9 udhcpd
killall -9 hostapd

pathDir=`pwd`
#下面两句解决nl80211: Could not configure driver mode问题。
##改变NetworkManager里的状态,关闭wifi,同时软锁定
#sudo nmcli nm wifi off

#启用wifi设备,不同于网络状态中的启用wifi(后者改变NetworkManager里的状态)
#sudo rfkill unblock wlan

ifconfig wlan0 192.168.75.1 netmask 255.255.255.0

ifconfig wlan0 down
#sudo ifconfig wlan0 up
sleep 1

echo "udhcpd!"
./udhcpd $pathDir/udhcpd.conf&

echo "hostapd!"
#-B后台运行,-d检测hostapd.conf正确性-B -d
./hostapd $pathDir/hostapd.conf&

sleep 1

ifconfig wlan0 up

#取消桥接:

#sudo ifconfig br0 down
#sudo brctl delif br0 wlan0
#sudo brctl delif br0 eth0
#sudo ifconfig br0 down

#sudo brctl delbr br0
#sudo dhclient eth0
#echo "bridge is down,now up it!"
#进行桥接:
#sudo brctl addbr br0
#sudo brctl addif br0 wlan0
#sudo ifconfig eth0 inet 0.0.0.0
#sudo brctl addif br0 eth0
#sudo ifconfig br0 up
#sudo dhclient br0
echo "finish!"

##############################成功连接和ping通############################
/xxx/outdir/exe # ping 192.168.75.20
64 bytes from 192.168.75.20: seq=0 ttl=64 time=14.303 ms
64 bytes from 192.168.75.20: seq=1 ttl=64 time=2.208 ms
64 bytes from 192.168.75.20: seq=2 ttl=64 time=1.997 ms
64 bytes from 192.168.75.20: seq=3 ttl=64 time=2.128 ms
64 bytes from 192.168.75.20: seq=4 ttl=64 time=1.971 ms

标签:hi3519v101,hostapd,WIFI,DY,udhcpd,wpa,DIR,搭建
来源: https://blog.csdn.net/hxchuan000/article/details/93493287