Subversion Repositories Kolibri OS

Rev

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

Rev 5976 Rev 6011
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: 5976 $
17
$Revision: 6011 $
Line 18... Line 18...
18
 
18
 
Line 36... Line 36...
36
endg
36
endg
Line 37... Line 37...
37
 
37
 
38
 
38
 
39
;-----------------------------------------------------------------;
39
;-----------------------------------------------------------------;
40
;                                                                 ;
40
;                                                                 ;
41
; UDP_init: This function resets all UDP variables                ;
41
; udp_init: This function resets all UDP variables                ;
42
;                                                                 ;
42
;                                                                 ;
Line 43... Line 43...
43
;-----------------------------------------------------------------;
43
;-----------------------------------------------------------------;
44
macro   UDP_init {
44
macro   udp_init {
45
 
45
 
46
        xor     eax, eax
46
        xor     eax, eax
47
        mov     edi, UDP_PACKETS_TX
47
        mov     edi, UDP_PACKETS_TX
Line 48... Line 48...
48
        mov     ecx, 2*NET_DEVICES_MAX
48
        mov     ecx, 2*NET_DEVICES_MAX
Line 49... Line 49...
49
        rep stosd
49
        rep stosd
50
}
50
}
Line 51... Line 51...
51
 
51
 
Line 96... Line 96...
96
}
96
}
Line 97... Line 97...
97
 
97
 
98
 
98
 
99
;-----------------------------------------------------------------;
99
;-----------------------------------------------------------------;
100
;                                                                 ;
100
;                                                                 ;
101
; UDP_input: Inject the UDP data in the application sockets.      ;
101
; udp_input: Inject the UDP data in the application sockets.      ;
102
;                                                                 ;
102
;                                                                 ;
103
;   IN: [esp] = ptr to buffer                                     ;
103
;   IN: [esp] = ptr to buffer                                     ;
104
;       ebx = ptr to device struct                                ;
104
;       ebx = ptr to device struct                                ;
Line 109... Line 109...
109
;                                                                 ;
109
;                                                                 ;
110
;  OUT: /                                                         ;
110
;  OUT: /                                                         ;
111
;                                                                 ;
111
;                                                                 ;
112
;-----------------------------------------------------------------;
112
;-----------------------------------------------------------------;
113
align 4
113
align 4
114
UDP_input:
114
udp_input:
Line 115... Line 115...
115
 
115
 
Line 116... Line 116...
116
        DEBUGF  DEBUG_NETWORK_VERBOSE, "UDP_input: size=%u\n", ecx
116
        DEBUGF  DEBUG_NETWORK_VERBOSE, "UDP_input: size=%u\n", ecx
Line 121... Line 121...
121
        jz      .no_checksum                    ; if checksum is zero, it is considered valid
121
        jz      .no_checksum                    ; if checksum is zero, it is considered valid
Line 122... Line 122...
122
 
122
 
Line 123... Line 123...
123
        ; 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
 
124
 
125
        mov     eax, edx
125
        mov     eax, edx
Line 126... Line 126...
126
        UDP_checksum (eax+IPv4_header.SourceAddress), (eax+IPv4_header.DestinationAddress)
126
        udp_checksum (eax+IPv4_header.SourceAddress), (eax+IPv4_header.DestinationAddress)
127
        jnz     .checksum_mismatch
127
        jnz     .checksum_mismatch
Line 192... Line 192...
192
 
192
 
193
        movzx   ecx, [esi + UDP_header.Length]
193
        movzx   ecx, [esi + UDP_header.Length]
194
        sub     ecx, sizeof.UDP_header
194
        sub     ecx, sizeof.UDP_header
Line 195... Line 195...
195
        add     esi, sizeof.UDP_header
195
        add     esi, sizeof.UDP_header
Line 196... Line 196...
196
 
196
 
197
        jmp     SOCKET_input
197
        jmp     socket_input
198
 
198
 
199
  .updateport:
199
  .updateport:
Line 218... Line 218...
218
  .checksum_mismatch:
218
  .checksum_mismatch:
219
        DEBUGF  DEBUG_NETWORK_VERBOSE, "UDP_input: checksum mismatch\n"
219
        DEBUGF  DEBUG_NETWORK_VERBOSE, "UDP_input: checksum mismatch\n"
Line 220... Line 220...
220
 
220
 
221
  .dump:
221
  .dump:
222
        DEBUGF  DEBUG_NETWORK_VERBOSE, "UDP_input: dumping\n"
222
        DEBUGF  DEBUG_NETWORK_VERBOSE, "UDP_input: dumping\n"
223
        call    NET_BUFF_free
223
        call    net_buff_free
Line 224... Line 224...
224
        ret
224
        ret
225
 
225
 
226
 
226
 
227
 
227
 
228
;-----------------------------------------------------------------;
228
;-----------------------------------------------------------------;
229
;                                                                 ;
229
;                                                                 ;
230
; UDP_output: Create an UDP packet.                               ;
230
; udp_output: Create an UDP packet.                               ;
231
;                                                                 ;
231
;                                                                 ;
232
;  IN:  eax = socket pointer                                      ;
232
;  IN:  eax = socket pointer                                      ;
233
;       ecx = number of bytes to send                             ;
233
;       ecx = number of bytes to send                             ;
234
;       esi = pointer to data                                     ;
234
;       esi = pointer to data                                     ;
Line 235... Line 235...
235
;                                                                 ;
235
;                                                                 ;
236
; OUT:  eax = -1 on error                                         ;
236
; OUT:  eax = -1 on error                                         ;
Line 237... Line 237...
237
;                                                                 ;
237
;                                                                 ;
Line 238... Line 238...
238
;-----------------------------------------------------------------;
238
;-----------------------------------------------------------------;
239
 
239
 
Line 254... Line 254...
254
        mov     edx, [eax + IP_SOCKET.LocalIP]
254
        mov     edx, [eax + IP_SOCKET.LocalIP]
255
        mov     edi, [eax + IP_SOCKET.RemoteIP]
255
        mov     edi, [eax + IP_SOCKET.RemoteIP]
256
        mov     al, [eax + IP_SOCKET.ttl]
256
        mov     al, [eax + IP_SOCKET.ttl]
257
        mov     ah, IP_PROTO_UDP
257
        mov     ah, IP_PROTO_UDP
258
        add     ecx, sizeof.UDP_header
258
        add     ecx, sizeof.UDP_header
259
        call    IPv4_output
259
        call    ipv4_output
260
        jz      .fail
260
        jz      .fail
261
        mov     [esp + 8], eax                                  ; pointer to buffer start
261
        mov     [esp + 8], eax                                  ; pointer to buffer start
Line 262... Line 262...
262
 
262
 
263
        mov     [edi + UDP_header.Length], cx
263
        mov     [edi + UDP_header.Length], cx
Line 277... Line 277...
277
        pop     dword [edi + UDP_header.SourcePort]
277
        pop     dword [edi + UDP_header.SourcePort]
Line 278... Line 278...
278
 
278
 
279
; Checksum
279
; Checksum
280
        mov     esi, edi
280
        mov     esi, edi
281
        mov     [edi + UDP_header.Checksum], 0
281
        mov     [edi + UDP_header.Checksum], 0
Line 282... Line 282...
282
        UDP_checksum (edi-4), (edi-8)                           ; FIXME: IPv4 packet could have options..
282
        udp_checksum (edi-4), (edi-8)                           ; FIXME: IPv4 packet could have options..
283
 
283
 
284
        DEBUGF  DEBUG_NETWORK_VERBOSE, "UDP_output: sending with device %x\n", ebx
284
        DEBUGF  DEBUG_NETWORK_VERBOSE, "UDP_output: sending with device %x\n", ebx
285
        call    [ebx + NET_DEVICE.transmit]
285
        call    [ebx + NET_DEVICE.transmit]
286
        test    eax, eax
286
        test    eax, eax
287
        jnz     @f
287
        jnz     @f
288
        call    NET_ptr_to_num4
288
        call    net_ptr_to_num4
Line 289... Line 289...
289
        inc     [UDP_PACKETS_TX + edi]
