aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2011-11-25 18:19:26 (GMT)
committerJouni Malinen <j@w1.fi>2013-11-24 20:46:38 (GMT)
commit13f2221fc6f53e150c006fd768e989e7e38589bb (patch)
treedd8c007269c66c823aea6cebe1aaba62ff66aec1
parentbabba1ef31f4df73ab5ed00e945923e4e6106a76 (diff)
downloadhostap-13f2221fc6f53e150c006fd768e989e7e38589bb.zip
hostap-13f2221fc6f53e150c006fd768e989e7e38589bb.tar.gz
hostap-13f2221fc6f53e150c006fd768e989e7e38589bb.tar.bz2
Android: nl80211: Add driver_cmd POWERMODE and GETPOWER
-rw-r--r--src/drivers/driver_nl80211.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 258a792..b9b5744 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -10825,6 +10825,64 @@ static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data *drv)
}
+#define WPA_PS_ENABLED 0
+#define WPA_PS_DISABLED 1
+
+static int wpa_driver_set_power_save(void *priv, int state)
+{
+ return nl80211_set_power_save(priv, state == WPA_PS_ENABLED);
+}
+
+
+static int get_power_mode_handler(struct nl_msg *msg, void *arg)
+{
+ struct nlattr *tb[NL80211_ATTR_MAX + 1];
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+ int *state = arg;
+
+ nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL);
+
+ if (!tb[NL80211_ATTR_PS_STATE])
+ return NL_SKIP;
+
+ if (state) {
+ int s = (int) nla_get_u32(tb[NL80211_ATTR_PS_STATE]);
+ wpa_printf(MSG_DEBUG, "nl80211: Get power mode = %d", s);
+ *state = (s == NL80211_PS_ENABLED) ?
+ WPA_PS_ENABLED : WPA_PS_DISABLED;
+ }
+
+ return NL_SKIP;
+}
+
+
+static int wpa_driver_get_power_save(void *priv, int *state)
+{
+ struct i802_bss *bss = priv;
+ struct wpa_driver_nl80211_data *drv = bss->drv;
+ struct nl_msg *msg;
+ int ret = -1;
+ enum nl80211_ps_state ps_state;
+
+ msg = nlmsg_alloc();
+ if (!msg)
+ return -1;
+
+ nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_POWER_SAVE);
+
+ NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
+
+ ret = send_and_recv_msgs(drv, msg, get_power_mode_handler, state);
+ msg = NULL;
+ if (ret < 0)
+ wpa_printf(MSG_ERROR, "nl80211: Get power mode fail: %d", ret);
+nla_put_failure:
+ nlmsg_free(msg);
+ return ret;
+}
+
+
static int android_priv_cmd(struct i802_bss *bss, const char *cmd)
{
struct wpa_driver_nl80211_data *drv = bss->drv;
@@ -10960,6 +11018,19 @@ static int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
MAC2STR(macaddr));
} else if (os_strcasecmp(cmd, "RELOAD") == 0) {
wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED");
+ } else if (os_strncasecmp(cmd, "POWERMODE ", 10) == 0) {
+ int state = atoi(cmd + 10);
+ ret = wpa_driver_set_power_save(priv, state);
+ if (ret < 0)
+ wpa_driver_send_hang_msg(drv);
+ else
+ drv_errors = 0;
+ } else if (os_strncasecmp(cmd, "GETPOWER", 8) == 0) {
+ int state = -1;
+ ret = wpa_driver_get_power_save(priv, &state);
+ if (!ret && (state != -1))
+ ret = os_snprintf(buf, buf_len, "POWERMODE = %d\n",
+ state);
} else {
wpa_printf(MSG_ERROR, "Unsupported command: %s", cmd);
ret = -1;