forked from KolibriOS/kolibrios
Network stack: dynamic sockets list, other small fixes
git-svn-id: svn://kolibrios.org@907 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
2d73c440b4
commit
54e9661045
@ -20,6 +20,14 @@ irq0:
|
|||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
|
||||||
|
; cmp dword[CURRENT_TASK], 1
|
||||||
|
; jnz @f
|
||||||
|
; mov eax, [esp + 32]
|
||||||
|
; cmp eax, idle_loop + 1
|
||||||
|
; jz @f
|
||||||
|
; DEBUGF 1, "K : OOOPS! EAX = 0x%x\n", eax
|
||||||
|
; @@:
|
||||||
|
|
||||||
inc dword [timer_ticks]
|
inc dword [timer_ticks]
|
||||||
|
|
||||||
mov eax, [timer_ticks]
|
mov eax, [timer_ticks]
|
||||||
|
@ -524,20 +524,20 @@ endp
|
|||||||
; Also adjust PCI latency timer to a reasonable value, 32.
|
; Also adjust PCI latency timer to a reasonable value, 32.
|
||||||
proc adjust_pci_device
|
proc adjust_pci_device
|
||||||
|
|
||||||
DEBUGF 1,"K : adjust_pci_device\n"
|
; DEBUGF 1,"K : adjust_pci_device\n"
|
||||||
|
|
||||||
stdcall pci_read_config_word,PCI_COMMAND
|
stdcall pci_read_config_word,PCI_COMMAND
|
||||||
mov bx,ax
|
mov bx,ax
|
||||||
or bx,PCI_COMMAND_MASTER or PCI_COMMAND_IO
|
or bx,PCI_COMMAND_MASTER or PCI_COMMAND_IO
|
||||||
cmp ax,bx
|
cmp ax,bx
|
||||||
je @f
|
je @f
|
||||||
DEBUGF 1,"K : adjust_pci_device: The PCI BIOS has not enabled this device!\nK : Updating PCI command %x->%x. pci_bus %x pci_device_fn %x\n",ax,bx,[pci_bus]:2,[pci_dev]:2
|
; DEBUGF 1,"K : adjust_pci_device: The PCI BIOS has not enabled this device!\nK : Updating PCI command %x->%x. pci_bus %x pci_device_fn %x\n",ax,bx,[pci_bus]:2,[pci_dev]:2
|
||||||
stdcall pci_write_config_word,PCI_COMMAND,ebx
|
stdcall pci_write_config_word,PCI_COMMAND,ebx
|
||||||
@@:
|
@@:
|
||||||
stdcall pci_read_config_byte,PCI_LATENCY_TIMER
|
stdcall pci_read_config_byte,PCI_LATENCY_TIMER
|
||||||
cmp al,32
|
cmp al,32
|
||||||
jae @f
|
jae @f
|
||||||
DEBUGF 1,"K : adjust_pci_device: PCI latency timer (CFLT) is unreasonably low at %d.\nK : Setting to 32 clocks.\n",al
|
; DEBUGF 1,"K : adjust_pci_device: PCI latency timer (CFLT) is unreasonably low at %d.\nK : Setting to 32 clocks.\n",al
|
||||||
stdcall pci_write_config_byte,PCI_LATENCY_TIMER,32
|
stdcall pci_write_config_byte,PCI_LATENCY_TIMER,32
|
||||||
@@:
|
@@:
|
||||||
ret
|
ret
|
||||||
@ -559,7 +559,7 @@ proc pci_bar_start,index:dword
|
|||||||
stdcall pci_read_config_dword,eax
|
stdcall pci_read_config_dword,eax
|
||||||
or eax,eax
|
or eax,eax
|
||||||
jz .not64
|
jz .not64
|
||||||
DEBUGF 1,"K : pci_bar_start: Unhandled 64bit BAR\n"
|
; DEBUGF 1,"K : pci_bar_start: Unhandled 64bit BAR\n"
|
||||||
add esp,4
|
add esp,4
|
||||||
or eax,-1
|
or eax,-1
|
||||||
ret
|
ret
|
||||||
@ -572,7 +572,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_init_board
|
proc rtl8169_init_board
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_init_board\n"
|
; DEBUGF 1,"K : rtl8169_init_board\n"
|
||||||
|
|
||||||
call adjust_pci_device
|
call adjust_pci_device
|
||||||
|
|
||||||
@ -592,7 +592,7 @@ proc rtl8169_init_board
|
|||||||
; identify config method
|
; identify config method
|
||||||
RTL_R32 RTL8169_REG_TxConfig
|
RTL_R32 RTL8169_REG_TxConfig
|
||||||
and eax,0x7c800000
|
and eax,0x7c800000
|
||||||
DEBUGF 1,"K : rtl8169_init_board: TxConfig & 0x7c800000 = 0x%x\n",eax
|
; DEBUGF 1,"K : rtl8169_init_board: TxConfig & 0x7c800000 = 0x%x\n",eax
|
||||||
mov esi,mac_info-8
|
mov esi,mac_info-8
|
||||||
@@: add esi,8
|
@@: add esi,8
|
||||||
mov ecx,eax
|
mov ecx,eax
|
||||||
@ -625,9 +625,9 @@ proc rtl8169_init_board
|
|||||||
jmp .match
|
jmp .match
|
||||||
@@:
|
@@:
|
||||||
; if unknown chip, assume array element #0, original RTL-8169 in this case
|
; if unknown chip, assume array element #0, original RTL-8169 in this case
|
||||||
DEBUGF 1,"K : rtl8169_init_board: PCI device: unknown chip version, assuming RTL-8169\n"
|
; DEBUGF 1,"K : rtl8169_init_board: PCI device: unknown chip version, assuming RTL-8169\n"
|
||||||
RTL_R32 RTL8169_REG_TxConfig
|
RTL_R32 RTL8169_REG_TxConfig
|
||||||
DEBUGF 1,"K : rtl8169_init_board: PCI device: TxConfig = 0x%x\n",eax
|
; DEBUGF 1,"K : rtl8169_init_board: PCI device: TxConfig = 0x%x\n",eax
|
||||||
|
|
||||||
mov [rtl8169_tpc.chipset],0
|
mov [rtl8169_tpc.chipset],0
|
||||||
|
|
||||||
@ -642,7 +642,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_hw_PHY_config
|
proc rtl8169_hw_PHY_config
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[rtl8169_tpc.mcfg],[rtl8169_tpc.pcfg]
|
; DEBUGF 1,"K : rtl8169_hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[rtl8169_tpc.mcfg],[rtl8169_tpc.pcfg]
|
||||||
|
|
||||||
; DBG_PRINT("priv->mcfg=%d, priv->pcfg=%d\n", tpc->mcfg, tpc->pcfg);
|
; DBG_PRINT("priv->mcfg=%d, priv->pcfg=%d\n", tpc->mcfg, tpc->pcfg);
|
||||||
|
|
||||||
@ -705,7 +705,7 @@ proc rtl8169_hw_PHY_config
|
|||||||
jmp .exit
|
jmp .exit
|
||||||
.not_2_or_3:
|
.not_2_or_3:
|
||||||
; DBG_PRINT("tpc->mcfg=%d. Discard hw PHY config.\n", tpc->mcfg);
|
; DBG_PRINT("tpc->mcfg=%d. Discard hw PHY config.\n", tpc->mcfg);
|
||||||
DEBUGF 1,"K : tpc.mcfg=%d, discard hw PHY config\n",[rtl8169_tpc.mcfg]
|
; DEBUGF 1,"K : tpc.mcfg=%d, discard hw PHY config\n",[rtl8169_tpc.mcfg]
|
||||||
.exit:
|
.exit:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
@ -767,7 +767,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_set_rx_mode
|
proc rtl8169_set_rx_mode
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_set_rx_mode\n"
|
; DEBUGF 1,"K : rtl8169_set_rx_mode\n"
|
||||||
|
|
||||||
; IFF_ALLMULTI
|
; IFF_ALLMULTI
|
||||||
; Too many to filter perfectly -- accept all multicasts
|
; Too many to filter perfectly -- accept all multicasts
|
||||||
@ -785,7 +785,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_init_ring
|
proc rtl8169_init_ring
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_init_ring\n"
|
; DEBUGF 1,"K : rtl8169_init_ring\n"
|
||||||
|
|
||||||
xor eax,eax
|
xor eax,eax
|
||||||
mov [rtl8169_tpc.cur_rx],eax
|
mov [rtl8169_tpc.cur_rx],eax
|
||||||
@ -834,7 +834,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_hw_start
|
proc rtl8169_hw_start
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_hw_start\n"
|
; DEBUGF 1,"K : rtl8169_hw_start\n"
|
||||||
|
|
||||||
; Soft reset the chip
|
; Soft reset the chip
|
||||||
RTL_W8 RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
|
RTL_W8 RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
|
||||||
@ -920,7 +920,7 @@ endp
|
|||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
proc rtl8169_probe
|
proc rtl8169_probe
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_probe: 0x%x : 0x%x 0x%x\n",[io_addr]:8,[pci_bus]:2,[pci_dev]:2
|
; DEBUGF 1,"K : rtl8169_probe: 0x%x : 0x%x 0x%x\n",[io_addr]:8,[pci_bus]:2,[pci_dev]:2
|
||||||
|
|
||||||
call rtl8169_init_board
|
call rtl8169_init_board
|
||||||
|
|
||||||
@ -935,7 +935,7 @@ proc rtl8169_probe
|
|||||||
inc ebx
|
inc ebx
|
||||||
loop @b
|
loop @b
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_probe: MAC = %x-%x-%x-%x-%x-%x\n",[node_addr+0]:2,[node_addr+1]:2,[node_addr+2]:2,[node_addr+3]:2,[node_addr+4]:2,[node_addr+5]:2
|
; DEBUGF 1,"K : rtl8169_probe: MAC = %x-%x-%x-%x-%x-%x\n",[node_addr+0]:2,[node_addr+1]:2,[node_addr+2]:2,[node_addr+3]:2,[node_addr+4]:2,[node_addr+5]:2
|
||||||
|
|
||||||
; Config PHY
|
; Config PHY
|
||||||
stdcall rtl8169_hw_PHY_config
|
stdcall rtl8169_hw_PHY_config
|
||||||
@ -995,7 +995,7 @@ endp
|
|||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
proc rtl8169_reset
|
proc rtl8169_reset
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_reset: 0x%x : 0x%x 0x%x\n",[io_addr]:8,[pci_bus]:2,[pci_dev]:2
|
; DEBUGF 1,"K : rtl8169_reset: 0x%x : 0x%x 0x%x\n",[io_addr]:8,[pci_bus]:2,[pci_dev]:2
|
||||||
|
|
||||||
mov [rtl8169_tpc.TxDescArrays],rtl8169_tx_ring
|
mov [rtl8169_tpc.TxDescArrays],rtl8169_tx_ring
|
||||||
; Tx Desscriptor needs 256 bytes alignment
|
; Tx Desscriptor needs 256 bytes alignment
|
||||||
@ -1040,7 +1040,7 @@ endp
|
|||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
proc rtl8169_transmit
|
proc rtl8169_transmit
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_transmit\n" ;: 0x%x : 0x%x 0x%x 0x%x 0x%x\n",[io_addr]:8,edi,bx,ecx,esi
|
; DEBUGF 1,"K : rtl8169_transmit\n" ;: 0x%x : 0x%x 0x%x 0x%x 0x%x\n",[io_addr]:8,edi,bx,ecx,esi
|
||||||
|
|
||||||
push ecx edx esi
|
push ecx edx esi
|
||||||
mov eax,MAX_ETH_FRAME_SIZE
|
mov eax,MAX_ETH_FRAME_SIZE
|
||||||
@ -1118,7 +1118,7 @@ proc rtl8169_transmit
|
|||||||
jnz @f
|
jnz @f
|
||||||
stdcall udelay,10
|
stdcall udelay,10
|
||||||
loop @b
|
loop @b
|
||||||
DEBUGF 1,"K : rtl8169_transmit: TX Time Out\n"
|
; DEBUGF 1,"K : rtl8169_transmit: TX Time Out\n"
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
ret
|
ret
|
||||||
@ -1176,7 +1176,7 @@ proc rtl8169_poll
|
|||||||
add eax,-4
|
add eax,-4
|
||||||
mov [eth_rx_data_len],ax
|
mov [eth_rx_data_len],ax
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_poll: data length = %u\n",ax
|
; DEBUGF 1,"K : rtl8169_poll: data length = %u\n",ax
|
||||||
|
|
||||||
push eax
|
push eax
|
||||||
mov ecx,eax
|
mov ecx,eax
|
||||||
@ -1201,7 +1201,7 @@ proc rtl8169_poll
|
|||||||
sub [ebx + rtl8169_RxDesc.buf_addr],OS_BASE ; shurf 28.09.2008
|
sub [ebx + rtl8169_RxDesc.buf_addr],OS_BASE ; shurf 28.09.2008
|
||||||
jmp @f
|
jmp @f
|
||||||
.else:
|
.else:
|
||||||
DEBUGF 1,"K : rtl8169_poll: Rx Error\n"
|
; DEBUGF 1,"K : rtl8169_poll: Rx Error\n"
|
||||||
; FIXME: shouldn't I reset the status on an error
|
; FIXME: shouldn't I reset the status on an error
|
||||||
@@:
|
@@:
|
||||||
inc [rtl8169_tpc.cur_rx]
|
inc [rtl8169_tpc.cur_rx]
|
||||||
|
@ -353,6 +353,9 @@ endp
|
|||||||
; All registers may be destroyed
|
; All registers may be destroyed
|
||||||
;
|
;
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
|
uglobal
|
||||||
|
ether_IP_handler_cnt dd ?
|
||||||
|
endg
|
||||||
ether_IP_handler:
|
ether_IP_handler:
|
||||||
mov eax, EMPTY_QUEUE
|
mov eax, EMPTY_QUEUE
|
||||||
call dequeue
|
call dequeue
|
||||||
@ -376,6 +379,9 @@ ether_IP_handler:
|
|||||||
cld
|
cld
|
||||||
rep movsd
|
rep movsd
|
||||||
|
|
||||||
|
; inc [ether_IP_handler_cnt]
|
||||||
|
; DEBUGF 1, "K : ether_IP_handler (%u)\n", [ether_IP_handler_cnt]
|
||||||
|
|
||||||
; And finally, place the buffer in the IPRX queue
|
; And finally, place the buffer in the IPRX queue
|
||||||
pop ebx
|
pop ebx
|
||||||
mov eax, IPIN_QUEUE
|
mov eax, IPIN_QUEUE
|
||||||
@ -462,16 +468,18 @@ eth_rx:
|
|||||||
cmp ax, ETHER_ARP
|
cmp ax, ETHER_ARP
|
||||||
je .is_arp ; It is ARP
|
je .is_arp ; It is ARP
|
||||||
|
|
||||||
|
DEBUGF 1,"K : eth_rx - dumped (%u)\n", ax
|
||||||
|
inc [dumped_rx_count]
|
||||||
jmp .exit ; If not IP or ARP, ignore
|
jmp .exit ; If not IP or ARP, ignore
|
||||||
|
|
||||||
.is_ip:
|
.is_ip:
|
||||||
DEBUGF 1,"K : eth_rx - IP packet\n"
|
; DEBUGF 1,"K : eth_rx - IP packet\n"
|
||||||
inc dword [ip_rx_count]
|
inc dword [ip_rx_count]
|
||||||
call ether_IP_handler
|
call ether_IP_handler
|
||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
.is_arp:
|
.is_arp:
|
||||||
DEBUGF 1,"K : eth_rx - ARP packet\n"
|
; DEBUGF 1,"K : eth_rx - ARP packet\n"
|
||||||
; At this point, the packet is still in the Ether_buffer
|
; At this point, the packet is still in the Ether_buffer
|
||||||
call arp_handler
|
call arp_handler
|
||||||
|
|
||||||
|
@ -87,6 +87,10 @@ macro GET_IHL reg, header_addr
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
include "tcp.inc"
|
||||||
|
include "udp.inc"
|
||||||
|
include "icmp.inc"
|
||||||
|
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
; Function
|
; Function
|
||||||
; ip_rx
|
; ip_rx
|
||||||
@ -114,11 +118,13 @@ local buffer_number dd ?
|
|||||||
|
|
||||||
mov ebx, eax ; ebx=pointer to IP_PACKET
|
mov ebx, eax ; ebx=pointer to IP_PACKET
|
||||||
|
|
||||||
|
; DEBUGF 1, "K : ip_rx - proto: %u\n", [ebx + IP_PACKET.Protocol]:1
|
||||||
|
|
||||||
; Validate the IP checksum
|
; Validate the IP checksum
|
||||||
mov dx, word[ebx + IP_PACKET.HeaderChecksum]
|
mov dx, word[ebx + IP_PACKET.HeaderChecksum]
|
||||||
xchg dh,dl ; Get the checksum in intel format
|
xchg dh,dl ; Get the checksum in intel format
|
||||||
|
|
||||||
mov [ebx + IP_PACKET.HeaderChecksum], word 0 ; clear checksum field - need to when
|
mov [ebx + IP_PACKET.HeaderChecksum], 0 ; clear checksum field - need to when
|
||||||
; recalculating checksum
|
; recalculating checksum
|
||||||
; this needs two data pointers and two size #.
|
; this needs two data pointers and two size #.
|
||||||
; 2nd pointer can be of length 0
|
; 2nd pointer can be of length 0
|
||||||
@ -127,8 +133,12 @@ local buffer_number dd ?
|
|||||||
stdcall checksum_jb, ebx, ecx ;buf_ptr, buf_size
|
stdcall checksum_jb, ebx, ecx ;buf_ptr, buf_size
|
||||||
cmp dx, ax
|
cmp dx, ax
|
||||||
|
|
||||||
|
; DEBUGF 1, "K : ip_rx - checksums: %x - %x\n", dx, ax
|
||||||
|
|
||||||
|
jnz .dump.1 ;if CHECKSUM isn't valid then dump packet
|
||||||
mov edx, ebx ; EDX (IP-BUFFER POINTER) WILL BE USED FOR *_rx HANDLERS BELOW!!!
|
mov edx, ebx ; EDX (IP-BUFFER POINTER) WILL BE USED FOR *_rx HANDLERS BELOW!!!
|
||||||
jnz .dump ;if CHECKSUM isn't valid then dump packet
|
|
||||||
|
; DEBUGF 1, "K : ip_rx - dest: %x - %x\n", [ebx + IP_PACKET.DestinationAddress], [stack_ip]
|
||||||
|
|
||||||
; Validate the IP address, if it isn't broadcast
|
; Validate the IP address, if it isn't broadcast
|
||||||
mov eax, [stack_ip]
|
mov eax, [stack_ip]
|
||||||
@ -137,22 +147,37 @@ local buffer_number dd ?
|
|||||||
|
|
||||||
; If the IP address is 255.255.255.255, accept it
|
; If the IP address is 255.255.255.255, accept it
|
||||||
; - it is a broadcast packet, which we need for dhcp
|
; - it is a broadcast packet, which we need for dhcp
|
||||||
cmp dword[ebx + IP_PACKET.DestinationAddress], 0xffffffff
|
|
||||||
jne .dump
|
mov eax, [ebx + IP_PACKET.DestinationAddress]
|
||||||
|
cmp eax, 0xffffffff
|
||||||
|
;je @f
|
||||||
|
;mov ecx, [stack_ip]
|
||||||
|
;and eax, [subnet_mask]
|
||||||
|
;and ecx, [subnet_mask]
|
||||||
|
;cmp eax, ecx
|
||||||
|
;jne .dump.2
|
||||||
|
;mov eax, [ebx + IP_PACKET.DestinationAddress]
|
||||||
|
;or eax, [subnet_mask]
|
||||||
|
;cmp eax, 0xffffffff
|
||||||
|
jne .dump.2
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
mov al, [ebx + IP_PACKET.VersionAndIHL]
|
mov al, [ebx + IP_PACKET.VersionAndIHL]
|
||||||
and al, 0x0f ;get IHL(header length)
|
and al, 0x0f ;get IHL(header length)
|
||||||
cmp al, 0x05 ;if IHL!= 5*4(20 bytes)
|
cmp al, 0x05 ;if IHL!= 5*4(20 bytes)
|
||||||
jnz .dump ;then dump it
|
; DEBUGF 1, "K : ip_rx - ihl: %x - 05\n", al
|
||||||
|
jnz .dump.3 ;then dump it
|
||||||
|
|
||||||
cmp byte[ebx + IP_PACKET.TimeToLive], byte 0
|
; DEBUGF 1, "K : ip_rx - ttl: %x - 00\n", [ebx + IP_PACKET.TimeToLive]:2
|
||||||
je .dump ;if TTL==0 then dump it
|
|
||||||
|
|
||||||
mov ax, word[ebx + IP_PACKET.FlagsAndFragmentOffset]
|
cmp [ebx + IP_PACKET.TimeToLive], 0
|
||||||
|
je .dump.4 ;if TTL==0 then dump it
|
||||||
|
|
||||||
|
mov ax, [ebx + IP_PACKET.FlagsAndFragmentOffset]
|
||||||
and ax, 0xFFBF ;get flags
|
and ax, 0xFFBF ;get flags
|
||||||
|
; DEBUGF 1, "K : ip_rx - flags: %x - 0000\n", ax
|
||||||
cmp ax, 0 ;if some flags was set then we dump this packet
|
cmp ax, 0 ;if some flags was set then we dump this packet
|
||||||
jnz .dump ;the flags should be used for fragmented packets
|
jnz .dump.5 ;the flags should be used for fragmented packets
|
||||||
|
|
||||||
; Check the protocol, and call the appropriate handler
|
; Check the protocol, and call the appropriate handler
|
||||||
; Each handler will re-use or free the queue buffer as appropriate
|
; Each handler will re-use or free the queue buffer as appropriate
|
||||||
@ -161,7 +186,7 @@ local buffer_number dd ?
|
|||||||
|
|
||||||
cmp al , PROTOCOL_TCP
|
cmp al , PROTOCOL_TCP
|
||||||
jne .not_tcp
|
jne .not_tcp
|
||||||
DEBUGF 1,"K : ip_rx - TCP packet\n"
|
; DEBUGF 1,"K : ip_rx - TCP packet\n"
|
||||||
mov eax, dword[buffer_number]
|
mov eax, dword[buffer_number]
|
||||||
call tcp_rx
|
call tcp_rx
|
||||||
jmp .exit
|
jmp .exit
|
||||||
@ -169,29 +194,48 @@ local buffer_number dd ?
|
|||||||
.not_tcp:
|
.not_tcp:
|
||||||
cmp al, PROTOCOL_UDP
|
cmp al, PROTOCOL_UDP
|
||||||
jne .not_udp
|
jne .not_udp
|
||||||
DEBUGF 1,"K : ip_rx - UDP packet\n"
|
; DEBUGF 1,"K : ip_rx - UDP packet\n"
|
||||||
mov eax, dword[buffer_number]
|
mov eax, dword[buffer_number]
|
||||||
call udp_rx
|
call udp_rx
|
||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
.not_udp:
|
.not_udp:
|
||||||
cmp al , PROTOCOL_ICMP
|
cmp al, PROTOCOL_ICMP
|
||||||
jne .dump ;protocol ain't supported
|
jne .dump.6 ;protocol ain't supported
|
||||||
|
|
||||||
DEBUGF 1,"K : ip_rx - ICMP packet\n"
|
; DEBUGF 1,"K : ip_rx - ICMP packet\n"
|
||||||
;GET_IHL ecx, ebx + IP_PACKET.VersionAndIHL ;get packet length in ecx
|
;GET_IHL ecx, ebx + IP_PACKET.VersionAndIHL ;get packet length in ecx
|
||||||
mov eax, dword[buffer_number]
|
mov eax, dword[buffer_number]
|
||||||
stdcall icmp_rx,eax,ebx,ecx ;buffer_number,IPPacketBase,IPHeaderLength
|
stdcall icmp_rx,eax,ebx,ecx ;buffer_number,IPPacketBase,IPHeaderLength
|
||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
|
|
||||||
.dump:
|
.dump.1:
|
||||||
; No protocol handler available, so
|
DEBUGF 1, "K : ip_rx - dumped (checksum: 0x%x-0x%x)\n", dx, ax
|
||||||
; silently dump the packet, freeing up the queue buffer
|
jmp .dump.x
|
||||||
|
|
||||||
inc dword [dumped_rx_count]
|
.dump.2:
|
||||||
|
DEBUGF 1, "K : ip_rx - dumped (ip: %u.%u.%u.%u)\n", [ebx + IP_PACKET.DestinationAddress + 0]:1, [ebx + IP_PACKET.DestinationAddress + 1]:1, [ebx + IP_PACKET.DestinationAddress + 2]:1, [ebx + IP_PACKET.DestinationAddress + 3]:1
|
||||||
|
jmp .dump.x
|
||||||
|
|
||||||
mov eax, dword[buffer_number]
|
.dump.3:
|
||||||
|
DEBUGF 1, "K : ip_rx - dumped (ihl: %u)\n", al
|
||||||
|
jmp .dump.x
|
||||||
|
|
||||||
|
.dump.4:
|
||||||
|
DEBUGF 1, "K : ip_rx - dumped (ihl: %u)\n", [ebx + IP_PACKET.TimeToLive]
|
||||||
|
jmp .dump.x
|
||||||
|
|
||||||
|
.dump.5:
|
||||||
|
DEBUGF 1, "K : ip_rx - dumped (flags: 0x%x)\n", ax
|
||||||
|
jmp .dump.x
|
||||||
|
|
||||||
|
.dump.6:
|
||||||
|
DEBUGF 1, "K : ip_rx - dumped (proto: %u)\n", [ebx + IP_PACKET.Protocol]:1
|
||||||
|
|
||||||
|
.dump.x:
|
||||||
|
inc dword[dumped_rx_count]
|
||||||
|
mov eax, [buffer_number]
|
||||||
call freeBuff
|
call freeBuff
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
|
@ -43,18 +43,19 @@ $Revision$
|
|||||||
; all other registers preserved
|
; all other registers preserved
|
||||||
; This always works, so no error returned
|
; This always works, so no error returned
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
|
uglobal
|
||||||
|
freeBuff_cnt dd ?
|
||||||
|
endg
|
||||||
freeBuff:
|
freeBuff:
|
||||||
|
; inc [freeBuff_cnt]
|
||||||
|
; DEBUGF 1, "K : freeBuff (%u)\n", [freeBuff_cnt]
|
||||||
push ebx
|
push ebx
|
||||||
push ecx
|
push ecx
|
||||||
mov ebx, EMPTY_QUEUE
|
mov ebx, queues + EMPTY_QUEUE * 2
|
||||||
shl ebx, 1
|
|
||||||
add ebx, queues
|
|
||||||
cli ; Ensure that another process does not interfer
|
cli ; Ensure that another process does not interfer
|
||||||
movzx ecx, word [ebx]
|
mov cx, [ebx]
|
||||||
mov [ebx], ax
|
mov [ebx], ax
|
||||||
shl eax, 1
|
mov [queueList + eax * 2], cx
|
||||||
add eax, queueList
|
|
||||||
mov [eax], cx
|
|
||||||
sti
|
sti
|
||||||
pop ecx
|
pop ecx
|
||||||
pop ebx
|
pop ebx
|
||||||
@ -105,7 +106,12 @@ 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
|
||||||
|
queue_cnt dd ?
|
||||||
|
endg
|
||||||
queue:
|
queue:
|
||||||
|
; inc [queue_cnt]
|
||||||
|
; DEBUGF 1, "K : queue (%u)\n", [queue_cnt]
|
||||||
push ebx
|
push ebx
|
||||||
shl ebx, 1
|
shl ebx, 1
|
||||||
add ebx, queueList ; eax now holds address of queue entry
|
add ebx, queueList ; eax now holds address of queue entry
|
||||||
@ -155,6 +161,9 @@ qu_exit:
|
|||||||
; all other registers preserved
|
; all other registers preserved
|
||||||
;
|
;
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
|
uglobal
|
||||||
|
dequeue_cnt dd ?
|
||||||
|
endg
|
||||||
dequeue:
|
dequeue:
|
||||||
push ebx
|
push ebx
|
||||||
shl eax, 1
|
shl eax, 1
|
||||||
@ -164,6 +173,8 @@ dequeue:
|
|||||||
movzx eax, word [eax]
|
movzx eax, word [eax]
|
||||||
cmp ax, NO_BUFFER
|
cmp ax, NO_BUFFER
|
||||||
je dq_exit
|
je dq_exit
|
||||||
|
; inc [dequeue_cnt]
|
||||||
|
; DEBUGF 1, "K : dequeue (%u)\n", [dequeue_cnt]
|
||||||
push eax
|
push eax
|
||||||
shl eax, 1
|
shl eax, 1
|
||||||
add eax, queueList ; eax now holds address of queue entry
|
add eax, queueList ; eax now holds address of queue entry
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -37,7 +37,7 @@ $Revision$
|
|||||||
|
|
||||||
uglobal
|
uglobal
|
||||||
StackCounters:
|
StackCounters:
|
||||||
dumped_rx_count: dd 0
|
dumped_rx_count dd 0
|
||||||
arp_tx_count: dd 0
|
arp_tx_count: dd 0
|
||||||
arp_rx_count: dd 0
|
arp_rx_count: dd 0
|
||||||
ip_rx_count: dd 0
|
ip_rx_count: dd 0
|
||||||
@ -46,9 +46,9 @@ endg
|
|||||||
|
|
||||||
; socket buffers
|
; socket buffers
|
||||||
SOCKETBUFFSIZE equ 4096 ; state + config + buffer.
|
SOCKETBUFFSIZE equ 4096 ; state + config + buffer.
|
||||||
SOCKETHEADERSIZE equ 76 ; thus 4096 - SOCKETHEADERSIZE bytes data
|
SOCKETHEADERSIZE equ 76+8+8 ; thus 4096 - SOCKETHEADERSIZE bytes data
|
||||||
|
|
||||||
NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20
|
;NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20
|
||||||
|
|
||||||
; IPBUFF status values
|
; IPBUFF status values
|
||||||
BUFF_EMPTY equ 0
|
BUFF_EMPTY equ 0
|
||||||
@ -59,6 +59,7 @@ BUFF_TX_FULL equ 3
|
|||||||
NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX
|
NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX
|
||||||
|
|
||||||
NUMQUEUES equ 4
|
NUMQUEUES equ 4
|
||||||
|
|
||||||
EMPTY_QUEUE equ 0
|
EMPTY_QUEUE equ 0
|
||||||
IPIN_QUEUE equ 1
|
IPIN_QUEUE equ 1
|
||||||
IPOUT_QUEUE equ 2
|
IPOUT_QUEUE equ 2
|
||||||
@ -94,7 +95,7 @@ ethernet_active equ stack_data + 9
|
|||||||
; TODO :: empty memory area
|
; TODO :: empty memory area
|
||||||
|
|
||||||
; Address of selected socket
|
; Address of selected socket
|
||||||
sktAddr equ stack_data + 32
|
;sktAddr equ stack_data + 32
|
||||||
; Parameter to checksum routine - data ptr
|
; Parameter to checksum routine - data ptr
|
||||||
checkAdd1 equ stack_data + 36
|
checkAdd1 equ stack_data + 36
|
||||||
; Parameter to checksum routine - 2nd data ptr
|
; Parameter to checksum routine - 2nd data ptr
|
||||||
@ -110,8 +111,8 @@ checkResult equ stack_data + 48
|
|||||||
pseudoHeader equ stack_data + 50
|
pseudoHeader equ stack_data + 50
|
||||||
|
|
||||||
; receive and transmit IP buffer allocation
|
; receive and transmit IP buffer allocation
|
||||||
sockets equ stack_data + 62
|
;sockets equ stack_data + 62
|
||||||
Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS)
|
Next_free2 equ stack_data + 62;Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS)
|
||||||
; 1560 byte buffer for rx / tx ethernet packets
|
; 1560 byte buffer for rx / tx ethernet packets
|
||||||
Ether_buffer equ Next_free2
|
Ether_buffer equ Next_free2
|
||||||
Next_free3 equ Ether_buffer + 1518
|
Next_free3 equ Ether_buffer + 1518
|
||||||
@ -128,9 +129,15 @@ last_1hsTick equ queueList + ( 2 * NUMQUEUEENTRIES )
|
|||||||
|
|
||||||
|
|
||||||
;resendQ equ 0x770000
|
;resendQ equ 0x770000
|
||||||
resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP
|
;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP ; XTODO: validate size
|
||||||
|
resendBuffer equ resendQ + ( 8 * NUMRESENDENTRIES ) ; for TCP
|
||||||
|
|
||||||
|
|
||||||
|
uglobal
|
||||||
|
net_sockets_mutex dd 0
|
||||||
|
net_sockets rd 2
|
||||||
|
endg
|
||||||
|
|
||||||
; simple macro for memory set operation
|
; simple macro for memory set operation
|
||||||
macro _memset_dw adr,value,amount
|
macro _memset_dw adr,value,amount
|
||||||
{
|
{
|
||||||
@ -151,9 +158,6 @@ macro _memset_dw adr,value,amount
|
|||||||
include "queue.inc"
|
include "queue.inc"
|
||||||
include "eth_drv/ethernet.inc"
|
include "eth_drv/ethernet.inc"
|
||||||
include "ip.inc"
|
include "ip.inc"
|
||||||
include "icmp.inc"
|
|
||||||
include "tcp.inc"
|
|
||||||
include "udp.inc"
|
|
||||||
include "socket.inc"
|
include "socket.inc"
|
||||||
|
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
@ -171,7 +175,8 @@ include "socket.inc"
|
|||||||
stack_init:
|
stack_init:
|
||||||
; Init two address spaces with default values
|
; Init two address spaces with default values
|
||||||
_memset_dw stack_data_start, 0, 0x20000/4
|
_memset_dw stack_data_start, 0, 0x20000/4
|
||||||
_memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES
|
;_memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES ; XTODO: validate size
|
||||||
|
_memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES * 2
|
||||||
|
|
||||||
; Queries initialization
|
; Queries initialization
|
||||||
call queueInit
|
call queueInit
|
||||||
@ -931,13 +936,11 @@ stack_get_packet:
|
|||||||
pop edx
|
pop edx
|
||||||
|
|
||||||
push eax ; save address of IP data
|
push eax ; save address of IP data
|
||||||
|
|
||||||
; Get the address of the callers data
|
; Get the address of the callers data
|
||||||
mov edi,[TASK_BASE]
|
mov edi,[TASK_BASE]
|
||||||
add edi,TASKDATA.mem_start
|
add edi,TASKDATA.mem_start
|
||||||
add edx,[edi]
|
add edx,[edi]
|
||||||
mov edi, edx
|
mov edi, edx
|
||||||
|
|
||||||
pop eax
|
pop eax
|
||||||
|
|
||||||
mov ecx, 1500 ; should get the actual number of bytes to write
|
mov ecx, 1500 ; should get the actual number of bytes to write
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -71,7 +71,8 @@ end virtual
|
|||||||
; Free up (or re-use) IP buffer when finished
|
; Free up (or re-use) IP buffer when finished
|
||||||
;
|
;
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
udp_rx:
|
|
||||||
|
proc udp_rx stdcall
|
||||||
push eax
|
push eax
|
||||||
|
|
||||||
; First validate the header & checksum. Discard buffer if error
|
; First validate the header & checksum. Discard buffer if error
|
||||||
@ -80,94 +81,83 @@ udp_rx:
|
|||||||
; IP Packet UDP Destination Port = local Port
|
; IP Packet UDP Destination Port = local Port
|
||||||
; IP Packet SA = Remote IP
|
; IP Packet SA = Remote IP
|
||||||
|
|
||||||
movzx ebx, word [edx + 22] ; get the local port from
|
mov ax, [edx + 20 + UDP_PACKET.DestinationPort] ; get the local port from
|
||||||
; the IP packet's UDP header
|
; the IP packet's UDP header
|
||||||
mov eax, SOCKETBUFFSIZE * NUM_SOCKETS
|
|
||||||
mov ecx, NUM_SOCKETS
|
|
||||||
|
|
||||||
fs1:
|
mov ebx, net_sockets_mutex
|
||||||
sub eax, SOCKETBUFFSIZE
|
call wait_mutex
|
||||||
cmp [eax + sockets + 12], bx ; bx will hold the 'wrong' value,
|
mov ebx, net_sockets
|
||||||
|
|
||||||
|
.next_socket:
|
||||||
|
mov ebx, [ebx + SOCKET.NextPtr]
|
||||||
|
or ebx, ebx
|
||||||
|
jz .exit ; No match, so exit
|
||||||
|
cmp [ebx + SOCKET.LocalPort], ax ; ax will hold the 'wrong' value,
|
||||||
; but the comparision is correct
|
; but the comparision is correct
|
||||||
loopnz fs1 ; Return back if no match
|
jne .next_socket ; Return back if no match
|
||||||
jz fs_done
|
|
||||||
|
|
||||||
; No match, so exit
|
|
||||||
jmp udprx_001
|
|
||||||
|
|
||||||
fs_done:
|
|
||||||
; For dhcp, we must allow any remote server to respond.
|
; For dhcp, we must allow any remote server to respond.
|
||||||
; I will accept the first incoming response to be the one
|
; I will accept the first incoming response to be the one
|
||||||
; I bind to, if the socket is opened with a destination IP address of
|
; I bind to, if the socket is opened with a destination IP address of
|
||||||
; 255.255.255.255
|
; 255.255.255.255
|
||||||
mov ebx, [eax + sockets + 16]
|
cmp [ebx + SOCKET.RemoteIP], 0xffffffff
|
||||||
cmp ebx, 0xffffffff
|
je @f
|
||||||
je udprx_002
|
|
||||||
|
|
||||||
mov ebx, [edx + 12] ; get the Source address from the IP packet
|
mov eax, [edx + IP_PACKET.SourceAddress] ; get the Source address from the IP packet
|
||||||
cmp [eax + sockets + 16], ebx
|
cmp [ebx + SOCKET.RemoteIP], ebx
|
||||||
jne udprx_001 ; Quit if the source IP is not valid
|
jne .exit ; Quit if the source IP is not valid
|
||||||
|
|
||||||
udprx_002:
|
@@: ; OK - we have a valid UDP packet for this socket.
|
||||||
; OK - we have a valid UDP packet for this socket.
|
|
||||||
; First, update the sockets remote port number with the incoming msg
|
; First, update the sockets remote port number with the incoming msg
|
||||||
; - it will have changed
|
; - it will have changed
|
||||||
; from the original ( 69 normally ) to allow further connects
|
; from the original ( 69 normally ) to allow further connects
|
||||||
movzx ebx, word [edx + 20] ; get the UDP source port
|
mov ax, [edx + 20 + UDP_PACKET.SourcePort] ; get the UDP source port
|
||||||
; ( was 69, now new )
|
; ( was 69, now new )
|
||||||
mov [eax + sockets + 20], bx
|
mov [ebx + SOCKET.RemotePort], ax
|
||||||
|
|
||||||
; Now, copy data to socket. We have socket address as [eax + sockets].
|
; Now, copy data to socket. We have socket address as [eax + sockets].
|
||||||
; We have IP packet in edx
|
; We have IP packet in edx
|
||||||
|
|
||||||
; get # of bytes in ecx
|
; get # of bytes in ecx
|
||||||
movzx ecx, byte [edx + 3] ; total length of IP packet. Subtract
|
movzx ecx, [edx + IP_PACKET.TotalLength] ; total length of IP packet. Subtract
|
||||||
mov ch, byte [edx + 2] ; 20 + 8 gives data length
|
xchg cl, ch ; 20 + 8 gives data length
|
||||||
sub ecx, 28
|
sub ecx, 28
|
||||||
|
|
||||||
mov ebx, eax
|
mov eax, [ebx + SOCKET.rxDataCount] ; get # of bytes already in buffer
|
||||||
add ebx, sockets ; ebx = address of actual socket
|
add [ebx + SOCKET.rxDataCount], ecx ; increment the count of bytes in buffer
|
||||||
|
|
||||||
mov eax, [ebx+ 4] ; get socket owner PID
|
; ecx has count, edx points to data
|
||||||
push eax
|
|
||||||
|
|
||||||
mov eax, [ebx + 24] ; get # of bytes already in buffer
|
|
||||||
add [ebx + 24], ecx ; increment the count of bytes in buffer
|
|
||||||
|
|
||||||
; point to the location to store the data
|
|
||||||
add ebx, eax
|
|
||||||
add ebx, SOCKETHEADERSIZE
|
|
||||||
|
|
||||||
; ebx = location for first byte, ecx has count,
|
|
||||||
; edx points to data
|
|
||||||
|
|
||||||
add edx, 28 ; edx now points to the data
|
add edx, 28 ; edx now points to the data
|
||||||
mov edi, ebx
|
lea edi, [ebx + eax + SOCKETHEADERSIZE]
|
||||||
mov esi, edx
|
mov esi, edx
|
||||||
|
|
||||||
cld
|
cld
|
||||||
rep movsb ; copy the data across
|
rep movsb ; copy the data across
|
||||||
|
|
||||||
; flag an event to the application
|
; flag an event to the application
|
||||||
pop eax
|
mov eax, [ebx + SOCKET.PID] ; get socket owner PID
|
||||||
mov ecx,1
|
mov ecx, 1
|
||||||
mov esi,TASK_DATA+TASKDATA.pid
|
mov esi, TASK_DATA + TASKDATA.pid
|
||||||
|
|
||||||
newsearch:
|
.next_pid:
|
||||||
cmp [esi],eax
|
cmp [esi], eax
|
||||||
je foundPID
|
je .found_pid
|
||||||
inc ecx
|
inc ecx
|
||||||
add esi,0x20
|
add esi, 0x20
|
||||||
cmp ecx,[TASK_COUNT]
|
cmp ecx, [TASK_COUNT]
|
||||||
jbe newsearch
|
jbe .next_pid
|
||||||
|
|
||||||
foundPID:
|
jmp .exit
|
||||||
shl ecx,8
|
|
||||||
or dword [ecx+SLOT_BASE+APPDATA.event_mask],dword 10000000b ; stack event
|
|
||||||
|
|
||||||
mov [check_idle_semaphore],200
|
.found_pid:
|
||||||
|
shl ecx, 8
|
||||||
|
or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK ; stack event
|
||||||
|
|
||||||
udprx_001:
|
mov [check_idle_semaphore], 200
|
||||||
|
|
||||||
|
.exit:
|
||||||
pop eax
|
pop eax
|
||||||
call freeBuff ; Discard the packet
|
call freeBuff ; Discard the packet
|
||||||
ret
|
ret
|
||||||
|
endp
|
||||||
|
Loading…
Reference in New Issue
Block a user