sta_cmd.c 69 KB

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