ie.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*
  2. * Marvell Wireless LAN device driver: management IE handling- setting and
  3. * deleting IE.
  4. *
  5. * Copyright (C) 2012-2014, 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, tlv_len;
  73. struct mwifiex_ie *ie;
  74. u8 *tmp;
  75. input_len = le16_to_cpu(ie_list->len);
  76. travel_len = sizeof(struct mwifiex_ie_types_header);
  77. ie_list->len = 0;
  78. while (input_len >= sizeof(struct mwifiex_ie_types_header)) {
  79. ie = (struct mwifiex_ie *)(((u8 *)ie_list) + travel_len);
  80. tlv_len = le16_to_cpu(ie->ie_length);
  81. travel_len += tlv_len + MWIFIEX_IE_HDR_SIZE;
  82. if (input_len < tlv_len + MWIFIEX_IE_HDR_SIZE)
  83. return -1;
  84. index = le16_to_cpu(ie->ie_index);
  85. mask = le16_to_cpu(ie->mgmt_subtype_mask);
  86. if (index == MWIFIEX_AUTO_IDX_MASK) {
  87. /* automatic addition */
  88. if (mwifiex_ie_get_autoidx(priv, mask, ie, &index))
  89. return -1;
  90. if (index == MWIFIEX_AUTO_IDX_MASK)
  91. return -1;
  92. tmp = (u8 *)&priv->mgmt_ie[index].ie_buffer;
  93. memcpy(tmp, &ie->ie_buffer, le16_to_cpu(ie->ie_length));
  94. priv->mgmt_ie[index].ie_length = ie->ie_length;
  95. priv->mgmt_ie[index].ie_index = cpu_to_le16(index);
  96. priv->mgmt_ie[index].mgmt_subtype_mask =
  97. cpu_to_le16(mask);
  98. ie->ie_index = cpu_to_le16(index);
  99. } else {
  100. if (mask != MWIFIEX_DELETE_MASK)
  101. return -1;
  102. /*
  103. * Check if this index is being used on any
  104. * other interface.
  105. */
  106. if (mwifiex_ie_index_used_by_other_intf(priv, index))
  107. return -1;
  108. ie->ie_length = 0;
  109. memcpy(&priv->mgmt_ie[index], ie,
  110. sizeof(struct mwifiex_ie));
  111. }
  112. le16_unaligned_add_cpu(&ie_list->len,
  113. le16_to_cpu(
  114. priv->mgmt_ie[index].ie_length) +
  115. MWIFIEX_IE_HDR_SIZE);
  116. input_len -= tlv_len + MWIFIEX_IE_HDR_SIZE;
  117. }
  118. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
  119. return mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  120. HostCmd_ACT_GEN_SET,
  121. UAP_CUSTOM_IE_I, ie_list, true);
  122. return 0;
  123. }
  124. /* Copy individual custom IEs for beacon, probe response and assoc response
  125. * and prepare single structure for IE setting.
  126. * This function also updates allocated IE indices from driver.
  127. */
  128. static int
  129. mwifiex_update_uap_custom_ie(struct mwifiex_private *priv,
  130. struct mwifiex_ie *beacon_ie, u16 *beacon_idx,
  131. struct mwifiex_ie *pr_ie, u16 *probe_idx,
  132. struct mwifiex_ie *ar_ie, u16 *assoc_idx)
  133. {
  134. struct mwifiex_ie_list *ap_custom_ie;
  135. u8 *pos;
  136. u16 len;
  137. int ret;
  138. ap_custom_ie = kzalloc(sizeof(*ap_custom_ie), GFP_KERNEL);
  139. if (!ap_custom_ie)
  140. return -ENOMEM;
  141. ap_custom_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  142. pos = (u8 *)ap_custom_ie->ie_list;
  143. if (beacon_ie) {
  144. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  145. le16_to_cpu(beacon_ie->ie_length);
  146. memcpy(pos, beacon_ie, len);
  147. pos += len;
  148. le16_unaligned_add_cpu(&ap_custom_ie->len, len);
  149. }
  150. if (pr_ie) {
  151. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  152. le16_to_cpu(pr_ie->ie_length);
  153. memcpy(pos, pr_ie, len);
  154. pos += len;
  155. le16_unaligned_add_cpu(&ap_custom_ie->len, len);
  156. }
  157. if (ar_ie) {
  158. len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
  159. le16_to_cpu(ar_ie->ie_length);
  160. memcpy(pos, ar_ie, len);
  161. pos += len;
  162. le16_unaligned_add_cpu(&ap_custom_ie->len, len);
  163. }
  164. ret = mwifiex_update_autoindex_ies(priv, ap_custom_ie);
  165. pos = (u8 *)(&ap_custom_ie->ie_list[0].ie_index);
  166. if (beacon_ie && *beacon_idx == MWIFIEX_AUTO_IDX_MASK) {
  167. /* save beacon ie index after auto-indexing */
  168. *beacon_idx = le16_to_cpu(ap_custom_ie->ie_list[0].ie_index);
  169. len = sizeof(*beacon_ie) - IEEE_MAX_IE_SIZE +
  170. le16_to_cpu(beacon_ie->ie_length);
  171. pos += len;
  172. }
  173. if (pr_ie && le16_to_cpu(pr_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK) {
  174. /* save probe resp ie index after auto-indexing */
  175. *probe_idx = *((u16 *)pos);
  176. len = sizeof(*pr_ie) - IEEE_MAX_IE_SIZE +
  177. le16_to_cpu(pr_ie->ie_length);
  178. pos += len;
  179. }
  180. if (ar_ie && le16_to_cpu(ar_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK)
  181. /* save assoc resp ie index after auto-indexing */
  182. *assoc_idx = *((u16 *)pos);
  183. kfree(ap_custom_ie);
  184. return ret;
  185. }
  186. /* This function checks if the vendor specified IE is present in passed buffer
  187. * and copies it to mwifiex_ie structure.
  188. * Function takes pointer to struct mwifiex_ie pointer as argument.
  189. * If the vendor specified IE is present then memory is allocated for
  190. * mwifiex_ie pointer and filled in with IE. Caller should take care of freeing
  191. * this memory.
  192. */
  193. static int mwifiex_update_vs_ie(const u8 *ies, int ies_len,
  194. struct mwifiex_ie **ie_ptr, u16 mask,
  195. unsigned int oui, u8 oui_type)
  196. {
  197. struct ieee_types_header *vs_ie;
  198. struct mwifiex_ie *ie = *ie_ptr;
  199. const u8 *vendor_ie;
  200. vendor_ie = cfg80211_find_vendor_ie(oui, oui_type, ies, ies_len);
  201. if (vendor_ie) {
  202. if (!*ie_ptr) {
  203. *ie_ptr = kzalloc(sizeof(struct mwifiex_ie),
  204. GFP_KERNEL);
  205. if (!*ie_ptr)
  206. return -ENOMEM;
  207. ie = *ie_ptr;
  208. }
  209. vs_ie = (struct ieee_types_header *)vendor_ie;
  210. memcpy(ie->ie_buffer + le16_to_cpu(ie->ie_length),
  211. vs_ie, vs_ie->len + 2);
  212. le16_unaligned_add_cpu(&ie->ie_length, vs_ie->len + 2);
  213. ie->mgmt_subtype_mask = cpu_to_le16(mask);
  214. ie->ie_index = cpu_to_le16(MWIFIEX_AUTO_IDX_MASK);
  215. }
  216. *ie_ptr = ie;
  217. return 0;
  218. }
  219. /* This function parses beacon IEs, probe response IEs, association response IEs
  220. * from cfg80211_ap_settings->beacon and sets these IE to FW.
  221. */
  222. static int mwifiex_set_mgmt_beacon_data_ies(struct mwifiex_private *priv,
  223. struct cfg80211_beacon_data *data)
  224. {
  225. struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL, *ar_ie = NULL;
  226. u16 beacon_idx = MWIFIEX_AUTO_IDX_MASK, pr_idx = MWIFIEX_AUTO_IDX_MASK;
  227. u16 ar_idx = MWIFIEX_AUTO_IDX_MASK;
  228. int ret = 0;
  229. if (data->beacon_ies && data->beacon_ies_len) {
  230. mwifiex_update_vs_ie(data->beacon_ies, data->beacon_ies_len,
  231. &beacon_ie, MGMT_MASK_BEACON,
  232. WLAN_OUI_MICROSOFT,
  233. WLAN_OUI_TYPE_MICROSOFT_WPS);
  234. mwifiex_update_vs_ie(data->beacon_ies, data->beacon_ies_len,
  235. &beacon_ie, MGMT_MASK_BEACON,
  236. WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P);
  237. }
  238. if (data->proberesp_ies && data->proberesp_ies_len) {
  239. mwifiex_update_vs_ie(data->proberesp_ies,
  240. data->proberesp_ies_len, &pr_ie,
  241. MGMT_MASK_PROBE_RESP, WLAN_OUI_MICROSOFT,
  242. WLAN_OUI_TYPE_MICROSOFT_WPS);
  243. mwifiex_update_vs_ie(data->proberesp_ies,
  244. data->proberesp_ies_len, &pr_ie,
  245. MGMT_MASK_PROBE_RESP,
  246. WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P);
  247. }
  248. if (data->assocresp_ies && data->assocresp_ies_len) {
  249. mwifiex_update_vs_ie(data->assocresp_ies,
  250. data->assocresp_ies_len, &ar_ie,
  251. MGMT_MASK_ASSOC_RESP |
  252. MGMT_MASK_REASSOC_RESP,
  253. WLAN_OUI_MICROSOFT,
  254. WLAN_OUI_TYPE_MICROSOFT_WPS);
  255. mwifiex_update_vs_ie(data->assocresp_ies,
  256. data->assocresp_ies_len, &ar_ie,
  257. MGMT_MASK_ASSOC_RESP |
  258. MGMT_MASK_REASSOC_RESP, WLAN_OUI_WFA,
  259. WLAN_OUI_TYPE_WFA_P2P);
  260. }
  261. if (beacon_ie || pr_ie || ar_ie) {
  262. ret = mwifiex_update_uap_custom_ie(priv, beacon_ie,
  263. &beacon_idx, pr_ie,
  264. &pr_idx, ar_ie, &ar_idx);
  265. if (ret)
  266. goto done;
  267. }
  268. priv->beacon_idx = beacon_idx;
  269. priv->proberesp_idx = pr_idx;
  270. priv->assocresp_idx = ar_idx;
  271. done:
  272. kfree(beacon_ie);
  273. kfree(pr_ie);
  274. kfree(ar_ie);
  275. return ret;
  276. }
  277. /* This function parses head and tail IEs, from cfg80211_beacon_data and sets
  278. * these IE to FW.
  279. */
  280. static int mwifiex_uap_parse_tail_ies(struct mwifiex_private *priv,
  281. struct cfg80211_beacon_data *info)
  282. {
  283. struct mwifiex_ie *gen_ie;
  284. struct ieee_types_header *hdr;
  285. struct ieee80211_vendor_ie *vendorhdr;
  286. u16 gen_idx = MWIFIEX_AUTO_IDX_MASK, ie_len = 0;
  287. int left_len, parsed_len = 0;
  288. if (!info->tail || !info->tail_len)
  289. return 0;
  290. gen_ie = kzalloc(sizeof(*gen_ie), GFP_KERNEL);
  291. if (!gen_ie)
  292. return -ENOMEM;
  293. left_len = info->tail_len;
  294. /* Many IEs are generated in FW by parsing bss configuration.
  295. * Let's not add them here; else we may end up duplicating these IEs
  296. */
  297. while (left_len > sizeof(struct ieee_types_header)) {
  298. hdr = (void *)(info->tail + parsed_len);
  299. switch (hdr->element_id) {
  300. case WLAN_EID_SSID:
  301. case WLAN_EID_SUPP_RATES:
  302. case WLAN_EID_COUNTRY:
  303. case WLAN_EID_PWR_CONSTRAINT:
  304. case WLAN_EID_EXT_SUPP_RATES:
  305. case WLAN_EID_HT_CAPABILITY:
  306. case WLAN_EID_HT_OPERATION:
  307. case WLAN_EID_VHT_CAPABILITY:
  308. case WLAN_EID_VHT_OPERATION:
  309. case WLAN_EID_VENDOR_SPECIFIC:
  310. break;
  311. default:
  312. memcpy(gen_ie->ie_buffer + ie_len, hdr,
  313. hdr->len + sizeof(struct ieee_types_header));
  314. ie_len += hdr->len + sizeof(struct ieee_types_header);
  315. break;
  316. }
  317. left_len -= hdr->len + sizeof(struct ieee_types_header);
  318. parsed_len += hdr->len + sizeof(struct ieee_types_header);
  319. }
  320. /* parse only WPA vendor IE from tail, WMM IE is configured by
  321. * bss_config command
  322. */
  323. vendorhdr = (void *)cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  324. WLAN_OUI_TYPE_MICROSOFT_WPA,
  325. info->tail, info->tail_len);
  326. if (vendorhdr) {
  327. memcpy(gen_ie->ie_buffer + ie_len, vendorhdr,
  328. vendorhdr->len + sizeof(struct ieee_types_header));
  329. ie_len += vendorhdr->len + sizeof(struct ieee_types_header);
  330. }
  331. if (!ie_len) {
  332. kfree(gen_ie);
  333. return 0;
  334. }
  335. gen_ie->ie_index = cpu_to_le16(gen_idx);
  336. gen_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_BEACON |
  337. MGMT_MASK_PROBE_RESP |
  338. MGMT_MASK_ASSOC_RESP);
  339. gen_ie->ie_length = cpu_to_le16(ie_len);
  340. if (mwifiex_update_uap_custom_ie(priv, gen_ie, &gen_idx, NULL, NULL,
  341. NULL, NULL)) {
  342. kfree(gen_ie);
  343. return -1;
  344. }
  345. priv->gen_idx = gen_idx;
  346. kfree(gen_ie);
  347. return 0;
  348. }
  349. /* This function parses different IEs-head & tail IEs, beacon IEs,
  350. * probe response IEs, association response IEs from cfg80211_ap_settings
  351. * function and sets these IE to FW.
  352. */
  353. int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
  354. struct cfg80211_beacon_data *info)
  355. {
  356. int ret;
  357. ret = mwifiex_uap_parse_tail_ies(priv, info);
  358. if (ret)
  359. return ret;
  360. return mwifiex_set_mgmt_beacon_data_ies(priv, info);
  361. }
  362. /* This function removes management IE set */
  363. int mwifiex_del_mgmt_ies(struct mwifiex_private *priv)
  364. {
  365. struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
  366. struct mwifiex_ie *ar_ie = NULL, *gen_ie = NULL;
  367. int ret = 0;
  368. if (priv->gen_idx != MWIFIEX_AUTO_IDX_MASK) {
  369. gen_ie = kmalloc(sizeof(*gen_ie), GFP_KERNEL);
  370. if (!gen_ie)
  371. return -ENOMEM;
  372. gen_ie->ie_index = cpu_to_le16(priv->gen_idx);
  373. gen_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  374. gen_ie->ie_length = 0;
  375. if (mwifiex_update_uap_custom_ie(priv, gen_ie, &priv->gen_idx,
  376. NULL, &priv->proberesp_idx,
  377. NULL, &priv->assocresp_idx)) {
  378. ret = -1;
  379. goto done;
  380. }
  381. priv->gen_idx = MWIFIEX_AUTO_IDX_MASK;
  382. }
  383. if (priv->beacon_idx != MWIFIEX_AUTO_IDX_MASK) {
  384. beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  385. if (!beacon_ie) {
  386. ret = -ENOMEM;
  387. goto done;
  388. }
  389. beacon_ie->ie_index = cpu_to_le16(priv->beacon_idx);
  390. beacon_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  391. beacon_ie->ie_length = 0;
  392. }
  393. if (priv->proberesp_idx != MWIFIEX_AUTO_IDX_MASK) {
  394. pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  395. if (!pr_ie) {
  396. ret = -ENOMEM;
  397. goto done;
  398. }
  399. pr_ie->ie_index = cpu_to_le16(priv->proberesp_idx);
  400. pr_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  401. pr_ie->ie_length = 0;
  402. }
  403. if (priv->assocresp_idx != MWIFIEX_AUTO_IDX_MASK) {
  404. ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
  405. if (!ar_ie) {
  406. ret = -ENOMEM;
  407. goto done;
  408. }
  409. ar_ie->ie_index = cpu_to_le16(priv->assocresp_idx);
  410. ar_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
  411. ar_ie->ie_length = 0;
  412. }
  413. if (beacon_ie || pr_ie || ar_ie)
  414. ret = mwifiex_update_uap_custom_ie(priv,
  415. beacon_ie, &priv->beacon_idx,
  416. pr_ie, &priv->proberesp_idx,
  417. ar_ie, &priv->assocresp_idx);
  418. done:
  419. kfree(gen_ie);
  420. kfree(beacon_ie);
  421. kfree(pr_ie);
  422. kfree(ar_ie);
  423. return ret;
  424. }