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