2007-03-26 16:18:08 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; ;;
|
|
|
|
;; UDP.INC ;;
|
|
|
|
;; ;;
|
|
|
|
;; UDP Processes for Menuet OS TCP/IP stack ;;
|
|
|
|
;; ;;
|
|
|
|
;; Version 0.3 29 August 2002 ;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;;
|
|
|
|
;; ;;
|
|
|
|
;; See file COPYING for details ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2007-07-27 17:52:03 +04:00
|
|
|
$Revision$
|
|
|
|
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
;*******************************************************************
|
|
|
|
; Interface
|
|
|
|
;
|
|
|
|
; udp_rx Handles received IP packets with the UDP protocol
|
2007-02-28 11:52:06 +03:00
|
|
|
;
|
2005-10-06 21:56:22 +04:00
|
|
|
;*******************************************************************
|
2007-01-06 04:15:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
; UDP Payload ( Data field in IP datagram )
|
|
|
|
;
|
|
|
|
; 0 1 2 3
|
|
|
|
; 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
|
|
|
|
;
|
|
|
|
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
; | Source Port | Destination Port |
|
|
|
|
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
; | Length ( UDP Header + Data ) | Checksum |
|
|
|
|
; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
; | UDP Data |
|
|
|
|
; +-+-+-.......... -+
|
|
|
|
;
|
|
|
|
|
|
|
|
struc UDP_PACKET
|
|
|
|
{ .SourcePort dw ? ;+00
|
|
|
|
.DestinationPort dw ? ;+02
|
|
|
|
.Length dw ? ;+04 - Length of (UDP Header + Data)
|
|
|
|
.Checksum dw ? ;+06
|
|
|
|
.Data db ? ;+08
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual at 0
|
|
|
|
UDP_PACKET UDP_PACKET
|
|
|
|
end virtual
|
|
|
|
|
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
;***************************************************************************
|
|
|
|
; Function
|
2007-01-06 04:15:21 +03:00
|
|
|
; udp_rx [by Johnny_B]
|
2005-10-06 21:56:22 +04:00
|
|
|
;
|
|
|
|
; Description
|
|
|
|
; UDP protocol handler
|
|
|
|
; This is a kernel function, called by ip_rx
|
|
|
|
; IP buffer address given in edx
|
2007-01-06 04:15:21 +03:00
|
|
|
; IP buffer number in eax
|
2005-10-06 21:56:22 +04:00
|
|
|
; Free up (or re-use) IP buffer when finished
|
|
|
|
;
|
|
|
|
;***************************************************************************
|
|
|
|
udp_rx:
|
|
|
|
push eax
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
; First validate the header & checksum. Discard buffer if error
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
; Look for a socket where
|
|
|
|
; IP Packet UDP Destination Port = local Port
|
|
|
|
; IP Packet SA = Remote IP
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
movzx ebx, word [edx + 22] ; get the local port from
|
|
|
|
; the IP packet's UDP header
|
|
|
|
mov eax, SOCKETBUFFSIZE * NUM_SOCKETS
|
|
|
|
mov ecx, NUM_SOCKETS
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
fs1:
|
|
|
|
sub eax, SOCKETBUFFSIZE
|
|
|
|
cmp [eax + sockets + 12], bx ; bx will hold the 'wrong' value,
|
|
|
|
; but the comparision is correct
|
|
|
|
loopnz fs1 ; Return back if no match
|
|
|
|
jz fs_done
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
; No match, so exit
|
|
|
|
jmp udprx_001
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
fs_done:
|
|
|
|
; For dhcp, we must allow any remote server to respond.
|
|
|
|
; 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
|
|
|
|
; 255.255.255.255
|
|
|
|
mov ebx, [eax + sockets + 16]
|
|
|
|
cmp ebx, 0xffffffff
|
2007-02-28 11:52:06 +03:00
|
|
|
je udprx_002
|
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
mov ebx, [edx + 12] ; get the Source address from the IP packet
|
|
|
|
cmp [eax + sockets + 16], ebx
|
|
|
|
jne udprx_001 ; Quit if the source IP is not valid
|
|
|
|
|
2007-02-28 11:52:06 +03:00
|
|
|
udprx_002:
|
2005-10-06 21:56:22 +04:00
|
|
|
; OK - we have a valid UDP packet for this socket.
|
|
|
|
; First, update the sockets remote port number with the incoming msg
|
|
|
|
; - it will have changed
|
|
|
|
; from the original ( 69 normally ) to allow further connects
|
|
|
|
movzx ebx, word [edx + 20] ; get the UDP source port
|
|
|
|
; ( was 69, now new )
|
|
|
|
mov [eax + sockets + 20], bx
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
; Now, copy data to socket. We have socket address as [eax + sockets].
|
|
|
|
; We have IP packet in edx
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
; get # of bytes in ecx
|
|
|
|
movzx ecx, byte [edx + 3] ; total length of IP packet. Subtract
|
|
|
|
mov ch, byte [edx + 2] ; 20 + 8 gives data length
|
|
|
|
sub ecx, 28
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
mov ebx, eax
|
|
|
|
add ebx, sockets ; ebx = address of actual socket
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
mov eax, [ebx+ 4] ; get socket owner PID
|
|
|
|
push eax
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
mov eax, [ebx + 24] ; get # of bytes already in buffer
|
|
|
|
add [ebx + 24], ecx ; increment the count of bytes in buffer
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
; point to the location to store the data
|
|
|
|
add ebx, eax
|
2007-02-28 11:52:06 +03:00
|
|
|
add ebx, SOCKETHEADERSIZE
|
2005-10-06 21:56:22 +04:00
|
|
|
|
|
|
|
; ebx = location for first byte, ecx has count,
|
|
|
|
; edx points to data
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
add edx, 28 ; edx now points to the data
|
|
|
|
mov edi, ebx
|
|
|
|
mov esi, edx
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
cld
|
|
|
|
rep movsb ; copy the data across
|
2007-02-28 11:52:06 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
; flag an event to the application
|
|
|
|
pop eax
|
|
|
|
mov ecx,1
|
2007-02-28 11:52:06 +03:00
|
|
|
mov esi,TASK_DATA+TASKDATA.pid
|
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
newsearch:
|
|
|
|
cmp [esi],eax
|
|
|
|
je foundPID
|
|
|
|
inc ecx
|
|
|
|
add esi,0x20
|
2007-02-28 11:52:06 +03:00
|
|
|
cmp ecx,[TASK_COUNT]
|
2005-10-06 21:56:22 +04:00
|
|
|
jbe newsearch
|
2007-02-28 11:52:06 +03:00
|
|
|
|
|
|
|
foundPID:
|
2005-10-06 21:56:22 +04:00
|
|
|
shl ecx,8
|
2007-02-28 13:51:05 +03:00
|
|
|
or dword [ecx+SLOT_BASE+APPDATA.event_mask],dword 10000000b ; stack event
|
2005-10-06 21:56:22 +04:00
|
|
|
|
2007-02-28 11:52:06 +03:00
|
|
|
mov [check_idle_semaphore],200
|
2005-10-06 21:56:22 +04:00
|
|
|
|
|
|
|
udprx_001:
|
|
|
|
pop eax
|
|
|
|
call freeBuff ; Discard the packet
|
2007-02-28 11:52:06 +03:00
|
|
|
ret
|