[Feature][ZXW-292]merge P56U06 version

Only Configure: No
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I922cf7b03b256d7dd5b0a6b73c3eac813f9512eb
diff --git a/ap/app/zte_comm/wlan/src/wlan-station.c b/ap/app/zte_comm/wlan/src/wlan-station.c
index ea2efcd..371635b 100755
--- a/ap/app/zte_comm/wlan/src/wlan-station.c
+++ b/ap/app/zte_comm/wlan/src/wlan-station.c
@@ -14,6 +14,10 @@
 #include "rtk_arch.h"

 #include <semaphore.h>

 #include <limits.h>

+//#include <sys/socket.h>

+//#include <netinet/in.h>

+#include <arpa/inet.h>

+

 #define  SUCCESS  "1"

 #define  FAILED   "0"

 #define REPLY_BUF_SIZE 4096 // wpa_supplicant's maximum size.

@@ -1267,7 +1271,11 @@
 //EAP-SIM/AKA, ÓëÔ­±¾Ð´µÄ802.1xÒ²²»Æ¥Å䣬µ¼ÖÂÎÞ·¨¸üÐÂÈȵãÐźÅ

 //ÐÞ¸ÄΪɨÃèÈȵãµÄ¼ÓÃÜÀàÐÍΪTKIP CCMP,Ö»ÒªÄÜÔÚ±£´æÈȵãÖÐÕÒµ½´Ë×Ö·û£¬ÔòÈÏΪÊÇͬһ¸öÈȵ㣬µ«ÊÇÎÞ·¨½â¾öÕæµÄÓÐÁ½¸öÏàͬµÄÈȵ㣬Õâ¸öÎÞ·¨Ê¶±ð

 			{

+#ifdef USE_CAP_SUPPORT

+				g_spot_list_p[i]->signal = scan_result->signal_db;

+#else

 				g_spot_list_p[i]->signal = scan_result->signal;

+#endif

 				break;

 			}

 		}

@@ -2743,6 +2751,90 @@
 

 }

 

+static int get_cur_ap_rssi(void)

+{

+    char *reply = NULL;

+	int rssi = 0;

+    char *start = NULL;

+	char *end = NULL;

+	

+	reply = sta_docmd("SIGNAL_POLL");

+	if (reply == NULL) {

+        wf_log("SIGNAL_POLL failed\n");

+        return 0;

+    }

+	

+	start = strstr(reply, "RSSI=");

+    if (start != NULL) {

+        start += strlen("RSSI="); // skip "RSSI="

+        rssi = strtol(start, &end, 10);

+        if (start == end) {

+            wf_log("Failed to convert RSSI\n");

+            return 0;

+        }

+    } else {

+        wf_log("Could not find RSSI\n");

+        return 0;

+    }

+    return rssi;

+}

+

+static int get_cur_ap_signal(char *mac)

+{

+	int rssi = 0;

+

+	int spot_num = 0;

+	int i = 0;

+

+	char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};

+	sc_cfg_get("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));

+

+	spot_num = atoi(wifi_profile_num);

+

+	for (i = 0; i < spot_num; i++) {

+		if (strcmp(g_spot_list_p[i]->mac, mac) == 0) {

+			rssi = (int)g_spot_list_p[i]->signal;

+			break;

+		}

+	}

+	

+	return rssi;

+}

+

+static unsigned char single_db_to_level(int rssi)

+{

+	unsigned char level = 0;

+

+	if (rssi > WIFI_STATION_SIGNAL_LEVEL4) {

+		level = 4;

+	} else if (rssi > WIFI_STATION_SIGNAL_LEVEL3) {//kw 3

+		level = 3;

+	} else if (rssi > WIFI_STATION_SIGNAL_LEVEL2) {

+		level = 2;

+	} else if (rssi > WIFI_STATION_SIGNAL_LEVEL1) {

+		level = 1;

+	} else {

+		level = 0;

+	}

+

+	return level;

+}

+

+static int netmask_length(const char *netmask)

+{

+    struct in_addr addr;

+	int count = 0;

+	int i = 0;

+	

+    inet_pton(AF_INET, netmask, &addr);

+    for (i = 0; i < 32; i++) {

+        if ((addr.s_addr >> i) & 1) {

+            count++;

+        }

+    }

+    return count;

+}

