join.c 47 KB

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