1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
9 * Copyright (C) 2018 - 2019 Intel Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * The full GNU General Public License is included in this distribution
21 * in the file called COPYING.
23 * Contact Information:
24 * Intel Linux Wireless <linuxwifi@intel.com>
25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
29 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
30 * Copyright (C) 2018 - 2019 Intel Corporation
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * * Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in
41 * the documentation and/or other materials provided with the
43 * * Neither the name Intel Corporation nor the names of its
44 * contributors may be used to endorse or promote products derived
45 * from this software without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *****************************************************************************/
60 #include <net/cfg80211.h>
61 #include <linux/etherdevice.h>
63 #include "constants.h"
65 static int iwl_mvm_ftm_responder_set_bw_v1(struct cfg80211_chan_def
*chandef
,
66 u8
*bw
, u8
*ctrl_ch_position
)
68 switch (chandef
->width
) {
69 case NL80211_CHAN_WIDTH_20_NOHT
:
70 *bw
= IWL_TOF_BW_20_LEGACY
;
72 case NL80211_CHAN_WIDTH_20
:
73 *bw
= IWL_TOF_BW_20_HT
;
75 case NL80211_CHAN_WIDTH_40
:
77 *ctrl_ch_position
= iwl_mvm_get_ctrl_pos(chandef
);
79 case NL80211_CHAN_WIDTH_80
:
81 *ctrl_ch_position
= iwl_mvm_get_ctrl_pos(chandef
);
90 static int iwl_mvm_ftm_responder_set_bw_v2(struct cfg80211_chan_def
*chandef
,
94 switch (chandef
->width
) {
95 case NL80211_CHAN_WIDTH_20_NOHT
:
96 *format_bw
= IWL_LOCATION_FRAME_FORMAT_LEGACY
;
97 *format_bw
|= IWL_LOCATION_BW_20MHZ
<< LOCATION_BW_POS
;
99 case NL80211_CHAN_WIDTH_20
:
100 *format_bw
= IWL_LOCATION_FRAME_FORMAT_HT
;
101 *format_bw
|= IWL_LOCATION_BW_20MHZ
<< LOCATION_BW_POS
;
103 case NL80211_CHAN_WIDTH_40
:
104 *format_bw
= IWL_LOCATION_FRAME_FORMAT_HT
;
105 *format_bw
|= IWL_LOCATION_BW_40MHZ
<< LOCATION_BW_POS
;
106 *ctrl_ch_position
= iwl_mvm_get_ctrl_pos(chandef
);
108 case NL80211_CHAN_WIDTH_80
:
109 *format_bw
= IWL_LOCATION_FRAME_FORMAT_VHT
;
110 *format_bw
|= IWL_LOCATION_BW_80MHZ
<< LOCATION_BW_POS
;
111 *ctrl_ch_position
= iwl_mvm_get_ctrl_pos(chandef
);
121 iwl_mvm_ftm_responder_cmd(struct iwl_mvm
*mvm
,
122 struct ieee80211_vif
*vif
,
123 struct cfg80211_chan_def
*chandef
)
125 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
127 * The command structure is the same for versions 6 and 7, (only the
128 * field interpretation is different), so the same struct can be use
131 struct iwl_tof_responder_config_cmd cmd
= {
132 .channel_num
= chandef
->chan
->hw_value
,
134 cpu_to_le32(IWL_TOF_RESPONDER_CMD_VALID_CHAN_INFO
|
135 IWL_TOF_RESPONDER_CMD_VALID_BSSID
|
136 IWL_TOF_RESPONDER_CMD_VALID_STA_ID
),
137 .sta_id
= mvmvif
->bcast_sta
.sta_id
,
139 u8 cmd_ver
= iwl_mvm_lookup_cmd_ver(mvm
->fw
, LOCATION_GROUP
,
140 TOF_RESPONDER_CONFIG_CMD
);
143 lockdep_assert_held(&mvm
->mutex
);
146 err
= iwl_mvm_ftm_responder_set_bw_v2(chandef
, &cmd
.format_bw
,
147 &cmd
.ctrl_ch_position
);
149 err
= iwl_mvm_ftm_responder_set_bw_v1(chandef
, &cmd
.format_bw
,
150 &cmd
.ctrl_ch_position
);
153 IWL_ERR(mvm
, "Failed to set responder bandwidth\n");
157 memcpy(cmd
.bssid
, vif
->addr
, ETH_ALEN
);
159 return iwl_mvm_send_cmd_pdu(mvm
, iwl_cmd_id(TOF_RESPONDER_CONFIG_CMD
,
161 0, sizeof(cmd
), &cmd
);
165 iwl_mvm_ftm_responder_dyn_cfg_cmd(struct iwl_mvm
*mvm
,
166 struct ieee80211_vif
*vif
,
167 struct ieee80211_ftm_responder_params
*params
)
169 struct iwl_tof_responder_dyn_config_cmd cmd
= {
170 .lci_len
= cpu_to_le32(params
->lci_len
+ 2),
171 .civic_len
= cpu_to_le32(params
->civicloc_len
+ 2),
173 u8 data
[IWL_LCI_CIVIC_IE_MAX_SIZE
] = {0};
174 struct iwl_host_cmd hcmd
= {
175 .id
= iwl_cmd_id(TOF_RESPONDER_DYN_CONFIG_CMD
,
178 .len
[0] = sizeof(cmd
),
180 /* .len[1] set later */
181 /* may not be able to DMA from stack */
182 .dataflags
[1] = IWL_HCMD_DFL_DUP
,
184 u32 aligned_lci_len
= ALIGN(params
->lci_len
+ 2, 4);
185 u32 aligned_civicloc_len
= ALIGN(params
->civicloc_len
+ 2, 4);
188 lockdep_assert_held(&mvm
->mutex
);
190 if (aligned_lci_len
+ aligned_civicloc_len
> sizeof(data
)) {
191 IWL_ERR(mvm
, "LCI/civicloc data too big (%zd + %zd)\n",
192 params
->lci_len
, params
->civicloc_len
);
196 pos
[0] = WLAN_EID_MEASURE_REPORT
;
197 pos
[1] = params
->lci_len
;
198 memcpy(pos
+ 2, params
->lci
, params
->lci_len
);
200 pos
+= aligned_lci_len
;
201 pos
[0] = WLAN_EID_MEASURE_REPORT
;
202 pos
[1] = params
->civicloc_len
;
203 memcpy(pos
+ 2, params
->civicloc
, params
->civicloc_len
);
205 hcmd
.len
[1] = aligned_lci_len
+ aligned_civicloc_len
;
207 return iwl_mvm_send_cmd(mvm
, &hcmd
);
210 int iwl_mvm_ftm_start_responder(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
212 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
213 struct ieee80211_ftm_responder_params
*params
;
214 struct ieee80211_chanctx_conf ctx
, *pctx
;
216 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
219 params
= vif
->bss_conf
.ftmr_params
;
221 lockdep_assert_held(&mvm
->mutex
);
223 if (WARN_ON_ONCE(!vif
->bss_conf
.ftm_responder
))
226 if (vif
->p2p
|| vif
->type
!= NL80211_IFTYPE_AP
||
227 !mvmvif
->ap_ibss_active
) {
228 IWL_ERR(mvm
, "Cannot start responder, not in AP mode\n");
233 pctx
= rcu_dereference(vif
->chanctx_conf
);
234 /* Copy the ctx to unlock the rcu and send the phy ctxt. We don't care
235 * about changes in the ctx after releasing the lock because the driver
236 * is still protected by the mutex. */
238 phy_ctxt_id
= (u16
*)pctx
->drv_priv
;
241 phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
242 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
.def
,
243 ctx
.rx_chains_static
,
244 ctx
.rx_chains_dynamic
);
248 ret
= iwl_mvm_ftm_responder_cmd(mvm
, vif
, &ctx
.def
);
253 ret
= iwl_mvm_ftm_responder_dyn_cfg_cmd(mvm
, vif
, params
);
258 void iwl_mvm_ftm_restart_responder(struct iwl_mvm
*mvm
,
259 struct ieee80211_vif
*vif
)
261 if (!vif
->bss_conf
.ftm_responder
)
264 iwl_mvm_ftm_start_responder(mvm
, vif
);
267 void iwl_mvm_ftm_responder_stats(struct iwl_mvm
*mvm
,
268 struct iwl_rx_cmd_buffer
*rxb
)
270 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
271 struct iwl_ftm_responder_stats
*resp
= (void *)pkt
->data
;
272 struct cfg80211_ftm_responder_stats
*stats
= &mvm
->ftm_resp_stats
;
273 u32 flags
= le32_to_cpu(resp
->flags
);
275 if (resp
->success_ftm
== resp
->ftm_per_burst
)
276 stats
->success_num
++;
277 else if (resp
->success_ftm
>= 2)
278 stats
->partial_num
++;
282 if ((flags
& FTM_RESP_STAT_ASAP_REQ
) &&
283 (flags
& FTM_RESP_STAT_ASAP_RESP
))
286 if (flags
& FTM_RESP_STAT_NON_ASAP_RESP
)
287 stats
->non_asap_num
++;
289 stats
->total_duration_ms
+= le32_to_cpu(resp
->duration
) / USEC_PER_MSEC
;
291 if (flags
& FTM_RESP_STAT_TRIGGER_UNKNOWN
)
292 stats
->unknown_triggers_num
++;
294 if (flags
& FTM_RESP_STAT_DUP
)
295 stats
->reschedule_requests_num
++;
297 if (flags
& FTM_RESP_STAT_NON_ASAP_OUT_WIN
)
298 stats
->out_of_window_triggers_num
++;