]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/net/wireless/mwifiex/11h.c
08c12aece9aed5d8a1619fa38dabed7d9ba1fe95
[mirror_ubuntu-zesty-kernel.git] / drivers / net / wireless / mwifiex / 11h.c
1 /*
2 * Marvell Wireless LAN device driver: 802.11h
3 *
4 * Copyright (C) 2013-2014, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20 #include "main.h"
21 #include "fw.h"
22
23
24 /* This function appends 11h info to a buffer while joining an
25 * infrastructure BSS
26 */
27 static void
28 mwifiex_11h_process_infra_join(struct mwifiex_private *priv, u8 **buffer,
29 struct mwifiex_bssdescriptor *bss_desc)
30 {
31 struct mwifiex_ie_types_header *ie_header;
32 struct mwifiex_ie_types_pwr_capability *cap;
33 struct mwifiex_ie_types_local_pwr_constraint *constraint;
34 struct ieee80211_supported_band *sband;
35 u8 radio_type;
36 int i;
37
38 if (!buffer || !(*buffer))
39 return;
40
41 radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
42 sband = priv->wdev.wiphy->bands[radio_type];
43
44 cap = (struct mwifiex_ie_types_pwr_capability *)*buffer;
45 cap->header.type = cpu_to_le16(WLAN_EID_PWR_CAPABILITY);
46 cap->header.len = cpu_to_le16(2);
47 cap->min_pwr = 0;
48 cap->max_pwr = 0;
49 *buffer += sizeof(*cap);
50
51 constraint = (struct mwifiex_ie_types_local_pwr_constraint *)*buffer;
52 constraint->header.type = cpu_to_le16(WLAN_EID_PWR_CONSTRAINT);
53 constraint->header.len = cpu_to_le16(2);
54 constraint->chan = bss_desc->channel;
55 constraint->constraint = bss_desc->local_constraint;
56 *buffer += sizeof(*constraint);
57
58 ie_header = (struct mwifiex_ie_types_header *)*buffer;
59 ie_header->type = cpu_to_le16(TLV_TYPE_PASSTHROUGH);
60 ie_header->len = cpu_to_le16(2 * sband->n_channels + 2);
61 *buffer += sizeof(*ie_header);
62 *(*buffer)++ = WLAN_EID_SUPPORTED_CHANNELS;
63 *(*buffer)++ = 2 * sband->n_channels;
64 for (i = 0; i < sband->n_channels; i++) {
65 *(*buffer)++ = ieee80211_frequency_to_channel(
66 sband->channels[i].center_freq);
67 *(*buffer)++ = 1; /* one channel in the subband */
68 }
69 }
70
71 /* Enable or disable the 11h extensions in the firmware */
72 static int mwifiex_11h_activate(struct mwifiex_private *priv, bool flag)
73 {
74 u32 enable = flag;
75
76 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
77 HostCmd_ACT_GEN_SET, DOT11H_I, &enable, true);
78 }
79
80 /* This functions processes TLV buffer for a pending BSS Join command.
81 *
82 * Activate 11h functionality in the firmware if the spectrum management
83 * capability bit is found in the network we are joining. Also, necessary
84 * TLVs are set based on requested network's 11h capability.
85 */
86 void mwifiex_11h_process_join(struct mwifiex_private *priv, u8 **buffer,
87 struct mwifiex_bssdescriptor *bss_desc)
88 {
89 if (bss_desc->sensed_11h) {
90 /* Activate 11h functions in firmware, turns on capability
91 * bit
92 */
93 mwifiex_11h_activate(priv, true);
94 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_SPECTRUM_MGMT;
95 mwifiex_11h_process_infra_join(priv, buffer, bss_desc);
96 } else {
97 /* Deactivate 11h functions in the firmware */
98 mwifiex_11h_activate(priv, false);
99 bss_desc->cap_info_bitmap &= ~WLAN_CAPABILITY_SPECTRUM_MGMT;
100 }
101 }
102
103 /* This is DFS CAC work queue function.
104 * This delayed work emits CAC finished event for cfg80211 if
105 * CAC was started earlier.
106 */
107 void mwifiex_dfs_cac_work_queue(struct work_struct *work)
108 {
109 struct cfg80211_chan_def chandef;
110 struct delayed_work *delayed_work =
111 container_of(work, struct delayed_work, work);
112 struct mwifiex_private *priv =
113 container_of(delayed_work, struct mwifiex_private,
114 dfs_cac_work);
115
116 if (WARN_ON(!priv))
117 return;
118
119 chandef = priv->dfs_chandef;
120 if (priv->wdev.cac_started) {
121 dev_dbg(priv->adapter->dev,
122 "CAC timer finished; No radar detected\n");
123 cfg80211_cac_event(priv->netdev, &chandef,
124 NL80211_RADAR_CAC_FINISHED,
125 GFP_KERNEL);
126 }
127 }
128
129 /* This function prepares channel report request command to FW for
130 * starting radar detection.
131 */
132 int mwifiex_cmd_issue_chan_report_request(struct mwifiex_private *priv,
133 struct host_cmd_ds_command *cmd,
134 void *data_buf)
135 {
136 struct host_cmd_ds_chan_rpt_req *cr_req = &cmd->params.chan_rpt_req;
137 struct mwifiex_radar_params *radar_params = (void *)data_buf;
138
139 cmd->command = cpu_to_le16(HostCmd_CMD_CHAN_REPORT_REQUEST);
140 cmd->size = cpu_to_le16(S_DS_GEN);
141 le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_chan_rpt_req));
142
143 cr_req->chan_desc.start_freq = cpu_to_le16(MWIFIEX_A_BAND_START_FREQ);
144 cr_req->chan_desc.chan_num = radar_params->chandef->chan->hw_value;
145 cr_req->chan_desc.chan_width = radar_params->chandef->width;
146 cr_req->msec_dwell_time = cpu_to_le32(radar_params->cac_time_ms);
147
148 dev_dbg(priv->adapter->dev,
149 "11h: issuing DFS Radar check for channel=%d\n",
150 radar_params->chandef->chan->hw_value);
151
152 return 0;
153 }
154
155 /* This function is to abort ongoing CAC upon stopping AP operations
156 * or during unload.
157 */
158 void mwifiex_abort_cac(struct mwifiex_private *priv)
159 {
160 if (priv->wdev.cac_started) {
161 dev_dbg(priv->adapter->dev,
162 "Aborting delayed work for CAC.\n");
163 cancel_delayed_work_sync(&priv->dfs_cac_work);
164 cfg80211_cac_event(priv->netdev, &priv->dfs_chandef,
165 NL80211_RADAR_CAC_ABORTED, GFP_KERNEL);
166 }
167 }
168
169 /* This function handles channel report event from FW during CAC period.
170 * If radar is detected during CAC, driver indicates the same to cfg80211
171 * and also cancels ongoing delayed work.
172 */
173 int mwifiex_11h_handle_chanrpt_ready(struct mwifiex_private *priv,
174 struct sk_buff *skb)
175 {
176 struct host_cmd_ds_chan_rpt_event *rpt_event;
177 struct mwifiex_ie_types_chan_rpt_data *rpt;
178 u8 *evt_buf;
179 u16 event_len, tlv_len;
180
181 rpt_event = (void *)(skb->data + sizeof(u32));
182 event_len = skb->len - (sizeof(struct host_cmd_ds_chan_rpt_event)+
183 sizeof(u32));
184
185 if (le32_to_cpu(rpt_event->result) != HostCmd_RESULT_OK) {
186 dev_err(priv->adapter->dev, "Error in channel report event\n");
187 return -1;
188 }
189
190 evt_buf = (void *)&rpt_event->tlvbuf;
191
192 while (event_len >= sizeof(struct mwifiex_ie_types_header)) {
193 rpt = (void *)&rpt_event->tlvbuf;
194 tlv_len = le16_to_cpu(rpt->header.len);
195
196 switch (le16_to_cpu(rpt->header.type)) {
197 case TLV_TYPE_CHANRPT_11H_BASIC:
198 if (rpt->map.radar) {
199 dev_notice(priv->adapter->dev,
200 "RADAR Detected on channel %d!\n",
201 priv->dfs_chandef.chan->hw_value);
202 cancel_delayed_work_sync(&priv->dfs_cac_work);
203 cfg80211_cac_event(priv->netdev,
204 &priv->dfs_chandef,
205 NL80211_RADAR_DETECTED,
206 GFP_KERNEL);
207 }
208 break;
209 default:
210 break;
211 }
212
213 evt_buf += (tlv_len + sizeof(rpt->header));
214 event_len -= (tlv_len + sizeof(rpt->header));
215 }
216
217 return 0;
218 }
219
220 /* Handler for radar detected event from FW.*/
221 int mwifiex_11h_handle_radar_detected(struct mwifiex_private *priv,
222 struct sk_buff *skb)
223 {
224 struct mwifiex_radar_det_event *rdr_event;
225
226 rdr_event = (void *)(skb->data + sizeof(u32));
227
228 if (le32_to_cpu(rdr_event->passed)) {
229 dev_notice(priv->adapter->dev,
230 "radar detected; indicating kernel\n");
231 cfg80211_radar_event(priv->adapter->wiphy, &priv->dfs_chandef,
232 GFP_KERNEL);
233 dev_dbg(priv->adapter->dev, "regdomain: %d\n",
234 rdr_event->reg_domain);
235 dev_dbg(priv->adapter->dev, "radar detection type: %d\n",
236 rdr_event->det_type);
237 } else {
238 dev_dbg(priv->adapter->dev, "false radar detection event!\n");
239 }
240
241 return 0;
242 }