?? ip.s
字號:
.module ip.c
.area lit(rom, con, rel)
_ip_str1::
.byte 10,'T,0
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
.dbsym e ip_str1 _ip_str1 A[3:3]kc
_ip_str2::
.byte 10,'R,0
.dbsym e ip_str2 _ip_str2 A[3:3]kc
_ip_str2a::
.byte 'X,58,32,'P,'r,'o,'t,58,32,'P,'P,'P,95,'I,'P,32
.byte 0
.dbsym e ip_str2a _ip_str2a A[17:17]kc
_ip_str3::
.byte 32,32,32,32,'I,'P,'H,'d,'r,58,32,'V,'e,'r,58,0
.dbsym e ip_str3 _ip_str3 A[16:16]kc
_ip_str4::
.byte 32,'H,'d,'r,'L,'e,'n,58,0
.dbsym e ip_str4 _ip_str4 A[9:9]kc
_ip_str5::
.byte 32,'T,'o,'s,58,0
.dbsym e ip_str5 _ip_str5 A[6:6]kc
_ip_str6::
.byte 32,'T,'o,'t,'L,'e,'n,58,0
.dbsym e ip_str6 _ip_str6 A[9:9]kc
_ip_str7::
.byte 32,'I,'D,58,0
.dbsym e ip_str7 _ip_str7 A[5:5]kc
_ip_str8::
.byte 32,'F,'r,'a,'g,58,0
.dbsym e ip_str8 _ip_str8 A[7:7]kc
_ip_str9::
.byte 32,'T,'T,'L,58,0
.dbsym e ip_str9 _ip_str9 A[6:6]kc
_ip_str10::
.byte 32,'I,'C,'M,'P,0
.dbsym e ip_str10 _ip_str10 A[6:6]kc
_ip_str11::
.byte 32,'U,'D,'P,0
.dbsym e ip_str11 _ip_str11 A[5:5]kc
_ip_str12::
.byte 32,'T,'C,'P,0
.dbsym e ip_str12 _ip_str12 A[5:5]kc
_ip_str13::
.byte 32,'C,'h,'k,'s,'u,'m,58,0
.dbsym e ip_str13 _ip_str13 A[9:9]kc
_ip_str14::
.byte 32,32,32,32,'o,'p,'t,'i,'o,'n,58,0
.dbsym e ip_str14 _ip_str14 A[12:12]kc
_ip_str15::
.byte 32,32,32,32,'D,'a,'t,'a,'B,'y,'t,'e,'s,58,0
.dbsym e ip_str15 _ip_str15 A[15:15]kc
_ip_str16::
.byte 42,42,42,32,'I,'P,32,'c,'h,'k,'s,'u,'m,32,'e,'r
.byte 'r,10,0
.dbsym e ip_str16 _ip_str16 A[19:19]kc
_ip_str17::
.byte 42,42,42,32,'F,'r,'a,'g,'m,'e,'n,'t,'e,'d,32,45
.byte 32,'i,'g,'n,'o,'r,'i,'n,'g,10,0
.dbsym e ip_str17 _ip_str17 A[27:27]kc
_SubnetMask::
.byte 255,255
.byte 255,0
.dbsym e SubnetMask _SubnetMask A[4:4]kc
_AllowedIP::
.byte 192,168
.byte 254,2
.byte 192,168
.byte 254,5
.byte 192,168
.byte 254,7
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0,0
.dbsym e AllowedIP _AllowedIP A[40:10:4]kc
.area text(rom, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\ip.c
.dbfunc e IP_DisplayProtocol _IP_DisplayProtocol fV
; TotalBytes -> R20,R21
; Tx -> R22
.even
_IP_DisplayProtocol::
xcall push_gset2
movw R20,R18
mov R22,R16
sbiw R28,4
.dbline -1
.dbline 109
;
; /*
; * Copyright (C) 2003-2004 by Clive Moss All rights reserved.
; *
; * Help & Contributions from D.J.Armstrong
;
; * Redistribution and use in source and binary forms, with or without
; * modification, are permitted provided that the following conditions
; * are met:
; *
; * 1. Redistributions of source code must retain the above copyright
; * notice, this list of conditions and the following disclaimer.
; * 2. Redistributions in binary form must reproduce the above copyright
; * notice, this list of conditions and the following disclaimer in the
; * documentation and/or other materials provided with the distribution.
; * 3. Neither the name of the copyright holders nor the names of
; * contributors may be used to endorse or promote products derived
; * from this software without specific prior written permission.
; *
; * THIS SOFTWARE IS PROVIDED BY CLIVE MOSS 'AS IS' AND ANY EXPRESS OR
; * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; * ARE DISCLAIMED.
; * IN NO EVENT SHALL CLIVE MOSS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
; * INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
; * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
; * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
; * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
; * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
; * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
; * SUCH DAMAGE.
; */
;
; //#ifdef CPU_eZ8
; // #pragma stkck // enable stack checking
; //#endif
;
; #include <stdio.h>
; #include <stdlib.h>
; #include <string.h>
;
; #include "common.h"
; #include "ppp.h"
; #include "ip.h"
;
; #ifdef IncludeTCP
; #include "tcp.h"
; #endif
;
; #ifdef IncludeICMP
; #include "icmp.h"
; #endif
;
; #ifdef IncludeUDP
; #include "udp.h"
; #endif
;
; #ifdef Debug
; flash char ip_str1[] = "\nT";
; flash char ip_str2[] = "\nR";
; flash char ip_str2a[] = "X: Prot: PPP_IP ";
; flash char ip_str3[] = " IPHdr: Ver:";
; flash char ip_str4[] = " HdrLen:";
; flash char ip_str5[] = " Tos:";
; flash char ip_str6[] = " TotLen:";
; flash char ip_str7[] = " ID:";
; flash char ip_str8[] = " Frag:";
; flash char ip_str9[] = " TTL:";
; flash char ip_str10[] = " ICMP";
; flash char ip_str11[] = " UDP";
; flash char ip_str12[] = " TCP";
; flash char ip_str13[] = " Chksum:";
; flash char ip_str14[] = " option:";
; flash char ip_str15[] = " DataBytes:";
; flash char ip_str16[] = "*** IP chksum err\n";
; flash char ip_str17[] = "*** Fragmented - ignoring\n";
; #endif
;
; flash char SubnetMask[4] = {255, 255, 255, 0};
;
; flash char AllowedIP[10][4] = { // these are the ip's that are allowed to ping us and are allowed to ping & tcp in
; // FIREWALL stuff
; {192, 168, 254, 2}, // local lan ip
; {192, 168, 254, 5}, // local lan ip
; {192, 168, 254, 7}, // local lan ip
; {0, 0, 0, 0}, // spare
; {0, 0, 0, 0}, // spare
; {0, 0, 0, 0}, // spare
; {0, 0, 0, 0}, // spare
; {0, 0, 0, 0}, // spare
; {0, 0, 0, 0}, // spare
; {0, 0, 0, 0} // leave as '0'
; };
;
; #ifdef CPU_eZ8
; near u16 IP_ID;
; #endif
; #ifdef CPU_ATmega128
; u16 IP_ID;
; #endif
;
; T_IP_Header *IP_Header;
;
; // **************************************************************************
;
; #ifdef Debug
;
; void IP_DisplayProtocol(bool Tx, int TotalBytes)
; {
.dbline 110
; if (Tx)
tst R22
breq L2
.dbline 111
; {
.dbline 112
; if (!SendDebugRStr(ip_str1)) return;
ldi R16,<_ip_str1
ldi R17,>_ip_str1
xcall _SendDebugRStr
tst R16
brne L3
.dbline 112
xjmp L1
X0:
.dbline 113
; }
L2:
.dbline 115
; else
; {
.dbline 116
; if (!SendDebugRStr(ip_str2)) return;
ldi R16,<_ip_str2
ldi R17,>_ip_str2
xcall _SendDebugRStr
tst R16
brne L6
.dbline 116
xjmp L1
L6:
.dbline 117
; }
L3:
.dbline 118
; if (!SendDebugRStr(ip_str2a)) return;
ldi R16,<_ip_str2a
ldi R17,>_ip_str2a
xcall _SendDebugRStr
tst R16
brne L8
.dbline 118
xjmp L1
L8:
.dbline 119
std y+3,R21
std y+2,R20
ldi R24,33
ldi R25,0
std y+1,R25
std y+0,R24
ldi R18,<L10
ldi R19,>L10
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _sprintf
.dbline 120
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _SendDebugStr
tst R16
brne L11
.dbline 120
L11:
.dbline -2
L1:
adiw R28,4
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r TotalBytes 20 I
.dbsym r Tx 22 c
.dbend
.dbfunc e IP_DisplayHeader _IP_DisplayHeader fV
; j -> R10,R11
; i -> R20,R21
; len -> R12
; type -> R14
; TotalBytes -> R22,R23
; HeaderIdx -> R10,R11
.even
_IP_DisplayHeader::
xcall push_gset5
movw R22,R18
movw R10,R16
sbiw R28,4
.dbline -1
.dbline 124
; sprintf((char*)ScratchPad, "[%04x] %d-bytes\n", PPP_IP, TotalBytes);
; if (!SendDebugStr((char*)ScratchPad)) return;
; }
;
; void IP_DisplayHeader(int HeaderIdx, int TotalBytes)
; {
.dbline 146
; int i, j;
; u8 type, len;
; /*
; 0 1 2 3
; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; |Ver= 4 |IHL= 5 |Type of Service| Total Length = 21 |
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; | Identification = 111 |Flg=0| Fragment Offset = 0 |
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; | Time = 123 | Protocol = 1 | header checksum |
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; | source address |
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; | destination address |
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; | Options | Padding | < optional
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; */
; // display the header
;
; if (!SendDebugRStr(ip_str3)) return;
ldi R16,<_ip_str3
ldi R17,>_ip_str3
xcall _SendDebugRStr
tst R16
brne L14
.dbline 146
xjmp L13
L14:
.dbline 147
; sprintf((char*)ScratchPad, "%u", (IP_Header->VerLen & 0xf0) >> 4);
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R24,z+0
clr R25
andi R24,240
andi R25,0
asr R25
ror R24
asr R25
ror R24
asr R25
ror R24
asr R25
ror R24
std y+1,R25
std y+0,R24
ldi R18,<L16
ldi R19,>L16
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _sprintf
.dbline 148
; if (!SendDebugStr((char*)ScratchPad)) return;
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _SendDebugStr
tst R16
brne L17
.dbline 148
xjmp L13
L17:
.dbline 150
;
; if (!SendDebugRStr(ip_str4)) return;
ldi R16,<_ip_str4
ldi R17,>_ip_str4
xcall _SendDebugRStr
tst R16
brne L19
.dbline 150
xjmp L13
L19:
.dbline 151
; sprintf((char*)ScratchPad, "%u", IP_Header->VerLen & 0x0f);
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R24,z+0
clr R25
andi R24,15
andi R25,0
std y+1,R25
std y+0,R24
ldi R18,<L16
ldi R19,>L16
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _sprintf
.dbline 152
; if (!SendDebugStr((char*)ScratchPad)) return;
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _SendDebugStr
tst R16
brne L21
.dbline 152
xjmp L13
L21:
.dbline 154
;
; if (!SendDebugRStr(ip_str5)) return;
ldi R16,<_ip_str5
ldi R17,>_ip_str5
xcall _SendDebugRStr
tst R16
brne L23
.dbline 154
xjmp L13
L23:
.dbline 155
; sprintf((char*)ScratchPad, "%02X", IP_Header->TOS);
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R2,z+1
clr R3
std y+1,R3
std y+0,R2
ldi R18,<L25
ldi R19,>L25
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _sprintf
.dbline 156
; if (!SendDebugStr((char*)ScratchPad)) return;
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _SendDebugStr
tst R16
brne L26
.dbline 156
xjmp L13
L26:
.dbline 158
;
; if (!SendDebugRStr(ip_str6)) return;
ldi R16,<_ip_str6
ldi R17,>_ip_str6
xcall _SendDebugRStr
tst R16
brne L28
.dbline 158
xjmp L13
L28:
.dbline 159
; sprintf((char*)ScratchPad, "%u", ntohs(IP_Header->TotalLength));
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R16,z+2
ldd R17,z+3
xcall _ntohs
std y+1,R17
std y+0,R16
ldi R18,<L16
ldi R19,>L16
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _sprintf
.dbline 160
; if (!SendDebugStr((char*)ScratchPad)) return;
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _SendDebugStr
tst R16
brne L30
.dbline 160
xjmp L13
L30:
.dbline 162
;
; if (!SendDebugRStr(ip_str7)) return;
ldi R16,<_ip_str7
ldi R17,>_ip_str7
xcall _SendDebugRStr
tst R16
brne L32
.dbline 162
xjmp L13
L32:
.dbline 163
; sprintf((char*)ScratchPad, "%u", ntohs(IP_Header->ID));
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R16,z+4
ldd R17,z+5
xcall _ntohs
std y+1,R17
std y+0,R16
ldi R18,<L16
ldi R19,>L16
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _sprintf
.dbline 164
; if (!SendDebugStr((char*)ScratchPad)) return;
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _SendDebugStr
tst R16
brne L34
.dbline 164
xjmp L13
L34:
.dbline 166
;
; if (!SendDebugRStr(ip_str8)) return;
ldi R16,<_ip_str8
ldi R17,>_ip_str8
xcall _SendDebugRStr
tst R16
brne L36
.dbline 166
xjmp L13
L36:
.dbline 167
; sprintf((char*)ScratchPad, "%04X", ntohs(IP_Header->Fragment));
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R16,z+6
ldd R17,z+7
xcall _ntohs
std y+1,R17
std y+0,R16
ldi R18,<L38
ldi R19,>L38
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _sprintf
.dbline 168
; if (!SendDebugStr((char*)ScratchPad)) return;
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _SendDebugStr
tst R16
brne L39
.dbline 168
xjmp L13
L39:
.dbline 170
;
; if (!SendDebugRStr(ip_str9)) return;
ldi R16,<_ip_str9
ldi R17,>_ip_str9
xcall _SendDebugRStr
tst R16
brne L41
.dbline 170
xjmp L13
L41:
.dbline 171
; sprintf((char*)ScratchPad, "%u", IP_Header->TTL);
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R2,z+8
clr R3
std y+1,R3
std y+0,R2
ldi R18,<L16
ldi R19,>L16
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _sprintf
.dbline 172
; if (!SendDebugStr((char*)ScratchPad)) return;
ldi R16,<_ScratchPad
ldi R17,>_ScratchPad
xcall _SendDebugStr
tst R16
brne L43
.dbline 172
xjmp L13
L43:
.dbline 174
;
; switch (IP_Header->Protocol)
lds R30,_IP_Header
lds R31,_IP_Header+1
ldd R20,z+9
clr R21
cpi R20,6
ldi R30,0
cpc R21,R30
breq L54
ldi R24,6
ldi R25,0
cp R24,R20
cpc R25,R21
brlt L58
L57:
cpi R20,1
ldi R30,0
cpc R21,R30
breq L48
xjmp L45
L58:
cpi R20,17
ldi R30,0
cpc R21,R30
breq L51
xjmp L45
X1:
.dbline 175
; {
L48:
.dbline 176
; case IP_PROTO_ICMP : if (!SendDebugRStr(ip_str10)) return;
ldi R16,<_ip_str10
ldi R17,>_ip_str10
xcall _SendDebugRStr
tst R16
brne L46
.dbline 176
xjmp L13
X2:
.dbline 177
; break;
L51:
.dbline 178
; case IP_PROTO_UDP : if (!SendDebugRStr(ip_str11)) return;
ldi R16,<_ip_str11
ldi R17,>_ip_str11
xcall _SendDebugRStr
tst R16
brne L46
.dbline 178
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -