Kernel version 0.9 : TCPIP, new RAW socket type for ICMP

This commit is contained in:
Rémy GIBERT 2017-01-30 17:30:39 +01:00
parent 1d95ec18e7
commit 8c891ccf04
14 changed files with 331 additions and 271 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -14,7 +14,7 @@ AUTO 6
*-------------------------------------- *--------------------------------------
TIMEOUT.MAX .EQ 20 2 sec. TIMEOUT.MAX .EQ 20 2 sec.
*-------------------------------------- *--------------------------------------
ZPFrameBase .EQ ZPBIN ZPFrameBase .EQ ZPBIN
ZPFrameLen .EQ ZPBIN+2 ZPFrameLen .EQ ZPBIN+2
ZPFramePtr1 .EQ ZPBIN+4 ZPFramePtr1 .EQ ZPBIN+4
ZPIPCfgPtr .EQ ZPBIN+6 ZPIPCfgPtr .EQ ZPBIN+6
@ -36,41 +36,96 @@ CS.START cld
.DA CS.DOEVENT .DA CS.DOEVENT
.DA CS.QUIT .DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP L.LIBTCPIP .DA LIBTCPIP
L.MSG0 .DA MSG0 L.Socket .DA Socket
L.MSG1 .DA MSG1 L.MSG.IPKO .DA MSG.IPKO
L.MSG.USAGE .DA MSG.USAGE
L.MSG.UNKNOWN .DA MSG.UNKNOWN
L.MSG.HOSTOK .DA MSG.HOSTOK
L.MSG2 .DA MSG2 L.MSG2 .DA MSG2
L.MSG3 .DA MSG3 L.MSG3 .DA MSG3
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
CS.INIT >SYSCALL GetArgC CS.INIT >LDYA L.LIBTCPIP
cmp #1
bne .1
lda #SYSMGR.ERRSYN
sec
rts
.1 >LDYA L.LIBTCPIP
>SYSCALL LoadLibYA >SYSCALL LoadLibYA
bcs .9
sta hLIBTCPIP sta hLIBTCPIP
>LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG is TCPIP loaded ? lda (pPs)
bcs .9 ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN >LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG is TCPIP loaded ?
>STYA ZPIPCfgPtr >STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ? lda (ZPIPCfgPtr) Configured ?
bpl .9 bmi CS.RUN.IPOK
ldy #S.IPCFG.HDEV >LDYA L.MSG.IPKO
lda (ZPIPCfgPtr),y >SYSCALL CPrintFYA
sta hDev lda #SYSMGR.ERRSYN
sec
rts
*--------------------------------------
CS.RUN.IPOK >SYSCALL GetArgC
cmp #1
beq .9
jsr Init.Timeout
.2 >PUSHW pData DST.IP
lda #1
>SYSCALL GetArgA
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GETBYNAME
bcc CS.RUN.HOSTOK
>SYSCALL Sleep
jsr Wait.Timeout
bcc .2
lda #1
>SYSCALL GetArgA
>PUSHYA
>LDYA L.MSG.UNKNOWN
bra .99
.9 >LDYA L.MSG.USAGE
.99 >SYSCALL CPrintFYA
lda #SYSMGR.ERRSYN
sec
rts
*--------------------------------------
CS.RUN.HOSTOK lda #1
>SYSCALL GetArgA
>PUSHYA
ldy #DST.IP+3
>PUSHB (pData),y DST.IP+3
dey
>PUSHB (pData),y DST.IP+2
dey
>PUSHB (pData),y DST.IP+1
dey
>PUSHB (pData),y DST.IP
>LDYA L.MSG.HOSTOK
>SYSCALL CPrintFYA
CS.RUN.ECHO ldx #3
ldy #S.IPCFG.IP+3
.1 lda (ZPIPCfgPtr),y
sta Socket.Src.Addr,x
dey
dex
bpl .1
lda A2OSX.RANDOM16 lda A2OSX.RANDOM16
ldy #Identifier sta Socket.Src.Port
sta (pData),y
lda A2OSX.RANDOM16+1 lda A2OSX.RANDOM16+1
iny sta Socket.Src.Port+1
sta (pData),y
lda #0 lda #0
ldy #Sequence ldy #Sequence
@ -78,80 +133,20 @@ CS.INIT >SYSCALL GetArgC
iny iny
sta (pData),y sta (pData),y
lda (pPs) ldy #S.ICMP.SEQUENCE
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
.9 sec
rts
*--------------------------------------
CS.RUN jsr Init.Timeout
.1 >PUSHW pData DST.IP
lda #1
>SYSCALL GetArgA
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GETBYNAME
bcc .2
>SYSCALL Sleep
jsr Wait.Timeout
bcc .1
lda #1
>SYSCALL GetArgA
>PUSHYA
>LDYA L.MSG0
>SYSCALL CPrintFYA
lda #1
sec
rts
.2 lda #1
>SYSCALL GetArgA
>PUSHYA
ldy #3
>PUSHB (pData),y DST.IP+3
dey
>PUSHB (pData),y DST.IP+2
dey
>PUSHB (pData),y DST.IP+1
>PUSHB (pData) DST.IP
>LDYA L.MSG1
>SYSCALL CPrintFYA
CS.RUN.ECHO >LIBCALL hLIBTCPIP,LIBTCPIP.NEW.ICMP.FRAME
>STYA ZPFrameBase
txa
ldy #hFrame
sta (pData),y
lda #S.ICMP+32-2
sta (ZPFrameBase)
lda /S.ICMP+32-2
ldy #1
sta (ZPFrameBase),y sta (ZPFrameBase),y
ldx #3
ldy #0
.10 lda (pData),y
pha
iny iny
dex txa
bpl .10
ldx #3
ldy #S.IP.DST+3
.1 pla
sta (ZPFrameBase),y sta (ZPFrameBase),y
dey
dex
bpl .1
ldy #S.ICMP.TYPE >PUSHW L.Socket
lda #S.ICMP.TYPE.ECHOREQ >LIBCALL hLIBTCPIP,LIBTCPIP.SKT.NEW
sta (ZPFrameBase),y bcs .99
txa
ldy #hSocket
sta (pData),y
ldy #Identifier ldy #Identifier
lda (pData),y lda (pData),y
@ -264,47 +259,11 @@ CS.DOEVENT lda (pEvent)
dec dec
sta (pData),y sta (pData),y
.9 sec do not discard TIMER event .9 sec do not discard TIMER event
rts rts
*-------------------------------------- *--------------------------------------
CS.Print.REPLY lda #TIMEOUT.MAX
ldy #S.EVT.DATALO Get Frame hMem
lda (pEvent),y
>SYSCALL GetMemPtrA
>STYA ZPFrameBase
ldy #S.IP.PROTOCOL
lda (ZPFrameBase),y
cmp #S.IP.PROTOCOL.ICMP
bne .9
ldy #S.ICMP.TYPE
lda (ZPFrameBase),y
cmp #S.ICMP.TYPE.ECHOREP
bne .9
ldy #S.ICMP.IDENTIFIER
lda (ZPFrameBase),y
tax
iny
lda (ZPFrameBase),y
ldy #Identifier+1
cmp (pData),y
bne .9
dey
txa
cmp (pData),y
bne .9
jsr CS.EVENT.REPLY
.8 clc
rts
.9 sec
rts
*--------------------------------------
CS.EVENT.REPLY lda #TIMEOUT.MAX
sec sec
ldy #TimeOut ldy #TimeOut
sbc (pData),y sbc (pData),y
@ -371,23 +330,37 @@ Wait.TimeOut sec
*-------------------------------------- *--------------------------------------
CS.END CS.END
LIBTCPIP >PSTR "libtcpip.o" LIBTCPIP >PSTR "libtcpip.o"
MSG0 >CSTR "%S: Unknown host\n" MSG.IPKO >CSTR "TCP/IP Not Loaded/Configured.\n"
MSG1 >CSTR "PING %d.%d.%d.%d (%S)\n" MSG.USAGE >CSTR "Usage : PING <ip|host>\n"
MSG.UNKNOWN >CSTR "%S: Unknown host\n"
MSG.HOSTOK >CSTR "PING %d.%d.%d.%d (%S)\n"
MSG2 >CSTR "%d.%d.%d.%d: TimeOut/Host unreachable\n" MSG2 >CSTR "%d.%d.%d.%d: TimeOut/Host unreachable\n"
MSG3 >CSTR "32 bytes from %d.%d.%d.%d, icmp_seq=%D, ttl=%d, time=%D ms\n" MSG3 >CSTR "32 bytes from %d.%d.%d.%d, icmp_seq=%D, ttl=%d, time=%D ms\n"
hLIBTCPIP .BS 1 hLIBTCPIP .BS 1
hDev .BS 1
TimeOut.ms .BS 2 TimeOut.ms .BS 2
Socket .DA #S.SOCKET.SOCK.RAW
.BS 2
.BS #S.IP.PROTOCOL.ICMP
Socket.Src.Addr .BS 4
Socket.Src.Port .BS 2 Identifier
Socket.Dst.Addr .BS 4
Socket.Dst.Port .DA 0 not used
.BS 16
*--------------------------------------
ICMP.Request .DA #S.ICMP.TYPE.ECHOREQ
.DA #0 CODE
.DA 0 CHECKSUM
ICMP.Request.ID .BS 2
ICMP.Request.SQ .BS 2
.AS "ABCDEFGHIJKLMNOP"
.AS "QRSTUVWXYZ012345"
*-------------------------------------- *--------------------------------------
.DUMMY .DUMMY
.OR 0 .OR 0
DS.START DS.START
DST.IP .BS 4 DST.IP .BS 4
hFrame .BS 1
TimeOut .BS 1
Identifier .BS 2
Sequence .BS 2 Sequence .BS 2
bReply .BS 1 TimeOut .BS 1
DS.END DS.END
.ED .ED
*-------------------------------------- *--------------------------------------

