2008-07-28 08:29:05 +02: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 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
|
;*******************************************************************
|
|
|
|
; Interface
|
|
|
|
;
|
|
|
|
; udp_rx Handles received IP packets with the UDP protocol
|
|
|
|
;
|
|
|
|
;*******************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
; 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
|
|
|
|
|
|
|
|
|
|
|
|
;***************************************************************************
|
|
|
|
; Function
|
|
|
|
; udp_rx [by Johnny_B]
|
|
|
|
;
|
|
|
|
; Description
|
|
|
|
; UDP protocol handler
|
|
|
|
; This is a kernel function, called by ip_rx
|
|
|
|
; IP buffer address given in edx
|
|
|
|
; IP buffer number in eax
|
|
|
|
; Free up (or re-use) IP buffer when finished
|
|
|
|
;
|
|
|
|
;***************************************************************************
|
2008-11-07 05:10:42 +01:00
|
|
|
|
|
|
|
proc udp_rx stdcall
|
2008-07-28 08:29:05 +02:00
|
|
|
push eax
|
|
|
|
|
|
|
|
; First validate the header & checksum. Discard buffer if error
|
|
|
|
|
|
|
|
; Look for a socket where
|
|
|
|
; IP Packet UDP Destination Port = local Port
|
|
|
|
; IP Packet SA = Remote IP
|
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
mov ax, [edx + 20 + UDP_PACKET.DestinationPort] ; get the local port from
|
2008-07-28 08:29:05 +02:00
|
|
|
; the IP packet's UDP header
|
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
mov ebx, net_sockets
|
2008-07-28 08:29:05 +02:00
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
.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
|
|
|
|
jne .next_socket ; Return back if no match
|
2008-07-28 08:29:05 +02:00
|
|
|
|
|
|
|
; 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
|
2008-11-07 05:10:42 +01:00
|
|
|
cmp [ebx + SOCKET.RemoteIP], 0xffffffff
|
|
|
|
je @f
|
2008-07-28 08:29:05 +02:00
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
mov eax, [edx + IP_PACKET.SourceAddress] ; get the Source address from the IP packet
|
|
|
|
cmp [ebx + SOCKET.RemoteIP], ebx
|
|
|
|
jne .exit ; Quit if the source IP is not valid
|
2008-07-28 08:29:05 +02:00
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
@@: ; OK - we have a valid UDP packet for this socket.
|
2008-07-28 08:29:05 +02:00
|
|
|
; First, update the sockets remote port number with the incoming msg
|
|
|
|
; - it will have changed
|
|
|
|
; from the original ( 69 normally ) to allow further connects
|
2008-11-07 05:10:42 +01:00
|
|
|
mov ax, [edx + 20 + UDP_PACKET.SourcePort] ; get the UDP source port
|
2008-07-28 08:29:05 +02:00
|
|
|
; ( was 69, now new )
|
2008-11-07 05:10:42 +01:00
|
|
|
mov [ebx + SOCKET.RemotePort], ax
|
2008-07-28 08:29:05 +02:00
|
|
|
|
|
|
|
; Now, copy data to socket. We have socket address as [eax + sockets].
|
|
|
|
; We have IP packet in edx
|
|
|
|
|
|
|
|
; get # of bytes in ecx
|
2008-11-07 05:10:42 +01:00
|
|
|
movzx ecx, [edx + IP_PACKET.TotalLength] ; total length of IP packet. Subtract
|
|
|
|
xchg cl, ch ; 20 + 8 gives data length
|
2008-07-28 08:29:05 +02:00
|
|
|
sub ecx, 28
|
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
mov eax, [ebx + SOCKET.rxDataCount] ; get # of bytes already in buffer
|
|
|
|
add [ebx + SOCKET.rxDataCount], ecx ; increment the count of bytes in buffer
|
2008-07-28 08:29:05 +02:00
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
; ecx has count, edx points to data
|
2008-07-28 08:29:05 +02:00
|
|
|
|
|
|
|
add edx, 28 ; edx now points to the data
|
2008-11-07 05:10:42 +01:00
|
|
|
lea edi, [ebx + eax + SOCKETHEADERSIZE]
|
2008-07-28 08:29:05 +02:00
|
|
|
mov esi, edx
|
|
|
|
|
|
|
|
cld
|
|
|
|
rep movsb ; copy the data across
|
|
|
|
|
|
|
|
; flag an event to the application
|
2008-11-07 05:10:42 +01:00
|
|
|
mov eax, [ebx + SOCKET.PID] ; get socket owner PID
|
|
|
|
mov ecx, 1
|
|
|
|
mov esi, TASK_DATA + TASKDATA.pid
|
2008-07-28 08:29:05 +02:00
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
.next_pid:
|
|
|
|
cmp [esi], eax
|
|
|
|
je .found_pid
|
2008-07-28 08:29:05 +02:00
|
|
|
inc ecx
|
2008-11-07 05:10:42 +01:00
|
|
|
add esi, 0x20
|
|
|
|
cmp ecx, [TASK_COUNT]
|
|
|
|
jbe .next_pid
|
|
|
|
|
|
|
|
jmp .exit
|
2008-07-28 08:29:05 +02:00
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
.found_pid:
|
|
|
|
shl ecx, 8
|
|
|
|
or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK ; stack event
|
2008-07-28 08:29:05 +02:00
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
mov [check_idle_semaphore], 200
|
2008-07-28 08:29:05 +02:00
|
|
|
|
2008-11-07 05:10:42 +01:00
|
|
|
.exit:
|
2008-07-28 08:29:05 +02:00
|
|
|
pop eax
|
|
|
|
call freeBuff ; Discard the packet
|
|
|
|
ret
|
2008-11-07 05:10:42 +01:00
|
|
|
endp
|