2 * IP Packet Parser Module.
4 * $Copyright Open Broadcom Corporation$
11 #include <proto/ethernet.h>
12 #include <proto/vlan.h>
13 #include <proto/802.3.h>
14 #include <proto/bcmip.h>
15 #include <bcmendian.h>
22 /* 802.3 llc/snap header */
23 static const uint8 llc_snap_hdr[SNAP_HDR_LEN] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
25 pkt_frag_t pkt_frag_info(osl_t *osh, void *p)
29 uint8 *pt; /* Pointer to type field */
31 struct ipv4_hdr *iph; /* IP frame pointer */
32 int ipl; /* IP frame length */
37 frame = PKTDATA(osh, p);
38 length = PKTLEN(osh, p);
40 /* Process Ethernet II or SNAP-encapsulated 802.3 frames */
41 if (length < ETHER_HDR_LEN) {
42 DHD_INFO(("%s: short eth frame (%d)\n", __FUNCTION__, length));
43 return DHD_PKT_FRAG_NONE;
44 } else if (ntoh16(*(uint16 *)(frame + ETHER_TYPE_OFFSET)) >= ETHER_TYPE_MIN) {
45 /* Frame is Ethernet II */
46 pt = frame + ETHER_TYPE_OFFSET;
47 } else if (length >= ETHER_HDR_LEN + SNAP_HDR_LEN + ETHER_TYPE_LEN &&
48 !bcmp(llc_snap_hdr, frame + ETHER_HDR_LEN, SNAP_HDR_LEN)) {
49 pt = frame + ETHER_HDR_LEN + SNAP_HDR_LEN;
51 DHD_INFO(("%s: non-SNAP 802.3 frame\n", __FUNCTION__));
52 return DHD_PKT_FRAG_NONE;
55 ethertype = ntoh16(*(uint16 *)pt);
57 /* Skip VLAN tag, if any */
58 if (ethertype == ETHER_TYPE_8021Q) {
61 if (pt + ETHER_TYPE_LEN > frame + length) {
62 DHD_INFO(("%s: short VLAN frame (%d)\n", __FUNCTION__, length));
63 return DHD_PKT_FRAG_NONE;
66 ethertype = ntoh16(*(uint16 *)pt);
69 if (ethertype != ETHER_TYPE_IP) {
70 DHD_INFO(("%s: non-IP frame (ethertype 0x%x, length %d)\n",
71 __FUNCTION__, ethertype, length));
72 return DHD_PKT_FRAG_NONE;
75 iph = (struct ipv4_hdr *)(pt + ETHER_TYPE_LEN);
76 ipl = length - (pt + ETHER_TYPE_LEN - frame);
78 /* We support IPv4 only */
79 if ((ipl < IPV4_OPTIONS_OFFSET) || (IP_VER(iph) != IP_VER_4)) {
80 DHD_INFO(("%s: short frame (%d) or non-IPv4\n", __FUNCTION__, ipl));
81 return DHD_PKT_FRAG_NONE;
84 iph_frag = ntoh16(iph->frag);
86 if (iph_frag & IPV4_FRAG_DONT) {
87 return DHD_PKT_FRAG_NONE;
88 } else if ((iph_frag & IPV4_FRAG_MORE) == 0) {
89 return DHD_PKT_FRAG_LAST;
91 return (iph_frag & IPV4_FRAG_OFFSET_MASK)? DHD_PKT_FRAG_CONT : DHD_PKT_FRAG_FIRST;