sta_cmdresp.c 29 KB

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