more small updates and fixes in net branch

git-svn-id: svn://kolibrios.org@2311 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2011-11-12 22:35:01 +00:00
parent 3ce07b4be0
commit 343d6e80ca
5 changed files with 439 additions and 448 deletions

View File

@ -18,52 +18,52 @@
$Revision$ $Revision$
ARP_NO_ENTRY equ 0 ARP_NO_ENTRY equ 0
ARP_VALID_MAPPING equ 1 ARP_VALID_MAPPING equ 1
ARP_AWAITING_RESPONSE equ 2 ARP_AWAITING_RESPONSE equ 2
ARP_RESPONSE_TIMEOUT equ 3 ARP_RESPONSE_TIMEOUT equ 3
ARP_REQUEST_TTL equ 31 ; 20 s ARP_REQUEST_TTL equ 31 ; 20 s
ARP_ENTRY_TTL equ 937 ; 600 s ARP_ENTRY_TTL equ 937 ; 600 s
ARP_STATIC_ENTRY equ -1 ARP_STATIC_ENTRY equ -1
ARP_REQ_OPCODE equ 0x0100 ; request ARP_REQ_OPCODE equ 0x0100 ; request
ARP_REP_OPCODE equ 0x0200 ; reply ARP_REP_OPCODE equ 0x0200 ; reply
ARP_TABLE_SIZE equ 20 ; Size of table ARP_TABLE_SIZE equ 20 ; Size of table
struct ARP_entry struct ARP_entry
IP dd ? IP dd ?
MAC dp ? MAC dp ?
Status dw ? Status dw ?
TTL dw ? TTL dw ?
ends ends
struct ARP_header struct ARP_header
HardwareType dw ? HardwareType dw ?
ProtocolType dw ? ProtocolType dw ?
HardwareSize db ? HardwareSize db ?
ProtocolSize db ? ProtocolSize db ?
Opcode dw ? Opcode dw ?
SenderMAC dp ? SenderMAC dp ?
SenderIP dd ? SenderIP dd ?
TargetMAC dp ? TargetMAC dp ?
TargetIP dd ? TargetIP dd ?
ends ends
align 4 align 4
uglobal uglobal
NumARP dd ? NumARP dd ?
ARP_table rb ARP_TABLE_SIZE * sizeof.ARP_entry ARP_table rb ARP_TABLE_SIZE * sizeof.ARP_entry
ARP_PACKETS_TX rd MAX_NET_DEVICES ARP_PACKETS_TX rd MAX_NET_DEVICES
ARP_PACKETS_RX rd MAX_NET_DEVICES ARP_PACKETS_RX rd MAX_NET_DEVICES
endg endg
@ -79,12 +79,12 @@ endg
;----------------------------------------------------------------- ;-----------------------------------------------------------------
macro ARP_init { macro ARP_init {
xor eax, eax xor eax, eax
mov [NumARP], eax mov [NumARP], eax
mov edi, ARP_PACKETS_TX mov edi, ARP_PACKETS_TX
mov ecx, 2*MAX_NET_DEVICES mov ecx, 2*MAX_NET_DEVICES
rep stosd rep stosd
} }
@ -96,8 +96,8 @@ macro ARP_init {
macro ARP_decrease_entry_ttls { macro ARP_decrease_entry_ttls {
local .loop local .loop
local .exit local .exit
; The TTL field is decremented every second, and is deleted when it reaches 0. ; The TTL field is decremented every second, and is deleted when it reaches 0.
; It is refreshed every time a packet is received. ; It is refreshed every time a packet is received.
@ -110,39 +110,39 @@ local .exit
; The last status value is provided to allow the network layer to delete ; The last status value is provided to allow the network layer to delete
; a packet that is queued awaiting an ARP response ; a packet that is queued awaiting an ARP response
mov ecx, [NumARP] mov ecx, [NumARP]
test ecx, ecx test ecx, ecx
jz .exit jz .exit
mov esi, ARP_table mov esi, ARP_table
.loop: .loop:
cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY
je .next je .next
dec [esi + ARP_entry.TTL] dec [esi + ARP_entry.TTL]
jz .time_out jz .time_out
.next: .next:
add esi, sizeof.ARP_entry add esi, sizeof.ARP_entry
dec ecx dec ecx
jnz .loop jnz .loop
jmp .exit jmp .exit
.time_out: .time_out:
cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE
je .response_timeout je .response_timeout
push esi ecx push esi ecx
call ARP_del_entry call ARP_del_entry
pop ecx esi pop ecx esi
jmp .next jmp .next
.response_timeout: .response_timeout:
mov [esi + ARP_entry.Status], ARP_RESPONSE_TIMEOUT mov [esi + ARP_entry.Status], ARP_RESPONSE_TIMEOUT
mov [esi + ARP_entry.TTL], 10 mov [esi + ARP_entry.TTL], 10
jmp .next jmp .next
.exit: .exit:
@ -162,117 +162,117 @@ local .exit
align 4 align 4
ARP_input: ARP_input:
DEBUGF 1,"ARP_Handler - start\n" DEBUGF 1,"ARP_Handler - start\n"
cmp ecx, sizeof.ARP_header cmp ecx, sizeof.ARP_header
jb .exit jb .exit
;--------------------- ;---------------------
; Handle Reply packets ; Handle Reply packets
cmp [edx + ARP_header.Opcode], ARP_REP_OPCODE cmp [edx + ARP_header.Opcode], ARP_REP_OPCODE
jne .maybe_request jne .maybe_request
DEBUGF 1,"ARP_Handler - it's a reply packet from %u.%u.%u.%u\n",\ DEBUGF 1,"ARP_Handler - it's a reply packet from %u.%u.%u.%u\n",\
[edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP+1]:1, [edx + ARP_header.SenderIP+2]:1, [edx + ARP_header.SenderIP+3]:1 [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP+1]:1, [edx + ARP_header.SenderIP+2]:1, [edx + ARP_header.SenderIP+3]:1
mov ecx, [NumARP] mov ecx, [NumARP]
test ecx, ecx test ecx, ecx
jz .exit jz .exit
mov eax, [edx + ARP_header.SenderIP] mov eax, [edx + ARP_header.SenderIP]
mov esi, ARP_table mov esi, ARP_table
.loop: .loop:
cmp [esi + ARP_entry.IP], eax cmp [esi + ARP_entry.IP], eax
je .gotit je .gotit
add esi, sizeof.ARP_entry add esi, sizeof.ARP_entry
dec ecx dec ecx
jnz .loop jnz .loop
jmp .exit jmp .exit
.gotit: .gotit:
DEBUGF 1,"ARP_Handler - found matching entry\n" DEBUGF 1,"ARP_Handler - found matching entry\n"
cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY ; if it is a static entry, dont touch it cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY ; if it is a static entry, dont touch it
je .exit je .exit
DEBUGF 1,"ARP_Handler - updating entry\n" DEBUGF 1,"ARP_Handler - updating entry\n"
mov [esi + ARP_entry.Status], ARP_VALID_MAPPING mov [esi + ARP_entry.Status], ARP_VALID_MAPPING
mov [esi + ARP_entry.TTL], ARP_ENTRY_TTL mov [esi + ARP_entry.TTL], ARP_ENTRY_TTL
mov eax, dword [edx + ARP_header.SenderMAC] mov eax, dword [edx + ARP_header.SenderMAC]
mov dword [esi+ARP_entry.MAC], eax mov dword [esi+ARP_entry.MAC], eax
mov ax , word [edx + ARP_header.SenderMAC + 4] mov ax , word [edx + ARP_header.SenderMAC + 4]
mov word [esi+ARP_entry.MAC+4], ax mov word [esi+ARP_entry.MAC+4], ax
jmp .exit jmp .exit
;----------------------- ;-----------------------
; Handle Request packets ; Handle Request packets
.maybe_request: .maybe_request:
cmp [edx + ARP_header.Opcode], ARP_REQ_OPCODE cmp [edx + ARP_header.Opcode], ARP_REQ_OPCODE
jne .exit jne .exit
call NET_ptr_to_num call NET_ptr_to_num
cmp edi, -1 cmp edi, -1
jz .exit jz .exit
DEBUGF 1,"ARP Request packet through device: %u\n", edi DEBUGF 1,"ARP Request packet through device: %u\n", edi
inc [ARP_PACKETS_RX+4*edi] inc [ARP_PACKETS_RX+4*edi]
mov eax, [IP_LIST+4*edi] mov eax, [IP_LIST+4*edi]
cmp eax, [edx + ARP_header.TargetIP] ; Is it looking for my IP address? cmp eax, [edx + ARP_header.TargetIP] ; Is it looking for my IP address?
jne .exit ; TODO: instead of quitting, update local entrys with matching IP's ? jne .exit ; TODO: instead of quitting, update local entrys with matching IP's ?
push eax push eax
push edi push edi
; OK, it is a request for one of our MAC addresses. ; OK, it is a request for one of our MAC addresses.
; Build the frame and send it. We can reuse the buffer. (faster then using ARP_create_packet) ; Build the frame and send it. We can reuse the buffer. (faster then using ARP_create_packet)
lea esi, [edx + ARP_header.SenderMAC] lea esi, [edx + ARP_header.SenderMAC]
lea edi, [edx + ARP_header.TargetMAC] lea edi, [edx + ARP_header.TargetMAC]
movsd ; Move Sender Mac to Dest MAC movsd ; Move Sender Mac to Dest MAC
movsw ; movsw ;
movsd ; Move sender IP to Dest IP movsd ; Move sender IP to Dest IP
pop esi pop esi
mov esi, [NET_DRV_LIST + 4*esi] mov esi, [NET_DRV_LIST + 4*esi]
lea esi, [esi + ETH_DEVICE.mac] lea esi, [esi + ETH_DEVICE.mac]
lea edi, [edx + ARP_header.SenderMAC] lea edi, [edx + ARP_header.SenderMAC]
movsd ; Copy MAC address from in MAC_LIST movsd ; Copy MAC address from in MAC_LIST
movsw ; movsw ;
pop eax pop eax
stosd ; Write our IP stosd ; Write our IP
mov [edx + ARP_header.Opcode], ARP_REP_OPCODE mov [edx + ARP_header.Opcode], ARP_REP_OPCODE
; Now, Fill in ETHERNET header ; Now, Fill in ETHERNET header
mov edi, [esp] mov edi, [esp]
lea esi, [edx + ARP_header.TargetMAC] lea esi, [edx + ARP_header.TargetMAC]
movsd movsd
movsw movsw
lea esi, [edx + ARP_header.SenderMAC] lea esi, [edx + ARP_header.SenderMAC]
movsd movsd
movsw movsw
; mov ax , ETHER_ARP ; mov ax , ETHER_ARP
; stosw ; stosw
DEBUGF 1,"ARP_Handler - Sending reply \n" DEBUGF 1,"ARP_Handler - Sending reply \n"
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
.exit: .exit:
call kernel_free call kernel_free
add esp, 4 ; pop (balance stack) add esp, 4 ; pop (balance stack)
DEBUGF 1,"ARP_Handler - exiting\n" DEBUGF 1,"ARP_Handler - exiting\n"
ret ret
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
@ -286,54 +286,54 @@ ARP_input:
align 4 align 4
ARP_output_request: ARP_output_request:
DEBUGF 1,"Create ARP Packet\n" DEBUGF 1,"Create ARP Packet\n"
call IPv4_dest_to_dev call IPv4_dest_to_dev
push eax ; DestIP push eax ; DestIP
pushd [IP_LIST+edi] ; SenderIP pushd [IP_LIST+edi] ; SenderIP
mov ebx, [NET_DRV_LIST+edi] ; device ptr mov ebx, [NET_DRV_LIST+edi] ; device ptr
lea eax, [ebx + ETH_DEVICE.mac] ; local device mac lea eax, [ebx + ETH_DEVICE.mac] ; local device mac
mov edx, ETH_BROADCAST ; broadcast mac mov edx, ETH_BROADCAST ; broadcast mac
mov ecx, sizeof.ARP_header mov ecx, sizeof.ARP_header
mov di, ETHER_ARP mov di, ETHER_ARP
call ETH_output call ETH_output
jz .exit jz .exit
mov ecx, eax mov ecx, eax
mov [edi + ARP_header.HardwareType], 0x0100 ; Ethernet mov [edi + ARP_header.HardwareType], 0x0100 ; Ethernet
mov [edi + ARP_header.ProtocolType], 0x0008 ; IP mov [edi + ARP_header.ProtocolType], 0x0008 ; IP
mov [edi + ARP_header.HardwareSize], 6 ; MAC-addr length mov [edi + ARP_header.HardwareSize], 6 ; MAC-addr length
mov [edi + ARP_header.ProtocolSize], 4 ; IP-addr length mov [edi + ARP_header.ProtocolSize], 4 ; IP-addr length
mov [edi + ARP_header.Opcode], ARP_REQ_OPCODE ; Request mov [edi + ARP_header.Opcode], ARP_REQ_OPCODE ; Request
add edi, ARP_header.SenderMAC add edi, ARP_header.SenderMAC
lea esi, [ebx + ETH_DEVICE.mac] ; SenderMac lea esi, [ebx + ETH_DEVICE.mac] ; SenderMac
movsw ; movsw ;
movsd ; movsd ;
pop eax ; SenderIP pop eax ; SenderIP
stosd ; stosd ;
mov eax, -1 ; DestMac mov eax, -1 ; DestMac
stosd ; stosd ;
stosw ; stosw ;
pop eax ; DestIP pop eax ; DestIP
stosd ; stosd ;
DEBUGF 1,"ARP Packet for device %x created successfully\n", ebx DEBUGF 1,"ARP Packet for device %x created successfully\n", ebx
push edx ecx push edx ecx
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
.exit: .exit:
add esp, 4+4 add esp, 4+4
DEBUGF 1,"Create ARP Packet - failed\n" DEBUGF 1,"Create ARP Packet - failed\n"
sub eax, eax sub eax, eax
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
@ -347,59 +347,59 @@ ARP_output_request:
align 4 align 4
ARP_add_entry: ARP_add_entry:
DEBUGF 1,"ARP add entry: " DEBUGF 1,"ARP add entry: "
mov ecx, [NumARP] mov ecx, [NumARP]
test ecx, ecx ; first entry? test ecx, ecx ; first entry?
jz .add jz .add
cmp ecx, ARP_TABLE_SIZE ; list full ? cmp ecx, ARP_TABLE_SIZE ; list full ?
jae .error jae .error
mov eax, dword [esi + ARP_entry.MAC] mov eax, dword [esi + ARP_entry.MAC]
mov bx , word [esi + ARP_entry.MAC + 4] mov bx , word [esi + ARP_entry.MAC + 4]
mov edi, ARP_table mov edi, ARP_table
.loop: .loop:
cmp dword [edi + ARP_entry.MAC], eax ; Check for duplicate MAC's cmp dword [edi + ARP_entry.MAC], eax ; Check for duplicate MAC's
jne .maybe_next ; jne .maybe_next ;
cmp word [edi + ARP_entry.MAC + 4], bx ; cmp word [edi + ARP_entry.MAC + 4], bx ;
jne .maybe_next ; jne .maybe_next ;
cmp [edi + ARP_entry.TTL], ARP_STATIC_ENTRY cmp [edi + ARP_entry.TTL], ARP_STATIC_ENTRY
jne .notstatic jne .notstatic
cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY
jne .error jne .error
.notstatic: .notstatic:
neg ecx neg ecx
add ecx, [NumARP] add ecx, [NumARP]
jmp .add jmp .add
.maybe_next: .maybe_next:
add esi, sizeof.ARP_entry add esi, sizeof.ARP_entry
loop .loop loop .loop
mov ecx, [NumARP] mov ecx, [NumARP]
.add: .add:
push ecx push ecx
imul ecx, sizeof.ARP_entry imul ecx, sizeof.ARP_entry
lea edi, [ecx + ARP_table] lea edi, [ecx + ARP_table]
mov ecx, sizeof.ARP_entry/2 mov ecx, sizeof.ARP_entry/2
rep movsw rep movsw
lea esi, [edi - sizeof.ARP_entry] lea esi, [edi - sizeof.ARP_entry]
inc [NumARP] inc [NumARP]
pop eax pop eax
DEBUGF 1,"New entry created: %u\n", eax DEBUGF 1,"New entry created: %u\n", eax
.exit: .exit:
DEBUGF 1,"Exiting\n" DEBUGF 1,"Exiting\n"
ret ret
.error: .error:
DEBUGF 1,"error! \n" DEBUGF 1,"error! \n"
mov eax, -1 mov eax, -1
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
@ -413,20 +413,20 @@ ARP_add_entry:
align 4 align 4
ARP_del_entry: ARP_del_entry:
DEBUGF 1,"ARP del entry %x, total entrys: %u\n", esi, [NumARP] DEBUGF 1,"ARP del entry %x, total entrys: %u\n", esi, [NumARP]
mov ecx, ARP_table + (ARP_TABLE_SIZE - 1) * sizeof.ARP_entry mov ecx, ARP_table + (ARP_TABLE_SIZE - 1) * sizeof.ARP_entry
sub ecx, esi sub ecx, esi
shr ecx, 1 shr ecx, 1
mov edi, esi mov edi, esi
lea esi, [edi + sizeof.ARP_entry] lea esi, [edi + sizeof.ARP_entry]
rep movsw rep movsw
dec [NumARP] dec [NumARP]
DEBUGF 1,"ARP entry deleted\n" DEBUGF 1,"ARP entry deleted\n"
ret ret
@ -447,110 +447,110 @@ ARP_del_entry:
align 4 align 4
ARP_IP_to_MAC: ARP_IP_to_MAC:
DEBUGF 1,"ARP_IP_to_MAC\n" DEBUGF 1,"ARP_IP_to_MAC\n"
cmp eax, 0xffffffff cmp eax, 0xffffffff
je .broadcast je .broadcast
; if ((Remote IP & subnet_mask) == (local IP & subnet_mask )) ; if ((Remote IP & subnet_mask) == (local IP & subnet_mask ))
; destination is on same subnet ; destination is on same subnet
; else, destination is remote and must use a gateway ; else, destination is remote and must use a gateway
call IPv4_dest_to_dev call IPv4_dest_to_dev
mov ebx, [IP_LIST + edi] mov ebx, [IP_LIST + edi]
and ebx, [SUBNET_LIST + edi] and ebx, [SUBNET_LIST + edi]
mov ecx, eax mov ecx, eax
and ecx, [SUBNET_LIST + edi] and ecx, [SUBNET_LIST + edi]
cmp ecx, ebx cmp ecx, ebx
je .local je .local
mov eax, [GATEWAY_LIST + edi] mov eax, [GATEWAY_LIST + edi]
DEBUGF 1,"requested IP is not on subnet, using default gateway\n" DEBUGF 1,"requested IP is not on subnet, using default gateway\n"
;-------------------------------- ;--------------------------------
; Try to find the IP in ARP_table ; Try to find the IP in ARP_table
.local: .local:
mov ecx, [NumARP] mov ecx, [NumARP]
test ecx, ecx test ecx, ecx
jz .not_in_list jz .not_in_list
mov esi, ARP_table + ARP_entry.IP mov esi, ARP_table + ARP_entry.IP
.scan_loop: .scan_loop:
cmp [esi], eax cmp [esi], eax
je .found_it je .found_it
add esi, sizeof.ARP_entry add esi, sizeof.ARP_entry
loop .scan_loop loop .scan_loop
.not_in_list: .not_in_list:
DEBUGF 1,"IP not found on list, preparing for ARP request\n" DEBUGF 1,"IP not found on list, preparing for ARP request\n"
;-------------------- ;--------------------
; Send an ARP request ; Send an ARP request
push eax push eax
pushw ARP_REQUEST_TTL pushw ARP_REQUEST_TTL
pushw ARP_AWAITING_RESPONSE pushw ARP_AWAITING_RESPONSE
pushd 0 pushd 0
pushw 0 pushw 0
pushd eax pushd eax
mov esi, esp mov esi, esp
call ARP_add_entry call ARP_add_entry
add esp, sizeof.ARP_entry add esp, sizeof.ARP_entry
cmp eax, -1 cmp eax, -1
je .full je .full
mov ecx, eax mov ecx, eax
pop eax pop eax
push ecx push ecx
call ARP_output_request call ARP_output_request
;; TODO: check if driver could transmit packet ;; TODO: check if driver could transmit packet
pop esi pop esi
imul esi, sizeof.ARP_entry imul esi, sizeof.ARP_entry
add esi, ARP_table add esi, ARP_table
mov ecx, 25 mov ecx, 25
.wait_loop: .wait_loop:
cmp [esi + ARP_entry.Status], 1 cmp [esi + ARP_entry.Status], 1
je .got_it je .got_it
push esi push esi
mov esi, 10 mov esi, 10
call delay_ms call delay_ms
pop esi pop esi
loop .wait_loop loop .wait_loop
mov eax, -2 ; request send mov eax, -2 ; request send
ret ret
.found_it: .found_it:
DEBUGF 1,"found IP in ARPTable\n" DEBUGF 1,"found IP in ARPTable\n"
cmp [esi + ARP_entry.Status], 1 cmp [esi + ARP_entry.Status], 1
jne .invalid jne .invalid
.got_it: .got_it:
movzx eax, word [esi + ARP_entry.MAC] movzx eax, word [esi + ARP_entry.MAC]
mov ebx, dword[esi + ARP_entry.MAC+2] mov ebx, dword[esi + ARP_entry.MAC+2]
ret ret
.invalid: .invalid:
mov eax, -1 mov eax, -1
ret ret
.full: .full:
DEBUGF 1,"ARP table is full!\n" DEBUGF 1,"ARP table is full!\n"
pop eax pop eax
mov eax, -1 mov eax, -1
ret ret
.broadcast: .broadcast:
mov eax, 0x0000ffff mov eax, 0x0000ffff
mov ebx, 0xffffffff mov ebx, 0xffffffff
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
@ -569,66 +569,66 @@ ARP_IP_to_MAC:
align 4 align 4
ARP_API: ARP_API:
movzx eax, bh movzx eax, bh
shl eax, 2 shl eax, 2
test bl, bl test bl, bl
jz .packets_tx ; 0 jz .packets_tx ; 0
dec bl dec bl
jz .packets_rx ; 1 jz .packets_rx ; 1
dec bl dec bl
jz .entries ; 2 jz .entries ; 2
dec bl dec bl
jz .read ; 3 jz .read ; 3
dec bl dec bl
jz .write ; 4 jz .write ; 4
dec bl dec bl
jz .remove ; 5 jz .remove ; 5
dec bl dec bl
.error: .error:
mov eax, -1 mov eax, -1
ret ret
.packets_tx: .packets_tx:
add eax, ARP_PACKETS_TX add eax, ARP_PACKETS_TX
mov eax, [eax] mov eax, [eax]
ret ret
.packets_rx: .packets_rx:
add eax, ARP_PACKETS_RX add eax, ARP_PACKETS_RX
mov eax, [eax] mov eax, [eax]
ret ret
.entries: .entries:
mov eax, [NumARP] mov eax, [NumARP]
ret ret
.read: .read:
cmp ecx, [NumARP] cmp ecx, [NumARP]
jae .error jae .error
; edi = pointer to buffer ; edi = pointer to buffer
; ecx = # entry ; ecx = # entry
imul ecx, sizeof.ARP_entry imul ecx, sizeof.ARP_entry
add ecx, ARP_table add ecx, ARP_table
mov esi, ecx mov esi, ecx
mov ecx, sizeof.ARP_entry/2 mov ecx, sizeof.ARP_entry/2
rep movsw rep movsw
xor eax, eax xor eax, eax
ret ret
.write: .write:
; esi = pointer to buffer ; esi = pointer to buffer
call ARP_add_entry ;out: eax = entry number, -1 on error call ARP_add_entry ;out: eax = entry number, -1 on error
ret ret
.remove: .remove:
; ecx = # entry ; ecx = # entry
cmp ecx, [NumARP] cmp ecx, [NumARP]
jae .error jae .error
imul ecx, sizeof.ARP_entry imul ecx, sizeof.ARP_entry
lea esi, [ARP_table + ecx] lea esi, [ARP_table + ecx]
call ARP_del_entry call ARP_del_entry
ret ret

View File

@ -16,33 +16,33 @@
$Revision$ $Revision$
struct ETH_header struct ETH_header
DstMAC dp ? ; destination MAC-address DstMAC dp ? ; destination MAC-address
SrcMAC dp ? ; source MAC-address SrcMAC dp ? ; source MAC-address
Type dw ? ; type of the upper-layer protocol Type dw ? ; type of the upper-layer protocol
ends ends
ETH_FRAME_MINIMUM equ 60 ETH_FRAME_MINIMUM equ 60
struct ETH_DEVICE NET_DEVICE struct ETH_DEVICE NET_DEVICE
set_mode dd ? set_mode dd ?
get_mode dd ? get_mode dd ?
set_MAC dd ? set_MAC dd ?
get_MAC dd ? get_MAC dd ?
mode dd ? mode dd ?
mac dp ? mac dp ?
ends ends
align 4 align 4
iglobal iglobal
ETH_BROADCAST dp 0xffffffffffff ETH_BROADCAST dp 0xffffffffffff
endg endg
;----------------------------------------------------------------- ;-----------------------------------------------------------------
@ -60,33 +60,33 @@ endg
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_input: ETH_input:
mov eax, [esp] mov eax, [esp]
mov ecx, [esp+4] mov ecx, [esp+4]
DEBUGF 1,"ETH_input - size: %u\n", ecx DEBUGF 1,"ETH_input - size: %u\n", ecx
cmp ecx, ETH_FRAME_MINIMUM cmp ecx, ETH_FRAME_MINIMUM
jb .dump jb .dump
sub ecx, sizeof.ETH_header sub ecx, sizeof.ETH_header
lea edx, [eax + sizeof.ETH_header] lea edx, [eax + sizeof.ETH_header]
mov ax , [eax + ETH_header.Type] mov ax , [eax + ETH_header.Type]
cmp ax, ETHER_IPv4 cmp ax, ETHER_IPv4
je IPv4_input je IPv4_input
cmp ax, ETHER_ARP cmp ax, ETHER_ARP
je ARP_input je ARP_input
; cmp ax, ETHER_PPP_DISCOVERY ; cmp ax, ETHER_PPP_DISCOVERY
; je PPPOE_discovery ; je PPPOE_discovery
DEBUGF 2,"Unknown ethernet packet type %x\n", ax DEBUGF 2,"Unknown ethernet packet type %x\n", ax
.dump: .dump:
DEBUGF 2,"ETH_input - dumping\n" DEBUGF 2,"ETH_input - dumping\n"
call kernel_free call kernel_free
add esp, 4 add esp, 4
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
@ -108,60 +108,53 @@ ETH_input:
align 4 align 4
ETH_output: ETH_output:
DEBUGF 1,"ETH_output: size=%u device:%x\n", ecx, ebx DEBUGF 1,"ETH_output: size=%u device:%x\n", ecx, ebx
cmp ecx, [ebx + NET_DEVICE.mtu] cmp ecx, [ebx + NET_DEVICE.mtu]
ja .exit ja .exit
push ecx ; << 1 push ecx
push di eax edx ; << 2 push di eax edx
add ecx, sizeof.ETH_header
push ecx ; << 3 add ecx, sizeof.ETH_header
stdcall kernel_alloc, ecx
test eax, eax
jz .out_of_ram
mov edi, eax
push ecx ; << 4 pop esi
call kernel_alloc ; >> 4 movsd
test eax, eax movsw
jz .out_of_ram pop esi
mov edi, eax movsd
movsw
pop ax
stosw
pop ecx ; >> 3 lea eax, [edi - sizeof.ETH_header] ; Set eax to buffer start
pop ecx
lea edx, [ecx + sizeof.ETH_header] ; Set edx to complete buffer size
pop esi ; >> 2 cmp edx, ETH_FRAME_MINIMUM
movsd jb .adjust_size
movsw DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx
pop esi ; >> 2 ret
movsd
movsw
pop ax ; >> 2
stosw
lea eax, [edi - sizeof.ETH_header] ; Set eax to buffer start
mov edx, ecx ; Set edx to complete buffer size
pop ecx ; >> 1
cmp edx, ETH_FRAME_MINIMUM
jb .adjust_size
DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx
ret
.adjust_size: .adjust_size:
mov edx, ETH_FRAME_MINIMUM mov edx, ETH_FRAME_MINIMUM
test edx, edx ; clear zero flag test edx, edx ; clear zero flag
ret ret
.out_of_ram: .out_of_ram:
DEBUGF 2,"ETH_output: Out of ram space!!\n" DEBUGF 2,"ETH_output: Out of ram space!!\n"
add esp, 3*4+2+4 add esp, 4+4+2+4
sub edi, edi sub edi, edi
ret ret
.exit: .exit:
DEBUGF 2,"ETH_output: Packet too large!\n" DEBUGF 2,"ETH_output: Packet too large!\n"
sub edi, edi sub edi, edi
;;; dec edi ret
ret
@ -181,64 +174,64 @@ ETH_output:
align 4 align 4
ETH_API: ETH_API:
cmp bh, MAX_NET_DEVICES cmp bh, MAX_NET_DEVICES
ja .error ja .error
movzx eax, bh movzx eax, bh
shl eax, 2 shl eax, 2
mov eax, dword [NET_DRV_LIST + eax] mov eax, dword [NET_DRV_LIST + eax]
cmp [eax + NET_DEVICE.type], NET_TYPE_ETH cmp [eax + NET_DEVICE.type], NET_TYPE_ETH
jne .error jne .error
test bl, bl test bl, bl
jz .packets_tx ; 0 jz .packets_tx ; 0
dec bl dec bl
jz .packets_rx ; 1 jz .packets_rx ; 1
dec bl dec bl
jz .bytes_tx ; 2 jz .bytes_tx ; 2
dec bl dec bl
jz .bytes_rx ; 3 jz .bytes_rx ; 3
dec bl dec bl
jz .read_mac ; 4 jz .read_mac ; 4
dec bl dec bl
jz .write_mac ; 5 jz .write_mac ; 5
.error: .error:
DEBUGF 2,"Device is not ethernet type\n" DEBUGF 2,"Device is not ethernet type\n"
or eax, -1 or eax, -1
ret ret
.packets_tx: .packets_tx:
mov eax, [eax + NET_DEVICE.packets_tx] mov eax, [eax + NET_DEVICE.packets_tx]
ret ret
.packets_rx: .packets_rx:
mov eax, [eax + NET_DEVICE.packets_rx] mov eax, [eax + NET_DEVICE.packets_rx]
ret ret
.bytes_tx: .bytes_tx:
mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4] mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4]
mov eax, dword [eax + NET_DEVICE.bytes_tx] mov eax, dword [eax + NET_DEVICE.bytes_tx]
mov [esp+20+4], ebx ; TODO: fix this ugly code mov [esp+20+4], ebx ; TODO: fix this ugly code
ret ret
.bytes_rx: .bytes_rx:
mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4] mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4]
mov eax, dword [eax + NET_DEVICE.bytes_rx] mov eax, dword [eax + NET_DEVICE.bytes_rx]
mov [esp+20+4], ebx ; TODO: fix this ugly code mov [esp+20+4], ebx ; TODO: fix this ugly code
ret ret
.read_mac: .read_mac:
movzx ebx, word [eax + ETH_DEVICE.mac] movzx ebx, word [eax + ETH_DEVICE.mac]
mov eax, dword [eax + ETH_DEVICE.mac + 2] mov eax, dword [eax + ETH_DEVICE.mac + 2]
mov [esp+20+4], ebx ; TODO: fix this ugly code mov [esp+20+4], ebx ; TODO: fix this ugly code
ret ret
.write_mac: .write_mac:
push ecx push ecx
push dx push dx
call [eax + ETH_DEVICE.set_MAC] call [eax + ETH_DEVICE.set_MAC]
ret ret

