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