sta_cmd.c 70 KB

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