Fix the device names too long (#1591)
[openwrt.git] / package / broadcom-wl / src / kmod / bcmip.h
1 /*
2 * Copyright 2006, Broadcom Corporation
3 * All Rights Reserved.
4 *
5 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
7 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
9 *
10 * Fundamental constants relating to IP Protocol
11 *
12 * $Id: bcmip.h,v 1.1.1.3 2006/02/27 03:43:16 honor Exp $
13 */
14
15 #ifndef _bcmip_h_
16 #define _bcmip_h_
17
18 /* IPV4 and IPV6 common */
19 #define IP_VER_OFFSET 0x0 /* offset to version field */
20 #define IP_VER_MASK 0xf0 /* version mask */
21 #define IP_VER_SHIFT 4 /* version shift */
22 #define IP_VER_4 4 /* version number for IPV4 */
23 #define IP_VER_6 6 /* version number for IPV6 */
24
25 #define IP_VER(ip_body) \
26 ((((uint8 *)(ip_body))[IP_VER_OFFSET] & IP_VER_MASK) >> IP_VER_SHIFT)
27
28 #define IP_PROT_ICMP 0x1 /* ICMP protocol */
29 #define IP_PROT_TCP 0x6 /* TCP protocol */
30 #define IP_PROT_UDP 0x11 /* UDP protocol type */
31
32 /* IPV4 field offsets */
33 #define IPV4_VER_HL_OFFSET 0 /* version and ihl byte offset */
34 #define IPV4_TOS_OFFSET 1 /* type of service offset */
35 #define IPV4_PROT_OFFSET 9 /* protocol type offset */
36 #define IPV4_CHKSUM_OFFSET 10 /* IP header checksum offset */
37 #define IPV4_SRC_IP_OFFSET 12 /* src IP addr offset */
38 #define IPV4_DEST_IP_OFFSET 16 /* dest IP addr offset */
39
40 /* IPV4 field decodes */
41 #define IPV4_VER_MASK 0xf0 /* IPV4 version mask */
42 #define IPV4_VER_SHIFT 4 /* IPV4 version shift */
43
44 #define IPV4_HLEN_MASK 0x0f /* IPV4 header length mask */
45 #define IPV4_HLEN(ipv4_body) (4 * (((uint8 *)(ipv4_body))[IPV4_VER_HL_OFFSET] & IPV4_HLEN_MASK))
46
47 #define IPV4_ADDR_LEN 4 /* IPV4 address length */
48
49 #define IPV4_ADDR_NULL(a) ((((uint8 *)(a))[0] | ((uint8 *)(a))[1] | \
50 ((uint8 *)(a))[2] | ((uint8 *)(a))[3]) == 0)
51
52 #define IPV4_TOS_DSCP_MASK 0xfc /* DiffServ codepoint mask */
53 #define IPV4_TOS_DSCP_SHIFT 2 /* DiffServ codepoint shift */
54
55 #define IPV4_TOS(ipv4_body) (((uint8 *)(ipv4_body))[IPV4_TOS_OFFSET])
56
57 #define IPV4_TOS_PREC_MASK 0xe0 /* Historical precedence mask */
58 #define IPV4_TOS_PREC_SHIFT 5 /* Historical precedence shift */
59
60 #define IPV4_TOS_LOWDELAY 0x10 /* Lowest delay requested */
61 #define IPV4_TOS_THROUGHPUT 0x8 /* Best throughput requested */
62 #define IPV4_TOS_RELIABILITY 0x4 /* Most reliable delivery requested */
63
64 #define IPV4_PROT(ipv4_body) (((uint8 *)(ipv4_body))[IPV4_PROT_OFFSET])
65
66 #define IPV4_ADDR_STR_LEN 16 /* Max IP address length in string format */
67
68 /* IPV6 field offsets */
69 #define IPV6_PAYLOAD_LEN_OFFSET 4 /* payload length offset */
70 #define IPV6_NEXT_HDR_OFFSET 6 /* next header/protocol offset */
71 #define IPV6_HOP_LIMIT_OFFSET 7 /* hop limit offset */
72 #define IPV6_SRC_IP_OFFSET 8 /* src IP addr offset */
73 #define IPV6_DEST_IP_OFFSET 24 /* dst IP addr offset */
74
75 /* IPV6 field decodes */
76 #define IPV6_TRAFFIC_CLASS(ipv6_body) \
77 (((((uint8 *)(ipv6_body))[0] & 0x0f) << 4) | \
78 ((((uint8 *)(ipv6_body))[1] & 0xf0) >> 4))
79
80 #define IPV6_FLOW_LABEL(ipv6_body) \
81 (((((uint8 *)(ipv6_body))[1] & 0x0f) << 16) | \
82 (((uint8 *)(ipv6_body))[2] << 8) | \
83 (((uint8 *)(ipv6_body))[3]))
84
85 #define IPV6_PAYLOAD_LEN(ipv6_body) \
86 ((((uint8 *)(ipv6_body))[IPV6_PAYLOAD_LEN_OFFSET + 0] << 8) | \
87 ((uint8 *)(ipv6_body))[IPV6_PAYLOAD_LEN_OFFSET + 1])
88
89 #define IPV6_NEXT_HDR(ipv6_body) \
90 (((uint8 *)(ipv6_body))[IPV6_NEXT_HDR_OFFSET])
91
92 #define IPV6_PROT(ipv6_body) IPV6_NEXT_HDR(ipv6_body)
93
94 #define IPV6_ADDR_LEN 16 /* IPV6 address length */
95
96 /* IPV4 TOS or IPV6 Traffic Classifier or 0 */
97 #define IP_TOS(ip_body) \
98 (IP_VER(ip_body) == IP_VER_4 ? IPV4_TOS(ip_body) : \
99 IP_VER(ip_body) == IP_VER_6 ? IPV6_TRAFFIC_CLASS(ip_body) : 0)
100
101 #endif /* _bcmip_h_ */
This page took 0.057911 seconds and 5 git commands to generate.