Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5200 → Rev 5201

/kernel/branches/Kolibri-acpi/network/ARP.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; ARP.INC ;;
318,10 → 318,9
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: ip=%u.%u.%u.%u device=0x%x\n",\
[esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1, ebx
 
lea eax, [ebx + ETH_DEVICE.mac] ; local device mac
mov ax, ETHER_PROTO_ARP
mov ecx, sizeof.ARP_header
mov edx, ETH_BROADCAST ; broadcast mac
mov ecx, sizeof.ARP_header
mov di, ETHER_PROTO_ARP
call ETH_output
jz .exit
 
/kernel/branches/Kolibri-acpi/network/IPv4.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; IPv4.INC ;;
267,10 → 267,9
cmp eax, 224
je .ip_ok
 
; or a loopback address (127.0.0.0/8)
; maybe we just dont have an IP yet and should accept everything on the IP level
 
and eax, 0x00ffffff
cmp eax, 127
cmp [IP_LIST + edi], 0
je .ip_ok
 
; or it's just not meant for us.. :(
577,11 → 576,11
; edx = Source IP
; di = TTL shl 8 + protocol
;
; OUT: eax = pointer to buffer start
; ebx = pointer to device struct (needed for sending procedure)
; ecx = unchanged (packet size of embedded data)
; edx = size of complete buffer
; edi = pointer to start of data (0 on error)
; OUT: eax = pointer to buffer start / 0 on error
; ebx = device ptr (send packet through this device)
; ecx = data length
; edx = size of complete frame
; edi = start of IPv4 payload
;
;------------------------------------------------------------------
align 4
595,7 → 594,6
push ecx di eax
call IPv4_route ; outputs device number in edi, dest ip in eax, source IP in edx
push edx
 
test edi, edi
jz .loopback
 
607,12 → 605,11
 
inc [IPv4_packets_tx + edi] ; update stats
 
mov ax, ETHER_PROTO_IPv4
mov ebx, [NET_DRV_LIST + edi]
lea eax, [ebx + ETH_DEVICE.mac]
mov edx, esp
mov ecx, [esp + 6 + 8 + 2]
add ecx, sizeof.IPv4_header
mov di, ETHER_PROTO_IPv4
mov edx, esp
call ETH_output
jz .eth_error
add esp, 6 ; pop the mac out of the stack
642,18 → 639,18
.eth_error:
DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ethernet error\n"
add esp, 3*4+2+6
xor edi, edi
xor eax, eax
ret
 
.arp_error:
DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ARP error=%x\n", eax
add esp, 3*4+2
xor edi, edi
xor eax, eax
ret
 
.too_large:
DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: Packet too large!\n"
xor edi, edi
xor eax, eax
ret
 
.loopback:
675,7 → 672,7
; ecx = data length
; esi = data ptr
;
; OUT: /
; OUT: eax = -1 on error
;
;------------------------------------------------------------------
align 4
699,15 → 696,13
push ax
 
inc [IPv4_packets_tx + 4*edi]
mov ax, ETHER_PROTO_IPv4
mov ebx, [NET_DRV_LIST + 4*edi]
lea eax, [ebx + ETH_DEVICE.mac]
mov edx, esp
mov ecx, [esp + 6 + 4]
add ecx, sizeof.IPv4_header
mov di, ETHER_PROTO_IPv4
mov edx, esp
call ETH_output
jz .error
 
add esp, 6 ; pop the mac
 
mov dword[esp+4+4], edx
746,7 → 741,7
add esp, 8+4+4
.too_large:
DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output_raw: Failed\n"
sub edi, edi
or eax, -1
ret
 
 
795,13 → 790,9
.new_fragment:
DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: new fragment"
 
 
mov eax, [esp + 3*4]
mov ax, ETHER_PROTO_IPv4
lea ebx, [esp + 4*4]
mov di , ETHER_PROTO_IPv4
call ETH_output
 
cmp edi, -1
jz .err
 
; copy header
/kernel/branches/Kolibri-acpi/network/PPPoE.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2012-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2012-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; PPPoE.INC ;;
14,6 → 14,9
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
$Revision: 5015 $
 
 
struct PPPoE_frame
VersionAndType db ?
Code db ?
240,17 → 243,15
;
; PPPoE_output
;
; IN:
; IN: ax = protocol
; ebx = device ptr
; ecx = packet size
;
; di = protocol
;
; OUT: edi = 0 on error, pointer to buffer otherwise
; eax = buffer start
; ebx = to device structure
; ecx = unchanged (packet size of embedded data)
; OUT: eax = buffer start / 0 on error
; ebx = device ptr
; ecx = packet size
; edx = size of complete buffer
; edi = start of PPP payload
;
;-----------------------------------------------------------------
align 4
258,13 → 259,12
 
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: size=%u device=%x\n", ecx, ebx
 
pushw di
pushw ax
pushw [PPPoE_SID]
 
lea eax, [ebx + ETH_DEVICE.mac]
mov ax, ETHER_PROTO_PPP_SESSION
add ecx, PPPoE_frame.Payload + 2
lea edx, [PPPoE_MAC]
add ecx, PPPoE_frame.Payload + 2
mov di, ETHER_PROTO_PPP_SESSION
call ETH_output
jz .eth_error
 
287,8 → 287,7
 
.eth_error:
add esp, 4
xor edi, edi
 
xor eax, eax
ret
 
 
/kernel/branches/Kolibri-acpi/network/ethernet.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; ETHERNET.INC ;;
86,11 → 86,7
push ebx
mov esi, esp
 
pushf
cli
add_to_queue ETH_queue, ETH_QUEUE_SIZE, sizeof.ETH_queue_entry, .fail
popf
 
add esp, sizeof.ETH_queue_entry
 
xor edx, edx
102,10 → 98,9
ret
 
.fail:
popf
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH incoming queue is full, discarding packet!\n"
DEBUGF DEBUG_NETWORK_ERROR, "ETH incoming queue is full, discarding packet!\n"
 
add esp, sizeof.ETH_queue_entry - 8
pop ebx
call NET_packet_free
add esp, 4
 
150,14 → 145,14
cmp ax, ETHER_PROTO_ARP
je ARP_input
 
cmp ax, ETHER_PROTO_IPv6
je IPv6_input
; cmp ax, ETHER_PROTO_IPv6
; je IPv6_input
 
cmp ax, ETHER_PROTO_PPP_DISCOVERY
je PPPoE_discovery_input
; cmp ax, ETHER_PROTO_PPP_DISCOVERY
; je PPPoE_discovery_input
 
cmp ax, ETHER_PROTO_PPP_SESSION
je PPPoE_session_input
; cmp ax, ETHER_PROTO_PPP_SESSION
; je PPPoE_session_input
 
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: Unknown packet type=%x\n", ax
 
171,17 → 166,16
;
; ETH_output
;
; IN: eax = pointer to source mac
; IN: ax = protocol
; ebx = device ptr
; ecx = packet size
; ecx = payload size
; edx = pointer to destination mac
; di = protocol
;
; OUT: edi = 0 on error, pointer to buffer otherwise
; eax = buffer start
; ebx = to device structure
; ecx = unchanged (packet size of embedded data)
; edx = size of complete buffer
; OUT: eax = start of ethernet frame / 0 on error
; ebx = device ptr
; ecx = payload size
; edx = ethernet frame size
; edi = start of ethernet payload
;
;-----------------------------------------------------------------
align 4
189,11 → 183,11
 
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: size=%u device=%x\n", ecx, ebx
 
cmp ecx, [ebx + NET_DEVICE.mtu]
cmp ecx, [ebx + ETH_DEVICE.mtu]
ja .exit
 
push ecx
push di eax edx
push ax edx
 
add ecx, sizeof.ETH_header
stdcall kernel_alloc, ecx
204,7 → 198,7
pop esi
movsd
movsw
pop esi
lea esi, [ebx + ETH_DEVICE.mac]
movsd
movsw
pop ax
227,13 → 221,13
 
.out_of_ram:
DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Out of ram!\n"
add esp, 4+4+2+4
sub edi, edi
add esp, 4+2+4
xor eax, eax
ret
 
