1 /*********************************************
2 * vim:sw=8:ts=8:si:et
3 * To use the above modeline in vim you must have "set modeline" in your .vimrc
4 * Author: Guido Socher
5 * Copyright: GPL V2
6 *
7 * Based on the net.h file from the AVRlib library by Pascal Stang.
8 * For AVRlib See http://www.procyonengineering.com/
9 * Used with explicit permission of Pascal Stang.
10 *
11 * Chip type : ATMEGA88 with ENC28J60
12 *********************************************/
13 /*********************************************
14 * Modified: nuelectronics.com -- Ethershield for Arduino
15 *********************************************/
16
17 // notation: _P = position of a field
18 // _V = value of a field
19
20 //@{
21
22 #ifndef NET_H
23 #define NET_H
24
25 // ******* ETH *******
26 #define ETH_HEADER_LEN 14
27 // values of certain bytes:
28 #define ETHTYPE_ARP_H_V 0x08
29 #define ETHTYPE_ARP_L_V 0x06
30 #define ETHTYPE_IP_H_V 0x08
31 #define ETHTYPE_IP_L_V 0x00
32 // byte positions in the ethernet frame:
33 //
34 // Ethernet type field (2bytes):
35 #define ETH_TYPE_H_P 12
36 #define ETH_TYPE_L_P 13
37 //
38 #define ETH_DST_MAC 0
39 #define ETH_SRC_MAC 6
40
41
42 // ******* ARP *******
43 #define ETH_ARP_OPCODE_REPLY_H_V 0x0
44 #define ETH_ARP_OPCODE_REPLY_L_V 0x02
45 //
46 #define ETHTYPE_ARP_L_V 0x06
47 // arp.dst.ip
48 #define ETH_ARP_DST_IP_P 0x26
49 // arp.opcode
50 #define ETH_ARP_OPCODE_H_P 0x14
51 #define ETH_ARP_OPCODE_L_P 0x15
52 // arp.src.mac
53 #define ETH_ARP_SRC_MAC_P 0x16
54 #define ETH_ARP_SRC_IP_P 0x1c
55 #define ETH_ARP_DST_MAC_P 0x20
56 #define ETH_ARP_DST_IP_P 0x26
57
58 // ******* IP *******
59 #define IP_HEADER_LEN 20
60 // ip.src
61 #define IP_SRC_P 0x1a
62 #define IP_DST_P 0x1e
63 #define IP_HEADER_LEN_VER_P 0xe
64 #define IP_CHECKSUM_P 0x18
65 #define IP_TTL_P 0x16
66 #define IP_FLAGS_P 0x14
67 #define IP_P 0xe
68 #define IP_TOTLEN_H_P 0x10
69 #define IP_TOTLEN_L_P 0x11
70
71 #define IP_PROTO_P 0x17
72
73 #define IP_PROTO_ICMP_V 1
74 #define IP_PROTO_TCP_V 6
75 // 17=0x11
76 #define IP_PROTO_UDP_V 17
77 // ******* ICMP *******
78 #define ICMP_TYPE_ECHOREPLY_V 0
79 #define ICMP_TYPE_ECHOREQUEST_V 8
80 //
81 #define ICMP_TYPE_P 0x22
82 #define ICMP_CHECKSUM_P 0x24
83
84 // ******* UDP *******
85 #define UDP_HEADER_LEN 8
86 //
87 #define UDP_SRC_PORT_H_P 0x22
88 #define UDP_SRC_PORT_L_P 0x23
89 #define UDP_DST_PORT_H_P 0x24
90 #define UDP_DST_PORT_L_P 0x25
91 //
92 #define UDP_LEN_H_P 0x26
93 #define UDP_LEN_L_P 0x27
94 #define UDP_CHECKSUM_H_P 0x28
95 #define UDP_CHECKSUM_L_P 0x29
96 #define UDP_DATA_P 0x2a
97
98 // ******* TCP *******
99 #define TCP_SRC_PORT_H_P 0x22
100 #define TCP_SRC_PORT_L_P 0x23
101 #define TCP_DST_PORT_H_P 0x24
102 #define TCP_DST_PORT_L_P 0x25
103 // the tcp seq number is 4 bytes 0x26-0x29
104 #define TCP_SEQ_H_P 0x26
105 #define TCP_SEQACK_H_P 0x2a
106 // flags: SYN=2
107 #define TCP_FLAGS_P 0x2f
108 #define TCP_FLAGS_SYN_V 2
109 #define TCP_FLAGS_FIN_V 1
110 #define TCP_FLAGS_PUSH_V 8
111 #define TCP_FLAGS_SYNACK_V 0x12
112 #define TCP_FLAGS_ACK_V 0x10
113 #define TCP_FLAGS_PSHACK_V 0x18
114 // plain len without the options:
115 #define TCP_HEADER_LEN_PLAIN 20
116 #define TCP_HEADER_LEN_P 0x2e
117 #define TCP_CHECKSUM_H_P 0x32
118 #define TCP_CHECKSUM_L_P 0x33
119 #define TCP_OPTIONS_P 0x36
120 //
121 #endif
122 //@}
123
Kner
2011