join.c 43 KB

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