Skip to content

Add HT MCS table and helper for 802.11n bitrate lookup #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions vwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ struct vwifi_vif {

/* Transmit power */
s32 tx_power;

struct cfg80211_bitrate_mask bitrate_mask;
};

static int station = 2;
Expand All @@ -214,6 +216,27 @@ static struct vwifi_context *vwifi = NULL;

static struct sock *nl_sk = NULL;

struct ht_mcs_entry {
int mcs_index;
int bitrate_20mhz_gi08; // in kbps
int bitrate_20mhz_gi04; // in kbps
};

static const struct ht_mcs_entry ht_mcs_table[32] = {
{0, 6500, 7200}, {1, 13000, 14400}, {2, 19500, 21700},
{3, 26000, 28900}, {4, 39000, 43300}, {5, 52000, 57800},
{6, 58500, 65000}, {7, 65000, 72200}, {8, 13000, 14400},
{9, 26000, 28900}, {10, 39000, 43300}, {11, 52000, 57800},
{12, 78000, 86700}, {13, 104000, 115600}, {14, 117000, 130000},
{15, 130000, 144400}, {16, 19500, 21700}, {17, 39000, 43300},
{18, 58500, 65000}, {19, 78000, 86700}, {20, 117000, 130000},
{21, 156000, 173300}, {22, 175500, 195000}, {23, 195000, 216700},
{24, 26000, 28900}, {25, 52000, 57800}, {26, 78000, 86700},
{27, 104000, 115600}, {28, 156000, 173300}, {29, 208000, 231100},
{30, 234000, 260000}, {31, 260000, 288900},
};


static int denylist_check(char *dest, char *source)
{
if (!vwifi->denylist || !*(vwifi->denylist))
Expand Down Expand Up @@ -702,6 +725,20 @@ static int vwifi_ndo_stop(struct net_device *dev)
return 0;
}

static inline int get_ht_bitrate_kbps(const struct vwifi_vif *vif,
int mcs_index)
{
enum nl80211_txrate_gi gi = vif->bitrate_mask.control[NL80211_BAND_2GHZ].gi;

if (mcs_index < 0 || mcs_index >= 32)
return 0; // fallback for invalid index

if (gi == NL80211_TXRATE_FORCE_SGI)
return ht_mcs_table[mcs_index].bitrate_20mhz_gi04;
else
return ht_mcs_table[mcs_index].bitrate_20mhz_gi08;
}

static struct net_device_stats *vwifi_ndo_get_stats(struct net_device *dev)
{
struct vwifi_vif *vif = ndev_get_vwifi_vif(dev);
Expand Down Expand Up @@ -1974,7 +2011,11 @@ static int vwifi_delete_interface(struct vwifi_vif *vif)

cancel_work_sync(&vif->ws_scan);
cancel_work_sync(&vif->ws_scan_timeout);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 84)
timer_delete_sync(&vif->scan_complete);
#else
del_timer_sync(&vif->scan_complete);
#endif

/* If there's a pending scan, call cfg80211_scan_done to finish it. */
if (vif->scan_request) {
Expand All @@ -1985,7 +2026,11 @@ static int vwifi_delete_interface(struct vwifi_vif *vif)
}

/* Make sure that no work is queued */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 84)
timer_delete_sync(&vif->scan_timeout);
#else
del_timer_sync(&vif->scan_timeout);
#endif
cancel_work_sync(&vif->ws_connect);
cancel_work_sync(&vif->ws_disconnect);

Expand Down