Subversion Repositories Kolibri OS

Rev

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