1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "main.h"
21#include "fw.h"
22
23
24void mwifiex_init_11h_params(struct mwifiex_private *priv)
25{
26 priv->state_11h.is_11h_enabled = true;
27 priv->state_11h.is_11h_active = false;
28}
29
30inline int mwifiex_is_11h_active(struct mwifiex_private *priv)
31{
32 return priv->state_11h.is_11h_active;
33}
34
35
36
37static void
38mwifiex_11h_process_infra_join(struct mwifiex_private *priv, u8 **buffer,
39 struct mwifiex_bssdescriptor *bss_desc)
40{
41 struct mwifiex_ie_types_header *ie_header;
42 struct mwifiex_ie_types_pwr_capability *cap;
43 struct mwifiex_ie_types_local_pwr_constraint *constraint;
44 struct ieee80211_supported_band *sband;
45 u8 radio_type;
46 int i;
47
48 if (!buffer || !(*buffer))
49 return;
50
51 radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
52 sband = priv->wdev.wiphy->bands[radio_type];
53
54 cap = (struct mwifiex_ie_types_pwr_capability *)*buffer;
55 cap->header.type = cpu_to_le16(WLAN_EID_PWR_CAPABILITY);
56 cap->header.len = cpu_to_le16(2);
57 cap->min_pwr = 0;
58 cap->max_pwr = 0;
59 *buffer += sizeof(*cap);
60
61 constraint = (struct mwifiex_ie_types_local_pwr_constraint *)*buffer;
62 constraint->header.type = cpu_to_le16(WLAN_EID_PWR_CONSTRAINT);
63 constraint->header.len = cpu_to_le16(2);
64 constraint->chan = bss_desc->channel;
65 constraint->constraint = bss_desc->local_constraint;
66 *buffer += sizeof(*constraint);
67
68 ie_header = (struct mwifiex_ie_types_header *)*buffer;
69 ie_header->type = cpu_to_le16(TLV_TYPE_PASSTHROUGH);
70 ie_header->len = cpu_to_le16(2 * sband->n_channels + 2);
71 *buffer += sizeof(*ie_header);
72 *(*buffer)++ = WLAN_EID_SUPPORTED_CHANNELS;
73 *(*buffer)++ = 2 * sband->n_channels;
74 for (i = 0; i < sband->n_channels; i++) {
75 *(*buffer)++ = ieee80211_frequency_to_channel(
76 sband->channels[i].center_freq);
77 *(*buffer)++ = 1;
78 }
79}
80
81
82int mwifiex_11h_activate(struct mwifiex_private *priv, bool flag)
83{
84 u32 enable = flag;
85
86
87 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) && enable)
88 enable |= MWIFIEX_MASTER_RADAR_DET_MASK;
89
90 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
91 HostCmd_ACT_GEN_SET, DOT11H_I, &enable, true);
92}
93
94
95
96
97
98
99
100void mwifiex_11h_process_join(struct mwifiex_private *priv, u8 **buffer,
101 struct mwifiex_bssdescriptor *bss_desc)
102{
103 if (bss_desc->sensed_11h) {
104
105
106
107 mwifiex_11h_activate(priv, true);
108 priv->state_11h.is_11h_active = true;
109 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_SPECTRUM_MGMT;
110 mwifiex_11h_process_infra_join(priv, buffer, bss_desc);
111 } else {
112
113 mwifiex_11h_activate(priv, false);
114 priv->state_11h.is_11h_active = false;
115 bss_desc->cap_info_bitmap &= ~WLAN_CAPABILITY_SPECTRUM_MGMT;
116 }
117}
118
119
120
121
122
123void mwifiex_dfs_cac_work_queue(struct work_struct *work)
124{
125 struct cfg80211_chan_def chandef;
126 struct delayed_work *delayed_work = to_delayed_work(work);
127 struct mwifiex_private *priv =
128 container_of(delayed_work, struct mwifiex_private,
129 dfs_cac_work);
130
131 if (WARN_ON(!priv))
132 return;
133
134 chandef = priv->dfs_chandef;
135 if (priv->wdev.cac_started) {
136 mwifiex_dbg(priv->adapter, MSG,
137 "CAC timer finished; No radar detected\n");
138 cfg80211_cac_event(priv->netdev, &chandef,
139 NL80211_RADAR_CAC_FINISHED,
140 GFP_KERNEL);
141 }
142}
143
144
145
146
147int mwifiex_cmd_issue_chan_report_request(struct mwifiex_private *priv,
148 struct host_cmd_ds_command *cmd,
149 void *data_buf)
150{
151 struct host_cmd_ds_chan_rpt_req *cr_req = &cmd->params.chan_rpt_req;
152 struct mwifiex_radar_params *radar_params = (void *)data_buf;
153
154 cmd->command = cpu_to_le16(HostCmd_CMD_CHAN_REPORT_REQUEST);
155 cmd->size = cpu_to_le16(S_DS_GEN);
156 le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_chan_rpt_req));
157
158 cr_req->chan_desc.start_freq = cpu_to_le16(MWIFIEX_A_BAND_START_FREQ);
159 cr_req->chan_desc.chan_num = radar_params->chandef->chan->hw_value;
160 cr_req->chan_desc.chan_width = radar_params->chandef->width;
161 cr_req->msec_dwell_time = cpu_to_le32(radar_params->cac_time_ms);
162
163 if (radar_params->cac_time_ms)
164 mwifiex_dbg(priv->adapter, MSG,
165 "11h: issuing DFS Radar check for channel=%d\n",
166 radar_params->chandef->chan->hw_value);
167 else
168 mwifiex_dbg(priv->adapter, MSG, "cancelling CAC\n");
169
170 return 0;
171}
172
173int mwifiex_stop_radar_detection(struct mwifiex_private *priv,
174 struct cfg80211_chan_def *chandef)
175{
176 struct mwifiex_radar_params radar_params;
177
178 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
179 radar_params.chandef = chandef;
180 radar_params.cac_time_ms = 0;
181
182 return mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
183 HostCmd_ACT_GEN_SET, 0, &radar_params, true);
184}
185
186
187
188
189void mwifiex_abort_cac(struct mwifiex_private *priv)
190{
191 if (priv->wdev.cac_started) {
192 if (mwifiex_stop_radar_detection(priv, &priv->dfs_chandef))
193 mwifiex_dbg(priv->adapter, ERROR,
194 "failed to stop CAC in FW\n");
195 mwifiex_dbg(priv->adapter, MSG,
196 "Aborting delayed work for CAC.\n");
197 cancel_delayed_work_sync(&priv->dfs_cac_work);
198 cfg80211_cac_event(priv->netdev, &priv->dfs_chandef,
199 NL80211_RADAR_CAC_ABORTED, GFP_KERNEL);
200 }
201}
202
203
204
205
206
207int mwifiex_11h_handle_chanrpt_ready(struct mwifiex_private *priv,
208 struct sk_buff *skb)
209{
210 struct host_cmd_ds_chan_rpt_event *rpt_event;
211 struct mwifiex_ie_types_chan_rpt_data *rpt;
212 u8 *evt_buf;
213 u16 event_len, tlv_len;
214
215 rpt_event = (void *)(skb->data + sizeof(u32));
216 event_len = skb->len - (sizeof(struct host_cmd_ds_chan_rpt_event)+
217 sizeof(u32));
218
219 if (le32_to_cpu(rpt_event->result) != HostCmd_RESULT_OK) {
220 mwifiex_dbg(priv->adapter, ERROR,
221 "Error in channel report event\n");
222 return -1;
223 }
224
225 evt_buf = (void *)&rpt_event->tlvbuf;
226
227 while (event_len >= sizeof(struct mwifiex_ie_types_header)) {
228 rpt = (void *)&rpt_event->tlvbuf;
229 tlv_len = le16_to_cpu(rpt->header.len);
230
231 switch (le16_to_cpu(rpt->header.type)) {
232 case TLV_TYPE_CHANRPT_11H_BASIC:
233 if (rpt->map.radar) {
234 mwifiex_dbg(priv->adapter, MSG,
235 "RADAR Detected on channel %d!\n",
236 priv->dfs_chandef.chan->hw_value);
237 cancel_delayed_work_sync(&priv->dfs_cac_work);
238 cfg80211_cac_event(priv->netdev,
239 &priv->dfs_chandef,
240 NL80211_RADAR_DETECTED,
241 GFP_KERNEL);
242 }
243 break;
244 default:
245 break;
246 }
247
248 evt_buf += (tlv_len + sizeof(rpt->header));
249 event_len -= (tlv_len + sizeof(rpt->header));
250 }
251
252 return 0;
253}
254
255
256int mwifiex_11h_handle_radar_detected(struct mwifiex_private *priv,
257 struct sk_buff *skb)
258{
259 struct mwifiex_radar_det_event *rdr_event;
260
261 rdr_event = (void *)(skb->data + sizeof(u32));
262
263 mwifiex_dbg(priv->adapter, MSG,
264 "radar detected; indicating kernel\n");
265 if (mwifiex_stop_radar_detection(priv, &priv->dfs_chandef))
266 mwifiex_dbg(priv->adapter, ERROR,
267 "Failed to stop CAC in FW\n");
268 cfg80211_radar_event(priv->adapter->wiphy, &priv->dfs_chandef,
269 GFP_KERNEL);
270 mwifiex_dbg(priv->adapter, MSG, "regdomain: %d\n",
271 rdr_event->reg_domain);
272 mwifiex_dbg(priv->adapter, MSG, "radar detection type: %d\n",
273 rdr_event->det_type);
274
275 return 0;
276}
277
278
279
280
281
282
283void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
284{
285 struct mwifiex_uap_bss_param *bss_cfg;
286 struct delayed_work *delayed_work = to_delayed_work(work);
287 struct mwifiex_private *priv =
288 container_of(delayed_work, struct mwifiex_private,
289 dfs_chan_sw_work);
290
291 if (WARN_ON(!priv))
292 return;
293
294 bss_cfg = &priv->bss_cfg;
295 if (!bss_cfg->beacon_period) {
296 mwifiex_dbg(priv->adapter, ERROR,
297 "channel switch: AP already stopped\n");
298 return;
299 }
300
301 mwifiex_uap_set_channel(priv, bss_cfg, priv->dfs_chandef);
302
303 if (mwifiex_config_start_uap(priv, bss_cfg)) {
304 mwifiex_dbg(priv->adapter, ERROR,
305 "Failed to start AP after channel switch\n");
306 return;
307 }
308
309 mwifiex_dbg(priv->adapter, MSG,
310 "indicating channel switch completion to kernel\n");
311 cfg80211_ch_switch_notify(priv->netdev, &priv->dfs_chandef);
312}
313