Subversion Repositories Kolibri OS

Rev

Rev 3589 | Rev 3725 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3589 Rev 3626
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: 3589 $
24
$Revision: 3626 $
25
 
25
 
26
uglobal
26
uglobal
27
        net_10ms        dd ?
27
        net_10ms        dd ?
Line 28... Line 28...
28
        net_tmr_count   dw ?
28
        net_tmr_count   dw ?
29
endg
29
endg
Line 30... Line 30...
30
 
30
 
31
DEBUG_NETWORK_ERROR     = 1
31
DEBUG_NETWORK_ERROR     = 1
Line 32... Line 32...
32
DEBUG_NETWORK_VERBOSE   = 0
32
DEBUG_NETWORK_VERBOSE   = 0
-
 
33
 
33
 
34
NET_DEVICES_MAX         = 16
34
MAX_NET_DEVICES         = 16
-
 
35
ARP_BLOCK               = 1             ; true or false
35
ARP_BLOCK               = 1             ; true or false
Line 36... Line 36...
36
 
36
 
37
MIN_EPHEMERAL_PORT      = 49152
37
EPHEMERAL_PORT_MIN      = 49152
38
MIN_EPHEMERAL_PORT_N    = 0x00C0        ; same in Network byte order (FIXME)
38
EPHEMERAL_PORT_MAX      = 61000
39
MAX_EPHEMERAL_PORT      = 61000
39
MIN_EPHEMERAL_PORT_N    = 0x00C0        ; same in Network byte order (FIXME)
40
MAX_EPHEMERAL_PORT_N    = 0x48EE        ; same in Network byte order (FIXME)
40
MAX_EPHEMERAL_PORT_N    = 0x48EE        ; same in Network byte order (FIXME)
41
 
41
 
-
 
42
; Ethernet protocol numbers
-
 
43
ETHER_PROTO_ARP                 = 0x0608
-
 
44
ETHER_PROTO_IPv4                = 0x0008
-
 
45
ETHER_PROTO_IPv6                = 0xDD86
-
 
46
ETHER_PROTO_PPP_DISCOVERY       = 0x6388
-
 
47
ETHER_PROTO_PPP_SESSION         = 0x6488
Line 42... Line 48...
42
; Ethernet protocol numbers
48
 
43
ETHER_ARP               = 0x0608
49
; Internet protocol numbers
44
ETHER_IPv4              = 0x0008
50
IP_PROTO_IP             = 0
-
 
51
IP_PROTO_ICMP           = 1
Line 45... Line 52...
45
ETHER_IPv6              = 0xDD86
52
IP_PROTO_TCP            = 6
46
ETHER_PPP_DISCOVERY     = 0x6388
53
IP_PROTO_UDP            = 17
47
ETHER_PPP_SESSION       = 0x6488
54
 
48
 
55
; PPP protocol numbers
49
; PPP protocol numbers
56
PPP_PROTO_IPv4          = 0x2100
50
PPP_IPv4                = 0x2100
57
PPP_PROTO_IPV6          = 0x5780
51
PPP_IPV6                = 0x5780
-
 
52
 
-
 
53
;Protocol family
-
 
54
AF_UNSPEC               = 0
-
 
55
AF_LOCAL                = 1
-
 
56
AF_INET4                = 2
-
 
57
AF_INET6                = 10
-
 
58
AF_PPP                  = 777
-
 
59
 
-
 
Line 60... Line 58...
60
; Internet protocol numbers
58
PPP_PROTO_ETHERNET      = 666           ; FIXME
61
IP_PROTO_IP             = 0
59
 
62
IP_PROTO_ICMP           = 1
60
;Protocol family
63
IP_PROTO_TCP            = 6
61
AF_UNSPEC               = 0
Line 112... Line 110...
112
 
110
 
Line 113... Line 111...
113
SS_BLOCKED              = 0x8000
111
SS_BLOCKED              = 0x8000
114
 
-
 
115
 
-
 
116
SOCKET_MAXDATA          = 4096*32     ; must be 4096*(power of 2) where 'power of 2' is at least 8
-
 
117
 
-
 
118
; Network driver types
-
 
119
NET_TYPE_LOOPBACK       = 0
-
 
120
NET_TYPE_ETH            = 1
112
 
Line 121... Line 113...
121
NET_TYPE_SLIP           = 2
113
 
122
 
