2022-12-4----Android11(H713m)---- WiFi驱动添加写入mac号补丁

一、问题

用全志的写号工具,写入wifi_mac,设置下边不生效

二、分析

因为我们的WiFi不是用全志平台的,也不是用全志集成好的,而是用希微这家第三方的WiFi/BT,所以该驱动还没完善。

三、修改前的准备

用写号工具写号后,adb shell 打开 proc/comline,查看wifi_mac字段是否有内容,确保mac已经写入主控。

正确的如下:

三、修改步骤

1、修改framework

XML 复制代码
diff --git a/H713-v1.3/device/softwinner/ares/common/overlay/overlay/frameworks/opt/net/wifi/service/res/values/config.xml b/H713-v1.3/device/softwinner/ares/common/overlay/overlay/frameworks/opt/net/wifi/service/res/values/config.xml
index b5d94ba681..5fac8cd248 100644
--- a/H713-v1.3/device/softwinner/ares/common/overlay/overlay/frameworks/opt/net/wifi/service/res/values/config.xml
+++ b/H713-v1.3/device/softwinner/ares/common/overlay/overlay/frameworks/opt/net/wifi/service/res/values/config.xml
@@ -22,5 +22,5 @@
 
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <!-- Indicates that connected MAC randomization is supported on this device -->
-    <bool translatable="false" name="config_wifi_connected_mac_randomization_supported">true</bool>
+    <bool translatable="false" name="config_wifi_connected_mac_randomization_supported">false</bool>

config_wifi_connected_mac_randomization_supported 该属性要改为false,禁止上层随机生成mac号

2、驱动的修改

cpp 复制代码
--- a/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/Makefile
+++ b/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/Makefile
@@ -25,7 +25,8 @@ skw-$(CONFIG_SKW_VENDOR) += skw_vendor.o
 skw-$(CONFIG_SKW_DFS_MASTER) += skw_dfs.o
 skw-$(CONFIG_SKW_TDLS) += skw_tdls.o
 
-ccflags-$(CONFIG_SKW_CALIB_DPD) += -DSKW_IMPORT_NS
+#ccflags-$(CONFIG_SKW_CALIB_DPD) += -DSKW_IMPORT_NS
+ccflags-y += -DSKW_IMPORT_NS
 
 ccflags-y += -I$(srctree)/include/linux/platform_data/
 
diff --git a/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_core.c b/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_core.c
index b3cfc17d0c..9c9dcbc379 100755
--- a/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_core.c
+++ b/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_core.c
@@ -2323,6 +2323,9 @@ static int skw_drv_probe(struct platform_device *pdev)
 	    skw_sync_chip_info(wiphy, &chip))
 		goto core_deinit;
 
+	if (!is_valid_ether_addr(skw_mac))
+		skw_get_mac_from_boot_cmd_line(skw_mac);/*add fungo 20241122 for wifi mac*/
+
 	skw_setup_mac_address(wiphy, skw_mac, chip.mac);
 
 	if (skw_calib_download(wiphy, skw->fw.calib_file) < 0)
diff --git a/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_util.c b/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_util.c
index 8c9f4ff4a0..941cabb333 100755
--- a/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_util.c
+++ b/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_util.c
@@ -85,9 +85,75 @@ void skw_file_close(struct file *fp)
 	filp_close(fp, NULL);
 }
 
+int skw_get_mac_from_boot_cmd_line(u8 *mac_addr)
+{
+	int ret = 0;
+	struct file *file;
+	loff_t pos = 0;
+	ssize_t len;
+	char *page;
+	char *wifi_mac = NULL;
+	char tmp_mac_addr[27] = {0};
+	char *saved_cmdline = NULL;
+	
+	page = (char *)__get_free_page(GFP_KERNEL);
+	if (!page) {
+		skw_err("Failed to allocate memory for cmdline\n");
+		return -ENOMEM;
+	}
+
+	file = filp_open("/proc/cmdline", O_RDONLY, 0);
+	if (IS_ERR(file)) {
+		skw_err("Could not open /proc/cmdline\n");
+		ret = -ENOENT;
+		goto free_page_exit;
+	}
+
+	len = kernel_read(file, page, PAGE_SIZE, &pos);
+	filp_close(file, NULL);
+
+	if (len < 0) {
+		skw_err("Error reading /proc/cmdline\n");
+		ret = -EIO;
+		goto free_page_exit;
+	}
+
+	saved_cmdline = kmalloc(len + 1, GFP_KERNEL);
+	if (!saved_cmdline) {
+		free_page((unsigned long)page);
+		ret = -ENOMEM;
+		goto free_page_exit;
+	}
+
+	strncpy(saved_cmdline, page, len);
+	saved_cmdline[len] = '\0';
+	wifi_mac = strstr(saved_cmdline, "wifi_mac=");
+
+	if (wifi_mac) {
+		memcpy(tmp_mac_addr, wifi_mac, 27);
+		tmp_mac_addr[26] = '\0';
+		skw_err("wifi_mac=%s\n", tmp_mac_addr);
+		ret = sscanf(tmp_mac_addr, "wifi_mac=%02X:%02X:%02X:%02X:%02X:%02X",
+			mac_addr, mac_addr + 1, mac_addr + 2,
+			mac_addr + 3, mac_addr + 4, mac_addr + 5);
+		if (ret != 6) {
+			skw_err("Invalid wifi_mac format\n");
+			ret = -EINVAL;
+		}
+	}
+
+	kfree(saved_cmdline);
+free_page_exit:
+	free_page((unsigned long)page);
+	skw_err("skw_get_mac_from_boot_cmd_line err!\n");
+	return ret;
+}
 MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);
+#else
+int skw_get_mac_from_boot_cmd_line(u8 *mac_addr){
+	return 0;
+}
 #endif
-
 void *skw_build_presp_frame(struct wiphy *wiphy, struct skw_iface *iface,
 			u8 *da, u8 *sa, u8 *bssid, u8 *ssid, int ssid_len,
 			u16 chan, struct ieee80211_supported_band *sband,
diff --git a/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_util.h b/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_util.h
index f57c396fd6..2495f01931 100755
--- a/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_util.h
+++ b/H713-v1.3/longan/kernel/linux-5.4/drivers/net/wireless/seekwave/skw_util.h
@@ -311,6 +311,7 @@ int skw_file_sync(struct file *fp);
 void skw_file_close(struct file *fp);
 #endif
 
+int skw_get_mac_from_boot_cmd_line(u8 *mac_addr);
 u64 skw_local_clock(void);
 int skw_key_idx(u16 bitmap);
 char *skw_mgmt_name(u16 fc);

在wifi驱动的写入mac的地方进行逻辑修改,修改为从系统的cmdline读取wifi_mac字段,所以最核心的地方便是 skw_get_mac_from_boot_cmd_line 该函数。

3、se权限的修改

cpp 复制代码
diff --git a/H713-v1.3/device/softwinner/common/config/wireless/initrc/init.wireless.bluetooth.rc b/H713-v1.3/device/softwinner/common/config/wireless/initrc/init.wireless.bluetooth.rc
index 065155d04c..aee1c580ab 100644
--- a/H713-v1.3/device/softwinner/common/config/wireless/initrc/init.wireless.bluetooth.rc
+++ b/H713-v1.3/device/softwinner/common/config/wireless/initrc/init.wireless.bluetooth.rc
@@ -4,6 +4,7 @@ on boot
     chown bluetooth net_bt_admin ${persist.vendor.bluetooth_port}
 
     # bluetooth power up/down interface
+    chmod 0777 /proc/cmdline
     chmod 0660 /sys/class/rfkill/rfkill0/state
     chmod 0660 /sys/class/rfkill/rfkill0/type
     chown bluetooth net_bt_admin /sys/class/rfkill/rfkill0/state
diff --git a/H713-v1.3/device/softwinner/common/sepolicy/vendor/hal_wifi_default.te b/H713-v1.3/device/softwinner/common/sepolicy/vendor/hal_wifi_default.te
index bea874c399..02d2271526 100644
--- a/H713-v1.3/device/softwinner/common/sepolicy/vendor/hal_wifi_default.te
+++ b/H713-v1.3/device/softwinner/common/sepolicy/vendor/hal_wifi_default.te
@@ -7,3 +7,4 @@ allow hal_wifi_default wifi_data_file:file getattr;
 allow hal_wifi_default vendor_data_file:dir { add_name write };
 allow hal_wifi_default vendor_data_file:file { create open write read};
 allow hal_wifi_default debugfs_wifi_tracing:dir search;
+allow hal_wifi_default proc_cmdline:file {read open};

读取cmdline报se权限错误,所以添加上

四、注意

该修改方法适用于 以ko方式加载驱动的形式,WiFi驱动是编译成ko,然后init.rc里进行insmod挂载驱动的。

为什么只能以ko的方式!

因为Android 的启动流程是

uboot------>kernel------->init------->系统层

众所周知,Android 的根目录是在init阶段形成的!

如果编译成.o,那么驱动将会在kernel进行挂载,这个时候读取cmdline绝对会报错!因为根本没有形成根目录!

相关推荐
高林雨露5 小时前
ImageView android:scaleType各种属性
android·imageview各种属性
Hi-Dison6 小时前
OpenHarmony系统中实现Android虚拟化、模拟器相关的功能,包括桌面显示,详细解决方案
android
事业运财运爆棚7 小时前
http 502 和 504 的区别
android
峥嵘life9 小时前
Android Studio新版本的一个资源id无法找到的bug解决
android·bug·android studio
编程乐学9 小时前
网络资源模板--Android Studio 实现绿豆通讯录
android·前端·毕业设计·android studio·大作业·安卓课设·绿豆通讯录
朴拙数科12 小时前
mysql报错解决 `1525 - Incorrect DATETIME value: ‘0000-00-00 00:00:00‘`
android·数据库·mysql
1登峰造极14 小时前
scroll-view 实现滑动显示,确保超出正常显示,小程序app,h5兼容
android·小程序
刘争Stanley14 小时前
Android 15(V)新功能适配,雕琢移动细节之美
android·kotlin·android 15·android v
小狗爱世界14 小时前
深入解析Binder源码
android·binder
qq_2146703514 小时前
android 聊天界面键盘、表情切换丝滑
android·gitee