2013-05-28 21:34:26 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2024-05-22 18:15:14 +03:00
|
|
|
;; Copyright (C) KolibriOS team 2012-2024. All rights reserved. ;;
|
2013-05-28 21:34:26 +04: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-18 01:19:45 +04:00
|
|
|
|
2013-05-28 21:34:26 +04: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 15:39:05 +04:00
|
|
|
align 4
|
|
|
|
|
2013-05-28 21:34:26 +04:00
|
|
|
PPPoE_SID dw ?
|
|
|
|
PPPoE_MAC dp ?
|
2013-06-24 15:39:05 +04:00
|
|
|
|
2013-05-28 21:34:26 +04:00
|
|
|
endg
|
|
|
|
|
2015-12-27 18:37:31 +03:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; pppoe_init: Reset all pppoe variables ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
macro pppoe_init {
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-12-27 18:37:31 +03:00
|
|
|
call pppoe_stop_connection
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-27 18:37:31 +03: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 21:34:26 +04:00
|
|
|
align 4
|
2015-12-27 18:37:31 +03:00
|
|
|
pppoe_discovery_input:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_input\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; First, find open PPPoE socket
|
|
|
|
|
2013-06-12 14:21:41 +04:00
|
|
|
pusha
|
|
|
|
mov ecx, socket_mutex
|
|
|
|
call mutex_lock
|
|
|
|
popa
|
|
|
|
|
2013-05-28 21:34:26 +04: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 14:21:41 +04:00
|
|
|
pusha
|
|
|
|
mov ecx, socket_mutex
|
|
|
|
call mutex_unlock
|
|
|
|
popa
|
|
|
|
|
2013-05-28 21:34:26 +04:00
|
|
|
; Now, send it to the this socket
|
|
|
|
|
|
|
|
mov ecx, [esp + 4]
|
|
|
|
mov esi, [esp]
|
|
|
|
|
2015-12-27 18:37:31 +03:00
|
|
|
jmp socket_input
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
.dump:
|
2013-06-12 14:21:41 +04:00
|
|
|
pusha
|
|
|
|
mov ecx, socket_mutex
|
|
|
|
call mutex_unlock
|
|
|
|
popa
|
|
|
|
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n'
|
2015-12-27 18:37:31 +03:00
|
|
|
call net_buff_free
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
2015-12-27 18:37:31 +03:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; pppoe_discovery_output ;
|
|
|
|
; ;
|
|
|
|
; IN: eax = socket pointer ;
|
|
|
|
; ecx = number of bytes to send ;
|
|
|
|
; esi = pointer to data ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
2013-05-28 21:34:26 +04:00
|
|
|
align 4
|
2015-12-27 18:37:31 +03:00
|
|
|
pppoe_discovery_output:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: socket=%x buffer=%x size=%d\n", eax, esi, ecx
|
2013-05-28 21:34:26 +04: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 18:12:37 +04:00
|
|
|
cmp ebx, NET_DEVICES_MAX
|
2013-05-28 21:34:26 +04:00
|
|
|
ja .bad
|
|
|
|
|
2019-08-25 21:46:47 +03:00
|
|
|
mov ebx, [net_device_list + 4*ebx]
|
2013-05-28 21:34:26 +04:00
|
|
|
test ebx, ebx
|
|
|
|
jz .bad
|
|
|
|
|
2013-06-04 18:12:37 +04:00
|
|
|
cmp [ebx + NET_DEVICE.device_type], NET_DEVICE_ETH
|
2013-05-28 21:34:26 +04:00
|
|
|
jne .bad
|
|
|
|
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: device=%x\n", ebx
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Create packet.
|
2021-07-10 12:41:13 +03:00
|
|
|
stdcall net_buff_alloc, 1514 + NET_BUFF.data
|
2013-05-28 21:34:26 +04:00
|
|
|
test eax, eax
|
|
|
|
jz .bad
|
|
|
|
|
2021-07-10 12:41:13 +03:00
|
|
|
; Net buffer header
|
|
|
|
mov [eax + NET_BUFF.type], NET_BUFF_ETH
|
|
|
|
mov [eax + NET_BUFF.device], ebx
|
|
|
|
mov [eax + NET_BUFF.offset], NET_BUFF.data
|
|
|
|
|
|
|
|
; Packet data
|
2013-05-28 21:34:26 +04:00
|
|
|
mov edx, ecx
|
2021-07-10 12:41:13 +03:00
|
|
|
lea edi, [eax + NET_BUFF.data]
|
2013-06-27 03:35:43 +04:00
|
|
|
rep movsb
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2021-07-10 12:41:13 +03:00
|
|
|
; Packet size
|
|
|
|
cmp edx, 60
|
2013-05-28 21:34:26 +04:00
|
|
|
ja @f
|
|
|
|
mov edx, 60
|
2021-07-10 12:41:13 +03:00
|
|
|
@@:
|
|
|
|
mov [eax + NET_BUFF.length], edx
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2021-07-10 12:41:13 +03:00
|
|
|
; Overwrite ETH source MAC with our own
|
2013-05-28 21:34:26 +04:00
|
|
|
lea esi, [ebx + ETH_DEVICE.mac]
|
2021-07-10 12:41:13 +03:00
|
|
|
lea edi, [eax + NET_BUFF.data + ETH_header.SrcMAC]
|
2013-05-28 21:34:26 +04:00
|
|
|
movsd
|
|
|
|
movsw
|
2021-07-10 12:41:13 +03:00
|
|
|
|
|
|
|
; Allow only PPP_discovery, or LCP
|
|
|
|
cmp word[edi], ETHER_PROTO_PPP_SESSION
|
2013-05-28 21:34:26 +04:00
|
|
|
je @f
|
2021-07-10 12:41:13 +03:00
|
|
|
mov word[edi], ETHER_PROTO_PPP_DISCOVERY
|
2013-05-28 21:34:26 +04:00
|
|
|
@@:
|
|
|
|
|
|
|
|
; And send the packet
|
2021-07-10 12:41:13 +03:00
|
|
|
stdcall [ebx + NET_DEVICE.transmit], eax
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
.bad:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2015-12-27 18:37:31 +03: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 21:34:26 +04:00
|
|
|
align 4
|
2015-12-27 18:37:31 +03:00
|
|
|
pppoe_session_input:
|
2013-05-28 21:34:26 +04: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 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: session ID=%x, length=%u\n", ax, cx
|
2013-05-28 21:34:26 +04:00
|
|
|
cmp ax, [PPPoE_SID]
|
|
|
|
jne .dump
|
|
|
|
|
|
|
|
mov ax, word [edx + PPPoE_frame.Payload]
|
|
|
|
add edx, PPPoE_frame.Payload + 2
|
|
|
|
|
2013-06-04 18:12:37 +04:00
|
|
|
cmp ax, PPP_PROTO_IPv4
|
2015-12-27 18:37:31 +03:00
|
|
|
je ipv4_input
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2013-06-04 18:12:37 +04:00
|
|
|
; cmp ax, PPP_PROTO_IPv6
|
2015-12-27 18:37:31 +03:00
|
|
|
; je ipv6_input
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-12-27 18:37:31 +03:00
|
|
|
jmp pppoe_discovery_input ; Send LCP,CHAP,CBCP,... packets to the PPP dialer
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: Unknown protocol=%x\n", ax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
.dump:
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: dumping\n"
|
2015-12-27 18:37:31 +03:00
|
|
|
call net_buff_free
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-27 18:37:31 +03: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 21:34:26 +04:00
|
|
|
align 4
|
2015-12-27 18:37:31 +03:00
|
|
|
pppoe_output:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: size=%u device=%x\n", ecx, ebx
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-08-02 16:48:32 +04:00
|
|
|
pushw ax
|
2013-05-28 21:34:26 +04:00
|
|
|
pushw [PPPoE_SID]
|
|
|
|
|
2014-08-02 16:48:32 +04:00
|
|
|
mov ax, ETHER_PROTO_PPP_SESSION
|
2013-05-28 21:34:26 +04:00
|
|
|
add ecx, PPPoE_frame.Payload + 2
|
2014-08-02 16:48:32 +04:00
|
|
|
lea edx, [PPPoE_MAC]
|
2015-12-27 18:37:31 +03:00
|
|
|
call eth_output
|
2013-05-28 21:34:26 +04: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 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: success!\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
.eth_error:
|
|
|
|
add esp, 4
|
2014-08-02 16:48:32 +04:00
|
|
|
xor eax, eax
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
2015-12-27 18:37:31 +03:00
|
|
|
align 4
|
|
|
|
pppoe_start_connection:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_start_connection: %x\n", cx
|
2013-05-28 21:34:26 +04: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 18:37:31 +03:00
|
|
|
pppoe_stop_connection:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2013-05-28 23:19:23 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_stop_connection\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [PPPoE_SID], ax
|
|
|
|
mov dword [PPPoE_MAC], eax
|
|
|
|
mov word [PPPoE_MAC + 4], ax
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2015-12-27 18:37:31 +03: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 21:34:26 +04:00
|
|
|
align 4
|
2015-12-27 18:37:31 +03:00
|
|
|
pppoe_api:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
movzx eax, bh
|
|
|
|
shl eax, 2
|
|
|
|
|
|
|
|
and ebx, 0xff
|
|
|
|
cmp ebx, .number
|
|
|
|
ja .error
|
|
|
|
jmp dword [.table + 4*ebx]
|
|
|
|
|
|
|
|
.table:
|
2015-12-27 18:37:31 +03:00
|
|
|
dd pppoe_start_connection ; 0
|
|
|
|
dd pppoe_stop_connection ; 1
|
2013-05-28 21:34:26 +04:00
|
|
|
.number = ($ - .table) / 4 - 1
|
|
|
|
|
|
|
|
.error:
|
|
|
|
mov eax, -1
|
|
|
|
ret
|