114
SOCKET_MAXDATA          = 4096*32       ; must be 4096*(power of 2) where 'power of 2' is at least 8
123
MAX_backlog             = 20          ; maximum backlog for stream sockets
115
MAX_backlog             = 20            ; maximum backlog for stream sockets
Line 137... Line 129...
137
API_TCP                 = 4
129
API_TCP                 = 4
138
API_ARP                 = 5
130
API_ARP                 = 5
139
API_PPPOE               = 6
131
API_PPPOE               = 6
140
API_IPv6                = 7
132
API_IPv6                = 7
Line -... Line 133...
-
 
133
 
-
 
134
; Network device types
-
 
135
NET_DEVICE_LOOPBACK     = 0
-
 
136
NET_DEVICE_ETH          = 1
-
 
137
NET_DEVICE_SLIP         = 2
-
 
138
 
-
 
139
; Network link types (link protocols)
-
 
140
NET_LINK_LOOPBACK       = 0     ;;; Really a link type?
-
 
141
NET_LINK_MAC            = 1     ; Media access control (ethernet, isdn, ...)
-
 
142
NET_LINK_PPP            = 2     ; Point to Point Protocol (PPPoE, ...)
-
 
143
NET_LINK_IEEE802.11     = 3     ; IEEE 802.11 (WiFi)
-
 
144
 
141
 
145
; Hardware acceleration bits
Line 142... Line 146...
142
HWACC_TCP_IPv4          = 1 shl 0
146
HWACC_TCP_IPv4          = 1 shl 0
Line 143... Line 147...
143
 
147
 
144
struct  NET_DEVICE
148
struct  NET_DEVICE
145
 
149
 
Line 146... Line 150...
146
        type            dd ?    ; Type field
150
        device_type     dd ?    ; Type field
147
        mtu             dd ?    ; Maximal Transmission Unit
151
        mtu             dd ?    ; Maximal Transmission Unit
Line 154... Line 158...
154
        bytes_tx        dq ?    ; Statistics, updated by the driver
158
        bytes_tx        dq ?    ; Statistics, updated by the driver
155
        bytes_rx        dq ?    ;
159
        bytes_rx        dq ?    ;
156
        packets_tx      dd ?    ;
160
        packets_tx      dd ?    ;
157
        packets_rx      dd ?    ;
161
        packets_rx      dd ?    ;
Line 158... Line 162...
158
 
162
 
159
        state           dd ?    ; link state (0 = no link)
163
        link_state      dd ?    ; link state (0 = no link)
Line 160... Line 164...
160
        hwacc           dd ?    ; bitmask stating enabled HW accelerations (offload engines)
164
        hwacc           dd ?    ; bitmask stating enabled HW accelerations (offload engines)
Line 211... Line 215...
211
 
215
 
212
align 4
216
align 4
Line 213... Line 217...
213
uglobal
217
uglobal
214
 
-
 
215
        NET_RUNNING     dd  ?
218
 
Line 216... Line 219...
216
        NET_DEFAULT     dd  ?
219
        NET_RUNNING     dd  ?
Line 217... Line 220...
217
        NET_DRV_LIST    rd  MAX_NET_DEVICES
220
        NET_DRV_LIST    rd  NET_DEVICES_MAX
Line 233... Line 236...
233
stack_init:
236
stack_init:
Line 234... Line 237...
234
 
237
 
235
; Init the network drivers list
238
; Init the network drivers list
236
        xor     eax, eax
239
        xor     eax, eax
237
        mov     edi, NET_RUNNING
240
        mov     edi, NET_RUNNING
238
        mov     ecx, (MAX_NET_DEVICES + 2)
241
        mov     ecx, (NET_DEVICES_MAX + 2)
Line 239... Line 242...
239
        rep     stosd
242
        rep     stosd
Line 240... Line 243...
240
 
243
 
Line 248... Line 251...
248
        UDP_init
251
        UDP_init
249
        TCP_init
252
        TCP_init
Line 250... Line 253...
250
 
253
 
Line -... Line 254...
-
 
254
        SOCKET_init
-
 
255
 
251
        SOCKET_init
256
        LOOP_init
Line 252... Line 257...
252
 
257
 
Line 306... Line 311...
306
 
311
 
307
 
312
 
Line 308... Line 313...
308
align 4
313
align 4
Line 309... Line 314...
309
NET_link_changed:
314
NET_link_changed:
310
 
