sta_cmd.c 74 KB

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