31,24 → 31,31 |
DEBUG_NETWORK_ERROR = 1 |
DEBUG_NETWORK_VERBOSE = 0 |
|
MAX_NET_DEVICES = 16 |
NET_DEVICES_MAX = 16 |
ARP_BLOCK = 1 ; true or false |
|
MIN_EPHEMERAL_PORT = 49152 |
EPHEMERAL_PORT_MIN = 49152 |
EPHEMERAL_PORT_MAX = 61000 |
MIN_EPHEMERAL_PORT_N = 0x00C0 ; same in Network byte order (FIXME) |
MAX_EPHEMERAL_PORT = 61000 |
MAX_EPHEMERAL_PORT_N = 0x48EE ; same in Network byte order (FIXME) |
|
; Ethernet protocol numbers |
ETHER_ARP = 0x0608 |
ETHER_IPv4 = 0x0008 |
ETHER_IPv6 = 0xDD86 |
ETHER_PPP_DISCOVERY = 0x6388 |
ETHER_PPP_SESSION = 0x6488 |
ETHER_PROTO_ARP = 0x0608 |
ETHER_PROTO_IPv4 = 0x0008 |
ETHER_PROTO_IPv6 = 0xDD86 |
ETHER_PROTO_PPP_DISCOVERY = 0x6388 |
ETHER_PROTO_PPP_SESSION = 0x6488 |
|
; Internet protocol numbers |
IP_PROTO_IP = 0 |
IP_PROTO_ICMP = 1 |
IP_PROTO_TCP = 6 |
IP_PROTO_UDP = 17 |
|
; PPP protocol numbers |
PPP_IPv4 = 0x2100 |
PPP_IPV6 = 0x5780 |
PPP_PROTO_IPv4 = 0x2100 |
PPP_PROTO_IPV6 = 0x5780 |
PPP_PROTO_ETHERNET = 666 ; FIXME |
|
;Protocol family |
AF_UNSPEC = 0 |
55,17 → 62,8 |
AF_LOCAL = 1 |
AF_INET4 = 2 |
AF_INET6 = 10 |
AF_PPP = 777 |
AF_PPP = 777 ; FIXME |
|
; Internet protocol numbers |
IP_PROTO_IP = 0 |
IP_PROTO_ICMP = 1 |
IP_PROTO_TCP = 6 |
IP_PROTO_UDP = 17 |
|
; PPP protocol number |
PPP_PROTO_ETHERNET = 666 |
|
; Socket types |
SOCK_STREAM = 1 |
SOCK_DGRAM = 2 |
114,12 → 112,6 |
|
|
SOCKET_MAXDATA = 4096*32 ; must be 4096*(power of 2) where 'power of 2' is at least 8 |
|
; Network driver types |
NET_TYPE_LOOPBACK = 0 |
NET_TYPE_ETH = 1 |
NET_TYPE_SLIP = 2 |
|
MAX_backlog = 20 ; maximum backlog for stream sockets |
|
; Error Codes |
139,11 → 131,23 |
API_PPPOE = 6 |
API_IPv6 = 7 |
|
; Network device types |
NET_DEVICE_LOOPBACK = 0 |
NET_DEVICE_ETH = 1 |
NET_DEVICE_SLIP = 2 |
|
; Network link types (link protocols) |
NET_LINK_LOOPBACK = 0 ;;; Really a link type? |
NET_LINK_MAC = 1 ; Media access control (ethernet, isdn, ...) |
NET_LINK_PPP = 2 ; Point to Point Protocol (PPPoE, ...) |
NET_LINK_IEEE802.11 = 3 ; IEEE 802.11 (WiFi) |
|
; Hardware acceleration bits |
HWACC_TCP_IPv4 = 1 shl 0 |
|
struct NET_DEVICE |
|
type dd ? ; Type field |
device_type dd ? ; Type field |
mtu dd ? ; Maximal Transmission Unit |
name dd ? ; Ptr to 0 terminated string |
|
156,7 → 160,7 |
packets_tx dd ? ; |
packets_rx dd ? ; |
|
state dd ? ; link state (0 = no link) |
link_state dd ? ; link state (0 = no link) |
hwacc dd ? ; bitmask stating enabled HW accelerations (offload engines) |
|
ends |
213,8 → 217,7 |
uglobal |
|
NET_RUNNING dd ? |
NET_DEFAULT dd ? |
NET_DRV_LIST rd MAX_NET_DEVICES |
NET_DRV_LIST rd NET_DEVICES_MAX |
|
endg |
|
235,7 → 238,7 |
; Init the network drivers list |
xor eax, eax |
mov edi, NET_RUNNING |
mov ecx, (MAX_NET_DEVICES + 2) |
mov ecx, (NET_DEVICES_MAX + 2) |
rep stosd |
|
PPPoE_init |
250,6 → 253,8 |
|
SOCKET_init |
|
LOOP_init |
|
mov [net_tmr_count], 0 |
|
ret |
308,7 → 313,7 |
align 4 |
NET_link_changed: |
|
DEBUGF DEBUG_NETWORK_VERBOSE, "NET_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.state] |
DEBUGF DEBUG_NETWORK_VERBOSE, "NET_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.link_state] |
|
align 4 |
NET_send_event: |
345,13 → 350,13 |
|
DEBUGF DEBUG_NETWORK_VERBOSE, "NET_Add_Device: %x\n", ebx ;;; TODO: use mutex to lock net device list |
|
cmp [NET_RUNNING], MAX_NET_DEVICES |
cmp [NET_RUNNING], NET_DEVICES_MAX |
jae .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 ecx, NET_DEVICES_MAX ; 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 |
360,7 → 365,7 |
;---------------------------- |
; Find empty slot in the list |
xor eax, eax |
mov ecx, MAX_NET_DEVICES |
mov ecx, NET_DEVICES_MAX |
mov edi, NET_DRV_LIST |
|
repne scasd |
378,13 → 383,6 |
|
inc [NET_RUNNING] ; Indicate that one more network device is up and running |
|
cmp eax, 1 ; If it's the first network device, try to set it as default |
jne @f |
push eax |
call NET_set_default |
pop eax |
@@: |
|
call NET_send_event |
|
DEBUGF DEBUG_NETWORK_VERBOSE, "Device number: %u\n", eax |
399,41 → 397,9 |
|
;----------------------------------------------------------------- |
; |
; NET_set_default |
; |
; API to set the default interface |
; |
; IN: Device num in eax |
; OUT: Device num in eax, -1 on error |
; |
;----------------------------------------------------------------- |
align 4 |
NET_set_default: |
|
DEBUGF DEBUG_NETWORK_VERBOSE, "NET_set_default: device=%x\n", eax |
|
cmp eax, MAX_NET_DEVICES |
jae .error |
|
cmp [NET_DRV_LIST+eax*4], 0 |
je .error |
|
mov [NET_DEFAULT], eax |
|
DEBUGF DEBUG_NETWORK_VERBOSE, "NET_set_default: succes\n" |
ret |
|
.error: |
or eax, -1 |
DEBUGF DEBUG_NETWORK_ERROR, "NET_set_default: failed\n" |
ret |
|
|
;----------------------------------------------------------------- |
; |
; NET_Remove_Device: |
; |
; This function is called by etwork drivers, |
; This function is called by network drivers, |
; to unregister network devices from the kernel |
; |
; IN: Pointer to device structure in ebx |
446,28 → 412,12 |
cmp [NET_RUNNING], 0 |
je .error |
|
cmp [NET_DRV_LIST], ebx |
jne @f |
mov [NET_DRV_LIST], 0 |
cmp [NET_RUNNING], 1 |
je @f |
; there are still active devices, find one and make it default |
xor eax, eax |
mov ecx, MAX_NET_DEVICES |
mov edi, NET_DRV_LIST |
repe scasd |
je @f |
shr edi, 2 |
dec edi |
mov [NET_DEFAULT], edi |
@@: |
|
;---------------------------- |
; Find the driver in the list |
|
mov eax, ebx |
mov ecx, MAX_NET_DEVICES |
mov edi, NET_DRV_LIST+4 |
mov ecx, NET_DEVICES_MAX |
mov edi, NET_DRV_LIST |
|
repne scasd |
jnz .error |
477,10 → 427,11 |
|
xor eax, eax |
mov dword [edi-4], eax |
dec [NET_RUNNING] |
|
call NET_send_event |
|
dec [NET_RUNNING] |
xor eax, eax |
ret |
|
.error: |
501,7 → 452,7 |
NET_ptr_to_num: |
push ecx |
|
mov ecx, MAX_NET_DEVICES |
mov ecx, NET_DEVICES_MAX |
mov edi, NET_DRV_LIST |
|
.loop: |
645,20 → 596,21 |
|
;---------------------------------------------------------------- |
; |
; System function to work with network devices (75) |
; System function to work with network devices (74) |
; |
;---------------------------------------------------------------- |
align 4 |
sys_network: ; FIXME: make default device easily accessible |
sys_network: |
|
cmp ebx, -1 |
jne @f |
|
mov eax, [NET_RUNNING] |
jmp .return |
mov [esp+32], eax |
ret |
|
@@: |
cmp bh, MAX_NET_DEVICES ; Check if device number exists |
cmp bh, NET_DEVICES_MAX ; Check if device number exists |
jae .doesnt_exist |
|
mov esi, ebx |
682,17 → 634,20 |
dd .stop ; 3 |
dd .get_ptr ; 4 |
dd .get_drv_name ; 5 |
dd .set_default ; 6 |
|
dd .packets_tx ; 6 |
dd .packets_rx ; 7 |
dd .bytes_tx ; 8 |
dd .bytes_rx ; 9 |
dd .state ; 10 |
.number = ($ - .table) / 4 - 1 |
|
.get_type: ; 0 = Get device type (ethernet/token ring/...) |
.get_type: |
mov eax, [eax + NET_DEVICE.device_type] |
mov [esp+32], eax |
ret |
|
mov eax, [eax + NET_DEVICE.type] |
jmp .return |
|
|
.get_dev_name: ; 1 = Get device name |
|
.get_dev_name: |
mov esi, [eax + NET_DEVICE.name] |
mov edi, ecx |
|
700,43 → 655,66 |
rep movsd |
|
xor eax, eax |
jmp .return |
mov [esp+32], eax |
ret |
|
.reset: ; 2 = Reset the device |
|
.reset: |
call [eax + NET_DEVICE.reset] |
jmp .return |
mov [esp+32], eax |
ret |
|
.stop: ; 3 = Stop driver for this device |
|
.stop: |
call [eax + NET_DEVICE.unload] |
jmp .return |
mov [esp+32], eax |
ret |
|
|
.get_ptr: ; 4 = Get driver pointer |
.get_ptr: |
mov [esp+32], eax |
ret |
|
jmp .return |
|
|
.get_drv_name: ; 5 = Get driver name |
|
.get_drv_name: |
xor eax, eax |
jmp .return |
mov [esp+32], eax |
ret |
|
.packets_tx: |
mov eax, [eax + NET_DEVICE.packets_tx] |
mov [esp+32], eax |
ret |
|
.set_default: ; 6 = Set default device |
.packets_rx: |
mov eax, [eax + NET_DEVICE.packets_rx] |
mov [esp+32], eax |
ret |
|
call NET_set_default |
jmp .return |
.bytes_tx: |
mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4] |
mov [esp+20], ebx |
mov eax, dword [eax + NET_DEVICE.bytes_tx] |
mov [esp+32], eax |
ret |
|
.doesnt_exist: |
mov eax, -1 |
.bytes_rx: |
mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4] |
mov [esp+20], ebx |
mov eax, dword [eax + NET_DEVICE.bytes_rx] |
mov [esp+32], eax |
ret |
|
.return: |
.state: |
mov eax, [eax + NET_DEVICE.link_state] |
mov [esp+32], eax |
ret |
|
|
.doesnt_exist: |
mov dword[esp+32], -1 |
ret |
|
|
|
;---------------------------------------------------------------- |
; |
; System function to work with protocols (76) |
744,7 → 722,7 |
;---------------------------------------------------------------- |
align 4 |
sys_protocols: |
cmp bh, MAX_NET_DEVICES ; Check if device number exists |
cmp bh, NET_DEVICES_MAX ; Check if device number exists |
jae .doesnt_exist |
|
mov esi, ebx |