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