• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * IP Packet Parser Module.
3  *
4  * Copyright (C) 1999-2013, Broadcom Corporation
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  * $Id$
25  */
26 #include <typedefs.h>
27 #include <osl.h>
28 
29 #include <proto/ethernet.h>
30 #include <proto/vlan.h>
31 #include <proto/802.3.h>
32 #include <proto/bcmip.h>
33 #include <bcmendian.h>
34 
35 #include <dhd_dbg.h>
36 
37 #include <dhd_ip.h>
38 
39 /* special values */
40 /* 802.3 llc/snap header */
41 static const uint8 llc_snap_hdr[SNAP_HDR_LEN] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
42 
pkt_frag_info(osl_t * osh,void * p)43 pkt_frag_t pkt_frag_info(osl_t *osh, void *p)
44 {
45 	uint8 *frame;
46 	int length;
47 	uint8 *pt;			/* Pointer to type field */
48 	uint16 ethertype;
49 	struct ipv4_hdr *iph;		/* IP frame pointer */
50 	int ipl;			/* IP frame length */
51 	uint16 iph_frag;
52 
53 	ASSERT(osh && p);
54 
55 	frame = PKTDATA(osh, p);
56 	length = PKTLEN(osh, p);
57 
58 	/* Process Ethernet II or SNAP-encapsulated 802.3 frames */
59 	if (length < ETHER_HDR_LEN) {
60 		DHD_INFO(("%s: short eth frame (%d)\n", __FUNCTION__, length));
61 		return DHD_PKT_FRAG_NONE;
62 	} else if (ntoh16(*(uint16 *)(frame + ETHER_TYPE_OFFSET)) >= ETHER_TYPE_MIN) {
63 		/* Frame is Ethernet II */
64 		pt = frame + ETHER_TYPE_OFFSET;
65 	} else if (length >= ETHER_HDR_LEN + SNAP_HDR_LEN + ETHER_TYPE_LEN &&
66 	           !bcmp(llc_snap_hdr, frame + ETHER_HDR_LEN, SNAP_HDR_LEN)) {
67 		pt = frame + ETHER_HDR_LEN + SNAP_HDR_LEN;
68 	} else {
69 		DHD_INFO(("%s: non-SNAP 802.3 frame\n", __FUNCTION__));
70 		return DHD_PKT_FRAG_NONE;
71 	}
72 
73 	ethertype = ntoh16(*(uint16 *)pt);
74 
75 	/* Skip VLAN tag, if any */
76 	if (ethertype == ETHER_TYPE_8021Q) {
77 		pt += VLAN_TAG_LEN;
78 
79 		if (pt + ETHER_TYPE_LEN > frame + length) {
80 			DHD_INFO(("%s: short VLAN frame (%d)\n", __FUNCTION__, length));
81 			return DHD_PKT_FRAG_NONE;
82 		}
83 
84 		ethertype = ntoh16(*(uint16 *)pt);
85 	}
86 
87 	if (ethertype != ETHER_TYPE_IP) {
88 		DHD_INFO(("%s: non-IP frame (ethertype 0x%x, length %d)\n",
89 			__FUNCTION__, ethertype, length));
90 		return DHD_PKT_FRAG_NONE;
91 	}
92 
93 	iph = (struct ipv4_hdr *)(pt + ETHER_TYPE_LEN);
94 	ipl = length - (pt + ETHER_TYPE_LEN - frame);
95 
96 	/* We support IPv4 only */
97 	if ((ipl < IPV4_OPTIONS_OFFSET) || (IP_VER(iph) != IP_VER_4)) {
98 		DHD_INFO(("%s: short frame (%d) or non-IPv4\n", __FUNCTION__, ipl));
99 		return DHD_PKT_FRAG_NONE;
100 	}
101 
102 	iph_frag = ntoh16(iph->frag);
103 
104 	if (iph_frag & IPV4_FRAG_DONT) {
105 		return DHD_PKT_FRAG_NONE;
106 	} else if ((iph_frag & IPV4_FRAG_MORE) == 0) {
107 		return DHD_PKT_FRAG_LAST;
108 	} else {
109 		return (iph_frag & IPV4_FRAG_OFFSET_MASK)? DHD_PKT_FRAG_CONT : DHD_PKT_FRAG_FIRST;
110 	}
111 }
112