resurrect sntp

git-svn-id: http://svn.code.sf.net/p/netboot65/code@325 93682198-c243-4bdb-bd91-e943c89aac3b
This commit is contained in:
jonnosan 2012-01-12 09:43:40 +00:00
parent 1b48a97269
commit 4a022ff144
17 changed files with 324 additions and 50 deletions

View File

@ -119,8 +119,9 @@ are also set to indicate current connection state and error conditions (if any).
<td>none</td>
<td>POLL</td>
</tr>
<tr>
<td>TCPSEND</td>
<td>Send a string (up to 255 bytes) over a previously opened connection.Integer variables CO% and ER% ae aset to indicate current connection state and any error condition which may occur during the sending of the file. <i>NB - in the current implementation of Kipper BASIC, it is possible for data to arrive during a call to TCPSEND, which may not be passed through to the BASIC program.</i></td>
<td>Send a string (up to 255 bytes) over a previously opened connection.Integer variables CO% and ER% are set to indicate current connection state and any error condition which may occur during the sending of the file. <i>NB - in the current implementation of Kipper BASIC, it is possible for data to arrive during a call to TCPSEND, which may not be passed through to the BASIC program.</i></td>
<td><li>data (string)</td>
<td><li>TCPSEND"HELLO "+"WORLD"</td>
</tr>
@ -129,7 +130,17 @@ are also set to indicate current connection state and error conditions (if any).
<td>Send a file (of any length) over a previously opened connection. The file will be looked for on the current 'default' device, i.e. which ever drive was last accessed. Integer variables CO% and ER% ae aset to indicate current connection state and any error condition which may occur during the sending of the file. <i>NB - in the current implementation of Kipper BASIC, it is possible for data to arrive during a call to TCPSEND, which may not be passed through to the BASIC program.</i></td>
<td><li>filename (string)</td>
<td><li>TCPBLAT"GOPHERMAP.TXT"</td>
</tr>
<tr>
<td>UDPSEND</td>
<td>Send a string (up to 255 bytes) over UDP . There is no need to connect first </i></td>
<td>
<li>destination hostname&nbsp;or&nbsp;IP&nbsp;address&nbsp;(string)
<li>destination port&nbsp;number&nbsp;(1..65535)
<li>local port&nbsp;number&nbsp;(1..65535)
<li>data (string)
</td>
<td><li>UDPSEND"JAMTRONIX.COM",7,6464,"echo test"</td>
</tr>
</table>

View File

@ -32,18 +32,11 @@ kipperbasv20.prg: kipperbasv20.o $(IP65LIB) $(VIC20RRNETLIB) $(INCFILES) ../cfg/
bails.d64: bails.prg
# ripxplore.rb -r -e kbload $@ -o kbload
# ripxplore.rb -r -e kbapp $@ -o kbapp
# ripxplore.rb $@ -I CbmDos -a kipperbas.prg
ripxplore.rb $@ -a bails.prg
c1541 -format bails,bb d64 $@ -attach $@ -write bails.prg
kipperbas.d64: kipperbas.prg
c1541 -format kipperbas,kb d64 $@ -attach $@ -write kipperbas.prg
kipperbas.d64: kipperbas.prg chat
# ripxplore.rb -r -e kbload $@ -o kbload
# ripxplore.rb -r -e kbapp $@ -o kbapp
ripxplore.rb $@ -I CbmDos -a kipperbas.prg
# ripxplore.rb $@ -a kipperbas.prg
cp chat autoexec.bas
ripxplore.rb $@ -a autoexec.bas -t C64Prg
clean:
rm -f *.o *.bin *.map *.prg

Binary file not shown.

Binary file not shown.

View File

