sta_cmdresp.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. /*
  2. * Marvell Wireless LAN device driver: station command response handling
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. #include "11ac.h"
  27. /*
  28. * This function handles the command response error case.
  29. *
  30. * For scan response error, the function cancels all the pending
  31. * scan commands and generates an event to inform the applications
  32. * of the scan completion.
  33. *
  34. * For Power Save command failure, we do not retry enter PS
  35. * command in case of Ad-hoc mode.
  36. *
  37. * For all other response errors, the current command buffer is freed
  38. * and returned to the free command queue.
  39. */
  40. static void
  41. mwifiex_process_cmdresp_error(struct mwifiex_private *priv,
  42. struct host_cmd_ds_command *resp)
  43. {
  44. struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
  45. struct mwifiex_adapter *adapter = priv->adapter;
  46. struct host_cmd_ds_802_11_ps_mode_enh *pm;
  47. unsigned long flags;
  48. dev_err(adapter->dev, "CMD_RESP: cmd %#x error, result=%#x\n",
  49. resp->command, resp->result);
  50. if (adapter->curr_cmd->wait_q_enabled)
  51. adapter->cmd_wait_q.status = -1;
  52. switch (le16_to_cpu(resp->command)) {
  53. case HostCmd_CMD_802_11_PS_MODE_ENH:
  54. pm = &resp->params.psmode_enh;
  55. dev_err(adapter->dev,
  56. "PS_MODE_ENH cmd failed: result=0x%x action=0x%X\n",
  57. resp->result, le16_to_cpu(pm->action));
  58. /* We do not re-try enter-ps command in ad-hoc mode. */
  59. if (le16_to_cpu(pm->action) == EN_AUTO_PS &&
  60. (le16_to_cpu(pm->params.ps_bitmap) & BITMAP_STA_PS) &&
  61. priv->bss_mode == NL80211_IFTYPE_ADHOC)
  62. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  63. break;
  64. case HostCmd_CMD_802_11_SCAN:
  65. /* Cancel all pending scan command */
  66. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  67. list_for_each_entry_safe(cmd_node, tmp_node,
  68. &adapter->scan_pending_q, list) {
  69. list_del(&cmd_node->list);
  70. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  71. flags);
  72. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  73. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  74. }
  75. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  76. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  77. adapter->scan_processing = false;
  78. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  79. if (priv->report_scan_result)
  80. priv->report_scan_result = false;
  81. break;
  82. case HostCmd_CMD_MAC_CONTROL:
  83. break;
  84. default:
  85. break;
  86. }
  87. /* Handling errors here */
  88. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  89. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  90. adapter->curr_cmd = NULL;
  91. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  92. }
  93. /*
  94. * This function handles the command response of get RSSI info.
  95. *
  96. * Handling includes changing the header fields into CPU format
  97. * and saving the following parameters in driver -
  98. * - Last data and beacon RSSI value
  99. * - Average data and beacon RSSI value
  100. * - Last data and beacon NF value
  101. * - Average data and beacon NF value
  102. *
  103. * The parameters are send to the application as well, along with
  104. * calculated SNR values.
  105. */
  106. static int mwifiex_ret_802_11_rssi_info(struct mwifiex_private *priv,
  107. struct host_cmd_ds_command *resp)
  108. {
  109. struct host_cmd_ds_802_11_rssi_info_rsp *rssi_info_rsp =
  110. &resp->params.rssi_info_rsp;
  111. struct mwifiex_ds_misc_subsc_evt *subsc_evt =
  112. &priv->async_subsc_evt_storage;
  113. priv->data_rssi_last = le16_to_cpu(rssi_info_rsp->data_rssi_last);
  114. priv->data_nf_last = le16_to_cpu(rssi_info_rsp->data_nf_last);
  115. priv->data_rssi_avg = le16_to_cpu(rssi_info_rsp->data_rssi_avg);
  116. priv->data_nf_avg = le16_to_cpu(rssi_info_rsp->data_nf_avg);
  117. priv->bcn_rssi_last = le16_to_cpu(rssi_info_rsp->bcn_rssi_last);
  118. priv->bcn_nf_last = le16_to_cpu(rssi_info_rsp->bcn_nf_last);
  119. priv->bcn_rssi_avg = le16_to_cpu(rssi_info_rsp->bcn_rssi_avg);
  120. priv->bcn_nf_avg = le16_to_cpu(rssi_info_rsp->bcn_nf_avg);
  121. if (priv->subsc_evt_rssi_state == EVENT_HANDLED)
  122. return 0;
  123. memset(subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
  124. /* Resubscribe low and high rssi events with new thresholds */
  125. subsc_evt->events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
  126. subsc_evt->action = HostCmd_ACT_BITWISE_SET;
  127. if (priv->subsc_evt_rssi_state == RSSI_LOW_RECVD) {
  128. subsc_evt->bcn_l_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg -
  129. priv->cqm_rssi_hyst);
  130. subsc_evt->bcn_h_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
  131. } else if (priv->subsc_evt_rssi_state == RSSI_HIGH_RECVD) {
  132. subsc_evt->bcn_l_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
  133. subsc_evt->bcn_h_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg +
  134. priv->cqm_rssi_hyst);
  135. }
  136. subsc_evt->bcn_l_rssi_cfg.evt_freq = 1;
  137. subsc_evt->bcn_h_rssi_cfg.evt_freq = 1;
  138. priv->subsc_evt_rssi_state = EVENT_HANDLED;
  139. mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  140. 0, 0, subsc_evt);
  141. return 0;
  142. }
  143. /*
  144. * This function handles the command response of set/get SNMP
  145. * MIB parameters.
  146. *
  147. * Handling includes changing the header fields into CPU format
  148. * and saving the parameter in driver.
  149. *
  150. * The following parameters are supported -
  151. * - Fragmentation threshold
  152. * - RTS threshold
  153. * - Short retry limit
  154. */
  155. static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
  156. struct host_cmd_ds_command *resp,
  157. u32 *data_buf)
  158. {
  159. struct host_cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
  160. u16 oid = le16_to_cpu(smib->oid);
  161. u16 query_type = le16_to_cpu(smib->query_type);
  162. u32 ul_temp;
  163. dev_dbg(priv->adapter->dev, "info: SNMP_RESP: oid value = %#x,"
  164. " query_type = %#x, buf size = %#x\n",
  165. oid, query_type, le16_to_cpu(smib->buf_size));
  166. if (query_type == HostCmd_ACT_GEN_GET) {
  167. ul_temp = le16_to_cpu(*((__le16 *) (smib->value)));
  168. if (data_buf)
  169. *data_buf = ul_temp;
  170. switch (oid) {
  171. case FRAG_THRESH_I:
  172. dev_dbg(priv->adapter->dev,
  173. "info: SNMP_RESP: FragThsd =%u\n", ul_temp);
  174. break;
  175. case RTS_THRESH_I:
  176. dev_dbg(priv->adapter->dev,
  177. "info: SNMP_RESP: RTSThsd =%u\n", ul_temp);
  178. break;
  179. case SHORT_RETRY_LIM_I:
  180. dev_dbg(priv->adapter->dev,
  181. "info: SNMP_RESP: TxRetryCount=%u\n", ul_temp);
  182. break;
  183. case DTIM_PERIOD_I:
  184. dev_dbg(priv->adapter->dev,
  185. "info: SNMP_RESP: DTIM period=%u\n", ul_temp);
  186. default:
  187. break;
  188. }
  189. }
  190. return 0;
  191. }
  192. /*
  193. * This function handles the command response of get log request
  194. *
  195. * Handling includes changing the header fields into CPU format
  196. * and sending the received parameters to application.
  197. */
  198. static int mwifiex_ret_get_log(struct mwifiex_private *priv,
  199. struct host_cmd_ds_command *resp,
  200. struct mwifiex_ds_get_stats *stats)
  201. {
  202. struct host_cmd_ds_802_11_get_log *get_log =
  203. &resp->params.get_log;
  204. if (stats) {
  205. stats->mcast_tx_frame = le32_to_cpu(get_log->mcast_tx_frame);
  206. stats->failed = le32_to_cpu(get_log->failed);
  207. stats->retry = le32_to_cpu(get_log->retry);
  208. stats->multi_retry = le32_to_cpu(get_log->multi_retry);
  209. stats->frame_dup = le32_to_cpu(get_log->frame_dup);
  210. stats->rts_success = le32_to_cpu(get_log->rts_success);
  211. stats->rts_failure = le32_to_cpu(get_log->rts_failure);
  212. stats->ack_failure = le32_to_cpu(get_log->ack_failure);
  213. stats->rx_frag = le32_to_cpu(get_log->rx_frag);
  214. stats->mcast_rx_frame = le32_to_cpu(get_log->mcast_rx_frame);
  215. stats->fcs_error = le32_to_cpu(get_log->fcs_error);
  216. stats->tx_frame = le32_to_cpu(get_log->tx_frame);
  217. stats->wep_icv_error[0] =
  218. le32_to_cpu(get_log->wep_icv_err_cnt[0]);
  219. stats->wep_icv_error[1] =
  220. le32_to_cpu(get_log->wep_icv_err_cnt[1]);
  221. stats->wep_icv_error[2] =
  222. le32_to_cpu(get_log->wep_icv_err_cnt[2]);
  223. stats->wep_icv_error[3] =
  224. le32_to_cpu(get_log->wep_icv_err_cnt[3]);
  225. }
  226. return 0;
  227. }
  228. /*
  229. * This function handles the command response of set/get Tx rate
  230. * configurations.
  231. *
  232. * Handling includes changing the header fields into CPU format
  233. * and saving the following parameters in driver -
  234. * - DSSS rate bitmap
  235. * - OFDM rate bitmap
  236. * - HT MCS rate bitmaps
  237. *
  238. * Based on the new rate bitmaps, the function re-evaluates if
  239. * auto data rate has been activated. If not, it sends another
  240. * query to the firmware to get the current Tx data rate.
  241. */
  242. static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
  243. struct host_cmd_ds_command *resp)
  244. {
  245. struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
  246. struct mwifiex_rate_scope *rate_scope;
  247. struct mwifiex_ie_types_header *head;
  248. u16 tlv, tlv_buf_len;
  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 = le16_to_cpu(*(__le16 *) (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. /* This function handles the command response of set_cfg_data */
  715. static int mwifiex_ret_cfg_data(struct mwifiex_private *priv,
  716. struct host_cmd_ds_command *resp)
  717. {
  718. if (resp->result != HostCmd_RESULT_OK) {
  719. dev_err(priv->adapter->dev, "Cal data cmd resp failed\n");
  720. return -1;
  721. }
  722. return 0;
  723. }
  724. /*
  725. * This function handles the command responses.
  726. *
  727. * This is a generic function, which calls command specific
  728. * response handlers based on the command ID.
  729. */
  730. int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
  731. struct host_cmd_ds_command *resp)
  732. {
  733. int ret = 0;
  734. struct mwifiex_adapter *adapter = priv->adapter;
  735. void *data_buf = adapter->curr_cmd->data_buf;
  736. /* If the command is not successful, cleanup and return failure */
  737. if (resp->result != HostCmd_RESULT_OK) {
  738. mwifiex_process_cmdresp_error(priv, resp);
  739. return -1;
  740. }
  741. /* Command successful, handle response */
  742. switch (cmdresp_no) {
  743. case HostCmd_CMD_GET_HW_SPEC:
  744. ret = mwifiex_ret_get_hw_spec(priv, resp);
  745. break;
  746. case HostCmd_CMD_CFG_DATA:
  747. ret = mwifiex_ret_cfg_data(priv, resp);
  748. break;
  749. case HostCmd_CMD_MAC_CONTROL:
  750. break;
  751. case HostCmd_CMD_802_11_MAC_ADDRESS:
  752. ret = mwifiex_ret_802_11_mac_address(priv, resp);
  753. break;
  754. case HostCmd_CMD_MAC_MULTICAST_ADR:
  755. ret = mwifiex_ret_mac_multicast_adr(priv, resp);
  756. break;
  757. case HostCmd_CMD_TX_RATE_CFG:
  758. ret = mwifiex_ret_tx_rate_cfg(priv, resp);
  759. break;
  760. case HostCmd_CMD_802_11_SCAN:
  761. ret = mwifiex_ret_802_11_scan(priv, resp);
  762. adapter->curr_cmd->wait_q_enabled = false;
  763. break;
  764. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  765. ret = mwifiex_ret_802_11_scan(priv, resp);
  766. dev_dbg(adapter->dev,
  767. "info: CMD_RESP: BG_SCAN result is ready!\n");
  768. break;
  769. case HostCmd_CMD_TXPWR_CFG:
  770. ret = mwifiex_ret_tx_power_cfg(priv, resp);
  771. break;
  772. case HostCmd_CMD_RF_TX_PWR:
  773. ret = mwifiex_ret_rf_tx_power(priv, resp);
  774. break;
  775. case HostCmd_CMD_RF_ANTENNA:
  776. ret = mwifiex_ret_rf_antenna(priv, resp);
  777. break;
  778. case HostCmd_CMD_802_11_PS_MODE_ENH:
  779. ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
  780. break;
  781. case HostCmd_CMD_802_11_HS_CFG_ENH:
  782. ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
  783. break;
  784. case HostCmd_CMD_802_11_ASSOCIATE:
  785. ret = mwifiex_ret_802_11_associate(priv, resp);
  786. break;
  787. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  788. ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
  789. break;
  790. case HostCmd_CMD_802_11_AD_HOC_START:
  791. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  792. ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
  793. break;
  794. case HostCmd_CMD_802_11_AD_HOC_STOP:
  795. ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
  796. break;
  797. case HostCmd_CMD_802_11_GET_LOG:
  798. ret = mwifiex_ret_get_log(priv, resp, data_buf);
  799. break;
  800. case HostCmd_CMD_RSSI_INFO:
  801. ret = mwifiex_ret_802_11_rssi_info(priv, resp);
  802. break;
  803. case HostCmd_CMD_802_11_SNMP_MIB:
  804. ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
  805. break;
  806. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  807. ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
  808. break;
  809. case HostCmd_CMD_VERSION_EXT:
  810. ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
  811. break;
  812. case HostCmd_CMD_REMAIN_ON_CHAN:
  813. ret = mwifiex_ret_remain_on_chan(priv, resp, data_buf);
  814. break;
  815. case HostCmd_CMD_11AC_CFG:
  816. break;
  817. case HostCmd_CMD_P2P_MODE_CFG:
  818. ret = mwifiex_ret_p2p_mode_cfg(priv, resp, data_buf);
  819. break;
  820. case HostCmd_CMD_MGMT_FRAME_REG:
  821. case HostCmd_CMD_FUNC_INIT:
  822. case HostCmd_CMD_FUNC_SHUTDOWN:
  823. break;
  824. case HostCmd_CMD_802_11_KEY_MATERIAL:
  825. ret = mwifiex_ret_802_11_key_material(priv, resp);
  826. break;
  827. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  828. ret = mwifiex_ret_802_11d_domain_info(priv, resp);
  829. break;
  830. case HostCmd_CMD_11N_ADDBA_REQ:
  831. ret = mwifiex_ret_11n_addba_req(priv, resp);
  832. break;
  833. case HostCmd_CMD_11N_DELBA:
  834. ret = mwifiex_ret_11n_delba(priv, resp);
  835. break;
  836. case HostCmd_CMD_11N_ADDBA_RSP:
  837. ret = mwifiex_ret_11n_addba_resp(priv, resp);
  838. break;
  839. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  840. adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
  841. tx_buf.buff_size);
  842. adapter->tx_buf_size = (adapter->tx_buf_size
  843. / MWIFIEX_SDIO_BLOCK_SIZE)
  844. * MWIFIEX_SDIO_BLOCK_SIZE;
  845. adapter->curr_tx_buf_size = adapter->tx_buf_size;
  846. dev_dbg(adapter->dev, "cmd: curr_tx_buf_size=%d\n",
  847. adapter->curr_tx_buf_size);
  848. if (adapter->if_ops.update_mp_end_port)
  849. adapter->if_ops.update_mp_end_port(adapter,
  850. le16_to_cpu(resp->params.tx_buf.mp_end_port));
  851. break;
  852. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  853. break;
  854. case HostCmd_CMD_WMM_GET_STATUS:
  855. ret = mwifiex_ret_wmm_get_status(priv, resp);
  856. break;
  857. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  858. ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
  859. break;
  860. case HostCmd_CMD_MAC_REG_ACCESS:
  861. case HostCmd_CMD_BBP_REG_ACCESS:
  862. case HostCmd_CMD_RF_REG_ACCESS:
  863. case HostCmd_CMD_PMIC_REG_ACCESS:
  864. case HostCmd_CMD_CAU_REG_ACCESS:
  865. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  866. ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
  867. break;
  868. case HostCmd_CMD_SET_BSS_MODE:
  869. break;
  870. case HostCmd_CMD_11N_CFG:
  871. break;
  872. case HostCmd_CMD_PCIE_DESC_DETAILS:
  873. break;
  874. case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
  875. ret = mwifiex_ret_subsc_evt(priv, resp);
  876. break;
  877. case HostCmd_CMD_UAP_SYS_CONFIG:
  878. break;
  879. case HostCmd_CMD_UAP_BSS_START:
  880. priv->bss_started = 1;
  881. break;
  882. case HostCmd_CMD_UAP_BSS_STOP:
  883. priv->bss_started = 0;
  884. break;
  885. case HostCmd_CMD_UAP_STA_DEAUTH:
  886. break;
  887. case HostCmd_CMD_MEF_CFG:
  888. break;
  889. case HostCmd_CMD_COALESCE_CFG:
  890. break;
  891. default:
  892. dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
  893. resp->command);
  894. break;
  895. }
  896. return ret;
  897. }