.exit:
DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Packet too large!\n"
sub edi, edi
xor eax, eax
ret
 
 
/kernel/branches/Kolibri-acpi/network/icmp.inc
294,12 → 294,12
call mutex_unlock
popa
 
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input: no socket found\n"
DEBUGF DEBUG_NETWORK_ERROR, "ICMP_input: no socket found\n"
jmp .dump
 
 
.checksum_mismatch:
DEBUGF DEBUG_NETWORK_VERBOSE, "checksum mismatch\n"
DEBUGF DEBUG_NETWORK_ERROR, "ICMP_input: checksum mismatch\n"
 
.dump:
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input: dumping\n"
/kernel/branches/Kolibri-acpi/network/queue.inc
28,7 → 28,6
size dd ? ; number of queued packets in this queue
w_ptr dd ? ; current writing pointer in queue
r_ptr dd ? ; current reading pointer
mutex MUTEX
 
ends
 
47,18 → 46,12
 
local .ok, .no_wrap
 
pusha
lea ecx, [ptr + queue.mutex]
call mutex_lock
popa
spin_lock_irqsave
 
cmp [ptr + queue.size], size ; Check if queue isnt full
jb .ok
 
pusha
lea ecx, [ptr + queue.mutex]
call mutex_unlock
popa
spin_unlock_irqrestore
jmp failaddr
 
.ok:
76,10 → 69,7
.no_wrap:
mov [ptr + queue.w_ptr], edi
 
pusha
lea ecx, [ptr + queue.mutex]
call mutex_unlock
popa
spin_unlock_irqrestore
 
}
 
89,18 → 79,12
 
local .ok, .no_wrap
 
pusha
lea ecx, [ptr + queue.mutex]
call mutex_lock
popa
spin_lock_irqsave
 
cmp [ptr + queue.size], 0 ; any packets queued?
ja .ok
 
pusha
lea ecx, [ptr + queue.mutex]
call mutex_unlock
popa
spin_unlock_irqrestore
jmp failaddr
 
.ok:
122,10 → 106,7
 
pop esi
 
pusha
lea ecx, [ptr + queue.mutex]
call mutex_unlock
popa
spin_unlock_irqrestore
 
}
 
136,6 → 117,4
mov [ptr + queue.w_ptr], edi
mov [ptr + queue.r_ptr], edi
 
lea ecx, [ptr + queue.mutex]
call mutex_init
}
/kernel/branches/Kolibri-acpi/network/socket.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; Part of the TCP/IP network stack for KolibriOS ;;
293,6 → 293,7
push ecx edx esi
call SOCKET_alloc
pop esi edx ecx
test eax, eax
jz .nobuffs
 
mov [esp+32], edi ; return socketnumber
697,7 → 698,7
 
test [eax + SOCKET.state], SS_BLOCKED ; Is the socket still in blocked state?
jz @f
call SOCKET_notify.unblock ; Unblock it.
call SOCKET_notify ; Unblock it.
@@:
 
cmp [eax + SOCKET.Domain], AF_INET4
1192,6 → 1193,7
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_pair\n"
 
call SOCKET_alloc
test eax, eax
jz .nomem1
mov [esp+32], edi ; application's eax
 
1204,6 → 1206,7
mov ebx, eax
 
call SOCKET_alloc
test eax, eax
jz .nomem2
mov [esp+20], edi ; application's ebx
 
1220,10 → 1223,13
 
lea eax, [eax + STREAM_SOCKET.rcv]
call SOCKET_ring_create
test eax, eax
jz .nomem1
 
lea eax, [ebx + STREAM_SOCKET.rcv]
call SOCKET_ring_create
pop eax
test eax, eax
jz .nomem2
 
ret
 
1465,7 → 1471,8
 
;--------------------------
;
; eax = ptr to ring struct (just a buffer of the right size)
; IN: eax = ptr to ring struct (just a buffer of the right size)
; OUT: eax = unchanged / 0 on error
;
align 4
SOCKET_ring_create:
1476,6 → 1483,8
push edx
stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW
pop edx
test eax, eax
jz .fail
 
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_ring_created: %x\n", eax
 
1493,6 → 1502,7
mov eax, esi
pop esi
 
.fail:
ret
 