View File

@ -25,14 +25,14 @@ K.TCP.WSIZE .EQ K.TCP.MSS
LIBTCPIP.SET.IPCFG .EQ 4 LIBTCPIP.SET.IPCFG .EQ 4
LIBTCPIP.GET.IPCFG .EQ 6 LIBTCPIP.GET.IPCFG .EQ 6
LIBTCPIP.NEW.ICMP.FRAME .EQ 8 *LIBTCPIP.NEW.ICMP.FRAME .EQ 8
*LIBTCPIP.NEW.TCP.FRAME .EQ 10 *LIBTCPIP.NEW.TCP.FRAME .EQ 10
*LIBTCPIP.NEW.UDP.FRAME .EQ 12 *LIBTCPIP.NEW.UDP.FRAME .EQ 12
*LIBTCPIP.NEW.IP.FRAME .EQ 14 *LIBTCPIP.NEW.IP.FRAME .EQ 14
*LIBTCPIP.NEW.ARP.FRAME .EQ 16 *LIBTCPIP.NEW.ARP.FRAME .EQ 16
*LIBTCPIP.NEW.ETH.FRAME .EQ 18 *LIBTCPIP.NEW.ETH.FRAME .EQ 18
LIBTCPIP.SEND.ICMP.FRAME .EQ 20 *LIBTCPIP.SEND.ICMP.FRAME .EQ 20
*LIBTCPIP.SEND.TCP.FRAME .EQ 22 *LIBTCPIP.SEND.TCP.FRAME .EQ 22
*LIBTCPIP.SEND.UDP.FRAME .EQ 24 *LIBTCPIP.SEND.UDP.FRAME .EQ 24
*LIBTCPIP.SEND.IP.FRAME .EQ 26 *LIBTCPIP.SEND.IP.FRAME .EQ 26
@ -158,7 +158,8 @@ S.SOCKET.STATUS.FINWT2 .EQ 8
S.SOCKET.STATUS.CLOSING .EQ 9 S.SOCKET.STATUS.CLOSING .EQ 9
S.SOCKET.STATUS.TIMEWT .EQ 10 S.SOCKET.STATUS.TIMEWT .EQ 10
*S.SOCKET.PARENT .EQ 3 S.SOCKET.RAW.PROTO .EQ 3
S.SOCKET.SRC.ADDR .EQ 4 S.SOCKET.SRC.ADDR .EQ 4
S.SOCKET.SRC.PORT .EQ 8 S.SOCKET.SRC.PORT .EQ 8
S.SOCKET.DST.ADDR .EQ 10 S.SOCKET.DST.ADDR .EQ 10
@ -193,8 +194,8 @@ S.ETH.FRAMELEN .EQ 0
S.ETH.DSTMAC .EQ 2 S.ETH.DSTMAC .EQ 2
S.ETH.SRCMAC .EQ 8 S.ETH.SRCMAC .EQ 8
S.ETH.ETHERTYPE .EQ 14 S.ETH.ETHERTYPE .EQ 14
S.ETH.ETHERTYPE.IP .EQ $800 S.ETH.ETHERTYPE.IP .EQ $800
S.ETH.ETHERTYPE.ARP .EQ $806 S.ETH.ETHERTYPE.ARP .EQ $806
* *
S.ETH .EQ 2+6+6+2 S.ETH .EQ 2+6+6+2
*-------------------------------------- *--------------------------------------
@ -218,9 +219,9 @@ S.IP.IDENTIFICATION .EQ S.ETH+4 $0000
S.IP.FRAGMENT.FLAGS .EQ S.ETH+6 S.IP.FRAGMENT.FLAGS .EQ S.ETH+6
S.IP.TTL .EQ S.ETH+8 S.IP.TTL .EQ S.ETH+8
S.IP.PROTOCOL .EQ S.ETH+9 S.IP.PROTOCOL .EQ S.ETH+9
S.IP.PROTOCOL.ICMP .EQ 1 S.IP.PROTOCOL.ICMP .EQ 1
S.IP.PROTOCOL.TCP .EQ 6 S.IP.PROTOCOL.TCP .EQ 6
S.IP.PROTOCOL.UDP .EQ 17 S.IP.PROTOCOL.UDP .EQ 17
S.IP.HDR.CHECKSUM .EQ S.ETH+10 S.IP.HDR.CHECKSUM .EQ S.ETH+10
S.IP.SRC .EQ S.ETH+12 S.IP.SRC .EQ S.ETH+12
S.IP.DST .EQ S.ETH+16 S.IP.DST .EQ S.ETH+16
@ -228,9 +229,9 @@ S.IP.DST .EQ S.ETH+16
S.IP .EQ S.ETH+20 S.IP .EQ S.ETH+20
*-------------------------------------- *--------------------------------------
S.ICMP.TYPE .EQ S.IP+0 S.ICMP.TYPE .EQ S.IP+0
S.ICMP.TYPE.ECHOREP .EQ 0 S.ICMP.TYPE.ECHOREP .EQ 0
S.ICMP.TYPE.UNREACH .EQ 3 S.ICMP.TYPE.UNREACH .EQ 3
S.ICMP.TYPE.ECHOREQ .EQ 8 S.ICMP.TYPE.ECHOREQ .EQ 8
S.ICMP.CODE .EQ S.IP+1 S.ICMP.CODE .EQ S.IP+1
S.ICMP.CHECKSUM .EQ S.IP+2 S.ICMP.CHECKSUM .EQ S.IP+2
S.ICMP.IDENTIFIER .EQ S.IP+4 S.ICMP.IDENTIFIER .EQ S.IP+4
@ -252,12 +253,12 @@ S.TCP.ACK.NUMBER .EQ S.IP+8
S.TCP.DATAOFFSET .EQ S.IP+12 S.TCP.DATAOFFSET .EQ S.IP+12
S.TCP.DATAOFFSET20 .EQ $50 S.TCP.DATAOFFSET20 .EQ $50
S.TCP.OPTIONS .EQ S.IP+13 S.TCP.OPTIONS .EQ S.IP+13
S.TCP.OPTIONS.URG .EQ %00100000 S.TCP.OPTIONS.URG .EQ %00100000
S.TCP.OPTIONS.ACK .EQ %00010000 S.TCP.OPTIONS.ACK .EQ %00010000
S.TCP.OPTIONS.PSH .EQ %00001000 S.TCP.OPTIONS.PSH .EQ %00001000
S.TCP.OPTIONS.RST .EQ %00000100 S.TCP.OPTIONS.RST .EQ %00000100
S.TCP.OPTIONS.SYN .EQ %00000010 S.TCP.OPTIONS.SYN .EQ %00000010
S.TCP.OPTIONS.FIN .EQ %00000001 S.TCP.OPTIONS.FIN .EQ %00000001
S.TCP.WINDOW .EQ S.IP+14 S.TCP.WINDOW .EQ S.IP+14
S.TCP.CHECKSUM .EQ S.IP+16 S.TCP.CHECKSUM .EQ S.IP+16
S.TCP.URGPTR .EQ S.IP+18 S.TCP.URGPTR .EQ S.IP+18

