安装软件
opkg install hostapd-utils
使用 hostapd_cli
-i 指定网卡 使用 ifconfig获取
方法1
假设切换到信道4
hostapd_cli -i phy0-ap0 set channel 4
然后
hostapd_cli -i phy0-ap0 disable
hostapd_cli -i phy0-ap0 enable
才能生效 这样会导致客户端全体下线 再上线
方法2
hostapd_cli chan_switch
chan_switch <cs_count> [sec_channel_offset=] [center_freq1=] [center_freq2=] [bandwidth=] [blocktx] [ht|vht]
参数
cs_count:switch channel after how many beacon frames 在多少信标帧后切换信道
freq: 信道频率
bandwidth 可选 20MHz ; 40MHz
ht|vht 对应HT20 和 HT40
通过信道获取对应频率
物理网卡 phy0 对应 无线网卡,一个phy可以创建出多个 dev
指定 [值] 信道值
如 获取第7信道的频率
iw phy phy0 channels|grep “24” |grep -w [7]|awk -F " " ‘{print $2}’
或
第几行就是第几信道
iw phy phy0 channels|grep * |awk -F " " ‘{print $2}’|sed -n ‘4p’
iw phy phy0 channels|grep * |awk -F " " ‘{print $2}’|sed -n 3p’
实例 切换到 第1信道 对应频率 2412
hostapd_cli -i phy0-ap0 chan_switch 30 2412
需要附加 bandwidth 和 hz 否则信号没有这些功能
hostapd_cli -i phy0-ap0 chan_switch 100 2417 bandwidth=20MHz ht
日志
daemon.info hostapd: phy0-ap0: IEEE 802.11 driver had channel switch: iface->freq=2462, freq=2462, ht=1, vht_ch=0x0, he_ch=0x0, eht_ch=0x0, offset=0, width=1 (20 MHz), cf1=2462, cf2=0, puncturing_bitmap=0x0
daemon.notice hostapd: phy0-ap0: CTRL-EVENT-CHANNEL-SWITCH freq=2462 ht_enabled=1 ch_offset=0 ch_width=20 MHz cf1=2462 cf2=0 is_dfs0=0 dfs=0 puncturing_bitmap=0x0000
daemon.notice hostapd: phy0-ap0: AP-CSA-FINISHED freq=2462 dfs=0
hostapd通告 CTRL-EVENT-CHANNEL-SWITCH AP-CSA-FINISHED AP-STA-DISCONNECTED AP-STA-CONNECTED
大部分 sta端 无需重新认证 保持连接; 除非sta端不支持 csa 才需要重新认证连接
对应40MHz 需要将信道设置到 1 6 11 才能设置成功
配置自动选择最佳信道脚本 可实现无干预切换