join.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  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 if needed */
  379. if (priv->sec_info.authentication_mode != MWIFIEX_AUTH_MODE_AUTO) {
  380. auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
  381. auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
  382. auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
  383. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  384. auth_tlv->auth_type = cpu_to_le16((u16) priv->sec_info.
  385. authentication_mode);
  386. else
  387. auth_tlv->auth_type =
  388. cpu_to_le16(MWIFIEX_AUTH_MODE_OPEN);
  389. pos += sizeof(auth_tlv->header) +
  390. le16_to_cpu(auth_tlv->header.len);
  391. }
  392. if (IS_SUPPORT_MULTI_BANDS(priv->adapter)
  393. && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
  394. && (!bss_desc->disable_11n)
  395. && (priv->adapter->config_bands & BAND_GN
  396. || priv->adapter->config_bands & BAND_AN)
  397. && (bss_desc->bcn_ht_cap)
  398. )
  399. ) {
  400. /* Append a channel TLV for the channel the attempted AP was
  401. found on */
  402. chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
  403. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  404. chan_tlv->header.len =
  405. cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
  406. memset(chan_tlv->chan_scan_param, 0x00,
  407. sizeof(struct mwifiex_chan_scan_param_set));
  408. chan_tlv->chan_scan_param[0].chan_number =
  409. (bss_desc->phy_param_set.ds_param_set.current_chan);
  410. dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
  411. chan_tlv->chan_scan_param[0].chan_number);
  412. chan_tlv->chan_scan_param[0].radio_type =
  413. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  414. dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
  415. chan_tlv->chan_scan_param[0].radio_type);
  416. pos += sizeof(chan_tlv->header) +
  417. sizeof(struct mwifiex_chan_scan_param_set);
  418. }
  419. if (!priv->wps.session_enable) {
  420. if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
  421. rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
  422. if (rsn_ie_len == -1)
  423. return -1;
  424. }
  425. if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
  426. && (!bss_desc->disable_11n)
  427. && (priv->adapter->config_bands & BAND_GN
  428. || priv->adapter->config_bands & BAND_AN))
  429. mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
  430. /* Append vendor specific IE TLV */
  431. mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
  432. mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
  433. bss_desc->bcn_ht_cap);
  434. if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
  435. mwifiex_cmd_append_wapi_ie(priv, &pos);
  436. mwifiex_cmd_append_generic_ie(priv, &pos);
  437. mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
  438. cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
  439. /* Set the Capability info at last */
  440. tmp_cap = bss_desc->cap_info_bitmap;
  441. if (priv->adapter->config_bands == BAND_B)
  442. SHORT_SLOT_TIME_DISABLED(tmp_cap);
  443. tmp_cap &= CAPINFO_MASK;
  444. dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
  445. tmp_cap, CAPINFO_MASK);
  446. assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
  447. return 0;
  448. }
  449. /*
  450. * Association firmware command response handler
  451. *
  452. * The response buffer for the association command has the following
  453. * memory layout.
  454. *
  455. * For cases where an association response was not received (indicated
  456. * by the CapInfo and AId field):
  457. *
  458. * .------------------------------------------------------------.
  459. * | Header(4 * sizeof(t_u16)): Standard command response hdr |
  460. * .------------------------------------------------------------.
  461. * | cap_info/Error Return(t_u16): |
  462. * | 0xFFFF(-1): Internal error |
  463. * | 0xFFFE(-2): Authentication unhandled message |
  464. * | 0xFFFD(-3): Authentication refused |
  465. * | 0xFFFC(-4): Timeout waiting for AP response |
  466. * .------------------------------------------------------------.
  467. * | status_code(t_u16): |
  468. * | If cap_info is -1: |
  469. * | An internal firmware failure prevented the |
  470. * | command from being processed. The status_code |
  471. * | will be set to 1. |
  472. * | |
  473. * | If cap_info is -2: |
  474. * | An authentication frame was received but was |
  475. * | not handled by the firmware. IEEE Status |
  476. * | code for the failure is returned. |
  477. * | |
  478. * | If cap_info is -3: |
  479. * | An authentication frame was received and the |
  480. * | status_code is the IEEE Status reported in the |
  481. * | response. |
  482. * | |
  483. * | If cap_info is -4: |
  484. * | (1) Association response timeout |
  485. * | (2) Authentication response timeout |
  486. * .------------------------------------------------------------.
  487. * | a_id(t_u16): 0xFFFF |
  488. * .------------------------------------------------------------.
  489. *
  490. *
  491. * For cases where an association response was received, the IEEE
  492. * standard association response frame is returned:
  493. *
  494. * .------------------------------------------------------------.
  495. * | Header(4 * sizeof(t_u16)): Standard command response hdr |
  496. * .------------------------------------------------------------.
  497. * | cap_info(t_u16): IEEE Capability |
  498. * .------------------------------------------------------------.
  499. * | status_code(t_u16): IEEE Status Code |
  500. * .------------------------------------------------------------.
  501. * | a_id(t_u16): IEEE Association ID |
  502. * .------------------------------------------------------------.
  503. * | IEEE IEs(variable): Any received IEs comprising the |
  504. * | remaining portion of a received |
  505. * | association response frame. |
  506. * .------------------------------------------------------------.
  507. *
  508. * For simplistic handling, the status_code field can be used to determine
  509. * an association success (0) or failure (non-zero).
  510. */
  511. int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
  512. struct host_cmd_ds_command *resp, void *wq_buf)
  513. {
  514. int ret = 0;
  515. struct mwifiex_wait_queue *wait_queue =
  516. (struct mwifiex_wait_queue *) wq_buf;
  517. struct ieee_types_assoc_rsp *assoc_rsp;
  518. struct mwifiex_bssdescriptor *bss_desc;
  519. u8 enable_data = true;
  520. assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
  521. priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
  522. sizeof(priv->assoc_rsp_buf));
  523. memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
  524. if (le16_to_cpu(assoc_rsp->status_code)) {
  525. priv->adapter->dbg.num_cmd_assoc_failure++;
  526. dev_err(priv->adapter->dev, "ASSOC_RESP: association failed, "
  527. "status code = %d, error = 0x%x, a_id = 0x%x\n",
  528. le16_to_cpu(assoc_rsp->status_code),
  529. le16_to_cpu(assoc_rsp->cap_info_bitmap),
  530. le16_to_cpu(assoc_rsp->a_id));
  531. ret = -1;
  532. goto done;
  533. }
  534. /* Send a Media Connected event, according to the Spec */
  535. priv->media_connected = true;
  536. priv->adapter->ps_state = PS_STATE_AWAKE;
  537. priv->adapter->pps_uapsd_mode = false;
  538. priv->adapter->tx_lock_flag = false;
  539. /* Set the attempted BSSID Index to current */
  540. bss_desc = priv->attempted_bss_desc;
  541. dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
  542. bss_desc->ssid.ssid);
  543. /* Make a copy of current BSSID descriptor */
  544. memcpy(&priv->curr_bss_params.bss_descriptor,
  545. bss_desc, sizeof(struct mwifiex_bssdescriptor));
  546. /* Update curr_bss_params */
  547. priv->curr_bss_params.bss_descriptor.channel
  548. = bss_desc->phy_param_set.ds_param_set.current_chan;
  549. priv->curr_bss_params.band = (u8) bss_desc->bss_band;
  550. /*
  551. * Adjust the timestamps in the scan table to be relative to the newly
  552. * associated AP's TSF
  553. */
  554. mwifiex_update_tsf_timestamps(priv, bss_desc);
  555. if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
  556. priv->curr_bss_params.wmm_enabled = true;
  557. else
  558. priv->curr_bss_params.wmm_enabled = false;
  559. if ((priv->wmm_required || bss_desc->bcn_ht_cap)
  560. && priv->curr_bss_params.wmm_enabled)
  561. priv->wmm_enabled = true;
  562. else
  563. priv->wmm_enabled = false;
  564. priv->curr_bss_params.wmm_uapsd_enabled = false;
  565. if (priv->wmm_enabled)
  566. priv->curr_bss_params.wmm_uapsd_enabled
  567. = ((bss_desc->wmm_ie.qos_info_bitmap &
  568. IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
  569. dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
  570. priv->curr_pkt_filter);
  571. if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
  572. priv->wpa_is_gtk_set = false;
  573. if (priv->wmm_enabled) {
  574. /* Don't re-enable carrier until we get the WMM_GET_STATUS
  575. event */
  576. enable_data = false;
  577. } else {
  578. /* Since WMM is not enabled, setup the queues with the
  579. defaults */
  580. mwifiex_wmm_setup_queue_priorities(priv, NULL);
  581. mwifiex_wmm_setup_ac_downgrade(priv);
  582. }
  583. if (enable_data)
  584. dev_dbg(priv->adapter->dev,
  585. "info: post association, re-enabling data flow\n");
  586. /* Reset SNR/NF/RSSI values */
  587. priv->data_rssi_last = 0;
  588. priv->data_nf_last = 0;
  589. priv->data_rssi_avg = 0;
  590. priv->data_nf_avg = 0;
  591. priv->bcn_rssi_last = 0;
  592. priv->bcn_nf_last = 0;
  593. priv->bcn_rssi_avg = 0;
  594. priv->bcn_nf_avg = 0;
  595. priv->rxpd_rate = 0;
  596. priv->rxpd_htinfo = 0;
  597. mwifiex_save_curr_bcn(priv);
  598. priv->adapter->dbg.num_cmd_assoc_success++;
  599. dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
  600. /* Add the ra_list here for infra mode as there will be only 1 ra
  601. always */
  602. mwifiex_ralist_add(priv,
  603. priv->curr_bss_params.bss_descriptor.mac_address);
  604. if (!netif_carrier_ok(priv->netdev))
  605. netif_carrier_on(priv->netdev);
  606. if (netif_queue_stopped(priv->netdev))
  607. netif_wake_queue(priv->netdev);
  608. if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
  609. priv->scan_block = true;
  610. done:
  611. /* Need to indicate IOCTL complete */
  612. if (wait_queue) {
  613. if (ret) {
  614. if (assoc_rsp->status_code)
  615. wait_queue->status =
  616. le16_to_cpu(assoc_rsp->status_code);
  617. else
  618. wait_queue->status = MWIFIEX_ERROR_ASSOC_FAIL;
  619. } else {
  620. wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
  621. }
  622. }
  623. return ret;
  624. }
  625. /*
  626. * This function prepares command for ad-hoc start.
  627. *
  628. * Driver will fill up SSID, BSS mode, IBSS parameters, physical
  629. * parameters, probe delay, and capability information. Firmware
  630. * will fill up beacon period, basic rates and operational rates.
  631. *
  632. * In addition, the following TLVs are added -
  633. * - Channel TLV
  634. * - Vendor specific IE
  635. * - WPA/WPA2 IE
  636. * - HT Capabilities IE
  637. * - HT Information IE
  638. *
  639. * Preparation also includes -
  640. * - Setting command ID and proper size
  641. * - Ensuring correct endian-ness
  642. */
  643. int
  644. mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
  645. struct host_cmd_ds_command *cmd, void *data_buf)
  646. {
  647. int ret = 0, rsn_ie_len = 0;
  648. struct mwifiex_adapter *adapter = priv->adapter;
  649. struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
  650. &cmd->params.adhoc_start;
  651. struct mwifiex_bssdescriptor *bss_desc;
  652. u32 cmd_append_size = 0;
  653. u32 i;
  654. u16 tmp_cap;
  655. uint16_t ht_cap_info;
  656. struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
  657. struct mwifiex_ie_types_htcap *ht_cap;
  658. struct mwifiex_ie_types_htinfo *ht_info;
  659. u8 *pos = (u8 *) adhoc_start +
  660. sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
  661. if (!adapter)
  662. return -1;
  663. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
  664. bss_desc = &priv->curr_bss_params.bss_descriptor;
  665. priv->attempted_bss_desc = bss_desc;
  666. /*
  667. * Fill in the parameters for 2 data structures:
  668. * 1. struct host_cmd_ds_802_11_ad_hoc_start command
  669. * 2. bss_desc
  670. * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
  671. * probe delay, and Cap info.
  672. * Firmware will fill up beacon period, Basic rates
  673. * and operational rates.
  674. */
  675. memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
  676. memcpy(adhoc_start->ssid,
  677. ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
  678. ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
  679. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
  680. adhoc_start->ssid);
  681. memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
  682. memcpy(bss_desc->ssid.ssid,
  683. ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
  684. ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
  685. bss_desc->ssid.ssid_len =
  686. ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len;
  687. /* Set the BSS mode */
  688. adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
  689. bss_desc->bss_mode = MWIFIEX_BSS_MODE_IBSS;
  690. adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
  691. bss_desc->beacon_period = priv->beacon_period;
  692. /* Set Physical param set */
  693. /* Parameter IE Id */
  694. #define DS_PARA_IE_ID 3
  695. /* Parameter IE length */
  696. #define DS_PARA_IE_LEN 1
  697. adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
  698. adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
  699. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  700. (priv, adapter->adhoc_start_band, (u16)
  701. priv->adhoc_channel)) {
  702. struct mwifiex_chan_freq_power *cfp;
  703. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
  704. adapter->adhoc_start_band, FIRST_VALID_CHANNEL);
  705. if (cfp)
  706. priv->adhoc_channel = (u8) cfp->channel;
  707. }
  708. if (!priv->adhoc_channel) {
  709. dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
  710. return -1;
  711. }
  712. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
  713. priv->adhoc_channel);
  714. priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
  715. priv->curr_bss_params.band = adapter->adhoc_start_band;
  716. bss_desc->channel = priv->adhoc_channel;
  717. adhoc_start->phy_param_set.ds_param_set.current_chan =
  718. priv->adhoc_channel;
  719. memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
  720. sizeof(union ieee_types_phy_param_set));
  721. /* Set IBSS param set */
  722. /* IBSS parameter IE Id */
  723. #define IBSS_PARA_IE_ID 6
  724. /* IBSS parameter IE length */
  725. #define IBSS_PARA_IE_LEN 2
  726. adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
  727. adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
  728. adhoc_start->ss_param_set.ibss_param_set.atim_window
  729. = cpu_to_le16(priv->atim_window);
  730. memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
  731. sizeof(union ieee_types_ss_param_set));
  732. /* Set Capability info */
  733. bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
  734. tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
  735. tmp_cap &= ~WLAN_CAPABILITY_ESS;
  736. tmp_cap |= WLAN_CAPABILITY_IBSS;
  737. /* Set up privacy in bss_desc */
  738. if (priv->sec_info.encryption_mode != MWIFIEX_ENCRYPTION_MODE_NONE) {
  739. /* Ad-Hoc capability privacy on */
  740. dev_dbg(adapter->dev,
  741. "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
  742. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  743. tmp_cap |= WLAN_CAPABILITY_PRIVACY;
  744. } else {
  745. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
  746. " setting privacy to ACCEPT ALL\n");
  747. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  748. }
  749. memset(adhoc_start->DataRate, 0, sizeof(adhoc_start->DataRate));
  750. mwifiex_get_active_data_rates(priv, adhoc_start->DataRate);
  751. if ((adapter->adhoc_start_band & BAND_G) &&
  752. (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
  753. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  754. HostCmd_ACT_GEN_SET,
  755. 0, NULL, &priv->curr_pkt_filter);
  756. if (ret) {
  757. dev_err(adapter->dev,
  758. "ADHOC_S_CMD: G Protection config failed\n");
  759. return -1;
  760. }
  761. }
  762. /* Find the last non zero */
  763. for (i = 0; i < sizeof(adhoc_start->DataRate) &&
  764. adhoc_start->DataRate[i];
  765. i++)
  766. ;
  767. priv->curr_bss_params.num_of_rates = i;
  768. /* Copy the ad-hoc creating rates into Current BSS rate structure */
  769. memcpy(&priv->curr_bss_params.data_rates,
  770. &adhoc_start->DataRate, priv->curr_bss_params.num_of_rates);
  771. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
  772. adhoc_start->DataRate[0], adhoc_start->DataRate[1],
  773. adhoc_start->DataRate[2], adhoc_start->DataRate[3]);
  774. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
  775. if (IS_SUPPORT_MULTI_BANDS(adapter)) {
  776. /* Append a channel TLV */
  777. chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
  778. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  779. chan_tlv->header.len =
  780. cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
  781. memset(chan_tlv->chan_scan_param, 0x00,
  782. sizeof(struct mwifiex_chan_scan_param_set));
  783. chan_tlv->chan_scan_param[0].chan_number =
  784. (u8) priv->curr_bss_params.bss_descriptor.channel;
  785. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
  786. chan_tlv->chan_scan_param[0].chan_number);
  787. chan_tlv->chan_scan_param[0].radio_type
  788. = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  789. if (adapter->adhoc_start_band & BAND_GN
  790. || adapter->adhoc_start_band & BAND_AN) {
  791. if (adapter->chan_offset == SEC_CHANNEL_ABOVE)
  792. chan_tlv->chan_scan_param[0].radio_type |=
  793. SECOND_CHANNEL_ABOVE;
  794. else if (adapter->chan_offset == SEC_CHANNEL_BELOW)
  795. chan_tlv->chan_scan_param[0].radio_type |=
  796. SECOND_CHANNEL_BELOW;
  797. }
  798. dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
  799. chan_tlv->chan_scan_param[0].radio_type);
  800. pos += sizeof(chan_tlv->header) +
  801. sizeof(struct mwifiex_chan_scan_param_set);
  802. cmd_append_size +=
  803. sizeof(chan_tlv->header) +
  804. sizeof(struct mwifiex_chan_scan_param_set);
  805. }
  806. /* Append vendor specific IE TLV */
  807. cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
  808. MWIFIEX_VSIE_MASK_ADHOC, &pos);
  809. if (priv->sec_info.wpa_enabled) {
  810. rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
  811. if (rsn_ie_len == -1)
  812. return -1;
  813. cmd_append_size += rsn_ie_len;
  814. }
  815. if (adapter->adhoc_11n_enabled) {
  816. {
  817. ht_cap = (struct mwifiex_ie_types_htcap *) pos;
  818. memset(ht_cap, 0,
  819. sizeof(struct mwifiex_ie_types_htcap));
  820. ht_cap->header.type =
  821. cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  822. ht_cap->header.len =
  823. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  824. ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
  825. SETHT_SHORTGI20(ht_cap_info);
  826. if (adapter->chan_offset) {
  827. SETHT_SHORTGI40(ht_cap_info);
  828. SETHT_DSSSCCK40(ht_cap_info);
  829. SETHT_SUPPCHANWIDTH(ht_cap_info);
  830. SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
  831. }
  832. ht_cap->ht_cap.ampdu_params_info
  833. = MAX_RX_AMPDU_SIZE_64K;
  834. ht_cap->ht_cap.mcs.rx_mask[0] = 0xff;
  835. pos += sizeof(struct mwifiex_ie_types_htcap);
  836. cmd_append_size +=
  837. sizeof(struct mwifiex_ie_types_htcap);
  838. }
  839. {
  840. ht_info = (struct mwifiex_ie_types_htinfo *) pos;
  841. memset(ht_info, 0,
  842. sizeof(struct mwifiex_ie_types_htinfo));
  843. ht_info->header.type =
  844. cpu_to_le16(WLAN_EID_HT_INFORMATION);
  845. ht_info->header.len =
  846. cpu_to_le16(sizeof(struct ieee80211_ht_info));
  847. ht_info->ht_info.control_chan =
  848. (u8) priv->curr_bss_params.bss_descriptor.
  849. channel;
  850. if (adapter->chan_offset) {
  851. ht_info->ht_info.ht_param =
  852. adapter->chan_offset;
  853. SET_CHANWIDTH40(ht_info->ht_info.ht_param);
  854. }
  855. ht_info->ht_info.operation_mode =
  856. cpu_to_le16(NON_GREENFIELD_STAS);
  857. ht_info->ht_info.basic_set[0] = 0xff;
  858. pos += sizeof(struct mwifiex_ie_types_htinfo);
  859. cmd_append_size +=
  860. sizeof(struct mwifiex_ie_types_htinfo);
  861. }
  862. }
  863. cmd->size = cpu_to_le16((u16)
  864. (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. SHORT_SLOT_TIME_DISABLED(tmp_cap);
  868. else
  869. SHORT_SLOT_TIME_ENABLED(tmp_cap);
  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, void *data_buf)
  892. {
  893. int ret = 0, rsn_ie_len = 0;
  894. struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
  895. &cmd->params.adhoc_join;
  896. struct mwifiex_bssdescriptor *bss_desc =
  897. (struct mwifiex_bssdescriptor *) data_buf;
  898. struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
  899. u32 cmd_append_size = 0;
  900. u16 tmp_cap;
  901. u32 i, rates_size = 0;
  902. u16 curr_pkt_filter;
  903. u8 *pos =
  904. (u8 *) adhoc_join +
  905. sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
  906. /* Use G protection */
  907. #define USE_G_PROTECTION 0x02
  908. if (bss_desc->erp_flags & USE_G_PROTECTION) {
  909. curr_pkt_filter =
  910. priv->
  911. curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
  912. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  913. HostCmd_ACT_GEN_SET, 0, NULL,
  914. &curr_pkt_filter);
  915. if (ret) {
  916. dev_err(priv->adapter->dev,
  917. "ADHOC_J_CMD: G Protection config failed\n");
  918. return -1;
  919. }
  920. }
  921. priv->attempted_bss_desc = bss_desc;
  922. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
  923. adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
  924. adhoc_join->bss_descriptor.beacon_period
  925. = cpu_to_le16(bss_desc->beacon_period);
  926. memcpy(&adhoc_join->bss_descriptor.bssid,
  927. &bss_desc->mac_address, ETH_ALEN);
  928. memcpy(&adhoc_join->bss_descriptor.ssid,
  929. &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
  930. memcpy(&adhoc_join->bss_descriptor.phy_param_set,
  931. &bss_desc->phy_param_set,
  932. sizeof(union ieee_types_phy_param_set));
  933. memcpy(&adhoc_join->bss_descriptor.ss_param_set,
  934. &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
  935. tmp_cap = bss_desc->cap_info_bitmap;
  936. tmp_cap &= CAPINFO_MASK;
  937. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
  938. " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
  939. /* Information on BSSID descriptor passed to FW */
  940. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
  941. adhoc_join->bss_descriptor.bssid,
  942. adhoc_join->bss_descriptor.ssid);
  943. for (i = 0; bss_desc->supported_rates[i] &&
  944. i < MWIFIEX_SUPPORTED_RATES;
  945. i++)
  946. ;
  947. rates_size = i;
  948. /* Copy Data Rates from the Rates recorded in scan response */
  949. memset(adhoc_join->bss_descriptor.data_rates, 0,
  950. sizeof(adhoc_join->bss_descriptor.data_rates));
  951. memcpy(adhoc_join->bss_descriptor.data_rates,
  952. bss_desc->supported_rates, rates_size);
  953. /* Copy the adhoc join rates into Current BSS state structure */
  954. priv->curr_bss_params.num_of_rates = rates_size;
  955. memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
  956. rates_size);
  957. /* Copy the channel information */
  958. priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
  959. priv->curr_bss_params.band = (u8) bss_desc->bss_band;
  960. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
  961. || priv->sec_info.wpa_enabled)
  962. tmp_cap |= WLAN_CAPABILITY_PRIVACY;
  963. if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
  964. /* Append a channel TLV */
  965. chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
  966. chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  967. chan_tlv->header.len =
  968. cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
  969. memset(chan_tlv->chan_scan_param, 0x00,
  970. sizeof(struct mwifiex_chan_scan_param_set));
  971. chan_tlv->chan_scan_param[0].chan_number =
  972. (bss_desc->phy_param_set.ds_param_set.current_chan);
  973. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
  974. chan_tlv->chan_scan_param[0].chan_number);
  975. chan_tlv->chan_scan_param[0].radio_type =
  976. mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  977. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
  978. chan_tlv->chan_scan_param[0].radio_type);
  979. pos += sizeof(chan_tlv->header) +
  980. sizeof(struct mwifiex_chan_scan_param_set);
  981. cmd_append_size += sizeof(chan_tlv->header) +
  982. sizeof(struct mwifiex_chan_scan_param_set);
  983. }
  984. if (priv->sec_info.wpa_enabled)
  985. rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
  986. if (rsn_ie_len == -1)
  987. return -1;
  988. cmd_append_size += rsn_ie_len;
  989. if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
  990. cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
  991. bss_desc, &pos);
  992. /* Append vendor specific IE TLV */
  993. cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
  994. MWIFIEX_VSIE_MASK_ADHOC, &pos);
  995. cmd->size = cpu_to_le16((u16)
  996. (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
  997. + S_DS_GEN + cmd_append_size));
  998. adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
  999. return ret;
  1000. }
  1001. /*
  1002. * This function handles the command response of ad-hoc start and
  1003. * ad-hoc join.
  1004. *
  1005. * The function generates a device-connected event to notify
  1006. * the applications, in case of successful ad-hoc start/join, and
  1007. * saves the beacon buffer.
  1008. */
  1009. int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
  1010. struct host_cmd_ds_command *resp, void *wq_buf)
  1011. {
  1012. int ret = 0;
  1013. struct mwifiex_wait_queue *wait_queue =
  1014. (struct mwifiex_wait_queue *) wq_buf;
  1015. struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
  1016. struct mwifiex_bssdescriptor *bss_desc;
  1017. u16 command = le16_to_cpu(resp->command);
  1018. u16 result = le16_to_cpu(resp->result);
  1019. adhoc_result = &resp->params.adhoc_result;
  1020. bss_desc = priv->attempted_bss_desc;
  1021. /* Join result code 0 --> SUCCESS */
  1022. if (result) {
  1023. dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
  1024. if (priv->media_connected)
  1025. mwifiex_reset_connect_state(priv);
  1026. memset(&priv->curr_bss_params.bss_descriptor,
  1027. 0x00, sizeof(struct mwifiex_bssdescriptor));
  1028. ret = -1;
  1029. goto done;
  1030. }
  1031. /* Send a Media Connected event, according to the Spec */
  1032. priv->media_connected = true;
  1033. if (command == HostCmd_CMD_802_11_AD_HOC_START) {
  1034. dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
  1035. bss_desc->ssid.ssid);
  1036. /* Update the created network descriptor with the new BSSID */
  1037. memcpy(bss_desc->mac_address,
  1038. adhoc_result->bssid, ETH_ALEN);
  1039. priv->adhoc_state = ADHOC_STARTED;
  1040. } else {
  1041. /*
  1042. * Now the join cmd should be successful.
  1043. * If BSSID has changed use SSID to compare instead of BSSID
  1044. */
  1045. dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
  1046. bss_desc->ssid.ssid);
  1047. /*
  1048. * Make a copy of current BSSID descriptor, only needed for
  1049. * join since the current descriptor is already being used
  1050. * for adhoc start
  1051. */
  1052. memcpy(&priv->curr_bss_params.bss_descriptor,
  1053. bss_desc, sizeof(struct mwifiex_bssdescriptor));
  1054. priv->adhoc_state = ADHOC_JOINED;
  1055. }
  1056. dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
  1057. priv->adhoc_channel);
  1058. dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
  1059. priv->curr_bss_params.bss_descriptor.mac_address);
  1060. if (!netif_carrier_ok(priv->netdev))
  1061. netif_carrier_on(priv->netdev);
  1062. if (netif_queue_stopped(priv->netdev))
  1063. netif_wake_queue(priv->netdev);
  1064. mwifiex_save_curr_bcn(priv);
  1065. done:
  1066. /* Need to indicate IOCTL complete */
  1067. if (wait_queue) {
  1068. if (ret)
  1069. wait_queue->status = MWIFIEX_ERROR_ASSOC_FAIL;
  1070. else
  1071. wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
  1072. }
  1073. return ret;
  1074. }
  1075. /*
  1076. * This function associates to a specific BSS discovered in a scan.
  1077. *
  1078. * It clears any past association response stored for application
  1079. * retrieval and calls the command preparation routine to send the
  1080. * command to firmware.
  1081. */
  1082. int mwifiex_associate(struct mwifiex_private *priv,
  1083. void *wait_queue, struct mwifiex_bssdescriptor *bss_desc)
  1084. {
  1085. int ret = 0;
  1086. u8 current_bssid[ETH_ALEN];
  1087. /* Return error if the adapter or table entry is not marked as infra */
  1088. if ((priv->bss_mode != MWIFIEX_BSS_MODE_INFRA) ||
  1089. (bss_desc->bss_mode != MWIFIEX_BSS_MODE_INFRA))
  1090. return -1;
  1091. memcpy(&current_bssid,
  1092. &priv->curr_bss_params.bss_descriptor.mac_address,
  1093. sizeof(current_bssid));
  1094. /* Clear any past association response stored for application
  1095. retrieval */
  1096. priv->assoc_rsp_size = 0;
  1097. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_ASSOCIATE,
  1098. HostCmd_ACT_GEN_SET, 0, wait_queue,
  1099. bss_desc);
  1100. return ret;
  1101. }
  1102. /*
  1103. * This function starts an ad-hoc network.
  1104. *
  1105. * It calls the command preparation routine to send the command to firmware.
  1106. */
  1107. int
  1108. mwifiex_adhoc_start(struct mwifiex_private *priv,
  1109. void *wait_queue, struct mwifiex_802_11_ssid *adhoc_ssid)
  1110. {
  1111. int ret = 0;
  1112. dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
  1113. priv->adhoc_channel);
  1114. dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
  1115. priv->curr_bss_params.bss_descriptor.channel);
  1116. dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
  1117. priv->curr_bss_params.band);
  1118. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_AD_HOC_START,
  1119. HostCmd_ACT_GEN_SET, 0, wait_queue,
  1120. adhoc_ssid);
  1121. return ret;
  1122. }
  1123. /*
  1124. * This function joins an ad-hoc network found in a previous scan.
  1125. *
  1126. * It calls the command preparation routine to send the command to firmware,
  1127. * if already not connected to the requested SSID.
  1128. */
  1129. int mwifiex_adhoc_join(struct mwifiex_private *priv,
  1130. void *wait_queue, struct mwifiex_bssdescriptor *bss_desc)
  1131. {
  1132. int ret = 0;
  1133. dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
  1134. priv->curr_bss_params.bss_descriptor.ssid.ssid);
  1135. dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
  1136. priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
  1137. dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
  1138. bss_desc->ssid.ssid);
  1139. dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
  1140. bss_desc->ssid.ssid_len);
  1141. /* Check if the requested SSID is already joined */
  1142. if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
  1143. !mwifiex_ssid_cmp(&bss_desc->ssid,
  1144. &priv->curr_bss_params.bss_descriptor.ssid) &&
  1145. (priv->curr_bss_params.bss_descriptor.bss_mode ==
  1146. MWIFIEX_BSS_MODE_IBSS)) {
  1147. dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
  1148. " is the same as current; not attempting to re-join\n");
  1149. return -1;
  1150. }
  1151. dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
  1152. priv->curr_bss_params.bss_descriptor.channel);
  1153. dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
  1154. priv->curr_bss_params.band);
  1155. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
  1156. HostCmd_ACT_GEN_SET, 0, wait_queue,
  1157. bss_desc);
  1158. return ret;
  1159. }
  1160. /*
  1161. * This function deauthenticates/disconnects from infra network by sending
  1162. * deauthentication request.
  1163. */
  1164. static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv,
  1165. struct mwifiex_wait_queue *wait,
  1166. u8 *mac)
  1167. {
  1168. u8 mac_address[ETH_ALEN];
  1169. int ret = 0;
  1170. u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
  1171. if (mac) {
  1172. if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
  1173. memcpy((u8 *) &mac_address,
  1174. (u8 *) &priv->curr_bss_params.bss_descriptor.
  1175. mac_address, ETH_ALEN);
  1176. else
  1177. memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
  1178. } else {
  1179. memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
  1180. bss_descriptor.mac_address, ETH_ALEN);
  1181. }
  1182. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
  1183. HostCmd_ACT_GEN_SET, 0, wait, &mac_address);
  1184. if (!ret && wait)
  1185. ret = -EINPROGRESS;
  1186. return ret;
  1187. }
  1188. /*
  1189. * This function deauthenticates/disconnects from a BSS.
  1190. *
  1191. * In case of infra made, it sends deauthentication request, and
  1192. * in case of ad-hoc mode, a stop network request is sent to the firmware.
  1193. */
  1194. int mwifiex_deauthenticate(struct mwifiex_private *priv,
  1195. struct mwifiex_wait_queue *wait, u8 *mac)
  1196. {
  1197. int ret = 0;
  1198. if (priv->media_connected) {
  1199. if (priv->bss_mode == MWIFIEX_BSS_MODE_INFRA) {
  1200. ret = mwifiex_deauthenticate_infra(priv, wait, mac);
  1201. } else if (priv->bss_mode == MWIFIEX_BSS_MODE_IBSS) {
  1202. ret = mwifiex_prepare_cmd(priv,
  1203. HostCmd_CMD_802_11_AD_HOC_STOP,
  1204. HostCmd_ACT_GEN_SET, 0, wait, NULL);
  1205. if (!ret && wait)
  1206. ret = -EINPROGRESS;
  1207. }
  1208. }
  1209. return ret;
  1210. }
  1211. /*
  1212. * This function converts band to radio type used in channel TLV.
  1213. */
  1214. u8
  1215. mwifiex_band_to_radio_type(u8 band)
  1216. {
  1217. u8 ret_radio_type;
  1218. switch (band) {
  1219. case BAND_A:
  1220. case BAND_AN:
  1221. case BAND_A | BAND_AN:
  1222. ret_radio_type = HostCmd_SCAN_RADIO_TYPE_A;
  1223. break;
  1224. case BAND_B:
  1225. case BAND_G:
  1226. case BAND_B | BAND_G:
  1227. default:
  1228. ret_radio_type = HostCmd_SCAN_RADIO_TYPE_BG;
  1229. break;
  1230. }
  1231. return ret_radio_type;
  1232. }