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 /* This function appends 11h info to a buffer while joining an
28 mwifiex_11h_process_infra_join(struct mwifiex_private
*priv
, u8
**buffer
,
29 struct mwifiex_bssdescriptor
*bss_desc
)
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
;
38 if (!buffer
|| !(*buffer
))
41 radio_type
= mwifiex_band_to_radio_type((u8
) bss_desc
->bss_band
);
42 sband
= priv
->wdev
.wiphy
->bands
[radio_type
];
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);
49 *buffer
+= sizeof(*cap
);
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
);
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 */
71 /* Enable or disable the 11h extensions in the firmware */
72 static int mwifiex_11h_activate(struct mwifiex_private
*priv
, bool flag
)
76 return mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_SNMP_MIB
,
77 HostCmd_ACT_GEN_SET
, DOT11H_I
, &enable
, true);
80 /* This functions processes TLV buffer for a pending BSS Join command.
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.
86 void mwifiex_11h_process_join(struct mwifiex_private
*priv
, u8
**buffer
,
87 struct mwifiex_bssdescriptor
*bss_desc
)
89 if (bss_desc
->sensed_11h
) {
90 /* Activate 11h functions in firmware, turns on capability
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
);
97 /* Deactivate 11h functions in the firmware */
98 mwifiex_11h_activate(priv
, false);
99 bss_desc
->cap_info_bitmap
&= ~WLAN_CAPABILITY_SPECTRUM_MGMT
;
103 /* This is DFS CAC work queue function.
104 * This delayed work emits CAC finished event for cfg80211 if
105 * CAC was started earlier.
107 void mwifiex_dfs_cac_work_queue(struct work_struct
*work
)
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
,
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
,
129 /* This function prepares channel report request command to FW for
130 * starting radar detection.
132 int mwifiex_cmd_issue_chan_report_request(struct mwifiex_private
*priv
,
133 struct host_cmd_ds_command
*cmd
,
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
;
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
));
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
);
148 dev_dbg(priv
->adapter
->dev
,
149 "11h: issuing DFS Radar check for channel=%d\n",
150 radar_params
->chandef
->chan
->hw_value
);
155 /* This function is to abort ongoing CAC upon stopping AP operations
158 void mwifiex_abort_cac(struct mwifiex_private
*priv
)
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
);
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.
173 int mwifiex_11h_handle_chanrpt_ready(struct mwifiex_private
*priv
,
176 struct host_cmd_ds_chan_rpt_event
*rpt_event
;
177 struct mwifiex_ie_types_chan_rpt_data
*rpt
;
179 u16 event_len
, tlv_len
;
181 rpt_event
= (void *)(skb
->data
+ sizeof(u32
));
182 event_len
= skb
->len
- (sizeof(struct host_cmd_ds_chan_rpt_event
)+
185 if (le32_to_cpu(rpt_event
->result
) != HostCmd_RESULT_OK
) {
186 dev_err(priv
->adapter
->dev
, "Error in channel report event\n");
190 evt_buf
= (void *)&rpt_event
->tlvbuf
;
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
);
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
,
205 NL80211_RADAR_DETECTED
,
213 evt_buf
+= (tlv_len
+ sizeof(rpt
->header
));
214 event_len
-= (tlv_len
+ sizeof(rpt
->header
));
220 /* Handler for radar detected event from FW.*/
221 int mwifiex_11h_handle_radar_detected(struct mwifiex_private
*priv
,
224 struct mwifiex_radar_det_event
*rdr_event
;
226 rdr_event
= (void *)(skb
->data
+ sizeof(u32
));
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
,
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
);
238 dev_dbg(priv
->adapter
->dev
, "false radar detection event!\n");