Subversion Repositories Kolibri OS

Rev

Rev 2 | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;;  UDP.INC                                                        ;;
  4. ;;                                                                 ;;
  5. ;;  UDP Processes for Menuet OS  TCP/IP stack                      ;;
  6. ;;                                                                 ;;
  7. ;;  Version 0.3  29 August 2002                                    ;;
  8. ;;                                                                 ;;
  9. ;;  Copyright 2002 Mike Hibbett, mikeh@oceanfree.net               ;;
  10. ;;                                                                 ;;
  11. ;;  See file COPYING for details                                   ;;
  12. ;;                                                                 ;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.    
  15.    
  16. ;*******************************************************************
  17. ;   Interface
  18. ;
  19. ;       udp_rx      Handles received IP packets with the UDP protocol
  20. ;                  
  21. ;*******************************************************************
  22.    
  23.    
  24.    
  25.    
  26. ;***************************************************************************
  27. ;   Function
  28. ;      udp_rx
  29. ;
  30. ;   Description
  31. ;       UDP protocol handler
  32. ;       This is a kernel function, called by ip_rx
  33. ;       IP buffer address given in edx
  34. ;          Free up (or re-use) IP buffer when finished
  35. ;
  36. ;***************************************************************************
  37. udp_rx:
  38.     push    eax
  39.          
  40.     ; First validate the header & checksum. Discard buffer if error
  41.    
  42.     ; Look for a socket where
  43.     ; IP Packet UDP Destination Port = local Port
  44.     ; IP Packet SA = Remote IP
  45.    
  46.     movzx   ebx, word [edx + 22]   ; get the local port from
  47.                                   ; the IP packet's UDP header
  48.     mov     eax, SOCKETBUFFSIZE * NUM_SOCKETS
  49.     mov     ecx, NUM_SOCKETS
  50.        
  51. fs1:
  52.     sub     eax, SOCKETBUFFSIZE
  53.     cmp     [eax + sockets + 12], bx ; bx will hold the 'wrong' value,
  54.                                     ; but the comparision is correct
  55.     loopnz  fs1                     ; Return back if no match
  56.     jz      fs_done
  57.    
  58.     ; No match, so exit
  59.     jmp     udprx_001
  60.        
  61. fs_done:
  62.     ; For dhcp, we must allow any remote server to respond.
  63.     ; I will accept the first incoming response to be the one
  64.     ; I bind to, if the socket is opened with a destination IP address of
  65.     ; 255.255.255.255
  66.     mov     ebx, [eax + sockets + 16]
  67.     cmp     ebx, 0xffffffff
  68.     je      udprx_002  
  69.      
  70.     mov     ebx, [edx + 12]    ; get the Source address from the IP packet
  71.     cmp     [eax + sockets + 16], ebx
  72.     jne     udprx_001          ; Quit if the source IP is not valid
  73.  
  74. udprx_002:  
  75.     ; OK - we have a valid UDP packet for this socket.
  76.     ; First, update the sockets remote port number with the incoming msg
  77.     ; - it will have changed
  78.     ; from the original ( 69 normally ) to allow further connects
  79.     movzx   ebx, word [edx + 20]      ; get the UDP source port
  80.                                      ; ( was 69, now new )
  81.     mov     [eax + sockets + 20], bx
  82.    
  83.     ; Now, copy data to socket. We have socket address as [eax + sockets].
  84.     ; We have IP packet in edx
  85.      
  86.     ; get # of bytes in ecx
  87.     movzx   ecx, byte [edx + 3]  ; total length of IP packet. Subtract
  88.     mov     ch, byte [edx + 2]   ; 20 + 8 gives data length
  89.     sub     ecx, 28
  90.    
  91.     mov     ebx, eax
  92.     add     ebx, sockets         ; ebx = address of actual socket
  93.    
  94.     mov     eax, [ebx+ 4]       ; get socket owner PID
  95.     push    eax
  96.    
  97.     mov     eax, [ebx + 24]      ; get # of bytes already in buffer
  98.     add     [ebx + 24], ecx      ; increment the count of bytes in buffer
  99.    
  100.     ; point to the location to store the data
  101.     add     ebx, eax
  102.     add     ebx, SOCKETHEADERSIZE
  103.  
  104.     ; ebx = location for first byte, ecx has count,
  105.     ; edx points to data
  106.    
  107.     add     edx, 28        ; edx now points to the data
  108.     mov     edi, ebx
  109.     mov     esi, edx
  110.    
  111.     cld
  112.     rep     movsb          ; copy the data across
  113.      
  114.     ; flag an event to the application
  115.     pop     eax
  116.     mov     ecx,1
  117.     mov     esi,0x3020+TASKDATA.pid
  118.    
  119. newsearch:
  120.     cmp     [esi],eax
  121.     je      foundPID
  122.     inc     ecx
  123.     add     esi,0x20
  124.     cmp     ecx,[0x3004]
  125.     jbe     newsearch
  126.              
  127. foundPID:
  128.     shl     ecx,8
  129.     or      dword [ecx+0x80000+APPDATA.event_mask],dword 10000000b ; stack event
  130.  
  131.     mov     [check_idle_semaphore],200  
  132.  
  133. udprx_001:
  134.     pop     eax
  135.     call    freeBuff    ; Discard the packet
  136.     ret    
  137.