Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 2613 → Rev 2614

/kernel/branches/net/network/ARP.inc
18,19 → 18,19
 
$Revision$
 
ARP_NO_ENTRY equ 0
ARP_VALID_MAPPING equ 1
ARP_AWAITING_RESPONSE equ 2
ARP_RESPONSE_TIMEOUT equ 3
ARP_NO_ENTRY = 0
ARP_VALID_MAPPING = 1
ARP_AWAITING_RESPONSE = 2
ARP_RESPONSE_TIMEOUT = 3
 
ARP_REQUEST_TTL equ 31 ; 20 s
ARP_ENTRY_TTL equ 937 ; 600 s
ARP_STATIC_ENTRY equ -1
ARP_REQUEST_TTL = 31 ; 20 s
ARP_ENTRY_TTL = 937 ; 600 s
ARP_STATIC_ENTRY = -1
 
ARP_REQ_OPCODE equ 0x0100 ; request
ARP_REP_OPCODE equ 0x0200 ; reply
ARP_REQ_OPCODE = 0x0100 ; request
ARP_REP_OPCODE = 0x0200 ; reply
 
ARP_TABLE_SIZE equ 20 ; Size of table
ARP_TABLE_SIZE = 20 ; Size of table
 
struct ARP_entry
 
570,37 → 570,35
;
;-----------------------------------------------------------------
align 4
ARP_API:
ARP_api:
 
movzx eax, bh
shl eax, 2
 
test bl, bl
jz .packets_tx ; 0
dec bl
jz .packets_rx ; 1
dec bl
jz .entries ; 2
dec bl
jz .read ; 3
dec bl
jz .write ; 4
dec bl
jz .remove ; 5
dec bl
and ebx, 0xff
cmp ebx, .number
ja .error
jmp dword [.table + 4*ebx]
 
.table:
dd .packets_tx ; 0
dd .packets_rx ; 1
dd .entries ; 2
dd .read ; 3
dd .write ; 4
dd .remove ; 5
.number = ($ - .table) / 4 - 1
 
.error:
mov eax, -1
ret
 
.packets_tx:
add eax, ARP_PACKETS_TX
mov eax, [eax]
mov eax, [ARP_PACKETS_TX + eax]
ret
 
.packets_rx:
add eax, ARP_PACKETS_RX
mov eax, [eax]
mov eax, [ARP_PACKETS_RX + eax]
ret
 
.entries:
/kernel/branches/net/network/IPv4.inc
18,9 → 18,9
 
$Revision$
 
MAX_FRAGMENTS equ 64
MAX_IP equ MAX_NET_DEVICES
IP_MAX_INTERFACES equ MAX_IP
MAX_FRAGMENTS = 64
MAX_IP = MAX_NET_DEVICES
IP_MAX_INTERFACES = MAX_IP
 
struct IPv4_header
 
194,7 → 194,8
; IN: Pointer to buffer in [esp]
; size of buffer in [esp+4]
; pointer to device struct in ebx
; pointer to IP Packet data in edx
; pointer to IP header in edx
; size of IP packet in ecx
; OUT: /
;
;-----------------------------------------------------------------
943,86 → 944,72
;
;---------------------------------------------------------------------------
align 4
IPv4_API:
IPv4_api:
 
movzx eax, bh
shl eax, 2
 
test bl, bl
jz .packets_tx ; 0
dec bl
jz .packets_rx ; 1
dec bl
jz .read_ip ; 2
dec bl
jz .write_ip ; 3
dec bl
jz .read_dns ; 4
dec bl
jz .write_dns ; 5
dec bl
jz .read_subnet ; 6
dec bl
jz .write_subnet ; 7
dec bl
jz .read_gateway ; 8
dec bl
jz .write_gateway ; 9
and ebx, 0xff
cmp ebx, .number
ja .error
jmp dword [.table + 4*ebx]
 
