Merge "[rdkb][hal] fix dmcli set password fail issue in wpa3psk mode"
diff --git a/src/logan_wifi/wifi_hal.c b/src/logan_wifi/wifi_hal.c
index 3d9d1d3..8954aef 100644
--- a/src/logan_wifi/wifi_hal.c
+++ b/src/logan_wifi/wifi_hal.c
@@ -81,6 +81,7 @@
 #define MAX_SUB_CMD_SIZE 200
 
 #define IF_NAME_SIZE 16
+#define MAX_SSID_NAME_LEN 33
 #define CONFIG_PREFIX "/nvram/hostapd"
 #define ACL_PREFIX "/nvram/hostapd-acl"
 #define DENY_PREFIX "/nvram/hostapd-deny"
@@ -306,6 +307,10 @@
 };
 struct mld_configuration mld_config;
 
+wifi_hal_capability_t g_hal_cap;
+
+#define RUNTIME_MAX_RADIO g_phy_count
+
 static int util_unii_5g_centerfreq(const char *ht_mode, int channel);
 static int util_unii_6g_centerfreq(const char *ht_mode, int channel);
 wifi_secur_list *	   wifi_get_item_by_key(wifi_secur_list *list, int list_sz, int key);
@@ -581,6 +586,7 @@
 static char l1profile[32] = "/etc/wireless/l1profile.dat";
 char main_prefix[MAX_NUM_RADIOS][IFNAMSIZ];
 char ext_prefix[MAX_NUM_RADIOS][IFNAMSIZ];
+int g_phy_count = 0;
 #define MAX_SSID_LEN  64
 char default_ssid[MAX_NUM_RADIOS][MAX_SSID_LEN];;
 int radio_band[MAX_NUM_RADIOS];
@@ -689,8 +695,8 @@
 #define WMODE_CAP_2G(_x) \
 (((_x) & (WMODE_B | WMODE_G | WMODE_GN | WMODE_AX_24G | WMODE_BE_24G)) != 0)
 
-static int array_index_to_vap_index(UINT radioIndex, int arrayIndex);
-static int vap_index_to_array_index(int vapIndex, int *radioIndex, int *arrayIndex);
+static int array_index_to_vap_index(UINT radioIndex, int arrayIndex, int *vap_index);
+static int vap_index_to_radio_array_index(int vapIndex, int *radioIndex, int *arrayIndex);
 static int wifi_datfileRead(char *conf_file, char *param, char *output, int output_size);
 int hwaddr_aton2(const char *txt, unsigned char *addr);
 static int wifi_GetInterfaceName(int apIndex, char *interface_name);
@@ -701,7 +707,7 @@
 								char *output,
 								int output_size,
 								char *default_value);
-static int array_index_to_vap_index(UINT radioIndex, int arrayIndex);
+static int array_index_to_vap_index(UINT radioIndex, int arrayIndex, int *vap_index);
 struct params
 {
 	char * name;
@@ -709,13 +715,22 @@
 };
 static int wifi_datfileWrite(char *conf_file, struct params *list, int item_count);
 
+int get_bandwidth_handler(struct nl_msg *msg, void *data);
+
+INT mtk_wifi_get_radio_info(
+	INT radioIndex, INT vendor_data_attr, mtk_nl80211_cb call_back, void *output);
+
+
 #ifdef WIFI_HAL_VERSION_3
 #define MAX_ML_MLD_CNT	16	/*Max multi-link MLD*/
 //#define MAX_SL_MLD_CNT	48	/*MAX single-link MLD*/
 
 static void mld_set(unsigned char mld_index, unsigned char set)
 {
-	mld_config.valid_mld_bitmap[mld_index / 8] |= set ? (1 << (mld_index % 8)) : ~(1 << (mld_index % 8));
+	if (set)
+		mld_config.valid_mld_bitmap[mld_index / 8] |= (1 << (mld_index % 8));
+	else
+		mld_config.valid_mld_bitmap[mld_index / 8] &= ~(1 << (mld_index % 8));
 }
 
 static unsigned char mld_test(unsigned char mld_index)
@@ -725,7 +740,10 @@
 
 static void mld_ap_set(struct multi_link_device *mld, unsigned char ap_index, unsigned char set)
 {
-	mld->affiliated_ap_bitmap[ap_index / 8] |= set ? (1 << (ap_index % 8)) : ~(1 << (ap_index % 8));
+	if (set)
+		mld->affiliated_ap_bitmap[ap_index / 8] |= (1 << (ap_index % 8));
+	else
+		mld->affiliated_ap_bitmap[ap_index / 8] &= ~(1 << (ap_index % 8));
 }
 
 static unsigned char mld_ap_test(struct multi_link_device *mld, unsigned char ap_index)
@@ -733,29 +751,107 @@
 	return mld->affiliated_ap_bitmap[ap_index / 8] & (1 << (ap_index % 8));
 }
 
+int ml_info_callback(struct nl_msg *msg, void *data) {
+    struct nlattr *tb[NL80211_ATTR_MAX + 1];
+    struct nlattr *vndr_tb[MTK_NL80211_VENDOR_ATTR_BSS_MLO_INFO_ATTR_MAX + 1];
+    struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+    int err = 0;
+
+    err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+              genlmsg_attrlen(gnlh, 0), NULL);
+    if (err < 0){
+        wifi_debug(DEBUG_ERROR, "get NL80211_ATTR_MAX fails\n");
+        return err;
+    }
+
+    if (tb[NL80211_ATTR_VENDOR_DATA]) {
+        err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_ATTR_BSS_MLO_INFO_ATTR_MAX,
+            tb[NL80211_ATTR_VENDOR_DATA], NULL);
+        if (err < 0){
+            wifi_debug(DEBUG_ERROR, "get MTK_NL80211_VENDOR_ATTR_BSS_MLO_INFO fails\n");
+            return err;
+        }
+
+        if (vndr_tb[MTK_NL80211_VENDOR_ATTR_BSS_MLO_INFO]) {
+			if ((size_t)nla_len(vndr_tb[MTK_NL80211_VENDOR_ATTR_BSS_MLO_INFO]) !=
+				sizeof(struct bss_mlo_info)) {
+				wifi_debug(DEBUG_ERROR, "wrong mlo info from driver\n");
+				return -1;
+			}
+			memcpy(data, nla_data(vndr_tb[MTK_NL80211_VENDOR_ATTR_BSS_MLO_INFO]), sizeof(struct bss_mlo_info));
+        } else
+        return -1;
+    }
+
+    return 0;
+}
+
+static INT eht_mld_nl80211_get_bss_mlo_info(INT apIndex, struct bss_mlo_info *ml_info)
+{
+	char inf_name[IF_NAME_SIZE] = {0};
+	unsigned int if_idx = 0;
+	int ret = -1;
+	struct unl unl_ins;
+	struct nl_msg *msg	= NULL;
+	struct nlattr * msg_data = NULL;
+	struct mtk_nl80211_param param;
+
+	if (wifi_GetInterfaceName(apIndex, inf_name) != RETURN_OK)
+		return RETURN_ERR;
+	if_idx = if_nametoindex(inf_name);
+
+	/*init mtk nl80211 vendor cmd*/
+	param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_GET_BSS_MLO_INFO;
+	param.if_type = NL80211_ATTR_IFINDEX;
+	param.if_idx = if_idx;
+
+	ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
+	if (ret) {
+		wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
+		return RETURN_ERR;
+	}
+	/*add mtk vendor cmd data*/
+	if (nla_put_flag(msg, MTK_NL80211_VENDOR_ATTR_BSS_MLO_INFO)) {
+		wifi_debug(DEBUG_ERROR, "Nla put vendor_data_attr(%d) attribute error\n", MTK_NL80211_VENDOR_ATTR_BSS_MLO_INFO);
+		nlmsg_free(msg);
+		goto err;
+	}
+
+	/*send mtk nl80211 vendor msg*/
+	ret = mtk_nl80211_send(&unl_ins, msg, msg_data, ml_info_callback, (void*)ml_info);
+	if (ret) {
+		wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
+		goto err;
+	}
+	/*deinit mtk nl80211 vendor msg*/
+	mtk_nl80211_deint(&unl_ins);
+	wifi_debug(DEBUG_INFO,"send cmd success\n");
+	return RETURN_OK;
+err:
+	mtk_nl80211_deint(&unl_ins);
+	wifi_debug(DEBUG_ERROR,"send cmd fails\n");
+	return RETURN_ERR;
+}
+
 static int eht_mld_config_init(void)
 {
-	char config_file[128] = {0}, str_mldgroup[256], *buf, mac_str[32] = {0};
+	char config_file[128] = {0}, str_mldgroup[256];
 	int res, band, bss_idx;
 	char *token;
 	long mld_index;
 	unsigned char ap_index;
+	int vap_idx;
 	struct multi_link_device *mld;
-	char *mld_start, *mldaddr_start, *mldaddr_end;
+	BOOL ap_enable = 0;
+	struct bss_mlo_info ml_info;
 
-	buf = (char*)malloc(4096);
-	if (!buf) {
-		wifi_debug(DEBUG_ERROR, "fail to allocate memory\n");
-		return RETURN_ERR;
-	}
 	wifi_debug(DEBUG_ERROR, "==========>\n");
 
 	memset(&mld_config, 0, sizeof(mld_config));
-	for (band = 0; band < MAX_NUM_RADIOS; band++) {
+	for (band = 0; band < RUNTIME_MAX_RADIO; band++) {
 		res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
 		if (os_snprintf_error(sizeof(config_file), res)) {
 			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
-			free(buf);
 			return RETURN_ERR;
 		}
 
@@ -776,13 +872,13 @@
 			}
 
 			mld_set(mld_index, 1);
-			ap_index = array_index_to_vap_index(band, bss_idx);
-
+			if (array_index_to_vap_index(band, bss_idx, &vap_idx) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid band %d, bss_idx %d, skip it.\n", band, bss_idx);
+				continue;
+			}
+			ap_index = vap_idx;
 			mld = &(mld_config.mld[mld_index]);
 			mld->mld_index = mld_index;
-			/* need to fulfill mld mac later.
-			memcpy(mld->mld_mac, mac, sizeof(mld->mld_mac));
-			*/
 //			mld->type = mld_index <= MAX_ML_MLD_CNT ? AP_MLD_MULTI_LINK : AP_MLD_SINGLE_LINK;
 			mld_ap_set(mld, ap_index, 1);
 			bss_idx++;
@@ -791,82 +887,37 @@
 		}
 	}
 
