Rev 2931 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2614 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2931 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2012. All rights reserved. ;; |
2614 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
2931 | hidnplayr | 6 | ;; PPPoE.INC ;; |
2614 | hidnplayr | 7 | ;; ;; |
2931 | hidnplayr | 8 | ;; Part of the tcp/ip network stack for KolibriOS ;; |
9 | ;; ;; |
||
10 | ;; Written by hidnplayr@kolibrios.org ;; |
||
11 | ;; ;; |
||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
13 | ;; Version 2, June 1991 ;; |
||
14 | ;; ;; |
||
2614 | hidnplayr | 15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
16 | |||
2931 | hidnplayr | 17 | struct PPPoE_frame |
2614 | hidnplayr | 18 | |
19 | VersionAndType db ? |
||
20 | Code db ? |
||
21 | SessionID dw ? |
||
22 | Length dw ? ; Length of payload, does NOT include the length PPPoE header. |
||
2931 | hidnplayr | 23 | Payload rb 0 |
2614 | hidnplayr | 24 | |
25 | ends |
||
26 | |||
27 | |||
2931 | hidnplayr | 28 | uglobal |
2614 | hidnplayr | 29 | |
2931 | hidnplayr | 30 | PPPoE_SID dw ? |
31 | PPPoE_MAC dp ? |
||
2614 | hidnplayr | 32 | |
33 | endg |
||
34 | |||
35 | |||
2931 | hidnplayr | 36 | ;----------------------------------------------------------------- |
37 | ; |
||
38 | ; PPPoE discovery input |
||
39 | ; |
||
40 | ; Handler of received Ethernet packet with type = Discovery |
||
41 | ; |
||
42 | ; |
||
43 | ; IN: Pointer to buffer in [esp] |
||
44 | ; size of buffer in [esp+4] |
||
45 | ; pointer to device struct in ebx |
||
46 | ; pointer to PPP header in edx |
||
47 | ; size of PPP packet in ecx |
||
48 | ; OUT: / |
||
49 | ; |
||
50 | ;----------------------------------------------------------------- |
||
2614 | hidnplayr | 51 | align 4 |
2931 | hidnplayr | 52 | PPPoE_discovery_input: |
2614 | hidnplayr | 53 | |
2931 | hidnplayr | 54 | DEBUGF 2,"PPPoE_discovery_input\n" |
2614 | hidnplayr | 55 | |
2931 | hidnplayr | 56 | ; First, find open PPPoE socket |
2614 | hidnplayr | 57 | |
2931 | hidnplayr | 58 | mov eax, net_sockets |
2614 | hidnplayr | 59 | |
2931 | hidnplayr | 60 | .next_socket: |
61 | mov eax, [eax + SOCKET.NextPtr] |
||
62 | or eax, eax |
||
63 | jz .dump |
||
2614 | hidnplayr | 64 | |
2931 | hidnplayr | 65 | cmp [eax + SOCKET.Domain], AF_PPP |
66 | jne .next_socket |
||
2614 | hidnplayr | 67 | |
2931 | hidnplayr | 68 | cmp [eax + SOCKET.Protocol], PPP_PROTO_ETHERNET |
69 | jne .next_socket |
||
2614 | hidnplayr | 70 | |
2931 | hidnplayr | 71 | ; Now, send it to the this socket |
2614 | hidnplayr | 72 | |
2931 | hidnplayr | 73 | mov ecx, [esp + 4] |
74 | mov esi, [esp] |
||
2614 | hidnplayr | 75 | |
2931 | hidnplayr | 76 | jmp SOCKET_input |
2614 | hidnplayr | 77 | |
2931 | hidnplayr | 78 | .dump: |
79 | DEBUGF 1,'PPPoE_discovery_input: dumping\n' |
||
80 | call kernel_free |
||
81 | add esp, 4 |
||
2614 | hidnplayr | 82 | ret |
83 | |||
84 | |||
2931 | hidnplayr | 85 | ;-------------------------------------- |
86 | ; |
||
87 | ; Send discovery packet |
||
88 | ; |
||
2950 | hidnplayr | 89 | ; IN: eax = socket pointer |
90 | ; ecx = number of bytes to send |
||
91 | ; esi = pointer to data |
||
2931 | hidnplayr | 92 | ; |
93 | ;-------------------------------------- |
||
2950 | hidnplayr | 94 | |
2614 | hidnplayr | 95 | align 4 |
2931 | hidnplayr | 96 | PPPoE_discovery_output: |
2614 | hidnplayr | 97 | |
2950 | hidnplayr | 98 | DEBUGF 2,"PPPoE_discovery_output: socket=%x buffer=%x size=%d\n", eax, esi, ecx |
99 | |||
2614 | hidnplayr | 100 | ; RFC2516: An entire PADI packet (including the PPPoE header) MUST NOT |
101 | ; exceed 1484 octets. |
||
2931 | hidnplayr | 102 | cmp ecx, 1484 + 14 |
2614 | hidnplayr | 103 | ja .bad |
104 | |||
2931 | hidnplayr | 105 | ; Check that device exists and is ethernet device |
2950 | hidnplayr | 106 | mov ebx, [eax + SOCKET.device] |
107 | |||
2931 | hidnplayr | 108 | cmp ebx, MAX_NET_DEVICES |
109 | ja .bad |
||
2614 | hidnplayr | 110 | |
2931 | hidnplayr | 111 | mov ebx, [NET_DRV_LIST + 4*ebx] |
112 | test ebx, ebx |
||
113 | jz .bad |
||
2614 | hidnplayr | 114 | |
2931 | hidnplayr | 115 | cmp [ebx + NET_DEVICE.type], NET_TYPE_ETH |
116 | jne .bad |
||
2614 | hidnplayr | 117 | |
2950 | hidnplayr | 118 | DEBUGF 2,"PPPoE_discovery_output: device=%x\n", ebx |
119 | |||
2931 | hidnplayr | 120 | ; Create packet. |
2950 | hidnplayr | 121 | push ecx esi |
2931 | hidnplayr | 122 | stdcall kernel_alloc, 1500 |
2950 | hidnplayr | 123 | pop esi ecx |
2931 | hidnplayr | 124 | test eax, eax |
125 | jz .bad |
||
2614 | hidnplayr | 126 | |
2950 | hidnplayr | 127 | mov edx, ecx |
2931 | hidnplayr | 128 | mov edi, eax |
129 | rep movsb |
||
2614 | hidnplayr | 130 | |
2950 | hidnplayr | 131 | cmp edx, 60 ; Min ETH size |
132 | ja @f |
||
133 | mov edx, 60 |
||
134 | @@: |
||
135 | |||
136 | push edx eax ; size and packet ptr for driver send proc |
||
137 | |||
2931 | hidnplayr | 138 | ; Overwrite source MAC and protocol type |
139 | lea edi, [eax + ETH_header.SrcMAC] |
||
140 | lea esi, [ebx + ETH_DEVICE.mac] |
||
141 | movsd |
||
142 | movsw |
||
143 | mov ax, ETHER_PPP_DISCOVERY |
||
144 | stosw |
||
2614 | hidnplayr | 145 | |
2931 | hidnplayr | 146 | ; And send the packet |
147 | call [ebx + NET_DEVICE.transmit] |
||
2614 | hidnplayr | 148 | |
149 | xor eax, eax |
||
150 | ret |
||
151 | |||
152 | .bad: |
||
153 | or eax, -1 |
||
154 | ret |
||
155 | |||
156 | |||
2931 | hidnplayr | 157 | ;----------------------------------------------------------------- |
158 | ; |
||
159 | ; PPPoE session input |
||
160 | ; |
||
161 | ; Handler of received Ethernet packet with type = Session |
||
162 | ; |
||
163 | ; |
||
164 | ; IN: Pointer to buffer in [esp] |
||
165 | ; size of buffer in [esp+4] |
||
166 | ; pointer to device struct in ebx |
||
167 | ; pointer to PPP header in edx |
||
168 | ; size of PPP packet in ecx |
||
169 | ; OUT: / |
||
170 | ; |
||
171 | ;----------------------------------------------------------------- |
||
2614 | hidnplayr | 172 | align 4 |
2931 | hidnplayr | 173 | PPPoE_session_input: |
2614 | hidnplayr | 174 | |
2931 | hidnplayr | 175 | cmp [edx + PPPoE_frame.VersionAndType], 0x11 |
176 | jne .dump |
||
2614 | hidnplayr | 177 | |
2931 | hidnplayr | 178 | cmp [edx + PPPoE_frame.Code], 0x00 |
179 | jne .dump |
||
2614 | hidnplayr | 180 | |
2931 | hidnplayr | 181 | movzx ecx, [edx + PPPoE_frame.Length] |
182 | xchg cl, ch |
||
2614 | hidnplayr | 183 | |
2931 | hidnplayr | 184 | mov ax, [edx + PPPoE_frame.SessionID] |
185 | DEBUGF 2,"PPPoE_input: session ID=%x, length=%u\n", ax, cx |
||
186 | cmp ax, [PPPoE_SID] |
||
187 | jne .dump |
||
188 | |||
189 | mov ax, word [edx + PPPoE_frame.Payload] |
||
190 | add edx, PPPoE_frame.Payload + 2 |
||
191 | |||
192 | cmp ax, PPP_IPv4 |
||
193 | je IPv4_input |
||
194 | |||
195 | DEBUGF 2,"PPPoE_input: Unknown protocol=%x\n", ax |
||
196 | |||
197 | .dump: |
||
198 | DEBUGF 2,"PPPoE_input: dumping\n" |
||
199 | call kernel_free |
||
200 | add esp, 4 |
||
2614 | hidnplayr | 201 | ret |
202 | |||
203 | |||
204 | |||
2931 | hidnplayr | 205 | |
2614 | hidnplayr | 206 | ;----------------------------------------------------------------- |
207 | ; |
||
2931 | hidnplayr | 208 | ; PPPoE_output |
2614 | hidnplayr | 209 | ; |
2931 | hidnplayr | 210 | ; IN: |
211 | ; ebx = device ptr |
||
212 | ; ecx = packet size |
||
2614 | hidnplayr | 213 | ; |
2931 | hidnplayr | 214 | ; di = protocol |
2614 | hidnplayr | 215 | ; |
2931 | hidnplayr | 216 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
217 | ; eax = buffer start |
||
218 | ; ebx = to device structure |
||
219 | ; ecx = unchanged (packet size of embedded data) |
||
220 | ; edx = size of complete buffer |
||
2614 | hidnplayr | 221 | ; |
222 | ;----------------------------------------------------------------- |
||
223 | align 4 |
||
2931 | hidnplayr | 224 | PPPoE_output: |
2614 | hidnplayr | 225 | |
2931 | hidnplayr | 226 | DEBUGF 1,"PPPoE_output: size=%u device=%x\n", ecx, ebx |
2614 | hidnplayr | 227 | |
2931 | hidnplayr | 228 | pushw di |
229 | pushw [PPPoE_SID] |
||
2614 | hidnplayr | 230 | |
2931 | hidnplayr | 231 | lea eax, [ebx + ETH_DEVICE.mac] |
232 | lea edx, [PPPoE_MAC] |
||
233 | add ecx, PPPoE_frame.Payload + 2 |
||
234 | mov di, ETHER_PPP_SESSION |
||
235 | call ETH_output |
||
236 | jz .eth_error |
||
2614 | hidnplayr | 237 | |
2931 | hidnplayr | 238 | mov [edi + PPPoE_frame.VersionAndType], 0x11 |
239 | mov [edi + PPPoE_frame.Code], 0 |
||
240 | popw [edi + PPPoE_frame.SessionID] |
||
241 | xchg cl, ch |
||
242 | mov [edi + PPPoE_frame.Length], cx |
||
243 | xchg cl, ch |
||
244 | pop word [edi + PPPoE_frame.Payload] |
||
2614 | hidnplayr | 245 | |
2931 | hidnplayr | 246 | sub ecx, PPPoE_frame.Payload + 2 |
247 | add edi, PPPoE_frame.Payload + 2 |
||
2614 | hidnplayr | 248 | |
2931 | hidnplayr | 249 | DEBUGF 1,"PPPoE_output: success!\n" |
250 | ret |
||
2614 | hidnplayr | 251 | |
252 | |||
2931 | hidnplayr | 253 | .eth_error: |
254 | add esp, 4 |
||
255 | xor edi, edi |
||
2614 | hidnplayr | 256 | |
257 | ret |
||
258 | |||
259 | |||
260 | |||
2931 | hidnplayr | 261 | align 4 |
262 | PPPoE_start_connection: |
||
2614 | hidnplayr | 263 | |
2931 | hidnplayr | 264 | cmp [PPPoE_SID], 0 |
265 | je .fail |
||
266 | |||
267 | mov [PPPoE_SID], cx |
||
268 | mov dword [PPPoE_MAC], edx |
||
269 | mov word [PPPoE_MAC + 4], si |
||
270 | |||
271 | xor eax, eax |
||
272 | ret |
||
273 | |||
274 | .fail: |
||
275 | or eax, -1 |
||
276 | ret |
||
277 | |||
278 | |||
279 | align 4 |
||
280 | PPPoE_stop_connection: |
||
281 | |||
282 | xor eax, eax |
||
283 | mov [PPPoE_SID], ax |
||
284 | mov dword [PPPoE_MAC], eax |
||
285 | mov word [PPPoE_MAC + 4], ax |
||
286 | |||
287 | ret |
||
288 | |||
289 | |||
2614 | hidnplayr | 290 | ;--------------------------------------------------------------------------- |
291 | ; |
||
292 | ; PPPoE API |
||
293 | ; |
||
294 | ; This function is called by system function 75 |
||
295 | ; |
||
296 | ; IN: subfunction number in bl |
||
297 | ; device number in bh |
||
298 | ; ecx, edx, .. depends on subfunction |
||
299 | ; |
||
300 | ; OUT: |
||
301 | ; |
||
302 | ;--------------------------------------------------------------------------- |
||
303 | align 4 |
||
304 | PPPoE_api: |
||
305 | |||
306 | movzx eax, bh |
||
307 | shl eax, 2 |
||
308 | |||
309 | and ebx, 0xff |
||
310 | cmp ebx, .number |
||
311 | ja .error |
||
312 | jmp dword [.table + 4*ebx] |
||
313 | |||
314 | .table: |
||
2931 | hidnplayr | 315 | dd PPPoE_start_connection ; 0 |
316 | dd PPPoE_stop_connection ; 1 |
||
2614 | hidnplayr | 317 | .number = ($ - .table) / 4 - 1 |
318 | |||
319 | .error: |
||
320 | mov eax, -1 |
||
321 | ret |