Subversion Repositories Kolibri OS

Rev

Rev 8103 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8103 Rev 9054
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2019. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2021. 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                                  ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
11
;;                                                                 ;;
11
;;                                                                 ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
 
16
 
17
$Revision: 8103 $
17
$Revision: 9054 $
18
 
18
 
19
iglobal
19
iglobal
20
align 4
20
align 4
21
 
21
 
22
LOOPBACK_DEVICE:
22
LOOPBACK_DEVICE:
23
 
23
 
24
        .device_type    dd NET_DEVICE_LOOPBACK
24
        .device_type     dd NET_DEVICE_LOOPBACK
25
        .mtu            dd 4096
25
        .mtu             dd NET_BUFFER_SIZE - NET_BUFF.data
26
        .name           dd .namestr
26
        .name            dd .namestr
27
 
27
 
28
        .unload         dd loop_dummy
28
        .unload          dd loop_dummy
29
        .reset          dd loop_dummy
29
        .reset           dd loop_dummy
30
        .transmit       dd loop_input
30
        .transmit        dd loop_input
31
 
-
 
32
        .bytes_tx       dq 0
-
 
33
        .bytes_rx       dq 0
-
 
34
        .packets_tx     dd 0
-
 
35
        .packets_rx     dd 0
-
 
36
 
31
 
37
        .link_state     dd -1
32
        .link_state      dd -1
38
        .hwacc          dd NET_HWACC_TCP_IPv4_IN + NET_HWACC_TCP_IPv4_OUT
33
        .hwacc           dd NET_HWACC_TCP_IPv4_IN + NET_HWACC_TCP_IPv4_OUT
-
 
34
 
-
 
35
        .bytes_tx        dq ?
-
 
36
        .bytes_rx        dq ?
-
 
37
 
-
 
38
        .packets_tx      dd ?
-
 
39
        .packets_tx_err  dd ?
-
 
40
        .packets_tx_drop dd ?
-
 
41
        .packets_tx_ovr  dd ?
-
 
42
 
-
 
43
        .packets_rx      dd ?
-
 
44
        .packets_rx_err  dd ?
-
 
45
        .packets_rx_drop dd ?
-
 
46
        .packets_rx_ovr  dd ?
39
 
47
 
40
        .namestr        db 'loopback', 0
48
        .namestr         db 'loopback', 0
41
 
49
 
42
endg
50
endg
43
 
51
 
44
 
52
 
45
macro   loop_init {
53
macro   loop_init {
46
local   .fail
54
local   .fail
47
 
55
 
48
        mov     ebx, LOOPBACK_DEVICE
56
        mov     ebx, LOOPBACK_DEVICE
49
        call    net_add_device
57
        call    net_add_device
50
 
58
 
51
        cmp     eax, -1
59
        cmp     eax, -1
52
        je      .fail
60
        je      .fail
53
 
61
 
54
        mov     [IPv4_address], 127 + 1 shl 24
62
        mov     [IPv4_address], 127 + 1 shl 24
55
        mov     [IPv4_subnet], 255
63
        mov     [IPv4_subnet], 255
56
        mov     [IPv4_broadcast], 0xffffff00 + 127
64
        mov     [IPv4_broadcast], 0xffffff00 + 127
57
 
65
 
58
  .fail:
66
  .fail:
59
}
67
}
60
 
68
 
61
;-----------------------------------------------------------------;
69
;-----------------------------------------------------------------;
62
;                                                                 ;
70
;                                                                 ;
63
; loop_dummy                                                      ;
71
; loop_dummy                                                      ;
64
;                                                                 ;
72
;                                                                 ;
65
;   IN: /                                                         ;
73
;   IN: /                                                         ;
66
;                                                                 ;
74
;                                                                 ;
67
;  OUT: /                                                         ;
75
;  OUT: /                                                         ;
68
;                                                                 ;
76
;                                                                 ;
69
;-----------------------------------------------------------------;
77
;-----------------------------------------------------------------;
70
align 4
78
align 4
71
loop_dummy:
79
loop_dummy:
72
        ret
80
        ret
73
 
81
 
74
;-----------------------------------------------------------------;
82
;-----------------------------------------------------------------;
75
;                                                                 ;
83
;                                                                 ;
76
; loop_input                                                      ;
84
; loop_input                                                      ;
77
;                                                                 ;
85
;                                                                 ;
78
;   IN: [esp+4] = Pointer to buffer                               ;
86
;   IN: [esp+4] = Pointer to buffer                               ;
79
;                                                                 ;
87
;                                                                 ;
80
;  OUT: eax = 0 on success, errorcode otherwise                   ;
88
;  OUT: eax = 0 on success, errorcode otherwise                   ;
81
;                                                                 ;
89
;                                                                 ;
82
;-----------------------------------------------------------------;
90
;-----------------------------------------------------------------;
83
align 4
91
align 4
84
loop_input:
92
loop_input:
85
 
93
 
86
        mov     eax, [esp+4]
94
        mov     eax, [esp+4]
87
 
95
 
88
; Update stats
96
; Update stats
89
        inc     [LOOPBACK_DEVICE.packets_tx]
97
        inc     [LOOPBACK_DEVICE.packets_tx]
90
        inc     [LOOPBACK_DEVICE.packets_rx]
98
        inc     [LOOPBACK_DEVICE.packets_rx]
91
 
99
 
92
        mov     ecx, [eax + NET_BUFF.length]
100
        mov     ecx, [eax + NET_BUFF.length]
93
        add     dword[LOOPBACK_DEVICE.bytes_rx], ecx
