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