To make the ps_mode (power_save) control easier, this commit adds a new
module parameter allow_ps_mode and set it false (disallowed) by default.

When this parameter is set to false, changing the power_save mode will
be disallowed like the following:

    $ sudo iw dev mlan0 set power_save on
    command failed: Operation not permitted (-1)

Signed-off-by: Tsuchiya Yuto <kita...@gmail.com>
---
 drivers/net/wireless/marvell/mwifiex/cfg80211.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c 
b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
index a6b9dc6700b14..943bc1e8ceaee 100644
--- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
+++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
@@ -25,6 +25,11 @@
 static char *reg_alpha2;
 module_param(reg_alpha2, charp, 0);
 
+static bool allow_ps_mode;
+module_param(allow_ps_mode, bool, 0644);
+MODULE_PARM_DESC(allow_ps_mode,
+                "allow WiFi power management to be enabled. (default: 
disallowed)");
+
 static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
        {
                .max = MWIFIEX_MAX_BSS_NUM,
@@ -435,6 +440,17 @@ mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
 
        ps_mode = enabled;
 
+       /* Allow ps_mode to be enabled only when allow_ps_mode is true */
+       if (ps_mode && !allow_ps_mode) {
+               mwifiex_dbg(priv->adapter, MSG,
+                           "Enabling ps_mode disallowed by modparam\n");
+
+               /* Return -EPERM to inform userspace tools that setting
+                * power_save to be enabled is not permitted.
+                */
+               return -EPERM;
+       }
+
        return mwifiex_drv_set_power(priv, &ps_mode);
 }
 
-- 
2.29.1

Reply via email to