hostapd_acs 源码分析

在自动信道文件中。函数处理流程进行:

   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. 1在../src/ap/drv_callbacks.c  加上
  1. 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 版本实现原理:

  1. 从页面配置到hostapd 通过channel 字段的文本来触发开启自动功能。Hostapd 初始化解析配置文件将信道channel=acs_survey设置为0.
  2. 当开启自动信道功能后,启动hostapd 进程hostapd 内部通过检查信道是否可用,如果信道为0,就触发启动自动信道功能调用acs_init()。

具体自动信道实现acs 处理

  1. 收集干扰数据

Acs  发出扫描请求,调用驱动进行扫描hostapd_driver_scan();

     2. 分析计算干扰数据

      3. 根据计算出的结果选择一个理想信道然后赋值

iface->conf->channel = ideal_chan->chan;

struct hostapd_iface *iface

自动选择信道:

在分析自动选择信号到后,可以找到调用自动信道的位置为:

  1. Shell 或者lua :解析到acs, 启动定时自动调用函数,调用命令:killall -16 hostapd 向hostapd 发送一个信号SIGUSR1 (16)
  2. 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");

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值