00001
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef __UIP_H__
00053 #define __UIP_H__
00054
00055 #include "uipopt.h"
00056
00057
00058
00059
00060
00061
00062
00082 #define uip_sethostaddr(addr) do { uip_hostaddr[0] = addr[0]; \
00083 uip_hostaddr[1] = addr[1]; } while(0)
00084
00097 #define uip_gethostaddr(addr) do { addr[0] = uip_hostaddr[0]; \
00098 addr[1] = uip_hostaddr[1]; } while(0)
00099
00115 void uip_init(void);
00116
00177 #define uip_input() uip_process(UIP_DATA)
00178
00221 #define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
00222 uip_process(UIP_TIMER); } while (0)
00223
00236 #define uip_periodic_conn(conn) do { uip_conn = conn; \
00237 uip_process(UIP_TIMER); } while (0)
00238
00239 #if UIP_UDP
00240
00271 #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
00272 uip_process(UIP_UDP_TIMER); } while (0)
00273
00288 #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
00289 uip_process(UIP_UDP_TIMER); } while (0)
00290
00291
00292 #endif
00293
00316 extern u8_t uip_buf[UIP_BUFSIZE+2];
00317
00320
00321
00322
00323
00324
00344 void uip_listen(u16_t port);
00345
00358 void uip_unlisten(u16_t port);
00359
00393 struct uip_conn *uip_connect(u16_t *ripaddr, u16_t port);
00394
00395
00396
00406 #define uip_outstanding(conn) ((conn)->len)
00407
00433 #define uip_send(data, len) do { uip_sappdata = (data); uip_slen = (len);} while(0)
00434
00444 #define uip_datalen() uip_len
00445
00455 #define uip_urgdatalen() uip_urglen
00456
00464 #define uip_close() (uip_flags = UIP_CLOSE)
00465
00475 #define uip_abort() (uip_flags = UIP_ABORT)
00476
00485 #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
00486
00493 #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)
00494
00504 #define uip_restart() do { uip_flags |= UIP_NEWDATA; \
00505 uip_conn->tcpstateflags &= ~UIP_STOPPED; \
00506 } while(0)
00507
00508
00509
00510
00511
00521 #define uip_newdata() (uip_flags & UIP_NEWDATA)
00522
00532 #define uip_acked() (uip_flags & UIP_ACKDATA)
00533
00544 #define uip_connected() (uip_flags & UIP_CONNECTED)
00545
00554 #define uip_closed() (uip_flags & UIP_CLOSE)
00555
00564 #define uip_aborted() (uip_flags & UIP_ABORT)
00565
00574 #define uip_timedout() (uip_flags & UIP_TIMEDOUT)
00575
00586 #define uip_rexmit() (uip_flags & UIP_REXMIT)
00587
00600 #define uip_poll() (uip_flags & UIP_POLL)
00601
00608 #define uip_initialmss() (uip_conn->initialmss)
00609
00621 #define uip_mss() (uip_conn->mss)
00622
00634 struct uip_udp_conn *uip_udp_new(u16_t *ripaddr, u16_t rport);
00635
00643 #define uip_udp_remove(conn) (conn)->lport = 0
00644
00656 #define uip_udp_send(len) uip_slen = (len)
00657
00660
00661
00690 #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
00691 (addr)[0] = HTONS(((addr0) << 8) | (addr1)); \
00692 (addr)[1] = HTONS(((addr2) << 8) | (addr3)); \
00693 } while(0)
00694
00704 #ifndef HTONS
00705 # if BYTE_ORDER == BIG_ENDIAN
00706 # define HTONS(n) (n)
00707 # else
00708 # define HTONS(n) ((((u16_t)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8))
00709 # endif
00710 #endif
00711
00719 #ifndef htons
00720 u16_t htons(u16_t val);
00721 #endif
00722
00732 extern volatile u8_t *uip_appdata;
00733 extern volatile u8_t *uip_sappdata;
00734
00735 #if UIP_URGDATA > 0
00736
00737
00738
00739
00740
00741 extern volatile u8_t *uip_urgdata;
00742 #endif
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754 extern volatile u16_t uip_len, uip_slen;
00755
00756 #if UIP_URGDATA > 0
00757 extern volatile u8_t uip_urglen, uip_surglen;
00758 #endif
00759
00760
00771 struct uip_conn {
00772 u16_t ripaddr[2];
00774 u16_t lport;
00775 u16_t rport;
00778 u8_t rcv_nxt[4];
00780 u8_t snd_nxt[4];
00782 u16_t len;
00783 u16_t mss;
00785 u16_t initialmss;
00787 u8_t sa;
00789 u8_t sv;
00791 u8_t rto;
00792 u8_t tcpstateflags;
00793 u8_t timer;
00794 u8_t nrtx;
00798 u8_t appstate[UIP_APPSTATE_SIZE];
00799 };
00800
00801
00802
00803 extern struct uip_conn *uip_conn;
00804
00805 extern struct uip_conn uip_conns[UIP_CONNS];
00814 extern volatile u8_t uip_acc32[4];
00815
00819 #if UIP_UDP
00820
00823 struct uip_udp_conn {
00824 u16_t ripaddr[2];
00825 u16_t lport;
00826 u16_t rport;
00827 };
00828
00829 extern struct uip_udp_conn *uip_udp_conn;
00830 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
00831 #endif
00832
00838 struct uip_stats {
00839 struct {
00840 uip_stats_t drop;
00842 uip_stats_t recv;
00844 uip_stats_t sent;
00846 uip_stats_t vhlerr;
00848 uip_stats_t hblenerr;
00850 uip_stats_t lblenerr;
00852 uip_stats_t fragerr;
00854 uip_stats_t chkerr;
00856 uip_stats_t protoerr;
00858 } ip;
00859 struct {
00860 uip_stats_t drop;
00861 uip_stats_t recv;
00862 uip_stats_t sent;
00863 uip_stats_t typeerr;
00865 } icmp;
00866 struct {
00867 uip_stats_t drop;
00868 uip_stats_t recv;
00869 uip_stats_t sent;
00870 uip_stats_t chkerr;
00872 uip_stats_t ackerr;
00874 uip_stats_t rst;
00875 uip_stats_t rexmit;
00876 uip_stats_t syndrop;
00878 uip_stats_t synrst;
00880 } tcp;
00881 };
00882
00888 extern struct uip_stats uip_stat;
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902 extern volatile u8_t uip_flags;
00903
00904
00905
00906
00907
00908
00909
00910 #define UIP_ACKDATA 1
00911
00912
00913
00914 #define UIP_NEWDATA 2
00915
00916 #define UIP_REXMIT 4
00917
00918 #define UIP_POLL 8
00919
00920
00921 #define UIP_CLOSE 16
00922
00923
00924
00925
00926 #define UIP_ABORT 32
00927
00928
00929
00930
00931 #define UIP_CONNECTED 64
00932
00933
00934
00935
00936 #define UIP_TIMEDOUT 128
00937
00938
00939
00940
00941
00942
00943
00944 void uip_process(u8_t flag);
00945
00946
00947
00948
00949
00950
00951
00952 #define UIP_DATA 1
00953
00954
00955
00956 #define UIP_TIMER 2
00957
00958 #if UIP_UDP
00959 #define UIP_UDP_TIMER 3
00960 #endif
00961
00962
00963 #define CLOSED 0
00964 #define SYN_RCVD 1
00965 #define SYN_SENT 2
00966 #define ESTABLISHED 3
00967 #define FIN_WAIT_1 4
00968 #define FIN_WAIT_2 5
00969 #define CLOSING 6
00970 #define TIME_WAIT 7
00971 #define LAST_ACK 8
00972 #define TS_MASK 15
00973
00974 #define UIP_STOPPED 16
00975
00976 #define UIP_TCPIP_HLEN 40
00977
00978
00979 typedef struct {
00980
00981 u8_t vhl,
00982 tos,
00983 len[2],
00984 ipid[2],
00985 ipoffset[2],
00986 ttl,
00987 proto;
00988 u16_t ipchksum;
00989 u16_t srcipaddr[2],
00990 destipaddr[2];
00991
00992
00993 u16_t srcport,
00994 destport;
00995 u8_t seqno[4],
00996 ackno[4],
00997 tcpoffset,
00998 flags,
00999 wnd[2];
01000 u16_t tcpchksum;
01001 u8_t urgp[2];
01002 u8_t optdata[4];
01003 } uip_tcpip_hdr;
01004
01005
01006 typedef struct {
01007
01008 u8_t vhl,
01009 tos,
01010 len[2],
01011 ipid[2],
01012 ipoffset[2],
01013 ttl,
01014 proto;
01015 u16_t ipchksum;
01016 u16_t srcipaddr[2],
01017 destipaddr[2];
01018
01019 u8_t type, icode;
01020 u16_t icmpchksum;
01021 u16_t id, seqno;
01022 } uip_icmpip_hdr;
01023
01024
01025
01026 typedef struct {
01027
01028 u8_t vhl,
01029 tos,
01030 len[2],
01031 ipid[2],
01032 ipoffset[2],
01033 ttl,
01034 proto;
01035 u16_t ipchksum;
01036 u16_t srcipaddr[2],
01037 destipaddr[2];
01038
01039
01040 u16_t srcport,
01041 destport;
01042 u16_t udplen;
01043 u16_t udpchksum;
01044 } uip_udpip_hdr;
01045
01046 #define UIP_PROTO_ICMP 1
01047 #define UIP_PROTO_TCP 6
01048 #define UIP_PROTO_UDP 17
01049
01050 #if UIP_FIXEDADDR
01051 extern const u16_t uip_hostaddr[2];
01052 #else
01053 extern u16_t uip_hostaddr[2];
01054 #endif
01055
01056 #endif
01057
01058