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

📄 uip.lst

📁 STC51系列的源码
💻 LST
📖 第 1 页 / 共 5 页
字号:
                        opt = uip_buf[40 + UIP_LLH_LEN + c];
                        if(opt == 0x00) {
                          /* End of options. */       
                          break;
                        } else if(opt == 0x01) {
                          ++c;
                          /* NOP option. */
                        } else if(opt == 0x02 &&
                                  uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0x04) {
                          /* An MSS option with the right option length. */
                          tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
                            uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
                          uip_connr->initialmss =
                            uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
              
                          /* And we are done processing options. */
                          break;
                        } else {
                          /* All other options have a length field, so that we easily
                             can skip past them. */
                          if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
                            /* If the length field is zero, the options are malformed
                               and we don't process them further. */
                            break;
                          }
                          c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
                        }      
                      }
                    }
                    uip_connr->tcpstateflags = ESTABLISHED;      
                    uip_connr->rcv_nxt[0] = BUF->seqno[0];
                    uip_connr->rcv_nxt[1] = BUF->seqno[1];
                    uip_connr->rcv_nxt[2] = BUF->seqno[2];
                    uip_connr->rcv_nxt[3] = BUF->seqno[3];
                    uip_add_rcv_nxt(1);
                    uip_flags = UIP_CONNECTED | UIP_NEWDATA;
C51 COMPILER V8.02   UIP                                                                   10/28/2008 15:31:45 PAGE 19  

                    uip_connr->len = 0;
                    uip_len = 0;
                    uip_slen = 0;
                    UIP_APPCALL();
                    goto appsend;
                  }
                  goto reset;
              #endif /* UIP_ACTIVE_OPEN */
1116   2          
1117   2        case ESTABLISHED:
1118   2          /* In the ESTABLISHED state, we call upon the application to feed
1119   2          data into the uip_buf. If the UIP_ACKDATA flag is set, the
1120   2          application should put new data into the buffer, otherwise we are
1121   2          retransmitting an old segment, and the application should put that
1122   2          data into the buffer.
1123   2      
1124   2          If the incoming packet is a FIN, we should close the connection on
1125   2          this side as well, and we send out a FIN and enter the LAST_ACK
1126   2          state. We require that there is no outstanding data; otherwise the
1127   2          sequence numbers will be screwed up. */
1128   2      
1129   2          if(BUF->flags & TCP_FIN) {
1130   3            if(uip_outstanding(uip_connr)) {
1131   4              goto drop;
1132   4            }
1133   3            uip_add_rcv_nxt(1 + uip_len);      
1134   3            uip_flags = UIP_CLOSE;
1135   3            if(uip_len > 0) {
1136   4              uip_flags |= UIP_NEWDATA;
1137   4            }
1138   3            UIP_APPCALL();
1139   3            uip_connr->len = 1;
1140   3            uip_connr->tcpstateflags = LAST_ACK;
1141   3            uip_connr->nrtx = 0;
1142   3          tcp_send_finack:
1143   3            BUF->flags = TCP_FIN | TCP_ACK;      
1144   3            goto tcp_send_nodata;
1145   3          }
1146   2      
1147   2          /* Check the URG flag. If this is set, the segment carries urgent
1148   2             data that we must pass to the application. */
1149   2          if(BUF->flags & TCP_URG) {
1150   3      #if UIP_URGDATA > 0
1151   3            uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
1152   3            if(uip_urglen > uip_len) {
1153   4              /* There is more urgent data in the next segment to come. */
1154   4              uip_urglen = uip_len;
1155   4            }
1156   3            uip_add_rcv_nxt(uip_urglen);
1157   3            uip_len -= uip_urglen;
1158   3            uip_urgdata = uip_appdata;
1159   3            uip_appdata += uip_urglen;
1160   3          } else {
1161   3            uip_urglen = 0;
1162   3      #endif /* UIP_URGDATA > 0 */
1163   3            uip_appdata += (BUF->urgp[0] << 8) | BUF->urgp[1];
1164   3            uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];
1165   3          }
1166   2          
1167   2          
1168   2          /* If uip_len > 0 we have TCP data in the packet, and we flag this
1169   2             by setting the UIP_NEWDATA flag and update the sequence number
C51 COMPILER V8.02   UIP                                                                   10/28/2008 15:31:45 PAGE 20  

1170   2             we acknowledge. If the application has stopped the dataflow
1171   2             using uip_stop(), we must not accept any data packets from the
1172   2             remote host. */
1173   2          if(uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
1174   3            uip_flags |= UIP_NEWDATA;
1175   3            uip_add_rcv_nxt(uip_len);
1176   3          }
1177   2      
1178   2          /* Check if the available buffer space advertised by the other end
1179   2             is smaller than the initial MSS for this connection. If so, we
1180   2             set the current MSS to the window size to ensure that the
1181   2             application does not send more data than the other end can
1182   2             handle.
1183   2      
1184   2             If the remote host advertises a zero window, we set the MSS to
1185   2             the initial MSS so that the application will send an entire MSS
1186   2             of data. This data will not be acknowledged by the receiver,
1187   2             and the application will retransmit it. This is called the
1188   2             "persistent timer" and uses the retransmission mechanim.
1189   2          */
1190   2          tmp16 = ((u16_t)BUF->wnd[0] << 8) + (u16_t)BUF->wnd[1];
1191   2          if(tmp16 > uip_connr->initialmss ||
1192   2             tmp16 == 0) {
1193   3            tmp16 = uip_connr->initialmss;
1194   3          }
1195   2          uip_connr->mss = tmp16;
1196   2      
1197   2          /* If this packet constitutes an ACK for outstanding data (flagged
1198   2             by the UIP_ACKDATA flag, we should call the application since it
1199   2             might want to send more data. If the incoming packet had data
1200   2             from the peer (as flagged by the UIP_NEWDATA flag), the
1201   2             application must also be notified.
1202   2      
1203   2             When the application is called, the global variable uip_len
1204   2             contains the length of the incoming data. The application can
1205   2             access the incoming data through the global pointer
1206   2             uip_appdata, which usually points 40 bytes into the uip_buf
1207   2             array.
1208   2      
1209   2             If the application wishes to send any data, this data should be
1210   2             put into the uip_appdata and the length of the data should be
1211   2             put into uip_len. If the application don't have any data to
1212   2             send, uip_len must be set to 0. */
1213   2          if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
1214   3            uip_slen = 0;
1215   3            UIP_APPCALL();
1216   3      
1217   3          appsend:
1218   3            
1219   3            if(uip_flags & UIP_ABORT) {
1220   4              uip_slen = 0;
1221   4              uip_connr->tcpstateflags = CLOSED;
1222   4              BUF->flags = TCP_RST | TCP_ACK;
1223   4              goto tcp_send_nodata;
1224   4            }
1225   3      
1226   3            if(uip_flags & UIP_CLOSE) {
1227   4              uip_slen = 0;
1228   4              uip_connr->len = 1;
1229   4              uip_connr->tcpstateflags = FIN_WAIT_1;
1230   4              uip_connr->nrtx = 0;
1231   4              BUF->flags = TCP_FIN | TCP_ACK;
C51 COMPILER V8.02   UIP                                                                   10/28/2008 15:31:45 PAGE 21  

1232   4              goto tcp_send_nodata;   
1233   4            }
1234   3      
1235   3            /* If uip_slen > 0, the application has data to be sent. */
1236   3            if(uip_slen > 0) {
1237   4      
1238   4              /* If the connection has acknowledged data, the contents of
1239   4                 the ->len variable should be discarded. */ 
1240   4              if((uip_flags & UIP_ACKDATA) != 0) {
1241   5                uip_connr->len = 0;
1242   5              }
1243   4      
1244   4              /* If the ->len variable is non-zero the connection has
1245   4                 already data in transit and cannot send anymore right
1246   4                 now. */
1247   4              if(uip_connr->len == 0) {
1248   5      
1249   5                /* The application cannot send more than what is allowed by
1250   5                   the mss (the minumum of the MSS and the available
1251   5                   window). */
1252   5                if(uip_slen > uip_connr->mss) {
1253   6                  uip_slen = uip_connr->mss;
1254   6                }
1255   5      
1256   5                /* Remember how much data we send out now so that we know
1257   5                   when everything has been acknowledged. */
1258   5                uip_connr->len = uip_slen;
1259   5              } else {
1260   5      
1261   5                /* If the application already had unacknowledged data, we
1262   5                   make sure that the application does not send (i.e.,
1263   5                   retransmit) out more than it previously sent out. */
1264   5                uip_slen = uip_connr->len;
1265   5              }
1266   4            } else {
1267   4              uip_connr->len = 0;
1268   4            }
1269   3            uip_connr->nrtx = 0;
1270   3          apprexmit:
1271   3            uip_appdata = uip_sappdata;
1272   3            
1273   3            /* If the application has data to be sent, or if the incoming
1274   3               packet had new data in it, we must send out a packet. */
1275   3            if(uip_slen > 0 && uip_connr->len > 0) {
1276   4              /* Add the length of the IP and TCP headers. */
1277   4              uip_len = uip_connr->len + UIP_TCPIP_HLEN;
1278   4              /* We always set the ACK flag in response packets. */
1279   4              BUF->flags = TCP_ACK | TCP_PSH;
1280   4              /* Send the packet. */
1281   4              goto tcp_send_noopts;
1282   4            }
1283   3            /* If there is no data to send, just send out a pure ACK if
1284   3               there is newdata. */
1285   3            if(uip_flags & UIP_NEWDATA) {
1286   4              uip_len = UIP_TCPIP_HLEN;
1287   4              BUF->flags = TCP_ACK;
1288   4              goto tcp_send_noopts;
1289   4            }
1290   3          }
1291   2          goto drop;
1292   2        case LAST_ACK:
1293   2          /* We can close this connection if the peer has acknowledged our
C51 COMPILER V8.02   UIP                                                                   10/28/2008 15:31:45 PAGE 22  

1294   2             FIN. This is indicated by the UIP_ACKDATA flag. */     
1295   2          if(uip_flags & UIP_ACKDATA) {
1296   3            uip_connr->tcpstateflags = CLOSED;
1297   3            uip_flags = UIP_CLOSE;
1298   3            UIP_APPCALL();
1299   3          }
1300   2          break;
1301   2          
1302   2        case FIN_WAIT_1:
1303   2          /* The application has closed the connection, but the remote host
1304   2             hasn't closed its end yet. Thus we do nothing but wait for a
1305   2             FIN from the other side. */
1306   2          if(uip_len > 0) {
1307   3            uip_add_rcv_nxt(uip_len);
1308   3          }
1309   2          if(BUF->flags & TCP_FIN) {
1310   3            if(uip_flags & UIP_ACKDATA) {
1311   4              uip_connr->tcpstateflags = TIME_WAIT;
1312   4              uip_connr->timer = 0;
1313   4              uip_connr->len = 0;
1314   4            } else {
1315   4              uip_connr->tcpstateflags = CLOSING;
1316   4            }
1317   3            uip_add_rcv_nxt(1);
1318   3            uip_flags = UIP_CLOSE;
1319   3            UIP_APPCALL();
1320   3            goto tcp_send_ack;
1321   3          } else if(uip_flags & UIP_ACKDATA) {
1322   3            uip_connr->tcpstateflags = FIN_WAIT_2;
1323   3            uip_connr->len = 0;
1324   3            goto drop;
1325   3          }
1326   2          if(uip_len > 0) {
1327   3            goto tcp_send_ack;
1328   3          }
1329   2          goto drop;
1330   2            
1331   2        case FIN_WAIT_2:
1332   2          if(uip_len > 0) {
1333   3            uip_add_rcv_nxt(uip_len);
1334   3          }
1335   2          if(BUF->flags & TCP_FIN) {
1336   3            uip_connr->tcpstateflags = TIME_WAIT;
1337   3            uip_connr->timer = 0;
1338   3           

⌨️ 快捷键说明

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