Rev 3555 | Rev 3626 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3555 | Rev 3589 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2010. 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: 2891 $ |
18 | 18 | ||
19 | iglobal |
19 | iglobal |
20 | 20 | ||
21 | LOOPBACK_DEVICE: |
21 | LOOPBACK_DEVICE: |
22 | .type dd NET_TYPE_LOOPBACK |
22 | .type dd NET_TYPE_LOOPBACK |
23 | .mtu dd 4096 |
23 | .mtu dd 4096 |
24 | .name dd .namestr |
24 | .name dd .namestr |
25 | 25 | ||
26 | .unload dd .dummy_fn |
26 | .unload dd .dummy_fn |
27 | .reset dd .dummy_fn |
27 | .reset dd .dummy_fn |
28 | .transmit dd LOOP_input |
28 | .transmit dd LOOP_input |
29 | 29 | ||
30 | .bytes_tx dq 0 |
30 | .bytes_tx dq 0 |
31 | .bytes_rx dq 0 |
31 | .bytes_rx dq 0 |
32 | .packets_tx dd 0 |
32 | .packets_tx dd 0 |
33 | .packets_rx dd 0 |
33 | .packets_rx dd 0 |
34 | 34 | ||
35 | .namestr db 'loopback', 0 |
35 | .namestr db 'loopback', 0 |
36 | 36 | ||
37 | .dummy_fn: |
37 | .dummy_fn: |
38 | ret |
38 | ret |
39 | 39 | ||
40 | endg |
40 | endg |
41 | 41 | ||
42 | ;----------------------------------------------------------------- |
42 | ;----------------------------------------------------------------- |
43 | ; |
43 | ; |
44 | ; LOOP_input |
44 | ; LOOP_input |
45 | ; |
45 | ; |
46 | ; IN: [esp+4] = Pointer to buffer |
46 | ; IN: [esp+4] = Pointer to buffer |
47 | ; [esp+8] = size of buffer |
47 | ; [esp+8] = size of buffer |
48 | ; |
48 | ; |
49 | ; OUT: / |
49 | ; OUT: / |
50 | ; |
50 | ; |
51 | ;----------------------------------------------------------------- |
51 | ;----------------------------------------------------------------- |
52 | align 4 |
52 | align 4 |
53 | LOOP_input: |
53 | LOOP_input: |
54 | pop ebx |
54 | pop ebx |
55 | pop eax |
55 | pop eax |
56 | pop ecx |
56 | pop ecx |
57 | 57 | ||
58 | push ebx |
58 | push ebx |
59 | push ecx |
59 | push ecx |
60 | push eax |
60 | push eax |
61 | 61 | ||
62 | DEBUGF 1,"LOOP_input: size=%u\n", ecx |
62 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx |
63 | lea edx, [eax + 2] |
63 | lea edx, [eax + 2] |
64 | mov ax, word[eax] |
64 | mov ax, word[eax] |
65 | mov ebx, LOOPBACK_DEVICE |
65 | mov ebx, LOOPBACK_DEVICE |
66 | 66 | ||
67 | cmp ax, ETHER_IPv4 |
67 | cmp ax, ETHER_IPv4 |
68 | je IPv4_input |
68 | je IPv4_input |
69 | 69 | ||
70 | DEBUGF 2,"LOOP_input: Unknown packet type=%x\n", ax |
70 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax |
71 | 71 | ||
72 | .dump: |
72 | .dump: |
73 | DEBUGF 2,"LOOP_input: dumping\n" |
73 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n" |
74 | call kernel_free |
74 | call kernel_free |
75 | add esp, 4 |
75 | add esp, 4 |
76 | ret |
76 | ret |
77 | 77 | ||
78 | ;----------------------------------------------------------------- |
78 | ;----------------------------------------------------------------- |
79 | ; |
79 | ; |
80 | ; LOOP_output |
80 | ; LOOP_output |
81 | ; |
81 | ; |
82 | ; IN: |
82 | ; IN: |
83 | ; ecx = packet size |
83 | ; ecx = packet size |
84 | ; di = protocol |
84 | ; di = protocol |
85 | ; |
85 | ; |
86 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
86 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
87 | ; eax = buffer start |
87 | ; eax = buffer start |
88 | ; ebx = to device structure |
88 | ; ebx = to device structure |
89 | ; ecx = unchanged (packet size of embedded data) |
89 | ; ecx = unchanged (packet size of embedded data) |
90 | ; edx = size of complete buffer |
90 | ; edx = size of complete buffer |
91 | ; |
91 | ; |
92 | ;----------------------------------------------------------------- |
92 | ;----------------------------------------------------------------- |
93 | align 4 |
93 | align 4 |
94 | LOOP_output: |
94 | LOOP_output: |
95 | 95 | ||
96 | DEBUGF 1,"LOOP_output\n" |
96 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n" |
97 | 97 | ||
98 | push ecx |
98 | push ecx |
99 | push di |
99 | push di |
100 | 100 | ||
101 | add ecx, 2 |
101 | add ecx, 2 |
102 | cmp ecx, [LOOPBACK_DEVICE.mtu] |
102 | cmp ecx, [LOOPBACK_DEVICE.mtu] |
103 | ja .out_of_ram |
103 | ja .out_of_ram |
104 | stdcall kernel_alloc, ecx |
104 | stdcall kernel_alloc, ecx |
105 | test eax, eax |
105 | test eax, eax |
106 | jz .out_of_ram |
106 | jz .out_of_ram |
107 | mov edi, eax |
107 | mov edi, eax |
108 | pop ax |
108 | pop ax |
109 | stosw |
109 | stosw |
110 | 110 | ||
111 | lea eax, [edi - 2] ; Set eax to buffer start |
111 | lea eax, [edi - 2] ; Set eax to buffer start |
112 | pop ecx |
112 | pop ecx |
113 | lea edx, [ecx + 2] ; Set edx to complete buffer size |
113 | lea edx, [ecx + 2] ; Set edx to complete buffer size |
114 | mov ebx, LOOPBACK_DEVICE |
114 | mov ebx, LOOPBACK_DEVICE |
115 | 115 | ||
116 | .done: |
116 | .done: |
117 | DEBUGF 2,"LOOP_output: ptr=%x size=%u\n", eax, edx |
117 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx |
118 | ret |
118 | ret |
119 | 119 | ||
120 | .out_of_ram: |
120 | .out_of_ram: |
121 | DEBUGF 2,"LOOP_output: failed\n" |
121 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: failed\n" |
122 | add esp, 2+4 |
122 | add esp, 2+4 |
123 | sub edi, edi |
123 | sub edi, edi |
124 | ret |
124 | ret |