Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1159 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
1514 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.    ;;
1159 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  ETHERNET.INC                                                   ;;
7
;;                                                                 ;;
8
;;  Ethernet network layer for KolibriOS                           ;;
9
;;                                                                 ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
11
;;                                                                 ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
 
1206 hidnplayr 17
$Revision: 2311 $
1159 hidnplayr 18
 
2311 hidnplayr 19
struct  ETH_header
2305 hidnplayr 20
 
2311 hidnplayr 21
        DstMAC          dp  ?  ; destination MAC-address
22
        SrcMAC          dp  ?  ; source MAC-address
23
        Type            dw  ?  ; type of the upper-layer protocol
2305 hidnplayr 24
 
1159 hidnplayr 25
ends
26
 
2311 hidnplayr 27
ETH_FRAME_MINIMUM       equ 60
2301 hidnplayr 28
 
2311 hidnplayr 29
struct  ETH_DEVICE      NET_DEVICE
1514 hidnplayr 30
 
2311 hidnplayr 31
        set_mode        dd ?
32
        get_mode        dd ?
1519 hidnplayr 33
 
2311 hidnplayr 34
        set_MAC         dd ?
35
        get_MAC         dd ?
1159 hidnplayr 36
 
2311 hidnplayr 37
        mode            dd ?
38
        mac             dp ?
1519 hidnplayr 39
 
2305 hidnplayr 40
ends
1159 hidnplayr 41
 
42
align 4
1196 hidnplayr 43
iglobal
44
 
2311 hidnplayr 45
        ETH_BROADCAST   dp  0xffffffffffff
1196 hidnplayr 46
endg
47
 
1257 hidnplayr 48
;-----------------------------------------------------------------
1159 hidnplayr 49
;
1529 hidnplayr 50
; ETH_input
1159 hidnplayr 51
;
52
;  This function is called by ethernet drivers,
53
;  It pushes the received ethernet packets onto the eth_in_queue
54
;
1514 hidnplayr 55
;  IN:   [esp]  = Pointer to buffer
1529 hidnplayr 56
;       [esp+4] = size of buffer
1514 hidnplayr 57
;         ebx   = pointer to eth_device
1159 hidnplayr 58
;  OUT: /
59
;
1257 hidnplayr 60
;-----------------------------------------------------------------
1159 hidnplayr 61
align 4
1529 hidnplayr 62
ETH_input:
2311 hidnplayr 63
        mov     eax, [esp]
64
        mov     ecx, [esp+4]
1249 hidnplayr 65
 
2311 hidnplayr 66
        DEBUGF  1,"ETH_input - size: %u\n", ecx
67
        cmp     ecx, ETH_FRAME_MINIMUM
68
        jb      .dump
69
        sub     ecx, sizeof.ETH_header
1159 hidnplayr 70
 
2311 hidnplayr 71
        lea     edx, [eax + sizeof.ETH_header]
72
        mov     ax , [eax + ETH_header.Type]
1159 hidnplayr 73
 
2311 hidnplayr 74
        cmp     ax, ETHER_IPv4
75
        je      IPv4_input
1159 hidnplayr 76
 
2311 hidnplayr 77
        cmp     ax, ETHER_ARP
78
        je      ARP_input
1159 hidnplayr 79
 
1519 hidnplayr 80
;        cmp     ax, ETHER_PPP_DISCOVERY
81
;        je      PPPOE_discovery
82
 
2311 hidnplayr 83
        DEBUGF  2,"Unknown ethernet packet type %x\n", ax
1159 hidnplayr 84
 
85
  .dump:
2311 hidnplayr 86
        DEBUGF  2,"ETH_input - dumping\n"
87
        call    kernel_free
88
        add     esp, 4
89
        ret
1159 hidnplayr 90
 
1249 hidnplayr 91
;-----------------------------------------------------------------
92
;
1529 hidnplayr 93
; ETH_output
1159 hidnplayr 94
;
1514 hidnplayr 95
; IN: eax = pointer to source mac
1529 hidnplayr 96
;     ebx = device ptr
1514 hidnplayr 97
;     ecx = packet size
1529 hidnplayr 98
;     edx = pointer to destination mac
1514 hidnplayr 99
;      di = protocol
1159 hidnplayr 100
;
1514 hidnplayr 101
; OUT: edi = 0 on error, pointer to buffer otherwise
102
;      eax = buffer start
103
;      ebx = to device structure
104
;      ecx = unchanged (packet size of embedded data)
105
;      edx = size of complete buffer
1159 hidnplayr 106
;
1257 hidnplayr 107
;-----------------------------------------------------------------
1159 hidnplayr 108
align 4
1529 hidnplayr 109
ETH_output:
1159 hidnplayr 110
 
2311 hidnplayr 111
        DEBUGF  1,"ETH_output: size=%u device:%x\n", ecx, ebx
1159 hidnplayr 112
 
2311 hidnplayr 113
        cmp     ecx, [ebx + NET_DEVICE.mtu]
114
        ja      .exit
1159 hidnplayr 115
 
2311 hidnplayr 116
        push    ecx
117
        push    di eax edx
