dhcp.h
4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
******************************************************************************
* @file dhcp.h
* @version V1.0
* @date 2018-06-18
* @brief dhcp.c的头文件
*
* @company 深圳炜世科技有限公司
* @information WIZnet W5100S官方代理商,全程技术支持,价格优势大!
* @website www.wisioe.com
* @forum www.w5100s.com
* @qqGroup 579842114
******************************************************************************
*/
#ifndef _DHCP_H_
#define _DHCP_H_
#include "stdio.h"
#include "types.h"
#define DEVICE_ID "W5100S"
typedef struct _DHCP_GET
{
uint8 mac[6];
uint8 lip[4];
uint8 sub[4];
uint8 gw[4];
uint8 dns[4];
}DHCP_Get;
extern uint32 dhcp_time;
extern DHCP_Get DHCP_GET;
#define EXTERN_DHCP_MAC DHCP_GET.mac
#define EXTERN_DHCP_SN DHCP_GET.sub
#define EXTERN_DHCP_GW DHCP_GET.gw
#define EXTERN_DHCP_DNS DHCP_GET.dns
#define EXTERN_DHCP_NAME "iweb"//ConfigMsg.domain
#define EXTERN_DHCP_SIP DHCP_GET.lip
#define DHCP_RET_NONE 0
#define DHCP_RET_ERR 1
#define DHCP_RET_TIMEOUT 2
#define DHCP_RET_UPDATE 3
#define DHCP_RET_CONFLICT 4
/* DHCP state machine. */
#define STATE_DHCP_READY 0
#define STATE_DHCP_DISCOVER 1
#define STATE_DHCP_REQUEST 2
#define STATE_DHCP_LEASED 3
#define STATE_DHCP_REREQUEST 4
#define STATE_DHCP_RELEASE 5
#define MAX_DHCP_RETRY 3
#define DHCP_WAIT_TIME 5
#define DHCP_FLAGSBROADCAST 0x8000
/* UDP port numbers for DHCP */
#define DHCP_SERVER_PORT 67 // from server to client
#define DHCP_CLIENT_PORT 68 // from client to server
/* DHCP message OP code */
#define DHCP_BOOTREQUEST 1
#define DHCP_BOOTREPLY 2
/* DHCP message type */
#define DHCP_DISCOVER 1
#define DHCP_OFFER 2
#define DHCP_REQUEST 3
#define DHCP_DECLINE 4
#define DHCP_ACK 5
#define DHCP_NAK 6
#define DHCP_RELEASE 7
#define DHCP_INFORM 8
#define DHCP_HTYPE10MB 1
#define DHCP_HTYPE100MB 2
#define DHCP_HLENETHERNET 6
#define DHCP_HOPS 0
#define DHCP_SECS 0
#define MAGIC_COOKIE 0x63825363
#define DEFAULT_XID 0x12345678
#define DEFAULT_LEASETIME 0xffffffff // infinite lease time
/* DHCP option and value (cf. RFC1533) */
enum
{
padOption = 0,
subnetMask = 1,
timerOffset = 2,
routersOnSubnet = 3,
timeServer = 4,
nameServer = 5,
dns = 6,
logServer = 7,
cookieServer = 8,
lprServer = 9,
impressServer = 10,
resourceLocationServer = 11,
hostName = 12,
bootFileSize = 13,
meritDumpFile = 14,
domainName = 15,
swapServer = 16,
rootPath = 17,
extentionsPath = 18,
IPforwarding = 19,
nonLocalSourceRouting = 20,
policyFilter = 21,
maxDgramReasmSize = 22,
defaultIPTTL = 23,
pathMTUagingTimeout = 24,
pathMTUplateauTable = 25,
ifMTU = 26,
allSubnetsLocal = 27,
broadcastAddr = 28,
performMaskDiscovery = 29,
maskSupplier = 30,
performRouterDiscovery = 31,
routerSolicitationAddr = 32,
staticRoute = 33,
trailerEncapsulation = 34,
arpCacheTimeout = 35,
ethernetEncapsulation = 36,
tcpDefaultTTL = 37,
tcpKeepaliveInterval = 38,
tcpKeepaliveGarbage = 39,
nisDomainName = 40,
nisServers = 41,
ntpServers = 42,
vendorSpecificInfo = 43,
netBIOSnameServer = 44,
netBIOSdgramDistServer = 45,
netBIOSnodeType = 46,
netBIOSscope = 47,
xFontServer = 48,
xDisplayManager = 49,
dhcpRequestedIPaddr = 50,
dhcpIPaddrLeaseTime = 51,
dhcpOptionOverload = 52,
dhcpMessageType = 53,
dhcpServerIdentifier = 54,
dhcpParamRequest = 55,
dhcpMsg = 56,
dhcpMaxMsgSize = 57,
dhcpT1value = 58,
dhcpT2value = 59,
dhcpClassIdentifier = 60,
dhcpClientIdentifier = 61,
endOption = 255
};
typedef struct _RIP_MSG
{
uint8 op;
uint8 htype;
uint8 hlen;
uint8 hops;
uint32 xid;
uint16 secs;
uint16 flags;
uint8 ciaddr[4];
uint8 yiaddr[4];
uint8 siaddr[4];
uint8 giaddr[4];
uint8 chaddr[16];
uint8 sname[64];
uint8 file[128];
uint8 OPT[312];
}RIP_MSG;
#define MAX_DHCP_OPT 16
void init_dhcp_client(void);
void iinchip_init(void);
uint8 check_DHCP_state(SOCKET s);
void do_dhcp(void);
#endif /* _DHCP_H_ */