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