xref: /wlan-driver/fw-api/fw/enet.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2012-2014, 2017, 2021 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 _ENET__H_
29 #define _ENET__H_
30 
31 #if defined(ATH_TARGET)
32 #include <osapi.h>   /* A_UINT8 */
33 #else
34 #include <a_types.h> /* A_UINT8 */
35 #endif
36 
37 
38 #define ETHERNET_ADDR_LEN 6 /* bytes */
39 #define ETHERNET_TYPE_LEN 2 /* bytes - length of the Ethernet type field */
40 
41 struct ethernet_hdr_t {
42     A_UINT8 dest_addr[ETHERNET_ADDR_LEN];
43     A_UINT8 src_addr[ETHERNET_ADDR_LEN];
44     A_UINT8 ethertype[ETHERNET_TYPE_LEN];
45 };
46 
47 #define ETHERNET_HDR_LEN (sizeof(struct ethernet_hdr_t))
48 
49 #define ETHERNET_CRC_LEN  4     /* bytes - length of the Ethernet CRC */
50 #define ETHERNET_MAX_LEN  1518  /* bytes */
51 
52 #define ETHERNET_MTU (ETHERNET_MAX_LEN - (ETHERNET_HDR_LEN + ETHERNET_CRC_LEN))
53 
54 
55 typedef struct llc_snap_hdr_t {
56     A_UINT8 dsap;
57     A_UINT8 ssap;
58     A_UINT8 cntl;
59     A_UINT8 org_code[3];
60     A_UINT8 ethertype[2];
61 } LLC_SNAP_HDR;
62 
63 #define LLC_SNAP_HDR_LEN (sizeof(struct llc_snap_hdr_t))
64 #define LLC_SNAP_HDR_OFFSET_ETHERTYPE \
65     (offsetof(struct llc_snap_hdr_t, ethertype[0]))
66 
67 #define ETHERTYPE_VLAN_LEN  4
68 
69 struct ethernet_vlan_hdr_t {
70     A_UINT8 dest_addr[ETHERNET_ADDR_LEN];
71     A_UINT8 src_addr[ETHERNET_ADDR_LEN];
72     A_UINT8 vlan_tpid[2];
73     A_UINT8 vlan_tci[2];
74     A_UINT8 ethertype[2];
75 };
76 
77 typedef PREPACK struct _wai_hdr {
78     A_UINT8 version[2];
79     A_UINT8 type;
80     A_UINT8 stype;
81     A_UINT8 reserve[2];
82     A_UINT8 length[2];
83     A_UINT8 rxseq[2];
84     A_UINT8 frag_sc;
85     A_UINT8 more_frag;
86     /* followed octets of data */
87 } POSTPACK wai_hdr;
88 
89 typedef PREPACK struct {
90     A_UINT16 vlan_tci;
91     A_UINT16 vlan_encap_p;
92 } POSTPACK vlan_hdr_t;
93 
94 #define ETHERTYPE_IS_EAPOL_WAPI(typeorlen)           \
95 			((typeorlen) == ETHERTYPE_PAE ||  \
96 			(typeorlen) == ETHERTYPE_WAI)
97 
98 #define IS_ETHERTYPE(_typeOrLen) ((_typeOrLen) >= 0x0600)
99 
100 #ifndef ETHERTYPE_IPV4
101 #define ETHERTYPE_IPV4  0x0800 /* Internet Protocol, Version 4 (IPv4) */
102 #endif
103 
104 #ifndef ETHERTYPE_AARP
105 #define	ETHERTYPE_AARP	0x80f3		/* Internal QCA AARP protocol */
106 #endif
107 
108 #ifndef ETHERTYPE_IPX
109 #define ETHERTYPE_IPX    0x8137    /* IPX over DIX protocol */
110 #endif
111 
112 #ifndef ETHERTYPE_ARP
113 #define ETHERTYPE_ARP   0x0806 /* Address Resolution Protocol (ARP) */
114 #endif
115 
116 #ifndef ETHERTYPE_RARP
117 #define ETHERTYPE_RARP  0x8035 /* Reverse Address Resolution Protocol (RARP) */
118 #endif
119 
120 #ifndef ETHERTYPE_VLAN
121 #define ETHERTYPE_VLAN  0x8100 /* VLAN TAG protocol */
122 #endif
123 
124 #ifndef ETHERTYPE_SNMP
125 #define ETHERTYPE_SNMP  0x814C /* Simple Network Management Protocol (SNMP) */
126 #endif
127 
128 #ifndef ETHERTYPE_IPV6
129 #define ETHERTYPE_IPV6  0x86DD /* Internet Protocol, Version 6 (IPv6) */
130 #endif
131 
132 #ifndef ETHERTYPE_PAE
133 #define ETHERTYPE_PAE   0x888E /* EAP over LAN (EAPOL) */
134 #endif
135 
136 #ifndef ETHERTYPE_WAI
137 #define ETHERTYPE_WAI   0x88B4 /* WAPI */
138 #endif
139 
140 #ifndef ETHERTYPE_TDLS
141 #define ETHERTYPE_TDLS  0x890D /* TDLS */
142 #endif
143 
144 #define LLC_SNAP_LSAP 0xaa
145 #define LLC_UI 0x3
146 
147 #define RFC1042_SNAP_ORGCODE_0 0x00
148 #define RFC1042_SNAP_ORGCODE_1 0x00
149 #define RFC1042_SNAP_ORGCODE_2 0x00
150 
151 #define BTEP_SNAP_ORGCODE_0 0x00
152 #define BTEP_SNAP_ORGCODE_1 0x00
153 #define BTEP_SNAP_ORGCODE_2 0xf8
154 
155 
156 #define WAI_FRAME_TYPE 0X01
157 #define WAPI_M4_TYPE 0x0c
158 #define WAPI_M2_TYPE 0x09
159 
160 
161 #define ICMP_PROTOCOL   1
162 #define TCP_PROTOCOL    6
163 #define UDP_PROTOCOL    17
164 #define IGMP_PROTOCOL   2
165 #define ICMPV6_PROTOCOL 58
166 #define BOOTP_SERVER_PORT 67
167 #define BOOTP_CLIENT_PORT 68
168 #define MLD_QUERY 130
169 #define MLD_DONE  132
170 
171 
172 #define IS_EAPOL(typeorlen) \
173     ((typeorlen) == ETHERTYPE_PAE || \
174      (typeorlen) == ETHERTYPE_WAI)
175 
176 #define IS_SNAP(_llc) \
177     ((_llc)->dsap == LLC_SNAP_LSAP && \
178      (_llc)->ssap == LLC_SNAP_LSAP && \
179      (_llc)->cntl == LLC_UI)
180 
181 #define IS_RFC1042(_llc) \
182     ((_llc)->org_code[0] == RFC1042_SNAP_ORGCODE_0 && \
183      (_llc)->org_code[1] == RFC1042_SNAP_ORGCODE_1 && \
184      (_llc)->org_code[2] == RFC1042_SNAP_ORGCODE_2)
185 
186 #define IS_BTEP(_llc) \
187     ((_llc)->org_code[0] == BTEP_SNAP_ORGCODE_0 && \
188      (_llc)->org_code[1] == BTEP_SNAP_ORGCODE_1 && \
189      (_llc)->org_code[2] == BTEP_SNAP_ORGCODE_2)
190 
191 #define IS_MULTICAST(_hdr) (*(A_UINT8 *)(_hdr) & 0x1)
192 #define IS_BROADCAST(_hdr) \
193     ((*((A_UINT8 *)(_hdr) + 0) == 0xff) && \
194      (*((A_UINT8 *)(_hdr) + 1) == 0xff) && \
195      (*((A_UINT8 *)(_hdr) + 2) == 0xff) && \
196      (*((A_UINT8 *)(_hdr) + 3) == 0xff) && \
197      (*((A_UINT8 *)(_hdr) + 4) == 0xff) && \
198      (*((A_UINT8 *)(_hdr) + 5) == 0xff))
199 
200 
201 #endif /* _ENET__H_ */
202