join.c 44 KB

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