View File

@ -4,56 +4,25 @@ NEW
INC 1 INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*-------------------------------------- */--------------------------------------
* Out: * #FRM.NewA
* ##In:
* A = S.IP.PROTOCOL.???
* ##Out:
* Y,A = Frame PTR * Y,A = Frame PTR
* X = hMem * X = hMem
*-------------------------------------- *\--------------------------------------
NEW.ICMP.FRAME jsr NEW.IP.FRAME FRM.NewA sta .1+2
bcs .9 >PUSHWI K.ETH.FRAME.LEN
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.ICMP
sta (ZPFrameBase),y
>LDYA ZPFrameBase
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.TCP.FRAME jsr NEW.IP.FRAME
bcs .9
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.TCP
sta (ZPFrameBase),y
>LDYA ZPFrameBase
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.UDP.FRAME jsr NEW.IP.FRAME
bcs .9
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.UDP
sta (ZPFrameBase),y
>LDYA ZPFrameBase
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.IP.FRAME >PUSHWI K.ETH.FRAME.LEN
>PUSHBI S.MEM.F.INIT0 >PUSHBI S.MEM.F.INIT0
>SYSCALL GetMem >SYSCALL GetMem
bcs .9 bcs .9
>STYA ZPFrameBase >STYA ZPFrameBase
ldy #S.IP.PROTOCOL
.1 lda #$ff
sta (ZPFrameBase),y
lda DevFlags lda DevFlags
and #S.DEVSTAT.NET.FLAGS.IPOFFLOAD and #S.DEVSTAT.NET.FLAGS.IPOFFLOAD
bne .9 bne .9
@ -89,11 +58,7 @@ NEW.IP.FRAME >PUSHWI K.ETH.FRAME.LEN
>LDYA ZPFrameBase >LDYA ZPFrameBase
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
SEND.ICMP.FRAME >PULLW ZPFrameBase FRM.SendICMP >PUSHW ZPFrameLen
jsr FRM.GetLen
stz hFrameOut
SEND.ICMP.FRAME.I
>PUSHW ZPFrameLen
>PUSHWI S.ICMP.TYPE-2 >PUSHWI S.ICMP.TYPE-2
ldy #S.ICMP.CHECKSUM ldy #S.ICMP.CHECKSUM
@ -111,20 +76,13 @@ SEND.ICMP.FRAME.I
pla pla
sta (ZPFrameBase),y sta (ZPFrameBase),y
bra SEND.IP.FRAME.I bra FRM.SendIP
*-------------------------------------- *--------------------------------------
SEND.TCP.FRAME >PULLW ZPFrameBase FRM.SendTCP
jsr FRM.GetLen
stz hFrameOut
SEND.TCP.FRAME.I
bra SEND.IP.FRAME.I bra FRM.SendIP
*-------------------------------------- *--------------------------------------
SEND.UDP.FRAME >PULLW ZPFrameBase FRM.SendUDP ldy #S.UDP.LENGTH+1
jsr FRM.GetLen
stz hFrameOut
SEND.UDP.FRAME.I
ldy #S.UDP.LENGTH+1
lda ZPFrameLen lda ZPFrameLen
sec sec
sbc #S.IP-2 sbc #S.IP-2
@ -133,13 +91,8 @@ SEND.UDP.FRAME.I
lda ZPFrameLen+1 lda ZPFrameLen+1
sbc /S.IP-2 sbc /S.IP-2
sta (ZPFrameBase),y sta (ZPFrameBase),y
bra SEND.IP.FRAME.I
*-------------------------------------- *--------------------------------------
SEND.IP.FRAME >PULLW ZPFrameBase FRM.SendIP ldx #3 Copy SRC.IP even if IP offload
jsr FRM.GetLen
stz hFrameOut
SEND.IP.FRAME.I ldx #3 Copy SRC.IP even if IP offload
ldy #S.IP.SRC+3 for proper UDP/TCP CRC calculation ldy #S.IP.SRC+3 for proper UDP/TCP CRC calculation
.1 lda IPCFG+S.IPCFG.IP,x .1 lda IPCFG+S.IPCFG.IP,x

