📄 uip.lst
字号:
221 void
222 uip_unlisten(u16_t port) //关闭监听端口
223 {
224 for(c = 0; c < UIP_LISTENPORTS; ++c) {
225 if(uip_listenports[c] == port) {
226 uip_listenports[c] = 0;
227 return;
228 }
229 }
230 }
231 -----------------------------------------------------------------------------------------------*/
232 void
233 uip_listen(u16_t port) //创建新的端口
234 {
235 1 for(c = 0; c < UIP_LISTENPORTS; ++c) {
236 2 if(uip_listenports[c] == 0) {
237 3 uip_listenports[c] = port;
238 3 return;
239 3 }
240 2 }
241 1 }
C51 COMPILER V8.08 UIP 08/22/2008 14:32:51 PAGE 5
242 /*----------------------------------------------------------------------------------------------*/
243
244
245 /*---------------------------------------------------------------------------------------------------*/
246 static void
247 uip_add_rcv_nxt(u16_t n) //想要接收下个的序列号
248 {
249 1 uip_add32(uip_conn->rcv_nxt, n); //产生这个序列号的函数
250 1 uip_conn->rcv_nxt[0] = uip_acc32[0];
251 1 uip_conn->rcv_nxt[1] = uip_acc32[1];
252 1 uip_conn->rcv_nxt[2] = uip_acc32[2];
253 1 uip_conn->rcv_nxt[3] = uip_acc32[3];
254 1 }
255 /*----------------------------------------------------------------------------------------------------*/
256 void
257 uip_process(u8_t flag)
258 {
259 1 struct uip_conn xdata *uip_connr = uip_conn; //目前的连接
260 1
261 1 uip_appdata = &uip_buf[40 + UIP_LLH_LEN]; // uip_appdata首地址 //add5
262 1
263 1
264 1 /* Check if we were invoked because of the perodic timer fireing.未接到数据*/
265 1 if(flag == UIP_TIMER)
266 1 {
267 2 /* Increase the initial sequence number. */
268 2 if(++iss[3] == 0)
269 2 { if(++iss[2] == 0)
270 3 { if(++iss[1] == 0)
271 4 { ++iss[0];
272 5 }
273 4 }
274 3 }
275 2 uip_len = 0; //无数据
276 2
277 2 if(uip_connr->tcpstateflags == TIME_WAIT || //判断uip_connr->tcpstateflags
278 2 uip_connr->tcpstateflags == FIN_WAIT_2)
279 2 { ++(uip_connr->timer);
280 3 if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT)
281 3 { uip_connr->tcpstateflags = CLOSED; //超时,中断连接
282 4 }
283 3 }
284 2 else if(uip_connr->tcpstateflags != CLOSED)
285 2 //判断uip_connr->tcpstateflags
286 2 /* If the connection has outstanding data, we increase the
287 2 connection's timer and see if it has reached the RTO value
288 2 in which case we retransmit. */
289 2 { if(uip_outstanding(uip_connr)) //uip_outstanding(conn)=((conn)->len)
290 3 {
291 4 if((uip_connr->timer == 3)||(uip_connr->timer == 1))
292 4 {Timer0on();} //add6
293 4 else
294 4 if(uip_connr->timer-- == 0)
295 4 {
296 5 if(uip_connr->nrtx == UIP_MAXRTX || //最后一次重传的次数
297 5 ((uip_connr->tcpstateflags == SYN_SENT ||
298 5 uip_connr->tcpstateflags == SYN_RCVD) &&
299 5 uip_connr->nrtx == UIP_MAXSYNRTX))
300 5 {
301 6 uip_connr->tcpstateflags = CLOSED; //关闭的关键 add5
302 6
303 6 /* We call UIP_APPCALL() with uip_flags set to
C51 COMPILER V8.08 UIP 08/22/2008 14:32:51 PAGE 6
304 6 UIP_TIMEDOUT to inform the application that the
305 6 connection has timed out. */
306 6 uip_flags = UIP_TIMEDOUT;
307 6 UIP_APPCALL();
308 6 //不经过此地add8
309 6 /* We also send a reset packet to the remote host. */ //发送一个重来的包给远程主机
310 6 BUF->flags = TCP_RST | TCP_ACK; //TCP_ACK=0x10;TCP_RST=0x04
311 6 goto tcp_send_nodata;
312 6 }
313 5
314 5 /* Exponential backoff. */
315 5 uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4? //UIP_RT0和timer的关系?
316 5 4:
317 5 uip_connr->nrtx);
318 5
319 5 if(uip_connr->timer!=0)
320 5 {Timer0on();} //add6
321 5 ++(uip_connr->nrtx);
322 5
323 5 /* Ok, so we need to retransmit. We do this differently
324 5 depending on which state we are in. In ESTABLISHED, we
325 5 call upon the application so that it may prepare the
326 5 data for the retransmit. In SYN_RCVD, we resend the
327 5 SYNACK that we sent earlier and in LAST_ACK we have to
328 5 retransmit our FINACK. */
329 5 UIP_STAT(++uip_stat.tcp.rexmit); //UIP_STAT(s)=s
330 5 switch(uip_connr->tcpstateflags & TS_MASK)
331 5 { //TS_TASK=0x0f;
332 6 case SYN_RCVD: //add5 2次
333 6 /* In the SYN_RCVD state, we should retransmit our
334 6 SYNACK. */
335 6 goto tcp_send_synack;
336 6
337 6 #if UIP_ACTIVE_OPEN
338 6 case SYN_SENT:
339 6 /* In the SYN_SENT state, we retransmit out SYN. */
340 6 BUF->flags = 0;
341 6 goto tcp_send_syn;
342 6 #endif /* UIP_ACTIVE_OPEN */
343 6
344 6 case ESTABLISHED:
345 6 /* In the ESTABLISHED state, we call upon the application
346 6 to do the actual retransmit after which we jump into
347 6 the code for sending out the packet (the apprexmit
348 6 label). */
349 6 uip_len = 0;
350 6 uip_slen = 0;
351 6 uip_flags = UIP_REXMIT;
352 6 UIP_APPCALL();
353 6 goto apprexmit;
354 6
355 6 case FIN_WAIT_1:
356 6 case CLOSING:
357 6 case LAST_ACK: //发送完经过
358 6 /* In all these states we should retransmit a FINACK. */
359 6 goto tcp_send_finack;
360 6 }
361 5 }
362 4
363 4 }
364 3 else if((uip_connr->tcpstateflags & TS_MASK) == ESTABLISHED)
365 3 {
C51 COMPILER V8.08 UIP 08/22/2008 14:32:51 PAGE 7
366 4 //判断uip_connr->tcpstateflags
367 4 /* If there was no need for a retransmission, we poll the
368 4 application for new data. */
369 4 uip_len = 0;
370 4 uip_slen = 0;
371 4 uip_flags = UIP_POLL;
372 4 UIP_APPCALL();
373 4 goto appsend;
374 4 }
375 3 }
376 2 goto drop; //drop表示结束
377 2 }
378 1
379 1 /* This is where the input processing starts. 接收包处理*************************************************
-*****/
380 1 UIP_STAT(++uip_stat.ip.recv);
381 1
382 1
383 1 /* Start of IPv4 input header processing code. */
384 1
385 1 /* Check validity of the IP header. */
386 1 if(BUF->vhl != 0x45) { /* IP version and header length. */
387 2 UIP_STAT(++uip_stat.ip.drop);
388 2 UIP_STAT(++uip_stat.ip.vhlerr);
389 2 UIP_LOG("ip: invalid version or header length.");
390 2 goto drop;
391 2 }
392 1
393 1 /* Check the size of the packet. If the size reported to us in
394 1 uip_len doesn't match the size reported in the IP header, there
395 1 has been a transmission error and we drop the packet. */
396 1
397 1 if(BUF->len[0] != (uip_len >> 8)) { /* IP length, high byte. */
398 2 //uip_len里面的长度是整个的长度减去以太网包的长度
399 2 uip_len = (uip_len & 0xff) | (BUF->len[0] << 8); //重新把包的大小给uip_len
400 2 }
401 1 if(BUF->len[1] != (uip_len & 0xff)) { /* IP length, low byte. */
402 2 uip_len = (uip_len & 0xff00) | BUF->len[1]; //重新把包的大小给uip_len
403 2 }
404 1
405 1 /* Check the fragment flag. */
406 1 if((BUF->ipoffset[0] & 0x3f) != 0 ||
407 1 BUF->ipoffset[1] != 0) {
408 2 #if UIP_REASSEMBLY //未用到
uip_len = uip_reass();
if(uip_len == 0) {
goto drop;
}
#else
414 2 UIP_STAT(++uip_stat.ip.drop);
415 2 UIP_STAT(++uip_stat.ip.fragerr);
416 2 UIP_LOG("ip: fragment dropped.");
417 2 goto drop;
418 2 #endif /* UIP_REASSEMBLY */
419 2 }
420 1
421 1
422 1
423 1 /* If we are configured to use ping IP address configuration and
424 1 hasn't been assigned an IP address yet, we accept all ICMP
425 1 packets. */
426 1 #if UIP_PINGADDRCONF //未用到
C51 COMPILER V8.08 UIP 08/22/2008 14:32:51 PAGE 8
if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {
if(BUF->proto == UIP_PROTO_ICMP) {
UIP_LOG("ip: possible ping config packet received.");
goto icmp_input;
} else {
UIP_LOG("ip: packet dropped since no address assigned.");
goto drop;
}
}
#endif /* UIP_PINGADDRCONF */
437 1
438 1 /***************** Check if the packet is destined for our IP address. *****************************/
439 1 if(BUF->destipaddr[0] != uip_hostaddr[0]) { //确认地址是不是发给我的
440 2 UIP_STAT(++uip_stat.ip.drop);
441 2 UIP_LOG("ip: packet not for us.");
442 2 goto drop;
443 2 }
444 1 if(BUF->destipaddr[1] != uip_hostaddr[1]) {
445 2 UIP_STAT(++uip_stat.ip.drop);
446 2 UIP_LOG("ip: packet not for us.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -