sta_cmd.c 37 KB

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