blob: 0c44914ea3e65198cfbd8b9e53ae4a30fc9cc698 [file] [log] [blame]
Larry Finger5adef662013-08-21 22:34:01 -05001/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
Larry Finger5adef662013-08-21 22:34:01 -050014 ******************************************************************************/
Larry Finger5adef662013-08-21 22:34:01 -050015#include <osdep_service.h>
16#include <drv_types.h>
17
18#include <wifi.h>
19#include <recv_osdep.h>
20
21#include <osdep_intf.h>
navin patidar17452ee2014-06-21 18:19:37 +053022#include <usb_ops_linux.h>
Larry Finger5adef662013-08-21 22:34:01 -050023
Larry Fingerf31cca82014-02-14 16:54:07 -060024/* alloc os related resource in struct recv_frame */
Sudip Mukherjee0b476492015-08-07 16:06:29 +053025void rtw_os_recv_resource_alloc(struct recv_frame *precvframe)
Larry Finger5adef662013-08-21 22:34:01 -050026{
Larry Fingerf31cca82014-02-14 16:54:07 -060027 precvframe->pkt_newalloc = NULL;
28 precvframe->pkt = NULL;
Larry Finger5adef662013-08-21 22:34:01 -050029}
30
Larry Finger5adef662013-08-21 22:34:01 -050031/* alloc os related resource in struct recv_buf */
32int rtw_os_recvbuf_resource_alloc(struct adapter *padapter,
33 struct recv_buf *precvbuf)
34{
Larry Finger5adef662013-08-21 22:34:01 -050035 precvbuf->pskb = NULL;
36 precvbuf->reuse = false;
Sudip Mukherjee469d3802015-08-07 16:06:30 +053037 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
38 if (!precvbuf->purb)
39 return _FAIL;
40 return _SUCCESS;
Larry Finger5adef662013-08-21 22:34:01 -050041}
42
Larry Finger5adef662013-08-21 22:34:01 -050043void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
44{
45 union iwreq_data wrqu;
46 struct iw_michaelmicfailure ev;
47 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
48 struct security_priv *psecuritypriv = &padapter->securitypriv;
49 u32 cur_time = 0;
50
51 if (psecuritypriv->last_mic_err_time == 0) {
Larry Fingerc01fb492013-12-19 22:38:40 -060052 psecuritypriv->last_mic_err_time = jiffies;
Larry Finger5adef662013-08-21 22:34:01 -050053 } else {
Larry Fingerc01fb492013-12-19 22:38:40 -060054 cur_time = jiffies;
Larry Finger5adef662013-08-21 22:34:01 -050055
56 if (cur_time - psecuritypriv->last_mic_err_time < 60*HZ) {
57 psecuritypriv->btkip_countermeasure = true;
58 psecuritypriv->last_mic_err_time = 0;
59 psecuritypriv->btkip_countermeasure_time = cur_time;
60 } else {
Larry Fingerc01fb492013-12-19 22:38:40 -060061 psecuritypriv->last_mic_err_time = jiffies;
Larry Finger5adef662013-08-21 22:34:01 -050062 }
63 }
64
navin patidar1ce39842014-06-22 13:49:28 +053065 memset(&ev, 0x00, sizeof(ev));
Larry Finger5adef662013-08-21 22:34:01 -050066 if (bgroup)
67 ev.flags |= IW_MICFAILURE_GROUP;
68 else
69 ev.flags |= IW_MICFAILURE_PAIRWISE;
70
71 ev.src_addr.sa_family = ARPHRD_ETHER;
72 memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
navin patidar1ce39842014-06-22 13:49:28 +053073 memset(&wrqu, 0x00, sizeof(wrqu));
Larry Finger5adef662013-08-21 22:34:01 -050074 wrqu.data.length = sizeof(ev);
75 wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE,
76 &wrqu, (char *)&ev);
77}
78
Larry Finger5adef662013-08-21 22:34:01 -050079int rtw_recv_indicatepkt(struct adapter *padapter,
Larry Fingerf31cca82014-02-14 16:54:07 -060080 struct recv_frame *precv_frame)
Larry Finger5adef662013-08-21 22:34:01 -050081{
82 struct recv_priv *precvpriv;
83 struct __queue *pfree_recv_queue;
84 struct sk_buff *skb;
85 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
86
Larry Finger5adef662013-08-21 22:34:01 -050087
88 precvpriv = &(padapter->recvpriv);
89 pfree_recv_queue = &(precvpriv->free_recv_queue);
90
Larry Fingerf31cca82014-02-14 16:54:07 -060091 skb = precv_frame->pkt;
Shraddha Barkefc749a92015-09-11 10:40:57 +053092 if (!skb) {
Larry Finger5adef662013-08-21 22:34:01 -050093 RT_TRACE(_module_recv_osdep_c_, _drv_err_,
94 ("rtw_recv_indicatepkt():skb == NULL something wrong!!!!\n"));
95 goto _recv_indicatepkt_drop;
96 }
97
98 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
99 ("rtw_recv_indicatepkt():skb != NULL !!!\n"));
100 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
Larry Fingerf31cca82014-02-14 16:54:07 -0600101 ("rtw_recv_indicatepkt():precv_frame->rx_head =%p precv_frame->hdr.rx_data =%p\n",
102 precv_frame->rx_head, precv_frame->rx_data));
Larry Finger5adef662013-08-21 22:34:01 -0500103 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
Larry Fingerf31cca82014-02-14 16:54:07 -0600104 ("precv_frame->hdr.rx_tail =%p precv_frame->rx_end =%p precv_frame->hdr.len =%d\n",
105 precv_frame->rx_tail, precv_frame->rx_end,
106 precv_frame->len));
Larry Finger5adef662013-08-21 22:34:01 -0500107
Larry Fingerf31cca82014-02-14 16:54:07 -0600108 skb->data = precv_frame->rx_data;
Larry Finger5adef662013-08-21 22:34:01 -0500109
Larry Fingerf31cca82014-02-14 16:54:07 -0600110 skb_set_tail_pointer(skb, precv_frame->len);
Larry Finger5adef662013-08-21 22:34:01 -0500111
Larry Fingerf31cca82014-02-14 16:54:07 -0600112 skb->len = precv_frame->len;
Larry Finger5adef662013-08-21 22:34:01 -0500113
114 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
115 ("skb->head =%p skb->data =%p skb->tail =%p skb->end =%p skb->len =%d\n",
116 skb->head, skb->data, skb_tail_pointer(skb),
117 skb_end_pointer(skb), skb->len));
118
119 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
120 struct sk_buff *pskb2 = NULL;
121 struct sta_info *psta = NULL;
122 struct sta_priv *pstapriv = &padapter->stapriv;
Larry Fingerf31cca82014-02-14 16:54:07 -0600123 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
Larry Finger5adef662013-08-21 22:34:01 -0500124 int bmcast = IS_MCAST(pattrib->dst);
125
Larry Fingerf42f52a2014-02-09 15:15:54 -0600126 if (memcmp(pattrib->dst, myid(&padapter->eeprompriv),
127 ETH_ALEN)) {
Larry Finger5adef662013-08-21 22:34:01 -0500128 if (bmcast) {
129 psta = rtw_get_bcmc_stainfo(padapter);
130 pskb2 = skb_clone(skb, GFP_ATOMIC);
131 } else {
132 psta = rtw_get_stainfo(pstapriv, pattrib->dst);
133 }
134
135 if (psta) {
136 struct net_device *pnetdev;
137
138 pnetdev = (struct net_device *)padapter->pnetdev;
139 skb->dev = pnetdev;
140 skb_set_queue_mapping(skb, rtw_recv_select_queue(skb));
141
142 rtw_xmit_entry(skb, pnetdev);
143
144 if (bmcast)
145 skb = pskb2;
146 else
147 goto _recv_indicatepkt_end;
148 }
149 }
150 }
151
152 rcu_read_lock();
153 rcu_dereference(padapter->pnetdev->rx_handler_data);
154 rcu_read_unlock();
155
156 skb->ip_summed = CHECKSUM_NONE;
157 skb->dev = padapter->pnetdev;
158 skb->protocol = eth_type_trans(skb, padapter->pnetdev);
159
160 netif_rx(skb);
161
162_recv_indicatepkt_end:
163
164 /* pointers to NULL before rtw_free_recvframe() */
Larry Fingerf31cca82014-02-14 16:54:07 -0600165 precv_frame->pkt = NULL;
Larry Finger5adef662013-08-21 22:34:01 -0500166
167 rtw_free_recvframe(precv_frame, pfree_recv_queue);
168
169 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
170 ("\n rtw_recv_indicatepkt :after netif_rx!!!!\n"));
171
Larry Finger5adef662013-08-21 22:34:01 -0500172
173 return _SUCCESS;
174
175_recv_indicatepkt_drop:
176
177 /* enqueue back to free_recv_queue */
Larry Finger9b276d22013-09-04 15:55:59 -0500178 rtw_free_recvframe(precv_frame, pfree_recv_queue);
Larry Finger5adef662013-08-21 22:34:01 -0500179
Larry Finger5adef662013-08-21 22:34:01 -0500180 return _FAIL;
181}
182
Larry Finger5adef662013-08-21 22:34:01 -0500183void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
184{
Larry Finger5adef662013-08-21 22:34:01 -0500185
Vaishali Thakkar28af7ea2015-03-11 11:41:24 +0530186 setup_timer(&preorder_ctrl->reordering_ctrl_timer,
187 rtw_reordering_ctrl_timeout_handler,
188 (unsigned long)preorder_ctrl);
Larry Finger5adef662013-08-21 22:34:01 -0500189}