@ -92,6 +92,14 @@ crunched_line = $0200 ;Input buffer
.import timer_read
.import native_to_ascii
.import ascii_to_native
.import udp_send_dest
.import udp_send_dest_port
.import udp_send_src_port
.import udp_send_len
.import udp_send
.import udp_add_listener
.import udp_remove_listener
.import udp_callback
.zeropage
temp: .res 2
temp2: .res 2
@ -1335,12 +1343,16 @@ tcpconnect_callback:
sta connection_state
rts
@not_end_packet:
stax inbound_data_length
set_packet_vars:
jsr copymem
ldx tcp_inbound_data_length+1
ldx inbound_data_length+1
beq @short_packet
lda #$ff
@short_packet:
lda tcp_inbound_data_length
lda inbound_data_length
set_input_string:
pha
lda #'I'
@ -1374,10 +1386,10 @@ set_input_string:
lda #'I'+$80
ldx #'L'+$80
jsr find_var
lda tcp_inbound_data_length+1
lda inbound_data_length+1
sta (VARPNT),y
iny
lda tcp_inbound_data_length
lda inbound_data_length
sta (VARPNT),y
rts
@ -1461,6 +1473,7 @@ tcpblat_keyword:
@eof:
and #$40 ; end of file?
beq @readerror
beq @readerror
lda #$00
sty tcp_send_data_len
sta tcp_send_data_len+1
@ -1486,6 +1499,53 @@ tcpblat_keyword:
lda #KPR_ERROR_FILE_ACCESS_FAILURE
jmp @store_error
;send udp packet
udpsend_keyword:
ldax #udp_send_dest
jsr get_ip_parameter
bcc @no_error
rts
@no_error:
jsr skip_comma_get_integer
stax udp_send_dest_port
jsr skip_comma_get_integer
stax udp_send_src_port
jsr CHRGOT
jsr CHKCOM ;make sure next char is a comma (and skip it)
jsr extract_string
inc $d020
ldy param_length
sty udp_send_len
ldy #0
sty udp_send_len+1
ldax #transfer_buffer
jsr udp_send
lda #0
sta ip65_error
clc
rts
udplisten_keyword:
ldax #udp_handler
stax udp_callback
jsr get_integer ;port number
stax port
jsr udp_remove_listener
ldax port
jsr udp_add_listener
bcc @ok
ldax #too_many_listeners
jmp print_error
@ok:
rts
udp_handler:
inc $d020
rts
evaluate:
lda #$00
@ -1557,6 +1617,8 @@ dhcp_server_msg:
tftp_server_msg:
.byte "TFTP SERVER : ", 0
too_many_listeners:
.byte "TOO MANY LISTENERS",0
address_resolution:
.byte "ADDRESS RESOLUTION",0
@ -1604,8 +1666,10 @@ keywords:
.byte "TCP",$A0,$F0 ;TCPLOSE - BASIC will replace CLOSE with $A0
.byte "TCPBLAT",$F1
.byte "MAC",$F2
.byte $00 ;end of list
HITOKEN=$F3
.byte "UDPS",$80,$F3 ;UDPSEND - BASIC will replace END with $80
.byte "UDP",$9B,"EN",$F4 ;UDPLISTEN - BASIC will replace LIST with $9b
.byte $00 ;end of list
HITOKEN=$F5
;
; Table of token locations-1
@ -1630,6 +1694,8 @@ EF: .word tcpsend_keyword-1
FO: .word tcpclose_keyword-1
F1: .word tcpblat_keyword-1
F2: .word mac_keyword-1
F3: .word udpsend_keyword-1
F4: .word udplisten_keyword-1
.segment "SELF_MODIFIED_CODE"
@ -1669,3 +1735,5 @@ connection_state: .res 1
netcat_timeout: .res 1
buffer_length: .res 2
cursor_state: .res 1
port: .res 2
inbound_data_length: .res 2

View File

@ -0,0 +1 @@
puts Time.now.strftime(".byte \" (%Y-%m-%d)\"")

View File

