/kernel/branches/net/applications/netstat/netstat.asm |
---|
0,0 → 1,504 |
; |
; Netstat for KolibriOS v0.1 |
; |
; hidnplayr@gmail.com |
; |
use32 |
org 0x0 |
db 'MENUET01' ; 8 byte id |
dd 0x01 ; header version |
dd START ; start of code |
dd I_END ; size of image |
dd IM_END ; memory for app |
dd IM_END ; esp |
dd I_PARAM , 0x0 ; I_Param , I_Icon |
__DEBUG__ equ 1 |
__DEBUG_LEVEL__ equ 1 |
include '..\macros.inc' |
include '..\debug-fdo.inc' |
START: ; start of execution |
; TODO: check Parameters |
DEBUGF 1, 'Hello!\n' |
redraw: |
mcall 12, 1 |
mcall 0, 100 shl 16 + 520, 100 shl 16 + 240, 0x34bcbcbc, ,name |
mov edx, 101 |
mov esi, 0x00aaaaff |
mov edi, 0x00aaffff |
cmp dl, [mode] |
cmove esi, edi |
mcall 8, 25 shl 16 + 65, 25 shl 16 + 20 |
@@: |
inc edx |
add ebx, 75 shl 16 |
mov esi, 0x00aaaaff |
cmp dl, [mode] |
cmove esi, edi |
mcall |
cmp edx, 105 |
jle @r |
mcall 4, 28 shl 16 + 31, 0x80000000, modes |
cmp [mode], 101 |
jne @f |
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx |
add ebx, 18 |
mov edx, str_packets_rx |
mcall |
add ebx, 18 |
mov edx, str_bytes_tx |
mcall |
add ebx, 18 |
mov edx, str_bytes_rx |
mcall |
add ebx, 18 |
mov edx, str_MAC |
mcall |
add ebx, 18 |
mov edx, str_queue_in |
mcall |
add ebx, 18 |
mov edx, str_queue_out |
mcall |
push end_of_draw |
mov ebx,1337 shl 16 + 4 |
mov bh, [device] |
mcall 75 |
push eax |
push bx |
mov edx, 135 shl 16 + 75 + 4*18 |
jmp draw_mac |
@@: |
cmp [mode], 102 |
jne @f |
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx |
add ebx, 18 |
mov edx, str_packets_rx |
mcall |
add ebx, 18 |
mov edx, str_ip |
mcall |
add ebx, 18 |
mov edx, str_dns |
mcall |
add ebx, 18 |
mov edx, str_subnet |
mcall |
add ebx, 18 |
mov edx, str_gateway |
mcall |
mov ebx, 0 shl 16 + 8 |
mov bh, [device] |
mcall 75 |
push eax |
dec bl |
dec bl |
mcall 75 |
push eax |
dec bl |
dec bl |
mcall 75 |
push eax |
dec bl |
dec bl |
mcall 75 |
push eax |
mov edx, 135 shl 16 + 75 + 2*18 |
call draw_ip |
add edx, 18 |
call draw_ip |
add edx, 18 |
call draw_ip |
add edx, 18 |
call draw_ip |
jmp end_of_draw |
@@: |
cmp [mode], 103 |
jne @f |
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx |
add ebx, 18 |
mov edx, str_packets_rx |
mcall |
add ebx, 18 |
mov edx, str_arp |
mcall |
jmp end_of_draw |
@@: |
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx |
add ebx, 18 |
mov edx, str_packets_rx |
mcall |
end_of_draw: |
mcall 12, 2 |
jmp draw_stats |
mainloop: |
mcall 23,50 ; wait for event with timeout (0,5 s) |
cmp eax, 1 |
je redraw |
cmp eax, 2 |
je key |
cmp eax, 3 |
je button |
;------------------------------- |
; |
;------------------------------ |
draw_stats: |
cmp [mode], 101 |
jne not_101 |
mov ebx, 1337 shl 16 + 0 |
mov bh, [device] |
@@: |
mcall 75 |
push eax |
inc bl |
cmp bl, 3 |
jle @r |
inc bl |
inc bl |
@@: |
mcall 75 |
push eax |
inc bl |
cmp bl, 7 |
jle @r |
mov eax, 47 |
mov ebx, 0x000a0000 |
mov esi, 0x40000000 |
mov edi, 0x00bcbcbc |
mov edx, 135 shl 16 + 75 + 6*18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
sub edx, 2*18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
jmp mainloop |
not_101: |
cmp [mode], 102 |
jne not_102 |
mov ebx, 0 shl 16 |
mov bh, [device] |
mcall 75 |
push eax |
inc bl |
mcall 75 |
push eax |
inc bl |
mov eax, 47 |
mov ebx, 0x000a0000 |
mov esi, 0x40000000 |
mov edi, 0x00bcbcbc |
mov edx, 135 shl 16 + 75 + 18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
jmp mainloop |
not_102: |
cmp [mode], 103 |
jne not_103 |
mov ebx, 0x0608 shl 16 + 0 |
mov bh, [device] |
mcall 75 |
push eax |
inc bl |
mcall 75 |
push eax |
inc bl |
mcall 75 |
push eax |
inc bl |
mov eax, 47 |
mov ebx, 0x000a0000 |
mov esi, 0x40000000 |
mov edi, 0x00bcbcbc |
mov edx, 135 shl 16 + 75 + 2*18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
jmp mainloop |
not_103: |
cmp [mode], 104 |
jne not_104 |
mov ebx, 1 shl 16 + 0 |
mov bh, [device] |
mcall 75 |
push eax |
inc bl |
mcall 75 |
push eax |
inc bl |
mov eax, 47 |
mov ebx, 0x000a0000 |
mov esi, 0x40000000 |
mov edi, 0x00bcbcbc |
mov edx, 135 shl 16 + 75 + 18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
jmp mainloop |
not_104: |
cmp [mode], 105 |
jne not_105 |
mov ebx, 17 shl 16 + 0 |
mov bh, [device] |
mcall 75 |
push eax |
inc bl |
mcall 75 |
push eax |
inc bl |
mov eax, 47 |
mov ebx, 0x000a0000 |
mov esi, 0x40000000 |
mov edi, 0x00bcbcbc |
mov edx, 135 shl 16 + 75 + 18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
jmp mainloop |
not_105: |
cmp [mode], 106 |
jne not_106 |
mov ebx, 6 shl 16 + 0 |
mov bh, [device] |
mcall 75 |
push eax |
inc bl |
mcall 75 |
push eax |
inc bl |
mov eax, 47 |
mov ebx, 0x000a0000 |
mov esi, 0x40000000 |
mov edi, 0x00bcbcbc |
mov edx, 135 shl 16 + 75 + 18 |
pop ecx |
mcall |
sub edx, 18 |
pop ecx |
mcall |
jmp mainloop |
not_106: |
jmp mainloop |
key: |
mcall 2 |
jmp mainloop |
button: ; button |
mcall 17 ; get id |
cmp ah, 1 |
je close |
mov [mode], ah |
jmp redraw |
close: |
mcall -1 |
draw_mac: |
mov eax, 47 |
mov ebx, 0x00020100 |
mov esi, 0x40000000 |
mov edi, 0x00bcbcbc |
mov cl, [esp] |
mcall |
mov cl, [esp+1] |
add edx, 15 shl 16 |
mcall |
mov cl, [esp+2] |
add edx, 15 shl 16 |
mcall |
mov cl, [esp+3] |
add edx, 15 shl 16 |
mcall |
mov cl, [esp+4] |
add edx, 15 shl 16 |
mcall |
mov cl, [esp+5] |
add edx, 15 shl 16 |
mcall |
add esp, 6 |
sub edx, 5*15 shl 16 |
ret |
draw_ip: |
mov eax, 47 |
mov ebx, 0x00030000 |
mov esi, 0x40000000 |
mov edi, 0x00bcbcbc |
xor ecx, ecx |
mov cl, [esp+4] |
mcall |
mov cl, [esp+4+1] |
add edx, 30 shl 16 |
mcall |
mov cl, [esp+4+2] |
add edx, 30 shl 16 |
mcall |
mov cl, [esp+4+3] |
add edx, 30 shl 16 |
mcall |
sub edx, 3*30 shl 16 |
mov eax, [esp] |
add esp, 8 |
jmp eax |
; DATA AREA |
I_END: |
name db 'Netstat',0 |
mode db 101 |
device db 0 |
modes db 'Ethernet IPv4 ARP ICMP UDP TCP',0 |
str_packets_tx db 'Packets sent:',0 |
str_packets_rx db 'Packets received:',0 |
str_bytes_tx db 'Bytes sent:',0 |
str_bytes_rx db 'Bytes received:',0 |
str_MAC db 'MAC address:',0 |
str_queue_in db 'IN-queue size:',0 |
str_queue_out db 'OUT-queue size:',0 |
str_ip db 'IP address:',0 |
str_dns db 'DNS address:',0 |
str_subnet db 'Subnet mask:',0 |
str_gateway db 'Standard gateway:',0 |
str_arp db 'ARP entrys:',0 |
include_debug_strings ; ALWAYS present in data section |
I_PARAM rb 1024 |
IM_END: |
/kernel/branches/net/drivers/ps2m_irqh.inc |
---|
File deleted |
/kernel/branches/net/drivers/com_mouse.asm |
---|
File deleted |
/kernel/branches/net/drivers/ensoniq.asm |
---|
File deleted |
/kernel/branches/net/drivers/main.inc |
---|
File deleted |
/kernel/branches/net/drivers/ps2m_iofuncs.inc |
---|
File deleted |
/kernel/branches/net/drivers/infinity.asm |
---|
File deleted |
/kernel/branches/net/drivers/mix_mmx.inc |
---|
File deleted |
/kernel/branches/net/drivers/sis.asm |
---|
File deleted |
/kernel/branches/net/drivers/sound.asm |
---|
File deleted |
/kernel/branches/net/drivers/codec.inc |
---|
File deleted |
/kernel/branches/net/drivers/vmode.asm |
---|
File deleted |
/kernel/branches/net/drivers/mix_sse2.inc |
---|
File deleted |
/kernel/branches/net/drivers/uart.asm |
---|
File deleted |
/kernel/branches/net/drivers/ati2d.asm |
---|
File deleted |
/kernel/branches/net/drivers/mixer.asm |
---|
File deleted |
/kernel/branches/net/drivers/ps2mouse.asm |
---|
File deleted |
/kernel/branches/net/drivers/r500hw.inc |
---|
File deleted |
/kernel/branches/net/drivers/RTL8139.asm |
---|
701,6 → 701,12 |
mov [ebx+device.rx_data_offset], eax |
mov [ebx+device.curr_tx_desc], al |
; clear packet/byte counters |
lea edi, [ebx+device.bytes_tx] ; TODO: check if destroying edi, ecx doesnt harm anything |
mov ecx, 6 |
rep stosd |
; clear missing packet counter |
add edx, REG_MPC - REG_9346CR |
818,8 → 824,8 |
inc [ebx+device.packets_tx] ; |
mov eax, [esp+4] ; Get packet size in eax |
add dword [ebx + device.bytes_tx], eax |
adc dword [ebx + device.bytes_tx + 4], 0 |
add dword [ebx + device.bytes_tx + 4], eax |
adc dword [ebx + device.bytes_tx], 0 |
; or eax, (ERTXTH shl BIT_ERTXTH) ; Set descriptor size and the early tx treshold into the correct Transmission status register (TSD0, TSD1, TSD2 or TSD3) |
out dx , eax ; |
900,8 → 906,8 |
jz .reset_rx |
; packet is ok, copy it |
movzx ecx, word [eax+2] ; packet length |
add dword [ebx + device.bytes_rx], ecx ; Update stats |
adc dword [ebx + device.bytes_rx + 4], 0 |
add dword [ebx + device.bytes_rx + 4], ecx ; Update stats |
adc dword [ebx + device.bytes_rx], 0 |
inc dword [ebx + device.packets_rx] ; |
sub ecx, 4 ; don't copy CRC |
DEBUGF 1,"Received %u bytes\n", ecx |
/kernel/branches/net/network/ARP.inc |
---|
531,6 → 531,8 |
xor edx, edx |
shl edx, 2 |
inc [ARP_PACKETS_TX+edx] |
push dword .returnaddr |
push dword 60 |
push ebx |
598,7 → 600,8 |
jne .exit |
call ETH_struc2dev |
DEBUGF 1,"Packet came from device: %u\n", edi |
DEBUGF 1,"ARP Packet came from device: %u\n", edi |
inc [ARP_PACKETS_RX+4*edi] |
cmp edi, -1 |
jz .exit |
/kernel/branches/net/network/IPv4.inc |
---|
149,7 → 149,8 |
jmp .dump |
.ip_ok: |
call ETH_struc2dev ; TODO: make this work on other protocols too! |
inc [IP_PACKETS_RX+4*edi] |
DEBUGF 1,"IP_Handler - packet from %u.%u.%u.%u\n",\ |
[edx + IPv4_Packet.SourceAddress]:1,[edx + IPv4_Packet.SourceAddress + 1]:1,[edx + IPv4_Packet.SourceAddress + 2]:1,[edx + IPv4_Packet.SourceAddress + 3]:1 |
390,10 → 391,10 |
mov al , [edx + IPv4_Packet.Protocol] |
pop edx ; Offset to data (tcp/udp/icmp/.. Packet) |
; cmp al , PROTOCOL_TCP |
; cmp al , IP_PROTO_TCP |
; je TCP_Handler |
cmp al , PROTOCOL_UDP |
cmp al , IP_PROTO_UDP |
je UDP_Handler |
cmp al , IP_PROTO_ICMP |
535,6 → 536,7 |
.send: |
push ecx eax ebx dx di |
call IPv4_dest_to_dev |
inc [IP_PACKETS_TX+4*edi] |
mov edi, [ETH_DRV_LIST + 4*edi] |
lea eax, [edi + ETH_DEVICE.mac] |
mov ebx, temp_dstmac |
581,7 → 583,7 |
uglobal |
temp_dstmac dp ? |
temp_dstmac dp ? ; TODO: place this in stack instead! |
endg |
/kernel/branches/net/network/ethernet.inc |
---|
449,7 → 449,6 |
dec bl |
jz .out_queue ; 7 |
.error: |
mov eax, -1 |
ret |
456,25 → 455,26 |
.packets_tx: |
add eax, ETH_DRV_LIST |
mov eax, [eax] |
mov eax, [eax + ETH_DEVICE.packets_tx] |
mov eax, dword [eax] |
mov eax, dword [eax + ETH_DEVICE.packets_tx] |
ret |
.packets_rx: |
add eax, ETH_DRV_LIST |
mov eax, [eax] |
mov eax, [eax + ETH_DEVICE.packets_rx] |
mov eax, dword [eax] |
mov eax, dword [eax + ETH_DEVICE.packets_rx] |
ret |
.bytes_tx: |
add eax, ETH_DRV_LIST |
mov eax, [eax] |
mov eax, dword [eax] |
mov eax, dword [eax + ETH_DEVICE.bytes_tx + 4] |
ret |
.bytes_rx: |
add eax, ETH_DRV_LIST |
mov eax, [eax] |
mov eax, dword [eax] |
mov eax, dword [eax + ETH_DEVICE.bytes_rx + 4] |
ret |
/kernel/branches/net/network/icmp.inc |
---|
125,6 → 125,14 |
ret |
;-------------------------------- |
; |
; ICMP_Handler: |
151,6 → 159,11 |
mov byte [edx + ICMP_Packet.Type], ICMP_ECHOREPLY ; Change Packet type to reply |
mov word [edx + ICMP_Packet.Checksum], 0 ; Set checksum to 0, needed to calculate new checksum |
call ETH_struc2dev |
cmp edi,-1 |
je .dump |
inc [ICMP_PACKETS_RX+4*edi] |
; exchange dest and source address in IP header |
; exchange dest and source MAC in ETH header |
mov esi, [esp] |
197,8 → 210,12 |
xchg al, ah ; Convert to intel byte order |
mov word [edx + ICMP_Packet.Checksum], ax |
jmp ETH_Sender |
jmp ETH_Sender ; Send the reply |
.check_sockets: |
; TODO: validate the header & checksum. Discard buffer if error |
222,6 → 239,11 |
cmp ecx, SOCKETBUFFSIZE - SOCKETHEADERSIZE; TODO: fix this problem ! |
jg .dump |
call IPv4_dest_to_dev |
cmp edi,-1 |
je .dump |
inc [ICMP_PACKETS_RX+4*edi] |
DEBUGF 1,"Found valid ICMP packet for socket %x\n", esi |
lea ebx, [esi + SOCKET.lock] |
/kernel/branches/net/network/stack.inc |
---|
1,23 → 1,21 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; |
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;; STACK.INC ;; |
;; ;; |
;; TCP/IP stack for Menuet OS ;; |
;; BASIC TCP/IP stack for KolibriOS ;; |
;; ;; |
;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;; |
;; Written by hidnplayr@kolibrios.org ;; |
;; ;; |
;; See file COPYING for details ;; |
;; based on the work of Mike Hibbett, mikeh@oceanfree.net ;; |
;; but also Paolo Franchetti ;; |
;; ;; |
;; Version 0.7 ;; |
;; Added a timer per socket to allow delays when rx window ;; |
;; gets below 1KB ;; |
;; GNU GENERAL PUBLIC LICENSE ;; |
;; Version 2, June 1991 ;; |
;; ;; |
;;10.01.2007 Bugfix for checksum function from Paolo Franchetti ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
$Revision: 983 $ |
192,8 → 190,8 |
;---------------------------------------------------------------- |
; |
; System function to work with network devices (73) |
; |
; |
;---------------------------------------------------------------- |
align 4 |
242,13 → 240,12 |
;---------------------------------------------------------------- |
; |
; System Function To work with Protocols (75) |
; |
; |
;---------------------------------------------------------------- |
align 4 |
sys_protocols: |
cmp bh, MAX_NET_DEVICES ; Check if device number exists |
jge .doesnt_exist |
255,8 → 252,7 |
mov esi, ebx |
and esi, 0x0000ff00 |
shr esi, 6 |
cmp dword [esi + ETH_DRV_LIST], 0 ; check if driver is running TODO: check otehr lists too |
cmp dword [esi + ETH_DRV_LIST], 0 ; check if driver is running TODO: check other lists too |
je .doesnt_exist |
push .return ; return address (we will be using jumps instead of calls) |
273,7 → 269,7 |
cmp ax , IP_PROTO_UDP |
je UDP_API |
; cmp ax , IP_PROTO_TCP |
cmp ax , IP_PROTO_TCP |
; je TCP_API |
cmp ax, ETHER_ARP |
285,9 → 281,9 |
add esp,4 ; if we reached here, no function was called, so we need to balance stack |
.doesnt_exist: |
DEBUGF 1,"sys_protocols: invalid device specified!\n" |
DEBUGF 1,"sys_protocols: protocol %u doesnt exist on device %u!\n",ax, bh |
mov eax, -1 |
.return: |
mov [esp+32], eax |
mov [esp+28+4], eax |
ret |