Rev 907 | Rev 913 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; STACK.INC ;; |
||
7 | ;; ;; |
||
8 | ;; TCP/IP stack for Menuet OS ;; |
||
9 | ;; ;; |
||
10 | ;; Version 0.7 4th July 2004 ;; |
||
11 | ;; ;; |
||
12 | ;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;; |
||
13 | ;; ;; |
||
14 | ;; See file COPYING for details ;; |
||
15 | ;; ;; |
||
16 | ;; Version 0.7 ;; |
||
17 | ;; Added a timer per socket to allow delays when rx window ;; |
||
18 | ;; gets below 1KB ;; |
||
19 | ;; ;; |
||
20 | ;;10.01.2007 Bugfix for checksum function from Paolo Franchetti ;; |
||
21 | ;; ;; |
||
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1 | ha | 23 | |
593 | mikedld | 24 | $Revision: 909 $ |
1 | ha | 25 | |
261 | hidnplayr | 26 | |
1 | ha | 27 | ;******************************************************************* |
28 | ; Interface |
||
29 | ; The interfaces defined in ETHERNET.INC plus: |
||
30 | ; stack_init |
||
31 | ; stack_handler |
||
32 | ; app_stack_handler |
||
33 | ; app_socket_handler |
||
34 | ; checksum |
||
35 | ; |
||
36 | ;******************************************************************* |
||
37 | |||
261 | hidnplayr | 38 | uglobal |
39 | StackCounters: |
||
907 | mikedld | 40 | dumped_rx_count dd 0 |
261 | hidnplayr | 41 | arp_tx_count: dd 0 |
42 | arp_rx_count: dd 0 |
||
302 | hidnplayr | 43 | ip_rx_count: dd 0 |
44 | ip_tx_count: dd 0 |
||
261 | hidnplayr | 45 | endg |
1 | ha | 46 | |
261 | hidnplayr | 47 | ; socket buffers |
302 | hidnplayr | 48 | SOCKETBUFFSIZE equ 4096 ; state + config + buffer. |
907 | mikedld | 49 | SOCKETHEADERSIZE equ 76+8+8 ; thus 4096 - SOCKETHEADERSIZE bytes data |
1 | ha | 50 | |
907 | mikedld | 51 | ;NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20 |
1 | ha | 52 | |
261 | hidnplayr | 53 | ; IPBUFF status values |
302 | hidnplayr | 54 | BUFF_EMPTY equ 0 |
55 | BUFF_RX_FULL equ 1 |
||
56 | BUFF_ALLOCATED equ 2 |
||
57 | BUFF_TX_FULL equ 3 |
||
1 | ha | 58 | |
302 | hidnplayr | 59 | NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX |
1 | ha | 60 | |
302 | hidnplayr | 61 | NUMQUEUES equ 4 |
907 | mikedld | 62 | |
302 | hidnplayr | 63 | EMPTY_QUEUE equ 0 |
64 | IPIN_QUEUE equ 1 |
||
65 | IPOUT_QUEUE equ 2 |
||
66 | NET1OUT_QUEUE equ 3 |
||
1 | ha | 67 | |
302 | hidnplayr | 68 | NO_BUFFER equ 0xFFFF |
69 | IPBUFFSIZE equ 1500 ; MTU of an ethernet packet |
||
70 | NUMQUEUEENTRIES equ NUM_IPBUFFERS |
||
71 | NUMRESENDENTRIES equ 18 ; Buffers for TCP resend packets |
||
1 | ha | 72 | |
73 | ; These are the 0x40 function codes for application access to the stack |
||
74 | STACK_DRIVER_STATUS equ 52 |
||
75 | SOCKET_INTERFACE equ 53 |
||
76 | |||
77 | |||
78 | ; 128KB allocated for the stack and network driver buffers and other |
||
79 | ; data requirements |
||
412 | serge | 80 | ;stack_data_start equ 0x700000 |
81 | ;eth_data_start equ 0x700000 |
||
82 | ;stack_data equ 0x704000 |
||
83 | ;stack_data_end equ 0x71ffff |
||
1 | ha | 84 | |
85 | ; 32 bit word |
||
302 | hidnplayr | 86 | stack_config equ stack_data |
261 | hidnplayr | 87 | |
1 | ha | 88 | ; 32 bit word - IP Address in network format |
302 | hidnplayr | 89 | stack_ip equ stack_data + 4 |
261 | hidnplayr | 90 | |
1 | ha | 91 | ; 1 byte. 0 == inactive, 1 = active |
92 | ethernet_active equ stack_data + 9 |
||
261 | hidnplayr | 93 | |
94 | |||
95 | ; TODO :: empty memory area |
||
96 | |||
1 | ha | 97 | ; Address of selected socket |
907 | mikedld | 98 | ;sktAddr equ stack_data + 32 |
1 | ha | 99 | ; Parameter to checksum routine - data ptr |
302 | hidnplayr | 100 | checkAdd1 equ stack_data + 36 |
1 | ha | 101 | ; Parameter to checksum routine - 2nd data ptr |
302 | hidnplayr | 102 | checkAdd2 equ stack_data + 40 |
1 | ha | 103 | ; Parameter to checksum routine - data size |
302 | hidnplayr | 104 | checkSize1 equ stack_data + 44 |
1 | ha | 105 | ; Parameter to checksum routine - 2nd data size |
302 | hidnplayr | 106 | checkSize2 equ stack_data + 46 |
1 | ha | 107 | ; result of checksum routine |
302 | hidnplayr | 108 | checkResult equ stack_data + 48 |
1 | ha | 109 | |
110 | ; holds the TCP/UDP pseudo header. SA|DA|0|prot|UDP len| |
||
302 | hidnplayr | 111 | pseudoHeader equ stack_data + 50 |
1 | ha | 112 | |
113 | ; receive and transmit IP buffer allocation |
||
907 | mikedld | 114 | ;sockets equ stack_data + 62 |
115 | Next_free2 equ stack_data + 62;Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS) |
||
1 | ha | 116 | ; 1560 byte buffer for rx / tx ethernet packets |
302 | hidnplayr | 117 | Ether_buffer equ Next_free2 |
118 | Next_free3 equ Ether_buffer + 1518 |
||
261 | hidnplayr | 119 | last_1sTick equ Next_free3 |
302 | hidnplayr | 120 | IPbuffs equ Next_free3 + 1 |
121 | queues equ IPbuffs + ( NUM_IPBUFFERS * IPBUFFSIZE ) |
||
122 | queueList equ queues + (2 * NUMQUEUES) |
||
123 | last_1hsTick equ queueList + ( 2 * NUMQUEUEENTRIES ) |
||
1 | ha | 124 | |
125 | ;resendQ equ queueList + ( 2 * NUMQUEUEENTRIES ) |
||
126 | ;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
||
127 | ; equ resendBuffer + ( IPBUFFSIZE * NUMRESENDENTRIES ) |
||
128 | |||
129 | |||
130 | |||
412 | serge | 131 | ;resendQ equ 0x770000 |
907 | mikedld | 132 | ;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP ; XTODO: validate size |
133 | resendBuffer equ resendQ + ( 8 * NUMRESENDENTRIES ) ; for TCP |
||
1 | ha | 134 | |
135 | |||
907 | mikedld | 136 | uglobal |
137 | net_sockets rd 2 |
||
138 | endg |
||
139 | |||
261 | hidnplayr | 140 | ; simple macro for memory set operation |
141 | macro _memset_dw adr,value,amount |
||
142 | { |
||
302 | hidnplayr | 143 | mov edi, adr |
144 | mov ecx, amount |
||
261 | hidnplayr | 145 | if value = 0 |
146 | xor eax, eax |
||
147 | else |
||
148 | mov eax, value |
||
149 | end if |
||
150 | cld |
||
302 | hidnplayr | 151 | rep stosd |
261 | hidnplayr | 152 | } |
153 | |||
154 | |||
155 | ; Below, the main network layer source code is included |
||
156 | ; |
||
157 | include "queue.inc" |
||
158 | include "eth_drv/ethernet.inc" |
||
159 | include "ip.inc" |
||
160 | include "socket.inc" |
||
161 | |||
1 | ha | 162 | ;*************************************************************************** |
163 | ; Function |
||
164 | ; stack_init |
||
165 | ; |
||
166 | ; Description |
||
167 | ; Clear all allocated memory to zero. This ensures that |
||
168 | ; on startup, the stack is inactive, and consumes no resources |
||
169 | ; This is a kernel function, called prior to the OS main loop |
||
170 | ; in set_variables |
||
171 | ; |
||
172 | ;*************************************************************************** |
||
261 | hidnplayr | 173 | |
1 | ha | 174 | stack_init: |
261 | hidnplayr | 175 | ; Init two address spaces with default values |
176 | _memset_dw stack_data_start, 0, 0x20000/4 |
||
907 | mikedld | 177 | ;_memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES ; XTODO: validate size |
178 | _memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES * 2 |
||
1 | ha | 179 | |
909 | mikedld | 180 | mov [net_sockets], 0 |
181 | mov [net_sockets + 4], 0 |
||
182 | |||
261 | hidnplayr | 183 | ; Queries initialization |
184 | call queueInit |
||
1 | ha | 185 | |
261 | hidnplayr | 186 | ; The following block sets up the 1s timer |
187 | mov al, 0x0 |
||
188 | out 0x70, al |
||
189 | in al, 0x71 |
||
190 | mov [last_1sTick], al |
||
191 | ret |
||
1 | ha | 192 | |
193 | |||
194 | |||
195 | ;*************************************************************************** |
||
196 | ; Function |
||
197 | ; stack_handler |
||
198 | ; |
||
199 | ; Description |
||
200 | ; The kernel loop routine for the stack |
||
201 | ; This is a kernel function, called in the main loop |
||
202 | ; |
||
203 | ;*************************************************************************** |
||
204 | stack_handler: |
||
205 | |||
206 | call ethernet_driver |
||
207 | call ip_rx |
||
208 | |||
209 | |||
210 | ; Test for 10ms tick, call tcp timer |
||
211 | mov eax, [timer_ticks] ;[0xfdf0] |
||
212 | cmp eax, [last_1hsTick] |
||
302 | hidnplayr | 213 | je sh_001 |
1 | ha | 214 | |
215 | mov [last_1hsTick], eax |
||
216 | call tcp_tx_handler |
||
217 | |||
218 | sh_001: |
||
219 | |||
220 | ; Test for 1 second event, call 1s timer functions |
||
261 | hidnplayr | 221 | mov al, 0x0 ;second |
222 | out 0x70, al |
||
302 | hidnplayr | 223 | in al, 0x71 |
1 | ha | 224 | cmp al, [last_1sTick] |
302 | hidnplayr | 225 | je sh_exit |
1 | ha | 226 | |
227 | mov [last_1sTick], al |
||
228 | |||
379 | serge | 229 | stdcall arp_table_manager, ARP_TABLE_TIMER, 0, 0 |
1 | ha | 230 | call tcp_tcb_handler |
231 | |||
232 | sh_exit: |
||
233 | ret |
||
234 | |||
261 | hidnplayr | 235 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
236 | ;; Checksum [by Johnny_B] |
||
237 | ;; IN: |
||
238 | ;; buf_ptr=POINTER to buffer |
||
239 | ;; buf_size=SIZE of buffer |
||
240 | ;; OUT: |
||
241 | ;; AX=16-bit checksum |
||
242 | ;; Saves all used registers |
||
243 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
244 | proc checksum_jb stdcall uses ebx esi ecx,\ |
||
245 | buf_ptr:DWORD, buf_size:DWORD |
||
1 | ha | 246 | |
261 | hidnplayr | 247 | xor eax, eax |
248 | xor ebx, ebx ;accumulator |
||
249 | mov esi, dword[buf_ptr] |
||
250 | mov ecx, dword[buf_size] |
||
251 | shr ecx, 1 ; ecx=ecx/2 |
||
302 | hidnplayr | 252 | jnc @f ; if CF==0 then size is even number |
261 | hidnplayr | 253 | mov bh, byte[esi + ecx*2] |
254 | @@: |
||
255 | cld |
||
1 | ha | 256 | |
261 | hidnplayr | 257 | .loop: |
258 | lodsw ;eax=word[esi],esi=esi+2 |
||
259 | xchg ah,al ;cause must be a net byte-order |
||
260 | add ebx, eax |
||
261 | loop .loop |
||
1 | ha | 262 | |
261 | hidnplayr | 263 | mov eax, ebx |
264 | shr eax, 16 |
||
265 | add ax, bx |
||
266 | not ax |
||
1 | ha | 267 | |
268 | ret |
||
261 | hidnplayr | 269 | endp |
1 | ha | 270 | |
271 | ;*************************************************************************** |
||
272 | ; Function |
||
273 | ; checksum |
||
274 | ; |
||
275 | ; Description |
||
276 | ; checkAdd1,checkAdd2, checkSize1, checkSize2, checkResult |
||
277 | ; Dont break anything; Most registers are used by the caller |
||
278 | ; This code is derived from the 'C' source, cksum.c, in the book |
||
279 | ; Internetworking with TCP/IP Volume II by D.E. Comer |
||
280 | ; |
||
281 | ;*************************************************************************** |
||
261 | hidnplayr | 282 | |
283 | |||
1 | ha | 284 | checksum: |
285 | pusha |
||
323 | hidnplayr | 286 | mov eax, [checkAdd1] |
302 | hidnplayr | 287 | xor edx, edx ; edx is the accumulative checksum |
1 | ha | 288 | xor ebx, ebx |
289 | mov cx, [checkSize1] |
||
290 | shr cx, 1 |
||
302 | hidnplayr | 291 | jz cs1_1 |
1 | ha | 292 | |
293 | cs1: |
||
294 | mov bh, [eax] |
||
295 | mov bl, [eax + 1] |
||
296 | |||
297 | add eax, 2 |
||
298 | add edx, ebx |
||
299 | |||
300 | loopw cs1 |
||
301 | |||
302 | cs1_1: |
||
303 | and word [checkSize1], 0x01 |
||
302 | hidnplayr | 304 | jz cs_test2 |
1 | ha | 305 | |
306 | mov bh, [eax] |
||
307 | xor bl, bl |
||
308 | |||
309 | add edx, ebx |
||
310 | |||
311 | cs_test2: |
||
312 | mov cx, [checkSize2] |
||
313 | cmp cx, 0 |
||
302 | hidnplayr | 314 | jz cs_exit ; Finished if no 2nd buffer |
1 | ha | 315 | |
323 | hidnplayr | 316 | mov eax, [checkAdd2] |
317 | |||
1 | ha | 318 | shr cx, 1 |
302 | hidnplayr | 319 | jz cs2_1 |
1 | ha | 320 | |
321 | cs2: |
||
322 | mov bh, [eax] |
||
323 | mov bl, [eax + 1] |
||
324 | |||
325 | add eax, 2 |
||
326 | add edx, ebx |
||
327 | |||
328 | loopw cs2 |
||
329 | |||
330 | cs2_1: |
||
331 | and word [checkSize2], 0x01 |
||
302 | hidnplayr | 332 | jz cs_exit |
1 | ha | 333 | |
334 | mov bh, [eax] |
||
335 | xor bl, bl |
||
336 | |||
337 | add edx, ebx |
||
338 | |||
339 | cs_exit: |
||
340 | mov ebx, edx |
||
341 | |||
342 | shr ebx, 16 |
||
343 | and edx, 0xffff |
||
344 | add edx, ebx |
||
345 | mov eax, edx |
||
346 | shr eax, 16 |
||
347 | add edx, eax |
||
348 | not dx |
||
349 | |||
350 | mov [checkResult], dx |
||
351 | popa |
||
352 | ret |
||
353 | |||
354 | |||
355 | |||
356 | |||
357 | ;*************************************************************************** |
||
358 | ; Function |
||
359 | ; app_stack_handler |
||
360 | ; |
||
361 | ; Description |
||
261 | hidnplayr | 362 | ; This is an application service, called by int 0x40, function 52 |
1 | ha | 363 | ; It provides application access to the network interface layer |
364 | ; |
||
365 | ;*************************************************************************** |
||
366 | app_stack_handler: |
||
367 | cmp eax, 0 |
||
368 | jnz not0 |
||
261 | hidnplayr | 369 | ; Read the configuration word |
1 | ha | 370 | mov eax, [stack_config] |
371 | ret |
||
372 | |||
373 | not0: |
||
374 | cmp eax, 1 |
||
375 | jnz not1 |
||
376 | ; read the IP address |
||
377 | |||
378 | mov eax, [stack_ip] |
||
379 | ret |
||
380 | |||
381 | not1: |
||
382 | cmp eax, 2 |
||
383 | jnz not2 |
||
384 | |||
385 | ; write the configuration word |
||
386 | mov [stack_config], ebx |
||
387 | |||
388 | ; |
||
389 | ; If ethernet now enabled, probe for the card, reset it and empty |
||
390 | ; the packet buffer |
||
391 | ; If all successfull, enable the card. |
||
392 | ; If ethernet now disabled, set it as disabled. Should really |
||
393 | ; empty the tcpip data area too. |
||
394 | |||
395 | ; ethernet interface is '3' in ls 7 bits |
||
396 | and bl, 0x7f |
||
397 | cmp bl, 3 |
||
398 | |||
302 | hidnplayr | 399 | je ash_eth_enable |
1 | ha | 400 | ; Ethernet isn't enabled, so make sure that the card is disabled |
401 | mov [ethernet_active], byte 0 |
||
402 | |||
403 | ret |
||
404 | |||
405 | ash_eth_enable: |
||
406 | ; Probe for the card. This will reset it and enable the interface |
||
407 | ; if found |
||
408 | call eth_probe |
||
409 | cmp eax, 0 |
||
302 | hidnplayr | 410 | je ash_eth_done ; Abort if no hardware found |
1 | ha | 411 | |
412 | mov [ethernet_active], byte 1 |
||
413 | |||
414 | ash_eth_done: |
||
415 | ret |
||
416 | |||
417 | not2: |
||
418 | cmp eax, 3 |
||
419 | jnz not3 |
||
420 | ; write the IP Address |
||
421 | mov [stack_ip], ebx |
||
422 | ret |
||
423 | |||
261 | hidnplayr | 424 | ;old functions was deleted |
425 | |||
1 | ha | 426 | not3: |
427 | cmp eax, 6 |
||
428 | jnz not6 |
||
429 | |||
430 | ; Insert an IP packet into the stacks received packet queue |
||
431 | call stack_insert_packet |
||
432 | ret |
||
433 | |||
434 | not6: |
||
435 | cmp eax, 7 |
||
436 | jnz not7 |
||
437 | |||
438 | ; Test for any packets queued for transmission over the network |
||
439 | |||
440 | not7: |
||
441 | cmp eax, 8 |
||
442 | jnz not8 |
||
443 | |||
444 | call stack_get_packet |
||
445 | ; Extract a packet queued for transmission by the network |
||
446 | ret |
||
447 | |||
448 | not8: |
||
449 | cmp eax, 9 |
||
450 | jnz not9 |
||
451 | |||
452 | ; read the gateway IP address |
||
453 | |||
454 | mov eax, [gateway_ip] |
||
455 | ret |
||
456 | |||
457 | not9: |
||
458 | cmp eax, 10 |
||
459 | jnz not10 |
||
460 | |||
461 | ; read the subnet mask |
||
462 | |||
463 | mov eax, [subnet_mask] |
||
464 | ret |
||
465 | |||
466 | not10: |
||
467 | cmp eax, 11 |
||
468 | jnz not11 |
||
469 | |||
470 | ; write the gateway IP Address |
||
471 | mov [gateway_ip], ebx |
||
472 | |||
473 | ret |
||
474 | |||
475 | not11: |
||
476 | cmp eax, 12 |
||
477 | jnz not12 |
||
478 | |||
479 | ; write the subnet mask |
||
480 | mov [subnet_mask], ebx |
||
481 | |||
482 | |||
483 | not12: |
||
484 | cmp eax, 13 |
||
485 | jnz not13 |
||
486 | |||
487 | ; read the dns |
||
488 | |||
489 | mov eax, [dns_ip] |
||
490 | ret |
||
491 | |||
492 | not13: |
||
493 | cmp eax, 14 |
||
261 | hidnplayr | 494 | jnz not14 |
1 | ha | 495 | |
496 | ; write the dns IP Address |
||
497 | mov [dns_ip], ebx |
||
498 | |||
379 | serge | 499 | ret |
500 | |||
261 | hidnplayr | 501 | ; |
502 | not14: |
||
503 | cmp eax, 15 |
||
504 | jnz not15 |
||
505 | |||
506 | ; in ebx we need 4 to read the last 2 bytes |
||
507 | cmp ebx, dword 4 |
||
508 | je read |
||
379 | serge | 509 | |
261 | hidnplayr | 510 | ; or we need 0 to read the first 4 bytes |
511 | cmp ebx, dword 0 |
||
512 | jnz param_error |
||
513 | |||
514 | ; read MAC, returned (in mirrored byte order) in eax |
||
515 | read: |
||
516 | mov eax, [node_addr + ebx] |
||
517 | jmp @f |
||
379 | serge | 518 | |
519 | param_error: |
||
261 | hidnplayr | 520 | mov eax, -1 ; params not accepted |
521 | @@: |
||
522 | ret |
||
523 | |||
379 | serge | 524 | |
261 | hidnplayr | 525 | ; 0 -> arp_probe |
526 | ; 1 -> arp_announce |
||
527 | ; 2 -> arp_responce (not supported yet) |
||
528 | |||
529 | not15: ; ARP stuff |
||
530 | cmp eax, 16 |
||
531 | jnz not16 |
||
379 | serge | 532 | |
261 | hidnplayr | 533 | cmp ebx, 0 |
534 | je a_probe |
||
379 | serge | 535 | |
261 | hidnplayr | 536 | cmp ebx, 1 |
537 | je a_ann ; arp announce |
||
379 | serge | 538 | |
302 | hidnplayr | 539 | ; cmp ebx,2 |
540 | ; jne a_resp ; arp response |
||
261 | hidnplayr | 541 | |
542 | jmp param15_error |
||
379 | serge | 543 | |
544 | |||
261 | hidnplayr | 545 | ; arp probe, sender IP must be set to 0.0.0.0, target IP is set to address being probed |
546 | ; ecx: pointer to target MAC, MAC should set to 0 by application |
||
547 | ; edx: target IP |
||
548 | a_probe: |
||
549 | push dword [stack_ip] |
||
379 | serge | 550 | |
261 | hidnplayr | 551 | mov edx, [stack_ip] |
552 | mov [stack_ip], dword 0 |
||
379 | serge | 553 | mov esi, ecx ; pointer to target MAC address |
261 | hidnplayr | 554 | call arp_request |
379 | serge | 555 | |
556 | pop dword [stack_ip] |
||
302 | hidnplayr | 557 | jmp @f |
379 | serge | 558 | |
261 | hidnplayr | 559 | ; arp announce, sender IP must be set to target IP |
560 | ; ecx: pointer to target MAC |
||
561 | a_ann: |
||
562 | mov edx, [stack_ip] |
||
563 | mov esi, ecx ; pointer to target MAC address |
||
564 | call arp_request |
||
565 | jmp @f |
||
379 | serge | 566 | |
261 | hidnplayr | 567 | param15_error: |
568 | mov eax, -1 |
||
379 | serge | 569 | |
261 | hidnplayr | 570 | @@: |
571 | ret |
||
572 | ; |
||
573 | ; modified by [smb] |
||
574 | |||
575 | ; |
||
576 | ; ARPTable manager interface |
||
577 | not16: |
||
578 | cmp eax, 17 |
||
579 | jnz stack_driver_end |
||
580 | |||
581 | ;see "proc arp_table_manager" for more details |
||
582 | stdcall arp_table_manager,ebx,ecx,edx ;Opcode,Index,Extra |
||
583 | |||
1 | ha | 584 | ret |
261 | hidnplayr | 585 | ; |
1 | ha | 586 | |
587 | stack_driver_end: |
||
261 | hidnplayr | 588 | ret |
1 | ha | 589 | |
590 | |||
591 | |||
592 | ;*************************************************************************** |
||
593 | ; Function |
||
594 | ; app_socket_handler |
||
595 | ; |
||
596 | ; Description |
||
261 | hidnplayr | 597 | ; This is an application service, called by int 0x40, function 53 |
1 | ha | 598 | ; It provides application access to stack socket services |
599 | ; such as opening sockets |
||
600 | ; |
||
601 | ;*************************************************************************** |
||
602 | app_socket_handler: |
||
603 | cmp eax, 0 |
||
604 | jnz nots0 |
||
605 | |||
606 | call socket_open |
||
607 | ret |
||
608 | |||
609 | nots0: |
||
610 | cmp eax, 1 |
||
611 | jnz nots1 |
||
612 | |||
613 | call socket_close |
||
614 | ret |
||
615 | |||
616 | nots1: |
||
617 | cmp eax, 2 |
||
618 | jnz nots2 |
||
619 | |||
620 | call socket_poll |
||
621 | ret |
||
622 | |||
623 | nots2: |
||
624 | cmp eax, 3 |
||
625 | jnz nots3 |
||
626 | |||
627 | call socket_read |
||
628 | ret |
||
629 | |||
630 | nots3: |
||
631 | cmp eax, 4 |
||
632 | jnz nots4 |
||
633 | |||
634 | call socket_write |
||
635 | ret |
||
636 | |||
637 | nots4: |
||
638 | cmp eax, 5 |
||
639 | jnz nots5 |
||
640 | |||
641 | call socket_open_tcp |
||
642 | ret |
||
643 | |||
644 | nots5: |
||
645 | cmp eax, 6 |
||
646 | jnz nots6 |
||
647 | |||
648 | call socket_status |
||
649 | ret |
||
650 | |||
651 | nots6: |
||
652 | cmp eax, 7 |
||
653 | jnz nots7 |
||
654 | |||
655 | call socket_write_tcp |
||
656 | ret |
||
657 | |||
658 | nots7: |
||
659 | cmp eax, 8 |
||
660 | jnz nots8 |
||
661 | |||
662 | call socket_close_tcp |
||
663 | ret |
||
664 | |||
665 | nots8: |
||
666 | cmp eax, 9 |
||
667 | jnz nots9 |
||
668 | |||
669 | call is_localport_unused |
||
670 | ret |
||
671 | |||
672 | nots9: |
||
302 | hidnplayr | 673 | cmp eax, 10 |
674 | jnz nots10 |
||
675 | |||
676 | mov eax,dword[drvr_cable] |
||
677 | test eax,eax |
||
678 | jnz @f ; if function is not implented, return -1 |
||
679 | mov al,-1 |
||
680 | ret |
||
681 | |||
682 | @@: |
||
683 | call dword[drvr_cable] |
||
684 | ret |
||
685 | |||
686 | |||
687 | nots10: |
||
323 | hidnplayr | 688 | cmp eax, 11 |
689 | jnz nots11 |
||
690 | |||
691 | call socket_read_packet |
||
692 | ret |
||
693 | |||
694 | nots11: |
||
1 | ha | 695 | cmp eax, 254 |
696 | jnz notdump |
||
697 | |||
698 | ret |
||
699 | |||
700 | notdump: |
||
701 | cmp eax, 255 |
||
702 | jnz notsdebug |
||
703 | |||
704 | ; This sub function allows access to debugging information on the stack |
||
705 | ; ebx holds the request: |
||
706 | ; 100 : return length of empty queue |
||
707 | ; 101 : return length of IPOUT QUEUE |
||
708 | ; 102 : return length of IPIN QUEUE |
||
709 | ; 103 : return length of NET1OUT QUEUE |
||
710 | ; 200 : return # of ARP entries |
||
711 | ; 201 : return size of ARP table ( max # entries ) |
||
712 | ; 202 : select ARP table entry # |
||
713 | ; 203 : return IP of selected table entry |
||
714 | ; 204 : return High 4 bytes of MAC address of selected table entry |
||
715 | ; 205 : return low 2 bytes of MAC address of selected table entry |
||
716 | ; 206 : return status word of selected table entry |
||
717 | ; 207 : return Time to live of selected table entry |
||
718 | |||
719 | |||
720 | ; 2 : return number of IP packets received |
||
721 | ; 3 : return number of packets transmitted |
||
722 | ; 4 : return number of received packets dumped |
||
723 | ; 5 : return number of arp packets received |
||
724 | ; 6 : return status of packet driver |
||
725 | ; ( 0 == not active, FFFFFFFF = successful ) |
||
726 | |||
727 | call stack_internal_status |
||
728 | ret |
||
729 | |||
730 | notsdebug: |
||
731 | ; Invalid Option |
||
732 | ret |
||
733 | |||
734 | |||
735 | uglobal |
||
736 | ARPTmp: |
||
737 | times 14 db 0 |
||
738 | endg |
||
739 | |||
740 | ;*************************************************************************** |
||
741 | ; Function |
||
742 | ; stack_internal_status |
||
743 | ; |
||
744 | ; Description |
||
745 | ; Returns information about the internal status of the stack |
||
746 | ; This is only useful for debugging |
||
747 | ; It works with the ethernet driver |
||
748 | ; sub function in ebx |
||
749 | ; return requested data in eax |
||
750 | ; |
||
751 | ;*************************************************************************** |
||
752 | stack_internal_status: |
||
753 | cmp ebx, 100 |
||
754 | jnz notsis100 |
||
755 | |||
756 | ; 100 : return length of EMPTY QUEUE |
||
757 | mov ebx, EMPTY_QUEUE |
||
758 | call queueSize |
||
759 | ret |
||
760 | |||
761 | notsis100: |
||
762 | cmp ebx, 101 |
||
763 | jnz notsis101 |
||
764 | |||
765 | ; 101 : return length of IPOUT QUEUE |
||
766 | mov ebx, IPOUT_QUEUE |
||
767 | call queueSize |
||
768 | ret |
||
769 | |||
770 | notsis101: |
||
771 | cmp ebx, 102 |
||
772 | jnz notsis102 |
||
773 | |||
774 | ; 102 : return length of IPIN QUEUE |
||
775 | mov ebx, IPIN_QUEUE |
||
776 | call queueSize |
||
777 | ret |
||
778 | |||
779 | notsis102: |
||
780 | cmp ebx, 103 |
||
781 | jnz notsis103 |
||
782 | |||
783 | ; 103 : return length of NET1OUT QUEUE |
||
784 | mov ebx, NET1OUT_QUEUE |
||
785 | call queueSize |
||
786 | ret |
||
787 | |||
788 | notsis103: |
||
789 | cmp ebx, 200 |
||
790 | jnz notsis200 |
||
791 | |||
792 | ; 200 : return num entries in arp table |
||
793 | movzx eax, byte [NumARP] |
||
794 | ret |
||
795 | |||
796 | notsis200: |
||
797 | cmp ebx, 201 |
||
798 | jnz notsis201 |
||
799 | |||
800 | ; 201 : return arp table size |
||
801 | mov eax, 20 ; ARP_TABLE_SIZE |
||
802 | ret |
||
803 | |||
804 | notsis201: |
||
805 | cmp ebx, 202 |
||
806 | jnz notsis202 |
||
807 | |||
808 | ; 202 - read the requested table entry |
||
809 | ; into a temporary buffer |
||
810 | ; ecx holds the entry number |
||
811 | |||
812 | mov eax, ecx |
||
813 | mov ecx, 14 ; ARP_ENTRY_SIZE |
||
814 | mul ecx |
||
815 | |||
816 | mov ecx, [eax + ARPTable] |
||
817 | mov [ARPTmp], ecx |
||
818 | mov ecx, [eax + ARPTable+4] |
||
819 | mov [ARPTmp+4], ecx |
||
820 | mov ecx, [eax + ARPTable+8] |
||
821 | mov [ARPTmp+8], ecx |
||
822 | mov cx, [eax + ARPTable+12] |
||
823 | mov [ARPTmp+12], cx |
||
824 | ret |
||
825 | |||
826 | notsis202: |
||
827 | cmp ebx, 203 |
||
828 | jnz notsis203 |
||
829 | |||
830 | ; 203 - return IP address |
||
831 | mov eax, [ARPTmp] |
||
832 | ret |
||
833 | |||
834 | notsis203: |
||
835 | cmp ebx, 204 |
||
836 | jnz notsis204 |
||
837 | |||
838 | ; 204 - return MAC high dword |
||
839 | mov eax, [ARPTmp+4] |
||
840 | ret |
||
841 | |||
842 | notsis204: |
||
843 | cmp ebx, 205 |
||
844 | jnz notsis205 |
||
845 | |||
846 | ; 205 - return MAC ls word |
||
847 | movzx eax, word [ARPTmp+8] |
||
848 | ret |
||
849 | |||
850 | notsis205: |
||
851 | cmp ebx, 206 |
||
852 | jnz notsis206 |
||
853 | |||
854 | ; 206 - return status word |
||
855 | movzx eax, word [ARPTmp+10] |
||
856 | ret |
||
857 | |||
858 | notsis206: |
||
859 | cmp ebx, 207 |
||
860 | jnz notsis207 |
||
861 | |||
862 | ; 207 - return ttl word |
||
863 | movzx eax, word [ARPTmp+12] |
||
864 | ret |
||
865 | |||
866 | notsis207: |
||
867 | cmp ebx, 2 |
||
868 | jnz notsis2 |
||
869 | |||
870 | ; 2 : return number of IP packets received |
||
871 | mov eax, [ip_rx_count] |
||
872 | ret |
||
873 | |||
874 | notsis2: |
||
875 | cmp ebx, 3 |
||
876 | jnz notsis3 |
||
877 | |||
878 | ; 3 : return number of packets transmitted |
||
879 | mov eax, [ip_tx_count] |
||
880 | ret |
||
881 | |||
882 | notsis3: |
||
883 | cmp ebx, 4 |
||
884 | jnz notsis4 |
||
885 | |||
886 | ; 4 : return number of received packets dumped |
||
887 | mov eax, [dumped_rx_count] |
||
888 | ret |
||
889 | |||
890 | notsis4: |
||
891 | cmp ebx, 5 |
||
892 | jnz notsis5 |
||
893 | |||
894 | ; 5 : return number of arp packets received |
||
895 | mov eax, [arp_rx_count] |
||
896 | ret |
||
897 | |||
898 | notsis5: |
||
899 | cmp ebx, 6 |
||
900 | jnz notsis6 |
||
901 | |||
902 | ; 6 : return status of packet driver |
||
903 | ; ( 0 == not active, FFFFFFFF = successful ) |
||
904 | mov eax, [eth_status] |
||
905 | ret |
||
906 | |||
907 | notsis6: |
||
908 | xor eax, eax |
||
909 | ret |
||
910 | |||
911 | |||
912 | |||
913 | ;*************************************************************************** |
||
914 | ; Function |
||
915 | ; stack_get_packet |
||
916 | ; |
||
917 | ; Description |
||
918 | ; extracts an IP packet from the NET1 output queue |
||
919 | ; and sends the data to the calling process |
||
920 | ; pointer to data in edx |
||
921 | ; returns number of bytes read in eax |
||
922 | ; |
||
923 | ;*************************************************************************** |
||
924 | stack_get_packet: |
||
925 | ; Look for a buffer to tx |
||
926 | mov eax, NET1OUT_QUEUE |
||
927 | call dequeue |
||
928 | cmp ax, NO_BUFFER |
||
302 | hidnplayr | 929 | je sgp_non_exit ; Exit if no buffer available |
1 | ha | 930 | |
302 | hidnplayr | 931 | push eax ; Save buffer number for freeing at end |
1 | ha | 932 | |
933 | push edx |
||
934 | ; convert buffer pointer eax to the absolute address |
||
935 | mov ecx, IPBUFFSIZE |
||
936 | mul ecx |
||
937 | add eax, IPbuffs |
||
938 | pop edx |
||
939 | |||
302 | hidnplayr | 940 | push eax ; save address of IP data |
1 | ha | 941 | ; Get the address of the callers data |
379 | serge | 942 | mov edi,[TASK_BASE] |
115 | poddubny | 943 | add edi,TASKDATA.mem_start |
1 | ha | 944 | add edx,[edi] |
945 | mov edi, edx |
||
946 | pop eax |
||
947 | |||
302 | hidnplayr | 948 | mov ecx, 1500 ; should get the actual number of bytes to write |
1 | ha | 949 | mov esi, eax |
950 | cld |
||
302 | hidnplayr | 951 | rep movsb ; copy the data across |
1 | ha | 952 | |
953 | ; And finally, return the buffer to the free queue |
||
954 | pop eax |
||
955 | call freeBuff |
||
956 | |||
957 | mov eax, 1500 |
||
958 | ret |
||
959 | |||
960 | sgp_non_exit: |
||
961 | xor eax, eax |
||
962 | ret |
||
963 | |||
964 | |||
965 | |||
966 | ;*************************************************************************** |
||
967 | ; Function |
||
968 | ; stack_insert_packet |
||
969 | ; |
||
970 | ; Description |
||
971 | ; writes an IP packet into the stacks receive queue |
||
972 | ; # of bytes to write in ecx |
||
973 | ; pointer to data in edx |
||
974 | ; returns 0 in eax ok, -1 == failed |
||
975 | ; |
||
976 | ;*************************************************************************** |
||
977 | stack_insert_packet: |
||
978 | |||
979 | mov eax, EMPTY_QUEUE |
||
980 | call dequeue |
||
981 | cmp ax, NO_BUFFER |
||
302 | hidnplayr | 982 | je sip_err_exit |
1 | ha | 983 | |
984 | push eax |
||
985 | |||
986 | ; save the pointers to the data buffer & size |
||
987 | push edx |
||
988 | push ecx |
||
989 | |||
990 | ; convert buffer pointer eax to the absolute address |
||
991 | mov ecx, IPBUFFSIZE |
||
992 | mul ecx |
||
993 | add eax, IPbuffs |
||
994 | |||
995 | mov edx, eax |
||
996 | |||
997 | ; So, edx holds the IPbuffer ptr |
||
998 | |||
302 | hidnplayr | 999 | pop ecx ; count of bytes to send |
1000 | mov ebx, ecx ; need the length later |
||
1001 | pop eax ; get callers ptr to data to send |
||
1 | ha | 1002 | |
1003 | ; Get the address of the callers data |
||
379 | serge | 1004 | mov edi,[TASK_BASE] |
115 | poddubny | 1005 | add edi,TASKDATA.mem_start |
1 | ha | 1006 | add eax,[edi] |
1007 | mov esi, eax |
||
1008 | |||
1009 | mov edi, edx |
||
1010 | cld |
||
302 | hidnplayr | 1011 | rep movsb ; copy the data across |
1 | ha | 1012 | |
1013 | pop ebx |
||
1014 | |||
1015 | mov eax, IPIN_QUEUE |
||
1016 | call queue |
||
1017 | |||
1018 | inc dword [ip_rx_count] |
||
1019 | |||
1020 | mov eax, 0 |
||
1021 | ret |
||
1022 | |||
1023 | sip_err_exit: |
||
1024 | mov eax, 0xFFFFFFFF |
||
1025 | ret |
||
1026 |