📄 uip.lis
字号:
01F6 0895 ret
01F8 .dbsym r cconn 12 pS[uip_conn]
01F8 .dbsym r conn 10 pS[uip_conn]
01F8 .dbsym r rport 14 s
01F8 .dbsym l ripaddr 6 ps
01F8 .dbend
01F8 .dbfunc e uip_unlisten _uip_unlisten fV
01F8 ; port -> R16,R17
.even
01F8 _uip_unlisten::
01F8 .dbline -1
01F8 .dbline 316
01F8 ; }
01F8 ; #endif /* UIP_ACTIVE_OPEN */
01F8 ; /*-----------------------------------------------------------------------------------*/
01F8 ; #if UIP_UDP
01F8 ; struct uip_udp_conn *
01F8 ; uip_udp_new(u16_t *ripaddr, u16_t rport)
01F8 ; {
01F8 ; register struct uip_udp_conn *conn;
01F8 ;
01F8 ; /* Find an unused local port. */
01F8 ; again:
01F8 ; ++lastport;
01F8 ;
01F8 ; if(lastport >= 32000) {
01F8 ; lastport = 4096;
01F8 ; }
01F8 ;
01F8 ; for(c = 0; c < UIP_UDP_CONNS; ++c) {
01F8 ; if(uip_udp_conns[c].lport == lastport) {
01F8 ; goto again;
01F8 ; }
01F8 ; }
01F8 ;
01F8 ;
01F8 ; conn = 0;
01F8 ; for(c = 0; c < UIP_UDP_CONNS; ++c) {
01F8 ; if(uip_udp_conns[c].lport == 0) {
01F8 ; conn = &uip_udp_conns[c];
01F8 ; break;
01F8 ; }
01F8 ; }
01F8 ;
01F8 ; if(conn == 0) {
01F8 ; return 0;
01F8 ; }
01F8 ;
01F8 ; conn->lport = HTONS(lastport);
01F8 ; conn->rport = HTONS(rport);
01F8 ; conn->ripaddr[0] = ripaddr[0];
01F8 ; conn->ripaddr[1] = ripaddr[1];
01F8 ;
01F8 ; return conn;
01F8 ; }
01F8 ; #endif /* UIP_UDP */
01F8 ; /*-----------------------------------------------------------------------------------*/
01F8 ; void
01F8 ; uip_unlisten(u16_t port)
01F8 ; {
01F8 .dbline 317
01F8 2224 clr R2
01FA 20920300 sts _c,R2
01FE 21C0 xjmp L47
0200 L44:
0200 .dbline 317
0200 ; for(c = 0; c < UIP_LISTENPORTS; ++c) {
0200 .dbline 318
0200 ; if(uip_listenports[c] == port) {
0200 20900300 lds R2,_c
0204 82E0 ldi R24,2
0206 829D mul R24,R2
0208 F001 movw R30,R0
020A 80E0 ldi R24,<_uip_listenports
020C 90E0 ldi R25,>_uip_listenports
020E E80F add R30,R24
0210 F91F adc R31,R25
0212 2080 ldd R2,z+0
0214 3180 ldd R3,z+1
0216 2016 cp R2,R16
0218 3106 cpc R3,R17
021A 71F4 brne L48
021C .dbline 318
021C .dbline 319
021C ; uip_listenports[c] = 0;
021C 20900300 lds R2,_c
0220 82E0 ldi R24,2
0222 829D mul R24,R2
0224 F001 movw R30,R0
0226 80E0 ldi R24,<_uip_listenports
0228 90E0 ldi R25,>_uip_listenports
022A E80F add R30,R24
022C F91F adc R31,R25
022E 2224 clr R2
0230 3324 clr R3
0232 3182 std z+1,R3
0234 2082 std z+0,R2
0236 .dbline 320
0236 ; return;
0236 09C0 xjmp L43
0238 L48:
0238 .dbline 322
0238 L45:
0238 .dbline 317
0238 80910300 lds R24,_c
023C 8F5F subi R24,255 ; addi 1
023E 80930300 sts _c,R24
0242 L47:
0242 .dbline 317
0242 80910300 lds R24,_c
0246 8A30 cpi R24,10
0248 D8F2 brlo L44
024A .dbline -2
024A L43:
024A .dbline 0 ; func end
024A 0895 ret
024C .dbsym r port 16 s
024C .dbend
024C .dbfunc e uip_listen _uip_listen fV
024C ; port -> R16,R17
.even
024C _uip_listen::
024C .dbline -1
024C .dbline 327
024C ; }
024C ; }
024C ; }
024C ; /*-----------------------------------------------------------------------------------*/
024C ; void
024C ; uip_listen(u16_t port)
024C ; {
024C .dbline 328
024C 2224 clr R2
024E 20920300 sts _c,R2
0252 20C0 xjmp L54
0254 L51:
0254 .dbline 328
0254 ; for(c = 0; c < UIP_LISTENPORTS; ++c) {
0254 .dbline 329
0254 ; if(uip_listenports[c] == 0) {
0254 20900300 lds R2,_c
0258 82E0 ldi R24,2
025A 829D mul R24,R2
025C F001 movw R30,R0
025E 80E0 ldi R24,<_uip_listenports
0260 90E0 ldi R25,>_uip_listenports
0262 E80F add R30,R24
0264 F91F adc R31,R25
0266 2080 ldd R2,z+0
0268 3180 ldd R3,z+1
026A 2220 tst R2
026C 71F4 brne L55
026E 3320 tst R3
0270 61F4 brne L55
0272 X3:
0272 .dbline 329
0272 .dbline 330
0272 ; uip_listenports[c] = port;
0272 20900300 lds R2,_c
0276 82E0 ldi R24,2
0278 829D mul R24,R2
027A F001 movw R30,R0
027C 80E0 ldi R24,<_uip_listenports
027E 90E0 ldi R25,>_uip_listenports
0280 E80F add R30,R24
0282 F91F adc R31,R25
0284 1183 std z+1,R17
0286 0083 std z+0,R16
0288 .dbline 331
0288 ; return;
0288 09C0 xjmp L50
028A L55:
028A .dbline 333
028A L52:
028A .dbline 328
028A 80910300 lds R24,_c
028E 8F5F subi R24,255 ; addi 1
0290 80930300 sts _c,R24
0294 L54:
0294 .dbline 328
0294 80910300 lds R24,_c
0298 8A30 cpi R24,10
029A E0F2 brlo L51
029C .dbline -2
029C L50:
029C .dbline 0 ; func end
029C 0895 ret
029E .dbsym r port 16 s
029E .dbend
029E .dbfunc s uip_add_rcv_nxt _uip_add_rcv_nxt fV
029E ; n -> R10,R11
.even
029E _uip_add_rcv_nxt:
029E 0E940000 xcall push_gset3x
02A2 5801 movw R10,R16
02A4 .dbline -1
02A4 .dbline 471
02A4 ; }
02A4 ; }
02A4 ; }
02A4 ; /*-----------------------------------------------------------------------------------*/
02A4 ; /* XXX: IP fragment reassembly: not well-tested. */
02A4 ;
02A4 ; #if UIP_REASSEMBLY
02A4 ; #define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
02A4 ; static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
02A4 ; static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
02A4 ; static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
02A4 ; 0x0f, 0x07, 0x03, 0x01};
02A4 ; static u16_t uip_reasslen;
02A4 ; static u8_t uip_reassflags;
02A4 ; #define UIP_REASS_FLAG_LASTFRAG 0x01
02A4 ; static u8_t uip_reasstmr;
02A4 ;
02A4 ; #define IP_HLEN 20
02A4 ; #define IP_MF 0x20
02A4 ;
02A4 ; static u8_t
02A4 ; uip_reass(void)
02A4 ; {
02A4 ; u16_t offset, len;
02A4 ; u16_t i;
02A4 ;
02A4 ; /* If ip_reasstmr is zero, no packet is present in the buffer, so we
02A4 ; write the IP header of the fragment into the reassembly
02A4 ; buffer. The timer is updated with the maximum age. */
02A4 ; if(uip_reasstmr == 0) {
02A4 ; memcpy(uip_reassbuf, &BUF->vhl, IP_HLEN);
02A4 ; uip_reasstmr = UIP_REASS_MAXAGE;
02A4 ; uip_reassflags = 0;
02A4 ; /* Clear the bitmap. */
02A4 ; memset(uip_reassbitmap, sizeof(uip_reassbitmap), 0);
02A4 ; }
02A4 ;
02A4 ; /* Check if the incoming fragment matches the one currently present
02A4 ; in the reasembly buffer. If so, we proceed with copying the
02A4 ; fragment into the buffer. */
02A4 ; if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&
02A4 ; BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&
02A4 ; BUF->destipaddr[0] == FBUF->destipaddr[0] &&
02A4 ; BUF->destipaddr[1] == FBUF->destipaddr[1] &&
02A4 ; BUF->ipid[0] == FBUF->ipid[0] &&
02A4 ; BUF->ipid[1] == FBUF->ipid[1]) {
02A4 ;
02A4 ; len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;
02A4 ; offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8;
02A4 ;
02A4 ; /* If the offset or the offset + fragment length overflows the
02A4 ; reassembly buffer, we discard the entire packet. */
02A4 ; if(offset > UIP_REASS_BUFSIZE ||
02A4 ; offset + len > UIP_REASS_BUFSIZE) {
02A4 ; uip_reasstmr = 0;
02A4 ; goto nullreturn;
02A4 ; }
02A4 ;
02A4 ; /* Copy the fragment into the reassembly buffer, at the right
02A4 ; offset. */
02A4 ; memcpy(&uip_reassbuf[IP_HLEN + offset],
02A4 ; (char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
02A4 ; len);
02A4 ;
02A4 ; /* Update the bitmap. */
02A4 ; if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
02A4 ; /* If the two endpoints are in the same byte, we only update
02A4 ; that byte. */
02A4 ;
02A4 ; uip_reassbitmap[offset / (8 * 8)] |=
02A4 ; bitmap_bits[(offset / 8 ) & 7] &
02A4 ; ~bitmap_bits[((offset + len) / 8 ) & 7];
02A4 ; } else {
02A4 ; /* If the two endpoints are in different bytes, we update the
02A4 ; bytes in the endpoints and fill the stuff inbetween with
02A4 ; 0xff. */
02A4 ; uip_reassbitmap[offset / (8 * 8)] |=
02A4 ; bitmap_bits[(offset / 8 ) & 7];
02A4 ; for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
02A4 ; uip_reassbitmap[i] = 0xff;
02A4 ; }
02A4 ; uip_reassbitmap[(offset + len) / (8 * 8)] |=
02A4 ; ~bitmap_bits[((offset + len) / 8 ) & 7];
02A4 ; }
02A4 ;
02A4 ; /* If this fragment has the More Fragments flag set to zero, we
02A4 ; know that this is the last fragment, so we can calculate the
02A4 ; size of the entire packet. We also set the
02A4 ; IP_REASS_FLAG_LASTFRAG flag to indicate that we have received
02A4 ; the final fragment. */
02A4 ;
02A4 ; if((BUF->ipoffset[0] & IP_MF) == 0) {
02A4 ; uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
02A4 ; uip_reasslen = offset + len;
02A4 ; }
02A4 ;
02A4 ; /* Finally, we check if we have a full packet in the buffer. We do
02A4 ; this by checking if we have the last fragment and if all bits
02A4 ; in the bitmap are set. */
02A4 ; if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
02A4 ; /* Check all bytes up to and including all but the last byte in
02A4 ; the bitmap. */
02A4 ; for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
02A4 ; if(uip_reassbitmap[i] != 0xff) {
02A4 ; goto nullreturn;
02A4 ; }
02A4 ; }
02A4 ; /* Check the last byte in the bitmap. It should contain just the
02A4 ; right amount of bits. */
02A4 ; if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=
02A4 ; (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
02A4 ; goto nullreturn;
02A4 ; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -