Skip to content

Commit 9d0a168

Browse files
committed
Maintain command consistency
To maintain command consistency, use command "iw dev [interface] set txpower auto/limit/fixed [transmit power (mBm)]" to set the transmit power. Since using the above command results in the 'wdev' parameter NULL, a new function 'wiphy_get_vwifi_vif' was added to obtain the virtual interface. Additionally, the 'type' parameter is used to distinguish between "auto/limit/fixed" : auto: Use default transmit power limit: Restrict power limits to a specific value fixed: Set power freely
1 parent 0f7cf79 commit 9d0a168

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

scripts/verify.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ if [ $final_ret -eq 0 ]; then
2424
# to avoid device or resource busy error
2525
sleep 0.5
2626

27-
# set transmit power
28-
sudo iwconfig vw0 txpower 11
29-
sudo iwconfig vw1 txpower 12
30-
sudo iwconfig vw2 txpower 13
27+
# set transmit power (mBm)
28+
sudo iw dev vw0 set txpower auto
29+
sudo iw dev vw1 set txpower fixed 1200
30+
sudo iw dev vw2 set txpower fixed 1300
3131

3232
# get phy number of each interface
3333
sudo iw dev > device.log

vwifi.c

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,18 +1843,63 @@ static int vwifi_delete_interface(struct vwifi_vif *vif)
18431843
return 0;
18441844
}
18451845

1846+
static struct vwifi_vif *wiphy_get_vwifi_vif(struct wiphy *wiphy)
1847+
{
1848+
struct wireless_dev *wdev;
1849+
struct vwifi_vif *vif = NULL;
1850+
1851+
list_for_each_entry (wdev, &wiphy->wdev_list, list) {
1852+
vif = container_of(wdev, struct vwifi_vif, wdev);
1853+
break; /* Assuming only one virtual interface is present */
1854+
}
1855+
1856+
return vif;
1857+
}
1858+
18461859
/* Set transmit power for the virtual interface */
18471860
static int vwifi_set_tx_power(struct wiphy *wiphy,
18481861
struct wireless_dev *wdev,
18491862
enum nl80211_tx_power_setting type,
18501863
int mbm)
18511864
{
1852-
struct vwifi_vif *vif = wdev_get_vwifi_vif(wdev);
1865+
struct vwifi_vif *vif = wiphy_get_vwifi_vif(wiphy);
1866+
/* Validate vif pointer */
1867+
if (!vif) {
1868+
pr_info("vwifi_vif is NULL\n");
1869+
return -EINVAL;
1870+
}
1871+
18531872
if (mutex_lock_interruptible(&vif->lock))
18541873
return -ERESTARTSYS;
1855-
/* 1 dBm = 100 mBm */
1856-
vif->tx_power = MBM_TO_DBM(mbm);
1874+
1875+
int power = MBM_TO_DBM(mbm);
1876+
switch (type) {
1877+
case NL80211_TX_POWER_AUTOMATIC:
1878+
/* Use default transmit power (11 dBm) */
1879+
vif->tx_power = 11;
1880+
break;
1881+
1882+
case NL80211_TX_POWER_LIMITED:
1883+
/* Restrict power limits to a specific value (0 ~ 18 dBm) */
1884+
if (power < 0)
1885+
vif->tx_power = 0;
1886+
else if (power > 18)
1887+
vif->tx_power = 18;
1888+
else
1889+
vif->tx_power = power;
1890+
break;
1891+
1892+
case NL80211_TX_POWER_FIXED:
1893+
/* Set power freely */
1894+
vif->tx_power = power;
1895+
break;
1896+
1897+
default:
1898+
return -EINVAL; /* Invalid parameter */
1899+
}
1900+
18571901
mutex_unlock(&vif->lock);
1902+
18581903
return 0;
18591904
}
18601905

@@ -1864,6 +1909,11 @@ static int vwifi_get_tx_power(struct wiphy *wiphy,
18641909
int *dbm)
18651910
{
18661911
struct vwifi_vif *vif = wdev_get_vwifi_vif(wdev);
1912+
/* Validate vif pointer */
1913+
if (!vif) {
1914+
pr_info("vwifi_vif is NULL\n");
1915+
return -EINVAL;
1916+
}
18671917
*dbm = vif->tx_power;
18681918
return 0;
18691919
}

0 commit comments

Comments
 (0)