From 7037fa9979d1133a81f3855f07d1deb95d8427fd Mon Sep 17 00:00:00 2001 From: Joerg Deckert Date: Sun, 22 Dec 2013 18:10:57 +0100 Subject: [PATCH] cleanup, sending password added --- lib/adm-lan.spin | 173 --------------------------- lib/glob-con.spin | 13 +- lib/reg-ios.spin | 80 ++----------- system/administra/admnet/admnet.spin | 126 +++++-------------- system/regnatix/ftp.spin | 83 ++++++++----- 5 files changed, 101 insertions(+), 374 deletions(-) delete mode 100644 lib/adm-lan.spin diff --git a/lib/adm-lan.spin b/lib/adm-lan.spin deleted file mode 100644 index ffdb5c3..0000000 --- a/lib/adm-lan.spin +++ /dev/null @@ -1,173 +0,0 @@ -{{ LAN-Funktionen für Administra }} - -CON 'Signaldefinitionen -------------------------------------------------------------------------- - -'signaldefinitionen administra (todo: nach glob-con.spin auslagern!!!) - -#14, A_NETCS,A_NETSCK,A_NETSI,A_NETSO 'Pins zum ENC28J60 - -CON 'NVRAM Konstanten -------------------------------------------------------------------------- - -' todo: nach glob-con.spin auslagern!!! - -#4, NVRAM_IPADDR -#8, NVRAM_IPMASK -#12, NVRAM_IPGW -#16, NVRAM_IPDNS -#20, NVRAM_IPBOOT -#24, NVRAM_HIVE ' 4 Bytes - -CON - - ' buffer sizes, must be a power of 2 - rxlen = 2048 - txlen = 128 - -VAR - - byte ftp_bufrx1[rxlen] ' buffers for connection to server - byte ftp_buftx1[txlen] - - byte ftp_bufrx2[rxlen] ' buffers for connection from server - byte ftp_buftx2[txlen] - - byte strTemp[128] - -OBJ - - gc : "glob-con" 'globale konstanten - num : "glob-numbers" 'Number Engine - rtc : "adm-rtc" 'RTC-Engine - com : "adm-com" 'serielle schnittstelle (nur zum Debugging genutzt) - sock : "api_telnet_serial" 'TCP Socket Funktionen - -PUB start | hiveid, hivestr, strpos, macpos - - ip_addr := rtc.getNVSRAM(NVRAM_IPADDR) - ip_addr[1] := rtc.getNVSRAM(NVRAM_IPADDR+1) - ip_addr[2] := rtc.getNVSRAM(NVRAM_IPADDR+2) - ip_addr[3] := rtc.getNVSRAM(NVRAM_IPADDR+3) - - ip_subnet := rtc.getNVSRAM(NVRAM_IPMASK) - ip_subnet[1] := rtc.getNVSRAM(NVRAM_IPMASK+1) - ip_subnet[2] := rtc.getNVSRAM(NVRAM_IPMASK+2) - ip_subnet[3] := rtc.getNVSRAM(NVRAM_IPMASK+3) - - ip_gateway := rtc.getNVSRAM(NVRAM_IPGW) - ip_gateway[1] := rtc.getNVSRAM(NVRAM_IPGW+1) - ip_gateway[2] := rtc.getNVSRAM(NVRAM_IPGW+2) - ip_gateway[3] := rtc.getNVSRAM(NVRAM_IPGW+3) - - ip_dns := rtc.getNVSRAM(NVRAM_IPDNS) - ip_dns[1] := rtc.getNVSRAM(NVRAM_IPDNS+1) - ip_dns[2] := rtc.getNVSRAM(NVRAM_IPDNS+2) - ip_dns[3] := rtc.getNVSRAM(NVRAM_IPDNS+3) - - hiveid := rtc.getNVSRAM(NVRAM_HIVE) - hiveid := hiveid + rtc.getNVSRAM(NVRAM_HIVE+1) << 8 - hiveid := hiveid + rtc.getNVSRAM(NVRAM_HIVE+2) << 16 - hiveid := hiveid + rtc.getNVSRAM(NVRAM_HIVE+3) << 24 - hivestr := num.ToStr(hiveid, num#DEC) - strpos := strsize(hivestr) - macpos := 5 - repeat while (strpos AND macpos) - strpos-- - if(strpos) - strpos-- - mac_addr[macpos] := num.FromStr(hivestr+strpos, num#HEX) - byte[hivestr+strpos] := 0 - macpos-- - - sock.start(A_NETCS,A_NETSCK,A_NETSI,A_NETSO, -1, @mac_addr, @ip_addr) - -PUB stop - - sock.stop - -PUB ftpOpen(addr) : connected 'FTP-Verbindung öffnen - - com.str(string("ftpOpen Start",13,10)) - repeat 5 'mehrmals probieren, falls z.B. TCP-Engine-Cog noch nicht bereit - sock.connect(addr, 21, @ftp_bufrx1, rxlen, @ftp_buftx1, txlen) - 'sock.resetBuffers - if connected := sock.waitConnectTimeout(1500) - 'todo: einfügen? if getResponse(string("220")) - if getResponse(string("220 ")) - com.str(string("Send: USER anonymous",13,10)) - sock.str(string("USER anonymous",13,10)) - if getResponse(string("230 ")) - quit - else - sock.close - -PUB ftpClose 'FTP-Verbindung schließen - - com.str(string("Send: QUIT",13,10)) - sock.str(string("QUIT",13,10)) - getResponse(string("221 ")) - sock.close - -PUB ftpOpenData(addr,port) : connected - -PUB ftpCloseData - -PUB ftpBoot 'zum Boot-Server verbinden - - ip_boot := rtc.getNVSRAM(NVRAM_IPBOOT) << 24 - ip_boot := ip_boot + rtc.getNVSRAM(NVRAM_IPBOOT+1) << 16 - ip_boot := ip_boot + rtc.getNVSRAM(NVRAM_IPBOOT+2) << 8 - ip_boot := ip_boot + rtc.getNVSRAM(NVRAM_IPBOOT+3) - - if ip_boot - if ftpOpen(ip_boot) - ftpClose - -PUB ftpListName 'Verzeichniseintrag lesen - - return - -PRI getResponse (strOk) : respOk | len - - respOk := FALSE - - repeat - readLine - com.str(@strTemp) - com.str(string(13,10)) - if strsize(@strTemp) == 0 - quit - 'byte[@strTemp+strsize(strOk)] := 0 - strTemp[strsize(strOk)] := 0 - com.str(string("StrOk: ")) - com.str(strOk) - com.str(string("StrComp: ")) - com.str(@strTemp) - com.str(string(13,10)) - if strcomp(@strTemp, strOk) - respOk := TRUE - - return respOk - -PRI readLine | i, ch - - repeat i from 0 to 126 - ch := sock.rxtime(500) - if ch == 13 - ch := sock.rxtime(500) - if ch == -1 or ch == 10 - quit - strTemp[i] := ch - - strTemp[i] := 0 - - return i - -DAT - long ' long alignment for addresses - ip_addr byte 10, 1, 1, 1 'ip - ip_subnet byte 255, 255, 255, 0 'subnet-maske - ip_gateway byte 10, 1, 1, 254 'gateway - ip_dns byte 10, 1, 1, 254 'dns - ip_boot long 0 'boot-server (IP address in long) - mac_addr byte $c0, $de, $ba, $be, $00, $00 'mac-adresse - diff --git a/lib/glob-con.spin b/lib/glob-con.spin index 731fe18..462d933 100644 --- a/lib/glob-con.spin +++ b/lib/glob-con.spin @@ -168,22 +168,11 @@ A_AYS = %00000000_00000000_00000010_00000000 a_lanStop 'Stop Network a_lanConnect 'ausgehende TCP-Verbindung öffnen a_lanListen 'auf eingehende TCP-Verbindung lauschen - a_lanReListen 'wieder auf eingehende TCP-Verbindung lauschen - a_lanIsConnected 'Prüfen, ob verbunden - a_lanRXCount 'Anzahl Zeichen im Empfangspuffer - a_lanResetBuffers 'Puffer zurücksetzen a_lanWaitConnTimeout 'bestimmte Zeit auf Verbindung warten a_lanClose 'TCP-Verbindung schließen - a_lanRXFlush 'Empfangspuffer leeren - a_lanRXCheck 'warten auf Byte aus Empfangspuffer a_lanRXTime 'bestimmte Zeit warten auf Byte aus Empfangspuffer - a_lanRXByte 'Byte aus Empfangspuffer lesen - a_lanRXDataTime 'bestimmte Zeit auf daten aus Empfangspuffer warten a_lanRXData 'Daten aus Empfangspuffer lesen - a_lanTXFlush 'Sendepuffer leeren - a_lanTXCheck 'Verbindung prüfen und Byte senden - a_lanTX 'Byte senden - a_lanTXData '90 'Daten senden + a_lanTXData '79 'Daten senden ' ---------------------------------------------- CHIP-MANAGMENT #92, a_mgrSetSound 'soundsubsysteme verwalten diff --git a/lib/reg-ios.spin b/lib/reg-ios.spin index e2ba93a..14e1d82 100644 --- a/lib/reg-ios.spin +++ b/lib/reg-ios.spin @@ -1064,39 +1064,25 @@ PUB lan_connect(ipaddr, remoteport): handleidx bus_putword1(remoteport) handleidx := bus_getchar1 -PUB lan_listen -PUB lan_relisten -PUB lan_isconnected(handleidx): connected +PUB lan_listen(port): handleidx ''funktionsgruppe : lan -''funktion : Abfrage, ob Socket verbunden +''funktion : Port für eingehende TCP-Verbindung öffnen ''eingabe : - ''ausgabe : - -''busprotokoll : [076][sub_putlong.handle][get.connected] -'' : handleidx - lfd. Nr. der zu testenden Verbindung -'' : connected - True, if connected +''busprotokoll : [074][sub_putword.port][get.handleidx] +'' : port - zu öffnende Portnummer +'' : handleidx - lfd. Nr. der Verbindung (index des kompletten handle) - bus_putchar1(gc#a_lanIsConnected) - bus_putchar1(handleidx) - connected := bus_getchar1 - -PUB lan_rxcount -PUB lan_resetbuffers(handleidx) -''funktionsgruppe : lan -''funktion : Sende- und Empfangspuffer zurücksetzen -''eingabe : - -''ausgabe : - -''busprotokoll : [078][put.handleidx] -'' : handleidx - lfd. Nr. der Verbindung - - bus_putchar1(gc#a_lanResetBuffers) - bus_putchar1(handleidx) + bus_putchar1(gc#a_lanListen) + bus_putword1(port) + handleidx := bus_getchar1 PUB lan_waitconntimeout(handleidx, timeout): connected ''funktionsgruppe : lan ''funktion : bestimmte Zeit auf Verbindung warten ''eingabe : - ''ausgabe : - -''busprotokoll : [079][put.handleidx][sub_putword.timeout][get.connected] +''busprotokoll : [075][put.handleidx][sub_putword.timeout][get.connected] '' : handleidx - lfd. Nr. der zu testenden Verbindung '' : timeout - Timeout in Millisekunden '' : connected - True, if connected @@ -1111,38 +1097,19 @@ PUB lan_close(handleidx) ''funktion : TCP-Verbindung (ein- oder ausgehend) schließen ''eingabe : - ''ausgabe : - -''busprotokoll : [080][put.handleidx] +''busprotokoll : [076][put.handleidx] '' : handleidx - lfd. Nr. der zu schließenden Verbindung bus_putchar1(gc#a_lanClose) bus_putchar1(handleidx) -PUB lan_rxflush -PUB lan_rxcheck(handleidx): rxbyte -''funktionsgruppe : lan -''funktion : ASCII-Zeichen lesen, wenn vorhanden -'' : nicht verwenden, wenn anderes als ASCII (0 - 127) empfangen wird -'' : (vor allem nicht, wenn -1 und -3 enthalten sein können) -''eingabe : - -''ausgabe : - -''busprotokoll : [082][put.handleidx][get.rxbyte] -'' : handleidx - lfd. Nr. der Verbindung -'' : rxbyte - empfangenes Zeichen (0 - 127) oder -'' : sock#RETBUFFEREMPTY (-1) wenn Puffer leer -'' : sock#ERRSOCKETCLOSED (-3) wenn keine Verbindung mehr - - bus_putchar1(gc#a_lanRXCheck) - bus_putchar1(handleidx) - rxbyte := bus_getchar1 - rxbyte := ~rxbyte - PUB lan_rxtime(handleidx, timeout): rxbyte ''funktionsgruppe : lan ''funktion : angegebene Zeit auf ASCII-Zeichen warten '' : nicht verwenden, wenn anderes als ASCII (0 - 127) empfangen wird ''eingabe : - ''ausgabe : - -''busprotokoll : [083][sub_putlong.handleidx][sub_putword.timeout][get.rxbyte] +''busprotokoll : [077][sub_putlong.handleidx][sub_putword.timeout][get.rxbyte] '' : handleidx - lfd. Nr. der Verbindung '' : timeout - Timeout in Millisekunden '' : rxbyte - empfangenes Zeichen (0 - 127) oder @@ -1154,14 +1121,12 @@ PUB lan_rxtime(handleidx, timeout): rxbyte rxbyte := bus_getchar1 rxbyte := ~rxbyte -PUB lan_rxbyte -PUB lan_rxdatatime PUB lan_rxdata(handleidx, filename, len): error | fnr ''funktionsgruppe : lan ''funktion : bei bestehender Verbindung die angegebene Datenmenge empfangen ''eingabe : - ''ausgabe : - -''busprotokoll : [086][put.handleidx][sub_putlong.len][get.byte1][get.byte][get.error] +''busprotokoll : [078][put.handleidx][sub_putlong.len][get.byte1][get.byte][get.error] '' : handleidx - lfd. Nr. der Verbindung '' : byte1 ... byte - zu empfangende Bytes '' : len - Anzahl zu empfangende Bytes @@ -1180,31 +1145,12 @@ PUB lan_rxdata(handleidx, filename, len): error | fnr error := bus_getchar1 error := ~error -PUB lan_txflush -PUB lan_txcheck(handleidx, txbyte): error -''funktionsgruppe : lan -''funktion : bei bestehender Verbindung ein ASCII-Zeichen zu senden -'' : nicht verwenden, wenn anderes als ASCII (0 - 127) gesendet wird -'' : (vor allem nicht, wenn -1 enthalten sein kann) -''eingabe : - -''ausgabe : - -''busprotokoll : [088][put.handleidx][put.tybyte][get.error] -'' : handleidx - lfd. Nr. der Verbindung -'' : txbyte - zu sendendes Zeichen -'' : error - ungleich Null bei Fehler - - bus_putchar1(gc#a_lanTXCheck) - bus_putchar1(handleidx) - bus_putchar1(txbyte) - error := bus_getchar1 - -PUB lan_tx PUB lan_txdata(handleidx, ptr, len): error ''funktionsgruppe : lan ''funktion : bei bestehender Verbindung die angegebene Datenmenge senden ''eingabe : - ''ausgabe : - -''busprotokoll : [090][put.handleidx][sub_putlong.len][put.byte1][put.byte][get.error] +''busprotokoll : [079][put.handleidx][sub_putlong.len][put.byte1][put.byte][get.error] '' : handleidx - lfd. Nr. der Verbindung '' : byte1 ... byte - zu sendende Bytes '' : len - Anzahl zu sendender Bytes diff --git a/system/administra/admnet/admnet.spin b/system/administra/admnet/admnet.spin index 42155a2..0955966 100644 --- a/system/administra/admnet/admnet.spin +++ b/system/administra/admnet/admnet.spin @@ -1,7 +1,7 @@ {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ -│ Autor: Ingo Kripahle & Jörg Deckert │ -│ Copyright (c) 2010 Ingo Kripahle, 2013 Jörg Deckert │ +│ Autor: Ingo Kripahle & Jörg Deckert │ +│ Copyright (c) 2010 Ingo Kripahle, 2013 Jörg Deckert │ │ See end of file for terms of use. │ │ Die Nutzungsbedingungen befinden sich am Ende der Datei │ └──────────────────────────────────────────────────────────────────────────────────────────────────────┘ @@ -50,7 +50,9 @@ Funktion : Diese Codeversion basiert auf admflash.spin und wird um einen - Wartefunktionen LAN-Funktionen: - - + - Ethernet-Port mit daten aus NVRAM initialisieren + - ein- und ausgehende Verbindungen öffnen + - Daten übertragen Komponenten : FATEngine 01/18/2009 Kwabena W. Agyeman MIT Lizenz RTCEngine 11/22/2009 Kwabena W. Agyeman MIT Lizenz @@ -58,9 +60,9 @@ Komponenten : FATEngine 01/18/2009 Kwabena W. Agyeman MIT Lizenz COG's : MANAGMENT 1 COG FAT/RTC 1 COG - NET 2 COGs + NET 1 COG ------------------- - 4 COGs + 3 COGs Logbuch : @@ -115,6 +117,7 @@ Logbuch : 03-12-2010-stepha - RTC Datums- und Zeit Funktionen 04-12-2010-stepha - NVRAM Funktionen 17-04-2013-dr235 - konstanten für administra-funktionen komplett ausgelagert +22-12-2013-joergd - LAN Funktionen Kommandoliste : @@ -291,21 +294,10 @@ PUB main | cmd,err 'chip: kommandointerpret gc#a_lanStop:lan_stop 'Stop Network gc#a_lanConnect: lan_connect 'ausgehende TCP-Verbindung öffnen gc#a_lanListen: lan_listen 'auf eingehende TCP-Verbindung lauschen - gc#a_lanReListen: lan_relisten 'wieder auf eingehende TCP-Verbindung lauschen - gc#a_lanIsConnected: lan_isconnected 'Prüfen, ob verbunden - gc#a_lanRXCount: lan_rxcount 'Anzahl Zeichen im Empfangspuffer - gc#a_lanResetBuffers: lan_resetbuffers 'Puffer zurücksetzen gc#a_lanWaitConnTimeout: lan_waitconntimeout 'bestimmte Zeit auf Verbindung warten gc#a_lanClose: lan_close 'TCP-Verbindung schließen - gc#a_lanRXFlush: lan_rxflush 'Empfangspuffer leeren - gc#a_lanRXCheck: lan_rxcheck 'warten auf Byte aus Empfangspuffer gc#a_lanRXTime: lan_rxtime 'bestimmte Zeit warten auf Byte aus Empfangspuffer - gc#a_lanRXByte: lan_rxbyte 'Byte aus Empfangspuffer lesen - gc#a_lanRXDataTime: lan_rxdatatime 'bestimmte Zeit auf daten aus Empfangspuffer warten gc#a_lanRXData: lan_rxdata 'Daten aus Empfangspuffer lesen - gc#a_lanTXFlush: lan_txflush 'Sendepuffer leeren - gc#a_lanTXCheck: lan_txcheck 'Verbindung prüfen und Byte senden - gc#a_lanTX: lan_tx 'Byte senden gc#a_lanTXData: lan_txdata 'Daten senden ' ---------------------------------------------- CHIP-MANAGMENT @@ -1202,7 +1194,7 @@ PRI lan_connect | ipaddr, remoteport, handle, handleidx, i quit i++ - ifnot (handle := sock.connect(ipaddr, remoteport, @bufrx[i*rxlen], rxlen, @buftx[i*txlen], txlen)) ==-102 + ifnot (handle := sock.connect(ipaddr, remoteport, @bufrx[i*rxlen], rxlen, @buftx[i*txlen], txlen)) == -102 handleidx := handle.byte[0] 'extract the handle index from the lower 8 bits sockhandle[handleidx] := handle 'komplettes handle zu handle index speichern bufidx[i] :=handleidx @@ -1210,40 +1202,38 @@ PRI lan_connect | ipaddr, remoteport, handle, handleidx, i else bus_putchar($FF) -PRI lan_listen -PRI lan_relisten -PRI lan_isconnected | handleidx +PRI lan_listen | port, handle, handleidx, i ''funktionsgruppe : lan -''funktion : Abfrage, ob Socket verbunden +''funktion : Port für eingehende TCP-Verbindung öffnen ''eingabe : - ''ausgabe : - -''busprotokoll : [076][get.handleidx][put.connected] -'' : handleidx - lfd. Nr. der zu testenden Verbindung -'' : connected - True, if connected +''busprotokoll : [074][sub_getword.port][put.handleidx] +'' : port - zu öffnende Portnummer +'' : handleidx - lfd. Nr. der Verbindung (index des kompletten handle) - handleidx := bus_getchar + port := sub_getword - bus_putchar(sock.isConnected(sockhandle[handleidx])) + 'freien Pufferabschnitt suchen + i := 0 + repeat sock#sNumSockets + if bufidx[i] == $FF '0xFF: nicht zugewiesen + quit + i++ -PRI lan_rxcount -PRI lan_resetbuffers | handleidx -''funktionsgruppe : lan -''funktion : Sende- und Empfangspuffer zurücksetzen -''eingabe : - -''ausgabe : - -''busprotokoll : [078][sub_getlong.handle] -'' : handleidx - lfd. Nr. der Verbindung - - handleidx := bus_getchar - - sock.resetBuffers(sockhandle[handleidx]) + ifnot (handle := sock.listen(port, @bufrx[i*rxlen], rxlen, @buftx[i*txlen], txlen)) == -102 + handleidx := handle.byte[0] 'extract the handle index from the lower 8 bits + sockhandle[handleidx] := handle 'komplettes handle zu handle index speichern + bufidx[i] :=handleidx + bus_putchar(handleidx) 'handleidx senden + else + bus_putchar($FF) PRI lan_waitconntimeout | handleidx, timeout, t, connected ''funktionsgruppe : lan ''funktion : bestimmte Zeit auf Verbindung warten ''eingabe : - ''ausgabe : - -''busprotokoll : [079][get.handleidx][sub_getword.timeout][put.connected] +''busprotokoll : [075][get.handleidx][sub_getword.timeout][put.connected] '' : handleidx - lfd. Nr. der zu testenden Verbindung '' : timeout - Timeout in Millisekunden '' : connected - True, if connected @@ -1261,7 +1251,7 @@ PRI lan_close | handleidx, i ''funktion : TCP-Verbindung (ein- oder ausgehend) schließen ''eingabe : - ''ausgabe : - -''busprotokoll : [080][get.handleidx] +''busprotokoll : [076][get.handleidx] '' : handleidx - lfd. Nr. der zu schließenden Verbindung handleidx := bus_getchar @@ -1276,35 +1266,13 @@ PRI lan_close | handleidx, i quit -PRI lan_rxflush -PRI lan_rxcheck | handleidx, rxbyte -''funktionsgruppe : lan -''funktion : ASCII-Zeichen lesen, wenn vorhanden -'' : nicht verwenden, wenn anderes als ASCII (0 - 127) empfangen wird -'' : (vor allem nicht, wenn -1 und -3 enthalten sein können) -''eingabe : - -''ausgabe : - -''busprotokoll : [082][get.handleidx][put.rxbyte] -'' : handleidx - lfd. Nr. der Verbindung -'' : rxbyte - empfangenes Zeichen (0 - 127) oder -'' : sock#RETBUFFEREMPTY (-1) wenn Puffer leer -'' : sock#ERRSOCKETCLOSED (-3) wenn keine Verbindung mehr - - handleidx := bus_getchar - - rxbyte := sock.readByteNonBlocking(sockhandle[handleidx]) - if (not sock.isConnected(sockhandle[handleidx])) and (rxbyte == -1) - rxbyte := sock#ERRSOCKETCLOSED - - bus_putchar(rxbyte) - PRI lan_rxtime | handleidx, timeout, t, rxbyte ''funktionsgruppe : lan ''funktion : angegebene Zeit auf ASCII-Zeichen warten '' : nicht verwenden, wenn anderes als ASCII (0 - 127) empfangen wird ''eingabe : - ''ausgabe : - -''busprotokoll : [083][get.handleidx][sub_getword.timeout][put.rxbyte] +''busprotokoll : [077][get.handleidx][sub_getword.timeout][put.rxbyte] '' : handleidx - lfd. Nr. der Verbindung '' : timeout - Timeout in Millisekunden '' : rxbyte - empfangenes Zeichen (0 - 127) oder @@ -1318,14 +1286,12 @@ PRI lan_rxtime | handleidx, timeout, t, rxbyte bus_putchar(rxbyte) -PRI lan_rxbyte -PRI lan_rxdatatime PRI lan_rxdata | handleidx, len, rxbyte, error ''funktionsgruppe : lan ''funktion : bei bestehender Verbindung die angegebene Datenmenge empfangen ''eingabe : - ''ausgabe : - -''busprotokoll : [086][get.handleidx][sub_getlong.len][put.byte1][put.byte][put.error] +''busprotokoll : [078][get.handleidx][sub_getlong.len][put.byte1][put.byte][put.error] '' : handleidx - lfd. Nr. der Verbindung '' : len - Anzahl zu empfangender Bytes '' : error - ungleich Null bei Fehler @@ -1344,38 +1310,12 @@ PRI lan_rxdata | handleidx, len, rxbyte, error bus_putchar(error) -PRI lan_txflush -PRI lan_txcheck | handleidx, txbyte -''funktionsgruppe : lan -''funktion : bei bestehender Verbindung ein ASCII-Zeichen zu senden -'' : nicht verwenden, wenn anderes als ASCII (0 - 127) gesendet wird -'' : (vor allem nicht, wenn -1 enthalten sein kann) -''eingabe : - -''ausgabe : - -''busprotokoll : [088][get.handleidx][get.tybyte][put.error] -'' : handleidx - lfd. Nr. der Verbindung -'' : txbyte - zu sendendes Zeichen -'' : error - ungleich Null bei Fehler - - handleidx := bus_getchar - txbyte := bus_getchar - - ifnot sock.isConnected(sockhandle[handleidx]) - bus_putchar(sock#ERRSOCKETCLOSED) - - if (sock.writeByteNonBlocking(sockhandle[handleidx], txbyte) == txbyte) - bus_putchar(0) - else - bus_putchar(sock#RETBUFFERFULL) - - -PRI lan_tx PRI lan_txdata | handleidx, len, txbyte, error ''funktionsgruppe : lan ''funktion : bei bestehender Verbindung die angegebene Datenmenge senden ''eingabe : - ''ausgabe : - -''busprotokoll : [090][get.handleidx][sub_getlong.len][get.byte1][get.byte][put.error] +''busprotokoll : [079][get.handleidx][sub_getlong.len][get.byte1][get.byte][put.error] '' : handleidx - lfd. Nr. der Verbindung '' : len - Anzahl zu sendender Bytes '' : error - ungleich Null bei Fehler diff --git a/system/regnatix/ftp.spin b/system/regnatix/ftp.spin index b2721de..6e3ff46 100644 --- a/system/regnatix/ftp.spin +++ b/system/regnatix/ftp.spin @@ -1,7 +1,7 @@ {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ -│ Autor: Jörg Deckert │ -│ Copyright (c) 2013 Jörg Deckert │ +│ Autor: Jörg Deckert │ +│ Copyright (c) 2013 Jörg Deckert │ │ See end of file for terms of use. │ │ Die Nutzungsbedingungen befinden sich am Ende der Datei │ └──────────────────────────────────────────────────────────────────────────────────────────────────────┘ @@ -19,7 +19,7 @@ Komponenten : - COG's : - Logbuch : -11.12.2013-joergd - erste Version +22.12.2013-joergd - erste Version Kommandoliste : @@ -44,6 +44,7 @@ VAR long ip_addr byte parastr[64] + byte remdir[64] byte filename[64] byte strTemp[128] byte addrset @@ -53,6 +54,7 @@ VAR PUB main ip_addr := 0 + remdir[0] := 0 filename[0] := 0 ios.start 'ios initialisieren @@ -64,16 +66,17 @@ PUB main "?": ios.print(@help) "s": if ios.paranext(@parastr) setaddr(@parastr) - "d": if ios.paranext(@parastr) - download(@parastr) + "v": ios.paranext(@remdir) + "d": ios.paranext(@filename) other: ios.print(@help) ifnot ftpconnect ifnot ftplogin(string("anonymous"),string("password")) - ifnot ftpcwd(string("system")) - ifnot byte[filename][0] == 0 - if ftppasv - ftpretr + ifnot byte[@remdir][0] == 0 + ftpcwd + ifnot byte[@filename][0] == 0 + if ftppasv + ftpretr ftpclose @@ -88,14 +91,13 @@ PRI ftpconnect ios.print(string("Starte LAN...")) ios.printnl ios.lanstart - delay_ms(1000) 'nach ios.lanstart dauert es, bis der Stack funktioniert + delay_ms(800) 'nach ios.lanstart dauert es, bis der Stack funktioniert ios.print(string("Verbinde mit FTP-Server...")) ios.printnl if (handleidx_control := ios.lan_connect(ip_addr, 21)) == $FF ios.print(string("Kein Socket frei...")) ios.printnl return(-1) -'' ios.lan_resetbuffers(handleidx_control) ifnot (ios.lan_waitconntimeout(handleidx_control, 2000)) ios.print(string("Verbindung mit FTP-Server konnte nicht aufgebaut werden.")) ios.printnl @@ -117,7 +119,10 @@ PRI ftpclose ios.lan_close(handleidx_data) handleidx_data := 0 -PRI ftplogin(username, password) +PRI ftplogin(username, password) | pwreq, respOK + + pwreq := FALSE + respOK := FALSE ifnot strsize(username) username := string("anonymous") @@ -125,17 +130,43 @@ PRI ftplogin(username, password) ios.print(string("Fehler beim Senden des Usernamens")) ios.printnl return(-1) + + repeat until readLine == -1 + ios.print(string(" < ")) + ios.print(@strTemp) + ios.printnl + strTemp[4] := 0 + if strcomp(@strTemp, string("230 ")) + respOk := TRUE + ios.print(string("Antwort korrekt.")) + ios.printnl + elseif strcomp(@strTemp, string("331 ")) + pwreq := TRUE + respOk := TRUE + ios.print(string("Antwort korrekt.")) + ios.printnl + ifnot respOK + ios.print(string("Keine oder falsche Antwort vom FTP-Server erhalten.")) + ios.printnl + return(-1) + + ifnot pwreq + return(0) + + if sendStr(string("PASS ")) || sendStr(password) || sendStr(string(13,10)) + ios.print(string("Fehler beim Senden des Passworts")) + ios.printnl + return(-1) ifnot getResponse(string("230 ")) ios.print(string("Keine oder falsche Antwort vom FTP-Server erhalten.")) ios.printnl return(-1) + return(0) -PRI ftpcwd(directory) +PRI ftpcwd - ifnot strsize(directory) - directory := string("/") - if sendStr(string("CWD ")) || sendStr(directory) || sendStr(string(13,10)) + if sendStr(string("CWD ")) || sendStr(@remdir) || sendStr(string(13,10)) ios.print(string("Fehler beim Senden des Verzeichnisses")) ios.printnl return(-1) @@ -194,7 +225,7 @@ PRI ftppasv : port | i, k, port256, port1 PRI ftpretr | len - if sendStr(string("SIZE ")) || sendStr(filename) || sendStr(string(13,10)) + if sendStr(string("SIZE ")) || sendStr(@filename) || sendStr(string(13,10)) ios.print(string("Fehler beim Senden des SIZE-Kommandos")) ios.printnl return(-1) @@ -214,7 +245,7 @@ PRI ftpretr | len ios.printnl return(-1) - if sendStr(string("RETR ")) || sendStr(filename) || sendStr(string(13,10)) + if sendStr(string("RETR ")) || sendStr(@filename) || sendStr(string(13,10)) ios.print(string("Fehler beim Senden des Filenamens")) return -1 ifnot getResponse(string("150 ")) @@ -222,7 +253,7 @@ PRI ftpretr | len ios.printnl return(-1) - if ios.lan_rxdata(handleidx_data, filename, len) + if ios.lan_rxdata(handleidx_data, @filename, len) ios.print(string("Fehler beim Empfang der Datei.")) ios.printnl return(-1) @@ -232,13 +263,6 @@ PRI ftpretr | len ios.printnl return(-1) -PRI download (parameter) | i 'filename kopieren - - repeat strsize(parameter) - byte[filename][i] := byte[parameter][i] - i++ - byte[filename][i] := 0 - PRI setaddr (ipaddr) | pos, count 'IP-Adresse in Variable schreiben count := 3 @@ -294,9 +318,10 @@ PRI delay_ms(Duration) DAT 'sys: helptext -help byte "/? : Hilfe",13 - byte "/s : Server-Adresse",13 - byte "/d : Download ",13 +help byte "/? : Hilfe",13 + byte "/s : Server-Adresse",13 + byte "/v : in entferntes Verzeichnis wechseln",13 + byte "/d : Download ",13 byte 0 DAT 'lizenz