Merge "[rdkb][common][hal][Refactor hal for single Wiphy]"
diff --git a/src/wifi/wifi_hal.c b/src/wifi/wifi_hal.c
index a965254..2d814e6 100644
--- a/src/wifi/wifi_hal.c
+++ b/src/wifi/wifi_hal.c
@@ -135,6 +135,13 @@
#define PS_MAX_TID 16
+
+#ifdef SINGLE_WIPHY_SUPPORT
+#define single_wiphy TRUE
+#else
+#define single_wiphy FALSE
+#endif
+
static wifi_radioQueueType_t _tid_ac_index_get[PS_MAX_TID] = {
WIFI_RADIO_QUEUE_TYPE_BE, /* 0 */
WIFI_RADIO_QUEUE_TYPE_BK, /* 1 */
@@ -491,7 +498,7 @@
WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
- snprintf(cmd, sizeof(cmd), "iw list | grep Wiphy | wc -l");
+ snprintf(cmd, sizeof(cmd), "ls /sys/class/ieee80211 | wc -l");
_syscmd(cmd, buf, sizeof(buf));
*max_radio_num = strtoul(buf, NULL, 10) > MAX_NUM_RADIOS ? MAX_NUM_RADIOS:strtoul(buf, NULL, 10);
@@ -551,34 +558,17 @@
wifi_getMaxRadioNumber(&max_radio_num);
radioIndex = apIndex % max_radio_num;
- phyIndex = radio_index_to_phy(radioIndex);
- snprintf(cmd, sizeof(cmd), "cat /sys/class/ieee80211/phy%d/device/device 2> /dev/null", phyIndex);
- _syscmd(cmd, buf, sizeof(buf));
- if (strncmp(buf, "0x7915", 6) == 0) { // harrier have two bands, consider as a special case.
- snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
- wifi_hostapdRead(config_file, "hw_mode", buf, sizeof(buf));
- if (strncmp(buf, "a", 1) == 0)
- return band_5;
- else
- return band_2_4;
- }
- while(i < 10){
- snprintf(cmd, sizeof(cmd), "iw phy%d info | grep 'Band .:' | tr -d ':\\n' | awk '{print $2}'", phyIndex);
- _syscmd(cmd, buf, sizeof(buf));
- nl80211_band = strtol(buf, NULL, 10);
- if (nl80211_band == 1)
- band = band_2_4;
- else if (nl80211_band == 2)
- band = band_5;
- else if (nl80211_band == 4) // band == 3 is 60GHz
- band = band_6;
+ snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, apIndex);
+ wifi_hostapdRead(config_file, "op_class", buf, sizeof(buf));
+ if (strlen(buf) > 0)
+ return band_6;
- if(band != band_invalid)
- break;
-
- i++;
- sleep(1);
- }
+ memset(buf, 0, sizeof(buf));
+ wifi_hostapdRead(config_file, "hw_mode", buf, sizeof(buf));
+ if (strncmp(buf, "a", 1) == 0)
+ return band_5;
+ else
+ return band_2_4;
WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
return band;
@@ -1419,8 +1409,9 @@
}
}
snprintf(cmd, sizeof(cmd), "hostapd_cli -i global raw ADD bss_config=phy%d:/nvram/hostapd%d.conf",
- phyId, apIndex);
+ single_wiphy ? radioIndex : phyId, apIndex);
_syscmd(cmd, buf, sizeof(buf));
+
if(strncmp(buf, "OK", 2))
fprintf(stderr, "Could not detach %s from hostapd daemon", interface_name);
}
@@ -3180,7 +3171,7 @@
// Get the maximum tx power of the device
snprintf(cmd, sizeof(cmd), "cat /sys/kernel/debug/ieee80211/phy%d/mt76/txpower_info | "
- "grep 'Percentage Control:' | awk '{print $3}' | tr -d '\\n'", phyIndex);
+ "grep 'Percentage Control:' | awk '{print $3}' | tr -d '\\n'", single_wiphy ? radioIndex : phyIndex);
_syscmd(cmd, buf, sizeof(buf));
if (strcmp(buf, "enable") == 0)
enabled = true;
@@ -3193,7 +3184,7 @@
memset(cmd, 0, sizeof(cmd));
memset(buf, 0, sizeof(buf));
snprintf(cmd, sizeof(cmd), "cat /sys/kernel/debug/ieee80211/phy%d/mt76/txpower_info | "
- "grep 'Power Drop:' | awk '{print $3}' | tr -d '\\n'", phyIndex);
+ "grep 'Power Drop:' | awk '{print $3}' | tr -d '\\n'", single_wiphy ? radioIndex : phyIndex);
_syscmd(cmd, buf, sizeof(buf));
cur_tx_dbm = strtol(buf, NULL, 10);
@@ -3258,7 +3249,7 @@
phyId = radio_index_to_phy(radioIndex);
snprintf(cmd, sizeof(cmd), "echo %lu > /sys/kernel/debug/ieee80211/phy%d/mt76/txpower_level",
- TransmitPower, phyId);
+ TransmitPower, single_wiphy ? radioIndex : phyId);
_syscmd(cmd, buf, sizeof(buf));
WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
@@ -6258,14 +6249,10 @@
if (!(apIndex/max_radio_num)) {
sprintf(cmd, "iw %s del", interface_name);
_syscmd(cmd, buf, sizeof(buf));
-#ifdef SINGLE_WIPHY_SUPPORT
- sprintf(cmd, "iw phy phy0 interface add %s type __ap", interface_name);
-#else
sprintf(cmd, "iw phy phy%d interface add %s type __ap", phyId, interface_name);
-#endif
_syscmd(cmd, buf, sizeof(buf));
}
- sprintf(cmd, "hostapd_cli -i global raw ADD bss_config=phy%d:%s", phyId, config_file);
+ sprintf(cmd, "hostapd_cli -i global raw ADD bss_config=phy%d:%s", single_wiphy ? radioIndex : phyId, config_file);
_syscmd(cmd, buf, sizeof(buf));
}
else {
@@ -11310,7 +11297,7 @@
// Get the maximum tx power of the device
snprintf(cmd, sizeof(cmd), "cat /sys/kernel/debug/ieee80211/phy%d/mt76/txpower_info | "
- "grep 'Percentage Control:' | awk '{print $3}' | tr -d '\\n'", phyIndex);
+ "grep 'Percentage Control:' | awk '{print $3}' | tr -d '\\n'", single_wiphy ? radioIndex : phyIndex);
_syscmd(cmd, buf, sizeof(buf));
if (strcmp(buf, "enable") == 0)
enabled = true;
@@ -11323,7 +11310,7 @@
memset(cmd, 0, sizeof(cmd));
memset(buf, 0, sizeof(buf));
snprintf(cmd, sizeof(cmd), "cat /sys/kernel/debug/ieee80211/phy%d/mt76/txpower_info | "
- "grep 'Power Drop:' | awk '{print $3}' | tr -d '\\n'", phyIndex);
+ "grep 'Power Drop:' | awk '{print $3}' | tr -d '\\n'", single_wiphy ? radioIndex : phyIndex);
_syscmd(cmd, buf, sizeof(buf));
cur_tx_dbm = strtol(buf, NULL, 10);
@@ -13975,7 +13962,7 @@
radio_index = ap_index % max_radio_num;
phyId = radio_index_to_phy(radio_index);
- sprintf(cmd, "cat /sys/kernel/debug/ieee80211/phy%d/mt76/twt_stats | wc -l", phyId);
+ sprintf(cmd, "cat /sys/kernel/debug/ieee80211/phy%d/mt76/twt_stats | wc -l", single_wiphy ? radio_index : phyId);
_syscmd(cmd, buf, sizeof(buf));
*numSessionReturned = strtol(buf, NULL, 10) - 1;
if (*numSessionReturned > maxNumberSessions)
@@ -13985,7 +13972,7 @@
return RETURN_OK;
}
- sprintf(cmd, "cat /sys/kernel/debug/ieee80211/phy%d/mt76/twt_stats | tail -n %d | tr '|' ' ' | tr -s ' '", phyId, *numSessionReturned);
+ sprintf(cmd, "cat /sys/kernel/debug/ieee80211/phy%d/mt76/twt_stats | tail -n %d | tr '|' ' ' | tr -s ' '", single_wiphy ? radio_index : phyId, *numSessionReturned);
if ((f = popen(cmd, "r")) == NULL) {
wifi_dbg_printf("%s: popen %s error\n", __func__, cmd);
return RETURN_ERR;