sta_cmd.c 73 KB

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