OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [uIP_Demo_IAR_ARM7/] [uip/] [uip.h] - Blame information for rev 607

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 583 jeremybenn
/**
2
 * \addtogroup uip
3
 * @{
4
 */
5
 
6
/**
7
 * \file
8
 * Header file for the uIP TCP/IP stack.
9
 * \author Adam Dunkels <adam@dunkels.com>
10
 *
11
 * The uIP TCP/IP stack header file contains definitions for a number
12
 * of C macros that are used by uIP programs as well as internal uIP
13
 * structures, TCP/IP header structures and function declarations.
14
 *
15
 */
16
 
17
 
18
/*
19
 * Copyright (c) 2001-2003, Adam Dunkels.
20
 * All rights reserved.
21
 *
22
 * Redistribution and use in source and binary forms, with or without
23
 * modification, are permitted provided that the following conditions
24
 * are met:
25
 * 1. Redistributions of source code must retain the above copyright
26
 *    notice, this list of conditions and the following disclaimer.
27
 * 2. Redistributions in binary form must reproduce the above copyright
28
 *    notice, this list of conditions and the following disclaimer in the
29
 *    documentation and/or other materials provided with the distribution.
30
 * 3. The name of the author may not be used to endorse or promote
31
 *    products derived from this software without specific prior
32
 *    written permission.
33
 *
34
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
35
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
38
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
 *
46
 * This file is part of the uIP TCP/IP stack.
47
 *
48
 * $Id: uip.h 2 2011-07-17 20:13:17Z filepang@gmail.com $
49
 *
50
 */
51
 
52
#ifndef __UIP_H__
53
#define __UIP_H__
54
 
55
#include "uipopt.h"
56
 
57
/*-----------------------------------------------------------------------------------*/
58
/* First, the functions that should be called from the
59
 * system. Initialization, the periodic timer and incoming packets are
60
 * handled by the following three functions.
61
 */
62
 
63
/**
64
 * \defgroup uipconffunc uIP configuration functions
65
 * @{
66
 *
67
 * The uIP configuration functions are used for setting run-time
68
 * parameters in uIP such as IP addresses.
69
 */
70
 
71
/**
72
 * Set the IP address of this host.
73
 *
74
 * The IP address is represented as a 4-byte array where the first
75
 * octet of the IP address is put in the first member of the 4-byte
76
 * array.
77
 *
78
 * \param addr A pointer to a 4-byte representation of the IP address.
79
 *
80
 * \hideinitializer
81
 */
82
#define uip_sethostaddr(addr) do { uip_hostaddr[0] = addr[0]; \
83
                              uip_hostaddr[1] = addr[1]; } while(0)
84
 
85
/**
86
 * Get the IP address of this host.
87
 *
88
 * The IP address is represented as a 4-byte array where the first
89
 * octet of the IP address is put in the first member of the 4-byte
90
 * array.
91
 *
92
 * \param addr A pointer to a 4-byte array that will be filled in with
93
 * the currently configured IP address.
94
 *
95
 * \hideinitializer
96
 */
97
#define uip_gethostaddr(addr) do { addr[0] = uip_hostaddr[0]; \
98
                              addr[1] = uip_hostaddr[1]; } while(0)
99
 
100
/** @} */
101
 
102
/**
103
 * \defgroup uipinit uIP initialization functions
104
 * @{
105
 *
106
 * The uIP initialization functions are used for booting uIP.
107
 */
108
 
109
/**
110
 * uIP initialization function.
111
 *
112
 * This function should be called at boot up to initilize the uIP
113
 * TCP/IP stack.
114
 */
115
void uip_init(void);
116
 
117
/** @} */
118
 
119
/**
120
 * \defgroup uipdevfunc uIP device driver functions
121
 * @{
122
 *
123
 * These functions are used by a network device driver for interacting
124
 * with uIP.
125
 */
126
 