View File

@ -1,23 +1,26 @@
PR#3 PR#3
PREFIX /A2OSX.SRC PREFIX /A2OSX.SRC
NEW LOMEM $A00
INC 1 INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*-------------------------------------- *--------------------------------------
ICMP.IN ldy #S.ICMP.TYPE ICMP.IN ldy #S.ICMP.TYPE
lda (ZPFrameBase),y lda (ZPFrameBase),y
cmp #S.ICMP.TYPE.ECHOREP
beq ICMP.IN.ECHOREP
cmp #S.ICMP.TYPE.ECHOREQ cmp #S.ICMP.TYPE.ECHOREQ
bne .9 bne ICMP.IN.EXIT
ldy #S.IP.DST ICMP.IN.ECHOREQ ldy #S.IP.DST+3
ldx #S.IPCFG.IP ldx #3
.1 lda (ZPFrameBase),y .1 lda (ZPFrameBase),y
cmp IPCFG,x cmp IPCFG+S.IPCFG.IP,x
bne .9 bne ICMP.IN.EXIT
iny dey
inx dex
cpx #S.IPCFG.IP+4
bne .1 bne .1
ldy #S.ICMP.TYPE ldy #S.ICMP.TYPE
@ -59,11 +62,66 @@ ICMP.IN ldy #S.ICMP.TYPE
lda #S.ARPCACHE.STATUS.RESOLVED lda #S.ARPCACHE.STATUS.RESOLVED
jsr ARP.ADD.I jsr ARP.ADD.I
stz hFrameOut DO NOT QUEUE/DISCARD this frame,it is SOURCE frame!!! lda hFrameIn
jmp SEND.ICMP.FRAME.I sta hFrameOut DO NOT DISCARD this frame,it is SOURCE frame!!!
.9 sec jmp FRM.SendICMP
ICMP.IN.EXIT lda hFrameIn
>SYSCALL FreeMemA
rts rts
*-------------------------------------- *--------------------------------------
ICMP.IN.ECHOREP jsr IP.FillTmpSocketSrcDst
lda #S.IP.PROTOCOL.ICMP
sta TmpSocket+S.SOCKET.RAW.PROTO
ldy #S.ICMP.IDENTIFIER
lda (ZPFrameBase),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameBase),y
sta TmpSocket+S.SOCKET.SRC.PORT
>LDYA L.SKT.TABLE
>STYA ZPPtrSKT
ldx #0
.3 lda (ZPPtrSKT)
beq .7
cmp #S.SOCKET.SOCK.RAW
bne .7
ldy #S.SOCKET.SRC.ADDR
.4 lda (ZPPtrSKT),y
cmp TmpSocket,y
bne .7
iny
cpy #S.SOCKET.DST.PORT Compare SRC.ADDR,SRC.PORT,DST.ADDR
bne .4
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 FreeMemA
rts
*--------------------------------------
MAN MAN
SAVE LIB/LIBTCPIP.S.ICMP SAVE LIB/LIBTCPIP.S.ICMP
LOAD LIB/LIBTCPIP.S LOAD LIB/LIBTCPIP.S

