linux/drivers/staging/rtl8188eu/os_dep/recv_linux.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/******************************************************************************
   3 *
   4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
   5 *
   6 ******************************************************************************/
   7#include <osdep_service.h>
   8#include <drv_types.h>
   9
  10#include <wifi.h>
  11#include <recv_osdep.h>
  12
  13#include <osdep_intf.h>
  14#include <usb_ops_linux.h>
  15
  16/* alloc os related resource in struct recv_buf */
  17int rtw_os_recvbuf_resource_alloc(struct recv_buf *precvbuf)
  18{
  19        precvbuf->pskb = NULL;
  20        precvbuf->reuse = false;
  21        precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
  22        if (!precvbuf->purb)
  23                return _FAIL;
  24        return _SUCCESS;
  25}
  26
  27void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
  28{
  29        union iwreq_data wrqu;
  30        struct iw_michaelmicfailure ev;
  31        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  32        struct security_priv *psecuritypriv = &padapter->securitypriv;
  33        u32 cur_time = 0;
  34
  35        if (psecuritypriv->last_mic_err_time == 0) {
  36                psecuritypriv->last_mic_err_time = jiffies;
  37        } else {
  38                cur_time = jiffies;
  39
  40                if (cur_time - psecuritypriv->last_mic_err_time < 60 * HZ) {
  41                        psecuritypriv->btkip_countermeasure = true;
  42                        psecuritypriv->last_mic_err_time = 0;
  43                        psecuritypriv->btkip_countermeasure_time = cur_time;
  44                } else {
  45                        psecuritypriv->last_mic_err_time = jiffies;
  46                }
  47        }
  48
  49        memset(&ev, 0x00, sizeof(ev));
  50        if (bgroup)
  51                ev.flags |= IW_MICFAILURE_GROUP;
  52        else
  53                ev.flags |= IW_MICFAILURE_PAIRWISE;
  54
  55        ev.src_addr.sa_family = ARPHRD_ETHER;
  56        memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
  57        memset(&wrqu, 0x00, sizeof(wrqu));
  58        wrqu.data.length = sizeof(ev);
  59        wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE,
  60                            &wrqu, (char *)&ev);
  61}
  62
  63int rtw_recv_indicatepkt(struct adapter *padapter,
  64                         struct recv_frame *precv_frame)
  65{
  66        struct recv_priv *precvpriv;
  67        struct __queue *pfree_recv_queue;
  68        struct sk_buff *skb;
  69        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  70
  71        precvpriv = &padapter->recvpriv;
  72        pfree_recv_queue = &precvpriv->free_recv_queue;
  73
  74        skb = precv_frame->pkt;
  75        if (!skb)
  76                goto _recv_indicatepkt_drop;
  77
  78        if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  79                struct sk_buff *pskb2 = NULL;
  80                struct sta_info *psta = NULL;
  81                struct sta_priv *pstapriv = &padapter->stapriv;
  82                struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
  83                bool mcast = is_multicast_ether_addr(pattrib->dst);
  84
  85                if (memcmp(pattrib->dst, myid(&padapter->eeprompriv),
  86                           ETH_ALEN)) {
  87                        if (mcast) {
  88                                psta = rtw_get_bcmc_stainfo(padapter);
  89                                pskb2 = skb_clone(skb, GFP_ATOMIC);
  90                        } else {
  91                                psta = rtw_get_stainfo(pstapriv, pattrib->dst);
  92                        }
  93
  94                        if (psta) {
  95                                struct net_device *pnetdev;
  96
  97                                pnetdev = (struct net_device *)padapter->pnetdev;
  98                                skb->dev = pnetdev;
  99                                skb_set_queue_mapping(skb, rtw_recv_select_queue(skb));
 100
 101                                rtw_xmit_entry(skb, pnetdev);
 102
 103                                if (mcast)
 104                                        skb = pskb2;
 105                                else
 106                                        goto _recv_indicatepkt_end;
 107                        }
 108                }
 109        }
 110
 111        skb->ip_summed = CHECKSUM_NONE;
 112        skb->dev = padapter->pnetdev;
 113        skb->protocol = eth_type_trans(skb, padapter->pnetdev);
 114
 115        netif_rx(skb);
 116
 117_recv_indicatepkt_end:
 118
 119        /*  pointers to NULL before rtw_free_recvframe() */
 120        precv_frame->pkt = NULL;
 121
 122        rtw_free_recvframe(precv_frame, pfree_recv_queue);
 123
 124        return _SUCCESS;
 125
 126_recv_indicatepkt_drop:
 127
 128         /* enqueue back to free_recv_queue */
 129        rtw_free_recvframe(precv_frame, pfree_recv_queue);
 130
 131        return _FAIL;
 132}
 133
 134void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
 135{
 136        timer_setup(&preorder_ctrl->reordering_ctrl_timer,
 137                    rtw_reordering_ctrl_timeout_handler, 0);
 138}
 139