sta_cmd.c 37 KB

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