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