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