rk3308b-cc开启wifi AP模式
本帖最后由 luckxu 于 2020-2-4 02:42 编辑环境: 主线内核,rootfs为ubuntu18.04附件为内核的两个补丁,提交信息如下:
commit 22bad544b0f1a0084b01b2ac4635e71ac2e15656 (HEAD -> xuhj/rk3308, xuhj/xuhj/rk3308)
Author: xuhj <xu_415@126.com>
Date: Tue Feb 4 01:53:08 2020 +0800
enable iptable support
Change-Id: Idb283b61bdcd243840dce16d12304b2634982972
commit 693b3eafc6132827cbb1cd5f2c1ccc8e3ce26db5
Author: xuhj <xu_415@126.com>
Date: Sun Feb 2 17:05:58 2020 +0800
add ubuntu-16.04 rootfs support and enable wifi(rtl8188eus)
generate wireless mac address from cpuid
Change-Id: I2bcdfc32dd6285a0fc4af9a00b28a89c59afa039
commit d734f176d177472e3f0788fcad67d1758b72fdfd (xuhj/develop-4.4, rockchip-linux/develop-4.4, develop-4.4)
Author: Finley Xiao <finley.xiao@rock-chips.com>
Date: Wed Jan 15 18:05:12 2020 +0800
arm64: dts: rockchip: rk3308: Modify power-model for cpu
Change-Id: Id0a098ff85afe49cddbc9da05da722155e338e60
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
第一个补丁修改主要涉及串口波特率、RTL8188EU网卡配置、增加rk3308b-cc编译支持、固定无线网卡mac地址、支持ubuntu等,非必须,请酌情使用,修改如下:
1. arch/arm64/boot/dts/rockchip/rk3308.dtsi,修改串口波特率为115200
2. arch/arm64/boot/dts/rockchip/rk3308b-firefly.dtsi 从sdk中复制并修改了bootargs参数,以支持ubuntu18.04启动
+ chosen {
+ bootargs = "earlycon=uart8250,mmio32,0xff0c0000 swiotlb=1 console=ttyFIQ0 rw root=PARTUUID=614e0000-0000 rootfstype=ext4";
+ };
3. arch/arm64/boot/dts/rockchip/rk3308b-roc-cc-amic_emmc.dts 从sdk中复制
4. arch/arm64/configs/firefly-rk3308b_linux_defconfig 从sdk复制,增加ubunt支持,添加rtl8188eu支持
4. net/rfkill/rfkill-wlan.c 无线网卡的MAC地址从随机生成变更为从cpuid生成,以此生成固定的MAC地址
diff --git a/net/rfkill/rfkill-wlan.c b/net/rfkill/rfkill-wlan.c
index 333368f2f071..bddb5b8cd256 100644
--- a/net/rfkill/rfkill-wlan.c
+++ b/net/rfkill/rfkill-wlan.c
@@ -27,6 +27,7 @@
#include <linux/wakelock.h>
#include <linux/interrupt.h>
#include <asm/irq.h>
+#include <asm/system_info.h>
#include <linux/suspend.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>
@@ -488,14 +489,20 @@ static int get_wifi_addr_vendor(unsigned char *addr)
}
ret = rk_vendor_read(WIFI_MAC_ID, addr, 6);
if (ret != 6 || is_zero_ether_addr(addr)) {
- LOG("%s: rk_vendor_read wifi mac address failed (%d)\n",
- __func__, ret);
#ifdef CONFIG_WIFI_GENERATE_RANDOM_MAC_ADDR
random_ether_addr(addr);
LOG("%s: generate random wifi mac address: "
"%02x:%02x:%02x:%02x:%02x:%02x\n",
__func__, addr, addr, addr,
addr, addr, addr);
+#else
+ addr = ((system_serial_high >> 8) & 0xff) ^ 0x73;
+ addr = ((system_serial_high >> 0) & 0xff) ^ 0x68;
+ addr = ((system_serial_low >> 24) & 0xff) ^ 0x75;
+ addr = ((system_serial_low >> 16) & 0xff) ^ 0x6c;
+ addr = ((system_serial_low >> 8)& 0xff) ^ 0x61;
+ addr = ((system_serial_low >> 0)& 0xff) ^ 0x6e;
+#endif
ret = rk_vendor_write(WIFI_MAC_ID, addr, 6);
if (ret != 0) {
LOG("%s: rk_vendor_write"
@@ -504,15 +511,12 @@ static int get_wifi_addr_vendor(unsigned char *addr)
memset(addr, 0, 6);
return -1;
}
-#else
- return -1;
-#endif
- } else {
- LOG("%s: rk_vendor_read wifi mac address: "
- "%02x:%02x:%02x:%02x:%02x:%02x\n",
- __func__, addr, addr, addr,
- addr, addr, addr);
}
+
+ LOG("%s: rk_vendor_read wifi mac address: "
+ "%02x:%02x:%02x:%02x:%02x:%02x\n",
+ __func__, addr, addr, addr,
+ addr, addr, addr);
return 0;
}
第二个补丁修改涉及内核iptable支持,修改如下:
1. 修改arch/arm64/configs/firefly-rk3308b_linux_defconfig,启用内核iptable支持,ap模式需要使用
From 22bad544b0f1a0084b01b2ac4635e71ac2e15656 Mon Sep 17 00:00:00 2001
From: xuhj <xu_415@126.com>
Date: Tue, 4 Feb 2020 01:53:08 +0800
Subject: enable iptable support
Change-Id: Idb283b61bdcd243840dce16d12304b2634982972
---
.../configs/firefly-rk3308b_linux_defconfig | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/arch/arm64/configs/firefly-rk3308b_linux_defconfig b/arch/arm64/configs/firefly-rk3308b_linux_defconfig
index 80e4445a9587..966cffb645d1 100644
--- a/arch/arm64/configs/firefly-rk3308b_linux_defconfig
+++ b/arch/arm64/configs/firefly-rk3308b_linux_defconfig
@@ -381,3 +381,45 @@ CONFIG_CRYPTO_AES_ARM64_CE_CCM=y
CONFIG_CRYPTO_AES_ARM64_CE_BLK=y
CONFIG_CRYPTO_AES_ARM64_NEON_BLK=y
CONFIG_CRYPTO_CRC32_ARM64=y
+
+CONFIG_NETFILTER=y
+CONFIG_NETFILTER_ADVANCED=y
+
+#
+# Core Netfilter Configuration
+#
+CONFIG_NETFILTER_INGRESS=y
+CONFIG_NETFILTER_NETLINK=y
+CONFIG_NF_CONNTRACK=y
+CONFIG_NF_CONNTRACK_PROCFS=y
+CONFIG_NF_NAT=y
+CONFIG_NF_NAT_NEEDED=y
+CONFIG_NF_NAT_REDIRECT=y
+CONFIG_NF_TABLES=y
+CONFIG_NFT_COMPAT=y
+CONFIG_NETFILTER_XTABLES=y
+
+#
+# Xtables targets
+#
+CONFIG_NETFILTER_XT_NAT=y
+CONFIG_NETFILTER_XT_TARGET_NETMAP=y
+CONFIG_NETFILTER_XT_TARGET_REDIRECT=y
+
+#
+# IP: Netfilter Configuration
+#
+CONFIG_NF_DEFRAG_IPV4=y
+CONFIG_NF_CONNTRACK_IPV4=y
+CONFIG_NF_CONNTRACK_PROC_COMPAT=y
+CONFIG_NF_TABLES_IPV4=y
+CONFIG_NF_REJECT_IPV4=y
+CONFIG_NF_NAT_IPV4=y
+CONFIG_NF_NAT_MASQUERADE_IPV4=y
+CONFIG_IP_NF_IPTABLES=y
+CONFIG_IP_NF_FILTER=y
+CONFIG_IP_NF_TARGET_REJECT=y
+CONFIG_IP_NF_NAT=y
+CONFIG_IP_NF_TARGET_MASQUERADE=y
+CONFIG_IP_NF_TARGET_NETMAP=y
+CONFIG_IP_NF_TARGET_REDIRECT=y
--
2.24.1
如果使用make menuconfig手动修改,可参考:
[*] Networking support--->
--- Networking support
Networking options--->
--- Network packet filtering framework (Netfilter)
Core Netfilter Configuration--->
[*] Netfilter ingress support
ubuntu18.04中操作:安装必要软件包,增加相关配置,开启无线AP
1. 安装hostapd dnsmasq iptables
apt install hostapd dnsmasq iptables -y --no-install-suggests --no-install-recommends
2. 编辑/etc/dnsmasq.conf追加如下内容:
interface=p2p0
bind-interfaces
except-interface=lo
dhcp-range=192.168.3.100,192.168.3.254,12h
dhcp-option=3,192.168.3.13. 编辑/etc/hostapd/hostapd.conf,内容如下:
interface=p2p0
ctrl_interface=/var/run/hostapd
ssid=firefly
channel=6
wpa=2
wpa_passphrase=firefly1234564. 禁用systemd-resolved,该服务会占用53端口,导致dnsmasq运行错误:
systemctl disable systemd-resolved
systemctl stop systemd-resolved
5. 执行如下操作启用AP,启用AP后可以手机上搜索到firefly的wifi:
hostapd -B /etc/hostapd/hostapd.conf > /dev/null 2>&1
ip addr add 192.168.3.1/24 dev p2p0
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
service dnsmasq restart6. 如需自启动,可启用rc-local服务(systemctl enable rc-local),添加/etc/rc.local文件并赋予可执行权限,rc.local内容如下
#!/bin/sh -e
# eth0自动获取IP地址
dhclient eth0 > /dev/null 2>&1 || :
hostapd -B /etc/hostapd/hostapd.conf > /dev/null 2>&1
ip addr add 192.168.3.1/24 dev p2p0
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
service dnsmasq restart
无线网卡从CPUID生成固定MAC地址那段代码中异或的几个数字没有意义,我随便添加的。 luckxu 发表于 2020-2-4 02:44
无线网卡从CPUID生成固定MAC地址那段代码中异或的几个数字没有意义,我随便添加的。
感谢前辈的分享。
有点疑惑咨询下前辈,就是这两个补丁怎么使用。
先介绍下我这边的情况,我已经用源码编译了一个img镜像,已经烧录到rk3308的板子里了。
这种情况下,两个补丁该怎么使用了,求帮助。
页:
[1]