Subversion Repositories Kolibri OS

Rev

Rev 2608 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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