Network stack: real socket numbers, comments, code cleanup
git-svn-id: svn://kolibrios.org@922 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
bbf8c5f14d
commit
22720e823e
@ -7,8 +7,6 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;; Address Resolution Protocol ;;
|
;; Address Resolution Protocol ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Last revision: 10.11.2006 ;;
|
|
||||||
;; ;;
|
|
||||||
;; This file contains the following: ;;
|
;; This file contains the following: ;;
|
||||||
;; arp_table_manager - Manages an ARPTable ;;
|
;; arp_table_manager - Manages an ARPTable ;;
|
||||||
;; arp_request - Sends an ARP request on the ethernet ;;
|
;; arp_request - Sends an ARP request on the ethernet ;;
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;; Ethernet network layer for Menuet OS ;;
|
;; Ethernet network layer for Menuet OS ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Version 0.4 22 September 2003 ;;
|
|
||||||
;; ;;
|
|
||||||
;; This file contains the following: ;;
|
;; This file contains the following: ;;
|
||||||
;; PCI bus scanning for valid devices ;;
|
;; PCI bus scanning for valid devices ;;
|
||||||
;; Table of supported ethernet drivers ;;
|
;; Table of supported ethernet drivers ;;
|
||||||
@ -353,9 +351,9 @@ endp
|
|||||||
; All registers may be destroyed
|
; All registers may be destroyed
|
||||||
;
|
;
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
uglobal
|
;uglobal
|
||||||
ether_IP_handler_cnt dd ?
|
; ether_IP_handler_cnt dd ?
|
||||||
endg
|
;endg
|
||||||
ether_IP_handler:
|
ether_IP_handler:
|
||||||
mov eax, EMPTY_QUEUE
|
mov eax, EMPTY_QUEUE
|
||||||
call dequeue
|
call dequeue
|
||||||
|
@ -150,15 +150,15 @@ local buffer_number dd ?
|
|||||||
|
|
||||||
mov eax, [ebx + IP_PACKET.DestinationAddress]
|
mov eax, [ebx + IP_PACKET.DestinationAddress]
|
||||||
cmp eax, 0xffffffff
|
cmp eax, 0xffffffff
|
||||||
;je @f
|
je @f
|
||||||
;mov ecx, [stack_ip]
|
mov ecx, [stack_ip]
|
||||||
;and eax, [subnet_mask]
|
and eax, [subnet_mask]
|
||||||
;and ecx, [subnet_mask]
|
and ecx, [subnet_mask]
|
||||||
;cmp eax, ecx
|
cmp eax, ecx
|
||||||
;jne .dump.2
|
jne .dump.2
|
||||||
;mov eax, [ebx + IP_PACKET.DestinationAddress]
|
mov eax, [ebx + IP_PACKET.DestinationAddress]
|
||||||
;or eax, [subnet_mask]
|
or eax, [subnet_mask]
|
||||||
;cmp eax, 0xffffffff
|
cmp eax, 0xffffffff
|
||||||
jne .dump.2
|
jne .dump.2
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
@ -223,7 +223,7 @@ local buffer_number dd ?
|
|||||||
jmp .dump.x
|
jmp .dump.x
|
||||||
|
|
||||||
.dump.4:
|
.dump.4:
|
||||||
DEBUGF 1, "K : ip_rx - dumped (ihl: %u)\n", [ebx + IP_PACKET.TimeToLive]
|
DEBUGF 1, "K : ip_rx - dumped (ttl: %u)\n", [ebx + IP_PACKET.TimeToLive]
|
||||||
jmp .dump.x
|
jmp .dump.x
|
||||||
|
|
||||||
.dump.5:
|
.dump.5:
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;; Buffer queue management for Menuet OS TCP/IP Stack ;;
|
;; Buffer queue management for Menuet OS TCP/IP Stack ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Version 0.3 29 August 2002 ;;
|
|
||||||
;; ;;
|
|
||||||
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; See file COPYING for details ;;
|
;; See file COPYING for details ;;
|
||||||
@ -43,9 +41,9 @@ $Revision$
|
|||||||
; all other registers preserved
|
; all other registers preserved
|
||||||
; This always works, so no error returned
|
; This always works, so no error returned
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
uglobal
|
;uglobal
|
||||||
freeBuff_cnt dd ?
|
; freeBuff_cnt dd ?
|
||||||
endg
|
;endg
|
||||||
freeBuff:
|
freeBuff:
|
||||||
; inc [freeBuff_cnt]
|
; inc [freeBuff_cnt]
|
||||||
; DEBUGF 1, "K : freeBuff (%u)\n", [freeBuff_cnt]
|
; DEBUGF 1, "K : freeBuff (%u)\n", [freeBuff_cnt]
|
||||||
@ -106,9 +104,9 @@ qs_exit:
|
|||||||
; all other registers preserved
|
; all other registers preserved
|
||||||
; This always works, so no error returned
|
; This always works, so no error returned
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
uglobal
|
;uglobal
|
||||||
queue_cnt dd ?
|
; queue_cnt dd ?
|
||||||
endg
|
;endg
|
||||||
queue:
|
queue:
|
||||||
; inc [queue_cnt]
|
; inc [queue_cnt]
|
||||||
; DEBUGF 1, "K : queue (%u)\n", [queue_cnt]
|
; DEBUGF 1, "K : queue (%u)\n", [queue_cnt]
|
||||||
@ -161,9 +159,9 @@ qu_exit:
|
|||||||
; all other registers preserved
|
; all other registers preserved
|
||||||
;
|
;
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
uglobal
|
;uglobal
|
||||||
dequeue_cnt dd ?
|
; dequeue_cnt dd ?
|
||||||
endg
|
;endg
|
||||||
dequeue:
|
dequeue:
|
||||||
push ebx
|
push ebx
|
||||||
shl eax, 1
|
shl eax, 1
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;; Sockets constants, structures and functions ;;
|
;; Sockets constants, structures and functions ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Last revision: 11.11.2006 ;;
|
|
||||||
;; ;;
|
|
||||||
;; This file contains the following: ;;
|
;; This file contains the following: ;;
|
||||||
;; is_localport_unused ;;
|
;; is_localport_unused ;;
|
||||||
;; get_free_socket ;;
|
;; get_free_socket ;;
|
||||||
@ -31,111 +29,56 @@
|
|||||||
|
|
||||||
$Revision$
|
$Revision$
|
||||||
|
|
||||||
|
; socket data structure
|
||||||
;
|
struct SOCKET
|
||||||
; Socket Descriptor + Buffer
|
.PrevPtr dd ? ; pointer to previous socket in list
|
||||||
;
|
.NextPtr dd ? ; pointer to next socket in list
|
||||||
; 0 1 2 3
|
.Number dd ? ; socket number (unique within single process)
|
||||||
; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
.PID dd ? ; application process id
|
||||||
;
|
.LocalIP dd ? ; local IP address
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.LocalPort dw ? ; local port
|
||||||
; 0| Status ( of this buffer ) |
|
.RemoteIP dd ? ; remote IP address
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.RemotePort dw ? ; remote port
|
||||||
; 4| Application Process ID |
|
.OrigRemoteIP dd ? ; original remote IP address (used to reset to LISTEN state)
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.OrigRemotePort dw ? ; original remote port (used to reset to LISTEN state)
|
||||||
; 8| Local IP Address |
|
.rxDataCount dd ? ; rx data count
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.TCBState dd ? ; TCB state
|
||||||
; 12| Local IP Port | Unused ( set to 0 ) |
|
.TCBTimer dd ? ; TCB timer (seconds)
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.ISS dd ? ; initial send sequence
|
||||||
; 16| Remote IP Address |
|
.IRS dd ? ; initial receive sequence
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.SND_UNA dd ? ; sequence number of unack'ed sent packets
|
||||||
; 20| Remote IP Port | Unused ( set to 0 ) |
|
.SND_NXT dd ? ; bext send sequence number to use
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.SND_WND dd ? ; send window
|
||||||
; 24| Rx Data Count INTEL format|
|
.RCV_NXT dd ? ; next receive sequence number to use
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.RCV_WND dd ? ; receive window
|
||||||
; 28| TCB STATE INTEL format|
|
.SEG_LEN dd ? ; segment length
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.SEG_WND dd ? ; segment window
|
||||||
; 32| TCB Timer (seconds) INTEL format|
|
.wndsizeTimer dd ? ; window size timer
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
.rxData dd ? ; receive data buffer here
|
||||||
; 36| ISS (Inital Sequence # used by this connection ) INET format|
|
ends
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 40| IRS ( Inital Receive Sequence # ) INET format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 44| SND.UNA Seq # of unack'ed sent packets INET format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 48| SND.NXT Next send seq # to use INET format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 52| SND.WND Send window INET format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 56| RCV.NXT Next expected receive sequence # INET format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 60| RCV.WND Receive window INET format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 64| SEG.LEN Segment length INTEL format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 68| SEG.WND Segment window INTEL format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 72| Retransmit queue # NOW WINDOW SIZE TIMER INTEL format|
|
|
||||||
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
; 76| RX Data Buffer |
|
|
||||||
; +-+-+-.......... -+
|
|
||||||
|
|
||||||
|
|
||||||
; so, define struct
|
|
||||||
struc SOCKET
|
|
||||||
{
|
|
||||||
.PrevPtr dd ?
|
|
||||||
.NextPtr dd ?
|
|
||||||
.Status dd ? ;+00 - Status ( of this buffer )
|
|
||||||
.PID dd ? ;+04 - Application Process ID
|
|
||||||
.LocalIP dd ? ;+08 - Local IP Address
|
|
||||||
.LocalPort dw ? ;+12 - Local Port
|
|
||||||
.RemoteIP dd ? ;+16 - Remote IP Address
|
|
||||||
.RemotePort dw ? ;+20 - Remote Port
|
|
||||||
.OrigRemoteIP dd ?
|
|
||||||
.OrigRemotePort dw ?
|
|
||||||
.rxDataCount dd ? ;+24 - Rx Data Count
|
|
||||||
.TCBState dd ? ;+28 - TCB STATE
|
|
||||||
.TCBTimer dd ? ;+32 - TCB Timer (seconds)
|
|
||||||
.ISS dd ? ;+36 - Initial Send Sequence
|
|
||||||
.IRS dd ? ;+40 - Initial Receive Sequence
|
|
||||||
.SND_UNA dd ? ;+44 - Sequence number of unack'ed sent packets
|
|
||||||
.SND_NXT dd ? ;+48 - Next send sequence number to use
|
|
||||||
.SND_WND dd ? ;+52 - Send window
|
|
||||||
.RCV_NXT dd ? ;+56 - Next receive sequence number to use
|
|
||||||
.RCV_WND dd ? ;+60 - Receive window
|
|
||||||
.SEG_LEN dd ? ;+64 - Segment length
|
|
||||||
.SEG_WND dd ? ;+68 - Segment window
|
|
||||||
.wndsizeTimer dd ? ;+72 - Retransmit queue # NOW WINDOW SIZE TIMER
|
|
||||||
.rxData dd ? ;+76 - receive data buffer here
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual at 0
|
|
||||||
SOCKET SOCKET
|
|
||||||
end virtual
|
|
||||||
|
|
||||||
; simple macro calcing real memory address of SOCKET struct by socket's
|
|
||||||
;macro Index2RealAddr reg
|
|
||||||
;{
|
|
||||||
; shl reg, 12
|
|
||||||
; add reg, sockets
|
|
||||||
;}
|
|
||||||
|
|
||||||
;Constants
|
|
||||||
; current socket statuses
|
|
||||||
SOCK_EMPTY = 0 ; socket not in use
|
|
||||||
SOCK_OPEN = 1 ; open issued, but no data sent
|
|
||||||
|
|
||||||
; TCP opening modes
|
; TCP opening modes
|
||||||
SOCKET_PASSIVE equ 0
|
SOCKET_PASSIVE = 0
|
||||||
SOCKET_ACTIVE equ 1
|
SOCKET_ACTIVE = 1
|
||||||
|
|
||||||
|
; socket types
|
||||||
|
SOCK_STREAM = 1
|
||||||
|
SOCK_DGRAM = 2
|
||||||
|
|
||||||
|
;; Allocate memory for socket data and put new socket into the list
|
||||||
|
; Newly created socket is initialized with calling PID and number and
|
||||||
|
; put into beginning of list (which is a fastest way).
|
||||||
|
;
|
||||||
|
; @return socket structure address in EAX
|
||||||
|
;;
|
||||||
proc net_socket_alloc stdcall uses ebx ecx edx edi
|
proc net_socket_alloc stdcall uses ebx ecx edx edi
|
||||||
stdcall kernel_alloc, SOCKETBUFFSIZE
|
stdcall kernel_alloc, SOCKETBUFFSIZE
|
||||||
DEBUGF 1, "K : net_socket_alloc (0x%x)\n", eax
|
DEBUGF 1, "K : net_socket_alloc (0x%x)\n", eax
|
||||||
|
; check if we can allocate needed amount of memory
|
||||||
or eax, eax
|
or eax, eax
|
||||||
jz .exit
|
jz .exit
|
||||||
|
|
||||||
|
; zero-initialize allocated memory
|
||||||
push eax
|
push eax
|
||||||
mov edi, eax
|
mov edi, eax
|
||||||
mov ecx, SOCKETBUFFSIZE / 4
|
mov ecx, SOCKETBUFFSIZE / 4
|
||||||
@ -144,6 +87,7 @@ proc net_socket_alloc stdcall uses ebx ecx edx edi
|
|||||||
rep stosd
|
rep stosd
|
||||||
pop eax
|
pop eax
|
||||||
|
|
||||||
|
; add socket to the list by changing pointers
|
||||||
mov ebx, net_sockets
|
mov ebx, net_sockets
|
||||||
push [ebx + SOCKET.NextPtr]
|
push [ebx + SOCKET.NextPtr]
|
||||||
mov [ebx + SOCKET.NextPtr], eax
|
mov [ebx + SOCKET.NextPtr], eax
|
||||||
@ -154,23 +98,50 @@ proc net_socket_alloc stdcall uses ebx ecx edx edi
|
|||||||
jz @f
|
jz @f
|
||||||
mov [ebx + SOCKET.PrevPtr], eax
|
mov [ebx + SOCKET.PrevPtr], eax
|
||||||
|
|
||||||
@@: mov ebx, [TASK_BASE]
|
@@: ; set socket owner PID to the one of calling process
|
||||||
|
mov ebx, [TASK_BASE]
|
||||||
mov ebx, [ebx + TASKDATA.pid]
|
mov ebx, [ebx + TASKDATA.pid]
|
||||||
mov [eax + SOCKET.PID], ebx
|
mov [eax + SOCKET.PID], ebx
|
||||||
|
|
||||||
|
; find first free socket number and use it
|
||||||
|
;mov edx, ebx
|
||||||
|
mov ebx, net_sockets
|
||||||
|
xor ecx, ecx
|
||||||
|
.next_socket_number:
|
||||||
|
inc ecx
|
||||||
|
.next_socket:
|
||||||
|
mov ebx, [ebx + SOCKET.NextPtr]
|
||||||
|
or ebx, ebx
|
||||||
|
jz .last_socket_number
|
||||||
|
cmp [ebx + SOCKET.Number], ecx
|
||||||
|
jne .next_socket
|
||||||
|
;cmp [ebx + SOCKET.PID], edx
|
||||||
|
;jne .next_socket
|
||||||
|
mov ebx, net_sockets
|
||||||
|
jmp .next_socket_number
|
||||||
|
|
||||||
|
.last_socket_number:
|
||||||
|
mov [eax + SOCKET.Number], ecx
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
proc net_socket_free stdcall uses ebx ecx edx, sock:DWORD
|
;; Free socket data memory and pop socket off the list
|
||||||
mov eax, [sock]
|
;
|
||||||
|
; @param sockAddr is a socket structure address
|
||||||
|
;;
|
||||||
|
proc net_socket_free stdcall uses ebx ecx edx, sockAddr:DWORD
|
||||||
|
mov eax, [sockAddr]
|
||||||
DEBUGF 1, "K : net_socket_free (0x%x)\n", eax
|
DEBUGF 1, "K : net_socket_free (0x%x)\n", eax
|
||||||
|
; check if we got something similar to socket structure address
|
||||||
or eax, eax
|
or eax, eax
|
||||||
jz .error
|
jz .error
|
||||||
|
|
||||||
|
; make sure sockAddr is one of the socket addresses in the list
|
||||||
mov ebx, net_sockets
|
mov ebx, net_sockets
|
||||||
mov ecx, [TASK_BASE]
|
;mov ecx, [TASK_BASE]
|
||||||
mov ecx, [ecx + TASKDATA.pid]
|
;mov ecx, [ecx + TASKDATA.pid]
|
||||||
.next_socket:
|
.next_socket:
|
||||||
mov ebx, [ebx + SOCKET.NextPtr]
|
mov ebx, [ebx + SOCKET.NextPtr]
|
||||||
or ebx, ebx
|
or ebx, ebx
|
||||||
@ -180,6 +151,8 @@ proc net_socket_free stdcall uses ebx ecx edx, sock:DWORD
|
|||||||
;cmp [ebx + SOCKET.PID], ecx
|
;cmp [ebx + SOCKET.PID], ecx
|
||||||
;jne .next_socket
|
;jne .next_socket
|
||||||
|
|
||||||
|
; okay, we found the correct one
|
||||||
|
; remove it from the list first, changing pointers
|
||||||
mov ebx, [eax + SOCKET.NextPtr]
|
mov ebx, [eax + SOCKET.NextPtr]
|
||||||
mov eax, [eax + SOCKET.PrevPtr]
|
mov eax, [eax + SOCKET.PrevPtr]
|
||||||
mov [eax + SOCKET.NextPtr], ebx
|
mov [eax + SOCKET.NextPtr], ebx
|
||||||
@ -187,7 +160,8 @@ proc net_socket_free stdcall uses ebx ecx edx, sock:DWORD
|
|||||||
jz @f
|
jz @f
|
||||||
mov [ebx + SOCKET.PrevPtr], eax
|
mov [ebx + SOCKET.PrevPtr], eax
|
||||||
|
|
||||||
@@: stdcall kernel_free, [sock]
|
@@: ; and finally free the memory structure used
|
||||||
|
stdcall kernel_free, [sockAddr]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.error:
|
.error:
|
||||||
@ -195,12 +169,60 @@ proc net_socket_free stdcall uses ebx ecx edx, sock:DWORD
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
proc net_socket_num_to_addr stdcall uses ebx ecx, x:DWORD
|
;; Get socket structure address by its number
|
||||||
; FIXME: do real transform
|
; Scan through sockets list to find the socket with specified number.
|
||||||
mov eax, [x]
|
; This proc uses SOCKET.PID indirectly to check if socket is owned by
|
||||||
|
; calling process.
|
||||||
|
;
|
||||||
|
; @param sockNum is a socket number
|
||||||
|
; @return socket structure address or 0 (not found) in EAX
|
||||||
|
;;
|
||||||
|
proc net_socket_num_to_addr stdcall uses ebx ecx, sockNum:DWORD
|
||||||
|
mov eax, [sockNum]
|
||||||
|
; check if we got something similar to socket number
|
||||||
|
or eax, eax
|
||||||
|
jz .error
|
||||||
|
|
||||||
|
; scan through sockets list
|
||||||
mov ebx, net_sockets
|
mov ebx, net_sockets
|
||||||
mov ecx, [TASK_BASE]
|
;mov ecx, [TASK_BASE]
|
||||||
mov ecx, [ecx + TASKDATA.pid]
|
;mov ecx, [ecx + TASKDATA.pid]
|
||||||
|
.next_socket:
|
||||||
|
mov ebx, [ebx + SOCKET.NextPtr]
|
||||||
|
or ebx, ebx
|
||||||
|
jz .error
|
||||||
|
cmp [ebx + SOCKET.Number], eax
|
||||||
|
jne .next_socket
|
||||||
|
;cmp [ebx + SOCKET.PID], ecx
|
||||||
|
;jne .next_socket
|
||||||
|
|
||||||
|
; okay, we found the correct one
|
||||||
|
mov eax, ebx
|
||||||
|
ret
|
||||||
|
|
||||||
|
.error:
|
||||||
|
xor eax, eax
|
||||||
|
ret
|
||||||
|
endp
|
||||||
|
|
||||||
|
;; Get socket number by its structure address
|
||||||
|
; Scan through sockets list to find the socket with specified address.
|
||||||
|
; This proc uses SOCKET.PID indirectly to check if socket is owned by
|
||||||
|
; calling process.
|
||||||
|
;
|
||||||
|
; @param sockAddr is a socket structure address
|
||||||
|
; @return socket number (SOCKET.Number) or 0 (not found) in EAX
|
||||||
|
;;
|
||||||
|
proc net_socket_addr_to_num stdcall uses ebx ecx, sockAddr:DWORD
|
||||||
|
mov eax, [sockAddr]
|
||||||
|
; check if we got something similar to socket structure address
|
||||||
|
or eax, eax
|
||||||
|
jz .error
|
||||||
|
|
||||||
|
; scan through sockets list
|
||||||
|
mov ebx, net_sockets
|
||||||
|
;mov ecx, [TASK_BASE]
|
||||||
|
;mov ecx, [ecx + TASKDATA.pid]
|
||||||
.next_socket:
|
.next_socket:
|
||||||
mov ebx, [ebx + SOCKET.NextPtr]
|
mov ebx, [ebx + SOCKET.NextPtr]
|
||||||
or ebx, ebx
|
or ebx, ebx
|
||||||
@ -209,6 +231,9 @@ proc net_socket_num_to_addr stdcall uses ebx ecx, x:DWORD
|
|||||||
jne .next_socket
|
jne .next_socket
|
||||||
;cmp [ebx + SOCKET.PID], ecx
|
;cmp [ebx + SOCKET.PID], ecx
|
||||||
;jne .next_socket
|
;jne .next_socket
|
||||||
|
|
||||||
|
; okay, we found the correct one
|
||||||
|
mov eax, [ebx + SOCKET.Number]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.error:
|
.error:
|
||||||
@ -216,45 +241,23 @@ proc net_socket_num_to_addr stdcall uses ebx ecx, x:DWORD
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
proc net_socket_addr_to_num stdcall uses ebx ecx, x:DWORD
|
;; [53.9] Check if local port is used by any socket in the system.
|
||||||
; FIXME: do real transform
|
; Scan through sockets list, checking SOCKET.LocalPort.
|
||||||
mov eax, [x]
|
; Useful when you want a to generate a unique local port number.
|
||||||
mov ebx, net_sockets
|
; This proc doesn't guarantee that after calling it and trying to use
|
||||||
mov ecx, [TASK_BASE]
|
; the port reported being free in calls to socket_open/socket_open_tcp it'll
|
||||||
mov ecx, [ecx + TASKDATA.pid]
|
; still be free or otherwise it'll still be used if reported being in use.
|
||||||
.next_socket:
|
|
||||||
mov ebx, [ebx + SOCKET.NextPtr]
|
|
||||||
or ebx, ebx
|
|
||||||
jz .error
|
|
||||||
cmp ebx, eax
|
|
||||||
jne .next_socket
|
|
||||||
;cmp [ebx + SOCKET.PID], ecx
|
|
||||||
;jne .next_socket
|
|
||||||
ret
|
|
||||||
|
|
||||||
.error:
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
endp
|
|
||||||
|
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; is_localport_unused
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param BX is a port number
|
||||||
; scans through all the active sockets , looking to see if the
|
; @return 1 (port is free) or 0 (port is in use) in EAX
|
||||||
; port number specified in bx is in use as a localport number.
|
;;
|
||||||
; This is useful when you want a to generate a unique local port
|
|
||||||
; number.
|
|
||||||
; On return, eax = 1 for free, 0 for in use
|
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc is_localport_unused stdcall
|
proc is_localport_unused stdcall
|
||||||
|
|
||||||
xchg bl, bh
|
xchg bl, bh
|
||||||
|
|
||||||
xor eax, eax ; Assume the return value is 'free'
|
; assume the return value is 'free'
|
||||||
|
xor eax, eax
|
||||||
inc al
|
inc al
|
||||||
|
|
||||||
mov edx, net_sockets
|
mov edx, net_sockets
|
||||||
|
|
||||||
.next_socket:
|
.next_socket:
|
||||||
@ -262,27 +265,22 @@ proc is_localport_unused stdcall
|
|||||||
or edx, edx
|
or edx, edx
|
||||||
jz .exit
|
jz .exit
|
||||||
cmp [edx + SOCKET.LocalPort], bx
|
cmp [edx + SOCKET.LocalPort], bx
|
||||||
jne .next_socket ; Return back if the port is not occupied
|
jne .next_socket
|
||||||
|
|
||||||
dec al ; return 'in use'
|
; return 'in use'
|
||||||
|
dec al
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.0] Open DGRAM socket (connectionless, unreliable)
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; socket_open
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param BX is local port number
|
||||||
; find a free socket
|
; @param CX is remote port number
|
||||||
; local port in ebx
|
; @param EDX is remote IP address
|
||||||
; remote port in ecx
|
; @return socket number or -1 (error) in EAX
|
||||||
; remote ip in edx
|
;;
|
||||||
; return socket # in eax, -1 if none available
|
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_open stdcall
|
proc socket_open stdcall
|
||||||
call net_socket_alloc
|
call net_socket_alloc
|
||||||
or eax, eax
|
or eax, eax
|
||||||
@ -292,7 +290,6 @@ proc socket_open stdcall
|
|||||||
|
|
||||||
push eax
|
push eax
|
||||||
|
|
||||||
mov [eax + SOCKET.Status], SOCK_OPEN
|
|
||||||
xchg bh, bl
|
xchg bh, bl
|
||||||
mov [eax + SOCKET.LocalPort], bx
|
mov [eax + SOCKET.LocalPort], bx
|
||||||
xchg ch, cl
|
xchg ch, cl
|
||||||
@ -311,21 +308,14 @@ proc socket_open stdcall
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.5] Open STREAM socket (connection-based, sequenced, reliable, two-way)
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; socket_open_tcp
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param BX is local port number
|
||||||
; Opens a TCP socket in PASSIVE or ACTIVE mode
|
; @param CX is remote port number
|
||||||
; find a free socket
|
; @param EDX is remote IP address
|
||||||
; local port in ebx ( intel format )
|
; @param ESI is open mode (SOCKET_ACTIVE, SOCKET_PASSIVE)
|
||||||
; remote port in ecx ( intel format )
|
; @return socket number or -1 (error) in EAX
|
||||||
; remote ip in edx ( in Internet byte order )
|
;;
|
||||||
; Socket open mode in esi ( SOCKET_PASSIVE or SOCKET_ACTIVE )
|
|
||||||
; return socket # in eax, -1 if none available
|
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_open_tcp stdcall
|
proc socket_open_tcp stdcall
|
||||||
local sockAddr dd ?
|
local sockAddr dd ?
|
||||||
|
|
||||||
@ -364,7 +354,6 @@ local sockAddr dd ?
|
|||||||
mov [sockAddr], eax
|
mov [sockAddr], eax
|
||||||
|
|
||||||
; TODO - check this works!
|
; TODO - check this works!
|
||||||
;xxx: already 0 (intialized by net_socket_alloc)
|
|
||||||
;mov [eax + SOCKET.wndsizeTimer], 0 ; Reset the window timer.
|
;mov [eax + SOCKET.wndsizeTimer], 0 ; Reset the window timer.
|
||||||
|
|
||||||
xchg bh, bl
|
xchg bh, bl
|
||||||
@ -417,10 +406,8 @@ local sockAddr dd ?
|
|||||||
call inc_inet_esi
|
call inc_inet_esi
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
mov ebx, [sockAddr]
|
; Get the socket number back, so we can return it
|
||||||
mov [ebx + SOCKET.Status], SOCK_OPEN
|
stdcall net_socket_addr_to_num, [sockAddr]
|
||||||
;pop eax ; Get the socket number back, so we can return it
|
|
||||||
stdcall net_socket_addr_to_num, ebx
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.error:
|
.error:
|
||||||
@ -429,32 +416,18 @@ local sockAddr dd ?
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.1] Close DGRAM socket
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; socket_close
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param EBX is socket number
|
||||||
; socket # in ebx
|
; @return 0 (closed successfully) or -1 (error) in EAX
|
||||||
; returns 0 for ok, -1 for socket not open (fail)
|
;;
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_close stdcall
|
proc socket_close stdcall
|
||||||
DEBUGF 1, "K : socket_close (0x%x)\n", ebx
|
DEBUGF 1, "K : socket_close (0x%x)\n", ebx
|
||||||
stdcall net_socket_num_to_addr, ebx
|
stdcall net_socket_num_to_addr, ebx
|
||||||
or eax, eax
|
or eax, eax
|
||||||
jz .error
|
jz .error
|
||||||
|
|
||||||
cmp [eax + SOCKET.Status], dword SOCK_EMPTY
|
|
||||||
jz .error
|
|
||||||
|
|
||||||
; Clear the socket varaibles
|
|
||||||
stdcall net_socket_free, eax
|
stdcall net_socket_free, eax
|
||||||
; mov edi, eax
|
|
||||||
; xor eax, eax
|
|
||||||
; mov ecx, SOCKETHEADERSIZE
|
|
||||||
; cld
|
|
||||||
; rep stosb
|
|
||||||
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
ret
|
ret
|
||||||
@ -465,18 +438,16 @@ proc socket_close stdcall
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.8] Close STREAM socket
|
||||||
;***************************************************************************
|
; Closing TCP sockets takes time, so when you get successful return code
|
||||||
; Function
|
; from this function doesn't always mean that socket is actually closed.
|
||||||
; socket_close_tcp
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param EBX is socket number
|
||||||
; socket # in ebx
|
; @return 0 (closed successfully) or -1 (error) in EAX
|
||||||
; returns 0 for ok, -1 for socket not open (fail)
|
;;
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_close_tcp stdcall
|
proc socket_close_tcp stdcall
|
||||||
local sockAddr dd ?
|
local sockAddr dd ?
|
||||||
|
|
||||||
DEBUGF 1, "K : socket_close_tcp (0x%x)\n", ebx
|
DEBUGF 1, "K : socket_close_tcp (0x%x)\n", ebx
|
||||||
; first, remove any resend entries
|
; first, remove any resend entries
|
||||||
pusha
|
pusha
|
||||||
@ -487,14 +458,12 @@ local sockAddr dd ?
|
|||||||
.next_resendq:
|
.next_resendq:
|
||||||
cmp ecx, NUMRESENDENTRIES
|
cmp ecx, NUMRESENDENTRIES
|
||||||
je .last_resendq ; None left
|
je .last_resendq ; None left
|
||||||
;cmp [esi], bl ; XTODO: bl -> ebx
|
|
||||||
cmp [esi + 4], ebx
|
cmp [esi + 4], ebx
|
||||||
je @f ; found one
|
je @f ; found one
|
||||||
inc ecx
|
inc ecx
|
||||||
add esi, 8
|
add esi, 8
|
||||||
jmp .next_resendq
|
jmp .next_resendq
|
||||||
|
|
||||||
;@@: mov byte[esi], 0xff ; XTODO: 0xff -> 0
|
|
||||||
@@: mov dword[esi + 4], 0
|
@@: mov dword[esi + 4], 0
|
||||||
inc ecx
|
inc ecx
|
||||||
add esi, 8
|
add esi, 8
|
||||||
@ -509,13 +478,11 @@ local sockAddr dd ?
|
|||||||
|
|
||||||
mov ebx, eax
|
mov ebx, eax
|
||||||
mov [sockAddr], eax
|
mov [sockAddr], eax
|
||||||
cmp [ebx + SOCKET.Status], SOCK_EMPTY
|
|
||||||
je .error
|
|
||||||
|
|
||||||
cmp [ebx + SOCKET.TCBState], TCB_LISTEN ;xxx
|
cmp [ebx + SOCKET.TCBState], TCB_LISTEN
|
||||||
je .destroy_tcb ;xxx
|
je .destroy_tcb
|
||||||
cmp [ebx + SOCKET.TCBState], TCB_SYN_SENT ;xxx
|
cmp [ebx + SOCKET.TCBState], TCB_SYN_SENT
|
||||||
je .destroy_tcb ;xxx
|
je .destroy_tcb
|
||||||
|
|
||||||
; Now construct the response, and queue for sending by IP
|
; Now construct the response, and queue for sending by IP
|
||||||
mov eax, EMPTY_QUEUE
|
mov eax, EMPTY_QUEUE
|
||||||
@ -525,8 +492,7 @@ local sockAddr dd ?
|
|||||||
|
|
||||||
push eax
|
push eax
|
||||||
|
|
||||||
;xxx mov bl, TH_FIN + TH_ACK
|
mov bl, TH_FIN
|
||||||
mov bl, TH_FIN ;xxx
|
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
xor esi, esi
|
xor esi, esi
|
||||||
stdcall build_tcp_packet, [sockAddr]
|
stdcall build_tcp_packet, [sockAddr]
|
||||||
@ -538,10 +504,6 @@ local sockAddr dd ?
|
|||||||
|
|
||||||
; Get the socket state
|
; Get the socket state
|
||||||
mov eax, [ebx + SOCKET.TCBState]
|
mov eax, [ebx + SOCKET.TCBState]
|
||||||
;xxx cmp eax, TCB_LISTEN
|
|
||||||
;xxx je .destroy_tcb
|
|
||||||
;xxx cmp eax, TCB_SYN_SENT
|
|
||||||
;xxx je .destroy_tcb
|
|
||||||
cmp eax, TCB_SYN_RECEIVED
|
cmp eax, TCB_SYN_RECEIVED
|
||||||
je .fin_wait_1
|
je .fin_wait_1
|
||||||
cmp eax, TCB_ESTABLISHED
|
cmp eax, TCB_ESTABLISHED
|
||||||
@ -549,7 +511,6 @@ local sockAddr dd ?
|
|||||||
|
|
||||||
; assume CLOSE WAIT
|
; assume CLOSE WAIT
|
||||||
; Send a fin, then enter last-ack state
|
; Send a fin, then enter last-ack state
|
||||||
; TODO: check if it's really a TCB_CLOSE_WAIT
|
|
||||||
mov [ebx + SOCKET.TCBState], TCB_LAST_ACK
|
mov [ebx + SOCKET.TCBState], TCB_LAST_ACK
|
||||||
jmp .send
|
jmp .send
|
||||||
|
|
||||||
@ -572,10 +533,8 @@ local sockAddr dd ?
|
|||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
.destroy_tcb:
|
.destroy_tcb:
|
||||||
;xxx pop eax
|
|
||||||
|
|
||||||
; Clear the socket variables
|
; Clear the socket variables
|
||||||
;xxx stdcall net_socket_free, [sockAddr]
|
|
||||||
stdcall net_socket_free, ebx
|
stdcall net_socket_free, ebx
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
@ -588,16 +547,11 @@ local sockAddr dd ?
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.2] Poll socket
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; socket_poll
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param EBX is socket number
|
||||||
; socket # in ebx
|
; @return count or bytes in rx buffer or 0 (error) in EAX
|
||||||
; returns count in eax.
|
;;
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_poll stdcall
|
proc socket_poll stdcall
|
||||||
; DEBUGF 1, "socket_poll(0x%x)\n", ebx
|
; DEBUGF 1, "socket_poll(0x%x)\n", ebx
|
||||||
stdcall net_socket_num_to_addr, ebx
|
stdcall net_socket_num_to_addr, ebx
|
||||||
@ -612,16 +566,11 @@ proc socket_poll stdcall
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.6] Get socket TCB state
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; socket_status
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param EBX is socket number
|
||||||
; socket # in ebx
|
; @return socket TCB state or 0 (error) in EAX
|
||||||
; returns TCB state in eax.
|
;;
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_status stdcall
|
proc socket_status stdcall
|
||||||
;; DEBUGF 1, "socket_status(0x%x)\n", ebx
|
;; DEBUGF 1, "socket_status(0x%x)\n", ebx
|
||||||
stdcall net_socket_num_to_addr, ebx
|
stdcall net_socket_num_to_addr, ebx
|
||||||
@ -636,21 +585,15 @@ proc socket_status stdcall
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; Index2RealAddr ebx
|
;; [53.3] Get one byte from rx buffer
|
||||||
; mov eax, [ebx + SOCKET.TCBState]
|
; This function can return 0 in two cases: if there's one byte read and
|
||||||
|
; non left, and if an error occured. Behavior should be changed and function
|
||||||
|
; shouldn't be used for now. Consider using [53.11] instead.
|
||||||
;
|
;
|
||||||
; ret
|
; @param EBX is socket number
|
||||||
|
; @return number of bytes left in rx buffer or 0 (error) in EAX
|
||||||
|
; @return byte read in BL
|
||||||
;***************************************************************************
|
;;
|
||||||
; Function
|
|
||||||
; socket_read
|
|
||||||
;
|
|
||||||
; Description
|
|
||||||
; socket # in ebx
|
|
||||||
; returns # of bytes remaining in eax, data in bl
|
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_read stdcall
|
proc socket_read stdcall
|
||||||
; DEBUGF 1, "socket_read(0x%x)\n", ebx
|
; DEBUGF 1, "socket_read(0x%x)\n", ebx
|
||||||
stdcall net_socket_num_to_addr, ebx
|
stdcall net_socket_num_to_addr, ebx
|
||||||
@ -681,23 +624,21 @@ proc socket_read stdcall
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
.error:
|
.error:
|
||||||
xor eax, eax
|
|
||||||
xor ebx, ebx
|
xor ebx, ebx
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.11] Get specified number of bytes from rx buffer
|
||||||
;***************************************************************************
|
; Number of bytes in rx buffer can be less than requested size. In this case,
|
||||||
; Function
|
; only available number of bytes is read.
|
||||||
; socket_read_packet
|
; This function can return 0 in two cases: if there's no data to read, and if
|
||||||
|
; an error occured. Behavior should be changed.
|
||||||
;
|
;
|
||||||
; Description
|
; @param EBX is socket number
|
||||||
; socket # in ebx
|
; @param ECX is pointer to application buffer
|
||||||
; datapointer # in ecx
|
; @param EDX is application buffer size (number of bytes to read)
|
||||||
; buffer size in edx
|
; @return number of bytes read or 0 (error) in EAX
|
||||||
; returns # of bytes copied in eax
|
;;
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_read_packet stdcall
|
proc socket_read_packet stdcall
|
||||||
; DEBUGF 1, "socket_read_packet(0x%x)\n", ebx
|
; DEBUGF 1, "socket_read_packet(0x%x)\n", ebx
|
||||||
stdcall net_socket_num_to_addr, ebx ; get real socket address
|
stdcall net_socket_num_to_addr, ebx ; get real socket address
|
||||||
@ -761,19 +702,13 @@ proc socket_read_packet stdcall
|
|||||||
retn ; exit, or go back to shift remaining bytes if any
|
retn ; exit, or go back to shift remaining bytes if any
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.4] Send data through DGRAM socket
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; socket_write
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param EBX is socket number
|
||||||
; socket in ebx
|
; @param ECX is application data size (number of bytes to send)
|
||||||
; # of bytes to write in ecx
|
; @param EDX is pointer to application data buffer
|
||||||
; pointer to data in edx
|
; @return 0 (sent successfully) or -1 (error) in EAX
|
||||||
; returns 0 in eax ok, -1 == failed ( invalid socket, or
|
;;
|
||||||
; could not queue IP packet )
|
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_write stdcall
|
proc socket_write stdcall
|
||||||
; DEBUGF 1, "socket_write(0x%x)\n", ebx
|
; DEBUGF 1, "socket_write(0x%x)\n", ebx
|
||||||
stdcall net_socket_num_to_addr, ebx ; get real socket address
|
stdcall net_socket_num_to_addr, ebx ; get real socket address
|
||||||
@ -782,10 +717,6 @@ proc socket_write stdcall
|
|||||||
|
|
||||||
mov ebx, eax
|
mov ebx, eax
|
||||||
|
|
||||||
; If the socket is invalid, return with an error code
|
|
||||||
cmp [ebx + SOCKET.Status], SOCK_EMPTY
|
|
||||||
je .error
|
|
||||||
|
|
||||||
mov eax, EMPTY_QUEUE
|
mov eax, EMPTY_QUEUE
|
||||||
call dequeue
|
call dequeue
|
||||||
cmp ax, NO_BUFFER
|
cmp ax, NO_BUFFER
|
||||||
@ -930,19 +861,13 @@ proc socket_write stdcall
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
;; [53.7] Send data through STREAM socket
|
||||||
;***************************************************************************
|
|
||||||
; Function
|
|
||||||
; socket_write_tcp
|
|
||||||
;
|
;
|
||||||
; Description
|
; @param EBX is socket number
|
||||||
; socket in ebx
|
; @param ECX is application data size (number of bytes to send)
|
||||||
; # of bytes to write in ecx
|
; @param EDX is pointer to application data buffer
|
||||||
; pointer to data in edx
|
; @return 0 (sent successfully) or -1 (error) in EAX
|
||||||
; returns 0 in eax ok, -1 == failed ( invalid socket, or
|
;;
|
||||||
; could not queue IP packet )
|
|
||||||
;
|
|
||||||
;***************************************************************************
|
|
||||||
proc socket_write_tcp stdcall
|
proc socket_write_tcp stdcall
|
||||||
local sockAddr dd ?
|
local sockAddr dd ?
|
||||||
|
|
||||||
@ -954,12 +879,7 @@ local sockAddr dd ?
|
|||||||
mov ebx, eax
|
mov ebx, eax
|
||||||
mov [sockAddr], ebx
|
mov [sockAddr], ebx
|
||||||
|
|
||||||
; If the socket is invalid, return with an error code
|
|
||||||
cmp [ebx + SOCKET.Status], SOCK_EMPTY
|
|
||||||
je .error
|
|
||||||
|
|
||||||
; If the sockets window timer is nonzero, do not queue packet
|
; If the sockets window timer is nonzero, do not queue packet
|
||||||
; TODO - done
|
|
||||||
cmp [ebx + SOCKET.wndsizeTimer], 0
|
cmp [ebx + SOCKET.wndsizeTimer], 0
|
||||||
jne .error
|
jne .error
|
||||||
|
|
||||||
@ -1020,7 +940,6 @@ local sockAddr dd ?
|
|||||||
.next_resendq:
|
.next_resendq:
|
||||||
cmp ecx, NUMRESENDENTRIES
|
cmp ecx, NUMRESENDENTRIES
|
||||||
je .exit ; None found
|
je .exit ; None found
|
||||||
;cmp byte[esi], 0xff ; XTODO: 0xff -> 0
|
|
||||||
cmp dword[esi + 4], 0
|
cmp dword[esi + 4], 0
|
||||||
je @f ; found one
|
je @f ; found one
|
||||||
inc ecx
|
inc ecx
|
||||||
@ -1038,7 +957,6 @@ local sockAddr dd ?
|
|||||||
; fill IP buffer associated with this descriptor
|
; fill IP buffer associated with this descriptor
|
||||||
|
|
||||||
stdcall net_socket_addr_to_num, [sockAddr]
|
stdcall net_socket_addr_to_num, [sockAddr]
|
||||||
;mov [esi], al ; XTODO: al -> eax
|
|
||||||
mov [esi + 4], eax
|
mov [esi + 4], eax
|
||||||
mov byte[esi + 1], TCP_RETRIES
|
mov byte[esi + 1], TCP_RETRIES
|
||||||
mov word[esi + 2], TCP_TIMEOUT
|
mov word[esi + 2], TCP_TIMEOUT
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;; TCP/IP stack for Menuet OS ;;
|
;; TCP/IP stack for Menuet OS ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Version 0.7 4th July 2004 ;;
|
|
||||||
;; ;;
|
|
||||||
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; See file COPYING for details ;;
|
;; See file COPYING for details ;;
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;; TCP Processes for Menuet OS TCP/IP stack ;;
|
;; TCP Processes for Menuet OS TCP/IP stack ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Version 0.6 4th July 2004 ;;
|
|
||||||
;; ;;
|
|
||||||
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; See file COPYING for details ;;
|
;; See file COPYING for details ;;
|
||||||
@ -125,7 +123,7 @@ proc tcp_tcb_handler stdcall uses ebx
|
|||||||
or ebx, ebx
|
or ebx, ebx
|
||||||
jz .exit
|
jz .exit
|
||||||
|
|
||||||
DEBUGF 1, "K : %x: %x-%x-%x-%u\n", ebx, [ebx + SOCKET.LocalPort]:4, [ebx + SOCKET.RemoteIP], [ebx + SOCKET.RemotePort]:4, [ebx + SOCKET.TCBState]
|
DEBUGF 1, "K : %x-%x: %x-%x-%x-%u\n", [ebx + SOCKET.PID]:2, [ebx + SOCKET.Number]:2, [ebx + SOCKET.LocalPort]:4, [ebx + SOCKET.RemoteIP], [ebx + SOCKET.RemotePort]:4, [ebx + SOCKET.TCBState]
|
||||||
|
|
||||||
cmp [ebx + SOCKET.TCBTimer], 0
|
cmp [ebx + SOCKET.TCBTimer], 0
|
||||||
jne .decrement_tcb
|
jne .decrement_tcb
|
||||||
@ -177,7 +175,6 @@ proc tcp_tx_handler stdcall
|
|||||||
.next_resendq:
|
.next_resendq:
|
||||||
cmp ecx, NUMRESENDENTRIES
|
cmp ecx, NUMRESENDENTRIES
|
||||||
je .exit ; None left
|
je .exit ; None left
|
||||||
;cmp [esi], byte 0xFF ; XTODO: 0xff -> 0
|
|
||||||
cmp dword[esi + 4], 0
|
cmp dword[esi + 4], 0
|
||||||
jne @f ; found one
|
jne @f ; found one
|
||||||
inc ecx
|
inc ecx
|
||||||
@ -192,7 +189,6 @@ proc tcp_tx_handler stdcall
|
|||||||
jmp .next_resendq ; Timer not zero, so move on
|
jmp .next_resendq ; Timer not zero, so move on
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
;mov bl, 0xff ; XTODO: bl -> ebx, 0xff -> 0
|
|
||||||
xor ebx, ebx
|
xor ebx, ebx
|
||||||
; restart timer, and decrement retries
|
; restart timer, and decrement retries
|
||||||
; After the first resend, back of on next, by a factor of 5
|
; After the first resend, back of on next, by a factor of 5
|
||||||
@ -201,7 +197,6 @@ proc tcp_tx_handler stdcall
|
|||||||
jnz @f
|
jnz @f
|
||||||
|
|
||||||
; retries now 0, so delete from queue
|
; retries now 0, so delete from queue
|
||||||
;xchg [esi], bl ; XTODO: bl -> ebx
|
|
||||||
xchg [esi + 4], ebx
|
xchg [esi + 4], ebx
|
||||||
|
|
||||||
@@: ; resend packet
|
@@: ; resend packet
|
||||||
@ -213,10 +208,8 @@ proc tcp_tx_handler stdcall
|
|||||||
jne .tth004z
|
jne .tth004z
|
||||||
|
|
||||||
; TODO - try again in 10ms.
|
; TODO - try again in 10ms.
|
||||||
;cmp bl, 0xff ; XTODO: 0xff -> 0
|
|
||||||
test ebx, ebx
|
test ebx, ebx
|
||||||
jnz @f
|
jnz @f
|
||||||
;mov [esi], bl ; XTODO: bl -> ebx
|
|
||||||
mov [esi + 4], ebx
|
mov [esi + 4], ebx
|
||||||
|
|
||||||
@@: ; Mark it to expire in 10ms - 1 tick
|
@@: ; Mark it to expire in 10ms - 1 tick
|
||||||
@ -310,9 +303,6 @@ proc tcp_rx stdcall uses ebx
|
|||||||
or ebx, ebx
|
or ebx, ebx
|
||||||
jz .next_socket.1.exit
|
jz .next_socket.1.exit
|
||||||
|
|
||||||
cmp [ebx + SOCKET.Status], SOCK_OPEN
|
|
||||||
jne .next_socket.1
|
|
||||||
|
|
||||||
; DEBUGF 1, "K : tcp_rx - 1.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
|
; DEBUGF 1, "K : tcp_rx - 1.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
|
||||||
|
|
||||||
mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr
|
mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr
|
||||||
@ -349,9 +339,6 @@ proc tcp_rx stdcall uses ebx
|
|||||||
or ebx, ebx
|
or ebx, ebx
|
||||||
jz .next_socket.2.exit
|
jz .next_socket.2.exit
|
||||||
|
|
||||||
cmp [ebx + SOCKET.Status], SOCK_OPEN
|
|
||||||
jne .next_socket.2
|
|
||||||
|
|
||||||
; DEBUGF 1, "K : tcp_rx - 2.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
|
; DEBUGF 1, "K : tcp_rx - 2.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
|
||||||
|
|
||||||
mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr
|
mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr
|
||||||
@ -387,9 +374,6 @@ proc tcp_rx stdcall uses ebx
|
|||||||
or ebx, ebx
|
or ebx, ebx
|
||||||
jz .next_socket.3.exit
|
jz .next_socket.3.exit
|
||||||
|
|
||||||
cmp [ebx + SOCKET.Status], SOCK_OPEN
|
|
||||||
jne .next_socket.3
|
|
||||||
|
|
||||||
; DEBUGF 1, "K : tcp_rx - 3.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
|
; DEBUGF 1, "K : tcp_rx - 3.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
|
||||||
|
|
||||||
mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get destination port from the TCP hdr
|
mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get destination port from the TCP hdr
|
||||||
@ -415,16 +399,7 @@ proc tcp_rx stdcall uses ebx
|
|||||||
|
|
||||||
DEBUGF 1, "K : tcp_rx - dumped\n"
|
DEBUGF 1, "K : tcp_rx - dumped\n"
|
||||||
DEBUGF 1, "K : --------: %x-%x-%x (flags: %x)\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [edx + IP_PACKET.SourceAddress], [edx + 20 + TCP_PACKET.SourcePort]:4, [edx + 20 + TCP_PACKET.Flags]:2
|
DEBUGF 1, "K : --------: %x-%x-%x (flags: %x)\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [edx + IP_PACKET.SourceAddress], [edx + 20 + TCP_PACKET.SourcePort]:4, [edx + 20 + TCP_PACKET.Flags]:2
|
||||||
; mov ebx, net_sockets
|
|
||||||
;
|
|
||||||
; .next_socket.4:
|
|
||||||
; mov ebx, [ebx + SOCKET.NextPtr]
|
|
||||||
; or ebx, ebx
|
|
||||||
; jz .next_socket.4.exit
|
|
||||||
; DEBUGF 1, "K : %x: %x-%x-%x-%u\n", ebx, [ebx + SOCKET.LocalPort]:4, [ebx + SOCKET.RemoteIP], [ebx + SOCKET.RemotePort]:4, [ebx + SOCKET.TCBState]
|
|
||||||
; jne .next_socket.4
|
|
||||||
;
|
|
||||||
; .next_socket.4.exit:
|
|
||||||
inc [dumped_rx_count]
|
inc [dumped_rx_count]
|
||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
@ -655,7 +630,6 @@ proc tcpStateMachine stdcall, sockAddr:DWORD
|
|||||||
.next_resendq:
|
.next_resendq:
|
||||||
cmp ecx, NUMRESENDENTRIES
|
cmp ecx, NUMRESENDENTRIES
|
||||||
je .call_handler ; None left
|
je .call_handler ; None left
|
||||||
;cmp [esi], al ; XTODO: al -> eax
|
|
||||||
cmp [esi + 4], eax
|
cmp [esi + 4], eax
|
||||||
je @f ; found one
|
je @f ; found one
|
||||||
inc ecx
|
inc ecx
|
||||||
@ -696,7 +670,6 @@ proc tcpStateMachine stdcall, sockAddr:DWORD
|
|||||||
add esi, 8
|
add esi, 8
|
||||||
jmp .next_resendq
|
jmp .next_resendq
|
||||||
|
|
||||||
;@@: mov byte[esi], 0xff ; XTODO: 0xff -> 0
|
|
||||||
@@: mov dword[esi + 4], 0
|
@@: mov dword[esi + 4], 0
|
||||||
inc ecx
|
inc ecx
|
||||||
add esi, 8
|
add esi, 8
|
||||||
@ -845,16 +818,16 @@ proc stateTCB_SYN_RECEIVED stdcall, sockAddr:DWORD
|
|||||||
; For now, if the packet is an ACK, process it,
|
; For now, if the packet is an ACK, process it,
|
||||||
; If not, ignore it
|
; If not, ignore it
|
||||||
|
|
||||||
test [edx + 20 + TCP_PACKET.Flags], TH_RST ;xxx
|
test [edx + 20 + TCP_PACKET.Flags], TH_RST
|
||||||
jz .check_ack ;xxx
|
jz .check_ack
|
||||||
|
|
||||||
push [ebx + SOCKET.OrigRemotePort] [ebx + SOCKET.OrigRemoteIP]
|
push [ebx + SOCKET.OrigRemotePort] [ebx + SOCKET.OrigRemoteIP]
|
||||||
pop [ebx + SOCKET.RemoteIP] [ebx + SOCKET.RemotePort]
|
pop [ebx + SOCKET.RemoteIP] [ebx + SOCKET.RemotePort]
|
||||||
|
|
||||||
mov [ebx + SOCKET.TCBState], TCB_LISTEN ;xxx
|
mov [ebx + SOCKET.TCBState], TCB_LISTEN
|
||||||
jmp .exit ;xxx
|
jmp .exit
|
||||||
|
|
||||||
.check_ack: ;xxx
|
.check_ack:
|
||||||
; Look at control flags - expecting an ACK
|
; Look at control flags - expecting an ACK
|
||||||
test [edx + 20 + TCP_PACKET.Flags], TH_ACK
|
test [edx + 20 + TCP_PACKET.Flags], TH_ACK
|
||||||
jz .exit
|
jz .exit
|
||||||
@ -871,10 +844,8 @@ proc stateTCB_ESTABLISHED stdcall, sockAddr:DWORD
|
|||||||
; OR both...
|
; OR both...
|
||||||
|
|
||||||
; Did we receive a FIN or RST?
|
; Did we receive a FIN or RST?
|
||||||
;xxx test [edx + 20 + TCP_PACKET.Flags], TH_FIN + TH_RST
|
test [edx + 20 + TCP_PACKET.Flags], TH_FIN
|
||||||
;xxx jz .check_ack
|
jz .check_ack
|
||||||
test [edx + 20 + TCP_PACKET.Flags], TH_FIN ;xxx
|
|
||||||
jz .check_ack ;xxx
|
|
||||||
|
|
||||||
; It was a fin or reset.
|
; It was a fin or reset.
|
||||||
|
|
||||||
@ -890,14 +861,12 @@ proc stateTCB_ESTABLISHED stdcall, sockAddr:DWORD
|
|||||||
.next_resendq:
|
.next_resendq:
|
||||||
cmp ecx, NUMRESENDENTRIES
|
cmp ecx, NUMRESENDENTRIES
|
||||||
je .last_resendq ; None left
|
je .last_resendq ; None left
|
||||||
;cmp [esi], al ; XTODO: al -> eax
|
|
||||||
cmp [esi + 4], eax
|
cmp [esi + 4], eax
|
||||||
je @f ; found one
|
je @f ; found one
|
||||||
inc ecx
|
inc ecx
|
||||||
add esi, 8
|
add esi, 8
|
||||||
jmp .next_resendq
|
jmp .next_resendq
|
||||||
|
|
||||||
;@@: mov byte[esi], 0xff ; XTODO: 0xff -> 0
|
|
||||||
@@: mov dword[esi + 4], 0
|
@@: mov dword[esi + 4], 0
|
||||||
inc ecx
|
inc ecx
|
||||||
add esi, 8
|
add esi, 8
|
||||||
@ -906,13 +875,6 @@ proc stateTCB_ESTABLISHED stdcall, sockAddr:DWORD
|
|||||||
.last_resendq:
|
.last_resendq:
|
||||||
popad
|
popad
|
||||||
|
|
||||||
;xxx ; was it a reset?
|
|
||||||
;xxx test [edx + 20 + TCP_PACKET.Flags], TH_RST
|
|
||||||
;xxx jz @f
|
|
||||||
|
|
||||||
;xxx mov [ebx + SOCKET.TCBState], TCB_CLOSED
|
|
||||||
;xxx jmp .exit
|
|
||||||
|
|
||||||
@@: ; Send an ACK to that fin, and enter closewait state
|
@@: ; Send an ACK to that fin, and enter closewait state
|
||||||
|
|
||||||
mov [ebx + SOCKET.TCBState], TCB_CLOSE_WAIT
|
mov [ebx + SOCKET.TCBState], TCB_CLOSE_WAIT
|
||||||
@ -1158,11 +1120,6 @@ proc stateTCB_LAST_ACK stdcall, sockAddr:DWORD
|
|||||||
|
|
||||||
; delete the socket
|
; delete the socket
|
||||||
stdcall net_socket_free, ebx
|
stdcall net_socket_free, ebx
|
||||||
; mov edi, ebx
|
|
||||||
; xor eax, eax
|
|
||||||
; mov ecx, SOCKETHEADERSIZE
|
|
||||||
; cld
|
|
||||||
; rep stosb
|
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
ret
|
ret
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;; UDP Processes for Menuet OS TCP/IP stack ;;
|
;; UDP Processes for Menuet OS TCP/IP stack ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Version 0.3 29 August 2002 ;;
|
|
||||||
;; ;;
|
|
||||||
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; See file COPYING for details ;;
|
;; See file COPYING for details ;;
|
||||||
|
Loading…
Reference in New Issue
Block a user