mwifiex: Fix NL80211_TX_POWER_LIMITED
authorAdrian Bunk <bunk@kernel.org>
Wed, 13 Feb 2019 13:59:38 +0000 (15:59 +0200)
committerKalle Valo <kvalo@codeaurora.org>
Tue, 19 Feb 2019 15:15:10 +0000 (17:15 +0200)
NL80211_TX_POWER_LIMITED was treated as NL80211_TX_POWER_AUTOMATIC,
which is the opposite of what should happen and can cause nasty
regulatory problems.

if/else converted to a switch without default to make gcc warn
on unhandled enum values.

Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/marvell/mwifiex/cfg80211.c
drivers/net/wireless/marvell/mwifiex/ioctl.h
drivers/net/wireless/marvell/mwifiex/sta_ioctl.c

index 1467af22e3944c8eebedb089fcea1afbef6165db..9ef0fc1086419ced38c60367cb615abdece85308 100644 (file)
@@ -376,11 +376,20 @@ mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
        struct mwifiex_power_cfg power_cfg;
        int dbm = MBM_TO_DBM(mbm);
 
-       if (type == NL80211_TX_POWER_FIXED) {
+       switch (type) {
+       case NL80211_TX_POWER_FIXED:
                power_cfg.is_power_auto = 0;
+               power_cfg.is_power_fixed = 1;
                power_cfg.power_level = dbm;
-       } else {
+               break;
+       case NL80211_TX_POWER_LIMITED:
+               power_cfg.is_power_auto = 0;
+               power_cfg.is_power_fixed = 0;
+               power_cfg.power_level = dbm;
+               break;
+       case NL80211_TX_POWER_AUTOMATIC:
                power_cfg.is_power_auto = 1;
+               break;
        }
 
        priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
index 48e154e1865df321e12f4f160d51085d599d8721..0dd592ea6e8332a26829483613c047ad5d77f5aa 100644 (file)
@@ -267,6 +267,7 @@ struct mwifiex_ds_encrypt_key {
 
 struct mwifiex_power_cfg {
        u32 is_power_auto;
+       u32 is_power_fixed;
        u32 power_level;
 };
 
index b454b5f855034be5667985b4037aeb86ff68dea8..ebc0e41e5d3b533e24868dd9dbce6027ec791e87 100644 (file)
@@ -688,6 +688,9 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
        txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
        txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
        if (!power_cfg->is_power_auto) {
+               u16 dbm_min = power_cfg->is_power_fixed ?
+                             dbm : priv->min_tx_power_level;
+
                txp_cfg->mode = cpu_to_le32(1);
                pg_tlv = (struct mwifiex_types_power_group *)
                         (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
@@ -702,7 +705,7 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
                pg->last_rate_code = 0x03;
                pg->modulation_class = MOD_CLASS_HR_DSSS;
                pg->power_step = 0;
-               pg->power_min = (s8) dbm;
+               pg->power_min = (s8) dbm_min;
                pg->power_max = (s8) dbm;
                pg++;
                /* Power group for modulation class OFDM */
@@ -710,7 +713,7 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
                pg->last_rate_code = 0x07;
                pg->modulation_class = MOD_CLASS_OFDM;
                pg->power_step = 0;
-               pg->power_min = (s8) dbm;
+               pg->power_min = (s8) dbm_min;
                pg->power_max = (s8) dbm;
                pg++;
                /* Power group for modulation class HTBW20 */
@@ -718,7 +721,7 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
                pg->last_rate_code = 0x20;
                pg->modulation_class = MOD_CLASS_HT;
                pg->power_step = 0;
-               pg->power_min = (s8) dbm;
+               pg->power_min = (s8) dbm_min;
                pg->power_max = (s8) dbm;
                pg->ht_bandwidth = HT_BW_20;
                pg++;
@@ -727,7 +730,7 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
                pg->last_rate_code = 0x20;
                pg->modulation_class = MOD_CLASS_HT;
                pg->power_step = 0;
-               pg->power_min = (s8) dbm;
+               pg->power_min = (s8) dbm_min;
                pg->power_max = (s8) dbm;
                pg->ht_bandwidth = HT_BW_40;
        }