Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3610 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
3545 hidnplayr 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
 
3610 hidnplayr 83
        inc     [LOOPBACK_DEVICE.packets_rx]
84
        add     dword[LOOPBACK_DEVICE.bytes_rx], ecx
85
        adc     dword[LOOPBACK_DEVICE.bytes_rx + 4], 0
86
 
3556 hidnplayr 87
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
3600 hidnplayr 88
        lea     edx, [eax + 4]
89
        mov     eax, dword[eax]
3545 hidnplayr 90
        mov     ebx, LOOPBACK_DEVICE
91
 
3600 hidnplayr 92
        cmp     eax, AF_INET4
3545 hidnplayr 93
        je      IPv4_input
94
 
3556 hidnplayr 95
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax
3545 hidnplayr 96
 
97
  .dump:
3556 hidnplayr 98
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
3545 hidnplayr 99
        call    kernel_free
100
        add     esp, 4
101
        ret
102
 
103
;-----------------------------------------------------------------
104
;
105
; LOOP_output
106
;
107
; IN:
3610 hidnplayr 108
;       ecx = packet size
109
;       edi = address family
3545 hidnplayr 110
;
3610 hidnplayr 111
; OUT:  edi = 0 on error, pointer to buffer otherwise
112
;       eax = buffer start
113
;       ebx = to device structure
114
;       ecx = unchanged (packet size of embedded data)
115
;       edx = size of complete buffer
3545 hidnplayr 116
;
117
;-----------------------------------------------------------------
118
align 4
119
LOOP_output:
120
 
3556 hidnplayr 121
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
3545 hidnplayr 122
 
123
        push    ecx
3600 hidnplayr 124
        push    edi
3545 hidnplayr 125
 
3600 hidnplayr 126
        add     ecx, 4
3545 hidnplayr 127
        cmp     ecx, [LOOPBACK_DEVICE.mtu]
128
        ja      .out_of_ram
129
        stdcall kernel_alloc, ecx
130
        test    eax, eax
131
        jz      .out_of_ram
132
        mov     edi, eax
3600 hidnplayr 133
        pop     eax
134
        stosd
3545 hidnplayr 135
 
3600 hidnplayr 136
        lea     eax, [edi - 4]  ; Set eax to buffer start
3545 hidnplayr 137
        pop     ecx
3600 hidnplayr 138
        lea     edx, [ecx + 4]  ; Set edx to complete buffer size
3545 hidnplayr 139
        mov     ebx, LOOPBACK_DEVICE
140
 
3610 hidnplayr 141
        inc     [LOOPBACK_DEVICE.packets_tx]
142
        add     dword[LOOPBACK_DEVICE.bytes_tx], ecx
143
        adc     dword[LOOPBACK_DEVICE.bytes_tx + 4], 0
144
 
3556 hidnplayr 145
        DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
3545 hidnplayr 146
        ret
147
 
148
  .out_of_ram:
3610 hidnplayr 149
        DEBUGF  DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n"
3600 hidnplayr 150
        add     esp, 4+4
151
        xor     edi, edi
3545 hidnplayr 152
        ret
153