sta_cmd.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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. /*
  27. * This function prepares command to set/get RSSI information.
  28. *
  29. * Preparation includes -
  30. * - Setting command ID, action and proper size
  31. * - Setting data/beacon average factors
  32. * - Resetting SNR/NF/RSSI values in private structure
  33. * - Ensuring correct endian-ness
  34. */
  35. static int
  36. mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
  37. struct host_cmd_ds_command *cmd, u16 cmd_action)
  38. {
  39. cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
  40. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
  41. S_DS_GEN);
  42. cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
  43. cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
  44. cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
  45. /* Reset SNR/NF/RSSI values in private structure */
  46. priv->data_rssi_last = 0;
  47. priv->data_nf_last = 0;
  48. priv->data_rssi_avg = 0;
  49. priv->data_nf_avg = 0;
  50. priv->bcn_rssi_last = 0;
  51. priv->bcn_nf_last = 0;
  52. priv->bcn_rssi_avg = 0;
  53. priv->bcn_nf_avg = 0;
  54. return 0;
  55. }
  56. /*
  57. * This function prepares command to set MAC control.
  58. *
  59. * Preparation includes -
  60. * - Setting command ID, action and proper size
  61. * - Ensuring correct endian-ness
  62. */
  63. static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
  64. struct host_cmd_ds_command *cmd,
  65. u16 cmd_action, u16 *action)
  66. {
  67. struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
  68. if (cmd_action != HostCmd_ACT_GEN_SET) {
  69. dev_err(priv->adapter->dev,
  70. "mac_control: only support set cmd\n");
  71. return -1;
  72. }
  73. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
  74. cmd->size =
  75. cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
  76. mac_ctrl->action = cpu_to_le16(*action);
  77. return 0;
  78. }
  79. /*
  80. * This function prepares command to set/get SNMP MIB.
  81. *
  82. * Preparation includes -
  83. * - Setting command ID, action and proper size
  84. * - Setting SNMP MIB OID number and value
  85. * (as required)
  86. * - Ensuring correct endian-ness
  87. *
  88. * The following SNMP MIB OIDs are supported -
  89. * - FRAG_THRESH_I : Fragmentation threshold
  90. * - RTS_THRESH_I : RTS threshold
  91. * - SHORT_RETRY_LIM_I : Short retry limit
  92. * - DOT11D_I : 11d support
  93. */
  94. static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
  95. struct host_cmd_ds_command *cmd,
  96. u16 cmd_action, u32 cmd_oid,
  97. u32 *ul_temp)
  98. {
  99. struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
  100. dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
  101. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
  102. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
  103. - 1 + S_DS_GEN);
  104. if (cmd_action == HostCmd_ACT_GEN_GET) {
  105. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
  106. snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
  107. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  108. + MAX_SNMP_BUF_SIZE);
  109. }
  110. switch (cmd_oid) {
  111. case FRAG_THRESH_I:
  112. snmp_mib->oid = cpu_to_le16((u16) FRAG_THRESH_I);
  113. if (cmd_action == HostCmd_ACT_GEN_SET) {
  114. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  115. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  116. *((__le16 *) (snmp_mib->value)) =
  117. cpu_to_le16((u16) *ul_temp);
  118. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  119. + sizeof(u16));
  120. }
  121. break;
  122. case RTS_THRESH_I:
  123. snmp_mib->oid = cpu_to_le16((u16) RTS_THRESH_I);
  124. if (cmd_action == HostCmd_ACT_GEN_SET) {
  125. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  126. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  127. *(__le16 *) (snmp_mib->value) =
  128. cpu_to_le16((u16) *ul_temp);
  129. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  130. + sizeof(u16));
  131. }
  132. break;
  133. case SHORT_RETRY_LIM_I:
  134. snmp_mib->oid = cpu_to_le16((u16) SHORT_RETRY_LIM_I);
  135. if (cmd_action == HostCmd_ACT_GEN_SET) {
  136. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  137. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  138. *((__le16 *) (snmp_mib->value)) =
  139. cpu_to_le16((u16) *ul_temp);
  140. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  141. + sizeof(u16));
  142. }
  143. break;
  144. case DOT11D_I:
  145. snmp_mib->oid = cpu_to_le16((u16) DOT11D_I);
  146. if (cmd_action == HostCmd_ACT_GEN_SET) {
  147. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  148. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  149. *((__le16 *) (snmp_mib->value)) =
  150. cpu_to_le16((u16) *ul_temp);
  151. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  152. + sizeof(u16));
  153. }
  154. break;
  155. default:
  156. break;
  157. }
  158. dev_dbg(priv->adapter->dev,
  159. "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
  160. " Value=0x%x\n",
  161. cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
  162. le16_to_cpu(*(__le16 *) snmp_mib->value));
  163. return 0;
  164. }
  165. /*
  166. * This function prepares command to get log.
  167. *
  168. * Preparation includes -
  169. * - Setting command ID and proper size
  170. * - Ensuring correct endian-ness
  171. */
  172. static int
  173. mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
  174. {
  175. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
  176. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
  177. S_DS_GEN);
  178. return 0;
  179. }
  180. /*
  181. * This function prepares command to set/get Tx data rate configuration.
  182. *
  183. * Preparation includes -
  184. * - Setting command ID, action and proper size
  185. * - Setting configuration index, rate scope and rate drop pattern
  186. * parameters (as required)
  187. * - Ensuring correct endian-ness
  188. */
  189. static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
  190. struct host_cmd_ds_command *cmd,
  191. u16 cmd_action, u16 *pbitmap_rates)
  192. {
  193. struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
  194. struct mwifiex_rate_scope *rate_scope;
  195. struct mwifiex_rate_drop_pattern *rate_drop;
  196. u32 i;
  197. cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
  198. rate_cfg->action = cpu_to_le16(cmd_action);
  199. rate_cfg->cfg_index = 0;
  200. rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
  201. sizeof(struct host_cmd_ds_tx_rate_cfg));
  202. rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
  203. rate_scope->length = cpu_to_le16(sizeof(struct mwifiex_rate_scope) -
  204. sizeof(struct mwifiex_ie_types_header));
  205. if (pbitmap_rates != NULL) {
  206. rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
  207. rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
  208. for (i = 0;
  209. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  210. i++)
  211. rate_scope->ht_mcs_rate_bitmap[i] =
  212. cpu_to_le16(pbitmap_rates[2 + i]);
  213. } else {
  214. rate_scope->hr_dsss_rate_bitmap =
  215. cpu_to_le16(priv->bitmap_rates[0]);
  216. rate_scope->ofdm_rate_bitmap =
  217. cpu_to_le16(priv->bitmap_rates[1]);
  218. for (i = 0;
  219. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  220. i++)
  221. rate_scope->ht_mcs_rate_bitmap[i] =
  222. cpu_to_le16(priv->bitmap_rates[2 + i]);
  223. }
  224. rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
  225. sizeof(struct mwifiex_rate_scope));
  226. rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
  227. rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
  228. rate_drop->rate_drop_mode = 0;
  229. cmd->size =
  230. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
  231. sizeof(struct mwifiex_rate_scope) +
  232. sizeof(struct mwifiex_rate_drop_pattern));
  233. return 0;
  234. }
  235. /*
  236. * This function prepares command to set/get Tx power configuration.
  237. *
  238. * Preparation includes -
  239. * - Setting command ID, action and proper size
  240. * - Setting Tx power mode, power group TLV
  241. * (as required)
  242. * - Ensuring correct endian-ness
  243. */
  244. static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
  245. u16 cmd_action,
  246. struct host_cmd_ds_txpwr_cfg *txp)
  247. {
  248. struct mwifiex_types_power_group *pg_tlv;
  249. struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
  250. cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
  251. cmd->size =
  252. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
  253. switch (cmd_action) {
  254. case HostCmd_ACT_GEN_SET:
  255. if (txp->mode) {
  256. pg_tlv = (struct mwifiex_types_power_group
  257. *) ((unsigned long) txp +
  258. sizeof(struct host_cmd_ds_txpwr_cfg));
  259. memmove(cmd_txp_cfg, txp,
  260. sizeof(struct host_cmd_ds_txpwr_cfg) +
  261. sizeof(struct mwifiex_types_power_group) +
  262. pg_tlv->length);
  263. pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
  264. cmd_txp_cfg +
  265. sizeof(struct host_cmd_ds_txpwr_cfg));
  266. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
  267. sizeof(struct mwifiex_types_power_group) +
  268. pg_tlv->length);
  269. } else {
  270. memmove(cmd_txp_cfg, txp, sizeof(*txp));
  271. }
  272. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  273. break;
  274. case HostCmd_ACT_GEN_GET:
  275. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  276. break;
  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. u16 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
  304. != cpu_to_le32(HOST_SLEEP_CFG_CANCEL))
  305. && ((adapter->arp_filter_size > 0)
  306. && (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
  307. dev_dbg(adapter->dev,
  308. "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
  309. adapter->arp_filter_size);
  310. memcpy(((u8 *) hs_cfg) +
  311. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
  312. adapter->arp_filter, adapter->arp_filter_size);
  313. cmd->size = cpu_to_le16(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 = 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. u16 key_param_len = 0;
  498. int ret = 0;
  499. const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  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 (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
  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->wapi_rxpn, WAPI_RXPN_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(key_param_len +
  558. sizeof(key_material->action) + S_DS_GEN);
  559. return ret;
  560. }
  561. if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
  562. dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
  563. key_material->key_param_set.key_type_id =
  564. cpu_to_le16(KEY_TYPE_ID_AES);
  565. if (cmd_oid == KEY_INFO_ENABLED)
  566. key_material->key_param_set.key_info =
  567. cpu_to_le16(KEY_ENABLED);
  568. else
  569. key_material->key_param_set.key_info =
  570. cpu_to_le16(!KEY_ENABLED);
  571. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  572. /* AES pairwise key: unicast */
  573. key_material->key_param_set.key_info |=
  574. cpu_to_le16(KEY_UNICAST);
  575. else /* AES group key: multicast */
  576. key_material->key_param_set.key_info |=
  577. cpu_to_le16(KEY_MCAST);
  578. } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
  579. dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
  580. key_material->key_param_set.key_type_id =
  581. cpu_to_le16(KEY_TYPE_ID_TKIP);
  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. /* TKIP pairwise key: unicast */
  586. key_material->key_param_set.key_info |=
  587. cpu_to_le16(KEY_UNICAST);
  588. else /* TKIP group key: multicast */
  589. key_material->key_param_set.key_info |=
  590. cpu_to_le16(KEY_MCAST);
  591. }
  592. if (key_material->key_param_set.key_type_id) {
  593. key_material->key_param_set.type =
  594. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  595. key_material->key_param_set.key_len =
  596. cpu_to_le16((u16) enc_key->key_len);
  597. memcpy(key_material->key_param_set.key, enc_key->key_material,
  598. enc_key->key_len);
  599. key_material->key_param_set.length =
  600. cpu_to_le16((u16) enc_key->key_len +
  601. KEYPARAMSET_FIXED_LEN);
  602. key_param_len = (u16) (enc_key->key_len + KEYPARAMSET_FIXED_LEN)
  603. + sizeof(struct mwifiex_ie_types_header);
  604. cmd->size = cpu_to_le16(key_param_len +
  605. sizeof(key_material->action) + S_DS_GEN);
  606. }
  607. return ret;
  608. }
  609. /*
  610. * This function prepares command to set/get 11d domain information.
  611. *
  612. * Preparation includes -
  613. * - Setting command ID, action and proper size
  614. * - Setting domain information fields (for SET only)
  615. * - Ensuring correct endian-ness
  616. */
  617. static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
  618. struct host_cmd_ds_command *cmd,
  619. u16 cmd_action)
  620. {
  621. struct mwifiex_adapter *adapter = priv->adapter;
  622. struct host_cmd_ds_802_11d_domain_info *domain_info =
  623. &cmd->params.domain_info;
  624. struct mwifiex_ietypes_domain_param_set *domain =
  625. &domain_info->domain;
  626. u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
  627. dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
  628. cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
  629. domain_info->action = cpu_to_le16(cmd_action);
  630. if (cmd_action == HostCmd_ACT_GEN_GET) {
  631. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  632. return 0;
  633. }
  634. /* Set domain info fields */
  635. domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
  636. memcpy(domain->country_code, adapter->domain_reg.country_code,
  637. sizeof(domain->country_code));
  638. domain->header.len = cpu_to_le16((no_of_triplet *
  639. sizeof(struct ieee80211_country_ie_triplet)) +
  640. sizeof(domain->country_code));
  641. if (no_of_triplet) {
  642. memcpy(domain->triplet, adapter->domain_reg.triplet,
  643. no_of_triplet *
  644. sizeof(struct ieee80211_country_ie_triplet));
  645. cmd->size = cpu_to_le16(sizeof(domain_info->action) +
  646. le16_to_cpu(domain->header.len) +
  647. sizeof(struct mwifiex_ie_types_header)
  648. + S_DS_GEN);
  649. } else {
  650. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  651. }
  652. return 0;
  653. }
  654. /*
  655. * This function prepares command to set/get RF channel.
  656. *
  657. * Preparation includes -
  658. * - Setting command ID, action and proper size
  659. * - Setting RF type and current RF channel (for SET only)
  660. * - Ensuring correct endian-ness
  661. */
  662. static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv,
  663. struct host_cmd_ds_command *cmd,
  664. u16 cmd_action, u16 *channel)
  665. {
  666. struct host_cmd_ds_802_11_rf_channel *rf_chan =
  667. &cmd->params.rf_channel;
  668. uint16_t rf_type = le16_to_cpu(rf_chan->rf_type);
  669. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL);
  670. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel)
  671. + S_DS_GEN);
  672. if (cmd_action == HostCmd_ACT_GEN_SET) {
  673. if ((priv->adapter->adhoc_start_band & BAND_A)
  674. || (priv->adapter->adhoc_start_band & BAND_AN))
  675. rf_chan->rf_type =
  676. cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A);
  677. rf_type = le16_to_cpu(rf_chan->rf_type);
  678. SET_SECONDARYCHAN(rf_type, priv->adapter->chan_offset);
  679. rf_chan->current_channel = cpu_to_le16(*channel);
  680. }
  681. rf_chan->action = cpu_to_le16(cmd_action);
  682. return 0;
  683. }
  684. /*
  685. * This function prepares command to set/get IBSS coalescing status.
  686. *
  687. * Preparation includes -
  688. * - Setting command ID, action and proper size
  689. * - Setting status to enable or disable (for SET only)
  690. * - Ensuring correct endian-ness
  691. */
  692. static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
  693. u16 cmd_action, u16 *enable)
  694. {
  695. struct host_cmd_ds_802_11_ibss_status *ibss_coal =
  696. &(cmd->params.ibss_coalescing);
  697. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
  698. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
  699. S_DS_GEN);
  700. cmd->result = 0;
  701. ibss_coal->action = cpu_to_le16(cmd_action);
  702. switch (cmd_action) {
  703. case HostCmd_ACT_GEN_SET:
  704. if (enable)
  705. ibss_coal->enable = cpu_to_le16(*enable);
  706. break;
  707. /* In other case.. Nothing to do */
  708. case HostCmd_ACT_GEN_GET:
  709. default:
  710. break;
  711. }
  712. return 0;
  713. }
  714. /*
  715. * This function prepares command to set/get register value.
  716. *
  717. * Preparation includes -
  718. * - Setting command ID, action and proper size
  719. * - Setting register offset (for both GET and SET) and
  720. * register value (for SET only)
  721. * - Ensuring correct endian-ness
  722. *
  723. * The following type of registers can be accessed with this function -
  724. * - MAC register
  725. * - BBP register
  726. * - RF register
  727. * - PMIC register
  728. * - CAU register
  729. * - EEPROM
  730. */
  731. static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
  732. u16 cmd_action, void *data_buf)
  733. {
  734. struct mwifiex_ds_reg_rw *reg_rw = data_buf;
  735. switch (le16_to_cpu(cmd->command)) {
  736. case HostCmd_CMD_MAC_REG_ACCESS:
  737. {
  738. struct host_cmd_ds_mac_reg_access *mac_reg;
  739. cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
  740. mac_reg = (struct host_cmd_ds_mac_reg_access *) &cmd->
  741. params.mac_reg;
  742. mac_reg->action = cpu_to_le16(cmd_action);
  743. mac_reg->offset =
  744. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  745. mac_reg->value = reg_rw->value;
  746. break;
  747. }
  748. case HostCmd_CMD_BBP_REG_ACCESS:
  749. {
  750. struct host_cmd_ds_bbp_reg_access *bbp_reg;
  751. cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
  752. bbp_reg = (struct host_cmd_ds_bbp_reg_access *) &cmd->
  753. params.bbp_reg;
  754. bbp_reg->action = cpu_to_le16(cmd_action);
  755. bbp_reg->offset =
  756. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  757. bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
  758. break;
  759. }
  760. case HostCmd_CMD_RF_REG_ACCESS:
  761. {
  762. struct host_cmd_ds_rf_reg_access *rf_reg;
  763. cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
  764. rf_reg = (struct host_cmd_ds_rf_reg_access *) &cmd->
  765. params.rf_reg;
  766. rf_reg->action = cpu_to_le16(cmd_action);
  767. rf_reg->offset =
  768. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  769. rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
  770. break;
  771. }
  772. case HostCmd_CMD_PMIC_REG_ACCESS:
  773. {
  774. struct host_cmd_ds_pmic_reg_access *pmic_reg;
  775. cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
  776. pmic_reg = (struct host_cmd_ds_pmic_reg_access *) &cmd->
  777. params.pmic_reg;
  778. pmic_reg->action = cpu_to_le16(cmd_action);
  779. pmic_reg->offset =
  780. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  781. pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
  782. break;
  783. }
  784. case HostCmd_CMD_CAU_REG_ACCESS:
  785. {
  786. struct host_cmd_ds_rf_reg_access *cau_reg;
  787. cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
  788. cau_reg = (struct host_cmd_ds_rf_reg_access *) &cmd->
  789. params.rf_reg;
  790. cau_reg->action = cpu_to_le16(cmd_action);
  791. cau_reg->offset =
  792. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  793. cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
  794. break;
  795. }
  796. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  797. {
  798. struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
  799. struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
  800. (struct host_cmd_ds_802_11_eeprom_access *)
  801. &cmd->params.eeprom;
  802. cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
  803. cmd_eeprom->action = cpu_to_le16(cmd_action);
  804. cmd_eeprom->offset = rd_eeprom->offset;
  805. cmd_eeprom->byte_count = rd_eeprom->byte_count;
  806. cmd_eeprom->value = 0;
  807. break;
  808. }
  809. default:
  810. return -1;
  811. }
  812. return 0;
  813. }
  814. /*
  815. * This function prepares the commands before sending them to the firmware.
  816. *
  817. * This is a generic function which calls specific command preparation
  818. * routines based upon the command number.
  819. */
  820. int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
  821. u16 cmd_action, u32 cmd_oid,
  822. void *data_buf, void *cmd_buf)
  823. {
  824. struct host_cmd_ds_command *cmd_ptr = cmd_buf;
  825. int ret = 0;
  826. /* Prepare command */
  827. switch (cmd_no) {
  828. case HostCmd_CMD_GET_HW_SPEC:
  829. ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
  830. break;
  831. case HostCmd_CMD_MAC_CONTROL:
  832. ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
  833. data_buf);
  834. break;
  835. case HostCmd_CMD_802_11_MAC_ADDRESS:
  836. ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
  837. cmd_action);
  838. break;
  839. case HostCmd_CMD_MAC_MULTICAST_ADR:
  840. ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
  841. data_buf);
  842. break;
  843. case HostCmd_CMD_TX_RATE_CFG:
  844. ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
  845. data_buf);
  846. break;
  847. case HostCmd_CMD_TXPWR_CFG:
  848. ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
  849. data_buf);
  850. break;
  851. case HostCmd_CMD_802_11_PS_MODE_ENH:
  852. ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
  853. (uint16_t)cmd_oid, data_buf);
  854. break;
  855. case HostCmd_CMD_802_11_HS_CFG_ENH:
  856. ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
  857. (struct mwifiex_hs_config_param *) data_buf);
  858. break;
  859. case HostCmd_CMD_802_11_SCAN:
  860. ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
  861. break;
  862. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  863. ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
  864. break;
  865. case HostCmd_CMD_802_11_ASSOCIATE:
  866. ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
  867. break;
  868. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  869. ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
  870. data_buf);
  871. break;
  872. case HostCmd_CMD_802_11_AD_HOC_START:
  873. ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
  874. data_buf);
  875. break;
  876. case HostCmd_CMD_802_11_GET_LOG:
  877. ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
  878. break;
  879. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  880. ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
  881. data_buf);
  882. break;
  883. case HostCmd_CMD_802_11_AD_HOC_STOP:
  884. ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
  885. break;
  886. case HostCmd_CMD_RSSI_INFO:
  887. ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
  888. break;
  889. case HostCmd_CMD_802_11_SNMP_MIB:
  890. ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
  891. cmd_oid, data_buf);
  892. break;
  893. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  894. cmd_ptr->command =
  895. cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
  896. cmd_ptr->size =
  897. cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
  898. S_DS_GEN);
  899. priv->tx_rate = 0;
  900. ret = 0;
  901. break;
  902. case HostCmd_CMD_VERSION_EXT:
  903. cmd_ptr->command = cpu_to_le16(cmd_no);
  904. cmd_ptr->params.verext.version_str_sel =
  905. (u8) (*((u32 *) data_buf));
  906. memcpy(&cmd_ptr->params, data_buf,
  907. sizeof(struct host_cmd_ds_version_ext));
  908. cmd_ptr->size =
  909. cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
  910. S_DS_GEN);
  911. ret = 0;
  912. break;
  913. case HostCmd_CMD_802_11_RF_CHANNEL:
  914. ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action,
  915. data_buf);
  916. break;
  917. case HostCmd_CMD_FUNC_INIT:
  918. if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
  919. priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  920. cmd_ptr->command = cpu_to_le16(cmd_no);
  921. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  922. break;
  923. case HostCmd_CMD_FUNC_SHUTDOWN:
  924. priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
  925. cmd_ptr->command = cpu_to_le16(cmd_no);
  926. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  927. break;
  928. case HostCmd_CMD_11N_ADDBA_REQ:
  929. ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
  930. break;
  931. case HostCmd_CMD_11N_DELBA:
  932. ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
  933. break;
  934. case HostCmd_CMD_11N_ADDBA_RSP:
  935. ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
  936. break;
  937. case HostCmd_CMD_802_11_KEY_MATERIAL:
  938. ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
  939. cmd_action, cmd_oid,
  940. data_buf);
  941. break;
  942. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  943. ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
  944. cmd_action);
  945. break;
  946. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  947. ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
  948. data_buf);
  949. break;
  950. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  951. ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
  952. data_buf);
  953. break;
  954. case HostCmd_CMD_11N_CFG:
  955. ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action,
  956. data_buf);
  957. break;
  958. case HostCmd_CMD_WMM_GET_STATUS:
  959. dev_dbg(priv->adapter->dev,
  960. "cmd: WMM: WMM_GET_STATUS cmd sent\n");
  961. cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
  962. cmd_ptr->size =
  963. cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
  964. S_DS_GEN);
  965. ret = 0;
  966. break;
  967. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  968. ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
  969. data_buf);
  970. break;
  971. case HostCmd_CMD_MAC_REG_ACCESS:
  972. case HostCmd_CMD_BBP_REG_ACCESS:
  973. case HostCmd_CMD_RF_REG_ACCESS:
  974. case HostCmd_CMD_PMIC_REG_ACCESS:
  975. case HostCmd_CMD_CAU_REG_ACCESS:
  976. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  977. ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
  978. break;
  979. case HostCmd_CMD_SET_BSS_MODE:
  980. cmd_ptr->command = cpu_to_le16(cmd_no);
  981. if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
  982. cmd_ptr->params.bss_mode.con_type =
  983. CONNECTION_TYPE_ADHOC;
  984. else if (priv->bss_mode == NL80211_IFTYPE_STATION)
  985. cmd_ptr->params.bss_mode.con_type =
  986. CONNECTION_TYPE_INFRA;
  987. cmd_ptr->size = cpu_to_le16(sizeof(struct
  988. host_cmd_ds_set_bss_mode) + S_DS_GEN);
  989. ret = 0;
  990. break;
  991. default:
  992. dev_err(priv->adapter->dev,
  993. "PREP_CMD: unknown cmd- %#x\n", cmd_no);
  994. ret = -1;
  995. break;
  996. }
  997. return ret;
  998. }
  999. /*
  1000. * This function issues commands to initialize firmware.
  1001. *
  1002. * This is called after firmware download to bring the card to
  1003. * working state.
  1004. *
  1005. * The following commands are issued sequentially -
  1006. * - Function init (for first interface only)
  1007. * - Read MAC address (for first interface only)
  1008. * - Reconfigure Tx buffer size (for first interface only)
  1009. * - Enable auto deep sleep (for first interface only)
  1010. * - Get Tx rate
  1011. * - Get Tx power
  1012. * - Set IBSS coalescing status
  1013. * - Set AMSDU aggregation control
  1014. * - Set 11d control
  1015. * - Set MAC control (this must be the last command to initialize firmware)
  1016. */
  1017. int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
  1018. {
  1019. int ret;
  1020. u16 enable = true;
  1021. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  1022. struct mwifiex_ds_auto_ds auto_ds;
  1023. enum state_11d_t state_11d;
  1024. if (first_sta) {
  1025. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
  1026. HostCmd_ACT_GEN_SET, 0, NULL);
  1027. if (ret)
  1028. return -1;
  1029. /* Read MAC address from HW */
  1030. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
  1031. HostCmd_ACT_GEN_GET, 0, NULL);
  1032. if (ret)
  1033. return -1;
  1034. /* Reconfigure tx buf size */
  1035. ret = mwifiex_send_cmd_async(priv,
  1036. HostCmd_CMD_RECONFIGURE_TX_BUFF,
  1037. HostCmd_ACT_GEN_SET, 0,
  1038. &priv->adapter->tx_buf_size);
  1039. if (ret)
  1040. return -1;
  1041. /* Enable IEEE PS by default */
  1042. priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1043. ret = mwifiex_send_cmd_async(priv,
  1044. HostCmd_CMD_802_11_PS_MODE_ENH,
  1045. EN_AUTO_PS, BITMAP_STA_PS, NULL);
  1046. if (ret)
  1047. return -1;
  1048. }
  1049. /* get tx rate */
  1050. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
  1051. HostCmd_ACT_GEN_GET, 0, NULL);
  1052. if (ret)
  1053. return -1;
  1054. priv->data_rate = 0;
  1055. /* get tx power */
  1056. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TXPWR_CFG,
  1057. HostCmd_ACT_GEN_GET, 0, NULL);
  1058. if (ret)
  1059. return -1;
  1060. /* set ibss coalescing_status */
  1061. ret = mwifiex_send_cmd_async(priv,
  1062. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1063. HostCmd_ACT_GEN_SET, 0, &enable);
  1064. if (ret)
  1065. return -1;
  1066. memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
  1067. amsdu_aggr_ctrl.enable = true;
  1068. /* Send request to firmware */
  1069. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
  1070. HostCmd_ACT_GEN_SET, 0,
  1071. &amsdu_aggr_ctrl);
  1072. if (ret)
  1073. return -1;
  1074. /* MAC Control must be the last command in init_fw */
  1075. /* set MAC Control */
  1076. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  1077. HostCmd_ACT_GEN_SET, 0,
  1078. &priv->curr_pkt_filter);
  1079. if (ret)
  1080. return -1;
  1081. if (first_sta) {
  1082. /* Enable auto deep sleep */
  1083. auto_ds.auto_ds = DEEP_SLEEP_ON;
  1084. auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  1085. ret = mwifiex_send_cmd_async(priv,
  1086. HostCmd_CMD_802_11_PS_MODE_ENH,
  1087. EN_AUTO_PS, BITMAP_AUTO_DS,
  1088. &auto_ds);
  1089. if (ret)
  1090. return -1;
  1091. }
  1092. /* Send cmd to FW to enable/disable 11D function */
  1093. state_11d = ENABLE_11D;
  1094. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1095. HostCmd_ACT_GEN_SET, DOT11D_I, &state_11d);
  1096. if (ret)
  1097. dev_err(priv->adapter->dev, "11D: failed to enable 11D\n");
  1098. /* set last_init_cmd */
  1099. priv->adapter->last_init_cmd = HostCmd_CMD_802_11_SNMP_MIB;
  1100. ret = -EINPROGRESS;
  1101. return ret;
  1102. }