127
/**
128
 * Process an incoming packet.
129
 *
130
 * This function should be called when the device driver has received
131
 * a packet from the network. The packet from the device driver must
132
 * be present in the uip_buf buffer, and the length of the packet
133
 * should be placed in the uip_len variable.
134
 *
135
 * When the function returns, there may be an outbound packet placed
136
 * in the uip_buf packet buffer. If so, the uip_len variable is set to
137
 * the length of the packet. If no packet is to be sent out, the
138
 * uip_len variable is set to 0.
139
 *
140
 * The usual way of calling the function is presented by the source
141
 * code below.
142
 \code
143
  uip_len = devicedriver_poll();
144
  if(uip_len > 0) {
145
    uip_input();
146
    if(uip_len > 0) {
147
      devicedriver_send();
148
    }
149
  }
150
 \endcode
151
 *
152
 * \note If you are writing a uIP device driver that needs ARP
153
 * (Address Resolution Protocol), e.g., when running uIP over
154
 * Ethernet, you will need to call the uIP ARP code before calling
155
 * this function:
156
 \code
157
  #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
158
  uip_len = ethernet_devicedrver_poll();
159
  if(uip_len > 0) {
160
    if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
161
      uip_arp_ipin();
162
      uip_input();
163
      if(uip_len > 0) {
164
        uip_arp_out();
165
        ethernet_devicedriver_send();
166
      }
167
    } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
168
      uip_arp_arpin();
169
      if(uip_len > 0) {
170
        ethernet_devicedriver_send();
171
      }
172
    }
173
 \endcode
174
 *
175
 * \hideinitializer
176
 */
177
#define uip_input()        uip_process(UIP_DATA)
178
 
179
/**
180
 * Periodic processing for a connection identified by its number.
181
 *
182
 * This function does the necessary periodic processing (timers,
183
 * polling) for a uIP TCP conneciton, and should be called when the
184
 * periodic uIP timer goes off. It should be called for every
185
 * connection, regardless of whether they are open of closed.
186
 *
187
 * When the function returns, it may have an outbound packet waiting
188
 * for service in the uIP packet buffer, and if so the uip_len
189
 * variable is set to a value larger than zero. The device driver
190
 * should be called to send out the packet.
191
 *
192
 * The ususal way of calling the function is through a for() loop like
193
 * this:
194
 \code
195
  for(i = 0; i < UIP_CONNS; ++i) {
196
    uip_periodic(i);
197
    if(uip_len > 0) {
198
      devicedriver_send();
199
    }
200
  }
201
 \endcode
202
 *
203
 * \note If you are writing a uIP device driver that needs ARP
204
 * (Address Resolution Protocol), e.g., when running uIP over
205
 * Ethernet, you will need to call the uip_arp_out() function before
206
 * calling the device driver:
207
 \code
208
  for(i = 0; i < UIP_CONNS; ++i) {
209
    uip_periodic(i);
210
    if(uip_len > 0) {
211
      uip_arp_out();
212
      ethernet_devicedriver_send();
213
    }
214
  }
215
 \endcode
216
 *
217
 * \param conn The number of the connection which is to be periodically polled.
218
 *
219
 * \hideinitializer
220
 */
221
#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
222
                                uip_process(UIP_TIMER); } while (0)
223
 
224
/**
225
 * Periodic processing for a connection identified by a pointer to its structure.
226
 *
227
 * Same as uip_periodic() but takes a pointer to the actual uip_conn
228
 * struct instead of an integer as its argument. This function can be
229
 * used to force periodic processing of a specific connection.
230
 *
231
 * \param conn A pointer to the uip_conn struct for the connection to
232
 * be processed.
233
 *
234
 * \hideinitializer
235
 */
236
#define uip_periodic_conn(conn) do { uip_conn = conn; \
237
                                     uip_process(UIP_TIMER); } while (0)
238
 
239
#if UIP_UDP
240
/**
241
 * Periodic processing for a UDP connection identified by its number.
242
 *
243
 * This function is essentially the same as uip_prerioic(), but for
244
 * UDP connections. It is called in a similar fashion as the
245
 * uip_periodic() function:
246
 \code
247
  for(i = 0; i < UIP_UDP_CONNS; i++) {
248
    uip_udp_periodic(i);
249
    if(uip_len > 0) {
250
      devicedriver_send();
251
    }
252
  }
253
 \endcode
254
 *
255
 * \note As for the uip_periodic() function, special care has to be
256
 * taken when using uIP together with ARP and Ethernet:
257
 \code
258
  for(i = 0; i < UIP_UDP_CONNS; i++) {
259
    uip_udp_periodic(i);
260
    if(uip_len > 0) {
261
      uip_arp_out();
262
      ethernet_devicedriver_send();
263
    }
264
  }
265
 \endcode
266
 *
267
 * \param conn The number of the UDP connection to be processed.
268
 *
269
 * \hideinitializer
270
 */
271
#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
272
                                uip_process(UIP_UDP_TIMER); } while (0)
273
 
274
/**
275
 * Periodic processing for a UDP connection identified by a pointer to
276
 * its structure.
277
 *
278
 * Same as uip_udp_periodic() but takes a pointer to the actual
279
 * uip_conn struct instead of an integer as its argument. This
280
 * function can be used to force periodic processing of a specific
281
 * connection.
282
 *
283
 * \param conn A pointer to the uip_udp_conn struct for the connection
284
 * to be processed.
285
 *
286
 * \hideinitializer
287
 */
