forked from KolibriOS/kolibrios
Fixed bugs in previous revision
git-svn-id: svn://kolibrios.org@1530 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
fab920c5c8
commit
5e2d9e4b59
@ -499,10 +499,25 @@ ARP_IP_to_MAC:
|
||||
cmp eax, -1
|
||||
je .full
|
||||
|
||||
mov ecx, eax
|
||||
pop eax
|
||||
|
||||
push ecx
|
||||
call ARP_output_request
|
||||
|
||||
;; TODO: check if driver could transmit packet
|
||||
|
||||
pop eax
|
||||
imul eax, ARP_ENTRY.size
|
||||
add eax, ARP_table
|
||||
|
||||
mov ecx, 25
|
||||
.wait_loop:
|
||||
cmp [eax + ARP_ENTRY.Status], 1
|
||||
je .got_it
|
||||
mov esi, 10
|
||||
call delay_ms
|
||||
loop .wait_loop
|
||||
|
||||
mov eax, -2 ; request send
|
||||
ret
|
||||
|
||||
@ -511,6 +526,7 @@ ARP_IP_to_MAC:
|
||||
cmp [esi + ARP_ENTRY.Status], 1
|
||||
jne .invalid
|
||||
|
||||
.got_it:
|
||||
movzx eax, word [esi+ARP_ENTRY.MAC]
|
||||
mov ebx, dword[esi+ARP_ENTRY.MAC+2]
|
||||
ret
|
||||
@ -531,7 +547,6 @@ ARP_IP_to_MAC:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ARP_API
|
||||
|
@ -54,6 +54,65 @@ struct FRAGMENT_entry ; This structure will replace the ethernet header
|
||||
ends
|
||||
|
||||
|
||||
align 4
|
||||
uglobal
|
||||
|
||||
IP_LIST rd MAX_IP
|
||||
SUBNET_LIST rd MAX_IP
|
||||
DNS_LIST rd MAX_IP
|
||||
GATEWAY_LIST rd MAX_IP
|
||||
|
||||
IP_PACKETS_TX rd MAX_IP
|
||||
IP_PACKETS_RX rd MAX_IP
|
||||
|
||||
FRAGMENT_LIST rb MAX_FRAGMENTS*FRAGMENT_slot.size
|
||||
endg
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; IPv4_init
|
||||
;
|
||||
; This function resets all IP variables
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
macro IPv4_init {
|
||||
|
||||
xor eax, eax
|
||||
mov edi, IP_LIST
|
||||
mov ecx, 4*MAX_IP
|
||||
rep stosd
|
||||
|
||||
mov edi, FRAGMENT_LIST
|
||||
mov ecx, FRAGMENT_slot.size*MAX_FRAGMENTS/4 + 2*MAX_IP
|
||||
rep stosd
|
||||
|
||||
}
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; Decrease TimeToLive of all fragment slots
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
macro IPv4_decrease_fragment_ttls {
|
||||
|
||||
local .loop
|
||||
|
||||
mov esi, FRAGMENT_LIST
|
||||
mov ecx, MAX_FRAGMENTS
|
||||
.loop:
|
||||
cmp [esi + FRAGMENT_slot.ttl], 0
|
||||
je .try_next
|
||||
dec [esi + FRAGMENT_slot.ttl]
|
||||
jnz .try_next
|
||||
DEBUGF 1,"Fragment slot timed-out!\n"
|
||||
;;; TODO: clear all entry's of timed-out slot
|
||||
.try_next:
|
||||
add esi, 4
|
||||
loop .loop
|
||||
}
|
||||
|
||||
|
||||
|
||||
macro IPv4_checksum ptr {
|
||||
@ -120,67 +179,6 @@ macro IPv4_checksum ptr {
|
||||
|
||||
|
||||
|
||||
align 4
|
||||
uglobal
|
||||
|
||||
IP_LIST rd MAX_IP
|
||||
SUBNET_LIST rd MAX_IP
|
||||
DNS_LIST rd MAX_IP
|
||||
GATEWAY_LIST rd MAX_IP
|
||||
|
||||
IP_PACKETS_TX rd MAX_IP
|
||||
IP_PACKETS_RX rd MAX_IP
|
||||
|
||||
FRAGMENT_LIST rb MAX_FRAGMENTS*FRAGMENT_slot.size
|
||||
endg
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; IPv4_init
|
||||
;
|
||||
; This function resets all IP variables
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
macro IPv4_init {
|
||||
|
||||
xor eax, eax
|
||||
mov edi, IP_LIST
|
||||
mov ecx, 4*MAX_IP
|
||||
rep stosd
|
||||
|
||||
mov edi, FRAGMENT_LIST
|
||||
mov ecx, FRAGMENT_slot.size*MAX_FRAGMENTS/4 + 2*MAX_IP
|
||||
rep stosd
|
||||
|
||||
}
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; Decrease TimeToLive of all fragment slots
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
macro IPv4_decrease_fragment_ttls {
|
||||
|
||||
local .loop
|
||||
|
||||
mov esi, FRAGMENT_LIST
|
||||
mov ecx, MAX_FRAGMENTS
|
||||
.loop:
|
||||
cmp [esi + FRAGMENT_slot.ttl], 0
|
||||
je .try_next
|
||||
dec [esi + FRAGMENT_slot.ttl]
|
||||
jnz .try_next
|
||||
DEBUGF 1,"Fragment slot timed-out!\n"
|
||||
;;; TODO: clear all entry's of timed-out slot
|
||||
.try_next:
|
||||
add esi, 4
|
||||
loop .loop
|
||||
}
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; IPv4_input:
|
||||
@ -608,6 +606,8 @@ IPv4_output:
|
||||
test eax, 0xffff0000 ; error bits
|
||||
jnz .arp_error
|
||||
|
||||
.continue:
|
||||
|
||||
push ebx ; push the mac
|
||||
push ax
|
||||
|
||||
|
@ -240,16 +240,16 @@ macro TCP_checksum IP1, IP2 {
|
||||
mov edx, IP_PROTO_TCP
|
||||
|
||||
; source address
|
||||
add dl, byte [IP1+1+4]
|
||||
adc dh, byte [IP1+0+4]
|
||||
adc dl, byte [IP1+3+4]
|
||||
adc dh, byte [IP1+2+4]
|
||||
add dl, byte [IP1+1]
|
||||
adc dh, byte [IP1+0]
|
||||
adc dl, byte [IP1+3]
|
||||
adc dh, byte [IP1+2]
|
||||
|
||||
; destination address
|
||||
adc dl, byte [IP2+1+8]
|
||||
adc dh, byte [IP2+0+8]
|
||||
adc dl, byte [IP2+3+8]
|
||||
adc dh, byte [IP2+2+8]
|
||||
adc dl, byte [IP2+1]
|
||||
adc dh, byte [IP2+0]
|
||||
adc dl, byte [IP2+3]
|
||||
adc dh, byte [IP2+2]
|
||||
|
||||
; size
|
||||
adc dl, cl
|
||||
@ -306,7 +306,7 @@ TCP_input:
|
||||
mov [edx + TCP_segment.Checksum], 0
|
||||
push esi edi
|
||||
mov esi, edx
|
||||
TCP_checksum
|
||||
TCP_checksum (esp), (esp+4)
|
||||
pop esi edi ; yes, swap them (we dont need dest addr)
|
||||
pop cx ; previous checksum
|
||||
cmp cx, dx
|
||||
@ -437,7 +437,7 @@ TCP_input:
|
||||
|
||||
DEBUGF 1,"Segment has options\n"
|
||||
|
||||
test [ebx + TCP_SOCKET.t_state], TCB_LISTEN ; no options when in listen state
|
||||
cmp [ebx + TCP_SOCKET.t_state], TCB_LISTEN ; no options when in listen state
|
||||
jz .no_options
|
||||
|
||||
lea edi, [edx + TCP_segment.Data]
|
||||
@ -475,9 +475,12 @@ TCP_input:
|
||||
test [edx + TCP_segment.Flags], TH_SYN
|
||||
jz @f
|
||||
|
||||
DEBUGF 1,"Got maxseg option"
|
||||
movzx eax, word[edi+2]
|
||||
rol ax, 8
|
||||
DEBUGF 1,"Maxseg: %u", ax
|
||||
|
||||
mov [ebx + TCP_SOCKET.t_maxseg], eax
|
||||
|
||||
;;;;;
|
||||
@@:
|
||||
add edi, 4
|
||||
jmp .opt_loop
|
||||
@ -1758,8 +1761,8 @@ TCP_output:
|
||||
pop ecx
|
||||
add esp, ecx
|
||||
|
||||
mov [esp + 3*4+4], edx ; packet size
|
||||
mov [esp + 3*4], eax ; packet ptr
|
||||
mov [esp + 4+4], edx ; packet size
|
||||
mov [esp + 4], eax ; packet ptr
|
||||
|
||||
mov edx, edi
|
||||
sub edx, ecx
|
||||
@ -1782,8 +1785,6 @@ TCP_output:
|
||||
; Create the checksum (we have already pushed IPs onto stack)
|
||||
|
||||
DEBUGF 1,"checksum: ptr=%x size=%u\n", esi, ecx
|
||||
DEBUGF 1,"ip=%x\n", [esp]:8
|
||||
DEBUGF 1,"ip=%x\n", [esp+4]:8
|
||||
|
||||
TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP)
|
||||
mov [esi+TCP_segment.Checksum], dx
|
||||
|
@ -50,22 +50,20 @@ macro UDP_init {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size, destroys: ecx, edx
|
||||
|
||||
; Pseudoheader
|
||||
mov edx, IP_PROTO_UDP
|
||||
|
||||
add dl, [IP1+1+4]
|
||||
adc dh, [IP1+0+4]
|
||||
adc dl, [IP1+3+4]
|
||||
adc dh, [IP1+2+4]
|
||||
add dl, [IP1+1]
|
||||
adc dh, [IP1+0]
|
||||
adc dl, [IP1+3]
|
||||
adc dh, [IP1+2]
|
||||
|
||||
adc dl, [IP2+1+8]
|
||||
adc dh, [IP2+0+8]
|
||||
adc dl, [IP2+3+8]
|
||||
adc dh, [IP2+2+8]
|
||||
adc dl, [IP2+1]
|
||||
adc dh, [IP2+0]
|
||||
adc dl, [IP2+3]
|
||||
adc dh, [IP2+2]
|
||||
|
||||
adc dl, cl ; byte[esi+UDP_Packet.Length+1]
|
||||
adc dh, ch ; byte[esi+UDP_Packet.Length+0]
|
||||
@ -123,7 +121,7 @@ UDP_input:
|
||||
DEBUGF 1,"UDP_input, size:%u\n", ecx
|
||||
|
||||
; First validate, checksum:
|
||||
neg [esi+UDP_Packet.Checksum] ; substract chechksum from 0
|
||||
neg [edx+UDP_Packet.Checksum] ; substract chechksum from 0
|
||||
jz .no_checksum ; if checksum is zero, it is considered valid and we continue processing
|
||||
; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user