Path: blob/main/sys/contrib/dev/athk/ath12k/p2p.c
178701 views
// SPDX-License-Identifier: BSD-3-Clause-Clear1/*2* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.3* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.4*/56#include <net/mac80211.h>7#include "core.h"8#include "mac.h"9#include "p2p.h"1011static void ath12k_p2p_noa_ie_fill(u8 *data, size_t len,12const struct ath12k_wmi_p2p_noa_info *noa)13{14struct ieee80211_p2p_noa_attr *noa_attr;15u8 ctwindow = le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_CTWIN_TU);16bool oppps = le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_OPP_PS);17__le16 *noa_attr_len;18u16 attr_len;19u8 noa_descriptors = le32_get_bits(noa->noa_attr,20WMI_P2P_NOA_INFO_DESC_NUM);21int i;2223/* P2P IE */24data[0] = WLAN_EID_VENDOR_SPECIFIC;25data[1] = len - 2;26data[2] = (WLAN_OUI_WFA >> 16) & 0xff;27data[3] = (WLAN_OUI_WFA >> 8) & 0xff;28data[4] = (WLAN_OUI_WFA >> 0) & 0xff;29data[5] = WLAN_OUI_TYPE_WFA_P2P;3031/* NOA ATTR */32data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;33noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */34noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];3536noa_attr->index = le32_get_bits(noa->noa_attr,37WMI_P2P_NOA_INFO_INDEX);38noa_attr->oppps_ctwindow = ctwindow;39if (oppps)40noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;4142for (i = 0; i < noa_descriptors; i++) {43noa_attr->desc[i].count =44__le32_to_cpu(noa->descriptors[i].type_count);45noa_attr->desc[i].duration = noa->descriptors[i].duration;46noa_attr->desc[i].interval = noa->descriptors[i].interval;47noa_attr->desc[i].start_time = noa->descriptors[i].start_time;48}4950attr_len = 2; /* index + oppps_ctwindow */51attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);52*noa_attr_len = __cpu_to_le16(attr_len);53}5455static size_t ath12k_p2p_noa_ie_len_compute(const struct ath12k_wmi_p2p_noa_info *noa)56{57size_t len = 0;5859if (!(le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_DESC_NUM)) &&60!(le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_OPP_PS)))61return 0;6263len += 1 + 1 + 4; /* EID + len + OUI */64len += 1 + 2; /* noa attr + attr len */65len += 1 + 1; /* index + oppps_ctwindow */66len += le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_DESC_NUM) *67sizeof(struct ieee80211_p2p_noa_desc);6869return len;70}7172static void ath12k_p2p_noa_ie_assign(struct ath12k_link_vif *arvif, void *ie,73size_t len)74{75struct ath12k *ar = arvif->ar;7677lockdep_assert_held(&ar->data_lock);7879kfree(arvif->ahvif->u.ap.noa_data);8081arvif->ahvif->u.ap.noa_data = ie;82arvif->ahvif->u.ap.noa_len = len;83}8485static void __ath12k_p2p_noa_update(struct ath12k_link_vif *arvif,86const struct ath12k_wmi_p2p_noa_info *noa)87{88struct ath12k *ar = arvif->ar;89void *ie;90size_t len;9192lockdep_assert_held(&ar->data_lock);9394ath12k_p2p_noa_ie_assign(arvif, NULL, 0);9596len = ath12k_p2p_noa_ie_len_compute(noa);97if (!len)98return;99100ie = kmalloc(len, GFP_ATOMIC);101if (!ie)102return;103104ath12k_p2p_noa_ie_fill(ie, len, noa);105ath12k_p2p_noa_ie_assign(arvif, ie, len);106}107108void ath12k_p2p_noa_update(struct ath12k_link_vif *arvif,109const struct ath12k_wmi_p2p_noa_info *noa)110{111struct ath12k *ar = arvif->ar;112113spin_lock_bh(&ar->data_lock);114__ath12k_p2p_noa_update(arvif, noa);115spin_unlock_bh(&ar->data_lock);116}117118static void ath12k_p2p_noa_update_vdev_iter(void *data, u8 *mac,119struct ieee80211_vif *vif)120{121struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);122struct ath12k_p2p_noa_arg *arg = data;123struct ath12k_link_vif *arvif;124125WARN_ON(!rcu_read_lock_any_held());126arvif = &ahvif->deflink;127if (!arvif->is_created || arvif->ar != arg->ar || arvif->vdev_id != arg->vdev_id)128return;129130ath12k_p2p_noa_update(arvif, arg->noa);131}132133void ath12k_p2p_noa_update_by_vdev_id(struct ath12k *ar, u32 vdev_id,134const struct ath12k_wmi_p2p_noa_info *noa)135{136struct ath12k_p2p_noa_arg arg = {137.vdev_id = vdev_id,138.ar = ar,139.noa = noa,140};141142ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar),143IEEE80211_IFACE_ITER_NORMAL,144ath12k_p2p_noa_update_vdev_iter,145&arg);146}147148149