我正在尝试让 wpa_supplicant 和 hostapd 同时工作,以便使用单个接口连接到 wifi 网络并生成接入点(不提供互联网)。如果我wpa_supplicant
先运行hostapd
然后运行,一切正常:
wpa_supplicant -i wlan0 -c wpa.conf -B # wpa.conf has been generated using wpa_passphrase
udhcpc -i wlan0
/bin/bash /usr/sbin/create_access_point.sh
但是,如果我先运行 hostapd,然后运行 wpa_supplicant,则连接到 AP 的每个客户端都会断开连接,并且无法再连接。具体来说,如果在启动 wpa_supplicant 后有新客户端尝试连接,客户端会卡在“正在获取 IP 地址...”上,并且 hostapd 会不断交替显示 AP-STA-CONNECTED 和 AP-STA-DICCONNECTED。
两种情况下 ip route 的输出:
default via 192.168.1.254 dev wlan0 metric 10 192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.74 192.168.3.0/24 dev wlan1 proto kernel scope link src 192.168.3.1
create_access_point.sh的内容:
#!/bin/bash
modprobe brcmfmac
iw dev wlan0 interface add wlan1 type __ap
ifconfig wlan1 192.168.3.1 up
udhcpd /etc/udhcpd.conf
hostapd /etc/myhostapd.conf
hostapd 配置:
interface=wlan1
driver=nl80211
logger_syslog=-1
logger_syslog_level=0
logger_stdout=-1
logger_stdout_level=3
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=myssid
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypasswd
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
iw 列表的输出:
Wiphy phy0 max # scan SSIDs: 10 max scan IEs length: 2048 bytes max # sched scan SSIDs: 16 max # match sets: 16 max # scan plans: 1 max scan plan interval: 508 max scan plan iterations: 0 Retry short limit: 7 Retry long limit: 4 Coverage class: 0 (up to 0m) Device supports roaming. Supported Ciphers: * WEP40 (00-0f-ac:1) * WEP104 (00-0f-ac:5) * TKIP (00-0f-ac:2) * CCMP-128 (00-0f-ac:4) Available Antennas: TX 0 RX 0 Supported interface modes: * IBSS * managed * AP * P2P-client * P2P-GO * P2P-device Band 1: Capabilities: 0x1020 HT20 Static SM Power Save RX HT20 SGI No RX STBC Max AMSDU length: 3839 bytes DSSS/CCK HT40 Maximum RX AMPDU length 65535 bytes (exponent: 0x003) Minimum RX AMPDU time spacing: 16 usec (0x07) HT TX/RX MCS rate indexes supported: 0-7 Bitrates (non-HT): * 1.0 Mbps * 2.0 Mbps (short preamble supported) * 5.5 Mbps (short preamble supported) * 11.0 Mbps (short preamble supported) * 6.0 Mbps * 9.0 Mbps * 12.0 Mbps * 18.0 Mbps * 24.0 Mbps * 36.0 Mbps * 48.0 Mbps * 54.0 Mbps Frequencies: * 2412 MHz [1] (20.0 dBm) * 2417 MHz [2] (20.0 dBm) * 2422 MHz [3] (20.0 dBm) * 2427 MHz [4] (20.0 dBm) * 2432 MHz [5] (20.0 dBm) * 2437 MHz [6] (20.0 dBm) * 2442 MHz [7] (20.0 dBm) * 2447 MHz [8] (20.0 dBm) * 2452 MHz [9] (20.0 dBm) * 2457 MHz [10] (20.0 dBm) * 2462 MHz [11] (20.0 dBm) * 2467 MHz [12] (20.0 dBm) * 2472 MHz [13] (20.0 dBm) * 2484 MHz [14] (disabled) Supported commands: * new_interface * set_interface * new_key * start_ap * set_bss * join_ibss * set_pmksa * del_pmksa * flush_pmksa * remain_on_channel * frame * set_wiphy_netns * set_channel * start_sched_scan * start_p2p_device * connect * disconnect * crit_protocol_start * crit_protocol_stop * update_connect_params Supported TX frame types: * managed: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0 * AP: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0 * P2P-client: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0 * P2P-GO: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0 * P2P-device: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0 Supported RX frame types: * managed: 0x40 0xd0 * AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0 * P2P-client: 0x40 0xd0 * P2P-GO: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0 * P2P-device: 0x40 0xd0 software interface modes (can always be added): valid interface combinations: * #{ managed } <= 1, #{ P2P-device } <= 1, #{ P2P-client, P2P-GO } <= 1, total <= 3, #channels <= 2 * #{ managed } <= 1, #{ AP } <= 1, #{ P2P-client } <= 1, #{ P2P-device } <= 1, total <= 4, #channels <= 1 Device supports scan flush. Device supports randomizing MAC-addr in sched scans. Supported extended features: * [ 4WAY_HANDSHAKE_STA_PSK ]: 4-way handshake with PSK in station mode * [ 4WAY_HANDSHAKE_STA_1X ]: 4-way handshake with 802.1X in station mode
我希望能够在启动时运行 hostapd,稍后再运行 wpa_supplicant。我该怎么做?
更新: 我尝试使用 wpa_supplicant 而不是 hostapd 来生成接入点,使用以下配置:
network={
ssid="TESTAP"
mode=2
key_mgmt=WPA-PSK
psk="password"
frequency=2437
}
现在,即使设备连接到另一个 wifi,我也可以连接到接入点,但客户端和 AP 无法互相 ping 通。
更新2:添加p2p_disabled=1
到 wpa.conf 允许 AP 的客户端(使用 hostapd 生成)保持连接,但在这种情况下无法 ping 通 AP。 终止 wpa_supplicant 允许 ping 通 AP。