[rdk-b][mt7986][wifi-hal][Add GuardInterval functions]
[Description]
Add GuardInterval functions. And record GI value in the file.
The function getRadioGuardInterval and setRadioGuardInterval is deprecated, So I implement them just call the corresponding new functions.
Use iw instead of hostapd beacause hostapd can not set GI in he mode.
[Release-log]
N/A
Change-Id: I7cb89b583c6d53650f641bc80fbc45100916a92a
diff --git a/src/wifi/wifi_hal.c b/src/wifi/wifi_hal.c
index 5b3dcd5..37f2ef7 100644
--- a/src/wifi/wifi_hal.c
+++ b/src/wifi/wifi_hal.c
@@ -74,6 +74,8 @@
#define SOCK_PREFIX "/var/run/hostapd/wifi"
#define VAP_STATUS_FILE "/tmp/vap-status"
#define ESSID_FILE "/tmp/essid"
+#define GUARD_INTERVAL_FILE "/tmp/guard-interval"
+
#define DRIVER_2GHZ "ath9k"
#define DRIVER_5GHZ "ath10k_pci"
@@ -2251,19 +2253,54 @@
//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_getRadioGuardInterval(INT radioIndex, CHAR *output_string) //Tr181
{
- //save config and apply instantly
- if (NULL == output_string)
+ wifi_guard_interval_t GI;
+
+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
+
+ if (output_string == NULL || wifi_getGuardInterval(radioIndex, &GI) == RETURN_ERR)
return RETURN_ERR;
- snprintf(output_string, 64, (radioIndex == 0) ? "400nsec" : "400nsec");
+
+ if (GI == wifi_guard_interval_400)
+ strcpy(output_string, "400nsec");
+ else if (GI == wifi_guard_interval_800)
+ strcpy(output_string, "800nsec");
+ else if (GI == wifi_guard_interval_1600)
+ strcpy(output_string, "1600nsec");
+ else if (GI == wifi_guard_interval_3200)
+ strcpy(output_string, "3200nsec");
+ else
+ strcpy(output_string, "auto");
+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
return RETURN_OK;
}
//Set the guard interval value.
INT wifi_setRadioGuardInterval(INT radioIndex, CHAR *string) //Tr181
{
- //Apply setting instantly
- return RETURN_ERR;
+ wifi_guard_interval_t GI;
+ int ret = 0;
+
+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
+
+ if (strcmp(string, "400nsec") == 0)
+ GI = wifi_guard_interval_400;
+ else if (strcmp(string , "800nsec") == 0 || strcmp(string, "auto") == 0)
+ GI = wifi_guard_interval_800;
+ else if (strcmp(string , "1600nsec") == 0)
+ GI = wifi_guard_interval_1600;
+ else if (strcmp(string , "3200nsec") == 0)
+ GI = wifi_guard_interval_3200;
+
+ ret = wifi_setGuardInterval(radioIndex, GI);
+
+ if (ret == RETURN_ERR) {
+ wifi_dbg_printf("%s: wifi_setGuardInterval return error\n", __func__);
+ return RETURN_ERR;
+ }
+
+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
+ return RETURN_OK;
}
//Get the Modulation Coding Scheme index, eg: "-1", "1", "15"
@@ -9211,6 +9248,94 @@
return RETURN_OK;
}
+INT wifi_setGuardInterval(INT radio_index, wifi_guard_interval_t guard_interval)
+{
+ char cmd[128] = {0};
+ char buf[64] = {0};
+ char band_str[8] = {0};
+ char GI[8] = {0};
+ int tmp = 0;
+ BOOL ax_mode = FALSE;
+ BOOL short_GI = FALSE;
+ FILE *f = NULL;
+ wifi_band band;
+
+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
+
+ if (wifi_getRadioMode(radio_index, buf, &tmp) == RETURN_ERR) {
+ wifi_dbg_printf("%s: wifi_getRadioMode return error\n", __func__);
+ return RETURN_ERR;
+ }
+ if (strstr(buf, "ax") != NULL)
+ ax_mode = TRUE;
+
+ if (guard_interval == wifi_guard_interval_400 && ax_mode != TRUE) {
+ short_GI = TRUE;
+ strcpy(GI, "0.4");
+ } else if (guard_interval == wifi_guard_interval_1600 && ax_mode == TRUE)
+ strcpy(GI, "1.6");
+ else if (guard_interval == wifi_guard_interval_3200 && ax_mode == TRUE)
+ strcpy(GI, "3.2");
+ else // default
+ strcpy(GI, "0.8");
+
+ band = wifi_index_to_band(radio_index);
+ if (band == band_2_4)
+ strcpy(band_str, "2.4");
+ else if (band == band_5)
+ strcpy(band_str, "5");
+ else if (band == band_6)
+ strcpy(band_str, "6");
+ else {
+ wifi_dbg_printf("%s: invalid band\n");
+ return RETURN_ERR;
+ }
+
+ if (ax_mode == TRUE)
+ snprintf(cmd, sizeof(cmd), "iw dev %s%d set bitrates he-gi-%s %s", AP_PREFIX, radio_index, band_str, GI);
+ else
+ snprintf(cmd, sizeof(cmd), "iw dev %s%d set bitrates %sgi-%s", AP_PREFIX, radio_index, (short_GI)?"s":"l", band_str);
+ _syscmd(cmd, buf, sizeof(buf));
+
+ // Record GI for get GI function
+ snprintf(buf, sizeof(buf), "%s%d.txt", GUARD_INTERVAL_FILE, radio_index);
+ f = fopen(buf, "w");
+ if (f != NULL) {
+ fprintf(f, "%s", GI);
+ }
+ fclose(f);
+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
+ return RETURN_OK;
+}
+
+INT wifi_getGuardInterval(INT radio_index, wifi_guard_interval_t *guard_interval)
+{
+ char buf[32] = {0};
+ char cmd[64] = {0};
+
+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
+
+ if (guard_interval == NULL)
+ return RETURN_ERR;
+
+ snprintf(cmd, sizeof(cmd), "cat %s%d.txt", GUARD_INTERVAL_FILE, radio_index);
+ _syscmd(cmd, buf, sizeof(buf));
+
+ if (strncmp(buf, "0.4", 3) == 0)
+ *guard_interval = wifi_guard_interval_400;
+ else if (strncmp(buf, "0.8", 3) == 0)
+ *guard_interval = wifi_guard_interval_800;
+ else if (strncmp(buf, "1.6", 3) == 0)
+ *guard_interval = wifi_guard_interval_1600;
+ else if (strncmp(buf, "3.2", 3) == 0)
+ *guard_interval = wifi_guard_interval_3200;
+ else
+ *guard_interval = wifi_guard_interval_auto;
+
+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
+ return RETURN_OK;
+}
+
/* multi-psk support */
INT wifi_getMultiPskClientKey(INT apIndex, mac_address_t mac, wifi_key_multi_psk_t *key)
{