Rev 2993 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1159 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2362 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
1159 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
2888 | hidnplayr | 6 | ;; Part of the tcp/ip network stack for KolibriOS ;; |
7 | ;; ;; |
||
8 | ;; Written by hidnplayr@kolibrios.org, ;; |
||
1529 | hidnplayr | 9 | ;; and Clevermouse. ;; |
1159 | hidnplayr | 10 | ;; ;; |
1529 | hidnplayr | 11 | ;; Based on code by mike.dld ;; |
1159 | hidnplayr | 12 | ;; ;; |
1529 | hidnplayr | 13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; Version 2, June 1991 ;; |
||
15 | ;; ;; |
||
1159 | hidnplayr | 16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
17 | |||
1206 | hidnplayr | 18 | $Revision: 2994 $ |
1159 | hidnplayr | 19 | |
1773 | hidnplayr | 20 | |
2402 | hidnplayr | 21 | struct SOCKET |
1249 | hidnplayr | 22 | |
2402 | hidnplayr | 23 | NextPtr dd ? ; pointer to next socket in list |
24 | PrevPtr dd ? ; pointer to previous socket in list |
||
25 | Number dd ? ; socket number |
||
1249 | hidnplayr | 26 | |
2402 | hidnplayr | 27 | mutex MUTEX |
1249 | hidnplayr | 28 | |
2402 | hidnplayr | 29 | PID dd ? ; application process id |
30 | Domain dd ? ; INET/UNIX/.. |
||
31 | Type dd ? ; RAW/STREAM/DGRAP |
||
32 | Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP |
||
33 | errorcode dd ? |
||
2877 | hidnplayr | 34 | device dd ? |
1249 | hidnplayr | 35 | |
2402 | hidnplayr | 36 | options dd ? |
37 | state dd ? |
||
38 | backlog dw ? ; how many incomming connections that can be queued |
||
1249 | hidnplayr | 39 | |
2402 | hidnplayr | 40 | snd_proc dd ? |
41 | rcv_proc dd ? |
||
1536 | hidnplayr | 42 | |
2305 | hidnplayr | 43 | ends |
1249 | hidnplayr | 44 | |
2402 | hidnplayr | 45 | struct IP_SOCKET SOCKET |
1254 | hidnplayr | 46 | |
2402 | hidnplayr | 47 | LocalIP rd 4 |
48 | RemoteIP rd 4 |
||
1318 | hidnplayr | 49 | |
2305 | hidnplayr | 50 | ends |
1159 | hidnplayr | 51 | |
2402 | hidnplayr | 52 | struct TCP_SOCKET IP_SOCKET |
1249 | hidnplayr | 53 | |
2402 | hidnplayr | 54 | LocalPort dw ? |
55 | RemotePort dw ? |
||
1514 | hidnplayr | 56 | |
2402 | hidnplayr | 57 | t_state dd ? ; TCB state |
2955 | hidnplayr | 58 | t_rxtshift db ? |
59 | rb 3 ; align |
||
2402 | hidnplayr | 60 | t_rxtcur dd ? |
61 | t_dupacks dd ? |
||
62 | t_maxseg dd ? |
||
63 | t_force dd ? |
||
64 | t_flags dd ? |
||
1514 | hidnplayr | 65 | |
66 | ;--------------- |
||
67 | ; RFC783 page 21 |
||
68 | |||
69 | ; send sequence |
||
2402 | hidnplayr | 70 | SND_UNA dd ? ; sequence number of unack'ed sent Packets |
71 | SND_NXT dd ? ; next send sequence number to use |
||
2890 | hidnplayr | 72 | SND_UP dd ? ; urgent pointer |
2402 | hidnplayr | 73 | SND_WL1 dd ? ; window minus one |
74 | SND_WL2 dd ? ; |
||
75 | ISS dd ? ; initial send sequence number |
||
76 | SND_WND dd ? ; send window |
||
1514 | hidnplayr | 77 | |
78 | ; receive sequence |
||
2957 | hidnplayr | 79 | RCV_WND dd ? ; receive window |
2402 | hidnplayr | 80 | RCV_NXT dd ? ; next receive sequence number to use |
2890 | hidnplayr | 81 | RCV_UP dd ? ; urgent pointer |
2402 | hidnplayr | 82 | IRS dd ? ; initial receive sequence number |
1514 | hidnplayr | 83 | |
84 | ;--------------------- |
||
85 | ; Additional variables |
||
86 | |||
87 | ; receive variables |
||
2402 | hidnplayr | 88 | RCV_ADV dd ? |
1514 | hidnplayr | 89 | |
90 | ; retransmit variables |
||
2402 | hidnplayr | 91 | SND_MAX dd ? |
1514 | hidnplayr | 92 | |
93 | ; congestion control |
||
2402 | hidnplayr | 94 | SND_CWND dd ? |
95 | SND_SSTHRESH dd ? |
||
1514 | hidnplayr | 96 | |
97 | ;---------------------- |
||
98 | ; Transmit timing stuff |
||
2402 | hidnplayr | 99 | t_idle dd ? |
100 | t_rtt dd ? |
||
101 | t_rtseq dd ? |
||
102 | t_srtt dd ? |
||
103 | t_rttvar dd ? |
||
104 | t_rttmin dd ? |
||
105 | max_sndwnd dd ? |
||
1514 | hidnplayr | 106 | |
107 | ;----------------- |
||
108 | ; Out-of-band data |
||
2402 | hidnplayr | 109 | t_oobflags dd ? |
110 | t_iobc dd ? |
||
111 | t_softerror dd ? |
||
1514 | hidnplayr | 112 | |
113 | |||
114 | ;--------- |
||
2924 | hidnplayr | 115 | ; RFC 1323 ; the order of next 4 elements may not change |
1514 | hidnplayr | 116 | |
2402 | hidnplayr | 117 | SND_SCALE db ? |
118 | RCV_SCALE db ? |
||
119 | requested_s_scale db ? |
||
120 | request_r_scale db ? |
||
1514 | hidnplayr | 121 | |
2924 | hidnplayr | 122 | ts_recent dd ? ; a copy of the most-recent valid timestamp from the other end |
2402 | hidnplayr | 123 | ts_recent_age dd ? |
124 | last_ack_sent dd ? |
||
1519 | hidnplayr | 125 | |
2310 | hidnplayr | 126 | |
1519 | hidnplayr | 127 | ;------- |
128 | ; Timers |
||
2955 | hidnplayr | 129 | timer_retransmission dd ? ; rexmt |
130 | timer_persist dd ? |
||
131 | timer_keepalive dd ? ; keepalive/syn timeout |
||
132 | timer_timed_wait dd ? ; also used as 2msl timer |
||
1519 | hidnplayr | 133 | |
2890 | hidnplayr | 134 | ; extra |
135 | |||
2924 | hidnplayr | 136 | ts_ecr dd ? ; timestamp echo reply |
2937 | hidnplayr | 137 | ts_val dd ? |
138 | temp_bits db ? |
||
2890 | hidnplayr | 139 | |
2305 | hidnplayr | 140 | ends |
1249 | hidnplayr | 141 | |
2402 | hidnplayr | 142 | struct UDP_SOCKET IP_SOCKET |
1249 | hidnplayr | 143 | |
2402 | hidnplayr | 144 | LocalPort dw ? |
145 | RemotePort dw ? |
||
146 | firstpacket db ? |
||
1249 | hidnplayr | 147 | |
2305 | hidnplayr | 148 | ends |
1249 | hidnplayr | 149 | |
150 | |||
2402 | hidnplayr | 151 | struct ICMP_SOCKET IP_SOCKET |
1249 | hidnplayr | 152 | |
2402 | hidnplayr | 153 | Identifier dw ? |
1514 | hidnplayr | 154 | |
2305 | hidnplayr | 155 | ends |
1514 | hidnplayr | 156 | |
157 | |||
2402 | hidnplayr | 158 | struct RING_BUFFER |
2311 | hidnplayr | 159 | |
2402 | hidnplayr | 160 | start_ptr dd ? ; Pointer to start of buffer |
161 | end_ptr dd ? ; pointer to end of buffer |
||
162 | read_ptr dd ? ; Read pointer |
||
163 | write_ptr dd ? ; Write pointer |
||
164 | size dd ? ; Number of bytes buffered |
||
2311 | hidnplayr | 165 | |
2305 | hidnplayr | 166 | ends |
1514 | hidnplayr | 167 | |
2402 | hidnplayr | 168 | struct STREAM_SOCKET TCP_SOCKET |
1529 | hidnplayr | 169 | |
2402 | hidnplayr | 170 | rcv RING_BUFFER |
171 | snd RING_BUFFER |
||
1529 | hidnplayr | 172 | |
2305 | hidnplayr | 173 | ends |
1529 | hidnplayr | 174 | |
2402 | hidnplayr | 175 | struct socket_queue_entry |
1529 | hidnplayr | 176 | |
2402 | hidnplayr | 177 | data_ptr dd ? |
178 | buf_ptr dd ? |
||
179 | data_size dd ? |
||
1529 | hidnplayr | 180 | |
1274 | hidnplayr | 181 | ends |
182 | |||
1514 | hidnplayr | 183 | |
2614 | hidnplayr | 184 | SOCKETBUFFSIZE = 4096 ; in bytes |
1514 | hidnplayr | 185 | |
2614 | hidnplayr | 186 | SOCKET_QUEUE_SIZE = 10 ; maximum number ofincoming packets queued for 1 socket |
1514 | hidnplayr | 187 | ; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start |
2614 | hidnplayr | 188 | SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) |
1249 | hidnplayr | 189 | |
1159 | hidnplayr | 190 | uglobal |
2402 | hidnplayr | 191 | net_sockets rd 4 |
192 | last_socket_num dd ? |
||
193 | last_UDP_port dw ? ; These values give the number of the last used ephemeral port |
||
194 | last_TCP_port dw ? ; |
||
1159 | hidnplayr | 195 | endg |
196 | |||
197 | |||
1257 | hidnplayr | 198 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 199 | ; |
200 | ; SOCKET_init |
||
201 | ; |
||
1257 | hidnplayr | 202 | ;----------------------------------------------------------------- |
2402 | hidnplayr | 203 | macro SOCKET_init { |
1159 | hidnplayr | 204 | |
2402 | hidnplayr | 205 | xor eax, eax |
206 | mov edi, net_sockets |
||
207 | mov ecx, 5 |
||
208 | rep stosd |
||
1159 | hidnplayr | 209 | |
1529 | hidnplayr | 210 | @@: |
2402 | hidnplayr | 211 | pseudo_random eax |
212 | cmp ax, MIN_EPHEMERAL_PORT |
||
213 | jb @r |
||
214 | cmp ax, MAX_EPHEMERAL_PORT |
||
215 | ja @r |
||
216 | mov [last_UDP_port], ax |
||
1529 | hidnplayr | 217 | |
218 | @@: |
||
2402 | hidnplayr | 219 | pseudo_random eax |
220 | cmp ax, MIN_EPHEMERAL_PORT |
||
221 | jb @r |
||
222 | cmp ax, MAX_EPHEMERAL_PORT |
||
223 | ja @r |
||
224 | mov [last_TCP_port], ax |
||
1529 | hidnplayr | 225 | |
226 | } |
||
227 | |||
228 | |||
1257 | hidnplayr | 229 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 230 | ; |
2994 | hidnplayr | 231 | ; SOCKET_block |
232 | ; |
||
233 | ;----------------------------------------------------------------- |
||
234 | macro SOCKET_block socket, loop, done { |
||
235 | |||
236 | test [socket + SOCKET.options], SO_BLOCK ; Is this a blocking socket? |
||
237 | jz done ; No, return immediately |
||
238 | |||
239 | push esi |
||
240 | mov esi, 5 ; yes, wait for event |
||
241 | call delay_ms |
||
242 | pop esi |
||
243 | |||
244 | jmp loop |
||
245 | |||
246 | } |
||
247 | |||
248 | |||
249 | ;----------------------------------------------------------------- |
||
250 | ; |
||
1159 | hidnplayr | 251 | ; Socket API (function 74) |
252 | ; |
||
1257 | hidnplayr | 253 | ;----------------------------------------------------------------- |
2614 | hidnplayr | 254 | align 4 |
255 | sys_socket: |
||
256 | |||
257 | cmp ebx, 255 |
||
258 | jz SOCKET_debug |
||
259 | |||
260 | cmp ebx, .number |
||
261 | ja s_error |
||
262 | jmp dword [.table + 4*ebx] |
||
263 | |||
264 | .table: |
||
2402 | hidnplayr | 265 | dd SOCKET_open ; 0 |
266 | dd SOCKET_close ; 1 |
||
267 | dd SOCKET_bind ; 2 |
||
268 | dd SOCKET_listen ; 3 |
||
269 | dd SOCKET_connect ; 4 |
||
270 | dd SOCKET_accept ; 5 |
||
271 | dd SOCKET_send ; 6 |
||
272 | dd SOCKET_receive ; 7 |
||
273 | dd SOCKET_set_opt ; 8 |
||
274 | dd SOCKET_get_opt ; 9 |
||
2614 | hidnplayr | 275 | .number = ($ - .table) / 4 - 1 |
2301 | hidnplayr | 276 | |
1529 | hidnplayr | 277 | s_error: |
2402 | hidnplayr | 278 | DEBUGF 1,"socket error\n" |
279 | mov dword [esp+32], -1 |
||
1529 | hidnplayr | 280 | |
2402 | hidnplayr | 281 | ret |
1529 | hidnplayr | 282 | |
1159 | hidnplayr | 283 | |
2301 | hidnplayr | 284 | |
1257 | hidnplayr | 285 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 286 | ; |
287 | ; SOCKET_open |
||
288 | ; |
||
289 | ; IN: domain in ecx |
||
290 | ; type in edx |
||
1196 | hidnplayr | 291 | ; protocol in esi |
1159 | hidnplayr | 292 | ; OUT: eax is socket num, -1 on error |
293 | ; |
||
1257 | hidnplayr | 294 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 295 | align 4 |
1514 | hidnplayr | 296 | SOCKET_open: |
1159 | hidnplayr | 297 | |
2891 | hidnplayr | 298 | DEBUGF 1,"SOCKET_open: domain=%u type=%u protocol=%x\n", ecx, edx, esi |
1159 | hidnplayr | 299 | |
2402 | hidnplayr | 300 | push ecx edx esi |
301 | call SOCKET_alloc |
||
302 | pop esi edx ecx |
||
303 | jz s_error |
||
1159 | hidnplayr | 304 | |
2402 | hidnplayr | 305 | mov [esp+32], edi ; return socketnumber |
1542 | hidnplayr | 306 | |
2402 | hidnplayr | 307 | mov [eax + SOCKET.Domain], ecx |
308 | mov [eax + SOCKET.Type], edx |
||
309 | mov [eax + SOCKET.Protocol], esi |
||
1159 | hidnplayr | 310 | |
2402 | hidnplayr | 311 | cmp ecx, AF_INET4 |
312 | jne .no_inet4 |
||
1529 | hidnplayr | 313 | |
2402 | hidnplayr | 314 | cmp edx, SOCK_DGRAM |
315 | je .udp |
||
1536 | hidnplayr | 316 | |
2402 | hidnplayr | 317 | cmp edx, SOCK_STREAM |
318 | je .tcp |
||
1529 | hidnplayr | 319 | |
2402 | hidnplayr | 320 | cmp edx, SOCK_RAW |
321 | je .raw |
||
1541 | hidnplayr | 322 | |
1536 | hidnplayr | 323 | .no_inet4: |
2931 | hidnplayr | 324 | cmp ecx, AF_PPP |
325 | jne .no_ppp |
||
326 | |||
327 | cmp esi, PPP_PROTO_ETHERNET |
||
328 | je .pppoe |
||
329 | |||
330 | .no_ppp: |
||
2402 | hidnplayr | 331 | ret |
1536 | hidnplayr | 332 | |
1542 | hidnplayr | 333 | align 4 |
334 | .raw: |
||
2402 | hidnplayr | 335 | test esi, esi ; IP_PROTO_IP |
336 | jz .ip |
||
1529 | hidnplayr | 337 | |
2402 | hidnplayr | 338 | cmp esi, IP_PROTO_ICMP |
339 | je .icmp |
||
1529 | hidnplayr | 340 | |
2402 | hidnplayr | 341 | cmp esi, IP_PROTO_UDP |
342 | je .udp |
||
1533 | hidnplayr | 343 | |
2402 | hidnplayr | 344 | cmp esi, IP_PROTO_TCP |
345 | je .tcp |
||
1536 | hidnplayr | 346 | |
2402 | hidnplayr | 347 | ret |
1159 | hidnplayr | 348 | |
1542 | hidnplayr | 349 | align 4 |
1536 | hidnplayr | 350 | .udp: |
2402 | hidnplayr | 351 | mov [eax + SOCKET.Protocol], IP_PROTO_UDP |
352 | mov [eax + SOCKET.snd_proc], SOCKET_send_udp |
||
353 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
||
354 | ret |
||
1529 | hidnplayr | 355 | |
1542 | hidnplayr | 356 | align 4 |
357 | .tcp: |
||
2402 | hidnplayr | 358 | mov [eax + SOCKET.Protocol], IP_PROTO_TCP |
359 | mov [eax + SOCKET.snd_proc], SOCKET_send_tcp |
||
360 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_tcp |
||
1838 | hidnplayr | 361 | |
2612 | hidnplayr | 362 | TCP_init_socket eax |
2402 | hidnplayr | 363 | ret |
1529 | hidnplayr | 364 | |
365 | |||
1543 | hidnplayr | 366 | align 4 |
367 | .ip: |
||
2402 | hidnplayr | 368 | mov [eax + SOCKET.snd_proc], SOCKET_send_ip |
369 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
||
370 | ret |
||
1541 | hidnplayr | 371 | |
1542 | hidnplayr | 372 | |
373 | align 4 |
||
1541 | hidnplayr | 374 | .icmp: |
2402 | hidnplayr | 375 | mov [eax + SOCKET.snd_proc], SOCKET_send_icmp |
376 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
||
377 | ret |
||
1541 | hidnplayr | 378 | |
2931 | hidnplayr | 379 | align 4 |
380 | .pppoe: |
||
381 | push eax |
||
382 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
||
383 | pop eax |
||
1541 | hidnplayr | 384 | |
2931 | hidnplayr | 385 | mov [eax + SOCKET.snd_proc], SOCKET_send_pppoe |
386 | mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram |
||
387 | ret |
||
1541 | hidnplayr | 388 | |
2931 | hidnplayr | 389 | |
1257 | hidnplayr | 390 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 391 | ; |
392 | ; SOCKET_bind |
||
393 | ; |
||
394 | ; IN: socket number in ecx |
||
395 | ; pointer to sockaddr struct in edx |
||
396 | ; length of that struct in esi |
||
397 | ; OUT: 0 on success |
||
398 | ; |
||
1257 | hidnplayr | 399 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 400 | align 4 |
1514 | hidnplayr | 401 | SOCKET_bind: |
1159 | hidnplayr | 402 | |
2891 | hidnplayr | 403 | DEBUGF 1,"SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
1159 | hidnplayr | 404 | |
2402 | hidnplayr | 405 | call SOCKET_num_to_ptr |
406 | jz s_error |
||
1159 | hidnplayr | 407 | |
2402 | hidnplayr | 408 | cmp esi, 2 |
409 | jb s_error |
||
1159 | hidnplayr | 410 | |
2402 | hidnplayr | 411 | cmp word [edx], AF_INET4 |
412 | je .af_inet4 |
||
1159 | hidnplayr | 413 | |
2402 | hidnplayr | 414 | cmp word [edx], AF_UNIX |
415 | je .af_unix |
||
1249 | hidnplayr | 416 | |
2402 | hidnplayr | 417 | jmp s_error |
1249 | hidnplayr | 418 | |
419 | .af_unix: |
||
2402 | hidnplayr | 420 | ; TODO: write code here |
1249 | hidnplayr | 421 | |
2402 | hidnplayr | 422 | mov dword [esp+32], 0 |
423 | ret |
||
1249 | hidnplayr | 424 | |
1159 | hidnplayr | 425 | .af_inet4: |
426 | |||
2402 | hidnplayr | 427 | cmp esi, 6 |
428 | jb s_error |
||
1159 | hidnplayr | 429 | |
2622 | hidnplayr | 430 | cmp [eax + SOCKET.Protocol], IP_PROTO_UDP |
431 | je .udp |
||
1159 | hidnplayr | 432 | |
2622 | hidnplayr | 433 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
434 | je .tcp |
||
1159 | hidnplayr | 435 | |
2622 | hidnplayr | 436 | jmp s_error |
437 | |||
438 | .tcp: |
||
439 | .udp: |
||
440 | |||
441 | mov ebx, [edx + 4] ; First, fill in the IP |
||
442 | test ebx, ebx ; If IP is 0, use default |
||
443 | jnz @f |
||
444 | mov ebx, [NET_DEFAULT] |
||
445 | mov ebx, [IP_LIST + 4*ebx] |
||
446 | @@: |
||
447 | mov [eax + IP_SOCKET.LocalIP], ebx |
||
448 | |||
449 | mov bx, [edx + 2] ; Now fill in the port if it's still available |
||
450 | call SOCKET_check_port |
||
451 | jz s_error ; ZF is set by socket_check_port, on error |
||
452 | |||
2891 | hidnplayr | 453 | DEBUGF 1,"SOCKET_bind: local ip=%u.%u.%u.%u\n",\ |
2402 | hidnplayr | 454 | [eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\ |
455 | [eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1 |
||
1159 | hidnplayr | 456 | |
2402 | hidnplayr | 457 | mov dword [esp+32], 0 |
458 | ret |
||
1159 | hidnplayr | 459 | |
460 | |||
461 | |||
462 | |||
1257 | hidnplayr | 463 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 464 | ; |
465 | ; SOCKET_connect |
||
466 | ; |
||
467 | ; IN: socket number in ecx |
||
468 | ; pointer to sockaddr struct in edx |
||
469 | ; length of that struct in esi |
||
470 | ; OUT: 0 on success |
||
471 | ; |
||
1257 | hidnplayr | 472 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 473 | align 4 |
1514 | hidnplayr | 474 | SOCKET_connect: |
1159 | hidnplayr | 475 | |
2891 | hidnplayr | 476 | DEBUGF 1,"SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
1159 | hidnplayr | 477 | |
2402 | hidnplayr | 478 | call SOCKET_num_to_ptr |
479 | jz s_error |
||
1159 | hidnplayr | 480 | |
2402 | hidnplayr | 481 | cmp esi, 8 |
482 | jb s_error |
||
1159 | hidnplayr | 483 | |
2402 | hidnplayr | 484 | cmp word [edx], AF_INET4 |
485 | je .af_inet4 |
||
1159 | hidnplayr | 486 | |
2402 | hidnplayr | 487 | jmp s_error |
1159 | hidnplayr | 488 | |
489 | .af_inet4: |
||
2402 | hidnplayr | 490 | cmp [eax + IP_SOCKET.LocalIP], 0 |
491 | jne @f |
||
492 | push [IP_LIST] |
||
493 | pop [eax + IP_SOCKET.LocalIP] |
||
1543 | hidnplayr | 494 | @@: |
1159 | hidnplayr | 495 | |
2402 | hidnplayr | 496 | cmp [eax + SOCKET.Protocol], IP_PROTO_UDP |
497 | je .udp |
||
1159 | hidnplayr | 498 | |
2402 | hidnplayr | 499 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
500 | je .tcp |
||
1159 | hidnplayr | 501 | |
2402 | hidnplayr | 502 | cmp [eax + SOCKET.Protocol], IP_PROTO_IP |
503 | je .ip |
||
1541 | hidnplayr | 504 | |
2402 | hidnplayr | 505 | cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP |
506 | je .ip |
||
1542 | hidnplayr | 507 | |
2402 | hidnplayr | 508 | jmp s_error |
1159 | hidnplayr | 509 | |
1542 | hidnplayr | 510 | align 4 |
1254 | hidnplayr | 511 | .udp: |
2402 | hidnplayr | 512 | pusha |
513 | lea ecx, [eax + SOCKET.mutex] |
||
514 | call mutex_lock |
||
515 | popa |
||
1543 | hidnplayr | 516 | |
2402 | hidnplayr | 517 | pushw [edx + 2] |
518 | pop [eax + UDP_SOCKET.RemotePort] |
||
1543 | hidnplayr | 519 | |
2402 | hidnplayr | 520 | pushd [edx + 4] |
521 | pop [eax + IP_SOCKET.RemoteIP] |
||
1543 | hidnplayr | 522 | |
2402 | hidnplayr | 523 | cmp [eax + UDP_SOCKET.LocalPort], 0 |
524 | jne @f |
||
525 | call SOCKET_find_port |
||
1543 | hidnplayr | 526 | @@: |
527 | |||
2402 | hidnplayr | 528 | mov [eax + UDP_SOCKET.firstpacket], 0 |
1159 | hidnplayr | 529 | |
2402 | hidnplayr | 530 | push eax |
531 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
||
532 | pop eax |
||
1159 | hidnplayr | 533 | |
2402 | hidnplayr | 534 | lea ecx, [eax + SOCKET.mutex] |
535 | call mutex_unlock |
||
1159 | hidnplayr | 536 | |
2402 | hidnplayr | 537 | mov dword [esp+32], 0 |
538 | ret |
||
539 | |||
1542 | hidnplayr | 540 | align 4 |
1254 | hidnplayr | 541 | .tcp: |
2402 | hidnplayr | 542 | pusha |
543 | lea ecx, [eax + SOCKET.mutex] |
||
544 | call mutex_lock |
||
545 | popa |
||
1159 | hidnplayr | 546 | |
2402 | hidnplayr | 547 | pushw [edx + 2] |
548 | pop [eax + TCP_SOCKET.RemotePort] |
||
1159 | hidnplayr | 549 | |
2402 | hidnplayr | 550 | pushd [edx + 4] |
551 | pop [eax + IP_SOCKET.RemoteIP] |
||
1159 | hidnplayr | 552 | |
2402 | hidnplayr | 553 | cmp [eax + TCP_SOCKET.LocalPort], 0 |
554 | jne @f |
||
555 | call SOCKET_find_port |
||
1543 | hidnplayr | 556 | @@: |
1159 | hidnplayr | 557 | |
2402 | hidnplayr | 558 | mov [eax + TCP_SOCKET.timer_persist], 0 |
559 | mov [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT |
||
2612 | hidnplayr | 560 | |
2402 | hidnplayr | 561 | push [TCP_sequence_num] |
562 | add [TCP_sequence_num], 6400 |
||
563 | pop [eax + TCP_SOCKET.ISS] |
||
564 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init |
||
1519 | hidnplayr | 565 | |
2612 | hidnplayr | 566 | |
2402 | hidnplayr | 567 | TCP_sendseqinit eax |
1529 | hidnplayr | 568 | |
1543 | hidnplayr | 569 | ; mov [ebx + TCP_SOCKET.timer_retransmission], ;; todo: create macro to set retransmission timer |
1533 | hidnplayr | 570 | |
2402 | hidnplayr | 571 | mov ebx, eax |
1159 | hidnplayr | 572 | |
2402 | hidnplayr | 573 | lea eax, [ebx + STREAM_SOCKET.snd] |
574 | call SOCKET_ring_create |
||
1543 | hidnplayr | 575 | |
2402 | hidnplayr | 576 | lea eax, [ebx + STREAM_SOCKET.rcv] |
577 | call SOCKET_ring_create |
||
1543 | hidnplayr | 578 | |
2402 | hidnplayr | 579 | pusha |
2939 | hidnplayr | 580 | lea ecx, [ebx + SOCKET.mutex] |
2402 | hidnplayr | 581 | call mutex_unlock |
582 | popa |
||
1733 | hidnplayr | 583 | |
2402 | hidnplayr | 584 | mov eax, ebx |
585 | call TCP_output |
||
1733 | hidnplayr | 586 | |
2994 | hidnplayr | 587 | ;;; TODO: wait for successfull connection if blocking socket |
588 | |||
2402 | hidnplayr | 589 | mov dword [esp+32], 0 |
590 | ret |
||
1159 | hidnplayr | 591 | |
1542 | hidnplayr | 592 | align 4 |
593 | .ip: |
||
2402 | hidnplayr | 594 | pusha |
595 | lea ecx, [eax + SOCKET.mutex] |
||
596 | call mutex_lock |
||
597 | popa |
||
1543 | hidnplayr | 598 | |
2402 | hidnplayr | 599 | pushd [edx + 4] |
600 | pop [eax + IP_SOCKET.RemoteIP] |
||
1159 | hidnplayr | 601 | |
2402 | hidnplayr | 602 | push eax |
603 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
||
604 | pop eax |
||
1543 | hidnplayr | 605 | |
2402 | hidnplayr | 606 | lea ecx, [eax + SOCKET.mutex] |
607 | call mutex_unlock |
||
1541 | hidnplayr | 608 | |
2402 | hidnplayr | 609 | mov dword [esp+32], 0 |
610 | ret |
||
1541 | hidnplayr | 611 | |
2402 | hidnplayr | 612 | |
1257 | hidnplayr | 613 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 614 | ; |
615 | ; SOCKET_listen |
||
616 | ; |
||
617 | ; IN: socket number in ecx |
||
618 | ; backlog in edx |
||
619 | ; OUT: eax is socket num, -1 on error |
||
620 | ; |
||
1257 | hidnplayr | 621 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 622 | align 4 |
1514 | hidnplayr | 623 | SOCKET_listen: |
1159 | hidnplayr | 624 | |
2891 | hidnplayr | 625 | DEBUGF 1,"SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx |
1159 | hidnplayr | 626 | |
2402 | hidnplayr | 627 | call SOCKET_num_to_ptr |
628 | jz s_error |
||
1159 | hidnplayr | 629 | |
2402 | hidnplayr | 630 | cmp [eax + SOCKET.Domain], AF_INET4 |
631 | jne s_error |
||
1254 | hidnplayr | 632 | |
2402 | hidnplayr | 633 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
634 | jne s_error |
||
1254 | hidnplayr | 635 | |
2402 | hidnplayr | 636 | cmp [eax + TCP_SOCKET.LocalPort], 0 |
637 | je s_error |
||
1514 | hidnplayr | 638 | |
2402 | hidnplayr | 639 | cmp [eax + IP_SOCKET.LocalIP], 0 |
640 | jne @f |
||
641 | push [IP_LIST] |
||
642 | pop [eax + IP_SOCKET.LocalIP] |
||
1543 | hidnplayr | 643 | @@: |
644 | |||
2402 | hidnplayr | 645 | cmp edx, MAX_backlog |
646 | jbe @f |
||
647 | mov edx, MAX_backlog |
||
1543 | hidnplayr | 648 | @@: |
1159 | hidnplayr | 649 | |
2402 | hidnplayr | 650 | mov [eax + SOCKET.backlog], dx |
651 | or [eax + SOCKET.options], SO_ACCEPTCON |
||
652 | mov [eax + TCP_SOCKET.t_state], TCPS_LISTEN |
||
2880 | hidnplayr | 653 | mov [eax + TCP_SOCKET.timer_keepalive], 0 ; disable keepalive timer |
1159 | hidnplayr | 654 | |
2402 | hidnplayr | 655 | push eax |
656 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up sockets queue |
||
657 | pop eax |
||
1543 | hidnplayr | 658 | |
2402 | hidnplayr | 659 | mov dword [esp+32], 0 |
1514 | hidnplayr | 660 | |
2402 | hidnplayr | 661 | ret |
1159 | hidnplayr | 662 | |
663 | |||
1257 | hidnplayr | 664 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 665 | ; |
666 | ; SOCKET_accept |
||
667 | ; |
||
668 | ; IN: socket number in ecx |
||
669 | ; addr in edx |
||
670 | ; addrlen in esi |
||
671 | ; OUT: eax is socket num, -1 on error |
||
672 | ; |
||
1257 | hidnplayr | 673 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 674 | align 4 |
1514 | hidnplayr | 675 | SOCKET_accept: |
1159 | hidnplayr | 676 | |
2891 | hidnplayr | 677 | DEBUGF 1,"SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi |
1159 | hidnplayr | 678 | |
2402 | hidnplayr | 679 | call SOCKET_num_to_ptr |
680 | jz s_error |
||
1159 | hidnplayr | 681 | |
2402 | hidnplayr | 682 | test [eax + SOCKET.options], SO_ACCEPTCON |
683 | jz s_error |
||
1543 | hidnplayr | 684 | |
2402 | hidnplayr | 685 | cmp [eax + SOCKET.Domain], AF_INET4 |
686 | jne s_error |
||
1249 | hidnplayr | 687 | |
2402 | hidnplayr | 688 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
689 | jne s_error |
||
1249 | hidnplayr | 690 | |
2994 | hidnplayr | 691 | .loop: |
692 | get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block |
||
693 | |||
694 | ; Ok, we got a socket ptr |
||
2572 | hidnplayr | 695 | mov eax, [esi] |
1249 | hidnplayr | 696 | |
2572 | hidnplayr | 697 | ; Change PID to that of the current process |
698 | mov ebx, [TASK_BASE] |
||
699 | mov ebx, [ebx + TASKDATA.pid] |
||
700 | mov [eax + SOCKET.PID], ebx |
||
701 | |||
2994 | hidnplayr | 702 | ; Convert it to a socket number |
2402 | hidnplayr | 703 | call SOCKET_ptr_to_num |
704 | jz s_error |
||
2994 | hidnplayr | 705 | ; and return it to caller |
2402 | hidnplayr | 706 | mov [esp+32], eax |
707 | ret |
||
1514 | hidnplayr | 708 | |
2994 | hidnplayr | 709 | .block: |
710 | SOCKET_block eax, .loop, s_error |
||
1159 | hidnplayr | 711 | |
1257 | hidnplayr | 712 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 713 | ; |
714 | ; SOCKET_close |
||
715 | ; |
||
716 | ; IN: socket number in ecx |
||
717 | ; OUT: eax is socket num, -1 on error |
||
718 | ; |
||
1257 | hidnplayr | 719 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 720 | align 4 |
1514 | hidnplayr | 721 | SOCKET_close: |
1159 | hidnplayr | 722 | |
2891 | hidnplayr | 723 | DEBUGF 1,"SOCKET_close: %u\n", ecx |
1159 | hidnplayr | 724 | |
2402 | hidnplayr | 725 | call SOCKET_num_to_ptr |
726 | jz s_error |
||
1159 | hidnplayr | 727 | |
2402 | hidnplayr | 728 | cmp [eax + SOCKET.Domain], AF_INET4 |
729 | jne s_error |
||
1159 | hidnplayr | 730 | |
2402 | hidnplayr | 731 | cmp [eax + SOCKET.Protocol], IP_PROTO_UDP |
732 | je .free |
||
1159 | hidnplayr | 733 | |
2402 | hidnplayr | 734 | cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP |
735 | je .free |
||
1159 | hidnplayr | 736 | |
2402 | hidnplayr | 737 | cmp [eax + SOCKET.Protocol], IP_PROTO_IP |
738 | je .free |
||
1542 | hidnplayr | 739 | |
2402 | hidnplayr | 740 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
741 | je .tcp |
||
1159 | hidnplayr | 742 | |
2402 | hidnplayr | 743 | jmp s_error |
1159 | hidnplayr | 744 | |
745 | .tcp: |
||
2402 | hidnplayr | 746 | cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED ; state must be LISTEN, SYN_SENT or CLOSED |
747 | jb .free |
||
1318 | hidnplayr | 748 | |
2890 | hidnplayr | 749 | call TCP_usrclosed |
2891 | hidnplayr | 750 | call TCP_output ;;;; Fixme: is this nescessary?? |
2994 | hidnplayr | 751 | |
752 | ;;; TODO: wait for successfull termination if blocking socket |
||
2402 | hidnplayr | 753 | mov dword [esp+32], 0 |
1159 | hidnplayr | 754 | |
2402 | hidnplayr | 755 | ret |
1159 | hidnplayr | 756 | |
1514 | hidnplayr | 757 | .free: |
2402 | hidnplayr | 758 | call SOCKET_free |
759 | mov dword [esp+32], 0 |
||
1159 | hidnplayr | 760 | |
2402 | hidnplayr | 761 | ret |
1159 | hidnplayr | 762 | |
763 | |||
1257 | hidnplayr | 764 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 765 | ; |
766 | ; SOCKET_receive |
||
767 | ; |
||
768 | ; IN: socket number in ecx |
||
1249 | hidnplayr | 769 | ; addr to buffer in edx |
770 | ; length of buffer in esi |
||
1159 | hidnplayr | 771 | ; flags in edi |
772 | ; OUT: eax is number of bytes copied, -1 on error |
||
773 | ; |
||
1257 | hidnplayr | 774 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 775 | align 4 |
1514 | hidnplayr | 776 | SOCKET_receive: |
1159 | hidnplayr | 777 | |
2891 | hidnplayr | 778 | DEBUGF 1,"SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi |
1514 | hidnplayr | 779 | |
2402 | hidnplayr | 780 | call SOCKET_num_to_ptr |
781 | jz s_error |
||
1159 | hidnplayr | 782 | |
2402 | hidnplayr | 783 | jmp [eax + SOCKET.rcv_proc] |
1533 | hidnplayr | 784 | |
1536 | hidnplayr | 785 | |
786 | align 4 |
||
1541 | hidnplayr | 787 | SOCKET_receive_dgram: |
1536 | hidnplayr | 788 | |
2402 | hidnplayr | 789 | DEBUGF 1,"SOCKET_receive: DGRAM\n" |
1536 | hidnplayr | 790 | |
2402 | hidnplayr | 791 | mov ebx, esi |
792 | mov edi, edx ; addr to buffer |
||
1159 | hidnplayr | 793 | |
2994 | hidnplayr | 794 | .loop: |
795 | get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block ; destroys esi and ecx |
||
1536 | hidnplayr | 796 | |
2402 | hidnplayr | 797 | mov ecx, [esi + socket_queue_entry.data_size] |
2891 | hidnplayr | 798 | DEBUGF 1,"SOCKET_receive: %u bytes data\n", ecx |
1159 | hidnplayr | 799 | |
2402 | hidnplayr | 800 | cmp ecx, ebx |
801 | ja .too_small |
||
1514 | hidnplayr | 802 | |
2402 | hidnplayr | 803 | push [esi + socket_queue_entry.buf_ptr] ; save the buffer addr so we can clear it later |
804 | mov esi, [esi + socket_queue_entry.data_ptr] |
||
2891 | hidnplayr | 805 | DEBUGF 1,"SOCKET_receive: Source buffer=%x real addr=%x\n", [esp], esi |
2402 | hidnplayr | 806 | mov [esp+32+4], ecx ; return number of bytes copied |
1159 | hidnplayr | 807 | |
1514 | hidnplayr | 808 | ; copy the data |
2402 | hidnplayr | 809 | shr ecx, 1 |
810 | jnc .nb |
||
811 | movsb |
||
1536 | hidnplayr | 812 | .nb: |
2402 | hidnplayr | 813 | shr ecx, 1 |
814 | jnc .nw |
||
815 | movsw |
||
1536 | hidnplayr | 816 | .nw: |
2402 | hidnplayr | 817 | test ecx, ecx |
818 | jz .nd |
||
819 | rep movsd |
||
1536 | hidnplayr | 820 | .nd: |
1159 | hidnplayr | 821 | |
2402 | hidnplayr | 822 | call kernel_free ; remove the packet |
823 | ret |
||
1514 | hidnplayr | 824 | |
1536 | hidnplayr | 825 | .too_small: |
1533 | hidnplayr | 826 | |
2891 | hidnplayr | 827 | DEBUGF 1,"SOCKET_receive: Buffer too small\n" |
2402 | hidnplayr | 828 | jmp s_error |
1536 | hidnplayr | 829 | |
2994 | hidnplayr | 830 | .block: |
831 | SOCKET_block eax, .loop, s_error |
||
832 | |||
833 | |||
1536 | hidnplayr | 834 | align 4 |
835 | SOCKET_receive_tcp: |
||
836 | |||
2402 | hidnplayr | 837 | DEBUGF 1,"SOCKET_receive: TCP\n" |
1536 | hidnplayr | 838 | |
2402 | hidnplayr | 839 | mov ecx, esi |
840 | mov edi, edx |
||
2994 | hidnplayr | 841 | xor edx, edx |
2402 | hidnplayr | 842 | add eax, STREAM_SOCKET.rcv |
2994 | hidnplayr | 843 | .loop: ;;;; FIXME: ecx! |
2402 | hidnplayr | 844 | call SOCKET_ring_read |
2994 | hidnplayr | 845 | test ecx, ecx |
846 | jz .block |
||
2402 | hidnplayr | 847 | call SOCKET_ring_free |
1533 | hidnplayr | 848 | |
2402 | hidnplayr | 849 | mov [esp+32], ecx ; return number of bytes copied |
850 | ret |
||
1159 | hidnplayr | 851 | |
2994 | hidnplayr | 852 | .block: |
853 | SOCKET_block (eax - STREAM_SOCKET.rcv), .loop, s_error |
||
1159 | hidnplayr | 854 | |
2994 | hidnplayr | 855 | |
1257 | hidnplayr | 856 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 857 | ; |
858 | ; SOCKET_send |
||
859 | ; |
||
860 | ; |
||
861 | ; IN: socket number in ecx |
||
1206 | hidnplayr | 862 | ; pointer to data in edx |
863 | ; datalength in esi |
||
1159 | hidnplayr | 864 | ; flags in edi |
865 | ; OUT: -1 on error |
||
866 | ; |
||
1257 | hidnplayr | 867 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 868 | align 4 |
1514 | hidnplayr | 869 | SOCKET_send: |
1159 | hidnplayr | 870 | |
2891 | hidnplayr | 871 | DEBUGF 1,"SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi |
1159 | hidnplayr | 872 | |
2402 | hidnplayr | 873 | call SOCKET_num_to_ptr |
874 | jz s_error |
||
1159 | hidnplayr | 875 | |
2402 | hidnplayr | 876 | mov ecx, esi |
877 | mov esi, edx |
||
1763 | hidnplayr | 878 | |
2402 | hidnplayr | 879 | jmp [eax + SOCKET.snd_proc] |
1206 | hidnplayr | 880 | |
881 | |||
1536 | hidnplayr | 882 | align 4 |
883 | SOCKET_send_udp: |
||
1529 | hidnplayr | 884 | |
2402 | hidnplayr | 885 | DEBUGF 1,"SOCKET_send: UDP\n" |
1159 | hidnplayr | 886 | |
2573 | hidnplayr | 887 | mov [esp+32], ecx |
2402 | hidnplayr | 888 | call UDP_output |
2573 | hidnplayr | 889 | cmp eax, -1 |
890 | je s_error |
||
2402 | hidnplayr | 891 | ret |
1159 | hidnplayr | 892 | |
893 | |||
1536 | hidnplayr | 894 | align 4 |
895 | SOCKET_send_tcp: |
||
1254 | hidnplayr | 896 | |
2402 | hidnplayr | 897 | DEBUGF 1,"SOCKET_send: TCP\n" |
1254 | hidnplayr | 898 | |
2402 | hidnplayr | 899 | push eax |
900 | add eax, STREAM_SOCKET.snd |
||
901 | call SOCKET_ring_write |
||
902 | pop eax |
||
1536 | hidnplayr | 903 | |
2621 | hidnplayr | 904 | mov [esp+32], ecx |
905 | |||
2402 | hidnplayr | 906 | call TCP_output |
907 | ret |
||
1159 | hidnplayr | 908 | |
1249 | hidnplayr | 909 | |
1543 | hidnplayr | 910 | align 4 |
911 | SOCKET_send_ip: |
||
1249 | hidnplayr | 912 | |
2891 | hidnplayr | 913 | DEBUGF 1,"SOCKET_send: IPv4\n" |
1543 | hidnplayr | 914 | |
2573 | hidnplayr | 915 | mov [esp+32], ecx |
2402 | hidnplayr | 916 | call IPv4_output_raw |
2573 | hidnplayr | 917 | cmp eax, -1 |
918 | je s_error |
||
2402 | hidnplayr | 919 | ret |
1543 | hidnplayr | 920 | |
2573 | hidnplayr | 921 | |
1541 | hidnplayr | 922 | align 4 |
923 | SOCKET_send_icmp: |
||
1249 | hidnplayr | 924 | |
2402 | hidnplayr | 925 | DEBUGF 1,"SOCKET_send: ICMP\n" |
1541 | hidnplayr | 926 | |
2573 | hidnplayr | 927 | mov [esp+32], ecx |
2402 | hidnplayr | 928 | call ICMP_output_raw |
2573 | hidnplayr | 929 | cmp eax, -1 |
930 | je s_error |
||
2402 | hidnplayr | 931 | ret |
1541 | hidnplayr | 932 | |
933 | |||
2931 | hidnplayr | 934 | align 4 |
935 | SOCKET_send_pppoe: |
||
1541 | hidnplayr | 936 | |
2931 | hidnplayr | 937 | DEBUGF 1,"SOCKET_send: PPPoE\n" |
1541 | hidnplayr | 938 | |
2931 | hidnplayr | 939 | mov [esp+32], ecx |
940 | mov ebx, [eax + SOCKET.device] |
||
941 | |||
942 | call PPPoE_discovery_output |
||
943 | cmp eax, -1 |
||
944 | je s_error |
||
945 | ret |
||
946 | |||
947 | |||
948 | |||
949 | |||
1257 | hidnplayr | 950 | ;----------------------------------------------------------------- |
1256 | clevermous | 951 | ; |
1257 | hidnplayr | 952 | ; SOCKET_get_options |
1256 | clevermous | 953 | ; |
1514 | hidnplayr | 954 | ; IN: ecx = socket number |
955 | ; edx = pointer to the options: |
||
1257 | hidnplayr | 956 | ; dd level, optname, optval, optlen |
1256 | clevermous | 957 | ; OUT: -1 on error |
958 | ; |
||
959 | ; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP. |
||
960 | ; TODO: find best way to notify that send()'ed data were acknowledged |
||
1831 | hidnplayr | 961 | ; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*. |
1256 | clevermous | 962 | ; |
1257 | hidnplayr | 963 | ;----------------------------------------------------------------- |
964 | align 4 |
||
1514 | hidnplayr | 965 | SOCKET_get_opt: |
1257 | hidnplayr | 966 | |
2402 | hidnplayr | 967 | DEBUGF 1,"SOCKET_get_opt\n" |
1514 | hidnplayr | 968 | |
2402 | hidnplayr | 969 | call SOCKET_num_to_ptr |
970 | jz s_error |
||
1514 | hidnplayr | 971 | |
2402 | hidnplayr | 972 | cmp dword [edx], IP_PROTO_TCP |
973 | jne s_error |
||
974 | cmp dword [edx+4], -2 |
||
975 | je @f |
||
976 | cmp dword [edx+4], -3 |
||
977 | jne s_error |
||
1299 | clevermous | 978 | @@: |
1514 | hidnplayr | 979 | ; mov eax, [edx+12] |
980 | ; test eax, eax |
||
981 | ; jz .fail |
||
982 | ; cmp dword [eax], 4 |
||
983 | ; mov dword [eax], 4 |
||
984 | ; jb .fail |
||
985 | ; stdcall net_socket_num_to_addr, ecx |
||
986 | ; test eax, eax |
||
987 | ; jz .fail |
||
988 | ; ; todo: check that eax is really TCP socket |
||
989 | ; mov ecx, [eax + TCP_SOCKET.last_ack_number] |
||
990 | ; cmp dword [edx+4], -2 |
||
991 | ; jz @f |
||
992 | ; mov ecx, [eax + TCP_SOCKET.state] |
||
1299 | clevermous | 993 | @@: |
2402 | hidnplayr | 994 | mov eax, [edx+8] |
995 | test eax, eax |
||
996 | jz @f |
||
997 | mov [eax], ecx |
||
1256 | clevermous | 998 | @@: |
2402 | hidnplayr | 999 | mov dword [esp+32], 0 |
1000 | ret |
||
1159 | hidnplayr | 1001 | |
1002 | |||
1529 | hidnplayr | 1003 | |
2731 | hidnplayr | 1004 | ;----------------------------------------------------------------- |
1005 | ; |
||
1006 | ; SOCKET_set_options |
||
1007 | ; |
||
1008 | ; IN: ecx = socket number |
||
1009 | ; edx = pointer to the options: |
||
2877 | hidnplayr | 1010 | ; dd level, optname, optlen, optval |
2731 | hidnplayr | 1011 | ; OUT: -1 on error |
1012 | ; |
||
1013 | ;----------------------------------------------------------------- |
||
1542 | hidnplayr | 1014 | align 4 |
1015 | SOCKET_set_opt: |
||
1016 | |||
2731 | hidnplayr | 1017 | DEBUGF 1,"SOCKET_set_opt\n" |
1018 | |||
1019 | call SOCKET_num_to_ptr |
||
1020 | jz s_error |
||
1021 | |||
2877 | hidnplayr | 1022 | cmp dword [edx], SOL_SOCKET |
1023 | jne s_error |
||
2731 | hidnplayr | 1024 | |
2877 | hidnplayr | 1025 | cmp dword [edx+4], SO_BINDTODEVICE |
1026 | je .bind |
||
2731 | hidnplayr | 1027 | |
2877 | hidnplayr | 1028 | jmp s_error |
1029 | |||
1030 | .bind: |
||
1031 | cmp dword [edx+8], 0 |
||
1032 | je .unbind |
||
1033 | |||
1034 | movzx edx, byte [edx + 9] |
||
1035 | cmp edx, MAX_NET_DEVICES |
||
1036 | ja s_error |
||
1037 | |||
1038 | mov edx, [NET_DRV_LIST + 4*edx] |
||
1039 | test edx, edx |
||
1040 | jz s_error |
||
1041 | mov [eax + SOCKET.device], edx |
||
1042 | |||
2891 | hidnplayr | 1043 | DEBUGF 1,"SOCKET_set_opt: Bound socket %x to device %x\n",eax, edx |
2877 | hidnplayr | 1044 | |
1045 | mov dword [esp+32], 0 ; success! |
||
2402 | hidnplayr | 1046 | ret |
1542 | hidnplayr | 1047 | |
2877 | hidnplayr | 1048 | .unbind: |
1049 | mov [eax + SOCKET.device], 0 |
||
1542 | hidnplayr | 1050 | |
2877 | hidnplayr | 1051 | mov dword [esp+32], 0 ; success! |
1052 | ret |
||
1542 | hidnplayr | 1053 | |
2877 | hidnplayr | 1054 | |
1055 | |||
1257 | hidnplayr | 1056 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 1057 | ; |
1529 | hidnplayr | 1058 | ; SOCKET_debug |
1059 | ; |
||
1060 | ; Copies socket variables to application buffer |
||
1061 | ; |
||
1062 | ; IN: ecx = socket number |
||
1063 | ; edx = pointer to buffer |
||
1064 | ; |
||
1065 | ; OUT: -1 on error |
||
1066 | ;----------------------------------------------------------------- |
||
1067 | align 4 |
||
1068 | SOCKET_debug: |
||
1069 | |||
2891 | hidnplayr | 1070 | DEBUGF 1,"SOCKET_debug\n" |
1529 | hidnplayr | 1071 | |
2402 | hidnplayr | 1072 | call SOCKET_num_to_ptr |
1073 | jz s_error |
||
1529 | hidnplayr | 1074 | |
2402 | hidnplayr | 1075 | mov esi, eax |
1076 | mov edi, edx |
||
1077 | mov ecx, SOCKETBUFFSIZE/4 |
||
1078 | rep movsd |
||
1529 | hidnplayr | 1079 | |
2402 | hidnplayr | 1080 | mov dword [esp+32], 0 |
1081 | ret |
||
1529 | hidnplayr | 1082 | |
1083 | |||
1084 | ;----------------------------------------------------------------- |
||
1085 | ; |
||
1514 | hidnplayr | 1086 | ; SOCKET_find_port |
1206 | hidnplayr | 1087 | ; |
1514 | hidnplayr | 1088 | ; Fills in the local port number for TCP and UDP sockets |
1089 | ; This procedure always works because the number of sockets is |
||
1090 | ; limited to a smaller number then the number of possible ports |
||
1206 | hidnplayr | 1091 | ; |
1514 | hidnplayr | 1092 | ; IN: eax = socket pointer |
1093 | ; OUT: / |
||
1206 | hidnplayr | 1094 | ; |
1257 | hidnplayr | 1095 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 1096 | align 4 |
1514 | hidnplayr | 1097 | SOCKET_find_port: |
1159 | hidnplayr | 1098 | |
2402 | hidnplayr | 1099 | DEBUGF 1,"SOCKET_find_port\n" |
1159 | hidnplayr | 1100 | |
2402 | hidnplayr | 1101 | push ebx esi ecx |
1514 | hidnplayr | 1102 | |
2402 | hidnplayr | 1103 | cmp [eax + SOCKET.Protocol], IP_PROTO_UDP |
1104 | je .udp |
||
1159 | hidnplayr | 1105 | |
2402 | hidnplayr | 1106 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
1107 | je .tcp |
||
1159 | hidnplayr | 1108 | |
2402 | hidnplayr | 1109 | jmp .error |
1514 | hidnplayr | 1110 | |
1111 | .done: |
||
2402 | hidnplayr | 1112 | mov [eax + UDP_SOCKET.LocalPort], bx |
1514 | hidnplayr | 1113 | .error: |
2402 | hidnplayr | 1114 | pop ecx esi ebx |
1115 | ret |
||
1514 | hidnplayr | 1116 | |
1206 | hidnplayr | 1117 | .udp: |
2402 | hidnplayr | 1118 | mov bx, [last_UDP_port] |
1119 | call .findit |
||
1120 | mov [last_UDP_port], bx |
||
1121 | jmp .done |
||
1206 | hidnplayr | 1122 | |
1123 | .tcp: |
||
2402 | hidnplayr | 1124 | mov bx, [last_TCP_port] |
1125 | call .findit |
||
1126 | mov [last_TCP_port], bx |
||
1127 | jmp .done |
||
1206 | hidnplayr | 1128 | |
1129 | |||
1514 | hidnplayr | 1130 | .restart: |
2402 | hidnplayr | 1131 | mov bx, MIN_EPHEMERAL_PORT |
1514 | hidnplayr | 1132 | .findit: |
2402 | hidnplayr | 1133 | inc bx |
1206 | hidnplayr | 1134 | |
2402 | hidnplayr | 1135 | cmp bx, MAX_EPHEMERAL_PORT |
1136 | jz .restart |
||
1206 | hidnplayr | 1137 | |
2402 | hidnplayr | 1138 | call SOCKET_check_port |
1139 | jz .findit |
||
1206 | hidnplayr | 1140 | |
2402 | hidnplayr | 1141 | ret |
1206 | hidnplayr | 1142 | |
1257 | hidnplayr | 1143 | |
1144 | |||
1145 | ;----------------------------------------------------------------- |
||
1206 | hidnplayr | 1146 | ; |
1542 | hidnplayr | 1147 | ; SOCKET_check_port (to be used with AF_INET only!) |
1206 | hidnplayr | 1148 | ; |
1514 | hidnplayr | 1149 | ; Checks if a local port number is unused |
1150 | ; If the proposed port number is unused, it is filled in in the socket structure |
||
1206 | hidnplayr | 1151 | ; |
1514 | hidnplayr | 1152 | ; IN: eax = socket ptr (to find out if its a TCP/UDP socket) |
1153 | ; bx = proposed socket number |
||
1206 | hidnplayr | 1154 | ; |
1514 | hidnplayr | 1155 | ; OUT: ZF = cleared on error |
1156 | ; |
||
1257 | hidnplayr | 1157 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 1158 | align 4 |
1514 | hidnplayr | 1159 | SOCKET_check_port: |
1160 | |||
2891 | hidnplayr | 1161 | DEBUGF 1,"SOCKET_check_port: " |
1514 | hidnplayr | 1162 | |
2402 | hidnplayr | 1163 | mov ecx, [eax + SOCKET.Protocol] |
2622 | hidnplayr | 1164 | mov edx, [eax + IP_SOCKET.LocalIP] |
2402 | hidnplayr | 1165 | mov esi, net_sockets |
1206 | hidnplayr | 1166 | |
1167 | .next_socket: |
||
2402 | hidnplayr | 1168 | mov esi, [esi + SOCKET.NextPtr] |
1169 | or esi, esi |
||
1170 | jz .port_ok |
||
1206 | hidnplayr | 1171 | |
2402 | hidnplayr | 1172 | cmp [esi + SOCKET.Protocol], ecx |
1173 | jne .next_socket |
||
1206 | hidnplayr | 1174 | |
2622 | hidnplayr | 1175 | cmp [esi + IP_SOCKET.LocalIP], edx |
1176 | jne .next_socket |
||
1177 | |||
2402 | hidnplayr | 1178 | cmp [esi + UDP_SOCKET.LocalPort], bx |
1179 | jne .next_socket |
||
1206 | hidnplayr | 1180 | |
2402 | hidnplayr | 1181 | DEBUGF 1,"local port %u already in use\n", bx |
1182 | ret |
||
1206 | hidnplayr | 1183 | |
1184 | .port_ok: |
||
2891 | hidnplayr | 1185 | DEBUGF 1,"local port %u is free\n", bx |
2402 | hidnplayr | 1186 | mov [eax + UDP_SOCKET.LocalPort], bx |
1187 | or bx, bx ; set the zero-flag |
||
1514 | hidnplayr | 1188 | |
2402 | hidnplayr | 1189 | ret |
1206 | hidnplayr | 1190 | |
1191 | |||
1257 | hidnplayr | 1192 | |
1193 | ;----------------------------------------------------------------- |
||
1206 | hidnplayr | 1194 | ; |
1514 | hidnplayr | 1195 | ; SOCKET_input |
1206 | hidnplayr | 1196 | ; |
1536 | hidnplayr | 1197 | ; Updates a (stateless) socket with received data |
1206 | hidnplayr | 1198 | ; |
1514 | hidnplayr | 1199 | ; Note: the mutex should already be set ! |
1206 | hidnplayr | 1200 | ; |
1249 | hidnplayr | 1201 | ; IN: eax = socket ptr |
1514 | hidnplayr | 1202 | ; ecx = data size |
1203 | ; esi = ptr to data |
||
1204 | ; [esp] = ptr to buf |
||
1205 | ; [esp + 4] = buf size |
||
1249 | hidnplayr | 1206 | ; |
1514 | hidnplayr | 1207 | ; OUT: / |
1206 | hidnplayr | 1208 | ; |
1257 | hidnplayr | 1209 | ;----------------------------------------------------------------- |
1206 | hidnplayr | 1210 | align 4 |
1514 | hidnplayr | 1211 | SOCKET_input: |
1206 | hidnplayr | 1212 | |
2402 | hidnplayr | 1213 | DEBUGF 1,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx |
1206 | hidnplayr | 1214 | |
2402 | hidnplayr | 1215 | mov [esp+4], ecx |
1216 | push esi |
||
1217 | mov esi, esp |
||
1514 | hidnplayr | 1218 | |
2402 | hidnplayr | 1219 | add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full |
1514 | hidnplayr | 1220 | |
2402 | hidnplayr | 1221 | DEBUGF 1,"SOCKET_input: queued packet successfully\n" |
1222 | add esp, sizeof.socket_queue_entry |
||
1206 | hidnplayr | 1223 | |
2402 | hidnplayr | 1224 | pusha |
1225 | lea ecx, [eax + SOCKET.mutex] |
||
1226 | call mutex_unlock |
||
1227 | popa |
||
1228 | |||
1229 | jmp SOCKET_notify_owner |
||
1230 | |||
1514 | hidnplayr | 1231 | .full: |
2402 | hidnplayr | 1232 | DEBUGF 2,"SOCKET_input: socket %x is full!\n", eax |
1206 | hidnplayr | 1233 | |
2402 | hidnplayr | 1234 | pusha |
1235 | lea ecx, [eax + SOCKET.mutex] |
||
1236 | call mutex_unlock |
||
1237 | popa |
||
1514 | hidnplayr | 1238 | |
2402 | hidnplayr | 1239 | call kernel_free |
1240 | add esp, 8 |
||
1533 | hidnplayr | 1241 | |
2402 | hidnplayr | 1242 | ret |
1243 | |||
1244 | |||
1533 | hidnplayr | 1245 | ;-------------------------- |
1246 | ; |
||
1247 | ; eax = ptr to ring struct (just a buffer of the right size) |
||
1248 | ; |
||
1249 | align 4 |
||
1250 | SOCKET_ring_create: |
||
1251 | |||
2402 | hidnplayr | 1252 | push esi |
1253 | mov esi, eax |
||
1543 | hidnplayr | 1254 | |
2402 | hidnplayr | 1255 | push edx |
1256 | stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW |
||
1257 | pop edx |
||
1533 | hidnplayr | 1258 | |
2402 | hidnplayr | 1259 | DEBUGF 1,"SOCKET_ring_created: %x\n", eax |
1260 | mov [esi + RING_BUFFER.start_ptr], eax |
||
1261 | mov [esi + RING_BUFFER.write_ptr], eax |
||
1262 | mov [esi + RING_BUFFER.read_ptr], eax |
||
1263 | mov [esi + RING_BUFFER.size], 0 |
||
2888 | hidnplayr | 1264 | add eax, SOCKET_MAXDATA |
2402 | hidnplayr | 1265 | mov [esi + RING_BUFFER.end_ptr], eax |
1266 | mov eax, esi |
||
1267 | pop esi |
||
1533 | hidnplayr | 1268 | |
2402 | hidnplayr | 1269 | ret |
1533 | hidnplayr | 1270 | |
1514 | hidnplayr | 1271 | ;----------------------------------------------------------------- |
1272 | ; |
||
1533 | hidnplayr | 1273 | ; SOCKET_ring_write |
1529 | hidnplayr | 1274 | ; |
1533 | hidnplayr | 1275 | ; Adds data to a stream socket, and updates write pointer and size |
1529 | hidnplayr | 1276 | ; |
1277 | ; IN: eax = ptr to ring struct |
||
1278 | ; ecx = data size |
||
1279 | ; esi = ptr to data |
||
1280 | ; |
||
1533 | hidnplayr | 1281 | ; OUT: ecx = number of bytes stored |
1529 | hidnplayr | 1282 | ; |
1283 | ;----------------------------------------------------------------- |
||
1284 | align 4 |
||
1533 | hidnplayr | 1285 | SOCKET_ring_write: |
1529 | hidnplayr | 1286 | |
2402 | hidnplayr | 1287 | DEBUGF 1,"SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx |
1529 | hidnplayr | 1288 | |
2402 | hidnplayr | 1289 | add [eax + RING_BUFFER.size], ecx |
2573 | hidnplayr | 1290 | jc .way_too_large |
2402 | hidnplayr | 1291 | cmp [eax + RING_BUFFER.size], SOCKET_MAXDATA |
1292 | ja .too_large |
||
1529 | hidnplayr | 1293 | |
1294 | .copy: |
||
2402 | hidnplayr | 1295 | mov edi, [eax + RING_BUFFER.write_ptr] |
1296 | DEBUGF 2,"SOCKET_ring_write: %u bytes from %x to %x\n", ecx, esi, edi |
||
1529 | hidnplayr | 1297 | |
2402 | hidnplayr | 1298 | push ecx |
1299 | shr ecx, 1 |
||
1300 | jnc .nb |
||
1301 | movsb |
||
1536 | hidnplayr | 1302 | .nb: |
2402 | hidnplayr | 1303 | shr ecx, 1 |
1304 | jnc .nw |
||
1305 | movsw |
||
1536 | hidnplayr | 1306 | .nw: |
2402 | hidnplayr | 1307 | test ecx, ecx |
1308 | jz .nd |
||
1309 | rep movsd |
||
1536 | hidnplayr | 1310 | .nd: |
2402 | hidnplayr | 1311 | pop ecx |
1529 | hidnplayr | 1312 | |
2402 | hidnplayr | 1313 | cmp edi, [eax + RING_BUFFER.end_ptr] |
1314 | jae .wrap |
||
1315 | mov [eax + RING_BUFFER.write_ptr], edi |
||
1533 | hidnplayr | 1316 | |
2402 | hidnplayr | 1317 | ret |
1529 | hidnplayr | 1318 | |
1533 | hidnplayr | 1319 | .wrap: |
2402 | hidnplayr | 1320 | sub edi, SOCKET_MAXDATA |
1321 | mov [eax + RING_BUFFER.write_ptr], edi |
||
1533 | hidnplayr | 1322 | |
2402 | hidnplayr | 1323 | ret |
1533 | hidnplayr | 1324 | |
2404 | hidnplayr | 1325 | .too_large: ; update size, we will fill buffer completely |
1326 | sub [eax + RING_BUFFER.size], SOCKET_MAXDATA |
||
2402 | hidnplayr | 1327 | sub ecx, [eax + RING_BUFFER.size] |
2404 | hidnplayr | 1328 | mov [eax + RING_BUFFER.size], SOCKET_MAXDATA |
2573 | hidnplayr | 1329 | ja .copy |
1529 | hidnplayr | 1330 | |
2573 | hidnplayr | 1331 | .full: |
2402 | hidnplayr | 1332 | DEBUGF 2,"SOCKET_ring_write: ring buffer is full!\n" |
1333 | xor ecx, ecx |
||
1334 | ret |
||
1529 | hidnplayr | 1335 | |
2573 | hidnplayr | 1336 | .way_too_large: |
1337 | sub [eax + RING_BUFFER.size], ecx |
||
1338 | mov ecx, SOCKET_MAXDATA |
||
1339 | sub ecx, [eax + RING_BUFFER.size] |
||
1340 | ja .copy |
||
1341 | jmp .full |
||
1529 | hidnplayr | 1342 | |
2573 | hidnplayr | 1343 | |
1344 | |||
1529 | hidnplayr | 1345 | ;----------------------------------------------------------------- |
1346 | ; |
||
1347 | ; SOCKET_ring_read |
||
1348 | ; |
||
2893 | hidnplayr | 1349 | ; IN: eax = ring struct ptr |
1350 | ; ecx = bytes to read |
||
1351 | ; edx = offset |
||
2994 | hidnplayr | 1352 | ; edi = ptr to buffer start |
1529 | hidnplayr | 1353 | ; |
2994 | hidnplayr | 1354 | ; OUT: eax = unchanged |
1355 | ; ecx = number of bytes read (0 on error) |
||
1356 | ; edx = destroyed |
||
1357 | ; esi = destroyed |
||
1358 | ; edi = ptr to buffer end |
||
1529 | hidnplayr | 1359 | ; |
1360 | ;----------------------------------------------------------------- |
||
1361 | align 4 |
||
1362 | SOCKET_ring_read: |
||
1363 | |||
2893 | hidnplayr | 1364 | DEBUGF 1,"SOCKET_ring_read: ringbuff=%x ptr=%x size=%u offset=%x\n", eax, edi, ecx, edx |
1529 | hidnplayr | 1365 | |
2893 | hidnplayr | 1366 | mov esi, [eax + RING_BUFFER.read_ptr] |
1367 | add esi, edx ; esi = start_ptr + offset |
||
1368 | |||
1369 | neg edx |
||
1370 | add edx, [eax + RING_BUFFER.size] ; edx = snd.size - offset |
||
1371 | jle .no_data_at_all |
||
1372 | |||
1373 | cmp ecx, edx |
||
2402 | hidnplayr | 1374 | ja .less_data |
1529 | hidnplayr | 1375 | |
1376 | .copy: |
||
2402 | hidnplayr | 1377 | DEBUGF 2,"SOCKET_ring_read: %u bytes from %x to %x\n", ecx, esi, edi |
1378 | push ecx |
||
1379 | shr ecx, 1 |
||
1380 | jnc .nb |
||
1381 | movsb |
||
1536 | hidnplayr | 1382 | .nb: |
2402 | hidnplayr | 1383 | shr ecx, 1 |
1384 | jnc .nw |
||
1385 | movsw |
||
1536 | hidnplayr | 1386 | .nw: |
2402 | hidnplayr | 1387 | test ecx, ecx |
1388 | jz .nd |
||
1389 | rep movsd |
||
1536 | hidnplayr | 1390 | .nd: |
2402 | hidnplayr | 1391 | pop ecx |
2893 | hidnplayr | 1392 | ret |
1529 | hidnplayr | 1393 | |
1830 | hidnplayr | 1394 | .no_data_at_all: |
2894 | hidnplayr | 1395 | DEBUGF 1,"SOCKET_ring_read: no data at all!\n" |
2993 | hidnplayr | 1396 | xor ecx, ecx |
2402 | hidnplayr | 1397 | ret |
1529 | hidnplayr | 1398 | |
1533 | hidnplayr | 1399 | .less_data: |
2893 | hidnplayr | 1400 | mov ecx, edx |
2402 | hidnplayr | 1401 | jmp .copy |
1529 | hidnplayr | 1402 | |
1403 | |||
1404 | ;----------------------------------------------------------------- |
||
1405 | ; |
||
1406 | ; SOCKET_ring_free |
||
1407 | ; |
||
1408 | ; Free's some bytes from the ringbuffer |
||
1409 | ; |
||
1410 | ; IN: eax = ptr to ring struct |
||
1411 | ; ecx = data size |
||
1412 | ; |
||
1413 | ; OUT: ecx = number of bytes free-ed |
||
1414 | ; |
||
1415 | ;----------------------------------------------------------------- |
||
1416 | align 4 |
||
1417 | SOCKET_ring_free: |
||
1418 | |||
2402 | hidnplayr | 1419 | DEBUGF 1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax |
1529 | hidnplayr | 1420 | |
2402 | hidnplayr | 1421 | sub [eax + RING_BUFFER.size], ecx |
2888 | hidnplayr | 1422 | jb .error |
2402 | hidnplayr | 1423 | add [eax + RING_BUFFER.read_ptr], ecx |
1529 | hidnplayr | 1424 | |
2402 | hidnplayr | 1425 | mov edx, [eax + RING_BUFFER.end_ptr] |
1426 | cmp [eax + RING_BUFFER.read_ptr], edx |
||
1427 | jb @f |
||
1428 | sub [eax + RING_BUFFER.read_ptr], SOCKET_MAXDATA |
||
1529 | hidnplayr | 1429 | @@: |
2402 | hidnplayr | 1430 | ret |
1529 | hidnplayr | 1431 | |
2888 | hidnplayr | 1432 | .error: ; we could free all available bytes, but that would be stupid, i guess.. |
1433 | DEBUGF 1,"SOCKET_ring_free: buffer=%x error!\n", eax |
||
2402 | hidnplayr | 1434 | add [eax + RING_BUFFER.size], ecx |
1435 | xor ecx, ecx |
||
1436 | ret |
||
1529 | hidnplayr | 1437 | |
1438 | |||
1439 | ;----------------------------------------------------------------- |
||
1440 | ; |
||
1514 | hidnplayr | 1441 | ; SOCKET_notify_owner |
1442 | ; |
||
1443 | ; notify's the owner of a socket that something happened |
||
1444 | ; |
||
1445 | ; IN: eax = socket ptr |
||
1446 | ; OUT: / |
||
1447 | ; |
||
1448 | ;----------------------------------------------------------------- |
||
1449 | align 4 |
||
1450 | SOCKET_notify_owner: |
||
1451 | |||
2402 | hidnplayr | 1452 | DEBUGF 1,"SOCKET_notify_owner: %x\n", eax |
1514 | hidnplayr | 1453 | |
2402 | hidnplayr | 1454 | call SOCKET_check |
1455 | jz .error |
||
1514 | hidnplayr | 1456 | |
2402 | hidnplayr | 1457 | push eax ecx esi |
1514 | hidnplayr | 1458 | |
1459 | ; socket exists, now try to flag an event to the application |
||
1460 | |||
2402 | hidnplayr | 1461 | mov eax, [eax + SOCKET.PID] |
2629 | hidnplayr | 1462 | test eax, eax |
1463 | jz .error2 |
||
2402 | hidnplayr | 1464 | mov ecx, 1 |
1465 | mov esi, TASK_DATA + TASKDATA.pid |
||
1206 | hidnplayr | 1466 | |
1467 | .next_pid: |
||
2402 | hidnplayr | 1468 | cmp [esi], eax |
1469 | je .found_pid |
||
1470 | inc ecx |
||
1471 | add esi, 0x20 |
||
1472 | cmp ecx, [TASK_COUNT] |
||
1473 | jbe .next_pid |
||
1206 | hidnplayr | 1474 | |
1514 | hidnplayr | 1475 | ; PID not found, TODO: close socket! |
1476 | |||
2402 | hidnplayr | 1477 | jmp .error2 |
1514 | hidnplayr | 1478 | |
1206 | hidnplayr | 1479 | .found_pid: |
2402 | hidnplayr | 1480 | shl ecx, 8 |
1481 | or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK |
||
1482 | mov [check_idle_semaphore], 200 |
||
1206 | hidnplayr | 1483 | |
2402 | hidnplayr | 1484 | DEBUGF 1,"SOCKET_notify_owner: succes!\n" |
1514 | hidnplayr | 1485 | |
1486 | .error2: |
||
2402 | hidnplayr | 1487 | pop esi ecx eax |
1536 | hidnplayr | 1488 | |
1514 | hidnplayr | 1489 | .error: |
1490 | |||
2402 | hidnplayr | 1491 | ret |
1206 | hidnplayr | 1492 | |
1493 | |||
1514 | hidnplayr | 1494 | ;-------------------------------------------------------------------- |
1495 | ; |
||
1496 | ; SOCKET_alloc |
||
1497 | ; |
||
1159 | hidnplayr | 1498 | ; Allocate memory for socket data and put new socket into the list |
1499 | ; Newly created socket is initialized with calling PID and number and |
||
1500 | ; put into beginning of list (which is a fastest way). |
||
1501 | ; |
||
1514 | hidnplayr | 1502 | ; IN: / |
1503 | ; OUT: eax = 0 on error, socket ptr otherwise |
||
1504 | ; edi = socket number |
||
1505 | ; ZF = cleared on error |
||
1159 | hidnplayr | 1506 | ; |
1514 | hidnplayr | 1507 | ;-------------------------------------------------------------------- |
1508 | align 4 |
||
1509 | SOCKET_alloc: |
||
1510 | |||
2402 | hidnplayr | 1511 | push ebx |
1514 | hidnplayr | 1512 | |
2402 | hidnplayr | 1513 | stdcall kernel_alloc, SOCKETBUFFSIZE |
1514 | DEBUGF 1, "SOCKET_alloc: ptr=%x\n", eax |
||
1515 | or eax, eax |
||
1516 | jz .exit |
||
1159 | hidnplayr | 1517 | |
1514 | hidnplayr | 1518 | ; zero-initialize allocated memory |
2402 | hidnplayr | 1519 | push eax |
1520 | mov edi, eax |
||
1521 | mov ecx, SOCKETBUFFSIZE / 4 |
||
1522 | xor eax, eax |
||
1523 | rep stosd |
||
1524 | pop eax |
||
1159 | hidnplayr | 1525 | |
1536 | hidnplayr | 1526 | ; set send-and receive procedures to return -1 |
2402 | hidnplayr | 1527 | mov [eax + SOCKET.snd_proc], s_error |
1528 | mov [eax + SOCKET.rcv_proc], s_error |
||
1536 | hidnplayr | 1529 | |
1514 | hidnplayr | 1530 | ; find first free socket number and use it |
2402 | hidnplayr | 1531 | mov edi, [last_socket_num] |
1159 | hidnplayr | 1532 | .next_socket_number: |
2402 | hidnplayr | 1533 | inc edi |
1534 | jz .next_socket_number ; avoid socket nr 0 |
||
1535 | cmp edi, -1 |
||
1536 | je .next_socket_number ; avoid socket nr -1 |
||
1537 | mov ebx, net_sockets |
||
1159 | hidnplayr | 1538 | .next_socket: |
2402 | hidnplayr | 1539 | mov ebx, [ebx + SOCKET.NextPtr] |
1540 | test ebx, ebx |
||
1541 | jz .last_socket |
||
1536 | hidnplayr | 1542 | |
2402 | hidnplayr | 1543 | cmp [ebx + SOCKET.Number], edi |
1544 | jne .next_socket |
||
1545 | jmp .next_socket_number |
||
1159 | hidnplayr | 1546 | |
1514 | hidnplayr | 1547 | .last_socket: |
2402 | hidnplayr | 1548 | mov [last_socket_num], edi |
1549 | mov [eax + SOCKET.Number], edi |
||
1550 | DEBUGF 1, "SOCKET_alloc: number=%u\n", edi |
||
1159 | hidnplayr | 1551 | |
1514 | hidnplayr | 1552 | ; Fill in PID |
2402 | hidnplayr | 1553 | mov ebx, [TASK_BASE] |
1554 | mov ebx, [ebx + TASKDATA.pid] |
||
1555 | mov [eax + SOCKET.PID], ebx |
||
1514 | hidnplayr | 1556 | |
2403 | hidnplayr | 1557 | ; init mutex |
1558 | pusha |
||
1559 | lea ecx, [eax + SOCKET.mutex] |
||
1560 | call mutex_init |
||
1561 | popa |
||
1562 | |||
1529 | hidnplayr | 1563 | ; add socket to the list by re-arranging some pointers |
2402 | hidnplayr | 1564 | mov ebx, [net_sockets + SOCKET.NextPtr] |
1514 | hidnplayr | 1565 | |
2402 | hidnplayr | 1566 | mov [eax + SOCKET.PrevPtr], net_sockets |
1567 | mov [eax + SOCKET.NextPtr], ebx |
||
1514 | hidnplayr | 1568 | |
2402 | hidnplayr | 1569 | test ebx, ebx |
1570 | jz @f |
||
1571 | |||
1572 | pusha |
||
1573 | lea ecx, [ebx + SOCKET.mutex] |
||
1574 | call mutex_lock |
||
1575 | popa |
||
1576 | |||
1577 | mov [ebx + SOCKET.PrevPtr], eax |
||
1578 | |||
1579 | pusha |
||
1580 | lea ecx, [ebx + SOCKET.mutex] |
||
1581 | call mutex_unlock |
||
1582 | popa |
||
1514 | hidnplayr | 1583 | @@: |
1584 | |||
2402 | hidnplayr | 1585 | mov [net_sockets + SOCKET.NextPtr], eax |
1586 | or eax, eax ; used to clear zero flag |
||
1159 | hidnplayr | 1587 | .exit: |
2402 | hidnplayr | 1588 | pop ebx |
1514 | hidnplayr | 1589 | |
2402 | hidnplayr | 1590 | ret |
1159 | hidnplayr | 1591 | |
1514 | hidnplayr | 1592 | |
1593 | ;---------------------------------------------------- |
||
1159 | hidnplayr | 1594 | ; |
1514 | hidnplayr | 1595 | ; SOCKET_free |
1159 | hidnplayr | 1596 | ; |
1514 | hidnplayr | 1597 | ; Free socket data memory and remove socket from the list |
1598 | ; |
||
1599 | ; IN: eax = socket ptr |
||
1600 | ; OUT: / |
||
1601 | ; |
||
1602 | ;---------------------------------------------------- |
||
1603 | align 4 |
||
1604 | SOCKET_free: |
||
1159 | hidnplayr | 1605 | |
2402 | hidnplayr | 1606 | DEBUGF 1, "SOCKET_free: %x\n", eax |
1514 | hidnplayr | 1607 | |
2402 | hidnplayr | 1608 | call SOCKET_check |
1609 | jz .error |
||
1159 | hidnplayr | 1610 | |
2402 | hidnplayr | 1611 | push ebx |
1514 | hidnplayr | 1612 | |
2402 | hidnplayr | 1613 | pusha |
1614 | lea ecx, [eax + SOCKET.mutex] |
||
1615 | call mutex_lock |
||
1616 | popa |
||
1514 | hidnplayr | 1617 | |
2402 | hidnplayr | 1618 | cmp [eax + SOCKET.Domain], AF_INET4 |
1619 | jnz .no_tcp |
||
1529 | hidnplayr | 1620 | |
2402 | hidnplayr | 1621 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
1622 | jnz .no_tcp |
||
1623 | |||
1624 | mov ebx, eax |
||
1625 | stdcall kernel_free, [ebx + STREAM_SOCKET.rcv.start_ptr] |
||
1626 | stdcall kernel_free, [ebx + STREAM_SOCKET.snd.start_ptr] |
||
1627 | mov eax, ebx |
||
1536 | hidnplayr | 1628 | .no_tcp: |
1529 | hidnplayr | 1629 | |
2402 | hidnplayr | 1630 | push eax ; this will be passed to kernel_free |
1631 | mov ebx, [eax + SOCKET.NextPtr] |
||
1632 | mov eax, [eax + SOCKET.PrevPtr] |
||
1514 | hidnplayr | 1633 | |
2402 | hidnplayr | 1634 | DEBUGF 1, "SOCKET_free: linking socket %x to socket %x\n", eax, ebx |
1514 | hidnplayr | 1635 | |
2402 | hidnplayr | 1636 | test eax, eax |
1637 | jz @f |
||
1638 | mov [eax + SOCKET.NextPtr], ebx |
||
1514 | hidnplayr | 1639 | @@: |
1159 | hidnplayr | 1640 | |
2402 | hidnplayr | 1641 | test ebx, ebx |
1642 | jz @f |
||
1643 | mov [ebx + SOCKET.PrevPtr], eax |
||
1514 | hidnplayr | 1644 | @@: |
1249 | hidnplayr | 1645 | |
2402 | hidnplayr | 1646 | call kernel_free |
1647 | pop ebx |
||
1159 | hidnplayr | 1648 | |
2402 | hidnplayr | 1649 | DEBUGF 1, "SOCKET_free: success!\n" |
1514 | hidnplayr | 1650 | |
1159 | hidnplayr | 1651 | .error: |
2402 | hidnplayr | 1652 | ret |
1159 | hidnplayr | 1653 | |
1543 | hidnplayr | 1654 | ;------------------------------------ |
1655 | ; |
||
1656 | ; SOCKET_fork |
||
1657 | ; |
||
1658 | ; Create a child socket |
||
1659 | ; |
||
1533 | hidnplayr | 1660 | ; IN: socket nr in ebx |
1543 | hidnplayr | 1661 | ; OUT: child socket nr in eax |
1662 | ; |
||
1663 | ;----------------------------------- |
||
1529 | hidnplayr | 1664 | align 4 |
1665 | SOCKET_fork: |
||
1666 | |||
2402 | hidnplayr | 1667 | DEBUGF 1,"SOCKET_fork: %x\n", ebx |
1529 | hidnplayr | 1668 | |
1543 | hidnplayr | 1669 | ; Exit if backlog queue is full |
2402 | hidnplayr | 1670 | mov eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size] |
1671 | cmp ax, [ebx + SOCKET.backlog] |
||
1672 | jae .fail |
||
1543 | hidnplayr | 1673 | |
1529 | hidnplayr | 1674 | ; Allocate new socket |
2402 | hidnplayr | 1675 | push ebx |
1676 | call SOCKET_alloc |
||
1677 | pop ebx |
||
1678 | jz .fail |
||
1529 | hidnplayr | 1679 | |
2402 | hidnplayr | 1680 | push eax |
1681 | mov esi, esp |
||
1682 | add_to_queue (ebx + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .fail2 |
||
1683 | pop eax |
||
1543 | hidnplayr | 1684 | |
1685 | ; Copy structure from current socket to new |
||
1686 | ; We start at PID to preserve the socket num, and the 2 pointers at beginning of socket |
||
2402 | hidnplayr | 1687 | lea esi, [ebx + SOCKET.PID] |
1688 | lea edi, [eax + SOCKET.PID] |
||
1689 | mov ecx, (SOCKET_QUEUE_LOCATION - SOCKET.PID + 3)/4 |
||
1690 | rep movsd |
||
1529 | hidnplayr | 1691 | |
2402 | hidnplayr | 1692 | and [eax + SOCKET.options], not SO_ACCEPTCON |
1529 | hidnplayr | 1693 | |
2402 | hidnplayr | 1694 | ret |
1529 | hidnplayr | 1695 | |
1543 | hidnplayr | 1696 | .fail2: |
2402 | hidnplayr | 1697 | add esp, 4+4+4 |
1543 | hidnplayr | 1698 | .fail: |
2402 | hidnplayr | 1699 | DEBUGF 1,"SOCKET_fork: failed\n" |
1700 | xor eax, eax |
||
1701 | ret |
||
1529 | hidnplayr | 1702 | |
1543 | hidnplayr | 1703 | |
1514 | hidnplayr | 1704 | ;--------------------------------------------------- |
1705 | ; |
||
1706 | ; SOCKET_num_to_ptr |
||
1707 | ; |
||
1159 | hidnplayr | 1708 | ; Get socket structure address by its number |
1709 | ; |
||
1514 | hidnplayr | 1710 | ; IN: ecx = socket number |
1533 | hidnplayr | 1711 | ; OUT: eax = 0 on error, socket ptr otherwise |
1514 | hidnplayr | 1712 | ; ZF = set on error |
1159 | hidnplayr | 1713 | ; |
1514 | hidnplayr | 1714 | ;--------------------------------------------------- |
1715 | align 4 |
||
1716 | SOCKET_num_to_ptr: |
||
1159 | hidnplayr | 1717 | |
2891 | hidnplayr | 1718 | DEBUGF 1,"SOCKET_num_to_ptr: num=%u ", ecx |
1514 | hidnplayr | 1719 | |
2402 | hidnplayr | 1720 | mov eax, net_sockets |
1514 | hidnplayr | 1721 | |
1159 | hidnplayr | 1722 | .next_socket: |
2402 | hidnplayr | 1723 | mov eax, [eax + SOCKET.NextPtr] |
1724 | or eax, eax |
||
1725 | jz .error |
||
1726 | cmp [eax + SOCKET.Number], ecx |
||
1727 | jne .next_socket |
||
1159 | hidnplayr | 1728 | |
2402 | hidnplayr | 1729 | test eax, eax |
1159 | hidnplayr | 1730 | |
2891 | hidnplayr | 1731 | DEBUGF 1,"ptr=%x\n", eax |
1732 | ret |
||
1733 | |||
1159 | hidnplayr | 1734 | .error: |
2891 | hidnplayr | 1735 | DEBUGF 1,"not found\n", eax |
2402 | hidnplayr | 1736 | ret |
1159 | hidnplayr | 1737 | |
1514 | hidnplayr | 1738 | |
1739 | ;--------------------------------------------------- |
||
1159 | hidnplayr | 1740 | ; |
1514 | hidnplayr | 1741 | ; SOCKET_ptr_to_num |
1159 | hidnplayr | 1742 | ; |
1514 | hidnplayr | 1743 | ; Get socket number by its address |
1744 | ; |
||
1745 | ; IN: eax = socket ptr |
||
1746 | ; OUT: eax = 0 on error, socket num otherwise |
||
1747 | ; ZF = set on error |
||
1748 | ; |
||
1749 | ;--------------------------------------------------- |
||
1750 | align 4 |
||
1751 | SOCKET_ptr_to_num: |
||
1752 | |||
2891 | hidnplayr | 1753 | DEBUGF 1,"SOCKET_ptr_to_num: ptr=%x ", eax |
1514 | hidnplayr | 1754 | |
2402 | hidnplayr | 1755 | call SOCKET_check |
1756 | jz .error |
||
1159 | hidnplayr | 1757 | |
2402 | hidnplayr | 1758 | mov eax, [eax + SOCKET.Number] |
1514 | hidnplayr | 1759 | |
2891 | hidnplayr | 1760 | DEBUGF 1,"num=%u\n", eax |
1761 | ret |
||
1514 | hidnplayr | 1762 | |
1763 | .error: |
||
2891 | hidnplayr | 1764 | DEBUGF 1,"not found\n", eax |
2402 | hidnplayr | 1765 | ret |
1514 | hidnplayr | 1766 | |
1767 | |||
1768 | ;--------------------------------------------------- |
||
1769 | ; |
||
1770 | ; SOCKET_check |
||
1771 | ; |
||
1772 | ; checks if the given value is really a socket ptr |
||
1773 | ; |
||
1774 | ; IN: eax = socket ptr |
||
1775 | ; OUT: eax = 0 on error, unchanged otherwise |
||
1776 | ; ZF = set on error |
||
1777 | ; |
||
1778 | ;--------------------------------------------------- |
||
1779 | align 4 |
||
1780 | SOCKET_check: |
||
1781 | |||
2402 | hidnplayr | 1782 | DEBUGF 1,"SOCKET_check: %x\n", eax |
1514 | hidnplayr | 1783 | |
2402 | hidnplayr | 1784 | push ebx |
1785 | mov ebx, net_sockets |
||
1514 | hidnplayr | 1786 | |
1159 | hidnplayr | 1787 | .next_socket: |
2402 | hidnplayr | 1788 | mov ebx, [ebx + SOCKET.NextPtr] |
1789 | or ebx, ebx |
||
1790 | jz .done |
||
1791 | cmp ebx, eax |
||
1792 | jnz .next_socket |
||
1159 | hidnplayr | 1793 | |
1514 | hidnplayr | 1794 | .done: |
2402 | hidnplayr | 1795 | mov eax, ebx |
1796 | test eax, eax |
||
1797 | pop ebx |
||
1514 | hidnplayr | 1798 | |
2402 | hidnplayr | 1799 | ret |
1159 | hidnplayr | 1800 | |
1514 | hidnplayr | 1801 | |
1802 | |||
1803 | ;--------------------------------------------------- |
||
1804 | ; |
||
1805 | ; SOCKET_check_owner |
||
1806 | ; |
||
1807 | ; checks if the caller application owns the socket |
||
1808 | ; |
||
1809 | ; IN: eax = socket ptr |
||
1810 | ; OUT: ZF = true/false |
||
1811 | ; |
||
1812 | ;--------------------------------------------------- |
||
1813 | align 4 |
||
1814 | SOCKET_check_owner: |
||
1815 | |||
2402 | hidnplayr | 1816 | DEBUGF 1,"SOCKET_check_owner: %x\n", eax |
1514 | hidnplayr | 1817 | |
2402 | hidnplayr | 1818 | push ebx |
1819 | mov ebx, [TASK_BASE] |
||
1820 | mov ebx, [ecx + TASKDATA.pid] |
||
1821 | cmp [eax + SOCKET.PID], ebx |
||
1822 | pop ebx |
||
1514 | hidnplayr | 1823 | |
2402 | hidnplayr | 1824 | ret |
1514 | hidnplayr | 1825 | |
1826 | |||
1827 | |||
1828 | |||
1885 | hidnplayr | 1829 | ;------------------------------------------------------ |
1514 | hidnplayr | 1830 | ; |
1831 | ; SOCKET_process_end |
||
1832 | ; |
||
1833 | ; Kernel calls this function when a certain process ends |
||
1834 | ; This function will check if the process had any open sockets |
||
1835 | ; And update them accordingly |
||
1836 | ; |
||
2867 | hidnplayr | 1837 | ; IN: edx = pid |
1514 | hidnplayr | 1838 | ; OUT: / |
1839 | ; |
||
1840 | ;------------------------------------------------------ |
||
1841 | align 4 |
||
1842 | SOCKET_process_end: |
||
1843 | |||
2867 | hidnplayr | 1844 | DEBUGF 1,"SOCKET_process_end: %x\n", edx |
1514 | hidnplayr | 1845 | |
2402 | hidnplayr | 1846 | push ebx |
1847 | mov ebx, net_sockets |
||
1514 | hidnplayr | 1848 | |
1849 | .next_socket: |
||
2402 | hidnplayr | 1850 | mov ebx, [ebx + SOCKET.NextPtr] |
1514 | hidnplayr | 1851 | .test_socket: |
2402 | hidnplayr | 1852 | test ebx, ebx |
1853 | jz .done |
||
1514 | hidnplayr | 1854 | |
2867 | hidnplayr | 1855 | cmp [ebx + SOCKET.PID], edx |
2402 | hidnplayr | 1856 | jne .next_socket |
1514 | hidnplayr | 1857 | |
2891 | hidnplayr | 1858 | DEBUGF 1,"SOCKET_process_end: killing socket %x\n", ebx |
1514 | hidnplayr | 1859 | |
2402 | hidnplayr | 1860 | mov [ebx + SOCKET.PID], 0 |
1514 | hidnplayr | 1861 | |
2402 | hidnplayr | 1862 | cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP |
1863 | je .tcp |
||
1514 | hidnplayr | 1864 | |
2629 | hidnplayr | 1865 | ; The socket is stateless, just kill it right away! |
1514 | hidnplayr | 1866 | |
2402 | hidnplayr | 1867 | mov eax, ebx |
1868 | mov ebx, [ebx + SOCKET.NextPtr] |
||
1869 | call SOCKET_free |
||
1870 | jmp .test_socket |
||
1514 | hidnplayr | 1871 | |
1872 | .tcp: |
||
2629 | hidnplayr | 1873 | push [ebx + SOCKET.NextPtr] |
1874 | mov eax, ebx |
||
2869 | hidnplayr | 1875 | call TCP_disconnect |
2629 | hidnplayr | 1876 | pop ebx |
1877 | jmp .test_socket |
||
1885 | hidnplayr | 1878 | |
1514 | hidnplayr | 1879 | .done: |
2402 | hidnplayr | 1880 | pop ebx |
1514 | hidnplayr | 1881 | |
2402 | hidnplayr | 1882 | ret |
1773 | hidnplayr | 1883 | |
1884 | |||
1885 | |||
1886 | |||
1885 | hidnplayr | 1887 | ;----------------------------------------------------------------- |
1888 | ; |
||
1889 | ; SOCKET_is_connecting |
||
1890 | ; |
||
1891 | ; IN: eax = socket ptr |
||
1892 | ; OUT: / |
||
1893 | ; |
||
1894 | ;----------------------------------------------------------------- |
||
1773 | hidnplayr | 1895 | |
1885 | hidnplayr | 1896 | align 4 |
1897 | SOCKET_is_connecting: |
||
1773 | hidnplayr | 1898 | |
2891 | hidnplayr | 1899 | DEBUGF 1,"SOCKET_is_connecting: %x\n", eax |
1773 | hidnplayr | 1900 | |
2402 | hidnplayr | 1901 | and [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING) |
1902 | or [eax + SOCKET.options], SS_ISCONNECTING |
||
1773 | hidnplayr | 1903 | |
2402 | hidnplayr | 1904 | jmp SOCKET_notify_owner |
1885 | hidnplayr | 1905 | |
1906 | |||
1907 | |||
1773 | hidnplayr | 1908 | ;----------------------------------------------------------------- |
1909 | ; |
||
1885 | hidnplayr | 1910 | ; SOCKET_is_connected |
1911 | ; |
||
1912 | ; IN: eax = socket ptr |
||
1913 | ; OUT: / |
||
1914 | ; |
||
1915 | ;----------------------------------------------------------------- |
||
1916 | |||
1917 | align 4 |
||
1918 | SOCKET_is_connected: |
||
1919 | |||
2891 | hidnplayr | 1920 | DEBUGF 1,"SOCKET_is_connected: %x\n", eax |
1885 | hidnplayr | 1921 | |
2402 | hidnplayr | 1922 | and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) |
1923 | or [eax + SOCKET.options], SS_ISCONNECTED |
||
1885 | hidnplayr | 1924 | |
2402 | hidnplayr | 1925 | jmp SOCKET_notify_owner |
1885 | hidnplayr | 1926 | |
1927 | |||
1928 | |||
1929 | |||
1930 | ;----------------------------------------------------------------- |
||
1931 | ; |
||
1773 | hidnplayr | 1932 | ; SOCKET_is_disconnecting |
1933 | ; |
||
1934 | ; IN: eax = socket ptr |
||
1935 | ; OUT: / |
||
1936 | ; |
||
1937 | ;----------------------------------------------------------------- |
||
1938 | |||
1939 | align 4 |
||
1940 | SOCKET_is_disconnecting: |
||
1941 | |||
2891 | hidnplayr | 1942 | DEBUGF 1,"SOCKET_is_disconnecting: %x\n", eax |
1943 | |||
2402 | hidnplayr | 1944 | and [eax + SOCKET.options], not (SS_ISCONNECTING) |
1945 | or [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE |
||
1773 | hidnplayr | 1946 | |
2402 | hidnplayr | 1947 | jmp SOCKET_notify_owner |
1773 | hidnplayr | 1948 | |
1949 | |||
1950 | |||
1951 | ;----------------------------------------------------------------- |
||
1952 | ; |
||
1953 | ; SOCKET_is_disconnected |
||
1954 | ; |
||
1955 | ; IN: eax = socket ptr |
||
1956 | ; OUT: / |
||
1957 | ; |
||
1958 | ;----------------------------------------------------------------- |
||
1959 | |||
1960 | align 4 |
||
1961 | SOCKET_is_disconnected: |
||
1962 | |||
2891 | hidnplayr | 1963 | DEBUGF 1,"SOCKET_is_disconnected: %x\n", eax |
1964 | |||
2402 | hidnplayr | 1965 | and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) |
1966 | or [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE |
||
1773 | hidnplayr | 1967 | |
2402 | hidnplayr | 1968 | jmp SOCKET_notify_owner |
1774 | hidnplayr | 1969 | |
1970 | |||
1971 | ;----------------------------------------------------------------- |
||
1972 | ; |
||
1973 | ; SOCKET_cant_recv_more |
||
1974 | ; |
||
1975 | ; IN: eax = socket ptr |
||
1976 | ; OUT: / |
||
1977 | ; |
||
1978 | ;----------------------------------------------------------------- |
||
1979 | |||
1980 | align 4 |
||
1981 | SOCKET_cant_recv_more: |
||
1982 | |||
2891 | hidnplayr | 1983 | DEBUGF 1,"SOCKET_cant_recv_more: %x\n", eax |
1984 | |||
2402 | hidnplayr | 1985 | or [eax + SOCKET.options], SS_CANTRCVMORE |
1885 | hidnplayr | 1986 | |
2402 | hidnplayr | 1987 | ret |
1831 | hidnplayr | 1988 | |
1989 | |||
1990 | |||
1991 | ;----------------------------------------------------------------- |
||
1992 | ; |
||
1885 | hidnplayr | 1993 | ; SOCKET_cant_send_more |
1831 | hidnplayr | 1994 | ; |
1995 | ; IN: eax = socket ptr |
||
1996 | ; OUT: / |
||
1997 | ; |
||
1998 | ;----------------------------------------------------------------- |
||
1999 | |||
2000 | align 4 |
||
1885 | hidnplayr | 2001 | SOCKET_cant_send_more: |
1831 | hidnplayr | 2002 | |
2891 | hidnplayr | 2003 | DEBUGF 1,"SOCKET_cant_send_more: %x\n", eax |
2004 | |||
2402 | hidnplayr | 2005 | or [eax + SOCKET.options], SS_CANTSENDMORE |
1831 | hidnplayr | 2006 | |
2402 | hidnplayr | 2007 | ret |