1 |
hedin |
54 |
/*********************************************************************
|
2 |
|
|
*
|
3 |
|
|
* Microchip TCP/IP Stack Definations for PIC18
|
4 |
|
|
*
|
5 |
|
|
*********************************************************************
|
6 |
|
|
* FileName: StackTsk.h
|
7 |
|
|
* Dependencies: compiler.h
|
8 |
|
|
* Processor: PIC18
|
9 |
|
|
* Complier: MCC18 v1.00.50 or higher
|
10 |
|
|
* HITECH PICC-18 V8.10PL1 or higher
|
11 |
|
|
* Company: Microchip Technology, Inc.
|
12 |
|
|
*
|
13 |
|
|
* Software License Agreement
|
14 |
|
|
*
|
15 |
|
|
* The software supplied herewith by Microchip Technology Incorporated
|
16 |
|
|
* (the “Company”) for its PICmicro® Microcontroller is intended and
|
17 |
|
|
* supplied to you, the Company’s customer, for use solely and
|
18 |
|
|
* exclusively on Microchip PICmicro Microcontroller products. The
|
19 |
|
|
* software is owned by the Company and/or its supplier, and is
|
20 |
|
|
* protected under applicable copyright laws. All rights are reserved.
|
21 |
|
|
* Any use in violation of the foregoing restrictions may subject the
|
22 |
|
|
* user to criminal sanctions under applicable laws, as well as to
|
23 |
|
|
* civil liability for the breach of the terms and conditions of this
|
24 |
|
|
* license.
|
25 |
|
|
*
|
26 |
|
|
* THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
|
27 |
|
|
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
|
28 |
|
|
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
29 |
|
|
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
|
30 |
|
|
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
|
31 |
|
|
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
32 |
|
|
*
|
33 |
|
|
* Author Date Comment
|
34 |
|
|
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
35 |
|
|
* Nilesh Rajbharti 8/10/01 Original (Rev 1.0)
|
36 |
|
|
* Nilesh Rajbharti 2/9/02 Cleanup
|
37 |
|
|
* Nilesh Rajbharti 5/22/02 Rev 2.0 (See version.log for detail)
|
38 |
|
|
* Nilesh Rajbharti 8/7/03 Rev 2.21 - TFTP Client addition
|
39 |
|
|
********************************************************************/
|
40 |
|
|
#ifndef STACK_TSK_H
|
41 |
|
|
#define STACK_TSK_H
|
42 |
|
|
|
43 |
|
|
#include "compiler.h"
|
44 |
|
|
|
45 |
|
|
/*
|
46 |
|
|
* This value is used by TCP to implement timeout actions.
|
47 |
|
|
* If SNMP module is in use, this value should be 100 as required
|
48 |
|
|
* by SNMP protocol unless main application is providing separate
|
49 |
|
|
* tick which 10mS.
|
50 |
|
|
*/
|
51 |
|
|
#define TICKS_PER_SECOND (100) // 10ms
|
52 |
|
|
|
53 |
|
|
#if (TICKS_PER_SECOND < 10 || TICKS_PER_SECOND > 255)
|
54 |
|
|
#error Invalid TICKS_PER_SECONDS specified.
|
55 |
|
|
#endif
|
56 |
|
|
|
57 |
|
|
/*
|
58 |
|
|
* Manually select prescale value to achieve necessary tick period
|
59 |
|
|
* for a given clock frequency.
|
60 |
|
|
*/
|
61 |
|
|
#define TICK_PRESCALE_VALUE (256)
|
62 |
|
|
|
63 |
|
|
#if (TICK_PRESCALE_VALUE != 2 && \
|
64 |
|
|
TICK_PRESCALE_VALUE != 4 && \
|
65 |
|
|
TICK_PRESCALE_VALUE != 8 && \
|
66 |
|
|
TICK_PRESCALE_VALUE != 16 && \
|
67 |
|
|
TICK_PRESCALE_VALUE != 32 && \
|
68 |
|
|
TICK_PRESCALE_VALUE != 64 && \
|
69 |
|
|
TICK_PRESCALE_VALUE != 128 && \
|
70 |
|
|
TICK_PRESCALE_VALUE != 256 )
|
71 |
|
|
#error Invalid TICK_PRESCALE_VALUE specified.
|
72 |
|
|
#endif
|
73 |
|
|
|
74 |
|
|
#if defined(WIN32)
|
75 |
|
|
#undef TICKS_PER_SECOND
|
76 |
|
|
#define TICKS_PER_SECOND (1)
|
77 |
|
|
#endif
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
/*
|
82 |
|
|
* This value is for Microchip 24LC256 - 256kb serial EEPROM
|
83 |
|
|
*/
|
84 |
|
|
//#define EEPROM_CONTROL (0xa0)
|
85 |
|
|
|
86 |
|
|
/*
|
87 |
|
|
* Number of bytes to be reserved before MPFS storage is to start.
|
88 |
|
|
*
|
89 |
|
|
* These bytes host application configurations such as IP Address,
|
90 |
|
|
* MAC Address, and any other required variables.
|
91 |
|
|
*
|
92 |
|
|
* After making any change to this variable, MPFS.exe must be
|
93 |
|
|
* executed with correct block size.
|
94 |
|
|
* See MPFS.exe help message by executing MPFS /?
|
95 |
|
|
*/
|
96 |
|
|
#define MPFS_RESERVE_BLOCK (32)
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
/*
|
101 |
|
|
* Comment/Uncomment following lines depending on types of modules
|
102 |
|
|
* are required.
|
103 |
|
|
*/
|
104 |
|
|
#define STACK_USE_ICMP
|
105 |
|
|
//#define STACK_USE_HTTP_SERVER
|
106 |
|
|
|
107 |
|
|
/*
|
108 |
|
|
* For demo purpose only, each sample project defines one or more
|
109 |
|
|
* of following defines in compiler command-line options. (See
|
110 |
|
|
* each MPLAB Project Node Properties under "Project->Edit Project" menu.
|
111 |
|
|
* In real applcation, user may want to define them here.
|
112 |
|
|
*/
|
113 |
|
|
//#define STACK_USE_SLIP
|
114 |
|
|
//#define STACK_USE_IP_GLEANING
|
115 |
|
|
#define STACK_USE_DHCP
|
116 |
|
|
//#define STACK_USE_FTP_SERVER
|
117 |
|
|
//#define STACK_USE_SNMP_SERVER
|
118 |
|
|
//#define STACK_USE_TFTP_CLIENT
|
119 |
|
|
|
120 |
|
|
/*
|
121 |
|
|
* Following low level modules are automatically enabled/disabled based on high-level
|
122 |
|
|
* module selections.
|
123 |
|
|
* If you need them with your custom application, enable it here.
|
124 |
|
|
*/
|
125 |
hedin |
62 |
//#define STACK_USE_TCP
|
126 |
|
|
//#define STACK_USE_UDP
|
127 |
hedin |
54 |
|
128 |
|
|
/*
|
129 |
|
|
* When SLIP is used, DHCP is not supported.
|
130 |
|
|
*/
|
131 |
|
|
#if defined(STACK_USE_SLIP)
|
132 |
|
|
#undef STACK_USE_DHCP
|
133 |
|
|
#endif
|
134 |
|
|
|
135 |
|
|
/*
|
136 |
|
|
* When MPFS_USE_PGRM is used, FTP is not supported.
|
137 |
|
|
*/
|
138 |
|
|
#if defined(MPFS_USE_PGRM)
|
139 |
|
|
#undef STACK_USE_FTP_SERVER
|
140 |
|
|
#endif
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
/*
|
144 |
|
|
* Comment following line if StackTsk should wait for acknowledgement
|
145 |
|
|
* from remote host before transmitting another packet.
|
146 |
|
|
* Commenting following line may reduce throughput.
|
147 |
|
|
*/
|
148 |
|
|
#define TCP_NO_WAIT_FOR_ACK
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
/*
|
152 |
|
|
* Uncomment following line if this stack will be used in CLIENT
|
153 |
|
|
* mode. In CLIENT mode, some functions specific to client operation
|
154 |
|
|
* are enabled.
|
155 |
|
|
*/
|
156 |
|
|
#define STACK_CLIENT_MODE
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
/*
|
160 |
|
|
* If html pages are stored in internal program memory,
|
161 |
|
|
* uncomment MPFS_USE_PRGM and comment MPFS_USE_EEPROM
|
162 |
|
|
* If html pages are stored in external eeprom memory,
|
163 |
|
|
* comment MPFS_USE_PRGM and uncomment MPFS_USE_EEPROM
|
164 |
|
|
*/
|
165 |
|
|
//#define MPFS_USE_PGRM
|
166 |
|
|
#define MPFS_USE_EEPROM
|
167 |
|
|
|
168 |
|
|
#if defined(MPFS_USE_PGRM) && defined(MPFS_USE_EEPROM)
|
169 |
|
|
#error Invalid MPFS Storage option specified.
|
170 |
|
|
#endif
|
171 |
|
|
|
172 |
|
|
#if !defined(MPFS_USE_PGRM) && !defined(MPFS_USE_EEPROM)
|
173 |
|
|
#error You have not specified MPFS storage option.
|
174 |
|
|
#endif
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
/*
|
178 |
|
|
* When HTTP is enabled, TCP must be enabled.
|
179 |
|
|
*/
|
180 |
|
|
#if defined(STACK_USE_HTTP_SERVER)
|
181 |
|
|
#if !defined(STACK_USE_TCP)
|
182 |
|
|
#define STACK_USE_TCP
|
183 |
|
|
#endif
|
184 |
|
|
#endif
|
185 |
|
|
|
186 |
|
|
/*
|
187 |
|
|
* When FTP is enabled, TCP must be enabled.
|
188 |
|
|
*/
|
189 |
|
|
#if defined(STACK_USE_FTP_SERVER)
|
190 |
|
|
#if !defined(STACK_USE_TCP)
|
191 |
|
|
#define STACK_USE_TCP
|
192 |
|
|
#endif
|
193 |
|
|
#endif
|
194 |
|
|
|
195 |
|
|
#if defined(STACK_USE_FTP_SERVER) && !defined(STACK_CLIENT_MODE)
|
196 |
|
|
#define STACK_CLIENT_MODE
|
197 |
|
|
#endif
|
198 |
|
|
|
199 |
|
|
#if defined(STACK_USE_SNMP_SERVER) && !defined(STACK_CLIENT_MODE)
|
200 |
|
|
#define STACK_CLIENT_MODE
|
201 |
|
|
#endif
|
202 |
|
|
|
203 |
|
|
/*
|
204 |
|
|
* When DHCP is enabled, UDP must also be enabled.
|
205 |
|
|
*/
|
206 |
|
|
#if defined(STACK_USE_DHCP)
|
207 |
|
|
#if !defined(STACK_USE_UDP)
|
208 |
|
|
#define STACK_USE_UDP
|
209 |
|
|
#endif
|
210 |
|
|
#endif
|
211 |
|
|
|
212 |
|
|
#if defined(STACK_USE_SNMP_SERVER) && !defined(STACK_USE_UDP)
|
213 |
|
|
#define STACK_USE_UDP
|
214 |
|
|
#endif
|
215 |
|
|
|
216 |
|
|
/*
|
217 |
|
|
* When IP Gleaning is enabled, ICMP must also be enabled.
|
218 |
|
|
*/
|
219 |
|
|
#if defined(STACK_USE_IP_GLEANING)
|
220 |
|
|
#if !defined(STACK_USE_ICMP)
|
221 |
|
|
#define STACK_USE_ICMP
|
222 |
|
|
#endif
|
223 |
|
|
#endif
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
/*
|
227 |
|
|
* When TFTP Client is enabled, UDP must also be enabled.
|
228 |
|
|
* And client mode must also be enabled.
|
229 |
|
|
*/
|
230 |
|
|
#if defined(STACK_USE_TFTP_CLIENT) && !defined(STACK_USE_UDP)
|
231 |
|
|
#define STACK_USE_UDP
|
232 |
|
|
#endif
|
233 |
|
|
|
234 |
|
|
#if defined(STACK_USE_TFTP_CLIENT) && !defined(STACK_CLIENT_MODE)
|
235 |
|
|
#define STACK_CLIENT_MODE
|
236 |
|
|
#endif
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
/*
|
240 |
|
|
* DHCP requires unfragmented packet size of at least 328 bytes,
|
241 |
|
|
* and while in SLIP mode, our maximum packet size is less than
|
242 |
|
|
* 255. Hence disallow DHCP module while SLIP is in use.
|
243 |
|
|
* If required, one can use DHCP while SLIP is in use by modifying
|
244 |
|
|
* C18 linker scipt file such that C18 compiler can allocate
|
245 |
|
|
* a static array larger than 255 bytes.
|
246 |
|
|
* Due to very specific application that would require this,
|
247 |
|
|
* sample stack does not provide such facility. Interested users
|
248 |
|
|
* must do this on their own.
|
249 |
|
|
*/
|
250 |
|
|
#if defined(STACK_USE_SLIP)
|
251 |
|
|
#if defined(STACK_USE_DHCP)
|
252 |
|
|
#error DHCP cannot be used when SLIP is enabled.
|
253 |
|
|
#endif
|
254 |
|
|
#endif
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
/*
|
258 |
|
|
* Modify following macros depending on your interrupt usage
|
259 |
|
|
*/
|
260 |
|
|
#define ENABLE_INTERRUPTS() INTCON_GIEH = 1
|
261 |
|
|
#define DISBALE_INTERRUPTS() INTCON_GIEH = 0
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
/*
|
266 |
|
|
* Default Address information - If not found in data EEPROM.
|
267 |
|
|
*/
|
268 |
|
|
#define MY_DEFAULT_IP_ADDR_BYTE1 (10)
|
269 |
|
|
#define MY_DEFAULT_IP_ADDR_BYTE2 (10)
|
270 |
|
|
#define MY_DEFAULT_IP_ADDR_BYTE3 (5)
|
271 |
|
|
#define MY_DEFAULT_IP_ADDR_BYTE4 (15)
|
272 |
|
|
|
273 |
|
|
#define MY_DEFAULT_MASK_BYTE1 (0xff)
|
274 |
|
|
#define MY_DEFAULT_MASK_BYTE2 (0xff)
|
275 |
|
|
#define MY_DEFAULT_MASK_BYTE3 (0xff)
|
276 |
|
|
#define MY_DEFAULT_MASK_BYTE4 (0x00)
|
277 |
|
|
|
278 |
|
|
#define MY_DEFAULT_GATE_BYTE1 MY_DEFAULT_IP_ADDR_BYTE1
|
279 |
|
|
#define MY_DEFAULT_GATE_BYTE2 MY_DEFAULT_IP_ADDR_BYTE2
|
280 |
|
|
#define MY_DEFAULT_GATE_BYTE3 MY_DEFAULT_IP_ADDR_BYTE3
|
281 |
|
|
#define MY_DEFAULT_GATE_BYTE4 MY_DEFAULT_IP_ADDR_BYTE4
|
282 |
|
|
|
283 |
|
|
#define MY_DEFAULT_MAC_BYTE1 (0x00)
|
284 |
|
|
#define MY_DEFAULT_MAC_BYTE2 (0x04)
|
285 |
|
|
#define MY_DEFAULT_MAC_BYTE3 (0xa3)
|
286 |
|
|
#define MY_DEFAULT_MAC_BYTE4 (0x00)
|
287 |
|
|
#define MY_DEFAULT_MAC_BYTE5 (0x00)
|
288 |
|
|
#define MY_DEFAULT_MAC_BYTE6 (0x00)
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
#define MY_MAC_BYTE1 AppConfig.MyMACAddr.v[0]
|
293 |
|
|
#define MY_MAC_BYTE2 AppConfig.MyMACAddr.v[1]
|
294 |
|
|
#define MY_MAC_BYTE3 AppConfig.MyMACAddr.v[2]
|
295 |
|
|
#define MY_MAC_BYTE4 AppConfig.MyMACAddr.v[3]
|
296 |
|
|
#define MY_MAC_BYTE5 AppConfig.MyMACAddr.v[4]
|
297 |
|
|
#define MY_MAC_BYTE6 AppConfig.MyMACAddr.v[5]
|
298 |
|
|
|
299 |
|
|
/*
|
300 |
|
|
* Subnet mask for this node.
|
301 |
|
|
* Must not be all zero's or else this node will never transmit
|
302 |
|
|
* anything !!
|
303 |
|
|
*/
|
304 |
|
|
#define MY_MASK_BYTE1 AppConfig.MyMask.v[0]
|
305 |
|
|
#define MY_MASK_BYTE2 AppConfig.MyMask.v[1]
|
306 |
|
|
#define MY_MASK_BYTE3 AppConfig.MyMask.v[2]
|
307 |
|
|
#define MY_MASK_BYTE4 AppConfig.MyMask.v[3]
|
308 |
|
|
|
309 |
|
|
/*
|
310 |
|
|
* Hardcoded IP address of this node
|
311 |
|
|
* My IP = 10.10.5.10
|
312 |
|
|
*
|
313 |
|
|
* Gateway = 10.10.5.10
|
314 |
|
|
*/
|
315 |
|
|
#define MY_IP_BYTE1 AppConfig.MyIPAddr.v[0]
|
316 |
|
|
#define MY_IP_BYTE2 AppConfig.MyIPAddr.v[1]
|
317 |
|
|
#define MY_IP_BYTE3 AppConfig.MyIPAddr.v[2]
|
318 |
|
|
#define MY_IP_BYTE4 AppConfig.MyIPAddr.v[3]
|
319 |
|
|
|
320 |
|
|
/*
|
321 |
|
|
* Harcoded Gateway address for this node.
|
322 |
|
|
* This should be changed to match actual network environment.
|
323 |
|
|
*/
|
324 |
|
|
#define MY_GATE_BYTE1 AppConfig.MyGateway.v[0]
|
325 |
|
|
#define MY_GATE_BYTE2 AppConfig.MyGateway.v[1]
|
326 |
|
|
#define MY_GATE_BYTE3 AppConfig.MyGateway.v[2]
|
327 |
|
|
#define MY_GATE_BYTE4 AppConfig.MyGateway.v[3]
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
/*
|
331 |
|
|
* TCP configurations
|
332 |
|
|
* To minmize page update, match number of sockets and
|
333 |
|
|
* HTTP connections with different page sources in a
|
334 |
|
|
* page.
|
335 |
|
|
* For example, if page contains reference to 3 more pages,
|
336 |
|
|
* browser may try to open 4 simultaneous HTTP connections,
|
337 |
|
|
* and to minimize browser delay, set HTTP connections to
|
338 |
|
|
* 4, MAX_SOCKETS to 4.
|
339 |
|
|
* If you are using ICMP or other applications, you should
|
340 |
|
|
* keep at least one socket available for them.
|
341 |
|
|
*/
|
342 |
|
|
|
343 |
|
|
/*
|
344 |
|
|
* Maximum sockets to be defined.
|
345 |
|
|
* Note that each socket consumes 36 bytes of RAM.
|
346 |
|
|
*/
|
347 |
|
|
#define MAX_SOCKETS (4)
|
348 |
|
|
|
349 |
|
|
/*
|
350 |
|
|
* Avaialble UDP Socket
|
351 |
|
|
*/
|
352 |
|
|
#define MAX_UDP_SOCKETS (2)
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
#if (MAX_SOCKETS <= 0 || MAX_SOCKETS > 255)
|
356 |
|
|
#error Invalid MAX_SOCKETS value specified.
|
357 |
|
|
#endif
|
358 |
|
|
|
359 |
|
|
#if (MAX_UDP_SOCKETS <= 0 || MAX_UDP_SOCKETS > 255 )
|
360 |
|
|
#error Invlaid MAX_UDP_SOCKETS value specified
|
361 |
|
|
#endif
|
362 |
|
|
|
363 |
|
|
|
364 |
|
|
#if !defined(STACK_USE_SLIP)
|
365 |
|
|
#define MAC_TX_BUFFER_SIZE (1024)
|
366 |
|
|
#define MAC_TX_BUFFER_COUNT (1)
|
367 |
|
|
#else
|
368 |
|
|
/*
|
369 |
|
|
* For SLIP, there can only be one transmit and one receive buffer.
|
370 |
|
|
* Both buffer must fit in one bank. If bigger buffer is required,
|
371 |
|
|
* you must manually locate tx and rx buffer in different bank
|
372 |
|
|
* or modify your linker script file to support arrays bigger than
|
373 |
|
|
* 256 bytes.
|
374 |
|
|
*/
|
375 |
|
|
#define MAC_TX_BUFFER_SIZE (250)
|
376 |
|
|
#define MAC_TX_BUFFER_COUNT (1)
|
377 |
|
|
#endif
|
378 |
|
|
// Rests are Receive Buffers
|
379 |
|
|
|
380 |
|
|
#define MAC_RX_BUFFER_SIZE (MAC_TX_BUFFER_SIZE)
|
381 |
|
|
|
382 |
|
|
#if (MAC_TX_BUFFER_SIZE <= 0 || MAC_TX_BUFFER_SIZE > 1500 )
|
383 |
|
|
#error Invalid MAC_TX_BUFFER_SIZE value specified.
|
384 |
|
|
#endif
|
385 |
|
|
|
386 |
|
|
#if ( (MAC_TX_BUFFER_SIZE * MAC_TX_BUFFER_COUNT) > (4* 1024) )
|
387 |
|
|
#error Not enough room for Receive buffer.
|
388 |
|
|
#endif
|
389 |
|
|
|
390 |
|
|
/*
|
391 |
|
|
* Maximum numbers of simultaneous HTTP connections allowed.
|
392 |
|
|
* Each connection consumes 10 bytes.
|
393 |
|
|
*/
|
394 |
|
|
#define MAX_HTTP_CONNECTIONS (2)
|
395 |
|
|
|
396 |
|
|
#if (MAX_HTTP_CONNECTIONS <= 0 || MAX_HTTP_CONNECTIONS > 255 )
|
397 |
|
|
#error Invalid MAX_HTTP_CONNECTIONS value specified.
|
398 |
|
|
#endif
|
399 |
|
|
|
400 |
|
|
#define AVAILABLE_SOCKETS (MAX_SOCKETS)
|
401 |
|
|
#if defined(STACK_USE_HTTP_SERVER)
|
402 |
|
|
#define AVAILABLE_SOCKETS2 (AVAILABLE_SOCKETS - MAX_HTTP_CONNECTIONS)
|
403 |
|
|
#else
|
404 |
|
|
#define AVAILABLE_SOCKETS2 (MAX_SOCKETS)
|
405 |
|
|
#endif
|
406 |
|
|
|
407 |
|
|
/*
|
408 |
|
|
* When using FTP, you must have at least two sockets free
|
409 |
|
|
*/
|
410 |
|
|
#if defined(STACK_USE_FTP_SERVER)
|
411 |
|
|
#define AVAILABLE_SOCKETS3 (AVAILABLE_SOCKETS2 - 2)
|
412 |
|
|
#else
|
413 |
|
|
#define AVAILABLE_SOCKETS3 (AVAILABLE_SOCKETS2)
|
414 |
|
|
#endif
|
415 |
|
|
|
416 |
|
|
#if AVAILABLE_SOCKETS3 < 0
|
417 |
|
|
#error Maximum TCP Socket count is not enough.
|
418 |
|
|
#error Either increase MAX_SOCKETS or decrease module socket usage.
|
419 |
|
|
#endif
|
420 |
|
|
|
421 |
|
|
|
422 |
|
|
#define AVAILABLE_UDP_SOCKETS (MAX_UDP_SOCKETS)
|
423 |
|
|
#if defined(STACK_USE_DHCP)
|
424 |
|
|
#define AVAILABLE_UDP_SOCKETS2 (AVAILABLE_UDP_SOCKETS - 1)
|
425 |
|
|
#else
|
426 |
|
|
#define AVAILABLE_UDP_SOCKETS2 AVAILABLE_UDP_SOCKETS
|
427 |
|
|
#endif
|
428 |
|
|
|
429 |
|
|
#if defined(STACK_USE_SNMP_SERVER)
|
430 |
|
|
#define AVAILABLE_UDP_SOCKETS3 (AVAILABLE_UDP_SOCKETS2 - 1)
|
431 |
|
|
#else
|
432 |
|
|
#define AVAILABLE_UDP_SOCKETS3 AVAILABLE_UDP_SOCKETS2
|
433 |
|
|
#endif
|
434 |
|
|
|
435 |
|
|
#if defined(STACK_USE_TFTP_CLIENT)
|
436 |
|
|
#define AVAILABLE_UDP_SOCKETS4 (AVAILABLE_UDP_SOCKETS2)
|
437 |
|
|
#else
|
438 |
|
|
#define AVAILABLE_UDP_SOCKETS4 AVAILABLE_UDP_SOCKETS3
|
439 |
|
|
#endif
|
440 |
|
|
|
441 |
|
|
|
442 |
|
|
#if AVAILABLE_UDP_SOCKETS4 < 0
|
443 |
|
|
#error Maximum UDP Socket count is not enough.
|
444 |
|
|
#error Either increase MAX_UDP_SOCKETS or decrease module UDP socket usage.
|
445 |
|
|
#endif
|
446 |
|
|
|
447 |
|
|
|
448 |
|
|
|
449 |
|
|
#undef BOOL
|
450 |
|
|
#undef TRUE
|
451 |
|
|
#undef FALSE
|
452 |
|
|
#undef BYTE
|
453 |
|
|
#undef WORD
|
454 |
|
|
#undef DWORD
|
455 |
|
|
|
456 |
|
|
typedef enum _BOOL { FALSE = 0, TRUE } BOOL;
|
457 |
|
|
typedef unsigned char BYTE; // 8-bit
|
458 |
|
|
typedef unsigned short int WORD; // 16-bit
|
459 |
|
|
#ifndef _WIN32
|
460 |
|
|
typedef unsigned short long SWORD; // 24-bit
|
461 |
|
|
#else
|
462 |
|
|
typedef short int SWORD;
|
463 |
|
|
#endif
|
464 |
|
|
typedef unsigned long DWORD; // 32-bit
|
465 |
|
|
|
466 |
|
|
typedef union _BYTE_VAL
|
467 |
|
|
{
|
468 |
|
|
struct
|
469 |
|
|
{
|
470 |
|
|
unsigned int b0:1;
|
471 |
|
|
unsigned int b1:1;
|
472 |
|
|
unsigned int b2:1;
|
473 |
|
|
unsigned int b3:1;
|
474 |
|
|
unsigned int b4:1;
|
475 |
|
|
unsigned int b5:1;
|
476 |
|
|
unsigned int b6:1;
|
477 |
|
|
unsigned int b7:1;
|
478 |
|
|
} bits;
|
479 |
|
|
BYTE Val;
|
480 |
|
|
} BYTE_VAL;
|
481 |
|
|
|
482 |
|
|
typedef union _SWORD_VAL
|
483 |
|
|
{
|
484 |
|
|
SWORD Val;
|
485 |
|
|
struct
|
486 |
|
|
{
|
487 |
|
|
BYTE LSB;
|
488 |
|
|
BYTE MSB;
|
489 |
|
|
BYTE USB;
|
490 |
|
|
} byte;
|
491 |
|
|
} SWORD_VAL;
|
492 |
|
|
|
493 |
|
|
|
494 |
|
|
typedef union _WORD_VAL
|
495 |
|
|
{
|
496 |
|
|
WORD Val;
|
497 |
|
|
struct
|
498 |
|
|
{
|
499 |
|
|
BYTE LSB;
|
500 |
|
|
BYTE MSB;
|
501 |
|
|
} byte;
|
502 |
|
|
BYTE v[2];
|
503 |
|
|
} WORD_VAL;
|
504 |
|
|
|
505 |
|
|
#define LSB(a) ((a).v[0])
|
506 |
|
|
#define MSB(a) ((a).v[1])
|
507 |
|
|
|
508 |
|
|
typedef union _DWORD_VAL
|
509 |
|
|
{
|
510 |
|
|
DWORD Val;
|
511 |
|
|
struct
|
512 |
|
|
{
|
513 |
|
|
BYTE LOLSB;
|
514 |
|
|
BYTE LOMSB;
|
515 |
|
|
BYTE HILSB;
|
516 |
|
|
BYTE HIMSB;
|
517 |
|
|
} byte;
|
518 |
|
|
struct
|
519 |
|
|
{
|
520 |
|
|
WORD LSW;
|
521 |
|
|
WORD MSW;
|
522 |
|
|
} word;
|
523 |
|
|
BYTE v[4];
|
524 |
|
|
} DWORD_VAL;
|
525 |
|
|
#define LOWER_LSB(a) ((a).v[0])
|
526 |
|
|
#define LOWER_MSB(a) ((a).v[1])
|
527 |
|
|
#define UPPER_LSB(a) ((a).v[2])
|
528 |
|
|
#define UPPER_MSB(a) ((a).v[3])
|
529 |
|
|
|
530 |
|
|
typedef BYTE BUFFER;
|
531 |
|
|
|
532 |
|
|
typedef struct _MAC_ADDR
|
533 |
|
|
{
|
534 |
|
|
BYTE v[6];
|
535 |
|
|
} MAC_ADDR;
|
536 |
|
|
|
537 |
|
|
typedef union _IP_ADDR
|
538 |
|
|
{
|
539 |
|
|
BYTE v[4];
|
540 |
|
|
DWORD Val;
|
541 |
|
|
} IP_ADDR;
|
542 |
|
|
|
543 |
|
|
|
544 |
|
|
typedef struct _NODE_INFO
|
545 |
|
|
{
|
546 |
|
|
MAC_ADDR MACAddr;
|
547 |
|
|
IP_ADDR IPAddr;
|
548 |
|
|
} NODE_INFO;
|
549 |
|
|
|
550 |
|
|
typedef struct _APP_CONFIG
|
551 |
|
|
{
|
552 |
|
|
IP_ADDR MyIPAddr;
|
553 |
|
|
MAC_ADDR MyMACAddr;
|
554 |
|
|
IP_ADDR MyMask;
|
555 |
|
|
IP_ADDR MyGateway;
|
556 |
|
|
WORD_VAL SerialNumber;
|
557 |
|
|
IP_ADDR SMTPServerAddr; // Not used.
|
558 |
|
|
struct
|
559 |
|
|
{
|
560 |
|
|
unsigned int bIsDHCPEnabled : 1;
|
561 |
|
|
} Flags;
|
562 |
|
|
IP_ADDR TFTPServerAddr;
|
563 |
|
|
} APP_CONFIG;
|
564 |
|
|
|
565 |
|
|
|
566 |
|
|
typedef union _STACK_FLAGS
|
567 |
|
|
{
|
568 |
|
|
struct
|
569 |
|
|
{
|
570 |
|
|
unsigned int bInConfigMode : 1;
|
571 |
|
|
} bits;
|
572 |
|
|
BYTE Val;
|
573 |
|
|
} STACK_FLAGS;
|
574 |
|
|
|
575 |
|
|
|
576 |
|
|
#ifndef THIS_IS_STACK_APPLICATION
|
577 |
|
|
extern APP_CONFIG AppConfig;
|
578 |
|
|
#endif
|
579 |
|
|
|
580 |
|
|
#if defined(STACK_USE_IP_GLEANING) || defined(STACK_USE_DHCP)
|
581 |
|
|
#ifndef STACK_INCLUDE
|
582 |
|
|
extern STACK_FLAGS stackFlags;
|
583 |
|
|
#endif
|
584 |
|
|
#endif
|
585 |
|
|
|
586 |
|
|
#if defined(STACK_USE_IP_GLEANING) || defined(STACK_USE_DHCP)
|
587 |
|
|
#define StackIsInConfigMode() (stackFlags.bits.bInConfigMode)
|
588 |
|
|
#else
|
589 |
|
|
#define StackIsInConfigMode() (FALSE)
|
590 |
|
|
#endif
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
/*********************************************************************
|
594 |
|
|
* Function: void StackInit(void)
|
595 |
|
|
*
|
596 |
|
|
* PreCondition: None
|
597 |
|
|
*
|
598 |
|
|
* Input: None
|
599 |
|
|
*
|
600 |
|
|
* Output: Stack and its componentns are initialized
|
601 |
|
|
*
|
602 |
|
|
* Side Effects: None
|
603 |
|
|
*
|
604 |
|
|
* Note: This function must be called before any of the
|
605 |
|
|
* stack or its component routines be used.
|
606 |
|
|
*
|
607 |
|
|
********************************************************************/
|
608 |
|
|
void StackInit(void);
|
609 |
|
|
|
610 |
|
|
|
611 |
|
|
/*********************************************************************
|
612 |
|
|
* Function: void StackTask(void)
|
613 |
|
|
*
|
614 |
|
|
* PreCondition: StackInit() is already called.
|
615 |
|
|
*
|
616 |
|
|
* Input: None
|
617 |
|
|
*
|
618 |
|
|
* Output: Stack FSM is executed.
|
619 |
|
|
*
|
620 |
|
|
* Side Effects: None
|
621 |
|
|
*
|
622 |
|
|
* Note: This FSM checks for new incoming packets,
|
623 |
|
|
* and routes it to appropriate stack components.
|
624 |
|
|
* It also performs timed operations.
|
625 |
|
|
*
|
626 |
|
|
* This function must be called periodically called
|
627 |
|
|
* to make sure that timely response.
|
628 |
|
|
*
|
629 |
|
|
********************************************************************/
|
630 |
|
|
void StackTask(void);
|
631 |
|
|
|
632 |
|
|
|
633 |
|
|
#endif
|