1159 hidnplayr 118
 
2311 hidnplayr 119
        add     ecx, sizeof.ETH_header
120
        stdcall kernel_alloc, ecx
121
        test    eax, eax
122
        jz      .out_of_ram
123
        mov     edi, eax
1529 hidnplayr 124
 
2311 hidnplayr 125
        pop     esi
126
        movsd
127
        movsw
128
        pop     esi
129
        movsd
130
        movsw
131
        pop     ax
132
        stosw
1159 hidnplayr 133
 
2311 hidnplayr 134
        lea     eax, [edi - sizeof.ETH_header]  ; Set eax to buffer start
135
        pop     ecx
136
        lea     edx, [ecx + sizeof.ETH_header]  ; Set edx to complete buffer size
1159 hidnplayr 137
 
2311 hidnplayr 138
        cmp     edx, ETH_FRAME_MINIMUM
139
        jb      .adjust_size
140
        DEBUGF  1,"ETH_output: done: %x total size: %u\n", eax, edx
141
        ret
1159 hidnplayr 142
 
1529 hidnplayr 143
  .adjust_size:
2311 hidnplayr 144
        mov     edx, ETH_FRAME_MINIMUM
145
        test    edx, edx        ; clear zero flag
146
        ret
1159 hidnplayr 147
 
1529 hidnplayr 148
  .out_of_ram:
2311 hidnplayr 149
        DEBUGF  2,"ETH_output: Out of ram space!!\n"
150
        add     esp, 4+4+2+4
151
        sub     edi, edi
152
        ret
1206 hidnplayr 153
 
1159 hidnplayr 154
  .exit:
2311 hidnplayr 155
        DEBUGF  2,"ETH_output: Packet too large!\n"
156
        sub     edi, edi
157
        ret
1159 hidnplayr 158
 
159
 
160
 
1257 hidnplayr 161
;-----------------------------------------------------------------
1159 hidnplayr 162
;
163
; ETH_API
164
;
165
; This function is called by system function 75
166
;
167
; IN:  subfunction number in bl
168
;      device number in bh
169
;      ecx, edx, .. depends on subfunction
170
;
171
; OUT:
172
;
1257 hidnplayr 173
;-----------------------------------------------------------------
1159 hidnplayr 174
align 4
175
ETH_API:
176
 
2311 hidnplayr 177
        cmp     bh, MAX_NET_DEVICES
178
        ja      .error
179
        movzx   eax, bh
180
        shl     eax, 2
1159 hidnplayr 181
 
2311 hidnplayr 182
        mov     eax, dword [NET_DRV_LIST + eax]
183
        cmp     [eax + NET_DEVICE.type], NET_TYPE_ETH
184
        jne     .error
1514 hidnplayr 185
 
2311 hidnplayr 186
        test    bl, bl
187
        jz      .packets_tx     ; 0
188
        dec     bl
189
        jz      .packets_rx     ; 1
190
        dec     bl
191
        jz      .bytes_tx       ; 2
192
        dec     bl
193
        jz      .bytes_rx       ; 3
194
        dec     bl
195
        jz      .read_mac       ; 4
196
        dec     bl
197
        jz      .write_mac      ; 5
1159 hidnplayr 198
 
1514 hidnplayr 199
  .error:
2311 hidnplayr 200
        DEBUGF  2,"Device is not ethernet type\n"
201
        or      eax, -1
202
        ret
1159 hidnplayr 203
 
204
.packets_tx:
2311 hidnplayr 205
        mov     eax, [eax + NET_DEVICE.packets_tx]
1171 hidnplayr 206
 
2311 hidnplayr 207
        ret
1159 hidnplayr 208
 
209
.packets_rx:
2311 hidnplayr 210
        mov     eax, [eax + NET_DEVICE.packets_rx]
211
        ret
1159 hidnplayr 212
 
213
.bytes_tx:
2311 hidnplayr 214
        mov     ebx, dword [eax + NET_DEVICE.bytes_tx + 4]
215
        mov     eax, dword [eax + NET_DEVICE.bytes_tx]
216
        mov     [esp+20+4], ebx                         ; TODO: fix this ugly code
217
        ret
1159 hidnplayr 218
 
219
.bytes_rx:
2311 hidnplayr 220
        mov     ebx, dword [eax + NET_DEVICE.bytes_rx + 4]
221
        mov     eax, dword [eax + NET_DEVICE.bytes_rx]
222
        mov     [esp+20+4], ebx                         ; TODO: fix this ugly code
223
        ret
1159 hidnplayr 224
 
1174 hidnplayr 225
 
1159 hidnplayr 226
.read_mac:
2311 hidnplayr 227
        movzx   ebx, word [eax + ETH_DEVICE.mac]
228
        mov     eax, dword [eax + ETH_DEVICE.mac + 2]
229
        mov     [esp+20+4], ebx                         ; TODO: fix this ugly code
230
        ret
1159 hidnplayr 231
 
232
.write_mac:
2311 hidnplayr 233
        push    ecx
234
        push    dx
235
        call    [eax + ETH_DEVICE.set_MAC]
236
        ret
1159 hidnplayr 237