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:
hidnplayr 2009-11-09 13:59:46 +00:00
parent 1f42f20b6f
commit adec2ac083
9 changed files with 165 additions and 195 deletions

View File

@ -91,7 +91,6 @@ endg
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ARP_init: ARP_init:
@ -118,7 +117,6 @@ ARP_init:
; ebx = last four bytes of mac ; TODO: special eax value for 'request send' ; ebx = last four bytes of mac ; TODO: special eax value for 'request send'
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ARP_IP_to_MAC: ARP_IP_to_MAC:
@ -202,8 +200,6 @@ ARP_IP_to_MAC:
; OUT: / ; OUT: /
; ;
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
align 4 align 4
ARP_create_request: ARP_create_request:
@ -266,7 +262,6 @@ ARP_create_request:
; OUT: / ; OUT: /
; ;
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
align 4 align 4
ARP_decrease_entry_ttls: ARP_decrease_entry_ttls:
@ -320,7 +315,7 @@ ARP_decrease_entry_ttls:
ret ret
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ARP_add_entry (or update) ; ARP_add_entry (or update)
; ;
@ -332,10 +327,7 @@ ARP_decrease_entry_ttls:
; ;
; OUT: eax = entry #, -1 on error ; OUT: eax = entry #, -1 on error
; ;
;--------------------------------------------------------------------------- ;----------------------------------------------------------------- ; TODO: use a mutex
; TODO: use a mutex
align 4 align 4
ARP_add_entry: ARP_add_entry:
@ -397,15 +389,14 @@ ARP_add_entry:
jmp .exit jmp .exit
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ARP_del_entry ; ARP_del_entry
; ;
; IN: entry # in esi ; IN: entry # in esi
; OUT: / ; OUT: /
; ;
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ARP_del_entry: ARP_del_entry:
@ -434,7 +425,7 @@ ARP_del_entry:
;----------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ARP_Handler: ; ARP_Handler:
; ;
@ -446,8 +437,7 @@ ARP_del_entry:
; packet size (without ethernet header) in ecx ; packet size (without ethernet header) in ecx
; OUT: / ; OUT: /
; ;
;----------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ARP_handler: ARP_handler:
@ -565,7 +555,7 @@ ARP_handler:
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ARP_API ; ARP_API
; ;
@ -575,10 +565,9 @@ ARP_handler:
; device number in bh ; device number in bh
; ecx, edx, .. depends on subfunction ; ecx, edx, .. depends on subfunction
; ;
; OUT: ; OUT: ?
; ;
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ARP_API: ARP_API:

View File

@ -79,7 +79,6 @@ endg
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
IPv4_init: IPv4_init:
@ -113,9 +112,10 @@ IPv4_init:
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 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" DEBUGF 1,"IP_Handler - start\n"
@ -475,7 +475,6 @@ IPv4_handler:
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
IPv4_decrease_fragment_ttls: IPv4_decrease_fragment_ttls:
@ -514,10 +513,7 @@ IPv4_decrease_fragment_ttls:
; esi = pointer to sending procedure ; esi = pointer to sending procedure
; edi = pointer to start of data (-1 on error) ; edi = pointer to start of data (-1 on error)
; ;
;----------------------------------------------------------------- ;----------------------------------------------------------------- ;;; TODO: create fragmented packets
;;; TODO: create fragmented packets
align 4 align 4
IPv4_create_packet: IPv4_create_packet:
@ -622,7 +618,6 @@ IPv4_create_packet:
; OUT: device id in edi ; OUT: device id in edi
; ;
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
align 4 align 4
IPv4_dest_to_dev: IPv4_dest_to_dev:
@ -663,7 +658,6 @@ IPv4_dest_to_dev:
; OUT: fragment number in ax ; OUT: fragment number in ax
; ;
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
align 4 align 4
IPv4_get_frgmnt_num: IPv4_get_frgmnt_num:
xor ax, ax ;;; TODO: replace this with real code xor ax, ax ;;; TODO: replace this with real code
@ -684,7 +678,6 @@ IPv4_get_frgmnt_num:
; OUT: ; OUT:
; ;
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
align 4 align 4
IPv4_API: IPv4_API:

