Rev 983 | Rev 1369 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
983 | diamond | 3 | ;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; |
431 | serge | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; STACK.INC ;; |
||
7 | ;; ;; |
||
8 | ;; TCP/IP stack for Menuet OS ;; |
||
9 | ;; ;; |
||
10 | ;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;; |
||
11 | ;; ;; |
||
12 | ;; See file COPYING for details ;; |
||
13 | ;; ;; |
||
14 | ;; Version 0.7 ;; |
||
15 | ;; Added a timer per socket to allow delays when rx window ;; |
||
16 | ;; gets below 1KB ;; |
||
17 | ;; ;; |
||
18 | ;;10.01.2007 Bugfix for checksum function from Paolo Franchetti ;; |
||
19 | ;; ;; |
||
20 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1 | ha | 21 | |
593 | mikedld | 22 | $Revision: 1168 $ |
1 | ha | 23 | |
261 | hidnplayr | 24 | |
1 | ha | 25 | ;******************************************************************* |
26 | ; Interface |
||
27 | ; The interfaces defined in ETHERNET.INC plus: |
||
28 | ; stack_init |
||
29 | ; stack_handler |
||
30 | ; app_stack_handler |
||
31 | ; app_socket_handler |
||
32 | ; checksum |
||
33 | ; |
||
34 | ;******************************************************************* |
||
35 | |||
261 | hidnplayr | 36 | uglobal |
37 | StackCounters: |
||
907 | mikedld | 38 | dumped_rx_count dd 0 |
261 | hidnplayr | 39 | arp_tx_count: dd 0 |
40 | arp_rx_count: dd 0 |
||
1168 | Lrz | 41 | ip_rx_count: dd 0 |
42 | ip_tx_count: dd 0 |
||
261 | hidnplayr | 43 | endg |
1 | ha | 44 | |
261 | hidnplayr | 45 | ; socket buffers |
1168 | Lrz | 46 | SOCKETBUFFSIZE equ 4096 ; state + config + buffer. |
47 | SOCKETHEADERSIZE equ SOCKET.rxData ; thus 4096 - SOCKETHEADERSIZE bytes data |
||
1 | ha | 48 | |
907 | mikedld | 49 | ;NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20 |
1 | ha | 50 | |
261 | hidnplayr | 51 | ; IPBUFF status values |
1168 | Lrz | 52 | BUFF_EMPTY equ 0 |
53 | BUFF_RX_FULL equ 1 |
||
54 | BUFF_ALLOCATED equ 2 |
||
55 | BUFF_TX_FULL equ 3 |
||
1 | ha | 56 | |
1168 | Lrz | 57 | NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX |
1 | ha | 58 | |
1168 | Lrz | 59 | NUMQUEUES equ 4 |
907 | mikedld | 60 | |
1168 | Lrz | 61 | EMPTY_QUEUE equ 0 |
62 | IPIN_QUEUE equ 1 |
||
63 | IPOUT_QUEUE equ 2 |
||
64 | NET1OUT_QUEUE equ 3 |
||
1 | ha | 65 | |
1168 | Lrz | 66 | NO_BUFFER equ 0xFFFF |
67 | IPBUFFSIZE equ 1500 ; MTU of an ethernet packet |
||
68 | NUMQUEUEENTRIES equ NUM_IPBUFFERS |
||
69 | NUMRESENDENTRIES equ 18 ; Buffers for TCP resend packets |
||
1 | ha | 70 | |
71 | ; These are the 0x40 function codes for application access to the stack |
||
72 | STACK_DRIVER_STATUS equ 52 |
||
73 | SOCKET_INTERFACE equ 53 |
||
74 | |||
75 | |||
76 | ; 128KB allocated for the stack and network driver buffers and other |
||
77 | ; data requirements |
||
412 | serge | 78 | ;stack_data_start equ 0x700000 |
79 | ;eth_data_start equ 0x700000 |
||
80 | ;stack_data equ 0x704000 |
||
81 | ;stack_data_end equ 0x71ffff |
||
1 | ha | 82 | |
83 | ; 32 bit word |
||
1168 | Lrz | 84 | stack_config equ stack_data |
261 | hidnplayr | 85 | |
1 | ha | 86 | ; 32 bit word - IP Address in network format |
1168 | Lrz | 87 | stack_ip equ stack_data + 4 |
261 | hidnplayr | 88 | |
1 | ha | 89 | ; 1 byte. 0 == inactive, 1 = active |
90 | ethernet_active equ stack_data + 9 |
||
261 | hidnplayr | 91 | |
92 | |||
93 | ; TODO :: empty memory area |
||
94 | |||
1 | ha | 95 | ; Address of selected socket |
907 | mikedld | 96 | ;sktAddr equ stack_data + 32 |
1 | ha | 97 | ; Parameter to checksum routine - data ptr |
1168 | Lrz | 98 | checkAdd1 equ stack_data + 36 |
1 | ha | 99 | ; Parameter to checksum routine - 2nd data ptr |
1168 | Lrz | 100 | checkAdd2 equ stack_data + 40 |
1 | ha | 101 | ; Parameter to checksum routine - data size |
1168 | Lrz | 102 | checkSize1 equ stack_data + 44 |
1 | ha | 103 | ; Parameter to checksum routine - 2nd data size |
1168 | Lrz | 104 | checkSize2 equ stack_data + 46 |
1 | ha | 105 | ; result of checksum routine |
1168 | Lrz | 106 | checkResult equ stack_data + 48 |
1 | ha | 107 | |
108 | ; holds the TCP/UDP pseudo header. SA|DA|0|prot|UDP len| |
||
1168 | Lrz | 109 | pseudoHeader equ stack_data + 50 |
1 | ha | 110 | |
111 | ; receive and transmit IP buffer allocation |
||
907 | mikedld | 112 | ;sockets equ stack_data + 62 |
113 | Next_free2 equ stack_data + 62;Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS) |
||
1 | ha | 114 | ; 1560 byte buffer for rx / tx ethernet packets |
1168 | Lrz | 115 | Ether_buffer equ Next_free2 |
116 | Next_free3 equ Ether_buffer + 1518 |
||
117 | last_1sTick equ Next_free3 |
||
118 | IPbuffs equ Next_free3 + 1 |
||
119 | queues equ IPbuffs + ( NUM_IPBUFFERS * IPBUFFSIZE ) |
||
120 | queueList equ queues + (2 * NUMQUEUES) |
||
121 | last_1hsTick equ queueList + ( 2 * NUMQUEUEENTRIES ) |
||
1 | ha | 122 | |
123 | ;resendQ equ queueList + ( 2 * NUMQUEUEENTRIES ) |
||
124 | ;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
||
125 | ; equ resendBuffer + ( IPBUFFSIZE * NUMRESENDENTRIES ) |
||
126 | |||
127 | |||
128 | |||
412 | serge | 129 | ;resendQ equ 0x770000 |
907 | mikedld | 130 | ;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP ; XTODO: validate size |
1168 | Lrz | 131 | resendBuffer equ resendQ + ( 8 * NUMRESENDENTRIES ) ; for TCP |
1 | ha | 132 | |
133 | |||
907 | mikedld | 134 | uglobal |
135 | net_sockets rd 2 |
||
136 | endg |
||
137 | |||
261 | hidnplayr | 138 | ; simple macro for memory set operation |
139 | macro _memset_dw adr,value,amount |
||
140 | { |
||
1168 | Lrz | 141 | mov edi, adr |
142 | mov ecx, amount |
||
143 | if value = 0 |
||
144 | xor eax, eax |
||
145 | else |
||
146 | mov eax, value |
||
147 | end if |
||
148 | cld |
||
149 | rep stosd |
||
261 | hidnplayr | 150 | } |
151 | |||
152 | |||
153 | ; Below, the main network layer source code is included |
||
154 | ; |
||
155 | include "queue.inc" |
||
156 | include "eth_drv/ethernet.inc" |
||
157 | include "ip.inc" |
||
158 | include "socket.inc" |
||
159 | |||
1 | ha | 160 | ;*************************************************************************** |
161 | ; Function |
||
162 | ; stack_init |
||
163 | ; |
||
164 | ; Description |
||
165 | ; Clear all allocated memory to zero. This ensures that |
||
166 | ; on startup, the stack is inactive, and consumes no resources |
||
167 | ; This is a kernel function, called prior to the OS main loop |
||
168 | ; in set_variables |
||
169 | ; |
||
170 | ;*************************************************************************** |
||
261 | hidnplayr | 171 | |
1 | ha | 172 | stack_init: |
1168 | Lrz | 173 | ; Init two address spaces with default values |
174 | _memset_dw stack_data_start, 0, 0x20000/4 |
||
175 | _memset_dw resendQ, 0, NUMRESENDENTRIES * 2 |
||
1 | ha | 176 | |
1168 | Lrz | 177 | mov [net_sockets], 0 |
178 | mov [net_sockets + 4], 0 |
||
909 | mikedld | 179 | |
1168 | Lrz | 180 | ; Queries initialization |
181 | call queueInit |
||
1 | ha | 182 | |
1168 | Lrz | 183 | ; The following block sets up the 1s timer |
184 | mov al, 0x0 |
||
185 | out 0x70, al |
||
186 | in al, 0x71 |
||
187 | mov [last_1sTick], al |
||
261 | hidnplayr | 188 | ret |
1 | ha | 189 | |
190 | |||
191 | |||
192 | ;*************************************************************************** |
||
193 | ; Function |
||
194 | ; stack_handler |
||
195 | ; |
||
196 | ; Description |
||
197 | ; The kernel loop routine for the stack |
||
198 | ; This is a kernel function, called in the main loop |
||
199 | ; |
||
200 | ;*************************************************************************** |
||
1168 | Lrz | 201 | align 4 |
1 | ha | 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] |
||
1168 | Lrz | 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 |
||
1168 | Lrz | 221 | in al, 0x71 |
1 | ha | 222 | cmp al, [last_1sTick] |
1168 | Lrz | 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 |
||
1168 | Lrz | 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] |
1168 | Lrz | 285 | xor edx, edx ; edx is the accumulative checksum |
1 | ha | 286 | xor ebx, ebx |
287 | mov cx, [checkSize1] |
||
288 | shr cx, 1 |
||
1168 | Lrz | 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 |
||
1168 | Lrz | 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 |
||
1168 | Lrz | 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 |
1168 | Lrz | 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 |
||
1168 | Lrz | 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 | |||
1168 | Lrz | 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 |
||
1168 | Lrz | 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: |
||
1168 | Lrz | 501 | cmp eax, 15 |
502 | jnz not15 |
||
261 | hidnplayr | 503 | |
504 | ; in ebx we need 4 to read the last 2 bytes |
||
1168 | Lrz | 505 | cmp ebx, dword 4 |
506 | je read |
||
379 | serge | 507 | |
261 | hidnplayr | 508 | ; or we need 0 to read the first 4 bytes |
1168 | Lrz | 509 | cmp ebx, dword 0 |
510 | jnz param_error |
||
261 | hidnplayr | 511 | |
512 | ; read MAC, returned (in mirrored byte order) in eax |
||
513 | read: |
||
1168 | Lrz | 514 | mov eax, [node_addr + ebx] |
515 | jmp @f |
||
379 | serge | 516 | |
517 | param_error: |
||
1168 | Lrz | 518 | mov eax, -1 ; params not accepted |
261 | hidnplayr | 519 | @@: |
1168 | Lrz | 520 | ret |
261 | hidnplayr | 521 | |
379 | serge | 522 | |
261 | hidnplayr | 523 | ; 0 -> arp_probe |
524 | ; 1 -> arp_announce |
||
525 | ; 2 -> arp_responce (not supported yet) |
||
526 | |||
1168 | Lrz | 527 | not15: ; ARP stuff |
528 | cmp eax, 16 |
||
529 | jnz not16 |
||
379 | serge | 530 | |
1168 | Lrz | 531 | cmp ebx, 0 |
532 | je a_probe |
||
379 | serge | 533 | |
1168 | Lrz | 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 | |
1168 | Lrz | 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: |
||
1168 | Lrz | 547 | push dword [stack_ip] |
379 | serge | 548 | |
1168 | Lrz | 549 | mov edx, [stack_ip] |
550 | mov [stack_ip], dword 0 |
||
551 | mov esi, ecx ; pointer to target MAC address |
||
552 | call arp_request |
||
379 | serge | 553 | |
1168 | Lrz | 554 | pop dword [stack_ip] |
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: |
||
1168 | Lrz | 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: |
1168 | Lrz | 566 | mov eax, -1 |
379 | serge | 567 | |
261 | hidnplayr | 568 | @@: |
1168 | Lrz | 569 | ret |
261 | hidnplayr | 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: |
||
1168 | Lrz | 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 |
||
1168 | Lrz | 676 | jnz @f ; if function is not implented, return -1 |
302 | hidnplayr | 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 |
||
1168 | Lrz | 927 | je sgp_non_exit ; Exit if no buffer available |
1 | ha | 928 | |
1168 | Lrz | 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 | |||
1168 | Lrz | 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 | |||
1168 | Lrz | 946 | mov ecx, 1500 ; should get the actual number of bytes to write |
1 | ha | 947 | mov esi, eax |
948 | cld |
||
1168 | Lrz | 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 |
||
1168 | Lrz | 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 | |||
1168 | Lrz | 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 |
||
1168 | Lrz | 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 |