;-----------------------------------------------------------------
1536,6 → 1546,7
jb @f
sub edi, SOCKET_MAXDATA ; WRAP
@@:
 
mov [eax + RING_BUFFER.write_ptr], edi
pop edi
 
1707,8 → 1718,9
 
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_block: %x\n", eax
 
push eax
 
pushf
push eax
cli
 
; Set the 'socket is blocked' flag
1724,12 → 1736,12
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_block: suspending thread: %u\n", edx
mov [eax + SOCKET.TID], edx
pop edx
popf
 
call change_task
pop eax
popf
 
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_block: continueing\n"
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_block: continuing\n"
 
ret
 
1752,70 → 1764,54
call SOCKET_check
jz .error
 
test [eax + SOCKET.state], SS_BLOCKED
jnz .unblock
 
; test [eax + SOCKET.options], SO_NONBLOCK
; jz .error
 
push eax ecx esi
 
; socket exists and is of non blocking type.
; We'll try to flag an event to the thread
 
mov eax, [eax + SOCKET.TID]
test eax, eax
jz .done
mov ecx, 1
mov esi, TASK_DATA + TASKDATA.pid
 
.next_pid:
cmp [esi], eax
je .found_pid
; Find the associated thread's TASK_DATA
push ebx ecx esi
mov ebx, [eax + SOCKET.TID]
test ebx, ebx
jz .error2
xor ecx, ecx
inc ecx
mov esi, TASK_DATA
.next:
cmp [esi + TASKDATA.pid], ebx
je .found
inc ecx
add esi, 0x20
cmp ecx, [TASK_COUNT]
jbe .next_pid
jbe .next
 
.error2:
; PID not found, TODO: close socket!
jmp .done
DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_notify: error finding thread 0x%x !\n", ebx
pop esi ecx ebx
ret
 
.found_pid:
.error:
DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_notify: invalid socket ptr: 0x%x !\n", eax
ret
 
.found:
test [eax + SOCKET.state], SS_BLOCKED
jnz .un_block
 
; socket and thread exists and socket is of non blocking type.
; We'll try to flag an event to the thread.
shl ecx, 8
or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
 
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", eax
jmp .done
pop esi ecx ebx
ret
 
.unblock:
push eax ecx esi
; Clear the 'socket is blocked' flag
and [eax + SOCKET.state], not SS_BLOCKED
 
; Find the thread's TASK_DATA
mov eax, [eax + SOCKET.TID]
test eax, eax
jz .error
xor ecx, ecx
inc ecx
mov esi, TASK_DATA
.next:
cmp [esi + TASKDATA.pid], eax
je .found
inc ecx
add esi, 0x20
cmp ecx, [TASK_COUNT]
jbe .next
jmp .error
.found:
.un_block:
; socket and thread exists and socket is of blocking type
; We'll try to unblock it.
and [eax + SOCKET.state], not SS_BLOCKED ; Clear the 'socket is blocked' flag
mov [esi + TASKDATA.state], 0 ; Run the thread
 
; Run the thread
mov [esi + TASKDATA.state], 0 ; Running
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_notify: Unblocked socket!\n"
 
.done:
pop esi ecx eax
 
.error:
pop esi ecx ebx
ret
 
 
1830,7 → 1826,6
; IN: /
; OUT: eax = 0 on error, socket ptr otherwise
; edi = socket number
; ZF = cleared on error
;
;--------------------------------------------------------------------
align 4
1917,7 → 1912,6
@@:
 
mov [net_sockets + SOCKET.NextPtr], eax
or eax, eax ; used to clear zero flag
 
pusha
mov ecx, socket_mutex
1968,8 → 1962,14
jnz .no_tcp
 
mov ebx, eax
cmp [ebx + STREAM_SOCKET.rcv.start_ptr], 0
je @f
stdcall kernel_free, [ebx + STREAM_SOCKET.rcv.start_ptr]
@@:
cmp [ebx + STREAM_SOCKET.snd.start_ptr], 0
je @f
stdcall kernel_free, [ebx + STREAM_SOCKET.snd.start_ptr]
@@:
mov eax, ebx
.no_tcp:
 
