ie.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Marvell Wireless LAN device driver: management IE handling- setting and
  3. * deleting IE.
  4. *
  5. * Copyright (C) 2012, Marvell International Ltd.
  6. *
  7. * This software file (the "File") is distributed by Marvell International
  8. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  9. * (the "License"). You may use, redistribute and/or modify this File in
  10. * accordance with the terms and conditions of the License, a copy of which
  11. * is available by writing to the Free Software Foundation, Inc.,
  12. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  13. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  14. *
  15. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  18. * this warranty disclaimer.
  19. */
  20. #include "main.h"
  21. /* This function checks if current IE index is used by any on other interface.
  22. * Return: -1: yes, current IE index is used by someone else.
  23. * 0: no, current IE index is NOT used by other interface.
  24. */
  25. static int
  26. mwifiex_ie_index_used_by_other_intf(struct mwifiex_private *priv, u16 idx)
  27. {
  28. int i;
  29. struct mwifiex_adapter *adapter = priv->adapter;
  30. struct mwifiex_ie *ie;
  31. for (i = 0; i < adapter->priv_num; i++) {
  32. if (adapter->priv[i] != priv) {
  33. ie = &adapter->priv[i]->mgmt_ie[idx];
  34. if (ie->mgmt_subtype_mask && ie->ie_length)
  35. return -1;
  36. }
  37. }
  38. return 0;
  39. }
  40. /* Get unused IE index. This index will be used for setting new IE */
  41. static int
  42. mwifiex_ie_get_autoidx(struct mwifiex_private *priv, u16 subtype_mask,
  43. struct mwifiex_ie *ie, u16 *index)
  44. {
  45. u16 mask, len, i;
  46. for (i = 0; i < priv->adapter->max_mgmt_ie_index; i++) {
  47. mask = le16_to_cpu(priv->mgmt_ie[i].mgmt_subtype_mask);
  48. len = le16_to_cpu(priv->mgmt_ie[i].ie_length) +
  49. le16_to_cpu(ie->ie_length);
  50. if (mask == MWIFIEX_AUTO_IDX_MASK)
  51. continue;
  52. if (mask == subtype_mask) {
  53. if (len > IEEE_MAX_IE_SIZE)
  54. continue;
  55. *index = i;
  56. return 0;
  57. }
  58. if (!priv->mgmt_ie[i].ie_length) {
  59. if (mwifiex_ie_index_used_by_other_intf(priv, i))
  60. continue;
  61. *index = i;
  62. return 0;
  63. }
  64. }
  65. return -1;
  66. }
  67. /* This function prepares IE data buffer for command to be sent to FW */
  68. static int
  69. mwifiex_update_autoindex_ies(struct mwifiex_private *priv,
  70. struct mwifiex_ie_list *ie_list)
  71. {
  72. u16 travel_len, index, mask;
  73. s16 input_len;
  74. struct mwifiex_ie *ie;
  75. u8 *tmp;
  76. input_len = le16_to_cpu(ie_list->len);
  77. travel_len = sizeof(struct host_cmd_tlv);
  78. ie_list->len = 0;
  79. while (input_len > 0) {
  80. ie = (struct mwifiex_ie *)(((u8 *)ie_list) + travel_len);
  81. input_len -= le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE;
  82. travel_len += le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE;
  83. index = le16_to_cpu(ie->ie_index);
  84. mask = le16_to_cpu(ie->mgmt_subtype_mask);
  85. if (index == MWIFIEX_AUTO_IDX_MASK) {
  86. /* automatic addition */
  87. if (mwifiex_ie_get_autoidx(priv, mask, ie, &index))
  88. return -1;
  89. if (index == MWIFIEX_AUTO_IDX_MASK)
  90. return -1;
  91. tmp = (u8 *)&priv->mgmt_ie[index].ie_buffer;
  92. tmp += le16_to_cpu(priv->mgmt_ie[index].ie_length);
  93. memcpy(tmp, &ie->ie_buffer, le16_to_cpu(ie->ie_length));
  94. le16_add_cpu(&priv->mgmt_ie[index].ie_length,
  95. le16_to_cpu(ie->ie_length));
  96. priv->mgmt_ie[index].ie_index = cpu_to_le16(index);
  97. priv->mgmt_ie[index].mgmt_subtype_mask =
  98. cpu_to_le16(mask);
  99. ie->ie_index = cpu_to_le16(index);
  100. ie->ie_length = priv->mgmt_ie[index].ie_length;
  101. memcpy(&ie->ie_buffer, &priv->mgmt_ie[index].ie_buffer,
  102. le16_to_cpu(priv->mgmt_ie[index].ie_length));
  103. } else {
  104. if (mask != MWIFIEX_DELETE_MASK)
  105. return -1;
  106. /*
  107. * Check if this index is being used on any
  108. * other interface.
  109. */
  110. if (mwifiex_ie_index_used_by_other_intf(priv, index))
  111. return -1;
  112. ie->ie_length = 0;
  113. memcpy(&priv->mgmt_ie[index], ie,
  114. sizeof(struct mwifiex_ie));
  115. }
  116. le16_add_cpu(&ie_list->len,
  117. le16_to_cpu(priv->mgmt_ie[index].ie_length) +
  118. MWIFIEX_IE_HDR_SIZE);
  119. }
  120. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
  121. return mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  122. HostCmd_ACT_GEN_SET,
  123. UAP_CUSTOM_IE_I, ie_list);
  124. return 0;
  125. }