ie.c 14 KB

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