2009-09-17 15:55:38 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2010-07-12 03:13:12 +04:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
|
2009-09-17 15:55:38 +04: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 18:39:59 +04:00
|
|
|
$Revision$
|
2009-09-17 15:55:38 +04:00
|
|
|
|
|
|
|
struct ETH_FRAME
|
2010-07-12 03:13:12 +04: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 15:55:38 +04:00
|
|
|
ends
|
|
|
|
|
2010-07-12 03:13:12 +04:00
|
|
|
virtual at NET_DEVICE.end
|
|
|
|
|
|
|
|
ETH_DEVICE:
|
2010-07-15 22:54:19 +04:00
|
|
|
|
2009-09-17 15:55:38 +04:00
|
|
|
.set_mode dd ?
|
|
|
|
.get_mode dd ?
|
|
|
|
|
2010-07-15 22:54:19 +04:00
|
|
|
.set_MAC dd ?
|
|
|
|
.get_MAC dd ?
|
|
|
|
|
2010-07-12 03:13:12 +04:00
|
|
|
.mode dd ?
|
2009-09-17 15:55:38 +04:00
|
|
|
.mac dp ?
|
2009-11-16 00:44:17 +03:00
|
|
|
|
2010-07-12 03:13:12 +04:00
|
|
|
end virtual
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2009-10-06 00:47:27 +04:00
|
|
|
align 4
|
|
|
|
iglobal
|
|
|
|
|
|
|
|
ETH_BROADCAST dp 0xffffffffffff
|
|
|
|
endg
|
|
|
|
|
2009-11-09 16:59:46 +03:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 15:55:38 +04:00
|
|
|
;
|
2010-07-27 22:53:38 +04:00
|
|
|
; ETH_input
|
2009-09-17 15:55:38 +04:00
|
|
|
;
|
|
|
|
; This function is called by ethernet drivers,
|
|
|
|
; It pushes the received ethernet packets onto the eth_in_queue
|
|
|
|
;
|
2010-07-12 03:13:12 +04:00
|
|
|
; IN: [esp] = Pointer to buffer
|
2010-07-27 22:53:38 +04:00
|
|
|
; [esp+4] = size of buffer
|
2010-07-12 03:13:12 +04:00
|
|
|
; ebx = pointer to eth_device
|
2009-09-17 15:55:38 +04:00
|
|
|
; OUT: /
|
|
|
|
;
|
2009-11-09 16:59:46 +03:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 15:55:38 +04:00
|
|
|
align 4
|
2010-07-27 22:53:38 +04:00
|
|
|
ETH_input:
|
2010-05-29 00:47:32 +04:00
|
|
|
mov eax, [esp]
|
|
|
|
mov ecx, [esp+4]
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
DEBUGF 1,"ETH_input - size: %u\n", ecx
|
2009-09-17 15:55:38 +04:00
|
|
|
cmp ecx, 60 ; check packet length
|
2011-11-08 00:25:47 +04:00
|
|
|
jb .dump
|
2009-09-17 15:55:38 +04:00
|
|
|
sub ecx, ETH_FRAME.Data
|
|
|
|
|
|
|
|
lea edx, [eax + ETH_FRAME.Data]
|
|
|
|
mov ax , [eax + ETH_FRAME.Type]
|
|
|
|
|
|
|
|
cmp ax, ETHER_IPv4
|
2010-07-27 22:53:38 +04:00
|
|
|
je IPv4_input
|
2009-09-17 15:55:38 +04:00
|
|
|
|
|
|
|
cmp ax, ETHER_ARP
|
2010-07-27 22:53:38 +04:00
|
|
|
je ARP_input
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-15 22:54:19 +04:00
|
|
|
; cmp ax, ETHER_PPP_DISCOVERY
|
|
|
|
; je PPPOE_discovery
|
|
|
|
|
2010-05-29 00:47:32 +04:00
|
|
|
DEBUGF 2,"Unknown ethernet packet type %x\n", ax
|
2009-09-17 15:55:38 +04:00
|
|
|
|
|
|
|
.dump:
|
2010-07-27 22:53:38 +04:00
|
|
|
DEBUGF 2,"ETH_input - dumping\n"
|
2009-09-17 15:55:38 +04:00
|
|
|
call kernel_free
|
|
|
|
add esp, 4
|
|
|
|
ret
|
|
|
|
|
2009-11-09 16:59:46 +03:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 15:55:38 +04:00
|
|
|
;
|
2010-07-27 22:53:38 +04:00
|
|
|
; ETH_output
|
2009-09-17 15:55:38 +04:00
|
|
|
;
|
2010-07-12 03:13:12 +04:00
|
|
|
; IN: eax = pointer to source mac
|
2010-07-27 22:53:38 +04:00
|
|
|
; ebx = device ptr
|
2010-07-12 03:13:12 +04:00
|
|
|
; ecx = packet size
|
2010-07-27 22:53:38 +04:00
|
|
|
; edx = pointer to destination mac
|
2010-07-12 03:13:12 +04:00
|
|
|
; di = protocol
|
2009-09-17 15:55:38 +04:00
|
|
|
;
|
2010-07-12 03:13:12 +04: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 15:55:38 +04:00
|
|
|
;
|
2009-11-09 16:59:46 +03:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 15:55:38 +04:00
|
|
|
align 4
|
2010-07-27 22:53:38 +04:00
|
|
|
ETH_output:
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
DEBUGF 1,"ETH_output: size=%u device:%x\n", ecx, ebx
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
cmp ecx, [ebx + NET_DEVICE.mtu]
|
2011-11-08 00:25:47 +04:00
|
|
|
ja .exit
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
push ecx ; << 1
|
|
|
|
push di eax edx ; << 2
|
2009-09-17 15:55:38 +04:00
|
|
|
add ecx, ETH_FRAME.Data
|
2010-07-27 22:53:38 +04:00
|
|
|
|
|
|
|
push ecx ; << 3
|
|
|
|
|
|
|
|
push ecx ; << 4
|
|
|
|
call kernel_alloc ; >> 4
|
|
|
|
test eax, eax
|
|
|
|
jz .out_of_ram
|
2010-07-12 03:13:12 +04:00
|
|
|
mov edi, eax
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
pop ecx ; >> 3
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
pop esi ; >> 2
|
2009-09-17 15:55:38 +04:00
|
|
|
movsd
|
|
|
|
movsw
|
2010-07-27 22:53:38 +04:00
|
|
|
pop esi ; >> 2
|
2009-09-17 15:55:38 +04:00
|
|
|
movsd
|
|
|
|
movsw
|
2010-07-27 22:53:38 +04:00
|
|
|
pop ax ; >> 2
|
2009-09-17 15:55:38 +04:00
|
|
|
stosw
|
|
|
|
|
|
|
|
lea eax, [edi - ETH_FRAME.Data] ; Set eax to buffer start
|
2010-07-27 22:53:38 +04:00
|
|
|
mov edx, ecx ; Set edx to complete buffer size
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
pop ecx ; >> 1
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-08 00:25:47 +04:00
|
|
|
cmp edx, 60 ; minimum ethernet packet size
|
|
|
|
jb .adjust_size
|
2010-07-27 22:53:38 +04:00
|
|
|
DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx
|
|
|
|
ret
|
2009-10-12 18:39:59 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
.adjust_size:
|
|
|
|
mov edx, 60
|
2010-07-30 13:09:06 +04:00
|
|
|
test edx, edx ; clear zero flag
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|
2010-07-27 22:53:38 +04: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 18:39:59 +04:00
|
|
|
ret
|
|
|
|
|
2009-09-17 15:55:38 +04:00
|
|
|
.exit:
|
2010-07-27 22:53:38 +04:00
|
|
|
DEBUGF 2,"ETH_output: Packet too large!\n"
|
|
|
|
sub edi, edi
|
|
|
|
;;; dec edi
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-09 16:59:46 +03:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 15:55:38 +04: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 16:59:46 +03:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 15:55:38 +04:00
|
|
|
align 4
|
|
|
|
ETH_API:
|
|
|
|
|
2010-07-12 03:13:12 +04:00
|
|
|
cmp bh, MAX_NET_DEVICES
|
2011-11-08 00:25:47 +04:00
|
|
|
ja .error
|
2009-09-17 15:55:38 +04:00
|
|
|
movzx eax, bh
|
|
|
|
shl eax, 2
|
|
|
|
|
2010-07-12 03:13:12 +04:00
|
|
|
mov eax, dword [NET_DRV_LIST + eax]
|
|
|
|
cmp [eax + NET_DEVICE.type], NET_TYPE_ETH
|
|
|
|
jne .error
|
|
|
|
|
2009-09-17 15:55:38 +04: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 03:13:12 +04:00
|
|
|
.error:
|
|
|
|
DEBUGF 2,"Device is not ethernet type\n"
|
|
|
|
or eax, -1
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
.packets_tx:
|
2010-07-15 22:54:19 +04:00
|
|
|
mov eax, dword [eax + NET_DEVICE.packets_tx]
|
2009-09-22 20:42:54 +04:00
|
|
|
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
.packets_rx:
|
2010-07-15 22:54:19 +04:00
|
|
|
mov eax, dword [eax + NET_DEVICE.packets_rx]
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
.bytes_tx:
|
2010-07-15 22:54:19 +04:00
|
|
|
mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4]
|
|
|
|
mov eax, dword [eax + NET_DEVICE.bytes_tx]
|
2009-09-24 22:32:03 +04:00
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
.bytes_rx:
|
2010-07-15 22:54:19 +04:00
|
|
|
mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4]
|
|
|
|
mov eax, dword [eax + NET_DEVICE.bytes_rx]
|
2009-09-24 22:32:03 +04:00
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|
2009-09-24 22:32:03 +04:00
|
|
|
|
2009-09-17 15:55:38 +04:00
|
|
|
.read_mac:
|
|
|
|
movzx ebx, word [eax + ETH_DEVICE.mac]
|
|
|
|
mov eax, dword [eax + ETH_DEVICE.mac + 2]
|
2009-09-22 20:42:54 +04:00
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
.write_mac:
|
|
|
|
push ecx
|
|
|
|
push dx
|
2010-07-15 22:54:19 +04:00
|
|
|
call [eax + ETH_DEVICE.set_MAC]
|
2009-09-17 15:55:38 +04:00
|
|
|
ret
|
|
|
|
|