join.c 43 KB

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