Subversion Repositories Kolibri OS

Rev

Rev 2301 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1196 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
1763 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved.    ;;
1196 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
7
;;                                                                 ;;
1514 hidnplayr 8
;;   Written by hidnplayr@kolibrios.org                            ;;
1196 hidnplayr 9
;;                                                                 ;;
1514 hidnplayr 10
;;    Based on the code of 4.4BSD                                  ;;
11
;;                                                                 ;;
1196 hidnplayr 12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1159 hidnplayr 16
 
1206 hidnplayr 17
$Revision: 2305 $
1159 hidnplayr 18
 
1514 hidnplayr 19
; Socket states
2301 hidnplayr 20
TCPS_CLOSED		equ 0
21
TCPS_LISTEN		equ 1
22
TCPS_SYN_SENT		equ 2
23
TCPS_SYN_RECEIVED	equ 3
24
TCPS_ESTABLISHED	equ 4
25
TCPS_CLOSE_WAIT 	equ 5
26
TCPS_FIN_WAIT_1 	equ 6
27
TCPS_CLOSING		equ 7
28
TCPS_LAST_ACK		equ 8
29
TCPS_FIN_WAIT_2 	equ 9
30
TCPS_TIMED_WAIT 	equ 10
1196 hidnplayr 31
 
1514 hidnplayr 32
; Socket Flags
33
TF_ACKNOW		equ 1 shl 0	; ack peer immediately
34
TF_DELACK		equ 1 shl 1	; ack, but try to delay it
35
TF_NODELAY		equ 1 shl 2	; don't delay packets to coalesce
36
TF_NOOPT		equ 1 shl 3	; don't use tcp options
37
TF_SENTFIN		equ 1 shl 4	; have sent FIN
38
TF_REQ_SCALE		equ 1 shl 5	; have/will request window scaling
39
TF_RCVD_SCALE		equ 1 shl 6	; other side has requested scaling
40
TF_REQ_TSTMP		equ 1 shl 7	; have/will request timestamps
41
TF_RCVD_TSTMP		equ 1 shl 8	; a timestamp was received in SYN
42
TF_SACK_PERMIT		equ 1 shl 9	; other side said I could SACK
1249 hidnplayr 43
 
1514 hidnplayr 44
; Segment flags
45
TH_FIN			equ 1 shl 0
46
TH_SYN			equ 1 shl 1
47
TH_RST			equ 1 shl 2
48
TH_PUSH 		equ 1 shl 3
49
TH_ACK			equ 1 shl 4
50
TH_URG			equ 1 shl 5
1318 hidnplayr 51
 
1514 hidnplayr 52
; Segment header options
53
TCP_OPT_EOL		equ 0		; End of option list.
54
TCP_OPT_NOP		equ 1		; No-Operation.
55
TCP_OPT_MAXSEG		equ 2		; Maximum Segment Size.
56
TCP_OPT_WINDOW		equ 3		; window scale
57
TCP_OPT_TIMESTAMP	equ 8
58
 
1519 hidnplayr 59
; Fundamental timer values
60
TCP_time_MSL		equ 47		; max segment lifetime (30s)
61
TCP_time_re_min 	equ 2		; min retransmission (1,28s)
62
TCP_time_re_max 	equ 100 	; max retransmission (64s)
63
TCP_time_pers_min	equ 8		; min persist (5,12s)
64
TCP_time_pers_max	equ 94		; max persist (60,16s)
65
TCP_time_keep_init	equ 118 	; connectione stablishment (75,52s)
66
TCP_time_keep_idle	equ 4608	; idle time before 1st probe (2h)
67
TCP_time_keep_interval	equ 118 	; between probes when no response (75,52s)
68
TCP_time_rtt_default	equ 5		; default Round Trip Time (3,2s)
69
 
70
; timer constants
71
TCP_max_rxtshift	equ 12		; max retransmissions waiting for ACK
72
TCP_max_keepcnt 	equ 8		; max keepalive probes
73
 
1529 hidnplayr 74
;
75
TCP_max_winshift	equ 14
76
TCP_max_win		equ 65535
1519 hidnplayr 77
 
1763 hidnplayr 78
TCP_re_xmit_thresh	equ 3
79
 
2305 hidnplayr 80
struct	TCP_header
81
 
82
	SourcePort		dw ?
83
	DestinationPort 	dw ?
84
	SequenceNumber		dd ?
85
	AckNumber		dd ?
86
	DataOffset		db ?	; DataOffset[0-3 bits] and Reserved[4-7]
87
	Flags			db ?	; Reserved[0-1 bits]|URG|ACK|PSH|RST|SYN|FIN
88
	Window			dw ?
89
	Checksum		dw ?
90
	UrgentPointer		dw ?
91
 
1159 hidnplayr 92
ends
93
 
1196 hidnplayr 94
align 4
95
uglobal
2305 hidnplayr 96
	TCP_headers_tx	       rd IP_MAX_INTERFACES
97
	TCP_headers_rx	       rd IP_MAX_INTERFACES
1514 hidnplayr 98
	TCP_bytes_rx		rq IP_MAX_INTERFACES
99
	TCP_bytes_tx		rq IP_MAX_INTERFACES
100
	TCP_sequence_num	dd ?
1196 hidnplayr 101
endg
102
 
103
 
104
;-----------------------------------------------------------------
105
;
106
; TCP_init
107
;
108
;  This function resets all TCP variables
109
;
110
;-----------------------------------------------------------------
1529 hidnplayr 111
macro	TCP_init {
1196 hidnplayr 112
 
113
	xor	eax, eax
2305 hidnplayr 114
	mov	edi, TCP_headers_tx
1514 hidnplayr 115
	mov	ecx, (6*IP_MAX_INTERFACES)
1196 hidnplayr 116
	rep	stosd
117
 
1529 hidnplayr 118
	pseudo_random	eax
119
	mov	[TCP_sequence_num], eax
1196 hidnplayr 120
 
1529 hidnplayr 121
}
1196 hidnplayr 122
 
123
 
1733 hidnplayr 124
include 'tcp_timer.inc'
125
include 'tcp_subr.inc'
126
include 'tcp_input.inc'
127
include 'tcp_output.inc'
1159 hidnplayr 128
 
1529 hidnplayr 129
 
1254 hidnplayr 130
;---------------------------------------------------------------------------
131
;
132
; TCP_API
133
;
134
; This function is called by system function 75
135
;
136
; IN:  subfunction number in bl
137
;      device number in bh
138
;      ecx, edx, .. depends on subfunction
139
;
140
; OUT:
141
;
142
;---------------------------------------------------------------------------
143
align 4
144
TCP_API:
145
 
146
	movzx	eax, bh
147
	shl	eax, 2
148
 
149
	test	bl, bl
150
	jz	.packets_tx	; 0
151
	dec	bl
152
	jz	.packets_rx	; 1
153
 
154
.error:
155
	mov	eax, -1
156
	ret
157
 
158
.packets_tx:
2305 hidnplayr 159
	add	eax, TCP_headers_tx
1254 hidnplayr 160
	mov	eax, [eax]
161
	ret
162
 
163
.packets_rx:
2305 hidnplayr 164
	add	eax, TCP_headers_rx
1254 hidnplayr 165
	mov	eax, [eax]
166
	ret