ie.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. }
  126. /* Copy individual custom IEs for beacon, probe response and assoc response
  127. * and prepare single structure for IE setting.
  128. * This function also updates allocated IE indices from driver.
  129. */
  130. static int
  131. mwifiex_update_uap_custom_ie(struct mwifiex_private *priv,
  132. struct mwifiex_ie *beacon_ie, u16 *beacon_idx,
  133. struct mwifiex_ie *pr_ie, u16 *probe_idx,
  134. struct mwifiex_ie *ar_ie, u16 *assoc_idx)
  135. {
  136. struct mwifiex_ie_list *ap_custom_ie;
  137. u8 *pos;
  138. u16 len;
  139. int ret;
  140. ap_custom_ie = kzalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  141. if (!ap_custom_ie)
  142. return -ENOMEM;
  143. ap_custom_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  144. pos = (u8 *)ap_custom_ie->ie_list;
  145. if (beacon_ie) {
  146. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  147. le16_to_cpu(beacon_ie->ie_length);
  148. memcpy(pos, beacon_ie, len);
  149. pos += len;
  150. le16_add_cpu(&ap_custom_ie->len, len);
  151. }
  152. if (pr_ie) {
  153. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  154. le16_to_cpu(pr_ie->ie_length);
  155. memcpy(pos, pr_ie, len);
  156. pos += len;
  157. le16_add_cpu(&ap_custom_ie->len, len);
  158. }
  159. if (ar_ie) {
  160. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  161. le16_to_cpu(ar_ie->ie_length);
  162. memcpy(pos, ar_ie, len);
  163. pos += len;
  164. le16_add_cpu(&ap_custom_ie->len, len);
  165. }
  166. ret = mwifiex_update_autoindex_ies(priv, ap_custom_ie);
  167. pos = (u8 *)(&ap_custom_ie->ie_list[0].ie_index);
  168. if (beacon_ie && *beacon_idx == MWIFIEX_AUTO_IDX_MASK) {
  169. /* save beacon ie index after auto-indexing */
  170. *beacon_idx = le16_to_cpu(ap_custom_ie->ie_list[0].ie_index);
  171. len = sizeof(*beacon_ie) - IEEE_MAX_IE_SIZE +
  172. le16_to_cpu(beacon_ie->ie_length);
  173. pos += len;
  174. }
  175. if (pr_ie && le16_to_cpu(pr_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK) {
  176. /* save probe resp ie index after auto-indexing */
  177. *probe_idx = *((u16 *)pos);
  178. len = sizeof(*pr_ie) - IEEE_MAX_IE_SIZE +
  179. le16_to_cpu(pr_ie->ie_length);
  180. pos += len;
  181. }
  182. if (ar_ie && le16_to_cpu(ar_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK)
  183. /* save assoc resp ie index after auto-indexing */
  184. *assoc_idx = *((u16 *)pos);
  185. return ret;
  186. }
  187. /* This function parses different IEs- Tail IEs, beacon IEs, probe response IEs,
  188. * association response IEs from cfg80211_ap_settings function and sets these IE
  189. * to FW.
  190. */
  191. int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
  192. struct cfg80211_ap_settings *params)
  193. {
  194. struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
  195. struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL;
  196. struct ieee_types_header *ie = NULL;
  197. u16 beacon_idx = MWIFIEX_AUTO_IDX_MASK, pr_idx = MWIFIEX_AUTO_IDX_MASK;
  198. u16 ar_idx = MWIFIEX_AUTO_IDX_MASK, rsn_idx = MWIFIEX_AUTO_IDX_MASK;
  199. u16 mask;
  200. int ret = 0;
  201. if (params->beacon.tail && params->beacon.tail_len) {
  202. ie = (void *)cfg80211_find_ie(WLAN_EID_RSN, params->beacon.tail,
  203. params->beacon.tail_len);
  204. if (ie) {
  205. rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  206. if (!rsn_ie)
  207. return -ENOMEM;
  208. rsn_ie->ie_index = cpu_to_le16(rsn_idx);
  209. mask = MGMT_MASK_BEACON | MGMT_MASK_PROBE_RESP |
  210. MGMT_MASK_ASSOC_RESP;
  211. rsn_ie->mgmt_subtype_mask = cpu_to_le16(mask);
  212. rsn_ie->ie_length = cpu_to_le16(ie->len + 2);
  213. memcpy(rsn_ie->ie_buffer, ie, ie->len + 2);
  214. if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &rsn_idx,
  215. NULL, NULL,
  216. NULL, NULL)) {
  217. ret = -1;
  218. goto done;
  219. }
  220. priv->rsn_idx = rsn_idx;
  221. }
  222. }
  223. if (params->beacon.beacon_ies && params->beacon.beacon_ies_len) {
  224. beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  225. if (!beacon_ie) {
  226. ret = -ENOMEM;
  227. goto done;
  228. }
  229. beacon_ie->ie_index = cpu_to_le16(beacon_idx);
  230. beacon_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_BEACON);
  231. beacon_ie->ie_length =
  232. cpu_to_le16(params->beacon.beacon_ies_len);
  233. memcpy(beacon_ie->ie_buffer, params->beacon.beacon_ies,
  234. params->beacon.beacon_ies_len);
  235. }
  236. if (params->beacon.proberesp_ies && params->beacon.proberesp_ies_len) {
  237. pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  238. if (!pr_ie) {
  239. ret = -ENOMEM;
  240. goto done;
  241. }
  242. pr_ie->ie_index = cpu_to_le16(pr_idx);
  243. pr_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_PROBE_RESP);
  244. pr_ie->ie_length =
  245. cpu_to_le16(params->beacon.proberesp_ies_len);
  246. memcpy(pr_ie->ie_buffer, params->beacon.proberesp_ies,
  247. params->beacon.proberesp_ies_len);
  248. }
  249. if (params->beacon.assocresp_ies && params->beacon.assocresp_ies_len) {
  250. ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  251. if (!ar_ie) {
  252. ret = -ENOMEM;
  253. goto done;
  254. }
  255. ar_ie->ie_index = cpu_to_le16(ar_idx);
  256. mask = MGMT_MASK_ASSOC_RESP | MGMT_MASK_REASSOC_RESP;
  257. ar_ie->mgmt_subtype_mask = cpu_to_le16(mask);
  258. ar_ie->ie_length =
  259. cpu_to_le16(params->beacon.assocresp_ies_len);
  260. memcpy(ar_ie->ie_buffer, params->beacon.assocresp_ies,
  261. params->beacon.assocresp_ies_len);
  262. }
  263. if (beacon_ie || pr_ie || ar_ie) {
  264. ret = mwifiex_update_uap_custom_ie(priv, beacon_ie,
  265. &beacon_idx, pr_ie,
  266. &pr_idx, ar_ie, &ar_idx);
  267. if (ret)
  268. goto done;
  269. }
  270. priv->beacon_idx = beacon_idx;
  271. priv->proberesp_idx = pr_idx;
  272. priv->assocresp_idx = ar_idx;
  273. done:
  274. kfree(beacon_ie);
  275. kfree(pr_ie);
  276. kfree(ar_ie);
  277. kfree(rsn_ie);
  278. return ret;
  279. }
  280. /* This function removes management IE set */
  281. int mwifiex_del_mgmt_ies(struct mwifiex_private *priv)
  282. {
  283. struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
  284. struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL;
  285. int ret = 0;
  286. if (priv->rsn_idx != MWIFIEX_AUTO_IDX_MASK) {
  287. rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  288. if (!rsn_ie)
  289. return -ENOMEM;
  290. rsn_ie->ie_index = cpu_to_le16(priv->rsn_idx);
  291. rsn_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  292. rsn_ie->ie_length = 0;
  293. if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &priv->rsn_idx,
  294. NULL, &priv->proberesp_idx,
  295. NULL, &priv->assocresp_idx)) {
  296. ret = -1;
  297. goto done;
  298. }
  299. priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
  300. }
  301. if (priv->beacon_idx != MWIFIEX_AUTO_IDX_MASK) {
  302. beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  303. if (!beacon_ie) {
  304. ret = -ENOMEM;
  305. goto done;
  306. }
  307. beacon_ie->ie_index = cpu_to_le16(priv->beacon_idx);
  308. beacon_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  309. beacon_ie->ie_length = 0;
  310. }
  311. if (priv->proberesp_idx != MWIFIEX_AUTO_IDX_MASK) {
  312. pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  313. if (!pr_ie) {
  314. ret = -ENOMEM;
  315. goto done;
  316. }
  317. pr_ie->ie_index = cpu_to_le16(priv->proberesp_idx);
  318. pr_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  319. pr_ie->ie_length = 0;
  320. }
  321. if (priv->assocresp_idx != MWIFIEX_AUTO_IDX_MASK) {
  322. ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  323. if (!ar_ie) {
  324. ret = -ENOMEM;
  325. goto done;
  326. }
  327. ar_ie->ie_index = cpu_to_le16(priv->assocresp_idx);
  328. ar_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  329. ar_ie->ie_length = 0;
  330. }
  331. if (beacon_ie || pr_ie || ar_ie)
  332. ret = mwifiex_update_uap_custom_ie(priv,
  333. beacon_ie, &priv->beacon_idx,
  334. pr_ie, &priv->proberesp_idx,
  335. ar_ie, &priv->assocresp_idx);
  336. done:
  337. kfree(beacon_ie);
  338. kfree(pr_ie);
  339. kfree(ar_ie);
  340. kfree(rsn_ie);
  341. return ret;
  342. }