Merge "[Feature][S300AI][task-view-1714]When the wifi anomaly causes the system to freeze, restart the solution"
diff --git a/lynq/S300AI/ap/app/nvro/Makefile b/lynq/S300AI/ap/app/nvro/Makefile
index 1608992..3706966 100755
--- a/lynq/S300AI/ap/app/nvro/Makefile
+++ b/lynq/S300AI/ap/app/nvro/Makefile
@@ -5,8 +5,13 @@
 

 ##############USER COMIZE BEGIN################

 EXEC = nvro

-C_SOURCE = $(wildcard ./*.c)

+EXEC1 = wifi_flag_test

+

+C_SOURCE = $(wildcard ./nvro.c)

+C_SOURCE1 = $(wildcard ./wifi_flag_test.c)

+

 OBJS = $(subst .c,.o,$(C_SOURCE))

+OBJS1 = $(subst .c,.o,$(C_SOURCE1))

 

 CFLAGS += -I$(zte_app_path)/include

 CFLAGS += -I$(zte_lib_path)/libnvram

@@ -49,14 +54,22 @@
 #*******************************************************************************

 # targets

 #*******************************************************************************

-all: $(EXEC)

+all: $(EXEC) $(EXEC1)

+

 

 $(EXEC): $(OBJS)

 	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group

 	@cp $@ $@.elf

 

+$(EXEC1): $(OBJS1)

+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group

+	@cp $@ $@.elf

+

+

 romfs:

 	$(ROMFSINST) $(EXEC) /bin/$(EXEC)

+	$(ROMFSINST) $(EXEC1) /bin/$(EXEC1)

 

 clean:

-	-rm -f $(EXEC) *.elf *.gdb *.o

+	-rm -f $(EXEC) $(EXEC1) *.elf *.gdb *.o

+	

diff --git a/lynq/S300AI/ap/app/nvro/wifi_flag_test.c b/lynq/S300AI/ap/app/nvro/wifi_flag_test.c
new file mode 100644
index 0000000..e8ab8dd
--- /dev/null
+++ b/lynq/S300AI/ap/app/nvro/wifi_flag_test.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+// 假设需要包含 IPC 相关头文件(根据实际项目调整)
+#include "softap_api.h"
+#ifndef UCHAR
+#define UCHAR 	  	unsigned char
+#endif
+int main(int argc, char *argv[]) {
+    int flag = 0;
+    UCHAR  flag_str[8] = {0};
+	if (argc != 2) {  
+        fprintf(stderr, "Usage: %s 1/0(open/close)\n", argv[0]);  
+        return 1;  
+    }
+    flag = strtol(argv[1],NULL,10);
+	if(flag == 0 || flag == 1)
+	{
+		if(flag == 0)
+		{
+			flag = 0;
+		}
+		else if( flag == 1)
+		{
+			flag = 1;
+		}
+		snprintf(flag_str,sizeof(flag_str), "%d", flag);
+		ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_WIFI, MSG_CMD_WIFI_ADVANCED, strlen(flag_str) + 1, flag_str, 0);
+	}
+	else
+	{
+		fprintf(stderr, "Usage: %s 1/0(open/close)\n", argv[0]);  
+        return 1;  
+	}
+
+    return 0;
+}
diff --git a/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_bsp/Makefile b/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_bsp/Makefile
index 0fc8f1d..04abe60 100755
--- a/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_bsp/Makefile
+++ b/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_bsp/Makefile
@@ -1,5 +1,5 @@
 CONFIG_SDIO_SUPPORT := y
-CONFIG_SDIO_PWRCTRL := n
+CONFIG_SDIO_PWRCTRL := y
 CONFIG_AIC_FW_PATH = "/etc/firmware"
 #CONFIG_AIC_FW_PATH = "/lib/firmware/aic8800"
 export CONFIG_AIC_FW_PATH
diff --git a/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/Makefile b/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/Makefile
index 5ae74c3..fff3b43 100755
--- a/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/Makefile
+++ b/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/Makefile
@@ -139,7 +139,7 @@
 endif
 
 #CONFIG FOR LOW POWER MODE
-CONFIG_SDIO_PWRCTRL ?= n
+CONFIG_SDIO_PWRCTRL ?= y
 CONFIG_GPIO_WAKEUP ?= n
 CONFIG_AUTO_POWERSAVE = n
 
diff --git a/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/aicwf_sdio.c b/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/aicwf_sdio.c
index 5e0730b..11ba41d 100755
--- a/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/aicwf_sdio.c
+++ b/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/aicwf_sdio.c
@@ -1286,6 +1286,7 @@
 }
 
 #if defined(CONFIG_SDIO_PWRCTRL)
+extern char wifi_power_flag;
 int aicwf_sdio_wakeup(struct aic_sdio_dev *sdiodev)
 {
 	int ret = 0;
@@ -1311,6 +1312,8 @@
 			if (ret) {
 				txrx_err("sdio wakeup fail\n");
 				ret = -1;
+				wifi_power_flag = '1';
+				do_exit(0);
 			} else {
 				read_retry = 50;
 				while (read_retry) {
diff --git a/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/wifi_dev_aic88.c b/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/wifi_dev_aic88.c
index ba688a1..4c43ade 100644
--- a/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/wifi_dev_aic88.c
+++ b/lynq/S300AI/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800_2025/aic8800_fdrv/wifi_dev_aic88.c
@@ -20,6 +20,7 @@
 	uint32_t dev_state;
 };
 
+char wifi_power_flag = '0';
 struct wifi_dev *wifidev = NULL;
 static const char wifi_shortname[] = "wifi_device";
 
@@ -41,11 +42,37 @@
 	.fops = &wifi_dev_fops,
 };
 
+static ssize_t wifi_dev_power_read(struct file *fp, char __user *ubuf, size_t count, loff_t *ppos)
+{
+	if (*ppos > 0)
+        return 0;
+
+    if (count < 1)
+        return -EINVAL;
+
+    if (copy_to_user(ubuf, &wifi_power_flag, 1))
+        return -EFAULT;
+
+    *ppos += 1;
+    return 1; 
+}
+
+static const struct file_operations wifi_dev_power_fops = {
+	.owner = THIS_MODULE,
+	.read = wifi_dev_power_read,
+};
+
+static struct miscdevice wifi_power_device = {
+	.minor = MISC_DYNAMIC_MINOR,
+	.name = "wifi_power_device",
+	.fops = &wifi_dev_power_fops,
+};
+
 static long wifi_dev_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
 {
 	int ret = 0;
 	void __user *argp = (void __user *) arg;
-
+	wifi_power_flag = '0';
 	switch (cmd) {
 	case WIFI_IOCTL_STOP: {
 		if((aic_runmode == WIFI_IOCTL_START) || (aic_runmode == WIFI_IOCTL_START_TESTMODE)){
@@ -126,6 +153,11 @@
 		printk(KERN_ERR "wifi dev failed to initialize\n");
 		return -EFAULT;
 	}
+	ret = misc_register(&wifi_power_device);
+	if (ret) {
+		printk(KERN_ERR "wifi power dev failed to initialize\n");
+		return -EFAULT;
+	}
 	printk("qqq wifi_dev_init.\n");
 	return 0;
 }
@@ -133,5 +165,6 @@
 void  wifi_dev_exit(void)
 {
 	misc_deregister(&wifi_device);
+	misc_deregister(&wifi_power_device);
 }
 
diff --git a/lynq/S300AI/ap/project/zx297520v3/prj_cpe/fs/normal/rootfs/etc/rc b/lynq/S300AI/ap/project/zx297520v3/prj_cpe/fs/normal/rootfs/etc/rc
index 69b5a04..00d7aef 100755
--- a/lynq/S300AI/ap/project/zx297520v3/prj_cpe/fs/normal/rootfs/etc/rc
+++ b/lynq/S300AI/ap/project/zx297520v3/prj_cpe/fs/normal/rootfs/etc/rc
@@ -287,3 +287,6 @@
 cwmpd &
 fi
 /sbin/wefota &
+if [ -e /dev/wifi_power_device ]; then
+	/sbin/watch_aicwf.sh &
+fi
diff --git a/lynq/S300AI/ap/project/zx297520v3/prj_cpe/fs/normal/rootfs/sbin/watch_aicwf.sh b/lynq/S300AI/ap/project/zx297520v3/prj_cpe/fs/normal/rootfs/sbin/watch_aicwf.sh
new file mode 100644
index 0000000..930d58f
--- /dev/null
+++ b/lynq/S300AI/ap/project/zx297520v3/prj_cpe/fs/normal/rootfs/sbin/watch_aicwf.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+if [ -e /dev/wifi_power_device ]; then
+    echo "wifi power device exist" > /dev/ttyS1
+else
+    echo "wifi power device not exist" > /dev/ttyS1
+    exit 0
+fi
+while :; do
+    num=$(cat /dev/wifi_power_device)
+    sleep 5
+    if [ "$num" -eq 1 ]; then
+		wifi_flag_test 0
+		sleep 2
+		wifi_flag_test 1
+		sleep 25
+        echo "wifi reset done" > /dev/ttyS1
+    fi
+done
\ No newline at end of file