.table:
dd .packets_tx ; 0
dd .packets_rx ; 1
dd .write_ip ; 3
dd .read_dns ; 4
dd .write_dns ; 5
dd .read_subnet ; 6
dd .write_subnet ; 7
dd .read_gateway ; 8
dd .write_gateway ; 9
.number = ($ - .table) / 4 - 1
 
.error:
mov eax, -1
ret
 
.packets_tx:
add eax, IP_PACKETS_TX
mov eax, [eax]
mov eax, [IP_PACKETS_TX + eax]
ret
 
.packets_rx:
add eax, IP_PACKETS_RX
mov eax, [eax]
mov eax, [IP_PACKETS_RX + eax]
ret
 
.read_ip:
add eax, IP_LIST
mov eax, [eax]
mov eax, [IP_LIST + eax]
ret
 
.write_ip:
add eax, IP_LIST
mov [eax], ecx
mov [IP_LIST + eax], ecx
xor eax, eax
ret
 
.read_dns:
add eax, DNS_LIST
mov eax, [eax]
mov eax, [DNS_LIST + eax]
ret
 
.write_dns:
add eax, DNS_LIST
mov [eax], ecx
mov [DNS_LIST + eax], ecx
xor eax, eax
ret
 
.read_subnet:
add eax, SUBNET_LIST
mov eax, [eax]
mov eax, [SUBNET_LIST + eax]
ret
 
.write_subnet:
add eax, SUBNET_LIST
mov [eax], ecx
mov [SUBNET_LIST + eax], ecx
xor eax, eax
ret
 
.read_gateway:
add eax, GATEWAY_LIST
mov eax, [eax]
mov eax, [GATEWAY_LIST + eax]
ret
 
.write_gateway:
add eax, GATEWAY_LIST
mov [eax], ecx
mov [GATEWAY_LIST + eax], ecx
xor eax, eax
ret
/kernel/branches/net/network/PPPoE.inc
0,0 → 1,286
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2009-2012. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; Clevermouse & hidnplayr ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
struct PPPoE_header
 
VersionAndType db ?
Code db ?
SessionID dw ?
Length dw ? ; Length of payload, does NOT include the length PPPoE header.
 
ends
 
struct PPPoE_connection
 
next dd ? ; pointer to next connection
prev dd ? ; pointer to previous connection
 
pid dd ? ; identifier of base application
 
datalen dd ? ; length of received data
recvbuf rb 1500 ; buffer for received data
sendbuf rb 1500 ; buffer for data to send
 
ends
 
iglobal
align 4
PPPoE.head dd PPPoE.head
PPPoE.tail dd PPPoE.head
endg
 
uglobal
PPPoE.cur_receiver dd ?
PPPoE.cur_receiver_ptr dd ?
PPPoE.cur_receiver_len dd ?
endg
 
 
; Allocates internal structure for future PPPoE actions.
align 4
PPPoE_alloc_connection:
 
; 1. Allocate memory in the kernel area.
stdcall kernel_alloc, sizeof.PPPoE_connection
 
; 1a. If memory allocation failed, return NULL.
test eax, eax
jz .nothing
 
; 2. Copy PID of caller to the structure.
mov edx, [CURRENT_TASK]
mov [eax + PPPoE_connection.pid], edx
 
; 3. Insert the structure to the list of all connections.
mov [eax + PPPoE_connection.next], PPPoE.head
mov edx, [PPPoE.tail]
mov [eax + PPPoE_connection.prev], edx
mov [edx + PPPoE_connection.next], eax
mov [PPPoE.tail], eax
 
.nothing:
ret
 
 
align 4
PPPoE_free_connection:
 
; 1. Check that the caller is the owner of this connection.
mov eax, [CURRENT_TASK]
cmp [ebx+PPPoE_connection.pid], eax
jnz .nothing
 
; 2. Delete the structure from the list of all connections.
mov eax, [ebx+PPPoE_connection.next]
mov edx, [ebx+PPPoE_connection.prev]
mov [eax+PPPoE_connection.prev], edx
mov [edx+PPPoE_connection.next], eax
 
