2009-10-06 00:47:27 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2012-02-21 12:44:51 +04:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2009-10-06 00:47:27 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; Part of the tcp/ip network stack for KolibriOS ;;
|
|
|
|
;; ;;
|
2010-07-12 03:13:12 +04:00
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; Based on the code of 4.4BSD ;;
|
2009-10-06 00:47:27 +04:00
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2009-10-12 18:39:59 +04:00
|
|
|
$Revision$
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2010-07-12 03:13:12 +04:00
|
|
|
; Socket states
|
2012-04-15 01:15:00 +04:00
|
|
|
TCPS_CLOSED = 0
|
|
|
|
TCPS_LISTEN = 1
|
|
|
|
TCPS_SYN_SENT = 2
|
|
|
|
TCPS_SYN_RECEIVED = 3
|
|
|
|
TCPS_ESTABLISHED = 4
|
|
|
|
TCPS_CLOSE_WAIT = 5
|
|
|
|
TCPS_FIN_WAIT_1 = 6
|
|
|
|
TCPS_CLOSING = 7
|
|
|
|
TCPS_LAST_ACK = 8
|
|
|
|
TCPS_FIN_WAIT_2 = 9
|
|
|
|
TCPS_TIMED_WAIT = 10
|
2010-07-12 03:13:12 +04:00
|
|
|
|
|
|
|
; Socket Flags
|
2012-04-15 01:15:00 +04:00
|
|
|
TF_ACKNOW = 1 shl 0 ; ack peer immediately
|
|
|
|
TF_DELACK = 1 shl 1 ; ack, but try to delay it
|
|
|
|
TF_NODELAY = 1 shl 2 ; don't delay packets to coalesce
|
|
|
|
TF_NOOPT = 1 shl 3 ; don't use tcp options
|
|
|
|
TF_SENTFIN = 1 shl 4 ; have sent FIN
|
|
|
|
TF_REQ_SCALE = 1 shl 5 ; have/will request window scaling
|
|
|
|
TF_RCVD_SCALE = 1 shl 6 ; other side has requested scaling
|
|
|
|
TF_REQ_TSTMP = 1 shl 7 ; have/will request timestamps
|
|
|
|
TF_RCVD_TSTMP = 1 shl 8 ; a timestamp was received in SYN
|
|
|
|
TF_SACK_PERMIT = 1 shl 9 ; other side said I could SACK
|
2010-07-12 03:13:12 +04:00
|
|
|
|
|
|
|
; Segment flags
|
2012-04-15 01:15:00 +04:00
|
|
|
TH_FIN = 1 shl 0
|
|
|
|
TH_SYN = 1 shl 1
|
|
|
|
TH_RST = 1 shl 2
|
|
|
|
TH_PUSH = 1 shl 3
|
|
|
|
TH_ACK = 1 shl 4
|
|
|
|
TH_URG = 1 shl 5
|
2010-07-12 03:13:12 +04:00
|
|
|
|
|
|
|
; Segment header options
|
2012-04-15 01:15:00 +04:00
|
|
|
TCP_OPT_EOL = 0 ; End of option list.
|
|
|
|
TCP_OPT_NOP = 1 ; No-Operation.
|
|
|
|
TCP_OPT_MAXSEG = 2 ; Maximum Segment Size.
|
|
|
|
TCP_OPT_WINDOW = 3 ; window scale
|
|
|
|
TCP_OPT_TIMESTAMP = 8
|
2010-07-12 03:13:12 +04:00
|
|
|
|
2010-07-15 22:54:19 +04:00
|
|
|
; Fundamental timer values
|
2012-04-15 01:15:00 +04:00
|
|
|
TCP_time_MSL = 47 ; max segment lifetime (30s)
|
|
|
|
TCP_time_re_min = 2 ; min retransmission (1,28s)
|
|
|
|
TCP_time_re_max = 100 ; max retransmission (64s)
|
|
|
|
TCP_time_pers_min = 8 ; min persist (5,12s)
|
|
|
|
TCP_time_pers_max = 94 ; max persist (60,16s)
|
|
|
|
TCP_time_keep_init = 118 ; connectione stablishment (75,52s)
|
|
|
|
TCP_time_keep_idle = 4608 ; idle time before 1st probe (2h)
|
|
|
|
TCP_time_keep_interval = 118 ; between probes when no response (75,52s)
|
|
|
|
TCP_time_rtt_default = 5 ; default Round Trip Time (3,2s)
|
|
|
|
TCP_time_srtt_default = 0 ;
|
2010-07-15 22:54:19 +04:00
|
|
|
|
|
|
|
; timer constants
|
2012-04-15 01:15:00 +04:00
|
|
|
TCP_max_rxtshift = 12 ; max retransmissions waiting for ACK
|
|
|
|
TCP_max_keepcnt = 8 ; max keepalive probes
|
2010-07-15 22:54:19 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
;
|
2012-04-15 01:15:00 +04:00
|
|
|
TCP_max_winshift = 14
|
|
|
|
TCP_max_win = 65535
|
2010-07-15 22:54:19 +04:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
TCP_re_xmit_thresh = 3
|
2011-01-25 01:01:54 +03:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
TCP_mss_default = 1480 ; default max segment size
|
2011-11-09 03:06:26 +04:00
|
|
|
|
2012-04-14 22:20:01 +04:00
|
|
|
struct TCP_header
|
|
|
|
|
|
|
|
SourcePort dw ?
|
|
|
|
DestinationPort dw ?
|
|
|
|
SequenceNumber dd ?
|
|
|
|
AckNumber dd ?
|
|
|
|
DataOffset db ? ; DataOffset[0-3 bits] and Reserved[4-7]
|
|
|
|
Flags db ? ; Reserved[0-1 bits]|URG|ACK|PSH|RST|SYN|FIN
|
|
|
|
Window dw ?
|
|
|
|
Checksum dw ?
|
|
|
|
UrgentPointer dw ?
|
2011-11-09 03:06:26 +04:00
|
|
|
|
2009-09-17 15:55:38 +04:00
|
|
|
ends
|
|
|
|
|
2009-10-06 00:47:27 +04:00
|
|
|
align 4
|
|
|
|
uglobal
|
2012-04-15 01:15:00 +04:00
|
|
|
TCP_segments_tx rd IP_MAX_INTERFACES
|
|
|
|
TCP_segments_rx rd IP_MAX_INTERFACES
|
2012-04-14 22:20:01 +04:00
|
|
|
TCP_bytes_rx rq IP_MAX_INTERFACES
|
|
|
|
TCP_bytes_tx rq IP_MAX_INTERFACES
|
|
|
|
TCP_sequence_num dd ?
|
2009-11-06 23:45:08 +03:00
|
|
|
endg
|
|
|
|
|
|
|
|
|
2009-10-06 00:47:27 +04:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; TCP_init
|
|
|
|
;
|
|
|
|
; This function resets all TCP variables
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
2012-04-14 22:20:01 +04:00
|
|
|
macro TCP_init {
|
2009-10-06 00:47:27 +04:00
|
|
|
|
2012-04-14 22:20:01 +04:00
|
|
|
xor eax, eax
|
2012-04-15 01:15:00 +04:00
|
|
|
mov edi, TCP_segments_tx
|
2012-04-14 22:20:01 +04:00
|
|
|
mov ecx, (6*IP_MAX_INTERFACES)
|
|
|
|
rep stosd
|
2009-10-06 00:47:27 +04:00
|
|
|
|
2012-04-14 22:20:01 +04:00
|
|
|
pseudo_random eax
|
|
|
|
mov [TCP_sequence_num], eax
|
2009-10-06 00:47:27 +04:00
|
|
|
|
2010-07-27 22:53:38 +04:00
|
|
|
}
|
2009-10-06 00:47:27 +04:00
|
|
|
|
|
|
|
|
2011-01-08 17:59:21 +03:00
|
|
|
include 'tcp_timer.inc'
|
|
|
|
include 'tcp_subr.inc'
|
|
|
|
include 'tcp_input.inc'
|
|
|
|
include 'tcp_output.inc'
|
2010-07-12 03:13:12 +04:00
|
|
|
|
|
|
|
|
2009-11-08 21:00:01 +03:00
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; TCP_API
|
|
|
|
;
|
2012-07-13 17:29:28 +04:00
|
|
|
; This function is called by system function 76
|
2009-11-08 21:00:01 +03:00
|
|
|
;
|
|
|
|
; IN: subfunction number in bl
|
|
|
|
; device number in bh
|
|
|
|
; ecx, edx, .. depends on subfunction
|
|
|
|
;
|
|
|
|
; OUT:
|
|
|
|
;
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
align 4
|
2012-04-15 01:15:00 +04:00
|
|
|
TCP_api:
|
2009-09-17 15:55:38 +04:00
|
|
|
|
2012-04-14 22:20:01 +04:00
|
|
|
movzx eax, bh
|
|
|
|
shl eax, 2
|
2009-11-08 21:00:01 +03:00
|
|
|
|
2012-04-14 22:20:01 +04:00
|
|
|
test bl, bl
|
|
|
|
jz .packets_tx ; 0
|
|
|
|
dec bl
|
|
|
|
jz .packets_rx ; 1
|
2009-11-08 21:00:01 +03:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
.error:
|
2012-04-14 22:20:01 +04:00
|
|
|
mov eax, -1
|
|
|
|
ret
|
2009-11-08 21:00:01 +03:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
.packets_tx:
|
|
|
|
mov eax, [TCP_segments_tx + eax]
|
2012-04-14 22:20:01 +04:00
|
|
|
ret
|
2009-11-08 21:00:01 +03:00
|
|
|
|
2012-04-15 01:15:00 +04:00
|
|
|
.packets_rx:
|
|
|
|
mov eax, [TCP_segments_rx + eax]
|
2012-04-14 22:20:01 +04:00
|
|
|
ret
|