Subversion Repositories Kolibri OS

Rev

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

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