sta_cmd.c 66 KB

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