hostapd啓動失敗,第一反應是配置文件配的不對,從hostapd的啓動日誌或許能看出點貓膩。
hostapd的config文件如下:
#cat /data/misc/wifi/hostapd.conf <
interface=wlan0
driver=nl80211
ctrl_interface=/data/misc/wifi/hostapd
ssid=MyAP
channel=13
ieee80211n=1
hw_mode=ad
ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40+]
ignore_broadcast_ssid=0
wowlan_triggers=any
#
報錯日誌如下:
I/hostapd (15503): wlan0: IEEE 802.11 ---------Configured channel (13) not found from the channel list of current mode (1) IEEE 802.11g
W/hostapd (15503): wlan0: IEEE 802.11 ---------Configured channel (13) not found from the channel list of current mode (1) IEEE 802.11g
I/hostapd (15503): wlan0: IEEE 802.11 Hardware does not support configured channel
W/hostapd (15503): wlan0: IEEE 802.11 Hardware does not support configured channel
E/hostapd (15503): Could not select hw_mode and channel. (-3)
I/hostapd (15503): wlan0: interface state UNINITIALIZED->DISABLED
I/hostapd (15503): wlan0: AP-DISABLED
E/hostapd (15503): wlan0: Unable to setup interface.
從報錯看是不支持13信道,第一反應是網卡國家碼不對。
iw reg get查看國家碼是US,確實不支持13信道。重新配置網卡國家碼爲CN:iw reg set CN,配置失敗,設置後會重新變回US,看來網卡驅動的配置是以環境的AP來配置國家碼的。
重新設置網卡的WCNSS_qcom_cfg.ini文件以支持手動配置國家碼,並強制關閉環境AP的配置:
gStaCountryCode=CN //默認sta的國家碼爲CN
gAPCntryCode=CN //默認AP的國家碼爲CN
g11dSupportEnabled=0 //關閉國家碼從環境獲取
這個文件一開始以爲是kernel中生效的,但是改了後重新安裝網卡驅動並沒有生效,最後才發現此init生效是在啓動hostapd或者wpa_supplicant時動態加載的,所以嘗試調整網卡參數時可直接在設備上修改這個文件[/system/lib/qcom.ini]。
好了,國家碼能正常設置了,但是啓動hostapd還是直接退出了,報錯還是不支持13信道。
沒辦法,就去看了一下hostapd報錯的位置的代碼。
static int hostapd_is_usable_chans(struct hostapd_iface *iface)
{
if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1))
return 0;
if (!iface->conf->secondary_channel)
return 1;
return hostapd_is_usable_chan(iface, iface->conf->channel +
iface->conf->secondary_channel * 4, 0);
}
原來,配置文件中指定的啓動HT40[即信道帶寬是40MHz]時,要求輔信道也必須在支持的信道內。HT40+是指輔信道是主信道+4,17信道是不支持的,因此配置失敗了。
同樣,5G信道也有一些配置是不允許的,除非查看代碼,不然也搞不懂失敗的原因。
5G時設置hostapd失敗打印:
I/hostapd ( 661): wlan0: interface state UNINITIALIZED->HT_SCAN
E/hostapd ( 661): HT40 channel pair (153, 1) not allowed
I/hostapd ( 661): Fallback to 20 MHz
E/hostapd ( 661): Interface initialization failed
I/hostapd ( 661): wlan0: interface state HT_SCAN->DISABLED
I/hostapd ( 661): wlan0: AP-DISABLED
E/hostapd ( 661): hostapd_free_hapd_data: Interface wlan0 wasn't started
而代碼中指定要求5G時hostapd的信道只能有以下幾個:
int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 140,
149, 157, 184, 192 };