1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file is part of wlcore
5 * Copyright (C) 2014 Texas Instruments. All rights reserved.
8 #include <linux/pm_runtime.h>
10 #include <net/mac80211.h>
11 #include <net/netlink.h>
16 #include "vendor_cmd.h"
19 struct nla_policy wlcore_vendor_attr_policy[NUM_WLCORE_VENDOR_ATTR] = {
20 [WLCORE_VENDOR_ATTR_FREQ] = { .type = NLA_U32 },
21 [WLCORE_VENDOR_ATTR_GROUP_ID] = { .type = NLA_U32 },
22 [WLCORE_VENDOR_ATTR_GROUP_KEY] = { .type = NLA_BINARY,
23 .len = WLAN_MAX_KEY_LEN },
27 wlcore_vendor_cmd_smart_config_start(struct wiphy *wiphy,
28 struct wireless_dev *wdev,
29 const void *data, int data_len)
31 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
32 struct wl1271 *wl = hw->priv;
33 struct nlattr *tb[NUM_WLCORE_VENDOR_ATTR];
36 wl1271_debug(DEBUG_CMD, "vendor cmd smart config start");
41 ret = nla_parse_deprecated(tb, MAX_WLCORE_VENDOR_ATTR, data, data_len,
42 wlcore_vendor_attr_policy, NULL);
46 if (!tb[WLCORE_VENDOR_ATTR_GROUP_ID])
49 mutex_lock(&wl->mutex);
51 if (unlikely(wl->state != WLCORE_STATE_ON)) {
56 ret = pm_runtime_resume_and_get(wl->dev);
60 ret = wlcore_smart_config_start(wl,
61 nla_get_u32(tb[WLCORE_VENDOR_ATTR_GROUP_ID]));
63 pm_runtime_mark_last_busy(wl->dev);
64 pm_runtime_put_autosuspend(wl->dev);
66 mutex_unlock(&wl->mutex);
72 wlcore_vendor_cmd_smart_config_stop(struct wiphy *wiphy,
73 struct wireless_dev *wdev,
74 const void *data, int data_len)
76 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
77 struct wl1271 *wl = hw->priv;
80 wl1271_debug(DEBUG_CMD, "testmode cmd smart config stop");
82 mutex_lock(&wl->mutex);
84 if (unlikely(wl->state != WLCORE_STATE_ON)) {
89 ret = pm_runtime_resume_and_get(wl->dev);
93 ret = wlcore_smart_config_stop(wl);
95 pm_runtime_mark_last_busy(wl->dev);
96 pm_runtime_put_autosuspend(wl->dev);
98 mutex_unlock(&wl->mutex);
104 wlcore_vendor_cmd_smart_config_set_group_key(struct wiphy *wiphy,
105 struct wireless_dev *wdev,
106 const void *data, int data_len)
108 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
109 struct wl1271 *wl = hw->priv;
110 struct nlattr *tb[NUM_WLCORE_VENDOR_ATTR];
113 wl1271_debug(DEBUG_CMD, "testmode cmd smart config set group key");
118 ret = nla_parse_deprecated(tb, MAX_WLCORE_VENDOR_ATTR, data, data_len,
119 wlcore_vendor_attr_policy, NULL);
123 if (!tb[WLCORE_VENDOR_ATTR_GROUP_ID] ||
124 !tb[WLCORE_VENDOR_ATTR_GROUP_KEY])
127 mutex_lock(&wl->mutex);
129 if (unlikely(wl->state != WLCORE_STATE_ON)) {
134 ret = pm_runtime_resume_and_get(wl->dev);
138 ret = wlcore_smart_config_set_group_key(wl,
139 nla_get_u32(tb[WLCORE_VENDOR_ATTR_GROUP_ID]),
140 nla_len(tb[WLCORE_VENDOR_ATTR_GROUP_KEY]),
141 nla_data(tb[WLCORE_VENDOR_ATTR_GROUP_KEY]));
143 pm_runtime_mark_last_busy(wl->dev);
144 pm_runtime_put_autosuspend(wl->dev);
146 mutex_unlock(&wl->mutex);
151 static const struct wiphy_vendor_command wlcore_vendor_commands[] = {
155 .subcmd = WLCORE_VENDOR_CMD_SMART_CONFIG_START,
157 .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
158 WIPHY_VENDOR_CMD_NEED_RUNNING,
159 .doit = wlcore_vendor_cmd_smart_config_start,
160 .policy = wlcore_vendor_attr_policy,
165 .subcmd = WLCORE_VENDOR_CMD_SMART_CONFIG_STOP,
167 .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
168 WIPHY_VENDOR_CMD_NEED_RUNNING,
169 .doit = wlcore_vendor_cmd_smart_config_stop,
170 .policy = wlcore_vendor_attr_policy,
175 .subcmd = WLCORE_VENDOR_CMD_SMART_CONFIG_SET_GROUP_KEY,
177 .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
178 WIPHY_VENDOR_CMD_NEED_RUNNING,
179 .doit = wlcore_vendor_cmd_smart_config_set_group_key,
180 .policy = wlcore_vendor_attr_policy,
184 static const struct nl80211_vendor_cmd_info wlcore_vendor_events[] = {
187 .subcmd = WLCORE_VENDOR_EVENT_SC_SYNC,
191 .subcmd = WLCORE_VENDOR_EVENT_SC_DECODE,
195 void wlcore_set_vendor_commands(struct wiphy *wiphy)
197 wiphy->vendor_commands = wlcore_vendor_commands;
198 wiphy->n_vendor_commands = ARRAY_SIZE(wlcore_vendor_commands);
199 wiphy->vendor_events = wlcore_vendor_events;
200 wiphy->n_vendor_events = ARRAY_SIZE(wlcore_vendor_events);