sta_cmdresp.c 28 KB

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