2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
|
|
|
|
;; 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 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision: 3346 $
|
|
|
|
|
|
|
|
ETH_FRAME_MINIMUM = 60
|
|
|
|
|
|
|
|
struct ETH_header
|
|
|
|
|
|
|
|
DstMAC dp ? ; destination MAC-address
|
|
|
|
SrcMAC dp ? ; source MAC-address
|
|
|
|
Type dw ? ; type of the upper-layer protocol
|
|
|
|
|
|
|
|
ends
|
|
|
|
|
|
|
|
struct ETH_DEVICE NET_DEVICE
|
|
|
|
|
|
|
|
mac dp ?
|
|
|
|
|
|
|
|
ends
|
|
|
|
|
|
|
|
iglobal
|
2013-06-24 13:39:05 +02:00
|
|
|
align 4
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ETH_BROADCAST dp 0xffffffffffff
|
|
|
|
endg
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; ETH_input
|
|
|
|
;
|
|
|
|
; This function is called by ethernet drivers,
|
|
|
|
; It pushes the received ethernet packets onto the eth_in_queue
|
|
|
|
;
|
|
|
|
; IN: [esp] = Pointer to buffer
|
|
|
|
; [esp+4] = size of buffer
|
|
|
|
; ebx = pointer to eth_device
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
ETH_input:
|
|
|
|
mov eax, [esp]
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE,"ETH_input: size=%u\n", ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
sub ecx, sizeof.ETH_header
|
2013-06-11 12:46:29 +02:00
|
|
|
jb .dump
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
lea edx, [eax + sizeof.ETH_header]
|
|
|
|
mov ax, [eax + ETH_header.Type]
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp ax, ETHER_PROTO_IPv4
|
2013-05-28 19:34:26 +02:00
|
|
|
je IPv4_input
|
|
|
|
|
2013-06-05 02:21:20 +02:00
|
|
|
cmp ax, ETHER_PROTO_ARP
|
2013-05-28 19:34:26 +02:00
|
|
|
je ARP_input
|
|
|
|
|
2013-06-05 02:21:20 +02:00
|
|
|
cmp ax, ETHER_PROTO_IPv6
|
2013-05-28 19:34:26 +02:00
|
|
|
je IPv6_input
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp ax, ETHER_PROTO_PPP_DISCOVERY
|
2013-05-28 19:34:26 +02:00
|
|
|
je PPPoE_discovery_input
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp ax, ETHER_PROTO_PPP_SESSION
|
2013-05-28 19:34:26 +02:00
|
|
|
je PPPoE_session_input
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_ERROR, "ETH_input: Unknown packet type=%x\n", ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.dump:
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE,"ETH_input: dumping\n"
|
2013-08-07 15:13:29 +02:00
|
|
|
call NET_packet_free
|
2013-05-28 19:34:26 +02:00
|
|
|
add esp, 4
|
|
|
|
ret
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; ETH_output
|
|
|
|
;
|
|
|
|
; IN: eax = pointer to source mac
|
|
|
|
; ebx = device ptr
|
|
|
|
; ecx = packet size
|
|
|
|
; edx = pointer to destination mac
|
|
|
|
; di = protocol
|
|
|
|
;
|
|
|
|
; 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
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
ETH_output:
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: size=%u device=%x\n", ecx, ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp ecx, [ebx + NET_DEVICE.mtu]
|
|
|
|
ja .exit
|
|
|
|
|
|
|
|
push ecx
|
|
|
|
push di eax edx
|
|
|
|
|
|
|
|
add ecx, sizeof.ETH_header
|
|
|
|
stdcall kernel_alloc, ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .out_of_ram
|
|
|
|
mov edi, eax
|
|
|
|
|
|
|
|
pop esi
|
|
|
|
movsd
|
|
|
|
movsw
|
|
|
|
pop esi
|
|
|
|
movsd
|
|
|
|
movsw
|
|
|
|
pop ax
|
|
|
|
stosw
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
cmp edx, ETH_FRAME_MINIMUM
|
|
|
|
jbe .adjust_size
|
|
|
|
.done:
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: ptr=%x size=%u\n", eax, edx
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.adjust_size:
|
|
|
|
mov edx, ETH_FRAME_MINIMUM
|
|
|
|
test edx, edx ; clear zero flag
|
|
|
|
jmp .done
|
|
|
|
|
|
|
|
.out_of_ram:
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Out of ram!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
add esp, 4+4+2+4
|
|
|
|
sub edi, edi
|
|
|
|
ret
|
|
|
|
|
|
|
|
.exit:
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Packet too large!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
sub edi, edi
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; ETH_API
|
|
|
|
;
|
2013-06-05 02:21:20 +02:00
|
|
|
; This function is called by system function 76
|
2013-05-28 19:34:26 +02:00
|
|
|
;
|
|
|
|
; IN: subfunction number in bl
|
|
|
|
; device number in bh
|
|
|
|
; ecx, edx, .. depends on subfunction
|
|
|
|
;
|
|
|
|
; OUT:
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
ETH_api:
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp bh, NET_DEVICES_MAX
|
2013-05-28 19:34:26 +02:00
|
|
|
ja .error
|
|
|
|
movzx eax, bh
|
|
|
|
mov eax, dword [NET_DRV_LIST + 4*eax]
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp [eax + NET_DEVICE.device_type], NET_DEVICE_ETH
|
2013-05-28 19:34:26 +02:00
|
|
|
jne .error
|
|
|
|
|
|
|
|
and ebx, 0xff
|
|
|
|
cmp ebx, .number
|
|
|
|
ja .error
|
|
|
|
jmp dword [.table + 4*ebx]
|
|
|
|
|
|
|
|
.table:
|
2013-06-05 02:21:20 +02:00
|
|
|
dd .read_mac ; 0
|
2013-05-28 19:34:26 +02:00
|
|
|
.number = ($ - .table) / 4 - 1
|
|
|
|
|
|
|
|
.error:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
.read_mac:
|
|
|
|
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
|
|
|
|
|
|
|
|
|