sta_cmdresp.c 28 KB

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