sta_cmdresp.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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_insert_cmd_to_free_q(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;
  249. u8 *tlv_buf;
  250. u32 i;
  251. tlv_buf = ((u8 *)rate_cfg) +
  252. sizeof(struct host_cmd_ds_tx_rate_cfg);
  253. tlv_buf_len = *(u16 *) (tlv_buf + sizeof(u16));
  254. while (tlv_buf && tlv_buf_len > 0) {
  255. tlv = (*tlv_buf);
  256. tlv = tlv | (*(tlv_buf + 1) << 8);
  257. switch (tlv) {
  258. case TLV_TYPE_RATE_SCOPE:
  259. rate_scope = (struct mwifiex_rate_scope *) tlv_buf;
  260. priv->bitmap_rates[0] =
  261. le16_to_cpu(rate_scope->hr_dsss_rate_bitmap);
  262. priv->bitmap_rates[1] =
  263. le16_to_cpu(rate_scope->ofdm_rate_bitmap);
  264. for (i = 0;
  265. i <
  266. sizeof(rate_scope->ht_mcs_rate_bitmap) /
  267. sizeof(u16); i++)
  268. priv->bitmap_rates[2 + i] =
  269. le16_to_cpu(rate_scope->
  270. ht_mcs_rate_bitmap[i]);
  271. break;
  272. /* Add RATE_DROP tlv here */
  273. }
  274. head = (struct mwifiex_ie_types_header *) tlv_buf;
  275. tlv_buf += le16_to_cpu(head->len) + sizeof(*head);
  276. tlv_buf_len -= le16_to_cpu(head->len);
  277. }
  278. priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
  279. if (priv->is_data_rate_auto)
  280. priv->data_rate = 0;
  281. else
  282. return mwifiex_send_cmd_async(priv,
  283. HostCmd_CMD_802_11_TX_RATE_QUERY,
  284. HostCmd_ACT_GEN_GET, 0, NULL);
  285. return 0;
  286. }
  287. /*
  288. * This function handles the command response of get Tx power level.
  289. *
  290. * Handling includes saving the maximum and minimum Tx power levels
  291. * in driver, as well as sending the values to user.
  292. */
  293. static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
  294. {
  295. int length, max_power = -1, min_power = -1;
  296. struct mwifiex_types_power_group *pg_tlv_hdr;
  297. struct mwifiex_power_group *pg;
  298. if (!data_buf)
  299. return -1;
  300. pg_tlv_hdr = (struct mwifiex_types_power_group *)
  301. ((u8 *) data_buf + sizeof(struct host_cmd_ds_txpwr_cfg));
  302. pg = (struct mwifiex_power_group *)
  303. ((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
  304. length = pg_tlv_hdr->length;
  305. if (length > 0) {
  306. max_power = pg->power_max;
  307. min_power = pg->power_min;
  308. length -= sizeof(struct mwifiex_power_group);
  309. }
  310. while (length) {
  311. pg++;
  312. if (max_power < pg->power_max)
  313. max_power = pg->power_max;
  314. if (min_power > pg->power_min)
  315. min_power = pg->power_min;
  316. length -= sizeof(struct mwifiex_power_group);
  317. }
  318. if (pg_tlv_hdr->length > 0) {
  319. priv->min_tx_power_level = (u8) min_power;
  320. priv->max_tx_power_level = (u8) max_power;
  321. }
  322. return 0;
  323. }
  324. /*
  325. * This function handles the command response of set/get Tx power
  326. * configurations.
  327. *
  328. * Handling includes changing the header fields into CPU format
  329. * and saving the current Tx power level in driver.
  330. */
  331. static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
  332. struct host_cmd_ds_command *resp)
  333. {
  334. struct mwifiex_adapter *adapter = priv->adapter;
  335. struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
  336. struct mwifiex_types_power_group *pg_tlv_hdr;
  337. struct mwifiex_power_group *pg;
  338. u16 action = le16_to_cpu(txp_cfg->action);
  339. switch (action) {
  340. case HostCmd_ACT_GEN_GET:
  341. pg_tlv_hdr = (struct mwifiex_types_power_group *)
  342. ((u8 *) txp_cfg +
  343. sizeof(struct host_cmd_ds_txpwr_cfg));
  344. pg = (struct mwifiex_power_group *)
  345. ((u8 *) pg_tlv_hdr +
  346. sizeof(struct mwifiex_types_power_group));
  347. if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
  348. mwifiex_get_power_level(priv, txp_cfg);
  349. priv->tx_power_level = (u16) pg->power_min;
  350. break;
  351. case HostCmd_ACT_GEN_SET:
  352. if (!le32_to_cpu(txp_cfg->mode))
  353. break;
  354. pg_tlv_hdr = (struct mwifiex_types_power_group *)
  355. ((u8 *) txp_cfg +
  356. sizeof(struct host_cmd_ds_txpwr_cfg));
  357. pg = (struct mwifiex_power_group *)
  358. ((u8 *) pg_tlv_hdr +
  359. sizeof(struct mwifiex_types_power_group));
  360. if (pg->power_max == pg->power_min)
  361. priv->tx_power_level = (u16) pg->power_min;
  362. break;
  363. default:
  364. dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
  365. action);
  366. return 0;
  367. }
  368. dev_dbg(adapter->dev,
  369. "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
  370. priv->tx_power_level, priv->max_tx_power_level,
  371. priv->min_tx_power_level);
  372. return 0;
  373. }
  374. /*
  375. * This function handles the command response of get RF Tx power.
  376. */
  377. static int mwifiex_ret_rf_tx_power(struct mwifiex_private *priv,
  378. struct host_cmd_ds_command *resp)
  379. {
  380. struct host_cmd_ds_rf_tx_pwr *txp = &resp->params.txp;
  381. u16 action = le16_to_cpu(txp->action);
  382. priv->tx_power_level = le16_to_cpu(txp->cur_level);
  383. if (action == HostCmd_ACT_GEN_GET) {
  384. priv->max_tx_power_level = txp->max_power;
  385. priv->min_tx_power_level = txp->min_power;
  386. }
  387. dev_dbg(priv->adapter->dev,
  388. "Current TxPower Level=%d, Max Power=%d, Min Power=%d\n",
  389. priv->tx_power_level, priv->max_tx_power_level,
  390. priv->min_tx_power_level);
  391. return 0;
  392. }
  393. /*
  394. * This function handles the command response of set rf antenna
  395. */
  396. static int mwifiex_ret_rf_antenna(struct mwifiex_private *priv,
  397. struct host_cmd_ds_command *resp)
  398. {
  399. struct host_cmd_ds_rf_ant_mimo *ant_mimo = &resp->params.ant_mimo;
  400. struct host_cmd_ds_rf_ant_siso *ant_siso = &resp->params.ant_siso;
  401. struct mwifiex_adapter *adapter = priv->adapter;
  402. if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
  403. dev_dbg(adapter->dev,
  404. "RF_ANT_RESP: Tx action = 0x%x, Tx Mode = 0x%04x"
  405. " Rx action = 0x%x, Rx Mode = 0x%04x\n",
  406. le16_to_cpu(ant_mimo->action_tx),
  407. le16_to_cpu(ant_mimo->tx_ant_mode),
  408. le16_to_cpu(ant_mimo->action_rx),
  409. le16_to_cpu(ant_mimo->rx_ant_mode));
  410. else
  411. dev_dbg(adapter->dev,
  412. "RF_ANT_RESP: action = 0x%x, Mode = 0x%04x\n",
  413. le16_to_cpu(ant_siso->action),
  414. le16_to_cpu(ant_siso->ant_mode));
  415. return 0;
  416. }
  417. /*
  418. * This function handles the command response of set/get MAC address.
  419. *
  420. * Handling includes saving the MAC address in driver.
  421. */
  422. static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
  423. struct host_cmd_ds_command *resp)
  424. {
  425. struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
  426. &resp->params.mac_addr;
  427. memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
  428. dev_dbg(priv->adapter->dev,
  429. "info: set mac address: %pM\n", priv->curr_addr);
  430. return 0;
  431. }
  432. /*
  433. * This function handles the command response of set/get MAC multicast
  434. * address.
  435. */
  436. static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
  437. struct host_cmd_ds_command *resp)
  438. {
  439. return 0;
  440. }
  441. /*
  442. * This function handles the command response of get Tx rate query.
  443. *
  444. * Handling includes changing the header fields into CPU format
  445. * and saving the Tx rate and HT information parameters in driver.
  446. *
  447. * Both rate configuration and current data rate can be retrieved
  448. * with this request.
  449. */
  450. static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
  451. struct host_cmd_ds_command *resp)
  452. {
  453. priv->tx_rate = resp->params.tx_rate.tx_rate;
  454. priv->tx_htinfo = resp->params.tx_rate.ht_info;
  455. if (!priv->is_data_rate_auto)
  456. priv->data_rate =
  457. mwifiex_index_to_data_rate(priv, priv->tx_rate,
  458. priv->tx_htinfo);
  459. return 0;
  460. }
  461. /*
  462. * This function handles the command response of a deauthenticate
  463. * command.
  464. *
  465. * If the deauthenticated MAC matches the current BSS MAC, the connection
  466. * state is reset.
  467. */
  468. static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
  469. struct host_cmd_ds_command *resp)
  470. {
  471. struct mwifiex_adapter *adapter = priv->adapter;
  472. adapter->dbg.num_cmd_deauth++;
  473. if (!memcmp(resp->params.deauth.mac_addr,
  474. &priv->curr_bss_params.bss_descriptor.mac_address,
  475. sizeof(resp->params.deauth.mac_addr)))
  476. mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING);
  477. return 0;
  478. }
  479. /*
  480. * This function handles the command response of ad-hoc stop.
  481. *
  482. * The function resets the connection state in driver.
  483. */
  484. static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
  485. struct host_cmd_ds_command *resp)
  486. {
  487. mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING);
  488. return 0;
  489. }
  490. /*
  491. * This function handles the command response of set/get key material.
  492. *
  493. * Handling includes updating the driver parameters to reflect the
  494. * changes.
  495. */
  496. static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
  497. struct host_cmd_ds_command *resp)
  498. {
  499. struct host_cmd_ds_802_11_key_material *key =
  500. &resp->params.key_material;
  501. if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
  502. if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
  503. dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
  504. priv->wpa_is_gtk_set = true;
  505. priv->scan_block = false;
  506. }
  507. }
  508. memset(priv->aes_key.key_param_set.key, 0,
  509. sizeof(key->key_param_set.key));
  510. priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
  511. memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
  512. le16_to_cpu(priv->aes_key.key_param_set.key_len));
  513. return 0;
  514. }
  515. /*
  516. * This function handles the command response of get 11d domain information.
  517. */
  518. static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
  519. struct host_cmd_ds_command *resp)
  520. {
  521. struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
  522. &resp->params.domain_info_resp;
  523. struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
  524. u16 action = le16_to_cpu(domain_info->action);
  525. u8 no_of_triplet;
  526. no_of_triplet = (u8) ((le16_to_cpu(domain->header.len)
  527. - IEEE80211_COUNTRY_STRING_LEN)
  528. / sizeof(struct ieee80211_country_ie_triplet));
  529. dev_dbg(priv->adapter->dev,
  530. "info: 11D Domain Info Resp: no_of_triplet=%d\n",
  531. no_of_triplet);
  532. if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
  533. dev_warn(priv->adapter->dev,
  534. "11D: invalid number of triplets %d returned\n",
  535. no_of_triplet);
  536. return -1;
  537. }
  538. switch (action) {
  539. case HostCmd_ACT_GEN_SET: /* Proc Set Action */
  540. break;
  541. case HostCmd_ACT_GEN_GET:
  542. break;
  543. default:
  544. dev_err(priv->adapter->dev,
  545. "11D: invalid action:%d\n", domain_info->action);
  546. return -1;
  547. }
  548. return 0;
  549. }
  550. /*
  551. * This function handles the command response of get extended version.
  552. *
  553. * Handling includes forming the extended version string and sending it
  554. * to application.
  555. */
  556. static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
  557. struct host_cmd_ds_command *resp,
  558. struct host_cmd_ds_version_ext *version_ext)
  559. {
  560. struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
  561. if (version_ext) {
  562. version_ext->version_str_sel = ver_ext->version_str_sel;
  563. memcpy(version_ext->version_str, ver_ext->version_str,
  564. sizeof(char) * 128);
  565. memcpy(priv->version_str, ver_ext->version_str, 128);
  566. }
  567. return 0;
  568. }
  569. /*
  570. * This function handles the command response of remain on channel.
  571. */
  572. static int
  573. mwifiex_ret_remain_on_chan(struct mwifiex_private *priv,
  574. struct host_cmd_ds_command *resp,
  575. struct host_cmd_ds_remain_on_chan *roc_cfg)
  576. {
  577. struct host_cmd_ds_remain_on_chan *resp_cfg = &resp->params.roc_cfg;
  578. if (roc_cfg)
  579. memcpy(roc_cfg, resp_cfg, sizeof(*roc_cfg));
  580. return 0;
  581. }
  582. /*
  583. * This function handles the command response of P2P mode cfg.
  584. */
  585. static int
  586. mwifiex_ret_p2p_mode_cfg(struct mwifiex_private *priv,
  587. struct host_cmd_ds_command *resp,
  588. void *data_buf)
  589. {
  590. struct host_cmd_ds_p2p_mode_cfg *mode_cfg = &resp->params.mode_cfg;
  591. if (data_buf)
  592. *((u16 *)data_buf) = le16_to_cpu(mode_cfg->mode);
  593. return 0;
  594. }
  595. /*
  596. * This function handles the command response of register access.
  597. *
  598. * The register value and offset are returned to the user. For EEPROM
  599. * access, the byte count is also returned.
  600. */
  601. static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
  602. void *data_buf)
  603. {
  604. struct mwifiex_ds_reg_rw *reg_rw;
  605. struct mwifiex_ds_read_eeprom *eeprom;
  606. union reg {
  607. struct host_cmd_ds_mac_reg_access *mac;
  608. struct host_cmd_ds_bbp_reg_access *bbp;
  609. struct host_cmd_ds_rf_reg_access *rf;
  610. struct host_cmd_ds_pmic_reg_access *pmic;
  611. struct host_cmd_ds_802_11_eeprom_access *eeprom;
  612. } r;
  613. if (!data_buf)
  614. return 0;
  615. reg_rw = data_buf;
  616. eeprom = data_buf;
  617. switch (type) {
  618. case HostCmd_CMD_MAC_REG_ACCESS:
  619. r.mac = &resp->params.mac_reg;
  620. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
  621. reg_rw->value = r.mac->value;
  622. break;
  623. case HostCmd_CMD_BBP_REG_ACCESS:
  624. r.bbp = &resp->params.bbp_reg;
  625. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
  626. reg_rw->value = cpu_to_le32((u32) r.bbp->value);
  627. break;
  628. case HostCmd_CMD_RF_REG_ACCESS:
  629. r.rf = &resp->params.rf_reg;
  630. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
  631. reg_rw->value = cpu_to_le32((u32) r.bbp->value);
  632. break;
  633. case HostCmd_CMD_PMIC_REG_ACCESS:
  634. r.pmic = &resp->params.pmic_reg;
  635. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
  636. reg_rw->value = cpu_to_le32((u32) r.pmic->value);
  637. break;
  638. case HostCmd_CMD_CAU_REG_ACCESS:
  639. r.rf = &resp->params.rf_reg;
  640. reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
  641. reg_rw->value = cpu_to_le32((u32) r.rf->value);
  642. break;
  643. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  644. r.eeprom = &resp->params.eeprom;
  645. pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
  646. if (le16_to_cpu(eeprom->byte_count) <
  647. le16_to_cpu(r.eeprom->byte_count)) {
  648. eeprom->byte_count = cpu_to_le16(0);
  649. pr_debug("info: EEPROM read length is too big\n");
  650. return -1;
  651. }
  652. eeprom->offset = r.eeprom->offset;
  653. eeprom->byte_count = r.eeprom->byte_count;
  654. if (le16_to_cpu(eeprom->byte_count) > 0)
  655. memcpy(&eeprom->value, &r.eeprom->value,
  656. le16_to_cpu(r.eeprom->byte_count));
  657. break;
  658. default:
  659. return -1;
  660. }
  661. return 0;
  662. }
  663. /*
  664. * This function handles the command response of get IBSS coalescing status.
  665. *
  666. * If the received BSSID is different than the current one, the current BSSID,
  667. * beacon interval, ATIM window and ERP information are updated, along with
  668. * changing the ad-hoc state accordingly.
  669. */
  670. static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
  671. struct host_cmd_ds_command *resp)
  672. {
  673. struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
  674. &(resp->params.ibss_coalescing);
  675. if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
  676. return 0;
  677. dev_dbg(priv->adapter->dev,
  678. "info: new BSSID %pM\n", ibss_coal_resp->bssid);
  679. /* If rsp has NULL BSSID, Just return..... No Action */
  680. if (is_zero_ether_addr(ibss_coal_resp->bssid)) {
  681. dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
  682. return 0;
  683. }
  684. /* If BSSID is diff, modify current BSS parameters */
  685. if (memcmp(priv->curr_bss_params.bss_descriptor.mac_address,
  686. ibss_coal_resp->bssid, ETH_ALEN)) {
  687. /* BSSID */
  688. memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
  689. ibss_coal_resp->bssid, ETH_ALEN);
  690. /* Beacon Interval */
  691. priv->curr_bss_params.bss_descriptor.beacon_period
  692. = le16_to_cpu(ibss_coal_resp->beacon_interval);
  693. /* ERP Information */
  694. priv->curr_bss_params.bss_descriptor.erp_flags =
  695. (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
  696. priv->adhoc_state = ADHOC_COALESCED;
  697. }
  698. return 0;
  699. }
  700. /*
  701. * This function handles the command response for subscribe event command.
  702. */
  703. static int mwifiex_ret_subsc_evt(struct mwifiex_private *priv,
  704. struct host_cmd_ds_command *resp)
  705. {
  706. struct host_cmd_ds_802_11_subsc_evt *cmd_sub_event =
  707. &resp->params.subsc_evt;
  708. /* For every subscribe event command (Get/Set/Clear), FW reports the
  709. * current set of subscribed events*/
  710. dev_dbg(priv->adapter->dev, "Bitmap of currently subscribed events: %16x\n",
  711. le16_to_cpu(cmd_sub_event->events));
  712. return 0;
  713. }
  714. /*
  715. * This function handles the command responses.
  716. *
  717. * This is a generic function, which calls command specific
  718. * response handlers based on the command ID.
  719. */
  720. int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
  721. struct host_cmd_ds_command *resp)
  722. {
  723. int ret = 0;
  724. struct mwifiex_adapter *adapter = priv->adapter;
  725. void *data_buf = adapter->curr_cmd->data_buf;
  726. /* If the command is not successful, cleanup and return failure */
  727. if (resp->result != HostCmd_RESULT_OK) {
  728. mwifiex_process_cmdresp_error(priv, resp);
  729. return -1;
  730. }
  731. /* Command successful, handle response */
  732. switch (cmdresp_no) {
  733. case HostCmd_CMD_GET_HW_SPEC:
  734. ret = mwifiex_ret_get_hw_spec(priv, resp);
  735. break;
  736. case HostCmd_CMD_MAC_CONTROL:
  737. break;
  738. case HostCmd_CMD_802_11_MAC_ADDRESS:
  739. ret = mwifiex_ret_802_11_mac_address(priv, resp);
  740. break;
  741. case HostCmd_CMD_MAC_MULTICAST_ADR:
  742. ret = mwifiex_ret_mac_multicast_adr(priv, resp);
  743. break;
  744. case HostCmd_CMD_TX_RATE_CFG:
  745. ret = mwifiex_ret_tx_rate_cfg(priv, resp);
  746. break;
  747. case HostCmd_CMD_802_11_SCAN:
  748. ret = mwifiex_ret_802_11_scan(priv, resp);
  749. adapter->curr_cmd->wait_q_enabled = false;
  750. break;
  751. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  752. ret = mwifiex_ret_802_11_scan(priv, resp);
  753. dev_dbg(adapter->dev,
  754. "info: CMD_RESP: BG_SCAN result is ready!\n");
  755. break;
  756. case HostCmd_CMD_TXPWR_CFG:
  757. ret = mwifiex_ret_tx_power_cfg(priv, resp);
  758. break;
  759. case HostCmd_CMD_RF_TX_PWR:
  760. ret = mwifiex_ret_rf_tx_power(priv, resp);
  761. break;
  762. case HostCmd_CMD_RF_ANTENNA:
  763. ret = mwifiex_ret_rf_antenna(priv, resp);
  764. break;
  765. case HostCmd_CMD_802_11_PS_MODE_ENH:
  766. ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
  767. break;
  768. case HostCmd_CMD_802_11_HS_CFG_ENH:
  769. ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
  770. break;
  771. case HostCmd_CMD_802_11_ASSOCIATE:
  772. ret = mwifiex_ret_802_11_associate(priv, resp);
  773. break;
  774. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  775. ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
  776. break;
  777. case HostCmd_CMD_802_11_AD_HOC_START:
  778. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  779. ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
  780. break;
  781. case HostCmd_CMD_802_11_AD_HOC_STOP:
  782. ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
  783. break;
  784. case HostCmd_CMD_802_11_GET_LOG:
  785. ret = mwifiex_ret_get_log(priv, resp, data_buf);
  786. break;
  787. case HostCmd_CMD_RSSI_INFO:
  788. ret = mwifiex_ret_802_11_rssi_info(priv, resp);
  789. break;
  790. case HostCmd_CMD_802_11_SNMP_MIB:
  791. ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
  792. break;
  793. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  794. ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
  795. break;
  796. case HostCmd_CMD_VERSION_EXT:
  797. ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
  798. break;
  799. case HostCmd_CMD_REMAIN_ON_CHAN:
  800. ret = mwifiex_ret_remain_on_chan(priv, resp, data_buf);
  801. break;
  802. case HostCmd_CMD_P2P_MODE_CFG:
  803. ret = mwifiex_ret_p2p_mode_cfg(priv, resp, data_buf);
  804. break;
  805. case HostCmd_CMD_MGMT_FRAME_REG:
  806. case HostCmd_CMD_FUNC_INIT:
  807. case HostCmd_CMD_FUNC_SHUTDOWN:
  808. break;
  809. case HostCmd_CMD_802_11_KEY_MATERIAL:
  810. ret = mwifiex_ret_802_11_key_material(priv, resp);
  811. break;
  812. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  813. ret = mwifiex_ret_802_11d_domain_info(priv, resp);
  814. break;
  815. case HostCmd_CMD_11N_ADDBA_REQ:
  816. ret = mwifiex_ret_11n_addba_req(priv, resp);
  817. break;
  818. case HostCmd_CMD_11N_DELBA:
  819. ret = mwifiex_ret_11n_delba(priv, resp);
  820. break;
  821. case HostCmd_CMD_11N_ADDBA_RSP:
  822. ret = mwifiex_ret_11n_addba_resp(priv, resp);
  823. break;
  824. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  825. adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
  826. tx_buf.buff_size);
  827. adapter->tx_buf_size = (adapter->tx_buf_size
  828. / MWIFIEX_SDIO_BLOCK_SIZE)
  829. * MWIFIEX_SDIO_BLOCK_SIZE;
  830. adapter->curr_tx_buf_size = adapter->tx_buf_size;
  831. dev_dbg(adapter->dev, "cmd: curr_tx_buf_size=%d\n",
  832. adapter->curr_tx_buf_size);
  833. if (adapter->if_ops.update_mp_end_port)
  834. adapter->if_ops.update_mp_end_port(adapter,
  835. le16_to_cpu(resp->params.tx_buf.mp_end_port));
  836. break;
  837. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  838. break;
  839. case HostCmd_CMD_WMM_GET_STATUS:
  840. ret = mwifiex_ret_wmm_get_status(priv, resp);
  841. break;
  842. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  843. ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
  844. break;
  845. case HostCmd_CMD_MAC_REG_ACCESS:
  846. case HostCmd_CMD_BBP_REG_ACCESS:
  847. case HostCmd_CMD_RF_REG_ACCESS:
  848. case HostCmd_CMD_PMIC_REG_ACCESS:
  849. case HostCmd_CMD_CAU_REG_ACCESS:
  850. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  851. ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
  852. break;
  853. case HostCmd_CMD_SET_BSS_MODE:
  854. break;
  855. case HostCmd_CMD_11N_CFG:
  856. break;
  857. case HostCmd_CMD_PCIE_DESC_DETAILS:
  858. break;
  859. case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
  860. ret = mwifiex_ret_subsc_evt(priv, resp);
  861. break;
  862. case HostCmd_CMD_UAP_SYS_CONFIG:
  863. break;
  864. case HostCmd_CMD_UAP_BSS_START:
  865. priv->bss_started = 1;
  866. break;
  867. case HostCmd_CMD_UAP_BSS_STOP:
  868. priv->bss_started = 0;
  869. break;
  870. default:
  871. dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
  872. resp->command);
  873. break;
  874. }
  875. return ret;
  876. }