2009-09-17 13:55:38 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2010-07-12 01:13:12 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
|
2009-09-17 13:55:38 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; ETHERNET.INC ;;
|
|
|
|
;; ;;
|
|
|
|
;; Ethernet network layer for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2009-10-12 16:39:59 +02:00
|
|
|
$Revision$
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
struct ETH_FRAME
|
2010-07-12 01:13:12 +02:00
|
|
|
.DstMAC dp ? ; destination MAC-address
|
|
|
|
.SrcMAC dp ? ; source MAC-address
|
|
|
|
.Type dw ? ; type of the upper-layer protocol
|
|
|
|
.Data: ; data (46-1500 bytes for a normal packet)
|
2009-09-17 13:55:38 +02:00
|
|
|
ends
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
virtual at NET_DEVICE.end
|
|
|
|
|
|
|
|
ETH_DEVICE:
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
.set_mode dd ?
|
|
|
|
.get_mode dd ?
|
|
|
|
|
2010-07-15 20:54:19 +02:00
|
|
|
.set_MAC dd ?
|
|
|
|
.get_MAC dd ?
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
.mode dd ?
|
2009-09-17 13:55:38 +02:00
|
|
|
.mac dp ?
|
2009-11-15 22:44:17 +01:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
end virtual
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-10-05 22:47:27 +02:00
|
|
|
align 4
|
|
|
|
iglobal
|
|
|
|
|
|
|
|
ETH_BROADCAST dp 0xffffffffffff
|
|
|
|
endg
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
align 4
|
|
|
|
uglobal
|
|
|
|
ETH_RUNNING dd ?
|
|
|
|
endg
|
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; ETH_init
|
|
|
|
;
|
|
|
|
; This function resets all ethernet variables
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2010-07-27 20:53:38 +02:00
|
|
|
macro ETH_init {
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
mov [ETH_RUNNING], 0
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
}
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-27 20:53:38 +02:00
|
|
|
; ETH_input
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; This function is called by ethernet drivers,
|
|
|
|
; It pushes the received ethernet packets onto the eth_in_queue
|
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; IN: [esp] = Pointer to buffer
|
2010-07-27 20:53:38 +02:00
|
|
|
; [esp+4] = size of buffer
|
2010-07-12 01:13:12 +02:00
|
|
|
; ebx = pointer to eth_device
|
2009-09-17 13:55:38 +02:00
|
|
|
; OUT: /
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
align 4
|
2010-07-27 20:53:38 +02:00
|
|
|
ETH_input:
|
2010-05-28 22:47:32 +02:00
|
|
|
mov eax, [esp]
|
|
|
|
mov ecx, [esp+4]
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
DEBUGF 1,"ETH_input - size: %u\n", ecx
|
2009-09-17 13:55:38 +02:00
|
|
|
cmp ecx, 60 ; check packet length
|
|
|
|
jl .dump
|
|
|
|
sub ecx, ETH_FRAME.Data
|
|
|
|
|
|
|
|
lea edx, [eax + ETH_FRAME.Data]
|
|
|
|
mov ax , [eax + ETH_FRAME.Type]
|
|
|
|
|
|
|
|
cmp ax, ETHER_IPv4
|
2010-07-27 20:53:38 +02:00
|
|
|
je IPv4_input
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
cmp ax, ETHER_ARP
|
2010-07-27 20:53:38 +02:00
|
|
|
je ARP_input
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-15 20:54:19 +02:00
|
|
|
; cmp ax, ETHER_PPP_DISCOVERY
|
|
|
|
; je PPPOE_discovery
|
|
|
|
|
2010-05-28 22:47:32 +02:00
|
|
|
DEBUGF 2,"Unknown ethernet packet type %x\n", ax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.dump:
|
2010-07-27 20:53:38 +02:00
|
|
|
DEBUGF 2,"ETH_input - dumping\n"
|
2009-09-17 13:55:38 +02:00
|
|
|
call kernel_free
|
|
|
|
add esp, 4
|
|
|
|
ret
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-27 20:53:38 +02:00
|
|
|
; ETH_output
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; IN: eax = pointer to source mac
|
2010-07-27 20:53:38 +02:00
|
|
|
; ebx = device ptr
|
2010-07-12 01:13:12 +02:00
|
|
|
; ecx = packet size
|
2010-07-27 20:53:38 +02:00
|
|
|
; edx = pointer to destination mac
|
2010-07-12 01:13:12 +02:00
|
|
|
; di = protocol
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; OUT: edi = 0 on error, pointer to buffer otherwise
|
|
|
|
; eax = buffer start
|
|
|
|
; ebx = to device structure
|
|
|
|
; ecx = unchanged (packet size of embedded data)
|
|
|
|
; edx = size of complete buffer
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
align 4
|
2010-07-27 20:53:38 +02:00
|
|
|
ETH_output:
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
DEBUGF 1,"ETH_output: size=%u device:%x\n", ecx, ebx
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
cmp ecx, [ebx + NET_DEVICE.mtu]
|
2009-09-17 13:55:38 +02:00
|
|
|
jg .exit
|
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
push ecx ; << 1
|
|
|
|
push di eax edx ; << 2
|
2009-09-17 13:55:38 +02:00
|
|
|
add ecx, ETH_FRAME.Data
|
2010-07-27 20:53:38 +02:00
|
|
|
|
|
|
|
push ecx ; << 3
|
|
|
|
|
|
|
|
push ecx ; << 4
|
|
|
|
call kernel_alloc ; >> 4
|
|
|
|
test eax, eax
|
|
|
|
jz .out_of_ram
|
2010-07-12 01:13:12 +02:00
|
|
|
mov edi, eax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
pop ecx ; >> 3
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
pop esi ; >> 2
|
2009-09-17 13:55:38 +02:00
|
|
|
movsd
|
|
|
|
movsw
|
2010-07-27 20:53:38 +02:00
|
|
|
pop esi ; >> 2
|
2009-09-17 13:55:38 +02:00
|
|
|
movsd
|
|
|
|
movsw
|
2010-07-27 20:53:38 +02:00
|
|
|
pop ax ; >> 2
|
2009-09-17 13:55:38 +02:00
|
|
|
stosw
|
|
|
|
|
|
|
|
lea eax, [edi - ETH_FRAME.Data] ; Set eax to buffer start
|
2010-07-27 20:53:38 +02:00
|
|
|
mov edx, ecx ; Set edx to complete buffer size
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
pop ecx ; >> 1
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
cmp edx, 60-1 ; minimum ethernet packet size
|
|
|
|
jle .adjust_size
|
|
|
|
DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx
|
|
|
|
ret
|
2009-10-12 16:39:59 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
.adjust_size:
|
|
|
|
mov edx, 60
|
2010-07-30 11:09:06 +02:00
|
|
|
test edx, edx ; clear zero flag
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
.out_of_ram:
|
|
|
|
DEBUGF 2,"ETH_output: Out of ram space!!\n"
|
|
|
|
add esp, 3*4+2+4
|
|
|
|
sub edi, edi
|
2009-10-12 16:39:59 +02:00
|
|
|
ret
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
.exit:
|
2010-07-27 20:53:38 +02:00
|
|
|
DEBUGF 2,"ETH_output: Packet too large!\n"
|
|
|
|
sub edi, edi
|
|
|
|
;;; dec edi
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; ETH_API
|
|
|
|
;
|
|
|
|
; This function is called by system function 75
|
|
|
|
;
|
|
|
|
; IN: subfunction number in bl
|
|
|
|
; device number in bh
|
|
|
|
; ecx, edx, .. depends on subfunction
|
|
|
|
;
|
|
|
|
; OUT:
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
align 4
|
|
|
|
ETH_API:
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
cmp bh, MAX_NET_DEVICES
|
|
|
|
jg .error
|
2009-09-17 13:55:38 +02:00
|
|
|
movzx eax, bh
|
|
|
|
shl eax, 2
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
cmp bl, 7
|
|
|
|
jz .out_queue
|
|
|
|
cmp bl, 6
|
|
|
|
jz .in_queue
|
|
|
|
|
|
|
|
mov eax, dword [NET_DRV_LIST + eax]
|
|
|
|
cmp [eax + NET_DEVICE.type], NET_TYPE_ETH
|
|
|
|
jne .error
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
test bl, bl
|
|
|
|
jz .packets_tx ; 0
|
|
|
|
dec bl
|
|
|
|
jz .packets_rx ; 1
|
|
|
|
dec bl
|
|
|
|
jz .bytes_tx ; 2
|
|
|
|
dec bl
|
|
|
|
jz .bytes_rx ; 3
|
|
|
|
dec bl
|
|
|
|
jz .read_mac ; 4
|
|
|
|
dec bl
|
|
|
|
jz .write_mac ; 5
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
.error:
|
|
|
|
DEBUGF 2,"Device is not ethernet type\n"
|
|
|
|
or eax, -1
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.packets_tx:
|
2010-07-15 20:54:19 +02:00
|
|
|
mov eax, dword [eax + NET_DEVICE.packets_tx]
|
2009-09-22 18:42:54 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.packets_rx:
|
2010-07-15 20:54:19 +02:00
|
|
|
mov eax, dword [eax + NET_DEVICE.packets_rx]
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.bytes_tx:
|
2010-07-15 20:54:19 +02:00
|
|
|
mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4]
|
|
|
|
mov eax, dword [eax + NET_DEVICE.bytes_tx]
|
2009-09-24 20:32:03 +02:00
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.bytes_rx:
|
2010-07-15 20:54:19 +02:00
|
|
|
mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4]
|
|
|
|
mov eax, dword [eax + NET_DEVICE.bytes_rx]
|
2009-09-24 20:32:03 +02:00
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
2009-09-24 20:32:03 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
.read_mac:
|
|
|
|
movzx ebx, word [eax + ETH_DEVICE.mac]
|
|
|
|
mov eax, dword [eax + ETH_DEVICE.mac + 2]
|
2009-09-22 18:42:54 +02:00
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.write_mac:
|
|
|
|
push ecx
|
|
|
|
push dx
|
2010-07-15 20:54:19 +02:00
|
|
|
call [eax + ETH_DEVICE.set_MAC]
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.in_queue:
|
2010-07-12 01:13:12 +02:00
|
|
|
if ETH_QUEUE
|
2009-09-17 13:55:38 +02:00
|
|
|
add eax, ETH_IN_QUEUE
|
|
|
|
mov eax, [eax + queue.size]
|
2010-07-12 01:13:12 +02:00
|
|
|
else
|
|
|
|
or eax, -1
|
|
|
|
end if
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.out_queue:
|
2010-07-12 01:13:12 +02:00
|
|
|
if ETH_QUEUE
|
2009-09-17 13:55:38 +02:00
|
|
|
add eax, ETH_OUT_QUEUE
|
|
|
|
mov eax, [eax + queue.size]
|
2010-07-12 01:13:12 +02:00
|
|
|
else
|
|
|
|
or eax, -1
|
|
|
|
end if
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|