Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1529 → Rev 1530

/kernel/branches/net/network/ARP.inc
499,10 → 499,25
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
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
ret
 
 
 
;-----------------------------------------------------------------
;
; ARP_API
/kernel/branches/net/network/IPv4.inc
54,8 → 54,67
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 {
 
; This is the fast procedure to create or check a IP header without options
120,69 → 179,8
 
 
 
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:
;
; Will check if IP Packet isnt damaged
608,6 → 606,8
test eax, 0xffff0000 ; error bits
jnz .arp_error
 
.continue:
 
push ebx ; push the mac
push ax
 
/kernel/branches/net/network/tcp.inc
240,16 → 240,16
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
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
 
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
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
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
; 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
/kernel/branches/net/network/udp.inc
50,22 → 50,20
}
 
 
 
 
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
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