; 3. Free the memory.
stdcall kernel_free, ebx
 
.nothing:
ret
 
 
; Send PADI packet
 
; ebx (ecx in app) = size of buffer for PPPoE offers, must be at least 1514
; ecx (edx in app) = size of tags, 0 means "use default"
; edx (esi in app) = pointer to buffer for PPPoE offers
; esi (edi in app) = pointer to tags, ignored if 'size of tags' == 0
align 4
PPPoE_send_init:
 
; 1. Check length.
cmp ebi, 1514
jb .bad
 
; RFC2516: An entire PADI packet (including the PPPoE header) MUST NOT
; exceed 1484 octets.
; PPPoE header is 6 bytes long, so maximum length of tags is 1478.
cmp ecx, 1478
ja .bad
 
; 2. Check that no one listen for offers.
cmp [PPPoE.cur_receiver], 0
jnz .bad
 
; 3. Remember PID and data pointer of current listener.
push [CURRENT_TASK]
pop [PPPoE.cur_receiver]
mov [PPPoE.cur_receiver_ptr], edx
mov [PPPoE.cur_receiver_len], ebx
and dword [edx], 0 ; no offers yet
 
; 4. Create packet.
test ecx, ecx
jnz @f
mov esi, .default_payload
mov ecx, .default_payload_length
@@:
 
mov edx, [NET_DRV_LIST] ;;;; FIXME
lea eax, [ebx + ETH_DEVICE.mac] ; Source Address
mov edx, ETH_BROADCAST ; Destination Address
add ecx, sizeof.PPPoE_header ; Data size
mov di, ETHER_PPP_DISCOVERY ; Protocol
call ETH_output
jz .eth_error
 
push edx eax
 
; 4b. Set ver=1, type=1 (=> first byte 0x11), code=9 (PADI packet), session=0
mov dword [edi], (0x09 shl 8) + 0x11
 
; 4c. Set payload length.
mov [edi+4], ch
mov [edi+5], cl
 
; 4e. Copy given tags.
rep movsb
 
; 5. Send packet.
call [ebx + NET_DEVICE.transmit]
; 6. Return.
xor eax, eax
ret
 
.bad:
or eax, -1
ret
 
.default_payload:
; Service-Name tag with zero length
dw 0x0101, 0x0000
.default_payload_length = $ - .default_payload
 
 
; Stop receiving PADO packets
align 4
PPPoE_stop_offers:
 
; Only the listener can stop listen. ;;; TODO: make sure this function is called when process gets terminated
mov eax, [CURRENT_TASK]
cmp [PPPoE.cur_receiver], eax
jnz .bad
xor eax, eax
mov [PPPoE.cur_receiver_ptr], eax
mov [PPPoE.cur_receiver], eax
ret
 
.bad:
or eax, -1
ret
 
; Send PPPoE data in Discovery stage
align 4
PPPoE_send_discovery:
ret
 
; Receive PPPoE data in Discovery stage
align 4
PPPoE_receive_discovery:
ret
 
 
 
;-----------------------------------------------------------------
;
; PPPoE discovery input
;
; Handler of received Ethernet packet with type = Discovery
;
;
; IN: Pointer to buffer in [esp]
; size of buffer in [esp+4]
; pointer to device struct in ebx
; pointer to PPP header in edx
; size of PPP packet in ecx
; OUT: /
;
;-----------------------------------------------------------------
align 4
PPPoE_discovery_input:
 
; 1. Minimum 6 bytes for PPPoE header.
cmp ecx, sizeof.PPPoE_header
jb .bad
 
; 1. Ignore packets with ver<>1 and/or type<>1.
cmp [edx + PPPoE_header.VersionAndType], 0x11
jnz .bad
 
; 2. Code must be either 7 for Offer,
; or 0x65 for Session-Confirmation, or 0xa7 for Terminate.
; Because only Initiation/Offers are supported, we expect only value 7.
cmp [edx + PPPoE_header.Code], 7
jnz .bad
 
