ie.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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(ie->ie_length);
  49. if (mask == MWIFIEX_AUTO_IDX_MASK)
  50. continue;
  51. if (mask == subtype_mask) {
  52. if (len > IEEE_MAX_IE_SIZE)
  53. continue;
  54. *index = i;
  55. return 0;
  56. }
  57. if (!priv->mgmt_ie[i].ie_length) {
  58. if (mwifiex_ie_index_used_by_other_intf(priv, i))
  59. continue;
  60. *index = i;
  61. return 0;
  62. }
  63. }
  64. return -1;
  65. }
  66. /* This function prepares IE data buffer for command to be sent to FW */
  67. static int
  68. mwifiex_update_autoindex_ies(struct mwifiex_private *priv,
  69. struct mwifiex_ie_list *ie_list)
  70. {
  71. u16 travel_len, index, mask;
  72. s16 input_len;
  73. struct mwifiex_ie *ie;
  74. u8 *tmp;
  75. input_len = le16_to_cpu(ie_list->len);
  76. travel_len = sizeof(struct host_cmd_tlv);
  77. ie_list->len = 0;
  78. while (input_len > 0) {
  79. ie = (struct mwifiex_ie *)(((u8 *)ie_list) + travel_len);
  80. input_len -= le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE;
  81. travel_len += le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE;
  82. index = le16_to_cpu(ie->ie_index);
  83. mask = le16_to_cpu(ie->mgmt_subtype_mask);
  84. if (index == MWIFIEX_AUTO_IDX_MASK) {
  85. /* automatic addition */
  86. if (mwifiex_ie_get_autoidx(priv, mask, ie, &index))
  87. return -1;
  88. if (index == MWIFIEX_AUTO_IDX_MASK)
  89. return -1;
  90. tmp = (u8 *)&priv->mgmt_ie[index].ie_buffer;
  91. memcpy(tmp, &ie->ie_buffer, le16_to_cpu(ie->ie_length));
  92. priv->mgmt_ie[index].ie_length = ie->ie_length;
  93. priv->mgmt_ie[index].ie_index = cpu_to_le16(index);
  94. priv->mgmt_ie[index].mgmt_subtype_mask =
  95. cpu_to_le16(mask);
  96. ie->ie_index = cpu_to_le16(index);
  97. } else {
  98. if (mask != MWIFIEX_DELETE_MASK)
  99. return -1;
  100. /*
  101. * Check if this index is being used on any
  102. * other interface.
  103. */
  104. if (mwifiex_ie_index_used_by_other_intf(priv, index))
  105. return -1;
  106. ie->ie_length = 0;
  107. memcpy(&priv->mgmt_ie[index], ie,
  108. sizeof(struct mwifiex_ie));
  109. }
  110. le16_add_cpu(&ie_list->len,
  111. le16_to_cpu(priv->mgmt_ie[index].ie_length) +
  112. MWIFIEX_IE_HDR_SIZE);
  113. }
  114. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
  115. return mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  116. HostCmd_ACT_GEN_SET,
  117. UAP_CUSTOM_IE_I, ie_list);
  118. return 0;
  119. }
  120. /* Copy individual custom IEs for beacon, probe response and assoc response
  121. * and prepare single structure for IE setting.
  122. * This function also updates allocated IE indices from driver.
  123. */
  124. static int
  125. mwifiex_update_uap_custom_ie(struct mwifiex_private *priv,
  126. struct mwifiex_ie *beacon_ie, u16 *beacon_idx,
  127. struct mwifiex_ie *pr_ie, u16 *probe_idx,
  128. struct mwifiex_ie *ar_ie, u16 *assoc_idx)
  129. {
  130. struct mwifiex_ie_list *ap_custom_ie;
  131. u8 *pos;
  132. u16 len;
  133. int ret;
  134. ap_custom_ie = kzalloc(sizeof(*ap_custom_ie), GFP_KERNEL);
  135. if (!ap_custom_ie)
  136. return -ENOMEM;
  137. ap_custom_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  138. pos = (u8 *)ap_custom_ie->ie_list;
  139. if (beacon_ie) {
  140. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  141. le16_to_cpu(beacon_ie->ie_length);
  142. memcpy(pos, beacon_ie, len);
  143. pos += len;
  144. le16_add_cpu(&ap_custom_ie->len, len);
  145. }
  146. if (pr_ie) {
  147. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  148. le16_to_cpu(pr_ie->ie_length);
  149. memcpy(pos, pr_ie, len);
  150. pos += len;
  151. le16_add_cpu(&ap_custom_ie->len, len);
  152. }
  153. if (ar_ie) {
  154. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  155. le16_to_cpu(ar_ie->ie_length);
  156. memcpy(pos, ar_ie, len);
  157. pos += len;
  158. le16_add_cpu(&ap_custom_ie->len, len);
  159. }
  160. ret = mwifiex_update_autoindex_ies(priv, ap_custom_ie);
  161. pos = (u8 *)(&ap_custom_ie->ie_list[0].ie_index);
  162. if (beacon_ie && *beacon_idx == MWIFIEX_AUTO_IDX_MASK) {
  163. /* save beacon ie index after auto-indexing */
  164. *beacon_idx = le16_to_cpu(ap_custom_ie->ie_list[0].ie_index);
  165. len = sizeof(*beacon_ie) - IEEE_MAX_IE_SIZE +
  166. le16_to_cpu(beacon_ie->ie_length);
  167. pos += len;
  168. }
  169. if (pr_ie && le16_to_cpu(pr_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK) {
  170. /* save probe resp ie index after auto-indexing */
  171. *probe_idx = *((u16 *)pos);
  172. len = sizeof(*pr_ie) - IEEE_MAX_IE_SIZE +
  173. le16_to_cpu(pr_ie->ie_length);
  174. pos += len;
  175. }
  176. if (ar_ie && le16_to_cpu(ar_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK)
  177. /* save assoc resp ie index after auto-indexing */
  178. *assoc_idx = *((u16 *)pos);
  179. kfree(ap_custom_ie);
  180. return ret;
  181. }
  182. /* This function checks if the vendor specified IE is present in passed buffer
  183. * and copies it to mwifiex_ie structure.
  184. * Function takes pointer to struct mwifiex_ie pointer as argument.
  185. * If the vendor specified IE is present then memory is allocated for
  186. * mwifiex_ie pointer and filled in with IE. Caller should take care of freeing
  187. * this memory.
  188. */
  189. static int mwifiex_update_vs_ie(const u8 *ies, int ies_len,
  190. struct mwifiex_ie **ie_ptr, u16 mask,
  191. unsigned int oui, u8 oui_type)
  192. {
  193. struct ieee_types_header *vs_ie;
  194. struct mwifiex_ie *ie = *ie_ptr;
  195. const u8 *vendor_ie;
  196. vendor_ie = cfg80211_find_vendor_ie(oui, oui_type, ies, ies_len);
  197. if (vendor_ie) {
  198. if (!*ie_ptr) {
  199. *ie_ptr = kzalloc(sizeof(struct mwifiex_ie),
  200. GFP_KERNEL);
  201. if (!*ie_ptr)
  202. return -ENOMEM;
  203. ie = *ie_ptr;
  204. }
  205. vs_ie = (struct ieee_types_header *)vendor_ie;
  206. memcpy(ie->ie_buffer + le16_to_cpu(ie->ie_length),
  207. vs_ie, vs_ie->len + 2);
  208. le16_add_cpu(&ie->ie_length, vs_ie->len + 2);
  209. ie->mgmt_subtype_mask = cpu_to_le16(mask);
  210. ie->ie_index = cpu_to_le16(MWIFIEX_AUTO_IDX_MASK);
  211. }
  212. *ie_ptr = ie;
  213. return 0;
  214. }
  215. /* This function parses beacon IEs, probe response IEs, association response IEs
  216. * from cfg80211_ap_settings->beacon and sets these IE to FW.
  217. */
  218. static int mwifiex_set_mgmt_beacon_data_ies(struct mwifiex_private *priv,
  219. struct cfg80211_beacon_data *data)
  220. {
  221. struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL, *ar_ie = NULL;
  222. u16 beacon_idx = MWIFIEX_AUTO_IDX_MASK, pr_idx = MWIFIEX_AUTO_IDX_MASK;
  223. u16 ar_idx = MWIFIEX_AUTO_IDX_MASK;
  224. int ret = 0;
  225. if (data->beacon_ies && data->beacon_ies_len) {
  226. mwifiex_update_vs_ie(data->beacon_ies, data->beacon_ies_len,
  227. &beacon_ie, MGMT_MASK_BEACON,
  228. WLAN_OUI_MICROSOFT,
  229. WLAN_OUI_TYPE_MICROSOFT_WPS);
  230. mwifiex_update_vs_ie(data->beacon_ies, data->beacon_ies_len,
  231. &beacon_ie, MGMT_MASK_BEACON,
  232. WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P);
  233. }
  234. if (data->proberesp_ies && data->proberesp_ies_len) {
  235. mwifiex_update_vs_ie(data->proberesp_ies,
  236. data->proberesp_ies_len, &pr_ie,
  237. MGMT_MASK_PROBE_RESP, WLAN_OUI_MICROSOFT,
  238. WLAN_OUI_TYPE_MICROSOFT_WPS);
  239. mwifiex_update_vs_ie(data->proberesp_ies,
  240. data->proberesp_ies_len, &pr_ie,
  241. MGMT_MASK_PROBE_RESP,
  242. WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P);
  243. }
  244. if (data->assocresp_ies && data->assocresp_ies_len) {
  245. mwifiex_update_vs_ie(data->assocresp_ies,
  246. data->assocresp_ies_len, &ar_ie,
  247. MGMT_MASK_ASSOC_RESP |
  248. MGMT_MASK_REASSOC_RESP,
  249. WLAN_OUI_MICROSOFT,
  250. WLAN_OUI_TYPE_MICROSOFT_WPS);
  251. mwifiex_update_vs_ie(data->assocresp_ies,
  252. data->assocresp_ies_len, &ar_ie,
  253. MGMT_MASK_ASSOC_RESP |
  254. MGMT_MASK_REASSOC_RESP, WLAN_OUI_WFA,
  255. WLAN_OUI_TYPE_WFA_P2P);
  256. }
  257. if (beacon_ie || pr_ie || ar_ie) {
  258. ret = mwifiex_update_uap_custom_ie(priv, beacon_ie,
  259. &beacon_idx, pr_ie,
  260. &pr_idx, ar_ie, &ar_idx);
  261. if (ret)
  262. goto done;
  263. }
  264. priv->beacon_idx = beacon_idx;
  265. priv->proberesp_idx = pr_idx;
  266. priv->assocresp_idx = ar_idx;
  267. done:
  268. kfree(beacon_ie);
  269. kfree(pr_ie);
  270. kfree(ar_ie);
  271. return ret;
  272. }
  273. /* This function parses different IEs-tail IEs, beacon IEs, probe response IEs,
  274. * association response IEs from cfg80211_ap_settings function and sets these IE
  275. * to FW.
  276. */
  277. int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
  278. struct cfg80211_beacon_data *info)
  279. {
  280. struct mwifiex_ie *gen_ie;
  281. struct ieee_types_header *rsn_ie, *wpa_ie = NULL;
  282. u16 rsn_idx = MWIFIEX_AUTO_IDX_MASK, ie_len = 0;
  283. const u8 *vendor_ie;
  284. if (info->tail && info->tail_len) {
  285. gen_ie = kzalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  286. if (!gen_ie)
  287. return -ENOMEM;
  288. gen_ie->ie_index = cpu_to_le16(rsn_idx);
  289. gen_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_BEACON |
  290. MGMT_MASK_PROBE_RESP |
  291. MGMT_MASK_ASSOC_RESP);
  292. rsn_ie = (void *)cfg80211_find_ie(WLAN_EID_RSN,
  293. info->tail, info->tail_len);
  294. if (rsn_ie) {
  295. memcpy(gen_ie->ie_buffer, rsn_ie, rsn_ie->len + 2);
  296. ie_len = rsn_ie->len + 2;
  297. gen_ie->ie_length = cpu_to_le16(ie_len);
  298. }
  299. vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  300. WLAN_OUI_TYPE_MICROSOFT_WPA,
  301. info->tail,
  302. info->tail_len);
  303. if (vendor_ie) {
  304. wpa_ie = (struct ieee_types_header *)vendor_ie;
  305. memcpy(gen_ie->ie_buffer + ie_len,
  306. wpa_ie, wpa_ie->len + 2);
  307. ie_len += wpa_ie->len + 2;
  308. gen_ie->ie_length = cpu_to_le16(ie_len);
  309. }
  310. if (rsn_ie || wpa_ie) {
  311. if (mwifiex_update_uap_custom_ie(priv, gen_ie, &rsn_idx,
  312. NULL, NULL,
  313. NULL, NULL)) {
  314. kfree(gen_ie);
  315. return -1;
  316. }
  317. priv->rsn_idx = rsn_idx;
  318. }
  319. kfree(gen_ie);
  320. }
  321. return mwifiex_set_mgmt_beacon_data_ies(priv, info);
  322. }
  323. /* This function removes management IE set */
  324. int mwifiex_del_mgmt_ies(struct mwifiex_private *priv)
  325. {
  326. struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
  327. struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL;
  328. int ret = 0;
  329. if (priv->rsn_idx != MWIFIEX_AUTO_IDX_MASK) {
  330. rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  331. if (!rsn_ie)
  332. return -ENOMEM;
  333. rsn_ie->ie_index = cpu_to_le16(priv->rsn_idx);
  334. rsn_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  335. rsn_ie->ie_length = 0;
  336. if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &priv->rsn_idx,
  337. NULL, &priv->proberesp_idx,
  338. NULL, &priv->assocresp_idx)) {
  339. ret = -1;
  340. goto done;
  341. }
  342. priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
  343. }
  344. if (priv->beacon_idx != MWIFIEX_AUTO_IDX_MASK) {
  345. beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  346. if (!beacon_ie) {
  347. ret = -ENOMEM;
  348. goto done;
  349. }
  350. beacon_ie->ie_index = cpu_to_le16(priv->beacon_idx);
  351. beacon_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  352. beacon_ie->ie_length = 0;
  353. }
  354. if (priv->proberesp_idx != MWIFIEX_AUTO_IDX_MASK) {
  355. pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  356. if (!pr_ie) {
  357. ret = -ENOMEM;
  358. goto done;
  359. }
  360. pr_ie->ie_index = cpu_to_le16(priv->proberesp_idx);
  361. pr_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  362. pr_ie->ie_length = 0;
  363. }
  364. if (priv->assocresp_idx != MWIFIEX_AUTO_IDX_MASK) {
  365. ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  366. if (!ar_ie) {
  367. ret = -ENOMEM;
  368. goto done;
  369. }
  370. ar_ie->ie_index = cpu_to_le16(priv->assocresp_idx);
  371. ar_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  372. ar_ie->ie_length = 0;
  373. }
  374. if (beacon_ie || pr_ie || ar_ie)
  375. ret = mwifiex_update_uap_custom_ie(priv,
  376. beacon_ie, &priv->beacon_idx,
  377. pr_ie, &priv->proberesp_idx,
  378. ar_ie, &priv->assocresp_idx);
  379. done:
  380. kfree(beacon_ie);
  381. kfree(pr_ie);
  382. kfree(ar_ie);
  383. kfree(rsn_ie);
  384. return ret;
  385. }