2022,6 → 2022,7
push ebx
call SOCKET_alloc
pop ebx
test eax, eax
jz .fail
 
push eax
2101,7 → 2102,8
call mutex_unlock
popa
 
DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: not found\n", eax
DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: socket %u not found!\n", eax
DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: caller = 0x%x\n", [esp]
ret
 
 
2210,6 → 2212,8
align 4
SOCKET_process_end:
 
ret ; FIXME
 
cmp [net_sockets + SOCKET.NextPtr], 0 ; Are there any active sockets at all?
je .quickret ; nope, exit immediately
 
/kernel/branches/Kolibri-acpi/network/stack.inc
110,7 → 110,7
SS_BLOCKED = 0x8000
 
 
SOCKET_MAXDATA = 4096*8 ; must be 4096*(power of 2) where 'power of 2' is at least 8
SOCKET_MAXDATA = 4096*64 ; must be 4096*(power of 2) where 'power of 2' is at least 8
MAX_backlog = 20 ; maximum backlog for stream sockets
 
; Error Codes
313,10 → 313,15
test [net_10ms], 0x3f ; 640ms
jnz .exit
 
TCP_timer_640ms
ARP_decrease_entry_ttls
IPv4_decrease_fragment_ttls
 
xor edx, edx
mov eax, [TCP_timer1_event]
mov ebx, [eax + EVENT.id]
xor esi, esi
call raise_event
 
.exit:
ret
 
/kernel/branches/Kolibri-acpi/network/tcp.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; Part of the TCP/IP network stack for KolibriOS ;;
96,6 → 96,7
TCP_BIT_NEEDOUTPUT = 1 shl 0
TCP_BIT_TIMESTAMP = 1 shl 1
TCP_BIT_DROPSOCKET = 1 shl 2
TCP_BIT_FIN_IS_ACKED = 1 shl 3
 
TCP_BIT_SENDALOT = 1 shl 0
 
141,6 → 142,7
TCP_sequence_num dd ?
TCP_queue rd (TCP_QUEUE_SIZE*sizeof.TCP_queue_entry + sizeof.queue)/4
TCP_input_event dd ?
TCP_timer1_event dd ?
endg
 
uglobal
224,9 → 226,17
call new_sys_threads
test eax, eax
jns @f
DEBUGF DEBUG_NETWORK_ERROR,'K : cannot create kernel thread for TCP, error %d\n', eax
DEBUGF DEBUG_NETWORK_ERROR,'K : cannot create kernel thread for TCP input, error %d\n', eax
@@:
 
movi ebx, 1
mov ecx, TCP_timer_640ms
call new_sys_threads
test eax, eax
jns @f
DEBUGF DEBUG_NETWORK_ERROR,'K : cannot create kernel thread for TCP timer, error %d\n', eax
@@:
 
}
 
 
264,6 → 274,8
jz .packets_missed ; 2
dec bl
jz .packets_dumped ; 3
dec bl
jz .packets_queued ; 4
 
.error:
mov eax, -1
284,3 → 296,7
.packets_dumped:
mov eax, [TCP_segments_dumped + eax]
ret
 
.packets_queued:
mov eax, [TCP_queue + queue.size]
ret
/kernel/branches/Kolibri-acpi/network/tcp_input.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; Part of the TCP/IP network stack for KolibriOS ;;
7,7 → 7,7
;; ;;
;; Written by hidnplayr@kolibrios.org ;;
;; ;;
;; Based on the code of 4.4BSD ;;
;; Based on the algorithms used in 4.4BSD ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
14,7 → 14,7
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
$Revision: 3407 $
$Revision: 5155 $
 
;-----------------------------------------------------------------
;
43,11 → 43,7
push ebx ecx esi edi ; mind the order
mov esi, esp
 
pushf
cli
add_to_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, .fail
popf
 
add esp, sizeof.TCP_queue_entry
 
call NET_ptr_to_num4
62,7 → 58,6
ret
 
.fail:
popf
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP incoming queue is full, discarding packet!\n"
 
call NET_ptr_to_num4
536,12 → 531,10
cmp eax, [ebx + TCP_SOCKET.SND_UNA]
jne .not_uni_xfer
 