View File

@ -89,19 +89,19 @@ ICMP_PHOTURIS_DECRYPT_FAILED equ 3 ; decrypt failed
struct ICMP_header struct ICMP_header
Type db ? Type db ?
Code db ? Code db ?
Checksum dw ? Checksum dw ?
Identifier dw ? Identifier dw ?
SequenceNumber dw ? SequenceNumber dw ?
ends ends
align 4 align 4
uglobal uglobal
ICMP_PACKETS_TX rd MAX_IP ICMP_PACKETS_TX rd MAX_IP
ICMP_PACKETS_RX rd MAX_IP ICMP_PACKETS_RX rd MAX_IP
endg endg

View File

@ -138,7 +138,7 @@ struct UDP_SOCKET IP_SOCKET
ends ends
struct ICMP_SOCKET struct ICMP_SOCKET IP_SOCKET
Identifier dw ? Identifier dw ?
@ -146,11 +146,13 @@ ends
struct RING_BUFFER struct RING_BUFFER
start_ptr dd ? ; Pointer to start of buffer start_ptr dd ? ; Pointer to start of buffer
end_ptr dd ? ; pointer to end of buffer end_ptr dd ? ; pointer to end of buffer
read_ptr dd ? ; Read pointer read_ptr dd ? ; Read pointer
write_ptr dd ? ; Write pointer write_ptr dd ? ; Write pointer
size dd ? ; Number of bytes buffered size dd ? ; Number of bytes buffered
ends ends
struct STREAM_SOCKET TCP_SOCKET struct STREAM_SOCKET TCP_SOCKET
@ -320,7 +322,6 @@ align 4
mov [eax + SOCKET.snd_proc], SOCKET_send_tcp mov [eax + SOCKET.snd_proc], SOCKET_send_tcp
mov [eax + SOCKET.rcv_proc], SOCKET_receive_tcp mov [eax + SOCKET.rcv_proc], SOCKET_receive_tcp
mov [eax + TCP_SOCKET.t_maxseg], 1480 ;;;;; FIXME mov [eax + TCP_SOCKET.t_maxseg], 1480 ;;;;; FIXME
ret ret

