diff --git a/client/libnet/Makefile b/client/libnet/Makefile new file mode 100644 index 0000000..6a3cb1f --- /dev/null +++ b/client/libnet/Makefile @@ -0,0 +1,52 @@ +CC=cc65 +CL=cl65 +AS=ca65 +LD=ld65 +CFLAGS=-Oirs -t $(TARGET) +AFLAGS= + + + +IP65LIB=../ip65/ip65.lib +IP65TCPLIB=../ip65/ip65_tcp.lib +C64RRNETLIB=../drivers/c64rrnet.lib +C64WIZNETLIB=../drivers/c64wiznet.lib +IP65WIZNETLIB=../ip65/ip65_wiznet.lib +A2UTHERLIB=../drivers/a2uther.lib +A2LANCEGSLIB=../drivers/a2lancegs.lib +VIC20RRNETLIB=../drivers/vic20rrnet.lib +LIBNET=libnet.o + +INCFILES=\ + ../inc/common.i\ + ../inc/commonprint.i\ + ../inc/net.i\ + +all: \ + ip65 \ + drivers \ + libnet.o \ + test_sntp.prg \ + +ip65: + make -C ../ip65 all + +drivers: + make -C ../drivers all + +%.o: %.s + $(AS) $(AFLAGS) $< + +test_sntp.prg: test_sntp.c $(IP65TCPLIB) $(C64RRNETLIB) $(INCFILES) $(LIBNET) + $(CL) $< -m test_sntp.map -C c64libnet.cfg -o $@ $(LIBNET) $(IP65TCPLIB) $(C64RRNETLIB) + $(CC) test_sntp.c #this just makes a asm listing to help debug + + + +clean: + rm -f *.o *.pg2 *.prg *.map + rm -f ip65test.dsk + + +distclean: clean + rm -f *~ diff --git a/client/libnet/c64libnet.cfg b/client/libnet/c64libnet.cfg new file mode 100644 index 0000000..94ca560 --- /dev/null +++ b/client/libnet/c64libnet.cfg @@ -0,0 +1,43 @@ +MEMORY { + ZP: start = $02, size = $1A, type = rw ,define = yes ; + IP65ZP: start = $5f, size = $10, type = rw,define = yes; + RAM: start = $07FF, size = $c7ab, file = %O,define = yes; +} + +SEGMENTS { + STARTUP: load = RAM, type = ro; + LOWCODE: load = RAM, type = ro, optional = yes; + INIT: load = RAM, type = ro, define = yes, optional = yes; + CODE: load = RAM, type = ro; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + SELF_MODIFIED_CODE: load = RAM, type = rw,define = yes, optional=yes; + IP65_DEFAULTS: load = RAM, type = rw,define = yes, optional=yes; + APP_SCRATCH: load = RAM, type = bss, optional=yes; + TCP_VARS: load = RAM, type = bss, optional=yes; + HTTP_VARS: load = RAM, type = bss, optional=yes; + BSS: load = RAM, type = bss, define = yes; + HEAP: load = RAM, type = bss, optional = yes; # must sit just below stack + ZPSAVE: load = RAM, type = bss; + + ZEROPAGE: load = ZP, type = zp; + IP65ZP: load = IP65ZP, type = zp, optional=yes; + +} +FEATURES { + CONDES: segment = INIT, + type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__; + CONDES: segment = RODATA, + type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__; + CONDES: segment = RODATA, + type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__; +} +SYMBOLS { + __STACKSIZE__: value = $0800, weak = yes; # 2k stack +} diff --git a/client/libnet/libnet.h b/client/libnet/libnet.h new file mode 100644 index 0000000..74eff20 --- /dev/null +++ b/client/libnet/libnet.h @@ -0,0 +1,47 @@ + +#ifndef _LIBNET_H +#define _LIBNET_H + + +/* IP configuration structure */ +typedef unsigned char u8; +typedef unsigned char libnet_err_t; + +typedef struct ip_config { + u8 ip_addr[4]; + u8 netmask[4]; + u8 gateway_addr[4]; + u8 dns_server_addr[4]; +} IP_CONFIG; + + +#define LIBNET_USE_DHCP 0x0000 + +extern libnet_err_t __fastcall__ libnet_init (IP_CONFIG* config_p); +extern void __fastcall__ libnet_get_config (IP_CONFIG* config_p); +extern char libnet_MAC[6]; + + + + +#define LIBNET_OK 0x00 +#define LIBNET_ERROR_PORT_IN_USE 0x80 +#define LIBNET_ERROR_TIMEOUT_ON_RECEIVE 0x81 +#define LIBNET_ERROR_TRANSMIT_FAILED 0x82 +#define LIBNET_ERROR_TRANSMISSION_REJECTED_BY_PEER 0x83 +#define LIBNET_ERROR_INPUT_TOO_LARGE 0x84 +#define LIBNET_ERROR_DEVICE_FAILURE 0x85 +#define LIBNET_ERROR_ABORTED_BY_USER 0x86 +#define LIBNET_ERROR_LISTENER_NOT_AVAILABLE 0x87 +#define LIBNET_ERROR_NO_SUCH_LISTENER 0x88 +#define LIBNET_ERROR_CONNECTION_RESET_BY_PEER 0x89 +#define LIBNET_ERROR_CONNECTION_CLOSED 0x8A +#define LIBNET_ERROR_TOO_MANY_ERRORS 0x8B +#define LIBNET_ERROR_FILE_ACCESS_FAILURE 0x90 +#define LIBNET_ERROR_MALFORMED_URL 0xA0 +#define LIBNET_ERROR_DNS_LOOKUP_FAILED 0xA1 +#define LIBNET_ERROR_OPTION_NOT_SUPPORTED 0xFE +#define LIBNET_ERROR_FUNCTION_NOT_SUPPORTED 0xFF + + +#endif diff --git a/client/libnet/libnet.s b/client/libnet/libnet.s new file mode 100644 index 0000000..c88c230 --- /dev/null +++ b/client/libnet/libnet.s @@ -0,0 +1,95 @@ +.export _libnet_init +.export _libnet_get_config +.export _libnet_MAC + +.import cfg_init +.import cfg_ip +.import copymem +.import ip65_init +.import dhcp_init +.import ip65_error +.import cfg_mac_default +.import cfg_mac +.import cfg_size + +_libnet_MAC=cfg_mac_default + +; load A/X macro +.macro ldax arg +.if (.match (.left (1, arg), #)) ; immediate mode + lda #<(.right (.tcount (arg)-1, arg)) + ldx #>(.right (.tcount (arg)-1, arg)) +.else ; assume absolute or zero page + lda arg + ldx 1+(arg) +.endif +.endmacro + +; store A/X macro +.macro stax arg + sta arg + stx 1+(arg) +.endmacro + + +NO_ERROR=$00 + + +.importzp copy_src +.importzp copy_dest +.zeropage + +.code +_libnet_init: + sta copy_src + stx copy_src+1 + beq @dhcp_request + ldax #cfg_ip + stax copy_dest + ldax #$10 ;4 items of config data + jsr copymem + jsr ip65_init +@check_error: + bcc @ok + lda ip65_error + rts +@ok: + lda #NO_ERROR + rts + + +@dhcp_request: + jsr ip65_init + jsr dhcp_init + jmp @check_error + +_libnet_get_config: + + stax copy_dest + ldax #cfg_ip + stax copy_src + ldax #$10 ;4 items of config data + + jmp copymem + +.bss +tmp_ax: .res 2 + +;-- LICENSE FOR libnet.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 libnet. +; +; The Initial Developer of the Original Code is Jonno Downes, +; jonno@jamtronix.com. +; Portions created by the Initial Developer are Copyright (C) 2012 +; Jonno DOwnes. All Rights Reserved. +; -- LICENSE END -- diff --git a/client/libnet/test_sntp.c b/client/libnet/test_sntp.c new file mode 100644 index 0000000..f4cffdc --- /dev/null +++ b/client/libnet/test_sntp.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include "libnet.h" + +/* +#define SECONDS_IN_DAY 86400 +#define NTP_TO_UNIX = 2208988800 //((70 * 365 + 17) * 86400); +struct tm* __fastcall__ sntp_timestamp_to_tm(unsigned long sntp_timestamp) { + unsigned long epoch_timestamp=sntp_timestamp-NTP_TO_UNIX; + return (gmtime(&epoch_timestamp)); +} +int main (void) +{ + unsigned long timestamp=0xd2b929e6; + signed long utc_offset=-10; + struct tm * _tm; + timestamp+=(utc_offset*3600); + _tm=sntp_timestamp_to_tm(timestamp); + printf ("%02d:%02d:%02d\n",_tm->tm_hour,_tm->tm_min,_tm->tm_sec); + puts (asctime(_tm)); + return EXIT_SUCCESS; +} + +*/ + +char * addr_to_s(u8* a) { + static char buffer[16]; + sprintf(buffer,"%u.%u.%u.%u",a[0],a[1],a[2],a[3]); + return(buffer); +} +void showconfig(void) { + IP_CONFIG config_p; + libnet_get_config(&config_p); + printf ("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",libnet_MAC[0],libnet_MAC[1], + libnet_MAC[2],libnet_MAC[3],libnet_MAC[4],libnet_MAC[5],); + printf ("IP: %s\n",addr_to_s(config_p.ip_addr)); + printf ("NETMASK: %s\n",addr_to_s(config_p.netmask)); + printf ("GATEWAY: %s\n",addr_to_s(config_p.gateway_addr)); + printf ("DNS: %s\n",addr_to_s(config_p.dns_server_addr)); +} +int main (void) +{ + IP_CONFIG _default_config ={ + {1,2,3,4}, //IP address + {255,255,255,0}, // netmask + {192,168,1,1}, //default gateway + {192,168,2,1}, // dns server + }; + + libnet_err_t ln_err; + +// ln_err=libnet_init(&_default_config); + ln_err=libnet_init(LIBNET_USE_DHCP); + + printf("result: %02x\n",ln_err); + showconfig(); + return EXIT_SUCCESS; +}