sta_cmd.c 44 KB

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