⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uip.lst

📁 运行环境是keil。这是一个实现嵌入式TCP/IP的程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.06   UIP                                                                   04/05/2006 12:13:01 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE UIP
OBJECT MODULE PLACED IN .\DEBUG\uip.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE uip\uip.c LARGE OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\DEBUG\u
                    -ip.lst) OBJECT(.\DEBUG\uip.obj)

stmt level    source

   1          
   2          /*
   3          This is a small implementation of the IP and TCP protocols (as well as
   4          some basic ICMP stuff). The implementation couples the IP, TCP and the
   5          application layers very tightly. To keep the size of the compiled code
   6          down, this code also features heavy usage of the goto statement.
   7          
   8          The principle is that we have a small buffer, called the uip_buf, in which
   9          the device driver puts an incoming packet. The TCP/IP stack parses the
  10          headers in the packet, and calls upon the application. If the remote
  11          host has sent data to the application, this data is present in the uip_buf
  12          and the application read the data from there. It is up to the
  13          application to put this data into a byte stream if needed. The
  14          application will not be fed with data that is out of sequence.
  15          
  16          If the application whishes to send data to the peer, it should put its
  17          data into the uip_buf, 40 bytes from the start of the buffer. The TCP/IP
  18          stack will calculate the checksums, and fill in the necessary header
  19          fields and finally send the packet back to the peer. */
  20          
  21          #include "uip.h"
  22          #include "uipopt.h"
  23          #include "uip_arch.h"
  24          
  25          #include <LCD\LCD.h>
  26          /*-----------------------------------------------------------------------------------*/
  27          /* Variable definitions. */
  28          
  29          u8_t uip_buf[UIP_BUFSIZE];   /* The packet buffer that contains
  30                                          incoming packets. */
  31          volatile u8_t *uip_appdata;  /* The uip_appdata pointer points to
  32                                          application data. */
  33          
  34          #if UIP_BUFSIZE > 255
              volatile u16_t uip_len;      /* The uip_len is either 8 or 16 bits,
                                              depending on the maximum packet
                                              size. */
              #else
  39          volatile u8_t uip_len;
  40          #endif /* UIP_BUFSIZE > 255 */
  41          
  42          volatile u8_t uip_flags;     /* The uip_flags variable is used for
  43                                          communication between the TCP/IP stack
  44                                          and the application program. */
  45          struct uip_conn *uip_conn;   /* uip_conn always points to the current
  46                                          connection. */
  47          
  48          struct uip_conn uip_conns[UIP_CONNS];
  49                                       /* The uip_conns array holds all TCP
  50                                          connections. */
  51          u16_t uip_listenports[UIP_LISTENPORTS];
  52                                       /* The uip_listenports list all currently
  53                                          listning ports. */
  54          
C51 COMPILER V7.06   UIP                                                                   04/05/2006 12:13:01 PAGE 2   

  55          
  56          static u16_t ipid;           /* Ths ipid variable is an increasing
  57                                          number that is used for the IP ID
  58                                          field. */
  59          
  60          static u8_t iss[4];          /* The iss variable is used for the TCP
  61                                          initial sequence number. */
  62          
  63          #if UIP_ACTIVE_OPEN
              static u16_t lastport;       /* Keeps track of the last port used for
                                              a new connection. */
              #endif /* UIP_ACTIVE_OPEN */
  67          
  68          /* Temporary variables. */
  69          static u8_t c, opt;
  70          static u16_t tmpport;
  71          
  72          /* Structures and definitions. */
  73          typedef struct {
  74            /* IP header. */
  75            u8_t vhl,
  76              tos,          
  77              len[2],       
  78              ipid[2],        
  79              ipoffset[2],  
  80              ttl,          
  81              proto;     
  82            u16_t ipchksum;
  83            u16_t srcipaddr[2], 
  84              destipaddr[2];
  85            /* ICMP (echo) header. */
  86            u8_t type, icode;
  87            u16_t icmpchksum;
  88            u16_t id, seqno;  
  89          } ipicmphdr;
  90          
  91          #define TCP_FIN 0x01
  92          #define TCP_SYN 0x02
  93          #define TCP_RST 0x04
  94          #define TCP_PSH 0x08
  95          #define TCP_ACK 0x10
  96          #define TCP_URG 0x20
  97          
  98          #define IP_PROTO_ICMP   1
  99          #define IP_PROTO_TCP    6
 100          
 101          #define ICMP_ECHO_REPLY 0
 102          #define ICMP_ECHO       8     
 103          
 104          /* Macros. */
 105          #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
 106          #define ICMPBUF ((ipicmphdr *)&uip_buf[UIP_LLH_LEN])
 107          
 108          #if UIP_STATISTICS == 1
 109          //struct uip_stats uip_stat;  LEON;
 110          struct uip_stats uip_stat={
 111                                     {0,0,0,0,0,0,0,0,0},
 112                                     {0,0,0,0}, 
 113                                     {0,0,0,0,0,0,0,0,0}, 
 114                                    };
 115          #define UIP_STAT(s) s
 116          #else