View File

@ -93,6 +93,24 @@ IP.ComputeChecksum
eor #$FF eor #$FF
rts rts
*-------------------------------------- *--------------------------------------
IP.FillTmpSocketSrcDst
ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameBase),y
sta TmpSocket+S.SOCKET.DST.ADDR,x
dey
dex
bpl .1
ldy #S.IP.DST+3
ldx #3
.2 lda (ZPFrameBase),y
sta TmpSocket+S.SOCKET.SRC.ADDR,x
dey
dex
bpl .2
rts
*--------------------------------------
IP.SetDestMAC ldy #S.IP.DST IP.SetDestMAC ldy #S.IP.DST
lda (ZPFrameBase),y lda (ZPFrameBase),y
iny iny

View File

@ -1,6 +1,6 @@
PR#3 PR#3
PREFIX /A2OSX.SRC PREFIX /A2OSX.SRC
NEW LOMEM $A00
INC 1 INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
@ -8,7 +8,7 @@ AUTO 6
* IN : PULLW = PTR to S.SOCKET template * IN : PULLW = PTR to S.SOCKET template
* OUT : * OUT :
* YA=PTR to new S.SOCKET * YA=PTR to new S.SOCKET
* X hSocket 128<x<255 * X=hSocket
*-------------------------------------- *--------------------------------------
SKT.NEW >PULLW ZPTmpPtr1 SKT.NEW >PULLW ZPTmpPtr1
@ -53,9 +53,7 @@ SKT.NEW >PULLW ZPTmpPtr1
bmi .5 Already found an empty slot bmi .5 Already found an empty slot
>LDYA ZPTmpPtr2 >LDYA ZPTmpPtr2
>STYA ZPTmpPtr3 >STYA ZPTmpPtr3
txa stx TmpOffset
ora #$80
sta TmpOffset
.5 lda ZPTmpPtr2 .5 lda ZPTmpPtr2
clc clc
@ -115,11 +113,9 @@ SKT.ACCEPTA jsr SKT.GetA
sec sec
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
SKT.SENDA * SKT.Send
sec
rts
*-------------------------------------- *--------------------------------------
SKT.SEND >PULLB hSocket SKT.Send >PULLB hSocket
pha pha
>PULLW ZPDataPtr >PULLW ZPDataPtr
>PULLW ZPDataLen >PULLW ZPDataLen
@ -132,13 +128,18 @@ SKT.SEND >PULLB hSocket
beq SKT.SEND.UDP beq SKT.SEND.UDP
cpx #S.SOCKET.SOCK.STREAM cpx #S.SOCKET.SOCK.STREAM
bne .99 bne .1
jmp SKT.SEND.TCP jmp SKT.SEND.TCP
.1 cpx #S.SOCKET.SOCK.RAW
bne .99
jmp SKT.SEND.RAW
.99 sec .99 sec
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
SKT.SEND.UDP jsr NEW.UDP.FRAME SKT.SEND.UDP lda #S.IP.PROTOCOL.UDP
jsr FRM.NewA
bcs .9 bcs .9
stx hFrameOut stx hFrameOut
@ -213,7 +214,7 @@ SKT.SEND.UDP jsr NEW.UDP.FRAME
inc ZPTmpPtr1 inc ZPTmpPtr1
bra .3 bra .3
.4 jmp SEND.UDP.FRAME.I .4 jmp FRM.SendUDP
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
SKT.SEND.TCP SKT.SEND.TCP
@ -221,6 +222,22 @@ SKT.SEND.TCP
sec sec
rts rts
*-------------------------------------- *--------------------------------------
SKT.SEND.RAW ldy #S.SOCKET.RAW.PROTO
lda (ZPPtrSKT),y
cmp #S.IP.PROTOCOL.ICMP
bne .9
jsr FRM.NewA
bcs .9
stx hFrameOut
jmp FRM.SendIP
.9 sec
rts
*--------------------------------------
SKT.RCVDA jsr SKT.GetA SKT.RCVDA jsr SKT.GetA
bcs .9 bcs .9
@ -332,7 +349,8 @@ SKT.AddToQueueL pha
sec sec
rts rts
*-------------------------------------- *--------------------------------------
SKT.AddToQueueD ldy #S.SOCKET.DQ.HEAD SKT.AddToQueueA sta .2+1
ldy #S.SOCKET.DQ.HEAD
lda (ZPPtrSKT),y lda (ZPPtrSKT),y
tax tax
inc inc
@ -349,7 +367,8 @@ SKT.AddToQueueD ldy #S.SOCKET.DQ.HEAD
clc clc
adc #S.SOCKET.DQ adc #S.SOCKET.DQ
tay tay
lda hFrameOut
.2 lda #$ff
sta (ZPPtrSKT),y sta (ZPPtrSKT),y
clc clc
rts rts

