?? uip.lst
字號(hào):
conn = &uip_conns[c];
conn->tcpstateflags = SYN_SENT | UIP_OUTSTANDING;
conn->snd_nxt[0] = conn->ack_nxt[0] = iss[0];
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 */
238 /*-----------------------------------------------------------------------------------*/
239 void
240 uip_listen(u16_t port)
241 {
C51 COMPILER V7.08 UIP 12/26/2003 07:27:14 PAGE 5
242 1 for(c = 0; c < UIP_LISTENPORTS; ++c) {
243 2 if(uip_listenports[c] == 0) {
244 3 uip_listenports[c] = htons(port);
245 3 break;
246 3 }
247 2 }
248 1 }
249 /*-----------------------------------------------------------------------------------*/
250 void
251 uip_process(u8_t flag)
252 {
253 1 uip_appdata = &uip_buf[40 + UIP_LLH_LEN];
254 1
255 1 /* Check if we were invoked because of the perodic timer fireing. */
256 1 if(flag == UIP_TIMER)
257 1 {
258 2 /* Increase the initial sequence number. */
259 2 if(++iss[3] == 0)
260 2 {
261 3 if(++iss[2] == 0)
262 3 {
263 4 if(++iss[1] == 0)
264 4 {
265 5 ++iss[0];
266 5 }
267 4 }
268 3 }
269 2 uip_len = 0;
270 2 if(uip_conn->tcpstateflags == TIME_WAIT ||
271 2 uip_conn->tcpstateflags == FIN_WAIT_2)
272 2 {
273 3 ++(uip_conn->timer);
274 3 if(uip_conn->timer == UIP_TIME_WAIT_TIMEOUT)
275 3 {
276 4 uip_conn->tcpstateflags = CLOSED;
277 4 }
278 3 } else if(uip_conn->tcpstateflags != CLOSED)
279 2 {
280 3 /* If the connection has outstanding data, we increase the
281 3 connection's timer and see if it has reached the RTO value
282 3 in which case we retransmit. */
283 3 if(uip_conn->tcpstateflags & UIP_OUTSTANDING)
284 3 {
285 4 --(uip_conn->timer);
286 4 if(uip_conn->timer == 0)
287 4 {
288 5 if(uip_conn->nrtx == UIP_MAXRTX)
289 5 {
290 6 uip_conn->tcpstateflags = CLOSED;
291 6
292 6 /* We call UIP_APPCALL() with uip_flags set to
293 6 UIP_TIMEDOUT to inform the application that the
294 6 connection has timed out. */
295 6 uip_flags = UIP_TIMEDOUT;
296 6 UIP_APPCALL();
297 6
298 6 /* We also send a reset packet to the remote host. */
299 6 BUF->flags = TCP_RST | TCP_ACK;
300 6 goto tcp_send_nodata;
301 6 }
302 5
303 5 /* Exponential backoff. */
C51 COMPILER V7.08 UIP 12/26/2003 07:27:14 PAGE 6
304 5 uip_conn->timer = UIP_RTO << (uip_conn->nrtx > 4? 4: uip_conn->nrtx);
305 5
306 5 ++(uip_conn->nrtx);
307 5
308 5 /* Ok, so we need to retransmit. We do this differently
309 5 depending on which state we are in. In ESTABLISHED, we
310 5 call upon the application so that it may prepare the
311 5 data for the retransmit. In SYN_RCVD, we resend the
312 5 SYNACK that we sent earlier and in LAST_ACK we have to
313 5 retransmit our FINACK. */
314 5 UIP_STAT(++uip_stat.tcp.rexmit);
315 5 switch(uip_conn->tcpstateflags & TS_MASK)
316 5 {
317 6 case SYN_RCVD:
318 6 /* In the SYN_RCVD state, we should retransmit our
319 6 SYNACK. */
320 6 goto tcp_send_synack;
321 6
322 6 #if UIP_ACTIVE_OPEN
case SYN_SENT:
/* In the SYN_SENT state, we retransmit out SYN. */
BUF->flags = 0;
goto tcp_send_syn;
#endif /* UIP_ACTIVE_OPEN */
328 6
329 6 case ESTABLISHED:
330 6 /* In the ESTABLISHED state, we call upon the application
331 6 to do the actual retransmit after which we jump into
332 6 the code for sending out the packet (the apprexmit
333 6 label). */
334 6 uip_len = 0;
335 6 uip_flags = UIP_REXMIT;
336 6 UIP_APPCALL();
337 6 goto apprexmit;
338 6
339 6 case FIN_WAIT_1:
340 6 case CLOSING:
341 6 case LAST_ACK:
342 6 /* In all these states we should retransmit a FINACK. */
343 6 goto tcp_send_finack;
344 6
345 6 }
346 5 }
347 4 } else if((uip_conn->tcpstateflags & TS_MASK) == ESTABLISHED)
348 3 {
349 4 /* If there was no need for a retransmission, we poll the
350 4 application for new data. */
351 4 uip_len = 0;
352 4 uip_flags = UIP_POLL;
353 4 UIP_APPCALL();
354 4 goto appsend;
355 4 }
356 3 }
357 2 goto drop;
358 2 }
359 1
360 1 /* This is where the input processing starts. */
361 1 UIP_STAT(++uip_stat.ip.recv);
362 1
363 1 /* Check validity of the IP header. */
364 1 if(BUF->vhl != 0x45) { /* IP version and header length. */
365 2 UIP_STAT(++uip_stat.ip.drop);
C51 COMPILER V7.08 UIP 12/26/2003 07:27:14 PAGE 7
366 2 UIP_STAT(++uip_stat.ip.vhlerr);
367 2 UIP_LOG("ip: invalid version or header length.");
368 2 goto drop;
369 2 }
370 1
371 1 /* Check the size of the packet. If the size reported to us in
372 1 uip_len doesn't match the size reported in the IP header, there
373 1 has been a transmission error and we drop the packet. */
374 1
375 1 #if UIP_BUFSIZE > 255
376 1
377 1 if(BUF->len[0] != (uip_len >> 8)) {
378 2 UIP_STAT(++uip_stat.ip.drop);
379 2 UIP_STAT(++uip_stat.ip.hblenerr);
380 2 UIP_LOG("ip: invalid length, high byte.");
381 2 /* IP length, high byte. */
382 2 goto drop;
383 2 }
384 1 if(BUF->len[1] != (uip_len & 0xff)) {
385 2 UIP_STAT(++uip_stat.ip.drop);
386 2 UIP_STAT(++uip_stat.ip.lblenerr);
387 2 UIP_LOG("ip: invalid length, low byte.");
388 2 /* IP length, low byte. */
389 2 goto drop;
390 2 }
391 1 #else
if(BUF->len[0] != 0) { /* IP length, high byte. */
UIP_STAT(++uip_stat.ip.drop);
UIP_STAT(++uip_stat.ip.hblenerr);
UIP_LOG("ip: invalid length, high byte.");
goto drop;
}
if(BUF->len[1] != uip_len) { /* IP length, low byte. */
UIP_STAT(++uip_stat.ip.drop);
UIP_STAT(++uip_stat.ip.lblenerr);
UIP_LOG("ip: invalid length, low byte.");
goto drop;
}
#endif /* UIP_BUFSIZE > 255 */
405 1
406 1 if(BUF->ipoffset[0] & 0x3f) { /* We don't allow IP fragments. */
407 2 UIP_STAT(++uip_stat.ip.drop);
408 2 UIP_STAT(++uip_stat.ip.fragerr);
409 2 UIP_LOG("ip: fragment dropped.");
410 2 goto drop;
411 2 }
412 1
413 1 /* Check if the packet is destined for our IP address. */
414 1 if(BUF->destipaddr[0] != htons(((u16_t)UIP_IPADDR0 << 8) | UIP_IPADDR1)) {
415 2 UIP_STAT(++uip_stat.ip.drop);
416 2 UIP_LOG("ip: packet not for us.");
417 2 goto drop;
418 2 }
419 1 if(BUF->destipaddr[1] != htons(((u16_t)UIP_IPADDR2 << 8) | UIP_IPADDR3)) {
420 2 UIP_STAT(++uip_stat.ip.drop);
421 2 UIP_LOG("ip: packet not for us.");
422 2 goto drop;
423 2 }
424 1
425 1 if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
426 2 checksum. */
427 2 UIP_STAT(++uip_stat.ip.drop);
C51 COMPILER V7.08 UIP 12/26/2003 07:27:14 PAGE 8
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -