join.c 44 KB

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