Rev 837 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 837 | Rev 914 | ||
---|---|---|---|
Line 27... | Line 27... | ||
27 | ;; 22.09.2003 - [Mike Hibbett] : mikeh@oceanfree.net ;; |
27 | ;; 22.09.2003 - [Mike Hibbett] : mikeh@oceanfree.net ;; |
28 | ;; 11.11.2006 - [Johnny_B] and [smb] ;; |
28 | ;; 11.11.2006 - [Johnny_B] and [smb] ;; |
29 | ;; ;; |
29 | ;; ;; |
30 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
30 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 31... | Line 31... | ||
31 | 31 | ||
Line 32... | Line 32... | ||
32 | $Revision: 738 $ |
32 | $Revision: 914 $ |
33 | 33 | ||
34 | 34 | ||
Line 75... | Line 75... | ||
75 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
75 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
76 | ; 68| SEG.WND Segment window INTEL format| |
76 | ; 68| SEG.WND Segment window INTEL format| |
77 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
77 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
78 | ; 72| Retransmit queue # NOW WINDOW SIZE TIMER INTEL format| |
78 | ; 72| Retransmit queue # NOW WINDOW SIZE TIMER INTEL format| |
79 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
79 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
80 | ; 76| RX offset from |
- | |
81 | ; 76| RX Data | |
80 | ; 76| RX Data Buffer | |
82 | ; +-+-+-.......... -+ |
81 | ; +-+-+-.......... -+ |
Line 83... | Line 82... | ||
83 | 82 | ||
84 | 83 | ||
- | 84 | ; so, define struct |
|
- | 85 | struc SOCKET |
|
- | 86 | { |
|
85 | ; so, define struct |
87 | .PrevPtr dd ? |
86 | struc SOCKET |
88 | .NextPtr dd ? |
87 | { .Status dd ? ;+00 - Status ( of this buffer ) |
89 | .Status dd ? ;+00 - Status ( of this buffer ) |
88 | .PID dd ? ;+04 - Application Process ID |
90 | .PID dd ? ;+04 - Application Process ID |
89 | .LocalIP dd ? ;+08 - Local IP Address |
- | |
90 | .LocalPort dw ? ;+12 - Local Port |
91 | .LocalIP dd ? ;+08 - Local IP Address |
91 | .UnusedL dw ? ;+14 - may be removed in future |
92 | .LocalPort dw ? ;+12 - Local Port |
- | 93 | .RemoteIP dd ? ;+16 - Remote IP Address |
|
92 | .RemoteIP dd ? ;+16 - Remote IP Address |
94 | .RemotePort dw ? ;+20 - Remote Port |
93 | .RemotePort dw ? ;+20 - Remote Port |
95 | .OrigRemoteIP dd ? |
94 | .UnusedR dw ? ;+22 - may be removed in future |
96 | .OrigRemotePort dw ? |
95 | .rxDataCount dd ? ;+24 - Rx Data Count |
97 | .rxDataCount dd ? ;+24 - Rx Data Count |
96 | .TCBState dd ? ;+28 - TCB STATE |
98 | .TCBState dd ? ;+28 - TCB STATE |
97 | .TCBTimer dd ? ;+32 - TCB Timer (seconds) |
99 | .TCBTimer dd ? ;+32 - TCB Timer (seconds) |
Line 111... | Line 113... | ||
111 | virtual at 0 |
113 | virtual at 0 |
112 | SOCKET SOCKET |
114 | SOCKET SOCKET |
113 | end virtual |
115 | end virtual |
Line 114... | Line 116... | ||
114 | 116 | ||
115 | ; simple macro calcing real memory address of SOCKET struct by socket's |
117 | ; simple macro calcing real memory address of SOCKET struct by socket's |
116 | macro Index2RealAddr reg |
118 | ;macro Index2RealAddr reg |
117 | { |
119 | ;{ |
118 | shl reg, 12 |
120 | ; shl reg, 12 |
119 | add reg, sockets |
121 | ; add reg, sockets |
Line 120... | Line 122... | ||
120 | } |
122 | ;} |
121 | 123 | ||
122 | ;Constants |
124 | ;Constants |
123 | ; current socket statuses |
125 | ; current socket statuses |
Line 124... | Line 126... | ||
124 | SOCK_EMPTY equ 0 ; socket not in use |
126 | SOCK_EMPTY = 0 ; socket not in use |
125 | SOCK_OPEN equ 1 ; open issued, but no data sent |
127 | SOCK_OPEN = 1 ; open issued, but no data sent |
126 | 128 | ||
Line 127... | Line 129... | ||
127 | ; TCP opening modes |
129 | ; TCP opening modes |
128 | SOCKET_PASSIVE equ 0 |
- | |
129 | SOCKET_ACTIVE equ 1 |
130 | SOCKET_PASSIVE equ 0 |
130 | - | ||
131 | ;*************************************************************************** |
131 | SOCKET_ACTIVE equ 1 |
132 | ; Function |
- | |
133 | ; is_localport_unused |
- | |
134 | ; |
- | |
135 | ; Description |
132 | |
136 | ; scans through all the active sockets , looking to see if the |
133 | proc net_socket_alloc stdcall uses ebx ecx edx edi |
137 | ; port number specified in bx is in use as a localport number. |
- | |
138 | ; This is useful when you want a to generate a unique local port |
- | |
139 | ; number. |
- | |
140 | ; On return, eax = 1 for free, 0 for in use |
- | |
141 | ; |
134 | mov ecx, SOCKETBUFFSIZE |
142 | ;*************************************************************************** |
135 | mov edx, PG_SW |
Line -... | Line 136... | ||
- | 136 | call @mem_alloc@8 |
|
- | 137 | DEBUGF 1, "K : net_socket_alloc (0x%x)\n", eax |
|
143 | is_localport_unused: |
138 | or eax, eax |
- | 139 | jz .exit |
|
- | 140 | ||
- | 141 | push eax |
|
- | 142 | mov edi, eax |
|
- | 143 | mov ecx, SOCKETBUFFSIZE / 4 |
|
- | 144 | cld |
|
- | 145 | xor eax, eax |
|
- | 146 | rep stosd |
|
- | 147 | pop eax |
|
- | 148 | ||
- | 149 | mov ebx, net_sockets |
|
- | 150 | push [ebx + SOCKET.NextPtr] |
|
- | 151 | mov [ebx + SOCKET.NextPtr], eax |
|
- | 152 | mov [eax + SOCKET.PrevPtr], ebx |
|
- | 153 | pop ebx |
|
144 | mov al, bh |
154 | mov [eax + SOCKET.NextPtr], ebx |
- | 155 | or ebx, ebx |
|
- | 156 | jz @f |
|
- | 157 | mov [ebx + SOCKET.PrevPtr], eax |
|
- | 158 | ||
- | 159 | @@: mov ebx, [TASK_BASE] |
|
- | 160 | mov ebx, [ebx + TASKDATA.pid] |
|
- | 161 | mov [eax + SOCKET.PID], ebx |
|
145 | mov ah, bl |
162 | |
- | 163 | .exit: |
|
- | 164 | ret |
|
- | 165 | endp |
|
- | 166 | ||
- | 167 | proc net_socket_free stdcall uses ebx ecx edx, sock:DWORD |
|
- | 168 | mov eax, [sock] |
|
- | 169 | DEBUGF 1, "K : net_socket_free (0x%x)\n", eax |
|
- | 170 | or eax, eax |
|
- | 171 | jz .error |
|
- | 172 | ||
- | 173 | mov ebx, net_sockets |
|
- | 174 | mov ecx, [TASK_BASE] |
|
- | 175 | mov ecx, [ecx + TASKDATA.pid] |
|
- | 176 | .next_socket: |
|
- | 177 | mov ebx, [ebx + SOCKET.NextPtr] |
|
- | 178 | or ebx, ebx |
|
- | 179 | jz .error |
|
- | 180 | cmp ebx, eax |
|
- | 181 | jne .next_socket |
|
- | 182 | ;cmp [ebx + SOCKET.PID], ecx |
|
- | 183 | ;jne .next_socket |
|
- | 184 | ||
- | 185 | mov ebx, [eax + SOCKET.NextPtr] |
|
- | 186 | mov eax, [eax + SOCKET.PrevPtr] |
|
- | 187 | mov [eax + SOCKET.NextPtr], ebx |
|
- | 188 | or ebx, ebx |
|
- | 189 | jz @f |
|
- | 190 | mov [ebx + SOCKET.PrevPtr], eax |
|
Line 146... | Line 191... | ||
146 | mov bx, ax |
191 | |
147 | 192 | @@: |
|
148 | mov edx, SOCKETBUFFSIZE * NUM_SOCKETS |
- | |
149 | mov ecx, NUM_SOCKETS |
- | |
- | 193 | mov ecx, [sock] |
|
- | 194 | call @mem_free@4 |
|
Line -... | Line 195... | ||
- | 195 | ret |
|
- | 196 | ||
- | 197 | .error: |
|
- | 198 | DEBUGF 1, "K : failed\n" |
|
- | 199 | ret |
|
- | 200 | endp |
|
150 | mov eax, 0 ; Assume the return value is 'in use' |
201 | |
- | 202 | proc net_socket_num_to_addr stdcall uses ebx ecx, x:DWORD |
|
- | 203 | ; FIXME: do real transform |
|
- | 204 | mov eax, [x] |
|
- | 205 | mov ebx, net_sockets |
|
- | 206 | mov ecx, [TASK_BASE] |
|
151 | 207 | mov ecx, [ecx + TASKDATA.pid] |
|
- | 208 | .next_socket: |
|
- | 209 | mov ebx, [ebx + SOCKET.NextPtr] |
|
Line 152... | Line 210... | ||
152 | ilu1: |
210 | or ebx, ebx |
- | 211 | jz .error |
|
153 | sub edx, SOCKETBUFFSIZE |
212 | cmp ebx, eax |
- | 213 | jne .next_socket |
|
Line -... | Line 214... | ||
- | 214 | ;cmp [ebx + SOCKET.PID], ecx |
|
- | 215 | ;jne .next_socket |
|
- | 216 | ret |
|
- | 217 | ||
- | 218 | .error: |
|
- | 219 | xor eax, eax |
|
- | 220 | ret |
|
- | 221 | endp |
|
- | 222 | ||
- | 223 | proc net_socket_addr_to_num stdcall uses ebx ecx, x:DWORD |
|
- | 224 | ; FIXME: do real transform |
|
- | 225 | mov eax, [x] |
|
- | 226 | mov ebx, net_sockets |
|
- | 227 | mov ecx, [TASK_BASE] |
|
- | 228 | mov ecx, [ecx + TASKDATA.pid] |
|
Line -... | Line 229... | ||
- | 229 | .next_socket: |
|
- | 230 | mov ebx, [ebx + SOCKET.NextPtr] |
|
- | 231 | or ebx, ebx |
|
- | 232 | jz .error |
|
Line 154... | Line 233... | ||
154 | cmp [edx + sockets + SOCKET.LocalPort], bx |
233 | cmp ebx, eax |
155 | loopnz ilu1 ; Return back if the socket is occupied |
234 | jne .next_socket |
156 | 235 | ;cmp [ebx + SOCKET.PID], ecx |
|
157 | jz ilu_exit |
236 | ;jne .next_socket |
158 | inc eax ; return port not in use |
237 | ret |
- | 238 | ||
- | 239 | .error: |
|
- | 240 | xor eax, eax |
|
- | 241 | ret |
|
- | 242 | endp |
|
159 | 243 | ||
160 | ilu_exit: |
244 | ;*************************************************************************** |
161 | ret |
- | |
162 | - | ||
163 | - | ||
164 | 245 | ; Function |
|
Line 165... | Line 246... | ||
165 | ;*************************************************************************** |
246 | ; is_localport_unused |
- | 247 | ; |
|
166 | ; Function |
248 | ; Description |
- | 249 | ; scans through all the active sockets , looking to see if the |
|
167 | ; get_free_socket |
250 | ; port number specified in bx is in use as a localport number. |
- | 251 | ; This is useful when you want a to generate a unique local port |
|
168 | ; |
252 | ; number. |
169 | ; Description |
253 | ; On return, eax = 1 for free, 0 for in use |
170 | ; |
254 | ; |
171 | ;*************************************************************************** |
255 | ;*************************************************************************** |
- | 256 | proc is_localport_unused stdcall |
|
- | 257 | ||
- | 258 | xchg bl, bh |
|
172 | get_free_socket: |
259 | |
Line 173... | Line 260... | ||
173 | push ecx |
260 | xor eax, eax ; Assume the return value is 'free' |
174 | mov eax, SOCKETBUFFSIZE * NUM_SOCKETS |
261 | inc al |
- | 262 | mov edx, net_sockets |
|
Line 175... | Line 263... | ||
175 | mov ecx, NUM_SOCKETS |
263 | |
176 | 264 | .next_socket: |
|
177 | gfs1: |
265 | mov edx, [edx + SOCKET.NextPtr] |
Line 197... | Line 285... | ||
197 | ; remote port in ecx |
285 | ; remote port in ecx |
198 | ; remote ip in edx |
286 | ; remote ip in edx |
199 | ; return socket # in eax, -1 if none available |
287 | ; return socket # in eax, -1 if none available |
200 | ; |
288 | ; |
201 | ;*************************************************************************** |
289 | ;*************************************************************************** |
202 | socket_open: |
290 | proc socket_open stdcall |
203 | call get_free_socket |
291 | call net_socket_alloc |
- | 292 | or eax, eax |
|
- | 293 | jz .error |
|
Line 204... | Line 294... | ||
204 | 294 | ||
205 | cmp eax, 0xFFFFFFFF |
- | |
Line 206... | Line -... | ||
206 | jz so_exit |
- | |
207 | 295 | DEBUGF 1, "K : socket_open (0x%x)\n", eax |
|
208 | ; ax holds the socket number that is free. Get real address |
- | |
209 | push eax |
- | |
210 | Index2RealAddr eax |
- | |
Line -... | Line 296... | ||
- | 296 | ||
211 | 297 | push eax |
|
212 | mov [eax + SOCKET.Status], dword SOCK_OPEN |
298 | |
213 | 299 | mov [eax + SOCKET.Status], SOCK_OPEN |
|
214 | xchg bh, bl |
300 | xchg bh, bl |
Line 215... | Line 301... | ||
215 | mov [eax + SOCKET.LocalPort], bx |
301 | mov [eax + SOCKET.LocalPort], bx |
216 | xchg ch, cl |
302 | xchg ch, cl |
217 | mov [eax + SOCKET.RemotePort], cx |
303 | mov [eax + SOCKET.RemotePort], cx |
218 | - | ||
Line 219... | Line -... | ||
219 | mov ebx, [stack_ip] |
- | |
220 | mov [eax + SOCKET.LocalIP], ebx |
- | |
221 | mov [eax + SOCKET.RemoteIP], edx |
- | |
222 | mov [eax + SOCKET.rxDataCount], dword 0 ; recieved data count |
304 | |
223 | - | ||
224 | mov esi, [TASK_BASE] |
305 | mov ebx, [stack_ip] |
225 | mov ebx, [esi+TASKDATA.pid] |
306 | mov [eax + SOCKET.LocalIP], ebx |
Line -... | Line 307... | ||
- | 307 | mov [eax + SOCKET.RemoteIP], edx |
|
- | 308 | ||
- | 309 | ;pop eax ; Get the socket number back, so we can return it |
|
- | 310 | stdcall net_socket_addr_to_num |
|
- | 311 | ret |
|
Line 226... | Line 312... | ||
226 | mov [eax + SOCKET.PID], ebx ; save the process ID |
312 | |
227 | pop eax ; Get the socket number back, so we can return it |
313 | .error: |
228 | 314 | DEBUGF 1, "K : socket_open (fail)\n" |
|
Line 243... | Line 329... | ||
243 | ; remote ip in edx ( in Internet byte order ) |
329 | ; remote ip in edx ( in Internet byte order ) |
244 | ; Socket open mode in esi ( SOCKET_PASSIVE or SOCKET_ACTIVE ) |
330 | ; Socket open mode in esi ( SOCKET_PASSIVE or SOCKET_ACTIVE ) |
245 | ; return socket # in eax, -1 if none available |
331 | ; return socket # in eax, -1 if none available |
246 | ; |
332 | ; |
247 | ;*************************************************************************** |
333 | ;*************************************************************************** |
248 | socket_open_tcp: |
334 | proc socket_open_tcp stdcall |
249 | call get_free_socket |
335 | local sockAddr dd ? |
Line 250... | Line 336... | ||
250 | 336 | ||
251 | cmp eax, 0xFFFFFFFF |
337 | cmp esi, SOCKET_PASSIVE |
Line 252... | Line -... | ||
252 | jz so_exit |
- | |
253 | 338 | jne .skip_port_check |
|
- | 339 | ||
- | 340 | push ebx |
|
254 | ; ax holds the socket number that is free. Get real address |
341 | mov eax, ebx |
Line 255... | Line 342... | ||
255 | push eax |
342 | xchg al, ah |
256 | Index2RealAddr eax |
343 | mov ebx, net_sockets |
- | 344 | ||
- | 345 | .next_socket: |
|
- | 346 | mov ebx, [ebx + SOCKET.NextPtr] |
|
- | 347 | or ebx, ebx |
|
- | 348 | jz .last_socket |
|
- | 349 | cmp [ebx + SOCKET.TCBState], TCB_LISTEN |
|
- | 350 | jne .next_socket |
|
- | 351 | cmp [ebx + SOCKET.LocalPort], ax |
|
- | 352 | jne .next_socket |
|
- | 353 | ||
- | 354 | xchg al, ah |
|
- | 355 | DEBUGF 1, "K : error: port %u is listened by 0x%x\n", ax, ebx |
|
- | 356 | pop ebx |
|
- | 357 | jmp .error |
|
- | 358 | ||
- | 359 | .last_socket: |
|
- | 360 | pop ebx |
|
- | 361 | ||
- | 362 | .skip_port_check: |
|
- | 363 | call net_socket_alloc |
|
- | 364 | or eax, eax |
|
- | 365 | jz .error |
|
- | 366 | ||
Line 257... | Line 367... | ||
257 | 367 | DEBUGF 1, "K : socket_open_tcp (0x%x)\n", eax |
|
- | 368 | ||
258 | mov [sktAddr], eax |
369 | mov [sockAddr], eax |
Line 259... | Line 370... | ||
259 | mov [eax], dword SOCK_OPEN |
370 | |
260 | 371 | ; TODO - check this works! |
|
261 | ; TODO - check this works! |
- | |
262 | mov [eax + SOCKET.wndsizeTimer], dword 0 ; Reset the window timer. |
- | |
263 | - | ||
264 | xchg bh, bl |
372 | ;xxx: already 0 (intialized by net_socket_alloc) |
265 | mov [eax + SOCKET.LocalPort], bx |
373 | ;mov [eax + SOCKET.wndsizeTimer], 0 ; Reset the window timer. |
266 | ; mov [eax + 12], byte bh ; Local port ( LS 16 bits ) |
- | |
267 | ; mov [eax + 13], byte bl ; Local port ( LS 16 bits ) |
374 | |
268 | - | ||
269 | xchg ch, cl |
375 | xchg bh, bl |
270 | mov [eax + SOCKET.RemotePort], cx |
376 | mov [eax + SOCKET.LocalPort], bx |
271 | ; mov [eax + 20], ch ; Remote Port ( LS 16 bits ) |
377 | xchg ch, cl |
272 | ; mov [eax + 21], cl ; Remote Port ( LS 16 bits ) |
378 | mov [eax + SOCKET.RemotePort], cx |
Line 273... | Line -... | ||
273 | - | ||
274 | mov ebx, [stack_ip] |
379 | mov [eax + SOCKET.OrigRemotePort], cx |
275 | mov [eax + SOCKET.LocalIP], ebx |
380 | mov ebx, [stack_ip] |
276 | mov [eax + SOCKET.RemoteIP], edx |
381 | mov [eax + SOCKET.LocalIP], ebx |
277 | mov [eax + SOCKET.rxDataCount], dword 0 |
382 | mov [eax + SOCKET.RemoteIP], edx |
278 | - | ||
279 | ; Now fill in TCB state |
- | |
280 | mov ebx, TCB_LISTEN |
383 | mov [eax + SOCKET.OrigRemoteIP], edx |
281 | cmp esi, SOCKET_PASSIVE |
- | |
282 | jz sot_001 |
- | |
283 | mov ebx, TCB_SYN_SENT |
- | |
284 | - | ||
Line 285... | Line 384... | ||
285 | sot_001: |
384 | |
286 | mov [eax + SOCKET.TCBState], ebx ; Indicate the state of the TCB |
385 | mov ebx, TCB_LISTEN |
Line 287... | Line 386... | ||
287 | 386 | cmp esi, SOCKET_PASSIVE |
|
288 | mov esi, [TASK_BASE] |
387 | je @f |
289 | mov ecx, [esi+TASKDATA.pid] |
388 | mov ebx, TCB_SYN_SENT |
290 | mov [eax + SOCKET.PID], ecx ; save the process ID |
389 | @@: mov [eax + SOCKET.TCBState], ebx ; Indicate the state of the TCB |
291 | 390 | ||
Line 292... | Line 391... | ||
292 | cmp ebx, TCB_LISTEN |
391 | cmp ebx, TCB_LISTEN |
Line 293... | Line 392... | ||
293 | je sot_done |
392 | je .exit |
294 | 393 | ||
295 | ; Now, if we are in active mode, then we have to send a SYN to the specified remote port |
- | |
296 | mov eax, EMPTY_QUEUE |
394 | ; Now, if we are in active mode, then we have to send a SYN to the specified remote port |
Line 297... | Line 395... | ||
297 | call dequeue |
395 | mov eax, EMPTY_QUEUE |
Line 298... | Line 396... | ||
298 | cmp ax, NO_BUFFER |
396 | call dequeue |
299 | je sot_done |
397 | cmp ax, NO_BUFFER |
300 | 398 | je .exit |
|
301 | push eax |
- | |
302 | 399 | ||
303 | mov bl, 0x02 ; SYN |
400 | push eax |
Line 304... | Line 401... | ||
304 | mov ecx, 0 |
401 | |
305 | 402 | mov bl, TH_SYN |
|
306 | call buildTCPPacket |
403 | xor ecx, ecx |
307 | 404 | stdcall build_tcp_packet, [sockAddr] |
|
Line 308... | Line 405... | ||
308 | mov eax, NET1OUT_QUEUE |
405 | |
Line 309... | Line 406... | ||
309 | 406 | mov eax, NET1OUT_QUEUE |
|
310 | mov edx, [stack_ip] |
407 | |
311 | mov ecx, [sktAddr ] |
408 | mov edx, [stack_ip] |
Line 312... | Line 409... | ||
312 | mov ecx, [ecx + 16] |
409 | mov ecx, [sockAddr] |
- | 410 | cmp edx, [ecx + SOCKET.RemoteIP] |
|
- | 411 | jne .not_local |
|
313 | cmp edx, ecx |
412 | mov eax, IPIN_QUEUE |
314 | jne sot_notlocal |
- | |
315 | mov eax, IPIN_QUEUE |
413 | |
316 | 414 | .not_local: |
|
Line -... | Line 415... | ||
- | 415 | ; Send it. |
|
- | 416 | pop ebx |
|
- | 417 | call queue |
|
- | 418 | ||
- | 419 | mov esi, [sockAddr] |
|
Line 317... | Line 420... | ||
317 | sot_notlocal: |
420 | |
318 | ; Send it. |
421 | ; increment SND.NXT in socket |
319 | pop ebx |
422 | add esi, SOCKET.SND_NXT |
Line 340... | Line 443... | ||
340 | ; Description |
443 | ; Description |
341 | ; socket # in ebx |
444 | ; socket # in ebx |
342 | ; returns 0 for ok, -1 for socket not open (fail) |
445 | ; returns 0 for ok, -1 for socket not open (fail) |
343 | ; |
446 | ; |
344 | ;*************************************************************************** |
447 | ;*************************************************************************** |
345 | socket_close: |
448 | proc socket_close stdcall |
346 | mov eax, 0xFFFFFFFF ; assume this operation will fail.. |
449 | DEBUGF 1, "K : socket_close (0x%x)\n", ebx |
347 | cmp ebx, NUM_SOCKETS |
450 | stdcall net_socket_num_to_addr, ebx |
348 | jae sc_exit |
451 | or eax, eax |
349 | Index2RealAddr ebx |
452 | jz .error |
- | 453 | ||
350 | cmp [ebx + SOCKET.Status], dword SOCK_EMPTY |
454 | cmp [eax + SOCKET.Status], dword SOCK_EMPTY |
351 | jz sc_exit |
455 | jz .error |
Line 352... | Line 456... | ||
352 | 456 | ||
- | 457 | ; Clear the socket varaibles |
|
353 | ; Clear the socket varaibles |
458 | stdcall net_socket_free, eax |
354 | xor eax, eax |
459 | ; mov edi, eax |
355 | mov edi, ebx |
460 | ; xor eax, eax |
356 | mov ecx, SOCKETHEADERSIZE |
461 | ; mov ecx, SOCKETHEADERSIZE |
357 | cld |
462 | ; cld |
Line 358... | Line 463... | ||
358 | rep stosb |
463 | ; rep stosb |
359 | 464 | ||
Line -... | Line 465... | ||
- | 465 | xor eax, eax |
|
- | 466 | ret |
|
- | 467 | ||
- | 468 | .error: |
|
- | 469 | DEBUGF 1, "K : socket_close (fail)\n" |
|
Line 360... | Line 470... | ||
360 | sc_exit: |
470 | or eax, -1 |
361 | ret |
471 | ret |
362 | 472 | endp |
|
Line 369... | Line 479... | ||
369 | ; Description |
479 | ; Description |
370 | ; socket # in ebx |
480 | ; socket # in ebx |
371 | ; returns 0 for ok, -1 for socket not open (fail) |
481 | ; returns 0 for ok, -1 for socket not open (fail) |
372 | ; |
482 | ; |
373 | ;*************************************************************************** |
483 | ;*************************************************************************** |
374 | socket_close_tcp: |
484 | proc socket_close_tcp stdcall |
- | 485 | local sockAddr dd ? |
|
- | 486 | DEBUGF 1, "K : socket_close_tcp (0x%x)\n", ebx |
|
375 | ; first, remove any resend entries |
487 | ; first, remove any resend entries |
376 | pusha |
488 | pusha |
Line 377... | Line 489... | ||
377 | 489 | ||
378 | mov esi, resendQ |
490 | mov esi, resendQ |
Line 379... | Line 491... | ||
379 | mov ecx, 0 |
491 | mov ecx, 0 |
380 | 492 | ||
381 | sct001: |
493 | .next_resendq: |
- | 494 | cmp ecx, NUMRESENDENTRIES |
|
382 | cmp ecx, NUMRESENDENTRIES |
495 | je .last_resendq ; None left |
383 | je sct003 ; None left |
496 | ;cmp [esi], bl ; XTODO: bl -> ebx |
384 | cmp [esi], bl |
497 | cmp [esi + 4], ebx |
385 | je sct002 ; found one |
498 | je @f ; found one |
386 | inc ecx |
499 | inc ecx |
Line -... | Line 500... | ||
- | 500 | add esi, 8 |
|
- | 501 | jmp .next_resendq |
|
387 | add esi, 4 |
502 | |
388 | jmp sct001 |
- | |
389 | 503 | ;@@: mov byte[esi], 0xff ; XTODO: 0xff -> 0 |
|
390 | sct002: |
504 | @@: mov dword[esi + 4], 0 |
Line 391... | Line 505... | ||
391 | 505 | inc ecx |
|
392 | mov [esi], byte 0xFF |
506 | add esi, 8 |
Line 393... | Line 507... | ||
393 | jmp sct001 |
507 | jmp .next_resendq |
- | 508 | ||
- | 509 | .last_resendq: |
|
- | 510 | popa |
|
- | 511 | ||
394 | 512 | stdcall net_socket_num_to_addr, ebx |
|
- | 513 | or eax, eax |
|
- | 514 | jz .error |
|
- | 515 | ||
395 | sct003: |
516 | mov ebx, eax |
- | 517 | mov [sockAddr], eax |
|
396 | popa |
518 | cmp [ebx + SOCKET.Status], SOCK_EMPTY |
397 | 519 | je .error |
|
Line 398... | Line 520... | ||
398 | Index2RealAddr ebx |
520 | |
399 | mov [sktAddr], ebx |
521 | cmp [ebx + SOCKET.TCBState], TCB_LISTEN ;xxx |
400 | mov eax, 0xFFFFFFFF ; assume this operation will fail.. |
522 | je .destroy_tcb ;xxx |
401 | cmp [ebx + SOCKET.Status], dword SOCK_EMPTY |
523 | cmp [ebx + SOCKET.TCBState], TCB_SYN_SENT ;xxx |
402 | jz sct_exit |
524 | je .destroy_tcb ;xxx |
Line 403... | Line 525... | ||
403 | 525 | ||
Line 404... | Line 526... | ||
404 | ; Now construct the response, and queue for sending by IP |
526 | ; Now construct the response, and queue for sending by IP |
405 | mov eax, EMPTY_QUEUE |
527 | mov eax, EMPTY_QUEUE |
406 | call dequeue |
528 | call dequeue |
407 | cmp ax, NO_BUFFER |
- | |
408 | je stl_exit |
529 | cmp ax, NO_BUFFER |
409 | - | ||
410 | push eax |
530 | je .error |
Line -... | Line 531... | ||
- | 531 | ||
411 | 532 | push eax |
|
412 | mov bl, 0x11 ; FIN + ACK |
- | |
413 | mov ecx, 0 |
533 | |
414 | mov esi, 0 |
534 | ;xxx mov bl, TH_FIN + TH_ACK |
Line 415... | Line 535... | ||
415 | 535 | mov bl, TH_FIN ;xxx |
|
416 | call buildTCPPacket |
536 | xor ecx, ecx |
417 | 537 | xor esi, esi |
|
418 | mov ebx, [sktAddr] |
538 | stdcall build_tcp_packet, [sockAddr] |
419 | 539 | ||
420 | ; increament SND.NXT in socket |
540 | mov ebx, [sockAddr] |
421 | mov esi, 48 |
541 | ; increament SND.NXT in socket |
422 | add esi, ebx |
542 | lea esi, [ebx + SOCKET.SND_NXT] |
423 | call inc_inet_esi |
543 | call inc_inet_esi |
424 | 544 | ||
Line 425... | Line 545... | ||
425 | 545 | ||
426 | ; Get the socket state |
546 | ; Get the socket state |
427 | mov eax, [ebx + SOCKET.TCBState] |
547 | mov eax, [ebx + SOCKET.TCBState] |
428 | cmp eax, TCB_LISTEN |
548 | ;xxx cmp eax, TCB_LISTEN |
429 | je destroyTCB |
- | |
430 | cmp eax, TCB_SYN_SENT |
549 | ;xxx je .destroy_tcb |
Line 431... | Line 550... | ||
431 | je destroyTCB |
550 | ;xxx cmp eax, TCB_SYN_SENT |
432 | cmp eax, TCB_SYN_RECEIVED |
551 | ;xxx je .destroy_tcb |
433 | je sct_finwait1 |
- | |
434 | cmp eax, TCB_ESTABLISHED |
552 | cmp eax, TCB_SYN_RECEIVED |
435 | je sct_finwait1 |
- | |
Line 436... | Line 553... | ||
436 | 553 | je .fin_wait_1 |
|
437 | ; assume CLOSE WAIT |
554 | cmp eax, TCB_ESTABLISHED |
Line 438... | Line 555... | ||
438 | ; Send a fin, then enter last-ack state |
555 | je .fin_wait_1 |
439 | mov eax, TCB_LAST_ACK |
556 | |
440 | mov [ebx + SOCKET.TCBState], eax |
557 | ; assume CLOSE WAIT |
441 | xor eax, eax |
- | |
442 | jmp sct_send |
558 | ; Send a fin, then enter last-ack state |
443 | 559 | ; TODO: check if it's really a TCB_CLOSE_WAIT |
|
Line 444... | Line 560... | ||
444 | sct_finwait1: |
560 | mov [ebx + SOCKET.TCBState], TCB_LAST_ACK |
445 | ; Send a fin, then enter finwait2 state |
561 | jmp .send |
446 | mov eax, TCB_FIN_WAIT_1 |
562 | |
447 | mov [ebx + SOCKET.TCBState], eax |
563 | .fin_wait_1: |
448 | xor eax, eax |
564 | ; Send a fin, then enter finwait2 state |
Line 449... | Line 565... | ||
449 | 565 | mov [ebx + SOCKET.TCBState], TCB_FIN_WAIT_1 |
|
450 | sct_send: |
566 | |
451 | mov eax, NET1OUT_QUEUE |
- | |
452 | - | ||
453 | mov edx, [stack_ip] |
- | |
454 | mov ecx, [sktAddr ] |
- | |
455 | mov ecx, [ecx + 16] |
- | |
456 | cmp edx, ecx |
- | |
Line -... | Line 567... | ||
- | 567 | .send: |
|
- | 568 | mov eax, NET1OUT_QUEUE |
|
- | 569 | ||
- | 570 | mov edx, [stack_ip] |
|
457 | jne sct_notlocal |
571 | mov ecx, [sockAddr] |
- | 572 | cmp edx, [ecx + SOCKET.RemoteIP] |
|
458 | mov eax, IPIN_QUEUE |
573 | jne .not_local |
Line -... | Line 574... | ||
- | 574 | mov eax, IPIN_QUEUE |
|
- | 575 | ||
- | 576 | .not_local: |
|
- | 577 | ; Send it. |
|
- | 578 | pop ebx |
|
Line 459... | Line 579... | ||
459 | 579 | call queue |
|
460 | sct_notlocal: |
580 | jmp .exit |
461 | ; Send it. |
581 | |
Line 484... | Line 604... | ||
484 | ; Description |
604 | ; Description |
485 | ; socket # in ebx |
605 | ; socket # in ebx |
486 | ; returns count in eax. |
606 | ; returns count in eax. |
487 | ; |
607 | ; |
488 | ;*************************************************************************** |
608 | ;*************************************************************************** |
489 | socket_poll: |
609 | proc socket_poll stdcall |
490 | Index2RealAddr ebx |
610 | ; DEBUGF 1, "socket_poll(0x%x)\n", ebx |
491 | mov eax, [ebx + SOCKET.rxDataCount] |
611 | stdcall net_socket_num_to_addr, ebx |
- | 612 | or eax, eax |
|
- | 613 | jz .error |
|
Line -... | Line 614... | ||
- | 614 | ||
492 | 615 | mov eax, [eax + SOCKET.rxDataCount] |
|
Line -... | Line 616... | ||
- | 616 | ret |
|
- | 617 | ||
- | 618 | .error: |
|
- | 619 | ;or eax, -1 |
|
- | 620 | xor eax, eax |
|
Line 493... | Line 621... | ||
493 | ret |
621 | ret |
494 | 622 | endp |
|
495 | 623 | ||
Line 501... | Line 629... | ||
501 | ; Description |
629 | ; Description |
502 | ; socket # in ebx |
630 | ; socket # in ebx |
503 | ; returns TCB state in eax. |
631 | ; returns TCB state in eax. |
504 | ; |
632 | ; |
505 | ;*************************************************************************** |
633 | ;*************************************************************************** |
506 | socket_status: |
634 | proc socket_status stdcall |
- | 635 | ;; DEBUGF 1, "socket_status(0x%x)\n", ebx |
|
507 | Index2RealAddr ebx |
636 | stdcall net_socket_num_to_addr, ebx |
- | 637 | or eax, eax |
|
- | 638 | jz .error |
|
- | 639 | ||
508 | mov eax, [ebx + SOCKET.TCBState] |
640 | mov eax, [eax + SOCKET.TCBState] |
- | 641 | ret |
|
Line -... | Line 642... | ||
- | 642 | ||
- | 643 | .error: |
|
- | 644 | ;or eax, -1 |
|
509 | 645 | xor eax, eax |
|
- | 646 | ret |
|
Line -... | Line 647... | ||
- | 647 | endp |
|
- | 648 | ||
- | 649 | ; Index2RealAddr ebx |
|
- | 650 | ; mov eax, [ebx + SOCKET.TCBState] |
|
Line 510... | Line 651... | ||
510 | ret |
651 | ; |
511 | 652 | ; ret |
|
512 | 653 | ||
Line 518... | Line 659... | ||
518 | ; Description |
659 | ; Description |
519 | ; socket # in ebx |
660 | ; socket # in ebx |
520 | ; returns # of bytes remaining in eax, data in bl |
661 | ; returns # of bytes remaining in eax, data in bl |
521 | ; |
662 | ; |
522 | ;*************************************************************************** |
663 | ;*************************************************************************** |
523 | socket_read: |
664 | proc socket_read stdcall |
- | 665 | ; DEBUGF 1, "socket_read(0x%x)\n", ebx |
|
524 | Index2RealAddr ebx |
666 | stdcall net_socket_num_to_addr, ebx |
- | 667 | or eax, eax |
|
- | 668 | jz .error |
|
- | 669 | ||
- | 670 | mov ebx, eax |
|
525 | mov eax, [ebx + SOCKET.rxDataCount] ; get count of bytes |
671 | mov eax, [ebx + SOCKET.rxDataCount] ; get count of bytes |
526 | mov ecx, 1 |
- | |
527 | test eax, eax |
672 | test eax, eax |
528 | jz sr2 |
673 | jz .error |
Line 529... | Line 674... | ||
529 | 674 | ||
530 | dec eax |
675 | dec eax |
531 | mov esi, ebx ; esi is address of socket |
676 | mov esi, ebx ; esi is address of socket |
532 | mov [ebx + SOCKET.rxDataCount], eax ; store new count |
677 | mov [ebx + SOCKET.rxDataCount], eax ; store new count |
Line 535... | Line 680... | ||
535 | add esi, SOCKETHEADERSIZE |
680 | add esi, SOCKETHEADERSIZE |
536 | mov edi, esi |
681 | mov edi, esi |
537 | inc esi |
682 | inc esi |
Line 538... | Line 683... | ||
538 | 683 | ||
- | 684 | mov ecx, (SOCKETBUFFSIZE - SOCKETHEADERSIZE) / 4 |
|
- | 685 | lea edi, [ebx + SOCKETHEADERSIZE] |
|
539 | mov ecx, (SOCKETBUFFSIZE - SOCKETHEADERSIZE) / 4 |
686 | lea esi, [edi + 1] |
540 | cld |
687 | cld |
541 | rep movsd |
- | |
542 | xor ecx, ecx |
- | |
543 | - | ||
544 | sr1: |
- | |
Line 545... | Line 688... | ||
545 | jmp sor_exit |
688 | rep movsd |
546 | - | ||
Line -... | Line 689... | ||
- | 689 | ||
- | 690 | ret |
|
- | 691 | ||
547 | sr2: |
692 | .error: |
548 | xor bl, bl |
693 | ;or eax, -1 |
- | 694 | xor eax, eax |
|
Line 549... | Line 695... | ||
549 | 695 | xor ebx, ebx |
|
550 | sor_exit: |
696 | ret |
551 | ret |
697 | endp |
Line 560... | Line 706... | ||
560 | ; datapointer # in ecx |
706 | ; datapointer # in ecx |
561 | ; buffer size in edx |
707 | ; buffer size in edx |
562 | ; returns # of bytes copied in eax |
708 | ; returns # of bytes copied in eax |
563 | ; |
709 | ; |
564 | ;*************************************************************************** |
710 | ;*************************************************************************** |
565 | socket_read_packet: |
711 | proc socket_read_packet stdcall |
- | 712 | ; DEBUGF 1, "socket_read_packet(0x%x)\n", ebx |
|
566 | Index2RealAddr ebx ; get real socket address |
713 | stdcall net_socket_num_to_addr, ebx ; get real socket address |
- | 714 | or eax, eax |
|
- | 715 | jz .error |
|
- | 716 | ||
- | 717 | mov ebx, eax |
|
567 | mov eax, [ebx + SOCKET.rxDataCount] ; get count of bytes |
718 | mov eax, [ebx + SOCKET.rxDataCount] ; get count of bytes |
568 | test eax, eax ; if count of bytes is zero.. |
719 | test eax, eax ; if count of bytes is zero.. |
569 | jz .exit ; exit function (eax will be zero) |
720 | jz .exit ; exit function (eax will be zero) |
Line 570... | Line 721... | ||
570 | 721 | ||
571 | test edx, edx ; if buffer size is zero, copy all data |
722 | test edx, edx ; if buffer size is zero, copy all data |
572 | jz .copyallbytes |
723 | jz .copy_all_bytes |
573 | cmp edx, eax ; if buffer size is larger then the bytes of data, copy all data |
724 | cmp edx, eax ; if buffer size is larger then the bytes of data, copy all data |
Line 574... | Line 725... | ||
574 | jge .copyallbytes |
725 | jge .copy_all_bytes |
575 | 726 | ||
576 | sub eax, edx ; store new count (data bytes in buffer - bytes we're about to copy) |
727 | sub eax, edx ; store new count (data bytes in buffer - bytes we're about to copy) |
577 | mov [ebx + SOCKET.rxDataCount], eax ; |
728 | mov [ebx + SOCKET.rxDataCount], eax ; |
578 | push eax |
729 | push eax |
Line 579... | Line 730... | ||
579 | mov eax, edx ; number of bytes we want to copy must be in eax |
730 | mov eax, edx ; number of bytes we want to copy must be in eax |
580 | call .startcopy ; copy to the application |
731 | call .start_copy ; copy to the application |
581 | 732 | ||
582 | mov esi, ebx ; now we're going to copy the remaining bytes to the beginning |
733 | mov esi, ebx ; now we're going to copy the remaining bytes to the beginning |
Line 590... | Line 741... | ||
590 | rep movsd ; copy all full dwords |
741 | rep movsd ; copy all full dwords |
591 | pop ecx |
742 | pop ecx |
592 | and ecx, 3 |
743 | and ecx, 3 |
593 | rep movsb ; copy remaining bytes |
744 | rep movsb ; copy remaining bytes |
Line -... | Line 745... | ||
- | 745 | ||
594 | 746 | .exit: |
|
Line -... | Line 747... | ||
- | 747 | ret ; at last, exit |
|
- | 748 | ||
- | 749 | .error: |
|
- | 750 | ;or eax, -1 |
|
- | 751 | xor eax, eax |
|
595 | ret ; at last, exit |
752 | ret |
596 | 753 | ||
597 | .copyallbytes: |
754 | .copy_all_bytes: |
- | 755 | xor esi, esi |
|
- | 756 | mov [ebx + SOCKET.rxDataCount], esi ; store new count (zero) |
|
Line 598... | Line 757... | ||
598 | xor esi, esi |
757 | call .start_copy |
599 | mov [ebx + SOCKET.rxDataCount], esi ; store new count (zero) |
758 | ret |
600 | - | ||
601 | .startcopy: |
- | |
602 | mov edi, ecx ; |
759 | |
603 | ; add edi, std_application_base_address ; get data pointer to buffer in application |
760 | .start_copy: |
604 | 761 | mov edi, ecx |
|
605 | mov esi, ebx ; |
762 | mov esi, ebx |
606 | add esi, SOCKETHEADERSIZE ; we dont need to copy the header |
763 | add esi, SOCKETHEADERSIZE ; we dont need to copy the header |
607 | mov ecx, eax ; eax is count of bytes |
764 | mov ecx, eax ; eax is count of bytes |
608 | push ecx |
765 | push ecx |
609 | shr ecx, 2 ; divide eax by 4 |
766 | shr ecx, 2 ; divide eax by 4 |
610 | cld ; copy all full dwords |
767 | cld ; copy all full dwords |
611 | rep movsd ; |
768 | rep movsd |
612 | pop ecx |
- | |
613 | and ecx, 3 |
- | |
614 | rep movsb ; copy the rest bytes |
769 | pop ecx |
615 | - | ||
616 | .exit: |
770 | and ecx, 3 |
Line 617... | Line 771... | ||
617 | ret ; exit, or go back to shift remaining bytes if any |
771 | rep movsb ; copy the rest bytes |
618 | 772 | retn ; exit, or go back to shift remaining bytes if any |
|
619 | 773 | endp |
|
Line 629... | Line 783... | ||
629 | ; pointer to data in edx |
783 | ; pointer to data in edx |
630 | ; returns 0 in eax ok, -1 == failed ( invalid socket, or |
784 | ; returns 0 in eax ok, -1 == failed ( invalid socket, or |
631 | ; could not queue IP packet ) |
785 | ; could not queue IP packet ) |
632 | ; |
786 | ; |
633 | ;*************************************************************************** |
787 | ;*************************************************************************** |
634 | socket_write: |
788 | proc socket_write stdcall |
- | 789 | ; DEBUGF 1, "socket_write(0x%x)\n", ebx |
|
- | 790 | stdcall net_socket_num_to_addr, ebx ; get real socket address |
|
635 | Index2RealAddr ebx |
791 | or eax, eax |
- | 792 | jz .error |
|
Line 636... | Line -... | ||
636 | - | ||
637 | mov eax, 0xFFFFFFFF |
- | |
638 | ; If the socket is invalid, return with an error code |
- | |
639 | cmp [ebx], dword SOCK_EMPTY |
793 | |
Line -... | Line 794... | ||
- | 794 | mov ebx, eax |
|
- | 795 | ||
- | 796 | ; If the socket is invalid, return with an error code |
|
Line 640... | Line 797... | ||
640 | je sw_exit |
797 | cmp [ebx + SOCKET.Status], SOCK_EMPTY |
641 | 798 | je .error |
|
642 | 799 | ||
643 | mov eax, EMPTY_QUEUE |
800 | mov eax, EMPTY_QUEUE |
Line 644... | Line 801... | ||
644 | call dequeue |
801 | call dequeue |
645 | cmp ax, NO_BUFFER |
802 | cmp ax, NO_BUFFER |
Line 646... | Line 803... | ||
646 | je sw_exit |
803 | je .error |
Line 660... | Line 817... | ||
660 | mov edx, eax |
817 | mov edx, eax |
Line 661... | Line 818... | ||
661 | 818 | ||
Line 662... | Line 819... | ||
662 | ; So, ebx holds the socket ptr, edx holds the IPbuffer ptr |
819 | ; So, ebx holds the socket ptr, edx holds the IPbuffer ptr |
663 | 820 | ||
664 | ; Fill in the IP header ( some data is in the socket descriptor) |
821 | ; Fill in the IP header (some data is in the socket descriptor) |
665 | mov eax, [ebx + 8] |
822 | mov eax, [ebx + SOCKET.LocalIP] |
666 | mov [edx + 12], eax ; source IP |
823 | mov [edx + IP_PACKET.SourceAddress], eax |
667 | mov eax, [ebx + 16] |
824 | mov eax, [ebx + SOCKET.RemoteIP] |
668 | mov [edx + 16], eax ; Destination IP |
- | |
669 | 825 | mov [edx + IP_PACKET.DestinationAddress], eax |
|
670 | mov al, 0x45 |
- | |
671 | mov [edx], al ; Version, IHL |
826 | |
Line 672... | Line 827... | ||
672 | xor al, al |
827 | mov [edx + IP_PACKET.VersionAndIHL], 0x45 |
673 | mov [edx + 1], al ; Type of service |
828 | mov [edx + IP_PACKET.TypeOfService], 0 |
Line 674... | Line 829... | ||
674 | 829 | ||
675 | pop eax ; Get the UDP data length |
- | |
676 | push eax |
- | |
677 | 830 | pop eax ; Get the UDP data length |
|
678 | add eax, 20 + 8 ; add IP header and UDP header lengths |
- | |
679 | mov [edx + 2], ah |
831 | push eax |
680 | mov [edx + 3], al |
- | |
681 | xor al, al |
- | |
682 | mov [edx + 4], al |
832 | |
683 | mov [edx + 5], al |
833 | add eax, 20 + 8 ; add IP header and UDP header lengths |
684 | mov al, 0x40 |
834 | xchg al, ah |
685 | mov [edx + 6], al |
835 | mov [edx + IP_PACKET.TotalLength], ax |
686 | xor al, al |
- | |
687 | mov [edx + 7], al |
836 | xor eax, eax |
Line 688... | Line 837... | ||
688 | mov al, 0x20 |
837 | mov [edx + IP_PACKET.Identification], ax |
689 | mov [edx + 8], al |
- | |
690 | mov al, 17 |
838 | mov [edx + IP_PACKET.FlagsAndFragmentOffset], 0x0040 |
Line 691... | Line 839... | ||
691 | mov [edx + 9], al |
839 | mov [edx + IP_PACKET.TimeToLive], 0x20 |
692 | 840 | mov [edx + IP_PACKET.Protocol], PROTOCOL_UDP |
|
693 | ; Checksum left unfilled |
841 | |
Line 694... | Line 842... | ||
694 | xor ax, ax |
842 | ; Checksum left unfilled |
695 | mov [edx + 10], ax |
843 | mov [edx + IP_PACKET.HeaderChecksum], ax |
Line 696... | Line 844... | ||
696 | 844 | ||
697 | ; Fill in the UDP header ( some data is in the socket descriptor) |
845 | ; Fill in the UDP header (some data is in the socket descriptor) |
Line 698... | Line 846... | ||
698 | mov ax, [ebx + 12] |
846 | mov ax, [ebx + SOCKET.LocalPort] |
699 | mov [edx + 20], ax |
847 | mov [edx + 20 + UDP_PACKET.SourcePort], ax |
700 | 848 | ||
Line 701... | Line 849... | ||
701 | mov ax, [ebx + 20] |
849 | mov ax, [ebx + SOCKET.RemotePort] |
702 | mov [edx + 20 + 2], ax |
850 | mov [edx + 20 + UDP_PACKET.DestinationPort], ax |
703 | 851 | ||
Line 704... | Line 852... | ||
704 | pop eax |
852 | pop eax |
705 | push eax |
853 | push eax |
706 | 854 | ||
Line 728... | Line 876... | ||
728 | rep movsb ; copy the data across |
876 | rep movsb ; copy the data across |
Line 729... | Line 877... | ||
729 | 877 | ||
730 | ; we have edx as IPbuffer ptr. |
878 | ; we have edx as IPbuffer ptr. |
731 | ; Fill in the UDP checksum |
879 | ; Fill in the UDP checksum |
732 | ; First, fill in pseudoheader |
880 | ; First, fill in pseudoheader |
733 | mov eax, [edx + 12] |
881 | mov eax, [edx + IP_PACKET.SourceAddress] |
734 | mov [pseudoHeader], eax |
882 | mov [pseudoHeader], eax |
735 | mov eax, [edx + 16] |
883 | mov eax, [edx + IP_PACKET.DestinationAddress] |
736 | mov [pseudoHeader+4], eax |
884 | mov [pseudoHeader + 4], eax |
737 | mov ax, 0x1100 ; 0 + protocol |
- | |
738 | mov [pseudoHeader+8], ax |
885 | mov word[pseudoHeader + 8], PROTOCOL_UDP shl 8 + 0 ; 0 + protocol |
739 | add ebx, 8 |
886 | add ebx, 8 |
740 | mov eax, ebx |
887 | mov eax, ebx |
741 | mov [pseudoHeader+10], ah |
888 | xchg al, ah |
Line 742... | Line 889... | ||
742 | mov [pseudoHeader+11], al |
889 | mov [pseudoHeader + 10], ax |
743 | 890 | ||
744 | mov eax, pseudoHeader |
891 | mov eax, pseudoHeader |
745 | mov [checkAdd1], eax |
892 | mov [checkAdd1], eax |
Line 755... | Line 902... | ||
755 | ; store it in the UDP checksum ( in the correct order! ) |
902 | ; store it in the UDP checksum ( in the correct order! ) |
756 | mov ax, [checkResult] |
903 | mov ax, [checkResult] |
Line 757... | Line 904... | ||
757 | 904 | ||
758 | ; If the UDP checksum computes to 0, we must make it 0xffff |
905 | ; If the UDP checksum computes to 0, we must make it 0xffff |
759 | ; (0 is reserved for 'not used') |
906 | ; (0 is reserved for 'not used') |
760 | cmp ax, 0 |
907 | test ax, ax |
761 | jne sw_001 |
908 | jnz @f |
Line 762... | Line -... | ||
762 | mov ax, 0xffff |
- | |
763 | 909 | mov ax, 0xffff |
|
764 | sw_001: |
910 | |
Line 765... | Line 911... | ||
765 | mov [edx + 20 + 6], ah |
911 | @@: xchg al, ah |
766 | mov [edx + 20 + 7], al |
912 | mov [edx + 20 + UDP_PACKET.Checksum], ax |
767 | 913 | ||
768 | ; Fill in the IP header checksum |
- | |
769 | GET_IHL ecx,edx ; get IP-Header length |
914 | ; Fill in the IP header checksum |
770 | stdcall checksum_jb,edx,ecx ; buf_ptr, buf_size |
915 | GET_IHL ecx,edx ; get IP-Header length |
Line 771... | Line 916... | ||
771 | 916 | stdcall checksum_jb,edx,ecx ; buf_ptr, buf_size |
|
772 | mov [edx + 10], ah |
917 | xchg al, ah |
Line 773... | Line 918... | ||
773 | mov [edx + 11], al |
918 | mov [edx + IP_PACKET.HeaderChecksum], ax |
774 | 919 | ||
775 | ; Check destination IP address. |
- | |
776 | ; If it is the local host IP, route it back to IP_RX |
920 | ; Check destination IP address. |
777 | 921 | ; If it is the local host IP, route it back to IP_RX |
|
778 | pop ebx |
922 | |
779 | mov eax, NET1OUT_QUEUE |
923 | pop ebx |
780 | 924 | mov eax, NET1OUT_QUEUE |
|
Line 781... | Line 925... | ||
781 | mov ecx, [ edx + 16] |
925 | mov ecx, [edx + SOCKET.RemoteIP] |
782 | mov edx, [stack_ip] |
926 | mov edx, [stack_ip] |
783 | cmp edx, ecx |
927 | cmp edx, ecx |
Line 784... | Line 928... | ||
784 | jne sw_notlocal |
928 | jne .not_local |
785 | mov eax, IPIN_QUEUE |
- | |
786 | - | ||
787 | sw_notlocal: |
929 | mov eax, IPIN_QUEUE |
Line -... | Line 930... | ||
- | 930 | ||
- | 931 | .not_local: |
|
- | 932 | ; Send it. |
|
- | 933 | call queue |
|
Line 788... | Line 934... | ||
788 | ; Send it. |
934 | |
789 | call queue |
935 | xor eax, eax |
790 | 936 | ret |
|
Line 805... | Line 951... | ||
805 | ; pointer to data in edx |
951 | ; pointer to data in edx |
806 | ; returns 0 in eax ok, -1 == failed ( invalid socket, or |
952 | ; returns 0 in eax ok, -1 == failed ( invalid socket, or |
807 | ; could not queue IP packet ) |
953 | ; could not queue IP packet ) |
808 | ; |
954 | ; |
809 | ;*************************************************************************** |
955 | ;*************************************************************************** |
810 | socket_write_tcp: |
956 | proc socket_write_tcp stdcall |
811 | Index2RealAddr ebx |
957 | local sockAddr dd ? |
Line -... | Line 958... | ||
- | 958 | ||
- | 959 | ; DEBUGF 1, "socket_write_tcp(0x%x)\n", ebx |
|
- | 960 | stdcall net_socket_num_to_addr, ebx |
|
- | 961 | or eax, eax |
|
- | 962 | jz .error |
|
- | 963 | ||
812 | 964 | mov ebx, eax |
|
Line 813... | Line -... | ||
813 | mov [sktAddr], ebx |
- | |
814 | 965 | mov [sockAddr], ebx |
|
815 | mov eax, 0xFFFFFFFF |
966 | |
816 | ; If the socket is invalid, return with an error code |
967 | ; If the socket is invalid, return with an error code |
Line 817... | Line 968... | ||
817 | cmp [ebx], dword SOCK_EMPTY |
968 | cmp [ebx + SOCKET.Status], SOCK_EMPTY |
818 | je swt_exit |
969 | je .error |
819 | 970 | ||
820 | ; If the sockets window timer is nonzero, do not queue packet |
971 | ; If the sockets window timer is nonzero, do not queue packet |
Line 821... | Line 972... | ||
821 | ; TODO - done |
972 | ; TODO - done |
822 | cmp [ebx + SOCKET.wndsizeTimer], dword 0 |
973 | cmp [ebx + SOCKET.wndsizeTimer], 0 |
823 | jne swt_exit |
974 | jne .error |
824 | 975 | ||
Line 825... | Line 976... | ||
825 | mov eax, EMPTY_QUEUE |
976 | mov eax, EMPTY_QUEUE |
Line 826... | Line -... | ||
826 | call dequeue |
- | |
827 | cmp ax, NO_BUFFER |
- | |
828 | je swt_exit |
977 | call dequeue |
829 | 978 | cmp ax, NO_BUFFER |
|
830 | push eax |
979 | je .error |
831 | 980 | ||
832 | mov bl, 0x10 ; ACK |
981 | push eax |
Line 833... | Line 982... | ||
833 | 982 | ||
834 | ; Get the address of the callers data |
983 | ; Get the address of the callers data |
Line 835... | Line 984... | ||
835 | mov edi, [TASK_BASE] |
984 | mov edi, [TASK_BASE] |
- | 985 | add edi, TASKDATA.mem_start |
|
836 | add edi, TASKDATA.mem_start |
986 | add edx, [edi] |
837 | add edx, [edi] |
987 | mov esi, edx |
Line 838... | Line 988... | ||
838 | mov esi, edx |
988 | |
839 | 989 | pop eax |
|
Line 840... | Line 990... | ||
840 | pop eax |
990 | push eax |
841 | push eax |
991 | |
842 | 992 | push ecx |
|
Line 843... | Line 993... | ||
843 | push ecx |
993 | mov bl, TH_ACK |
844 | call buildTCPPacket |
994 | stdcall build_tcp_packet, [sockAddr] |
845 | pop ecx |
995 | pop ecx |
846 | - | ||
847 | ; Check destination IP address. |
996 | |
848 | ; If it is the local host IP, route it back to IP_RX |
997 | ; Check destination IP address. |
Line 849... | Line 998... | ||
849 | 998 | ; If it is the local host IP, route it back to IP_RX |
|
850 | pop ebx |
999 | |
Line 851... | Line 1000... | ||
851 | push ecx |
1000 | pop ebx |
Line 852... | Line 1001... | ||
852 | mov eax, NET1OUT_QUEUE |
1001 | push ecx |
Line 853... | Line 1002... | ||
853 | 1002 | mov eax, NET1OUT_QUEUE |
|
Line 854... | Line 1003... | ||
854 | mov edx, [stack_ip] |
1003 | |
855 | mov ecx, [sktAddr ] |
1004 | mov edx, [stack_ip] |
856 | mov ecx, [ecx + 16] |
1005 | mov ecx, [sockAddr] |
857 | cmp edx, ecx |
1006 | cmp edx, [ecx + SOCKET.RemoteIP] |
Line 858... | Line 1007... | ||
858 | jne swt_notlocal |
1007 | jne .not_local |
Line 859... | Line 1008... | ||
859 | mov eax, IPIN_QUEUE |
1008 | mov eax, IPIN_QUEUE |
860 | 1009 | ||
861 | swt_notlocal: |
1010 | .not_local: |
862 | pop ecx |
1011 | pop ecx |
Line 863... | Line 1012... | ||
863 | 1012 | ||
864 | push ebx ; save ipbuffer number |
1013 | push ebx ; save ipbuffer number |
865 | 1014 | ||
- | 1015 | call queue |
|
866 | call queue |
1016 | |
867 | 1017 | mov esi, [sockAddr] |
|
868 | mov esi, [sktAddr] |
1018 | |
869 | 1019 | ; increament SND.NXT in socket |
|
870 | ; increament SND.NXT in socket |
1020 | ; Amount to increment by is in ecx |
Line 871... | Line -... | ||
871 | ; Amount to increment by is in ecx |
- | |
872 | add esi, 48 |
1021 | add esi, SOCKET.SND_NXT |
Line 873... | Line 1022... | ||
873 | call add_inet_esi |
1022 | call add_inet_esi |
874 | 1023 | ||
875 | pop ebx |
1024 | pop ebx |
876 | 1025 | ||
877 | ; Copy the IP buffer to a resend queue |
1026 | ; Copy the IP buffer to a resend queue |
878 | ; If there isn't one, dont worry about it for now |
1027 | ; If there isn't one, dont worry about it for now |
879 | mov esi, resendQ |
1028 | mov esi, resendQ |
Line 880... | Line 1029... | ||
880 | mov ecx, 0 |
1029 | mov ecx, 0 |
881 | - | ||
882 | swt003: |
1030 | |
883 | cmp ecx, NUMRESENDENTRIES |
1031 | .next_resendq: |
884 | je swt001 ; None found |
1032 | cmp ecx, NUMRESENDENTRIES |
885 | cmp [esi], byte 0xFF |
1033 | je .exit ; None found |
Line 886... | Line 1034... | ||
886 | je swt002 ; found one |
1034 | ;cmp byte[esi], 0xff ; XTODO: 0xff -> 0 |
887 | inc ecx |
1035 | cmp dword[esi + 4], 0 |
888 | add esi, 4 |
1036 | je @f ; found one |
889 | jmp swt003 |
1037 | inc ecx |
890 | 1038 | add esi, 8 |
|
891 | swt002: |
1039 | jmp .next_resendq |
Line 892... | Line 1040... | ||
892 | push ebx |
1040 | |
893 | 1041 | @@: push ebx |
|
894 | ; OK, we have a buffer descriptor ptr in esi. |
1042 | |
895 | ; resend entry # in ecx |
1043 | ; OK, we have a buffer descriptor ptr in esi. |
Line 924... | Line 1072... | ||
924 | ; do copy |
1072 | ; do copy |
925 | mov ecx, IPBUFFSIZE |
1073 | mov ecx, IPBUFFSIZE |
926 | cld |
1074 | cld |
927 | rep movsb |
1075 | rep movsb |
Line 928... | Line 1076... | ||
928 | 1076 | ||
929 | swt001: |
1077 | .exit: |
930 | xor eax, eax |
- | |
931 | - | ||
932 | swt_exit: |
1078 | xor eax, eax |
Line -... | Line 1079... | ||
- | 1079 | ret |
|
- | 1080 | ||
- | 1081 | .error: |
|
- | 1082 | or eax, -1 |