You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2024/09/12 04:43:59 UTC
(nuttx-apps) 02/03: [wireless][wapi] add powersave cmd of wapi for Low-power modules
This is an automated email from the ASF dual-hosted git repository.
archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit cf7491a1fe01afe1c135fa13584939fe06fc55c2
Author: meijian <me...@xiaomi.com>
AuthorDate: Thu Nov 16 14:29:13 2023 +0800
[wireless][wapi] add powersave cmd of wapi for Low-power modules
Signed-off-by: meijian <me...@xiaomi.com>
---
include/wireless/wapi.h | 21 ++++++++++++++++++
wireless/wapi/src/wapi.c | 29 ++++++++++++++++++++++++-
wireless/wapi/src/wireless.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 100 insertions(+), 1 deletion(-)
diff --git a/include/wireless/wapi.h b/include/wireless/wapi.h
index aa481fe42..e7fa77695 100644
--- a/include/wireless/wapi.h
+++ b/include/wireless/wapi.h
@@ -53,6 +53,7 @@
* Included Files
****************************************************************************/
+#include <stdbool.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <net/ethernet.h>
@@ -973,6 +974,26 @@ int wapi_get_pta_prio(int sock, FAR const char *ifname,
int wapi_extend_params(int sock, int cmd, FAR struct iwreq *wrq);
+/****************************************************************************
+ * Name: wapi_set_power_save
+ *
+ * Description:
+ * Set power save status of wifi.
+ *
+ ****************************************************************************/
+
+int wapi_set_power_save(int sock, FAR const char *ifname, bool on);
+
+/****************************************************************************
+ * Name: wapi_get_power_save
+ *
+ * Description:
+ * Get power save status of wifi.
+ *
+ ****************************************************************************/
+
+int wapi_get_power_save(int sock, FAR const char *ifname, bool *on);
+
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c
index fe65d99f2..a5fb04ce2 100644
--- a/wireless/wapi/src/wapi.c
+++ b/wireless/wapi/src/wapi.c
@@ -105,6 +105,7 @@ static int wapi_reconnect_cmd (int sock, int argc, FAR char **argv);
static int wapi_save_config_cmd (int sock, int argc, FAR char **argv);
#endif
static int wapi_pta_prio_cmd (int sock, int argc, FAR char **argv);
+static int wapi_power_save_cmd (int sock, int argc, FAR char **argv);
/****************************************************************************
* Private Data
@@ -134,6 +135,7 @@ static const struct wapi_command_s g_wapi_commands[] =
{"save_config", 1, 1, wapi_save_config_cmd},
#endif
{"pta_prio", 2, 2, wapi_pta_prio_cmd},
+ {"power_save", 2, 2, wapi_power_save_cmd},
};
/****************************************************************************
@@ -1110,6 +1112,31 @@ static int wapi_pta_prio_cmd(int sock, int argc, FAR char **argv)
return wapi_set_pta_prio(sock, argv[0], pta_prio);
}
+/****************************************************************************
+ * Name: wapi_power_save_cmd
+ *
+ * Description:
+ * Manually configure the power save status.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static int wapi_power_save_cmd(int sock, int argc, FAR char **argv)
+{
+ bool on = false;
+
+ if (strcmp(argv[1], "on") == 0)
+ {
+ on = true;
+ }
+
+ /* Set power save status */
+
+ return wapi_set_power_save(sock, argv[0], on);
+}
+
/****************************************************************************
* Name: wapi_showusage
*
@@ -1154,7 +1181,7 @@ static void wapi_showusage(FAR const char *progname, int exitcode)
fprintf(stderr, "\t%s save_config <ifname>\n", progname);
#endif
fprintf(stderr, "\t%s pta_prio <ifname> <index/flag>\n", progname);
-
+ fprintf(stderr, "\t%s power_save <ifname> <on|off>\n", progname);
fprintf(stderr, "\t%s help\n", progname);
fprintf(stderr, "\nFrequency Flags:\n");
diff --git a/wireless/wapi/src/wireless.c b/wireless/wapi/src/wireless.c
index 36a3b0544..94dc29245 100644
--- a/wireless/wapi/src/wireless.c
+++ b/wireless/wapi/src/wireless.c
@@ -1659,3 +1659,54 @@ int wapi_extend_params(int sock, int cmd, FAR struct iwreq *wrq)
return ret;
}
+/****************************************************************************
+ * Name: wapi_set_power_save
+ *
+ * Description:
+ * Set power save status of wifi.
+ *
+ ****************************************************************************/
+
+int wapi_set_power_save(int sock, FAR const char *ifname, bool on)
+{
+ struct iwreq wrq =
+ {
+ };
+
+ int ret;
+
+ wrq.u.power.flags = on;
+ strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
+ ret = wapi_extend_params(sock, SIOCSIWPWSAVE, &wrq);
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: wapi_get_power_save
+ *
+ * Description:
+ * Get power save status of wifi.
+ *
+ ****************************************************************************/
+
+int wapi_get_power_save(int sock, FAR const char *ifname, bool *on)
+{
+ struct iwreq wrq =
+ {
+ };
+
+ int ret;
+
+ WAPI_VALIDATE_PTR(on);
+
+ strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
+ ret = wapi_extend_params(sock, SIOCGIWPWSAVE, &wrq);
+ if (ret >= 0)
+ {
+ *on = wrq.u.power.flags;
+ }
+
+ return ret;
+}
+