View File

@ -61,7 +61,7 @@ uglobal
endg endg
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; ETH_init ; ETH_init
; ;
@ -70,8 +70,7 @@ endg
; IN: / ; IN: /
; OUT: / ; OUT: /
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_init: ETH_init:
@ -86,7 +85,7 @@ ETH_init:
ret ret
;--------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ETH_Add_Device: ; ETH_Add_Device:
; ;
@ -96,8 +95,7 @@ ETH_init:
; IN: Pointer to device structure in ebx ; IN: Pointer to device structure in ebx
; OUT: Device num in eax, -1 on error ; OUT: Device num in eax, -1 on error
; ;
;--------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_add_device: ETH_add_device:
@ -142,13 +140,12 @@ ETH_add_device:
.error: .error:
or eax, -1 or eax, -1
DEBUGF 1,"- fail\n" DEBUGF 1,"- fail\n"
ret ret
;-------------------------------- ;-----------------------------------------------------------------
; ;
; ETH_Remove_Device: ; ETH_Remove_Device:
; ;
@ -158,8 +155,7 @@ ETH_add_device:
; IN: Pointer to device structure in ebx ; IN: Pointer to device structure in ebx
; OUT: eax: -1 on error ; OUT: eax: -1 on error
; ;
;-------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_remove_device: ETH_remove_device:
@ -182,38 +178,38 @@ ETH_remove_device:
mov dword [ETH_IN_QUEUE], ETH_QUEUE_SIZE mov dword [ETH_IN_QUEUE], ETH_QUEUE_SIZE
mov dword [ETH_OUT_QUEUE], ETH_QUEUE_SIZE mov dword [ETH_OUT_QUEUE], ETH_QUEUE_SIZE
.notlast: .notlast:
ret ret
.error: .error:
or eax, -1 or eax, -1
ret ret
;------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ETH_Receiver: ; ETH_Receiver:
; ;
; This function is called by ethernet drivers, ; This function is called by ethernet drivers,
; It pushes the received ethernet packets onto the eth_in_queue ; 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: / ; OUT: /
; ;
;------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_receiver: ETH_receiver:
DEBUGF 1,"ETH_Receiver: "
DEBUGF 1,"ETH_Receiver: "
push ebx push ebx
mov esi, esp mov esi, esp
add_to_queue ETH_IN_QUEUE, ETH_QUEUE_SIZE, eth_queue_entry.size, .fail add_to_queue ETH_IN_QUEUE, ETH_QUEUE_SIZE, eth_queue_entry.size, .fail
DEBUGF 1,"Queued packet successfully\n" DEBUGF 1,"Queued packet successfully\n"
add esp, 4*3 add esp, 4*3
ret ret
.fail: .fail:
@ -221,13 +217,12 @@ ETH_receiver:
add esp, 4 add esp, 4
call kernel_free call kernel_free
add esp, 4 add esp, 4
ret ret
;-----------------------------------------------------------------
;-------------------------------------------------------------
; ;
; ETH_Handler: ; ETH_Handler:
; ;
@ -236,8 +231,7 @@ ETH_receiver:
; IN: / ; IN: /
; OUT: / ; OUT: /
; ;
;------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_handler: ETH_handler:
@ -292,9 +286,9 @@ ETH_handler:
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_sender: ETH_sender:
DEBUGF 1,"ETH_Sender: queuing for device: %x, %u bytes\n", [esp], [esp + 4] DEBUGF 1,"ETH_Sender: queuing for device: %x, %u bytes\n", [esp], [esp + 4]
push ebx push ebx
@ -302,6 +296,7 @@ ETH_sender:
add_to_queue ETH_OUT_QUEUE, ETH_QUEUE_SIZE, eth_queue_entry.size, .fail add_to_queue ETH_OUT_QUEUE, ETH_QUEUE_SIZE, eth_queue_entry.size, .fail
DEBUGF 1,"Queued packet successfully\n" DEBUGF 1,"Queued packet successfully\n"
add esp, 3*4 add esp, 3*4
ret ret
.fail: .fail:
@ -309,6 +304,7 @@ ETH_sender:
add esp, 4 add esp, 4
call kernel_free call kernel_free
add esp, 4 add esp, 4
ret ret
@ -321,7 +317,6 @@ ETH_sender:
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_send_queued: ETH_send_queued:
@ -340,11 +335,11 @@ ETH_send_queued:
call kernel_free call kernel_free
add esp, 4 ; pop (balance stack) add esp, 4 ; pop (balance stack)
.gohome: .gohome:
ret ret
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ETH_struc2dev ; ETH_struc2dev
; ;
@ -352,8 +347,7 @@ ETH_send_queued:
; ;
; OUT: edi is -1 on error, device number otherwise ; OUT: edi is -1 on error, device number otherwise
; ;
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_struc2dev: ETH_struc2dev:
push eax ecx push eax ecx
@ -377,9 +371,9 @@ ETH_struc2dev:
ret ret
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ETH_create_Packet ; ETH_create_packet
; ;
; IN: pointer to source mac in eax ; IN: pointer to source mac in eax
; pointer to destination mac in ebx ; pointer to destination mac in ebx
@ -394,8 +388,7 @@ ETH_struc2dev:
; edx is size of complete buffer ; edx is size of complete buffer
; esi points to procedure wich needs to be called to send packet ; esi points to procedure wich needs to be called to send packet
; ;
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_create_packet: ETH_create_packet:
@ -455,7 +448,7 @@ ETH_create_packet:
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ETH_API ; ETH_API
; ;
@ -467,8 +460,7 @@ ETH_create_packet:
; ;
; OUT: ; OUT:
; ;
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ETH_API: ETH_API:

View File

@ -115,7 +115,6 @@ endg
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ICMP_init: ICMP_init:
@ -129,7 +128,7 @@ ICMP_init:
;-------------------------------- ;-----------------------------------------------------------------
; ;
; ICMP_Handler: ; ICMP_Handler:
; ;
@ -143,8 +142,7 @@ ICMP_init:
; pointer to ICMP Packet data in edx ; pointer to ICMP Packet data in edx
; OUT: / ; OUT: /
; ;
;-------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ICMP_handler: ;TODO: works only on pure ethernet right now ! 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 ret
;-------------------------------- ;-----------------------------------------------------------------
; ;
; ICMP_Handler_fragments: ; ICMP_Handler_fragments:
; ;
@ -272,8 +270,7 @@ ICMP_handler: ;TODO: works only on pure ethernet right now !
; pointer to ICMP Packet data in edx ; pointer to ICMP Packet data in edx
; OUT: / ; OUT: /
; ;
;-------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ICMP_handler_fragments: ; works only on pure ethernet right now ! 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) add esp, 4 ; pop (balance stack)
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; Note: ICMP only works on top of IP protocol :) ; 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 ; edi = identifier shl 16 + sequence number
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ICMP_create_packet: ICMP_create_packet:
@ -385,7 +382,7 @@ ICMP_create_packet:
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ICMP_API ; ICMP_API
; ;
@ -397,8 +394,7 @@ ICMP_create_packet:
; ;
; OUT: ; OUT:
; ;
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ICMP_API: ICMP_API:

View File

@ -14,6 +14,15 @@
$Revision$ $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 struct queue
.size dd ? ; number of queued packets in thsi queue .size dd ? ; number of queued packets in thsi queue
.w_ptr dd ? ; current writing pointer in queue .w_ptr dd ? ; current writing pointer in queue
@ -53,19 +62,30 @@ struct socket_queue_entry
.size: .size:
ends 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 { 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 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 mov ecx, entry_size/4 ; Write the queue entry
rep movsd ; rep movsd ;
lea ecx, [size*entry_size+ptr+queue.data] lea ecx, [size*entry_size+ptr+queue.data]
cmp edi, ecx ; entry size cmp edi, ecx ; entry size
jl .no_wrap jl .no_wrap
sub edi, size*entry_size 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 { 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 je failaddr
dec [ptr + queue.size] dec [ptr + queue.size] ; if so, dequeue one
mov esi, [ptr + queue.r_ptr] mov esi, [ptr + queue.r_ptr]
push esi push esi
@ -90,7 +110,7 @@ macro get_from_queue ptr, size, entry_size, failaddr {
add esi, entry_size add esi, entry_size
lea ecx, [size*entry_size+ptr+queue.data] lea ecx, [size*entry_size+ptr+queue.data]
cmp esi, ecx ; entry size cmp esi, ecx ; entry size
jl .no_wrap jl .no_wrap
sub esi, size*entry_size 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 mov [ptr + queue.size] , 0
lea esi, [queue_ptr + queue.data] lea edi, [ptr + queue.data]
mov [queue_ptr + queue.w_ptr], esi mov [ptr + queue.w_ptr], edi
mov [queue_ptr + queue.r_ptr], esi mov [ptr + queue.r_ptr], edi
} }

View File

@ -97,6 +97,7 @@ ends
MAX_backlog equ 20 ; backlog for stream sockets MAX_backlog equ 20 ; backlog for stream sockets
SOCKETBUFFSIZE equ 4096 ; in bytes SOCKETBUFFSIZE equ 4096 ; in bytes
SOCKET_QUEUE_SIZE equ 10 ; maximum number ofincoming packets queued for 1 socket 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 uglobal
net_sockets rd 2 net_sockets rd 2
@ -105,7 +106,7 @@ uglobal
endg endg
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_init ; SOCKET_init
; ;
@ -114,8 +115,7 @@ endg
; IN: / ; IN: /
; OUT: / ; OUT: /
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_init: socket_init:
@ -128,12 +128,11 @@ socket_init:
ret ret
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; Socket API (function 74) ; Socket API (function 74)
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
sys_socket: sys_socket:
and ebx, 0x000000FF ; should i remove this line ? and ebx, 0x000000FF ; should i remove this line ?
@ -151,7 +150,7 @@ sys_socket:
dd socket_accept ; 5 dd socket_accept ; 5
dd socket_send ; 6 dd socket_send ; 6
dd socket_recv ; 7 dd socket_recv ; 7
dd socket_get_opt ; 8 dd socket_get_opt ; 8
; dd socket_set_opt ; 9 ; dd socket_set_opt ; 9
@ -161,7 +160,7 @@ s_error:
ret ret
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_open ; SOCKET_open
; ;
@ -171,7 +170,7 @@ s_error:
; protocol in esi ; protocol in esi
; OUT: eax is socket num, -1 on error ; OUT: eax is socket num, -1 on error
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_open: socket_open:
@ -188,7 +187,7 @@ socket_open:
stdcall net_socket_addr_to_num, eax stdcall net_socket_addr_to_num, eax
DEBUGF 1,", socketnumber: %u\n", 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 mov [esp+32], eax
@ -196,12 +195,7 @@ socket_open:
;-----------------------------------------------------------------
;-----------------------------------------------
; ;
; SOCKET_bind ; SOCKET_bind
; ;
@ -210,7 +204,7 @@ socket_open:
; length of that struct in esi ; length of that struct in esi
; OUT: 0 on success ; OUT: 0 on success
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_bind: socket_bind:
@ -278,7 +272,7 @@ socket_bind:
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_connect ; SOCKET_connect
; ;
@ -288,7 +282,7 @@ socket_bind:
; length of that struct in esi ; length of that struct in esi
; OUT: 0 on success ; OUT: 0 on success
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_connect: socket_connect:
@ -375,9 +369,7 @@ socket_connect:
ret ret
;-----------------------------------------------------------------
;-----------------------------------------------
; ;
; SOCKET_listen ; SOCKET_listen
; ;
@ -386,7 +378,7 @@ socket_connect:
; backlog in edx ; backlog in edx
; OUT: eax is socket num, -1 on error ; OUT: eax is socket num, -1 on error
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_listen: socket_listen:
@ -414,11 +406,7 @@ socket_listen:
ret ret
;-----------------------------------------------------------------
;-----------------------------------------------
; ;
; SOCKET_accept ; SOCKET_accept
; ;
@ -428,7 +416,7 @@ socket_listen:
; addrlen in esi ; addrlen in esi
; OUT: eax is socket num, -1 on error ; OUT: eax is socket num, -1 on error
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_accept: socket_accept:
@ -461,7 +449,7 @@ socket_accept:
dec [esi + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.backlog_cur] 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 eax, [eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.end + (eax-1)*4]
mov [esi + SOCKET_head.lock], 0 mov [esi + SOCKET_head.lock], 0
stdcall net_socket_addr_to_num, eax stdcall net_socket_addr_to_num, eax
mov [esp+32], eax mov [esp+32], eax
ret ret
.unlock_err: .unlock_err:
@ -469,7 +457,7 @@ socket_accept:
jmp s_error jmp s_error
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_close ; SOCKET_close
; ;
@ -477,7 +465,7 @@ socket_accept:
; IN: socket number in ecx ; IN: socket number in ecx
; OUT: eax is socket num, -1 on error ; OUT: eax is socket num, -1 on error
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_close: socket_close:
@ -559,7 +547,7 @@ socket_close:
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_receive ; SOCKET_receive
; ;
@ -570,7 +558,7 @@ socket_close:
; flags in edi ; flags in edi
; OUT: eax is number of bytes copied, -1 on error ; OUT: eax is number of bytes copied, -1 on error
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_recv: socket_recv:
@ -582,7 +570,7 @@ socket_recv:
DEBUGF 1,"Socket pointer: %x\n", eax 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 edi, edx
mov ecx, [esi + socket_queue_entry.data_size] mov ecx, [esi + socket_queue_entry.data_size]
@ -615,7 +603,7 @@ socket_recv:
ret ret
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_send ; SOCKET_send
; ;
@ -626,8 +614,7 @@ socket_recv:
; flags in edi ; flags in edi
; OUT: -1 on error ; OUT: -1 on error
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_send: socket_send:
@ -745,21 +732,23 @@ socket_send:
mov [esp+32], eax mov [esp+32], eax
ret ret
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_send ; SOCKET_get_options
; ;
; ;
; IN: socket number in ecx ; IN: socket number in ecx
; edx points to the options: ; edx points to the options:
; dd level, optname, optval, optlen ; dd level, optname, optval, optlen
; OUT: -1 on error ; OUT: -1 on error
; ;
; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP. ; 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 ; TODO: find best way to notify that send()'ed data were acknowledged
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4
socket_get_opt: socket_get_opt:
cmp dword [edx], IP_PROTO_TCP cmp dword [edx], IP_PROTO_TCP
jnz .unknown jnz .unknown
cmp dword [edx+4], -2 cmp dword [edx+4], -2
@ -770,7 +759,7 @@ socket_get_opt:
cmp dword [eax], 4 cmp dword [eax], 4
mov dword [eax], 4 mov dword [eax], 4
jb .fail jb .fail
stdcall net_socket_num_to_addr, ecx stdcall net_socket_num_to_addr, ecx
test eax, eax test eax, eax
jz .fail jz .fail
; todo: check that eax is really TCP socket ; todo: check that eax is really TCP socket
@ -780,15 +769,15 @@ socket_get_opt:
jz @f jz @f
mov [eax], ecx mov [eax], ecx
@@: @@:
xor eax, eax mov dword [esp+32], 0
ret ret
.fail: .fail:
.unknown: .unknown:
or eax, -1 mov dword [esp+32], -1
ret ret
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; SOCKET_find_free_port (local port) ; SOCKET_find_free_port (local port)
; ;
@ -797,7 +786,7 @@ socket_get_opt:
; IN: type in ecx (TCP/UDP) ; IN: type in ecx (TCP/UDP)
; OUT: bx = 0 on error, portnumber otherwise ; OUT: bx = 0 on error, portnumber otherwise
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_find_port: socket_find_port:
@ -848,7 +837,9 @@ socket_find_port:
rol bx, 8 rol bx, 8
ret ret
;-----------------------------------------------
;-----------------------------------------------------------------
; ;
; SOCKET_check_port (local port) ; SOCKET_check_port (local port)
; ;
@ -858,7 +849,7 @@ socket_find_port:
; port to check in bx ; port to check in bx
; OUT: bx = 0 on error, unchanged otherwise ; OUT: bx = 0 on error, unchanged otherwise
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_check_port: socket_check_port:
mov esi, net_sockets mov esi, net_sockets
@ -880,7 +871,8 @@ socket_check_port:
ret ret
;-----------------------------------------------
;-----------------------------------------------------------------
; ;
; SOCKET_internal_receiver ; SOCKET_internal_receiver
; ;
@ -895,7 +887,7 @@ socket_check_port:
; ;
; OUT: xxx ; OUT: xxx
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
socket_internal_receiver: socket_internal_receiver:
@ -905,9 +897,9 @@ socket_internal_receiver:
push ecx ; size push ecx ; size
push esi ; data_ptr push esi ; data_ptr
mov esi, esp 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" DEBUGF 1,"Queued packet successfully\n"
add esp, 4*3 add esp, socket_queue_entry.size
mov [eax + SOCKET_head.lock], 0 mov [eax + SOCKET_head.lock], 0
@ -964,7 +956,7 @@ proc net_socket_alloc stdcall uses ebx ecx edx edi
rep stosd rep stosd
pop eax pop eax
init_queue (eax + 2048) init_queue (eax + SOCKET_QUEUE_LOCATION)
; add socket to the list by changing pointers ; add socket to the list by changing pointers
mov ebx, net_sockets mov ebx, net_sockets

View File

@ -29,7 +29,7 @@ MAX_NET_DEVICES equ 16
MIN_EPHEMERAL_PORT equ 49152 MIN_EPHEMERAL_PORT equ 49152
MAX_EPHEMERAL_PORT equ 61000 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 ETHER_ARP equ 0x0608
AF_UNSPEC equ 0 AF_UNSPEC equ 0
@ -105,7 +105,7 @@ include "tcp.inc"
include "udp.inc" include "udp.inc"
include "icmp.inc" include "icmp.inc"
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; stack_init ; stack_init
; ;
@ -114,8 +114,7 @@ include "icmp.inc"
; IN: / ; IN: /
; OUT: / ; OUT: /
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
stack_init: stack_init:
@ -136,7 +135,7 @@ stack_init:
;----------------------------------------------- ;-----------------------------------------------------------------
; ;
; stack_handler ; stack_handler
; ;
@ -145,45 +144,41 @@ stack_init:
; IN: / ; IN: /
; OUT: / ; OUT: /
; ;
;----------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
stack_handler: stack_handler:
cmp [ETH_RUNNING], 0 cmp [ETH_RUNNING], 0
je .exit je .exit
; Test for 1/100 s (10ms) tick ; Test for 1/100 s (10ms) tick
mov eax, [timer_ticks] mov eax, [timer_ticks]
cmp eax, [last_1hsTick] cmp eax, [last_1hsTick]
je .exit je .exit
mov [last_1hsTick], eax mov [last_1hsTick], eax
call ETH_handler ; handle all queued ethernet packets call ETH_handler ; handle all queued ethernet packets
call ETH_send_queued call ETH_send_queued
call TCP_send_queued call TCP_send_queued
.sec_tick: .sec_tick:
; Test for 1 second tick ; Test for 1 second tick
mov al, 0 mov al, 0
out 0x70, al out 0x70, al
in al, 0x71 in al, 0x71
cmp al, [last_1sTick] cmp al, [last_1sTick]
je .exit je .exit
mov [last_1sTick], al mov [last_1sTick], al
call ARP_decrease_entry_ttls call ARP_decrease_entry_ttls
call IPv4_decrease_fragment_ttls call IPv4_decrease_fragment_ttls
call TCP_decrease_socket_ttls call TCP_decrease_socket_ttls
.exit: .exit:
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
@ -198,7 +193,6 @@ stack_handler:
; OUT: edx = semi-checksum ; OUT: edx = semi-checksum
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
checksum_1: checksum_1:
@ -222,7 +216,6 @@ checksum_1:
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; checksum_2 ; checksum_2
@ -233,7 +226,6 @@ checksum_1:
; OUT: dx = checksum (in INET byte order) ; OUT: dx = checksum (in INET byte order)
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
checksum_2: checksum_2:
@ -262,7 +254,6 @@ checksum_2:
; System function to work with network devices (73) ; System function to work with network devices (73)
; ;
;---------------------------------------------------------------- ;----------------------------------------------------------------
align 4 align 4
sys_network: sys_network:
@ -346,7 +337,6 @@ sys_network:
; System Function To work with Protocols (75) ; System Function To work with Protocols (75)
; ;
;---------------------------------------------------------------- ;----------------------------------------------------------------
align 4 align 4
sys_protocols: sys_protocols:
cmp bh, MAX_NET_DEVICES ; Check if device number exists cmp bh, MAX_NET_DEVICES ; Check if device number exists

View File

@ -20,7 +20,6 @@ $Revision$
TCP_RETRIES equ 5 ; Number of times to resend a Packet 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_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_SOCKET_TTL equ 10 ; # of secs to wait before closing socket
TCP_QUEUE_SIZE equ 16 TCP_QUEUE_SIZE equ 16
@ -51,7 +50,6 @@ endg
align 4 align 4
iglobal iglobal
stateHandler: stateHandler:
dd stateTCB_LISTEN dd stateTCB_LISTEN
@ -79,7 +77,6 @@ endg
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
TCP_init: TCP_init:
@ -90,7 +87,12 @@ TCP_init:
init_queue TCP_IN_QUEUE 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 xor eax, eax
mov esi, TCP_OUT_QUEUE mov esi, TCP_OUT_QUEUE
mov ecx, TCP_QUEUE_SIZE*tcp_out_queue_entry/4+1 mov ecx, TCP_QUEUE_SIZE*tcp_out_queue_entry/4+1
@ -107,7 +109,6 @@ TCP_init:
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
TCP_decrease_socket_ttls: TCP_decrease_socket_ttls:
; scan through all the sockets, decrementing active timers ; scan through all the sockets, decrementing active timers
@ -168,7 +169,6 @@ TCP_decrease_socket_ttls:
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
TCP_send_queued: 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_size]
push [esi + tcp_out_queue_entry.data_ptr] 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] 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] call [esi + tcp_out_queue_entry.sendproc]
add esp, 8 add esp, 8
pop esi ecx eax pop esi ecx eax
@ -237,7 +238,6 @@ TCP_send_queued:
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
TCP_add_to_queue: TCP_add_to_queue:
@ -298,7 +298,6 @@ TCP_add_to_queue:
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
TCP_handler : TCP_handler :
@ -338,6 +337,8 @@ TCP_handler :
DEBUGF 1,"Found valid socket for packet\n" DEBUGF 1,"Found valid socket for packet\n"
inc [TCP_PACKETS_RX]
push ebx push ebx
lea ebx, [ebx + SOCKET_head.lock] lea ebx, [ebx + SOCKET_head.lock]
call wait_mutex call wait_mutex
@ -425,7 +426,6 @@ TCP_handler :
; esi = pointer to data ; esi = pointer to data
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
TCP_socket_send: TCP_socket_send:
@ -523,7 +523,6 @@ TCP_socket_send:
; bl = flags ; bl = flags
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
TCP_send_ack: TCP_send_ack:
@ -570,7 +569,7 @@ TCP_send_ack:
; Now, calculate the checksum ; Now, calculate the checksum
pushw TCP_Packet.Options shl 8 pushw TCP_Packet.Options shl 8
pushw IP_PROTO_TCP 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 pushd [edi-8] ; source address
xor edx, edx xor edx, edx
@ -979,7 +978,6 @@ stateTCB_CLOSED:
; OUT: ; OUT:
; ;
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
align 4 align 4
TCP_API: TCP_API:

View File

@ -247,7 +247,7 @@ UDP_socket_send:
mov esi, edi mov esi, edi
call checksum_1 call checksum_1
; Checksum for pseudoheader ; 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 pushd [edi-8] ; source address
mov ecx, 12 mov ecx, 12
mov esi, esp mov esi, esp