join.c 45 KB

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