[Feature][ZXW-265]merge P56U03 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: I873f6df64e2605a77b8b8bfec35b21e7f33c5444
diff --git a/ap/app/zte_comm/wlan/inc/wlan-station.h b/ap/app/zte_comm/wlan/inc/wlan-station.h
index f0de3cb..6ba1be7 100755
--- a/ap/app/zte_comm/wlan/inc/wlan-station.h
+++ b/ap/app/zte_comm/wlan/inc/wlan-station.h
@@ -23,6 +23,12 @@
 //#include "../include/errorcode.h"
 //#include "../include/netapi.h"
 
+typedef struct
+{
+    int freq;
+    int ch;
+} wlan_sta_freq_ch_t;
+
 void   wlan_station_init(void);
 BOOL wlan_station_is_station_msg(unsigned short msg);
 void   wlan_station_msg_handle(MSG_BUF *pMsg);
diff --git a/ap/app/zte_comm/wlan/src/wifi_ap_ctrl.c b/ap/app/zte_comm/wlan/src/wifi_ap_ctrl.c
index 0c398e3..1a14627 100755
--- a/ap/app/zte_comm/wlan/src/wifi_ap_ctrl.c
+++ b/ap/app/zte_comm/wlan/src/wifi_ap_ctrl.c
@@ -60,6 +60,10 @@
 #elif defined(__AIC_8800DW_CHIP__)
 #define HT_CAPAB_40 "[LDPC][HT40+][HT40-][SHORT-GI-20][SHORT-GI-40]"
 #define HT_CAPAB_20 "[HT20][LDPC][SHORT-GI-20]"
+
+#define VHT_CAPAB_160 "[SHORT-GI-80][SHORT-GI-160][VHT160]"//unsupport
+#define VHT_CAPAB_80 "[VHT40+]" //invalid parameter [SHORT-GI-80][MAX-A-MPDU-LEN-EXP7]
+#define VHT_CAPAB_40 "[HT40+][HT40-][SHORT-GI-20][SHORT-GI-40]" //5G ht
 #endif
 
 /**********mmi wlan wps status***************/
@@ -104,6 +108,11 @@
 #ifdef USE_CAP_SUPPORT
 #define PATH_MAX 256
 #define INT_MAX 2147483647
+
+extern int g_work_mode;
+
+extern void acl_mode_set();
+extern void acl_mode_set_5g();
 #endif
 
 extern struct   wlan_ap_server  * ap_server;
@@ -887,6 +896,555 @@
     close(fd);
     return ret;
 }