; 3. Session ID must be zero for Offers.
cmp [edx + PPPoE_header.SessionID], 0
jnz .bad
 
; 4. Payload length
rol [edx + PPPoE_header.Length], 8 ; Convert INET byte order to intel
 
; 5. Ignore packet if nobody is listening.
cmp [PPPoE.cur_receiver], 0
jz .bad
 
; 6. Good, now copy the received packet to the buffer of listener.
 
;;; TODO
 
.bad:
DEBUGF 1,'K : PPPoE - dumped\n'
call kernel_free
add esp, 4 ; pop (balance stack)
ret
 
 
 
 
;---------------------------------------------------------------------------
;
; PPPoE API
;
; This function is called by system function 75
;
; IN: subfunction number in bl
; device number in bh
; ecx, edx, .. depends on subfunction
;
; OUT:
;
;---------------------------------------------------------------------------
align 4
PPPoE_api:
 
movzx eax, bh
shl eax, 2
 
and ebx, 0xff
cmp ebx, .number
ja .error
jmp dword [.table + 4*ebx]
 
.table:
dd PPPoE_send_init ; 0
dd PPPoE_stop_offers ; 1
dd PPPoE_alloc_connection ; 3
dd PPPoE_free_connection ; 4
dd PPPoE_send_discovery ; 5
dd PPPoE_receive_discovery ; 6
.number = ($ - .table) / 4 - 1
 
.error:
mov eax, -1
ret
/kernel/branches/net/network/ethernet.inc
24,7 → 24,7
 
ends
 
ETH_FRAME_MINIMUM equ 60
ETH_FRAME_MINIMUM = 60
 
struct ETH_DEVICE NET_DEVICE
 
78,7 → 78,7
je ARP_input
 
; cmp ax, ETHER_PPP_DISCOVERY
; je PPPOE_discovery
; je PPPoE_discovery_input
 
DEBUGF 2,"Unknown ethernet packet type %x\n", ax
 
173,30 → 173,29
;
;-----------------------------------------------------------------
align 4
ETH_API:
ETH_api:
 
cmp bh, MAX_NET_DEVICES
ja .error
movzx eax, bh
shl eax, 2
 
mov eax, dword [NET_DRV_LIST + eax]
mov eax, dword [NET_DRV_LIST + 4*eax]
cmp [eax + NET_DEVICE.type], NET_TYPE_ETH
jne .error
 
test bl, bl
jz .packets_tx ; 0
dec bl
jz .packets_rx ; 1
dec bl
jz .bytes_tx ; 2
dec bl
jz .bytes_rx ; 3
dec bl
jz .read_mac ; 4
dec bl
jz .write_mac ; 5
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
dd .write_mac ; 5
.number = ($ - .table) / 4 - 1
 
.error:
DEBUGF 2,"Device is not ethernet type\n"
or eax, -1
/kernel/branches/net/network/icmp.inc
21,69 → 21,69
 
; ICMP types & codes
 
ICMP_ECHOREPLY equ 0 ; echo reply message
ICMP_ECHOREPLY = 0 ; echo reply message
 
