join.c 45 KB

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