join.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  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. assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
  559. cap_info = le16_to_cpu(assoc_rsp->cap_info_bitmap);
  560. status_code = le16_to_cpu(assoc_rsp->status_code);
  561. aid = le16_to_cpu(assoc_rsp->a_id);
  562. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  563. dev_err(priv->adapter->dev,
  564. "invalid AID value 0x%x; bits 15:14 not set\n",
  565. aid);
  566. aid &= ~(BIT(15) | BIT(14));
  567. priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
  568. sizeof(priv->assoc_rsp_buf));
  569. memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
  570. assoc_rsp->a_id = cpu_to_le16(aid);
  571. if (status_code) {
  572. priv->adapter->dbg.num_cmd_assoc_failure++;
  573. mwifiex_dbg(priv->adapter, ERROR,
  574. "ASSOC_RESP: failed,\t"
  575. "status code=%d err=%#x a_id=%#x\n",
  576. status_code, cap_info,
  577. le16_to_cpu(assoc_rsp->a_id));
  578. mwifiex_dbg(priv->adapter, ERROR, "assoc failure: reason %s\n",
  579. assoc_failure_reason_to_str(cap_info));
  580. if (cap_info == CONNECT_ERR_ASSOC_ERR_TIMEOUT) {
  581. if (status_code == MWIFIEX_ASSOC_CMD_FAILURE_AUTH) {
  582. ret = WLAN_STATUS_AUTH_TIMEOUT;
  583. mwifiex_dbg(priv->adapter, ERROR,
  584. "ASSOC_RESP: AUTH timeout\n");
  585. } else {
  586. ret = WLAN_STATUS_UNSPECIFIED_FAILURE;
  587. mwifiex_dbg(priv->adapter, ERROR,
  588. "ASSOC_RESP: UNSPECIFIED failure\n");
  589. }
  590. } else {
  591. ret = status_code;
  592. }
  593. goto done;
  594. }
  595. /* Send a Media Connected event, according to the Spec */
  596. priv->media_connected = true;
  597. priv->adapter->ps_state = PS_STATE_AWAKE;
  598. priv->adapter->pps_uapsd_mode = false;
  599. priv->adapter->tx_lock_flag = false;
  600. /* Set the attempted BSSID Index to current */
  601. bss_desc = priv->attempted_bss_desc;
  602. mwifiex_dbg(priv->adapter, INFO, "info: ASSOC_RESP: %s\n",
  603. bss_desc->ssid.ssid);
  604. /* Make a copy of current BSSID descriptor */
  605. memcpy(&priv->curr_bss_params.bss_descriptor,
  606. bss_desc, sizeof(struct mwifiex_bssdescriptor));
  607. /* Update curr_bss_params */
  608. priv->curr_bss_params.bss_descriptor.channel
  609. = bss_desc->phy_param_set.ds_param_set.current_chan;
  610. priv->curr_bss_params.band = (u8) bss_desc->bss_band;
  611. if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
  612. priv->curr_bss_params.wmm_enabled = true;
  613. else
  614. priv->curr_bss_params.wmm_enabled = false;
  615. if ((priv->wmm_required || bss_desc->bcn_ht_cap) &&
  616. priv->curr_bss_params.wmm_enabled)
  617. priv->wmm_enabled = true;
  618. else
  619. priv->wmm_enabled = false;
  620. priv->curr_bss_params.wmm_uapsd_enabled = false;
  621. if (priv->wmm_enabled)
  622. priv->curr_bss_params.wmm_uapsd_enabled
  623. = ((bss_desc->wmm_ie.qos_info_bitmap &
  624. IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
  625. mwifiex_dbg(priv->adapter, INFO,
  626. "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
  627. priv->curr_pkt_filter);
  628. if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
  629. priv->wpa_is_gtk_set = false;
  630. if (priv->wmm_enabled) {
  631. /* Don't re-enable carrier until we get the WMM_GET_STATUS
  632. event */
  633. enable_data = false;
  634. } else {
  635. /* Since WMM is not enabled, setup the queues with the
  636. defaults */
  637. mwifiex_wmm_setup_queue_priorities(priv, NULL);
  638. mwifiex_wmm_setup_ac_downgrade(priv);
  639. }
  640. if (enable_data)
  641. mwifiex_dbg(priv->adapter, INFO,
  642. "info: post association, re-enabling data flow\n");
  643. /* Reset SNR/NF/RSSI values */
  644. priv->data_rssi_last = 0;
  645. priv->data_nf_last = 0;
  646. priv->data_rssi_avg = 0;
  647. priv->data_nf_avg = 0;
  648. priv->bcn_rssi_last = 0;
  649. priv->bcn_nf_last = 0;
  650. priv->bcn_rssi_avg = 0;
  651. priv->bcn_nf_avg = 0;
  652. priv->rxpd_rate = 0;
  653. priv->rxpd_htinfo = 0;
  654. mwifiex_save_curr_bcn(priv);
  655. priv->adapter->dbg.num_cmd_assoc_success++;
  656. mwifiex_dbg(priv->adapter, INFO, "info: ASSOC_RESP: associated\n");
  657. /* Add the ra_list here for infra mode as there will be only 1 ra
  658. always */
  659. mwifiex_ralist_add(priv,
  660. priv->curr_bss_params.bss_descriptor.mac_address);
  661. if (!netif_carrier_ok(priv->netdev))
  662. netif_carrier_on(priv->netdev);
  663. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  664. if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
  665. priv->scan_block = true;
  666. else
  667. priv->port_open = true;
  668. done:
  669. /* Need to indicate IOCTL complete */
  670. if (adapter->curr_cmd->wait_q_enabled) {
  671. if (ret)
  672. adapter->cmd_wait_q.status = -1;
  673. else
  674. adapter->cmd_wait_q.status = 0;
  675. }
  676. return ret;
  677. }
  678. /*
  679. * This function prepares command for ad-hoc start.
  680. *
  681. * Driver will fill up SSID, BSS mode, IBSS parameters, physical
  682. * parameters, probe delay, and capability information. Firmware
  683. * will fill up beacon period, basic rates and operational rates.
  684. *
  685. * In addition, the following TLVs are added -
  686. * - Channel TLV
  687. * - Vendor specific IE
  688. * - WPA/WPA2 IE
  689. * - HT Capabilities IE
  690. * - HT Information IE
  691. *
  692. * Preparation also includes -
  693. * - Setting command ID and proper size
  694. * - Ensuring correct endian-ness
  695. */
  696. int
  697. mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
  698. struct host_cmd_ds_command *cmd,
  699. struct cfg80211_ssid *req_ssid)
  700. {
  701. int rsn_ie_len = 0;
  702. struct mwifiex_adapter *adapter = priv->adapter;
  703. struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
  704. &cmd->params.adhoc_start;
  705. struct mwifiex_bssdescriptor *bss_desc;
  706. u32 cmd_append_size = 0;
  707. u32 i;
  708. u16 tmp_cap;
  709. struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
  710. u8 radio_type;
  711. struct mwifiex_ie_types_htcap *ht_cap;
  712. struct mwifiex_ie_types_htinfo *ht_info;
  713. u8 *pos = (u8 *) adhoc_start +
  714. sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
  715. if (!adapter)
  716. return -1;
  717. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
  718. bss_desc = &priv->curr_bss_params.bss_descriptor;
  719. priv->attempted_bss_desc = bss_desc;
  720. /*
  721. * Fill in the parameters for 2 data structures:
  722. * 1. struct host_cmd_ds_802_11_ad_hoc_start command
  723. * 2. bss_desc
  724. * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
  725. * probe delay, and Cap info.
  726. * Firmware will fill up beacon period, Basic rates
  727. * and operational rates.
  728. */
  729. memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
  730. memcpy(adhoc_start->ssid, req_ssid->ssid, req_ssid->ssid_len);
  731. mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: SSID = %s\n",
  732. adhoc_start->ssid);
  733. memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
  734. memcpy(bss_desc->ssid.ssid, req_ssid->ssid, req_ssid->ssid_len);
  735. bss_desc->ssid.ssid_len = req_ssid->ssid_len;
  736. /* Set the BSS mode */
  737. adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
  738. bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
  739. adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
  740. bss_desc->beacon_period = priv->beacon_period;
  741. /* Set Physical param set */
  742. /* Parameter IE Id */
  743. #define DS_PARA_IE_ID 3
  744. /* Parameter IE length */
  745. #define DS_PARA_IE_LEN 1
  746. adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
  747. adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
  748. if (!mwifiex_get_cfp(priv, adapter->adhoc_start_band,
  749. (u16) priv->adhoc_channel, 0)) {
  750. struct mwifiex_chan_freq_power *cfp;
  751. cfp = mwifiex_get_cfp(priv, adapter->adhoc_start_band,
  752. FIRST_VALID_CHANNEL, 0);
  753. if (cfp)
  754. priv->adhoc_channel = (u8) cfp->channel;
  755. }
  756. if (!priv->adhoc_channel) {
  757. mwifiex_dbg(adapter, ERROR,
  758. "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
  759. return -1;
  760. }
  761. mwifiex_dbg(adapter, INFO,
  762. "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
  763. priv->adhoc_channel);
  764. priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
  765. priv->curr_bss_params.band = adapter->adhoc_start_band;
  766. bss_desc->channel = priv->adhoc_channel;
  767. adhoc_start->phy_param_set.ds_param_set.current_chan =
  768. priv->adhoc_channel;
  769. memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
  770. sizeof(union ieee_types_phy_param_set));
  771. /* Set IBSS param set */
  772. /* IBSS parameter IE Id */
  773. #define IBSS_PARA_IE_ID 6
  774. /* IBSS parameter IE length */
  775. #define IBSS_PARA_IE_LEN 2
  776. adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
  777. adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
  778. adhoc_start->ss_param_set.ibss_param_set.atim_window
  779. = cpu_to_le16(priv->atim_window);
  780. memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
  781. sizeof(union ieee_types_ss_param_set));
  782. /* Set Capability info */
  783. bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
  784. tmp_cap = WLAN_CAPABILITY_IBSS;
  785. /* Set up privacy in bss_desc */
  786. if (priv->sec_info.encryption_mode) {
  787. /* Ad-Hoc capability privacy on */
  788. mwifiex_dbg(adapter, INFO,
  789. "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
  790. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  791. tmp_cap |= WLAN_CAPABILITY_PRIVACY;
  792. } else {
  793. mwifiex_dbg(adapter, INFO,
  794. "info: ADHOC_S_CMD: wep_status NOT set,\t"
  795. "setting privacy to ACCEPT ALL\n");
  796. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  797. }
  798. memset(adhoc_start->data_rate, 0, sizeof(adhoc_start->data_rate));
  799. mwifiex_get_active_data_rates(priv, adhoc_start->data_rate);
  800. if ((adapter->adhoc_start_band & BAND_G) &&
  801. (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
  802. if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  803. HostCmd_ACT_GEN_SET, 0,
  804. &priv->curr_pkt_filter, false)) {
  805. mwifiex_dbg(adapter, ERROR,
  806. "ADHOC_S_CMD: G Protection config failed\n");
  807. return -1;
  808. }
  809. }
  810. /* Find the last non zero */
  811. for (i = 0; i < sizeof(adhoc_start->data_rate); i++)
  812. if (!adhoc_start->data_rate[i])
  813. break;
  814. priv->curr_bss_params.num_of_rates = i;
  815. /* Copy the ad-hoc creating rates into Current BSS rate structure */
  816. memcpy(&priv->curr_bss_params.data_rates,
  817. &adhoc_start->data_rate, priv->curr_bss_params.num_of_rates);
  818. mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: rates=%4ph\n",
  819. adhoc_start->data_rate);
  820. mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
  821. if (IS_SUPPORT_MULTI_BANDS(adapter)) {
  822. /* Append a channel TLV */
  823. chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
  824. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  825. chan_tlv->header.len =
  826. cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
  827. memset(chan_tlv->chan_scan_param, 0x00,
  828. sizeof(struct mwifiex_chan_scan_param_set));
  829. chan_tlv->chan_scan_param[0].chan_number =
  830. (u8) priv->curr_bss_params.bss_descriptor.channel;
  831. mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: TLV Chan = %d\n",
  832. chan_tlv->chan_scan_param[0].chan_number);
  833. chan_tlv->chan_scan_param[0].radio_type
  834. = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  835. if (adapter->adhoc_start_band & BAND_GN ||
  836. adapter->adhoc_start_band & BAND_AN) {
  837. if (adapter->sec_chan_offset ==
  838. IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  839. chan_tlv->chan_scan_param[0].radio_type |=
  840. (IEEE80211_HT_PARAM_CHA_SEC_ABOVE << 4);
  841. else if (adapter->sec_chan_offset ==
  842. IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  843. chan_tlv->chan_scan_param[0].radio_type |=
  844. (IEEE80211_HT_PARAM_CHA_SEC_BELOW << 4);
  845. }
  846. mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: TLV Band = %d\n",
  847. chan_tlv->chan_scan_param[0].radio_type);
  848. pos += sizeof(chan_tlv->header) +
  849. sizeof(struct mwifiex_chan_scan_param_set);
  850. cmd_append_size +=
  851. sizeof(chan_tlv->header) +
  852. sizeof(struct mwifiex_chan_scan_param_set);
  853. }
  854. /* Append vendor specific IE TLV */
  855. cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
  856. MWIFIEX_VSIE_MASK_ADHOC, &pos);
  857. if (priv->sec_info.wpa_enabled) {
  858. rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
  859. if (rsn_ie_len == -1)
  860. return -1;
  861. cmd_append_size += rsn_ie_len;
  862. }
  863. if (adapter->adhoc_11n_enabled) {
  864. /* Fill HT CAPABILITY */
  865. ht_cap = (struct mwifiex_ie_types_htcap *) pos;
  866. memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
  867. ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  868. ht_cap->header.len =
  869. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  870. radio_type = mwifiex_band_to_radio_type(
  871. priv->adapter->config_bands);
  872. mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
  873. if (adapter->sec_chan_offset ==
  874. IEEE80211_HT_PARAM_CHA_SEC_NONE) {
  875. u16 tmp_ht_cap;
  876. tmp_ht_cap = le16_to_cpu(ht_cap->ht_cap.cap_info);
  877. tmp_ht_cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  878. tmp_ht_cap &= ~IEEE80211_HT_CAP_SGI_40;
  879. ht_cap->ht_cap.cap_info = cpu_to_le16(tmp_ht_cap);
  880. }
  881. pos += sizeof(struct mwifiex_ie_types_htcap);
  882. cmd_append_size += sizeof(struct mwifiex_ie_types_htcap);
  883. /* Fill HT INFORMATION */
  884. ht_info = (struct mwifiex_ie_types_htinfo *) pos;
  885. memset(ht_info, 0, sizeof(struct mwifiex_ie_types_htinfo));
  886. ht_info->header.type = cpu_to_le16(WLAN_EID_HT_OPERATION);
  887. ht_info->header.len =
  888. cpu_to_le16(sizeof(struct ieee80211_ht_operation));
  889. ht_info->ht_oper.primary_chan =
  890. (u8) priv->curr_bss_params.bss_descriptor.channel;
  891. if (adapter->sec_chan_offset) {
  892. ht_info->ht_oper.ht_param = adapter->sec_chan_offset;
  893. ht_info->ht_oper.ht_param |=
  894. IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
  895. }
  896. ht_info->ht_oper.operation_mode =
  897. cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  898. ht_info->ht_oper.basic_set[0] = 0xff;
  899. pos += sizeof(struct mwifiex_ie_types_htinfo);
  900. cmd_append_size +=
  901. sizeof(struct mwifiex_ie_types_htinfo);
  902. }
  903. cmd->size =
  904. cpu_to_le16((u16)(sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
  905. + S_DS_GEN + cmd_append_size));
  906. if (adapter->adhoc_start_band == BAND_B)
  907. tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
  908. else
  909. tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  910. adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
  911. return 0;
  912. }
  913. /*
  914. * This function prepares command for ad-hoc join.
  915. *
  916. * Most of the parameters are set up by copying from the target BSS descriptor
  917. * from the scan response.
  918. *
  919. * In addition, the following TLVs are added -
  920. * - Channel TLV
  921. * - Vendor specific IE
  922. * - WPA/WPA2 IE
  923. * - 11n IE
  924. *
  925. * Preparation also includes -
  926. * - Setting command ID and proper size
  927. * - Ensuring correct endian-ness
  928. */
  929. int
  930. mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
  931. struct host_cmd_ds_command *cmd,
  932. struct mwifiex_bssdescriptor *bss_desc)
  933. {
  934. int rsn_ie_len = 0;
  935. struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
  936. &cmd->params.adhoc_join;
  937. struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
  938. u32 cmd_append_size = 0;
  939. u16 tmp_cap;
  940. u32 i, rates_size = 0;
  941. u16 curr_pkt_filter;
  942. u8 *pos =
  943. (u8 *) adhoc_join +
  944. sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
  945. /* Use G protection */
  946. #define USE_G_PROTECTION 0x02
  947. if (bss_desc->erp_flags & USE_G_PROTECTION) {
  948. curr_pkt_filter =
  949. priv->
  950. curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
  951. if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  952. HostCmd_ACT_GEN_SET, 0,
  953. &curr_pkt_filter, false)) {
  954. mwifiex_dbg(priv->adapter, ERROR,
  955. "ADHOC_J_CMD: G Protection config failed\n");
  956. return -1;
  957. }
  958. }
  959. priv->attempted_bss_desc = bss_desc;
  960. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
  961. adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
  962. adhoc_join->bss_descriptor.beacon_period
  963. = cpu_to_le16(bss_desc->beacon_period);
  964. memcpy(&adhoc_join->bss_descriptor.bssid,
  965. &bss_desc->mac_address, ETH_ALEN);
  966. memcpy(&adhoc_join->bss_descriptor.ssid,
  967. &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
  968. memcpy(&adhoc_join->bss_descriptor.phy_param_set,
  969. &bss_desc->phy_param_set,
  970. sizeof(union ieee_types_phy_param_set));
  971. memcpy(&adhoc_join->bss_descriptor.ss_param_set,
  972. &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
  973. tmp_cap = bss_desc->cap_info_bitmap;
  974. tmp_cap &= CAPINFO_MASK;
  975. mwifiex_dbg(priv->adapter, INFO,
  976. "info: ADHOC_J_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
  977. tmp_cap, CAPINFO_MASK);
  978. /* Information on BSSID descriptor passed to FW */
  979. mwifiex_dbg(priv->adapter, INFO,
  980. "info: ADHOC_J_CMD: BSSID=%pM, SSID='%s'\n",
  981. adhoc_join->bss_descriptor.bssid,
  982. adhoc_join->bss_descriptor.ssid);
  983. for (i = 0; i < MWIFIEX_SUPPORTED_RATES &&
  984. bss_desc->supported_rates[i]; i++)
  985. ;
  986. rates_size = i;
  987. /* Copy Data Rates from the Rates recorded in scan response */
  988. memset(adhoc_join->bss_descriptor.data_rates, 0,
  989. sizeof(adhoc_join->bss_descriptor.data_rates));
  990. memcpy(adhoc_join->bss_descriptor.data_rates,
  991. bss_desc->supported_rates, rates_size);
  992. /* Copy the adhoc join rates into Current BSS state structure */
  993. priv->curr_bss_params.num_of_rates = rates_size;
  994. memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
  995. rates_size);
  996. /* Copy the channel information */
  997. priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
  998. priv->curr_bss_params.band = (u8) bss_desc->bss_band;
  999. if (priv->sec_info.wep_enabled || priv->sec_info.wpa_enabled)
  1000. tmp_cap |= WLAN_CAPABILITY_PRIVACY;
  1001. if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
  1002. /* Append a channel TLV */
  1003. chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
  1004. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  1005. chan_tlv->header.len =
  1006. cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
  1007. memset(chan_tlv->chan_scan_param, 0x00,
  1008. sizeof(struct mwifiex_chan_scan_param_set));
  1009. chan_tlv->chan_scan_param[0].chan_number =
  1010. (bss_desc->phy_param_set.ds_param_set.current_chan);
  1011. mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_J_CMD: TLV Chan=%d\n",
  1012. chan_tlv->chan_scan_param[0].chan_number);
  1013. chan_tlv->chan_scan_param[0].radio_type =
  1014. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  1015. mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_J_CMD: TLV Band=%d\n",
  1016. chan_tlv->chan_scan_param[0].radio_type);
  1017. pos += sizeof(chan_tlv->header) +
  1018. sizeof(struct mwifiex_chan_scan_param_set);
  1019. cmd_append_size += sizeof(chan_tlv->header) +
  1020. sizeof(struct mwifiex_chan_scan_param_set);
  1021. }
  1022. if (priv->sec_info.wpa_enabled)
  1023. rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
  1024. if (rsn_ie_len == -1)
  1025. return -1;
  1026. cmd_append_size += rsn_ie_len;
  1027. if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
  1028. cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
  1029. bss_desc, &pos);
  1030. /* Append vendor specific IE TLV */
  1031. cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
  1032. MWIFIEX_VSIE_MASK_ADHOC, &pos);
  1033. cmd->size = cpu_to_le16
  1034. ((u16) (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
  1035. + S_DS_GEN + cmd_append_size));
  1036. adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
  1037. return 0;
  1038. }
  1039. /*
  1040. * This function handles the command response of ad-hoc start and
  1041. * ad-hoc join.
  1042. *
  1043. * The function generates a device-connected event to notify
  1044. * the applications, in case of successful ad-hoc start/join, and
  1045. * saves the beacon buffer.
  1046. */
  1047. int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
  1048. struct host_cmd_ds_command *resp)
  1049. {
  1050. int ret = 0;
  1051. struct mwifiex_adapter *adapter = priv->adapter;
  1052. struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
  1053. struct mwifiex_bssdescriptor *bss_desc;
  1054. u16 reason_code;
  1055. adhoc_result = &resp->params.adhoc_result;
  1056. bss_desc = priv->attempted_bss_desc;
  1057. /* Join result code 0 --> SUCCESS */
  1058. reason_code = le16_to_cpu(resp->result);
  1059. if (reason_code) {
  1060. mwifiex_dbg(priv->adapter, ERROR, "ADHOC_RESP: failed\n");
  1061. if (priv->media_connected)
  1062. mwifiex_reset_connect_state(priv, reason_code);
  1063. memset(&priv->curr_bss_params.bss_descriptor,
  1064. 0x00, sizeof(struct mwifiex_bssdescriptor));
  1065. ret = -1;
  1066. goto done;
  1067. }
  1068. /* Send a Media Connected event, according to the Spec */
  1069. priv->media_connected = true;
  1070. if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
  1071. mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_S_RESP %s\n",
  1072. bss_desc->ssid.ssid);
  1073. /* Update the created network descriptor with the new BSSID */
  1074. memcpy(bss_desc->mac_address,
  1075. adhoc_result->bssid, ETH_ALEN);
  1076. priv->adhoc_state = ADHOC_STARTED;
  1077. } else {
  1078. /*
  1079. * Now the join cmd should be successful.
  1080. * If BSSID has changed use SSID to compare instead of BSSID
  1081. */
  1082. mwifiex_dbg(priv->adapter, INFO,
  1083. "info: ADHOC_J_RESP %s\n",
  1084. bss_desc->ssid.ssid);
  1085. /*
  1086. * Make a copy of current BSSID descriptor, only needed for
  1087. * join since the current descriptor is already being used
  1088. * for adhoc start
  1089. */
  1090. memcpy(&priv->curr_bss_params.bss_descriptor,
  1091. bss_desc, sizeof(struct mwifiex_bssdescriptor));
  1092. priv->adhoc_state = ADHOC_JOINED;
  1093. }
  1094. mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_RESP: channel = %d\n",
  1095. priv->adhoc_channel);
  1096. mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_RESP: BSSID = %pM\n",
  1097. priv->curr_bss_params.bss_descriptor.mac_address);
  1098. if (!netif_carrier_ok(priv->netdev))
  1099. netif_carrier_on(priv->netdev);
  1100. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  1101. mwifiex_save_curr_bcn(priv);
  1102. done:
  1103. /* Need to indicate IOCTL complete */
  1104. if (adapter->curr_cmd->wait_q_enabled) {
  1105. if (ret)
  1106. adapter->cmd_wait_q.status = -1;
  1107. else
  1108. adapter->cmd_wait_q.status = 0;
  1109. }
  1110. return ret;
  1111. }
  1112. /*
  1113. * This function associates to a specific BSS discovered in a scan.
  1114. *
  1115. * It clears any past association response stored for application
  1116. * retrieval and calls the command preparation routine to send the
  1117. * command to firmware.
  1118. */
  1119. int mwifiex_associate(struct mwifiex_private *priv,
  1120. struct mwifiex_bssdescriptor *bss_desc)
  1121. {
  1122. /* Return error if the adapter is not STA role or table entry
  1123. * is not marked as infra.
  1124. */
  1125. if ((GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) ||
  1126. (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
  1127. return -1;
  1128. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
  1129. !bss_desc->disable_11n && !bss_desc->disable_11ac &&
  1130. priv->adapter->config_bands & BAND_AAC)
  1131. mwifiex_set_11ac_ba_params(priv);
  1132. else
  1133. mwifiex_set_ba_params(priv);
  1134. /* Clear any past association response stored for application
  1135. retrieval */
  1136. priv->assoc_rsp_size = 0;
  1137. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_ASSOCIATE,
  1138. HostCmd_ACT_GEN_SET, 0, bss_desc, true);
  1139. }
  1140. /*
  1141. * This function starts an ad-hoc network.
  1142. *
  1143. * It calls the command preparation routine to send the command to firmware.
  1144. */
  1145. int
  1146. mwifiex_adhoc_start(struct mwifiex_private *priv,
  1147. struct cfg80211_ssid *adhoc_ssid)
  1148. {
  1149. mwifiex_dbg(priv->adapter, INFO, "info: Adhoc Channel = %d\n",
  1150. priv->adhoc_channel);
  1151. mwifiex_dbg(priv->adapter, INFO, "info: curr_bss_params.channel = %d\n",
  1152. priv->curr_bss_params.bss_descriptor.channel);
  1153. mwifiex_dbg(priv->adapter, INFO, "info: curr_bss_params.band = %d\n",
  1154. priv->curr_bss_params.band);
  1155. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
  1156. priv->adapter->config_bands & BAND_AAC)
  1157. mwifiex_set_11ac_ba_params(priv);
  1158. else
  1159. mwifiex_set_ba_params(priv);
  1160. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_START,
  1161. HostCmd_ACT_GEN_SET, 0, adhoc_ssid, true);
  1162. }
  1163. /*
  1164. * This function joins an ad-hoc network found in a previous scan.
  1165. *
  1166. * It calls the command preparation routine to send the command to firmware,
  1167. * if already not connected to the requested SSID.
  1168. */
  1169. int mwifiex_adhoc_join(struct mwifiex_private *priv,
  1170. struct mwifiex_bssdescriptor *bss_desc)
  1171. {
  1172. mwifiex_dbg(priv->adapter, INFO,
  1173. "info: adhoc join: curr_bss ssid =%s\n",
  1174. priv->curr_bss_params.bss_descriptor.ssid.ssid);
  1175. mwifiex_dbg(priv->adapter, INFO,
  1176. "info: adhoc join: curr_bss ssid_len =%u\n",
  1177. priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
  1178. mwifiex_dbg(priv->adapter, INFO, "info: adhoc join: ssid =%s\n",
  1179. bss_desc->ssid.ssid);
  1180. mwifiex_dbg(priv->adapter, INFO, "info: adhoc join: ssid_len =%u\n",
  1181. bss_desc->ssid.ssid_len);
  1182. /* Check if the requested SSID is already joined */
  1183. if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
  1184. !mwifiex_ssid_cmp(&bss_desc->ssid,
  1185. &priv->curr_bss_params.bss_descriptor.ssid) &&
  1186. (priv->curr_bss_params.bss_descriptor.bss_mode ==
  1187. NL80211_IFTYPE_ADHOC)) {
  1188. mwifiex_dbg(priv->adapter, INFO,
  1189. "info: ADHOC_J_CMD: new ad-hoc SSID\t"
  1190. "is the same as current; not attempting to re-join\n");
  1191. return -1;
  1192. }
  1193. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
  1194. !bss_desc->disable_11n && !bss_desc->disable_11ac &&
  1195. priv->adapter->config_bands & BAND_AAC)
  1196. mwifiex_set_11ac_ba_params(priv);
  1197. else
  1198. mwifiex_set_ba_params(priv);
  1199. mwifiex_dbg(priv->adapter, INFO,
  1200. "info: curr_bss_params.channel = %d\n",
  1201. priv->curr_bss_params.bss_descriptor.channel);
  1202. mwifiex_dbg(priv->adapter, INFO,
  1203. "info: curr_bss_params.band = %c\n",
  1204. priv->curr_bss_params.band);
  1205. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
  1206. HostCmd_ACT_GEN_SET, 0, bss_desc, true);
  1207. }
  1208. /*
  1209. * This function deauthenticates/disconnects from infra network by sending
  1210. * deauthentication request.
  1211. */
  1212. static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
  1213. {
  1214. u8 mac_address[ETH_ALEN];
  1215. int ret;
  1216. if (!mac || is_zero_ether_addr(mac))
  1217. memcpy(mac_address,
  1218. priv->curr_bss_params.bss_descriptor.mac_address,
  1219. ETH_ALEN);
  1220. else
  1221. memcpy(mac_address, mac, ETH_ALEN);
  1222. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
  1223. HostCmd_ACT_GEN_SET, 0, mac_address, true);
  1224. return ret;
  1225. }
  1226. /*
  1227. * This function deauthenticates/disconnects from a BSS.
  1228. *
  1229. * In case of infra made, it sends deauthentication request, and
  1230. * in case of ad-hoc mode, a stop network request is sent to the firmware.
  1231. * In AP mode, a command to stop bss is sent to firmware.
  1232. */
  1233. int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
  1234. {
  1235. int ret = 0;
  1236. if (!priv->media_connected)
  1237. return 0;
  1238. switch (priv->bss_mode) {
  1239. case NL80211_IFTYPE_STATION:
  1240. case NL80211_IFTYPE_P2P_CLIENT:
  1241. ret = mwifiex_deauthenticate_infra(priv, mac);
  1242. if (ret)
  1243. cfg80211_disconnected(priv->netdev, 0, NULL, 0,
  1244. true, GFP_KERNEL);
  1245. break;
  1246. case NL80211_IFTYPE_ADHOC:
  1247. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_STOP,
  1248. HostCmd_ACT_GEN_SET, 0, NULL, true);
  1249. case NL80211_IFTYPE_AP:
  1250. return mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
  1251. HostCmd_ACT_GEN_SET, 0, NULL, true);
  1252. default:
  1253. break;
  1254. }
  1255. return ret;
  1256. }
  1257. /* This function deauthenticates/disconnects from all BSS. */
  1258. void mwifiex_deauthenticate_all(struct mwifiex_adapter *adapter)
  1259. {
  1260. struct mwifiex_private *priv;
  1261. int i;
  1262. for (i = 0; i < adapter->priv_num; i++) {
  1263. priv = adapter->priv[i];
  1264. if (priv)
  1265. mwifiex_deauthenticate(priv, NULL);
  1266. }
  1267. }
  1268. EXPORT_SYMBOL_GPL(mwifiex_deauthenticate_all);
  1269. /*
  1270. * This function converts band to radio type used in channel TLV.
  1271. */
  1272. u8
  1273. mwifiex_band_to_radio_type(u8 band)
  1274. {
  1275. switch (band) {
  1276. case BAND_A:
  1277. case BAND_AN:
  1278. case BAND_A | BAND_AN:
  1279. case BAND_A | BAND_AN | BAND_AAC:
  1280. return HostCmd_SCAN_RADIO_TYPE_A;
  1281. case BAND_B:
  1282. case BAND_G:
  1283. case BAND_B | BAND_G:
  1284. default:
  1285. return HostCmd_SCAN_RADIO_TYPE_BG;
  1286. }
  1287. }