+
+#ifdef USE_CAP_SUPPORT
+void wlan_ap_get_para_5g(struct wlan_ap_server *ap_svr)
+{
+	struct  wlan_ap_para *  para = &ap_svr->ap_para;
+	
+	sc_cfg_get ("wifi_set_flags", para->wifi_set_flags, NVIO_WIFI_LEN_8-1);
+	sc_cfg_get ("SSID1_5g", para->ssid, WIFI_STATION_SSID_LEN-1);
+	sc_cfg_get ("HideSSID_5g", para->ignore_broadcast_ssid, NVIO_WIFI_LEN_8-1);
+	sc_cfg_get ("AuthMode_5g", para->auth_mode, WIFI_STATION_AUTH_MODE_LEN-1);
+	sc_cfg_get ("WPAPSK1_5g", para->password, WIFI_STATION_SPOT_PASSWORD_LEN-1);
+	sc_cfg_get ("wifi_11n_cap_5g", para->wifi_11n_cap, NVIO_WIFI_LEN_8-1);//bandwhidh
+	//sc_cfg_get ("wifi_band_5g", para->wifi_band, NVIO_WIFI_LEN_8-1);
+	sc_cfg_get ("WirelessMode_5g", para->WirelessMode, NVIO_WIFI_LEN_8-1);
+	sc_cfg_get ("Channel_5g", para->Channel, NVIO_WIFI_LEN_8-1);
+	
+	sc_cfg_get ("CountryCode_5g", para->CountryCode, NVIO_WIFI_LEN_8-1);
+	if (0 == strcmp(para->CountryCode, "NONE")) {
+		strcpy(para->CountryCode, "00");
+	}
+	
+	sc_cfg_get ("wifi_coverage", para->wifi_coverage, NVIO_WIFI_LEN_16-1);
+	sc_cfg_get ("MAX_Access_num_5g", para->max_num_sta, NVIO_WIFI_LEN_8-1);
+	sc_cfg_get ("ACL_mode_5g", para->accesspolicy0, NVIO_WIFI_LEN_8-1);
+
+	wf_log("5G SSID1=%s HideSSID=%s, AuthMode=%s, WPAPSK1=%s, wifi_11n_cap=%s, \n"
+		"wifi_band=%s, WirelessMode=%s, Channel=%s, CountryCode=%s, wifi_coverage=%s, MAX_Access_num=%s, AccessPolicy0=%s\n", 
+		para->ssid, para->ignore_broadcast_ssid, para->auth_mode, para->password, para->wifi_11n_cap, 
+		para->wifi_band, para->WirelessMode,para->Channel, para->CountryCode, para->wifi_coverage, para->max_num_sta,para->accesspolicy0);
+
+	sc_cfg_set("tmp_channel", para->Channel);
+
+	char m_ssid_enable[8] = {0};
+	sc_cfg_get ("m_ssid_enable", m_ssid_enable, sizeof (m_ssid_enable));	
+	if(strcmp (m_ssid_enable, "1") == 0){	//v3v not use
+		sc_cfg_get ("m_SSID_5g", para->m_ssid, WIFI_STATION_SSID_LEN-1);
+		sc_cfg_get ("m_HideSSID_5g", para->m_ignore_broadcast_ssid, NVIO_WIFI_LEN_8-1);
+		sc_cfg_get ("m_AuthMode_5g", para->m_auth_mode, WIFI_STATION_AUTH_MODE_LEN-1);
+		sc_cfg_get ("m_WPAPSK1_5g", para->m_password, WIFI_STATION_SPOT_PASSWORD_LEN-1);
+		sc_cfg_get ("m_MAX_Access_num_5g", para->m_max_num_sta, NVIO_WIFI_LEN_8-1);
+		wf_log("5G m_SSID=%s m_HideSSID=%s, m_AuthMode=%s, m_password=%s,MAX_Station_num:%s m_MAX_Access_num=%s\n", 
+		para->m_ssid, para->m_ignore_broadcast_ssid, para->m_auth_mode, para->m_password,para->max_num_sta, para->m_max_num_sta);
+	}	
+
+}
+
+static int get_centr_freq_seg0_idx(int band, int chan)
+{
+	int center_segment0 = 0;
+	
+	if (band == 160) {//20/40/80/160
+		if (chan >= 36 && chan <= 64) {
+			center_segment0 = 50;
+		}
+		else if (chan >= 100 && chan <= 128) {
+			center_segment0 = 114;
+		}
+		else {
+			center_segment0 = 0;
+		}
+		
+	}
+	else if (band == 80) {//20/40/80
+		//center_segment0 = 0;
+		if (chan >= 36 && chan <= 48) {
+			center_segment0 = 42;
+		}
+		else if (chan >= 52 && chan <= 64) {
+			center_segment0 = 58;
+		}
+		else if (chan >= 100 && chan <= 112) {
+			center_segment0 = 106;
+		}
+		else if (chan >= 116 && chan <= 128) {
+			center_segment0 = 122;
+		}
+		else if (chan >= 132 && chan <= 144) {
+			center_segment0 = 138;
+		}
+		else if (chan >= 149 && chan <= 161) {
+			center_segment0 = 155;
+		}
+		else {
+			center_segment0 = 0;
+		}
+	}
+	else if (band == 40) {//20/40
+		center_segment0 = 0;
+	}
+	else {
+		center_segment0 = 0;;
+	}
+
+	return center_segment0;
+}
+
+static void wlan_80211Mode_config_5g(char *wirelessMode)
+{
+	if (!strcmp(wirelessMode, "4")) {//11a/n mixed mode
+		ap_docmd("SET hw_mode a", NULL);
+		ap_docmd("SET ieee80211n 1", NULL);
+		ap_docmd("SET ieee80211ac 0", NULL);
+		ap_docmd("SET ieee80211ax 0", NULL);
+	}
+	else if (!strcmp(wirelessMode, "5")) {//11a/an/ac
+		ap_docmd("SET hw_mode a", NULL);
+		ap_docmd("SET ieee80211n 1", NULL);
+		ap_docmd("SET ieee80211ac 1", NULL);
+		ap_docmd("SET ieee80211ax 0", NULL);
+	}	
+	else if (!strcmp(wirelessMode, "6")) {//11a/an/ac/ax
+		ap_docmd("SET hw_mode a", NULL);
+		ap_docmd("SET ieee80211n 1", NULL);
+		ap_docmd("SET ieee80211ac 1", NULL);
+		ap_docmd("SET ieee80211ax 1", NULL);
+		
+	}	
+	else {
+		ap_docmd("SET hw_mode a", NULL);
+		ap_docmd("SET ieee80211n 1", NULL);
+		wf_log("wirelessMode=%s not support", wirelessMode);
+	}
+
+}
+static void wlan_set_ht_5g(char *htMode)
+{
+	if (!strcmp(htMode, "6")) {//20/40/80/160
+		ap_docmd("SET he_oper_chwidth", "2");
+		ap_docmd("SET vht_oper_chwidth", "2");
+		ap_docmd("SET ht_capab", VHT_CAPAB_40);
+		ap_docmd("SET vht_capab", VHT_CAPAB_160);
+	}
+	else if (!strcmp(htMode, "4")) {//20/40/80
+		ap_docmd("SET he_oper_chwidth", "1");
+		ap_docmd("SET vht_oper_chwidth", "1");
+		ap_docmd("SET ht_capab", VHT_CAPAB_40);
+		ap_docmd("SET vht_capab", VHT_CAPAB_80);
+	}
+	else if (!strcmp(htMode, "1")) {//20/40
+		ap_docmd("SET he_oper_chwidth", "0");
+		ap_docmd("SET vht_oper_chwidth", "0");
+		ap_docmd("SET ht_capab", VHT_CAPAB_40);
+	}
+	else { //0
+		//defualt use 20M
+		ap_docmd("SET ht_capab", HT_CAPAB_20);
+		ap_docmd("SET vht_oper_chwidth", "0");
+	}
+
+}
+static void wlan_set_channel_5g(char *channel, char *htMode)
+{
+	char idx0[8] = {0};
+	int idx0_i = 0;
+	
+	if (!strcmp(htMode, "6")) {//20/40/80/160
+		idx0_i = get_centr_freq_seg0_idx(160, atoi(channel));
+	}
+	else if (!strcmp(htMode, "4")) {//20/40/80
+		idx0_i = get_centr_freq_seg0_idx(80, atoi(channel));
+	}
+	else if (!strcmp(htMode, "1")) {//20/40
+		idx0_i = get_centr_freq_seg0_idx(40, atoi(channel));
+	}
+	else {
+		idx0_i = get_centr_freq_seg0_idx(20, atoi(channel));
+	}
+
+	snprintf(idx0, sizeof(idx0), "%d", idx0_i);
+	//when channel=0, can't be set at runtime, idx has a value(channel id)?
+	ap_docmd("SET vht_oper_centr_freq_seg0_idx", idx0);
+	ap_docmd("SET he_oper_centr_freq_seg0_idx", idx0);
+	//80+80
+	//ap_docmd_5g("SET vht_oper_centr_freq_seg1_idx", "0");
+	//ap_docmd_5g("SET he_oper_centr_freq_seg1_idx", "0");
+	
+	if (0 == strcmp(channel, "165") && 0 != strcmp(htMode, "0")) {
+		ap_docmd("SET ht_capab", HT_CAPAB_20);
+		ap_docmd("SET he_oper_chwidth", "0");
+		ap_docmd("SET vht_oper_chwidth", "0");
+	}
+	ap_docmd("SET channel", channel);
+}
+static void wlan_advance_set_5g(struct wlan_ap_para *para)
+{
+
+	wlan_80211Mode_config_5g(para->WirelessMode); // an wang kou ge li
+	wlan_set_ht_5g(para->wifi_11n_cap);
+	wlan_set_channel_5g(para->Channel, para->wifi_11n_cap);
+
+}
+
+void wifi_config_ap_5g(struct wlan_ap_server *ap_svr)
+{
+	struct  wlan_ap_para*  para = &ap_svr->ap_para;
+	char max_Access_num_bbak[16]={0};
+
+	unsigned int flags = 0;
+	flags = atoi(para->wifi_set_flags);
+	wf_log("wifi_set_flags=0x%x", flags);
+
+	if( 0 == flags ){
+		//quick_setup¿ìËÙÉèÖÃûÖÃ
+		flags = ZTE_WLAN_SSID_SET|ZTE_WLAN_BROADCAST_SET|ZTE_WLAN_BASIC_SECURITY_SET;
+	}
+	
+	if( flags & ZTE_WLAN_SSID_SET){
+		ap_docmd("SET ssid", para->ssid);
+//		hostapd_conf_change_para("ssid", para->ssid);
+	}
+	if( flags & ZTE_WLAN_BROADCAST_SET){
+		ap_docmd("SET ignore_broadcast_ssid", para->ignore_broadcast_ssid);
+//		hostapd_conf_change_para("ssid", para->ssid);
+		ap_docmd("SET wps_state", "2");
+	}
+	if( flags & ZTE_WLAN_BASIC_SECURITY_SET){
+		if (!strcmp (para->auth_mode, "WPAPSKWPA2PSK") || !strcmp (para->auth_mode, "WPA-PSK/WPA2-PSK")) {
+			ap_docmd("SET wpa","3");
+			ap_docmd("SET ieee80211w","0");
+			ap_docmd("SET wpa_key_mgmt","WPA-PSK");
+			ap_docmd("SET wpa_pairwise","TKIP CCMP");
+			ap_docmd("SET rsn_pairwise","TKIP CCMP");
+			ap_docmd("SET wpa_passphrase",para->password);
+		} else if (!strcmp(para->auth_mode, "WPA2PSK")) {
+			ap_docmd("SET wpa","2");
+			ap_docmd("SET ieee80211w","0");
+			ap_docmd("SET wpa_key_mgmt","WPA-PSK");
+			ap_docmd("SET wpa_pairwise","TKIP");
+			ap_docmd("SET rsn_pairwise","CCMP");
+			ap_docmd("SET wpa_passphrase",para->password);
+		} else if (!strcmp(para->auth_mode, "WPA3Personal")) {
+			ap_docmd("SET wpa","2");
+			ap_docmd("SET ieee80211w","2");
+			ap_docmd("SET wpa_key_mgmt","SAE");
+			ap_docmd("SET wpa_pairwise","CCMP");
+			ap_docmd("SET rsn_pairwise","CCMP");
+			ap_docmd("SET wpa_passphrase",para->password);
+			ap_docmd("SET sae_pwe","2");
+		} else if (!strcmp(para->auth_mode, "WPA2WPA3")) {
+			ap_docmd("SET wpa","2");
+			ap_docmd("SET ieee80211w","1");
+			ap_docmd("SET wpa_key_mgmt","SAE WPA-PSK");
+			ap_docmd("SET wpa_pairwise","CCMP");
+			ap_docmd("SET rsn_pairwise","CCMP");
+			ap_docmd("SET wpa_passphrase",para->password);
+			ap_docmd("SET sae_pwe","2");
+		} else if (!strcmp(para->auth_mode, "OPEN")) {
+			ap_docmd("SET wpa","0");
+		}
+	}
+		
+	if( flags & ZTE_WLAN_MAX_ACCESS_NUM_SET){
+		ap_docmd("SET max_num_sta", para->max_num_sta);		
+		sc_cfg_get("MAX_Access_num_bbak", max_Access_num_bbak, sizeof(max_Access_num_bbak));
+		if(strlen(max_Access_num_bbak) != 0 && strcmp(max_Access_num_bbak,"0")){
+			sc_cfg_set("MAX_Access_num_bbak","0");
+		}
+	}
+
+	if ((flags & ZTE_WLAN_COUNTRY_SET) || (flags & ZTE_WLAN_CHANNEL_SET) || (flags & ZTE_WLAN_WIRELESS_MODE_SET)) {
+		ap_docmd("SET country_code", para->CountryCode);
+		wlan_advance_set_5g(para);
+	}
+	
+	if( flags & ZTE_WLAN_POWER_SET) {
+#if defined(__AIC_8800DW_CHIP__)
+		wlan_set_wifiConverage_aic(ap_svr->drv_proxy.iface_name, para->wifi_coverage);
+		wf_log("ZTE_WLAN_POWER_SET:%08x", flags);
+		return;
+#else
+		wlan_set_wifiConverage(para->wifi_coverage);
+#endif
+	}
+
+	//ap_docmd("RELOAD", NULL);
+	ap_docmd("DISABLE", NULL);
+	ap_docmd("ENABLE", NULL);
+	wlan_set_txpwr();
+}
+
+static void wlan_get_ht_5g(struct wlan_ap_para *para, char *ht_conf, int ht_len)
+{
+	char ieee_mode[64] = {0};
+	char ht_cap[172] = {0};
+	int idx0 = 0;
+
+	if (!strcmp(para->WirelessMode, "4")) {//11a/n mixed mode
+		snprintf(ieee_mode, sizeof(ieee_mode), "ieee80211n=1\n");
+	}
+	else if (!strcmp(para->WirelessMode, "5")) {//11a/an/ac
+		snprintf(ieee_mode, sizeof(ieee_mode), "ieee80211n=1\nieee80211ac=1\n");
+	}	
+	else if (!strcmp(para->WirelessMode, "6")) {//11a/an/ac/ax
+		snprintf(ieee_mode, sizeof(ieee_mode), "ieee80211n=1\nieee80211ac=1\nieee80211ax=1\n");
+	}	
+	else {
+		snprintf(ieee_mode, sizeof(ieee_mode), "ieee80211n=1\n");
+	}
+
+	if (0 == strcmp(para->wifi_11n_cap, "6")) {
+		snprintf(ht_cap, sizeof(ht_cap), "ht_capab=%s\nvht_capab=%s\nhe_oper_chwidth=2\nvht_oper_chwidth=2\n",
+			VHT_CAPAB_40, VHT_CAPAB_160);
+		idx0 = get_centr_freq_seg0_idx(160, atoi(para->Channel));
+	}
+	else if (0 == strcmp(para->wifi_11n_cap, "4")) {
+		snprintf(ht_cap, sizeof(ht_cap), "ht_capab=%s\nvht_capab=%s\nhe_oper_chwidth=1\nvht_oper_chwidth=1\n",
+			VHT_CAPAB_40, VHT_CAPAB_80);
+		idx0 = get_centr_freq_seg0_idx(80, atoi(para->Channel));
+	}
+	else if (0 == strcmp(para->wifi_11n_cap, "1")) {
+		snprintf(ht_cap, sizeof(ht_cap), "ht_capab=%s\nhe_oper_chwidth=0\nvht_oper_chwidth=0\n",
+			VHT_CAPAB_40);
+		idx0 = get_centr_freq_seg0_idx(40, atoi(para->Channel));
+	}
+	else {
+		snprintf(ht_cap, sizeof(ht_cap), "ht_capab=%s\nhe_oper_chwidth=0\nvht_oper_chwidth=0\n",
+			HT_CAPAB_20);
+		idx0 = get_centr_freq_seg0_idx(20, atoi(para->Channel));
+	}
+#if 1
+	//channel 149~161, if 160M, to 80M
+	//ch 165, to 20M
+	//country code BZ\BO, not support 160M, to 80M
+	if (0 != strcmp(para->wifi_11n_cap, "0") && 0 == strcmp(para->Channel, "165")) {//error: please set correct channel\bandwith
+		snprintf(ht_cap, sizeof(ht_cap), "ht_capab=%s\nhe_oper_chwidth=0\nvht_oper_chwidth=0\n",
+			HT_CAPAB_20);
+		idx0 = get_centr_freq_seg0_idx(20, atoi(para->Channel));
+		wf_log("error: please set correct channel(%s)-bandwith(%s) nv!!", para->Channel, para->wifi_11n_cap);
+	}
+	else if ((0 == strcmp(para->wifi_11n_cap, "6")) && 
+		(0 == strcmp(para->Channel, "149") || 0 == strcmp(para->Channel, "153") ||
+		0 == strcmp(para->Channel, "157") || 0 == strcmp(para->Channel, "161"))) {
+		snprintf(ht_cap, sizeof(ht_cap), "ht_capab=%s\nvht_capab=%s\nhe_oper_chwidth=1\nvht_oper_chwidth=1\n",
+			VHT_CAPAB_40, VHT_CAPAB_80);
+		idx0 = get_centr_freq_seg0_idx(80, atoi(para->Channel));
+		wf_log("error: please set correct channel(%s)-bandwith(%s) nv!!", para->Channel, para->wifi_11n_cap);
+	}
+	else if ((0 == strcmp(para->wifi_11n_cap, "6")) && (0 == strcmp(para->Channel, "0"))
+		&& (0 == strcmp(para->CountryCode, "BZ") || 0 == strcmp(para->CountryCode, "HN") ||
+		0 == strcmp(para->CountryCode, "PK") || 0 == strcmp(para->CountryCode, "BD") ||
+		0 == strcmp(para->CountryCode, "BO") || 0 == strcmp(para->CountryCode, "JO") ||
+		0 == strcmp(para->CountryCode, "KE"))) {
+		snprintf(ht_cap, sizeof(ht_cap), "ht_capab=%s\nvht_capab=%s\nhe_oper_chwidth=1\nvht_oper_chwidth=1\n",
+			VHT_CAPAB_40, VHT_CAPAB_80);
+		idx0 = get_centr_freq_seg0_idx(80, atoi(para->Channel));
+		wf_log("error: please set correct countrycode(%s)-bandwith(%s) nv!!", para->CountryCode, para->wifi_11n_cap);
+	}
+#endif
+	//no 80+80
+	//"vht_oper_centr_freq_seg1_idx=0\n" //ac
+	//"he_oper_centr_freq_seg1_idx=0\n" //ax
+
+	snprintf(ht_conf, ht_len, "%s%svht_oper_centr_freq_seg0_idx=%d\nhe_oper_centr_freq_seg0_idx=%d\n", 
+		ieee_mode, ht_cap, idx0, idx0);
+
+}
+
+int wlan_ap_save_config_5g(struct wlan_ap_server *ap_svr) 
+{
+	int ret = 0;
+	int i = 0;
+	int fd;
+	char *wbuf = NULL;
+	char *fbuf = NULL;
+	char *sbuf = NULL;
+	char *sbuf2 = NULL;
+	struct	wlan_ap_para*  para = &ap_svr->ap_para;
+
+	char wifi_mac[64] = {0};
+	char m_read_mac[32] = {0};
+	char m_ssid_enable[8] = {0};
+	sc_cfg_get ("wifi_mac", wifi_mac, sizeof(wifi_mac));
+	str_remove_chr(wifi_mac, ':');	
+
+	//acs_num_scans
+	char acs_num[8] = {0};
+	sc_cfg_get ("wifi_acs_num", acs_num, sizeof(acs_num));
+	
+	char w11n_ht_cap[256] = {0};
+	wlan_get_ht_5g(para, w11n_ht_cap, sizeof(w11n_ht_cap));
+
+	sc_cfg_get ("m_ssid_enable", m_ssid_enable, sizeof (m_ssid_enable));	
+
+	asprintf(&wbuf, "interface=wlan0\n"
+			"driver=nl80211\n"
+			"bridge=br0\n"
+			"ctrl_interface=/etc_rw/wifi/hostapd\n" 		
+			"logger_syslog= 8\n"
+			"logger_syslog_level=2\n"
+			"logger_stdout=8\n"
+			"logger_stdout_level=2\n"			
+			"ssid=%s\n"
+			"ignore_broadcast_ssid=%s\n"
+		
+			"channel=%s\n"
+			"acs_num_scans=%s\n"
+
+			//"ieee80211ac=1\n"
+			//"ieee80211ax=1\n"
+			"dtim_period=1\n"
+			
+			//TX MCS11
+			"he_basic_mcs_nss_set=65534\n"
+			
+			"wmm_enabled=1\n"
+
+			"require_ht=0\n"
+			"require_vht=0\n"
+			"%s"
+			
+			//"ieee80211n=1\n"
+			"hw_mode=a\n"
+			"ieee80211d=1\n"
+			"wowlan_triggers=any\n"
+		
+			"country_code=%s\n"
+			"max_num_sta=%s\n"
+			"macaddr_acl=%d\n"
+			"accept_mac_file=/etc_rw/wifi/hostapd.accept\n"
+			"deny_mac_file=/etc_rw/wifi/hostapd.deny\n"
+
+			"ap_max_inactivity=10\n"
+
+			"wps_state=2\n"
+			"eap_server=1\n"
+			"ap_setup_locked=1\n"
+			"wps_pin_requests=/etc_rw/wifi/hostapd_wps_pin_requests\n"
+			"manufacturer=zxic\n"
+			"model_name=MF922\n"
+			"model_number=7520V3WLAN\n"
+			"serial_number=%s\n"
+			"device_type=6-0050F204-1\n"
+			"os_version=01020300\n"
+			"config_methods=virtual_push_button\n",
+			para->ssid, para->ignore_broadcast_ssid,
+			para->Channel, acs_num, 
+
+			w11n_ht_cap,
+
+			para->CountryCode,	 para->max_num_sta, 
+			acl_mode_value_transist(para->accesspolicy0), wifi_mac+6);
+
+	if (!strcmp (para->auth_mode, "WPAPSKWPA2PSK") || !strcmp (para->auth_mode, "WPA-PSK/WPA2-PSK")) {
+		asprintf(&fbuf, "%swpa=3\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP CCMP\nrsn_pairwise=TKIP CCMP\nwpa_passphrase=%s\nwpa_group_rekey=3600\n", wbuf, para->password);
+	} else if (!strcmp(para->auth_mode, "WPA2PSK")) {
+		asprintf(&fbuf, "%swpa=2\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP\nwpa_passphrase=%s\nwpa_group_rekey=3600\n", wbuf, para->password);
+	} else if (!strcmp(para->auth_mode, "WPA3Personal")) {
+		asprintf(&fbuf, "%swpa=2\nwpa_key_mgmt=SAE\nwpa_pairwise=CCMP\nrsn_pairwise=CCMP\nieee80211w=2\nwpa_passphrase=%s\nwpa_group_rekey=3600\nsae_pwe=2\n", wbuf, para->password);
+	} else if (!strcmp(para->auth_mode, "WPA2WPA3")) {
+		asprintf(&fbuf, "%swpa=2\nwpa_key_mgmt=SAE WPA-PSK\nwpa_pairwise=CCMP\nrsn_pairwise=CCMP\nieee80211w=1\nwpa_passphrase=%s\nwpa_group_rekey=3600\nsae_pwe=2\n", wbuf, para->password);
+	} else if (!strcmp(para->auth_mode, "OPEN")) {
+		asprintf(&fbuf, "%swpa=0\n", wbuf);
+	} else {//kw
+		wf_log("Unsupport auth_mode: %s", para->auth_mode);
+		free(wbuf);
+		return -1;
+	}
+	
+	if (strcmp (m_ssid_enable, "1") == 0) { 
+		sc_cfg_get ("m_wifi_mac", m_read_mac, sizeof (m_read_mac));
+		sc_cfg_get ("m_wifi_mac", wifi_mac, sizeof (wifi_mac));
+		str_remove_chr(wifi_mac, ':');	
+		wf_log("asprintf sbuf m_read_mac : %s,wifi_mac : %s wifi_mac+6 : %s",m_read_mac,wifi_mac,wifi_mac+6);
+		asprintf(&sbuf, "%sbss=wlan0-va1\n"
+			"bssid=%s\n"
+			"ssid=%s\n"
+			"ignore_broadcast_ssid=%s\n"
+			"max_num_sta=%s\n"
+			"bridge=br0\n"
+			"ctrl_interface=/etc_rw/wifi/hostapd\n"
+			"dtim_period=1\n"
+			"wmm_enabled=1\n"
+			"wowlan_triggers=any\n"
+			"macaddr_acl=%d\n"
+			"accept_mac_file=/etc_rw/wifi/hostapd.accept\n"
+			"deny_mac_file=/etc_rw/wifi/hostapd.deny\n"
+			
+			"ap_max_inactivity=10\n"
+
+			"wps_state=2\n"
+			"eap_server=1\n"
+			"ap_setup_locked=1\n"
+			"wps_pin_requests=/etc_rw/wifi/hostapd_wps_pin_requests_2\n"
+			"manufacturer=zxic_2\n"
+			"model_name=MF922_2\n"
+			"model_number=7520V3WLAN_2\n"
+			"serial_number=%s\n"
+			"device_type=6-0050F204-1_2\n"
+			"os_version=01020300_2\n"
+			"config_methods=virtual_push_button\n", 
+			fbuf,m_read_mac, para->m_ssid, para->m_ignore_broadcast_ssid, 
+			para->m_max_num_sta,acl_mode_value_transist(para->accesspolicy0),wifi_mac+6);
+		
+		if (!strcmp (para->m_auth_mode, "WPAPSKWPA2PSK") || !strcmp (para->m_auth_mode, "WPA-PSK/WPA2-PSK")) {
+			asprintf(&sbuf2, "%swpa=3\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP CCMP\nrsn_pairwise=TKIP CCMP\nwpa_passphrase=%s\nwpa_group_rekey=3600\n", sbuf, para->m_password);
+		} else if (!strcmp(para->m_auth_mode, "WPA2PSK")) {
+			asprintf(&sbuf2, "%swpa=2\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP\nwpa_passphrase=%s\nwpa_group_rekey=3600\n", sbuf, para->m_password);
+		} else if (!strcmp(para->m_auth_mode, "WPA3Personal")) {
+			asprintf(&sbuf2, "%swpa=2\nwpa_key_mgmt=SAE\nwpa_pairwise=CCMP\nrsn_pairwise=CCMP\nieee80211w=2\nwpa_passphrase=%s\nwpa_group_rekey=3600\nsae_pwe=2\n", sbuf, para->m_password);
+		} else if (!strcmp(para->m_auth_mode, "WPA2WPA3")) {
+			asprintf(&sbuf2, "%swpa=2\nwpa_key_mgmt=SAE WPA-PSK\nwpa_pairwise=CCMP\nrsn_pairwise=CCMP\nieee80211w=1\nwpa_passphrase=%s\nwpa_group_rekey=3600\nsae_pwe=2\n", sbuf, para->m_password);
+		} else if (!strcmp(para->m_auth_mode, "OPEN")) {
+			asprintf(&sbuf2, "%swpa=0\n", sbuf);
+		} else {//kw
+			wf_log("Unsupport m_auth_mode: %s", para->m_auth_mode);
+			free(wbuf);
+			free(fbuf);
+			free(sbuf);
+			return -1;
+		}	
+
+	}
+	
+	generate_acl_list_file(para->accesspolicy0);
+
+	fd = open(HOSTAPD_CONF_FILE, O_CREAT | O_TRUNC | O_WRONLY, 0660);
+	if (fd < 0) {
+		wf_log("Cannot update \"%s\": %s", HOSTAPD_CONF_FILE, strerror(errno));
+		return -1;
+	}
+	if(strcmp (m_ssid_enable, "1") == 0){
+		if (write(fd, sbuf2, strlen(sbuf2)) < 0) {
+			wf_log("Cannot write to \"%s\": %s", HOSTAPD_CONF_FILE, strerror(errno));
+			ret = -1;
+		}
+		free(sbuf);
+		free(sbuf2);
+	}else{
+		if (write(fd, fbuf, strlen(fbuf)) < 0) {
+			wf_log("Cannot write to \"%s\": %s", HOSTAPD_CONF_FILE, strerror(errno));
+			ret = -1;
+		}
+	}
+	free(wbuf);
+	free(fbuf);
+	/* Note: apparently open can fail to set permissions correctly at times */
+	if (fchmod(fd, 0660) < 0) {
+		wf_log("Error changing permissions of %s to 0660: %s",
+				HOSTAPD_CONF_FILE, strerror(errno));
+		close(fd);
+		unlink(HOSTAPD_CONF_FILE);
+		return -1;
+	}
+	
+	close(fd);
+	return ret;
+}
+#endif
+
 static void open_wifi_nv_set()
 {
 	sc_cfg_set ("wifiSleep", "0");
@@ -969,7 +1527,7 @@
 {
 	slog(WIFI_PRINT, SLOG_ERR, "ap_enabled_timeout!\n");
 	//2.4GµÄËùÓÐssid¶¼ÊÇͬһ״̬
-	send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ERROR);
+	send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ERROR);
 	return 0;
 }
 #endif
