p2p.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2015 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "core.h"
  17. #include "wmi.h"
  18. #include "mac.h"
  19. #include "p2p.h"
  20. static void ath10k_p2p_noa_ie_fill(u8 *data, size_t len,
  21. const struct wmi_p2p_noa_info *noa)
  22. {
  23. struct ieee80211_p2p_noa_attr *noa_attr;
  24. u8 ctwindow_oppps = noa->ctwindow_oppps;
  25. u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
  26. bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
  27. __le16 *noa_attr_len;
  28. u16 attr_len;
  29. u8 noa_descriptors = noa->num_descriptors;
  30. int i;
  31. /* P2P IE */
  32. data[0] = WLAN_EID_VENDOR_SPECIFIC;
  33. data[1] = len - 2;
  34. data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
  35. data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
  36. data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
  37. data[5] = WLAN_OUI_TYPE_WFA_P2P;
  38. /* NOA ATTR */
  39. data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
  40. noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
  41. noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
  42. noa_attr->index = noa->index;
  43. noa_attr->oppps_ctwindow = ctwindow;
  44. if (oppps)
  45. noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
  46. for (i = 0; i < noa_descriptors; i++) {
  47. noa_attr->desc[i].count =
  48. __le32_to_cpu(noa->descriptors[i].type_count);
  49. noa_attr->desc[i].duration = noa->descriptors[i].duration;
  50. noa_attr->desc[i].interval = noa->descriptors[i].interval;
  51. noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
  52. }
  53. attr_len = 2; /* index + oppps_ctwindow */
  54. attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
  55. *noa_attr_len = __cpu_to_le16(attr_len);
  56. }
  57. static size_t ath10k_p2p_noa_ie_len_compute(const struct wmi_p2p_noa_info *noa)
  58. {
  59. size_t len = 0;
  60. if (!noa->num_descriptors &&
  61. !(noa->ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT))
  62. return 0;
  63. len += 1 + 1 + 4; /* EID + len + OUI */
  64. len += 1 + 2; /* noa attr + attr len */
  65. len += 1 + 1; /* index + oppps_ctwindow */
  66. len += noa->num_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
  67. return len;
  68. }
  69. static void ath10k_p2p_noa_ie_assign(struct ath10k_vif *arvif, void *ie,
  70. size_t len)
  71. {
  72. struct ath10k *ar = arvif->ar;
  73. lockdep_assert_held(&ar->data_lock);
  74. kfree(arvif->u.ap.noa_data);
  75. arvif->u.ap.noa_data = ie;
  76. arvif->u.ap.noa_len = len;
  77. }
  78. static void __ath10k_p2p_noa_update(struct ath10k_vif *arvif,
  79. const struct wmi_p2p_noa_info *noa)
  80. {
  81. struct ath10k *ar = arvif->ar;
  82. void *ie;
  83. size_t len;
  84. lockdep_assert_held(&ar->data_lock);
  85. ath10k_p2p_noa_ie_assign(arvif, NULL, 0);
  86. len = ath10k_p2p_noa_ie_len_compute(noa);
  87. if (!len)
  88. return;
  89. ie = kmalloc(len, GFP_ATOMIC);
  90. if (!ie)
  91. return;
  92. ath10k_p2p_noa_ie_fill(ie, len, noa);
  93. ath10k_p2p_noa_ie_assign(arvif, ie, len);
  94. }
  95. void ath10k_p2p_noa_update(struct ath10k_vif *arvif,
  96. const struct wmi_p2p_noa_info *noa)
  97. {
  98. struct ath10k *ar = arvif->ar;
  99. spin_lock_bh(&ar->data_lock);
  100. __ath10k_p2p_noa_update(arvif, noa);
  101. spin_unlock_bh(&ar->data_lock);
  102. }
  103. struct ath10k_p2p_noa_arg {
  104. u32 vdev_id;
  105. const struct wmi_p2p_noa_info *noa;
  106. };
  107. static void ath10k_p2p_noa_update_vdev_iter(void *data, u8 *mac,
  108. struct ieee80211_vif *vif)
  109. {
  110. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  111. struct ath10k_p2p_noa_arg *arg = data;
  112. if (arvif->vdev_id != arg->vdev_id)
  113. return;
  114. ath10k_p2p_noa_update(arvif, arg->noa);
  115. }
  116. void ath10k_p2p_noa_update_by_vdev_id(struct ath10k *ar, u32 vdev_id,
  117. const struct wmi_p2p_noa_info *noa)
  118. {
  119. struct ath10k_p2p_noa_arg arg = {
  120. .vdev_id = vdev_id,
  121. .noa = noa,
  122. };
  123. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  124. IEEE80211_IFACE_ITER_NORMAL,
  125. ath10k_p2p_noa_update_vdev_iter,
  126. &arg);
  127. }