blob: cd4e0f05d82fbfac31be7dbbc45ae7ffe66d682b [file] [log] [blame]
Larry Finger5e93f352014-03-28 21:37:38 -05001/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15#define _RTW_CMD_C_
16
17#include <osdep_service.h>
18#include <drv_types.h>
19#include <recv_osdep.h>
Larry Finger5e93f352014-03-28 21:37:38 -050020#include <mlme_osdep.h>
Larry Finger88cdc942014-04-09 23:21:18 +020021#include <rtl8723a_cmd.h>
Jes Sorensen96808172014-05-21 09:37:25 +020022#include <rtw_sreset.h>
Larry Finger5e93f352014-03-28 21:37:38 -050023
Larry Finger5e93f352014-03-28 21:37:38 -050024static struct cmd_hdl wlancmds[] = {
25 GEN_DRV_CMD_HANDLER(0, NULL) /*0*/
26 GEN_DRV_CMD_HANDLER(0, NULL)
27 GEN_DRV_CMD_HANDLER(0, NULL)
28 GEN_DRV_CMD_HANDLER(0, NULL)
29 GEN_DRV_CMD_HANDLER(0, NULL)
30 GEN_DRV_CMD_HANDLER(0, NULL)
31 GEN_MLME_EXT_HANDLER(0, NULL)
32 GEN_MLME_EXT_HANDLER(0, NULL)
33 GEN_MLME_EXT_HANDLER(0, NULL)
34 GEN_MLME_EXT_HANDLER(0, NULL)
35 GEN_MLME_EXT_HANDLER(0, NULL) /*10*/
36 GEN_MLME_EXT_HANDLER(0, NULL)
37 GEN_MLME_EXT_HANDLER(0, NULL)
38 GEN_MLME_EXT_HANDLER(0, NULL)
anuvazhayiled09b442014-10-29 03:43:26 +053039 GEN_MLME_EXT_HANDLER(sizeof(struct wlan_bssid_ex), join_cmd_hdl23a) /*14*/
40 GEN_MLME_EXT_HANDLER(sizeof(struct disconnect_parm), disconnect_hdl23a)
41 GEN_MLME_EXT_HANDLER(sizeof(struct wlan_bssid_ex), createbss_hdl23a)
42 GEN_MLME_EXT_HANDLER(sizeof(struct setopmode_parm), setopmode_hdl23a)
43 GEN_MLME_EXT_HANDLER(sizeof(struct sitesurvey_parm), sitesurvey_cmd_hdl23a) /*18*/
44 GEN_MLME_EXT_HANDLER(sizeof(struct setauth_parm), setauth_hdl23a)
45 GEN_MLME_EXT_HANDLER(sizeof(struct setkey_parm), setkey_hdl23a) /*20*/
46 GEN_MLME_EXT_HANDLER(sizeof(struct set_stakey_parm), set_stakey_hdl23a)
47 GEN_MLME_EXT_HANDLER(sizeof(struct set_assocsta_parm), NULL)
48 GEN_MLME_EXT_HANDLER(sizeof(struct del_assocsta_parm), NULL)
49 GEN_MLME_EXT_HANDLER(sizeof(struct setstapwrstate_parm), NULL)
50 GEN_MLME_EXT_HANDLER(sizeof(struct setbasicrate_parm), NULL)
51 GEN_MLME_EXT_HANDLER(sizeof(struct getbasicrate_parm), NULL)
52 GEN_MLME_EXT_HANDLER(sizeof(struct setdatarate_parm), NULL)
53 GEN_MLME_EXT_HANDLER(sizeof(struct getdatarate_parm), NULL)
54 GEN_MLME_EXT_HANDLER(sizeof(struct setphyinfo_parm), NULL)
55 GEN_MLME_EXT_HANDLER(sizeof(struct getphyinfo_parm), NULL) /*30*/
56 GEN_MLME_EXT_HANDLER(sizeof(struct setphy_parm), NULL)
57 GEN_MLME_EXT_HANDLER(sizeof(struct getphy_parm), NULL)
Larry Finger5e93f352014-03-28 21:37:38 -050058 GEN_MLME_EXT_HANDLER(0, NULL)
59 GEN_MLME_EXT_HANDLER(0, NULL)
60 GEN_MLME_EXT_HANDLER(0, NULL)
61 GEN_MLME_EXT_HANDLER(0, NULL)
62 GEN_MLME_EXT_HANDLER(0, NULL)
63 GEN_MLME_EXT_HANDLER(0, NULL)
64 GEN_MLME_EXT_HANDLER(0, NULL)
65 GEN_MLME_EXT_HANDLER(0, NULL) /*40*/
66 GEN_MLME_EXT_HANDLER(0, NULL)
67 GEN_MLME_EXT_HANDLER(0, NULL)
68 GEN_MLME_EXT_HANDLER(0, NULL)
69 GEN_MLME_EXT_HANDLER(0, NULL)
70 GEN_MLME_EXT_HANDLER(sizeof(struct addBaReq_parm), add_ba_hdl23a)
71 GEN_MLME_EXT_HANDLER(sizeof(struct set_ch_parm), set_ch_hdl23a) /* 46 */
72 GEN_MLME_EXT_HANDLER(0, NULL)
73 GEN_MLME_EXT_HANDLER(0, NULL)
74 GEN_MLME_EXT_HANDLER(0, NULL)
75 GEN_MLME_EXT_HANDLER(0, NULL) /*50*/
76 GEN_MLME_EXT_HANDLER(0, NULL)
77 GEN_MLME_EXT_HANDLER(0, NULL)
78 GEN_MLME_EXT_HANDLER(0, NULL)
79 GEN_MLME_EXT_HANDLER(0, NULL)
80 GEN_MLME_EXT_HANDLER(sizeof(struct Tx_Beacon_param), tx_beacon_hdl23a) /*55*/
81
82 GEN_MLME_EXT_HANDLER(0, mlme_evt_hdl23a) /*56*/
83 GEN_MLME_EXT_HANDLER(0, rtw_drvextra_cmd_hdl23a) /*57*/
84
85 GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl23a) /*58*/
86 GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelPlan_param), set_chplan_hdl23a) /*59*/
87 GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param), led_blink_hdl23a) /*60*/
88
89 GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelSwitch_param), set_csa_hdl23a) /*61*/
90 GEN_MLME_EXT_HANDLER(sizeof(struct TDLSoption_param), tdls_hdl23a) /*62*/
91};
92
93struct _cmd_callback rtw_cmd_callback[] = {
94 {GEN_CMD_CODE(_Read_MACREG), NULL}, /*0*/
95 {GEN_CMD_CODE(_Write_MACREG), NULL},
96 {GEN_CMD_CODE(_Read_BBREG), &rtw_getbbrfreg_cmdrsp_callback23a},
97 {GEN_CMD_CODE(_Write_BBREG), NULL},
98 {GEN_CMD_CODE(_Read_RFREG), &rtw_getbbrfreg_cmdrsp_callback23a},
99 {GEN_CMD_CODE(_Write_RFREG), NULL}, /*5*/
100 {GEN_CMD_CODE(_Read_EEPROM), NULL},
101 {GEN_CMD_CODE(_Write_EEPROM), NULL},
102 {GEN_CMD_CODE(_Read_EFUSE), NULL},
103 {GEN_CMD_CODE(_Write_EFUSE), NULL},
104
105 {GEN_CMD_CODE(_Read_CAM), NULL}, /*10*/
106 {GEN_CMD_CODE(_Write_CAM), NULL},
107 {GEN_CMD_CODE(_setBCNITV), NULL},
108 {GEN_CMD_CODE(_setMBIDCFG), NULL},
109 {GEN_CMD_CODE(_JoinBss), &rtw_joinbss_cmd23a_callback}, /*14*/
110 {GEN_CMD_CODE(_DisConnect), &rtw_disassoc_cmd23a_callback}, /*15*/
111 {GEN_CMD_CODE(_CreateBss), &rtw_createbss_cmd23a_callback},
112 {GEN_CMD_CODE(_SetOpMode), NULL},
113 {GEN_CMD_CODE(_SiteSurvey), &rtw_survey_cmd_callback23a}, /*18*/
114 {GEN_CMD_CODE(_SetAuth), NULL},
115
116 {GEN_CMD_CODE(_SetKey), NULL}, /*20*/
117 {GEN_CMD_CODE(_SetStaKey), &rtw_setstaKey_cmdrsp_callback23a},
118 {GEN_CMD_CODE(_SetAssocSta), &rtw_setassocsta_cmdrsp_callback23a},
119 {GEN_CMD_CODE(_DelAssocSta), NULL},
120 {GEN_CMD_CODE(_SetStaPwrState), NULL},
121 {GEN_CMD_CODE(_SetBasicRate), NULL}, /*25*/
122 {GEN_CMD_CODE(_GetBasicRate), NULL},
123 {GEN_CMD_CODE(_SetDataRate), NULL},
124 {GEN_CMD_CODE(_GetDataRate), NULL},
125 {GEN_CMD_CODE(_SetPhyInfo), NULL},
126
127 {GEN_CMD_CODE(_GetPhyInfo), NULL}, /*30*/
128 {GEN_CMD_CODE(_SetPhy), NULL},
129 {GEN_CMD_CODE(_GetPhy), NULL},
130 {GEN_CMD_CODE(_readRssi), NULL},
131 {GEN_CMD_CODE(_readGain), NULL},
132 {GEN_CMD_CODE(_SetAtim), NULL}, /*35*/
133 {GEN_CMD_CODE(_SetPwrMode), NULL},
134 {GEN_CMD_CODE(_JoinbssRpt), NULL},
135 {GEN_CMD_CODE(_SetRaTable), NULL},
136 {GEN_CMD_CODE(_GetRaTable), NULL},
137
138 {GEN_CMD_CODE(_GetCCXReport), NULL}, /*40*/
139 {GEN_CMD_CODE(_GetDTMReport), NULL},
140 {GEN_CMD_CODE(_GetTXRateStatistics), NULL},
141 {GEN_CMD_CODE(_SetUsbSuspend), NULL},
142 {GEN_CMD_CODE(_SetH2cLbk), NULL},
143 {GEN_CMD_CODE(_AddBAReq), NULL}, /*45*/
144 {GEN_CMD_CODE(_SetChannel), NULL}, /*46*/
145 {GEN_CMD_CODE(_SetTxPower), NULL},
146 {GEN_CMD_CODE(_SwitchAntenna), NULL},
147 {GEN_CMD_CODE(_SetCrystalCap), NULL},
148 {GEN_CMD_CODE(_SetSingleCarrierTx), NULL}, /*50*/
149
150 {GEN_CMD_CODE(_SetSingleToneTx), NULL}, /*51*/
151 {GEN_CMD_CODE(_SetCarrierSuppressionTx), NULL},
152 {GEN_CMD_CODE(_SetContinuousTx), NULL},
153 {GEN_CMD_CODE(_SwitchBandwidth), NULL}, /*54*/
154 {GEN_CMD_CODE(_TX_Beacon), NULL},/*55*/
155
156 {GEN_CMD_CODE(_Set_MLME_EVT), NULL},/*56*/
157 {GEN_CMD_CODE(_Set_Drv_Extra), NULL},/*57*/
158 {GEN_CMD_CODE(_Set_H2C_MSG), NULL},/*58*/
159 {GEN_CMD_CODE(_SetChannelPlan), NULL},/*59*/
160 {GEN_CMD_CODE(_LedBlink), NULL},/*60*/
161
162 {GEN_CMD_CODE(_SetChannelSwitch), NULL},/*61*/
163 {GEN_CMD_CODE(_TDLS), NULL},/*62*/
164};
165
166/*
167Caller and the rtw_cmd_thread23a can protect cmd_q by spin_lock.
168No irqsave is necessary.
169*/
170
171int rtw_init_cmd_priv23a(struct cmd_priv *pcmdpriv)
172{
173 int res = _SUCCESS;
174
Larry Finger5e93f352014-03-28 21:37:38 -0500175 pcmdpriv->cmd_issued_cnt = 0;
176 pcmdpriv->cmd_done_cnt = 0;
177 pcmdpriv->rsp_cnt = 0;
178
Jes Sorensen8df06a32014-05-09 15:03:13 +0200179 pcmdpriv->wq = alloc_workqueue("rtl8723au_cmd", 0, 1);
Jes Sorensend97e2d22014-04-26 18:54:57 +0200180 if (!pcmdpriv->wq)
181 res = _FAIL;
182
Larry Finger5e93f352014-03-28 21:37:38 -0500183 return res;
184}
185
186/* forward definition */
187
Jes Sorensen980cf722014-05-09 15:03:14 +0200188static void rtw_irq_work(struct work_struct *work);
Larry Finger5e93f352014-03-28 21:37:38 -0500189
Jes Sorensenab033fdb2014-04-26 18:55:01 +0200190u32 rtw_init_evt_priv23a(struct evt_priv *pevtpriv)
191{
Jes Sorensen980cf722014-05-09 15:03:14 +0200192 pevtpriv->wq = alloc_workqueue("rtl8723au_evt", 0, 1);
193
194 INIT_WORK(&pevtpriv->irq_wk, rtw_irq_work);
Larry Finger5e93f352014-03-28 21:37:38 -0500195
Jes Sorensenab033fdb2014-04-26 18:55:01 +0200196 return _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500197}
198
199void rtw_free_evt_priv23a(struct evt_priv *pevtpriv)
200{
Jes Sorensen980cf722014-05-09 15:03:14 +0200201 cancel_work_sync(&pevtpriv->irq_wk);
Larry Finger5e93f352014-03-28 21:37:38 -0500202}
203
Larry Finger5e93f352014-03-28 21:37:38 -0500204static int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
205{
Larry Finger5e93f352014-03-28 21:37:38 -0500206 /* set to true to allow enqueuing cmd when hw_init_completed is false */
207 u8 bAllow = false;
208
Larry Finger5e93f352014-03-28 21:37:38 -0500209 if (cmd_obj->cmdcode == GEN_CMD_CODE(_SetChannelPlan))
210 bAllow = true;
211
Jes Sorensend97e2d22014-04-26 18:54:57 +0200212 if (pcmdpriv->padapter->hw_init_completed == false && bAllow == false)
Larry Finger5e93f352014-03-28 21:37:38 -0500213 return _FAIL;
214 return _SUCCESS;
215}
216
Jes Sorensend97e2d22014-04-26 18:54:57 +0200217static void rtw_cmd_work(struct work_struct *work);
218
219int rtw_enqueue_cmd23a(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
Larry Finger5e93f352014-03-28 21:37:38 -0500220{
221 int res = _FAIL;
Larry Finger5e93f352014-03-28 21:37:38 -0500222
223 if (!cmd_obj)
224 goto exit;
225
Jes Sorensend97e2d22014-04-26 18:54:57 +0200226 cmd_obj->padapter = pcmdpriv->padapter;
Larry Finger5e93f352014-03-28 21:37:38 -0500227
228 res = rtw_cmd_filter(pcmdpriv, cmd_obj);
229 if (res == _FAIL) {
230 rtw_free_cmd_obj23a(cmd_obj);
231 goto exit;
232 }
233
Jes Sorensend97e2d22014-04-26 18:54:57 +0200234 INIT_WORK(&cmd_obj->work, rtw_cmd_work);
Larry Finger5e93f352014-03-28 21:37:38 -0500235
Jes Sorensend97e2d22014-04-26 18:54:57 +0200236 res = queue_work(pcmdpriv->wq, &cmd_obj->work);
Larry Finger5e93f352014-03-28 21:37:38 -0500237
Jes Sorensend97e2d22014-04-26 18:54:57 +0200238 if (!res) {
Alison Schofield0d07fc12015-10-20 23:06:45 -0700239 netdev_err(pcmdpriv->padapter->pnetdev,
240 "%s: Call to queue_work() failed\n", __func__);
Jes Sorensend97e2d22014-04-26 18:54:57 +0200241 res = _FAIL;
242 } else
243 res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500244exit:
Jes Sorensend97e2d22014-04-26 18:54:57 +0200245
Larry Finger5e93f352014-03-28 21:37:38 -0500246 return res;
247}
248
Larry Finger5e93f352014-03-28 21:37:38 -0500249void rtw_free_cmd_obj23a(struct cmd_obj *pcmd)
250{
251
252 if (pcmd->cmdcode != _JoinBss_CMD_ &&
253 pcmd->cmdcode != _CreateBss_CMD_) {
254 /* free parmbuf in cmd_obj */
255 kfree(pcmd->parmbuf);
256 }
257
258 if (pcmd->rsp) {
259 if (pcmd->rspsz != 0) {
260 /* free rsp in cmd_obj */
261 kfree(pcmd->rsp);
262 }
263 }
264
265 kfree(pcmd);
266}
267
Jes Sorensend97e2d22014-04-26 18:54:57 +0200268static void rtw_cmd_work(struct work_struct *work)
Larry Finger5e93f352014-03-28 21:37:38 -0500269{
Jes Sorensen1ec89112014-05-16 10:04:28 +0200270 int (*cmd_hdl)(struct rtw_adapter *padapter, const u8 *pbuf);
Larry Finger5e93f352014-03-28 21:37:38 -0500271 void (*pcmd_callback)(struct rtw_adapter *dev, struct cmd_obj *pcmd);
Jes Sorensend97e2d22014-04-26 18:54:57 +0200272 struct cmd_priv *pcmdpriv;
273 struct cmd_obj *pcmd = container_of(work, struct cmd_obj, work);
Larry Finger5e93f352014-03-28 21:37:38 -0500274
Jes Sorensend97e2d22014-04-26 18:54:57 +0200275 pcmdpriv = &pcmd->padapter->cmdpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500276
Jes Sorensend97e2d22014-04-26 18:54:57 +0200277 if (rtw_cmd_filter(pcmdpriv, pcmd) == _FAIL) {
278 pcmd->res = H2C_DROPPED;
279 goto post_process;
280 }
Larry Finger5e93f352014-03-28 21:37:38 -0500281
Jes Sorensend97e2d22014-04-26 18:54:57 +0200282 pcmdpriv->cmd_issued_cnt++;
Larry Finger5e93f352014-03-28 21:37:38 -0500283
Jes Sorensend97e2d22014-04-26 18:54:57 +0200284 pcmd->cmdsz = ALIGN(pcmd->cmdsz, 4);
Larry Finger5e93f352014-03-28 21:37:38 -0500285
Jes Sorensend97e2d22014-04-26 18:54:57 +0200286 if (pcmd->cmdcode < (sizeof(wlancmds)/sizeof(struct cmd_hdl))) {
287 cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns;
288
289 if (cmd_hdl)
Jes Sorensenc347dc62014-05-09 15:03:10 +0200290 pcmd->res = cmd_hdl(pcmd->padapter, pcmd->parmbuf);
Jes Sorensend97e2d22014-04-26 18:54:57 +0200291 else
Larry Finger5e93f352014-03-28 21:37:38 -0500292 pcmd->res = H2C_DROPPED;
Jes Sorensend97e2d22014-04-26 18:54:57 +0200293 } else
294 pcmd->res = H2C_PARAMETERS_ERROR;
Larry Finger5e93f352014-03-28 21:37:38 -0500295
296post_process:
Jes Sorensend97e2d22014-04-26 18:54:57 +0200297 /* call callback function for post-processed */
Janani Ravichandran993c0a02016-02-11 18:50:40 -0500298 if (pcmd->cmdcode < ARRAY_SIZE(rtw_cmd_callback)) {
Jes Sorensend97e2d22014-04-26 18:54:57 +0200299 pcmd_callback = rtw_cmd_callback[pcmd->cmdcode].callback;
300 if (!pcmd_callback) {
301 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700302 "mlme_cmd_hdl(): pcmd_callback = 0x%p, cmdcode = 0x%x\n",
303 pcmd_callback, pcmd->cmdcode);
Larry Finger5e93f352014-03-28 21:37:38 -0500304 rtw_free_cmd_obj23a(pcmd);
Jes Sorensend97e2d22014-04-26 18:54:57 +0200305 } else {
Masanari Iida808bcb42014-07-22 23:42:53 +0900306 /* need consider that free cmd_obj in
Jes Sorensend97e2d22014-04-26 18:54:57 +0200307 rtw_cmd_callback */
308 pcmd_callback(pcmd->padapter, pcmd);
Larry Finger5e93f352014-03-28 21:37:38 -0500309 }
Jes Sorensend97e2d22014-04-26 18:54:57 +0200310 } else {
311 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -0700312 "%s: cmdcode = 0x%x callback not defined!\n",
313 __func__, pcmd->cmdcode);
Larry Finger5e93f352014-03-28 21:37:38 -0500314 rtw_free_cmd_obj23a(pcmd);
Jes Sorensend97e2d22014-04-26 18:54:57 +0200315 }
Larry Finger5e93f352014-03-28 21:37:38 -0500316}
317
Jes Sorensend97e2d22014-04-26 18:54:57 +0200318
Jes Sorensen1ec89112014-05-16 10:04:28 +0200319int rtw_sitesurvey_cmd23a(struct rtw_adapter *padapter,
320 struct cfg80211_ssid *ssid, int ssid_num,
321 struct rtw_ieee80211_channel *ch, int ch_num)
Larry Finger5e93f352014-03-28 21:37:38 -0500322{
Jes Sorensen1ec89112014-05-16 10:04:28 +0200323 int res = _FAIL;
Larry Finger5e93f352014-03-28 21:37:38 -0500324 struct cmd_obj *ph2c;
325 struct sitesurvey_parm *psurveyPara;
326 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
327 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
328
Jes Sorensenf2f97032014-05-25 22:43:04 +0200329 if (check_fwstate(pmlmepriv, _FW_LINKED))
Larry Finger5e93f352014-03-28 21:37:38 -0500330 rtw_lps_ctrl_wk_cmd23a(padapter, LPS_CTRL_SCAN, 1);
331
Larry Finger5e93f352014-03-28 21:37:38 -0500332 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
333 if (!ph2c)
334 return _FAIL;
335
336 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
337 if (!psurveyPara) {
338 kfree(ph2c);
339 return _FAIL;
340 }
341
Jes Sorensen528e5c12014-04-26 18:55:51 +0200342 rtw_free_network_queue23a(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500343
344 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700345 "%s: flush network queue\n", __func__);
Larry Finger5e93f352014-03-28 21:37:38 -0500346
347 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara,
348 GEN_CMD_CODE(_SiteSurvey));
349
350 /* psurveyPara->bsslimit = 48; */
351 psurveyPara->scan_mode = pmlmepriv->scan_mode;
352
353 /* prepare ssid list */
354 if (ssid) {
355 int i;
Yeliz Taneroglufbc6d792014-10-09 01:22:10 +0300356
Larry Finger5e93f352014-03-28 21:37:38 -0500357 for (i = 0; i < ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) {
358 if (ssid[i].ssid_len) {
359 memcpy(&psurveyPara->ssid[i], &ssid[i],
360 sizeof(struct cfg80211_ssid));
361 psurveyPara->ssid_num++;
Larry Finger5e93f352014-03-28 21:37:38 -0500362 }
363 }
364 }
365
366 /* prepare channel list */
367 if (ch) {
368 int i;
Yeliz Taneroglufbc6d792014-10-09 01:22:10 +0300369
Larry Finger5e93f352014-03-28 21:37:38 -0500370 for (i = 0; i < ch_num && i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
371 if (ch[i].hw_value &&
372 !(ch[i].flags & IEEE80211_CHAN_DISABLED)) {
373 memcpy(&psurveyPara->ch[i], &ch[i],
374 sizeof(struct rtw_ieee80211_channel));
375 psurveyPara->ch_num++;
Larry Finger5e93f352014-03-28 21:37:38 -0500376 }
377 }
378 }
379
380 set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
381
382 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
383
384 if (res == _SUCCESS) {
385 mod_timer(&pmlmepriv->scan_to_timer, jiffies +
386 msecs_to_jiffies(SCANNING_TIMEOUT));
387
Larry Finger5e93f352014-03-28 21:37:38 -0500388 pmlmepriv->scan_interval = SCAN_INTERVAL;/* 30*2 sec = 60sec */
389 } else
390 _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
391
392 return res;
393}
394
395void rtw_getbbrfreg_cmdrsp_callback23a(struct rtw_adapter *padapter,
396 struct cmd_obj *pcmd)
397{
398 kfree(pcmd->parmbuf);
399 kfree(pcmd);
400}
401
Jes Sorensen1ec89112014-05-16 10:04:28 +0200402int rtw_createbss_cmd23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -0500403{
404 struct cmd_obj *pcmd;
405 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
406 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
407 struct wlan_bssid_ex *pdev_network;
408 u8 res = _SUCCESS;
409
410 pdev_network = &padapter->registrypriv.dev_network;
411
Larry Finger5e93f352014-03-28 21:37:38 -0500412 if (pmlmepriv->assoc_ssid.ssid_len == 0) {
413 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700414 "createbss for Any SSid:%s\n",
415 pmlmepriv->assoc_ssid.ssid);
Larry Finger5e93f352014-03-28 21:37:38 -0500416 } else {
417 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700418 "createbss for SSid:%s\n",
419 pmlmepriv->assoc_ssid.ssid);
Larry Finger5e93f352014-03-28 21:37:38 -0500420 }
421
422 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
423 if (!pcmd) {
424 res = _FAIL;
425 goto exit;
426 }
427
Larry Finger5e93f352014-03-28 21:37:38 -0500428 pcmd->cmdcode = _CreateBss_CMD_;
429 pcmd->parmbuf = (unsigned char *)pdev_network;
Jes Sorensenaab26452014-04-26 18:55:08 +0200430 pcmd->cmdsz = get_wlan_bssid_ex_sz(pdev_network);
Larry Finger5e93f352014-03-28 21:37:38 -0500431 pcmd->rsp = NULL;
432 pcmd->rspsz = 0;
433
434 pdev_network->Length = pcmd->cmdsz;
435
436 res = rtw_enqueue_cmd23a(pcmdpriv, pcmd);
437
438exit:
439
440 return res;
441}
442
Jes Sorensen1ec89112014-05-16 10:04:28 +0200443int rtw_joinbss_cmd23a(struct rtw_adapter *padapter,
444 struct wlan_network *pnetwork)
Larry Finger5e93f352014-03-28 21:37:38 -0500445{
Jes Sorensen1ec89112014-05-16 10:04:28 +0200446 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500447 struct wlan_bssid_ex *psecnetwork;
448 struct cmd_obj *pcmd;
449 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
450 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500451 struct security_priv *psecuritypriv = &padapter->securitypriv;
452 struct registry_priv *pregistrypriv = &padapter->registrypriv;
453 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
Jes Sorensenefc71442014-05-21 09:37:26 +0200454 enum nl80211_iftype ifmode;
Larry Finger5e93f352014-03-28 21:37:38 -0500455 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
456 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
457
Jes Sorensenefc71442014-05-21 09:37:26 +0200458 ifmode = pnetwork->network.ifmode;
Larry Finger5e93f352014-03-28 21:37:38 -0500459
Larry Finger5e93f352014-03-28 21:37:38 -0500460 if (pmlmepriv->assoc_ssid.ssid_len == 0) {
461 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700462 "+Join cmd: Any SSid\n");
Larry Finger5e93f352014-03-28 21:37:38 -0500463 } else {
464 RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_,
Joe Perches90403aa2015-03-24 16:06:44 -0700465 "+Join cmd: SSid =[%s]\n",
466 pmlmepriv->assoc_ssid.ssid);
Larry Finger5e93f352014-03-28 21:37:38 -0500467 }
468
469 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
470 if (!pcmd) {
471 res = _FAIL;
472 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -0700473 "rtw_joinbss_cmd23a: memory allocate for cmd_obj fail!!!\n");
Larry Finger5e93f352014-03-28 21:37:38 -0500474 goto exit;
475 }
Larry Finger5e93f352014-03-28 21:37:38 -0500476
477 /* for hidden ap to set fw_state here */
478 if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE)) {
Jes Sorensenefc71442014-05-21 09:37:26 +0200479 switch (ifmode) {
480 case NL80211_IFTYPE_ADHOC:
Larry Finger5e93f352014-03-28 21:37:38 -0500481 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
482 break;
Jes Sorensenefc71442014-05-21 09:37:26 +0200483 case NL80211_IFTYPE_P2P_CLIENT:
484 case NL80211_IFTYPE_STATION:
Larry Finger5e93f352014-03-28 21:37:38 -0500485 set_fwstate(pmlmepriv, WIFI_STATION_STATE);
486 break;
Jes Sorensenefc71442014-05-21 09:37:26 +0200487 default:
Larry Finger5e93f352014-03-28 21:37:38 -0500488 break;
489 }
490 }
491
Jes Sorensenea4190b2014-04-26 18:55:07 +0200492 psecnetwork = &psecuritypriv->sec_bss;
Larry Finger5e93f352014-03-28 21:37:38 -0500493 if (!psecnetwork) {
Fabian Frederick352f1452014-07-01 10:11:23 +0200494 kfree(pcmd);
Larry Finger5e93f352014-03-28 21:37:38 -0500495 res = _FAIL;
496
497 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -0700498 "rtw_joinbss_cmd23a :psecnetwork == NULL!!!\n");
Larry Finger5e93f352014-03-28 21:37:38 -0500499
500 goto exit;
501 }
502
Jes Sorensenea4190b2014-04-26 18:55:07 +0200503 memset(psecnetwork, 0, sizeof(struct wlan_bssid_ex));
Larry Finger5e93f352014-03-28 21:37:38 -0500504
505 memcpy(psecnetwork, &pnetwork->network,
506 get_wlan_bssid_ex_sz(&pnetwork->network));
507
Larry Finger5e93f352014-03-28 21:37:38 -0500508 psecnetwork->IELength = 0;
509 /* Added by Albert 2009/02/18 */
510 /* If the the driver wants to use the bssid to create the
511 * connection. If not, we have to copy the connecting AP's
512 * MAC address to it so that the driver just has the bssid
513 * information for PMKIDList searching. */
514
515 if (pmlmepriv->assoc_by_bssid == false)
516 ether_addr_copy(&pmlmepriv->assoc_bssid[0],
517 &pnetwork->network.MacAddress[0]);
518
519 psecnetwork->IELength =
520 rtw_restruct_sec_ie23a(padapter, &pnetwork->network.IEs[0],
521 &psecnetwork->IEs[0],
522 pnetwork->network.IELength);
523
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200524 pmlmepriv->qos_option = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500525
526 if (pregistrypriv->wmm_enable) {
527 u32 tmp_len;
528
529 tmp_len = rtw_restruct_wmm_ie23a(padapter,
530 &pnetwork->network.IEs[0],
531 &psecnetwork->IEs[0],
532 pnetwork->network.IELength,
533 psecnetwork->IELength);
534
535 if (psecnetwork->IELength != tmp_len) {
536 psecnetwork->IELength = tmp_len;
537 /* There is WMM IE in this corresp. beacon */
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200538 pmlmepriv->qos_option = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500539 } else {
540 /* There is no WMM IE in this corresp. beacon */
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200541 pmlmepriv->qos_option = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500542 }
543 }
544
545 phtpriv->ht_option = false;
546 if (pregistrypriv->ht_enable) {
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200547 u32 algo = padapter->securitypriv.dot11PrivacyAlgrthm;
Larry Finger5e93f352014-03-28 21:37:38 -0500548 /* Added by Albert 2010/06/23 */
549 /* For the WEP mode, we will use the bg mode to do
550 the connection to avoid some IOT issue. */
551 /* Especially for Realtek 8192u SoftAP. */
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200552 if (algo != WLAN_CIPHER_SUITE_WEP40 &&
553 algo != WLAN_CIPHER_SUITE_WEP104 &&
554 algo != WLAN_CIPHER_SUITE_TKIP) {
Larry Finger5e93f352014-03-28 21:37:38 -0500555 /* rtw_restructure_ht_ie23a */
556 rtw_restructure_ht_ie23a(padapter,
557 &pnetwork->network.IEs[0],
558 &psecnetwork->IEs[0],
559 pnetwork->network.IELength,
560 &psecnetwork->IELength);
561 }
562 }
563
564 pmlmeinfo->assoc_AP_vendor =
565 check_assoc_AP23a(pnetwork->network.IEs,
566 pnetwork->network.IELength);
567
568 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_TENDA)
569 padapter->pwrctrlpriv.smart_ps = 0;
570 else
571 padapter->pwrctrlpriv.smart_ps =
572 padapter->registrypriv.smart_ps;
573
574 DBG_8723A("%s: smart_ps =%d\n", __func__,
575 padapter->pwrctrlpriv.smart_ps);
576
577 /* get cmdsz before endian conversion */
578 pcmd->cmdsz = get_wlan_bssid_ex_sz(psecnetwork);
579
Larry Finger5e93f352014-03-28 21:37:38 -0500580 pcmd->cmdcode = _JoinBss_CMD_;/* GEN_CMD_CODE(_JoinBss) */
581 pcmd->parmbuf = (unsigned char *)psecnetwork;
582 pcmd->rsp = NULL;
583 pcmd->rspsz = 0;
584
585 res = rtw_enqueue_cmd23a(pcmdpriv, pcmd);
586exit:
587
588 return res;
589}
590
anuvazhayila58af1e2014-10-30 00:03:48 +0530591int rtw_disassoc_cmd23a(struct rtw_adapter *padapter, u32 deauth_timeout_ms,
Jes Sorensen1ec89112014-05-16 10:04:28 +0200592 bool enqueue)
Larry Finger5e93f352014-03-28 21:37:38 -0500593{
594 struct cmd_obj *cmdobj = NULL;
595 struct disconnect_parm *param = NULL;
596 struct cmd_priv *cmdpriv = &padapter->cmdpriv;
Jes Sorensen1ec89112014-05-16 10:04:28 +0200597 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500598
599 RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_,
Joe Perches90403aa2015-03-24 16:06:44 -0700600 "+rtw_disassoc_cmd23a\n");
Larry Finger5e93f352014-03-28 21:37:38 -0500601
602 /* prepare cmd parameter */
603 param = kzalloc(sizeof(*param), GFP_ATOMIC);
604 if (param == NULL) {
605 res = _FAIL;
606 goto exit;
607 }
608 param->deauth_timeout_ms = deauth_timeout_ms;
609
610 if (enqueue) {
611 /* need enqueue, prepare cmd_obj and enqueue */
612 cmdobj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
613 if (!cmdobj) {
614 res = _FAIL;
615 kfree(param);
616 goto exit;
617 }
618 init_h2fwcmd_w_parm_no_rsp(cmdobj, param, _DisConnect_CMD_);
619 res = rtw_enqueue_cmd23a(cmdpriv, cmdobj);
620 } else {
621 /* no need to enqueue, do the cmd hdl directly and
622 free cmd parameter */
Alison Schofieldc12e8db2015-10-20 23:08:27 -0700623 if (disconnect_hdl23a(padapter, (u8 *)param) != H2C_SUCCESS)
Larry Finger5e93f352014-03-28 21:37:38 -0500624 res = _FAIL;
625 kfree(param);
626 }
627
628exit:
629 return res;
630}
631
Jes Sorensen1ec89112014-05-16 10:04:28 +0200632int rtw_setopmode_cmd23a(struct rtw_adapter *padapter,
Jes Sorensenefc71442014-05-21 09:37:26 +0200633 enum nl80211_iftype ifmode)
Larry Finger5e93f352014-03-28 21:37:38 -0500634{
635 struct cmd_obj *ph2c;
636 struct setopmode_parm *psetop;
637 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
Jes Sorensen1ec89112014-05-16 10:04:28 +0200638 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500639
640 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
641 if (!ph2c) {
642 res = false;
643 goto exit;
644 }
645 psetop = kzalloc(sizeof(struct setopmode_parm), GFP_KERNEL);
646
647 if (!psetop) {
648 kfree(ph2c);
649 res = false;
650 goto exit;
651 }
652
653 init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
Jes Sorensenefc71442014-05-21 09:37:26 +0200654 psetop->mode = ifmode;
Larry Finger5e93f352014-03-28 21:37:38 -0500655
656 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
657exit:
658 return res;
659}
660
Jes Sorensen1ec89112014-05-16 10:04:28 +0200661int rtw_setstakey_cmd23a(struct rtw_adapter *padapter, u8 *psta, u8 unicast_key)
Larry Finger5e93f352014-03-28 21:37:38 -0500662{
663 struct cmd_obj *ph2c;
664 struct set_stakey_parm *psetstakey_para;
665 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
666 struct set_stakey_rsp *psetstakey_rsp = NULL;
667 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
668 struct security_priv *psecuritypriv = &padapter->securitypriv;
Greg Donald7e6646d2014-09-06 19:42:03 -0500669 struct sta_info *sta = (struct sta_info *)psta;
Jes Sorensen1ec89112014-05-16 10:04:28 +0200670 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500671
672 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
673 if (!ph2c) {
674 res = _FAIL;
675 goto exit;
676 }
677
678 psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL);
679 if (!psetstakey_para) {
680 kfree(ph2c);
681 res = _FAIL;
682 goto exit;
683 }
684
685 psetstakey_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_KERNEL);
686 if (!psetstakey_rsp) {
687 kfree(ph2c);
688 kfree(psetstakey_para);
689 res = _FAIL;
690 goto exit;
691 }
692
693 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
694 ph2c->rsp = (u8 *) psetstakey_rsp;
695 ph2c->rspsz = sizeof(struct set_stakey_rsp);
696
697 ether_addr_copy(psetstakey_para->addr, sta->hwaddr);
698
699 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
700 psetstakey_para->algorithm =
701 (unsigned char)psecuritypriv->dot11PrivacyAlgrthm;
702 } else {
703 GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm,
704 false);
705 }
706
707 if (unicast_key == true) {
708 memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16);
Greg Donalda82b4b02014-09-08 20:50:23 -0500709 } else {
Larry Finger5e93f352014-03-28 21:37:38 -0500710 int idx = psecuritypriv->dot118021XGrpKeyid;
Yeliz Taneroglufbc6d792014-10-09 01:22:10 +0300711
Larry Finger5e93f352014-03-28 21:37:38 -0500712 memcpy(&psetstakey_para->key,
713 &psecuritypriv->dot118021XGrpKey[idx].skey, 16);
Greg Donalda82b4b02014-09-08 20:50:23 -0500714 }
Larry Finger5e93f352014-03-28 21:37:38 -0500715
Masanari Iida808bcb42014-07-22 23:42:53 +0900716 /* jeff: set this because at least sw key is ready */
Jes Sorensen9216c512014-05-21 09:37:29 +0200717 padapter->securitypriv.busetkipkey = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500718
719 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
720
721exit:
722
723 return res;
724}
725
Jes Sorensen1ec89112014-05-16 10:04:28 +0200726int rtw_clearstakey_cmd23a(struct rtw_adapter *padapter, u8 *psta, u8 entry,
727 u8 enqueue)
Larry Finger5e93f352014-03-28 21:37:38 -0500728{
729 struct cmd_obj *ph2c;
730 struct set_stakey_parm *psetstakey_para;
731 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
732 struct set_stakey_rsp *psetstakey_rsp = NULL;
733 struct sta_info *sta = (struct sta_info *)psta;
Jes Sorensen1ec89112014-05-16 10:04:28 +0200734 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500735
736 if (!enqueue) {
737 clear_cam_entry23a(padapter, entry);
738 } else {
739 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
740 if (!ph2c) {
741 res = _FAIL;
742 goto exit;
743 }
744
745 psetstakey_para = kzalloc(sizeof(struct set_stakey_parm),
746 GFP_KERNEL);
747 if (!psetstakey_para) {
748 kfree(ph2c);
749 res = _FAIL;
750 goto exit;
751 }
752
753 psetstakey_rsp = kzalloc(sizeof(struct set_stakey_rsp),
754 GFP_KERNEL);
755 if (!psetstakey_rsp) {
756 kfree(ph2c);
757 kfree(psetstakey_para);
758 res = _FAIL;
759 goto exit;
760 }
761
762 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para,
763 _SetStaKey_CMD_);
764 ph2c->rsp = (u8 *) psetstakey_rsp;
765 ph2c->rspsz = sizeof(struct set_stakey_rsp);
766
767 ether_addr_copy(psetstakey_para->addr, sta->hwaddr);
768
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200769 psetstakey_para->algorithm = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500770
771 psetstakey_para->id = entry;
772
773 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
774 }
775exit:
776 return res;
777}
778
anuvazhayila58af1e2014-10-30 00:03:48 +0530779int rtw_addbareq_cmd23a(struct rtw_adapter *padapter, u8 tid, u8 *addr)
Larry Finger5e93f352014-03-28 21:37:38 -0500780{
781 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
782 struct cmd_obj *ph2c;
783 struct addBaReq_parm *paddbareq_parm;
Jes Sorensen1ec89112014-05-16 10:04:28 +0200784 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500785
Jes Sorensend7f2c232014-05-09 15:04:17 +0200786 if (tid >= MAXTID) {
787 res = _FAIL;
788 goto exit;
789 }
790
Larry Finger5e93f352014-03-28 21:37:38 -0500791 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
792 if (!ph2c) {
793 res = _FAIL;
794 goto exit;
795 }
796
797 paddbareq_parm = kzalloc(sizeof(struct addBaReq_parm), GFP_ATOMIC);
798 if (!paddbareq_parm) {
799 kfree(ph2c);
800 res = _FAIL;
801 goto exit;
802 }
803
804 paddbareq_parm->tid = tid;
805 ether_addr_copy(paddbareq_parm->addr, addr);
806
807 init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm,
808 GEN_CMD_CODE(_AddBAReq));
809
810 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
811exit:
812 return res;
813}
814
anuvazhayila58af1e2014-10-30 00:03:48 +0530815int rtw_dynamic_chk_wk_cmd23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -0500816{
817 struct cmd_obj *ph2c;
818 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
819 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
Jes Sorensen1ec89112014-05-16 10:04:28 +0200820 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500821
822 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
823 if (!ph2c) {
824 res = _FAIL;
825 goto exit;
826 }
827
828 pdrvextra_cmd_parm = kzalloc(sizeof(*pdrvextra_cmd_parm), GFP_ATOMIC);
829 if (!pdrvextra_cmd_parm) {
830 kfree(ph2c);
831 res = _FAIL;
832 goto exit;
833 }
834
835 pdrvextra_cmd_parm->ec_id = DYNAMIC_CHK_WK_CID;
836 pdrvextra_cmd_parm->type_size = 0;
837 pdrvextra_cmd_parm->pbuf = (u8 *)padapter;
838
839 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm,
840 GEN_CMD_CODE(_Set_Drv_Extra));
841
842 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
843exit:
844
845 return res;
846}
847
Larry Finger5e93f352014-03-28 21:37:38 -0500848static void traffic_status_watchdog(struct rtw_adapter *padapter)
849{
850 u8 bEnterPS;
851 u8 bBusyTraffic = false, bTxBusyTraffic = false, bRxBusyTraffic = false;
852 u8 bHigherBusyTraffic = false, bHigherBusyRxTraffic = false;
853 u8 bHigherBusyTxTraffic = false;
854 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Larry Fingerc17416e2014-03-28 21:37:42 -0500855 int BusyThreshold = 100;
Sanjeev Sharma6b1b4ca2014-11-11 15:28:14 +0530856 struct rt_link_detect *ldi = &pmlmepriv->LinkDetectInfo;
857
Larry Finger5e93f352014-03-28 21:37:38 -0500858 /* */
859 /* Determine if our traffic is busy now */
860 /* */
861 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
Jes Sorensen09d88792014-05-25 22:43:32 +0200862 if (rtl8723a_BT_coexist(padapter))
863 BusyThreshold = 50;
Sanjeev Sharma6b1b4ca2014-11-11 15:28:14 +0530864 else if (ldi->bBusyTraffic)
Jes Sorensen09d88792014-05-25 22:43:32 +0200865 BusyThreshold = 75;
Larry Finger5e93f352014-03-28 21:37:38 -0500866 /* if we raise bBusyTraffic in last watchdog, using
867 lower threshold. */
Sanjeev Sharma6b1b4ca2014-11-11 15:28:14 +0530868 if (ldi->NumRxOkInPeriod > BusyThreshold ||
869 ldi->NumTxOkInPeriod > BusyThreshold) {
Larry Finger5e93f352014-03-28 21:37:38 -0500870 bBusyTraffic = true;
871
Sanjeev Sharma6b1b4ca2014-11-11 15:28:14 +0530872 if (ldi->NumRxOkInPeriod > ldi->NumTxOkInPeriod)
Larry Finger5e93f352014-03-28 21:37:38 -0500873 bRxBusyTraffic = true;
874 else
875 bTxBusyTraffic = true;
876 }
877
878 /* Higher Tx/Rx data. */
Sanjeev Sharma6b1b4ca2014-11-11 15:28:14 +0530879 if (ldi->NumRxOkInPeriod > 4000 ||
880 ldi->NumTxOkInPeriod > 4000) {
Larry Finger5e93f352014-03-28 21:37:38 -0500881 bHigherBusyTraffic = true;
882
Sanjeev Sharma6b1b4ca2014-11-11 15:28:14 +0530883 if (ldi->NumRxOkInPeriod > ldi->NumTxOkInPeriod)
Larry Finger5e93f352014-03-28 21:37:38 -0500884 bHigherBusyRxTraffic = true;
885 else
886 bHigherBusyTxTraffic = true;
887 }
888
Jes Sorensenef95e272014-05-25 22:43:26 +0200889 if (!rtl8723a_BT_coexist(padapter) ||
890 !rtl8723a_BT_using_antenna_1(padapter)) {
Larry Finger5e93f352014-03-28 21:37:38 -0500891 /* check traffic for powersaving. */
Sanjeev Sharma6b1b4ca2014-11-11 15:28:14 +0530892 if (((ldi->NumRxUnicastOkInPeriod +
893 ldi->NumTxOkInPeriod) > 8) ||
894 ldi->NumRxUnicastOkInPeriod > 2)
Jes Sorensenef95e272014-05-25 22:43:26 +0200895 bEnterPS = false;
896 else
897 bEnterPS = true;
Larry Finger5e93f352014-03-28 21:37:38 -0500898
Jes Sorensenef95e272014-05-25 22:43:26 +0200899 /* LeisurePS only work in infra mode. */
900 if (bEnterPS)
901 LPS_Enter23a(padapter);
902 else
903 LPS_Leave23a(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500904 }
905 } else
906 LPS_Leave23a(padapter);
907
Sanjeev Sharma6b1b4ca2014-11-11 15:28:14 +0530908 ldi->NumRxOkInPeriod = 0;
909 ldi->NumTxOkInPeriod = 0;
910 ldi->NumRxUnicastOkInPeriod = 0;
911 ldi->bBusyTraffic = bBusyTraffic;
912 ldi->bTxBusyTraffic = bTxBusyTraffic;
913 ldi->bRxBusyTraffic = bRxBusyTraffic;
914 ldi->bHigherBusyTraffic = bHigherBusyTraffic;
915 ldi->bHigherBusyRxTraffic = bHigherBusyRxTraffic;
916 ldi->bHigherBusyTxTraffic = bHigherBusyTxTraffic;
Larry Finger5e93f352014-03-28 21:37:38 -0500917}
918
Larry Fingerc0b99be2014-04-26 18:55:17 +0200919static void dynamic_chk_wk_hdl(struct rtw_adapter *padapter, u8 *pbuf, int sz)
Larry Finger5e93f352014-03-28 21:37:38 -0500920{
921 struct mlme_priv *pmlmepriv;
922
923 padapter = (struct rtw_adapter *)pbuf;
924 pmlmepriv = &padapter->mlmepriv;
925
926#ifdef CONFIG_8723AU_AP_MODE
Jes Sorensenf2f97032014-05-25 22:43:04 +0200927 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
Larry Finger5e93f352014-03-28 21:37:38 -0500928 expire_timeout_chk23a(padapter);
929#endif
930
Jes Sorensenb7c19c22014-05-16 10:04:00 +0200931 rtl8723a_sreset_xmit_status_check(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500932
933 linked_status_chk23a(padapter);
934 traffic_status_watchdog(padapter);
935
Jes Sorensen8289d352014-05-16 10:03:59 +0200936 rtl8723a_HalDmWatchDog(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500937
Larry Finger5e93f352014-03-28 21:37:38 -0500938 /* */
939 /* BT-Coexist */
940 /* */
Jes Sorensenfebf3082014-05-25 22:43:27 +0200941 rtl8723a_BT_do_coexist(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500942}
943
Larry Fingerc0b99be2014-04-26 18:55:17 +0200944static void lps_ctrl_wk_hdl(struct rtw_adapter *padapter, u8 lps_ctrl_type)
Larry Finger5e93f352014-03-28 21:37:38 -0500945{
946 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
947 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
948 u8 mstatus;
949
Jes Sorensenf2f97032014-05-25 22:43:04 +0200950 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
951 check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))
Larry Finger5e93f352014-03-28 21:37:38 -0500952 return;
953
Tina Ruchandanif2372162014-10-23 20:16:51 -0700954 switch (lps_ctrl_type) {
Tina Ruchandani3e3f8782014-10-23 20:17:48 -0700955 case LPS_CTRL_SCAN:
956 rtl8723a_BT_wifiscan_notify(padapter, true);
957 if (!rtl8723a_BT_using_antenna_1(padapter)) {
958 if (check_fwstate(pmlmepriv, _FW_LINKED))
959 LPS_Leave23a(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500960 }
Tina Ruchandani3e3f8782014-10-23 20:17:48 -0700961 break;
962 case LPS_CTRL_JOINBSS:
963 LPS_Leave23a(padapter);
964 break;
965 case LPS_CTRL_CONNECT:
966 mstatus = 1;/* connect */
967 /* Reset LPS Setting */
968 padapter->pwrctrlpriv.LpsIdleCount = 0;
969 rtl8723a_set_FwJoinBssReport_cmd(padapter, 1);
970 rtl8723a_BT_mediastatus_notify(padapter, mstatus);
971 break;
972 case LPS_CTRL_DISCONNECT:
973 mstatus = 0;/* disconnect */
974 rtl8723a_BT_mediastatus_notify(padapter, mstatus);
975 if (!rtl8723a_BT_using_antenna_1(padapter))
Larry Finger5e93f352014-03-28 21:37:38 -0500976 LPS_Leave23a(padapter);
Tina Ruchandani3e3f8782014-10-23 20:17:48 -0700977 rtl8723a_set_FwJoinBssReport_cmd(padapter, 0);
978 break;
979 case LPS_CTRL_SPECIAL_PACKET:
980 pwrpriv->DelayLPSLastTimeStamp = jiffies;
981 rtl8723a_BT_specialpacket_notify(padapter);
982 if (!rtl8723a_BT_using_antenna_1(padapter))
983 LPS_Leave23a(padapter);
984 break;
985 case LPS_CTRL_LEAVE:
986 rtl8723a_BT_lps_leave(padapter);
987 if (!rtl8723a_BT_using_antenna_1(padapter))
988 LPS_Leave23a(padapter);
989 break;
Larry Finger5e93f352014-03-28 21:37:38 -0500990
Tina Ruchandani3e3f8782014-10-23 20:17:48 -0700991 default:
992 break;
Larry Finger5e93f352014-03-28 21:37:38 -0500993 }
994}
995
Jes Sorensen1ec89112014-05-16 10:04:28 +0200996int rtw_lps_ctrl_wk_cmd23a(struct rtw_adapter *padapter,
997 u8 lps_ctrl_type, u8 enqueue)
Larry Finger5e93f352014-03-28 21:37:38 -0500998{
999 struct cmd_obj *ph2c;
1000 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1001 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
Jes Sorensen1ec89112014-05-16 10:04:28 +02001002 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -05001003
1004 if (enqueue) {
1005 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1006 if (!ph2c) {
1007 res = _FAIL;
1008 goto exit;
1009 }
1010
1011 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm),
1012 GFP_ATOMIC);
1013 if (!pdrvextra_cmd_parm) {
1014 kfree(ph2c);
1015 res = _FAIL;
1016 goto exit;
1017 }
1018
1019 pdrvextra_cmd_parm->ec_id = LPS_CTRL_WK_CID;
1020 pdrvextra_cmd_parm->type_size = lps_ctrl_type;
1021 pdrvextra_cmd_parm->pbuf = NULL;
1022
1023 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm,
1024 GEN_CMD_CODE(_Set_Drv_Extra));
1025
1026 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
1027 } else
1028 lps_ctrl_wk_hdl(padapter, lps_ctrl_type);
1029exit:
1030
1031 return res;
1032}
1033
anuvazhayila58af1e2014-10-30 00:03:48 +05301034int rtw_ps_cmd23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -05001035{
1036 struct cmd_obj *ppscmd;
1037 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1038 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
Jes Sorensen1ec89112014-05-16 10:04:28 +02001039 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -05001040
1041 ppscmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1042 if (!ppscmd) {
1043 res = _FAIL;
1044 goto exit;
1045 }
1046
1047 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm),
1048 GFP_ATOMIC);
1049 if (!pdrvextra_cmd_parm) {
1050 kfree(ppscmd);
1051 res = _FAIL;
1052 goto exit;
1053 }
1054
1055 pdrvextra_cmd_parm->ec_id = POWER_SAVING_CTRL_WK_CID;
1056 pdrvextra_cmd_parm->pbuf = NULL;
1057 init_h2fwcmd_w_parm_no_rsp(ppscmd, pdrvextra_cmd_parm,
1058 GEN_CMD_CODE(_Set_Drv_Extra));
1059
1060 res = rtw_enqueue_cmd23a(pcmdpriv, ppscmd);
1061exit:
1062
1063 return res;
1064}
1065
1066#ifdef CONFIG_8723AU_AP_MODE
1067
1068static void rtw_chk_hi_queue_hdl(struct rtw_adapter *padapter)
1069{
1070 int cnt = 0;
1071 struct sta_info *psta_bmc;
1072 struct sta_priv *pstapriv = &padapter->stapriv;
1073
1074 psta_bmc = rtw_get_bcmc_stainfo23a(padapter);
1075 if (!psta_bmc)
1076 return;
1077
1078 if (psta_bmc->sleepq_len == 0) {
Jes Sorensen8d3fd612014-04-09 23:20:55 +02001079 bool val;
Larry Finger5e93f352014-03-28 21:37:38 -05001080
Jes Sorensen8d3fd612014-04-09 23:20:55 +02001081 val = rtl8723a_chk_hi_queue_empty(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001082
Roberta Dobrescu08551cb2014-10-26 23:30:05 +02001083 while (!val) {
Larry Finger5e93f352014-03-28 21:37:38 -05001084 msleep(100);
1085
1086 cnt++;
1087
Sanjeev Sharmaaf13ccf2014-11-11 13:24:43 +05301088 if (cnt > 10)
Larry Finger5e93f352014-03-28 21:37:38 -05001089 break;
1090
Jes Sorensen8d3fd612014-04-09 23:20:55 +02001091 val = rtl8723a_chk_hi_queue_empty(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001092 }
1093
1094 if (cnt <= 10) {
1095 pstapriv->tim_bitmap &= ~BIT(0);
1096 pstapriv->sta_dz_bitmap &= ~BIT(0);
1097
Jes Sorensen3021bc42014-04-15 19:43:33 +02001098 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
Larry Finger5e93f352014-03-28 21:37:38 -05001099 } else /* re check again */
1100 rtw_chk_hi_queue_cmd23a(padapter);
1101 }
1102}
1103
anuvazhayila58af1e2014-10-30 00:03:48 +05301104int rtw_chk_hi_queue_cmd23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -05001105{
1106 struct cmd_obj *ph2c;
1107 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1108 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
Jes Sorensen1ec89112014-05-16 10:04:28 +02001109 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -05001110
1111 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1112 if (!ph2c) {
1113 res = _FAIL;
1114 goto exit;
1115 }
1116
1117 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm),
1118 GFP_ATOMIC);
1119 if (!pdrvextra_cmd_parm) {
1120 kfree(ph2c);
1121 res = _FAIL;
1122 goto exit;
1123 }
1124
1125 pdrvextra_cmd_parm->ec_id = CHECK_HIQ_WK_CID;
1126 pdrvextra_cmd_parm->type_size = 0;
1127 pdrvextra_cmd_parm->pbuf = NULL;
1128
1129 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm,
1130 GEN_CMD_CODE(_Set_Drv_Extra));
1131
1132 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
1133exit:
1134
1135 return res;
1136}
1137#endif
1138
Jes Sorensen1ec89112014-05-16 10:04:28 +02001139int rtw_c2h_wk_cmd23a(struct rtw_adapter *padapter, u8 *c2h_evt)
Larry Finger5e93f352014-03-28 21:37:38 -05001140{
1141 struct cmd_obj *ph2c;
1142 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1143 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
Jes Sorensen1ec89112014-05-16 10:04:28 +02001144 int res = _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -05001145
1146 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1147 if (!ph2c) {
1148 res = _FAIL;
1149 goto exit;
1150 }
1151
1152 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm),
1153 GFP_ATOMIC);
1154 if (!pdrvextra_cmd_parm) {
1155 kfree(ph2c);
1156 res = _FAIL;
1157 goto exit;
1158 }
1159
1160 pdrvextra_cmd_parm->ec_id = C2H_WK_CID;
1161 pdrvextra_cmd_parm->type_size = c2h_evt?16:0;
1162 pdrvextra_cmd_parm->pbuf = c2h_evt;
1163
1164 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm,
1165 GEN_CMD_CODE(_Set_Drv_Extra));
1166
1167 res = rtw_enqueue_cmd23a(pcmdpriv, ph2c);
1168
1169exit:
1170
1171 return res;
1172}
1173
Jes Sorensen849befa2014-05-09 15:04:10 +02001174static int c2h_evt_hdl(struct rtw_adapter *adapter, struct c2h_evt_hdr *c2h_evt)
Larry Finger5e93f352014-03-28 21:37:38 -05001175{
Jes Sorensenab281e32014-05-09 15:04:09 +02001176 int ret = _FAIL;
Larry Finger5e93f352014-03-28 21:37:38 -05001177 u8 buf[16];
1178
1179 if (!c2h_evt) {
1180 /* No c2h event in cmd_obj, read c2h event before handling*/
1181 if (c2h_evt_read23a(adapter, buf) == _SUCCESS) {
1182 c2h_evt = (struct c2h_evt_hdr *)buf;
1183
Jes Sorensen00cf86c2014-05-09 15:04:12 +02001184 ret = c2h_handler_8723a(adapter, c2h_evt);
Larry Finger5e93f352014-03-28 21:37:38 -05001185 }
Jes Sorensen849befa2014-05-09 15:04:10 +02001186 } else
Jes Sorensen00cf86c2014-05-09 15:04:12 +02001187 ret = c2h_handler_8723a(adapter, c2h_evt);
Jes Sorensen849befa2014-05-09 15:04:10 +02001188
Larry Finger5e93f352014-03-28 21:37:38 -05001189 return ret;
1190}
1191
Jes Sorensen980cf722014-05-09 15:03:14 +02001192static void rtw_irq_work(struct work_struct *work)
Larry Finger5e93f352014-03-28 21:37:38 -05001193{
1194 struct evt_priv *evtpriv;
1195 struct rtw_adapter *adapter;
Jes Sorensen980cf722014-05-09 15:03:14 +02001196
1197 evtpriv = container_of(work, struct evt_priv, irq_wk);
1198 adapter = container_of(evtpriv, struct rtw_adapter, evtpriv);
1199
1200 c2h_evt_clear23a(adapter);
1201}
1202
1203void rtw_evt_work(struct work_struct *work)
1204{
1205 struct evt_work *ework;
1206 struct rtw_adapter *adapter;
Larry Finger5e93f352014-03-28 21:37:38 -05001207
Jes Sorensen980cf722014-05-09 15:03:14 +02001208 ework = container_of(work, struct evt_work, work);
1209 adapter = ework->adapter;
1210
Jes Sorensen980cf722014-05-09 15:03:14 +02001211 c2h_evt_clear23a(adapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001212
Jes Sorensen980cf722014-05-09 15:03:14 +02001213 if (!c2h_evt_exist(&ework->u.c2h_evt)) {
1214 kfree(ework);
1215 return;
Larry Finger5e93f352014-03-28 21:37:38 -05001216 }
1217
Jes Sorensen227ca8c2014-05-09 15:04:11 +02001218 if (c2h_id_filter_ccx_8723a(ework->u.c2h_evt.id) == true) {
Jes Sorensen980cf722014-05-09 15:03:14 +02001219 /* Handle CCX report here */
Jes Sorensen00cf86c2014-05-09 15:04:12 +02001220 c2h_handler_8723a(adapter, &ework->u.c2h_evt);
Jes Sorensen980cf722014-05-09 15:03:14 +02001221 kfree(ework);
1222 } else {
1223 /*
1224 * Enqueue into cmd_thread for others.
1225 * ework will be turned into a c2h_evt and freed once it
1226 * has been consumed.
1227 */
1228 rtw_c2h_wk_cmd23a(adapter, (u8 *)&ework->u.c2h_evt);
1229 }
Larry Finger5e93f352014-03-28 21:37:38 -05001230}
1231
Jes Sorensen1ec89112014-05-16 10:04:28 +02001232int rtw_drvextra_cmd_hdl23a(struct rtw_adapter *padapter, const u8 *pbuf)
Larry Finger5e93f352014-03-28 21:37:38 -05001233{
Jes Sorensen0348dc742014-04-26 18:55:06 +02001234 const struct drvextra_cmd_parm *pdrvextra_cmd;
Larry Finger5e93f352014-03-28 21:37:38 -05001235
1236 if (!pbuf)
1237 return H2C_PARAMETERS_ERROR;
1238
1239 pdrvextra_cmd = (struct drvextra_cmd_parm *)pbuf;
1240
Tina Ruchandanif2372162014-10-23 20:16:51 -07001241 switch (pdrvextra_cmd->ec_id) {
Larry Finger5e93f352014-03-28 21:37:38 -05001242 case DYNAMIC_CHK_WK_CID:
1243 dynamic_chk_wk_hdl(padapter, pdrvextra_cmd->pbuf,
1244 pdrvextra_cmd->type_size);
1245 break;
1246 case POWER_SAVING_CTRL_WK_CID:
Jes Sorensen462eb492014-07-01 10:11:15 +02001247 rtw_ps_processor23a(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001248 break;
1249 case LPS_CTRL_WK_CID:
1250 lps_ctrl_wk_hdl(padapter, (u8)pdrvextra_cmd->type_size);
1251 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001252#ifdef CONFIG_8723AU_AP_MODE
1253 case CHECK_HIQ_WK_CID:
1254 rtw_chk_hi_queue_hdl(padapter);
1255 break;
1256#endif /* CONFIG_8723AU_AP_MODE */
1257 case C2H_WK_CID:
1258 c2h_evt_hdl(padapter,
Jes Sorensen849befa2014-05-09 15:04:10 +02001259 (struct c2h_evt_hdr *)pdrvextra_cmd->pbuf);
Larry Finger5e93f352014-03-28 21:37:38 -05001260 break;
1261
1262 default:
1263 break;
1264 }
1265
1266 if (pdrvextra_cmd->pbuf && (pdrvextra_cmd->type_size > 0)) {
1267 kfree(pdrvextra_cmd->pbuf);
Jes Sorensen0348dc742014-04-26 18:55:06 +02001268 /*
1269 * No need to set pdrvextra_cmd->pbuf = NULL as we were
1270 * operating on a copy of the original pcmd->parmbuf
1271 * created in rtw_cmd_work().
1272 */
Larry Finger5e93f352014-03-28 21:37:38 -05001273 }
1274
1275 return H2C_SUCCESS;
1276}
1277
1278void rtw_survey_cmd_callback23a(struct rtw_adapter *padapter,
Jes Sorensen1ec89112014-05-16 10:04:28 +02001279 struct cmd_obj *pcmd)
Larry Finger5e93f352014-03-28 21:37:38 -05001280{
1281 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1282
1283 if (pcmd->res == H2C_DROPPED) {
1284 /* TODO: cancel timer and do timeout handler directly... */
1285 /* need to make timeout handlerOS independent */
1286 mod_timer(&pmlmepriv->scan_to_timer,
1287 jiffies + msecs_to_jiffies(1));
1288 } else if (pcmd->res != H2C_SUCCESS) {
1289 mod_timer(&pmlmepriv->scan_to_timer,
1290 jiffies + msecs_to_jiffies(1));
1291 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -07001292 "********Error: MgntActrtw_set_802_11_bssid23a_LIST_SCAN Fail ************\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001293 }
1294
1295 /* free cmd */
1296 rtw_free_cmd_obj23a(pcmd);
1297}
1298
1299void rtw_disassoc_cmd23a_callback(struct rtw_adapter *padapter,
1300 struct cmd_obj *pcmd)
1301{
1302 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1303
1304 if (pcmd->res != H2C_SUCCESS) {
1305 spin_lock_bh(&pmlmepriv->lock);
1306 set_fwstate(pmlmepriv, _FW_LINKED);
1307 spin_unlock_bh(&pmlmepriv->lock);
1308 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -07001309 "***Error: disconnect_cmd_callback Fail ***\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001310 return;
1311 }
1312
1313 /* free cmd */
1314 rtw_free_cmd_obj23a(pcmd);
1315}
1316
1317void rtw_joinbss_cmd23a_callback(struct rtw_adapter *padapter,
1318 struct cmd_obj *pcmd)
1319{
1320 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1321
1322 if (pcmd->res == H2C_DROPPED) {
1323 /* TODO: cancel timer and do timeout handler directly... */
1324 /* need to make timeout handlerOS independent */
1325 mod_timer(&pmlmepriv->assoc_timer,
1326 jiffies + msecs_to_jiffies(1));
1327 } else if (pcmd->res != H2C_SUCCESS) {
1328 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -07001329 "********Error:rtw_select_and_join_from_scanned_queue Wait Sema Fail ************\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001330 mod_timer(&pmlmepriv->assoc_timer,
1331 jiffies + msecs_to_jiffies(1));
1332 }
1333
1334 rtw_free_cmd_obj23a(pcmd);
1335}
1336
1337void rtw_createbss_cmd23a_callback(struct rtw_adapter *padapter,
1338 struct cmd_obj *pcmd)
1339{
1340 struct sta_info *psta;
1341 struct wlan_network *pwlan;
1342 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1343 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)pcmd->parmbuf;
1344 struct wlan_network *tgt_network = &pmlmepriv->cur_network;
Alison Schofield164e2652015-10-20 23:09:37 -07001345 struct rtw_queue *scanned_queue = &pmlmepriv->scanned_queue;
Larry Finger5e93f352014-03-28 21:37:38 -05001346
1347 if (pcmd->res != H2C_SUCCESS) {
1348 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -07001349 "********Error: rtw_createbss_cmd23a_callback Fail ************\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001350 mod_timer(&pmlmepriv->assoc_timer,
1351 jiffies + msecs_to_jiffies(1));
1352 }
1353
1354 del_timer_sync(&pmlmepriv->assoc_timer);
1355
Larry Finger5e93f352014-03-28 21:37:38 -05001356 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1357 psta = rtw_get_stainfo23a(&padapter->stapriv,
1358 pnetwork->MacAddress);
1359 if (!psta) {
1360 psta = rtw_alloc_stainfo23a(&padapter->stapriv,
Jes Sorensen6e8bc712014-05-09 15:03:49 +02001361 pnetwork->MacAddress,
1362 GFP_KERNEL);
Larry Finger5e93f352014-03-28 21:37:38 -05001363 if (!psta) {
1364 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -07001365 "Can't alloc sta_info when createbss_cmd_callback\n");
Yeliz Taneroglu25d55462015-02-27 12:58:09 +02001366 goto createbss_cmd_fail;
Larry Finger5e93f352014-03-28 21:37:38 -05001367 }
1368 }
1369
Jes Sorensen5290cd62014-05-09 15:03:45 +02001370 spin_lock_bh(&pmlmepriv->lock);
Larry Finger5e93f352014-03-28 21:37:38 -05001371 rtw_indicate_connect23a(padapter);
Jes Sorensen5290cd62014-05-09 15:03:45 +02001372 spin_unlock_bh(&pmlmepriv->lock);
Larry Finger5e93f352014-03-28 21:37:38 -05001373 } else {
Jes Sorensenec838b02014-05-09 15:03:46 +02001374 pwlan = rtw_alloc_network(pmlmepriv, GFP_KERNEL);
Alison Schofield164e2652015-10-20 23:09:37 -07001375 spin_lock_bh(&scanned_queue->lock);
Larry Finger5e93f352014-03-28 21:37:38 -05001376 if (!pwlan) {
Alison Schofield164e2652015-10-20 23:09:37 -07001377 pwlan = rtw_get_oldest_wlan_network23a(scanned_queue);
Larry Finger5e93f352014-03-28 21:37:38 -05001378 if (!pwlan) {
1379 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -07001380 "Error: can't get pwlan in rtw23a_joinbss_event_cb\n");
Alison Schofield164e2652015-10-20 23:09:37 -07001381 spin_unlock_bh(&scanned_queue->lock);
Larry Finger5e93f352014-03-28 21:37:38 -05001382 goto createbss_cmd_fail;
1383 }
1384 pwlan->last_scanned = jiffies;
1385 } else {
1386 list_add_tail(&pwlan->list,
Alison Schofield164e2652015-10-20 23:09:37 -07001387 &scanned_queue->queue);
Larry Finger5e93f352014-03-28 21:37:38 -05001388 }
1389
1390 pnetwork->Length = get_wlan_bssid_ex_sz(pnetwork);
1391 memcpy(&pwlan->network, pnetwork, pnetwork->Length);
1392 /* pwlan->fixed = true; */
1393
1394 /* list_add_tail(&pwlan->list,
1395 &pmlmepriv->scanned_queue.queue); */
1396
1397 /* copy pdev_network information to
1398 pmlmepriv->cur_network */
1399 memcpy(&tgt_network->network, pnetwork,
1400 get_wlan_bssid_ex_sz(pnetwork));
1401
1402 /* reset DSConfig */
1403
Jes Sorensen5290cd62014-05-09 15:03:45 +02001404 clr_fwstate(pmlmepriv, _FW_UNDER_LINKING);
Larry Finger5e93f352014-03-28 21:37:38 -05001405
Larry Finger5e93f352014-03-28 21:37:38 -05001406 /* we will set _FW_LINKED when there is one more sat to
1407 join us (rtw_stassoc_event_callback23a) */
Alison Schofield164e2652015-10-20 23:09:37 -07001408 spin_unlock_bh(&scanned_queue->lock);
Larry Finger5e93f352014-03-28 21:37:38 -05001409 }
1410
1411createbss_cmd_fail:
1412
Larry Finger5e93f352014-03-28 21:37:38 -05001413 rtw_free_cmd_obj23a(pcmd);
1414}
1415
1416void rtw_setstaKey_cmdrsp_callback23a(struct rtw_adapter *padapter,
1417 struct cmd_obj *pcmd)
1418{
1419 struct sta_priv *pstapriv;
1420 struct set_stakey_rsp *psetstakey_rsp;
1421 struct sta_info *psta;
1422
1423 pstapriv = &padapter->stapriv;
Greg Donald7e6646d2014-09-06 19:42:03 -05001424 psetstakey_rsp = (struct set_stakey_rsp *) (pcmd->rsp);
Larry Finger5e93f352014-03-28 21:37:38 -05001425 psta = rtw_get_stainfo23a(pstapriv, psetstakey_rsp->addr);
1426
1427 if (!psta) {
1428 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -07001429 "ERROR: rtw_setstaKey_cmdrsp_callback23a => can't get sta_info\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001430 goto exit;
1431 }
1432
1433exit:
1434
1435 rtw_free_cmd_obj23a(pcmd);
1436}
1437
1438void rtw_setassocsta_cmdrsp_callback23a(struct rtw_adapter *padapter,
1439 struct cmd_obj *pcmd)
1440{
1441 struct sta_priv *pstapriv = &padapter->stapriv;
1442 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Greg Donald4e66cf02014-08-22 10:57:49 -05001443 struct set_assocsta_parm *passocsta_parm;
1444 struct set_assocsta_rsp *passocsta_rsp;
Larry Finger5e93f352014-03-28 21:37:38 -05001445 struct sta_info *psta;
1446
1447 passocsta_parm = (struct set_assocsta_parm *)(pcmd->parmbuf);
Greg Donald7e6646d2014-09-06 19:42:03 -05001448 passocsta_rsp = (struct set_assocsta_rsp *) (pcmd->rsp);
Larry Finger5e93f352014-03-28 21:37:38 -05001449 psta = rtw_get_stainfo23a(pstapriv, passocsta_parm->addr);
1450
1451 if (psta == NULL) {
1452 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -07001453 "ERROR: setassocsta_cmdrsp_callbac => can't get sta_info\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001454 goto exit;
1455 }
1456
1457 psta->aid = psta->mac_id = passocsta_rsp->cam_id;
1458
1459 spin_lock_bh(&pmlmepriv->lock);
1460
Jes Sorensenf2f97032014-05-25 22:43:04 +02001461 if (check_fwstate(pmlmepriv, WIFI_MP_STATE) &&
1462 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
Larry Finger5e93f352014-03-28 21:37:38 -05001463 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
1464
1465 set_fwstate(pmlmepriv, _FW_LINKED);
1466 spin_unlock_bh(&pmlmepriv->lock);
1467
1468exit:
1469 rtw_free_cmd_obj23a(pcmd);
1470}