@@ -1002,7 +1560,7 @@
 			ret = wifi_ap_enable(ap_svr); 
 			if (ret == 0) {
 			#ifdef USE_CAP_SUPPORT
-				send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ENABLED);
+				send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ENABLED);
 			#endif
 				return 0;
 			}
@@ -1011,8 +1569,16 @@
 		}
 	}
 #ifdef USE_CAP_SUPPORT
-	wlan_ap_get_para(ap_svr);
-	wlan_ap_save_config(ap_svr);
+	if (g_work_mode == IN_WIFI_WORK_MODE_AP1) {
+		acl_mode_set_5g();
+		wlan_ap_get_para_5g(ap_svr);
+		wlan_ap_save_config_5g(ap_svr);
+	}
+	else {
+		acl_mode_set();
+		wlan_ap_get_para(ap_svr);
+		wlan_ap_save_config(ap_svr);
+	}
 #endif
 	
 	/* Reset sockets used for exiting from hung state */
@@ -1024,7 +1590,7 @@
 	ret = ap_svr->drv_proxy.drv_init(&ap_svr->drv_proxy);
 	if(-1 == ret) {
 	#ifdef USE_CAP_SUPPORT
-		send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ERROR);
+		send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ERROR);
 	#endif
 		return -1;
 	}
