Subversion Repositories Kolibri OS

Rev

Rev 5984 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5984 Rev 6078
Line 19... Line 19...
19
;;          GNU GENERAL PUBLIC LICENSE                             ;;
19
;;          GNU GENERAL PUBLIC LICENSE                             ;;
20
;;             Version 2, June 1991                                ;;
20
;;             Version 2, June 1991                                ;;
21
;;                                                                 ;;
21
;;                                                                 ;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 23... Line 23...
23
 
23
 
Line 24... Line 24...
24
$Revision: 5984 $
24
$Revision: 6078 $
25
 
25
 
26
uglobal
26
uglobal
27
        net_10ms        dd ?
27
        net_10ms        dd ?
Line 256... Line 256...
256
        .current        dd ?
256
        .current        dd ?
Line 257... Line 257...
257
 
257
 
Line 258... Line 258...
258
endg
258
endg
259
 
-
 
-
 
259
 
260
 
260
 
261
;-----------------------------------------------------------------
-
 
262
;
261
;-----------------------------------------------------------------;
263
; stack_init
-
 
264
;
262
;                                                                 ;
265
;  This function calls all network init procedures
263
; stack_init: Initialize all network variables                    ;
266
;
-
 
-
 
264
;                                                                 ;
267
;  IN:  /
265
;  IN:  /                                                         ;
268
;  OUT: /
266
;  OUT: /                                                         ;
269
;
267
;                                                                 ;
Line 270... Line 268...
270
;-----------------------------------------------------------------
268
;-----------------------------------------------------------------;
271
align 4
269
align 4
Line 292... Line 290...
292
        xor     eax, eax
290
        xor     eax, eax
293
        mov     edi, NET_RUNNING
291
        mov     edi, NET_RUNNING
294
        mov     ecx, (NET_DEVICES_MAX + 1)
292
        mov     ecx, (NET_DEVICES_MAX + 1)
295
        rep stosd
293
        rep stosd
Line 296... Line 294...
296
 
294
 
Line 297... Line 295...
297
        ETH_init
295
        eth_init
Line 298... Line 296...
298
 
296
 
299
        PPPoE_init
297
        pppoe_init
300
 
298
 
Line 301... Line 299...
301
        IPv4_init
299
        ipv4_init
302
;        IPv6_init
300
;        ipv6_init
303
        ICMP_init
301
        icmp_init
Line 304... Line 302...
304
 
302
 
Line 305... Line 303...
305
        ARP_init
303
        arp_init
Line 306... Line 304...
306
        UDP_init
304
        udp_init
307
        TCP_init
305
        tcp_init
Line 308... Line 306...
308
 
306
 
Line 327... Line 325...
327
 
325
 
328
        ret
326
        ret
Line 329... Line 327...
329
endp
327
endp
330
 
-
 
-
 
328
 
331
 
329
 
332
;-----------------------------------------------------------------
-
 
333
;
330
;-----------------------------------------------------------------;
334
; stack_handler
-
 
335
;
331
;                                                                 ;
336
;  This function is called in kernel loop
332
; stack_handler: Network handlers called from os_loop.            ;
337
;
-
 
-
 
333
;                                                                 ;
338
;  IN:  /
334
;  IN:  /                                                         ;
339
;  OUT: /
335
;  OUT: /                                                         ;
340
;
336
;                                                                 ;
Line 341... Line 337...
341
;-----------------------------------------------------------------
337
;-----------------------------------------------------------------;
342
align 4
338
align 4
Line 352... Line 348...
352
        je      .exit
348
        je      .exit
Line 353... Line 349...
353
 
349
 
354
        test    [net_10ms], 0x0f        ; 160ms
350
        test    [net_10ms], 0x0f        ; 160ms
Line 355... Line 351...
355
        jnz     .exit
351
        jnz     .exit
Line 356... Line 352...
356
 
352
 
357
        TCP_timer_160ms
353
        tcp_timer_160ms
Line 358... Line 354...
358
 
354
 
359
        test    [net_10ms], 0x3f        ; 640ms
355
        test    [net_10ms], 0x3f        ; 640ms
Line 360... Line 356...
360
        jnz     .exit
356
        jnz     .exit
361
 
357
 
362
        ARP_decrease_entry_ttls
358
        arp_decrease_entry_ttls