288
#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
289
                                         uip_process(UIP_UDP_TIMER); } while (0)
290
 
291
 
292
#endif /* UIP_UDP */
293
 
294
/**
295
 * The uIP packet buffer.
296
 *
297
 * The uip_buf array is used to hold incoming and outgoing
298
 * packets. The device driver should place incoming data into this
299
 * buffer. When sending data, the device driver should read the link
300
 * level headers and the TCP/IP headers from this buffer. The size of
301
 * the link level headers is configured by the UIP_LLH_LEN define.
302
 *
303
 * \note The application data need not be placed in this buffer, so
304
 * the device driver must read it from the place pointed to by the
305
 * uip_appdata pointer as illustrated by the following example:
306
 \code
307
 void
308
 devicedriver_send(void)
309
 {
310
    hwsend(&uip_buf[0], UIP_LLH_LEN);
311
    hwsend(&uip_buf[UIP_LLH_LEN], 40);
312
    hwsend(uip_appdata, uip_len - 40 - UIP_LLH_LEN);
313
 }
314
 \endcode
315
 */
316
extern u8_t uip_buf[UIP_BUFSIZE+2]; /*_RB_ __attribute__ ((aligned (4)));*/
317
 
318
/** @} */
319
 
320
/*-----------------------------------------------------------------------------------*/
321
/* Functions that are used by the uIP application program. Opening and
322
 * closing connections, sending and receiving data, etc. is all
323
 * handled by the functions below.
324
*/
325
/**
326
 * \defgroup uipappfunc uIP application functions
327
 * @{
328
 *
329
 * Functions used by an application running of top of uIP.
330
 */
331
 
332
/**
333
 * Start listening to the specified port.
334
 *
335
 * \note Since this function expects the port number in network byte
336
 * order, a conversion using HTONS() or htons() is necessary.
337
 *
338
 \code
339
 uip_listen(HTONS(80));
340
 \endcode
341
 *
342
 * \param port A 16-bit port number in network byte order.
343
 */
344
void uip_listen(u16_t port);
345
 
346
/**
347
 * Stop listening to the specified port.
348
 *
349
 * \note Since this function expects the port number in network byte
350
 * order, a conversion using HTONS() or htons() is necessary.
351
 *
352
 \code
353
 uip_unlisten(HTONS(80));
354
 \endcode
355
 *
356
 * \param port A 16-bit port number in network byte order.
357
 */
358
void uip_unlisten(u16_t port);
359
 
360
/**
361
 * Connect to a remote host using TCP.
362
 *
363
 * This function is used to start a new connection to the specified
364
 * port on the specied host. It allocates a new connection identifier,
365
 * sets the connection to the SYN_SENT state and sets the
366
 * retransmission timer to 0. This will cause a TCP SYN segment to be
367
 * sent out the next time this connection is periodically processed,
368
 * which usually is done within 0.5 seconds after the call to
369
 * uip_connect().
370
 *
371
 * \note This function is avaliable only if support for active open
372
 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
373
 *
374
 * \note Since this function requires the port number to be in network
375
 * byte order, a convertion using HTONS() or htons() is necessary.
376
 *
377
 \code
378
 u16_t ipaddr[2];
379
 
380
 uip_ipaddr(ipaddr, 192,168,1,2);
381
 uip_connect(ipaddr, HTONS(80));
382
 \endcode
383
 *
384
 * \param ripaddr A pointer to a 4-byte array representing the IP
385
 * address of the remote hot.
386
 *
387
 * \param port A 16-bit port number in network byte order.
388
 *
389
 * \return A pointer to the uIP connection identifier for the new connection,
390
 * or NULL if no connection could be allocated.
391
 *
392
 */
393
struct uip_conn *uip_connect(u16_t *ripaddr, u16_t port);
394
 
395
 
396
 
397
/**
398
 * \internal
399
 *
400
 * Check if a connection has outstanding (i.e., unacknowledged) data.
401
 *
402
 * \param conn A pointer to the uip_conn structure for the connection.
403
 *
404
 * \hideinitializer
405
 */
406
#define uip_outstanding(conn) ((conn)->len)
407
 
