sta_cmd.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  1. /*
  2. * Marvell Wireless LAN device driver: station command handling
  3. *
  4. * Copyright (C) 2011, 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. /*
  28. * This function prepares command to set/get RSSI information.
  29. *
  30. * Preparation includes -
  31. * - Setting command ID, action and proper size
  32. * - Setting data/beacon average factors
  33. * - Resetting SNR/NF/RSSI values in private structure
  34. * - Ensuring correct endian-ness
  35. */
  36. static int
  37. mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
  38. struct host_cmd_ds_command *cmd, u16 cmd_action)
  39. {
  40. cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
  41. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
  42. S_DS_GEN);
  43. cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
  44. cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
  45. cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
  46. /* Reset SNR/NF/RSSI values in private structure */
  47. priv->data_rssi_last = 0;
  48. priv->data_nf_last = 0;
  49. priv->data_rssi_avg = 0;
  50. priv->data_nf_avg = 0;
  51. priv->bcn_rssi_last = 0;
  52. priv->bcn_nf_last = 0;
  53. priv->bcn_rssi_avg = 0;
  54. priv->bcn_nf_avg = 0;
  55. return 0;
  56. }
  57. /*
  58. * This function prepares command to set MAC control.
  59. *
  60. * Preparation includes -
  61. * - Setting command ID, action and proper size
  62. * - Ensuring correct endian-ness
  63. */
  64. static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
  65. struct host_cmd_ds_command *cmd,
  66. u16 cmd_action, u16 *action)
  67. {
  68. struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
  69. if (cmd_action != HostCmd_ACT_GEN_SET) {
  70. dev_err(priv->adapter->dev,
  71. "mac_control: only support set cmd\n");
  72. return -1;
  73. }
  74. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
  75. cmd->size =
  76. cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
  77. mac_ctrl->action = cpu_to_le16(*action);
  78. return 0;
  79. }
  80. /*
  81. * This function prepares command to set/get SNMP MIB.
  82. *
  83. * Preparation includes -
  84. * - Setting command ID, action and proper size
  85. * - Setting SNMP MIB OID number and value
  86. * (as required)
  87. * - Ensuring correct endian-ness
  88. *
  89. * The following SNMP MIB OIDs are supported -
  90. * - FRAG_THRESH_I : Fragmentation threshold
  91. * - RTS_THRESH_I : RTS threshold
  92. * - SHORT_RETRY_LIM_I : Short retry limit
  93. * - DOT11D_I : 11d support
  94. */
  95. static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
  96. struct host_cmd_ds_command *cmd,
  97. u16 cmd_action, u32 cmd_oid,
  98. u16 *ul_temp)
  99. {
  100. struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
  101. dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
  102. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
  103. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
  104. - 1 + S_DS_GEN);
  105. snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
  106. if (cmd_action == HostCmd_ACT_GEN_GET) {
  107. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
  108. snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
  109. le16_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE);
  110. } else if (cmd_action == HostCmd_ACT_GEN_SET) {
  111. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  112. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  113. *((__le16 *) (snmp_mib->value)) = cpu_to_le16(*ul_temp);
  114. le16_add_cpu(&cmd->size, sizeof(u16));
  115. }
  116. dev_dbg(priv->adapter->dev,
  117. "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
  118. " Value=0x%x\n",
  119. cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
  120. le16_to_cpu(*(__le16 *) snmp_mib->value));
  121. return 0;
  122. }
  123. /*
  124. * This function prepares command to get log.
  125. *
  126. * Preparation includes -
  127. * - Setting command ID and proper size
  128. * - Ensuring correct endian-ness
  129. */
  130. static int
  131. mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
  132. {
  133. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
  134. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
  135. S_DS_GEN);
  136. return 0;
  137. }
  138. /*
  139. * This function prepares command to set/get Tx data rate configuration.
  140. *
  141. * Preparation includes -
  142. * - Setting command ID, action and proper size
  143. * - Setting configuration index, rate scope and rate drop pattern
  144. * parameters (as required)
  145. * - Ensuring correct endian-ness
  146. */
  147. static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
  148. struct host_cmd_ds_command *cmd,
  149. u16 cmd_action, u16 *pbitmap_rates)
  150. {
  151. struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
  152. struct mwifiex_rate_scope *rate_scope;
  153. struct mwifiex_rate_drop_pattern *rate_drop;
  154. u32 i;
  155. cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
  156. rate_cfg->action = cpu_to_le16(cmd_action);
  157. rate_cfg->cfg_index = 0;
  158. rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
  159. sizeof(struct host_cmd_ds_tx_rate_cfg));
  160. rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
  161. rate_scope->length = cpu_to_le16
  162. (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
  163. if (pbitmap_rates != NULL) {
  164. rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
  165. rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
  166. for (i = 0;
  167. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  168. i++)
  169. rate_scope->ht_mcs_rate_bitmap[i] =
  170. cpu_to_le16(pbitmap_rates[2 + i]);
  171. } else {
  172. rate_scope->hr_dsss_rate_bitmap =
  173. cpu_to_le16(priv->bitmap_rates[0]);
  174. rate_scope->ofdm_rate_bitmap =
  175. cpu_to_le16(priv->bitmap_rates[1]);
  176. for (i = 0;
  177. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  178. i++)
  179. rate_scope->ht_mcs_rate_bitmap[i] =
  180. cpu_to_le16(priv->bitmap_rates[2 + i]);
  181. }
  182. rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
  183. sizeof(struct mwifiex_rate_scope));
  184. rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
  185. rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
  186. rate_drop->rate_drop_mode = 0;
  187. cmd->size =
  188. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
  189. sizeof(struct mwifiex_rate_scope) +
  190. sizeof(struct mwifiex_rate_drop_pattern));
  191. return 0;
  192. }
  193. /*
  194. * This function prepares command to set/get Tx power configuration.
  195. *
  196. * Preparation includes -
  197. * - Setting command ID, action and proper size
  198. * - Setting Tx power mode, power group TLV
  199. * (as required)
  200. * - Ensuring correct endian-ness
  201. */
  202. static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
  203. u16 cmd_action,
  204. struct host_cmd_ds_txpwr_cfg *txp)
  205. {
  206. struct mwifiex_types_power_group *pg_tlv;
  207. struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
  208. cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
  209. cmd->size =
  210. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
  211. switch (cmd_action) {
  212. case HostCmd_ACT_GEN_SET:
  213. if (txp->mode) {
  214. pg_tlv = (struct mwifiex_types_power_group
  215. *) ((unsigned long) txp +
  216. sizeof(struct host_cmd_ds_txpwr_cfg));
  217. memmove(cmd_txp_cfg, txp,
  218. sizeof(struct host_cmd_ds_txpwr_cfg) +
  219. sizeof(struct mwifiex_types_power_group) +
  220. le16_to_cpu(pg_tlv->length));
  221. pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
  222. cmd_txp_cfg +
  223. sizeof(struct host_cmd_ds_txpwr_cfg));
  224. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
  225. sizeof(struct mwifiex_types_power_group) +
  226. le16_to_cpu(pg_tlv->length));
  227. } else {
  228. memmove(cmd_txp_cfg, txp, sizeof(*txp));
  229. }
  230. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  231. break;
  232. case HostCmd_ACT_GEN_GET:
  233. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  234. break;
  235. }
  236. return 0;
  237. }
  238. /*
  239. * This function prepares command to get RF Tx power.
  240. */
  241. static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
  242. struct host_cmd_ds_command *cmd,
  243. u16 cmd_action, void *data_buf)
  244. {
  245. struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
  246. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
  247. + S_DS_GEN);
  248. cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
  249. txp->action = cpu_to_le16(cmd_action);
  250. return 0;
  251. }
  252. /*
  253. * This function prepares command to set rf antenna.
  254. */
  255. static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv,
  256. struct host_cmd_ds_command *cmd,
  257. u16 cmd_action,
  258. struct mwifiex_ds_ant_cfg *ant_cfg)
  259. {
  260. struct host_cmd_ds_rf_ant_mimo *ant_mimo = &cmd->params.ant_mimo;
  261. struct host_cmd_ds_rf_ant_siso *ant_siso = &cmd->params.ant_siso;
  262. cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA);
  263. if (cmd_action != HostCmd_ACT_GEN_SET)
  264. return 0;
  265. if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
  266. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_mimo) +
  267. S_DS_GEN);
  268. ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX);
  269. ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
  270. ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
  271. ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->rx_ant);
  272. } else {
  273. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_siso) +
  274. S_DS_GEN);
  275. ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
  276. ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
  277. }
  278. return 0;
  279. }
  280. /*
  281. * This function prepares command to set Host Sleep configuration.
  282. *
  283. * Preparation includes -
  284. * - Setting command ID and proper size
  285. * - Setting Host Sleep action, conditions, ARP filters
  286. * (as required)
  287. * - Ensuring correct endian-ness
  288. */
  289. static int
  290. mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
  291. struct host_cmd_ds_command *cmd,
  292. u16 cmd_action,
  293. struct mwifiex_hs_config_param *hscfg_param)
  294. {
  295. struct mwifiex_adapter *adapter = priv->adapter;
  296. struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
  297. bool hs_activate = false;
  298. if (!hscfg_param)
  299. /* New Activate command */
  300. hs_activate = true;
  301. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
  302. if (!hs_activate &&
  303. (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) &&
  304. ((adapter->arp_filter_size > 0) &&
  305. (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
  306. dev_dbg(adapter->dev,
  307. "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
  308. adapter->arp_filter_size);
  309. memcpy(((u8 *) hs_cfg) +
  310. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
  311. adapter->arp_filter, adapter->arp_filter_size);
  312. cmd->size = cpu_to_le16
  313. (adapter->arp_filter_size +
  314. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
  315. + S_DS_GEN);
  316. } else {
  317. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
  318. host_cmd_ds_802_11_hs_cfg_enh));
  319. }
  320. if (hs_activate) {
  321. hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
  322. hs_cfg->params.hs_activate.resp_ctrl = cpu_to_le16(RESP_NEEDED);
  323. } else {
  324. hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
  325. hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
  326. hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
  327. hs_cfg->params.hs_config.gap = hscfg_param->gap;
  328. dev_dbg(adapter->dev,
  329. "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
  330. hs_cfg->params.hs_config.conditions,
  331. hs_cfg->params.hs_config.gpio,
  332. hs_cfg->params.hs_config.gap);
  333. }
  334. return 0;
  335. }
  336. /*
  337. * This function prepares command to set/get MAC address.
  338. *
  339. * Preparation includes -
  340. * - Setting command ID, action and proper size
  341. * - Setting MAC address (for SET only)
  342. * - Ensuring correct endian-ness
  343. */
  344. static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
  345. struct host_cmd_ds_command *cmd,
  346. u16 cmd_action)
  347. {
  348. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
  349. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
  350. S_DS_GEN);
  351. cmd->result = 0;
  352. cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
  353. if (cmd_action == HostCmd_ACT_GEN_SET)
  354. memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
  355. ETH_ALEN);
  356. return 0;
  357. }
  358. /*
  359. * This function prepares command to set MAC multicast address.
  360. *
  361. * Preparation includes -
  362. * - Setting command ID, action and proper size
  363. * - Setting MAC multicast address
  364. * - Ensuring correct endian-ness
  365. */
  366. static int
  367. mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
  368. u16 cmd_action,
  369. struct mwifiex_multicast_list *mcast_list)
  370. {
  371. struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
  372. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
  373. S_DS_GEN);
  374. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
  375. mcast_addr->action = cpu_to_le16(cmd_action);
  376. mcast_addr->num_of_adrs =
  377. cpu_to_le16((u16) mcast_list->num_multicast_addr);
  378. memcpy(mcast_addr->mac_list, mcast_list->mac_list,
  379. mcast_list->num_multicast_addr * ETH_ALEN);
  380. return 0;
  381. }
  382. /*
  383. * This function prepares command to deauthenticate.
  384. *
  385. * Preparation includes -
  386. * - Setting command ID and proper size
  387. * - Setting AP MAC address and reason code
  388. * - Ensuring correct endian-ness
  389. */
  390. static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
  391. struct host_cmd_ds_command *cmd,
  392. u8 *mac)
  393. {
  394. struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
  395. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
  396. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
  397. + S_DS_GEN);
  398. /* Set AP MAC address */
  399. memcpy(deauth->mac_addr, mac, ETH_ALEN);
  400. dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
  401. deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
  402. return 0;
  403. }
  404. /*
  405. * This function prepares command to stop Ad-Hoc network.
  406. *
  407. * Preparation includes -
  408. * - Setting command ID and proper size
  409. * - Ensuring correct endian-ness
  410. */
  411. static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
  412. {
  413. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
  414. cmd->size = cpu_to_le16(S_DS_GEN);
  415. return 0;
  416. }
  417. /*
  418. * This function sets WEP key(s) to key parameter TLV(s).
  419. *
  420. * Multi-key parameter TLVs are supported, so we can send multiple
  421. * WEP keys in a single buffer.
  422. */
  423. static int
  424. mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
  425. struct mwifiex_ie_type_key_param_set *key_param_set,
  426. u16 *key_param_len)
  427. {
  428. int cur_key_param_len;
  429. u8 i;
  430. /* Multi-key_param_set TLV is supported */
  431. for (i = 0; i < NUM_WEP_KEYS; i++) {
  432. if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
  433. (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
  434. key_param_set->type =
  435. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  436. /* Key_param_set WEP fixed length */
  437. #define KEYPARAMSET_WEP_FIXED_LEN 8
  438. key_param_set->length = cpu_to_le16((u16)
  439. (priv->wep_key[i].
  440. key_length +
  441. KEYPARAMSET_WEP_FIXED_LEN));
  442. key_param_set->key_type_id =
  443. cpu_to_le16(KEY_TYPE_ID_WEP);
  444. key_param_set->key_info =
  445. cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
  446. KEY_MCAST);
  447. key_param_set->key_len =
  448. cpu_to_le16(priv->wep_key[i].key_length);
  449. /* Set WEP key index */
  450. key_param_set->key[0] = i;
  451. /* Set default Tx key flag */
  452. if (i ==
  453. (priv->
  454. wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
  455. key_param_set->key[1] = 1;
  456. else
  457. key_param_set->key[1] = 0;
  458. memmove(&key_param_set->key[2],
  459. priv->wep_key[i].key_material,
  460. priv->wep_key[i].key_length);
  461. cur_key_param_len = priv->wep_key[i].key_length +
  462. KEYPARAMSET_WEP_FIXED_LEN +
  463. sizeof(struct mwifiex_ie_types_header);
  464. *key_param_len += (u16) cur_key_param_len;
  465. key_param_set =
  466. (struct mwifiex_ie_type_key_param_set *)
  467. ((u8 *)key_param_set +
  468. cur_key_param_len);
  469. } else if (!priv->wep_key[i].key_length) {
  470. continue;
  471. } else {
  472. dev_err(priv->adapter->dev,
  473. "key%d Length = %d is incorrect\n",
  474. (i + 1), priv->wep_key[i].key_length);
  475. return -1;
  476. }
  477. }
  478. return 0;
  479. }
  480. /*
  481. * This function prepares command to set/get/reset network key(s).
  482. *
  483. * Preparation includes -
  484. * - Setting command ID, action and proper size
  485. * - Setting WEP keys, WAPI keys or WPA keys along with required
  486. * encryption (TKIP, AES) (as required)
  487. * - Ensuring correct endian-ness
  488. */
  489. static int
  490. mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
  491. struct host_cmd_ds_command *cmd,
  492. u16 cmd_action, u32 cmd_oid,
  493. struct mwifiex_ds_encrypt_key *enc_key)
  494. {
  495. struct host_cmd_ds_802_11_key_material *key_material =
  496. &cmd->params.key_material;
  497. struct host_cmd_tlv_mac_addr *tlv_mac;
  498. u16 key_param_len = 0, cmd_size;
  499. int ret = 0;
  500. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
  501. key_material->action = cpu_to_le16(cmd_action);
  502. if (cmd_action == HostCmd_ACT_GEN_GET) {
  503. cmd->size =
  504. cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
  505. return ret;
  506. }
  507. if (!enc_key) {
  508. memset(&key_material->key_param_set, 0,
  509. (NUM_WEP_KEYS *
  510. sizeof(struct mwifiex_ie_type_key_param_set)));
  511. ret = mwifiex_set_keyparamset_wep(priv,
  512. &key_material->key_param_set,
  513. &key_param_len);
  514. cmd->size = cpu_to_le16(key_param_len +
  515. sizeof(key_material->action) + S_DS_GEN);
  516. return ret;
  517. } else
  518. memset(&key_material->key_param_set, 0,
  519. sizeof(struct mwifiex_ie_type_key_param_set));
  520. if (enc_key->is_wapi_key) {
  521. dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
  522. key_material->key_param_set.key_type_id =
  523. cpu_to_le16(KEY_TYPE_ID_WAPI);
  524. if (cmd_oid == KEY_INFO_ENABLED)
  525. key_material->key_param_set.key_info =
  526. cpu_to_le16(KEY_ENABLED);
  527. else
  528. key_material->key_param_set.key_info =
  529. cpu_to_le16(!KEY_ENABLED);
  530. key_material->key_param_set.key[0] = enc_key->key_index;
  531. if (!priv->sec_info.wapi_key_on)
  532. key_material->key_param_set.key[1] = 1;
  533. else
  534. /* set 0 when re-key */
  535. key_material->key_param_set.key[1] = 0;
  536. if (!is_broadcast_ether_addr(enc_key->mac_addr)) {
  537. /* WAPI pairwise key: unicast */
  538. key_material->key_param_set.key_info |=
  539. cpu_to_le16(KEY_UNICAST);
  540. } else { /* WAPI group key: multicast */
  541. key_material->key_param_set.key_info |=
  542. cpu_to_le16(KEY_MCAST);
  543. priv->sec_info.wapi_key_on = true;
  544. }
  545. key_material->key_param_set.type =
  546. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  547. key_material->key_param_set.key_len =
  548. cpu_to_le16(WAPI_KEY_LEN);
  549. memcpy(&key_material->key_param_set.key[2],
  550. enc_key->key_material, enc_key->key_len);
  551. memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
  552. enc_key->pn, PN_LEN);
  553. key_material->key_param_set.length =
  554. cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
  555. key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
  556. sizeof(struct mwifiex_ie_types_header);
  557. cmd->size = cpu_to_le16(sizeof(key_material->action)
  558. + S_DS_GEN + key_param_len);
  559. return ret;
  560. }
  561. if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
  562. if (enc_key->is_igtk_key) {
  563. dev_dbg(priv->adapter->dev, "cmd: CMAC_AES\n");
  564. key_material->key_param_set.key_type_id =
  565. cpu_to_le16(KEY_TYPE_ID_AES_CMAC);
  566. if (cmd_oid == KEY_INFO_ENABLED)
  567. key_material->key_param_set.key_info =
  568. cpu_to_le16(KEY_ENABLED);
  569. else
  570. key_material->key_param_set.key_info =
  571. cpu_to_le16(!KEY_ENABLED);
  572. key_material->key_param_set.key_info |=
  573. cpu_to_le16(KEY_IGTK);
  574. } else {
  575. dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
  576. key_material->key_param_set.key_type_id =
  577. cpu_to_le16(KEY_TYPE_ID_AES);
  578. if (cmd_oid == KEY_INFO_ENABLED)
  579. key_material->key_param_set.key_info =
  580. cpu_to_le16(KEY_ENABLED);
  581. else
  582. key_material->key_param_set.key_info =
  583. cpu_to_le16(!KEY_ENABLED);
  584. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  585. /* AES pairwise key: unicast */
  586. key_material->key_param_set.key_info |=
  587. cpu_to_le16(KEY_UNICAST);
  588. else /* AES group key: multicast */
  589. key_material->key_param_set.key_info |=
  590. cpu_to_le16(KEY_MCAST);
  591. }
  592. } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
  593. dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
  594. key_material->key_param_set.key_type_id =
  595. cpu_to_le16(KEY_TYPE_ID_TKIP);
  596. key_material->key_param_set.key_info =
  597. cpu_to_le16(KEY_ENABLED);
  598. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  599. /* TKIP pairwise key: unicast */
  600. key_material->key_param_set.key_info |=
  601. cpu_to_le16(KEY_UNICAST);
  602. else /* TKIP group key: multicast */
  603. key_material->key_param_set.key_info |=
  604. cpu_to_le16(KEY_MCAST);
  605. }
  606. if (key_material->key_param_set.key_type_id) {
  607. key_material->key_param_set.type =
  608. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  609. key_material->key_param_set.key_len =
  610. cpu_to_le16((u16) enc_key->key_len);
  611. memcpy(key_material->key_param_set.key, enc_key->key_material,
  612. enc_key->key_len);
  613. key_material->key_param_set.length =
  614. cpu_to_le16((u16) enc_key->key_len +
  615. KEYPARAMSET_FIXED_LEN);
  616. key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
  617. + sizeof(struct mwifiex_ie_types_header);
  618. if (le16_to_cpu(key_material->key_param_set.key_type_id) ==
  619. KEY_TYPE_ID_AES_CMAC) {
  620. struct mwifiex_cmac_param *param =
  621. (void *)key_material->key_param_set.key;
  622. memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN);
  623. memcpy(param->key, enc_key->key_material,
  624. WLAN_KEY_LEN_AES_CMAC);
  625. key_param_len = sizeof(struct mwifiex_cmac_param);
  626. key_material->key_param_set.key_len =
  627. cpu_to_le16(key_param_len);
  628. key_param_len += KEYPARAMSET_FIXED_LEN;
  629. key_material->key_param_set.length =
  630. cpu_to_le16(key_param_len);
  631. key_param_len += sizeof(struct mwifiex_ie_types_header);
  632. }
  633. cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
  634. + key_param_len);
  635. if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
  636. tlv_mac = (void *)((u8 *)&key_material->key_param_set +
  637. key_param_len);
  638. tlv_mac->header.type =
  639. cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
  640. tlv_mac->header.len = cpu_to_le16(ETH_ALEN);
  641. memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
  642. cmd_size = key_param_len + S_DS_GEN +
  643. sizeof(key_material->action) +
  644. sizeof(struct host_cmd_tlv_mac_addr);
  645. } else {
  646. cmd_size = key_param_len + S_DS_GEN +
  647. sizeof(key_material->action);
  648. }
  649. cmd->size = cpu_to_le16(cmd_size);
  650. }
  651. return ret;
  652. }
  653. /*
  654. * This function prepares command to set/get 11d domain information.
  655. *
  656. * Preparation includes -
  657. * - Setting command ID, action and proper size
  658. * - Setting domain information fields (for SET only)
  659. * - Ensuring correct endian-ness
  660. */
  661. static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
  662. struct host_cmd_ds_command *cmd,
  663. u16 cmd_action)
  664. {
  665. struct mwifiex_adapter *adapter = priv->adapter;
  666. struct host_cmd_ds_802_11d_domain_info *domain_info =
  667. &cmd->params.domain_info;
  668. struct mwifiex_ietypes_domain_param_set *domain =
  669. &domain_info->domain;
  670. u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
  671. dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
  672. cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
  673. domain_info->action = cpu_to_le16(cmd_action);
  674. if (cmd_action == HostCmd_ACT_GEN_GET) {
  675. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  676. return 0;
  677. }
  678. /* Set domain info fields */
  679. domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
  680. memcpy(domain->country_code, adapter->domain_reg.country_code,
  681. sizeof(domain->country_code));
  682. domain->header.len =
  683. cpu_to_le16((no_of_triplet *
  684. sizeof(struct ieee80211_country_ie_triplet))
  685. + sizeof(domain->country_code));
  686. if (no_of_triplet) {
  687. memcpy(domain->triplet, adapter->domain_reg.triplet,
  688. no_of_triplet * sizeof(struct
  689. ieee80211_country_ie_triplet));
  690. cmd->size = cpu_to_le16(sizeof(domain_info->action) +
  691. le16_to_cpu(domain->header.len) +
  692. sizeof(struct mwifiex_ie_types_header)
  693. + S_DS_GEN);
  694. } else {
  695. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  696. }
  697. return 0;
  698. }
  699. /*
  700. * This function prepares command to set/get IBSS coalescing status.
  701. *
  702. * Preparation includes -
  703. * - Setting command ID, action and proper size
  704. * - Setting status to enable or disable (for SET only)
  705. * - Ensuring correct endian-ness
  706. */
  707. static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
  708. u16 cmd_action, u16 *enable)
  709. {
  710. struct host_cmd_ds_802_11_ibss_status *ibss_coal =
  711. &(cmd->params.ibss_coalescing);
  712. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
  713. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
  714. S_DS_GEN);
  715. cmd->result = 0;
  716. ibss_coal->action = cpu_to_le16(cmd_action);
  717. switch (cmd_action) {
  718. case HostCmd_ACT_GEN_SET:
  719. if (enable)
  720. ibss_coal->enable = cpu_to_le16(*enable);
  721. else
  722. ibss_coal->enable = 0;
  723. break;
  724. /* In other case.. Nothing to do */
  725. case HostCmd_ACT_GEN_GET:
  726. default:
  727. break;
  728. }
  729. return 0;
  730. }
  731. /*
  732. * This function prepares command to set/get register value.
  733. *
  734. * Preparation includes -
  735. * - Setting command ID, action and proper size
  736. * - Setting register offset (for both GET and SET) and
  737. * register value (for SET only)
  738. * - Ensuring correct endian-ness
  739. *
  740. * The following type of registers can be accessed with this function -
  741. * - MAC register
  742. * - BBP register
  743. * - RF register
  744. * - PMIC register
  745. * - CAU register
  746. * - EEPROM
  747. */
  748. static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
  749. u16 cmd_action, void *data_buf)
  750. {
  751. struct mwifiex_ds_reg_rw *reg_rw = data_buf;
  752. switch (le16_to_cpu(cmd->command)) {
  753. case HostCmd_CMD_MAC_REG_ACCESS:
  754. {
  755. struct host_cmd_ds_mac_reg_access *mac_reg;
  756. cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
  757. mac_reg = &cmd->params.mac_reg;
  758. mac_reg->action = cpu_to_le16(cmd_action);
  759. mac_reg->offset =
  760. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  761. mac_reg->value = reg_rw->value;
  762. break;
  763. }
  764. case HostCmd_CMD_BBP_REG_ACCESS:
  765. {
  766. struct host_cmd_ds_bbp_reg_access *bbp_reg;
  767. cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
  768. bbp_reg = &cmd->params.bbp_reg;
  769. bbp_reg->action = cpu_to_le16(cmd_action);
  770. bbp_reg->offset =
  771. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  772. bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
  773. break;
  774. }
  775. case HostCmd_CMD_RF_REG_ACCESS:
  776. {
  777. struct host_cmd_ds_rf_reg_access *rf_reg;
  778. cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
  779. rf_reg = &cmd->params.rf_reg;
  780. rf_reg->action = cpu_to_le16(cmd_action);
  781. rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  782. rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
  783. break;
  784. }
  785. case HostCmd_CMD_PMIC_REG_ACCESS:
  786. {
  787. struct host_cmd_ds_pmic_reg_access *pmic_reg;
  788. cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
  789. pmic_reg = &cmd->params.pmic_reg;
  790. pmic_reg->action = cpu_to_le16(cmd_action);
  791. pmic_reg->offset =
  792. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  793. pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
  794. break;
  795. }
  796. case HostCmd_CMD_CAU_REG_ACCESS:
  797. {
  798. struct host_cmd_ds_rf_reg_access *cau_reg;
  799. cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
  800. cau_reg = &cmd->params.rf_reg;
  801. cau_reg->action = cpu_to_le16(cmd_action);
  802. cau_reg->offset =
  803. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  804. cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
  805. break;
  806. }
  807. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  808. {
  809. struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
  810. struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
  811. &cmd->params.eeprom;
  812. cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
  813. cmd_eeprom->action = cpu_to_le16(cmd_action);
  814. cmd_eeprom->offset = rd_eeprom->offset;
  815. cmd_eeprom->byte_count = rd_eeprom->byte_count;
  816. cmd_eeprom->value = 0;
  817. break;
  818. }
  819. default:
  820. return -1;
  821. }
  822. return 0;
  823. }
  824. /*
  825. * This function prepares command to set PCI-Express
  826. * host buffer configuration
  827. *
  828. * Preparation includes -
  829. * - Setting command ID, action and proper size
  830. * - Setting host buffer configuration
  831. * - Ensuring correct endian-ness
  832. */
  833. static int
  834. mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
  835. struct host_cmd_ds_command *cmd, u16 action)
  836. {
  837. struct host_cmd_ds_pcie_details *host_spec =
  838. &cmd->params.pcie_host_spec;
  839. struct pcie_service_card *card = priv->adapter->card;
  840. cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
  841. cmd->size = cpu_to_le16(sizeof(struct
  842. host_cmd_ds_pcie_details) + S_DS_GEN);
  843. cmd->result = 0;
  844. memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
  845. if (action != HostCmd_ACT_GEN_SET)
  846. return 0;
  847. /* Send the ring base addresses and count to firmware */
  848. host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
  849. host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
  850. host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
  851. host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
  852. host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
  853. host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
  854. host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
  855. host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
  856. host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
  857. if (card->sleep_cookie_vbase) {
  858. host_spec->sleep_cookie_addr_lo =
  859. (u32)(card->sleep_cookie_pbase);
  860. host_spec->sleep_cookie_addr_hi =
  861. (u32)(((u64)(card->sleep_cookie_pbase)) >> 32);
  862. dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
  863. host_spec->sleep_cookie_addr_lo);
  864. }
  865. return 0;
  866. }
  867. /*
  868. * This function prepares command for event subscription, configuration
  869. * and query. Events can be subscribed or unsubscribed. Current subscribed
  870. * events can be queried. Also, current subscribed events are reported in
  871. * every FW response.
  872. */
  873. static int
  874. mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
  875. struct host_cmd_ds_command *cmd,
  876. struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
  877. {
  878. struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
  879. struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
  880. u16 event_bitmap;
  881. u8 *pos;
  882. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
  883. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
  884. S_DS_GEN);
  885. subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
  886. dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
  887. /*For query requests, no configuration TLV structures are to be added.*/
  888. if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
  889. return 0;
  890. subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
  891. event_bitmap = subsc_evt_cfg->events;
  892. dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
  893. event_bitmap);
  894. if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
  895. (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
  896. (event_bitmap == 0)) {
  897. dev_dbg(priv->adapter->dev, "Error: No event specified "
  898. "for bitwise action type\n");
  899. return -EINVAL;
  900. }
  901. /*
  902. * Append TLV structures for each of the specified events for
  903. * subscribing or re-configuring. This is not required for
  904. * bitwise unsubscribing request.
  905. */
  906. if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
  907. return 0;
  908. pos = ((u8 *)subsc_evt) +
  909. sizeof(struct host_cmd_ds_802_11_subsc_evt);
  910. if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
  911. rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
  912. rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
  913. rssi_tlv->header.len =
  914. cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
  915. sizeof(struct mwifiex_ie_types_header));
  916. rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
  917. rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
  918. dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
  919. "RSSI:-%d dBm, Freq:%d\n",
  920. subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
  921. subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
  922. pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
  923. le16_add_cpu(&cmd->size,
  924. sizeof(struct mwifiex_ie_types_rssi_threshold));
  925. }
  926. if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
  927. rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
  928. rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
  929. rssi_tlv->header.len =
  930. cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
  931. sizeof(struct mwifiex_ie_types_header));
  932. rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
  933. rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
  934. dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
  935. "RSSI:-%d dBm, Freq:%d\n",
  936. subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
  937. subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
  938. pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
  939. le16_add_cpu(&cmd->size,
  940. sizeof(struct mwifiex_ie_types_rssi_threshold));
  941. }
  942. return 0;
  943. }
  944. static int
  945. mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv,
  946. struct mwifiex_mef_entry *mef_entry,
  947. u8 **buffer)
  948. {
  949. struct mwifiex_mef_filter *filter = mef_entry->filter;
  950. int i, byte_len;
  951. u8 *stack_ptr = *buffer;
  952. for (i = 0; i < MWIFIEX_MEF_MAX_FILTERS; i++) {
  953. filter = &mef_entry->filter[i];
  954. if (!filter->filt_type)
  955. break;
  956. *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->repeat);
  957. stack_ptr += 4;
  958. *stack_ptr = TYPE_DNUM;
  959. stack_ptr += 1;
  960. byte_len = filter->byte_seq[MWIFIEX_MEF_MAX_BYTESEQ];
  961. memcpy(stack_ptr, filter->byte_seq, byte_len);
  962. stack_ptr += byte_len;
  963. *stack_ptr = byte_len;
  964. stack_ptr += 1;
  965. *stack_ptr = TYPE_BYTESEQ;
  966. stack_ptr += 1;
  967. *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->offset);
  968. stack_ptr += 4;
  969. *stack_ptr = TYPE_DNUM;
  970. stack_ptr += 1;
  971. *stack_ptr = filter->filt_type;
  972. stack_ptr += 1;
  973. if (filter->filt_action) {
  974. *stack_ptr = filter->filt_action;
  975. stack_ptr += 1;
  976. }
  977. if (stack_ptr - *buffer > STACK_NBYTES)
  978. return -1;
  979. }
  980. *buffer = stack_ptr;
  981. return 0;
  982. }
  983. static int
  984. mwifiex_cmd_mef_cfg(struct mwifiex_private *priv,
  985. struct host_cmd_ds_command *cmd,
  986. struct mwifiex_ds_mef_cfg *mef)
  987. {
  988. struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg;
  989. u8 *pos = (u8 *)mef_cfg;
  990. cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG);
  991. mef_cfg->criteria = cpu_to_le32(mef->criteria);
  992. mef_cfg->num_entries = cpu_to_le16(mef->num_entries);
  993. pos += sizeof(*mef_cfg);
  994. mef_cfg->mef_entry->mode = mef->mef_entry->mode;
  995. mef_cfg->mef_entry->action = mef->mef_entry->action;
  996. pos += sizeof(*(mef_cfg->mef_entry));
  997. if (mwifiex_cmd_append_rpn_expression(priv, mef->mef_entry, &pos))
  998. return -1;
  999. mef_cfg->mef_entry->exprsize =
  1000. cpu_to_le16(pos - mef_cfg->mef_entry->expr);
  1001. cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN);
  1002. return 0;
  1003. }
  1004. /* This function parse cal data from ASCII to hex */
  1005. static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
  1006. {
  1007. u8 *s = src, *d = dst;
  1008. while (s - src < len) {
  1009. if (*s && (isspace(*s) || *s == '\t')) {
  1010. s++;
  1011. continue;
  1012. }
  1013. if (isxdigit(*s)) {
  1014. *d++ = simple_strtol(s, NULL, 16);
  1015. s += 2;
  1016. } else {
  1017. s++;
  1018. }
  1019. }
  1020. return d - dst;
  1021. }
  1022. int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
  1023. struct device_node *node, const char *prefix)
  1024. {
  1025. #ifdef CONFIG_OF
  1026. struct property *prop;
  1027. size_t len = strlen(prefix);
  1028. int ret;
  1029. /* look for all matching property names */
  1030. for_each_property_of_node(node, prop) {
  1031. if (len > strlen(prop->name) ||
  1032. strncmp(prop->name, prefix, len))
  1033. continue;
  1034. /* property header is 6 bytes, data must fit in cmd buffer */
  1035. if (prop && prop->value && prop->length > 6 &&
  1036. prop->length <= MWIFIEX_SIZE_OF_CMD_BUFFER - S_DS_GEN) {
  1037. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_CFG_DATA,
  1038. HostCmd_ACT_GEN_SET, 0,
  1039. prop);
  1040. if (ret)
  1041. return ret;
  1042. }
  1043. }
  1044. #endif
  1045. return 0;
  1046. }
  1047. /* This function prepares command of set_cfg_data. */
  1048. static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv,
  1049. struct host_cmd_ds_command *cmd, void *data_buf)
  1050. {
  1051. struct mwifiex_adapter *adapter = priv->adapter;
  1052. struct property *prop = data_buf;
  1053. u32 len;
  1054. u8 *data = (u8 *)cmd + S_DS_GEN;
  1055. int ret;
  1056. if (prop) {
  1057. len = prop->length;
  1058. ret = of_property_read_u8_array(adapter->dt_node, prop->name,
  1059. data, len);
  1060. if (ret)
  1061. return ret;
  1062. dev_dbg(adapter->dev,
  1063. "download cfg_data from device tree: %s\n", prop->name);
  1064. } else if (adapter->cal_data->data && adapter->cal_data->size > 0) {
  1065. len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data,
  1066. adapter->cal_data->size, data);
  1067. dev_dbg(adapter->dev, "download cfg_data from config file\n");
  1068. } else {
  1069. return -1;
  1070. }
  1071. cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA);
  1072. cmd->size = cpu_to_le16(S_DS_GEN + len);
  1073. return 0;
  1074. }
  1075. static int
  1076. mwifiex_cmd_coalesce_cfg(struct mwifiex_private *priv,
  1077. struct host_cmd_ds_command *cmd,
  1078. u16 cmd_action, void *data_buf)
  1079. {
  1080. struct host_cmd_ds_coalesce_cfg *coalesce_cfg =
  1081. &cmd->params.coalesce_cfg;
  1082. struct mwifiex_ds_coalesce_cfg *cfg = data_buf;
  1083. struct coalesce_filt_field_param *param;
  1084. u16 cnt, idx, length;
  1085. struct coalesce_receive_filt_rule *rule;
  1086. cmd->command = cpu_to_le16(HostCmd_CMD_COALESCE_CFG);
  1087. cmd->size = cpu_to_le16(S_DS_GEN);
  1088. coalesce_cfg->action = cpu_to_le16(cmd_action);
  1089. coalesce_cfg->num_of_rules = cpu_to_le16(cfg->num_of_rules);
  1090. rule = coalesce_cfg->rule;
  1091. for (cnt = 0; cnt < cfg->num_of_rules; cnt++) {
  1092. rule->header.type = cpu_to_le16(TLV_TYPE_COALESCE_RULE);
  1093. rule->max_coalescing_delay =
  1094. cpu_to_le16(cfg->rule[cnt].max_coalescing_delay);
  1095. rule->pkt_type = cfg->rule[cnt].pkt_type;
  1096. rule->num_of_fields = cfg->rule[cnt].num_of_fields;
  1097. length = 0;
  1098. param = rule->params;
  1099. for (idx = 0; idx < cfg->rule[cnt].num_of_fields; idx++) {
  1100. param->operation = cfg->rule[cnt].params[idx].operation;
  1101. param->operand_len =
  1102. cfg->rule[cnt].params[idx].operand_len;
  1103. param->offset =
  1104. cpu_to_le16(cfg->rule[cnt].params[idx].offset);
  1105. memcpy(param->operand_byte_stream,
  1106. cfg->rule[cnt].params[idx].operand_byte_stream,
  1107. param->operand_len);
  1108. length += sizeof(struct coalesce_filt_field_param);
  1109. param++;
  1110. }
  1111. /* Total rule length is sizeof max_coalescing_delay(u16),
  1112. * num_of_fields(u8), pkt_type(u8) and total length of the all
  1113. * params
  1114. */
  1115. rule->header.len = cpu_to_le16(length + sizeof(u16) +
  1116. sizeof(u8) + sizeof(u8));
  1117. /* Add the rule length to the command size*/
  1118. le16_add_cpu(&cmd->size, le16_to_cpu(rule->header.len) +
  1119. sizeof(struct mwifiex_ie_types_header));
  1120. rule = (void *)((u8 *)rule->params + length);
  1121. }
  1122. /* Add sizeof action, num_of_rules to total command length */
  1123. le16_add_cpu(&cmd->size, sizeof(u16) + sizeof(u16));
  1124. return 0;
  1125. }
  1126. /*
  1127. * This function prepares the commands before sending them to the firmware.
  1128. *
  1129. * This is a generic function which calls specific command preparation
  1130. * routines based upon the command number.
  1131. */
  1132. int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
  1133. u16 cmd_action, u32 cmd_oid,
  1134. void *data_buf, void *cmd_buf)
  1135. {
  1136. struct host_cmd_ds_command *cmd_ptr = cmd_buf;
  1137. int ret = 0;
  1138. /* Prepare command */
  1139. switch (cmd_no) {
  1140. case HostCmd_CMD_GET_HW_SPEC:
  1141. ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
  1142. break;
  1143. case HostCmd_CMD_CFG_DATA:
  1144. ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, data_buf);
  1145. break;
  1146. case HostCmd_CMD_MAC_CONTROL:
  1147. ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
  1148. data_buf);
  1149. break;
  1150. case HostCmd_CMD_802_11_MAC_ADDRESS:
  1151. ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
  1152. cmd_action);
  1153. break;
  1154. case HostCmd_CMD_MAC_MULTICAST_ADR:
  1155. ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
  1156. data_buf);
  1157. break;
  1158. case HostCmd_CMD_TX_RATE_CFG:
  1159. ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
  1160. data_buf);
  1161. break;
  1162. case HostCmd_CMD_TXPWR_CFG:
  1163. ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
  1164. data_buf);
  1165. break;
  1166. case HostCmd_CMD_RF_TX_PWR:
  1167. ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
  1168. data_buf);
  1169. break;
  1170. case HostCmd_CMD_RF_ANTENNA:
  1171. ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
  1172. data_buf);
  1173. break;
  1174. case HostCmd_CMD_802_11_PS_MODE_ENH:
  1175. ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
  1176. (uint16_t)cmd_oid, data_buf);
  1177. break;
  1178. case HostCmd_CMD_802_11_HS_CFG_ENH:
  1179. ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
  1180. (struct mwifiex_hs_config_param *) data_buf);
  1181. break;
  1182. case HostCmd_CMD_802_11_SCAN:
  1183. ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
  1184. break;
  1185. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  1186. ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
  1187. break;
  1188. case HostCmd_CMD_802_11_ASSOCIATE:
  1189. ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
  1190. break;
  1191. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  1192. ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
  1193. data_buf);
  1194. break;
  1195. case HostCmd_CMD_802_11_AD_HOC_START:
  1196. ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
  1197. data_buf);
  1198. break;
  1199. case HostCmd_CMD_802_11_GET_LOG:
  1200. ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
  1201. break;
  1202. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  1203. ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
  1204. data_buf);
  1205. break;
  1206. case HostCmd_CMD_802_11_AD_HOC_STOP:
  1207. ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
  1208. break;
  1209. case HostCmd_CMD_RSSI_INFO:
  1210. ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
  1211. break;
  1212. case HostCmd_CMD_802_11_SNMP_MIB:
  1213. ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
  1214. cmd_oid, data_buf);
  1215. break;
  1216. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  1217. cmd_ptr->command =
  1218. cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
  1219. cmd_ptr->size =
  1220. cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
  1221. S_DS_GEN);
  1222. priv->tx_rate = 0;
  1223. ret = 0;
  1224. break;
  1225. case HostCmd_CMD_VERSION_EXT:
  1226. cmd_ptr->command = cpu_to_le16(cmd_no);
  1227. cmd_ptr->params.verext.version_str_sel =
  1228. (u8) (*((u32 *) data_buf));
  1229. memcpy(&cmd_ptr->params, data_buf,
  1230. sizeof(struct host_cmd_ds_version_ext));
  1231. cmd_ptr->size =
  1232. cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
  1233. S_DS_GEN);
  1234. ret = 0;
  1235. break;
  1236. case HostCmd_CMD_MGMT_FRAME_REG:
  1237. cmd_ptr->command = cpu_to_le16(cmd_no);
  1238. cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action);
  1239. cmd_ptr->params.reg_mask.mask = cpu_to_le32(*(u32 *)data_buf);
  1240. cmd_ptr->size =
  1241. cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) +
  1242. S_DS_GEN);
  1243. ret = 0;
  1244. break;
  1245. case HostCmd_CMD_REMAIN_ON_CHAN:
  1246. cmd_ptr->command = cpu_to_le16(cmd_no);
  1247. memcpy(&cmd_ptr->params, data_buf,
  1248. sizeof(struct host_cmd_ds_remain_on_chan));
  1249. cmd_ptr->size =
  1250. cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) +
  1251. S_DS_GEN);
  1252. break;
  1253. case HostCmd_CMD_11AC_CFG:
  1254. ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf);
  1255. break;
  1256. case HostCmd_CMD_P2P_MODE_CFG:
  1257. cmd_ptr->command = cpu_to_le16(cmd_no);
  1258. cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action);
  1259. cmd_ptr->params.mode_cfg.mode = cpu_to_le16(*(u16 *)data_buf);
  1260. cmd_ptr->size =
  1261. cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) +
  1262. S_DS_GEN);
  1263. break;
  1264. case HostCmd_CMD_FUNC_INIT:
  1265. if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
  1266. priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  1267. cmd_ptr->command = cpu_to_le16(cmd_no);
  1268. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  1269. break;
  1270. case HostCmd_CMD_FUNC_SHUTDOWN:
  1271. priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
  1272. cmd_ptr->command = cpu_to_le16(cmd_no);
  1273. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  1274. break;
  1275. case HostCmd_CMD_11N_ADDBA_REQ:
  1276. ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
  1277. break;
  1278. case HostCmd_CMD_11N_DELBA:
  1279. ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
  1280. break;
  1281. case HostCmd_CMD_11N_ADDBA_RSP:
  1282. ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
  1283. break;
  1284. case HostCmd_CMD_802_11_KEY_MATERIAL:
  1285. ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
  1286. cmd_action, cmd_oid,
  1287. data_buf);
  1288. break;
  1289. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  1290. ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
  1291. cmd_action);
  1292. break;
  1293. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  1294. ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
  1295. data_buf);
  1296. break;
  1297. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  1298. ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
  1299. data_buf);
  1300. break;
  1301. case HostCmd_CMD_11N_CFG:
  1302. ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
  1303. break;
  1304. case HostCmd_CMD_WMM_GET_STATUS:
  1305. dev_dbg(priv->adapter->dev,
  1306. "cmd: WMM: WMM_GET_STATUS cmd sent\n");
  1307. cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
  1308. cmd_ptr->size =
  1309. cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
  1310. S_DS_GEN);
  1311. ret = 0;
  1312. break;
  1313. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  1314. ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
  1315. data_buf);
  1316. break;
  1317. case HostCmd_CMD_MAC_REG_ACCESS:
  1318. case HostCmd_CMD_BBP_REG_ACCESS:
  1319. case HostCmd_CMD_RF_REG_ACCESS:
  1320. case HostCmd_CMD_PMIC_REG_ACCESS:
  1321. case HostCmd_CMD_CAU_REG_ACCESS:
  1322. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  1323. ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
  1324. break;
  1325. case HostCmd_CMD_SET_BSS_MODE:
  1326. cmd_ptr->command = cpu_to_le16(cmd_no);
  1327. if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
  1328. cmd_ptr->params.bss_mode.con_type =
  1329. CONNECTION_TYPE_ADHOC;
  1330. else if (priv->bss_mode == NL80211_IFTYPE_STATION)
  1331. cmd_ptr->params.bss_mode.con_type =
  1332. CONNECTION_TYPE_INFRA;
  1333. else if (priv->bss_mode == NL80211_IFTYPE_AP)
  1334. cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP;
  1335. cmd_ptr->size = cpu_to_le16(sizeof(struct
  1336. host_cmd_ds_set_bss_mode) + S_DS_GEN);
  1337. ret = 0;
  1338. break;
  1339. case HostCmd_CMD_PCIE_DESC_DETAILS:
  1340. ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
  1341. break;
  1342. case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
  1343. ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
  1344. break;
  1345. case HostCmd_CMD_MEF_CFG:
  1346. ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf);
  1347. break;
  1348. case HostCmd_CMD_COALESCE_CFG:
  1349. ret = mwifiex_cmd_coalesce_cfg(priv, cmd_ptr, cmd_action,
  1350. data_buf);
  1351. break;
  1352. default:
  1353. dev_err(priv->adapter->dev,
  1354. "PREP_CMD: unknown cmd- %#x\n", cmd_no);
  1355. ret = -1;
  1356. break;
  1357. }
  1358. return ret;
  1359. }
  1360. /*
  1361. * This function issues commands to initialize firmware.
  1362. *
  1363. * This is called after firmware download to bring the card to
  1364. * working state.
  1365. *
  1366. * The following commands are issued sequentially -
  1367. * - Set PCI-Express host buffer configuration (PCIE only)
  1368. * - Function init (for first interface only)
  1369. * - Read MAC address (for first interface only)
  1370. * - Reconfigure Tx buffer size (for first interface only)
  1371. * - Enable auto deep sleep (for first interface only)
  1372. * - Get Tx rate
  1373. * - Get Tx power
  1374. * - Set IBSS coalescing status
  1375. * - Set AMSDU aggregation control
  1376. * - Set 11d control
  1377. * - Set MAC control (this must be the last command to initialize firmware)
  1378. */
  1379. int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
  1380. {
  1381. struct mwifiex_adapter *adapter = priv->adapter;
  1382. int ret;
  1383. u16 enable = true;
  1384. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  1385. struct mwifiex_ds_auto_ds auto_ds;
  1386. enum state_11d_t state_11d;
  1387. struct mwifiex_ds_11n_tx_cfg tx_cfg;
  1388. if (first_sta) {
  1389. if (priv->adapter->iface_type == MWIFIEX_PCIE) {
  1390. ret = mwifiex_send_cmd_sync(priv,
  1391. HostCmd_CMD_PCIE_DESC_DETAILS,
  1392. HostCmd_ACT_GEN_SET, 0, NULL);
  1393. if (ret)
  1394. return -1;
  1395. }
  1396. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_FUNC_INIT,
  1397. HostCmd_ACT_GEN_SET, 0, NULL);
  1398. if (ret)
  1399. return -1;
  1400. /* Download calibration data to firmware.
  1401. * The cal-data can be read from device tree and/or
  1402. * a configuration file and downloaded to firmware.
  1403. */
  1404. adapter->dt_node =
  1405. of_find_node_by_name(NULL, "marvell_cfgdata");
  1406. if (adapter->dt_node) {
  1407. ret = mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node,
  1408. "marvell,caldata");
  1409. if (ret)
  1410. return -1;
  1411. }
  1412. if (adapter->cal_data) {
  1413. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_CFG_DATA,
  1414. HostCmd_ACT_GEN_SET, 0, NULL);
  1415. if (ret)
  1416. return -1;
  1417. }
  1418. /* Read MAC address from HW */
  1419. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_GET_HW_SPEC,
  1420. HostCmd_ACT_GEN_GET, 0, NULL);
  1421. if (ret)
  1422. return -1;
  1423. /* Reconfigure tx buf size */
  1424. ret = mwifiex_send_cmd_sync(priv,
  1425. HostCmd_CMD_RECONFIGURE_TX_BUFF,
  1426. HostCmd_ACT_GEN_SET, 0,
  1427. &priv->adapter->tx_buf_size);
  1428. if (ret)
  1429. return -1;
  1430. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1431. /* Enable IEEE PS by default */
  1432. priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1433. ret = mwifiex_send_cmd_sync(
  1434. priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1435. EN_AUTO_PS, BITMAP_STA_PS, NULL);
  1436. if (ret)
  1437. return -1;
  1438. }
  1439. }
  1440. /* get tx rate */
  1441. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
  1442. HostCmd_ACT_GEN_GET, 0, NULL);
  1443. if (ret)
  1444. return -1;
  1445. priv->data_rate = 0;
  1446. /* get tx power */
  1447. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_TX_PWR,
  1448. HostCmd_ACT_GEN_GET, 0, NULL);
  1449. if (ret)
  1450. return -1;
  1451. if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
  1452. /* set ibss coalescing_status */
  1453. ret = mwifiex_send_cmd_sync(
  1454. priv, HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1455. HostCmd_ACT_GEN_SET, 0, &enable);
  1456. if (ret)
  1457. return -1;
  1458. }
  1459. memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
  1460. amsdu_aggr_ctrl.enable = true;
  1461. /* Send request to firmware */
  1462. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
  1463. HostCmd_ACT_GEN_SET, 0,
  1464. &amsdu_aggr_ctrl);
  1465. if (ret)
  1466. return -1;
  1467. /* MAC Control must be the last command in init_fw */
  1468. /* set MAC Control */
  1469. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
  1470. HostCmd_ACT_GEN_SET, 0,
  1471. &priv->curr_pkt_filter);
  1472. if (ret)
  1473. return -1;
  1474. if (first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
  1475. priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1476. /* Enable auto deep sleep */
  1477. auto_ds.auto_ds = DEEP_SLEEP_ON;
  1478. auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  1479. ret = mwifiex_send_cmd_sync(priv,
  1480. HostCmd_CMD_802_11_PS_MODE_ENH,
  1481. EN_AUTO_PS, BITMAP_AUTO_DS,
  1482. &auto_ds);
  1483. if (ret)
  1484. return -1;
  1485. }
  1486. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1487. /* Send cmd to FW to enable/disable 11D function */
  1488. state_11d = ENABLE_11D;
  1489. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1490. HostCmd_ACT_GEN_SET, DOT11D_I,
  1491. &state_11d);
  1492. if (ret)
  1493. dev_err(priv->adapter->dev,
  1494. "11D: failed to enable 11D\n");
  1495. }
  1496. /* set last_init_cmd before sending the command */
  1497. priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
  1498. /* Send cmd to FW to configure 11n specific configuration
  1499. * (Short GI, Channel BW, Green field support etc.) for transmit
  1500. */
  1501. tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
  1502. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_11N_CFG,
  1503. HostCmd_ACT_GEN_SET, 0, &tx_cfg);
  1504. ret = -EINPROGRESS;
  1505. return ret;
  1506. }