Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 906 → Rev 907

/kernel/trunk/network/udp.inc
71,7 → 71,8
; Free up (or re-use) IP buffer when finished
;
;***************************************************************************
udp_rx:
 
proc udp_rx stdcall
push eax
 
; First validate the header & checksum. Discard buffer if error
80,69 → 81,55
; IP Packet UDP Destination Port = local Port
; 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
mov eax, SOCKETBUFFSIZE * NUM_SOCKETS
mov ecx, NUM_SOCKETS
 
fs1:
sub eax, SOCKETBUFFSIZE
cmp [eax + sockets + 12], bx ; bx will hold the 'wrong' value,
mov ebx, net_sockets_mutex
call wait_mutex
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
loopnz fs1 ; Return back if no match
jz fs_done
jne .next_socket ; Return back if no match
 
; No match, so exit
jmp udprx_001
 
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
je udprx_002
cmp [ebx + SOCKET.RemoteIP], 0xffffffff
je @f
 
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
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
 
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
; - it will have changed
; 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 )
mov [eax + sockets + 20], bx
mov [ebx + SOCKET.RemotePort], ax
 
; Now, copy data to socket. We have socket address as [eax + sockets].
; We have IP packet in edx
 
; 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
movzx ecx, [edx + IP_PACKET.TotalLength] ; total length of IP packet. Subtract
xchg cl, ch ; 20 + 8 gives data length
sub ecx, 28
 
mov ebx, eax
add ebx, sockets ; ebx = address of actual socket
mov eax, [ebx + SOCKET.rxDataCount] ; get # of bytes already in buffer
add [ebx + SOCKET.rxDataCount], ecx ; increment the count of bytes in buffer
 
mov eax, [ebx+ 4] ; get socket owner PID
push eax
; ecx has count, edx points to data
 
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
mov edi, ebx
lea edi, [ebx + eax + SOCKETHEADERSIZE]
mov esi, edx
 
cld
149,25 → 136,28
rep movsb ; copy the data across
 
; flag an event to the application
pop eax
mov eax, [ebx + SOCKET.PID] ; get socket owner PID
mov ecx,1
mov esi,TASK_DATA+TASKDATA.pid
 
newsearch:
.next_pid:
cmp [esi],eax
je foundPID
je .found_pid
inc ecx
add esi,0x20
cmp ecx,[TASK_COUNT]
jbe newsearch
jbe .next_pid
 
foundPID:
jmp .exit
 
.found_pid:
shl ecx,8
or dword [ecx+SLOT_BASE+APPDATA.event_mask],dword 10000000b ; stack event
or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK ; stack event
 
mov [check_idle_semaphore],200
 
udprx_001:
.exit:
pop eax
call freeBuff ; Discard the packet
ret
endp