sta_cmdresp.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  1. /*
  2. * Marvell Wireless LAN device driver: station command response handling
  3. *
  4. * Copyright (C) 2011-2014, 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. #include "11ac.h"
  27. /*
  28. * This function handles the command response error case.
  29. *
  30. * For scan response error, the function cancels all the pending
  31. * scan commands and generates an event to inform the applications
  32. * of the scan completion.
  33. *
  34. * For Power Save command failure, we do not retry enter PS
  35. * command in case of Ad-hoc mode.
  36. *
  37. * For all other response errors, the current command buffer is freed
  38. * and returned to the free command queue.
  39. */
  40. static void
  41. mwifiex_process_cmdresp_error(struct mwifiex_private *priv,
  42. struct host_cmd_ds_command *resp)
  43. {
  44. struct mwifiex_adapter *adapter = priv->adapter;
  45. struct host_cmd_ds_802_11_ps_mode_enh *pm;
  46. unsigned long flags;
  47. mwifiex_dbg(adapter, ERROR,
  48. "CMD_RESP: cmd %#x error, result=%#x\n",
  49. resp->command, resp->result);
  50. if (adapter->curr_cmd->wait_q_enabled)
  51. adapter->cmd_wait_q.status = -1;
  52. switch (le16_to_cpu(resp->command)) {
  53. case HostCmd_CMD_802_11_PS_MODE_ENH:
  54. pm = &resp->params.psmode_enh;
  55. mwifiex_dbg(adapter, ERROR,
  56. "PS_MODE_ENH cmd failed: 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. case HostCmd_CMD_802_11_SCAN_EXT:
  66. mwifiex_cancel_pending_scan_cmd(adapter);
  67. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  68. adapter->scan_processing = false;
  69. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  70. break;
  71. case HostCmd_CMD_MAC_CONTROL:
  72. break;
  73. case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
  74. mwifiex_dbg(adapter, MSG,
  75. "SDIO RX single-port aggregation Not support\n");
  76. break;
  77. default:
  78. break;
  79. }
  80. /* Handling errors here */
  81. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  82. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  83. adapter->curr_cmd = NULL;
  84. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  85. }
  86. /*
  87. * This function handles the command response of get RSSI info.
  88. *
  89. * Handling includes changing the header fields into CPU format
  90. * and saving the following parameters in driver -
  91. * - Last data and beacon RSSI value
  92. * - Average data and beacon RSSI value
  93. * - Last data and beacon NF value
  94. * - Average data and beacon NF value
  95. *
  96. * The parameters are send to the application as well, along with
  97. * calculated SNR values.
  98. */
  99. static int mwifiex_ret_802_11_rssi_info(struct mwifiex_private *priv,
  100. struct host_cmd_ds_command *resp)
  101. {
  102. struct host_cmd_ds_802_11_rssi_info_rsp *rssi_info_rsp =
  103. &resp->params.rssi_info_rsp;
  104. struct mwifiex_ds_misc_subsc_evt *subsc_evt =
  105. &priv->async_subsc_evt_storage;
  106. priv->data_rssi_last = le16_to_cpu(rssi_info_rsp->data_rssi_last);
  107. priv->data_nf_last = le16_to_cpu(rssi_info_rsp->data_nf_last);
  108. priv->data_rssi_avg = le16_to_cpu(rssi_info_rsp->data_rssi_avg);
  109. priv->data_nf_avg = le16_to_cpu(rssi_info_rsp->data_nf_avg);
  110. priv->bcn_rssi_last = le16_to_cpu(rssi_info_rsp->bcn_rssi_last);
  111. priv->bcn_nf_last = le16_to_cpu(rssi_info_rsp->bcn_nf_last);
  112. priv->bcn_rssi_avg = le16_to_cpu(rssi_info_rsp->bcn_rssi_avg);
  113. priv->bcn_nf_avg = le16_to_cpu(rssi_info_rsp->bcn_nf_avg);
  114. if (priv->subsc_evt_rssi_state == EVENT_HANDLED)
  115. return 0;
  116. memset(subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
  117. /* Resubscribe low and high rssi events with new thresholds */
  118. subsc_evt->events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
  119. subsc_evt->action = HostCmd_ACT_BITWISE_SET;
  120. if (priv->subsc_evt_rssi_state == RSSI_LOW_RECVD) {
  121. subsc_evt->bcn_l_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg -
  122. priv->cqm_rssi_hyst);
  123. subsc_evt->bcn_h_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
  124. } else if (priv->subsc_evt_rssi_state == RSSI_HIGH_RECVD) {
  125. subsc_evt->bcn_l_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
  126. subsc_evt->bcn_h_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg +
  127. priv->cqm_rssi_hyst);
  128. }
  129. subsc_evt->bcn_l_rssi_cfg.evt_freq = 1;
  130. subsc_evt->bcn_h_rssi_cfg.evt_freq = 1;
  131. priv->subsc_evt_rssi_state = EVENT_HANDLED;
  132. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  133. 0, 0, subsc_evt, false);
  134. return 0;
  135. }
  136. /*
  137. * This function handles the command response of set/get SNMP
  138. * MIB parameters.
  139. *
  140. * Handling includes changing the header fields into CPU format
  141. * and saving the parameter in driver.
  142. *
  143. * The following parameters are supported -
  144. * - Fragmentation threshold
  145. * - RTS threshold
  146. * - Short retry limit
  147. */
  148. static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
  149. struct host_cmd_ds_command *resp,
  150. u32 *data_buf)
  151. {
  152. struct host_cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
  153. u16 oid = le16_to_cpu(smib->oid);
  154. u16 query_type = le16_to_cpu(smib->query_type);
  155. u32 ul_temp;
  156. mwifiex_dbg(priv->adapter, INFO,
  157. "info: SNMP_RESP: oid value = %#x,\t"
  158. "query_type = %#x, buf size = %#x\n",
  159. oid, query_type, le16_to_cpu(smib->buf_size));
  160. if (query_type == HostCmd_ACT_GEN_GET) {
  161. ul_temp = le16_to_cpu(*((__le16 *) (smib->value)));
  162. if (data_buf)
  163. *data_buf = ul_temp;
  164. switch (oid) {
  165. case FRAG_THRESH_I:
  166. mwifiex_dbg(priv->adapter, INFO,
  167. "info: SNMP_RESP: FragThsd =%u\n",
  168. ul_temp);
  169. break;
  170. case RTS_THRESH_I:
  171. mwifiex_dbg(priv->adapter, INFO,
  172. "info: SNMP_RESP: RTSThsd =%u\n",
  173. ul_temp);
  174. break;
  175. case SHORT_RETRY_LIM_I:
  176. mwifiex_dbg(priv->adapter, INFO,
  177. "info: SNMP_RESP: TxRetryCount=%u\n",
  178. ul_temp);
  179. break;
  180. case DTIM_PERIOD_I:
  181. mwifiex_dbg(priv->adapter, INFO,
  182. "info: SNMP_RESP: DTIM period=%u\n",
  183. ul_temp);
  184. default:
  185. break;
  186. }
  187. }
  188. return 0;
  189. }
  190. /*
  191. * This function handles the command response of get log request
  192. *
  193. * Handling includes changing the header fields into CPU format
  194. * and sending the received parameters to application.
  195. */
  196. static int mwifiex_ret_get_log(struct mwifiex_private *priv,
  197. struct host_cmd_ds_command *resp,
  198. struct mwifiex_ds_get_stats *stats)
  199. {
  200. struct host_cmd_ds_802_11_get_log *get_log =
  201. &resp->params.get_log;
  202. if (stats) {
  203. stats->mcast_tx_frame = le32_to_cpu(get_log->mcast_tx_frame);
  204. stats->failed = le32_to_cpu(get_log->failed);
  205. stats->retry = le32_to_cpu(get_log->retry);
  206. stats->multi_retry = le32_to_cpu(get_log->multi_retry);
  207. stats->frame_dup = le32_to_cpu(get_log->frame_dup);
  208. stats->rts_success = le32_to_cpu(get_log->rts_success);
  209. stats->rts_failure = le32_to_cpu(get_log->rts_failure);
  210. stats->ack_failure = le32_to_cpu(get_log->ack_failure);
  211. stats->rx_frag = le32_to_cpu(get_log->rx_frag);
  212. stats->mcast_rx_frame = le32_to_cpu(get_log->mcast_rx_frame);
  213. stats->fcs_error = le32_to_cpu(get_log->fcs_error);
  214. stats->tx_frame = le32_to_cpu(get_log->tx_frame);
  215. stats->wep_icv_error[0] =
  216. le32_to_cpu(get_log->wep_icv_err_cnt[0]);
  217. stats->wep_icv_error[1] =
  218. le32_to_cpu(get_log->wep_icv_err_cnt[1]);
  219. stats->wep_icv_error[2] =
  220. le32_to_cpu(get_log->wep_icv_err_cnt[2]);
  221. stats->wep_icv_error[3] =
  222. le32_to_cpu(get_log->wep_icv_err_cnt[3]);
  223. stats->bcn_rcv_cnt = le32_to_cpu(get_log->bcn_rcv_cnt);
  224. stats->bcn_miss_cnt = le32_to_cpu(get_log->bcn_miss_cnt);
  225. }
  226. return 0;
  227. }
  228. /*
  229. * This function handles the command response of set/get Tx rate
  230. * configurations.
  231. *
  232. * Handling includes changing the header fields into CPU format
  233. * and saving the following parameters in driver -
  234. * - DSSS rate bitmap
  235. * - OFDM rate bitmap
  236. * - HT MCS rate bitmaps
  237. *
  238. * Based on the new rate bitmaps, the function re-evaluates if
  239. * auto data rate has been activated. If not, it sends another
  240. * query to the firmware to get the current Tx data rate.
  241. */
  242. static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
  243. struct host_cmd_ds_command *resp)
  244. {
  245. struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
  246. struct mwifiex_rate_scope *rate_scope;
  247. struct mwifiex_ie_types_header *head;
  248. u16 tlv, tlv_buf_len, tlv_buf_left;
  249. u8 *tlv_buf;
  250. u32 i;
  251. tlv_buf = ((u8 *)rate_cfg) + sizeof(struct host_cmd_ds_tx_rate_cfg);
  252. tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*rate_cfg);
  253. while (tlv_buf_left >= sizeof(*head)) {
  254. head = (struct mwifiex_ie_types_header *)tlv_buf;
  255. tlv = le16_to_cpu(head->type);
  256. tlv_buf_len = le16_to_cpu(head->len);
  257. if (tlv_buf_left < (sizeof(*head) + tlv_buf_len))
  258. break;
  259. switch (tlv) {
  260. case TLV_TYPE_RATE_SCOPE:
  261. rate_scope = (struct mwifiex_rate_scope *) tlv_buf;
  262. priv->bitmap_rates[0] =
  263. le16_to_cpu(rate_scope->hr_dsss_rate_bitmap);
  264. priv->bitmap_rates[1] =
  265. le16_to_cpu(rate_scope->ofdm_rate_bitmap);
  266. for (i = 0;
  267. i <
  268. sizeof(rate_scope->ht_mcs_rate_bitmap) /
  269. sizeof(u16); i++)
  270. priv->bitmap_rates[2 + i] =
  271. le16_to_cpu(rate_scope->
  272. ht_mcs_rate_bitmap[i]);
  273. if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
  274. for (i = 0; i < ARRAY_SIZE(rate_scope->
  275. vht_mcs_rate_bitmap);
  276. i++)
  277. priv->bitmap_rates[10 + i] =
  278. le16_to_cpu(rate_scope->
  279. vht_mcs_rate_bitmap[i]);
  280. }
  281. break;
  282. /* Add RATE_DROP tlv here */
  283. }
  284. tlv_buf += (sizeof(*head) + tlv_buf_len);
  285. tlv_buf_left -= (sizeof(*head) + tlv_buf_len);
  286. }
  287. priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
  288. if (priv->is_data_rate_auto)
  289. priv->data_rate = 0;
  290. else
  291. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
  292. HostCmd_ACT_GEN_GET, 0, NULL, false);
  293. return 0;
  294. }
  295. /*
  296. * This function handles the command response of get Tx power level.
  297. *
  298. * Handling includes saving the maximum and minimum Tx power levels
  299. * in driver, as well as sending the values to user.
  300. */
  301. static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
  302. {
  303. int length, max_power = -1, min_power = -1;
  304. struct mwifiex_types_power_group *pg_tlv_hdr;
  305. struct mwifiex_power_group *pg;
  306. if (!data_buf)
  307. return -1;
  308. pg_tlv_hdr = (struct mwifiex_types_power_group *)((u8 *)data_buf);
  309. pg = (struct mwifiex_power_group *)
  310. ((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
  311. length = le16_to_cpu(pg_tlv_hdr->length);
  312. /* At least one structure required to update power */
  313. if (length < sizeof(struct mwifiex_power_group))
  314. return 0;
  315. max_power = pg->power_max;
  316. min_power = pg->power_min;
  317. length -= sizeof(struct mwifiex_power_group);
  318. while (length >= sizeof(struct mwifiex_power_group)) {
  319. pg++;
  320. if (max_power < pg->power_max)
  321. max_power = pg->power_max;
  322. if (min_power > pg->power_min)
  323. min_power = pg->power_min;
  324. length -= sizeof(struct mwifiex_power_group);
  325. }
  326. priv->min_tx_power_level = (u8) min_power;
  327. priv->max_tx_power_level = (u8) max_power;
  328. return 0;
  329. }
  330. /*
  331. * This function handles the command response of set/get Tx power
  332. * configurations.
  333. *
  334. * Handling includes changing the header fields into CPU format
  335. * and saving the current Tx power level in driver.
  336. */
  337. static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
  338. struct host_cmd_ds_command *resp)
  339. {
  340. struct mwifiex_adapter *adapter = priv->adapter;
  341. struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
  342. struct mwifiex_types_power_group *pg_tlv_hdr;
  343. struct mwifiex_power_group *pg;
  344. u16 action = le16_to_cpu(txp_cfg->action);
  345. u16 tlv_buf_left;
  346. pg_tlv_hdr = (struct mwifiex_types_power_group *)
  347. ((u8 *)txp_cfg +
  348. sizeof(struct host_cmd_ds_txpwr_cfg));
  349. pg = (struct mwifiex_power_group *)
  350. ((u8 *)pg_tlv_hdr +
  351. sizeof(struct mwifiex_types_power_group));
  352. tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*txp_cfg);
  353. if (tlv_buf_left <
  354. le16_to_cpu(pg_tlv_hdr->length) + sizeof(*pg_tlv_hdr))
  355. return 0;
  356. switch (action) {
  357. case HostCmd_ACT_GEN_GET:
  358. if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
  359. mwifiex_get_power_level(priv, pg_tlv_hdr);
  360. priv->tx_power_level = (u16) pg->power_min;
  361. break;
  362. case HostCmd_ACT_GEN_SET:
  363. if (!le32_to_cpu(txp_cfg->mode))
  364. break;
  365. if (pg->power_max == pg->power_min)
  366. priv->tx_power_level = (u16) pg->power_min;
  367. break;
  368. default:
  369. mwifiex_dbg(adapter, ERROR,
  370. "CMD_RESP: unknown cmd action %d\n",
  371. action);
  372. return 0;
  373. }
  374. mwifiex_dbg(adapter, INFO,
  375. "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
  376. priv->tx_power_level, priv->max_tx_power_level,
  377. priv->min_tx_power_level);
  378. return 0;
  379. }
  380. /*
  381. * This function handles the command response of get RF Tx power.
  382. */
  383. static int mwifiex_ret_rf_tx_power(struct mwifiex_private *priv,
  384. struct host_cmd_ds_command *resp)
  385. {
  386. struct host_cmd_ds_rf_tx_pwr *txp = &resp->params.txp;
  387. u16 action = le16_to_cpu(txp->action);
  388. priv->tx_power_level = le16_to_cpu(txp->cur_level);
  389. if (action == HostCmd_ACT_GEN_GET) {
  390. priv->max_tx_power_level = txp->max_power;
  391. priv->min_tx_power_level = txp->min_power;
  392. }
  393. mwifiex_dbg(priv->adapter, INFO,
  394. "Current TxPower Level=%d, Max Power=%d, Min Power=%d\n",
  395. priv->tx_power_level, priv->max_tx_power_level,
  396. priv->min_tx_power_level);
  397. return 0;
  398. }
  399. /*
  400. * This function handles the command response of set rf antenna
  401. */
  402. static int mwifiex_ret_rf_antenna(struct mwifiex_private *priv,
  403. struct host_cmd_ds_command *resp)
  404. {
  405. struct host_cmd_ds_rf_ant_mimo *ant_mimo = &resp->params.ant_mimo;
  406. struct host_cmd_ds_rf_ant_siso *ant_siso = &resp->params.ant_siso;
  407. struct mwifiex_adapter *adapter = priv->adapter;
  408. if (adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
  409. priv->tx_ant = le16_to_cpu(ant_mimo->tx_ant_mode);
  410. priv->rx_ant = le16_to_cpu(ant_mimo->rx_ant_mode);
  411. mwifiex_dbg(adapter, INFO,
  412. "RF_ANT_RESP: Tx action = 0x%x, Tx Mode = 0x%04x\t"
  413. "Rx action = 0x%x, Rx Mode = 0x%04x\n",
  414. le16_to_cpu(ant_mimo->action_tx),
  415. le16_to_cpu(ant_mimo->tx_ant_mode),
  416. le16_to_cpu(ant_mimo->action_rx),
  417. le16_to_cpu(ant_mimo->rx_ant_mode));
  418. } else {
  419. priv->tx_ant = le16_to_cpu(ant_siso->ant_mode);
  420. priv->rx_ant = le16_to_cpu(ant_siso->ant_mode);
  421. mwifiex_dbg(adapter, INFO,
  422. "RF_ANT_RESP: action = 0x%x, Mode = 0x%04x\n",
  423. le16_to_cpu(ant_siso->action),
  424. le16_to_cpu(ant_siso->ant_mode));
  425. }
  426. return 0;
  427. }
  428. /*
  429. * This function handles the command response of set/get MAC address.
  430. *
  431. * Handling includes saving the MAC address in driver.
  432. */
  433. static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
  434. struct host_cmd_ds_command *resp)
  435. {
  436. struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
  437. &resp->params.mac_addr;
  438. memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
  439. mwifiex_dbg(priv->adapter, INFO,
  440. "info: set mac address: %pM\n", priv->curr_addr);
  441. return 0;
  442. }
  443. /*
  444. * This function handles the command response of set/get MAC multicast
  445. * address.
  446. */
  447. static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
  448. struct host_cmd_ds_command *resp)
  449. {
  450. return 0;
  451. }
  452. /*
  453. * This function handles the command response of get Tx rate query.
  454. *
  455. * Handling includes changing the header fields into CPU format
  456. * and saving the Tx rate and HT information parameters in driver.
  457. *
  458. * Both rate configuration and current data rate can be retrieved
  459. * with this request.
  460. */
  461. static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
  462. struct host_cmd_ds_command *resp)
  463. {
  464. priv->tx_rate = resp->params.tx_rate.tx_rate;
  465. priv->tx_htinfo = resp->params.tx_rate.ht_info;
  466. if (!priv->is_data_rate_auto)
  467. priv->data_rate =
  468. mwifiex_index_to_data_rate(priv, priv->tx_rate,
  469. priv->tx_htinfo);
  470. return 0;
  471. }
  472. /*
  473. * This function handles the command response of a deauthenticate
  474. * command.
  475. *
  476. * If the deauthenticated MAC matches the current BSS MAC, the connection
  477. * state is reset.
  478. */
  479. static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
  480. struct host_cmd_ds_command *resp)
  481. {
  482. struct mwifiex_adapter *adapter = priv->adapter;
  483. adapter->dbg.num_cmd_deauth++;
  484. if (!memcmp(resp->params.deauth.mac_addr,
  485. &priv->curr_bss_params.bss_descriptor.mac_address,
  486. sizeof(resp->params.deauth.mac_addr)))
  487. mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING,
  488. false);
  489. return 0;
  490. }
  491. /*
  492. * This function handles the command response of ad-hoc stop.
  493. *
  494. * The function resets the connection state in driver.
  495. */
  496. static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
  497. struct host_cmd_ds_command *resp)
  498. {
  499. mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING, false);
  500. return 0;
  501. }
  502. /*
  503. * This function handles the command response of set/get v1 key material.
  504. *
  505. * Handling includes updating the driver parameters to reflect the
  506. * changes.
  507. */
  508. static int mwifiex_ret_802_11_key_material_v1(struct mwifiex_private *priv,
  509. struct host_cmd_ds_command *resp)
  510. {
  511. struct host_cmd_ds_802_11_key_material *key =
  512. &resp->params.key_material;
  513. if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
  514. if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
  515. mwifiex_dbg(priv->adapter, INFO,
  516. "info: key: GTK is set\n");
  517. priv->wpa_is_gtk_set = true;
  518. priv->scan_block = false;
  519. priv->port_open = true;
  520. }
  521. }
  522. memset(priv->aes_key.key_param_set.key, 0,
  523. sizeof(key->key_param_set.key));
  524. priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
  525. memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
  526. le16_to_cpu(priv->aes_key.key_param_set.key_len));
  527. return 0;
  528. }
  529. /*
  530. * This function handles the command response of set/get v2 key material.
  531. *
  532. * Handling includes updating the driver parameters to reflect the
  533. * changes.
  534. */
  535. static int mwifiex_ret_802_11_key_material_v2(struct mwifiex_private *priv,
  536. struct host_cmd_ds_command *resp)
  537. {
  538. struct host_cmd_ds_802_11_key_material_v2 *key_v2;
  539. __le16 len;
  540. key_v2 = &resp->params.key_material_v2;
  541. if (le16_to_cpu(key_v2->action) == HostCmd_ACT_GEN_SET) {
  542. if ((le16_to_cpu(key_v2->key_param_set.key_info) & KEY_MCAST)) {
  543. mwifiex_dbg(priv->adapter, INFO, "info: key: GTK is set\n");
  544. priv->wpa_is_gtk_set = true;
  545. priv->scan_block = false;
  546. priv->port_open = true;
  547. }
  548. }
  549. if (key_v2->key_param_set.key_type != KEY_TYPE_ID_AES)
  550. return 0;
  551. memset(priv->aes_key_v2.key_param_set.key_params.aes.key, 0,
  552. WLAN_KEY_LEN_CCMP);
  553. priv->aes_key_v2.key_param_set.key_params.aes.key_len =
  554. key_v2->key_param_set.key_params.aes.key_len;
  555. len = priv->aes_key_v2.key_param_set.key_params.aes.key_len;
  556. memcpy(priv->aes_key_v2.key_param_set.key_params.aes.key,
  557. key_v2->key_param_set.key_params.aes.key, le16_to_cpu(len));
  558. return 0;
  559. }
  560. /* Wrapper function for processing response of key material command */
  561. static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
  562. struct host_cmd_ds_command *resp)
  563. {
  564. if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
  565. return mwifiex_ret_802_11_key_material_v2(priv, resp);
  566. else
  567. return mwifiex_ret_802_11_key_material_v1(priv, resp);
  568. }
  569. /*
  570. * This function handles the command response of get 11d domain information.
  571. */
  572. static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
  573. struct host_cmd_ds_command *resp)
  574. {
  575. struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
  576. &resp->params.domain_info_resp;
  577. struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
  578. u16 action = le16_to_cpu(domain_info->action);
  579. u8 no_of_triplet;
  580. no_of_triplet = (u8) ((le16_to_cpu(domain->header.len)
  581. - IEEE80211_COUNTRY_STRING_LEN)
  582. / sizeof(struct ieee80211_country_ie_triplet));
  583. mwifiex_dbg(priv->adapter, INFO,
  584. "info: 11D Domain Info Resp: no_of_triplet=%d\n",
  585. no_of_triplet);
  586. if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
  587. mwifiex_dbg(priv->adapter, FATAL,
  588. "11D: invalid number of triplets %d returned\n",
  589. no_of_triplet);
  590. return -1;
  591. }
  592. switch (action) {
  593. case HostCmd_ACT_GEN_SET: /* Proc Set Action */
  594. break;
  595. case HostCmd_ACT_GEN_GET:
  596. break;
  597. default:
  598. mwifiex_dbg(priv->adapter, ERROR,
  599. "11D: invalid action:%d\n", domain_info->action);
  600. return -1;
  601. }
  602. return 0;
  603. }
  604. /*
  605. * This function handles the command response of get extended version.
  606. *
  607. * Handling includes forming the extended version string and sending it
  608. * to application.
  609. */
  610. static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
  611. struct host_cmd_ds_command *resp,
  612. struct host_cmd_ds_version_ext *version_ext)
  613. {
  614. struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
  615. if (version_ext) {
  616. version_ext->version_str_sel = ver_ext->version_str_sel;
  617. memcpy(version_ext->version_str, ver_ext->version_str,
  618. sizeof(char) * 128);
  619. memcpy(priv->version_str, ver_ext->version_str, 128);
  620. }
  621. return 0;
  622. }
  623. /*
  624. * This function handles the command response of remain on channel.
  625. */
  626. static int
  627. mwifiex_ret_remain_on_chan(struct mwifiex_private *priv,
  628. struct host_cmd_ds_command *resp,
  629. struct host_cmd_ds_remain_on_chan *roc_cfg)
  630. {
  631. struct host_cmd_ds_remain_on_chan *resp_cfg = &resp->params.roc_cfg;
  632. if (roc_cfg)
  633. memcpy(roc_cfg, resp_cfg, sizeof(*roc_cfg));
  634. return 0;
  635. }
  636. /*
  637. * This function handles the command response of P2P mode cfg.
  638. */
  639. static int
  640. mwifiex_ret_p2p_mode_cfg(struct mwifiex_private *priv,
  641. struct host_cmd_ds_command *resp,
  642. void *data_buf)
  643. {
  644. struct host_cmd_ds_p2p_mode_cfg *mode_cfg = &resp->params.mode_cfg;
  645. if (data_buf)
  646. *((u16 *)data_buf) = le16_to_cpu(mode_cfg->mode);
  647. return 0;
  648. }
  649. /* This function handles the command response of mem_access command
  650. */
  651. static int
  652. mwifiex_ret_mem_access(struct mwifiex_private *priv,
  653. struct host_cmd_ds_command *resp, void *pioctl_buf)
  654. {
  655. struct host_cmd_ds_mem_access *mem = (void *)&resp->params.mem;
  656. priv->mem_rw.addr = le32_to_cpu(mem->addr);
  657. priv->mem_rw.value = le32_to_cpu(mem->value);
  658. return 0;
  659. }
  660. /*
  661. * This function handles the command response of register access.
  662. *
  663. * The register value and offset are returned to the user. For EEPROM
  664. * access, the byte count is also returned.
  665. */
  666. static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
  667. void *data_buf)
  668. {
  669. struct mwifiex_ds_reg_rw *reg_rw;
  670. struct mwifiex_ds_read_eeprom *eeprom;
  671. union reg {
  672. struct host_cmd_ds_mac_reg_access *mac;
  673. struct host_cmd_ds_bbp_reg_access *bbp;
  674. struct host_cmd_ds_rf_reg_access *rf;
  675. struct host_cmd_ds_pmic_reg_access *pmic;
  676. struct host_cmd_ds_802_11_eeprom_access *eeprom;
  677. } r;
  678. if (!data_buf)
  679. return 0;
  680. reg_rw = data_buf;
  681. eeprom = data_buf;
  682. switch (type) {
  683. case HostCmd_CMD_MAC_REG_ACCESS:
  684. r.mac = &resp->params.mac_reg;
  685. reg_rw->offset = (u32) le16_to_cpu(r.mac->offset);
  686. reg_rw->value = le32_to_cpu(r.mac->value);
  687. break;
  688. case HostCmd_CMD_BBP_REG_ACCESS:
  689. r.bbp = &resp->params.bbp_reg;
  690. reg_rw->offset = (u32) le16_to_cpu(r.bbp->offset);
  691. reg_rw->value = (u32) r.bbp->value;
  692. break;
  693. case HostCmd_CMD_RF_REG_ACCESS:
  694. r.rf = &resp->params.rf_reg;
  695. reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
  696. reg_rw->value = (u32) r.bbp->value;
  697. break;
  698. case HostCmd_CMD_PMIC_REG_ACCESS:
  699. r.pmic = &resp->params.pmic_reg;
  700. reg_rw->offset = (u32) le16_to_cpu(r.pmic->offset);
  701. reg_rw->value = (u32) r.pmic->value;
  702. break;
  703. case HostCmd_CMD_CAU_REG_ACCESS:
  704. r.rf = &resp->params.rf_reg;
  705. reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
  706. reg_rw->value = (u32) r.rf->value;
  707. break;
  708. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  709. r.eeprom = &resp->params.eeprom;
  710. pr_debug("info: EEPROM read len=%x\n",
  711. le16_to_cpu(r.eeprom->byte_count));
  712. if (eeprom->byte_count < le16_to_cpu(r.eeprom->byte_count)) {
  713. eeprom->byte_count = 0;
  714. pr_debug("info: EEPROM read length is too big\n");
  715. return -1;
  716. }
  717. eeprom->offset = le16_to_cpu(r.eeprom->offset);
  718. eeprom->byte_count = le16_to_cpu(r.eeprom->byte_count);
  719. if (eeprom->byte_count > 0)
  720. memcpy(&eeprom->value, &r.eeprom->value,
  721. min((u16)MAX_EEPROM_DATA, eeprom->byte_count));
  722. break;
  723. default:
  724. return -1;
  725. }
  726. return 0;
  727. }
  728. /*
  729. * This function handles the command response of get IBSS coalescing status.
  730. *
  731. * If the received BSSID is different than the current one, the current BSSID,
  732. * beacon interval, ATIM window and ERP information are updated, along with
  733. * changing the ad-hoc state accordingly.
  734. */
  735. static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
  736. struct host_cmd_ds_command *resp)
  737. {
  738. struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
  739. &(resp->params.ibss_coalescing);
  740. if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
  741. return 0;
  742. mwifiex_dbg(priv->adapter, INFO,
  743. "info: new BSSID %pM\n", ibss_coal_resp->bssid);
  744. /* If rsp has NULL BSSID, Just return..... No Action */
  745. if (is_zero_ether_addr(ibss_coal_resp->bssid)) {
  746. mwifiex_dbg(priv->adapter, FATAL, "new BSSID is NULL\n");
  747. return 0;
  748. }
  749. /* If BSSID is diff, modify current BSS parameters */
  750. if (!ether_addr_equal(priv->curr_bss_params.bss_descriptor.mac_address, ibss_coal_resp->bssid)) {
  751. /* BSSID */
  752. memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
  753. ibss_coal_resp->bssid, ETH_ALEN);
  754. /* Beacon Interval */
  755. priv->curr_bss_params.bss_descriptor.beacon_period
  756. = le16_to_cpu(ibss_coal_resp->beacon_interval);
  757. /* ERP Information */
  758. priv->curr_bss_params.bss_descriptor.erp_flags =
  759. (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
  760. priv->adhoc_state = ADHOC_COALESCED;
  761. }
  762. return 0;
  763. }
  764. static int mwifiex_ret_tdls_oper(struct mwifiex_private *priv,
  765. struct host_cmd_ds_command *resp)
  766. {
  767. struct host_cmd_ds_tdls_oper *cmd_tdls_oper = &resp->params.tdls_oper;
  768. u16 reason = le16_to_cpu(cmd_tdls_oper->reason);
  769. u16 action = le16_to_cpu(cmd_tdls_oper->tdls_action);
  770. struct mwifiex_sta_node *node =
  771. mwifiex_get_sta_entry(priv, cmd_tdls_oper->peer_mac);
  772. switch (action) {
  773. case ACT_TDLS_DELETE:
  774. if (reason) {
  775. if (!node || reason == TDLS_ERR_LINK_NONEXISTENT)
  776. mwifiex_dbg(priv->adapter, MSG,
  777. "TDLS link delete for %pM failed: reason %d\n",
  778. cmd_tdls_oper->peer_mac, reason);
  779. else
  780. mwifiex_dbg(priv->adapter, ERROR,
  781. "TDLS link delete for %pM failed: reason %d\n",
  782. cmd_tdls_oper->peer_mac, reason);
  783. } else {
  784. mwifiex_dbg(priv->adapter, MSG,
  785. "TDLS link delete for %pM successful\n",
  786. cmd_tdls_oper->peer_mac);
  787. }
  788. break;
  789. case ACT_TDLS_CREATE:
  790. if (reason) {
  791. mwifiex_dbg(priv->adapter, ERROR,
  792. "TDLS link creation for %pM failed: reason %d",
  793. cmd_tdls_oper->peer_mac, reason);
  794. if (node && reason != TDLS_ERR_LINK_EXISTS)
  795. node->tdls_status = TDLS_SETUP_FAILURE;
  796. } else {
  797. mwifiex_dbg(priv->adapter, MSG,
  798. "TDLS link creation for %pM successful",
  799. cmd_tdls_oper->peer_mac);
  800. }
  801. break;
  802. case ACT_TDLS_CONFIG:
  803. if (reason) {
  804. mwifiex_dbg(priv->adapter, ERROR,
  805. "TDLS link config for %pM failed, reason %d\n",
  806. cmd_tdls_oper->peer_mac, reason);
  807. if (node)
  808. node->tdls_status = TDLS_SETUP_FAILURE;
  809. } else {
  810. mwifiex_dbg(priv->adapter, MSG,
  811. "TDLS link config for %pM successful\n",
  812. cmd_tdls_oper->peer_mac);
  813. }
  814. break;
  815. default:
  816. mwifiex_dbg(priv->adapter, ERROR,
  817. "Unknown TDLS command action response %d", action);
  818. return -1;
  819. }
  820. return 0;
  821. }
  822. /*
  823. * This function handles the command response for subscribe event command.
  824. */
  825. static int mwifiex_ret_subsc_evt(struct mwifiex_private *priv,
  826. struct host_cmd_ds_command *resp)
  827. {
  828. struct host_cmd_ds_802_11_subsc_evt *cmd_sub_event =
  829. &resp->params.subsc_evt;
  830. /* For every subscribe event command (Get/Set/Clear), FW reports the
  831. * current set of subscribed events*/
  832. mwifiex_dbg(priv->adapter, EVENT,
  833. "Bitmap of currently subscribed events: %16x\n",
  834. le16_to_cpu(cmd_sub_event->events));
  835. return 0;
  836. }
  837. static int mwifiex_ret_uap_sta_list(struct mwifiex_private *priv,
  838. struct host_cmd_ds_command *resp)
  839. {
  840. struct host_cmd_ds_sta_list *sta_list =
  841. &resp->params.sta_list;
  842. struct mwifiex_ie_types_sta_info *sta_info = (void *)&sta_list->tlv;
  843. int i;
  844. struct mwifiex_sta_node *sta_node;
  845. for (i = 0; i < (le16_to_cpu(sta_list->sta_count)); i++) {
  846. sta_node = mwifiex_get_sta_entry(priv, sta_info->mac);
  847. if (unlikely(!sta_node))
  848. continue;
  849. sta_node->stats.rssi = sta_info->rssi;
  850. sta_info++;
  851. }
  852. return 0;
  853. }
  854. /* This function handles the command response of set_cfg_data */
  855. static int mwifiex_ret_cfg_data(struct mwifiex_private *priv,
  856. struct host_cmd_ds_command *resp)
  857. {
  858. if (resp->result != HostCmd_RESULT_OK) {
  859. mwifiex_dbg(priv->adapter, ERROR, "Cal data cmd resp failed\n");
  860. return -1;
  861. }
  862. return 0;
  863. }
  864. /** This Function handles the command response of sdio rx aggr */
  865. static int mwifiex_ret_sdio_rx_aggr_cfg(struct mwifiex_private *priv,
  866. struct host_cmd_ds_command *resp)
  867. {
  868. struct mwifiex_adapter *adapter = priv->adapter;
  869. struct host_cmd_sdio_sp_rx_aggr_cfg *cfg =
  870. &resp->params.sdio_rx_aggr_cfg;
  871. adapter->sdio_rx_aggr_enable = cfg->enable;
  872. adapter->sdio_rx_block_size = le16_to_cpu(cfg->block_size);
  873. return 0;
  874. }
  875. static int mwifiex_ret_robust_coex(struct mwifiex_private *priv,
  876. struct host_cmd_ds_command *resp,
  877. bool *is_timeshare)
  878. {
  879. struct host_cmd_ds_robust_coex *coex = &resp->params.coex;
  880. struct mwifiex_ie_types_robust_coex *coex_tlv;
  881. u16 action = le16_to_cpu(coex->action);
  882. u32 mode;
  883. coex_tlv = (struct mwifiex_ie_types_robust_coex
  884. *)((u8 *)coex + sizeof(struct host_cmd_ds_robust_coex));
  885. if (action == HostCmd_ACT_GEN_GET) {
  886. mode = le32_to_cpu(coex_tlv->mode);
  887. if (mode == MWIFIEX_COEX_MODE_TIMESHARE)
  888. *is_timeshare = true;
  889. else
  890. *is_timeshare = false;
  891. }
  892. return 0;
  893. }
  894. static struct ieee80211_regdomain *
  895. mwifiex_create_custom_regdomain(struct mwifiex_private *priv,
  896. u8 *buf, u16 buf_len)
  897. {
  898. u16 num_chan = buf_len / 2;
  899. struct ieee80211_regdomain *regd;
  900. struct ieee80211_reg_rule *rule;
  901. bool new_rule;
  902. int regd_size, idx, freq, prev_freq = 0;
  903. u32 bw, prev_bw = 0;
  904. u8 chflags, prev_chflags = 0, valid_rules = 0;
  905. if (WARN_ON_ONCE(num_chan > NL80211_MAX_SUPP_REG_RULES))
  906. return ERR_PTR(-EINVAL);
  907. regd_size = sizeof(struct ieee80211_regdomain) +
  908. num_chan * sizeof(struct ieee80211_reg_rule);
  909. regd = kzalloc(regd_size, GFP_KERNEL);
  910. if (!regd)
  911. return ERR_PTR(-ENOMEM);
  912. for (idx = 0; idx < num_chan; idx++) {
  913. u8 chan;
  914. enum nl80211_band band;
  915. chan = *buf++;
  916. if (!chan) {
  917. kfree(regd);
  918. return NULL;
  919. }
  920. chflags = *buf++;
  921. band = (chan <= 14) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
  922. freq = ieee80211_channel_to_frequency(chan, band);
  923. new_rule = false;
  924. if (chflags & MWIFIEX_CHANNEL_DISABLED)
  925. continue;
  926. if (band == NL80211_BAND_5GHZ) {
  927. if (!(chflags & MWIFIEX_CHANNEL_NOHT80))
  928. bw = MHZ_TO_KHZ(80);
  929. else if (!(chflags & MWIFIEX_CHANNEL_NOHT40))
  930. bw = MHZ_TO_KHZ(40);
  931. else
  932. bw = MHZ_TO_KHZ(20);
  933. } else {
  934. if (!(chflags & MWIFIEX_CHANNEL_NOHT40))
  935. bw = MHZ_TO_KHZ(40);
  936. else
  937. bw = MHZ_TO_KHZ(20);
  938. }
  939. if (idx == 0 || prev_chflags != chflags || prev_bw != bw ||
  940. freq - prev_freq > 20) {
  941. valid_rules++;
  942. new_rule = true;
  943. }
  944. rule = &regd->reg_rules[valid_rules - 1];
  945. rule->freq_range.end_freq_khz = MHZ_TO_KHZ(freq + 10);
  946. prev_chflags = chflags;
  947. prev_freq = freq;
  948. prev_bw = bw;
  949. if (!new_rule)
  950. continue;
  951. rule->freq_range.start_freq_khz = MHZ_TO_KHZ(freq - 10);
  952. rule->power_rule.max_eirp = DBM_TO_MBM(19);
  953. if (chflags & MWIFIEX_CHANNEL_PASSIVE)
  954. rule->flags = NL80211_RRF_NO_IR;
  955. if (chflags & MWIFIEX_CHANNEL_DFS)
  956. rule->flags = NL80211_RRF_DFS;
  957. rule->freq_range.max_bandwidth_khz = bw;
  958. }
  959. regd->n_reg_rules = valid_rules;
  960. regd->alpha2[0] = '9';
  961. regd->alpha2[1] = '9';
  962. return regd;
  963. }
  964. static int mwifiex_ret_chan_region_cfg(struct mwifiex_private *priv,
  965. struct host_cmd_ds_command *resp)
  966. {
  967. struct host_cmd_ds_chan_region_cfg *reg = &resp->params.reg_cfg;
  968. u16 action = le16_to_cpu(reg->action);
  969. u16 tlv, tlv_buf_len, tlv_buf_left;
  970. struct mwifiex_ie_types_header *head;
  971. struct ieee80211_regdomain *regd;
  972. u8 *tlv_buf;
  973. if (action != HostCmd_ACT_GEN_GET)
  974. return 0;
  975. tlv_buf = (u8 *)reg + sizeof(*reg);
  976. tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*reg);
  977. while (tlv_buf_left >= sizeof(*head)) {
  978. head = (struct mwifiex_ie_types_header *)tlv_buf;
  979. tlv = le16_to_cpu(head->type);
  980. tlv_buf_len = le16_to_cpu(head->len);
  981. if (tlv_buf_left < (sizeof(*head) + tlv_buf_len))
  982. break;
  983. switch (tlv) {
  984. case TLV_TYPE_CHAN_ATTR_CFG:
  985. mwifiex_dbg_dump(priv->adapter, CMD_D, "CHAN:",
  986. (u8 *)head + sizeof(*head),
  987. tlv_buf_len);
  988. regd = mwifiex_create_custom_regdomain(priv,
  989. (u8 *)head + sizeof(*head), tlv_buf_len);
  990. if (!IS_ERR(regd))
  991. priv->adapter->regd = regd;
  992. break;
  993. }
  994. tlv_buf += (sizeof(*head) + tlv_buf_len);
  995. tlv_buf_left -= (sizeof(*head) + tlv_buf_len);
  996. }
  997. return 0;
  998. }
  999. /*
  1000. * This function handles the command responses.
  1001. *
  1002. * This is a generic function, which calls command specific
  1003. * response handlers based on the command ID.
  1004. */
  1005. int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
  1006. struct host_cmd_ds_command *resp)
  1007. {
  1008. int ret = 0;
  1009. struct mwifiex_adapter *adapter = priv->adapter;
  1010. void *data_buf = adapter->curr_cmd->data_buf;
  1011. /* If the command is not successful, cleanup and return failure */
  1012. if (resp->result != HostCmd_RESULT_OK) {
  1013. mwifiex_process_cmdresp_error(priv, resp);
  1014. return -1;
  1015. }
  1016. /* Command successful, handle response */
  1017. switch (cmdresp_no) {
  1018. case HostCmd_CMD_GET_HW_SPEC:
  1019. ret = mwifiex_ret_get_hw_spec(priv, resp);
  1020. break;
  1021. case HostCmd_CMD_CFG_DATA:
  1022. ret = mwifiex_ret_cfg_data(priv, resp);
  1023. break;
  1024. case HostCmd_CMD_MAC_CONTROL:
  1025. break;
  1026. case HostCmd_CMD_802_11_MAC_ADDRESS:
  1027. ret = mwifiex_ret_802_11_mac_address(priv, resp);
  1028. break;
  1029. case HostCmd_CMD_MAC_MULTICAST_ADR:
  1030. ret = mwifiex_ret_mac_multicast_adr(priv, resp);
  1031. break;
  1032. case HostCmd_CMD_TX_RATE_CFG:
  1033. ret = mwifiex_ret_tx_rate_cfg(priv, resp);
  1034. break;
  1035. case HostCmd_CMD_802_11_SCAN:
  1036. ret = mwifiex_ret_802_11_scan(priv, resp);
  1037. adapter->curr_cmd->wait_q_enabled = false;
  1038. break;
  1039. case HostCmd_CMD_802_11_SCAN_EXT:
  1040. ret = mwifiex_ret_802_11_scan_ext(priv, resp);
  1041. adapter->curr_cmd->wait_q_enabled = false;
  1042. break;
  1043. case HostCmd_CMD_802_11_BG_SCAN_QUERY:
  1044. ret = mwifiex_ret_802_11_scan(priv, resp);
  1045. cfg80211_sched_scan_results(priv->wdev.wiphy);
  1046. mwifiex_dbg(adapter, CMD,
  1047. "info: CMD_RESP: BG_SCAN result is ready!\n");
  1048. break;
  1049. case HostCmd_CMD_802_11_BG_SCAN_CONFIG:
  1050. break;
  1051. case HostCmd_CMD_TXPWR_CFG:
  1052. ret = mwifiex_ret_tx_power_cfg(priv, resp);
  1053. break;
  1054. case HostCmd_CMD_RF_TX_PWR:
  1055. ret = mwifiex_ret_rf_tx_power(priv, resp);
  1056. break;
  1057. case HostCmd_CMD_RF_ANTENNA:
  1058. ret = mwifiex_ret_rf_antenna(priv, resp);
  1059. break;
  1060. case HostCmd_CMD_802_11_PS_MODE_ENH:
  1061. ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
  1062. break;
  1063. case HostCmd_CMD_802_11_HS_CFG_ENH:
  1064. ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
  1065. break;
  1066. case HostCmd_CMD_802_11_ASSOCIATE:
  1067. ret = mwifiex_ret_802_11_associate(priv, resp);
  1068. break;
  1069. case HostCmd_CMD_802_11_DEAUTHENTICATE:
  1070. ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
  1071. break;
  1072. case HostCmd_CMD_802_11_AD_HOC_START:
  1073. case HostCmd_CMD_802_11_AD_HOC_JOIN:
  1074. ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
  1075. break;
  1076. case HostCmd_CMD_802_11_AD_HOC_STOP:
  1077. ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
  1078. break;
  1079. case HostCmd_CMD_802_11_GET_LOG:
  1080. ret = mwifiex_ret_get_log(priv, resp, data_buf);
  1081. break;
  1082. case HostCmd_CMD_RSSI_INFO:
  1083. ret = mwifiex_ret_802_11_rssi_info(priv, resp);
  1084. break;
  1085. case HostCmd_CMD_802_11_SNMP_MIB:
  1086. ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
  1087. break;
  1088. case HostCmd_CMD_802_11_TX_RATE_QUERY:
  1089. ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
  1090. break;
  1091. case HostCmd_CMD_VERSION_EXT:
  1092. ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
  1093. break;
  1094. case HostCmd_CMD_REMAIN_ON_CHAN:
  1095. ret = mwifiex_ret_remain_on_chan(priv, resp, data_buf);
  1096. break;
  1097. case HostCmd_CMD_11AC_CFG:
  1098. break;
  1099. case HostCmd_CMD_P2P_MODE_CFG:
  1100. ret = mwifiex_ret_p2p_mode_cfg(priv, resp, data_buf);
  1101. break;
  1102. case HostCmd_CMD_MGMT_FRAME_REG:
  1103. case HostCmd_CMD_FUNC_INIT:
  1104. case HostCmd_CMD_FUNC_SHUTDOWN:
  1105. break;
  1106. case HostCmd_CMD_802_11_KEY_MATERIAL:
  1107. ret = mwifiex_ret_802_11_key_material(priv, resp);
  1108. break;
  1109. case HostCmd_CMD_802_11D_DOMAIN_INFO:
  1110. ret = mwifiex_ret_802_11d_domain_info(priv, resp);
  1111. break;
  1112. case HostCmd_CMD_11N_ADDBA_REQ:
  1113. ret = mwifiex_ret_11n_addba_req(priv, resp);
  1114. break;
  1115. case HostCmd_CMD_11N_DELBA:
  1116. ret = mwifiex_ret_11n_delba(priv, resp);
  1117. break;
  1118. case HostCmd_CMD_11N_ADDBA_RSP:
  1119. ret = mwifiex_ret_11n_addba_resp(priv, resp);
  1120. break;
  1121. case HostCmd_CMD_RECONFIGURE_TX_BUFF:
  1122. if (0xffff == (u16)le16_to_cpu(resp->params.tx_buf.buff_size)) {
  1123. if (adapter->iface_type == MWIFIEX_USB &&
  1124. adapter->usb_mc_setup) {
  1125. if (adapter->if_ops.multi_port_resync)
  1126. adapter->if_ops.
  1127. multi_port_resync(adapter);
  1128. adapter->usb_mc_setup = false;
  1129. adapter->tx_lock_flag = false;
  1130. }
  1131. break;
  1132. }
  1133. adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
  1134. tx_buf.buff_size);
  1135. adapter->tx_buf_size = (adapter->tx_buf_size
  1136. / MWIFIEX_SDIO_BLOCK_SIZE)
  1137. * MWIFIEX_SDIO_BLOCK_SIZE;
  1138. adapter->curr_tx_buf_size = adapter->tx_buf_size;
  1139. mwifiex_dbg(adapter, CMD, "cmd: curr_tx_buf_size=%d\n",
  1140. adapter->curr_tx_buf_size);
  1141. if (adapter->if_ops.update_mp_end_port)
  1142. adapter->if_ops.update_mp_end_port(adapter,
  1143. le16_to_cpu(resp->params.tx_buf.mp_end_port));
  1144. break;
  1145. case HostCmd_CMD_AMSDU_AGGR_CTRL:
  1146. break;
  1147. case HostCmd_CMD_WMM_GET_STATUS:
  1148. ret = mwifiex_ret_wmm_get_status(priv, resp);
  1149. break;
  1150. case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
  1151. ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
  1152. break;
  1153. case HostCmd_CMD_MEM_ACCESS:
  1154. ret = mwifiex_ret_mem_access(priv, resp, data_buf);
  1155. break;
  1156. case HostCmd_CMD_MAC_REG_ACCESS:
  1157. case HostCmd_CMD_BBP_REG_ACCESS:
  1158. case HostCmd_CMD_RF_REG_ACCESS:
  1159. case HostCmd_CMD_PMIC_REG_ACCESS:
  1160. case HostCmd_CMD_CAU_REG_ACCESS:
  1161. case HostCmd_CMD_802_11_EEPROM_ACCESS:
  1162. ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
  1163. break;
  1164. case HostCmd_CMD_SET_BSS_MODE:
  1165. break;
  1166. case HostCmd_CMD_11N_CFG:
  1167. break;
  1168. case HostCmd_CMD_PCIE_DESC_DETAILS:
  1169. break;
  1170. case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
  1171. ret = mwifiex_ret_subsc_evt(priv, resp);
  1172. break;
  1173. case HostCmd_CMD_UAP_SYS_CONFIG:
  1174. break;
  1175. case HOST_CMD_APCMD_STA_LIST:
  1176. ret = mwifiex_ret_uap_sta_list(priv, resp);
  1177. break;
  1178. case HostCmd_CMD_UAP_BSS_START:
  1179. adapter->tx_lock_flag = false;
  1180. adapter->pps_uapsd_mode = false;
  1181. adapter->delay_null_pkt = false;
  1182. priv->bss_started = 1;
  1183. break;
  1184. case HostCmd_CMD_UAP_BSS_STOP:
  1185. priv->bss_started = 0;
  1186. break;
  1187. case HostCmd_CMD_UAP_STA_DEAUTH:
  1188. break;
  1189. case HOST_CMD_APCMD_SYS_RESET:
  1190. break;
  1191. case HostCmd_CMD_MEF_CFG:
  1192. break;
  1193. case HostCmd_CMD_COALESCE_CFG:
  1194. break;
  1195. case HostCmd_CMD_TDLS_OPER:
  1196. ret = mwifiex_ret_tdls_oper(priv, resp);
  1197. case HostCmd_CMD_MC_POLICY:
  1198. break;
  1199. case HostCmd_CMD_CHAN_REPORT_REQUEST:
  1200. break;
  1201. case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
  1202. ret = mwifiex_ret_sdio_rx_aggr_cfg(priv, resp);
  1203. break;
  1204. case HostCmd_CMD_HS_WAKEUP_REASON:
  1205. ret = mwifiex_ret_wakeup_reason(priv, resp, data_buf);
  1206. break;
  1207. case HostCmd_CMD_TDLS_CONFIG:
  1208. break;
  1209. case HostCmd_CMD_ROBUST_COEX:
  1210. ret = mwifiex_ret_robust_coex(priv, resp, data_buf);
  1211. break;
  1212. case HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG:
  1213. break;
  1214. case HostCmd_CMD_CHAN_REGION_CFG:
  1215. ret = mwifiex_ret_chan_region_cfg(priv, resp);
  1216. break;
  1217. default:
  1218. mwifiex_dbg(adapter, ERROR,
  1219. "CMD_RESP: unknown cmd response %#x\n",
  1220. resp->command);
  1221. break;
  1222. }
  1223. return ret;
  1224. }