18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2018 - 2019 Intel Corporation 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#ifndef __PMSR_H 68c2ecf20Sopenharmony_ci#define __PMSR_H 78c2ecf20Sopenharmony_ci#include <net/cfg80211.h> 88c2ecf20Sopenharmony_ci#include "core.h" 98c2ecf20Sopenharmony_ci#include "nl80211.h" 108c2ecf20Sopenharmony_ci#include "rdev-ops.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistatic int pmsr_parse_ftm(struct cfg80211_registered_device *rdev, 138c2ecf20Sopenharmony_ci struct nlattr *ftmreq, 148c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request_peer *out, 158c2ecf20Sopenharmony_ci struct genl_info *info) 168c2ecf20Sopenharmony_ci{ 178c2ecf20Sopenharmony_ci const struct cfg80211_pmsr_capabilities *capa = rdev->wiphy.pmsr_capa; 188c2ecf20Sopenharmony_ci struct nlattr *tb[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1]; 198c2ecf20Sopenharmony_ci u32 preamble = NL80211_PREAMBLE_DMG; /* only optional in DMG */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci /* validate existing data */ 228c2ecf20Sopenharmony_ci if (!(rdev->wiphy.pmsr_capa->ftm.bandwidths & BIT(out->chandef.width))) { 238c2ecf20Sopenharmony_ci NL_SET_ERR_MSG(info->extack, "FTM: unsupported bandwidth"); 248c2ecf20Sopenharmony_ci return -EINVAL; 258c2ecf20Sopenharmony_ci } 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci /* no validation needed - was already done via nested policy */ 288c2ecf20Sopenharmony_ci nla_parse_nested_deprecated(tb, NL80211_PMSR_FTM_REQ_ATTR_MAX, ftmreq, 298c2ecf20Sopenharmony_ci NULL, NULL); 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci if (tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE]) 328c2ecf20Sopenharmony_ci preamble = nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE]); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci /* set up values - struct is 0-initialized */ 358c2ecf20Sopenharmony_ci out->ftm.requested = true; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci switch (out->chandef.chan->band) { 388c2ecf20Sopenharmony_ci case NL80211_BAND_60GHZ: 398c2ecf20Sopenharmony_ci /* optional */ 408c2ecf20Sopenharmony_ci break; 418c2ecf20Sopenharmony_ci default: 428c2ecf20Sopenharmony_ci if (!tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE]) { 438c2ecf20Sopenharmony_ci NL_SET_ERR_MSG(info->extack, 448c2ecf20Sopenharmony_ci "FTM: must specify preamble"); 458c2ecf20Sopenharmony_ci return -EINVAL; 468c2ecf20Sopenharmony_ci } 478c2ecf20Sopenharmony_ci } 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci if (!(capa->ftm.preambles & BIT(preamble))) { 508c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 518c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE], 528c2ecf20Sopenharmony_ci "FTM: invalid preamble"); 538c2ecf20Sopenharmony_ci return -EINVAL; 548c2ecf20Sopenharmony_ci } 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci out->ftm.preamble = preamble; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci out->ftm.burst_period = 0; 598c2ecf20Sopenharmony_ci if (tb[NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD]) 608c2ecf20Sopenharmony_ci out->ftm.burst_period = 618c2ecf20Sopenharmony_ci nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD]); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci out->ftm.asap = !!tb[NL80211_PMSR_FTM_REQ_ATTR_ASAP]; 648c2ecf20Sopenharmony_ci if (out->ftm.asap && !capa->ftm.asap) { 658c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 668c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_ASAP], 678c2ecf20Sopenharmony_ci "FTM: ASAP mode not supported"); 688c2ecf20Sopenharmony_ci return -EINVAL; 698c2ecf20Sopenharmony_ci } 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci if (!out->ftm.asap && !capa->ftm.non_asap) { 728c2ecf20Sopenharmony_ci NL_SET_ERR_MSG(info->extack, 738c2ecf20Sopenharmony_ci "FTM: non-ASAP mode not supported"); 748c2ecf20Sopenharmony_ci return -EINVAL; 758c2ecf20Sopenharmony_ci } 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci out->ftm.num_bursts_exp = 0; 788c2ecf20Sopenharmony_ci if (tb[NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP]) 798c2ecf20Sopenharmony_ci out->ftm.num_bursts_exp = 808c2ecf20Sopenharmony_ci nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP]); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci if (capa->ftm.max_bursts_exponent >= 0 && 838c2ecf20Sopenharmony_ci out->ftm.num_bursts_exp > capa->ftm.max_bursts_exponent) { 848c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 858c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP], 868c2ecf20Sopenharmony_ci "FTM: max NUM_BURSTS_EXP must be set lower than the device limit"); 878c2ecf20Sopenharmony_ci return -EINVAL; 888c2ecf20Sopenharmony_ci } 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci out->ftm.burst_duration = 15; 918c2ecf20Sopenharmony_ci if (tb[NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION]) 928c2ecf20Sopenharmony_ci out->ftm.burst_duration = 938c2ecf20Sopenharmony_ci nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION]); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci out->ftm.ftms_per_burst = 0; 968c2ecf20Sopenharmony_ci if (tb[NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST]) 978c2ecf20Sopenharmony_ci out->ftm.ftms_per_burst = 988c2ecf20Sopenharmony_ci nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST]); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci if (capa->ftm.max_ftms_per_burst && 1018c2ecf20Sopenharmony_ci (out->ftm.ftms_per_burst > capa->ftm.max_ftms_per_burst || 1028c2ecf20Sopenharmony_ci out->ftm.ftms_per_burst == 0)) { 1038c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 1048c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST], 1058c2ecf20Sopenharmony_ci "FTM: FTMs per burst must be set lower than the device limit but non-zero"); 1068c2ecf20Sopenharmony_ci return -EINVAL; 1078c2ecf20Sopenharmony_ci } 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci out->ftm.ftmr_retries = 3; 1108c2ecf20Sopenharmony_ci if (tb[NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES]) 1118c2ecf20Sopenharmony_ci out->ftm.ftmr_retries = 1128c2ecf20Sopenharmony_ci nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES]); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci out->ftm.request_lci = !!tb[NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI]; 1158c2ecf20Sopenharmony_ci if (out->ftm.request_lci && !capa->ftm.request_lci) { 1168c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 1178c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI], 1188c2ecf20Sopenharmony_ci "FTM: LCI request not supported"); 1198c2ecf20Sopenharmony_ci } 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci out->ftm.request_civicloc = 1228c2ecf20Sopenharmony_ci !!tb[NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC]; 1238c2ecf20Sopenharmony_ci if (out->ftm.request_civicloc && !capa->ftm.request_civicloc) { 1248c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 1258c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC], 1268c2ecf20Sopenharmony_ci "FTM: civic location request not supported"); 1278c2ecf20Sopenharmony_ci } 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci out->ftm.trigger_based = 1308c2ecf20Sopenharmony_ci !!tb[NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED]; 1318c2ecf20Sopenharmony_ci if (out->ftm.trigger_based && !capa->ftm.trigger_based) { 1328c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 1338c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED], 1348c2ecf20Sopenharmony_ci "FTM: trigger based ranging is not supported"); 1358c2ecf20Sopenharmony_ci return -EINVAL; 1368c2ecf20Sopenharmony_ci } 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci out->ftm.non_trigger_based = 1398c2ecf20Sopenharmony_ci !!tb[NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED]; 1408c2ecf20Sopenharmony_ci if (out->ftm.non_trigger_based && !capa->ftm.non_trigger_based) { 1418c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 1428c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED], 1438c2ecf20Sopenharmony_ci "FTM: trigger based ranging is not supported"); 1448c2ecf20Sopenharmony_ci return -EINVAL; 1458c2ecf20Sopenharmony_ci } 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci if (out->ftm.trigger_based && out->ftm.non_trigger_based) { 1488c2ecf20Sopenharmony_ci NL_SET_ERR_MSG(info->extack, 1498c2ecf20Sopenharmony_ci "FTM: can't set both trigger based and non trigger based"); 1508c2ecf20Sopenharmony_ci return -EINVAL; 1518c2ecf20Sopenharmony_ci } 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci if ((out->ftm.trigger_based || out->ftm.non_trigger_based) && 1548c2ecf20Sopenharmony_ci out->ftm.preamble != NL80211_PREAMBLE_HE) { 1558c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 1568c2ecf20Sopenharmony_ci tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE], 1578c2ecf20Sopenharmony_ci "FTM: non EDCA based ranging must use HE preamble"); 1588c2ecf20Sopenharmony_ci return -EINVAL; 1598c2ecf20Sopenharmony_ci } 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci return 0; 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic int pmsr_parse_peer(struct cfg80211_registered_device *rdev, 1658c2ecf20Sopenharmony_ci struct nlattr *peer, 1668c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request_peer *out, 1678c2ecf20Sopenharmony_ci struct genl_info *info) 1688c2ecf20Sopenharmony_ci{ 1698c2ecf20Sopenharmony_ci struct nlattr *tb[NL80211_PMSR_PEER_ATTR_MAX + 1]; 1708c2ecf20Sopenharmony_ci struct nlattr *req[NL80211_PMSR_REQ_ATTR_MAX + 1]; 1718c2ecf20Sopenharmony_ci struct nlattr *treq; 1728c2ecf20Sopenharmony_ci int err, rem; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci /* no validation needed - was already done via nested policy */ 1758c2ecf20Sopenharmony_ci nla_parse_nested_deprecated(tb, NL80211_PMSR_PEER_ATTR_MAX, peer, 1768c2ecf20Sopenharmony_ci NULL, NULL); 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci if (!tb[NL80211_PMSR_PEER_ATTR_ADDR] || 1798c2ecf20Sopenharmony_ci !tb[NL80211_PMSR_PEER_ATTR_CHAN] || 1808c2ecf20Sopenharmony_ci !tb[NL80211_PMSR_PEER_ATTR_REQ]) { 1818c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, peer, 1828c2ecf20Sopenharmony_ci "insufficient peer data"); 1838c2ecf20Sopenharmony_ci return -EINVAL; 1848c2ecf20Sopenharmony_ci } 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci memcpy(out->addr, nla_data(tb[NL80211_PMSR_PEER_ATTR_ADDR]), ETH_ALEN); 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci /* reuse info->attrs */ 1898c2ecf20Sopenharmony_ci memset(info->attrs, 0, sizeof(*info->attrs) * (NL80211_ATTR_MAX + 1)); 1908c2ecf20Sopenharmony_ci err = nla_parse_nested_deprecated(info->attrs, NL80211_ATTR_MAX, 1918c2ecf20Sopenharmony_ci tb[NL80211_PMSR_PEER_ATTR_CHAN], 1928c2ecf20Sopenharmony_ci NULL, info->extack); 1938c2ecf20Sopenharmony_ci if (err) 1948c2ecf20Sopenharmony_ci return err; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci err = nl80211_parse_chandef(rdev, info, &out->chandef); 1978c2ecf20Sopenharmony_ci if (err) 1988c2ecf20Sopenharmony_ci return err; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci /* no validation needed - was already done via nested policy */ 2018c2ecf20Sopenharmony_ci nla_parse_nested_deprecated(req, NL80211_PMSR_REQ_ATTR_MAX, 2028c2ecf20Sopenharmony_ci tb[NL80211_PMSR_PEER_ATTR_REQ], NULL, 2038c2ecf20Sopenharmony_ci NULL); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci if (!req[NL80211_PMSR_REQ_ATTR_DATA]) { 2068c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 2078c2ecf20Sopenharmony_ci tb[NL80211_PMSR_PEER_ATTR_REQ], 2088c2ecf20Sopenharmony_ci "missing request type/data"); 2098c2ecf20Sopenharmony_ci return -EINVAL; 2108c2ecf20Sopenharmony_ci } 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci if (req[NL80211_PMSR_REQ_ATTR_GET_AP_TSF]) 2138c2ecf20Sopenharmony_ci out->report_ap_tsf = true; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci if (out->report_ap_tsf && !rdev->wiphy.pmsr_capa->report_ap_tsf) { 2168c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 2178c2ecf20Sopenharmony_ci req[NL80211_PMSR_REQ_ATTR_GET_AP_TSF], 2188c2ecf20Sopenharmony_ci "reporting AP TSF is not supported"); 2198c2ecf20Sopenharmony_ci return -EINVAL; 2208c2ecf20Sopenharmony_ci } 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci nla_for_each_nested(treq, req[NL80211_PMSR_REQ_ATTR_DATA], rem) { 2238c2ecf20Sopenharmony_ci switch (nla_type(treq)) { 2248c2ecf20Sopenharmony_ci case NL80211_PMSR_TYPE_FTM: 2258c2ecf20Sopenharmony_ci err = pmsr_parse_ftm(rdev, treq, out, info); 2268c2ecf20Sopenharmony_ci break; 2278c2ecf20Sopenharmony_ci default: 2288c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, treq, 2298c2ecf20Sopenharmony_ci "unsupported measurement type"); 2308c2ecf20Sopenharmony_ci err = -EINVAL; 2318c2ecf20Sopenharmony_ci } 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci if (err) 2358c2ecf20Sopenharmony_ci return err; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci return 0; 2388c2ecf20Sopenharmony_ci} 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ciint nl80211_pmsr_start(struct sk_buff *skb, struct genl_info *info) 2418c2ecf20Sopenharmony_ci{ 2428c2ecf20Sopenharmony_ci struct nlattr *reqattr = info->attrs[NL80211_ATTR_PEER_MEASUREMENTS]; 2438c2ecf20Sopenharmony_ci struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2448c2ecf20Sopenharmony_ci struct wireless_dev *wdev = info->user_ptr[1]; 2458c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request *req; 2468c2ecf20Sopenharmony_ci struct nlattr *peers, *peer; 2478c2ecf20Sopenharmony_ci int count, rem, err, idx; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci if (!rdev->wiphy.pmsr_capa) 2508c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci if (!reqattr) 2538c2ecf20Sopenharmony_ci return -EINVAL; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci peers = nla_find(nla_data(reqattr), nla_len(reqattr), 2568c2ecf20Sopenharmony_ci NL80211_PMSR_ATTR_PEERS); 2578c2ecf20Sopenharmony_ci if (!peers) 2588c2ecf20Sopenharmony_ci return -EINVAL; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci count = 0; 2618c2ecf20Sopenharmony_ci nla_for_each_nested(peer, peers, rem) { 2628c2ecf20Sopenharmony_ci count++; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci if (count > rdev->wiphy.pmsr_capa->max_peers) { 2658c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, peer, 2668c2ecf20Sopenharmony_ci "Too many peers used"); 2678c2ecf20Sopenharmony_ci return -EINVAL; 2688c2ecf20Sopenharmony_ci } 2698c2ecf20Sopenharmony_ci } 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci req = kzalloc(struct_size(req, peers, count), GFP_KERNEL); 2728c2ecf20Sopenharmony_ci if (!req) 2738c2ecf20Sopenharmony_ci return -ENOMEM; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci if (info->attrs[NL80211_ATTR_TIMEOUT]) 2768c2ecf20Sopenharmony_ci req->timeout = nla_get_u32(info->attrs[NL80211_ATTR_TIMEOUT]); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci if (info->attrs[NL80211_ATTR_MAC]) { 2798c2ecf20Sopenharmony_ci if (!rdev->wiphy.pmsr_capa->randomize_mac_addr) { 2808c2ecf20Sopenharmony_ci NL_SET_ERR_MSG_ATTR(info->extack, 2818c2ecf20Sopenharmony_ci info->attrs[NL80211_ATTR_MAC], 2828c2ecf20Sopenharmony_ci "device cannot randomize MAC address"); 2838c2ecf20Sopenharmony_ci err = -EINVAL; 2848c2ecf20Sopenharmony_ci goto out_err; 2858c2ecf20Sopenharmony_ci } 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci err = nl80211_parse_random_mac(info->attrs, req->mac_addr, 2888c2ecf20Sopenharmony_ci req->mac_addr_mask); 2898c2ecf20Sopenharmony_ci if (err) 2908c2ecf20Sopenharmony_ci goto out_err; 2918c2ecf20Sopenharmony_ci } else { 2928c2ecf20Sopenharmony_ci memcpy(req->mac_addr, wdev_address(wdev), ETH_ALEN); 2938c2ecf20Sopenharmony_ci eth_broadcast_addr(req->mac_addr_mask); 2948c2ecf20Sopenharmony_ci } 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci idx = 0; 2978c2ecf20Sopenharmony_ci nla_for_each_nested(peer, peers, rem) { 2988c2ecf20Sopenharmony_ci /* NB: this reuses info->attrs, but we no longer need it */ 2998c2ecf20Sopenharmony_ci err = pmsr_parse_peer(rdev, peer, &req->peers[idx], info); 3008c2ecf20Sopenharmony_ci if (err) 3018c2ecf20Sopenharmony_ci goto out_err; 3028c2ecf20Sopenharmony_ci idx++; 3038c2ecf20Sopenharmony_ci } 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci req->n_peers = count; 3068c2ecf20Sopenharmony_ci req->cookie = cfg80211_assign_cookie(rdev); 3078c2ecf20Sopenharmony_ci req->nl_portid = info->snd_portid; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci err = rdev_start_pmsr(rdev, wdev, req); 3108c2ecf20Sopenharmony_ci if (err) 3118c2ecf20Sopenharmony_ci goto out_err; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci list_add_tail(&req->list, &wdev->pmsr_list); 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci nl_set_extack_cookie_u64(info->extack, req->cookie); 3168c2ecf20Sopenharmony_ci return 0; 3178c2ecf20Sopenharmony_ciout_err: 3188c2ecf20Sopenharmony_ci kfree(req); 3198c2ecf20Sopenharmony_ci return err; 3208c2ecf20Sopenharmony_ci} 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_civoid cfg80211_pmsr_complete(struct wireless_dev *wdev, 3238c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request *req, 3248c2ecf20Sopenharmony_ci gfp_t gfp) 3258c2ecf20Sopenharmony_ci{ 3268c2ecf20Sopenharmony_ci struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 3278c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request *tmp, *prev, *to_free = NULL; 3288c2ecf20Sopenharmony_ci struct sk_buff *msg; 3298c2ecf20Sopenharmony_ci void *hdr; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci trace_cfg80211_pmsr_complete(wdev->wiphy, wdev, req->cookie); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 3348c2ecf20Sopenharmony_ci if (!msg) 3358c2ecf20Sopenharmony_ci goto free_request; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci hdr = nl80211hdr_put(msg, 0, 0, 0, 3388c2ecf20Sopenharmony_ci NL80211_CMD_PEER_MEASUREMENT_COMPLETE); 3398c2ecf20Sopenharmony_ci if (!hdr) 3408c2ecf20Sopenharmony_ci goto free_msg; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 3438c2ecf20Sopenharmony_ci nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 3448c2ecf20Sopenharmony_ci NL80211_ATTR_PAD)) 3458c2ecf20Sopenharmony_ci goto free_msg; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->cookie, 3488c2ecf20Sopenharmony_ci NL80211_ATTR_PAD)) 3498c2ecf20Sopenharmony_ci goto free_msg; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci genlmsg_end(msg, hdr); 3528c2ecf20Sopenharmony_ci genlmsg_unicast(wiphy_net(wdev->wiphy), msg, req->nl_portid); 3538c2ecf20Sopenharmony_ci goto free_request; 3548c2ecf20Sopenharmony_cifree_msg: 3558c2ecf20Sopenharmony_ci nlmsg_free(msg); 3568c2ecf20Sopenharmony_cifree_request: 3578c2ecf20Sopenharmony_ci spin_lock_bh(&wdev->pmsr_lock); 3588c2ecf20Sopenharmony_ci /* 3598c2ecf20Sopenharmony_ci * cfg80211_pmsr_process_abort() may have already moved this request 3608c2ecf20Sopenharmony_ci * to the free list, and will free it later. In this case, don't free 3618c2ecf20Sopenharmony_ci * it here. 3628c2ecf20Sopenharmony_ci */ 3638c2ecf20Sopenharmony_ci list_for_each_entry_safe(tmp, prev, &wdev->pmsr_list, list) { 3648c2ecf20Sopenharmony_ci if (tmp == req) { 3658c2ecf20Sopenharmony_ci list_del(&req->list); 3668c2ecf20Sopenharmony_ci to_free = req; 3678c2ecf20Sopenharmony_ci break; 3688c2ecf20Sopenharmony_ci } 3698c2ecf20Sopenharmony_ci } 3708c2ecf20Sopenharmony_ci spin_unlock_bh(&wdev->pmsr_lock); 3718c2ecf20Sopenharmony_ci kfree(to_free); 3728c2ecf20Sopenharmony_ci} 3738c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(cfg80211_pmsr_complete); 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_cistatic int nl80211_pmsr_send_ftm_res(struct sk_buff *msg, 3768c2ecf20Sopenharmony_ci struct cfg80211_pmsr_result *res) 3778c2ecf20Sopenharmony_ci{ 3788c2ecf20Sopenharmony_ci if (res->status == NL80211_PMSR_STATUS_FAILURE) { 3798c2ecf20Sopenharmony_ci if (nla_put_u32(msg, NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON, 3808c2ecf20Sopenharmony_ci res->ftm.failure_reason)) 3818c2ecf20Sopenharmony_ci goto error; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci if (res->ftm.failure_reason == 3848c2ecf20Sopenharmony_ci NL80211_PMSR_FTM_FAILURE_PEER_BUSY && 3858c2ecf20Sopenharmony_ci res->ftm.busy_retry_time && 3868c2ecf20Sopenharmony_ci nla_put_u32(msg, NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME, 3878c2ecf20Sopenharmony_ci res->ftm.busy_retry_time)) 3888c2ecf20Sopenharmony_ci goto error; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci return 0; 3918c2ecf20Sopenharmony_ci } 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci#define PUT(tp, attr, val) \ 3948c2ecf20Sopenharmony_ci do { \ 3958c2ecf20Sopenharmony_ci if (nla_put_##tp(msg, \ 3968c2ecf20Sopenharmony_ci NL80211_PMSR_FTM_RESP_ATTR_##attr, \ 3978c2ecf20Sopenharmony_ci res->ftm.val)) \ 3988c2ecf20Sopenharmony_ci goto error; \ 3998c2ecf20Sopenharmony_ci } while (0) 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci#define PUTOPT(tp, attr, val) \ 4028c2ecf20Sopenharmony_ci do { \ 4038c2ecf20Sopenharmony_ci if (res->ftm.val##_valid) \ 4048c2ecf20Sopenharmony_ci PUT(tp, attr, val); \ 4058c2ecf20Sopenharmony_ci } while (0) 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci#define PUT_U64(attr, val) \ 4088c2ecf20Sopenharmony_ci do { \ 4098c2ecf20Sopenharmony_ci if (nla_put_u64_64bit(msg, \ 4108c2ecf20Sopenharmony_ci NL80211_PMSR_FTM_RESP_ATTR_##attr,\ 4118c2ecf20Sopenharmony_ci res->ftm.val, \ 4128c2ecf20Sopenharmony_ci NL80211_PMSR_FTM_RESP_ATTR_PAD)) \ 4138c2ecf20Sopenharmony_ci goto error; \ 4148c2ecf20Sopenharmony_ci } while (0) 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci#define PUTOPT_U64(attr, val) \ 4178c2ecf20Sopenharmony_ci do { \ 4188c2ecf20Sopenharmony_ci if (res->ftm.val##_valid) \ 4198c2ecf20Sopenharmony_ci PUT_U64(attr, val); \ 4208c2ecf20Sopenharmony_ci } while (0) 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci if (res->ftm.burst_index >= 0) 4238c2ecf20Sopenharmony_ci PUT(u32, BURST_INDEX, burst_index); 4248c2ecf20Sopenharmony_ci PUTOPT(u32, NUM_FTMR_ATTEMPTS, num_ftmr_attempts); 4258c2ecf20Sopenharmony_ci PUTOPT(u32, NUM_FTMR_SUCCESSES, num_ftmr_successes); 4268c2ecf20Sopenharmony_ci PUT(u8, NUM_BURSTS_EXP, num_bursts_exp); 4278c2ecf20Sopenharmony_ci PUT(u8, BURST_DURATION, burst_duration); 4288c2ecf20Sopenharmony_ci PUT(u8, FTMS_PER_BURST, ftms_per_burst); 4298c2ecf20Sopenharmony_ci PUTOPT(s32, RSSI_AVG, rssi_avg); 4308c2ecf20Sopenharmony_ci PUTOPT(s32, RSSI_SPREAD, rssi_spread); 4318c2ecf20Sopenharmony_ci if (res->ftm.tx_rate_valid && 4328c2ecf20Sopenharmony_ci !nl80211_put_sta_rate(msg, &res->ftm.tx_rate, 4338c2ecf20Sopenharmony_ci NL80211_PMSR_FTM_RESP_ATTR_TX_RATE)) 4348c2ecf20Sopenharmony_ci goto error; 4358c2ecf20Sopenharmony_ci if (res->ftm.rx_rate_valid && 4368c2ecf20Sopenharmony_ci !nl80211_put_sta_rate(msg, &res->ftm.rx_rate, 4378c2ecf20Sopenharmony_ci NL80211_PMSR_FTM_RESP_ATTR_RX_RATE)) 4388c2ecf20Sopenharmony_ci goto error; 4398c2ecf20Sopenharmony_ci PUTOPT_U64(RTT_AVG, rtt_avg); 4408c2ecf20Sopenharmony_ci PUTOPT_U64(RTT_VARIANCE, rtt_variance); 4418c2ecf20Sopenharmony_ci PUTOPT_U64(RTT_SPREAD, rtt_spread); 4428c2ecf20Sopenharmony_ci PUTOPT_U64(DIST_AVG, dist_avg); 4438c2ecf20Sopenharmony_ci PUTOPT_U64(DIST_VARIANCE, dist_variance); 4448c2ecf20Sopenharmony_ci PUTOPT_U64(DIST_SPREAD, dist_spread); 4458c2ecf20Sopenharmony_ci if (res->ftm.lci && res->ftm.lci_len && 4468c2ecf20Sopenharmony_ci nla_put(msg, NL80211_PMSR_FTM_RESP_ATTR_LCI, 4478c2ecf20Sopenharmony_ci res->ftm.lci_len, res->ftm.lci)) 4488c2ecf20Sopenharmony_ci goto error; 4498c2ecf20Sopenharmony_ci if (res->ftm.civicloc && res->ftm.civicloc_len && 4508c2ecf20Sopenharmony_ci nla_put(msg, NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC, 4518c2ecf20Sopenharmony_ci res->ftm.civicloc_len, res->ftm.civicloc)) 4528c2ecf20Sopenharmony_ci goto error; 4538c2ecf20Sopenharmony_ci#undef PUT 4548c2ecf20Sopenharmony_ci#undef PUTOPT 4558c2ecf20Sopenharmony_ci#undef PUT_U64 4568c2ecf20Sopenharmony_ci#undef PUTOPT_U64 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci return 0; 4598c2ecf20Sopenharmony_cierror: 4608c2ecf20Sopenharmony_ci return -ENOSPC; 4618c2ecf20Sopenharmony_ci} 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_cistatic int nl80211_pmsr_send_result(struct sk_buff *msg, 4648c2ecf20Sopenharmony_ci struct cfg80211_pmsr_result *res) 4658c2ecf20Sopenharmony_ci{ 4668c2ecf20Sopenharmony_ci struct nlattr *pmsr, *peers, *peer, *resp, *data, *typedata; 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); 4698c2ecf20Sopenharmony_ci if (!pmsr) 4708c2ecf20Sopenharmony_ci goto error; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci peers = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_PEERS); 4738c2ecf20Sopenharmony_ci if (!peers) 4748c2ecf20Sopenharmony_ci goto error; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci peer = nla_nest_start_noflag(msg, 1); 4778c2ecf20Sopenharmony_ci if (!peer) 4788c2ecf20Sopenharmony_ci goto error; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci if (nla_put(msg, NL80211_PMSR_PEER_ATTR_ADDR, ETH_ALEN, res->addr)) 4818c2ecf20Sopenharmony_ci goto error; 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci resp = nla_nest_start_noflag(msg, NL80211_PMSR_PEER_ATTR_RESP); 4848c2ecf20Sopenharmony_ci if (!resp) 4858c2ecf20Sopenharmony_ci goto error; 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci if (nla_put_u32(msg, NL80211_PMSR_RESP_ATTR_STATUS, res->status) || 4888c2ecf20Sopenharmony_ci nla_put_u64_64bit(msg, NL80211_PMSR_RESP_ATTR_HOST_TIME, 4898c2ecf20Sopenharmony_ci res->host_time, NL80211_PMSR_RESP_ATTR_PAD)) 4908c2ecf20Sopenharmony_ci goto error; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci if (res->ap_tsf_valid && 4938c2ecf20Sopenharmony_ci nla_put_u64_64bit(msg, NL80211_PMSR_RESP_ATTR_AP_TSF, 4948c2ecf20Sopenharmony_ci res->ap_tsf, NL80211_PMSR_RESP_ATTR_PAD)) 4958c2ecf20Sopenharmony_ci goto error; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci if (res->final && nla_put_flag(msg, NL80211_PMSR_RESP_ATTR_FINAL)) 4988c2ecf20Sopenharmony_ci goto error; 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci data = nla_nest_start_noflag(msg, NL80211_PMSR_RESP_ATTR_DATA); 5018c2ecf20Sopenharmony_ci if (!data) 5028c2ecf20Sopenharmony_ci goto error; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci typedata = nla_nest_start_noflag(msg, res->type); 5058c2ecf20Sopenharmony_ci if (!typedata) 5068c2ecf20Sopenharmony_ci goto error; 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci switch (res->type) { 5098c2ecf20Sopenharmony_ci case NL80211_PMSR_TYPE_FTM: 5108c2ecf20Sopenharmony_ci if (nl80211_pmsr_send_ftm_res(msg, res)) 5118c2ecf20Sopenharmony_ci goto error; 5128c2ecf20Sopenharmony_ci break; 5138c2ecf20Sopenharmony_ci default: 5148c2ecf20Sopenharmony_ci WARN_ON(1); 5158c2ecf20Sopenharmony_ci } 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci nla_nest_end(msg, typedata); 5188c2ecf20Sopenharmony_ci nla_nest_end(msg, data); 5198c2ecf20Sopenharmony_ci nla_nest_end(msg, resp); 5208c2ecf20Sopenharmony_ci nla_nest_end(msg, peer); 5218c2ecf20Sopenharmony_ci nla_nest_end(msg, peers); 5228c2ecf20Sopenharmony_ci nla_nest_end(msg, pmsr); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci return 0; 5258c2ecf20Sopenharmony_cierror: 5268c2ecf20Sopenharmony_ci return -ENOSPC; 5278c2ecf20Sopenharmony_ci} 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_civoid cfg80211_pmsr_report(struct wireless_dev *wdev, 5308c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request *req, 5318c2ecf20Sopenharmony_ci struct cfg80211_pmsr_result *result, 5328c2ecf20Sopenharmony_ci gfp_t gfp) 5338c2ecf20Sopenharmony_ci{ 5348c2ecf20Sopenharmony_ci struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 5358c2ecf20Sopenharmony_ci struct sk_buff *msg; 5368c2ecf20Sopenharmony_ci void *hdr; 5378c2ecf20Sopenharmony_ci int err; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci trace_cfg80211_pmsr_report(wdev->wiphy, wdev, req->cookie, 5408c2ecf20Sopenharmony_ci result->addr); 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci /* 5438c2ecf20Sopenharmony_ci * Currently, only variable items are LCI and civic location, 5448c2ecf20Sopenharmony_ci * both of which are reasonably short so we don't need to 5458c2ecf20Sopenharmony_ci * worry about them here for the allocation. 5468c2ecf20Sopenharmony_ci */ 5478c2ecf20Sopenharmony_ci msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 5488c2ecf20Sopenharmony_ci if (!msg) 5498c2ecf20Sopenharmony_ci return; 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PEER_MEASUREMENT_RESULT); 5528c2ecf20Sopenharmony_ci if (!hdr) 5538c2ecf20Sopenharmony_ci goto free; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 5568c2ecf20Sopenharmony_ci nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 5578c2ecf20Sopenharmony_ci NL80211_ATTR_PAD)) 5588c2ecf20Sopenharmony_ci goto free; 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_ci if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->cookie, 5618c2ecf20Sopenharmony_ci NL80211_ATTR_PAD)) 5628c2ecf20Sopenharmony_ci goto free; 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci err = nl80211_pmsr_send_result(msg, result); 5658c2ecf20Sopenharmony_ci if (err) { 5668c2ecf20Sopenharmony_ci pr_err_ratelimited("peer measurement result: message didn't fit!"); 5678c2ecf20Sopenharmony_ci goto free; 5688c2ecf20Sopenharmony_ci } 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci genlmsg_end(msg, hdr); 5718c2ecf20Sopenharmony_ci genlmsg_unicast(wiphy_net(wdev->wiphy), msg, req->nl_portid); 5728c2ecf20Sopenharmony_ci return; 5738c2ecf20Sopenharmony_cifree: 5748c2ecf20Sopenharmony_ci nlmsg_free(msg); 5758c2ecf20Sopenharmony_ci} 5768c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(cfg80211_pmsr_report); 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_cistatic void cfg80211_pmsr_process_abort(struct wireless_dev *wdev) 5798c2ecf20Sopenharmony_ci{ 5808c2ecf20Sopenharmony_ci struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 5818c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request *req, *tmp; 5828c2ecf20Sopenharmony_ci LIST_HEAD(free_list); 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci lockdep_assert_held(&wdev->mtx); 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci spin_lock_bh(&wdev->pmsr_lock); 5878c2ecf20Sopenharmony_ci list_for_each_entry_safe(req, tmp, &wdev->pmsr_list, list) { 5888c2ecf20Sopenharmony_ci if (req->nl_portid) 5898c2ecf20Sopenharmony_ci continue; 5908c2ecf20Sopenharmony_ci list_move_tail(&req->list, &free_list); 5918c2ecf20Sopenharmony_ci } 5928c2ecf20Sopenharmony_ci spin_unlock_bh(&wdev->pmsr_lock); 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci list_for_each_entry_safe(req, tmp, &free_list, list) { 5958c2ecf20Sopenharmony_ci rdev_abort_pmsr(rdev, wdev, req); 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci kfree(req); 5988c2ecf20Sopenharmony_ci } 5998c2ecf20Sopenharmony_ci} 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_civoid cfg80211_pmsr_free_wk(struct work_struct *work) 6028c2ecf20Sopenharmony_ci{ 6038c2ecf20Sopenharmony_ci struct wireless_dev *wdev = container_of(work, struct wireless_dev, 6048c2ecf20Sopenharmony_ci pmsr_free_wk); 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci wdev_lock(wdev); 6078c2ecf20Sopenharmony_ci cfg80211_pmsr_process_abort(wdev); 6088c2ecf20Sopenharmony_ci wdev_unlock(wdev); 6098c2ecf20Sopenharmony_ci} 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_civoid cfg80211_pmsr_wdev_down(struct wireless_dev *wdev) 6128c2ecf20Sopenharmony_ci{ 6138c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request *req; 6148c2ecf20Sopenharmony_ci bool found = false; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci spin_lock_bh(&wdev->pmsr_lock); 6178c2ecf20Sopenharmony_ci list_for_each_entry(req, &wdev->pmsr_list, list) { 6188c2ecf20Sopenharmony_ci found = true; 6198c2ecf20Sopenharmony_ci req->nl_portid = 0; 6208c2ecf20Sopenharmony_ci } 6218c2ecf20Sopenharmony_ci spin_unlock_bh(&wdev->pmsr_lock); 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci if (found) 6248c2ecf20Sopenharmony_ci cfg80211_pmsr_process_abort(wdev); 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci WARN_ON(!list_empty(&wdev->pmsr_list)); 6278c2ecf20Sopenharmony_ci} 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_civoid cfg80211_release_pmsr(struct wireless_dev *wdev, u32 portid) 6308c2ecf20Sopenharmony_ci{ 6318c2ecf20Sopenharmony_ci struct cfg80211_pmsr_request *req; 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci spin_lock_bh(&wdev->pmsr_lock); 6348c2ecf20Sopenharmony_ci list_for_each_entry(req, &wdev->pmsr_list, list) { 6358c2ecf20Sopenharmony_ci if (req->nl_portid == portid) { 6368c2ecf20Sopenharmony_ci req->nl_portid = 0; 6378c2ecf20Sopenharmony_ci schedule_work(&wdev->pmsr_free_wk); 6388c2ecf20Sopenharmony_ci } 6398c2ecf20Sopenharmony_ci } 6408c2ecf20Sopenharmony_ci spin_unlock_bh(&wdev->pmsr_lock); 6418c2ecf20Sopenharmony_ci} 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci#endif /* __PMSR_H */ 644