sta_cmd.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  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. else
  707. ibss_coal->enable = 0;
  708. break;
  709. /* In other case.. Nothing to do */
  710. case HostCmd_ACT_GEN_GET:
  711. default:
  712. break;
  713. }
  714. return 0;
  715. }
  716. /*
  717. * This function prepares command to set/get register value.
  718. *
  719. * Preparation includes -
  720. * - Setting command ID, action and proper size
  721. * - Setting register offset (for both GET and SET) and
  722. * register value (for SET only)
  723. * - Ensuring correct endian-ness
  724. *
  725. * The following type of registers can be accessed with this function -
  726. * - MAC register
  727. * - BBP register
  728. * - RF register
  729. * - PMIC register
  730. * - CAU register
  731. * - EEPROM
  732. */
  733. static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
  734. u16 cmd_action, void *data_buf)
  735. {
  736. struct mwifiex_ds_reg_rw *reg_rw = data_buf;
  737. switch (le16_to_cpu(cmd->command)) {
  738. case HostCmd_CMD_MAC_REG_ACCESS:
  739. {
  740. struct host_cmd_ds_mac_reg_access *mac_reg;
  741. cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
  742. mac_reg = (struct host_cmd_ds_mac_reg_access *) &cmd->
  743. params.mac_reg;
  744. mac_reg->action = cpu_to_le16(cmd_action);
  745. mac_reg->offset =
  746. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  747. mac_reg->value = reg_rw->value;
  748. break;
  749. }
  750. case HostCmd_CMD_BBP_REG_ACCESS:
  751. {
  752. struct host_cmd_ds_bbp_reg_access *bbp_reg;
  753. cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
  754. bbp_reg = (struct host_cmd_ds_bbp_reg_access *) &cmd->
  755. params.bbp_reg;
  756. bbp_reg->action = cpu_to_le16(cmd_action);
  757. bbp_reg->offset =
  758. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  759. bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
  760. break;
  761. }
  762. case HostCmd_CMD_RF_REG_ACCESS:
  763. {
  764. struct host_cmd_ds_rf_reg_access *rf_reg;
  765. cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
  766. rf_reg = (struct host_cmd_ds_rf_reg_access *) &cmd->
  767. params.rf_reg;
  768. rf_reg->action = cpu_to_le16(cmd_action);
  769. rf_reg->offset =
  770. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  771. rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
  772. break;
  773. }
  774. case HostCmd_CMD_PMIC_REG_ACCESS:
  775. {
  776. struct host_cmd_ds_pmic_reg_access *pmic_reg;
  777. cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
  778. pmic_reg = (struct host_cmd_ds_pmic_reg_access *) &cmd->
  779. params.pmic_reg;
  780. pmic_reg->action = cpu_to_le16(cmd_action);
  781. pmic_reg->offset =
  782. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  783. pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
  784. break;
  785. }
  786. case HostCmd_CMD_CAU_REG_ACCESS:
  787. {
  788. struct host_cmd_ds_rf_reg_access *cau_reg;
  789. cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
  790. cau_reg = (struct host_cmd_ds_rf_reg_access *) &cmd->
  791. params.rf_reg;
  792. cau_reg->action = cpu_to_le16(cmd_action);
  793. cau_reg->offset =
  794. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  795. cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
  796. break;
  797. }
  798. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  799. {
  800. struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
  801. struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
  802. (struct host_cmd_ds_802_11_eeprom_access *)
  803. &cmd->params.eeprom;
  804. cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
  805. cmd_eeprom->action = cpu_to_le16(cmd_action);
  806. cmd_eeprom->offset = rd_eeprom->offset;
  807. cmd_eeprom->byte_count = rd_eeprom->byte_count;
  808. cmd_eeprom->value = 0;
  809. break;
  810. }
  811. default:
  812. return -1;
  813. }
  814. return 0;
  815. }
  816. /*
  817. * This function prepares command to set PCI-Express
  818. * host buffer configuration
  819. *
  820. * Preparation includes -
  821. * - Setting command ID, action and proper size
  822. * - Setting host buffer configuration
  823. * - Ensuring correct endian-ness
  824. */
  825. static int
  826. mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
  827. struct host_cmd_ds_command *cmd, u16 action)
  828. {
  829. struct host_cmd_ds_pcie_details *host_spec =
  830. &cmd->params.pcie_host_spec;
  831. struct pcie_service_card *card = priv->adapter->card;
  832. phys_addr_t *buf_pa;
  833. cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
  834. cmd->size = cpu_to_le16(sizeof(struct
  835. host_cmd_ds_pcie_details) + S_DS_GEN);
  836. cmd->result = 0;
  837. memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
  838. if (action == HostCmd_ACT_GEN_SET) {
  839. /* Send the ring base addresses and count to firmware */
  840. host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
  841. host_spec->txbd_addr_hi =
  842. (u32)(((u64)card->txbd_ring_pbase)>>32);
  843. host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
  844. host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
  845. host_spec->rxbd_addr_hi =
  846. (u32)(((u64)card->rxbd_ring_pbase)>>32);
  847. host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
  848. host_spec->evtbd_addr_lo =
  849. (u32)(card->evtbd_ring_pbase);
  850. host_spec->evtbd_addr_hi =
  851. (u32)(((u64)card->evtbd_ring_pbase)>>32);
  852. host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
  853. if (card->sleep_cookie) {
  854. buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie);
  855. host_spec->sleep_cookie_addr_lo = (u32) *buf_pa;
  856. host_spec->sleep_cookie_addr_hi =
  857. (u32) (((u64)*buf_pa) >> 32);
  858. dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: "
  859. "0x%x\n", host_spec->sleep_cookie_addr_lo);
  860. }
  861. }
  862. return 0;
  863. }
  864. /*
  865. * This function prepares the commands before sending them to the firmware.
  866. *
  867. * This is a generic function which calls specific command preparation
  868. * routines based upon the command number.
  869. */
  870. int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
  871. u16 cmd_action, u32 cmd_oid,
  872. void *data_buf, void *cmd_buf)
  873. {
  874. struct host_cmd_ds_command *cmd_ptr = cmd_buf;
  875. int ret = 0;
  876. /* Prepare command */
  877. switch (cmd_no) {
  878. case HostCmd_CMD_GET_HW_SPEC:
  879. ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
  880. break;
  881. case HostCmd_CMD_MAC_CONTROL:
  882. ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
  883. data_buf);
  884. break;
  885. case HostCmd_CMD_802_11_MAC_ADDRESS:
  886. ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
  887. cmd_action);
  888. break;
  889. case HostCmd_CMD_MAC_MULTICAST_ADR:
  890. ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
  891. data_buf);
  892. break;
  893. case HostCmd_CMD_TX_RATE_CFG:
  894. ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
  895. data_buf);
  896. break;
  897. case HostCmd_CMD_TXPWR_CFG:
  898. ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
  899. data_buf);
  900. break;
  901. case HostCmd_CMD_802_11_PS_MODE_ENH:
  902. ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
  903. (uint16_t)cmd_oid, data_buf);
  904. break;
  905. case HostCmd_CMD_802_11_HS_CFG_ENH:
  906. ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
  907. (struct mwifiex_hs_config_param *) data_buf);
  908. break;
  909. case HostCmd_CMD_802_11_SCAN:
  910. ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
  911. break;
  912. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  913. ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
  914. break;
  915. case HostCmd_CMD_802_11_ASSOCIATE:
  916. ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
  917. break;
  918. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  919. ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
  920. data_buf);
  921. break;
  922. case HostCmd_CMD_802_11_AD_HOC_START:
  923. ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
  924. data_buf);
  925. break;
  926. case HostCmd_CMD_802_11_GET_LOG:
  927. ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
  928. break;
  929. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  930. ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
  931. data_buf);
  932. break;
  933. case HostCmd_CMD_802_11_AD_HOC_STOP:
  934. ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
  935. break;
  936. case HostCmd_CMD_RSSI_INFO:
  937. ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
  938. break;
  939. case HostCmd_CMD_802_11_SNMP_MIB:
  940. ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
  941. cmd_oid, data_buf);
  942. break;
  943. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  944. cmd_ptr->command =
  945. cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
  946. cmd_ptr->size =
  947. cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
  948. S_DS_GEN);
  949. priv->tx_rate = 0;
  950. ret = 0;
  951. break;
  952. case HostCmd_CMD_VERSION_EXT:
  953. cmd_ptr->command = cpu_to_le16(cmd_no);
  954. cmd_ptr->params.verext.version_str_sel =
  955. (u8) (*((u32 *) data_buf));
  956. memcpy(&cmd_ptr->params, data_buf,
  957. sizeof(struct host_cmd_ds_version_ext));
  958. cmd_ptr->size =
  959. cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
  960. S_DS_GEN);
  961. ret = 0;
  962. break;
  963. case HostCmd_CMD_802_11_RF_CHANNEL:
  964. ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action,
  965. data_buf);
  966. break;
  967. case HostCmd_CMD_FUNC_INIT:
  968. if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
  969. priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  970. cmd_ptr->command = cpu_to_le16(cmd_no);
  971. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  972. break;
  973. case HostCmd_CMD_FUNC_SHUTDOWN:
  974. priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
  975. cmd_ptr->command = cpu_to_le16(cmd_no);
  976. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  977. break;
  978. case HostCmd_CMD_11N_ADDBA_REQ:
  979. ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
  980. break;
  981. case HostCmd_CMD_11N_DELBA:
  982. ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
  983. break;
  984. case HostCmd_CMD_11N_ADDBA_RSP:
  985. ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
  986. break;
  987. case HostCmd_CMD_802_11_KEY_MATERIAL:
  988. ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
  989. cmd_action, cmd_oid,
  990. data_buf);
  991. break;
  992. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  993. ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
  994. cmd_action);
  995. break;
  996. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  997. ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
  998. data_buf);
  999. break;
  1000. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  1001. ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
  1002. data_buf);
  1003. break;
  1004. case HostCmd_CMD_11N_CFG:
  1005. ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action,
  1006. data_buf);
  1007. break;
  1008. case HostCmd_CMD_WMM_GET_STATUS:
  1009. dev_dbg(priv->adapter->dev,
  1010. "cmd: WMM: WMM_GET_STATUS cmd sent\n");
  1011. cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
  1012. cmd_ptr->size =
  1013. cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
  1014. S_DS_GEN);
  1015. ret = 0;
  1016. break;
  1017. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  1018. ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
  1019. data_buf);
  1020. break;
  1021. case HostCmd_CMD_MAC_REG_ACCESS:
  1022. case HostCmd_CMD_BBP_REG_ACCESS:
  1023. case HostCmd_CMD_RF_REG_ACCESS:
  1024. case HostCmd_CMD_PMIC_REG_ACCESS:
  1025. case HostCmd_CMD_CAU_REG_ACCESS:
  1026. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  1027. ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
  1028. break;
  1029. case HostCmd_CMD_SET_BSS_MODE:
  1030. cmd_ptr->command = cpu_to_le16(cmd_no);
  1031. if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
  1032. cmd_ptr->params.bss_mode.con_type =
  1033. CONNECTION_TYPE_ADHOC;
  1034. else if (priv->bss_mode == NL80211_IFTYPE_STATION)
  1035. cmd_ptr->params.bss_mode.con_type =
  1036. CONNECTION_TYPE_INFRA;
  1037. cmd_ptr->size = cpu_to_le16(sizeof(struct
  1038. host_cmd_ds_set_bss_mode) + S_DS_GEN);
  1039. ret = 0;
  1040. break;
  1041. case HostCmd_CMD_PCIE_DESC_DETAILS:
  1042. ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
  1043. break;
  1044. default:
  1045. dev_err(priv->adapter->dev,
  1046. "PREP_CMD: unknown cmd- %#x\n", cmd_no);
  1047. ret = -1;
  1048. break;
  1049. }
  1050. return ret;
  1051. }
  1052. /*
  1053. * This function issues commands to initialize firmware.
  1054. *
  1055. * This is called after firmware download to bring the card to
  1056. * working state.
  1057. *
  1058. * The following commands are issued sequentially -
  1059. * - Set PCI-Express host buffer configuration (PCIE only)
  1060. * - Function init (for first interface only)
  1061. * - Read MAC address (for first interface only)
  1062. * - Reconfigure Tx buffer size (for first interface only)
  1063. * - Enable auto deep sleep (for first interface only)
  1064. * - Get Tx rate
  1065. * - Get Tx power
  1066. * - Set IBSS coalescing status
  1067. * - Set AMSDU aggregation control
  1068. * - Set 11d control
  1069. * - Set MAC control (this must be the last command to initialize firmware)
  1070. */
  1071. int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
  1072. {
  1073. int ret;
  1074. u16 enable = true;
  1075. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  1076. struct mwifiex_ds_auto_ds auto_ds;
  1077. enum state_11d_t state_11d;
  1078. struct mwifiex_ds_11n_tx_cfg tx_cfg;
  1079. if (first_sta) {
  1080. if (priv->adapter->iface_type == MWIFIEX_PCIE) {
  1081. ret = mwifiex_send_cmd_async(priv,
  1082. HostCmd_CMD_PCIE_DESC_DETAILS,
  1083. HostCmd_ACT_GEN_SET, 0, NULL);
  1084. if (ret)
  1085. return -1;
  1086. }
  1087. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
  1088. HostCmd_ACT_GEN_SET, 0, NULL);
  1089. if (ret)
  1090. return -1;
  1091. /* Read MAC address from HW */
  1092. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
  1093. HostCmd_ACT_GEN_GET, 0, NULL);
  1094. if (ret)
  1095. return -1;
  1096. /* Reconfigure tx buf size */
  1097. ret = mwifiex_send_cmd_async(priv,
  1098. HostCmd_CMD_RECONFIGURE_TX_BUFF,
  1099. HostCmd_ACT_GEN_SET, 0,
  1100. &priv->adapter->tx_buf_size);
  1101. if (ret)
  1102. return -1;
  1103. /* Enable IEEE PS by default */
  1104. priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1105. ret = mwifiex_send_cmd_async(priv,
  1106. HostCmd_CMD_802_11_PS_MODE_ENH,
  1107. EN_AUTO_PS, BITMAP_STA_PS, NULL);
  1108. if (ret)
  1109. return -1;
  1110. }
  1111. /* get tx rate */
  1112. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
  1113. HostCmd_ACT_GEN_GET, 0, NULL);
  1114. if (ret)
  1115. return -1;
  1116. priv->data_rate = 0;
  1117. /* get tx power */
  1118. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TXPWR_CFG,
  1119. HostCmd_ACT_GEN_GET, 0, NULL);
  1120. if (ret)
  1121. return -1;
  1122. /* set ibss coalescing_status */
  1123. ret = mwifiex_send_cmd_async(priv,
  1124. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1125. HostCmd_ACT_GEN_SET, 0, &enable);
  1126. if (ret)
  1127. return -1;
  1128. memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
  1129. amsdu_aggr_ctrl.enable = true;
  1130. /* Send request to firmware */
  1131. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
  1132. HostCmd_ACT_GEN_SET, 0,
  1133. &amsdu_aggr_ctrl);
  1134. if (ret)
  1135. return -1;
  1136. /* MAC Control must be the last command in init_fw */
  1137. /* set MAC Control */
  1138. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  1139. HostCmd_ACT_GEN_SET, 0,
  1140. &priv->curr_pkt_filter);
  1141. if (ret)
  1142. return -1;
  1143. if (first_sta) {
  1144. /* Enable auto deep sleep */
  1145. auto_ds.auto_ds = DEEP_SLEEP_ON;
  1146. auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  1147. ret = mwifiex_send_cmd_async(priv,
  1148. HostCmd_CMD_802_11_PS_MODE_ENH,
  1149. EN_AUTO_PS, BITMAP_AUTO_DS,
  1150. &auto_ds);
  1151. if (ret)
  1152. return -1;
  1153. }
  1154. /* Send cmd to FW to enable/disable 11D function */
  1155. state_11d = ENABLE_11D;
  1156. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1157. HostCmd_ACT_GEN_SET, DOT11D_I, &state_11d);
  1158. if (ret)
  1159. dev_err(priv->adapter->dev, "11D: failed to enable 11D\n");
  1160. /* Send cmd to FW to configure 11n specific configuration
  1161. * (Short GI, Channel BW, Green field support etc.) for transmit
  1162. */
  1163. tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
  1164. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
  1165. HostCmd_ACT_GEN_SET, 0, &tx_cfg);
  1166. /* set last_init_cmd */
  1167. priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
  1168. ret = -EINPROGRESS;
  1169. return ret;
  1170. }