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

📄 ip.s

📁 AVR单片机系统开发经典实例部分源程序
💻 S
📖 第 1 页 / 共 4 页
字号:
	xjmp L13
X3:
	.dbline 179
; 								break;
L54:
	.dbline 180
; 		case IP_PROTO_TCP	:	if (!SendDebugRStr(ip_str12)) return;
	ldi R16,<_ip_str12
	ldi R17,>_ip_str12
	xcall _SendDebugRStr
	tst R16
	brne L46
	.dbline 180
	xjmp L13
X4:
	.dbline 181
; 								break;
L45:
L46:
	.dbline 183
; 	}
; 	sprintf((char*)ScratchPad, " [%04X]", IP_Header->Protocol);
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R2,z+9
	clr R3
	std y+1,R3
	std y+0,R2
	ldi R18,<L59
	ldi R19,>L59
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 184
; 	if (!SendDebugStr((char*)ScratchPad)) return;
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L60
	.dbline 184
	xjmp L13
L60:
	.dbline 186
; 
; 	if (!SendDebugRStr(ip_str13)) return;
	ldi R16,<_ip_str13
	ldi R17,>_ip_str13
	xcall _SendDebugRStr
	tst R16
	brne L62
	.dbline 186
	xjmp L13
L62:
	.dbline 187
; 	sprintf((char*)ScratchPad, "%04X ", ntohs(IP_Header->Checksum));
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R16,z+10
	ldd R17,z+11
	xcall _ntohs
	std y+1,R17
	std y+0,R16
	ldi R18,<L64
	ldi R19,>L64
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 188
; 	if (!SendDebugStr((char*)ScratchPad)) return;
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L65
	.dbline 188
	xjmp L13
L65:
	.dbline 190
; 
; 	IP_Str((char*)ScratchPad, IP_Header->SourceIP.ip32);
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R2,z+12
	ldd R3,z+13
	ldd R4,z+14
	ldd R5,z+15
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _IP_Str
	.dbline 191
; 	strcat((char*)ScratchPad, " > ");
	ldi R18,<L67
	ldi R19,>L67
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _strcat
	.dbline 192
; 	IP_Str((char*)ScratchPad + strlen((char*)ScratchPad), IP_Header->DestIP.ip32);
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _strlen
	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
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldi R24,<_ScratchPad
	ldi R25,>_ScratchPad
	add R16,R24
	adc R17,R25
	xcall _IP_Str
	.dbline 193
; 	if (!SendDebugStr((char*)ScratchPad)) return;
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L68
	.dbline 193
	xjmp L13
L68:
	.dbline 195
; 
; 	if (!SendDebugStr("\n")) return;
	ldi R16,<L72
	ldi R17,>L72
	xcall _SendDebugStr
	tst R16
	brne L70
	.dbline 195
	xjmp L13
L70:
	.dbline 199
; 
; 	// display any header options
; 
; 	i = HeaderIdx;													// index of header
	movw R20,R10
	.dbline 200
; 	j = (int)(IP_Header->VerLen & 0x0f);							// j = length of header in 32-bit dwords
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R24,z+0
	clr R25
	andi R24,15
	andi R25,0
	movw R10,R24
	.dbline 201
; 	j <<= 2;														//  ... and now in bytes
	lsl R10
	rol R11
	lsl R10
	rol R11
	.dbline 202
; 	j += i;															// point to data (immediately follows the IP header)
	add R10,R20
	adc R11,R21
	.dbline 203
; 	i += sizeof(T_IP_Header);										// point to header options
	subi R20,236  ; offset = 20
	sbci R21,255
	xjmp L74
L73:
	.dbline 205