315
 
Line 311... Line 316...
311
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.state]
316
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.link_state]
Line 343... Line 348...
343
align 4
348
align 4
344
NET_add_device:
349
NET_add_device:
Line 345... Line 350...
345
 
350
 
Line 346... Line 351...
346
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_Add_Device: %x\n", ebx   ;;; TODO: use mutex to lock net device list
351
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_Add_Device: %x\n", ebx   ;;; TODO: use mutex to lock net device list
347
 
352
 
Line 348... Line 353...
348
        cmp     [NET_RUNNING], MAX_NET_DEVICES
353
        cmp     [NET_RUNNING], NET_DEVICES_MAX
349
        jae     .error
354
        jae     .error
350
 
355
 
351
;----------------------------------
356
;----------------------------------
352
; Check if device is already listed
357
; Check if device is already listed
Line 353... Line 358...
353
        mov     eax, ebx
358
        mov     eax, ebx
354
        mov     ecx, MAX_NET_DEVICES    ; We need to check whole list because a device may be removed without re-organizing list
359
        mov     ecx, NET_DEVICES_MAX    ; We need to check whole list because a device may be removed without re-organizing list
Line 355... Line 360...
355
        mov     edi, NET_DRV_LIST
360
        mov     edi, NET_DRV_LIST
356
 
361
 
357
        repne   scasd                   ; See if device is already in the list
362
        repne   scasd                   ; See if device is already in the list
358
        jz      .error
363
        jz      .error
359
 
364
 
Line 360... Line 365...
360
;----------------------------
365
;----------------------------
361
; Find empty slot in the list
366
; Find empty slot in the list
Line 376... Line 381...
376
        sub     eax, NET_DRV_LIST
381
        sub     eax, NET_DRV_LIST
377
        shr     eax, 2
382
        shr     eax, 2
Line 378... Line 383...
378
 
383
 
Line 379... Line -...
379
        inc     [NET_RUNNING]           ; Indicate that one more network device is up and running
-
 
380
 
-
 
381
        cmp     eax, 1                  ; If it's the first network device, try to set it as default
-
 
382
        jne     @f
-
 
383
        push    eax
-
 
384
        call    NET_set_default
-
 
385
        pop     eax
-
 
386
       @@:
384
        inc     [NET_RUNNING]           ; Indicate that one more network device is up and running
Line 387... Line 385...
387
 
385
 
388
        call    NET_send_event
386
        call    NET_send_event
Line 397... Line 395...
397
 
395
 
398
 
396
 
399
 
-
 
400
;-----------------------------------------------------------------
-
 
401
;
-
 
402
; NET_set_default
-
 
403
;
-
 
404
;  API to set the default interface
-
 
405
;
-
 
406
;  IN:  Device num in eax
-
 
407
;  OUT: Device num in eax, -1 on error
-
 
408
;
-
 
409
;-----------------------------------------------------------------
-
 
410
align 4
-
 
411
NET_set_default:
-
 
412
 
-
 
413
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_set_default: device=%x\n", eax
-
 
414
 
-
 
415
        cmp     eax, MAX_NET_DEVICES
-
 
416
        jae     .error
-
 
417
 
-
 
418
        cmp     [NET_DRV_LIST+eax*4], 0
-
 
419
        je      .error
-
 
420
 
-
 
421
        mov     [NET_DEFAULT], eax
-
 
422
 
-
 
423
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_set_default: succes\n"
-
 
424
        ret
-
 
425
 
-
 
426
  .error:
-
 
427
        or      eax, -1
-
 
428
        DEBUGF  DEBUG_NETWORK_ERROR, "NET_set_default: failed\n"
-
 
429
        ret
-
 
430
 
-
 
431
 
397
 
432
;-----------------------------------------------------------------
398
;-----------------------------------------------------------------
433
;
399
;
434
; NET_Remove_Device:
400
; NET_Remove_Device:
435
;
401
;
436
;  This function is called by etwork drivers,
402
;  This function is called by network drivers,
437
;  to unregister network devices from the kernel
403
;  to unregister network devices from the kernel
438
;
404
;
Line 444... Line 410...
444
NET_remove_device:
410
NET_remove_device:
Line 445... Line 411...
445
 
411
 
446
        cmp     [NET_RUNNING], 0
412
        cmp     [NET_RUNNING], 0
Line 447... Line -...
447
        je      .error
-
 
448
 
-
 
449
        cmp     [NET_DRV_LIST], ebx
-
 
450
        jne     @f
-
 
451
        mov     [NET_DRV_LIST], 0
-
 
452
        cmp     [NET_RUNNING], 1
-
 
453
        je      @f
-
 
454
        ; there are still active devices, find one and make it default
-
 
455
        xor     eax, eax
-
 
456
        mov     ecx, MAX_NET_DEVICES
-
 
457
        mov     edi, NET_DRV_LIST
-
 
458
        repe    scasd
-
 
459
        je      @f
-
 
460
        shr     edi, 2
-
 
461
        dec     edi
-
 
462
        mov     [NET_DEFAULT], edi
-
 
463
       @@:
413
        je      .error
464
 
414
 
Line 465... Line 415...
465
;----------------------------
415
;----------------------------
466
; Find the driver in the list
416
; Find the driver in the list
467
 
417
 
Line 468... Line 418...
468
        mov     eax, ebx
418
        mov     eax, ebx
469
        mov     ecx, MAX_NET_DEVICES
419
        mov     ecx, NET_DEVICES_MAX
Line 470... Line 420...
470
        mov     edi, NET_DRV_LIST+4
420
        mov     edi, NET_DRV_LIST
471
 
421
 
Line 472... Line 422...
472
        repne   scasd
422
        repne   scasd
473
        jnz     .error
423
        jnz     .error
-
 
424
 
Line 474... Line 425...
474
 
425
;------------------------
Line 475... Line 426...
475
;------------------------
426
; Remove it from the list
476
; Remove it from the list
427
 
Line 477... Line 428...
477
 
428
        xor     eax, eax
478
        xor     eax, eax
429
        mov     dword [edi-4], eax
479
        mov     dword [edi-4], eax
430
        dec     [NET_RUNNING]
Line 499... Line 450...
499
;-----------------------------------------------------------------
450
;-----------------------------------------------------------------
500
align 4
451
align 4
501
NET_ptr_to_num:
452
NET_ptr_to_num:
502
        push    ecx
453
        push    ecx
Line 503... Line 454...
503
 
454
 
504
        mov     ecx, MAX_NET_DEVICES
455
        mov     ecx, NET_DEVICES_MAX
Line 505... Line 456...
505
        mov     edi, NET_DRV_LIST
456
        mov     edi, NET_DRV_LIST
506
 
457
 
507
  .loop:
458
  .loop:
Line 643... Line 594...
643
 
594
 
644
 
595
 
645
 
596
 
646
;----------------------------------------------------------------
597
;----------------------------------------------------------------
647
;
598
;
648
;  System function to work with network devices (75)
599
;  System function to work with network devices (74)
649
;
600
;
Line 650... Line 601...
650
;----------------------------------------------------------------
601
;----------------------------------------------------------------
651
align 4
602
align 4
Line 652... Line 603...
652
sys_network:                    ; FIXME: make default device easily accessible
603
sys_network:
653
 
604
 
-
 
605
        cmp     ebx, -1
Line 654... Line 606...
654
        cmp     ebx, -1
606
        jne     @f
655
        jne     @f
607
 
656
 
608
        mov     eax, [NET_RUNNING]
Line 657... Line 609...
657
        mov     eax, [NET_RUNNING]
609
        mov     [esp+32], eax
658
        jmp     .return
610
        ret
659
 
611
 
Line 680... Line 632...
680
        dd      .get_dev_name           ; 1
632
        dd      .get_dev_name           ; 1
681
        dd      .reset                  ; 2
633
        dd      .reset                  ; 2
682
        dd      .stop                   ; 3
634
        dd      .stop                   ; 3
683
        dd      .get_ptr                ; 4
635
        dd      .get_ptr                ; 4
684
        dd      .get_drv_name           ; 5
636
        dd      .get_drv_name           ; 5
685
        dd      .set_default            ; 6
-
 
686
  .number = ($ - .table) / 4 - 1
-
 
687
 
-
 
688
  .get_type:                            ; 0 = Get device type (ethernet/token ring/...)
-
 
689
 
-
 
690
        mov     eax, [eax + NET_DEVICE.type]
-
 
691
        jmp     .return
-
 
Line -... Line 637...
-
 
637
 
-
 
