Subversion Repositories Kolibri OS

Rev

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

Rev 3556 Rev 3600
Line 29... Line 29...
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
 
Line 34... Line 34...
34
MAX_NET_DEVICES         = 16
34
NET_DEVICES_MAX         = 16
-
 
35
ARP_BLOCK               = 1             ; true or false
35
ARP_BLOCK               = 1             ; true or false
36
 
36
 
-
 
37
MIN_EPHEMERAL_PORT      = 49152
37
EPHEMERAL_PORT_MIN      = 49152
Line 38... Line 38...
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
42
; Ethernet protocol numbers
43
ETHER_ARP               = 0x0608
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
-
 
48
 
-
 
49
; Internet protocol numbers
Line 44... Line 50...
44
ETHER_IPv4              = 0x0008
50
IP_PROTO_IP             = 0
45
ETHER_IPv6              = 0xDD86
51
IP_PROTO_ICMP           = 1
46
ETHER_PPP_DISCOVERY     = 0x6388
52
IP_PROTO_TCP            = 6
-
 
53
IP_PROTO_UDP            = 17
Line 47... Line 54...
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
58
PPP_PROTO_ETHERNET      = 666           ; FIXME
52
 
59
 
53
;Protocol family
-
 
54
AF_UNSPEC               = 0
-
 
55
AF_LOCAL                = 1
-
 
56
AF_INET4                = 2
-
 
57
AF_INET6                = 10
-
 
58
AF_PPP                  = 777
-
 
59
 
-
 
60
; Internet protocol numbers
-
 
61
IP_PROTO_IP             = 0
-
 
Line 62... Line 60...
62
IP_PROTO_ICMP           = 1
60
;Protocol family
63
IP_PROTO_TCP            = 6
61
AF_UNSPEC               = 0
64
IP_PROTO_UDP            = 17
62
AF_LOCAL                = 1
65
 
63
AF_INET4                = 2
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 212... Line 216...
212
align 4
216
align 4
213
uglobal
217
uglobal
Line 214... Line 218...
214
 
218
 
215
        NET_RUNNING     dd  ?
219
        NET_RUNNING     dd  ?
216
        NET_DEFAULT     dd  ?
220
        NET_DEFAULT     dd  ?
Line 217... Line 221...
217
        NET_DRV_LIST    rd  MAX_NET_DEVICES
221
        NET_DRV_LIST    rd  NET_DEVICES_MAX
Line 218... Line 222...
218
 
222
 
Line 233... Line 237...
233
stack_init:
237
stack_init:
Line 234... Line 238...
234
 
238
 
235
; Init the network drivers list
239
; Init the network drivers list
236
        xor     eax, eax
240
        xor     eax, eax
237
        mov     edi, NET_RUNNING
241
        mov     edi, NET_RUNNING
238
        mov     ecx, (MAX_NET_DEVICES + 2)
242
        mov     ecx, (NET_DEVICES_MAX + 2)
Line 239... Line 243...
239
        rep     stosd
243
        rep     stosd
Line 240... Line 244...
240
 
244
 
Line 343... Line 347...
343
align 4
347
align 4
344
NET_add_device:
348
NET_add_device:
Line 345... Line 349...
345
 
349
 
Line 346... Line 350...
346
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_Add_Device: %x\n", ebx   ;;; TODO: use mutex to lock net device list
350
        DEBUGF  DEBUG_NETWORK_VERBOSE, "NET_Add_Device: %x\n", ebx   ;;; TODO: use mutex to lock net device list
347
 
351
 
Line 348... Line 352...
348
        cmp     [NET_RUNNING], MAX_NET_DEVICES
352
        cmp     [NET_RUNNING], NET_DEVICES_MAX
349
        jae     .error
353
        jae     .error
350
 
354
 
351
;----------------------------------
355
;----------------------------------
352
; Check if device is already listed
356
; Check if device is already listed
Line 353... Line 357...
353
        mov     eax, ebx
357
        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
358
        mov     ecx, NET_DEVICES_MAX    ; We need to check whole list because a device may be removed without re-organizing list
Line 355... Line 359...
355
        mov     edi, NET_DRV_LIST
359
        mov     edi, NET_DRV_LIST
356
 
360
 
357
        repne   scasd                   ; See if device is already in the list
361
        repne   scasd                   ; See if device is already in the list
358
        jz      .error
362
        jz      .error
359
 
363
 
Line 360... Line 364...
360
;----------------------------
364
;----------------------------
361
; Find empty slot in the list
365
; Find empty slot in the list
Line 376... Line 380...
376
        sub     eax, NET_DRV_LIST
380
        sub     eax, NET_DRV_LIST
377
        shr     eax, 2
381
        shr     eax, 2
Line 378... Line 382...
378
 
382
 
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
       @@:
383
        inc     [NET_RUNNING]           ; Indicate that one more network device is up and running
Line 387... Line 384...
387
 
384
 
388
        call    NET_send_event
385
        call    NET_send_event
Line 397... Line 394...
397
 
394
 
398
 
395
 
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
 
396
 
432
;-----------------------------------------------------------------
397
;-----------------------------------------------------------------
433
;
398
;
434
; NET_Remove_Device:
399
; NET_Remove_Device:
435
;
400
;
Line 451... Line 416...
451
        mov     [NET_DRV_LIST], 0
416
        mov     [NET_DRV_LIST], 0
452
        cmp     [NET_RUNNING], 1
417
        cmp     [NET_RUNNING], 1
453
        je      @f
418
        je      @f
454
        ; there are still active devices, find one and make it default
419
        ; there are still active devices, find one and make it default
455
        xor     eax, eax
420
        xor     eax, eax
456
        mov     ecx, MAX_NET_DEVICES
421
        mov     ecx, NET_DEVICES_MAX
457
        mov     edi, NET_DRV_LIST
422
        mov     edi, NET_DRV_LIST
458
        repe    scasd
423
        repe    scasd
459
        je      @f
424
        je      @f
460
        shr     edi, 2
425
        shr     edi, 2
461
        dec     edi
426
        dec     edi
Line 464... Line 429...
464
 
429
 
465
;----------------------------
430
;----------------------------
Line 466... Line 431...
466
; Find the driver in the list
431
; Find the driver in the list
467
 
432
 
468
        mov     eax, ebx
433
        mov     eax, ebx
Line 469... Line 434...
469
        mov     ecx, MAX_NET_DEVICES
434
        mov     ecx, NET_DEVICES_MAX
470
        mov     edi, NET_DRV_LIST+4
435
        mov     edi, NET_DRV_LIST+4
Line 499... Line 464...
499
;-----------------------------------------------------------------
464
;-----------------------------------------------------------------
500
align 4
465
align 4
501
NET_ptr_to_num:
466
NET_ptr_to_num:
502
        push    ecx
467
        push    ecx
Line 503... Line 468...
503
 
468
 
504
        mov     ecx, MAX_NET_DEVICES
469
        mov     ecx, NET_DEVICES_MAX
Line 505... Line 470...
505
        mov     edi, NET_DRV_LIST
470
        mov     edi, NET_DRV_LIST
506
 
471
 
507
  .loop:
472
  .loop:
Line 656... Line 621...
656
 
621
 
657
        mov     eax, [NET_RUNNING]
622
        mov     eax, [NET_RUNNING]
Line 658... Line 623...
658
        jmp     .return
623
        jmp     .return
659
 
624
 
660
   @@:
625
   @@:
Line 661... Line 626...
661
        cmp     bh, MAX_NET_DEVICES             ; Check if device number exists
626
        cmp     bh, NET_DEVICES_MAX             ; Check if device number exists
662
        jae     .doesnt_exist
627
        jae     .doesnt_exist
663
 
628
 
Line 680... Line 645...
680
        dd      .get_dev_name           ; 1
645
        dd      .get_dev_name           ; 1
681
        dd      .reset                  ; 2
646
        dd      .reset                  ; 2
682
        dd      .stop                   ; 3
647
        dd      .stop                   ; 3
683
        dd      .get_ptr                ; 4
648
        dd      .get_ptr                ; 4
684
        dd      .get_drv_name           ; 5
649
        dd      .get_drv_name           ; 5
685
        dd      .set_default            ; 6
-
 
686
  .number = ($ - .table) / 4 - 1
650
  .number = ($ - .table) / 4 - 1
Line 687... Line 651...
687
 
651
 
Line 688... Line 652...
688
  .get_type:                            ; 0 = Get device type (ethernet/token ring/...)
652
  .get_type:                            ; 0 = Get device type (ethernet/token ring/...)
689
 
653
 
Line 690... Line 654...
690
        mov     eax, [eax + NET_DEVICE.type]
654
        mov     eax, [eax + NET_DEVICE.device_type]
Line 722... Line 686...
722
 
686
 
723
        xor     eax, eax
687
        xor     eax, eax
Line 724... Line -...
724
        jmp     .return
-
 
725
 
-
 
726
 
-
 
727
  .set_default:                         ; 6 = Set default device
-
 
728
 
-
 
729
        call    NET_set_default
688
        jmp     .return
730
        jmp     .return
689
 
Line 731... Line 690...
731
 
690
 
732
  .doesnt_exist:
691
  .doesnt_exist:
Line 742... Line 701...
742
;  System function to work with protocols  (76)
701
;  System function to work with protocols  (76)
743
;
702
;
744
;----------------------------------------------------------------
703
;----------------------------------------------------------------
745
align 4
704
align 4
746
sys_protocols:
705
sys_protocols:
747
        cmp     bh, MAX_NET_DEVICES             ; Check if device number exists
706
        cmp     bh, NET_DEVICES_MAX             ; Check if device number exists
748
        jae     .doesnt_exist
707
        jae     .doesnt_exist
Line 749... Line 708...
749
 
708
 
750
        mov     esi, ebx
709
        mov     esi, ebx
751
        and     esi, 0x0000ff00
710
        and     esi, 0x0000ff00