Subversion Repositories Kolibri OS

Rev

Rev 2465 | Rev 3589 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2465 Rev 3555
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                              ;;
5
;;                                                                 ;;
6
;;                                                              ;;
-
 
7
;;  UDP.INC                                                     ;;
6
;;  UDP.INC                                                        ;;
8
;;                                                              ;;
7
;;                                                                 ;;
9
;;  UDP Processes for Menuet OS  TCP/IP stack                   ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
10
;;                                                              ;;
9
;;                                                                 ;;
11
;;  Copyright 2002 Mike Hibbett, mikeh@oceanfree.net            ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
12
;;                                                              ;;
11
;;                                                                 ;;
-
 
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;  See file COPYING for details                                ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                              ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 16... Line 16...
16
 
16
 
Line 17... Line -...
17
$Revision: 2465 $
-
 
18
 
17
$Revision: 3555 $
19
 
-
 
20
;*******************************************************************
-
 
21
;   Interface
-
 
22
;
-
 
Line -... Line 18...
-
 
18
 
-
 
19
 
-
 
20
struct  UDP_header
-
 
21
 
Line -... Line 22...
-
 
22
        SourcePort              dw  ?
-
 
23
        DestinationPort         dw  ?
-
 
24
        Length                  dw  ?  ; Length of (UDP Header + Data)
-
 
25
        Checksum                dw  ?
-
 
26
 
-
 
27
ends
-
 
28
 
-
 
29
 
-
 
30
align 4
-
 
31
uglobal
-
 
32
        UDP_PACKETS_TX          rd  MAX_NET_DEVICES
23
;       udp_rx      Handles received IP packets with the UDP protocol
33
        UDP_PACKETS_RX          rd  MAX_NET_DEVICES
24
;
-
 
25
;*******************************************************************
34
endg
26
 
-
 
27
 
-
 
28
;
35
 
29
;   UDP Payload ( Data field in IP datagram )
-
 
30
;
-
 
31
;    0                   1                   2                   3
-
 
32
;    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
36
 
33
;
-
 
34
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
 
35
;   |       Source Port             |      Destination Port         |
-
 
36
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37
;-----------------------------------------------------------------
-
 
38
;
-
 
39
; UDP_init
Line 37... Line -...
37
;   | Length ( UDP Header + Data )  |           Checksum            |
-
 
38
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40
;
39
;   |       UDP Data                                                |
-
 
40
;   +-+-+-..........                                               -+
41
;  This function resets all UDP variables
41
;
42
;
42
 
43
;-----------------------------------------------------------------
43
struc UDP_PACKET
44
macro   UDP_init {
Line -... Line 45...
-
 
45
 
-
 
46
        xor     eax, eax
-
 
47
        mov     edi, UDP_PACKETS_TX
44
{  .SourcePort	     dw  ?  ;+00
48
        mov     ecx, 2*MAX_NET_DEVICES
-
 
49
        rep     stosd
-
 
50
}
-
 
51
 
-
 
52
 
-
 
53
macro   UDP_checksum    IP1, IP2  { ; esi = ptr to udp packet, ecx = packet size, destroys: ecx, edx
-
 
54
 
-
 
55
; Pseudoheader
-
 
56
        mov     edx, IP_PROTO_UDP
-
 
57
 
-
 
58
        add     dl, [IP1+1]
-
 
59
        adc     dh, [IP1+0]
-
 
60
        adc     dl, [IP1+3]
-
 
61
        adc     dh, [IP1+2]
-
 
62
 
-
 
63
        adc     dl, [IP2+1]
-
 
64
        adc     dh, [IP2+0]
-
 
65
        adc     dl, [IP2+3]
-
 
66
        adc     dh, [IP2+2]
-
 
67
 
-
 
68
        adc     dl, cl ; byte[esi+UDP_header.Length+1]
-
 
69
        adc     dh, ch ; byte[esi+UDP_header.Length+0]
-
 
70
 
-
 
71
; Done with pseudoheader, now do real header
-
 
72
        adc     dl, byte[esi+UDP_header.SourcePort+1]
-
 
73
        adc     dh, byte[esi+UDP_header.SourcePort+0]
45
   .DestinationPort  dw  ?  ;+02
74
 
-
 
75
        adc     dl, byte[esi+UDP_header.DestinationPort+1]
-
 
76
        adc     dh, byte[esi+UDP_header.DestinationPort+0]
46
   .Length	     dw  ?  ;+04 - Length of (UDP Header + Data)
77
 
-
 
78
        adc     dl, byte[esi+UDP_header.Length+1]
-
 
79
        adc     dh, byte[esi+UDP_header.Length+0]
-
 
80
 
-
 
81
        adc     edx, 0
-
 
82
 
-
 
83
; Done with header, now do data
-
 
84
        push    esi
-
 
85
        movzx   ecx, [esi+UDP_header.Length]
-
 
86
        rol     cx , 8
-
 
87
        sub     cx , sizeof.UDP_header
-
 
88
        add     esi, sizeof.UDP_header
-
 
89
 
Line 47... Line 90...
47
   .Checksum	     dw  ?  ;+06
90
        call    checksum_1
-
 
91
        call    checksum_2
48
   .Data	     db  ?  ;+08
92
        pop     esi
-
 
93
 
49
}
94
        add     [esi+UDP_header.Checksum], dx   ; this final instruction will set or clear ZF :)
-
 
95
 
50
 
96
}
51
virtual at 0
97
 
52
  UDP_PACKET UDP_PACKET
98
 
53
end virtual
99
;-----------------------------------------------------------------
54
 
100
;
55
 
101
; UDP_input:
56
;***************************************************************************
102
;
57
;   Function
103
;  Called by IPv4_input,
-
 
104
;  this procedure will inject the udp data diagrams in the application sockets.
-
 
105
;
58
;      udp_rx  [by Johnny_B]
106
;  IN:   [esp]  = Pointer to buffer
-
 
107
;       [esp+4] = size of buffer
-
 
108
;       ebx = ptr to device struct
-
 
109
;       ecx = UDP Packet size
-
 
110
;       esi = ptr to UDP header
-
 
111
;       edi = ptr to ipv4 source and dest address
-
 
112
;
Line 59... Line 113...
59
;
113
;  OUT: /
60
;   Description
-
 
-
 
114
;
Line 61... Line 115...
61
;       UDP protocol handler
115
;-----------------------------------------------------------------
-
 
116
align 4
-
 
117
UDP_input:
-
 
118
 
-
 
119
        DEBUGF  1,"UDP_input: size=%u\n", ecx
-
 
120
 
-
 
121
        ; First validate, checksum
-
 
122
 
-
 
123
        neg     [esi + UDP_header.Checksum]     ; substract checksum from 0
-
 
124
        jz      .no_checksum                    ; if checksum is zero, it is considered valid
-
 
125
 
Line 62... Line 126...
62
;       This is a kernel function, called by ip_rx
126
        ; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct
63
;       IP buffer address given in edx
127
 
64
;          IP buffer number in eax
128
        UDP_checksum (edi), (edi+4)
Line 65... Line 129...
65
;          Free up (or re-use) IP buffer when finished
129
        jnz     .checksum_mismatch
66
;
130
 
67
;***************************************************************************
-
 
-
 
131
  .no_checksum:
68
 
132
        DEBUGF  1,"UDP_input: checksum ok\n"
Line 69... Line 133...
69
proc udp_rx stdcall
133
 
140
	cmp	ecx, [TASK_COUNT]
311
        jz      .packets_tx     ; 0
141
	jbe	.next_pid
-