sta_cmd.c 47 KB

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