📄 stack.inc
字号:
test eax,eax
jnz not0
; Read the configuartion word
mov eax, [stack_config]
ret
not0:
cmp eax, 1
jnz not1
; read the IP address
mov eax, [stack_ip]
ret
not1:
cmp eax, 2
jnz not2
; write the configuration word
mov [stack_config], ebx
; <Slip shouldn't be active anyway - thats an operational issue.>
; If ethernet now enabled, probe for the card, reset it and empty
; the packet buffer
; If all successfull, enable the card.
; If ethernet now disabled, set it as disabled. Should really
; empty the tcpip data area too.
; ethernet interface is '3' in ls 7 bits
and bl, 0x7f
cmp bl, 3
je ash_eth_enable
; Ethernet isn't enabled, so make sure that the card is disabled
mov [ethernet_active], byte 0
ret
ash_eth_enable:
; Probe for the card. This will reset it and enable the interface
; if found
call eth_probe
test eax,eax
je ash_eth_done ; Abort if no hardware found
mov [ethernet_active], byte 1
ash_eth_done:
ret
not2:
cmp eax, 3
jnz not3
; write the IP Address
mov [stack_ip], ebx
ret
not3:
cmp eax, 4
jnz not4
; Enabled the slip driver on the comm port
if SLIP_PRESENT = TRUE
call enable_slip
end if
ret
not4:
cmp eax, 5
jnz stack_driver_end
; Disable the slip driver on the comm port
if SLIP_PRESENT = TRUE
call disable_slip
end if
stack_driver_end:
ret
;***************************************************************************
; Function
; app_socket_handler
;
; Description
; This is an application service, called by int 0x40
; It provides application access to stack socket services
; such as opening sockets
;
;***************************************************************************
app_socket_handler:
test eax,eax
jnz nots0
call socket_open
ret
nots0:
cmp eax, 1
jnz nots1
call socket_close
ret
nots1:
cmp eax, 2
jnz nots2
call socket_poll
ret
nots2:
cmp eax, 3
jnz nots3
call socket_read
ret
nots3:
cmp eax, 4
jnz nots4
call socket_write
ret
nots4:
cmp eax, 5
jnz nots5
call socket_open_tcp
ret
nots5:
cmp eax, 6
jnz nots6
call socket_status
ret
nots6:
cmp eax, 7
jnz nots7
call socket_write_tcp
ret
nots7:
cmp eax, 8
jnz nots8
call socket_close_tcp
ret
nots8:
cmp eax, 9
jnz nots9
call is_localport_unused
ret
nots9:
cmp eax, 254
jnz notdump
ret
notdump:
cmp eax, 255
jnz notsdebug
; This sub function allows access to debugging information on the stack
; ebx holds the request:
; 100 : return length of empty queue
; 101 : return length of IPOUT QUEUE
; 102 : return length of IPIN QUEUE
; 103 : return length of NET1OUT QUEUE
; 200 : return # of ARP entries
; 201 : return size of ARP table ( max # entries )
; 202 : select ARP table entry #
; 203 : return IP of selected table entry
; 204 : return High 4 bytes of MAC address of selected table entry
; 205 : return low 2 bytes of MAC address of selected table entry
; 206 : return status word of selected table entry
; 207 : return Time to live of selected table entry
; 2 : return number of IP packets received
; 3 : return number of packets transmitted
; 4 : return number of received packets dumped
; 5 : return number of arp packets received
; 6 : return status of packet driver
; ( 0 == not active, FFFFFFFF = successful )
call stack_internal_status
ret
notsdebug:
; Invalid Option
ret
ARPTmp:
times 14 db 0
;***************************************************************************
; Function
; stack_internal_status
;
; Description
; Returns information about the internal status of the stack
; This is only useful for debugging
; It works with the ethernet driver
; sub function in ebx
; return requested data in eax
;
;***************************************************************************
stack_internal_status:
cmp ebx, 100
jnz notsis100
; 100 : return length of EMPTY QUEUE
mov ebx, EMPTY_QUEUE
call queueSize
ret
notsis100:
cmp ebx, 101
jnz notsis101
; 101 : return length of IPOUT QUEUE
mov ebx, IPOUT_QUEUE
call queueSize
ret
notsis101:
cmp ebx, 102
jnz notsis102
; 102 : return length of IPIN QUEUE
mov ebx, IPIN_QUEUE
call queueSize
ret
notsis102:
cmp ebx, 103
jnz notsis103
; 103 : return length of NET1OUT QUEUE
mov ebx, NET1OUT_QUEUE
call queueSize
ret
notsis103:
cmp ebx, 200
jnz notsis200
; 200 : return num entries in arp table
movzx eax, byte [NumARP]
ret
notsis200:
cmp ebx, 201
jnz notsis201
; 201 : return arp table size
mov eax, 20 ; ARP_TABLE_SIZE
ret
notsis201:
cmp ebx, 202
jnz notsis202
; 202 - read the requested table entry
; into a temporary buffer
; ecx holds the entry number
mov eax, ecx
mov ecx, 14 ; ARP_ENTRY_SIZE
mul ecx
mov ecx, [eax + ARPTable]
mov [ARPTmp], ecx
mov ecx, [eax + ARPTable+4]
mov [ARPTmp+4], ecx
mov ecx, [eax + ARPTable+8]
mov [ARPTmp+8], ecx
mov cx, [eax + ARPTable+12]
mov [ARPTmp+12], cx
ret
notsis202:
cmp ebx, 203
jnz notsis203
; 203 - return IP address
mov eax, [ARPTmp]
ret
notsis203:
cmp ebx, 204
jnz notsis204
; 204 - return MAC high dword
mov eax, [ARPTmp+4]
ret
notsis204:
cmp ebx, 205
jnz notsis205
; 205 - return MAC ls word
movzx eax, word [ARPTmp+8]
ret
notsis205:
cmp ebx, 206
jnz notsis206
; 206 - return status word
movzx eax, word [ARPTmp+10]
ret
notsis206:
cmp ebx, 207
jnz notsis207
; 207 - return ttl word
movzx eax, word [ARPTmp+12]
ret
notsis207:
cmp ebx, 2
jnz notsis2
; 2 : return number of IP packets received
mov eax, [ip_rx_count]
ret
notsis2:
cmp ebx, 3
jnz notsis3
; 3 : return number of packets transmitted
mov eax, [ip_tx_count]
ret
notsis3:
cmp ebx, 4
jnz notsis4
; 4 : return number of received packets dumped
mov eax, [dumped_rx_count]
ret
notsis4:
cmp ebx, 5
jnz notsis5
; 5 : return number of arp packets received
mov eax, [arp_rx_count]
ret
notsis5:
cmp ebx, 6
jnz notsis6
; 6 : return status of packet driver
; ( 0 == not active, FFFFFFFF = successful )
mov eax, [eth_status]
ret
notsis6:
xor eax, eax
ret
;***************************************************************************
; Function
; socket_open
;
; Description
; find a free socket
; local port in ebx
; remote port in ecx
; remote ip in edx
; return socket # in eax, -1 if none available
;
;***************************************************************************
socket_open:
call get_free_socket
cmp eax, 0xFFFFFFFF
jz so_exit
; ax holds the socket number that is free. Get real address
push eax
shl eax, 12
add eax, sockets
mov [eax], dword SOCK_OPEN
mov [eax + 12], byte bh ; Local port ( LS 16 bits )
mov [eax + 13], byte bl ; Local port ( LS 16 bits )
mov ebx, [stack_ip]
mov [eax + 8], ebx ; Local IP
mov [eax + 20], ch ; Remote Port ( LS 16 bits )
mov [eax + 21], cl ; Remote Port ( LS 16 bits )
mov [eax + 16], edx ; Remote IP ( in Internet order )
mov [eax + 24], dword 0 ; recieved data count
mov esi, [0x3010]
mov ebx, [esi+0x4]
mov [eax + 4], ebx ; save the process ID
pop eax ; Get the socket number back, so we can return it
so_exit:
ret
;***************************************************************************
; Function
; socket_open_tcp
;
; Description
; Opens a TCP socket in PASSIVE or ACTIVE mode
; find a free socket
; local port in ebx ( intel format )
; remote port in ecx ( intel format )
; 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
;
;***************************************************************************
socket_open_tcp:
call get_free_socket
cmp eax, 0xFFFFFFFF
jz so_exit
; ax holds the socket number that is free. Get real address
push eax
shl eax, 12
add eax, sockets
mov [sktAddr], eax
mov [eax], dword SOCK_OPEN
mov [eax + 12], byte bh ; Local port ( LS 16 bits )
mov [eax + 13], byte bl ; Local port ( LS 16 bits )
mov ebx, [stack_ip]
mov [eax + 8], ebx ; Local IP
mov [eax + 20], ch ; Remote Port ( LS 16 bits )
mov [eax + 21], cl ; Remote Port ( LS 16 bits )
mov [eax + 16], edx ; Remote IP ( in Internet order )
mov [eax + 24], dword 0 ; recieved data count
; Now fill in TCB state
mov ebx, TCB_LISTEN
cmp esi, SOCKET_PASSIVE
jz sot_001
mov ebx, TCB_SYN_SENT
sot_001:
mov [eax + 28], ebx ; Indicate the state of the TCB
mov esi, [0x3010]
mov ecx, [esi+0x4]
mov [eax + 4], ecx ; save the process ID
cmp ebx, TCB_LISTEN
je sot_done
; Now, if we are in active mode, then we have to send a SYN to the specified remote port
mov eax, EMPTY_QUEUE
call dequeue
cmp ax, NO_BUFFER
je sot_done
push eax
mov bl, 0x02 ; SYN
mov ecx, 0
call buildTCPPacket
mov eax, NET1OUT_QUEUE
mov edx, [stack_ip]
mov ecx, [ sktAddr ]
mov ecx, [ ecx + 16 ]
cmp edx, ecx
jne sot_notlocal
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -