2009-09-22 18:42:54 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2010-07-12 01:13:12 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
|
2009-09-22 18:42:54 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; STACK.INC ;;
|
|
|
|
;; ;;
|
|
|
|
;; BASIC TCP/IP stack for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; based on the work of Mike Hibbett, mikeh@oceanfree.net ;;
|
|
|
|
;; but also Paolo Franchetti ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-10-12 16:39:59 +02:00
|
|
|
$Revision$
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-05-28 22:47:32 +02:00
|
|
|
__DEBUG_LEVEL_OLD__ equ __DEBUG_LEVEL__
|
|
|
|
__DEBUG_LEVEL__ equ 1 ; this sets the debug level for network part of kernel
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
uglobal
|
2010-07-12 01:13:12 +02:00
|
|
|
net_10ms dd ?
|
|
|
|
net_tmr_count dw ?
|
2009-09-17 13:55:38 +02:00
|
|
|
endg
|
|
|
|
|
2009-11-09 18:59:50 +01:00
|
|
|
MAX_NET_DEVICES equ 16
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
ETH_QUEUE equ 0 ; 1 = enable / 0 = disable
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-09-28 21:48:32 +02:00
|
|
|
MIN_EPHEMERAL_PORT equ 49152
|
|
|
|
MAX_EPHEMERAL_PORT equ 61000
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; Ethernet protocol numbers
|
2009-09-28 21:48:32 +02:00
|
|
|
ETHER_ARP equ 0x0608
|
2010-07-12 01:13:12 +02:00
|
|
|
ETHER_IPv4 equ 0x0008 ; Reversed from 0800 for intel
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
;Protocol family
|
2009-11-08 19:00:01 +01:00
|
|
|
AF_UNSPEC equ 0
|
2009-11-06 21:45:08 +01:00
|
|
|
AF_UNIX equ 1
|
2009-09-17 13:55:38 +02:00
|
|
|
AF_INET4 equ 2
|
|
|
|
;AF_AX25 equ 3
|
|
|
|
;AF_IPX equ 4
|
|
|
|
;AF_APPLETALK equ 5
|
|
|
|
;AF_NETROM equ 6
|
|
|
|
;AF_BRIDGE equ 7
|
|
|
|
;AF_AAL5 equ 8
|
|
|
|
;AF_X25 equ 9
|
2010-07-12 01:13:12 +02:00
|
|
|
AF_INET6 equ 10
|
2009-09-17 13:55:38 +02:00
|
|
|
;AF_MAX equ 12
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; Internet protocol numbers
|
2009-09-17 13:55:38 +02:00
|
|
|
IP_PROTO_IP equ 0
|
|
|
|
IP_PROTO_ICMP equ 1
|
|
|
|
IP_PROTO_TCP equ 6
|
|
|
|
IP_PROTO_UDP equ 17
|
|
|
|
|
2009-10-07 22:36:58 +02:00
|
|
|
; Socket types
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCK_STREAM equ 1
|
|
|
|
SOCK_DGRAM equ 2
|
|
|
|
SOCK_RAW equ 3
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; Socket options
|
|
|
|
SO_ACCEPTCON equ 1
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
SOCKET_MAXDATA equ 4096
|
2009-11-08 19:00:01 +01:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; Network driver types
|
|
|
|
NET_TYPE_ETH equ 1
|
|
|
|
NET_TYPE_SLIP equ 2
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-12-13 15:55:42 +01:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
virtual at 0
|
|
|
|
|
|
|
|
NET_DEVICE:
|
|
|
|
.type dd ?
|
|
|
|
.end:
|
2009-12-13 15:55:42 +01:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
end virtual
|
|
|
|
|
|
|
|
|
|
|
|
; Exactly as it says..
|
|
|
|
macro pseudo_random reg {
|
2009-12-13 15:55:42 +01:00
|
|
|
add reg, [esp]
|
|
|
|
rol reg, 5
|
|
|
|
xor reg, [timer_ticks]
|
|
|
|
imul reg, 214013
|
|
|
|
xor reg, 0xdeadbeef
|
|
|
|
rol reg, 9
|
2010-07-12 01:13:12 +02:00
|
|
|
}
|
2009-12-13 15:55:42 +01:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
macro ntohld reg {
|
|
|
|
|
|
|
|
rol word reg, 8
|
|
|
|
rol dword reg, 16
|
|
|
|
rol word reg, 8
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
macro ntohlw reg {
|
|
|
|
|
|
|
|
rol word reg, 8
|
2009-12-13 15:55:42 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
include "queue.inc"
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
include "ethernet.inc"
|
|
|
|
;include "slip.inc"
|
|
|
|
|
2009-09-28 22:16:23 +02:00
|
|
|
include "ARP.inc"
|
|
|
|
include "IPv4.inc"
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2009-09-28 21:48:32 +02:00
|
|
|
include "icmp.inc"
|
2010-07-12 01:13:12 +02:00
|
|
|
include "udp.inc"
|
|
|
|
include "tcp.inc"
|
|
|
|
|
|
|
|
include "socket.inc"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
uglobal
|
|
|
|
|
|
|
|
NET_RUNNING dd ?
|
|
|
|
NET_DRV_LIST rd MAX_NET_DEVICES
|
|
|
|
|
|
|
|
endg
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; stack_init
|
|
|
|
;
|
|
|
|
; This function calls all network init procedures
|
|
|
|
;
|
|
|
|
; IN: /
|
|
|
|
; OUT: /
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
align 4
|
|
|
|
stack_init:
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; Init the network drivers list
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov edi, NET_RUNNING
|
|
|
|
mov ecx, MAX_NET_DEVICES + 1
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
; Call other init procedures
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
call ETH_init
|
2010-07-12 01:13:12 +02:00
|
|
|
; call SLIP_init
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
call IPv4_init
|
2010-07-12 01:13:12 +02:00
|
|
|
call ICMP_init
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
call ARP_init
|
|
|
|
call UDP_init
|
2009-11-06 21:45:08 +01:00
|
|
|
call TCP_init
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
call socket_init
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
mov [net_tmr_count], 0
|
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
|
|
|
;
|
|
|
|
; stack_handler
|
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; This function is called in kernel loop
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
; IN: /
|
|
|
|
; OUT: /
|
|
|
|
;
|
2009-11-09 14:59:46 +01:00
|
|
|
;-----------------------------------------------------------------
|
2009-09-17 13:55:38 +02:00
|
|
|
align 4
|
|
|
|
stack_handler:
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
cmp [NET_RUNNING], 0
|
2009-11-09 14:59:46 +01:00
|
|
|
je .exit
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-12-13 15:55:42 +01:00
|
|
|
; Test for 10ms tick
|
2009-11-09 14:59:46 +01:00
|
|
|
mov eax, [timer_ticks]
|
2010-07-12 01:13:12 +02:00
|
|
|
cmp eax, [net_10ms]
|
2009-11-09 14:59:46 +01:00
|
|
|
je .exit
|
2010-07-12 01:13:12 +02:00
|
|
|
mov [net_10ms], eax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
if ETH_QUEUE
|
|
|
|
call ETH_handler
|
2009-11-09 14:59:46 +01:00
|
|
|
call ETH_send_queued
|
2010-07-12 01:13:12 +02:00
|
|
|
end if
|
|
|
|
call TCP_10ms
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
inc [net_tmr_count]
|
|
|
|
cmp [net_tmr_count], 50
|
|
|
|
je .500ms
|
|
|
|
cmp [net_tmr_count], 100
|
|
|
|
jne .exit
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
call ARP_decrease_entry_ttls
|
|
|
|
call IPv4_decrease_fragment_ttls
|
2010-07-12 01:13:12 +02:00
|
|
|
call TCP_timer_1000ms
|
|
|
|
|
|
|
|
mov [net_tmr_count], 0
|
|
|
|
|
|
|
|
.500ms:
|
|
|
|
call TCP_500ms
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.exit:
|
2009-11-09 14:59:46 +01:00
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; NET_Add_Device:
|
|
|
|
;
|
|
|
|
; This function is called by the network drivers,
|
|
|
|
; to register each running NIC to the kernel
|
|
|
|
;
|
|
|
|
; IN: Pointer to device structure in ebx
|
|
|
|
; OUT: Device num in eax, -1 on error
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
NET_add_device:
|
|
|
|
|
|
|
|
DEBUGF 1,"NET_Add_Device: %x\n", ebx
|
|
|
|
|
|
|
|
mov eax, [NET_RUNNING]
|
|
|
|
cmp eax, MAX_NET_DEVICES
|
|
|
|
jge .error
|
|
|
|
|
|
|
|
;----------------------------------
|
|
|
|
; Check if device is already listed
|
|
|
|
mov eax, ebx
|
|
|
|
mov ecx, MAX_NET_DEVICES ; We need to check whole list because a device may be removed without re-organizing list
|
|
|
|
mov edi, NET_DRV_LIST
|
|
|
|
|
|
|
|
repne scasd ; See if device is already in the list
|
|
|
|
jz .error
|
|
|
|
|
|
|
|
;----------------------------
|
|
|
|
; Find empty slot in the list
|
|
|
|
xor eax, eax
|
|
|
|
mov ecx, MAX_NET_DEVICES
|
|
|
|
mov edi, NET_DRV_LIST
|
|
|
|
|
|
|
|
repne scasd
|
|
|
|
jnz .error
|
|
|
|
|
|
|
|
sub edi, 4
|
|
|
|
|
|
|
|
cmp [ebx + NET_DEVICE.type], NET_TYPE_ETH
|
|
|
|
je .ethernet
|
|
|
|
|
|
|
|
cmp [ebx + NET_DEVICE.type], NET_TYPE_SLIP
|
|
|
|
je .slip
|
|
|
|
|
|
|
|
DEBUGF 1,"Unknown network device type: %u\n", [ebx + NET_DEVICE.type]
|
|
|
|
jmp .error
|
|
|
|
|
|
|
|
.ethernet:
|
|
|
|
DEBUGF 1,"Trying to add an ethernet driver\n"
|
|
|
|
|
|
|
|
inc [ETH_RUNNING] ; Indicate that one more ethernet device is up and running
|
|
|
|
jmp .add_it
|
|
|
|
|
|
|
|
.slip:
|
|
|
|
DEBUGF 1,"Trying to add a slip driver\n"
|
|
|
|
;;;;
|
|
|
|
jmp .error
|
|
|
|
|
|
|
|
|
|
|
|
.add_it:
|
|
|
|
|
|
|
|
;-----------------------------
|
|
|
|
; Add device to the found slot
|
|
|
|
mov [edi], ebx ; add device to list
|
|
|
|
|
|
|
|
sub edi, NET_DRV_LIST ; Calculate device number in eax
|
|
|
|
mov eax, edi ;
|
|
|
|
shr eax, 2
|
|
|
|
|
|
|
|
inc [NET_RUNNING] ; Indicate that one more network device is up and running
|
|
|
|
|
|
|
|
DEBUGF 1,"Device number: %u\n",eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.error:
|
|
|
|
or eax, -1
|
|
|
|
DEBUGF 2,"Adding network device failed\n"
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; NET_Remove_Device:
|
|
|
|
;
|
|
|
|
; This function is called by etwork drivers,
|
|
|
|
; to unregister network devices from the kernel
|
|
|
|
;
|
|
|
|
; IN: Pointer to device structure in ebx
|
|
|
|
; OUT: eax: -1 on error
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
NET_remove_device:
|
|
|
|
|
|
|
|
cmp [NET_RUNNING], 0
|
|
|
|
je .error
|
|
|
|
|
|
|
|
;----------------------------
|
|
|
|
; Find the driver in the list
|
|
|
|
|
|
|
|
mov eax, ebx
|
|
|
|
mov ecx, MAX_NET_DEVICES
|
|
|
|
mov edi, NET_DRV_LIST
|
|
|
|
|
|
|
|
repne scasd
|
|
|
|
jnz .error
|
|
|
|
|
|
|
|
;------------------------
|
|
|
|
; Remove it from the list
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov dword [edi-4], eax
|
|
|
|
|
|
|
|
dec [NET_RUNNING]
|
|
|
|
ret
|
|
|
|
|
|
|
|
.error:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; NET_ptr_to_num
|
|
|
|
;
|
|
|
|
; IN: ebx = ptr to device struct
|
|
|
|
; OUT: edi = -1 on error, device number otherwise
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
NET_ptr_to_num:
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov ecx, MAX_NET_DEVICES
|
|
|
|
mov edi, NET_DRV_LIST
|
|
|
|
|
|
|
|
.loop:
|
|
|
|
cmp ebx, [edi]
|
|
|
|
jz .found
|
|
|
|
add edi, 4
|
|
|
|
dec ecx
|
|
|
|
jnz .loop
|
|
|
|
|
|
|
|
; repnz scasd could work too if eax is used instead of ebx!
|
|
|
|
|
|
|
|
or edi, -1
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
ret
|
|
|
|
|
|
|
|
.found:
|
|
|
|
sub edi, NET_DRV_LIST
|
|
|
|
shr edi, 2
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;--------------------------
|
|
|
|
;
|
|
|
|
; NET_send
|
|
|
|
;
|
|
|
|
; IN: ebx = ptr to device struct
|
|
|
|
; [esp] = data ptr
|
|
|
|
; [esp + 4] = data size
|
|
|
|
;
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;--------------------------
|
|
|
|
align 4
|
|
|
|
NET_send:
|
|
|
|
|
|
|
|
call [ebx + ETH_DEVICE.transmit] ;;;;
|
|
|
|
|
|
|
|
;;; TODO:check if packet was sent ok
|
|
|
|
|
|
|
|
call kernel_free
|
|
|
|
add esp, 4
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; checksum_1
|
|
|
|
;
|
2010-06-07 11:37:13 +02:00
|
|
|
; This is the first of two functions needed to calculate a checksum.
|
2009-11-06 21:45:08 +01:00
|
|
|
;
|
2010-05-28 22:47:32 +02:00
|
|
|
; IN: edx = start offset for semi-checksum
|
2009-11-06 21:45:08 +01:00
|
|
|
; esi = pointer to data
|
|
|
|
; ecx = data size
|
|
|
|
; OUT: edx = semi-checksum
|
|
|
|
;
|
2010-05-28 22:47:32 +02:00
|
|
|
;
|
|
|
|
; Code was optimized by diamond
|
|
|
|
;
|
2009-11-06 21:45:08 +01:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
checksum_1:
|
|
|
|
|
|
|
|
shr ecx, 1
|
|
|
|
pushf
|
2010-05-28 22:47:32 +02:00
|
|
|
jz .no_2
|
|
|
|
|
|
|
|
shr ecx, 1
|
|
|
|
pushf
|
|
|
|
jz .no_4
|
|
|
|
|
|
|
|
shr ecx, 1
|
|
|
|
pushf
|
|
|
|
jz .no_8
|
|
|
|
|
|
|
|
.loop:
|
|
|
|
add dl, [esi+1]
|
|
|
|
adc dh, [esi+0]
|
|
|
|
|
|
|
|
adc dl, [esi+3]
|
|
|
|
adc dh, [esi+2]
|
|
|
|
|
|
|
|
adc dl, [esi+5]
|
|
|
|
adc dh, [esi+4]
|
|
|
|
|
|
|
|
adc dl, [esi+7]
|
|
|
|
adc dh, [esi+6]
|
|
|
|
|
|
|
|
adc edx, 0
|
|
|
|
add esi, 8
|
|
|
|
|
|
|
|
dec ecx
|
|
|
|
jnz .loop
|
|
|
|
|
|
|
|
adc edx, 0
|
|
|
|
|
|
|
|
.no_8:
|
|
|
|
popf
|
|
|
|
jnc .no_4
|
|
|
|
|
|
|
|
add dl, [esi+1]
|
|
|
|
adc dh, [esi+0]
|
|
|
|
|
|
|
|
adc dl, [esi+3]
|
|
|
|
adc dh, [esi+2]
|
|
|
|
|
|
|
|
adc edx, 0
|
|
|
|
add esi, 4
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2010-05-28 22:47:32 +02:00
|
|
|
.no_4:
|
|
|
|
popf
|
|
|
|
jnc .no_2
|
|
|
|
|
|
|
|
add dl, [esi+1]
|
|
|
|
adc dh, [esi+0]
|
|
|
|
|
|
|
|
adc edx, 0
|
2010-06-07 14:57:52 +02:00
|
|
|
inc esi
|
|
|
|
inc esi
|
2010-05-28 22:47:32 +02:00
|
|
|
|
|
|
|
.no_2:
|
2009-11-06 21:45:08 +01:00
|
|
|
popf
|
|
|
|
jnc .end
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-05-28 22:47:32 +02:00
|
|
|
add dh, [esi+0]
|
|
|
|
adc edx, 0
|
|
|
|
.end:
|
|
|
|
ret
|
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; checksum_2
|
|
|
|
;
|
|
|
|
; This function calculates the final ip/tcp/udp checksum for you
|
|
|
|
;
|
|
|
|
; IN: edx = semi-checksum
|
|
|
|
; OUT: dx = checksum (in INET byte order)
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
checksum_2:
|
|
|
|
|
|
|
|
mov ecx, edx
|
|
|
|
shr ecx, 16
|
|
|
|
and edx, 0xffff
|
|
|
|
add edx, ecx
|
2010-06-07 11:37:13 +02:00
|
|
|
|
|
|
|
mov ecx, edx
|
|
|
|
shr ecx, 16
|
|
|
|
add edx, ecx
|
2009-11-06 21:45:08 +01:00
|
|
|
|
|
|
|
not dx
|
|
|
|
jnz .not_zero
|
|
|
|
dec dx
|
|
|
|
.not_zero:
|
|
|
|
xchg dl, dh
|
|
|
|
|
|
|
|
DEBUGF 1,"Checksum: %x\n",dx
|
|
|
|
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
;
|
2009-09-22 18:42:54 +02:00
|
|
|
; System function to work with network devices (73)
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
sys_network:
|
|
|
|
|
2009-10-05 22:47:27 +02:00
|
|
|
cmp ebx, -1
|
|
|
|
jne @f
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
mov eax, [NET_RUNNING]
|
2009-10-05 22:47:27 +02:00
|
|
|
jmp .return
|
|
|
|
|
|
|
|
@@:
|
2009-09-17 13:55:38 +02:00
|
|
|
cmp bh, MAX_NET_DEVICES ; Check if device number exists
|
|
|
|
jge .doesnt_exist
|
|
|
|
|
|
|
|
mov esi, ebx
|
|
|
|
and esi, 0x0000ff00
|
|
|
|
shr esi, 6
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
cmp dword [esi + NET_DRV_LIST], 0 ; check if driver is running
|
2009-09-17 13:55:38 +02:00
|
|
|
je .doesnt_exist
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
test bl, bl ; 0 = Get device type (ethernet/token ring/...)
|
2009-09-17 13:55:38 +02:00
|
|
|
jnz @f
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2009-10-02 21:49:42 +02:00
|
|
|
xor eax, eax
|
|
|
|
jmp .return
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
@@:
|
|
|
|
dec bl ; 1 = Get device name
|
|
|
|
jnz @f
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
mov esi, [esi + NET_DRV_LIST]
|
2009-09-17 13:55:38 +02:00
|
|
|
mov esi, [esi + ETH_DEVICE.name]
|
|
|
|
mov edi, ecx
|
|
|
|
|
|
|
|
mov ecx, 64 ; max length
|
|
|
|
repnz movsb
|
|
|
|
|
2009-10-02 21:49:42 +02:00
|
|
|
xor eax, eax
|
|
|
|
jmp .return
|
|
|
|
|
|
|
|
@@:
|
|
|
|
|
|
|
|
dec bl ; 2 = Reset the device
|
|
|
|
jnz @f
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
mov esi, [esi + NET_DRV_LIST]
|
2009-10-02 21:49:42 +02:00
|
|
|
call [esi + ETH_DEVICE.reset]
|
|
|
|
jmp .return
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
@@:
|
2009-10-02 21:49:42 +02:00
|
|
|
|
|
|
|
dec bl ; 3 = Stop driver for this device
|
|
|
|
jnz @f
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
mov esi, [esi + NET_DRV_LIST]
|
2009-10-02 21:49:42 +02:00
|
|
|
call [esi + ETH_DEVICE.unload]
|
|
|
|
jmp .return
|
|
|
|
|
|
|
|
@@:
|
2009-11-06 21:45:08 +01:00
|
|
|
dec bl ; 4 = Get driver pointer
|
|
|
|
jnz @f
|
|
|
|
|
|
|
|
; ..;
|
|
|
|
|
|
|
|
|
|
|
|
@@:
|
|
|
|
; ... ; 5 Get driver name
|
2009-10-02 21:49:42 +02:00
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
.doesnt_exist:
|
|
|
|
DEBUGF 1,"sys_network: invalid device/function specified!\n"
|
|
|
|
mov eax, -1
|
|
|
|
|
2009-10-02 21:49:42 +02:00
|
|
|
.return:
|
|
|
|
mov [esp+28+4], eax
|
2009-09-17 13:55:38 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
;
|
2010-07-12 01:13:12 +02:00
|
|
|
; System function to work with protocols (75)
|
2009-09-17 13:55:38 +02:00
|
|
|
;
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
sys_protocols:
|
|
|
|
cmp bh, MAX_NET_DEVICES ; Check if device number exists
|
|
|
|
jge .doesnt_exist
|
|
|
|
|
|
|
|
mov esi, ebx
|
|
|
|
and esi, 0x0000ff00
|
2010-07-12 01:13:12 +02:00
|
|
|
shr esi, 6 ; now we have the device num * 4 in esi
|
|
|
|
cmp dword [esi + NET_DRV_LIST], 0 ; check if driver is running
|
2009-09-17 13:55:38 +02:00
|
|
|
je .doesnt_exist
|
|
|
|
|
|
|
|
push .return ; return address (we will be using jumps instead of calls)
|
|
|
|
|
|
|
|
mov eax, ebx ; set ax to protocol number
|
|
|
|
shr eax, 16 ;
|
|
|
|
|
|
|
|
cmp ax , IP_PROTO_IP
|
|
|
|
je IPv4_API
|
|
|
|
|
|
|
|
cmp ax , IP_PROTO_ICMP
|
|
|
|
je ICMP_API
|
|
|
|
|
|
|
|
cmp ax , IP_PROTO_UDP
|
|
|
|
je UDP_API
|
|
|
|
|
2009-09-22 18:42:54 +02:00
|
|
|
cmp ax , IP_PROTO_TCP
|
2009-11-08 19:00:01 +01:00
|
|
|
je TCP_API
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-09-22 18:42:54 +02:00
|
|
|
cmp ax , ETHER_ARP
|
2009-09-17 13:55:38 +02:00
|
|
|
je ARP_API
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
cmp ax , 1337
|
2009-09-17 13:55:38 +02:00
|
|
|
je ETH_API
|
|
|
|
|
2009-09-22 18:42:54 +02:00
|
|
|
add esp, 4 ; if we reached here, no function was called, so we need to balance stack
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.doesnt_exist:
|
2009-09-22 18:42:54 +02:00
|
|
|
DEBUGF 1,"sys_protocols: protocol %u doesnt exist on device %u!\n",ax, bh
|
2009-09-17 13:55:38 +02:00
|
|
|
mov eax, -1
|
|
|
|
|
|
|
|
.return:
|
2009-09-22 18:42:54 +02:00
|
|
|
mov [esp+28+4], eax
|
2009-11-09 14:59:46 +01:00
|
|
|
ret
|
2010-05-28 22:47:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
__DEBUG_LEVEL__ equ __DEBUG_LEVEL_OLD__
|