2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-01-08 21:10:22 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2012-2015. All rights reserved. ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; PPPoE.INC ;;
|
|
|
|
;; ;;
|
|
|
|
;; Part of the tcp/ip network stack for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-04-17 23:19:45 +02:00
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
struct PPPoE_frame
|
|
|
|
VersionAndType db ?
|
|
|
|
Code db ?
|
|
|
|
SessionID dw ?
|
|
|
|
Length dw ? ; Length of payload, does NOT include the length PPPoE header.
|
|
|
|
Payload rb 0
|
|
|
|
ends
|
|
|
|
|
|
|
|
uglobal
|
2013-06-24 13:39:05 +02:00
|
|
|
align 4
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
PPPoE_SID dw ?
|
|
|
|
PPPoE_MAC dp ?
|
2013-06-24 13:39:05 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
endg
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; pppoe_init: Reset all pppoe variables ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
macro pppoe_init {
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
call pppoe_stop_connection
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; pppoe_discovery_input ;
|
|
|
|
; ;
|
|
|
|
; IN: [esp] = ptr to buffer ;
|
|
|
|
; [esp+4] = size of buffer ;
|
|
|
|
; ebx = ptr to device struct ;
|
|
|
|
; ecx = size of PPP packet ;
|
|
|
|
; edx = ptr to PPP header ;
|
|
|
|
; ;
|
|
|
|
; OUT: / ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
2013-05-28 19:34:26 +02:00
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
pppoe_discovery_input:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_input\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; First, find open PPPoE socket
|
|
|
|
|
2013-06-12 12:21:41 +02:00
|
|
|
pusha
|
|
|
|
mov ecx, socket_mutex
|
|
|
|
call mutex_lock
|
|
|
|
popa
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
mov eax, net_sockets
|
|
|
|
|
|
|
|
.next_socket:
|
|
|
|
mov eax, [eax + SOCKET.NextPtr]
|
|
|
|
or eax, eax
|
|
|
|
jz .dump
|
|
|
|
|
|
|
|
cmp [eax + SOCKET.Domain], AF_PPP
|
|
|
|
jne .next_socket
|
|
|
|
|
|
|
|
cmp [eax + SOCKET.Protocol], PPP_PROTO_ETHERNET
|
|
|
|
jne .next_socket
|
|
|
|
|
2013-06-12 12:21:41 +02:00
|
|
|
pusha
|
|
|
|
mov ecx, socket_mutex
|
|
|
|
call mutex_unlock
|
|
|
|
popa
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
; Now, send it to the this socket
|
|
|
|
|
|
|
|
mov ecx, [esp + 4]
|
|
|
|
mov esi, [esp]
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
jmp socket_input
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.dump:
|
2013-06-12 12:21:41 +02:00
|
|
|
pusha
|
|
|
|
mov ecx, socket_mutex
|
|
|
|
call mutex_unlock
|
|
|
|
popa
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n'
|
2015-12-27 16:37:31 +01:00
|
|
|
call net_buff_free
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; pppoe_discovery_output ;
|
|
|
|
; ;
|
|
|
|
; IN: eax = socket pointer ;
|
|
|
|
; ecx = number of bytes to send ;
|
|
|
|
; esi = pointer to data ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
2013-05-28 19:34:26 +02:00
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
pppoe_discovery_output:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: socket=%x buffer=%x size=%d\n", eax, esi, ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; RFC2516: An entire PADI packet (including the PPPoE header) MUST NOT
|
|
|
|
; exceed 1484 octets.
|
|
|
|
cmp ecx, 1484 + 14
|
|
|
|
ja .bad
|
|
|
|
|
|
|
|
; Check that device exists and is ethernet device
|
|
|
|
mov ebx, [eax + SOCKET.device]
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp ebx, NET_DEVICES_MAX
|
2013-05-28 19:34:26 +02:00
|
|
|
ja .bad
|
|
|
|
|
|
|
|
mov ebx, [NET_DRV_LIST + 4*ebx]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .bad
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp [ebx + NET_DEVICE.device_type], NET_DEVICE_ETH
|
2013-05-28 19:34:26 +02:00
|
|
|
jne .bad
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: device=%x\n", ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Create packet.
|
|
|
|
push ecx esi
|
2015-12-27 16:37:31 +01:00
|
|
|
;;;; FIXME stdcall kernel_alloc, 1500
|
2013-05-28 19:34:26 +02:00
|
|
|
pop esi ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .bad
|
|
|
|
|
|
|
|
mov edx, ecx
|
|
|
|
mov edi, eax
|
2013-06-27 01:35:43 +02:00
|
|
|
rep movsb
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp edx, 60 ; Min ETH size
|
|
|
|
ja @f
|
|
|
|
mov edx, 60
|
|
|
|
@@:
|
|
|
|
|
|
|
|
push edx eax ; size and packet ptr for driver send proc
|
|
|
|
|
|
|
|
; Overwrite source MAC and protocol type
|
|
|
|
lea edi, [eax + ETH_header.SrcMAC]
|
|
|
|
lea esi, [ebx + ETH_DEVICE.mac]
|
|
|
|
movsd
|
|
|
|
movsw
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp word[edi], ETHER_PROTO_PPP_SESSION ; Allow only PPP_discovery, or LCP
|
2013-05-28 19:34:26 +02:00
|
|
|
je @f
|
2013-06-04 16:12:37 +02:00
|
|
|
mov ax, ETHER_PROTO_PPP_DISCOVERY
|
2013-05-28 19:34:26 +02:00
|
|
|
stosw
|
|
|
|
@@:
|
|
|
|
|
|
|
|
; And send the packet
|
|
|
|
call [ebx + NET_DEVICE.transmit]
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.bad:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; pppoe_session_input ;
|
|
|
|
; ;
|
|
|
|
; IN: [esp] = ptr to buffer ;
|
|
|
|
; [esp+4] = size of buffer ;
|
|
|
|
; ebx = ptr to device struct ;
|
|
|
|
; edx = ptr to PPP header ;
|
|
|
|
; ecx = size of PPP packet ;
|
|
|
|
; ;
|
|
|
|
; OUT: / ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
2013-05-28 19:34:26 +02:00
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
pppoe_session_input:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp [edx + PPPoE_frame.VersionAndType], 0x11
|
|
|
|
jne .dump
|
|
|
|
|
|
|
|
cmp [edx + PPPoE_frame.Code], 0x00
|
|
|
|
jne .dump
|
|
|
|
|
|
|
|
movzx ecx, [edx + PPPoE_frame.Length]
|
|
|
|
xchg cl, ch
|
|
|
|
|
|
|
|
mov ax, [edx + PPPoE_frame.SessionID]
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: session ID=%x, length=%u\n", ax, cx
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp ax, [PPPoE_SID]
|
|
|
|
jne .dump
|
|
|
|
|
|
|
|
mov ax, word [edx + PPPoE_frame.Payload]
|
|
|
|
add edx, PPPoE_frame.Payload + 2
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp ax, PPP_PROTO_IPv4
|
2015-12-27 16:37:31 +01:00
|
|
|
je ipv4_input
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
; cmp ax, PPP_PROTO_IPv6
|
2015-12-27 16:37:31 +01:00
|
|
|
; je ipv6_input
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
jmp pppoe_discovery_input ; Send LCP,CHAP,CBCP,... packets to the PPP dialer
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: Unknown protocol=%x\n", ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.dump:
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: dumping\n"
|
2015-12-27 16:37:31 +01:00
|
|
|
call net_buff_free
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; pppoe_output ;
|
|
|
|
; ;
|
|
|
|
; IN: ax = protocol ;
|
|
|
|
; ebx = device ptr ;
|
|
|
|
; ecx = packet size ;
|
|
|
|
; ;
|
|
|
|
; OUT: eax = buffer start ;
|
|
|
|
; eax = 0 on error ;
|
|
|
|
; ebx = device ptr ;
|
|
|
|
; ecx = packet size ;
|
|
|
|
; edx = size of complete buffer ;
|
|
|
|
; edi = start of PPP payload ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
2013-05-28 19:34:26 +02:00
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
pppoe_output:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: size=%u device=%x\n", ecx, ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-02 14:48:32 +02:00
|
|
|
pushw ax
|
2013-05-28 19:34:26 +02:00
|
|
|
pushw [PPPoE_SID]
|
|
|
|
|
2014-08-02 14:48:32 +02:00
|
|
|
mov ax, ETHER_PROTO_PPP_SESSION
|
2013-05-28 19:34:26 +02:00
|
|
|
add ecx, PPPoE_frame.Payload + 2
|
2014-08-02 14:48:32 +02:00
|
|
|
lea edx, [PPPoE_MAC]
|
2015-12-27 16:37:31 +01:00
|
|
|
call eth_output
|
2013-05-28 19:34:26 +02:00
|
|
|
jz .eth_error
|
|
|
|
|
|
|
|
sub ecx, PPPoE_frame.Payload
|
|
|
|
mov [edi + PPPoE_frame.VersionAndType], 0x11
|
|
|
|
mov [edi + PPPoE_frame.Code], 0
|
|
|
|
popw [edi + PPPoE_frame.SessionID]
|
|
|
|
xchg cl, ch
|
|
|
|
mov [edi + PPPoE_frame.Length], cx
|
|
|
|
xchg cl, ch
|
|
|
|
|
|
|
|
pop word [edi + PPPoE_frame.Payload]
|
|
|
|
|
|
|
|
sub ecx, 2
|
|
|
|
add edi, PPPoE_frame.Payload + 2
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: success!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
.eth_error:
|
|
|
|
add esp, 4
|
2014-08-02 14:48:32 +02:00
|
|
|
xor eax, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
align 4
|
|
|
|
pppoe_start_connection:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_start_connection: %x\n", cx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp [PPPoE_SID], 0
|
|
|
|
jne .fail
|
|
|
|
|
|
|
|
mov [PPPoE_SID], cx
|
|
|
|
mov dword [PPPoE_MAC], edx
|
|
|
|
mov word [PPPoE_MAC + 4], si
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
pppoe_stop_connection:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_stop_connection\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [PPPoE_SID], ax
|
|
|
|
mov dword [PPPoE_MAC], eax
|
|
|
|
mov word [PPPoE_MAC + 4], ax
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; pppoe_api: Part of system function 76 ;
|
|
|
|
; ;
|
|
|
|
; IN: subfunction number in bl ;
|
|
|
|
; device number in bh ;
|
|
|
|
; ecx, edx, .. depends on subfunction ;
|
|
|
|
; ;
|
|
|
|
; OUT: ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
2013-05-28 19:34:26 +02:00
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
pppoe_api:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
movzx eax, bh
|
|
|
|
shl eax, 2
|
|
|
|
|
|
|
|
and ebx, 0xff
|
|
|
|
cmp ebx, .number
|
|
|
|
ja .error
|
|
|
|
jmp dword [.table + 4*ebx]
|
|
|
|
|
|
|
|
.table:
|
2015-12-27 16:37:31 +01:00
|
|
|
dd pppoe_start_connection ; 0
|
|
|
|
dd pppoe_stop_connection ; 1
|
2013-05-28 19:34:26 +02:00
|
|
|
.number = ($ - .table) / 4 - 1
|
|
|
|
|
|
|
|
.error:
|
|
|
|
mov eax, -1
|
|
|
|
ret
|