View File

@ -346,7 +346,7 @@ TCP.SendMSG sta TCP.MSG+S.TCP.OPTIONS
bpl .3 bpl .3
>PUSHW L.TCP.MSG >PUSHW L.TCP.MSG
jsr SEND.TCP.FRAME * jsr FRM.SendTCP
clc clc
rts rts

View File

@ -5,13 +5,7 @@ INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*-------------------------------------- *--------------------------------------
UDP.IN ldy #S.IP.SRC+3 UDP.IN jsr IP.FillTmpSocketSrcDst
ldx #3
.1 lda (ZPFrameBase),y
sta TmpSocket+S.SOCKET.DST.ADDR,x
dey
dex
bpl .1
ldy #S.UDP.SRCPORT ldy #S.UDP.SRCPORT
lda (ZPFrameBase),y lda (ZPFrameBase),y
@ -20,14 +14,6 @@ UDP.IN ldy #S.IP.SRC+3
lda (ZPFrameBase),y lda (ZPFrameBase),y
sta TmpSocket+S.SOCKET.DST.PORT sta TmpSocket+S.SOCKET.DST.PORT
ldy #S.IP.DST+3
ldx #3
.2 lda (ZPFrameBase),y
sta TmpSocket+S.SOCKET.SRC.ADDR,x
dey
dex
bpl .2
ldy #S.UDP.DSTPORT ldy #S.UDP.DSTPORT
lda (ZPFrameBase),y lda (ZPFrameBase),y
sta TmpSocket+S.SOCKET.SRC.PORT+1 sta TmpSocket+S.SOCKET.SRC.PORT+1
@ -69,7 +55,8 @@ UDP.IN ldy #S.IP.SRC+3
cpy #S.SOCKET.DST.PORT+2 cpy #S.SOCKET.DST.PORT+2
bne .5 bne .5
jsr SKT.AddToQueueD lda hFrameIn
jsr SKT.AddToQueueA
bcs .9 Q full, discard... bcs .9 Q full, discard...
rts DO NOT Discard this queued frame rts DO NOT Discard this queued frame