@@ -1075,7 +1641,7 @@
 		wf_log ("hostapd start failed");
 		wlan_set_state(WLAN_OFF,WLAN_OFF);
 	#ifdef USE_CAP_SUPPORT
-		send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ERROR);
+		send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ERROR);
 	#endif
 	}
 	
@@ -1099,7 +1665,34 @@
 	
 	return 0;
 }
+#ifdef USE_CAP_SUPPORT
+int wifi_set_hostapd (struct  wlan_ap_server  *ap_svr)
+{
+	if (g_work_mode == IN_WIFI_WORK_MODE_AP1) {
+		acl_mode_set_5g();
+		wlan_ap_get_para_5g(ap_svr);
+		wlan_ap_save_config_5g(ap_svr);
+		wifi_config_ap_5g(ap_svr);
+	}
+	else {
+		acl_mode_set();
+		wlan_ap_get_para(ap_svr);
+		wlan_ap_save_config(ap_svr);
+		wifi_config_ap(ap_svr);
+	}
+#ifdef __AP_FUNC__
+#ifdef __USE_AES__
+	wifi_encrypt_code();
+#endif
+#endif
 
+//	wifi_stop_hostapd(ap_svr);
+//	wifi_start_hostapd(ap_svr);
+	//acl_set_process();
+	sc_cfg_set("wifi_set_flags", "");
+	return 0;
+}
+#else
 int wifi_set_hostapd (struct  wlan_ap_server  *ap_svr)
 {
 	wlan_ap_get_para(ap_svr);
@@ -1117,6 +1710,7 @@
 	sc_cfg_set("wifi_set_flags", "");
 	return 0;
 }
+#endif
 
 void *channel_follow_timer_handle(void *arg)
 {
@@ -1137,17 +1731,42 @@
 	wf_log ("wifi_channel_follow retry %s#%s!!", t_channel, f_channel);
 
 	if (0 != strcmp(t_channel, f_channel)) {
-		int fchan = atoi(f_channel);
 		
+#ifdef USE_CAP_SUPPORT		
+		if (g_work_mode == IN_WIFI_WORK_MODE_AP1) {
+			sc_cfg_get ("wifi_11n_cap_5g", w_11n_ht, NVIO_WIFI_LEN_8-1);
+			wlan_set_channel_5g(f_channel, w_11n_ht);
+		}
+		else {
+			int fchan = atoi(f_channel);
+		
+			sc_cfg_get ("wifi_11n_cap", w_11n_ht, NVIO_WIFI_LEN_8-1);
+			if (0 == strcmp(w_11n_ht, "1")) {
+				ap_docmd("SET force_40mhz", "0");//set channel fail
+				//ap_docmd("SET ht_capab [HT40+][HT40-][SHORT-GI-20][SHORT-GI-40]", NULL);
+			}
+			if (fchan > 11) {
+				//ap_docmd("SET country_code", "CN");
+				char country_code[NVIO_WIFI_LEN_8] = {0};
+				sc_cfg_get("CountryCode", country_code, NVIO_WIFI_LEN_8-1);
+				wf_log("wifi_channel_follow country_code %s!!", country_code);
+			}
+			ap_docmd("SET channel", f_channel);
+		}
+#else
+		int fchan = atoi(f_channel);
+				
 		sc_cfg_get ("wifi_11n_cap", w_11n_ht, NVIO_WIFI_LEN_8-1);
 		if (0 == strcmp(w_11n_ht, "1")) {
 			ap_docmd("SET force_40mhz", "0");//set channel fail
 			//ap_docmd("SET ht_capab [HT40+][HT40-][SHORT-GI-20][SHORT-GI-40]", NULL);
 		}
-		
-		if (fchan > 11)
+
+		if (fchan > 11) {
 			ap_docmd("SET country_code", "CN");
+		}
 		ap_docmd("SET channel", f_channel);
+#endif
 
 		ap_docmd("DISABLE", NULL);
 
@@ -1349,7 +1968,7 @@
 				g_ap_enabled = 1;
 			#ifdef USE_CAP_SUPPORT
 				sc_timer_delete(WIFI_AP_ENABLED_TIMER_ID);
-				send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ENABLED);
+				send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ENABLED);
 			#endif
 			}
 		}
@@ -1878,16 +2497,20 @@
 */
 void wlan_basic_restart_apsta()
 {
-	write_status (WIFISTATUS, WIFI_CLOSED);
-	clear_sta_count_nv();
-	//close mssid
-	ap_server->stopap(ap_server);
-	g_ap_enabled = 0;
-	sc_cfg_set("m_ssid_enable","0");
-	wlan_ap_get_para(ap_server);
-	wlan_ap_save_config(ap_server);
-	ap_server->startap(ap_server);
-	wlan_set_state(WLAN_ON, WLAN_OFF);
+	char m_ssid_enable[8] = {0};
+	sc_cfg_get("m_ssid_enable", m_ssid_enable, sizeof (m_ssid_enable));
+	if (strcmp(m_ssid_enable, "1") == 0) { 
+		write_status (WIFISTATUS, WIFI_CLOSED);
+		clear_sta_count_nv();
+		//close mssid
+		ap_server->stopap(ap_server);
+		g_ap_enabled = 0;
+		sc_cfg_set("m_ssid_enable","0");
+		wlan_ap_get_para(ap_server);
+		wlan_ap_save_config(ap_server); //5g will set in startap
+		ap_server->startap(ap_server);
+		wlan_set_state(WLAN_ON, WLAN_OFF);
+	}
 #ifdef  __STA_FUNC__
 	wait_ap_enabled();
 	wlan_station_init();
@@ -2065,8 +2688,12 @@
 		} else {
 			wifi_ap_reset_para(ap_svr);
 		}
-#endif
+#endif 
+#ifdef USE_CAP_SUPPORT
+		ap_svr->stopap(ap_svr);
+#else
 		ap_svr->disable(ap_svr);
+#endif
 		g_ap_enabled = 0;
 		break;
 
diff --git a/ap/app/zte_comm/wlan/src/wifi_hal.c b/ap/app/zte_comm/wlan/src/wifi_hal.c
index 88eb8c3..5a2cb1e 100755
--- a/ap/app/zte_comm/wlan/src/wifi_hal.c
+++ b/ap/app/zte_comm/wlan/src/wifi_hal.c
@@ -1944,14 +1944,14 @@
 	if (wlan_system(WLAN_DEAL, "open_va0") < 0) {

 		wlan_set_state(WLAN_OFF,WLAN_OFF);

 	#ifdef USE_CAP_SUPPORT

-		send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ERROR);

+		send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ERROR);

 	#endif

 		return;

 	}

 

 	wlan_set_state(WLAN_ON,WLAN_OFF);

 #ifdef USE_CAP_SUPPORT

-	send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ENABLED);

+	send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ENABLED);

 #endif

 

 #ifdef  __STA_FUNC__

@@ -1970,14 +1970,14 @@
 	if (wlan_system(WLAN_DEAL,"open_va0_va1") < 0) {

 		wlan_set_state(WLAN_OFF,WLAN_OFF);

 	#ifdef USE_CAP_SUPPORT

-		send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ERROR);

