Rev 3589 | Rev 3725 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3555 | Serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3626 | Serge | 3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
3555 | Serge | 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 | |||
3626 | Serge | 23 | .device_type dd NET_DEVICE_LOOPBACK |
24 | .mtu dd 4096 |
||
25 | .name dd .namestr |
||
3555 | Serge | 26 | |
3626 | Serge | 27 | .unload dd .dummy_fn |
28 | .reset dd .dummy_fn |
||
29 | .transmit dd LOOP_input |
||
3555 | Serge | 30 | |
3626 | Serge | 31 | .bytes_tx dq 0 |
32 | .bytes_rx dq 0 |
||
33 | .packets_tx dd 0 |
||
34 | .packets_rx dd 0 |
||
3555 | Serge | 35 | |
3626 | Serge | 36 | .link_state dd -1 |
37 | .hwacc dd 0 |
||
38 | |||
39 | .namestr db 'loopback', 0 |
||
40 | |||
3555 | Serge | 41 | .dummy_fn: |
42 | ret |
||
43 | |||
44 | endg |
||
45 | |||
3626 | Serge | 46 | |
47 | macro LOOP_init { |
||
48 | local .fail |
||
49 | |||
50 | mov ebx, LOOPBACK_DEVICE |
||
51 | call NET_add_device |
||
52 | |||
53 | cmp eax, -1 |
||
54 | je .fail |
||
55 | |||
56 | mov [IP_LIST], 127 + 1 shl 24 |
||
57 | mov [SUBNET_LIST], 255 |
||
58 | mov [BROADCAST_LIST], 0xffffff00 + 127 |
||
59 | |||
60 | .fail: |
||
61 | } |
||
62 | |||
3555 | Serge | 63 | ;----------------------------------------------------------------- |
64 | ; |
||
65 | ; LOOP_input |
||
66 | ; |
||
3626 | Serge | 67 | ; IN: [esp+4] = Pointer to buffer |
3555 | Serge | 68 | ; [esp+8] = size of buffer |
69 | ; |
||
70 | ; OUT: / |
||
71 | ; |
||
72 | ;----------------------------------------------------------------- |
||
73 | align 4 |
||
74 | LOOP_input: |
||
75 | pop ebx |
||
76 | pop eax |
||
77 | pop ecx |
||
78 | |||
79 | push ebx |
||
80 | push ecx |
||
81 | push eax |
||
82 | |||
3626 | Serge | 83 | inc [LOOPBACK_DEVICE.packets_rx] |
84 | add dword[LOOPBACK_DEVICE.bytes_rx], ecx |
||
85 | adc dword[LOOPBACK_DEVICE.bytes_rx + 4], 0 |
||
86 | |||
3589 | Serge | 87 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx |
3626 | Serge | 88 | lea edx, [eax + 4] |
89 | mov eax, dword[eax] |
||
3555 | Serge | 90 | mov ebx, LOOPBACK_DEVICE |
91 | |||
3626 | Serge | 92 | cmp eax, AF_INET4 |
3555 | Serge | 93 | je IPv4_input |
94 | |||
3589 | Serge | 95 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax |
3555 | Serge | 96 | |
97 | .dump: |
||
3589 | Serge | 98 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n" |
3555 | Serge | 99 | call kernel_free |
100 | add esp, 4 |
||
101 | ret |
||
102 | |||
103 | ;----------------------------------------------------------------- |
||
104 | ; |
||
105 | ; LOOP_output |
||
106 | ; |
||
107 | ; IN: |
||
3626 | Serge | 108 | ; ecx = packet size |
109 | ; edi = address family |
||
3555 | Serge | 110 | ; |
3626 | Serge | 111 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
112 | ; eax = buffer start |
||
113 | ; ebx = to device structure |
||
114 | ; ecx = unchanged (packet size of embedded data) |
||
115 | ; edx = size of complete buffer |
||
3555 | Serge | 116 | ; |
117 | ;----------------------------------------------------------------- |
||
118 | align 4 |
||
119 | LOOP_output: |
||
120 | |||
3589 | Serge | 121 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n" |
3555 | Serge | 122 | |
123 | push ecx |
||
3626 | Serge | 124 | push edi |
3555 | Serge | 125 | |
3626 | Serge | 126 | add ecx, 4 |
3555 | Serge | 127 | cmp ecx, [LOOPBACK_DEVICE.mtu] |
128 | ja .out_of_ram |
||
129 | stdcall kernel_alloc, ecx |
||
130 | test eax, eax |
||
131 | jz .out_of_ram |
||
132 | mov edi, eax |
||
3626 | Serge | 133 | pop eax |
134 | stosd |
||
3555 | Serge | 135 | |
3626 | Serge | 136 | lea eax, [edi - 4] ; Set eax to buffer start |
3555 | Serge | 137 | pop ecx |
3626 | Serge | 138 | lea edx, [ecx + 4] ; Set edx to complete buffer size |
3555 | Serge | 139 | mov ebx, LOOPBACK_DEVICE |
140 | |||
3626 | Serge | 141 | inc [LOOPBACK_DEVICE.packets_tx] |
142 | add dword[LOOPBACK_DEVICE.bytes_tx], ecx |
||
143 | adc dword[LOOPBACK_DEVICE.bytes_tx + 4], 0 |
||
144 | |||
3589 | Serge | 145 | DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx |
3555 | Serge | 146 | ret |
147 | |||
148 | .out_of_ram: |
||
3626 | Serge | 149 | DEBUGF DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n" |
150 | add esp, 4+4 |
||
151 | xor edi, edi |
||
3555 | Serge | 152 | ret |
153 |