Subversion Repositories Kolibri OS

Rev

Rev 412 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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