ICMP_UNREACH equ 3
ICMP_UNREACH_NET equ 0 ; bad net
ICMP_UNREACH_HOST equ 1 ; bad host
ICMP_UNREACH_PROTOCOL equ 2 ; bad protocol
ICMP_UNREACH_PORT equ 3 ; bad port
ICMP_UNREACH_NEEDFRAG equ 4 ; IP_DF caused drop
ICMP_UNREACH_SRCFAIL equ 5 ; src route failed
ICMP_UNREACH_NET_UNKNOWN equ 6 ; unknown net
ICMP_UNREACH_HOST_UNKNOWN equ 7 ; unknown host
ICMP_UNREACH_ISOLATED equ 8 ; src host isolated
ICMP_UNREACH_NET_PROHIB equ 9 ; prohibited access
ICMP_UNREACH_HOST_PROHIB equ 10 ; ditto
ICMP_UNREACH_TOSNET equ 11 ; bad tos for net
ICMP_UNREACH_TOSHOST equ 12 ; bad tos for host
ICMP_UNREACH_FILTER_PROHIB equ 13 ; admin prohib
ICMP_UNREACH_HOST_PRECEDENCE equ 14 ; host prec vio.
ICMP_UNREACH_PRECEDENCE_CUTOFF equ 15 ; prec cutoff
ICMP_UNREACH = 3
ICMP_UNREACH_NET = 0 ; bad net
ICMP_UNREACH_HOST = 1 ; bad host
ICMP_UNREACH_PROTOCOL = 2 ; bad protocol
ICMP_UNREACH_PORT = 3 ; bad port
ICMP_UNREACH_NEEDFRAG = 4 ; IP_DF caused drop
ICMP_UNREACH_SRCFAIL = 5 ; src route failed
ICMP_UNREACH_NET_UNKNOWN = 6 ; unknown net
ICMP_UNREACH_HOST_UNKNOWN = 7 ; unknown host
ICMP_UNREACH_ISOLATED = 8 ; src host isolated
ICMP_UNREACH_NET_PROHIB = 9 ; prohibited access
ICMP_UNREACH_HOST_PROHIB = 10 ; ditto
ICMP_UNREACH_TOSNET = 11 ; bad tos for net
ICMP_UNREACH_TOSHOST = 12 ; bad tos for host
ICMP_UNREACH_FILTER_PROHIB = 13 ; admin prohib
ICMP_UNREACH_HOST_PRECEDENCE = 14 ; host prec vio.
ICMP_UNREACH_PRECEDENCE_CUTOFF = 15 ; prec cutoff
 
ICMP_SOURCEQUENCH equ 4 ; Packet lost, slow down
ICMP_SOURCEQUENCH = 4 ; Packet lost, slow down
 
ICMP_REDIRECT equ 5 ; shorter route, codes:
ICMP_REDIRECT_NET equ 0 ; for network
ICMP_REDIRECT_HOST equ 1 ; for host
ICMP_REDIRECT_TOSNET equ 2 ; for tos and net
ICMP_REDIRECT_TOSHOST equ 3 ; for tos and host
ICMP_REDIRECT = 5 ; shorter route, codes:
ICMP_REDIRECT_NET = 0 ; for network
ICMP_REDIRECT_HOST = 1 ; for host
ICMP_REDIRECT_TOSNET = 2 ; for tos and net
ICMP_REDIRECT_TOSHOST = 3 ; for tos and host
 
ICMP_ALTHOSTADDR equ 6 ; alternate host address
ICMP_ECHO equ 8 ; echo service
ICMP_ROUTERADVERT equ 9 ; router advertisement
ICMP_ROUTERADVERT_NORMAL equ 0 ; normal advertisement
ICMP_ROUTERADVERT_NOROUTE_COMMON equ 16 ; selective routing
ICMP_ALTHOSTADDR = 6 ; alternate host address
ICMP_ECHO = 8 ; echo service
ICMP_ROUTERADVERT = 9 ; router advertisement
ICMP_ROUTERADVERT_NORMAL = 0 ; normal advertisement
ICMP_ROUTERADVERT_NOROUTE_COMMON= 16 ; selective routing
 
ICMP_ROUTERSOLICIT equ 10 ; router solicitation
ICMP_TIMXCEED equ 11 ; time exceeded, code:
ICMP_TIMXCEED_INTRANS equ 0 ; ttl==0 in transit
ICMP_TIMXCEED_REASS equ 1 ; ttl==0 in reass
ICMP_ROUTERSOLICIT = 10 ; router solicitation
ICMP_TIMXCEED = 11 ; time exceeded, code:
ICMP_TIMXCEED_INTRANS = 0 ; ttl==0 in transit
ICMP_TIMXCEED_REASS = 1 ; ttl==0 in reass
 
