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 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  loopback.inc                                                   ;;
6
;;  loopback.inc                                                   ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  LoopBack device for KolibriOS                                  ;;
8
;;  LoopBack device for KolibriOS                                  ;;
Line 17... Line 17...
17
$Revision: 2891 $
17
$Revision: 2891 $
Line 18... Line 18...
18
 
18
 
Line 19... Line 19...
19
iglobal
19
iglobal
-
 
20
 
20
 
21
LOOPBACK_DEVICE:
21
LOOPBACK_DEVICE:
22
 
22
        .type            dd NET_TYPE_LOOPBACK
23
        .device_type    dd NET_DEVICE_LOOPBACK
Line 23... Line 24...
23
        .mtu             dd 4096
24
        .mtu            dd 4096
24
        .name            dd .namestr
25
        .name           dd .namestr
Line 30... Line 31...
30
        .bytes_tx        dq 0
31
        .bytes_tx       dq 0
31
        .bytes_rx        dq 0
32
        .bytes_rx       dq 0
32
        .packets_tx      dd 0
33
        .packets_tx     dd 0
33
        .packets_rx      dd 0
34
        .packets_rx     dd 0
Line -... Line 35...
-
 
35
 
-
 
36
        .link_state     dd -1
-
 
37
        .hwacc          dd 0
34
 
38
 
Line 35... Line 39...
35
        .namestr         db 'loopback', 0
39
        .namestr        db 'loopback', 0
36
 
40
 
Line 37... Line 41...
37
        .dummy_fn:
41
        .dummy_fn:
Line -... Line 42...
-
 
42
                ret
-
 
43
 
-
 
44
endg
-
 
45
 
-
 
46
 
-
 
47
macro   LOOP_init {
-
 
48
local   .fail
-
 
49
 
-
 
50
        mov     ebx, LOOPBACK_DEVICE
-
 
51
        call    NET_add_device
-
 
52
 
-
 
53
        cmp     eax, -1
-
 
54
        je      .fail
-
 
55
 
-
 
56
        mov     [IP_LIST], 127 + 1 shl 24
-
 
57
        mov     [SUBNET_LIST], 255
-
 
58
        mov     [BROADCAST_LIST], 0xffffff00 + 127
38
                ret
59
 
39
 
60
  .fail:
40
endg
61
}
41
 
62
 
42
;-----------------------------------------------------------------
63
;-----------------------------------------------------------------
Line 57... Line 78...
57
 
78
 
58
        push    ebx
79
        push    ebx
59
        push    ecx
80
        push    ecx
Line -... Line 81...
-
 
81
        push    eax
-
 
82
 
-
 
83
        inc     [LOOPBACK_DEVICE.packets_rx]
-
 
84
        add     dword[LOOPBACK_DEVICE.bytes_rx], ecx
60
        push    eax
85
        adc     dword[LOOPBACK_DEVICE.bytes_rx + 4], 0
61
 
86
 
62
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
87
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
63
        lea     edx, [eax + 2]
88
        lea     edx, [eax + 4]
Line 64... Line 89...
64
        mov     ax, word[eax]
89
        mov     eax, dword[eax]
65
        mov     ebx, LOOPBACK_DEVICE
90
        mov     ebx, LOOPBACK_DEVICE
Line 66... Line 91...
66
 
91
 
Line 67... Line 92...
67
        cmp     ax, ETHER_IPv4
92
        cmp     eax, AF_INET4
Line 79... Line 104...
79
;
104
;
80
; LOOP_output
105
; LOOP_output
81
;
106
;
82
; IN:
107
; IN:
83
;     ecx = packet size
108
;       ecx = packet size
84
;      di = protocol
109
;       edi = address family
85
;
110
;
86
; OUT: edi = 0 on error, pointer to buffer otherwise
111
; OUT:  edi = 0 on error, pointer to buffer otherwise
87
;      eax = buffer start
112
;       eax = buffer start
88
;      ebx = to device structure
113
;       ebx = to device structure
89
;      ecx = unchanged (packet size of embedded data)
114
;       ecx = unchanged (packet size of embedded data)
Line 94... Line 119...
94
LOOP_output:
119
LOOP_output:
Line 95... Line 120...
95
 
120
 
Line 96... Line 121...
96
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
121
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
97
 
122
 
Line 98... Line 123...
98
        push    ecx
123
        push    ecx
99
        push    di
124
        push    edi
100
 
125
 
101
        add     ecx, 2
126
        add     ecx, 4
102
        cmp     ecx, [LOOPBACK_DEVICE.mtu]
127
        cmp     ecx, [LOOPBACK_DEVICE.mtu]
103
        ja      .out_of_ram
128
        ja      .out_of_ram
104
        stdcall kernel_alloc, ecx
129
        stdcall kernel_alloc, ecx
105
        test    eax, eax
130
        test    eax, eax
106
        jz      .out_of_ram
131
        jz      .out_of_ram
Line 107... Line 132...
107
        mov     edi, eax
132
        mov     edi, eax
108
        pop     ax
133
        pop     eax
109
        stosw
134
        stosd
110
 
135
 
Line -... Line 136...
-
 
136
        lea     eax, [edi - 4]  ; Set eax to buffer start
-
 
137
        pop     ecx
-
 
138
        lea     edx, [ecx + 4]  ; Set edx to complete buffer size
111
        lea     eax, [edi - 2]  ; Set eax to buffer start
139
        mov     ebx, LOOPBACK_DEVICE
112
        pop     ecx
140
 
113
        lea     edx, [ecx + 2]  ; Set edx to complete buffer size
141
        inc     [LOOPBACK_DEVICE.packets_tx]
Line 114... Line 142...
114
        mov     ebx, LOOPBACK_DEVICE
142
        add     dword[LOOPBACK_DEVICE.bytes_tx], ecx
115
 
143
        adc     dword[LOOPBACK_DEVICE.bytes_tx + 4], 0
116
  .done:
144
 
117
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
145
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
118
        ret
146
        ret