sta_cmd.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. /*
  2. * Marvell Wireless LAN device driver: station command handling
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. /*
  27. * This function prepares command to set/get RSSI information.
  28. *
  29. * Preparation includes -
  30. * - Setting command ID, action and proper size
  31. * - Setting data/beacon average factors
  32. * - Resetting SNR/NF/RSSI values in private structure
  33. * - Ensuring correct endian-ness
  34. */
  35. static int
  36. mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
  37. struct host_cmd_ds_command *cmd, u16 cmd_action)
  38. {
  39. cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
  40. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
  41. S_DS_GEN);
  42. cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
  43. cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
  44. cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
  45. /* Reset SNR/NF/RSSI values in private structure */
  46. priv->data_rssi_last = 0;
  47. priv->data_nf_last = 0;
  48. priv->data_rssi_avg = 0;
  49. priv->data_nf_avg = 0;
  50. priv->bcn_rssi_last = 0;
  51. priv->bcn_nf_last = 0;
  52. priv->bcn_rssi_avg = 0;
  53. priv->bcn_nf_avg = 0;
  54. return 0;
  55. }
  56. /*
  57. * This function prepares command to set MAC control.
  58. *
  59. * Preparation includes -
  60. * - Setting command ID, action and proper size
  61. * - Ensuring correct endian-ness
  62. */
  63. static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
  64. struct host_cmd_ds_command *cmd,
  65. u16 cmd_action, u16 *action)
  66. {
  67. struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
  68. if (cmd_action != HostCmd_ACT_GEN_SET) {
  69. dev_err(priv->adapter->dev,
  70. "mac_control: only support set cmd\n");
  71. return -1;
  72. }
  73. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
  74. cmd->size =
  75. cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
  76. mac_ctrl->action = cpu_to_le16(*action);
  77. return 0;
  78. }
  79. /*
  80. * This function prepares command to set/get SNMP MIB.
  81. *
  82. * Preparation includes -
  83. * - Setting command ID, action and proper size
  84. * - Setting SNMP MIB OID number and value
  85. * (as required)
  86. * - Ensuring correct endian-ness
  87. *
  88. * The following SNMP MIB OIDs are supported -
  89. * - FRAG_THRESH_I : Fragmentation threshold
  90. * - RTS_THRESH_I : RTS threshold
  91. * - SHORT_RETRY_LIM_I : Short retry limit
  92. * - DOT11D_I : 11d support
  93. */
  94. static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
  95. struct host_cmd_ds_command *cmd,
  96. u16 cmd_action, u32 cmd_oid,
  97. u32 *ul_temp)
  98. {
  99. struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
  100. dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
  101. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
  102. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
  103. - 1 + S_DS_GEN);
  104. if (cmd_action == HostCmd_ACT_GEN_GET) {
  105. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
  106. snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
  107. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  108. + MAX_SNMP_BUF_SIZE);
  109. }
  110. switch (cmd_oid) {
  111. case FRAG_THRESH_I:
  112. snmp_mib->oid = cpu_to_le16((u16) FRAG_THRESH_I);
  113. if (cmd_action == HostCmd_ACT_GEN_SET) {
  114. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  115. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  116. *((__le16 *) (snmp_mib->value)) =
  117. cpu_to_le16((u16) *ul_temp);
  118. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  119. + sizeof(u16));
  120. }
  121. break;
  122. case RTS_THRESH_I:
  123. snmp_mib->oid = cpu_to_le16((u16) RTS_THRESH_I);
  124. if (cmd_action == HostCmd_ACT_GEN_SET) {
  125. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  126. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  127. *(__le16 *) (snmp_mib->value) =
  128. cpu_to_le16((u16) *ul_temp);
  129. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  130. + sizeof(u16));
  131. }
  132. break;
  133. case SHORT_RETRY_LIM_I:
  134. snmp_mib->oid = cpu_to_le16((u16) SHORT_RETRY_LIM_I);
  135. if (cmd_action == HostCmd_ACT_GEN_SET) {
  136. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  137. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  138. *((__le16 *) (snmp_mib->value)) =
  139. cpu_to_le16((u16) *ul_temp);
  140. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  141. + sizeof(u16));
  142. }
  143. break;
  144. case DOT11D_I:
  145. snmp_mib->oid = cpu_to_le16((u16) DOT11D_I);
  146. if (cmd_action == HostCmd_ACT_GEN_SET) {
  147. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  148. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  149. *((__le16 *) (snmp_mib->value)) =
  150. cpu_to_le16((u16) *ul_temp);
  151. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
  152. + sizeof(u16));
  153. }
  154. break;
  155. default:
  156. break;
  157. }
  158. dev_dbg(priv->adapter->dev,
  159. "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
  160. " Value=0x%x\n",
  161. cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
  162. le16_to_cpu(*(__le16 *) snmp_mib->value));
  163. return 0;
  164. }
  165. /*
  166. * This function prepares command to get log.
  167. *
  168. * Preparation includes -
  169. * - Setting command ID and proper size
  170. * - Ensuring correct endian-ness
  171. */
  172. static int
  173. mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
  174. {
  175. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
  176. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
  177. S_DS_GEN);
  178. return 0;
  179. }
  180. /*
  181. * This function prepares command to set/get Tx data rate configuration.
  182. *
  183. * Preparation includes -
  184. * - Setting command ID, action and proper size
  185. * - Setting configuration index, rate scope and rate drop pattern
  186. * parameters (as required)
  187. * - Ensuring correct endian-ness
  188. */
  189. static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
  190. struct host_cmd_ds_command *cmd,
  191. u16 cmd_action, u16 *pbitmap_rates)
  192. {
  193. struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
  194. struct mwifiex_rate_scope *rate_scope;
  195. struct mwifiex_rate_drop_pattern *rate_drop;
  196. u32 i;
  197. cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
  198. rate_cfg->action = cpu_to_le16(cmd_action);
  199. rate_cfg->cfg_index = 0;
  200. rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
  201. sizeof(struct host_cmd_ds_tx_rate_cfg));
  202. rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
  203. rate_scope->length = cpu_to_le16(sizeof(struct mwifiex_rate_scope) -
  204. sizeof(struct mwifiex_ie_types_header));
  205. if (pbitmap_rates != NULL) {
  206. rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
  207. rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
  208. for (i = 0;
  209. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  210. i++)
  211. rate_scope->ht_mcs_rate_bitmap[i] =
  212. cpu_to_le16(pbitmap_rates[2 + i]);
  213. } else {
  214. rate_scope->hr_dsss_rate_bitmap =
  215. cpu_to_le16(priv->bitmap_rates[0]);
  216. rate_scope->ofdm_rate_bitmap =
  217. cpu_to_le16(priv->bitmap_rates[1]);
  218. for (i = 0;
  219. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  220. i++)
  221. rate_scope->ht_mcs_rate_bitmap[i] =
  222. cpu_to_le16(priv->bitmap_rates[2 + i]);
  223. }
  224. rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
  225. sizeof(struct mwifiex_rate_scope));
  226. rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
  227. rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
  228. rate_drop->rate_drop_mode = 0;
  229. cmd->size =
  230. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
  231. sizeof(struct mwifiex_rate_scope) +
  232. sizeof(struct mwifiex_rate_drop_pattern));
  233. return 0;
  234. }
  235. /*
  236. * This function prepares command to set/get Tx power configuration.
  237. *
  238. * Preparation includes -
  239. * - Setting command ID, action and proper size
  240. * - Setting Tx power mode, power group TLV
  241. * (as required)
  242. * - Ensuring correct endian-ness
  243. */
  244. static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
  245. u16 cmd_action,
  246. struct host_cmd_ds_txpwr_cfg *txp)
  247. {
  248. struct mwifiex_types_power_group *pg_tlv;
  249. struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
  250. cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
  251. cmd->size =
  252. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
  253. switch (cmd_action) {
  254. case HostCmd_ACT_GEN_SET:
  255. if (txp->mode) {
  256. pg_tlv = (struct mwifiex_types_power_group
  257. *) ((unsigned long) txp +
  258. sizeof(struct host_cmd_ds_txpwr_cfg));
  259. memmove(cmd_txp_cfg, txp,
  260. sizeof(struct host_cmd_ds_txpwr_cfg) +
  261. sizeof(struct mwifiex_types_power_group) +
  262. pg_tlv->length);
  263. pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
  264. cmd_txp_cfg +
  265. sizeof(struct host_cmd_ds_txpwr_cfg));
  266. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
  267. sizeof(struct mwifiex_types_power_group) +
  268. pg_tlv->length);
  269. } else {
  270. memmove(cmd_txp_cfg, txp, sizeof(*txp));
  271. }
  272. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  273. break;
  274. case HostCmd_ACT_GEN_GET:
  275. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  276. break;
  277. }
  278. return 0;
  279. }
  280. /*
  281. * This function prepares command to set Host Sleep configuration.
  282. *
  283. * Preparation includes -
  284. * - Setting command ID and proper size
  285. * - Setting Host Sleep action, conditions, ARP filters
  286. * (as required)
  287. * - Ensuring correct endian-ness
  288. */
  289. static int
  290. mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
  291. struct host_cmd_ds_command *cmd,
  292. u16 cmd_action,
  293. struct mwifiex_hs_config_param *hscfg_param)
  294. {
  295. struct mwifiex_adapter *adapter = priv->adapter;
  296. struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
  297. u16 hs_activate = false;
  298. if (!hscfg_param)
  299. /* New Activate command */
  300. hs_activate = true;
  301. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
  302. if (!hs_activate &&
  303. (hscfg_param->conditions
  304. != cpu_to_le32(HOST_SLEEP_CFG_CANCEL))
  305. && ((adapter->arp_filter_size > 0)
  306. && (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
  307. dev_dbg(adapter->dev,
  308. "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
  309. adapter->arp_filter_size);
  310. memcpy(((u8 *) hs_cfg) +
  311. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
  312. adapter->arp_filter, adapter->arp_filter_size);
  313. cmd->size = cpu_to_le16(adapter->arp_filter_size +
  314. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
  315. + S_DS_GEN);
  316. } else {
  317. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
  318. host_cmd_ds_802_11_hs_cfg_enh));
  319. }
  320. if (hs_activate) {
  321. hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
  322. hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED;
  323. } else {
  324. hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
  325. hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
  326. hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
  327. hs_cfg->params.hs_config.gap = hscfg_param->gap;
  328. dev_dbg(adapter->dev,
  329. "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
  330. hs_cfg->params.hs_config.conditions,
  331. hs_cfg->params.hs_config.gpio,
  332. hs_cfg->params.hs_config.gap);
  333. }
  334. return 0;
  335. }
  336. /*
  337. * This function prepares command to set/get MAC address.
  338. *
  339. * Preparation includes -
  340. * - Setting command ID, action and proper size
  341. * - Setting MAC address (for SET only)
  342. * - Ensuring correct endian-ness
  343. */
  344. static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
  345. struct host_cmd_ds_command *cmd,
  346. u16 cmd_action)
  347. {
  348. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
  349. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
  350. S_DS_GEN);
  351. cmd->result = 0;
  352. cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
  353. if (cmd_action == HostCmd_ACT_GEN_SET)
  354. memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
  355. ETH_ALEN);
  356. return 0;
  357. }
  358. /*
  359. * This function prepares command to set MAC multicast address.
  360. *
  361. * Preparation includes -
  362. * - Setting command ID, action and proper size
  363. * - Setting MAC multicast address
  364. * - Ensuring correct endian-ness
  365. */
  366. static int
  367. mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
  368. u16 cmd_action,
  369. struct mwifiex_multicast_list *mcast_list)
  370. {
  371. struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
  372. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
  373. S_DS_GEN);
  374. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
  375. mcast_addr->action = cpu_to_le16(cmd_action);
  376. mcast_addr->num_of_adrs =
  377. cpu_to_le16((u16) mcast_list->num_multicast_addr);
  378. memcpy(mcast_addr->mac_list, mcast_list->mac_list,
  379. mcast_list->num_multicast_addr * ETH_ALEN);
  380. return 0;
  381. }
  382. /*
  383. * This function prepares command to deauthenticate.
  384. *
  385. * Preparation includes -
  386. * - Setting command ID and proper size
  387. * - Setting AP MAC address and reason code
  388. * - Ensuring correct endian-ness
  389. */
  390. static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
  391. struct host_cmd_ds_command *cmd,
  392. u8 *mac)
  393. {
  394. struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
  395. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
  396. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
  397. + S_DS_GEN);
  398. /* Set AP MAC address */
  399. memcpy(deauth->mac_addr, mac, ETH_ALEN);
  400. dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
  401. deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
  402. return 0;
  403. }
  404. /*
  405. * This function prepares command to stop Ad-Hoc network.
  406. *
  407. * Preparation includes -
  408. * - Setting command ID and proper size
  409. * - Ensuring correct endian-ness
  410. */
  411. static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
  412. {
  413. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
  414. cmd->size = cpu_to_le16(S_DS_GEN);
  415. return 0;
  416. }
  417. /*
  418. * This function sets WEP key(s) to key parameter TLV(s).
  419. *
  420. * Multi-key parameter TLVs are supported, so we can send multiple
  421. * WEP keys in a single buffer.
  422. */
  423. static int
  424. mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
  425. struct mwifiex_ie_type_key_param_set *key_param_set,
  426. u16 *key_param_len)
  427. {
  428. int cur_key_param_len;
  429. u8 i;
  430. /* Multi-key_param_set TLV is supported */
  431. for (i = 0; i < NUM_WEP_KEYS; i++) {
  432. if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
  433. (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
  434. key_param_set->type =
  435. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  436. /* Key_param_set WEP fixed length */
  437. #define KEYPARAMSET_WEP_FIXED_LEN 8
  438. key_param_set->length = cpu_to_le16((u16)
  439. (priv->wep_key[i].
  440. key_length +
  441. KEYPARAMSET_WEP_FIXED_LEN));
  442. key_param_set->key_type_id =
  443. cpu_to_le16(KEY_TYPE_ID_WEP);
  444. key_param_set->key_info =
  445. cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
  446. KEY_MCAST);
  447. key_param_set->key_len =
  448. cpu_to_le16(priv->wep_key[i].key_length);
  449. /* Set WEP key index */
  450. key_param_set->key[0] = i;
  451. /* Set default Tx key flag */
  452. if (i ==
  453. (priv->
  454. wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
  455. key_param_set->key[1] = 1;
  456. else
  457. key_param_set->key[1] = 0;
  458. memmove(&key_param_set->key[2],
  459. priv->wep_key[i].key_material,
  460. priv->wep_key[i].key_length);
  461. cur_key_param_len = priv->wep_key[i].key_length +
  462. KEYPARAMSET_WEP_FIXED_LEN +
  463. sizeof(struct mwifiex_ie_types_header);
  464. *key_param_len += (u16) cur_key_param_len;
  465. key_param_set =
  466. (struct mwifiex_ie_type_key_param_set *)
  467. ((u8 *)key_param_set +
  468. cur_key_param_len);
  469. } else if (!priv->wep_key[i].key_length) {
  470. continue;
  471. } else {
  472. dev_err(priv->adapter->dev,
  473. "key%d Length = %d is incorrect\n",
  474. (i + 1), priv->wep_key[i].key_length);
  475. return -1;
  476. }
  477. }
  478. return 0;
  479. }
  480. /*
  481. * This function prepares command to set/get/reset network key(s).
  482. *
  483. * Preparation includes -
  484. * - Setting command ID, action and proper size
  485. * - Setting WEP keys, WAPI keys or WPA keys along with required
  486. * encryption (TKIP, AES) (as required)
  487. * - Ensuring correct endian-ness
  488. */
  489. static int
  490. mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
  491. struct host_cmd_ds_command *cmd,
  492. u16 cmd_action, u32 cmd_oid,
  493. struct mwifiex_ds_encrypt_key *enc_key)
  494. {
  495. struct host_cmd_ds_802_11_key_material *key_material =
  496. &cmd->params.key_material;
  497. u16 key_param_len = 0;
  498. int ret = 0;
  499. const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  500. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
  501. key_material->action = cpu_to_le16(cmd_action);
  502. if (cmd_action == HostCmd_ACT_GEN_GET) {
  503. cmd->size =
  504. cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
  505. return ret;
  506. }
  507. if (!enc_key) {
  508. memset(&key_material->key_param_set, 0,
  509. (NUM_WEP_KEYS *
  510. sizeof(struct mwifiex_ie_type_key_param_set)));
  511. ret = mwifiex_set_keyparamset_wep(priv,
  512. &key_material->key_param_set,
  513. &key_param_len);
  514. cmd->size = cpu_to_le16(key_param_len +
  515. sizeof(key_material->action) + S_DS_GEN);
  516. return ret;
  517. } else
  518. memset(&key_material->key_param_set, 0,
  519. sizeof(struct mwifiex_ie_type_key_param_set));
  520. if (enc_key->is_wapi_key) {
  521. dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
  522. key_material->key_param_set.key_type_id =
  523. cpu_to_le16(KEY_TYPE_ID_WAPI);
  524. if (cmd_oid == KEY_INFO_ENABLED)
  525. key_material->key_param_set.key_info =
  526. cpu_to_le16(KEY_ENABLED);
  527. else
  528. key_material->key_param_set.key_info =
  529. cpu_to_le16(!KEY_ENABLED);
  530. key_material->key_param_set.key[0] = enc_key->key_index;
  531. if (!priv->sec_info.wapi_key_on)
  532. key_material->key_param_set.key[1] = 1;
  533. else
  534. /* set 0 when re-key */
  535. key_material->key_param_set.key[1] = 0;
  536. if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
  537. /* WAPI pairwise key: unicast */
  538. key_material->key_param_set.key_info |=
  539. cpu_to_le16(KEY_UNICAST);
  540. } else { /* WAPI group key: multicast */
  541. key_material->key_param_set.key_info |=
  542. cpu_to_le16(KEY_MCAST);
  543. priv->sec_info.wapi_key_on = true;
  544. }
  545. key_material->key_param_set.type =
  546. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  547. key_material->key_param_set.key_len =
  548. cpu_to_le16(WAPI_KEY_LEN);
  549. memcpy(&key_material->key_param_set.key[2],
  550. enc_key->key_material, enc_key->key_len);
  551. memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
  552. enc_key->wapi_rxpn, WAPI_RXPN_LEN);
  553. key_material->key_param_set.length =
  554. cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
  555. key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
  556. sizeof(struct mwifiex_ie_types_header);
  557. cmd->size = cpu_to_le16(key_param_len +
  558. sizeof(key_material->action) + S_DS_GEN);
  559. return ret;
  560. }
  561. if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
  562. dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
  563. key_material->key_param_set.key_type_id =
  564. cpu_to_le16(KEY_TYPE_ID_AES);
  565. if (cmd_oid == KEY_INFO_ENABLED)
  566. key_material->key_param_set.key_info =
  567. cpu_to_le16(KEY_ENABLED);
  568. else
  569. key_material->key_param_set.key_info =
  570. cpu_to_le16(!KEY_ENABLED);
  571. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  572. /* AES pairwise key: unicast */
  573. key_material->key_param_set.key_info |=
  574. cpu_to_le16(KEY_UNICAST);
  575. else /* AES group key: multicast */
  576. key_material->key_param_set.key_info |=
  577. cpu_to_le16(KEY_MCAST);
  578. } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
  579. dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
  580. key_material->key_param_set.key_type_id =
  581. cpu_to_le16(KEY_TYPE_ID_TKIP);
  582. key_material->key_param_set.key_info =
  583. cpu_to_le16(KEY_ENABLED);
  584. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  585. /* TKIP pairwise key: unicast */
  586. key_material->key_param_set.key_info |=
  587. cpu_to_le16(KEY_UNICAST);
  588. else /* TKIP group key: multicast */
  589. key_material->key_param_set.key_info |=
  590. cpu_to_le16(KEY_MCAST);
  591. }
  592. if (key_material->key_param_set.key_type_id) {
  593. key_material->key_param_set.type =
  594. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  595. key_material->key_param_set.key_len =
  596. cpu_to_le16((u16) enc_key->key_len);
  597. memcpy(key_material->key_param_set.key, enc_key->key_material,
  598. enc_key->key_len);
  599. key_material->key_param_set.length =
  600. cpu_to_le16((u16) enc_key->key_len +
  601. KEYPARAMSET_FIXED_LEN);
  602. key_param_len = (u16) (enc_key->key_len + KEYPARAMSET_FIXED_LEN)
  603. + sizeof(struct mwifiex_ie_types_header);
  604. cmd->size = cpu_to_le16(key_param_len +
  605. sizeof(key_material->action) + S_DS_GEN);
  606. }
  607. return ret;
  608. }
  609. /*
  610. * This function prepares command to set/get 11d domain information.
  611. *
  612. * Preparation includes -
  613. * - Setting command ID, action and proper size
  614. * - Setting domain information fields (for SET only)
  615. * - Ensuring correct endian-ness
  616. */
  617. static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
  618. struct host_cmd_ds_command *cmd,
  619. u16 cmd_action)
  620. {
  621. struct mwifiex_adapter *adapter = priv->adapter;
  622. struct host_cmd_ds_802_11d_domain_info *domain_info =
  623. &cmd->params.domain_info;
  624. struct mwifiex_ietypes_domain_param_set *domain =
  625. &domain_info->domain;
  626. u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
  627. dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
  628. cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
  629. domain_info->action = cpu_to_le16(cmd_action);
  630. if (cmd_action == HostCmd_ACT_GEN_GET) {
  631. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  632. return 0;
  633. }
  634. /* Set domain info fields */
  635. domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
  636. memcpy(domain->country_code, adapter->domain_reg.country_code,
  637. sizeof(domain->country_code));
  638. domain->header.len = cpu_to_le16((no_of_triplet *
  639. sizeof(struct ieee80211_country_ie_triplet)) +
  640. sizeof(domain->country_code));
  641. if (no_of_triplet) {
  642. memcpy(domain->triplet, adapter->domain_reg.triplet,
  643. no_of_triplet *
  644. sizeof(struct ieee80211_country_ie_triplet));
  645. cmd->size = cpu_to_le16(sizeof(domain_info->action) +
  646. le16_to_cpu(domain->header.len) +
  647. sizeof(struct mwifiex_ie_types_header)
  648. + S_DS_GEN);
  649. } else {
  650. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  651. }
  652. return 0;
  653. }
  654. /*
  655. * This function prepares command to set/get RF channel.
  656. *
  657. * Preparation includes -
  658. * - Setting command ID, action and proper size
  659. * - Setting RF type and current RF channel (for SET only)
  660. * - Ensuring correct endian-ness
  661. */
  662. static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv,
  663. struct host_cmd_ds_command *cmd,
  664. u16 cmd_action, u16 *channel)
  665. {
  666. struct host_cmd_ds_802_11_rf_channel *rf_chan =
  667. &cmd->params.rf_channel;
  668. uint16_t rf_type = le16_to_cpu(rf_chan->rf_type);
  669. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL);
  670. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel)
  671. + S_DS_GEN);
  672. if (cmd_action == HostCmd_ACT_GEN_SET) {
  673. if ((priv->adapter->adhoc_start_band & BAND_A)
  674. || (priv->adapter->adhoc_start_band & BAND_AN))
  675. rf_chan->rf_type =
  676. cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A);
  677. rf_type = le16_to_cpu(rf_chan->rf_type);
  678. SET_SECONDARYCHAN(rf_type, priv->adapter->chan_offset);
  679. rf_chan->current_channel = cpu_to_le16(*channel);
  680. }
  681. rf_chan->action = cpu_to_le16(cmd_action);
  682. return 0;
  683. }
  684. /*
  685. * This function prepares command to set/get IBSS coalescing status.
  686. *
  687. * Preparation includes -
  688. * - Setting command ID, action and proper size
  689. * - Setting status to enable or disable (for SET only)
  690. * - Ensuring correct endian-ness
  691. */
  692. static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
  693. u16 cmd_action, u16 *enable)
  694. {
  695. struct host_cmd_ds_802_11_ibss_status *ibss_coal =
  696. &(cmd->params.ibss_coalescing);
  697. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
  698. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
  699. S_DS_GEN);
  700. cmd->result = 0;
  701. ibss_coal->action = cpu_to_le16(cmd_action);
  702. switch (cmd_action) {
  703. case HostCmd_ACT_GEN_SET:
  704. if (enable)
  705. ibss_coal->enable = cpu_to_le16(*enable);
  706. else
  707. ibss_coal->enable = 0;
  708. break;
  709. /* In other case.. Nothing to do */
  710. case HostCmd_ACT_GEN_GET:
  711. default:
  712. break;
  713. }
  714. return 0;
  715. }
  716. /*
  717. * This function prepares command to set/get register value.
  718. *
  719. * Preparation includes -
  720. * - Setting command ID, action and proper size
  721. * - Setting register offset (for both GET and SET) and
  722. * register value (for SET only)
  723. * - Ensuring correct endian-ness
  724. *
  725. * The following type of registers can be accessed with this function -
  726. * - MAC register
  727. * - BBP register
  728. * - RF register
  729. * - PMIC register
  730. * - CAU register
  731. * - EEPROM
  732. */
  733. static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
  734. u16 cmd_action, void *data_buf)
  735. {
  736. struct mwifiex_ds_reg_rw *reg_rw = data_buf;
  737. switch (le16_to_cpu(cmd->command)) {
  738. case HostCmd_CMD_MAC_REG_ACCESS:
  739. {
  740. struct host_cmd_ds_mac_reg_access *mac_reg;
  741. cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
  742. mac_reg = (struct host_cmd_ds_mac_reg_access *) &cmd->
  743. params.mac_reg;
  744. mac_reg->action = cpu_to_le16(cmd_action);
  745. mac_reg->offset =
  746. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  747. mac_reg->value = reg_rw->value;
  748. break;
  749. }
  750. case HostCmd_CMD_BBP_REG_ACCESS:
  751. {
  752. struct host_cmd_ds_bbp_reg_access *bbp_reg;
  753. cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
  754. bbp_reg = (struct host_cmd_ds_bbp_reg_access *) &cmd->
  755. params.bbp_reg;
  756. bbp_reg->action = cpu_to_le16(cmd_action);
  757. bbp_reg->offset =
  758. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  759. bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
  760. break;
  761. }
  762. case HostCmd_CMD_RF_REG_ACCESS:
  763. {
  764. struct host_cmd_ds_rf_reg_access *rf_reg;
  765. cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
  766. rf_reg = (struct host_cmd_ds_rf_reg_access *) &cmd->
  767. params.rf_reg;
  768. rf_reg->action = cpu_to_le16(cmd_action);
  769. rf_reg->offset =
  770. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  771. rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
  772. break;
  773. }
  774. case HostCmd_CMD_PMIC_REG_ACCESS:
  775. {
  776. struct host_cmd_ds_pmic_reg_access *pmic_reg;
  777. cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
  778. pmic_reg = (struct host_cmd_ds_pmic_reg_access *) &cmd->
  779. params.pmic_reg;
  780. pmic_reg->action = cpu_to_le16(cmd_action);
  781. pmic_reg->offset =
  782. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  783. pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
  784. break;
  785. }
  786. case HostCmd_CMD_CAU_REG_ACCESS:
  787. {
  788. struct host_cmd_ds_rf_reg_access *cau_reg;
  789. cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
  790. cau_reg = (struct host_cmd_ds_rf_reg_access *) &cmd->
  791. params.rf_reg;
  792. cau_reg->action = cpu_to_le16(cmd_action);
  793. cau_reg->offset =
  794. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  795. cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
  796. break;
  797. }
  798. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  799. {
  800. struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
  801. struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
  802. (struct host_cmd_ds_802_11_eeprom_access *)
  803. &cmd->params.eeprom;
  804. cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
  805. cmd_eeprom->action = cpu_to_le16(cmd_action);
  806. cmd_eeprom->offset = rd_eeprom->offset;
  807. cmd_eeprom->byte_count = rd_eeprom->byte_count;
  808. cmd_eeprom->value = 0;
  809. break;
  810. }
  811. default:
  812. return -1;
  813. }
  814. return 0;
  815. }
  816. /*
  817. * This function prepares 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,
  958. data_buf);
  959. break;
  960. case HostCmd_CMD_WMM_GET_STATUS:
  961. dev_dbg(priv->adapter->dev,
  962. "cmd: WMM: WMM_GET_STATUS cmd sent\n");
  963. cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
  964. cmd_ptr->size =
  965. cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
  966. S_DS_GEN);
  967. ret = 0;
  968. break;
  969. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  970. ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
  971. data_buf);
  972. break;
  973. case HostCmd_CMD_MAC_REG_ACCESS:
  974. case HostCmd_CMD_BBP_REG_ACCESS:
  975. case HostCmd_CMD_RF_REG_ACCESS:
  976. case HostCmd_CMD_PMIC_REG_ACCESS:
  977. case HostCmd_CMD_CAU_REG_ACCESS:
  978. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  979. ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
  980. break;
  981. case HostCmd_CMD_SET_BSS_MODE:
  982. cmd_ptr->command = cpu_to_le16(cmd_no);
  983. if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
  984. cmd_ptr->params.bss_mode.con_type =
  985. CONNECTION_TYPE_ADHOC;
  986. else if (priv->bss_mode == NL80211_IFTYPE_STATION)
  987. cmd_ptr->params.bss_mode.con_type =
  988. CONNECTION_TYPE_INFRA;
  989. cmd_ptr->size = cpu_to_le16(sizeof(struct
  990. host_cmd_ds_set_bss_mode) + S_DS_GEN);
  991. ret = 0;
  992. break;
  993. default:
  994. dev_err(priv->adapter->dev,
  995. "PREP_CMD: unknown cmd- %#x\n", cmd_no);
  996. ret = -1;
  997. break;
  998. }
  999. return ret;
  1000. }
  1001. /*
  1002. * This function issues commands to initialize firmware.
  1003. *
  1004. * This is called after firmware download to bring the card to
  1005. * working state.
  1006. *
  1007. * The following commands are issued sequentially -
  1008. * - Function init (for first interface only)
  1009. * - Read MAC address (for first interface only)
  1010. * - Reconfigure Tx buffer size (for first interface only)
  1011. * - Enable auto deep sleep (for first interface only)
  1012. * - Get Tx rate
  1013. * - Get Tx power
  1014. * - Set IBSS coalescing status
  1015. * - Set AMSDU aggregation control
  1016. * - Set 11d control
  1017. * - Set MAC control (this must be the last command to initialize firmware)
  1018. */
  1019. int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
  1020. {
  1021. int ret;
  1022. u16 enable = true;
  1023. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  1024. struct mwifiex_ds_auto_ds auto_ds;
  1025. enum state_11d_t state_11d;
  1026. struct mwifiex_ds_11n_tx_cfg tx_cfg;
  1027. if (first_sta) {
  1028. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
  1029. HostCmd_ACT_GEN_SET, 0, NULL);
  1030. if (ret)
  1031. return -1;
  1032. /* Read MAC address from HW */
  1033. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
  1034. HostCmd_ACT_GEN_GET, 0, NULL);
  1035. if (ret)
  1036. return -1;
  1037. /* Reconfigure tx buf size */
  1038. ret = mwifiex_send_cmd_async(priv,
  1039. HostCmd_CMD_RECONFIGURE_TX_BUFF,
  1040. HostCmd_ACT_GEN_SET, 0,
  1041. &priv->adapter->tx_buf_size);
  1042. if (ret)
  1043. return -1;
  1044. /* Enable IEEE PS by default */
  1045. priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1046. ret = mwifiex_send_cmd_async(priv,
  1047. HostCmd_CMD_802_11_PS_MODE_ENH,
  1048. EN_AUTO_PS, BITMAP_STA_PS, NULL);
  1049. if (ret)
  1050. return -1;
  1051. }
  1052. /* get tx rate */
  1053. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
  1054. HostCmd_ACT_GEN_GET, 0, NULL);
  1055. if (ret)
  1056. return -1;
  1057. priv->data_rate = 0;
  1058. /* get tx power */
  1059. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TXPWR_CFG,
  1060. HostCmd_ACT_GEN_GET, 0, NULL);
  1061. if (ret)
  1062. return -1;
  1063. /* set ibss coalescing_status */
  1064. ret = mwifiex_send_cmd_async(priv,
  1065. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1066. HostCmd_ACT_GEN_SET, 0, &enable);
  1067. if (ret)
  1068. return -1;
  1069. memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
  1070. amsdu_aggr_ctrl.enable = true;
  1071. /* Send request to firmware */
  1072. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
  1073. HostCmd_ACT_GEN_SET, 0,
  1074. &amsdu_aggr_ctrl);
  1075. if (ret)
  1076. return -1;
  1077. /* MAC Control must be the last command in init_fw */
  1078. /* set MAC Control */
  1079. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  1080. HostCmd_ACT_GEN_SET, 0,
  1081. &priv->curr_pkt_filter);
  1082. if (ret)
  1083. return -1;
  1084. if (first_sta) {
  1085. /* Enable auto deep sleep */
  1086. auto_ds.auto_ds = DEEP_SLEEP_ON;
  1087. auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  1088. ret = mwifiex_send_cmd_async(priv,
  1089. HostCmd_CMD_802_11_PS_MODE_ENH,
  1090. EN_AUTO_PS, BITMAP_AUTO_DS,
  1091. &auto_ds);
  1092. if (ret)
  1093. return -1;
  1094. }
  1095. /* Send cmd to FW to enable/disable 11D function */
  1096. state_11d = ENABLE_11D;
  1097. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1098. HostCmd_ACT_GEN_SET, DOT11D_I, &state_11d);
  1099. if (ret)
  1100. dev_err(priv->adapter->dev, "11D: failed to enable 11D\n");
  1101. /* Send cmd to FW to configure 11n specific configuration
  1102. * (Short GI, Channel BW, Green field support etc.) for transmit
  1103. */
  1104. tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
  1105. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
  1106. HostCmd_ACT_GEN_SET, 0, &tx_cfg);
  1107. /* set last_init_cmd */
  1108. priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
  1109. ret = -EINPROGRESS;
  1110. return ret;
  1111. }