; - The reassembly list of out-of-order segments for the connection is empty (seg_next equals tp).
; - The reassembly list of out-of-order segments for the connection is empty.
cmp [ebx + TCP_SOCKET.seg_next], 0
jne .not_uni_xfer
 
;;; TODO
 
; jnz .not_uni_xfer
 
; Complete processing of received data
 
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: Header prediction: we are receiving %u bytes\n", ecx
845,7 → 838,7
pop word [ebx + TCP_SOCKET.SND_SCALE]
@@:
 
;;; TODO: call TCP_reassemble
call TCP_reassemble
 
mov eax, [edx + TCP_header.SequenceNumber]
dec eax
1099,8 → 1092,7
pop ebx edx ecx
 
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is acked\n"
stc
 
or [temp_bits], TCP_BIT_FIN_IS_ACKED
jmp .wakeup
 
.finiacked:
1114,19 → 1106,15
pop edx ecx
 
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is not acked\n"
clc
 
;----------------------------------------
; Wake up process waiting on send buffer
 
.wakeup:
 
pushf ; Keep the flags (Carry flag)
mov eax, ebx
call SOCKET_notify
 
; Update TCPS
 
mov eax, [edx + TCP_header.AckNumber]
mov [ebx + TCP_SOCKET.SND_UNA], eax
cmp eax, [ebx + TCP_SOCKET.SND_NXT]
1134,8 → 1122,6
mov [ebx + TCP_SOCKET.SND_NXT], eax
@@:
 
popf
 
; General ACK handling complete
; Now do the state-specific ones
; Carry flag is set when our FIN is acked
1158,7 → 1144,8
 
 
.ack_fw1:
jnc .ack_processed
test [temp_bits], TCP_BIT_FIN_IS_ACKED
jz .ack_processed
 
test [ebx + SOCKET.state], SS_CANTRCVMORE
jnz @f
1171,7 → 1158,8
jmp .ack_processed
 
.ack_c:
jnc .ack_processed
test [temp_bits], TCP_BIT_FIN_IS_ACKED
jz .ack_processed
 
