ie.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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, *gen_ie = NULL;
  196. struct ieee_types_header *rsn_ie = NULL, *wpa_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, ie_len = 0;
  200. const u8 *vendor_ie;
  201. int ret = 0;
  202. if (params->beacon.tail && params->beacon.tail_len) {
  203. gen_ie = kzalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  204. if (!gen_ie)
  205. return -ENOMEM;
  206. gen_ie->ie_index = cpu_to_le16(rsn_idx);
  207. mask = MGMT_MASK_BEACON | MGMT_MASK_PROBE_RESP |
  208. MGMT_MASK_ASSOC_RESP;
  209. gen_ie->mgmt_subtype_mask = cpu_to_le16(mask);
  210. rsn_ie = (void *)cfg80211_find_ie(WLAN_EID_RSN,
  211. params->beacon.tail,
  212. params->beacon.tail_len);
  213. if (rsn_ie) {
  214. memcpy(gen_ie->ie_buffer, rsn_ie, rsn_ie->len + 2);
  215. ie_len = rsn_ie->len + 2;
  216. gen_ie->ie_length = cpu_to_le16(ie_len);
  217. }
  218. vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  219. WLAN_OUI_TYPE_MICROSOFT_WPA,
  220. params->beacon.tail,
  221. params->beacon.tail_len);
  222. if (vendor_ie) {
  223. wpa_ie = (struct ieee_types_header *)vendor_ie;
  224. memcpy(gen_ie->ie_buffer + ie_len,
  225. wpa_ie, wpa_ie->len + 2);
  226. ie_len += wpa_ie->len + 2;
  227. gen_ie->ie_length = cpu_to_le16(ie_len);
  228. }
  229. if (rsn_ie || wpa_ie) {
  230. if (mwifiex_update_uap_custom_ie(priv, gen_ie, &rsn_idx,
  231. NULL, NULL,
  232. NULL, NULL)) {
  233. ret = -1;
  234. goto done;
  235. }
  236. priv->rsn_idx = rsn_idx;
  237. }
  238. }
  239. if (params->beacon.beacon_ies && params->beacon.beacon_ies_len) {
  240. beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  241. if (!beacon_ie) {
  242. ret = -ENOMEM;
  243. goto done;
  244. }
  245. beacon_ie->ie_index = cpu_to_le16(beacon_idx);
  246. beacon_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_BEACON);
  247. beacon_ie->ie_length =
  248. cpu_to_le16(params->beacon.beacon_ies_len);
  249. memcpy(beacon_ie->ie_buffer, params->beacon.beacon_ies,
  250. params->beacon.beacon_ies_len);
  251. }
  252. if (params->beacon.proberesp_ies && params->beacon.proberesp_ies_len) {
  253. pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  254. if (!pr_ie) {
  255. ret = -ENOMEM;
  256. goto done;
  257. }
  258. pr_ie->ie_index = cpu_to_le16(pr_idx);
  259. pr_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_PROBE_RESP);
  260. pr_ie->ie_length =
  261. cpu_to_le16(params->beacon.proberesp_ies_len);
  262. memcpy(pr_ie->ie_buffer, params->beacon.proberesp_ies,
  263. params->beacon.proberesp_ies_len);
  264. }
  265. if (params->beacon.assocresp_ies && params->beacon.assocresp_ies_len) {
  266. ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  267. if (!ar_ie) {
  268. ret = -ENOMEM;
  269. goto done;
  270. }
  271. ar_ie->ie_index = cpu_to_le16(ar_idx);
  272. mask = MGMT_MASK_ASSOC_RESP | MGMT_MASK_REASSOC_RESP;
  273. ar_ie->mgmt_subtype_mask = cpu_to_le16(mask);
  274. ar_ie->ie_length =
  275. cpu_to_le16(params->beacon.assocresp_ies_len);
  276. memcpy(ar_ie->ie_buffer, params->beacon.assocresp_ies,
  277. params->beacon.assocresp_ies_len);
  278. }
  279. if (beacon_ie || pr_ie || ar_ie) {
  280. ret = mwifiex_update_uap_custom_ie(priv, beacon_ie,
  281. &beacon_idx, pr_ie,
  282. &pr_idx, ar_ie, &ar_idx);
  283. if (ret)
  284. goto done;
  285. }
  286. priv->beacon_idx = beacon_idx;
  287. priv->proberesp_idx = pr_idx;
  288. priv->assocresp_idx = ar_idx;
  289. done:
  290. kfree(beacon_ie);
  291. kfree(pr_ie);
  292. kfree(ar_ie);
  293. kfree(gen_ie);
  294. return ret;
  295. }
  296. /* This function removes management IE set */
  297. int mwifiex_del_mgmt_ies(struct mwifiex_private *priv)
  298. {
  299. struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
  300. struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL;
  301. int ret = 0;
  302. if (priv->rsn_idx != MWIFIEX_AUTO_IDX_MASK) {
  303. rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  304. if (!rsn_ie)
  305. return -ENOMEM;
  306. rsn_ie->ie_index = cpu_to_le16(priv->rsn_idx);
  307. rsn_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  308. rsn_ie->ie_length = 0;
  309. if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &priv->rsn_idx,
  310. NULL, &priv->proberesp_idx,
  311. NULL, &priv->assocresp_idx)) {
  312. ret = -1;
  313. goto done;
  314. }
  315. priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
  316. }
  317. if (priv->beacon_idx != MWIFIEX_AUTO_IDX_MASK) {
  318. beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  319. if (!beacon_ie) {
  320. ret = -ENOMEM;
  321. goto done;
  322. }
  323. beacon_ie->ie_index = cpu_to_le16(priv->beacon_idx);
  324. beacon_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  325. beacon_ie->ie_length = 0;
  326. }
  327. if (priv->proberesp_idx != MWIFIEX_AUTO_IDX_MASK) {
  328. pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  329. if (!pr_ie) {
  330. ret = -ENOMEM;
  331. goto done;
  332. }
  333. pr_ie->ie_index = cpu_to_le16(priv->proberesp_idx);
  334. pr_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  335. pr_ie->ie_length = 0;
  336. }
  337. if (priv->assocresp_idx != MWIFIEX_AUTO_IDX_MASK) {
  338. ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  339. if (!ar_ie) {
  340. ret = -ENOMEM;
  341. goto done;
  342. }
  343. ar_ie->ie_index = cpu_to_le16(priv->assocresp_idx);
  344. ar_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  345. ar_ie->ie_length = 0;
  346. }
  347. if (beacon_ie || pr_ie || ar_ie)
  348. ret = mwifiex_update_uap_custom_ie(priv,
  349. beacon_ie, &priv->beacon_idx,
  350. pr_ie, &priv->proberesp_idx,
  351. ar_ie, &priv->assocresp_idx);
  352. done:
  353. kfree(beacon_ie);
  354. kfree(pr_ie);
  355. kfree(ar_ie);
  356. kfree(rsn_ie);
  357. return ret;
  358. }