Skip to content

Commit d52092f

Browse files
Implement dynamic MCS selection based on signal strength in vWIFI driver
This commit enhances the vWIFI driver by implementing dynamic Modulation and Coding Scheme (MCS) selection in the `vwifi_get_station` function, adjusting the MCS index based on signal strength. After implement dynamic MCS can avoid TX power waste for a bad channel quality.
1 parent 0258f2a commit d52092f

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

vwifi.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,18 @@ static int vwifi_get_station(struct wiphy *wiphy,
14031403
sinfo->tx_failed = vif->stats.tx_dropped;
14041404
sinfo->tx_bytes = vif->stats.tx_bytes;
14051405
sinfo->rx_bytes = vif->stats.rx_bytes;
1406+
1407+
/* Log byte counters for debugging */
1408+
pr_info(
1409+
"vwifi: Station %pM tx_bytes %llu, rx_bytes %llu, tx_packets %u, "
1410+
"rx_packets %u, tx_failed %u\n",
1411+
mac, sinfo->tx_bytes, sinfo->rx_bytes, sinfo->tx_packets,
1412+
sinfo->rx_packets, sinfo->tx_failed);
1413+
14061414
/* For CFG80211_SIGNAL_TYPE_MBM, value is expressed in dBm */
14071415
sinfo->signal = rand_int_smooth(-100, -30, jiffies);
1416+
pr_info("vwifi: Station %pM signal %d dBm (raw)\n", mac,
1417+
sinfo->signal);
14081418
sinfo->inactive_time = jiffies_to_msecs(jiffies - vif->active_time);
14091419
/*
14101420
* Using 802.11n (HT) as the PHY, configure as follows:
@@ -1425,15 +1435,53 @@ static int vwifi_get_station(struct wiphy *wiphy,
14251435
* https://semfionetworks.com/blog/mcs-table-updated-with-80211ax-data-rates/
14261436
* IEEE 802.11n : https://zh.wikipedia.org/zh-tw/IEEE_802.11n
14271437
*/
1428-
sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
1429-
sinfo->rxrate.mcs = 31;
1438+
/* Log byte counters for debugging */
1439+
pr_info("vwifi: Station %pM tx_bytes %llu, rx_bytes %llu\n", mac,
1440+
sinfo->tx_bytes, sinfo->rx_bytes);
1441+
1442+
/* Dynamic modulation based on signal strength */
1443+
int mcs_index;
1444+
const char *modulation;
1445+
unsigned int data_rate_mbps;
1446+
if (sinfo->signal > -50) {
1447+
/* Strong signal: 64-QAM, MCS 31 */
1448+
mcs_index = 31;
1449+
modulation = "64-QAM";
1450+
} else if (sinfo->signal > -70 && sinfo->signal <= -50) {
1451+
/* Medium signal: 16-QAM, MCS 23 */
1452+
mcs_index = 23;
1453+
modulation = "16-QAM";
1454+
} else if (sinfo->signal > -90 && sinfo->signal <= -70) {
1455+
/* Weak signal: QPSK, MCS 15 */
1456+
mcs_index = 15;
1457+
modulation = "QPSK";
1458+
} else {
1459+
/* Very weak signal: BPSK, MCS 7 */
1460+
mcs_index = 7;
1461+
modulation = "BPSK";
1462+
}
1463+
1464+
/* Log signal, modulation, and data rate for debugging */
1465+
pr_info(
1466+
"vwifi: Station %pM signal %d dBm, using modulation %s (MCS %d, %u "
1467+
"Mbps)\n",
1468+
mac, sinfo->signal, modulation, mcs_index, data_rate_mbps);
1469+
1470+
/* Configure RX and TX rates */
1471+
sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS;
1472+
sinfo->rxrate.mcs = mcs_index;
14301473
sinfo->rxrate.bw = RATE_INFO_BW_20;
14311474
sinfo->rxrate.n_bonded_ch = 1;
14321475

1433-
sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1434-
sinfo->txrate.mcs = 31;
1476+
sinfo->txrate.flags = RATE_INFO_FLAGS_MCS;
1477+
sinfo->txrate.mcs = mcs_index;
14351478
sinfo->txrate.bw = RATE_INFO_BW_20;
14361479
sinfo->txrate.n_bonded_ch = 1;
1480+
1481+
/* Log rate configuration for verification */
1482+
pr_info("vwifi: Station %pM txrate MCS %d, rxrate MCS %d\n", mac,
1483+
sinfo->txrate.mcs, sinfo->rxrate.mcs);
1484+
14371485
return 0;
14381486
}
14391487

0 commit comments

Comments
 (0)