Subversion Repositories Kolibri OS

Rev

Rev 3600 | Rev 3610 | 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
 
3601 hidnplayr 23
        .device_type    dd NET_DEVICE_LOOPBACK
24
        .mtu            dd 4096
25
        .name           dd .namestr
3545 hidnplayr 26
 
3601 hidnplayr 27
        .unload         dd .dummy_fn
28
        .reset          dd .dummy_fn
29
        .transmit       dd LOOP_input
3545 hidnplayr 30
 
3601 hidnplayr 31
        .bytes_tx       dq 0
32
        .bytes_rx       dq 0
33
        .packets_tx     dd 0
34
        .packets_rx     dd 0
3545 hidnplayr 35
 
3601 hidnplayr 36
        .link_state     dd -1
37
        .hwacc          dd 0
3545 hidnplayr 38
 
3601 hidnplayr 39
        .namestr        db 'loopback', 0
40
 
3545 hidnplayr 41
        .dummy_fn:
42
                ret
43
 
44
endg
45
 
3601 hidnplayr 46
 
47
macro   LOOP_init {
48
local   .fail
49
 
50
        mov     ebx, LOOPBACK_DEVICE
51
        call    NET_add_device
52
 
53
        cmp     eax, -1
54
        je      .fail
55
 
56
        mov     [IP_LIST], 127 + 1 shl 24
57
        mov     [SUBNET_LIST], 255
58
        mov     [BROADCAST_LIST], 0xffffff00 + 127
59
 
60
  .fail:
61
}
62
 
3545 hidnplayr 63
;-----------------------------------------------------------------
64
;
65
; LOOP_input
66
;
3600 hidnplayr 67
;  IN:  [esp+4] = Pointer to buffer
3545 hidnplayr 68
;       [esp+8] = size of buffer
69
;
70
;  OUT: /
71
;
72
;-----------------------------------------------------------------
73
align 4
74
LOOP_input:
75
        pop     ebx
76
        pop     eax
77
        pop     ecx
78
 
79
        push    ebx
80
        push    ecx
81
        push    eax
82
 
3556 hidnplayr 83
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
3600 hidnplayr 84
        lea     edx, [eax + 4]
85
        mov     eax, dword[eax]
3545 hidnplayr 86
        mov     ebx, LOOPBACK_DEVICE
87
 
3600 hidnplayr 88
        cmp     eax, AF_INET4
3545 hidnplayr 89
        je      IPv4_input
90
 
3556 hidnplayr 91
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax
3545 hidnplayr 92
 
93
  .dump:
3556 hidnplayr 94
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
3545 hidnplayr 95
        call    kernel_free
96
        add     esp, 4
97
        ret
98
 
99
;-----------------------------------------------------------------
100
;
101
; LOOP_output
102
;
103
; IN:
104
;     ecx = packet size
105
;      di = protocol
106
;
107
; OUT: edi = 0 on error, pointer to buffer otherwise
108
;      eax = buffer start
109
;      ebx = to device structure
110
;      ecx = unchanged (packet size of embedded data)
111
;      edx = size of complete buffer
112
;
113
;-----------------------------------------------------------------
114
align 4
115
LOOP_output:
116
 
3556 hidnplayr 117
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
3545 hidnplayr 118
 
119
        push    ecx
3600 hidnplayr 120
        push    edi
3545 hidnplayr 121
 
3600 hidnplayr 122
        add     ecx, 4
3545 hidnplayr 123
        cmp     ecx, [LOOPBACK_DEVICE.mtu]
124
        ja      .out_of_ram
125
        stdcall kernel_alloc, ecx
126
        test    eax, eax
127
        jz      .out_of_ram
128
        mov     edi, eax
3600 hidnplayr 129
        pop     eax
130
        stosd
3545 hidnplayr 131
 
3600 hidnplayr 132
        lea     eax, [edi - 4]  ; Set eax to buffer start
3545 hidnplayr 133
        pop     ecx
3600 hidnplayr 134
        lea     edx, [ecx + 4]  ; Set edx to complete buffer size
3545 hidnplayr 135
        mov     ebx, LOOPBACK_DEVICE
136
 
137
  .done:
3556 hidnplayr 138
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
3545 hidnplayr 139
        ret
140
 
141
  .out_of_ram:
3556 hidnplayr 142
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: failed\n"
3600 hidnplayr 143
        add     esp, 4+4
144
        xor     edi, edi
3545 hidnplayr 145
        ret
146