join.c 48 KB

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