Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
363 johboh 1
/*********************************************************************
2
 *
3
 *                  TCP Module Defs for Microchip TCP/IP Stack
4
 *
5
 *********************************************************************
6
 * FileName:        TCP.h
7
 * Dependencies:    StackTsk.h
8
 * Processor:       PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
9
 * Complier:        Microchip C18 v3.02 or higher
10
 *                  Microchip C30 v2.01 or higher
11
 * Company:         Microchip Technology, Inc.
12
 *
13
 * Software License Agreement
14
 *
15
 * This software is owned by Microchip Technology Inc. ("Microchip")
16
 * and is supplied to you for use exclusively as described in the
17
 * associated software agreement.  This software is protected by
18
 * software and other intellectual property laws.  Any use in
19
 * violation of the software license may subject the user to criminal
20
 * sanctions as well as civil liability.  Copyright 2006 Microchip
21
 * Technology Inc.  All rights reserved.
22
 *
23
 * This software is provided "AS IS."  MICROCHIP DISCLAIMS ALL
24
 * WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED
25
 * TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
26
 * INFRINGEMENT.  Microchip shall in no event be liable for special,
27
 * incidental, or consequential damages.
28
 *
29
 *
30
 * Author               Date    Comment
31
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
 * Nilesh Rajbharti     5/8/01  Original        (Rev 1.0)
33
 * Nilesh Rajbharti     5/22/02 Rev 2.0 (See version.log for detail)
34
 * Nilesh Rajbharti     12/5/03 Modified TCPProcess() prototype.
35
 *                              See TCP.c for more information.
36
 ********************************************************************/
37
 
38
#ifndef TCP_H
39
#define TCP_H
40
 
41
#include "..\Include\StackTsk.h"
42
#include "..\Include\Tick.h"
43
 
44
typedef BYTE TCP_SOCKET;
45
typedef WORD TCP_PORT;
46
 
47
 
48
/*
49
 * Maximum number of times a connection be retried before
50
 * closing it down.
51
 */
52
#define MAX_RETRY_COUNTS    (3)
53
 
54
#define INVALID_SOCKET      (0xfe)
55
#define UNKNOWN_SOCKET      (0xff)
56
 
57
#define REMOTE_HOST(s)      (TCB[s].remote)
58
 
59
/*
60
 * TCP States as defined by rfc793
61
 */
62
typedef enum _TCP_STATE
63
{
64
    TCP_LISTEN = 0,
65
    TCP_SYN_SENT,
66
    TCP_SYN_RECEIVED,
67
    TCP_ESTABLISHED,
68
    TCP_FIN_WAIT_1,
69
    TCP_FIN_WAIT_2,
70
    TCP_CLOSING,
71
    TCP_TIME_WAIT,
72
    TCP_CLOSE_WAIT,
73
    TCP_LAST_ACK,
74
    TCP_CLOSED,
75
} TCP_STATE;
76
 
77
/*
78
 * Socket info.
79
 * Union is used to create anonymous structure members.
80
 */
81
typedef struct _SOCKET_INFO
82
{
83
    TCP_STATE smState;
84
 
85
    NODE_INFO remote;
86
    TCP_PORT localPort;
87
    TCP_PORT remotePort;
88
 
89
    BUFFER TxBuffer;
90
    WORD TxCount;
91
    WORD RxCount;
92
    WORD RemoteWindow;
93
 
94
    DWORD SND_SEQ;
95
    DWORD SND_ACK;
96
 
97
    BYTE RetryCount;
98
    TICK startTick;
99
    TICK TimeOut;
100
 
101
    struct
102
    {
103
        unsigned char bServer        : 1;
104
        unsigned char bIsPutReady    : 1;
105
        unsigned char bFirstRead     : 1;
106
        unsigned char bIsGetReady    : 1;
107
        unsigned char bIsTxInProgress : 1;
108
        unsigned char bACKValid : 1;
109
    } Flags;
110
 
111
} SOCKET_INFO;
112
 
113
 
114
#if !defined(THIS_IS_TCP)
115
/*
116
 * These are all sockets supported by this TCP.
117
 */
118
extern SOCKET_INFO TCB[MAX_SOCKETS];
119
#endif
120
 
121
 
122
 
123
/*********************************************************************
124
 * Function:        void TCPInit(void)
125
 *
126
 * PreCondition:    None
127
 *
128
 * Input:           None
129
 *
130
 * Output:          TCP is initialized.
131
 *
132
 * Side Effects:    None
133
 *
134
 * Overview:        Initialize all socket info.
135
 *
136
 * Note:            This function is called only one during lifetime
137
 *                  of the application.
138
 ********************************************************************/
