Merge "[[RDK-B]fix crash in hal api]"
diff --git a/src/logan_wifi/wifi_hal.c b/src/logan_wifi/wifi_hal.c
index 09194e4..462dd0d 100644
--- a/src/logan_wifi/wifi_hal.c
+++ b/src/logan_wifi/wifi_hal.c
@@ -1779,7 +1779,7 @@
 			ap_idx = array_index_to_vap_index(radio_idx, bss_idx);
 
 			snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, ap_idx);
-			snprintf(buf, sizeof(buf), "cp /etc/hostapd-%s.conf %s", band_str[radio_idx], config_file);
+			snprintf(buf, sizeof(buf), "cp /etc/hostapd-%s.conf %s", wifi_band_str[radio_idx], config_file);
 			_syscmd(buf, ret_buf, sizeof(ret_buf));
 
 			if (radio_idx == band_2_4) {
@@ -1975,8 +1975,6 @@
 
 	wifi_vap_status_reset();
 
-    wifi_BringUpInterfaces();
-
 
     WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
 
@@ -2020,8 +2018,6 @@
 
 	wifi_vap_status_reset();
 
-    wifi_BringUpInterfaces();
-
     return RETURN_OK;
 }
 
@@ -3617,7 +3613,7 @@
 	vap_index_to_array_index(apIndex, &radio_idx, &bss_idx);
 
 	/*prepare new config file*/
-	snprintf(cmd, sizeof(cmd), "cp /etc/hostapd-%s.conf %s", band_str[radio_idx], ap_config_file);
+	snprintf(cmd, sizeof(cmd), "cp /etc/hostapd-%s.conf %s", wifi_band_str[radio_idx], ap_config_file);
 	_syscmd(cmd, ret_buf, sizeof(ret_buf));
 
 	if (radio_idx == band_2_4) {
@@ -7615,6 +7611,7 @@
 	char interface_name[IF_NAME_SIZE] = {0};
 	char cmd[MAX_CMD_SIZE] = {0};
 	char buf[MAX_BUF_SIZE] = {0};
+	int ret;
 
 	if ((!output_bool) || (apIndex < 0) || (apIndex >= MAX_APS))
 		return RETURN_ERR;
@@ -7626,8 +7623,10 @@
 			*output_bool = FALSE;
 			return RETURN_OK;
 		}
-		snprintf(cmd, MAX_CMD_SIZE, "ifconfig %s 2> /dev/null | grep UP", interface_name);
-		*output_bool = _syscmd(cmd, buf, sizeof(buf)) ? 0 : 1;
+		snprintf(cmd, sizeof(cmd), "hostapd_cli -i %s status", interface_name);
+		ret = system(cmd);
+		if (ret == 0)
+			*output_bool = 1;
 	}
 
 	return RETURN_OK;
@@ -14230,12 +14229,14 @@
         }
         snprintf(map->vap_array[i].u.bss_info.ssid, sizeof(map->vap_array[i].u.bss_info.ssid), "%s", buf);
 
+#if 0
         ret = wifi_getSSIDEnable(vap_index, &enabled);
         if (ret != RETURN_OK) {
             printf("%s: wifi_getSSIDEnable return error\n", __func__);
             return RETURN_ERR;
         }
-        map->vap_array[i].u.bss_info.enabled = enabled;
+#endif
+        map->vap_array[i].u.bss_info.enabled = true;
 
         ret = wifi_getApSsidAdvertisementEnable(vap_index, &enabled);
         if (ret != RETURN_OK) {
@@ -14409,6 +14410,8 @@
     char bssid[32] = {0};
     char psk_file[64] = {0};
     BOOL enable = FALSE;
+    int band_idx;
+
 
     WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
     printf("Entering %s index = %d\n", __func__, (int)index);
@@ -14424,25 +14427,12 @@
 
         fprintf(stderr, "\nCreate VAP for ssid_index=%d (vap_num=%d)\n", vap_info->vap_index, i);
 
-        if (wifi_getApEnable(vap_info->vap_index, &enable) != RETURN_OK)
-            enable = FALSE;
-
-        // multi-ap first up need to copy current radio config
-        if (vap_info->radio_index != vap_info->vap_index && enable == FALSE) {
-            snprintf(cmd, sizeof(cmd), "cp %s%d.conf %s%d.conf", CONFIG_PREFIX, vap_info->radio_index, CONFIG_PREFIX, vap_info->vap_index);
-            _syscmd(cmd, buf, sizeof(buf));
-            if (strlen(vap_info->vap_name) == 0)    // default name of the interface is wifiX
-                snprintf(vap_info->vap_name, 16, "wifi%d", vap_info->vap_index);
-        } else {
-            // Check whether the interface name is valid or this ap change it.
-            int apIndex = -1;
-            wifi_getApIndexFromName(vap_info->vap_name, &apIndex);
-            if (apIndex != -1 && apIndex != vap_info->vap_index)
-                continue;
-            prepareInterface(vap_info->vap_index, vap_info->vap_name);
-        }
+        band_idx = radio_index_to_band(index);
+        snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, vap_info->vap_index);
+        snprintf(cmd, sizeof(cmd), "cp /etc/hostapd-%s.conf %s", wifi_band_str[band_idx], config_file);
+        _syscmd(cmd, buf, sizeof(buf));
 
-        struct params params[3];
+        struct params params[4];
         params[0].name = "interface";
         params[0].value = vap_info->vap_name;
         mac_addr_ntoa(bssid, vap_info->u.bss_info.bssid);
@@ -14451,9 +14441,11 @@
         snprintf(psk_file, sizeof(psk_file), "\\/nvram\\/hostapd%d.psk", vap_info->vap_index);
         params[2].name = "wpa_psk_file";
         params[2].value = psk_file;
+        params[3].name = "ssid";
+        params[3].value = vap_info->u.bss_info.ssid;
 
         sprintf(config_file, "%s%d.conf", CONFIG_PREFIX, vap_info->vap_index);
-        wifi_hostapdWrite(config_file, params, 3);
+        wifi_hostapdWrite(config_file, params, 4);
 
         snprintf(cmd, sizeof(cmd), "touch %s", psk_file);
         _syscmd(cmd, buf, sizeof(buf));