View File

@ -172,7 +172,7 @@ UDP_input:
@@: @@:
cmp [eax + UDP_SOCKET.firstpacket], 0 cmp [eax + UDP_SOCKET.firstpacket], 0
jz .updateport je .updateport
cmp [eax + UDP_SOCKET.RemotePort], cx cmp [eax + UDP_SOCKET.RemotePort], cx
jne .dump jne .dump
@ -197,9 +197,8 @@ UDP_input:
call wait_mutex call wait_mutex
pop ebx pop ebx
mov si, [edx + UDP_header.SourcePort] DEBUGF 1,"Changing remote port to: %u\n", cx
DEBUGF 1,"Changing remote port to: %u\n", si mov [eax + UDP_SOCKET.RemotePort], cx
mov [eax + UDP_SOCKET.RemotePort], si
inc [eax + UDP_SOCKET.firstpacket] inc [eax + UDP_SOCKET.firstpacket]
jmp .updatesock jmp .updatesock
@ -323,11 +322,9 @@ UDP_API:
ret ret
.packets_tx: .packets_tx:
add eax, UDP_PACKETS_TX mov eax, [UDP_PACKETS_TX + eax]
mov eax, [eax]
ret ret
.packets_rx: .packets_rx:
add eax, UDP_PACKETS_RX mov eax, [UDP_PACKETS_RX + eax]
mov eax, [eax]
ret ret