1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 #include <drv_types.h>
8 #include <rtw_debug.h>
9 #include <hal_btcoex.h>
10 #include <linux/jiffies.h>
11
12 static struct _cmd_callback rtw_cmd_callback[] = {
13 {GEN_CMD_CODE(_Read_MACREG), NULL}, /*0*/
14 {GEN_CMD_CODE(_Write_MACREG), NULL},
15 {GEN_CMD_CODE(_Read_BBREG), &rtw_getbbrfreg_cmdrsp_callback},
16 {GEN_CMD_CODE(_Write_BBREG), NULL},
17 {GEN_CMD_CODE(_Read_RFREG), &rtw_getbbrfreg_cmdrsp_callback},
18 {GEN_CMD_CODE(_Write_RFREG), NULL}, /*5*/
19 {GEN_CMD_CODE(_Read_EEPROM), NULL},
20 {GEN_CMD_CODE(_Write_EEPROM), NULL},
21 {GEN_CMD_CODE(_Read_EFUSE), NULL},
22 {GEN_CMD_CODE(_Write_EFUSE), NULL},
23
24 {GEN_CMD_CODE(_Read_CAM), NULL}, /*10*/
25 {GEN_CMD_CODE(_Write_CAM), NULL},
26 {GEN_CMD_CODE(_setBCNITV), NULL},
27 {GEN_CMD_CODE(_setMBIDCFG), NULL},
28 {GEN_CMD_CODE(_JoinBss), &rtw_joinbss_cmd_callback}, /*14*/
29 {GEN_CMD_CODE(_DisConnect), &rtw_disassoc_cmd_callback}, /*15*/
30 {GEN_CMD_CODE(_CreateBss), &rtw_createbss_cmd_callback},
31 {GEN_CMD_CODE(_SetOpMode), NULL},
32 {GEN_CMD_CODE(_SiteSurvey), &rtw_survey_cmd_callback}, /*18*/
33 {GEN_CMD_CODE(_SetAuth), NULL},
34
35 {GEN_CMD_CODE(_SetKey), NULL}, /*20*/
36 {GEN_CMD_CODE(_SetStaKey), &rtw_setstaKey_cmdrsp_callback},
37 {GEN_CMD_CODE(_SetAssocSta), &rtw_setassocsta_cmdrsp_callback},
38 {GEN_CMD_CODE(_DelAssocSta), NULL},
39 {GEN_CMD_CODE(_SetStaPwrState), NULL},
40 {GEN_CMD_CODE(_SetBasicRate), NULL}, /*25*/
41 {GEN_CMD_CODE(_GetBasicRate), NULL},
42 {GEN_CMD_CODE(_SetDataRate), NULL},
43 {GEN_CMD_CODE(_GetDataRate), NULL},
44 {GEN_CMD_CODE(_SetPhyInfo), NULL},
45
46 {GEN_CMD_CODE(_GetPhyInfo), NULL}, /*30*/
47 {GEN_CMD_CODE(_SetPhy), NULL},
48 {GEN_CMD_CODE(_GetPhy), NULL},
49 {GEN_CMD_CODE(_readRssi), NULL},
50 {GEN_CMD_CODE(_readGain), NULL},
51 {GEN_CMD_CODE(_SetAtim), NULL}, /*35*/
52 {GEN_CMD_CODE(_SetPwrMode), NULL},
53 {GEN_CMD_CODE(_JoinbssRpt), NULL},
54 {GEN_CMD_CODE(_SetRaTable), NULL},
55 {GEN_CMD_CODE(_GetRaTable), NULL},
56
57 {GEN_CMD_CODE(_GetCCXReport), NULL}, /*40*/
58 {GEN_CMD_CODE(_GetDTMReport), NULL},
59 {GEN_CMD_CODE(_GetTXRateStatistics), NULL},
60 {GEN_CMD_CODE(_SetUsbSuspend), NULL},
61 {GEN_CMD_CODE(_SetH2cLbk), NULL},
62 {GEN_CMD_CODE(_AddBAReq), NULL}, /*45*/
63 {GEN_CMD_CODE(_SetChannel), NULL}, /*46*/
64 {GEN_CMD_CODE(_SetTxPower), NULL},
65 {GEN_CMD_CODE(_SwitchAntenna), NULL},
66 {GEN_CMD_CODE(_SetCrystalCap), NULL},
67 {GEN_CMD_CODE(_SetSingleCarrierTx), NULL}, /*50*/
68
69 {GEN_CMD_CODE(_SetSingleToneTx), NULL}, /*51*/
70 {GEN_CMD_CODE(_SetCarrierSuppressionTx), NULL},
71 {GEN_CMD_CODE(_SetContinuousTx), NULL},
72 {GEN_CMD_CODE(_SwitchBandwidth), NULL}, /*54*/
73 {GEN_CMD_CODE(_TX_Beacon), NULL},/*55*/
74
75 {GEN_CMD_CODE(_Set_MLME_EVT), NULL},/*56*/
76 {GEN_CMD_CODE(_Set_Drv_Extra), NULL},/*57*/
77 {GEN_CMD_CODE(_Set_H2C_MSG), NULL},/*58*/
78 {GEN_CMD_CODE(_SetChannelPlan), NULL},/*59*/
79
80 {GEN_CMD_CODE(_SetChannelSwitch), NULL},/*60*/
81 {GEN_CMD_CODE(_TDLS), NULL},/*61*/
82 {GEN_CMD_CODE(_ChkBMCSleepq), NULL}, /*62*/
83
84 {GEN_CMD_CODE(_RunInThreadCMD), NULL},/*63*/
85 };
86
87 static struct cmd_hdl wlancmds[] = {
88 GEN_DRV_CMD_HANDLER(0, NULL) /*0*/
89 GEN_DRV_CMD_HANDLER(0, NULL)
90 GEN_DRV_CMD_HANDLER(0, NULL)
91 GEN_DRV_CMD_HANDLER(0, NULL)
92 GEN_DRV_CMD_HANDLER(0, NULL)
93 GEN_DRV_CMD_HANDLER(0, NULL)
94 GEN_MLME_EXT_HANDLER(0, NULL)
95 GEN_MLME_EXT_HANDLER(0, NULL)
96 GEN_MLME_EXT_HANDLER(0, NULL)
97 GEN_MLME_EXT_HANDLER(0, NULL)
98 GEN_MLME_EXT_HANDLER(0, NULL) /*10*/
99 GEN_MLME_EXT_HANDLER(0, NULL)
100 GEN_MLME_EXT_HANDLER(0, NULL)
101 GEN_MLME_EXT_HANDLER(0, NULL)
102 GEN_MLME_EXT_HANDLER(sizeof(struct joinbss_parm), join_cmd_hdl) /*14*/
103 GEN_MLME_EXT_HANDLER(sizeof(struct disconnect_parm), disconnect_hdl)
104 GEN_MLME_EXT_HANDLER(sizeof(struct createbss_parm), createbss_hdl)
105 GEN_MLME_EXT_HANDLER(sizeof(struct setopmode_parm), setopmode_hdl)
106 GEN_MLME_EXT_HANDLER(sizeof(struct sitesurvey_parm), sitesurvey_cmd_hdl) /*18*/
107 GEN_MLME_EXT_HANDLER(sizeof(struct setauth_parm), setauth_hdl)
108 GEN_MLME_EXT_HANDLER(sizeof(struct setkey_parm), setkey_hdl) /*20*/
109 GEN_MLME_EXT_HANDLER(sizeof(struct set_stakey_parm), set_stakey_hdl)
110 GEN_MLME_EXT_HANDLER(sizeof(struct set_assocsta_parm), NULL)
111 GEN_MLME_EXT_HANDLER(sizeof(struct del_assocsta_parm), NULL)
112 GEN_MLME_EXT_HANDLER(sizeof(struct setstapwrstate_parm), NULL)
113 GEN_MLME_EXT_HANDLER(sizeof(struct setbasicrate_parm), NULL)
114 GEN_MLME_EXT_HANDLER(sizeof(struct getbasicrate_parm), NULL)
115 GEN_MLME_EXT_HANDLER(sizeof(struct setdatarate_parm), NULL)
116 GEN_MLME_EXT_HANDLER(sizeof(struct getdatarate_parm), NULL)
117 GEN_MLME_EXT_HANDLER(sizeof(struct setphyinfo_parm), NULL)
118 GEN_MLME_EXT_HANDLER(sizeof(struct getphyinfo_parm), NULL) /*30*/
119 GEN_MLME_EXT_HANDLER(sizeof(struct setphy_parm), NULL)
120 GEN_MLME_EXT_HANDLER(sizeof(struct getphy_parm), NULL)
121 GEN_MLME_EXT_HANDLER(0, NULL)
122 GEN_MLME_EXT_HANDLER(0, NULL)
123 GEN_MLME_EXT_HANDLER(0, NULL)
124 GEN_MLME_EXT_HANDLER(0, NULL)
125 GEN_MLME_EXT_HANDLER(0, NULL)
126 GEN_MLME_EXT_HANDLER(0, NULL)
127 GEN_MLME_EXT_HANDLER(0, NULL)
128 GEN_MLME_EXT_HANDLER(0, NULL) /*40*/
129 GEN_MLME_EXT_HANDLER(0, NULL)
130 GEN_MLME_EXT_HANDLER(0, NULL)
131 GEN_MLME_EXT_HANDLER(0, NULL)
132 GEN_MLME_EXT_HANDLER(0, NULL)
133 GEN_MLME_EXT_HANDLER(sizeof(struct addBaReq_parm), add_ba_hdl)
134 GEN_MLME_EXT_HANDLER(sizeof(struct set_ch_parm), set_ch_hdl) /* 46 */
135 GEN_MLME_EXT_HANDLER(0, NULL)
136 GEN_MLME_EXT_HANDLER(0, NULL)
137 GEN_MLME_EXT_HANDLER(0, NULL)
138 GEN_MLME_EXT_HANDLER(0, NULL) /*50*/
139 GEN_MLME_EXT_HANDLER(0, NULL)
140 GEN_MLME_EXT_HANDLER(0, NULL)
141 GEN_MLME_EXT_HANDLER(0, NULL)
142 GEN_MLME_EXT_HANDLER(0, NULL)
143 GEN_MLME_EXT_HANDLER(sizeof(struct Tx_Beacon_param), tx_beacon_hdl) /*55*/
144
145 GEN_MLME_EXT_HANDLER(0, mlme_evt_hdl) /*56*/
146 GEN_MLME_EXT_HANDLER(0, rtw_drvextra_cmd_hdl) /*57*/
147
148 GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl) /*58*/
149 GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelPlan_param), set_chplan_hdl) /*59*/
150
151 GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelSwitch_param), set_csa_hdl) /*60*/
152 GEN_MLME_EXT_HANDLER(sizeof(struct TDLSoption_param), tdls_hdl) /*61*/
153 GEN_MLME_EXT_HANDLER(0, chk_bmc_sleepq_hdl) /*62*/
154 GEN_MLME_EXT_HANDLER(sizeof(struct RunInThread_param), run_in_thread_hdl) /*63*/
155 };
156
157 /*
158 * Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
159 * No irqsave is necessary.
160 */
161
rtw_init_cmd_priv(struct cmd_priv * pcmdpriv)162 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
163 {
164 int res = 0;
165
166 init_completion(&pcmdpriv->cmd_queue_comp);
167 init_completion(&pcmdpriv->terminate_cmdthread_comp);
168
169 INIT_LIST_HEAD(&pcmdpriv->cmd_queue.queue);
170 spin_lock_init(&pcmdpriv->cmd_queue.lock);
171
172 /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
173
174 pcmdpriv->cmd_seq = 1;
175
176 pcmdpriv->cmd_allocated_buf = rtw_zmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ);
177
178 if (!pcmdpriv->cmd_allocated_buf) {
179 res = -ENOMEM;
180 goto exit;
181 }
182
183 pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - ((SIZE_PTR)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ-1));
184
185 pcmdpriv->rsp_allocated_buf = rtw_zmalloc(MAX_RSPSZ + 4);
186
187 if (!pcmdpriv->rsp_allocated_buf) {
188 res = -ENOMEM;
189 goto exit;
190 }
191
192 pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((SIZE_PTR)(pcmdpriv->rsp_allocated_buf) & 3);
193
194 pcmdpriv->cmd_issued_cnt = 0;
195 pcmdpriv->cmd_done_cnt = 0;
196 pcmdpriv->rsp_cnt = 0;
197
198 mutex_init(&pcmdpriv->sctx_mutex);
199 exit:
200 return res;
201 }
202
203 static void c2h_wk_callback(struct work_struct *work);
rtw_init_evt_priv(struct evt_priv * pevtpriv)204 int rtw_init_evt_priv(struct evt_priv *pevtpriv)
205 {
206 /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
207 atomic_set(&pevtpriv->event_seq, 0);
208 pevtpriv->evt_done_cnt = 0;
209
210 _init_workitem(&pevtpriv->c2h_wk, c2h_wk_callback, NULL);
211 pevtpriv->c2h_wk_alive = false;
212 pevtpriv->c2h_queue = rtw_cbuf_alloc(C2H_QUEUE_MAX_LEN+1);
213 if (!pevtpriv->c2h_queue)
214 return -ENOMEM;
215
216 return 0;
217 }
218
_rtw_free_evt_priv(struct evt_priv * pevtpriv)219 void _rtw_free_evt_priv(struct evt_priv *pevtpriv)
220 {
221 _cancel_workitem_sync(&pevtpriv->c2h_wk);
222 while (pevtpriv->c2h_wk_alive)
223 msleep(10);
224
225 while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) {
226 void *c2h = rtw_cbuf_pop(pevtpriv->c2h_queue);
227
228 if (c2h && c2h != (void *)pevtpriv)
229 kfree(c2h);
230 }
231 kfree(pevtpriv->c2h_queue);
232 }
233
_rtw_free_cmd_priv(struct cmd_priv * pcmdpriv)234 void _rtw_free_cmd_priv(struct cmd_priv *pcmdpriv)
235 {
236 if (pcmdpriv) {
237 kfree(pcmdpriv->cmd_allocated_buf);
238
239 kfree(pcmdpriv->rsp_allocated_buf);
240
241 mutex_destroy(&pcmdpriv->sctx_mutex);
242 }
243 }
244
245 /*
246 * Calling Context:
247 *
248 * rtw_enqueue_cmd can only be called between kernel thread,
249 * since only spin_lock is used.
250 *
251 * ISR/Call-Back functions can't call this sub-function.
252 *
253 */
254
_rtw_enqueue_cmd(struct __queue * queue,struct cmd_obj * obj)255 int _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj)
256 {
257 unsigned long irqL;
258
259 if (!obj)
260 goto exit;
261
262 /* spin_lock_bh(&queue->lock); */
263 spin_lock_irqsave(&queue->lock, irqL);
264
265 list_add_tail(&obj->list, &queue->queue);
266
267 /* spin_unlock_bh(&queue->lock); */
268 spin_unlock_irqrestore(&queue->lock, irqL);
269
270 exit:
271 return _SUCCESS;
272 }
273
_rtw_dequeue_cmd(struct __queue * queue)274 struct cmd_obj *_rtw_dequeue_cmd(struct __queue *queue)
275 {
276 unsigned long irqL;
277 struct cmd_obj *obj;
278
279 /* spin_lock_bh(&(queue->lock)); */
280 spin_lock_irqsave(&queue->lock, irqL);
281 if (list_empty(&queue->queue))
282 obj = NULL;
283 else {
284 obj = container_of(get_next(&queue->queue), struct cmd_obj, list);
285 list_del_init(&obj->list);
286 }
287
288 /* spin_unlock_bh(&(queue->lock)); */
289 spin_unlock_irqrestore(&queue->lock, irqL);
290
291 return obj;
292 }
293
rtw_free_evt_priv(struct evt_priv * pevtpriv)294 void rtw_free_evt_priv(struct evt_priv *pevtpriv)
295 {
296 _rtw_free_evt_priv(pevtpriv);
297 }
298
rtw_free_cmd_priv(struct cmd_priv * pcmdpriv)299 void rtw_free_cmd_priv(struct cmd_priv *pcmdpriv)
300 {
301 _rtw_free_cmd_priv(pcmdpriv);
302 }
303
304 int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj);
rtw_cmd_filter(struct cmd_priv * pcmdpriv,struct cmd_obj * cmd_obj)305 int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
306 {
307 u8 bAllow = false; /* set to true to allow enqueuing cmd when hw_init_completed is false */
308
309 if (cmd_obj->cmdcode == GEN_CMD_CODE(_SetChannelPlan))
310 bAllow = true;
311
312 if ((!pcmdpriv->padapter->hw_init_completed && !bAllow) ||
313 !atomic_read(&pcmdpriv->cmdthd_running)) /* com_thread not running */
314 return _FAIL;
315
316 return _SUCCESS;
317 }
318
rtw_enqueue_cmd(struct cmd_priv * pcmdpriv,struct cmd_obj * cmd_obj)319 int rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
320 {
321 int res = _FAIL;
322 struct adapter *padapter = pcmdpriv->padapter;
323
324 if (!cmd_obj)
325 goto exit;
326
327 cmd_obj->padapter = padapter;
328
329 res = rtw_cmd_filter(pcmdpriv, cmd_obj);
330 if (res == _FAIL) {
331 rtw_free_cmd_obj(cmd_obj);
332 goto exit;
333 }
334
335 res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
336
337 if (res == _SUCCESS)
338 complete(&pcmdpriv->cmd_queue_comp);
339
340 exit:
341 return res;
342 }
343
rtw_dequeue_cmd(struct cmd_priv * pcmdpriv)344 struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv)
345 {
346 return _rtw_dequeue_cmd(&pcmdpriv->cmd_queue);
347 }
348
rtw_free_cmd_obj(struct cmd_obj * pcmd)349 void rtw_free_cmd_obj(struct cmd_obj *pcmd)
350 {
351 if ((pcmd->cmdcode != _JoinBss_CMD_) &&
352 (pcmd->cmdcode != _CreateBss_CMD_)) {
353 /* free parmbuf in cmd_obj */
354 kfree(pcmd->parmbuf);
355 }
356
357 if (pcmd->rsp) {
358 if (pcmd->rspsz != 0) {
359 /* free rsp in cmd_obj */
360 kfree(pcmd->rsp);
361 }
362 }
363
364 /* free cmd_obj */
365 kfree(pcmd);
366 }
367
rtw_stop_cmd_thread(struct adapter * adapter)368 void rtw_stop_cmd_thread(struct adapter *adapter)
369 {
370 if (adapter->cmdThread &&
371 atomic_read(&adapter->cmdpriv.cmdthd_running) &&
372 adapter->cmdpriv.stop_req == 0) {
373 adapter->cmdpriv.stop_req = 1;
374 complete(&adapter->cmdpriv.cmd_queue_comp);
375 wait_for_completion(&adapter->cmdpriv.terminate_cmdthread_comp);
376 }
377 }
378
rtw_cmd_thread(void * context)379 int rtw_cmd_thread(void *context)
380 {
381 u8 ret;
382 struct cmd_obj *pcmd;
383 u8 *pcmdbuf;
384 u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf);
385 void (*pcmd_callback)(struct adapter *dev, struct cmd_obj *pcmd);
386 struct adapter *padapter = context;
387 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
388 struct drvextra_cmd_parm *extra_parm = NULL;
389
390 thread_enter("RTW_CMD_THREAD");
391
392 pcmdbuf = pcmdpriv->cmd_buf;
393
394 pcmdpriv->stop_req = 0;
395 atomic_set(&pcmdpriv->cmdthd_running, true);
396 complete(&pcmdpriv->terminate_cmdthread_comp);
397
398 while (1) {
399 if (wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp)) {
400 netdev_dbg(padapter->pnetdev,
401 FUNC_ADPT_FMT " wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp) return != 0, break\n",
402 FUNC_ADPT_ARG(padapter));
403 break;
404 }
405
406 if (padapter->bDriverStopped || padapter->bSurpriseRemoved) {
407 netdev_dbg(padapter->pnetdev,
408 "%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
409 __func__, padapter->bDriverStopped,
410 padapter->bSurpriseRemoved, __LINE__);
411 break;
412 }
413
414 if (pcmdpriv->stop_req) {
415 netdev_dbg(padapter->pnetdev,
416 FUNC_ADPT_FMT " stop_req:%u, break\n",
417 FUNC_ADPT_ARG(padapter),
418 pcmdpriv->stop_req);
419 break;
420 }
421
422 if (list_empty(&pcmdpriv->cmd_queue.queue))
423 continue;
424
425 if (rtw_register_cmd_alive(padapter) != _SUCCESS)
426 continue;
427
428 _next:
429 if (padapter->bDriverStopped || padapter->bSurpriseRemoved) {
430 netdev_dbg(padapter->pnetdev,
431 "%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
432 __func__, padapter->bDriverStopped,
433 padapter->bSurpriseRemoved, __LINE__);
434 break;
435 }
436
437 pcmd = rtw_dequeue_cmd(pcmdpriv);
438 if (!pcmd) {
439 rtw_unregister_cmd_alive(padapter);
440 continue;
441 }
442
443 if (rtw_cmd_filter(pcmdpriv, pcmd) == _FAIL) {
444 pcmd->res = H2C_DROPPED;
445 goto post_process;
446 }
447
448 pcmdpriv->cmd_issued_cnt++;
449
450 pcmd->cmdsz = round_up((pcmd->cmdsz), 4);
451
452 memcpy(pcmdbuf, pcmd->parmbuf, pcmd->cmdsz);
453
454 if (pcmd->cmdcode < ARRAY_SIZE(wlancmds)) {
455 cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns;
456
457 if (cmd_hdl) {
458 ret = cmd_hdl(pcmd->padapter, pcmdbuf);
459 pcmd->res = ret;
460 }
461
462 pcmdpriv->cmd_seq++;
463 } else {
464 pcmd->res = H2C_PARAMETERS_ERROR;
465 }
466
467 cmd_hdl = NULL;
468
469 post_process:
470
471 if (mutex_lock_interruptible(&pcmd->padapter->cmdpriv.sctx_mutex) == 0) {
472 if (pcmd->sctx) {
473 netdev_dbg(padapter->pnetdev,
474 FUNC_ADPT_FMT " pcmd->sctx\n",
475 FUNC_ADPT_ARG(pcmd->padapter));
476
477 if (pcmd->res == H2C_SUCCESS)
478 rtw_sctx_done(&pcmd->sctx);
479 else
480 rtw_sctx_done_err(&pcmd->sctx, RTW_SCTX_DONE_CMD_ERROR);
481 }
482 mutex_unlock(&pcmd->padapter->cmdpriv.sctx_mutex);
483 }
484
485 /* call callback function for post-processed */
486 if (pcmd->cmdcode < ARRAY_SIZE(rtw_cmd_callback)) {
487 pcmd_callback = rtw_cmd_callback[pcmd->cmdcode].callback;
488 if (!pcmd_callback) {
489 rtw_free_cmd_obj(pcmd);
490 } else {
491 /* todo: !!! fill rsp_buf to pcmd->rsp if (pcmd->rsp!= NULL) */
492 pcmd_callback(pcmd->padapter, pcmd);/* need consider that free cmd_obj in rtw_cmd_callback */
493 }
494 } else {
495 rtw_free_cmd_obj(pcmd);
496 }
497 flush_signals_thread();
498 goto _next;
499 }
500
501 /* free all cmd_obj resources */
502 do {
503 pcmd = rtw_dequeue_cmd(pcmdpriv);
504 if (!pcmd) {
505 rtw_unregister_cmd_alive(padapter);
506 break;
507 }
508
509 if (pcmd->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
510 extra_parm = (struct drvextra_cmd_parm *)pcmd->parmbuf;
511 if (extra_parm->pbuf && extra_parm->size > 0)
512 kfree(extra_parm->pbuf);
513 }
514
515 rtw_free_cmd_obj(pcmd);
516 } while (1);
517
518 complete(&pcmdpriv->terminate_cmdthread_comp);
519 atomic_set(&pcmdpriv->cmdthd_running, false);
520
521 return 0;
522 }
523
524 /*
525 * rtw_sitesurvey_cmd(~)
526 * ### NOTE:#### (!!!!)
527 * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
528 */
529
rtw_sitesurvey_cmd(struct adapter * padapter,struct ndis_802_11_ssid * ssid,int ssid_num,struct rtw_ieee80211_channel * ch,int ch_num)530 u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid, int ssid_num,
531 struct rtw_ieee80211_channel *ch, int ch_num)
532 {
533 u8 res = _FAIL;
534 struct cmd_obj *ph2c;
535 struct sitesurvey_parm *psurveyPara;
536 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
537 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
538
539 if (check_fwstate(pmlmepriv, _FW_LINKED))
540 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
541
542 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
543 if (!ph2c)
544 return _FAIL;
545
546 psurveyPara = rtw_zmalloc(sizeof(struct sitesurvey_parm));
547 if (!psurveyPara) {
548 kfree(ph2c);
549 return _FAIL;
550 }
551
552 rtw_free_network_queue(padapter, false);
553
554 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
555
556 /* psurveyPara->bsslimit = 48; */
557 psurveyPara->scan_mode = pmlmepriv->scan_mode;
558
559 /* prepare ssid list */
560 if (ssid) {
561 int i;
562
563 for (i = 0; i < ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) {
564 if (ssid[i].ssid_length) {
565 memcpy(&psurveyPara->ssid[i], &ssid[i], sizeof(struct ndis_802_11_ssid));
566 psurveyPara->ssid_num++;
567 }
568 }
569 }
570
571 /* prepare channel list */
572 if (ch) {
573 int i;
574
575 for (i = 0; i < ch_num && i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
576 if (ch[i].hw_value && !(ch[i].flags & RTW_IEEE80211_CHAN_DISABLED)) {
577 memcpy(&psurveyPara->ch[i], &ch[i], sizeof(struct rtw_ieee80211_channel));
578 psurveyPara->ch_num++;
579 }
580 }
581 }
582
583 set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
584
585 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
586
587 if (res == _SUCCESS) {
588 pmlmepriv->scan_start_time = jiffies;
589 _set_timer(&pmlmepriv->scan_to_timer, SCANNING_TIMEOUT);
590 } else {
591 _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
592 }
593 return res;
594 }
595
rtw_setdatarate_cmd(struct adapter * padapter,u8 * rateset)596 u8 rtw_setdatarate_cmd(struct adapter *padapter, u8 *rateset)
597 {
598 struct cmd_obj *ph2c;
599 struct setdatarate_parm *pbsetdataratepara;
600 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
601 u8 res = _SUCCESS;
602
603 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
604 if (!ph2c) {
605 res = _FAIL;
606 goto exit;
607 }
608
609 pbsetdataratepara = rtw_zmalloc(sizeof(struct setdatarate_parm));
610 if (!pbsetdataratepara) {
611 kfree(ph2c);
612 res = _FAIL;
613 goto exit;
614 }
615
616 init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara, GEN_CMD_CODE(_SetDataRate));
617 pbsetdataratepara->mac_id = 5;
618 memcpy(pbsetdataratepara->datarates, rateset, NumRates);
619
620 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
621 exit:
622 return res;
623 }
624
rtw_getbbrfreg_cmdrsp_callback(struct adapter * padapter,struct cmd_obj * pcmd)625 void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd)
626 {
627 /* rtw_free_cmd_obj(pcmd); */
628 kfree(pcmd->parmbuf);
629 kfree(pcmd);
630 }
631
rtw_createbss_cmd(struct adapter * padapter)632 u8 rtw_createbss_cmd(struct adapter *padapter)
633 {
634 struct cmd_obj *pcmd;
635 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
636 struct wlan_bssid_ex *pdev_network = &padapter->registrypriv.dev_network;
637 u8 res = _SUCCESS;
638
639 pcmd = rtw_zmalloc(sizeof(struct cmd_obj));
640 if (!pcmd) {
641 res = _FAIL;
642 goto exit;
643 }
644
645 INIT_LIST_HEAD(&pcmd->list);
646 pcmd->cmdcode = _CreateBss_CMD_;
647 pcmd->parmbuf = (unsigned char *)pdev_network;
648 pcmd->cmdsz = get_wlan_bssid_ex_sz((struct wlan_bssid_ex *)pdev_network);
649 pcmd->rsp = NULL;
650 pcmd->rspsz = 0;
651
652 pdev_network->length = pcmd->cmdsz;
653
654 res = rtw_enqueue_cmd(pcmdpriv, pcmd);
655
656 exit:
657 return res;
658 }
659
rtw_startbss_cmd(struct adapter * padapter,int flags)660 int rtw_startbss_cmd(struct adapter *padapter, int flags)
661 {
662 struct cmd_obj *pcmd;
663 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
664 struct submit_ctx sctx;
665 int res = _SUCCESS;
666
667 if (flags & RTW_CMDF_DIRECTLY) {
668 /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
669 start_bss_network(padapter);
670 } else {
671 /* need enqueue, prepare cmd_obj and enqueue */
672 pcmd = rtw_zmalloc(sizeof(struct cmd_obj));
673 if (!pcmd) {
674 res = _FAIL;
675 goto exit;
676 }
677
678 INIT_LIST_HEAD(&pcmd->list);
679 pcmd->cmdcode = GEN_CMD_CODE(_CreateBss);
680 pcmd->parmbuf = NULL;
681 pcmd->cmdsz = 0;
682 pcmd->rsp = NULL;
683 pcmd->rspsz = 0;
684
685 if (flags & RTW_CMDF_WAIT_ACK) {
686 pcmd->sctx = &sctx;
687 rtw_sctx_init(&sctx, 2000);
688 }
689
690 res = rtw_enqueue_cmd(pcmdpriv, pcmd);
691
692 if (res == _SUCCESS && (flags & RTW_CMDF_WAIT_ACK)) {
693 rtw_sctx_wait(&sctx);
694 if (mutex_lock_interruptible(&pcmdpriv->sctx_mutex) == 0) {
695 if (sctx.status == RTW_SCTX_SUBMITTED)
696 pcmd->sctx = NULL;
697 mutex_unlock(&pcmdpriv->sctx_mutex);
698 }
699 }
700 }
701
702 exit:
703 return res;
704 }
705
rtw_joinbss_cmd(struct adapter * padapter,struct wlan_network * pnetwork)706 u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
707 {
708 u8 res = _SUCCESS;
709 uint t_len = 0;
710 struct wlan_bssid_ex *psecnetwork;
711 struct cmd_obj *pcmd;
712 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
713 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
714 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
715 struct security_priv *psecuritypriv = &padapter->securitypriv;
716 struct registry_priv *pregistrypriv = &padapter->registrypriv;
717 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
718 enum ndis_802_11_network_infrastructure ndis_network_mode = pnetwork->network.infrastructure_mode;
719 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
720 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
721 u32 tmp_len;
722 u8 *ptmp = NULL;
723
724 pcmd = rtw_zmalloc(sizeof(struct cmd_obj));
725 if (!pcmd) {
726 res = _FAIL;
727 goto exit;
728 }
729 /* for ies is fix buf size */
730 t_len = sizeof(struct wlan_bssid_ex);
731
732
733 /* for hidden ap to set fw_state here */
734 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) != true) {
735 switch (ndis_network_mode) {
736 case Ndis802_11IBSS:
737 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
738 break;
739
740 case Ndis802_11Infrastructure:
741 set_fwstate(pmlmepriv, WIFI_STATION_STATE);
742 break;
743
744 case Ndis802_11APMode:
745 case Ndis802_11AutoUnknown:
746 case Ndis802_11InfrastructureMax:
747 break;
748 }
749 }
750
751 psecnetwork = (struct wlan_bssid_ex *)&psecuritypriv->sec_bss;
752
753 memset(psecnetwork, 0, t_len);
754
755 memcpy(psecnetwork, &pnetwork->network, get_wlan_bssid_ex_sz(&pnetwork->network));
756
757 psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->ie_length;
758
759 if ((psecnetwork->ie_length-12) < (256-1))
760 memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->ies[12], psecnetwork->ie_length-12);
761 else
762 memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->ies[12], (256-1));
763
764 psecnetwork->ie_length = 0;
765 /* Added by Albert 2009/02/18 */
766 /* If the driver wants to use the bssid to create the connection. */
767 /* If not, we have to copy the connecting AP's MAC address to it so that */
768 /* the driver just has the bssid information for PMKIDList searching. */
769
770 if (!pmlmepriv->assoc_by_bssid)
771 memcpy(&pmlmepriv->assoc_bssid[0], &pnetwork->network.mac_address[0], ETH_ALEN);
772
773 psecnetwork->ie_length = rtw_restruct_sec_ie(padapter, &pnetwork->network.ies[0], &psecnetwork->ies[0], pnetwork->network.ie_length);
774
775
776 pqospriv->qos_option = 0;
777
778 if (pregistrypriv->wmm_enable) {
779 tmp_len = rtw_restruct_wmm_ie(padapter, &pnetwork->network.ies[0], &psecnetwork->ies[0], pnetwork->network.ie_length, psecnetwork->ie_length);
780
781 if (psecnetwork->ie_length != tmp_len) {
782 psecnetwork->ie_length = tmp_len;
783 pqospriv->qos_option = 1; /* There is WMM IE in this corresp. beacon */
784 } else {
785 pqospriv->qos_option = 0;/* There is no WMM IE in this corresp. beacon */
786 }
787 }
788
789 phtpriv->ht_option = false;
790 ptmp = rtw_get_ie(&pnetwork->network.ies[12], WLAN_EID_HT_CAPABILITY, &tmp_len, pnetwork->network.ie_length-12);
791 if (pregistrypriv->ht_enable && ptmp && tmp_len > 0) {
792 /* Added by Albert 2010/06/23 */
793 /* For the WEP mode, we will use the bg mode to do the connection to avoid some IOT issue. */
794 /* Especially for Realtek 8192u SoftAP. */
795 if ((padapter->securitypriv.dot11PrivacyAlgrthm != _WEP40_) &&
796 (padapter->securitypriv.dot11PrivacyAlgrthm != _WEP104_) &&
797 (padapter->securitypriv.dot11PrivacyAlgrthm != _TKIP_)) {
798 rtw_ht_use_default_setting(padapter);
799
800 rtw_build_wmm_ie_ht(padapter, &psecnetwork->ies[12], &psecnetwork->ie_length);
801
802 /* rtw_restructure_ht_ie */
803 rtw_restructure_ht_ie(padapter, &pnetwork->network.ies[12], &psecnetwork->ies[0],
804 pnetwork->network.ie_length-12, &psecnetwork->ie_length,
805 pnetwork->network.configuration.ds_config);
806 }
807 }
808
809 rtw_append_exented_cap(padapter, &psecnetwork->ies[0], &psecnetwork->ie_length);
810
811 pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pnetwork->network.ies, pnetwork->network.ie_length);
812
813 pcmd->cmdsz = get_wlan_bssid_ex_sz(psecnetwork);/* get cmdsz before endian conversion */
814
815 INIT_LIST_HEAD(&pcmd->list);
816 pcmd->cmdcode = _JoinBss_CMD_;/* GEN_CMD_CODE(_JoinBss) */
817 pcmd->parmbuf = (unsigned char *)psecnetwork;
818 pcmd->rsp = NULL;
819 pcmd->rspsz = 0;
820
821 res = rtw_enqueue_cmd(pcmdpriv, pcmd);
822
823 exit:
824 return res;
825 }
826
rtw_disassoc_cmd(struct adapter * padapter,u32 deauth_timeout_ms,bool enqueue)827 u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueue) /* for sta_mode */
828 {
829 struct cmd_obj *cmdobj = NULL;
830 struct disconnect_parm *param = NULL;
831 struct cmd_priv *cmdpriv = &padapter->cmdpriv;
832 u8 res = _SUCCESS;
833
834 /* prepare cmd parameter */
835 param = rtw_zmalloc(sizeof(*param));
836 if (!param) {
837 res = _FAIL;
838 goto exit;
839 }
840 param->deauth_timeout_ms = deauth_timeout_ms;
841
842 if (enqueue) {
843 /* need enqueue, prepare cmd_obj and enqueue */
844 cmdobj = rtw_zmalloc(sizeof(*cmdobj));
845 if (!cmdobj) {
846 res = _FAIL;
847 kfree(param);
848 goto exit;
849 }
850 init_h2fwcmd_w_parm_no_rsp(cmdobj, param, _DisConnect_CMD_);
851 res = rtw_enqueue_cmd(cmdpriv, cmdobj);
852 } else {
853 /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
854 if (disconnect_hdl(padapter, (u8 *)param) != H2C_SUCCESS)
855 res = _FAIL;
856 kfree(param);
857 }
858
859 exit:
860 return res;
861 }
862
rtw_setopmode_cmd(struct adapter * padapter,enum ndis_802_11_network_infrastructure networktype,bool enqueue)863 u8 rtw_setopmode_cmd(struct adapter *padapter, enum ndis_802_11_network_infrastructure networktype, bool enqueue)
864 {
865 struct cmd_obj *ph2c;
866 struct setopmode_parm *psetop;
867
868 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
869 u8 res = _SUCCESS;
870
871 psetop = rtw_zmalloc(sizeof(struct setopmode_parm));
872
873 if (!psetop) {
874 res = _FAIL;
875 goto exit;
876 }
877 psetop->mode = (u8)networktype;
878
879 if (enqueue) {
880 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
881 if (!ph2c) {
882 kfree(psetop);
883 res = _FAIL;
884 goto exit;
885 }
886
887 init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
888 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
889 } else {
890 setopmode_hdl(padapter, (u8 *)psetop);
891 kfree(psetop);
892 }
893 exit:
894 return res;
895 }
896
rtw_setstakey_cmd(struct adapter * padapter,struct sta_info * sta,u8 unicast_key,bool enqueue)897 u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_key, bool enqueue)
898 {
899 struct cmd_obj *ph2c;
900 struct set_stakey_parm *psetstakey_para;
901 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
902 struct set_stakey_rsp *psetstakey_rsp = NULL;
903 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
904 struct security_priv *psecuritypriv = &padapter->securitypriv;
905 u8 res = _SUCCESS;
906
907 psetstakey_para = rtw_zmalloc(sizeof(struct set_stakey_parm));
908 if (!psetstakey_para) {
909 res = _FAIL;
910 goto exit;
911 }
912
913 memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
914
915 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
916 psetstakey_para->algorithm = (unsigned char)psecuritypriv->dot11PrivacyAlgrthm;
917 else
918 GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm, false);
919
920 if (unicast_key)
921 memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16);
922 else
923 memcpy(&psetstakey_para->key, &psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey, 16);
924
925 /* jeff: set this because at least sw key is ready */
926 padapter->securitypriv.busetkipkey = true;
927
928 if (enqueue) {
929 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
930 if (!ph2c) {
931 kfree(psetstakey_para);
932 res = _FAIL;
933 goto exit;
934 }
935
936 psetstakey_rsp = rtw_zmalloc(sizeof(struct set_stakey_rsp));
937 if (!psetstakey_rsp) {
938 kfree(ph2c);
939 kfree(psetstakey_para);
940 res = _FAIL;
941 goto exit;
942 }
943
944 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
945 ph2c->rsp = (u8 *)psetstakey_rsp;
946 ph2c->rspsz = sizeof(struct set_stakey_rsp);
947 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
948 } else {
949 set_stakey_hdl(padapter, (u8 *)psetstakey_para);
950 kfree(psetstakey_para);
951 }
952 exit:
953 return res;
954 }
955
rtw_clearstakey_cmd(struct adapter * padapter,struct sta_info * sta,u8 enqueue)956 u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueue)
957 {
958 struct cmd_obj *ph2c;
959 struct set_stakey_parm *psetstakey_para;
960 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
961 struct set_stakey_rsp *psetstakey_rsp = NULL;
962 s16 cam_id = 0;
963 u8 res = _SUCCESS;
964
965 if (!enqueue) {
966 while ((cam_id = rtw_camid_search(padapter, sta->hwaddr, -1)) >= 0) {
967 netdev_dbg(padapter->pnetdev,
968 "clear key for addr:%pM, camid:%d\n",
969 MAC_ARG(sta->hwaddr), cam_id);
970 clear_cam_entry(padapter, cam_id);
971 rtw_camid_free(padapter, cam_id);
972 }
973 } else {
974 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
975 if (!ph2c) {
976 res = _FAIL;
977 goto exit;
978 }
979
980 psetstakey_para = rtw_zmalloc(sizeof(struct set_stakey_parm));
981 if (!psetstakey_para) {
982 kfree(ph2c);
983 res = _FAIL;
984 goto exit;
985 }
986
987 psetstakey_rsp = rtw_zmalloc(sizeof(struct set_stakey_rsp));
988 if (!psetstakey_rsp) {
989 kfree(ph2c);
990 kfree(psetstakey_para);
991 res = _FAIL;
992 goto exit;
993 }
994
995 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
996 ph2c->rsp = (u8 *)psetstakey_rsp;
997 ph2c->rspsz = sizeof(struct set_stakey_rsp);
998
999 memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
1000
1001 psetstakey_para->algorithm = _NO_PRIVACY_;
1002
1003 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1004 }
1005 exit:
1006 return res;
1007 }
1008
rtw_addbareq_cmd(struct adapter * padapter,u8 tid,u8 * addr)1009 u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr)
1010 {
1011 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1012 struct cmd_obj *ph2c;
1013 struct addBaReq_parm *paddbareq_parm;
1014
1015 u8 res = _SUCCESS;
1016
1017 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1018 if (!ph2c) {
1019 res = _FAIL;
1020 goto exit;
1021 }
1022
1023 paddbareq_parm = rtw_zmalloc(sizeof(struct addBaReq_parm));
1024 if (!paddbareq_parm) {
1025 kfree(ph2c);
1026 res = _FAIL;
1027 goto exit;
1028 }
1029
1030 paddbareq_parm->tid = tid;
1031 memcpy(paddbareq_parm->addr, addr, ETH_ALEN);
1032
1033 init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm, GEN_CMD_CODE(_AddBAReq));
1034
1035 /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
1036 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1037
1038 exit:
1039 return res;
1040 }
1041 /* add for CONFIG_IEEE80211W, none 11w can use it */
rtw_reset_securitypriv_cmd(struct adapter * padapter)1042 u8 rtw_reset_securitypriv_cmd(struct adapter *padapter)
1043 {
1044 struct cmd_obj *ph2c;
1045 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1046 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1047 u8 res = _SUCCESS;
1048
1049 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1050 if (!ph2c) {
1051 res = _FAIL;
1052 goto exit;
1053 }
1054
1055 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1056 if (!pdrvextra_cmd_parm) {
1057 kfree(ph2c);
1058 res = _FAIL;
1059 goto exit;
1060 }
1061
1062 pdrvextra_cmd_parm->ec_id = RESET_SECURITYPRIV;
1063 pdrvextra_cmd_parm->type = 0;
1064 pdrvextra_cmd_parm->size = 0;
1065 pdrvextra_cmd_parm->pbuf = NULL;
1066
1067 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1068
1069
1070 /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
1071 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1072 exit:
1073 return res;
1074 }
1075
rtw_free_assoc_resources_cmd(struct adapter * padapter)1076 u8 rtw_free_assoc_resources_cmd(struct adapter *padapter)
1077 {
1078 struct cmd_obj *ph2c;
1079 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1080 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1081 u8 res = _SUCCESS;
1082
1083 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1084 if (!ph2c) {
1085 res = _FAIL;
1086 goto exit;
1087 }
1088
1089 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1090 if (!pdrvextra_cmd_parm) {
1091 kfree(ph2c);
1092 res = _FAIL;
1093 goto exit;
1094 }
1095
1096 pdrvextra_cmd_parm->ec_id = FREE_ASSOC_RESOURCES;
1097 pdrvextra_cmd_parm->type = 0;
1098 pdrvextra_cmd_parm->size = 0;
1099 pdrvextra_cmd_parm->pbuf = NULL;
1100
1101 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1102
1103 /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
1104 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1105 exit:
1106 return res;
1107 }
1108
rtw_dynamic_chk_wk_cmd(struct adapter * padapter)1109 u8 rtw_dynamic_chk_wk_cmd(struct adapter *padapter)
1110 {
1111 struct cmd_obj *ph2c;
1112 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1113 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1114 u8 res = _SUCCESS;
1115
1116 /* only primary padapter does this cmd */
1117 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1118 if (!ph2c) {
1119 res = _FAIL;
1120 goto exit;
1121 }
1122
1123 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1124 if (!pdrvextra_cmd_parm) {
1125 kfree(ph2c);
1126 res = _FAIL;
1127 goto exit;
1128 }
1129
1130 pdrvextra_cmd_parm->ec_id = DYNAMIC_CHK_WK_CID;
1131 pdrvextra_cmd_parm->type = 0;
1132 pdrvextra_cmd_parm->size = 0;
1133 pdrvextra_cmd_parm->pbuf = NULL;
1134 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1135
1136
1137 /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
1138 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1139 exit:
1140 return res;
1141 }
1142
rtw_set_chplan_cmd(struct adapter * padapter,u8 chplan,u8 enqueue,u8 swconfig)1143 u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue, u8 swconfig)
1144 {
1145 struct cmd_obj *pcmdobj;
1146 struct SetChannelPlan_param *setChannelPlan_param;
1147 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1148
1149 u8 res = _SUCCESS;
1150
1151 /* check if allow software config */
1152 if (swconfig && rtw_hal_is_disable_sw_channel_plan(padapter)) {
1153 res = _FAIL;
1154 goto exit;
1155 }
1156
1157 /* check input parameter */
1158 if (!rtw_is_channel_plan_valid(chplan)) {
1159 res = _FAIL;
1160 goto exit;
1161 }
1162
1163 /* prepare cmd parameter */
1164 setChannelPlan_param = rtw_zmalloc(sizeof(struct SetChannelPlan_param));
1165 if (!setChannelPlan_param) {
1166 res = _FAIL;
1167 goto exit;
1168 }
1169 setChannelPlan_param->channel_plan = chplan;
1170
1171 if (enqueue) {
1172 /* need enqueue, prepare cmd_obj and enqueue */
1173 pcmdobj = rtw_zmalloc(sizeof(struct cmd_obj));
1174 if (!pcmdobj) {
1175 kfree(setChannelPlan_param);
1176 res = _FAIL;
1177 goto exit;
1178 }
1179
1180 init_h2fwcmd_w_parm_no_rsp(pcmdobj, setChannelPlan_param, GEN_CMD_CODE(_SetChannelPlan));
1181 res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
1182 } else {
1183 /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
1184 if (set_chplan_hdl(padapter, (unsigned char *)setChannelPlan_param) != H2C_SUCCESS)
1185 res = _FAIL;
1186
1187 kfree(setChannelPlan_param);
1188 }
1189
1190 /* do something based on res... */
1191 if (res == _SUCCESS)
1192 padapter->mlmepriv.ChannelPlan = chplan;
1193
1194 exit:
1195 return res;
1196 }
1197
collect_traffic_statistics(struct adapter * padapter)1198 static void collect_traffic_statistics(struct adapter *padapter)
1199 {
1200 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
1201
1202 /* Tx */
1203 pdvobjpriv->traffic_stat.tx_bytes = padapter->xmitpriv.tx_bytes;
1204 pdvobjpriv->traffic_stat.tx_pkts = padapter->xmitpriv.tx_pkts;
1205 pdvobjpriv->traffic_stat.tx_drop = padapter->xmitpriv.tx_drop;
1206
1207 /* Rx */
1208 pdvobjpriv->traffic_stat.rx_bytes = padapter->recvpriv.rx_bytes;
1209 pdvobjpriv->traffic_stat.rx_pkts = padapter->recvpriv.rx_pkts;
1210 pdvobjpriv->traffic_stat.rx_drop = padapter->recvpriv.rx_drop;
1211
1212 /* Calculate throughput in last interval */
1213 pdvobjpriv->traffic_stat.cur_tx_bytes = pdvobjpriv->traffic_stat.tx_bytes - pdvobjpriv->traffic_stat.last_tx_bytes;
1214 pdvobjpriv->traffic_stat.cur_rx_bytes = pdvobjpriv->traffic_stat.rx_bytes - pdvobjpriv->traffic_stat.last_rx_bytes;
1215 pdvobjpriv->traffic_stat.last_tx_bytes = pdvobjpriv->traffic_stat.tx_bytes;
1216 pdvobjpriv->traffic_stat.last_rx_bytes = pdvobjpriv->traffic_stat.rx_bytes;
1217
1218 pdvobjpriv->traffic_stat.cur_tx_tp = (u32)(pdvobjpriv->traffic_stat.cur_tx_bytes * 8/2/1024/1024);
1219 pdvobjpriv->traffic_stat.cur_rx_tp = (u32)(pdvobjpriv->traffic_stat.cur_rx_bytes * 8/2/1024/1024);
1220 }
1221
traffic_status_watchdog(struct adapter * padapter,u8 from_timer)1222 u8 traffic_status_watchdog(struct adapter *padapter, u8 from_timer)
1223 {
1224 u8 bEnterPS = false;
1225 u16 BusyThresholdHigh = 25;
1226 u16 BusyThresholdLow = 10;
1227 u16 BusyThreshold = BusyThresholdHigh;
1228 u8 bBusyTraffic = false, bTxBusyTraffic = false, bRxBusyTraffic = false;
1229 u8 bHigherBusyTraffic = false, bHigherBusyRxTraffic = false, bHigherBusyTxTraffic = false;
1230 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1231
1232 collect_traffic_statistics(padapter);
1233
1234 /* */
1235 /* Determine if our traffic is busy now */
1236 /* */
1237 if ((check_fwstate(pmlmepriv, _FW_LINKED))
1238 /*&& !MgntInitAdapterInProgress(pMgntInfo)*/) {
1239 /* if we raise bBusyTraffic in last watchdog, using lower threshold. */
1240 if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
1241 BusyThreshold = BusyThresholdLow;
1242
1243 if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > BusyThreshold ||
1244 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > BusyThreshold) {
1245 bBusyTraffic = true;
1246
1247 if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
1248 bRxBusyTraffic = true;
1249 else
1250 bTxBusyTraffic = true;
1251 }
1252
1253 /* Higher Tx/Rx data. */
1254 if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
1255 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > 4000) {
1256 bHigherBusyTraffic = true;
1257
1258 if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
1259 bHigherBusyRxTraffic = true;
1260 else
1261 bHigherBusyTxTraffic = true;
1262 }
1263
1264 /* check traffic for powersaving. */
1265 if (((pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod + pmlmepriv->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1266 (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)) {
1267 bEnterPS = false;
1268
1269 if (bBusyTraffic) {
1270 if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount <= 4)
1271 pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 4;
1272
1273 pmlmepriv->LinkDetectInfo.TrafficTransitionCount++;
1274
1275 if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount > 30/*TrafficTransitionLevel*/)
1276 pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 30;
1277 }
1278 } else {
1279 if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount >= 2)
1280 pmlmepriv->LinkDetectInfo.TrafficTransitionCount -= 2;
1281 else
1282 pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 0;
1283
1284 if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount == 0)
1285 bEnterPS = true;
1286 }
1287
1288 /* LeisurePS only work in infra mode. */
1289 if (bEnterPS) {
1290 if (!from_timer)
1291 LPS_Enter(padapter, "TRAFFIC_IDLE");
1292 } else {
1293 if (!from_timer)
1294 LPS_Leave(padapter, "TRAFFIC_BUSY");
1295 else
1296 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_TRAFFIC_BUSY, 1);
1297 }
1298 } else {
1299 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1300 int n_assoc_iface = 0;
1301
1302 if (check_fwstate(&dvobj->padapters->mlmepriv, WIFI_ASOC_STATE))
1303 n_assoc_iface++;
1304
1305 if (!from_timer && n_assoc_iface == 0)
1306 LPS_Leave(padapter, "NON_LINKED");
1307 }
1308
1309 pmlmepriv->LinkDetectInfo.NumRxOkInPeriod = 0;
1310 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod = 0;
1311 pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
1312 pmlmepriv->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
1313 pmlmepriv->LinkDetectInfo.bTxBusyTraffic = bTxBusyTraffic;
1314 pmlmepriv->LinkDetectInfo.bRxBusyTraffic = bRxBusyTraffic;
1315 pmlmepriv->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
1316 pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
1317 pmlmepriv->LinkDetectInfo.bHigherBusyTxTraffic = bHigherBusyTxTraffic;
1318
1319 return bEnterPS;
1320
1321 }
1322
dynamic_chk_wk_hdl(struct adapter * padapter)1323 static void dynamic_chk_wk_hdl(struct adapter *padapter)
1324 {
1325 struct mlme_priv *pmlmepriv;
1326
1327 pmlmepriv = &padapter->mlmepriv;
1328
1329 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
1330 expire_timeout_chk(padapter);
1331
1332 /* for debug purpose */
1333 _linked_info_dump(padapter);
1334 /* if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING|_FW_UNDER_SURVEY) ==false) */
1335 {
1336 linked_status_chk(padapter);
1337 traffic_status_watchdog(padapter, 0);
1338 }
1339 rtw_hal_dm_watchdog(padapter);
1340
1341 /* check_hw_pbc(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type); */
1342
1343 /* */
1344 /* BT-Coexist */
1345 /* */
1346 hal_btcoex_Handler(padapter);
1347
1348
1349 /* always call rtw_ps_processor() at last one. */
1350 if (is_primary_adapter(padapter))
1351 rtw_ps_processor(padapter);
1352 }
1353
1354 void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type);
lps_ctrl_wk_hdl(struct adapter * padapter,u8 lps_ctrl_type)1355 void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type)
1356 {
1357 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1358 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1359 u8 mstatus;
1360
1361 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
1362 check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
1363 return;
1364 }
1365
1366 switch (lps_ctrl_type) {
1367 case LPS_CTRL_SCAN:
1368 hal_btcoex_ScanNotify(padapter, true);
1369
1370 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1371 /* connect */
1372 LPS_Leave(padapter, "LPS_CTRL_SCAN");
1373 }
1374 break;
1375 case LPS_CTRL_JOINBSS:
1376 LPS_Leave(padapter, "LPS_CTRL_JOINBSS");
1377 break;
1378 case LPS_CTRL_CONNECT:
1379 mstatus = 1;/* connect */
1380 /* Reset LPS Setting */
1381 pwrpriv->LpsIdleCount = 0;
1382 rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
1383 rtw_btcoex_MediaStatusNotify(padapter, mstatus);
1384 break;
1385 case LPS_CTRL_DISCONNECT:
1386 mstatus = 0;/* disconnect */
1387 rtw_btcoex_MediaStatusNotify(padapter, mstatus);
1388 LPS_Leave(padapter, "LPS_CTRL_DISCONNECT");
1389 rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
1390 break;
1391 case LPS_CTRL_SPECIAL_PACKET:
1392 pwrpriv->DelayLPSLastTimeStamp = jiffies;
1393 hal_btcoex_SpecialPacketNotify(padapter, PACKET_DHCP);
1394 LPS_Leave(padapter, "LPS_CTRL_SPECIAL_PACKET");
1395 break;
1396 case LPS_CTRL_LEAVE:
1397 LPS_Leave(padapter, "LPS_CTRL_LEAVE");
1398 break;
1399 case LPS_CTRL_TRAFFIC_BUSY:
1400 LPS_Leave(padapter, "LPS_CTRL_TRAFFIC_BUSY");
1401 break;
1402 default:
1403 break;
1404 }
1405 }
1406
rtw_lps_ctrl_wk_cmd(struct adapter * padapter,u8 lps_ctrl_type,u8 enqueue)1407 u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue)
1408 {
1409 struct cmd_obj *ph2c;
1410 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1411 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1412 /* struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); */
1413 u8 res = _SUCCESS;
1414
1415 /* if (!pwrctrlpriv->bLeisurePs) */
1416 /* return res; */
1417
1418 if (enqueue) {
1419 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1420 if (!ph2c) {
1421 res = _FAIL;
1422 goto exit;
1423 }
1424
1425 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1426 if (!pdrvextra_cmd_parm) {
1427 kfree(ph2c);
1428 res = _FAIL;
1429 goto exit;
1430 }
1431
1432 pdrvextra_cmd_parm->ec_id = LPS_CTRL_WK_CID;
1433 pdrvextra_cmd_parm->type = lps_ctrl_type;
1434 pdrvextra_cmd_parm->size = 0;
1435 pdrvextra_cmd_parm->pbuf = NULL;
1436
1437 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1438
1439 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1440 } else {
1441 lps_ctrl_wk_hdl(padapter, lps_ctrl_type);
1442 }
1443
1444 exit:
1445 return res;
1446 }
1447
rtw_dm_in_lps_hdl(struct adapter * padapter)1448 static void rtw_dm_in_lps_hdl(struct adapter *padapter)
1449 {
1450 rtw_hal_set_hwreg(padapter, HW_VAR_DM_IN_LPS, NULL);
1451 }
1452
rtw_dm_in_lps_wk_cmd(struct adapter * padapter)1453 u8 rtw_dm_in_lps_wk_cmd(struct adapter *padapter)
1454 {
1455 struct cmd_obj *ph2c;
1456 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1457 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1458 u8 res = _SUCCESS;
1459
1460
1461 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1462 if (!ph2c) {
1463 res = _FAIL;
1464 goto exit;
1465 }
1466
1467 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1468 if (!pdrvextra_cmd_parm) {
1469 kfree(ph2c);
1470 res = _FAIL;
1471 goto exit;
1472 }
1473
1474 pdrvextra_cmd_parm->ec_id = DM_IN_LPS_WK_CID;
1475 pdrvextra_cmd_parm->type = 0;
1476 pdrvextra_cmd_parm->size = 0;
1477 pdrvextra_cmd_parm->pbuf = NULL;
1478
1479 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1480
1481 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1482
1483 exit:
1484 return res;
1485 }
1486
rtw_lps_change_dtim_hdl(struct adapter * padapter,u8 dtim)1487 static void rtw_lps_change_dtim_hdl(struct adapter *padapter, u8 dtim)
1488 {
1489 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1490
1491 if (dtim <= 0 || dtim > 16)
1492 return;
1493
1494 if (hal_btcoex_IsBtControlLps(padapter))
1495 return;
1496
1497 mutex_lock(&pwrpriv->lock);
1498
1499 pwrpriv->dtim = dtim;
1500
1501 if (pwrpriv->fw_current_in_ps_mode && (pwrpriv->pwr_mode > PS_MODE_ACTIVE)) {
1502 u8 ps_mode = pwrpriv->pwr_mode;
1503
1504 rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
1505 }
1506
1507 mutex_unlock(&pwrpriv->lock);
1508 }
1509
rtw_dm_ra_mask_hdl(struct adapter * padapter,struct sta_info * psta)1510 static void rtw_dm_ra_mask_hdl(struct adapter *padapter, struct sta_info *psta)
1511 {
1512 if (psta)
1513 set_sta_rate(padapter, psta);
1514 }
1515
rtw_dm_ra_mask_wk_cmd(struct adapter * padapter,u8 * psta)1516 u8 rtw_dm_ra_mask_wk_cmd(struct adapter *padapter, u8 *psta)
1517 {
1518 struct cmd_obj *ph2c;
1519 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1520 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1521 u8 res = _SUCCESS;
1522
1523 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1524 if (!ph2c) {
1525 res = _FAIL;
1526 goto exit;
1527 }
1528
1529 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1530 if (!pdrvextra_cmd_parm) {
1531 kfree(ph2c);
1532 res = _FAIL;
1533 goto exit;
1534 }
1535
1536 pdrvextra_cmd_parm->ec_id = DM_RA_MSK_WK_CID;
1537 pdrvextra_cmd_parm->type = 0;
1538 pdrvextra_cmd_parm->size = 0;
1539 pdrvextra_cmd_parm->pbuf = psta;
1540
1541 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1542
1543 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1544
1545 exit:
1546
1547 return res;
1548
1549 }
1550
rtw_ps_cmd(struct adapter * padapter)1551 u8 rtw_ps_cmd(struct adapter *padapter)
1552 {
1553 struct cmd_obj *ppscmd;
1554 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1555 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1556 u8 res = _SUCCESS;
1557 ppscmd = rtw_zmalloc(sizeof(struct cmd_obj));
1558 if (!ppscmd) {
1559 res = _FAIL;
1560 goto exit;
1561 }
1562
1563 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1564 if (!pdrvextra_cmd_parm) {
1565 kfree(ppscmd);
1566 res = _FAIL;
1567 goto exit;
1568 }
1569
1570 pdrvextra_cmd_parm->ec_id = POWER_SAVING_CTRL_WK_CID;
1571 pdrvextra_cmd_parm->type = 0;
1572 pdrvextra_cmd_parm->size = 0;
1573 pdrvextra_cmd_parm->pbuf = NULL;
1574 init_h2fwcmd_w_parm_no_rsp(ppscmd, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1575
1576 res = rtw_enqueue_cmd(pcmdpriv, ppscmd);
1577
1578 exit:
1579 return res;
1580 }
1581
1582 u32 g_wait_hiq_empty;
1583
rtw_chk_hi_queue_hdl(struct adapter * padapter)1584 static void rtw_chk_hi_queue_hdl(struct adapter *padapter)
1585 {
1586 struct sta_info *psta_bmc;
1587 struct sta_priv *pstapriv = &padapter->stapriv;
1588 unsigned long start = jiffies;
1589 u8 empty = false;
1590
1591 psta_bmc = rtw_get_bcmc_stainfo(padapter);
1592 if (!psta_bmc)
1593 return;
1594
1595 rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
1596
1597 while (!empty && jiffies_to_msecs(jiffies - start) < g_wait_hiq_empty) {
1598 msleep(100);
1599 rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
1600 }
1601
1602 if (psta_bmc->sleepq_len == 0) {
1603 if (empty == _SUCCESS) {
1604 bool update_tim = false;
1605
1606 if (pstapriv->tim_bitmap & BIT(0))
1607 update_tim = true;
1608
1609 pstapriv->tim_bitmap &= ~BIT(0);
1610 pstapriv->sta_dz_bitmap &= ~BIT(0);
1611
1612 if (update_tim)
1613 update_beacon(padapter, WLAN_EID_TIM, NULL, true);
1614 } else {/* re check again */
1615 rtw_chk_hi_queue_cmd(padapter);
1616 }
1617
1618 }
1619
1620 }
1621
rtw_chk_hi_queue_cmd(struct adapter * padapter)1622 u8 rtw_chk_hi_queue_cmd(struct adapter *padapter)
1623 {
1624 struct cmd_obj *ph2c;
1625 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1626 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1627 u8 res = _SUCCESS;
1628
1629 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1630 if (!ph2c) {
1631 res = _FAIL;
1632 goto exit;
1633 }
1634
1635 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1636 if (!pdrvextra_cmd_parm) {
1637 kfree(ph2c);
1638 res = _FAIL;
1639 goto exit;
1640 }
1641
1642 pdrvextra_cmd_parm->ec_id = CHECK_HIQ_WK_CID;
1643 pdrvextra_cmd_parm->type = 0;
1644 pdrvextra_cmd_parm->size = 0;
1645 pdrvextra_cmd_parm->pbuf = NULL;
1646
1647 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1648
1649 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1650
1651 exit:
1652 return res;
1653 }
1654
1655 struct btinfo {
1656 u8 cid;
1657 u8 len;
1658
1659 u8 bConnection:1;
1660 u8 bSCOeSCO:1;
1661 u8 bInQPage:1;
1662 u8 bACLBusy:1;
1663 u8 bSCOBusy:1;
1664 u8 bHID:1;
1665 u8 bA2DP:1;
1666 u8 bFTP:1;
1667
1668 u8 retry_cnt:4;
1669 u8 rsvd_34:1;
1670 u8 rsvd_35:1;
1671 u8 rsvd_36:1;
1672 u8 rsvd_37:1;
1673
1674 u8 rssi;
1675
1676 u8 rsvd_50:1;
1677 u8 rsvd_51:1;
1678 u8 rsvd_52:1;
1679 u8 rsvd_53:1;
1680 u8 rsvd_54:1;
1681 u8 rsvd_55:1;
1682 u8 eSCO_SCO:1;
1683 u8 Master_Slave:1;
1684
1685 u8 rsvd_6;
1686 u8 rsvd_7;
1687 };
1688
rtw_btinfo_hdl(struct adapter * adapter,u8 * buf,u16 buf_len)1689 static void rtw_btinfo_hdl(struct adapter *adapter, u8 *buf, u16 buf_len)
1690 {
1691 #define BTINFO_WIFI_FETCH 0x23
1692 #define BTINFO_BT_AUTO_RPT 0x27
1693 struct btinfo *info = (struct btinfo *)buf;
1694 u8 cmd_idx;
1695 u8 len;
1696
1697 cmd_idx = info->cid;
1698
1699 if (info->len > buf_len-2) {
1700 rtw_warn_on(1);
1701 len = buf_len-2;
1702 } else {
1703 len = info->len;
1704 }
1705
1706 /* transform BT-FW btinfo to WiFI-FW C2H format and notify */
1707 if (cmd_idx == BTINFO_WIFI_FETCH)
1708 buf[1] = 0;
1709 else if (cmd_idx == BTINFO_BT_AUTO_RPT)
1710 buf[1] = 2;
1711 hal_btcoex_BtInfoNotify(adapter, len+1, &buf[1]);
1712 }
1713
rtw_c2h_packet_wk_cmd(struct adapter * padapter,u8 * pbuf,u16 length)1714 u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length)
1715 {
1716 struct cmd_obj *ph2c;
1717 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1718 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1719 u8 res = _SUCCESS;
1720
1721 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1722 if (!ph2c) {
1723 res = _FAIL;
1724 goto exit;
1725 }
1726
1727 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1728 if (!pdrvextra_cmd_parm) {
1729 kfree(ph2c);
1730 res = _FAIL;
1731 goto exit;
1732 }
1733
1734 pdrvextra_cmd_parm->ec_id = C2H_WK_CID;
1735 pdrvextra_cmd_parm->type = 0;
1736 pdrvextra_cmd_parm->size = length;
1737 pdrvextra_cmd_parm->pbuf = pbuf;
1738
1739 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1740
1741 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1742
1743 exit:
1744 return res;
1745 }
1746
1747 /* dont call R/W in this function, beucase SDIO interrupt have claim host */
1748 /* or deadlock will happen and cause special-systemserver-died in android */
rtw_c2h_wk_cmd(struct adapter * padapter,u8 * c2h_evt)1749 u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt)
1750 {
1751 struct cmd_obj *ph2c;
1752 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1753 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1754 u8 res = _SUCCESS;
1755
1756 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1757 if (!ph2c) {
1758 res = _FAIL;
1759 goto exit;
1760 }
1761
1762 pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
1763 if (!pdrvextra_cmd_parm) {
1764 kfree(ph2c);
1765 res = _FAIL;
1766 goto exit;
1767 }
1768
1769 pdrvextra_cmd_parm->ec_id = C2H_WK_CID;
1770 pdrvextra_cmd_parm->type = 0;
1771 pdrvextra_cmd_parm->size = c2h_evt?16:0;
1772 pdrvextra_cmd_parm->pbuf = c2h_evt;
1773
1774 init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1775
1776 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1777
1778 exit:
1779
1780 return res;
1781 }
1782
c2h_wk_callback(struct work_struct * work)1783 static void c2h_wk_callback(struct work_struct *work)
1784 {
1785 struct evt_priv *evtpriv = container_of(work, struct evt_priv, c2h_wk);
1786 struct adapter *adapter = container_of(evtpriv, struct adapter, evtpriv);
1787 u8 *c2h_evt;
1788 c2h_id_filter ccx_id_filter = rtw_hal_c2h_id_filter_ccx(adapter);
1789
1790 evtpriv->c2h_wk_alive = true;
1791
1792 while (!rtw_cbuf_empty(evtpriv->c2h_queue)) {
1793 c2h_evt = (u8 *)rtw_cbuf_pop(evtpriv->c2h_queue);
1794 if (c2h_evt) {
1795 /* This C2H event is read, clear it */
1796 c2h_evt_clear(adapter);
1797 } else {
1798 c2h_evt = rtw_malloc(16);
1799 if (c2h_evt) {
1800 /* This C2H event is not read, read & clear now */
1801 if (c2h_evt_read_88xx(adapter, c2h_evt) != _SUCCESS) {
1802 kfree(c2h_evt);
1803 continue;
1804 }
1805 }
1806 }
1807
1808 /* Special pointer to trigger c2h_evt_clear only */
1809 if ((void *)c2h_evt == (void *)evtpriv)
1810 continue;
1811
1812 if (!rtw_hal_c2h_valid(adapter, c2h_evt)) {
1813 kfree(c2h_evt);
1814 continue;
1815 }
1816
1817 if (ccx_id_filter(c2h_evt)) {
1818 /* Handle CCX report here */
1819 rtw_hal_c2h_handler(adapter, c2h_evt);
1820 kfree(c2h_evt);
1821 } else {
1822 /* Enqueue into cmd_thread for others */
1823 rtw_c2h_wk_cmd(adapter, c2h_evt);
1824 }
1825 }
1826
1827 evtpriv->c2h_wk_alive = false;
1828 }
1829
rtw_drvextra_cmd_hdl(struct adapter * padapter,unsigned char * pbuf)1830 u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf)
1831 {
1832 struct drvextra_cmd_parm *pdrvextra_cmd;
1833
1834 if (!pbuf)
1835 return H2C_PARAMETERS_ERROR;
1836
1837 pdrvextra_cmd = (struct drvextra_cmd_parm *)pbuf;
1838
1839 switch (pdrvextra_cmd->ec_id) {
1840 case DYNAMIC_CHK_WK_CID:/* only primary padapter go to this cmd, but execute dynamic_chk_wk_hdl() for two interfaces */
1841 dynamic_chk_wk_hdl(padapter);
1842 break;
1843 case POWER_SAVING_CTRL_WK_CID:
1844 rtw_ps_processor(padapter);
1845 break;
1846 case LPS_CTRL_WK_CID:
1847 lps_ctrl_wk_hdl(padapter, (u8)pdrvextra_cmd->type);
1848 break;
1849 case DM_IN_LPS_WK_CID:
1850 rtw_dm_in_lps_hdl(padapter);
1851 break;
1852 case LPS_CHANGE_DTIM_CID:
1853 rtw_lps_change_dtim_hdl(padapter, (u8)pdrvextra_cmd->type);
1854 break;
1855 case CHECK_HIQ_WK_CID:
1856 rtw_chk_hi_queue_hdl(padapter);
1857 break;
1858 /* add for CONFIG_IEEE80211W, none 11w can use it */
1859 case RESET_SECURITYPRIV:
1860 rtw_reset_securitypriv(padapter);
1861 break;
1862 case FREE_ASSOC_RESOURCES:
1863 rtw_free_assoc_resources(padapter, 1);
1864 break;
1865 case C2H_WK_CID:
1866 rtw_hal_set_hwreg_with_buf(padapter, HW_VAR_C2H_HANDLE, pdrvextra_cmd->pbuf, pdrvextra_cmd->size);
1867 break;
1868 case DM_RA_MSK_WK_CID:
1869 rtw_dm_ra_mask_hdl(padapter, (struct sta_info *)pdrvextra_cmd->pbuf);
1870 break;
1871 case BTINFO_WK_CID:
1872 rtw_btinfo_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->size);
1873 break;
1874 default:
1875 break;
1876 }
1877
1878 if (pdrvextra_cmd->pbuf && pdrvextra_cmd->size > 0)
1879 kfree(pdrvextra_cmd->pbuf);
1880
1881 return H2C_SUCCESS;
1882 }
1883
rtw_survey_cmd_callback(struct adapter * padapter,struct cmd_obj * pcmd)1884 void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
1885 {
1886 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1887
1888 if (pcmd->res != H2C_SUCCESS) {
1889 /* TODO: cancel timer and do timeout handler directly... */
1890 _set_timer(&pmlmepriv->scan_to_timer, 1);
1891 }
1892
1893 /* free cmd */
1894 rtw_free_cmd_obj(pcmd);
1895 }
1896
rtw_disassoc_cmd_callback(struct adapter * padapter,struct cmd_obj * pcmd)1897 void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
1898 {
1899 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1900
1901 if (pcmd->res != H2C_SUCCESS) {
1902 spin_lock_bh(&pmlmepriv->lock);
1903 set_fwstate(pmlmepriv, _FW_LINKED);
1904 spin_unlock_bh(&pmlmepriv->lock);
1905
1906 return;
1907 }
1908 /* free cmd */
1909 rtw_free_cmd_obj(pcmd);
1910 }
1911
rtw_joinbss_cmd_callback(struct adapter * padapter,struct cmd_obj * pcmd)1912 void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
1913 {
1914 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1915
1916 if (pcmd->res != H2C_SUCCESS) {
1917 /* TODO: cancel timer and do timeout handler directly... */
1918 _set_timer(&pmlmepriv->assoc_timer, 1);
1919 }
1920
1921 rtw_free_cmd_obj(pcmd);
1922 }
1923
rtw_createbss_cmd_callback(struct adapter * padapter,struct cmd_obj * pcmd)1924 void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
1925 {
1926 struct sta_info *psta = NULL;
1927 struct wlan_network *pwlan = NULL;
1928 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1929 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)pcmd->parmbuf;
1930 struct wlan_network *tgt_network = &pmlmepriv->cur_network;
1931
1932 if (!pcmd->parmbuf)
1933 goto exit;
1934
1935 if (pcmd->res != H2C_SUCCESS)
1936 _set_timer(&pmlmepriv->assoc_timer, 1);
1937
1938 del_timer_sync(&pmlmepriv->assoc_timer);
1939
1940 spin_lock_bh(&pmlmepriv->lock);
1941
1942
1943 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1944 psta = rtw_get_stainfo(&padapter->stapriv, pnetwork->mac_address);
1945 if (!psta) {
1946 psta = rtw_alloc_stainfo(&padapter->stapriv, pnetwork->mac_address);
1947 if (!psta)
1948 goto createbss_cmd_fail;
1949 }
1950
1951 rtw_indicate_connect(padapter);
1952 } else {
1953 pwlan = rtw_alloc_network(pmlmepriv);
1954 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
1955 if (!pwlan) {
1956 pwlan = rtw_get_oldest_wlan_network(&pmlmepriv->scanned_queue);
1957 if (!pwlan) {
1958 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
1959 goto createbss_cmd_fail;
1960 }
1961 pwlan->last_scanned = jiffies;
1962 } else {
1963 list_add_tail(&pwlan->list, &pmlmepriv->scanned_queue.queue);
1964 }
1965
1966 pnetwork->length = get_wlan_bssid_ex_sz(pnetwork);
1967 memcpy(&pwlan->network, pnetwork, pnetwork->length);
1968 /* pwlan->fixed = true; */
1969
1970 /* list_add_tail(&(pwlan->list), &pmlmepriv->scanned_queue.queue); */
1971
1972 /* copy pdev_network information to pmlmepriv->cur_network */
1973 memcpy(&tgt_network->network, pnetwork, (get_wlan_bssid_ex_sz(pnetwork)));
1974
1975 /* reset ds_config */
1976 /* tgt_network->network.configuration.ds_config = (u32)rtw_ch2freq(pnetwork->configuration.ds_config); */
1977
1978 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
1979
1980 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
1981 /* we will set _FW_LINKED when there is one more sat to join us (rtw_stassoc_event_callback) */
1982
1983 }
1984
1985 createbss_cmd_fail:
1986
1987 spin_unlock_bh(&pmlmepriv->lock);
1988 exit:
1989 rtw_free_cmd_obj(pcmd);
1990 }
1991
rtw_setstaKey_cmdrsp_callback(struct adapter * padapter,struct cmd_obj * pcmd)1992 void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd)
1993 {
1994 struct sta_priv *pstapriv = &padapter->stapriv;
1995 struct set_stakey_rsp *psetstakey_rsp = (struct set_stakey_rsp *)(pcmd->rsp);
1996 struct sta_info *psta = rtw_get_stainfo(pstapriv, psetstakey_rsp->addr);
1997
1998 if (!psta)
1999 goto exit;
2000
2001 exit:
2002 rtw_free_cmd_obj(pcmd);
2003 }
2004
rtw_setassocsta_cmdrsp_callback(struct adapter * padapter,struct cmd_obj * pcmd)2005 void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd)
2006 {
2007 struct sta_priv *pstapriv = &padapter->stapriv;
2008 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2009 struct set_assocsta_parm *passocsta_parm = (struct set_assocsta_parm *)(pcmd->parmbuf);
2010 struct set_assocsta_rsp *passocsta_rsp = (struct set_assocsta_rsp *)(pcmd->rsp);
2011 struct sta_info *psta = rtw_get_stainfo(pstapriv, passocsta_parm->addr);
2012
2013 if (!psta)
2014 goto exit;
2015
2016 psta->aid = passocsta_rsp->cam_id;
2017 psta->mac_id = passocsta_rsp->cam_id;
2018
2019 spin_lock_bh(&pmlmepriv->lock);
2020
2021 if (check_fwstate(pmlmepriv, WIFI_MP_STATE) && check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
2022 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
2023
2024 set_fwstate(pmlmepriv, _FW_LINKED);
2025 spin_unlock_bh(&pmlmepriv->lock);
2026
2027 exit:
2028 rtw_free_cmd_obj(pcmd);
2029 }
2030