ICMP_PARAMPROB equ 12 ; ip header bad
ICMP_PARAMPROB_ERRATPTR equ 0 ; error at param ptr
ICMP_PARAMPROB_OPTABSENT equ 1 ; req. opt. absent
ICMP_PARAMPROB_LENGTH equ 2 ; bad length
ICMP_PARAMPROB = 12 ; ip header bad
ICMP_PARAMPROB_ERRATPTR = 0 ; error at param ptr
ICMP_PARAMPROB_OPTABSENT = 1 ; req. opt. absent
ICMP_PARAMPROB_LENGTH = 2 ; bad length
 
ICMP_TSTAMP equ 13 ; timestamp request
ICMP_TSTAMPREPLY equ 14 ; timestamp reply
ICMP_IREQ equ 15 ; information request
ICMP_IREQREPLY equ 16 ; information reply
ICMP_MASKREQ equ 17 ; address mask request
ICMP_MASKREPLY equ 18 ; address mask reply
ICMP_TRACEROUTE equ 30 ; traceroute
ICMP_DATACONVERR equ 31 ; data conversion error
ICMP_MOBILE_REDIRECT equ 32 ; mobile host redirect
ICMP_IPV6_WHEREAREYOU equ 33 ; IPv6 where-are-you
ICMP_IPV6_IAMHERE equ 34 ; IPv6 i-am-here
ICMP_MOBILE_REGREQUEST equ 35 ; mobile registration req
ICMP_MOBILE_REGREPLY equ 36 ; mobile registreation reply
ICMP_SKIP equ 39 ; SKIP
ICMP_TSTAMP = 13 ; timestamp request
ICMP_TSTAMPREPLY = 14 ; timestamp reply
ICMP_IREQ = 15 ; information request
ICMP_IREQREPLY = 16 ; information reply
ICMP_MASKREQ = 17 ; address mask request
ICMP_MASKREPLY = 18 ; address mask reply
ICMP_TRACEROUTE = 30 ; traceroute
ICMP_DATACONVERR = 31 ; data conversion error
ICMP_MOBILE_REDIRECT = 32 ; mobile host redirect
ICMP_IPV6_WHEREAREYOU = 33 ; IPv6 where-are-you
ICMP_IPV6_IAMHERE = 34 ; IPv6 i-am-here
ICMP_MOBILE_REGREQUEST = 35 ; mobile registration req
ICMP_MOBILE_REGREPLY = 36 ; mobile registreation reply
ICMP_SKIP = 39 ; SKIP
 
ICMP_PHOTURIS equ 40 ; Photuris
ICMP_PHOTURIS_UNKNOWN_INDEX equ 1 ; unknown sec index
ICMP_PHOTURIS_AUTH_FAILED equ 2 ; auth failed
ICMP_PHOTURIS_DECRYPT_FAILED equ 3 ; decrypt failed
ICMP_PHOTURIS = 40 ; Photuris
ICMP_PHOTURIS_UNKNOWN_INDEX = 1 ; unknown sec index
ICMP_PHOTURIS_AUTH_FAILED = 2 ; auth failed
ICMP_PHOTURIS_DECRYPT_FAILED = 3 ; decrypt failed
 
 
 
410,7 → 410,7
;
;-----------------------------------------------------------------
align 4
ICMP_API:
ICMP_api:
 
movzx eax, bh
shl eax, 2
425,11 → 425,9
ret
 
.packets_tx:
add eax, ICMP_PACKETS_TX
mov eax, [eax]
mov eax, [ICMP_PACKETS_TX + eax]
ret
 
.packets_rx:
add eax, ICMP_PACKETS_RX
mov eax, [eax]
mov eax, [ICMP_PACKETS_RX + eax]
ret
/kernel/branches/net/network/socket.inc
171,11 → 171,11
ends
 <