2 * This file is part of wlcore
4 * Copyright (C) 2014 Texas Instruments. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
11 #include <linux/pm_runtime.h>
13 #include <net/mac80211.h>
14 #include <net/netlink.h>
19 #include "vendor_cmd.h"
22 struct nla_policy wlcore_vendor_attr_policy[NUM_WLCORE_VENDOR_ATTR] = {
23 [WLCORE_VENDOR_ATTR_FREQ] = { .type = NLA_U32 },
24 [WLCORE_VENDOR_ATTR_GROUP_ID] = { .type = NLA_U32 },
25 [WLCORE_VENDOR_ATTR_GROUP_KEY] = { .type = NLA_BINARY,
26 .len = WLAN_MAX_KEY_LEN },
30 wlcore_vendor_cmd_smart_config_start(struct wiphy *wiphy,
31 struct wireless_dev *wdev,
32 const void *data, int data_len)
34 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
35 struct wl1271 *wl = hw->priv;
36 struct nlattr *tb[NUM_WLCORE_VENDOR_ATTR];
39 wl1271_debug(DEBUG_CMD, "vendor cmd smart config start");
44 ret = nla_parse(tb, MAX_WLCORE_VENDOR_ATTR, data, data_len,
45 wlcore_vendor_attr_policy, NULL);
49 if (!tb[WLCORE_VENDOR_ATTR_GROUP_ID])
52 mutex_lock(&wl->mutex);
54 if (unlikely(wl->state != WLCORE_STATE_ON)) {
59 ret = pm_runtime_get_sync(wl->dev);
61 pm_runtime_put_noidle(wl->dev);
65 ret = wlcore_smart_config_start(wl,
66 nla_get_u32(tb[WLCORE_VENDOR_ATTR_GROUP_ID]));
68 pm_runtime_mark_last_busy(wl->dev);
69 pm_runtime_put_autosuspend(wl->dev);
71 mutex_unlock(&wl->mutex);
77 wlcore_vendor_cmd_smart_config_stop(struct wiphy *wiphy,
78 struct wireless_dev *wdev,
79 const void *data, int data_len)
81 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
82 struct wl1271 *wl = hw->priv;
85 wl1271_debug(DEBUG_CMD, "testmode cmd smart config stop");
87 mutex_lock(&wl->mutex);
89 if (unlikely(wl->state != WLCORE_STATE_ON)) {
94 ret = pm_runtime_get_sync(wl->dev);
96 pm_runtime_put_noidle(wl->dev);
100 ret = wlcore_smart_config_stop(wl);
102 pm_runtime_mark_last_busy(wl->dev);
103 pm_runtime_put_autosuspend(wl->dev);
105 mutex_unlock(&wl->mutex);
111 wlcore_vendor_cmd_smart_config_set_group_key(struct wiphy *wiphy,
112 struct wireless_dev *wdev,
113 const void *data, int data_len)
115 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
116 struct wl1271 *wl = hw->priv;
117 struct nlattr *tb[NUM_WLCORE_VENDOR_ATTR];
120 wl1271_debug(DEBUG_CMD, "testmode cmd smart config set group key");
125 ret = nla_parse(tb, MAX_WLCORE_VENDOR_ATTR, data, data_len,
126 wlcore_vendor_attr_policy, NULL);
130 if (!tb[WLCORE_VENDOR_ATTR_GROUP_ID] ||
131 !tb[WLCORE_VENDOR_ATTR_GROUP_KEY])
134 mutex_lock(&wl->mutex);
136 if (unlikely(wl->state != WLCORE_STATE_ON)) {
141 ret = pm_runtime_get_sync(wl->dev);
143 pm_runtime_put_noidle(wl->dev);
147 ret = wlcore_smart_config_set_group_key(wl,
148 nla_get_u32(tb[WLCORE_VENDOR_ATTR_GROUP_ID]),
149 nla_len(tb[WLCORE_VENDOR_ATTR_GROUP_KEY]),
150 nla_data(tb[WLCORE_VENDOR_ATTR_GROUP_KEY]));
152 pm_runtime_mark_last_busy(wl->dev);
153 pm_runtime_put_autosuspend(wl->dev);
155 mutex_unlock(&wl->mutex);
160 static const struct wiphy_vendor_command wlcore_vendor_commands[] = {
164 .subcmd = WLCORE_VENDOR_CMD_SMART_CONFIG_START,
166 .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
167 WIPHY_VENDOR_CMD_NEED_RUNNING,
168 .doit = wlcore_vendor_cmd_smart_config_start,
173 .subcmd = WLCORE_VENDOR_CMD_SMART_CONFIG_STOP,
175 .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
176 WIPHY_VENDOR_CMD_NEED_RUNNING,
177 .doit = wlcore_vendor_cmd_smart_config_stop,
182 .subcmd = WLCORE_VENDOR_CMD_SMART_CONFIG_SET_GROUP_KEY,
184 .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
185 WIPHY_VENDOR_CMD_NEED_RUNNING,
186 .doit = wlcore_vendor_cmd_smart_config_set_group_key,
190 static const struct nl80211_vendor_cmd_info wlcore_vendor_events[] = {
193 .subcmd = WLCORE_VENDOR_EVENT_SC_SYNC,
197 .subcmd = WLCORE_VENDOR_EVENT_SC_DECODE,
201 void wlcore_set_vendor_commands(struct wiphy *wiphy)
203 wiphy->vendor_commands = wlcore_vendor_commands;
204 wiphy->n_vendor_commands = ARRAY_SIZE(wlcore_vendor_commands);
205 wiphy->vendor_events = wlcore_vendor_events;
206 wiphy->n_vendor_events = ARRAY_SIZE(wlcore_vendor_events);