+		send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ERROR);

 	#endif

 		return;

 	}

 

 	wlan_set_state(WLAN_ON,WLAN_ON);

 #ifdef USE_CAP_SUPPORT

-	send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ENABLED);

+	send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ENABLED);

 #endif

 

 // Ö»ÐèÒªÉèÖø±SSIDµÄºÚ°×Ãûµ¥ --- TODO: Ö÷¸±siidµÄºÚ°×Ãûµ¥°´ÀíÓ¦¸Ã·Ö¿ª¹ÜÀí£¬ºóÐøÓÅ»¯

@@ -2813,7 +2813,7 @@
 	if (! (-1 != ret && WIFEXITED (ret) && 0 == WEXITSTATUS (ret))) {

 		wlan_set_state(WLAN_OFF,WLAN_OFF);

 	#ifdef USE_CAP_SUPPORT

-		send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ERROR);

+		send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ERROR);

 	#endif

 		wf_log ("Open Error");

 		return;

@@ -2842,7 +2842,7 @@
 #endif

 

 #ifdef USE_CAP_SUPPORT

-	send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_ENABLED);

+	send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_ENABLED);

 #endif

 

 	wf_log ("Open Success ");

diff --git a/ap/app/zte_comm/wlan/src/wifi_sta_ctrl.c b/ap/app/zte_comm/wlan/src/wifi_sta_ctrl.c
index 471a44a..c1570bd 100755
--- a/ap/app/zte_comm/wlan/src/wifi_sta_ctrl.c
+++ b/ap/app/zte_comm/wlan/src/wifi_sta_ctrl.c
@@ -11,6 +11,32 @@
 #include "wifi_sta_ctrl.h"

 #include "wifi_drv_ko.h"

 

+#ifdef USE_CAP_SUPPORT

+extern int g_work_mode;

+void reset_wpa_supplicant_conf (void)

+{

+	if (g_work_mode == IN_WIFI_WORK_MODE_AP1) {

+		wlan_write_file (SUPPLICANT_CONF, "##### wpa_supplicant configuration file template #####\n\

+			ctrl_interface=/etc_rw/wifi/sockets\n\

+			update_config=1\n\

+			pmf=1\n\

+			sae_pwe=2\n\

+			eapol_version=1\n\

+			ap_scan=1\n\

+			freq_list=5180 5200 5220 5240 5260 5280 5300 5320 5500 5520 5540 5560 5580 5600 5620 5640 5660 5680 5700 5720 5745 5765 5785 5805 5825\n");

+	}

+	else {

+		wlan_write_file (SUPPLICANT_CONF, "##### wpa_supplicant configuration file template #####\n\

+			ctrl_interface=/etc_rw/wifi/sockets\n\

+			update_config=1\n\

+			pmf=1\n\

+			sae_pwe=2\n\

+			eapol_version=1\n\

+			ap_scan=1\n\

+			freq_list=2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 2484\n");

+	}

+}

+#endif

 void check_wpa_supplicant_conf (void)

 {

 	//char  *file = SUPPLICANT_CONF;

@@ -42,7 +68,6 @@
 }

 

 

-

 char wpa_supplicant_pid[16] = {0};

 

 pid_t  read_wpa_pid()

@@ -85,6 +110,14 @@
 	if (check_alive(&sta_ctrl->sock)) 

 		return 0;

 

+#ifdef USE_CAP_SUPPORT

+	char support5g[10] = {0};

+	sc_cfg_get("wifi_sup_5g_band",support5g,sizeof(support5g));

+	if(0 == strcmp(support5g, "1")) {

+		reset_wpa_supplicant_conf();

+	}

+#endif

+

 	/* Reset sockets used for exiting from hung state */

 	sta_ctrl->sock.exit_sockets[0] = sta_ctrl->sock.exit_sockets[1] = -1;

 

diff --git a/ap/app/zte_comm/wlan/src/wifi_util.c b/ap/app/zte_comm/wlan/src/wifi_util.c
index 946d86a..f5bc845 100755
--- a/ap/app/zte_comm/wlan/src/wifi_util.c
+++ b/ap/app/zte_comm/wlan/src/wifi_util.c
@@ -1010,6 +1010,29 @@
 	sc_cfg_set("m_WPAPSK1_aes", s_aes);

 	printf("encrypt psk2\n");

 

+#ifdef USE_CAP_SUPPORT   //(&& WIFI_5G_SUPPORT)

+	char support5g[10] = {0};

+	sc_cfg_get("wifi_sup_5g_band",support5g,sizeof(support5g));

+	if(0 == strcmp(support5g, "1")) {

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

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

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

+		sc_cfg_get("WPAPSK1_5g", w_code, sizeof(w_code));

+		bs_aes_encrypt(w_code, WIFI_PSW_MAN_LEN, b_aes, wifi_aes_key, sizeof(wifi_aes_key));

+		wifi_bytes2string(b_aes, s_aes, WIFI_PSW_MAN_LEN);

+		sc_cfg_set("WPAPSK1_aes_5g", s_aes);

+		printf("5g encrypt psk1\n");

+

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

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

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

+		sc_cfg_get("m_WPAPSK1_5g", w_code, sizeof(w_code));

+		bs_aes_encrypt(w_code, WIFI_PSW_MAN_LEN, b_aes, wifi_aes_key, sizeof(wifi_aes_key));

+		wifi_bytes2string(b_aes, s_aes, WIFI_PSW_MAN_LEN);

+		sc_cfg_set("m_WPAPSK1_aes_5g", s_aes);

+		printf("5g encrypt psk2\n");

+	}

+#endif

 	return 1;

 }

 

@@ -1049,6 +1072,42 @@
 	return 1;

 }

 

+static int wifi_decode_b64_psk1_5g(void)

+{

+	unsigned char *p_code = NULL;

+	int p_code_len = 0;

+	char b_code[WLAN_ENCODE_PSK_LEN] = {0};

+	sc_cfg_get("WPAPSK1_encode_5g", b_code, sizeof(b_code));

+	p_code = wlan_base64_decode(b_code, strlen(b_code), &p_code_len);

+	if (p_code == NULL) {

+		printf("5g decrypt psk1 no memory\n");

+		return 0;

+	}

+	sc_cfg_set("WPAPSK1_5g", (char *)p_code);

+	printf("5g decrypt psk1\n");

+	free(p_code);

+

+	return 1;

+}

+

+static int wifi_decode_b64_psk2_5g(void)

+{

+	unsigned char *p_code = NULL;

+	int p_code_len = 0;

+	char b_code[WLAN_ENCODE_PSK_LEN] = {0};

+	sc_cfg_get("m_WPAPSK1_encode_5g", b_code, sizeof(b_code));

+	p_code = wlan_base64_decode(b_code, strlen(b_code), &p_code_len);

+	if (p_code == NULL) {

+		printf("5g decrypt psk2 no memory\n");

+		return 0;

+	}

+	sc_cfg_set("m_WPAPSK1_5g", (char *)p_code);

+	printf("5g decrypt psk2\n");

+	free(p_code);

+

+	return 1;

+}

+

 //»Ö¸´nv, wepÒòwebui²»Ö§³Ö£¬Î´´¦Àí

 int wifi_decrypt_code(void)

 {

@@ -1088,6 +1147,46 @@
 		}

 	}

 

+#ifdef USE_CAP_SUPPORT   //(&& WIFI_5G_SUPPORT)

+	char support5g[10] = {0};

+	sc_cfg_get("wifi_sup_5g_band",support5g,sizeof(support5g));

+	if(0 == strcmp(support5g, "1")) {

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

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

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

+		sc_cfg_get("WPAPSK1_aes_5g", s_aes, sizeof(s_aes));

+		if (strlen(s_aes) > 0) {

+			wifi_string2bytes(s_aes, b_aes, WIFI_PSW_MAN_LEN*2);

+			bs_aes_decrypt(b_aes, WIFI_PSW_MAN_LEN, w_code, wifi_aes_key, sizeof(wifi_aes_key));

+			sc_cfg_set("WPAPSK1_5g", w_code);

+			printf("5g dec1\n");

+		} else {

+			if (wifi_decode_b64_psk1()) {

+				flag = 1;

+			} else {

+				return 0;

+			}

+		}

+		

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

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

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

+		sc_cfg_get("m_WPAPSK1_aes_5g", s_aes, sizeof(s_aes));

+		if (strlen(s_aes) > 0) {

+			wifi_string2bytes(s_aes, b_aes, WIFI_PSW_MAN_LEN*2);

+			bs_aes_decrypt(b_aes, WIFI_PSW_MAN_LEN, w_code, wifi_aes_key, sizeof(wifi_aes_key));

+			sc_cfg_set("m_WPAPSK1_5g", w_code);

+			printf("5g dec2\n");

+		} else {

+			if (wifi_decode_b64_psk2()) {

+				flag = 1;

+			} else {

+				return 0;

+			}

+		}

+	}

+#endif

+

 	if (flag)

 		return 2;

 	return 1;

@@ -1102,6 +1201,20 @@
 	if (!wifi_decode_b64_psk2()) {

 		return 0;

 	}

+	

+#ifdef USE_CAP_SUPPORT   //(&& WIFI_5G_SUPPORT)

+	char support5g[10] = {0};

+	sc_cfg_get("wifi_sup_5g_band",support5g,sizeof(support5g));

+	if(0 == strcmp(support5g, "1")) {

+		if (!wifi_decode_b64_psk1_5g()) {

+			return 0;

+		}

+

+		if (!wifi_decode_b64_psk2_5g()) {

+			return 0;

+		}

+	}

+#endif

 

 	return 1;

 }

diff --git a/ap/app/zte_comm/wlan/src/wlan-station.c b/ap/app/zte_comm/wlan/src/wlan-station.c
index 68d39e0..1be786d 100755
--- a/ap/app/zte_comm/wlan/src/wlan-station.c
+++ b/ap/app/zte_comm/wlan/src/wlan-station.c
@@ -71,6 +71,35 @@
 #define WIFI_STATION_CHANNEL11  2462

 #define WIFI_STATION_CHANNEL12  2467

 #define WIFI_STATION_CHANNEL13  2472

+

+#define WIFI_STATION_CHANNEL14  2484

+//5G

+#define WIFI_STATION_CHANNEL36  5180

+#define WIFI_STATION_CHANNEL40  5200