+

 int send_sta_status_to_cap(int status, int reason)

 {

 	int ret = 0;

@@ -2758,10 +2850,12 @@
 		char wifi_mac[20] = {0};

 		char wifi_signal[20] = {0};

 		sc_cfg_get("EX_mac", wifi_mac, sizeof(wifi_mac));

-		sc_cfg_get("EX_signal", wifi_signal, sizeof(wifi_signal));

+		//sc_cfg_get("EX_signal", wifi_signal, sizeof(wifi_signal));

 		

 		strncpy(sta_stat.ap_bssid, wifi_mac, sizeof(sta_stat.ap_bssid) - 1);

-		sta_stat.signal_level = atoi(wifi_signal);

+		//sta_stat.rssi = get_cur_ap_signal(wifi_mac);

+		sta_stat.rssi = get_cur_ap_rssi();

+		sta_stat.signal_level = single_db_to_level(sta_stat.rssi);

 	}

 

 	if (sta_stat.status == IN_WIFI_STA_STATUS_ERROR) {

@@ -2779,18 +2873,74 @@
 		//wlan

 		sc_cfg_get("wifiwan", nv_wifiwan, sizeof(nv_wifiwan));

 		//ipv4

+		sta_stat.has_addr = 1;

+		//ip

 		snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_ip", nv_wifiwan);

 		sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));

-		sta_stat.has_addr = 1;

-		strncpy(sta_stat.str_addr, wifiwan_ip, sizeof(sta_stat.str_addr) - 1);

-

+		strncpy(sta_stat.addr.addr, wifiwan_ip, sizeof(sta_stat.addr.addr) - 1);

+		//netmask

+		memset(nv_wifiwan_ip, 0, sizeof(nv_wifiwan_ip));

+		memset(wifiwan_ip, 0, sizeof(wifiwan_ip));

+		snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_nm", nv_wifiwan);

+		sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));

+		strncpy(sta_stat.addr.netmask, wifiwan_ip, sizeof(sta_stat.addr.netmask) - 1);

+		sta_stat.addr.subnet_bits = netmask_length(sta_stat.addr.netmask);

+		//gateway

+		memset(nv_wifiwan_ip, 0, sizeof(nv_wifiwan_ip));

+		memset(wifiwan_ip, 0, sizeof(wifiwan_ip));

+		snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_gw", nv_wifiwan);

+		sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));

+		strncpy(sta_stat.addr.gateway, wifiwan_ip, sizeof(sta_stat.addr.gateway) - 1);

+		//pdns

+		memset(nv_wifiwan_ip, 0, sizeof(nv_wifiwan_ip));

+		memset(wifiwan_ip, 0, sizeof(wifiwan_ip));

+		snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_pridns", nv_wifiwan);

+		sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));

+		strncpy(sta_stat.addr.dnsp, wifiwan_ip, sizeof(sta_stat.addr.dnsp) - 1);

+		//sdns

+		memset(nv_wifiwan_ip, 0, sizeof(nv_wifiwan_ip));

+		memset(wifiwan_ip, 0, sizeof(wifiwan_ip));

+		snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_secdns", nv_wifiwan);

+		sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));

+		strncpy(sta_stat.addr.dnss, wifiwan_ip, sizeof(sta_stat.addr.dnss) - 1);

+		

 		//ipv6

-		snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_ip", nv_wifiwan);

-		sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));

 		sc_cfg_get("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));

 		if (atoi(wbwanv6_enable) == 1) {

 			sta_stat.has_addr6 = 1;

-			strncpy(sta_stat.str_addr6, wifiwan_ipv6, sizeof(sta_stat.str_addr6) - 1);

+			snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_ip", nv_wifiwan);

+			sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));

+			strncpy(sta_stat.addr6.addr, wifiwan_ipv6, sizeof(sta_stat.addr6.addr) - 1);

+			//prefix

+			memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));

+			memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));

+			snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_prefix_info", nv_wifiwan);

+			sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));

+			strncpy(sta_stat.addr6.prefix, wifiwan_ipv6, sizeof(sta_stat.addr6.prefix) - 1);

+			//len

+			memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));

+			memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));

+			snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_prefix_len", nv_wifiwan);

+			sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));

+			sta_stat.addr6.prefix_bits = atoi(wifiwan_ipv6);

+			//gateway

+			memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));

+			memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));

+			snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_gw", nv_wifiwan);

+			sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));

+			strncpy(sta_stat.addr6.gateway, wifiwan_ipv6, sizeof(sta_stat.addr6.gateway) - 1);

+			//pdns

+			memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));

+			memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));

+			snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_pridns_auto", nv_wifiwan);

+			sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));

+			strncpy(sta_stat.addr6.dnsp, wifiwan_ipv6, sizeof(sta_stat.addr6.dnsp) - 1);

+			//sdns

+			memset(nv_wifiwan_ipv6, 0, sizeof(nv_wifiwan_ipv6));

+			memset(wifiwan_ipv6, 0, sizeof(wifiwan_ipv6));

+			snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_secdns_auto", nv_wifiwan);

+			sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));

+			strncpy(sta_stat.addr6.dnss, wifiwan_ipv6, sizeof(sta_stat.addr6.dnss) - 1);

 		}

 	}

 	

@@ -2931,7 +3081,7 @@
 			g_cap_scan = 0;

 		}

 	}

-	

+

 }

 #endif