Subversion Repositories Kolibri OS

Rev

Rev 6011 | Rev 9054 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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