sta_cmdresp.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. /*
  2. * Marvell Wireless LAN device driver: station command response 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. #include "11ac.h"
  27. /*
  28. * This function handles the command response error case.
  29. *
  30. * For scan response error, the function cancels all the pending
  31. * scan commands and generates an event to inform the applications
  32. * of the scan completion.
  33. *
  34. * For Power Save command failure, we do not retry enter PS
  35. * command in case of Ad-hoc mode.
  36. *
  37. * For all other response errors, the current command buffer is freed
  38. * and returned to the free command queue.
  39. */
  40. static void
  41. mwifiex_process_cmdresp_error(struct mwifiex_private *priv,
  42. struct host_cmd_ds_command *resp)
  43. {
  44. struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
  45. struct mwifiex_adapter *adapter = priv->adapter;
  46. struct host_cmd_ds_802_11_ps_mode_enh *pm;
  47. unsigned long flags;
  48. dev_err(adapter->dev, "CMD_RESP: cmd %#x error, result=%#x\n",
  49. resp->command, resp->result);
  50. if (adapter->curr_cmd->wait_q_enabled)
  51. adapter->cmd_wait_q.status = -1;
  52. switch (le16_to_cpu(resp->command)) {
  53. case HostCmd_CMD_802_11_PS_MODE_ENH:
  54. pm = &resp->params.psmode_enh;
  55. dev_err(adapter->dev,
  56. "PS_MODE_ENH cmd failed: result=0x%x action=0x%X\n",
  57. resp->result, le16_to_cpu(pm->action));
  58. /* We do not re-try enter-ps command in ad-hoc mode. */
  59. if (le16_to_cpu(pm->action) == EN_AUTO_PS &&
  60. (le16_to_cpu(pm->params.ps_bitmap) & BITMAP_STA_PS) &&
  61. priv->bss_mode == NL80211_IFTYPE_ADHOC)
  62. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  63. break;
  64. case HostCmd_CMD_802_11_SCAN:
  65. /* Cancel all pending scan command */
  66. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  67. list_for_each_entry_safe(cmd_node, tmp_node,
  68. &adapter->scan_pending_q, list) {
  69. list_del(&cmd_node->list);
  70. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  71. flags);
  72. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  73. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  74. }
  75. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  76. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  77. adapter->scan_processing = false;
  78. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  79. if (priv->report_scan_result)
  80. priv->report_scan_result = false;
  81. break;
  82. case HostCmd_CMD_MAC_CONTROL:
  83. break;
  84. default:
  85. break;
  86. }
  87. /* Handling errors here */
  88. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  89. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  90. adapter->curr_cmd = NULL;
  91. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  92. }
  93. /*
  94. * This function handles the command response of get RSSI info.
  95. *
  96. * Handling includes changing the header fields into CPU format
  97. * and saving the following parameters in driver -
  98. * - Last data and beacon RSSI value
  99. * - Average data and beacon RSSI value
  100. * - Last data and beacon NF value
  101. * - Average data and beacon NF value
  102. *
  103. * The parameters are send to the application as well, along with
  104. * calculated SNR values.
  105. */
  106. static int mwifiex_ret_802_11_rssi_info(struct mwifiex_private *priv,
  107. struct host_cmd_ds_command *resp)
  108. {
  109. struct host_cmd_ds_802_11_rssi_info_rsp *rssi_info_rsp =
  110. &resp->params.rssi_info_rsp;
  111. struct mwifiex_ds_misc_subsc_evt *subsc_evt =
  112. &priv->async_subsc_evt_storage;
  113. priv->data_rssi_last = le16_to_cpu(rssi_info_rsp->data_rssi_last);
  114. priv->data_nf_last = le16_to_cpu(rssi_info_rsp->data_nf_last);
  115. priv->data_rssi_avg = le16_to_cpu(rssi_info_rsp->data_rssi_avg);
  116. priv->data_nf_avg = le16_to_cpu(rssi_info_rsp->data_nf_avg);
  117. priv->bcn_rssi_last = le16_to_cpu(rssi_info_rsp->bcn_rssi_last);
  118. priv->bcn_nf_last = le16_to_cpu(rssi_info_rsp->bcn_nf_last);
  119. priv->bcn_rssi_avg = le16_to_cpu(rssi_info_rsp->bcn_rssi_avg);
  120. priv->bcn_nf_avg = le16_to_cpu(rssi_info_rsp->bcn_nf_avg);
  121. if (priv->subsc_evt_rssi_state == EVENT_HANDLED)
  122. return 0;
  123. memset(subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
  124. /* Resubscribe low and high rssi events with new thresholds */
  125. subsc_evt->events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
  126. subsc_evt->action = HostCmd_ACT_BITWISE_SET;
  127. if (priv->subsc_evt_rssi_state == RSSI_LOW_RECVD) {
  128. subsc_evt->bcn_l_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg -
  129. priv->cqm_rssi_hyst);
  130. subsc_evt->bcn_h_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
  131. } else if (priv->subsc_evt_rssi_state == RSSI_HIGH_RECVD) {
  132. subsc_evt->bcn_l_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
  133. subsc_evt->bcn_h_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg +
  134. priv->cqm_rssi_hyst);
  135. }
  136. subsc_evt->bcn_l_rssi_cfg.evt_freq = 1;
  137. subsc_evt->bcn_h_rssi_cfg.evt_freq = 1;
  138. priv->subsc_evt_rssi_state = EVENT_HANDLED;
  139. mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  140. 0, 0, subsc_evt);
  141. return 0;
  142. }
  143. /*
  144. * This function handles the command response of set/get SNMP
  145. * MIB parameters.
  146. *
  147. * Handling includes changing the header fields into CPU format
  148. * and saving the parameter in driver.
  149. *
  150. * The following parameters are supported -
  151. * - Fragmentation threshold
  152. * - RTS threshold
  153. * - Short retry limit
  154. */
  155. static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
  156. struct host_cmd_ds_command *resp,
  157. u32 *data_buf)
  158. {
  159. struct host_cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
  160. u16 oid = le16_to_cpu(smib->oid);
  161. u16 query_type = le16_to_cpu(smib->query_type);
  162. u32 ul_temp;
  163. dev_dbg(priv->adapter->dev, "info: SNMP_RESP: oid value = %#x,"
  164. " query_type = %#x, buf size = %#x\n",
  165. oid, query_type, le16_to_cpu(smib->buf_size));
  166. if (query_type == HostCmd_ACT_GEN_GET) {
  167. ul_temp = le16_to_cpu(*((__le16 *) (smib->value)));
  168. if (data_buf)
  169. *data_buf = ul_temp;
  170. switch (oid) {
  171. case FRAG_THRESH_I:
  172. dev_dbg(priv->adapter->dev,
  173. "info: SNMP_RESP: FragThsd =%u\n", ul_temp);
  174. break;
  175. case RTS_THRESH_I:
  176. dev_dbg(priv->adapter->dev,
  177. "info: SNMP_RESP: RTSThsd =%u\n", ul_temp);
  178. break;
  179. case SHORT_RETRY_LIM_I:
  180. dev_dbg(priv->adapter->dev,
  181. "info: SNMP_RESP: TxRetryCount=%u\n", ul_temp);
  182. break;
  183. case DTIM_PERIOD_I:
  184. dev_dbg(priv->adapter->dev,
  185. "info: SNMP_RESP: DTIM period=%u\n", ul_temp);
  186. default:
  187. break;
  188. }
  189. }
  190. return 0;
  191. }
  192. /*
  193. * This function handles the command response of get log request
  194. *
  195. * Handling includes changing the header fields into CPU format
  196. * and sending the received parameters to application.
  197. */
  198. static int mwifiex_ret_get_log(struct mwifiex_private *priv,
  199. struct host_cmd_ds_command *resp,
  200. struct mwifiex_ds_get_stats *stats)
  201. {
  202. struct host_cmd_ds_802_11_get_log *get_log =
  203. &resp->params.get_log;
  204. if (stats) {
  205. stats->mcast_tx_frame = le32_to_cpu(get_log->mcast_tx_frame);
  206. stats->failed = le32_to_cpu(get_log->failed);
  207. stats->retry = le32_to_cpu(get_log->retry);
  208. stats->multi_retry = le32_to_cpu(get_log->multi_retry);
  209. stats->frame_dup = le32_to_cpu(get_log->frame_dup);
  210. stats->rts_success = le32_to_cpu(get_log->rts_success);
  211. stats->rts_failure = le32_to_cpu(get_log->rts_failure);
  212. stats->ack_failure = le32_to_cpu(get_log->ack_failure);
  213. stats->rx_frag = le32_to_cpu(get_log->rx_frag);
  214. stats->mcast_rx_frame = le32_to_cpu(get_log->mcast_rx_frame);
  215. stats->fcs_error = le32_to_cpu(get_log->fcs_error);
  216. stats->tx_frame = le32_to_cpu(get_log->tx_frame);
  217. stats->wep_icv_error[0] =
  218. le32_to_cpu(get_log->wep_icv_err_cnt[0]);
  219. stats->wep_icv_error[1] =
  220. le32_to_cpu(get_log->wep_icv_err_cnt[1]);
  221. stats->wep_icv_error[2] =
  222. le32_to_cpu(get_log->wep_icv_err_cnt[2]);
  223. stats->wep_icv_error[3] =
  224. le32_to_cpu(get_log->wep_icv_err_cnt[3]);
  225. }
  226. return 0;
  227. }
  228. /*
  229. * This function handles the command response of set/get Tx rate
  230. * configurations.
  231. *
  232. * Handling includes changing the header fields into CPU format
  233. * and saving the following parameters in driver -
  234. * - DSSS rate bitmap
  235. * - OFDM rate bitmap
  236. * - HT MCS rate bitmaps
  237. *
  238. * Based on the new rate bitmaps, the function re-evaluates if
  239. * auto data rate has been activated. If not, it sends another
  240. * query to the firmware to get the current Tx data rate.
  241. */
  242. static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
  243. struct host_cmd_ds_command *resp)
  244. {
  245. struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
  246. struct mwifiex_rate_scope *rate_scope;
  247. struct mwifiex_ie_types_header *head;
  248. u16 tlv, tlv_buf_len, tlv_buf_left;
  249. u8 *tlv_buf;
  250. u32 i;
  251. tlv_buf = ((u8 *)rate_cfg) + sizeof(struct host_cmd_ds_tx_rate_cfg);
  252. tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*rate_cfg);
  253. while (tlv_buf_left >= sizeof(*head)) {
  254. head = (struct mwifiex_ie_types_header *)tlv_buf;
  255. tlv = le16_to_cpu(head->type);
  256. tlv_buf_len = le16_to_cpu(head->len);
  257. if (tlv_buf_left < (sizeof(*head) + tlv_buf_len))
  258. break;
  259. switch (tlv) {
  260. case TLV_TYPE_RATE_SCOPE:
  261. rate_scope = (struct mwifiex_rate_scope *) tlv_buf;
  262. priv->bitmap_rates[0] =
  263. le16_to_cpu(rate_scope->hr_dsss_rate_bitmap);
  264. priv->bitmap_rates[1] =
  265. le16_to_cpu(rate_scope->ofdm_rate_bitmap);
  266. for (i = 0;
  267. i <
  268. sizeof(rate_scope->ht_mcs_rate_bitmap) /
  269. sizeof(u16); i++)
  270. priv->bitmap_rates[2 + i] =
  271. le16_to_cpu(rate_scope->
  272. ht_mcs_rate_bitmap[i]);
  273. break;
  274. /* Add RATE_DROP tlv here */
  275. }
  276. tlv_buf += (sizeof(*head) + tlv_buf_len);
  277. tlv_buf_left -= (sizeof(*head) + tlv_buf_len);
  278. }
  279. priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
  280. if (priv->is_data_rate_auto)
  281. priv->data_rate = 0;
  282. else
  283. return mwifiex_send_cmd_async(priv,
  284. HostCmd_CMD_802_11_TX_RATE_QUERY,
  285. HostCmd_ACT_GEN_GET, 0, NULL);
  286. return 0;
  287. }
  288. /*
  289. * This function handles the command response of get Tx power level.
  290. *
  291. * Handling includes saving the maximum and minimum Tx power levels
  292. * in driver, as well as sending the values to user.
  293. */
  294. static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
  295. {
  296. int length, max_power = -1, min_power = -1;
  297. struct mwifiex_types_power_group *pg_tlv_hdr;
  298. struct mwifiex_power_group *pg;
  299. if (!data_buf)
  300. return -1;
  301. pg_tlv_hdr = (struct mwifiex_types_power_group *)((u8 *)data_buf);
  302. pg = (struct mwifiex_power_group *)
  303. ((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
  304. length = le16_to_cpu(pg_tlv_hdr->length);
  305. /* At least one structure required to update power */
  306. if (length < sizeof(struct mwifiex_power_group))
  307. return 0;
  308. max_power = pg->power_max;
  309. min_power = pg->power_min;
  310. length -= sizeof(struct mwifiex_power_group);
  311. while (length >= sizeof(struct mwifiex_power_group)) {
  312. pg++;
  313. if (max_power < pg->power_max)
  314. max_power = pg->power_max;
  315. if (min_power > pg->power_min)
  316. min_power = pg->power_min;
  317. length -= sizeof(struct mwifiex_power_group);
  318. }
  319. priv->min_tx_power_level = (u8) min_power;
  320. priv->max_tx_power_level = (u8) max_power;
  321. return 0;
  322. }
  323. /*
  324. * This function handles the command response of set/get Tx power
  325. * configurations.
  326. *
  327. * Handling includes changing the header fields into CPU format
  328. * and saving the current Tx power level in driver.
  329. */
  330. static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
  331. struct host_cmd_ds_command *resp)
  332. {
  333. struct mwifiex_adapter *adapter = priv->adapter;
  334. struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
  335. struct mwifiex_types_power_group *pg_tlv_hdr;
  336. struct mwifiex_power_group *pg;
  337. u16 action = le16_to_cpu(txp_cfg->action);
  338. u16 tlv_buf_left;
  339. pg_tlv_hdr = (struct mwifiex_types_power_group *)
  340. ((u8 *)txp_cfg +
  341. sizeof(struct host_cmd_ds_txpwr_cfg));
  342. pg = (struct mwifiex_power_group *)
  343. ((u8 *)pg_tlv_hdr +
  344. sizeof(struct mwifiex_types_power_group));
  345. tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*txp_cfg);
  346. if (tlv_buf_left <
  347. le16_to_cpu(pg_tlv_hdr->length) + sizeof(*pg_tlv_hdr))
  348. return 0;
  349. switch (action) {
  350. case HostCmd_ACT_GEN_GET:
  351. if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
  352. mwifiex_get_power_level(priv, pg_tlv_hdr);
  353. priv->tx_power_level = (u16) pg->power_min;
  354. break;
  355. case HostCmd_ACT_GEN_SET:
  356. if (!le32_to_cpu(txp_cfg->mode))
  357. break;
  358. if (pg->power_max == pg->power_min)
  359. priv->tx_power_level = (u16) pg->power_min;
  360. break;
  361. default:
  362. dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
  363. action);
  364. return 0;
  365. }
  366. dev_dbg(adapter->dev,
  367. "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
  368. priv->tx_power_level, priv->max_tx_power_level,
  369. priv->min_tx_power_level);
  370. return 0;
  371. }
  372. /*
  373. * This function handles the command response of get RF Tx power.
  374. */
  375. static int mwifiex_ret_rf_tx_power(struct mwifiex_private *priv,
  376. struct host_cmd_ds_command *resp)
  377. {
  378. struct host_cmd_ds_rf_tx_pwr *txp = &resp->params.txp;
  379. u16 action = le16_to_cpu(txp->action);
  380. priv->tx_power_level = le16_to_cpu(txp->cur_level);
  381. if (action == HostCmd_ACT_GEN_GET) {
  382. priv->max_tx_power_level = txp->max_power;
  383. priv->min_tx_power_level = txp->min_power;
  384. }
  385. dev_dbg(priv->adapter->dev,
  386. "Current TxPower Level=%d, Max Power=%d, Min Power=%d\n",
  387. priv->tx_power_level, priv->max_tx_power_level,
  388. priv->min_tx_power_level);
  389. return 0;
  390. }
  391. /*
  392. * This function handles the command response of set rf antenna
  393. */
  394. static int mwifiex_ret_rf_antenna(struct mwifiex_private *priv,
  395. struct host_cmd_ds_command *resp)
  396. {
  397. struct host_cmd_ds_rf_ant_mimo *ant_mimo = &resp->params.ant_mimo;
  398. struct host_cmd_ds_rf_ant_siso *ant_siso = &resp->params.ant_siso;
  399. struct mwifiex_adapter *adapter = priv->adapter;
  400. if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
  401. dev_dbg(adapter->dev,
  402. "RF_ANT_RESP: Tx action = 0x%x, Tx Mode = 0x%04x"
  403. " Rx action = 0x%x, Rx Mode = 0x%04x\n",
  404. le16_to_cpu(ant_mimo->action_tx),
  405. le16_to_cpu(ant_mimo->tx_ant_mode),
  406. le16_to_cpu(ant_mimo->action_rx),
  407. le16_to_cpu(ant_mimo->rx_ant_mode));
  408. else
  409. dev_dbg(adapter->dev,
  410. "RF_ANT_RESP: action = 0x%x, Mode = 0x%04x\n",
  411. le16_to_cpu(ant_siso->action),
  412. le16_to_cpu(ant_siso->ant_mode));
  413. return 0;
  414. }
  415. /*
  416. * This function handles the command response of set/get MAC address.
  417. *
  418. * Handling includes saving the MAC address in driver.
  419. */
  420. static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
  421. struct host_cmd_ds_command *resp)
  422. {
  423. struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
  424. &resp->params.mac_addr;
  425. memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
  426. dev_dbg(priv->adapter->dev,
  427. "info: set mac address: %pM\n", priv->curr_addr);
  428. return 0;
  429. }
  430. /*
  431. * This function handles the command response of set/get MAC multicast
  432. * address.
  433. */
  434. static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
  435. struct host_cmd_ds_command *resp)
  436. {
  437. return 0;
  438. }
  439. /*
  440. * This function handles the command response of get Tx rate query.
  441. *
  442. * Handling includes changing the header fields into CPU format
  443. * and saving the Tx rate and HT information parameters in driver.
  444. *
  445. * Both rate configuration and current data rate can be retrieved
  446. * with this request.
  447. */
  448. static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
  449. struct host_cmd_ds_command *resp)
  450. {
  451. priv->tx_rate = resp->params.tx_rate.tx_rate;
  452. priv->tx_htinfo = resp->params.tx_rate.ht_info;
  453. if (!priv->is_data_rate_auto)
  454. priv->data_rate =
  455. mwifiex_index_to_data_rate(priv, priv->tx_rate,
  456. priv->tx_htinfo);
  457. return 0;
  458. }
  459. /*
  460. * This function handles the command response of a deauthenticate
  461. * command.
  462. *
  463. * If the deauthenticated MAC matches the current BSS MAC, the connection
  464. * state is reset.
  465. */
  466. static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
  467. struct host_cmd_ds_command *resp)
  468. {
  469. struct mwifiex_adapter *adapter = priv->adapter;
  470. adapter->dbg.num_cmd_deauth++;
  471. if (!memcmp(resp->params.deauth.mac_addr,
  472. &priv->curr_bss_params.bss_descriptor.mac_address,
  473. sizeof(resp->params.deauth.mac_addr)))
  474. mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING);
  475. return 0;
  476. }
  477. /*
  478. * This function handles the command response of ad-hoc stop.
  479. *
  480. * The function resets the connection state in driver.
  481. */
  482. static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
  483. struct host_cmd_ds_command *resp)
  484. {
  485. mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING);
  486. return 0;
  487. }
  488. /*
  489. * This function handles the command response of set/get key material.
  490. *
  491. * Handling includes updating the driver parameters to reflect the
  492. * changes.
  493. */
  494. static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
  495. struct host_cmd_ds_command *resp)
  496. {
  497. struct host_cmd_ds_802_11_key_material *key =
  498. &resp->params.key_material;
  499. if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
  500. if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
  501. dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
  502. priv->wpa_is_gtk_set = true;
  503. priv->scan_block = false;
  504. }
  505. }
  506. memset(priv->aes_key.key_param_set.key, 0,
  507. sizeof(key->key_param_set.key));
  508. priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
  509. memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
  510. le16_to_cpu(priv->aes_key.key_param_set.key_len));
  511. return 0;
  512. }
  513. /*
  514. * This function handles the command response of get 11d domain information.
  515. */
  516. static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
  517. struct host_cmd_ds_command *resp)
  518. {
  519. struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
  520. &resp->params.domain_info_resp;
  521. struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
  522. u16 action = le16_to_cpu(domain_info->action);
  523. u8 no_of_triplet;
  524. no_of_triplet = (u8) ((le16_to_cpu(domain->header.len)
  525. - IEEE80211_COUNTRY_STRING_LEN)
  526. / sizeof(struct ieee80211_country_ie_triplet));
  527. dev_dbg(priv->adapter->dev,
  528. "info: 11D Domain Info Resp: no_of_triplet=%d\n",
  529. no_of_triplet);
  530. if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
  531. dev_warn(priv->adapter->dev,
  532. "11D: invalid number of triplets %d returned\n",
  533. no_of_triplet);
  534. return -1;
  535. }
  536. switch (action) {
  537. case HostCmd_ACT_GEN_SET: /* Proc Set Action */
  538. break;
  539. case HostCmd_ACT_GEN_GET:
  540. break;
  541. default:
  542. dev_err(priv->adapter->dev,
  543. "11D: invalid action:%d\n", domain_info->action);
  544. return -1;
  545. }
  546. return 0;
  547. }
  548. /*
  549. * This function handles the command response of get extended version.
  550. *
  551. * Handling includes forming the extended version string and sending it
  552. * to application.
  553. */
  554. static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
  555. struct host_cmd_ds_command *resp,
  556. struct host_cmd_ds_version_ext *version_ext)
  557. {
  558. struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
  559. if (version_ext) {
  560. version_ext->version_str_sel = ver_ext->version_str_sel;
  561. memcpy(version_ext->version_str, ver_ext->version_str,
  562. sizeof(char) * 128);
  563. memcpy(priv->version_str, ver_ext->version_str, 128);
  564. }
  565. return 0;
  566. }
  567. /*
  568. * This function handles the command response of remain on channel.
  569. */
  570. static int
  571. mwifiex_ret_remain_on_chan(struct mwifiex_private *priv,
  572. struct host_cmd_ds_command *resp,
  573. struct host_cmd_ds_remain_on_chan *roc_cfg)
  574. {
  575. struct host_cmd_ds_remain_on_chan *resp_cfg = &resp->params.roc_cfg;
  576. if (roc_cfg)
  577. memcpy(roc_cfg, resp_cfg, sizeof(*roc_cfg));
  578. return 0;
  579. }
  580. /*
  581. * This function handles the command response of P2P mode cfg.
  582. */
  583. static int
  584. mwifiex_ret_p2p_mode_cfg(struct mwifiex_private *priv,
  585. struct host_cmd_ds_command *resp,
  586. void *data_buf)
  587. {
  588. struct host_cmd_ds_p2p_mode_cfg *mode_cfg = &resp->params.mode_cfg;
  589. if (data_buf)
  590. *((u16 *)data_buf) = le16_to_cpu(mode_cfg->mode);
  591. return 0;
  592. }
  593. /*
  594. * This function handles the command response of register access.
  595. *
  596. * The register value and offset are returned to the user. For EEPROM
  597. * access, the byte count is also returned.
  598. */
  599. static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
  600. void *data_buf)
  601. {
  602. struct mwifiex_ds_reg_rw *reg_rw;
  603. struct mwifiex_ds_read_eeprom *eeprom;
  604. union reg {
  605. struct host_cmd_ds_mac_reg_access *mac;
  606. struct host_cmd_ds_bbp_reg_access *bbp;
  607. struct host_cmd_ds_rf_reg_access *rf;
  608. struct host_cmd_ds_pmic_reg_access *pmic;
  609. struct host_cmd_ds_802_11_eeprom_access *eeprom;
  610. } r;
  611. if (!data_buf)
  612. return 0;
  613. reg_rw = data_buf;
  614. eeprom = data_buf;
  615. switch (type) {
  616. case HostCmd_CMD_MAC_REG_ACCESS:
  617. r.mac = &resp->params.mac_reg;
  618. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
  619. reg_rw->value = r.mac->value;
  620. break;
  621. case HostCmd_CMD_BBP_REG_ACCESS:
  622. r.bbp = &resp->params.bbp_reg;
  623. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
  624. reg_rw->value = cpu_to_le32((u32) r.bbp->value);
  625. break;
  626. case HostCmd_CMD_RF_REG_ACCESS:
  627. r.rf = &resp->params.rf_reg;
  628. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
  629. reg_rw->value = cpu_to_le32((u32) r.bbp->value);
  630. break;
  631. case HostCmd_CMD_PMIC_REG_ACCESS:
  632. r.pmic = &resp->params.pmic_reg;
  633. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
  634. reg_rw->value = cpu_to_le32((u32) r.pmic->value);
  635. break;
  636. case HostCmd_CMD_CAU_REG_ACCESS:
  637. r.rf = &resp->params.rf_reg;
  638. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
  639. reg_rw->value = cpu_to_le32((u32) r.rf->value);
  640. break;
  641. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  642. r.eeprom = &resp->params.eeprom;
  643. pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
  644. if (le16_to_cpu(eeprom->byte_count) <
  645. le16_to_cpu(r.eeprom->byte_count)) {
  646. eeprom->byte_count = cpu_to_le16(0);
  647. pr_debug("info: EEPROM read length is too big\n");
  648. return -1;
  649. }
  650. eeprom->offset = r.eeprom->offset;
  651. eeprom->byte_count = r.eeprom->byte_count;
  652. if (le16_to_cpu(eeprom->byte_count) > 0)
  653. memcpy(&eeprom->value, &r.eeprom->value,
  654. le16_to_cpu(r.eeprom->byte_count));
  655. break;
  656. default:
  657. return -1;
  658. }
  659. return 0;
  660. }
  661. /*
  662. * This function handles the command response of get IBSS coalescing status.
  663. *
  664. * If the received BSSID is different than the current one, the current BSSID,
  665. * beacon interval, ATIM window and ERP information are updated, along with
  666. * changing the ad-hoc state accordingly.
  667. */
  668. static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
  669. struct host_cmd_ds_command *resp)
  670. {
  671. struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
  672. &(resp->params.ibss_coalescing);
  673. if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
  674. return 0;
  675. dev_dbg(priv->adapter->dev,
  676. "info: new BSSID %pM\n", ibss_coal_resp->bssid);
  677. /* If rsp has NULL BSSID, Just return..... No Action */
  678. if (is_zero_ether_addr(ibss_coal_resp->bssid)) {
  679. dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
  680. return 0;
  681. }
  682. /* If BSSID is diff, modify current BSS parameters */
  683. if (memcmp(priv->curr_bss_params.bss_descriptor.mac_address,
  684. ibss_coal_resp->bssid, ETH_ALEN)) {
  685. /* BSSID */
  686. memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
  687. ibss_coal_resp->bssid, ETH_ALEN);
  688. /* Beacon Interval */
  689. priv->curr_bss_params.bss_descriptor.beacon_period
  690. = le16_to_cpu(ibss_coal_resp->beacon_interval);
  691. /* ERP Information */
  692. priv->curr_bss_params.bss_descriptor.erp_flags =
  693. (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
  694. priv->adhoc_state = ADHOC_COALESCED;
  695. }
  696. return 0;
  697. }
  698. /*
  699. * This function handles the command response for subscribe event command.
  700. */
  701. static int mwifiex_ret_subsc_evt(struct mwifiex_private *priv,
  702. struct host_cmd_ds_command *resp)
  703. {
  704. struct host_cmd_ds_802_11_subsc_evt *cmd_sub_event =
  705. &resp->params.subsc_evt;
  706. /* For every subscribe event command (Get/Set/Clear), FW reports the
  707. * current set of subscribed events*/
  708. dev_dbg(priv->adapter->dev, "Bitmap of currently subscribed events: %16x\n",
  709. le16_to_cpu(cmd_sub_event->events));
  710. return 0;
  711. }
  712. /* This function handles the command response of set_cfg_data */
  713. static int mwifiex_ret_cfg_data(struct mwifiex_private *priv,
  714. struct host_cmd_ds_command *resp)
  715. {
  716. if (resp->result != HostCmd_RESULT_OK) {
  717. dev_err(priv->adapter->dev, "Cal data cmd resp failed\n");
  718. return -1;
  719. }
  720. return 0;
  721. }
  722. /*
  723. * This function handles the command responses.
  724. *
  725. * This is a generic function, which calls command specific
  726. * response handlers based on the command ID.
  727. */
  728. int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
  729. struct host_cmd_ds_command *resp)
  730. {
  731. int ret = 0;
  732. struct mwifiex_adapter *adapter = priv->adapter;
  733. void *data_buf = adapter->curr_cmd->data_buf;
  734. /* If the command is not successful, cleanup and return failure */
  735. if (resp->result != HostCmd_RESULT_OK) {
  736. mwifiex_process_cmdresp_error(priv, resp);
  737. return -1;
  738. }
  739. /* Command successful, handle response */
  740. switch (cmdresp_no) {
  741. case HostCmd_CMD_GET_HW_SPEC:
  742. ret = mwifiex_ret_get_hw_spec(priv, resp);
  743. break;
  744. case HostCmd_CMD_CFG_DATA:
  745. ret = mwifiex_ret_cfg_data(priv, resp);
  746. break;
  747. case HostCmd_CMD_MAC_CONTROL:
  748. break;
  749. case HostCmd_CMD_802_11_MAC_ADDRESS:
  750. ret = mwifiex_ret_802_11_mac_address(priv, resp);
  751. break;
  752. case HostCmd_CMD_MAC_MULTICAST_ADR:
  753. ret = mwifiex_ret_mac_multicast_adr(priv, resp);
  754. break;
  755. case HostCmd_CMD_TX_RATE_CFG:
  756. ret = mwifiex_ret_tx_rate_cfg(priv, resp);
  757. break;
  758. case HostCmd_CMD_802_11_SCAN:
  759. ret = mwifiex_ret_802_11_scan(priv, resp);
  760. adapter->curr_cmd->wait_q_enabled = false;
  761. break;
  762. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  763. ret = mwifiex_ret_802_11_scan(priv, resp);
  764. dev_dbg(adapter->dev,
  765. "info: CMD_RESP: BG_SCAN result is ready!\n");
  766. break;
  767. case HostCmd_CMD_TXPWR_CFG:
  768. ret = mwifiex_ret_tx_power_cfg(priv, resp);
  769. break;
  770. case HostCmd_CMD_RF_TX_PWR:
  771. ret = mwifiex_ret_rf_tx_power(priv, resp);
  772. break;
  773. case HostCmd_CMD_RF_ANTENNA:
  774. ret = mwifiex_ret_rf_antenna(priv, resp);
  775. break;
  776. case HostCmd_CMD_802_11_PS_MODE_ENH:
  777. ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
  778. break;
  779. case HostCmd_CMD_802_11_HS_CFG_ENH:
  780. ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
  781. break;
  782. case HostCmd_CMD_802_11_ASSOCIATE:
  783. ret = mwifiex_ret_802_11_associate(priv, resp);
  784. break;
  785. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  786. ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
  787. break;
  788. case HostCmd_CMD_802_11_AD_HOC_START:
  789. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  790. ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
  791. break;
  792. case HostCmd_CMD_802_11_AD_HOC_STOP:
  793. ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
  794. break;
  795. case HostCmd_CMD_802_11_GET_LOG:
  796. ret = mwifiex_ret_get_log(priv, resp, data_buf);
  797. break;
  798. case HostCmd_CMD_RSSI_INFO:
  799. ret = mwifiex_ret_802_11_rssi_info(priv, resp);
  800. break;
  801. case HostCmd_CMD_802_11_SNMP_MIB:
  802. ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
  803. break;
  804. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  805. ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
  806. break;
  807. case HostCmd_CMD_VERSION_EXT:
  808. ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
  809. break;
  810. case HostCmd_CMD_REMAIN_ON_CHAN:
  811. ret = mwifiex_ret_remain_on_chan(priv, resp, data_buf);
  812. break;
  813. case HostCmd_CMD_11AC_CFG:
  814. break;
  815. case HostCmd_CMD_P2P_MODE_CFG:
  816. ret = mwifiex_ret_p2p_mode_cfg(priv, resp, data_buf);
  817. break;
  818. case HostCmd_CMD_MGMT_FRAME_REG:
  819. case HostCmd_CMD_FUNC_INIT:
  820. case HostCmd_CMD_FUNC_SHUTDOWN:
  821. break;
  822. case HostCmd_CMD_802_11_KEY_MATERIAL:
  823. ret = mwifiex_ret_802_11_key_material(priv, resp);
  824. break;
  825. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  826. ret = mwifiex_ret_802_11d_domain_info(priv, resp);
  827. break;
  828. case HostCmd_CMD_11N_ADDBA_REQ:
  829. ret = mwifiex_ret_11n_addba_req(priv, resp);
  830. break;
  831. case HostCmd_CMD_11N_DELBA:
  832. ret = mwifiex_ret_11n_delba(priv, resp);
  833. break;
  834. case HostCmd_CMD_11N_ADDBA_RSP:
  835. ret = mwifiex_ret_11n_addba_resp(priv, resp);
  836. break;
  837. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  838. adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
  839. tx_buf.buff_size);
  840. adapter->tx_buf_size = (adapter->tx_buf_size
  841. / MWIFIEX_SDIO_BLOCK_SIZE)
  842. * MWIFIEX_SDIO_BLOCK_SIZE;
  843. adapter->curr_tx_buf_size = adapter->tx_buf_size;
  844. dev_dbg(adapter->dev, "cmd: curr_tx_buf_size=%d\n",
  845. adapter->curr_tx_buf_size);
  846. if (adapter->if_ops.update_mp_end_port)
  847. adapter->if_ops.update_mp_end_port(adapter,
  848. le16_to_cpu(resp->params.tx_buf.mp_end_port));
  849. break;
  850. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  851. break;
  852. case HostCmd_CMD_WMM_GET_STATUS:
  853. ret = mwifiex_ret_wmm_get_status(priv, resp);
  854. break;
  855. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  856. ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
  857. break;
  858. case HostCmd_CMD_MAC_REG_ACCESS:
  859. case HostCmd_CMD_BBP_REG_ACCESS:
  860. case HostCmd_CMD_RF_REG_ACCESS:
  861. case HostCmd_CMD_PMIC_REG_ACCESS:
  862. case HostCmd_CMD_CAU_REG_ACCESS:
  863. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  864. ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
  865. break;
  866. case HostCmd_CMD_SET_BSS_MODE:
  867. break;
  868. case HostCmd_CMD_11N_CFG:
  869. break;
  870. case HostCmd_CMD_PCIE_DESC_DETAILS:
  871. break;
  872. case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
  873. ret = mwifiex_ret_subsc_evt(priv, resp);
  874. break;
  875. case HostCmd_CMD_UAP_SYS_CONFIG:
  876. break;
  877. case HostCmd_CMD_UAP_BSS_START:
  878. priv->bss_started = 1;
  879. break;
  880. case HostCmd_CMD_UAP_BSS_STOP:
  881. priv->bss_started = 0;
  882. break;
  883. case HostCmd_CMD_UAP_STA_DEAUTH:
  884. break;
  885. case HostCmd_CMD_MEF_CFG:
  886. break;
  887. case HostCmd_CMD_COALESCE_CFG:
  888. break;
  889. default:
  890. dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
  891. resp->command);
  892. break;
  893. }
  894. return ret;
  895. }