2009-09-17 15:55:38 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2013-01-18 18:32:05 +04:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2013. 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
|
|
|
|
2012-06-03 23:28:01 +04:00
|
|
|
ETH_FRAME_MINIMUM = 60
|
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
struct ETH_header
|
2011-11-09 03:06:26 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
DstMAC dp ? ; destination MAC-address
|
|
|
|
SrcMAC dp ? ; source MAC-address
|
|
|
|
Type dw ? ; type of the upper-layer protocol
|
2011-11-09 03:06:26 +04:00
|
|
|
|
2009-09-17 15:55:38 +04:00
|
|
|
ends
|
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
struct ETH_DEVICE NET_DEVICE
|
2010-07-12 03:13:12 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
mac dp ?
|
2010-07-15 22:54:19 +04:00
|
|
|
|
2011-11-09 03:06:26 +04:00
|
|
|
ends
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2009-10-06 00:47:27 +04:00
|
|
|
align 4
|
|
|
|
iglobal
|
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
ETH_BROADCAST dp 0xffffffffffff
|
2009-10-06 00:47:27 +04:00
|
|
|
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:
|
2011-11-13 02:35:01 +04:00
|
|
|
mov eax, [esp]
|
|
|
|
mov ecx, [esp+4]
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2012-07-27 03:21:35 +04:00
|
|
|
DEBUGF 1,"ETH_input: size=%u\n", ecx
|
2011-11-13 02:35:01 +04:00
|
|
|
cmp ecx, ETH_FRAME_MINIMUM
|
|
|
|
jb .dump
|
|
|
|
sub ecx, sizeof.ETH_header
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
lea edx, [eax + sizeof.ETH_header]
|
2012-06-03 23:28:01 +04:00
|
|
|
mov ax, [eax + ETH_header.Type]
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
cmp ax, ETHER_IPv4
|
|
|
|
je IPv4_input
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
cmp ax, ETHER_ARP
|
|
|
|
je ARP_input
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2013-01-18 18:32:05 +04:00
|
|
|
cmp ax, ETHER_IPv6
|
|
|
|
je IPv6_input
|
2012-06-03 23:28:01 +04:00
|
|
|
|
2012-08-19 23:09:09 +04:00
|
|
|
cmp ax, ETHER_PPP_DISCOVERY
|
|
|
|
je PPPoE_discovery_input
|
2010-07-15 22:54:19 +04:00
|
|
|
|
2012-08-19 23:09:09 +04:00
|
|
|
cmp ax, ETHER_PPP_SESSION
|
|
|
|
je PPPoE_session_input
|
2012-06-03 23:28:01 +04:00
|
|
|
|
2012-07-27 03:21:35 +04:00
|
|
|
DEBUGF 2,"ETH_input: Unknown packet type=%x\n", ax
|
2009-09-17 15:55:38 +04:00
|
|
|
|
|
|
|
.dump:
|
2012-07-27 03:21:35 +04:00
|
|
|
DEBUGF 2,"ETH_input: dumping\n"
|
2011-11-13 02:35:01 +04:00
|
|
|
call kernel_free
|
|
|
|
add esp, 4
|
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|
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
|
|
|
|
2012-07-27 03:21:35 +04:00
|
|
|
DEBUGF 1,"ETH_output: size=%u device=%x\n", ecx, ebx
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
cmp ecx, [ebx + NET_DEVICE.mtu]
|
|
|
|
ja .exit
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
push ecx
|
|
|
|
push di eax edx
|
2010-07-27 22:53:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
add ecx, sizeof.ETH_header
|
|
|
|
stdcall kernel_alloc, ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .out_of_ram
|
|
|
|
mov edi, eax
|
2010-07-27 22:53:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
pop esi
|
|
|
|
movsd
|
|
|
|
movsw
|
|
|
|
pop esi
|
|
|
|
movsd
|
|
|
|
movsw
|
|
|
|
pop ax
|
|
|
|
stosw
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
lea eax, [edi - sizeof.ETH_header] ; Set eax to buffer start
|
|
|
|
pop ecx
|
|
|
|
lea edx, [ecx + sizeof.ETH_header] ; Set edx to complete buffer size
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
cmp edx, ETH_FRAME_MINIMUM
|
2012-04-13 03:09:15 +04:00
|
|
|
jbe .adjust_size
|
|
|
|
.done:
|
2012-07-27 03:21:35 +04:00
|
|
|
DEBUGF 1,"ETH_output: ptr=%x size=%u\n", eax, edx
|
2011-11-13 02:35:01 +04:00
|
|
|
ret
|
2009-10-12 18:39:59 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
.adjust_size:
|
2011-11-13 02:35:01 +04:00
|
|
|
mov edx, ETH_FRAME_MINIMUM
|
|
|
|
test edx, edx ; clear zero flag
|
2012-04-13 03:09:15 +04:00
|
|
|
jmp .done
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
.out_of_ram:
|
2012-07-27 03:21:35 +04:00
|
|
|
DEBUGF 2,"ETH_output: Out of ram!\n"
|
2011-11-13 02:35:01 +04:00
|
|
|
add esp, 4+4+2+4
|
|
|
|
sub edi, edi
|
|
|
|
ret
|
2009-10-12 18:39:59 +04:00
|
|
|
|
2009-09-17 15:55:38 +04:00
|
|
|
.exit:
|
2011-11-13 02:35:01 +04:00
|
|
|
DEBUGF 2,"ETH_output: Packet too large!\n"
|
|
|
|
sub edi, edi
|
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2012-04-15 01:15:00 +04:00
|
|
|
ETH_api:
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
cmp bh, MAX_NET_DEVICES
|
|
|
|
ja .error
|
|
|
|
movzx eax, bh
|
2012-04-15 01:15:00 +04:00
|
|
|
mov eax, dword [NET_DRV_LIST + 4*eax]
|
2011-11-13 02:35:01 +04:00
|
|
|
cmp [eax + NET_DEVICE.type], NET_TYPE_ETH
|
|
|
|
jne .error
|
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
and ebx, 0xff
|
|
|
|
cmp ebx, .number
|
|
|
|
ja .error
|
|
|
|
jmp dword [.table + 4*ebx]
|
|
|
|
|
|
|
|
.table:
|
|
|
|
dd .packets_tx ; 0
|
|
|
|
dd .packets_rx ; 1
|
|
|
|
dd .bytes_tx ; 2
|
|
|
|
dd .bytes_rx ; 3
|
|
|
|
dd .read_mac ; 4
|
2013-03-07 13:35:24 +04:00
|
|
|
dd .state ; 5
|
2012-04-15 01:15:00 +04:00
|
|
|
.number = ($ - .table) / 4 - 1
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-12 03:13:12 +04:00
|
|
|
.error:
|
2011-11-13 02:35:01 +04:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
.packets_tx:
|
2011-11-13 02:35:01 +04:00
|
|
|
mov eax, [eax + NET_DEVICE.packets_tx]
|
2009-09-22 20:42:54 +04:00
|
|
|
|
2011-11-13 02:35:01 +04:00
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
.packets_rx:
|
2011-11-13 02:35:01 +04:00
|
|
|
mov eax, [eax + NET_DEVICE.packets_rx]
|
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
.bytes_tx:
|
2011-11-13 02:35:01 +04:00
|
|
|
mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4]
|
|
|
|
mov eax, dword [eax + NET_DEVICE.bytes_tx]
|
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
.bytes_rx:
|
2011-11-13 02:35:01 +04:00
|
|
|
mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4]
|
|
|
|
mov eax, dword [eax + NET_DEVICE.bytes_rx]
|
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2009-09-24 22:32:03 +04:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
.read_mac:
|
2011-11-13 02:35:01 +04:00
|
|
|
movzx ebx, word [eax + ETH_DEVICE.mac]
|
|
|
|
mov eax, dword [eax + ETH_DEVICE.mac + 2]
|
|
|
|
mov [esp+20+4], ebx ; TODO: fix this ugly code
|
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2013-03-07 13:35:24 +04:00
|
|
|
.state:
|
|
|
|
mov eax, [eax + NET_DEVICE.state]
|
2011-11-13 02:35:01 +04:00
|
|
|
ret
|
2009-09-17 15:55:38 +04:00
|
|
|
|