408
/**
409
 * Send data on the current connection.
410
 *
411
 * This function is used to send out a single segment of TCP
412
 * data. Only applications that have been invoked by uIP for event
413
 * processing can send data.
414
 *
415
 * The amount of data that actually is sent out after a call to this
416
 * funcion is determined by the maximum amount of data TCP allows. uIP
417
 * will automatically crop the data so that only the appropriate
418
 * amount of data is sent. The function uip_mss() can be used to query
419
 * uIP for the amount of data that actually will be sent.
420
 *
421
 * \note This function does not guarantee that the sent data will
422
 * arrive at the destination. If the data is lost in the network, the
423
 * application will be invoked with the uip_rexmit() event being
424
 * set. The application will then have to resend the data using this
425
 * function.
426
 *
427
 * \param data A pointer to the data which is to be sent.
428
 *
429
 * \param len The maximum amount of data bytes to be sent.
430
 *
431
 * \hideinitializer
432
 */
433
#define uip_send(data, len) do { uip_sappdata = (data); uip_slen = (len);} while(0)
434
 
435
/**
436
 * The length of any incoming data that is currently avaliable (if avaliable)
437
 * in the uip_appdata buffer.
438
 *
439
 * The test function uip_data() must first be used to check if there
440
 * is any data available at all.
441
 *
442
 * \hideinitializer
443
 */
444
#define uip_datalen()       uip_len
445
 
446
/**
447
 * The length of any out-of-band data (urgent data) that has arrived
448
 * on the connection.
449
 *
450
 * \note The configuration parameter UIP_URGDATA must be set for this
451
 * function to be enabled.
452
 *
453
 * \hideinitializer
454
 */
455
#define uip_urgdatalen()    uip_urglen
456
 
457
/**
458
 * Close the current connection.
459
 *
460
 * This function will close the current connection in a nice way.
461
 *
462
 * \hideinitializer
463
 */
464
#define uip_close()         (uip_flags = UIP_CLOSE)
465
 
466
/**
467
 * Abort the current connection.
468
 *
469
 * This function will abort (reset) the current connection, and is
470
 * usually used when an error has occured that prevents using the
471
 * uip_close() function.
472
 *
473
 * \hideinitializer
474
 */
475
#define uip_abort()         (uip_flags = UIP_ABORT)
476
 
477
/**
478
 * Tell the sending host to stop sending data.
479
 *
480
 * This function will close our receiver's window so that we stop
481
 * receiving data for the current connection.
482
 *
483
 * \hideinitializer
484
 */
485
#define uip_stop()          (uip_conn->tcpstateflags |= UIP_STOPPED)
486
 
487
/**
488
 * Find out if the current connection has been previously stopped with
489
 * uip_stop().
490
 *
491
 * \hideinitializer
492
 */
493
#define uip_stopped(conn)   ((conn)->tcpstateflags & UIP_STOPPED)
494
 
495
/**
496
 * Restart the current connection, if is has previously been stopped
497
 * with uip_stop().
498
 *
499
 * This function will open the receiver's window again so that we
500
 * start receiving data for the current connection.
501
 *
502
 * \hideinitializer
503
 */
504
#define uip_restart()         do { uip_flags |= UIP_NEWDATA; \
505
                                   uip_conn->tcpstateflags &= ~UIP_STOPPED; \
506
                              } while(0)
507
 
508
 
509
/* uIP tests that can be made to determine in what state the current
510
   connection is, and what the application function should do. */
511
 
512
/**
513
 * Is new incoming data available?
514
 *
515
 * Will reduce to non-zero if there is new data for the application
516
 * present at the uip_appdata pointer. The size of the data is
517
 * avaliable through the uip_len variable.
518
 *
519
 * \hideinitializer
520
 */
521
#define uip_newdata()   (uip_flags & UIP_NEWDATA)
522
 
523
/**
524
 * Has previously sent data been acknowledged?
525
 *
526
 * Will reduce to non-zero if the previously sent data has been
527
 * acknowledged by the remote host. This means that the application
528
 * can send new data.
529
 *
530
 * \hideinitializer
531
 */
532
#define uip_acked()   (uip_flags & UIP_ACKDATA)
533
 
534
/**
535
 * Has the connection just been connected?
536
 *
537
 * Reduces to non-zero if the current connection has been connected to
538
 * a remote host. This will happen both if the connection has been
539
 * actively opened (with uip_connect()) or passively opened (with
540
 * uip_listen()).
541
 *
542
 * \hideinitializer
543
 */
544
#define uip_connected() (uip_flags & UIP_CONNECTED)
545
 
546
/**
547
 * Has the connection been closed by the other end?
548
 *
549
 * Is non-zero if the connection has been closed by the remote
550
 * host. The application may then do the necessary clean-ups.
551
 *
552
 * \hideinitializer
553
 */
554
#define uip_closed()    (uip_flags & UIP_CLOSE)
555
 
556
/**
557
 * Has the connection been aborted by the other end?
558
 *
559
 * Non-zero if the current connection has been aborted (reset) by the
560
 * remote host.
561
 *
562
 * \hideinitializer
563
 */
564
#define uip_aborted()    (uip_flags & UIP_ABORT)
565
 
566
/**
567
 * Has the connection timed out?
568
 *
569
 * Non-zero if the current connection has been aborted due to too many
570
 * retransmissions.
571
 *
572
 * \hideinitializer
573
 */
574
#define uip_timedout()    (uip_flags & UIP_TIMEDOUT)
575
 
576
/**
577
 * Do we need to retransmit previously data?
578
 *
579
 * Reduces to non-zero if the previously sent data has been lost in
580
 * the network, and the application should retransmit it. The
581
 * application should send the exact same data as it did the last
582
 * time, using the uip_send() function.
583
 *
584
 * \hideinitializer
585
 */
586
#define uip_rexmit()     (uip_flags & UIP_REXMIT)
587
 
588
/**
589
 * Is the connection being polled by uIP?
590
 *
591
 * Is non-zero if the reason the application is invoked is that the
592
 * current connection has been idle for a while and should be
593
 * polled.
594
 *
595
 * The polling event can be used for sending data without having to
596
 * wait for the remote host to send data.
597
 *
598
 * \hideinitializer
599
 */
600
#define uip_poll()       (uip_flags & UIP_POLL)
601
 
602
/**
603
 * Get the initial maxium segment size (MSS) of the current
604
 * connection.
605
 *
606
 * \hideinitializer
607
 */
608
#define uip_initialmss()             (uip_conn->initialmss)
609
 
610
/**
611
 * Get the current maxium segment size that can be sent on the current
612
 * connection.
613
 *
614
 * The current maxiumum segment size that can be sent on the
615
 * connection is computed from the receiver's window and the MSS of
616
 * the connection (which also is available by calling
617
 * uip_initialmss()).
618
 *
619
 * \hideinitializer
620
 */
621
#define uip_mss()             (uip_conn->mss)
622
 
623
/**
624
 * Set up a new UDP connection.
625
 *
626
 * \param ripaddr A pointer to a 4-byte structure representing the IP
627
 * address of the remote host.
628
 *
629
 * \param rport The remote port number in network byte order.
630
 *
631
 * \return The uip_udp_conn structure for the new connection or NULL
632
 * if no connection could be allocated.
633
 */
634
struct uip_udp_conn *uip_udp_new(u16_t *ripaddr, u16_t rport);
635
 
636
/**
637
 * Removed a UDP connection.
638
 *
639
 * \param conn A pointer to the uip_udp_conn structure for the connection.
640
 *
641
 * \hideinitializer
642
 */
643
#define uip_udp_remove(conn) (conn)->lport = 0
644
 
645
/**
646
 * Send a UDP datagram of length len on the current connection.
647
 *
648
 * This function can only be called in response to a UDP event (poll
649
 * or newdata). The data must be present in the uip_buf buffer, at the
650
 * place pointed to by the uip_appdata pointer.
651
 *
652
 * \param len The length of the data in the uip_buf buffer.
653
 *
654
 * \hideinitializer
655
 */
656
#define uip_udp_send(len) uip_slen = (len)
657
 
658
/** @} */
659
 
660
/* uIP convenience and converting functions. */
661
 
662
/**
663
 * \defgroup uipconvfunc uIP conversion functions
664
 * @{
665
 *
666
 * These functions can be used for converting between different data
667
 * formats used by uIP.
668
 */
669
 
670
/**
671
 * Pack an IP address into a 4-byte array which is used by uIP to
672
 * represent IP addresses.
673
 *
674
 * Example:
675
 \code
676
 u16_t ipaddr[2];
677
 
678
 uip_ipaddr(&ipaddr, 192,168,1,2);
679
 \endcode
680
 *
681
 * \param addr A pointer to a 4-byte array that will be filled in with
682
 * the IP addres.
683
 * \param addr0 The first octet of the IP address.
684
 * \param addr1 The second octet of the IP address.
685
 * \param addr2 The third octet of the IP address.
686
 * \param addr3 The forth octet of the IP address.
687
 *
688
 * \hideinitializer
689
 */
690
#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
691
                     (addr)[0] = HTONS(((addr0) << 8) | (addr1)); \
692
                     (addr)[1] = HTONS(((addr2) << 8) | (addr3)); \
693
                  } while(0)
694
 
695
/**
696
 * Convert 16-bit quantity from host byte order to network byte order.
697
 *
698
 * This macro is primarily used for converting constants from host
699
 * byte order to network byte order. For converting variables to
700
 * network byte order, use the htons() function instead.
701
 *
702
 * \hideinitializer
703
 */
704
#ifndef HTONS
705
#   if BYTE_ORDER == BIG_ENDIAN
706
#      define HTONS(n) (n)
707
#   else /* BYTE_ORDER == BIG_ENDIAN */
708
#      define HTONS(n) ((((u16_t)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8))
709
#   endif /* BYTE_ORDER == BIG_ENDIAN */
710
#endif /* HTONS */
711
 
712
/**
713
 * Convert 16-bit quantity from host byte order to network byte order.
714
 *
715
 * This function is primarily used for converting variables from host
716
 * byte order to network byte order. For converting constants to
717
 * network byte order, use the HTONS() macro instead.
718
 */
719
#ifndef htons
720
u16_t htons(u16_t val);
721
#endif /* htons */
722
 
723
/** @} */
724
 
725
/**
726
 * Pointer to the application data in the packet buffer.
727
 *
728
 * This pointer points to the application data when the application is
729
 * called. If the application wishes to send data, the application may
730
 * use this space to write the data into before calling uip_send().
731
 */
732
extern volatile u8_t *uip_appdata;
733
extern volatile u8_t *uip_sappdata;
734
 
735
#if UIP_URGDATA > 0
736
/* u8_t *uip_urgdata:
737
 *
738
 * This pointer points to any urgent data that has been received. Only
739
 * present if compiled with support for urgent data (UIP_URGDATA).
740
 */
741
extern volatile u8_t *uip_urgdata;
742
#endif /* UIP_URGDATA > 0 */
743
 
744
 
745
/* u[8|16]_t uip_len:
746
 *
747
 * When the application is called, uip_len contains the length of any
748
 * new data that has been received from the remote host. The
749
 * application should set this variable to the size of any data that
750
 * the application wishes to send. When the network device driver
751
 * output function is called, uip_len should contain the length of the
752
 * outgoing packet.
753
 */
754
extern volatile u16_t uip_len, uip_slen;
755
 
756
#if UIP_URGDATA > 0
757
extern volatile u8_t uip_urglen, uip_surglen;
758
#endif /* UIP_URGDATA > 0 */
759
 
760
 
761
/**
762
 * Representation of a uIP TCP connection.
763
 *
764
 * The uip_conn structure is used for identifying a connection. All
765
 * but one field in the structure are to be considered read-only by an
766
 * application. The only exception is the appstate field whos purpose
767
 * is to let the application store application-specific state (e.g.,
768
 * file pointers) for the connection. The size of this field is
769
 * configured in the "uipopt.h" header file.
770
 */
771
struct uip_conn {
772
  u16_t ripaddr[2];   /**< The IP address of the remote host. */
773
 
774
  u16_t lport;        /**< The local TCP port, in network byte order. */
775
  u16_t rport;        /**< The local remote TCP port, in network byte
776
                         order. */
777
 
778
  u8_t rcv_nxt[4];    /**< The sequence number that we expect to
779
                         receive next. */
780
  u8_t snd_nxt[4];    /**< The sequence number that was last sent by
781
                         us. */
782
  u16_t len;          /**< Length of the data that was previously sent. */
783
  u16_t mss;          /**< Current maximum segment size for the
784
                         connection. */
785
  u16_t initialmss;   /**< Initial maximum segment size for the
786
                         connection. */
787
  u8_t sa;            /**< Retransmission time-out calculation state
788
                         variable. */
789
  u8_t sv;            /**< Retransmission time-out calculation state
790
                         variable. */
791
  u8_t rto;           /**< Retransmission time-out. */
792
  u8_t tcpstateflags; /**< TCP state and flags. */
793
  u8_t timer;         /**< The retransmission timer. */
794
  u8_t nrtx;          /**< The number of retransmissions for the last
795
                         segment sent. */
796
 
797
  /** The application state. */
798
  u8_t appstate[UIP_APPSTATE_SIZE];
799
};
800
 
801
 
802
/* Pointer to the current connection. */
803
extern struct uip_conn *uip_conn;
804
/* The array containing all uIP connections. */
805
extern struct uip_conn uip_conns[UIP_CONNS];
806
/**
807
 * \addtogroup uiparch
808
 * @{
809
 */
810
 
811
/**
812
 * 4-byte array used for the 32-bit sequence number calculations.
813
 */
814
extern volatile u8_t uip_acc32[4];
815
 
816
/** @} */
817
 
818
 
819
#if UIP_UDP
820
/**
821
 * Representation of a uIP UDP connection.
822
 */
823
struct uip_udp_conn {
824
  u16_t ripaddr[2];   /**< The IP address of the remote peer. */
825
  u16_t lport;        /**< The local port number in network byte order. */
826
  u16_t rport;        /**< The remote port number in network byte order. */
827
};
828
 
829
extern struct uip_udp_conn *uip_udp_conn;
830
extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
831
#endif /* UIP_UDP */
832
 
833
/**
834
 * The structure holding the TCP/IP statistics that are gathered if
835
 * UIP_STATISTICS is set to 1.
836
 *
837
 */
838
struct uip_stats {
839
  struct {
840
    uip_stats_t drop;     /**< Number of dropped packets at the IP
841
                             layer. */
842
    uip_stats_t recv;     /**< Number of received packets at the IP
843
                             layer. */
844
    uip_stats_t sent;     /**< Number of sent packets at the IP
845
                             layer. */
846
    uip_stats_t vhlerr;   /**< Number of packets dropped due to wrong
847
                             IP version or header length. */
848
    uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
849
                             IP length, high byte. */
850
    uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
851
                             IP length, low byte. */
852
    uip_stats_t fragerr;  /**< Number of packets dropped since they
853
                             were IP fragments. */
854
    uip_stats_t chkerr;   /**< Number of packets dropped due to IP
855
                             checksum errors. */
856
    uip_stats_t protoerr; /**< Number of packets dropped since they
857
                             were neither ICMP, UDP nor TCP. */
858
  } ip;                   /**< IP statistics. */
859
  struct {
860
    uip_stats_t drop;     /**< Number of dropped ICMP packets. */
861
    uip_stats_t recv;     /**< Number of received ICMP packets. */
862
    uip_stats_t sent;     /**< Number of sent ICMP packets. */
863
    uip_stats_t typeerr;  /**< Number of ICMP packets with a wrong
864
                             type. */
865
  } icmp;                 /**< ICMP statistics. */
866
  struct {
867
    uip_stats_t drop;     /**< Number of dropped TCP segments. */
868
    uip_stats_t recv;     /**< Number of recived TCP segments. */
869
    uip_stats_t sent;     /**< Number of sent TCP segments. */
870
    uip_stats_t chkerr;   /**< Number of TCP segments with a bad
871
                             checksum. */
872
    uip_stats_t ackerr;   /**< Number of TCP segments with a bad ACK
873
                             number. */
874
    uip_stats_t rst;      /**< Number of recevied TCP RST (reset) segments. */
875
    uip_stats_t rexmit;   /**< Number of retransmitted TCP segments. */
876
    uip_stats_t syndrop;  /**< Number of dropped SYNs due to too few
877
                             connections was avaliable. */
878
    uip_stats_t synrst;   /**< Number of SYNs for closed ports,
879
                             triggering a RST. */
880
  } tcp;                  /**< TCP statistics. */
881
};
882
 
883
/**
884
 * The uIP TCP/IP statistics.
885
 *
886
 * This is the variable in which the uIP TCP/IP statistics are gathered.
887
 */
888
extern struct uip_stats uip_stat;
889
 
890
 
891
/*-----------------------------------------------------------------------------------*/
892
/* All the stuff below this point is internal to uIP and should not be
893
 * used directly by an application or by a device driver.
894
 */
895
/*-----------------------------------------------------------------------------------*/
896
/* u8_t uip_flags:
897
 *
898
 * When the application is called, uip_flags will contain the flags
899
 * that are defined in this file. Please read below for more
900
 * infomation.
901
 */
902
extern volatile u8_t uip_flags;
903
 
904
/* The following flags may be set in the global variable uip_flags
905
   before calling the application callback. The UIP_ACKDATA and
906
   UIP_NEWDATA flags may both be set at the same time, whereas the
907
   others are mutualy exclusive. Note that these flags should *NOT* be
908
   accessed directly, but through the uIP functions/macros. */
909
 
910
#define UIP_ACKDATA   1     /* Signifies that the outstanding data was
911
                               acked and the application should send
912
                               out new data instead of retransmitting
913
                               the last data. */
914
#define UIP_NEWDATA   2     /* Flags the fact that the peer has sent
915
                               us new data. */
916
#define UIP_REXMIT    4     /* Tells the application to retransmit the
917
                               data that was last sent. */
918
#define UIP_POLL      8     /* Used for polling the application, to
919
                               check if the application has data that
920
                               it wants to send. */
