Subversion Repositories Kolibri OS

Rev

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

Rev 5594 Rev 5984
Line 12... Line 12...
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 16... Line 16...
16
 
16
 
Line 17... Line 17...
17
$Revision: 5594 $
17
$Revision: 5984 $
Line 18... Line 18...
18
 
18
 
Line 34... Line 34...
34
        UDP_PACKETS_RX          rd  NET_DEVICES_MAX
34
        UDP_PACKETS_RX          rd  NET_DEVICES_MAX
Line 35... Line 35...
35
 
35
 
Line 36... Line 36...
36
endg
36
endg
37
 
-
 
38
 
-
 
39
;-----------------------------------------------------------------
-
 
-
 
37
 
40
;
38
 
41
; UDP_init
-
 
-
 
39
;-----------------------------------------------------------------;
42
;
40
;                                                                 ;
43
;  This function resets all UDP variables
41
; UDP_init: This function resets all UDP variables                ;
Line 44... Line 42...
44
;
42
;                                                                 ;
45
;-----------------------------------------------------------------
43
;-----------------------------------------------------------------;
46
macro   UDP_init {
44
macro   UDP_init {
Line 55... Line 53...
55
macro   UDP_checksum    IP1, IP2  { ; esi = ptr to udp packet, ecx = packet size, destroys: ecx, edx
53
macro   UDP_checksum    IP1, IP2  { ; esi = ptr to udp packet, ecx = packet size, destroys: ecx, edx
Line 56... Line 54...
56
 
54
 
57
; Pseudoheader
55
; Pseudoheader
Line 58... Line 56...
58
        mov     edx, IP_PROTO_UDP
56
        mov     edx, IP_PROTO_UDP
59
 
57
 
60
        add     dl, [IP1+1]
58
        add     dl, byte[IP1+1]
61
        adc     dh, [IP1+0]
59
        adc     dh, byte[IP1+0]
62
        adc     dl, [IP1+3]
60
        adc     dl, byte[IP1+3]
63
        adc     dh, [IP1+2]
61
        adc     dh, byte[IP1+2]
64
 
62
 
65
        adc     dl, [IP2+1]
63
        adc     dl, byte[IP2+1]
66
        adc     dh, [IP2+0]
64
        adc     dh, byte[IP2+0]
Line 67... Line 65...
67
        adc     dl, [IP2+3]
65
        adc     dl, byte[IP2+3]
68
        adc     dh, [IP2+2]
66
        adc     dh, byte[IP2+2]
Line 69... Line 67...
69
 
67
 
Line 96... Line 94...
96
        add     [esi+UDP_header.Checksum], dx   ; this final instruction will set or clear ZF :)
94
        add     [esi+UDP_header.Checksum], dx   ; this final instruction will set or clear ZF :)
Line 97... Line 95...
97
 
95
 
Line 98... Line 96...
98
}
96
}
99
 
-
 
100
 
-
 
101
;-----------------------------------------------------------------
-
 
102
;
97
 
103
; UDP_input:
98
 
104
;
-
 
105
;  Called by IPv4_input,
99
;-----------------------------------------------------------------;
106
;  this procedure will inject the udp data diagrams in the application sockets.
100
;                                                                 ;
107
;
101
; UDP_input: Inject the UDP data in the application sockets.      ;
108
;  IN:   [esp]  = Pointer to buffer
102
;                                                                 ;
109
;       [esp+4] = size of buffer
103
;   IN: [esp] = ptr to buffer                                     ;
110
;       ebx = ptr to device struct
104
;       ebx = ptr to device struct                                ;
111
;       ecx = UDP Packet size
-
 
-
 
105
;       ecx = UDP packet size                                     ;
-
 
106
;       edx = ptr to IPv4 header                                  ;
112
;       esi = ptr to UDP header
107
;       esi = ptr to UDP packet data                              ;
113
;       edi = ptr to ipv4 source and dest address
-
 
-
 
108
;       edi = interface number*4                                  ;
114
;
109
;                                                                 ;
115
;  OUT: /
110
;  OUT: /                                                         ;
116
;
111
;                                                                 ;
Line 117... Line 112...
117
;-----------------------------------------------------------------
112
;-----------------------------------------------------------------;
Line 125... Line 120...
125
        neg     [esi + UDP_header.Checksum]     ; substract checksum from 0
120
        neg     [esi + UDP_header.Checksum]     ; substract checksum from 0
126
        jz      .no_checksum                    ; if checksum is zero, it is considered valid
121
        jz      .no_checksum                    ; if checksum is zero, it is considered valid
Line 127... Line 122...
127
 
122
 
Line 128... Line 123...
128
        ; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct
