Updates Related to new Soket API (coming soon!)

This commit is contained in:
Rémy GIBERT 2016-03-13 22:54:28 +01:00
parent 6ef6d21da7
commit 7b2c457def
2 changed files with 335 additions and 74 deletions

View File

@ -1,6 +1,6 @@
PR#3
PREFIX /A2OSX.SRC
NEW
LOMEM $C00
INC 1
AUTO 6
.LIST OFF
@ -10,9 +10,10 @@ AUTO 6
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBSTR.I
.INB INC/LIBTCPIP.I
*--------------------------------------
TIMEOUT.MAX .EQ 4 4 sec.
*--------------------------------------
ZPFrameBase1 .EQ ZPBIN
ZPFrameLen1 .EQ ZPBIN+2
ZPFramePtr1 .EQ ZPBIN+4
@ -38,9 +39,11 @@ CS.START cld
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
L.IPCFG .DA IPCFG
L.MSG.CFG .DA MSG.CFG
L.MSG.CFG1 .DA MSG.CFG1
L.MSG.CFG2 .DA MSG.CFG2
L.MSG.CFG.KO .DA MSG.CFG.KO
L.MSG.CFG.OK .DA MSG.CFG.OK
L.MSG.CFG.ND .DA MSG.CFG.ND
L.MSG.CFG.NA .DA MSG.CFG.NA
.DA 0
*--------------------------------------
@ -56,6 +59,10 @@ CS.INIT >LDYA L.LIBTCPIP
and #S.IPCFG.STATUS.OK
bne .99 Already Configured, exit
ldy #S.IPCFG.HDEV
lda (ZPPtr1),y
beq .98
ldy #0
.1 lda (ZPPtr1),y
sta IPCFG,y
@ -80,9 +87,6 @@ CS.INIT >LDYA L.LIBTCPIP
dex
bpl .2
lda #20
sta TimeOut
lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
@ -90,31 +94,44 @@ CS.INIT >LDYA L.LIBTCPIP
clc
.9 rts
.98 >LDYA L.MSG.CFG.ND
bra .90
.99 >LDYA L.MSG.CFG.NA
>SYSCALL SYS.PSTROutYA
.90 >SYSCALL SYS.PSTROutYA
lda #0
sec
rts
*--------------------------------------
CS.RUN >LDYA L.MSG.CFG
CS.RUN >LDYA L.MSG.CFG1
>SYSCALL SYS.PSTROutYA
CS.RUN.DISC jsr SendDHCPDiscFrame
bcs CS.RUN.KO
lda #S.IPCFG.STATUS.SDISC
sta IPCFG
jsr Init.Timeout
CS.RUN.OFFER >SYSCALL SYS.Sleep
lda IPCFG
and #S.IPCFG.STATUS.ROFFER
bne CS.RUN.REQ
lda TimeOut
bne CS.RUN.OFFER
jsr Wait.Timeout
bcc CS.RUN.OFFER
lda #1
bra CS.RUN.KO
CS.RUN.REQ jsr SendDHCPReqFrame
CS.RUN.REQ ldx #3
.1 >PUSHB IPCFG+S.IPCFG.DHCPSRVR,x
dex
bpl .1
>LDYA L.MSG.CFG2
>SYSCALL SYS.PSTROutYA
jsr SendDHCPReqFrame
bcs CS.RUN.KO
lda #S.IPCFG.STATUS.SREQ
@ -124,10 +141,17 @@ CS.RUN.RACK >SYSCALL SYS.Sleep
lda IPCFG
and #S.IPCFG.STATUS.RACK
bne CS.RUN.OK
lda TimeOut
bne CS.RUN.RACK
jsr Wait.Timeout
bcc CS.RUN.RACK
lda #2
bra CS.RUN.KO
CS.RUN.KO pha
>PUSHA
>LDYA L.MSG.CFG.KO
>SYSCALL SYS.PSTROutYA
pla
sec
rts
CS.RUN.OK lda #S.IPCFG.STATUS.OK
sta IPCFG
@ -152,27 +176,23 @@ CS.RUN.OK lda #S.IPCFG.STATUS.OK
lda #0 Leave with NO ERROR
sec
rts
CS.RUN.KO pha
>PUSHA
>LDYA L.MSG.CFG.KO
>SYSCALL SYS.PSTROutYA
pla
sec
rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
and #S.EVT.F.TIMER is it a TIMER event?
beq .1 no....
bpl .1 is it a TIMER event?
lda TimeOut
asl One second ?
bpl .9
ldy #TimeOut
lda (pData),y
beq .9
dec TimeOut
bra .9 do not discard TIMER event
dec
sta (pData),y
sec do not discard TIMER event
rts
.1 lda (pEvent)
and #S.EVT.F.NET
.1 bit #S.EVT.F.NET
beq .9
ldy #S.IPCFG.HDEV
@ -186,11 +206,10 @@ CS.DOEVENT lda (pEvent)
>SYSCALL SYS.GetMemPtrA
>STYA ZPFrameBase1
ldy #S.EVT.DATAW1 Get Frame Len
lda (pEvent),y
lda (ZPFrameBase1)
sta ZPFrameLen1
iny
lda (pEvent),y
ldy #1
lda (ZPFrameBase1),y
sta ZPFrameLen1+1
lda IPCFG
@ -222,10 +241,6 @@ CS.QUIT lda hLIBTCPIP
clc
rts
*--------------------------------------
* SendDHCPDiscFrame
* In:
* Out:
*--------------------------------------
SendDHCPDiscFrame
jsr NewDHCPFrame
bcs .9
@ -246,8 +261,12 @@ SendDHCPDiscFrame
tya
bne .1
>LDYAI S.UDP+FRAME.DISC.LEN
>PUSHYA
lda #S.UDP+FRAME.DISC.LEN-2
sta (ZPFrameBase1)
ldy #1
lda /S.UDP+FRAME.DISC.LEN-2
sta (ZPFrameBase1),y
>PUSHW ZPFrameBase1
>LIBCALL hLIBTCPIP,LIBTCPIP.SEND.UDP.FRAME
pla
@ -376,10 +395,6 @@ GetDHCPOption.CopyIP
bne .2
rts
*--------------------------------------
* SendDHCPReqFrame
* In:
* Out:
*--------------------------------------
SendDHCPReqFrame
jsr NewDHCPFrame
bcs .9
@ -400,8 +415,12 @@ SendDHCPReqFrame
tya
bne .1
>LDYAI S.UDP+FRAME.REQ.LEN
>PUSHYA
lda #S.UDP+FRAME.REQ.LEN-2
sta (ZPFrameBase1)
ldy #1
lda /S.UDP+FRAME.REQ.LEN-2
sta (ZPFrameBase1),y
>PUSHW ZPFrameBase1
>LIBCALL hLIBTCPIP,LIBTCPIP.SEND.UDP.FRAME
pla
@ -476,43 +495,60 @@ SetFramePtr1AX clc
sta ZPFramePtr1+1
rts
*--------------------------------------
Init.Timeout ldy #TimeOut
lda #TIMEOUT.MAX
sta (pData),y
rts
*--------------------------------------
Wait.TimeOut sec
ldy #TimeOut
lda (pData),y
beq .9
ldy #bCTRLC
lda (pData),y
bmi .9
clc
.9 rts
*--------------------------------------
CS.END
LIBTCPIP >PSTRING "libtcpip.o"
MSG.CFG >PSTRING "DHCPCLNT:Querying DHCP Server...\n"
MSG.CFG1 >PSTRING "DHCPCLNT:Searching for DHCP servers...\n"
MSG.CFG2 >PSTRING "DHCPCLNT:Reply from DHCP Server at %d.%d.%d.%d, requesting...\n"
MSG.CFG.KO >PSTRING "DHCPCLNT:Time Out [%h].\n"
MSG.CFG.OK >PSTRING "DHCPCLNT:Success:[IP=%d.%d.%d.%d/%d.%d.%d.%d]\n"
MSG.CFG.NA >PSTRING "DHCPCLNT:TCPIP Already Configured, Exiting.\n"
*--------------------------------------
MSG.CFG.ND >PSTRING "DHCPCLNT:No Device, exiting.\n"
MSG.CFG.NA >PSTRING "DHCPCLNT:TCPIP Already configured, exiting.\n"
hLIBTCPIP .BS 1
IPCFG .BS S.IPCFG
FRAME.DISC .HS 01010600 OP,HTYPE,HLEN,HOPS
FRAME.DISC.XID .BS 4
FRAME.DISC.SECS .HS 0000
FRAME.DISC.FLAGS .HS 0000
FRAME.DISC.CIADDR .HS 00000000
.HS 0000 SECS
.HS 0000 FLAGS
.HS 00000000 CIADDR
FRAME.DISC.YIADDR .HS 00000000
FRAME.DISC.SIADDR .HS 00000000
FRAME.DISC.GIADDR .HS 00000000
.HS 00000000 SIADDR
.HS 00000000 GIADDR
FRAME.DISC.CHADDR .HS 00000000.00000000.00000000.00000000
FRAME.DISC.SNAME .BS 64
FRAME.DISC.FILE .BS 128
FRAME.DISC.COOKIE .HS 63825363
FRAME.DISC.OPT .HS 3501
.BS 64 SNAME
.BS 128 FILE
.HS 63825363 COOKIE
.HS 3501 OPT
.DA #S.DHCP.OPTIONS.DHCPDiscover
.HS 37040103060FFF
FRAME.DISC.LEN .EQ *-FRAME.DISC
*--------------------------------------
FRAME.DISC.LEN .EQ *-FRAME.DISC
FRAME.REQ .HS 01010600 OP,HTYPE,HLEN,HOPS
FRAME.REQ.XID .BS 4
FRAME.REQ.SECS .HS 0000
FRAME.REQ.FLAGS .HS 0000
FRAME.REQ.CIADDR .HS 00000000
.HS 0000 SECS
.HS 0000 FLAGS
.HS 00000000 CIADDR
FRAME.REQ.YIADDR .HS 00000000
FRAME.REQ.SIADDR .HS 00000000
FRAME.REQ.GIADDR .HS 00000000
.HS 00000000 SIADDR
.HS 00000000 GIADDR
FRAME.REQ.CHADDR .HS 00000000.00000000.00000000.00000000
FRAME.REQ.SNAME .BS 64
FRAME.REQ.FILE .BS 128
FRAME.REQ.COOKIE .HS 63825363
FRAME.REQ.OPT .HS 3501
.BS 64 SNAME
.BS 128 FILE
.HS 63825363 COOKIE
.HS 3501 OPT
.DA #S.DHCP.OPTIONS.DHCPRequest
.HS 3204
FRAME.REQ.OPT.REQIP .BS 4
@ -521,13 +557,10 @@ FRAME.REQ.OPT.SVRIP .BS 4
.HS FF
FRAME.REQ.LEN .EQ *-FRAME.REQ
*--------------------------------------
hLIBTCPIP .BS 1
TimeOut .BS 1
IPCFG .BS S.IPCFG
*--------------------------------------
DS.START
TimeOut .BS 1
bCTRLC .BS 1
DS.END
*--------------------------------------
MAN
SAVE SBIN/DHCPCLNT.S
ASM

