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