forked from KolibriOS/kolibrios
Some code cleanup (cosmethical changes) in net_branch
git-svn-id: svn://kolibrios.org@1257 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
1f42f20b6f
commit
adec2ac083
@ -91,7 +91,6 @@ endg
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
ARP_init:
|
||||
|
||||
@ -118,7 +117,6 @@ ARP_init:
|
||||
; ebx = last four bytes of mac ; TODO: special eax value for 'request send'
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
ARP_IP_to_MAC:
|
||||
|
||||
@ -202,8 +200,6 @@ ARP_IP_to_MAC:
|
||||
; OUT: /
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
|
||||
align 4
|
||||
ARP_create_request:
|
||||
|
||||
@ -266,7 +262,6 @@ ARP_create_request:
|
||||
; OUT: /
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
ARP_decrease_entry_ttls:
|
||||
|
||||
@ -320,7 +315,7 @@ ARP_decrease_entry_ttls:
|
||||
|
||||
ret
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ARP_add_entry (or update)
|
||||
;
|
||||
@ -332,10 +327,7 @@ ARP_decrease_entry_ttls:
|
||||
;
|
||||
; OUT: eax = entry #, -1 on error
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
; TODO: use a mutex
|
||||
|
||||
;----------------------------------------------------------------- ; TODO: use a mutex
|
||||
align 4
|
||||
ARP_add_entry:
|
||||
|
||||
@ -397,15 +389,14 @@ ARP_add_entry:
|
||||
jmp .exit
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ARP_del_entry
|
||||
;
|
||||
; IN: entry # in esi
|
||||
; OUT: /
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ARP_del_entry:
|
||||
|
||||
@ -434,7 +425,7 @@ ARP_del_entry:
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ARP_Handler:
|
||||
;
|
||||
@ -446,8 +437,7 @@ ARP_del_entry:
|
||||
; packet size (without ethernet header) in ecx
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ARP_handler:
|
||||
|
||||
@ -565,7 +555,7 @@ ARP_handler:
|
||||
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ARP_API
|
||||
;
|
||||
@ -575,10 +565,9 @@ ARP_handler:
|
||||
; device number in bh
|
||||
; ecx, edx, .. depends on subfunction
|
||||
;
|
||||
; OUT:
|
||||
; OUT: ?
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ARP_API:
|
||||
|
||||
|
@ -79,7 +79,6 @@ endg
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
IPv4_init:
|
||||
|
||||
@ -113,9 +112,10 @@ IPv4_init:
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
IPv4_handler:
|
||||
IPv4_handler: ; TODO: clean up this mess
|
||||
; for instance, there should be only one piece of code wich make the jump to an underlying protocol, and not two..
|
||||
; TODO2: add code for IPv4 sockets (raw sockets)
|
||||
|
||||
DEBUGF 1,"IP_Handler - start\n"
|
||||
|
||||
@ -475,7 +475,6 @@ IPv4_handler:
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
IPv4_decrease_fragment_ttls:
|
||||
|
||||
@ -514,10 +513,7 @@ IPv4_decrease_fragment_ttls:
|
||||
; esi = pointer to sending procedure
|
||||
; edi = pointer to start of data (-1 on error)
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
;;; TODO: create fragmented packets
|
||||
|
||||
;----------------------------------------------------------------- ;;; TODO: create fragmented packets
|
||||
align 4
|
||||
IPv4_create_packet:
|
||||
|
||||
@ -622,7 +618,6 @@ IPv4_create_packet:
|
||||
; OUT: device id in edi
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
IPv4_dest_to_dev:
|
||||
|
||||
@ -663,7 +658,6 @@ IPv4_dest_to_dev:
|
||||
; OUT: fragment number in ax
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
IPv4_get_frgmnt_num:
|
||||
xor ax, ax ;;; TODO: replace this with real code
|
||||
@ -684,7 +678,6 @@ IPv4_get_frgmnt_num:
|
||||
; OUT:
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
IPv4_API:
|
||||
|
||||
|
@ -61,7 +61,7 @@ uglobal
|
||||
endg
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ETH_init
|
||||
;
|
||||
@ -70,8 +70,7 @@ endg
|
||||
; IN: /
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ETH_init:
|
||||
|
||||
@ -86,7 +85,7 @@ ETH_init:
|
||||
ret
|
||||
|
||||
|
||||
;---------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ETH_Add_Device:
|
||||
;
|
||||
@ -96,8 +95,7 @@ ETH_init:
|
||||
; IN: Pointer to device structure in ebx
|
||||
; OUT: Device num in eax, -1 on error
|
||||
;
|
||||
;---------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ETH_add_device:
|
||||
|
||||
@ -142,13 +140,12 @@ ETH_add_device:
|
||||
.error:
|
||||
or eax, -1
|
||||
DEBUGF 1,"- fail\n"
|
||||
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
;--------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ETH_Remove_Device:
|
||||
;
|
||||
@ -158,8 +155,7 @@ ETH_add_device:
|
||||
; IN: Pointer to device structure in ebx
|
||||
; OUT: eax: -1 on error
|
||||
;
|
||||
;--------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ETH_remove_device:
|
||||
|
||||
@ -182,38 +178,38 @@ ETH_remove_device:
|
||||
mov dword [ETH_IN_QUEUE], ETH_QUEUE_SIZE
|
||||
mov dword [ETH_OUT_QUEUE], ETH_QUEUE_SIZE
|
||||
|
||||
.notlast:
|
||||
|
||||
.notlast:
|
||||
ret
|
||||
|
||||
.error:
|
||||
.error:
|
||||
or eax, -1
|
||||
|
||||
ret
|
||||
|
||||
|
||||
|
||||
;-------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ETH_Receiver:
|
||||
;
|
||||
; This function is called by ethernet drivers,
|
||||
; It pushes the received ethernet packets onto the eth_in_queue
|
||||
;
|
||||
; IN: Pointer to buffer in [esp], size of buffer in [esp-4], pointer to eth_device in ebx
|
||||
; IN: [esp] = Pointer to buffer
|
||||
; [esp-4] = size of buffer
|
||||
; ebx = pointer to eth_device
|
||||
; OUT: /
|
||||
;
|
||||
;-------------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ETH_receiver:
|
||||
DEBUGF 1,"ETH_Receiver: "
|
||||
|
||||
DEBUGF 1,"ETH_Receiver: "
|
||||
push ebx
|
||||
mov esi, esp
|
||||
add_to_queue ETH_IN_QUEUE, ETH_QUEUE_SIZE, eth_queue_entry.size, .fail
|
||||
DEBUGF 1,"Queued packet successfully\n"
|
||||
add esp, 4*3
|
||||
|
||||
ret
|
||||
|
||||
.fail:
|
||||
@ -221,13 +217,12 @@ ETH_receiver:
|
||||
add esp, 4
|
||||
call kernel_free
|
||||
add esp, 4
|
||||
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;-------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ETH_Handler:
|
||||
;
|
||||
@ -236,8 +231,7 @@ ETH_receiver:
|
||||
; IN: /
|
||||
; OUT: /
|
||||
;
|
||||
;-------------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ETH_handler:
|
||||
|
||||
@ -292,9 +286,9 @@ ETH_handler:
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
ETH_sender:
|
||||
|
||||
DEBUGF 1,"ETH_Sender: queuing for device: %x, %u bytes\n", [esp], [esp + 4]
|
||||
|
||||
push ebx
|
||||
@ -302,6 +296,7 @@ ETH_sender:
|
||||
add_to_queue ETH_OUT_QUEUE, ETH_QUEUE_SIZE, eth_queue_entry.size, .fail
|
||||
DEBUGF 1,"Queued packet successfully\n"
|
||||
add esp, 3*4
|
||||
|
||||
ret
|
||||
|
||||
.fail:
|
||||
@ -309,6 +304,7 @@ ETH_sender:
|
||||
add esp, 4
|
||||
call kernel_free
|
||||
add esp, 4
|
||||
|
||||
ret
|
||||
|
||||
|
||||
@ -321,7 +317,6 @@ ETH_sender:
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
ETH_send_queued:
|
||||
|
||||
@ -340,11 +335,11 @@ ETH_send_queued:
|
||||
call kernel_free
|
||||
add esp, 4 ; pop (balance stack)
|
||||
|
||||
.gohome:
|
||||
.gohome:
|
||||
ret
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ETH_struc2dev
|
||||
;
|
||||
@ -352,8 +347,7 @@ ETH_send_queued:
|
||||
;
|
||||
; OUT: edi is -1 on error, device number otherwise
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ETH_struc2dev:
|
||||
push eax ecx
|
||||
@ -377,9 +371,9 @@ ETH_struc2dev:
|
||||
ret
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ETH_create_Packet
|
||||
; ETH_create_packet
|
||||
;
|
||||
; IN: pointer to source mac in eax
|
||||
; pointer to destination mac in ebx
|
||||
@ -394,8 +388,7 @@ ETH_struc2dev:
|
||||
; edx is size of complete buffer
|
||||
; esi points to procedure wich needs to be called to send packet
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ETH_create_packet:
|
||||
|
||||
@ -455,7 +448,7 @@ ETH_create_packet:
|
||||
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ETH_API
|
||||
;
|
||||
@ -467,8 +460,7 @@ ETH_create_packet:
|
||||
;
|
||||
; OUT:
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ETH_API:
|
||||
|
||||
|
@ -115,7 +115,6 @@ endg
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
ICMP_init:
|
||||
|
||||
@ -129,7 +128,7 @@ ICMP_init:
|
||||
|
||||
|
||||
|
||||
;--------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ICMP_Handler:
|
||||
;
|
||||
@ -143,8 +142,7 @@ ICMP_init:
|
||||
; pointer to ICMP Packet data in edx
|
||||
; OUT: /
|
||||
;
|
||||
;--------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ICMP_handler: ;TODO: works only on pure ethernet right now !
|
||||
|
||||
@ -258,7 +256,7 @@ ICMP_handler: ;TODO: works only on pure ethernet right now !
|
||||
ret
|
||||
|
||||
|
||||
;--------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ICMP_Handler_fragments:
|
||||
;
|
||||
@ -272,8 +270,7 @@ ICMP_handler: ;TODO: works only on pure ethernet right now !
|
||||
; pointer to ICMP Packet data in edx
|
||||
; OUT: /
|
||||
;
|
||||
;--------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ICMP_handler_fragments: ; works only on pure ethernet right now !
|
||||
|
||||
@ -311,6 +308,7 @@ ICMP_handler_fragments: ; works only on pure ethernet right now !
|
||||
add esp, 4 ; pop (balance stack)
|
||||
ret
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; Note: ICMP only works on top of IP protocol :)
|
||||
@ -327,7 +325,6 @@ ICMP_handler_fragments: ; works only on pure ethernet right now !
|
||||
; edi = identifier shl 16 + sequence number
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
ICMP_create_packet:
|
||||
|
||||
@ -385,7 +382,7 @@ ICMP_create_packet:
|
||||
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; ICMP_API
|
||||
;
|
||||
@ -397,8 +394,7 @@ ICMP_create_packet:
|
||||
;
|
||||
; OUT:
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
ICMP_API:
|
||||
|
||||
|
@ -14,6 +14,15 @@
|
||||
|
||||
$Revision$
|
||||
|
||||
; The Queues implemented by these macros for a sort of ring-buffer.
|
||||
; The data to these queue's always looks like this:
|
||||
;
|
||||
; At top, you have the queue struct, wich has the size (number of currently queued packets, read and write pointers.
|
||||
; This struct is followed by a number of slots wich you can read and write to using the macros.
|
||||
; How these slots look like is up to you to chose, normally they should have at least a pointer to where the real data is.
|
||||
; (you can see some examples below)
|
||||
|
||||
|
||||
struct queue
|
||||
.size dd ? ; number of queued packets in thsi queue
|
||||
.w_ptr dd ? ; current writing pointer in queue
|
||||
@ -53,19 +62,30 @@ struct socket_queue_entry
|
||||
.size:
|
||||
ends
|
||||
|
||||
; The following macros share these inputs:
|
||||
|
||||
; ptr = pointer to where the queue data is located
|
||||
; size = number of slots/entrys in the queue
|
||||
; entry_size = size of one slot, in bytes
|
||||
; failaddr = the address where macro will jump to when there is no data in the queue
|
||||
|
||||
; additionally, add_to_queue requires you to set esi to the data wich you want to queue
|
||||
; get_from_queue on the other hand will return a pointer in esi, to the entry you're interessed in
|
||||
; PS: macros WILL destroy ecx and edi
|
||||
|
||||
macro add_to_queue ptr, size, entry_size, failaddr {
|
||||
|
||||
cmp [ptr + queue.size], size ; Check if queue isnt full
|
||||
cmp [ptr + queue.size], size ; Check if queue isnt full
|
||||
jge failaddr
|
||||
|
||||
inc [ptr + queue.size]
|
||||
inc [ptr + queue.size] ; if not full, queue one more
|
||||
|
||||
mov edi, [ptr + queue.w_ptr] ; Current write pointer (FIFO!)
|
||||
mov edi, [ptr + queue.w_ptr] ; Current write pointer (FIFO!)
|
||||
mov ecx, entry_size/4 ; Write the queue entry
|
||||
rep movsd ;
|
||||
|
||||
lea ecx, [size*entry_size+ptr+queue.data]
|
||||
cmp edi, ecx ; entry size
|
||||
cmp edi, ecx ; entry size
|
||||
jl .no_wrap
|
||||
|
||||
sub edi, size*entry_size
|
||||
@ -79,10 +99,10 @@ macro add_to_queue ptr, size, entry_size, failaddr {
|
||||
|
||||
macro get_from_queue ptr, size, entry_size, failaddr {
|
||||
|
||||
cmp [ptr + queue.size], 0 ; any packets queued?
|
||||
cmp [ptr + queue.size], 0 ; any packets queued?
|
||||
je failaddr
|
||||
|
||||
dec [ptr + queue.size]
|
||||
dec [ptr + queue.size] ; if so, dequeue one
|
||||
|
||||
mov esi, [ptr + queue.r_ptr]
|
||||
push esi
|
||||
@ -90,7 +110,7 @@ macro get_from_queue ptr, size, entry_size, failaddr {
|
||||
add esi, entry_size
|
||||
|
||||
lea ecx, [size*entry_size+ptr+queue.data]
|
||||
cmp esi, ecx ; entry size
|
||||
cmp esi, ecx ; entry size
|
||||
jl .no_wrap
|
||||
|
||||
sub esi, size*entry_size
|
||||
@ -102,10 +122,10 @@ macro get_from_queue ptr, size, entry_size, failaddr {
|
||||
|
||||
}
|
||||
|
||||
macro init_queue queue_ptr {
|
||||
macro init_queue ptr {
|
||||
|
||||
mov [queue_ptr + queue.size] , 0
|
||||
lea esi, [queue_ptr + queue.data]
|
||||
mov [queue_ptr + queue.w_ptr], esi
|
||||
mov [queue_ptr + queue.r_ptr], esi
|
||||
mov [ptr + queue.size] , 0
|
||||
lea edi, [ptr + queue.data]
|
||||
mov [ptr + queue.w_ptr], edi
|
||||
mov [ptr + queue.r_ptr], edi
|
||||
}
|
@ -97,6 +97,7 @@ ends
|
||||
MAX_backlog equ 20 ; backlog for stream sockets
|
||||
SOCKETBUFFSIZE equ 4096 ; in bytes
|
||||
SOCKET_QUEUE_SIZE equ 10 ; maximum number ofincoming packets queued for 1 socket
|
||||
SOCKET_QUEUE_LOCATION equ 2048 ; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
|
||||
|
||||
uglobal
|
||||
net_sockets rd 2
|
||||
@ -105,7 +106,7 @@ uglobal
|
||||
endg
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_init
|
||||
;
|
||||
@ -114,8 +115,7 @@ endg
|
||||
; IN: /
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_init:
|
||||
|
||||
@ -128,12 +128,11 @@ socket_init:
|
||||
ret
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; Socket API (function 74)
|
||||
;
|
||||
;-----------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
sys_socket:
|
||||
and ebx, 0x000000FF ; should i remove this line ?
|
||||
@ -151,7 +150,7 @@ sys_socket:
|
||||
dd socket_accept ; 5
|
||||
dd socket_send ; 6
|
||||
dd socket_recv ; 7
|
||||
dd socket_get_opt ; 8
|
||||
dd socket_get_opt ; 8
|
||||
; dd socket_set_opt ; 9
|
||||
|
||||
|
||||
@ -161,7 +160,7 @@ s_error:
|
||||
ret
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_open
|
||||
;
|
||||
@ -171,7 +170,7 @@ s_error:
|
||||
; protocol in esi
|
||||
; OUT: eax is socket num, -1 on error
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_open:
|
||||
|
||||
@ -188,7 +187,7 @@ socket_open:
|
||||
stdcall net_socket_addr_to_num, eax
|
||||
DEBUGF 1,", socketnumber: %u\n", eax
|
||||
|
||||
; TODO: if it is txcp socket, set state to TCB_CLOSED
|
||||
; TODO: if it is a tcp socket, set state to TCB_CLOSED
|
||||
|
||||
mov [esp+32], eax
|
||||
|
||||
@ -196,12 +195,7 @@ socket_open:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_bind
|
||||
;
|
||||
@ -210,7 +204,7 @@ socket_open:
|
||||
; length of that struct in esi
|
||||
; OUT: 0 on success
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_bind:
|
||||
|
||||
@ -278,7 +272,7 @@ socket_bind:
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_connect
|
||||
;
|
||||
@ -288,7 +282,7 @@ socket_bind:
|
||||
; length of that struct in esi
|
||||
; OUT: 0 on success
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_connect:
|
||||
|
||||
@ -375,9 +369,7 @@ socket_connect:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_listen
|
||||
;
|
||||
@ -386,7 +378,7 @@ socket_connect:
|
||||
; backlog in edx
|
||||
; OUT: eax is socket num, -1 on error
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_listen:
|
||||
|
||||
@ -414,11 +406,7 @@ socket_listen:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_accept
|
||||
;
|
||||
@ -428,7 +416,7 @@ socket_listen:
|
||||
; addrlen in esi
|
||||
; OUT: eax is socket num, -1 on error
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_accept:
|
||||
|
||||
@ -461,7 +449,7 @@ socket_accept:
|
||||
dec [esi + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.backlog_cur]
|
||||
mov eax, [eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.end + (eax-1)*4]
|
||||
mov [esi + SOCKET_head.lock], 0
|
||||
stdcall net_socket_addr_to_num, eax
|
||||
stdcall net_socket_addr_to_num, eax
|
||||
mov [esp+32], eax
|
||||
ret
|
||||
.unlock_err:
|
||||
@ -469,7 +457,7 @@ socket_accept:
|
||||
jmp s_error
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_close
|
||||
;
|
||||
@ -477,7 +465,7 @@ socket_accept:
|
||||
; IN: socket number in ecx
|
||||
; OUT: eax is socket num, -1 on error
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_close:
|
||||
|
||||
@ -559,7 +547,7 @@ socket_close:
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_receive
|
||||
;
|
||||
@ -570,7 +558,7 @@ socket_close:
|
||||
; flags in edi
|
||||
; OUT: eax is number of bytes copied, -1 on error
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_recv:
|
||||
|
||||
@ -582,7 +570,7 @@ socket_recv:
|
||||
|
||||
DEBUGF 1,"Socket pointer: %x\n", eax
|
||||
|
||||
get_from_queue (eax + 2048), SOCKET_QUEUE_SIZE, 4*3, s_error
|
||||
get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, s_error
|
||||
|
||||
mov edi, edx
|
||||
mov ecx, [esi + socket_queue_entry.data_size]
|
||||
@ -615,7 +603,7 @@ socket_recv:
|
||||
ret
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_send
|
||||
;
|
||||
@ -626,8 +614,7 @@ socket_recv:
|
||||
; flags in edi
|
||||
; OUT: -1 on error
|
||||
;
|
||||
;-----------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_send:
|
||||
|
||||
@ -745,21 +732,23 @@ socket_send:
|
||||
mov [esp+32], eax
|
||||
ret
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_send
|
||||
; SOCKET_get_options
|
||||
;
|
||||
;
|
||||
; IN: socket number in ecx
|
||||
; edx points to the options:
|
||||
; dd level, optname, optval, optlen
|
||||
; dd level, optname, optval, optlen
|
||||
; OUT: -1 on error
|
||||
;
|
||||
; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP.
|
||||
; TODO: find best way to notify that send()'ed data were acknowledged
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_get_opt:
|
||||
|
||||
cmp dword [edx], IP_PROTO_TCP
|
||||
jnz .unknown
|
||||
cmp dword [edx+4], -2
|
||||
@ -770,7 +759,7 @@ socket_get_opt:
|
||||
cmp dword [eax], 4
|
||||
mov dword [eax], 4
|
||||
jb .fail
|
||||
stdcall net_socket_num_to_addr, ecx
|
||||
stdcall net_socket_num_to_addr, ecx
|
||||
test eax, eax
|
||||
jz .fail
|
||||
; todo: check that eax is really TCP socket
|
||||
@ -780,15 +769,15 @@ socket_get_opt:
|
||||
jz @f
|
||||
mov [eax], ecx
|
||||
@@:
|
||||
xor eax, eax
|
||||
mov dword [esp+32], 0
|
||||
ret
|
||||
.fail:
|
||||
.unknown:
|
||||
or eax, -1
|
||||
mov dword [esp+32], -1
|
||||
ret
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_find_free_port (local port)
|
||||
;
|
||||
@ -797,7 +786,7 @@ socket_get_opt:
|
||||
; IN: type in ecx (TCP/UDP)
|
||||
; OUT: bx = 0 on error, portnumber otherwise
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_find_port:
|
||||
|
||||
@ -848,7 +837,9 @@ socket_find_port:
|
||||
rol bx, 8
|
||||
ret
|
||||
|
||||
;-----------------------------------------------
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_check_port (local port)
|
||||
;
|
||||
@ -858,7 +849,7 @@ socket_find_port:
|
||||
; port to check in bx
|
||||
; OUT: bx = 0 on error, unchanged otherwise
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_check_port:
|
||||
mov esi, net_sockets
|
||||
@ -880,7 +871,8 @@ socket_check_port:
|
||||
ret
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; SOCKET_internal_receiver
|
||||
;
|
||||
@ -895,7 +887,7 @@ socket_check_port:
|
||||
;
|
||||
; OUT: xxx
|
||||
;
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
socket_internal_receiver:
|
||||
|
||||
@ -905,9 +897,9 @@ socket_internal_receiver:
|
||||
push ecx ; size
|
||||
push esi ; data_ptr
|
||||
mov esi, esp
|
||||
add_to_queue (eax + 2048), SOCKET_QUEUE_SIZE, 3*4, notify_network_event.full
|
||||
add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, notify_network_event.full
|
||||
DEBUGF 1,"Queued packet successfully\n"
|
||||
add esp, 4*3
|
||||
add esp, socket_queue_entry.size
|
||||
|
||||
mov [eax + SOCKET_head.lock], 0
|
||||
|
||||
@ -964,7 +956,7 @@ proc net_socket_alloc stdcall uses ebx ecx edx edi
|
||||
rep stosd
|
||||
pop eax
|
||||
|
||||
init_queue (eax + 2048)
|
||||
init_queue (eax + SOCKET_QUEUE_LOCATION)
|
||||
|
||||
; add socket to the list by changing pointers
|
||||
mov ebx, net_sockets
|
||||
|
@ -29,7 +29,7 @@ MAX_NET_DEVICES equ 16
|
||||
MIN_EPHEMERAL_PORT equ 49152
|
||||
MAX_EPHEMERAL_PORT equ 61000
|
||||
|
||||
ETHER equ 1337
|
||||
ETHER equ 1337 ; TODO: find another value for this (how does it work in posix ?)
|
||||
ETHER_ARP equ 0x0608
|
||||
|
||||
AF_UNSPEC equ 0
|
||||
@ -105,7 +105,7 @@ include "tcp.inc"
|
||||
include "udp.inc"
|
||||
include "icmp.inc"
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; stack_init
|
||||
;
|
||||
@ -114,8 +114,7 @@ include "icmp.inc"
|
||||
; IN: /
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
stack_init:
|
||||
|
||||
@ -136,7 +135,7 @@ stack_init:
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; stack_handler
|
||||
;
|
||||
@ -145,45 +144,41 @@ stack_init:
|
||||
; IN: /
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
align 4
|
||||
stack_handler:
|
||||
|
||||
cmp [ETH_RUNNING], 0
|
||||
je .exit
|
||||
cmp [ETH_RUNNING], 0
|
||||
je .exit
|
||||
|
||||
; Test for 1/100 s (10ms) tick
|
||||
mov eax, [timer_ticks]
|
||||
cmp eax, [last_1hsTick]
|
||||
je .exit
|
||||
; Test for 1/100 s (10ms) tick
|
||||
mov eax, [timer_ticks]
|
||||
cmp eax, [last_1hsTick]
|
||||
je .exit
|
||||
|
||||
mov [last_1hsTick], eax
|
||||
mov [last_1hsTick], eax
|
||||
|
||||
call ETH_handler ; handle all queued ethernet packets
|
||||
call ETH_send_queued
|
||||
call TCP_send_queued
|
||||
call ETH_handler ; handle all queued ethernet packets
|
||||
call ETH_send_queued
|
||||
call TCP_send_queued
|
||||
|
||||
.sec_tick:
|
||||
|
||||
; Test for 1 second tick
|
||||
mov al, 0
|
||||
out 0x70, al
|
||||
in al, 0x71
|
||||
cmp al, [last_1sTick]
|
||||
je .exit
|
||||
; Test for 1 second tick
|
||||
mov al, 0
|
||||
out 0x70, al
|
||||
in al, 0x71
|
||||
cmp al, [last_1sTick]
|
||||
je .exit
|
||||
|
||||
mov [last_1sTick], al
|
||||
mov [last_1sTick], al
|
||||
|
||||
call ARP_decrease_entry_ttls
|
||||
call IPv4_decrease_fragment_ttls
|
||||
call TCP_decrease_socket_ttls
|
||||
call ARP_decrease_entry_ttls
|
||||
call IPv4_decrease_fragment_ttls
|
||||
call TCP_decrease_socket_ttls
|
||||
|
||||
.exit:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
ret
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
@ -198,7 +193,6 @@ stack_handler:
|
||||
; OUT: edx = semi-checksum
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
checksum_1:
|
||||
|
||||
@ -222,7 +216,6 @@ checksum_1:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
; checksum_2
|
||||
@ -233,7 +226,6 @@ checksum_1:
|
||||
; OUT: dx = checksum (in INET byte order)
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
checksum_2:
|
||||
|
||||
@ -262,7 +254,6 @@ checksum_2:
|
||||
; System function to work with network devices (73)
|
||||
;
|
||||
;----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
sys_network:
|
||||
|
||||
@ -346,7 +337,6 @@ sys_network:
|
||||
; System Function To work with Protocols (75)
|
||||
;
|
||||
;----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
sys_protocols:
|
||||
cmp bh, MAX_NET_DEVICES ; Check if device number exists
|
||||
@ -389,4 +379,4 @@ sys_protocols:
|
||||
|
||||
.return:
|
||||
mov [esp+28+4], eax
|
||||
ret
|
||||
ret
|
||||
|
@ -20,7 +20,6 @@ $Revision$
|
||||
TCP_RETRIES equ 5 ; Number of times to resend a Packet
|
||||
TCP_PACKET_TTL equ 50 ; resend if not replied to in 1/100 s
|
||||
TCP_SOCKET_TTL equ 10 ; # of secs to wait before closing socket
|
||||
|
||||
TCP_QUEUE_SIZE equ 16
|
||||
|
||||
|
||||
@ -51,7 +50,6 @@ endg
|
||||
|
||||
align 4
|
||||
iglobal
|
||||
|
||||
stateHandler:
|
||||
|
||||
dd stateTCB_LISTEN
|
||||
@ -79,7 +77,6 @@ endg
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
TCP_init:
|
||||
|
||||
@ -90,7 +87,12 @@ TCP_init:
|
||||
|
||||
init_queue TCP_IN_QUEUE
|
||||
|
||||
; tcp_out_queue is a special type of queue
|
||||
; tcp_out_queue is a special type of queue:
|
||||
; The first dword is a counter of total packets queued.
|
||||
; The remaining bytes are socket 'slots' wich use tcp_out_queue_entry data structure.
|
||||
; An empty slot is know by the fact that tcp_out_queue_entry.data_ptr (first dword of the slot) is set to 0
|
||||
; There are TCP_OUT_QUEUE_SIZE number of slots
|
||||
|
||||
xor eax, eax
|
||||
mov esi, TCP_OUT_QUEUE
|
||||
mov ecx, TCP_QUEUE_SIZE*tcp_out_queue_entry/4+1
|
||||
@ -107,7 +109,6 @@ TCP_init:
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
TCP_decrease_socket_ttls:
|
||||
; scan through all the sockets, decrementing active timers
|
||||
@ -168,7 +169,6 @@ TCP_decrease_socket_ttls:
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
TCP_send_queued:
|
||||
|
||||
@ -205,6 +205,7 @@ TCP_send_queued:
|
||||
push [esi + tcp_out_queue_entry.data_size]
|
||||
push [esi + tcp_out_queue_entry.data_ptr]
|
||||
DEBUGF 1,"Now sending TCP packet %x, size: %u, owner: %x, sendproc %x\n", [esp], [esp+4], ebx, [esi + tcp_out_queue_entry.sendproc]
|
||||
inc [TCP_PACKETS_TX]
|
||||
call [esi + tcp_out_queue_entry.sendproc]
|
||||
add esp, 8
|
||||
pop esi ecx eax
|
||||
@ -237,7 +238,6 @@ TCP_send_queued:
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
TCP_add_to_queue:
|
||||
|
||||
@ -298,7 +298,6 @@ TCP_add_to_queue:
|
||||
; OUT: /
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
TCP_handler :
|
||||
|
||||
@ -338,6 +337,8 @@ TCP_handler :
|
||||
|
||||
DEBUGF 1,"Found valid socket for packet\n"
|
||||
|
||||
inc [TCP_PACKETS_RX]
|
||||
|
||||
push ebx
|
||||
lea ebx, [ebx + SOCKET_head.lock]
|
||||
call wait_mutex
|
||||
@ -425,7 +426,6 @@ TCP_handler :
|
||||
; esi = pointer to data
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
TCP_socket_send:
|
||||
|
||||
@ -523,7 +523,6 @@ TCP_socket_send:
|
||||
; bl = flags
|
||||
;
|
||||
;-----------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
TCP_send_ack:
|
||||
|
||||
@ -570,7 +569,7 @@ TCP_send_ack:
|
||||
; Now, calculate the checksum
|
||||
pushw TCP_Packet.Options shl 8
|
||||
pushw IP_PROTO_TCP shl 8
|
||||
pushd [edi-4] ; destination address
|
||||
pushd [edi-4] ; destination address ; TODO: fix this, IPv4 packet could have options..
|
||||
pushd [edi-8] ; source address
|
||||
|
||||
xor edx, edx
|
||||
@ -979,7 +978,6 @@ stateTCB_CLOSED:
|
||||
; OUT:
|
||||
;
|
||||
;---------------------------------------------------------------------------
|
||||
|
||||
align 4
|
||||
TCP_API:
|
||||
|
||||
|
@ -247,7 +247,7 @@ UDP_socket_send:
|
||||
mov esi, edi
|
||||
call checksum_1
|
||||
; Checksum for pseudoheader
|
||||
pushd [edi-4] ; destination address
|
||||
pushd [edi-4] ; destination address ; TODO: fix this, IPv4 packet could have options..
|
||||
pushd [edi-8] ; source address
|
||||
mov ecx, 12
|
||||
mov esi, esp
|
||||
|
Loading…
Reference in New Issue
Block a user