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

📄 uip.s

📁 uIP是免费的TCP/IP协议栈,我们将它移植到我们的AVR以太网开发板中
💻 S
📖 第 1 页 / 共 5 页
字号:
	std z+2,R2
	.dbline 268
;   
;   return conn;
	movw R16,R10
	.dbline -2
L17:
	xcall pop_gset5x
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym r cconn 12 pS[uip_conn]
	.dbsym r conn 10 pS[uip_conn]
	.dbsym r rport 14 s
	.dbsym l ripaddr 6 ps
	.dbend
	.dbfunc e uip_unlisten _uip_unlisten fV
;           port -> R16,R17
	.even
_uip_unlisten::
	.dbline -1
	.dbline 316
; }
; #endif /* UIP_ACTIVE_OPEN */
; /*-----------------------------------------------------------------------------------*/
; #if UIP_UDP
; struct uip_udp_conn *
; uip_udp_new(u16_t *ripaddr, u16_t rport)
; {
;   register struct uip_udp_conn *conn;
;   
;   /* Find an unused local port. */
;  again:
;   ++lastport;
; 
;   if(lastport >= 32000) {
;     lastport = 4096;
;   }
;   
;   for(c = 0; c < UIP_UDP_CONNS; ++c) {
;     if(uip_udp_conns[c].lport == lastport) {
;       goto again;
;     }
;   }
; 
; 
;   conn = 0;
;   for(c = 0; c < UIP_UDP_CONNS; ++c) {
;     if(uip_udp_conns[c].lport == 0) {
;       conn = &uip_udp_conns[c]; 
;       break;
;     }
;   }
; 
;   if(conn == 0) {
;     return 0;
;   }
;   
;   conn->lport = HTONS(lastport);
;   conn->rport = HTONS(rport);
;   conn->ripaddr[0] = ripaddr[0];
;   conn->ripaddr[1] = ripaddr[1];
;   
;   return conn;
; }
; #endif /* UIP_UDP */
; /*-----------------------------------------------------------------------------------*/
; void
; uip_unlisten(u16_t port)
; {
	.dbline 317
	clr R2
	sts _c,R2
	xjmp L47
L44:
	.dbline 317
;   for(c = 0; c < UIP_LISTENPORTS; ++c) {
	.dbline 318
;     if(uip_listenports[c] == port) {
	lds R2,_c
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_uip_listenports
	ldi R25,>_uip_listenports
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	cp R2,R16
	cpc R3,R17
	brne L48
	.dbline 318
	.dbline 319
;       uip_listenports[c] = 0;
	lds R2,_c
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_uip_listenports
	ldi R25,>_uip_listenports
	add R30,R24
	adc R31,R25
	clr R2
	clr R3
	std z+1,R3
	std z+0,R2
	.dbline 320
;       return;
	xjmp L43
L48:
	.dbline 322
L45:
	.dbline 317
	lds R24,_c
	subi R24,255    ; addi 1
	sts _c,R24
L47:
	.dbline 317
	lds R24,_c
	cpi R24,10
	brlo L44
	.dbline -2
L43:
	.dbline 0 ; func end
	ret
	.dbsym r port 16 s
	.dbend
	.dbfunc e uip_listen _uip_listen fV
;           port -> R16,R17
	.even
_uip_listen::
	.dbline -1
	.dbline 327
;     }
;   }
; }
; /*-----------------------------------------------------------------------------------*/
; void
; uip_listen(u16_t port)
; {
	.dbline 328
	clr R2
	sts _c,R2
	xjmp L54
L51:
	.dbline 328
;   for(c = 0; c < UIP_LISTENPORTS; ++c) {
	.dbline 329
;     if(uip_listenports[c] == 0) {
	lds R2,_c
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_uip_listenports
	ldi R25,>_uip_listenports
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	tst R2
	brne L55
	tst R3
	brne L55
X3:
	.dbline 329
	.dbline 330
;       uip_listenports[c] = port;
	lds R2,_c
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_uip_listenports
	ldi R25,>_uip_listenports
	add R30,R24
	adc R31,R25
	std z+1,R17
	std z+0,R16
	.dbline 331
;       return;
	xjmp L50
L55:
	.dbline 333
L52:
	.dbline 328
	lds R24,_c
	subi R24,255    ; addi 1
	sts _c,R24
L54:
	.dbline 328
	lds R24,_c
	cpi R24,10
	brlo L51
	.dbline -2
L50:
	.dbline 0 ; func end
	ret
	.dbsym r port 16 s
	.dbend
	.dbfunc s uip_add_rcv_nxt _uip_add_rcv_nxt fV
;              n -> R10,R11
	.even
_uip_add_rcv_nxt:
	xcall push_gset3x
	movw R10,R16
	.dbline -1
	.dbline 471
;     }
;   }
; }
; /*-----------------------------------------------------------------------------------*/
; /* XXX: IP fragment reassembly: not well-tested. */
; 
; #if UIP_REASSEMBLY
; #define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
; static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
; static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
; static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
; 				    0x0f, 0x07, 0x03, 0x01};
; static u16_t uip_reasslen;
; static u8_t uip_reassflags;
; #define UIP_REASS_FLAG_LASTFRAG 0x01
; static u8_t uip_reasstmr;
; 
; #define IP_HLEN 20
; #define IP_MF   0x20
; 
; static u8_t
; uip_reass(void)
; {
;   u16_t offset, len;
;   u16_t i;
; 
;   /* If ip_reasstmr is zero, no packet is present in the buffer, so we
;      write the IP header of the fragment into the reassembly
;      buffer. The timer is updated with the maximum age. */
;   if(uip_reasstmr == 0) {
;     memcpy(uip_reassbuf, &BUF->vhl, IP_HLEN);
;     uip_reasstmr = UIP_REASS_MAXAGE;
;     uip_reassflags = 0;
;     /* Clear the bitmap. */
;     memset(uip_reassbitmap, sizeof(uip_reassbitmap), 0);
;   }
; 
;   /* Check if the incoming fragment matches the one currently present
;      in the reasembly buffer. If so, we proceed with copying the
;      fragment into the buffer. */
;   if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&
;      BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&
;      BUF->destipaddr[0] == FBUF->destipaddr[0] &&
;      BUF->destipaddr[1] == FBUF->destipaddr[1] &&
;      BUF->ipid[0] == FBUF->ipid[0] &&
;      BUF->ipid[1] == FBUF->ipid[1]) {
; 
;     len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;
;     offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8;
; 
;     /* If the offset or the offset + fragment length overflows the
;        reassembly buffer, we discard the entire packet. */
;     if(offset > UIP_REASS_BUFSIZE ||
;        offset + len > UIP_REASS_BUFSIZE) {
;       uip_reasstmr = 0;
;       goto nullreturn;
;     }
; 
;     /* Copy the fragment into the reassembly buffer, at the right
;        offset. */
;     memcpy(&uip_reassbuf[IP_HLEN + offset],
; 	   (char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
; 	   len);
;       
;     /* Update the bitmap. */
;     if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
;       /* If the two endpoints are in the same byte, we only update
; 	 that byte. */
; 	     
;       uip_reassbitmap[offset / (8 * 8)] |=
; 	     bitmap_bits[(offset / 8 ) & 7] &
; 	     ~bitmap_bits[((offset + len) / 8 ) & 7];
;     } else {
;       /* If the two endpoints are in different bytes, we update the
; 	 bytes in the endpoints and fill the stuff inbetween with
; 	 0xff. */
;       uip_reassbitmap[offset / (8 * 8)] |=
; 	bitmap_bits[(offset / 8 ) & 7];
;       for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
; 	uip_reassbitmap[i] = 0xff;
;       }      
;       uip_reassbitmap[(offset + len) / (8 * 8)] |=
; 	~bitmap_bits[((offset + len) / 8 ) & 7];
;     }
;     
;     /* If this fragment has the More Fragments flag set to zero, we
;        know that this is the last fragment, so we can calculate the
;        size of the entire packet. We also set the
;        IP_REASS_FLAG_LASTFRAG flag to indicate that we have received
;        the final fragment. */
; 
;     if((BUF->ipoffset[0] & IP_MF) == 0) {
;       uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
;       uip_reasslen = offset + len;
;     }
;     
;     /* Finally, we check if we have a full packet in the buffer. We do
;        this by checking if we have the last fragment and if all bits
;        in the bitmap are set. */
;     if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
;       /* Check all bytes up to and including all but the last byte in
; 	 the bitmap. */
;       for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
; 	if(uip_reassbitmap[i] != 0xff) {
; 	  goto nullreturn;
; 	}
;       }
;       /* Check the last byte in the bitmap. It should contain just the
; 	 right amount of bits. */
;       if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=
; 	 (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
; 	goto nullreturn;
;       }
; 
;       /* If we have come this far, we have a full packet in the
; 	 buffer, so we allocate a pbuf and copy the packet into it. We
; 	 also reset the timer. */
;       uip_reasstmr = 0;
;       memcpy(BUF, FBUF, uip_reasslen);
; 
;       /* Pretend to be a "normal" (i.e., not fragmented) IP packet
; 	 from now on. */
;       BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
;       BUF->len[0] = uip_reasslen >> 8;
;       BUF->len[1] = uip_reasslen & 0xff;
;       BUF->ipchksum = 0;
;       BUF->ipchksum = ~(uip_ipchksum());
; 
;       return uip_reasslen;
;     }
;   }
; 
;  nullreturn:
;   return 0;
; }
; #endif /* UIP_REASSEMBL */
; /*-----------------------------------------------------------------------------------*/
; static void
; uip_add_rcv_nxt(u16_t n)
; {
	.dbline 472
;   uip_add32(uip_conn->rcv_nxt, n);
	movw R18,R10
	lds R16,_uip_conn
	lds R17,_uip_conn+1
	subi R16,248  ; offset = 8
	sbci R17,255
	xcall _uip_add32
	.dbline 473
;   uip_conn->rcv_nxt[0] = uip_acc32[0];
	lds R2,_uip_acc32
	lds R30,_uip_conn
	lds R31,_uip_conn+1
	std z+8,R2
	.dbline 474
;   uip_conn->rcv_nxt[1] = uip_acc32[1];
	lds R2,_uip_acc32+1
	lds R30,_uip_conn
	lds R31,_uip_conn+1
	std z+9,R2
	.dbline 475
;   uip_conn->rcv_nxt[2] = uip_acc32[2];
	lds R2,_uip_acc32+2
	lds R30,_uip_conn
	lds R31,_uip_conn+1
	std z+10,R2
	.dbline 476
;   uip_conn->rcv_nxt[3] = uip_acc32[3];
	lds R2,_uip_acc32+3
	lds R30,_uip_conn
	lds R31,_uip_conn+1
	std z+11,R2
	.dbline -2
L57:
	xcall pop_gset3x
	.dbline 0 ; func end
	ret
	.dbsym r n 10 s
	.dbend
	.dbfunc e uip_process _uip_process fV
;              m -> R14
;      uip_connr -> y+0
;           flag -> R10
	.even
_uip_process::
	xcall push_gset5x
	mov R10,R16
	sbiw R28,2
	.dbline -1
	.dbline 481
; }
; /*-----------------------------------------------------------------------------------*/
; void
; uip_process(u8_t flag)
; {
	.dbline 482
;   register struct uip_conn *uip_connr = uip_conn;
	lds R2,_uip_conn
	lds R3,_uip_conn+1
	std y+1,R3
	std y+0,R2
	.dbline 484
;   
;   uip_appdata = &uip_buf[40 + UIP_LLH_LEN];
	ldi R24,<_uip_buf+54
	ldi R25,>_uip_buf+54
	sts _uip_appdata+1,R25
	sts _uip_appdata,R24
	.dbline 488
; 
;   
;   /* Check if we were invoked because of the perodic timer fireing. */
;   if(flag == UIP_TIMER) {
	mov R24,R10
	cpi R24,2
	breq X31
	xjmp L63
X31:
	.dbline 488
	.dbline 495
; #if UIP_REASSEMBLY
;     if(uip_reasstmr != 0) {
;       --uip_reasstmr;
;     }
; #endif /* UIP_REASSEMBLY */
;     /* Increase the initial sequence number. */
;     if(++iss[3] == 0) {
	lds R24,_iss+3
	subi R24,255    ; addi 1
	mov R2,R24
	sts _iss+3,R2
	tst R24
	brne L65
	.dbline 495
	.dbline 496
;       if(++iss[2] == 0) {
	lds R24,_iss+2
	subi R24,255    ; addi 1
	mov R2,R24
	sts _iss+2,R2
	tst R24
	brne L68
	.dbline 496
	.dbline 497
; 	if(++iss[1] == 0) {
	lds R24,_iss+1
	subi R24,255    ; addi 1
	mov R2,R24
	sts _iss+1,R2
	tst R24
	brne L71
	.dbline 497
	.dbline 498
; 	  ++iss[0];
	lds R24,_iss
	subi R24,255    ; addi 1
	sts _iss,R24
	.dbline 499
; 	}
L71:
	.dbline 500
;       }
L68:
	.dbline 501
;     }    
L65:
	.dbline 502
;     uip_len = 0;
	clr R2
	clr R3
	sts _uip_len+1,R3
	sts _uip_len,R2
	.dbline 503
;     if(uip_connr->tcpstateflags == TIME_WAIT ||
	ldd R30,y+0
	ldd R31,y+1
	ldd R2,z+25
	clr R3
	mov R24,R2
	cpi R24,7
	breq L76
	cpi R24,5
	brne L74
L76:
	.dbline 504
;        uip_connr->tcpstateflags == FIN_WAIT_2) {
	.dbline 505
;       ++(uip_connr->timer);
	ldd R24,y+0
	ldd R25,y+1
	adiw R24,26
	movw R30,R24
	ldd R24,z+0
	subi R24,255    ; addi 1
	std z+0,R24
	.dbline 506
;       if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {
	ldd R30,y+0
	ldd R31,y+1
	ldd R24,z+26
	cpi R24,120
	breq X32
	xjmp L112
X32:
	.dbline 506
	.dbline 507
; 	uip_connr->tcpstateflags = CLOSED;
	clr R2
	ldd R30,y+0
	ldd R31,y+1
	std z+25,R2
	.dbline 508
;       }
	.dbline 509
	xjmp L112
L74:
	.dbline 509
;     } else if(uip_connr->tcpstateflags != CLOSED) {
	ldd R30,y+0
	ldd R31,y+1
	ldd R2,z+25
	tst R2
	brne X33
	xjmp L112
X33:
	.dbline 509
	.dbline 513
;       /* If the connection has outstanding data, we increase the
; 	 connection's timer and see if it has reached the RTO value
; 	 in which case we retransmit. */
;       if(uip_outstanding(uip_connr)) {
	ldd R30,y+0
	ldd R31,y+1
	ldd R2,z+16
	ldd R3,z+17
	tst R2
	brne X4
	tst R3
	brne X34
	xjmp L81
X34:
X4:
	.dbline 513
	.dbline 514
; 	if(uip_connr->timer-- == 0) {
	ldd R24,y+0
	ldd R25,y+1
	adiw R24,26
	movw R30,R24
	ldd R4,z+0
	mov R24,R4
	subi R24,1
	std z+0,R24
	tst R4
	breq X35
	xjmp L112
X35:
	.dbline 514
	.dbline 515
; 	  if(uip_connr->nrtx == UIP_MAXRTX ||
	ldd R30,y+0
	ldd R31,y+1
	ldd R24,z+27
	cpi R24,8
	breq L87
	ldd R30,y+0
	ldd R31,y+1
	ldd R2,z+25
	clr R3
	mov R24,R2
	cpi R24,2
	breq L88
	cpi R24,1
	brne L85
L88:
	ldd R30,y+0
	ldd R31,y+1
	ldd R24,z+27
	cpi R24,3
	brne L85
L87:
	.dbline 518
; 	     ((uip_connr->tcpstateflags == SYN_SENT ||
; 	       uip_connr->tcpstateflags == SYN_RCVD) &&
; 	      uip_connr->nrtx == UIP_MAXSYNRTX)) {
	.dbline 519
; 	    uip_connr->tcpstateflags = CLOSED;
	clr R2
	ldd R30,y+0
	ldd R31,y+1
	std z+25,R2
	.dbline 524
; 
; 	    /* We call UIP_APPCALL() with uip_flags set to
; 	       UIP_TIMEDOUT to inform the application that the
; 	       connection has timed out. */
; 	    uip_flags = UIP_TIMEDOUT;
	ldi R24,128
	sts _uip_flags,R24
	.dbline 525
; 	    UIP_APPCALL();
	xcall _httpd_appcall
	.dbline 528

⌨️ 快捷键说明

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