101
        add     dword[LOOPBACK_DEVICE.bytes_rx], ecx
94
        adc     dword[LOOPBACK_DEVICE.bytes_rx + 4], 0
102
        adc     dword[LOOPBACK_DEVICE.bytes_rx + 4], 0
95
        add     dword[LOOPBACK_DEVICE.bytes_tx], ecx
103
        add     dword[LOOPBACK_DEVICE.bytes_tx], ecx
96
        adc     dword[LOOPBACK_DEVICE.bytes_tx + 4], 0
104
        adc     dword[LOOPBACK_DEVICE.bytes_tx + 4], 0
97
 
105
 
98
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: ptr=%x size=%u\n", eax, ecx
106
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: ptr=%x size=%u\n", eax, ecx
99
 
107
 
100
; Reverse buffptr and returnaddr on stack
108
; Reverse buffptr and returnaddr on stack
101
        pop     edx edi
109
        pop     edx edi
102
        push    edx .done edi
110
        push    edx .done edi
103
 
111
 
104
; Set registers for protocol handlers
112
; Set registers for protocol handlers
105
        lea     edx, [eax + NET_BUFF.data]
113
        lea     edx, [eax + NET_BUFF.data]
106
        mov     ebx, [eax + NET_BUFF.device]
114
        mov     ebx, [eax + NET_BUFF.device]
107
        mov     eax, [eax + NET_BUFF.type]
115
        mov     eax, [eax + NET_BUFF.type]
108
 
116
 
109
; Place protocol handlers here
117
; Place protocol handlers here
110
        cmp     eax, AF_INET4
118
        cmp     eax, AF_INET4
111
        je      ipv4_input
119
        je      ipv4_input
112
 
120
 
113
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", eax
121
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", eax
114
 
122
 
115
  .dump:
123
  .dump:
116
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
124
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
117
        call    net_buff_free
125
        call    net_buff_free
118
 
126
 
119
        or      eax, -1
127
        or      eax, -1
120
        ret
128
        ret
121
 
129
 
122
  .done:
130
  .done:
123
        xor     eax, eax
131
        xor     eax, eax
124
        ret
132
        ret
125
 
133
 
126
 
134
 
127
;-----------------------------------------------------------------;
135
;-----------------------------------------------------------------;
128
;                                                                 ;
136
;                                                                 ;
129
; loop_output                                                     ;
137
; loop_output                                                     ;
130
;                                                                 ;
138
;                                                                 ;
131
;  IN:  ecx = packet size                                         ;
139
;  IN:  ecx = packet size                                         ;
132
;       edi = address family                                      ;
140
;       edi = address family                                      ;
133
;                                                                 ;
141
;                                                                 ;
134
; OUT:  eax = start of net frame / 0 on error                     ;
142
; OUT:  eax = start of net frame / 0 on error                     ;
135
;       ebx = to device structure                                 ;
143
;       ebx = to device structure                                 ;
136
;       ecx = unchanged (packet size of embedded data)            ;
144
;       ecx = unchanged (packet size of embedded data)            ;
137
;       edi = start of payload                                    ;
145
;       edi = start of payload                                    ;
138
;                                                                 ;
146
;                                                                 ;
139
;-----------------------------------------------------------------;
147
;-----------------------------------------------------------------;
140
align 4
148
align 4
141
loop_output:
149
loop_output:
142
 
150
 
143
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
151
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
144
 
152
 
145
        cmp     ecx, [LOOPBACK_DEVICE.mtu]
153
        cmp     ecx, [LOOPBACK_DEVICE.mtu]
146
        ja      .too_large
154
        ja      .too_large
147
 
155
 
148
        push    ecx edi
156
        push    ecx edi
149
        add     ecx, NET_BUFF.data
157
        add     ecx, NET_BUFF.data
150
        stdcall net_buff_alloc, ecx
158
        stdcall net_buff_alloc, ecx
151
        test    eax, eax
159
        test    eax, eax
152
        jz      .out_of_ram
160
        jz      .out_of_ram
153
 
161
 
154
        pop     edi
162
        pop     edi
155
        mov     [eax + NET_BUFF.type], edi
163
        mov     [eax + NET_BUFF.type], edi
156
        mov     ebx, LOOPBACK_DEVICE
164
        mov     ebx, LOOPBACK_DEVICE
157
        mov     [eax + NET_BUFF.device], ebx
165
        mov     [eax + NET_BUFF.device], ebx
158
        pop     ecx
166
        pop     ecx
159
        mov     [eax + NET_BUFF.length], ecx
167
        mov     [eax + NET_BUFF.length], ecx
160
        lea     edi, [eax + NET_BUFF.data]
168
        lea     edi, [eax + NET_BUFF.data]
161
 
169
 
162
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, ecx
170
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, ecx
163
        ret
171
        ret
164
 
172
 
165
  .too_large:
173
  .too_large:
166
        DEBUGF  DEBUG_NETWORK_ERROR, "LOOP_output: packet is too large\n"
174
        DEBUGF  DEBUG_NETWORK_ERROR, "LOOP_output: packet is too large\n"
167
        xor     eax, eax
175
        xor     eax, eax
168
        ret
176
        ret
169
 
177
 
170
  .out_of_ram:
178
  .out_of_ram:
171
        DEBUGF  DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n"
179
        DEBUGF  DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n"
172
        add     esp, 4+4
180
        add     esp, 4+4
173
        xor     eax, eax
181
        xor     eax, eax
174
        ret
182
        ret