启动热点
- RK3568或RK3588
- Ubuntu, Debian系统
- Wi-Fi:AP6275S / FD7352S等
其他配置也可作参考验证
配置 AP 模式
安装 hostapd
sudo apt install hostapd
配置 hostapd
创建/etc/hostapd/hostapd.conf文件,内容如下:
- 2.4GHz
- 5GHz
interface=wlan0
driver=nl80211
ssid=neardi_hostapd
hw_mode=g
channel=6
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
interface=wlan0
driver=nl80211
ssid=neardi_hostapd_5G
hw_mode=a
channel=36
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
country_code=CN
ieee80211d=1
ieee80211h=1
更改/etc/default/hostapd, 内容如下:
# Defaults for hostapd initscript
#
# WARNING: The DAEMON_CONF setting has been deprecated and will be removed
# in future package releases.
#
# See /usr/share/doc/hostapd/README.Debian for information about alternative
# methods of managing hostapd.
#
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
#
#DAEMON_CONF=""
# Additional daemon options to be appended to hostapd command:-
# -d show more debug messages (-dd for even more)
# -K include key data in debug messages
# -t include timestamps in some debug messages
#
# Note that -B (daemon mode) and -P (pidfile) options are automatically
# configured by the init.d script and must not be added to DAEMON_OPTS.
#
#DAEMON_OPTS=""
DAEMON_CONF="/etc/hostapd/hostapd.conf"
最后执行如下命令:
sudo systemctl unmask hostapd
sudo systemctl restart hostapd
配置 DHCP Server
安装 DHCP Server
sudo apt install isc-dhcp-server
配置 wlan0
首先设置wlan0的IPv4的地址, 如下命令:
sudo ifconfig wlan0 192.168.200.1
之后更改/etc/default/isc-dhcp-server, 内容如下:
# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)
# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf
# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid
# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="wlan0"
INTERFACESv6=""
再更改/etc/dhcp/dhcpd.conf, 内容如下:
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers 8.8.8.8;
default-lease-time 600;
max-lease-time 7200;
# The ddns-updates-style parameter controls whether or not the server will
...
...
#shared-network 224-29 {
# subnet 10.17.224.0 netmask 255.255.255.0 {
# option routers rtr-224.example.org;
# }
# subnet 10.0.29.0 netmask 255.255.255.0 {
# option routers rtr-29.example.org;
# }
# pool {
# allow members of "foo";
# range 10.17.224.10 10.17.224.250;
# }
# pool {
# deny members of "foo";
# range 10.0.29.10 10.0.29.230;
# }
#}
subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.100 192.168.200.200;
option routers 192.168.200.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
最后启动DHCP SERVER, 如下命令:
sudo systemctl restart isc-dhcp-server
启动成功:
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.200.1 netmask 255.255.255.0 broadcast 192.168.200.255
ether 70:f7:54:87:08:76 txqueuelen 1000 (Ethernet)
RX packets 19895 bytes 4527795 (4.3 MiB)
RX errors 0 dropped 6 overruns 0 frame 0
TX packets 196 bytes 16517 (16.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
开机自启动(可选)
- 新增
/usr/local/bin/apstart.sh,内容如下:
#!/bin/bash
# 等待 wlan0 出现
for i in {1..15}; do
if ip link show wlan0 >/dev/null 2>&1; then break; fi
sleep 1
done
# 停掉可能占用 wlan0 的 wpa_supplicant
if systemctl is-active --quiet wpa_supplicant; then
echo "[APStart] stopping wpa_supplicant..."
systemctl stop wpa_supplicant
fi
# 永久屏蔽 wpa_supplicant,防止 systemd 自动重启
if ! systemctl is-enabled wpa_supplicant 2>/dev/null | grep -q masked; then
echo "[APStart] masking wpa_supplicant..."
systemctl mask wpa_supplicant
fi
# 配置 IP
ip link set wlan0 up
ip addr add 192.168.200.1/24 dev wlan0
# 启动 hostapd 并等待
systemctl unmask hostapd
systemctl restart hostapd
sleep 5
# 确认 hostapd 已启动,否则重试
if ! systemctl is-active --quiet hostapd; then
echo "hostapd failed, retrying..."
systemctl restart hostapd
sleep 5
fi
# 启动 DHCP
systemctl restart isc-dhcp-server
- 新增
/etc/systemd/system/apstart.service,内容如下:
[Unit]
Description=Start AP on wlan0
After=network.target
Wants=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/apstart.sh
ExecStop=/bin/systemctl stop hostapd
[Install]
WantedBy=multi-user.target
- 启用服务
sudo chmod +x /usr/local/bin/apstart.sh
sudo systemctl daemon-reload
sudo systemctl enable apstart.service
sudo systemctl start apstart.service
实现网络共享(可选)
将eth1的网络通过wlan0热点分享出去,参考以下步骤:
#开启网络转发功能
sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
#网络转发的功能生效
sudo sysctl -p
#将从eth1网卡输出的数据包进行源地址伪装,让其他设备通过eth1网卡访问外部网络,而不会被外部网络拒绝
sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
#允许从eth1网卡输入的数据包,若状态是RELATED或者ESTABLISHED,转发到wlan0网卡输出,让eth1网卡收到的响应数据包返回到wlan0
sudo iptables -A FORWARD -i eth1 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
#允许从wlan0网卡输入的数据包,无条件地转发到eth1网卡输出,让wlan0网卡的设备通过eth1网卡访问外部网络
sudo iptables -A FORWARD -i wlan0 -o eth1 -j ACCEPT
FAQ
如何查询/设置国家码
可以用 iw reg get 查看国家码:
country 00: DFS-UNSET
可以用 iw reg set CN 设置国家码为中国。
如何确认信道是否 DFS 信道
可以用 iw list | grep MHz -A3 查看具体信道:
* 5180 MHz [36] (30.0 dBm)
* 5200 MHz [40] (30.0 dBm)
* 5220 MHz [44] (30.0 dBm)
* 5240 MHz [48] (30.0 dBm)
* 5260 MHz [52] (24.0 dBm) (radar detection)
- 36/40/44/48 没有 (radar detection) → 非 DFS,设置 channel=36 是 完全合法的,不会触发 DFS CAC。
- 52 以上有 (radar detection) → DFS 信道,设置 channel=52 会触发 DFS CAC。
FD7352S/FD7256S IR(伊朗)的国家码库中如何支持36信道
目前通过 iw reg get 打印显示都是disabled。
* 5180 MHz [36] (disabled)
* 5200 MHz [40] (disabled)
* 5220 MHz [44] (disabled)
* 5240 MHz [48] (disabled)
* 5260 MHz [52] (disabled)
* 5280 MHz [56] (disabled)
* 5300 MHz [60] (disabled)
* 5320 MHz [64] (disabled)
* 5500 MHz [100] (disabled)
* 5520 MHz [104] (disabled)
* 5540 MHz [108] (disabled)
* 5560 MHz [112] (disabled)
* 5580 MHz [116] (disabled)
* 5600 MHz [120] (disabled)
* 5620 MHz [124] (disabled)
* 5640 MHz [128] (disabled)
* 5660 MHz [132] (disabled)
* 5680 MHz [136] (disabled)
* 5700 MHz [140] (disabled)
* 5720 MHz [144] (disabled)
SDK加入以下补丁,编译内核烧录验证:
+++ b/kernel-6.1/drivers/net/wireless/rockchip_wlan/skwifi/skw_db.c
@@ -1416,9 +1416,10 @@ static const struct ieee80211_regdomain regdom_IR = {
.dfs_region = NL80211_DFS_JP,
.reg_rules = {
REG_RULE_EXT(2402, 2482, 40, 0, 20, 0, 0),
- REG_RULE_EXT(5735, 5835, 80, 0, 30, 0, 0),
+ REG_RULE_EXT(5150, 5250, 80, 0, 30, 0, 0),
+ REG_RULE_EXT(5250, 5350, 80, 0, 24, 0, SKW_RRF_DFS | 0),
},
- .n_reg_rules = 2
+ .n_reg_rules = 3
};