/drivers/net/wireless/mwifiex/join.c

http://github.com/mirrors/linux · C · 1471 lines · 890 code · 234 blank · 347 comment · 124 complexity · 3f6f537f2fd02f6b8a8340c93c37efb0 MD5 · raw file

  1. /*
  2. * Marvell Wireless LAN device driver: association and ad-hoc start/join
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. #include "11ac.h"
  27. #define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9)))
  28. /*
  29. * Append a generic IE as a pass through TLV to a TLV buffer.
  30. *
  31. * This function is called from the network join command preparation routine.
  32. *
  33. * If the IE buffer has been setup by the application, this routine appends
  34. * the buffer as a pass through TLV type to the request.
  35. */
  36. static int
  37. mwifiex_cmd_append_generic_ie(struct mwifiex_private *priv, u8 **buffer)
  38. {
  39. int ret_len = 0;
  40. struct mwifiex_ie_types_header ie_header;
  41. /* Null Checks */
  42. if (!buffer)
  43. return 0;
  44. if (!(*buffer))
  45. return 0;
  46. /*
  47. * If there is a generic ie buffer setup, append it to the return
  48. * parameter buffer pointer.
  49. */
  50. if (priv->gen_ie_buf_len) {
  51. dev_dbg(priv->adapter->dev,
  52. "info: %s: append generic ie len %d to %p\n",
  53. __func__, priv->gen_ie_buf_len, *buffer);
  54. /* Wrap the generic IE buffer with a pass through TLV type */
  55. ie_header.type = cpu_to_le16(TLV_TYPE_PASSTHROUGH);
  56. ie_header.len = cpu_to_le16(priv->gen_ie_buf_len);
  57. memcpy(*buffer, &ie_header, sizeof(ie_header));
  58. /* Increment the return size and the return buffer pointer
  59. param */
  60. *buffer += sizeof(ie_header);
  61. ret_len += sizeof(ie_header);
  62. /* Copy the generic IE buffer to the output buffer, advance
  63. pointer */
  64. memcpy(*buffer, priv->gen_ie_buf, priv->gen_ie_buf_len);
  65. /* Increment the return size and the return buffer pointer
  66. param */
  67. *buffer += priv->gen_ie_buf_len;
  68. ret_len += priv->gen_ie_buf_len;
  69. /* Reset the generic IE buffer */
  70. priv->gen_ie_buf_len = 0;
  71. }
  72. /* return the length appended to the buffer */
  73. return ret_len;
  74. }
  75. /*
  76. * Append TSF tracking info from the scan table for the target AP.
  77. *
  78. * This function is called from the network join command preparation routine.
  79. *
  80. * The TSF table TSF sent to the firmware contains two TSF values:
  81. * - The TSF of the target AP from its previous beacon/probe response
  82. * - The TSF timestamp of our local MAC at the time we observed the
  83. * beacon/probe response.
  84. *
  85. * The firmware uses the timestamp values to set an initial TSF value
  86. * in the MAC for the new association after a reassociation attempt.
  87. */
  88. static int
  89. mwifiex_cmd_append_tsf_tlv(struct mwifiex_private *priv, u8 **buffer,
  90. struct mwifiex_bssdescriptor *bss_desc)
  91. {
  92. struct mwifiex_ie_types_tsf_timestamp tsf_tlv;
  93. __le64 tsf_val;
  94. /* Null Checks */
  95. if (buffer == NULL)
  96. return 0;
  97. if (*buffer == NULL)
  98. return 0;
  99. memset(&tsf_tlv, 0x00, sizeof(struct mwifiex_ie_types_tsf_timestamp));
  100. tsf_tlv.header.type = cpu_to_le16(TLV_TYPE_TSFTIMESTAMP);
  101. tsf_tlv.header.len = cpu_to_le16(2 * sizeof(tsf_val));
  102. memcpy(*buffer, &tsf_tlv, sizeof(tsf_tlv.header));
  103. *buffer += sizeof(tsf_tlv.header);
  104. /* TSF at the time when beacon/probe_response was received */
  105. tsf_val = cpu_to_le64(bss_desc->fw_tsf);
  106. memcpy(*buffer, &tsf_val, sizeof(tsf_val));
  107. *buffer += sizeof(tsf_val);
  108. tsf_val = cpu_to_le64(bss_desc->timestamp);
  109. dev_dbg(priv->adapter->dev,
  110. "info: %s: TSF offset calc: %016llx - %016llx\n",
  111. __func__, bss_desc->timestamp, bss_desc->fw_tsf);
  112. memcpy(*buffer, &tsf_val, sizeof(tsf_val));
  113. *buffer += sizeof(tsf_val);
  114. return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val));
  115. }
  116. /*
  117. * This function finds out the common rates between rate1 and rate2.
  118. *
  119. * It will fill common rates in rate1 as output if found.
  120. *
  121. * NOTE: Setting the MSB of the basic rates needs to be taken
  122. * care of, either before or after calling this function.
  123. */
  124. static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
  125. u32 rate1_size, u8 *rate2, u32 rate2_size)
  126. {
  127. int ret;
  128. u8 *ptr = rate1, *tmp;
  129. u32 i, j;
  130. tmp = kmemdup(rate1, rate1_size, GFP_KERNEL);
  131. if (!tmp) {
  132. dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
  133. return -ENOMEM;
  134. }
  135. memset(rate1, 0, rate1_size);
  136. for (i = 0; i < rate2_size && rate2[i]; i++) {
  137. for (j = 0; j < rate1_size && tmp[j]; j++) {
  138. /* Check common rate, excluding the bit for
  139. basic rate */
  140. if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
  141. *rate1++ = tmp[j];
  142. break;
  143. }
  144. }
  145. }
  146. dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
  147. priv->data_rate);
  148. if (!priv->is_data_rate_auto) {
  149. while (*ptr) {
  150. if ((*ptr & 0x7f) == priv->data_rate) {
  151. ret = 0;
  152. goto done;
  153. }
  154. ptr++;
  155. }
  156. dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
  157. " is not compatible with the network\n",
  158. priv->data_rate);
  159. ret = -1;
  160. goto done;
  161. }
  162. ret = 0;
  163. done:
  164. kfree(tmp);
  165. return ret;
  166. }
  167. /*
  168. * This function creates the intersection of the rates supported by a
  169. * target BSS and our adapter settings for use in an assoc/join command.
  170. */
  171. static int
  172. mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
  173. struct mwifiex_bssdescriptor *bss_desc,
  174. u8 *out_rates, u32 *out_rates_size)
  175. {
  176. u8 card_rates[MWIFIEX_SUPPORTED_RATES];
  177. u32 card_rates_size;
  178. /* Copy AP supported rates */
  179. memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES);
  180. /* Get the STA supported rates */
  181. card_rates_size = mwifiex_get_active_data_rates(priv, card_rates);
  182. /* Get the common rates between AP and STA supported rates */
  183. if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES,
  184. card_rates, card_rates_size)) {
  185. *out_rates_size = 0;
  186. dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
  187. __func__);
  188. return -1;
  189. }
  190. *out_rates_size =
  191. min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
  192. return 0;
  193. }
  194. /*
  195. * This function appends a WPS IE. It is called from the network join command
  196. * preparation routine.
  197. *
  198. * If the IE buffer has been setup by the application, this routine appends
  199. * the buffer as a WPS TLV type to the request.
  200. */
  201. static int
  202. mwifiex_cmd_append_wps_ie(struct mwifiex_private *priv, u8 **buffer)
  203. {
  204. int retLen = 0;
  205. struct mwifiex_ie_types_header ie_header;
  206. if (!buffer || !*buffer)
  207. return 0;
  208. /*
  209. * If there is a wps ie buffer setup, append it to the return
  210. * parameter buffer pointer.
  211. */
  212. if (priv->wps_ie_len) {
  213. dev_dbg(priv->adapter->dev, "cmd: append wps ie %d to %p\n",
  214. priv->wps_ie_len, *buffer);
  215. /* Wrap the generic IE buffer with a pass through TLV type */
  216. ie_header.type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  217. ie_header.len = cpu_to_le16(priv->wps_ie_len);
  218. memcpy(*buffer, &ie_header, sizeof(ie_header));
  219. *buffer += sizeof(ie_header);
  220. retLen += sizeof(ie_header);
  221. memcpy(*buffer, priv->wps_ie, priv->wps_ie_len);
  222. *buffer += priv->wps_ie_len;
  223. retLen += priv->wps_ie_len;
  224. }
  225. kfree(priv->wps_ie);
  226. priv->wps_ie_len = 0;
  227. return retLen;
  228. }
  229. /*
  230. * This function appends a WAPI IE.
  231. *
  232. * This function is called from the network join command preparation routine.
  233. *
  234. * If the IE buffer has been setup by the application, this routine appends
  235. * the buffer as a WAPI TLV type to the request.
  236. */
  237. static int
  238. mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
  239. {
  240. int retLen = 0;
  241. struct mwifiex_ie_types_header ie_header;
  242. /* Null Checks */
  243. if (buffer == NULL)
  244. return 0;
  245. if (*buffer == NULL)
  246. return 0;
  247. /*
  248. * If there is a wapi ie buffer setup, append it to the return
  249. * parameter buffer pointer.
  250. */
  251. if (priv->wapi_ie_len) {
  252. dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n",
  253. priv->wapi_ie_len, *buffer);
  254. /* Wrap the generic IE buffer with a pass through TLV type */
  255. ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
  256. ie_header.len = cpu_to_le16(priv->wapi_ie_len);
  257. memcpy(*buffer, &ie_header, sizeof(ie_header));
  258. /* Increment the return size and the return buffer pointer
  259. param */
  260. *buffer += sizeof(ie_header);
  261. retLen += sizeof(ie_header);
  262. /* Copy the wapi IE buffer to the output buffer, advance
  263. pointer */
  264. memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
  265. /* Increment the return size and the return buffer pointer
  266. param */
  267. *buffer += priv->wapi_ie_len;
  268. retLen += priv->wapi_ie_len;
  269. }
  270. /* return the length appended to the buffer */
  271. return retLen;
  272. }
  273. /*
  274. * This function appends rsn ie tlv for wpa/wpa2 security modes.
  275. * It is called from the network join command preparation routine.
  276. */
  277. static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
  278. u8 **buffer)
  279. {
  280. struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
  281. int rsn_ie_len;
  282. if (!buffer || !(*buffer))
  283. return 0;
  284. rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
  285. rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
  286. rsn_ie_tlv->header.type = cpu_to_le16(
  287. le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
  288. rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
  289. rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
  290. & 0x00FF);
  291. if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
  292. memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
  293. le16_to_cpu(rsn_ie_tlv->header.len));
  294. else
  295. return -1;
  296. rsn_ie_len = sizeof(rsn_ie_tlv->header) +
  297. le16_to_cpu(rsn_ie_tlv->header.len);
  298. *buffer += rsn_ie_len;
  299. return rsn_ie_len;
  300. }
  301. /*
  302. * This function prepares command for association.
  303. *
  304. * This sets the following parameters -
  305. * - Peer MAC address
  306. * - Listen interval
  307. * - Beacon interval
  308. * - Capability information
  309. *
  310. * ...and the following TLVs, as required -
  311. * - SSID TLV
  312. * - PHY TLV
  313. * - SS TLV
  314. * - Rates TLV
  315. * - Authentication TLV
  316. * - Channel TLV
  317. * - WPA/WPA2 IE
  318. * - 11n TLV
  319. * - Vendor specific TLV
  320. * - WMM TLV
  321. * - WAPI IE
  322. * - Generic IE
  323. * - TSF TLV
  324. *
  325. * Preparation also includes -
  326. * - Setting command ID and proper size
  327. * - Ensuring correct endian-ness
  328. */
  329. int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
  330. struct host_cmd_ds_command *cmd,
  331. struct mwifiex_bssdescriptor *bss_desc)
  332. {
  333. struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
  334. struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
  335. struct mwifiex_ie_types_phy_param_set *phy_tlv;
  336. struct mwifiex_ie_types_ss_param_set *ss_tlv;
  337. struct mwifiex_ie_types_rates_param_set *rates_tlv;
  338. struct mwifiex_ie_types_auth_type *auth_tlv;
  339. struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
  340. u8 rates[MWIFIEX_SUPPORTED_RATES];
  341. u32 rates_size;
  342. u16 tmp_cap;
  343. u8 *pos;
  344. int rsn_ie_len = 0;
  345. pos = (u8 *) assoc;
  346. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
  347. /* Save so we know which BSS Desc to use in the response handler */
  348. priv->attempted_bss_desc = bss_desc;
  349. memcpy(assoc->peer_sta_addr,
  350. bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
  351. pos += sizeof(assoc->peer_sta_addr);
  352. /* Set the listen interval */
  353. assoc->listen_interval = cpu_to_le16(priv->listen_interval);
  354. /* Set the beacon period */
  355. assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
  356. pos += sizeof(assoc->cap_info_bitmap);
  357. pos += sizeof(assoc->listen_interval);
  358. pos += sizeof(assoc->beacon_period);
  359. pos += sizeof(assoc->dtim_period);
  360. ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
  361. ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
  362. ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
  363. memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
  364. le16_to_cpu(ssid_tlv->header.len));
  365. pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
  366. phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
  367. phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
  368. phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
  369. memcpy(&phy_tlv->fh_ds.ds_param_set,
  370. &bss_desc->phy_param_set.ds_param_set.current_chan,
  371. sizeof(phy_tlv->fh_ds.ds_param_set));
  372. pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
  373. ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
  374. ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
  375. ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
  376. pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
  377. /* Get the common rates supported between the driver and the BSS Desc */
  378. if (mwifiex_setup_rates_from_bssdesc
  379. (priv, bss_desc, rates, &rates_size))
  380. return -1;
  381. /* Save the data rates into Current BSS state structure */
  382. priv->curr_bss_params.num_of_rates = rates_size;
  383. memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
  384. /* Setup the Rates TLV in the association command */
  385. rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
  386. rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
  387. rates_tlv->header.len = cpu_to_le16((u16) rates_size);
  388. memcpy(rates_tlv->rates, rates, rates_size);
  389. pos += sizeof(rates_tlv->header) + rates_size;
  390. dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
  391. rates_size);
  392. /* Add the Authentication type to be used for Auth frames */
  393. auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
  394. auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
  395. auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
  396. if (priv->sec_info.wep_enabled)
  397. auth_tlv->auth_type = cpu_to_le16(
  398. (u16) priv->sec_info.authentication_mode);
  399. else
  400. auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
  401. pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
  402. if (IS_SUPPORT_MULTI_BANDS(priv->adapter) &&
  403. !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
  404. (!bss_desc->disable_11n) &&
  405. (priv->adapter->config_bands & BAND_GN ||
  406. priv->adapter->config_bands & BAND_AN) &&
  407. (bss_desc->bcn_ht_cap)
  408. )
  409. ) {
  410. /* Append a channel TLV for the channel the attempted AP was
  411. found on */
  412. chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
  413. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  414. chan_tlv->header.len =
  415. cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
  416. memset(chan_tlv->chan_scan_param, 0x00,
  417. sizeof(struct mwifiex_chan_scan_param_set));
  418. chan_tlv->chan_scan_param[0].chan_number =
  419. (bss_desc->phy_param_set.ds_param_set.current_chan);
  420. dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
  421. chan_tlv->chan_scan_param[0].chan_number);
  422. chan_tlv->chan_scan_param[0].radio_type =
  423. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  424. dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
  425. chan_tlv->chan_scan_param[0].radio_type);
  426. pos += sizeof(chan_tlv->header) +
  427. sizeof(struct mwifiex_chan_scan_param_set);
  428. }
  429. if (!priv->wps.session_enable) {
  430. if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
  431. rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
  432. if (rsn_ie_len == -1)
  433. return -1;
  434. }
  435. if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
  436. (!bss_desc->disable_11n) &&
  437. (priv->adapter->config_bands & BAND_GN ||
  438. priv->adapter->config_bands & BAND_AN))
  439. mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
  440. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
  441. !bss_desc->disable_11n && !bss_desc->disable_11ac &&
  442. (priv->adapter->config_bands & BAND_GAC ||
  443. priv->adapter->config_bands & BAND_AAC))
  444. mwifiex_cmd_append_11ac_tlv(priv, bss_desc, &pos);
  445. /* Append vendor specific IE TLV */
  446. mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
  447. mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
  448. bss_desc->bcn_ht_cap);
  449. if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
  450. mwifiex_cmd_append_wapi_ie(priv, &pos);
  451. if (priv->wps.session_enable && priv->wps_ie_len)
  452. mwifiex_cmd_append_wps_ie(priv, &pos);
  453. mwifiex_cmd_append_generic_ie(priv, &pos);
  454. mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
  455. mwifiex_11h_process_join(priv, &pos, bss_desc);
  456. cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
  457. /* Set the Capability info at last */
  458. tmp_cap = bss_desc->cap_info_bitmap;
  459. if (priv->adapter->config_bands == BAND_B)
  460. tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
  461. tmp_cap &= CAPINFO_MASK;
  462. dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
  463. tmp_cap, CAPINFO_MASK);
  464. assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
  465. return 0;
  466. }
  467. /*
  468. * Association firmware command response handler
  469. *
  470. * The response buffer for the association command has the following
  471. * memory layout.
  472. *
  473. * For cases where an association response was not received (indicated
  474. * by the CapInfo and AId field):
  475. *
  476. * .------------------------------------------------------------.
  477. * | Header(4 * sizeof(t_u16)): Standard command response hdr |
  478. * .------------------------------------------------------------.
  479. * | cap_info/Error Return(t_u16): |
  480. * | 0xFFFF(-1): Internal error |
  481. * | 0xFFFE(-2): Authentication unhandled message |
  482. * | 0xFFFD(-3): Authentication refused |
  483. * | 0xFFFC(-4): Timeout waiting for AP response |
  484. * .------------------------------------------------------------.
  485. * | status_code(t_u16): |
  486. * | If cap_info is -1: |
  487. * | An internal firmware failure prevented the |
  488. * | command from being processed. The status_code |
  489. * | will be set to 1. |
  490. * | |
  491. * | If cap_info is -2: |
  492. * | An authentication frame was received but was |
  493. * | not handled by the firmware. IEEE Status |
  494. * | code for the failure is returned. |
  495. * | |
  496. * | If cap_info is -3: |
  497. * | An authentication frame was received and the |
  498. * | status_code is the IEEE Status reported in the |
  499. * | response. |
  500. * | |
  501. * | If cap_info is -4: |
  502. * | (1) Association response timeout |
  503. * | (2) Authentication response timeout |
  504. * .------------------------------------------------------------.
  505. * | a_id(t_u16): 0xFFFF |
  506. * .------------------------------------------------------------.
  507. *
  508. *
  509. * For cases where an association response was received, the IEEE
  510. * standard association response frame is returned:
  511. *
  512. * .------------------------------------------------------------.
  513. * | Header(4 * sizeof(t_u16)): Standard command response hdr |
  514. * .------------------------------------------------------------.
  515. * | cap_info(t_u16): IEEE Capability |
  516. * .------------------------------------------------------------.
  517. * | status_code(t_u16): IEEE Status Code |
  518. * .------------------------------------------------------------.
  519. * | a_id(t_u16): IEEE Association ID |
  520. * .------------------------------------------------------------.
  521. * | IEEE IEs(variable): Any received IEs comprising the |
  522. * | remaining portion of a received |
  523. * | association response frame. |
  524. * .------------------------------------------------------------.
  525. *
  526. * For simplistic handling, the status_code field can be used to determine
  527. * an association success (0) or failure (non-zero).
  528. */
  529. int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
  530. struct host_cmd_ds_command *resp)
  531. {
  532. struct mwifiex_adapter *adapter = priv->adapter;
  533. int ret = 0;
  534. struct ieee_types_assoc_rsp *assoc_rsp;
  535. struct mwifiex_bssdescriptor *bss_desc;
  536. u8 enable_data = true;
  537. u16 cap_info, status_code;
  538. assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
  539. cap_info = le16_to_cpu(assoc_rsp->cap_info_bitmap);
  540. status_code = le16_to_cpu(assoc_rsp->status_code);
  541. priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
  542. sizeof(priv->assoc_rsp_buf));
  543. memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
  544. if (status_code) {
  545. priv->adapter->dbg.num_cmd_assoc_failure++;
  546. dev_err(priv->adapter->dev,
  547. "ASSOC_RESP: failed, status code=%d err=%#x a_id=%#x\n",
  548. status_code, cap_info, le16_to_cpu(assoc_rsp->a_id));
  549. if (cap_info == MWIFIEX_TIMEOUT_FOR_AP_RESP) {
  550. if (status_code == MWIFIEX_STATUS_CODE_AUTH_TIMEOUT)
  551. ret = WLAN_STATUS_AUTH_TIMEOUT;
  552. else
  553. ret = WLAN_STATUS_UNSPECIFIED_FAILURE;
  554. } else {
  555. ret = status_code;
  556. }
  557. goto done;
  558. }
  559. /* Send a Media Connected event, according to the Spec */
  560. priv->media_connected = true;
  561. priv->adapter->ps_state = PS_STATE_AWAKE;
  562. priv->adapter->pps_uapsd_mode = false;
  563. priv->adapter->tx_lock_flag = false;
  564. /* Set the attempted BSSID Index to current */
  565. bss_desc = priv->attempted_bss_desc;
  566. dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
  567. bss_desc->ssid.ssid);
  568. /* Make a copy of current BSSID descriptor */
  569. memcpy(&priv->curr_bss_params.bss_descriptor,
  570. bss_desc, sizeof(struct mwifiex_bssdescriptor));
  571. /* Update curr_bss_params */
  572. priv->curr_bss_params.bss_descriptor.channel
  573. = bss_desc->phy_param_set.ds_param_set.current_chan;
  574. priv->curr_bss_params.band = (u8) bss_desc->bss_band;
  575. if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
  576. priv->curr_bss_params.wmm_enabled = true;
  577. else
  578. priv->curr_bss_params.wmm_enabled = false;
  579. if ((priv->wmm_required || bss_desc->bcn_ht_cap) &&
  580. priv->curr_bss_params.wmm_enabled)
  581. priv->wmm_enabled = true;
  582. else
  583. priv->wmm_enabled = false;
  584. priv->curr_bss_params.wmm_uapsd_enabled = false;
  585. if (priv->wmm_enabled)
  586. priv->curr_bss_params.wmm_uapsd_enabled
  587. = ((bss_desc->wmm_ie.qos_info_bitmap &
  588. IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
  589. dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
  590. priv->curr_pkt_filter);
  591. if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
  592. priv->wpa_is_gtk_set = false;
  593. if (priv->wmm_enabled) {
  594. /* Don't re-enable carrier until we get the WMM_GET_STATUS
  595. event */
  596. enable_data = false;
  597. } else {
  598. /* Since WMM is not enabled, setup the queues with the
  599. defaults */
  600. mwifiex_wmm_setup_queue_priorities(priv, NULL);
  601. mwifiex_wmm_setup_ac_downgrade(priv);
  602. }
  603. if (enable_data)
  604. dev_dbg(priv->adapter->dev,
  605. "info: post association, re-enabling data flow\n");
  606. /* Reset SNR/NF/RSSI values */
  607. priv->data_rssi_last = 0;
  608. priv->data_nf_last = 0;
  609. priv->data_rssi_avg = 0;
  610. priv->data_nf_avg = 0;
  611. priv->bcn_rssi_last = 0;
  612. priv->bcn_nf_last = 0;
  613. priv->bcn_rssi_avg = 0;
  614. priv->bcn_nf_avg = 0;
  615. priv->rxpd_rate = 0;
  616. priv->rxpd_htinfo = 0;
  617. mwifiex_save_curr_bcn(priv);
  618. priv->adapter->dbg.num_cmd_assoc_success++;
  619. dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
  620. /* Add the ra_list here for infra mode as there will be only 1 ra
  621. always */
  622. mwifiex_ralist_add(priv,
  623. priv->curr_bss_params.bss_descriptor.mac_address);
  624. if (!netif_carrier_ok(priv->netdev))
  625. netif_carrier_on(priv->netdev);
  626. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  627. if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
  628. priv->scan_block = true;
  629. done:
  630. /* Need to indicate IOCTL complete */
  631. if (adapter->curr_cmd->wait_q_enabled) {
  632. if (ret)
  633. adapter->cmd_wait_q.status = -1;
  634. else
  635. adapter->cmd_wait_q.status = 0;
  636. }
  637. return ret;
  638. }
  639. /*
  640. * This function prepares command for ad-hoc start.
  641. *
  642. * Driver will fill up SSID, BSS mode, IBSS parameters, physical
  643. * parameters, probe delay, and capability information. Firmware
  644. * will fill up beacon period, basic rates and operational rates.
  645. *
  646. * In addition, the following TLVs are added -
  647. * - Channel TLV
  648. * - Vendor specific IE
  649. * - WPA/WPA2 IE
  650. * - HT Capabilities IE
  651. * - HT Information IE
  652. *
  653. * Preparation also includes -
  654. * - Setting command ID and proper size
  655. * - Ensuring correct endian-ness
  656. */
  657. int
  658. mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
  659. struct host_cmd_ds_command *cmd,
  660. struct cfg80211_ssid *req_ssid)
  661. {
  662. int rsn_ie_len = 0;
  663. struct mwifiex_adapter *adapter = priv->adapter;
  664. struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
  665. &cmd->params.adhoc_start;
  666. struct mwifiex_bssdescriptor *bss_desc;
  667. u32 cmd_append_size = 0;
  668. u32 i;
  669. u16 tmp_cap;
  670. struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
  671. u8 radio_type;
  672. struct mwifiex_ie_types_htcap *ht_cap;
  673. struct mwifiex_ie_types_htinfo *ht_info;
  674. u8 *pos = (u8 *) adhoc_start +
  675. sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
  676. if (!adapter)
  677. return -1;
  678. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
  679. bss_desc = &priv->curr_bss_params.bss_descriptor;
  680. priv->attempted_bss_desc = bss_desc;
  681. /*
  682. * Fill in the parameters for 2 data structures:
  683. * 1. struct host_cmd_ds_802_11_ad_hoc_start command
  684. * 2. bss_desc
  685. * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
  686. * probe delay, and Cap info.
  687. * Firmware will fill up beacon period, Basic rates
  688. * and operational rates.
  689. */
  690. memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
  691. memcpy(adhoc_start->ssid, req_ssid->ssid, req_ssid->ssid_len);
  692. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
  693. adhoc_start->ssid);
  694. memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
  695. memcpy(bss_desc->ssid.ssid, req_ssid->ssid, req_ssid->ssid_len);
  696. bss_desc->ssid.ssid_len = req_ssid->ssid_len;
  697. /* Set the BSS mode */
  698. adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
  699. bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
  700. adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
  701. bss_desc->beacon_period = priv->beacon_period;
  702. /* Set Physical param set */
  703. /* Parameter IE Id */
  704. #define DS_PARA_IE_ID 3
  705. /* Parameter IE length */
  706. #define DS_PARA_IE_LEN 1
  707. adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
  708. adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
  709. if (!mwifiex_get_cfp(priv, adapter->adhoc_start_band,
  710. (u16) priv->adhoc_channel, 0)) {
  711. struct mwifiex_chan_freq_power *cfp;
  712. cfp = mwifiex_get_cfp(priv, adapter->adhoc_start_band,
  713. FIRST_VALID_CHANNEL, 0);
  714. if (cfp)
  715. priv->adhoc_channel = (u8) cfp->channel;
  716. }
  717. if (!priv->adhoc_channel) {
  718. dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
  719. return -1;
  720. }
  721. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
  722. priv->adhoc_channel);
  723. priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
  724. priv->curr_bss_params.band = adapter->adhoc_start_band;
  725. bss_desc->channel = priv->adhoc_channel;
  726. adhoc_start->phy_param_set.ds_param_set.current_chan =
  727. priv->adhoc_channel;
  728. memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
  729. sizeof(union ieee_types_phy_param_set));
  730. /* Set IBSS param set */
  731. /* IBSS parameter IE Id */
  732. #define IBSS_PARA_IE_ID 6
  733. /* IBSS parameter IE length */
  734. #define IBSS_PARA_IE_LEN 2
  735. adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
  736. adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
  737. adhoc_start->ss_param_set.ibss_param_set.atim_window
  738. = cpu_to_le16(priv->atim_window);
  739. memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
  740. sizeof(union ieee_types_ss_param_set));
  741. /* Set Capability info */
  742. bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
  743. tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
  744. tmp_cap &= ~WLAN_CAPABILITY_ESS;
  745. tmp_cap |= WLAN_CAPABILITY_IBSS;
  746. /* Set up privacy in bss_desc */
  747. if (priv->sec_info.encryption_mode) {
  748. /* Ad-Hoc capability privacy on */
  749. dev_dbg(adapter->dev,
  750. "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
  751. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  752. tmp_cap |= WLAN_CAPABILITY_PRIVACY;
  753. } else {
  754. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
  755. " setting privacy to ACCEPT ALL\n");
  756. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  757. }
  758. memset(adhoc_start->data_rate, 0, sizeof(adhoc_start->data_rate));
  759. mwifiex_get_active_data_rates(priv, adhoc_start->data_rate);
  760. if ((adapter->adhoc_start_band & BAND_G) &&
  761. (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
  762. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  763. HostCmd_ACT_GEN_SET, 0,
  764. &priv->curr_pkt_filter)) {
  765. dev_err(adapter->dev,
  766. "ADHOC_S_CMD: G Protection config failed\n");
  767. return -1;
  768. }
  769. }
  770. /* Find the last non zero */
  771. for (i = 0; i < sizeof(adhoc_start->data_rate); i++)
  772. if (!adhoc_start->data_rate[i])
  773. break;
  774. priv->curr_bss_params.num_of_rates = i;
  775. /* Copy the ad-hoc creating rates into Current BSS rate structure */
  776. memcpy(&priv->curr_bss_params.data_rates,
  777. &adhoc_start->data_rate, priv->curr_bss_params.num_of_rates);
  778. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%4ph\n",
  779. adhoc_start->data_rate);
  780. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
  781. if (IS_SUPPORT_MULTI_BANDS(adapter)) {
  782. /* Append a channel TLV */
  783. chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
  784. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  785. chan_tlv->header.len =
  786. cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
  787. memset(chan_tlv->chan_scan_param, 0x00,
  788. sizeof(struct mwifiex_chan_scan_param_set));
  789. chan_tlv->chan_scan_param[0].chan_number =
  790. (u8) priv->curr_bss_params.bss_descriptor.channel;
  791. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
  792. chan_tlv->chan_scan_param[0].chan_number);
  793. chan_tlv->chan_scan_param[0].radio_type
  794. = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  795. if (adapter->adhoc_start_band & BAND_GN ||
  796. adapter->adhoc_start_band & BAND_AN) {
  797. if (adapter->sec_chan_offset ==
  798. IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  799. chan_tlv->chan_scan_param[0].radio_type |=
  800. (IEEE80211_HT_PARAM_CHA_SEC_ABOVE << 4);
  801. else if (adapter->sec_chan_offset ==
  802. IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  803. chan_tlv->chan_scan_param[0].radio_type |=
  804. (IEEE80211_HT_PARAM_CHA_SEC_BELOW << 4);
  805. }
  806. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
  807. chan_tlv->chan_scan_param[0].radio_type);
  808. pos += sizeof(chan_tlv->header) +
  809. sizeof(struct mwifiex_chan_scan_param_set);
  810. cmd_append_size +=
  811. sizeof(chan_tlv->header) +
  812. sizeof(struct mwifiex_chan_scan_param_set);
  813. }
  814. /* Append vendor specific IE TLV */
  815. cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
  816. MWIFIEX_VSIE_MASK_ADHOC, &pos);
  817. if (priv->sec_info.wpa_enabled) {
  818. rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
  819. if (rsn_ie_len == -1)
  820. return -1;
  821. cmd_append_size += rsn_ie_len;
  822. }
  823. if (adapter->adhoc_11n_enabled) {
  824. /* Fill HT CAPABILITY */
  825. ht_cap = (struct mwifiex_ie_types_htcap *) pos;
  826. memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
  827. ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  828. ht_cap->header.len =
  829. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  830. radio_type = mwifiex_band_to_radio_type(
  831. priv->adapter->config_bands);
  832. mwifiex_fill_cap_info(priv, radio_type, ht_cap);
  833. if (adapter->sec_chan_offset ==
  834. IEEE80211_HT_PARAM_CHA_SEC_NONE) {
  835. u16 tmp_ht_cap;
  836. tmp_ht_cap = le16_to_cpu(ht_cap->ht_cap.cap_info);
  837. tmp_ht_cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  838. tmp_ht_cap &= ~IEEE80211_HT_CAP_SGI_40;
  839. ht_cap->ht_cap.cap_info = cpu_to_le16(tmp_ht_cap);
  840. }
  841. pos += sizeof(struct mwifiex_ie_types_htcap);
  842. cmd_append_size += sizeof(struct mwifiex_ie_types_htcap);
  843. /* Fill HT INFORMATION */
  844. ht_info = (struct mwifiex_ie_types_htinfo *) pos;
  845. memset(ht_info, 0, sizeof(struct mwifiex_ie_types_htinfo));
  846. ht_info->header.type = cpu_to_le16(WLAN_EID_HT_OPERATION);
  847. ht_info->header.len =
  848. cpu_to_le16(sizeof(struct ieee80211_ht_operation));
  849. ht_info->ht_oper.primary_chan =
  850. (u8) priv->curr_bss_params.bss_descriptor.channel;
  851. if (adapter->sec_chan_offset) {
  852. ht_info->ht_oper.ht_param = adapter->sec_chan_offset;
  853. ht_info->ht_oper.ht_param |=
  854. IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
  855. }
  856. ht_info->ht_oper.operation_mode =
  857. cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  858. ht_info->ht_oper.basic_set[0] = 0xff;
  859. pos += sizeof(struct mwifiex_ie_types_htinfo);
  860. cmd_append_size +=
  861. sizeof(struct mwifiex_ie_types_htinfo);
  862. }
  863. cmd->size =
  864. cpu_to_le16((u16)(sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
  865. + S_DS_GEN + cmd_append_size));
  866. if (adapter->adhoc_start_band == BAND_B)
  867. tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
  868. else
  869. tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  870. adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
  871. return 0;
  872. }
  873. /*
  874. * This function prepares command for ad-hoc join.
  875. *
  876. * Most of the parameters are set up by copying from the target BSS descriptor
  877. * from the scan response.
  878. *
  879. * In addition, the following TLVs are added -
  880. * - Channel TLV
  881. * - Vendor specific IE
  882. * - WPA/WPA2 IE
  883. * - 11n IE
  884. *
  885. * Preparation also includes -
  886. * - Setting command ID and proper size
  887. * - Ensuring correct endian-ness
  888. */
  889. int
  890. mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
  891. struct host_cmd_ds_command *cmd,
  892. struct mwifiex_bssdescriptor *bss_desc)
  893. {
  894. int rsn_ie_len = 0;
  895. struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
  896. &cmd->params.adhoc_join;
  897. struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
  898. u32 cmd_append_size = 0;
  899. u16 tmp_cap;
  900. u32 i, rates_size = 0;
  901. u16 curr_pkt_filter;
  902. u8 *pos =
  903. (u8 *) adhoc_join +
  904. sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
  905. /* Use G protection */
  906. #define USE_G_PROTECTION 0x02
  907. if (bss_desc->erp_flags & USE_G_PROTECTION) {
  908. curr_pkt_filter =
  909. priv->
  910. curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
  911. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  912. HostCmd_ACT_GEN_SET, 0,
  913. &curr_pkt_filter)) {
  914. dev_err(priv->adapter->dev,
  915. "ADHOC_J_CMD: G Protection config failed\n");
  916. return -1;
  917. }
  918. }
  919. priv->attempted_bss_desc = bss_desc;
  920. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
  921. adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
  922. adhoc_join->bss_descriptor.beacon_period
  923. = cpu_to_le16(bss_desc->beacon_period);
  924. memcpy(&adhoc_join->bss_descriptor.bssid,
  925. &bss_desc->mac_address, ETH_ALEN);
  926. memcpy(&adhoc_join->bss_descriptor.ssid,
  927. &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
  928. memcpy(&adhoc_join->bss_descriptor.phy_param_set,
  929. &bss_desc->phy_param_set,
  930. sizeof(union ieee_types_phy_param_set));
  931. memcpy(&adhoc_join->bss_descriptor.ss_param_set,
  932. &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
  933. tmp_cap = bss_desc->cap_info_bitmap;
  934. tmp_cap &= CAPINFO_MASK;
  935. dev_dbg(priv->adapter->dev,
  936. "info: ADHOC_J_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
  937. tmp_cap, CAPINFO_MASK);
  938. /* Information on BSSID descriptor passed to FW */
  939. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID=%pM, SSID='%s'\n",
  940. adhoc_join->bss_descriptor.bssid,
  941. adhoc_join->bss_descriptor.ssid);
  942. for (i = 0; i < MWIFIEX_SUPPORTED_RATES &&
  943. bss_desc->supported_rates[i]; i++)
  944. ;
  945. rates_size = i;
  946. /* Copy Data Rates from the Rates recorded in scan response */
  947. memset(adhoc_join->bss_descriptor.data_rates, 0,
  948. sizeof(adhoc_join->bss_descriptor.data_rates));
  949. memcpy(adhoc_join->bss_descriptor.data_rates,
  950. bss_desc->supported_rates, rates_size);
  951. /* Copy the adhoc join rates into Current BSS state structure */
  952. priv->curr_bss_params.num_of_rates = rates_size;
  953. memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
  954. rates_size);
  955. /* Copy the channel information */
  956. priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
  957. priv->curr_bss_params.band = (u8) bss_desc->bss_band;
  958. if (priv->sec_info.wep_enabled || priv->sec_info.wpa_enabled)
  959. tmp_cap |= WLAN_CAPABILITY_PRIVACY;
  960. if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
  961. /* Append a channel TLV */
  962. chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
  963. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  964. chan_tlv->header.len =
  965. cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
  966. memset(chan_tlv->chan_scan_param, 0x00,
  967. sizeof(struct mwifiex_chan_scan_param_set));
  968. chan_tlv->chan_scan_param[0].chan_number =
  969. (bss_desc->phy_param_set.ds_param_set.current_chan);
  970. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan=%d\n",
  971. chan_tlv->chan_scan_param[0].chan_number);
  972. chan_tlv->chan_scan_param[0].radio_type =
  973. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  974. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band=%d\n",
  975. chan_tlv->chan_scan_param[0].radio_type);
  976. pos += sizeof(chan_tlv->header) +
  977. sizeof(struct mwifiex_chan_scan_param_set);
  978. cmd_append_size += sizeof(chan_tlv->header) +
  979. sizeof(struct mwifiex_chan_scan_param_set);
  980. }
  981. if (priv->sec_info.wpa_enabled)
  982. rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
  983. if (rsn_ie_len == -1)
  984. return -1;
  985. cmd_append_size += rsn_ie_len;
  986. if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
  987. cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
  988. bss_desc, &pos);
  989. /* Append vendor specific IE TLV */
  990. cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
  991. MWIFIEX_VSIE_MASK_ADHOC, &pos);
  992. cmd->size = cpu_to_le16
  993. ((u16) (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
  994. + S_DS_GEN + cmd_append_size));
  995. adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
  996. return 0;
  997. }
  998. /*
  999. * This function handles the command response of ad-hoc start and
  1000. * ad-hoc join.
  1001. *
  1002. * The function generates a device-connected event to notify
  1003. * the applications, in case of successful ad-hoc start/join, and
  1004. * saves the beacon buffer.
  1005. */
  1006. int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
  1007. struct host_cmd_ds_command *resp)
  1008. {
  1009. int ret = 0;
  1010. struct mwifiex_adapter *adapter = priv->adapter;
  1011. struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
  1012. struct mwifiex_bssdescriptor *bss_desc;
  1013. u16 reason_code;
  1014. adhoc_result = &resp->params.adhoc_result;
  1015. bss_desc = priv->attempted_bss_desc;
  1016. /* Join result code 0 --> SUCCESS */
  1017. reason_code = le16_to_cpu(resp->result);
  1018. if (reason_code) {
  1019. dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
  1020. if (priv->media_connected)
  1021. mwifiex_reset_connect_state(priv, reason_code);
  1022. memset(&priv->curr_bss_params.bss_descriptor,
  1023. 0x00, sizeof(struct mwifiex_bssdescriptor));
  1024. ret = -1;
  1025. goto done;
  1026. }
  1027. /* Send a Media Connected event, according to the Spec */
  1028. priv->media_connected = true;
  1029. if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
  1030. dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
  1031. bss_desc->ssid.ssid);
  1032. /* Update the created network descriptor with the new BSSID */
  1033. memcpy(bss_desc->mac_address,
  1034. adhoc_result->bssid, ETH_ALEN);
  1035. priv->adhoc_state = ADHOC_STARTED;
  1036. } else {
  1037. /*
  1038. * Now the join cmd should be successful.
  1039. * If BSSID has changed use SSID to compare instead of BSSID
  1040. */
  1041. dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
  1042. bss_desc->ssid.ssid);
  1043. /*
  1044. * Make a copy of current BSSID descriptor, only needed for
  1045. * join since the current descriptor is already being used
  1046. * for adhoc start
  1047. */
  1048. memcpy(&priv->curr_bss_params.bss_descriptor,
  1049. bss_desc, sizeof(struct mwifiex_bssdescriptor));
  1050. priv->adhoc_state = ADHOC_JOINED;
  1051. }
  1052. dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
  1053. priv->adhoc_channel);
  1054. dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
  1055. priv->curr_bss_params.bss_descriptor.mac_address);
  1056. if (!netif_carrier_ok(priv->netdev))
  1057. netif_carrier_on(priv->netdev);
  1058. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  1059. mwifiex_save_curr_bcn(priv);
  1060. done:
  1061. /* Need to indicate IOCTL complete */
  1062. if (adapter->curr_cmd->wait_q_enabled) {
  1063. if (ret)
  1064. adapter->cmd_wait_q.status = -1;
  1065. else
  1066. adapter->cmd_wait_q.status = 0;
  1067. }
  1068. return ret;
  1069. }
  1070. /*
  1071. * This function associates to a specific BSS discovered in a scan.
  1072. *
  1073. * It clears any past association response stored for application
  1074. * retrieval and calls the command preparation routine to send the
  1075. * command to firmware.
  1076. */
  1077. int mwifiex_associate(struct mwifiex_private *priv,
  1078. struct mwifiex_bssdescriptor *bss_desc)
  1079. {
  1080. u8 current_bssid[ETH_ALEN];
  1081. /* Return error if the adapter is not STA role or table entry
  1082. * is not marked as infra.
  1083. */
  1084. if ((GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) ||
  1085. (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
  1086. return -1;
  1087. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
  1088. !bss_desc->disable_11n && !bss_desc->disable_11ac &&
  1089. (priv->adapter->config_bands & BAND_GAC ||
  1090. priv->adapter->config_bands & BAND_AAC))
  1091. mwifiex_set_11ac_ba_params(priv);
  1092. else
  1093. mwifiex_set_ba_params(priv);
  1094. memcpy(&current_bssid,
  1095. &priv->curr_bss_params.bss_descriptor.mac_address,
  1096. sizeof(current_bssid));
  1097. /* Clear any past association response stored for application
  1098. retrieval */
  1099. priv->assoc_rsp_size = 0;
  1100. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE,
  1101. HostCmd_ACT_GEN_SET, 0, bss_desc);
  1102. }
  1103. /*
  1104. * This function starts an ad-hoc network.
  1105. *
  1106. * It calls the command preparation routine to send the command to firmware.
  1107. */
  1108. int
  1109. mwifiex_adhoc_start(struct mwifiex_private *priv,
  1110. struct cfg80211_ssid *adhoc_ssid)
  1111. {
  1112. dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
  1113. priv->adhoc_channel);
  1114. dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
  1115. priv->curr_bss_params.bss_descriptor.channel);
  1116. dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
  1117. priv->curr_bss_params.band);
  1118. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
  1119. (priv->adapter->config_bands & BAND_GAC ||
  1120. priv->adapter->config_bands & BAND_AAC))
  1121. mwifiex_set_11ac_ba_params(priv);
  1122. else
  1123. mwifiex_set_ba_params(priv);
  1124. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START,
  1125. HostCmd_ACT_GEN_SET, 0, adhoc_ssid);
  1126. }
  1127. /*
  1128. * This function joins an ad-hoc network found in a previous scan.
  1129. *
  1130. * It calls the command preparation routine to send the command to firmware,
  1131. * if already not connected to the requested SSID.
  1132. */
  1133. int mwifiex_adhoc_join(struct mwifiex_private *priv,
  1134. struct mwifiex_bssdescriptor *bss_desc)
  1135. {
  1136. dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
  1137. priv->curr_bss_params.bss_descriptor.ssid.ssid);
  1138. dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
  1139. priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
  1140. dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
  1141. bss_desc->ssid.ssid);
  1142. dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
  1143. bss_desc->ssid.ssid_len);
  1144. /* Check if the requested SSID is already joined */
  1145. if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
  1146. !mwifiex_ssid_cmp(&bss_desc->ssid,
  1147. &priv->curr_bss_params.bss_descriptor.ssid) &&
  1148. (priv->curr_bss_params.bss_descriptor.bss_mode ==
  1149. NL80211_IFTYPE_ADHOC)) {
  1150. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
  1151. " is the same as current; not attempting to re-join\n");
  1152. return -1;
  1153. }
  1154. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
  1155. !bss_desc->disable_11n && !bss_desc->disable_11ac &&
  1156. (priv->adapter->config_bands & BAND_GAC ||
  1157. priv->adapter->config_bands & BAND_AAC))
  1158. mwifiex_set_11ac_ba_params(priv);
  1159. else
  1160. mwifiex_set_ba_params(priv);
  1161. dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
  1162. priv->curr_bss_params.bss_descriptor.channel);
  1163. dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
  1164. priv->curr_bss_params.band);
  1165. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
  1166. HostCmd_ACT_GEN_SET, 0, bss_desc);
  1167. }
  1168. /*
  1169. * This function deauthenticates/disconnects from infra network by sending
  1170. * deauthentication request.
  1171. */
  1172. static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
  1173. {
  1174. u8 mac_address[ETH_ALEN];
  1175. int ret;
  1176. if (!mac || is_zero_ether_addr(mac))
  1177. memcpy(mac_address,
  1178. priv->curr_bss_params.bss_descriptor.mac_address,
  1179. ETH_ALEN);
  1180. else
  1181. memcpy(mac_address, mac, ETH_ALEN);
  1182. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
  1183. HostCmd_ACT_GEN_SET, 0, mac_address);
  1184. return ret;
  1185. }
  1186. /*
  1187. * This function deauthenticates/disconnects from a BSS.
  1188. *
  1189. * In case of infra made, it sends deauthentication request, and
  1190. * in case of ad-hoc mode, a stop network request is sent to the firmware.
  1191. * In AP mode, a command to stop bss is sent to firmware.
  1192. */
  1193. int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
  1194. {
  1195. int ret = 0;
  1196. if (!priv->media_connected)
  1197. return 0;
  1198. switch (priv->bss_mode) {
  1199. case NL80211_IFTYPE_STATION:
  1200. case NL80211_IFTYPE_P2P_CLIENT:
  1201. ret = mwifiex_deauthenticate_infra(priv, mac);
  1202. if (ret)
  1203. cfg80211_disconnected(priv->netdev, 0, NULL, 0,
  1204. GFP_KERNEL);
  1205. break;
  1206. case NL80211_IFTYPE_ADHOC:
  1207. return mwifiex_send_cmd_sync(priv,
  1208. HostCmd_CMD_802_11_AD_HOC_STOP,
  1209. HostCmd_ACT_GEN_SET, 0, NULL);
  1210. case NL80211_IFTYPE_AP:
  1211. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
  1212. HostCmd_ACT_GEN_SET, 0, NULL);
  1213. default:
  1214. break;
  1215. }
  1216. return ret;
  1217. }
  1218. EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
  1219. /*
  1220. * This function converts band to radio type used in channel TLV.
  1221. */
  1222. u8
  1223. mwifiex_band_to_radio_type(u8 band)
  1224. {
  1225. switch (band) {
  1226. case BAND_A:
  1227. case BAND_AN:
  1228. case BAND_A | BAND_AN:
  1229. case BAND_A | BAND_AN | BAND_AAC:
  1230. return HostCmd_SCAN_RADIO_TYPE_A;
  1231. case BAND_B:
  1232. case BAND_G:
  1233. case BAND_B | BAND_G:
  1234. default:
  1235. return HostCmd_SCAN_RADIO_TYPE_BG;
  1236. }
  1237. }