2 * Marvell Wireless LAN device driver: 802.11h
4 * Copyright (C) 2013-2014, Marvell International Ltd.
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.
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.
24 void mwifiex_init_11h_params(struct mwifiex_private
*priv
)
26 priv
->state_11h
.is_11h_enabled
= true;
27 priv
->state_11h
.is_11h_active
= false;
30 inline int mwifiex_is_11h_active(struct mwifiex_private
*priv
)
32 return priv
->state_11h
.is_11h_active
;
34 /* This function appends 11h info to a buffer while joining an
38 mwifiex_11h_process_infra_join(struct mwifiex_private
*priv
, u8
**buffer
,
39 struct mwifiex_bssdescriptor
*bss_desc
)
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
;
48 if (!buffer
|| !(*buffer
))
51 radio_type
= mwifiex_band_to_radio_type((u8
) bss_desc
->bss_band
);
52 sband
= priv
->wdev
.wiphy
->bands
[radio_type
];
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);
59 *buffer
+= sizeof(*cap
);
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
);
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; /* one channel in the subband */
81 /* Enable or disable the 11h extensions in the firmware */
82 int mwifiex_11h_activate(struct mwifiex_private
*priv
, bool flag
)
86 /* enable master mode radar detection on AP interface */
87 if ((GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
) && enable
)
88 enable
|= MWIFIEX_MASTER_RADAR_DET_MASK
;
90 return mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_SNMP_MIB
,
91 HostCmd_ACT_GEN_SET
, DOT11H_I
, &enable
, true);
94 /* This functions processes TLV buffer for a pending BSS Join command.
96 * Activate 11h functionality in the firmware if the spectrum management
97 * capability bit is found in the network we are joining. Also, necessary
98 * TLVs are set based on requested network's 11h capability.
100 void mwifiex_11h_process_join(struct mwifiex_private
*priv
, u8
**buffer
,
101 struct mwifiex_bssdescriptor
*bss_desc
)
103 if (bss_desc
->sensed_11h
) {
104 /* Activate 11h functions in firmware, turns on capability
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
);
112 /* Deactivate 11h functions in the firmware */
113 mwifiex_11h_activate(priv
, false);
114 priv
->state_11h
.is_11h_active
= false;
115 bss_desc
->cap_info_bitmap
&= ~WLAN_CAPABILITY_SPECTRUM_MGMT
;
119 /* This is DFS CAC work queue function.
120 * This delayed work emits CAC finished event for cfg80211 if
121 * CAC was started earlier.
123 void mwifiex_dfs_cac_work_queue(struct work_struct
*work
)
125 struct cfg80211_chan_def chandef
;
126 struct delayed_work
*delayed_work
=
127 container_of(work
, struct delayed_work
, work
);
128 struct mwifiex_private
*priv
=
129 container_of(delayed_work
, struct mwifiex_private
,
135 chandef
= priv
->dfs_chandef
;
136 if (priv
->wdev
.cac_started
) {
137 mwifiex_dbg(priv
->adapter
, MSG
,
138 "CAC timer finished; No radar detected\n");
139 cfg80211_cac_event(priv
->netdev
, &chandef
,
140 NL80211_RADAR_CAC_FINISHED
,
145 /* This function prepares channel report request command to FW for
146 * starting radar detection.
148 int mwifiex_cmd_issue_chan_report_request(struct mwifiex_private
*priv
,
149 struct host_cmd_ds_command
*cmd
,
152 struct host_cmd_ds_chan_rpt_req
*cr_req
= &cmd
->params
.chan_rpt_req
;
153 struct mwifiex_radar_params
*radar_params
= (void *)data_buf
;
155 cmd
->command
= cpu_to_le16(HostCmd_CMD_CHAN_REPORT_REQUEST
);
156 cmd
->size
= cpu_to_le16(S_DS_GEN
);
157 le16_add_cpu(&cmd
->size
, sizeof(struct host_cmd_ds_chan_rpt_req
));
159 cr_req
->chan_desc
.start_freq
= cpu_to_le16(MWIFIEX_A_BAND_START_FREQ
);
160 cr_req
->chan_desc
.chan_num
= radar_params
->chandef
->chan
->hw_value
;
161 cr_req
->chan_desc
.chan_width
= radar_params
->chandef
->width
;
162 cr_req
->msec_dwell_time
= cpu_to_le32(radar_params
->cac_time_ms
);
164 if (radar_params
->cac_time_ms
)
165 mwifiex_dbg(priv
->adapter
, MSG
,
166 "11h: issuing DFS Radar check for channel=%d\n",
167 radar_params
->chandef
->chan
->hw_value
);
169 mwifiex_dbg(priv
->adapter
, MSG
, "cancelling CAC\n");
174 int mwifiex_stop_radar_detection(struct mwifiex_private
*priv
,
175 struct cfg80211_chan_def
*chandef
)
177 struct mwifiex_radar_params radar_params
;
179 memset(&radar_params
, 0, sizeof(struct mwifiex_radar_params
));
180 radar_params
.chandef
= chandef
;
181 radar_params
.cac_time_ms
= 0;
183 return mwifiex_send_cmd(priv
, HostCmd_CMD_CHAN_REPORT_REQUEST
,
184 HostCmd_ACT_GEN_SET
, 0, &radar_params
, true);
187 /* This function is to abort ongoing CAC upon stopping AP operations
190 void mwifiex_abort_cac(struct mwifiex_private
*priv
)
192 if (priv
->wdev
.cac_started
) {
193 if (mwifiex_stop_radar_detection(priv
, &priv
->dfs_chandef
))
194 mwifiex_dbg(priv
->adapter
, ERROR
,
195 "failed to stop CAC in FW\n");
196 mwifiex_dbg(priv
->adapter
, MSG
,
197 "Aborting delayed work for CAC.\n");
198 cancel_delayed_work_sync(&priv
->dfs_cac_work
);
199 cfg80211_cac_event(priv
->netdev
, &priv
->dfs_chandef
,
200 NL80211_RADAR_CAC_ABORTED
, GFP_KERNEL
);
204 /* This function handles channel report event from FW during CAC period.
205 * If radar is detected during CAC, driver indicates the same to cfg80211
206 * and also cancels ongoing delayed work.
208 int mwifiex_11h_handle_chanrpt_ready(struct mwifiex_private
*priv
,
211 struct host_cmd_ds_chan_rpt_event
*rpt_event
;
212 struct mwifiex_ie_types_chan_rpt_data
*rpt
;
214 u16 event_len
, tlv_len
;
216 rpt_event
= (void *)(skb
->data
+ sizeof(u32
));
217 event_len
= skb
->len
- (sizeof(struct host_cmd_ds_chan_rpt_event
)+
220 if (le32_to_cpu(rpt_event
->result
) != HostCmd_RESULT_OK
) {
221 mwifiex_dbg(priv
->adapter
, ERROR
,
222 "Error in channel report event\n");
226 evt_buf
= (void *)&rpt_event
->tlvbuf
;
228 while (event_len
>= sizeof(struct mwifiex_ie_types_header
)) {
229 rpt
= (void *)&rpt_event
->tlvbuf
;
230 tlv_len
= le16_to_cpu(rpt
->header
.len
);
232 switch (le16_to_cpu(rpt
->header
.type
)) {
233 case TLV_TYPE_CHANRPT_11H_BASIC
:
234 if (rpt
->map
.radar
) {
235 mwifiex_dbg(priv
->adapter
, MSG
,
236 "RADAR Detected on channel %d!\n",
237 priv
->dfs_chandef
.chan
->hw_value
);
238 cancel_delayed_work_sync(&priv
->dfs_cac_work
);
239 cfg80211_cac_event(priv
->netdev
,
241 NL80211_RADAR_DETECTED
,
249 evt_buf
+= (tlv_len
+ sizeof(rpt
->header
));
250 event_len
-= (tlv_len
+ sizeof(rpt
->header
));
256 /* Handler for radar detected event from FW.*/
257 int mwifiex_11h_handle_radar_detected(struct mwifiex_private
*priv
,
260 struct mwifiex_radar_det_event
*rdr_event
;
262 rdr_event
= (void *)(skb
->data
+ sizeof(u32
));
264 if (le32_to_cpu(rdr_event
->passed
)) {
265 mwifiex_dbg(priv
->adapter
, MSG
,
266 "radar detected; indicating kernel\n");
267 if (mwifiex_stop_radar_detection(priv
, &priv
->dfs_chandef
))
268 mwifiex_dbg(priv
->adapter
, ERROR
,
269 "Failed to stop CAC in FW\n");
270 cfg80211_radar_event(priv
->adapter
->wiphy
, &priv
->dfs_chandef
,
272 mwifiex_dbg(priv
->adapter
, MSG
, "regdomain: %d\n",
273 rdr_event
->reg_domain
);
274 mwifiex_dbg(priv
->adapter
, MSG
, "radar detection type: %d\n",
275 rdr_event
->det_type
);
277 mwifiex_dbg(priv
->adapter
, MSG
,
278 "false radar detection event!\n");
284 /* This is work queue function for channel switch handling.
285 * This function takes care of updating new channel definitin to
286 * bss config structure, restart AP and indicate channel switch success
289 void mwifiex_dfs_chan_sw_work_queue(struct work_struct
*work
)
291 struct mwifiex_uap_bss_param
*bss_cfg
;
292 struct delayed_work
*delayed_work
=
293 container_of(work
, struct delayed_work
, work
);
294 struct mwifiex_private
*priv
=
295 container_of(delayed_work
, struct mwifiex_private
,
301 bss_cfg
= &priv
->bss_cfg
;
302 if (!bss_cfg
->beacon_period
) {
303 mwifiex_dbg(priv
->adapter
, ERROR
,
304 "channel switch: AP already stopped\n");
308 mwifiex_uap_set_channel(priv
, bss_cfg
, priv
->dfs_chandef
);
310 if (mwifiex_config_start_uap(priv
, bss_cfg
)) {
311 mwifiex_dbg(priv
->adapter
, ERROR
,
312 "Failed to start AP after channel switch\n");
316 mwifiex_dbg(priv
->adapter
, MSG
,
317 "indicating channel switch completion to kernel\n");
318 cfg80211_ch_switch_notify(priv
->netdev
, &priv
->dfs_chandef
);