; 	while (i < j)													//
; 	{																// go thru each IP header option
	.dbline 206
; 		type = MainBuffer[i++];										// option type
	movw R2,R20
	subi R20,255  ; offset = 1
	sbci R21,255
	ldi R24,<_MainBuffer
	ldi R25,>_MainBuffer
	movw R30,R2
	add R30,R24
	adc R31,R25
	ldd R14,z+0
	.dbline 207
; 		len = 0;													//
	clr R12
	.dbline 208
; 		if (type >= 2) len = MainBuffer[i++];						// option length
	mov R24,R14
	cpi R24,2
	brlo L76
	.dbline 208
	movw R2,R20
	subi R20,255  ; offset = 1
	sbci R21,255
	ldi R24,<_MainBuffer
	ldi R25,>_MainBuffer
	movw R30,R2
	add R30,R24
	adc R31,R25
	ldd R12,z+0
L76:
	.dbline 210
; 
; 		if (!SendDebugRStr(ip_str14)) return;
	ldi R16,<_ip_str14
	ldi R17,>_ip_str14
	xcall _SendDebugRStr
	tst R16
	brne L78
	.dbline 210
	xjmp L13
L78:
	.dbline 211
; 		if (type < 2)
	mov R24,R14
	cpi R24,2
	brsh L80
	.dbline 212
; 			sprintf((char*)ScratchPad, "%u\n", type);
	mov R2,R24
	clr R3
	std y+1,R3
	std y+0,R2
	ldi R18,<L82
	ldi R19,>L82
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	xjmp L81
L80:
	.dbline 214
; 		else
; 			sprintf((char*)ScratchPad, "%u  len:%u\n", type, len);
	mov R2,R12
	clr R3
	std y+3,R3
	std y+2,R2
	mov R2,R14
	clr R3
	std y+1,R3
	std y+0,R2
	ldi R18,<L83
	ldi R19,>L83
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
L81:
	.dbline 215
; 		if (!SendDebugStr((char*)ScratchPad)) return;
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L84
	.dbline 215
	xjmp L13
L84:
	.dbline 217
; 
; 		if (!type) break;											// end of option list
	tst R14
	brne L86
	.dbline 217
	xjmp L75
L86:
	.dbline 218
; 		if (type == 1) continue;									// no length byte (NOP option)
	mov R24,R14
	cpi R24,1
	brne L88
	.dbline 218
	xjmp L74
L88:
	.dbline 220
; 																	//
; 		if (len < 2) len = 2;										//
	mov R24,R12
	cpi R24,2
	brsh L90
	.dbline 220
	ldi R24,2
	mov R12,R24
L90:
	.dbline 224
	mov R24,R12
	clr R25
	sbiw R24,2
	add R20,R24
	adc R21,R25
	.dbline 225
L74:
	.dbline 204
	cp R20,R10
	cpc R21,R11
	brge X5
	xjmp L73
X5:
L75:
	.dbline 226
; 																	//
; 
; 																	//
; 		i += (len - 2);												//
; 	}																//
; 	i = j;
	movw R20,R10
	.dbline 230
; 
; 	// done
; 
; 	if (!SendDebugRStr(ip_str15)) return;
	ldi R16,<_ip_str15
	ldi R17,>_ip_str15
	xcall _SendDebugRStr
	tst R16
	brne L92
	.dbline 230
	xjmp L13
L92:
	.dbline 231
	movw R2,R22
	sub R2,R20
	sbc R3,R21
	std y+1,R3
	std y+0,R2
	ldi R18,<L82
	ldi R19,>L82
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 232
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L94
	.dbline 232
L94:
	.dbline -2
L13:
	adiw R28,4
	xcall pop_gset5
	.dbline 0 ; func end
	ret
	.dbsym r j 10 I
	.dbsym r i 20 I
	.dbsym r len 12 c
	.dbsym r type 14 c
	.dbsym r TotalBytes 22 I
	.dbsym r HeaderIdx 10 I
	.dbend
	.dbfunc e IP_FireWalled _IP_FireWalled fc
;              i -> R10,R11
;            dw1 -> y+2
	.even
_IP_FireWalled::
	xcall push_gset3
	sbiw R28,6
	.dbline -1
	.dbline 241