921
#define UIP_CLOSE     16    /* The remote host has closed the
922
                               connection, thus the connection has
923
                               gone away. Or the application signals
924
                               that it wants to close the
925
                               connection. */
926
#define UIP_ABORT     32    /* The remote host has aborted the
927
                               connection, thus the connection has
928
                               gone away. Or the application signals
929
                               that it wants to abort the
930
                               connection. */
931
#define UIP_CONNECTED 64    /* We have got a connection from a remote
932
                               host and have set up a new connection
933
                               for it, or an active connection has
934
                               been successfully established. */
935
 
936
#define UIP_TIMEDOUT  128   /* The connection has been aborted due to
937
                               too many retransmissions. */
938
 
939
 
940
/* uip_process(flag):
941
 *
942
 * The actual uIP function which does all the work.
943
 */
944
void uip_process(u8_t flag);
945
 
946
/* The following flags are passed as an argument to the uip_process()
947
   function. They are used to distinguish between the two cases where
948
   uip_process() is called. It can be called either because we have
949
   incoming data that should be processed, or because the periodic
950
   timer has fired. */
951
 
952
#define UIP_DATA    1     /* Tells uIP that there is incoming data in
953
                             the uip_buf buffer. The length of the
954
                             data is stored in the global variable
955
                             uip_len. */
956
#define UIP_TIMER   2     /* Tells uIP that the periodic timer has
957
                             fired. */
958
#if UIP_UDP
959
#define UIP_UDP_TIMER 3
960
#endif /* UIP_UDP */
961
 
962
/* The TCP states used in the uip_conn->tcpstateflags. */
963
#define CLOSED      0
964
#define SYN_RCVD    1
965
#define SYN_SENT    2
966
#define ESTABLISHED 3
967
#define FIN_WAIT_1  4
968
#define FIN_WAIT_2  5
969
#define CLOSING     6
970
#define TIME_WAIT   7
971
#define LAST_ACK    8
972
#define TS_MASK     15
973
 
974
#define UIP_STOPPED      16
975
 
976
#define UIP_TCPIP_HLEN 40
977
 
978
/* The TCP and IP headers. */
979
typedef struct {
980
  /* IP header. */
981
  u8_t vhl,
982
    tos,
983
    len[2],
984
    ipid[2],
985
    ipoffset[2],
986
    ttl,
987
    proto;
988
  u16_t ipchksum;
989
  u16_t srcipaddr[2],
990
    destipaddr[2];
991
 
992
  /* TCP header. */
993
  u16_t srcport,
994
    destport;
995
  u8_t seqno[4],
996
    ackno[4],
997
    tcpoffset,
998
    flags,
999
    wnd[2];
1000
  u16_t tcpchksum;
1001
  u8_t urgp[2];
1002
  u8_t optdata[4];
1003
} uip_tcpip_hdr;
1004
 
1005
/* The ICMP and IP headers. */
1006
typedef struct {
1007
  /* IP header. */
1008
  u8_t vhl,
1009
    tos,
1010
    len[2],
1011
    ipid[2],
1012
    ipoffset[2],
1013
    ttl,
1014
    proto;
1015
  u16_t ipchksum;
1016
  u16_t srcipaddr[2],
1017
    destipaddr[2];
1018
  /* ICMP (echo) header. */
1019
  u8_t type, icode;
1020
  u16_t icmpchksum;
1021
  u16_t id, seqno;
1022
} uip_icmpip_hdr;
1023
 
1024
 
1025
/* The UDP and IP headers. */
1026
typedef struct {
1027
  /* IP header. */
1028
  u8_t vhl,
1029
    tos,
1030
    len[2],
1031
    ipid[2],
1032
    ipoffset[2],
1033
    ttl,
1034
    proto;
1035
  u16_t ipchksum;
1036
  u16_t srcipaddr[2],
1037
    destipaddr[2];
1038
 
1039
  /* UDP header. */
1040
  u16_t srcport,
1041
    destport;
1042
  u16_t udplen;
1043
  u16_t udpchksum;
1044
} uip_udpip_hdr;
1045
 
1046
#define UIP_PROTO_ICMP  1
1047
#define UIP_PROTO_TCP   6
1048
#define UIP_PROTO_UDP   17
1049
 
1050
#if UIP_FIXEDADDR
1051
extern const u16_t uip_hostaddr[2];
1052
#else /* UIP_FIXEDADDR */
1053
extern u16_t uip_hostaddr[2];
1054
#endif /* UIP_FIXEDADDR */
1055
 
1056
#endif /* __UIP_H__ */
1057
 
1058
 
1059
/** @} */
1060
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.