363
        IPv4_decrease_fragment_ttls
359
        ipv4_decrease_fragment_ttls
Line 371... Line 367...
371
  .exit:
367
  .exit:
372
        ret
368
        ret
Line 373... Line 369...
373
 
369
 
374
 
370
 
-
 
371
align 4
375
align 4
372
proc net_buff_alloc stdcall, buffersize
376
proc NET_BUFF_alloc stdcall, buffersize
373
 
Line 377... Line 374...
377
        cmp     [buffersize], NET_BUFFER_SIZE
374
        cmp     [buffersize], NET_BUFFER_SIZE
Line 385... Line 382...
385
        mov     eax, [eax]
382
        mov     eax, [eax]
386
        add     [NET_BUFFS_FREE.current], 4
383
        add     [NET_BUFFS_FREE.current], 4
Line 387... Line 384...
387
 
384
 
Line 388... Line 385...
388
        spin_unlock_irqrestore
385
        spin_unlock_irqrestore
389
 
386
 
Line 390... Line 387...
390
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net alloc: 0x%x\n", eax
387
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net_buff_alloc: 0x%x\n", eax
391
        ret
388
        ret
Line 392... Line 389...
392
 
389
 
393
  .out_of_mem:
390
  .out_of_mem:
394
        spin_unlock_irqrestore
391
        spin_unlock_irqrestore
Line 395... Line 392...
395
 
392
 
396
        xor     eax, eax
393
        xor     eax, eax
397
        DEBUGF  DEBUG_NETWORK_ERROR, "NET_BUFF_alloc: out of mem!\n"
394
        DEBUGF  DEBUG_NETWORK_ERROR, "net_buff_alloc: out of mem!\n"
398
        ret
395
        ret
399
 
396
 
Line 400... Line 397...
400
  .too_large:
397
  .too_large:
401
        xor     eax, eax
398
        xor     eax, eax
Line 402... Line 399...
402
        DEBUGF  DEBUG_NETWORK_ERROR, "NET_BUFF_alloc: too large!\n"
399
        DEBUGF  DEBUG_NETWORK_ERROR, "net_buff_alloc: too large!\n"
Line 403... Line 400...
403
        ret
400
        ret
Line 404... Line 401...
404
endp
401
endp
405
 
402
 
Line 421... Line 418...
421
        ret
418
        ret
422
endp
419
endp
Line 423... Line 420...
423
 
420
 
424
 
421
 
Line 425... Line 422...
425
align 4
422
align 4
Line 426... Line 423...
426
NET_link_changed:
423
net_link_changed:
427
 
424
 
Line 428... Line 425...
428
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.link_state]
425
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.link_state]
Line 429... Line 426...
429
 
426
 
430
align 4
427
align 4
431
NET_send_event:
428
net_send_event:
432
 
429
 
Line 444... Line 441...
444
 
441
 
Line 445... Line 442...
445
        ret
442
        ret
446
 
-
 
447
 
443
 
448
 
-
 
449
;-----------------------------------------------------------------
444
 
450
;
445
 
451
; NET_add_device:
-
 
452
;
446
;-----------------------------------------------------------------;
-
 
447
;                                                                 ;
453
;  This function is called by the network drivers,
448
; net_add_device: Called by network driver to register interface. ;
454
;  to register each running NIC to the kernel
-
 
-
 
449
;                                                                 ;
-
 
450
;  IN:  ebx = ptr to device structure                             ;
455
;
451
;                                                                 ;
456
;  IN:  Pointer to device structure in ebx
452
;  OUT: eax = device num on success                               ;
457
;  OUT: Device num in eax, -1 on error
453
;       eax = -1 on error                                         ;
Line 458... Line 454...
458
;
454
;                                                                 ;
Line 459... Line 455...
459
;-----------------------------------------------------------------
455
;-----------------------------------------------------------------;
460
align 4
456
align 4
Line 461... Line 457...
461
NET_add_device:
457
net_add_device:
Line 493... Line 489...
493
        sub     eax, NET_DRV_LIST
489
        sub     eax, NET_DRV_LIST
494
        shr     eax, 2
490
        shr     eax, 2
Line 495... Line 491...
495
 
491
 
Line 496... Line 492...
496
        inc     [NET_RUNNING]           ; Indicate that one more network device is up and running
