Rev 5363 | Rev 5442 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3545 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
5363 | yogev_ezra | 3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3545 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
||
7 | ;; ;; |
||
8 | ;; Written by hidnplayr@kolibrios.org, ;; |
||
9 | ;; and Clevermouse. ;; |
||
10 | ;; ;; |
||
11 | ;; Based on code by mike.dld ;; |
||
12 | ;; ;; |
||
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
14 | ;; Version 2, June 1991 ;; |
||
15 | ;; ;; |
||
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
17 | |||
4850 | mario79 | 18 | $Revision: 5364 $ |
3545 | hidnplayr | 19 | |
20 | struct SOCKET |
||
21 | |||
22 | NextPtr dd ? ; pointer to next socket in list |
||
23 | PrevPtr dd ? ; pointer to previous socket in list |
||
24 | Number dd ? ; socket number |
||
25 | |||
26 | mutex MUTEX |
||
27 | |||
28 | PID dd ? ; process ID |
||
29 | TID dd ? ; thread ID |
||
30 | Domain dd ? ; INET/LOCAL/.. |
||
4365 | hidnplayr | 31 | Type dd ? ; RAW/STREAM/DGRAM |
3545 | hidnplayr | 32 | Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP |
33 | errorcode dd ? |
||
34 | device dd ? ; driver pointer, socket pointer if it's an LOCAL socket |
||
35 | |||
36 | options dd ? |
||
37 | state dd ? |
||
38 | backlog dw ? ; how many incoming connections that can be queued |
||
39 | |||
40 | snd_proc dd ? |
||
41 | rcv_proc dd ? |
||
4030 | hidnplayr | 42 | connect_proc dd ? |
3545 | hidnplayr | 43 | |
44 | ends |
||
45 | |||
46 | struct IP_SOCKET SOCKET |
||
47 | |||
48 | LocalIP rd 4 ; network byte order |
||
49 | RemoteIP rd 4 ; network byte order |
||
50 | |||
51 | ends |
||
52 | |||
53 | struct TCP_SOCKET IP_SOCKET |
||
54 | |||
55 | LocalPort dw ? ; network byte order |
||
56 | RemotePort dw ? ; network byte order |
||
57 | |||
58 | t_state dd ? ; TCB state |
||
59 | t_rxtshift db ? |
||
60 | rb 3 ; align |
||
61 | t_rxtcur dd ? |
||
62 | t_dupacks dd ? |
||
63 | t_maxseg dd ? |
||
64 | t_force dd ? |
||
65 | t_flags dd ? |
||
66 | |||
67 | ;--------------- |
||
68 | ; RFC783 page 21 |
||
69 | |||
70 | ; send sequence |
||
71 | SND_UNA dd ? ; sequence number of unack'ed sent Packets |
||
72 | SND_NXT dd ? ; next send sequence number to use |
||
73 | SND_UP dd ? ; urgent pointer |
||
74 | SND_WL1 dd ? ; window minus one |
||
75 | SND_WL2 dd ? ; |
||
76 | ISS dd ? ; initial send sequence number |
||
77 | SND_WND dd ? ; send window |
||
78 | |||
79 | ; receive sequence |
||
80 | RCV_WND dd ? ; receive window |
||
81 | RCV_NXT dd ? ; next receive sequence number to use |
||
82 | RCV_UP dd ? ; urgent pointer |
||
83 | IRS dd ? ; initial receive sequence number |
||
84 | |||
85 | ;--------------------- |
||
86 | ; Additional variables |
||
87 | |||
88 | ; receive variables |
||
89 | RCV_ADV dd ? |
||
90 | |||
91 | ; retransmit variables |
||
92 | SND_MAX dd ? |
||
93 | |||
94 | ; congestion control |
||
4339 | hidnplayr | 95 | SND_CWND dd ? ; congestion window |
96 | SND_SSTHRESH dd ? ; slow start threshold |
||
3545 | hidnplayr | 97 | |
98 | ;---------------------- |
||
99 | ; Transmit timing stuff |
||
100 | t_idle dd ? |
||
101 | t_rtt dd ? |
||
102 | t_rtseq dd ? |
||
103 | t_srtt dd ? |
||
104 | t_rttvar dd ? |
||
105 | t_rttmin dd ? |
||
106 | max_sndwnd dd ? |
||
107 | |||
108 | ;----------------- |
||
109 | ; Out-of-band data |
||
110 | t_oobflags dd ? |
||
111 | t_iobc dd ? |
||
112 | t_softerror dd ? |
||
113 | |||
114 | |||
115 | ;--------- |
||
116 | ; RFC 1323 ; the order of next 4 elements may not change |
||
117 | |||
118 | SND_SCALE db ? |
||
119 | RCV_SCALE db ? |
||
120 | requested_s_scale db ? |
||
121 | request_r_scale db ? |
||
122 | |||
123 | ts_recent dd ? ; a copy of the most-recent valid timestamp from the other end |
||
124 | ts_recent_age dd ? |
||
125 | last_ack_sent dd ? |
||
126 | |||
127 | |||
128 | ;------- |
||
129 | ; Timers |
||
3600 | hidnplayr | 130 | timer_flags dd ? |
3545 | hidnplayr | 131 | timer_retransmission dd ? ; rexmt |
132 | timer_persist dd ? |
||
133 | timer_keepalive dd ? ; keepalive/syn timeout |
||
134 | timer_timed_wait dd ? ; also used as 2msl timer |
||
4021 | hidnplayr | 135 | timer_connect dd ? |
3545 | hidnplayr | 136 | |
137 | ; extra |
||
138 | |||
139 | ts_ecr dd ? ; timestamp echo reply |
||
140 | ts_val dd ? |
||
141 | |||
142 | seg_next dd ? ; re-assembly queue |
||
143 | |||
144 | ends |
||
145 | |||
146 | struct UDP_SOCKET IP_SOCKET |
||
147 | |||
148 | LocalPort dw ? ; network byte order |
||
149 | RemotePort dw ? ; network byte order |
||
150 | |||
151 | ends |
||
152 | |||
153 | |||
154 | struct ICMP_SOCKET IP_SOCKET |
||
155 | |||
156 | Identifier dw ? |
||
157 | |||
158 | ends |
||
159 | |||
160 | |||
161 | struct RING_BUFFER |
||
162 | |||
163 | mutex MUTEX |
||
164 | start_ptr dd ? ; Pointer to start of buffer |
||
165 | end_ptr dd ? ; pointer to end of buffer |
||
166 | read_ptr dd ? ; Read pointer |
||
167 | write_ptr dd ? ; Write pointer |
||
168 | size dd ? ; Number of bytes buffered |
||
169 | |||
170 | ends |
||
171 | |||
172 | struct STREAM_SOCKET TCP_SOCKET |
||
173 | |||
174 | rcv RING_BUFFER |
||
175 | snd RING_BUFFER |
||
176 | |||
177 | ends |
||
178 | |||
179 | struct socket_queue_entry |
||
180 | |||
181 | data_ptr dd ? |
||
182 | buf_ptr dd ? |
||
183 | data_size dd ? |
||
184 | |||
185 | ends |
||
186 | |||
187 | |||
188 | SOCKETBUFFSIZE = 4096 ; in bytes |
||
189 | |||
190 | SOCKET_QUEUE_SIZE = 10 ; maximum number of incoming packets queued for 1 socket |
||
191 | ; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start |
||
192 | SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) |
||
193 | |||
194 | uglobal |
||
3698 | hidnplayr | 195 | align 4 |
196 | |||
3545 | hidnplayr | 197 | net_sockets rd 4 |
198 | last_socket_num dd ? |
||
199 | last_UDP_port dw ? ; These values give the number of the last used ephemeral port |
||
200 | last_TCP_port dw ? ; |
||
3647 | hidnplayr | 201 | socket_mutex MUTEX |
3698 | hidnplayr | 202 | |
3545 | hidnplayr | 203 | endg |
204 | |||
205 | |||
206 | ;----------------------------------------------------------------- |
||
207 | ; |
||
208 | ; SOCKET_init |
||
209 | ; |
||
210 | ;----------------------------------------------------------------- |
||
211 | macro SOCKET_init { |
||
212 | |||
213 | xor eax, eax |
||
214 | mov edi, net_sockets |
||
215 | mov ecx, 5 |
||
3711 | clevermous | 216 | rep stosd |
3545 | hidnplayr | 217 | |
218 | @@: |
||
219 | pseudo_random eax |
||
3600 | hidnplayr | 220 | cmp ax, EPHEMERAL_PORT_MIN |
3545 | hidnplayr | 221 | jb @r |
3600 | hidnplayr | 222 | cmp ax, EPHEMERAL_PORT_MAX |
3545 | hidnplayr | 223 | ja @r |
224 | xchg al, ah |
||
225 | mov [last_UDP_port], ax |
||
226 | |||
227 | @@: |
||
228 | pseudo_random eax |
||
3600 | hidnplayr | 229 | cmp ax, EPHEMERAL_PORT_MIN |
3545 | hidnplayr | 230 | jb @r |
3600 | hidnplayr | 231 | cmp ax, EPHEMERAL_PORT_MAX |
3545 | hidnplayr | 232 | ja @r |
233 | xchg al, ah |
||
234 | mov [last_TCP_port], ax |
||
235 | |||
3647 | hidnplayr | 236 | mov ecx, socket_mutex |
237 | call mutex_init |
||
238 | |||
3545 | hidnplayr | 239 | } |
240 | |||
241 | ;--------------------------- |