sta_cmd.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  1. /*
  2. * Marvell Wireless LAN device driver: station command handling
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. /*
  27. * This function prepares command to set/get RSSI information.
  28. *
  29. * Preparation includes -
  30. * - Setting command ID, action and proper size
  31. * - Setting data/beacon average factors
  32. * - Resetting SNR/NF/RSSI values in private structure
  33. * - Ensuring correct endian-ness
  34. */
  35. static int
  36. mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
  37. struct host_cmd_ds_command *cmd, u16 cmd_action)
  38. {
  39. cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
  40. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
  41. S_DS_GEN);
  42. cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
  43. cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
  44. cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
  45. /* Reset SNR/NF/RSSI values in private structure */
  46. priv->data_rssi_last = 0;
  47. priv->data_nf_last = 0;
  48. priv->data_rssi_avg = 0;
  49. priv->data_nf_avg = 0;
  50. priv->bcn_rssi_last = 0;
  51. priv->bcn_nf_last = 0;
  52. priv->bcn_rssi_avg = 0;
  53. priv->bcn_nf_avg = 0;
  54. return 0;
  55. }
  56. /*
  57. * This function prepares command to set MAC control.
  58. *
  59. * Preparation includes -
  60. * - Setting command ID, action and proper size
  61. * - Ensuring correct endian-ness
  62. */
  63. static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
  64. struct host_cmd_ds_command *cmd,
  65. u16 cmd_action, u16 *action)
  66. {
  67. struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
  68. if (cmd_action != HostCmd_ACT_GEN_SET) {
  69. dev_err(priv->adapter->dev,
  70. "mac_control: only support set cmd\n");
  71. return -1;
  72. }
  73. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
  74. cmd->size =
  75. cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
  76. mac_ctrl->action = cpu_to_le16(*action);
  77. return 0;
  78. }
  79. /*
  80. * This function prepares command to set/get SNMP MIB.
  81. *
  82. * Preparation includes -
  83. * - Setting command ID, action and proper size
  84. * - Setting SNMP MIB OID number and value
  85. * (as required)
  86. * - Ensuring correct endian-ness
  87. *
  88. * The following SNMP MIB OIDs are supported -
  89. * - FRAG_THRESH_I : Fragmentation threshold
  90. * - RTS_THRESH_I : RTS threshold
  91. * - SHORT_RETRY_LIM_I : Short retry limit
  92. * - DOT11D_I : 11d support
  93. */
  94. static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
  95. struct host_cmd_ds_command *cmd,
  96. u16 cmd_action, u32 cmd_oid,
  97. u16 *ul_temp)
  98. {
  99. struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
  100. dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
  101. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
  102. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
  103. - 1 + S_DS_GEN);
  104. snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
  105. if (cmd_action == HostCmd_ACT_GEN_GET) {
  106. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
  107. snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
  108. le16_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE);
  109. } else if (cmd_action == HostCmd_ACT_GEN_SET) {
  110. snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
  111. snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
  112. *((__le16 *) (snmp_mib->value)) = cpu_to_le16(*ul_temp);
  113. le16_add_cpu(&cmd->size, sizeof(u16));
  114. }
  115. dev_dbg(priv->adapter->dev,
  116. "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
  117. " Value=0x%x\n",
  118. cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
  119. le16_to_cpu(*(__le16 *) snmp_mib->value));
  120. return 0;
  121. }
  122. /*
  123. * This function prepares command to get log.
  124. *
  125. * Preparation includes -
  126. * - Setting command ID and proper size
  127. * - Ensuring correct endian-ness
  128. */
  129. static int
  130. mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
  131. {
  132. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
  133. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
  134. S_DS_GEN);
  135. return 0;
  136. }
  137. /*
  138. * This function prepares command to set/get Tx data rate configuration.
  139. *
  140. * Preparation includes -
  141. * - Setting command ID, action and proper size
  142. * - Setting configuration index, rate scope and rate drop pattern
  143. * parameters (as required)
  144. * - Ensuring correct endian-ness
  145. */
  146. static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
  147. struct host_cmd_ds_command *cmd,
  148. u16 cmd_action, u16 *pbitmap_rates)
  149. {
  150. struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
  151. struct mwifiex_rate_scope *rate_scope;
  152. struct mwifiex_rate_drop_pattern *rate_drop;
  153. u32 i;
  154. cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
  155. rate_cfg->action = cpu_to_le16(cmd_action);
  156. rate_cfg->cfg_index = 0;
  157. rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
  158. sizeof(struct host_cmd_ds_tx_rate_cfg));
  159. rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
  160. rate_scope->length = cpu_to_le16
  161. (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
  162. if (pbitmap_rates != NULL) {
  163. rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
  164. rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
  165. for (i = 0;
  166. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  167. i++)
  168. rate_scope->ht_mcs_rate_bitmap[i] =
  169. cpu_to_le16(pbitmap_rates[2 + i]);
  170. } else {
  171. rate_scope->hr_dsss_rate_bitmap =
  172. cpu_to_le16(priv->bitmap_rates[0]);
  173. rate_scope->ofdm_rate_bitmap =
  174. cpu_to_le16(priv->bitmap_rates[1]);
  175. for (i = 0;
  176. i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
  177. i++)
  178. rate_scope->ht_mcs_rate_bitmap[i] =
  179. cpu_to_le16(priv->bitmap_rates[2 + i]);
  180. }
  181. rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
  182. sizeof(struct mwifiex_rate_scope));
  183. rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
  184. rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
  185. rate_drop->rate_drop_mode = 0;
  186. cmd->size =
  187. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
  188. sizeof(struct mwifiex_rate_scope) +
  189. sizeof(struct mwifiex_rate_drop_pattern));
  190. return 0;
  191. }
  192. /*
  193. * This function prepares command to set/get Tx power configuration.
  194. *
  195. * Preparation includes -
  196. * - Setting command ID, action and proper size
  197. * - Setting Tx power mode, power group TLV
  198. * (as required)
  199. * - Ensuring correct endian-ness
  200. */
  201. static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
  202. u16 cmd_action,
  203. struct host_cmd_ds_txpwr_cfg *txp)
  204. {
  205. struct mwifiex_types_power_group *pg_tlv;
  206. struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
  207. cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
  208. cmd->size =
  209. cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
  210. switch (cmd_action) {
  211. case HostCmd_ACT_GEN_SET:
  212. if (txp->mode) {
  213. pg_tlv = (struct mwifiex_types_power_group
  214. *) ((unsigned long) txp +
  215. sizeof(struct host_cmd_ds_txpwr_cfg));
  216. memmove(cmd_txp_cfg, txp,
  217. sizeof(struct host_cmd_ds_txpwr_cfg) +
  218. sizeof(struct mwifiex_types_power_group) +
  219. pg_tlv->length);
  220. pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
  221. cmd_txp_cfg +
  222. sizeof(struct host_cmd_ds_txpwr_cfg));
  223. cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
  224. sizeof(struct mwifiex_types_power_group) +
  225. pg_tlv->length);
  226. } else {
  227. memmove(cmd_txp_cfg, txp, sizeof(*txp));
  228. }
  229. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  230. break;
  231. case HostCmd_ACT_GEN_GET:
  232. cmd_txp_cfg->action = cpu_to_le16(cmd_action);
  233. break;
  234. }
  235. return 0;
  236. }
  237. /*
  238. * This function prepares command to get RF Tx power.
  239. */
  240. static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
  241. struct host_cmd_ds_command *cmd,
  242. u16 cmd_action, void *data_buf)
  243. {
  244. struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
  245. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
  246. + S_DS_GEN);
  247. cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
  248. txp->action = cpu_to_le16(cmd_action);
  249. return 0;
  250. }
  251. /*
  252. * This function prepares command to set Host Sleep configuration.
  253. *
  254. * Preparation includes -
  255. * - Setting command ID and proper size
  256. * - Setting Host Sleep action, conditions, ARP filters
  257. * (as required)
  258. * - Ensuring correct endian-ness
  259. */
  260. static int
  261. mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
  262. struct host_cmd_ds_command *cmd,
  263. u16 cmd_action,
  264. struct mwifiex_hs_config_param *hscfg_param)
  265. {
  266. struct mwifiex_adapter *adapter = priv->adapter;
  267. struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
  268. u16 hs_activate = false;
  269. if (!hscfg_param)
  270. /* New Activate command */
  271. hs_activate = true;
  272. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
  273. if (!hs_activate &&
  274. (hscfg_param->conditions != cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) &&
  275. ((adapter->arp_filter_size > 0) &&
  276. (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
  277. dev_dbg(adapter->dev,
  278. "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
  279. adapter->arp_filter_size);
  280. memcpy(((u8 *) hs_cfg) +
  281. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
  282. adapter->arp_filter, adapter->arp_filter_size);
  283. cmd->size = cpu_to_le16
  284. (adapter->arp_filter_size +
  285. sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
  286. + S_DS_GEN);
  287. } else {
  288. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
  289. host_cmd_ds_802_11_hs_cfg_enh));
  290. }
  291. if (hs_activate) {
  292. hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
  293. hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED;
  294. } else {
  295. hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
  296. hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
  297. hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
  298. hs_cfg->params.hs_config.gap = hscfg_param->gap;
  299. dev_dbg(adapter->dev,
  300. "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
  301. hs_cfg->params.hs_config.conditions,
  302. hs_cfg->params.hs_config.gpio,
  303. hs_cfg->params.hs_config.gap);
  304. }
  305. return 0;
  306. }
  307. /*
  308. * This function prepares command to set/get MAC address.
  309. *
  310. * Preparation includes -
  311. * - Setting command ID, action and proper size
  312. * - Setting MAC address (for SET only)
  313. * - Ensuring correct endian-ness
  314. */
  315. static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
  316. struct host_cmd_ds_command *cmd,
  317. u16 cmd_action)
  318. {
  319. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
  320. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
  321. S_DS_GEN);
  322. cmd->result = 0;
  323. cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
  324. if (cmd_action == HostCmd_ACT_GEN_SET)
  325. memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
  326. ETH_ALEN);
  327. return 0;
  328. }
  329. /*
  330. * This function prepares command to set MAC multicast address.
  331. *
  332. * Preparation includes -
  333. * - Setting command ID, action and proper size
  334. * - Setting MAC multicast address
  335. * - Ensuring correct endian-ness
  336. */
  337. static int
  338. mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
  339. u16 cmd_action,
  340. struct mwifiex_multicast_list *mcast_list)
  341. {
  342. struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
  343. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
  344. S_DS_GEN);
  345. cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
  346. mcast_addr->action = cpu_to_le16(cmd_action);
  347. mcast_addr->num_of_adrs =
  348. cpu_to_le16((u16) mcast_list->num_multicast_addr);
  349. memcpy(mcast_addr->mac_list, mcast_list->mac_list,
  350. mcast_list->num_multicast_addr * ETH_ALEN);
  351. return 0;
  352. }
  353. /*
  354. * This function prepares command to deauthenticate.
  355. *
  356. * Preparation includes -
  357. * - Setting command ID and proper size
  358. * - Setting AP MAC address and reason code
  359. * - Ensuring correct endian-ness
  360. */
  361. static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
  362. struct host_cmd_ds_command *cmd,
  363. u8 *mac)
  364. {
  365. struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
  366. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
  367. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
  368. + S_DS_GEN);
  369. /* Set AP MAC address */
  370. memcpy(deauth->mac_addr, mac, ETH_ALEN);
  371. dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
  372. deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
  373. return 0;
  374. }
  375. /*
  376. * This function prepares command to stop Ad-Hoc network.
  377. *
  378. * Preparation includes -
  379. * - Setting command ID and proper size
  380. * - Ensuring correct endian-ness
  381. */
  382. static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
  383. {
  384. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
  385. cmd->size = cpu_to_le16(S_DS_GEN);
  386. return 0;
  387. }
  388. /*
  389. * This function sets WEP key(s) to key parameter TLV(s).
  390. *
  391. * Multi-key parameter TLVs are supported, so we can send multiple
  392. * WEP keys in a single buffer.
  393. */
  394. static int
  395. mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
  396. struct mwifiex_ie_type_key_param_set *key_param_set,
  397. u16 *key_param_len)
  398. {
  399. int cur_key_param_len;
  400. u8 i;
  401. /* Multi-key_param_set TLV is supported */
  402. for (i = 0; i < NUM_WEP_KEYS; i++) {
  403. if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
  404. (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
  405. key_param_set->type =
  406. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  407. /* Key_param_set WEP fixed length */
  408. #define KEYPARAMSET_WEP_FIXED_LEN 8
  409. key_param_set->length = cpu_to_le16((u16)
  410. (priv->wep_key[i].
  411. key_length +
  412. KEYPARAMSET_WEP_FIXED_LEN));
  413. key_param_set->key_type_id =
  414. cpu_to_le16(KEY_TYPE_ID_WEP);
  415. key_param_set->key_info =
  416. cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
  417. KEY_MCAST);
  418. key_param_set->key_len =
  419. cpu_to_le16(priv->wep_key[i].key_length);
  420. /* Set WEP key index */
  421. key_param_set->key[0] = i;
  422. /* Set default Tx key flag */
  423. if (i ==
  424. (priv->
  425. wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
  426. key_param_set->key[1] = 1;
  427. else
  428. key_param_set->key[1] = 0;
  429. memmove(&key_param_set->key[2],
  430. priv->wep_key[i].key_material,
  431. priv->wep_key[i].key_length);
  432. cur_key_param_len = priv->wep_key[i].key_length +
  433. KEYPARAMSET_WEP_FIXED_LEN +
  434. sizeof(struct mwifiex_ie_types_header);
  435. *key_param_len += (u16) cur_key_param_len;
  436. key_param_set =
  437. (struct mwifiex_ie_type_key_param_set *)
  438. ((u8 *)key_param_set +
  439. cur_key_param_len);
  440. } else if (!priv->wep_key[i].key_length) {
  441. continue;
  442. } else {
  443. dev_err(priv->adapter->dev,
  444. "key%d Length = %d is incorrect\n",
  445. (i + 1), priv->wep_key[i].key_length);
  446. return -1;
  447. }
  448. }
  449. return 0;
  450. }
  451. /*
  452. * This function prepares command to set/get/reset network key(s).
  453. *
  454. * Preparation includes -
  455. * - Setting command ID, action and proper size
  456. * - Setting WEP keys, WAPI keys or WPA keys along with required
  457. * encryption (TKIP, AES) (as required)
  458. * - Ensuring correct endian-ness
  459. */
  460. static int
  461. mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
  462. struct host_cmd_ds_command *cmd,
  463. u16 cmd_action, u32 cmd_oid,
  464. struct mwifiex_ds_encrypt_key *enc_key)
  465. {
  466. struct host_cmd_ds_802_11_key_material *key_material =
  467. &cmd->params.key_material;
  468. struct host_cmd_tlv_mac_addr *tlv_mac;
  469. u16 key_param_len = 0, cmd_size;
  470. int ret = 0;
  471. const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  472. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
  473. key_material->action = cpu_to_le16(cmd_action);
  474. if (cmd_action == HostCmd_ACT_GEN_GET) {
  475. cmd->size =
  476. cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
  477. return ret;
  478. }
  479. if (!enc_key) {
  480. memset(&key_material->key_param_set, 0,
  481. (NUM_WEP_KEYS *
  482. sizeof(struct mwifiex_ie_type_key_param_set)));
  483. ret = mwifiex_set_keyparamset_wep(priv,
  484. &key_material->key_param_set,
  485. &key_param_len);
  486. cmd->size = cpu_to_le16(key_param_len +
  487. sizeof(key_material->action) + S_DS_GEN);
  488. return ret;
  489. } else
  490. memset(&key_material->key_param_set, 0,
  491. sizeof(struct mwifiex_ie_type_key_param_set));
  492. if (enc_key->is_wapi_key) {
  493. dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
  494. key_material->key_param_set.key_type_id =
  495. cpu_to_le16(KEY_TYPE_ID_WAPI);
  496. if (cmd_oid == KEY_INFO_ENABLED)
  497. key_material->key_param_set.key_info =
  498. cpu_to_le16(KEY_ENABLED);
  499. else
  500. key_material->key_param_set.key_info =
  501. cpu_to_le16(!KEY_ENABLED);
  502. key_material->key_param_set.key[0] = enc_key->key_index;
  503. if (!priv->sec_info.wapi_key_on)
  504. key_material->key_param_set.key[1] = 1;
  505. else
  506. /* set 0 when re-key */
  507. key_material->key_param_set.key[1] = 0;
  508. if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
  509. /* WAPI pairwise key: unicast */
  510. key_material->key_param_set.key_info |=
  511. cpu_to_le16(KEY_UNICAST);
  512. } else { /* WAPI group key: multicast */
  513. key_material->key_param_set.key_info |=
  514. cpu_to_le16(KEY_MCAST);
  515. priv->sec_info.wapi_key_on = true;
  516. }
  517. key_material->key_param_set.type =
  518. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  519. key_material->key_param_set.key_len =
  520. cpu_to_le16(WAPI_KEY_LEN);
  521. memcpy(&key_material->key_param_set.key[2],
  522. enc_key->key_material, enc_key->key_len);
  523. memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
  524. enc_key->wapi_rxpn, WAPI_RXPN_LEN);
  525. key_material->key_param_set.length =
  526. cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
  527. key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
  528. sizeof(struct mwifiex_ie_types_header);
  529. cmd->size = cpu_to_le16(sizeof(key_material->action)
  530. + S_DS_GEN + key_param_len);
  531. return ret;
  532. }
  533. if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
  534. dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
  535. key_material->key_param_set.key_type_id =
  536. cpu_to_le16(KEY_TYPE_ID_AES);
  537. if (cmd_oid == KEY_INFO_ENABLED)
  538. key_material->key_param_set.key_info =
  539. cpu_to_le16(KEY_ENABLED);
  540. else
  541. key_material->key_param_set.key_info =
  542. cpu_to_le16(!KEY_ENABLED);
  543. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  544. /* AES pairwise key: unicast */
  545. key_material->key_param_set.key_info |=
  546. cpu_to_le16(KEY_UNICAST);
  547. else /* AES group key: multicast */
  548. key_material->key_param_set.key_info |=
  549. cpu_to_le16(KEY_MCAST);
  550. } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
  551. dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
  552. key_material->key_param_set.key_type_id =
  553. cpu_to_le16(KEY_TYPE_ID_TKIP);
  554. key_material->key_param_set.key_info =
  555. cpu_to_le16(KEY_ENABLED);
  556. if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
  557. /* TKIP pairwise key: unicast */
  558. key_material->key_param_set.key_info |=
  559. cpu_to_le16(KEY_UNICAST);
  560. else /* TKIP group key: multicast */
  561. key_material->key_param_set.key_info |=
  562. cpu_to_le16(KEY_MCAST);
  563. }
  564. if (key_material->key_param_set.key_type_id) {
  565. key_material->key_param_set.type =
  566. cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  567. key_material->key_param_set.key_len =
  568. cpu_to_le16((u16) enc_key->key_len);
  569. memcpy(key_material->key_param_set.key, enc_key->key_material,
  570. enc_key->key_len);
  571. key_material->key_param_set.length =
  572. cpu_to_le16((u16) enc_key->key_len +
  573. KEYPARAMSET_FIXED_LEN);
  574. key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
  575. + sizeof(struct mwifiex_ie_types_header);
  576. cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
  577. + key_param_len);
  578. if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
  579. tlv_mac = (void *)((u8 *)&key_material->key_param_set +
  580. key_param_len);
  581. tlv_mac->tlv.type = cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
  582. tlv_mac->tlv.len = cpu_to_le16(ETH_ALEN);
  583. memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
  584. cmd_size = key_param_len + S_DS_GEN +
  585. sizeof(key_material->action) +
  586. sizeof(struct host_cmd_tlv_mac_addr);
  587. } else {
  588. cmd_size = key_param_len + S_DS_GEN +
  589. sizeof(key_material->action);
  590. }
  591. cmd->size = cpu_to_le16(cmd_size);
  592. }
  593. return ret;
  594. }
  595. /*
  596. * This function prepares command to set/get 11d domain information.
  597. *
  598. * Preparation includes -
  599. * - Setting command ID, action and proper size
  600. * - Setting domain information fields (for SET only)
  601. * - Ensuring correct endian-ness
  602. */
  603. static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
  604. struct host_cmd_ds_command *cmd,
  605. u16 cmd_action)
  606. {
  607. struct mwifiex_adapter *adapter = priv->adapter;
  608. struct host_cmd_ds_802_11d_domain_info *domain_info =
  609. &cmd->params.domain_info;
  610. struct mwifiex_ietypes_domain_param_set *domain =
  611. &domain_info->domain;
  612. u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
  613. dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
  614. cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
  615. domain_info->action = cpu_to_le16(cmd_action);
  616. if (cmd_action == HostCmd_ACT_GEN_GET) {
  617. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  618. return 0;
  619. }
  620. /* Set domain info fields */
  621. domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
  622. memcpy(domain->country_code, adapter->domain_reg.country_code,
  623. sizeof(domain->country_code));
  624. domain->header.len =
  625. cpu_to_le16((no_of_triplet *
  626. sizeof(struct ieee80211_country_ie_triplet))
  627. + sizeof(domain->country_code));
  628. if (no_of_triplet) {
  629. memcpy(domain->triplet, adapter->domain_reg.triplet,
  630. no_of_triplet * sizeof(struct
  631. ieee80211_country_ie_triplet));
  632. cmd->size = cpu_to_le16(sizeof(domain_info->action) +
  633. le16_to_cpu(domain->header.len) +
  634. sizeof(struct mwifiex_ie_types_header)
  635. + S_DS_GEN);
  636. } else {
  637. cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
  638. }
  639. return 0;
  640. }
  641. /*
  642. * This function prepares command to set/get RF channel.
  643. *
  644. * Preparation includes -
  645. * - Setting command ID, action and proper size
  646. * - Setting RF type and current RF channel (for SET only)
  647. * - Ensuring correct endian-ness
  648. */
  649. static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv,
  650. struct host_cmd_ds_command *cmd,
  651. u16 cmd_action, u16 *channel)
  652. {
  653. struct host_cmd_ds_802_11_rf_channel *rf_chan =
  654. &cmd->params.rf_channel;
  655. uint16_t rf_type = le16_to_cpu(rf_chan->rf_type);
  656. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL);
  657. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel)
  658. + S_DS_GEN);
  659. if (cmd_action == HostCmd_ACT_GEN_SET) {
  660. if ((priv->adapter->adhoc_start_band & BAND_A) ||
  661. (priv->adapter->adhoc_start_band & BAND_AN))
  662. rf_chan->rf_type =
  663. cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A);
  664. rf_type = le16_to_cpu(rf_chan->rf_type);
  665. SET_SECONDARYCHAN(rf_type, priv->adapter->sec_chan_offset);
  666. rf_chan->current_channel = cpu_to_le16(*channel);
  667. }
  668. rf_chan->action = cpu_to_le16(cmd_action);
  669. return 0;
  670. }
  671. /*
  672. * This function prepares command to set/get IBSS coalescing status.
  673. *
  674. * Preparation includes -
  675. * - Setting command ID, action and proper size
  676. * - Setting status to enable or disable (for SET only)
  677. * - Ensuring correct endian-ness
  678. */
  679. static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
  680. u16 cmd_action, u16 *enable)
  681. {
  682. struct host_cmd_ds_802_11_ibss_status *ibss_coal =
  683. &(cmd->params.ibss_coalescing);
  684. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
  685. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
  686. S_DS_GEN);
  687. cmd->result = 0;
  688. ibss_coal->action = cpu_to_le16(cmd_action);
  689. switch (cmd_action) {
  690. case HostCmd_ACT_GEN_SET:
  691. if (enable)
  692. ibss_coal->enable = cpu_to_le16(*enable);
  693. else
  694. ibss_coal->enable = 0;
  695. break;
  696. /* In other case.. Nothing to do */
  697. case HostCmd_ACT_GEN_GET:
  698. default:
  699. break;
  700. }
  701. return 0;
  702. }
  703. /*
  704. * This function prepares command to set/get register value.
  705. *
  706. * Preparation includes -
  707. * - Setting command ID, action and proper size
  708. * - Setting register offset (for both GET and SET) and
  709. * register value (for SET only)
  710. * - Ensuring correct endian-ness
  711. *
  712. * The following type of registers can be accessed with this function -
  713. * - MAC register
  714. * - BBP register
  715. * - RF register
  716. * - PMIC register
  717. * - CAU register
  718. * - EEPROM
  719. */
  720. static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
  721. u16 cmd_action, void *data_buf)
  722. {
  723. struct mwifiex_ds_reg_rw *reg_rw = data_buf;
  724. switch (le16_to_cpu(cmd->command)) {
  725. case HostCmd_CMD_MAC_REG_ACCESS:
  726. {
  727. struct host_cmd_ds_mac_reg_access *mac_reg;
  728. cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
  729. mac_reg = &cmd->params.mac_reg;
  730. mac_reg->action = cpu_to_le16(cmd_action);
  731. mac_reg->offset =
  732. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  733. mac_reg->value = reg_rw->value;
  734. break;
  735. }
  736. case HostCmd_CMD_BBP_REG_ACCESS:
  737. {
  738. struct host_cmd_ds_bbp_reg_access *bbp_reg;
  739. cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
  740. bbp_reg = &cmd->params.bbp_reg;
  741. bbp_reg->action = cpu_to_le16(cmd_action);
  742. bbp_reg->offset =
  743. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  744. bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
  745. break;
  746. }
  747. case HostCmd_CMD_RF_REG_ACCESS:
  748. {
  749. struct host_cmd_ds_rf_reg_access *rf_reg;
  750. cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
  751. rf_reg = &cmd->params.rf_reg;
  752. rf_reg->action = cpu_to_le16(cmd_action);
  753. rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  754. rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
  755. break;
  756. }
  757. case HostCmd_CMD_PMIC_REG_ACCESS:
  758. {
  759. struct host_cmd_ds_pmic_reg_access *pmic_reg;
  760. cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
  761. pmic_reg = &cmd->params.pmic_reg;
  762. pmic_reg->action = cpu_to_le16(cmd_action);
  763. pmic_reg->offset =
  764. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  765. pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
  766. break;
  767. }
  768. case HostCmd_CMD_CAU_REG_ACCESS:
  769. {
  770. struct host_cmd_ds_rf_reg_access *cau_reg;
  771. cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
  772. cau_reg = &cmd->params.rf_reg;
  773. cau_reg->action = cpu_to_le16(cmd_action);
  774. cau_reg->offset =
  775. cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
  776. cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
  777. break;
  778. }
  779. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  780. {
  781. struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
  782. struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
  783. &cmd->params.eeprom;
  784. cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
  785. cmd_eeprom->action = cpu_to_le16(cmd_action);
  786. cmd_eeprom->offset = rd_eeprom->offset;
  787. cmd_eeprom->byte_count = rd_eeprom->byte_count;
  788. cmd_eeprom->value = 0;
  789. break;
  790. }
  791. default:
  792. return -1;
  793. }
  794. return 0;
  795. }
  796. /*
  797. * This function prepares command to set PCI-Express
  798. * host buffer configuration
  799. *
  800. * Preparation includes -
  801. * - Setting command ID, action and proper size
  802. * - Setting host buffer configuration
  803. * - Ensuring correct endian-ness
  804. */
  805. static int
  806. mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
  807. struct host_cmd_ds_command *cmd, u16 action)
  808. {
  809. struct host_cmd_ds_pcie_details *host_spec =
  810. &cmd->params.pcie_host_spec;
  811. struct pcie_service_card *card = priv->adapter->card;
  812. phys_addr_t *buf_pa;
  813. cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
  814. cmd->size = cpu_to_le16(sizeof(struct
  815. host_cmd_ds_pcie_details) + S_DS_GEN);
  816. cmd->result = 0;
  817. memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
  818. if (action != HostCmd_ACT_GEN_SET)
  819. return 0;
  820. /* Send the ring base addresses and count to firmware */
  821. host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
  822. host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
  823. host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
  824. host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
  825. host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
  826. host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
  827. host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
  828. host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
  829. host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
  830. if (card->sleep_cookie) {
  831. buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie);
  832. host_spec->sleep_cookie_addr_lo = (u32) *buf_pa;
  833. host_spec->sleep_cookie_addr_hi = (u32) (((u64)*buf_pa) >> 32);
  834. dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
  835. host_spec->sleep_cookie_addr_lo);
  836. }
  837. return 0;
  838. }
  839. /*
  840. * This function prepares command for event subscription, configuration
  841. * and query. Events can be subscribed or unsubscribed. Current subscribed
  842. * events can be queried. Also, current subscribed events are reported in
  843. * every FW response.
  844. */
  845. static int
  846. mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
  847. struct host_cmd_ds_command *cmd,
  848. struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
  849. {
  850. struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
  851. struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
  852. u16 event_bitmap;
  853. u8 *pos;
  854. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
  855. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
  856. S_DS_GEN);
  857. subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
  858. dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
  859. /*For query requests, no configuration TLV structures are to be added.*/
  860. if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
  861. return 0;
  862. subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
  863. event_bitmap = subsc_evt_cfg->events;
  864. dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
  865. event_bitmap);
  866. if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
  867. (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
  868. (event_bitmap == 0)) {
  869. dev_dbg(priv->adapter->dev, "Error: No event specified "
  870. "for bitwise action type\n");
  871. return -EINVAL;
  872. }
  873. /*
  874. * Append TLV structures for each of the specified events for
  875. * subscribing or re-configuring. This is not required for
  876. * bitwise unsubscribing request.
  877. */
  878. if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
  879. return 0;
  880. pos = ((u8 *)subsc_evt) +
  881. sizeof(struct host_cmd_ds_802_11_subsc_evt);
  882. if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
  883. rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
  884. rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
  885. rssi_tlv->header.len =
  886. cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
  887. sizeof(struct mwifiex_ie_types_header));
  888. rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
  889. rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
  890. dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
  891. "RSSI:-%d dBm, Freq:%d\n",
  892. subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
  893. subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
  894. pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
  895. le16_add_cpu(&cmd->size,
  896. sizeof(struct mwifiex_ie_types_rssi_threshold));
  897. }
  898. if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
  899. rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
  900. rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
  901. rssi_tlv->header.len =
  902. cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
  903. sizeof(struct mwifiex_ie_types_header));
  904. rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
  905. rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
  906. dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
  907. "RSSI:-%d dBm, Freq:%d\n",
  908. subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
  909. subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
  910. pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
  911. le16_add_cpu(&cmd->size,
  912. sizeof(struct mwifiex_ie_types_rssi_threshold));
  913. }
  914. return 0;
  915. }
  916. /*
  917. * This function prepares the commands before sending them to the firmware.
  918. *
  919. * This is a generic function which calls specific command preparation
  920. * routines based upon the command number.
  921. */
  922. int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
  923. u16 cmd_action, u32 cmd_oid,
  924. void *data_buf, void *cmd_buf)
  925. {
  926. struct host_cmd_ds_command *cmd_ptr = cmd_buf;
  927. int ret = 0;
  928. /* Prepare command */
  929. switch (cmd_no) {
  930. case HostCmd_CMD_GET_HW_SPEC:
  931. ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
  932. break;
  933. case HostCmd_CMD_MAC_CONTROL:
  934. ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
  935. data_buf);
  936. break;
  937. case HostCmd_CMD_802_11_MAC_ADDRESS:
  938. ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
  939. cmd_action);
  940. break;
  941. case HostCmd_CMD_MAC_MULTICAST_ADR:
  942. ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
  943. data_buf);
  944. break;
  945. case HostCmd_CMD_TX_RATE_CFG:
  946. ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
  947. data_buf);
  948. break;
  949. case HostCmd_CMD_TXPWR_CFG:
  950. ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
  951. data_buf);
  952. break;
  953. case HostCmd_CMD_RF_TX_PWR:
  954. ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
  955. data_buf);
  956. break;
  957. case HostCmd_CMD_802_11_PS_MODE_ENH:
  958. ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
  959. (uint16_t)cmd_oid, data_buf);
  960. break;
  961. case HostCmd_CMD_802_11_HS_CFG_ENH:
  962. ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
  963. (struct mwifiex_hs_config_param *) data_buf);
  964. break;
  965. case HostCmd_CMD_802_11_SCAN:
  966. ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
  967. break;
  968. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  969. ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
  970. break;
  971. case HostCmd_CMD_802_11_ASSOCIATE:
  972. ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
  973. break;
  974. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  975. ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
  976. data_buf);
  977. break;
  978. case HostCmd_CMD_802_11_AD_HOC_START:
  979. ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
  980. data_buf);
  981. break;
  982. case HostCmd_CMD_802_11_GET_LOG:
  983. ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
  984. break;
  985. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  986. ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
  987. data_buf);
  988. break;
  989. case HostCmd_CMD_802_11_AD_HOC_STOP:
  990. ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
  991. break;
  992. case HostCmd_CMD_RSSI_INFO:
  993. ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
  994. break;
  995. case HostCmd_CMD_802_11_SNMP_MIB:
  996. ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
  997. cmd_oid, data_buf);
  998. break;
  999. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  1000. cmd_ptr->command =
  1001. cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
  1002. cmd_ptr->size =
  1003. cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
  1004. S_DS_GEN);
  1005. priv->tx_rate = 0;
  1006. ret = 0;
  1007. break;
  1008. case HostCmd_CMD_VERSION_EXT:
  1009. cmd_ptr->command = cpu_to_le16(cmd_no);
  1010. cmd_ptr->params.verext.version_str_sel =
  1011. (u8) (*((u32 *) data_buf));
  1012. memcpy(&cmd_ptr->params, data_buf,
  1013. sizeof(struct host_cmd_ds_version_ext));
  1014. cmd_ptr->size =
  1015. cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
  1016. S_DS_GEN);
  1017. ret = 0;
  1018. break;
  1019. case HostCmd_CMD_802_11_RF_CHANNEL:
  1020. ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action,
  1021. data_buf);
  1022. break;
  1023. case HostCmd_CMD_FUNC_INIT:
  1024. if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
  1025. priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  1026. cmd_ptr->command = cpu_to_le16(cmd_no);
  1027. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  1028. break;
  1029. case HostCmd_CMD_FUNC_SHUTDOWN:
  1030. priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
  1031. cmd_ptr->command = cpu_to_le16(cmd_no);
  1032. cmd_ptr->size = cpu_to_le16(S_DS_GEN);
  1033. break;
  1034. case HostCmd_CMD_11N_ADDBA_REQ:
  1035. ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
  1036. break;
  1037. case HostCmd_CMD_11N_DELBA:
  1038. ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
  1039. break;
  1040. case HostCmd_CMD_11N_ADDBA_RSP:
  1041. ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
  1042. break;
  1043. case HostCmd_CMD_802_11_KEY_MATERIAL:
  1044. ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
  1045. cmd_action, cmd_oid,
  1046. data_buf);
  1047. break;
  1048. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  1049. ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
  1050. cmd_action);
  1051. break;
  1052. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  1053. ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
  1054. data_buf);
  1055. break;
  1056. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  1057. ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
  1058. data_buf);
  1059. break;
  1060. case HostCmd_CMD_11N_CFG:
  1061. ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action, data_buf);
  1062. break;
  1063. case HostCmd_CMD_WMM_GET_STATUS:
  1064. dev_dbg(priv->adapter->dev,
  1065. "cmd: WMM: WMM_GET_STATUS cmd sent\n");
  1066. cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
  1067. cmd_ptr->size =
  1068. cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
  1069. S_DS_GEN);
  1070. ret = 0;
  1071. break;
  1072. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  1073. ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
  1074. data_buf);
  1075. break;
  1076. case HostCmd_CMD_MAC_REG_ACCESS:
  1077. case HostCmd_CMD_BBP_REG_ACCESS:
  1078. case HostCmd_CMD_RF_REG_ACCESS:
  1079. case HostCmd_CMD_PMIC_REG_ACCESS:
  1080. case HostCmd_CMD_CAU_REG_ACCESS:
  1081. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  1082. ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
  1083. break;
  1084. case HostCmd_CMD_SET_BSS_MODE:
  1085. cmd_ptr->command = cpu_to_le16(cmd_no);
  1086. if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
  1087. cmd_ptr->params.bss_mode.con_type =
  1088. CONNECTION_TYPE_ADHOC;
  1089. else if (priv->bss_mode == NL80211_IFTYPE_STATION)
  1090. cmd_ptr->params.bss_mode.con_type =
  1091. CONNECTION_TYPE_INFRA;
  1092. cmd_ptr->size = cpu_to_le16(sizeof(struct
  1093. host_cmd_ds_set_bss_mode) + S_DS_GEN);
  1094. ret = 0;
  1095. break;
  1096. case HostCmd_CMD_PCIE_DESC_DETAILS:
  1097. ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
  1098. break;
  1099. case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
  1100. ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
  1101. break;
  1102. default:
  1103. dev_err(priv->adapter->dev,
  1104. "PREP_CMD: unknown cmd- %#x\n", cmd_no);
  1105. ret = -1;
  1106. break;
  1107. }
  1108. return ret;
  1109. }
  1110. /*
  1111. * This function issues commands to initialize firmware.
  1112. *
  1113. * This is called after firmware download to bring the card to
  1114. * working state.
  1115. *
  1116. * The following commands are issued sequentially -
  1117. * - Set PCI-Express host buffer configuration (PCIE only)
  1118. * - Function init (for first interface only)
  1119. * - Read MAC address (for first interface only)
  1120. * - Reconfigure Tx buffer size (for first interface only)
  1121. * - Enable auto deep sleep (for first interface only)
  1122. * - Get Tx rate
  1123. * - Get Tx power
  1124. * - Set IBSS coalescing status
  1125. * - Set AMSDU aggregation control
  1126. * - Set 11d control
  1127. * - Set MAC control (this must be the last command to initialize firmware)
  1128. */
  1129. int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
  1130. {
  1131. int ret;
  1132. u16 enable = true;
  1133. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  1134. struct mwifiex_ds_auto_ds auto_ds;
  1135. enum state_11d_t state_11d;
  1136. struct mwifiex_ds_11n_tx_cfg tx_cfg;
  1137. if (first_sta) {
  1138. if (priv->adapter->iface_type == MWIFIEX_PCIE) {
  1139. ret = mwifiex_send_cmd_async(priv,
  1140. HostCmd_CMD_PCIE_DESC_DETAILS,
  1141. HostCmd_ACT_GEN_SET, 0, NULL);
  1142. if (ret)
  1143. return -1;
  1144. }
  1145. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
  1146. HostCmd_ACT_GEN_SET, 0, NULL);
  1147. if (ret)
  1148. return -1;
  1149. /* Read MAC address from HW */
  1150. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
  1151. HostCmd_ACT_GEN_GET, 0, NULL);
  1152. if (ret)
  1153. return -1;
  1154. /* Reconfigure tx buf size */
  1155. ret = mwifiex_send_cmd_async(priv,
  1156. HostCmd_CMD_RECONFIGURE_TX_BUFF,
  1157. HostCmd_ACT_GEN_SET, 0,
  1158. &priv->adapter->tx_buf_size);
  1159. if (ret)
  1160. return -1;
  1161. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1162. /* Enable IEEE PS by default */
  1163. priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1164. ret = mwifiex_send_cmd_async(
  1165. priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1166. EN_AUTO_PS, BITMAP_STA_PS, NULL);
  1167. if (ret)
  1168. return -1;
  1169. }
  1170. }
  1171. /* get tx rate */
  1172. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
  1173. HostCmd_ACT_GEN_GET, 0, NULL);
  1174. if (ret)
  1175. return -1;
  1176. priv->data_rate = 0;
  1177. /* get tx power */
  1178. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_RF_TX_PWR,
  1179. HostCmd_ACT_GEN_GET, 0, NULL);
  1180. if (ret)
  1181. return -1;
  1182. if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
  1183. /* set ibss coalescing_status */
  1184. ret = mwifiex_send_cmd_async(
  1185. priv, HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  1186. HostCmd_ACT_GEN_SET, 0, &enable);
  1187. if (ret)
  1188. return -1;
  1189. }
  1190. memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
  1191. amsdu_aggr_ctrl.enable = true;
  1192. /* Send request to firmware */
  1193. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
  1194. HostCmd_ACT_GEN_SET, 0,
  1195. &amsdu_aggr_ctrl);
  1196. if (ret)
  1197. return -1;
  1198. /* MAC Control must be the last command in init_fw */
  1199. /* set MAC Control */
  1200. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  1201. HostCmd_ACT_GEN_SET, 0,
  1202. &priv->curr_pkt_filter);
  1203. if (ret)
  1204. return -1;
  1205. if (first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
  1206. priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1207. /* Enable auto deep sleep */
  1208. auto_ds.auto_ds = DEEP_SLEEP_ON;
  1209. auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  1210. ret = mwifiex_send_cmd_async(priv,
  1211. HostCmd_CMD_802_11_PS_MODE_ENH,
  1212. EN_AUTO_PS, BITMAP_AUTO_DS,
  1213. &auto_ds);
  1214. if (ret)
  1215. return -1;
  1216. }
  1217. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  1218. /* Send cmd to FW to enable/disable 11D function */
  1219. state_11d = ENABLE_11D;
  1220. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1221. HostCmd_ACT_GEN_SET, DOT11D_I,
  1222. &state_11d);
  1223. if (ret)
  1224. dev_err(priv->adapter->dev,
  1225. "11D: failed to enable 11D\n");
  1226. }
  1227. /* Send cmd to FW to configure 11n specific configuration
  1228. * (Short GI, Channel BW, Green field support etc.) for transmit
  1229. */
  1230. tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
  1231. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
  1232. HostCmd_ACT_GEN_SET, 0, &tx_cfg);
  1233. /* set last_init_cmd */
  1234. priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
  1235. ret = -EINPROGRESS;
  1236. return ret;
  1237. }