📄 ip.s
字号:
clr R16
xcall _IP_DisplayProtocol
.dbline 372
; IP_DisplayHeader(MainBufferRd_Rx, MainBufferWr_Rx);
lds R18,_MainBufferWr_Rx
lds R19,_MainBufferWr_Rx+1
lds R16,_MainBufferRd_Rx
lds R17,_MainBufferRd_Rx+1
xcall _IP_DisplayHeader
.dbline 377
; #endif
;
; // ********************************
;
; w = (u16)(IP_Header->VerLen & 0x0f) << 2; // w = length of header in bytes
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R24,z+0
clr R25
andi R24,15
andi R25,0
movw R10,R24
lsl R10
rol R11
lsl R10
rol R11
.dbline 378
; w += MainBufferRd_Rx; // point to data (immediately follows the IP header)
lds R2,_MainBufferRd_Rx
lds R3,_MainBufferRd_Rx+1
add R10,R2
adc R11,R3
.dbline 379
; MainBufferRd_Rx += sizeof(T_IP_Header); // point to header options
movw R24,R2
adiw R24,20
sts _MainBufferRd_Rx+1,R25
sts _MainBufferRd_Rx,R24
xjmp L151
L150:
.dbline 381
; while (MainBufferRd_Rx < w) //
; { // go thru each IP header option
.dbline 382
; type = MainBuffer[MainBufferRd_Rx++]; // option type
lds R2,_MainBufferRd_Rx
lds R3,_MainBufferRd_Rx+1
movw R24,R2
adiw R24,1
sts _MainBufferRd_Rx+1,R25
sts _MainBufferRd_Rx,R24
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
movw R30,R2
add R30,R24
adc R31,R25
ldd R12,z+0
.dbline 383
; len = 0; //
clr R14
.dbline 384
; if (!type) break; // end of option list
tst R12
brne L153
.dbline 384
xjmp L152
L153:
.dbline 385
; if (type == 1) continue; // no length byte (NOP option)
mov R24,R12
cpi R24,1
brne L155
.dbline 385
xjmp L151
L155:
.dbline 386
; len = MainBuffer[MainBufferRd_Rx++]; // option length
lds R2,_MainBufferRd_Rx
lds R3,_MainBufferRd_Rx+1
movw R24,R2
adiw R24,1
sts _MainBufferRd_Rx+1,R25
sts _MainBufferRd_Rx,R24
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
movw R30,R2
add R30,R24
adc R31,R25
ldd R14,z+0
.dbline 387
; if (len < 2) len = 2; //
mov R24,R14
cpi R24,2
brsh L157
.dbline 387
ldi R24,2
mov R14,R24
L157:
.dbline 391
mov R24,R14
clr R25
sbiw R24,2
lds R2,_MainBufferRd_Rx
lds R3,_MainBufferRd_Rx+1
add R2,R24
adc R3,R25
sts _MainBufferRd_Rx+1,R3
sts _MainBufferRd_Rx,R2
.dbline 392
L151:
.dbline 380
lds R2,_MainBufferRd_Rx
lds R3,_MainBufferRd_Rx+1
cp R2,R10
cpc R3,R11
brsh X11
xjmp L150
X11:
L152:
.dbline 393
; //
;
; //
; MainBufferRd_Rx += (len - 2); //
; } //
; MainBufferRd_Rx = w; // point to IP data
sts _MainBufferRd_Rx+1,R11
sts _MainBufferRd_Rx,R10
.dbline 397
;
; // ********************************
;
; if ((IP_Header->DestIP.ip32 != 0xffffffff) && (IP_Header->DestIP.ip32 != PPP.OUR_IP.ip32)) return; // it's not for us so drop it now
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R2,z+16
ldd R3,z+17
ldd R4,z+18
ldd R5,z+19
movw R30,R28
std z+0,R2
std z+1,R3
std z+2,R4
std z+3,R5
ldi R20,255
ldi R21,255
ldi R22,255
ldi R23,255
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
cp R2,R20
cpc R3,R21
cpc R4,R22
cpc R5,R23
breq L159
lds R4,_PPP+13+2
lds R5,_PPP+13+2+1
lds R2,_PPP+13
lds R3,_PPP+13+1
movw R30,R28
ldd R6,z+0
ldd R7,z+1
ldd R8,z+2
ldd R9,z+3
cp R6,R2
cpc R7,R3
cpc R8,R4
cpc R9,R5
breq L159
.dbline 397
xjmp L133
L159:
.dbline 402
;
; // ********************************
; // check for fragmentation
;
; w = ntohs(IP_Header->Fragment); //
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R16,z+6
ldd R17,z+7
xcall _ntohs
movw R10,R16
.dbline 404
; //
; if (w & IP_FRAGMENTED) //
movw R24,R10
andi R25,63
cpi R24,0
cpc R24,R25
breq L162
X10:
.dbline 405
; { //
.dbline 407
; #ifdef Debug
; SendDebugRStr(ip_str17); //
ldi R16,<_ip_str17
ldi R17,>_ip_str17
xcall _SendDebugRStr
.dbline 409
; #endif
; return; // we don't yet deal with fragmentation - just not got the ram available :(
xjmp L133
L162:
.dbline 418
; } // .. but how do we force the other end to set the "don't fragment" flag when sending packets ?
; //
; // w &= IP_FRAGMENT_OFFSET; // w = fragment offset
;
;
; // ********************************
;
; #ifdef IncludeICMP
; if (IP_Header->Protocol == IP_PROTO_ICMP) ICMP_In(); //
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R24,z+9
cpi R24,1
brne L164
.dbline 418
xcall _ICMP_In
xjmp L165
L164:
.dbline 426
; #endif
; #ifdef IncludeUDP
; else //
; if (IP_Header->Protocol == IP_PROTO_UDP) UDP_In(); //
; #endif
; #ifdef IncludeTCP
; else //
; if (IP_Header->Protocol == IP_PROTO_TCP) TCP_In(); //
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R24,z+9
cpi R24,6
brne L166
.dbline 426
xcall _TCP_In
L166:
L165:
.dbline -2
L133:
adiw R28,4
xcall pop_gset5
.dbline 0 ; func end
ret
.dbsym r w 10 s
.dbsym r type 12 c
.dbsym r len 14 c
.dbend
.dbfunc e IP_StartPacket _IP_StartPacket fV
; IP -> y+4
; Protocol -> R20
.even
_IP_StartPacket::
st -y,r19
st -y,r18
xcall push_gset1
mov R20,R16
sbiw R28,2
.dbline -1
.dbline 436
; #endif
;
; // ********************************
; }
;
; // **************************************************************************
; // start an IP packet
;
; void IP_StartPacket(u8 Protocol, u32 IP)
; {
.dbline 437
; PPP_StartPacket(PPP_IP); //
ldi R16,33
ldi R17,0
xcall _PPP_StartPacket
.dbline 439
; //
; IP_Header = (T_IP_Header*)(MainBuffer + MainBufferWr_Tx); // point to the IP header
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
lds R2,_MainBufferWr_Tx
lds R3,_MainBufferWr_Tx+1
add R2,R24
adc R3,R25
sts _IP_Header+1,R3
sts _IP_Header,R2
.dbline 440
; memset(IP_Header, 0, sizeof(T_IP_Header)); // clear it
ldi R24,20
ldi R25,0
std y+1,R25
std y+0,R24
clr R18
clr R19
movw R16,R2
xcall _memset
.dbline 442
; //
; IP_Header->VerLen = 0x40 | (sizeof(T_IP_Header) >> 2); //
ldi R24,69
lds R30,_IP_Header
lds R31,_IP_Header+1
std z+0,R24
.dbline 443
; IP_Header->TOS = 0x04; // make it high-reliable
ldi R24,4
lds R30,_IP_Header
lds R31,_IP_Header+1
std z+1,R24
.dbline 445
; // IP_Header->TOS = 0x08; // make it high-throughput - suseptable to retires though
; IP_Header->TotalLength = sizeof(T_IP_Header); //
ldi R24,20
ldi R25,0
lds R30,_IP_Header
lds R31,_IP_Header+1
std z+3,R25
std z+2,R24
.dbline 446
; IP_Header->ID = IP_ID++; //
lds R2,_IP_ID
lds R3,_IP_ID+1
movw R24,R2
adiw R24,1
sts _IP_ID+1,R25
sts _IP_ID,R24
std z+5,R3
std z+4,R2
.dbline 447
; IP_Header->Fragment = IP_DONT_FRAGMENT; //
ldi R24,16384
ldi R25,64
std z+7,R25
std z+6,R24
.dbline 448
; IP_Header->TTL = 128; //
ldi R24,128
std z+8,R24
.dbline 449
; IP_Header->Protocol = Protocol; //
lds R30,_IP_Header
lds R31,_IP_Header+1
std z+9,R20
.dbline 450
; IP_Header->SourceIP.ip32 = PPP.OUR_IP.ip32; //
lds R4,_PPP+13+2
lds R5,_PPP+13+2+1
lds R2,_PPP+13
lds R3,_PPP+13+1
lds R30,_IP_Header
lds R31,_IP_Header+1
std z+12,R2
std z+13,R3
std z+14,R4
std z+15,R5
.dbline 451
; IP_Header->DestIP.ip32 = IP; //
movw R30,R28
ldd R2,z+4
ldd R3,z+5
ldd R4,z+6
ldd R5,z+7
lds R30,_IP_Header
lds R31,_IP_Header+1
std z+16,R2
std z+17,R3
std z+18,R4
std z+19,R5
.dbline 453
; //
; MainBufferWr_Tx += sizeof(T_IP_Header); // update index
lds R24,_MainBufferWr_Tx
lds R25,_MainBufferWr_Tx+1
adiw R24,20
sts _MainBufferWr_Tx+1,R25
sts _MainBufferWr_Tx,R24
.dbline -2
L168:
adiw R28,2
xcall pop_gset1
adiw R28,2
.dbline 0 ; func end
ret
.dbsym l IP 4 l
.dbsym r Protocol 20 c
.dbend
.dbfunc e IP_EndPacket _IP_EndPacket fV
; w -> R20,R21
.even
_IP_EndPacket::
xcall push_gset1
.dbline -1
.dbline 457
; }
;
; void IP_EndPacket(void)
; {
.dbline 460
; u16 w; //
; //
; IP_Header->ID = htons(IP_Header->ID); //
lds R24,_IP_Header
lds R25,_IP_Header+1
adiw R24,4
movw R30,R24
ldd R16,z+0
ldd R17,z+1
push R24
push R25
xcall _htons
pop R31
pop R30
std z+1,R17
std z+0,R16
.dbline 461
; IP_Header->Fragment = htons(IP_Header->Fragment); //
lds R24,_IP_Header
lds R25,_IP_Header+1
adiw R24,6
movw R30,R24
ldd R16,z+0
ldd R17,z+1
push R24
push R25
xcall _htons
pop R31
pop R30
std z+1,R17
std z+0,R16
.dbline 462
; IP_Header->TotalLength = htons(IP_Header->TotalLength); //
lds R24,_IP_Header
lds R25,_IP_Header+1
adiw R24,2
movw R30,R24
ldd R16,z+0
ldd R17,z+1
push R24
push R25
xcall _htons
pop R31
pop R30
std z+1,R17
std z+0,R16
.dbline 464
; //
; w = (u16)(IP_Header->VerLen & 0x0f); // number of 32-bit words to the ip header
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R20,z+0
clr R21
andi R20,15
andi R21,0
.dbline 465
; w <<= 2; // now number of bytes
lsl R20
rol R21
lsl R20
rol R21
.dbline 466
; w = IP_Checksum1((char*)IP_Header, w); // update the IP header checksum
movw R18,R20
movw R16,R30
xcall _IP_Checksum1
movw R20,R16
.dbline 468
; // if (!w) w = 0xffff; //
; IP_Header->Checksum = htons(w); //
xcall _htons
lds R30,_IP_Header
lds R31,_IP_Header+1
std z+11,R17
std z+10,R16
.dbline -2
L170:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r w 20 s
.dbend
.dbfunc e IP_10ms_Timer _IP_10ms_Timer fV
.even
_IP_10ms_Timer::
.dbline -1
.dbline 475
; }
;
; // **************************************************************************
; // this is called from the ppp module - every 10ms
;
; void IP_10ms_Timer(void)
; {
.dbline 477
; #ifdef IncludeICMP
; ICMP_10ms_Timer(); //
xcall _ICMP_10ms_Timer
.dbline 485
; #endif
;
; #ifdef IncludeUDP
; UDP_10ms_Timer(); //
; #endif
;
; #ifdef IncludeTCP
; TCP_10ms_Timer(); //
xcall _TCP_10ms_Timer
.dbline -2
L171:
.dbline 0 ; func end
ret
.dbend
.dbfunc e IP_Process _IP_Process fV
.even
_IP_Process::
.dbline -1
.dbline 493
; #endif
; }
;
; // **************************************************************************
; // this is called from the ppp module - as often as pos
;
; void IP_Process(void)
; {
.dbline 495
; #ifdef IncludeTCP
; TCP_Process(); //
xcall _TCP_Process
.dbline -2
L172:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
_IP_Header::
.blkb 2
.dbunion 0 4 TIPAddr
.dbfield 0 ip8 A[4:4]c
.dbfield 0 ip32 l
.dbend
.dbstruct 0 20 TIPHeader
.dbfield 0 VerLen c
.dbfield 1 TOS c
.dbfield 2 TotalLength s
.dbfield 4 ID s
.dbfield 6 Fragment s
.dbfield 8 TTL c
.dbfield 9 Protocol c
.dbfield 10 Checksum s
.dbfield 12 SourceIP S[TIPAddr]
.dbfield 16 DestIP S[TIPAddr]
.dbend
.dbsym e IP_Header _IP_Header pS[TIPHeader]
_IP_ID::
.blkb 2
.dbsym e IP_ID _IP_ID s
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L83:
.blkb 12
.area idata
.byte 37,'u,32,32,'l,'e,'n,58,37,'u,10,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L82:
.blkb 4
.area idata
.byte 37,'u,10,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L72:
.blkb 2
.area idata
.byte 10,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L67:
.blkb 4
.area idata
.byte 32,62,32,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L64:
.blkb 6
.area idata
.byte 37,48,52,'X,32,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L59:
.blkb 8
.area idata
.byte 32,91,37,48,52,'X,93,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L38:
.blkb 5
.area idata
.byte 37,48,52,'X,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L25:
.blkb 5
.area idata
.byte 37,48,50,'X,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L16:
.blkb 3
.area idata
.byte 37,'u,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
L10:
.blkb 17
.area idata
.byte 91,37,48,52,'x,93,32,37,'d,45,'b,'y,'t,'e,'s,10
.byte 0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -