Subversion Repositories Kolibri OS

Rev

Rev 425 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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