Skip to content

Commit cf7491a

Browse files
Meissi-jiananchao
authored andcommitted
[wireless][wapi] add powersave cmd of wapi for Low-power modules
Signed-off-by: meijian <[email protected]>
1 parent c5541bf commit cf7491a

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

include/wireless/wapi.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
* Included Files
5454
****************************************************************************/
5555

56+
#include <stdbool.h>
5657
#include <netinet/in.h>
5758
#include <sys/socket.h>
5859
#include <net/ethernet.h>
@@ -973,6 +974,26 @@ int wapi_get_pta_prio(int sock, FAR const char *ifname,
973974

974975
int wapi_extend_params(int sock, int cmd, FAR struct iwreq *wrq);
975976

977+
/****************************************************************************
978+
* Name: wapi_set_power_save
979+
*
980+
* Description:
981+
* Set power save status of wifi.
982+
*
983+
****************************************************************************/
984+
985+
int wapi_set_power_save(int sock, FAR const char *ifname, bool on);
986+
987+
/****************************************************************************
988+
* Name: wapi_get_power_save
989+
*
990+
* Description:
991+
* Get power save status of wifi.
992+
*
993+
****************************************************************************/
994+
995+
int wapi_get_power_save(int sock, FAR const char *ifname, bool *on);
996+
976997
#undef EXTERN
977998
#ifdef __cplusplus
978999
}

wireless/wapi/src/wapi.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ static int wapi_reconnect_cmd (int sock, int argc, FAR char **argv);
105105
static int wapi_save_config_cmd (int sock, int argc, FAR char **argv);
106106
#endif
107107
static int wapi_pta_prio_cmd (int sock, int argc, FAR char **argv);
108+
static int wapi_power_save_cmd (int sock, int argc, FAR char **argv);
108109

109110
/****************************************************************************
110111
* Private Data
@@ -134,6 +135,7 @@ static const struct wapi_command_s g_wapi_commands[] =
134135
{"save_config", 1, 1, wapi_save_config_cmd},
135136
#endif
136137
{"pta_prio", 2, 2, wapi_pta_prio_cmd},
138+
{"power_save", 2, 2, wapi_power_save_cmd},
137139
};
138140

139141
/****************************************************************************
@@ -1110,6 +1112,31 @@ static int wapi_pta_prio_cmd(int sock, int argc, FAR char **argv)
11101112
return wapi_set_pta_prio(sock, argv[0], pta_prio);
11111113
}
11121114

1115+
/****************************************************************************
1116+
* Name: wapi_power_save_cmd
1117+
*
1118+
* Description:
1119+
* Manually configure the power save status.
1120+
*
1121+
* Returned Value:
1122+
* None
1123+
*
1124+
****************************************************************************/
1125+
1126+
static int wapi_power_save_cmd(int sock, int argc, FAR char **argv)
1127+
{
1128+
bool on = false;
1129+
1130+
if (strcmp(argv[1], "on") == 0)
1131+
{
1132+
on = true;
1133+
}
1134+
1135+
/* Set power save status */
1136+
1137+
return wapi_set_power_save(sock, argv[0], on);
1138+
}
1139+
11131140
/****************************************************************************
11141141
* Name: wapi_showusage
11151142
*
@@ -1154,7 +1181,7 @@ static void wapi_showusage(FAR const char *progname, int exitcode)
11541181
fprintf(stderr, "\t%s save_config <ifname>\n", progname);
11551182
#endif
11561183
fprintf(stderr, "\t%s pta_prio <ifname> <index/flag>\n", progname);
1157-
1184+
fprintf(stderr, "\t%s power_save <ifname> <on|off>\n", progname);
11581185
fprintf(stderr, "\t%s help\n", progname);
11591186

11601187
fprintf(stderr, "\nFrequency Flags:\n");

wireless/wapi/src/wireless.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,3 +1659,54 @@ int wapi_extend_params(int sock, int cmd, FAR struct iwreq *wrq)
16591659
return ret;
16601660
}
16611661

1662+
/****************************************************************************
1663+
* Name: wapi_set_power_save
1664+
*
1665+
* Description:
1666+
* Set power save status of wifi.
1667+
*
1668+
****************************************************************************/
1669+
1670+
int wapi_set_power_save(int sock, FAR const char *ifname, bool on)
1671+
{
1672+
struct iwreq wrq =
1673+
{
1674+
};
1675+
1676+
int ret;
1677+
1678+
wrq.u.power.flags = on;
1679+
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
1680+
ret = wapi_extend_params(sock, SIOCSIWPWSAVE, &wrq);
1681+
1682+
return ret;
1683+
}
1684+
1685+
/****************************************************************************
1686+
* Name: wapi_get_power_save
1687+
*
1688+
* Description:
1689+
* Get power save status of wifi.
1690+
*
1691+
****************************************************************************/
1692+
1693+
int wapi_get_power_save(int sock, FAR const char *ifname, bool *on)
1694+
{
1695+
struct iwreq wrq =
1696+
{
1697+
};
1698+
1699+
int ret;
1700+
1701+
WAPI_VALIDATE_PTR(on);
1702+
1703+
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
1704+
ret = wapi_extend_params(sock, SIOCGIWPWSAVE, &wrq);
1705+
if (ret >= 0)
1706+
{
1707+
*on = wrq.u.power.flags;
1708+
}
1709+
1710+
return ret;
1711+
}
1712+

0 commit comments

Comments
 (0)