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_PADS = 0x65 ; .. Session-confirmation
PPPoE_PADT = 0xa7 ; .. Terminate 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 ? VersionAndType db ?
Code db ? Code db ?
SessionID dw ? SessionID dw ?
@ -73,9 +86,9 @@ main:
mcall socket, 777, 3, 666 mcall socket, 777, 3, 666
mov [socketnum], eax mov [socketnum], eax
mcall send, [socketnum], PADI, 14 + 6 + 4, 0 mcall send, [socketnum], PADI, PADI.length, 0
.recv: mainloop:
mcall 10 mcall 10
call [con_get_flags] call [con_get_flags]
@ -83,65 +96,65 @@ main:
jnz close_conn jnz close_conn
mcall recv, [socketnum], buffer, 4096 mcall recv, [socketnum], buffer, 4096
cmp eax, 20 cmp eax, sizeof.PPPoE_frame
jb .recv jb mainloop
cmp [buffer + 14 + PPPoE_frame.Code], PPPoE_PADO cmp [buffer + PPPoE_frame.Code], PPPoE_PADO
je .pado je pado
cmp [buffer + 14 + PPPoE_frame.Code], PPPoE_PADS cmp [buffer + PPPoE_frame.Code], PPPoE_PADS
je .pads je pads
cmp [buffer + 14 + PPPoE_frame.Code], PPPoE_PADT cmp [buffer + PPPoE_frame.Code], PPPoE_PADT
je .padt je padt
jmp .recv jmp mainloop
.pado: pado:
push str2 push str2
call [con_write_asciiz] call [con_write_asciiz]
lea esi, [buffer + 6] ; source mac -> dest mac lea esi, [buffer + ETH_frame.SrcMac] ; source mac -> dest mac
lea edi, [buffer] lea edi, [buffer + ETH_frame.DestMac]
movsb movsw
movsd 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 al, byte [buffer + PPPoE_frame.Length + 1] ; get packet size
mov ah, byte [buffer + 18] mov ah, byte [buffer + PPPoE_frame.Length + 0]
movzx esi, ax movzx esi, ax
add esi, 20 add esi, sizeof.PPPoE_frame
mcall send, [socketnum], buffer, , 0 ; now send it! mcall send, [socketnum], buffer, , 0 ; now send it!
jmp .recv jmp mainloop
.pads: pads:
push str3 push str3
call [con_write_asciiz] call [con_write_asciiz]
mov edx, dword [buffer + 6] ; copy the MAC address mov edx, dword [buffer + ETH_frame.SrcMac] ; source mac -> dest mac
mov si, word [buffer + 6 +4] mov si, word [buffer + ETH_frame.SrcMac + 4]
mov dword [PADT.mac], edx mov dword [PADT.mac], edx
mov word [PADT.mac + 4], si 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 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 push str4
call [con_write_asciiz] call [con_write_asciiz]
mcall 75, API_PPPOE + 1 mcall 76, API_PPPOE + 1
exit: exit:
mcall close, [socketnum] mcall close, [socketnum]
@ -169,11 +182,19 @@ PADI:
db 0x11 db 0x11
db PPPoE_PADI db PPPoE_PADI
dw 0 ; session ID 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 0x0000
dw TAG_HOST_UNIQ
dw 0x0c00 ; 12 bytes long
dd 0xdead ; some random id
dd 0xbeef
dd 0x1337
.length = $ - PADI
PADT: PADT:
.mac dp 0 .mac dp 0

View File

@ -33,6 +33,20 @@ uglobal
endg endg
;-----------------------------------------------------------------
;
; IPv4_init
;
; This function resets all IP variables
;
;-----------------------------------------------------------------
macro PPPoE_init {
call PPPoE_stop_connection
}
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; PPPoE discovery input ; PPPoE discovery input
@ -235,15 +249,17 @@ PPPoE_output:
call ETH_output call ETH_output
jz .eth_error jz .eth_error
sub ecx, PPPoE_frame.Payload
mov [edi + PPPoE_frame.VersionAndType], 0x11 mov [edi + PPPoE_frame.VersionAndType], 0x11
mov [edi + PPPoE_frame.Code], 0 mov [edi + PPPoE_frame.Code], 0
popw [edi + PPPoE_frame.SessionID] popw [edi + PPPoE_frame.SessionID]
xchg cl, ch xchg cl, ch
mov [edi + PPPoE_frame.Length], cx mov [edi + PPPoE_frame.Length], cx
xchg cl, ch xchg cl, ch
pop word [edi + PPPoE_frame.Payload] pop word [edi + PPPoE_frame.Payload]
sub ecx, PPPoE_frame.Payload + 2 sub ecx, 2
add edi, PPPoE_frame.Payload + 2 add edi, PPPoE_frame.Payload + 2
DEBUGF 1,"PPPoE_output: success!\n" DEBUGF 1,"PPPoE_output: success!\n"
@ -262,7 +278,7 @@ align 4
PPPoE_start_connection: PPPoE_start_connection:
cmp [PPPoE_SID], 0 cmp [PPPoE_SID], 0
je .fail jne .fail
mov [PPPoE_SID], cx mov [PPPoE_SID], cx
mov dword [PPPoE_MAC], edx mov dword [PPPoE_MAC], edx

View File

@ -221,7 +221,7 @@ stack_init:
mov ecx, (MAX_NET_DEVICES + 2) mov ecx, (MAX_NET_DEVICES + 2)
rep stosd rep stosd
; PPPOE_init PPPoE_init
IPv4_init IPv4_init
; IPv6_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 align 4