139
void        TCPInit(void);
140
 
141
 
142
 
143
/*********************************************************************
144
 * Function:        TCP_SOCKET TCPListen(TCP_PORT port)
145
 *
146
 * PreCondition:    TCPInit() is already called.
147
 *
148
 * Input:           port    - A TCP port to be opened.
149
 *
150
 * Output:          Given port is opened and returned on success
151
 *                  INVALID_SOCKET if no more sockets left.
152
 *
153
 * Side Effects:    None
154
 *
155
 * Overview:        None
156
 *
157
 * Note:            None
158
 ********************************************************************/
159
TCP_SOCKET  TCPListen(TCP_PORT port);
160
 
161
 
162
 
163
/*********************************************************************
164
 * Function:        TCP_SOCKET TCPConnect(NODE_INFO* remote,
165
 *                                      TCP_PORT remotePort)
166
 *
167
 * PreCondition:    TCPInit() is already called.
168
 *
169
 * Input:           remote      - Remote node address info
170
 *                  remotePort  - remote port to be connected.
171
 *
172
 * Output:          A new socket is created, connection request is
173
 *                  sent and socket handle is returned.
174
 *
175
 * Side Effects:    None
176
 *
177
 * Overview:        None
178
 *
179
 * Note:            By default this function is not included in
180
 *                  source.  You must define STACK_CLIENT_MODE to
181
 *                  be able to use this function.
182
 ********************************************************************/
183
TCP_SOCKET  TCPConnect(NODE_INFO *remote, TCP_PORT port);
184
 
185
 
186
/*********************************************************************
187
 * Function:        BOOL TCPIsConnected(TCP_SOCKET s)
188
 *
189
 * PreCondition:    TCPInit() is already called.
190
 *
191
 * Input:           s       - Socket to be checked for connection.
192
 *
193
 * Output:          TRUE    if given socket is connected
194
 *                  FALSE   if given socket is not connected.
195
 *
196
 * Side Effects:    None
197
 *
198
 * Overview:        None
199
 *
200
 * Note:            A socket is said to be connected if it is not
201
 *                  in LISTEN and CLOSED mode.  Socket may be in
202
 *                  SYN_RCVD or FIN_WAIT_1 and may contain socket
203
 *                  data.
204
 ********************************************************************/
205
BOOL        TCPIsConnected(TCP_SOCKET s);
206
 
207
 
208
/*********************************************************************
209
 * Function:        void TCPDisconnect(TCP_SOCKET s)
210
 *
211
 * PreCondition:    TCPInit() is already called     AND
212
 *                  TCPIsPutReady(s) == TRUE
213
 *
214
 * Input:           s       - Socket to be disconnected.
215
 *
216
 * Output:          A disconnect request is sent for given socket.
217
 *
218
 * Side Effects:    None
219
 *
220
 * Overview:        None
221
 *
222
 * Note:            None
223
 ********************************************************************/
224
void        TCPDisconnect(TCP_SOCKET s);
225
 
226
 
227
/*********************************************************************
228
 * Function:        BOOL TCPIsPutReady(TCP_SOCKET s)
229
 *
230
 * PreCondition:    TCPInit() is already called.
231
 *
232
 * Input:           s       - socket to test
233
 *
234
 * Output:          TRUE if socket 's' is free to transmit
235
 *                  FALSE if socket 's' is not free to transmit.
236
 *
237
 * Side Effects:    None
238
 *
239
 * Overview:        None
240
 *
241
 * Note:            Each socket maintains only transmit buffer.
242
 *                  Hence until a data packet is acknowledeged by
243
 *                  remote node, socket will not be ready for
244
 *                  next transmission.
245
 *                  All control transmission such as Connect,
246
 *                  Disconnect do not consume/reserve any transmit
247
 *                  buffer.
248
 ********************************************************************/
249
BOOL        TCPIsPutReady(TCP_SOCKET s);
250
 
251
 
252
/*********************************************************************
253
 * Function:        BOOL TCPPut(TCP_SOCKET s, BYTE byte)
254
 *
255
 * PreCondition:    TCPIsPutReady() == TRUE
256
 *
257
 * Input:           s       - socket to use
258
 *                  byte    - a data byte to send
259
 *
260
 * Output:          TRUE if given byte was put in transmit buffer
261
 *                  FALSE if transmit buffer is full.
262
 *
263
 * Side Effects:    None
264
 *
265
 * Overview:        None
266
 *
267
 * Note:            None
268
 ********************************************************************/
269
BOOL        TCPPut(TCP_SOCKET socket, BYTE byte);
270
 
271
 