638
        dd      .packets_tx             ; 6
-
 
639
        dd      .packets_rx             ; 7
-
 
640
        dd      .bytes_tx               ; 8
-
 
641
        dd      .bytes_rx               ; 9
-
 
642
        dd      .state                  ; 10
Line -... Line 643...
-
 
643
  .number = ($ - .table) / 4 - 1
692
 
644
 
-
 
645
  .get_type:
-
 
646
        mov     eax, [eax + NET_DEVICE.device_type]
Line -... Line 647...
-
 
647
        mov     [esp+32], eax
693
 
648
        ret
694
  .get_dev_name:                        ; 1 = Get device name
649
 
Line 695... Line 650...
695
 
650
  .get_dev_name:
696
        mov     esi, [eax + NET_DEVICE.name]
651
        mov     esi, [eax + NET_DEVICE.name]
Line 697... Line 652...
697
        mov     edi, ecx
652
        mov     edi, ecx
698
 
653
 
699
        mov     ecx, 64/4 ; max length
-
 
700
        rep     movsd
654
        mov     ecx, 64/4 ; max length
Line -... Line 655...
-
 
655
        rep     movsd
701
 
656
 
702
        xor     eax, eax
657
        xor     eax, eax
703
        jmp     .return
-
 
704
 
658
        mov     [esp+32], eax
Line -... Line 659...
-
 
659
        ret
705
  .reset:                               ; 2 = Reset the device
660
 
706
 
661
  .reset:
707
        call    [eax + NET_DEVICE.reset]
-
 
708
        jmp     .return
-
 
709
 
662
        call    [eax + NET_DEVICE.reset]
Line 710... Line -...
710
  .stop:                                ; 3 = Stop driver for this device
-
 
Line -... Line 663...
-
 
663
        mov     [esp+32], eax
-
 
664
        ret
-
 
665
 
Line 711... Line -...
711
 
-
 
Line -... Line 666...
-
 
666
  .stop:
712
        call    [eax + NET_DEVICE.unload]
667
        call    [eax + NET_DEVICE.unload]
713
        jmp     .return
668
        mov     [esp+32], eax
-
 
669
        ret
Line -... Line 670...
-
 
670
 
-
 
671
 
-
 
672
  .get_ptr:
-
 
673
        mov     [esp+32], eax
Line -... Line 674...
-
 
674
        ret
714
 
675
 
-
 
676
 
-
 
677
  .get_drv_name:
Line -... Line 678...
-
 
678
        xor     eax, eax
-
 
679
        mov     [esp+32], eax
715
 
680
        ret
-
 
681
 
716
  .get_ptr:                             ; 4 = Get driver pointer
682
  .packets_tx:
-
 
683
        mov     eax, [eax + NET_DEVICE.packets_tx]
Line 717... Line 684...
717
 
684
        mov     [esp+32], eax
-
 
685
        ret
-
 
686
 
-
 
687
  .packets_rx:
718
        jmp     .return
688
        mov     eax, [eax + NET_DEVICE.packets_rx]
-
 
689
        mov     [esp+32], eax
Line 719... Line 690...
719
 
690
        ret
-
 
691
 
720
 
692
  .bytes_tx:
721
  .get_drv_name:                        ; 5 = Get driver name
693
        mov     ebx, dword [eax + NET_DEVICE.bytes_tx + 4]
Line -... Line 694...
-
 
694
        mov     [esp+20], ebx
-
 
695
        mov     eax, dword [eax + NET_DEVICE.bytes_tx]
-
 
696
        mov     [esp+32], eax
-
 
697
        ret
-
 
698
 
-
 
699
  .bytes_rx:
722
 
700
        mov     ebx, dword [eax + NET_DEVICE.bytes_rx + 4]
723
        xor     eax, eax
701
        mov     [esp+20], ebx
724
        jmp     .return
702
        mov     eax, dword [eax + NET_DEVICE.bytes_rx]
725
 
703
        mov     [esp+32], eax
726
 
704
        ret
727
  .set_default:                         ; 6 = Set default device
705
 
728
 
706
  .state:
729
        call    NET_set_default
707
        mov     eax, [eax + NET_DEVICE.link_state]
730
        jmp     .return
708
        mov     [esp+32], eax
Line 731... Line 709...
731
 
709
        ret
732
  .doesnt_exist:
710
 
733
        mov     eax, -1
711