Rev 1373 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1337 | hidnplayr | 1 | use32 |
1514 | hidnplayr | 2 | org 0x0 |
1337 | hidnplayr | 3 | |
1514 | hidnplayr | 4 | db 'MENUET01' |
5 | dd 0x1 |
||
6 | dd START |
||
7 | dd I_END |
||
8 | dd IM_END |
||
9 | dd IM_END |
||
10 | dd 0, 0 |
||
1337 | hidnplayr | 11 | |
12 | include '../proc32.inc' |
||
13 | include '../macros.inc' |
||
1514 | hidnplayr | 14 | include '../libio.inc' |
1337 | hidnplayr | 15 | include '../dll.inc' |
1514 | hidnplayr | 16 | include 'editbox_ex.mac' |
1337 | hidnplayr | 17 | |
18 | include '../network.inc' |
||
19 | |||
20 | |||
21 | filebuffer_size equ 4*4096 ; 16kb (dont try to change it yet..) |
||
1514 | hidnplayr | 22 | TIMEOUT equ 100 |
1337 | hidnplayr | 23 | buffer_len equ 1500 |
24 | |||
25 | AF_INET4 equ 2 |
||
26 | IP_PROTO_UDP equ 17 |
||
27 | |||
1514 | hidnplayr | 28 | opcode_rrq equ 1 |
29 | opcode_wrq equ 2 |
||
30 | opcode_data equ 3 |
||
31 | opcode_ack equ 4 |
||
32 | opcode_error equ 5 |
||
1337 | hidnplayr | 33 | |
34 | ; read/write request packet |
||
35 | ; |
||
36 | ; 2 bytes string 1 byte string 1 byte |
||
37 | ; ------------------------------------------------ |
||
38 | ; | Opcode | Filename | 0 | Mode | 0 | |
||
39 | ; ------------------------------------------------ |
||
40 | |||
41 | ; data packet |
||
42 | ; |
||
43 | ; 2 bytes 2 bytes n bytes |
||
44 | ; ---------------------------------- |
||
45 | ; | Opcode | Block # | Data | |
||
46 | ; ---------------------------------- |
||
47 | |||
48 | ; acknowledgement packet |
||
49 | ; |
||
50 | ; 2 bytes 2 bytes |
||
51 | ; --------------------- |
||
52 | ; | Opcode | Block # | |
||
53 | ; --------------------- |
||
54 | |||
55 | ; error packet |
||
56 | ; |
||
57 | ; 2 bytes 2 bytes string 1 byte |
||
1514 | hidnplayr | 58 | ; ---------------------------------------- |
1337 | hidnplayr | 59 | ; | Opcode | ErrorCode | ErrMsg | 0 | |
1514 | hidnplayr | 60 | ; ---------------------------------------- |
1337 | hidnplayr | 61 | |
62 | |||
63 | START: |
||
64 | |||
1514 | hidnplayr | 65 | mcall 68, 11 |
1337 | hidnplayr | 66 | |
67 | stdcall dll.Load, @IMPORT |
||
68 | or eax, eax |
||
69 | jnz exit |
||
70 | |||
71 | stop_transfer: |
||
72 | mcall 40, 00100111b |
||
73 | |||
74 | red_win: |
||
75 | call draw_window |
||
76 | |||
77 | align 4 |
||
78 | still: |
||
79 | mcall 10 |
||
80 | |||
81 | dec eax |
||
82 | jz red_win |
||
83 | |||
84 | dec eax |
||
85 | jz key |
||
86 | |||
87 | dec eax |
||
88 | jz button |
||
89 | |||
90 | push dword edit1 |
||
91 | call [edit_box_mouse] |
||
92 | |||
93 | push dword edit2 |
||
94 | call [edit_box_mouse] |
||
95 | |||
96 | push dword edit3 |
||
97 | call [edit_box_mouse] |
||
98 | |||
99 | push dword edit4 |
||
100 | call [edit_box_mouse] |
||
101 | |||
102 | push dword Option_boxs1 |
||
103 | call [option_box_mouse] |
||
104 | |||
105 | push dword Option_boxs2 |
||
106 | call [option_box_mouse] |
||
107 | |||
108 | jmp still |
||
109 | |||
110 | button: |
||
111 | mcall 17 |
||
112 | |||
113 | cmp ah,0x10 |
||
114 | je start_transfer |
||
115 | |||
116 | |||
117 | test ah , ah |
||
118 | jz still |
||
119 | |||
120 | exit: mcall -1 |
||
121 | key: |
||
122 | mcall 2 |
||
123 | |||
124 | push dword edit1 |
||
125 | call [edit_box_key] |
||
126 | |||
127 | push dword edit2 |
||
128 | call [edit_box_key] |
||
129 | |||
130 | push dword edit3 |
||
131 | call [edit_box_key] |
||
132 | |||
133 | push dword edit4 |
||
134 | call [edit_box_key] |
||
135 | |||
136 | jmp still |
||
137 | |||
138 | |||
139 | align 4 |
||
140 | draw_window: |
||
141 | mcall 12,1 |
||
142 | mcall 0,(50*65536+400),(30*65536+180),0x34AABBCC,0x085080DD,str_title |
||
143 | |||
144 | mcall 4,35*65536+10,0x80000000, str_server |
||
145 | |||
146 | mov ebx,5*65536+ 30 |
||
147 | mov edx, str_source |
||
148 | mcall |
||
149 | |||
150 | mov ebx,11*65536+ 50 |
||
151 | mov edx, str_destination |
||
152 | mcall |
||
153 | |||
154 | mov ebx,47*65536+72 |
||
155 | mov edx, str_mode |
||
156 | mcall |
||
157 | |||
158 | mov ebx,160*65536+72 |
||
159 | mov edx, str_method |
||
160 | mcall |
||
161 | |||
162 | mov ebx,270*65536+72 |
||
163 | mov edx, str_blocksize |
||
164 | mcall |
||
165 | |||
166 | push dword edit1 |
||
167 | call [edit_box_draw] |
||
168 | |||
169 | push dword edit2 |
||
170 | call [edit_box_draw] |
||
171 | |||
172 | push dword edit3 |
||
173 | call [edit_box_draw] |
||
174 | |||
175 | push dword edit4 |
||
176 | call [edit_box_draw] |
||
177 | |||
178 | push dword Option_boxs1 |
||
179 | call [option_box_draw] |
||
180 | |||
181 | push dword Option_boxs2 |
||
182 | call [option_box_draw] |
||
183 | |||
184 | mcall 8,210*65536+170, 105*65536+16,0x00000010,0x085080DD |
||
185 | |||
186 | mcall 4,260*65536+110, 0x80000000, str_transfer |
||
187 | |||
188 | mcall 38,10*65536+380, 130*65536+130,0x00000000 |
||
189 | |||
190 | mcall 4,350*65536+137, 0x80000000, str_kb_s |
||
191 | |||
1514 | hidnplayr | 192 | mcall 47,1 shl 31 + 7 shl 16 + 1,kbps,305*65536+137,0x00000000 |
1337 | hidnplayr | 193 | |
1514 | hidnplayr | 194 | mcall 4,50*65536+137, 0x80000000, str_complete |
1337 | hidnplayr | 195 | |
1514 | hidnplayr | 196 | mcall 47,1 shl 31 + 3 shl 16 + 1,done,25*65536+137,0x00000000 |
1337 | hidnplayr | 197 | |
198 | mcall 12,2 |
||
199 | |||
200 | ret |
||
201 | |||
202 | |||
203 | |||
204 | |||
205 | |||
206 | |||
207 | start_transfer: |
||
208 | |||
209 | ; first, resolve the hostname |
||
210 | |||
211 | push esp ; reserve stack place |
||
212 | |||
213 | push esp ; fourth parameter |
||
214 | push 0 ; third parameter |
||
215 | push 0 ; second parameter |
||
1514 | hidnplayr | 216 | push dword SRV ; first parameter |
1337 | hidnplayr | 217 | call [getaddrinfo] |
218 | |||
1514 | hidnplayr | 219 | pop esi |
1337 | hidnplayr | 220 | |
221 | ; test for error |
||
222 | test eax, eax |
||
223 | jnz still |
||
224 | |||
1514 | hidnplayr | 225 | mov esi, [esi] |
1337 | hidnplayr | 226 | mov esi, [esi + sockaddr_in.sin_addr] |
227 | mov dword [IP], esi |
||
228 | |||
1514 | hidnplayr | 229 | mcall socket, AF_INET4, IP_PROTO_UDP, 0 ; socket_open |
1337 | hidnplayr | 230 | cmp eax, -1 |
231 | je still |
||
232 | |||
233 | mov [socketnum], eax |
||
234 | |||
1514 | hidnplayr | 235 | mcall connect, [socketnum], sockaddr, sockaddr_len ; socket_connect |
1337 | hidnplayr | 236 | cmp eax, -1 |
237 | je still |
||
238 | |||
239 | mov word [I_END], opcode_rrq |
||
1514 | hidnplayr | 240 | cmp [option_group2],op3 |
241 | je @f |
||
1337 | hidnplayr | 242 | mov word [I_END], opcode_wrq |
1514 | hidnplayr | 243 | @@: |
1337 | hidnplayr | 244 | |
245 | xor al , al |
||
246 | mov edi, remote_addr |
||
247 | mov ecx, 250 |
||
248 | repnz scasb |
||
1514 | hidnplayr | 249 | sub edi, remote_addr-1 |
1337 | hidnplayr | 250 | mov ecx, edi |
251 | mov edi, I_END+2 |
||
252 | mov esi, remote_addr |
||
253 | rep movsb |
||
254 | |||
255 | cmp [option_group1], op1 |
||
256 | je .ascii |
||
257 | |||
258 | mov esi, octet |
||
259 | movsd |
||
260 | movsb |
||
261 | |||
262 | jmp .send_request |
||
263 | |||
264 | .ascii: |
||
265 | |||
266 | mov esi, netascii |
||
267 | movsd |
||
268 | movsd |
||
269 | |||
270 | .send_request: |
||
271 | |||
272 | xor al, al |
||
273 | stosb |
||
274 | |||
275 | sub edi, I_END |
||
276 | mov esi, edi |
||
277 | mcall send, [socketnum], I_END |
||
278 | |||
1514 | hidnplayr | 279 | mcall 40, 10000101b |
280 | |||
1337 | hidnplayr | 281 | mov [last_ack], 0 |
282 | |||
283 | |||
284 | |||
285 | |||
286 | |||
287 | |||
288 | receive_data_loop: |
||
289 | |||
290 | mcall 23, TIMEOUT |
||
291 | |||
292 | dec eax |
||
1514 | hidnplayr | 293 | jz .red |
1337 | hidnplayr | 294 | |
295 | dec eax |
||
1514 | hidnplayr | 296 | jz .key |
1337 | hidnplayr | 297 | |
298 | |||
1514 | hidnplayr | 299 | mcall recv, [socketnum], buffer, buffer_len, 0 ; receive data |
300 | |||
301 | cmp word[buffer], opcode_data |
||
1337 | hidnplayr | 302 | jne .error |
303 | |||
304 | mov bx, [last_ack] |
||
1514 | hidnplayr | 305 | cmp word [buffer + 2], bx |
1337 | hidnplayr | 306 | jne .packet_got_lost |
307 | inc [last_ack] |
||
308 | |||
1514 | hidnplayr | 309 | cmp eax, 4+512 |
310 | je .continue |
||
1337 | hidnplayr | 311 | |
1514 | hidnplayr | 312 | ; last packet, or something else |
313 | .error: |
||
1337 | hidnplayr | 314 | |
1514 | hidnplayr | 315 | .packet_got_lost: |
1337 | hidnplayr | 316 | |
317 | |||
318 | |||
1514 | hidnplayr | 319 | .continue: |
1337 | hidnplayr | 320 | |
1514 | hidnplayr | 321 | mov word[buffer], opcode_ack ; send ack |
322 | mcall send, [socketnum], buffer, 4, 0 |
||
1337 | hidnplayr | 323 | |
1514 | hidnplayr | 324 | jmp receive_data_loop |
1337 | hidnplayr | 325 | |
1514 | hidnplayr | 326 | .red: |
1337 | hidnplayr | 327 | |
1514 | hidnplayr | 328 | call draw_window |
1337 | hidnplayr | 329 | |
1514 | hidnplayr | 330 | jmp receive_data_loop |
1337 | hidnplayr | 331 | |
332 | |||
1514 | hidnplayr | 333 | .key: |
334 | mcall 2 |
||
335 | cmp ah, 2 |
||
336 | jz exit |
||
1337 | hidnplayr | 337 | |
1514 | hidnplayr | 338 | ; close socket ? |
1337 | hidnplayr | 339 | |
340 | jmp receive_data_loop |
||
341 | |||
342 | |||
343 | |||
344 | |||
345 | |||
346 | |||
1514 | hidnplayr | 347 | ;-------------------------------- |
1337 | hidnplayr | 348 | |
349 | |||
1514 | hidnplayr | 350 | send_: |
1337 | hidnplayr | 351 | |
1514 | hidnplayr | 352 | invoke file_open, local_addr, O_READ |
353 | or eax, eax |
||
354 | jz .exit |
||
355 | mov [fh], eax |
||
1337 | hidnplayr | 356 | |
1514 | hidnplayr | 357 | stdcall mem.Alloc, filebuffer_size |
358 | or eax, eax |
||
359 | jz .exit |
||
360 | mov [fb], eax |
||
1337 | hidnplayr | 361 | |
1514 | hidnplayr | 362 | mov [last_ack], 0 |
363 | mov [fo], 0 |
||
1337 | hidnplayr | 364 | |
1514 | hidnplayr | 365 | .read_chunk: |
1337 | hidnplayr | 366 | |
1514 | hidnplayr | 367 | invoke file_seek, [fh], [fo], SEEK_END |
368 | cmp eax, -1 |
||
369 | je .exit |
||
370 | invoke file_read, [fh], [fb], filebuffer_size |
||
371 | cmp eax, -1 |
||
372 | je .exit |
||
373 | add [fo], filebuffer_size |
||
374 | cmp eax, filebuffer_size |
||
375 | je .packet |
||
1337 | hidnplayr | 376 | |
1514 | hidnplayr | 377 | ; ijhidfhfdsndsfqk |
1337 | hidnplayr | 378 | |
1514 | hidnplayr | 379 | .packet: |
1337 | hidnplayr | 380 | |
1514 | hidnplayr | 381 | movzx esi, [last_ack] |
382 | and esi, 0x000000001f ; last five bits BUFFER SIZE MUST BE 16 kb for this to work !!! |
||
383 | shl esi, 9 ; = * 512 |
||
384 | add esi, [fb] |
||
385 | mov edi, buffer |
||
386 | mov ax, opcode_data |
||
387 | stosw |
||
1337 | hidnplayr | 388 | mov ax, [last_ack] |
1514 | hidnplayr | 389 | stosw |
390 | mov ecx, 512/4 |
||
391 | rep movsd |
||
1337 | hidnplayr | 392 | |
1514 | hidnplayr | 393 | mcall send, [socketnum], buffer, 4+512, 0 ; send data |
1337 | hidnplayr | 394 | |
395 | |||
1514 | hidnplayr | 396 | .loop: |
1337 | hidnplayr | 397 | |
398 | mcall 23, TIMEOUT |
||
399 | |||
400 | dec eax |
||
401 | jz .red |
||
402 | |||
403 | dec eax |
||
1514 | hidnplayr | 404 | jz .key |
1337 | hidnplayr | 405 | |
1514 | hidnplayr | 406 | mcall recv, [socketnum], buffer, buffer_len, 0 ; receive ack |
1337 | hidnplayr | 407 | |
1514 | hidnplayr | 408 | cmp word[buffer], opcode_ack |
409 | jne .exit |
||
1337 | hidnplayr | 410 | |
411 | mov ax, [last_ack] |
||
1514 | hidnplayr | 412 | cmp word[buffer+2], ax |
413 | jne .packet |
||
414 | inc [last_ack] |
||
415 | test [last_ack],0x001f |
||
416 | jz .read_chunk |
||
417 | jmp .packet |
||
1337 | hidnplayr | 418 | |
419 | |||
1514 | hidnplayr | 420 | .red: |
1337 | hidnplayr | 421 | |
1514 | hidnplayr | 422 | call draw_window |
1337 | hidnplayr | 423 | |
424 | jmp .loop |
||
425 | |||
426 | |||
1514 | hidnplayr | 427 | .key: |
428 | mcall 2 |
||
429 | cmp ah, 2 |
||
430 | jz exit |
||
1337 | hidnplayr | 431 | |
1514 | hidnplayr | 432 | ; close socket ? |
1337 | hidnplayr | 433 | |
1514 | hidnplayr | 434 | jmp .loop |
435 | |||
436 | .exit: |
||
1337 | hidnplayr | 437 | invoke file_close, [fh] |
1514 | hidnplayr | 438 | jmp still |
1337 | hidnplayr | 439 | |
440 | |||
441 | |||
442 | |||
443 | |||
444 | ;------------------------- |
||
445 | ; DATA |
||
446 | |||
447 | socketnum dd 0 |
||
448 | kbps dd 0 |
||
449 | done dd 0 |
||
450 | |||
451 | sockaddr: |
||
452 | dw AF_INET4 |
||
1514 | hidnplayr | 453 | dw 69 |
1337 | hidnplayr | 454 | IP db 192,168,1,115 |
455 | sockaddr_len = $ - sockaddr |
||
456 | |||
457 | align 16 |
||
458 | @IMPORT: |
||
459 | |||
1514 | hidnplayr | 460 | library box_lib , 'box_lib.obj' |
461 | library io_lib , 'libio.obj' |
||
462 | library network , 'network.obj' |
||
1337 | hidnplayr | 463 | |
464 | import box_lib ,\ |
||
465 | edit_box_draw ,'edit_box' ,\ |
||
466 | edit_box_key ,'edit_box_key' ,\ |
||
467 | edit_box_mouse ,'edit_box_mouse' ,\ |
||
468 | version_ed ,'version_ed' ,\ |
||
469 | check_box_draw ,'check_box_draw' ,\ |
||
470 | check_box_mouse ,'check_box_mouse' ,\ |
||
471 | version_ch ,'version_ch' ,\ |
||
472 | option_box_draw ,'option_box_draw' ,\ |
||
473 | option_box_mouse ,'option_box_mouse' ,\ |
||
474 | version_op ,'version_op' |
||
475 | |||
476 | import io_lib ,\ |
||
477 | file_find_first , 'file_find_first' ,\ |
||
478 | file_find_next , 'file_find_next' ,\ |
||
479 | file_find_close , 'file_find_close' ,\ |
||
480 | file_size , 'file_size' ,\ |
||
481 | file_open , 'file_open' ,\ |
||
482 | file_read , 'file_read' ,\ |
||
483 | file_write , 'file_write' ,\ |
||
484 | file_seek , 'file_seek' ,\ |
||
485 | file_tell , 'file_tell' ,\ |
||
486 | file_eof? , 'file_iseof' ,\ |
||
487 | file_seteof , 'file_seteof' ,\ |
||
488 | file_truncate , 'file_truncate' ,\ |
||
489 | file_close , 'file_close' |
||
490 | |||
1514 | hidnplayr | 491 | import network ,\ |
492 | inet_ntoa , 'inet_ntoa' ,\ |
||
493 | getaddrinfo , 'getaddrinfo' ,\ |
||
494 | freeaddrinfo , 'freeaddrinfo' |
||
1337 | hidnplayr | 495 | |
496 | |||
1514 | hidnplayr | 497 | edit1 edit_box 300,80,5 ,0xffffff,0x6f9480,0,0,0,99 ,SRV,ed_focus, 11,11 |
498 | edit2 edit_box 300,80,25,0xffffff,0x6a9480,0,0,0,99 ,remote_addr,ed_figure_only, 10,10 |
||
499 | edit3 edit_box 300,80,45,0xffffff,0x6a9480,0,0,0,99 ,local_addr,ed_figure_only, 27,27 |
||
500 | edit4 edit_box 40,340,68,0xffffff,0x6a9480,0,0,0,5 ,BLK,ed_figure_only, 3,3 |
||
1337 | hidnplayr | 501 | |
502 | op1 option_box option_group1,80,68,6,12,0xffffff,0,0,netascii,octet-netascii |
||
503 | op2 option_box option_group1,80,85,6,12,0xFFFFFF,0,0,octet,get-octet |
||
504 | |||
505 | op3 option_box option_group2,210,68,6,12,0xffffff,0,0,get,put-get |
||
506 | op4 option_box option_group2,210,85,6,12,0xFFFFFF,0,0,put,BLK-put |
||
507 | |||
508 | option_group1 dd op1 |
||
509 | option_group2 dd op3 |
||
510 | Option_boxs1 dd op1,op2,0 |
||
511 | Option_boxs2 dd op3,op4,0 |
||
512 | |||
513 | str_title db 'TFTP client for KolibriOS',0 |
||
514 | str_server db 'Server:',0 |
||
515 | str_source db 'Remote file:',0 |
||
516 | str_destination db 'Local file:',0 |
||
517 | str_mode db 'Mode:',0 |
||
518 | str_method db 'Method:',0 |
||
519 | str_blocksize db 'Blocksize:',0 |
||
520 | str_kb_s db 'kb/s',0 |
||
521 | str_complete db '% complete',0 |
||
522 | str_transfer db 'Transfer',0 |
||
523 | |||
524 | str_error: |
||
525 | ._0 db 'Not defined, see error message (if any).',0 |
||
526 | ._1 db 'File not found.',0 |
||
527 | ._2 db 'Access violation.',0 |
||
528 | ._3 db 'Disk full or allocation exceeded.',0 |
||
529 | ._4 db 'Illegal TFTP operation.',0 |
||
530 | ._5 db 'Unknown transfer ID.',0 |
||
531 | ._6 db 'File already exists.',0 |
||
532 | ._7 db 'No such user.',0 |
||
533 | |||
534 | |||
535 | netascii db 'NetASCII' |
||
536 | octet db 'Octet' |
||
537 | get db 'GET' |
||
538 | put db 'PUT' |
||
539 | |||
540 | BLK db "512",0,0,0 |
||
541 | |||
542 | last_ack dw ? |
||
543 | |||
544 | fh dd ? ; file handle |
||
1514 | hidnplayr | 545 | fo dd ? ; file offset |
546 | fb dd ? ; file buffer |
||
1337 | hidnplayr | 547 | |
548 | SRV db "192.168.1.115",0 |
||
1514 | hidnplayr | 549 | rb (SRV + 256 - $) |
1337 | hidnplayr | 550 | |
1514 | hidnplayr | 551 | remote_addr db "IMG00",0 |
552 | rb (remote_addr + 256 - $) |
||
1337 | hidnplayr | 553 | |
1514 | hidnplayr | 554 | local_addr db "/hd0/1/KolibriOS/kernel.mnt",0 |
555 | rb (local_addr + 256 - $) |
||
1337 | hidnplayr | 556 | |
557 | I_END: |
||
558 | buffer: |
||
559 | rb buffer_len |
||
560 | |||
561 | IM_END: |