mov [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
mov eax, ebx
1183,7 → 1171,8
jmp .ack_processed
 
.ack_la:
jnc .ack_processed
test [temp_bits], TCP_BIT_FIN_IS_ACKED
jz .ack_processed
 
push ebx
lea ecx, [ebx + SOCKET.mutex]
1246,9 → 1235,13
 
lea eax, [ebx + STREAM_SOCKET.snd]
call SOCKET_ring_create
test eax, eax
jz .drop
 
lea eax, [ebx + STREAM_SOCKET.rcv]
call SOCKET_ring_create
test eax, eax
jz .drop
 
and [temp_bits], not TCP_BIT_DROPSOCKET
 
1257,7 → 1250,7
call SOCKET_notify
popa
 
jmp .trim_then_step6
jmp .trim
 
;------------
; Active Open
1350,9 → 1343,9
 
mov eax, [ebx + TCP_SOCKET.t_rtt]
test eax, eax
je .trim_then_step6
je .trim
call TCP_xmit_timer
jmp .trim_then_step6
jmp .trim
 
.simultaneous_open:
 
1363,8 → 1356,7
;-------------------------------------
; Common processing for receipt of SYN
 
.trim_then_step6:
 
.trim:
inc [edx + TCP_header.SequenceNumber]
 
; Drop any received data that doesnt fit in the receive window.
1377,17 → 1369,12
;;; TODO: update stats
 
.dont_trim:
 
mov eax, [edx + TCP_header.SequenceNumber]
mov [ebx + TCP_SOCKET.RCV_UP], eax
dec eax
mov [ebx + TCP_SOCKET.SND_WL1], eax
 
;-------
; step 6
 
.ack_processed:
 
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: ACK processed\n"
 
;----------------------------------------------
1592,7 → 1579,7
jnz .need_output
 
test [eax + TCP_SOCKET.t_flags], TF_ACKNOW
jz .dumpit
jz .done
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: ACK now!\n"
 
.need_output:
1599,7 → 1586,7
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: need output\n"
call TCP_output
 
.dumpit:
.done:
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: dumping\n"
 
call NET_packet_free
1619,7 → 1606,7
pop eax edx
 
test [edx + TCP_header.Flags], TH_RST
jnz .dumpit
jnz .done
 
or [eax + TCP_SOCKET.t_flags], TF_ACKNOW
jmp .need_output
1633,7 → 1620,7
pop edx ebx
 
test [edx + TCP_header.Flags], TH_RST
jnz .dumpit
jnz .done
 
;;; if its a multicast/broadcast, also drop
 
1642,7 → 1629,7
 
test [edx + TCP_header.Flags], TH_SYN
jnz .respond_syn
jmp .dumpit
jmp .done
 
;---------
; Respond
1661,8 → 1648,10
pop ebx
jmp .destroy_new_socket
 
;-----------------------------------------
; The connection has no associated socket
 
.no_socket:
 
pusha
mov ecx, socket_mutex
call mutex_unlock
1692,8 → 1681,8
call TCP_respond_segment
jmp .drop_no_socket
 
;-----
; Drop
;------------------------------------------------
; Unlock socket mutex and prepare to drop segment
 
.drop:
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: Dropping segment\n"
1703,6 → 1692,9
call mutex_unlock
popa
 
;--------------------------------------------
; Destroy the newly created socket if needed
 
.destroy_new_socket:
test [temp_bits], TCP_BIT_DROPSOCKET
jz .drop_no_socket
1710,6 → 1702,9
mov eax, ebx
call SOCKET_free
 
;------------------
; Drop the segment
 
.drop_no_socket:
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: Drop (no socket)\n"
 
/kernel/branches/Kolibri-acpi/network/tcp_subr.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; Part of the TCP/IP network stack for KolibriOS ;;
14,7 → 14,7
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
$Revision: 3514 $
$Revision: 5015 $
 
align 4
iglobal
143,7 → 143,7
;
;-------------------------
align 4
TCP_drop:
TCP_drop: ; FIXME CHECKME TODO
 
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_drop: %x\n", eax
 
290,7 → 290,6
mov ecx, sizeof.TCP_header
mov di, IP_PROTO_TCP shl 8 + 128
call IPv4_output
test edi, edi
jz .error
pop esi cx
push edx eax
/kernel/branches/Kolibri-acpi/network/tcp_timer.inc
14,7 → 14,7
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
$Revision: 3143 $
$Revision: 5013 $
 
timer_flag_retransmission = 1 shl 0
timer_flag_keepalive = 1 shl 1
61,14 → 61,19
}
 
 
;----------------------
; 640 ms timer
;----------------------
macro TCP_timer_640ms { ; TODO: implement timed wait timer!
align 4
proc TCP_timer_640ms ; TODO: implement timed wait timer!
 
local .loop
local .exit
xor esi, esi
mov ecx, MANUAL_DESTROY
call create_event
mov [TCP_timer1_event], eax
 
.wait:
mov eax, [TCP_timer1_event]
mov ebx, [eax + EVENT.id]
call wait_event
 
; Update TCP sequence number
 
add [TCP_sequence_num], 64000
81,7 → 86,7
mov eax, [eax + SOCKET.NextPtr]
.check_only:
or eax, eax
jz .exit
jz .wait
 
cmp [eax + SOCKET.Domain], AF_INET4
jne .loop
157,9 → 162,8
mov [eax + TCP_SOCKET.t_force], 0
 
jmp .loop
.exit:
 
}
endp
 
 
 
/kernel/branches/Kolibri-acpi/network/tcp_usreq.inc
14,7 → 14,9
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
$Revision: 4850 $
 
 
;-------------------------
;
; TCP_usrclose
186,7 → 188,7
mov eax, [esp+4]
mov [eax + SOCKET.errorcode], ETIMEDOUT
and [eax + SOCKET.state], not SS_ISCONNECTING
call SOCKET_notify.unblock
call SOCKET_notify
ret 4
 
.fail:
/kernel/branches/Kolibri-acpi/network/udp.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; UDP.INC ;;
245,6 → 245,8
; ecx = number of bytes to send
; esi = pointer to data
;
; OUT: eax = -1 on error
;
;-----------------------------------------------------------------
 
align 4