Fixed some bugs in PPPoE implementation. Discovery works, now we need PPP-LCP.

git-svn-id: svn://kolibrios.org@2960 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-08-30 20:01:42 +00:00
parent 761cdb63f8
commit 7c750c97d3
3 changed files with 72 additions and 35 deletions

View File

@ -39,7 +39,20 @@ PPPoE_PADR = 0x19 ; .. Request
PPPoE_PADS = 0x65 ; .. Session-confirmation
PPPoE_PADT = 0xa7 ; .. Terminate
struct PPPoE_frame
TAG_EOL = 0x0000
TAG_SERVICE_NAME= 0x0101
TAG_AC_NAME = 0x0201
TAG_HOST_UNIQ = 0x0301
TAG_AC_COOKIE = 0x0401
struct ETH_frame
DestMac dp ?
SrcMac dp ?
Type dw ?
ends
struct PPPoE_frame ETH_frame
VersionAndType db ?
Code db ?
SessionID dw ?
@ -73,9 +86,9 @@ main:
mcall socket, 777, 3, 666
mov [socketnum], eax
mcall send, [socketnum], PADI, 14 + 6 + 4, 0
mcall send, [socketnum], PADI, PADI.length, 0
.recv:
mainloop:
mcall 10
call [con_get_flags]
@ -83,65 +96,65 @@ main:
jnz close_conn
mcall recv, [socketnum], buffer, 4096
cmp eax, 20
jb .recv
cmp eax, sizeof.PPPoE_frame
jb mainloop
cmp [buffer + 14 + PPPoE_frame.Code], PPPoE_PADO
je .pado
cmp [buffer + PPPoE_frame.Code], PPPoE_PADO
je pado
cmp [buffer + 14 + PPPoE_frame.Code], PPPoE_PADS
je .pads
cmp [buffer + PPPoE_frame.Code], PPPoE_PADS
je pads
cmp [buffer + 14 + PPPoE_frame.Code], PPPoE_PADT
je .padt
cmp [buffer + PPPoE_frame.Code], PPPoE_PADT
je padt
jmp .recv
jmp mainloop
.pado:
pado:
push str2
call [con_write_asciiz]
lea esi, [buffer + 6] ; source mac -> dest mac
lea edi, [buffer]
movsb
lea esi, [buffer + ETH_frame.SrcMac] ; source mac -> dest mac
lea edi, [buffer + ETH_frame.DestMac]
movsw
movsd
mov byte [buffer + 15], PPPoE_PADR ; change packet type to PADR
mov byte [buffer + PPPoE_frame.Code], PPPoE_PADR ; change packet type to PADR
mov al, byte [buffer + 19] ; get packet size
mov ah, byte [buffer + 18]
mov al, byte [buffer + PPPoE_frame.Length + 1] ; get packet size
mov ah, byte [buffer + PPPoE_frame.Length + 0]
movzx esi, ax
add esi, 20
add esi, sizeof.PPPoE_frame
mcall send, [socketnum], buffer, , 0 ; now send it!
jmp .recv
jmp mainloop
.pads:
pads:
push str3
call [con_write_asciiz]
mov edx, dword [buffer + 6] ; copy the MAC address
mov si, word [buffer + 6 +4]
mov edx, dword [buffer + ETH_frame.SrcMac] ; source mac -> dest mac
mov si, word [buffer + ETH_frame.SrcMac + 4]
mov dword [PADT.mac], edx
mov word [PADT.mac + 4], si
mov cx, word [buffer + 6 + 2] ; and Session ID
mov cx, word [buffer + PPPoE_frame.SessionID] ; and Session ID
mov [PADT.sid], cx
mcall 75, API_PPPOE + 0 ; Start PPPoE session
mcall 76, API_PPPOE + 0 ; Start PPPoE session
jmp .recv
jmp mainloop
.padt:
padt:
push str4
call [con_write_asciiz]
mcall 75, API_PPPOE + 1
mcall 76, API_PPPOE + 1
exit:
mcall close, [socketnum]
@ -169,11 +182,19 @@ PADI:
db 0x11
db PPPoE_PADI
dw 0 ; session ID
dw 4 shl 8
dw 20 shl 8
dw 0x0101 ; service name tag with zero length
dw TAG_SERVICE_NAME
dw 0x0000
dw TAG_HOST_UNIQ
dw 0x0c00 ; 12 bytes long
dd 0xdead ; some random id
dd 0xbeef
dd 0x1337
.length = $ - PADI
PADT:
.mac dp 0

View File

@ -33,6 +33,20 @@ uglobal
endg
;-----------------------------------------------------------------
;
; IPv4_init
;
; This function resets all IP variables
;
;-----------------------------------------------------------------
macro PPPoE_init {
call PPPoE_stop_connection
}
;-----------------------------------------------------------------
;
; PPPoE discovery input
@ -235,15 +249,17 @@ PPPoE_output:
call ETH_output
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, PPPoE_frame.Payload + 2
sub ecx, 2
add edi, PPPoE_frame.Payload + 2
DEBUGF 1,"PPPoE_output: success!\n"
@ -262,7 +278,7 @@ align 4
PPPoE_start_connection:
cmp [PPPoE_SID], 0
je .fail
jne .fail
mov [PPPoE_SID], cx
mov dword [PPPoE_MAC], edx

View File

@ -221,7 +221,7 @@ stack_init:
mov ecx, (MAX_NET_DEVICES + 2)
rep stosd
; PPPOE_init
PPPoE_init
IPv4_init
; IPv6_init
@ -590,7 +590,7 @@ checksum_2:
;----------------------------------------------------------------
;
; System function to work with network devices (73)
; System function to work with network devices (76)
;
;----------------------------------------------------------------
align 4