Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: ISC
0002 /*
0003  * Copyright (c) 2015 Qualcomm Atheros, Inc.
0004  */
0005 
0006 #include "core.h"
0007 #include "wmi.h"
0008 #include "mac.h"
0009 #include "p2p.h"
0010 
0011 static void ath10k_p2p_noa_ie_fill(u8 *data, size_t len,
0012                    const struct wmi_p2p_noa_info *noa)
0013 {
0014     struct ieee80211_p2p_noa_attr *noa_attr;
0015     u8  ctwindow_oppps = noa->ctwindow_oppps;
0016     u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
0017     bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
0018     __le16 *noa_attr_len;
0019     u16 attr_len;
0020     u8 noa_descriptors = noa->num_descriptors;
0021     int i;
0022 
0023     /* P2P IE */
0024     data[0] = WLAN_EID_VENDOR_SPECIFIC;
0025     data[1] = len - 2;
0026     data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
0027     data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
0028     data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
0029     data[5] = WLAN_OUI_TYPE_WFA_P2P;
0030 
0031     /* NOA ATTR */
0032     data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
0033     noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
0034     noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
0035 
0036     noa_attr->index = noa->index;
0037     noa_attr->oppps_ctwindow = ctwindow;
0038     if (oppps)
0039         noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
0040 
0041     for (i = 0; i < noa_descriptors; i++) {
0042         noa_attr->desc[i].count =
0043             __le32_to_cpu(noa->descriptors[i].type_count);
0044         noa_attr->desc[i].duration = noa->descriptors[i].duration;
0045         noa_attr->desc[i].interval = noa->descriptors[i].interval;
0046         noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
0047     }
0048 
0049     attr_len = 2; /* index + oppps_ctwindow */
0050     attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
0051     *noa_attr_len = __cpu_to_le16(attr_len);
0052 }
0053 
0054 static size_t ath10k_p2p_noa_ie_len_compute(const struct wmi_p2p_noa_info *noa)
0055 {
0056     size_t len = 0;
0057 
0058     if (!noa->num_descriptors &&
0059         !(noa->ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT))
0060         return 0;
0061 
0062     len += 1 + 1 + 4; /* EID + len + OUI */
0063     len += 1 + 2; /* noa attr + attr len */
0064     len += 1 + 1; /* index + oppps_ctwindow */
0065     len += noa->num_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
0066 
0067     return len;
0068 }
0069 
0070 static void ath10k_p2p_noa_ie_assign(struct ath10k_vif *arvif, void *ie,
0071                      size_t len)
0072 {
0073     struct ath10k *ar = arvif->ar;
0074 
0075     lockdep_assert_held(&ar->data_lock);
0076 
0077     kfree(arvif->u.ap.noa_data);
0078 
0079     arvif->u.ap.noa_data = ie;
0080     arvif->u.ap.noa_len = len;
0081 }
0082 
0083 static void __ath10k_p2p_noa_update(struct ath10k_vif *arvif,
0084                     const struct wmi_p2p_noa_info *noa)
0085 {
0086     struct ath10k *ar = arvif->ar;
0087     void *ie;
0088     size_t len;
0089 
0090     lockdep_assert_held(&ar->data_lock);
0091 
0092     ath10k_p2p_noa_ie_assign(arvif, NULL, 0);
0093 
0094     len = ath10k_p2p_noa_ie_len_compute(noa);
0095     if (!len)
0096         return;
0097 
0098     ie = kmalloc(len, GFP_ATOMIC);
0099     if (!ie)
0100         return;
0101 
0102     ath10k_p2p_noa_ie_fill(ie, len, noa);
0103     ath10k_p2p_noa_ie_assign(arvif, ie, len);
0104 }
0105 
0106 void ath10k_p2p_noa_update(struct ath10k_vif *arvif,
0107                const struct wmi_p2p_noa_info *noa)
0108 {
0109     struct ath10k *ar = arvif->ar;
0110 
0111     spin_lock_bh(&ar->data_lock);
0112     __ath10k_p2p_noa_update(arvif, noa);
0113     spin_unlock_bh(&ar->data_lock);
0114 }
0115 
0116 struct ath10k_p2p_noa_arg {
0117     u32 vdev_id;
0118     const struct wmi_p2p_noa_info *noa;
0119 };
0120 
0121 static void ath10k_p2p_noa_update_vdev_iter(void *data, u8 *mac,
0122                         struct ieee80211_vif *vif)
0123 {
0124     struct ath10k_vif *arvif = (void *)vif->drv_priv;
0125     struct ath10k_p2p_noa_arg *arg = data;
0126 
0127     if (arvif->vdev_id != arg->vdev_id)
0128         return;
0129 
0130     ath10k_p2p_noa_update(arvif, arg->noa);
0131 }
0132 
0133 void ath10k_p2p_noa_update_by_vdev_id(struct ath10k *ar, u32 vdev_id,
0134                       const struct wmi_p2p_noa_info *noa)
0135 {
0136     struct ath10k_p2p_noa_arg arg = {
0137         .vdev_id = vdev_id,
0138         .noa = noa,
0139     };
0140 
0141     ieee80211_iterate_active_interfaces_atomic(ar->hw,
0142                            ATH10K_ITER_NORMAL_FLAGS,
0143                            ath10k_p2p_noa_update_vdev_iter,
0144                            &arg);
0145 }