sta_cmd.c 37 KB

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