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 #define _RECV_OSDEP_C_
22 #include <drv_types.h>
24 int rtw_os_recvframe_duplicate_skb(_adapter *padapter, union recv_frame *pcloneframe, _pkt *pskb)
27 _pkt *pkt_copy = NULL;
28 struct rx_pkt_attrib *pattrib = &pcloneframe->u.hdr.attrib;
31 RTW_INFO("%s [WARN] skb == NULL, drop frag frame\n", __func__);
35 pkt_copy = rtw_skb_copy(pskb);
37 if (pkt_copy == NULL) {
38 RTW_INFO("%s [WARN] rtw_skb_copy fail , drop frag frame\n", __func__);
42 pkt_copy = rtw_skb_clone(pskb);
44 if (pkt_copy == NULL) {
45 RTW_INFO("%s [WARN] rtw_skb_clone fail , drop frag frame\n", __func__);
49 pkt_copy->dev = padapter->pnetdev;
51 pcloneframe->u.hdr.pkt = pkt_copy;
52 pcloneframe->u.hdr.rx_head = pkt_copy->head;
53 pcloneframe->u.hdr.rx_data = pkt_copy->data;
54 pcloneframe->u.hdr.rx_end = skb_end_pointer(pkt_copy);
55 pcloneframe->u.hdr.rx_tail = skb_tail_pointer(pkt_copy);
56 pcloneframe->u.hdr.len = pkt_copy->len;
61 int rtw_os_alloc_recvframe(_adapter *padapter, union recv_frame *precvframe, u8 *pdata, _pkt *pskb)
65 u32 skb_len, alloc_sz;
66 _pkt *pkt_copy = NULL;
67 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
71 precvframe->u.hdr.pkt = NULL;
77 /* Modified by Albert 20101213 */
78 /* For 8 bytes IP header alignment. */
79 shift_sz = pattrib->qos ? 6 : 0; /* Qos data, wireless lan header length is 26 */
81 skb_len = pattrib->pkt_len;
83 /* for first fragment packet, driver need allocate 1536+drvinfo_sz+RXDESC_SIZE to defrag packet. */
84 /* modify alloc_sz for recvive crc error packet by thomas 2011-06-02 */
85 if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) {
86 /* alloc_sz = 1664; */ /* 1664 is 128 alignment. */
87 alloc_sz = (skb_len <= 1650) ? 1664 : (skb_len + 14);
90 /* 6 is for IP header 8 bytes alignment in QoS packet case. */
91 /* 8 is for skb->data 4 bytes alignment. */
95 pkt_copy = rtw_skb_alloc(alloc_sz);
98 pkt_copy->dev = padapter->pnetdev;
99 pkt_copy->len = skb_len;
100 precvframe->u.hdr.pkt = pkt_copy;
101 precvframe->u.hdr.rx_head = pkt_copy->head;
102 precvframe->u.hdr.rx_end = pkt_copy->data + alloc_sz;
103 skb_reserve(pkt_copy, 8 - ((SIZE_PTR)(pkt_copy->data) & 7)); /* force pkt_copy->data at 8-byte alignment address */
104 skb_reserve(pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */
105 _rtw_memcpy(pkt_copy->data, pdata, skb_len);
106 precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pkt_copy->data;
110 rtw_free_recvframe(precvframe_if2, &precvpriv->free_recv_queue);
111 rtw_enqueue_recvbuf_to_head(precvbuf, &precvpriv->recv_buf_pending_queue);
113 /* The case of can't allocate skb is serious and may never be recovered,
114 once bDriverStopped is enable, this task should be stopped.*/
115 if (!rtw_is_drv_stopped(secondary_padapter))
116 #ifdef PLATFORM_LINUX
117 tasklet_schedule(&precvpriv->recv_tasklet);
124 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
125 RTW_INFO("%s:can not allocate memory for skb copy\n", __func__);
127 precvframe->u.hdr.pkt = NULL;
129 /* rtw_free_recvframe(precvframe, pfree_recv_queue); */
130 /*exit_rtw_os_recv_resource_alloc;*/
134 if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) {
135 RTW_INFO("%s: alloc_skb fail , drop frag frame\n", __FUNCTION__);
136 /* rtw_free_recvframe(precvframe, pfree_recv_queue); */
138 goto exit_rtw_os_recv_resource_alloc;
143 goto exit_rtw_os_recv_resource_alloc;
146 precvframe->u.hdr.pkt = rtw_skb_clone(pskb);
147 if (precvframe->u.hdr.pkt) {
148 precvframe->u.hdr.pkt->dev = padapter->pnetdev;
149 precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pdata;
150 precvframe->u.hdr.rx_end = pdata + alloc_sz;
152 RTW_INFO("%s: rtw_skb_clone fail\n", __FUNCTION__);
153 /* rtw_free_recvframe(precvframe, pfree_recv_queue); */
154 /*exit_rtw_os_recv_resource_alloc;*/
160 exit_rtw_os_recv_resource_alloc:
166 void rtw_os_free_recvframe(union recv_frame *precvframe)
168 if (precvframe->u.hdr.pkt) {
169 rtw_skb_free(precvframe->u.hdr.pkt);/* free skb by driver */
171 precvframe->u.hdr.pkt = NULL;
175 /* init os related resource in struct recv_priv */
176 int rtw_os_recv_resource_init(struct recv_priv *precvpriv, _adapter *padapter)
181 #ifdef CONFIG_RTW_NAPI
182 skb_queue_head_init(&precvpriv->rx_napi_skb_queue);
183 #endif /* CONFIG_RTW_NAPI */
188 /* alloc os related resource in union recv_frame */
189 int rtw_os_recv_resource_alloc(_adapter *padapter, union recv_frame *precvframe)
193 precvframe->u.hdr.pkt_newalloc = precvframe->u.hdr.pkt = NULL;
198 /* free os related resource in union recv_frame */
199 void rtw_os_recv_resource_free(struct recv_priv *precvpriv)
202 union recv_frame *precvframe;
203 precvframe = (union recv_frame *) precvpriv->precv_frame_buf;
206 #ifdef CONFIG_RTW_NAPI
207 if (skb_queue_len(&precvpriv->rx_napi_skb_queue))
208 RTW_WARN("rx_napi_skb_queue not empty\n");
209 rtw_skb_queue_purge(&precvpriv->rx_napi_skb_queue);
210 #endif /* CONFIG_RTW_NAPI */
212 for (i = 0; i < NR_RECVFRAME; i++) {
213 if (precvframe->u.hdr.pkt) {
214 rtw_skb_free(precvframe->u.hdr.pkt);/* free skb by driver */
215 precvframe->u.hdr.pkt = NULL;
221 /* alloc os related resource in struct recv_buf */
222 int rtw_os_recvbuf_resource_alloc(_adapter *padapter, struct recv_buf *precvbuf)
226 #ifdef CONFIG_USB_HCI
227 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
228 struct usb_device *pusbd = pdvobjpriv->pusbdev;
230 precvbuf->irp_pending = _FALSE;
231 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
232 if (precvbuf->purb == NULL)
235 precvbuf->pskb = NULL;
237 precvbuf->pallocated_buf = precvbuf->pbuf = NULL;
239 precvbuf->pdata = precvbuf->phead = precvbuf->ptail = precvbuf->pend = NULL;
241 precvbuf->transfer_len = 0;
245 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
246 precvbuf->pallocated_buf = rtw_usb_buffer_alloc(pusbd, (size_t)precvbuf->alloc_sz, &precvbuf->dma_transfer_addr);
247 precvbuf->pbuf = precvbuf->pallocated_buf;
248 if (precvbuf->pallocated_buf == NULL)
250 #endif /* CONFIG_USE_USB_BUFFER_ALLOC_RX */
252 #endif /* CONFIG_USB_HCI */
257 /* free os related resource in struct recv_buf */
258 int rtw_os_recvbuf_resource_free(_adapter *padapter, struct recv_buf *precvbuf)
262 #ifdef CONFIG_USB_HCI
264 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
266 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
267 struct usb_device *pusbd = pdvobjpriv->pusbdev;
269 rtw_usb_buffer_free(pusbd, (size_t)precvbuf->alloc_sz, precvbuf->pallocated_buf, precvbuf->dma_transfer_addr);
270 precvbuf->pallocated_buf = NULL;
271 precvbuf->dma_transfer_addr = 0;
273 #endif /* CONFIG_USE_USB_BUFFER_ALLOC_RX */
275 if (precvbuf->purb) {
276 /* usb_kill_urb(precvbuf->purb); */
277 usb_free_urb(precvbuf->purb);
280 #endif /* CONFIG_USB_HCI */
283 if (precvbuf->pskb) {
284 #ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
285 if (rtw_free_skb_premem(precvbuf->pskb) != 0)
287 rtw_skb_free(precvbuf->pskb);
293 _pkt *rtw_os_alloc_msdu_pkt(union recv_frame *prframe, u16 nSubframe_Length, u8 *pdata)
298 struct rx_pkt_attrib *pattrib;
300 pattrib = &prframe->u.hdr.attrib;
302 #ifdef CONFIG_SKB_COPY
303 sub_skb = rtw_skb_alloc(nSubframe_Length + 12);
305 skb_reserve(sub_skb, 12);
306 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
307 _rtw_memcpy(data_ptr, (pdata + ETH_HLEN), nSubframe_Length);
309 #endif /* CONFIG_SKB_COPY */
311 sub_skb = rtw_skb_clone(prframe->u.hdr.pkt);
313 sub_skb->data = pdata + ETH_HLEN;
314 sub_skb->len = nSubframe_Length;
315 skb_set_tail_pointer(sub_skb, nSubframe_Length);
317 RTW_INFO("%s(): rtw_skb_clone() Fail!!!\n", __FUNCTION__);
322 eth_type = RTW_GET_BE16(&sub_skb->data[6]);
324 if (sub_skb->len >= 8 &&
325 ((_rtw_memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
326 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
327 _rtw_memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
328 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
329 skb_pull(sub_skb, SNAP_SIZE);
330 _rtw_memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
331 _rtw_memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
334 /* Leave Ethernet header part of hdr and full payload */
335 len = htons(sub_skb->len);
336 _rtw_memcpy(skb_push(sub_skb, 2), &len, 2);
337 _rtw_memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
338 _rtw_memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
344 #ifdef CONFIG_RTW_NAPI
345 static int napi_recv(_adapter *padapter, int budget)
348 struct recv_priv *precvpriv = &padapter->recvpriv;
350 struct registry_priv *pregistrypriv = &padapter->registrypriv;
354 while ((work_done < budget) &&
355 (!skb_queue_empty(&precvpriv->rx_napi_skb_queue))) {
356 pskb = skb_dequeue(&precvpriv->rx_napi_skb_queue);
362 #ifdef CONFIG_RTW_GRO
363 if (pregistrypriv->en_gro) {
364 if (rtw_napi_gro_receive(&padapter->napi, pskb) != GRO_DROP)
368 #endif /* CONFIG_RTW_GRO */
370 if (rtw_netif_receive_skb(padapter->pnetdev, pskb) == NET_RX_SUCCESS)
374 if (rx_ok == _TRUE) {
376 DBG_COUNTER(padapter->rx_logs.os_netif_ok);
378 DBG_COUNTER(padapter->rx_logs.os_netif_err);
385 int rtw_recv_napi_poll(struct napi_struct *napi, int budget)
387 _adapter *padapter = container_of(napi, _adapter, napi);
389 struct recv_priv *precvpriv = &padapter->recvpriv;
392 work_done = napi_recv(padapter, budget);
393 if (work_done < budget) {
395 if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue))
401 #endif /* CONFIG_RTW_NAPI */
403 #ifdef DBG_UDP_PKT_LOSE_11AC
404 #define PAYLOAD_LEN_LOC_OF_IP_HDR 0x10 /*ethernet payload length location of ip header (DA + SA+eth_type+(version&hdr_len)) */
407 void rtw_os_recv_indicate_pkt(_adapter *padapter, _pkt *pkt, struct rx_pkt_attrib *pattrib)
409 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
410 struct recv_priv *precvpriv = &(padapter->recvpriv);
411 struct registry_priv *pregistrypriv = &padapter->registrypriv;
413 void *br_port = NULL;
417 /* Indicat the packets to upper layer */
419 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
421 struct sta_info *psta = NULL;
422 struct sta_priv *pstapriv = &padapter->stapriv;
423 int bmcast = IS_MCAST(pattrib->dst);
425 /* RTW_INFO("bmcast=%d\n", bmcast); */
427 if (_rtw_memcmp(pattrib->dst, adapter_mac_addr(padapter), ETH_ALEN) == _FALSE) {
428 /* RTW_INFO("not ap psta=%p, addr=%pM\n", psta, pattrib->dst); */
431 psta = rtw_get_bcmc_stainfo(padapter);
432 pskb2 = rtw_skb_clone(pkt);
434 psta = rtw_get_stainfo(pstapriv, pattrib->dst);
437 struct net_device *pnetdev = (struct net_device *)padapter->pnetdev;
439 /* RTW_INFO("directly forwarding to the rtw_xmit_entry\n"); */
441 /* skb->ip_summed = CHECKSUM_NONE; */
443 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
444 skb_set_queue_mapping(pkt, rtw_recv_select_queue(pkt));
445 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35) */
447 _rtw_xmit_entry(pkt, pnetdev);
449 if (bmcast && (pskb2 != NULL)) {
451 DBG_COUNTER(padapter->rx_logs.os_indicate_ap_mcast);
453 DBG_COUNTER(padapter->rx_logs.os_indicate_ap_forward);
457 } else { /* to APself */
458 /* RTW_INFO("to APSelf\n"); */
459 DBG_COUNTER(padapter->rx_logs.os_indicate_ap_self);
464 /* Insert NAT2.5 RX here! */
465 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
466 br_port = padapter->pnetdev->br_port;
467 #else /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35)) */
469 br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
471 #endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35)) */
474 if (br_port && (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE) == _TRUE)) {
475 int nat25_handle_frame(_adapter *priv, struct sk_buff *skb);
476 if (nat25_handle_frame(padapter, pkt) == -1) {
477 /* priv->ext_stats.rx_data_drops++; */
478 /* DEBUG_ERR("RX DROP: nat25_handle_frame fail!\n"); */
482 /* bypass this frame to upper layer!! */
484 rtw_skb_free(sub_skb);
489 #endif /* CONFIG_BR_EXT */
490 if (precvpriv->sink_udpport > 0)
491 rtw_sink_rtp_seq_dbg(padapter, pkt);
492 #ifdef DBG_UDP_PKT_LOSE_11AC
493 /* After eth_type_trans process , pkt->data pointer will move from ethrnet header to ip header ,
494 * we have to check ethernet type , so this debug must be print before eth_type_trans
496 if (*((unsigned short *)(pkt->data + ETH_ALEN * 2)) == htons(ETH_P_ARP)) {
497 /* ARP Payload length will be 42bytes or 42+18(tailer)=60bytes*/
498 if (pkt->len != 42 && pkt->len != 60)
499 RTW_INFO("Error !!%s,ARP Payload length %u not correct\n" , __func__ , pkt->len);
500 } else if (*((unsigned short *)(pkt->data + ETH_ALEN * 2)) == htons(ETH_P_IP)) {
501 if (be16_to_cpu(*((u16 *)(pkt->data + PAYLOAD_LEN_LOC_OF_IP_HDR))) != (pkt->len) - ETH_HLEN) {
502 RTW_INFO("Error !!%s,Payload length not correct\n" , __func__);
503 RTW_INFO("%s, IP header describe Total length=%u\n" , __func__ , be16_to_cpu(*((u16 *)(pkt->data + PAYLOAD_LEN_LOC_OF_IP_HDR))));
504 RTW_INFO("%s, Pkt real length=%u\n" , __func__ , (pkt->len) - ETH_HLEN);
508 /* After eth_type_trans process , pkt->data pointer will move from ethrnet header to ip header */
509 pkt->protocol = eth_type_trans(pkt, padapter->pnetdev);
510 pkt->dev = padapter->pnetdev;
512 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
513 if ((pattrib->tcpchk_valid == 1) && (pattrib->tcp_chkrpt == 1))
514 pkt->ip_summed = CHECKSUM_UNNECESSARY;
516 pkt->ip_summed = CHECKSUM_NONE;
517 #else /* !CONFIG_TCP_CSUM_OFFLOAD_RX */
518 pkt->ip_summed = CHECKSUM_NONE;
519 #endif /* CONFIG_TCP_CSUM_OFFLOAD_RX */
521 #ifdef CONFIG_RTW_NAPI
522 if (pregistrypriv->en_napi) {
523 skb_queue_tail(&precvpriv->rx_napi_skb_queue, pkt);
524 napi_schedule(&padapter->napi);
527 #endif /* CONFIG_RTW_NAPI */
529 ret = rtw_netif_rx(padapter->pnetdev, pkt);
530 if (ret == NET_RX_SUCCESS)
531 DBG_COUNTER(padapter->rx_logs.os_netif_ok);
533 DBG_COUNTER(padapter->rx_logs.os_netif_err);
537 void rtw_handle_tkip_mic_err(_adapter *padapter, struct sta_info *sta, u8 bgroup)
539 #ifdef CONFIG_IOCTL_CFG80211
540 enum nl80211_key_type key_type = 0;
542 union iwreq_data wrqu;
543 struct iw_michaelmicfailure ev;
544 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
545 struct security_priv *psecuritypriv = &padapter->securitypriv;
548 if (psecuritypriv->last_mic_err_time == 0)
549 psecuritypriv->last_mic_err_time = rtw_get_current_time();
551 cur_time = rtw_get_current_time();
553 if (cur_time - psecuritypriv->last_mic_err_time < 60 * HZ) {
554 psecuritypriv->btkip_countermeasure = _TRUE;
555 psecuritypriv->last_mic_err_time = 0;
556 psecuritypriv->btkip_countermeasure_time = cur_time;
558 psecuritypriv->last_mic_err_time = rtw_get_current_time();
561 #ifdef CONFIG_IOCTL_CFG80211
563 key_type |= NL80211_KEYTYPE_GROUP;
565 key_type |= NL80211_KEYTYPE_PAIRWISE;
567 cfg80211_michael_mic_failure(padapter->pnetdev, sta->hwaddr, key_type, -1, NULL, GFP_ATOMIC);
570 _rtw_memset(&ev, 0x00, sizeof(ev));
572 ev.flags |= IW_MICFAILURE_GROUP;
574 ev.flags |= IW_MICFAILURE_PAIRWISE;
576 ev.src_addr.sa_family = ARPHRD_ETHER;
577 _rtw_memcpy(ev.src_addr.sa_data, sta->hwaddr, ETH_ALEN);
579 _rtw_memset(&wrqu, 0x00, sizeof(wrqu));
580 wrqu.data.length = sizeof(ev);
582 #ifndef CONFIG_IOCTL_CFG80211
583 wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev);
587 void rtw_hostapd_mlme_rx(_adapter *padapter, union recv_frame *precv_frame)
589 #ifdef CONFIG_HOSTAPD_MLME
591 struct hostapd_priv *phostapdpriv = padapter->phostapdpriv;
592 struct net_device *pmgnt_netdev = phostapdpriv->pmgnt_netdev;
595 skb = precv_frame->u.hdr.pkt;
600 skb->data = precv_frame->u.hdr.rx_data;
601 skb->tail = precv_frame->u.hdr.rx_tail;
602 skb->len = precv_frame->u.hdr.len;
604 /* pskb_copy = rtw_skb_copy(skb);
605 * if(skb == NULL) goto _exit; */
607 skb->dev = pmgnt_netdev;
608 skb->ip_summed = CHECKSUM_NONE;
609 skb->pkt_type = PACKET_OTHERHOST;
610 /* skb->protocol = __constant_htons(0x0019); ETH_P_80211_RAW */
611 skb->protocol = __constant_htons(0x0003); /*ETH_P_80211_RAW*/
613 /* RTW_INFO("(1)data=0x%x, head=0x%x, tail=0x%x, mac_header=0x%x, len=%d\n", skb->data, skb->head, skb->tail, skb->mac_header, skb->len); */
615 /* skb->mac.raw = skb->data; */
616 skb_reset_mac_header(skb);
618 /* skb_pull(skb, 24); */
619 _rtw_memset(skb->cb, 0, sizeof(skb->cb));
621 rtw_netif_rx(pmgnt_netdev, skb);
623 precv_frame->u.hdr.pkt = NULL; /* set pointer to NULL before rtw_free_recvframe() if call rtw_netif_rx() */
627 #ifdef CONFIG_AUTO_AP_MODE
628 static void rtw_os_ksocket_send(_adapter *padapter, union recv_frame *precv_frame)
630 _pkt *skb = precv_frame->u.hdr.pkt;
631 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
632 struct sta_info *psta = precv_frame->u.hdr.psta;
634 RTW_INFO("eth rx: got eth_type=0x%x\n", pattrib->eth_type);
636 if (psta && psta->isrc && psta->pid > 0) {
639 rx_pid = *(u16 *)(skb->data + ETH_HLEN);
641 RTW_INFO("eth rx(pid=0x%x): sta("MAC_FMT") pid=0x%x\n",
642 rx_pid, MAC_ARG(psta->hwaddr), psta->pid);
644 if (rx_pid == psta->pid) {
646 u16 len = *(u16 *)(skb->data + ETH_HLEN + 2);
647 /* u16 ctrl_type = *(u16*)(skb->data+ETH_HLEN+4); */
649 /* RTW_INFO("eth, RC: len=0x%x, ctrl_type=0x%x\n", len, ctrl_type); */
650 RTW_INFO("eth, RC: len=0x%x\n", len);
652 for (i = 0; i < len; i++)
653 RTW_INFO("0x%x\n", *(skb->data + ETH_HLEN + 4 + i));
654 /* RTW_INFO("0x%x\n", *(skb->data+ETH_HLEN+6+i)); */
656 RTW_INFO("eth, RC-end\n");
659 /* send_sz = ksocket_send(padapter->ksock_send, &padapter->kaddr_send, (skb->data+ETH_HLEN+2), len); */
660 rtw_recv_ksocket_send_cmd(padapter, (skb->data + ETH_HLEN + 2), len);
662 /* RTW_INFO("ksocket_send size=%d\n", send_sz); */
669 #endif /* CONFIG_AUTO_AP_MODE */
671 int rtw_recv_monitor(_adapter *padapter, union recv_frame *precv_frame)
674 struct recv_priv *precvpriv;
675 _queue *pfree_recv_queue;
677 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
678 struct rx_pkt_attrib *pattrib;
680 if (NULL == precv_frame)
683 pattrib = &precv_frame->u.hdr.attrib;
684 precvpriv = &(padapter->recvpriv);
685 pfree_recv_queue = &(precvpriv->free_recv_queue);
687 skb = precv_frame->u.hdr.pkt;
689 RTW_INFO("%s :skb==NULL something wrong!!!!\n", __func__);
693 skb->data = precv_frame->u.hdr.rx_data;
694 skb_set_tail_pointer(skb, precv_frame->u.hdr.len);
695 skb->len = precv_frame->u.hdr.len;
696 skb->ip_summed = CHECKSUM_NONE;
697 skb->pkt_type = PACKET_OTHERHOST;
698 skb->protocol = htons(0x0019); /* ETH_P_80211_RAW */
700 rtw_netif_rx(padapter->pnetdev, skb);
702 /* pointers to NULL before rtw_free_recvframe() */
703 precv_frame->u.hdr.pkt = NULL;
709 /* enqueue back to free_recv_queue */
711 rtw_free_recvframe(precv_frame, pfree_recv_queue);
717 int rtw_recv_indicatepkt(_adapter *padapter, union recv_frame *precv_frame)
719 struct recv_priv *precvpriv;
720 _queue *pfree_recv_queue;
722 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
723 struct rx_pkt_attrib *pattrib;
725 if (NULL == precv_frame)
726 goto _recv_indicatepkt_drop;
728 DBG_COUNTER(padapter->rx_logs.os_indicate);
729 pattrib = &precv_frame->u.hdr.attrib;
730 precvpriv = &(padapter->recvpriv);
731 pfree_recv_queue = &(precvpriv->free_recv_queue);
733 #ifdef CONFIG_DRVEXT_MODULE
734 if (drvext_rx_handler(padapter, precv_frame->u.hdr.rx_data, precv_frame->u.hdr.len) == _SUCCESS)
735 goto _recv_indicatepkt_drop;
738 #ifdef CONFIG_WAPI_SUPPORT
739 if (rtw_wapi_check_for_drop(padapter, precv_frame)) {
740 WAPI_TRACE(WAPI_ERR, "%s(): Rx Reorder Drop case!!\n", __FUNCTION__);
741 goto _recv_indicatepkt_drop;
745 skb = precv_frame->u.hdr.pkt;
747 goto _recv_indicatepkt_drop;
751 skb->data = precv_frame->u.hdr.rx_data;
753 skb_set_tail_pointer(skb, precv_frame->u.hdr.len);
755 skb->len = precv_frame->u.hdr.len;
758 if (pattrib->eth_type == 0x888e)
759 RTW_PRINT("recv eapol packet\n");
761 #ifdef CONFIG_AUTO_AP_MODE
762 #if 1 /* for testing */
764 if (0x8899 == pattrib->eth_type) {
765 rtw_os_ksocket_send(padapter, precv_frame);
767 /* goto _recv_indicatepkt_drop; */
770 if (0x8899 == pattrib->eth_type) {
771 rtw_auto_ap_mode_rx(padapter, precv_frame);
773 goto _recv_indicatepkt_end;
777 #endif /* CONFIG_AUTO_AP_MODE */
779 /* TODO: move to core */
782 struct ethhdr *etherhdr = (struct ethhdr *)pkt->data;
783 struct sta_info *sta = precv_frame->u.hdr.psta;
786 goto bypass_session_tracker;
788 if (ntohs(etherhdr->h_proto) == ETH_P_IP) {
789 u8 *ip = pkt->data + 14;
791 if (GET_IPV4_PROTOCOL(ip) == 0x06 /* TCP */
792 && rtw_st_ctl_chk_reg_s_proto(&sta->st_ctl, 0x06) == _TRUE
794 u8 *tcp = ip + GET_IPV4_IHL(ip) * 4;
796 if (rtw_st_ctl_chk_reg_rule(&sta->st_ctl, padapter, IPV4_DST(ip), TCP_DST(tcp), IPV4_SRC(ip), TCP_SRC(tcp)) == _TRUE) {
797 if (GET_TCP_SYN(tcp) && GET_TCP_ACK(tcp)) {
798 session_tracker_add_cmd(padapter, sta
799 , IPV4_DST(ip), TCP_DST(tcp)
800 , IPV4_SRC(ip), TCP_SRC(tcp));
801 if (DBG_SESSION_TRACKER)
802 RTW_INFO(FUNC_ADPT_FMT" local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT" SYN-ACK\n"
803 , FUNC_ADPT_ARG(padapter)
804 , IP_ARG(IPV4_DST(ip)), PORT_ARG(TCP_DST(tcp))
805 , IP_ARG(IPV4_SRC(ip)), PORT_ARG(TCP_SRC(tcp)));
807 if (GET_TCP_FIN(tcp)) {
808 session_tracker_del_cmd(padapter, sta
809 , IPV4_DST(ip), TCP_DST(tcp)
810 , IPV4_SRC(ip), TCP_SRC(tcp));
811 if (DBG_SESSION_TRACKER)
812 RTW_INFO(FUNC_ADPT_FMT" local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT" FIN\n"
813 , FUNC_ADPT_ARG(padapter)
814 , IP_ARG(IPV4_DST(ip)), PORT_ARG(TCP_DST(tcp))
815 , IP_ARG(IPV4_SRC(ip)), PORT_ARG(TCP_SRC(tcp)));
821 bypass_session_tracker:
825 rtw_os_recv_indicate_pkt(padapter, skb, pattrib);
827 _recv_indicatepkt_end:
829 precv_frame->u.hdr.pkt = NULL; /* pointers to NULL before rtw_free_recvframe() */
831 rtw_free_recvframe(precv_frame, pfree_recv_queue);
837 _recv_indicatepkt_drop:
839 /* enqueue back to free_recv_queue */
841 rtw_free_recvframe(precv_frame, pfree_recv_queue);
843 DBG_COUNTER(padapter->rx_logs.os_indicate_err);
849 void rtw_os_read_port(_adapter *padapter, struct recv_buf *precvbuf)
851 struct recv_priv *precvpriv = &padapter->recvpriv;
853 #ifdef CONFIG_USB_HCI
857 /* free skb in recv_buf */
858 rtw_skb_free(precvbuf->pskb);
860 precvbuf->pskb = NULL;
862 if (precvbuf->irp_pending == _FALSE)
863 rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);
867 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
868 precvbuf->pskb = NULL;
872 void _rtw_reordering_ctrl_timeout_handler(void *FunctionContext);
873 void _rtw_reordering_ctrl_timeout_handler(void *FunctionContext)
875 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)FunctionContext;
876 rtw_reordering_ctrl_timeout_handler(preorder_ctrl);
879 void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
881 _adapter *padapter = preorder_ctrl->padapter;
883 _init_timer(&(preorder_ctrl->reordering_ctrl_timer), padapter->pnetdev, _rtw_reordering_ctrl_timeout_handler, preorder_ctrl);