View File

@ -45,14 +45,14 @@ CS.START cld
.DA SET.IPCFG .DA SET.IPCFG
.DA GET.IPCFG .DA GET.IPCFG
.DA NEW.ICMP.FRAME .DA $ffff NEW.ICMP.FRAME
.DA $ffff NEW.TCP.FRAME .DA $ffff NEW.TCP.FRAME
.DA $ffff NEW.UDP.FRAME .DA $ffff NEW.UDP.FRAME
.DA $ffff NEW.IP.FRAME .DA $ffff NEW.IP.FRAME
.DA $ffff NEW.ARP.FRAME .DA $ffff NEW.ARP.FRAME
.DA $ffff NEW.ETH.FRAME .DA $ffff NEW.ETH.FRAME
.DA SEND.ICMP.FRAME .DA $ffff SEND.ICMP.FRAME
.DA $ffff SEND.TCP.FRAME .DA $ffff SEND.TCP.FRAME
.DA $ffff SEND.UDP.FRAME .DA $ffff SEND.UDP.FRAME
.DA $ffff SEND.IP.FRAME .DA $ffff SEND.IP.FRAME
@ -75,7 +75,7 @@ CS.START cld
.DA SKT.NEW .DA SKT.NEW
.DA $FFFF .DA $FFFF
.DA SKT.ACCEPTA .DA SKT.ACCEPTA
.DA SKT.SENDA .DA $FFFF
.DA SKT.SEND .DA SKT.SEND
.DA SKT.RCVDA .DA SKT.RCVDA
.DA $FFFF .DA $FFFF