C51 COMPILER V7.06   UIP                                                                   04/05/2006 12:13:01 PAGE 3   

              #define UIP_STAT(s)
              #endif /* UIP_STATISTICS == 1 */
 119          
 120          #if UIP_LOGGING == 1
              #define UIP_LOG(m) printf("%s\n", m)
              #else
 123          #define UIP_LOG(m) //LCD_log(m)  //leon;
 124          #endif /* UIP_LOGGING == 1 */
 125          
 126          /*-----------------------------------------------------------------------------------*/
 127          void
 128          uip_init(void)
 129          {
 130   1        for(c = 0; c < UIP_LISTENPORTS; ++c) {
 131   2          uip_listenports[c] = 0;
 132   2        }
 133   1        for(c = 0; c < UIP_CONNS; ++c) {
 134   2          uip_conns[c].tcpstateflags = CLOSED;
 135   2        }
 136   1      #if UIP_ACTIVE_OPEN
                lastport = 1024;
              #endif /* UIP_ACTIVE_OPEN */
 139   1      }
 140          /*-----------------------------------------------------------------------------------*/
 141          #if UIP_ACTIVE_OPEN
              struct uip_conn *
              uip_connect(u16_t *ripaddr, u16_t rport)
              {
                struct uip_conn *conn;
                
                /* Find an unused local port. */
               again:
                ++lastport;
              
                if(lastport >= 32000) {
                  lastport = 4096;
                }
                
                for(c = 0; c < UIP_CONNS; ++c) {
                  if(uip_conns[c].tcpstateflags != CLOSED &&
                     uip_conns[c].lport == lastport)
                    goto again;
                }
              
              
                for(c = 0; c < UIP_CONNS; ++c) {
                  if(uip_conns[c].tcpstateflags == CLOSED) 
                    goto found_unused;
                }
                for(c = 0; c < UIP_CONNS; ++c) {
                  if(uip_conns[c].tcpstateflags == TIME_WAIT) 
                    goto found_unused;
                }
                return (void *)0;
                
               found_unused:
              
                conn = &uip_conns[c];
                
                conn->tcpstateflags = SYN_SENT | UIP_OUTSTANDING;
              
                conn->snd_nxt[0] = conn->ack_nxt[0] = iss[0];
C51 COMPILER V7.06   UIP                                                                   04/05/2006 12:13:01 PAGE 4   

                conn->snd_nxt[1] = conn->ack_nxt[1] = iss[1];
                conn->snd_nxt[2] = conn->ack_nxt[2] = iss[2];
                conn->snd_nxt[3] = conn->ack_nxt[3] = iss[3];
              
                if(++conn->ack_nxt[3] == 0) {
                  if(++conn->ack_nxt[2] == 0) {
                    if(++conn->ack_nxt[1] == 0) {
                      ++conn->ack_nxt[0];
                    }
                  }
                }
                
                conn->nrtx = 0;
                conn->timer = 1; /* Send the SYN next time around. */
                conn->lport = htons(lastport);
                conn->rport = htons(rport);
                conn->ripaddr[0] = ripaddr[0];
                conn->ripaddr[1] = ripaddr[1];
                
                return conn;
              }
              #endif /* UIP_ACTIVE_OPEN */
 201          /*-----------------------------------------------------------------------------------*/
 202          void
 203          uip_listen(u16_t port)
 204          {
 205   1        for(c = 0; c < UIP_LISTENPORTS; ++c) {
 206   2          if(uip_listenports[c] == 0) {
 207   3            uip_listenports[c] = htons(port);
 208   3            break;
 209   3          }
 210   2        }
 211   1      }
 212          /*-----------------------------------------------------------------------------------*/
 213          void
 214          uip_process(u8_t flag) 
 215          {
 216   1        uip_appdata = &uip_buf[40 + UIP_LLH_LEN];
 217   1          
 218   1        /* Check if we were invoked because of the perodic timer fireing. */
 219   1        if(flag == UIP_TIMER) {
 220   2          /* Increase the initial sequence number. */
 221   2          if(++iss[3] == 0) {
 222   3            if(++iss[2] == 0) {
 223   4              if(++iss[1] == 0) {
 224   5                ++iss[0];
 225   5              }
 226   4            }
 227   3          }    
 228   2          uip_len = 0;
 229   2          if(uip_conn->tcpstateflags == TIME_WAIT ||
 230   2             uip_conn->tcpstateflags == FIN_WAIT_2) {
 231   3            ++(uip_conn->timer);
 232   3            if(uip_conn->timer == UIP_TIME_WAIT_TIMEOUT) {
 233   4              uip_conn->tcpstateflags = CLOSED;
 234   4            }
 235   3          } else if(uip_conn->tcpstateflags != CLOSED) {
 236   3            /* If the connection has outstanding data, we increase the
 237   3               connection's timer and see if it has reached the RTO value
 238   3               in which case we retransmit. */
 239   3            if(uip_conn->tcpstateflags & UIP_OUTSTANDING) {
 240   4              --(uip_conn->timer);
C51 COMPILER V7.06   UIP                                                                   04/05/2006 12:13:01 PAGE 5   

 241   4              if(uip_conn->timer == 0) {
 242   5      
 243   5                if(uip_conn->nrtx == UIP_MAXRTX) {
 244   6                  uip_conn->tcpstateflags = CLOSED;
 245   6      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -