sysprog21 / vwifi

A virtual wireless device driver for Linux
MIT License
203 stars 39 forks source link

Support transmit power #68

Closed jychen0611 closed 3 months ago

jychen0611 commented 3 months ago

Add tx_power to the virtual interface to describe the device's transmit power.

Implement vwifi_set_tx_power and vwifi_get_tx_power to correspond to set_tx_power and get_tx_power in cfg80211_ops, respectively. vwifi_set_tx_power can set the device's transmit power, while vwifi_get_tx_power can retrieve the transmit power information.

The transmit power can be set using the iwconfig vwn txpower command.

phy#12
    Interface vw2
        ifindex 14
        wdev 0xc00000001
        addr 00:76:77:32:00:00
        type managed
        txpower 13.00 dBm
phy#11
    Interface vw1
        ifindex 13
        wdev 0xb00000001
        addr 00:76:77:31:00:00
        type managed
        txpower 12.00 dBm
phy#10
    Interface vw0
        ifindex 12
        wdev 0xa00000001
        addr 00:76:77:30:00:00
        type managed
        txpower 11.00 dBm
jychen0611 commented 3 months ago

In the future, we may be able to introduce device coordinate parameters to calculate the RSSI value in free space in conjunction with transmit power.

jychen0611 commented 3 months ago

Also, you should avoid using "iwconfig," which is deprecated. Use "iw" command for consistency.

See https://dougvitale.wordpress.com/2011/12/21/deprecated-linux-networking-commands-and-their-replacements/#iwconfig

I'm currently facing an problem when using sudo iw dev vw0 set txpower fixed 1000 The wdev is NULL.

[ 1623.934439] wdev: 0000000000000000, vif: 0000000000000000
[ 1623.934447] wdev is NULL

Thus, I tried using wiphy to obtain vif, and it worked. :+1: :+1:

I found that the current set_tx_power function in Linux does not use the wdev parameter either. Could this be related to the changes between iwconfig and iw ?

I found that the function definition didn't use wdev before v3.7.10. In v3.8-rc1, wdev was added to the function definition.

v3.7.10

int (*set_tx_power)(struct wiphy* wiphy, enum nl80211_tx_power_setting type, int mbm);

cfg80211: allow per interface TX power setting

The TX power setting is currently per wiphy (hardware device) but with multi-channel capabilities that doesn't make much sense any more.

Allow drivers (and mac80211) to advertise support for per-interface TX power configuration. When the TX power is configured for the wiphy, the wdev will be NULL and the driver can still handle that, but when a wdev is given the TX power can be set only for that wdev now.

Signed-off-by: Johannes Berg johannes.berg@intel.com

v3.8-rc1

int (*set_tx_power)(struct wiphy* wiphy, struct wireless_dev* wdev, enum nl80211_tx_power_setting type, int mbm);

mwifiex: add a cfg80211 .get_tx_power operation callback

The mwifiex driver implements a cfg80211 .set_tx_power operation handler but doesn't have the inverse .get_tx_power callback.

This not only has the effect that the Tx power can't be reported to user space tools such as iwconfig and iwlist but also that the wireless core prints a warning when a new wiphy is created due an cfg80211 operation being implemented without its counterpart.

After this patch, the Tx power is properly reported to user-space tools: $ iwlist mlan0 txpower mlan0 unknown transmit-power information. Current Tx-Power=13 dBm (19 mW)

jserv commented 3 months ago

If this pull request is ready for reviewing, use git rebase -i to squash and refine the git commit message. Then, request the reviewers via GitHub web page.

jserv commented 3 months ago

Thank @jychen0611 for contributing!