join.c 45 KB

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