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

📄 smtp.asm

📁 web51的开发库
💻 ASM
字号:
.nolist.include	"param.inc".list	.datasmtpState:	.ds.b	1smtpCState:	.ds.b	1replyNum:	.ds.b	1	; may be .ds 1 - see Lcase1smtpNo:		.ds.b	1	.comm	fileID, 2	.bitcomm flag_out, 1	.text	.using	0.global sendSMTP.global	smtp.global	openSMTP.global	closeSMTPsendSMTP:	mov	smtpNo, r7	mov	smtpState, #0	sjmp	processSMTPsmtp:	;;process max. data_len bytes	mov	a,data_len+1	;LSB	mov	workreg+3,a	;LSB	mov	workreg+2,data_len	;MSB	orl	a,data_len	;MSB	jz	noSMTPsgetbuf:mov	Timeout1,#ethtiming	;restart retry timer;;  Retry1   = ETHRETRY1;	mov	Retry1,#ETHRETRY1	setb	flag1retry		;; NEW data in packet, send delayed Ack	LCALL   pcode;;  copy_r2s (buf, data_addr, sizeof(buf));      	.pcode pr2s BYTE buf, @data_addr, #BYTE sizeofbuf	;copy smtp data;;  data_addr += sizeof(buf);      	.pcode paddwi BYTE data_addr, #BYTE sizeofbuf	.byte 0	mov	R0,#buf-1tnxtin:inc	R0	mov	a,#(buf + sizeofbuf)	xrl	a,R0	jz	sgetbuf	mov	a,data_len	jnz	tdata	mov	a,data_len+1	jnz	tdata	sjmp	tallsendtdata:	mov	a,@r0	lcall	processSMTP;;  data_len--;	mov	a,data_len+1	; LSB	dec	a	mov	data_len+1,a	cjne	A,#0xFF,tnxtin	dec	data_len	; MSB	sjmp	tnxtintallsend:; Acknowledge only processed data;;  tx_eth_pkt.pkt.ip.ipdata.tcp.tcpheader.Ack =;;    rcvSeq + sendbytes;	mov	R7,workreg+3	;LSB	mov	R6,workreg+2	;MSB      	ljmp	AckBytesnoSMTP:	retopenSMTP:	setb	flag_out	retcloseSMTP:	mov	smtpState, #0	retprocessSMTP:	mov	r7,a;  switch (smtpState) {	mov	a,smtpState	add	a,acc		;sjmp = 2 byte	add	a,smtpState	;ljmp = 3 byte	add	a,#LOW(stateSMTPtable)	push	Acc		;push low addr	mov	a,#0	addc	a,#HIGH(stateSMTPtable)	push	Acc		;push high addr	ret			;and Go!stateSMTPtable:	ljmp	Lcase0	ljmp	Lcase1	ljmp	Lcase2	ljmp	Lcase3	ljmp	Lcase4	ljmp	Lcase5	ljmp	Lcase6	ljmp	Lcase7; case 0:Lcase0:	;; open connection to SMTP server (port 25)	mov	r7,#LASTSTACK1	lcall	changeStack	mov	a,tcpState	jnz	est25ch		;if Connect Established, don't make new	lcall	ConnectTCP1est25ch:flushAndNextCase:	;; flush end of received data	mov	data_len+1,#1	;LSB	mov	data_len,#0	;MSB	;; reset data state machine	mov	smtpCState,#0	;; next SMTP state	inc	smtpState	ret; case 1:Lcase1:	;; wait for REPLY "220 debian.localnet ESMTP..."	lcall	processSMTPcharacter	cjne	A,#3,Lc1	mov	a,replyNum	cjne	A,#LOW(220),Lx1	;; SEND "helo web51"	lcall	send_string	.asciz	"HELO web51\r\n"	sjmp	flushAndNextCaseLx1:Lc1:	ret	; case 2:Lcase2:	;; wait for REPLY "250 debian.localnet Hello web51..."	lcall	processSMTPcharacter	cjne	A,#3,Lc2	mov	a,replyNum	cjne	A,#LOW(250),Lx2	;; SEND "mail from:<robot@web51>"	lcall	send_string	.asciz	"MAIL FROM:"	mov	a, #LOW('f'+'r'+'o'+'m'+'.'+'t'+'x'+'t')	add	a,smtpNo	mov	fileID+1,a	mov	a, #HIGH('f'+'r'+'o'+'m'+'.'+'t'+'x'+'t')	addc	a,#0	mov	fileID,a	lcall	searchfile	;r4	file type				;dptr	file start				;r2r3	file end	jnc	fnd2;	lcall	send_string	.asciz	"ErrFrom\r\n"	sjmp	flushAndNextCasefnd2:	;r2	;MSB file end	;r3	;LSB file end	;dph	;MSB file start	;dpl	;LSB file start	;r5	;filesystem ID	mov	a,r5	lcall	sendFile	lcall	send_string	.asciz	"\r\n"	sjmp	flushAndNextCaseLx2:Lc2:	ret; case 3:Lcase3:	;; wait for REPLY "250 <robot@web51>..."	lcall	processSMTPcharacter	cjne	A,#3,Lc3	mov	a,replyNum	cjne	A,#LOW(250),Lx3	;; SEND "rcpt to:<robot@debian.localnet>"	lcall	send_string	.asciz	"RCPT TO:"	mov	a, #LOW('t'+'o'+'.'+'t'+'x'+'t')	add	a,smtpNo	mov	fileID+1,a	mov	a, #HIGH('t'+'o'+'.'+'t'+'x'+'t')	addc	a,#0	mov	fileID, a	lcall	searchfile	;r4	file type				;dptr	file start				;r2r3	file end	jnc	found3;	lcall	send_string	.asciz	"ErrTo\r\n"	ljmp	flushAndNextCasefound3:	;r2	;MSB file end	;r3	;LSB file end	;dph	;MSB file start	;dpl	;LSB file start	;r5	;filesystem ID	mov	a,r5	lcall	sendFile	lcall	send_string	.asciz	"\r\n"	ljmp	flushAndNextCaseLx3:Lc3:	ret; case 4:Lcase4:	;; wait for REPLY "250 <robot@debian.localnet>..."	lcall	processSMTPcharacter	cjne	A,#3,Lc4	mov	a,replyNum	cjne	A,#LOW(250),Lx4	;; SEND "data"	lcall	send_string	.asciz	"DATA\r\n"	ljmp	flushAndNextCaseLx4:Lc4:	ret; case 5:Lcase5:	;; wait for REPLY "354 Enter message, ..."	lcall	processSMTPcharacter	cjne	A,#3,Lc5	mov	a,replyNum	cjne	A,#LOW(354),Lx5	;; SEND "Subject: Ahoj<CR><LF>"	;; SEND "MESSAGE<CR><LF>"	;; SEND ".<CR><LF>"	lcall	send_string	.asciz	"Subject: "	mov	a, #LOW('s'+'u'+'b'+'j'+'e'+'c'+'t'+'.'+'t'+'x'+'t')	add	a,smtpNo	mov	fileID+1,a	mov	a, #HIGH('s'+'u'+'b'+'j'+'e'+'c'+'t'+'.'+'t'+'x'+'t')	addc	a,#0	mov	fileID, a	lcall	searchfile	;r4	file type				;dptr	file start				;r2r3	file end	jnc	found5a;	lcall	send_string	.asciz	"ErrSubject\r\n.\r\n"	ljmp	flushAndNextCasefound5a:	;r2	;MSB file end	;r3	;LSB file end	;dph	;MSB file start	;dpl	;LSB file start	;r5	;filesystem ID	mov	a,r5	lcall	sendFile	lcall	send_string	.asciz	"\r\n"	mov	a, #LOW('t'+'e'+'x'+'t'+'.'+'t'+'x'+'t')	add	a,smtpNo	mov	fileID+1,a	mov	a, #HIGH('t'+'e'+'x'+'t'+'.'+'t'+'x'+'t')	addc	a,#0	mov	fileID, a	lcall	searchfile	;r4	file type				;dptr	file start				;r2r3	file end	jnc	found5b;	lcall	send_string	.asciz	"ErrText\r\n.\r\n"	ljmp	flushAndNextCasefound5b:	;r2	;MSB file end	;r3	;LSB file end	;dph	;MSB file start	;dpl	;LSB file start	;r5	;filesystem ID	mov	a,r5	lcall	sendFile	lcall	send_string	.asciz	"\r\n.\r\n"	ljmp	flushAndNextCaseLx5:Lc5:	ret; case 6:Lcase6:	;; wait for REPLY "250 OK id=..."	lcall	processSMTPcharacter	cjne	A,#3,Lc6	mov	a,replyNum	cjne	A,#LOW(250),Lx6	lcall	send_string	;; SEND "quit"	.asciz	"QUIT\r\n"	ljmp	flushAndNextCaseLx6:Lc6:	ret; case 7:Lcase7:	;; wait for REPLY "221 debian.localnet closing connection..."	lcall	processSMTPcharacter	cjne	A,#3,Lc7	mov	a,replyNum	cjne	A,#LOW(221),Lx7	;; close connection to SMTP server	lcall	CloseTCP1	mov	smtpState, #0Lx7:Lc7:	retprocessSMTPcharacter:;  switch (smtpCState) {	mov	a,smtpCState	add	a,acc		;sjmp = 2 byte	add	a,#LOW(stateCSMTPtable)	push	Acc		;push low addr	mov	a,#0	addc	a,#HIGH(stateCSMTPtable)	push	Acc		;push high addr	ret			;and Go!stateCSMTPtable:	sjmp	LCcase0	sjmp	LCcase1	sjmp	LCcase2	sjmp	LCcase3;  case 0:LCcase0:;; skip non numeric on begin of line	mov	a,r7	add	a,#-'0'	cjne	a,#9+1,.+3	jnc	Lbreak		; out of range '0'..'9'	mov	replyNum,a	inc	smtpCState		; smtpCState = 1;  case 3:LCcase3:;; end of runLbreak:	mov	a,smtpCState	ret			; return smtpCState;  case 1:LCcase1:mov	a,r7	add	a,#-'0'	cjne	a,#9+1,.+3	jnc	Lend1	xch	a,replyNum	mov	B,#10	mul	ab	add	a,replyNum	mov	replyNum,a;	mov	replyNum+1,b	sjmp	LbreakLend1:	inc	smtpCState		; smtpCState = 2;  case 2: LCcase2:;; wait for control char	mov	a,r7	anl	a,#0xF0	jz	Lend2	sjmp	LbreakLend2:	inc	smtpCState		; smtpCState = 3	sjmp	Lbreak	.section fast, #alloc;*************************************************************	jnb	flag_out, noout	clr	flag_out	lcall	OutTCP1			;Syn Ack from MAIL server, REPLY Acknoout:	;; end

⌨️ 快捷键说明

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