p2p.c 4.0 KB

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