@ -103,9 +103,7 @@ kipperkart_rr.bin: kipperkart.bin
ruby fix_cart.rb $@ 32768
kipperdisk.d64: kipperkart.prg kipperterm.prg kipperkart.prg kippergo.prg
ripxplore.rb --init CbmDos $@ -a kipperkart.prg
ripxplore.rb $@ -a kipperterm.prg
ripxplore.rb $@ -a kippergo.prg
c1541 -format kipperdisk,kd d64 $@ -attach $@ -write kipperkart.prg -write kipperterm.prg -write kippergo.prg
cp $@ ../../server/boot/
bobcart.bin: bobcart.o $(IP65TCPLIB) $(C64RRNETLIB) $(INCFILES) ../cfg/c64_8kcart.cfg
@ -132,7 +130,7 @@ telnetd.prg: telnetd.bin cartheader.prg
d64_upload.d64: d64_upload.prg
cp d64_upload.prg ../../server/boot/
ripxplore.rb --init CbmDos $@ -a d64_upload.prg
c1541 -format d64upload,kd d64 $@ -attach $@ -write d64_upload.prg
clean:
rm -f *.o *.bin *.map *.prg *.pg2 *.dsk *.d64

View File

@ -66,9 +66,10 @@ end
if option_length==6 then
if value.downcase=="auto" then
require 'digest/md5'
digest = Digest::MD5.digest(Time.now.to_s)
digest = Digest::MD5.digest(Time.now.to_s).bytes.to_a
mac=[0x00,0x80,0x10,digest[0],digest[1],Kernel.rand(255)]
else
split_values=value.split(":")
if (split_values.length!=6) || (split_values[5].nil?) then
puts "'#{value}' is not a valid MAC address. (e.g. 12:34:56:78:ab:cd)"

View File

@ -56,16 +56,12 @@ upnatom.prg: upnatom.o $(IP65TCPLIB) $(C64RRNETLIB) $(INCFILES) ../cfg/c64prg.c
upnatom.d64: upnatom.prg url.cfg
cp upnatom.prg autoexec.prg
ripxplore.rb --init CbmDos upnatom.d64 -a autoexec.prg
ripxplore.rb upnatom.d64 -a url.cfg -t C64Seq
c1541 -format upnatom,up d64 $@ -attach $@ -write ../carts/kipperkart.prg "kipperkart.prg" -write autoexec.prg -write "url.cfg" "url.cfg,s"
webnoter.d64: webnoter.prg
cp webnoter.prg autoexec.prg
ripxplore.rb --init CbmDos webnoter.d64 -a ../carts/kipperkart.prg
ripxplore.rb webnoter.d64 -a autoexec.prg
c1541 -format webnoter,wn d64 $@ -attach $@ -write ../carts/kipperkart.prg "kipperkart.prg" -write autoexec.prg
httpd.prg: httpd.asm
$(DA) httpd.asm -ohttpd.prg
@ -74,8 +70,7 @@ httpd.prg: httpd.asm
%.d64: %.prg
cp $*.prg autoexec.prg
ripxplore.rb --init CbmDos $*.d64 -a autoexec.prg
c1541 -format kipper,kp d64 $@ -attach $@ -write autoexec.prg
clean:
rm -f *.o *.pg2 *.prg *.map upnatom.d64

View File

@ -1 +1 @@
.byte "1.0.39"
.byte "1.0.41"

View File

@ -38,6 +38,7 @@ ETHOBJS= \
url.o \
arithmetic.o\
ip.o \
sntp.o \
icmp.o \
cifs.o \
udp.o

213
client/ip65/sntp.s Normal file
View File

@ -0,0 +1,213 @@
; Simple Network Time Protocol implementation - per RFC 2030
MAX_SNTP_MESSAGES_SENT=8
.include "../inc/common.i"
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/kipper_constants.i"
.endif
.export sntp_ip
.export sntp_utc_timestamp
.export sntp_get_time
.import ip65_process
.import ip65_error
.import udp_add_listener
.import udp_remove_listener
.import udp_callback
.import udp_send
.import udp_inp
.import output_buffer
.importzp udp_data
.import udp_send_dest
.import udp_send_src_port
.import udp_send_dest_port
.import udp_send_len
.import check_for_abort_key
.import timer_read
.segment "IP65ZP" : zeropage
.data
sntp_ip: .byte $ff,$ff,$ff,$ff ;can be set to ip address of server that will be queried via sntp (default is a local LAN broadcast)
.bss
; sntp packet offsets
sntp_inp = udp_inp + udp_data
sntp_server_port=123
sntp_client_port=123
sntp_utc_timestamp: .res 4 ; will be set to seconds (only) part of utc timestamp (seconds since 00:00 on Jan 1, 1900)
; sntp state machine
sntp_initializing = 1 ; initial state
sntp_query_sent = 2 ; sent a query, waiting for a response
sntp_completed = 3 ; got a good response
sntp_timer: .res 1
sntp_loop_count: .res 1
sntp_break_polling_loop: .res 1
sntp_state: .res 1
sntp_message_sent_count: .res 1
.code
; query an sntp server for current UTC time
; inputs:
; sntp_ip must point to an SNTP server
; outputs:
; carry flag is set if there was an error, clear otherwise
; sntp_utc_timestamp: set to the number of seconds (seconds since 00:00 on Jan 1, 1900) - timezone is UTC
sntp_get_time:
ldax #sntp_in
stax udp_callback
ldax #sntp_client_port
jsr udp_add_listener
bcc :+
rts
:
lda #sntp_initializing
sta sntp_state
lda #0 ;reset the "message sent" counter
sta sntp_message_sent_count
jsr send_sntp_query
@sntp_polling_loop:
lda sntp_message_sent_count
adc #10
sta sntp_loop_count
@outer_delay_loop:
lda #0
sta sntp_break_polling_loop
jsr timer_read
stx sntp_timer ;we only care about the high byte
@inner_delay_loop:
jsr ip65_process
jsr check_for_abort_key
bcc @no_abort
lda #KPR_ERROR_ABORTED_BY_USER
sta ip65_error
rts
@no_abort:
lda sntp_state
cmp #sntp_completed
beq @complete
lda sntp_break_polling_loop
bne @break_polling_loop
jsr timer_read
cpx sntp_timer ;this will tick over after about 1/4 of a second
beq @inner_delay_loop
dec sntp_loop_count
bne @outer_delay_loop
@break_polling_loop:
jsr send_sntp_query
inc sntp_message_sent_count
lda sntp_message_sent_count
cmp #MAX_SNTP_MESSAGES_SENT-1
bpl @too_many_messages_sent
jmp @sntp_polling_loop
@complete:
ldax #sntp_client_port
jsr udp_remove_listener
rts
@too_many_messages_sent:
@failed:
ldax #sntp_client_port
jsr udp_remove_listener
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
sec ;signal an error
rts
send_sntp_query:
;make a zero filled buffer
lda #$0
ldx #$30
stx udp_send_len
sta udp_send_len+1
:
sta output_buffer,x
dex
bpl :-
;set the flags field
lda #$E3 ; flags - LI=11 (unknown), VN=100 (4), MODE=011 (client)
sta output_buffer
ldax #sntp_client_port
stax udp_send_src_port
ldax #sntp_server_port
stax udp_send_dest_port
ldx #3 ; set destination address
: lda sntp_ip,x
sta udp_send_dest,x
dex
bpl :-
ldax #output_buffer
jsr udp_send
bcs @error_on_send
lda #sntp_query_sent
sta sntp_state
@error_on_send:
rts
sntp_in:
ldx #3
ldy #0
:
lda sntp_inp+$28,x ;the 'transmit' timestamp (in big end order)
sta sntp_utc_timestamp,y
iny
dex
bpl :-
inc sntp_break_polling_loop
lda #sntp_completed
sta sntp_state
rts
;-- LICENSE FOR sntp.s --
; The contents of this file are subject to the Mozilla Public License
; Version 1.1 (the "License"); you may not use this file except in
; compliance with the License. You may obtain a copy of the License at
; http://www.mozilla.org/MPL/
;
; Software distributed under the License is distributed on an "AS IS"
; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
; License for the specific language governing rights and limitations
; under the License.
;
; The Original Code is ip65.
;
; The Initial Developer of the Original Code is Jonno Downes,
; jonno@jamtronix.com.
; Portions created by the Initial Developer are Copyright (C) 2009,2011
; Jonno Downes. All Rights Reserved.
; -- LICENSE END --

