Bugfixes in TFTPc (net branch)

git-svn-id: svn://kolibrios.org@2606 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-04-12 22:35:56 +00:00
parent 9fa539dadc
commit 4a382514dd

View File

@ -1,3 +1,5 @@
format binary as ""
use32 use32
org 0x0 org 0x0
@ -13,23 +15,23 @@ include '../proc32.inc'
include '../macros.inc' include '../macros.inc'
include '../libio.inc' include '../libio.inc'
include '../dll.inc' include '../dll.inc'
include 'editbox_ex.mac' include '../../../../../programs/develop/libraries/box_lib/trunk/box_lib.mac'
include '../network.inc' include '../network.inc'
filebuffer_size equ 4*4096 ; 16kb (dont try to change it yet..) filebuffer_size equ 4*4096 ; 16kb (dont try to change it yet..)
TIMEOUT equ 100 TIMEOUT equ 100
buffer_len equ 1500 buffer_len equ 1500
AF_INET4 equ 2 AF_INET4 equ 2
IP_PROTO_UDP equ 17 IP_PROTO_UDP equ 17
opcode_rrq equ 1 opcode_rrq equ 1
opcode_wrq equ 2 opcode_wrq equ 2
opcode_data equ 3 opcode_data equ 3
opcode_ack equ 4 opcode_ack equ 4
opcode_error equ 5 opcode_error equ 5
; read/write request packet ; read/write request packet
; ;
@ -62,142 +64,142 @@ opcode_error equ 5
START: START:
mcall 68, 11 mcall 68, 11
stdcall dll.Load, @IMPORT stdcall dll.Load, @IMPORT
or eax, eax or eax, eax
jnz exit jnz exit
stop_transfer: stop_transfer:
mcall 40, 00100111b mcall 40, 00100111b
red_win: red_win:
call draw_window call draw_window
align 4 align 4
still: still:
mcall 10 mcall 10
dec eax dec eax
jz red_win jz red_win
dec eax dec eax
jz key jz key
dec eax dec eax
jz button jz button
push dword edit1 push dword edit1
call [edit_box_mouse] call [edit_box_mouse]
push dword edit2 push dword edit2
call [edit_box_mouse] call [edit_box_mouse]
push dword edit3 push dword edit3
call [edit_box_mouse] call [edit_box_mouse]
push dword edit4 push dword edit4
call [edit_box_mouse] call [edit_box_mouse]
push dword Option_boxs1 push dword Option_boxs1
call [option_box_mouse] call [option_box_mouse]
push dword Option_boxs2 push dword Option_boxs2
call [option_box_mouse] call [option_box_mouse]
jmp still jmp still
button: button:
mcall 17 mcall 17
cmp ah,0x10 cmp ah,0x10
je start_transfer je start_transfer
test ah , ah test ah , ah
jz still jz still
exit: mcall -1 exit: mcall -1
key: key:
mcall 2 mcall 2
push dword edit1 push dword edit1
call [edit_box_key] call [edit_box_key]
push dword edit2 push dword edit2
call [edit_box_key] call [edit_box_key]
push dword edit3 push dword edit3
call [edit_box_key] call [edit_box_key]
push dword edit4 push dword edit4
call [edit_box_key] call [edit_box_key]
jmp still jmp still
align 4 align 4
draw_window: draw_window:
mcall 12,1 mcall 12,1
mcall 0,(50*65536+400),(30*65536+180),0x34AABBCC,0x085080DD,str_title mcall 0,(50*65536+400),(30*65536+180),0x34AABBCC,0x085080DD,str_title
mcall 4,35*65536+10,0x80000000, str_server mcall 4,35*65536+10,0x80000000, str_server
mov ebx,5*65536+ 30 mov ebx,5*65536+ 30
mov edx, str_source mov edx, str_source
mcall mcall
mov ebx,11*65536+ 50 mov ebx,11*65536+ 50
mov edx, str_destination mov edx, str_destination
mcall mcall
mov ebx,47*65536+72 mov ebx,47*65536+72
mov edx, str_mode mov edx, str_mode
mcall mcall
mov ebx,160*65536+72 mov ebx,160*65536+72
mov edx, str_method mov edx, str_method
mcall mcall
mov ebx,270*65536+72 mov ebx,270*65536+72
mov edx, str_blocksize mov edx, str_blocksize
mcall mcall
push dword edit1 push dword edit1
call [edit_box_draw] call [edit_box_draw]
push dword edit2 push dword edit2
call [edit_box_draw] call [edit_box_draw]
push dword edit3 push dword edit3
call [edit_box_draw] call [edit_box_draw]
push dword edit4 push dword edit4
call [edit_box_draw] call [edit_box_draw]
push dword Option_boxs1 push dword Option_boxs1
call [option_box_draw] call [option_box_draw]
push dword Option_boxs2 push dword Option_boxs2
call [option_box_draw] call [option_box_draw]
mcall 8,210*65536+170, 105*65536+16,0x00000010,0x085080DD mcall 8,210*65536+170, 105*65536+16,0x00000010,0x085080DD
mcall 4,260*65536+110, 0x80000000, str_transfer mcall 4,260*65536+110, 0x80000000, str_transfer
mcall 38,10*65536+380, 130*65536+130,0x00000000 mcall 38,10*65536+380, 130*65536+130,0x00000000
mcall 4,350*65536+137, 0x80000000, str_kb_s mcall 4,350*65536+137, 0x80000000, str_kb_s
mcall 47,1 shl 31 + 7 shl 16 + 1,kbps,305*65536+137,0x00000000 mcall 47,1 shl 31 + 7 shl 16 + 1,kbps,305*65536+137,0x00000000
mcall 4,50*65536+137, 0x80000000, str_complete mcall 4,50*65536+137, 0x80000000, str_complete
mcall 47,1 shl 31 + 3 shl 16 + 1,done,25*65536+137,0x00000000 mcall 47,1 shl 31 + 3 shl 16 + 1,done,25*65536+137,0x00000000
mcall 12,2 mcall 12,2
ret ret
@ -206,79 +208,79 @@ draw_window:
start_transfer: start_transfer:
; first, resolve the hostname ; first, resolve the hostname
push esp ; reserve stack place push esp ; reserve stack place
push esp ; fourth parameter push esp ; fourth parameter
push 0 ; third parameter push 0 ; third parameter
push 0 ; second parameter push 0 ; second parameter
push dword SRV ; first parameter push dword SRV ; first parameter
call [getaddrinfo] call [getaddrinfo]
pop esi pop esi
; test for error ; test for error
test eax, eax test eax, eax
jnz still jnz still
mov esi, [esi] mov esi, [esi]
mov esi, [esi + sockaddr_in.sin_addr] mov esi, [esi + sockaddr_in.sin_addr]
mov dword [IP], esi mov dword [IP], esi
mcall socket, AF_INET4, SOCK_DGRAM, 0 ; socket_open mcall socket, AF_INET4, SOCK_DGRAM, 0 ; socket_open
cmp eax, -1 cmp eax, -1
je still je still
mov [socketnum], eax mov [socketnum], eax
mcall connect, [socketnum], sockaddr, sockaddr_len ; socket_connect mcall connect, [socketnum], sockaddr, sockaddr_len ; socket_connect
cmp eax, -1 cmp eax, -1
je still je still
mov word [I_END], opcode_rrq mov word [I_END], opcode_rrq
cmp [option_group2],op3 cmp [option_group2],op3
je @f je @f
mov word [I_END], opcode_wrq mov word [I_END], opcode_wrq
@@: @@:
xor al , al xor al , al
mov edi, remote_addr mov edi, remote_addr
mov ecx, 250 mov ecx, 250
repnz scasb repnz scasb
sub edi, remote_addr-1 sub edi, remote_addr-1
mov ecx, edi mov ecx, edi
mov edi, I_END+2 mov edi, I_END+2
mov esi, remote_addr mov esi, remote_addr
rep movsb rep movsb
cmp [option_group1], op1 cmp [option_group1], op1
je .ascii je .ascii
mov esi, octet mov esi, octet
movsd movsd
movsb movsb
jmp .send_request jmp .send_request
.ascii: .ascii:
mov esi, netascii mov esi, netascii
movsd movsd
movsd movsd
.send_request: .send_request:
xor al, al xor al, al
stosb stosb
sub edi, I_END sub edi, I_END
mov esi, edi mov esi, edi
mcall send, [socketnum], I_END mcall send, [socketnum], I_END
mcall 40, 10000101b mcall 40, 10000101b
mov [last_ack], 0 mov [last_ack], 0
@ -287,27 +289,27 @@ start_transfer:
receive_data_loop: receive_data_loop:
mcall 23, TIMEOUT mcall 23, TIMEOUT
dec eax dec eax
jz .red jz .red
dec eax dec eax
jz .key jz .key
mcall recv, [socketnum], buffer, buffer_len, 0 ; receive data mcall recv, [socketnum], buffer, buffer_len, 0 ; receive data
cmp word[buffer], opcode_data cmp word[buffer], opcode_data
jne .error jne .error
mov bx, [last_ack] mov bx, [last_ack]
cmp word [buffer + 2], bx cmp word [buffer + 2], bx
jne .packet_got_lost jne .packet_got_lost
inc [last_ack] inc [last_ack]
cmp eax, 4+512 cmp eax, 4+512
je .continue je .continue
; last packet, or something else ; last packet, or something else
.error: .error:
@ -318,26 +320,26 @@ receive_data_loop:
.continue: .continue:
mov word[buffer], opcode_ack ; send ack mov word[buffer], opcode_ack ; send ack
mcall send, [socketnum], buffer, 4, 0 mcall send, [socketnum], buffer, 4, 0
jmp receive_data_loop jmp receive_data_loop
.red: .red:
call draw_window call draw_window
jmp receive_data_loop jmp receive_data_loop
.key: .key:
mcall 2 mcall 2
cmp ah, 2 cmp ah, 2
jz exit jz exit
; close socket ? ; close socket ?
jmp receive_data_loop jmp receive_data_loop
@ -349,93 +351,93 @@ receive_data_loop:
send_: send_:
invoke file_open, local_addr, O_READ invoke file_open, local_addr, O_READ
or eax, eax or eax, eax
jz .exit jz .exit
mov [fh], eax mov [fh], eax
stdcall mem.Alloc, filebuffer_size stdcall mem.Alloc, filebuffer_size
or eax, eax or eax, eax
jz .exit jz .exit
mov [fb], eax mov [fb], eax
mov [last_ack], 0 mov [last_ack], 0
mov [fo], 0 mov [fo], 0
.read_chunk: .read_chunk:
invoke file_seek, [fh], [fo], SEEK_END invoke file_seek, [fh], [fo], SEEK_END
cmp eax, -1 cmp eax, -1
je .exit je .exit
invoke file_read, [fh], [fb], filebuffer_size invoke file_read, [fh], [fb], filebuffer_size
cmp eax, -1 cmp eax, -1
je .exit je .exit
add [fo], filebuffer_size add [fo], filebuffer_size
cmp eax, filebuffer_size cmp eax, filebuffer_size
je .packet je .packet
; ijhidfhfdsndsfqk ; ijhidfhfdsndsfqk
.packet: .packet:
movzx esi, [last_ack] movzx esi, [last_ack]
and esi, 0x000000001f ; last five bits BUFFER SIZE MUST BE 16 kb for this to work !!! and esi, 0x000000001f ; last five bits BUFFER SIZE MUST BE 16 kb for this to work !!!
shl esi, 9 ; = * 512 shl esi, 9 ; = * 512
add esi, [fb] add esi, [fb]
mov edi, buffer mov edi, buffer
mov ax, opcode_data mov ax, opcode_data
stosw stosw
mov ax, [last_ack] mov ax, [last_ack]
stosw stosw
mov ecx, 512/4 mov ecx, 512/4
rep movsd rep movsd
mcall send, [socketnum], buffer, 4+512, 0 ; send data mcall send, [socketnum], buffer, 4+512, 0 ; send data
.loop: .loop:
mcall 23, TIMEOUT mcall 23, TIMEOUT
dec eax dec eax
jz .red jz .red
dec eax dec eax
jz .key jz .key
mcall recv, [socketnum], buffer, buffer_len, 0 ; receive ack mcall recv, [socketnum], buffer, buffer_len, 0 ; receive ack
cmp word[buffer], opcode_ack cmp word[buffer], opcode_ack
jne .exit jne .exit
mov ax, [last_ack] mov ax, [last_ack]
cmp word[buffer+2], ax cmp word[buffer+2], ax
jne .packet jne .packet
inc [last_ack] inc [last_ack]
test [last_ack],0x001f test [last_ack],0x001f
jz .read_chunk jz .read_chunk
jmp .packet jmp .packet
.red: .red:
call draw_window call draw_window
jmp .loop jmp .loop
.key: .key:
mcall 2 mcall 2
cmp ah, 2 cmp ah, 2
jz exit jz exit
; close socket ? ; close socket ?
jmp .loop jmp .loop
.exit: .exit:
invoke file_close, [fh] invoke file_close, [fh]
jmp still jmp still
@ -445,59 +447,59 @@ send_:
; DATA ; DATA
socketnum dd 0 socketnum dd 0
kbps dd 0 kbps dd 0
done dd 0 done dd 0
sockaddr: sockaddr:
dw AF_INET4 dw AF_INET4
dw 69 dw 69
IP db 192,168,1,115 IP db 192,168,1,115
sockaddr_len = $ - sockaddr sockaddr_len = $ - sockaddr
align 16 align 16
@IMPORT: @IMPORT:
library box_lib , 'box_lib.obj' library box_lib , 'box_lib.obj'
library io_lib , 'libio.obj' library io_lib , 'libio.obj'
library network , 'network.obj' library network , 'network.obj'
import box_lib ,\ import box_lib ,\
edit_box_draw ,'edit_box' ,\ edit_box_draw ,'edit_box' ,\
edit_box_key ,'edit_box_key' ,\ edit_box_key ,'edit_box_key' ,\
edit_box_mouse ,'edit_box_mouse' ,\ edit_box_mouse ,'edit_box_mouse' ,\
version_ed ,'version_ed' ,\ version_ed ,'version_ed' ,\
check_box_draw ,'check_box_draw' ,\ check_box_draw ,'check_box_draw' ,\
check_box_mouse ,'check_box_mouse' ,\ check_box_mouse ,'check_box_mouse' ,\
version_ch ,'version_ch' ,\ version_ch ,'version_ch' ,\
option_box_draw ,'option_box_draw' ,\ option_box_draw ,'option_box_draw' ,\
option_box_mouse ,'option_box_mouse' ,\ option_box_mouse ,'option_box_mouse' ,\
version_op ,'version_op' version_op ,'version_op'
import io_lib ,\ import io_lib ,\
file_find_first , 'file_find_first' ,\ file_find_first , 'file_find_first' ,\
file_find_next , 'file_find_next' ,\ file_find_next , 'file_find_next' ,\
file_find_close , 'file_find_close' ,\ file_find_close , 'file_find_close' ,\
file_size , 'file_size' ,\ file_size , 'file_size' ,\
file_open , 'file_open' ,\ file_open , 'file_open' ,\
file_read , 'file_read' ,\ file_read , 'file_read' ,\
file_write , 'file_write' ,\ file_write , 'file_write' ,\
file_seek , 'file_seek' ,\ file_seek , 'file_seek' ,\
file_tell , 'file_tell' ,\ file_tell , 'file_tell' ,\
file_eof? , 'file_iseof' ,\ file_eof? , 'file_iseof' ,\
file_seteof , 'file_seteof' ,\ file_seteof , 'file_seteof' ,\
file_truncate , 'file_truncate' ,\ file_truncate , 'file_truncate' ,\
file_close , 'file_close' file_close , 'file_close'
import network ,\ import network ,\
inet_ntoa , 'inet_ntoa' ,\ inet_ntoa , 'inet_ntoa' ,\
getaddrinfo , 'getaddrinfo' ,\ getaddrinfo , 'getaddrinfo' ,\
freeaddrinfo , 'freeaddrinfo' freeaddrinfo , 'freeaddrinfo'
edit1 edit_box 300,80,5 ,0xffffff,0x6f9480,0,0,0,99 ,SRV,ed_focus, 11,11 edit1 edit_box 300,80,5 ,0xffffff,0x6f9480,0,0,0,99 ,SRV,mouse_dd,ed_focus, 11,11
edit2 edit_box 300,80,25,0xffffff,0x6a9480,0,0,0,99 ,remote_addr,ed_figure_only, 10,10 edit2 edit_box 300,80,25,0xffffff,0x6a9480,0,0,0,99 ,remote_addr,mouse_dd,ed_figure_only, 10,10
edit3 edit_box 300,80,45,0xffffff,0x6a9480,0,0,0,99 ,local_addr,ed_figure_only, 27,27 edit3 edit_box 300,80,45,0xffffff,0x6a9480,0,0,0,99 ,local_addr,mouse_dd,ed_figure_only, 27,27
edit4 edit_box 40,340,68,0xffffff,0x6a9480,0,0,0,5 ,BLK,ed_figure_only, 3,3 edit4 edit_box 40,340,68,0xffffff,0x6a9480,0,0,0,5 ,BLK,mouse_dd,ed_figure_only, 3,3
op1 option_box option_group1,80,68,6,12,0xffffff,0,0,netascii,octet-netascii op1 option_box option_group1,80,68,6,12,0xffffff,0,0,netascii,octet-netascii
op2 option_box option_group1,80,85,6,12,0xFFFFFF,0,0,octet,get-octet op2 option_box option_group1,80,85,6,12,0xFFFFFF,0,0,octet,get-octet
@ -505,21 +507,21 @@ op2 option_box option_group1,80,85,6,12,0xFFFFFF,0,0,octet,get-octet
op3 option_box option_group2,210,68,6,12,0xffffff,0,0,get,put-get op3 option_box option_group2,210,68,6,12,0xffffff,0,0,get,put-get
op4 option_box option_group2,210,85,6,12,0xFFFFFF,0,0,put,BLK-put op4 option_box option_group2,210,85,6,12,0xFFFFFF,0,0,put,BLK-put
option_group1 dd op1 option_group1 dd op1
option_group2 dd op3 option_group2 dd op3
Option_boxs1 dd op1,op2,0 Option_boxs1 dd op1,op2,0
Option_boxs2 dd op3,op4,0 Option_boxs2 dd op3,op4,0
str_title db 'TFTP client for KolibriOS',0 str_title db 'TFTP client for KolibriOS',0
str_server db 'Server:',0 str_server db 'Server:',0
str_source db 'Remote file:',0 str_source db 'Remote file:',0
str_destination db 'Local file:',0 str_destination db 'Local file:',0
str_mode db 'Mode:',0 str_mode db 'Mode:',0
str_method db 'Method:',0 str_method db 'Method:',0
str_blocksize db 'Blocksize:',0 str_blocksize db 'Blocksize:',0
str_kb_s db 'kb/s',0 str_kb_s db 'kb/s',0
str_complete db '% complete',0 str_complete db '% complete',0
str_transfer db 'Transfer',0 str_transfer db 'Transfer',0
str_error: str_error:
._0 db 'Not defined, see error message (if any).',0 ._0 db 'Not defined, see error message (if any).',0
@ -533,17 +535,17 @@ str_error:
netascii db 'NetASCII' netascii db 'NetASCII'
octet db 'Octet' octet db 'Octet'
get db 'GET' get db 'GET'
put db 'PUT' put db 'PUT'
BLK db "512",0,0,0 BLK db "512",0,0,0
last_ack dw ? last_ack dw ?
fh dd ? ; file handle fh dd ? ; file handle
fo dd ? ; file offset fo dd ? ; file offset
fb dd ? ; file buffer fb dd ? ; file buffer
SRV db "192.168.1.115",0 SRV db "192.168.1.115",0
rb (SRV + 256 - $) rb (SRV + 256 - $)
@ -555,6 +557,7 @@ local_addr db "/hd0/1/KolibriOS/kernel.mnt",0
rb (local_addr + 256 - $) rb (local_addr + 256 - $)
I_END: I_END:
mouse_dd dd ?
buffer: buffer:
rb buffer_len rb buffer_len