sta_cmd.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  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 set Host Sleep configuration.
  239. *
  240. * Preparation includes -
  241. * - Setting command ID and proper size
  242. * - Setting Host Sleep action, conditions, ARP filters
  243. * (as required)
  244. * - Ensuring correct endian-ness
  245. */
  246. static int
  247. mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
  248. struct host_cmd_ds_command *cmd,
  249. u16 cmd_action,
  250. struct mwifiex_hs_config_param *hscfg_param)
  251. {
  252. struct mwifiex_adapter *adapter = priv->adapter;
  253. struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
  254. u16 hs_activate = false;
  255. if (!hscfg_param)
  256. /* New Activate command */
  257. hs_activate = true;
  258. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
  259. if (!hs_activate &&
  260. (hscfg_param->conditions != cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) &&
  261. ((adapter->arp_filter_size > 0) &&
  262. (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
  263. dev_dbg(adapter->dev,
  264. "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
  265. adapter->arp_filter_size);
  266. memcpy(((u8 *) hs_cfg) +
  267. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
  268. adapter->arp_filter, adapter->arp_filter_size);
  269. cmd->size = cpu_to_le16
  270. (adapter->arp_filter_size +
  271. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
  272. + S_DS_GEN);
  273. } else {
  274. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
  275. host_cmd_ds_802_11_hs_cfg_enh));
  276. }
  277. if (hs_activate) {
  278. hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
  279. hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED;
  280. } else {
  281. hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
  282. hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
  283. hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
  284. hs_cfg->params.hs_config.gap = hscfg_param->gap;
  285. dev_dbg(adapter->dev,
  286. "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
  287. hs_cfg->params.hs_config.conditions,
  288. hs_cfg->params.hs_config.gpio,
  289. hs_cfg->params.hs_config.gap);
  290. }
  291. return 0;
  292. }
  293. /*
  294. * This function prepares command to set/get MAC address.
  295. *
  296. * Preparation includes -
  297. * - Setting command ID, action and proper size
  298. * - Setting MAC address (for SET only)
  299. * - Ensuring correct endian-ness
  300. */
  301. static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
  302. struct host_cmd_ds_command *cmd,
  303. u16 cmd_action)
  304. {
  305. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
  306. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
  307. S_DS_GEN);
  308. cmd->result = 0;
  309. cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
  310. if (cmd_action == HostCmd_ACT_GEN_SET)
  311. memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
  312. ETH_ALEN);
  313. return 0;
  314. }
  315. /*
  316. * This function prepares command to set MAC multicast address.
  317. *
  318. * Preparation includes -
  319. * - Setting command ID, action and proper size
  320. * - Setting MAC multicast address
  321. * - Ensuring correct endian-ness
  322. */
  323. static int
  324. mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
  325. u16 cmd_action,
  326. struct mwifiex_multicast_list *mcast_list)
  327. {
  328. struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
  329. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
  330. S_DS_GEN);
  331. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
  332. mcast_addr->action = cpu_to_le16(cmd_action);
  333. mcast_addr->num_of_adrs =
  334. cpu_to_le16((u16) mcast_list->num_multicast_addr);
  335. memcpy(mcast_addr->mac_list, mcast_list->mac_list,
  336. mcast_list->num_multicast_addr * ETH_ALEN);
  337. return 0;
  338. }
  339. /*
  340. * This function prepares command to deauthenticate.
  341. *
  342. * Preparation includes -
  343. * - Setting command ID and proper size
  344. * - Setting AP MAC address and reason code
  345. * - Ensuring correct endian-ness
  346. */
  347. static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
  348. struct host_cmd_ds_command *cmd,
  349. u8 *mac)
  350. {
  351. struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
  352. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
  353. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
  354. + S_DS_GEN);
  355. /* Set AP MAC address */
  356. memcpy(deauth->mac_addr, mac, ETH_ALEN);
  357. dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
  358. deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
  359. return 0;
  360. }
  361. /*
  362. * This function prepares command to stop Ad-Hoc network.
  363. *
  364. * Preparation includes -
  365. * - Setting command ID and proper size
  366. * - Ensuring correct endian-ness
  367. */
  368. static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
  369. {
  370. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
  371. cmd->size = cpu_to_le16(S_DS_GEN);
  372. return 0;
  373. }
  374. /*
  375. * This function sets WEP key(s) to key parameter TLV(s).
  376. *
  377. * Multi-key parameter TLVs are supported, so we can send multiple
  378. * WEP keys in a single buffer.
  379. */
  380. static int
  381. mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
  382. struct mwifiex_ie_type_key_param_set *key_param_set,
  383. u16 *key_param_len)
  384. {
  385. int cur_key_param_len;
  386. u8 i;
  387. /* Multi-key_param_set TLV is supported */
  388. for (i = 0; i < NUM_WEP_KEYS; i++) {
  389. if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
  390. (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
  391. key_param_set->type =
  392. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  393. /* Key_param_set WEP fixed length */
  394. #define KEYPARAMSET_WEP_FIXED_LEN 8
  395. key_param_set->length = cpu_to_le16((u16)
  396. (priv->wep_key[i].
  397. key_length +
  398. KEYPARAMSET_WEP_FIXED_LEN));
  399. key_param_set->key_type_id =
  400. cpu_to_le16(KEY_TYPE_ID_WEP);
  401. key_param_set->key_info =
  402. cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
  403. KEY_MCAST);
  404. key_param_set->key_len =
  405. cpu_to_le16(priv->wep_key[i].key_length);
  406. /* Set WEP key index */
  407. key_param_set->key[0] = i;
  408. /* Set default Tx key flag */
  409. if (i ==
  410. (priv->
  411. wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
  412. key_param_set->key[1] = 1;
  413. else
  414. key_param_set->key[1] = 0;
  415. memmove(&key_param_set->key[2],
  416. priv->wep_key[i].key_material,
  417. priv->wep_key[i].key_length);
  418. cur_key_param_len = priv->wep_key[i].key_length +
  419. KEYPARAMSET_WEP_FIXED_LEN +
  420. sizeof(struct mwifiex_ie_types_header);
  421. *key_param_len += (u16) cur_key_param_len;
  422. key_param_set =
  423. (struct mwifiex_ie_type_key_param_set *)
  424. ((u8 *)key_param_set +
  425. cur_key_param_len);
  426. } else if (!priv->wep_key[i].key_length) {
  427. continue;
  428. } else {
  429. dev_err(priv->adapter->dev,
  430. "key%d Length = %d is incorrect\n",
  431. (i + 1), priv->wep_key[i].key_length);
  432. return -1;
  433. }
  434. }
  435. return 0;
  436. }
  437. /*
  438. * This function prepares command to set/get/reset network key(s).
  439. *
  440. * Preparation includes -
  441. * - Setting command ID, action and proper size
  442. * - Setting WEP keys, WAPI keys or WPA keys along with required
  443. * encryption (TKIP, AES) (as required)
  444. * - Ensuring correct endian-ness
  445. */
  446. static int
  447. mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
  448. struct host_cmd_ds_command *cmd,
  449. u16 cmd_action, u32 cmd_oid,
  450. struct mwifiex_ds_encrypt_key *enc_key)
  451. {
  452. struct host_cmd_ds_802_11_key_material *key_material =
  453. &cmd->params.key_material;
  454. u16 key_param_len = 0;
  455. int ret = 0;
  456. const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  457. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
  458. key_material->action = cpu_to_le16(cmd_action);
  459. if (cmd_action == HostCmd_ACT_GEN_GET) {
  460. cmd->size =
  461. cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
  462. return ret;
  463. }
  464. if (!enc_key) {
  465. memset(&key_material->key_param_set, 0,
  466. (NUM_WEP_KEYS *
  467. sizeof(struct mwifiex_ie_type_key_param_set)));
  468. ret = mwifiex_set_keyparamset_wep(priv,
  469. &key_material->key_param_set,
  470. &key_param_len);
  471. cmd->size = cpu_to_le16(key_param_len +
  472. sizeof(key_material->action) + S_DS_GEN);
  473. return ret;
  474. } else
  475. memset(&key_material->key_param_set, 0,
  476. sizeof(struct mwifiex_ie_type_key_param_set));
  477. if (enc_key->is_wapi_key) {
  478. dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
  479. key_material->key_param_set.key_type_id =
  480. cpu_to_le16(KEY_TYPE_ID_WAPI);
  481. if (cmd_oid == KEY_INFO_ENABLED)
  482. key_material->key_param_set.key_info =
  483. cpu_to_le16(KEY_ENABLED);
  484. else
  485. key_material->key_param_set.key_info =
  486. cpu_to_le16(!KEY_ENABLED);
  487. key_material->key_param_set.key[0] = enc_key->key_index;
  488. if (!priv->sec_info.wapi_key_on)
  489. key_material->key_param_set.key[1] = 1;
  490. else
  491. /* set 0 when re-key */
  492. key_material->key_param_set.key[1] = 0;
  493. if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
  494. /* WAPI pairwise key: unicast */
  495. key_material->key_param_set.key_info |=
  496. cpu_to_le16(KEY_UNICAST);
  497. } else { /* WAPI group key: multicast */
  498. key_material->key_param_set.key_info |=
  499. cpu_to_le16(KEY_MCAST);
  500. priv->sec_info.wapi_key_on = true;
  501. }
  502. key_material->key_param_set.type =
  503. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  504. key_material->key_param_set.key_len =
  505. cpu_to_le16(WAPI_KEY_LEN);
  506. memcpy(&key_material->key_param_set.key[2],
  507. enc_key->key_material, enc_key->key_len);
  508. memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
  509. enc_key->wapi_rxpn, WAPI_RXPN_LEN);
  510. key_material->key_param_set.length =
  511. cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
  512. key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
  513. sizeof(struct mwifiex_ie_types_header);
  514. cmd->size = cpu_to_le16(sizeof(key_material->action)
  515. + S_DS_GEN + key_param_len);
  516. return ret;
  517. }
  518. if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
  519. dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
  520. key_material->key_param_set.key_type_id =
  521. cpu_to_le16(KEY_TYPE_ID_AES);
  522. if (cmd_oid == KEY_INFO_ENABLED)
  523. key_material->key_param_set.key_info =
  524. cpu_to_le16(KEY_ENABLED);
  525. else
  526. key_material->key_param_set.key_info =
  527. cpu_to_le16(!KEY_ENABLED);
  528. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  529. /* AES pairwise key: unicast */
  530. key_material->key_param_set.key_info |=
  531. cpu_to_le16(KEY_UNICAST);
  532. else /* AES group key: multicast */
  533. key_material->key_param_set.key_info |=
  534. cpu_to_le16(KEY_MCAST);
  535. } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
  536. dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
  537. key_material->key_param_set.key_type_id =
  538. cpu_to_le16(KEY_TYPE_ID_TKIP);
  539. key_material->key_param_set.key_info =
  540. cpu_to_le16(KEY_ENABLED);
  541. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  542. /* TKIP pairwise key: unicast */
  543. key_material->key_param_set.key_info |=
  544. cpu_to_le16(KEY_UNICAST);
  545. else /* TKIP group key: multicast */
  546. key_material->key_param_set.key_info |=
  547. cpu_to_le16(KEY_MCAST);
  548. }
  549. if (key_material->key_param_set.key_type_id) {
  550. key_material->key_param_set.type =
  551. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  552. key_material->key_param_set.key_len =
  553. cpu_to_le16((u16) enc_key->key_len);
  554. memcpy(key_material->key_param_set.key, enc_key->key_material,
  555. enc_key->key_len);
  556. key_material->key_param_set.length =
  557. cpu_to_le16((u16) enc_key->key_len +
  558. KEYPARAMSET_FIXED_LEN);
  559. key_param_len = (u16) (enc_key->key_len + KEYPARAMSET_FIXED_LEN)
  560. + sizeof(struct mwifiex_ie_types_header);
  561. cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
  562. + key_param_len);
  563. }
  564. return ret;
  565. }
  566. /*
  567. * This function prepares command to set/get 11d domain information.
  568. *
  569. * Preparation includes -
  570. * - Setting command ID, action and proper size
  571. * - Setting domain information fields (for SET only)
  572. * - Ensuring correct endian-ness
  573. */
  574. static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
  575. struct host_cmd_ds_command *cmd,
  576. u16 cmd_action)
  577. {
  578. struct mwifiex_adapter *adapter = priv->adapter;
  579. struct host_cmd_ds_802_11d_domain_info *domain_info =
  580. &cmd->params.domain_info;
  581. struct mwifiex_ietypes_domain_param_set *domain =
  582. &domain_info->domain;
  583. u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
  584. dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
  585. cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
  586. domain_info->action = cpu_to_le16(cmd_action);
  587. if (cmd_action == HostCmd_ACT_GEN_GET) {
  588. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  589. return 0;
  590. }
  591. /* Set domain info fields */
  592. domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
  593. memcpy(domain->country_code, adapter->domain_reg.country_code,
  594. sizeof(domain->country_code));
  595. domain->header.len =
  596. cpu_to_le16((no_of_triplet *
  597. sizeof(struct ieee80211_country_ie_triplet))
  598. + sizeof(domain->country_code));
  599. if (no_of_triplet) {
  600. memcpy(domain->triplet, adapter->domain_reg.triplet,
  601. no_of_triplet * sizeof(struct
  602. ieee80211_country_ie_triplet));
  603. cmd->size = cpu_to_le16(sizeof(domain_info->action) +
  604. le16_to_cpu(domain->header.len) +
  605. sizeof(struct mwifiex_ie_types_header)
  606. + S_DS_GEN);
  607. } else {
  608. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  609. }
  610. return 0;
  611. }
  612. /*
  613. * This function prepares command to set/get RF channel.
  614. *
  615. * Preparation includes -
  616. * - Setting command ID, action and proper size
  617. * - Setting RF type and current RF channel (for SET only)
  618. * - Ensuring correct endian-ness
  619. */
  620. static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv,
  621. struct host_cmd_ds_command *cmd,
  622. u16 cmd_action, u16 *channel)
  623. {
  624. struct host_cmd_ds_802_11_rf_channel *rf_chan =
  625. &cmd->params.rf_channel;
  626. uint16_t rf_type = le16_to_cpu(rf_chan->rf_type);
  627. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL);
  628. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel)
  629. + S_DS_GEN);
  630. if (cmd_action == HostCmd_ACT_GEN_SET) {
  631. if ((priv->adapter->adhoc_start_band & BAND_A) ||
  632. (priv->adapter->adhoc_start_band & BAND_AN))
  633. rf_chan->rf_type =
  634. cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A);
  635. rf_type = le16_to_cpu(rf_chan->rf_type);
  636. SET_SECONDARYCHAN(rf_type, priv->adapter->sec_chan_offset);
  637. rf_chan->current_channel = cpu_to_le16(*channel);
  638. }
  639. rf_chan->action = cpu_to_le16(cmd_action);
  640. return 0;
  641. }
  642. /*
  643. * This function prepares command to set/get IBSS coalescing status.
  644. *
  645. * Preparation includes -
  646. * - Setting command ID, action and proper size
  647. * - Setting status to enable or disable (for SET only)
  648. * - Ensuring correct endian-ness
  649. */
  650. static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
  651. u16 cmd_action, u16 *enable)
  652. {
  653. struct host_cmd_ds_802_11_ibss_status *ibss_coal =
  654. &(cmd->params.ibss_coalescing);
  655. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
  656. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
  657. S_DS_GEN);
  658. cmd->result = 0;
  659. ibss_coal->action = cpu_to_le16(cmd_action);
  660. switch (cmd_action) {
  661. case HostCmd_ACT_GEN_SET:
  662. if (enable)
  663. ibss_coal->enable = cpu_to_le16(*enable);
  664. else
  665. ibss_coal->enable = 0;
  666. break;
  667. /* In other case.. Nothing to do */
  668. case HostCmd_ACT_GEN_GET:
  669. default:
  670. break;
  671. }
  672. return 0;
  673. }
  674. /*
  675. * This function prepares command to set/get register value.
  676. *
  677. * Preparation includes -
  678. * - Setting command ID, action and proper size
  679. * - Setting register offset (for both GET and SET) and
  680. * register value (for SET only)
  681. * - Ensuring correct endian-ness
  682. *
  683. * The following type of registers can be accessed with this function -
  684. * - MAC register
  685. * - BBP register
  686. * - RF register
  687. * - PMIC register
  688. * - CAU register
  689. * - EEPROM
  690. */
  691. static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
  692. u16 cmd_action, void *data_buf)
  693. {
  694. struct mwifiex_ds_reg_rw *reg_rw = data_buf;
  695. switch (le16_to_cpu(cmd->command)) {
  696. case HostCmd_CMD_MAC_REG_ACCESS:
  697. {
  698. struct host_cmd_ds_mac_reg_access *mac_reg;
  699. cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
  700. mac_reg = &cmd->params.mac_reg;
  701. mac_reg->action = cpu_to_le16(cmd_action);
  702. mac_reg->offset =
  703. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  704. mac_reg->value = reg_rw->value;
  705. break;
  706. }
  707. case HostCmd_CMD_BBP_REG_ACCESS:
  708. {
  709. struct host_cmd_ds_bbp_reg_access *bbp_reg;
  710. cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
  711. bbp_reg = &cmd->params.bbp_reg;
  712. bbp_reg->action = cpu_to_le16(cmd_action);
  713. bbp_reg->offset =
  714. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  715. bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
  716. break;
  717. }
  718. case HostCmd_CMD_RF_REG_ACCESS:
  719. {
  720. struct host_cmd_ds_rf_reg_access *rf_reg;
  721. cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
  722. rf_reg = &cmd->params.rf_reg;
  723. rf_reg->action = cpu_to_le16(cmd_action);
  724. rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  725. rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
  726. break;
  727. }
  728. case HostCmd_CMD_PMIC_REG_ACCESS:
  729. {
  730. struct host_cmd_ds_pmic_reg_access *pmic_reg;
  731. cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
  732. pmic_reg = &cmd->params.pmic_reg;
  733. pmic_reg->action = cpu_to_le16(cmd_action);
  734. pmic_reg->offset =
  735. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  736. pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
  737. break;
  738. }
  739. case HostCmd_CMD_CAU_REG_ACCESS:
  740. {
  741. struct host_cmd_ds_rf_reg_access *cau_reg;
  742. cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
  743. cau_reg = &cmd->params.rf_reg;
  744. cau_reg->action = cpu_to_le16(cmd_action);
  745. cau_reg->offset =
  746. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  747. cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
  748. break;
  749. }
  750. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  751. {
  752. struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
  753. struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
  754. &cmd->params.eeprom;
  755. cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
  756. cmd_eeprom->action = cpu_to_le16(cmd_action);
  757. cmd_eeprom->offset = rd_eeprom->offset;
  758. cmd_eeprom->byte_count = rd_eeprom->byte_count;
  759. cmd_eeprom->value = 0;
  760. break;
  761. }
  762. default:
  763. return -1;
  764. }
  765. return 0;
  766. }
  767. /*
  768. * This function prepares command to set PCI-Express
  769. * host buffer configuration
  770. *
  771. * Preparation includes -
  772. * - Setting command ID, action and proper size
  773. * - Setting host buffer configuration
  774. * - Ensuring correct endian-ness
  775. */
  776. static int
  777. mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
  778. struct host_cmd_ds_command *cmd, u16 action)
  779. {
  780. struct host_cmd_ds_pcie_details *host_spec =
  781. &cmd->params.pcie_host_spec;
  782. struct pcie_service_card *card = priv->adapter->card;
  783. phys_addr_t *buf_pa;
  784. cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
  785. cmd->size = cpu_to_le16(sizeof(struct
  786. host_cmd_ds_pcie_details) + S_DS_GEN);
  787. cmd->result = 0;
  788. memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
  789. if (action != HostCmd_ACT_GEN_SET)
  790. return 0;
  791. /* Send the ring base addresses and count to firmware */
  792. host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
  793. host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
  794. host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
  795. host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
  796. host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
  797. host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
  798. host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
  799. host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
  800. host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
  801. if (card->sleep_cookie) {
  802. buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie);
  803. host_spec->sleep_cookie_addr_lo = (u32) *buf_pa;
  804. host_spec->sleep_cookie_addr_hi = (u32) (((u64)*buf_pa) >> 32);
  805. dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
  806. host_spec->sleep_cookie_addr_lo);
  807. }
  808. return 0;
  809. }
  810. /*
  811. * This function prepares the commands before sending them to the firmware.
  812. *
  813. * This is a generic function which calls specific command preparation
  814. * routines based upon the command number.
  815. */
  816. int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
  817. u16 cmd_action, u32 cmd_oid,
  818. void *data_buf, void *cmd_buf)
  819. {
  820. struct host_cmd_ds_command *cmd_ptr = cmd_buf;
  821. int ret = 0;
  822. /* Prepare command */
  823. switch (cmd_no) {
  824. case HostCmd_CMD_GET_HW_SPEC:
  825. ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
  826. break;
  827. case HostCmd_CMD_MAC_CONTROL:
  828. ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
  829. data_buf);
  830. break;
  831. case HostCmd_CMD_802_11_MAC_ADDRESS:
  832. ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
  833. cmd_action);
  834. break;
  835. case HostCmd_CMD_MAC_MULTICAST_ADR:
  836. ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
  837. data_buf);
  838. break;
  839. case HostCmd_CMD_TX_RATE_CFG:
  840. ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
  841. data_buf);
  842. break;
  843. case HostCmd_CMD_TXPWR_CFG:
  844. ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
  845. data_buf);
  846. break;
  847. case HostCmd_CMD_802_11_PS_MODE_ENH:
  848. ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
  849. (uint16_t)cmd_oid, data_buf);
  850. break;
  851. case HostCmd_CMD_802_11_HS_CFG_ENH:
  852. ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
  853. (struct mwifiex_hs_config_param *) data_buf);
  854. break;
  855. case HostCmd_CMD_802_11_SCAN:
  856. ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
  857. break;
  858. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  859. ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
  860. break;
  861. case HostCmd_CMD_802_11_ASSOCIATE:
  862. ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
  863. break;
  864. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  865. ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
  866. data_buf);
  867. break;
  868. case HostCmd_CMD_802_11_AD_HOC_START:
  869. ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
  870. data_buf);
  871. break;
  872. case HostCmd_CMD_802_11_GET_LOG:
  873. ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
  874. break;
  875. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  876. ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
  877. data_buf);
  878. break;
  879. case HostCmd_CMD_802_11_AD_HOC_STOP:
  880. ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
  881. break;
  882. case HostCmd_CMD_RSSI_INFO:
  883. ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
  884. break;
  885. case HostCmd_CMD_802_11_SNMP_MIB:
  886. ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
  887. cmd_oid, data_buf);
  888. break;
  889. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  890. cmd_ptr->command =
  891. cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
  892. cmd_ptr->size =
  893. cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
  894. S_DS_GEN);
  895. priv->tx_rate = 0;
  896. ret = 0;
  897. break;
  898. case HostCmd_CMD_VERSION_EXT:
  899. cmd_ptr->command = cpu_to_le16(cmd_no);
  900. cmd_ptr->params.verext.version_str_sel =
  901. (u8) (*((u32 *) data_buf));
  902. memcpy(&cmd_ptr->params, data_buf,
  903. sizeof(struct host_cmd_ds_version_ext));
  904. cmd_ptr->size =
  905. cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
  906. S_DS_GEN);
  907. ret = 0;
  908. break;
  909. case HostCmd_CMD_802_11_RF_CHANNEL:
  910. ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action,
  911. data_buf);
  912. break;
  913. case HostCmd_CMD_FUNC_INIT:
  914. if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
  915. priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  916. cmd_ptr->command = cpu_to_le16(cmd_no);
  917. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  918. break;
  919. case HostCmd_CMD_FUNC_SHUTDOWN:
  920. priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
  921. cmd_ptr->command = cpu_to_le16(cmd_no);
  922. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  923. break;
  924. case HostCmd_CMD_11N_ADDBA_REQ:
  925. ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
  926. break;
  927. case HostCmd_CMD_11N_DELBA:
  928. ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
  929. break;
  930. case HostCmd_CMD_11N_ADDBA_RSP:
  931. ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
  932. break;
  933. case HostCmd_CMD_802_11_KEY_MATERIAL:
  934. ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
  935. cmd_action, cmd_oid,
  936. data_buf);
  937. break;
  938. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  939. ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
  940. cmd_action);
  941. break;
  942. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  943. ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
  944. data_buf);
  945. break;
  946. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  947. ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
  948. data_buf);
  949. break;
  950. case HostCmd_CMD_11N_CFG:
  951. ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action, data_buf);
  952. break;
  953. case HostCmd_CMD_WMM_GET_STATUS:
  954. dev_dbg(priv->adapter->dev,
  955. "cmd: WMM: WMM_GET_STATUS cmd sent\n");
  956. cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
  957. cmd_ptr->size =
  958. cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
  959. S_DS_GEN);
  960. ret = 0;
  961. break;
  962. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  963. ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
  964. data_buf);
  965. break;
  966. case HostCmd_CMD_MAC_REG_ACCESS:
  967. case HostCmd_CMD_BBP_REG_ACCESS:
  968. case HostCmd_CMD_RF_REG_ACCESS:
  969. case HostCmd_CMD_PMIC_REG_ACCESS:
  970. case HostCmd_CMD_CAU_REG_ACCESS:
  971. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  972. ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
  973. break;
  974. case HostCmd_CMD_SET_BSS_MODE:
  975. cmd_ptr->command = cpu_to_le16(cmd_no);
  976. if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
  977. cmd_ptr->params.bss_mode.con_type =
  978. CONNECTION_TYPE_ADHOC;
  979. else if (priv->bss_mode == NL80211_IFTYPE_STATION)
  980. cmd_ptr->params.bss_mode.con_type =
  981. CONNECTION_TYPE_INFRA;
  982. cmd_ptr->size = cpu_to_le16(sizeof(struct
  983. host_cmd_ds_set_bss_mode) + S_DS_GEN);
  984. ret = 0;
  985. break;
  986. case HostCmd_CMD_PCIE_DESC_DETAILS:
  987. ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
  988. break;
  989. default:
  990. dev_err(priv->adapter->dev,
  991. "PREP_CMD: unknown cmd- %#x\n", cmd_no);
  992. ret = -1;
  993. break;
  994. }
  995. return ret;
  996. }
  997. /*
  998. * This function issues commands to initialize firmware.
  999. *
  1000. * This is called after firmware download to bring the card to
  1001. * working state.
  1002. *
  1003. * The following commands are issued sequentially -
  1004. * - Set PCI-Express host buffer configuration (PCIE only)
  1005. * - Function init (for first interface only)
  1006. * - Read MAC address (for first interface only)
  1007. * - Reconfigure Tx buffer size (for first interface only)
  1008. * - Enable auto deep sleep (for first interface only)
  1009. * - Get Tx rate
  1010. * - Get Tx power
  1011. * - Set IBSS coalescing status
  1012. * - Set AMSDU aggregation control
  1013. * - Set 11d control
  1014. * - Set MAC control (this must be the last command to initialize firmware)
  1015. */
  1016. int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
  1017. {
  1018. int ret;
  1019. u16 enable = true;
  1020. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  1021. struct mwifiex_ds_auto_ds auto_ds;
  1022. enum state_11d_t state_11d;
  1023. struct mwifiex_ds_11n_tx_cfg tx_cfg;
  1024. if (first_sta) {
  1025. if (priv->adapter->iface_type == MWIFIEX_PCIE) {
  1026. ret = mwifiex_send_cmd_async(priv,
  1027. HostCmd_CMD_PCIE_DESC_DETAILS,
  1028. HostCmd_ACT_GEN_SET, 0, NULL);
  1029. if (ret)
  1030. return -1;
  1031. }
  1032. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
  1033. HostCmd_ACT_GEN_SET, 0, NULL);
  1034. if (ret)
  1035. return -1;
  1036. /* Read MAC address from HW */
  1037. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
  1038. HostCmd_ACT_GEN_GET, 0, NULL);
  1039. if (ret)
  1040. return -1;
  1041. /* Reconfigure tx buf size */
  1042. ret = mwifiex_send_cmd_async(priv,
  1043. HostCmd_CMD_RECONFIGURE_TX_BUFF,
  1044. HostCmd_ACT_GEN_SET, 0,
  1045. &priv->adapter->tx_buf_size);
  1046. if (ret)
  1047. return -1;
  1048. /* Enable IEEE PS by default */
  1049. priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1050. ret = mwifiex_send_cmd_async(priv,
  1051. HostCmd_CMD_802_11_PS_MODE_ENH,
  1052. EN_AUTO_PS, BITMAP_STA_PS, NULL);
  1053. if (ret)
  1054. return -1;
  1055. }
  1056. /* get tx rate */
  1057. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
  1058. HostCmd_ACT_GEN_GET, 0, NULL);
  1059. if (ret)
  1060. return -1;
  1061. priv->data_rate = 0;
  1062. /* get tx power */
  1063. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TXPWR_CFG,
  1064. HostCmd_ACT_GEN_GET, 0, NULL);
  1065. if (ret)
  1066. return -1;
  1067. /* set ibss coalescing_status */
  1068. ret = mwifiex_send_cmd_async(priv,
  1069. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1070. HostCmd_ACT_GEN_SET, 0, &enable);
  1071. if (ret)
  1072. return -1;
  1073. memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
  1074. amsdu_aggr_ctrl.enable = true;
  1075. /* Send request to firmware */
  1076. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
  1077. HostCmd_ACT_GEN_SET, 0,
  1078. &amsdu_aggr_ctrl);
  1079. if (ret)
  1080. return -1;
  1081. /* MAC Control must be the last command in init_fw */
  1082. /* set MAC Control */
  1083. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  1084. HostCmd_ACT_GEN_SET, 0,
  1085. &priv->curr_pkt_filter);
  1086. if (ret)
  1087. return -1;
  1088. if (first_sta) {
  1089. /* Enable auto deep sleep */
  1090. auto_ds.auto_ds = DEEP_SLEEP_ON;
  1091. auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  1092. ret = mwifiex_send_cmd_async(priv,
  1093. HostCmd_CMD_802_11_PS_MODE_ENH,
  1094. EN_AUTO_PS, BITMAP_AUTO_DS,
  1095. &auto_ds);
  1096. if (ret)
  1097. return -1;
  1098. }
  1099. /* Send cmd to FW to enable/disable 11D function */
  1100. state_11d = ENABLE_11D;
  1101. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1102. HostCmd_ACT_GEN_SET, DOT11D_I, &state_11d);
  1103. if (ret)
  1104. dev_err(priv->adapter->dev, "11D: failed to enable 11D\n");
  1105. /* Send cmd to FW to configure 11n specific configuration
  1106. * (Short GI, Channel BW, Green field support etc.) for transmit
  1107. */
  1108. tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
  1109. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
  1110. HostCmd_ACT_GEN_SET, 0, &tx_cfg);
  1111. /* set last_init_cmd */
  1112. priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
  1113. ret = -EINPROGRESS;
  1114. return ret;
  1115. }