View File

@ -0,0 +1,228 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/SBIN/HTTPD
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBTCPIP.I
*--------------------------------------
TIMEOUT.MAX .EQ 30 30 sec.
*--------------------------------------
ZPIPCfgPtr .EQ ZPBIN
ZPSktPtr .EQ ZPBIN+2
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
L.Socket .DA Socket
L.MSG.TCPWAIT .DA MSG.TCPWAIT
L.MSG.INITOK .DA MSG.INITOK
L.MSG.TCPIPERR .DA MSG.TCPIPERR
L.MSG.SKTERR .DA MSG.SKTERR
L.MSG.ABORT .DA MSG.ABORT
L.MSG.INCOMING .DA MSG.INCOMING
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
>SYSCALL SYS.LoadLibYA
sta hLIBTCPIP
lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
rts
*--------------------------------------
CS.RUN jsr Init.Timeout
>LDYA L.MSG.TCPWAIT
>SYSCALL SYS.PSTROutYA
.1 >LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG is TCPIP loaded ?
bcs .99
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
bmi CS.RUN.INIT
>SYSCALL SYS.Sleep
jsr Wait.Timeout
bcc .1
.99 >LDYA L.MSG.TCPIPERR
>SYSCALL SYS.PSTROutYA
lda #SYSMGR.ERRSYN
sec
rts
CS.RUN.INIT ldx #3
ldy #S.IPCFG.IP+3
.1 lda (ZPIPCfgPtr),y
sta Socket.Src.Addr,x
dey
dex
bpl .1
>PUSHW L.Socket
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.NEW
bcs .9
txa
ldy #hSocket
sta (pData),y
>LDYA L.MSG.INITOK
>SYSCALL SYS.PSTROutYA
.11 >SYSCALL SYS.Sleep
ldy #bCTRLC
lda (pData),y
bmi .99
bra .11
ldy #hSocket
lda (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.ACCEPTA
bcs .11
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.GETA
>STYA ZPSktPtr
ldx #3
ldy #S.SOCKET.DST.ADDR+3
.2 >PUSHB (ZPSktPtr),y
dey
dex
bpl .2
>LDYA L.MSG.INCOMING
>SYSCALL SYS.PSTROutYA
bra .11
.9 >LDYA L.MSG.SKTERR
>SYSCALL SYS.PSTROutYA
lda #SYSMGR.ERRSYN
sec
rts
.99 >LDYA L.MSG.ABORT
>SYSCALL SYS.PSTROutYA
lda #0
sec
rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .1 is it a TIMER event?
asl One second ?
bpl .9
ldy #TimeOut
lda (pData),y
beq .9
dec
sta (pData),y
sec do not discard TIMER event
rts
.1 bit #S.EVT.F.KEY is it a KEY event?
beq .9
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
ldy #S.EVT.DATALO
lda (pEvent),y
cmp #$03 Ctrl-C
bne .9
lda #$FF
ldy #bCTRLC
sta (pData),y
clc
rts
.9 sec
rts
*--------------------------------------
CS.QUIT ldy #hSocket
lda (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CLOSEA
lda hLIBTCPIP
>SYSCALL SYS.UnloadLibA
clc
rts
*--------------------------------------
Init.Timeout ldy #TimeOut
lda #TIMEOUT.MAX
sta (pData),y
rts
*--------------------------------------
Wait.TimeOut sec
ldy #TimeOut
lda (pData),y
beq .9
ldy #bCTRLC
lda (pData),y
bmi .9
clc
.9 rts
*--------------------------------------
CS.END
*--------------------------------------
LIBTCPIP >PSTRING "libtcpip.o"
MSG.TCPWAIT >PSTRING "HTTPD:Waiting for TCP/IP initializing...\n"
MSG.INITOK >PSTRING "HTTPD:Init Ok, Listening.\n"
MSG.TCPIPERR >PSTRING "HTTPD:TCP/IP Not initialized properly\n"
MSG.SKTERR >PSTRING "HTTPD:Listen Error\n"
MSG.ABORT >PSTRING "HTTPD:User Aborted\n"
MSG.INCOMING >PSTRING "HTTPD:Incoming Connection From : %d.%d.%d.%d\n"
hLIBTCPIP .BS 1
*--------------------------------------
Socket .DA #S.SOCKET.SOCK.STREAM
.DA #S.SOCKET.SO.ACCEPTCONN
.DA #S.SOCKET.STATUS.LISTEN
.BS 1
Socket.Src.Addr .BS 4
Socket.Src.Port .DA 80
Socket.Dst.Addr .BS 4
Socket.Dst.Port .BS 2
.BS 16
*--------------------------------------
.DUMMY
.OR 0
DS.START
TimeOut .BS 1
bCTRLC .BS 1
hSocket .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE SBIN/HTTPD.S
ASM