272
/*********************************************************************
273
 * Function:        BOOL TCPFlush(TCP_SOCKET s)
274
 *
275
 * PreCondition:    TCPInit() is already called.
276
 *
277
 * Input:           s       - Socket whose data is to be transmitted.
278
 *
279
 * Output:          All and any data associated with this socket
280
 *                  is marked as ready for transmission.
281
 *
282
 * Side Effects:    None
283
 *
284
 * Overview:        None
285
 *
286
 * Note:            None
287
 ********************************************************************/
288
BOOL        TCPFlush(TCP_SOCKET socket);
289
 
290
/*********************************************************************
291
 * Function:        BOOL TCPIsGetReady(TCP_SOCKET s)
292
 *
293
 * PreCondition:    TCPInit() is already called.
294
 *
295
 * Input:           s       - socket to test
296
 *
297
 * Output:          TRUE if socket 's' contains any data.
298
 *                  FALSE if socket 's' does not contain any data.
299
 *
300
 * Side Effects:    None
301
 *
302
 * Overview:        None
303
 *
304
 * Note:            None
305
 ********************************************************************/
306
BOOL        TCPIsGetReady(TCP_SOCKET s);
307
 
308
 
309
/*********************************************************************
310
 * Function:        BOOL TCPGet(TCP_SOCKET s, BYTE *byte)
311
 *
312
 * PreCondition:    TCPInit() is already called     AND
313
 *                  TCPIsGetReady(s) == TRUE
314
 *
315
 * Input:           s       - socket
316
 *                  byte    - Pointer to a byte.
317
 *
318
 * Output:          TRUE if a byte was read.
319
 *                  FALSE if byte was not read.
320
 *
321
 * Side Effects:    None
322
 *
323
 * Overview:        None
324
 *
325
 * Note:            None
326
 ********************************************************************/
327
BOOL        TCPGet(TCP_SOCKET socket, BYTE *byte);
328
 
329
 
330
/*********************************************************************
331
 * Function:        WORD TCPGetArray(TCP_SOCKET s, BYTE *buffer,
332
 *                                      WORD count)
333
 *
334
 * PreCondition:    TCPInit() is already called     AND
335
 *                  TCPIsGetReady(s) == TRUE
336
 *
337
 * Input:           s       - socket
338
 *                  buffer  - Buffer to hold received data.
339
 *                  count   - Buffer length
340
 *
341
 * Output:          Number of bytes loaded into buffer.
342
 *
343
 * Side Effects:    None
344
 *
345
 * Overview:        None
346
 *
347
 * Note:            None
348
 ********************************************************************/
349
WORD        TCPGetArray(TCP_SOCKET s, BYTE *buffer, WORD count);
350
 
351
 
352
/*********************************************************************
353
 * Function:        BOOL TCPDiscard(TCP_SOCKET s)
354
 *
355
 * PreCondition:    TCPInit() is already called.
356
 *
357
 * Input:           s       - socket
358
 *
359
 * Output:          TRUE if socket received data was discarded
360
 *                  FALSE if socket received data was already
361
 *                          discarded.
362
 *
363
 * Side Effects:    None
364
 *
365
 * Overview:        None
366
 *
367
 * Note:            None
368
 ********************************************************************/
369
BOOL        TCPDiscard(TCP_SOCKET socket);
370
 
371
/*********************************************************************
372
 * Function:        BOOL TCPProcess(NODE_INFO* remote,
373
 *                                  IP_ADDR *localIP,
374
 *                                  WORD len)
375
 *
376
 * PreCondition:    TCPInit() is already called     AND
377
 *                  TCP segment is ready in MAC buffer
378
 *
379
 * Input:           remote      - Remote node info
380
 *                  len         - Total length of TCP semgent.
381
 *
382
 * Output:          TRUE if this function has completed its task
383
 *                  FALSE otherwise
384
 *
385
 * Side Effects:    None
386
 *
387
 * Overview:        None
388
 *
389
 * Note:            None
390
 ********************************************************************/
391
BOOL        TCPProcess(NODE_INFO *remote,
392
                       IP_ADDR *localIP,
393
                       WORD len);
394
 
395
 
396
/*********************************************************************
397
 * Function:        void TCPTick(void)
398
 *
399
 * PreCondition:    TCPInit() is already called.
400
 *
401
 * Input:           None
402
 *
403
 * Output:          Each socket FSM is executed for any timeout
404
 *                  situation.
405
 *
406
 * Side Effects:    None
407
 *
408
 * Overview:        None
409
 *
410
 * Note:            None
411
 ********************************************************************/
412
void        TCPTick(void);
413
 
414
 
415
#endif