[Bugfix][API-1022] fix can't get connect ap ip of iQOO pro
[Bugfix][API-1031] fix can't get hostname

Change-Id: I7dc3bfa8e913c6326b5d214d1c5d6fb0913dece5
diff --git a/src/lynq/lib/liblynq-wifi6/libwifi6.c b/src/lynq/lib/liblynq-wifi6/libwifi6.c
index 96c4579..51b3ea2 100755
--- a/src/lynq/lib/liblynq-wifi6/libwifi6.c
+++ b/src/lynq/lib/liblynq-wifi6/libwifi6.c
@@ -1075,6 +1075,9 @@
 static int inner_get_hostname_by_ip(char *ip, char *hostname) {
     struct in_addr addr ={0};
     struct hostent *ht;
+    char cmd[64] = {0};
+    char * p;
+    int ret;
 
     if (ip == NULL || *ip == '\0' || hostname == NULL)
     {
@@ -1093,6 +1096,19 @@
 
     if (ht == NULL)
     {
+        hostname[0] = '\0';
+        sprintf(cmd, "grep -F '%s' /run/wg870/ap0.lease | awk '{print $4}' | tail -1", ip);
+        ret = exec_cmd(cmd, hostname, 32);
+        if (ret == 0)
+        {
+            p = strchr(hostname, '\n');
+            if (p != NULL)
+            {
+                *p = '\0';
+            }
+            return 0;
+        }
+        hostname[0] = '\0';
         RLOGE("---gethostbyaddr fail\n");
         herror(NULL);
         return -1;
@@ -2851,7 +2867,7 @@
 
 
     DO_OK_FAIL_REQUEST(cmd_disconnect);
-    system("echo \"\" > /tmp/dhcpcd.log");
+    system("echo \"\" > /tmp/wlan0_dhcpcd_router");
     usleep(200*1000);
 
     ret = inner_sta_start_stop(net_no, 1, 1);
@@ -3696,7 +3712,7 @@
     if (ip[0] == '\0' || strchr(ip, ':') != NULL) //temp change, not ok
     {
         ip[0] = '\0';
-        ret = exec_cmd("grep \"offered\" /tmp/dhcpcd.log | awk -F \"from\" '{print $2}'| tail -1", ip, 32);
+        ret = exec_cmd("grep \"new_router\" /tmp/wlan0_dhcpcd_router | awk '{print $2}'| tail -1", ip, 32);
         if (ret != 0)
         {
             ip[0] = '\0';
diff --git a/src/lynq/lib/liblynq-wifi6/scripts/start_stop_ap.sh b/src/lynq/lib/liblynq-wifi6/scripts/start_stop_ap.sh
index 5415602..259aa01 100755
--- a/src/lynq/lib/liblynq-wifi6/scripts/start_stop_ap.sh
+++ b/src/lynq/lib/liblynq-wifi6/scripts/start_stop_ap.sh
@@ -13,6 +13,7 @@
 	echo "bind-interfaces"  >> /run/wg870/dnsmasq.conf
 	echo "localise-queries" >> /run/wg870/dnsmasq.conf
 	echo "dhcp-range=192.168.15.2,192.168.15.14,255.255.255.240,1h"  >> /run/wg870/dnsmasq.conf
+	echo "dhcp-leasefile=/run/wg870/ap0.lease" >> /run/wg870/dnsmasq.conf
 	ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep
 	if [ $? != 0 ]; then
 		/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid -7 /run/wg870/dnsmasq.d --local-service -C /run/wg870/dnsmasq.conf -r /run/wg870
diff --git a/src/lynq/lib/liblynq-wifi6/scripts/start_stop_sta.sh b/src/lynq/lib/liblynq-wifi6/scripts/start_stop_sta.sh
index 5118808..4fd9ef0 100755
--- a/src/lynq/lib/liblynq-wifi6/scripts/start_stop_sta.sh
+++ b/src/lynq/lib/liblynq-wifi6/scripts/start_stop_sta.sh
@@ -7,7 +7,18 @@
         fi
 		ps -eo "%p %a" | grep "dhcpcd wlan0" | grep -v grep
 		if [ $? != 0 ];	then
-			dhcpcd wlan0 -t 0 -o domain_name_servers --noipv4ll -B -G -j /tmp/dhcpcd.log &
+			echo "" > /tmp/wlan0_dhcpcd_router
+			echo "#!/bin/sh" > /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			echo "if [ \"\$reason\" == \"BOUND\" -o \"\$reason\" == \"RENEW\" -o \"\$reason\" == \"REBIND\" ]; then" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			echo "    if [ \"\$new_routers\" != \"\" ]; then" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			echo "        for x in \$new_routers; do" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			echo "            echo \"new_router \$x\" > /tmp/wlan0_dhcpcd_router" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			echo "            ping -c2 \$x &" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			echo "        done" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			echo "    fi" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			echo "fi" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			chmod +x /run/wg870/wlan0_dhcpcd_run_hooks.sh
+			dhcpcd wlan0 -t 0 -o domain_name_servers --noipv4ll -4 -B -G -c /run/wg870/wlan0_dhcpcd_run_hooks.sh &
 		fi
 elif [ "$1" == "stop" ]; then
         ps -eo "%p %a" | grep "dhcpcd wlan0" | grep -v grep | awk '{print "kill "$1}' | sh