123
        ; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct
-
 
124
 
129
 
125
        mov     eax, edx
Line 130... Line 126...
130
        UDP_checksum (edi), (edi+4)
126
        UDP_checksum (eax+IPv4_header.SourceAddress), (eax+IPv4_header.DestinationAddress)
131
        jnz     .checksum_mismatch
127
        jnz     .checksum_mismatch
Line 146... Line 142...
146
        call    mutex_lock
142
        call    mutex_lock
147
        popa
143
        popa
Line 148... Line 144...
148
 
144
 
149
        mov     cx, [esi + UDP_header.SourcePort]
145
        mov     cx, [esi + UDP_header.SourcePort]
150
        mov     dx, [esi + UDP_header.DestinationPort]
-
 
151
        mov     edi, [edi + 4]                          ; ipv4 source address
146
        mov     dx, [esi + UDP_header.DestinationPort]
152
        mov     eax, net_sockets
-
 
153
 
147
        mov     eax, net_sockets
154
  .next_socket:
148
  .next_socket:
155
        mov     eax, [eax + SOCKET.NextPtr]
149
        mov     eax, [eax + SOCKET.NextPtr]
156
        or      eax, eax
150
        or      eax, eax
Line 170... Line 164...
170
        pusha
164
        pusha
171
        mov     ecx, socket_mutex
165
        mov     ecx, socket_mutex
172
        call    mutex_unlock
166
        call    mutex_unlock
173
        popa
167
        popa
Line 174... Line 168...
174
 
168
 
Line -... Line 169...
-
 
169
        ;;; TODO: when packet is processed, check more sockets?!
-
 
170
 
175
        ;;; TODO: when packet is processed, check more sockets!
171
; FIXME: check remote IP if possible
176
 
172
;
177
;        cmp     [eax + IP_SOCKET.RemoteIP], 0xffffffff
173
;        cmp     [eax + IP_SOCKET.RemoteIP], 0xffffffff
178
;        je      @f
174
;        je      @f
179
;        cmp     [eax + IP_SOCKET.RemoteIP], edi
175
;        cmp     [eax + IP_SOCKET.RemoteIP],
180
;        jne     .next_socket
-
 
181
;       @@:
-
 
Line 182... Line 176...
182
;
176
;        jne     .next_socket
183
; FIXME: UDP should check remote IP, but not under all circumstances!
177
;       @@:
Line 184... Line 178...
184
 
178
 
Line 192... Line 186...
192
        lea     ecx, [eax + SOCKET.mutex]
186
        lea     ecx, [eax + SOCKET.mutex]
193
        call    mutex_lock
187
        call    mutex_lock
194
        popa
188
        popa
Line 195... Line 189...
195
 
189
 
196
  .updatesock:
-
 
197
        call    NET_ptr_to_num4
190
  .updatesock:
Line 198... Line 191...
198
        inc     [UDP_PACKETS_RX + edi]
191
        inc     [UDP_PACKETS_RX + edi]
199
 
192
 
200
        movzx   ecx, [esi + UDP_header.Length]
193
        movzx   ecx, [esi + UDP_header.Length]
Line 230... Line 223...
230
        call    NET_BUFF_free
223
        call    NET_BUFF_free
231
        ret
224
        ret
Line 232... Line 225...
232
 
225
 
233
 
-
 
-
 
226
 
234
 
227
 
235
;-----------------------------------------------------------------
-
 
-
 
228
;-----------------------------------------------------------------;
236
;
229
;                                                                 ;
237
; UDP_output
230
; UDP_output: Create an UDP packet.                               ;
238
;
231
;                                                                 ;
239
; IN: eax = socket pointer
-
 
-
 
232
;  IN:  eax = socket pointer                                      ;
240
;     ecx = number of bytes to send
233
;       ecx = number of bytes to send                             ;
241
;     esi = pointer to data
-
 
-
 
234
;       esi = pointer to data                                     ;
242
;
235
;                                                                 ;
Line 243... Line 236...
243
; OUT: eax = -1 on error
236
; OUT:  eax = -1 on error                                         ;
244
;
237
;                                                                 ;
Line 245... Line 238...
245
;-----------------------------------------------------------------
238
;-----------------------------------------------------------------;
Line 255... Line 248...
255
        mov     dx, [eax + UDP_SOCKET.LocalPort]
248
        mov     dx, [eax + UDP_SOCKET.LocalPort]
256
        DEBUGF  DEBUG_NETWORK_VERBOSE, "local port=%x\n", dx
249
        DEBUGF  DEBUG_NETWORK_VERBOSE, "local port=%x\n", dx
