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