Subversion Repositories Kolibri OS

Rev

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