Skip to content

Commit 151e1eb

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 151e1eb

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

vwifi.c

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

1433-
sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1434-
sinfo->txrate.mcs = 31;
1477+
sinfo->txrate.flags = RATE_INFO_FLAGS_MCS;
1478+
sinfo->txrate.mcs = mcs_index;
14351479
sinfo->txrate.bw = RATE_INFO_BW_20;
14361480
sinfo->txrate.n_bonded_ch = 1;
1481+
1482+
/* Log rate configuration for verification */
1483+
pr_info("vwifi: Station %pM txrate MCS %d, rxrate MCS %d\n", mac,
1484+
sinfo->txrate.mcs, sinfo->rxrate.mcs);
1485+
14371486
return 0;
14381487
}
14391488

0 commit comments

Comments
 (0)