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