join.c 45 KB

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