staging: rtl8712: Remove boolean comparisons
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / drivers / staging / rtl8712 / rtl871x_recv.c
CommitLineData
2865d42c
LF
1/******************************************************************************
2 * rtl871x_recv.c
3 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 *
23 * Contact information:
24 * WLAN FAE <wlanfae@realtek.com>
25 * Larry Finger <Larry.Finger@lwfinger.net>
26 *
27 ******************************************************************************/
28
29#define _RTL871X_RECV_C_
30
20467825 31#include <linux/ip.h>
5d3da4a2 32#include <linux/slab.h>
be9a1204 33#include <linux/if_ether.h>
5d3da4a2 34#include <linux/kmemleak.h>
1e9ee6f7 35#include <linux/etherdevice.h>
5d3da4a2 36
2865d42c
LF
37#include "osdep_service.h"
38#include "drv_types.h"
39#include "recv_osdep.h"
40#include "mlme_osdep.h"
2865d42c
LF
41#include "ethernet.h"
42#include "usb_ops.h"
43#include "wifi.h"
44
45static const u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
46
47/* Datagram Delivery Protocol */
48static const u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
49
50/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
51static const u8 bridge_tunnel_header[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
52
53/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
54static const u8 rfc1042_header[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
55
56void _r8712_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
57{
58 memset((u8 *)psta_recvpriv, 0, sizeof(struct sta_recv_priv));
59 spin_lock_init(&psta_recvpriv->lock);
60 _init_queue(&psta_recvpriv->defrag_q);
61}
62
63sint _r8712_init_recv_priv(struct recv_priv *precvpriv,
64 struct _adapter *padapter)
65{
66 sint i;
67 union recv_frame *precvframe;
68
69 memset((unsigned char *)precvpriv, 0, sizeof(struct recv_priv));
70 spin_lock_init(&precvpriv->lock);
71 _init_queue(&precvpriv->free_recv_queue);
72 _init_queue(&precvpriv->recv_pending_queue);
73 precvpriv->adapter = padapter;
74 precvpriv->free_recvframe_cnt = NR_RECVFRAME;
91d435fe 75 precvpriv->pallocated_frame_buf = kmalloc(NR_RECVFRAME *
57b6686e
TP
76 sizeof(union recv_frame) + RXFRAME_ALIGN_SZ,
77 GFP_ATOMIC);
2865d42c
LF
78 if (precvpriv->pallocated_frame_buf == NULL)
79 return _FAIL;
5d3da4a2 80 kmemleak_not_leak(precvpriv->pallocated_frame_buf);
2865d42c
LF
81 memset(precvpriv->pallocated_frame_buf, 0, NR_RECVFRAME *
82 sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
83 precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf +
84 RXFRAME_ALIGN_SZ -
85 ((addr_t)(precvpriv->pallocated_frame_buf) &
86 (RXFRAME_ALIGN_SZ-1));
87 precvframe = (union recv_frame *)precvpriv->precv_frame_buf;
88 for (i = 0; i < NR_RECVFRAME; i++) {
534c4acd 89 INIT_LIST_HEAD(&(precvframe->u.list));
fdfbf789 90 list_add_tail(&(precvframe->u.list),
2865d42c
LF
91 &(precvpriv->free_recv_queue.queue));
92 r8712_os_recv_resource_alloc(padapter, precvframe);
93 precvframe->u.hdr.adapter = padapter;
94 precvframe++;
95 }
96 precvpriv->rx_pending_cnt = 1;
2865d42c
LF
97 return r8712_init_recv_priv(precvpriv, padapter);
98}
99
100void _r8712_free_recv_priv(struct recv_priv *precvpriv)
101{
102 kfree(precvpriv->pallocated_frame_buf);
103 r8712_free_recv_priv(precvpriv);
104}
105
106union recv_frame *r8712_alloc_recvframe(struct __queue *pfree_recv_queue)
107{
108 unsigned long irqL;
109 union recv_frame *precvframe;
110 struct list_head *plist, *phead;
111 struct _adapter *padapter;
112 struct recv_priv *precvpriv;
113
114 spin_lock_irqsave(&pfree_recv_queue->lock, irqL);
df353f61 115 if (list_empty(&pfree_recv_queue->queue))
2865d42c
LF
116 precvframe = NULL;
117 else {
e99a428a 118 phead = &pfree_recv_queue->queue;
849fb0a8 119 plist = phead->next;
2865d42c 120 precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
29197b7c 121 list_del_init(&precvframe->u.hdr.list);
2865d42c
LF
122 padapter = precvframe->u.hdr.adapter;
123 if (padapter != NULL) {
124 precvpriv = &padapter->recvpriv;
125 if (pfree_recv_queue == &precvpriv->free_recv_queue)
126 precvpriv->free_recvframe_cnt--;
127 }
128 }
129 spin_unlock_irqrestore(&pfree_recv_queue->lock, irqL);
130 return precvframe;
131}
132
2865d42c
LF
133/*
134caller : defrag; recvframe_chk_defrag in recv_thread (passive)
135pframequeue: defrag_queue : will be accessed in recv_thread (passive)
136
137using spin_lock to protect
138
139*/
140
141void r8712_free_recvframe_queue(struct __queue *pframequeue,
142 struct __queue *pfree_recv_queue)
143{
144 union recv_frame *precvframe;
145 struct list_head *plist, *phead;
146
147 spin_lock(&pframequeue->lock);
e99a428a 148 phead = &pframequeue->queue;
849fb0a8 149 plist = phead->next;
1ca96884 150 while (!end_of_queue_search(phead, plist)) {
2865d42c 151 precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
849fb0a8 152 plist = plist->next;
2865d42c
LF
153 r8712_free_recvframe(precvframe, pfree_recv_queue);
154 }
155 spin_unlock(&pframequeue->lock);
156}
157
158sint r8712_recvframe_chkmic(struct _adapter *adapter,
159 union recv_frame *precvframe)
160{
161 sint i, res = _SUCCESS;
162 u32 datalen;
163 u8 miccode[8];
164 u8 bmic_err = false;
165 u8 *pframe, *payload, *pframemic;
166 u8 *mickey, idx, *iv;
167 struct sta_info *stainfo;
168 struct rx_pkt_attrib *prxattrib = &precvframe->u.hdr.attrib;
169 struct security_priv *psecuritypriv = &adapter->securitypriv;
170
171 stainfo = r8712_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
172 if (prxattrib->encrypt == _TKIP_) {
173 /* calculate mic code */
174 if (stainfo != NULL) {
175 if (IS_MCAST(prxattrib->ra)) {
176 iv = precvframe->u.hdr.rx_data +
177 prxattrib->hdrlen;
178 idx = iv[3];
179 mickey = &psecuritypriv->XGrprxmickey[(((idx >>
180 6) & 0x3)) - 1].skey[0];
1ca96884 181 if (!psecuritypriv->binstallGrpkey)
2865d42c
LF
182 return _FAIL;
183 } else
184 mickey = &stainfo->tkiprxmickey.skey[0];
185 /*icv_len included the mic code*/
186 datalen = precvframe->u.hdr.len - prxattrib->hdrlen -
187 prxattrib->iv_len - prxattrib->icv_len - 8;
188 pframe = precvframe->u.hdr.rx_data;
189 payload = pframe + prxattrib->hdrlen +
190 prxattrib->iv_len;
191 seccalctkipmic(mickey, pframe, payload, datalen,
192 &miccode[0],
193 (unsigned char)prxattrib->priority);
194 pframemic = payload + datalen;
195 bmic_err = false;
196 for (i = 0; i < 8; i++) {
197 if (miccode[i] != *(pframemic + i))
198 bmic_err = true;
199 }
1ca96884
LB
200 if (bmic_err) {
201 if (prxattrib->bdecrypted)
2865d42c
LF
202 r8712_handle_tkip_mic_err(adapter,
203 (u8)IS_MCAST(prxattrib->ra));
204 res = _FAIL;
205 } else {
206 /* mic checked ok */
1ca96884
LB
207 if (!psecuritypriv->bcheck_grpkey &&
208 IS_MCAST(prxattrib->ra))
2865d42c
LF
209 psecuritypriv->bcheck_grpkey = true;
210 }
211 recvframe_pull_tail(precvframe, 8);
212 }
213 }
214 return res;
215}
216
217/* decrypt and set the ivlen,icvlen of the recv_frame */
218union recv_frame *r8712_decryptor(struct _adapter *padapter,
219 union recv_frame *precv_frame)
220{
221 struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib;
222 struct security_priv *psecuritypriv = &padapter->securitypriv;
223 union recv_frame *return_packet = precv_frame;
224
225 if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) ||
1ca96884 226 psecuritypriv->sw_decrypt)) {
2865d42c
LF
227 psecuritypriv->hw_decrypted = false;
228 switch (prxattrib->encrypt) {
229 case _WEP40_:
230 case _WEP104_:
231 r8712_wep_decrypt(padapter, (u8 *)precv_frame);
232 break;
233 case _TKIP_:
234 r8712_tkip_decrypt(padapter, (u8 *)precv_frame);
235 break;
236 case _AES_:
237 r8712_aes_decrypt(padapter, (u8 *)precv_frame);
238 break;
239 default:
240 break;
241 }
242 } else if (prxattrib->bdecrypted == 1)
243 psecuritypriv->hw_decrypted = true;
244 return return_packet;
245}
246/*###set the security information in the recv_frame */
247union recv_frame *r8712_portctrl(struct _adapter *adapter,
248 union recv_frame *precv_frame)
249{
250 u8 *psta_addr, *ptr;
251 uint auth_alg;
252 struct recv_frame_hdr *pfhdr;
253 struct sta_info *psta;
254 struct sta_priv *pstapriv;
255 union recv_frame *prtnframe;
f764cd68 256 u16 ether_type;
2865d42c
LF
257
258 pstapriv = &adapter->stapriv;
259 ptr = get_recvframe_data(precv_frame);
260 pfhdr = &precv_frame->u.hdr;
261 psta_addr = pfhdr->attrib.ta;
262 psta = r8712_get_stainfo(pstapriv, psta_addr);
263 auth_alg = adapter->securitypriv.AuthAlgrthm;
264 if (auth_alg == 2) {
f764cd68
LF
265 /* get ether_type */
266 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE;
267 memcpy(&ether_type, ptr, 2);
268 ether_type = ntohs((unsigned short)ether_type);
269
2865d42c
LF
270 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
271 /* blocked
272 * only accept EAPOL frame */
2865d42c
LF
273 if (ether_type == 0x888e)
274 prtnframe = precv_frame;
275 else {
276 /*free this frame*/
277 r8712_free_recvframe(precv_frame,
278 &adapter->recvpriv.free_recv_queue);
279 prtnframe = NULL;
280 }
281 } else {
282 /* allowed
283 * check decryption status, and decrypt the
284 * frame if needed */
285 prtnframe = precv_frame;
286 /* check is the EAPOL frame or not (Rekey) */
287 if (ether_type == 0x888e) {
288 /* check Rekey */
289 prtnframe = precv_frame;
290 }
291 }
292 } else
293 prtnframe = precv_frame;
294 return prtnframe;
295}
296
16e53729 297static sint recv_decache(union recv_frame *precv_frame, u8 bretry,
2865d42c
LF
298 struct stainfo_rxcache *prxcache)
299{
300 sint tid = precv_frame->u.hdr.attrib.priority;
301 u16 seq_ctrl = ((precv_frame->u.hdr.attrib.seq_num&0xffff) << 4) |
302 (precv_frame->u.hdr.attrib.frag_num & 0xf);
303
304 if (tid > 15)
305 return _FAIL;
306 if (seq_ctrl == prxcache->tid_rxseq[tid])
307 return _FAIL;
308 prxcache->tid_rxseq[tid] = seq_ctrl;
309 return _SUCCESS;
310}
311
2657c30e
JM
312static sint sta2sta_data_frame(struct _adapter *adapter,
313 union recv_frame *precv_frame,
314 struct sta_info **psta)
2865d42c
LF
315{
316 u8 *ptr = precv_frame->u.hdr.rx_data;
317 sint ret = _SUCCESS;
318 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
319 struct sta_priv *pstapriv = &adapter->stapriv;
320 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
321 u8 *mybssid = get_bssid(pmlmepriv);
322 u8 *myhwaddr = myid(&adapter->eeprompriv);
323 u8 *sta_addr = NULL;
324 sint bmcast = IS_MCAST(pattrib->dst);
325
1ca96884
LB
326 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
327 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
2865d42c
LF
328 /* filter packets that SA is myself or multicast or broadcast */
329 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN))
330 return _FAIL;
331 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast))
332 return _FAIL;
1e9ee6f7
WY
333 if (is_zero_ether_addr(pattrib->bssid) ||
334 is_zero_ether_addr(mybssid) ||
2865d42c
LF
335 (memcmp(pattrib->bssid, mybssid, ETH_ALEN)))
336 return _FAIL;
337 sta_addr = pattrib->src;
1ca96884 338 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
2865d42c
LF
339 /* For Station mode, sa and bssid should always be BSSID,
340 * and DA is my mac-address */
341 if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN))
342 return _FAIL;
343 sta_addr = pattrib->bssid;
1ca96884 344 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
2865d42c
LF
345 if (bmcast) {
346 /* For AP mode, if DA == MCAST, then BSSID should
347 * be also MCAST */
348 if (!IS_MCAST(pattrib->bssid))
349 return _FAIL;
350 } else { /* not mc-frame */
351 /* For AP mode, if DA is non-MCAST, then it must be
352 * BSSID, and bssid == BSSID */
353 if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN))
354 return _FAIL;
355 sta_addr = pattrib->src;
356 }
1ca96884 357 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
2865d42c
LF
358 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
359 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
360 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
361 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
362 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
363 sta_addr = mybssid;
364 } else
365 ret = _FAIL;
366 if (bmcast)
367 *psta = r8712_get_bcmc_stainfo(adapter);
368 else
369 *psta = r8712_get_stainfo(pstapriv, sta_addr); /* get ap_info */
370 if (*psta == NULL) {
1ca96884 371 if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
2865d42c
LF
372 adapter->mppriv.rx_pktloss++;
373 return _FAIL;
374 }
375 return ret;
376}
377
2657c30e
JM
378static sint ap2sta_data_frame(struct _adapter *adapter,
379 union recv_frame *precv_frame,
380 struct sta_info **psta)
2865d42c
LF
381{
382 u8 *ptr = precv_frame->u.hdr.rx_data;
383 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
384 struct sta_priv *pstapriv = &adapter->stapriv;
385 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
386 u8 *mybssid = get_bssid(pmlmepriv);
387 u8 *myhwaddr = myid(&adapter->eeprompriv);
388 sint bmcast = IS_MCAST(pattrib->dst);
389
1ca96884
LB
390 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
391 check_fwstate(pmlmepriv, _FW_LINKED)) {
2865d42c
LF
392 /* if NULL-frame, drop packet */
393 if ((GetFrameSubType(ptr)) == WIFI_DATA_NULL)
394 return _FAIL;
395 /* drop QoS-SubType Data, including QoS NULL,
396 * excluding QoS-Data */
397 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) ==
398 WIFI_QOS_DATA_TYPE) {
399 if (GetFrameSubType(ptr) & (BIT(4) | BIT(5) | BIT(6)))
400 return _FAIL;
401 }
402
403 /* filter packets that SA is myself or multicast or broadcast */
404 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN))
405 return _FAIL;
406
407 /* da should be for me */
408 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast))
409 return _FAIL;
410 /* check BSSID */
1e9ee6f7
WY
411 if (is_zero_ether_addr(pattrib->bssid) ||
412 is_zero_ether_addr(mybssid) ||
2865d42c
LF
413 (memcmp(pattrib->bssid, mybssid, ETH_ALEN)))
414 return _FAIL;
415 if (bmcast)
416 *psta = r8712_get_bcmc_stainfo(adapter);
417 else
418 *psta = r8712_get_stainfo(pstapriv, pattrib->bssid);
419 if (*psta == NULL)
420 return _FAIL;
1ca96884
LB
421 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) &&
422 check_fwstate(pmlmepriv, _FW_LINKED)) {
2865d42c
LF
423 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
424 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
425 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
426 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
427 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
428 memcpy(pattrib->bssid, mybssid, ETH_ALEN);
429 *psta = r8712_get_stainfo(pstapriv, pattrib->bssid);
430 if (*psta == NULL)
431 return _FAIL;
432 } else
433 return _FAIL;
434 return _SUCCESS;
435}
436
2657c30e
JM
437static sint sta2ap_data_frame(struct _adapter *adapter,
438 union recv_frame *precv_frame,
439 struct sta_info **psta)
2865d42c
LF
440{
441 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
442 struct sta_priv *pstapriv = &adapter->stapriv;
443 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
444 unsigned char *mybssid = get_bssid(pmlmepriv);
445
1ca96884 446 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
2865d42c
LF
447 /* For AP mode, if DA is non-MCAST, then it must be BSSID,
448 * and bssid == BSSID
449 * For AP mode, RA=BSSID, TX=STA(SRC_ADDR), A3=DST_ADDR */
450 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN))
451 return _FAIL;
452 *psta = r8712_get_stainfo(pstapriv, pattrib->src);
453 if (*psta == NULL)
454 return _FAIL;
455 }
456 return _SUCCESS;
457}
458
16e53729 459static sint validate_recv_ctrl_frame(struct _adapter *adapter,
2865d42c
LF
460 union recv_frame *precv_frame)
461{
462 return _FAIL;
463}
464
16e53729 465static sint validate_recv_mgnt_frame(struct _adapter *adapter,
2865d42c
LF
466 union recv_frame *precv_frame)
467{
468 return _FAIL;
469}
470
471
16e53729 472static sint validate_recv_data_frame(struct _adapter *adapter,
2865d42c
LF
473 union recv_frame *precv_frame)
474{
475 int res;
476 u8 bretry;
477 u8 *psa, *pda, *pbssid;
478 struct sta_info *psta = NULL;
479 u8 *ptr = precv_frame->u.hdr.rx_data;
480 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
481 struct security_priv *psecuritypriv = &adapter->securitypriv;
482
483 bretry = GetRetry(ptr);
484 pda = get_da(ptr);
485 psa = get_sa(ptr);
486 pbssid = get_hdr_bssid(ptr);
487 if (pbssid == NULL)
488 return _FAIL;
489 memcpy(pattrib->dst, pda, ETH_ALEN);
490 memcpy(pattrib->src, psa, ETH_ALEN);
491 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
492 switch (pattrib->to_fr_ds) {
493 case 0:
494 memcpy(pattrib->ra, pda, ETH_ALEN);
495 memcpy(pattrib->ta, psa, ETH_ALEN);
496 res = sta2sta_data_frame(adapter, precv_frame, &psta);
497 break;
498 case 1:
499 memcpy(pattrib->ra, pda, ETH_ALEN);
500 memcpy(pattrib->ta, pbssid, ETH_ALEN);
501 res = ap2sta_data_frame(adapter, precv_frame, &psta);
502 break;
503 case 2:
504 memcpy(pattrib->ra, pbssid, ETH_ALEN);
505 memcpy(pattrib->ta, psa, ETH_ALEN);
506 res = sta2ap_data_frame(adapter, precv_frame, &psta);
507 break;
508 case 3:
509 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
510 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
511 return _FAIL;
512 default:
513 return _FAIL;
514 }
515 if (res == _FAIL)
516 return _FAIL;
517 if (psta == NULL)
518 return _FAIL;
da077689 519 precv_frame->u.hdr.psta = psta;
2865d42c
LF
520 pattrib->amsdu = 0;
521 /* parsing QC field */
522 if (pattrib->qos == 1) {
523 pattrib->priority = GetPriority((ptr + 24));
524 pattrib->ack_policy = GetAckpolicy((ptr + 24));
525 pattrib->amsdu = GetAMsdu((ptr + 24));
526 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
527 } else {
528 pattrib->priority = 0;
529 pattrib->hdrlen = (pattrib->to_fr_ds == 3) ? 30 : 24;
530 }
531
532 if (pattrib->order)/*HT-CTRL 11n*/
533 pattrib->hdrlen += 4;
534 precv_frame->u.hdr.preorder_ctrl =
535 &psta->recvreorder_ctrl[pattrib->priority];
536
537 /* decache, drop duplicate recv packets */
538 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) ==
539 _FAIL)
540 return _FAIL;
541
542 if (pattrib->privacy) {
543 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt,
544 IS_MCAST(pattrib->ra));
545 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len,
546 pattrib->encrypt);
547 } else {
548 pattrib->encrypt = 0;
549 pattrib->iv_len = pattrib->icv_len = 0;
550 }
551 return _SUCCESS;
552}
553
554sint r8712_validate_recv_frame(struct _adapter *adapter,
555 union recv_frame *precv_frame)
556{
557 /*shall check frame subtype, to / from ds, da, bssid */
558 /*then call check if rx seq/frag. duplicated.*/
559
560 u8 type;
561 u8 subtype;
562 sint retval = _SUCCESS;
563 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
564
565 u8 *ptr = precv_frame->u.hdr.rx_data;
566 u8 ver = (unsigned char)(*ptr) & 0x3;
567
568 /*add version chk*/
569 if (ver != 0)
570 return _FAIL;
571 type = GetFrameType(ptr);
572 subtype = GetFrameSubType(ptr); /*bit(7)~bit(2)*/
573 pattrib->to_fr_ds = get_tofr_ds(ptr);
574 pattrib->frag_num = GetFragNum(ptr);
575 pattrib->seq_num = GetSequence(ptr);
576 pattrib->pw_save = GetPwrMgt(ptr);
577 pattrib->mfrag = GetMFrag(ptr);
578 pattrib->mdata = GetMData(ptr);
579 pattrib->privacy = GetPrivacy(ptr);
580 pattrib->order = GetOrder(ptr);
581 switch (type) {
582 case WIFI_MGT_TYPE: /*mgnt*/
583 retval = validate_recv_mgnt_frame(adapter, precv_frame);
584 break;
585 case WIFI_CTRL_TYPE:/*ctrl*/
586 retval = validate_recv_ctrl_frame(adapter, precv_frame);
587 break;
588 case WIFI_DATA_TYPE: /*data*/
589 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
590 retval = validate_recv_data_frame(adapter, precv_frame);
591 break;
592 default:
593 return _FAIL;
594 }
595 return retval;
596}
597
598sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
599{
600 /*remove the wlanhdr and add the eth_hdr*/
601 sint rmv_len;
e29d3ebc 602 u16 len;
2865d42c
LF
603 u8 bsnaphdr;
604 u8 *psnap_type;
605 struct ieee80211_snap_hdr *psnap;
2865d42c
LF
606 struct _adapter *adapter = precvframe->u.hdr.adapter;
607 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
608
609 u8 *ptr = get_recvframe_data(precvframe); /*point to frame_ctrl field*/
610 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
611
612 if (pattrib->encrypt)
613 recvframe_pull_tail(precvframe, pattrib->icv_len);
614 psnap = (struct ieee80211_snap_hdr *)(ptr + pattrib->hdrlen +
615 pattrib->iv_len);
616 psnap_type = ptr + pattrib->hdrlen + pattrib->iv_len + SNAP_SIZE;
617 /* convert hdr + possible LLC headers into Ethernet header */
618 if ((!memcmp(psnap, (void *)rfc1042_header, SNAP_SIZE) &&
619 (memcmp(psnap_type, (void *)SNAP_ETH_TYPE_IPX, 2)) &&
620 (memcmp(psnap_type, (void *)SNAP_ETH_TYPE_APPLETALK_AARP, 2))) ||
621 !memcmp(psnap, (void *)bridge_tunnel_header, SNAP_SIZE)) {
622 /* remove RFC1042 or Bridge-Tunnel encapsulation and
623 * replace EtherType */
624 bsnaphdr = true;
625 } else {
626 /* Leave Ethernet header part of hdr and full payload */
627 bsnaphdr = false;
628 }
629 rmv_len = pattrib->hdrlen + pattrib->iv_len +
630 (bsnaphdr ? SNAP_SIZE : 0);
631 len = precvframe->u.hdr.len - rmv_len;
1ca96884 632 if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
2865d42c
LF
633 ptr += rmv_len;
634 *ptr = 0x87;
635 *(ptr+1) = 0x12;
2865d42c
LF
636 /* append rx status for mp test packets */
637 ptr = recvframe_pull(precvframe, (rmv_len -
638 sizeof(struct ethhdr) + 2) - 24);
639 memcpy(ptr, get_rxmem(precvframe), 24);
640 ptr += 24;
641 } else
642 ptr = recvframe_pull(precvframe, (rmv_len -
643 sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
644
645 memcpy(ptr, pattrib->dst, ETH_ALEN);
646 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
647 if (!bsnaphdr) {
648 len = htons(len);
649 memcpy(ptr + 12, &len, 2);
650 }
8ffca9ea 651 return _SUCCESS;
2865d42c
LF
652}
653
654s32 r8712_recv_entry(union recv_frame *precvframe)
655{
656 struct _adapter *padapter;
657 struct recv_priv *precvpriv;
2865d42c 658
2865d42c 659 s32 ret = _SUCCESS;
2865d42c
LF
660
661 padapter = precvframe->u.hdr.adapter;
2865d42c 662 precvpriv = &(padapter->recvpriv);
2865d42c
LF
663
664 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_RX);
665
666 ret = recv_func(padapter, precvframe);
667 if (ret == _FAIL)
668 goto _recv_entry_drop;
669 precvpriv->rx_pkts++;
670 precvpriv->rx_bytes += (uint)(precvframe->u.hdr.rx_tail -
671 precvframe->u.hdr.rx_data);
672 return ret;
673_recv_entry_drop:
674 precvpriv->rx_drop++;
675 padapter->mppriv.rx_pktloss = precvpriv->rx_drop;
676 return ret;
677}