1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #include <osdep_service.h>
21 #include <drv_types.h>
24 #include <recv_osdep.h>
26 #include <osdep_intf.h>
27 #include <usb_ops_linux.h>
29 /* alloc os related resource in struct recv_frame */
30 void rtw_os_recv_resource_alloc(struct recv_frame *precvframe)
32 precvframe->pkt_newalloc = NULL;
33 precvframe->pkt = NULL;
36 /* alloc os related resource in struct recv_buf */
37 int rtw_os_recvbuf_resource_alloc(struct adapter *padapter,
38 struct recv_buf *precvbuf)
40 precvbuf->pskb = NULL;
41 precvbuf->reuse = false;
42 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
48 void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
50 union iwreq_data wrqu;
51 struct iw_michaelmicfailure ev;
52 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
53 struct security_priv *psecuritypriv = &padapter->securitypriv;
56 if (psecuritypriv->last_mic_err_time == 0) {
57 psecuritypriv->last_mic_err_time = jiffies;
61 if (cur_time - psecuritypriv->last_mic_err_time < 60*HZ) {
62 psecuritypriv->btkip_countermeasure = true;
63 psecuritypriv->last_mic_err_time = 0;
64 psecuritypriv->btkip_countermeasure_time = cur_time;
66 psecuritypriv->last_mic_err_time = jiffies;
70 memset(&ev, 0x00, sizeof(ev));
72 ev.flags |= IW_MICFAILURE_GROUP;
74 ev.flags |= IW_MICFAILURE_PAIRWISE;
76 ev.src_addr.sa_family = ARPHRD_ETHER;
77 memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
78 memset(&wrqu, 0x00, sizeof(wrqu));
79 wrqu.data.length = sizeof(ev);
80 wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE,
84 int rtw_recv_indicatepkt(struct adapter *padapter,
85 struct recv_frame *precv_frame)
87 struct recv_priv *precvpriv;
88 struct __queue *pfree_recv_queue;
90 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
93 precvpriv = &(padapter->recvpriv);
94 pfree_recv_queue = &(precvpriv->free_recv_queue);
96 skb = precv_frame->pkt;
98 RT_TRACE(_module_recv_osdep_c_, _drv_err_,
99 ("rtw_recv_indicatepkt():skb == NULL something wrong!!!!\n"));
100 goto _recv_indicatepkt_drop;
103 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
104 ("rtw_recv_indicatepkt():skb != NULL !!!\n"));
105 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
106 ("rtw_recv_indicatepkt():precv_frame->rx_head =%p precv_frame->hdr.rx_data =%p\n",
107 precv_frame->rx_head, precv_frame->rx_data));
108 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
109 ("precv_frame->hdr.rx_tail =%p precv_frame->rx_end =%p precv_frame->hdr.len =%d\n",
110 precv_frame->rx_tail, precv_frame->rx_end,
113 skb->data = precv_frame->rx_data;
115 skb_set_tail_pointer(skb, precv_frame->len);
117 skb->len = precv_frame->len;
119 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
120 ("skb->head =%p skb->data =%p skb->tail =%p skb->end =%p skb->len =%d\n",
121 skb->head, skb->data, skb_tail_pointer(skb),
122 skb_end_pointer(skb), skb->len));
124 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
125 struct sk_buff *pskb2 = NULL;
126 struct sta_info *psta = NULL;
127 struct sta_priv *pstapriv = &padapter->stapriv;
128 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
129 int bmcast = IS_MCAST(pattrib->dst);
131 if (memcmp(pattrib->dst, myid(&padapter->eeprompriv),
134 psta = rtw_get_bcmc_stainfo(padapter);
135 pskb2 = skb_clone(skb, GFP_ATOMIC);
137 psta = rtw_get_stainfo(pstapriv, pattrib->dst);
141 struct net_device *pnetdev;
143 pnetdev = (struct net_device *)padapter->pnetdev;
145 skb_set_queue_mapping(skb, rtw_recv_select_queue(skb));
147 rtw_xmit_entry(skb, pnetdev);
152 goto _recv_indicatepkt_end;
158 rcu_dereference(padapter->pnetdev->rx_handler_data);
161 skb->ip_summed = CHECKSUM_NONE;
162 skb->dev = padapter->pnetdev;
163 skb->protocol = eth_type_trans(skb, padapter->pnetdev);
167 _recv_indicatepkt_end:
169 /* pointers to NULL before rtw_free_recvframe() */
170 precv_frame->pkt = NULL;
172 rtw_free_recvframe(precv_frame, pfree_recv_queue);
174 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
175 ("\n rtw_recv_indicatepkt :after netif_rx!!!!\n"));
180 _recv_indicatepkt_drop:
182 /* enqueue back to free_recv_queue */
183 rtw_free_recvframe(precv_frame, pfree_recv_queue);
188 void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
191 setup_timer(&preorder_ctrl->reordering_ctrl_timer,
192 rtw_reordering_ctrl_timeout_handler,
193 (unsigned long)preorder_ctrl);