| 1 |
// SPDX-License-Identifier: BSD-3-Clause-Clear |
| 2 |
/* |
| 3 |
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. |
| 4 |
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <net/mac80211.h> |
| 8 |
#include "core.h" |
| 9 |
#include "mac.h" |
| 10 |
#include "p2p.h" |
| 11 |
|
| 12 |
static void ath12k_p2p_noa_ie_fill(u8 *data, size_t len, |
| 13 |
const struct ath12k_wmi_p2p_noa_info *noa) |
| 14 |
{ |
| 15 |
struct ieee80211_p2p_noa_attr *noa_attr; |
| 16 |
u8 ctwindow = le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_CTWIN_TU); |
| 17 |
bool oppps = le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_OPP_PS); |
| 18 |
__le16 *noa_attr_len; |
| 19 |
u16 attr_len; |
| 20 |
u8 noa_descriptors = le32_get_bits(noa->noa_attr, |
| 21 |
WMI_P2P_NOA_INFO_DESC_NUM); |
| 22 |
int i; |
| 23 |
|
| 24 |
/* P2P IE */ |
| 25 |
data[0] = WLAN_EID_VENDOR_SPECIFIC; |
| 26 |
data[1] = len - 2; |
| 27 |
data[2] = (WLAN_OUI_WFA >> 16) & 0xff; |
| 28 |
data[3] = (WLAN_OUI_WFA >> 8) & 0xff; |
| 29 |
data[4] = (WLAN_OUI_WFA >> 0) & 0xff; |
| 30 |
data[5] = WLAN_OUI_TYPE_WFA_P2P; |
| 31 |
|
| 32 |
/* NOA ATTR */ |
| 33 |
data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE; |
| 34 |
noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */ |
| 35 |
noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9]; |
| 36 |
|
| 37 |
noa_attr->index = le32_get_bits(noa->noa_attr, |
| 38 |
WMI_P2P_NOA_INFO_INDEX); |
| 39 |
noa_attr->oppps_ctwindow = ctwindow; |
| 40 |
if (oppps) |
| 41 |
noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT; |
| 42 |
|
| 43 |
for (i = 0; i < noa_descriptors; i++) { |
| 44 |
noa_attr->desc[i].count = |
| 45 |
__le32_to_cpu(noa->descriptors[i].type_count); |
| 46 |
noa_attr->desc[i].duration = noa->descriptors[i].duration; |
| 47 |
noa_attr->desc[i].interval = noa->descriptors[i].interval; |
| 48 |
noa_attr->desc[i].start_time = noa->descriptors[i].start_time; |
| 49 |
} |
| 50 |
|
| 51 |
attr_len = 2; /* index + oppps_ctwindow */ |
| 52 |
attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc); |
| 53 |
*noa_attr_len = __cpu_to_le16(attr_len); |
| 54 |
} |
| 55 |
|
| 56 |
static size_t ath12k_p2p_noa_ie_len_compute(const struct ath12k_wmi_p2p_noa_info *noa) |
| 57 |
{ |
| 58 |
size_t len = 0; |
| 59 |
|
| 60 |
if (!(le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_DESC_NUM)) && |
| 61 |
!(le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_OPP_PS))) |
| 62 |
return 0; |
| 63 |
|
| 64 |
len += 1 + 1 + 4; /* EID + len + OUI */ |
| 65 |
len += 1 + 2; /* noa attr + attr len */ |
| 66 |
len += 1 + 1; /* index + oppps_ctwindow */ |
| 67 |
len += le32_get_bits(noa->noa_attr, WMI_P2P_NOA_INFO_DESC_NUM) * |
| 68 |
sizeof(struct ieee80211_p2p_noa_desc); |
| 69 |
|
| 70 |
return len; |
| 71 |
} |
| 72 |
|
| 73 |
static void ath12k_p2p_noa_ie_assign(struct ath12k_link_vif *arvif, void *ie, |
| 74 |
size_t len) |
| 75 |
{ |
| 76 |
struct ath12k *ar = arvif->ar; |
| 77 |
|
| 78 |
lockdep_assert_held(&ar->data_lock); |
| 79 |
|
| 80 |
kfree(arvif->ahvif->u.ap.noa_data); |
| 81 |
|
| 82 |
arvif->ahvif->u.ap.noa_data = ie; |
| 83 |
arvif->ahvif->u.ap.noa_len = len; |
| 84 |
} |
| 85 |
|
| 86 |
static void __ath12k_p2p_noa_update(struct ath12k_link_vif *arvif, |
| 87 |
const struct ath12k_wmi_p2p_noa_info *noa) |
| 88 |
{ |
| 89 |
struct ath12k *ar = arvif->ar; |
| 90 |
void *ie; |
| 91 |
size_t len; |
| 92 |
|
| 93 |
lockdep_assert_held(&ar->data_lock); |
| 94 |
|
| 95 |
ath12k_p2p_noa_ie_assign(arvif, NULL, 0); |
| 96 |
|
| 97 |
len = ath12k_p2p_noa_ie_len_compute(noa); |
| 98 |
if (!len) |
| 99 |
return; |
| 100 |
|
| 101 |
ie = kmalloc(len, GFP_ATOMIC); |
| 102 |
if (!ie) |
| 103 |
return; |
| 104 |
|
| 105 |
ath12k_p2p_noa_ie_fill(ie, len, noa); |
| 106 |
ath12k_p2p_noa_ie_assign(arvif, ie, len); |
| 107 |
} |
| 108 |
|
| 109 |
void ath12k_p2p_noa_update(struct ath12k_link_vif *arvif, |
| 110 |
const struct ath12k_wmi_p2p_noa_info *noa) |
| 111 |
{ |
| 112 |
struct ath12k *ar = arvif->ar; |
| 113 |
|
| 114 |
spin_lock_bh(&ar->data_lock); |
| 115 |
__ath12k_p2p_noa_update(arvif, noa); |
| 116 |
spin_unlock_bh(&ar->data_lock); |
| 117 |
} |
| 118 |
|
| 119 |
static void ath12k_p2p_noa_update_vdev_iter(void *data, u8 *mac, |
| 120 |
struct ieee80211_vif *vif) |
| 121 |
{ |
| 122 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 123 |
struct ath12k_p2p_noa_arg *arg = data; |
| 124 |
struct ath12k_link_vif *arvif; |
| 125 |
|
| 126 |
WARN_ON(!rcu_read_lock_any_held()); |
| 127 |
arvif = &ahvif->deflink; |
| 128 |
if (!arvif->is_created || arvif->ar != arg->ar || arvif->vdev_id != arg->vdev_id) |
| 129 |
return; |
| 130 |
|
| 131 |
ath12k_p2p_noa_update(arvif, arg->noa); |
| 132 |
} |
| 133 |
|
| 134 |
void ath12k_p2p_noa_update_by_vdev_id(struct ath12k *ar, u32 vdev_id, |
| 135 |
const struct ath12k_wmi_p2p_noa_info *noa) |
| 136 |
{ |
| 137 |
struct ath12k_p2p_noa_arg arg = { |
| 138 |
.vdev_id = vdev_id, |
| 139 |
.ar = ar, |
| 140 |
.noa = noa, |
| 141 |
}; |
| 142 |
|
| 143 |
ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), |
| 144 |
IEEE80211_IFACE_ITER_NORMAL, |
| 145 |
ath12k_p2p_noa_update_vdev_iter, |
| 146 |
&arg); |
| 147 |
} |