join.c 48 KB

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