blob: 072c6bca2edbfc22dd320b155dd1d3c6985d22c0 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
2 * Copyright (c) 2011, 2014 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/* #ifndef _NET_IF_ETHERSUBR_H_ */
29/* #define _NET_IF_ETHERSUBR_H_ */
30#ifndef _NET_IF_UPPERPROTO_H_
31#define _NET_IF_UPPERPROTO_H_
32
33#define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
34#define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */
35#define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */
36#define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
37#define ETHER_MAX_LEN 1518
38
39#define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
40
41/*
42 * Structure of a 10Mb/s Ethernet header.
43 */
44#ifndef _NET_ETHERNET_H_
45struct ether_header {
46 uint8_t ether_dhost[ETHER_ADDR_LEN];
47 uint8_t ether_shost[ETHER_ADDR_LEN];
48 uint16_t ether_type;
49} __packed;
50#endif
51
52#ifndef ETHERTYPE_PAE
53#define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */
54#endif
55#ifndef ETHERTYPE_IP
56#define ETHERTYPE_IP 0x0800 /* IP protocol */
57#endif
58#ifndef ETHERTYPE_AARP
59#define ETHERTYPE_AARP 0x80f3 /* Appletalk AARP protocol */
60#endif
61#ifndef ETHERTYPE_IPX
62#define ETHERTYPE_IPX 0x8137 /* IPX over DIX protocol */
63#endif
64#ifndef ETHERTYPE_ARP
65#define ETHERTYPE_ARP 0x0806 /* ARP protocol */
66#endif
67#ifndef ETHERTYPE_IPV6
68#define ETHERTYPE_IPV6 0x86dd /* IPv6 */
69#endif
70#ifndef ETHERTYPE_8021Q
71#define ETHERTYPE_8021Q 0x8100 /* 802.1Q vlan protocol */
72#endif
73#ifndef ETHERTYPE_VLAN
74#define ETHERTYPE_VLAN 0x8100 /* VLAN TAG protocol */
75#endif
76#ifndef TX_QUEUE_FOR_EAPOL_FRAME
77#define TX_QUEUE_FOR_EAPOL_FRAME 0x7 /* queue eapol frame to queue 7 to avoid aggregation disorder */
78#endif
79
80/*
81 * define WAI ethertype
82 */
83#ifndef ETHERTYPE_WAI
84#define ETHERTYPE_WAI 0x88b4 /* WAI/WAPI */
85#endif
86
87#define ETHERTYPE_OCB_TX 0x8151
88#define ETHERTYPE_OCB_RX 0x8152
89
90/*
91 * Structure of a 48-bit Ethernet address.
92 */
93#if 0
94#ifndef _NET_ETHERNET_H_
95struct ether_addr {
96 uint8_t octet[ETHER_ADDR_LEN];
97} __packed;
98#endif
99#endif
100
101#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
102
103#define VLAN_PRI_SHIFT 13 /* Shift to find VLAN user priority */
104#define VLAN_PRI_MASK 7 /* Mask for user priority bits in VLAN */
105
106/*
107 * Structure of the IP frame
108 */
109struct ip_header {
110 uint8_t version_ihl;
111 uint8_t tos;
112 uint16_t tot_len;
113 uint16_t id;
114 uint16_t frag_off;
115 uint8_t ttl;
116 uint8_t protocol;
117 uint16_t check;
118 uint32_t saddr;
119 uint32_t daddr;
120 /*The options start here. */
121};
122#ifndef IP_PROTO_TCP
123#define IP_PROTO_TCP 0x6 /* TCP protocol */
124#endif
125#ifndef IP_PROTO_UDP
126#define IP_PROTO_UDP 17
127#endif
128
129/*
130 * IGMP protocol structures
131 */
132
133/* IGMP record type */
134#define IGMP_QUERY_TYPE 0x11
135#define IGMPV1_REPORT_TYPE 0x12
136#define IGMPV2_REPORT_TYPE 0x16
137#define IGMPV2_LEAVE_TYPE 0x17
138#define IGMPV3_REPORT_TYPE 0x22
139
140/* Is packet type is either leave or report */
141#define IS_IGMP_REPORT_LEAVE_PACKET(type) ( \
142 (IGMPV1_REPORT_TYPE == type) \
143 || (IGMPV2_REPORT_TYPE == type) \
144 || (IGMPV2_LEAVE_TYPE == type) \
145 || (IGMPV3_REPORT_TYPE == type) \
146 )
147/*
148 * Header in on cable format
149 */
150
151struct igmp_header {
152 uint8_t type;
153 uint8_t code; /* For newer IGMP */
154 uint16_t csum;
155 uint32_t group;
156};
157
158/* V3 group record types [grec_type] */
159#define IGMPV3_MODE_IS_INCLUDE 1
160#define IGMPV3_MODE_IS_EXCLUDE 2
161#define IGMPV3_CHANGE_TO_INCLUDE 3
162#define IGMPV3_CHANGE_TO_EXCLUDE 4
163#define IGMPV3_ALLOW_NEW_SOURCES 5
164#define IGMPV3_BLOCK_OLD_SOURCES 6
165
166/* Group record format
167 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
168 | Record Type | Aux Data Len | Number of Sources (N) |
169 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
170 | Multicast Address |
171 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
172 | Source Address [1] |
173 ||+- -+
174 | Source Address [2] |
175 ||+- -+
176 . . .
177 . . .
178 . . .
179 ||+- -+
180 | Source Address [N] |
181 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
182 | |
183 . .
184 . Auxiliary Data .
185 . .
186 | |
187 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
188 */
189struct igmp_v3_grec {
190 uint8_t grec_type;
191 uint8_t grec_auxwords;
192 uint16_t grec_nsrcs;
193 uint32_t grec_mca;
194};
195
196/* IGMPv3 report format
197 0 1 2 3
198 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
199 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
200 | Type = 0x22 | Reserved | Checksum |
201 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
202 | Reserved | Number of Group Records (M) |
203 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
204 | |
205 . .
206 . Group Record [1] .
207 . .
208 | |
209 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
210 | |
211 . .
212 . Group Record [2] .
213 . .
214 | |
215 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
216 | . |
217 . . .
218 | . |
219 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
220 | |
221 . .
222 . Group Record [M] .
223 . .
224 | |
225 ||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
226 */
227struct igmp_v3_report {
228 uint8_t type;
229 uint8_t resv1;
230 uint16_t csum;
231 uint16_t resv2;
232 uint16_t ngrec;
233};
234
235/* Calculate the group record length*/
236#define IGMPV3_GRP_REC_LEN(x) (8 + (4 * x->grec_nsrcs) + (4 * x->grec_auxwords) )
237
238#endif /* _NET_IF_ETHERSUBR_H_ */