sta_cmdresp.c 29 KB

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