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 #include #include #include @@ -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 \n", progname); #endif fprintf(stderr, "\t%s pta_prio \n", progname); - + fprintf(stderr, "\t%s power_save \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; +} +