Subversion Repositories Kolibri OS

Rev

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