A2osX/LIB/LIBTCPIP.S.UDP.txt
2018-07-26 08:03:49 +02:00

177 lines
3.3 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
UDP.IN jsr IP.FillSKT.TemplateSrcDst
ldy #S.UDP.SRCPORT
lda (ZPFrameInPtr),y
sta SKT.Template+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameInPtr),y
sta SKT.Template+S.SOCKET.DST.PORT
ldy #S.UDP.DSTPORT
lda (ZPFrameInPtr),y
sta SKT.Template+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameInPtr),y
sta SKT.Template+S.SOCKET.SRC.PORT
lda hSocketTable
>SYSCALL GetMemPtr
>STYA ZPPtrSKT
ldx #0
.3 lda (ZPPtrSKT)
beq .7
cmp #S.SOCKET.SOCK.DGRAM
bne .7
ldy #S.SOCKET.SRC.ADDR
lda (ZPPtrSKT),y SOCKET.SRC.ADDR=0.0.0.0 ?
bne .41
ldy #S.SOCKET.SRC.PORT yes, do not check if IP match
.4 lda (ZPPtrSKT),y
.41 cmp SKT.Template,y
bne .7
iny
cpy #S.SOCKET.DST.ADDR
bne .4
lda (ZPPtrSKT),y SOCKET.DST.ADDR=FF.FF.FF.FF ?
cmp #$FF
bne .51
ldy #S.SOCKET.DST.PORT yes, do not check if IP match
.5 lda (ZPPtrSKT),y
.51 cmp SKT.Template,y
bne .7
iny
cpy #S.SOCKET.DST.PORT+2
bne .5
lda hFrameIn
jsr SKT.AddToQueueA
bcs .9 Q full, discard...
rts DO NOT Discard this queued frame
.7 lda ZPPtrSKT
clc
adc #S.SOCKET
sta ZPPtrSKT
bcc .8
inc ZPPtrSKT+1
.8 inx
cpx #K.SKTTABLE.SIZE
bne .3
.9 lda hFrameIn
>SYSCALL FreeMem
rts
*--------------------------------------
UDP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM
ldy #S.UDP.CHECKSUM
sta (ZPFrameOutPtr),y
iny
sta (ZPFrameOutPtr),y
>LDYA ZPFrameOutPtr
>STYA ZPTmpPtr1
lda ZPFrameOutLen
sec
sbc #S.IP
sta ZPDataInLen
lda ZPFrameOutLen+1
sbc /S.IP
sta ZPDataInLen+1
clc
ldy #S.UDP.LENGTH
lda (ZPFrameOutPtr),y
* adc #0 RESERVED (all zero)
sta IP.CHECKSUM
iny
lda (ZPFrameOutPtr),y
adc #S.IP.PROTOCOL.UDP
sta IP.CHECKSUM+1
ldy #S.IP.SRC
ldx #4 4 words for SRC & DST IP
.10 lda (ZPFrameOutPtr),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameOutPtr),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
dex
bne .10
ldy #S.IP
.1 jsr DecDataInLen
beq .8
lda (ZPTmpPtr1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
bne .20
inc ZPTmpPtr1+1
.20 jsr DecDataInLen
bne .2
lda #0
bra .21
.2 lda (ZPTmpPtr1),y
.21 adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
bne .1
inc ZPTmpPtr1+1
bra .1
.8 ldy #S.UDP.CHECKSUM
lda IP.CHECKSUM
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameOutPtr),y
iny
lda IP.CHECKSUM+1
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameOutPtr),y
rts
*--------------------------------------
DecDataInLen lda ZPDataInLen
bne .1
lda ZPDataInLen+1
beq .9
dec ZPDataInLen+1
.1 dec ZPDataInLen
lda #$FF Make NZ
.9 rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/LIB/LIBTCPIP.S.UDP
LOAD /A2OSX.SRC/LIB/LIBTCPIP.S
ASM