Line 257... Line 250...
257
 
250
 
258
        sub     esp, 4                                          ; Data ptr will be placed here
251
        sub     esp, 4                                          ; Data ptr will be placed here
259
        push    edx esi
-
 
260
        mov     edx, [eax + IP_SOCKET.LocalIP]
252
        push    edx esi
-
 
253
        mov     ebx, [eax + IP_SOCKET.device]
261
        mov     ebx, [eax + IP_SOCKET.device]
254
        mov     edx, [eax + IP_SOCKET.LocalIP]
-
 
255
        mov     edi, [eax + IP_SOCKET.RemoteIP]
262
        mov     eax, [eax + IP_SOCKET.RemoteIP]
256
        mov     al, [eax + IP_SOCKET.ttl]
263
        mov     di, IP_PROTO_UDP shl 8 + 128
257
        mov     ah, IP_PROTO_UDP
264
        add     ecx, sizeof.UDP_header
258
        add     ecx, sizeof.UDP_header
265
        call    IPv4_output
259
        call    IPv4_output
266
        jz      .fail
260
        jz      .fail
Line 304... Line 298...
304
        ret
298
        ret
Line 305... Line 299...
305
 
299
 
306
 
-
 
-
 
300
 
307
 
301
 
308
 
-
 
-
 
302
 
309
;-----------------------------------------------------------------
303
;-----------------------------------------------------------------;
-
 
304
;                                                                 ;
310
;
305
; UDP_connect                                                     ;
-
 
306
;                                                                 ;
311
; UDP_connect
307
;   IN: eax = socket pointer                                      ;
312
;
-
 
-
 
308
;                                                                 ;
313
;   IN: eax = socket pointer
309
;  OUT: eax = 0 on success                                        ;
314
;  OUT: eax = 0 ok / -1 error
310
;       eax = -1 on error                                         ;
315
;       ebx = error code
311
;       ebx = error code on error                                 ;
Line 316... Line 312...
316
;
312
;                                                                 ;
317
;-------------------------
313
;-----------------------------------------------------------------;
Line 346... Line 342...
346
        jne     @f
342
        jne     @f
347
        call    SOCKET_find_port
343
        call    SOCKET_find_port
348
       @@:
344
       @@:
Line 349... Line 345...
349
 
345
 
350
        push    eax
-
 
351
        init_queue (eax + SOCKET_QUEUE_LOCATION)                ; Set up data receiving queue
-
 
352
        pop     eax
-
 
353
 
-
 
354
        push    eax
346
        push    eax
355
        lea     ecx, [eax + SOCKET.mutex]
347
        lea     ecx, [eax + SOCKET.mutex]
356
        call    mutex_unlock
348
        call    mutex_unlock
Line 357... Line 349...
357
        pop     eax
349
        pop     eax
Line 358... Line 350...
358
 
350
 
359
        call    SOCKET_is_connected
351
        call    SOCKET_is_connected
Line 360... Line 352...
360
 
352
 
361
        xor     eax, eax
-
 
-
 
353
        xor     eax, eax
362
        ret
354
        ret
363
 
-
 
-
 
355
 
364
 
356
 
-
 
357
;-----------------------------------------------------------------;
365
;-----------------------------------------------------------------
358
;                                                                 ;
366
;
-
 
-
 
359
; UDP_disconnect                                                  ;
367
; UDP_disconnect
360
;                                                                 ;
368
;
361
;   IN: eax = socket pointer                                      ;
369
;   IN: eax = socket pointer
362
;                                                                 ;
Line 370... Line 363...
370
;  OUT: eax = socket pointer
363
;  OUT: eax = socket pointer                                      ;
Line 381... Line 374...
381
 
374
 
382
 
-
 
383
 
-
 
384
 
-
 
-
 
375
 
385
 
376
 
386
;---------------------------------------------------------------------------
-
 
-
 
377
 
387
;
378
 
388
; UDP_API
379
;-----------------------------------------------------------------;
389
;
380
;                                                                 ;
390
; This function is called by system function 75
-
 
-
 
381
; UDP_api: This function is called by system function 76          ;
391
;
382
;                                                                 ;
392
; IN:  subfunction number in bl
-
 
-
 
383
;  IN: bl = subfunction number in bl                              ;
393
;      device number in bh
384
;      bh = device number in bh                                   ;
394
;      ecx, edx, .. depends on subfunction
-
 
395
;
385
;      ecx, edx, .. depends on subfunction                        ;
396
; OUT:
386
;                                                                 ;
Line 397... Line 387...
397
;
387
; OUT: depends on subfunction                                     ;
398
;---------------------------------------------------------------------------
388
;                                                                 ;