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