1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2017 Realtek Corporation.
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_RECV_C_
16
17 #include <drv_types.h>
18 #include <hal_data.h>
19
20 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
21 static void rtw_signal_stat_timer_hdl(void *ctx);
22
23 enum {
24 SIGNAL_STAT_CALC_PROFILE_0 = 0,
25 SIGNAL_STAT_CALC_PROFILE_1,
26 SIGNAL_STAT_CALC_PROFILE_2,
27 SIGNAL_STAT_CALC_PROFILE_MAX
28 };
29
30 u8 signal_stat_calc_profile[SIGNAL_STAT_CALC_PROFILE_MAX][3] = {
31 {4, 1}, /* Profile 0 => pre_stat : curr_stat = 4 : 1 */
32 {3, 7}, /* Profile 1 => pre_stat : curr_stat = 3 : 7 */
33 {0, 10} /* Profile 2 => pre_stat : curr_stat = 0 : 10 */
34 };
35
36 #ifndef RTW_SIGNAL_STATE_CALC_PROFILE
37 #define RTW_SIGNAL_STATE_CALC_PROFILE SIGNAL_STAT_CALC_PROFILE_1
38 #endif
39
40 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
41
42 u8 rtw_bridge_tunnel_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
43 u8 rtw_rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
44 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
45 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
46 #ifdef CONFIG_TDLS
47 static u8 SNAP_ETH_TYPE_TDLS[2] = {0x89, 0x0d};
48 #endif
49
_rtw_init_sta_recv_priv(struct sta_recv_priv * psta_recvpriv)50 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
51 {
52
53
54
55 _rtw_memset((u8 *)psta_recvpriv, 0, sizeof(struct sta_recv_priv));
56
57 _rtw_spinlock_init(&psta_recvpriv->lock);
58
59 /* for(i=0; i<MAX_RX_NUMBLKS; i++) */
60 /* _rtw_init_queue(&psta_recvpriv->blk_strms[i]); */
61
62 _rtw_init_queue(&psta_recvpriv->defrag_q);
63
64
65 }
66
_rtw_init_recv_priv(struct recv_priv * precvpriv,_adapter * padapter)67 sint _rtw_init_recv_priv(struct recv_priv *precvpriv, _adapter *padapter)
68 {
69 sint i;
70
71 union recv_frame *precvframe;
72 sint res = _SUCCESS;
73
74
75 /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */
76 /* _rtw_memset((unsigned char *)precvpriv, 0, sizeof (struct recv_priv)); */
77
78 _rtw_spinlock_init(&precvpriv->lock);
79
80 #ifdef CONFIG_RECV_THREAD_MODE
81 _rtw_init_sema(&precvpriv->recv_sema, 0);
82
83 #endif
84
85 _rtw_init_queue(&precvpriv->free_recv_queue);
86 _rtw_init_queue(&precvpriv->recv_pending_queue);
87 _rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
88
89 precvpriv->adapter = padapter;
90
91 precvpriv->free_recvframe_cnt = NR_RECVFRAME;
92
93 precvpriv->sink_udpport = 0;
94 precvpriv->pre_rtp_rxseq = 0;
95 precvpriv->cur_rtp_rxseq = 0;
96
97 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
98 precvpriv->store_law_data_flag = 1;
99 #else
100 precvpriv->store_law_data_flag = 0;
101 #endif
102
103 rtw_os_recv_resource_init(precvpriv, padapter);
104
105 precvpriv->pallocated_frame_buf = rtw_zvmalloc(NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
106
107 if (precvpriv->pallocated_frame_buf == NULL) {
108 res = _FAIL;
109 goto exit;
110 }
111 /* _rtw_memset(precvpriv->pallocated_frame_buf, 0, NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ); */
112
113 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
114 /* precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf + RXFRAME_ALIGN_SZ - */
115 /* ((SIZE_PTR) (precvpriv->pallocated_frame_buf) &(RXFRAME_ALIGN_SZ-1)); */
116
117 precvframe = (union recv_frame *) precvpriv->precv_frame_buf;
118
119
120 for (i = 0; i < NR_RECVFRAME ; i++) {
121 _rtw_init_listhead(&(precvframe->u.list));
122
123 rtw_list_insert_tail(&(precvframe->u.list), &(precvpriv->free_recv_queue.queue));
124
125 rtw_os_recv_resource_alloc(padapter, precvframe);
126
127 precvframe->u.hdr.len = 0;
128
129 precvframe->u.hdr.adapter = padapter;
130 precvframe++;
131
132 }
133
134 #ifdef CONFIG_USB_HCI
135
136 ATOMIC_SET(&(precvpriv->rx_pending_cnt), 1);
137
138 _rtw_init_sema(&precvpriv->allrxreturnevt, 0);
139
140 #endif
141
142 res = rtw_hal_init_recv_priv(padapter);
143
144 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
145 rtw_init_timer(&precvpriv->signal_stat_timer, padapter, rtw_signal_stat_timer_hdl, padapter);
146
147 precvpriv->signal_stat_sampling_interval = 2000; /* ms */
148 /* precvpriv->signal_stat_converging_constant = 5000; */ /* ms */
149
150 rtw_set_signal_stat_timer(precvpriv);
151 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
152
153 _rtw_memset(&precvpriv->ip_statistic, 0,
154 sizeof(struct rtw_ip_dbg_cnt_statistic));
155
156 exit:
157
158
159 return res;
160
161 }
162
163 void rtw_mfree_recv_priv_lock(struct recv_priv *precvpriv);
rtw_mfree_recv_priv_lock(struct recv_priv * precvpriv)164 void rtw_mfree_recv_priv_lock(struct recv_priv *precvpriv)
165 {
166 _rtw_spinlock_free(&precvpriv->lock);
167 #ifdef CONFIG_RECV_THREAD_MODE
168 _rtw_free_sema(&precvpriv->recv_sema);
169 #endif
170
171 _rtw_spinlock_free(&precvpriv->free_recv_queue.lock);
172 _rtw_spinlock_free(&precvpriv->recv_pending_queue.lock);
173
174 _rtw_spinlock_free(&precvpriv->free_recv_buf_queue.lock);
175
176 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
177 _rtw_spinlock_free(&precvpriv->recv_buf_pending_queue.lock);
178 #endif /* CONFIG_USE_USB_BUFFER_ALLOC_RX */
179 }
180
_rtw_free_recv_priv(struct recv_priv * precvpriv)181 void _rtw_free_recv_priv(struct recv_priv *precvpriv)
182 {
183 _adapter *padapter = precvpriv->adapter;
184
185
186 rtw_free_uc_swdec_pending_queue(padapter);
187
188 rtw_mfree_recv_priv_lock(precvpriv);
189
190 rtw_os_recv_resource_free(precvpriv);
191
192 if (precvpriv->pallocated_frame_buf)
193 rtw_vmfree(precvpriv->pallocated_frame_buf, NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
194
195 rtw_hal_free_recv_priv(padapter);
196
197
198 }
199
rtw_rframe_del_wfd_ie(union recv_frame * rframe,u8 ies_offset)200 bool rtw_rframe_del_wfd_ie(union recv_frame *rframe, u8 ies_offset)
201 {
202 #define DBG_RFRAME_DEL_WFD_IE 0
203 u8 *ies = rframe->u.hdr.rx_data + sizeof(struct rtw_ieee80211_hdr_3addr) + ies_offset;
204 uint ies_len_ori = rframe->u.hdr.len - (ies - rframe->u.hdr.rx_data);
205 uint ies_len;
206
207 ies_len = rtw_del_wfd_ie(ies, ies_len_ori, DBG_RFRAME_DEL_WFD_IE ? __func__ : NULL);
208 rframe->u.hdr.len -= ies_len_ori - ies_len;
209
210 return ies_len_ori != ies_len;
211 }
212
_rtw_alloc_recvframe(_queue * pfree_recv_queue)213 union recv_frame *_rtw_alloc_recvframe(_queue *pfree_recv_queue)
214 {
215
216 union recv_frame *precvframe;
217 _list *plist, *phead;
218 _adapter *padapter;
219 struct recv_priv *precvpriv;
220
221 if (_rtw_queue_empty(pfree_recv_queue) == _TRUE)
222 precvframe = NULL;
223 else {
224 phead = get_list_head(pfree_recv_queue);
225
226 plist = get_next(phead);
227
228 precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
229
230 rtw_list_delete(&precvframe->u.hdr.list);
231 padapter = precvframe->u.hdr.adapter;
232 if (padapter != NULL) {
233 precvpriv = &padapter->recvpriv;
234 if (pfree_recv_queue == &precvpriv->free_recv_queue)
235 precvpriv->free_recvframe_cnt--;
236 }
237 }
238
239
240 return precvframe;
241
242 }
243
rtw_alloc_recvframe(_queue * pfree_recv_queue)244 union recv_frame *rtw_alloc_recvframe(_queue *pfree_recv_queue)
245 {
246 _irqL irqL;
247 union recv_frame *precvframe;
248
249 _enter_critical_bh(&pfree_recv_queue->lock, &irqL);
250
251 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
252
253 _exit_critical_bh(&pfree_recv_queue->lock, &irqL);
254
255 return precvframe;
256 }
257
rtw_init_recvframe(union recv_frame * precvframe,struct recv_priv * precvpriv)258 void rtw_init_recvframe(union recv_frame *precvframe, struct recv_priv *precvpriv)
259 {
260 /* Perry: This can be removed */
261 _rtw_init_listhead(&precvframe->u.hdr.list);
262
263 precvframe->u.hdr.len = 0;
264 }
265
rtw_free_recvframe(union recv_frame * precvframe,_queue * pfree_recv_queue)266 int rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue)
267 {
268 _irqL irqL;
269 _adapter *padapter = precvframe->u.hdr.adapter;
270 struct recv_priv *precvpriv = &padapter->recvpriv;
271
272
273 #ifdef CONFIG_CONCURRENT_MODE
274 padapter = GET_PRIMARY_ADAPTER(padapter);
275 precvpriv = &padapter->recvpriv;
276 pfree_recv_queue = &precvpriv->free_recv_queue;
277 precvframe->u.hdr.adapter = padapter;
278 #endif
279
280
281 rtw_os_free_recvframe(precvframe);
282
283
284 _enter_critical_bh(&pfree_recv_queue->lock, &irqL);
285
286 rtw_list_delete(&(precvframe->u.hdr.list));
287
288 precvframe->u.hdr.len = 0;
289 precvframe->u.hdr.attrib.phy_info.physts_rpt_valid = _FALSE;
290
291 rtw_list_insert_tail(&(precvframe->u.hdr.list), get_list_head(pfree_recv_queue));
292
293 if (padapter != NULL) {
294 if (pfree_recv_queue == &precvpriv->free_recv_queue)
295 precvpriv->free_recvframe_cnt++;
296 }
297
298 _exit_critical_bh(&pfree_recv_queue->lock, &irqL);
299
300
301 return _SUCCESS;
302
303 }
304
305
306
307
_rtw_enqueue_recvframe(union recv_frame * precvframe,_queue * queue)308 sint _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
309 {
310
311 _adapter *padapter = precvframe->u.hdr.adapter;
312 struct recv_priv *precvpriv = &padapter->recvpriv;
313
314
315 /* _rtw_init_listhead(&(precvframe->u.hdr.list)); */
316 rtw_list_delete(&(precvframe->u.hdr.list));
317
318
319 rtw_list_insert_tail(&(precvframe->u.hdr.list), get_list_head(queue));
320
321 if (padapter != NULL) {
322 if (queue == &precvpriv->free_recv_queue)
323 precvpriv->free_recvframe_cnt++;
324 }
325
326
327 return _SUCCESS;
328 }
329
rtw_enqueue_recvframe(union recv_frame * precvframe,_queue * queue)330 sint rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
331 {
332 sint ret;
333 _irqL irqL;
334
335 /* _spinlock(&pfree_recv_queue->lock); */
336 _enter_critical_bh(&queue->lock, &irqL);
337 ret = _rtw_enqueue_recvframe(precvframe, queue);
338 /* _rtw_spinunlock(&pfree_recv_queue->lock); */
339 _exit_critical_bh(&queue->lock, &irqL);
340
341 return ret;
342 }
343
344 /*
345 sint rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
346 {
347 return rtw_free_recvframe(precvframe, queue);
348 }
349 */
350
351
352
353
354 /*
355 caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
356 pframequeue: defrag_queue : will be accessed in recv_thread (passive)
357
358 using spinlock to protect
359
360 */
361
rtw_free_recvframe_queue(_queue * pframequeue,_queue * pfree_recv_queue)362 void rtw_free_recvframe_queue(_queue *pframequeue, _queue *pfree_recv_queue)
363 {
364 union recv_frame *precvframe;
365 _list *plist, *phead;
366
367 _rtw_spinlock(&pframequeue->lock);
368
369 phead = get_list_head(pframequeue);
370 plist = get_next(phead);
371
372 while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
373 precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
374
375 plist = get_next(plist);
376
377 /* rtw_list_delete(&precvframe->u.hdr.list); */ /* will do this in rtw_free_recvframe() */
378
379 rtw_free_recvframe(precvframe, pfree_recv_queue);
380 }
381
382 _rtw_spinunlock(&pframequeue->lock);
383
384
385 }
386
rtw_free_uc_swdec_pending_queue(_adapter * adapter)387 u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter)
388 {
389 u32 cnt = 0;
390 union recv_frame *pending_frame;
391 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
392 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
393 cnt++;
394 }
395
396 if (cnt)
397 RTW_INFO(FUNC_ADPT_FMT" dequeue %d\n", FUNC_ADPT_ARG(adapter), cnt);
398
399 return cnt;
400 }
401
402
403 #ifndef CONFIG_RECVBUF_QUEUE_LOCK_BH
404 #ifdef CONFIG_SDIO_HCI
405 #define CONFIG_RECVBUF_QUEUE_LOCK_BH 1
406 #else
407 #define CONFIG_RECVBUF_QUEUE_LOCK_BH 0
408 #endif
409 #endif /* CONFIG_RECVBUF_QUEUE_LOCK_BH */
410
rtw_enqueue_recvbuf_to_head(struct recv_buf * precvbuf,_queue * queue)411 sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue)
412 {
413 _irqL irqL;
414
415 #if CONFIG_RECVBUF_QUEUE_LOCK_BH
416 _enter_critical_bh(&queue->lock, &irqL);
417 #else
418 _enter_critical_ex(&queue->lock, &irqL);
419 #endif
420
421 rtw_list_delete(&precvbuf->list);
422 rtw_list_insert_head(&precvbuf->list, get_list_head(queue));
423
424 #if CONFIG_RECVBUF_QUEUE_LOCK_BH
425 _exit_critical_bh(&queue->lock, &irqL);
426 #else
427 _exit_critical_ex(&queue->lock, &irqL);
428 #endif
429
430 return _SUCCESS;
431 }
432
rtw_enqueue_recvbuf(struct recv_buf * precvbuf,_queue * queue)433 sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue)
434 {
435 _irqL irqL;
436
437 #if CONFIG_RECVBUF_QUEUE_LOCK_BH
438 _enter_critical_bh(&queue->lock, &irqL);
439 #else
440 _enter_critical_ex(&queue->lock, &irqL);
441 #endif
442
443 rtw_list_delete(&precvbuf->list);
444
445 rtw_list_insert_tail(&precvbuf->list, get_list_head(queue));
446
447 #if CONFIG_RECVBUF_QUEUE_LOCK_BH
448 _exit_critical_bh(&queue->lock, &irqL);
449 #else
450 _exit_critical_ex(&queue->lock, &irqL);
451 #endif
452
453 return _SUCCESS;
454
455 }
456
rtw_dequeue_recvbuf(_queue * queue)457 struct recv_buf *rtw_dequeue_recvbuf(_queue *queue)
458 {
459 _irqL irqL;
460 struct recv_buf *precvbuf;
461 _list *plist, *phead;
462
463 #if CONFIG_RECVBUF_QUEUE_LOCK_BH
464 _enter_critical_bh(&queue->lock, &irqL);
465 #else
466 _enter_critical_ex(&queue->lock, &irqL);
467 #endif
468
469 if (_rtw_queue_empty(queue) == _TRUE)
470 precvbuf = NULL;
471 else {
472 phead = get_list_head(queue);
473
474 plist = get_next(phead);
475
476 precvbuf = LIST_CONTAINOR(plist, struct recv_buf, list);
477
478 rtw_list_delete(&precvbuf->list);
479
480 }
481
482 #if CONFIG_RECVBUF_QUEUE_LOCK_BH
483 _exit_critical_bh(&queue->lock, &irqL);
484 #else
485 _exit_critical_ex(&queue->lock, &irqL);
486 #endif
487
488 return precvbuf;
489
490 }
491
492 sint recvframe_chkmic(_adapter *adapter, union recv_frame *precvframe);
recvframe_chkmic(_adapter * adapter,union recv_frame * precvframe)493 sint recvframe_chkmic(_adapter *adapter, union recv_frame *precvframe)
494 {
495
496 sint i, res = _SUCCESS;
497 u32 datalen;
498 u8 miccode[8];
499 u8 bmic_err = _FALSE, brpt_micerror = _TRUE;
500 u8 *pframe, *payload, *pframemic;
501 u8 *mickey;
502 /* u8 *iv,rxdata_key_idx=0; */
503 struct sta_info *stainfo;
504 struct rx_pkt_attrib *prxattrib = &precvframe->u.hdr.attrib;
505 struct security_priv *psecuritypriv = &adapter->securitypriv;
506
507 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
508 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
509
510 stainfo = rtw_get_stainfo(&adapter->stapriv , &prxattrib->ta[0]);
511
512 if (prxattrib->encrypt == _TKIP_) {
513
514 /* calculate mic code */
515 if (stainfo != NULL) {
516 if (IS_MCAST(prxattrib->ra)) {
517 /* mickey=&psecuritypriv->dot118021XGrprxmickey.skey[0]; */
518 /* iv = precvframe->u.hdr.rx_data+prxattrib->hdrlen; */
519 /* rxdata_key_idx =( ((iv[3])>>6)&0x3) ; */
520 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
521
522 /* RTW_INFO("\n recvframe_chkmic: bcmc key psecuritypriv->dot118021XGrpKeyid(%d),pmlmeinfo->key_index(%d) ,recv key_id(%d)\n", */
523 /* psecuritypriv->dot118021XGrpKeyid,pmlmeinfo->key_index,rxdata_key_idx); */
524
525 if (psecuritypriv->binstallGrpkey == _FALSE) {
526 res = _FAIL;
527 RTW_INFO("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
528 goto exit;
529 }
530 } else {
531 mickey = &stainfo->dot11tkiprxmickey.skey[0];
532 }
533
534 datalen = precvframe->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len - prxattrib->icv_len - 8; /* icv_len included the mic code */
535 pframe = precvframe->u.hdr.rx_data;
536 payload = pframe + prxattrib->hdrlen + prxattrib->iv_len;
537
538
539 /* rtw_seccalctkipmic(&stainfo->dot11tkiprxmickey.skey[0],pframe,payload, datalen ,&miccode[0],(unsigned char)prxattrib->priority); */ /* care the length of the data */
540
541 rtw_seccalctkipmic(mickey, pframe, payload, datalen , &miccode[0], (unsigned char)prxattrib->priority); /* care the length of the data */
542
543 pframemic = payload + datalen;
544
545 bmic_err = _FALSE;
546
547 for (i = 0; i < 8; i++) {
548 if (miccode[i] != *(pframemic + i)) {
549 bmic_err = _TRUE;
550 }
551 }
552
553
554 if (bmic_err == _TRUE) {
555
556
557
558 /* double check key_index for some timing issue , */
559 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
560 if ((IS_MCAST(prxattrib->ra) == _TRUE) && (prxattrib->key_index != pmlmeinfo->key_index))
561 brpt_micerror = _FALSE;
562
563 if ((prxattrib->bdecrypted == _TRUE) && (brpt_micerror == _TRUE)) {
564 rtw_handle_tkip_mic_err(adapter, stainfo, (u8)IS_MCAST(prxattrib->ra));
565 RTW_INFO(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
566 } else {
567 RTW_INFO(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
568 }
569
570 res = _FAIL;
571
572 } else {
573 /* mic checked ok */
574 if ((psecuritypriv->bcheck_grpkey == _FALSE) && (IS_MCAST(prxattrib->ra) == _TRUE)) {
575 psecuritypriv->bcheck_grpkey = _TRUE;
576 }
577 }
578
579 }
580
581 recvframe_pull_tail(precvframe, 8);
582
583 }
584
585 exit:
586
587
588 return res;
589
590 }
591
592 /*#define DBG_RX_SW_DECRYPTOR*/
593
594 /* decrypt and set the ivlen,icvlen of the recv_frame */
595 union recv_frame *decryptor(_adapter *padapter, union recv_frame *precv_frame);
decryptor(_adapter * padapter,union recv_frame * precv_frame)596 union recv_frame *decryptor(_adapter *padapter, union recv_frame *precv_frame)
597 {
598
599 struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib;
600 struct security_priv *psecuritypriv = &padapter->securitypriv;
601 union recv_frame *return_packet = precv_frame;
602 u32 res = _SUCCESS;
603
604
605 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt);
606
607
608 if (prxattrib->encrypt > 0) {
609 u8 *iv = precv_frame->u.hdr.rx_data + prxattrib->hdrlen;
610 prxattrib->key_index = (((iv[3]) >> 6) & 0x3) ;
611
612 if (prxattrib->key_index > WEP_KEYS) {
613 RTW_INFO("prxattrib->key_index(%d) > WEP_KEYS\n", prxattrib->key_index);
614
615 switch (prxattrib->encrypt) {
616 case _WEP40_:
617 case _WEP104_:
618 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
619 break;
620 case _TKIP_:
621 case _AES_:
622 case _GCMP_:
623 case _GCMP_256_:
624 case _CCMP_256_:
625 default:
626 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
627 break;
628 }
629 }
630 }
631
632 if (prxattrib->encrypt && !prxattrib->bdecrypted) {
633 if (GetFrameType(get_recvframe_data(precv_frame)) == WIFI_DATA
634 #ifdef CONFIG_CONCURRENT_MODE
635 && !IS_MCAST(prxattrib->ra) /* bc/mc packets may use sw decryption for concurrent mode */
636 #endif
637 )
638 psecuritypriv->hw_decrypted = _FALSE;
639
640 #ifdef DBG_RX_SW_DECRYPTOR
641 RTW_INFO(ADPT_FMT" - sec_type:%s DO SW decryption\n",
642 ADPT_ARG(padapter), security_type_str(prxattrib->encrypt));
643 #endif
644
645 #ifdef DBG_RX_DECRYPTOR
646 RTW_INFO("[%s] %d:prxstat->bdecrypted:%d, prxattrib->encrypt:%d, Setting psecuritypriv->hw_decrypted = %d\n",
647 __FUNCTION__,
648 __LINE__,
649 prxattrib->bdecrypted,
650 prxattrib->encrypt,
651 psecuritypriv->hw_decrypted);
652 #endif
653
654 switch (prxattrib->encrypt) {
655 case _WEP40_:
656 case _WEP104_:
657 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_wep);
658 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
659 break;
660 case _TKIP_:
661 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_tkip);
662 res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
663 break;
664 case _AES_:
665 case _CCMP_256_:
666 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_aes);
667 res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
668 break;
669 case _GCMP_:
670 case _GCMP_256_:
671 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_gcmp);
672 res = rtw_gcmp_decrypt(padapter, (u8 *)precv_frame);
673 break;
674 #ifdef CONFIG_WAPI_SUPPORT
675 case _SMS4_:
676 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_wapi);
677 rtw_sms4_decrypt(padapter, (u8 *)precv_frame);
678 break;
679 #endif
680 default:
681 break;
682 }
683 } else if (prxattrib->bdecrypted == 1
684 && prxattrib->encrypt > 0
685 && (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_)
686 ) {
687 #if 0
688 if ((prxstat->icv == 1) && (prxattrib->encrypt != _AES_)) {
689 psecuritypriv->hw_decrypted = _FALSE;
690
691
692 rtw_free_recvframe(precv_frame, &padapter->recvpriv.free_recv_queue);
693
694 return_packet = NULL;
695
696 } else
697 #endif
698 {
699 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_hw);
700
701 psecuritypriv->hw_decrypted = _TRUE;
702 #ifdef DBG_RX_DECRYPTOR
703 RTW_INFO("[%s] %d:prxstat->bdecrypted:%d, prxattrib->encrypt:%d, Setting psecuritypriv->hw_decrypted = %d\n",
704 __FUNCTION__,
705 __LINE__,
706 prxattrib->bdecrypted,
707 prxattrib->encrypt,
708 psecuritypriv->hw_decrypted);
709
710 #endif
711 }
712 } else {
713 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_unknown);
714 #ifdef DBG_RX_DECRYPTOR
715 RTW_INFO("[%s] %d:prxstat->bdecrypted:%d, prxattrib->encrypt:%d, Setting psecuritypriv->hw_decrypted = %d\n",
716 __FUNCTION__,
717 __LINE__,
718 prxattrib->bdecrypted,
719 prxattrib->encrypt,
720 psecuritypriv->hw_decrypted);
721 #endif
722 }
723
724 #ifdef CONFIG_RTW_MESH
725 if (res != _FAIL
726 && !prxattrib->amsdu
727 && prxattrib->mesh_ctrl_present)
728 res = rtw_mesh_rx_validate_mctrl_non_amsdu(padapter, precv_frame);
729 #endif
730
731 if (res == _FAIL) {
732 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
733 return_packet = NULL;
734 } else
735 prxattrib->bdecrypted = _TRUE;
736 /* recvframe_chkmic(adapter, precv_frame); */ /* move to recvframme_defrag function */
737
738
739 return return_packet;
740
741 }
742 /* ###set the security information in the recv_frame */
743 union recv_frame *portctrl(_adapter *adapter, union recv_frame *precv_frame);
portctrl(_adapter * adapter,union recv_frame * precv_frame)744 union recv_frame *portctrl(_adapter *adapter, union recv_frame *precv_frame)
745 {
746 u8 *psta_addr = NULL;
747 u8 *ptr;
748 uint auth_alg;
749 struct recv_frame_hdr *pfhdr;
750 struct sta_info *psta;
751 struct sta_priv *pstapriv ;
752 union recv_frame *prtnframe;
753 u16 ether_type = 0;
754 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
755 struct rx_pkt_attrib *pattrib;
756
757
758 pstapriv = &adapter->stapriv;
759
760 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
761
762 ptr = get_recvframe_data(precv_frame);
763 pfhdr = &precv_frame->u.hdr;
764 pattrib = &pfhdr->attrib;
765 psta_addr = pattrib->ta;
766
767 prtnframe = NULL;
768
769 psta = rtw_get_stainfo(pstapriv, psta_addr);
770
771
772 if (auth_alg == dot11AuthAlgrthm_8021X) {
773 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
774 /* blocked */
775 /* only accept EAPOL frame */
776
777 prtnframe = precv_frame;
778
779 /* get ether_type */
780 ptr = ptr + pfhdr->attrib.hdrlen + pfhdr->attrib.iv_len + LLC_HEADER_SIZE;
781 _rtw_memcpy(ðer_type, ptr, 2);
782 ether_type = ntohs((unsigned short)ether_type);
783
784 if (ether_type == eapol_type)
785 prtnframe = precv_frame;
786 else {
787 /* free this frame */
788 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
789 prtnframe = NULL;
790 }
791 } else {
792 /* allowed */
793 /* check decryption status, and decrypt the frame if needed */
794
795
796 prtnframe = precv_frame;
797 /* check is the EAPOL frame or not (Rekey) */
798 /* if(ether_type == eapol_type){ */
799 /* check Rekey */
800
801 /* prtnframe=precv_frame; */
802 /* } */
803 }
804 } else
805 prtnframe = precv_frame;
806
807
808 return prtnframe;
809
810 }
811
812 /* VALID_PN_CHK
813 * Return true when PN is legal, otherwise false.
814 * Legal PN:
815 * 1. If old PN is 0, any PN is legal
816 * 2. PN > old PN
817 */
818 #define PN_LESS_CHK(a, b) (((a-b) & 0x800000000000) != 0)
819 #define VALID_PN_CHK(new, old) (((old) == 0) || PN_LESS_CHK(old, new))
820 #define CCMPH_2_KEYID(ch) (((ch) & 0x00000000c0000000) >> 30)
821 sint recv_ucast_pn_decache(union recv_frame *precv_frame);
recv_ucast_pn_decache(union recv_frame * precv_frame)822 sint recv_ucast_pn_decache(union recv_frame *precv_frame)
823 {
824 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
825 struct sta_info *sta = precv_frame->u.hdr.psta;
826 struct stainfo_rxcache *prxcache = &sta->sta_recvpriv.rxcache;
827 u8 *pdata = precv_frame->u.hdr.rx_data;
828 sint tid = precv_frame->u.hdr.attrib.priority;
829 u64 tmp_iv_hdr = 0;
830 u64 curr_pn = 0, pkt_pn = 0;
831
832 if (tid > 15)
833 return _FAIL;
834
835 if (pattrib->encrypt == _AES_) {
836 tmp_iv_hdr = le64_to_cpu(*(u64*)(pdata + pattrib->hdrlen));
837 pkt_pn = CCMPH_2_PN(tmp_iv_hdr);
838 tmp_iv_hdr = le64_to_cpu(*(u64*)prxcache->iv[tid]);
839 curr_pn = CCMPH_2_PN(tmp_iv_hdr);
840
841 if (!VALID_PN_CHK(pkt_pn, curr_pn)) {
842 /* return _FAIL; */
843 } else {
844 prxcache->last_tid = tid;
845 _rtw_memcpy(prxcache->iv[tid],
846 (pdata + pattrib->hdrlen),
847 sizeof(prxcache->iv[tid]));
848 }
849 }
850
851 return _SUCCESS;
852 }
853
854 sint recv_bcast_pn_decache(union recv_frame *precv_frame);
recv_bcast_pn_decache(union recv_frame * precv_frame)855 sint recv_bcast_pn_decache(union recv_frame *precv_frame)
856 {
857 _adapter *padapter = precv_frame->u.hdr.adapter;
858 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
859 struct security_priv *psecuritypriv = &padapter->securitypriv;
860 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
861 u8 *pdata = precv_frame->u.hdr.rx_data;
862 u64 tmp_iv_hdr = 0;
863 u64 curr_pn = 0, pkt_pn = 0;
864 u8 key_id;
865
866 if ((pattrib->encrypt == _AES_) &&
867 (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)) {
868
869 tmp_iv_hdr = le64_to_cpu(*(u64*)(pdata + pattrib->hdrlen));
870 key_id = CCMPH_2_KEYID(tmp_iv_hdr);
871 pkt_pn = CCMPH_2_PN(tmp_iv_hdr);
872
873 curr_pn = le64_to_cpu(*(u64*)psecuritypriv->iv_seq[key_id]);
874 curr_pn &= 0x0000ffffffffffff;
875
876 if (!VALID_PN_CHK(pkt_pn, curr_pn))
877 return _FAIL;
878
879 *(u64*)psecuritypriv->iv_seq[key_id] = cpu_to_le64(pkt_pn);
880 }
881
882 return _SUCCESS;
883 }
884
recv_decache(union recv_frame * precv_frame)885 sint recv_decache(union recv_frame *precv_frame)
886 {
887 struct sta_info *psta = precv_frame->u.hdr.psta;
888 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
889 _adapter *adapter = psta->padapter;
890 sint tid = pattrib->priority;
891 u16 seq_ctrl = ((precv_frame->u.hdr.attrib.seq_num & 0xffff) << 4) |
892 (precv_frame->u.hdr.attrib.frag_num & 0xf);
893 u16 *prxseq;
894
895 if (tid > 15)
896 return _FAIL;
897
898 if (pattrib->qos) {
899 if (IS_MCAST(pattrib->ra))
900 prxseq = &psta->sta_recvpriv.bmc_tid_rxseq[tid];
901 else
902 prxseq = &psta->sta_recvpriv.rxcache.tid_rxseq[tid];
903 } else {
904 if (IS_MCAST(pattrib->ra)) {
905 prxseq = &psta->sta_recvpriv.nonqos_bmc_rxseq;
906 #ifdef DBG_RX_SEQ
907 RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" nonqos bmc seq_num:%d\n"
908 , FUNC_ADPT_ARG(adapter), pattrib->seq_num);
909 #endif
910
911 } else {
912 prxseq = &psta->sta_recvpriv.nonqos_rxseq;
913 #ifdef DBG_RX_SEQ
914 RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" nonqos seq_num:%d\n"
915 , FUNC_ADPT_ARG(adapter), pattrib->seq_num);
916 #endif
917 }
918 }
919
920 if (seq_ctrl == *prxseq) {
921 /* for non-AMPDU case */
922 psta->sta_stats.duplicate_cnt++;
923
924 if (psta->sta_stats.duplicate_cnt % 100 == 0)
925 RTW_INFO("%s: tid=%u seq=%d frag=%d\n", __func__
926 , tid, precv_frame->u.hdr.attrib.seq_num
927 , precv_frame->u.hdr.attrib.frag_num);
928
929 #ifdef DBG_RX_DROP_FRAME
930 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" recv_decache _FAIL for sta="MAC_FMT"\n"
931 , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->cmn.mac_addr));
932 #endif
933 return _FAIL;
934 }
935 *prxseq = seq_ctrl;
936
937 return _SUCCESS;
938 }
939
process_pwrbit_data(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * psta)940 void process_pwrbit_data(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *psta)
941 {
942 #ifdef CONFIG_AP_MODE
943 unsigned char pwrbit;
944 u8 *ptr = precv_frame->u.hdr.rx_data;
945
946 pwrbit = GetPwrMgt(ptr);
947
948 if (pwrbit) {
949 if (!(psta->state & WIFI_SLEEP_STATE)) {
950 /* psta->state |= WIFI_SLEEP_STATE; */
951 /* rtw_tim_map_set(padapter, pstapriv->sta_dz_bitmap, BIT(psta->cmn.aid)); */
952
953 stop_sta_xmit(padapter, psta);
954 /* RTW_INFO_DUMP("to sleep, sta_dz_bitmap=", pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len); */
955 }
956 } else {
957 if (psta->state & WIFI_SLEEP_STATE) {
958 /* psta->state ^= WIFI_SLEEP_STATE; */
959 /* rtw_tim_map_clear(padapter, pstapriv->sta_dz_bitmap, BIT(psta->cmn.aid)); */
960
961 wakeup_sta_to_xmit(padapter, psta, ALL_FRAME);
962 /* RTW_INFO_DUMP("to wakeup, sta_dz_bitmap=", pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len); */
963 }
964 }
965 #endif
966 }
967
process_wmmps_data(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * psta)968 void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *psta)
969 {
970 #ifdef CONFIG_AP_MODE
971 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
972
973 #ifdef CONFIG_TDLS
974 if (!(psta->tdls_sta_state & TDLS_LINKED_STATE)) {
975 #endif /* CONFIG_TDLS */
976
977 if (!psta->qos_option)
978 return;
979
980 if (!(psta->qos_info & 0xf))
981 return;
982
983 #ifdef CONFIG_TDLS
984 }
985 #endif /* CONFIG_TDLS */
986
987 if (psta->state & WIFI_SLEEP_STATE) {
988 u8 wmmps_ac = 0;
989
990 switch (pattrib->priority) {
991 case 1:
992 case 2:
993 wmmps_ac = psta->uapsd_bk & BIT(1);
994 break;
995 case 4:
996 case 5:
997 wmmps_ac = psta->uapsd_vi & BIT(1);
998 break;
999 case 6:
1000 case 7:
1001 wmmps_ac = psta->uapsd_vo & BIT(1);
1002 break;
1003 case 0:
1004 case 3:
1005 default:
1006 wmmps_ac = psta->uapsd_be & BIT(1);
1007 break;
1008 }
1009
1010 if (wmmps_ac) {
1011 if (psta->sleepq_ac_len > 0) {
1012 /* process received triggered frame */
1013 xmit_delivery_enabled_frames(padapter, psta);
1014 } else {
1015 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (=1) */
1016 issue_qos_nulldata(padapter, psta->cmn.mac_addr, (u16)pattrib->priority, 0, 0, 0);
1017 }
1018 }
1019
1020 }
1021
1022
1023 #endif
1024
1025 }
1026
1027 #ifdef CONFIG_TDLS
OnTDLS(_adapter * adapter,union recv_frame * precv_frame)1028 sint OnTDLS(_adapter *adapter, union recv_frame *precv_frame)
1029 {
1030 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1031 sint ret = _SUCCESS;
1032 u8 *paction = get_recvframe_data(precv_frame);
1033 u8 category_field = 1;
1034 #ifdef CONFIG_WFD
1035 u8 WFA_OUI[3] = { 0x50, 0x6f, 0x9a };
1036 #endif /* CONFIG_WFD */
1037 struct tdls_info *ptdlsinfo = &(adapter->tdlsinfo);
1038 u8 *ptr = precv_frame->u.hdr.rx_data;
1039 struct sta_priv *pstapriv = &(adapter->stapriv);
1040 struct sta_info *ptdls_sta = NULL;
1041
1042 /* point to action field */
1043 paction += pattrib->hdrlen
1044 + pattrib->iv_len
1045 + SNAP_SIZE
1046 + ETH_TYPE_LEN
1047 + PAYLOAD_TYPE_LEN
1048 + category_field;
1049
1050 RTW_INFO("[TDLS] Recv %s from "MAC_FMT" with SeqNum = %d\n", rtw_tdls_action_txt(*paction), MAC_ARG(pattrib->src), GetSequence(get_recvframe_data(precv_frame)));
1051
1052 if (hal_chk_wl_func(adapter, WL_FUNC_TDLS) == _FALSE) {
1053 RTW_INFO("Ignore tdls frame since hal doesn't support tdls\n");
1054 ret = _FAIL;
1055 return ret;
1056 }
1057
1058 if (rtw_is_tdls_enabled(adapter) == _FALSE) {
1059 RTW_INFO("recv tdls frame, "
1060 "but tdls haven't enabled\n");
1061 ret = _FAIL;
1062 return ret;
1063 }
1064
1065 ptdls_sta = rtw_get_stainfo(pstapriv, get_sa(ptr));
1066 if (ptdls_sta == NULL) {
1067 switch (*paction) {
1068 case TDLS_SETUP_REQUEST:
1069 case TDLS_DISCOVERY_REQUEST:
1070 break;
1071 default:
1072 RTW_INFO("[TDLS] %s - Direct Link Peer = "MAC_FMT" not found for action = %d\n", __func__, MAC_ARG(get_sa(ptr)), *paction);
1073 ret = _FAIL;
1074 goto exit;
1075 }
1076 }
1077
1078 switch (*paction) {
1079 case TDLS_SETUP_REQUEST:
1080 ret = On_TDLS_Setup_Req(adapter, precv_frame, ptdls_sta);
1081 break;
1082 case TDLS_SETUP_RESPONSE:
1083 ret = On_TDLS_Setup_Rsp(adapter, precv_frame, ptdls_sta);
1084 break;
1085 case TDLS_SETUP_CONFIRM:
1086 ret = On_TDLS_Setup_Cfm(adapter, precv_frame, ptdls_sta);
1087 break;
1088 case TDLS_TEARDOWN:
1089 ret = On_TDLS_Teardown(adapter, precv_frame, ptdls_sta);
1090 break;
1091 case TDLS_DISCOVERY_REQUEST:
1092 ret = On_TDLS_Dis_Req(adapter, precv_frame);
1093 break;
1094 case TDLS_PEER_TRAFFIC_INDICATION:
1095 ret = On_TDLS_Peer_Traffic_Indication(adapter, precv_frame, ptdls_sta);
1096 break;
1097 case TDLS_PEER_TRAFFIC_RESPONSE:
1098 ret = On_TDLS_Peer_Traffic_Rsp(adapter, precv_frame, ptdls_sta);
1099 break;
1100 #ifdef CONFIG_TDLS_CH_SW
1101 case TDLS_CHANNEL_SWITCH_REQUEST:
1102 ret = On_TDLS_Ch_Switch_Req(adapter, precv_frame, ptdls_sta);
1103 break;
1104 case TDLS_CHANNEL_SWITCH_RESPONSE:
1105 ret = On_TDLS_Ch_Switch_Rsp(adapter, precv_frame, ptdls_sta);
1106 break;
1107 #endif
1108 #ifdef CONFIG_WFD
1109 /* First byte of WFA OUI */
1110 case 0x50:
1111 if (_rtw_memcmp(WFA_OUI, paction, 3)) {
1112 /* Probe request frame */
1113 if (*(paction + 3) == 0x04) {
1114 /* WFDTDLS: for sigma test, do not setup direct link automatically */
1115 ptdlsinfo->dev_discovered = _TRUE;
1116 RTW_INFO("recv tunneled probe request frame\n");
1117 issue_tunneled_probe_rsp(adapter, precv_frame);
1118 }
1119 /* Probe response frame */
1120 if (*(paction + 3) == 0x05) {
1121 /* WFDTDLS: for sigma test, do not setup direct link automatically */
1122 ptdlsinfo->dev_discovered = _TRUE;
1123 RTW_INFO("recv tunneled probe response frame\n");
1124 }
1125 }
1126 break;
1127 #endif /* CONFIG_WFD */
1128 default:
1129 RTW_INFO("receive TDLS frame %d but not support\n", *paction);
1130 ret = _FAIL;
1131 break;
1132 }
1133
1134 exit:
1135 return ret;
1136
1137 }
1138
rtw_tdls_rx_data_validate_hdr(_adapter * adapter,union recv_frame * precv_frame,struct sta_info ** psta)1139 sint rtw_tdls_rx_data_validate_hdr(
1140 _adapter *adapter,
1141 union recv_frame *precv_frame,
1142 struct sta_info **psta
1143 )
1144 {
1145 u8 *ptr = precv_frame->u.hdr.rx_data;
1146 sint ret = _SUCCESS;
1147 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1148 struct sta_priv *pstapriv = &adapter->stapriv;
1149 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1150 u8 *mybssid = get_bssid(pmlmepriv);
1151 u8 *myhwaddr = adapter_mac_addr(adapter);
1152 u8 *sta_addr = pattrib->ta;
1153 sint bmcast = IS_MCAST(pattrib->dst);
1154
1155 struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
1156 #ifdef CONFIG_TDLS_CH_SW
1157 struct tdls_ch_switch *pchsw_info = &ptdlsinfo->chsw_info;
1158 #endif
1159 struct sta_info *ptdls_sta = NULL;
1160 u8 *psnap_type = ptr + pattrib->hdrlen + pattrib->iv_len + SNAP_SIZE;
1161 /* frame body located after [+2]: ether-type, [+1]: payload type */
1162 u8 *pframe_body = psnap_type + 2 + 1;
1163
1164 *psta = ptdls_sta = rtw_get_stainfo(pstapriv, pattrib->ta);
1165 if (ptdls_sta == NULL) {
1166 ret = _FAIL;
1167 goto exit;
1168 } else if (ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE) {
1169 /* filter packets that SA is myself or multicast or broadcast */
1170 if (_rtw_memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
1171 ret = _FAIL;
1172 goto exit;
1173 }
1174 /* da should be for me */
1175 if ((!_rtw_memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
1176 ret = _FAIL;
1177 goto exit;
1178 }
1179 /* check BSSID */
1180 if (_rtw_memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
1181 _rtw_memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
1182 (!_rtw_memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
1183 ret = _FAIL;
1184 goto exit;
1185 }
1186
1187 #ifdef CONFIG_TDLS_CH_SW
1188 if (ATOMIC_READ(&pchsw_info->chsw_on) == _TRUE) {
1189 if (adapter->mlmeextpriv.cur_channel != rtw_get_oper_ch(adapter)) {
1190 pchsw_info->ch_sw_state |= TDLS_PEER_AT_OFF_STATE;
1191 if (!(pchsw_info->ch_sw_state & TDLS_CH_SW_INITIATOR_STATE))
1192 _cancel_timer_ex(&ptdls_sta->ch_sw_timer);
1193 /* On_TDLS_Peer_Traffic_Rsp(adapter, precv_frame); */
1194 }
1195 }
1196 #endif
1197
1198 /* process UAPSD tdls sta */
1199 process_pwrbit_data(adapter, precv_frame, ptdls_sta);
1200
1201 /* if NULL-frame, check pwrbit */
1202 if ((get_frame_sub_type(ptr) & WIFI_DATA_NULL) == WIFI_DATA_NULL) {
1203 /* NULL-frame with pwrbit=1, buffer_STA should buffer frames for sleep_STA */
1204 if (GetPwrMgt(ptr)) {
1205 /* it would be triggered when we are off channel and receiving NULL DATA */
1206 /* we can confirm that peer STA is at off channel */
1207 RTW_INFO("TDLS: recv peer null frame with pwr bit 1\n");
1208 /* ptdls_sta->tdls_sta_state|=TDLS_PEER_SLEEP_STATE; */
1209 }
1210
1211 /* TODO: Updated BSSID's seq. */
1212 /* RTW_INFO("drop Null Data\n"); */
1213 ptdls_sta->tdls_sta_state &= ~(TDLS_WAIT_PTR_STATE);
1214 ret = _FAIL;
1215 goto exit;
1216 }
1217
1218 /* receive some of all TDLS management frames, process it at ON_TDLS */
1219 if (_rtw_memcmp(psnap_type, SNAP_ETH_TYPE_TDLS, 2)) {
1220 ret = OnTDLS(adapter, precv_frame);
1221 goto exit;
1222 }
1223
1224 if ((get_frame_sub_type(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE)
1225 process_wmmps_data(adapter, precv_frame, ptdls_sta);
1226
1227 ptdls_sta->tdls_sta_state &= ~(TDLS_WAIT_PTR_STATE);
1228
1229 }
1230
1231 exit:
1232 return ret;
1233 }
1234 #endif /* CONFIG_TDLS */
1235
count_rx_stats(_adapter * padapter,union recv_frame * prframe,struct sta_info * sta)1236 void count_rx_stats(_adapter *padapter, union recv_frame *prframe, struct sta_info *sta)
1237 {
1238 int sz;
1239 struct sta_info *psta = NULL;
1240 struct stainfo_stats *pstats = NULL;
1241 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
1242 struct recv_priv *precvpriv = &padapter->recvpriv;
1243
1244 sz = get_recvframe_len(prframe);
1245 precvpriv->rx_bytes += sz;
1246
1247 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
1248
1249 if ((!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst)))
1250 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
1251
1252 if (sta)
1253 psta = sta;
1254 else
1255 psta = prframe->u.hdr.psta;
1256
1257 if (psta) {
1258 u8 is_ra_bmc = IS_MCAST(pattrib->ra);
1259
1260 pstats = &psta->sta_stats;
1261
1262 pstats->last_rx_time = rtw_get_current_time();
1263 pstats->rx_data_pkts++;
1264 pstats->rx_bytes += sz;
1265 if (is_broadcast_mac_addr(pattrib->ra)) {
1266 pstats->rx_data_bc_pkts++;
1267 pstats->rx_bc_bytes += sz;
1268 } else if (is_ra_bmc) {
1269 pstats->rx_data_mc_pkts++;
1270 pstats->rx_mc_bytes += sz;
1271 }
1272
1273 if (!is_ra_bmc) {
1274 pstats->rxratecnt[pattrib->data_rate]++;
1275 /*record rx packets for every tid*/
1276 pstats->rx_data_qos_pkts[pattrib->priority]++;
1277 }
1278 #ifdef CONFIG_DYNAMIC_SOML
1279 rtw_dyn_soml_byte_update(padapter, pattrib->data_rate, sz);
1280 #endif
1281 #if defined(CONFIG_CHECK_LEAVE_LPS) && defined(CONFIG_LPS_CHK_BY_TP)
1282 if (adapter_to_pwrctl(padapter)->lps_chk_by_tp)
1283 traffic_check_for_leave_lps_by_tp(padapter, _FALSE, psta);
1284 #endif /* CONFIG_LPS */
1285
1286 }
1287
1288 #ifdef CONFIG_CHECK_LEAVE_LPS
1289 #ifdef CONFIG_LPS_CHK_BY_TP
1290 if (!adapter_to_pwrctl(padapter)->lps_chk_by_tp)
1291 #endif
1292 traffic_check_for_leave_lps(padapter, _FALSE, 0);
1293 #endif /* CONFIG_CHECK_LEAVE_LPS */
1294
1295 }
1296
rtw_sta_rx_data_validate_hdr(_adapter * adapter,union recv_frame * rframe,struct sta_info ** sta)1297 int rtw_sta_rx_data_validate_hdr(_adapter *adapter, union recv_frame *rframe, struct sta_info **sta)
1298 {
1299 struct sta_priv *stapriv = &adapter->stapriv;
1300 u8 *mybssid = get_bssid(&adapter->mlmepriv);
1301 u8 *myhwaddr = adapter_mac_addr(adapter);
1302 struct rx_pkt_attrib *rattrib = &rframe->u.hdr.attrib;
1303 u8 *whdr = get_recvframe_data(rframe);
1304 u8 is_ra_bmc = IS_MCAST(GetAddr1Ptr(whdr)) ? 1 : 0;
1305 sint ret = _FAIL;
1306
1307 if (rattrib->to_fr_ds == 0) {
1308 _rtw_memcpy(rattrib->ra, GetAddr1Ptr(whdr), ETH_ALEN);
1309 _rtw_memcpy(rattrib->ta, get_addr2_ptr(whdr), ETH_ALEN);
1310 _rtw_memcpy(rattrib->dst, GetAddr1Ptr(whdr), ETH_ALEN);
1311 _rtw_memcpy(rattrib->src, get_addr2_ptr(whdr), ETH_ALEN);
1312 _rtw_memcpy(rattrib->bssid, GetAddr3Ptr(whdr), ETH_ALEN);
1313
1314 #ifdef CONFIG_TDLS
1315 if (adapter->tdlsinfo.link_established == _TRUE)
1316 ret = rtw_tdls_rx_data_validate_hdr(adapter, rframe, sta);
1317 else
1318 #endif
1319 {
1320 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
1321 if (!_rtw_memcmp(rattrib->bssid, rattrib->src, ETH_ALEN))
1322 goto exit;
1323
1324 *sta = rtw_get_stainfo(stapriv, get_addr2_ptr(whdr));
1325 if (*sta)
1326 ret = _SUCCESS;
1327 }
1328 goto exit;
1329 }
1330
1331 if (!(MLME_STATE(adapter) & (WIFI_ASOC_STATE | WIFI_UNDER_LINKING))) {
1332 if (!is_ra_bmc) {
1333 /* for AP multicast issue , modify by yiwei */
1334 static systime send_issue_deauth_time = 0;
1335
1336 /* RTW_INFO("After send deauth , %u ms has elapsed.\n", rtw_get_passing_time_ms(send_issue_deauth_time)); */
1337 if (rtw_get_passing_time_ms(send_issue_deauth_time) > 10000 || send_issue_deauth_time == 0) {
1338 send_issue_deauth_time = rtw_get_current_time();
1339 RTW_INFO(FUNC_ADPT_FMT" issue_deauth to "MAC_FMT" with reason(7), mlme_state:0x%x\n"
1340 , FUNC_ADPT_ARG(adapter), MAC_ARG(get_addr2_ptr(whdr)), MLME_STATE(adapter));
1341 issue_deauth(adapter, get_addr2_ptr(whdr), WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1342 }
1343 }
1344 #ifdef DBG_RX_DROP_FRAME
1345 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" fw_state:0x%x\n"
1346 , FUNC_ADPT_ARG(adapter), MLME_STATE(adapter));
1347 #endif
1348 goto exit;
1349 }
1350
1351 _rtw_memcpy(rattrib->ra, GetAddr1Ptr(whdr), ETH_ALEN);
1352 _rtw_memcpy(rattrib->ta, get_addr2_ptr(whdr), ETH_ALEN);
1353
1354 switch (rattrib->to_fr_ds) {
1355 case 2:
1356 _rtw_memcpy(rattrib->dst, GetAddr1Ptr(whdr), ETH_ALEN);
1357 _rtw_memcpy(rattrib->src, GetAddr3Ptr(whdr), ETH_ALEN); /* may change after checking AMSDU subframe header */
1358 _rtw_memcpy(rattrib->bssid, get_addr2_ptr(whdr), ETH_ALEN);
1359 break;
1360 case 3:
1361 _rtw_memcpy(rattrib->dst, GetAddr3Ptr(whdr), ETH_ALEN); /* may change after checking AMSDU subframe header */
1362 _rtw_memcpy(rattrib->src, GetAddr4Ptr(whdr), ETH_ALEN); /* may change after checking AMSDU subframe header */
1363 _rtw_memcpy(rattrib->bssid, get_addr2_ptr(whdr), ETH_ALEN);
1364 break;
1365 default:
1366 ret = RTW_RX_HANDLED; /* don't count for drop */
1367 goto exit;
1368 }
1369
1370 /* filter packets that SA is myself */
1371 if (!rattrib->amsdu && _rtw_memcmp(myhwaddr, rattrib->src, ETH_ALEN)) {
1372 #ifdef DBG_RX_DROP_FRAME
1373 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" SA="MAC_FMT", myhwaddr="MAC_FMT"\n"
1374 , FUNC_ADPT_ARG(adapter), MAC_ARG(rattrib->src), MAC_ARG(myhwaddr));
1375 #endif
1376 goto exit;
1377 }
1378
1379 *sta = rtw_get_stainfo(stapriv, rattrib->ta);
1380 if (*sta == NULL) {
1381 #ifndef CONFIG_CUSTOMER_ALIBABA_GENERAL
1382 if (!is_ra_bmc && !IS_RADAR_DETECTED(adapter_to_rfctl(adapter))) {
1383 RTW_INFO(FUNC_ADPT_FMT" issue_deauth to "MAC_FMT" with reason(7), unknown TA\n"
1384 , FUNC_ADPT_ARG(adapter), MAC_ARG(rattrib->ta));
1385 issue_deauth(adapter, rattrib->ta, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1386 }
1387 #endif
1388 #ifdef DBG_RX_DROP_FRAME
1389 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" can't get psta under STATION_MODE ; drop pkt\n"
1390 , FUNC_ADPT_ARG(adapter));
1391 #endif
1392 goto exit;
1393 }
1394
1395 #ifdef CONFIG_RTW_WDS_AUTO_EN
1396 if (rattrib->to_fr_ds == 3 && !(sta->flags & WLAN_STA_WDS))
1397 sta->flags |= WLAN_STA_WDS;
1398 #endif
1399
1400 /*if ((get_frame_sub_type(whdr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
1401 }
1402 */
1403
1404 if (get_frame_sub_type(whdr) & BIT(6)) {
1405 /* No data, will not indicate to upper layer, temporily count it here */
1406 count_rx_stats(adapter, rframe, *sta);
1407 ret = RTW_RX_HANDLED;
1408 goto exit;
1409 }
1410
1411 #ifdef CONFIG_RTW_WDS
1412 if (adapter_use_wds(adapter)
1413 && !rattrib->amsdu && IS_MCAST(rattrib->dst)
1414 && rtw_rx_wds_gptr_check(adapter, rattrib->src)
1415 ) {
1416 /* will not indicate to upper layer, temporily count it here */
1417 count_rx_stats(adapter, rframe, *sta);
1418 ret = RTW_RX_HANDLED;
1419 goto exit;
1420 }
1421 #endif
1422
1423 ret = _SUCCESS;
1424
1425 exit:
1426 return ret;
1427 }
1428
rtw_sta_rx_amsdu_act_check(union recv_frame * rframe,const u8 * da,const u8 * sa)1429 int rtw_sta_rx_amsdu_act_check(union recv_frame *rframe
1430 , const u8 *da, const u8 *sa)
1431 {
1432 int act = RTW_RX_MSDU_ACT_INDICATE;
1433
1434 #ifdef CONFIG_RTW_WDS
1435 _adapter *adapter = rframe->u.hdr.adapter;
1436
1437 if (adapter_use_wds(adapter)
1438 && IS_MCAST(da)
1439 && rtw_rx_wds_gptr_check(adapter, sa)
1440 ) {
1441 act = 0;
1442 }
1443 #endif
1444
1445 return act;
1446 }
1447
sta2sta_data_frame(_adapter * adapter,union recv_frame * precv_frame,struct sta_info ** psta)1448 sint sta2sta_data_frame(
1449 _adapter *adapter,
1450 union recv_frame *precv_frame,
1451 struct sta_info **psta
1452 )
1453 {
1454 u8 *ptr = precv_frame->u.hdr.rx_data;
1455 sint ret = _SUCCESS;
1456 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1457 struct sta_priv *pstapriv = &adapter->stapriv;
1458 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1459 u8 *mybssid = get_bssid(pmlmepriv);
1460 u8 *myhwaddr = adapter_mac_addr(adapter);
1461 u8 *sta_addr = pattrib->ta;
1462 sint bmcast = IS_MCAST(pattrib->dst);
1463
1464 /* RTW_INFO("[%s] %d, seqnum:%d\n", __FUNCTION__, __LINE__, pattrib->seq_num); */
1465
1466 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) ||
1467 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
1468
1469 /* filter packets that SA is myself or multicast or broadcast */
1470 if (_rtw_memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
1471 ret = _FAIL;
1472 goto exit;
1473 }
1474
1475 if ((!_rtw_memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
1476 ret = _FAIL;
1477 goto exit;
1478 }
1479
1480 if (_rtw_memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
1481 _rtw_memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
1482 (!_rtw_memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
1483 ret = _FAIL;
1484 goto exit;
1485 }
1486
1487 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE) {
1488 _rtw_memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
1489 _rtw_memcpy(pattrib->src, get_addr2_ptr(ptr), ETH_ALEN);
1490 _rtw_memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
1491 _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
1492 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1493
1494 sta_addr = mybssid;
1495 } else
1496 ret = _FAIL;
1497
1498 *psta = rtw_get_stainfo(pstapriv, sta_addr);
1499 if (*psta == NULL) {
1500 #ifdef CONFIG_MP_INCLUDED
1501 if (adapter->registrypriv.mp_mode == 1) {
1502 if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
1503 adapter->mppriv.rx_pktloss++;
1504 }
1505 #endif
1506 ret = _FAIL;
1507 goto exit;
1508 }
1509
1510 exit:
1511 return ret;
1512 }
1513
ap2sta_data_frame(_adapter * adapter,union recv_frame * precv_frame,struct sta_info ** psta)1514 sint ap2sta_data_frame(
1515 _adapter *adapter,
1516 union recv_frame *precv_frame,
1517 struct sta_info **psta)
1518 {
1519 u8 *ptr = precv_frame->u.hdr.rx_data;
1520 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1521 sint ret = _SUCCESS;
1522 struct sta_priv *pstapriv = &adapter->stapriv;
1523 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1524 u8 *myhwaddr = adapter_mac_addr(adapter);
1525 sint bmcast = IS_MCAST(pattrib->dst);
1526
1527 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE) &&
1528 (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)) {
1529 _rtw_memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
1530 _rtw_memcpy(pattrib->src, get_addr2_ptr(ptr), ETH_ALEN);
1531 _rtw_memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
1532 _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
1533 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1534
1535
1536 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
1537 if (*psta == NULL) {
1538 #ifdef DBG_RX_DROP_FRAME
1539 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" can't get psta under WIFI_MP_STATE ; drop pkt\n"
1540 , FUNC_ADPT_ARG(adapter));
1541 #endif
1542 ret = _FAIL;
1543 goto exit;
1544 }
1545
1546 } else {
1547 if (_rtw_memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
1548 *psta = rtw_get_stainfo(pstapriv, pattrib->ta);
1549 if (*psta == NULL) {
1550
1551 /* for AP multicast issue , modify by yiwei */
1552 static systime send_issue_deauth_time = 0;
1553
1554 /* RTW_INFO("After send deauth , %u ms has elapsed.\n", rtw_get_passing_time_ms(send_issue_deauth_time)); */
1555
1556 if (rtw_get_passing_time_ms(send_issue_deauth_time) > 10000 || send_issue_deauth_time == 0) {
1557 send_issue_deauth_time = rtw_get_current_time();
1558
1559 RTW_INFO("issue_deauth to the ap=" MAC_FMT " for the reason(7)\n", MAC_ARG(pattrib->bssid));
1560
1561 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1562 }
1563 }
1564 }
1565
1566 ret = _FAIL;
1567 #ifdef DBG_RX_DROP_FRAME
1568 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" fw_state:0x%x\n"
1569 , FUNC_ADPT_ARG(adapter), get_fwstate(pmlmepriv));
1570 #endif
1571 }
1572
1573 exit:
1574 return ret;
1575
1576 }
1577
sta2ap_data_frame(_adapter * adapter,union recv_frame * precv_frame,struct sta_info ** psta)1578 sint sta2ap_data_frame(
1579 _adapter *adapter,
1580 union recv_frame *precv_frame,
1581 struct sta_info **psta)
1582 {
1583 u8 *ptr = precv_frame->u.hdr.rx_data;
1584 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1585 struct sta_priv *pstapriv = &adapter->stapriv;
1586 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1587 unsigned char *mybssid = get_bssid(pmlmepriv);
1588 sint ret = _SUCCESS;
1589
1590 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE) &&
1591 (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)) {
1592 /* RTW_INFO("%s ,in WIFI_MP_STATE\n",__func__); */
1593 _rtw_memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
1594 _rtw_memcpy(pattrib->src, get_addr2_ptr(ptr), ETH_ALEN);
1595 _rtw_memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
1596 _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
1597 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1598
1599
1600 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
1601 if (*psta == NULL) {
1602 #ifdef DBG_RX_DROP_FRAME
1603 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" can't get psta under WIFI_MP_STATE ; drop pkt\n"
1604 , FUNC_ADPT_ARG(adapter));
1605 #endif
1606 ret = _FAIL;
1607 goto exit;
1608 }
1609
1610 } else {
1611 u8 *myhwaddr = adapter_mac_addr(adapter);
1612 if (!_rtw_memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
1613 ret = RTW_RX_HANDLED;
1614 goto exit;
1615 }
1616 #ifndef CONFIG_CUSTOMER_ALIBABA_GENERAL
1617 RTW_INFO("issue_deauth to sta=" MAC_FMT " for the reason(7)\n", MAC_ARG(pattrib->src));
1618 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1619 #endif
1620 ret = RTW_RX_HANDLED;
1621 goto exit;
1622 }
1623
1624 exit:
1625
1626
1627 return ret;
1628
1629 }
1630
1631 sint validate_recv_ctrl_frame(_adapter *padapter, union recv_frame *precv_frame);
validate_recv_ctrl_frame(_adapter * padapter,union recv_frame * precv_frame)1632 sint validate_recv_ctrl_frame(_adapter *padapter, union recv_frame *precv_frame)
1633 {
1634 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1635 struct sta_priv *pstapriv = &padapter->stapriv;
1636 u8 *pframe = precv_frame->u.hdr.rx_data;
1637 struct sta_info *psta = NULL;
1638 u8 dataq_null = _TRUE;
1639 #ifdef CONFIG_RTW_MGMT_QUEUE
1640 u8 mgmtq_null = _TRUE;
1641 #endif
1642
1643 /* uint len = precv_frame->u.hdr.len; */
1644
1645 /* RTW_INFO("+validate_recv_ctrl_frame\n"); */
1646
1647 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
1648 return _FAIL;
1649
1650 /* receive the frames that ra(a1) is my address */
1651 if (!_rtw_memcmp(GetAddr1Ptr(pframe), adapter_mac_addr(padapter), ETH_ALEN))
1652 return _FAIL;
1653
1654 psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
1655 if (psta == NULL)
1656 return _FAIL;
1657
1658 /* for rx pkt statistics */
1659 psta->sta_stats.last_rx_time = rtw_get_current_time();
1660 psta->sta_stats.rx_ctrl_pkts++;
1661
1662 /* only handle ps-poll */
1663 if (get_frame_sub_type(pframe) == WIFI_PSPOLL) {
1664 #ifdef CONFIG_AP_MODE
1665 u16 aid;
1666 u8 wmmps_ac = 0;
1667
1668 aid = GetAid(pframe);
1669 if (psta->cmn.aid != aid)
1670 return _FAIL;
1671
1672 switch (pattrib->priority) {
1673 case 1:
1674 case 2:
1675 wmmps_ac = psta->uapsd_bk & BIT(0);
1676 break;
1677 case 4:
1678 case 5:
1679 wmmps_ac = psta->uapsd_vi & BIT(0);
1680 break;
1681 case 6:
1682 case 7:
1683 wmmps_ac = psta->uapsd_vo & BIT(0);
1684 break;
1685 case 0:
1686 case 3:
1687 default:
1688 wmmps_ac = psta->uapsd_be & BIT(0);
1689 break;
1690 }
1691
1692 if (wmmps_ac)
1693 return _FAIL;
1694
1695 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
1696 RTW_INFO("%s alive check-rx ps-poll\n", __func__);
1697 psta->expire_to = pstapriv->expire_to;
1698 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
1699 }
1700
1701 if ((psta->state & WIFI_SLEEP_STATE) && (rtw_tim_map_is_set(padapter, pstapriv->sta_dz_bitmap, psta->cmn.aid))) {
1702 _irqL irqL;
1703 _list *xmitframe_plist, *xmitframe_phead;
1704 struct xmit_frame *pxmitframe = NULL;
1705 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1706
1707 /* _enter_critical_bh(&psta->sleep_q.lock, &irqL); */
1708 _enter_critical_bh(&pxmitpriv->lock, &irqL);
1709
1710 #ifdef CONFIG_RTW_MGMT_QUEUE
1711 xmitframe_phead = get_list_head(&psta->mgmt_sleep_q);
1712 xmitframe_plist = get_next(xmitframe_phead);
1713
1714 if ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE) {
1715 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
1716
1717 xmitframe_plist = get_next(xmitframe_plist);
1718
1719 rtw_list_delete(&pxmitframe->list);
1720
1721 #ifdef DBG_MGMT_QUEUE
1722 RTW_INFO("%s seq_num = %u, subtype = 0x%x\n",
1723 __func__, pxmitframe->attrib.seqnum, pxmitframe->attrib.subtype);
1724 #endif
1725
1726 psta->mgmt_sleepq_len--;
1727
1728 if (psta->mgmt_sleepq_len > 0)
1729 pxmitframe->attrib.mdata = 1;
1730 else
1731 pxmitframe->attrib.mdata = 0;
1732
1733 pxmitframe->attrib.triggered = 1;
1734
1735 rtw_hal_mgmt_xmitframe_enqueue(padapter, pxmitframe);
1736
1737 mgmtq_null = _FALSE;
1738 }
1739 #endif
1740 xmitframe_phead = get_list_head(&psta->sleep_q);
1741 xmitframe_plist = get_next(xmitframe_phead);
1742
1743 if ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE) {
1744 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
1745
1746 xmitframe_plist = get_next(xmitframe_plist);
1747
1748 rtw_list_delete(&pxmitframe->list);
1749
1750 psta->sleepq_len--;
1751
1752 if (psta->sleepq_len > 0)
1753 pxmitframe->attrib.mdata = 1;
1754 else
1755 pxmitframe->attrib.mdata = 0;
1756
1757 pxmitframe->attrib.triggered = 1;
1758
1759 /* RTW_INFO("handling ps-poll, q_len=%d\n", psta->sleepq_len); */
1760 /* RTW_INFO_DUMP("handling, tim=", pstapriv->tim_bitmap, pstapriv->aid_bmp_len); */
1761
1762 #if 0
1763 _exit_critical_bh(&psta->sleep_q.lock, &irqL);
1764 if (rtw_hal_xmit(padapter, pxmitframe) == _TRUE)
1765 rtw_os_xmit_complete(padapter, pxmitframe);
1766 _enter_critical_bh(&psta->sleep_q.lock, &irqL);
1767 #endif
1768 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
1769
1770 dataq_null = _FALSE;
1771 }
1772
1773 _exit_critical_bh(&pxmitpriv->lock, &irqL);
1774 /* _exit_critical_bh(&psta->sleep_q.lock, &irqL); */
1775
1776 /* Error handler : TIM is setted, but data queue and management queue is empty. */
1777 if (dataq_null
1778 #ifdef CONFIG_RTW_MGMT_QUEUE
1779 && mgmtq_null
1780 #endif
1781 && rtw_tim_map_is_set(padapter, pstapriv->tim_bitmap, psta->cmn.aid)) {
1782
1783 if (psta->sleepq_len == 0
1784 #ifdef CONFIG_RTW_MGMT_QUEUE
1785 && psta->mgmt_sleepq_len == 0
1786 #endif
1787 ) {
1788 RTW_INFO("No buffered packets to xmit\n");
1789
1790 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
1791 issue_nulldata(padapter, psta->cmn.mac_addr, 0, 0, 0);
1792 } else {
1793 if (psta->sleepq_len != 0) {
1794 RTW_INFO("error!psta->sleepq_len=%d\n", psta->sleepq_len);
1795 psta->sleepq_len = 0;
1796 }
1797 #ifdef CONFIG_RTW_MGMT_QUEUE
1798 if (psta->mgmt_sleepq_len != 0) {
1799 RTW_INFO("error!psta->mgmt_sleepq_len=%d\n", psta->mgmt_sleepq_len);
1800 psta->mgmt_sleepq_len = 0;
1801 }
1802 #endif
1803 }
1804 }
1805
1806 if (psta->sleepq_len == 0
1807 #ifdef CONFIG_RTW_MGMT_QUEUE
1808 && psta->mgmt_sleepq_len == 0
1809 #endif
1810 ) {
1811 rtw_tim_map_clear(padapter, pstapriv->tim_bitmap, psta->cmn.aid);
1812
1813 /* upate BCN for TIM IE */
1814 update_beacon(padapter, _TIM_IE_, NULL, _TRUE, 0);
1815 }
1816 }
1817 #endif /* CONFIG_AP_MODE */
1818 } else if (get_frame_sub_type(pframe) == WIFI_NDPA) {
1819 #ifdef CONFIG_BEAMFORMING
1820 rtw_beamforming_get_ndpa_frame(padapter, precv_frame);
1821 #endif/*CONFIG_BEAMFORMING*/
1822 } else if (get_frame_sub_type(pframe) == WIFI_BAR) {
1823 rtw_process_bar_frame(padapter, precv_frame);
1824 }
1825
1826 return _FAIL;
1827
1828 }
1829
1830 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_RTW_MESH)
validate_mgmt_protect(_adapter * adapter,union recv_frame * precv_frame)1831 static sint validate_mgmt_protect(_adapter *adapter, union recv_frame *precv_frame)
1832 {
1833 #define DBG_VALIDATE_MGMT_PROTECT 0
1834 #define DBG_VALIDATE_MGMT_DEC 0
1835
1836 struct security_priv *sec = &adapter->securitypriv;
1837 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1838 struct sta_info *psta = precv_frame->u.hdr.psta;
1839 u8 *ptr;
1840 u8 type;
1841 u8 subtype;
1842 u8 is_bmc;
1843 u8 category = 0xFF;
1844
1845 #ifdef CONFIG_IEEE80211W
1846 const u8 *igtk;
1847 u16 igtk_id;
1848 u64* ipn;
1849 enum security_type bip_cipher;
1850 #endif
1851
1852 u8 *mgmt_DATA;
1853 u32 data_len = 0;
1854
1855 sint ret;
1856
1857 #ifdef CONFIG_RTW_MESH
1858 if (MLME_IS_MESH(adapter)) {
1859 if (!adapter->mesh_info.mesh_auth_id)
1860 return pattrib->privacy ? _FAIL : _SUCCESS;
1861 } else
1862 #endif
1863 if (SEC_IS_BIP_KEY_INSTALLED(sec) == _FALSE)
1864 return _SUCCESS;
1865
1866 ptr = precv_frame->u.hdr.rx_data;
1867 type = GetFrameType(ptr);
1868 subtype = get_frame_sub_type(ptr); /* bit(7)~bit(2) */
1869 is_bmc = IS_MCAST(GetAddr1Ptr(ptr));
1870
1871 #if DBG_VALIDATE_MGMT_PROTECT
1872 if (subtype == WIFI_DEAUTH) {
1873 RTW_INFO(FUNC_ADPT_FMT" bmc:%u, deauth, privacy:%u, encrypt:%u, bdecrypted:%u\n"
1874 , FUNC_ADPT_ARG(adapter)
1875 , is_bmc, pattrib->privacy, pattrib->encrypt, pattrib->bdecrypted);
1876 } else if (subtype == WIFI_DISASSOC) {
1877 RTW_INFO(FUNC_ADPT_FMT" bmc:%u, disassoc, privacy:%u, encrypt:%u, bdecrypted:%u\n"
1878 , FUNC_ADPT_ARG(adapter)
1879 , is_bmc, pattrib->privacy, pattrib->encrypt, pattrib->bdecrypted);
1880 } if (subtype == WIFI_ACTION) {
1881 if (pattrib->privacy) {
1882 RTW_INFO(FUNC_ADPT_FMT" bmc:%u, action(?), privacy:%u, encrypt:%u, bdecrypted:%u\n"
1883 , FUNC_ADPT_ARG(adapter)
1884 , is_bmc, pattrib->privacy, pattrib->encrypt, pattrib->bdecrypted);
1885 } else {
1886 RTW_INFO(FUNC_ADPT_FMT" bmc:%u, action(%u), privacy:%u, encrypt:%u, bdecrypted:%u\n"
1887 , FUNC_ADPT_ARG(adapter), is_bmc
1888 , *(ptr + sizeof(struct rtw_ieee80211_hdr_3addr))
1889 , pattrib->privacy, pattrib->encrypt, pattrib->bdecrypted);
1890 }
1891 }
1892 #endif
1893
1894 if (!pattrib->privacy) {
1895 if (!psta || !(psta->flags & WLAN_STA_MFP)) {
1896 /* peer is not MFP capable, no need to check */
1897 goto exit;
1898 }
1899
1900 if (subtype == WIFI_ACTION)
1901 category = *(ptr + sizeof(struct rtw_ieee80211_hdr_3addr));
1902
1903 if (is_bmc) {
1904 /* broadcast cases */
1905 if (subtype == WIFI_ACTION) {
1906 if (CATEGORY_IS_GROUP_PRIVACY(category)) {
1907 /* drop broadcast group privacy action frame without encryption */
1908 #if DBG_VALIDATE_MGMT_PROTECT
1909 RTW_INFO(FUNC_ADPT_FMT" broadcast gp action(%u) w/o encrypt\n"
1910 , FUNC_ADPT_ARG(adapter), category);
1911 #endif
1912 goto fail;
1913 }
1914 if (CATEGORY_IS_ROBUST(category)) {
1915 /* broadcast robust action frame need BIP check */
1916 goto bip_verify;
1917 }
1918 }
1919 if (subtype == WIFI_DEAUTH || subtype == WIFI_DISASSOC) {
1920 /* broadcast deauth or disassoc frame need BIP check */
1921 goto bip_verify;
1922 }
1923 goto exit;
1924
1925 } else {
1926 /* unicast cases */
1927 #ifdef CONFIG_IEEE80211W
1928 if (subtype == WIFI_DEAUTH || subtype == WIFI_DISASSOC) {
1929 if (!MLME_IS_MESH(adapter)) {
1930 unsigned short reason = le16_to_cpu(*(unsigned short *)(ptr + WLAN_HDR_A3_LEN));
1931
1932 #if DBG_VALIDATE_MGMT_PROTECT
1933 RTW_INFO(FUNC_ADPT_FMT" unicast %s, reason=%d w/o encrypt\n"
1934 , FUNC_ADPT_ARG(adapter), subtype == WIFI_DEAUTH ? "deauth" : "disassoc", reason);
1935 #endif
1936 if (reason == 6 || reason == 7) {
1937 /* issue sa query request */
1938 issue_action_SA_Query(adapter, psta->cmn.mac_addr, 0, 0, IEEE80211W_RIGHT_KEY);
1939 }
1940 }
1941 goto fail;
1942 }
1943 #endif
1944
1945 if (subtype == WIFI_ACTION && CATEGORY_IS_ROBUST(category)) {
1946 if (psta->bpairwise_key_installed == _TRUE) {
1947 #if DBG_VALIDATE_MGMT_PROTECT
1948 RTW_INFO(FUNC_ADPT_FMT" unicast robust action(%d) w/o encrypt\n"
1949 , FUNC_ADPT_ARG(adapter), category);
1950 #endif
1951 goto fail;
1952 }
1953 }
1954 goto exit;
1955 }
1956
1957 bip_verify:
1958 #ifdef CONFIG_IEEE80211W
1959 #ifdef CONFIG_RTW_MESH
1960 if (MLME_IS_MESH(adapter)) {
1961 if (psta->igtk_bmp) {
1962 bip_cipher = psta->dot11wCipher;
1963 igtk = psta->igtk.skey;
1964 igtk_id = psta->igtk_id;
1965 ipn = &psta->igtk_pn.val;
1966 } else {
1967 /* mesh MFP without IGTK */
1968 goto exit;
1969 }
1970 } else
1971 #endif
1972 {
1973 bip_cipher = sec->dot11wCipher;
1974 igtk = sec->dot11wBIPKey[sec->dot11wBIPKeyid].skey;
1975 igtk_id = sec->dot11wBIPKeyid;
1976 ipn = &sec->dot11wBIPrxpn.val;
1977 }
1978
1979 /* verify BIP MME IE */
1980 ret = rtw_bip_verify(bip_cipher, pattrib->pkt_len,
1981 get_recvframe_data(precv_frame),
1982 get_recvframe_len(precv_frame),
1983 igtk, igtk_id, ipn);
1984
1985 if (ret == _FAIL) {
1986 /* RTW_INFO("802.11w BIP verify fail\n"); */
1987 goto fail;
1988
1989 } else if (ret == RTW_RX_HANDLED) {
1990 #if DBG_VALIDATE_MGMT_PROTECT
1991 RTW_INFO(FUNC_ADPT_FMT" none protected packet\n", FUNC_ADPT_ARG(adapter));
1992 #endif
1993 goto fail;
1994 }
1995 #endif /* CONFIG_IEEE80211W */
1996 goto exit;
1997 }
1998
1999 if (!psta || !(psta->flags & WLAN_STA_MFP)) {
2000 /* not peer or peer is not MFP capable, drop it */
2001 goto fail;
2002 }
2003
2004 /* cases to decrypt mgmt frame */
2005 pattrib->bdecrypted = 0;
2006 #ifdef CONFIG_RTW_MESH
2007 if (is_bmc)
2008 pattrib->encrypt = psta->group_privacy;
2009 else
2010 #endif
2011 pattrib->encrypt = psta->dot118021XPrivacy;
2012 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2013
2014 /* set iv and icv length */
2015 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
2016 _rtw_memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
2017 _rtw_memcpy(pattrib->ta, get_addr2_ptr(ptr), ETH_ALEN);
2018
2019 /* actual management data frame body */
2020 data_len = pattrib->pkt_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
2021 mgmt_DATA = rtw_zmalloc(data_len);
2022 if (mgmt_DATA == NULL) {
2023 RTW_INFO(FUNC_ADPT_FMT" mgmt allocate fail !!!!!!!!!\n", FUNC_ADPT_ARG(adapter));
2024 goto fail;
2025 }
2026
2027 #if DBG_VALIDATE_MGMT_DEC
2028 /* dump the packet content before decrypt */
2029 {
2030 int pp;
2031
2032 printk("pattrib->pktlen = %d =>", pattrib->pkt_len);
2033 for (pp = 0; pp < pattrib->pkt_len; pp++)
2034 printk(" %02x ", ptr[pp]);
2035 printk("\n");
2036 }
2037 #endif
2038
2039 precv_frame = decryptor(adapter, precv_frame);
2040 /* save actual management data frame body */
2041 _rtw_memcpy(mgmt_DATA, ptr + pattrib->hdrlen + pattrib->iv_len, data_len);
2042 /* overwrite the iv field */
2043 _rtw_memcpy(ptr + pattrib->hdrlen, mgmt_DATA, data_len);
2044 /* remove the iv and icv length */
2045 pattrib->pkt_len = pattrib->pkt_len - pattrib->iv_len - pattrib->icv_len;
2046 rtw_mfree(mgmt_DATA, data_len);
2047
2048 #if DBG_VALIDATE_MGMT_DEC
2049 /* print packet content after decryption */
2050 {
2051 int pp;
2052
2053 printk("after decryption pattrib->pktlen = %d @@=>", pattrib->pkt_len);
2054 for (pp = 0; pp < pattrib->pkt_len; pp++)
2055 printk(" %02x ", ptr[pp]);
2056 printk("\n");
2057 }
2058 #endif
2059
2060 if (!precv_frame) {
2061 #if DBG_VALIDATE_MGMT_PROTECT
2062 RTW_INFO(FUNC_ADPT_FMT" mgmt descrypt fail !!!!!!!!!\n", FUNC_ADPT_ARG(adapter));
2063 #endif
2064 goto fail;
2065 }
2066
2067 exit:
2068 return _SUCCESS;
2069
2070 fail:
2071 return _FAIL;
2072
2073 }
2074 #endif /* defined(CONFIG_IEEE80211W) || defined(CONFIG_RTW_MESH) */
2075
2076 union recv_frame *recvframe_chk_defrag(PADAPTER padapter, union recv_frame *precv_frame);
2077
validate_recv_mgnt_frame(PADAPTER padapter,union recv_frame * precv_frame)2078 sint validate_recv_mgnt_frame(PADAPTER padapter, union recv_frame *precv_frame)
2079 {
2080 struct sta_info *psta = precv_frame->u.hdr.psta
2081 = rtw_get_stainfo(&padapter->stapriv, get_addr2_ptr(precv_frame->u.hdr.rx_data));
2082
2083 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_RTW_MESH)
2084 if (validate_mgmt_protect(padapter, precv_frame) == _FAIL) {
2085 DBG_COUNTER(padapter->rx_logs.core_rx_pre_mgmt_err_80211w);
2086 goto exit;
2087 }
2088 #endif
2089
2090 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
2091 if (precv_frame == NULL)
2092 return _SUCCESS;
2093
2094 /* for rx pkt statistics */
2095 if (psta) {
2096 psta->sta_stats.last_rx_time = rtw_get_current_time();
2097 psta->sta_stats.rx_mgnt_pkts++;
2098 if (get_frame_sub_type(precv_frame->u.hdr.rx_data) == WIFI_BEACON)
2099 psta->sta_stats.rx_beacon_pkts++;
2100 else if (get_frame_sub_type(precv_frame->u.hdr.rx_data) == WIFI_PROBEREQ)
2101 psta->sta_stats.rx_probereq_pkts++;
2102 else if (get_frame_sub_type(precv_frame->u.hdr.rx_data) == WIFI_PROBERSP) {
2103 if (_rtw_memcmp(adapter_mac_addr(padapter), GetAddr1Ptr(precv_frame->u.hdr.rx_data), ETH_ALEN) == _TRUE)
2104 psta->sta_stats.rx_probersp_pkts++;
2105 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->u.hdr.rx_data))
2106 || is_multicast_mac_addr(GetAddr1Ptr(precv_frame->u.hdr.rx_data)))
2107 psta->sta_stats.rx_probersp_bm_pkts++;
2108 else
2109 psta->sta_stats.rx_probersp_uo_pkts++;
2110 }
2111 }
2112
2113 mgt_dispatcher(padapter, precv_frame);
2114
2115 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_RTW_MESH)
2116 exit:
2117 #endif
2118 return _SUCCESS;
2119
2120 }
2121
validate_recv_data_frame(_adapter * adapter,union recv_frame * precv_frame)2122 sint validate_recv_data_frame(_adapter *adapter, union recv_frame *precv_frame)
2123 {
2124 u8 bretry, a4_shift;
2125 struct sta_info *psta = NULL;
2126 u8 *ptr = precv_frame->u.hdr.rx_data;
2127 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
2128 struct security_priv *psecuritypriv = &adapter->securitypriv;
2129 sint ret = _SUCCESS;
2130
2131 bretry = GetRetry(ptr);
2132 a4_shift = (pattrib->to_fr_ds == 3) ? ETH_ALEN : 0;
2133
2134 /* some address fields are different when using AMSDU */
2135 if (pattrib->qos)
2136 pattrib->amsdu = GetAMsdu(ptr + WLAN_HDR_A3_LEN + a4_shift);
2137 else
2138 pattrib->amsdu = 0;
2139
2140 #ifdef CONFIG_RTW_MESH
2141 if (MLME_IS_MESH(adapter)) {
2142 ret = rtw_mesh_rx_data_validate_hdr(adapter, precv_frame, &psta);
2143 goto pre_validate_status_chk;
2144 } else
2145 #endif
2146 #ifdef CONFIG_AP_MODE
2147 if (MLME_IS_AP(adapter)) {
2148 ret = rtw_ap_rx_data_validate_hdr(adapter, precv_frame, &psta);
2149 goto pre_validate_status_chk;
2150 } else
2151 #endif
2152 if (MLME_IS_STA(adapter)) {
2153 ret = rtw_sta_rx_data_validate_hdr(adapter, precv_frame, &psta);
2154 goto pre_validate_status_chk;
2155 }
2156
2157 switch (pattrib->to_fr_ds) {
2158 case 0:
2159 _rtw_memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
2160 _rtw_memcpy(pattrib->ta, get_addr2_ptr(ptr), ETH_ALEN);
2161 _rtw_memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
2162 _rtw_memcpy(pattrib->src, get_addr2_ptr(ptr), ETH_ALEN);
2163 _rtw_memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
2164 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
2165 break;
2166
2167 case 1:
2168 _rtw_memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
2169 _rtw_memcpy(pattrib->ta, get_addr2_ptr(ptr), ETH_ALEN);
2170 _rtw_memcpy(pattrib->dst, GetAddr3Ptr(ptr), ETH_ALEN);
2171 _rtw_memcpy(pattrib->src, get_addr2_ptr(ptr), ETH_ALEN);
2172 _rtw_memcpy(pattrib->bssid, GetAddr1Ptr(ptr), ETH_ALEN);
2173 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
2174 break;
2175
2176 case 2:
2177 _rtw_memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
2178 _rtw_memcpy(pattrib->ta, get_addr2_ptr(ptr), ETH_ALEN);
2179 _rtw_memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
2180 _rtw_memcpy(pattrib->src, GetAddr3Ptr(ptr), ETH_ALEN);
2181 _rtw_memcpy(pattrib->bssid, get_addr2_ptr(ptr), ETH_ALEN);
2182 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
2183 break;
2184
2185 case 3:
2186 default:
2187 /* WDS is not supported */
2188 ret = _FAIL;
2189 break;
2190 }
2191
2192 pre_validate_status_chk:
2193
2194 if (ret == _FAIL) {
2195 #ifdef DBG_RX_DROP_FRAME
2196 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" case:%d, res:%d, ra="MAC_FMT", ta="MAC_FMT"\n"
2197 , FUNC_ADPT_ARG(adapter), pattrib->to_fr_ds, ret, MAC_ARG(GetAddr1Ptr(ptr)), MAC_ARG(get_addr2_ptr(ptr)));
2198 #endif
2199 goto exit;
2200 } else if (ret == RTW_RX_HANDLED)
2201 goto exit;
2202
2203
2204 if (psta == NULL) {
2205 #ifdef DBG_RX_DROP_FRAME
2206 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" psta == NULL, ra="MAC_FMT", ta="MAC_FMT"\n"
2207 , FUNC_ADPT_ARG(adapter), MAC_ARG(GetAddr1Ptr(ptr)), MAC_ARG(get_addr2_ptr(ptr)));
2208 #endif
2209 ret = _FAIL;
2210 goto exit;
2211 }
2212
2213 if ((psta->flags & WLAN_STA_AMSDU_DISABLE) && pattrib->amsdu) {
2214 #ifdef DBG_RX_DROP_FRAME
2215 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" amsdu not allowed"MAC_FMT"\n"
2216 , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->cmn.mac_addr));
2217 #endif
2218 ret = _FAIL;
2219 goto exit;
2220
2221 }
2222
2223 precv_frame->u.hdr.psta = psta;
2224 precv_frame->u.hdr.preorder_ctrl = NULL;
2225 pattrib->ack_policy = 0;
2226
2227 /* parsing QC field */
2228 if (pattrib->qos == 1) {
2229 pattrib->priority = GetPriority((ptr + WLAN_HDR_A3_LEN + a4_shift)); /* point to Qos field*/
2230 pattrib->ack_policy = GetAckpolicy((ptr + WLAN_HDR_A3_LEN + a4_shift));
2231 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN + a4_shift;
2232 if (pattrib->priority != 0 && pattrib->priority != 3)
2233 adapter->recvpriv.is_any_non_be_pkts = _TRUE;
2234 else
2235 adapter->recvpriv.is_any_non_be_pkts = _FALSE;
2236 } else {
2237 pattrib->priority = 0;
2238 pattrib->hdrlen = WLAN_HDR_A3_LEN + a4_shift;
2239 }
2240
2241 if (pattrib->order) /* HT-CTRL 11n */
2242 pattrib->hdrlen += 4;
2243
2244 /* decache, drop duplicate recv packets */
2245 ret = recv_decache(precv_frame);
2246 if (ret == _FAIL)
2247 goto exit;
2248
2249 if (!IS_MCAST(pattrib->ra)) {
2250
2251 if (pattrib->qos)
2252 precv_frame->u.hdr.preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
2253
2254 if (recv_ucast_pn_decache(precv_frame) == _FAIL) {
2255 #ifdef DBG_RX_DROP_FRAME
2256 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" recv_ucast_pn_decache return _FAIL for sta="MAC_FMT"\n"
2257 , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->cmn.mac_addr));
2258 #endif
2259 ret = _FAIL;
2260 goto exit;
2261 }
2262 } else {
2263 if (recv_bcast_pn_decache(precv_frame) == _FAIL) {
2264 #ifdef DBG_RX_DROP_FRAME
2265 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" recv_bcast_pn_decache return _FAIL for sta="MAC_FMT"\n"
2266 , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->cmn.mac_addr));
2267 #endif
2268 ret = _FAIL;
2269 goto exit;
2270 }
2271 }
2272
2273 if (pattrib->privacy) {
2274 #ifdef CONFIG_TDLS
2275 if ((psta->tdls_sta_state & TDLS_LINKED_STATE) && (psta->dot118021XPrivacy == _AES_))
2276 pattrib->encrypt = psta->dot118021XPrivacy;
2277 else
2278 #endif /* CONFIG_TDLS */
2279 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
2280
2281
2282 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
2283 } else {
2284 pattrib->encrypt = 0;
2285 pattrib->iv_len = pattrib->icv_len = 0;
2286 }
2287
2288 /* drop unprotected frame in protected network. */
2289 if (psecuritypriv->dot11PrivacyAlgrthm != _NO_PRIVACY_ ) {
2290 if (IS_MCAST(pattrib->ra)) {
2291 if (!pattrib->privacy) {
2292 #ifdef DBG_RX_DROP_FRAME
2293 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT"recv plaintext bmc packet for sta="MAC_FMT"\n"
2294 , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->cmn.mac_addr));
2295 #endif
2296 ret = _FAIL;
2297 goto exit;
2298 }
2299 } else {
2300 /* unicast */
2301 u16 ether_type;
2302 u8* ether_ptr = NULL;
2303 u16 eapol_type = 0x888e;
2304 ether_ptr = ptr + pattrib->hdrlen + pattrib->iv_len + RATTRIB_GET_MCTRL_LEN(pattrib) + LLC_HEADER_SIZE;
2305 _rtw_memcpy(ðer_type, ether_ptr, 2);
2306 ether_type = ntohs((unsigned short)ether_type);
2307
2308 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
2309 /* CVE-2020-26140, CVE-2020-26143, CVE-2020-26147, let eapol packet go through*/
2310 if (!pattrib->privacy && ether_type != eapol_type ) {
2311 #ifdef DBG_RX_DROP_FRAME
2312 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT"recv plaintext unicast packet for sta="MAC_FMT"\n"
2313 , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->cmn.mac_addr));
2314 #endif
2315 ret = _FAIL;
2316 goto exit;
2317 }
2318 /* CVE-2020-26144, pevernt plaintext A-MSDU */
2319 /* This can prevent plantext A-MSDU cloacked as an EAPOL frame */
2320 if (!pattrib->privacy && pattrib->amsdu) {
2321 #ifdef DBG_RX_DROP_FRAME
2322 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT"recv plaintext A-MSDU for sta="MAC_FMT"\n"
2323 , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->cmn.mac_addr));
2324 #endif
2325 ret = _FAIL;
2326 goto exit;
2327 }
2328 /* CVE-2020-26139, Drop any forwarding eapol packet until 4-way has done. */
2329 if ((ether_type == eapol_type)
2330 && (MLME_IS_AP(adapter) || MLME_IS_MESH(adapter))
2331 && (psta->dot118021XPrivacy == _NO_PRIVACY_)
2332 && (!_rtw_memcmp( adapter_mac_addr(adapter), pattrib->dst, ETH_ALEN))) {
2333 #ifdef DBG_RX_DROP_FRAME
2334 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" recv eapol packet forwarding(dst:"MAC_FMT") before 4-way finish.\n"
2335 , FUNC_ADPT_ARG(adapter), MAC_ARG(pattrib->dst));
2336 #endif
2337 ret = _FAIL;
2338 goto exit;
2339 }
2340 } else {
2341 /* CVE-2020-26140, CVE-2020-26143, CVE-2020-26147 */
2342 if (!pattrib->privacy
2343 #ifdef CONFIG_WAPI_SUPPORT
2344 && (0x88b4 != ether_type) /* Let WAI packet pass here */
2345 #endif
2346 ) {
2347 #ifdef DBG_RX_DROP_FRAME
2348 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT"recv plaintext packet for sta="MAC_FMT"\n"
2349 , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->cmn.mac_addr));
2350 #endif
2351 ret = _FAIL;
2352 goto exit;
2353 }
2354 }
2355 }
2356 }
2357
2358 #ifdef CONFIG_RTW_MESH
2359 if (!pattrib->amsdu
2360 && pattrib->mesh_ctrl_present
2361 && (!pattrib->encrypt || pattrib->bdecrypted))
2362 ret = rtw_mesh_rx_validate_mctrl_non_amsdu(adapter, precv_frame);
2363 #endif
2364
2365 exit:
2366 return ret;
2367 }
2368
dump_rx_packet(u8 * ptr)2369 static inline void dump_rx_packet(u8 *ptr)
2370 {
2371 int i;
2372
2373 RTW_INFO("#############################\n");
2374 for (i = 0; i < 64; i = i + 8)
2375 RTW_INFO("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr + i),
2376 *(ptr + i + 1), *(ptr + i + 2) , *(ptr + i + 3) , *(ptr + i + 4), *(ptr + i + 5), *(ptr + i + 6), *(ptr + i + 7));
2377 RTW_INFO("#############################\n");
2378 }
2379
2380 sint validate_recv_frame(_adapter *adapter, union recv_frame *precv_frame);
validate_recv_frame(_adapter * adapter,union recv_frame * precv_frame)2381 sint validate_recv_frame(_adapter *adapter, union recv_frame *precv_frame)
2382 {
2383 /* shall check frame subtype, to / from ds, da, bssid */
2384
2385 /* then call check if rx seq/frag. duplicated. */
2386
2387 u8 type;
2388 u8 subtype;
2389 sint retval = _SUCCESS;
2390
2391 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
2392 struct recv_priv *precvpriv = &adapter->recvpriv;
2393
2394 u8 *ptr = precv_frame->u.hdr.rx_data;
2395 u8 ver = (unsigned char)(*ptr) & 0x3 ;
2396 #ifdef CONFIG_FIND_BEST_CHANNEL
2397 struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
2398 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
2399 #endif
2400
2401 #ifdef CONFIG_TDLS
2402 struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
2403 #endif /* CONFIG_TDLS */
2404 #ifdef CONFIG_WAPI_SUPPORT
2405 PRT_WAPI_T pWapiInfo = &adapter->wapiInfo;
2406 struct recv_frame_hdr *phdr = &precv_frame->u.hdr;
2407 u8 wai_pkt = 0;
2408 u16 sc;
2409 u8 external_len = 0;
2410 #endif
2411
2412
2413 #ifdef CONFIG_FIND_BEST_CHANNEL
2414 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
2415 int ch_set_idx = rtw_chset_search_ch(rfctl->channel_set, rtw_get_oper_ch(adapter));
2416 if (ch_set_idx >= 0)
2417 rfctl->channel_set[ch_set_idx].rx_count++;
2418 }
2419 #endif
2420
2421 #ifdef CONFIG_TDLS
2422 if (ptdlsinfo->ch_sensing == 1 && ptdlsinfo->cur_channel != 0)
2423 ptdlsinfo->collect_pkt_num[ptdlsinfo->cur_channel - 1]++;
2424 #endif /* CONFIG_TDLS */
2425
2426 #ifdef RTK_DMP_PLATFORM
2427 if (0) {
2428 RTW_INFO("++\n");
2429 {
2430 int i;
2431 for (i = 0; i < 64; i = i + 8)
2432 RTW_INFO("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:", *(ptr + i),
2433 *(ptr + i + 1), *(ptr + i + 2) , *(ptr + i + 3) , *(ptr + i + 4), *(ptr + i + 5), *(ptr + i + 6), *(ptr + i + 7));
2434
2435 }
2436 RTW_INFO("--\n");
2437 }
2438 #endif /* RTK_DMP_PLATFORM */
2439
2440 /* add version chk */
2441 if (ver != 0) {
2442 retval = _FAIL;
2443 DBG_COUNTER(adapter->rx_logs.core_rx_pre_ver_err);
2444 goto exit;
2445 }
2446
2447 type = GetFrameType(ptr);
2448 subtype = get_frame_sub_type(ptr); /* bit(7)~bit(2) */
2449
2450 pattrib->to_fr_ds = get_tofr_ds(ptr);
2451
2452 pattrib->frag_num = GetFragNum(ptr);
2453 pattrib->seq_num = GetSequence(ptr);
2454
2455 pattrib->pw_save = GetPwrMgt(ptr);
2456 pattrib->mfrag = GetMFrag(ptr);
2457 pattrib->mdata = GetMData(ptr);
2458 pattrib->privacy = GetPrivacy(ptr);
2459 pattrib->order = GetOrder(ptr);
2460 #ifdef CONFIG_WAPI_SUPPORT
2461 sc = (pattrib->seq_num << 4) | pattrib->frag_num;
2462 #endif
2463
2464 #if 1 /* Dump rx packets */
2465 {
2466 u8 bDumpRxPkt = 0;
2467
2468 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
2469 if (bDumpRxPkt == 1) /* dump all rx packets */
2470 dump_rx_packet(ptr);
2471 else if ((bDumpRxPkt == 2) && (type == WIFI_MGT_TYPE))
2472 dump_rx_packet(ptr);
2473 else if ((bDumpRxPkt == 3) && (type == WIFI_DATA_TYPE))
2474 dump_rx_packet(ptr);
2475 }
2476 #endif
2477 switch (type) {
2478 case WIFI_MGT_TYPE: /* mgnt */
2479 DBG_COUNTER(adapter->rx_logs.core_rx_pre_mgmt);
2480 retval = validate_recv_mgnt_frame(adapter, precv_frame);
2481 if (retval == _FAIL) {
2482 DBG_COUNTER(adapter->rx_logs.core_rx_pre_mgmt_err);
2483 }
2484 retval = _FAIL; /* only data frame return _SUCCESS */
2485 break;
2486 case WIFI_CTRL_TYPE: /* ctrl */
2487 DBG_COUNTER(adapter->rx_logs.core_rx_pre_ctrl);
2488 retval = validate_recv_ctrl_frame(adapter, precv_frame);
2489 if (retval == _FAIL) {
2490 DBG_COUNTER(adapter->rx_logs.core_rx_pre_ctrl_err);
2491 }
2492 retval = _FAIL; /* only data frame return _SUCCESS */
2493 break;
2494 case WIFI_DATA_TYPE: /* data */
2495 DBG_COUNTER(adapter->rx_logs.core_rx_pre_data);
2496 #ifdef CONFIG_WAPI_SUPPORT
2497 if (pattrib->qos)
2498 external_len = 2;
2499 else
2500 external_len = 0;
2501
2502 wai_pkt = rtw_wapi_is_wai_packet(adapter, ptr);
2503
2504 phdr->bIsWaiPacket = wai_pkt;
2505
2506 if (wai_pkt != 0) {
2507 if (sc != adapter->wapiInfo.wapiSeqnumAndFragNum)
2508 adapter->wapiInfo.wapiSeqnumAndFragNum = sc;
2509 else {
2510 retval = _FAIL;
2511 DBG_COUNTER(adapter->rx_logs.core_rx_pre_data_wapi_seq_err);
2512 break;
2513 }
2514 } else {
2515
2516 if (rtw_wapi_drop_for_key_absent(adapter, get_addr2_ptr(ptr))) {
2517 retval = _FAIL;
2518 WAPI_TRACE(WAPI_RX, "drop for key absent for rx\n");
2519 DBG_COUNTER(adapter->rx_logs.core_rx_pre_data_wapi_key_err);
2520 break;
2521 }
2522 }
2523
2524 #endif
2525
2526 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
2527 retval = validate_recv_data_frame(adapter, precv_frame);
2528 if (retval == _FAIL) {
2529 precvpriv->dbg_rx_drop_count++;
2530 DBG_COUNTER(adapter->rx_logs.core_rx_pre_data_err);
2531 } else if (retval == _SUCCESS) {
2532 #ifdef DBG_RX_DUMP_EAP
2533 if (!pattrib->encrypt || pattrib->bdecrypted) {
2534 u8 bDumpRxPkt;
2535 u16 eth_type;
2536
2537 /* dump eapol */
2538 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
2539 /* get ether_type */
2540 _rtw_memcpy(ð_type, ptr + pattrib->hdrlen + pattrib->iv_len + RATTRIB_GET_MCTRL_LEN(pattrib) + LLC_HEADER_SIZE, 2);
2541 eth_type = ntohs((unsigned short) eth_type);
2542 if ((bDumpRxPkt == 4) && (eth_type == 0x888e))
2543 dump_rx_packet(ptr);
2544 }
2545 #endif
2546 } else
2547 DBG_COUNTER(adapter->rx_logs.core_rx_pre_data_handled);
2548 break;
2549 default:
2550 DBG_COUNTER(adapter->rx_logs.core_rx_pre_unknown);
2551 #ifdef DBG_RX_DROP_FRAME
2552 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" fail! type=0x%x\n"
2553 , FUNC_ADPT_ARG(adapter), type);
2554 #endif
2555 retval = _FAIL;
2556 break;
2557 }
2558
2559 exit:
2560
2561
2562 return retval;
2563 }
2564
2565 /* Reture expected handling for LLC */
rtw_recv_llc_parse(u8 * msdu,u16 msdu_len)2566 enum rtw_rx_llc_hdl rtw_recv_llc_parse(u8 *msdu, u16 msdu_len)
2567 {
2568 u16 eth_type;
2569
2570 if (msdu_len < 8)
2571 return RTW_RX_LLC_KEEP;
2572
2573 eth_type = RTW_GET_BE16(msdu + SNAP_SIZE);
2574
2575 if ((_rtw_memcmp(msdu, rtw_rfc1042_header, SNAP_SIZE)
2576 && eth_type != ETH_P_AARP && eth_type != ETH_P_IPX)
2577 || _rtw_memcmp(msdu, rtw_bridge_tunnel_header, SNAP_SIZE)) {
2578 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
2579 return RTW_RX_LLC_REMOVE;
2580 } else {
2581 /* Leave Ethernet header part of hdr and full payload */
2582 return RTW_RX_LLC_KEEP;
2583 }
2584
2585 /* TODO: VLAN tagged */
2586 }
2587
2588 /* remove the wlanhdr and add the eth_hdr */
wlanhdr_to_ethhdr(union recv_frame * precvframe,enum rtw_rx_llc_hdl llc_hdl)2589 sint wlanhdr_to_ethhdr(union recv_frame *precvframe, enum rtw_rx_llc_hdl llc_hdl)
2590 {
2591 u8 *ptr = get_recvframe_data(precvframe) ; /* point to frame_ctrl field */
2592 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
2593 sint rmv_len;
2594 u16 eth_type, len;
2595 sint ret = _SUCCESS;
2596
2597 if (pattrib->encrypt)
2598 recvframe_pull_tail(precvframe, pattrib->icv_len);
2599
2600 rmv_len = pattrib->hdrlen + pattrib->iv_len + RATTRIB_GET_MCTRL_LEN(pattrib) + (llc_hdl ? SNAP_SIZE : 0);
2601 len = precvframe->u.hdr.len - rmv_len;
2602
2603 ptr = recvframe_pull(precvframe, (rmv_len - sizeof(struct ethhdr) + (llc_hdl ? 2 : 0)));
2604 if (!ptr) {
2605 ret = _FAIL;
2606 goto exiting;
2607 }
2608
2609 _rtw_memcpy(ptr, pattrib->dst, ETH_ALEN);
2610 _rtw_memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN);
2611
2612 if (!llc_hdl) {
2613 len = htons(len);
2614 _rtw_memcpy(ptr + 12, &len, 2);
2615 }
2616
2617 rtw_rframe_set_os_pkt(precvframe);
2618
2619 exiting:
2620 return ret;
2621 }
2622
2623 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2624 #ifndef CONFIG_SDIO_RX_COPY
2625 #ifdef PLATFORM_LINUX
recvframe_expand_pkt(PADAPTER padapter,union recv_frame * prframe)2626 static void recvframe_expand_pkt(
2627 PADAPTER padapter,
2628 union recv_frame *prframe)
2629 {
2630 struct recv_frame_hdr *pfhdr;
2631 _pkt *ppkt;
2632 u8 shift_sz;
2633 u32 alloc_sz;
2634 u8 *ptr;
2635
2636
2637 pfhdr = &prframe->u.hdr;
2638
2639 /* 6 is for IP header 8 bytes alignment in QoS packet case. */
2640 if (pfhdr->attrib.qos)
2641 shift_sz = 6;
2642 else
2643 shift_sz = 0;
2644
2645 /* for first fragment packet, need to allocate */
2646 /* (1536 + RXDESC_SIZE + drvinfo_sz) to reassemble packet */
2647 /* 8 is for skb->data 8 bytes alignment.
2648 * alloc_sz = _RND(1536 + RXDESC_SIZE + pfhdr->attrib.drvinfosize + shift_sz + 8, 128); */
2649 alloc_sz = 1664; /* round (1536 + 24 + 32 + shift_sz + 8) to 128 bytes alignment */
2650
2651 /* 3 1. alloc new skb */
2652 /* prepare extra space for 4 bytes alignment */
2653 ppkt = rtw_skb_alloc(alloc_sz);
2654
2655 if (!ppkt)
2656 return; /* no way to expand */
2657
2658 /* 3 2. Prepare new skb to replace & release old skb */
2659 /* force ppkt->data at 8-byte alignment address */
2660 skb_reserve(ppkt, 8 - ((SIZE_PTR)ppkt->data & 7));
2661 /* force ip_hdr at 8-byte alignment address according to shift_sz */
2662 skb_reserve(ppkt, shift_sz);
2663
2664 /* copy data to new pkt */
2665 ptr = skb_put(ppkt, pfhdr->len);
2666 if (ptr)
2667 _rtw_memcpy(ptr, pfhdr->rx_data, pfhdr->len);
2668
2669 rtw_skb_free(pfhdr->pkt);
2670
2671 /* attach new pkt to recvframe */
2672 pfhdr->pkt = ppkt;
2673 pfhdr->rx_head = ppkt->head;
2674 pfhdr->rx_data = ppkt->data;
2675 pfhdr->rx_tail = skb_tail_pointer(ppkt);
2676 pfhdr->rx_end = skb_end_pointer(ppkt);
2677 }
2678 #else /*!= PLATFORM_LINUX*/
2679 #warning "recvframe_expand_pkt not implement, defrag may crash system"
2680 #endif
2681 #endif /*#ifndef CONFIG_SDIO_RX_COPY*/
2682 #endif
2683
2684 /* perform defrag */
2685 union recv_frame *recvframe_defrag(_adapter *adapter, _queue *defrag_q);
recvframe_defrag(_adapter * adapter,_queue * defrag_q)2686 union recv_frame *recvframe_defrag(_adapter *adapter, _queue *defrag_q)
2687 {
2688 _list *plist, *phead;
2689 u8 *data, wlanhdr_offset;
2690 u8 curfragnum;
2691 struct recv_frame_hdr *pfhdr, *pnfhdr;
2692 union recv_frame *prframe, *pnextrframe;
2693 _queue *pfree_recv_queue;
2694 u8 *pdata = NULL;
2695 u64 tmp_iv_hdr = 0;
2696 u64 pkt_pn = 0, cur_pn = 0;
2697 struct rx_pkt_attrib *pattrib = NULL;
2698
2699 curfragnum = 0;
2700 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
2701
2702 phead = get_list_head(defrag_q);
2703 plist = get_next(phead);
2704 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
2705 /* CVE-2020-26146 */
2706 pattrib = &prframe->u.hdr.attrib;
2707 if (pattrib->encrypt == _AES_ || pattrib->encrypt == _CCMP_256_
2708 || pattrib->encrypt == _GCMP_ || pattrib->encrypt == _GCMP_256_ ) {
2709 pdata = prframe->u.hdr.rx_data;
2710 tmp_iv_hdr = le64_to_cpu(*(u64*)(pdata + pattrib->hdrlen));
2711 /* get the first frame's PN. */
2712 cur_pn = CCMPH_2_PN(tmp_iv_hdr);
2713 }
2714 pfhdr = &prframe->u.hdr;
2715 rtw_list_delete(&(prframe->u.list));
2716
2717 if (curfragnum != pfhdr->attrib.frag_num) {
2718 /* the first fragment number must be 0 */
2719 /* free the whole queue */
2720 rtw_free_recvframe(prframe, pfree_recv_queue);
2721 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
2722
2723 return NULL;
2724 }
2725
2726 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2727 #ifndef CONFIG_SDIO_RX_COPY
2728 recvframe_expand_pkt(adapter, prframe);
2729 #endif
2730 #endif
2731
2732 curfragnum++;
2733
2734 plist = get_list_head(defrag_q);
2735
2736 plist = get_next(plist);
2737
2738 data = get_recvframe_data(prframe);
2739
2740 while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
2741 pnextrframe = LIST_CONTAINOR(plist, union recv_frame , u);
2742 pnfhdr = &pnextrframe->u.hdr;
2743 /* CVE-2020-26146, check whether the PN is consecutive. */
2744 pattrib = &pnextrframe->u.hdr.attrib;
2745 if (pattrib->encrypt == _AES_ || pattrib->encrypt == _CCMP_256_
2746 || pattrib->encrypt == _GCMP_ || pattrib->encrypt == _GCMP_256_ ) {
2747 pdata = pnextrframe->u.hdr.rx_data;
2748 tmp_iv_hdr = le64_to_cpu(*(u64*)(pdata + pattrib->hdrlen));
2749 pkt_pn = CCMPH_2_PN(tmp_iv_hdr);
2750 if (pkt_pn != cur_pn + 1) {
2751 RTW_INFO("%s non-consective PN! old:%llu, new:%llu\n",
2752 __func__, cur_pn, pkt_pn);
2753 /* PN must be consecutive */
2754 /* release the defrag_q & prframe */
2755 rtw_free_recvframe(prframe, pfree_recv_queue);
2756 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
2757 return NULL;
2758 } else {
2759 cur_pn = pkt_pn;
2760 }
2761 }
2762
2763 /* CVE-2020-24587, The keytrack of the fragment is supposed to be the same with other's */
2764 if (pfhdr->keytrack != pnfhdr->keytrack) {
2765 RTW_INFO("Inconsistent key track, drop fragmented frame!\n");
2766 rtw_free_recvframe(prframe, pfree_recv_queue);
2767 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
2768 return NULL;
2769 }
2770
2771 /* check the fragment sequence (2nd ~n fragment frame) */
2772
2773 if (curfragnum != pnfhdr->attrib.frag_num) {
2774 /* the fragment number must be increasing (after decache) */
2775 /* release the defrag_q & prframe */
2776 rtw_free_recvframe(prframe, pfree_recv_queue);
2777 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
2778 return NULL;
2779 }
2780
2781 /* copy the 2nd~n fragment frame's payload to the first fragment */
2782 /* get the 2nd~last fragment frame's payload */
2783
2784 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
2785
2786 recvframe_pull(pnextrframe, wlanhdr_offset);
2787
2788 if ((pfhdr->rx_end - pfhdr->rx_tail) < pnfhdr->len) {
2789 RTW_INFO("Not enough buffer space, drop fragmented frame!\n");
2790 rtw_free_recvframe(prframe, pfree_recv_queue);
2791 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
2792 return NULL;
2793 }
2794
2795 curfragnum++;
2796
2797 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
2798 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
2799
2800 /* memcpy */
2801 _rtw_memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
2802
2803 recvframe_put(prframe, pnfhdr->len);
2804
2805 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
2806 plist = get_next(plist);
2807
2808 };
2809
2810 /* free the defrag_q queue and return the prframe */
2811 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
2812
2813
2814
2815 return prframe;
2816 }
2817
2818 /* check if need to defrag, if needed queue the frame to defrag_q */
recvframe_chk_defrag(PADAPTER padapter,union recv_frame * precv_frame)2819 union recv_frame *recvframe_chk_defrag(PADAPTER padapter, union recv_frame *precv_frame)
2820 {
2821 u8 ismfrag;
2822 u8 fragnum;
2823 u8 *psta_addr;
2824 struct recv_frame_hdr *pfhdr;
2825 struct sta_info *psta;
2826 struct sta_priv *pstapriv;
2827 _list *phead;
2828 union recv_frame *prtnframe = NULL;
2829 _queue *pfree_recv_queue, *pdefrag_q = NULL;
2830
2831
2832 pstapriv = &padapter->stapriv;
2833
2834 pfhdr = &precv_frame->u.hdr;
2835
2836 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2837
2838 /* need to define struct of wlan header frame ctrl */
2839 ismfrag = pfhdr->attrib.mfrag;
2840 fragnum = pfhdr->attrib.frag_num;
2841
2842 psta_addr = pfhdr->attrib.ta;
2843 psta = rtw_get_stainfo(pstapriv, psta_addr);
2844 if (psta == NULL) {
2845 u8 type = GetFrameType(pfhdr->rx_data);
2846 if (type != WIFI_DATA_TYPE) {
2847 psta = rtw_get_bcmc_stainfo(padapter);
2848 if (psta)
2849 pdefrag_q = &psta->sta_recvpriv.defrag_q;
2850 } else
2851 pdefrag_q = NULL;
2852 } else
2853 pdefrag_q = &psta->sta_recvpriv.defrag_q;
2854
2855 if ((ismfrag == 0) && (fragnum == 0)) {
2856 prtnframe = precv_frame;/* isn't a fragment frame */
2857 } else {
2858 /* CVE-2020-26145, group addressed frame cannot use fragmentation!! */
2859 if (IS_MCAST(pfhdr->attrib.ra)) {
2860 RTW_INFO("DROP group addressed fragment!\n");
2861 rtw_free_recvframe(precv_frame, pfree_recv_queue);
2862 return NULL;
2863 }
2864 /* CVE-2020-24587 */
2865 if ((psta) && (pdefrag_q))
2866 precv_frame->u.hdr.keytrack = ATOMIC_READ(&psta->keytrack);
2867 }
2868
2869 if (ismfrag == 1) {
2870 /* 0~(n-1) fragment frame */
2871 /* enqueue to defraf_g */
2872 if (pdefrag_q != NULL) {
2873 if (fragnum == 0) {
2874 /* the first fragment */
2875 if (_rtw_queue_empty(pdefrag_q) == _FALSE) {
2876 /* free current defrag_q */
2877 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
2878 }
2879 }
2880
2881
2882 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
2883
2884 /* _rtw_spinlock(&pdefrag_q->lock); */
2885 phead = get_list_head(pdefrag_q);
2886 rtw_list_insert_tail(&pfhdr->list, phead);
2887 /* _rtw_spinunlock(&pdefrag_q->lock); */
2888
2889
2890 prtnframe = NULL;
2891
2892 } else {
2893 /* can't find this ta's defrag_queue, so free this recv_frame */
2894 rtw_free_recvframe(precv_frame, pfree_recv_queue);
2895 prtnframe = NULL;
2896 }
2897
2898 }
2899
2900 if ((ismfrag == 0) && (fragnum != 0)) {
2901 /* the last fragment frame */
2902 /* enqueue the last fragment */
2903 if (pdefrag_q != NULL) {
2904 /* _rtw_spinlock(&pdefrag_q->lock); */
2905 phead = get_list_head(pdefrag_q);
2906 rtw_list_insert_tail(&pfhdr->list, phead);
2907 /* _rtw_spinunlock(&pdefrag_q->lock); */
2908
2909 /* call recvframe_defrag to defrag */
2910 precv_frame = recvframe_defrag(padapter, pdefrag_q);
2911 prtnframe = precv_frame;
2912
2913 } else {
2914 /* can't find this ta's defrag_queue, so free this recv_frame */
2915 rtw_free_recvframe(precv_frame, pfree_recv_queue);
2916 prtnframe = NULL;
2917 }
2918
2919 }
2920
2921
2922 if ((prtnframe != NULL) && (prtnframe->u.hdr.attrib.privacy)) {
2923 /* after defrag we must check tkip mic code */
2924 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
2925 rtw_free_recvframe(prtnframe, pfree_recv_queue);
2926 prtnframe = NULL;
2927 }
2928 }
2929
2930
2931 return prtnframe;
2932
2933 }
2934
rtw_recv_indicatepkt_check(union recv_frame * rframe,u8 * ehdr_pos,u32 pkt_len)2935 static int rtw_recv_indicatepkt_check(union recv_frame *rframe, u8 *ehdr_pos, u32 pkt_len)
2936 {
2937 _adapter *adapter = rframe->u.hdr.adapter;
2938 struct recv_priv *recvpriv = &adapter->recvpriv;
2939 struct ethhdr *ehdr = (struct ethhdr *)ehdr_pos;
2940 struct rx_pkt_attrib *pattrib = &rframe->u.hdr.attrib;
2941 #ifdef DBG_IP_R_MONITOR
2942 int i;
2943 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
2944 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
2945 struct wlan_network *cur_network = &(pmlmepriv->cur_network);
2946 #endif/*DBG_IP_R_MONITOR*/
2947 enum eap_type eapol_type;
2948 int ret = _FAIL;
2949
2950 #ifdef CONFIG_WAPI_SUPPORT
2951 if (rtw_wapi_check_for_drop(adapter, rframe, ehdr_pos)) {
2952 #ifdef DBG_RX_DROP_FRAME
2953 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" rtw_wapi_check_for_drop\n"
2954 , FUNC_ADPT_ARG(adapter));
2955 #endif
2956 goto exit;
2957 }
2958 #endif
2959
2960 if (rframe->u.hdr.psta)
2961 rtw_st_ctl_rx(rframe->u.hdr.psta, ehdr_pos);
2962
2963 if (ntohs(ehdr->h_proto) == 0x888e) {
2964 eapol_type = parsing_eapol_packet(adapter, ehdr_pos + ETH_HLEN, rframe->u.hdr.psta, 0);
2965 if ((eapol_type == EAPOL_1_4 || eapol_type == EAPOL_3_4) && pattrib->encrypt == 0) {
2966 rframe->u.hdr.psta->resp_nonenc_eapol_key_starttime = rtw_get_current_time();
2967 RTW_INFO("Receive unencrypted eapol key\n");
2968 }
2969 }
2970 #ifdef DBG_ARP_DUMP
2971 else if (ntohs(ehdr->h_proto) == ETH_P_ARP)
2972 dump_arp_pkt(RTW_DBGDUMP, ehdr->h_dest, ehdr->h_source, ehdr_pos + ETH_HLEN, 0);
2973 #endif
2974
2975 if (recvpriv->sink_udpport > 0)
2976 rtw_sink_rtp_seq_dbg(adapter, ehdr_pos);
2977
2978 #ifdef DBG_UDP_PKT_LOSE_11AC
2979 #define PAYLOAD_LEN_LOC_OF_IP_HDR 0x10 /*ethernet payload length location of ip header (DA + SA+eth_type+(version&hdr_len)) */
2980
2981 if (ntohs(ehdr->h_proto) == ETH_P_ARP) {
2982 /* ARP Payload length will be 42bytes or 42+18(tailer)=60bytes*/
2983 if (pkt_len != 42 && pkt_len != 60)
2984 RTW_INFO("Error !!%s,ARP Payload length %u not correct\n" , __func__ , pkt_len);
2985 } else if (ntohs(ehdr->h_proto) == ETH_P_IP) {
2986 if (be16_to_cpu(*((u16 *)(ehdr_pos + PAYLOAD_LEN_LOC_OF_IP_HDR))) != (pkt_len) - ETH_HLEN) {
2987 RTW_INFO("Error !!%s,Payload length not correct\n" , __func__);
2988 RTW_INFO("%s, IP header describe Total length=%u\n" , __func__ , be16_to_cpu(*((u16 *)(ehdr_pos + PAYLOAD_LEN_LOC_OF_IP_HDR))));
2989 RTW_INFO("%s, Pkt real length=%u\n" , __func__ , (pkt_len) - ETH_HLEN);
2990 }
2991 }
2992 #endif
2993
2994 #ifdef DBG_IP_R_MONITOR
2995 #define LEN_ARP_OP_HDR 7 /*ARP OERATION */
2996 if (ntohs(ehdr->h_proto) == ETH_P_ARP) {
2997
2998 if(check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE){
2999 if(ehdr_pos[ETHERNET_HEADER_SIZE+LEN_ARP_OP_HDR] == 2) {
3000
3001 RTW_INFO("%s,[DBG_ARP] Rx ARP RSP Packet;SeqNum = %d !\n",
3002 __FUNCTION__, pattrib->seq_num);
3003
3004 dump_arp_pkt(RTW_DBGDUMP, ehdr->h_dest, ehdr->h_source, ehdr_pos + ETH_HLEN, 0);
3005
3006 }
3007 }
3008 }
3009 #endif/*DBG_IP_R_MONITOR*/
3010
3011 #ifdef CONFIG_AUTO_AP_MODE
3012 if (ntohs(ehdr->h_proto) == 0x8899)
3013 rtw_auto_ap_rx_msg_dump(adapter, rframe, ehdr_pos);
3014 #endif
3015
3016 ret = _SUCCESS;
3017
3018 #ifdef CONFIG_WAPI_SUPPORT
3019 exit:
3020 #endif
3021 return ret;
3022 }
3023
3024 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
recv_free_fwd_resource(_adapter * adapter,struct xmit_frame * fwd_frame,_list * f_list)3025 static void recv_free_fwd_resource(_adapter *adapter, struct xmit_frame *fwd_frame, _list *f_list)
3026 {
3027 struct xmit_priv *xmitpriv = &adapter->xmitpriv;
3028
3029 if (fwd_frame)
3030 rtw_free_xmitframe(xmitpriv, fwd_frame);
3031
3032 #if defined(CONFIG_RTW_WDS) || CONFIG_RTW_DATA_BMC_TO_UC
3033 if (!rtw_is_list_empty(f_list)) {
3034 struct xmit_frame *fframe;
3035 _list *list;
3036
3037 list = get_next(f_list);
3038 while (rtw_end_of_queue_search(f_list, list) == _FALSE) {
3039 fframe = LIST_CONTAINOR(list, struct xmit_frame, list);
3040 list = get_next(list);
3041 rtw_list_delete(&fframe->list);
3042 rtw_free_xmitframe(xmitpriv, fframe);
3043 }
3044 }
3045 #endif
3046 }
3047
recv_fwd_pkt_hdl(_adapter * adapter,_pkt * pkt,u8 act,struct xmit_frame * fwd_frame,_list * f_list)3048 static void recv_fwd_pkt_hdl(_adapter *adapter, _pkt *pkt
3049 , u8 act, struct xmit_frame *fwd_frame, _list *f_list)
3050 {
3051 struct xmit_priv *xmitpriv = &adapter->xmitpriv;
3052 _pkt *fwd_pkt = pkt;
3053
3054 if (act & RTW_RX_MSDU_ACT_INDICATE) {
3055 fwd_pkt = rtw_os_pkt_copy(pkt);
3056 if (!fwd_pkt) {
3057 #ifdef DBG_TX_DROP_FRAME
3058 RTW_INFO("DBG_TX_DROP_FRAME %s rtw_os_pkt_copy fail\n", __func__);
3059 #endif
3060 recv_free_fwd_resource(adapter, fwd_frame, f_list);
3061 goto exit;
3062 }
3063 }
3064
3065 #if defined(CONFIG_RTW_WDS) || CONFIG_RTW_DATA_BMC_TO_UC
3066 if (!rtw_is_list_empty(f_list)) {
3067 _list *list = get_next(f_list);
3068 struct xmit_frame *fframe;
3069
3070 while (rtw_end_of_queue_search(f_list, list) == _FALSE) {
3071 fframe = LIST_CONTAINOR(list, struct xmit_frame, list);
3072 list = get_next(list);
3073 rtw_list_delete(&fframe->list);
3074
3075 if (!fwd_frame && rtw_is_list_empty(f_list)) /* the last fwd_pkt */
3076 fframe->pkt = fwd_pkt;
3077 else
3078 fframe->pkt = rtw_os_pkt_copy(fwd_pkt);
3079 if (!fframe->pkt) {
3080 rtw_free_xmitframe(xmitpriv, fframe);
3081 continue;
3082 }
3083
3084 rtw_xmit_posthandle(adapter, fframe, fframe->pkt);
3085 }
3086 }
3087 #endif
3088
3089 if (fwd_frame) {
3090 fwd_frame->pkt = fwd_pkt;
3091 if (rtw_xmit_posthandle(adapter, fwd_frame, fwd_pkt) < 0) {
3092 #ifdef DBG_TX_DROP_FRAME
3093 RTW_INFO("DBG_TX_DROP_FRAME %s rtw_xmit_posthandle fail\n", __func__);
3094 #endif
3095 xmitpriv->tx_drop++;
3096 }
3097 }
3098
3099 exit:
3100 return;
3101 }
3102 #endif /* defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH) */
3103
3104 /*
3105 * From WFA suggestion: *
3106 * If first subframe meets one of the following condition, *
3107 * the whole received AMSDU should drop. *
3108 * 1. subframe's DA is not the same as RA in From DS case. *
3109 * 2. subframe's SA is not the same as TA in To DS case. *
3110 * 3. subframe's DA is AA:AA:03:00:00:00 *
3111 */
validate_amsdu_content(_adapter * padapter,union recv_frame * prframe,const u8 * da,const u8 * sa)3112 static u8 validate_amsdu_content(_adapter *padapter, union recv_frame *prframe,
3113 const u8 *da, const u8 *sa)
3114 {
3115 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
3116 u8 ret = _SUCCESS;
3117
3118 /* Use the recommendation method form Wi-Fi alliance to check subframe */
3119 /* in protected network */
3120 if (padapter->registrypriv.amsdu_mode == RTW_AMSDU_MODE_NON_SPP &&
3121 padapter->securitypriv.dot11PrivacyAlgrthm != _NO_PRIVACY_) {
3122
3123 /* 1.check From DS */
3124 if (pattrib->to_fr_ds == 2) {
3125 if (_rtw_memcmp(da, pattrib->ra, ETH_ALEN) == _FALSE)
3126 ret = _FAIL;
3127 }
3128
3129 /* 2.check To DS */
3130 if (pattrib->to_fr_ds == 1) {
3131 if (_rtw_memcmp(sa, pattrib->ta, ETH_ALEN) == _FALSE)
3132 ret = _FAIL;
3133 }
3134
3135 /* 3.Check whether DA is AA:AA:03:00:00:00 */
3136 if (_rtw_memcmp(da, rtw_rfc1042_header, ETH_ALEN) == _TRUE)
3137 ret = _FAIL;
3138
3139 }
3140
3141 return ret;
3142
3143 }
3144
amsdu_to_msdu(_adapter * padapter,union recv_frame * prframe)3145 int amsdu_to_msdu(_adapter *padapter, union recv_frame *prframe)
3146 {
3147 struct rx_pkt_attrib *rattrib = &prframe->u.hdr.attrib;
3148 int a_len, padding_len;
3149 u16 nSubframe_Length;
3150 u8 nr_subframes, i;
3151 u8 *pdata;
3152 _pkt *sub_pkt, *subframes[MAX_SUBFRAME_COUNT];
3153 struct recv_priv *precvpriv = &padapter->recvpriv;
3154 _queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
3155 const u8 *da, *sa;
3156 int act;
3157 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
3158 struct xmit_frame *fwd_frame;
3159 _list f_list;
3160 #endif
3161 enum rtw_rx_llc_hdl llc_hdl;
3162 u8 mctrl_len = 0;
3163 int ret = _SUCCESS;
3164
3165 nr_subframes = 0;
3166
3167 recvframe_pull(prframe, rattrib->hdrlen);
3168
3169 if (rattrib->iv_len > 0)
3170 recvframe_pull(prframe, rattrib->iv_len);
3171 if (rattrib->encrypt)
3172 recvframe_pull_tail(prframe, rattrib->icv_len);
3173
3174 a_len = prframe->u.hdr.len;
3175 pdata = prframe->u.hdr.rx_data;
3176
3177 while (a_len > ETH_HLEN) {
3178 /* Offset 12 denote 2 mac address */
3179 nSubframe_Length = RTW_GET_BE16(pdata + 12);
3180 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
3181 RTW_INFO("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
3182 break;
3183 }
3184
3185 act = RTW_RX_MSDU_ACT_INDICATE;
3186 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
3187 fwd_frame = NULL;
3188 #endif
3189
3190 #ifdef CONFIG_RTW_MESH
3191 if (MLME_IS_MESH(padapter)) {
3192 u8 *mda = pdata, *msa = pdata + ETH_ALEN;
3193 struct rtw_ieee80211s_hdr *mctrl = (struct rtw_ieee80211s_hdr *)(pdata + ETH_HLEN);
3194 int v_ret;
3195
3196 v_ret = rtw_mesh_rx_data_validate_mctrl(padapter, prframe
3197 , mctrl, mda, msa, &mctrl_len, &da, &sa);
3198
3199 if (validate_amsdu_content(padapter, prframe, da, sa) == _FAIL) {
3200 RTW_INFO("%s check subframe content fail!\n", __func__);
3201 break;
3202 }
3203
3204 if (v_ret != _SUCCESS)
3205 goto move_to_next;
3206
3207 llc_hdl = rtw_recv_llc_parse(pdata + ETH_HLEN + mctrl_len, nSubframe_Length - mctrl_len);
3208 act = rtw_mesh_rx_msdu_act_check(prframe
3209 , mda, msa, da, sa, mctrl
3210 , pdata + ETH_HLEN + mctrl_len, llc_hdl
3211 , &fwd_frame, &f_list);
3212 } else
3213 #endif
3214 {
3215 da = pdata;
3216 sa = pdata + ETH_ALEN;
3217
3218 if (validate_amsdu_content(padapter, prframe, da, sa) == _FAIL) {
3219 RTW_INFO("%s check subframe content fail!\n", __func__);
3220 break;
3221 }
3222
3223 llc_hdl = rtw_recv_llc_parse(pdata + ETH_HLEN, nSubframe_Length);
3224 #ifdef CONFIG_AP_MODE
3225 if (MLME_IS_AP(padapter)) {
3226 act = rtw_ap_rx_msdu_act_check(prframe, da, sa
3227 , pdata + ETH_HLEN, llc_hdl, &fwd_frame, &f_list);
3228 } else
3229 #endif
3230 if (MLME_IS_STA(padapter))
3231 act = rtw_sta_rx_amsdu_act_check(prframe, da, sa);
3232 }
3233
3234 if (!act)
3235 goto move_to_next;
3236
3237 rtw_led_rx_control(padapter, da);
3238
3239 sub_pkt = rtw_os_alloc_msdu_pkt(prframe, da, sa
3240 , pdata + ETH_HLEN + mctrl_len, nSubframe_Length - mctrl_len, llc_hdl);
3241 if (sub_pkt == NULL) {
3242 if (act & RTW_RX_MSDU_ACT_INDICATE) {
3243 #ifdef DBG_RX_DROP_FRAME
3244 RTW_INFO("DBG_RX_DROP_FRAME %s rtw_os_alloc_msdu_pkt fail\n", __func__);
3245 #endif
3246 }
3247 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
3248 if (act & RTW_RX_MSDU_ACT_FORWARD) {
3249 #ifdef DBG_TX_DROP_FRAME
3250 RTW_INFO("DBG_TX_DROP_FRAME %s rtw_os_alloc_msdu_pkt fail\n", __func__);
3251 #endif
3252 recv_free_fwd_resource(padapter, fwd_frame, &f_list);
3253 }
3254 #endif
3255 break;
3256 }
3257
3258 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
3259 if (act & RTW_RX_MSDU_ACT_FORWARD) {
3260 recv_fwd_pkt_hdl(padapter, sub_pkt, act, fwd_frame, &f_list);
3261 if (!(act & RTW_RX_MSDU_ACT_INDICATE))
3262 goto move_to_next;
3263 }
3264 #endif
3265
3266 if (rtw_recv_indicatepkt_check(prframe, rtw_os_pkt_data(sub_pkt), rtw_os_pkt_len(sub_pkt)) == _SUCCESS)
3267 subframes[nr_subframes++] = sub_pkt;
3268 else
3269 rtw_os_pkt_free(sub_pkt);
3270
3271 move_to_next:
3272 /* move the data point to data content */
3273 pdata += ETH_HLEN;
3274 a_len -= ETH_HLEN;
3275
3276 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
3277 RTW_WARN("ParseSubframe(): Too many Subframes! Packets dropped!\n");
3278 break;
3279 }
3280
3281 pdata += nSubframe_Length;
3282 a_len -= nSubframe_Length;
3283 if (a_len != 0) {
3284 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4 - 1));
3285 if (padding_len == 4)
3286 padding_len = 0;
3287
3288 if (a_len < padding_len) {
3289 RTW_INFO("ParseSubframe(): a_len < padding_len !\n");
3290 break;
3291 }
3292 pdata += padding_len;
3293 a_len -= padding_len;
3294 }
3295 }
3296
3297 for (i = 0; i < nr_subframes; i++) {
3298 sub_pkt = subframes[i];
3299
3300 /* Indicat the packets to upper layer */
3301 if (sub_pkt)
3302 rtw_os_recv_indicate_pkt(padapter, sub_pkt, prframe);
3303 }
3304
3305 prframe->u.hdr.len = 0;
3306 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
3307
3308 return ret;
3309 }
3310
recv_process_mpdu(_adapter * padapter,union recv_frame * prframe)3311 static int recv_process_mpdu(_adapter *padapter, union recv_frame *prframe)
3312 {
3313 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
3314 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
3315 int ret;
3316
3317 if (pattrib->amsdu) {
3318 ret = amsdu_to_msdu(padapter, prframe);
3319 if (ret != _SUCCESS) {
3320 #ifdef DBG_RX_DROP_FRAME
3321 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" amsdu_to_msdu fail\n"
3322 , FUNC_ADPT_ARG(padapter));
3323 #endif
3324 rtw_free_recvframe(prframe, pfree_recv_queue);
3325 goto exit;
3326 }
3327 } else {
3328 u8 *msdu = get_recvframe_data(prframe)
3329 + pattrib->hdrlen + pattrib->iv_len + RATTRIB_GET_MCTRL_LEN(pattrib);
3330 u16 msdu_len = prframe->u.hdr.len
3331 - pattrib->hdrlen - pattrib->iv_len - RATTRIB_GET_MCTRL_LEN(pattrib)
3332 - (pattrib->encrypt ? pattrib->icv_len : 0);
3333 enum rtw_rx_llc_hdl llc_hdl = rtw_recv_llc_parse(msdu, msdu_len);
3334 int act = RTW_RX_MSDU_ACT_INDICATE;
3335
3336 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
3337 struct xmit_frame *fwd_frame = NULL;
3338 _list f_list;
3339
3340 #ifdef CONFIG_RTW_MESH
3341 if (MLME_IS_MESH(padapter)) {
3342 if (pattrib->mesh_ctrl_present)
3343 act = rtw_mesh_rx_msdu_act_check(prframe
3344 , pattrib->mda, pattrib->msa
3345 , pattrib->dst, pattrib->src
3346 , (struct rtw_ieee80211s_hdr *)(msdu - RATTRIB_GET_MCTRL_LEN(pattrib))
3347 , msdu, llc_hdl
3348 , &fwd_frame, &f_list);
3349 } else
3350 #endif
3351 if (MLME_IS_AP(padapter))
3352 act = rtw_ap_rx_msdu_act_check(prframe, pattrib->dst, pattrib->src
3353 , msdu, llc_hdl, &fwd_frame, &f_list);
3354 #endif
3355
3356 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
3357 if (!act) {
3358 rtw_free_recvframe(prframe, pfree_recv_queue);
3359 ret = _FAIL;
3360 goto exit;
3361 }
3362 #endif
3363
3364 rtw_led_rx_control(padapter, pattrib->dst);
3365
3366 ret = wlanhdr_to_ethhdr(prframe, llc_hdl);
3367 if (ret != _SUCCESS) {
3368 if (act & RTW_RX_MSDU_ACT_INDICATE) {
3369 #ifdef DBG_RX_DROP_FRAME
3370 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" wlanhdr_to_ethhdr: drop pkt\n"
3371 , FUNC_ADPT_ARG(padapter));
3372 #endif
3373 }
3374 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
3375 if (act & RTW_RX_MSDU_ACT_FORWARD) {
3376 #ifdef DBG_TX_DROP_FRAME
3377 RTW_INFO("DBG_TX_DROP_FRAME %s wlanhdr_to_ethhdr fail\n", __func__);
3378 #endif
3379 recv_free_fwd_resource(padapter, fwd_frame, &f_list);
3380 }
3381 #endif
3382 rtw_free_recvframe(prframe, pfree_recv_queue);
3383 goto exit;
3384 }
3385
3386 #if defined(CONFIG_AP_MODE) || defined(CONFIG_RTW_MESH)
3387 if (act & RTW_RX_MSDU_ACT_FORWARD) {
3388 recv_fwd_pkt_hdl(padapter, prframe->u.hdr.pkt, act, fwd_frame, &f_list);
3389 if (!(act & RTW_RX_MSDU_ACT_INDICATE)) {
3390 prframe->u.hdr.pkt = NULL;
3391 rtw_free_recvframe(prframe, pfree_recv_queue);
3392 goto exit;
3393 }
3394 }
3395 #endif
3396
3397 if (!RTW_CANNOT_RUN(padapter)) {
3398 ret = rtw_recv_indicatepkt_check(prframe
3399 , get_recvframe_data(prframe), get_recvframe_len(prframe));
3400 if (ret != _SUCCESS) {
3401 rtw_free_recvframe(prframe, pfree_recv_queue);
3402 goto exit;
3403 }
3404
3405 /* indicate this recv_frame */
3406 ret = rtw_recv_indicatepkt(padapter, prframe);
3407 if (ret != _SUCCESS) {
3408 #ifdef DBG_RX_DROP_FRAME
3409 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" rtw_recv_indicatepkt fail!\n"
3410 , FUNC_ADPT_ARG(padapter));
3411 #endif
3412 goto exit;
3413 }
3414 } else {
3415 #ifdef DBG_RX_DROP_FRAME
3416 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" DS:%u SR:%u\n"
3417 , FUNC_ADPT_ARG(padapter)
3418 , rtw_is_drv_stopped(padapter)
3419 , rtw_is_surprise_removed(padapter));
3420 #endif
3421 ret = _SUCCESS; /* don't count as packet drop */
3422 rtw_free_recvframe(prframe, pfree_recv_queue);
3423 }
3424 }
3425
3426 exit:
3427 return ret;
3428 }
3429
3430 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
check_indicate_seq(struct recv_reorder_ctrl * preorder_ctrl,u16 seq_num)3431 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
3432 {
3433 PADAPTER padapter = preorder_ctrl->padapter;
3434 struct recv_priv *precvpriv = &padapter->recvpriv;
3435 u8 wsize = preorder_ctrl->wsize_b;
3436 u16 wend;
3437
3438 /* Rx Reorder initialize condition. */
3439 if (preorder_ctrl->indicate_seq == 0xFFFF) {
3440 preorder_ctrl->indicate_seq = seq_num;
3441 #ifdef DBG_RX_SEQ
3442 RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" tid:%u SN_INIT indicate_seq:%d, seq_num:%d\n"
3443 , FUNC_ADPT_ARG(padapter), preorder_ctrl->tid, preorder_ctrl->indicate_seq, seq_num);
3444 #endif
3445 }
3446 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF; /* % 4096; */
3447
3448 /* Drop out the packet which SeqNum is smaller than WinStart */
3449 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq)) {
3450 #ifdef DBG_RX_DROP_FRAME
3451 RTW_INFO(FUNC_ADPT_FMT" tid:%u indicate_seq:%d > seq_num:%d\n"
3452 , FUNC_ADPT_ARG(padapter), preorder_ctrl->tid, preorder_ctrl->indicate_seq, seq_num);
3453 #endif
3454 return _FALSE;
3455 }
3456
3457 /*
3458 * Sliding window manipulation. Conditions includes:
3459 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
3460 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
3461 */
3462 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
3463 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
3464 #ifdef DBG_RX_SEQ
3465 RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" tid:%u SN_EQUAL indicate_seq:%d, seq_num:%d\n"
3466 , FUNC_ADPT_ARG(padapter), preorder_ctrl->tid, preorder_ctrl->indicate_seq, seq_num);
3467 #endif
3468
3469 } else if (SN_LESS(wend, seq_num)) {
3470 /* boundary situation, when seq_num cross 0xFFF */
3471 if (seq_num >= (wsize - 1))
3472 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
3473 else
3474 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
3475
3476 precvpriv->dbg_rx_ampdu_window_shift_cnt++;
3477 #ifdef DBG_RX_SEQ
3478 RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" tid:%u SN_LESS(wend, seq_num) indicate_seq:%d, seq_num:%d\n"
3479 , FUNC_ADPT_ARG(padapter), preorder_ctrl->tid, preorder_ctrl->indicate_seq, seq_num);
3480 #endif
3481 }
3482
3483 return _TRUE;
3484 }
3485
enqueue_reorder_recvframe(struct recv_reorder_ctrl * preorder_ctrl,union recv_frame * prframe)3486 static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, union recv_frame *prframe)
3487 {
3488 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
3489 _queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
3490 _list *phead, *plist;
3491 union recv_frame *pnextrframe;
3492 struct rx_pkt_attrib *pnextattrib;
3493
3494 /* DbgPrint("+enqueue_reorder_recvframe()\n"); */
3495
3496 /* _enter_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3497 /* _rtw_spinlock_ex(&ppending_recvframe_queue->lock); */
3498
3499
3500 phead = get_list_head(ppending_recvframe_queue);
3501 plist = get_next(phead);
3502
3503 while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
3504 pnextrframe = LIST_CONTAINOR(plist, union recv_frame, u);
3505 pnextattrib = &pnextrframe->u.hdr.attrib;
3506
3507 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
3508 plist = get_next(plist);
3509 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num)) {
3510 /* Duplicate entry is found!! Do not insert current entry. */
3511
3512 /* _exit_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3513
3514 return _FALSE;
3515 } else
3516 break;
3517
3518 /* DbgPrint("enqueue_reorder_recvframe():while\n"); */
3519
3520 }
3521
3522
3523 /* _enter_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3524 /* _rtw_spinlock_ex(&ppending_recvframe_queue->lock); */
3525
3526 rtw_list_delete(&(prframe->u.hdr.list));
3527
3528 rtw_list_insert_tail(&(prframe->u.hdr.list), plist);
3529
3530 /* _rtw_spinunlock_ex(&ppending_recvframe_queue->lock); */
3531 /* _exit_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3532
3533
3534 return _TRUE;
3535
3536 }
3537
recv_indicatepkts_pkt_loss_cnt(_adapter * padapter,u64 prev_seq,u64 current_seq)3538 static void recv_indicatepkts_pkt_loss_cnt(_adapter *padapter, u64 prev_seq, u64 current_seq)
3539 {
3540 struct recv_priv *precvpriv = &padapter->recvpriv;
3541
3542 if (current_seq < prev_seq) {
3543 precvpriv->dbg_rx_ampdu_loss_count += (4096 + current_seq - prev_seq);
3544 precvpriv->rx_drop += (4096 + current_seq - prev_seq);
3545 } else {
3546 precvpriv->dbg_rx_ampdu_loss_count += (current_seq - prev_seq);
3547 precvpriv->rx_drop += (current_seq - prev_seq);
3548 }
3549 }
3550
recv_indicatepkts_in_order(_adapter * padapter,struct recv_reorder_ctrl * preorder_ctrl,int bforced)3551 static int recv_indicatepkts_in_order(_adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
3552 {
3553 /* _irqL irql; */
3554 _list *phead, *plist;
3555 union recv_frame *prframe;
3556 struct rx_pkt_attrib *pattrib;
3557 /* u8 index = 0; */
3558 int bPktInBuf = _FALSE;
3559 struct recv_priv *precvpriv = &padapter->recvpriv;
3560 _queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
3561
3562 DBG_COUNTER(padapter->rx_logs.core_rx_post_indicate_in_oder);
3563
3564 /* DbgPrint("+recv_indicatepkts_in_order\n"); */
3565
3566 /* _enter_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3567 /* _rtw_spinlock_ex(&ppending_recvframe_queue->lock); */
3568
3569 phead = get_list_head(ppending_recvframe_queue);
3570 plist = get_next(phead);
3571
3572 #if 0
3573 /* Check if there is any other indication thread running. */
3574 if (pTS->RxIndicateState == RXTS_INDICATE_PROCESSING)
3575 return;
3576 #endif
3577
3578 /* Handling some condition for forced indicate case. */
3579 if (bforced == _TRUE) {
3580 precvpriv->dbg_rx_ampdu_forced_indicate_count++;
3581 if (rtw_is_list_empty(phead)) {
3582 /* _exit_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3583 /* _rtw_spinunlock_ex(&ppending_recvframe_queue->lock); */
3584 return _TRUE;
3585 }
3586
3587 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
3588 pattrib = &prframe->u.hdr.attrib;
3589
3590 #ifdef DBG_RX_SEQ
3591 RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" tid:%u FORCE indicate_seq:%d, seq_num:%d\n"
3592 , FUNC_ADPT_ARG(padapter), preorder_ctrl->tid, preorder_ctrl->indicate_seq, pattrib->seq_num);
3593 #endif
3594 recv_indicatepkts_pkt_loss_cnt(padapter, preorder_ctrl->indicate_seq, pattrib->seq_num);
3595 preorder_ctrl->indicate_seq = pattrib->seq_num;
3596 }
3597
3598 /* Prepare indication list and indication. */
3599 /* Check if there is any packet need indicate. */
3600 while (!rtw_is_list_empty(phead)) {
3601
3602 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
3603 pattrib = &prframe->u.hdr.attrib;
3604
3605 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
3606
3607 #if 0
3608 /* This protect buffer from overflow. */
3609 if (index >= REORDER_WIN_SIZE) {
3610 RT_ASSERT(FALSE, ("IndicateRxReorderList(): Buffer overflow!!\n"));
3611 bPktInBuf = TRUE;
3612 break;
3613 }
3614 #endif
3615
3616 plist = get_next(plist);
3617 rtw_list_delete(&(prframe->u.hdr.list));
3618
3619 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
3620 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
3621 #ifdef DBG_RX_SEQ
3622 RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" tid:%u SN_EQUAL indicate_seq:%d, seq_num:%d\n"
3623 , FUNC_ADPT_ARG(padapter), preorder_ctrl->tid, preorder_ctrl->indicate_seq, pattrib->seq_num);
3624 #endif
3625 }
3626
3627 #if 0
3628 index++;
3629 if (index == 1) {
3630 /* Cancel previous pending timer. */
3631 /* PlatformCancelTimer(Adapter, &pTS->RxPktPendingTimer); */
3632 if (bforced != _TRUE) {
3633 /* RTW_INFO("_cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);\n"); */
3634 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
3635 }
3636 }
3637 #endif
3638
3639 /* Set this as a lock to make sure that only one thread is indicating packet. */
3640 /* pTS->RxIndicateState = RXTS_INDICATE_PROCESSING; */
3641
3642 /* Indicate packets */
3643 /* RT_ASSERT((index<=REORDER_WIN_SIZE), ("RxReorderIndicatePacket(): Rx Reorder buffer full!!\n")); */
3644
3645
3646 /* indicate this recv_frame */
3647 /* DbgPrint("recv_indicatepkts_in_order, indicate_seq=%d, seq_num=%d\n", precvpriv->indicate_seq, pattrib->seq_num); */
3648 if (recv_process_mpdu(padapter, prframe) != _SUCCESS)
3649 precvpriv->dbg_rx_drop_count++;
3650
3651 /* Update local variables. */
3652 bPktInBuf = _FALSE;
3653
3654 } else {
3655 bPktInBuf = _TRUE;
3656 break;
3657 }
3658
3659 /* DbgPrint("recv_indicatepkts_in_order():while\n"); */
3660
3661 }
3662
3663 /* _rtw_spinunlock_ex(&ppending_recvframe_queue->lock); */
3664 /* _exit_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3665
3666 #if 0
3667 /* Release the indication lock and set to new indication step. */
3668 if (bPktInBuf) {
3669 /* Set new pending timer. */
3670 /* pTS->RxIndicateState = RXTS_INDICATE_REORDER; */
3671 /* PlatformSetTimer(Adapter, &pTS->RxPktPendingTimer, pHTInfo->RxReorderPendingTime); */
3672
3673 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
3674 } else {
3675 /* pTS->RxIndicateState = RXTS_INDICATE_IDLE; */
3676 }
3677 #endif
3678 /* _exit_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3679
3680 /* return _TRUE; */
3681 return bPktInBuf;
3682
3683 }
3684
recv_indicatepkt_reorder(_adapter * padapter,union recv_frame * prframe)3685 static int recv_indicatepkt_reorder(_adapter *padapter, union recv_frame *prframe)
3686 {
3687 _irqL irql;
3688 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
3689 struct recv_reorder_ctrl *preorder_ctrl = prframe->u.hdr.preorder_ctrl;
3690 _queue *ppending_recvframe_queue = preorder_ctrl ? &preorder_ctrl->pending_recvframe_queue : NULL;
3691 struct recv_priv *precvpriv = &padapter->recvpriv;
3692
3693 if (!pattrib->qos || !preorder_ctrl || preorder_ctrl->enable == _FALSE)
3694 goto _success_exit;
3695
3696
3697 DBG_COUNTER(padapter->rx_logs.core_rx_post_indicate_reoder);
3698
3699 _enter_critical_bh(&ppending_recvframe_queue->lock, &irql);
3700
3701
3702 if(rtw_test_and_clear_bit(RTW_RECV_ACK_OR_TIMEOUT, &preorder_ctrl->rec_abba_rsp_ack))
3703 preorder_ctrl->indicate_seq = 0xFFFF;
3704 if(rtw_test_and_clear_bit(RTW_RECV_REORDER_WOW, &preorder_ctrl->rec_abba_rsp_ack)) {
3705 preorder_ctrl->indicate_seq = 0xFFFF;
3706 RTW_INFO("DBG_RX_SEQ %s:preorder_ctrl->rec_abba_rsp_ack = %lu,indicate_seq = %d\n"
3707 , __func__
3708 , preorder_ctrl->rec_abba_rsp_ack
3709 , preorder_ctrl->indicate_seq);
3710 }
3711 #ifdef DBG_RX_SEQ
3712 RTW_INFO("DBG_RX_SEQ %s:preorder_ctrl->rec_abba_rsp_ack = %lu,indicate_seq = %d\n"
3713 , __func__
3714 , preorder_ctrl->rec_abba_rsp_ack
3715 , preorder_ctrl->indicate_seq);
3716 #endif
3717
3718 /* s2. check if winstart_b(indicate_seq) needs to been updated */
3719 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) {
3720 precvpriv->dbg_rx_ampdu_drop_count++;
3721 /* pHTInfo->RxReorderDropCounter++; */
3722 /* ReturnRFDList(Adapter, pRfd); */
3723 /* _exit_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3724 /* return _FAIL; */
3725
3726 #ifdef DBG_RX_DROP_FRAME
3727 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" check_indicate_seq fail\n"
3728 , FUNC_ADPT_ARG(padapter));
3729 #endif
3730 #if 0
3731 rtw_recv_indicatepkt(padapter, prframe);
3732
3733 _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
3734
3735 goto _success_exit;
3736 #else
3737 goto _err_exit;
3738 #endif
3739 }
3740
3741
3742 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
3743 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe)) {
3744 /* DbgPrint("recv_indicatepkt_reorder, enqueue_reorder_recvframe fail!\n"); */
3745 /* _exit_critical_ex(&ppending_recvframe_queue->lock, &irql); */
3746 /* return _FAIL; */
3747 #ifdef DBG_RX_DROP_FRAME
3748 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" enqueue_reorder_recvframe fail\n"
3749 , FUNC_ADPT_ARG(padapter));
3750 #endif
3751 goto _err_exit;
3752 }
3753
3754
3755 /* s4. */
3756 /* Indication process. */
3757 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
3758 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
3759 /* */
3760 /* For Rx Reorder condition: */
3761 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
3762 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
3763 /* */
3764
3765 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, _TRUE); */
3766 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, _FALSE) == _TRUE) {
3767 if (!preorder_ctrl->bReorderWaiting) {
3768 preorder_ctrl->bReorderWaiting = _TRUE;
3769 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
3770 }
3771 _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
3772 } else {
3773 preorder_ctrl->bReorderWaiting = _FALSE;
3774 _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
3775 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
3776 }
3777
3778 return RTW_RX_HANDLED;
3779
3780 _success_exit:
3781
3782 return _SUCCESS;
3783
3784 _err_exit:
3785
3786 _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
3787
3788 return _FAIL;
3789 }
3790
3791
rtw_reordering_ctrl_timeout_handler(void * pcontext)3792 void rtw_reordering_ctrl_timeout_handler(void *pcontext)
3793 {
3794 _irqL irql;
3795 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)pcontext;
3796 _adapter *padapter = NULL;
3797 _queue *ppending_recvframe_queue = NULL;
3798
3799
3800 if (preorder_ctrl == NULL)
3801 return;
3802
3803 padapter = preorder_ctrl->padapter;
3804 if (RTW_CANNOT_RUN(padapter))
3805 return;
3806
3807 ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
3808
3809 /* RTW_INFO("+rtw_reordering_ctrl_timeout_handler()=>\n"); */
3810
3811 _enter_critical_bh(&ppending_recvframe_queue->lock, &irql);
3812
3813 preorder_ctrl->bReorderWaiting = _FALSE;
3814
3815 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, _TRUE) == _TRUE)
3816 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
3817
3818 _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
3819
3820 }
3821 #endif /* defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL) */
3822
recv_set_iseq_before_mpdu_process(union recv_frame * rframe,u16 seq_num,const char * caller)3823 static void recv_set_iseq_before_mpdu_process(union recv_frame *rframe, u16 seq_num, const char *caller)
3824 {
3825 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
3826 struct recv_reorder_ctrl *reorder_ctrl = rframe->u.hdr.preorder_ctrl;
3827
3828 if (reorder_ctrl) {
3829 reorder_ctrl->indicate_seq = seq_num;
3830 #ifdef DBG_RX_SEQ
3831 RTW_INFO("DBG_RX_SEQ %s("ADPT_FMT")-B tid:%u indicate_seq:%d, seq_num:%d\n"
3832 , caller, ADPT_ARG(reorder_ctrl->padapter)
3833 , reorder_ctrl->tid, reorder_ctrl->indicate_seq, seq_num);
3834 #endif
3835 }
3836 #endif
3837 }
3838
recv_set_iseq_after_mpdu_process(union recv_frame * rframe,u16 seq_num,const char * caller)3839 static void recv_set_iseq_after_mpdu_process(union recv_frame *rframe, u16 seq_num, const char *caller)
3840 {
3841 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
3842 struct recv_reorder_ctrl *reorder_ctrl = rframe->u.hdr.preorder_ctrl;
3843
3844 if (reorder_ctrl) {
3845 reorder_ctrl->indicate_seq = (reorder_ctrl->indicate_seq + 1) % 4096;
3846 #ifdef DBG_RX_SEQ
3847 RTW_INFO("DBG_RX_SEQ %s("ADPT_FMT")-A tid:%u indicate_seq:%d, seq_num:%d\n"
3848 , caller, ADPT_ARG(reorder_ctrl->padapter)
3849 , reorder_ctrl->tid, reorder_ctrl->indicate_seq, seq_num);
3850 #endif
3851 }
3852 #endif
3853 }
3854
3855 #ifdef CONFIG_MP_INCLUDED
validate_mp_recv_frame(_adapter * adapter,union recv_frame * precv_frame)3856 int validate_mp_recv_frame(_adapter *adapter, union recv_frame *precv_frame)
3857 {
3858 int ret = _SUCCESS;
3859 u8 *ptr = precv_frame->u.hdr.rx_data;
3860 u8 type, subtype;
3861 struct mp_priv *pmppriv = &adapter->mppriv;
3862 struct mp_tx *pmptx;
3863 unsigned char *sa , *da, *bs;
3864 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
3865 u32 i = 0;
3866 u8 rtk_prefix[]={0x52, 0x65, 0x61, 0x6C, 0x4C, 0x6F, 0x76, 0x65, 0x54, 0x65, 0x6B};
3867 u8 *prx_data;
3868 pmptx = &pmppriv->tx;
3869
3870
3871 if (pmppriv->mplink_brx == _FALSE) {
3872
3873 u8 bDumpRxPkt = 0;
3874 type = GetFrameType(ptr);
3875 subtype = get_frame_sub_type(ptr); /* bit(7)~bit(2) */
3876
3877 RTW_DBG("hdr len = %d iv_len=%d \n", pattrib->hdrlen , pattrib->iv_len);
3878 prx_data = ptr + pattrib->hdrlen + pattrib->iv_len;
3879
3880 for (i = 0; i < precv_frame->u.hdr.len; i++) {
3881 if (precv_frame->u.hdr.len < (11 + i))
3882 break;
3883
3884 if (_rtw_memcmp(prx_data + i, (void *)&rtk_prefix, 11) == _FALSE) {
3885 bDumpRxPkt = 0;
3886 RTW_DBG("prx_data = %02X != rtk_prefix[%d] = %02X \n", *(prx_data + i), i , rtk_prefix[i]);
3887 } else {
3888 bDumpRxPkt = 1;
3889 RTW_DBG("prx_data = %02X = rtk_prefix[%d] = %02X \n", *(prx_data + i), i , rtk_prefix[i]);
3890 break;
3891 }
3892 }
3893
3894 if (bDumpRxPkt == 1) { /* dump all rx packets */
3895 int i;
3896 RTW_INFO("############ type:0x%02x subtype:0x%02x #################\n", type, subtype);
3897
3898 for (i = 0; i < precv_frame->u.hdr.len; i = i + 8)
3899 RTW_INFO("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr + i),
3900 *(ptr + i + 1), *(ptr + i + 2) , *(ptr + i + 3) , *(ptr + i + 4), *(ptr + i + 5), *(ptr + i + 6), *(ptr + i + 7));
3901 RTW_INFO("#############################\n");
3902 _rtw_memset(pmppriv->mplink_buf, '\0' , sizeof(pmppriv->mplink_buf));
3903 _rtw_memcpy(pmppriv->mplink_buf, ptr, precv_frame->u.hdr.len);
3904 pmppriv->mplink_rx_len = precv_frame->u.hdr.len;
3905 pmppriv->mplink_brx =_TRUE;
3906 }
3907 }
3908 if (pmppriv->bloopback) {
3909 if (_rtw_memcmp(ptr + 24, pmptx->buf + 24, precv_frame->u.hdr.len - 24) == _FALSE) {
3910 RTW_INFO("Compare payload content Fail !!!\n");
3911 ret = _FAIL;
3912 }
3913 }
3914 if (pmppriv->bSetRxBssid == _TRUE) {
3915
3916 sa = get_addr2_ptr(ptr);
3917 da = GetAddr1Ptr(ptr);
3918 bs = GetAddr3Ptr(ptr);
3919 type = GetFrameType(ptr);
3920 subtype = get_frame_sub_type(ptr); /* bit(7)~bit(2) */
3921
3922 if (_rtw_memcmp(bs, adapter->mppriv.network_macaddr, ETH_ALEN) == _FALSE)
3923 ret = _FAIL;
3924
3925 RTW_DBG("############ type:0x%02x subtype:0x%02x #################\n", type, subtype);
3926 RTW_DBG("A2 sa %02X:%02X:%02X:%02X:%02X:%02X \n", *(sa) , *(sa + 1), *(sa+ 2), *(sa + 3), *(sa + 4), *(sa + 5));
3927 RTW_DBG("A1 da %02X:%02X:%02X:%02X:%02X:%02X \n", *(da) , *(da + 1), *(da+ 2), *(da + 3), *(da + 4), *(da + 5));
3928 RTW_DBG("A3 bs %02X:%02X:%02X:%02X:%02X:%02X \n --------------------------\n", *(bs) , *(bs + 1), *(bs+ 2), *(bs + 3), *(bs + 4), *(bs + 5));
3929 }
3930
3931 if (!adapter->mppriv.bmac_filter)
3932 return ret;
3933
3934 if (_rtw_memcmp(get_addr2_ptr(ptr), adapter->mppriv.mac_filter, ETH_ALEN) == _FALSE)
3935 ret = _FAIL;
3936
3937 return ret;
3938 }
3939
MPwlanhdr_to_ethhdr(union recv_frame * precvframe)3940 static sint MPwlanhdr_to_ethhdr(union recv_frame *precvframe)
3941 {
3942 sint rmv_len;
3943 u16 len;
3944 u8 mcastheadermac[] = {0x01, 0x00, 0x5e};
3945 sint ret = _SUCCESS;
3946 _adapter *adapter = precvframe->u.hdr.adapter;
3947
3948 u8 *ptr = get_recvframe_data(precvframe) ; /* point to frame_ctrl field */
3949 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
3950 enum rtw_rx_llc_hdl llc_hdl;
3951
3952
3953 if (pattrib->encrypt)
3954 recvframe_pull_tail(precvframe, pattrib->icv_len);
3955
3956 llc_hdl = rtw_recv_llc_parse(ptr + pattrib->hdrlen + pattrib->iv_len
3957 , precvframe->u.hdr.len - pattrib->hdrlen - pattrib->iv_len);
3958
3959 rmv_len = pattrib->hdrlen + pattrib->iv_len + (llc_hdl ? SNAP_SIZE : 0);
3960 len = precvframe->u.hdr.len - rmv_len;
3961
3962 ptr = recvframe_pull(precvframe, (rmv_len - sizeof(struct ethhdr) + (llc_hdl ? 2 : 0)));
3963
3964 _rtw_memcpy(ptr, pattrib->dst, ETH_ALEN);
3965 _rtw_memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN);
3966
3967 if (!llc_hdl) {
3968 len = htons(len);
3969 _rtw_memcpy(ptr + 12, &len, 2);
3970 }
3971
3972
3973 len = htons(pattrib->seq_num);
3974 /* RTW_INFO("wlan seq = %d ,seq_num =%x\n",len,pattrib->seq_num); */
3975 _rtw_memcpy(ptr + 12, &len, 2);
3976 if (adapter->mppriv.bRTWSmbCfg == _TRUE) {
3977 /* if(_rtw_memcmp(mcastheadermac, pattrib->dst, 3) == _TRUE) */ /* SimpleConfig Dest. */
3978 /* _rtw_memcpy(ptr+ETH_ALEN, pattrib->bssid, ETH_ALEN); */
3979
3980 if (_rtw_memcmp(mcastheadermac, pattrib->bssid, 3) == _TRUE) /* SimpleConfig Dest. */
3981 _rtw_memcpy(ptr, pattrib->bssid, ETH_ALEN);
3982
3983 }
3984
3985
3986 return ret;
3987
3988 }
3989
3990
mp_recv_frame(_adapter * padapter,union recv_frame * rframe)3991 int mp_recv_frame(_adapter *padapter, union recv_frame *rframe)
3992 {
3993 int ret = _SUCCESS;
3994 struct rx_pkt_attrib *pattrib = &rframe->u.hdr.attrib;
3995 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
3996 #ifdef CONFIG_MP_INCLUDED
3997 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3998 struct mp_priv *pmppriv = &padapter->mppriv;
3999 #endif /* CONFIG_MP_INCLUDED */
4000 u8 type;
4001 u8 *ptr = rframe->u.hdr.rx_data;
4002 u8 *psa, *pda, *pbssid;
4003 struct sta_info *psta = NULL;
4004 DBG_COUNTER(padapter->rx_logs.core_rx_pre);
4005
4006 if ((check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)) { /* &&(padapter->mppriv.check_mp_pkt == 0)) */
4007 if (pattrib->crc_err == 1)
4008 padapter->mppriv.rx_crcerrpktcount++;
4009 else {
4010 if (_SUCCESS == validate_mp_recv_frame(padapter, rframe))
4011 padapter->mppriv.rx_pktcount++;
4012 else
4013 padapter->mppriv.rx_pktcount_filter_out++;
4014 }
4015
4016 if (pmppriv->rx_bindicatePkt == _FALSE) {
4017 ret = _FAIL;
4018 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
4019 goto exit;
4020 } else {
4021 type = GetFrameType(ptr);
4022 pattrib->to_fr_ds = get_tofr_ds(ptr);
4023 pattrib->frag_num = GetFragNum(ptr);
4024 pattrib->seq_num = GetSequence(ptr);
4025 pattrib->pw_save = GetPwrMgt(ptr);
4026 pattrib->mfrag = GetMFrag(ptr);
4027 pattrib->mdata = GetMData(ptr);
4028 pattrib->privacy = GetPrivacy(ptr);
4029 pattrib->order = GetOrder(ptr);
4030
4031 if (type == WIFI_DATA_TYPE) {
4032 pda = get_da(ptr);
4033 psa = get_sa(ptr);
4034 pbssid = get_hdr_bssid(ptr);
4035
4036 _rtw_memcpy(pattrib->dst, pda, ETH_ALEN);
4037 _rtw_memcpy(pattrib->src, psa, ETH_ALEN);
4038 _rtw_memcpy(pattrib->bssid, pbssid, ETH_ALEN);
4039
4040 switch (pattrib->to_fr_ds) {
4041 case 0:
4042 _rtw_memcpy(pattrib->ra, pda, ETH_ALEN);
4043 _rtw_memcpy(pattrib->ta, psa, ETH_ALEN);
4044 ret = sta2sta_data_frame(padapter, rframe, &psta);
4045 break;
4046 case 1:
4047 _rtw_memcpy(pattrib->ra, pbssid, ETH_ALEN);
4048 _rtw_memcpy(pattrib->ta, psa, ETH_ALEN);
4049 ret = sta2ap_data_frame(padapter, rframe, &psta);
4050 break;
4051 case 2:
4052 _rtw_memcpy(pattrib->ra, pda, ETH_ALEN);
4053 _rtw_memcpy(pattrib->ta, pbssid, ETH_ALEN);
4054 ret = ap2sta_data_frame(padapter, rframe, &psta);
4055 break;
4056 case 3:
4057 _rtw_memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
4058 _rtw_memcpy(pattrib->ta, get_addr2_ptr(ptr), ETH_ALEN);
4059 ret = _FAIL;
4060 break;
4061 default:
4062 ret = _FAIL;
4063 break;
4064 }
4065
4066 if (ret != _SUCCESS) {
4067 #ifdef DBG_RX_DROP_FRAME
4068 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" 2_data_frame fail: drop pkt\n"
4069 , FUNC_ADPT_ARG(padapter));
4070 #endif
4071 ret = _FAIL;
4072 goto exit;
4073 }
4074
4075 ret = MPwlanhdr_to_ethhdr(rframe);
4076
4077 if (ret != _SUCCESS) {
4078 #ifdef DBG_RX_DROP_FRAME
4079 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" wlanhdr_to_ethhdr: drop pkt\n"
4080 , FUNC_ADPT_ARG(padapter));
4081 #endif
4082 ret = _FAIL;
4083 goto exit;
4084 }
4085 if (!RTW_CANNOT_RUN(padapter)) {
4086 /* indicate this recv_frame */
4087 ret = rtw_recv_indicatepkt(padapter, rframe);
4088 if (ret != _SUCCESS) {
4089 #ifdef DBG_RX_DROP_FRAME
4090 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" rtw_recv_indicatepkt fail!\n"
4091 , FUNC_ADPT_ARG(padapter));
4092 #endif
4093 ret = _FAIL;
4094 goto exit;
4095 }
4096 } else {
4097 #ifdef DBG_RX_DROP_FRAME
4098 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" bDriverStopped(%s) OR bSurpriseRemoved(%s)\n"
4099 , FUNC_ADPT_ARG(padapter)
4100 , rtw_is_drv_stopped(padapter) ? "True" : "False"
4101 , rtw_is_surprise_removed(padapter) ? "True" : "False");
4102 #endif
4103 ret = _FAIL;
4104 goto exit;
4105 }
4106
4107 }
4108 }
4109 }
4110 exit:
4111 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
4112 ret = _FAIL;
4113 return ret;
4114
4115 }
4116 #endif
4117
4118
4119 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
recv_frame_monitor(_adapter * padapter,union recv_frame * rframe)4120 int recv_frame_monitor(_adapter *padapter, union recv_frame *rframe)
4121 {
4122 int ret = _SUCCESS;
4123 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
4124
4125 #ifdef CONFIG_WIFI_MONITOR
4126 struct net_device *ndev = padapter->pnetdev;
4127 _pkt *pskb = NULL;
4128
4129 if (rframe == NULL)
4130 goto exit;
4131
4132 /* read skb information from recv frame */
4133 pskb = rframe->u.hdr.pkt;
4134 pskb->len = rframe->u.hdr.len;
4135 pskb->data = rframe->u.hdr.rx_data;
4136 skb_set_tail_pointer(pskb, rframe->u.hdr.len);
4137
4138 if (ndev->type == ARPHRD_IEEE80211_RADIOTAP) {
4139 /* fill radiotap header */
4140 if (rtw_fill_radiotap_hdr(padapter, &rframe->u.hdr.attrib, (u8 *)pskb) == _FAIL) {
4141 ret = _FAIL;
4142 goto exit;
4143 }
4144 }
4145
4146 /* write skb information to recv frame */
4147 skb_reset_mac_header(pskb);
4148 rframe->u.hdr.len = pskb->len;
4149 rframe->u.hdr.rx_data = pskb->data;
4150 rframe->u.hdr.rx_head = pskb->head;
4151 rframe->u.hdr.rx_tail = skb_tail_pointer(pskb);
4152 rframe->u.hdr.rx_end = skb_end_pointer(pskb);
4153
4154 if (!RTW_CANNOT_RUN(padapter)) {
4155 /* indicate this recv_frame */
4156 ret = rtw_recv_monitor(padapter, rframe);
4157 } else
4158 ret = _FAIL;
4159
4160 exit:
4161 #endif /* CONFIG_WIFI_MONITOR */
4162
4163 if (rframe) /* free this recv_frame */
4164 rtw_free_recvframe(rframe, pfree_recv_queue);
4165
4166 return ret;
4167 }
4168 #endif
recv_func_prehandle(_adapter * padapter,union recv_frame * rframe)4169 int recv_func_prehandle(_adapter *padapter, union recv_frame *rframe)
4170 {
4171 int ret = _SUCCESS;
4172 #ifdef DBG_RX_COUNTER_DUMP
4173 struct rx_pkt_attrib *pattrib = &rframe->u.hdr.attrib;
4174 #endif
4175 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
4176
4177 #ifdef DBG_RX_COUNTER_DUMP
4178 if (padapter->dump_rx_cnt_mode & DUMP_DRV_RX_COUNTER) {
4179 if (pattrib->crc_err == 1)
4180 padapter->drv_rx_cnt_crcerror++;
4181 else
4182 padapter->drv_rx_cnt_ok++;
4183 }
4184 #endif
4185
4186 #ifdef CONFIG_MP_INCLUDED
4187 if (padapter->registrypriv.mp_mode == 1 || padapter->mppriv.bRTWSmbCfg == _TRUE) {
4188 mp_recv_frame(padapter, rframe);
4189 ret = _FAIL;
4190 goto exit;
4191 } else
4192 #endif
4193 {
4194 /* check the frame crtl field and decache */
4195 ret = validate_recv_frame(padapter, rframe);
4196 if (ret != _SUCCESS) {
4197 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
4198 goto exit;
4199 }
4200 }
4201 exit:
4202 return ret;
4203 }
4204
4205 /*#define DBG_RX_BMC_FRAME*/
recv_func_posthandle(_adapter * padapter,union recv_frame * prframe)4206 int recv_func_posthandle(_adapter *padapter, union recv_frame *prframe)
4207 {
4208 int ret = _SUCCESS;
4209 union recv_frame *orig_prframe = prframe;
4210 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
4211 struct recv_priv *precvpriv = &padapter->recvpriv;
4212 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
4213 #ifdef CONFIG_TDLS
4214 u8 *psnap_type, *pcategory;
4215 #endif /* CONFIG_TDLS */
4216
4217 DBG_COUNTER(padapter->rx_logs.core_rx_post);
4218
4219 prframe = decryptor(padapter, prframe);
4220 if (prframe == NULL) {
4221 #ifdef DBG_RX_DROP_FRAME
4222 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" decryptor: drop pkt\n"
4223 , FUNC_ADPT_ARG(padapter));
4224 #endif
4225 ret = _FAIL;
4226 DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_err);
4227 goto _recv_data_drop;
4228 }
4229
4230 #ifdef DBG_RX_BMC_FRAME
4231 if (IS_MCAST(pattrib->ra))
4232 RTW_INFO("%s =>"ADPT_FMT" Rx BC/MC from "MAC_FMT"\n", __func__, ADPT_ARG(padapter), MAC_ARG(pattrib->ta));
4233 #endif
4234
4235 #if 0
4236 if (is_primary_adapter(padapter)) {
4237 RTW_INFO("+++\n");
4238 {
4239 int i;
4240 u8 *ptr = get_recvframe_data(prframe);
4241 for (i = 0; i < 140; i = i + 8)
4242 RTW_INFO("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:", *(ptr + i),
4243 *(ptr + i + 1), *(ptr + i + 2) , *(ptr + i + 3) , *(ptr + i + 4), *(ptr + i + 5), *(ptr + i + 6), *(ptr + i + 7));
4244
4245 }
4246 RTW_INFO("---\n");
4247 }
4248 #endif
4249
4250 #ifdef CONFIG_TDLS
4251 /* check TDLS frame */
4252 psnap_type = get_recvframe_data(orig_prframe) + pattrib->hdrlen + pattrib->iv_len + SNAP_SIZE;
4253 pcategory = psnap_type + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
4254
4255 if ((_rtw_memcmp(psnap_type, SNAP_ETH_TYPE_TDLS, ETH_TYPE_LEN)) &&
4256 ((*pcategory == RTW_WLAN_CATEGORY_TDLS) || (*pcategory == RTW_WLAN_CATEGORY_P2P))) {
4257 ret = OnTDLS(padapter, prframe);
4258 if (ret == _FAIL)
4259 goto _exit_recv_func;
4260 }
4261 #endif /* CONFIG_TDLS */
4262
4263 prframe = recvframe_chk_defrag(padapter, prframe);
4264 if (prframe == NULL) {
4265 #ifdef DBG_RX_DROP_FRAME
4266 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" recvframe_chk_defrag: drop pkt\n"
4267 , FUNC_ADPT_ARG(padapter));
4268 #endif
4269 DBG_COUNTER(padapter->rx_logs.core_rx_post_defrag_err);
4270 goto _recv_data_drop;
4271 }
4272
4273 prframe = portctrl(padapter, prframe);
4274 if (prframe == NULL) {
4275 #ifdef DBG_RX_DROP_FRAME
4276 RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" portctrl: drop pkt\n"
4277 , FUNC_ADPT_ARG(padapter));
4278 #endif
4279 ret = _FAIL;
4280 DBG_COUNTER(padapter->rx_logs.core_rx_post_portctrl_err);
4281 goto _recv_data_drop;
4282 }
4283
4284 count_rx_stats(padapter, prframe, NULL);
4285
4286 #ifdef CONFIG_WAPI_SUPPORT
4287 rtw_wapi_update_info(padapter, prframe);
4288 #endif
4289
4290 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
4291 /* including perform A-MPDU Rx Ordering Buffer Control */
4292 ret = recv_indicatepkt_reorder(padapter, prframe);
4293 if (ret == _FAIL) {
4294 rtw_free_recvframe(orig_prframe, pfree_recv_queue);
4295 goto _recv_data_drop;
4296 } else if (ret == RTW_RX_HANDLED) /* queued OR indicated in order */
4297 goto _exit_recv_func;
4298 #endif
4299
4300 recv_set_iseq_before_mpdu_process(prframe, pattrib->seq_num, __func__);
4301 ret = recv_process_mpdu(padapter, prframe);
4302 recv_set_iseq_after_mpdu_process(prframe, pattrib->seq_num, __func__);
4303 if (ret == _FAIL)
4304 goto _recv_data_drop;
4305
4306 _exit_recv_func:
4307 return ret;
4308
4309 _recv_data_drop:
4310 precvpriv->dbg_rx_drop_count++;
4311 return ret;
4312 }
4313
recv_func(_adapter * padapter,union recv_frame * rframe)4314 int recv_func(_adapter *padapter, union recv_frame *rframe)
4315 {
4316 int ret;
4317 struct rx_pkt_attrib *prxattrib = &rframe->u.hdr.attrib;
4318 struct recv_priv *recvpriv = &padapter->recvpriv;
4319 struct security_priv *psecuritypriv = &padapter->securitypriv;
4320 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
4321 u8 *ptr = rframe->u.hdr.rx_data;
4322 #ifdef CONFIG_CUSTOMER_ALIBABA_GENERAL
4323 u8 type;
4324 #endif
4325
4326 if (check_fwstate(mlmepriv, WIFI_MONITOR_STATE)
4327 #ifdef RTW_SIMPLE_CONFIG
4328 || (check_fwstate(mlmepriv, WIFI_AP_STATE) && padapter->rtw_simple_config == _TRUE && IS_MCAST(get_ra(ptr)))
4329 #endif
4330 ) {
4331 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
4332 recv_frame_monitor(padapter, rframe);
4333 #endif
4334 ret = _SUCCESS;
4335 goto exit;
4336 }
4337
4338 #ifdef CONFIG_CUSTOMER_ALIBABA_GENERAL
4339 type = GetFrameType(ptr);
4340 if ((type == WIFI_DATA_TYPE)&& check_fwstate(mlmepriv, WIFI_STATION_STATE)) {
4341 struct wlan_network *cur_network = &(mlmepriv->cur_network);
4342 if ( _rtw_memcmp(get_addr2_ptr(ptr), cur_network->network.MacAddress, ETH_ALEN)==0) {
4343 recv_frame_monitor(padapter, rframe);
4344 ret = _SUCCESS;
4345 goto exit;
4346 }
4347 }
4348 #endif
4349 /* check if need to handle uc_swdec_pending_queue*/
4350 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) {
4351 union recv_frame *pending_frame;
4352 int cnt = 0;
4353
4354 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
4355 cnt++;
4356 DBG_COUNTER(padapter->rx_logs.core_rx_dequeue);
4357 recv_func_posthandle(padapter, pending_frame);
4358 }
4359
4360 if (cnt)
4361 RTW_INFO(FUNC_ADPT_FMT" dequeue %d from uc_swdec_pending_queue\n",
4362 FUNC_ADPT_ARG(padapter), cnt);
4363 }
4364
4365 DBG_COUNTER(padapter->rx_logs.core_rx);
4366 ret = recv_func_prehandle(padapter, rframe);
4367
4368 if (ret == _SUCCESS) {
4369
4370 /* check if need to enqueue into uc_swdec_pending_queue*/
4371 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
4372 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
4373 (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt == _TRUE) &&
4374 psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPAPSK &&
4375 !psecuritypriv->busetkipkey) {
4376 DBG_COUNTER(padapter->rx_logs.core_rx_enqueue);
4377 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
4378 /* RTW_INFO("%s: no key, enqueue uc_swdec_pending_queue\n", __func__); */
4379
4380 if (recvpriv->free_recvframe_cnt < NR_RECVFRAME / 4) {
4381 /* to prevent from recvframe starvation, get recvframe from uc_swdec_pending_queue to free_recvframe_cnt */
4382 rframe = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue);
4383 if (rframe)
4384 goto do_posthandle;
4385 }
4386 goto exit;
4387 }
4388
4389 do_posthandle:
4390 ret = recv_func_posthandle(padapter, rframe);
4391 }
4392
4393 exit:
4394 return ret;
4395 }
4396
4397
rtw_recv_entry(union recv_frame * precvframe)4398 s32 rtw_recv_entry(union recv_frame *precvframe)
4399 {
4400 _adapter *padapter;
4401 struct recv_priv *precvpriv;
4402 s32 ret = _SUCCESS;
4403
4404
4405
4406 padapter = precvframe->u.hdr.adapter;
4407
4408 precvpriv = &padapter->recvpriv;
4409
4410
4411 ret = recv_func(padapter, precvframe);
4412 if (ret == _FAIL) {
4413 goto _recv_entry_drop;
4414 }
4415
4416
4417 precvpriv->rx_pkts++;
4418
4419
4420 return ret;
4421
4422 _recv_entry_drop:
4423
4424 #ifdef CONFIG_MP_INCLUDED
4425 if (padapter->registrypriv.mp_mode == 1)
4426 padapter->mppriv.rx_pktloss = precvpriv->rx_drop;
4427 #endif
4428
4429
4430
4431 return ret;
4432 }
4433
4434 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
rtw_signal_stat_timer_hdl(void * ctx)4435 static void rtw_signal_stat_timer_hdl(void *ctx)
4436 {
4437 _adapter *adapter = (_adapter *)ctx;
4438 struct recv_priv *recvpriv = &adapter->recvpriv;
4439
4440 u32 tmp_s, tmp_q;
4441 u8 avg_signal_strength = 0;
4442 u8 avg_signal_qual = 0;
4443 u32 num_signal_strength = 0;
4444 u32 num_signal_qual = 0;
4445 u8 ratio_pre_stat = 0, ratio_curr_stat = 0, ratio_total = 0, ratio_profile = SIGNAL_STAT_CALC_PROFILE_0;
4446
4447 if (adapter->recvpriv.is_signal_dbg) {
4448 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
4449 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg;
4450 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
4451 } else {
4452
4453 if (recvpriv->signal_strength_data.update_req == 0) { /* update_req is clear, means we got rx */
4454 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
4455 num_signal_strength = recvpriv->signal_strength_data.total_num;
4456 /* after avg_vals are accquired, we can re-stat the signal values */
4457 recvpriv->signal_strength_data.update_req = 1;
4458 }
4459
4460 if (recvpriv->signal_qual_data.update_req == 0) { /* update_req is clear, means we got rx */
4461 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
4462 num_signal_qual = recvpriv->signal_qual_data.total_num;
4463 /* after avg_vals are accquired, we can re-stat the signal values */
4464 recvpriv->signal_qual_data.update_req = 1;
4465 }
4466
4467 if (num_signal_strength == 0) {
4468 if (rtw_get_on_cur_ch_time(adapter) == 0
4469 || rtw_get_passing_time_ms(rtw_get_on_cur_ch_time(adapter)) < 2 * adapter->mlmeextpriv.mlmext_info.bcn_interval
4470 )
4471 goto set_timer;
4472 }
4473
4474 if (check_fwstate(&adapter->mlmepriv, WIFI_UNDER_SURVEY) == _TRUE
4475 || check_fwstate(&adapter->mlmepriv, WIFI_ASOC_STATE) == _FALSE
4476 )
4477 goto set_timer;
4478
4479 #ifdef CONFIG_CONCURRENT_MODE
4480 if (rtw_mi_buddy_check_fwstate(adapter, WIFI_UNDER_SURVEY) == _TRUE)
4481 goto set_timer;
4482 #endif
4483 if (adapter->registrypriv.mp_mode == 1)
4484 ratio_profile = SIGNAL_STAT_CALC_PROFILE_2;
4485 else if (RTW_SIGNAL_STATE_CALC_PROFILE < SIGNAL_STAT_CALC_PROFILE_MAX)
4486 ratio_profile = RTW_SIGNAL_STATE_CALC_PROFILE;
4487
4488 ratio_pre_stat = signal_stat_calc_profile[ratio_profile][0];
4489 ratio_curr_stat = signal_stat_calc_profile[ratio_profile][1];
4490 ratio_total = ratio_pre_stat + ratio_curr_stat;
4491
4492 /* update value of signal_strength, rssi, signal_qual */
4493 tmp_s = (ratio_curr_stat * avg_signal_strength + ratio_pre_stat * recvpriv->signal_strength);
4494 if (tmp_s % ratio_total)
4495 tmp_s = tmp_s / ratio_total + 1;
4496 else
4497 tmp_s = tmp_s / ratio_total;
4498 if (tmp_s > 100)
4499 tmp_s = 100;
4500
4501 tmp_q = (ratio_curr_stat * avg_signal_qual + ratio_pre_stat * recvpriv->signal_qual);
4502 if (tmp_q % ratio_total)
4503 tmp_q = tmp_q / ratio_total + 1;
4504 else
4505 tmp_q = tmp_q / ratio_total;
4506 if (tmp_q > 100)
4507 tmp_q = 100;
4508
4509 recvpriv->signal_strength = tmp_s;
4510 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
4511 recvpriv->signal_qual = tmp_q;
4512
4513 #if defined(DBG_RX_SIGNAL_DISPLAY_PROCESSING) && 1
4514 RTW_INFO(FUNC_ADPT_FMT" signal_strength:%3u, rssi:%3d, signal_qual:%3u"
4515 ", num_signal_strength:%u, num_signal_qual:%u"
4516 ", on_cur_ch_ms:%d"
4517 "\n"
4518 , FUNC_ADPT_ARG(adapter)
4519 , recvpriv->signal_strength
4520 , recvpriv->rssi
4521 , recvpriv->signal_qual
4522 , num_signal_strength, num_signal_qual
4523 , rtw_get_on_cur_ch_time(adapter) ? rtw_get_passing_time_ms(rtw_get_on_cur_ch_time(adapter)) : 0
4524 );
4525 #endif
4526 }
4527
4528 set_timer:
4529 rtw_set_signal_stat_timer(recvpriv);
4530
4531 }
4532 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4533
rx_process_rssi(_adapter * padapter,union recv_frame * prframe)4534 static void rx_process_rssi(_adapter *padapter, union recv_frame *prframe)
4535 {
4536 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
4537 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
4538 struct signal_stat *signal_stat = &padapter->recvpriv.signal_strength_data;
4539 #else /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4540 u32 last_rssi, tmp_val;
4541 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4542
4543 /* RTW_INFO("process_rssi=> pattrib->rssil(%d) signal_strength(%d)\n ",pattrib->recv_signal_power,pattrib->signal_strength); */
4544 /* if(pRfd->Status.bPacketToSelf || pRfd->Status.bPacketBeacon) */
4545 {
4546 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
4547 if (signal_stat->update_req) {
4548 signal_stat->total_num = 0;
4549 signal_stat->total_val = 0;
4550 signal_stat->update_req = 0;
4551 }
4552
4553 signal_stat->total_num++;
4554 signal_stat->total_val += pattrib->phy_info.signal_strength;
4555 signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
4556 #else /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4557
4558 /* Adapter->RxStats.RssiCalculateCnt++; */ /* For antenna Test */
4559 if (padapter->recvpriv.signal_strength_data.total_num++ >= PHY_RSSI_SLID_WIN_MAX) {
4560 padapter->recvpriv.signal_strength_data.total_num = PHY_RSSI_SLID_WIN_MAX;
4561 last_rssi = padapter->recvpriv.signal_strength_data.elements[padapter->recvpriv.signal_strength_data.index];
4562 padapter->recvpriv.signal_strength_data.total_val -= last_rssi;
4563 }
4564 padapter->recvpriv.signal_strength_data.total_val += pattrib->phy_info.signal_strength;
4565
4566 padapter->recvpriv.signal_strength_data.elements[padapter->recvpriv.signal_strength_data.index++] = pattrib->phy_info.signal_strength;
4567 if (padapter->recvpriv.signal_strength_data.index >= PHY_RSSI_SLID_WIN_MAX)
4568 padapter->recvpriv.signal_strength_data.index = 0;
4569
4570
4571 tmp_val = padapter->recvpriv.signal_strength_data.total_val / padapter->recvpriv.signal_strength_data.total_num;
4572
4573 if (padapter->recvpriv.is_signal_dbg) {
4574 padapter->recvpriv.signal_strength = padapter->recvpriv.signal_strength_dbg;
4575 padapter->recvpriv.rssi = (s8)translate_percentage_to_dbm(padapter->recvpriv.signal_strength_dbg);
4576 } else {
4577 padapter->recvpriv.signal_strength = tmp_val;
4578 padapter->recvpriv.rssi = (s8)translate_percentage_to_dbm(tmp_val);
4579 }
4580
4581 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4582 }
4583 }
4584
rx_process_link_qual(_adapter * padapter,union recv_frame * prframe)4585 static void rx_process_link_qual(_adapter *padapter, union recv_frame *prframe)
4586 {
4587 struct rx_pkt_attrib *pattrib;
4588 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
4589 struct signal_stat *signal_stat;
4590 #else /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4591 u32 last_evm = 0, tmpVal;
4592 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4593
4594 if (prframe == NULL || padapter == NULL)
4595 return;
4596
4597 pattrib = &prframe->u.hdr.attrib;
4598 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
4599 signal_stat = &padapter->recvpriv.signal_qual_data;
4600 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4601
4602 /* RTW_INFO("process_link_qual=> pattrib->signal_qual(%d)\n ",pattrib->signal_qual); */
4603
4604 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
4605 if (signal_stat->update_req) {
4606 signal_stat->total_num = 0;
4607 signal_stat->total_val = 0;
4608 signal_stat->update_req = 0;
4609 }
4610
4611 signal_stat->total_num++;
4612 signal_stat->total_val += pattrib->phy_info.signal_quality;
4613 signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
4614
4615 #else /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4616 if (pattrib->phy_info.signal_quality != 0) {
4617 /* */
4618 /* 1. Record the general EVM to the sliding window. */
4619 /* */
4620 if (padapter->recvpriv.signal_qual_data.total_num++ >= PHY_LINKQUALITY_SLID_WIN_MAX) {
4621 padapter->recvpriv.signal_qual_data.total_num = PHY_LINKQUALITY_SLID_WIN_MAX;
4622 last_evm = padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index];
4623 padapter->recvpriv.signal_qual_data.total_val -= last_evm;
4624 }
4625 padapter->recvpriv.signal_qual_data.total_val += pattrib->phy_info.signal_quality;
4626
4627 padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index++] = pattrib->phy_info.signal_quality;
4628 if (padapter->recvpriv.signal_qual_data.index >= PHY_LINKQUALITY_SLID_WIN_MAX)
4629 padapter->recvpriv.signal_qual_data.index = 0;
4630
4631
4632 /* <1> Showed on UI for user, in percentage. */
4633 tmpVal = padapter->recvpriv.signal_qual_data.total_val / padapter->recvpriv.signal_qual_data.total_num;
4634 padapter->recvpriv.signal_qual = (u8)tmpVal;
4635
4636 }
4637 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
4638 }
4639
rx_process_phy_info(_adapter * padapter,union recv_frame * rframe)4640 void rx_process_phy_info(_adapter *padapter, union recv_frame *rframe)
4641 {
4642 /* Check RSSI */
4643 rx_process_rssi(padapter, rframe);
4644
4645 /* Check PWDB */
4646 /* process_PWDB(padapter, rframe); */
4647
4648 /* UpdateRxSignalStatistics8192C(Adapter, pRfd); */
4649
4650 /* Check EVM */
4651 rx_process_link_qual(padapter, rframe);
4652 rtw_store_phy_info(padapter, rframe);
4653 }
4654
rx_query_phy_status(union recv_frame * precvframe,u8 * pphy_status)4655 void rx_query_phy_status(
4656 union recv_frame *precvframe,
4657 u8 *pphy_status)
4658 {
4659 PADAPTER padapter = precvframe->u.hdr.adapter;
4660 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
4661 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
4662 struct phydm_phyinfo_struct *p_phy_info = &pattrib->phy_info;
4663 u8 *wlanhdr;
4664 struct phydm_perpkt_info_struct pkt_info;
4665 u8 *ta, *ra;
4666 u8 is_ra_bmc;
4667 struct sta_priv *pstapriv;
4668 struct sta_info *psta = NULL;
4669 struct recv_priv *precvpriv = &padapter->recvpriv;
4670 /* _irqL irqL; */
4671
4672 pkt_info.is_packet_match_bssid = _FALSE;
4673 pkt_info.is_packet_to_self = _FALSE;
4674 pkt_info.is_packet_beacon = _FALSE;
4675 pkt_info.ppdu_cnt = pattrib->ppdu_cnt;
4676 pkt_info.station_id = 0xFF;
4677
4678 wlanhdr = get_recvframe_data(precvframe);
4679
4680 ta = get_ta(wlanhdr);
4681 ra = get_ra(wlanhdr);
4682 is_ra_bmc = IS_MCAST(ra);
4683
4684 if (_rtw_memcmp(adapter_mac_addr(padapter), ta, ETH_ALEN) == _TRUE) {
4685 static systime start_time = 0;
4686
4687 #if 0 /*For debug */
4688 if (IsFrameTypeCtrl(wlanhdr)) {
4689 RTW_INFO("-->Control frame: Y\n");
4690 RTW_INFO("-->pkt_len: %d\n", pattrib->pkt_len);
4691 RTW_INFO("-->Sub Type = 0x%X\n", get_frame_sub_type(wlanhdr));
4692 }
4693
4694 /* Dump first 40 bytes of header */
4695 int i = 0;
4696
4697 for (i = 0; i < 40; i++)
4698 RTW_INFO("%d: %X\n", i, *((u8 *)wlanhdr + i));
4699
4700 RTW_INFO("\n");
4701 #endif
4702
4703 if ((start_time == 0) || (rtw_get_passing_time_ms(start_time) > 5000)) {
4704 RTW_PRINT("Warning!!! %s: Confilc mac addr!!\n", __func__);
4705 start_time = rtw_get_current_time();
4706 }
4707 precvpriv->dbg_rx_conflic_mac_addr_cnt++;
4708 } else {
4709 pstapriv = &padapter->stapriv;
4710 psta = rtw_get_stainfo(pstapriv, ta);
4711 if (psta)
4712 pkt_info.station_id = psta->cmn.mac_id;
4713 }
4714
4715 pkt_info.is_packet_match_bssid = (!IsFrameTypeCtrl(wlanhdr))
4716 && (!pattrib->icv_err) && (!pattrib->crc_err)
4717 && ((!MLME_IS_MESH(padapter) && _rtw_memcmp(get_hdr_bssid(wlanhdr), get_bssid(&padapter->mlmepriv), ETH_ALEN))
4718 || (MLME_IS_MESH(padapter) && psta));
4719
4720 pkt_info.is_to_self = (!pattrib->icv_err) && (!pattrib->crc_err)
4721 && _rtw_memcmp(ra, adapter_mac_addr(padapter), ETH_ALEN);
4722
4723 pkt_info.is_packet_to_self = pkt_info.is_packet_match_bssid
4724 && _rtw_memcmp(ra, adapter_mac_addr(padapter), ETH_ALEN);
4725
4726 pkt_info.is_packet_beacon = pkt_info.is_packet_match_bssid
4727 && (get_frame_sub_type(wlanhdr) == WIFI_BEACON);
4728
4729 if (psta && IsFrameTypeData(wlanhdr)
4730 && !(get_frame_sub_type(wlanhdr) & BIT(6)) /* don't count NULL data */
4731 ) {
4732 if (is_ra_bmc)
4733 psta->curr_rx_rate_bmc = pattrib->data_rate;
4734 else
4735 psta->curr_rx_rate = pattrib->data_rate;
4736 }
4737 pkt_info.data_rate = pattrib->data_rate;
4738
4739 odm_phy_status_query(&pHalData->odmpriv, p_phy_info, pphy_status, &pkt_info);
4740
4741 /* If bw is initial value, get from phy status */
4742 if (pattrib->bw == CHANNEL_WIDTH_MAX)
4743 pattrib->bw = p_phy_info->band_width;
4744
4745 if (p_phy_info->physts_rpt_valid == _TRUE) {
4746 precvframe->u.hdr.psta = NULL;
4747 if (padapter->registrypriv.mp_mode != 1) {
4748 if ((!MLME_IS_MESH(padapter) && pkt_info.is_packet_match_bssid)
4749 || (MLME_IS_MESH(padapter) && psta)) {
4750 if (psta) {
4751 precvframe->u.hdr.psta = psta;
4752 rx_process_phy_info(padapter, precvframe);
4753 }
4754 } else if (pkt_info.is_packet_to_self || pkt_info.is_packet_beacon) {
4755 if (psta)
4756 precvframe->u.hdr.psta = psta;
4757 rx_process_phy_info(padapter, precvframe);
4758 }
4759 } else {
4760 #ifdef CONFIG_MP_INCLUDED
4761 if (padapter->mppriv.brx_filter_beacon == _TRUE) {
4762 if (pkt_info.is_packet_beacon) {
4763 RTW_INFO("in MP Rx is_packet_beacon\n");
4764 if (psta)
4765 precvframe->u.hdr.psta = psta;
4766 rx_process_phy_info(padapter, precvframe);
4767 }
4768 } else
4769 #endif
4770 {
4771 if (psta)
4772 precvframe->u.hdr.psta = psta;
4773 rx_process_phy_info(padapter, precvframe);
4774 }
4775 }
4776 }
4777
4778 rtw_odm_parse_rx_phy_status_chinfo(precvframe, pphy_status);
4779 }
4780 /*
4781 * Increase and check if the continual_no_rx_packet of this @param pmlmepriv is larger than MAX_CONTINUAL_NORXPACKET_COUNT
4782 * @return _TRUE:
4783 * @return _FALSE:
4784 */
rtw_inc_and_chk_continual_no_rx_packet(struct sta_info * sta,int tid_index)4785 int rtw_inc_and_chk_continual_no_rx_packet(struct sta_info *sta, int tid_index)
4786 {
4787
4788 int ret = _FALSE;
4789 int value = ATOMIC_INC_RETURN(&sta->continual_no_rx_packet[tid_index]);
4790
4791 if (value >= MAX_CONTINUAL_NORXPACKET_COUNT)
4792 ret = _TRUE;
4793
4794 return ret;
4795 }
4796
4797 /*
4798 * Set the continual_no_rx_packet of this @param pmlmepriv to 0
4799 */
rtw_reset_continual_no_rx_packet(struct sta_info * sta,int tid_index)4800 void rtw_reset_continual_no_rx_packet(struct sta_info *sta, int tid_index)
4801 {
4802 ATOMIC_SET(&sta->continual_no_rx_packet[tid_index], 0);
4803 }
4804
adapter_allow_bmc_data_rx(_adapter * adapter)4805 u8 adapter_allow_bmc_data_rx(_adapter *adapter)
4806 {
4807 if (check_fwstate(&adapter->mlmepriv, WIFI_MONITOR_STATE | WIFI_MP_STATE) == _TRUE)
4808 return 1;
4809
4810 #ifdef RTW_SIMPLE_CONFIG
4811 /* allow AP to receive multicast packet for RtwSimpleConfigV4 */
4812 if (MLME_IS_AP(adapter) && adapter->rtw_simple_config)
4813 return 1;
4814 #endif
4815
4816 if (MLME_IS_AP(adapter))
4817 return 0;
4818
4819 if (rtw_linked_check(adapter) == _FALSE)
4820 return 0;
4821
4822 return 1;
4823 }
4824
pre_recv_entry(union recv_frame * precvframe,u8 * pphy_status)4825 s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status)
4826 {
4827 s32 ret = _SUCCESS;
4828 u8 *pbuf = precvframe->u.hdr.rx_data;
4829 u8 *ra = get_ra(pbuf);
4830 u8 ra_is_bmc = IS_MCAST(ra);
4831 bool phy_queried = 0;
4832 _adapter *primary_padapter = precvframe->u.hdr.adapter;
4833 _adapter *iface = NULL;
4834
4835 #ifdef CONFIG_MP_INCLUDED
4836 if (rtw_mp_mode_check(primary_padapter))
4837 goto query_phy_status;
4838 #endif
4839 #ifdef CONFIG_WIFI_MONITOR
4840 if (MLME_IS_MONITOR(primary_padapter))
4841 goto query_phy_status;
4842 #endif
4843
4844 if (ra_is_bmc == _FALSE) {
4845 /* UC frame */
4846 iface = rtw_get_iface_by_macddr(primary_padapter , ra);
4847 if (!iface) {
4848 #if defined(CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI) || defined(CONFIG_RTW_SCAN_RAND)
4849 if (_rtw_memcmp(ra, adapter_pno_mac_addr(primary_padapter), ETH_ALEN))
4850 goto query_phy_status;
4851 #endif
4852
4853 #ifdef CONFIG_RTW_MULTI_AP
4854 /* unasoc STA RCPI */
4855 if (rtw_unassoc_sta_src_chk(primary_padapter, UNASOC_STA_SRC_RX_NMY_UC)) {
4856 if (pphy_status) {
4857 rx_query_phy_status(precvframe, pphy_status);
4858 rtw_rx_add_unassoc_sta(primary_padapter, UNASOC_STA_SRC_RX_NMY_UC, get_ta(pbuf)
4859 , precvframe->u.hdr.attrib.phy_info.recv_signal_power);
4860 }
4861 } else
4862 #endif
4863 RTW_INFO("%s [WARN] Cannot find appropriate adapter - mac_addr : "MAC_FMT"\n"
4864 , __func__, MAC_ARG(ra));
4865
4866 rtw_free_recvframe(precvframe, &precvframe->u.hdr.adapter->recvpriv.free_recv_queue);
4867 goto exit;
4868 }
4869 #ifdef CONFIG_CONCURRENT_MODE
4870 else
4871 precvframe->u.hdr.adapter = iface;
4872 #endif
4873
4874 } else {
4875 /* BMC frame */
4876 #ifdef CONFIG_CONCURRENT_MODE
4877 rtw_mi_buddy_clone_bcmc_packet(primary_padapter, precvframe, pphy_status);
4878 #endif
4879
4880 #ifdef CONFIG_RTW_MULTI_AP
4881 /* unasoc STA RCPI */
4882 if (pphy_status
4883 && rtw_unassoc_sta_src_chk(primary_padapter, UNASOC_STA_SRC_RX_BMC)
4884 ) {
4885 phy_queried = 1;
4886 rx_query_phy_status(precvframe, pphy_status);
4887 rtw_rx_add_unassoc_sta(primary_padapter, UNASOC_STA_SRC_RX_BMC, get_ta(pbuf)
4888 , precvframe->u.hdr.attrib.phy_info.recv_signal_power);
4889 }
4890 #endif
4891
4892 /* skip unnecessary BMC data frame for primary adapter */
4893 if (GetFrameType(pbuf) == WIFI_DATA_TYPE
4894 && !adapter_allow_bmc_data_rx(precvframe->u.hdr.adapter)
4895 ) {
4896 rtw_free_recvframe(precvframe, &precvframe->u.hdr.adapter->recvpriv.free_recv_queue);
4897 goto exit;
4898 }
4899 }
4900 #if defined(CONFIG_MP_INCLUDED) || defined(CONFIG_WIFI_MONITOR) || defined(CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI) || defined(CONFIG_RTW_SCAN_RAND)
4901 query_phy_status:
4902 #endif
4903 if (pphy_status) {
4904 if (!phy_queried)
4905 rx_query_phy_status(precvframe, pphy_status);
4906 #ifdef CONFIG_WIFI_MONITOR
4907 if (MLME_IS_MONITOR(primary_padapter))
4908 rx_query_moinfo(&precvframe->u.hdr.attrib, pphy_status);
4909 #endif
4910 }
4911
4912 ret = rtw_recv_entry(precvframe);
4913
4914 exit:
4915 return ret;
4916 }
4917
4918 #ifdef CONFIG_RECV_THREAD_MODE
rtw_recv_thread(thread_context context)4919 thread_return rtw_recv_thread(thread_context context)
4920 {
4921 _adapter *adapter = (_adapter *)context;
4922 struct recv_priv *recvpriv = &adapter->recvpriv;
4923 s32 err = _SUCCESS;
4924 #ifdef RTW_RECV_THREAD_HIGH_PRIORITY
4925 #ifdef PLATFORM_LINUX
4926 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0))
4927 sched_set_fifo_low(current);
4928 #else
4929 struct sched_param param = { .sched_priority = 1 };
4930
4931 sched_setscheduler(current, SCHED_FIFO, ¶m);
4932 #endif
4933 #endif /* PLATFORM_LINUX */
4934 #endif /*RTW_RECV_THREAD_HIGH_PRIORITY*/
4935 thread_enter("RTW_RECV_THREAD");
4936
4937 RTW_INFO(FUNC_ADPT_FMT" enter\n", FUNC_ADPT_ARG(adapter));
4938
4939 do {
4940 err = _rtw_down_sema(&recvpriv->recv_sema);
4941 if (_FAIL == err) {
4942 RTW_ERR(FUNC_ADPT_FMT" down recv_sema fail!\n", FUNC_ADPT_ARG(adapter));
4943 goto exit;
4944 }
4945
4946 if (RTW_CANNOT_RUN(adapter)) {
4947 RTW_DBG(FUNC_ADPT_FMT "- bDriverStopped(%s) bSurpriseRemoved(%s)\n",
4948 FUNC_ADPT_ARG(adapter),
4949 rtw_is_drv_stopped(adapter) ? "True" : "False",
4950 rtw_is_surprise_removed(adapter) ? "True" : "False");
4951 goto exit;
4952 }
4953
4954 err = rtw_hal_recv_hdl(adapter);
4955
4956 if (err == RTW_RFRAME_UNAVAIL
4957 || err == RTW_RFRAME_PKT_UNAVAIL
4958 ) {
4959 rtw_msleep_os(1);
4960 _rtw_up_sema(&recvpriv->recv_sema);
4961 }
4962
4963 flush_signals_thread();
4964
4965 } while (err != _FAIL);
4966
4967 exit:
4968
4969 RTW_INFO(FUNC_ADPT_FMT " Exit\n", FUNC_ADPT_ARG(adapter));
4970
4971 rtw_thread_wait_stop();
4972
4973 return 0;
4974 }
4975 #endif /* CONFIG_RECV_THREAD_MODE */
4976
4977 #if DBG_RX_BH_TRACKING
rx_bh_tk_set_stage(struct recv_priv * recv,u32 s)4978 void rx_bh_tk_set_stage(struct recv_priv *recv, u32 s)
4979 {
4980 recv->rx_bh_stage = s;
4981 }
4982
rx_bh_tk_set_buf(struct recv_priv * recv,void * buf,void * data,u32 dlen)4983 void rx_bh_tk_set_buf(struct recv_priv *recv, void *buf, void *data, u32 dlen)
4984 {
4985 if (recv->rx_bh_cbuf)
4986 recv->rx_bh_lbuf = recv->rx_bh_cbuf;
4987 recv->rx_bh_cbuf = buf;
4988 if (buf) {
4989 recv->rx_bh_cbuf_data = data;
4990 recv->rx_bh_cbuf_dlen = dlen;
4991 recv->rx_bh_buf_dq_cnt++;
4992 } else {
4993 recv->rx_bh_cbuf_data = NULL;
4994 recv->rx_bh_cbuf_dlen = 0;
4995 }
4996 }
4997
rx_bh_tk_set_buf_pos(struct recv_priv * recv,void * pos)4998 void rx_bh_tk_set_buf_pos(struct recv_priv *recv, void *pos)
4999 {
5000 if (recv->rx_bh_cbuf) {
5001 recv->rx_bh_cbuf_pos = pos - recv->rx_bh_cbuf_data;
5002 } else {
5003 rtw_warn_on(1);
5004 recv->rx_bh_cbuf_pos = 0;
5005 }
5006 }
5007
rx_bh_tk_set_frame(struct recv_priv * recv,void * frame)5008 void rx_bh_tk_set_frame(struct recv_priv *recv, void *frame)
5009 {
5010 recv->rx_bh_cframe = frame;
5011 }
5012
dump_rx_bh_tk(void * sel,struct recv_priv * recv)5013 void dump_rx_bh_tk(void *sel, struct recv_priv *recv)
5014 {
5015 RTW_PRINT_SEL(sel, "[RXBHTK]s:%u, buf_dqc:%u, lbuf:%p, cbuf:%p, dlen:%u, pos:%u, cframe:%p\n"
5016 , recv->rx_bh_stage
5017 , recv->rx_bh_buf_dq_cnt
5018 , recv->rx_bh_lbuf
5019 , recv->rx_bh_cbuf
5020 , recv->rx_bh_cbuf_dlen
5021 , recv->rx_bh_cbuf_pos
5022 , recv->rx_bh_cframe
5023 );
5024 }
5025 #endif /* DBG_RX_BH_TRACKING */
5026
5027