join.c 44 KB

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