289
        inc     [UDP_PACKETS_TX + edi]
Line 300... Line 300...
300
 
300
 
301
 
301
 
302
 
302
 
303
;-----------------------------------------------------------------;
303
;-----------------------------------------------------------------;
304
;                                                                 ;
304
;                                                                 ;
305
; UDP_connect                                                     ;
305
; udp_connect                                                     ;
306
;                                                                 ;
306
;                                                                 ;
307
;   IN: eax = socket pointer                                      ;
307
;   IN: eax = socket pointer                                      ;
308
;                                                                 ;
308
;                                                                 ;
309
;  OUT: eax = 0 on success                                        ;
309
;  OUT: eax = 0 on success                                        ;
310
;       eax = -1 on error                                         ;
310
;       eax = -1 on error                                         ;
311
;       ebx = error code on error                                 ;
311
;       ebx = error code on error                                 ;
312
;                                                                 ;
312
;                                                                 ;
Line 313... Line 313...
313
;-----------------------------------------------------------------;
313
;-----------------------------------------------------------------;
314
align 4
314
align 4
315
UDP_connect:
315
udp_connect:
316
 
316
 
Line 317... Line 317...
317
        test    [eax + SOCKET.state], SS_ISCONNECTED
317
        test    [eax + SOCKET.state], SS_ISCONNECTED
318
        jz      @f
318
        jz      @f
319
        call    UDP_disconnect
319
        call    udp_disconnect
Line 338... Line 338...
338
        pop     [eax + IP_SOCKET.RemoteIP]
338
        pop     [eax + IP_SOCKET.RemoteIP]
Line 339... Line 339...
339
 
339
 
340
; Find a local port, if user didnt define one
340
; Find a local port, if user didnt define one
341
        cmp     [eax + UDP_SOCKET.LocalPort], 0
341
        cmp     [eax + UDP_SOCKET.LocalPort], 0
342
        jne     @f
342
        jne     @f
343
        call    SOCKET_find_port
343
        call    socket_find_port
Line 344... Line 344...
344
       @@:
344
       @@:
345
 
345
 
346
        push    eax
346
        push    eax
347
        lea     ecx, [eax + SOCKET.mutex]
347
        lea     ecx, [eax + SOCKET.mutex]
Line 348... Line 348...
348
        call    mutex_unlock
348
        call    mutex_unlock
Line 349... Line 349...
349
        pop     eax
349
        pop     eax
350
 
350
 
Line 362... Line 362...
362
;                                                                 ;
362
;                                                                 ;
363
;  OUT: eax = socket pointer                                      ;
363
;  OUT: eax = socket pointer                                      ;
364
;                                                                 ;
364
;                                                                 ;
365
;-----------------------------------------------------------------;
365
;-----------------------------------------------------------------;
366
align 4
366
align 4
367
UDP_disconnect:
367
udp_disconnect:
Line 368... Line 368...
368
 
368
 
Line 369... Line 369...
369
        ; TODO: remove the pending received data
369
        ; TODO: remove the pending received data
Line 370... Line 370...
370
 
370
 
Line 371... Line 371...
371
        call    SOCKET_is_disconnected
371
        call    socket_is_disconnected
372
 
372
 
373
        ret
373
        ret
374
 
374
 
375
 
375
 
376
 
376
 
377
 
377
 
378
 
378
 
379
;-----------------------------------------------------------------;
379
;-----------------------------------------------------------------;
380
;                                                                 ;
380
;                                                                 ;
381
; UDP_api: This function is called by system function 76          ;
381
; UDP_api: Part of system function 76                             ;
382
;                                                                 ;
382
;                                                                 ;
383
;  IN: bl = subfunction number in bl                              ;
383
;  IN: bl = subfunction number in bl                              ;
Line 384... Line 384...
384
;      bh = device number in bh                                   ;
384
;      bh = device number in bh                                   ;
385
;      ecx, edx, .. depends on subfunction                        ;
385
;      ecx, edx, .. depends on subfunction                        ;
Line 386... Line 386...
386
;                                                                 ;
386
;                                                                 ;