sta_cmdresp.c 28 KB

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