+#define WIFI_STATION_CHANNEL44  5220

+#define WIFI_STATION_CHANNEL48  5240

+#define WIFI_STATION_CHANNEL52  5260

+#define WIFI_STATION_CHANNEL56  5280

+#define WIFI_STATION_CHANNEL60  5300

+#define WIFI_STATION_CHANNEL64  5320

+#define WIFI_STATION_CHANNEL100  5500

+#define WIFI_STATION_CHANNEL104  5520

+#define WIFI_STATION_CHANNEL108  5540

+#define WIFI_STATION_CHANNEL112  5560

+#define WIFI_STATION_CHANNEL116  5580

+#define WIFI_STATION_CHANNEL120  5600

+#define WIFI_STATION_CHANNEL124  5620

+#define WIFI_STATION_CHANNEL128  5640

+#define WIFI_STATION_CHANNEL132  5660

+#define WIFI_STATION_CHANNEL136  5680

+#define WIFI_STATION_CHANNEL140  5700

+#define WIFI_STATION_CHANNEL144  5720

+#define WIFI_STATION_CHANNEL149  5745

+#define WIFI_STATION_CHANNEL153  5765

+#define WIFI_STATION_CHANNEL157  5785

+#define WIFI_STATION_CHANNEL161  5805

+#define WIFI_STATION_CHANNEL165  5825

+

 #define WIFI_STATION_FREQ_LEN 16

 

 #define WIFI_STATION_MSG_SOURCE_STR_LEN  15

@@ -159,7 +188,51 @@
 //#define SIMCARD_INIT_LOCKED "locked"

 //#define SIMCARD_INIT_FAIL "fail"

 //#define SIMCARD_INIT_PARTIAL_SUCCESS "partial_success"

+#if 0

+static const wlan_sta_freq_ch_t g_sta_freq_ch[] =

+{

+    {WIFI_STATION_CHANNEL1, 	1},

+    {WIFI_STATION_CHANNEL2, 	2},

+    {WIFI_STATION_CHANNEL3, 	3},

+    {WIFI_STATION_CHANNEL4, 	4},

+    {WIFI_STATION_CHANNEL5, 	5},

+    {WIFI_STATION_CHANNEL6, 	6},

+    {WIFI_STATION_CHANNEL7, 	7},

+    {WIFI_STATION_CHANNEL8, 	8},

+    {WIFI_STATION_CHANNEL9, 	9},

+    {WIFI_STATION_CHANNEL10, 	10},

+    {WIFI_STATION_CHANNEL11, 	11},

+    {WIFI_STATION_CHANNEL12, 	12},

+    {WIFI_STATION_CHANNEL13, 	13},

+    {WIFI_STATION_CHANNEL14, 	14},

 

+	{WIFI_STATION_CHANNEL36, 	36},

+    {WIFI_STATION_CHANNEL40, 	40},

+    {WIFI_STATION_CHANNEL44, 	44},

+    {WIFI_STATION_CHANNEL48, 	48},

+    {WIFI_STATION_CHANNEL52, 	52},

+    {WIFI_STATION_CHANNEL56, 	56},

+    {WIFI_STATION_CHANNEL60, 	60},

+    {WIFI_STATION_CHANNEL64, 	64},

+    {WIFI_STATION_CHANNEL100, 	100},

+    {WIFI_STATION_CHANNEL104, 	104},

+    {WIFI_STATION_CHANNEL108, 	108},

+    {WIFI_STATION_CHANNEL112, 	112},

+    {WIFI_STATION_CHANNEL116, 	116},

+    {WIFI_STATION_CHANNEL120, 	120},

+    {WIFI_STATION_CHANNEL124, 	124},

+    {WIFI_STATION_CHANNEL128, 	128},

+    {WIFI_STATION_CHANNEL132, 	132},

+    {WIFI_STATION_CHANNEL136, 	136},

+    {WIFI_STATION_CHANNEL140, 	140},

+    {WIFI_STATION_CHANNEL144, 	144},

+    {WIFI_STATION_CHANNEL149, 	149},

+    {WIFI_STATION_CHANNEL153, 	153},

+    {WIFI_STATION_CHANNEL157, 	157},

+    {WIFI_STATION_CHANNEL161, 	161},

+    {WIFI_STATION_CHANNEL165, 	165}

+};

+#endif

 

 extern struct  wlan_sta_manager  *sta_manager;

 extern int need_channel_follow;

@@ -192,7 +265,7 @@
 

 #ifdef USE_CAP_SUPPORT

 int g_cap_scan = 0; //½öcap·¢Æðscanʱ,²ÅÉϱ¨½á¹û,ºǫִ́Ðнá¹û²»±¨

-static int send_sta_status_to_cap(int status, int reason);

+int send_sta_status_to_cap(int status, int reason);

 #endif

 

 static int wifi_station_connect (int from_where);

@@ -1314,6 +1387,136 @@
 

 }

 

+static int frequency_to_channel(int freq)

+{

+	int channel = 0;

+	//channel

+	switch(freq) {

+		case WIFI_STATION_CHANNEL1:

+			channel = 1;

+			break;

+		case WIFI_STATION_CHANNEL2:

+			channel = 2;

+			break;

+		case WIFI_STATION_CHANNEL3:

+			channel = 3;

+			break;

+		case WIFI_STATION_CHANNEL4:

+			channel = 4;

+			break;

+		case WIFI_STATION_CHANNEL5:

+			channel = 5;

+			break;

+		case WIFI_STATION_CHANNEL6:

+			channel = 6;

+			break;

+		case WIFI_STATION_CHANNEL7:

+			channel = 7;

+			break;

+		case WIFI_STATION_CHANNEL8:

+			channel = 8;

+			break;

+		case WIFI_STATION_CHANNEL9:

+			channel = 9;

+			break;

+		case WIFI_STATION_CHANNEL10:

+			channel = 10;

+			break;

+		case WIFI_STATION_CHANNEL11:

+			channel = 11;

+			break;

+		case WIFI_STATION_CHANNEL12:

+			channel = 12;

+			break;

+		case WIFI_STATION_CHANNEL13:

+			channel = 13;

+			break;

+		case WIFI_STATION_CHANNEL14:

+			channel = 14;

+			break;

+		case WIFI_STATION_CHANNEL36:

+			channel = 36;

+			break;

+		case WIFI_STATION_CHANNEL40:

+			channel = 40;

+			break;

+		case WIFI_STATION_CHANNEL44:

+			channel = 44;

+			break;

+		case WIFI_STATION_CHANNEL48:

+			channel = 48;

+			break;

+		case WIFI_STATION_CHANNEL52:

+			channel = 52;

+			break;

+		case WIFI_STATION_CHANNEL56:

+			channel = 56;

+			break;

+		case WIFI_STATION_CHANNEL60:

+			channel = 60;

+			break;

+		case WIFI_STATION_CHANNEL64:

+			channel = 64;

+			break;

+		case WIFI_STATION_CHANNEL100:

+			channel = 100;

+			break;

+		case WIFI_STATION_CHANNEL104:

+			channel = 104;

+			break;

+		case WIFI_STATION_CHANNEL108:

+			channel = 108;

+			break;

+		case WIFI_STATION_CHANNEL112:

+			channel = 112;

+			break;

+		case WIFI_STATION_CHANNEL116:

+			channel = 116;

+			break;

+		case WIFI_STATION_CHANNEL120:

+			channel = 120;

+			break;

+		case WIFI_STATION_CHANNEL124:

+			channel = 124;

+			break;

+		case WIFI_STATION_CHANNEL128:

+			channel = 128;

+			break;

+		case WIFI_STATION_CHANNEL132:

+			channel = 132;

+			break;

+		case WIFI_STATION_CHANNEL136:

+			channel = 136;

+			break;

+		case WIFI_STATION_CHANNEL140:

+			channel = 140;

+			break;

+		case WIFI_STATION_CHANNEL144:

+			channel = 144;

+			break;

+		case WIFI_STATION_CHANNEL149:

+			channel = 149;

+			break;

+		case WIFI_STATION_CHANNEL153:

+			channel = 153;

+			break;

+		case WIFI_STATION_CHANNEL157:

+			channel = 157;

+			break;

+		case WIFI_STATION_CHANNEL161:

+			channel = 161;

+			break;

+		case WIFI_STATION_CHANNEL165:

+			channel = 165;

+			break;

+		default:

+			channel = 0;

+			wf_log("unknow freq[%d]MHz!!!", freq);	

+			break;

+	}

+	

+	return channel;

+}

 

 static scan_result_t* parse_scan_result (Var *var)

 {

@@ -1403,6 +1606,9 @@
 		}

 

 		//channel

+#ifdef USE_CAP_SUPPORT

+		scan_result->channel = frequency_to_channel(frequency);

+#else

 		switch (frequency) {

 		case WIFI_STATION_CHANNEL1:

 			scan_result->channel = 1;

@@ -1447,7 +1653,7 @@
 			scan_result->channel = 0;

 			break;

 		}

-

+#endif

 		//authMode¼øÈ¨Ä£Ê½

 		ptr = NULL;

 		ptr2 = NULL;

@@ -1753,7 +1959,7 @@
 		wf_log ("wifi_sta_connection isn't 1,abormal!!!========");

 		return;

 	}

-

+#ifndef USE_CAP_SUPPORT

 	//ÕýÔÚÁ¬½Ó״̬ÔòÍ˳ö

 	sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));

 	if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0 ||

@@ -1762,7 +1968,7 @@
 		sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting

 		return;

 	}

-

+#endif

 	//wpa_supplicant½ø³ÌûÆô¶¯ÔòÆô¶¯£¬ÊôÓÚÒì³£±£»¤

 	if (check_supplicant_alive() ==0) {

 		wf_log ("detect wpa_supplicant isnot running========");

@@ -2513,6 +2719,7 @@
 	else {

 #ifdef USE_CAP_SUPPORT

 		send_sta_status_to_cap(IN_WIFI_STA_STATUS_NONE, IN_WIFI_REASON_CODE_NONE);

+		//sc_cfg_set("wifi_sta_connection", "0");

 #endif

 		if (0 == g_wpa_supplicant) {

 			wf_log("station has closed");

@@ -2528,7 +2735,7 @@
 

 }

 

-static int send_sta_status_to_cap(int status, int reason)

+int send_sta_status_to_cap(int status, int reason)

 {

 	int ret = 0;

 	wlan_sta_status_t sta_stat = {0};

@@ -2716,7 +2923,6 @@
 	}

 	

 }

-

 #endif

 

 //wifi station´¦Àíº¯Êý

@@ -3020,7 +3226,14 @@
 		snprintf(freq, len+1, "%s", start);

 		frequency = atoi(freq);

 		wf_log("Trying to associate with freq= %s[%d]", freq, frequency);

-

+		

+#ifdef USE_CAP_SUPPORT

+		int i_ch = 0;

+		char s_ch[10] = {0};

+		i_ch = frequency_to_channel(frequency);

+		snprintf(s_ch, sizeof(s_ch), "%d", i_ch);

+		sc_cfg_set("flower_channel", s_ch);

+#else

 		switch (frequency) {

 		case WIFI_STATION_CHANNEL1:

 			sc_cfg_set("flower_channel", "1");

@@ -3066,6 +3279,7 @@
 			wf_log("channel_follow with unknow freq = [%d]", frequency);

 			break;

 		}

+#endif

 	}

 	

 	ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_CHANNEL_FOLLOW, 0, NULL, 0);

diff --git a/ap/app/zte_comm/wlan/src/wlan_config_ssid.c b/ap/app/zte_comm/wlan/src/wlan_config_ssid.c
index 8a45aed..0187a24 100755
--- a/ap/app/zte_comm/wlan/src/wlan_config_ssid.c
+++ b/ap/app/zte_comm/wlan/src/wlan_config_ssid.c
@@ -24,6 +24,10 @@
 	CHAR ssid[40] = {0};
 	CHAR m_ssid[40] = {0};
     CHAR ssid_cmd[128] = {0};
+#ifdef USE_CAP_SUPPORT   //(&& WIFI_5G_SUPPORT)	
+	CHAR ssid_5g[40] = {0};
+	CHAR m_ssid_5g[40] = {0};
+#endif	
 	CHAR sLastbyte[3] = {0};
 	INT num = 0;
 	INT i = 0;
@@ -54,7 +58,12 @@
 
 	sc_cfg_set ("SSID1", ssid);
 	sc_cfg_set ("m_SSID", m_ssid);
-
+#ifdef USE_CAP_SUPPORT   //(&& WIFI_5G_SUPPORT)
+	sprintf(ssid_5g, "%s_5G", ssid);
+	sprintf(m_ssid_5g, "%s_2_5G", ssid);
+	sc_cfg_set ("SSID1_5g", ssid);
+	sc_cfg_set ("m_SSID_5g", m_ssid);
+#endif
 	sc_cfg_set ("ssid_write_flag", "1"); //½«nvÖеıê־λÖÃ1£¬±íʾSSIDÒÑдÈë¡£
 	//sc_cfg_save();
 	//softap_log(LOG_INFO,WIFI_PRINT,">-------------- ssid = %s", ssid);
@@ -268,12 +277,20 @@
 		encode = wlan_base64_encode(key, strlen (key));
 		sc_cfg_set ("WPAPSK1", key);
 		sc_cfg_set ("WPAPSK1_encode", encode);
+#ifdef USE_CAP_SUPPORT   //(&& WIFI_5G_SUPPORT)
+		sc_cfg_set ("WPAPSK1_5g", key);
+		sc_cfg_set ("WPAPSK1_encode_5g", encode);
+#endif
 	}
 
 	if (strlen (m_key) > 0) { // protect  multissid  , m_key maybe 0
 		m_encode =  wlan_base64_encode(m_key, strlen (m_key));
 		sc_cfg_set ("m_WPAPSK1", m_key);
 		sc_cfg_set ("m_WPAPSK1_encode", m_encode);
+#ifdef USE_CAP_SUPPORT   //(&& WIFI_5G_SUPPORT)
+		sc_cfg_set ("m_WPAPSK1_5g", m_key);
+		sc_cfg_set ("m_WPAPSK1_encode_5g", m_encode);
+#endif
 	}
 #ifdef __AP_FUNC__
 #ifdef __USE_AES__
diff --git a/ap/app/zte_comm/wlan/src/wlan_main.c b/ap/app/zte_comm/wlan/src/wlan_main.c
index 0e292d8..daac630 100755
--- a/ap/app/zte_comm/wlan/src/wlan_main.c
+++ b/ap/app/zte_comm/wlan/src/wlan_main.c
@@ -35,6 +35,11 @@
 

 #ifdef USE_CAP_SUPPORT

 #define FROM_CAP 0

+

+int g_work_mode = IN_WIFI_WORK_MODE_AP0; //default

+

+extern int send_sta_status_to_cap(int status, int reason);

+

 int send_ap_status_to_cap(int idx, int status);

 int send_sta_change_to_cap(int idx, int status, char *mac);

 #endif

@@ -202,6 +207,42 @@
 	

 }

 

+void acl_mode_set_5g()

+{

+	char ACL_mode[8] = {0};

+

+	sc_cfg_get ("ACL_mode_5g", ACL_mode, sizeof (ACL_mode));

+	CFG2WEB_UNCONDITIONAL ("ACL_mode_5g", "AccessPolicy0");

+

+	if (!strcmp (ACL_mode, "1")) {       // white-list

+		CFG2WEB_UNCONDITIONAL ("wifi_mac_white_list_5g", "AccessControlList0");

+	} else if (!strcmp (ACL_mode, "2")) { // black-list

+		CFG2WEB_UNCONDITIONAL ("wifi_mac_black_list_5g", "AccessControlList0");

+	} else {

+		sc_cfg_set ("AccessPolicy0", "0");

+	}

+}

+

+#ifdef USE_CAP_SUPPORT

+static void set_mac_access()

+{

+	wf_log ("nxl  set_mac_access  ");

+	if (g_work_mode == IN_WIFI_WORK_MODE_AP1) {

+		acl_mode_set_5g();

+	}

+	else {

+		acl_mode_set();

+	}

+	

+

+	if (ap_server->ap0_state == 1) {

+		wf_log ("wifi is on");

+		acl_set_process();   

+	} else {

+		wf_log ("wifi is off");

+	}

+}

+#else

 static void set_mac_access()

 {

 	wf_log ("nxl  set_mac_access  ");

@@ -214,7 +255,7 @@
 		wf_log ("wifi is off");

 	}

 }

-

+#endif

 

 

 static int chargingcheckstates()

@@ -855,6 +896,15 @@
 	wlan_ap_status_t w_stat = {0};

 	int ret = 0;

 

+	if (idx == IN_WIFI_AP_INDEX_MAX) {

+		if (g_work_mode == IN_WIFI_WORK_MODE_AP1) {

+			idx == IN_WIFI_AP_INDEX_AP1;

+		}

+		else {

+			idx == IN_WIFI_AP_INDEX_AP0;

+		}

+	}

+	

 	if (idx <= IN_WIFI_AP_INDEX_MIN || idx >= IN_WIFI_AP_INDEX_MAX) {

 		wf_log("idx:%d not support\n", idx);

 		return -1;

@@ -863,7 +913,7 @@
 	w_stat.idx = idx;

 	w_stat.status = status;

 

-	if (idx == IN_WIFI_AP_INDEX_AP0) {

+	if (idx == IN_WIFI_AP_INDEX_AP0 || idx == IN_WIFI_AP_INDEX_AP1) {

 #if defined(__REALTEK_8192_CHIP__)

 		snprintf(w_stat.ifname, sizeof(w_stat.ifname), "%s", "wlan0-va0");

 #else

@@ -946,11 +996,19 @@
 

 static void cap_wifi_disable(MSG_BUF *pstMsg)

 {

+	char wifi_sta_connection[8] = {0};

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

+

 	if (ap_server->ap0_state) {

 		wf_log("cap disable when ap not closed");

-		send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_DISABLING);

+		send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_DISABLING);

 		basic_deal_all(WIFI_CFG_CLOSE);

-		send_ap_status_to_cap(IN_WIFI_AP_INDEX_AP0, IN_WIFI_AP_STATUS_IDLE);

+		send_ap_status_to_cap(IN_WIFI_AP_INDEX_MAX, IN_WIFI_AP_STATUS_IDLE);

+	}

+

+	if (strcmp (wifi_sta_connection, "1") == 0) {

+		send_sta_status_to_cap(IN_WIFI_STA_STATUS_NONE, IN_WIFI_REASON_CODE_NONE);

+		sc_cfg_set("wifi_sta_connection", "0");

 	}

 

 	ap_server->drv_proxy.drv_deinit(&ap_server->drv_proxy);

@@ -958,7 +1016,10 @@
 

 static void cap_wifi_mode_set(MSG_BUF *pstMsg)

 {

-	;

+	wlan_work_mode_t *data_buf = (wlan_work_mode_t *)pstMsg->aucDataBuf;

+

+	g_work_mode = data_buf->work_mode;

+	//bitmap

 }

 

 static void cap_ssid_set(MSG_BUF *pstMsg)

@@ -976,7 +1037,7 @@
 	case IN_WIFI_AP_INDEX_AP0:

 		if(strlen(data_buf->ssid) > 0 && strlen(data_buf->ssid) < WIFI_SSID_LEN) {

 			sc_cfg_set("SSID1", data_buf->ssid); //ke fang cap

-			if (ap_server->ap0_state) {

+			if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) { //todo bu shi dang qian, bu zhi xing

 				unsigned int wifi_set_flags = ZTE_WLAN_SSID_SET|ZTE_WLAN_BASIC_SECURITY_SET;

 				char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

 				snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

@@ -986,7 +1047,19 @@
 			wf_log("ap0_state: %d, ssid: %s", ap_server->ap0_state, data_buf->ssid);

 		}

 		break;

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+		if(strlen(data_buf->ssid) > 0 && strlen(data_buf->ssid) < WIFI_SSID_LEN) {

+			sc_cfg_set("SSID1_5g", data_buf->ssid); //ke fang cap

+			if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) { //todo bu shi dang qian, bu zhi xing

+				unsigned int wifi_set_flags = ZTE_WLAN_SSID_SET|ZTE_WLAN_BASIC_SECURITY_SET;

+				char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

+				snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

+				sc_cfg_set("wifi_set_flags", wifi_set_flags_str);

+				basic_deal_all(WIFI_CFG_AP);//MSG_CMD_WIFI_CFG_AP

+			}

+			wf_log("ap0_state: %d, ssid: %s", ap_server->ap0_state, data_buf->ssid);

+		}

+		break;

 	default:

 		wf_log("not support: %d", idx);

 		break;

@@ -1006,7 +1079,7 @@
 		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->ssid_hide);	

 		sc_cfg_set("HideSSID", hide_str);

 		

-		if (ap_server->ap0_state) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

 			unsigned int wifi_set_flags = ZTE_WLAN_BROADCAST_SET;

 			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

 			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

@@ -1015,7 +1088,21 @@
 		}

 		break;

 	}

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+	{

+		char hide_str[NVIO_WIFI_LEN_32] = {0};

+		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->ssid_hide);	

+		sc_cfg_set("HideSSID_5g", hide_str);

+		

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+			unsigned int wifi_set_flags = ZTE_WLAN_BROADCAST_SET;

+			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

+			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

+			sc_cfg_set("wifi_set_flags", wifi_set_flags_str);

+			basic_deal_all(WIFI_CFG_AP);//MSG_CMD_WIFI_CFG_AP

+		}

+		break;

+	}

 	default:

 		break;

 	}

@@ -1034,7 +1121,7 @@
 		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->wl_mode);	

 		sc_cfg_set("WirelessMode", hide_str);

 		

-		if (ap_server->ap0_state) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

 			unsigned int wifi_set_flags = ZTE_WLAN_WIRELESS_MODE_SET;

 			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

 			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

@@ -1043,7 +1130,21 @@
 		}

 		break;

 	}

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+	{

+		char hide_str[NVIO_WIFI_LEN_32] = {0};

+		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->wl_mode);	

+		sc_cfg_set("WirelessMode_5g", hide_str);

+		

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+			unsigned int wifi_set_flags = ZTE_WLAN_WIRELESS_MODE_SET;

+			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

+			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

+			sc_cfg_set("wifi_set_flags", wifi_set_flags_str);

+			basic_deal_all(WIFI_CFG_RF);//MSG_CMD_WIFI_ADVANCED-WIFI_ADVANCED_RF

+		}

+		break;

+	}

 	default:

 		break;

 	}

@@ -1062,7 +1163,7 @@
 		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->htMode);	

 		sc_cfg_set("wifi_11n_cap", hide_str);

 		

-		if (ap_server->ap0_state) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

 			unsigned int wifi_set_flags = ZTE_WLAN_WIRELESS_MODE_SET;

 			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

 			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

@@ -1071,7 +1172,21 @@
 		}

 		break;

 	}

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+	{

+		char hide_str[NVIO_WIFI_LEN_32] = {0};

+		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->htMode);	

+		sc_cfg_set("wifi_11n_cap_5g", hide_str);

+		

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+			unsigned int wifi_set_flags = ZTE_WLAN_WIRELESS_MODE_SET;

+			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

+			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

+			sc_cfg_set("wifi_set_flags", wifi_set_flags_str);

+			basic_deal_all(WIFI_CFG_RF);//MSG_CMD_WIFI_ADVANCED-WIFI_ADVANCED_RF

+		}

+		break;

+	}

 	default:

 		break;

 	}

@@ -1092,7 +1207,7 @@
 		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->channel);	

 		sc_cfg_set("Channel", hide_str);

 			

-		if (ap_server->ap0_state) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

 			unsigned int wifi_set_flags = ZTE_WLAN_CHANNEL_SET | ZTE_WLAN_COUNTRY_SET;

 			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

 			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

@@ -1101,7 +1216,23 @@
 		}

 		break;

 	}

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+	{

+		char hide_str[NVIO_WIFI_LEN_32] = {0};

+		sc_cfg_set("CountryCode_5g", data_buf->countrycode);

+	

+		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->channel);	

+		sc_cfg_set("Channel_5g", hide_str);

+			

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+			unsigned int wifi_set_flags = ZTE_WLAN_CHANNEL_SET | ZTE_WLAN_COUNTRY_SET;

+			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

+			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

+			sc_cfg_set("wifi_set_flags", wifi_set_flags_str);

+			basic_deal_all(WIFI_CFG_RF);//MSG_CMD_WIFI_ADVANCED-WIFI_ADVANCED_RF

+		}

+		break;

+	}

 	default:

 		break;

 	}

@@ -1120,7 +1251,7 @@
 		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->max_sta_num);	

 		sc_cfg_set("MAX_Access_num", hide_str);

 		

-		if (ap_server->ap0_state) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

 			unsigned int wifi_set_flags = ZTE_WLAN_MAX_ACCESS_NUM_SET;

 			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

 			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

@@ -1129,7 +1260,21 @@
 		}

 		break;

 	}

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+	{

+		char hide_str[NVIO_WIFI_LEN_32] = {0};

+		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->max_sta_num);	

+		sc_cfg_set("MAX_Access_num_5g", hide_str);

+		

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+			unsigned int wifi_set_flags = ZTE_WLAN_MAX_ACCESS_NUM_SET;

+			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

+			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

+			sc_cfg_set("wifi_set_flags", wifi_set_flags_str);

+			basic_deal_all(WIFI_CFG_AP);//MSG_CMD_WIFI_CFG_AP

+		}

+		break;

+	}

 	default:

 		break;

 	}

@@ -1155,7 +1300,7 @@
 			sc_cfg_set("wifi_mac_black_list", data_buf->acl_list);

 		}

 		

-		if (ap_server->ap0_state) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

 			unsigned int wifi_set_flags = ZTE_WLAN_ACL_SET;

 			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

 			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

@@ -1164,7 +1309,28 @@
 		}

 		break;

 	}

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+	{

+		char hide_str[NVIO_WIFI_LEN_32] = {0};

+		snprintf(hide_str, sizeof(hide_str), "%d", data_buf->acl_rule);	

+		sc_cfg_set("ACL_mode_5g", hide_str);

+

+		if (data_buf->acl_rule == 1) {

+			sc_cfg_set("wifi_mac_white_list_5g", data_buf->acl_list);

+		}

+		else if (data_buf->acl_rule == 2) {

+			sc_cfg_set("wifi_mac_black_list_5g", data_buf->acl_list);

+		}

+		

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+			unsigned int wifi_set_flags = ZTE_WLAN_ACL_SET;

+			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

+			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

+			sc_cfg_set("wifi_set_flags", wifi_set_flags_str);

+			set_mac_access();//MSG_CMD_WIFI_MAC

+		}

+		break;

+	}

 	default:

 		break;

 	}

@@ -1195,7 +1361,7 @@
 		wifi_encrypt_code();

 #endif

 		

-		if (ap_server->ap0_state) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

 			unsigned int wifi_set_flags = ZTE_WLAN_BASIC_SECURITY_SET;

 			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

 			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

@@ -1204,7 +1370,33 @@
 		}

 		break;

 	}

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+	{

+		char *encode = NULL;		

+		sc_cfg_set("AuthMode_5g", data_buf->authmode);

+		sc_cfg_set("EncrypType_5g", data_buf->encrypt);//use default

+		sc_cfg_set("WPAPSK1_5g", data_buf->pwd);

+

+		encode = wlan_base64_encode(data_buf->pwd, strlen(data_buf->pwd));

+		sc_cfg_set("WPAPSK1_encode_5g", encode);

+		free(encode);

+				

+		//WPAPSK1_enaes

+#ifdef __USE_AES__

+		//efuse changed...

+		wifi_aes_init_key();

+		wifi_encrypt_code();

+#endif

+		

+		if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+			unsigned int wifi_set_flags = ZTE_WLAN_BASIC_SECURITY_SET;

+			char wifi_set_flags_str[NVIO_WIFI_LEN_32] = {0};

+			snprintf(wifi_set_flags_str, sizeof(wifi_set_flags_str), "%u", wifi_set_flags);

+			sc_cfg_set("wifi_set_flags", wifi_set_flags_str);

+			basic_deal_all(WIFI_CFG_AP);//MSG_CMD_WIFI_CFG_AP

+		}

+		break;

+	}

 	default:

 		break;

 	}

@@ -1220,7 +1412,7 @@
 	case IN_WIFI_AP_INDEX_AP0:

 		if (data_buf->enable) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

 			wf_log("cap open wifi");

-			if (!ap_server->ap0_state) {

+			if (!ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {

 				char m_ssid_enable[8] = {0};

 				

 				send_ap_status_to_cap(idx, IN_WIFI_AP_STATUS_ENABLING);

@@ -1236,14 +1428,39 @@
 		}

 		else {

 			wf_log("cap close wifi");

-			if (ap_server->ap0_state) {

+			if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP0) {

 				send_ap_status_to_cap(idx, IN_WIFI_AP_STATUS_DISABLING);

 				basic_deal_all(WIFI_CFG_CLOSE);

 				send_ap_status_to_cap(idx, IN_WIFI_AP_STATUS_IDLE);

 			}

 		}

 		break;

-	//case SC_WIFI_AP_INDEX_AP1: ...

+	case IN_WIFI_AP_INDEX_AP1:

+		if (data_buf->enable) {//jia yi ge nv ,zai cap sc_wifi_ap_start hou,zhi xing zhe xie

+			wf_log("cap open wifi 5G");

+			if (!ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {

+				char m_ssid_enable[8] = {0};

+				

+				send_ap_status_to_cap(idx, IN_WIFI_AP_STATUS_ENABLING);

+				

+

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

+				if (1 == atoi (m_ssid_enable)) {

+					basic_deal_all(WIFI_CFG_OPEN_VA0_VA1);

+				} else {

+					basic_deal_all(WIFI_CFG_OPEN);

+				}

+			}

+		}

+		else {

+			wf_log("cap close wifi 5G");

+			if (ap_server->ap0_state && g_work_mode == IN_WIFI_WORK_MODE_AP1) {

+				send_ap_status_to_cap(idx, IN_WIFI_AP_STATUS_DISABLING);

+				basic_deal_all(WIFI_CFG_CLOSE);

+				send_ap_status_to_cap(idx, IN_WIFI_AP_STATUS_IDLE);

+			}

+		}

+		break;

 	default:

 		break;

 	}

@@ -1423,8 +1640,8 @@
 		cap_wifi_disable(pMsg);

 		break;

 	case MSG_CMD_CAP_WIFI_WORK_MODE:

-		//to do, when enable, send mode to cap

-		//cap_wifi_mode_set

+		//before enable, set mode;

+		cap_wifi_mode_set(pMsg);

 		break;

 

 	case MSG_CMD_CAP_WIFI_SET_SSID: