sta_cmd.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. /*
  2. * Marvell Wireless LAN device driver: station command handling
  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. /*
  27. * This function prepares command to set/get RSSI information.
  28. *
  29. * Preparation includes -
  30. * - Setting command ID, action and proper size
  31. * - Setting data/beacon average factors
  32. * - Resetting SNR/NF/RSSI values in private structure
  33. * - Ensuring correct endian-ness
  34. */
  35. static int
  36. mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
  37. struct host_cmd_ds_command *cmd, u16 cmd_action)
  38. {
  39. cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
  40. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
  41. S_DS_GEN);
  42. cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
  43. cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
  44. cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
  45. /* Reset SNR/NF/RSSI values in private structure */
  46. priv->data_rssi_last = 0;
  47. priv->data_nf_last = 0;
  48. priv->data_rssi_avg = 0;
  49. priv->data_nf_avg = 0;
  50. priv->bcn_rssi_last = 0;
  51. priv->bcn_nf_last = 0;
  52. priv->bcn_rssi_avg = 0;
  53. priv->bcn_nf_avg = 0;
  54. return 0;
  55. }
  56. /*
  57. * This function prepares command to set MAC control.
  58. *
  59. * Preparation includes -
  60. * - Setting command ID, action and proper size
  61. * - Ensuring correct endian-ness
  62. */
  63. static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
  64. struct host_cmd_ds_command *cmd,
  65. u16 cmd_action, u16 *action)
  66. {
  67. struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
  68. if (cmd_action != HostCmd_ACT_GEN_SET) {
  69. dev_err(priv->adapter->dev,
  70. "mac_control: only support set cmd\n");
  71. return -1;
  72. }
  73. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
  74. cmd->size =
  75. cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
  76. mac_ctrl->action = cpu_to_le16(*action);
  77. return 0;
  78. }
  79. /*
  80. * This function prepares command to set/get SNMP MIB.
  81. *
  82. * Preparation includes -
  83. * - Setting command ID, action and proper size
  84. * - Setting SNMP MIB OID number and value
  85. * (as required)
  86. * - Ensuring correct endian-ness
  87. *
  88. * The following SNMP MIB OIDs are supported -
  89. * - FRAG_THRESH_I : Fragmentation threshold
  90. * - RTS_THRESH_I : RTS threshold
  91. * - SHORT_RETRY_LIM_I : Short retry limit
  92. * - DOT11D_I : 11d support
  93. */
  94. static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
  95. struct host_cmd_ds_command *cmd,
  96. u16 cmd_action, u32 cmd_oid,
  97. u16 *ul_temp)
  98. {
  99. struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
  100. dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
  101. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
  102. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
  103. - 1 + S_DS_GEN);
  104. snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
  105. if (cmd_action == HostCmd_ACT_GEN_GET) {
  106. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
  107. snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
  108. le16_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE);
  109. } else if (cmd_action == HostCmd_ACT_GEN_SET) {
  110. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  111. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  112. *((__le16 *) (snmp_mib->value)) = cpu_to_le16(*ul_temp);
  113. le16_add_cpu(&cmd->size, sizeof(u16));
  114. }
  115. dev_dbg(priv->adapter->dev,
  116. "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
  117. " Value=0x%x\n",
  118. cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
  119. le16_to_cpu(*(__le16 *) snmp_mib->value));
  120. return 0;
  121. }
  122. /*
  123. * This function prepares command to get log.
  124. *
  125. * Preparation includes -
  126. * - Setting command ID and proper size
  127. * - Ensuring correct endian-ness
  128. */
  129. static int
  130. mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
  131. {
  132. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
  133. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
  134. S_DS_GEN);
  135. return 0;
  136. }
  137. /*
  138. * This function prepares command to set/get Tx data rate configuration.
  139. *
  140. * Preparation includes -
  141. * - Setting command ID, action and proper size
  142. * - Setting configuration index, rate scope and rate drop pattern
  143. * parameters (as required)
  144. * - Ensuring correct endian-ness
  145. */
  146. static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
  147. struct host_cmd_ds_command *cmd,
  148. u16 cmd_action, u16 *pbitmap_rates)
  149. {
  150. struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
  151. struct mwifiex_rate_scope *rate_scope;
  152. struct mwifiex_rate_drop_pattern *rate_drop;
  153. u32 i;
  154. cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
  155. rate_cfg->action = cpu_to_le16(cmd_action);
  156. rate_cfg->cfg_index = 0;
  157. rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
  158. sizeof(struct host_cmd_ds_tx_rate_cfg));
  159. rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
  160. rate_scope->length = cpu_to_le16
  161. (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
  162. if (pbitmap_rates != NULL) {
  163. rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
  164. rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
  165. for (i = 0;
  166. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  167. i++)
  168. rate_scope->ht_mcs_rate_bitmap[i] =
  169. cpu_to_le16(pbitmap_rates[2 + i]);
  170. } else {
  171. rate_scope->hr_dsss_rate_bitmap =
  172. cpu_to_le16(priv->bitmap_rates[0]);
  173. rate_scope->ofdm_rate_bitmap =
  174. cpu_to_le16(priv->bitmap_rates[1]);
  175. for (i = 0;
  176. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  177. i++)
  178. rate_scope->ht_mcs_rate_bitmap[i] =
  179. cpu_to_le16(priv->bitmap_rates[2 + i]);
  180. }
  181. rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
  182. sizeof(struct mwifiex_rate_scope));
  183. rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
  184. rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
  185. rate_drop->rate_drop_mode = 0;
  186. cmd->size =
  187. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
  188. sizeof(struct mwifiex_rate_scope) +
  189. sizeof(struct mwifiex_rate_drop_pattern));
  190. return 0;
  191. }
  192. /*
  193. * This function prepares command to set/get Tx power configuration.
  194. *
  195. * Preparation includes -
  196. * - Setting command ID, action and proper size
  197. * - Setting Tx power mode, power group TLV
  198. * (as required)
  199. * - Ensuring correct endian-ness
  200. */
  201. static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
  202. u16 cmd_action,
  203. struct host_cmd_ds_txpwr_cfg *txp)
  204. {
  205. struct mwifiex_types_power_group *pg_tlv;
  206. struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
  207. cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
  208. cmd->size =
  209. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
  210. switch (cmd_action) {
  211. case HostCmd_ACT_GEN_SET:
  212. if (txp->mode) {
  213. pg_tlv = (struct mwifiex_types_power_group
  214. *) ((unsigned long) txp +
  215. sizeof(struct host_cmd_ds_txpwr_cfg));
  216. memmove(cmd_txp_cfg, txp,
  217. sizeof(struct host_cmd_ds_txpwr_cfg) +
  218. sizeof(struct mwifiex_types_power_group) +
  219. pg_tlv->length);
  220. pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
  221. cmd_txp_cfg +
  222. sizeof(struct host_cmd_ds_txpwr_cfg));
  223. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
  224. sizeof(struct mwifiex_types_power_group) +
  225. pg_tlv->length);
  226. } else {
  227. memmove(cmd_txp_cfg, txp, sizeof(*txp));
  228. }
  229. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  230. break;
  231. case HostCmd_ACT_GEN_GET:
  232. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  233. break;
  234. }
  235. return 0;
  236. }
  237. /*
  238. * This function prepares command to set Host Sleep configuration.
  239. *
  240. * Preparation includes -
  241. * - Setting command ID and proper size
  242. * - Setting Host Sleep action, conditions, ARP filters
  243. * (as required)
  244. * - Ensuring correct endian-ness
  245. */
  246. static int
  247. mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
  248. struct host_cmd_ds_command *cmd,
  249. u16 cmd_action,
  250. struct mwifiex_hs_config_param *hscfg_param)
  251. {
  252. struct mwifiex_adapter *adapter = priv->adapter;
  253. struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
  254. u16 hs_activate = false;
  255. if (!hscfg_param)
  256. /* New Activate command */
  257. hs_activate = true;
  258. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
  259. if (!hs_activate &&
  260. (hscfg_param->conditions != cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) &&
  261. ((adapter->arp_filter_size > 0) &&
  262. (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
  263. dev_dbg(adapter->dev,
  264. "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
  265. adapter->arp_filter_size);
  266. memcpy(((u8 *) hs_cfg) +
  267. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
  268. adapter->arp_filter, adapter->arp_filter_size);
  269. cmd->size = cpu_to_le16
  270. (adapter->arp_filter_size +
  271. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
  272. + S_DS_GEN);
  273. } else {
  274. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
  275. host_cmd_ds_802_11_hs_cfg_enh));
  276. }
  277. if (hs_activate) {
  278. hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
  279. hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED;
  280. } else {
  281. hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
  282. hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
  283. hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
  284. hs_cfg->params.hs_config.gap = hscfg_param->gap;
  285. dev_dbg(adapter->dev,
  286. "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
  287. hs_cfg->params.hs_config.conditions,
  288. hs_cfg->params.hs_config.gpio,
  289. hs_cfg->params.hs_config.gap);
  290. }
  291. return 0;
  292. }
  293. /*
  294. * This function prepares command to set/get MAC address.
  295. *
  296. * Preparation includes -
  297. * - Setting command ID, action and proper size
  298. * - Setting MAC address (for SET only)
  299. * - Ensuring correct endian-ness
  300. */
  301. static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
  302. struct host_cmd_ds_command *cmd,
  303. u16 cmd_action)
  304. {
  305. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
  306. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
  307. S_DS_GEN);
  308. cmd->result = 0;
  309. cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
  310. if (cmd_action == HostCmd_ACT_GEN_SET)
  311. memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
  312. ETH_ALEN);
  313. return 0;
  314. }
  315. /*
  316. * This function prepares command to set MAC multicast address.
  317. *
  318. * Preparation includes -
  319. * - Setting command ID, action and proper size
  320. * - Setting MAC multicast address
  321. * - Ensuring correct endian-ness
  322. */
  323. static int
  324. mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
  325. u16 cmd_action,
  326. struct mwifiex_multicast_list *mcast_list)
  327. {
  328. struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
  329. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
  330. S_DS_GEN);
  331. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
  332. mcast_addr->action = cpu_to_le16(cmd_action);
  333. mcast_addr->num_of_adrs =
  334. cpu_to_le16((u16) mcast_list->num_multicast_addr);
  335. memcpy(mcast_addr->mac_list, mcast_list->mac_list,
  336. mcast_list->num_multicast_addr * ETH_ALEN);
  337. return 0;
  338. }
  339. /*
  340. * This function prepares command to deauthenticate.
  341. *
  342. * Preparation includes -
  343. * - Setting command ID and proper size
  344. * - Setting AP MAC address and reason code
  345. * - Ensuring correct endian-ness
  346. */
  347. static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
  348. struct host_cmd_ds_command *cmd,
  349. u8 *mac)
  350. {
  351. struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
  352. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
  353. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
  354. + S_DS_GEN);
  355. /* Set AP MAC address */
  356. memcpy(deauth->mac_addr, mac, ETH_ALEN);
  357. dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
  358. deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
  359. return 0;
  360. }
  361. /*
  362. * This function prepares command to stop Ad-Hoc network.
  363. *
  364. * Preparation includes -
  365. * - Setting command ID and proper size
  366. * - Ensuring correct endian-ness
  367. */
  368. static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
  369. {
  370. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
  371. cmd->size = cpu_to_le16(S_DS_GEN);
  372. return 0;
  373. }
  374. /*
  375. * This function sets WEP key(s) to key parameter TLV(s).
  376. *
  377. * Multi-key parameter TLVs are supported, so we can send multiple
  378. * WEP keys in a single buffer.
  379. */
  380. static int
  381. mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
  382. struct mwifiex_ie_type_key_param_set *key_param_set,
  383. u16 *key_param_len)
  384. {
  385. int cur_key_param_len;
  386. u8 i;
  387. /* Multi-key_param_set TLV is supported */
  388. for (i = 0; i < NUM_WEP_KEYS; i++) {
  389. if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
  390. (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
  391. key_param_set->type =
  392. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  393. /* Key_param_set WEP fixed length */
  394. #define KEYPARAMSET_WEP_FIXED_LEN 8
  395. key_param_set->length = cpu_to_le16((u16)
  396. (priv->wep_key[i].
  397. key_length +
  398. KEYPARAMSET_WEP_FIXED_LEN));
  399. key_param_set->key_type_id =
  400. cpu_to_le16(KEY_TYPE_ID_WEP);
  401. key_param_set->key_info =
  402. cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
  403. KEY_MCAST);
  404. key_param_set->key_len =
  405. cpu_to_le16(priv->wep_key[i].key_length);
  406. /* Set WEP key index */
  407. key_param_set->key[0] = i;
  408. /* Set default Tx key flag */
  409. if (i ==
  410. (priv->
  411. wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
  412. key_param_set->key[1] = 1;
  413. else
  414. key_param_set->key[1] = 0;
  415. memmove(&key_param_set->key[2],
  416. priv->wep_key[i].key_material,
  417. priv->wep_key[i].key_length);
  418. cur_key_param_len = priv->wep_key[i].key_length +
  419. KEYPARAMSET_WEP_FIXED_LEN +
  420. sizeof(struct mwifiex_ie_types_header);
  421. *key_param_len += (u16) cur_key_param_len;
  422. key_param_set =
  423. (struct mwifiex_ie_type_key_param_set *)
  424. ((u8 *)key_param_set +
  425. cur_key_param_len);
  426. } else if (!priv->wep_key[i].key_length) {
  427. continue;
  428. } else {
  429. dev_err(priv->adapter->dev,
  430. "key%d Length = %d is incorrect\n",
  431. (i + 1), priv->wep_key[i].key_length);
  432. return -1;
  433. }
  434. }
  435. return 0;
  436. }
  437. /*
  438. * This function prepares command to set/get/reset network key(s).
  439. *
  440. * Preparation includes -
  441. * - Setting command ID, action and proper size
  442. * - Setting WEP keys, WAPI keys or WPA keys along with required
  443. * encryption (TKIP, AES) (as required)
  444. * - Ensuring correct endian-ness
  445. */
  446. static int
  447. mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
  448. struct host_cmd_ds_command *cmd,
  449. u16 cmd_action, u32 cmd_oid,
  450. struct mwifiex_ds_encrypt_key *enc_key)
  451. {
  452. struct host_cmd_ds_802_11_key_material *key_material =
  453. &cmd->params.key_material;
  454. struct host_cmd_tlv_mac_addr *tlv_mac;
  455. u16 key_param_len = 0, cmd_size;
  456. int ret = 0;
  457. const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  458. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
  459. key_material->action = cpu_to_le16(cmd_action);
  460. if (cmd_action == HostCmd_ACT_GEN_GET) {
  461. cmd->size =
  462. cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
  463. return ret;
  464. }
  465. if (!enc_key) {
  466. memset(&key_material->key_param_set, 0,
  467. (NUM_WEP_KEYS *
  468. sizeof(struct mwifiex_ie_type_key_param_set)));
  469. ret = mwifiex_set_keyparamset_wep(priv,
  470. &key_material->key_param_set,
  471. &key_param_len);
  472. cmd->size = cpu_to_le16(key_param_len +
  473. sizeof(key_material->action) + S_DS_GEN);
  474. return ret;
  475. } else
  476. memset(&key_material->key_param_set, 0,
  477. sizeof(struct mwifiex_ie_type_key_param_set));
  478. if (enc_key->is_wapi_key) {
  479. dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
  480. key_material->key_param_set.key_type_id =
  481. cpu_to_le16(KEY_TYPE_ID_WAPI);
  482. if (cmd_oid == KEY_INFO_ENABLED)
  483. key_material->key_param_set.key_info =
  484. cpu_to_le16(KEY_ENABLED);
  485. else
  486. key_material->key_param_set.key_info =
  487. cpu_to_le16(!KEY_ENABLED);
  488. key_material->key_param_set.key[0] = enc_key->key_index;
  489. if (!priv->sec_info.wapi_key_on)
  490. key_material->key_param_set.key[1] = 1;
  491. else
  492. /* set 0 when re-key */
  493. key_material->key_param_set.key[1] = 0;
  494. if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
  495. /* WAPI pairwise key: unicast */
  496. key_material->key_param_set.key_info |=
  497. cpu_to_le16(KEY_UNICAST);
  498. } else { /* WAPI group key: multicast */
  499. key_material->key_param_set.key_info |=
  500. cpu_to_le16(KEY_MCAST);
  501. priv->sec_info.wapi_key_on = true;
  502. }
  503. key_material->key_param_set.type =
  504. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  505. key_material->key_param_set.key_len =
  506. cpu_to_le16(WAPI_KEY_LEN);
  507. memcpy(&key_material->key_param_set.key[2],
  508. enc_key->key_material, enc_key->key_len);
  509. memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
  510. enc_key->wapi_rxpn, WAPI_RXPN_LEN);
  511. key_material->key_param_set.length =
  512. cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
  513. key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
  514. sizeof(struct mwifiex_ie_types_header);
  515. cmd->size = cpu_to_le16(sizeof(key_material->action)
  516. + S_DS_GEN + key_param_len);
  517. return ret;
  518. }
  519. if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
  520. dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
  521. key_material->key_param_set.key_type_id =
  522. cpu_to_le16(KEY_TYPE_ID_AES);
  523. if (cmd_oid == KEY_INFO_ENABLED)
  524. key_material->key_param_set.key_info =
  525. cpu_to_le16(KEY_ENABLED);
  526. else
  527. key_material->key_param_set.key_info =
  528. cpu_to_le16(!KEY_ENABLED);
  529. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  530. /* AES pairwise key: unicast */
  531. key_material->key_param_set.key_info |=
  532. cpu_to_le16(KEY_UNICAST);
  533. else /* AES group key: multicast */
  534. key_material->key_param_set.key_info |=
  535. cpu_to_le16(KEY_MCAST);
  536. } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
  537. dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
  538. key_material->key_param_set.key_type_id =
  539. cpu_to_le16(KEY_TYPE_ID_TKIP);
  540. key_material->key_param_set.key_info =
  541. cpu_to_le16(KEY_ENABLED);
  542. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  543. /* TKIP pairwise key: unicast */
  544. key_material->key_param_set.key_info |=
  545. cpu_to_le16(KEY_UNICAST);
  546. else /* TKIP group key: multicast */
  547. key_material->key_param_set.key_info |=
  548. cpu_to_le16(KEY_MCAST);
  549. }
  550. if (key_material->key_param_set.key_type_id) {
  551. key_material->key_param_set.type =
  552. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  553. key_material->key_param_set.key_len =
  554. cpu_to_le16((u16) enc_key->key_len);
  555. memcpy(key_material->key_param_set.key, enc_key->key_material,
  556. enc_key->key_len);
  557. key_material->key_param_set.length =
  558. cpu_to_le16((u16) enc_key->key_len +
  559. KEYPARAMSET_FIXED_LEN);
  560. key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
  561. + sizeof(struct mwifiex_ie_types_header);
  562. cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
  563. + key_param_len);
  564. if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
  565. tlv_mac = (void *)((u8 *)&key_material->key_param_set +
  566. key_param_len);
  567. tlv_mac->tlv.type = cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
  568. tlv_mac->tlv.len = cpu_to_le16(ETH_ALEN);
  569. memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
  570. cmd_size = key_param_len + S_DS_GEN +
  571. sizeof(key_material->action) +
  572. sizeof(struct host_cmd_tlv_mac_addr);
  573. } else {
  574. cmd_size = key_param_len + S_DS_GEN +
  575. sizeof(key_material->action);
  576. }
  577. cmd->size = cpu_to_le16(cmd_size);
  578. }
  579. return ret;
  580. }
  581. /*
  582. * This function prepares command to set/get 11d domain information.
  583. *
  584. * Preparation includes -
  585. * - Setting command ID, action and proper size
  586. * - Setting domain information fields (for SET only)
  587. * - Ensuring correct endian-ness
  588. */
  589. static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
  590. struct host_cmd_ds_command *cmd,
  591. u16 cmd_action)
  592. {
  593. struct mwifiex_adapter *adapter = priv->adapter;
  594. struct host_cmd_ds_802_11d_domain_info *domain_info =
  595. &cmd->params.domain_info;
  596. struct mwifiex_ietypes_domain_param_set *domain =
  597. &domain_info->domain;
  598. u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
  599. dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
  600. cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
  601. domain_info->action = cpu_to_le16(cmd_action);
  602. if (cmd_action == HostCmd_ACT_GEN_GET) {
  603. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  604. return 0;
  605. }
  606. /* Set domain info fields */
  607. domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
  608. memcpy(domain->country_code, adapter->domain_reg.country_code,
  609. sizeof(domain->country_code));
  610. domain->header.len =
  611. cpu_to_le16((no_of_triplet *
  612. sizeof(struct ieee80211_country_ie_triplet))
  613. + sizeof(domain->country_code));
  614. if (no_of_triplet) {
  615. memcpy(domain->triplet, adapter->domain_reg.triplet,
  616. no_of_triplet * sizeof(struct
  617. ieee80211_country_ie_triplet));
  618. cmd->size = cpu_to_le16(sizeof(domain_info->action) +
  619. le16_to_cpu(domain->header.len) +
  620. sizeof(struct mwifiex_ie_types_header)
  621. + S_DS_GEN);
  622. } else {
  623. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  624. }
  625. return 0;
  626. }
  627. /*
  628. * This function prepares command to set/get RF channel.
  629. *
  630. * Preparation includes -
  631. * - Setting command ID, action and proper size
  632. * - Setting RF type and current RF channel (for SET only)
  633. * - Ensuring correct endian-ness
  634. */
  635. static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv,
  636. struct host_cmd_ds_command *cmd,
  637. u16 cmd_action, u16 *channel)
  638. {
  639. struct host_cmd_ds_802_11_rf_channel *rf_chan =
  640. &cmd->params.rf_channel;
  641. uint16_t rf_type = le16_to_cpu(rf_chan->rf_type);
  642. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL);
  643. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel)
  644. + S_DS_GEN);
  645. if (cmd_action == HostCmd_ACT_GEN_SET) {
  646. if ((priv->adapter->adhoc_start_band & BAND_A) ||
  647. (priv->adapter->adhoc_start_band & BAND_AN))
  648. rf_chan->rf_type =
  649. cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A);
  650. rf_type = le16_to_cpu(rf_chan->rf_type);
  651. SET_SECONDARYCHAN(rf_type, priv->adapter->sec_chan_offset);
  652. rf_chan->current_channel = cpu_to_le16(*channel);
  653. }
  654. rf_chan->action = cpu_to_le16(cmd_action);
  655. return 0;
  656. }
  657. /*
  658. * This function prepares command to set/get IBSS coalescing status.
  659. *
  660. * Preparation includes -
  661. * - Setting command ID, action and proper size
  662. * - Setting status to enable or disable (for SET only)
  663. * - Ensuring correct endian-ness
  664. */
  665. static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
  666. u16 cmd_action, u16 *enable)
  667. {
  668. struct host_cmd_ds_802_11_ibss_status *ibss_coal =
  669. &(cmd->params.ibss_coalescing);
  670. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
  671. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
  672. S_DS_GEN);
  673. cmd->result = 0;
  674. ibss_coal->action = cpu_to_le16(cmd_action);
  675. switch (cmd_action) {
  676. case HostCmd_ACT_GEN_SET:
  677. if (enable)
  678. ibss_coal->enable = cpu_to_le16(*enable);
  679. else
  680. ibss_coal->enable = 0;
  681. break;
  682. /* In other case.. Nothing to do */
  683. case HostCmd_ACT_GEN_GET:
  684. default:
  685. break;
  686. }
  687. return 0;
  688. }
  689. /*
  690. * This function prepares command to set/get register value.
  691. *
  692. * Preparation includes -
  693. * - Setting command ID, action and proper size
  694. * - Setting register offset (for both GET and SET) and
  695. * register value (for SET only)
  696. * - Ensuring correct endian-ness
  697. *
  698. * The following type of registers can be accessed with this function -
  699. * - MAC register
  700. * - BBP register
  701. * - RF register
  702. * - PMIC register
  703. * - CAU register
  704. * - EEPROM
  705. */
  706. static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
  707. u16 cmd_action, void *data_buf)
  708. {
  709. struct mwifiex_ds_reg_rw *reg_rw = data_buf;
  710. switch (le16_to_cpu(cmd->command)) {
  711. case HostCmd_CMD_MAC_REG_ACCESS:
  712. {
  713. struct host_cmd_ds_mac_reg_access *mac_reg;
  714. cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
  715. mac_reg = (struct host_cmd_ds_mac_reg_access *) &cmd->
  716. params.mac_reg;
  717. mac_reg->action = cpu_to_le16(cmd_action);
  718. mac_reg->offset =
  719. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  720. mac_reg->value = reg_rw->value;
  721. break;
  722. }
  723. case HostCmd_CMD_BBP_REG_ACCESS:
  724. {
  725. struct host_cmd_ds_bbp_reg_access *bbp_reg;
  726. cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
  727. bbp_reg = (struct host_cmd_ds_bbp_reg_access *)
  728. &cmd->params.bbp_reg;
  729. bbp_reg->action = cpu_to_le16(cmd_action);
  730. bbp_reg->offset =
  731. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  732. bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
  733. break;
  734. }
  735. case HostCmd_CMD_RF_REG_ACCESS:
  736. {
  737. struct host_cmd_ds_rf_reg_access *rf_reg;
  738. cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
  739. rf_reg = (struct host_cmd_ds_rf_reg_access *)
  740. &cmd->params.rf_reg;
  741. rf_reg->action = cpu_to_le16(cmd_action);
  742. rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  743. rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
  744. break;
  745. }
  746. case HostCmd_CMD_PMIC_REG_ACCESS:
  747. {
  748. struct host_cmd_ds_pmic_reg_access *pmic_reg;
  749. cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
  750. pmic_reg = (struct host_cmd_ds_pmic_reg_access *) &cmd->
  751. params.pmic_reg;
  752. pmic_reg->action = cpu_to_le16(cmd_action);
  753. pmic_reg->offset =
  754. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  755. pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
  756. break;
  757. }
  758. case HostCmd_CMD_CAU_REG_ACCESS:
  759. {
  760. struct host_cmd_ds_rf_reg_access *cau_reg;
  761. cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
  762. cau_reg = (struct host_cmd_ds_rf_reg_access *)
  763. &cmd->params.rf_reg;
  764. cau_reg->action = cpu_to_le16(cmd_action);
  765. cau_reg->offset =
  766. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  767. cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
  768. break;
  769. }
  770. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  771. {
  772. struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
  773. struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
  774. (struct host_cmd_ds_802_11_eeprom_access *)
  775. &cmd->params.eeprom;
  776. cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
  777. cmd_eeprom->action = cpu_to_le16(cmd_action);
  778. cmd_eeprom->offset = rd_eeprom->offset;
  779. cmd_eeprom->byte_count = rd_eeprom->byte_count;
  780. cmd_eeprom->value = 0;
  781. break;
  782. }
  783. default:
  784. return -1;
  785. }
  786. return 0;
  787. }
  788. /*
  789. * This function prepares command to set PCI-Express
  790. * host buffer configuration
  791. *
  792. * Preparation includes -
  793. * - Setting command ID, action and proper size
  794. * - Setting host buffer configuration
  795. * - Ensuring correct endian-ness
  796. */
  797. static int
  798. mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
  799. struct host_cmd_ds_command *cmd, u16 action)
  800. {
  801. struct host_cmd_ds_pcie_details *host_spec =
  802. &cmd->params.pcie_host_spec;
  803. struct pcie_service_card *card = priv->adapter->card;
  804. phys_addr_t *buf_pa;
  805. cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
  806. cmd->size = cpu_to_le16(sizeof(struct
  807. host_cmd_ds_pcie_details) + S_DS_GEN);
  808. cmd->result = 0;
  809. memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
  810. if (action != HostCmd_ACT_GEN_SET)
  811. return 0;
  812. /* Send the ring base addresses and count to firmware */
  813. host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
  814. host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
  815. host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
  816. host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
  817. host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
  818. host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
  819. host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
  820. host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
  821. host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
  822. if (card->sleep_cookie) {
  823. buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie);
  824. host_spec->sleep_cookie_addr_lo = (u32) *buf_pa;
  825. host_spec->sleep_cookie_addr_hi = (u32) (((u64)*buf_pa) >> 32);
  826. dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
  827. host_spec->sleep_cookie_addr_lo);
  828. }
  829. return 0;
  830. }
  831. /*
  832. * This function prepares command for event subscription, configuration
  833. * and query. Events can be subscribed or unsubscribed. Current subscribed
  834. * events can be queried. Also, current subscribed events are reported in
  835. * every FW response.
  836. */
  837. static int
  838. mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
  839. struct host_cmd_ds_command *cmd,
  840. struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
  841. {
  842. struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
  843. struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
  844. u16 event_bitmap;
  845. u8 *pos;
  846. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
  847. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
  848. S_DS_GEN);
  849. subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
  850. dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
  851. /*For query requests, no configuration TLV structures are to be added.*/
  852. if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
  853. return 0;
  854. subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
  855. event_bitmap = subsc_evt_cfg->events;
  856. dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
  857. event_bitmap);
  858. if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
  859. (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
  860. (event_bitmap == 0)) {
  861. dev_dbg(priv->adapter->dev, "Error: No event specified "
  862. "for bitwise action type\n");
  863. return -EINVAL;
  864. }
  865. /*
  866. * Append TLV structures for each of the specified events for
  867. * subscribing or re-configuring. This is not required for
  868. * bitwise unsubscribing request.
  869. */
  870. if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
  871. return 0;
  872. pos = ((u8 *)subsc_evt) +
  873. sizeof(struct host_cmd_ds_802_11_subsc_evt);
  874. if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
  875. rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
  876. rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
  877. rssi_tlv->header.len =
  878. cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
  879. sizeof(struct mwifiex_ie_types_header));
  880. rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
  881. rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
  882. dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
  883. "RSSI:-%d dBm, Freq:%d\n",
  884. subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
  885. subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
  886. pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
  887. le16_add_cpu(&cmd->size,
  888. sizeof(struct mwifiex_ie_types_rssi_threshold));
  889. }
  890. if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
  891. rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
  892. rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
  893. rssi_tlv->header.len =
  894. cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
  895. sizeof(struct mwifiex_ie_types_header));
  896. rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
  897. rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
  898. dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
  899. "RSSI:-%d dBm, Freq:%d\n",
  900. subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
  901. subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
  902. pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
  903. le16_add_cpu(&cmd->size,
  904. sizeof(struct mwifiex_ie_types_rssi_threshold));
  905. }
  906. return 0;
  907. }
  908. /*
  909. * This function prepares the commands before sending them to the firmware.
  910. *
  911. * This is a generic function which calls specific command preparation
  912. * routines based upon the command number.
  913. */
  914. int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
  915. u16 cmd_action, u32 cmd_oid,
  916. void *data_buf, void *cmd_buf)
  917. {
  918. struct host_cmd_ds_command *cmd_ptr = cmd_buf;
  919. int ret = 0;
  920. /* Prepare command */
  921. switch (cmd_no) {
  922. case HostCmd_CMD_GET_HW_SPEC:
  923. ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
  924. break;
  925. case HostCmd_CMD_MAC_CONTROL:
  926. ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
  927. data_buf);
  928. break;
  929. case HostCmd_CMD_802_11_MAC_ADDRESS:
  930. ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
  931. cmd_action);
  932. break;
  933. case HostCmd_CMD_MAC_MULTICAST_ADR:
  934. ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
  935. data_buf);
  936. break;
  937. case HostCmd_CMD_TX_RATE_CFG:
  938. ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
  939. data_buf);
  940. break;
  941. case HostCmd_CMD_TXPWR_CFG:
  942. ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
  943. data_buf);
  944. break;
  945. case HostCmd_CMD_802_11_PS_MODE_ENH:
  946. ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
  947. (uint16_t)cmd_oid, data_buf);
  948. break;
  949. case HostCmd_CMD_802_11_HS_CFG_ENH:
  950. ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
  951. (struct mwifiex_hs_config_param *) data_buf);
  952. break;
  953. case HostCmd_CMD_802_11_SCAN:
  954. ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
  955. break;
  956. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  957. ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
  958. break;
  959. case HostCmd_CMD_802_11_ASSOCIATE:
  960. ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
  961. break;
  962. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  963. ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
  964. data_buf);
  965. break;
  966. case HostCmd_CMD_802_11_AD_HOC_START:
  967. ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
  968. data_buf);
  969. break;
  970. case HostCmd_CMD_802_11_GET_LOG:
  971. ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
  972. break;
  973. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  974. ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
  975. data_buf);
  976. break;
  977. case HostCmd_CMD_802_11_AD_HOC_STOP:
  978. ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
  979. break;
  980. case HostCmd_CMD_RSSI_INFO:
  981. ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
  982. break;
  983. case HostCmd_CMD_802_11_SNMP_MIB:
  984. ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
  985. cmd_oid, data_buf);
  986. break;
  987. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  988. cmd_ptr->command =
  989. cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
  990. cmd_ptr->size =
  991. cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
  992. S_DS_GEN);
  993. priv->tx_rate = 0;
  994. ret = 0;
  995. break;
  996. case HostCmd_CMD_VERSION_EXT:
  997. cmd_ptr->command = cpu_to_le16(cmd_no);
  998. cmd_ptr->params.verext.version_str_sel =
  999. (u8) (*((u32 *) data_buf));
  1000. memcpy(&cmd_ptr->params, data_buf,
  1001. sizeof(struct host_cmd_ds_version_ext));
  1002. cmd_ptr->size =
  1003. cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
  1004. S_DS_GEN);
  1005. ret = 0;
  1006. break;
  1007. case HostCmd_CMD_802_11_RF_CHANNEL:
  1008. ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action,
  1009. data_buf);
  1010. break;
  1011. case HostCmd_CMD_FUNC_INIT:
  1012. if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
  1013. priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  1014. cmd_ptr->command = cpu_to_le16(cmd_no);
  1015. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  1016. break;
  1017. case HostCmd_CMD_FUNC_SHUTDOWN:
  1018. priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
  1019. cmd_ptr->command = cpu_to_le16(cmd_no);
  1020. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  1021. break;
  1022. case HostCmd_CMD_11N_ADDBA_REQ:
  1023. ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
  1024. break;
  1025. case HostCmd_CMD_11N_DELBA:
  1026. ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
  1027. break;
  1028. case HostCmd_CMD_11N_ADDBA_RSP:
  1029. ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
  1030. break;
  1031. case HostCmd_CMD_802_11_KEY_MATERIAL:
  1032. ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
  1033. cmd_action, cmd_oid,
  1034. data_buf);
  1035. break;
  1036. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  1037. ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
  1038. cmd_action);
  1039. break;
  1040. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  1041. ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
  1042. data_buf);
  1043. break;
  1044. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  1045. ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
  1046. data_buf);
  1047. break;
  1048. case HostCmd_CMD_11N_CFG:
  1049. ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action, data_buf);
  1050. break;
  1051. case HostCmd_CMD_WMM_GET_STATUS:
  1052. dev_dbg(priv->adapter->dev,
  1053. "cmd: WMM: WMM_GET_STATUS cmd sent\n");
  1054. cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
  1055. cmd_ptr->size =
  1056. cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
  1057. S_DS_GEN);
  1058. ret = 0;
  1059. break;
  1060. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  1061. ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
  1062. data_buf);
  1063. break;
  1064. case HostCmd_CMD_MAC_REG_ACCESS:
  1065. case HostCmd_CMD_BBP_REG_ACCESS:
  1066. case HostCmd_CMD_RF_REG_ACCESS:
  1067. case HostCmd_CMD_PMIC_REG_ACCESS:
  1068. case HostCmd_CMD_CAU_REG_ACCESS:
  1069. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  1070. ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
  1071. break;
  1072. case HostCmd_CMD_SET_BSS_MODE:
  1073. cmd_ptr->command = cpu_to_le16(cmd_no);
  1074. if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
  1075. cmd_ptr->params.bss_mode.con_type =
  1076. CONNECTION_TYPE_ADHOC;
  1077. else if (priv->bss_mode == NL80211_IFTYPE_STATION)
  1078. cmd_ptr->params.bss_mode.con_type =
  1079. CONNECTION_TYPE_INFRA;
  1080. cmd_ptr->size = cpu_to_le16(sizeof(struct
  1081. host_cmd_ds_set_bss_mode) + S_DS_GEN);
  1082. ret = 0;
  1083. break;
  1084. case HostCmd_CMD_PCIE_DESC_DETAILS:
  1085. ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
  1086. break;
  1087. case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
  1088. ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
  1089. break;
  1090. default:
  1091. dev_err(priv->adapter->dev,
  1092. "PREP_CMD: unknown cmd- %#x\n", cmd_no);
  1093. ret = -1;
  1094. break;
  1095. }
  1096. return ret;
  1097. }
  1098. /*
  1099. * This function issues commands to initialize firmware.
  1100. *
  1101. * This is called after firmware download to bring the card to
  1102. * working state.
  1103. *
  1104. * The following commands are issued sequentially -
  1105. * - Set PCI-Express host buffer configuration (PCIE only)
  1106. * - Function init (for first interface only)
  1107. * - Read MAC address (for first interface only)
  1108. * - Reconfigure Tx buffer size (for first interface only)
  1109. * - Enable auto deep sleep (for first interface only)
  1110. * - Get Tx rate
  1111. * - Get Tx power
  1112. * - Set IBSS coalescing status
  1113. * - Set AMSDU aggregation control
  1114. * - Set 11d control
  1115. * - Set MAC control (this must be the last command to initialize firmware)
  1116. */
  1117. int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
  1118. {
  1119. int ret;
  1120. u16 enable = true;
  1121. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  1122. struct mwifiex_ds_auto_ds auto_ds;
  1123. enum state_11d_t state_11d;
  1124. struct mwifiex_ds_11n_tx_cfg tx_cfg;
  1125. if (first_sta) {
  1126. if (priv->adapter->iface_type == MWIFIEX_PCIE) {
  1127. ret = mwifiex_send_cmd_async(priv,
  1128. HostCmd_CMD_PCIE_DESC_DETAILS,
  1129. HostCmd_ACT_GEN_SET, 0, NULL);
  1130. if (ret)
  1131. return -1;
  1132. }
  1133. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
  1134. HostCmd_ACT_GEN_SET, 0, NULL);
  1135. if (ret)
  1136. return -1;
  1137. /* Read MAC address from HW */
  1138. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
  1139. HostCmd_ACT_GEN_GET, 0, NULL);
  1140. if (ret)
  1141. return -1;
  1142. /* Reconfigure tx buf size */
  1143. ret = mwifiex_send_cmd_async(priv,
  1144. HostCmd_CMD_RECONFIGURE_TX_BUFF,
  1145. HostCmd_ACT_GEN_SET, 0,
  1146. &priv->adapter->tx_buf_size);
  1147. if (ret)
  1148. return -1;
  1149. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1150. /* Enable IEEE PS by default */
  1151. priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1152. ret = mwifiex_send_cmd_async(
  1153. priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1154. EN_AUTO_PS, BITMAP_STA_PS, NULL);
  1155. if (ret)
  1156. return -1;
  1157. }
  1158. }
  1159. /* get tx rate */
  1160. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
  1161. HostCmd_ACT_GEN_GET, 0, NULL);
  1162. if (ret)
  1163. return -1;
  1164. priv->data_rate = 0;
  1165. /* get tx power */
  1166. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TXPWR_CFG,
  1167. HostCmd_ACT_GEN_GET, 0, NULL);
  1168. if (ret)
  1169. return -1;
  1170. if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
  1171. /* set ibss coalescing_status */
  1172. ret = mwifiex_send_cmd_async(
  1173. priv, HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1174. HostCmd_ACT_GEN_SET, 0, &enable);
  1175. if (ret)
  1176. return -1;
  1177. }
  1178. memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
  1179. amsdu_aggr_ctrl.enable = true;
  1180. /* Send request to firmware */
  1181. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
  1182. HostCmd_ACT_GEN_SET, 0,
  1183. &amsdu_aggr_ctrl);
  1184. if (ret)
  1185. return -1;
  1186. /* MAC Control must be the last command in init_fw */
  1187. /* set MAC Control */
  1188. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  1189. HostCmd_ACT_GEN_SET, 0,
  1190. &priv->curr_pkt_filter);
  1191. if (ret)
  1192. return -1;
  1193. if (first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
  1194. priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1195. /* Enable auto deep sleep */
  1196. auto_ds.auto_ds = DEEP_SLEEP_ON;
  1197. auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  1198. ret = mwifiex_send_cmd_async(priv,
  1199. HostCmd_CMD_802_11_PS_MODE_ENH,
  1200. EN_AUTO_PS, BITMAP_AUTO_DS,
  1201. &auto_ds);
  1202. if (ret)
  1203. return -1;
  1204. }
  1205. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1206. /* Send cmd to FW to enable/disable 11D function */
  1207. state_11d = ENABLE_11D;
  1208. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1209. HostCmd_ACT_GEN_SET, DOT11D_I,
  1210. &state_11d);
  1211. if (ret)
  1212. dev_err(priv->adapter->dev,
  1213. "11D: failed to enable 11D\n");
  1214. }
  1215. /* Send cmd to FW to configure 11n specific configuration
  1216. * (Short GI, Channel BW, Green field support etc.) for transmit
  1217. */
  1218. tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
  1219. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
  1220. HostCmd_ACT_GEN_SET, 0, &tx_cfg);
  1221. /* set last_init_cmd */
  1222. priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
  1223. ret = -EINPROGRESS;
  1224. return ret;
  1225. }