p2p.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (c) 2015 Qualcomm Atheros, Inc.
  4. */
  5. #include "core.h"
  6. #include "wmi.h"
  7. #include "mac.h"
  8. #include "p2p.h"
  9. static void ath10k_p2p_noa_ie_fill(u8 *data, size_t len,
  10. const struct wmi_p2p_noa_info *noa)
  11. {
  12. struct ieee80211_p2p_noa_attr *noa_attr;
  13. u8 ctwindow_oppps = noa->ctwindow_oppps;
  14. u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
  15. bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
  16. __le16 *noa_attr_len;
  17. u16 attr_len;
  18. u8 noa_descriptors = noa->num_descriptors;
  19. int i;
  20. /* P2P IE */
  21. data[0] = WLAN_EID_VENDOR_SPECIFIC;
  22. data[1] = len - 2;
  23. data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
  24. data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
  25. data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
  26. data[5] = WLAN_OUI_TYPE_WFA_P2P;
  27. /* NOA ATTR */
  28. data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
  29. noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
  30. noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
  31. noa_attr->index = noa->index;
  32. noa_attr->oppps_ctwindow = ctwindow;
  33. if (oppps)
  34. noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
  35. for (i = 0; i < noa_descriptors; i++) {
  36. noa_attr->desc[i].count =
  37. __le32_to_cpu(noa->descriptors[i].type_count);
  38. noa_attr->desc[i].duration = noa->descriptors[i].duration;
  39. noa_attr->desc[i].interval = noa->descriptors[i].interval;
  40. noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
  41. }
  42. attr_len = 2; /* index + oppps_ctwindow */
  43. attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
  44. *noa_attr_len = __cpu_to_le16(attr_len);
  45. }
  46. static size_t ath10k_p2p_noa_ie_len_compute(const struct wmi_p2p_noa_info *noa)
  47. {
  48. size_t len = 0;
  49. if (!noa->num_descriptors &&
  50. !(noa->ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT))
  51. return 0;
  52. len += 1 + 1 + 4; /* EID + len + OUI */
  53. len += 1 + 2; /* noa attr + attr len */
  54. len += 1 + 1; /* index + oppps_ctwindow */
  55. len += noa->num_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
  56. return len;
  57. }
  58. static void ath10k_p2p_noa_ie_assign(struct ath10k_vif *arvif, void *ie,
  59. size_t len)
  60. {
  61. struct ath10k *ar = arvif->ar;
  62. lockdep_assert_held(&ar->data_lock);
  63. kfree(arvif->u.ap.noa_data);
  64. arvif->u.ap.noa_data = ie;
  65. arvif->u.ap.noa_len = len;
  66. }
  67. static void __ath10k_p2p_noa_update(struct ath10k_vif *arvif,
  68. const struct wmi_p2p_noa_info *noa)
  69. {
  70. struct ath10k *ar = arvif->ar;
  71. void *ie;
  72. size_t len;
  73. lockdep_assert_held(&ar->data_lock);
  74. ath10k_p2p_noa_ie_assign(arvif, NULL, 0);
  75. len = ath10k_p2p_noa_ie_len_compute(noa);
  76. if (!len)
  77. return;
  78. ie = kmalloc(len, GFP_ATOMIC);
  79. if (!ie)
  80. return;
  81. ath10k_p2p_noa_ie_fill(ie, len, noa);
  82. ath10k_p2p_noa_ie_assign(arvif, ie, len);
  83. }
  84. void ath10k_p2p_noa_update(struct ath10k_vif *arvif,
  85. const struct wmi_p2p_noa_info *noa)
  86. {
  87. struct ath10k *ar = arvif->ar;
  88. spin_lock_bh(&ar->data_lock);
  89. __ath10k_p2p_noa_update(arvif, noa);
  90. spin_unlock_bh(&ar->data_lock);
  91. }
  92. struct ath10k_p2p_noa_arg {
  93. u32 vdev_id;
  94. const struct wmi_p2p_noa_info *noa;
  95. };
  96. static void ath10k_p2p_noa_update_vdev_iter(void *data, u8 *mac,
  97. struct ieee80211_vif *vif)
  98. {
  99. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  100. struct ath10k_p2p_noa_arg *arg = data;
  101. if (arvif->vdev_id != arg->vdev_id)
  102. return;
  103. ath10k_p2p_noa_update(arvif, arg->noa);
  104. }
  105. void ath10k_p2p_noa_update_by_vdev_id(struct ath10k *ar, u32 vdev_id,
  106. const struct wmi_p2p_noa_info *noa)
  107. {
  108. struct ath10k_p2p_noa_arg arg = {
  109. .vdev_id = vdev_id,
  110. .noa = noa,
  111. };
  112. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  113. ATH10K_ITER_NORMAL_FLAGS,
  114. ath10k_p2p_noa_update_vdev_iter,
  115. &arg);
  116. }