10
_Docs/LIBTCPIP.md Normal file
View File

@ -0,0 +1,10 @@
*** Auto generated by docgen.cmd ***
#FRM.NewA
##In:
+ A = S.IP.PROTOCOL.???
##Out:
* Y,A = Frame PTR
* X = hMem

View File

@ -6,10 +6,12 @@ SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
for /f %%a in ('copy /Z "%~f0" nul') do set "CR=%%a" for /f %%a in ('copy /Z "%~f0" nul') do set "CR=%%a"
mode con:cols=40 lines=24 mode con:cols=80 lines=24
cls cls
echo Apple //e echo Apple //e
set /a c=0
set DOCFILE=%~dp0..\_Docs\KERNEL.md set DOCFILE=%~dp0..\_Docs\KERNEL.md
@ -20,14 +22,12 @@ echo.
echo Scanning KERNEL Src Files... echo Scanning KERNEL Src Files...
echo. echo.
set /a c=0 for /f %%F in ('dir /b /ogn "%~dp0..\SYS\KERNEL.S*.txt"') do (
for /f %%F in ('dir /b /ogn %~dp0..\SYS\KERNEL.S*.txt') do (
set FN=%%F set FN=%%F
set /a c+=1 set /a c+=1
set /p "=!c! - !FN! !CR!" <NUL set /p "=!c! - !FN! !CR!" <NUL
set bInDoc=0 set bInDoc=0
for /F "tokens=*" %%L in (%~dp0..\SYS\!FN!) do ( for /F "tokens=*" %%L in ('type "%~dp0..\SYS\!FN!"') do (
set LINE=%%L set LINE=%%L
if defined LINE ( if defined LINE (
set bOut=1 set bOut=1
@ -51,6 +51,47 @@ for /f %%F in ('dir /b /ogn %~dp0..\SYS\KERNEL.S*.txt') do (
) )
) )
) )
set DOCFILE=%~dp0..\_Docs\LIBTCPIP.md
echo # A2osX LIBTCPIP API >!DOCFILE!
echo *** Auto generated by docgen.cmd *** >!DOCFILE!
echo.
echo Scanning LIBTCPIP Src Files...
echo.
for /f %%F in ('dir /b /ogn "%~dp0..\LIB\LIBTCPIP.S*.txt"') do (
set FN=%%F
set /a c+=1
set /p "=!c! - !FN! !CR!" <NUL
set bInDoc=0
for /F "tokens=*" %%L in ('type "%~dp0..\LIB\!FN!"') do (
set LINE=%%L
if defined LINE (
set bOut=1
if "!LINE:~0,2!" EQU "*/" (
set bInDoc=1
set bOut=0
)
if "!LINE:~0,2!" EQU "*\" (
set bInDoc=0
set bOut=0
)
if !bInDoc! EQU 1 (
if !bOut! EQU 1 (
if "!line:~0,4!" EQU "* " set LINE= + !LINE:~4!
if "!line:~0,3!" EQU "* " set LINE=+ !LINE:~3!
if "!line:~0,2!" EQU "* " set LINE=!LINE:~2!
if "!line:~0,1!" EQU "#" echo.>>!DOCFILE!
(echo !LINE!)>>!DOCFILE!
)
)
)
)
)
echo. echo.
echo. echo.
echo All done : !c! Files scanned. echo All done : !c! Files scanned.