sta_cmdresp.c 29 KB

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