View File

@ -38,15 +38,11 @@ kt2wiz.prg: kipperterm2.o $(IP65WIZNETLIB) $(C64WIZNETLIB) $(INCFILES) ../cfg/c6
kipperterm2.d64: kipperterm2.prg addresses.txt abe.bas
ripxplore.rb --init CbmDos $@ -a kipperterm2.prg
ripxplore.rb $@ -a addresses.txt -t C64Seq
ripxplore.rb $@ -a abe -t C64Prg
c1541 -format kipperterm2,k2 d64 $@ -attach $@ -write kipperterm2.prg -write "addresses.txt " "addresses.txt,s" -write abe
cp kipperterm2.d64 ../../server/boot
kt2wiz.d64: kt2wiz.prg addresses.txt abe.bas
ripxplore.rb --init CbmDos $@ -a kt2wiz.prg
ripxplore.rb $@ -a addresses.txt -t C64Seq
ripxplore.rb $@ -a abe -t C64Prg
c1541 -format kt2wiz,kw d64 $@ -attach $@ -write kt2wiz.prg -write "addresses.txt " "addresses.txt,s" -write abe
cp kt2wiz.d64 ../wiznet/
clean:

View File

@ -1 +1 @@
.byte "2011-06-10"
.byte "2012-01-08"

View File

@ -33,7 +33,7 @@ all: \
testtftp.pg2 \
test_cart_api.prg \
test_vt100.prg \
testdottedquad.pg2 \
test_sntp.prg \
testdottedquad.prg \
test_tcp.prg \
test_xmodem.prg \
@ -44,7 +44,8 @@ all: \
test_get_url.prg \
test_wiznet.prg \
test_parse_querystring.prg \
test_lancegs.pg2 \
test_sntp.prg \
# test_lancegs.pg2 \
# test_xmodem.d64 \
# httpd_test.d64 \
# ip65test.dsk \
@ -71,7 +72,6 @@ test_tcp.prg: test_tcp.o $(IP65TCPLIB) $(C64RRNETLIB) $(INCFILES) ../cfg/c64prg.
test_xmodem.o: test_xmodem.s ../ip65/xmodem.s
$(AS) $(AFLAGS) $<
test_xmodem.prg: test_xmodem.o $(IP65TCPLIB) $(C64RRNETLIB) $(INCFILES) ../cfg/c64prg.cfg
$(LD) -m test_xmodem.map -vm -C ../cfg/c64prg.cfg -o test_xmodem.prg $(AFLAGS) $< $(IP65TCPLIB) $(C64RRNETLIB)

View File

@ -68,10 +68,7 @@ wizbobcart.prg: wizbobcart.bin cartheader.prg
cat cartheader.prg wizbobcart.bin > $@
wiztest.d64: wiztest.prg wizboot.prg wizflash.prg
ripxplore.rb -I CbmDos $@
ripxplore.rb -a wizboot.prg $@
ripxplore.rb -a wiztest.prg $@
ripxplore.rb -a wizflash.prg $@
c1541 -format wiztest,wt d64 $@ -attach $@ -write wizboot.prg -write wiztest.prg -write wizflash.prg
clean:
rm -f *.o *.bin *.map *.prg *.pg2 *.dsk *.d64

View File

@ -1 +1 @@
1.0.39
1.0.41