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