在自動信道文件中。函數處理流程進行:
Main() ../hostapd/main.c + 552
hostapd_wpa_event() ../src/ap/drv_callbacks.c +1017 在該函數中通過接收 事件 是否 爲 EVENT_CHANNEL_LIST_CHANGED,觸發hostapd 更新信道。而這個事件在什麼地方發送的呢? src/drivers/Driver_nl80211.c +2754
分別會在 NL80211_CMD_REG_CHANGE 和 NL80211_CMD_REG_BEACON_HINT 這兩個事件下。
hostapd_channel_list_updated() ../src/ap/hostapd.c +992
--------setup_interface2(iface); ../src/ap/hostapd.c +1060
---------------hostapd_select_hw_mode() 信道是在這調用檢查信道功能,判斷是否channel =0, 如果=0 就進行自動信道選擇。
------------------------ hostapd_check_chans(iface) src/ap/hw_features.c +973 這函數中就是觸發自動信道功能的。
-------------------------------acs_init() // 初始化運行調用自動信道功能
----------------------------------------------acs_request_scan()
這個纔是自動信道 處理流程:
-------------main:709-----------
-------------hostapd_setup_interface:1249-----------
-------------setup_interface:1048-----------
-------------setup_interface:1058-----------
-------------setup_interface2:1066-----------
-------------setup_interface2:1071-----------
-------------hostapd_select_hw_mode:974-----------
-------------hostapd_check_chans:857-----------
-------------acs_init:795-----------
NL80211_CMD_REG_CHANGE 事件
wiphy_register()
/*
* This can happen on global regulatory changes or device specific settings
* based on custom world regulatory domains.
*/
nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); // .. \compat-wireless-2013-06-27\drivers\net\wireless\nl80211.c +9301
hostapd_select_hw_mode 選擇 hw 模式 在該函數中會檢查信道。
switch (hostapd_check_chans(iface)) {
case HOSTAPD_CHAN_VALID:
return 0;
case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
return 1;
case HOSTAPD_CHAN_INVALID:
default:
hostapd_notify_bad_chans(iface);
return -3;
}
nl80211作爲用戶空間的配置管理。
struct wpa_driver_ops *wpa_drivers[] =
{
#ifdef CONFIG_DRIVER_NL80211
&wpa_driver_nl80211_ops,
}
const struct wpa_driver_ops wpa_driver_nl80211_ops = {
.init2 = wpa_driver_nl80211_init, src/drivers/Driver_nl80211.c +11443
}
------- wpa_driver_nl80211_init()/ i802_init()
---------------wpa_driver_nl80211_drv_init() src/drivers/Driver_nl80211.c +3780
---------------------wpa_driver_nl80211_init_nl src/drivers/Driver_nl80211.c +3621
-----------------------------------process_drv_event src/drivers/Driver_nl80211.c +2794
--------------------------------------------------do_process_drv_event()
static int process_drv_event(struct nl_msg *msg, void *arg)
- 1在../src/ap/drv_callbacks.c 加上
- 2 Hostapd 打印錯誤
root@xxxxxx:/# hostapd -ddd -P /var/run/wifi-phy0.pid /var/run/hostapd-phy0.conf
Configuration file: /var/run/hostapd-phy0.conf
Channel not configured (hw_mode/channel in hostapd.conf)
Could not select hw_mode and channel. (-3)
wlan0: Unable to setup interface.
關於自動信道功能:
Hostapd 20131120 版本
Acs 中:
* How does it work
* ----------------
* 1. passive scans are used to collect survey data
* (it is assumed that scan trigger collection of survey data in driver)
* 2. interference factor is calculated for each channel
* 3. ideal channel is picked depending on channel width by using adjacent
* channel interference factors
Hostapd 20131120 版本實現原理:
- 從頁面配置到hostapd 通過channel 字段的文本來觸發開啓自動功能。Hostapd 初始化解析配置文件將信道channel=acs_survey設置爲0.
- 當開啓自動信道功能後,啓動hostapd 進程hostapd 內部通過檢查信道是否可用,如果信道爲0,就觸發啓動自動信道功能調用acs_init()。
具體自動信道實現acs 處理
- 收集干擾數據
Acs 發出掃描請求,調用驅動進行掃描hostapd_driver_scan();
2. 分析計算干擾數據
3. 根據計算出的結果選擇一個理想信道然後賦值
iface->conf->channel = ideal_chan->chan;
struct hostapd_iface *iface
自動選擇信道:
在分析自動選擇信號到後,可以找到調用自動信道的位置爲:
- Shell 或者lua :解析到acs, 啓動定時自動調用函數,調用命令:killall -16 hostapd 向hostapd 發送一個信號SIGUSR1 (16)
- Hostapd 在選擇信道的時候,默認如果是自動的會先選擇一個。
hostapd_select_hw_mode() 函數中,進行信號註冊,等待接收信號SIGUSR1, 如果收到了信號,進入信號處理函數進行選擇信道。
#ifdef CONFIG_ACS
if(iface->conf->channel == 0)
{
iface_G = iface;
signal(SIGUSR1, sig_han);
}
#endif
設置hostapd 配置文件裏面的信道方法:
system("sed -i \"s/$\(cat /var/run/hostapd-phy0.conf | grep \"channel=\"\)/channel=6/g\" /var/run/hostapd-phy0.conf");