Subversion Repositories Kolibri OS

Rev

Rev 3556 | Rev 3601 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  loopback.inc                                                   ;;
7
;;                                                                 ;;
8
;;  LoopBack device for KolibriOS                                  ;;
9
;;                                                                 ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
11
;;                                                                 ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
 
17
$Revision: 2891 $
18
 
19
iglobal
20
 
21
LOOPBACK_DEVICE:
3600 hidnplayr 22
 
23
        .device_type     dd NET_DEVICE_LOOPBACK
3545 hidnplayr 24
        .mtu             dd 4096
25
        .name            dd .namestr
26
 
27
        .unload          dd .dummy_fn
28
        .reset           dd .dummy_fn
29
        .transmit        dd LOOP_input
30
 
31
        .bytes_tx        dq 0
32
        .bytes_rx        dq 0
33
        .packets_tx      dd 0
34
        .packets_rx      dd 0
35
 
36
        .namestr         db 'loopback', 0
37
 
38
        .dummy_fn:
39
                ret
40
 
41
endg
42
 
43
;-----------------------------------------------------------------
44
;
45
; LOOP_input
46
;
3600 hidnplayr 47
;  IN:  [esp+4] = Pointer to buffer
3545 hidnplayr 48
;       [esp+8] = size of buffer
49
;
50
;  OUT: /
51
;
52
;-----------------------------------------------------------------
53
align 4
54
LOOP_input:
55
        pop     ebx
56
        pop     eax
57
        pop     ecx
58
 
59
        push    ebx
60
        push    ecx
61
        push    eax
62
 
3556 hidnplayr 63
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
3600 hidnplayr 64
        lea     edx, [eax + 4]
65
        mov     eax, dword[eax]
3545 hidnplayr 66
        mov     ebx, LOOPBACK_DEVICE
67
 
3600 hidnplayr 68
        cmp     eax, AF_INET4
3545 hidnplayr 69
        je      IPv4_input
70
 
3556 hidnplayr 71
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax
3545 hidnplayr 72
 
73
  .dump:
3556 hidnplayr 74
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
3545 hidnplayr 75
        call    kernel_free
76
        add     esp, 4
77
        ret
78
 
79
;-----------------------------------------------------------------
80
;
81
; LOOP_output
82
;
83
; IN:
84
;     ecx = packet size
85
;      di = protocol
86
;
87
; OUT: edi = 0 on error, pointer to buffer otherwise
88
;      eax = buffer start
89
;      ebx = to device structure
90
;      ecx = unchanged (packet size of embedded data)
91
;      edx = size of complete buffer
92
;
93
;-----------------------------------------------------------------
94
align 4
95
LOOP_output:
96
 
3556 hidnplayr 97
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
3545 hidnplayr 98
 
99
        push    ecx
3600 hidnplayr 100
        push    edi
3545 hidnplayr 101
 
3600 hidnplayr 102
        add     ecx, 4
3545 hidnplayr 103
        cmp     ecx, [LOOPBACK_DEVICE.mtu]
104
        ja      .out_of_ram
105
        stdcall kernel_alloc, ecx
106
        test    eax, eax
107
        jz      .out_of_ram
108
        mov     edi, eax
3600 hidnplayr 109
        pop     eax
110
        stosd
3545 hidnplayr 111
 
3600 hidnplayr 112
        lea     eax, [edi - 4]  ; Set eax to buffer start
3545 hidnplayr 113
        pop     ecx
3600 hidnplayr 114
        lea     edx, [ecx + 4]  ; Set edx to complete buffer size
3545 hidnplayr 115
        mov     ebx, LOOPBACK_DEVICE
116
 
117
  .done:
3556 hidnplayr 118
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
3545 hidnplayr 119
        ret
120
 
121
  .out_of_ram:
3556 hidnplayr 122
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: failed\n"
3600 hidnplayr 123
        add     esp, 4+4
124
        xor     edi, edi
3545 hidnplayr 125
        ret
126