sta_cmd.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070
  1. /*
  2. * Marvell Wireless LAN device driver: station command handling
  3. *
  4. * Copyright (C) 2011-2014, 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. if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
  172. for (i = 0;
  173. i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap);
  174. i++)
  175. rate_scope->vht_mcs_rate_bitmap[i] =
  176. cpu_to_le16(pbitmap_rates[10 + i]);
  177. }
  178. } else {
  179. rate_scope->hr_dsss_rate_bitmap =
  180. cpu_to_le16(priv->bitmap_rates[0]);
  181. rate_scope->ofdm_rate_bitmap =
  182. cpu_to_le16(priv->bitmap_rates[1]);
  183. for (i = 0;
  184. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  185. i++)
  186. rate_scope->ht_mcs_rate_bitmap[i] =
  187. cpu_to_le16(priv->bitmap_rates[2 + i]);
  188. if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
  189. for (i = 0;
  190. i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap);
  191. i++)
  192. rate_scope->vht_mcs_rate_bitmap[i] =
  193. cpu_to_le16(priv->bitmap_rates[10 + i]);
  194. }
  195. }
  196. rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
  197. sizeof(struct mwifiex_rate_scope));
  198. rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
  199. rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
  200. rate_drop->rate_drop_mode = 0;
  201. cmd->size =
  202. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
  203. sizeof(struct mwifiex_rate_scope) +
  204. sizeof(struct mwifiex_rate_drop_pattern));
  205. return 0;
  206. }
  207. /*
  208. * This function prepares command to set/get Tx power configuration.
  209. *
  210. * Preparation includes -
  211. * - Setting command ID, action and proper size
  212. * - Setting Tx power mode, power group TLV
  213. * (as required)
  214. * - Ensuring correct endian-ness
  215. */
  216. static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
  217. u16 cmd_action,
  218. struct host_cmd_ds_txpwr_cfg *txp)
  219. {
  220. struct mwifiex_types_power_group *pg_tlv;
  221. struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
  222. cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
  223. cmd->size =
  224. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
  225. switch (cmd_action) {
  226. case HostCmd_ACT_GEN_SET:
  227. if (txp->mode) {
  228. pg_tlv = (struct mwifiex_types_power_group
  229. *) ((unsigned long) txp +
  230. sizeof(struct host_cmd_ds_txpwr_cfg));
  231. memmove(cmd_txp_cfg, txp,
  232. sizeof(struct host_cmd_ds_txpwr_cfg) +
  233. sizeof(struct mwifiex_types_power_group) +
  234. le16_to_cpu(pg_tlv->length));
  235. pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
  236. cmd_txp_cfg +
  237. sizeof(struct host_cmd_ds_txpwr_cfg));
  238. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
  239. sizeof(struct mwifiex_types_power_group) +
  240. le16_to_cpu(pg_tlv->length));
  241. } else {
  242. memmove(cmd_txp_cfg, txp, sizeof(*txp));
  243. }
  244. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  245. break;
  246. case HostCmd_ACT_GEN_GET:
  247. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  248. break;
  249. }
  250. return 0;
  251. }
  252. /*
  253. * This function prepares command to get RF Tx power.
  254. */
  255. static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
  256. struct host_cmd_ds_command *cmd,
  257. u16 cmd_action, void *data_buf)
  258. {
  259. struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
  260. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
  261. + S_DS_GEN);
  262. cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
  263. txp->action = cpu_to_le16(cmd_action);
  264. return 0;
  265. }
  266. /*
  267. * This function prepares command to set rf antenna.
  268. */
  269. static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv,
  270. struct host_cmd_ds_command *cmd,
  271. u16 cmd_action,
  272. struct mwifiex_ds_ant_cfg *ant_cfg)
  273. {
  274. struct host_cmd_ds_rf_ant_mimo *ant_mimo = &cmd->params.ant_mimo;
  275. struct host_cmd_ds_rf_ant_siso *ant_siso = &cmd->params.ant_siso;
  276. cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA);
  277. if (cmd_action != HostCmd_ACT_GEN_SET)
  278. return 0;
  279. if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
  280. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_mimo) +
  281. S_DS_GEN);
  282. ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX);
  283. ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
  284. ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
  285. ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->rx_ant);
  286. } else {
  287. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_siso) +
  288. S_DS_GEN);
  289. ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
  290. ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
  291. }
  292. return 0;
  293. }
  294. /*
  295. * This function prepares command to set Host Sleep configuration.
  296. *
  297. * Preparation includes -
  298. * - Setting command ID and proper size
  299. * - Setting Host Sleep action, conditions, ARP filters
  300. * (as required)
  301. * - Ensuring correct endian-ness
  302. */
  303. static int
  304. mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
  305. struct host_cmd_ds_command *cmd,
  306. u16 cmd_action,
  307. struct mwifiex_hs_config_param *hscfg_param)
  308. {
  309. struct mwifiex_adapter *adapter = priv->adapter;
  310. struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
  311. bool hs_activate = false;
  312. if (!hscfg_param)
  313. /* New Activate command */
  314. hs_activate = true;
  315. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
  316. if (!hs_activate &&
  317. (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) &&
  318. ((adapter->arp_filter_size > 0) &&
  319. (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
  320. dev_dbg(adapter->dev,
  321. "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
  322. adapter->arp_filter_size);
  323. memcpy(((u8 *) hs_cfg) +
  324. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
  325. adapter->arp_filter, adapter->arp_filter_size);
  326. cmd->size = cpu_to_le16
  327. (adapter->arp_filter_size +
  328. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
  329. + S_DS_GEN);
  330. } else {
  331. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
  332. host_cmd_ds_802_11_hs_cfg_enh));
  333. }
  334. if (hs_activate) {
  335. hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
  336. hs_cfg->params.hs_activate.resp_ctrl = cpu_to_le16(RESP_NEEDED);
  337. } else {
  338. hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
  339. hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
  340. hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
  341. hs_cfg->params.hs_config.gap = hscfg_param->gap;
  342. dev_dbg(adapter->dev,
  343. "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
  344. hs_cfg->params.hs_config.conditions,
  345. hs_cfg->params.hs_config.gpio,
  346. hs_cfg->params.hs_config.gap);
  347. }
  348. return 0;
  349. }
  350. /*
  351. * This function prepares command to set/get MAC address.
  352. *
  353. * Preparation includes -
  354. * - Setting command ID, action and proper size
  355. * - Setting MAC address (for SET only)
  356. * - Ensuring correct endian-ness
  357. */
  358. static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
  359. struct host_cmd_ds_command *cmd,
  360. u16 cmd_action)
  361. {
  362. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
  363. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
  364. S_DS_GEN);
  365. cmd->result = 0;
  366. cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
  367. if (cmd_action == HostCmd_ACT_GEN_SET)
  368. memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
  369. ETH_ALEN);
  370. return 0;
  371. }
  372. /*
  373. * This function prepares command to set MAC multicast address.
  374. *
  375. * Preparation includes -
  376. * - Setting command ID, action and proper size
  377. * - Setting MAC multicast address
  378. * - Ensuring correct endian-ness
  379. */
  380. static int
  381. mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
  382. u16 cmd_action,
  383. struct mwifiex_multicast_list *mcast_list)
  384. {
  385. struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
  386. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
  387. S_DS_GEN);
  388. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
  389. mcast_addr->action = cpu_to_le16(cmd_action);
  390. mcast_addr->num_of_adrs =
  391. cpu_to_le16((u16) mcast_list->num_multicast_addr);
  392. memcpy(mcast_addr->mac_list, mcast_list->mac_list,
  393. mcast_list->num_multicast_addr * ETH_ALEN);
  394. return 0;
  395. }
  396. /*
  397. * This function prepares command to deauthenticate.
  398. *
  399. * Preparation includes -
  400. * - Setting command ID and proper size
  401. * - Setting AP MAC address and reason code
  402. * - Ensuring correct endian-ness
  403. */
  404. static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
  405. struct host_cmd_ds_command *cmd,
  406. u8 *mac)
  407. {
  408. struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
  409. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
  410. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
  411. + S_DS_GEN);
  412. /* Set AP MAC address */
  413. memcpy(deauth->mac_addr, mac, ETH_ALEN);
  414. dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
  415. deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
  416. return 0;
  417. }
  418. /*
  419. * This function prepares command to stop Ad-Hoc network.
  420. *
  421. * Preparation includes -
  422. * - Setting command ID and proper size
  423. * - Ensuring correct endian-ness
  424. */
  425. static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
  426. {
  427. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
  428. cmd->size = cpu_to_le16(S_DS_GEN);
  429. return 0;
  430. }
  431. /*
  432. * This function sets WEP key(s) to key parameter TLV(s).
  433. *
  434. * Multi-key parameter TLVs are supported, so we can send multiple
  435. * WEP keys in a single buffer.
  436. */
  437. static int
  438. mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
  439. struct mwifiex_ie_type_key_param_set *key_param_set,
  440. u16 *key_param_len)
  441. {
  442. int cur_key_param_len;
  443. u8 i;
  444. /* Multi-key_param_set TLV is supported */
  445. for (i = 0; i < NUM_WEP_KEYS; i++) {
  446. if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
  447. (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
  448. key_param_set->type =
  449. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  450. /* Key_param_set WEP fixed length */
  451. #define KEYPARAMSET_WEP_FIXED_LEN 8
  452. key_param_set->length = cpu_to_le16((u16)
  453. (priv->wep_key[i].
  454. key_length +
  455. KEYPARAMSET_WEP_FIXED_LEN));
  456. key_param_set->key_type_id =
  457. cpu_to_le16(KEY_TYPE_ID_WEP);
  458. key_param_set->key_info =
  459. cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
  460. KEY_MCAST);
  461. key_param_set->key_len =
  462. cpu_to_le16(priv->wep_key[i].key_length);
  463. /* Set WEP key index */
  464. key_param_set->key[0] = i;
  465. /* Set default Tx key flag */
  466. if (i ==
  467. (priv->
  468. wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
  469. key_param_set->key[1] = 1;
  470. else
  471. key_param_set->key[1] = 0;
  472. memmove(&key_param_set->key[2],
  473. priv->wep_key[i].key_material,
  474. priv->wep_key[i].key_length);
  475. cur_key_param_len = priv->wep_key[i].key_length +
  476. KEYPARAMSET_WEP_FIXED_LEN +
  477. sizeof(struct mwifiex_ie_types_header);
  478. *key_param_len += (u16) cur_key_param_len;
  479. key_param_set =
  480. (struct mwifiex_ie_type_key_param_set *)
  481. ((u8 *)key_param_set +
  482. cur_key_param_len);
  483. } else if (!priv->wep_key[i].key_length) {
  484. continue;
  485. } else {
  486. dev_err(priv->adapter->dev,
  487. "key%d Length = %d is incorrect\n",
  488. (i + 1), priv->wep_key[i].key_length);
  489. return -1;
  490. }
  491. }
  492. return 0;
  493. }
  494. /* This function populates key material v2 command
  495. * to set network key for AES & CMAC AES.
  496. */
  497. static int mwifiex_set_aes_key_v2(struct mwifiex_private *priv,
  498. struct host_cmd_ds_command *cmd,
  499. struct mwifiex_ds_encrypt_key *enc_key,
  500. struct host_cmd_ds_802_11_key_material_v2 *km)
  501. {
  502. struct mwifiex_adapter *adapter = priv->adapter;
  503. u16 size, len = KEY_PARAMS_FIXED_LEN;
  504. if (enc_key->is_igtk_key) {
  505. dev_dbg(adapter->dev, "%s: Set CMAC AES Key\n", __func__);
  506. if (enc_key->is_rx_seq_valid)
  507. memcpy(km->key_param_set.key_params.cmac_aes.ipn,
  508. enc_key->pn, enc_key->pn_len);
  509. km->key_param_set.key_info &= cpu_to_le16(~KEY_MCAST);
  510. km->key_param_set.key_info |= cpu_to_le16(KEY_IGTK);
  511. km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC;
  512. km->key_param_set.key_params.cmac_aes.key_len =
  513. cpu_to_le16(enc_key->key_len);
  514. memcpy(km->key_param_set.key_params.cmac_aes.key,
  515. enc_key->key_material, enc_key->key_len);
  516. len += sizeof(struct mwifiex_cmac_aes_param);
  517. } else {
  518. dev_dbg(adapter->dev, "%s: Set AES Key\n", __func__);
  519. if (enc_key->is_rx_seq_valid)
  520. memcpy(km->key_param_set.key_params.aes.pn,
  521. enc_key->pn, enc_key->pn_len);
  522. km->key_param_set.key_type = KEY_TYPE_ID_AES;
  523. km->key_param_set.key_params.aes.key_len =
  524. cpu_to_le16(enc_key->key_len);
  525. memcpy(km->key_param_set.key_params.aes.key,
  526. enc_key->key_material, enc_key->key_len);
  527. len += sizeof(struct mwifiex_aes_param);
  528. }
  529. km->key_param_set.len = cpu_to_le16(len);
  530. size = len + sizeof(struct mwifiex_ie_types_header) +
  531. sizeof(km->action) + S_DS_GEN;
  532. cmd->size = cpu_to_le16(size);
  533. return 0;
  534. }
  535. /* This function prepares command to set/get/reset network key(s).
  536. * This function prepares key material command for V2 format.
  537. * Preparation includes -
  538. * - Setting command ID, action and proper size
  539. * - Setting WEP keys, WAPI keys or WPA keys along with required
  540. * encryption (TKIP, AES) (as required)
  541. * - Ensuring correct endian-ness
  542. */
  543. static int
  544. mwifiex_cmd_802_11_key_material_v2(struct mwifiex_private *priv,
  545. struct host_cmd_ds_command *cmd,
  546. u16 cmd_action, u32 cmd_oid,
  547. struct mwifiex_ds_encrypt_key *enc_key)
  548. {
  549. struct mwifiex_adapter *adapter = priv->adapter;
  550. u8 *mac = enc_key->mac_addr;
  551. u16 key_info, len = KEY_PARAMS_FIXED_LEN;
  552. struct host_cmd_ds_802_11_key_material_v2 *km =
  553. &cmd->params.key_material_v2;
  554. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
  555. km->action = cpu_to_le16(cmd_action);
  556. if (cmd_action == HostCmd_ACT_GEN_GET) {
  557. dev_dbg(adapter->dev, "%s: Get key\n", __func__);
  558. km->key_param_set.key_idx =
  559. enc_key->key_index & KEY_INDEX_MASK;
  560. km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
  561. km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
  562. memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
  563. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  564. key_info = KEY_UNICAST;
  565. else
  566. key_info = KEY_MCAST;
  567. if (enc_key->is_igtk_key)
  568. key_info |= KEY_IGTK;
  569. km->key_param_set.key_info = cpu_to_le16(key_info);
  570. cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
  571. S_DS_GEN + KEY_PARAMS_FIXED_LEN +
  572. sizeof(km->action));
  573. return 0;
  574. }
  575. memset(&km->key_param_set, 0,
  576. sizeof(struct mwifiex_ie_type_key_param_set_v2));
  577. if (enc_key->key_disable) {
  578. dev_dbg(adapter->dev, "%s: Remove key\n", __func__);
  579. km->action = cpu_to_le16(HostCmd_ACT_GEN_REMOVE);
  580. km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
  581. km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
  582. km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
  583. key_info = KEY_MCAST | KEY_UNICAST;
  584. km->key_param_set.key_info = cpu_to_le16(key_info);
  585. memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
  586. cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
  587. S_DS_GEN + KEY_PARAMS_FIXED_LEN +
  588. sizeof(km->action));
  589. return 0;
  590. }
  591. km->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  592. km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
  593. km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
  594. key_info = KEY_ENABLED;
  595. memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
  596. if (enc_key->key_len <= WLAN_KEY_LEN_WEP104) {
  597. dev_dbg(adapter->dev, "%s: Set WEP Key\n", __func__);
  598. len += sizeof(struct mwifiex_wep_param);
  599. km->key_param_set.len = cpu_to_le16(len);
  600. km->key_param_set.key_type = KEY_TYPE_ID_WEP;
  601. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  602. key_info |= KEY_MCAST | KEY_UNICAST;
  603. } else {
  604. if (enc_key->is_current_wep_key) {
  605. key_info |= KEY_MCAST | KEY_UNICAST;
  606. if (km->key_param_set.key_idx ==
  607. (priv->wep_key_curr_index & KEY_INDEX_MASK))
  608. key_info |= KEY_DEFAULT;
  609. } else {
  610. if (mac) {
  611. if (is_broadcast_ether_addr(mac))
  612. key_info |= KEY_MCAST;
  613. else
  614. key_info |= KEY_UNICAST |
  615. KEY_DEFAULT;
  616. } else {
  617. key_info |= KEY_MCAST;
  618. }
  619. }
  620. }
  621. km->key_param_set.key_info = cpu_to_le16(key_info);
  622. km->key_param_set.key_params.wep.key_len =
  623. cpu_to_le16(enc_key->key_len);
  624. memcpy(km->key_param_set.key_params.wep.key,
  625. enc_key->key_material, enc_key->key_len);
  626. cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
  627. len + sizeof(km->action) + S_DS_GEN);
  628. return 0;
  629. }
  630. if (is_broadcast_ether_addr(mac))
  631. key_info |= KEY_MCAST | KEY_RX_KEY;
  632. else
  633. key_info |= KEY_UNICAST | KEY_TX_KEY | KEY_RX_KEY;
  634. if (enc_key->is_wapi_key) {
  635. dev_dbg(adapter->dev, "%s: Set WAPI Key\n", __func__);
  636. km->key_param_set.key_type = KEY_TYPE_ID_WAPI;
  637. memcpy(km->key_param_set.key_params.wapi.pn, enc_key->pn,
  638. PN_LEN);
  639. km->key_param_set.key_params.wapi.key_len =
  640. cpu_to_le16(enc_key->key_len);
  641. memcpy(km->key_param_set.key_params.wapi.key,
  642. enc_key->key_material, enc_key->key_len);
  643. if (is_broadcast_ether_addr(mac))
  644. priv->sec_info.wapi_key_on = true;
  645. if (!priv->sec_info.wapi_key_on)
  646. key_info |= KEY_DEFAULT;
  647. km->key_param_set.key_info = cpu_to_le16(key_info);
  648. len += sizeof(struct mwifiex_wapi_param);
  649. km->key_param_set.len = cpu_to_le16(len);
  650. cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
  651. len + sizeof(km->action) + S_DS_GEN);
  652. return 0;
  653. }
  654. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  655. key_info |= KEY_DEFAULT;
  656. /* Enable unicast bit for WPA-NONE/ADHOC_AES */
  657. if (!priv->sec_info.wpa2_enabled &&
  658. !is_broadcast_ether_addr(mac))
  659. key_info |= KEY_UNICAST;
  660. } else {
  661. /* Enable default key for WPA/WPA2 */
  662. if (!priv->wpa_is_gtk_set)
  663. key_info |= KEY_DEFAULT;
  664. }
  665. km->key_param_set.key_info = cpu_to_le16(key_info);
  666. if (enc_key->key_len == WLAN_KEY_LEN_CCMP)
  667. return mwifiex_set_aes_key_v2(priv, cmd, enc_key, km);
  668. if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
  669. dev_dbg(adapter->dev, "%s: Set TKIP Key\n", __func__);
  670. if (enc_key->is_rx_seq_valid)
  671. memcpy(km->key_param_set.key_params.tkip.pn,
  672. enc_key->pn, enc_key->pn_len);
  673. km->key_param_set.key_type = KEY_TYPE_ID_TKIP;
  674. km->key_param_set.key_params.tkip.key_len =
  675. cpu_to_le16(enc_key->key_len);
  676. memcpy(km->key_param_set.key_params.tkip.key,
  677. enc_key->key_material, enc_key->key_len);
  678. len += sizeof(struct mwifiex_tkip_param);
  679. km->key_param_set.len = cpu_to_le16(len);
  680. cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
  681. len + sizeof(km->action) + S_DS_GEN);
  682. }
  683. return 0;
  684. }
  685. /*
  686. * This function prepares command to set/get/reset network key(s).
  687. * This function prepares key material command for V1 format.
  688. *
  689. * Preparation includes -
  690. * - Setting command ID, action and proper size
  691. * - Setting WEP keys, WAPI keys or WPA keys along with required
  692. * encryption (TKIP, AES) (as required)
  693. * - Ensuring correct endian-ness
  694. */
  695. static int
  696. mwifiex_cmd_802_11_key_material_v1(struct mwifiex_private *priv,
  697. struct host_cmd_ds_command *cmd,
  698. u16 cmd_action, u32 cmd_oid,
  699. struct mwifiex_ds_encrypt_key *enc_key)
  700. {
  701. struct host_cmd_ds_802_11_key_material *key_material =
  702. &cmd->params.key_material;
  703. struct host_cmd_tlv_mac_addr *tlv_mac;
  704. u16 key_param_len = 0, cmd_size;
  705. int ret = 0;
  706. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
  707. key_material->action = cpu_to_le16(cmd_action);
  708. if (cmd_action == HostCmd_ACT_GEN_GET) {
  709. cmd->size =
  710. cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
  711. return ret;
  712. }
  713. if (!enc_key) {
  714. memset(&key_material->key_param_set, 0,
  715. (NUM_WEP_KEYS *
  716. sizeof(struct mwifiex_ie_type_key_param_set)));
  717. ret = mwifiex_set_keyparamset_wep(priv,
  718. &key_material->key_param_set,
  719. &key_param_len);
  720. cmd->size = cpu_to_le16(key_param_len +
  721. sizeof(key_material->action) + S_DS_GEN);
  722. return ret;
  723. } else
  724. memset(&key_material->key_param_set, 0,
  725. sizeof(struct mwifiex_ie_type_key_param_set));
  726. if (enc_key->is_wapi_key) {
  727. dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
  728. key_material->key_param_set.key_type_id =
  729. cpu_to_le16(KEY_TYPE_ID_WAPI);
  730. if (cmd_oid == KEY_INFO_ENABLED)
  731. key_material->key_param_set.key_info =
  732. cpu_to_le16(KEY_ENABLED);
  733. else
  734. key_material->key_param_set.key_info =
  735. cpu_to_le16(!KEY_ENABLED);
  736. key_material->key_param_set.key[0] = enc_key->key_index;
  737. if (!priv->sec_info.wapi_key_on)
  738. key_material->key_param_set.key[1] = 1;
  739. else
  740. /* set 0 when re-key */
  741. key_material->key_param_set.key[1] = 0;
  742. if (!is_broadcast_ether_addr(enc_key->mac_addr)) {
  743. /* WAPI pairwise key: unicast */
  744. key_material->key_param_set.key_info |=
  745. cpu_to_le16(KEY_UNICAST);
  746. } else { /* WAPI group key: multicast */
  747. key_material->key_param_set.key_info |=
  748. cpu_to_le16(KEY_MCAST);
  749. priv->sec_info.wapi_key_on = true;
  750. }
  751. key_material->key_param_set.type =
  752. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  753. key_material->key_param_set.key_len =
  754. cpu_to_le16(WAPI_KEY_LEN);
  755. memcpy(&key_material->key_param_set.key[2],
  756. enc_key->key_material, enc_key->key_len);
  757. memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
  758. enc_key->pn, PN_LEN);
  759. key_material->key_param_set.length =
  760. cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
  761. key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
  762. sizeof(struct mwifiex_ie_types_header);
  763. cmd->size = cpu_to_le16(sizeof(key_material->action)
  764. + S_DS_GEN + key_param_len);
  765. return ret;
  766. }
  767. if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
  768. if (enc_key->is_igtk_key) {
  769. dev_dbg(priv->adapter->dev, "cmd: CMAC_AES\n");
  770. key_material->key_param_set.key_type_id =
  771. cpu_to_le16(KEY_TYPE_ID_AES_CMAC);
  772. if (cmd_oid == KEY_INFO_ENABLED)
  773. key_material->key_param_set.key_info =
  774. cpu_to_le16(KEY_ENABLED);
  775. else
  776. key_material->key_param_set.key_info =
  777. cpu_to_le16(!KEY_ENABLED);
  778. key_material->key_param_set.key_info |=
  779. cpu_to_le16(KEY_IGTK);
  780. } else {
  781. dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
  782. key_material->key_param_set.key_type_id =
  783. cpu_to_le16(KEY_TYPE_ID_AES);
  784. if (cmd_oid == KEY_INFO_ENABLED)
  785. key_material->key_param_set.key_info =
  786. cpu_to_le16(KEY_ENABLED);
  787. else
  788. key_material->key_param_set.key_info =
  789. cpu_to_le16(!KEY_ENABLED);
  790. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  791. /* AES pairwise key: unicast */
  792. key_material->key_param_set.key_info |=
  793. cpu_to_le16(KEY_UNICAST);
  794. else /* AES group key: multicast */
  795. key_material->key_param_set.key_info |=
  796. cpu_to_le16(KEY_MCAST);
  797. }
  798. } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
  799. dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
  800. key_material->key_param_set.key_type_id =
  801. cpu_to_le16(KEY_TYPE_ID_TKIP);
  802. key_material->key_param_set.key_info =
  803. cpu_to_le16(KEY_ENABLED);
  804. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  805. /* TKIP pairwise key: unicast */
  806. key_material->key_param_set.key_info |=
  807. cpu_to_le16(KEY_UNICAST);
  808. else /* TKIP group key: multicast */
  809. key_material->key_param_set.key_info |=
  810. cpu_to_le16(KEY_MCAST);
  811. }
  812. if (key_material->key_param_set.key_type_id) {
  813. key_material->key_param_set.type =
  814. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  815. key_material->key_param_set.key_len =
  816. cpu_to_le16((u16) enc_key->key_len);
  817. memcpy(key_material->key_param_set.key, enc_key->key_material,
  818. enc_key->key_len);
  819. key_material->key_param_set.length =
  820. cpu_to_le16((u16) enc_key->key_len +
  821. KEYPARAMSET_FIXED_LEN);
  822. key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
  823. + sizeof(struct mwifiex_ie_types_header);
  824. if (le16_to_cpu(key_material->key_param_set.key_type_id) ==
  825. KEY_TYPE_ID_AES_CMAC) {
  826. struct mwifiex_cmac_param *param =
  827. (void *)key_material->key_param_set.key;
  828. memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN);
  829. memcpy(param->key, enc_key->key_material,
  830. WLAN_KEY_LEN_AES_CMAC);
  831. key_param_len = sizeof(struct mwifiex_cmac_param);
  832. key_material->key_param_set.key_len =
  833. cpu_to_le16(key_param_len);
  834. key_param_len += KEYPARAMSET_FIXED_LEN;
  835. key_material->key_param_set.length =
  836. cpu_to_le16(key_param_len);
  837. key_param_len += sizeof(struct mwifiex_ie_types_header);
  838. }
  839. cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
  840. + key_param_len);
  841. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  842. tlv_mac = (void *)((u8 *)&key_material->key_param_set +
  843. key_param_len);
  844. tlv_mac->header.type =
  845. cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
  846. tlv_mac->header.len = cpu_to_le16(ETH_ALEN);
  847. memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
  848. cmd_size = key_param_len + S_DS_GEN +
  849. sizeof(key_material->action) +
  850. sizeof(struct host_cmd_tlv_mac_addr);
  851. } else {
  852. cmd_size = key_param_len + S_DS_GEN +
  853. sizeof(key_material->action);
  854. }
  855. cmd->size = cpu_to_le16(cmd_size);
  856. }
  857. return ret;
  858. }
  859. /* Wrapper function for setting network key depending upon FW KEY API version */
  860. static int
  861. mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
  862. struct host_cmd_ds_command *cmd,
  863. u16 cmd_action, u32 cmd_oid,
  864. struct mwifiex_ds_encrypt_key *enc_key)
  865. {
  866. if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
  867. return mwifiex_cmd_802_11_key_material_v2(priv, cmd,
  868. cmd_action, cmd_oid,
  869. enc_key);
  870. else
  871. return mwifiex_cmd_802_11_key_material_v1(priv, cmd,
  872. cmd_action, cmd_oid,
  873. enc_key);
  874. }
  875. /*
  876. * This function prepares command to set/get 11d domain information.
  877. *
  878. * Preparation includes -
  879. * - Setting command ID, action and proper size
  880. * - Setting domain information fields (for SET only)
  881. * - Ensuring correct endian-ness
  882. */
  883. static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
  884. struct host_cmd_ds_command *cmd,
  885. u16 cmd_action)
  886. {
  887. struct mwifiex_adapter *adapter = priv->adapter;
  888. struct host_cmd_ds_802_11d_domain_info *domain_info =
  889. &cmd->params.domain_info;
  890. struct mwifiex_ietypes_domain_param_set *domain =
  891. &domain_info->domain;
  892. u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
  893. dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
  894. cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
  895. domain_info->action = cpu_to_le16(cmd_action);
  896. if (cmd_action == HostCmd_ACT_GEN_GET) {
  897. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  898. return 0;
  899. }
  900. /* Set domain info fields */
  901. domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
  902. memcpy(domain->country_code, adapter->domain_reg.country_code,
  903. sizeof(domain->country_code));
  904. domain->header.len =
  905. cpu_to_le16((no_of_triplet *
  906. sizeof(struct ieee80211_country_ie_triplet))
  907. + sizeof(domain->country_code));
  908. if (no_of_triplet) {
  909. memcpy(domain->triplet, adapter->domain_reg.triplet,
  910. no_of_triplet * sizeof(struct
  911. ieee80211_country_ie_triplet));
  912. cmd->size = cpu_to_le16(sizeof(domain_info->action) +
  913. le16_to_cpu(domain->header.len) +
  914. sizeof(struct mwifiex_ie_types_header)
  915. + S_DS_GEN);
  916. } else {
  917. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  918. }
  919. return 0;
  920. }
  921. /*
  922. * This function prepares command to set/get IBSS coalescing status.
  923. *
  924. * Preparation includes -
  925. * - Setting command ID, action and proper size
  926. * - Setting status to enable or disable (for SET only)
  927. * - Ensuring correct endian-ness
  928. */
  929. static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
  930. u16 cmd_action, u16 *enable)
  931. {
  932. struct host_cmd_ds_802_11_ibss_status *ibss_coal =
  933. &(cmd->params.ibss_coalescing);
  934. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
  935. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
  936. S_DS_GEN);
  937. cmd->result = 0;
  938. ibss_coal->action = cpu_to_le16(cmd_action);
  939. switch (cmd_action) {
  940. case HostCmd_ACT_GEN_SET:
  941. if (enable)
  942. ibss_coal->enable = cpu_to_le16(*enable);
  943. else
  944. ibss_coal->enable = 0;
  945. break;
  946. /* In other case.. Nothing to do */
  947. case HostCmd_ACT_GEN_GET:
  948. default:
  949. break;
  950. }
  951. return 0;
  952. }
  953. /*
  954. * This function prepares command to set/get register value.
  955. *
  956. * Preparation includes -
  957. * - Setting command ID, action and proper size
  958. * - Setting register offset (for both GET and SET) and
  959. * register value (for SET only)
  960. * - Ensuring correct endian-ness
  961. *
  962. * The following type of registers can be accessed with this function -
  963. * - MAC register
  964. * - BBP register
  965. * - RF register
  966. * - PMIC register
  967. * - CAU register
  968. * - EEPROM
  969. */
  970. static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
  971. u16 cmd_action, void *data_buf)
  972. {
  973. struct mwifiex_ds_reg_rw *reg_rw = data_buf;
  974. switch (le16_to_cpu(cmd->command)) {
  975. case HostCmd_CMD_MAC_REG_ACCESS:
  976. {
  977. struct host_cmd_ds_mac_reg_access *mac_reg;
  978. cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
  979. mac_reg = &cmd->params.mac_reg;
  980. mac_reg->action = cpu_to_le16(cmd_action);
  981. mac_reg->offset =
  982. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  983. mac_reg->value = reg_rw->value;
  984. break;
  985. }
  986. case HostCmd_CMD_BBP_REG_ACCESS:
  987. {
  988. struct host_cmd_ds_bbp_reg_access *bbp_reg;
  989. cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
  990. bbp_reg = &cmd->params.bbp_reg;
  991. bbp_reg->action = cpu_to_le16(cmd_action);
  992. bbp_reg->offset =
  993. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  994. bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
  995. break;
  996. }
  997. case HostCmd_CMD_RF_REG_ACCESS:
  998. {
  999. struct host_cmd_ds_rf_reg_access *rf_reg;
  1000. cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
  1001. rf_reg = &cmd->params.rf_reg;
  1002. rf_reg->action = cpu_to_le16(cmd_action);
  1003. rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  1004. rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
  1005. break;
  1006. }
  1007. case HostCmd_CMD_PMIC_REG_ACCESS:
  1008. {
  1009. struct host_cmd_ds_pmic_reg_access *pmic_reg;
  1010. cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
  1011. pmic_reg = &cmd->params.pmic_reg;
  1012. pmic_reg->action = cpu_to_le16(cmd_action);
  1013. pmic_reg->offset =
  1014. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  1015. pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
  1016. break;
  1017. }
  1018. case HostCmd_CMD_CAU_REG_ACCESS:
  1019. {
  1020. struct host_cmd_ds_rf_reg_access *cau_reg;
  1021. cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
  1022. cau_reg = &cmd->params.rf_reg;
  1023. cau_reg->action = cpu_to_le16(cmd_action);
  1024. cau_reg->offset =
  1025. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  1026. cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
  1027. break;
  1028. }
  1029. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  1030. {
  1031. struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
  1032. struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
  1033. &cmd->params.eeprom;
  1034. cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
  1035. cmd_eeprom->action = cpu_to_le16(cmd_action);
  1036. cmd_eeprom->offset = rd_eeprom->offset;
  1037. cmd_eeprom->byte_count = rd_eeprom->byte_count;
  1038. cmd_eeprom->value = 0;
  1039. break;
  1040. }
  1041. default:
  1042. return -1;
  1043. }
  1044. return 0;
  1045. }
  1046. /*
  1047. * This function prepares command to set PCI-Express
  1048. * host buffer configuration
  1049. *
  1050. * Preparation includes -
  1051. * - Setting command ID, action and proper size
  1052. * - Setting host buffer configuration
  1053. * - Ensuring correct endian-ness
  1054. */
  1055. static int
  1056. mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
  1057. struct host_cmd_ds_command *cmd, u16 action)
  1058. {
  1059. struct host_cmd_ds_pcie_details *host_spec =
  1060. &cmd->params.pcie_host_spec;
  1061. struct pcie_service_card *card = priv->adapter->card;
  1062. cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
  1063. cmd->size = cpu_to_le16(sizeof(struct
  1064. host_cmd_ds_pcie_details) + S_DS_GEN);
  1065. cmd->result = 0;
  1066. memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
  1067. if (action != HostCmd_ACT_GEN_SET)
  1068. return 0;
  1069. /* Send the ring base addresses and count to firmware */
  1070. host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
  1071. host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
  1072. host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
  1073. host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
  1074. host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
  1075. host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
  1076. host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
  1077. host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
  1078. host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
  1079. if (card->sleep_cookie_vbase) {
  1080. host_spec->sleep_cookie_addr_lo =
  1081. (u32)(card->sleep_cookie_pbase);
  1082. host_spec->sleep_cookie_addr_hi =
  1083. (u32)(((u64)(card->sleep_cookie_pbase)) >> 32);
  1084. dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
  1085. host_spec->sleep_cookie_addr_lo);
  1086. }
  1087. return 0;
  1088. }
  1089. /*
  1090. * This function prepares command for event subscription, configuration
  1091. * and query. Events can be subscribed or unsubscribed. Current subscribed
  1092. * events can be queried. Also, current subscribed events are reported in
  1093. * every FW response.
  1094. */
  1095. static int
  1096. mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
  1097. struct host_cmd_ds_command *cmd,
  1098. struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
  1099. {
  1100. struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
  1101. struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
  1102. u16 event_bitmap;
  1103. u8 *pos;
  1104. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
  1105. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
  1106. S_DS_GEN);
  1107. subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
  1108. dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
  1109. /*For query requests, no configuration TLV structures are to be added.*/
  1110. if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
  1111. return 0;
  1112. subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
  1113. event_bitmap = subsc_evt_cfg->events;
  1114. dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
  1115. event_bitmap);
  1116. if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
  1117. (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
  1118. (event_bitmap == 0)) {
  1119. dev_dbg(priv->adapter->dev, "Error: No event specified "
  1120. "for bitwise action type\n");
  1121. return -EINVAL;
  1122. }
  1123. /*
  1124. * Append TLV structures for each of the specified events for
  1125. * subscribing or re-configuring. This is not required for
  1126. * bitwise unsubscribing request.
  1127. */
  1128. if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
  1129. return 0;
  1130. pos = ((u8 *)subsc_evt) +
  1131. sizeof(struct host_cmd_ds_802_11_subsc_evt);
  1132. if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
  1133. rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
  1134. rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
  1135. rssi_tlv->header.len =
  1136. cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
  1137. sizeof(struct mwifiex_ie_types_header));
  1138. rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
  1139. rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
  1140. dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
  1141. "RSSI:-%d dBm, Freq:%d\n",
  1142. subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
  1143. subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
  1144. pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
  1145. le16_add_cpu(&cmd->size,
  1146. sizeof(struct mwifiex_ie_types_rssi_threshold));
  1147. }
  1148. if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
  1149. rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
  1150. rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
  1151. rssi_tlv->header.len =
  1152. cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
  1153. sizeof(struct mwifiex_ie_types_header));
  1154. rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
  1155. rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
  1156. dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
  1157. "RSSI:-%d dBm, Freq:%d\n",
  1158. subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
  1159. subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
  1160. pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
  1161. le16_add_cpu(&cmd->size,
  1162. sizeof(struct mwifiex_ie_types_rssi_threshold));
  1163. }
  1164. return 0;
  1165. }
  1166. static int
  1167. mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv,
  1168. struct mwifiex_mef_entry *mef_entry,
  1169. u8 **buffer)
  1170. {
  1171. struct mwifiex_mef_filter *filter = mef_entry->filter;
  1172. int i, byte_len;
  1173. u8 *stack_ptr = *buffer;
  1174. for (i = 0; i < MWIFIEX_MEF_MAX_FILTERS; i++) {
  1175. filter = &mef_entry->filter[i];
  1176. if (!filter->filt_type)
  1177. break;
  1178. *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->repeat);
  1179. stack_ptr += 4;
  1180. *stack_ptr = TYPE_DNUM;
  1181. stack_ptr += 1;
  1182. byte_len = filter->byte_seq[MWIFIEX_MEF_MAX_BYTESEQ];
  1183. memcpy(stack_ptr, filter->byte_seq, byte_len);
  1184. stack_ptr += byte_len;
  1185. *stack_ptr = byte_len;
  1186. stack_ptr += 1;
  1187. *stack_ptr = TYPE_BYTESEQ;
  1188. stack_ptr += 1;
  1189. *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->offset);
  1190. stack_ptr += 4;
  1191. *stack_ptr = TYPE_DNUM;
  1192. stack_ptr += 1;
  1193. *stack_ptr = filter->filt_type;
  1194. stack_ptr += 1;
  1195. if (filter->filt_action) {
  1196. *stack_ptr = filter->filt_action;
  1197. stack_ptr += 1;
  1198. }
  1199. if (stack_ptr - *buffer > STACK_NBYTES)
  1200. return -1;
  1201. }
  1202. *buffer = stack_ptr;
  1203. return 0;
  1204. }
  1205. static int
  1206. mwifiex_cmd_mef_cfg(struct mwifiex_private *priv,
  1207. struct host_cmd_ds_command *cmd,
  1208. struct mwifiex_ds_mef_cfg *mef)
  1209. {
  1210. struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg;
  1211. u8 *pos = (u8 *)mef_cfg;
  1212. cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG);
  1213. mef_cfg->criteria = cpu_to_le32(mef->criteria);
  1214. mef_cfg->num_entries = cpu_to_le16(mef->num_entries);
  1215. pos += sizeof(*mef_cfg);
  1216. mef_cfg->mef_entry->mode = mef->mef_entry->mode;
  1217. mef_cfg->mef_entry->action = mef->mef_entry->action;
  1218. pos += sizeof(*(mef_cfg->mef_entry));
  1219. if (mwifiex_cmd_append_rpn_expression(priv, mef->mef_entry, &pos))
  1220. return -1;
  1221. mef_cfg->mef_entry->exprsize =
  1222. cpu_to_le16(pos - mef_cfg->mef_entry->expr);
  1223. cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN);
  1224. return 0;
  1225. }
  1226. /* This function parse cal data from ASCII to hex */
  1227. static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
  1228. {
  1229. u8 *s = src, *d = dst;
  1230. while (s - src < len) {
  1231. if (*s && (isspace(*s) || *s == '\t')) {
  1232. s++;
  1233. continue;
  1234. }
  1235. if (isxdigit(*s)) {
  1236. *d++ = simple_strtol(s, NULL, 16);
  1237. s += 2;
  1238. } else {
  1239. s++;
  1240. }
  1241. }
  1242. return d - dst;
  1243. }
  1244. int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
  1245. struct device_node *node, const char *prefix)
  1246. {
  1247. #ifdef CONFIG_OF
  1248. struct property *prop;
  1249. size_t len = strlen(prefix);
  1250. int ret;
  1251. /* look for all matching property names */
  1252. for_each_property_of_node(node, prop) {
  1253. if (len > strlen(prop->name) ||
  1254. strncmp(prop->name, prefix, len))
  1255. continue;
  1256. /* property header is 6 bytes, data must fit in cmd buffer */
  1257. if (prop && prop->value && prop->length > 6 &&
  1258. prop->length <= MWIFIEX_SIZE_OF_CMD_BUFFER - S_DS_GEN) {
  1259. ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
  1260. HostCmd_ACT_GEN_SET, 0,
  1261. prop, true);
  1262. if (ret)
  1263. return ret;
  1264. }
  1265. }
  1266. #endif
  1267. return 0;
  1268. }
  1269. /* This function prepares command of set_cfg_data. */
  1270. static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv,
  1271. struct host_cmd_ds_command *cmd, void *data_buf)
  1272. {
  1273. struct mwifiex_adapter *adapter = priv->adapter;
  1274. struct property *prop = data_buf;
  1275. u32 len;
  1276. u8 *data = (u8 *)cmd + S_DS_GEN;
  1277. int ret;
  1278. if (prop) {
  1279. len = prop->length;
  1280. ret = of_property_read_u8_array(adapter->dt_node, prop->name,
  1281. data, len);
  1282. if (ret)
  1283. return ret;
  1284. dev_dbg(adapter->dev,
  1285. "download cfg_data from device tree: %s\n", prop->name);
  1286. } else if (adapter->cal_data->data && adapter->cal_data->size > 0) {
  1287. len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data,
  1288. adapter->cal_data->size, data);
  1289. dev_dbg(adapter->dev, "download cfg_data from config file\n");
  1290. } else {
  1291. return -1;
  1292. }
  1293. cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA);
  1294. cmd->size = cpu_to_le16(S_DS_GEN + len);
  1295. return 0;
  1296. }
  1297. static int
  1298. mwifiex_cmd_coalesce_cfg(struct mwifiex_private *priv,
  1299. struct host_cmd_ds_command *cmd,
  1300. u16 cmd_action, void *data_buf)
  1301. {
  1302. struct host_cmd_ds_coalesce_cfg *coalesce_cfg =
  1303. &cmd->params.coalesce_cfg;
  1304. struct mwifiex_ds_coalesce_cfg *cfg = data_buf;
  1305. struct coalesce_filt_field_param *param;
  1306. u16 cnt, idx, length;
  1307. struct coalesce_receive_filt_rule *rule;
  1308. cmd->command = cpu_to_le16(HostCmd_CMD_COALESCE_CFG);
  1309. cmd->size = cpu_to_le16(S_DS_GEN);
  1310. coalesce_cfg->action = cpu_to_le16(cmd_action);
  1311. coalesce_cfg->num_of_rules = cpu_to_le16(cfg->num_of_rules);
  1312. rule = coalesce_cfg->rule;
  1313. for (cnt = 0; cnt < cfg->num_of_rules; cnt++) {
  1314. rule->header.type = cpu_to_le16(TLV_TYPE_COALESCE_RULE);
  1315. rule->max_coalescing_delay =
  1316. cpu_to_le16(cfg->rule[cnt].max_coalescing_delay);
  1317. rule->pkt_type = cfg->rule[cnt].pkt_type;
  1318. rule->num_of_fields = cfg->rule[cnt].num_of_fields;
  1319. length = 0;
  1320. param = rule->params;
  1321. for (idx = 0; idx < cfg->rule[cnt].num_of_fields; idx++) {
  1322. param->operation = cfg->rule[cnt].params[idx].operation;
  1323. param->operand_len =
  1324. cfg->rule[cnt].params[idx].operand_len;
  1325. param->offset =
  1326. cpu_to_le16(cfg->rule[cnt].params[idx].offset);
  1327. memcpy(param->operand_byte_stream,
  1328. cfg->rule[cnt].params[idx].operand_byte_stream,
  1329. param->operand_len);
  1330. length += sizeof(struct coalesce_filt_field_param);
  1331. param++;
  1332. }
  1333. /* Total rule length is sizeof max_coalescing_delay(u16),
  1334. * num_of_fields(u8), pkt_type(u8) and total length of the all
  1335. * params
  1336. */
  1337. rule->header.len = cpu_to_le16(length + sizeof(u16) +
  1338. sizeof(u8) + sizeof(u8));
  1339. /* Add the rule length to the command size*/
  1340. le16_add_cpu(&cmd->size, le16_to_cpu(rule->header.len) +
  1341. sizeof(struct mwifiex_ie_types_header));
  1342. rule = (void *)((u8 *)rule->params + length);
  1343. }
  1344. /* Add sizeof action, num_of_rules to total command length */
  1345. le16_add_cpu(&cmd->size, sizeof(u16) + sizeof(u16));
  1346. return 0;
  1347. }
  1348. static int
  1349. mwifiex_cmd_tdls_oper(struct mwifiex_private *priv,
  1350. struct host_cmd_ds_command *cmd,
  1351. void *data_buf)
  1352. {
  1353. struct host_cmd_ds_tdls_oper *tdls_oper = &cmd->params.tdls_oper;
  1354. struct mwifiex_ds_tdls_oper *oper = data_buf;
  1355. struct mwifiex_sta_node *sta_ptr;
  1356. struct host_cmd_tlv_rates *tlv_rates;
  1357. struct mwifiex_ie_types_htcap *ht_capab;
  1358. struct mwifiex_ie_types_qos_info *wmm_qos_info;
  1359. struct mwifiex_ie_types_extcap *extcap;
  1360. struct mwifiex_ie_types_vhtcap *vht_capab;
  1361. struct mwifiex_ie_types_aid *aid;
  1362. struct mwifiex_ie_types_tdls_idle_timeout *timeout;
  1363. u8 *pos, qos_info;
  1364. u16 config_len = 0;
  1365. struct station_parameters *params = priv->sta_params;
  1366. cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_OPER);
  1367. cmd->size = cpu_to_le16(S_DS_GEN);
  1368. le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_tdls_oper));
  1369. tdls_oper->reason = 0;
  1370. memcpy(tdls_oper->peer_mac, oper->peer_mac, ETH_ALEN);
  1371. sta_ptr = mwifiex_get_sta_entry(priv, oper->peer_mac);
  1372. pos = (u8 *)tdls_oper + sizeof(struct host_cmd_ds_tdls_oper);
  1373. switch (oper->tdls_action) {
  1374. case MWIFIEX_TDLS_DISABLE_LINK:
  1375. tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_DELETE);
  1376. break;
  1377. case MWIFIEX_TDLS_CREATE_LINK:
  1378. tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CREATE);
  1379. break;
  1380. case MWIFIEX_TDLS_CONFIG_LINK:
  1381. tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CONFIG);
  1382. if (!params) {
  1383. dev_err(priv->adapter->dev,
  1384. "TDLS config params not available for %pM\n",
  1385. oper->peer_mac);
  1386. return -ENODATA;
  1387. }
  1388. *(__le16 *)pos = cpu_to_le16(params->capability);
  1389. config_len += sizeof(params->capability);
  1390. qos_info = params->uapsd_queues | (params->max_sp << 5);
  1391. wmm_qos_info = (struct mwifiex_ie_types_qos_info *)(pos +
  1392. config_len);
  1393. wmm_qos_info->header.type = cpu_to_le16(WLAN_EID_QOS_CAPA);
  1394. wmm_qos_info->header.len = cpu_to_le16(sizeof(qos_info));
  1395. wmm_qos_info->qos_info = qos_info;
  1396. config_len += sizeof(struct mwifiex_ie_types_qos_info);
  1397. if (params->ht_capa) {
  1398. ht_capab = (struct mwifiex_ie_types_htcap *)(pos +
  1399. config_len);
  1400. ht_capab->header.type =
  1401. cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  1402. ht_capab->header.len =
  1403. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  1404. memcpy(&ht_capab->ht_cap, params->ht_capa,
  1405. sizeof(struct ieee80211_ht_cap));
  1406. config_len += sizeof(struct mwifiex_ie_types_htcap);
  1407. }
  1408. if (params->supported_rates && params->supported_rates_len) {
  1409. tlv_rates = (struct host_cmd_tlv_rates *)(pos +
  1410. config_len);
  1411. tlv_rates->header.type =
  1412. cpu_to_le16(WLAN_EID_SUPP_RATES);
  1413. tlv_rates->header.len =
  1414. cpu_to_le16(params->supported_rates_len);
  1415. memcpy(tlv_rates->rates, params->supported_rates,
  1416. params->supported_rates_len);
  1417. config_len += sizeof(struct host_cmd_tlv_rates) +
  1418. params->supported_rates_len;
  1419. }
  1420. if (params->ext_capab && params->ext_capab_len) {
  1421. extcap = (struct mwifiex_ie_types_extcap *)(pos +
  1422. config_len);
  1423. extcap->header.type =
  1424. cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
  1425. extcap->header.len = cpu_to_le16(params->ext_capab_len);
  1426. memcpy(extcap->ext_capab, params->ext_capab,
  1427. params->ext_capab_len);
  1428. config_len += sizeof(struct mwifiex_ie_types_extcap) +
  1429. params->ext_capab_len;
  1430. }
  1431. if (params->vht_capa) {
  1432. vht_capab = (struct mwifiex_ie_types_vhtcap *)(pos +
  1433. config_len);
  1434. vht_capab->header.type =
  1435. cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
  1436. vht_capab->header.len =
  1437. cpu_to_le16(sizeof(struct ieee80211_vht_cap));
  1438. memcpy(&vht_capab->vht_cap, params->vht_capa,
  1439. sizeof(struct ieee80211_vht_cap));
  1440. config_len += sizeof(struct mwifiex_ie_types_vhtcap);
  1441. }
  1442. if (params->aid) {
  1443. aid = (struct mwifiex_ie_types_aid *)(pos + config_len);
  1444. aid->header.type = cpu_to_le16(WLAN_EID_AID);
  1445. aid->header.len = cpu_to_le16(sizeof(params->aid));
  1446. aid->aid = cpu_to_le16(params->aid);
  1447. config_len += sizeof(struct mwifiex_ie_types_aid);
  1448. }
  1449. timeout = (void *)(pos + config_len);
  1450. timeout->header.type = cpu_to_le16(TLV_TYPE_TDLS_IDLE_TIMEOUT);
  1451. timeout->header.len = cpu_to_le16(sizeof(timeout->value));
  1452. timeout->value = cpu_to_le16(MWIFIEX_TDLS_IDLE_TIMEOUT_IN_SEC);
  1453. config_len += sizeof(struct mwifiex_ie_types_tdls_idle_timeout);
  1454. break;
  1455. default:
  1456. dev_err(priv->adapter->dev, "Unknown TDLS operation\n");
  1457. return -ENOTSUPP;
  1458. }
  1459. le16_add_cpu(&cmd->size, config_len);
  1460. return 0;
  1461. }
  1462. /*
  1463. * This function prepares the commands before sending them to the firmware.
  1464. *
  1465. * This is a generic function which calls specific command preparation
  1466. * routines based upon the command number.
  1467. */
  1468. int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
  1469. u16 cmd_action, u32 cmd_oid,
  1470. void *data_buf, void *cmd_buf)
  1471. {
  1472. struct host_cmd_ds_command *cmd_ptr = cmd_buf;
  1473. int ret = 0;
  1474. /* Prepare command */
  1475. switch (cmd_no) {
  1476. case HostCmd_CMD_GET_HW_SPEC:
  1477. ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
  1478. break;
  1479. case HostCmd_CMD_CFG_DATA:
  1480. ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, data_buf);
  1481. break;
  1482. case HostCmd_CMD_MAC_CONTROL:
  1483. ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
  1484. data_buf);
  1485. break;
  1486. case HostCmd_CMD_802_11_MAC_ADDRESS:
  1487. ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
  1488. cmd_action);
  1489. break;
  1490. case HostCmd_CMD_MAC_MULTICAST_ADR:
  1491. ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
  1492. data_buf);
  1493. break;
  1494. case HostCmd_CMD_TX_RATE_CFG:
  1495. ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
  1496. data_buf);
  1497. break;
  1498. case HostCmd_CMD_TXPWR_CFG:
  1499. ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
  1500. data_buf);
  1501. break;
  1502. case HostCmd_CMD_RF_TX_PWR:
  1503. ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
  1504. data_buf);
  1505. break;
  1506. case HostCmd_CMD_RF_ANTENNA:
  1507. ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
  1508. data_buf);
  1509. break;
  1510. case HostCmd_CMD_802_11_PS_MODE_ENH:
  1511. ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
  1512. (uint16_t)cmd_oid, data_buf);
  1513. break;
  1514. case HostCmd_CMD_802_11_HS_CFG_ENH:
  1515. ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
  1516. (struct mwifiex_hs_config_param *) data_buf);
  1517. break;
  1518. case HostCmd_CMD_802_11_SCAN:
  1519. ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
  1520. break;
  1521. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  1522. ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
  1523. break;
  1524. case HostCmd_CMD_802_11_ASSOCIATE:
  1525. ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
  1526. break;
  1527. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  1528. ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
  1529. data_buf);
  1530. break;
  1531. case HostCmd_CMD_802_11_AD_HOC_START:
  1532. ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
  1533. data_buf);
  1534. break;
  1535. case HostCmd_CMD_802_11_GET_LOG:
  1536. ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
  1537. break;
  1538. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  1539. ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
  1540. data_buf);
  1541. break;
  1542. case HostCmd_CMD_802_11_AD_HOC_STOP:
  1543. ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
  1544. break;
  1545. case HostCmd_CMD_RSSI_INFO:
  1546. ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
  1547. break;
  1548. case HostCmd_CMD_802_11_SNMP_MIB:
  1549. ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
  1550. cmd_oid, data_buf);
  1551. break;
  1552. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  1553. cmd_ptr->command =
  1554. cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
  1555. cmd_ptr->size =
  1556. cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
  1557. S_DS_GEN);
  1558. priv->tx_rate = 0;
  1559. ret = 0;
  1560. break;
  1561. case HostCmd_CMD_VERSION_EXT:
  1562. cmd_ptr->command = cpu_to_le16(cmd_no);
  1563. cmd_ptr->params.verext.version_str_sel =
  1564. (u8) (*((u32 *) data_buf));
  1565. memcpy(&cmd_ptr->params, data_buf,
  1566. sizeof(struct host_cmd_ds_version_ext));
  1567. cmd_ptr->size =
  1568. cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
  1569. S_DS_GEN);
  1570. ret = 0;
  1571. break;
  1572. case HostCmd_CMD_MGMT_FRAME_REG:
  1573. cmd_ptr->command = cpu_to_le16(cmd_no);
  1574. cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action);
  1575. cmd_ptr->params.reg_mask.mask = cpu_to_le32(*(u32 *)data_buf);
  1576. cmd_ptr->size =
  1577. cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) +
  1578. S_DS_GEN);
  1579. ret = 0;
  1580. break;
  1581. case HostCmd_CMD_REMAIN_ON_CHAN:
  1582. cmd_ptr->command = cpu_to_le16(cmd_no);
  1583. memcpy(&cmd_ptr->params, data_buf,
  1584. sizeof(struct host_cmd_ds_remain_on_chan));
  1585. cmd_ptr->size =
  1586. cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) +
  1587. S_DS_GEN);
  1588. break;
  1589. case HostCmd_CMD_11AC_CFG:
  1590. ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf);
  1591. break;
  1592. case HostCmd_CMD_P2P_MODE_CFG:
  1593. cmd_ptr->command = cpu_to_le16(cmd_no);
  1594. cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action);
  1595. cmd_ptr->params.mode_cfg.mode = cpu_to_le16(*(u16 *)data_buf);
  1596. cmd_ptr->size =
  1597. cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) +
  1598. S_DS_GEN);
  1599. break;
  1600. case HostCmd_CMD_FUNC_INIT:
  1601. if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
  1602. priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  1603. cmd_ptr->command = cpu_to_le16(cmd_no);
  1604. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  1605. break;
  1606. case HostCmd_CMD_FUNC_SHUTDOWN:
  1607. priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
  1608. cmd_ptr->command = cpu_to_le16(cmd_no);
  1609. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  1610. break;
  1611. case HostCmd_CMD_11N_ADDBA_REQ:
  1612. ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
  1613. break;
  1614. case HostCmd_CMD_11N_DELBA:
  1615. ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
  1616. break;
  1617. case HostCmd_CMD_11N_ADDBA_RSP:
  1618. ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
  1619. break;
  1620. case HostCmd_CMD_802_11_KEY_MATERIAL:
  1621. ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
  1622. cmd_action, cmd_oid,
  1623. data_buf);
  1624. break;
  1625. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  1626. ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
  1627. cmd_action);
  1628. break;
  1629. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  1630. ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
  1631. data_buf);
  1632. break;
  1633. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  1634. ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
  1635. data_buf);
  1636. break;
  1637. case HostCmd_CMD_11N_CFG:
  1638. ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
  1639. break;
  1640. case HostCmd_CMD_WMM_GET_STATUS:
  1641. dev_dbg(priv->adapter->dev,
  1642. "cmd: WMM: WMM_GET_STATUS cmd sent\n");
  1643. cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
  1644. cmd_ptr->size =
  1645. cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
  1646. S_DS_GEN);
  1647. ret = 0;
  1648. break;
  1649. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  1650. ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
  1651. data_buf);
  1652. break;
  1653. case HostCmd_CMD_802_11_SCAN_EXT:
  1654. ret = mwifiex_cmd_802_11_scan_ext(priv, cmd_ptr, data_buf);
  1655. break;
  1656. case HostCmd_CMD_MAC_REG_ACCESS:
  1657. case HostCmd_CMD_BBP_REG_ACCESS:
  1658. case HostCmd_CMD_RF_REG_ACCESS:
  1659. case HostCmd_CMD_PMIC_REG_ACCESS:
  1660. case HostCmd_CMD_CAU_REG_ACCESS:
  1661. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  1662. ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
  1663. break;
  1664. case HostCmd_CMD_SET_BSS_MODE:
  1665. cmd_ptr->command = cpu_to_le16(cmd_no);
  1666. if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
  1667. cmd_ptr->params.bss_mode.con_type =
  1668. CONNECTION_TYPE_ADHOC;
  1669. else if (priv->bss_mode == NL80211_IFTYPE_STATION)
  1670. cmd_ptr->params.bss_mode.con_type =
  1671. CONNECTION_TYPE_INFRA;
  1672. else if (priv->bss_mode == NL80211_IFTYPE_AP)
  1673. cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP;
  1674. cmd_ptr->size = cpu_to_le16(sizeof(struct
  1675. host_cmd_ds_set_bss_mode) + S_DS_GEN);
  1676. ret = 0;
  1677. break;
  1678. case HostCmd_CMD_PCIE_DESC_DETAILS:
  1679. ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
  1680. break;
  1681. case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
  1682. ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
  1683. break;
  1684. case HostCmd_CMD_MEF_CFG:
  1685. ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf);
  1686. break;
  1687. case HostCmd_CMD_COALESCE_CFG:
  1688. ret = mwifiex_cmd_coalesce_cfg(priv, cmd_ptr, cmd_action,
  1689. data_buf);
  1690. break;
  1691. case HostCmd_CMD_TDLS_OPER:
  1692. ret = mwifiex_cmd_tdls_oper(priv, cmd_ptr, data_buf);
  1693. break;
  1694. default:
  1695. dev_err(priv->adapter->dev,
  1696. "PREP_CMD: unknown cmd- %#x\n", cmd_no);
  1697. ret = -1;
  1698. break;
  1699. }
  1700. return ret;
  1701. }
  1702. /*
  1703. * This function issues commands to initialize firmware.
  1704. *
  1705. * This is called after firmware download to bring the card to
  1706. * working state.
  1707. *
  1708. * The following commands are issued sequentially -
  1709. * - Set PCI-Express host buffer configuration (PCIE only)
  1710. * - Function init (for first interface only)
  1711. * - Read MAC address (for first interface only)
  1712. * - Reconfigure Tx buffer size (for first interface only)
  1713. * - Enable auto deep sleep (for first interface only)
  1714. * - Get Tx rate
  1715. * - Get Tx power
  1716. * - Set IBSS coalescing status
  1717. * - Set AMSDU aggregation control
  1718. * - Set 11d control
  1719. * - Set MAC control (this must be the last command to initialize firmware)
  1720. */
  1721. int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
  1722. {
  1723. struct mwifiex_adapter *adapter = priv->adapter;
  1724. int ret;
  1725. u16 enable = true;
  1726. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  1727. struct mwifiex_ds_auto_ds auto_ds;
  1728. enum state_11d_t state_11d;
  1729. struct mwifiex_ds_11n_tx_cfg tx_cfg;
  1730. if (first_sta) {
  1731. if (priv->adapter->iface_type == MWIFIEX_PCIE) {
  1732. ret = mwifiex_send_cmd(priv,
  1733. HostCmd_CMD_PCIE_DESC_DETAILS,
  1734. HostCmd_ACT_GEN_SET, 0, NULL,
  1735. true);
  1736. if (ret)
  1737. return -1;
  1738. }
  1739. ret = mwifiex_send_cmd(priv, HostCmd_CMD_FUNC_INIT,
  1740. HostCmd_ACT_GEN_SET, 0, NULL, true);
  1741. if (ret)
  1742. return -1;
  1743. /* Download calibration data to firmware.
  1744. * The cal-data can be read from device tree and/or
  1745. * a configuration file and downloaded to firmware.
  1746. */
  1747. adapter->dt_node =
  1748. of_find_node_by_name(NULL, "marvell_cfgdata");
  1749. if (adapter->dt_node) {
  1750. ret = mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node,
  1751. "marvell,caldata");
  1752. if (ret)
  1753. return -1;
  1754. }
  1755. if (adapter->cal_data) {
  1756. ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
  1757. HostCmd_ACT_GEN_SET, 0, NULL,
  1758. true);
  1759. if (ret)
  1760. return -1;
  1761. }
  1762. /* Read MAC address from HW */
  1763. ret = mwifiex_send_cmd(priv, HostCmd_CMD_GET_HW_SPEC,
  1764. HostCmd_ACT_GEN_GET, 0, NULL, true);
  1765. if (ret)
  1766. return -1;
  1767. /* Reconfigure tx buf size */
  1768. ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
  1769. HostCmd_ACT_GEN_SET, 0,
  1770. &priv->adapter->tx_buf_size, true);
  1771. if (ret)
  1772. return -1;
  1773. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1774. /* Enable IEEE PS by default */
  1775. priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1776. ret = mwifiex_send_cmd(priv,
  1777. HostCmd_CMD_802_11_PS_MODE_ENH,
  1778. EN_AUTO_PS, BITMAP_STA_PS, NULL,
  1779. true);
  1780. if (ret)
  1781. return -1;
  1782. }
  1783. }
  1784. /* get tx rate */
  1785. ret = mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
  1786. HostCmd_ACT_GEN_GET, 0, NULL, true);
  1787. if (ret)
  1788. return -1;
  1789. priv->data_rate = 0;
  1790. /* get tx power */
  1791. ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
  1792. HostCmd_ACT_GEN_GET, 0, NULL, true);
  1793. if (ret)
  1794. return -1;
  1795. if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
  1796. /* set ibss coalescing_status */
  1797. ret = mwifiex_send_cmd(
  1798. priv,
  1799. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1800. HostCmd_ACT_GEN_SET, 0, &enable, true);
  1801. if (ret)
  1802. return -1;
  1803. }
  1804. memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
  1805. amsdu_aggr_ctrl.enable = true;
  1806. /* Send request to firmware */
  1807. ret = mwifiex_send_cmd(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
  1808. HostCmd_ACT_GEN_SET, 0,
  1809. &amsdu_aggr_ctrl, true);
  1810. if (ret)
  1811. return -1;
  1812. /* MAC Control must be the last command in init_fw */
  1813. /* set MAC Control */
  1814. ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  1815. HostCmd_ACT_GEN_SET, 0,
  1816. &priv->curr_pkt_filter, true);
  1817. if (ret)
  1818. return -1;
  1819. if (first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
  1820. priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1821. /* Enable auto deep sleep */
  1822. auto_ds.auto_ds = DEEP_SLEEP_ON;
  1823. auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  1824. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1825. EN_AUTO_PS, BITMAP_AUTO_DS,
  1826. &auto_ds, true);
  1827. if (ret)
  1828. return -1;
  1829. }
  1830. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1831. /* Send cmd to FW to enable/disable 11D function */
  1832. state_11d = ENABLE_11D;
  1833. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1834. HostCmd_ACT_GEN_SET, DOT11D_I,
  1835. &state_11d, true);
  1836. if (ret)
  1837. dev_err(priv->adapter->dev,
  1838. "11D: failed to enable 11D\n");
  1839. }
  1840. /* set last_init_cmd before sending the command */
  1841. priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
  1842. /* Send cmd to FW to configure 11n specific configuration
  1843. * (Short GI, Channel BW, Green field support etc.) for transmit
  1844. */
  1845. tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
  1846. ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_CFG,
  1847. HostCmd_ACT_GEN_SET, 0, &tx_cfg, true);
  1848. ret = -EINPROGRESS;
  1849. return ret;
  1850. }