join.c 45 KB

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