; 	sprintf((char*)ScratchPad, "%u\n", TotalBytes - i);
; 	if (!SendDebugStr((char*)ScratchPad)) return;
; }
; 
; #endif
; 
; // **************************************************************************
; // fire wall
; 
; bool IP_FireWalled(void)
; {	// return TRUE is we are fire walling it
	.dbline 246
; 	int	i;
; 	u32	dw1;
; //    u32 dw2;
; 
; 	if (PPP.THEIR_IP.ip32)
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R4,_PPP+17+2
	lds R5,_PPP+17+2+1
	lds R2,_PPP+17
	lds R3,_PPP+17+1
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	breq L97
	.dbline 247
; 	{
	.dbline 248
; 		if (IP_Header->SourceIP.ip32 == PPP.THEIR_IP.ip32) return false; 		// it's the PPP server - allow it
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R6,z+12
	ldd R7,z+13
	ldd R8,z+14
	ldd R9,z+15
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne L100
	.dbline 248
	clr R16
	xjmp L96
L100:
	.dbline 249
; 	}
L97:
	.dbline 250
; 	if (IP_Header->SourceIP.ip32 == PPP.DNS1_IP.ip32) return false;			 	// it's the primary dns server - allow it
	lds R4,_PPP+21+2
	lds R5,_PPP+21+2+1
	lds R2,_PPP+21
	lds R3,_PPP+21+1
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R6,z+12
	ldd R7,z+13
	ldd R8,z+14
	ldd R9,z+15
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne L103
	.dbline 250
	clr R16
	xjmp L96
L103:
	.dbline 251
; 	if (IP_Header->SourceIP.ip32 == PPP.DNS2_IP.ip32) return false; 			// it's the secondary dns server - allow it
	lds R4,_PPP+25+2
	lds R5,_PPP+25+2+1
	lds R2,_PPP+25
	lds R3,_PPP+25+1
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R6,z+12
	ldd R7,z+13
	ldd R8,z+14
	ldd R9,z+15
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne L106
	.dbline 251
	clr R16
	xjmp L96
L106:
	.dbline 253
; 																				//
; 	for (i = 0; ; i++)
	clr R10
	clr R11
L109:
	.dbline 254
; 	{
	.dbline 255
; 		rmemcpy((char*)&dw1, AllowedIP[i], 4);									//
	ldi R24,4
	ldi R25,0
	std y+1,R25
	std y+0,R24
	ldi R16,4
	ldi R17,0
	movw R18,R10
	xcall empy16s
	movw R18,R16
	ldi R24,<_AllowedIP
	ldi R25,>_AllowedIP
	add R18,R24
	adc R19,R25
	movw R16,R28
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _rmemcpy
	.dbline 256
; 		if (!dw1) break;														// end of list
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+2
	ldd R3,z+3
	ldd R4,z+4
	ldd R5,z+5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L113
	.dbline 256
	xjmp L111
L113:
	.dbline 257
; 		if (IP_Header->SourceIP.ip32 == dw1) return false;						// allow it
	movw R30,R28
	ldd R2,z+2
	ldd R3,z+3
	ldd R4,z+4
	ldd R5,z+5
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R6,z+12
	ldd R7,z+13
	ldd R8,z+14
	ldd R9,z+15
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne L115
	.dbline 257
	clr R16
	xjmp L96
L115:
	.dbline 258
L110:
	.dbline 253
	movw R24,R10
	adiw R24,1
	movw R10,R24
	.dbline 253
	xjmp L109
L111:
	.dbline 266
; 	}
; 
; //	rmemcpy((char*)&dw1, SubnetMask, 4);										//
; //	dw2 = IP_Header->SourceIP.ip32 & dw1;										//
; //	dw1 &= PPP.OUR_IP.ip32;														//
; //	if (dw1 != dw2) return true;												// different subnet - firewall it
; 
; //	return false;																	// let it thru
; 	return true;																	// firewall it
	ldi R16,1
	.dbline -2
L96:
	adiw R28,6
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r i 10 I
	.dbsym l dw1 2 l
	.dbend
	.dbfunc e IP_Checksum _IP_Checksum fl
;              q -> R10,R11
;       checksum -> y+0
;              i -> R12,R13
;            len -> R14,R15
;              p -> R12,R13
	.even
_IP_Checksum::
	xcall push_gset5
	movw R14,R18
	movw R12,R16
	sbiw R28,4
	.dbline -1
	.dbline 273
; }
; 
; // **************************************************************************
; // Calculate a checksum - used in IP packets
; 
; u32 IP_Checksum(char *p, u16 len)
; {	// this one REALLY needs to be as fast as possible - best to do this in assembler code
	.dbline 275
; 	register u16	i;
; 	register u32	checksum = 0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	std z+0,R20
	std z+1,R21
	std z+2,R22
	std z+3,R23
	.dbline 278
; 	register u16	*q;
; 
; 	if (!p) return 0;
	tst R12
	brne L118
	tst R13
	brne L118
X6:
	.dbline 278
	ldi R16,0
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xjmp L117
L118:
	.dbline 279
; 	if (len == 0) return 0;
	tst R14
	brne L120
	tst R15
	brne L120
X7:
	.dbline 279
	ldi R16,0
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xjmp L117
L120:
	.dbline 281
; 
; 	q = (u16*)p;
	movw R10,R12
	.dbline 283
	clr R12
	clr R13
	xjmp L125
L122:
	.dbline 283
	movw R30,R10
	ld R16,Z+

⌨️ 快捷键说明

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