Wifi¶
- 环境
RK3568或RK3588 Ubuntu, Debian系统 Wi-Fi:AP6275S
- 查看wifi版本
cat /sys/bus/sdio/devices/mmc2\:0001\:1/vendor cat /sys/bus/sdio/devices/mmc2\:0001\:1/device dmesg | grep -i wlan - 0x02d0:0xaae8 表示 AP6275S。 - 0x024c:0xb852 表示 RTL8852。 - 0x024c:0xd723 表示 RTL8723DS。 - 0x024c:0xc821 表示 RTL8821CS。 - 0x1ffe:0x6316 表示 FD7352S。
- 下载hostapd
apt install --download-only hostapd
- 安装hostapd
dpkg -i hostapd_2%3a2.9-1ubuntu4.4_arm64.deb Selecting previously unselected package hostapd. (Reading database ... 101255 files and directories currently installed.) Preparing to unpack hostapd_2%3a2.9-1ubuntu4.4_arm64.deb ... Unpacking hostapd (2:2.9-1ubuntu4.4) ... Setting up hostapd (2:2.9-1ubuntu4.4) ... Created symlink /etc/systemd/system/multi-user.target.wants/hostapd.service → /lib/systemd/system/hostapd.service. Job for hostapd.service failed because the control process exited with error code. See "systemctl status hostapd.service" and "journalctl -xe" for details. Created symlink /etc/systemd/system/hostapd.service → /dev/null. Processing triggers for systemd (245.4-4ubuntu3.24) ... Processing triggers for man-db (2.9.1-1) ...
- 添加ap配置
vim /etc/hostapd/hostapd.conf interface=wlan0 driver=nl80211 ssid=neardi_rk3568 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
- 修改hostapd配置的引用(添加最后一行的:DAEMON_CONF="/etc/hostapd/hostapd.conf" )
vim /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"
- 启动ap
systemctl unmask hostapd systemctl restart hostapd 注:unmask 解除 hostapd 服务的屏蔽状态。当一个服务被屏蔽(masked)时,它不能被启动或启用。屏蔽通常用于防止服务被意外启动。解除屏蔽(unmask)是为了允许该服务再次启动。
- 安装isc-dhcp-server
apt install isc-dhcp-server
- 配置wlan0
1) ifconfig wlan0 171.172.10.1 2) vim /etc/default/isc-dhcp-server(主要添加:INTERFACESv4="wlan0") # 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="" 3) vim /etc/dhcp/dhcpd.conf # dhcpd.conf # # Sample configuration file for ISC dhcpd # # Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as # configuration file instead of this file. # # 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; ………… ………… #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 171.172.10.0 netmask 255.255.255.0 { range 171.172.10.100 171.172.10.200; option routers 171.172.10.1; option domain-name-servers 8.8.8.8, 8.8.4.4; }
- 启动dhcp server
systemctl restart isc-dhcp-server
- iperf调试
# 下行测试 设备:./iperf -s PC端:iperf -c 172.16.19.165 -i 1 -t 20 -w 1M [ ID] Interval Transfer Bandwidth [ 4] 0.0-3600.2 sec 18.9 GBytes 45.1 Mbits/sec # 上行测试 设备:./iperf -c 172.16.19.38 -i 1 -t 20 -w 1M PC端:iperf -s -w 1M [ ID] Interval Transfer Bandwidth [432] 0.0-3600.0 sec 17.1 GBytes 40.9 Mbits/sec 注: 1.PC端作服务端时,如不加 -w 1M参数,一般电脑的TCP窗口都会比较小,测试千兆上行时带宽不会够。 2.测试结果在设备端查看即可。 3. iperf 客户端发送数据到服务端,这通常被视为下载测试(从服务端的角度来看)
- 网络共享
# 将eth1的网络通过wlan0热点分享出去,参考以下步骤: #开启网络转发功能 echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf #网络转发的功能生效 sysctl -p #将从eth1网卡输出的数据包进行源地址伪装,让其他设备通过eth1网卡访问外部网络,而不会被外部网络拒绝 iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE #允许从eth1网卡输入的数据包,若状态是RELATED或者ESTABLISHED,转发到wlan0网卡输出,让eth1网卡收到的响应数据包返回到wlan0 iptables -A FORWARD -i eth1 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT #允许从wlan0网卡输入的数据包,无条件地转发到eth1网卡输出,让wlan0网卡的设备通过eth1网卡访问外部网络 iptables -A FORWARD -i wlan0 -o eth1 -j ACCEPT
- 参考
1.官网(非常重要): http://wiki.neardi.com/wiki/linux_guide/zh_CN/docs/demo/demo_hostapd.html 2.STA/AP使能与测试: https://forum.neardi.com/d/46-fd7352swifimo-kuai-shi-yong 服务器端运行: iperf3 -s 机器端运行: iperf3 -c ipaddr -P 6 -b 1000M -t 30 -i 1 // 测试发送 iperf3 -c ipaddr -P 6 -b 1000M -t 30 -i 1 -R //测试接收 -c ipaddr:指定 iperf3 服务器的 IP 地址(替换 ipaddr 为服务器的实际 IP 地址)。 -P 6:使用 6 个并行的流来进行测试。并行流可以帮助测试在多连接情况下的网络性能。 -b 1000M:设置带宽为 1000 Mbps(即 1 Gbps)。这个选项告诉 iperf3 客户端期望以 1 Gbps 的速度发送数据。 -t 30:测试持续时间为 30 秒。 -i 1:每秒报告一次测试结果。 -R:反向测试模式,意味着测试将会从服务器到客户端进行。这将使 iperf3 在服务器端向客户端发送数据,而不是客户端向服务器发送数据 3.Linux(5)WIFI/BT调试笔记: http://zhanzhang.ceden.cn/?article/1488404 4.LubanCat-RK3588系列板卡快速使用手册(蓝牙部分): https://doc.embedfire.com/linux/rk3588/quick_start/zh/latest/quick_start/wireless/bluetooth/bluetooth.html