492
        inc     [NET_RUNNING]           ; Indicate that one more network device is up and running
Line 497... Line 493...
497
 
493
 
498
        call    NET_send_event
494
        call    net_send_event
Line 499... Line 495...
499
 
495
 
Line 505... Line 501...
505
        DEBUGF  DEBUG_NETWORK_ERROR, "Adding network device failed\n"
501
        DEBUGF  DEBUG_NETWORK_ERROR, "Adding network device failed\n"
506
        ret
502
        ret
Line 507... Line 503...
507
 
503
 
508
 
-
 
509
 
504
 
510
;-----------------------------------------------------------------
-
 
511
;
505
 
512
; NET_Remove_Device:
506
;-----------------------------------------------------------------;
513
;
-
 
514
;  This function is called by network drivers,
507
;                                                                 ;
-
 
508
; net_remove_device: Called by network driver to unregister dev.  ;
515
;  to unregister network devices from the kernel
509
;                                                                 ;
516
;
-
 
-
 
510
;  IN:  ebx = ptr to device                                       ;
517
;  IN:  Pointer to device structure in ebx
511
;                                                                 ;
518
;  OUT: eax: -1 on error
512
;  OUT: eax: -1 on error                                          ;
519
;
513
;                                                                 ;
Line 520... Line 514...
520
;-----------------------------------------------------------------
514
;-----------------------------------------------------------------;
521
align 4
515
align 4
Line 522... Line 516...
522
NET_remove_device:
516
net_remove_device:
Line 539... Line 533...
539
 
533
 
540
        xor     eax, eax
534
        xor     eax, eax
541
        mov     dword [edi-4], eax
535
        mov     dword [edi-4], eax
Line 542... Line 536...
542
        dec     [NET_RUNNING]
536
        dec     [NET_RUNNING]
Line 543... Line 537...
543
 
537
 
544
        call    NET_send_event
538
        call    net_send_event
Line 545... Line 539...
545
 
539
 
546
        xor     eax, eax
540
        xor     eax, eax
547
        ret
541
        ret
Line 548... Line 542...
548
 
542
 
549
  .error:
-
 
-
 
543
  .error:
550
        or      eax, -1
544
        or      eax, -1
551
        ret
-
 
-
 
545
        ret
552
 
546
 
-
 
547
 
-
 
548
 
553
 
549
;-----------------------------------------------------------------;
554
 
-
 
-
 
550
;                                                                 ;
555
;-----------------------------------------------------------------
551
; net_ptr_to_num                                                  ;
556
;
552
;                                                                 ;
557
; NET_ptr_to_num
553
;  IN:  ebx = ptr to device struct                                ;
Line 558... Line 554...
558
;
554
;                                                                 ;
559
; IN:  ebx = ptr to device struct
555
;  OUT: edi = device number                                       ;
560
; OUT: edi = -1 on error, device number otherwise
556
;       edi = -1 on error                                         ;
Line 561... Line 557...
561
;
557
;                                                                 ;
Line 562... Line 558...
562
;-----------------------------------------------------------------
558
;-----------------------------------------------------------------;
563
align 4
559
align 4
Line 564... Line 560...
564
NET_ptr_to_num:
560
net_ptr_to_num:
565
 
561
 
Line 566... Line 562...
566
        call    NET_ptr_to_num4
562
        call    net_ptr_to_num4
Line 593... Line 589...
593
  .found:
589
  .found:
594
        sub     edi, NET_DRV_LIST
590
        sub     edi, NET_DRV_LIST
595
        pop     ecx
591
        pop     ecx
596
        ret
592
        ret
Line 597... Line 593...
597
 
593
 
598
;-----------------------------------------------------------------
-
 
-
 
594
;-----------------------------------------------------------------;
599
;
595
;                                                                 ;
600
; checksum_1
-
 
601
;
596
; checksum_1: Calculate semi-checksum for network packets.        ;
602
;  This is the first of two functions needed to calculate a checksum.
-
 
603
;
597
;                                                                 ;
604
;  IN:  edx = start offset for semi-checksum
598
;  IN:  edx = start offset for semi-checksum                      ;
605
;       esi = pointer to data
599
;       esi = pointer to data                                     ;
-
 
600
;       ecx = data size                                           ;
606
;       ecx = data size
601
;                                                                 ;
607
;  OUT: edx = semi-checksum
-
 
