[rdk-b][mt7986][wifi-hal][Add set and get BeaconRate]
[Description]
Add set and get BeaconRate wifi hal function.
The setApBeaconRate have specific input string format defined by documentation.
The unit in RDKB is Mbps, but the unit in hostapd is 100 kbps.
So, we should multiply 10 in set funtion and divide 10 in get funtion to convert the unit.
[Release-log]
N/A
diff --git a/recipes-ccsp/hal/hal-wifi-patches/0031-HAL-refactor-set-and-get-Beacon-Rate-function.patch b/recipes-ccsp/hal/hal-wifi-patches/0031-HAL-refactor-set-and-get-Beacon-Rate-function.patch
new file mode 100644
index 0000000..8156eb3
--- /dev/null
+++ b/recipes-ccsp/hal/hal-wifi-patches/0031-HAL-refactor-set-and-get-Beacon-Rate-function.patch
@@ -0,0 +1,81 @@
+From c47c87b8412a219286e6f80cd8234aa506465be3 Mon Sep 17 00:00:00 2001
+From: "Allen.Ye" <allen.ye@mediatek.com>
+Date: Thu, 28 Jul 2022 10:52:36 +0800
+Subject: [PATCH] HAL: refactor set and get Beacon Rate function
+
+---
+ source/wifi/wifi_hal.c | 52 ++++++++++++++++++++++++++++++++++++++++--
+ 1 file changed, 50 insertions(+), 2 deletions(-)
+
+diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c
+index 6596cfc..0e047fc 100644
+--- a/source/wifi/wifi_hal.c
++++ b/source/wifi/wifi_hal.c
+@@ -618,14 +618,62 @@ static int readBandWidth(int radioIndex,char *bw_value)
+ return RETURN_OK;
+ }
+
++// Input must be "1Mbps"; "5.5Mbps"; "6Mbps"; "2Mbps"; "11Mbps"; "12Mbps"; "24Mbps"
+ INT wifi_setApBeaconRate(INT radioIndex,CHAR *beaconRate)
+ {
+- return 0;
++ struct params params={'\0'};
++ char config_file[MAX_BUF_SIZE] = {0};
++ char buf[MAX_BUF_SIZE] = {'\0'};
++
++ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
++ if (strlen (beaconRate) < 5)
++ return RETURN_ERR;
++ // Copy the numeric value
++ strncpy(buf, beaconRate, strlen(beaconRate) - 4);
++ buf[strlen(beaconRate) - 4] = '\0';
++
++ params.name = "beacon_rate";
++ // hostapd config unit is 100 kbps. To convert Mbps to 100kbps, the value need to multiply 10.
++ if (strncmp(buf, "5.5", 3) == 0) {
++ snprintf(buf, sizeof(buf), "55");
++ params.value = buf;
++ } else {
++ strcat(buf, "0");
++ params.value = buf;
++ }
++
++ sprintf(config_file, "%s%d.conf", CONFIG_PREFIX, radioIndex);
++ wifi_hostapdWrite(config_file, ¶ms, 1);
++ wifi_hostapdProcessUpdate(radioIndex, ¶ms, 1);
++ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
++
++ return RETURN_OK;
+ }
+
+ INT wifi_getApBeaconRate(INT radioIndex, CHAR *beaconRate)
+ {
+- return 0;
++ char config_file[MAX_BUF_SIZE] = {'\0'};
++ char temp_output[MAX_BUF_SIZE] = {'\0'};
++ char buf[MAX_BUF_SIZE] = {'\0'};
++ float rate = 0;
++
++ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
++ if (NULL == beaconRate)
++ return RETURN_ERR;
++
++ sprintf(config_file, "%s%d.conf", CONFIG_PREFIX, radioIndex);
++ wifi_hostapdRead(config_file, "beacon_rate", buf, sizeof(buf));
++ // Hostapd unit is 100kbps. To convert to 100kbps to Mbps, the value need to divide 10.
++ if(strlen(buf) > 0) {
++ rate = atof(buf)/10;
++ snprintf(temp_output, sizeof(temp_output), "%.1fMbps", rate);
++ } else {
++ snprintf(temp_output, sizeof(temp_output), "1Mbps"); // default value
++ }
++ strncpy(beaconRate, temp_output, sizeof(temp_output));
++ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
++
++ return RETURN_OK;
+ }
+
+ INT wifi_setLED(INT radioIndex, BOOL enable)
+--
+2.18.0
+