Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 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 Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 14 | ******************************************************************************/ |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 15 | #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 patidar | 17452ee | 2014-06-21 18:19:37 +0530 | [diff] [blame] | 22 | #include <usb_ops_linux.h> |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 23 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 24 | /* alloc os related resource in struct recv_frame */ |
Sudip Mukherjee | 0b47649 | 2015-08-07 16:06:29 +0530 | [diff] [blame] | 25 | void rtw_os_recv_resource_alloc(struct recv_frame *precvframe) |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 26 | { |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 27 | precvframe->pkt_newalloc = NULL; |
| 28 | precvframe->pkt = NULL; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 29 | } |
| 30 | |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 31 | /* alloc os related resource in struct recv_buf */ |
| 32 | int rtw_os_recvbuf_resource_alloc(struct adapter *padapter, |
| 33 | struct recv_buf *precvbuf) |
| 34 | { |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 35 | precvbuf->pskb = NULL; |
| 36 | precvbuf->reuse = false; |
Sudip Mukherjee | 469d380 | 2015-08-07 16:06:30 +0530 | [diff] [blame] | 37 | precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL); |
| 38 | if (!precvbuf->purb) |
| 39 | return _FAIL; |
| 40 | return _SUCCESS; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 43 | void 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 Finger | c01fb49 | 2013-12-19 22:38:40 -0600 | [diff] [blame] | 52 | psecuritypriv->last_mic_err_time = jiffies; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 53 | } else { |
Larry Finger | c01fb49 | 2013-12-19 22:38:40 -0600 | [diff] [blame] | 54 | cur_time = jiffies; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 55 | |
| 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 Finger | c01fb49 | 2013-12-19 22:38:40 -0600 | [diff] [blame] | 61 | psecuritypriv->last_mic_err_time = jiffies; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 65 | memset(&ev, 0x00, sizeof(ev)); |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 66 | 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 patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 73 | memset(&wrqu, 0x00, sizeof(wrqu)); |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 74 | wrqu.data.length = sizeof(ev); |
| 75 | wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE, |
| 76 | &wrqu, (char *)&ev); |
| 77 | } |
| 78 | |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 79 | int rtw_recv_indicatepkt(struct adapter *padapter, |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 80 | struct recv_frame *precv_frame) |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 81 | { |
| 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 Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 87 | |
| 88 | precvpriv = &(padapter->recvpriv); |
| 89 | pfree_recv_queue = &(precvpriv->free_recv_queue); |
| 90 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 91 | skb = precv_frame->pkt; |
Shraddha Barke | fc749a9 | 2015-09-11 10:40:57 +0530 | [diff] [blame] | 92 | if (!skb) { |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 93 | 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 Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 101 | ("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 Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 103 | RT_TRACE(_module_recv_osdep_c_, _drv_info_, |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 104 | ("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 Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 107 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 108 | skb->data = precv_frame->rx_data; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 109 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 110 | skb_set_tail_pointer(skb, precv_frame->len); |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 111 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 112 | skb->len = precv_frame->len; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 113 | |
| 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 Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 123 | struct rx_pkt_attrib *pattrib = &precv_frame->attrib; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 124 | int bmcast = IS_MCAST(pattrib->dst); |
| 125 | |
Larry Finger | f42f52a | 2014-02-09 15:15:54 -0600 | [diff] [blame] | 126 | if (memcmp(pattrib->dst, myid(&padapter->eeprompriv), |
| 127 | ETH_ALEN)) { |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 128 | 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 Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 165 | precv_frame->pkt = NULL; |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 166 | |
| 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 Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 172 | |
| 173 | return _SUCCESS; |
| 174 | |
| 175 | _recv_indicatepkt_drop: |
| 176 | |
| 177 | /* enqueue back to free_recv_queue */ |
Larry Finger | 9b276d2 | 2013-09-04 15:55:59 -0500 | [diff] [blame] | 178 | rtw_free_recvframe(precv_frame, pfree_recv_queue); |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 179 | |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 180 | return _FAIL; |
| 181 | } |
| 182 | |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 183 | void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl) |
| 184 | { |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 185 | |
Vaishali Thakkar | 28af7ea | 2015-03-11 11:41:24 +0530 | [diff] [blame] | 186 | setup_timer(&preorder_ctrl->reordering_ctrl_timer, |
| 187 | rtw_reordering_ctrl_timeout_handler, |
| 188 | (unsigned long)preorder_ctrl); |
Larry Finger | 5adef66 | 2013-08-21 22:34:01 -0500 | [diff] [blame] | 189 | } |