Rev 4388 | Rev 5363 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4388 | Rev 4850 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. 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 ;; |
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: 2891 $ |
17 | $Revision: 4850 $ |
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 [IP_LIST], 127 + 1 shl 24 |
58 | mov [SUBNET_LIST], 255 |
58 | mov [SUBNET_LIST], 255 |
59 | mov [BROADCAST_LIST], 0xffffff00 + 127 |
59 | mov [BROADCAST_LIST], 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 | ; [esp+8] = size of buffer |
69 | ; [esp+8] = size of buffer |
70 | ; |
70 | ; |
71 | ; OUT: / |
71 | ; OUT: / |
72 | ; |
72 | ; |
73 | ;----------------------------------------------------------------- |
73 | ;----------------------------------------------------------------- |
74 | align 4 |
74 | align 4 |
75 | LOOP_input: |
75 | LOOP_input: |
76 | pop ebx |
76 | pop ebx |
77 | pop eax |
77 | pop eax |
78 | pop ecx |
78 | pop ecx |
79 | 79 | ||
80 | push ebx |
80 | push ebx |
81 | push ecx |
81 | push ecx |
82 | push eax |
82 | push eax |
83 | 83 | ||
84 | inc [LOOPBACK_DEVICE.packets_rx] |
84 | inc [LOOPBACK_DEVICE.packets_rx] |
85 | add dword[LOOPBACK_DEVICE.bytes_rx], ecx |
85 | add dword[LOOPBACK_DEVICE.bytes_rx], ecx |
86 | adc dword[LOOPBACK_DEVICE.bytes_rx + 4], 0 |
86 | adc dword[LOOPBACK_DEVICE.bytes_rx + 4], 0 |
87 | 87 | ||
88 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx |
88 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx |
89 | lea edx, [eax + 4] |
89 | lea edx, [eax + 4] |
90 | mov eax, dword[eax] |
90 | mov eax, dword[eax] |
91 | mov ebx, LOOPBACK_DEVICE |
91 | mov ebx, LOOPBACK_DEVICE |
92 | 92 | ||
93 | cmp eax, AF_INET4 |
93 | cmp eax, AF_INET4 |
94 | je IPv4_input |
94 | je IPv4_input |
95 | 95 | ||
96 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax |
96 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax |
97 | 97 | ||
98 | .dump: |
98 | .dump: |
99 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n" |
99 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n" |
100 | call NET_packet_free |
100 | call NET_packet_free |
101 | add esp, 4 |
101 | add esp, 4 |
102 | ret |
102 | ret |
103 | 103 | ||
104 | ;----------------------------------------------------------------- |
104 | ;----------------------------------------------------------------- |
105 | ; |
105 | ; |
106 | ; LOOP_output |
106 | ; LOOP_output |
107 | ; |
107 | ; |
108 | ; IN: |
108 | ; IN: |
109 | ; ecx = packet size |
109 | ; ecx = packet size |
110 | ; edi = address family |
110 | ; edi = address family |
111 | ; |
111 | ; |
112 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
112 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
113 | ; eax = buffer start |
113 | ; eax = buffer start |
114 | ; ebx = to device structure |
114 | ; ebx = to device structure |
115 | ; ecx = unchanged (packet size of embedded data) |
115 | ; ecx = unchanged (packet size of embedded data) |
116 | ; edx = size of complete buffer |
116 | ; edx = size of complete buffer |
117 | ; |
117 | ; |
118 | ;----------------------------------------------------------------- |
118 | ;----------------------------------------------------------------- |
119 | align 4 |
119 | align 4 |
120 | LOOP_output: |
120 | LOOP_output: |
121 | 121 | ||
122 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n" |
122 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n" |
123 | 123 | ||
124 | push ecx |
124 | push ecx |
125 | push edi |
125 | push edi |
126 | 126 | ||
127 | add ecx, 4 |
127 | add ecx, 4 |
128 | cmp ecx, [LOOPBACK_DEVICE.mtu] |
128 | cmp ecx, [LOOPBACK_DEVICE.mtu] |
129 | ja .out_of_ram |
129 | ja .out_of_ram |
130 | stdcall kernel_alloc, ecx |
130 | stdcall kernel_alloc, ecx |
131 | test eax, eax |
131 | test eax, eax |
132 | jz .out_of_ram |
132 | jz .out_of_ram |
133 | mov edi, eax |
133 | mov edi, eax |
134 | pop eax |
134 | pop eax |
135 | stosd |
135 | stosd |
136 | 136 | ||
137 | lea eax, [edi - 4] ; Set eax to buffer start |
137 | lea eax, [edi - 4] ; Set eax to buffer start |
138 | pop ecx |
138 | pop ecx |
139 | lea edx, [ecx + 4] ; Set edx to complete buffer size |
139 | lea edx, [ecx + 4] ; Set edx to complete buffer size |
140 | mov ebx, LOOPBACK_DEVICE |
140 | mov ebx, LOOPBACK_DEVICE |
141 | 141 | ||
142 | inc [LOOPBACK_DEVICE.packets_tx] |
142 | inc [LOOPBACK_DEVICE.packets_tx] |
143 | add dword[LOOPBACK_DEVICE.bytes_tx], ecx |
143 | add dword[LOOPBACK_DEVICE.bytes_tx], ecx |
144 | adc dword[LOOPBACK_DEVICE.bytes_tx + 4], 0 |
144 | adc dword[LOOPBACK_DEVICE.bytes_tx + 4], 0 |
145 | 145 | ||
146 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx |
146 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx |
147 | ret |
147 | ret |
148 | 148 | ||
149 | .out_of_ram: |
149 | .out_of_ram: |
150 | DEBUGF DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n" |
150 | DEBUGF DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n" |
151 | add esp, 4+4 |
151 | add esp, 4+4 |
152 | xor edi, edi |
152 | xor edi, edi |
153 | ret |
153 | ret |