-	res = _syscmd_secure(buf, 4096,
-		"mwctl ra0 show bssmngr;dmesg | tail -500 | grep -e \"MLD\" -e \"bss_mngr_con_info_show\"");
-	if (res) {
-		wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
-		free(buf);
-		return RETURN_ERR;
-	}
-
-	/*fulfill mld mac address from bssmngr information*/
-	mld_start = strstr(buf, "bss_mngr_con_info_show");
-	if (!mld_start) {
-		wifi_debug(DEBUG_ERROR, "fail to find string \"bss_mngr_con_info_show\"\n");
-		printf("*************************\n");
-		printf("buf:%s\n", buf);
-		printf("*************************\n");
-		free(buf);
-		return RETURN_ERR;
-	}
-	mld_start = strstr(mld_start, "MLD[");
-	if (!mld_start) {
-		printf("*************************\n");
-		printf("mld_start:%s\n", buf);
-		printf("*************************\n");
-	}
-	while (mld_start) {
-		if (hal_strtol(mld_start + 4, 10, &mld_index) < 0) {
-			wifi_debug(DEBUG_ERROR, "strtol fail\n");
-			free(buf);
-			return RETURN_ERR;
-		}
+	for (ap_index = 0; ap_index < MAX_APS; ap_index++) {
+		if (wifi_getApEnable(ap_index, &ap_enable) != RETURN_OK)
+			continue;
 
-		if (mld_index == 0 || mld_index > MAX_ML_MLD_CNT) {
-			wifi_debug(DEBUG_ERROR, "invalid mld_index %ld\n", mld_index);
-			mld_start = strstr(mld_start + 4, "MLD[");
+		if (!ap_enable)
 			continue;
-		}
 
-		if (!mld_test(mld_index)) {
-			wifi_debug(DEBUG_ERROR, "mld(%ld) is not obvoiusly config in dat file, stll maintain it!",
-				mld_index);
-			mld_set(mld_index, 1);
+		memset(&ml_info, 0, sizeof(ml_info));
+		if (eht_mld_nl80211_get_bss_mlo_info(ap_index, &ml_info) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "fail to get bss[%d] ml info\n", ap_index);
+			continue;
 		}
 
-		mld = &(mld_config.mld[mld_index]);
-		mldaddr_start = strstr(mld_start, "MLD Addr:");
-		if (!mldaddr_start) {
-			wifi_debug(DEBUG_ERROR, "invalid mld address from bssmngr, mld_index=%ld\n", mld_index);
-			free(buf);
-			return RETURN_ERR;
-		}
-		mldaddr_end = strstr(mldaddr_start, ")");
-		if (!mldaddr_end) {
-			wifi_debug(DEBUG_ERROR, "invalid mld address from bssmngr, mld_index=%ld\n", mld_index);
-			free(buf);
-			return RETURN_ERR;
+		if (ml_info.mld_grp_idx == 0 || ml_info.mld_grp_idx > MAX_ML_MLD_CNT) {
+			wifi_debug(DEBUG_ERROR, "invalid mld_index %d\n", ml_info.mld_grp_idx);
+			continue;
 		}
 
-		memset(mac_str, 0, sizeof(mac_str));
-		if ((mldaddr_end - mldaddr_start - 10) >= sizeof(mac_str)) {
-			wifi_debug(DEBUG_ERROR, "invalid mld address string from bssmngr, mld_index=%ld\n",
-				mld_index);
-			free(buf);
-			return RETURN_ERR;
-		}
-		strncpy(mac_str, mldaddr_start + 10, mldaddr_end - mldaddr_start - 10);
-		if (!hwaddr_aton2(mac_str, mld->mld_mac)) {
-			wifi_debug(DEBUG_ERROR, "invalid mld address from bssmngr, mld_index=%ld\n", mld_index);
-			free(buf);
-			return RETURN_ERR;
+		if (!mld_test(ml_info.mld_grp_idx)) {
+			wifi_debug(DEBUG_ERROR, "!!mld(%d) is not obvoiusly config in dat file, skip it.",
+				ml_info.mld_grp_idx);
+			continue;
 		}
-
-		mld_start = strstr(mldaddr_end, "MLD[");
+		wifi_debug(DEBUG_ERROR, "!Successfully get bss[%d] ml info from driver, mld_grp_idx=%d"
+			"mld_addr=%02x:%02x:%02x:%02x:%02x:%02x\n", ap_index, ml_info.mld_grp_idx,
+			ml_info.addr[0], ml_info.addr[1], ml_info.addr[2], ml_info.addr[3], ml_info.addr[4],
+			ml_info.addr[5]);
+		mld = &(mld_config.mld[ml_info.mld_grp_idx]);
+		memcpy(mld->mld_mac, ml_info.addr, sizeof(mld->mld_mac));
 	}
-	wifi_debug(DEBUG_ERROR, "<==========\n");
 
-	free(buf);
 	return RETURN_OK;
 }
 
@@ -1005,12 +1056,11 @@
 
 INT wifi_eht_add_to_ap_mld(unsigned char mld_index, INT ap_index)
 {
-	int res;
+	int res, radio1, radio2, bss_idx;
 //	enum mld_type type;
 	struct multi_link_device *mld;
 	char interface_name[IF_NAME_SIZE] = {0};
 	unsigned char i;
-	int max_radio_num;
 
 	if (ap_index < 0 || ap_index >= MAX_APS) {
 		wifi_debug(DEBUG_ERROR, "invalid ap_index %d\n", ap_index);
@@ -1054,17 +1104,24 @@
 	} else if (mld->type == AP_MLD_MULTI_LINK) {
 #endif
 		/*check if a same band ap already has been joined before*/
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
-		return RETURN_ERR;
-	}
 	for (i = 0; i < MAX_APS; i++) {
 		if(mld_ap_test(mld, i)) {
 			if (i == ap_index) {
 				wifi_debug(DEBUG_ERROR, "current ap(index=%d) has already joined current mld\n", i);
 				return RETURN_OK;
 			}
+
+			if (vap_index_to_radio_array_index(i, &radio1, &bss_idx) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid vap index %d\n", i);
+				return RETURN_ERR;
+			}
-			if ((i % max_radio_num) == (ap_index % max_radio_num)) {
+
+			if (vap_index_to_radio_array_index(ap_index, &radio2, &bss_idx) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid vap index %d\n", i);
+				return RETURN_ERR;
+			}
+
+			if (radio1 == radio2) {
 				wifi_debug(DEBUG_ERROR, "same band ap(index=%d) has already joined current mld\n", i);
 				return RETURN_ERR;
 			}
@@ -1113,7 +1170,7 @@
 
 	mld = &(mld_config.mld[mld_index]);
 
-	res = v_secure_system("mwctl %s apmld=dellink", interface_name);
+	res = v_secure_system("mwctl %s set apmld=dellink", interface_name);
 
 	if (res) {
 		wifi_debug(DEBUG_ERROR, "fail to del ap from ap mld with mld_index %d\n", mld_index);
@@ -1156,12 +1213,11 @@
 INT wifi_eht_mld_ap_transfer(unsigned char old_mld_index,
 	unsigned char new_mld_index, INT ap_index)
 {
-	int res;
+	int res, radio1, radio2, bss_idx;
 //	enum mld_type type;
 	struct multi_link_device *mld, *old_mld;
 	char interface_name[IF_NAME_SIZE] = {0};
 	unsigned char i;
-	int max_radio_num;
 
 	if (old_mld_index == new_mld_index) {
 		wifi_debug(DEBUG_ERROR, "same mld index %d\n", new_mld_index);
@@ -1182,7 +1238,7 @@
 		wifi_debug(DEBUG_ERROR, "invalid old_mld_index %d\n", old_mld_index);
 		return RETURN_ERR;
 	}
-	old_mld = mld = &(mld_config.mld[new_mld_index]);
+	old_mld = &(mld_config.mld[old_mld_index]);
 
 	if (!mld_test(old_mld_index)) {
 		wifi_debug(DEBUG_ERROR, "mld does not exist with old_mld_index %d\n", old_mld_index);
@@ -1203,17 +1259,25 @@
 
 	mld = &(mld_config.mld[new_mld_index]);
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
-		return RETURN_ERR;
-	}
+
 	for (i = 0; i < MAX_APS; i++) {
 		if(mld_ap_test(mld, i)) {
 			if (i == ap_index) {
 				wifi_debug(DEBUG_ERROR, "current ap has already joined current mld\n");
 				return RETURN_OK;
 			}
+
+			if (vap_index_to_radio_array_index(i, &radio1, &bss_idx) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid vap index %d\n", i);
+				return RETURN_ERR;
+			}
-			if ((i % max_radio_num) == (ap_index % max_radio_num)) {
+
+			if (vap_index_to_radio_array_index(ap_index, &radio2, &bss_idx) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid vap index %d\n", i);
+				return RETURN_ERR;
+			}
+
+			if (radio1 == radio2) {
 				wifi_debug(DEBUG_ERROR, "same band ap(index=%d) has already joined current mld\n", i);
 				return RETURN_ERR;
 			}
@@ -1240,7 +1304,7 @@
 	int res, vap_index, len = 0, bssidnum;
 	struct params MldGroup;
 
-	if (band >= MAX_NUM_RADIOS) {
+	if (band >= RUNTIME_MAX_RADIO) {
 		wifi_debug(DEBUG_ERROR, "invalid band %u\n", band);
 		return RETURN_ERR;
 	}
@@ -1268,8 +1332,7 @@
 	}
 
 	for (bss_idx = 0; bss_idx < bssidnum; bss_idx++) {
-		vap_index = array_index_to_vap_index(band, bss_idx);
-		if (vap_index == RETURN_ERR) {
+		if (array_index_to_vap_index(band, bss_idx, &vap_index) != RETURN_OK) {
 			wifi_debug(DEBUG_ERROR, "invalide vap index, band=%d, bss_idx=%d\n", (int)band, (int)bss_idx);
 			break;
 		}
@@ -1294,7 +1357,7 @@
 {
 	unsigned char band;
 
-	for (band = 0; band < MAX_NUM_RADIOS; band++) {
+	for (band = 0; band < RUNTIME_MAX_RADIO; band++) {
 		wifi_eht_config_sync2_dat_by_radio(band);
 	}
 }
@@ -1629,17 +1692,16 @@
 	long int nl80211_band = 0;
 	int i = 0;
 	int phyIndex = 0;
-	int radioIndex = 0;
-	int max_radio_num = 0;
+	int radioIndex = 0, bss_idx;
 	wifi_band band = band_invalid;
 	int res;
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
+	if (vap_index_to_radio_array_index(apIndex, &radioIndex, &bss_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid vap index %d\n", apIndex);
 		return RETURN_ERR;
 	}
-	radioIndex = apIndex % max_radio_num;
+
 	phyIndex = radio_index_to_phy(radioIndex);
 	while (i < 10) {
 		res = _syscmd_secure(buf, sizeof(buf),
@@ -1878,8 +1940,13 @@
 	char buf[MAX_CMD_SIZE]={'\0'};
 	UCHAR channel = 0;
 	int res;
+	int main_vap_idx;
+
+	if (array_index_to_vap_index(radio_index, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radio_index);
+	}
 
-	if (wifi_GetInterfaceName(radio_index, interface_name) != RETURN_OK)
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 	/*interface name to channel number*/
 	res = _syscmd_secure(buf, sizeof(buf), "iw dev %s info | grep -i 'channel' | cut -d ' ' -f2", interface_name);
@@ -2450,7 +2517,7 @@
 			}
 			if (get_value(card_profile, buf, band_profile, sizeof(band_profile)) < 0) {
 				/* LOG */
-				break;
+				continue;
 			}
 
 			res = snprintf(buf, sizeof(buf), "INDEX%d_main_ifname", card_idx);
@@ -2482,6 +2549,7 @@
 			wmode = cfgmode_to_wmode(wireless_mode);
 			radio_band[phy_idx] = wlan_config_set_ch_band(wmode);
 			phy_idx++;
+			g_phy_count = phy_idx;
 		}
 	}
 
@@ -2506,7 +2574,10 @@
 	for (radio_idx = 0; radio_idx < MAX_NUM_RADIOS; radio_idx++) {
 
 		for (bss_idx = 0; bss_idx < LOGAN_MAX_NUM_VAP_PER_RADIO; bss_idx++) {
-			ap_idx = array_index_to_vap_index(radio_idx, bss_idx);
+			if (array_index_to_vap_index(radio_idx, bss_idx, &ap_idx) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid radio_idx %d, bss_idx %d\n", radio_idx, bss_idx);
+				continue;
+			}
 
 			res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_idx);
 			if (os_snprintf_error(sizeof(config_file), res)) {
@@ -2601,7 +2672,10 @@
 	wifi_debug(DEBUG_ERROR, "band %d BssidNum %d\n", radio_idx, bss_num);
 	/*TBD: we need refine setup flow and mbss flow*/
     for (bss_idx = 0; bss_idx < bss_num; bss_idx++) {
-		ap_idx = array_index_to_vap_index(radio_idx, bss_idx);
+		if (array_index_to_vap_index(radio_idx, bss_idx, &ap_idx) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid radio_idx %d, bss_idx %d\n", radio_idx, bss_idx);
+			continue;
+		}
 
 		res = _syscmd_secure(ret_buf, sizeof(ret_buf), "touch %s%d.psk", PSK_FILE, ap_idx);
 		if (res) {
@@ -2646,7 +2720,7 @@
     int band_idx;
 
     WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
-    for (radio_idx = 0; radio_idx < MAX_NUM_RADIOS; radio_idx++) {
+    for (radio_idx = 0; radio_idx < RUNTIME_MAX_RADIO; radio_idx++) {
         band_idx = radio_index_to_band(radio_idx);
         if (band_idx < 0) {
             break;
@@ -2681,7 +2755,7 @@
 	int band_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
-	for (radio_idx = 0; radio_idx < MAX_NUM_RADIOS; radio_idx++) {
+	for (radio_idx = 0; radio_idx < RUNTIME_MAX_RADIO; radio_idx++) {
 		band_idx = radio_index_to_band(radio_idx);
 		if (band_idx < 0) {
 			break;
@@ -2778,21 +2852,24 @@
 
 static void wifi_radio_reset_count_reset()
 {
-
 	char ret_buf[MAX_BUF_SIZE] = {0};
 	int res;
+	FILE *f = NULL;
 
 	if (access(RADIO_RESET_FILE, F_OK) != 0) {
 		res =  _syscmd_secure(ret_buf, sizeof(ret_buf), "touch %s", RADIO_RESET_FILE);
 		if (res) {
 			wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
 		}
-	} else {
-		res =  _syscmd_secure(ret_buf, sizeof(ret_buf), "echo '' > /nvram/radio_reset");
-		if (res) {
-			wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
-		}
 	}
+	f = fopen("/nvram/radio_reset", "w");
+	if (f == NULL)
+		return;
+	fprintf(f, "%s", "reset0=0\n");
+	fprintf(f, "%s", "reset1=0\n");
+	fprintf(f, "%s", "reset2=0\n");
+	if (fclose(f) == EOF)
+		wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
 }
 
 static void wifi_guard_interval_file_check()
@@ -2802,10 +2879,8 @@
 	unsigned char i = 0;
 	char file[MAX_SUB_CMD_SIZE] = {0};
 	FILE *f = NULL;
-	INT radio_num = 0;
 
-	wifi_getMaxRadioNumber(&radio_num);
-	for (i = 0; i < radio_num; i++) {
+	for (i = 0; i < RUNTIME_MAX_RADIO; i++) {
 		res = snprintf(file, sizeof(file), "%s%d.txt", GUARD_INTERVAL_FILE, i);
 		if (os_snprintf_error(sizeof(file), res)) {
 			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
@@ -2862,10 +2937,8 @@
 	unsigned char i = 0;
 	char file[MAX_SUB_CMD_SIZE] = {0};
 	FILE *f = NULL;
-	INT radio_num = 0;
 
-	wifi_getMaxRadioNumber(&radio_num);
-	for (i = 0; i < radio_num; i++) {
+	for (i = 0; i < RUNTIME_MAX_RADIO; i++) {
 		res = snprintf(file, sizeof(file), "%s%d.txt", MCS_FILE, i);
 		if (os_snprintf_error(sizeof(file), res)) {
 			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
@@ -2886,12 +2959,26 @@
 	}
 }
 
+static void wifi_upload_reset()
+{
+	FILE *f = NULL;
+
+	if (access("/tmp/upload", F_OK) != 0) {
+		f = fopen("/tmp/upload", "w+");
+		if (f == NULL)
+			return;
+		fprintf(f, "%s", "5");
+		if (fclose(f) == EOF)
+			wifi_debug(DEBUG_ERROR, "Unexpected fclose fail\n");
+	}
+}
 
 // Initializes the wifi subsystem (all radios)
 INT wifi_init()							//RDKB
 {
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 	static int CallOnce = 1;
+
 	//Not intitializing macfilter for Turris-Omnia Platform for now
 	//macfilter_init();
 	if (CallOnce) {
@@ -2911,6 +2998,8 @@
 		wifi_guard_interval_file_check();
 		wifi_power_percentage_file_check();
 		wifi_mcs_file_check();
+		/* for wifiagent TDK test */
+		wifi_upload_reset();
 	}
 
 	WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
@@ -2938,7 +3027,7 @@
 */
 INT wifi_reset()
 {
-
+	int radio_idx;
 	wifi_BringDownInterfaces();
 	sleep(2);
 
@@ -2955,6 +3044,8 @@
 	sleep(2);
 
 	wifi_vap_status_reset();
+	for (radio_idx = 0; radio_idx < MAX_NUM_RADIOS; radio_idx++)
+		update_radio_reset_cnt(radio_idx);
 
 	return RETURN_OK;
 }
@@ -2981,10 +3072,7 @@
 INT wifi_down()
 {
 	//TODO: turns off transmit power for the entire Wifi subsystem, for all radios
-	int max_num_radios = 0;
-	wifi_getMaxRadioNumber(&max_num_radios);
-
-	for (int radioIndex = 0; radioIndex < max_num_radios; radioIndex++)
+	for (int radioIndex = 0; radioIndex < RUNTIME_MAX_RADIO; radioIndex++)
 		wifi_setRadioEnable(radioIndex, FALSE);
 
 	return RETURN_OK;
@@ -3098,10 +3186,15 @@
 	unsigned long tmp_ul;
 	size_t len = 0;
 	FILE *f = NULL;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	res = _syscmd_secure(buf, sizeof(buf), "iw %s scan | grep signal | awk '{print $2}' | sort -n | tail -n1", interface_name);
@@ -3239,7 +3332,7 @@
 {
 	if (NULL == output)
 		return RETURN_ERR;
-	*output = MAX_NUM_RADIOS;
+	*output = RUNTIME_MAX_RADIO;
 
 	return RETURN_OK;
 }
@@ -3259,22 +3352,20 @@
 {
 	char interface_name[16] = {0};
 	char buf[128] = {0};
-	int apIndex;
-	int max_radio_num = 0;
+	int apIndex, bss_idx;
 
 	if (NULL == output_bool)
 		return RETURN_ERR;
 
 	*output_bool = FALSE;
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-
-	if (radioIndex >= max_radio_num)
-		return RETURN_ERR;
-
 	/* loop all interface in radio, if any is enable, reture true, else return false */
-	for(apIndex = radioIndex; apIndex < MAX_APS; apIndex += max_radio_num)
+	for (bss_idx = 0; bss_idx < LOGAN_MAX_NUM_VAP_PER_RADIO; bss_idx++)
 	{
+		if (array_index_to_vap_index(radioIndex, bss_idx, &apIndex) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid radioIndex %d, bss_idx %d\n", radioIndex, bss_idx);
+			continue;
+		}
 		if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
 			continue;
 
@@ -3440,19 +3531,21 @@
 {
 	char interface_name[16] = {0};
 	char buf[MAX_BUF_SIZE] = {0};
-	int apIndex;
-	int max_radio_num = 0;
+	int apIndex, bss_idx;
 	int phyId = 0, res;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
 	phyId = radio_index_to_phy(radioIndex);
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-
 	if(enable == FALSE) {
 
+		if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		}
+
-		if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+		if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 			return RETURN_ERR;
 
 
@@ -3470,9 +3563,15 @@
 		if(strncmp(buf, "OK", 2))
 			wifi_debug(DEBUG_ERROR, "Could not detach %s from hostapd daemon", interface_name);
 	} else {
-		for (apIndex = radioIndex; apIndex < MAX_APS; apIndex += max_radio_num) {
-			if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
+		for (bss_idx = 0; bss_idx < LOGAN_MAX_NUM_VAP_PER_RADIO; bss_idx++) {
+			if (array_index_to_vap_index(radioIndex, bss_idx, &apIndex) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid radioIndex %d, bss_idx %d\n", radioIndex, bss_idx);
+				continue;
+			}
+			if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "!!!Fail to get name of apIndex[%d]\n", apIndex);
 				return RETURN_ERR;
+			}
 
 			memset(buf, 0, MAX_BUF_SIZE);
 
@@ -3518,9 +3617,15 @@
 //Get the Radio Interface name from platform, eg "wlan0"
 INT wifi_getRadioIfName(INT radioIndex, CHAR *output_string) //Tr181
 {
-	if (NULL == output_string || radioIndex>=MAX_NUM_RADIOS || radioIndex<0)
+	int main_vap_idx;
+
+	if (NULL == output_string || radioIndex>=RUNTIME_MAX_RADIO || radioIndex<0)
 		return RETURN_ERR;
-	return wifi_GetInterfaceName(radioIndex, output_string);
+
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+	}
+	return wifi_GetInterfaceName(main_vap_idx, output_string);
 }
 
 int mtk_get_vow_info_callback(struct nl_msg *msg, void *data)
@@ -3621,14 +3726,14 @@
 
 INT wifi_setATMEnable(BOOL enable)
 {
-	int max_radio_num = 0;
 	int radio_idx = 0;
+	int bss_idx;
 	char dat_file[MAX_BUF_SIZE] = {0};
 	int res;
-	struct params params[2];
+	struct params params[3];
+	struct vow_group_en_param atc_en_param;
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	for (radio_idx = 0; radio_idx < max_radio_num; radio_idx++) {
+	for (radio_idx = 0; radio_idx < RUNTIME_MAX_RADIO; radio_idx++) {
 		if (mtk_wifi_set_air_time_management
 			(radio_idx, MTK_NL80211_VENDOR_ATTR_AP_VOW_ATF_EN_INFO,
 			NULL, (char *)&enable, 1, NULL)!= RETURN_OK) {
@@ -3643,17 +3748,31 @@
 			return RETURN_ERR;
 		}
 
+		/* atc support 15 group now , per band use 5 group */
+		for (bss_idx = 0; bss_idx < 5; bss_idx++) {
+			atc_en_param.group = bss_idx;
+			atc_en_param.en = enable;
+			if (mtk_wifi_set_air_time_management
+				(radio_idx, MTK_NL80211_VENDOR_ATTR_AP_VOW_ATC_EN_INFO,
+				NULL, (char *)&atc_en_param, sizeof(struct vow_group_en_param), NULL)!= RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_ATC_EN_INFO cmd fails\n");
+				return RETURN_ERR;
+			}
+		}
+
 		params[0].name = "VOW_Airtime_Fairness_En";
 		params[0].value = enable ? "1" : "0";
 		params[1].name = "VOW_BW_Ctrl";
 		params[1].value = enable ? "1" : "0";
+		params[2].name = "VOW_Airtime_Ctrl_En";
+		params[2].value = enable ? "1;1;1;1;1;0;0;0;0;0;0;0;0;0;0" : "0;0;0;0;0;0;0;0;0;0;0;0;0;0;0";
 
 		res = snprintf(dat_file, sizeof(dat_file), "%s%d.dat", LOGAN_DAT_FILE, radio_idx);
 		if (os_snprintf_error(sizeof(dat_file), res)) {
 			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
 			return RETURN_ERR;
 		}
-		wifi_datfileWrite(dat_file, params, 2);
+		wifi_datfileWrite(dat_file, params, 3);
 	}
 
     return RETURN_OK;
@@ -3661,7 +3780,6 @@
 
 INT wifi_getATMEnable(BOOL *output_enable)
 {
-	int max_radio_num = 0;
 	int radio_idx = 0;
 	struct vow_info vow_info;
 	struct vow_info get_vow_info;
@@ -3670,7 +3788,6 @@
 	if (output_enable == NULL)
 		return RETURN_ERR;
 
-	wifi_getMaxRadioNumber(&max_radio_num);
 
 	*output_enable = FALSE;
 
@@ -3679,7 +3796,7 @@
 	cb_data.out_buf = (char *)&vow_info;
 	cb_data.out_len = sizeof(struct vow_info);
 
-	for (radio_idx = 0; radio_idx < max_radio_num; radio_idx++) {
+	for (radio_idx = 0; radio_idx < RUNTIME_MAX_RADIO; radio_idx++) {
 		if (mtk_wifi_set_air_time_management
 			(radio_idx, MTK_NL80211_VENDOR_ATTR_AP_VOW_GET_INFO,
 			mtk_get_vow_info_callback, (char *)&get_vow_info, sizeof(struct vow_info), &cb_data)!= RETURN_OK) {
@@ -3696,47 +3813,24 @@
     return RETURN_OK;
 }
 
-UINT apidx_to_group(INT apIndex)
-{
-	int max_radio_num = 0;
-	unsigned int group = 0;
-
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if (max_radio_num == 0) {
-		wifi_debug(DEBUG_ERROR, "invalid max radio num\n");
-		return 0;
-	}
-    group = apIndex / max_radio_num + 5 * (apIndex % max_radio_num);
-
-	return group;
-}
-
 INT wifi_setApATMAirTimePercent(INT apIndex, UINT ap_AirTimePercent)
 {
-	struct vow_group_en_param atc_en_param;
 	struct vow_ratio_param radio_param;
 	unsigned int group = 0;
-	//BOOL ATM_enable = FALSE;
+	int max_radio_num = 0;
 
-	if (ap_AirTimePercent < 5 || ap_AirTimePercent > 100) {
-		wifi_debug(DEBUG_ERROR, "invalid ait time percent!\n");
+	if (ap_AirTimePercent < 0 || ap_AirTimePercent > 100) {
+		wifi_debug(DEBUG_ERROR, "invalid air time percent!\n");
 		return RETURN_ERR;
 	}
 
-	/* mt7990 support 15 group now*/
-	group = apidx_to_group(apIndex);
-
-	if (group > 15) {
-		wifi_debug(DEBUG_ERROR, "invalid group!\n");
+	if (wifi_getMaxRadioNumber(&max_radio_num))
 		return RETURN_ERR;
-	}
+	/*support per band 5 group now*/
+	group = apIndex / max_radio_num;
 
-	atc_en_param.group = group;
-	atc_en_param.en = 1;
-	if (mtk_wifi_set_air_time_management
-		(apIndex, MTK_NL80211_VENDOR_ATTR_AP_VOW_ATC_EN_INFO,
-		NULL, (char *)&atc_en_param, sizeof(struct vow_group_en_param), NULL)!= RETURN_OK) {
-		wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_AP_VOW_ATC_EN_INFO cmd fails\n");
+	if (group > 5) {
+		wifi_debug(DEBUG_ERROR, "invalid group!\n");
 		return RETURN_ERR;
 	}
 
@@ -3764,12 +3858,16 @@
 	unsigned int group = 0;
 	struct vow_info get_vow_info, vow_info;
 	struct mtk_nl80211_cb_data cb_data;
+	int max_radio_num = 0;
 
 	if (output_ap_AirTimePercent == NULL)
 		return RETURN_ERR;
 
-	group = apidx_to_group(apIndex);
-	if (group > 15) {
+	if (wifi_getMaxRadioNumber(&max_radio_num))
+		return RETURN_ERR;
+
+	group = apIndex / max_radio_num;
+	if (group > 5) {
 		wifi_debug(DEBUG_ERROR, "invalid group!\n");
 		return RETURN_ERR;
 	}
@@ -4366,12 +4464,18 @@
 	struct nlattr * msg_data = NULL;
 	struct mtk_nl80211_param param;
 	struct mtk_nl80211_cb_data cb_data;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 	if (NULL == output_string || NULL == pureMode)
 		return RETURN_ERR;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	if_idx = if_nametoindex(interface_name);
@@ -4574,6 +4678,7 @@
 	char dat_file[MAX_BUF_SIZE] = {0};
 	struct params params={0};
 	int res;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s:%d_%d\n", __func__, channelMode, pureMode, __LINE__);
 
@@ -4584,7 +4689,12 @@
 		return RETURN_ERR;
 	}
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	if_idx = if_nametoindex(interface_name);
@@ -4789,98 +4899,410 @@
 	return RETURN_OK;
 }
 
-//Get the list for used channel. eg: "1,6,9,11"
-//The output_string is a max length 256 octet string that is allocated by the RDKB code.  Implementations must ensure that strings are not longer than this.
-INT wifi_getRadioChannelsInUse(INT radioIndex, CHAR *output_string)	//RDKB
-{
-	char interface_name[16] = {0};
+enum bw_idx {
+	BAND_WIDTH_20,
+	BAND_WIDTH_40,
+	BAND_WIDTH_80,
+	BAND_WIDTH_160,
+	BAND_WIDTH_8080 = 6,
+	BAND_WIDTH_320
+};
 
-	char buf[128] = {0};
-	char config_file[64] = {0};
-	int channel = 0;
-	int freq = 0;
-	int bandwidth = 0;
-	int center_freq = 0;
-	int center_channel = 0;
-	int channel_delta = 0;
-	wifi_band band = band_invalid;
-	int res;
+struct hal_ch_layout {
+	UCHAR ch_low_bnd;
+	UCHAR ch_up_bnd;
+	UCHAR cent_freq_idx;
+};
 
-	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
+static struct hal_ch_layout ch_5G_40M[] = {
+	{36, 40, 38},
+	{44, 48, 46},
+	{52, 56, 54},
+	{60, 64, 62},
+	{100, 104, 102},
+	{108, 112, 110},
+	{116, 120, 118},
+	{124, 128, 126},
+	{132, 136, 134},
+	{140, 144, 142},
+	{149, 153, 151},
+	{157, 161, 159},
+	{0, 0, 0},
+};
 
-	if (NULL == output_string)
-		return RETURN_ERR;
+static struct hal_ch_layout ch_5G_80M[] = {
+	{36, 48, 42},
+	{52, 64, 58},
+	{100, 112, 106},
+	{116, 128, 122},
+	{132, 144, 138},
+	{149, 161, 155},
+	{165, 177, 171},
+	{0, 0, 0},
+};
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
-		return RETURN_ERR;
+static struct hal_ch_layout ch_5G_160M[] = {
+	{36, 64, 50},
+	{100, 128, 114},
+	{149, 177, 163},
+	{0, 0, 0},
+};
 
-	res = _syscmd_secure(buf, sizeof(buf), "iw %s info | grep channel | sed -e 's/[^0-9 ]//g'", interface_name);
-	if (res) {
-		wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
+static struct hal_ch_layout ch_6G_40M[] = {
+	{1, 5, 3},
+	{9, 13, 11},
+	{17, 21, 19},
+	{25, 29, 27},
+	{33, 37, 35},
+	{41, 45, 43},
+	{49, 53, 51},
+	{57, 61, 59},
+	{65, 69, 67},
+	{73, 77, 75},
+	{81, 85, 83},
+	{89, 93, 91},
+	{97, 101, 99},
+	{105, 109, 107},
+	{113, 117, 115},
+	{121, 125, 123},
+	{129, 133, 131},
+	{137, 141, 139},
+	{145, 149, 147},
+	{153, 157, 155},
+	{161, 165, 163},
+	{169, 173, 171},
+	{177, 181, 179},
+	{185, 189, 187},
+	{193, 197, 195},
+	{201, 205, 203},
+	{209, 213, 211},
+	{217, 221, 219},
+	{225, 229, 227},
+	{0, 0, 0},
+};
+
+static struct hal_ch_layout ch_6G_80M[] = {
+	{1, 13, 7},
+	{17, 29, 23},
+	{33, 45, 39},
+	{49, 61, 55},
+	{65, 77, 71},
+	{81, 93, 87},
+	{97, 109, 103},
+	{113, 125, 119},
+	{129, 141, 135},
+	{145, 157, 151},
+	{161, 173, 167},
+	{177, 189, 183},
+	{193, 205, 199},
+	{209, 221, 215},
+	{0, 0, 0},
+};
+
+static struct hal_ch_layout ch_6G_160M[] = {
+	{1, 29, 15},
+	{33, 61, 47},
+	{65, 93, 79},
+	{97, 125, 111},
+	{129, 157, 143},
+	{161, 189, 175},
+	{193, 221, 207},
+	{0, 0, 0},
+};
+
+static struct  hal_ch_layout ch_6G_320M[] = {
+	{1, 61, 31},
+	{33, 93, 63},
+	{65, 125, 95},
+	{97, 157, 127},
+	{129, 189, 159},
+	{161, 221, 191},
+	{0, 0, 0},
+};
+
+struct hal_ch_layout *hal_get_ch_array(UCHAR bw, UCHAR ch_band, UCHAR *layout_size)
+{
+	switch (ch_band) {
+	case band_5:
+		if (bw == BAND_WIDTH_40) {
+			*layout_size = ARRAY_SIZE(ch_5G_40M);
+			return ch_5G_40M;
+		} else if (bw == BAND_WIDTH_80) {
+			*layout_size = ARRAY_SIZE(ch_5G_80M);
+			return ch_5G_80M;
+		} else if (bw == BAND_WIDTH_160) {
+			*layout_size = ARRAY_SIZE(ch_5G_160M);
+			return ch_5G_160M;
+		} else
+			return NULL;
+
+	case band_6:
+		if (bw == BAND_WIDTH_40) {
+			*layout_size = ARRAY_SIZE(ch_6G_40M);
+			return ch_6G_40M;
+		} else if (bw == BAND_WIDTH_80) {
+			*layout_size = ARRAY_SIZE(ch_6G_80M);
+			return ch_6G_80M;
+		} else if (bw == BAND_WIDTH_160) {
+			*layout_size = ARRAY_SIZE(ch_6G_160M);
+			return ch_6G_160M;
+		} else if (bw == BAND_WIDTH_320) {
+			*layout_size = ARRAY_SIZE(ch_6G_320M);
+			return ch_6G_320M;
+		} else
+			return NULL;
+
+	default:
+		return NULL;
 	}
-	if (strlen(buf) == 0) {
-		wifi_debug(DEBUG_ERROR, "failed to get channel information from iw.\n");
+}
+
+enum ext_ch {
+	EXT_NONE,
+	EXT_ABOVE,
+	EXT_BELOW = 3
+};
+
+int get_ExtCh_callback(struct nl_msg *msg, void *arg)
+{
+	UCHAR *data = (UCHAR *)arg;
+	struct nlattr *tb[NL80211_ATTR_MAX + 1];
+	struct nlattr *vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_MAX + 1];
+	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+	int err = 0;
+
+	err = nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+			  genlmsg_attrlen(gnlh, 0), NULL);
+	if (err < 0)
+		return NL_SKIP;
+
+	if (tb[NL80211_ATTR_VENDOR_DATA]) {
+		err = nla_parse_nested(vndr_tb, MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_MAX,
+			tb[NL80211_ATTR_VENDOR_DATA], NULL);
+		if (err < 0)
+			return NL_SKIP;
+
+		if (vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_EXTENSION_CHANNEL]) {
+			*data = nla_get_u8(vndr_tb[MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_EXTENSION_CHANNEL]);
+		}
+	}
+
+	return NL_OK;
+}
+
+//Get the extension channel via netlink
+UCHAR wifi_getExtCh_netlink(INT radioIndex)
+{
+	char interface_name[IF_NAME_SIZE] = {0};
+	int ret = -1;
+	unsigned int if_idx = 0;
+	struct unl unl_ins;
+	struct nl_msg *msg  = NULL;
+	struct nlattr * msg_data = NULL;
+	struct mtk_nl80211_param param;
+	UCHAR ext_ch = EXT_NONE;
+	int main_vap_idx;
+
+	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
+
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
 		return RETURN_ERR;
 	}
-	if (sscanf(buf, "%d %d %d %*d %d", &channel, &freq, &bandwidth, &center_freq) != 4) {
-		wifi_debug(DEBUG_ERROR, "sscanf format error.\n");
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
+		return RETURN_ERR;
+
+	if_idx = if_nametoindex(interface_name);
+	if (!if_idx) {
+		wifi_debug(DEBUG_ERROR, "can't finde ifname(%s) index,ERROR\n", interface_name);
 		return RETURN_ERR;
 	}
+	/*init mtk nl80211 vendor cmd*/
+	param.sub_cmd = MTK_NL80211_VENDOR_SUBCMD_GET_RUNTIME_INFO;
+	param.if_type = NL80211_ATTR_IFINDEX;
+	param.if_idx = if_idx;
 
-	if (bandwidth == 20) {
-		res = snprintf(output_string, 256, "%d", channel);
-		if (os_snprintf_error(256, res)) {
-			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
-			return RETURN_ERR;
-		}
-		return RETURN_OK;
+	ret = mtk_nl80211_init(&unl_ins, &msg, &msg_data, &param);
+	if (ret) {
+		wifi_debug(DEBUG_ERROR, "init mtk 80211 netlink and msg fails\n");
+		return RETURN_ERR;
+	}
+
+	/*add mtk vendor cmd data*/
+	if (nla_put_u8(msg, MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_EXTENSION_CHANNEL, 0)) {
+		wifi_debug(DEBUG_ERROR, "Nla put MTK_NL80211_VENDOR_ATTR_GET_RUNTIME_INFO_GET_EXTENSION_CHANNEL attribute error\n");
+		nlmsg_free(msg);
+		goto err;
 	}
 
+	/*send mtk nl80211 vendor msg*/
+	ret = mtk_nl80211_send(&unl_ins, msg, msg_data, get_ExtCh_callback, &ext_ch);
+
+	if (ret) {
+		wifi_debug(DEBUG_ERROR, "send mtk nl80211 vender msg fails\n");
+		goto err;
+	}
+	/*deinit mtk nl80211 vendor msg*/
+	mtk_nl80211_deint(&unl_ins);
+	wifi_debug(DEBUG_NOTICE,"send cmd success\n");
+
+	WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
+	return ext_ch;
+err:
+	mtk_nl80211_deint(&unl_ins);
+	wifi_debug(DEBUG_ERROR,"send cmd fails\n");
+	return EXT_NONE;
+
-	center_channel = ieee80211_frequency_to_channel(center_freq);
+}
+
+//Get the list for used channel. eg: "1,6,9,11"
+//the returned channels will be the all sub channels that the whole operating bw covers
+//The output_string is a max length 256 octet string that is allocated by the RDKB code.  Implementations must ensure that strings are not longer than this.
+INT wifi_getRadioChannelsInUse(INT radioIndex, CHAR *output_string)	//RDKB
+{
+	wifi_band band;
+	ULONG pri_ch = 0;
+	UCHAR bw = 0xff;
+	UCHAR ext_ch = EXT_NONE;
+	UCHAR sub_ch_list[16] = {0};
+	UCHAR sub_ch_num = 0;
+	struct hal_ch_layout *layout = NULL;
+	UCHAR layout_size = 0;
+	UCHAR sub_ch = 0;
+	UCHAR count = 0;
+	int res;
+
+	if (output_string == NULL) {
+		wifi_debug(DEBUG_ERROR, "output_string is NULL, return\n");
+		return RETURN_ERR;
+	}
 
 	band = wifi_index_to_band(radioIndex);
-	if (band == band_2_4 && bandwidth == 40) {
-		res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
-		if (os_snprintf_error(sizeof(config_file), res)) {
-			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
-			return RETURN_ERR;
+	if (band == band_invalid) {
+		wifi_debug(DEBUG_ERROR, "invalid band, return\n");
+		return RETURN_ERR;
+	}
+
+	/*get pri_ch*/
+	if (wifi_getRadioChannel(radioIndex, &pri_ch) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "Fail to get primary ch, return\n");
+		return RETURN_ERR;
+	}
+
+	if (pri_ch == 0) {
+		wifi_debug(DEBUG_ERROR, "invalid primary ch, return\n");
+		return RETURN_ERR;
+	}
+
+	/*get bw*/
+	if (mtk_wifi_get_radio_info(radioIndex, MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_BANDWIDTH,
+		get_bandwidth_handler, &bw)!= RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "Fail to get bw, return\n");
+		return RETURN_ERR;
+	}
+
+	if (bw == 0xff) {
+		wifi_debug(DEBUG_ERROR, "invalid bw, return\n");
+		return RETURN_ERR;
+	}
+
+	ext_ch = wifi_getExtCh_netlink(radioIndex);
+
+	/*2G 40M ext_ch sainity check, if check fail, only return primary ch*/
+	if (band == band_2_4 && bw == BAND_WIDTH_40) {
+		if (((ext_ch == EXT_ABOVE) && ((pri_ch + 4) > 14))
+			|| ((ext_ch == EXT_BELOW) && ((pri_ch - 4) < 1))) {
+			wifi_debug(DEBUG_ERROR, "EXTCHA channels out of range\n");
+			bw = BAND_WIDTH_20;
+		} else if (ext_ch == EXT_NONE) {
+			wifi_debug(DEBUG_ERROR, "EXTCHA is NONE for 40M\n");
+			bw = BAND_WIDTH_20;
 		}
-		memset(buf, 0, sizeof(buf));
-		wifi_halgetRadioExtChannel(config_file, buf);	   // read ht_capab for HT40+ or -
+	}
 
-		if (strncmp(buf, "AboveControlChannel", strlen("AboveControlChannel")) == 0 && channel < 10) {
-			res = snprintf(output_string, 256, "%d,%d", channel, channel+4);
-		} else if (strncmp(buf, "BelowControlChannel", strlen("BelowControlChannel")) == 0 && channel > 4) {
-			res = snprintf(output_string, 256, "%d,%d", channel-4, channel);
-		} else {
-			if (fprintf(stderr, "%s: invalid channel %d set with %s\n.", __func__, channel, buf) < 0)
-				wifi_debug(DEBUG_ERROR, "Unexpected fprintf fail\n");
-			return RETURN_ERR;
+	/*20M case, only return primary ch*/
+	if (bw == BAND_WIDTH_20) {
+		sub_ch_list[0] = pri_ch;
+		sub_ch_num = 1;
+		goto output;
+	}
+
+	/*2G/40M case, return all sub channels*/
+	if ((band == band_2_4) && (bw == BAND_WIDTH_40)) {
+		if (ext_ch == EXT_ABOVE) {
+			for (count = 0, sub_ch = pri_ch; (sub_ch <= 14) && (sub_ch <= pri_ch + 4); count++, sub_ch++)
+				sub_ch_list[count] = sub_ch;
+			sub_ch_num = count;
+		} else if (ext_ch == EXT_BELOW) {
+				for (count = 0, sub_ch = pri_ch - 4; (sub_ch > 0) && (sub_ch <= pri_ch); count++, sub_ch++)
+					sub_ch_list[count] = sub_ch;
+				sub_ch_num = count;
 		}
+		goto output;
+	}
 
-		if (os_snprintf_error(256, res)) {
-			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
-			return RETURN_ERR;
+	/*for 5G/6G, need find layout*/
+	if ((band == band_5) || (band == band_6)) {
+		UCHAR index;
+		UCHAR i;
+		UCHAR ch_find = FALSE;
+
+		layout = hal_get_ch_array(bw, band, &layout_size);
+		/*can not find, only return primary ch*/
+		if (layout == NULL) {
+			sub_ch_list[0] = pri_ch;
+			sub_ch_num = 1;
+			goto output;
 		}
-	} else if (band == band_5 || band == band_6){
-		// to minus 20 is an offset, because frequence of a channel have a range. We need to use offset to calculate correct channel.
-		// example: bandwidth 80: center is 42 (5210), channels are "36,40,44,48" (5170-5250). The delta should be 6.
-		channel_delta = (bandwidth-20)/10;
-		memset(output_string, 0, 256);
-		for (int i = center_channel-channel_delta; i <= center_channel+channel_delta; i+=4) {
-			// If i is not the last channel, we add a comma.
-			res = snprintf(buf, sizeof(buf), "%d%s", i, i==center_channel+channel_delta?"":",");
 
-			if (os_snprintf_error(sizeof(buf), res)) {
-				wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
-				return RETURN_ERR;
+		/*find the layout[index] which contains the channels in use*/
+		/*need consider 320M EXT here*/
+		for (i = 0; i < layout_size; i++) {
+			if (bw == BAND_WIDTH_320) {
+				if ((pri_ch >= layout[i].ch_low_bnd) && (pri_ch <= layout[i].ch_up_bnd)
+					&& (ext_ch == EXT_ABOVE) && (pri_ch < layout[i].cent_freq_idx)) {
+					ch_find = TRUE;
+					index = i;
+					break;
+				} else if ((pri_ch >= layout[i].ch_low_bnd) && (pri_ch <= layout[i].ch_up_bnd)
+					&& (ext_ch == EXT_BELOW) && (pri_ch > layout[i].cent_freq_idx)) {
+					ch_find = TRUE;
+					index = i;
+					break;
+				}
+			} else {
+				if ((pri_ch >= layout[i].ch_low_bnd) && (pri_ch <= layout[i].ch_up_bnd)) {
+					ch_find = TRUE;
+					index = i;
+					break;
+				}
 			}
-			strncat(output_string, buf, sizeof(output_string) - strlen(output_string) - 1);
 		}
-	} else
-		return RETURN_ERR;
 
-	WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n", __func__, __LINE__);
+		/*fill in sub_ch_list from layout[index]*/
+		if (ch_find) {
+			UCHAR start_ch = layout[index].ch_low_bnd;
+			UCHAR end_ch = layout[index].ch_up_bnd;
+			for (count = 0, sub_ch = start_ch; sub_ch <= end_ch; count++, sub_ch = sub_ch + 4)
+				sub_ch_list[count] = sub_ch;
+			sub_ch_num = count;
+		} else
+			wifi_debug(DEBUG_ERROR, "find layout[index] fail\n");
+	}
+
+output:
+	for (count = 0; (count < sub_ch_num) && (sub_ch_num < 16); count++) {
+		if (count == (sub_ch_num - 1))
+			res = snprintf(output_string + strlen(output_string), 256 - strlen(output_string), "%d", sub_ch_list[count]);
+		else
+			res = snprintf(output_string + strlen(output_string), 256 - strlen(output_string), "%d,", sub_ch_list[count]);
+		if (os_snprintf_error(256, res)) {
+			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
+			return RETURN_ERR;
+		}
+	}
+
 	return RETURN_OK;
 }
 
@@ -5132,7 +5554,7 @@
 	struct params list[2];
 	char str_idx[16];
 	char config_file[64];
-	int max_num_radios = 0, res;
+	int res, bss_idx, vap_idx;
 	wifi_band band = band_invalid;
 
 	band = wifi_index_to_band(radioIndex);
@@ -5150,13 +5572,13 @@
 	list[1].name = "he_oper_centr_freq_seg0_idx";
 	list[1].value = str_idx;
 
-	wifi_getMaxRadioNumber(&max_num_radios);
-	if(max_num_radios== 0){
-		return RETURN_ERR;
-	}
-	for(int i=0; i<=MAX_APS/max_num_radios; i++)
+	for (bss_idx = 0; bss_idx < LOGAN_MAX_NUM_VAP_PER_RADIO; bss_idx++)
 	{
-		res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex+(max_num_radios*i));
+		if (array_index_to_vap_index(radioIndex, bss_idx, &vap_idx) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid radioIndex[%d], bss_idx[%d]\n", radioIndex, bss_idx);
+			return RETURN_ERR;
+		}
+		res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, vap_idx);
 		if (os_snprintf_error(sizeof(config_file), res)) {
 			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
 			return RETURN_ERR;
@@ -5280,7 +5702,7 @@
 
 	memset(ret_buf, 0, sizeof(ret_buf));
 
-	vap_index_to_array_index(apIndex, &radio_idx, &bss_idx);
+	vap_index_to_radio_array_index(apIndex, &radio_idx, &bss_idx);
 
 	/*prepare new config file*/
 
@@ -5703,12 +6125,18 @@
 	struct nlattr * msg_data = NULL;
 	struct mtk_nl80211_param param;
 	unsigned long checktime = 0;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 	if (NULL == output_ulong)
 		return RETURN_ERR;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	if_idx = if_nametoindex(interface_name);
@@ -5765,11 +6193,17 @@
 	struct nl_msg *msg  = NULL;
 	struct nlattr * msg_data = NULL;
 	struct mtk_nl80211_param param;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
 		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
+		return RETURN_ERR;
 
 	if_idx = if_nametoindex(interface_name);
 	if (!if_idx) {
@@ -5840,15 +6274,6 @@
 	return 0;
 }
 
-enum bw_idx {
-	BAND_WIDTH_20,
-	BAND_WIDTH_40,
-	BAND_WIDTH_80,
-	BAND_WIDTH_160,
-	BAND_WIDTH_8080 = 6,
-	BAND_WIDTH_320
-};
-
 int bwidx_to_string(unsigned char bw, char *buf)
 {
 	int res;
@@ -5902,15 +6327,119 @@
 
 	return 0;
 }
+
+/*Calculate radio bw from ht_bw, vht_bw and eht bw*/
+UCHAR calculate_radio_bw(UCHAR ht_bw, UCHAR vht_bw, UCHAR eht_bw) {
+	UCHAR bw = BAND_WIDTH_20;
+
+	if (ht_bw == HT_BW_20)
+		return bw;
+
+	if (ht_bw == HT_BW_40) {
+		if (vht_bw == VHT_BW_2040)
+			bw = BAND_WIDTH_40;
+		else if (vht_bw == VHT_BW_80)
+			bw = BAND_WIDTH_80;
+		else if (vht_bw == VHT_BW_160) {
+			if (eht_bw == EHT_BW_320)
+				bw = BAND_WIDTH_320;
+			else
+				bw = BAND_WIDTH_160;
+		} else if (vht_bw == VHT_BW_8080)
+			bw = BAND_WIDTH_8080;
+	}
+
+	return bw;
+}
+//Get the Configured Bandwidth. eg "20MHz", "40MHz", "80MHz", "80+80", "160"
+//The output_string is a max length 64 octet string that is allocated by the RDKB code.  Implementations must ensure that strings are not longer than this.
+INT wifi_getRadioConfiguredChannelBandwidth(INT radioIndex, CHAR *output_string)
+{
+	char config_file[128] = {0};
+	wifi_band band = band_invalid;
+	char ht_bw_str[16] = {0};
+	char vht_bw_str[16] = {0};
+	char eht_bw_str[16] = {0};
+	UCHAR ht_bw;
+	UCHAR vht_bw;
+	UCHAR eht_bw;
+	UCHAR bw;
+	char buf[32] = {0};
+	int res;
+	int ret;
+
+	if (output_string == NULL) {
+		wifi_debug(DEBUG_ERROR, "output_string is NULL\n");
+		return RETURN_ERR;
+	}
+
+	band = wifi_index_to_band(radioIndex);
+	res = snprintf(config_file, sizeof(config_file), "%s%d.dat", LOGAN_DAT_FILE, band);
+	if (os_snprintf_error(sizeof(config_file), res)) {
+		wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
+		return RETURN_ERR;
+	}
+
+	/*parse HT_BW*/
+	wifi_datfileRead(config_file, "HT_BW", ht_bw_str, sizeof(ht_bw_str));
+	if (strncmp(ht_bw_str, "1", 1) == 0)
+		ht_bw = HT_BW_40;
+	else
+		ht_bw = HT_BW_20;
+
+	/*parse VHT_BW*/
+	wifi_datfileRead(config_file, "VHT_BW", vht_bw_str, sizeof(vht_bw_str));
+	if (strncmp(vht_bw_str, "0", 1) == 0)
+		vht_bw = VHT_BW_2040;
+	else if (strncmp(vht_bw_str, "1", 1) == 0)
+		vht_bw = VHT_BW_80;
+	else if (strncmp(vht_bw_str, "2", 1) == 0)
+		vht_bw = VHT_BW_160;
+	else if (strncmp(vht_bw_str, "3", 1) == 0)
+		vht_bw = VHT_BW_8080;
+	else
+		vht_bw = VHT_BW_2040;
+
+	/*parse EHT_BW*/
+	wifi_datfileRead(config_file, "EHT_ApBw", eht_bw_str, sizeof(eht_bw_str));
+	if (strncmp(eht_bw_str, "0", 1) == 0)
+		eht_bw = EHT_BW_20;
+	else if (strncmp(eht_bw_str, "1", 1) == 0)
+		eht_bw = EHT_BW_40;
+	else if (strncmp(eht_bw_str, "2", 1) == 0)
+		eht_bw = EHT_BW_80;
+	else if (strncmp(eht_bw_str, "3", 1) == 0)
+		eht_bw = EHT_BW_160;
+	else if (strncmp(eht_bw_str, "4", 1) == 0)
+		eht_bw = EHT_BW_320;
+	else
+		eht_bw = EHT_BW_20;
+
+	bw = calculate_radio_bw(ht_bw, vht_bw, eht_bw);
+	ret = bwidx_to_string(bw, buf);
+	if (ret) {
+		wifi_debug(DEBUG_ERROR, "bwidx_to_string fails\n");
+		return RETURN_ERR;
+	}
+
+	res = snprintf(output_string, 64, "%sMHz", buf);
+	if (os_snprintf_error(64, res)) {
+		wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
+		return RETURN_ERR;
+	}
+
+	return RETURN_OK;
+}
 
 //Get the Operating Channel Bandwidth. eg "20MHz", "40MHz", "80MHz", "80+80", "160"
 //The output_string is a max length 64 octet string that is allocated by the RDKB code.  Implementations must ensure that strings are not longer than this.
 INT wifi_getRadioOperatingChannelBandwidth(INT radioIndex, CHAR *output_string) //Tr181
 {
 	char buf[32] = {0};
-	int ret = 0, res;
+	int ret = 0, res, len = 0;
 	BOOL radio_enable = FALSE;
-	unsigned char bw;
+	//unsigned char bw;
+	char interface_name[64] = {0};
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
@@ -5926,15 +6455,18 @@
 		WIFI_ENTRY_EXIT_DEBUG("Radio %d is not enable failed %s: %d \n", radioIndex, __func__, __LINE__);
 		return RETURN_OK;
 	}
-	if (mtk_wifi_get_radio_info(radioIndex, MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_BANDWIDTH,
-		get_bandwidth_handler, &bw)!= RETURN_OK) {
-		wifi_debug(DEBUG_ERROR, "send MTK_NL80211_VENDOR_ATTR_GET_BAND_INFO_BANDWIDTH cmd fails\n");
+
+	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
 		return RETURN_ERR;
+
+	ret = _syscmd_secure(buf, sizeof(buf), "iw dev %s info | grep 'width' | cut -d  ' ' -f6 | tr -d '\\n'", interface_name);
+	if(ret) {
+		wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
 	}
 
-	ret = bwidx_to_string(bw, buf);
-	if (ret) {
-		wifi_debug(DEBUG_ERROR, "bwidx_to_string fails\n");
+	len = strlen(buf);
+	if ((ret != 0) || (len == 0))  {
+		wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
 		return RETURN_ERR;
 	}
 
@@ -6045,6 +6577,7 @@
 	int centr_channel = 0;
 	UINT mode_map = 0;
 	int freq=0, res;
+	int main_vap_idx;
 
 	if (output_string == NULL)
 		return RETURN_ERR;
@@ -6056,10 +6589,16 @@
 	band = wifi_index_to_band(radioIndex);
 	if (band == band_invalid)
 		return RETURN_ERR;
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
 		return RETURN_ERR;
+	}
 
-	res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
+		return RETURN_ERR;
+
+	res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, main_vap_idx);
 	if (os_snprintf_error(sizeof(config_file), res)) {
 		wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
 		return RETURN_ERR;
@@ -6133,7 +6672,7 @@
 	char ext_channel[64] = {0};
 	unsigned char ext_ch;
 	char buf[128] = {0};
-	int max_radio_num =0, ret = 0;
+	int ret = 0, bss_idx, vap_idx;
 	long int bandwidth = 0;
 	unsigned long channel = 0;
 	bool stbcEnable = FALSE;
@@ -6204,18 +6743,17 @@
 	}
 	wifi_datfileWrite(config_dat_file, &params, 1);
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num== 0){
-		return RETURN_ERR;
-	}
-	for(int i=0; i<=MAX_APS/max_radio_num; i++)
-	{
-		res = snprintf(config_file, sizeof(config_file), "%s%d.conf",CONFIG_PREFIX,radioIndex+(max_radio_num*i));
+	for (bss_idx = 0; bss_idx < LOGAN_MAX_NUM_VAP_PER_RADIO; bss_idx++) {
+		if (array_index_to_vap_index(radioIndex, bss_idx, &vap_idx) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid radioIndex[%d], bss_idx[%d]\n", radioIndex, bss_idx);
+			return RETURN_ERR;
+		}
+		res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, vap_idx);
 		if (os_snprintf_error(sizeof(config_file), res)) {
 			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
 			return RETURN_ERR;
 		}
-		wifi_setRadioSTBCEnable(radioIndex+(max_radio_num*i), stbcEnable);
+		wifi_setRadioSTBCEnable(vap_idx, stbcEnable);
 	}
 
 	/*do ext_ch quicking setting*/
@@ -6441,17 +6979,22 @@
 INT wifi_getRadioTransmitPower(INT radioIndex, ULONG *output_ulong)	//RDKB
 {
 	char interface_name[16] = {0};
-
 	char buf[16]={0};
 	char pwr_file[128]={0};
 	int res;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
 	if(output_ulong == NULL)
 		return RETURN_ERR;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 	res = snprintf(pwr_file, sizeof(pwr_file), "%s%d.txt", POWER_PERCENTAGE, radio_index_to_band(radioIndex));
 	if (os_snprintf_error(sizeof(pwr_file), res)) {
@@ -6490,10 +7033,16 @@
 	struct mtk_nl80211_param param;
 	struct unl unl_ins;
 	int res;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 	// Get the Tx power supported list and check that is the input in the list
 	res = snprintf(txpower_str, sizeof(txpower_str), "%lu", TransmitPower);
@@ -6679,15 +7228,20 @@
 INT wifi_getRadioBeaconPeriod(INT radioIndex, UINT *output)
 {
 	char interface_name[16] = {0};
-
 	char buf[MAX_CMD_SIZE]={'\0'};
 	int res;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 	if(output == NULL)
 		return RETURN_ERR;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i %s status | grep beacon_int | cut -d '=' -f2 | tr -d '\n'", interface_name);
@@ -7071,15 +7625,21 @@
 	CHAR interface_name[64] = {0};
 	BOOL iface_status = FALSE;
 	wifi_radioTrafficStats2_t radioTrafficStats = {0};
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n", __func__, __LINE__);
 	if (NULL == output_struct)
 		return RETURN_ERR;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
 		return RETURN_ERR;
+	}
 
-	wifi_getApEnable(radioIndex, &iface_status);
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
+		return RETURN_ERR;
+
+	wifi_getApEnable(main_vap_idx, &iface_status);
 
 	if (iface_status == TRUE)
 		wifi_halGetIfStats(interface_name, &radioTrafficStats);
@@ -7125,8 +7685,14 @@
 	struct nl_msg *msg	= NULL;
 	struct nlattr * msg_data = NULL;
 	struct mtk_nl80211_param param;
+	int main_vap_idx;
 
-	if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, inf_name) != RETURN_OK)
 		return RETURN_ERR;
 	if_idx = if_nametoindex(inf_name);
 	if (!if_idx) {
@@ -7177,8 +7743,14 @@
 	struct nl_msg *msg	= NULL;
 	struct nlattr * msg_data = NULL;
 	struct mtk_nl80211_param param;
+	int main_vap_idx;
 
-	if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, inf_name) != RETURN_OK)
 		return RETURN_ERR;
 	if_idx = if_nametoindex(inf_name);
 	if (!if_idx) {
@@ -7238,14 +7810,16 @@
 //Get the radio index assocated with this SSID entry
 INT wifi_getSSIDRadioIndex(INT ssidIndex, INT *radioIndex)
 {
+	int bss_idx;
+
 	if(NULL == radioIndex)
 		return RETURN_ERR;
-	int max_radio_num = 0;
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
+
+	if (vap_index_to_radio_array_index(ssidIndex, radioIndex, &bss_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid ssidIndex[%d]\n", ssidIndex);
 		return RETURN_ERR;
 	}
-	*radioIndex = ssidIndex%max_radio_num;
+
 	return RETURN_OK;
 }
 
@@ -7302,7 +7876,7 @@
 		wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
 		return RETURN_ERR;
 	}
-	wifi_hostapdRead(config_file,"ssid",output,32);
+	wifi_hostapdRead(config_file,"ssid",output, MAX_SSID_NAME_LEN);
 
 	wifi_dbg_printf("\n[%s]: SSID Name is : %s",__func__,output);
 	return RETURN_OK;
@@ -7316,7 +7890,7 @@
 	int res;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
-	if(NULL == ssid_string || strlen(ssid_string) >= 32 || strlen(ssid_string) == 0 )
+	if(NULL == ssid_string || strlen(ssid_string) > 32 || strlen(ssid_string) == 0 )
 		return RETURN_ERR;
 
 	params.name = "ssid";
@@ -7387,16 +7961,9 @@
 	BOOL status = false;
 	char buf[MAX_CMD_SIZE] = {0};
 	int apIndex, ret;
-	int max_radio_num = 0;
-	int radioIndex = 0;
+	int radioIndex = 0, bss_idx;
 	int res;
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
-		return RETURN_ERR;
-	}
-	radioIndex = ssidIndex % max_radio_num;
-
 	wifi_getApEnable(ssidIndex,&status);
 	// Do not apply when ssid index is disabled
 	if (status == false)
@@ -7415,8 +7982,16 @@
 	 * when first created interface will be removed
 	 * then all vaps other vaps on same phy are removed
 	 * after calling setApEnable to false readd all enabled vaps */
-	for(int i=0; i < MAX_APS/max_radio_num; i++) {
-		apIndex = max_radio_num*i+radioIndex;
+	if (vap_index_to_radio_array_index(ssidIndex, &radioIndex, &bss_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid ssidIndex[%d]\n", ssidIndex);
+		return RETURN_ERR;
+	}
+
+	for (bss_idx=0; bss_idx < LOGAN_MAX_NUM_VAP_PER_RADIO; bss_idx++) {
+		if (array_index_to_vap_index(radioIndex, bss_idx, &apIndex) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid radioIndex[%d] bss_idx[%d]\n", radioIndex, bss_idx);
+			continue;
+		}
 		if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK)
 			return RETURN_ERR;
 
@@ -7444,8 +8019,14 @@
 	char cmd[128] = {0};
 	char line[256] = {0};
 	int tmp = 0, arr_index = -1, res;
+	int main_vap_idx;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	res = snprintf(cmd, sizeof(cmd), "iw dev %s survey dump | grep 'frequency\\|noise' | awk '{print $2}'", interface_name);
@@ -7500,13 +8081,19 @@
 	int phyId = 0, res;
 	unsigned long len, tmp;
 	unsigned int DTIM_count;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s: %d\n", __func__, __LINE__);
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
-	res = snprintf(file_name, sizeof(file_name), "%s%d.txt", ESSID_FILE, radioIndex);
+	res = snprintf(file_name, sizeof(file_name), "%s%d.txt", ESSID_FILE, main_vap_idx);
 	if (os_snprintf_error(sizeof(file_name), res)) {
 		wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
 		return RETURN_ERR;
@@ -8437,8 +9024,14 @@
 	struct nl_msg *msg	= NULL;
 	struct nlattr * msg_data = NULL;
 	struct mtk_nl80211_param param;
+	int main_vap_idx;
 
-	if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, inf_name) != RETURN_OK)
 		return RETURN_ERR;
 	if_idx = if_nametoindex(inf_name);
 	/*init mtk nl80211 vendor cmd*/
@@ -8484,8 +9077,14 @@
 	struct nlattr * msg_data = NULL;
 	struct mtk_nl80211_param param;
 	int ret = -1;
+	int main_vap_idx;
+
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
 
-	if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
+	if (wifi_GetInterfaceName(main_vap_idx, inf_name) != RETURN_OK)
 		return RETURN_ERR;
 	if_idx = if_nametoindex(inf_name);
 	/*init mtk nl80211 vendor cmd*/
@@ -9122,13 +9721,20 @@
 	struct nlattr * msg_data = NULL;
 	struct mtk_nl80211_param param;
 	struct unl unl_ins;
+	int main_vap_idx;
 
 	if (radioIndex > MAX_APS) {
 		wifi_debug(DEBUG_ERROR, "Invalid apIndex %d\n", radioIndex);
 		return RETURN_ERR;
 	}
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	if_idx = if_nametoindex(interface_name);
@@ -9342,7 +9948,7 @@
 		return RETURN_ERR;
 
 	if (wifi_GetInterfaceName(apIndex, interface_name) != RETURN_OK) {
-		vap_index_to_array_index(apIndex, &radio_idx, &bss_idx);
+		vap_index_to_radio_array_index(apIndex, &radio_idx, &bss_idx);
 
 		res = snprintf(output_string, IF_NAME_SIZE, "%s%d", ext_prefix[radio_idx], bss_idx);	// For wifiagent generating data model.
 	} else
@@ -9360,7 +9966,7 @@
 INT wifi_getIndexFromName(CHAR *inputSsidString, INT *output_int)
 {
 	char buf[32] = {0};
-	char ap_idx = 0;
+	int ap_idx = 0;
 	char *apIndex_str = NULL;
 	char radio_idx = 0;
 	char bss_idx = 0;
@@ -9402,7 +10008,10 @@
 		return RETURN_ERR;
 	}
 
-	ap_idx = array_index_to_vap_index(radio_idx, bss_idx);
+	if(array_index_to_vap_index(radio_idx, bss_idx, &ap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_idx %d, bss_idx %d\n", radio_idx, bss_idx);
+		return RETURN_ERR;
+	}
 
 	if (ap_idx >= 0 && ap_idx < MAX_APS) {
 		printf("%s: hostapd conf not find, inf(%s), use inf idx(%d).\n",
@@ -9921,16 +10530,17 @@
 // outputs the radio index for the specified ap. similar as wifi_getSsidRadioIndex
 INT wifi_getApRadioIndex(INT apIndex, INT *output_int)
 {
-	int max_radio_num = 0;
+	int radioIndex, bss_idx;
 
 	if(NULL == output_int)
 		return RETURN_ERR;
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
+	if (vap_index_to_radio_array_index(apIndex, &radioIndex, &bss_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid apIndex[%d]\n", apIndex);
 		return RETURN_ERR;
 	}
-	*output_int = apIndex % max_radio_num;
+
+	*output_int = radioIndex;
 
 	return RETURN_OK;
 }
@@ -10908,13 +11518,12 @@
 
 	char buf[MAX_BUF_SIZE] = {0};
 	BOOL status = FALSE;
-	int  max_radio_num = 0;
+	int radioIndex, bss_idx;
 	int phyId = 0;
 	int res;
 
 	wifi_getApEnable(apIndex, &status);
 
-	wifi_getMaxRadioNumber(&max_radio_num);
 	if (enable == status)
 		return RETURN_OK;
 
@@ -10922,7 +11531,10 @@
 		return RETURN_ERR;
 
 	if (enable == TRUE) {
-		int radioIndex = apIndex % max_radio_num;
+		if (vap_index_to_radio_array_index(apIndex, &radioIndex, &bss_idx) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid apIndex[%d]\n", apIndex);
+			return RETURN_ERR;
+		}
 		phyId = radio_index_to_phy(radioIndex);
 
 		res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s up", interface_name);
@@ -10940,13 +11552,16 @@
 			wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
 		}
 	} else {
-		res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw REMOVE %s", interface_name);
-	        if (res) {
-			wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
-		}
-		res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s down", interface_name);
-	        if (res) {
-			wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
+		if (apIndex >= RUNTIME_MAX_RADIO) {
+			res = _syscmd_secure(buf, sizeof(buf), "hostapd_cli -i global raw REMOVE %s", interface_name);
+		    if (res) {
+				wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
+			}
+		} else {
+			res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s down", interface_name);
+		    if (res) {
+				wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
+			}
 		}
 	}
 	res = _syscmd_secure(buf, sizeof(buf), "sed -i -n -e '/^%s=/!p' -e '$a%s=%d' %s",
@@ -10966,6 +11581,7 @@
 	int res, len;
 	char ctrl_interface[64] = {0};
 	char config_file[128] = {0};
+	BOOL is_ap_enable, hostapd_state;
 
 	if ((!output_bool) || (apIndex < 0) || (apIndex >= MAX_APS))
 		return RETURN_ERR;
@@ -11003,10 +11619,15 @@
 			wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
 		}
 
-		if(strncmp(buf, "ENABLED", 7) == 0 || strncmp(buf, "ACS", 3) == 0 ||
-			strncmp(buf, "HT_SCAN", 7) == 0 || strncmp(buf, "DFS", 3) == 0) {
-			*output_bool = TRUE;
+		if (strncmp(buf, "ENABLED", 7) == 0 || strncmp(buf, "ACS", 3) == 0 ||
+			strncmp(buf, "HT_SCAN", 7) == 0 || strncmp(buf, "DFS", 3) == 0)  {
+			hostapd_state = TRUE;
 		}
+
+		is_ap_enable = _syscmd_secure(buf, sizeof(buf), "ifconfig %s | grep UP", interface_name) ? FALSE : TRUE;
+
+		if (hostapd_state && is_ap_enable)
+			*output_bool = TRUE;
 	}
 
 	return RETURN_OK;
@@ -11199,17 +11820,16 @@
 {
 	//get the running status from driver
 	char buf[128] = {0};
-	int max_radio_num = 0, radioIndex = 0;
+	int radioIndex = 0, bss_idx;
 	int phyId = 0;
 	int res;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
+	if (vap_index_to_radio_array_index(apIndex, &radioIndex, &bss_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid apIndex[%d]\n", apIndex);
 		return RETURN_ERR;
 	}
-	radioIndex = apIndex % max_radio_num;
 	phyId = radio_index_to_phy(radioIndex);
 
 	res = _syscmd_secure(buf, sizeof(buf), "iw phy phy%d info | grep u-APSD", phyId);
@@ -13606,8 +14226,14 @@
 	char interface_name[16] = {0};
 	char buf[1024];
 	int res;
+	int main_vap_idx;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 	res = _syscmd_secure(buf, sizeof(buf), "iwconfig %s freq %d",interface_name,channel);
 	if (res) {
@@ -14349,6 +14975,7 @@
 	int center_chan = 0;
 	int center_freq1 = 0;
 	int res;
+	int main_vap_idx;
 
 	res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex);
 	if (os_snprintf_error(sizeof(config_file), res)) {
@@ -14356,12 +14983,17 @@
 		return RETURN_ERR;
 	}
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
-	band = wifi_index_to_band(radioIndex);
+	band = wifi_index_to_band(main_vap_idx);
 
 	width = channel_width_MHz > 20 ? channel_width_MHz : 20;
 
@@ -14484,6 +15116,7 @@
 	int res;
 	unsigned long len;
 	struct channels_noise *channels_noise_arr = NULL;
+	int main_vap_idx;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s: %d\n", __func__, __LINE__);
 
@@ -14509,7 +15142,12 @@
 		}
 	}
 
+	if (array_index_to_vap_index(radio_index, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radio_index);
+		return RETURN_ERR;
+	}
+
-	if (wifi_GetInterfaceName(radio_index, interface_name) != RETURN_OK)
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	phyId = radio_index_to_phy(radio_index);
@@ -15589,14 +16227,12 @@
 {
 	char file_name[128] = {0};
 	FILE *f = NULL;
-	int max_num_radios = 0;
 	int res, ret;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
-	wifi_getMaxRadioNumber(&max_num_radios);
 	if (essid == NULL || strlen(essid) == 0 || apIndex == -1) {
-		for (int index = 0; index < max_num_radios; index++) {
+		for (int index = 0; index < RUNTIME_MAX_RADIO; index++) {
 			res = snprintf(file_name, sizeof(file_name), "%s%d.txt", ESSID_FILE, index);
 			if (os_snprintf_error(sizeof(file_name), res)) {
 				wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
@@ -15725,8 +16361,14 @@
 	char  if_name[IF_NAME_SIZE];
 	char interface_name[IF_NAME_SIZE] = {0};
 	int res;
+	int main_vap_idx;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	res = snprintf(if_name, sizeof(if_name), "%s", interface_name);
@@ -15985,7 +16627,14 @@
 {
 	Netlink nl;
 	char if_name[32];
-	if (wifi_GetInterfaceName(radioIndex, if_name) != RETURN_OK)
+	int main_vap_idx;
+
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, if_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	*output_array_size = sizeof(wifi_associated_dev_rate_info_rx_stats_t);
@@ -16129,8 +16778,14 @@
 	char if_name[IF_NAME_SIZE];
 	char interface_name[IF_NAME_SIZE] = {0};
 	int res;
+	int main_vap_idx;
 
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	*output_array_size = sizeof(wifi_associated_dev_rate_info_tx_stats_t);
@@ -16345,6 +17000,7 @@
 	char cmd[MAX_CMD_SIZE] = {'\0'};
 	char interface_name[16] = {0};
 	int res;
+	int main_vap_idx;
 
 	ieee80211_channel_to_frequency(channel, &freqMHz);
 	if (freqMHz == -1) {
@@ -16352,7 +17008,12 @@
 		return -1;
 	}
 
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK) {
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK) {
 		wifi_debug(DEBUG_ERROR, "wifi_GetInterfaceName fail\n");
 	}
 	res = snprintf(cmd, sizeof(cmd), "iw dev %s survey dump | grep -A5 %d | tr -d '\\t'", interface_name, freqMHz);
@@ -16425,10 +17086,16 @@
 	Netlink nl;
 	wifi_channelStats_t_loc local[array_size];
 	char  if_name[32];
+	int main_vap_idx;
 
 	local[0].array_size = array_size;
 
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
-	if (wifi_GetInterfaceName(radioIndex, if_name) != RETURN_OK)
+	if (wifi_GetInterfaceName(main_vap_idx, if_name) != RETURN_OK)
 		return RETURN_ERR;
 
 	nl.id = initSock80211(&nl);
@@ -16999,10 +17666,16 @@
 	struct mtk_nl80211_param param;
 	struct mtk_nl80211_cb_data cb_data;
 	wdev_ap_metric ap_metric;
+	int main_vap_idx;
 
 	/*init mtk nl80211 vendor cmd*/
 
-	if (wifi_GetInterfaceName(radioIndex, inf_name) != RETURN_OK)
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
+	if (wifi_GetInterfaceName(main_vap_idx, inf_name) != RETURN_OK)
 		return RETURN_ERR;
 	if_idx = if_nametoindex(inf_name);
 	if (!if_idx) {
@@ -17811,8 +18484,8 @@
 	char hex_bssid[13] = { 0 };
 	char bssid[18] = { 0 };
 	char nr[100] = { 0 };
-	char ssid[32];
-	char hex_ssid[32];
+	char ssid[MAX_SSID_NAME_LEN];
+	char hex_ssid[MAX_SSID_NAME_LEN];
 	char interface_name[16] = {0};
 	INT ret;
 	int res;
@@ -18016,7 +18689,7 @@
 	int index;
 	INT ret=0;
 	char buf[1024]="";
-
+	wifi_ParseProfile();
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 	if(argc<3)
 	{
@@ -18150,6 +18823,111 @@
 		else
 			printf("fail to get AP wps last connection status for ap_index=%d\n", index);
 	}
+
+#ifndef WIFI_7992
+	/*it is only suitable for eagle*/
+	if (strstr(argv[1], "mlo_test")) {
+		wifi_vap_info_map_t vap[3];
+		int i;
+		unsigned char mld_mac[6] = {0x00, 0x0c, 0x43, 0x11, 0x22, 0x33};
+		unsigned char mld_mac2[6] = {0x00, 0x0c, 0x43, 0x44, 0x55, 0x66};
+		radio_band[0] = band_2_4;
+		radio_band[1] = band_5;
+		radio_band[2] = band_6;
+
+		if (eht_mld_config_init() != RETURN_OK)
+			printf("eht_mld_config_init() fail!\n");
+
+		memset(vap, 0, sizeof(vap));
+		for (i = 0; i < 3; i++) {
+			if (wifi_getRadioVapInfoMap(i, &vap[i]) != RETURN_OK)
+				printf("wifi_getRadioVapInfoMap fail[%d]", i);
+		}
+
+		/*case 1-create mld[5], transfer ra0 mld[1]->mld[5]*/
+		vap[0].vap_array[0].u.bss_info.mld_info.common_info.mld_enable = 1;
+		vap[0].vap_array[0].u.bss_info.mld_info.common_info.mld_index = 5;	
+		memcpy(vap[0].vap_array[0].u.bss_info.mld_info.common_info.mld_addr, mld_mac, 6);
+
+		/*case 2-create mld[6], transfer ra1 mld[2]->mld[6]*/
+		vap[0].vap_array[1].u.bss_info.mld_info.common_info.mld_enable = 1;
+		vap[0].vap_array[1].u.bss_info.mld_info.common_info.mld_index = 6;	
+		memcpy(vap[0].vap_array[1].u.bss_info.mld_info.common_info.mld_addr, mld_mac2, 6);
+		if (wifi_createVAP(0, &vap[0]) != RETURN_OK)
+			printf("wifi_createVAP[0] fail\n");
+
+		/*case 3-rai0 keep in mld[1]*/
+		vap[1].vap_array[0].u.bss_info.mld_info.common_info.mld_enable = 1;
+		vap[1].vap_array[0].u.bss_info.mld_info.common_info.mld_index = 1;	
+		memcpy(vap[1].vap_array[0].u.bss_info.mld_info.common_info.mld_addr, mld_mac, 6);
+
+		/*case 4-rai1 leave mld[2]*/
+		vap[1].vap_array[1].u.bss_info.mld_info.common_info.mld_enable = 0;
+		vap[1].vap_array[1].u.bss_info.mld_info.common_info.mld_index = 2;	
+		memcpy(vap[1].vap_array[0].u.bss_info.mld_info.common_info.mld_addr, mld_mac2, 6);
+
+		if (wifi_createVAP(1, &vap[1]) != RETURN_OK)
+			printf("wifi_createVAP[0] fail\n");
+
+		/*case 5-rax1 leave mld[2]->null*/
+		vap[2].vap_array[1].u.bss_info.mld_info.common_info.mld_enable = 0;
+		vap[2].vap_array[1].u.bss_info.mld_info.common_info.mld_index = 2;	
+		memcpy(vap[1].vap_array[0].u.bss_info.mld_info.common_info.mld_addr, mld_mac2, 6);
+
+		if (wifi_createVAP(2, &vap[2]) != RETURN_OK)
+			printf("wifi_createVAP[0] fail\n");
+
+		/*case 6-rax1 null->join mld[7]*/
+		vap[2].vap_array[1].u.bss_info.mld_info.common_info.mld_enable = 1;
+		vap[2].vap_array[1].u.bss_info.mld_info.common_info.mld_index = 7;	
+		memcpy(vap[1].vap_array[0].u.bss_info.mld_info.common_info.mld_addr, mld_mac2, 6);
+
+		if (wifi_createVAP(2, &vap[2]) != RETURN_OK)
+			printf("wifi_createVAP[0] fail\n");
+
+		/*case 7-ra0 leve mld[5]->null, mld[5] destroy*/
+		vap[0].vap_array[0].u.bss_info.mld_info.common_info.mld_enable = 0;
+		vap[0].vap_array[0].u.bss_info.mld_info.common_info.mld_index = 5;	
+		memcpy(vap[0].vap_array[0].u.bss_info.mld_info.common_info.mld_addr, mld_mac, 6);
+		if (wifi_createVAP(0, &vap[0]) != RETURN_OK)
+			printf("wifi_createVAP[0] fail\n");
+
+		mld_info_display();
+	}
+
+	if (strstr(argv[1], "change_bridge_test")) {
+		wifi_vap_info_map_t vap[3];
+		int i;
+		radio_band[0] = band_2_4;
+		radio_band[1] = band_5;
+		radio_band[2] = band_6;
+
+		if (eht_mld_config_init() != RETURN_OK)
+			printf("eht_mld_config_init() fail!\n");
+
+		memset(vap, 0, sizeof(vap));
+		for (i = 0; i < 3; i++) {
+			if (wifi_getRadioVapInfoMap(i, &vap[i]) != RETURN_OK)
+				printf("wifi_getRadioVapInfoMap fail[%d]", i);
+		}
+
+		/*case 1-change bridge name of ra0*/
+		strncpy(vap[0].vap_array[0].bridge_name, "brlan1", sizeof(vap[0].vap_array[0].bridge_name));
+		if (wifi_createVAP(0, &vap[0]) != RETURN_OK)
+			printf("wifi_createVAP[0] fail\n");
+
+		/*case 2-change bridge name of rai1*/
+		strncpy(vap[1].vap_array[1].bridge_name, "brlan2", sizeof(vap[1].vap_array[1].bridge_name));
+		if (wifi_createVAP(1, &vap[1]) != RETURN_OK)
+			printf("wifi_createVAP[1] fail\n");
+
+		/*case 2-change bridge name of rax0*/
+		strncpy(vap[2].vap_array[0].bridge_name, "brlan3", sizeof(vap[2].vap_array[2].bridge_name));
+		if (wifi_createVAP(2, &vap[2]) != RETURN_OK)
+			printf("wifi_createVAP[2] fail\n");
+	}
+#endif
+
 	if(strstr(argv[1], "wifi_getApAssociatedDeviceDiagnosticResult3")!=NULL)
 	{
 		wifi_associated_dev3_t *associated_dev_array = NULL, *dev3;
@@ -18164,7 +18942,7 @@
 			dev3 = (wifi_associated_dev3_t *)(associated_dev_array + i);
 			printf("mac(%02x:%02x:%02x:%02x:%02x:%02x:)\n", dev3->cli_MACAddress[0], dev3->cli_MACAddress[1],
 				dev3->cli_MACAddress[2], dev3->cli_MACAddress[3], dev3->cli_MACAddress[4], dev3->cli_MACAddress[5]);
-			printf("\t tx_rate=%u, rx_rate=%u, snr=%u, rx_bytes=%lu, tx_bytes=%lu, rssi=%d, tx_pkts=%lu, rx_pkts=%lu\n"
+			printf("\t tx_rate=%u, rx_rate=%u, snr=%u, rx_bytes=%lu, tx_bytes=%lu, rssi=%hhd, tx_pkts=%lu, rx_pkts=%lu\n"
 				"mlo_enable=%u\n", dev3->cli_LastDataUplinkRate , dev3->cli_LastDataDownlinkRate,
 				dev3->cli_SNR, dev3->cli_BytesReceived, dev3->cli_BytesSent, dev3->cli_RSSI, dev3->cli_PacketsReceived,
 				dev3->cli_BytesSent, dev3->mld_enable);
@@ -18180,7 +18958,7 @@
 						dev3->mld_link_info[j].link_addr[1],
 						dev3->mld_link_info[j].link_addr[2], dev3->mld_link_info[j].link_addr[3], dev3->mld_link_info[j].link_addr[4],
 						dev3->mld_link_info[j].link_addr[5]);
-					printf("\trssi=%d, tx_rate=%lu, rx_rate=%lu, tx_bytes=%llu, rx_bytes=%llu\n",
+					printf("\trssi=%hhd, tx_rate=%lu, rx_rate=%lu, tx_bytes=%llu, rx_bytes=%llu\n",
 						dev3->mld_link_info[j].rssi, dev3->mld_link_info[j].tx_rate, dev3->mld_link_info[j].rx_rate,
 						dev3->mld_link_info[j].tx_bytes, dev3->mld_link_info[j].rx_bytes);
 				}
@@ -18881,9 +19659,33 @@
 		}
 		char buf[64]= {'\0'};
 		wifi_getRadioOperatingChannelBandwidth(index,buf);
-		printf("Current bandwidth is %s \n",buf);
+		printf("Current operating bandwidth is %s \n",buf);
+		return 0;
+	}
+	if(strstr(argv[1],"wifi_getRadioConfiguredChannelBandwidth") != NULL)
+	{
+		if (argc <= 2)
+		{
+			printf("Insufficient arguments\n");
+			exit(-1);
+		}
+		char buf[64]= {'\0'};
+		wifi_getRadioConfiguredChannelBandwidth(index, buf);
+		printf("Current config bandwidth is %s \n",buf);
 		return 0;
 	}
+	if(strstr(argv[1],"wifi_getRadioChannelsInUse") != NULL)
+	{
+		if (argc <= 2)
+		{
+			printf("Insufficient arguments\n");
+			exit(-1);
+		}
+		char buf[256]= {'\0'};
+		wifi_getRadioChannelsInUse(index, buf);
+		printf("RadioChannelsInUse is %s \n",buf);
+		return 0;
+	}
 	if(strstr(argv[1],"pushRadioChannel2")!=NULL)
 	{
 		if (argc <= 5)
@@ -19204,6 +20006,8 @@
 			bandwidth = 80;
 		else if (operationParam->channelWidth == WIFI_CHANNELBANDWIDTH_160MHZ || operationParam->channelWidth == WIFI_CHANNELBANDWIDTH_80_80MHZ)
 			bandwidth = 160;
+		else if (operationParam->channelWidth == WIFI_CHANNELBANDWIDTH_320MHZ)
+			bandwidth = 320;
 
 		if (operationParam->autoChannelEnabled) {
 			if (wifi_pushRadioChannel2(index, 0, bandwidth, operationParam->csa_beacon_count) != RETURN_OK) {
@@ -19244,7 +20048,10 @@
 	
 	if (current_param.dtimPeriod != operationParam->dtimPeriod) {
 		for (i = 0; i < bss_num; i++) {
-			ApIndex = array_index_to_vap_index(index, i);
+			if (array_index_to_vap_index(index, i, &ApIndex) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid index %d, i %d\n", index, i);
+				continue;
+			}
 			if (wifi_setApDTIMInterval(ApIndex, operationParam->dtimPeriod) != RETURN_OK) {
 				wifi_debug(DEBUG_ERROR, "wifi_setApDTIMInterval return error.\n");
 				goto err;
@@ -19254,7 +20061,11 @@
 	}
 	if (current_param.beaconInterval != operationParam->beaconInterval) {
 		for (i = 0; i < bss_num; i++) {
-			ApIndex = array_index_to_vap_index(index, i);
+			if (array_index_to_vap_index(index, i, &ApIndex) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid index %d, i %d\n", index, i);
+				continue;
+			}
+
 			if (wifi_setRadioBeaconPeriod(ApIndex, operationParam->beaconInterval) != RETURN_OK) {
 				wifi_debug(DEBUG_ERROR, "wifi_setRadioBeaconPeriod return error.\n");
 				goto err;
@@ -19265,7 +20076,10 @@
 	if (current_param.operationalDataTransmitRates != operationParam->operationalDataTransmitRates) {
 		BitMapToTransmitRates(operationParam->operationalDataTransmitRates, buf, sizeof(buf));
 		for (i = 0; i < bss_num; i++) {
-			ApIndex = array_index_to_vap_index(index, i);
+			if (array_index_to_vap_index(index, i, &ApIndex) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid index %d, i %d\n", index, i);
+				continue;
+			}
 			if (wifi_setRadioBasicDataTransmitRates(ApIndex, buf) != RETURN_OK) {
 				wifi_debug(DEBUG_ERROR, "wifi_setRadioBasicDataTransmitRates return error.\n");
 				goto err;
@@ -19275,7 +20089,10 @@
 	}
 	if (current_param.fragmentationThreshold != operationParam->fragmentationThreshold) {
 		for (i = 0; i < bss_num; i++) {
-			ApIndex = array_index_to_vap_index(index, i);
+			if (array_index_to_vap_index(index, i, &ApIndex) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid index %d, i %d\n", index, i);
+				continue;
+			}
 			if (wifi_setRadioFragmentationThreshold(ApIndex, operationParam->fragmentationThreshold) != RETURN_OK) {
 				wifi_debug(DEBUG_ERROR, "wifi_setRadioFragmentationThreshold return error.\n");
 				goto err;
@@ -19286,7 +20103,10 @@
 
 	if (current_param.rtsThreshold != operationParam->rtsThreshold) {
 		for (i = 0; i < bss_num; i++) {
-			ApIndex = array_index_to_vap_index(index, i);
+			if (array_index_to_vap_index(index, i, &ApIndex) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid index %d, i %d\n", index, i);
+				continue;
+			}
 			if (wifi_setApRtsThreshold(ApIndex, operationParam->rtsThreshold) != RETURN_OK) {
 				wifi_debug(DEBUG_ERROR, "wifi_setApRtsThreshold return error.\n");
 				goto err;
@@ -19346,11 +20166,17 @@
 	multiple_set = false;
 	if (drv_dat_change == TRUE) {
 		wifi_setRadioEnable(index, FALSE);
-		if (operationParam->enable == TRUE)
+		if (operationParam->enable == TRUE) {
 			wifi_setRadioEnable(index, TRUE);
+			eht_mld_config_init();
+			mld_info_display();
+		}
 	} else if (hapd_conf_change == TRUE) {
 		for (i = 0; i < bss_num; i++) {
-			ApIndex = array_index_to_vap_index(index, i);
+			if (array_index_to_vap_index(index, i, &ApIndex) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid index %d, i %d\n", index, i);
+				continue;
+			}
 			wifi_quick_reload_ap(ApIndex);
 		}
 	}
@@ -19443,6 +20269,7 @@
 	else if (!strcmp(buf, "40MHz")) operationParam->channelWidth = WIFI_CHANNELBANDWIDTH_40MHZ;
 	else if (!strcmp(buf, "80MHz")) operationParam->channelWidth = WIFI_CHANNELBANDWIDTH_80MHZ;
 	else if (!strcmp(buf, "160MHz")) operationParam->channelWidth = WIFI_CHANNELBANDWIDTH_160MHZ;
+	else if (!strcmp(buf, "320MHz")) operationParam->channelWidth = WIFI_CHANNELBANDWIDTH_320MHZ;
 	else
 	{
 		wifi_debug(DEBUG_ERROR, "Unknown channel bandwidth: %s\n", buf);
@@ -19466,6 +20293,9 @@
 		operationParam->variant |= WIFI_80211_VARIANT_AC;
 	if (mode & WIFI_MODE_AX)
 		operationParam->variant |= WIFI_80211_VARIANT_AX;
+	if (mode & WIFI_MODE_BE)
+		operationParam->variant |= WIFI_80211_VARIANT_BE;
+
 	if (wifi_getRadioDCSEnable(index, &operationParam->DCSEnabled) != RETURN_OK) {
 		wifi_debug(DEBUG_ERROR, "wifi_getRadioDCSEnable return error.\n");
 		return RETURN_ERR;
@@ -19570,34 +20400,40 @@
 	return RETURN_OK;
 }
 
-static int array_index_to_vap_index(UINT radioIndex, int arrayIndex)
+static int array_index_to_vap_index(UINT radioIndex, int arrayIndex, int *vap_index)
 {
-	int max_radio_num = 0;
-
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if (radioIndex >= max_radio_num) {
-		wifi_debug(DEBUG_ERROR, "Wrong radio index (%d)\n", radioIndex);
+	if (radioIndex > 2 || arrayIndex < 0 || arrayIndex >= LOGAN_MAX_NUM_VAP_PER_RADIO)
 		return RETURN_ERR;
-	}
 
-	return (arrayIndex * max_radio_num) + radioIndex;
-}
+	if (radioIndex < 2)
+		*vap_index = arrayIndex * 2 + radioIndex;
+	else if (radioIndex == 2)
+		*vap_index = (2 * LOGAN_MAX_NUM_VAP_PER_RADIO) + arrayIndex;
 
-static int vap_index_to_array_index(int vapIndex, int *radioIndex, int *arrayIndex)
-{
-	int max_radio_num = 0;
+	return RETURN_OK;
+}
 
-	if ((vapIndex < 0) || (vapIndex >  MAX_NUM_VAP_PER_RADIO*MAX_NUM_RADIOS))
-	return -1;
+/*
+ * 2.4G vap index: 0 2 4 6 8 10 12 14 ... (2*bss_idx)
+ * 5G vap index:   1 3 5 7 9 11 13 15 ... (2*bss_idx + 1)
+ * 6G vap index:   16 17 18 19 20 21 22 23 ... (2*LOGAN_MAX_NUM_VAP_PER_RADIO + bss_idx)
+ */
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
+//static int vap_index_to_array_index(int vapIndex, int *radioIndex, int *arrayIndex)
+static int vap_index_to_radio_array_index(int vapIndex, int *radioIndex, int *arrayIndex)
+{
+	if (vapIndex >= MAX_APS || vapIndex < 0)
 		return RETURN_ERR;
+
+	if (vapIndex >= 0 && vapIndex < (2 * LOGAN_MAX_NUM_VAP_PER_RADIO)) {
+		*radioIndex = vapIndex % 2;
+		*arrayIndex = vapIndex / 2;
+	} else if (vapIndex >= (2 * LOGAN_MAX_NUM_VAP_PER_RADIO) && vapIndex < (3 * LOGAN_MAX_NUM_VAP_PER_RADIO)) {
+		*radioIndex = 2;
+		*arrayIndex = vapIndex - (2 * LOGAN_MAX_NUM_VAP_PER_RADIO);
 	}
-	(*radioIndex) = vapIndex % max_radio_num;
-	(*arrayIndex) = vapIndex / max_radio_num;
 
-	return 0;
+	return RETURN_OK;
 }
 
 
@@ -19675,7 +20511,7 @@
 	int i = 0;
 	int vap_index = 0;
 	BOOL enabled = FALSE;
-	char buf[32] = {0};
+	char buf[MAX_SSID_NAME_LEN] = {0};
 	wifi_vap_security_t security = {0};
 	int res = RETURN_OK;
 	wifi_vap_info_t *vap;
@@ -19706,9 +20542,8 @@
 	{
 		map->vap_array[i].radio_index = index;
 
-		vap_index = array_index_to_vap_index(index, i);
-		if (vap_index < 0) {
-			res = RETURN_ERR;
+		if (array_index_to_vap_index(index, i, &vap_index) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid index %d, i %d\n", index, i);
 			continue;
 		}
 
@@ -19908,13 +20743,12 @@
 
 	char buf[MAX_BUF_SIZE] = {0};
 	BOOL status = FALSE;
-	int  max_radio_num = 0;
 	int phyId = 0;
+	int radioIndex, bss_idx;
 	int res;
 
 	wifi_getApEnable(apIndex, &status);
 
-	wifi_getMaxRadioNumber(&max_radio_num);
 	if (enable == status)
 		return RETURN_OK;
 
@@ -19922,7 +20756,10 @@
 		return RETURN_ERR;
 
 	if (enable == TRUE) {
-		int radioIndex = apIndex % max_radio_num;
+		if (vap_index_to_radio_array_index(apIndex, &radioIndex, &bss_idx) != RETURN_OK) {
+			wifi_debug(DEBUG_ERROR, "invalid apIndex[%d]\n", apIndex);
+			return RETURN_ERR;
+		}
 		phyId = radio_index_to_phy(radioIndex);
 		res = snprintf(config_file, MAX_BUF_SIZE, "%s%d.conf", CONFIG_PREFIX, apIndex);
 		if (os_snprintf_error(MAX_CMD_SIZE, res)) {
@@ -19979,6 +20816,47 @@
 	ret = hostapd_raw_add_bss(apIndex);
 	if(ret != RETURN_OK)
 		return RETURN_ERR;
+
+	return RETURN_OK;
+}
+
+static INT getVapBridge(int ap_index, char *bridge_name_buf, int buf_size)
+{
+	int res;
+	char config_file[128] = {0};
+
+	res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_index);
+	if (os_snprintf_error(sizeof(config_file), res)) {
+		wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
+		return RETURN_ERR;
+	}
+	if (wifi_hostapdRead(config_file, "bridge", bridge_name_buf, buf_size) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "get bridge fail from %s\n", config_file);
+		return RETURN_ERR;
+	}
+
+	return RETURN_OK;
+}
+
+static INT setVapBridge(int ap_index, char *bridge_name)
+{
+	int res;
+	char config_file[128] = {0};
+	struct params param = {.name = "bridge"};
+
+	res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_index);
+	if (os_snprintf_error(sizeof(config_file), res)) {
+		wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
+		return RETURN_ERR;
+	}
+	wifi_debug(DEBUG_ERROR, "set bridge to %s in %s\n", bridge_name, config_file);
+
+	param.name = "bridge";
+	param.value = bridge_name;
+	if (wifi_hostapdWrite(config_file, &param, 1) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "set bridge fail to %s\n", config_file);
+		return RETURN_ERR;
+	}
 
 	return RETURN_OK;
 }
@@ -19990,9 +20868,8 @@
 	int acl_mode;
 	int ret = 0;
 	char buf[256] = {0};
-	char cmd[128] = {0};
 	char config_file[64] = {0};
-	BOOL enable = FALSE;
+	BOOL apEnable;
 	int band_idx;
 	int res;
 	wifi_mld_common_info_t *mld_info;
@@ -20000,19 +20877,30 @@
 	unsigned char ap_index_array[MAX_APS] = {0};
 	unsigned char ap_array_num;
 	char interface_name[IF_NAME_SIZE] = {0};
+	char bridge_name[WIFI_BRIDGE_NAME_LEN] = {0};
+	unsigned char hostapd_if_restart;
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
-	printf("Entering %s index = %d\n", __func__, (int)index);
-	for (i = 0; i < map->num_vaps; i++)
-	{
+	printf("Entering %s index = %d, map->num_vaps = %d\n", __func__, (int)index, map->num_vaps);
+	for (i = 0; i < map->num_vaps; i++) {
+		hostapd_if_restart = 0;
 		multiple_set = TRUE;
-		
+
 		vap_info = &map->vap_array[i];
 
-		// Check vap status file to enable multiple ap if the system boot.
-		checkVapStatus(vap_info->vap_index, &enable);
-		if (vap_info->u.bss_info.enabled == FALSE && enable == FALSE)
+		if (vap_info->u.bss_info.enabled == FALSE) {
+			wifi_getApEnable(vap_info->vap_index, &apEnable);
+            if (apEnable) {
+				wifi_setApEnable(vap_info->vap_index, FALSE);
+            }
 			continue;
+		}
+
+		if (vap_info->u.bss_info.enabled == TRUE) {
+			wifi_getApEnable(vap_info->vap_index, &apEnable);
+			if (!apEnable)
+				wifi_setApEnable(vap_info->vap_index, TRUE);
+		}
 
 		wifi_debug(DEBUG_ERROR, "\nCreate VAP for ssid_index=%d (vap_num=%d)\n", vap_info->vap_index, i);
 
@@ -20022,32 +20910,21 @@
 			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
 			goto err;
 		}
-		if(band_idx >= 0 && band_idx < sizeof(wifi_band_str)/sizeof(wifi_band_str[0])){
-			res = snprintf(cmd, sizeof(cmd), "cp /etc/hostapd-%s.conf %s", wifi_band_str[band_idx], config_file);
-		} else{
-			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
-			goto err;
-		}
-		if (os_snprintf_error(sizeof(cmd), res)) {
-			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
-			goto err;
-		}
 
-		res = _syscmd_secure(buf, sizeof(buf), "cp /etc/hostapd-%s.conf %s", wifi_band_str[band_idx], config_file);
-		if (res) {
-			wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
-
+		/*check if hostapd conf file exist or not, if not exist, create an new one*/
+		if (access(config_file, F_OK) != 0) {
+			if(band_idx >= 0 && band_idx < sizeof(wifi_band_str)/sizeof(wifi_band_str[0])) {
+				wifi_debug(DEBUG_ERROR, "\n%s not exist, create an new one\n", config_file);
+				res = _syscmd_secure(buf, sizeof(buf), "cp /etc/hostapd-%s.conf %s", wifi_band_str[band_idx], config_file);
+				if (res) {
+					wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
+				}
+			}
 		}
 
 		struct params params[3];
 		params[0].name = "interface";
 		params[0].value = vap_info->vap_name;
-
-		res = snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, vap_info->vap_index);
-		if (os_snprintf_error(sizeof(config_file), res)) {
-			wifi_debug(DEBUG_ERROR, "Unexpected snprintf fail\n");
-			goto err;
-		}
 		wifi_hostapdWrite(config_file, params, 1);
 
 		ret = wifi_setSSIDName(vap_info->vap_index, vap_info->u.bss_info.ssid);
@@ -20088,9 +20965,7 @@
 				res = _syscmd_secure(buf, sizeof(buf), "touch %s%d", DENY_PREFIX, vap_info->vap_index);
 				if (res) {
 					wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
-
 				}
-
 			}else{
 				acl_mode = 1;
 			}
@@ -20121,8 +20996,21 @@
 			wifi_debug(DEBUG_ERROR, "wifi_setApSecurity return error\n");
 			goto err;
 		}
+
+		if (getVapBridge(vap_info->vap_index, bridge_name, sizeof(bridge_name)) == RETURN_OK) {
+			if (strlen(bridge_name) != strlen(vap_info->bridge_name) ||
+				(strlen(bridge_name) == strlen(vap_info->bridge_name) &&
+				strncmp(bridge_name, vap_info->bridge_name, strlen(bridge_name)))) {
+				hostapd_if_restart = 1;
+				setVapBridge(vap_info->vap_index, vap_info->bridge_name);
+			}
+		}
+
 		multiple_set = FALSE;
-		wifi_quick_reload_ap(vap_info->vap_index);
+		if (hostapd_if_restart)
+			hostapd_raw_restart_bss(vap_info->vap_index);
+		else
+			wifi_quick_reload_ap(vap_info->vap_index);
 		// If config use hostapd_cli to set, we calling these type of functions after enable the ap.
 		ret = wifi_setApMacAddressControlMode(vap_info->vap_index, acl_mode);
 		if (ret != RETURN_OK) {
@@ -20146,40 +21034,42 @@
 	}
 
 	/*process mlo operation*/
-	for (i = 0; i < map->num_vaps; i++)
-	{
+	for (i = 0; i < map->num_vaps; i++) {
 		vap_info = &map->vap_array[i];
 		mld_info = &vap_info->u.bss_info.mld_info.common_info;
 
 		wifi_debug(DEBUG_ERROR, "process mlo operation\n");
 		if (!mld_info->mld_enable) {
-			wifi_debug(DEBUG_ERROR, "disable mlo on vap[%d]\n",
-				(int)vap_info->vap_index);
+			wifi_debug(DEBUG_ERROR, "disable mlo on vap[%d], vap->enabled=%d\n",
+				(int)vap_info->vap_index, vap_info->u.bss_info.enabled);
 			mld_index = mld_ap_test_all_mlds((int)vap_info->vap_index);
 			if (mld_index) {
 				wifi_debug(DEBUG_ERROR, "mlo disabled, remove ap(%d) from mld group(%d)\n",
 					(int)vap_info->vap_index, (int)mld_index);
-				if (wifi_eht_remove_from_ap_mld(mld_index, vap_info->vap_index)) {
+				if (wifi_eht_remove_from_ap_mld(mld_index, vap_info->vap_index) != RETURN_OK) {
 					wifi_debug(DEBUG_ERROR, "fail to remove ap(%d) from mld(%d)\n",
 						(int)vap_info->vap_index, (int)mld_index);
 					continue;
 				}
 
-				if (wifi_GetInterfaceName(vap_info->vap_index, interface_name) == RETURN_OK) {
-						return RETURN_ERR;
-					res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s down", interface_name);
-					if (res) {
-						wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
-					}
-					res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s up", interface_name);
-					if (res) {
-						wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
+				if (wifi_GetInterfaceName(vap_info->vap_index, interface_name) == RETURN_OK &&
+					wifi_getApEnable(vap_info->vap_index, &apEnable) == RETURN_OK) {
+					/*if ap is enabled, bring it down and up to make it init single link mld*/
+					if (apEnable) {
+						res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s down", interface_name);
+						if (res) {
+							wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
+						}
+						res = _syscmd_secure(buf, sizeof(buf), "ifconfig %s up", interface_name);
+						if (res) {
+							wifi_debug(DEBUG_ERROR, "_syscmd_secure fail\n");
+						}
 					}
 				}
 
-				if (wifi_eht_get_ap_from_mld(mld_index, ap_index_array, &ap_array_num)) {
+				if (wifi_eht_get_ap_from_mld(mld_index, ap_index_array, &ap_array_num) != RETURN_OK) {
 					wifi_debug(DEBUG_ERROR,
-						"fail to get all aps from mld(%d), destroy it.\n", mld_index);
+						"fail to get all aps from mld(%d).\n", mld_index);
 					continue;
 				}
 
@@ -20196,8 +21086,14 @@
 				continue;
 			}
 
+			if (!vap_info->u.bss_info.enabled) {
+				wifi_debug(DEBUG_ERROR, "vap %d is disabled, not do mlo process.\n",
+					(int)vap_info->vap_index);
+				continue;
+			}
+			
 			if (!mld_test(mld_info->mld_index)) {
-				if (wifi_eht_create_ap_mld(mld_info->mld_index, mld_info->mld_addr)) {
+				if (wifi_eht_create_ap_mld(mld_info->mld_index, mld_info->mld_addr) != RETURN_OK) {
 					wifi_debug(DEBUG_ERROR,
 						"fail to create ap mld(%d)\n", mld_info->mld_index);
 					continue;
@@ -20216,7 +21112,7 @@
 				/*transfer*/
 				wifi_eht_mld_ap_transfer(mld_index, mld_info->mld_index, vap_info->vap_index);
 
-				if (wifi_eht_get_ap_from_mld(mld_index, ap_index_array, &ap_array_num)) {
+				if (wifi_eht_get_ap_from_mld(mld_index, ap_index_array, &ap_array_num) != RETURN_OK) {
 					wifi_debug(DEBUG_ERROR,
 						"fail to get all aps from mld(%d), destroy it.\n", mld_index);
 					continue;
@@ -20268,6 +21164,7 @@
 	CHAR interface_name[16] = {0};
 	wifi_band band;
 	int res;
+	int main_vap_idx;
 
 	if(rcap == NULL)
 	{
@@ -20331,7 +21228,12 @@
 	rcap->csi.maxDevices = 8;
 	rcap->csi.soudingFrameSupported = TRUE;
 
+	if (array_index_to_vap_index(radioIndex, 0, &main_vap_idx) != RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid radio_index[%d]\n", radioIndex);
+		return RETURN_ERR;
+	}
+
-	if (wifi_GetInterfaceName(radioIndex, interface_name) != RETURN_OK) {
+	if (wifi_GetInterfaceName(main_vap_idx, interface_name) != RETURN_OK) {
 		wifi_debug(DEBUG_ERROR, "wifi_GetInterfaceName fail\n");
 	}
 	res = snprintf(rcap->ifaceName, sizeof(interface_name), "%s",interface_name);
@@ -20347,24 +21249,29 @@
 		rcap->channelWidth[i] |= (WIFI_CHANNELBANDWIDTH_20MHZ |
 								WIFI_CHANNELBANDWIDTH_40MHZ);
 
-	}
-	else if (rcap->band[i] & (WIFI_FREQUENCY_5_BAND ) || rcap->band[i] & (WIFI_FREQUENCY_6_BAND)) {
+	} else if (rcap->band[i] & (WIFI_FREQUENCY_5_BAND ) || rcap->band[i] & (WIFI_FREQUENCY_6_BAND)) {
 		rcap->channelWidth[i] |= (WIFI_CHANNELBANDWIDTH_20MHZ |
 								WIFI_CHANNELBANDWIDTH_40MHZ |
 								WIFI_CHANNELBANDWIDTH_80MHZ | WIFI_CHANNELBANDWIDTH_160MHZ);
+	} else if (rcap->band[i] & (WIFI_FREQUENCY_6_BAND)) {
+		rcap->channelWidth[i] |= (WIFI_CHANNELBANDWIDTH_20MHZ |
+								WIFI_CHANNELBANDWIDTH_40MHZ |
+								WIFI_CHANNELBANDWIDTH_80MHZ | 
+								WIFI_CHANNELBANDWIDTH_160MHZ | 
+								WIFI_CHANNELBANDWIDTH_320MHZ);
 	}
 
 
 	/* mode - all supported variants */
 	// rcap->mode[i] = WIFI_80211_VARIANT_H;
 	if (rcap->band[i] & WIFI_FREQUENCY_2_4_BAND ) {
-		rcap->mode[i] = ( WIFI_80211_VARIANT_B | WIFI_80211_VARIANT_G | WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX );
+		rcap->mode[i] = ( WIFI_80211_VARIANT_B | WIFI_80211_VARIANT_G | WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AX | WIFI_80211_VARIANT_BE);
 	}
 	else if (rcap->band[i] & WIFI_FREQUENCY_5_BAND ) {
-		rcap->mode[i] = ( WIFI_80211_VARIANT_A | WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX );
+		rcap->mode[i] = ( WIFI_80211_VARIANT_A | WIFI_80211_VARIANT_N | WIFI_80211_VARIANT_AC | WIFI_80211_VARIANT_AX | WIFI_80211_VARIANT_BE);
 	}
 	else if (rcap->band[i] & WIFI_FREQUENCY_6_BAND) {
-		rcap->mode[i] = ( WIFI_80211_VARIANT_AX );
+		rcap->mode[i] = ( WIFI_80211_VARIANT_AX | WIFI_80211_VARIANT_BE);
 	}
 	rcap->maxBitRate[i] = ( rcap->band[i] & WIFI_FREQUENCY_2_4_BAND ) ? 300 :
 		((rcap->band[i] & WIFI_FREQUENCY_5_BAND) ? 1734 : 0);
@@ -20390,14 +21297,15 @@
 	rcap->transmitPowerSupported_list[i].transmitPowerSupported[4]=100;
 	rcap->cipherSupported = 0;
 	rcap->cipherSupported |= WIFI_CIPHER_CAPA_ENC_TKIP | WIFI_CIPHER_CAPA_ENC_CCMP;
-	rcap->maxNumberVAPs = MAX_NUM_VAP_PER_RADIO;
+	rcap->maxNumberVAPs = LOGAN_MAX_NUM_VAP_PER_RADIO;
 
 	return RETURN_OK;
 }
 
+
 INT wifi_getHalCapability(wifi_hal_capability_t *cap)
 {
-	INT status = 0, radioIndex = 0;
+	INT status = 0, radioIndex = 0, vap_idx;
 	char output[MAX_BUF_SIZE] = {0};
 	int iter = 0;
 	unsigned int j = 0;
@@ -20426,7 +21334,7 @@
 
 		for (j = 0; j < cap->wifi_prop.radiocap[radioIndex].maxNumberVAPs; j++)
 		{
-			if (iter >= MAX_NUM_RADIOS * MAX_NUM_VAP_PER_RADIO)
+			if (iter >= RUNTIME_MAX_RADIO * MAX_NUM_VAP_PER_RADIO)
 			{
 				 printf("%s: to many vaps for index map (%d)\n", __func__, iter);
 				 return RETURN_ERR;
@@ -20434,25 +21342,31 @@
 			iface_info = &cap->wifi_prop.interface_map[iter];
 			iface_info->phy_index = radioIndex; // XXX: parse phyX index instead
 			iface_info->rdk_radio_index = radioIndex;
-			memset(output, 0, sizeof(output));
-			if (wifi_getRadioIfName(radioIndex, output) == RETURN_OK)
-			{
-				strncpy(iface_info->interface_name, output, sizeof(iface_info->interface_name) - 1);
+
+			if (array_index_to_vap_index(radioIndex, j, &vap_idx) != RETURN_OK) {
+				wifi_debug(DEBUG_ERROR, "invalid radioIndex %d, j %d\n", radioIndex, j);
+				continue;
 			}
-			// TODO: bridge name
+
+			iface_info->index = vap_idx;
+
+			if (wifi_GetInterfaceName(iface_info->index, output))
+				strncpy(iface_info->interface_name, output, sizeof(iface_info->interface_name) - 1);
+
+			getVapBridge(iface_info->index, iface_info->bridge_name, sizeof(iface_info->bridge_name));
 			// TODO: vlan id
 			// TODO: primary
-			iface_info->index = array_index_to_vap_index(radioIndex, j);
-			memset(output, 0, sizeof(output));
 			if (wifi_getApName(iface_info->index, output) == RETURN_OK)
-			{
 				 strncpy(iface_info->vap_name, output, sizeof(iface_info->vap_name) - 1);
-			}
-		iter++;
+
+			iter++;
 		}
 	}
 
 	cap->BandSteeringSupported = FALSE;
+
+	memcpy(&g_hal_cap, cap, sizeof(g_hal_cap));
+
 	WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
 	return RETURN_OK;
 }
@@ -21024,7 +21938,7 @@
 
 INT wifi_getRadioStatsEnable(INT radioIndex, BOOL *output_enable)
 {
-	if (NULL == output_enable || radioIndex >=MAX_NUM_RADIOS)
+	if (NULL == output_enable || radioIndex >=RUNTIME_MAX_RADIO)
 		return RETURN_ERR;
 	*output_enable=TRUE;
 	return RETURN_OK;
@@ -21036,12 +21950,11 @@
 	char buf[128] = {0};
 	char line[128] = {0};
 	FILE *f = NULL;
-	int index = 0;
+	int index = 0, bss_idx;
 	int exp = 0;
 	int mantissa = 0;
 	int duration = 0;
 	int radio_index = 0;
-	int max_radio_num = 0;
 	uint twt_wake_interval = 0;
 	int phyId = 0;
 	int res;
@@ -21049,12 +21962,10 @@
 
 	WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
 
-	wifi_getMaxRadioNumber(&max_radio_num);
-	if(max_radio_num == 0){
+	if (vap_index_to_radio_array_index(ap_index, &radio_index, &bss_idx)!= RETURN_OK) {
+		wifi_debug(DEBUG_ERROR, "invalid ap_index[%d]\n", ap_index);
 		return RETURN_ERR;
 	}
-	radio_index = ap_index % max_radio_num;
-
 	phyId = radio_index_to_phy(radio_index);
 
 	res = _syscmd_secure(buf, sizeof(buf),"cat /sys/kernel/debug/ieee80211/phy%d/mt76/twt_stats | wc -l", phyId);