前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >hostapd_acs 源码分析

hostapd_acs 源码分析

作者头像
全栈程序员站长
发布2022-08-31 17:13:31
8430
发布2022-08-31 17:13:31
举报
文章被收录于专栏:全栈程序员必看

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

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

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”);

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年5月2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档