mirror of
https://github.com/A2osX/A2osX.git
synced 2024-12-26 11:30:07 +00:00
Kernel 0.9.2
This commit is contained in:
parent
f5a068fa2b
commit
e45693c1ae
@ -71,6 +71,23 @@ A2osX.S.XY .EQ $E1
|
||||
A2osX.S.NIC .EQ $E2
|
||||
A2osX.S.DISABLE .EQ $FF
|
||||
*--------------------------------------
|
||||
* A2osX.SYSCALL Constants
|
||||
*--------------------------------------
|
||||
AF.LOCAL .EQ 0
|
||||
AF.INET .EQ 2
|
||||
AF.APPLETALK .EQ 4
|
||||
*--------------------------------------
|
||||
O.RDONLY .EQ %00000001
|
||||
O.WRONLY .EQ %00000010
|
||||
O.RDWR .EQ %00000011
|
||||
O.APPEND .EQ %00000100
|
||||
O.TEXT .EQ %00001000
|
||||
O.CREATE .EQ %10000000
|
||||
*--------------------------------------
|
||||
SEEK.SET .EQ $00
|
||||
SEEK.CUR .EQ $02
|
||||
SEEK.END .EQ $04
|
||||
*--------------------------------------
|
||||
* A2osX.SYSCALL Functions Indexes
|
||||
*--------------------------------------
|
||||
* .EQ $00
|
||||
@ -86,11 +103,6 @@ SYS.OpenDir .EQ $10
|
||||
SYS.ReadDir .EQ $12
|
||||
SYS.CloseDir .EQ $14
|
||||
SYS.Open .EQ $16
|
||||
SYS.Open.RDONLY .EQ %00000001
|
||||
SYS.Open.WRONLY .EQ %00000010
|
||||
SYS.Open.RDWR .EQ %00000011
|
||||
SYS.Open.APPEND .EQ %00000100
|
||||
SYS.Open.CREATE .EQ %10000000
|
||||
SYS.Close .EQ $18
|
||||
SYS.Read .EQ $1A
|
||||
SYS.Write .EQ $1C
|
||||
@ -106,19 +118,11 @@ SYS.FGetS .EQ $2C
|
||||
* .EQ $2E
|
||||
|
||||
SYS.FOpen .EQ $30
|
||||
SYS.FOpen.R .EQ $01 Open For Read
|
||||
SYS.FOpen.W .EQ $02 Open For Write
|
||||
SYS.FOpen.A .EQ $04 Append
|
||||
SYS.FOpen.T .EQ $08 Open/Append in Text mode
|
||||
SYS.FOpen.X .EQ $80 Create if not exists
|
||||
SYS.FClose .EQ $32
|
||||
SYS.FRead .EQ $34
|
||||
SYS.FWrite .EQ $36
|
||||
SYS.FFlush .EQ $38
|
||||
SYS.FSeek .EQ $3A
|
||||
SYS.FSeek.SET .EQ $00
|
||||
SYS.FSeek.CUR .EQ $02
|
||||
SYS.FSeek.END .EQ $04
|
||||
SYS.FTell .EQ $3C
|
||||
SYS.FEOF .EQ $3E
|
||||
|
||||
|
@ -39,21 +39,23 @@ LIBTCPIP.DNS.GetCache .EQ 26
|
||||
LIBTCPIP.HST.GetByName .EQ 28
|
||||
LIBTCPIP.HST.GetByAddr .EQ 30
|
||||
|
||||
LIBTCPIP.SKT.New .EQ 32
|
||||
LIBTCPIP.SKT.Close .EQ 34
|
||||
LIBTCPIP.SKT.GetTable .EQ 36
|
||||
LIBTCPIP.SKT.Get .EQ 38
|
||||
LIBTCPIP.SKT.Socket .EQ 32
|
||||
LIBTCPIP.SKT.Bind .EQ 34
|
||||
LIBTCPIP.SKT.Connect .EQ 36
|
||||
LIBTCPIP.SKT.Listen .EQ 38
|
||||
|
||||
LIBTCPIP.SKT.Accept .EQ 40
|
||||
LIBTCPIP.SKT.MkNod .EQ 42
|
||||
LIBTCPIP.SKT.Close .EQ 42
|
||||
|
||||
LIBTCPIP.SKT.Read .EQ 44
|
||||
LIBTCPIP.SKT.Write .EQ 46
|
||||
LIBTCPIP.SKT.Rcvd .EQ 48
|
||||
LIBTCPIP.SKT.Recv .EQ 48
|
||||
LIBTCPIP.SKT.Send .EQ 50
|
||||
|
||||
LIBTCPIP.SKT.RcvdFrom .EQ 52
|
||||
LIBTCPIP.SKT.RecvFrom .EQ 52
|
||||
LIBTCPIP.SKT.SendTo .EQ 54
|
||||
|
||||
LIBTCPIP.SKT.GetTable .EQ 56
|
||||
*--------------------------------------
|
||||
ERR.SKT.OOS .EQ $BF
|
||||
ERR.SKT.BUSY .EQ $BE
|
||||
@ -110,20 +112,23 @@ S.DNSCACHE.IP .EQ 8
|
||||
*
|
||||
S.DNSCACHE .EQ 12
|
||||
*--------------------------------------
|
||||
S.SOCKADDR.ADDR .EQ 0
|
||||
S.SOCKADDR.PORT .EQ 4
|
||||
S.SOCKADDR.AF .EQ 0
|
||||
|
||||
S.SOCKADDR.ADDR .EQ 2
|
||||
S.SOCKADDR.PORT .EQ 6
|
||||
*
|
||||
S.SOCKADDR .EQ 6
|
||||
S.SOCKADDR .EQ 8
|
||||
*--------------------------------------
|
||||
S.SOCKET.T .EQ S.FD.SOCK+0
|
||||
S.SOCKET.AF .EQ S.FD.SOCK+0
|
||||
S.SOCKET.T .EQ S.FD.SOCK+1
|
||||
S.SOCKET.T.RAW .EQ 0
|
||||
S.SOCKET.T.DGRAM .EQ 2
|
||||
S.SOCKET.T.STREAM .EQ 4
|
||||
S.SOCKET.T.SEQPACKET .EQ 6
|
||||
|
||||
S.SOCKET.PROTO .EQ S.FD.SOCK+1
|
||||
S.SOCKET.PROTO .EQ S.FD.SOCK+2
|
||||
|
||||
S.SOCKET.O .EQ S.FD.SOCK+2
|
||||
S.SOCKET.O .EQ S.FD.SOCK+3
|
||||
S.SOCKET.O.DEBUG .EQ $01
|
||||
S.SOCKET.O.ACCEPTCONN .EQ $02
|
||||
S.SOCKET.O.REUSEADDR .EQ $04
|
||||
@ -133,10 +138,10 @@ S.SOCKET.O.BROADCAST .EQ $20
|
||||
S.SOCKET.O.USELOOPBACK .EQ $40
|
||||
S.SOCKET.O.LINGER .EQ $80
|
||||
|
||||
S.SOCKET.SRC.ADDR .EQ S.FD.SOCK+4
|
||||
S.SOCKET.SRC.PORT .EQ S.FD.SOCK+8
|
||||
S.SOCKET.DST.ADDR .EQ S.FD.SOCK+10
|
||||
S.SOCKET.DST.PORT .EQ S.FD.SOCK+14
|
||||
S.SOCKET.LOC.ADDR .EQ S.FD.SOCK+4
|
||||
S.SOCKET.LOC.PORT .EQ S.FD.SOCK+8
|
||||
S.SOCKET.REM.ADDR .EQ S.FD.SOCK+10
|
||||
S.SOCKET.REM.PORT .EQ S.FD.SOCK+14
|
||||
*--------------------------------------
|
||||
* Listen type Queue
|
||||
* Raw Type Queue
|
||||
|
@ -3,6 +3,38 @@ PREFIX /A2OSX.BUILD
|
||||
AUTO 4,1
|
||||
.LIST OFF
|
||||
*--------------------------------------
|
||||
FRM.GetTargetSKT
|
||||
ldy #S.TCPUDP.SRCPORT
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.REM.ADDR+S.SOCKADDR.PORT+1
|
||||
iny
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.REM.ADDR+S.SOCKADDR.PORT
|
||||
|
||||
iny #S.TCPUDP.DSTPORT
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.LOC.ADDR+S.SOCKADDR.PORT+1
|
||||
iny
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.LOC.ADDR+S.SOCKADDR.PORT
|
||||
|
||||
ldy #S.IP.SRC+3
|
||||
ldx #3
|
||||
.1 lda (ZPFrameInPtr),y
|
||||
sta SKT.REM.ADDR+S.SOCKADDR.ADDR,x
|
||||
dey
|
||||
dex
|
||||
bpl .1
|
||||
|
||||
ldy #S.IP.DST+3
|
||||
ldx #3
|
||||
.2 lda (ZPFrameInPtr),y
|
||||
sta SKT.LOC.ADDR+S.SOCKADDR.ADDR,x
|
||||
dey
|
||||
dex
|
||||
bpl .2
|
||||
rts
|
||||
*--------------------------------------
|
||||
* FRM.NewIP
|
||||
* In:
|
||||
* Y,A = DataLen
|
||||
|
@ -58,10 +58,10 @@ ICMP.IN.ECHOREP jsr IP.FillSKT.TemplateSrcDstIP
|
||||
|
||||
ldy #S.ICMP.IDENTIFIER
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.Template+S.SOCKET.DST.PORT+1
|
||||
sta SKT.Template+S.SOCKET.REM.PORT+1
|
||||
iny
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.Template+S.SOCKET.DST.PORT
|
||||
sta SKT.Template+S.SOCKET.REM.PORT
|
||||
|
||||
lda hSocketTable
|
||||
>SYSCALL GetMemPtr
|
||||
@ -74,19 +74,19 @@ ICMP.IN.ECHOREP jsr IP.FillSKT.TemplateSrcDstIP
|
||||
cmp #S.SOCKET.T.RAW
|
||||
bne .7
|
||||
|
||||
ldy #S.SOCKET.SRC.ADDR
|
||||
ldy #S.SOCKET.LOC.ADDR
|
||||
|
||||
.4 lda (ZPPtrSKT),y
|
||||
cmp SKT.Template,y
|
||||
bne .7
|
||||
iny
|
||||
cpy #S.SOCKET.SRC.PORT
|
||||
cpy #S.SOCKET.LOC.PORT
|
||||
bne .5
|
||||
|
||||
iny
|
||||
iny
|
||||
|
||||
.5 cpy #S.SOCKET.DST.PORT Compare SRC.ADDR,DST.ADDR,DST.PORT
|
||||
.5 cpy #S.SOCKET.REM.PORT Compare SRC.ADDR,DST.ADDR,DST.PORT
|
||||
bne .4
|
||||
|
||||
lda hFrameIn
|
||||
|
@ -189,23 +189,23 @@ IP.AddSrcDstIPToChecksum
|
||||
IP.FillSKT.TemplateSrcDstIPP
|
||||
ldy #S.TCPUDP.SRCPORT
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.Template+S.SOCKET.DST.PORT+1
|
||||
sta SKT.Template+S.SOCKET.REM.PORT+1
|
||||
iny
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.Template+S.SOCKET.DST.PORT
|
||||
sta SKT.Template+S.SOCKET.REM.PORT
|
||||
|
||||
iny #S.TCPUDP.DSTPORT
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.Template+S.SOCKET.SRC.PORT+1
|
||||
sta SKT.Template+S.SOCKET.LOC.PORT+1
|
||||
iny
|
||||
lda (ZPFrameInPtr),y
|
||||
sta SKT.Template+S.SOCKET.SRC.PORT
|
||||
sta SKT.Template+S.SOCKET.LOC.PORT
|
||||
*--------------------------------------
|
||||
IP.FillSKT.TemplateSrcDstIP
|
||||
ldy #S.IP.SRC+3
|
||||
ldx #3
|
||||
.1 lda (ZPFrameInPtr),y
|
||||
sta SKT.Template+S.SOCKET.DST.ADDR,x
|
||||
sta SKT.Template+S.SOCKET.REM.ADDR,x
|
||||
dey
|
||||
dex
|
||||
bpl .1
|
||||
@ -213,7 +213,7 @@ IP.FillSKT.TemplateSrcDstIP
|
||||
ldy #S.IP.DST+3
|
||||
ldx #3
|
||||
.2 lda (ZPFrameInPtr),y
|
||||
sta SKT.Template+S.SOCKET.SRC.ADDR,x
|
||||
sta SKT.Template+S.SOCKET.LOC.ADDR,x
|
||||
dey
|
||||
dex
|
||||
bpl .2
|
||||
|
@ -23,25 +23,22 @@ SKT.Socket sta FD.SSOCK+S.SOCKET.T save type
|
||||
|
||||
jmp (J.SKT.Socket,x)
|
||||
|
||||
SKT.Socket.RAW
|
||||
ldy #S.SOCKET
|
||||
SKT.Socket.RAW ldy #S.SOCKET
|
||||
bra SKT.Socket.NEW
|
||||
SKT.Socket.DGRAM
|
||||
lda #S.IP.PROTOCOL.UDP
|
||||
sta TmpDWord
|
||||
ldy #S.SOCKET
|
||||
bra SKT.Socket.NEW
|
||||
SKT.Socket.STREAM
|
||||
lda #S.IP.PROTOCOL.TCP
|
||||
sta TmpDWord
|
||||
ldy #S.SOCKET.TCP
|
||||
bra SKT.Socket.NEW
|
||||
SKT.Socket.SEQPACKET
|
||||
lda #S.IP.PROTOCOL.TCP
|
||||
sta TmpDWord
|
||||
ldy #S.SOCKET.TCP
|
||||
|
||||
SKT.Socket.NEW lda #0
|
||||
SKT.Socket.NEW sta FD.SSOCK+S.SOCKET.PROTO
|
||||
lda #0
|
||||
>SYSCALL GetMem0
|
||||
bcs .99
|
||||
>STYA ZPPtrSKT
|
||||
@ -90,63 +87,30 @@ SKT.Socket.NEW lda #0
|
||||
*\--------------------------------------
|
||||
SKT.bind >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
jsr SKT.GetLocAddr
|
||||
|
||||
>PULLW ZPTmpPtr1
|
||||
|
||||
ldy #S.SOCKADDR-1
|
||||
|
||||
.1 lda (ZPTmpPtr1),y
|
||||
sta SKT.ADDRCache,y
|
||||
dey
|
||||
lda SKT.LOC.ADDR+S.SOCKADDR.PORT
|
||||
bne .1
|
||||
ldy SKT.LOC.ADDR+S.SOCKADDR.PORT+1
|
||||
bne .1
|
||||
|
||||
jsr SKT.FindMatching
|
||||
jsr GetDynPort
|
||||
|
||||
sta SKT.LOC.ADDR+S.SOCKADDR.PORT+1
|
||||
stx SKT.LOC.ADDR+S.SOCKADDR.PORT
|
||||
|
||||
.1 jsr SKT.FindMatchingLoc
|
||||
bcc .9
|
||||
|
||||
ldy #S.SOCKET.SRC.ADDR+S.SOCKADDR-1
|
||||
jsr SKT.SetLocAddr
|
||||
|
||||
.2 lda SKT.ADDRCache-S.SOCKET.SRC.ADDR,y
|
||||
sta (ZPTmpPtr1),y
|
||||
bne .7
|
||||
dey
|
||||
bpl .2
|
||||
|
||||
clc
|
||||
rts
|
||||
|
||||
.9 lda #ERR.SKT.BUSY
|
||||
sec
|
||||
rts
|
||||
*--------------------------------------
|
||||
SKT.FindMatching
|
||||
|
||||
ldx #0
|
||||
|
||||
.1 lda SKT.TABLE,x
|
||||
beq .7
|
||||
|
||||
>SYSCALL GetMemPtr
|
||||
>STYA ZPTmpPtr1
|
||||
|
||||
ldy #S.SOCKET.SRC.ADDR+S.SOCKADDR-1
|
||||
|
||||
.2 lda (ZPTmpPtr1),y
|
||||
cmp SKT.ADDRCache-S.SOCKET.SRC.ADDR,y
|
||||
bne .7
|
||||
dey
|
||||
bpl .2
|
||||
|
||||
>LDYA ZPTmpPtr1
|
||||
clc
|
||||
rts
|
||||
|
||||
.7 inx
|
||||
cpx #K.SKTTABLE.SIZE
|
||||
bne .1
|
||||
|
||||
* sec
|
||||
|
||||
.9 rts
|
||||
*/--------------------------------------
|
||||
* # SKT.connect
|
||||
* Iinitiate a connection on a socket
|
||||
@ -164,164 +128,176 @@ SKT.FindMatching
|
||||
SKT.connect >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
>PULLW ZPTmpPtr1 sockaddr
|
||||
jsr SKT.GetRemAddr
|
||||
|
||||
ldy #S.SOCKET.T
|
||||
lda (ZPTmpPtr1),y
|
||||
lda (ZPPtrSKT),y
|
||||
tax
|
||||
jmp (J.SKT.connect,x)
|
||||
|
||||
|
||||
SKT.connect.RAW
|
||||
SKT.connect.DGRAM
|
||||
|
||||
jsr SKT.SetRemAddr
|
||||
|
||||
SKT.connect.STREAM
|
||||
SKT.connect.SEQPACKET
|
||||
|
||||
*/--------------------------------------
|
||||
* # SKT.listen
|
||||
* Create a new socket
|
||||
* ## C
|
||||
* `int listen(hFD fd);`
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `>PUSHW addr`
|
||||
* `lda fd`
|
||||
* `>LIBCALL hLIBTCPIP,LIBTCPIP.socket`
|
||||
* **Out:**
|
||||
* CC: A = hSOCKET
|
||||
* CS: A = EC
|
||||
*\--------------------------------------
|
||||
SKT.listen
|
||||
*/--------------------------------------
|
||||
* # SKT.New
|
||||
* Create a new socket
|
||||
* ## C
|
||||
* `hSOCKET skt.new(void *template);`
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `>PUSHW template`
|
||||
* `>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.New`
|
||||
* **Out:**
|
||||
* CC: A = hSOCKET
|
||||
* CS: A = EC
|
||||
*\--------------------------------------
|
||||
SKT.New >PULLW ZPTmpPtr1
|
||||
ldy #S.SOCKET.SRC.PORT+1
|
||||
lda (ZPTmpPtr1),y
|
||||
dey
|
||||
ora (ZPTmpPtr1),y
|
||||
bne .1
|
||||
|
||||
jsr GetDynPort
|
||||
|
||||
sta (ZPTmpPtr1),y
|
||||
txa
|
||||
iny
|
||||
sta (ZPTmpPtr1),y
|
||||
|
||||
.1 lda hSocketTable
|
||||
>SYSCALL GetMemPtr
|
||||
>STYA ZPTmpPtr2
|
||||
|
||||
lda #$ff
|
||||
sta TmpByte to keep track of any free slot
|
||||
|
||||
ldx #0
|
||||
|
||||
.2 lda (ZPTmpPtr2)
|
||||
beq .4 empty!!!
|
||||
|
||||
cmp (ZPTmpPtr1)
|
||||
bne .5 not same SKT type...try next
|
||||
|
||||
ldy #S.SOCKET.SRC.ADDR
|
||||
|
||||
.3 lda (ZPTmpPtr1),y
|
||||
cmp (ZPTmpPtr2),y
|
||||
bne .5
|
||||
iny
|
||||
cpy #S.SOCKET.DST.PORT+2
|
||||
bne .3
|
||||
|
||||
lda #ERR.SKT.BUSY same one!!!!! busy...
|
||||
sec
|
||||
clc
|
||||
rts
|
||||
|
||||
.4 lda TmpByte
|
||||
bpl .5 already found an empty slot....
|
||||
|
||||
>LDYA ZPTmpPtr2 found one...
|
||||
>STYA ZPPtrSKT save it!
|
||||
stx TmpByte
|
||||
SKT.connect.STREAM
|
||||
>LDYAI K.TCP.WSIZE
|
||||
>SYSCALL getmem
|
||||
bcs SKT.connect.99
|
||||
txa
|
||||
|
||||
.5 lda ZPTmpPtr2
|
||||
clc
|
||||
adc #S.SOCKET
|
||||
sta ZPTmpPtr2
|
||||
bcc .6
|
||||
inc ZPTmpPtr2+1
|
||||
.6 inx
|
||||
cpx #K.SKTTABLE.SIZE
|
||||
bne .2
|
||||
|
||||
lda TmpByte Did we found an empty slot ?
|
||||
bmi .9
|
||||
|
||||
ldy #S.SOCKET-1
|
||||
lda #0
|
||||
|
||||
.70 sta (ZPPtrSKT),y
|
||||
dey
|
||||
cpy #S.SOCKET.HDR-1
|
||||
bne .70
|
||||
|
||||
.7 lda (ZPTmpPtr1),y
|
||||
ldy #S.SOCKET.SQ.hInMem
|
||||
sta (ZPPtrSKT),y
|
||||
dey
|
||||
bpl .7
|
||||
|
||||
lda (ZPPtrSKT)
|
||||
cmp #S.SOCKET.T.STREAM
|
||||
bne .8
|
||||
|
||||
ldy #S.SOCKET.O
|
||||
>LDYAI K.TCP.WSIZE
|
||||
>SYSCALL getmem
|
||||
bcs SKT.connect.99
|
||||
txa
|
||||
|
||||
ldy #S.SOCKET.SQ.hOutMem
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
SKT.connect.SEQPACKET
|
||||
ldy #S.SOCKET.TCP.S
|
||||
lda (ZPPtrSKT),y
|
||||
bne SKT.connect.9
|
||||
|
||||
and #S.SOCKET.O.ACCEPTCONN
|
||||
bne .8 From Listen, do not send SYN packet
|
||||
jsr SKT.SetRemAddr
|
||||
|
||||
jsr SKT.NewTCB
|
||||
bcs .99
|
||||
lda #K.TCP.WSIZE
|
||||
ldy #S.SOCKET.TCP.INFREE
|
||||
sta (ZPPtrSKT),y
|
||||
ldy #S.SOCKET.TCP.OUTFREE
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
lda /K.TCP.WSIZE
|
||||
ldy #S.SOCKET.TCP.INFREE
|
||||
sta (ZPPtrSKT),y
|
||||
ldy #S.SOCKET.TCP.OUTFREE
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
ldy #S.SOCKET.TCP.OUTNEXTSEQ
|
||||
|
||||
.2 lda A2osX.TIMER16-S.SOCKET.TCP.OUTNEXTSEQ,y
|
||||
sta (ZPPtrSKT),y
|
||||
iny
|
||||
cpy #S.SOCKET.TCP.OUTNEXTSEQ+4
|
||||
bne .2
|
||||
|
||||
lda #S.TCP.OPTIONS.SYN
|
||||
jsr TCP.OUT.SendOptA Send SYN
|
||||
bcs .9
|
||||
|
||||
ldy #S.SOCKET.TCP.O
|
||||
lda (ZPPtrSKT),y
|
||||
ora #S.TCP.OPTIONS.SYN
|
||||
jsr TCP.OUT.SendOptA Send SYN,Only for CLIENT conn,or SYN/ACK if coming from LISTEN
|
||||
bcs .99
|
||||
|
||||
ldy #S.SOCKET.TCP.S
|
||||
lda #S.SOCKET.TCP.S.SYNSENT
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
.8 lda TmpByte
|
||||
ora #$80
|
||||
clc
|
||||
.9 rts
|
||||
|
||||
SKT.connect.9 lda #ERR.SKT.BAD
|
||||
sec
|
||||
SKT.connect.99 rts
|
||||
*/--------------------------------------
|
||||
* # SKT.listen
|
||||
* Listen for connections on a socket
|
||||
* ## C
|
||||
* `int listen(hFD fd);`
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `lda fd`
|
||||
* `>LIBCALL hLIBTCPIP,LIBTCPIP.listen`
|
||||
* **Out:**
|
||||
* CS: A = EC
|
||||
*\--------------------------------------
|
||||
SKT.listen >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
ldy #S.SOCKET.T
|
||||
lda (ZPPtrSKT),y
|
||||
cmp #S.SOCKET.T.STREAM+1
|
||||
bcc .9
|
||||
|
||||
ldy #S.SOCKET.TCP.S
|
||||
lda (ZPPtrSKT),y
|
||||
bne .9
|
||||
|
||||
lda #S.SOCKET.TCP.S.LISTEN
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
ldy #S.SOCKET.O
|
||||
lda #S.SOCKET.O.ACCEPTCONN
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
clc
|
||||
rts
|
||||
|
||||
.9 lda #ERR.SKT.OOS
|
||||
.9 lda #ERR.SKT.BAD
|
||||
sec
|
||||
.99 rts
|
||||
rts
|
||||
*/--------------------------------------
|
||||
* # SKT.Accept
|
||||
* Accept a connection on a socket
|
||||
* ## C
|
||||
* `hFD Accept(hFD fd);`
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `lda fd`
|
||||
* `>LIBCALL hLIBTCPIP,LIBTCPIP.accept`
|
||||
* **Out:**
|
||||
* A = hSocket
|
||||
*\--------------------------------------
|
||||
SKT.Accept >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
ldy #S.SOCKET.O
|
||||
lda (ZPPtrSKT),y
|
||||
and #S.SOCKET.O.ACCEPTCONN
|
||||
beq .99
|
||||
|
||||
ldy #S.SOCKET.HQ.TAIL
|
||||
lda (ZPPtrSKT),y
|
||||
ldy #S.SOCKET.HQ.HEAD
|
||||
cmp (ZPPtrSKT),y Queue Empty
|
||||
beq .9 CS
|
||||
|
||||
pha save tail...
|
||||
inc
|
||||
cmp #S.SOCKET.HQ.MAX
|
||||
bne .1
|
||||
|
||||
lda #0
|
||||
|
||||
.1 ldy #S.SOCKET.HQ.TAIL
|
||||
sta (ZPPtrSKT),y
|
||||
pla
|
||||
clc
|
||||
adc #S.SOCKET.HQ
|
||||
tay
|
||||
lda (ZPPtrSKT),y
|
||||
clc
|
||||
rts
|
||||
|
||||
.99 lda #ERR.SKT.BAD
|
||||
sec
|
||||
.9 rts
|
||||
*/--------------------------------------
|
||||
* # SKT.Close
|
||||
* Close socket
|
||||
* **In:**
|
||||
* A = hSocket
|
||||
* **Out:**
|
||||
* Close socket
|
||||
* ## C
|
||||
* `int close(int fd);`
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `lda fd`
|
||||
* `>LIBCALL hLIBTCPIP,LIBTCPIP.close`
|
||||
* **Out:**
|
||||
*\--------------------------------------
|
||||
SKT.Close jsr SKT.Get.I get SKT in ZPPtrSKT, S.SOCKET.T in A
|
||||
bcs .99
|
||||
SKT.Close >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
cmp #S.SOCKET.T.STREAM
|
||||
beq .10 TCP
|
||||
@ -387,146 +363,6 @@ SKT.Close jsr SKT.Get.I get SKT in ZPPtrSKT, S.SOCKET.T in A
|
||||
|
||||
jmp TCP.OUT Try to push FIN/ACK
|
||||
*/--------------------------------------
|
||||
* # SKT.Get
|
||||
* Get Ptr to socket
|
||||
* **In:**
|
||||
* A = hSocket
|
||||
* **Out:**
|
||||
* Y,A = pS.SOCKET
|
||||
*\--------------------------------------
|
||||
SKT.Get jsr SKT.Get.I
|
||||
|
||||
bcs .9
|
||||
|
||||
>LDYA ZPPtrSKT
|
||||
|
||||
.9 rts
|
||||
|
||||
SKT.Get.I and #$7f
|
||||
|
||||
cmp #K.SKTTABLE.SIZE
|
||||
bcs .9
|
||||
|
||||
pha
|
||||
lda hSocketTable
|
||||
>SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
pla
|
||||
beq .8
|
||||
|
||||
stz .1+1
|
||||
lsr
|
||||
ror .1+1
|
||||
lsr
|
||||
ror .1+1
|
||||
lsr
|
||||
ror .1+1
|
||||
|
||||
pha
|
||||
|
||||
lda ZPPtrSKT
|
||||
clc
|
||||
.1 adc #$ff
|
||||
sta ZPPtrSKT
|
||||
|
||||
pla
|
||||
adc ZPPtrSKT+1
|
||||
sta ZPPtrSKT+1
|
||||
|
||||
.8 lda (ZPPtrSKT)
|
||||
beq .9
|
||||
|
||||
clc
|
||||
rts
|
||||
|
||||
.9 lda #ERR.SKT.BAD
|
||||
sec
|
||||
rts
|
||||
*/--------------------------------------
|
||||
* # SKT.GetTable
|
||||
* Get socket table
|
||||
* **In:**
|
||||
* **Out:**
|
||||
* Y,A = pS.SOCKET
|
||||
*\--------------------------------------
|
||||
SKT.GetTable lda hSocketTable
|
||||
>SYSCALL GetMemPtr
|
||||
clc
|
||||
rts
|
||||
*/--------------------------------------
|
||||
* # SKT.Accept
|
||||
* Check for an incoming connection
|
||||
* **In:**
|
||||
* A = hListeningSocket
|
||||
* **Out:**
|
||||
* A = hSocket
|
||||
*\--------------------------------------
|
||||
SKT.Accept jsr SKT.Get.I
|
||||
bcs .9
|
||||
ldy #S.SOCKET.O
|
||||
lda (ZPPtrSKT),y
|
||||
and #S.SOCKET.O.ACCEPTCONN
|
||||
beq .99
|
||||
|
||||
ldy #S.SOCKET.HQ.TAIL
|
||||
lda (ZPPtrSKT),y
|
||||
ldy #S.SOCKET.HQ.HEAD
|
||||
cmp (ZPPtrSKT),y Queue Empty
|
||||
beq .9 CS
|
||||
|
||||
pha save tail...
|
||||
inc
|
||||
cmp #S.SOCKET.HQ.MAX
|
||||
bne .1
|
||||
|
||||
lda #0
|
||||
|
||||
.1 ldy #S.SOCKET.HQ.TAIL
|
||||
sta (ZPPtrSKT),y
|
||||
pla
|
||||
clc
|
||||
adc #S.SOCKET.HQ
|
||||
tay
|
||||
lda (ZPPtrSKT),y
|
||||
clc
|
||||
rts
|
||||
|
||||
.99 lda #ERR.SKT.BAD
|
||||
sec
|
||||
.9 rts
|
||||
*/--------------------------------------
|
||||
* # SKT.MkNod
|
||||
* ## C
|
||||
* `hFD skt.mknod(hSOCKET s);`
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `lda s`
|
||||
* `>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.MkNod`
|
||||
* **Out:**
|
||||
* CC: A = hFD
|
||||
* CS: A = EC
|
||||
*\--------------------------------------
|
||||
SKT.MkNod sta FD.SSOCK+S.FD.SOCK.HSKT
|
||||
|
||||
>LDYAI S.FD.SOCK
|
||||
>SYSCALL getmem0
|
||||
bcs .9
|
||||
|
||||
>STYA ZPTmpPtr1
|
||||
|
||||
ldy #S.FD.SOCK-1
|
||||
|
||||
.2 lda FD.SSOCK,y
|
||||
sta (ZPTmpPtr1),y
|
||||
dey
|
||||
bpl .2
|
||||
|
||||
txa
|
||||
* clc
|
||||
|
||||
.9 rts
|
||||
*/--------------------------------------
|
||||
* # SKT.Read (STREAM)
|
||||
* ## C
|
||||
* `int skt.read(hFD fd, void *buf, int count);`
|
||||
@ -540,13 +376,14 @@ SKT.MkNod sta FD.SSOCK+S.FD.SOCK.HSKT
|
||||
* CC: Y,A = bytes read
|
||||
* CS: A = EC
|
||||
*\--------------------------------------
|
||||
SKT.Read pha
|
||||
SKT.Read >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
>PULLW ZPDataInPtr !!!DataOut trashed when sending ACK in TCP.OUT
|
||||
>PULLW ZPDataInLen !!!use DataInPtr/Len
|
||||
pla
|
||||
|
||||
SKT.Read.I jsr SKT.Get.I
|
||||
bcs .99
|
||||
|
||||
ldy #S.SOCKET.T
|
||||
lda (ZPPtrSKT),y
|
||||
cmp #S.SOCKET.T.STREAM
|
||||
bne .90 bad skt
|
||||
|
||||
@ -590,14 +427,14 @@ SKT.Read.I jsr SKT.Get.I
|
||||
* CC: Y,A = bytes written
|
||||
* CS: A = EC
|
||||
*\--------------------------------------
|
||||
SKT.Write pha
|
||||
SKT.Write >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
>PULLW ZPDataInPtr
|
||||
>PULLW ZPDataInLen
|
||||
pla
|
||||
|
||||
jsr SKT.Get.I
|
||||
bcs .9
|
||||
|
||||
ldy #S.SOCKET.T
|
||||
lda (ZPPtrSKT),y
|
||||
cmp #S.SOCKET.T.STREAM
|
||||
bne .99
|
||||
|
||||
@ -630,14 +467,21 @@ SKT.Write pha
|
||||
sec
|
||||
.9 rts
|
||||
*/--------------------------------------
|
||||
* # SKT.Rcvd (DGRAM,RAW)
|
||||
* **In:**
|
||||
* A = hSocket
|
||||
* **Out:**
|
||||
* A = hFrame
|
||||
* # SKT.Recv (RAW,DGRAM,SEQPACKET)
|
||||
* # SKT.RecvFrom (RAW,DGRAM,SEQPACKET)
|
||||
* hMem recv(hFD fd);
|
||||
* hMem recv(hFD fd, const struct sockaddr *addr);
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `>PUSHW addr` (RecvFrom)
|
||||
* `lda fd`
|
||||
* `>LIBCALL hLIBTCPIP,LIBTCPIP.skt.Recv`
|
||||
* **Out:**
|
||||
* CC: A = hMem
|
||||
* CS: A = EC
|
||||
*\--------------------------------------
|
||||
SKT.Rcvd jsr SKT.Get.I
|
||||
bcs .9
|
||||
SKT.Recv >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
ldy #S.SOCKET.HQ.TAIL
|
||||
lda (ZPPtrSKT),y
|
||||
@ -666,11 +510,14 @@ SKT.Rcvd jsr SKT.Get.I
|
||||
.99 sec
|
||||
.9 rts
|
||||
*/--------------------------------------
|
||||
* # SKT.Send (DGRAM,RAW)
|
||||
* # SKT.Send (RAW,DGRAM,SEQPACKET)
|
||||
* # SKT.SendTo (RAW,DGRAM,SEQPACKET)
|
||||
* ## C
|
||||
* `int skt.send(hFD fd, const void *buf, int count);`
|
||||
* `int skt.sendto(hFD fd, const void *buf, int count, const struct sockaddr *addr);`
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `>PUSHW addr` (SendTo)
|
||||
* `>PUSHWI count`
|
||||
* `>PUSHW buf`
|
||||
* `lda fd`
|
||||
@ -679,13 +526,13 @@ SKT.Rcvd jsr SKT.Get.I
|
||||
* CC: Y,A = bytes written
|
||||
* CS: A = EC
|
||||
*\--------------------------------------
|
||||
SKT.Send pha
|
||||
SKT.Send >SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
>PULLW ZPDataInPtr
|
||||
>PULLW ZPDataInLen
|
||||
pla
|
||||
|
||||
jsr SKT.Get.I
|
||||
bcs SKT.Send.9
|
||||
ldy #S.SOCKET.T
|
||||
lda (ZPPtrSKT),y
|
||||
|
||||
cmp #S.SOCKET.T.DGRAM
|
||||
beq SKT.Send.UDP
|
||||
@ -719,8 +566,152 @@ SKT.Send.UDP.8 jsr SKT.SetFrameOutDstIP
|
||||
jsr SKT.CopyDataInToOut
|
||||
|
||||
jmp FRM.SendIP
|
||||
*/--------------------------------------
|
||||
* # SKT.GetTable
|
||||
* Get socket table
|
||||
* ## C
|
||||
* `void * skt.gettable();`
|
||||
* ## ASM
|
||||
* **In:**
|
||||
* `>LIBCALL hLIBTCPIP,LIBTCPIP.skt.GetTable`
|
||||
* **Out:**
|
||||
*\--------------------------------------
|
||||
SKT.GetTable >LDYA L.SKT.Table
|
||||
clc
|
||||
rts
|
||||
*--------------------------------------
|
||||
* PRIVATE
|
||||
*--------------------------------------
|
||||
SKT.GetLocAddr >PULLW ZPTmpPtr1
|
||||
|
||||
ldy #S.SOCKADDR-1
|
||||
|
||||
.1 lda (ZPTmpPtr1),y
|
||||
sta SKT.LOC.ADDR,y
|
||||
dey
|
||||
bne .1
|
||||
rts
|
||||
*--------------------------------------
|
||||
SKT.GetRemAddr >PULLW ZPTmpPtr1
|
||||
|
||||
ldy #S.SOCKADDR-1
|
||||
|
||||
.1 lda (ZPTmpPtr1),y
|
||||
sta SKT.REM.ADDR,y
|
||||
dey
|
||||
bne .1
|
||||
rts
|
||||
*--------------------------------------
|
||||
SKT.SetLocAddr ldy #S.SOCKET.LOC.PORT+1
|
||||
|
||||
.1 lda SKT.LOC.ADDR-S.SOCKET.LOC.ADDR,y
|
||||
sta (ZPPtrSKT),y
|
||||
dey
|
||||
cpy #S.SOCKET.LOC.ADDR-1
|
||||
bne .1
|
||||
rts
|
||||
*--------------------------------------
|
||||
SKT.SetRemAddr ldy #S.SOCKET.REM.PORT+1
|
||||
|
||||
.1 lda SKT.REM.ADDR-S.SOCKET.REM.ADDR,y
|
||||
sta (ZPPtrSKT),y
|
||||
dey
|
||||
cpy #S.SOCKET.REM.ADDR-1
|
||||
bne .1
|
||||
rts
|
||||
*--------------------------------------
|
||||
SKT.FindMatchingLocRem
|
||||
ldx #0
|
||||
|
||||
.1 lda SKT.TABLE,x
|
||||
beq .8
|
||||
|
||||
>SYSCALL GetMemPtr
|
||||
>STYA ZPTmpPtr1
|
||||
|
||||
ldy #0
|
||||
|
||||
.2 lda (ZPTmpPtr1),y
|
||||
bne .4
|
||||
|
||||
ldy #S.SOCKET.LOC.PORT This Socket is bound to 0.0.0.0,check only LOC port
|
||||
|
||||
.3 lda (ZPTmpPtr1),y
|
||||
|
||||
.4 cmp SKT.LOC.ADDR-S.SOCKET.LOC.ADDR,y
|
||||
bne .8
|
||||
iny
|
||||
cpy #S.SOCKET.REM.ADDR
|
||||
bne .3
|
||||
|
||||
lda SKT.REM.ADDR
|
||||
cmp #$ff FF.FF.FF.FF, Broadcast ?
|
||||
bne .5
|
||||
|
||||
ldy #S.SOCKET.O
|
||||
lda (ZPTmpPtr1),y
|
||||
and #S.SOCKET.O.BROADCAST
|
||||
beq .9 this socket does not accept broadcast
|
||||
|
||||
ldy #S.SOCKET.REM.PORT Boradcast, check port only
|
||||
|
||||
.5 lda (ZPTmpPtr1),y
|
||||
cmp SKT.REM.ADDR-S.SOCKET.REM.ADDR,y
|
||||
bne .9 wrong remote host, exit....
|
||||
iny
|
||||
cpy #S.SOCKET.REM.PORT+2
|
||||
bne .5
|
||||
|
||||
>LDYA ZPTmpPtr1 x = SKT.TABLE index
|
||||
clc
|
||||
rts
|
||||
|
||||
.8 inx
|
||||
cpx #K.SKTTABLE.SIZE
|
||||
bne .1
|
||||
|
||||
.9 sec
|
||||
|
||||
rts
|
||||
*--------------------------------------
|
||||
SKT.FindMatchingLoc
|
||||
|
||||
ldy #S.SOCKET.LOC.PORT+1
|
||||
phy
|
||||
|
||||
ldx #0
|
||||
|
||||
.1 lda SKT.TABLE,x
|
||||
beq .7
|
||||
|
||||
>SYSCALL GetMemPtr
|
||||
>STYA ZPTmpPtr1
|
||||
|
||||
ply
|
||||
phy
|
||||
|
||||
.2 lda (ZPTmpPtr1),y
|
||||
cmp SKT.LOC.ADDR-S.SOCKET.LOC.ADDR,y
|
||||
bne .7
|
||||
dey
|
||||
cpy #S.SOCKET.LOC.ADDR-1
|
||||
bne .2
|
||||
|
||||
ply
|
||||
|
||||
>LDYA ZPTmpPtr1 x = SKT.TABLE index
|
||||
clc
|
||||
rts
|
||||
|
||||
.7 inx
|
||||
cpx #K.SKTTABLE.SIZE
|
||||
bne .1
|
||||
|
||||
ply
|
||||
|
||||
* sec
|
||||
|
||||
.9 rts
|
||||
*--------------------------------------
|
||||
* ZPPtrSKT -> actual socket
|
||||
* A = hSocket or hFrame
|
||||
@ -1239,52 +1230,9 @@ SKT.AckDataToSktOut
|
||||
|
||||
.8 rts
|
||||
*--------------------------------------
|
||||
SKT.NewTCB >LDYAI S.TCB
|
||||
>SYSCALL getmem0
|
||||
bcs .9
|
||||
|
||||
>STYA .4+1
|
||||
txa
|
||||
SKT.NewTCB
|
||||
|
||||
ldy #S.SOCKET.SQ.hTCB
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
lda #K.TCP.WSIZE
|
||||
sta SKT.TCBCache+S.SOCKET.TCP.INFREE
|
||||
sta SKT.TCBCache+S.SOCKET.TCP.OUTFREE
|
||||
lda /K.TCP.WSIZE
|
||||
sta SKT.TCBCache+S.SOCKET.TCP.INFREE+1
|
||||
sta SKT.TCBCache+S.SOCKET.TCP.OUTFREE+1
|
||||
|
||||
ldx #3
|
||||
|
||||
.2 lda A2osX.TIMER16,x
|
||||
sta SKT.TCBCache+S.SOCKET.TCP.OUTNEXTSEQ,x
|
||||
dex
|
||||
bpl .2
|
||||
|
||||
>LDYAI K.TCP.WSIZE
|
||||
>SYSCALL getmem
|
||||
bcs .9
|
||||
txa
|
||||
|
||||
ldy #S.SOCKET.SQ.hInMem
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
>LDYAI K.TCP.WSIZE
|
||||
>SYSCALL getmem
|
||||
bcs .9
|
||||
txa
|
||||
|
||||
ldy #S.SOCKET.SQ.hOutMem
|
||||
sta (ZPPtrSKT),y
|
||||
|
||||
ldx #S.TCB-1
|
||||
|
||||
.3 lda SKT.TCBCache,x
|
||||
.4 sta $ffff,x
|
||||
dex
|
||||
bpl .3
|
||||
|
||||
clc
|
||||
.9 rts
|
||||
@ -1338,7 +1286,7 @@ SKT.Destroy ldy #S.SOCKET.SQ.hOutMem
|
||||
rts
|
||||
*--------------------------------------
|
||||
SKT.SetFrameOutDstIP
|
||||
ldy #S.SOCKET.DST.ADDR
|
||||
ldy #S.SOCKET.REM.ADDR
|
||||
ldx #4
|
||||
|
||||
.1 lda (ZPPtrSKT),y
|
||||
@ -1358,7 +1306,7 @@ SKT.SetFrameOutDstIP
|
||||
rts
|
||||
*--------------------------------------
|
||||
SKT.SetFrameOutTCPUDPPorts
|
||||
ldy #S.SOCKET.SRC.PORT
|
||||
ldy #S.SOCKET.LOC.PORT
|
||||
lda (ZPPtrSKT),y
|
||||
tax
|
||||
iny
|
||||
@ -1369,7 +1317,7 @@ SKT.SetFrameOutTCPUDPPorts
|
||||
txa
|
||||
sta (ZPFrameOutPtr),y
|
||||
|
||||
ldy #S.SOCKET.DST.PORT
|
||||
ldy #S.SOCKET.REM.PORT
|
||||
lda (ZPPtrSKT),y
|
||||
tax
|
||||
iny
|
||||
|
@ -3,80 +3,43 @@ PREFIX /A2OSX.BUILD
|
||||
AUTO 4,1
|
||||
.LIST OFF
|
||||
*--------------------------------------
|
||||
TCP.IN jsr IP.FillSKT.TemplateSrcDstIPP
|
||||
TCP.IN jsr FRM.GetTargetSKT
|
||||
|
||||
jsr SKT.FindMatchingLocRem
|
||||
bcs TCP.IN.JMP.CLOSED no socket, go discard
|
||||
|
||||
lda hSocketTable
|
||||
>SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
ldx #0
|
||||
|
||||
.3 lda (ZPPtrSKT)
|
||||
beq .7
|
||||
cmp #S.SOCKET.T.STREAM
|
||||
bne .7
|
||||
|
||||
ldy #S.SOCKET.SRC.ADDR
|
||||
|
||||
.4 lda SKT.Template,y
|
||||
cmp (ZPPtrSKT),y
|
||||
bne .7 Not for this socket...
|
||||
|
||||
iny
|
||||
cpy #S.SOCKET.SRC.PORT+2
|
||||
bne .4
|
||||
|
||||
ldy #S.SOCKET.O
|
||||
ldy #S.SOCKET.PROTO
|
||||
lda (ZPPtrSKT),y
|
||||
and #S.SOCKET.O.ACCEPTCONN Listening socket?
|
||||
beq .5 no, go check if Dst Match
|
||||
|
||||
ldy #S.TCP.OPTIONS yes, only accept SYN packet
|
||||
lda (ZPFrameInPtr),y
|
||||
|
||||
cmp #S.TCP.OPTIONS.SYN SYN only, if SYN.ACK, pass to regular socket
|
||||
beq TCP.IN.JMP.LISTEN
|
||||
|
||||
.5 ldy #S.SOCKET.DST.ADDR
|
||||
|
||||
.6 lda SKT.Template,y regular socket, check remote ADDR/PORT
|
||||
cmp (ZPPtrSKT),y
|
||||
bne .7
|
||||
iny
|
||||
cpy #S.SOCKET.DST.PORT+2
|
||||
bne .6
|
||||
cmp #S.SOCKET.T.TCP
|
||||
bne TCP.IN.JMP.CLOSED wrong protocol, go discard
|
||||
|
||||
ldy #S.TCP.OPTIONS
|
||||
lda (ZPFrameInPtr),y
|
||||
and #S.TCP.OPTIONS.RST RST ? go Kill this socket.
|
||||
bne TCP.IN.RST
|
||||
and #S.TCP.OPTIONS.RST RST ? go Kill this socket...
|
||||
bne TCP.IN.RST ...and discard frame
|
||||
|
||||
ldy #S.SOCKET.TCP.S
|
||||
lda (ZPPtrSKT),y
|
||||
cmp #S.SOCKET.TCP.S.TIMEWT+1
|
||||
bcs *
|
||||
asl
|
||||
tax
|
||||
|
||||
jmp (J.TCP.IN,x)
|
||||
|
||||
.7 lda ZPPtrSKT
|
||||
clc
|
||||
adc #S.SOCKET
|
||||
sta ZPPtrSKT
|
||||
bcc .8
|
||||
inc ZPPtrSKT+1
|
||||
|
||||
.8 inx
|
||||
cpx #K.SKTTABLE.SIZE
|
||||
bne .3
|
||||
|
||||
.9 clc Discard frame
|
||||
*--------------------------------------
|
||||
TCP.IN.RST jsr SKT.Destroy
|
||||
*--------------------------------------
|
||||
TCP.IN.JMP.CLOSED
|
||||
lda hFrameIn
|
||||
>SYSCALL FreeMem
|
||||
rts
|
||||
*--------------------------------------
|
||||
TCP.IN.RST jmp SKT.Destroy
|
||||
*--------------------------------------
|
||||
TCP.IN.JMP.LISTEN
|
||||
ldy #S.TCP.OPTIONS SYN Received, send SYN.ACK packet
|
||||
lda (ZPFrameInPtr),y
|
||||
cmp #S.TCP.OPTIONS.SYN
|
||||
bne TCP.IN.JMP.CLOSED
|
||||
|
||||
|
||||
lda #S.SOCKET.T.STREAM
|
||||
sta SKT.Template+S.SOCKET.T
|
||||
stz SKT.Template+S.SOCKET.O
|
||||
@ -84,8 +47,6 @@ TCP.IN.JMP.LISTEN
|
||||
lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
|
||||
sta SKT.Template+S.SOCKET.TCP.O
|
||||
|
||||
jsr ARP.AddFromFrameInPtr
|
||||
|
||||
>PUSHW L.SKT.Template
|
||||
|
||||
jsr SKT.New Assign OUTNEXTSEQ
|
||||
@ -99,6 +60,8 @@ TCP.IN.JMP.LISTEN
|
||||
|
||||
bcs .99 Queued successfully ?
|
||||
|
||||
jsr ARP.AddFromFrameInPtr
|
||||
|
||||
.1 lda #$ff
|
||||
sta ZPPtrSKT
|
||||
.2 lda #$ff
|
||||
@ -290,9 +253,6 @@ TCP.IN.JMP.CLOSING
|
||||
*--------------------------------------
|
||||
TCP.IN.JMP.TIMEWT
|
||||
*--------------------------------------
|
||||
TCP.IN.JMP.CLOSED
|
||||
jmp SKT.Destroy
|
||||
*--------------------------------------
|
||||
TCP.IN.ACKTheSYN
|
||||
ldy #S.TCP.SEQNUM+3 Get Remote SEQ
|
||||
ldx #3
|
||||
|
@ -3,63 +3,25 @@ PREFIX /A2OSX.BUILD
|
||||
AUTO 4,1
|
||||
.LIST OFF
|
||||
*--------------------------------------
|
||||
UDP.IN jsr IP.FillSKT.TemplateSrcDstIPP
|
||||
UDP.IN jsr FRM.GetTargetSKT
|
||||
|
||||
jsr SKT.FindMatchingLocRem
|
||||
bcs .9
|
||||
|
||||
lda hSocketTable
|
||||
>SYSCALL GetMemPtr
|
||||
>STYA ZPPtrSKT
|
||||
|
||||
ldx #0
|
||||
|
||||
.3 lda (ZPPtrSKT)
|
||||
beq .7
|
||||
cmp #S.SOCKET.T.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
|
||||
ldy #S.SOCKET.PROTO
|
||||
lda (ZPPtrSKT),y
|
||||
cmp #S.IP.PROTOCOL.UDP
|
||||
bne .9
|
||||
|
||||
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
|
||||
|
||||
.9 lda hFrameIn Q full, discard...
|
||||
>SYSCALL FreeMem
|
||||
rts
|
||||
.8 rts
|
||||
*--------------------------------------
|
||||
MAN
|
||||
SAVE /A2OSX.SRC/LIB/LIBTCPIP.S.UDP
|
||||
|
@ -4,7 +4,7 @@ AUTO 4,1
|
||||
.LIST OFF
|
||||
.OP 65C02
|
||||
.OR $2000
|
||||
.TF LIB/LIBTCPIP.O
|
||||
.TF LIB/LIBTCPIP
|
||||
*--------------------------------------
|
||||
.INB INC/MACROS.I
|
||||
.INB INC/A2OSX.I
|
||||
@ -71,18 +71,23 @@ CS.START cld
|
||||
.DA HST.GETBYNAME
|
||||
.DA HST.GETBYADDR
|
||||
|
||||
.DA SKT.New
|
||||
.DA SKT.Close
|
||||
.DA SKT.GetTable
|
||||
.DA SKT.Get
|
||||
.DA SKT.Socket
|
||||
.DA SKT.Bind
|
||||
.DA SKT.Connect
|
||||
.DA SKT.Listen
|
||||
|
||||
.DA SKT.Accept
|
||||
.DA SKT.MkNod
|
||||
.DA SKT.Close
|
||||
|
||||
.DA SKT.Read
|
||||
.DA SKT.Write
|
||||
.DA SKT.Rcvd
|
||||
.DA SKT.Send
|
||||
|
||||
.DA SKT.RcvdFrom
|
||||
.DA SKT.SendTo
|
||||
|
||||
.DA SKT.GetTable
|
||||
*--------------------------------------
|
||||
L.DEVNAME .DA DEVNAME
|
||||
L.MSG.DEV.KO .DA MSG.DEV.KO
|
||||
@ -110,6 +115,7 @@ L.DNS.MSG .DA DNS.MSG
|
||||
L.ARP.CACHE .DA ARP.CACHE
|
||||
L.DNS.CACHE .DA DNS.CACHE
|
||||
L.SKT.Template .DA SKT.Template
|
||||
L.SKT.Table .DA SKT.Table
|
||||
L.HST.SScanF .DA HST.SScanF
|
||||
L.IOCTL .DA IOCTL
|
||||
L.DCB.NIC .DA DCB.NIC
|
||||
@ -142,13 +148,7 @@ LIB.LOAD ldx RefCount
|
||||
jsr ARP.CLEAR
|
||||
|
||||
jsr DNS.CLEAR
|
||||
|
||||
>LDYAI K.SKTTABLE.SIZE*S.SOCKET
|
||||
>SYSCALL getmem0
|
||||
bcs .9
|
||||
|
||||
stx hSocketTable
|
||||
|
||||
|
||||
jsr CFG.Init
|
||||
bcs .9
|
||||
|
||||
@ -161,18 +161,13 @@ LIB.UNLOAD dec RefCount
|
||||
bne LIB.UNLOAD.8
|
||||
|
||||
lda IPCFG+S.IPCFG.hFD
|
||||
beq .1
|
||||
beq LIB.UNLOAD.8
|
||||
|
||||
>PUSHWI 0
|
||||
>PUSHBI IOCTL.CLOSE
|
||||
lda IPCFG+S.IPCFG.hFD
|
||||
>SYSCALL IOCTL
|
||||
|
||||
.1 lda hSocketTable
|
||||
beq LIB.UNLOAD.8
|
||||
|
||||
>SYSCALL FreeMem
|
||||
|
||||
|
||||
LIB.UNLOAD.8 clc
|
||||
rts
|
||||
*--------------------------------------
|
||||
@ -290,6 +285,8 @@ CFG.hCfgFile .BS 1
|
||||
CFG.IP .BS 4
|
||||
CFG.HOSTS.SScanF .AZ "%d.%d.%d.%d %s %s"
|
||||
*--------------------------------------
|
||||
SKT.TABLE .BS K.SKTTABLE.SIZE
|
||||
*--------------------------------------
|
||||
FD.SSOCK .BS 1 S.FD.HANDLER
|
||||
.DA #S.FD.T.SSOCK
|
||||
.BS 1 S.FD.SOCK.HSKT
|
||||
@ -298,6 +295,7 @@ FD.SSOCK .BS 1 S.FD.HANDLER
|
||||
.DA #LIBTCPIP.SKT.Read
|
||||
.DA #LIBTCPIP.SKT.Write
|
||||
.DA #0 S.FD.SOCK.STATUS
|
||||
.DA #AF.INET S.SOCKET.AF
|
||||
.BS 1 S.SOCKET.T
|
||||
.BS 1 S.SOCKET.PROTO
|
||||
FD.SSOCK.SIZE .EQ *-FD.SSOCK
|
||||
@ -358,19 +356,15 @@ FRM.QUEUE.Retry .BS K.FRMQUEUE.SIZE
|
||||
FRM.QUEUE.LenL .BS K.FRMQUEUE.SIZE
|
||||
FRM.QUEUE.LenH .BS K.FRMQUEUE.SIZE
|
||||
*--------------------------------------
|
||||
SKT.TABLE .BS K.SKTTABLE.SIZE
|
||||
*--------------------------------------
|
||||
RefCount .DA #0
|
||||
hSocketTable .BS 1
|
||||
DYNPORT.LAST .DA K.DYNPORT.START
|
||||
hDNSSocket1 .BS 1
|
||||
hDNSSocket2 .BS 1
|
||||
DNS.TmpCache .BS S.DNSCACHE
|
||||
ARP.TmpCache .BS S.ARP
|
||||
SKT.Template .BS S.SOCKET
|
||||
SKT.TCBCache .BS S.TCB
|
||||
SKT.ADDRCache .BS S.SOCKADDR
|
||||
TmpByte .BS 1
|
||||
SKT.LOC.ADDR .BS S.SOCKADDR
|
||||
SKT.REM.ADDR .BS S.SOCKADDR
|
||||
TmpDWord .BS 4
|
||||
TmpOffset .BS 2
|
||||
hFrameIn .BS 1
|
||||
|
Loading…
Reference in New Issue
Block a user