608
;
-
 
609
;
602
;  OUT: edx = semi-checksum                                       ;
610
; Code was optimized by diamond
-
 
611
;
603
;                                                                 ;
612
;-----------------------------------------------------------------
604
;-----------------------------------------------------------------;
613
align 4
605
align 4
Line 614... Line 606...
614
checksum_1:
606
checksum_1:
615
 
607
 
Line 677... Line 669...
677
        add     dh, [esi+0]
669
        add     dh, [esi+0]
678
        adc     edx, 0
670
        adc     edx, 0
679
  .end:
671
  .end:
680
        ret
672
        ret
Line 681... Line 673...
681
 
673
 
682
;-----------------------------------------------------------------
-
 
683
;
674
;-----------------------------------------------------------------;
684
; checksum_2
-
 
685
;
675
;                                                                 ;
686
;  This function calculates the final ip/tcp/udp checksum for you
-
 
-
 
676
; checksum_2: Calculate the final ip/tcp/udp checksum.            ;
687
;
677
;                                                                 ;
-
 
678
;   IN: edx = semi-checksum                                       ;
688
;  IN:  edx = semi-checksum
679
;                                                                 ;
689
;  OUT: dx = checksum (in INET byte order)
-
 
-
 
680
;  OUT: dx = checksum (in INET byte order)                        ;
690
;
681
;                                                                 ;
691
;-----------------------------------------------------------------
682
;-----------------------------------------------------------------;
692
align 4
683
align 4
Line 693... Line 684...
693
checksum_2:
684
checksum_2:
694
 
685
 
Line 711... Line 702...
711
 
702
 
Line 712... Line 703...
712
        ret
703
        ret
713
 
-
 
-
 
704
 
714
 
705
 
715
 
-
 
-
 
706
 
716
;----------------------------------------------------------------
707
;-----------------------------------------------------------------;
717
;
708
;                                                                 ;
718
;  System function to work with network devices (74)
709
;  System function 74: Low level access to network devices.       ;
Line 719... Line 710...
719
;
710
;                                                                 ;
720
;----------------------------------------------------------------
711
;-----------------------------------------------------------------;
Line 832... Line 823...
832
        mov     dword[esp+32], -1
823
        mov     dword[esp+32], -1
833
        ret
824
        ret
Line 834... Line 825...
834
 
825
 
835
 
-
 
-
 
826
 
836
 
827
 
837
;----------------------------------------------------------------
-
 
-
 
828
;-----------------------------------------------------------------;
838
;
829
;                                                                 ;
839
;  System function to work with protocols  (76)
830
;  System function 76: Low level access to protocol handlers.     ;
840
;
831
;                                                                 ;
841
;----------------------------------------------------------------
832
;-----------------------------------------------------------------;
842
align 4
833
align 4
Line 854... Line 845...
854
 
845
 
855
        mov     eax, ebx                        ; set ax to protocol number
846
        mov     eax, ebx                        ; set ax to protocol number
Line 856... Line 847...
856
        shr     eax, 16                         ;
847
        shr     eax, 16                         ;
857
 
848
 
Line 858... Line 849...
858
        cmp     ax, API_ETH
849
        cmp     ax, API_ETH
859
        je      ETH_api
850
        je      eth_api
Line 860... Line 851...
860
 
851
 
861
        cmp     ax, API_IPv4
852
        cmp     ax, API_IPv4
Line 862... Line 853...
862
        je      IPv4_api
853
        je      ipv4_api
863
 
854
 
Line 864... Line 855...
864
        cmp     ax, API_ICMP
855
        cmp     ax, API_ICMP
865
        je      ICMP_api
856
        je      icmp_api
Line 866... Line 857...
866
 
857
 
867
        cmp     ax, API_UDP
858
        cmp     ax, API_UDP
Line 868... Line 859...
868
        je      UDP_api
859
        je      udp_api
869
 
860
 
Line 870... Line 861...
870
        cmp     ax, API_TCP
861
        cmp     ax, API_TCP
871
        je      TCP_api
862
        je      tcp_api
Line 872... Line 863...
872
 
863
 
Line 873... Line 864...
873
        cmp     ax, API_ARP
864
        cmp     ax, API_ARP
874
        je      ARP_api
865
        je      arp_api