zl程序教程

您现在的位置是:首页 >  硬件

当前栏目

嵌入式系统中启动Hostapd

嵌入式系统 启动 Hostapd
2023-06-13 09:11:28 时间

大家好,又见面了,我是你们的朋友全栈君。

项目过程中需要添加AP热点的需求,自然会想用到hostapd,具体的不做分析,自行百度,这里主要分析下启动脚本

采用的 WiFi 模组是“博通”公司的 AP6255 芯片,“博通”公司的 wifi 芯片 AP 与 STATION 切换需要对网卡驱动进行卸载重装,所以配网方式不建议使用 AP 模式配网,这会造成多次 WiFi 模式的切换,耗时可能比较严重。不过给出以下方法,开发者可以自行配置,进入 AP 模式。

如果需要进入 AP 模式,需要依次执行以下命令,对应的 hostapd 和 dnsmasq

# 构造 WiFi AP 参数,其中 ssid 和 wpa_passphrase 分别对应 SSID 和 密码, 例如此配置文件对应的 SSID 是 rokid,密码是 rokidos_psk
echo "interface=wlan0 driver=nl80211 ctrl_interface=/var/run/hostapd ssid=rokid channel=6 ieee80211n=1 ieee80211ac=1 hw_mode=g hw_mode=a ignore_broadcast_ssid=0 wpa=3 wpa_passphrase=rokidos_psk wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP CCMP rsn_pairwise=CCMP"  > /etc/hostapd_temp.conf

# 创建虚拟网卡 
iw wlan0 interface add wlan1 type managed

# 启动 hostapd (AP 管理软件)
hostapd -B /etc/hostapd_temp.conf

# 配置网卡的 IP 地址
ifconfig wlan0 192.168.2.1

# 启动 dns 和 dhcp 服务, 其中注意 IP 参数要与 IP 地址相对应
dnsmasq -iwlan0  --dhcp-option=3,192.168.2.1 --dhcp-range=192.168.2.50,192.168.2.200,12h -p100

脚本中创建wlan1需要使用iw命令,参数含义如下:

	dev <devname> interface add <name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*]
	phy <phyname> interface add <name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*]
		Add a new virtual interface with the given configuration.
		Valid interface types are: managed, ibss, monitor, mesh, wds.
		
		The flags are only used for monitor interfaces, valid flags are:
		none:     no special flags
		fcsfail:  show frames with FCS errors
		control:  show control frames
		otherbss: show frames from other BSSes
		cook:     use cooked mode
		active:   use active mode (ACK incoming unicast packets)
		
		The mesh_id is used only for mesh mode.

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/143265.html原文链接:https://javaforall.cn