/kernel/branches/kolibri-lldw/network/loopback.inc |
---|
0,0 → 1,184 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;; loopback.inc ;; |
;; ;; |
;; LoopBack device for KolibriOS ;; |
;; ;; |
;; Written by hidnplayr@kolibrios.org ;; |
;; ;; |
;; GNU GENERAL PUBLIC LICENSE ;; |
;; Version 2, June 1991 ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
$Revision$ |
iglobal |
align 4 |
LOOPBACK_DEVICE: |
.device_type dd NET_DEVICE_LOOPBACK |
.mtu dd NET_BUFFER_SIZE - NET_BUFF.data |
.name dd .namestr |
.unload dd loop_dummy |
.reset dd loop_dummy |
.transmit dd loop_input |
.link_state dd -1 |
.hwacc dd NET_HWACC_TCP_IPv4_IN + NET_HWACC_TCP_IPv4_OUT |
.bytes_tx dq ? |
.bytes_rx dq ? |
.packets_tx dd ? |
.packets_tx_err dd ? |
.packets_tx_drop dd ? |
.packets_tx_ovr dd ? |
.packets_rx dd ? |
.packets_rx_err dd ? |
.packets_rx_drop dd ? |
.packets_rx_ovr dd ? |
.namestr db 'loopback', 0 |
endg |
macro loop_init { |
local .fail |
mov ebx, LOOPBACK_DEVICE |
call net_add_device |
cmp eax, -1 |
je .fail |
mov [IPv4_address], 127 + 1 shl 24 |
mov [IPv4_subnet], 255 |
mov [IPv4_broadcast], 0xffffff00 + 127 |
.fail: |
} |
;-----------------------------------------------------------------; |
; ; |
; loop_dummy ; |
; ; |
; IN: / ; |
; ; |
; OUT: / ; |
; ; |
;-----------------------------------------------------------------; |
align 4 |
loop_dummy: |
ret |
;-----------------------------------------------------------------; |
; ; |
; loop_input ; |
; ; |
; IN: [esp+4] = Pointer to buffer ; |
; ; |
; OUT: eax = 0 on success, errorcode otherwise ; |
; ; |
;-----------------------------------------------------------------; |
align 4 |
loop_input: |
mov eax, [esp+4] |
; Update stats |
inc [LOOPBACK_DEVICE.packets_tx] |
inc [LOOPBACK_DEVICE.packets_rx] |
mov ecx, [eax + NET_BUFF.length] |
add dword[LOOPBACK_DEVICE.bytes_rx], ecx |
adc dword[LOOPBACK_DEVICE.bytes_rx + 4], 0 |
add dword[LOOPBACK_DEVICE.bytes_tx], ecx |
adc dword[LOOPBACK_DEVICE.bytes_tx + 4], 0 |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: ptr=%x size=%u\n", eax, ecx |
; Reverse buffptr and returnaddr on stack |
pop edx edi |
push edx .done edi |
; Set registers for protocol handlers |
lea edx, [eax + NET_BUFF.data] |
mov ebx, [eax + NET_BUFF.device] |
mov eax, [eax + NET_BUFF.type] |
; Place protocol handlers here |
cmp eax, AF_INET4 |
je ipv4_input |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", eax |
.dump: |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n" |
call net_buff_free |
or eax, -1 |
ret |
.done: |
xor eax, eax |
ret |
;-----------------------------------------------------------------; |
; ; |
; loop_output ; |
; ; |
; IN: ecx = packet size ; |
; edi = address family ; |
; ; |
; OUT: eax = start of net frame / 0 on error ; |
; ebx = to device structure ; |
; ecx = unchanged (packet size of embedded data) ; |
; edi = start of payload ; |
; ; |
;-----------------------------------------------------------------; |
align 4 |
loop_output: |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n" |
cmp ecx, [LOOPBACK_DEVICE.mtu] |
ja .too_large |
push ecx edi |
add ecx, NET_BUFF.data |
stdcall net_buff_alloc, ecx |
test eax, eax |
jz .out_of_ram |
pop edi |
mov [eax + NET_BUFF.type], edi |
mov ebx, LOOPBACK_DEVICE |
mov [eax + NET_BUFF.device], ebx |
pop ecx |
mov [eax + NET_BUFF.length], ecx |
lea edi, [eax + NET_BUFF.data] |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, ecx |
ret |
.too_large: |
DEBUGF DEBUG_NETWORK_ERROR, "LOOP_output: packet is too large\n" |
xor eax, eax |
ret |
.out_of_ram: |
DEBUGF DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n" |
add esp, 4+4 |
xor eax, eax |
ret |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:keywords |
+Revision |
\ No newline at end of property |
/kernel/branches/kolibri-lldw/network/PPPoE.inc |
---|
0,0 → 1,349 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2012-2021. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;; PPPoE.INC ;; |
;; ;; |
;; Part of the tcp/ip network stack for KolibriOS ;; |
;; ;; |
;; Written by hidnplayr@kolibrios.org ;; |
;; ;; |
;; GNU GENERAL PUBLIC LICENSE ;; |
;; Version 2, June 1991 ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
$Revision$ |
struct PPPoE_frame |
VersionAndType db ? |
Code db ? |
SessionID dw ? |
Length dw ? ; Length of payload, does NOT include the length PPPoE header. |
Payload rb 0 |
ends |
uglobal |
align 4 |
PPPoE_SID dw ? |
PPPoE_MAC dp ? |
endg |
;-----------------------------------------------------------------; |
; ; |
; pppoe_init: Reset all pppoe variables ; |
; ; |
;-----------------------------------------------------------------; |
macro pppoe_init { |
call pppoe_stop_connection |
} |
;-----------------------------------------------------------------; |
; ; |
; pppoe_discovery_input ; |
; ; |
; IN: [esp] = ptr to buffer ; |
; [esp+4] = size of buffer ; |
; ebx = ptr to device struct ; |
; ecx = size of PPP packet ; |
; edx = ptr to PPP header ; |
; ; |
; OUT: / ; |
; ; |
;-----------------------------------------------------------------; |
align 4 |
pppoe_discovery_input: |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_input\n" |
; First, find open PPPoE socket |
pusha |
mov ecx, socket_mutex |
call mutex_lock |
popa |
mov eax, net_sockets |
.next_socket: |
mov eax, [eax + SOCKET.NextPtr] |
or eax, eax |
jz .dump |
cmp [eax + SOCKET.Domain], AF_PPP |
jne .next_socket |
cmp [eax + SOCKET.Protocol], PPP_PROTO_ETHERNET |
jne .next_socket |
pusha |
mov ecx, socket_mutex |
call mutex_unlock |
popa |
; Now, send it to the this socket |
mov ecx, [esp + 4] |
mov esi, [esp] |
jmp socket_input |
.dump: |
pusha |
mov ecx, socket_mutex |
call mutex_unlock |
popa |
DEBUGF DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n' |
call net_buff_free |
ret |
;-----------------------------------------------------------------; |
; ; |
; pppoe_discovery_output ; |
; ; |
; IN: eax = socket pointer ; |
; ecx = number of bytes to send ; |
; esi = pointer to data ; |
; ; |
;-----------------------------------------------------------------; |
align 4 |
pppoe_discovery_output: |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: socket=%x buffer=%x size=%d\n", eax, esi, ecx |
; RFC2516: An entire PADI packet (including the PPPoE header) MUST NOT |
; exceed 1484 octets. |
cmp ecx, 1484 + 14 |
ja .bad |
; Check that device exists and is ethernet device |
mov ebx, [eax + SOCKET.device] |
cmp ebx, NET_DEVICES_MAX |
ja .bad |
mov ebx, [net_device_list + 4*ebx] |
test ebx, ebx |
jz .bad |
cmp [ebx + NET_DEVICE.device_type], NET_DEVICE_ETH |
jne .bad |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: device=%x\n", ebx |
; Create packet. |
stdcall net_buff_alloc, 1514 + NET_BUFF.data |
test eax, eax |
jz .bad |
; Net buffer header |
mov [eax + NET_BUFF.type], NET_BUFF_ETH |
mov [eax + NET_BUFF.device], ebx |
mov [eax + NET_BUFF.offset], NET_BUFF.data |
; Packet data |
mov edx, ecx |
lea edi, [eax + NET_BUFF.data] |
rep movsb |
; Packet size |
cmp edx, 60 |
ja @f |
mov edx, 60 |
@@: |
mov [eax + NET_BUFF.length], edx |
; Overwrite ETH source MAC with our own |
lea esi, [ebx + ETH_DEVICE.mac] |
lea edi, [eax + NET_BUFF.data + ETH_header.SrcMAC] |
movsd |
movsw |
; Allow only PPP_discovery, or LCP |
cmp word[edi], ETHER_PROTO_PPP_SESSION |
je @f |
mov word[edi], ETHER_PROTO_PPP_DISCOVERY |
@@: |
; And send the packet |
stdcall [ebx + NET_DEVICE.transmit], eax |
ret |
.bad: |
or eax, -1 |
ret |
;-----------------------------------------------------------------; |
; ; |
; pppoe_session_input ; |
; ; |
; IN: [esp] = ptr to buffer ; |
; [esp+4] = size of buffer ; |
; ebx = ptr to device struct ; |
; edx = ptr to PPP header ; |
; ecx = size of PPP packet ; |
; ; |
; OUT: / ; |
; ; |
;-----------------------------------------------------------------; |
align 4 |
pppoe_session_input: |
cmp [edx + PPPoE_frame.VersionAndType], 0x11 |
jne .dump |
cmp [edx + PPPoE_frame.Code], 0x00 |
jne .dump |
movzx ecx, [edx + PPPoE_frame.Length] |
xchg cl, ch |
mov ax, [edx + PPPoE_frame.SessionID] |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: session ID=%x, length=%u\n", ax, cx |
cmp ax, [PPPoE_SID] |
jne .dump |
mov ax, word [edx + PPPoE_frame.Payload] |
add edx, PPPoE_frame.Payload + 2 |
cmp ax, PPP_PROTO_IPv4 |
je ipv4_input |
; cmp ax, PPP_PROTO_IPv6 |
; je ipv6_input |
jmp pppoe_discovery_input ; Send LCP,CHAP,CBCP,... packets to the PPP dialer |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: Unknown protocol=%x\n", ax |
.dump: |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: dumping\n" |
call net_buff_free |
ret |
;-----------------------------------------------------------------; |
; ; |
; pppoe_output ; |
; ; |
; IN: ax = protocol ; |
; ebx = device ptr ; |
; ecx = packet size ; |
; ; |
; OUT: eax = buffer start ; |
; eax = 0 on error ; |
; ebx = device ptr ; |
; ecx = packet size ; |
; edx = size of complete buffer ; |
; edi = start of PPP payload ; |
; ; |
;-----------------------------------------------------------------; |
align 4 |
pppoe_output: |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: size=%u device=%x\n", ecx, ebx |
pushw ax |
pushw [PPPoE_SID] |
mov ax, ETHER_PROTO_PPP_SESSION |
add ecx, PPPoE_frame.Payload + 2 |
lea edx, [PPPoE_MAC] |
call eth_output |
jz .eth_error |
sub ecx, PPPoE_frame.Payload |
mov [edi + PPPoE_frame.VersionAndType], 0x11 |
mov [edi + PPPoE_frame.Code], 0 |
popw [edi + PPPoE_frame.SessionID] |
xchg cl, ch |
mov [edi + PPPoE_frame.Length], cx |
xchg cl, ch |
pop word [edi + PPPoE_frame.Payload] |
sub ecx, 2 |
add edi, PPPoE_frame.Payload + 2 |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: success!\n" |
ret |
.eth_error: |
add esp, 4 |
xor eax, eax |
ret |
align 4 |
pppoe_start_connection: |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_start_connection: %x\n", cx |
cmp [PPPoE_SID], 0 |
jne .fail |
mov [PPPoE_SID], cx |
mov dword [PPPoE_MAC], edx |
mov word [PPPoE_MAC + 4], si |
xor eax, eax |
ret |
.fail: |
or eax, -1 |
ret |
align 4 |
pppoe_stop_connection: |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_stop_connection\n" |
xor eax, eax |
mov [PPPoE_SID], ax |
mov dword [PPPoE_MAC], eax |
mov word [PPPoE_MAC + 4], ax |
ret |
;-----------------------------------------------------------------; |
; ; |
; pppoe_api: Part of system function 76 ; |
; ; |
; 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_start_connection ; 0 |
dd pppoe_stop_connection ; 1 |
.number = ($ - .table) / 4 - 1 |
.error: |
mov eax, -1 |
ret |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:keywords |
+Revision |
\ No newline at end of property |
/kernel/branches/kolibri-lldw/network/socket.inc |
---|
0,0 → 1,2534 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;; Part of the TCP/IP network stack for KolibriOS ;; |
;; ;; |
;; Written by hidnplayr@kolibrios.org, ;; |
;; and Clevermouse. ;; |
;; ;; |
;; Based on code by mike.dld ;; |
;; ;; |
;; GNU GENERAL PUBLIC LICENSE ;; |
;; Version 2, June 1991 ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
$Revision$ |
struct SOCKET |
NextPtr dd ? ; pointer to next socket in list |
PrevPtr dd ? ; pointer to previous socket in list |
Number dd ? ; socket number |
mutex MUTEX |
PID dd ? ; process ID |
TID dd ? ; thread ID |
Domain dd ? ; INET4/INET6/LOCAL/.. |
Type dd ? ; RAW/STREAM/DGRAM |
Protocol dd ? ; UDP/TCP/ARP/ICMP |
errorcode dd ? |
device dd ? ; device pointer, paired socket pointer if it's a local socket |
options dd ? |
state dd ? |
backlog dw ? ; number of incoming connections that can be queued |
snd_proc dd ? |
rcv_proc dd ? |
connect_proc dd ? |
ends |
struct IP_SOCKET SOCKET |
LocalIP rd 4 ; network byte order |
RemoteIP rd 4 ; network byte order |
ttl db ? |
rb 3 ; align |
ends |
struct TCP_SOCKET IP_SOCKET |
LocalPort dw ? ; network byte order |
RemotePort dw ? ; network byte order |
t_state dd ? ; TCB state |
t_rxtshift db ? |
rb 3 ; align |
t_rxtcur dd ? |
t_dupacks dd ? |
t_maxseg dd ? |
t_flags dd ? |
;--------------- |
; RFC783 page 21 |
; send sequence |
SND_UNA dd ? ; sequence number of unack'ed sent Packets |
SND_NXT dd ? ; next send sequence number to use |
SND_UP dd ? ; urgent pointer |
SND_WL1 dd ? ; the sequence number of the last segment used to update the send window |
SND_WL2 dd ? ; the acknowledgment number of the last segment used to update the send window |
ISS dd ? ; initial send sequence number |
SND_WND dd ? ; send window |
; receive sequence |
RCV_WND dd ? ; receive window |
RCV_NXT dd ? ; next receive sequence number to use |
RCV_UP dd ? ; urgent pointer |
IRS dd ? ; initial receive sequence number |
;--------------------- |
; Additional variables |
; receive variables |
RCV_ADV dd ? |
; retransmit variables |
SND_MAX dd ? |
; congestion control |
SND_CWND dd ? ; congestion window |
SND_SSTHRESH dd ? ; slow start threshold |
;---------------------- |
; Transmit timing stuff |
t_idle dd ? |
t_rtt dd ? ; round trip time |
t_rtseq dd ? |
t_srtt dd ? ; smoothed round trip time |
t_rttvar dd ? |
t_rttmin dd ? |
max_sndwnd dd ? |
;----------------- |
; Out-of-band data |
t_oobflags dd ? |
t_iobc dd ? |
t_softerror dd ? |
;--------- |
; RFC 1323 ; the order of next 4 elements may not change |
SND_SCALE db ? |
RCV_SCALE db ? |
requested_s_scale db ? |
request_r_scale db ? |
ts_recent dd ? ; a copy of the most-recent valid timestamp from the other end |
ts_recent_age dd ? |
last_ack_sent dd ? |
;------- |
; Timers |
timer_flags dd ? |
timer_retransmission dd ? ; rexmt |
timer_persist dd ? |
timer_keepalive dd ? ; keepalive/syn timeout |
timer_timed_wait dd ? ; also used as 2msl timer |
timer_connect dd ? |
; extra |
ts_ecr dd ? ; timestamp echo reply |
ts_val dd ? |
seg_next dd ? ; re-assembly queue |
ends |